@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.
Files changed (28) hide show
  1. package/index.cjs.js +1881 -93
  2. package/index.esm.js +2042 -37
  3. package/package.json +3 -2
  4. package/src/lib/client/error/error.d.ts +8 -0
  5. package/src/lib/client/error/index.d.ts +1 -0
  6. package/src/lib/client/firestore/error.d.ts +1 -0
  7. package/src/lib/client/firestore/index.d.ts +1 -0
  8. package/src/lib/client/index.d.ts +1 -0
  9. package/src/lib/common/firestore/accessor/document.utility.d.ts +4 -0
  10. package/src/lib/common/firestore/collection/collection.d.ts +6 -1
  11. package/src/lib/model/index.d.ts +1 -0
  12. package/src/lib/model/notification/index.d.ts +14 -0
  13. package/src/lib/model/notification/notification.action.d.ts +24 -0
  14. package/src/lib/model/notification/notification.api.d.ts +389 -0
  15. package/src/lib/model/notification/notification.api.error.d.ts +7 -0
  16. package/src/lib/model/notification/notification.api.util.d.ts +31 -0
  17. package/src/lib/model/notification/notification.config.d.ts +207 -0
  18. package/src/lib/model/notification/notification.create.d.ts +139 -0
  19. package/src/lib/model/notification/notification.d.ts +403 -0
  20. package/src/lib/model/notification/notification.details.d.ts +98 -0
  21. package/src/lib/model/notification/notification.id.d.ts +49 -0
  22. package/src/lib/model/notification/notification.item.d.ts +70 -0
  23. package/src/lib/model/notification/notification.message.d.ts +152 -0
  24. package/src/lib/model/notification/notification.query.d.ts +43 -0
  25. package/src/lib/model/notification/notification.send.d.ts +22 -0
  26. package/src/lib/model/notification/notification.util.d.ts +51 -0
  27. package/test/CHANGELOG.md +4 -0
  28. package/test/package.json +1 -1
