@dereekb/firebase 13.2.2 → 13.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/index.cjs.js +12893 -4062
  2. package/index.esm.js +12872 -4065
  3. package/package.json +5 -5
  4. package/src/lib/client/error/error.d.ts +18 -3
  5. package/src/lib/client/firestore/array.d.ts +16 -3
  6. package/src/lib/client/firestore/driver.accessor.batch.d.ts +35 -4
  7. package/src/lib/client/firestore/driver.accessor.create.d.ts +15 -0
  8. package/src/lib/client/firestore/driver.accessor.d.ts +15 -0
  9. package/src/lib/client/firestore/driver.accessor.default.d.ts +32 -0
  10. package/src/lib/client/firestore/driver.accessor.transaction.d.ts +35 -4
  11. package/src/lib/client/firestore/driver.d.ts +16 -0
  12. package/src/lib/client/firestore/driver.query.d.ts +36 -0
  13. package/src/lib/client/firestore/firestore.d.ts +11 -1
  14. package/src/lib/client/firestore/increment.d.ts +12 -3
  15. package/src/lib/client/function/development.function.factory.d.ts +27 -2
  16. package/src/lib/client/function/error.d.ts +27 -0
  17. package/src/lib/client/function/function.callable.d.ts +50 -5
  18. package/src/lib/client/function/function.factory.d.ts +70 -4
  19. package/src/lib/client/function/model.function.factory.d.ts +64 -9
  20. package/src/lib/client/storage/driver.accessor.d.ts +93 -0
  21. package/src/lib/client/storage/driver.d.ts +15 -0
  22. package/src/lib/client/storage/storage.d.ts +10 -1
  23. package/src/lib/common/auth/auth.context.d.ts +17 -2
  24. package/src/lib/common/auth/auth.d.ts +38 -9
  25. package/src/lib/common/auth/auth.error.d.ts +25 -0
  26. package/src/lib/common/auth/auth.server.error.d.ts +6 -2
  27. package/src/lib/common/development/function.d.ts +17 -6
  28. package/src/lib/common/development/function.schedule.d.ts +30 -1
  29. package/src/lib/common/firestore/accessor/accessor.wrap.modify.d.ts +36 -12
  30. package/src/lib/common/firestore/accessor/array.d.ts +14 -4
  31. package/src/lib/common/firestore/accessor/document.d.ts +77 -2
  32. package/src/lib/common/firestore/accessor/increment.d.ts +15 -3
  33. package/src/lib/common/firestore/collection/collection.d.ts +22 -4
  34. package/src/lib/common/firestore/collection/collection.util.d.ts +12 -2
  35. package/src/lib/common/firestore/driver/accessor.d.ts +28 -1
  36. package/src/lib/common/firestore/driver/batch.d.ts +6 -4
  37. package/src/lib/common/firestore/driver/driver.d.ts +18 -1
  38. package/src/lib/common/firestore/driver/query.d.ts +20 -1
  39. package/src/lib/common/firestore/driver/query.handler.d.ts +23 -0
  40. package/src/lib/common/firestore/driver/transaction.d.ts +18 -6
  41. package/src/lib/common/firestore/error.d.ts +16 -4
  42. package/src/lib/common/firestore/query/iterator.d.ts +11 -0
  43. package/src/lib/common/firestore/reference.d.ts +11 -6
  44. package/src/lib/common/firestore/snapshot/snapshot.d.ts +4 -0
  45. package/src/lib/common/firestore/snapshot/snapshot.field.d.ts +263 -63
  46. package/src/lib/common/firestore/types.d.ts +39 -1
  47. package/src/lib/common/firestore/util/id.batch.d.ts +55 -3
  48. package/src/lib/common/function/action.d.ts +35 -0
  49. package/src/lib/common/model/context.d.ts +11 -1
  50. package/src/lib/common/model/function.d.ts +45 -9
  51. package/src/lib/common/model/model/model.loader.d.ts +37 -0
  52. package/src/lib/common/model/model/model.param.d.ts +24 -2
  53. package/src/lib/common/model/model.service.d.ts +126 -4
  54. package/src/lib/common/model/permission/permission.context.d.ts +15 -0
  55. package/src/lib/common/model/permission/permission.d.ts +16 -0
  56. package/src/lib/common/model/permission/permission.service.d.ts +24 -1
  57. package/src/lib/common/model/permission/permission.service.grant.d.ts +72 -28
  58. package/src/lib/common/model/permission/permission.service.role.d.ts +15 -0
  59. package/src/lib/common/storage/accessor/path.model.d.ts +25 -8
  60. package/src/lib/common/storage/context.d.ts +23 -6
  61. package/src/lib/common/storage/driver/accessor.d.ts +15 -4
  62. package/src/lib/common/storage/driver/accessor.iterate.d.ts +31 -8
  63. package/src/lib/common/storage/driver/accessor.util.d.ts +13 -6
  64. package/src/lib/common/storage/driver/driver.d.ts +10 -1
  65. package/src/lib/common/storage/driver/error.d.ts +16 -0
  66. package/src/lib/common/storage/driver/list.d.ts +30 -0
  67. package/src/lib/common/storage/storage.d.ts +76 -19
  68. package/src/lib/common/storage/types.d.ts +23 -5
  69. package/src/lib/model/index.d.ts +1 -0
  70. package/src/lib/model/notification/notification.action.d.ts +8 -0
  71. package/src/lib/model/notification/notification.api.d.ts +26 -0
  72. package/src/lib/model/notification/notification.api.error.d.ts +15 -0
  73. package/src/lib/model/notification/notification.api.util.d.ts +27 -12
  74. package/src/lib/model/notification/notification.config.d.ts +193 -64
  75. package/src/lib/model/notification/notification.create.d.ts +62 -13
  76. package/src/lib/model/notification/notification.create.task.d.ts +25 -4
  77. package/src/lib/model/notification/notification.d.ts +258 -99
  78. package/src/lib/model/notification/notification.details.d.ts +66 -18
  79. package/src/lib/model/notification/notification.id.d.ts +90 -12
  80. package/src/lib/model/notification/notification.item.d.ts +57 -16
  81. package/src/lib/model/notification/notification.message.d.ts +84 -18
  82. package/src/lib/model/notification/notification.query.d.ts +21 -24
  83. package/src/lib/model/notification/notification.send.d.ts +38 -5
  84. package/src/lib/model/notification/notification.task.d.ts +87 -16
  85. package/src/lib/model/notification/notification.task.subtask.d.ts +42 -13
  86. package/src/lib/model/notification/notification.util.d.ts +68 -18
  87. package/src/lib/model/oidcmodel/index.d.ts +8 -0
  88. package/src/lib/model/oidcmodel/oidcmodel.action.d.ts +37 -0
  89. package/src/lib/model/oidcmodel/oidcmodel.api.d.ts +131 -0
  90. package/src/lib/model/oidcmodel/oidcmodel.d.ts +114 -0
  91. package/src/lib/model/oidcmodel/oidcmodel.data.d.ts +17 -0
  92. package/src/lib/model/oidcmodel/oidcmodel.id.d.ts +18 -0
  93. package/src/lib/model/oidcmodel/oidcmodel.interaction.d.ts +40 -0
  94. package/src/lib/model/oidcmodel/oidcmodel.interaction.oauth.d.ts +73 -0
  95. package/src/lib/model/oidcmodel/oidcmodel.query.d.ts +21 -0
  96. package/src/lib/model/storagefile/storagefile.action.d.ts +47 -0
  97. package/src/lib/model/storagefile/storagefile.api.d.ts +54 -4
  98. package/src/lib/model/storagefile/storagefile.create.d.ts +40 -3
  99. package/src/lib/model/storagefile/storagefile.d.ts +153 -16
  100. package/src/lib/model/storagefile/storagefile.file.d.ts +22 -7
  101. package/src/lib/model/storagefile/storagefile.group.d.ts +30 -1
  102. package/src/lib/model/storagefile/storagefile.group.processing.d.ts +20 -2
  103. package/src/lib/model/storagefile/storagefile.id.d.ts +44 -5
  104. package/src/lib/model/storagefile/storagefile.permission.d.ts +23 -4
  105. package/src/lib/model/storagefile/storagefile.query.d.ts +63 -11
  106. package/src/lib/model/storagefile/storagefile.task.d.ts +47 -4
  107. package/src/lib/model/storagefile/storagefile.upload.claims.d.ts +21 -4
  108. package/src/lib/model/storagefile/storagefile.upload.d.ts +41 -9
  109. package/src/lib/model/storagefile/storagefile.upload.determiner.d.ts +112 -20
  110. package/src/lib/model/storagefile/storagefile.util.d.ts +66 -3
  111. package/src/lib/model/system/system.action.d.ts +25 -0
  112. package/src/lib/model/system/system.d.ts +80 -4
  113. package/src/lib/model/user.d.ts +8 -2
  114. package/test/index.cjs.js +11168 -3295
  115. package/test/index.esm.js +11176 -3303
  116. package/test/package.json +6 -6
  117. package/test/src/lib/client/firebase.authorized.d.ts +18 -0
  118. package/test/src/lib/client/firebase.d.ts +60 -0
  119. package/test/src/lib/common/firebase.instance.d.ts +21 -0
  120. package/test/src/lib/common/firestore/firestore.d.ts +40 -0
  121. package/test/src/lib/common/firestore/firestore.instance.d.ts +16 -0
  122. package/test/src/lib/common/firestore/test.driver.accessor.d.ts +39 -2
  123. package/test/src/lib/common/firestore/test.driver.utility.d.ts +8 -2
  124. package/test/src/lib/common/firestore/test.iterator.d.ts +7 -2
  125. package/test/src/lib/common/mock/mock.item.collection.fixture.d.ts +29 -1
  126. package/test/src/lib/common/mock/mock.item.d.ts +219 -5
  127. package/test/src/lib/common/mock/mock.item.id.d.ts +6 -0
  128. package/test/src/lib/common/mock/mock.item.query.d.ts +12 -0
  129. package/test/src/lib/common/mock/mock.item.service.d.ts +60 -0
  130. package/test/src/lib/common/mock/mock.item.storage.fixture.d.ts +28 -1
  131. package/test/src/lib/common/storage/storage.d.ts +30 -0
  132. package/test/src/lib/common/storage/storage.instance.d.ts +22 -0
  133. package/test/src/lib/common/storage/test.driver.accessor.d.ts +7 -2
  134. package/index.cjs.js.map +0 -1
  135. package/index.esm.js.map +0 -1
