-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathnotification-preference.object.ts
More file actions
85 lines (74 loc) · 2.99 KB
/
Copy pathnotification-preference.object.ts
File metadata and controls
85 lines (74 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
import { ObjectSchema, Field } from '@objectstack/spec/data';
/**
* `sys_notification_preference` — per-user × topic × channel delivery toggle
* (ADR-0030 Layer 3).
*
* The mute/allow matrix the preference filter consults before fan-out. A row
* declares whether `user_id` wants `topic` on `channel`. Resolution is
* most-specific-wins with wildcards:
*
* (user, topic, channel) → (user, topic, *) → (user, *, channel) →
* (user, *, *) → ('*', topic, channel) → … → ('*', '*', '*') → default ON
*
* `user_id = '*'` rows are the **admin global default**; a real-user row
* **overrides** it. `topic = '*'` / `channel = '*'` are wildcards. Mandatory
* topics (configured on the service) bypass this object entirely.
*
* Belongs to `service-messaging` (owner of the delivery pipeline).
*/
export const NotificationPreference = ObjectSchema.create({
name: 'sys_notification_preference',
label: 'Notification Preference',
pluralLabel: 'Notification Preferences',
icon: 'bell-ring',
isSystem: true,
managedBy: 'system',
description: 'Per-user × topic × channel notification toggle (mute/allow), with admin-global defaults.',
titleFormat: '{user_id} · {topic} · {channel}',
highlightFields: ['user_id', 'topic', 'channel', 'enabled', 'digest'],
fields: {
id: Field.text({ label: 'Preference ID', required: true, readonly: true }),
user_id: Field.text({
label: 'User',
required: true,
searchable: true,
description: "Recipient user id, or '*' for the admin-global default.",
}),
topic: Field.text({
label: 'Topic',
required: true,
searchable: true,
defaultValue: '*',
description: "Notification topic, or '*' for all topics.",
}),
channel: Field.text({
label: 'Channel',
required: true,
defaultValue: '*',
description: "Channel id (inbox/email/push/…), or '*' for all channels.",
}),
enabled: Field.boolean({
label: 'Enabled',
defaultValue: true,
description: 'When false, this (user, topic, channel) is muted.',
}),
digest: Field.select(['none', 'daily', 'weekly'], {
label: 'Digest',
required: false,
defaultValue: 'none',
description: 'Batch cadence (P3 digest middleware).',
}),
quiet_hours: Field.json({
label: 'Quiet Hours',
required: false,
description: 'Optional { tz, start, end } window (P3 quiet-hours middleware).',
}),
created_at: Field.datetime({ label: 'Created At', readonly: true }),
updated_at: Field.datetime({ label: 'Updated At', required: false }),
},
indexes: [
{ fields: ['user_id', 'topic', 'channel'], unique: true },
{ fields: ['topic'] },
],
});