@@ -0,0 +1,207 @@
1
+ import { type Maybe, type EmailAddress, type E164PhoneNumber, type BitwiseEncodedSet, type IndexRef, type NeedsSyncBoolean } from '@dereekb/util';
2
+ import { type NotificationBoxId, type NotificationSummaryId, type NotificationTemplateType } from './notification.id';
3
+ import { type FirebaseAuthUserId, type SavedToFirestoreIfTrue } from '../../common';
4
+ /**
5
+ * Notification configuration state for a template.
6
+ *
7
+ * Denotes which modes of message are enabled for the user to recieve.
8
+ */
9
+ export interface NotificationBoxRecipientTemplateConfig {
10
+ /**
11
+ * Send default is enabled/disabled for all types if not defined
12
+ */
13
+ sd?: Maybe<boolean>;
14
+ /**
15
+ * Email enabled / Send Email
16
+ */
17
+ se?: Maybe<boolean>;
18
+ /**
19
+ * Phone enabled / Send Text
20
+ */
21
+ st?: Maybe<boolean>;
22
+ /**
23
+ * Push notification enabled / Send Push Notification
24
+ */
25
+ sp?: Maybe<boolean>;
26
+ /**
27
+ * Send to notification summary of the associate user, if applicable.
28
+ */
29
+ sn?: Maybe<boolean>;
30
+ }
31
+ export declare function mergeNotificationBoxRecipientTemplateConfigs(a?: Maybe<NotificationBoxRecipientTemplateConfig>, b?: Maybe<NotificationBoxRecipientTemplateConfig>): NotificationBoxRecipientTemplateConfig;
32
+ export declare function effectiveNotificationBoxRecipientTemplateConfig(x: NotificationBoxRecipientTemplateConfig): NotificationBoxRecipientTemplateConfig;
33
+ /**
34
+ * Recipient configuration for a notification
35
+ */
36
+ export interface NotificationRecipient {
37
+ /**
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.
41
+ */
42
+ uid?: Maybe<FirebaseAuthUserId>;
43
+ /**
44
+ * User's name. Overrides any info in the user's Profile.
45
+ */
46
+ n?: Maybe<string>;
47
+ /**
48
+ * User's email address. Overrides any info in the user's Profile.
49
+ */
50
+ e?: Maybe<EmailAddress>;
51
+ /**
52
+ * User's phone number to send text messages to. Overrides any info in the user's Profile.
53
+ */
54
+ t?: Maybe<E164PhoneNumber>;
55
+ /**
56
+ * Notification summary id to send notifications to. Ignored and/or set null if uid is defined.
57
+ */
58
+ s?: Maybe<NotificationSummaryId>;
59
+ }
60
+ export declare function updateNotificationRecipient(a: NotificationRecipient, b: Partial<NotificationRecipient>): NotificationRecipient;
61
+ export interface NotificationRecipientWithConfig extends NotificationRecipient, NotificationBoxRecipientTemplateConfig {
62
+ }
63
+ export declare const firestoreNotificationRecipientWithConfig: import("../../common").FirestoreSubObjectFieldMapFunctionsConfig<NotificationRecipientWithConfig, Partial<import("@dereekb/util").ReplaceType<NotificationRecipientWithConfig, import("@dereekb/util").MaybeMap<object>, any>>>;
64
+ export declare enum NotificationBoxRecipientFlag {
65
+ /**
66
+ * The recipient is enabled.
67
+ *
68
+ * This is a transient state that should not be stored.
69
+ */
70
+ ENABLED = 0,
71
+ /**
72
+ * The recipient is not enabled to recieve notifications currently.
73
+ */
74
+ DISABLED = 1,
75
+ /**
76
+ * Recipient opted themselves out from recieving notifications.
77
+ */
78
+ OPT_OUT = 2
79
+ }
80
+ /**
81
+ * Settings related to recipients that recieve notifications.
82
+ *
83
+ * If uid is set, then most other NotificationRecipient fields are ignored as those are pulled from auth.
84
+ */
85
+ export interface NotificationBoxRecipient extends NotificationRecipient, IndexRef {
86
+ /**
87
+ * Enabled config types
88
+ */
89
+ c: NotificationBoxRecipientTemplateConfigRecord;
90
+ /**
91
+ * Current opt in flag. Non-zero values are opt-out.
92
+ *
93
+ * TODO: Test updating the flag and syncing
94
+ */
95
+ f?: Maybe<NotificationBoxRecipientFlag>;
96
+ /**
97
+ * Locked state that corresponds to the user's configuration and is sync'd by NotificationUserNotificationBoxRecipientConfig.
98
+ *
99
+ * If locked, updating the NotificationBox recipient will throw an error. The user can update their settings without issue.
100
+ */
101
+ lk?: Maybe<SavedToFirestoreIfTrue>;
102
+ }
103
+ export declare function newNotificationBoxRecipientForUid(uid: FirebaseAuthUserId, i: number): NotificationBoxRecipient;
104
+ /**
105
+ * Default NotificationUserNotificationBoxRecipientConfig.
106
+ */
107
+ export interface NotificationUserDefaultNotificationBoxRecipientConfig extends Omit<NotificationBoxRecipient, 'i' | 'n' | 's' | 'uid'> {
108
+ /**
109
+ * Locked state.
110
+ *
111
+ * If locked, updating the NotificationBox recipient will throw an error. The user can update their settings without issue.
112
+ */
113
+ lk?: Maybe<SavedToFirestoreIfTrue>;
114
+ /**
115
+ * Blocked state.
116
+ *
117
+ * If blocked, this NotificationBox will not be able to add this user back.
118
+ */
119
+ bk?: Maybe<SavedToFirestoreIfTrue>;
120
+ }
121
+ export declare function mergeNotificationUserDefaultNotificationBoxRecipientConfig(a: NotificationUserDefaultNotificationBoxRecipientConfig, b: NotificationUserDefaultNotificationBoxRecipientConfig): NotificationUserDefaultNotificationBoxRecipientConfig;
122
+ /**
123
+ * Used to reflect the NotificationBoxRecipient config back to a NotificationUser.
124
+ *
125
+ * The index reflects the index the user is in the NotificationBox.
126
+ */
127
+ export interface NotificationUserNotificationBoxRecipientConfig extends Omit<NotificationBoxRecipient, 'uid'> {
128
+ /**
129
+ * NotificationBox this configuration reflects.
130
+ *
131
+ * The model can be derived from this id.
132
+ */
133
+ nb: NotificationBoxId;
134
+ /**
135
+ * Removed state.
136
+ *
137
+ * If flagged, then this user has flagged themselves to be removed from the NotificationBox or have already been removed.
138
+ *
139
+ * Only the NotificationBox can restore a user, so a if a user removes themselves the user cannot restore themselves.
140
+ * A user will typically prefer to utilize the "f" value (opt-out) flag to not recieve any notifications, rather than remove themselves.
141
+ *
142
+ * The config for this NotificationBox is retained on the NotificationUser, unless the user deletes the configuration themselves.
143
+ */
144
+ rm?: Maybe<SavedToFirestoreIfTrue>;
145
+ /**
146
+ * Needs to be sync'd with the NotificationBox
147
+ */
148
+ ns?: Maybe<NeedsSyncBoolean>;
149
+ /**
150
+ * Locked state.
151
+ *
152
+ * If locked, updating the NotificationBox recipient will throw an error. The user can update their settings without issue.
153
+ */
154
+ lk?: Maybe<SavedToFirestoreIfTrue>;
155
+ /**
156
+ * Blocked state.
157
+ *
158
+ * If blocked, this NotificationBox will not be able to add this user back.
159
+ */
160
+ bk?: Maybe<SavedToFirestoreIfTrue>;
161
+ }
162
+ export declare enum NotificationBoxRecipientTemplateConfigBoolean {
163
+ SEND_ALL_ON = 0,
164
+ SEND_ALL_OFF = 1,
165
+ EMAIL = 2,
166
+ EMAIL_OFF = 3,
167
+ TEXT = 4,
168
+ TEXT_OFF = 5,
169
+ PUSH_NOTIFICATION = 6,
170
+ PUSH_NOTIFICATION_OFF = 7,
171
+ NOTIFICATION_SUMMARY = 8,
172
+ NOTIFICATION_SUMMARY_OFF = 9
173
+ }
174
+ /**
175
+ * Encoded NotificationBoxRecipientTemplateConfig
176
+ */
177
+ export type EncodedNotificationBoxRecipientTemplateConfig = BitwiseEncodedSet;
178
+ /**
179
+ * Map of template types to their configurations.
180
+ *
181
+ * Should not be saved with any template type entirely disabled.
182
+ */
183
+ export type NotificationBoxRecipientTemplateConfigRecord = Record<NotificationTemplateType, NotificationBoxRecipientTemplateConfig>;
184
+ export declare function mergeNotificationBoxRecipientTemplateConfigRecords(a: NotificationBoxRecipientTemplateConfigRecord, b: NotificationBoxRecipientTemplateConfigRecord): NotificationBoxRecipientTemplateConfigRecord;
185
+ /**
186
+ * Encoded NotificationBoxRecipientTemplateConfigRecord
187
+ */
188
+ export type EncodedNotificationBoxRecipientTemplateConfigRecord = Record<NotificationTemplateType, EncodedNotificationBoxRecipientTemplateConfig>;
189
+ export declare function firestoreNotificationBoxRecipientTemplateConfigRecord(): import("../../common").FirestoreModelFieldMapFunctionsConfig<import("../../common").FirestoreEncodedObjectMapFieldValueType<NotificationBoxRecipientTemplateConfig, string>, import("../../common").FirestoreMapFieldType<number, string>>;
190
+ export declare const firestoreNotificationBoxRecipient: import("../../common").FirestoreSubObjectFieldMapFunctionsConfig<NotificationBoxRecipient, Partial<import("@dereekb/util").ReplaceType<NotificationBoxRecipient, import("@dereekb/util").MaybeMap<object>, any>>>;
191
+ export declare const firestoreNotificationUserDefaultNotificationBoxRecipientConfig: import("../../common").FirestoreSubObjectFieldMapFunctionsConfig<NotificationUserDefaultNotificationBoxRecipientConfig, Partial<import("@dereekb/util").ReplaceType<NotificationUserDefaultNotificationBoxRecipientConfig, import("@dereekb/util").MaybeMap<object>, any>>>;
192
+ export declare const firestoreNotificationUserNotificationBoxRecipientConfig: import("../../common").FirestoreSubObjectFieldMapFunctionsConfig<NotificationUserNotificationBoxRecipientConfig, Partial<import("@dereekb/util").ReplaceType<NotificationUserNotificationBoxRecipientConfig, import("@dereekb/util").MaybeMap<object>, any>>>;
193
+ export interface NotificationBoxRecipientTemplateConfigArrayEntry extends NotificationBoxRecipientTemplateConfig {
194
+ /**
195
+ * Array entry template type
196
+ */
197
+ type: NotificationTemplateType;
198
+ }
199
+ export type NotificationBoxRecipientTemplateConfigArray = NotificationBoxRecipientTemplateConfigArrayEntry[];
200
+ export declare function notificationBoxRecipientTemplateConfigRecordToArray(input: NotificationBoxRecipientTemplateConfigRecord): NotificationBoxRecipientTemplateConfigArray;
201
+ export declare function notificationBoxRecipientTemplateConfigArrayToRecord(input: NotificationBoxRecipientTemplateConfigArray): NotificationBoxRecipientTemplateConfigRecord;
202
+ /**
203
+ * Config object that may contain a boolean called sendNotification.
204
+ */
205
+ export interface SendNotificationRef {
206
+ sendNotification?: Maybe<boolean>;
207
+ }
@@ -0,0 +1,139 @@
1
+ import { type Maybe, type ModelKey } from '@dereekb/util';
2
+ import { type Notification, type NotificationDocument, type NotificationFirestoreCollections, NotificationSendType } from './notification';
3
+ import { type NotificationRecipientWithConfig } from './notification.config';
4
+ import { type NotificationTemplateType } from './notification.id';
5
+ import { type FirebaseAuthUserId, type FirestoreDocumentAccessor, type ReadFirestoreModelKeyInput, type Transaction } from '../../common';
6
+ import { type NotificationItem } from './notification.item';
7
+ /**
8
+ * Template item for a new Notification
9
+ */
10
+ export interface CreateNotificationTemplateItem extends Omit<NotificationItem, 'r' | 'id' | 'cat'> {
11
+ /**
12
+ * Custom created at date for the item.
13
+ */
14
+ cat?: Maybe<Date>;
15
+ }
16
+ /**
17
+ * Template use for creating a new Notification
18
+ */
19
+ export interface CreateNotificationTemplate extends Partial<Omit<Notification, 'n' | 'a' | 'd' | 'tsr' | 'esr'>> {
20
+ /**
21
+ * Model key of the NotificationBox's target model (not the NotificationBox's key)
22
+ */
23
+ notificationModel: ModelKey;
24
+ /**
25
+ * Item template
26
+ */
27
+ n: CreateNotificationTemplateItem;
28
+ }
29
+ export interface CreateNotificationTemplateInput extends Partial<Omit<CreateNotificationTemplate, 'notificationModel'>>, Partial<Omit<CreateNotificationTemplateItem, 't'>> {
30
+ /**
31
+ * Model key input of the NotificationBox's target model (not the NotificationBox/key)
32
+ */
33
+ readonly notificationModel: ReadFirestoreModelKeyInput;
34
+ /**
35
+ * Template type
36
+ */
37
+ readonly type: NotificationTemplateType;
38
+ /**
39
+ * Overrides st
40
+ */
41
+ readonly sendType?: NotificationSendType;
42
+ /**
43
+ * Overrides r
44
+ */
45
+ readonly recipients?: NotificationRecipientWithConfig[];
46
+ /**
47
+ * Overrides cb
48
+ */
49
+ readonly createdBy?: Maybe<FirebaseAuthUserId>;
50
+ /**
51
+ * Overrides m
52
+ */
53
+ readonly targetModel?: Maybe<ReadFirestoreModelKeyInput>;
54
+ /**
55
+ * Overrides s
56
+ */
57
+ readonly subject?: Maybe<string>;
58
+ /**
59
+ * Overrides g
60
+ */
61
+ readonly message?: Maybe<string>;
62
+ /**
63
+ * Overrides d
64
+ */
65
+ readonly data?: Maybe<object>;
66
+ }
67
+ export declare function createNotificationTemplate(input: CreateNotificationTemplateInput): CreateNotificationTemplate;
68
+ export interface ShouldSendCreatedNotificationInput {
69
+ /**
70
+ * Whether or not to actually create/save the notification. Defaults to true.
71
+ */
72
+ readonly sendNotification?: Maybe<boolean>;
73
+ /**
74
+ * Date that can be provided to throttle sending notifications. If the throttle time has not elapsed since the last send then the notification will not be sent.
75
+ */
76
+ readonly sendNotificationThrottleDate?: Maybe<Date>;
77
+ /**
78
+ * Amount of time to throttle notifications. Only used if sendNotificationThrottleDate is provided. Defaults to 1 hour.
79
+ */
80
+ readonly sendNotificationThrottleTime?: Maybe<number>;
81
+ }
82
+ /**
83
+ * Returns true if the notification should be created/sent, given the input.
84
+ *
85
+ * @param input
86
+ * @returns
87
+ */
88
+ export declare function shouldSendCreatedNotificationInput(input: ShouldSendCreatedNotificationInput): boolean;
89
+ export interface CreateNotificationDocumentPairInput extends ShouldSendCreatedNotificationInput {
90
+ /**
91
+ * Additional flag controlling whether or not to create the notification.
92
+ */
93
+ readonly shouldCreateNotification?: Maybe<boolean>;
94
+ /**
95
+ * Template
96
+ */
97
+ readonly template: CreateNotificationTemplate;
98
+ /**
99
+ * Transaction, if available.
100
+ */
101
+ readonly transaction?: Maybe<Transaction>;
102
+ /**
103
+ * Context to create the accessor from.
104
+ */
105
+ readonly context?: Pick<NotificationFirestoreCollections, 'notificationCollectionFactory' | 'notificationBoxCollection'>;
106
+ /**
107
+ * Accessor to use directly.
108
+ */
109
+ readonly accessor?: FirestoreDocumentAccessor<Notification, NotificationDocument>;
110
+ }
111
+ export interface CreateNotificationDocumentPairResult {
112
+ readonly notificationDocument: NotificationDocument;
113
+ readonly notification: Notification;
114
+ /**
115
+ * Whether or not the notification was created.
116
+ */
117
+ readonly notificationCreated: boolean;
118
+ }
119
+ /**
120
+ * Creates a CreateNotificationDocumentPairResult from the input.
121
+ *
122
+ * Only creates a pair. Used createNotificationDocument() to also save the document's data.
123
+ *
124
+ * @param template
125
+ */
126
+ export declare function createNotificationDocumentPair(input: CreateNotificationDocumentPairInput): CreateNotificationDocumentPairResult;
127
+ /**
128
+ * Creates a new Notification and saves it to Firestore. Returns the pair.
129
+ *
130
+ * @param input
131
+ */
132
+ export declare function createNotificationDocument(input: CreateNotificationDocumentPairInput): Promise<CreateNotificationDocumentPairResult>;
133
+ /**
134
+ * Creates a new Notification and saves it to Firestore and returns the pair if sendNotification in the input is not false.
135
+ *
136
+ * @param input
137
+ * @returns
138
+ */
139
+ export declare function createNotificationDocumentIfSending(input: CreateNotificationDocumentPairInput): Promise<Maybe<CreateNotificationDocumentPairResult>>;