@@ -1,170 +1,258 @@
1
+ /**
2
+ * @module notification.config
3
+ *
4
+ * Notification recipient configuration types and the bitwise encoding system for per-template channel preferences.
5
+ *
6
+ * Configuration follows a 3-level hierarchy (highest priority first):
7
+ * 1. {@link NotificationUser.gc} — Global config override (applies at send time, not synced to boxes)
8
+ * 2. {@link NotificationUserNotificationBoxRecipientConfig} — Per-box config on the user (synced to boxes)
9
+ * 3. {@link NotificationBoxRecipientTemplateConfig} — Template defaults from the system configuration
10
+ *
11
+ * Each level can enable/disable delivery per channel (email, text, push, summary) per template type.
12
+ * Configs are stored efficiently using bitwise encoding via {@link EncodedNotificationBoxRecipientTemplateConfig}.
13
+ */
1
14
  import { type Maybe, type EmailAddress, type E164PhoneNumber, type BitwiseEncodedSet, type IndexRef, type NeedsSyncBoolean } from '@dereekb/util';
2
15
  import { type NotificationBoxId, type NotificationSummaryId, type NotificationTemplateType } from './notification.id';
3
16
  import { type FirebaseAuthUserId, type SavedToFirestoreIfTrue } from '../../common';
