@dereekb/firebase 11.0.21 → 11.1.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.
- package/index.cjs.js +1881 -93
- package/index.esm.js +2042 -37
- package/package.json +3 -2
- package/src/lib/client/error/error.d.ts +8 -0
- package/src/lib/client/error/index.d.ts +1 -0
- package/src/lib/client/firestore/error.d.ts +1 -0
- package/src/lib/client/firestore/index.d.ts +1 -0
- package/src/lib/client/index.d.ts +1 -0
- package/src/lib/common/firestore/accessor/document.utility.d.ts +4 -0
- package/src/lib/common/firestore/collection/collection.d.ts +6 -1
- package/src/lib/model/index.d.ts +1 -0
- package/src/lib/model/notification/index.d.ts +14 -0
- package/src/lib/model/notification/notification.action.d.ts +24 -0
- package/src/lib/model/notification/notification.api.d.ts +389 -0
- package/src/lib/model/notification/notification.api.error.d.ts +7 -0
- package/src/lib/model/notification/notification.api.util.d.ts +31 -0
- package/src/lib/model/notification/notification.config.d.ts +207 -0
- package/src/lib/model/notification/notification.create.d.ts +139 -0
- package/src/lib/model/notification/notification.d.ts +403 -0
- package/src/lib/model/notification/notification.details.d.ts +98 -0
- package/src/lib/model/notification/notification.id.d.ts +49 -0
- package/src/lib/model/notification/notification.item.d.ts +70 -0
- package/src/lib/model/notification/notification.message.d.ts +152 -0
- package/src/lib/model/notification/notification.query.d.ts +43 -0
- package/src/lib/model/notification/notification.send.d.ts +22 -0
- package/src/lib/model/notification/notification.util.d.ts +51 -0
- package/test/CHANGELOG.md +4 -0
- package/test/package.json +1 -1
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
import { type E164PhoneNumber, type EmailAddress, type Maybe, type NeedsSyncBoolean } from '@dereekb/util';
|
|
2
|
+
import { type GrantedReadRole, type GrantedUpdateRole } from '@dereekb/model';
|
|
3
|
+
import { type NotificationBoxId } from './notification.id';
|
|
4
|
+
import { type NotificationBoxRecipient, type NotificationRecipientWithConfig, type NotificationUserNotificationBoxRecipientConfig, type NotificationUserDefaultNotificationBoxRecipientConfig } from './notification.config';
|
|
5
|
+
import { type YearWeekCode } from '@dereekb/date';
|
|
6
|
+
import { type UserRelatedById, type UserRelated } from '../user';
|
|
7
|
+
import { AbstractFirestoreDocument, AbstractFirestoreDocumentWithParent, type CollectionGroup, type CollectionReference, type FirestoreCollection, type FirestoreCollectionGroup, type FirestoreCollectionWithParent, type FirestoreContext, type FirestoreModelKey, type SavedToFirestoreIfTrue } from '../../common';
|
|
8
|
+
import { type NotificationItem } from './notification.item';
|
|
9
|
+
export declare abstract class NotificationFirestoreCollections {
|
|
10
|
+
abstract readonly notificationUserCollection: NotificationUserFirestoreCollection;
|
|
11
|
+
abstract readonly notificationSummaryCollection: NotificationSummaryFirestoreCollection;
|
|
12
|
+
abstract readonly notificationBoxCollection: NotificationBoxFirestoreCollection;
|
|
13
|
+
abstract readonly notificationCollectionFactory: NotificationFirestoreCollectionFactory;
|
|
14
|
+
abstract readonly notificationCollectionGroup: NotificationFirestoreCollectionGroup;
|
|
15
|
+
abstract readonly notificationWeekCollectionFactory: NotificationWeekFirestoreCollectionFactory;
|
|
16
|
+
abstract readonly notificationWeekCollectionGroup: NotificationWeekFirestoreCollectionGroup;
|
|
17
|
+
}
|
|
18
|
+
export type NotificationTypes = typeof notificationUserIdentity | typeof notificationSummaryIdentity | typeof notificationBoxIdentity | typeof notificationIdentity | typeof notificationWeekIdentity;
|
|
19
|
+
/**
|
|
20
|
+
* Notification-related model that is initialized asynchronously at a later time.
|
|
21
|
+
*/
|
|
22
|
+
export interface InitializedNotificationModel {
|
|
23
|
+
/**
|
|
24
|
+
* True if this model needs to be sync'd/initialized with the original model.
|
|
25
|
+
*
|
|
26
|
+
* Is set false if/when "fi" is set true.
|
|
27
|
+
*/
|
|
28
|
+
s?: Maybe<NeedsSyncBoolean>;
|
|
29
|
+
/**
|
|
30
|
+
* True if this model has been flagged invalid.
|
|
31
|
+
*
|
|
32
|
+
* This is for cases where the model cannot be properly initiialized.
|
|
33
|
+
*
|
|
34
|
+
* NOTE: The server can also be configured to automatically delete these models instead of marking them as invalid.
|
|
35
|
+
*/
|
|
36
|
+
fi?: Maybe<SavedToFirestoreIfTrue>;
|
|
37
|
+
}
|
|
38
|
+
export declare const notificationUserIdentity: import("../../common").RootFirestoreModelIdentity<"notificationUser", "nu">;
|
|
39
|
+
/**
|
|
40
|
+
* A global notification User in the system.
|
|
41
|
+
*
|
|
42
|
+
* Keeps track of the NotificationBoxes the user is subscribed to, as well as other global subscriptions.
|
|
43
|
+
*
|
|
44
|
+
* The NotificationUser is created automatically by the NotificationBox as a user is created.
|
|
45
|
+
*/
|
|
46
|
+
export interface NotificationUser extends UserRelated, UserRelatedById {
|
|
47
|
+
/**
|
|
48
|
+
* List of notification boxes this user is associated with. Cannot be changed directly.
|
|
49
|
+
*/
|
|
50
|
+
b: NotificationBoxId[];
|
|
51
|
+
/**
|
|
52
|
+
* Global config override.
|
|
53
|
+
*
|
|
54
|
+
* This config effectively overrides all other configs, both NotificationBox configs and direct/default configs when used.
|
|
55
|
+
* It does not however get copied to dc/bc when updated.
|
|
56
|
+
*/
|
|
57
|
+
gc: NotificationUserDefaultNotificationBoxRecipientConfig;
|
|
58
|
+
/**
|
|
59
|
+
* Direct/default config.
|
|
60
|
+
*
|
|
61
|
+
* 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.
|
|
62
|
+
*/
|
|
63
|
+
dc: NotificationUserDefaultNotificationBoxRecipientConfig;
|
|
64
|
+
/**
|
|
65
|
+
* List of NotificationBox configurations.
|
|
66
|
+
*/
|
|
67
|
+
bc: NotificationUserNotificationBoxRecipientConfig[];
|
|
68
|
+
/**
|
|
69
|
+
* Whether or not the user has one or more configs that need to be synced.
|
|
70
|
+
*/
|
|
71
|
+
ns?: Maybe<NeedsSyncBoolean>;
|
|
72
|
+
}
|
|
73
|
+
export type NotificationUserRoles = 'sync' | GrantedUpdateRole | GrantedReadRole;
|
|
74
|
+
export declare class NotificationUserDocument extends AbstractFirestoreDocument<NotificationUser, NotificationUserDocument, typeof notificationUserIdentity> {
|
|
75
|
+
get modelIdentity(): import("../../common").RootFirestoreModelIdentity<"notificationUser", "nu">;
|
|
76
|
+
}
|
|
77
|
+
export declare const notificationUserConverter: import("../../common").SnapshotConverterFunctions<NotificationUser, Partial<import("@dereekb/util").ReplaceType<NotificationUser, import("@dereekb/util").MaybeMap<object>, any>>>;
|
|
78
|
+
export declare function notificationUserCollectionReference(context: FirestoreContext): CollectionReference<NotificationUser>;
|
|
79
|
+
export type NotificationUserFirestoreCollection = FirestoreCollection<NotificationUser, NotificationUserDocument>;
|
|
80
|
+
export declare function notificationUserFirestoreCollection(firestoreContext: FirestoreContext): NotificationUserFirestoreCollection;
|
|
81
|
+
/**
|
|
82
|
+
* An arbitrary summary object
|
|
83
|
+
*/
|
|
84
|
+
export declare const notificationSummaryIdentity: import("../../common").RootFirestoreModelIdentity<"notificationSummary", "ns">;
|
|
85
|
+
/**
|
|
86
|
+
* The maximum number of notifications that can be stored in a NotificationSummary.
|
|
87
|
+
*/
|
|
88
|
+
export declare const NOTIFICATION_SUMMARY_ITEM_LIMIT = 1000;
|
|
89
|
+
/**
|
|
90
|
+
* The expected max length of a subject on a NotificationSummary's embedded NotificationItem.
|
|
91
|
+
*/
|
|
92
|
+
export declare const NOTIFICATION_SUMMARY_EMBEDDED_NOTIFICATION_ITEM_SUBJECT_MAX_LENGTH = 80;
|
|
93
|
+
/**
|
|
94
|
+
* The expected max length of a message on a NotificationSummary's embedded NotificationItem.
|
|
95
|
+
*/
|
|
96
|
+
export declare const NOTIFICATION_SUMMARY_EMBEDDED_NOTIFICATION_ITEM_MESSAGE_MAX_LENGTH = 500;
|
|
97
|
+
/**
|
|
98
|
+
* 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.
|
|
99
|
+
*
|
|
100
|
+
* Notification Items can be delivered here.
|
|
101
|
+
*/
|
|
102
|
+
export interface NotificationSummary {
|
|
103
|
+
/**
|
|
104
|
+
* Notification Summary creation date
|
|
105
|
+
*/
|
|
106
|
+
cat: Date;
|
|
107
|
+
/**
|
|
108
|
+
* Model key of the model this box is assigned to.
|
|
109
|
+
*/
|
|
110
|
+
m: FirestoreModelKey;
|
|
111
|
+
/**
|
|
112
|
+
* Owner model key of the model this box is assigned to.
|
|
113
|
+
*
|
|
114
|
+
* Is created with a dummy value until it is initialized.
|
|
115
|
+
*/
|
|
116
|
+
o: FirestoreModelKey;
|
|
117
|
+
/**
|
|
118
|
+
* Notification items.
|
|
119
|
+
*
|
|
120
|
+
* They are sorted in ascending order, with the newest items at the end.
|
|
121
|
+
*/
|
|
122
|
+
n: NotificationItem[];
|
|
123
|
+
/**
|
|
124
|
+
* Date of the latest notification.
|
|
125
|
+
*/
|
|
126
|
+
lat?: Maybe<Date>;
|
|
127
|
+
/**
|
|
128
|
+
* Date of the last read at time so notifications can be marked as read.
|
|
129
|
+
*/
|
|
130
|
+
rat?: Maybe<Date>;
|
|
131
|
+
/**
|
|
132
|
+
* True if this NotificationSummary needs to be sync'd/initialized with the original model.
|
|
133
|
+
*/
|
|
134
|
+
s?: Maybe<NeedsSyncBoolean>;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* NotificationSummary roles
|
|
138
|
+
*/
|
|
139
|
+
export type NotificationSummaryRoles = GrantedReadRole;
|
|
140
|
+
export declare class NotificationSummaryDocument extends AbstractFirestoreDocument<NotificationSummary, NotificationSummaryDocument, typeof notificationSummaryIdentity> {
|
|
141
|
+
get modelIdentity(): import("../../common").RootFirestoreModelIdentity<"notificationSummary", "ns">;
|
|
142
|
+
}
|
|
143
|
+
export declare const notificationSummaryConverter: import("../../common").SnapshotConverterFunctions<NotificationSummary, Partial<import("@dereekb/util").ReplaceType<NotificationSummary, import("@dereekb/util").MaybeMap<object>, any>>>;
|
|
144
|
+
export declare function notificationSummaryCollectionReference(context: FirestoreContext): CollectionReference<NotificationSummary>;
|
|
145
|
+
export type NotificationSummaryFirestoreCollection = FirestoreCollection<NotificationSummary, NotificationSummaryDocument>;
|
|
146
|
+
export declare function notificationSummaryFirestoreCollection(firestoreContext: FirestoreContext): NotificationSummaryFirestoreCollection;
|
|
147
|
+
export declare const notificationBoxIdentity: import("../../common").RootFirestoreModelIdentity<"notificationBox", "nb">;
|
|
148
|
+
/**
|
|
149
|
+
* A Notification Box in the system for an object. The id for this is the two-way flat key of the object it represents.
|
|
150
|
+
*
|
|
151
|
+
* This object is the root collection for notifications for the corresponding object.
|
|
152
|
+
*
|
|
153
|
+
* Additional information about what notification templates are available to this type are available on a per-application basis, typically through the
|
|
154
|
+
* NotificationTemplateTypeInfoRecord configured for the app.
|
|
155
|
+
*
|
|
156
|
+
* Update to each recipient is propogated from NotificationUser values.
|
|
157
|
+
*/
|
|
158
|
+
export interface NotificationBox {
|
|
159
|
+
/**
|
|
160
|
+
* Notification Box creation date
|
|
161
|
+
*/
|
|
162
|
+
cat: Date;
|
|
163
|
+
/**
|
|
164
|
+
* Model key of the model this box is assigned to.
|
|
165
|
+
*/
|
|
166
|
+
m: FirestoreModelKey;
|
|
167
|
+
/**
|
|
168
|
+
* Owner model key of the model this box is assigned to.
|
|
169
|
+
*
|
|
170
|
+
* Is created with a dummy value until it is initialized.
|
|
171
|
+
*/
|
|
172
|
+
o: FirestoreModelKey;
|
|
173
|
+
/**
|
|
174
|
+
* Embedded recipients.
|
|
175
|
+
*/
|
|
176
|
+
r: NotificationBoxRecipient[];
|
|
177
|
+
/**
|
|
178
|
+
* Latest week.
|
|
179
|
+
*/
|
|
180
|
+
w: YearWeekCode;
|
|
181
|
+
/**
|
|
182
|
+
* True if this NotificationBox needs to be sync'd/initialized with the original model.
|
|
183
|
+
*
|
|
184
|
+
* Is set false if/when "fi" is set true.
|
|
185
|
+
*/
|
|
186
|
+
s?: Maybe<NeedsSyncBoolean>;
|
|
187
|
+
/**
|
|
188
|
+
* True if this NotificationBox has been flagged invalid.
|
|
189
|
+
*
|
|
190
|
+
* This is for cases where the NotificationBox cannot be properly initiialized.
|
|
191
|
+
*
|
|
192
|
+
* NOTE: The server can also be configured to automatically delete matching boxes instead of marking them as invalid.
|
|
193
|
+
*/
|
|
194
|
+
fi?: Maybe<SavedToFirestoreIfTrue>;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* NotificationBox roles
|
|
198
|
+
*
|
|
199
|
+
* subscribe: user can subscribe or unsubscribe to/from this notification box and manage themselves.
|
|
200
|
+
* manageRecipients: user can manage all recipients
|
|
201
|
+
*/
|
|
202
|
+
export type NotificationBoxRoles = 'subscribe' | 'manageRecipients' | 'createNotification' | GrantedReadRole | GrantedUpdateRole;
|
|
203
|
+
export declare class NotificationBoxDocument extends AbstractFirestoreDocument<NotificationBox, NotificationBoxDocument, typeof notificationBoxIdentity> {
|
|
204
|
+
get modelIdentity(): import("../../common").RootFirestoreModelIdentity<"notificationBox", "nb">;
|
|
205
|
+
}
|
|
206
|
+
export declare const notificationBoxConverter: import("../../common").SnapshotConverterFunctions<NotificationBox, Partial<import("@dereekb/util").ReplaceType<NotificationBox, import("@dereekb/util").MaybeMap<object>, any>>>;
|
|
207
|
+
export declare function notificationBoxCollectionReference(context: FirestoreContext): CollectionReference<NotificationBox>;
|
|
208
|
+
export type NotificationBoxFirestoreCollection = FirestoreCollection<NotificationBox, NotificationBoxDocument>;
|
|
209
|
+
export declare function notificationBoxFirestoreCollection(firestoreContext: FirestoreContext): NotificationBoxFirestoreCollection;
|
|
210
|
+
export declare const notificationIdentity: import("../../common").FirestoreModelIdentityWithParent<import("../../common").RootFirestoreModelIdentity<"notificationBox", "nb">, "notification", "nbn">;
|
|
211
|
+
export declare enum NotificationSendType {
|
|
212
|
+
/**
|
|
213
|
+
* Sends only if the NotificationBox exists.
|
|
214
|
+
*
|
|
215
|
+
* Does not create a NotificationBox for the model.
|
|
216
|
+
*/
|
|
217
|
+
SEND_IF_BOX_EXISTS = 0,
|
|
218
|
+
/**
|
|
219
|
+
* Creates a NotificationBox if it doesn't exist, and then sends the Notification.
|
|
220
|
+
*/
|
|
221
|
+
INIT_BOX_AND_SEND = 1,
|
|
222
|
+
/**
|
|
223
|
+
* Sends the notification even if the NotificationBox does not exist.
|
|
224
|
+
*/
|
|
225
|
+
SEND_WITHOUT_CREATING_BOX = 2
|
|
226
|
+
}
|
|
227
|
+
export declare enum NotificationSendState {
|
|
228
|
+
/**
|
|
229
|
+
* Notification will not be sent.
|
|
230
|
+
*/
|
|
231
|
+
NONE = -1,
|
|
232
|
+
/**
|
|
233
|
+
* Notification is queued up.
|
|
234
|
+
*/
|
|
235
|
+
QUEUED = 0,
|
|
236
|
+
/**
|
|
237
|
+
* Notification has been sent. Will still show as sent even if there were no messages/recipients to send for this medium.
|
|
238
|
+
*/
|
|
239
|
+
SENT = 1,
|
|
240
|
+
/**
|
|
241
|
+
* Some of the notifications have been sent, but some failed.
|
|
242
|
+
*/
|
|
243
|
+
SENT_PARTIAL = 2,
|
|
244
|
+
/**
|
|
245
|
+
* Notification has been skipped due to the box's settings.
|
|
246
|
+
*/
|
|
247
|
+
SKIPPED = 3,
|
|
248
|
+
/**
|
|
249
|
+
* Notification is flagged as being skipped and should not be reattempetd
|
|
250
|
+
*/
|
|
251
|
+
NO_TRY = 4,
|
|
252
|
+
/**
|
|
253
|
+
* Notification encountered an error while sending and could not be sent.
|
|
254
|
+
*/
|
|
255
|
+
SEND_ERROR = 5,
|
|
256
|
+
/**
|
|
257
|
+
* Notification encountered an error while building and could not be sent.
|
|
258
|
+
*/
|
|
259
|
+
BUILD_ERROR = 6,
|
|
260
|
+
/**
|
|
261
|
+
* Notification encountered an error due to the system not being configured properly.
|
|
262
|
+
*/
|
|
263
|
+
CONFIG_ERROR = 7
|
|
264
|
+
}
|
|
265
|
+
export declare enum NotificationType {
|
|
266
|
+
/**
|
|
267
|
+
* Normal notification that is sent to everyone that is configured for the notification box.
|
|
268
|
+
*/
|
|
269
|
+
NORMAL = 0,
|
|
270
|
+
/**
|
|
271
|
+
* Notification that goes to only the configured users.
|
|
272
|
+
*/
|
|
273
|
+
AD_HOC = 1
|
|
274
|
+
}
|
|
275
|
+
export declare enum NotificationRecipientSendFlag {
|
|
276
|
+
/**
|
|
277
|
+
* Will send to all recipients.
|
|
278
|
+
*/
|
|
279
|
+
NORMAL = 0,
|
|
280
|
+
/**
|
|
281
|
+
* Will not send to any of the configured notification box recipients. Will only to the globally configured message recpients or the notification specified recipients.
|
|
282
|
+
*/
|
|
283
|
+
SKIP_NOTIFICATION_BOX_RECIPIENTS = 1,
|
|
284
|
+
/**
|
|
285
|
+
* Will not send to any of the globally configured message recpients. Will only send to the notification specified recipients or the notification box recipients.
|
|
286
|
+
*/
|
|
287
|
+
SKIP_GLOBAL_RECIPIENTS = 2,
|
|
288
|
+
/**
|
|
289
|
+
* Will only sent to recipients that are configured in this notification. Will not send to globally configured message recipients or notification box recipients.
|
|
290
|
+
*/
|
|
291
|
+
ONLY_EXPLICIT_RECIPIENTS = 3,
|
|
292
|
+
/**
|
|
293
|
+
* Will only sent to globally configured message recipients.
|
|
294
|
+
*/
|
|
295
|
+
ONLY_GLOBAL_RECIPIENTS = 4
|
|
296
|
+
}
|
|
297
|
+
export interface NotificationSendFlags {
|
|
298
|
+
/**
|
|
299
|
+
* Text send state
|
|
300
|
+
*/
|
|
301
|
+
ts: NotificationSendState;
|
|
302
|
+
/**
|
|
303
|
+
* Email send state
|
|
304
|
+
*/
|
|
305
|
+
es: NotificationSendState;
|
|
306
|
+
/**
|
|
307
|
+
* Push notification send state
|
|
308
|
+
*/
|
|
309
|
+
ps: NotificationSendState;
|
|
310
|
+
/**
|
|
311
|
+
* Notification summary send state
|
|
312
|
+
*/
|
|
313
|
+
ns: NotificationSendState;
|
|
314
|
+
/**
|
|
315
|
+
* Push notification recipient send flag. Determines who will recieve the notifications, and if it should be saved to the NotificationWeek once sent.
|
|
316
|
+
*/
|
|
317
|
+
rf?: Maybe<NotificationRecipientSendFlag>;
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Contains information about which recipients were already sent their messages, etc.
|
|
321
|
+
*/
|
|
322
|
+
export interface NotificationSendCheckpoints {
|
|
323
|
+
/**
|
|
324
|
+
* Set of numbers the notification was sent to via text/sms.
|
|
325
|
+
*/
|
|
326
|
+
tsr: E164PhoneNumber[];
|
|
327
|
+
/**
|
|
328
|
+
* Set of emails that the notification was set to via email.
|
|
329
|
+
*/
|
|
330
|
+
esr: EmailAddress[];
|
|
331
|
+
}
|
|
332
|
+
export interface Notification extends NotificationSendFlags, NotificationSendCheckpoints {
|
|
333
|
+
/**
|
|
334
|
+
* Send type
|
|
335
|
+
*/
|
|
336
|
+
st: NotificationSendType;
|
|
337
|
+
/**
|
|
338
|
+
* Notification item
|
|
339
|
+
*/
|
|
340
|
+
n: NotificationItem;
|
|
341
|
+
/**
|
|
342
|
+
* Additional embedded recipients.
|
|
343
|
+
*/
|
|
344
|
+
r: NotificationRecipientWithConfig[];
|
|
345
|
+
/**
|
|
346
|
+
* Minimum time at which this notification should be sent.
|
|
347
|
+
*
|
|
348
|
+
* The notification is only guranteed to be sent after this time.
|
|
349
|
+
*
|
|
350
|
+
* 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.
|
|
351
|
+
*/
|
|
352
|
+
sat: Date;
|
|
353
|
+
/**
|
|
354
|
+
* Sending attempts count.
|
|
355
|
+
*/
|
|
356
|
+
a: number;
|
|
357
|
+
/**
|
|
358
|
+
* Notification has been delivered or should be archived. This is now safe to sync to the NotificationWeek and then delete this.
|
|
359
|
+
*/
|
|
360
|
+
d: boolean;
|
|
361
|
+
}
|
|
362
|
+
export type NotificationRoles = GrantedUpdateRole;
|
|
363
|
+
export declare class NotificationDocument extends AbstractFirestoreDocumentWithParent<NotificationBox, Notification, NotificationDocument, typeof notificationIdentity> {
|
|
364
|
+
get modelIdentity(): import("../../common").FirestoreModelIdentityWithParent<import("../../common").RootFirestoreModelIdentity<"notificationBox", "nb">, "notification", "nbn">;
|
|
365
|
+
}
|
|
366
|
+
export declare const notificationConverter: import("../../common").SnapshotConverterFunctions<Notification, Partial<import("@dereekb/util").ReplaceType<Notification, import("@dereekb/util").MaybeMap<object>, any>>>;
|
|
367
|
+
export declare function notificationCollectionReferenceFactory(context: FirestoreContext): (notificationBox: NotificationBoxDocument) => CollectionReference<Notification>;
|
|
368
|
+
export type NotificationFirestoreCollection = FirestoreCollectionWithParent<Notification, NotificationBox, NotificationDocument, NotificationBoxDocument>;
|
|
369
|
+
export type NotificationFirestoreCollectionFactory = (parent: NotificationBoxDocument) => NotificationFirestoreCollection;
|
|
370
|
+
export declare function notificationFirestoreCollectionFactory(firestoreContext: FirestoreContext): NotificationFirestoreCollectionFactory;
|
|
371
|
+
export declare function notificationCollectionReference(context: FirestoreContext): CollectionGroup<Notification>;
|
|
372
|
+
export type NotificationFirestoreCollectionGroup = FirestoreCollectionGroup<Notification, NotificationDocument>;
|
|
373
|
+
export declare function notificationFirestoreCollectionGroup(firestoreContext: FirestoreContext): NotificationFirestoreCollectionGroup;
|
|
374
|
+
export declare const notificationWeekIdentity: import("../../common").FirestoreModelIdentityWithParent<import("../../common").RootFirestoreModelIdentity<"notificationBox", "nb">, "notificationWeek", "nbnw">;
|
|
375
|
+
/**
|
|
376
|
+
* The maximum number of notifications that can be stored in a NotificationWeek.
|
|
377
|
+
*/
|
|
378
|
+
export declare const NOTIFICATION_WEEK_NOTIFICATION_ITEM_LIMIT = 5000;
|
|
379
|
+
/**
|
|
380
|
+
* Notification week. Contains all notifications in the box for the given week.
|
|
381
|
+
*/
|
|
382
|
+
export interface NotificationWeek {
|
|
383
|
+
/**
|
|
384
|
+
* YearWeekCode value. Same as the id.
|
|
385
|
+
*/
|
|
386
|
+
w: YearWeekCode;
|
|
387
|
+
/**
|
|
388
|
+
* Notification items.
|
|
389
|
+
*/
|
|
390
|
+
n: NotificationItem[];
|
|
391
|
+
}
|
|
392
|
+
export type NotificationWeekRoles = GrantedReadRole;
|
|
393
|
+
export declare class NotificationWeekDocument extends AbstractFirestoreDocumentWithParent<NotificationBox, NotificationWeek, NotificationWeekDocument, typeof notificationWeekIdentity> {
|
|
394
|
+
get modelIdentity(): import("../../common").FirestoreModelIdentityWithParent<import("../../common").RootFirestoreModelIdentity<"notificationBox", "nb">, "notificationWeek", "nbnw">;
|
|
395
|
+
}
|
|
396
|
+
export declare const notificationWeekConverter: import("../../common").SnapshotConverterFunctions<NotificationWeek, Partial<import("@dereekb/util").ReplaceType<NotificationWeek, import("@dereekb/util").MaybeMap<object>, any>>>;
|
|
397
|
+
export declare function notificationWeekCollectionReferenceFactory(context: FirestoreContext): (notificationBox: NotificationBoxDocument) => CollectionReference<NotificationWeek>;
|
|
398
|
+
export type NotificationWeekFirestoreCollection = FirestoreCollectionWithParent<NotificationWeek, NotificationBox, NotificationWeekDocument, NotificationBoxDocument>;
|
|
399
|
+
export type NotificationWeekFirestoreCollectionFactory = (parent: NotificationBoxDocument) => NotificationWeekFirestoreCollection;
|
|
400
|
+
export declare function notificationWeekFirestoreCollectionFactory(firestoreContext: FirestoreContext): NotificationWeekFirestoreCollectionFactory;
|
|
401
|
+
export declare function notificationWeekCollectionReference(context: FirestoreContext): CollectionGroup<NotificationWeek>;
|
|
402
|
+
export type NotificationWeekFirestoreCollectionGroup = FirestoreCollectionGroup<NotificationWeek, NotificationWeekDocument>;
|
|
403
|
+
export declare function notificationWeekFirestoreCollectionGroup(firestoreContext: FirestoreContext): NotificationWeekFirestoreCollectionGroup;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { type Maybe } from '@dereekb/util';
|
|
2
|
+
import { type FirestoreModelIdentity, type ReadFirestoreModelKeyInput } from '../../common';
|
|
3
|
+
import { type NotificationTemplateType } from './notification.id';
|
|
4
|
+
/**
|
|
5
|
+
* Template type identifier of the notification.
|
|
6
|
+
*
|
|
7
|
+
* Provides default information for the notification.
|
|
8
|
+
*
|
|
9
|
+
* Types are generally intended to be handled case-insensitively by notification services.
|
|
10
|
+
*/
|
|
11
|
+
export interface NotificationTemplateTypeInfo {
|
|
12
|
+
/**
|
|
13
|
+
* Notification type
|
|
14
|
+
*/
|
|
15
|
+
readonly type: NotificationTemplateType;
|
|
16
|
+
/**
|
|
17
|
+
* The notification's name
|
|
18
|
+
*/
|
|
19
|
+
readonly name: string;
|
|
20
|
+
/**
|
|
21
|
+
* Description of the notification's content.
|
|
22
|
+
*/
|
|
23
|
+
readonly description: string;
|
|
24
|
+
/**
|
|
25
|
+
* Model identity that this notification is for.
|
|
26
|
+
*
|
|
27
|
+
* This model will have a NotificationBox associated with it.
|
|
28
|
+
*/
|
|
29
|
+
readonly notificationModelIdentity: FirestoreModelIdentity;
|
|
30
|
+
/**
|
|
31
|
+
* Optional target model identity that this notification references.
|
|
32
|
+
*
|
|
33
|
+
* If not defined, it is assumed that the notificationModelIdentity is the target model.
|
|
34
|
+
*
|
|
35
|
+
* This model will not have a NotificationBox associated with it, and is typically a child model of the notificationModelIdentity.
|
|
36
|
+
*/
|
|
37
|
+
readonly targetModelIdentity?: Maybe<FirestoreModelIdentity>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Record of NotificationTemplateTypeInfo keyed by type.
|
|
41
|
+
*/
|
|
42
|
+
export type NotificationTemplateTypeInfoRecord = Record<NotificationTemplateType, NotificationTemplateTypeInfo>;
|
|
43
|
+
/**
|
|
44
|
+
* Creates a NotificationTemplateTypeInfoRecord from the input details array.
|
|
45
|
+
*
|
|
46
|
+
* @param infoArray
|
|
47
|
+
* @returns
|
|
48
|
+
*/
|
|
49
|
+
export declare function notificationTemplateTypeDetailsRecord(infoArray: NotificationTemplateTypeInfo[]): NotificationTemplateTypeInfoRecord;
|
|
50
|
+
/**
|
|
51
|
+
* Reference to a NotificationTemplateTypeInfoRecord that contains a AppNotificationTemplateTypeInfoRecordService
|
|
52
|
+
*/
|
|
53
|
+
export interface AppNotificationTemplateTypeInfoRecordServiceRef {
|
|
54
|
+
readonly appNotificationTemplateTypeInfoRecordService: AppNotificationTemplateTypeInfoRecordService;
|
|
55
|
+
}
|
|
56
|
+
export declare abstract class AppNotificationTemplateTypeInfoRecordService {
|
|
57
|
+
/**
|
|
58
|
+
* All records for this app.
|
|
59
|
+
*/
|
|
60
|
+
abstract readonly appNotificationTemplateTypeInfoRecord: NotificationTemplateTypeInfoRecord;
|
|
61
|
+
/**
|
|
62
|
+
* Returns the array of all known NotificationTemplateTypes
|
|
63
|
+
*/
|
|
64
|
+
abstract getAllKnownTemplateTypes(): NotificationTemplateType[];
|
|
65
|
+
/**
|
|
66
|
+
* Returns the array of all known NotificationTemplateTypeInfo
|
|
67
|
+
*/
|
|
68
|
+
abstract getAllKnownTemplateTypeDetails(): NotificationTemplateTypeInfo[];
|
|
69
|
+
/**
|
|
70
|
+
* Returns all individual FirestoreModelIdentity values that are associate with atleast one NotificationTemplateType.
|
|
71
|
+
*/
|
|
72
|
+
abstract getAllNotificationModelIdentityValues(): FirestoreModelIdentity[];
|
|
73
|
+
/**
|
|
74
|
+
* Returns all NotificationTemplateTypes that are associate with the given model input.
|
|
75
|
+
*
|
|
76
|
+
* @param model
|
|
77
|
+
*/
|
|
78
|
+
abstract getTemplateTypesForNotificationModel(model: ReadFirestoreModelKeyInput): NotificationTemplateType[];
|
|
79
|
+
/**
|
|
80
|
+
* Returns all NotificationTemplateTypeInfo that are associate with the given model input.
|
|
81
|
+
*
|
|
82
|
+
* @param model
|
|
83
|
+
*/
|
|
84
|
+
abstract getTemplateTypesDetailsForNotificationModel(model: ReadFirestoreModelKeyInput): NotificationTemplateTypeInfo[];
|
|
85
|
+
/**
|
|
86
|
+
* Returns all NotificationTemplateTypes that are associate with the given model input.
|
|
87
|
+
*
|
|
88
|
+
* @param model
|
|
89
|
+
*/
|
|
90
|
+
abstract getTemplateTypesForTargetModel(target: ReadFirestoreModelKeyInput): NotificationTemplateType[];
|
|
91
|
+
/**
|
|
92
|
+
* Returns all NotificationTemplateTypeInfo that are associate with the given model input.
|
|
93
|
+
*
|
|
94
|
+
* @param model
|
|
95
|
+
*/
|
|
96
|
+
abstract getTemplateTypesDetailsForTargetModel(target: ReadFirestoreModelKeyInput): NotificationTemplateTypeInfo[];
|
|
97
|
+
}
|
|
98
|
+
export declare function appNotificationTemplateTypeInfoRecordService(appNotificationTemplateTypeInfoRecord: NotificationTemplateTypeInfoRecord): AppNotificationTemplateTypeInfoRecordService;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type FactoryWithRequiredInput } from '@dereekb/util';
|
|
2
|
+
import { type FirestoreModelId, type FirestoreModelKey, type FlatFirestoreModelKey, twoWayFlatFirestoreModelKey, inferKeyFromTwoWayFlatFirestoreModelKey, type FirebaseAuthUserId, type RootFirestoreModelIdentity } from '../../common';
|
|
3
|
+
/**
|
|
4
|
+
* The NotificationBox's id is the two way flat firestore model key of the object that it represents.
|
|
5
|
+
*/
|
|
6
|
+
export type NotificationBoxId = FlatFirestoreModelKey;
|
|
7
|
+
export type NotificationBoxKey = FirestoreModelKey;
|
|
8
|
+
/**
|
|
9
|
+
* Creates a NotificationBoxId from the input FirestoreModelKey.
|
|
10
|
+
*
|
|
11
|
+
* @param modelKey
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
export declare const notificationBoxIdForModel: typeof twoWayFlatFirestoreModelKey;
|
|
15
|
+
export declare const inferNotificationBoxRelatedModelKey: typeof inferKeyFromTwoWayFlatFirestoreModelKey;
|
|
16
|
+
export type NotificationUserId = FlatFirestoreModelKey;
|
|
17
|
+
export type NotificationUserKey = FirestoreModelKey;
|
|
18
|
+
export type NotificationSummaryId = FlatFirestoreModelKey;
|
|
19
|
+
export type NotificationSummaryKey = FirestoreModelKey;
|
|
20
|
+
/**
|
|
21
|
+
* Creates a NotificationSummaryId from the input FirestoreModelKey.
|
|
22
|
+
*
|
|
23
|
+
* @param modelKey
|
|
24
|
+
* @returns
|
|
25
|
+
*/
|
|
26
|
+
export declare const notificationSummaryIdForModel: typeof twoWayFlatFirestoreModelKey;
|
|
27
|
+
/**
|
|
28
|
+
* Function used to retrieve a NotificationSummaryId given the input FirestoreAuthUserId.
|
|
29
|
+
*/
|
|
30
|
+
export type NotificationSummaryIdForUidFunction = FactoryWithRequiredInput<NotificationSummaryId, FirebaseAuthUserId>;
|
|
31
|
+
export declare function notificationSummaryIdForUidFunctionForRootFirestoreModelIdentity(userModelIdentity: RootFirestoreModelIdentity): NotificationSummaryIdForUidFunction;
|
|
32
|
+
export type NotificationWeekId = FirestoreModelId;
|
|
33
|
+
export type NotificationWeekKey = FirestoreModelKey;
|
|
34
|
+
export type NotificationId = FirestoreModelId;
|
|
35
|
+
export type NotificationKey = FirestoreModelKey;
|
|
36
|
+
/**
|
|
37
|
+
* The default notification template type that can be provided to subscribe to notifications not specified in the configurations.
|
|
38
|
+
*/
|
|
39
|
+
export declare const DEFAULT_NOTIFICATION_TEMPLATE_TYPE = "D";
|
|
40
|
+
/**
|
|
41
|
+
* Template type identifier of the notification.
|
|
42
|
+
*
|
|
43
|
+
* Provides default information for the notification.
|
|
44
|
+
*
|
|
45
|
+
* Types are generally intended to be handled case-insensitively by notification services.
|
|
46
|
+
*
|
|
47
|
+
* Ideally type type values are shorter to reduce database size impact.
|
|
48
|
+
*/
|
|
49
|
+
export type NotificationTemplateType = string;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { type Maybe } from '@dereekb/util';
|
|
2
|
+
import { type FirebaseAuthUserId, type FirestoreModelKey, type SavedToFirestoreIfTrue } from '../../common';
|
|
3
|
+
import { type NotificationId, type NotificationTemplateType } from './notification.id';
|
|
4
|
+
/**
|
|
5
|
+
* Arbitrary metadata for a job. Derived/managed by the concrete job type.
|
|
6
|
+
*/
|
|
7
|
+
export type NotificationItemMetadata = Readonly<Record<string, any>>;
|
|
8
|
+
export interface NotificationItemSubjectMessagePair<D extends NotificationItemMetadata = {}> {
|
|
9
|
+
readonly item: NotificationItem<D>;
|
|
10
|
+
readonly subject: string;
|
|
11
|
+
readonly message: string;
|
|
12
|
+
readonly date: Date;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A notification item.
|
|
16
|
+
*
|
|
17
|
+
* Is embedded within a Notification, NotificationWeek, and NotificationSummary.
|
|
18
|
+
*/
|
|
19
|
+
export interface NotificationItem<D extends NotificationItemMetadata = {}> {
|
|
20
|
+
/**
|
|
21
|
+
* Unique identifier
|
|
22
|
+
*/
|
|
23
|
+
id: NotificationId;
|
|
24
|
+
/**
|
|
25
|
+
* Notification date/time
|
|
26
|
+
*/
|
|
27
|
+
cat: Date;
|
|
28
|
+
/**
|
|
29
|
+
* Notification template type.
|
|
30
|
+
*/
|
|
31
|
+
t: NotificationTemplateType;
|
|
32
|
+
/**
|
|
33
|
+
* User who created this notification, if applicable.
|
|
34
|
+
*/
|
|
35
|
+
cb?: Maybe<FirebaseAuthUserId>;
|
|
36
|
+
/**
|
|
37
|
+
* Model/object that this notification item is targeting.
|
|
38
|
+
*/
|
|
39
|
+
m?: Maybe<FirestoreModelKey>;
|
|
40
|
+
/**
|
|
41
|
+
* Subject. Used to overwrite the template's default subject.
|
|
42
|
+
*/
|
|
43
|
+
s?: Maybe<string>;
|
|
44
|
+
/**
|
|
45
|
+
* Message. Used to overwrite the template's default message.
|
|
46
|
+
*/
|
|
47
|
+
g?: Maybe<string>;
|
|
48
|
+
/**
|
|
49
|
+
* Arbitrary metadata attached to the notification item.
|
|
50
|
+
*/
|
|
51
|
+
d?: Maybe<D>;
|
|
52
|
+
/**
|
|
53
|
+
* True if this notification item is marked as read/viewed.
|
|
54
|
+
*/
|
|
55
|
+
v?: Maybe<SavedToFirestoreIfTrue>;
|
|
56
|
+
}
|
|
57
|
+
export declare const firestoreNotificationItem: import("../../common").FirestoreSubObjectFieldMapFunctionsConfig<NotificationItem<{}>, Partial<import("@dereekb/util").ReplaceType<NotificationItem<{}>, import("@dereekb/util").MaybeMap<object>, any>>>;
|
|
58
|
+
export interface UnreadNotificationItemsResult<D extends NotificationItemMetadata = {}> {
|
|
59
|
+
readonly items: NotificationItem<D>[];
|
|
60
|
+
readonly considerReadIfCreatedBefore?: Maybe<Date>;
|
|
61
|
+
readonly read: NotificationItem<D>[];
|
|
62
|
+
readonly unread: NotificationItem<D>[];
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Returns an object containing input notification items split up by their determined read/unread state.
|
|
66
|
+
*
|
|
67
|
+
* @param items
|
|
68
|
+
*/
|
|
69
|
+
export declare function unreadNotificationItems<D extends NotificationItemMetadata = {}>(items: NotificationItem<D>[], considerReadIfCreatedBefore?: Maybe<Date>): UnreadNotificationItemsResult<D>;
|
|
70
|
+
export declare const sortNotificationItemsFunction: import("@dereekb/date").SortByDateFunction<NotificationItem<any>>;
|