@dereekb/firebase 13.2.2 → 13.3.0

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,3 +1,20 @@
1
+ /**
2
+ * @module notification
3
+ *
4
+ * Core notification model types and Firestore collection definitions for the multi-channel notification system.
5
+ *
6
+ * The notification system is built around five Firestore document types organized in a hierarchy:
7
+ *
8
+ * - {@link NotificationUser} — Per-user notification preferences and box subscriptions (top-level collection)
9
+ * - {@link NotificationSummary} — Aggregated notification items for a model, identified by two-way flat key (top-level collection)
10
+ * - {@link NotificationBox} — Root notification container for a model, holds recipients and spawns child notifications (top-level collection)
11
+ * - {@link Notification} — Individual notification or async task, child of NotificationBox (subcollection)
12
+ * - {@link NotificationWeek} — Weekly archive of sent notification items, child of NotificationBox (subcollection)
13
+ *
14
+ * Server-side processing is handled by the `NotificationServerActions` service in `@dereekb/firebase-server/model`.
15
+ *
16
+ * @see {@link NotificationFirestoreCollections} for the abstract collection accessor class
17
+ */
1
18
  import { type E164PhoneNumber, type EmailAddress, type Maybe, type NeedsSyncBoolean } from '@dereekb/util';
2
19
  import { type GrantedReadRole, type GrantedUpdateRole } from '@dereekb/model';
3
20
  import { type NotificationBoxSendExclusionList, type NotificationBoxId } from './notification.id';
@@ -6,6 +23,14 @@ import { type YearWeekCode } from '@dereekb/date';
6
23
  import { type UserRelatedById, type UserRelated } from '../user';
7
24
  import { AbstractFirestoreDocument, AbstractFirestoreDocumentWithParent, type CollectionGroup, type CollectionReference, type FirestoreCollection, type FirestoreCollectionGroup, type FirestoreCollectionWithParent, type FirestoreContext, type FirestoreModelKey, type SavedToFirestoreIfTrue, type SavedToFirestoreIfFalse } from '../../common';
8
25
  import { type NotificationItem } from './notification.item';