4
17
  /**
5
- * Notification configuration state for a template.
18
+ * Per-template notification channel preferences for a recipient.
6
19
  *
7
- * Denotes which modes of message are enabled for the user to recieve.
20
+ * Controls which delivery channels are enabled for a specific {@link NotificationTemplateType}.
21
+ * Undefined values inherit from the parent level in the configuration hierarchy.
22
+ *
23
+ * Field abbreviations:
24
+ * - `sd` — send default (master toggle for all channels)
25
+ * - `se` — send email
26
+ * - `st` — send text/SMS
27
+ * - `sp` — send push notification
28
+ * - `sn` — send to notification summary
8
29
  */
9
30
  export interface NotificationBoxRecipientTemplateConfig {
10
31
  /**
11
- * Send default is enabled/disabled for all types if not defined
32
+ * Master toggle. When set, acts as the default for all channels that aren't individually configured.
12
33
  */
13
34
  sd?: Maybe<boolean>;
14
35
  /**
15
- * Email enabled / Send Email
36
+ * Email channel enabled/disabled.
16
37
  */
17
38
  se?: Maybe<boolean>;
18
39
  /**
19
- * Phone enabled / Send Text
40
+ * Text/SMS channel enabled/disabled.
20
41
  */
21
42
  st?: Maybe<boolean>;
22
43
  /**
23
- * Push notification enabled / Send Push Notification
44
+ * Push notification channel enabled/disabled.
24
45
  */
25
46
  sp?: Maybe<boolean>;
26
47
  /**
27
- * Send to notification summary of the associate user, if applicable.
48
+ * In-app notification summary channel enabled/disabled.
28
49
  */
29
50
  sn?: Maybe<boolean>;
30
51
  }
52
+ /**
53
+ * Merges two {@link NotificationBoxRecipientTemplateConfig} objects, preferring values from `a` over `b`.
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * const merged = mergeNotificationBoxRecipientTemplateConfigs(
58
+ * { se: true }, // user prefers email on
59
+ * { se: false, st: true } // defaults
60
+ * );
61
+ * // merged === { se: true, st: true }
62
+ * ```
63
+ */
31
64
  export declare function mergeNotificationBoxRecipientTemplateConfigs(a?: Maybe<NotificationBoxRecipientTemplateConfig>, b?: Maybe<NotificationBoxRecipientTemplateConfig>): NotificationBoxRecipientTemplateConfig;
65
+ /**
66
+ * Resolves a {@link NotificationBoxRecipientTemplateConfig} by filling in undefined channel flags with the `sd` (send default) value.
67
+ *
68
+ * This produces the "effective" configuration used at send time, where each channel has a definite boolean.
69
+ *
70
+ * @example
71
+ * ```ts
72
+ * const effective = effectiveNotificationBoxRecipientTemplateConfig({ sd: true, se: false });
73
+ * // effective === { sd: true, se: false, st: true, sp: true, sn: true }
74
+ * ```
75
+ */
32
76
  export declare function effectiveNotificationBoxRecipientTemplateConfig(a: NotificationBoxRecipientTemplateConfig): NotificationBoxRecipientTemplateConfig;
33
77
  /**
34
- * Recipient configuration for a notification
78
+ * Contact information for a notification recipient.
79
+ *
80
+ * When `uid` is set, the server resolves contact details (name, email, phone) from the user's profile.
81
+ * Override fields (`n`, `e`, `t`) take precedence over profile data when present.
82
+ *
83
+ * Field abbreviations:
84
+ * - `uid` — Firebase auth user ID
85
+ * - `n` — name override
86
+ * - `e` — email override
87
+ * - `t` — phone/text number override (E.164 format)
88
+ * - `s` — notification summary ID (ignored when `uid` is set)
35
89
  */
36
90
  export interface NotificationRecipient {
37
91
  /**
38
- * User id for this config, if applicable.
39
- *
40
- * Is used to retrieve the contact's information when sending them information, as well as push notification details.
92
+ * Firebase auth UID. When set, contact info is resolved from the user's profile and push notification tokens.
41
93
  */
42
94
  uid?: Maybe<FirebaseAuthUserId>;
43
95
  /**
44
- * User's name. Overrides any info in the user's Profile.
96
+ * Display name override. Takes precedence over the user's profile name.
45
97
  */
46
98
  n?: Maybe<string>;
47
99
  /**
48
- * User's email address. Overrides any info in the user's Profile.
100
+ * Email address override. Takes precedence over the user's profile email.
49
101
  */
50
102
  e?: Maybe<EmailAddress>;
51
103
  /**
52
- * User's phone number to send text messages to. Overrides any info in the user's Profile.
104
+ * Phone number override (E.164 format). Takes precedence over the user's profile phone.
53
105
  */
54
106
  t?: Maybe<E164PhoneNumber>;
55
107
  /**
56
- * Notification summary id to send notifications to. Ignored and/or set null if uid is defined.
108
+ * Notification summary ID for in-app delivery. Automatically cleared when `uid` is set.
57
109
  */
58
110
  s?: Maybe<NotificationSummaryId>;
59
111
  }
