@dereekb/firebase 12.3.11 → 12.3.13

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dereekb/firebase",
3
- "version": "12.3.11",
3
+ "version": "12.3.13",
4
4
  "exports": {
5
5
  ".": {
6
6
  "types": "./src/index.d.ts",
@@ -211,6 +211,15 @@ export declare class UpdateNotificationBoxRecipientParams extends UpdateNotifica
211
211
  * Whether or not to remove the user if they exist. Defaults to false.
212
212
  */
213
213
  remove?: Maybe<boolean>;
214
+ /**
215
+ * If true, the target recipient will have this NotificationBox added to their exclusion list.
216
+ * If false, the target recipient will have this NotificationBox removed from their exclusion list.
217
+ *
218
+ * If set, the other functions are ignored.
219
+ *
220
+ * If targeting the user by the index, the NotificationBox must exist, and the user must have a uid, otherwise an error will be thrown.
221
+ */
222
+ setExclusion?: Maybe<boolean>;
214
223
  }
215
224
  export declare class NotificationRecipientParams {
216
225
  /**
@@ -258,6 +267,16 @@ export declare abstract class AbstractSubscribeOrUnsubscribeToNotificationBoxPar
258
267
  */
259
268
  unsubscribe?: Maybe<boolean>;
260
269
  }
270
+ export interface SendNotificationResultOnSendCompleteResult<T = unknown> {
271
+ /**
272
+ * Value, if returned by the onSendSuccess callback.
273
+ */
274
+ readonly value?: T;
275
+ /**
276
+ * Error value if the onSendSuccess callback throws an error.
277
+ */
278
+ readonly error?: Maybe<unknown>;
279
+ }
261
280
  export interface SendNotificationResult {
262
281
  /**
263
282
  * Attempted notification type
@@ -348,6 +367,14 @@ export interface SendNotificationResult {
348
367
  * Failed while attempting to build a message
349
368
  */
350
369
  readonly buildMessageFailure: boolean;
370
+ /**
371
+ * Result of the onSendAttempted callback, if called.
372
+ */
373
+ readonly onSendAttemptedResult?: Maybe<SendNotificationResultOnSendCompleteResult>;
374
+ /**
375
+ * Result of the onSendSuccess callback, if called.
376
+ */
377
+ readonly onSendSuccessResult?: Maybe<SendNotificationResultOnSendCompleteResult>;
351
378
  }
352
379
  /**
353
380
  * Used for sending queued notifications in the system.
@@ -3,6 +3,7 @@ export declare const NOTIFICATION_MODEL_ALREADY_INITIALIZED_ERROR_CODE = "NOTIFI
3
3
  export declare const NOTIFICATION_BOX_DOES_NOT_EXIST_ERROR_CODE = "NOTIFICATION_BOX_DOES_NOT_EXIST";
4
4
  export declare const NOTIFICATION_BOX_EXISTS_FOR_MODEL_ERROR_CODE = "NOTIFICATION_BOX_EXISTS_FOR_MODEL";
5
5
  export declare const NOTIFICATION_BOX_RECIPIENT_DOES_NOT_EXIST_ERROR_CODE = "NOTIFICATION_BOX_RECIPIENT_DOES_NOT_EXIST";
6
+ export declare const NOTIFICATION_BOX_EXCLUSION_TARGET_INVALID_ERROR_CODE = "NOTIFICATION_BOX_EXCLUSION_TARGET_INVALID";
6
7
  export declare const NOTIFICATION_USER_INVALID_UID_FOR_CREATE_ERROR_CODE = "NOTIFICATION_USER_INVALID_UID_FOR_CREATE";
7
8
  export declare const NOTIFICATION_USER_BLOCKED_FROM_BEING_ADD_TO_RECIPIENTS_ERROR_CODE = "NOTIFICATION_USER_BLOCKED_FROM_BEING_ADD_TO_RECIPIENTS";
8
9
  export declare const NOTIFICATION_USER_LOCKED_CONFIG_FROM_BEING_UPDATED_ERROR_CODE = "NOTIFICATION_USER_LOCKED_CONFIG_FROM_BEING_UPDATED";
@@ -29,7 +29,7 @@ export interface NotificationBoxRecipientTemplateConfig {
29
29
  sn?: Maybe<boolean>;
30
30
  }
31
31
  export declare function mergeNotificationBoxRecipientTemplateConfigs(a?: Maybe<NotificationBoxRecipientTemplateConfig>, b?: Maybe<NotificationBoxRecipientTemplateConfig>): NotificationBoxRecipientTemplateConfig;
32
- export declare function effectiveNotificationBoxRecipientTemplateConfig(x: NotificationBoxRecipientTemplateConfig): NotificationBoxRecipientTemplateConfig;
32
+ export declare function effectiveNotificationBoxRecipientTemplateConfig(a: NotificationBoxRecipientTemplateConfig): NotificationBoxRecipientTemplateConfig;
33
33
  /**
34
34
  * Recipient configuration for a notification
35
35
  */
@@ -83,6 +83,12 @@ export declare enum NotificationBoxRecipientFlag {
83
83
  * If uid is set, then most other NotificationRecipient fields are ignored as those are pulled from auth.
84
84
  */
85
85
  export interface NotificationBoxRecipient extends NotificationRecipient, IndexRef {
86
+ /**
87
+ * Whether or not this recipient has been marked as excluded.
88
+ *
89
+ * This can only be updated by removing the exclusion from the.
90
+ */
91
+ x?: Maybe<SavedToFirestoreIfTrue>;
86
92
  /**
87
93
  * Enabled config types
88
94
  */
@@ -104,7 +110,7 @@ export declare function newNotificationBoxRecipientForUid(uid: FirebaseAuthUserI
104
110
  /**
105
111
  * Default NotificationUserNotificationBoxRecipientConfig.
106
112
  */
107
- export interface NotificationUserDefaultNotificationBoxRecipientConfig extends Omit<NotificationBoxRecipient, 'i' | 'n' | 's' | 'uid'> {
113
+ export interface NotificationUserDefaultNotificationBoxRecipientConfig extends Omit<NotificationBoxRecipient, 'i' | 'n' | 's' | 'uid' | 'x'> {
108
114
  /**
109
115
  * Locked state.
110
116
  *
@@ -1,6 +1,6 @@
1
1
  import { type E164PhoneNumber, type EmailAddress, type Maybe, type NeedsSyncBoolean } from '@dereekb/util';
2
2
  import { type GrantedReadRole, type GrantedUpdateRole } from '@dereekb/model';
3
- import { type NotificationBoxId } from './notification.id';
3
+ import { NotificationBoxSendExclusionList, type NotificationBoxId } from './notification.id';
4
4
  import { type NotificationBoxRecipient, type NotificationRecipientWithConfig, type NotificationUserNotificationBoxRecipientConfig, type NotificationUserDefaultNotificationBoxRecipientConfig } from './notification.config';
5
5
  import { type YearWeekCode } from '@dereekb/date';
6
6
  import { type UserRelatedById, type UserRelated } from '../user';
@@ -48,6 +48,18 @@ export interface NotificationUser extends UserRelated, UserRelatedById {
48
48
  * List of notification boxes this user is associated with. Cannot be changed directly.
49
49
  */
50
50
  b: NotificationBoxId[];
51
+ /**
52
+ * Notification box id exclusion list. This value is treated used to generated send opt-outs.
53
+ *
54
+ * This list is used to exclude a user from recieving notifications from the NotificationBoxes in this list.
55
+ *
56
+ * Values in this list are usually populated from functions from the model controlling the NotificationBox.
57
+ *
58
+ * The user must be associated with atleast one NotificationBoxId that matches items in this list, otherwise non-matching items are removed.
59
+ *
60
+ * The exclusions are sync'd to the corresponding bc values, which are then sync'd to the NotificationBoxes.
61
+ */
62
+ x: NotificationBoxSendExclusionList;
51
63
  /**
52
64
  * Global config override.
53
65
  *
@@ -1,10 +1,22 @@
1
1
  import { type FactoryWithRequiredInput } from '@dereekb/util';
2
- import { type FirestoreModelId, type FirestoreModelKey, type FlatFirestoreModelKey, twoWayFlatFirestoreModelKey, inferKeyFromTwoWayFlatFirestoreModelKey, type FirebaseAuthUserId, type RootFirestoreModelIdentity, FirestoreModelIdInput } from '../../common';
2
+ import { type FirestoreModelId, type FirestoreModelKey, type FlatFirestoreModelKey, twoWayFlatFirestoreModelKey, inferKeyFromTwoWayFlatFirestoreModelKey, type FirebaseAuthUserId, type RootFirestoreModelIdentity, FirestoreModelIdInput, FirestoreCollectionName } from '../../common';
3
3
  /**
4
4
  * The NotificationBox's id is the two way flat firestore model key of the object that it represents.
5
5
  */
6
6
  export type NotificationBoxId = FlatFirestoreModelKey;
7
7
  export type NotificationBoxKey = FirestoreModelKey;
8
+ /**
9
+ * A notification box id (or firestore collection name) that is used to exclude a user from receiving notifications from that box or any notification boxes that start with the same prefix.
10
+ *
11
+ * This is used in cases where a user might be removed from access temporarily and should not recieve any notifications from that box or any child boxes.
12
+ *
13
+ * For example, if a box with id ab_123 is excluded, then any notifications to child boxes that start with ab_123 (e.g. ab_123_cd_456) will also be excluded.
14
+ */
15
+ export type NotificationBoxSendExclusion = FirestoreCollectionName | NotificationBoxId;
16
+ /**
17
+ * List of notification box exclusions.
18
+ */
19
+ export type NotificationBoxSendExclusionList = NotificationBoxSendExclusion[];
8
20
  /**
9
21
  * Creates a NotificationBoxId from the input FirestoreModelKey.
10
22
  *
@@ -1,8 +1,9 @@
1
- import { type Maybe, type WebsiteUrl } from '@dereekb/util';
1
+ import { PromiseOrValue, type Maybe, type WebsiteUrl } from '@dereekb/util';
2
2
  import { type NotificationRecipient, type NotificationRecipientWithConfig } from './notification.config';
3
- import { type Notification, type NotificationBox } from './notification';
3
+ import { NotificationSendFlags, type Notification, type NotificationBox } from './notification';
4
4
  import { type NotificationItem, type NotificationItemMetadata } from './notification.item';
5
5
  import { type DocumentDataWithIdAndKey } from '../../common';
6
+ import { NotificationSendEmailMessagesResult, NotificationSendTextMessagesResult, NotificationSendNotificationSummaryMessagesResult } from './notification.send';
6
7
  /**
7
8
  * Contextual information when
8
9
  */
@@ -130,11 +131,27 @@ export interface NotificationMessageFunctionFactoryConfig<D extends Notification
130
131
  * Creates a NotificationMessageFunction from the input config.
131
132
  */
132
133
  export type NotificationMessageFunctionFactory<D extends NotificationItemMetadata = {}> = (config: NotificationMessageFunctionFactoryConfig<D>) => Promise<NotificationMessageFunction>;
134
+ export interface NotificationMessageFunctionExtrasCallbackDetails {
135
+ readonly success: boolean;
136
+ readonly updatedSendFlags: NotificationSendFlags;
137
+ readonly sendEmailsResult?: Maybe<NotificationSendEmailMessagesResult>;
138
+ readonly sendTextsResult?: Maybe<NotificationSendTextMessagesResult>;
139
+ readonly sendNotificationSummaryResult?: Maybe<NotificationSendNotificationSummaryMessagesResult>;
140
+ }
141
+ export type NotificationMessageFunctionExtrasCallbackFunction = (callbackDetails: NotificationMessageFunctionExtrasCallbackDetails) => PromiseOrValue<unknown>;
133
142
  export interface NotificationMessageFunctionExtras {
134
143
  /**
135
144
  * Any global/additional recipient(s) that should be added to all Notifications associated with this NotificationMessageFunctionExtras.
136
145
  */
137
146
  readonly globalRecipients?: Maybe<NotificationRecipientWithConfig[]>;
147
+ /**
148
+ * Called each time the notification attempts to send something.
149
+ */
150
+ readonly onSendAttempted?: NotificationMessageFunctionExtrasCallbackFunction;
151
+ /**
152
+ * Called when the notification has is marked as done after sending to all recipients.
153
+ */
154
+ readonly onSendSuccess?: NotificationMessageFunctionExtrasCallbackFunction;
138
155
  }
139
156
  export type NotificationMessageFunctionWithoutExtras = (inputContext: NotificationMessageInputContext) => Promise<NotificationMessage>;
140
157
  /**
@@ -1,4 +1,6 @@
1
1
  import { type FirestoreQueryConstraint } from '../../common/firestore';
2
+ import { NotificationBoxSendExclusion } from './notification.id';
3
+ import { type ArrayOrValue } from '@dereekb/util';
2
4
  /**
3
5
  * Query for notificationUsers that are flagged for initialization.
4
6
  *
@@ -6,6 +8,13 @@ import { type FirestoreQueryConstraint } from '../../common/firestore';
6
8
  * @returns
7
9
  */
8
10
  export declare function notificationUsersFlaggedForNeedsSyncQuery(): FirestoreQueryConstraint[];
11
+ /**
12
+ * Query for notificationUsers that have excluded any of the input notification box ids.
13
+ *
14
+ * @param now
15
+ * @returns
16
+ */
17
+ export declare function notificationUserHasExclusionQuery(exclusionId: ArrayOrValue<NotificationBoxSendExclusion>): FirestoreQueryConstraint[];
9
18
  /**
10
19
  * Query for notificationSummaries that are flagged for initialization.
11
20
  *
@@ -1,8 +1,9 @@
1
- import { type Maybe } from '@dereekb/util';
2
- import { type Notification, type NotificationBox, type NotificationBoxDocument, NotificationRecipientSendFlag, type NotificationSendFlags, NotificationSendState } from './notification';
1
+ import { ArrayOrValue, type Maybe } from '@dereekb/util';
2
+ import { type Notification, type NotificationBox, type NotificationBoxDocument, NotificationRecipientSendFlag, type NotificationSendFlags, NotificationSendState, NotificationUser } from './notification';
3
3
  import { type NotificationUserNotificationBoxRecipientConfig, type NotificationBoxRecipient, type NotificationUserDefaultNotificationBoxRecipientConfig } from './notification.config';
4
4
  import { type AppNotificationTemplateTypeInfoRecordService } from './notification.details';
5
5
  import { type FirebaseAuthUserId, type FirestoreDocumentAccessor, type FirestoreModelKey } from '../../common';
6
+ import { NotificationBoxId, NotificationId, NotificationBoxSendExclusionList, NotificationBoxSendExclusion } from './notification.id';
6
7
  export interface EffectiveNotificationBoxRecipientConfigInput {
7
8
  readonly uid: FirebaseAuthUserId;
8
9
  readonly m?: FirestoreModelKey;
@@ -12,6 +13,32 @@ export interface EffectiveNotificationBoxRecipientConfigInput {
12
13
  readonly recipient?: Maybe<NotificationBoxRecipient>;
13
14
  }
14
15
  export declare function effectiveNotificationBoxRecipientConfig(input: EffectiveNotificationBoxRecipientConfigInput): NotificationBoxRecipient;
16
+ export interface UpdateNotificationUserNotificationSendExclusionsInput {
17
+ readonly notificationUser: Pick<NotificationUser, 'b' | 'x' | 'bc'>;
18
+ readonly addExclusions?: ArrayOrValue<NotificationBoxSendExclusion>;
19
+ readonly removeExclusions?: ArrayOrValue<NotificationBoxSendExclusion>;
20
+ }
21
+ export interface UpdateNotificationUserNotificationSendExclusionsResult {
22
+ readonly nextExclusions: NotificationBoxSendExclusionList;
23
+ readonly update: Pick<NotificationUser, 'x' | 'ns' | 'bc'>;
24
+ }
25
+ export declare function updateNotificationUserNotificationSendExclusions(input: UpdateNotificationUserNotificationSendExclusionsInput): UpdateNotificationUserNotificationSendExclusionsResult;
26
+ export interface ApplyExclusionsToNotificationUserNotificationBoxRecipientConfigsParams {
27
+ readonly x?: NotificationBoxSendExclusionList;
28
+ readonly bc?: Maybe<NotificationUserNotificationBoxRecipientConfig[]>;
29
+ readonly notificationUser?: Pick<NotificationUser, 'bc' | 'x'>;
30
+ readonly recalculateNs?: boolean;
31
+ }
32
+ export type ApplyExclusionsToNotificationUserNotificationBoxRecipientConfigsResult = Pick<NotificationUser, 'bc' | 'ns'>;
33
+ export declare function applyExclusionsToNotificationUserNotificationBoxRecipientConfigs(params: ApplyExclusionsToNotificationUserNotificationBoxRecipientConfigsParams): ApplyExclusionsToNotificationUserNotificationBoxRecipientConfigsResult;
34
+ export declare function calculateNsForNotificationUserNotificationBoxRecipientConfigs(configs: NotificationUserNotificationBoxRecipientConfig[]): boolean;
35
+ /**
36
+ * Function that returns true if the notification is not excluded from being sent.
37
+ */
38
+ export type NotificationSendExclusionCanSendFunction = ((notification: NotificationId | NotificationBoxId) => boolean) & {
39
+ readonly _exclusions: NotificationBoxSendExclusionList;
40
+ };
41
+ export declare const notificationSendExclusionCanSendFunction: (exclusions: NotificationBoxSendExclusionList) => NotificationSendExclusionCanSendFunction;
15
42
  /**
16
43
  * Returns true if the notification's send types are all marked as sent.
17
44
  *
package/test/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
4
 
5
+ ## [12.3.13](https://github.com/dereekb/dbx-components/compare/v12.3.12-dev...v12.3.13) (2025-08-22)
6
+
7
+
8
+
9
+ ## [12.3.12](https://github.com/dereekb/dbx-components/compare/v12.3.11-dev...v12.3.12) (2025-08-20)
10
+
11
+
12
+
5
13
  ## [12.3.11](https://github.com/dereekb/dbx-components/compare/v12.3.10-dev...v12.3.11) (2025-08-19)
6
14
 
7
15
 
package/test/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dereekb/firebase/test",
3
- "version": "12.3.11",
3
+ "version": "12.3.13",
4
4
  "type": "commonjs",
5
5
  "peerDependencies": {
6
6
  "@dereekb/util": "*",