26
+ /**
27
+ * Abstract class providing access to all notification-related Firestore collections.
28
+ *
29
+ * Implementations provide concrete collection instances wired to a specific {@link FirestoreContext}.
30
+ * Used by both client and server code to access notification documents.
31
+ *
32
+ * @see `NotificationServerActions` in `@dereekb/firebase-server/model` for server-side action processing
33
+ */
9
34
  export declare abstract class NotificationFirestoreCollections {
10
35
  abstract readonly notificationUserCollection: NotificationUserFirestoreCollection;
11
36
  abstract readonly notificationSummaryCollection: NotificationSummaryFirestoreCollection;
@@ -15,6 +40,9 @@ export declare abstract class NotificationFirestoreCollections {
15
40
  abstract readonly notificationWeekCollectionFactory: NotificationWeekFirestoreCollectionFactory;
16
41
  abstract readonly notificationWeekCollectionGroup: NotificationWeekFirestoreCollectionGroup;
17
42
  }
43
+ /**
44
+ * Union of all notification model identity types, used for type-safe identity discrimination.
45
+ */
18
46
  export type NotificationTypes = typeof notificationUserIdentity | typeof notificationSummaryIdentity | typeof notificationBoxIdentity | typeof notificationIdentity | typeof notificationWeekIdentity;
19
47
  /**
20
48
  * Notification-related model that is initialized asynchronously at a later time.
@@ -39,48 +67,54 @@ export interface InitializedNotificationModel {
39
67
  }
40
68
  export declare const notificationUserIdentity: import("../..").RootFirestoreModelIdentity<"notificationUser", "nu">;
41
69
  /**
42
- * A global notification User in the system.
70
+ * A global notification user profile that tracks notification preferences and box subscriptions.
71
+ *
72
+ * Each user in the notification system has a single NotificationUser document (keyed by uid) that stores:
73
+ * - Which {@link NotificationBox} instances they are subscribed to (`b`)
74
+ * - Per-box, direct/default, and global notification preferences (`bc`, `dc`, `gc`)
75
+ * - Box exclusions for temporary opt-outs (`x`)
43
76
  *
44
- * Keeps track of the NotificationBoxes the user is subscribed to, as well as other global subscriptions.
77
+ * Created automatically when a user is first added as a recipient to any {@link NotificationBox}.
78
+ * Configuration changes here propagate to the corresponding NotificationBox recipient entries during sync.
45
79
  *
46
- * The NotificationUser is created automatically by the NotificationBox as a user is created.
80
+ * @see {@link NotificationBoxRecipient} for the per-box recipient entry that mirrors these configs
81
+ * @see `NotificationServerActions.updateNotificationUser` in `@dereekb/firebase-server/model` for server-side sync logic
47
82
  */
48
83
  export interface NotificationUser extends UserRelated, UserRelatedById {
49
84
  /**
50
- * List of notification boxes this user is associated with. Cannot be changed directly.
85
+ * Notification box IDs this user is subscribed to. Managed by the server — not directly editable by clients.
51
86
  */
52
87
  b: NotificationBoxId[];
53
88
  /**
54
- * Notification box id exclusion list. This value is treated used to generated send opt-outs.
89
+ * Box exclusion list. Entries cause the user to be excluded from receiving notifications from matching boxes.
55
90
  *
56
- * This list is used to exclude a user from recieving notifications from the NotificationBoxes in this list.
91
+ * Supports prefix matching: excluding `ab_123` also excludes child boxes like `ab_123_cd_456`.
92
+ * Populated by server-side model logic (e.g., when a user loses access to a resource).
93
+ * Exclusions are synced to the corresponding `bc` configs, which then propagate to the NotificationBoxes.
57
94
  *
58
- * Values in this list are usually populated from functions from the model controlling the NotificationBox.
59
- *
60
- * The user must be associated with atleast one NotificationBoxId that matches items in this list, otherwise non-matching items are removed.
61
- *
62
- * The exclusions are sync'd to the corresponding bc values, which are then sync'd to the NotificationBoxes.
95
+ * Non-matching entries (where the user isn't associated with a matching box) are automatically removed.
63
96
  */
64
97
  x: NotificationBoxSendExclusionList;
65
98
  /**
66
- * Global config override.
99
+ * Global config override. Overrides all other configs (both per-box `bc` and direct/default `dc`) at send time.
67
100
  *
68
- * This config effectively overrides all other configs, both NotificationBox configs and direct/default configs when used.
69
- * It does not however get copied to dc/bc when updated.
101
+ * Unlike `dc`/`bc`, changes to `gc` are NOT copied to other config fields they apply as a final override during notification delivery.
70
102
  */
71
103
  gc: NotificationUserDefaultNotificationBoxRecipientConfig;
72
104
  /**
73
- * Direct/default config.
105
+ * Direct/default config. Used when a recipient is added ad-hoc (by uid) to a notification that isn't associated with any of their subscribed boxes.
74
106
  *
75
- * This config is retrieved and used for cases where the recipient isn't associated with the NotificationBox but was added on an ad-hoc basis as an additional user as a uid.
107
+ * Acts as the fallback config when no per-box config (`bc`) matches.
76
108
  */
77
109
  dc: NotificationUserDefaultNotificationBoxRecipientConfig;
78
110
  /**
79
- * List of NotificationBox configurations.
111
+ * Per-box recipient configurations. Each entry corresponds to one of the user's subscribed notification boxes.
112
+ *
113
+ * These configs are synced bidirectionally with the {@link NotificationBoxRecipient} entries on the corresponding {@link NotificationBox}.
80
114
  */
81
115
  bc: NotificationUserNotificationBoxRecipientConfig[];
82
116
  /**
83
- * Whether or not the user has one or more configs that need to be synced.
117
+ * Whether one or more configs need to be synced to their corresponding NotificationBox recipients.
84
118
  */
85
119
  ns?: Maybe<NeedsSyncBoolean>;
86
120
  }
@@ -88,12 +122,24 @@ export type NotificationUserRoles = 'sync' | GrantedUpdateRole | GrantedReadRole
88
122
  export declare class NotificationUserDocument extends AbstractFirestoreDocument<NotificationUser, NotificationUserDocument, typeof notificationUserIdentity> {
89
123
  get modelIdentity(): import("../..").RootFirestoreModelIdentity<"notificationUser", "nu">;
90
124
  }
125
+ /**
126
+ * Firestore snapshot converter for {@link NotificationUser} documents.
127
+ */
91
128
  export declare const notificationUserConverter: import("../..").SnapshotConverterFunctions<NotificationUser, Partial<import("@dereekb/util").ReplaceType<NotificationUser, import("@dereekb/util").MaybeMap<object>, any>>>;
129
+ /**
130
+ * Creates a Firestore collection reference for {@link NotificationUser} documents.
131
+ */
92
132
  export declare function notificationUserCollectionReference(context: FirestoreContext): CollectionReference<NotificationUser>;
133
+ /**
134
+ * Typed Firestore collection for {@link NotificationUser} documents.
135
+ */
93
136
  export type NotificationUserFirestoreCollection = FirestoreCollection<NotificationUser, NotificationUserDocument>;
137
+ /**
138
+ * Creates a typed {@link NotificationUserFirestoreCollection} bound to the given Firestore context.
139
+ */
94
140
  export declare function notificationUserFirestoreCollection(firestoreContext: FirestoreContext): NotificationUserFirestoreCollection;
95
141
  /**
96
- * An arbitrary summary object
142
+ * Identity for {@link NotificationSummary} documents. Collection name: `'notificationSummary'`, short code: `'ns'`.
97
143
  */
98
144
  export declare const notificationSummaryIdentity: import("../..").RootFirestoreModelIdentity<"notificationSummary", "ns">;
99
145
  /**
@@ -109,41 +155,41 @@ export declare const NOTIFICATION_SUMMARY_EMBEDDED_NOTIFICATION_ITEM_SUBJECT_MAX
109
155
  */
110
156
  export declare const NOTIFICATION_SUMMARY_EMBEDDED_NOTIFICATION_ITEM_MESSAGE_MAX_LENGTH = 500;
111
157
  /**
112
- * Used to hold arbitrary NotificationItems in the system for an object. The id for this is the two-way flat key of the object it represents.
158
+ * Aggregated notification feed for a specific model. Holds embedded {@link NotificationItem} entries
159
+ * that summarize recent notifications, similar to an activity feed.
113
160
  *
114
- * Notification Items can be delivered here.
161
+ * The document ID is a two-way flat key derived from the model it represents (see {@link notificationSummaryIdForModel}).
162
+ * Items are capped at {@link NOTIFICATION_SUMMARY_ITEM_LIMIT} entries.
163
+ *
164
+ * Implements {@link InitializedNotificationModel} — requires server-side initialization to populate the owner (`o`) field.
115
165
  */
116
166
  export interface NotificationSummary extends InitializedNotificationModel {
117
167
  /**
118
- * Notification Summary creation date
168
+ * Creation date of this summary document.
119
169
  */
120
170
  cat: Date;
121
171
  /**
122
- * Model key of the model this box is assigned to.
172
+ * Model key of the model this summary represents (e.g., `'project/abc123'`).
123
173
  */
124
174
  m: FirestoreModelKey;
125
175
  /**
126
- * Owner model key of the model this box is assigned to.
127
- *
128
- * Is created with a dummy value until it is initialized.
176
+ * Owner model key. Set to a dummy value on creation and populated during server-side initialization.
129
177
  */
130
178
  o: FirestoreModelKey;
131
179
  /**
132
- * Notification items.
133
- *
134
- * They are sorted in ascending order, with the newest items at the end.
180
+ * Embedded notification items, sorted ascending by date (newest at end).
135
181
  */
136
182
  n: NotificationItem[];
137
183
  /**
138
- * Date of the latest notification.
184
+ * Timestamp of the most recently added notification item.
139
185
  */
140
186
  lat?: Maybe<Date>;
141
187
  /**
142
- * Date of the last read at time so notifications can be marked as read.
188
+ * Timestamp of when the user last read this summary. Items with dates after this are considered unread.
143
189
  */
144
190
  rat?: Maybe<Date>;
145
191
  /**
146
- * True if this NotificationSummary needs to be sync'd/initialized with the original model.
192
+ * Whether this summary needs server-side sync/initialization with its source model.
147
193
  */
148
194
  s?: Maybe<NeedsSyncBoolean>;
149
195
  }
@@ -154,56 +200,73 @@ export type NotificationSummaryRoles = GrantedReadRole;
154
200
  export declare class NotificationSummaryDocument extends AbstractFirestoreDocument<NotificationSummary, NotificationSummaryDocument, typeof notificationSummaryIdentity> {
155
201
  get modelIdentity(): import("../..").RootFirestoreModelIdentity<"notificationSummary", "ns">;
156
202
  }
203
+ /**
204
+ * Firestore snapshot converter for {@link NotificationSummary} documents.
205
+ */
157
206
  export declare const notificationSummaryConverter: import("../..").SnapshotConverterFunctions<NotificationSummary, Partial<import("@dereekb/util").ReplaceType<NotificationSummary, import("@dereekb/util").MaybeMap<object>, any>>>;
207
+ /**
208
+ * Creates a Firestore collection reference for {@link NotificationSummary} documents.
209
+ */
158
210
  export declare function notificationSummaryCollectionReference(context: FirestoreContext): CollectionReference<NotificationSummary>;
211
+ /**
212
+ * Typed Firestore collection for {@link NotificationSummary} documents.
213
+ */
159
214
  export type NotificationSummaryFirestoreCollection = FirestoreCollection<NotificationSummary, NotificationSummaryDocument>;
215
+ /**
216
+ * Creates a typed {@link NotificationSummaryFirestoreCollection} bound to the given Firestore context.
217
+ */
160
218
  export declare function notificationSummaryFirestoreCollection(firestoreContext: FirestoreContext): NotificationSummaryFirestoreCollection;
219
+ /**
220
+ * Identity for {@link NotificationBox} documents. Collection name: `'notificationBox'`, short code: `'nb'`.
221
+ */
161
222
  export declare const notificationBoxIdentity: import("../..").RootFirestoreModelIdentity<"notificationBox", "nb">;
162
223
  /**
163
- * A Notification Box in the system for an object. The id for this is the two-way flat key of the object it represents.
224
+ * Root notification container for a model. The document ID is the two-way flat key of the model it represents
225
+ * (see {@link notificationBoxIdForModel} in `notification.id.ts`).
226
+ *
227
+ * A NotificationBox is the parent collection for {@link Notification} and {@link NotificationWeek} subcollections.
228
+ * It holds the list of recipients (`r`) who receive notifications, and tracks which notification template types
229
+ * are available via the application's `NotificationTemplateTypeInfoRecord`.
164
230
  *
165
- * This object is the root collection for notifications for the corresponding object.
231
+ * Recipient configs are synced from the corresponding {@link NotificationUser} documents.
166
232
  *
167
- * Additional information about what notification templates are available to this type are available on a per-application basis, typically through the
168
- * NotificationTemplateTypeInfoRecord configured for the app.
233
+ * Implements {@link InitializedNotificationModel} requires server-side initialization to populate the owner (`o`) field.
169
234
  *
170
- * Update to each recipient is propogated from NotificationUser values.
235
+ * @see {@link NotificationBoxRecipient} for per-recipient configuration embedded in this document
236
+ * @see `NotificationServerActions.createNotificationBox` in `@dereekb/firebase-server/model` for creation logic
171
237
  */
172
238
  export interface NotificationBox extends InitializedNotificationModel {
173
239
  /**
174
- * Notification Box creation date
240
+ * Creation date of this NotificationBox document.
175
241
  */
176
242
  cat: Date;
177
243
  /**
178
- * Model key of the model this box is assigned to.
244
+ * Model key of the model this box is assigned to (e.g., `'project/abc123'`).
179
245
  */
180
246
  m: FirestoreModelKey;
181
247
  /**
182
- * Owner model key of the model this box is assigned to.
183
- *
184
- * Is created with a dummy value until it is initialized.
248
+ * Owner model key. Set to a dummy value on creation and populated during server-side initialization.
185
249
  */
186
250
  o: FirestoreModelKey;
187
251
  /**
188
- * Embedded recipients.
252
+ * Embedded recipient entries. Each entry represents a user who can receive notifications from this box.
253
+ *
254
+ * Synced from the corresponding {@link NotificationUser} `bc` configs.
189
255
  */
190
256
  r: NotificationBoxRecipient[];
191
257
  /**
192
- * Latest week.
258
+ * Year-week code of the latest {@link NotificationWeek} subcollection document.
193
259
  */
194
260
  w: YearWeekCode;
195
261
  /**
196
- * True if this NotificationBox needs to be sync'd/initialized with the original model.
197
- *
198
- * Is set false if/when "fi" is set true.
262
+ * Whether this box needs server-side sync/initialization with its source model.
263
+ * Cleared when `fi` is set true (flagged invalid).
199
264
  */
200
265
  s?: Maybe<NeedsSyncBoolean>;
201
266
  /**
202
- * True if this NotificationBox has been flagged invalid.
203
- *
204
- * This is for cases where the NotificationBox cannot be properly initiialized.
267
+ * Flagged invalid set when the box cannot be properly initialized (e.g., source model deleted).
205
268
  *
206
- * NOTE: The server can also be configured to automatically delete matching boxes instead of marking them as invalid.
269
+ * The server can be configured to either flag or auto-delete invalid boxes.
207
270
  */
208
271
  fi?: Maybe<SavedToFirestoreIfTrue>;
209
272
  }
@@ -218,11 +281,32 @@ export declare class NotificationBoxDocument extends AbstractFirestoreDocument<N
218
281
  get modelIdentity(): import("../..").RootFirestoreModelIdentity<"notificationBox", "nb">;
219
282
  get notificationBoxRelatedModelKey(): string;
220
283
  }