112
+ /**
113
+ * Updates a {@link NotificationRecipient} with partial values, preserving existing fields where the update is undefined.
114
+ *
115
+ * Automatically clears the summary ID (`s`) when a `uid` is present.
116
+ */
60
117
  export declare function updateNotificationRecipient(a: NotificationRecipient, b: Partial<NotificationRecipient>): NotificationRecipient;
118
+ /**
119
+ * A {@link NotificationRecipient} combined with inline {@link NotificationBoxRecipientTemplateConfig} overrides.
120
+ *
121
+ * Used on individual {@link Notification} documents to attach per-notification recipient preferences
122
+ * that can override the box-level and user-level configurations.
123
+ */
61
124
  export interface NotificationRecipientWithConfig extends NotificationRecipient, NotificationBoxRecipientTemplateConfig {
62
125
  }
126
+ /**
127
+ * Firestore sub-object converter for {@link NotificationRecipientWithConfig}.
128
+ */
63
129
  export declare const firestoreNotificationRecipientWithConfig: import("../..").FirestoreSubObjectFieldMapFunctionsConfig<NotificationRecipientWithConfig, Partial<import("@dereekb/util").ReplaceType<NotificationRecipientWithConfig, import("@dereekb/util").MaybeMap<object>, any>>>;
130
+ /**
131
+ * Recipient-level opt-in/opt-out flag on a {@link NotificationBoxRecipient}.
132
+ *
133
+ * Non-zero values cause the recipient to be skipped during notification delivery.
134
+ */
64
135
  export declare enum NotificationBoxRecipientFlag {
65
136
  /**
66
- * The recipient is enabled.
67
- *
68
- * This is a transient state that should not be stored.
137
+ * Recipient is active and will receive notifications. This is the default; not stored in Firestore.
69
138
  */
70
139
  ENABLED = 0,
71
140
  /**
72
- * The recipient is not enabled to recieve notifications currently.
141
+ * Recipient is administratively disabled (e.g., by the box owner).
73
142
  */
74
143
  DISABLED = 1,
75
144
  /**
76
- * Recipient opted themselves out from recieving notifications.
145
+ * Recipient opted themselves out from receiving notifications.
77
146
  */
78
147
  OPT_OUT = 2
79
148
  }
80
149
  /**
81
- * Settings related to recipients that recieve notifications.
150
+ * Recipient entry embedded in a {@link NotificationBox}. Combines contact info with per-template channel configs.
151
+ *
152
+ * When `uid` is set, contact details are resolved from the user's profile at send time.
153
+ * The `i` field (from {@link IndexRef}) tracks the recipient's position and is synced with
154
+ * the corresponding {@link NotificationUserNotificationBoxRecipientConfig} on the user side.
82
155
  *
83
- * If uid is set, then most other NotificationRecipient fields are ignored as those are pulled from auth.
156
+ * Field abbreviations:
157
+ * - `x` — excluded flag (set via {@link NotificationBoxSendExclusion})
158
+ * - `c` — per-template channel config record
159
+ * - `f` — opt-in/opt-out flag
160
+ * - `lk` — locked flag (prevents box-side updates; user can still update their own config)
84
161
  */
85
162
  export interface NotificationBoxRecipient extends NotificationRecipient, IndexRef {
86
163
  /**
87
- * Whether or not this recipient has been marked as excluded.
88
- *
89
- * This can only be updated by removing the exclusion from the.
164
+ * Excluded flag. Set when the recipient is excluded via a {@link NotificationBoxSendExclusion} on their {@link NotificationUser}.
165
+ * Can only be cleared by removing the exclusion from the user's exclusion list.
90
166
  */
91
167
  x?: Maybe<SavedToFirestoreIfTrue>;
92
168
  /**
93
- * Enabled config types
169
+ * Per-template channel configuration. Keys are {@link NotificationTemplateType} values.
94
170
  */
95
171
  c: NotificationBoxRecipientTemplateConfigRecord;
96
172
  /**
97
- * Current opt in flag. Non-zero values are opt-out.
98
- *
99
- * TODO: Test updating the flag and syncing
173
+ * Opt-in/opt-out flag. Non-zero values prevent notification delivery to this recipient.
100
174
  */
101
175
  f?: Maybe<NotificationBoxRecipientFlag>;
102
176
  /**
103
- * Locked state that corresponds to the user's configuration and is sync'd by NotificationUserNotificationBoxRecipientConfig.
104
- *
105
- * If locked, updating the NotificationBox recipient will throw an error. The user can update their settings without issue.
177
+ * Locked flag. When true, the box cannot modify this recipient's config only the user can update via their {@link NotificationUser}.
106
178
  */
107
179
  lk?: Maybe<SavedToFirestoreIfTrue>;
108
180
  }
181
+ /**
182
+ * Creates a new {@link NotificationBoxRecipient} for a user with an empty config record.
183
+ *
184
+ * @param uid - the user's Firebase auth UID
185
+ * @param i - the recipient's index position in the box's recipient array
186
+ */
109
187
  export declare function newNotificationBoxRecipientForUid(uid: FirebaseAuthUserId, i: number): NotificationBoxRecipient;
110
188
  /**
111
- * Default NotificationUserNotificationBoxRecipientConfig.
189
+ * Default/fallback notification config stored on a {@link NotificationUser}.
190
+ *
191
+ * Used as the base configuration for the user's direct/default config (`dc`) and global config override (`gc`).
192
+ * Omits per-recipient fields (index, name, summary ID, uid, exclusion) that only apply to box-level entries.
193
+ *
194
+ * Field abbreviations:
195
+ * - `lk` — locked flag (prevents box-side updates to this user's recipient entry)
196
+ * - `bk` — blocked flag (prevents the box from re-adding this user)
112
197
  */
