@dereekb/firebase-server 12.5.8 → 12.5.10
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/CHANGELOG.md +8 -0
- package/mailgun/package.json +1 -1
- package/model/package.json +1 -1
- package/model/src/lib/notification/index.d.ts +1 -0
- package/model/src/lib/notification/index.js +1 -0
- package/model/src/lib/notification/index.js.map +1 -1
- package/model/src/lib/notification/notification.task.subtask.handler.d.ts +215 -0
- package/model/src/lib/notification/notification.task.subtask.handler.js +256 -0
- package/model/src/lib/notification/notification.task.subtask.handler.js.map +1 -0
- package/model/src/lib/storagefile/storagefile.action.server.d.ts +3 -1
- package/model/src/lib/storagefile/storagefile.action.server.js +38 -1
- package/model/src/lib/storagefile/storagefile.action.server.js.map +1 -1
- package/model/src/lib/storagefile/storagefile.task.service.handler.d.ts +16 -89
- package/model/src/lib/storagefile/storagefile.task.service.handler.js +73 -264
- package/model/src/lib/storagefile/storagefile.task.service.handler.js.map +1 -1
- package/model/src/lib/storagefile/storagefile.upload.service.initializer.js +4 -0
- package/model/src/lib/storagefile/storagefile.upload.service.initializer.js.map +1 -1
- package/package.json +1 -1
- package/src/lib/storage/driver.accessor.js +25 -5
- package/src/lib/storage/driver.accessor.js.map +1 -1
- package/test/package.json +1 -1
- package/zoho/package.json +1 -1
package/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.5.10](https://github.com/dereekb/dbx-components/compare/v12.5.9-dev...v12.5.10) (2025-11-21)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## [12.5.9](https://github.com/dereekb/dbx-components/compare/v12.5.8-dev...v12.5.9) (2025-11-16)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
5
13
|
## [12.5.8](https://github.com/dereekb/dbx-components/compare/v12.5.7-dev...v12.5.8) (2025-11-06)
|
|
6
14
|
|
|
7
15
|
|
package/mailgun/package.json
CHANGED
package/model/package.json
CHANGED
|
@@ -9,6 +9,7 @@ export * from './notification.send.service';
|
|
|
9
9
|
export * from './notification.send';
|
|
10
10
|
export * from './notification.task.service';
|
|
11
11
|
export * from './notification.task.service.handler';
|
|
12
|
+
export * from './notification.task.subtask.handler';
|
|
12
13
|
export * from './notification.error';
|
|
13
14
|
export * from './notification.expedite.service';
|
|
14
15
|
export * from './notification.util';
|
|
@@ -12,6 +12,7 @@ tslib_1.__exportStar(require("./notification.send.service"), exports);
|
|
|
12
12
|
tslib_1.__exportStar(require("./notification.send"), exports);
|
|
13
13
|
tslib_1.__exportStar(require("./notification.task.service"), exports);
|
|
14
14
|
tslib_1.__exportStar(require("./notification.task.service.handler"), exports);
|
|
15
|
+
tslib_1.__exportStar(require("./notification.task.subtask.handler"), exports);
|
|
15
16
|
tslib_1.__exportStar(require("./notification.error"), exports);
|
|
16
17
|
tslib_1.__exportStar(require("./notification.expedite.service"), exports);
|
|
17
18
|
tslib_1.__exportStar(require("./notification.util"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../packages/firebase-server/model/src/lib/notification/index.ts"],"names":[],"mappings":";;;AAAA,uEAA6C;AAC7C,4EAAkD;AAClD,wEAA8C;AAC9C,gEAAsC;AACtC,gEAAsC;AACtC,0FAAgE;AAChE,2EAAiD;AACjD,sEAA4C;AAC5C,8DAAoC;AACpC,sEAA4C;AAC5C,8EAAoD;AACpD,+DAAqC;AACrC,0EAAgD;AAChD,8DAAoC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../packages/firebase-server/model/src/lib/notification/index.ts"],"names":[],"mappings":";;;AAAA,uEAA6C;AAC7C,4EAAkD;AAClD,wEAA8C;AAC9C,gEAAsC;AACtC,gEAAsC;AACtC,0FAAgE;AAChE,2EAAiD;AACjD,sEAA4C;AAC5C,8DAAoC;AACpC,sEAA4C;AAC5C,8EAAoD;AACpD,8EAAoD;AACpD,+DAAqC;AACrC,0EAAgD;AAChD,8DAAoC"}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { type NotificationTaskSubtaskTarget, type NotificationTask, type NotificationTaskServiceHandleNotificationTaskResult, type NotificationTaskSubtaskMetadata, type NotificationTaskSubtaskCheckpointString, type NotificationTaskSubtaskData, type NotificationTaskSubtaskCheckpoint, type NotificationTaskType } from '@dereekb/firebase';
|
|
2
|
+
import { type NotificationTaskServiceTaskHandlerConfig } from '../notification/notification.task.service.handler';
|
|
3
|
+
import { type Maybe, type MaybeSo, type Milliseconds, type PromiseOrValue } from '@dereekb/util';
|
|
4
|
+
import { BaseError } from 'make-error';
|
|
5
|
+
/**
|
|
6
|
+
* A NotificationTask with a set data value.
|
|
7
|
+
*/
|
|
8
|
+
export type NotificationTaskSubtaskInputTask<D extends NotificationTaskSubtaskData> = Omit<NotificationTask<D>, 'data'> & {
|
|
9
|
+
readonly data: MaybeSo<NotificationTask<D>['data']>;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Input for a generic NotificationTaskSubtask
|
|
13
|
+
*/
|
|
14
|
+
export interface NotificationTaskSubtaskInput<D extends NotificationTaskSubtaskData<M, S>, M extends NotificationTaskSubtaskMetadata = any, S extends NotificationTaskSubtaskCheckpointString = NotificationTaskSubtaskCheckpointString> {
|
|
15
|
+
/**
|
|
16
|
+
* The retrieved target.
|
|
17
|
+
*/
|
|
18
|
+
readonly target: NotificationTaskSubtaskTarget;
|
|
19
|
+
/**
|
|
20
|
+
* The root NotificationTask.
|
|
21
|
+
*
|
|
22
|
+
* The data is always guranteed.
|
|
23
|
+
*/
|
|
24
|
+
readonly notificationTask: NotificationTaskSubtaskInputTask<D>;
|
|
25
|
+
/**
|
|
26
|
+
* List of completed subtasks.
|
|
27
|
+
*/
|
|
28
|
+
readonly completedSubtasks: S[];
|
|
29
|
+
/**
|
|
30
|
+
* The current metadata for the subtask.
|
|
31
|
+
*/
|
|
32
|
+
readonly subtaskData?: Maybe<M>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Result of a NotificationTaskSubtask.
|
|
36
|
+
*/
|
|
37
|
+
export type NotificationTaskSubtaskResult<M extends NotificationTaskSubtaskMetadata = any, S extends NotificationTaskSubtaskCheckpointString = NotificationTaskSubtaskCheckpointString> = NotificationTaskServiceHandleNotificationTaskResult<M, S>;
|
|
38
|
+
/**
|
|
39
|
+
* A NotificationTaskSubtask is a function that handles a specific NotificationTaskSubtaskTarget subtask.
|
|
40
|
+
*/
|
|
41
|
+
export type NotificationTaskSubtask<I extends NotificationTaskSubtaskInput<D, M, S>, D extends NotificationTaskSubtaskData<M, S>, M extends NotificationTaskSubtaskMetadata = any, S extends NotificationTaskSubtaskCheckpointString = NotificationTaskSubtaskCheckpointString> = (input: I) => Promise<NotificationTaskSubtaskResult<M, S>>;
|
|
42
|
+
/**
|
|
43
|
+
* Similar to NotificationTaskServiceTaskHandlerFlowEntry, but used in NotificationTaskSubtaskProcessorConfig as part of the flow.
|
|
44
|
+
*/
|
|
45
|
+
export interface NotificationTaskSubtaskFlowEntry<I extends NotificationTaskSubtaskInput<D, M, S>, D extends NotificationTaskSubtaskData<M, S>, M extends NotificationTaskSubtaskMetadata = any, S extends NotificationTaskSubtaskCheckpointString = NotificationTaskSubtaskCheckpointString> {
|
|
46
|
+
/**
|
|
47
|
+
* The subtask this flow entry represents.
|
|
48
|
+
*/
|
|
49
|
+
readonly subtask: S;
|
|
50
|
+
/**
|
|
51
|
+
* The subtask function
|
|
52
|
+
*/
|
|
53
|
+
readonly fn: NotificationTaskSubtask<I, D, M, S>;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The base output cleanup configuration.
|
|
57
|
+
*/
|
|
58
|
+
export interface NotificationTaskSubtaskCleanupInstructions {
|
|
59
|
+
/**
|
|
60
|
+
* Whether or not the cleanup was successful. If false, the task will be delayed until the cleanup can be retried.
|
|
61
|
+
*
|
|
62
|
+
* Defaults to true.
|
|
63
|
+
*/
|
|
64
|
+
readonly cleanupSuccess?: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* How long to delay the retry of the cleanup after cleanup fails.
|
|
67
|
+
*
|
|
68
|
+
* Ignored if cleanupSuccess is not false.
|
|
69
|
+
*/
|
|
70
|
+
readonly delayRetryUntil?: NotificationTaskServiceHandleNotificationTaskResult['delayUntil'];
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Cleanup function for a NotificationTaskSubtask.
|
|
74
|
+
*
|
|
75
|
+
* This is called during the cleanup step.
|
|
76
|
+
*/
|
|
77
|
+
export type NotificationTaskSubtaskCleanupInstructionsFunction<I extends NotificationTaskSubtaskInput<D, M, S>, CUI extends NotificationTaskSubtaskCleanupInstructions, D extends NotificationTaskSubtaskData<M, S>, M extends NotificationTaskSubtaskMetadata = any, S extends NotificationTaskSubtaskCheckpointString = NotificationTaskSubtaskCheckpointString> = (input: NotificationTaskSubtaskCleanupFunctionInput<I, D, M, S>) => CUI;
|
|
78
|
+
/**
|
|
79
|
+
* The actual cleanup function to execute using the input and instructions.
|
|
80
|
+
*/
|
|
81
|
+
export type NotificationTaskSubtaskCleanupFunction<I extends NotificationTaskSubtaskInput<D, M, S>, CUI extends NotificationTaskSubtaskCleanupInstructions, D extends NotificationTaskSubtaskData<M, S>, M extends NotificationTaskSubtaskMetadata = any, S extends NotificationTaskSubtaskCheckpointString = NotificationTaskSubtaskCheckpointString> = (input: NotificationTaskSubtaskCleanupFunctionInput<I, D, M, S>, cleanupInstructions: CUI) => Promise<NotificationTaskServiceHandleNotificationTaskResult<D, NotificationTaskSubtaskCheckpoint>>;
|
|
82
|
+
/**
|
|
83
|
+
* The input function result may not include a target, and the notificationTask, completedSubtasks, and subtaskData properties are ignored.
|
|
84
|
+
*/
|
|
85
|
+
export type NotificationTaskSubtaskCleanupFunctionInput<I extends NotificationTaskSubtaskInput<D, M, S>, D extends NotificationTaskSubtaskData<M, S>, M extends NotificationTaskSubtaskMetadata = any, S extends NotificationTaskSubtaskCheckpointString = NotificationTaskSubtaskCheckpointString> = Omit<I, 'target' | 'completedSubtasks' | 'subtaskData'> & Partial<Pick<I, 'target'>>;
|
|
86
|
+
/**
|
|
87
|
+
* Similar to NotificationTaskServiceTaskHandlerConfig, but instead targets a specific NotificationTaskSubtaskTarget.
|
|
88
|
+
*
|
|
89
|
+
* The flows behave the same way.
|
|
90
|
+
*/
|
|
91
|
+
export interface NotificationTaskSubtaskProcessorConfig<I extends NotificationTaskSubtaskInput<D, M, S>, CUI extends NotificationTaskSubtaskCleanupInstructions, D extends NotificationTaskSubtaskData<M, S>, M extends NotificationTaskSubtaskMetadata = any, S extends NotificationTaskSubtaskCheckpointString = NotificationTaskSubtaskCheckpointString> {
|
|
92
|
+
/**
|
|
93
|
+
* The target this configuration is for.
|
|
94
|
+
*/
|
|
95
|
+
readonly target: NotificationTaskSubtaskTarget;
|
|
96
|
+
/**
|
|
97
|
+
* The order/flow of checkpoints and handler functions.
|
|
98
|
+
*
|
|
99
|
+
* When handling a notification task, if the checkpoint has already been completed then the entry will be skipped.
|
|
100
|
+
*/
|
|
101
|
+
readonly flow: NotificationTaskSubtaskFlowEntry<I, D, M, S>[];
|
|
102
|
+
/**
|
|
103
|
+
* Optional cleanup function for the subtask.
|
|
104
|
+
*
|
|
105
|
+
* If not provided, the default cleanup actions will take place.
|
|
106
|
+
*/
|
|
107
|
+
readonly cleanup?: NotificationTaskSubtaskCleanupInstructionsFunction<I, CUI, D, M, S>;
|
|
108
|
+
/**
|
|
109
|
+
* If true, then results returned by this processor will set "canRunNextCheckpoint" to true if it is undefined.
|
|
110
|
+
*/
|
|
111
|
+
readonly allowRunMultipleParts?: Maybe<boolean>;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Generates input for a NotificationTaskSubtaskNotificationTaskHandler from the provided NotificationTask.
|
|
115
|
+
*
|
|
116
|
+
* Should throw an NotificationTaskSubTaskMissingRequiredDataTermination error if the NotificationTask is missing required data.
|
|
117
|
+
*/
|
|
118
|
+
export type NotificationTaskSubtaskNotificationTaskHandlerInputFunction<I extends NotificationTaskSubtaskInput<D, M, S>, D extends NotificationTaskSubtaskData<M, S>, M extends NotificationTaskSubtaskMetadata = any, S extends NotificationTaskSubtaskCheckpointString = NotificationTaskSubtaskCheckpointString> = (data: D, notificationTask: NotificationTask<D>) => PromiseOrValue<NotificationTaskSubtaskNotificationTaskHandlerInputFunctionResult<I, D, M, S>>;
|
|
119
|
+
/**
|
|
120
|
+
* The input function result may not include a target, and the notificationTask, completedSubtasks, and subtaskData properties are ignored.
|
|
121
|
+
*/
|
|
122
|
+
export type NotificationTaskSubtaskNotificationTaskHandlerInputFunctionResult<I extends NotificationTaskSubtaskInput<D, M, S>, D extends NotificationTaskSubtaskData<M, S>, M extends NotificationTaskSubtaskMetadata = any, S extends NotificationTaskSubtaskCheckpointString = NotificationTaskSubtaskCheckpointString> = Omit<I, 'target' | 'notificationTask' | 'completedSubtasks' | 'subtaskData'> & Partial<Pick<I, 'target'>>;
|
|
123
|
+
/**
|
|
124
|
+
* Function that builds the update metadata for a NotificationTaskSubtask.
|
|
125
|
+
*
|
|
126
|
+
* Updates to sfps and sd are ignored, as those should be managed by the processors/flow entries.
|
|
127
|
+
*/
|
|
128
|
+
export type NotificationTaskSubtaskNotificationTaskHandlerBuildUpdateMetadataFunction<I extends NotificationTaskSubtaskInput<D, M, S>, D extends NotificationTaskSubtaskData<M, S>, M extends NotificationTaskSubtaskMetadata = any, S extends NotificationTaskSubtaskCheckpointString = NotificationTaskSubtaskCheckpointString> = (baseUpdateMetadata: D, input: I) => PromiseOrValue<Omit<D, 'sfps' | 'sd'>>;
|
|
129
|
+
/**
|
|
130
|
+
* Configuration for notificationTaskSubtaskNotificationTaskHandler().
|
|
131
|
+
*/
|
|
132
|
+
export interface NotificationTaskSubtaskNotificationTaskHandlerFactoryConfig<I extends NotificationTaskSubtaskInput<D, M, S>, CUI extends NotificationTaskSubtaskCleanupInstructions, D extends NotificationTaskSubtaskData<M, S>, M extends NotificationTaskSubtaskMetadata = any, S extends NotificationTaskSubtaskCheckpointString = NotificationTaskSubtaskCheckpointString> {
|
|
133
|
+
/**
|
|
134
|
+
* A name for the subtask handler. Used for logging errors.
|
|
135
|
+
*/
|
|
136
|
+
readonly subtaskHandlerFunctionName: string;
|
|
137
|
+
/**
|
|
138
|
+
* The task type
|
|
139
|
+
*/
|
|
140
|
+
readonly taskType: NotificationTaskType;
|
|
141
|
+
/**
|
|
142
|
+
* Creates input for the NotificationTaskSubtaskNotificationTaskHandler from the provided NotificationTask.
|
|
143
|
+
*/
|
|
144
|
+
readonly inputFunction: NotificationTaskSubtaskNotificationTaskHandlerInputFunction<I, D, M, S>;
|
|
145
|
+
/**
|
|
146
|
+
* Configuration function for building/extending the update metadata for the NotificationTaskSubtaskNotificationTask.
|
|
147
|
+
*/
|
|
148
|
+
readonly buildUpdateMetadata?: NotificationTaskSubtaskNotificationTaskHandlerBuildUpdateMetadataFunction<I, D, M, S>;
|
|
149
|
+
/**
|
|
150
|
+
* The default cleanup instructions function.
|
|
151
|
+
*/
|
|
152
|
+
readonly defaultCleanup: NotificationTaskSubtaskCleanupInstructionsFunction<I, CUI, D, M, S>;
|
|
153
|
+
/**
|
|
154
|
+
* The cleanup function to execute using the input and instructions.
|
|
155
|
+
*/
|
|
156
|
+
readonly cleanupFunction: NotificationTaskSubtaskCleanupFunction<I, CUI, D, M, S>;
|
|
157
|
+
/**
|
|
158
|
+
* Sets the default max cleanup retry attempts for each processor.
|
|
159
|
+
*/
|
|
160
|
+
readonly defaultMaxCleanupRetryAttempts?: Maybe<number>;
|
|
161
|
+
/**
|
|
162
|
+
* Sets the default cleanup retry delay for each processor.
|
|
163
|
+
*/
|
|
164
|
+
readonly defaultCleanupRetryDelay?: Maybe<Milliseconds>;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Creates a NotificationTaskServiceTaskHandlerConfig using the input config.
|
|
168
|
+
*/
|
|
169
|
+
export type NotificationTaskSubtaskNotificationTaskHandlerFactory<I extends NotificationTaskSubtaskInput<D, M, S>, CUI extends NotificationTaskSubtaskCleanupInstructions, D extends NotificationTaskSubtaskData<M, S>, M extends NotificationTaskSubtaskMetadata = any, S extends NotificationTaskSubtaskCheckpointString = NotificationTaskSubtaskCheckpointString> = (config: NotificationTaskSubtaskNotificationTaskHandlerConfig<I, CUI, D, M, S>) => NotificationTaskServiceTaskHandlerConfig<D, NotificationTaskSubtaskCheckpoint>;
|
|
170
|
+
/**
|
|
171
|
+
* Configuration for notificationTaskSubtaskNotificationTaskHandler().
|
|
172
|
+
*/
|
|
173
|
+
export interface NotificationTaskSubtaskNotificationTaskHandlerConfig<I extends NotificationTaskSubtaskInput<D, M, S>, CUI extends NotificationTaskSubtaskCleanupInstructions, D extends NotificationTaskSubtaskData<M, S>, M extends NotificationTaskSubtaskMetadata = any, S extends NotificationTaskSubtaskCheckpointString = NotificationTaskSubtaskCheckpointString> {
|
|
174
|
+
/**
|
|
175
|
+
* List of all target values for the app. Used for verifying that all target values are handled.
|
|
176
|
+
*/
|
|
177
|
+
readonly validate?: NotificationTaskSubtaskTarget[];
|
|
178
|
+
/**
|
|
179
|
+
* List of handlers for NotificationTaskSubtaskTarget values.
|
|
180
|
+
*/
|
|
181
|
+
readonly processors: NotificationTaskSubtaskProcessorConfig<I, CUI, D, M, S>[];
|
|
182
|
+
/**
|
|
183
|
+
* The maximum number of times to delay the cleanup step of a NotificationTaskSubtaskNotificationTask.
|
|
184
|
+
*
|
|
185
|
+
* Defaults to DEFAULT_MAX_STORAGE_FILE_PROCESSING_CLEANUP_RETRY_ATTEMPTS.
|
|
186
|
+
*/
|
|
187
|
+
readonly maxCleanupRetryAttempts?: Maybe<number>;
|
|
188
|
+
/**
|
|
189
|
+
* The amount of time to delay the cleanup step of a NotificationTaskSubtaskNotificationTask.
|
|
190
|
+
*
|
|
191
|
+
* Defaults to DEFAULT_STORAGE_FILE_PROCESSING_CLEANUP_RETRY_DELAY.
|
|
192
|
+
*/
|
|
193
|
+
readonly cleanupRetryDelay?: Maybe<Milliseconds>;
|
|
194
|
+
/**
|
|
195
|
+
* The default value to use for allowRunMultipleParts if it is not specified, for each processor.
|
|
196
|
+
*/
|
|
197
|
+
readonly defaultAllowRunMultipleParts?: Maybe<boolean>;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Creates a NotificationTaskSubtaskNotificationTaskHandlerFactory.
|
|
201
|
+
*/
|
|
202
|
+
export declare function notificationTaskSubtaskNotificationTaskHandlerFactory<I extends NotificationTaskSubtaskInput<D, M, S>, CUI extends NotificationTaskSubtaskCleanupInstructions, D extends NotificationTaskSubtaskData<M, S>, M extends NotificationTaskSubtaskMetadata = any, S extends NotificationTaskSubtaskCheckpointString = NotificationTaskSubtaskCheckpointString>(factoryConfig: NotificationTaskSubtaskNotificationTaskHandlerFactoryConfig<I, CUI, D, M, S>): NotificationTaskSubtaskNotificationTaskHandlerFactory<I, CUI, D, M, S>;
|
|
203
|
+
/**
|
|
204
|
+
* Thrown when a subtask no longer has data available to continue processing.
|
|
205
|
+
*
|
|
206
|
+
* The subtask will be marked as immediately complete, and no cleanup will occur.
|
|
207
|
+
*
|
|
208
|
+
* This is useful in cases where the underlying models or data that the subtask rely on are deleted (and those models were also required for cleanup) so the task can be marked as complete without attempting cleanup.
|
|
209
|
+
*/
|
|
210
|
+
export declare class NotificationTaskSubTaskMissingRequiredDataTermination extends BaseError {
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Creates a NotificationTaskSubTaskMissingRequiredDataTermination.
|
|
214
|
+
*/
|
|
215
|
+
export declare function notificationTaskSubTaskMissingRequiredDataTermination(): NotificationTaskSubTaskMissingRequiredDataTermination;
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NotificationTaskSubTaskMissingRequiredDataTermination = void 0;
|
|
4
|
+
exports.notificationTaskSubtaskNotificationTaskHandlerFactory = notificationTaskSubtaskNotificationTaskHandlerFactory;
|
|
5
|
+
exports.notificationTaskSubTaskMissingRequiredDataTermination = notificationTaskSubTaskMissingRequiredDataTermination;
|
|
6
|
+
const firebase_1 = require("@dereekb/firebase");
|
|
7
|
+
const util_1 = require("@dereekb/util");
|
|
8
|
+
const make_error_1 = require("make-error");
|
|
9
|
+
const notification_task_service_util_1 = require("./notification.task.service.util");
|
|
10
|
+
/**
|
|
11
|
+
* Creates a NotificationTaskSubtaskNotificationTaskHandlerFactory.
|
|
12
|
+
*/
|
|
13
|
+
function notificationTaskSubtaskNotificationTaskHandlerFactory(factoryConfig) {
|
|
14
|
+
const { taskType, subtaskHandlerFunctionName: subtaskHandlerName, inputFunction, defaultCleanup, cleanupFunction, buildUpdateMetadata: inputBuildUpdateMetadata } = factoryConfig;
|
|
15
|
+
return (subtaskHandlerConfig) => {
|
|
16
|
+
const { processors: inputProcessors, maxCleanupRetryAttempts: inputMaxCleanupRetryAttempts, cleanupRetryDelay: inputCleanupRetryDelay, defaultAllowRunMultipleParts } = subtaskHandlerConfig;
|
|
17
|
+
const maxCleanupRetryAttempts = inputMaxCleanupRetryAttempts ?? firebase_1.DEFAULT_NOTIFICATION_TASK_SUBTASK_CLEANUP_RETRY_ATTEMPTS;
|
|
18
|
+
const cleanupRetryDelay = inputCleanupRetryDelay ?? firebase_1.DEFAULT_NOTIFICATION_TASK_SUBTASK_CLEANUP_RETRY_DELAY;
|
|
19
|
+
const buildUpdateMetadata = inputBuildUpdateMetadata ?? (() => undefined);
|
|
20
|
+
const processors = {};
|
|
21
|
+
inputProcessors.forEach((processorConfig) => {
|
|
22
|
+
const { target } = processorConfig;
|
|
23
|
+
processors[target] = processorFunctionForConfig(processorConfig);
|
|
24
|
+
});
|
|
25
|
+
/**
|
|
26
|
+
* Structure is similar to notificationTaskService(), but contained to handle the subtasks.
|
|
27
|
+
*/
|
|
28
|
+
function processorFunctionForConfig(processorConfig) {
|
|
29
|
+
const { flow: inputFlows, cleanup, allowRunMultipleParts: processorAllowRunMultipleParts } = processorConfig;
|
|
30
|
+
const { included: subtaskFlows, excluded: nonSubtaskFlows } = (0, util_1.separateValues)(inputFlows, (x) => x.subtask != null);
|
|
31
|
+
const allowRunMultipleParts = processorAllowRunMultipleParts ?? defaultAllowRunMultipleParts;
|
|
32
|
+
if (inputFlows.length === 0) {
|
|
33
|
+
throw new Error(`${subtaskHandlerName}(): NotificationTaskSubtaskProcessorConfig must have at least one flow entry.`);
|
|
34
|
+
}
|
|
35
|
+
else if (nonSubtaskFlows.length > 1) {
|
|
36
|
+
throw new Error(`${subtaskHandlerName}(): NotificationTaskSubtaskProcessorConfig must not have more than one non-subtask flow.`);
|
|
37
|
+
}
|
|
38
|
+
const allKnownSubtasks = (0, util_1.unique)(inputFlows.map((x) => x.subtask));
|
|
39
|
+
return {
|
|
40
|
+
process: async (input) => {
|
|
41
|
+
const { notificationTask, completedSubtasks, subtaskData } = input;
|
|
42
|
+
let fn;
|
|
43
|
+
switch (completedSubtasks.length) {
|
|
44
|
+
case 0:
|
|
45
|
+
fn = (nonSubtaskFlows[0] ?? subtaskFlows[0])?.fn;
|
|
46
|
+
break;
|
|
47
|
+
default:
|
|
48
|
+
const completedSubtasksSet = new Set(completedSubtasks);
|
|
49
|
+
/**
|
|
50
|
+
* Find the next flow function that hasn't had its checkpoint completed yet.
|
|
51
|
+
*/
|
|
52
|
+
const nextSubtask = subtaskFlows.find((x) => !completedSubtasksSet.has(x.subtask));
|
|
53
|
+
fn = nextSubtask?.fn;
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
let result;
|
|
57
|
+
if (fn) {
|
|
58
|
+
/*
|
|
59
|
+
* This section is similar to handleNotificationTask() in notification.action.server.ts,
|
|
60
|
+
* but is modified to handle the subtasks. The main difference is the attempt count is maintained,
|
|
61
|
+
* and instead is available via the normal NotificationTask attempts details.
|
|
62
|
+
*/
|
|
63
|
+
const subtaskResult = await fn(input);
|
|
64
|
+
const { completion: subtaskCompletion, updateMetadata: subtaskUpdateMetadata, delayUntil, canRunNextCheckpoint } = subtaskResult;
|
|
65
|
+
let allSubtasksDone = false;
|
|
66
|
+
let sfps = completedSubtasks;
|
|
67
|
+
// update the task metadata to reflect the changes
|
|
68
|
+
switch (subtaskCompletion) {
|
|
69
|
+
case true:
|
|
70
|
+
allSubtasksDone = true;
|
|
71
|
+
break;
|
|
72
|
+
case false:
|
|
73
|
+
// remove any completions, if applicable
|
|
74
|
+
sfps = (0, notification_task_service_util_1.removeFromCompletionsArrayWithTaskResult)(sfps, subtaskResult);
|
|
75
|
+
break;
|
|
76
|
+
default:
|
|
77
|
+
sfps = (0, util_1.unique)([
|
|
78
|
+
...(0, notification_task_service_util_1.removeFromCompletionsArrayWithTaskResult)(sfps, subtaskResult), // remove any completions, if applicable
|
|
79
|
+
...(0, util_1.asArray)(subtaskCompletion)
|
|
80
|
+
]);
|
|
81
|
+
const completedSubtasksSet = new Set(sfps);
|
|
82
|
+
const incompleteSubtasks = allKnownSubtasks.filter((x) => !completedSubtasksSet.has(x));
|
|
83
|
+
allSubtasksDone = incompleteSubtasks.length === 0;
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
// configure the update metadata result
|
|
87
|
+
const sd = {
|
|
88
|
+
...subtaskData,
|
|
89
|
+
...subtaskUpdateMetadata
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* This is updating the metadata for the NotificationTask, which has a nested data
|
|
93
|
+
*/
|
|
94
|
+
const baseUpdateMetadata = {
|
|
95
|
+
...notificationTask.data,
|
|
96
|
+
sfps,
|
|
97
|
+
sd
|
|
98
|
+
};
|
|
99
|
+
let updateMetadata = (await buildUpdateMetadata(baseUpdateMetadata, input));
|
|
100
|
+
if (updateMetadata) {
|
|
101
|
+
// inject sfps and sd back in
|
|
102
|
+
updateMetadata = {
|
|
103
|
+
...updateMetadata,
|
|
104
|
+
sfps,
|
|
105
|
+
sd
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
updateMetadata = baseUpdateMetadata;
|
|
110
|
+
}
|
|
111
|
+
const nextCanRunNextCheckpoint = canRunNextCheckpoint ?? allowRunMultipleParts;
|
|
112
|
+
result = {
|
|
113
|
+
completion: allSubtasksDone ? ['processing'] : (0, firebase_1.delayCompletion)(), // return processing until all subtasks are complete.
|
|
114
|
+
updateMetadata,
|
|
115
|
+
canRunNextCheckpoint: nextCanRunNextCheckpoint,
|
|
116
|
+
allCompletedSubTasks: sfps,
|
|
117
|
+
delayUntil // delay is passed through
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
// no more subtasks to process, and no metadata changes. Mark as processing complete and continue.
|
|
122
|
+
result = (0, firebase_1.completeSubtaskProcessingAndScheduleCleanupTaskResult)();
|
|
123
|
+
}
|
|
124
|
+
return result;
|
|
125
|
+
},
|
|
126
|
+
cleanup
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
function useInputDataFactory(fn) {
|
|
130
|
+
return async (notificationTask) => {
|
|
131
|
+
const { data } = notificationTask;
|
|
132
|
+
let result;
|
|
133
|
+
if (data) {
|
|
134
|
+
try {
|
|
135
|
+
const inputFunctionResult = await inputFunction(data, notificationTask);
|
|
136
|
+
result = await fn(notificationTask, inputFunctionResult, data);
|
|
137
|
+
}
|
|
138
|
+
catch (e) {
|
|
139
|
+
if (e instanceof NotificationTaskSubTaskMissingRequiredDataTermination) {
|
|
140
|
+
// Task is complete if the required data no longer exists. Nothing to cleanup.
|
|
141
|
+
result = (0, firebase_1.notificationTaskComplete)();
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
// rethrow the error
|
|
145
|
+
throw e;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
// Improperly configured task. Complete immediately.
|
|
151
|
+
result = (0, firebase_1.notificationTaskComplete)();
|
|
152
|
+
}
|
|
153
|
+
return result;
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
const result = {
|
|
157
|
+
type: taskType,
|
|
158
|
+
flow: [
|
|
159
|
+
{
|
|
160
|
+
checkpoint: firebase_1.NOTIFICATION_TASK_SUBTASK_CHECKPOINT_PROCESSING,
|
|
161
|
+
fn: useInputDataFactory(async (notificationTask, inputFunctionResult, data) => {
|
|
162
|
+
let result;
|
|
163
|
+
const baseInput = {
|
|
164
|
+
...inputFunctionResult,
|
|
165
|
+
notificationTask
|
|
166
|
+
};
|
|
167
|
+
const { target } = baseInput;
|
|
168
|
+
if (target) {
|
|
169
|
+
const processor = processors[target];
|
|
170
|
+
if (processor) {
|
|
171
|
+
const { sd: subtaskData, sfps: completedSubtasks } = data;
|
|
172
|
+
const input = {
|
|
173
|
+
...baseInput,
|
|
174
|
+
target,
|
|
175
|
+
completedSubtasks: completedSubtasks ?? [],
|
|
176
|
+
subtaskData
|
|
177
|
+
};
|
|
178
|
+
result = await processor.process(input);
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
// processor is unknown. Complete the task.
|
|
182
|
+
result = (0, firebase_1.completeSubtaskProcessingAndScheduleCleanupTaskResult)();
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
// target is unknown. Complete the task.
|
|
187
|
+
result = (0, firebase_1.completeSubtaskProcessingAndScheduleCleanupTaskResult)();
|
|
188
|
+
}
|
|
189
|
+
return result;
|
|
190
|
+
})
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
checkpoint: firebase_1.NOTIFICATION_TASK_SUBTASK_CHECKPOINT_CLEANUP,
|
|
194
|
+
fn: useInputDataFactory(async (notificationTask, inputFunctionResult, data) => {
|
|
195
|
+
let result;
|
|
196
|
+
let cleanupFunctionInput = {
|
|
197
|
+
...inputFunctionResult,
|
|
198
|
+
notificationTask
|
|
199
|
+
};
|
|
200
|
+
const { target } = cleanupFunctionInput;
|
|
201
|
+
let cleanupInstructions;
|
|
202
|
+
if (target) {
|
|
203
|
+
const processor = processors[target];
|
|
204
|
+
if (processor && processor.cleanup) {
|
|
205
|
+
const { sd: subtaskData, sfps: completedSubtasks } = data;
|
|
206
|
+
const input = {
|
|
207
|
+
...cleanupFunctionInput,
|
|
208
|
+
notificationTask,
|
|
209
|
+
completedSubtasks: completedSubtasks ?? [],
|
|
210
|
+
target,
|
|
211
|
+
subtaskData
|
|
212
|
+
};
|
|
213
|
+
cleanupInstructions = await processor.cleanup(input);
|
|
214
|
+
cleanupFunctionInput = input;
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
// processor is unknown. Complete the task.
|
|
218
|
+
cleanupInstructions = defaultCleanup(cleanupFunctionInput);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
// target is unknown. Complete the task.
|
|
223
|
+
cleanupInstructions = defaultCleanup(cleanupFunctionInput);
|
|
224
|
+
}
|
|
225
|
+
if (cleanupInstructions.cleanupSuccess === false && notificationTask.currentCheckpointSendAttempts <= maxCleanupRetryAttempts) {
|
|
226
|
+
result = (0, firebase_1.notificationTaskDelayRetry)(cleanupInstructions.delayRetryUntil ?? cleanupRetryDelay);
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
result = await cleanupFunction(cleanupFunctionInput, cleanupInstructions);
|
|
230
|
+
}
|
|
231
|
+
return result;
|
|
232
|
+
})
|
|
233
|
+
}
|
|
234
|
+
]
|
|
235
|
+
};
|
|
236
|
+
return result;
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
// MARK: Internally Handled Errors
|
|
240
|
+
/**
|
|
241
|
+
* Thrown when a subtask no longer has data available to continue processing.
|
|
242
|
+
*
|
|
243
|
+
* The subtask will be marked as immediately complete, and no cleanup will occur.
|
|
244
|
+
*
|
|
245
|
+
* This is useful in cases where the underlying models or data that the subtask rely on are deleted (and those models were also required for cleanup) so the task can be marked as complete without attempting cleanup.
|
|
246
|
+
*/
|
|
247
|
+
class NotificationTaskSubTaskMissingRequiredDataTermination extends make_error_1.BaseError {
|
|
248
|
+
}
|
|
249
|
+
exports.NotificationTaskSubTaskMissingRequiredDataTermination = NotificationTaskSubTaskMissingRequiredDataTermination;
|
|
250
|
+
/**
|
|
251
|
+
* Creates a NotificationTaskSubTaskMissingRequiredDataTermination.
|
|
252
|
+
*/
|
|
253
|
+
function notificationTaskSubTaskMissingRequiredDataTermination() {
|
|
254
|
+
return new NotificationTaskSubTaskMissingRequiredDataTermination();
|
|
255
|
+
}
|
|
256
|
+
//# sourceMappingURL=notification.task.subtask.handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notification.task.subtask.handler.js","sourceRoot":"","sources":["../../../../../../../packages/firebase-server/model/src/lib/notification/notification.task.subtask.handler.ts"],"names":[],"mappings":";;;AAkPA,sHA8QC;AAeD,sHAEC;AAjhBD,gDAiB2B;AAE3B,wCAAkI;AAClI,2CAAuC;AACvC,qFAA4F;AA0N5F;;GAEG;AACH,SAAgB,qDAAqD,CACnE,aAA2F;IAE3F,MAAM,EAAE,QAAQ,EAAE,0BAA0B,EAAE,kBAAkB,EAAE,aAAa,EAAE,cAAc,EAAE,eAAe,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,GAAG,aAAa,CAAC;IAElL,OAAO,CAAC,oBAA2F,EAAE,EAAE;QACrG,MAAM,EAAE,UAAU,EAAE,eAAe,EAAE,uBAAuB,EAAE,4BAA4B,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,4BAA4B,EAAE,GAAG,oBAAoB,CAAC;QAC7L,MAAM,uBAAuB,GAAG,4BAA4B,IAAI,mEAAwD,CAAC;QACzH,MAAM,iBAAiB,GAAG,sBAAsB,IAAI,gEAAqD,CAAC;QAE1G,MAAM,mBAAmB,GAAG,wBAAwB,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAS1E,MAAM,UAAU,GAA6F,EAAE,CAAC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CACrD,oBAAoB,GAAG,KAAK,CAAC;4BAC/B,CAAC;iCAAM,CAAC;gCACN,2CAA2C;gCAC3C,mBAAmB,GAAG,cAAc,CAAC,oBAAoB,CAAC,CAAC;4BAC7D,CAAC;wBACH,CAAC;6BAAM,CAAC;4BACN,wCAAwC;4BACxC,mBAAmB,GAAG,cAAc,CAAC,oBAAoB,CAAC,CAAC;wBAC7D,CAAC;wBAED,IAAI,mBAAmB,CAAC,cAAc,KAAK,KAAK,IAAI,gBAAgB,CAAC,6BAA6B,IAAI,uBAAuB,EAAE,CAAC;4BAC9H,MAAM,GAAG,IAAA,qCAA0B,EAAC,mBAAmB,CAAC,eAAe,IAAI,iBAAiB,CAAC,CAAC;wBAChG,CAAC;6BAAM,CAAC;4BACN,MAAM,GAAG,MAAM,eAAe,CAAC,oBAAoB,EAAE,mBAAmB,CAAC,CAAC;wBAC5E,CAAC;wBAED,OAAO,MAAM,CAAC;oBAChB,CAAC,CAAC;iBACH;aACF;SACF,CAAC;QAEF,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC;AAED,kCAAkC;AAClC;;;;;;GAMG;AACH,MAAa,qDAAsD,SAAQ,sBAAS;CAAG;AAAvF,sHAAuF;AAEvF;;GAEG;AACH,SAAgB,qDAAqD;IACnE,OAAO,IAAI,qDAAqD,EAAE,CAAC;AACrE,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type FirestoreContextReference, InitializeStorageFileFromUploadParams, type AsyncStorageFileCreateAction, type StorageFileFirestoreCollections, ProcessStorageFileParams, type StorageFileDocument, type ProcessStorageFileResult, CreateStorageFileParams, type AsyncStorageFileUpdateAction, UpdateStorageFileParams, type NotificationFirestoreCollections, type FirebaseStorageAccessorFile, type InitializeAllStorageFilesFromUploadsResult, InitializeAllStorageFilesFromUploadsParams, ProcessAllQueuedStorageFilesParams, type ProcessAllQueuedStorageFilesResult, DeleteAllQueuedStorageFilesParams, type DeleteAllQueuedStorageFilesResult, DeleteStorageFileParams, type AsyncStorageFileDeleteAction } from '@dereekb/firebase';
|
|
1
|
+
import { type FirestoreContextReference, InitializeStorageFileFromUploadParams, type AsyncStorageFileCreateAction, type StorageFileFirestoreCollections, ProcessStorageFileParams, type StorageFileDocument, type ProcessStorageFileResult, CreateStorageFileParams, type AsyncStorageFileUpdateAction, UpdateStorageFileParams, type NotificationFirestoreCollections, type FirebaseStorageAccessorFile, type InitializeAllStorageFilesFromUploadsResult, InitializeAllStorageFilesFromUploadsParams, ProcessAllQueuedStorageFilesParams, type ProcessAllQueuedStorageFilesResult, DeleteAllQueuedStorageFilesParams, type DeleteAllQueuedStorageFilesResult, DeleteStorageFileParams, type AsyncStorageFileDeleteAction, DownloadStorageFileParams, type DownloadStorageFileResult } from '@dereekb/firebase';
|
|
2
2
|
import { type FirebaseServerStorageServiceRef, type FirebaseServerActionsContext, type FirebaseServerAuthServiceRef } from '@dereekb/firebase-server';
|
|
3
3
|
import { type TransformAndValidateFunctionResult } from '@dereekb/model';
|
|
4
4
|
import { type InjectionToken } from '@nestjs/common';
|
|
@@ -25,6 +25,7 @@ export declare abstract class StorageFileServerActions {
|
|
|
25
25
|
abstract processStorageFile(params: ProcessStorageFileParams): Promise<TransformAndValidateFunctionResult<ProcessStorageFileParams, (storageFileDocument: StorageFileDocument) => Promise<ProcessStorageFileResult>>>;
|
|
26
26
|
abstract deleteAllQueuedStorageFiles(params: DeleteAllQueuedStorageFilesParams): Promise<TransformAndValidateFunctionResult<DeleteAllQueuedStorageFilesParams, () => Promise<DeleteAllQueuedStorageFilesResult>>>;
|
|
27
27
|
abstract deleteStorageFile(params: DeleteStorageFileParams): AsyncStorageFileDeleteAction<DeleteStorageFileParams>;
|
|
28
|
+
abstract downloadStorageFile(params: DownloadStorageFileParams): Promise<TransformAndValidateFunctionResult<DownloadStorageFileParams, (storageFileDocument: StorageFileDocument) => Promise<DownloadStorageFileResult>>>;
|
|
28
29
|
}
|
|
29
30
|
export declare function storageFileServerActions(context: StorageFileServerActionsContext): StorageFileServerActions;
|
|
30
31
|
export declare function createStorageFileFactory(context: BaseStorageFileServerActionsContext): import("@dereekb/model").TransformAndValidateFunctionResultFunction<CreateStorageFileParams, () => Promise<any>, object, unknown>;
|
|
@@ -39,3 +40,4 @@ export declare function processAllQueuedStorageFilesFactory(context: StorageFile
|
|
|
39
40
|
export declare function processStorageFileFactory(context: StorageFileServerActionsContext): import("@dereekb/model").TransformAndValidateFunctionResultFunction<ProcessStorageFileParams, (storageFileDocument: StorageFileDocument) => Promise<ProcessStorageFileResult>, object, unknown>;
|
|
40
41
|
export declare function deleteAllQueuedStorageFilesFactory(context: StorageFileServerActionsContext): import("@dereekb/model").TransformAndValidateFunctionResultFunction<DeleteAllQueuedStorageFilesParams, () => Promise<DeleteAllQueuedStorageFilesResult>, object, unknown>;
|
|
41
42
|
export declare function deleteStorageFileFactory(context: StorageFileServerActionsContext): import("@dereekb/model").TransformAndValidateFunctionResultFunction<DeleteStorageFileParams, (inputStorageFileDocument: StorageFileDocument) => Promise<void>, object, unknown>;
|
|
43
|
+
export declare function downloadStorageFileFactory(context: StorageFileServerActionsContext): import("@dereekb/model").TransformAndValidateFunctionResultFunction<DownloadStorageFileParams, (storageFileDocument: StorageFileDocument) => Promise<DownloadStorageFileResult>, object, unknown>;
|
|
@@ -11,10 +11,13 @@ exports.processAllQueuedStorageFilesFactory = processAllQueuedStorageFilesFactor
|
|
|
11
11
|
exports.processStorageFileFactory = processStorageFileFactory;
|
|
12
12
|
exports.deleteAllQueuedStorageFilesFactory = deleteAllQueuedStorageFilesFactory;
|
|
13
13
|
exports.deleteStorageFileFactory = deleteStorageFileFactory;
|
|
14
|
+
exports.downloadStorageFileFactory = downloadStorageFileFactory;
|
|
14
15
|
const firebase_1 = require("@dereekb/firebase");
|
|
15
16
|
const firebase_server_1 = require("@dereekb/firebase-server");
|
|
16
17
|
const storagefile_error_1 = require("./storagefile.error");
|
|
17
18
|
const util_1 = require("@dereekb/util");
|
|
19
|
+
const date_1 = require("@dereekb/date");
|
|
20
|
+
const date_fns_1 = require("date-fns");
|
|
18
21
|
/**
|
|
19
22
|
* Injection token for the BaseStorageFileServerActionsContext
|
|
20
23
|
*/
|
|
@@ -35,7 +38,8 @@ function storageFileServerActions(context) {
|
|
|
35
38
|
processAllQueuedStorageFiles: processAllQueuedStorageFilesFactory(context),
|
|
36
39
|
processStorageFile: processStorageFileFactory(context),
|
|
37
40
|
deleteAllQueuedStorageFiles: deleteAllQueuedStorageFilesFactory(context),
|
|
38
|
-
deleteStorageFile: deleteStorageFileFactory(context)
|
|
41
|
+
deleteStorageFile: deleteStorageFileFactory(context),
|
|
42
|
+
downloadStorageFile: downloadStorageFileFactory(context)
|
|
39
43
|
};
|
|
40
44
|
}
|
|
41
45
|
// MARK: Actions
|
|
@@ -389,4 +393,37 @@ function deleteStorageFileFactory(context) {
|
|
|
389
393
|
};
|
|
390
394
|
});
|
|
391
395
|
}
|
|
396
|
+
function downloadStorageFileFactory(context) {
|
|
397
|
+
const { storageService, firebaseServerActionTransformFunctionFactory } = context;
|
|
398
|
+
return firebaseServerActionTransformFunctionFactory(firebase_1.DownloadStorageFileParams, async (params) => {
|
|
399
|
+
const { asAdmin, expiresAt, expiresIn, responseDisposition, responseContentType } = params;
|
|
400
|
+
return async (storageFileDocument) => {
|
|
401
|
+
const storageFile = await (0, firebase_server_1.assertSnapshotData)(storageFileDocument);
|
|
402
|
+
const fileAccessor = storageService.file(storageFile);
|
|
403
|
+
let result;
|
|
404
|
+
if (fileAccessor.getSignedUrl) {
|
|
405
|
+
const expires = (0, util_1.expirationDetails)({ expiresAt, expiresIn });
|
|
406
|
+
let downloadUrlExpiresAt = expires.getExpirationDate();
|
|
407
|
+
// if they're not an admin, limit the expiration to a max of 30 days.
|
|
408
|
+
if (downloadUrlExpiresAt && !asAdmin) {
|
|
409
|
+
const maxExpirationDate = (0, date_fns_1.addDays)(new Date(), 30);
|
|
410
|
+
downloadUrlExpiresAt = (0, date_1.findMinDate)([downloadUrlExpiresAt, maxExpirationDate]);
|
|
411
|
+
}
|
|
412
|
+
const downloadUrl = await fileAccessor.getSignedUrl({
|
|
413
|
+
action: 'read',
|
|
414
|
+
expiresAt: downloadUrlExpiresAt ?? undefined,
|
|
415
|
+
responseDisposition: responseDisposition ?? undefined, // can be set by anyone
|
|
416
|
+
responseType: asAdmin ? (responseContentType ?? undefined) : undefined // can only be set by admins
|
|
417
|
+
});
|
|
418
|
+
result = {
|
|
419
|
+
url: downloadUrl
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
else {
|
|
423
|
+
throw (0, firebase_server_1.internalServerError)('Signed url function appears to not be avalable.');
|
|
424
|
+
}
|
|
425
|
+
return result;
|
|
426
|
+
};
|
|
427
|
+
});
|
|
428
|
+
}
|
|
392
429
|
//# sourceMappingURL=storagefile.action.server.js.map
|