284
+ /**
285
+ * Firestore snapshot converter for {@link NotificationBox} documents.
286
+ */
221
287
  export declare const notificationBoxConverter: import("../..").SnapshotConverterFunctions<NotificationBox, Partial<import("@dereekb/util").ReplaceType<NotificationBox, import("@dereekb/util").MaybeMap<object>, any>>>;
288
+ /**
289
+ * Creates a Firestore collection reference for {@link NotificationBox} documents.
290
+ */
222
291
  export declare function notificationBoxCollectionReference(context: FirestoreContext): CollectionReference<NotificationBox>;
292
+ /**
293
+ * Typed Firestore collection for {@link NotificationBox} documents.
294
+ */
223
295
  export type NotificationBoxFirestoreCollection = FirestoreCollection<NotificationBox, NotificationBoxDocument>;
296
+ /**
297
+ * Creates a typed {@link NotificationBoxFirestoreCollection} bound to the given Firestore context.
298
+ */
224
299
  export declare function notificationBoxFirestoreCollection(firestoreContext: FirestoreContext): NotificationBoxFirestoreCollection;
300
+ /**
301
+ * Identity for {@link Notification} documents. Subcollection of {@link NotificationBox}. Collection name: `'notification'`, short code: `'nbn'`.
302
+ */
225
303
  export declare const notificationIdentity: import("../..").FirestoreModelIdentityWithParent<import("../..").RootFirestoreModelIdentity<"notificationBox", "nb">, "notification", "nbn">;