113
198
  export interface NotificationUserDefaultNotificationBoxRecipientConfig extends Omit<NotificationBoxRecipient, 'i' | 'n' | 's' | 'uid' | 'x'> {
114
199
  /**
115
- * Locked state.
116
- *
117
- * If locked, updating the NotificationBox recipient will throw an error. The user can update their settings without issue.
200
+ * Locked flag. Prevents the NotificationBox from modifying this user's recipient config.
118
201
  */
119
202
  lk?: Maybe<SavedToFirestoreIfTrue>;
120
203
  /**
121
- * Blocked state.
122
- *
123
- * If blocked, this NotificationBox will not be able to add this user back.
204
+ * Blocked flag. Prevents the NotificationBox from re-adding this user as a recipient.
124
205
  */
125
206
  bk?: Maybe<SavedToFirestoreIfTrue>;
126
207
  }
208
+ /**
209
+ * Merges two {@link NotificationUserDefaultNotificationBoxRecipientConfig} objects, preferring defined values from `a` over `b`.
210
+ */
127
211
  export declare function mergeNotificationUserDefaultNotificationBoxRecipientConfig(a: NotificationUserDefaultNotificationBoxRecipientConfig, b: NotificationUserDefaultNotificationBoxRecipientConfig): NotificationUserDefaultNotificationBoxRecipientConfig;
128
212
  /**
129
- * Used to reflect the NotificationBoxRecipient config back to a NotificationUser.
213
+ * Per-box notification config stored on a {@link NotificationUser}, mirroring the user's {@link NotificationBoxRecipient} entry.
130
214
  *
131
- * The index reflects the index the user is in the NotificationBox.
215
+ * The `i` field tracks the user's index in the box's recipient array. Changes here are synced
216
+ * bidirectionally with the corresponding {@link NotificationBox} during server-side sync.
217
+ *
218
+ * Field abbreviations:
219
+ * - `nb` — NotificationBox ID this config mirrors
220
+ * - `rm` — removed flag (user self-removed from the box)
221
+ * - `ns` — needs-sync flag
222
+ * - `lk` — locked flag (prevents box-side updates)
223
+ * - `bk` — blocked flag (prevents re-addition to the box)
132
224
  */
133
225
  export interface NotificationUserNotificationBoxRecipientConfig extends Omit<NotificationBoxRecipient, 'uid'> {
134
226
  /**
135
- * NotificationBox this configuration reflects.
136
- *
137
- * The model can be derived from this id.
227
+ * ID of the {@link NotificationBox} this config mirrors. The related model key can be inferred via {@link inferNotificationBoxRelatedModelKey}.
138
228
  */
139
229
  nb: NotificationBoxId;
140
230
  /**
141
- * Removed state.
142
- *
143
- * If flagged, then this user has flagged themselves to be removed from the NotificationBox or have already been removed.
144
- *
145
- * Only the NotificationBox can restore a user, so a if a user removes themselves the user cannot restore themselves.
146
- * A user will typically prefer to utilize the "f" value (opt-out) flag to not recieve any notifications, rather than remove themselves.
231
+ * Self-removal flag. When set, the user has removed themselves from this box.
147
232
  *
148
- * The config for this NotificationBox is retained on the NotificationUser, unless the user deletes the configuration themselves.
233
+ * Only the box owner can restore a removed user. Users typically prefer the `f` (opt-out) flag instead,
234
+ * which stops delivery without removing the subscription. The config is retained unless the user explicitly deletes it.
149
235
  */
150
236
  rm?: Maybe<SavedToFirestoreIfTrue>;
151
237
  /**
152
- * Needs to be sync'd with the NotificationBox
238
+ * Whether this config needs to be synced with the corresponding {@link NotificationBox} recipient entry.
153
239
  */
154
240
  ns?: Maybe<NeedsSyncBoolean>;
155
241
  /**
156
- * Locked state.
157
- *
158
- * If locked, updating the NotificationBox recipient will throw an error. The user can update their settings without issue.
242
+ * Locked flag. Prevents the box from modifying this user's recipient config.
159
243
  */
160
244
  lk?: Maybe<SavedToFirestoreIfTrue>;
161
245
  /**
162
- * Blocked state.
163
- *
164
- * If blocked, this NotificationBox will not be able to add this user back.
246
+ * Blocked flag. Prevents the box from re-adding this user as a recipient.
165
247
  */
166
248
  bk?: Maybe<SavedToFirestoreIfTrue>;
167
249
  }
