@dereekb/firebase-server 13.2.1 → 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.
- package/index.cjs.js +7506 -1884
- package/index.esm.js +7505 -1890
- package/mailgun/index.cjs.js +333 -31
- package/mailgun/index.esm.js +333 -31
- package/mailgun/package.json +8 -8
- package/mailgun/src/lib/auth.mailgun.d.ts +22 -3
- package/model/index.cjs.js +11334 -3830
- package/model/index.esm.js +11338 -3834
- package/model/package.json +8 -8
- package/model/src/lib/mailgun/notification.send.service.mailgun.d.ts +27 -1
- package/model/src/lib/notification/notification.action.init.service.d.ts +93 -1
- package/model/src/lib/notification/notification.action.service.d.ts +151 -2
- package/model/src/lib/notification/notification.config.d.ts +19 -7
- package/model/src/lib/notification/notification.config.service.d.ts +44 -6
- package/model/src/lib/notification/notification.create.run.d.ts +33 -5
- package/model/src/lib/notification/notification.error.d.ts +63 -0
- package/model/src/lib/notification/notification.module.d.ts +11 -0
- package/model/src/lib/notification/notification.send.d.ts +8 -1
- package/model/src/lib/notification/notification.send.service.d.ts +7 -1
- package/model/src/lib/notification/notification.send.service.notificationsummary.d.ts +32 -2
- package/model/src/lib/notification/notification.send.service.text.d.ts +11 -3
- package/model/src/lib/notification/notification.task.service.d.ts +13 -1
- package/model/src/lib/notification/notification.task.service.handler.d.ts +27 -3
- package/model/src/lib/notification/notification.task.service.util.d.ts +16 -4
- package/model/src/lib/notification/notification.task.subtask.handler.d.ts +31 -1
- package/model/src/lib/notification/notification.util.d.ts +70 -0
- package/model/src/lib/storagefile/storagefile.action.init.service.d.ts +62 -1
- package/model/src/lib/storagefile/storagefile.action.server.d.ts +124 -2
- package/model/src/lib/storagefile/storagefile.error.d.ts +44 -0
- package/model/src/lib/storagefile/storagefile.module.d.ts +11 -0
- package/model/src/lib/storagefile/storagefile.task.service.handler.d.ts +4 -1
- package/model/src/lib/storagefile/storagefile.upload.service.d.ts +13 -1
- package/model/src/lib/storagefile/storagefile.upload.service.initializer.d.ts +43 -1
- package/model/src/lib/storagefile/storagefile.util.d.ts +8 -0
- package/oidc/index.cjs.default.js +1 -0
- package/oidc/index.cjs.js +5607 -0
- package/oidc/index.cjs.mjs +2 -0
- package/oidc/index.d.ts +1 -0
- package/oidc/index.esm.js +5560 -0
- package/oidc/package.json +26 -0
- package/oidc/src/index.d.ts +1 -0
- package/oidc/src/lib/controller/index.d.ts +3 -0
- package/oidc/src/lib/controller/oidc.interaction.controller.d.ts +54 -0
- package/oidc/src/lib/controller/oidc.provider.controller.d.ts +18 -0
- package/oidc/src/lib/controller/oidc.wellknown.controller.d.ts +36 -0
- package/oidc/src/lib/index.d.ts +6 -0
- package/oidc/src/lib/middleware/index.d.ts +3 -0
- package/oidc/src/lib/middleware/oauth-auth.decorator.d.ts +14 -0
- package/oidc/src/lib/middleware/oauth-auth.middleware.d.ts +21 -0
- package/oidc/src/lib/middleware/oauth-auth.module.d.ts +50 -0
- package/oidc/src/lib/model/index.d.ts +3 -0
- package/oidc/src/lib/model/jwks/index.d.ts +3 -0
- package/oidc/src/lib/model/jwks/jwks.d.ts +107 -0
- package/oidc/src/lib/model/jwks/jwks.id.d.ts +9 -0
- package/oidc/src/lib/model/jwks/jwks.query.d.ts +18 -0
- package/oidc/src/lib/model/model.d.ts +12 -0
- package/oidc/src/lib/model/oidc/index.d.ts +2 -0
- package/oidc/src/lib/model/oidc/oidcmodel.action.server.d.ts +62 -0
- package/oidc/src/lib/model/oidc/oidcmodel.module.d.ts +23 -0
- package/oidc/src/lib/oidc.config.d.ts +175 -0
- package/oidc/src/lib/oidc.module.d.ts +100 -0
- package/oidc/src/lib/service/index.d.ts +10 -0
- package/oidc/src/lib/service/oidc.account.d.ts +36 -0
- package/oidc/src/lib/service/oidc.account.service.d.ts +104 -0
- package/oidc/src/lib/service/oidc.adapter.service.d.ts +20 -0
- package/oidc/src/lib/service/oidc.auth.d.ts +26 -0
- package/oidc/src/lib/service/oidc.client.service.d.ts +57 -0
- package/oidc/src/lib/service/oidc.config.service.d.ts +100 -0
- package/oidc/src/lib/service/oidc.encryption.service.d.ts +53 -0
- package/oidc/src/lib/service/oidc.interaction.service.d.ts +44 -0
- package/oidc/src/lib/service/oidc.jwks.service.d.ts +105 -0
- package/oidc/src/lib/service/oidc.service.d.ts +55 -0
- package/package.json +15 -9
- package/src/lib/auth/auth.context.d.ts +22 -2
- package/src/lib/auth/auth.service.d.ts +5 -0
- package/src/lib/auth/auth.service.error.d.ts +2 -1
- package/src/lib/auth/auth.util.d.ts +15 -3
- package/src/lib/env/env.config.d.ts +42 -0
- package/src/lib/env/env.service.d.ts +17 -0
- package/src/lib/env/index.d.ts +1 -0
- package/src/lib/firestore/array.d.ts +11 -3
- package/src/lib/firestore/driver.accessor.batch.d.ts +27 -4
- package/src/lib/firestore/driver.accessor.d.ts +43 -0
- package/src/lib/firestore/driver.accessor.default.d.ts +20 -0
- package/src/lib/firestore/driver.accessor.transaction.d.ts +28 -4
- package/src/lib/firestore/driver.d.ts +14 -0
- package/src/lib/firestore/driver.query.d.ts +25 -0
- package/src/lib/firestore/increment.d.ts +13 -3
- package/src/lib/firestore/snapshot/index.d.ts +1 -1
- package/src/lib/firestore/snapshot/{snapshot.field.d.ts → snapshot.field.encrypt.d.ts} +13 -27
- package/src/lib/function/assert.d.ts +32 -16
- package/src/lib/function/context.d.ts +26 -0
- package/src/lib/function/error.auth.d.ts +15 -0
- package/src/lib/function/error.d.ts +68 -4
- package/src/lib/nest/app.d.ts +53 -9
- package/src/lib/nest/app.module.d.ts +90 -0
- package/src/lib/nest/auth/auth.module.d.ts +30 -4
- package/src/lib/nest/auth/auth.util.d.ts +38 -0
- package/src/lib/nest/controller/auth.context.server.d.ts +27 -0
- package/src/lib/nest/controller/index.d.ts +1 -0
- package/src/lib/nest/development/development.app.function.d.ts +45 -0
- package/src/lib/nest/development/development.assert.function.d.ts +19 -1
- package/src/lib/nest/development/development.function.d.ts +42 -3
- package/src/lib/nest/development/development.schedule.function.d.ts +29 -0
- package/src/lib/nest/development/development.schedule.function.error.d.ts +21 -0
- package/src/lib/nest/env/env.service.d.ts +9 -0
- package/src/lib/nest/env/env.util.d.ts +16 -0
- package/src/lib/nest/firebase/firebase.module.d.ts +13 -1
- package/src/lib/nest/firestore/firestore.module.d.ts +24 -8
- package/src/lib/nest/function/call.d.ts +75 -6
- package/src/lib/nest/function/context.d.ts +85 -2
- package/src/lib/nest/function/nest.d.ts +46 -0
- package/src/lib/nest/function/schedule.d.ts +49 -0
- package/src/lib/nest/function/v2/blocking.d.ts +92 -8
- package/src/lib/nest/function/v2/call.d.ts +38 -8
- package/src/lib/nest/function/v2/event.d.ts +67 -4
- package/src/lib/nest/function/v2/schedule.d.ts +36 -5
- package/src/lib/nest/index.d.ts +3 -0
- package/src/lib/nest/middleware/appcheck.d.ts +5 -0
- package/src/lib/nest/middleware/appcheck.middleware.d.ts +44 -14
- package/src/lib/nest/middleware/appcheck.module.d.ts +10 -1
- package/src/lib/nest/middleware/globalprefix.d.ts +31 -3
- package/src/lib/nest/middleware/index.d.ts +2 -1
- package/src/lib/nest/middleware/rawbody.middleware.d.ts +6 -0
- package/src/lib/nest/model/call.model.function.d.ts +69 -3
- package/src/lib/nest/model/create.model.function.d.ts +66 -0
- package/src/lib/nest/model/crud.assert.function.d.ts +27 -1
- package/src/lib/nest/model/delete.model.function.d.ts +55 -0
- package/src/lib/nest/model/permission.error.d.ts +15 -0
- package/src/lib/nest/model/read.model.function.d.ts +57 -0
- package/src/lib/nest/model/specifier.function.d.ts +58 -1
- package/src/lib/nest/model/update.model.function.d.ts +58 -0
- package/src/lib/nest/nest.provider.d.ts +24 -11
- package/src/lib/nest/nest.provider.server.d.ts +12 -0
- package/src/lib/nest/storage/storage.module.d.ts +30 -4
- package/src/lib/storage/driver.accessor.d.ts +33 -0
- package/src/lib/storage/driver.d.ts +14 -0
- package/src/lib/storage/storage.d.ts +11 -4
- package/src/lib/storage/storage.service.d.ts +10 -1
- package/src/lib/type.d.ts +7 -2
- package/test/index.cjs.js +4072 -757
- package/test/index.esm.js +4073 -761
- package/test/package.json +8 -8
- package/test/src/lib/firebase/firebase.admin.auth.d.ts +82 -1
- package/test/src/lib/firebase/firebase.admin.collection.d.ts +55 -3
- package/test/src/lib/firebase/firebase.admin.d.ts +64 -0
- package/test/src/lib/firebase/firebase.admin.function.d.ts +84 -0
- package/test/src/lib/firebase/firebase.admin.nest.d.ts +125 -17
- package/test/src/lib/firebase/firebase.admin.nest.function.callable.context.d.ts +44 -0
- package/test/src/lib/firebase/firebase.admin.nest.function.cloud.context.d.ts +41 -0
- package/test/src/lib/firebase/firebase.admin.nest.function.d.ts +98 -0
- package/test/src/lib/firebase/firebase.admin.test.server.d.ts +26 -0
- package/test/src/lib/firebase/firebase.d.ts +57 -2
- package/test/src/lib/firebase/firebase.function.d.ts +138 -0
- package/test/src/lib/firestore/firestore.admin.d.ts +6 -0
- package/test/src/lib/firestore/firestore.d.ts +30 -0
- package/test/src/lib/storage/storage.admin.d.ts +9 -3
- package/test/src/lib/storage/storage.d.ts +30 -0
- package/zoho/index.cjs.js +406 -73
- package/zoho/index.esm.js +406 -73
- package/zoho/package.json +8 -8
- package/zoho/src/lib/zoho.accounts.firebase.d.ts +13 -2
- package/zoho/src/lib/zoho.accounts.firebase.system.d.ts +29 -6
- package/index.cjs.js.map +0 -1
- package/index.esm.js.map +0 -1
- /package/src/lib/nest/middleware/{webhook.d.ts → webhook.module.d.ts} +0 -0
package/model/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dereekb/firebase-server/model",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.3.0",
|
|
4
4
|
"peerDependencies": {
|
|
5
|
-
"@dereekb/date": "13.
|
|
6
|
-
"@dereekb/firebase": "13.
|
|
7
|
-
"@dereekb/firebase-server": "13.
|
|
8
|
-
"@dereekb/model": "13.
|
|
9
|
-
"@dereekb/nestjs": "13.
|
|
10
|
-
"@dereekb/rxjs": "13.
|
|
11
|
-
"@dereekb/util": "13.
|
|
5
|
+
"@dereekb/date": "13.3.0",
|
|
6
|
+
"@dereekb/firebase": "13.3.0",
|
|
7
|
+
"@dereekb/firebase-server": "13.3.0",
|
|
8
|
+
"@dereekb/model": "13.3.0",
|
|
9
|
+
"@dereekb/nestjs": "13.3.0",
|
|
10
|
+
"@dereekb/rxjs": "13.3.0",
|
|
11
|
+
"@dereekb/util": "13.3.0",
|
|
12
12
|
"@nestjs/common": "^11.0.0",
|
|
13
13
|
"@nestjs/config": "^4.0.0",
|
|
14
14
|
"archiver": "^7.0.0",
|
|
@@ -20,7 +20,7 @@ export interface MailgunNotificationEmailSendServiceTemplateBuilderInput {
|
|
|
20
20
|
readonly messages: NotificationMessage[];
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
23
|
+
* Configuration for creating a {@link MailgunNotificationEmailSendService} via {@link mailgunNotificationEmailSendService}.
|
|
24
24
|
*/
|
|
25
25
|
export interface MailgunNotificationEmailSendServiceConfig {
|
|
26
26
|
/**
|
|
@@ -47,5 +47,31 @@ export declare const MAILGUN_NOTIFICATION_EMAIL_SEND_SERVICE_DEFAULT_MAX_BATCH_S
|
|
|
47
47
|
* Function that converts the input into zero or more MailgunTemplateEmailRequests.
|
|
48
48
|
*/
|
|
49
49
|
export type MailgunNotificationEmailSendServiceTemplateBuilder = (input: MailgunNotificationEmailSendServiceTemplateBuilderInput) => PromiseOrValue<ArrayOrValue<MailgunTemplateEmailRequest>>;
|
|
50
|
+
/**
|
|
51
|
+
* Mailgun-backed implementation of {@link NotificationEmailSendService}.
|
|
52
|
+
*/
|
|
50
53
|
export type MailgunNotificationEmailSendService = NotificationEmailSendService;
|
|
54
|
+
/**
|
|
55
|
+
* Creates a {@link NotificationEmailSendService} that sends notification emails via Mailgun.
|
|
56
|
+
*
|
|
57
|
+
* Groups messages by their send template name, batches them (up to `maxBatchSizePerRequest`),
|
|
58
|
+
* converts each batch to a {@link MailgunTemplateEmailRequest} using the configured template builders,
|
|
59
|
+
* and dispatches them through the Mailgun API.
|
|
60
|
+
*
|
|
61
|
+
* @param config - service configuration including the Mailgun service, template builders, and batch size
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* const emailService = mailgunNotificationEmailSendService({
|
|
66
|
+
* mailgunService,
|
|
67
|
+
* defaultSendTemplateName: 'notification',
|
|
68
|
+
* messageBuilders: {
|
|
69
|
+
* notification: buildNotificationTemplate
|
|
70
|
+
* }
|
|
71
|
+
* });
|
|
72
|
+
*
|
|
73
|
+
* const sendInstance = await emailService.buildSendInstanceForEmailNotificationMessages(messages);
|
|
74
|
+
* const result = await sendInstance();
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
51
77
|
export declare function mailgunNotificationEmailSendService(config: MailgunNotificationEmailSendServiceConfig): MailgunNotificationEmailSendService;
|
|
@@ -4,9 +4,15 @@ import { type Maybe } from '@dereekb/util';
|
|
|
4
4
|
import { type TransformAndValidateFunctionResult } from '@dereekb/model';
|
|
5
5
|
import { type InjectionToken } from '@nestjs/common';
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* NestJS injection token for the {@link NotificationInitServerActionsContextConfig},
|
|
8
|
+
* which provides the template functions used during {@link NotificationBox} and
|
|
9
|
+
* {@link NotificationSummary} initialization.
|
|
8
10
|
*/
|
|
9
11
|
export declare const NOTIFICATION_INIT_SERVER_ACTIONS_CONTEXT_CONFIG_TOKEN: InjectionToken;
|
|
12
|
+
/**
|
|
13
|
+
* Configuration providing the template functions that determine how notification models
|
|
14
|
+
* (boxes and summaries) are initialized for a given Firestore model.
|
|
15
|
+
*/
|
|
10
16
|
export interface NotificationInitServerActionsContextConfig {
|
|
11
17
|
/**
|
|
12
18
|
* MakeTemplateForNotificationBoxInitializationFunction used by the system for initializing the NotificationBoxes for models.
|
|
@@ -17,6 +23,10 @@ export interface NotificationInitServerActionsContextConfig {
|
|
|
17
23
|
*/
|
|
18
24
|
readonly makeTemplateForNotificationSummaryInitialization: MakeTemplateForNotificationSummaryInitializationFunction;
|
|
19
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Input passed to the template function during notification model initialization,
|
|
28
|
+
* providing the Firestore transaction context and the model identity being initialized.
|
|
29
|
+
*/
|
|
20
30
|
export interface MakeTemplateForNotificationRelatedModelInitializationFunctionInput {
|
|
21
31
|
readonly transaction: Transaction;
|
|
22
32
|
readonly flatModelKey: TwoWayFlatFirestoreModelKey;
|
|
@@ -38,15 +48,46 @@ export type MakeTemplateForNotificationRelatedModelInitializationFunctionResult<
|
|
|
38
48
|
export type MakeTemplateForNotificationRelatedModelInitializationFunction<T> = (input: MakeTemplateForNotificationRelatedModelInitializationFunctionInput) => Promise<MakeTemplateForNotificationRelatedModelInitializationFunctionResult<T>>;
|
|
39
49
|
export type MakeTemplateForNotificationBoxInitializationFunction = MakeTemplateForNotificationRelatedModelInitializationFunction<NotificationBox>;
|
|
40
50
|
export type MakeTemplateForNotificationSummaryInitializationFunction = MakeTemplateForNotificationRelatedModelInitializationFunction<NotificationSummary>;
|
|
51
|
+
/**
|
|
52
|
+
* Full context for notification initialization actions, combining Firebase infrastructure,
|
|
53
|
+
* notification Firestore collections, and the initialization template functions.
|
|
54
|
+
*/
|
|
41
55
|
export interface NotificationInitServerActionsContext extends FirebaseServerActionsContext, NotificationFirestoreCollections, FirestoreContextReference, NotificationInitServerActionsContextConfig {
|
|
42
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Abstract service defining initialization actions for notification models.
|
|
59
|
+
*
|
|
60
|
+
* Provides methods to initialize individual {@link NotificationBox}/{@link NotificationSummary}
|
|
61
|
+
* documents or batch-process all uninitialized ones. Initialization uses the app-specific
|
|
62
|
+
* template functions from {@link NotificationInitServerActionsContextConfig} to determine
|
|
63
|
+
* the initial state for each model.
|
|
64
|
+
*
|
|
65
|
+
* @see {@link notificationInitServerActions} for the concrete implementation factory.
|
|
66
|
+
*/
|
|
43
67
|
export declare abstract class NotificationInitServerActions {
|
|
44
68
|
abstract initializeNotificationBox(params: InitializeNotificationModelParams): AsyncNotificationBoxUpdateAction<InitializeNotificationModelParams>;
|
|
45
69
|
abstract initializeAllApplicableNotificationBoxes(params: InitializeAllApplicableNotificationBoxesParams): Promise<TransformAndValidateFunctionResult<InitializeAllApplicableNotificationBoxesParams, () => Promise<InitializeAllApplicableNotificationBoxesResult>>>;
|
|
46
70
|
abstract initializeNotificationSummary(params: InitializeNotificationModelParams): AsyncNotificationSummaryUpdateAction<InitializeNotificationModelParams>;
|
|
47
71
|
abstract initializeAllApplicableNotificationSummaries(params: InitializeAllApplicableNotificationSummariesParams): Promise<TransformAndValidateFunctionResult<InitializeAllApplicableNotificationSummariesParams, () => Promise<InitializeAllApplicableNotificationSummariesResult>>>;
|
|
48
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* Creates a concrete {@link NotificationInitServerActions} implementation by wiring each
|
|
75
|
+
* initialization action to its factory function.
|
|
76
|
+
*
|
|
77
|
+
* @param context - the initialization context with template functions and Firestore access
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* const initActions = notificationInitServerActions(context);
|
|
82
|
+
* const initBox = await initActions.initializeNotificationBox({ key: modelKey });
|
|
83
|
+
* await initBox(notificationBoxDocument);
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
49
86
|
export declare function notificationInitServerActions(context: NotificationInitServerActionsContext): NotificationInitServerActions;
|
|
87
|
+
/**
|
|
88
|
+
* Input for {@link initializeNotificationModelInTransaction}, providing the document,
|
|
89
|
+
* its current data, the template function, and the transaction context.
|
|
90
|
+
*/
|
|
50
91
|
export interface InitializeNotificationModelInTransactionInput<D extends FirestoreDocument<InitializedNotificationModel, any>> {
|
|
51
92
|
readonly makeTemplateFunction: MakeTemplateForNotificationRelatedModelInitializationFunction<FirestoreDocumentData<D>>;
|
|
52
93
|
readonly throwErrorIfAlreadyInitialized?: Maybe<boolean>;
|
|
@@ -54,19 +95,70 @@ export interface InitializeNotificationModelInTransactionInput<D extends Firesto
|
|
|
54
95
|
readonly document: D;
|
|
55
96
|
readonly data: FirestoreDocumentData<D>;
|
|
56
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Initializes a notification model document (box or summary) within a Firestore transaction.
|
|
100
|
+
*
|
|
101
|
+
* Uses the provided template function to determine the initial state:
|
|
102
|
+
* - Returns a partial template → applies it and marks as initialized (`s=null`)
|
|
103
|
+
* - Returns `null`/`undefined` → marks the model as invalid (`fi=true`)
|
|
104
|
+
* - Returns `false` → deletes the document entirely
|
|
105
|
+
*
|
|
106
|
+
* Skips initialization if the model is already initialized, optionally throwing an error.
|
|
107
|
+
*
|
|
108
|
+
* @param input - the document, transaction, template function, and options
|
|
109
|
+
* @throws notificationModelAlreadyInitializedError when `throwErrorIfAlreadyInitialized` is true
|
|
110
|
+
*/
|
|
57
111
|
export declare function initializeNotificationModelInTransaction<D extends FirestoreDocument<InitializedNotificationModel, any>>(input: InitializeNotificationModelInTransactionInput<D>): Promise<{
|
|
58
112
|
initialized: boolean;
|
|
59
113
|
alreadyInitialized: boolean;
|
|
60
114
|
}>;
|
|
115
|
+
/**
|
|
116
|
+
* Factory for initializing a single {@link NotificationBox} within a Firestore transaction.
|
|
117
|
+
*
|
|
118
|
+
* Loads the box document in the transaction, reads its current data, and delegates
|
|
119
|
+
* to {@link initializeNotificationModelInTransaction} with the box-specific template function.
|
|
120
|
+
*/
|
|
61
121
|
export declare function initializeNotificationBoxInTransactionFactory(context: NotificationInitServerActionsContext): (params: InitializeNotificationModelParams, notificationBoxDocument: NotificationBoxDocument, transaction: Transaction) => Promise<{
|
|
62
122
|
initialized: boolean;
|
|
63
123
|
alreadyInitialized: boolean;
|
|
64
124
|
}>;
|
|
125
|
+
/**
|
|
126
|
+
* Factory for the `initializeNotificationBox` action.
|
|
127
|
+
*
|
|
128
|
+
* Wraps the in-transaction initialization in a Firestore transaction
|
|
129
|
+
* and follows the transform-and-validate pattern.
|
|
130
|
+
*/
|
|
65
131
|
export declare function initializeNotificationBoxFactory(context: NotificationInitServerActionsContext): import("@dereekb/model").TransformAndValidateFunctionResultFunction<InitializeNotificationModelParams, (notificationBoxDocument: NotificationBoxDocument) => Promise<NotificationBoxDocument>, object, unknown>;
|
|
132
|
+
/**
|
|
133
|
+
* Factory for the `initializeAllApplicableNotificationBoxes` action.
|
|
134
|
+
*
|
|
135
|
+
* Batch-processes all {@link NotificationBox} documents flagged for initialization
|
|
136
|
+
* by querying for entries with `s=true` (setup needed), then initializing each in
|
|
137
|
+
* parallel (up to 5 concurrent tasks). Loops until no more flagged boxes are found.
|
|
138
|
+
*/
|
|
66
139
|
export declare function initializeAllApplicableNotificationBoxesFactory(context: NotificationInitServerActionsContext): import("@dereekb/model").TransformAndValidateFunctionResultFunction<InitializeAllApplicableNotificationBoxesParams, () => Promise<InitializeAllApplicableNotificationBoxesResult>, object, unknown>;
|
|
140
|
+
/**
|
|
141
|
+
* Factory for initializing a single {@link NotificationSummary} within a Firestore transaction.
|
|
142
|
+
*
|
|
143
|
+
* Loads the summary document in the transaction, reads its current data, and delegates
|
|
144
|
+
* to {@link initializeNotificationModelInTransaction} with the summary-specific template function.
|
|
145
|
+
*/
|
|
67
146
|
export declare function initializeNotificationSummaryInTransactionFactory(context: NotificationInitServerActionsContext): (params: InitializeNotificationModelParams, notificationSummaryDocument: NotificationSummaryDocument, transaction: Transaction) => Promise<{
|
|
68
147
|
initialized: boolean;
|
|
69
148
|
alreadyInitialized: boolean;
|
|
70
149
|
}>;
|
|
150
|
+
/**
|
|
151
|
+
* Factory for the `initializeNotificationSummary` action.
|
|
152
|
+
*
|
|
153
|
+
* Wraps the in-transaction summary initialization in a Firestore transaction
|
|
154
|
+
* and follows the transform-and-validate pattern.
|
|
155
|
+
*/
|
|
71
156
|
export declare function initializeNotificationSummaryFactory(context: NotificationInitServerActionsContext): import("@dereekb/model").TransformAndValidateFunctionResultFunction<InitializeNotificationModelParams, (notificationSummaryDocument: NotificationSummaryDocument) => Promise<NotificationSummaryDocument>, object, unknown>;
|
|
157
|
+
/**
|
|
158
|
+
* Factory for the `initializeAllApplicableNotificationSummaries` action.
|
|
159
|
+
*
|
|
160
|
+
* Batch-processes all {@link NotificationSummary} documents flagged for initialization
|
|
161
|
+
* by querying for entries with `s=true` (setup needed), then initializing each in
|
|
162
|
+
* parallel (up to 5 concurrent tasks). Loops until no more flagged summaries are found.
|
|
163
|
+
*/
|
|
72
164
|
export declare function initializeAllApplicableNotificationSummariesFactory(context: NotificationInitServerActionsContext): import("@dereekb/model").TransformAndValidateFunctionResultFunction<InitializeAllApplicableNotificationSummariesParams, () => Promise<InitializeAllApplicableNotificationSummariesResult>, object, unknown>;
|
|
@@ -7,17 +7,44 @@ import { type NotificationTemplateServiceRef } from './notification.config.servi
|
|
|
7
7
|
import { type NotificationSendServiceRef } from './notification.send.service';
|
|
8
8
|
import { type NotificationTaskServiceRef } from './notification.task.service';
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* NestJS injection token for the {@link BaseNotificationServerActionsContext}, which provides
|
|
11
|
+
* the foundational Firebase context, Firestore collections, and auth service needed by notification actions.
|
|
12
|
+
*
|
|
13
|
+
* The full {@link NotificationServerActionsContext} is assembled from this base plus additional services.
|
|
11
14
|
*/
|
|
12
15
|
export declare const BASE_NOTIFICATION_SERVER_ACTION_CONTEXT_TOKEN: InjectionToken;
|
|
13
16
|
/**
|
|
14
|
-
*
|
|
17
|
+
* NestJS injection token for the fully assembled {@link NotificationServerActionsContext},
|
|
18
|
+
* which adds template, send, task, and expedite services on top of the base context.
|
|
15
19
|
*/
|
|
16
20
|
export declare const NOTIFICATION_SERVER_ACTION_CONTEXT_TOKEN: InjectionToken;
|
|
21
|
+
/**
|
|
22
|
+
* Minimal context providing Firebase infrastructure, Firestore notification collections,
|
|
23
|
+
* auth service, and Firestore context needed by all notification server actions.
|
|
24
|
+
*/
|
|
17
25
|
export interface BaseNotificationServerActionsContext extends FirebaseServerActionsContext, NotificationFirestoreCollections, FirebaseServerAuthServiceRef, FirestoreContextReference {
|
|
18
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Full context for notification server actions, extending the base with template resolution,
|
|
29
|
+
* send channel orchestration, task dispatch, and expedite services.
|
|
30
|
+
*/
|
|
19
31
|
export interface NotificationServerActionsContext extends BaseNotificationServerActionsContext, AppNotificationTemplateTypeInfoRecordServiceRef, NotificationTemplateServiceRef, NotificationSendServiceRef, NotificationTaskServiceRef {
|
|
20
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Abstract service class defining all server-side notification CRUD and delivery actions.
|
|
35
|
+
*
|
|
36
|
+
* This is the central API surface for the notification system's backend. It provides:
|
|
37
|
+
*
|
|
38
|
+
* - **User management**: create/update {@link NotificationUser} records, resync user preferences
|
|
39
|
+
* - **Box management**: create/update {@link NotificationBox} containers and their recipients
|
|
40
|
+
* - **Summary management**: create/update {@link NotificationSummary} for in-app notification feeds
|
|
41
|
+
* - **Send pipeline**: send individual notifications, process queued notifications, and clean up sent ones
|
|
42
|
+
*
|
|
43
|
+
* Each method follows the transform-and-validate pattern: params are validated first,
|
|
44
|
+
* then a curried function is returned that operates on the target document.
|
|
45
|
+
*
|
|
46
|
+
* @see {@link notificationServerActions} for the concrete implementation factory.
|
|
47
|
+
*/
|
|
21
48
|
export declare abstract class NotificationServerActions {
|
|
22
49
|
abstract createNotificationUser(params: CreateNotificationUserParams): AsyncNotificationUserCreateAction<CreateNotificationUserParams>;
|
|
23
50
|
abstract updateNotificationUser(params: UpdateNotificationUserParams): AsyncNotificationUserUpdateAction<UpdateNotificationUserParams>;
|
|
@@ -32,12 +59,65 @@ export declare abstract class NotificationServerActions {
|
|
|
32
59
|
abstract sendQueuedNotifications(params: SendQueuedNotificationsParams): Promise<TransformAndValidateFunctionResult<SendQueuedNotificationsParams, (sendQueuedNotificationsInput?: Maybe<SendQueuedNotificationsInput>) => Promise<SendQueuedNotificationsResult>>>;
|
|
33
60
|
abstract cleanupSentNotifications(params: CleanupSentNotificationsParams): Promise<TransformAndValidateFunctionResult<CleanupSentNotificationsParams, () => Promise<CleanupSentNotificationsResult>>>;
|
|
34
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Creates a concrete {@link NotificationServerActions} implementation by wiring each action
|
|
64
|
+
* to its factory function using the provided context.
|
|
65
|
+
*
|
|
66
|
+
* @param context - the fully assembled notification server actions context
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* const actions = notificationServerActions(context);
|
|
71
|
+
* const sendFn = await actions.sendNotification({ key: notificationKey });
|
|
72
|
+
* const result = await sendFn(notificationDocument);
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
35
75
|
export declare function notificationServerActions(context: NotificationServerActionsContext): NotificationServerActions;
|
|
76
|
+
/**
|
|
77
|
+
* Factory for the `createNotificationUser` action.
|
|
78
|
+
*
|
|
79
|
+
* Validates the UID exists in Firebase Auth, then creates a new {@link NotificationUser} document
|
|
80
|
+
* with empty default and global configs. Throws if the UID is not found in Auth.
|
|
81
|
+
*/
|
|
36
82
|
export declare function createNotificationUserFactory(context: NotificationServerActionsContext): import("@dereekb/model").TransformAndValidateFunctionResultFunction<CreateNotificationUserParams, () => Promise<NotificationUserDocument>, object, unknown>;
|
|
83
|
+
/**
|
|
84
|
+
* Factory for the `updateNotificationUser` action.
|
|
85
|
+
*
|
|
86
|
+
* Updates a {@link NotificationUser}'s default config (`dc`), global config (`gc`), and/or
|
|
87
|
+
* box configs (`bc`). When the global config changes, iterates all box configs to propagate
|
|
88
|
+
* effective recipient changes and marks affected entries for sync.
|
|
89
|
+
*/
|
|
37
90
|
export declare function updateNotificationUserFactory(context: NotificationServerActionsContext): import("@dereekb/model").TransformAndValidateFunctionResultFunction<UpdateNotificationUserParams, (notificationUserDocument: NotificationUserDocument) => Promise<NotificationUserDocument>, object, unknown>;
|
|
91
|
+
/**
|
|
92
|
+
* Factory for the `resyncNotificationUser` action.
|
|
93
|
+
*
|
|
94
|
+
* Re-synchronizes a single {@link NotificationUser}'s box configs by iterating through
|
|
95
|
+
* entries flagged with `ns=true` (needs-sync), loading the corresponding {@link NotificationBox},
|
|
96
|
+
* and merging the user's preferences back into the box's recipient list. Handles removed entries
|
|
97
|
+
* and cleans up stale box references.
|
|
98
|
+
*/
|
|
38
99
|
export declare function resyncNotificationUserFactory(context: NotificationServerActionsContext): import("@dereekb/model").TransformAndValidateFunctionResultFunction<import("@dereekb/firebase").TargetModelParams, (notificationUserDocument: NotificationUserDocument) => Promise<ResyncNotificationUserResult>, object, unknown>;
|
|
100
|
+
/**
|
|
101
|
+
* Factory for the `resyncAllNotificationUsers` action.
|
|
102
|
+
*
|
|
103
|
+
* Batch-processes all {@link NotificationUser} documents flagged for sync by querying
|
|
104
|
+
* for entries with `ns=true`, then calling the resync logic for each in parallel
|
|
105
|
+
* (up to 5 concurrent tasks). Loops until no more flagged users are found.
|
|
106
|
+
*/
|
|
39
107
|
export declare function resyncAllNotificationUsersFactory(context: NotificationServerActionsContext): () => Promise<ResyncAllNotificationUsersResult>;
|
|
108
|
+
/**
|
|
109
|
+
* Factory for the `createNotificationSummary` action.
|
|
110
|
+
*
|
|
111
|
+
* Creates a new {@link NotificationSummary} document for a model, generating the summary ID
|
|
112
|
+
* from the model key and initializing it with a blank template.
|
|
113
|
+
*/
|
|
40
114
|
export declare function createNotificationSummaryFactory(context: NotificationServerActionsContext): import("@dereekb/model").TransformAndValidateFunctionResultFunction<CreateNotificationSummaryParams, () => Promise<NotificationSummaryDocument>, object, unknown>;
|
|
115
|
+
/**
|
|
116
|
+
* Factory for the `updateNotificationSummary` action.
|
|
117
|
+
*
|
|
118
|
+
* Updates an existing {@link NotificationSummary} document's owner or setup flag.
|
|
119
|
+
* Runs within a Firestore transaction to ensure consistency.
|
|
120
|
+
*/
|
|
41
121
|
export declare function updateNotificationSummaryFactory(context: NotificationServerActionsContext): import("@dereekb/model").TransformAndValidateFunctionResultFunction<UpdateNotificationSummaryParams, (notificationSummaryDocument: NotificationSummaryDocument) => Promise<NotificationSummaryDocument>, object, unknown>;
|
|
42
122
|
/**
|
|
43
123
|
* Used for creating a new NotificationBox within a transaction.
|
|
@@ -54,10 +134,22 @@ export interface CreateNotificationBoxInTransactionInput extends NotificationBox
|
|
|
54
134
|
*/
|
|
55
135
|
readonly skipCreate?: Maybe<boolean>;
|
|
56
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* Factory that creates a {@link NotificationBox} within a Firestore transaction.
|
|
139
|
+
*
|
|
140
|
+
* Checks for existing boxes and throws if one already exists for the model.
|
|
141
|
+
* Also syncs initial recipients with their corresponding {@link NotificationUser} documents.
|
|
142
|
+
*/
|
|
57
143
|
export declare function createNotificationBoxInTransactionFactory(context: BaseNotificationServerActionsContext): (params: CreateNotificationBoxInTransactionInput, transaction: Transaction) => Promise<{
|
|
58
144
|
notificationBoxTemplate: NotificationBox;
|
|
59
145
|
notificationBoxDocument: NotificationBoxDocument;
|
|
60
146
|
}>;
|
|
147
|
+
/**
|
|
148
|
+
* Factory for the `createNotificationBox` action.
|
|
149
|
+
*
|
|
150
|
+
* Wraps {@link createNotificationBoxInTransactionFactory} in a Firestore transaction
|
|
151
|
+
* and follows the transform-and-validate pattern.
|
|
152
|
+
*/
|
|
61
153
|
export declare function createNotificationBoxFactory(context: NotificationServerActionsContext): import("@dereekb/model").TransformAndValidateFunctionResultFunction<CreateNotificationBoxParams, () => Promise<NotificationBoxDocument>, object, unknown>;
|
|
62
154
|
export declare function updateNotificationBoxFactory({ firebaseServerActionTransformFunctionFactory }: NotificationServerActionsContext): import("@dereekb/model").TransformAndValidateFunctionResultFunction<import("@dereekb/firebase").TargetModelParams, (notificationBoxDocument: NotificationBoxDocument) => Promise<NotificationBoxDocument>, object, unknown>;
|
|
63
155
|
export interface UpdateNotificationBoxRecipientExclusionInTransactionInput extends NotificationBoxDocumentReferencePair {
|
|
@@ -66,6 +158,12 @@ export interface UpdateNotificationBoxRecipientExclusionInTransactionInput exten
|
|
|
66
158
|
export interface UpdateNotificationBoxRecipientExclusionInTransactionResult {
|
|
67
159
|
readonly notificationUserUpdate: Partial<NotificationUser>;
|
|
68
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* Factory that updates recipient send exclusions on a {@link NotificationBox} within a transaction.
|
|
163
|
+
*
|
|
164
|
+
* Manages the exclusion list (`x`) on both the box recipient and the corresponding
|
|
165
|
+
* {@link NotificationUser}'s send exclusion array, keeping them in sync.
|
|
166
|
+
*/
|
|
69
167
|
export declare function updateNotificationBoxRecipientExclusionInTransactionFactory(context: BaseNotificationServerActionsContext): (input: UpdateNotificationBoxRecipientExclusionInTransactionInput, transaction: Transaction) => Promise<Maybe<UpdateNotificationBoxRecipientExclusionInTransactionResult>>;
|
|
70
168
|
export interface UpdateNotificationBoxRecipientInTransactionInput extends NotificationBoxDocumentReferencePair {
|
|
71
169
|
/**
|
|
@@ -88,7 +186,20 @@ export interface UpdateNotificationBoxRecipientInTransactionResult {
|
|
|
88
186
|
readonly updatedNotificationBox: NotificationBox;
|
|
89
187
|
readonly notificationBoxDocument: NotificationBoxDocument;
|
|
90
188
|
}
|
|
189
|
+
/**
|
|
190
|
+
* Factory that updates a single recipient on a {@link NotificationBox} within a transaction.
|
|
191
|
+
*
|
|
192
|
+
* Handles inserting new recipients, updating existing ones, and removing recipients.
|
|
193
|
+
* Syncs changes with the recipient's {@link NotificationUser} document and manages
|
|
194
|
+
* recipient index assignment via a sorted-values free-index calculator.
|
|
195
|
+
*/
|
|
91
196
|
export declare function updateNotificationBoxRecipientInTransactionFactory(context: BaseNotificationServerActionsContext): (input: UpdateNotificationBoxRecipientInTransactionInput, transaction: Transaction) => Promise<Maybe<UpdateNotificationBoxRecipientInTransactionResult>>;
|
|
197
|
+
/**
|
|
198
|
+
* Factory for the `updateNotificationBoxRecipient` action.
|
|
199
|
+
*
|
|
200
|
+
* Wraps the in-transaction recipient update logic, handling both recipient changes
|
|
201
|
+
* and send exclusion updates in a single Firestore transaction.
|
|
202
|
+
*/
|
|
92
203
|
export declare function updateNotificationBoxRecipientFactory(context: NotificationServerActionsContext): import("@dereekb/model").TransformAndValidateFunctionResultFunction<UpdateNotificationBoxRecipientParams, (notificationBoxDocument: NotificationBoxDocument) => Promise<NotificationBoxDocument>, object, unknown>;
|
|
93
204
|
export declare const UNKNOWN_NOTIFICATION_TEMPLATE_TYPE_HOURS_DELAY = 8;
|
|
94
205
|
export declare const UNKNOWN_NOTIFICATION_TEMPLATE_TYPE_DELETE_AFTER_RETRY_ATTEMPTS = 1;
|
|
@@ -105,11 +216,49 @@ export declare const NOTIFICATION_TASK_MINIMUM_SET_AT_THROTTLE_TIME_MINUTES = 1;
|
|
|
105
216
|
export declare const NOTIFICATION_TASK_TYPE_MAX_SEND_ATTEMPTS = 5;
|
|
106
217
|
export declare const NOTIFICATION_TASK_TYPE_FAILURE_DELAY_HOURS = 3;
|
|
107
218
|
export declare const NOTIFICATION_TASK_TYPE_FAILURE_DELAY_MS: number;
|
|
219
|
+
/**
|
|
220
|
+
* Factory for the `sendNotification` action — the core of the notification delivery pipeline.
|
|
221
|
+
*
|
|
222
|
+
* Given a {@link Notification} document, this action:
|
|
223
|
+
* 1. Loads the notification and its parent {@link NotificationBox}
|
|
224
|
+
* 2. Expands recipients across all channels (email, SMS, notification summary)
|
|
225
|
+
* 3. Resolves the message template via {@link NotificationTemplateService}
|
|
226
|
+
* 4. Builds message content for each recipient using the template's message function
|
|
227
|
+
* 5. Dispatches messages through each configured channel's send service
|
|
228
|
+
* 6. Handles task completion, week-based archival, and cleanup of the notification document
|
|
229
|
+
*
|
|
230
|
+
* Supports throttling via `sendAt` time, configurable send flags, and task-based
|
|
231
|
+
* async workflows for notifications that require multi-step processing.
|
|
232
|
+
*/
|
|
108
233
|
export declare function sendNotificationFactory(context: NotificationServerActionsContext): import("@dereekb/model").TransformAndValidateFunctionResultFunction<SendNotificationParams, (inputNotificationDocument: NotificationDocument) => Promise<SendNotificationResult>, object, unknown>;
|
|
234
|
+
/**
|
|
235
|
+
* Warning threshold for the number of queued notifications. If exceeded, a warning is logged
|
|
236
|
+
* indicating the queue may be growing faster than it can be processed.
|
|
237
|
+
*/
|
|
109
238
|
export declare const SEND_QUEUE_NOTIFICATIONS_TASK_EXCESS_THRESHOLD = 5000;
|
|
239
|
+
/**
|
|
240
|
+
* Optional input for the `sendQueuedNotifications` action, allowing callers to configure
|
|
241
|
+
* parallelism and observe individual send results.
|
|
242
|
+
*/
|
|
110
243
|
export interface SendQueuedNotificationsInput {
|
|
111
244
|
readonly maxParellelSendTasks?: Maybe<number>;
|
|
112
245
|
readonly onSendNotificationResult?: (result: SendNotificationResult, document: NotificationDocument) => void;
|
|
113
246
|
}
|
|
247
|
+
/**
|
|
248
|
+
* Factory for the `sendQueuedNotifications` action.
|
|
249
|
+
*
|
|
250
|
+
* Queries for {@link Notification} documents whose `sendAt` time has passed,
|
|
251
|
+
* then processes them in batches. Supports configurable batch sizes, time windows,
|
|
252
|
+
* and an optional {@link NotificationExpediteService} for immediate delivery.
|
|
253
|
+
* Continues processing batches until no more queued notifications are found
|
|
254
|
+
* or the time budget is exhausted.
|
|
255
|
+
*/
|
|
114
256
|
export declare function sendQueuedNotificationsFactory(context: NotificationServerActionsContext): import("@dereekb/model").TransformAndValidateFunctionResultFunction<SendQueuedNotificationsParams, (input?: Maybe<SendQueuedNotificationsInput>) => Promise<SendQueuedNotificationsResult>, object, unknown>;
|
|
257
|
+
/**
|
|
258
|
+
* Factory for the `cleanupSentNotifications` action.
|
|
259
|
+
*
|
|
260
|
+
* Queries for {@link Notification} documents that are ready for cleanup (fully sent,
|
|
261
|
+
* past the retention window) and deletes them in batches. Continues until no more
|
|
262
|
+
* cleanup-eligible notifications are found.
|
|
263
|
+
*/
|
|
115
264
|
export declare function cleanupSentNotificationsFactory(context: NotificationServerActionsContext): import("@dereekb/model").TransformAndValidateFunctionResultFunction<CleanupSentNotificationsParams, () => Promise<CleanupSentNotificationsResult>, object, unknown>;
|
|
@@ -1,31 +1,43 @@
|
|
|
1
1
|
import { type InjectionToken } from '@nestjs/common';
|
|
2
2
|
import { type NotificationTemplateType, type NotificationMessageFunctionFactory } from '@dereekb/firebase';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* NestJS injection token for overriding the default {@link NotificationMessageFunctionFactory} values
|
|
5
|
+
* used by {@link NotificationTemplateService} when no type-specific config is found.
|
|
6
|
+
*
|
|
7
|
+
* Provide a {@link NotificationTemplateServiceDefaultsRecord} at this token to set baseline
|
|
8
|
+
* message factories for each {@link NotificationTemplateType}.
|
|
5
9
|
*/
|
|
6
10
|
export declare const NOTIFICATION_TEMPLATE_SERVICE_DEFAULTS_OVERRIDE_TOKEN: InjectionToken;
|
|
7
11
|
/**
|
|
8
|
-
*
|
|
12
|
+
* NestJS injection token for the array of type-specific template configurations
|
|
13
|
+
* consumed by {@link NotificationTemplateService}.
|
|
14
|
+
*
|
|
15
|
+
* Provide a {@link NotificationTemplateServiceTypeConfigArray} at this token to register
|
|
16
|
+
* message factories for individual {@link NotificationTemplateType} values.
|
|
9
17
|
*/
|
|
10
18
|
export declare const NOTIFICATION_TEMPLATE_SERVICE_CONFIGS_ARRAY_TOKEN: InjectionToken;
|
|
11
19
|
/**
|
|
12
|
-
*
|
|
20
|
+
* Maps a single {@link NotificationTemplateType} to its {@link NotificationMessageFunctionFactory},
|
|
21
|
+
* telling {@link NotificationTemplateService} how to build notification messages of that type.
|
|
13
22
|
*/
|
|
14
23
|
export interface NotificationTemplateServiceTypeConfig {
|
|
15
24
|
/**
|
|
16
|
-
*
|
|
25
|
+
* The notification template type this config handles.
|
|
17
26
|
*/
|
|
18
27
|
readonly type: NotificationTemplateType;
|
|
19
28
|
/**
|
|
20
|
-
* Factory
|
|
29
|
+
* Factory that creates {@link NotificationMessageFunction} instances for this type.
|
|
21
30
|
*/
|
|
22
31
|
readonly factory: NotificationMessageFunctionFactory<any>;
|
|
23
32
|
}
|
|
24
33
|
/**
|
|
25
|
-
*
|
|
34
|
+
* Array of {@link NotificationTemplateServiceTypeConfig} entries registered
|
|
35
|
+
* via {@link NOTIFICATION_TEMPLATE_SERVICE_CONFIGS_ARRAY_TOKEN}.
|
|
26
36
|
*/
|
|
27
37
|
export type NotificationTemplateServiceTypeConfigArray = NotificationTemplateServiceTypeConfig[];
|
|
28
38
|
/**
|
|
29
|
-
*
|
|
39
|
+
* Record mapping each {@link NotificationTemplateType} to a default {@link NotificationMessageFunctionFactory}.
|
|
40
|
+
*
|
|
41
|
+
* Used as the fallback when no type-specific {@link NotificationTemplateServiceTypeConfig} is registered.
|
|
30
42
|
*/
|
|
31
43
|
export type NotificationTemplateServiceDefaultsRecord = Record<NotificationTemplateType, NotificationMessageFunctionFactory>;
|
|
@@ -1,21 +1,49 @@
|
|
|
1
1
|
import { type Maybe } from '@dereekb/util';
|
|
2
2
|
import { type NotificationMessageFunction, type NotificationMessageFunctionFactory, type NotificationMessageFunctionFactoryConfig, type NotificationTemplateType } from '@dereekb/firebase';
|
|
3
3
|
import { type NotificationTemplateServiceTypeConfig, type NotificationTemplateServiceTypeConfigArray, type NotificationTemplateServiceDefaultsRecord } from './notification.config';
|
|
4
|
+
/**
|
|
5
|
+
* Provides a reference to a {@link NotificationTemplateService} instance.
|
|
6
|
+
*/
|
|
4
7
|
export interface NotificationTemplateServiceRef {
|
|
5
8
|
readonly notificationTemplateService: NotificationTemplateService;
|
|
6
9
|
}
|
|
7
10
|
/**
|
|
8
|
-
*
|
|
11
|
+
* Resolves {@link NotificationMessageFunctionFactory} instances for a given {@link NotificationTemplateType}.
|
|
12
|
+
*
|
|
13
|
+
* Combines an optional defaults record (injected via {@link NOTIFICATION_TEMPLATE_SERVICE_DEFAULTS_OVERRIDE_TOKEN})
|
|
14
|
+
* with per-type configs (injected via {@link NOTIFICATION_TEMPLATE_SERVICE_CONFIGS_ARRAY_TOKEN}) to determine
|
|
15
|
+
* which factory to use. If a type has no registered config or default, a no-content fallback factory is used.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const instance = notificationTemplateService.templateInstanceForType('welcome');
|
|
20
|
+
* const messageFn = await instance.loadMessageFunction({ notification, notificationBox });
|
|
21
|
+
* ```
|
|
9
22
|
*/
|
|
10
23
|
export declare class NotificationTemplateService {
|
|
11
24
|
private readonly _defaults;
|
|
12
25
|
private readonly _config;
|
|
13
26
|
constructor(_inputDefaults: NotificationTemplateServiceDefaultsRecord | undefined, _inputConfigs: NotificationTemplateServiceTypeConfigArray | undefined);
|
|
27
|
+
/**
|
|
28
|
+
* Returns the default factory and optional type-specific config for the given template type.
|
|
29
|
+
*
|
|
30
|
+
* @param type - the notification template type to look up
|
|
31
|
+
* @returns a tuple of [defaultFactory, typeConfig] where either may be undefined
|
|
32
|
+
*/
|
|
14
33
|
configPairForType(type: NotificationTemplateType): [NotificationMessageFunctionFactory, Maybe<NotificationTemplateServiceTypeConfig>];
|
|
34
|
+
/**
|
|
35
|
+
* Creates a {@link NotificationTemplateServiceInstance} scoped to a single template type,
|
|
36
|
+
* pre-wired with the resolved factory for that type.
|
|
37
|
+
*
|
|
38
|
+
* @param type - the notification template type
|
|
39
|
+
*/
|
|
15
40
|
templateInstanceForType(type: NotificationTemplateType): NotificationTemplateServiceInstance;
|
|
16
41
|
}
|
|
17
42
|
/**
|
|
18
|
-
* Loads
|
|
43
|
+
* Loads or creates a {@link NotificationMessageFunction} for a specific notification,
|
|
44
|
+
* using the factory resolved by {@link NotificationTemplateService}.
|
|
45
|
+
*
|
|
46
|
+
* @param config - contextual data (notification, box, recipients) needed to build the message function
|
|
19
47
|
*/
|
|
20
48
|
export type LoadNotificationMessageFunction = (config: NotificationMessageFunctionFactoryConfig) => Promise<NotificationMessageFunction>;
|
|
21
49
|
/**
|
|
@@ -40,10 +68,20 @@ export interface NotificationTemplateServiceInstance {
|
|
|
40
68
|
readonly loadMessageFunction: LoadNotificationMessageFunction;
|
|
41
69
|
}
|
|
42
70
|
/**
|
|
43
|
-
* Creates a NotificationTemplateServiceInstance.
|
|
71
|
+
* Creates a {@link NotificationTemplateServiceInstance} bound to a specific template type.
|
|
72
|
+
*
|
|
73
|
+
* Resolves the factory from the service's type-specific config first, falling back to
|
|
74
|
+
* a no-content default factory when no config is registered for the type.
|
|
75
|
+
*
|
|
76
|
+
* @param service - the parent template service
|
|
77
|
+
* @param type - the template type to bind
|
|
44
78
|
*
|
|
45
|
-
* @
|
|
46
|
-
*
|
|
47
|
-
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* const instance = notificationTemplateServiceInstance(service, 'order_update');
|
|
82
|
+
* if (instance.isConfiguredType) {
|
|
83
|
+
* const messageFn = await instance.loadMessageFunction(config);
|
|
84
|
+
* }
|
|
85
|
+
* ```
|
|
48
86
|
*/
|
|
49
87
|
export declare function notificationTemplateServiceInstance(service: NotificationTemplateService, type: NotificationTemplateType): NotificationTemplateServiceInstance;
|
|
@@ -2,7 +2,8 @@ import { type Maybe } from '@dereekb/util';
|
|
|
2
2
|
import { type NotificationExpediteService, type NotificationExpediteServiceInstance, type NotificationExpediteServiceSendNotificationOptions } from './notification.expedite.service';
|
|
3
3
|
import { type CreateNotificationDocumentPairInput, type CreateNotificationDocumentPairResult, type SendNotificationResult } from '@dereekb/firebase';
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Input for {@link createOrRunUniqueNotificationDocument}, extending the standard notification document
|
|
6
|
+
* creation input with options for immediate execution or expedited delivery.
|
|
6
7
|
*/
|
|
7
8
|
export interface CreateOrRunUniqueNotificationDocumentRunInput extends Omit<CreateNotificationDocumentPairInput, 'transaction'> {
|
|
8
9
|
/**
|
|
@@ -36,6 +37,10 @@ export interface CreateOrRunUniqueNotificationDocumentRunInput extends Omit<Crea
|
|
|
36
37
|
*/
|
|
37
38
|
readonly expediteInstance?: Maybe<NotificationExpediteServiceInstance>;
|
|
38
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Result of {@link createOrRunUniqueNotificationDocument}, extending the pair result with
|
|
42
|
+
* optional send/enqueue outcomes.
|
|
43
|
+
*/
|
|
39
44
|
export interface CreateOrRunUniqueNotificationDocumentRunResult extends CreateNotificationDocumentPairResult {
|
|
40
45
|
/**
|
|
41
46
|
* Set if the notification was run.
|
|
@@ -47,11 +52,34 @@ export interface CreateOrRunUniqueNotificationDocumentRunResult extends CreateNo
|
|
|
47
52
|
readonly runEnqueued?: Maybe<boolean>;
|
|
48
53
|
}
|
|
49
54
|
/**
|
|
50
|
-
*
|
|
55
|
+
* Creates a unique notification document if it doesn't exist, or triggers a send/expedite
|
|
56
|
+
* if the document already exists.
|
|
57
|
+
*
|
|
58
|
+
* This is the idempotent alternative to `createNotificationDocument()` for notifications
|
|
59
|
+
* flagged as unique (`ut=true`). The behavior varies based on whether the document exists:
|
|
60
|
+
*
|
|
61
|
+
* - **Document does not exist**: Creates it and optionally runs it immediately via `runImmediatelyIfCreated`.
|
|
62
|
+
* - **Document already exists**: Triggers the notification via the expedite service/instance,
|
|
63
|
+
* or updates the `sat` (send-at time) if `updateNextRunAtTime` is set.
|
|
64
|
+
*
|
|
65
|
+
* Does not support Firestore transactions, as running should occur outside of a transaction.
|
|
66
|
+
*
|
|
67
|
+
* @param input - creation and run configuration
|
|
68
|
+
* @throws Error if the notification template is not flagged as unique
|
|
51
69
|
*
|
|
52
|
-
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* const result = await createOrRunUniqueNotificationDocument({
|
|
73
|
+
* ...createInput,
|
|
74
|
+
* runImmediatelyIfCreated: true,
|
|
75
|
+
* expediteService
|
|
76
|
+
* });
|
|
53
77
|
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
78
|
+
* if (result.notificationCreated) {
|
|
79
|
+
* // newly created
|
|
80
|
+
* } else if (result.runResult) {
|
|
81
|
+
* // existing doc was re-sent
|
|
82
|
+
* }
|
|
83
|
+
* ```
|
|
56
84
|
*/
|
|
57
85
|
export declare function createOrRunUniqueNotificationDocument(input: CreateOrRunUniqueNotificationDocumentRunInput): Promise<CreateOrRunUniqueNotificationDocumentRunResult>;
|