304
+ /**
305
+ * Controls how a {@link Notification} interacts with its parent {@link NotificationBox} during delivery.
306
+ *
307
+ * Determines whether the box must exist, should be created on demand, or can be bypassed entirely.
308
+ * Task-type notifications (`TASK_NOTIFICATION`) bypass the box system and run async workflows instead.
309
+ */
226
310
  export declare enum NotificationSendType {
227
311
  /**
228
312
  * Sends only if the NotificationBox exists.
@@ -245,6 +329,16 @@ export declare enum NotificationSendType {
245
329
  */
246
330
  TASK_NOTIFICATION = 3
247
331
  }
332
+ /**
333
+ * Lifecycle state of a notification delivery channel (text, email, push, or summary).
334
+ *
335
+ * Each channel on a {@link Notification} tracks its own send state independently via {@link NotificationSendFlags}.
336
+ *
337
+ * State transitions:
338
+ * - `QUEUED` → `SENT` (success) | `SENT_PARTIAL` (partial success) | `SEND_ERROR` | `BUILD_ERROR` | `CONFIG_ERROR`
339
+ * - `QUEUED` → `SKIPPED` (box settings) | `NO_TRY` (permanently skipped)
340
+ * - `NONE` indicates the channel was never queued for this notification
341
+ */
248
342
  export declare enum NotificationSendState {
249
343
  /**
250
344
  * Notification will not be sent.
@@ -308,25 +402,28 @@ export declare enum NotificationRecipientSendFlag {
308
402
  */
309
403
  ONLY_GLOBAL_RECIPIENTS = 4
310
404
  }