250
+ /**
251
+ * Bit positions for encoding {@link NotificationBoxRecipientTemplateConfig} as a {@link BitwiseEncodedSet}.
252
+ *
253
+ * Each channel has an ON and OFF bit. If neither is set, the channel inherits from the parent config.
254
+ * This encoding allows compact storage of per-template preferences in Firestore.
255
+ */
168
256
  export declare enum NotificationBoxRecipientTemplateConfigBoolean {
169
257
  SEND_ALL_ON = 0,
170
258
  SEND_ALL_OFF = 1,
@@ -178,35 +266,76 @@ export declare enum NotificationBoxRecipientTemplateConfigBoolean {
178
266
  NOTIFICATION_SUMMARY_OFF = 9
179
267
  }
180
268
  /**
181
- * Encoded NotificationBoxRecipientTemplateConfig
269
+ * Bitwise-encoded form of {@link NotificationBoxRecipientTemplateConfig}, stored as a number in Firestore
270
+ * for space efficiency. Decoded via the internal `notificationBoxRecipientTemplateConfigDencoder`.
182
271
  */
183
272
  export type EncodedNotificationBoxRecipientTemplateConfig = BitwiseEncodedSet;
184
273
  /**
185
- * Map of template types to their configurations.
274
+ * Map of {@link NotificationTemplateType} to per-channel configuration for a recipient.
186
275
  *
187
- * Should not be saved with any template type entirely disabled.
276
+ * Stored on {@link NotificationBoxRecipient} and {@link NotificationUserNotificationBoxRecipientConfig}.
277
+ * Template types with all channels disabled should be omitted to save space.
188
278
  */
189
279
  export type NotificationBoxRecipientTemplateConfigRecord = Record<NotificationTemplateType, NotificationBoxRecipientTemplateConfig>;
280
+ /**
281
+ * Merges two {@link NotificationBoxRecipientTemplateConfigRecord} objects, preferring defined values from `a`.
282
+ */
190
283
  export declare function mergeNotificationBoxRecipientTemplateConfigRecords(a: NotificationBoxRecipientTemplateConfigRecord, b: NotificationBoxRecipientTemplateConfigRecord): NotificationBoxRecipientTemplateConfigRecord;
191
284
  /**
192
- * Encoded NotificationBoxRecipientTemplateConfigRecord
285
+ * Bitwise-encoded form of {@link NotificationBoxRecipientTemplateConfigRecord}, with each template type
286
+ * mapped to its {@link EncodedNotificationBoxRecipientTemplateConfig} number.
193
287
  */
194
288
  export type EncodedNotificationBoxRecipientTemplateConfigRecord = Record<NotificationTemplateType, EncodedNotificationBoxRecipientTemplateConfig>;
289
+ /**
290
+ * Creates a Firestore field converter for {@link NotificationBoxRecipientTemplateConfigRecord},
291
+ * using bitwise encoding for compact storage.
292
+ */
195
293
  export declare function firestoreNotificationBoxRecipientTemplateConfigRecord(): import("../..").FirestoreModelFieldMapFunctionsConfig<import("../..").FirestoreEncodedObjectMapFieldValueType<NotificationBoxRecipientTemplateConfig, string>, import("../..").FirestoreMapFieldType<number, string>>;
294
+ /**
295
+ * Firestore sub-object converter for {@link NotificationBoxRecipient}.
296
+ */
196
297
  export declare const firestoreNotificationBoxRecipient: import("../..").FirestoreSubObjectFieldMapFunctionsConfig<NotificationBoxRecipient, Partial<import("@dereekb/util").ReplaceType<NotificationBoxRecipient, import("@dereekb/util").MaybeMap<object>, any>>>;
298
+ /**
299
+ * Firestore sub-object converter for {@link NotificationUserDefaultNotificationBoxRecipientConfig}.
300
+ */
197
301
  export declare const firestoreNotificationUserDefaultNotificationBoxRecipientConfig: import("../..").FirestoreSubObjectFieldMapFunctionsConfig<NotificationUserDefaultNotificationBoxRecipientConfig, Partial<import("@dereekb/util").ReplaceType<NotificationUserDefaultNotificationBoxRecipientConfig, import("@dereekb/util").MaybeMap<object>, any>>>;
302
+ /**
303
+ * Firestore sub-object converter for {@link NotificationUserNotificationBoxRecipientConfig}.
304
+ */
198
305
  export declare const firestoreNotificationUserNotificationBoxRecipientConfig: import("../..").FirestoreSubObjectFieldMapFunctionsConfig<NotificationUserNotificationBoxRecipientConfig, Partial<import("@dereekb/util").ReplaceType<NotificationUserNotificationBoxRecipientConfig, import("@dereekb/util").MaybeMap<object>, any>>>;
306
+ /**
307
+ * Array-form entry of a {@link NotificationBoxRecipientTemplateConfig} with its template type key.
308
+ *
309
+ * Used for UI display where iterating over an array is more convenient than a record.
310
+ */
199
311
  export interface NotificationBoxRecipientTemplateConfigArrayEntry extends NotificationBoxRecipientTemplateConfig {
200
312
  /**
201
- * Array entry template type
313
+ * The template type this config entry belongs to.
202
314
  */
203
315
  type: NotificationTemplateType;
204
316
  }
317
+ /**
318
+ * Array form of {@link NotificationBoxRecipientTemplateConfigRecord} for UI consumption.
319
+ */
205
320
  export type NotificationBoxRecipientTemplateConfigArray = NotificationBoxRecipientTemplateConfigArrayEntry[];
321
+ /**
322
+ * Converts a {@link NotificationBoxRecipientTemplateConfigRecord} to an array of entries with their type keys.
323
+ *
324
+ * @example
325
+ * ```ts
326
+ * const array = notificationBoxRecipientTemplateConfigRecordToArray({ 'comment': { se: true } });
327
+ * // array === [{ type: 'comment', se: true }]
328
+ * ```
329
+ */
206
330
  export declare function notificationBoxRecipientTemplateConfigRecordToArray(input: NotificationBoxRecipientTemplateConfigRecord): NotificationBoxRecipientTemplateConfigArray;
331
+ /**
332
+ * Converts a {@link NotificationBoxRecipientTemplateConfigArray} back to a {@link NotificationBoxRecipientTemplateConfigRecord}.
333
+ */
207
334
  export declare function notificationBoxRecipientTemplateConfigArrayToRecord(input: NotificationBoxRecipientTemplateConfigArray): NotificationBoxRecipientTemplateConfigRecord;
208
335
  /**
209
- * Config object that may contain a boolean called sendNotification.
336
+ * Mixin interface for objects that can optionally trigger a notification on save/update.
337
+ *
338
+ * Used in API parameter types to let callers opt in or out of notification delivery for an action.
210
339
  */
211
340
  export interface SendNotificationRef {
212
341
  sendNotification?: Maybe<boolean>;
@@ -1,3 +1,11 @@
1
+ /**
2
+ * @module notification.create
3
+ *
4
+ * Factory functions and template types for creating {@link Notification} documents.
5
+ *
6
+ * Provides a fluent input pattern ({@link CreateNotificationTemplateInput}) that maps friendly field names
7
+ * to the abbreviated Firestore fields, plus throttling support to avoid duplicate sends.
8
+ */
1
9
  import { type Maybe, type Milliseconds, type ModelKey } from '@dereekb/util';
2
10
  import { type Notification, type NotificationDocument, type NotificationFirestoreCollections, NotificationSendType } from './notification';
3
11
  import { type NotificationRecipientWithConfig } from './notification.config';
@@ -5,7 +13,8 @@ import { type NotificationTaskType, type NotificationTaskUniqueId, type Notifica
5
13
  import { type FirebaseAuthUserId, type FirestoreDocumentAccessor, type ReadFirestoreModelKeyInput, type Transaction } from '../../common';
6
14
  import { type NotificationItem } from './notification.item';
7
15
  /**
8
- * Template item for a new Notification
16
+ * Template for the embedded {@link NotificationItem} within a new notification.
17
+ * Omits auto-generated fields (`id`, `cat`) that are set during document creation.
9
18
  */
10
19
  export interface CreateNotificationTemplateItem extends Omit<NotificationItem, 'r' | 'id' | 'cat'> {
11
20
  /**
@@ -14,7 +23,9 @@ export interface CreateNotificationTemplateItem extends Omit<NotificationItem, '
14
23
  readonly cat?: Maybe<Date>;
15
24
  }
16
25
  /**
17
- * Template use for creating a new Notification
26
+ * Low-level template for creating a new {@link Notification} document. Uses Firestore field abbreviations directly.
27
+ *
28
+ * Prefer using {@link CreateNotificationTemplateInput} with {@link createNotificationTemplate} for a friendlier API.
18
29
  */
19
30
  export interface CreateNotificationTemplate extends Partial<Omit<Notification, 'n' | 'a' | 'd' | 'tsr' | 'esr'>> {
20
31
  /**
@@ -44,6 +55,22 @@ export interface CreateNotificationTemplate extends Partial<Omit<Notification, '
44
55
  */
45
56
  readonly overrideExistingTask?: Maybe<boolean>;
46
57
  }
58
+ /**
59
+ * Friendly input type for creating notification templates. Maps readable field names to the abbreviated Firestore fields.
60
+ *
61
+ * Processed by {@link createNotificationTemplate} into a {@link CreateNotificationTemplate}.
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * const template = createNotificationTemplate({
66
+ * notificationModel: 'project/abc123',
67
+ * type: 'comment',
68
+ * subject: 'New comment',
69
+ * message: 'Someone commented on your project',
70
+ * createdBy: 'user-uid-123'
71
+ * });
72
+ * ```
73
+ */
47
74
  export interface CreateNotificationTemplateInput extends Partial<Omit<CreateNotificationTemplate, 'notificationModel'>>, Partial<Omit<CreateNotificationTemplateItem, 't' | 'cat'>> {
48
75
  /**
49
76
  * Model key input of the NotificationBox's target model (not the NotificationBox/key)
@@ -90,7 +117,20 @@ export interface CreateNotificationTemplateInput extends Partial<Omit<CreateNoti
90
117
  */
91
118
  readonly explicitOptInTextSmsSendOnly?: Maybe<boolean>;
92
119
  }
120
+ /**
121
+ * Converts a {@link CreateNotificationTemplateInput} into a {@link CreateNotificationTemplate}
122
+ * ready for document creation.
123
+ *
124
+ * Maps friendly field names (`subject`, `message`, `createdBy`, etc.) to their Firestore abbreviations
125
+ * and filters out null/undefined metadata values.
126
+ */
93
127
  export declare function createNotificationTemplate(input: CreateNotificationTemplateInput): CreateNotificationTemplate;
128
+ /**
129
+ * Input parameters controlling whether a notification should actually be created and sent.
130
+ *
131
+ * Supports both an explicit toggle (`sendNotification`) and time-based throttling
132
+ * to prevent duplicate sends within a configurable window.
133
+ */
94
134
  export interface ShouldSendCreatedNotificationInput {
95
135
  /**
96
136
  * Whether or not to actually create/save the notification. Defaults to true.
@@ -106,12 +146,15 @@ export interface ShouldSendCreatedNotificationInput {
106
146
  readonly sendNotificationThrottleTime?: Maybe<Milliseconds>;
107
147
  }
108
148
  /**
109
- * Returns true if the notification should be created/sent, given the input.
149
+ * Determines whether a notification should be created based on the explicit toggle and throttle settings.
110
150
  *
111
- * @param input
112
- * @returns
151
+ * Returns false if `sendNotification` is explicitly false, or if the throttle window hasn't elapsed.
113
152
  */
114
153
  export declare function shouldSendCreatedNotificationInput(input: ShouldSendCreatedNotificationInput): boolean;
154
+ /**
155
+ * Full input for creating a {@link Notification} document, including the template, transaction context,
156
+ * and collection accessors.
157
+ */
115
158
  export interface CreateNotificationDocumentPairInput extends ShouldSendCreatedNotificationInput {
116
159
  /**
117
160
  * Now to use when creating the notification.
@@ -140,6 +183,9 @@ export interface CreateNotificationDocumentPairInput extends ShouldSendCreatedNo
140
183
  */
141
184
  readonly accessor?: FirestoreDocumentAccessor<Notification, NotificationDocument>;
142
185
  }
186
+ /**
187
+ * Result of creating a notification document pair (document reference + data), before or after saving.
188
+ */
143
189
  export interface CreateNotificationDocumentPairResult extends Pick<CreateNotificationTemplate, 'overrideExistingTask'> {
144
190
  readonly notificationDocument: NotificationDocument;
145
191
  readonly notification: Notification;
@@ -153,11 +199,14 @@ export interface CreateNotificationDocumentPairResult extends Pick<CreateNotific
153
199
  readonly isNotificationTask: boolean;
154
200
  }
155
201
  /**
156
- * Creates a CreateNotificationDocumentPairResult from the input.
202
+ * Creates a notification document reference and builds the {@link Notification} data, but does NOT save to Firestore.
203
+ *
204
+ * Use {@link createNotificationDocument} to both create and save in one step.
157
205
  *
158
- * Only creates a pair. Used createNotificationDocument() to also save the document's data.
206
+ * For unique task notifications, generates a deterministic document ID from the target model and task type.
159
207
  *
160
- * @param template
208
+ * @throws {Error} When neither an accessor nor sufficient context is provided
209
+ * @throws {Error} When `unique=true` but no target model is specified
161
210
  */
162
211
  export declare function createNotificationDocumentPair(input: CreateNotificationDocumentPairInput): CreateNotificationDocumentPairResult;
163
212
  /**
@@ -165,15 +214,15 @@ export declare function createNotificationDocumentPair(input: CreateNotification
165
214
  */
166
215
  export declare function _createNotificationDocumentFromPair(input: Pick<CreateNotificationDocumentPairInput, 'shouldCreateNotification' | keyof ShouldSendCreatedNotificationInput>, pair: CreateNotificationDocumentPairResult): Promise<CreateNotificationDocumentPairResult>;
167
216
  /**
168
- * Creates a new Notification and saves it to Firestore. Returns the pair.
217
+ * Creates a new {@link Notification} document and saves it to Firestore.
169
218
  *
170
- * @param input
219
+ * For unique tasks with `overrideExistingTask`, uses `set()` to replace existing documents.
220
+ * Otherwise uses `create()` which fails if the document already exists.
171
221
  */
172
222
  export declare function createNotificationDocument(input: CreateNotificationDocumentPairInput): Promise<CreateNotificationDocumentPairResult>;
173
223
  /**
174
- * Creates a new Notification and saves it to Firestore and returns the pair if sendNotification in the input is not false.
224
+ * Creates and saves a notification only if sending conditions are met (not throttled, not explicitly disabled).
175
225
  *
176
- * @param input
177
- * @returns
226
+ * Returns `undefined` if the notification was not created.
178
227
  */
179
228
  export declare function createNotificationDocumentIfSending(input: CreateNotificationDocumentPairInput): Promise<Maybe<CreateNotificationDocumentPairResult>>;
@@ -1,10 +1,22 @@
1
+ /**
2
+ * @module notification.create.task
3
+ *
4
+ * Convenience factory for creating task-type notification templates.
5
+ * Wraps {@link createNotificationTemplate} with task-specific defaults.
6
+ */
1
7
  import { type Maybe } from '@dereekb/util';
2
8
  import { type NotificationTaskCheckpointString } from './notification';
3
9
  import { type CreateNotificationTemplate, type CreateNotificationTemplateInput } from './notification.create';
4
10
  /**
5
- * Template use for creating a new Notification task.
11
+ * Template for creating a task-type {@link Notification}. Alias for {@link CreateNotificationTemplate}.
6
12
  */
7
13
  export type CreateNotificationTaskTemplate = CreateNotificationTemplate;
14
+ /**
15
+ * Simplified input for creating task notification templates. Omits fields not applicable to tasks
16
+ * (recipients, send type, recipient flags) and makes `notificationModel` optional.
17
+ *
18
+ * When `notificationModel` is omitted, defaults to {@link DEFAULT_NOTIFICATION_TASK_NOTIFICATION_MODEL_KEY}.
19
+ */
8
20
  export interface CreateNotificationTaskTemplateInput extends Omit<CreateNotificationTemplateInput, 'notificationModel' | 'st' | 'recipients' | 'r' | 'rf' | 'sendType' | 'st'>, Partial<Pick<CreateNotificationTemplateInput, 'notificationModel'>> {
9
21
  /**
10
22
  * Corresponds with the tpr field in the Notification.
@@ -14,9 +26,18 @@ export interface CreateNotificationTaskTemplateInput extends Omit<CreateNotifica
14
26
  readonly completedCheckpoints?: Maybe<NotificationTaskCheckpointString[]>;
15
27
  }
16
28
  /**
17
- * Creates a notification template for a Notification with the task type.
29
+ * Creates a {@link CreateNotificationTaskTemplate} with `TASK_NOTIFICATION` send type and no recipients.
30
+ *
31
+ * @throws {Error} When `unique=true` but no `notificationModel` or target model is specified.
18
32
  *
19
- * @param input
20
- * @returns
33
+ * @example
34
+ * ```ts
35
+ * const template = createNotificationTaskTemplate({
36
+ * type: 'generate-report',
37
+ * targetModel: 'project/abc123',
38
+ * unique: true,
39
+ * data: { reportType: 'monthly' }
40
+ * });
41
+ * ```
21
42
  */
22
43
  export declare function createNotificationTaskTemplate(input: CreateNotificationTaskTemplateInput): CreateNotificationTaskTemplate;