405
+ /**
406
+ * Per-channel delivery state flags on a {@link Notification}. Each field tracks the send state for one delivery channel independently.
407
+ */
311
408
  export interface NotificationSendFlags {
312
409
  /**
313
- * Text send state
410
+ * Text/SMS send state.
314
411
  */
315
412
  ts: NotificationSendState;
316
413
  /**
317
- * Email send state
414
+ * Email send state.
318
415
  */
319
416
  es: NotificationSendState;
320
417
  /**
321
- * Push notification send state
418
+ * Push notification send state.
322
419
  */
323
420
  ps: NotificationSendState;
324
421
  /**
325
- * Notification summary send state
422
+ * In-app notification summary send state (delivery to {@link NotificationSummary}).
326
423
  */
327
424
  ns: NotificationSendState;
328
425
  /**
329
- * Push notification recipient send flag. Determines who will recieve the notifications, and if it should be saved to the NotificationWeek once sent.
426
+ * Recipient send flag controlling who receives this notification and whether it should be archived to {@link NotificationWeek} after delivery.
330
427
  */
331
428
  rf?: Maybe<NotificationRecipientSendFlag>;
332
429
  }
@@ -335,98 +432,104 @@ export interface NotificationSendFlags {
335
432
  */
336
433
  export type NotificationTaskCheckpointString = string;
337
434
  /**
338
- * Contains information about which recipients were already sent their messages, etc.
435
+ * Tracks delivery progress for a {@link Notification} to enable idempotent retries.
436
+ *
437
+ * Stores which recipients have already been contacted via each channel, plus task checkpoint progress.
438
+ * The server checks these sets before re-sending to avoid duplicate deliveries.
339
439
  */
340
440
  export interface NotificationSendCheckpoints {
341
441
  /**
342
- * Set of numbers the notification was sent to via text/sms.
442
+ * Phone numbers that have already received the text/SMS for this notification.
343
443
  */
344
444
  tsr: E164PhoneNumber[];
345
445
  /**
346
- * Set of emails that the notification was set to via email.
446
+ * Email addresses that have already received the email for this notification.
347
447
  */
348
448
  esr: EmailAddress[];
349
449
  /**
350
- * Set of checkpoint strings that denote checkpoint progress for a task.
450
+ * Completed checkpoint strings for multi-step task notifications.
351
451
  *
352
- * Used for multi-step tasks.
452
+ * @see {@link NotificationTaskCheckpointString}
353
453
  */
354
454
  tpr: NotificationTaskCheckpointString[];
355
455
  }
456
+ /**
457
+ * Individual notification document, stored as a subcollection of {@link NotificationBox}.
458
+ *
459
+ * Represents either a standard multi-channel notification or an async task notification, depending on the {@link NotificationSendType}.
460
+ * Standard notifications are delivered via text, email, push, and/or in-app summary channels.
461
+ * Task notifications run server-side async workflows with checkpoint-based progress tracking.
462
+ *
463
+ * After all channels are delivered, the notification is marked as done (`d = true`), its content is archived
464
+ * to a {@link NotificationWeek} document, and the notification document is deleted.
465
+ *
466
+ * @see {@link NotificationSendFlags} for per-channel delivery state
467
+ * @see {@link NotificationSendCheckpoints} for idempotent retry tracking
468
+ * @see `NotificationServerActions.sendQueuedNotifications` in `@dereekb/firebase-server/model` for the send pipeline
469
+ */
356
470
  export interface Notification extends NotificationSendFlags, NotificationSendCheckpoints {
357
471
  /**
358
- * Created at date/time
472
+ * Creation timestamp.
359
473
  */
360
474
  cat: Date;
361
475
  /**
362
- * Send type
476
+ * Send type controlling how this notification interacts with its parent NotificationBox.
363
477
  */
364
478
  st: NotificationSendType;
365
479
  /**
366
- * Notification item
480
+ * Embedded notification content (subject, message, template type, metadata).
367
481
  */
368
482
  n: NotificationItem;
369
483
  /**
370
- * Additional embedded recipients.
484
+ * Additional per-notification recipients with inline config overrides.
371
485
  *
372
- * Any values for the NotificationBoxRecipientTemplateConfig-related parameters will be used when considering explicit opt-in/op-out.
373
- * (I.E. setting "st" to true for a user with no other config for the notification template type will mark them as opt-in for texts, and
374
- * can only be overridden by the user's own config)
486
+ * Any `NotificationBoxRecipientTemplateConfig` values on these recipients affect opt-in/opt-out resolution.
487
+ * For example, setting `st: true` opts a user into text/SMS for this notification's template type,
488
+ * unless overridden by the user's own {@link NotificationUser} config.
375
489
  */
376
490
  r: NotificationRecipientWithConfig[];
377
491
  /**
378
- * Explicit opt-in send only.
379
- *
380
- * If true, will only send to users that have explicitly opted in to recieving notifications via specific methods.
492
+ * Explicit opt-in send only. When true, only sends to users who have explicitly opted in for each channel.
381
493
  *
382
- * This setting takes priority over the system's configured default for this notification's template type.
494
+ * Overrides the system-level default for this notification's template type.
383
495
  */
384
496
  ois?: Maybe<SavedToFirestoreIfTrue>;
385
497
  /**
386
- * Explicit opt-in text/sms send only.
498
+ * Opt-in text/SMS override. When false, sends text/SMS to all users even if they haven't explicitly opted in
499
+ * (still respects explicit opt-outs).
387
500
  *
388
- * If false, will send text/sms to all users regardless if they have not explicitly opted in to text/sms. Will still take their opt-out into account.
389
- *
390
- * This setting takes priority over the system's configured default for this notification's template type.
501
+ * Overrides the system-level default for this notification's template type.
391
502
  */
392
503
  ots?: Maybe<SavedToFirestoreIfFalse>;
393
504
  /**
394
- * Minimum time at which this notification should be sent.
395
- *
396
- * The notification is only guranteed to be sent after this time.
505
+ * Scheduled send time. The notification is guaranteed to be sent only after this time.
397
506
  *
398
- * This value is also used for locking/retrying. When locked for sending it is updated to push sat back a few minutes and increase the send attempts.
507
+ * Also serves as a lock mechanism: during active sending, `sat` is pushed forward by a few minutes
508
+ * and the attempt counter is incremented, preventing concurrent send attempts.
399
509
  */
400
510
  sat: Date;
401
511
  /**
402
- * Total sending attempts count.
403
- *
404
- * Only incremented when sending encounters an issue/error.
512
+ * Total error attempt count. Incremented only when sending encounters an error (not on success).
405
513
  */
406
514
  a: number;
407
515
  /**
408
- * Current task sending and delays attempts count.
409
- *
410
- * Only incremented when sending returns a delay or a failure for the current task checkpoint.
516
+ * Current task attempt count for the active checkpoint. Incremented on delay or failure responses.
411
517
  *
412
- * Reset when a non-failure is returned, and when a checkpoint is completed.
518
+ * Reset to 0 when a checkpoint completes successfully or when a new checkpoint begins.
413
519
  */
414
520
  at?: Maybe<number>;
415
521
  /**
416
- * Notification has been delivered or should be archived.
522
+ * Delivery complete flag. When true, content has been delivered and is ready to archive to {@link NotificationWeek}.
417
523
  *
418
- * This is now safe to sync to the NotificationWeek (not applicable for task-type notifications) and then delete this.
419
- *
420
- * For Task-type notifications, this is always set to false, as when the task is completed it is deleted.
524
+ * For task-type notifications this is always false tasks are deleted upon completion instead of archived.
421
525
  */
422
526
  d: boolean;
423
527
  /**
424
- * Unique Notification Task flag
425
- *
426
- * Only used for tasks.
528
+ * Unique task flag. Only used for task-type notifications.
427
529
  *
428
- * If flagged true, this task will be re-read and compared with the created at time before a task step is saved/completed when running the task.
429
- * If the created at time is different, the task changes are abandoned, and a success is returned.
530
+ * When true, the server re-reads the document and compares `cat` before committing a task step.
531
+ * If `cat` has changed (indicating the task was replaced), the step is abandoned silently.
532
+ * This prevents stale task executions when a unique task ID is reused.
430
533
  */
431
534
  ut?: Maybe<SavedToFirestoreIfTrue>;
432
535
  }
@@ -435,29 +538,61 @@ export type NotificationRoles = GrantedReadRole | GrantedUpdateRole | Notificati
435
538
  export declare class NotificationDocument extends AbstractFirestoreDocumentWithParent<NotificationBox, Notification, NotificationDocument, typeof notificationIdentity> {
436
539
  get modelIdentity(): import("../..").FirestoreModelIdentityWithParent<import("../..").RootFirestoreModelIdentity<"notificationBox", "nb">, "notification", "nbn">;
437
540
  }
541
+ /**
542
+ * Firestore snapshot converter for {@link Notification} documents.
543
+ */
438
544
  export declare const notificationConverter: import("../..").SnapshotConverterFunctions<Notification, Partial<import("@dereekb/util").ReplaceType<Notification, import("@dereekb/util").MaybeMap<object>, any>>>;
545
+ /**
546
+ * Creates a factory that produces {@link Notification} subcollection references for a given {@link NotificationBoxDocument} parent.
547
+ */
439
548
  export declare function notificationCollectionReferenceFactory(context: FirestoreContext): (notificationBox: NotificationBoxDocument) => CollectionReference<Notification>;
549
+ /**
550
+ * Typed Firestore subcollection for {@link Notification} documents under a {@link NotificationBox} parent.
551
+ */
440
552
  export type NotificationFirestoreCollection = FirestoreCollectionWithParent<Notification, NotificationBox, NotificationDocument, NotificationBoxDocument>;
553
+ /**
554
+ * Factory function that creates a {@link NotificationFirestoreCollection} for a given {@link NotificationBoxDocument} parent.
555
+ */
441
556
  export type NotificationFirestoreCollectionFactory = (parent: NotificationBoxDocument) => NotificationFirestoreCollection;
557
+ /**
558
+ * Creates a {@link NotificationFirestoreCollectionFactory} bound to the given Firestore context.
559
+ */
442
560
  export declare function notificationFirestoreCollectionFactory(firestoreContext: FirestoreContext): NotificationFirestoreCollectionFactory;
561
+ /**
562
+ * Creates a collection group reference for querying all {@link Notification} documents across all {@link NotificationBox} parents.
563
+ */
443
564
  export declare function notificationCollectionReference(context: FirestoreContext): CollectionGroup<Notification>;
565
+ /**
566
+ * Typed collection group for querying {@link Notification} documents across all parents.
567
+ */
444
568
  export type NotificationFirestoreCollectionGroup = FirestoreCollectionGroup<Notification, NotificationDocument>;
569
+ /**
570
+ * Creates a typed {@link NotificationFirestoreCollectionGroup} bound to the given Firestore context.
571
+ */
445
572
  export declare function notificationFirestoreCollectionGroup(firestoreContext: FirestoreContext): NotificationFirestoreCollectionGroup;
573
+ /**
574
+ * Identity for {@link NotificationWeek} documents. Subcollection of {@link NotificationBox}. Collection name: `'notificationWeek'`, short code: `'nbnw'`.
575
+ */
446
576
  export declare const notificationWeekIdentity: import("../..").FirestoreModelIdentityWithParent<import("../..").RootFirestoreModelIdentity<"notificationBox", "nb">, "notificationWeek", "nbnw">;
447
577
  /**
448
578
  * The maximum number of notifications that can be stored in a NotificationWeek.
449
579
  */
450
580
  export declare const NOTIFICATION_WEEK_NOTIFICATION_ITEM_LIMIT = 5000;
451
581
  /**
452
- * Notification week. Contains all notifications in the box for the given week.
582
+ * Weekly archive of delivered notification items within a {@link NotificationBox}.
583
+ *
584
+ * The document ID is the {@link YearWeekCode} string (same as the `w` field). Items are appended after
585
+ * a {@link Notification} completes delivery and is cleaned up. Capped at {@link NOTIFICATION_WEEK_NOTIFICATION_ITEM_LIMIT} items.
586
+ *
587
+ * Used for historical browsing of past notifications per box.
453
588
  */
454
589
  export interface NotificationWeek {
455
590
  /**
456
- * YearWeekCode value. Same as the id.
591
+ * Year-week code identifying this week. Matches the document ID.
457
592
  */
458
593
  w: YearWeekCode;
459
594
  /**
460
- * Notification items.
595
+ * Archived notification items delivered during this week.
461
596
  */
462
597
  n: NotificationItem[];
463
598
  }
@@ -465,11 +600,35 @@ export type NotificationWeekRoles = GrantedReadRole;
465
600
  export declare class NotificationWeekDocument extends AbstractFirestoreDocumentWithParent<NotificationBox, NotificationWeek, NotificationWeekDocument, typeof notificationWeekIdentity> {
466
601
  get modelIdentity(): import("../..").FirestoreModelIdentityWithParent<import("../..").RootFirestoreModelIdentity<"notificationBox", "nb">, "notificationWeek", "nbnw">;
467
602
  }
603
+ /**
604
+ * Firestore snapshot converter for {@link NotificationWeek} documents.
605
+ */
468
606
  export declare const notificationWeekConverter: import("../..").SnapshotConverterFunctions<NotificationWeek, Partial<import("@dereekb/util").ReplaceType<NotificationWeek, import("@dereekb/util").MaybeMap<object>, any>>>;
607
+ /**
608
+ * Creates a factory that produces {@link NotificationWeek} subcollection references for a given {@link NotificationBoxDocument} parent.
609
+ */
469
610
  export declare function notificationWeekCollectionReferenceFactory(context: FirestoreContext): (notificationBox: NotificationBoxDocument) => CollectionReference<NotificationWeek>;
611
+ /**
612
+ * Typed Firestore subcollection for {@link NotificationWeek} documents under a {@link NotificationBox} parent.
613
+ */
470
614
  export type NotificationWeekFirestoreCollection = FirestoreCollectionWithParent<NotificationWeek, NotificationBox, NotificationWeekDocument, NotificationBoxDocument>;
615
+ /**
616
+ * Factory function that creates a {@link NotificationWeekFirestoreCollection} for a given {@link NotificationBoxDocument} parent.
617
+ */
471
618
  export type NotificationWeekFirestoreCollectionFactory = (parent: NotificationBoxDocument) => NotificationWeekFirestoreCollection;
619
+ /**
620
+ * Creates a {@link NotificationWeekFirestoreCollectionFactory} bound to the given Firestore context.
621
+ */
472
622
  export declare function notificationWeekFirestoreCollectionFactory(firestoreContext: FirestoreContext): NotificationWeekFirestoreCollectionFactory;
623
+ /**
624
+ * Creates a collection group reference for querying all {@link NotificationWeek} documents across all {@link NotificationBox} parents.
625
+ */
473
626
  export declare function notificationWeekCollectionReference(context: FirestoreContext): CollectionGroup<NotificationWeek>;
627
+ /**
628
+ * Typed collection group for querying {@link NotificationWeek} documents across all parents.
629
+ */
474
630
  export type NotificationWeekFirestoreCollectionGroup = FirestoreCollectionGroup<NotificationWeek, NotificationWeekDocument>;
631
+ /**
632
+ * Creates a typed {@link NotificationWeekFirestoreCollectionGroup} bound to the given Firestore context.
633
+ */
475
634
  export declare function notificationWeekFirestoreCollectionGroup(firestoreContext: FirestoreContext): NotificationWeekFirestoreCollectionGroup;