@dereekb/firebase-server 13.6.9 → 13.6.11

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.
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@dereekb/firebase-server/mailgun",
3
- "version": "13.6.9",
3
+ "version": "13.6.11",
4
4
  "peerDependencies": {
5
- "@dereekb/analytics": "13.6.9",
6
- "@dereekb/firebase": "13.6.9",
7
- "@dereekb/firebase-server": "13.6.9",
8
- "@dereekb/date": "13.6.9",
9
- "@dereekb/nestjs": "13.6.9",
10
- "@dereekb/model": "13.6.9",
11
- "@dereekb/rxjs": "13.6.9",
12
- "@dereekb/util": "13.6.9"
5
+ "@dereekb/analytics": "13.6.11",
6
+ "@dereekb/firebase": "13.6.11",
7
+ "@dereekb/firebase-server": "13.6.11",
8
+ "@dereekb/date": "13.6.11",
9
+ "@dereekb/nestjs": "13.6.11",
10
+ "@dereekb/model": "13.6.11",
11
+ "@dereekb/rxjs": "13.6.11",
12
+ "@dereekb/util": "13.6.11"
13
13
  },
14
14
  "exports": {
15
15
  "./package.json": "./package.json",
@@ -7192,7 +7192,7 @@ function _inherits(subClass, superClass) {
7192
7192
  });
7193
7193
  if (superClass) _set_prototype_of(subClass, superClass);
7194
7194
  }
7195
- function _instanceof(left, right) {
7195
+ function _instanceof$1(left, right) {
7196
7196
  if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
7197
7197
  return !!right[Symbol.hasInstance](left);
7198
7198
  } else {
@@ -7577,7 +7577,7 @@ function _ts_generator$5(thisArg, body) {
7577
7577
  ];
7578
7578
  case 4:
7579
7579
  e = _state.sent();
7580
- if (_instanceof(e, NotificationTaskSubTaskMissingRequiredDataTermination)) {
7580
+ if (_instanceof$1(e, NotificationTaskSubTaskMissingRequiredDataTermination)) {
7581
7581
  // Task is complete if the required data no longer exists. Nothing to cleanup.
7582
7582
  result = firebase.notificationTaskComplete();
7583
7583
  } else {
@@ -8017,6 +8017,13 @@ function _define_property$4(obj, key, value) {
8017
8017
  }
8018
8018
  return obj;
8019
8019
  }
8020
+ function _instanceof(left, right) {
8021
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
8022
+ return !!right[Symbol.hasInstance](left);
8023
+ } else {
8024
+ return left instanceof right;
8025
+ }
8026
+ }
8020
8027
  function _iterable_to_array_limit(arr, i) {
8021
8028
  var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
8022
8029
  if (_i == null) return;
@@ -8240,6 +8247,7 @@ function _ts_generator$4(thisArg, body) {
8240
8247
  deleteAllQueuedStorageFiles: deleteAllQueuedStorageFilesFactory(context),
8241
8248
  deleteStorageFile: deleteStorageFileFactory(context),
8242
8249
  downloadStorageFile: downloadStorageFileFactory(context),
8250
+ downloadMultipleStorageFiles: downloadMultipleStorageFilesFactory(context),
8243
8251
  createStorageFileGroup: createStorageFileGroupFactory(context),
8244
8252
  updateStorageFileGroup: updateStorageFileGroupFactory(context),
8245
8253
  syncStorageFileWithGroups: syncStorageFileWithGroupsFactory(context),
@@ -9467,91 +9475,172 @@ function _ts_generator$4(thisArg, body) {
9467
9475
  })();
9468
9476
  });
9469
9477
  }
9478
+ /**
9479
+ * Default maximum number of concurrent download operations when batch-downloading StorageFiles.
9480
+ */ var DEFAULT_DOWNLOAD_MULTIPLE_STORAGE_FILES_MAX_PARALLEL_TASKS = 5;
9481
+ /**
9482
+ * Internal factory that generates signed download URLs for one or more StorageFiles.
9483
+ *
9484
+ * Uses {@link performAsyncTasks} with concurrency limiting to avoid overwhelming Cloud Storage.
9485
+ * Shared expiration/disposition/content-type options are applied uniformly to all items.
9486
+ * When `throwOnFirstError` is true, the first failure throws immediately (single-download behavior).
9487
+ * When false, failures are collected in the errors array (batch behavior).
9488
+ *
9489
+ * @param context - the storage file server actions context
9490
+ * @returns an async function that processes a {@link DownloadMultipleStorageFilesFactoryInput} and returns a {@link DownloadMultipleStorageFilesResult}
9491
+ */ function _downloadMultipleStorageFilesFactory(context) {
9492
+ var storageService = context.storageService, storageFileCollection = context.storageFileCollection;
9493
+ return function(input) {
9494
+ return _async_to_generator$4(function() {
9495
+ var items, asAdmin, expiresAt, inputExpiresIn, responseDisposition, responseContentType, throwOnFirstError, inputMaxParallelTasks, taskResult, success, errors;
9496
+ return _ts_generator$4(this, function(_state) {
9497
+ switch(_state.label){
9498
+ case 0:
9499
+ items = input.items, asAdmin = input.asAdmin, expiresAt = input.expiresAt, inputExpiresIn = input.expiresIn, responseDisposition = input.responseDisposition, responseContentType = input.responseContentType, throwOnFirstError = input.throwOnFirstError, inputMaxParallelTasks = input.maxParallelTasks;
9500
+ return [
9501
+ 4,
9502
+ util.performAsyncTasks(items, function(item) {
9503
+ return _async_to_generator$4(function() {
9504
+ var _item_storageFileDocument, _item_responseDisposition, _item_responseContentType, _ref, _item_expiresIn, _item_expiresAt, storageFileDocument, storageFile, fileAccessor, itemResponseDisposition, itemResponseContentType, expiresIn, expires, downloadUrlExpiresAt, maxExpirationDate, _ref1, downloadUrl, metadata;
9505
+ return _ts_generator$4(this, function(_state) {
9506
+ switch(_state.label){
9507
+ case 0:
9508
+ // Load document from key if not provided
9509
+ storageFileDocument = (_item_storageFileDocument = item.storageFileDocument) !== null && _item_storageFileDocument !== void 0 ? _item_storageFileDocument : storageFileCollection.documentAccessor().loadDocumentForKey(item.key);
9510
+ return [
9511
+ 4,
9512
+ firebaseServer.assertSnapshotData(storageFileDocument)
9513
+ ];
9514
+ case 1:
9515
+ storageFile = _state.sent();
9516
+ fileAccessor = storageService.file(storageFile);
9517
+ if (!fileAccessor.getSignedUrl) {
9518
+ throw firebaseServer.internalServerError('Signed url function appears to not be available.');
9519
+ }
9520
+ // Per-item options override defaults
9521
+ itemResponseDisposition = (_item_responseDisposition = item.responseDisposition) !== null && _item_responseDisposition !== void 0 ? _item_responseDisposition : responseDisposition;
9522
+ itemResponseContentType = (_item_responseContentType = item.responseContentType) !== null && _item_responseContentType !== void 0 ? _item_responseContentType : responseContentType;
9523
+ expiresIn = (_ref = (_item_expiresIn = item.expiresIn) !== null && _item_expiresIn !== void 0 ? _item_expiresIn : inputExpiresIn) !== null && _ref !== void 0 ? _ref : util.MS_IN_MINUTE * 30;
9524
+ expires = util.expirationDetails({
9525
+ defaultExpiresFromDateToNow: true,
9526
+ expiresAt: (_item_expiresAt = item.expiresAt) !== null && _item_expiresAt !== void 0 ? _item_expiresAt : expiresAt,
9527
+ expiresIn: expiresIn
9528
+ });
9529
+ downloadUrlExpiresAt = expires.getExpirationDate(); // always returns a Date when defaultExpiresFromDateToNow and expiresIn are set
9530
+ // if they're not an admin, limit the expiration to a max of 30 days.
9531
+ if (!asAdmin) {
9532
+ maxExpirationDate = dateFns.addDays(new Date(), 30);
9533
+ downloadUrlExpiresAt = date.findMinDate([
9534
+ downloadUrlExpiresAt,
9535
+ maxExpirationDate
9536
+ ]);
9537
+ }
9538
+ return [
9539
+ 4,
9540
+ Promise.all([
9541
+ fileAccessor.getSignedUrl({
9542
+ action: 'read',
9543
+ expiresAt: downloadUrlExpiresAt,
9544
+ responseDisposition: itemResponseDisposition !== null && itemResponseDisposition !== void 0 ? itemResponseDisposition : undefined,
9545
+ responseType: asAdmin ? itemResponseContentType !== null && itemResponseContentType !== void 0 ? itemResponseContentType : undefined : undefined // can only be set by admins
9546
+ }),
9547
+ fileAccessor.getMetadata()
9548
+ ])
9549
+ ];
9550
+ case 2:
9551
+ _ref1 = _sliced_to_array.apply(void 0, [
9552
+ _state.sent(),
9553
+ 2
9554
+ ]), downloadUrl = _ref1[0], metadata = _ref1[1];
9555
+ return [
9556
+ 2,
9557
+ {
9558
+ key: item.key,
9559
+ url: downloadUrl,
9560
+ fileName: metadata.name ? util.slashPathDetails(metadata.name).end : undefined,
9561
+ mimeType: itemResponseContentType !== null && itemResponseContentType !== void 0 ? itemResponseContentType : metadata.contentType,
9562
+ expiresAt: util.unixDateTimeSecondsNumberFromDate(downloadUrlExpiresAt)
9563
+ }
9564
+ ];
9565
+ }
9566
+ });
9567
+ })();
9568
+ }, {
9569
+ throwError: throwOnFirstError !== null && throwOnFirstError !== void 0 ? throwOnFirstError : false,
9570
+ maxParallelTasks: inputMaxParallelTasks !== null && inputMaxParallelTasks !== void 0 ? inputMaxParallelTasks : DEFAULT_DOWNLOAD_MULTIPLE_STORAGE_FILES_MAX_PARALLEL_TASKS
9571
+ })
9572
+ ];
9573
+ case 1:
9574
+ taskResult = _state.sent();
9575
+ success = taskResult.results.map(function(param) {
9576
+ var _param = _sliced_to_array(param, 2), result = _param[1];
9577
+ return result;
9578
+ });
9579
+ errors = taskResult.errors.map(function(param) {
9580
+ var _param = _sliced_to_array(param, 2), item = _param[0], error = _param[1];
9581
+ return {
9582
+ key: item.key,
9583
+ error: _instanceof(error, Error) ? error.message : 'Download failed'
9584
+ };
9585
+ });
9586
+ return [
9587
+ 2,
9588
+ {
9589
+ success: success,
9590
+ errors: errors
9591
+ }
9592
+ ];
9593
+ }
9594
+ });
9595
+ })();
9596
+ };
9597
+ }
9470
9598
  /**
9471
9599
  * Factory for the `downloadStorageFile` action.
9472
9600
  *
9473
9601
  * Generates a signed download URL for a {@link StorageFile}'s associated Cloud Storage file.
9474
- * The URL expires after the configured duration. Supports loading the storage file document
9475
- * by key if not provided directly.
9602
+ * Delegates to {@link _downloadMultipleStorageFilesFactory} with a single item and `throwOnFirstError: true`.
9476
9603
  *
9477
9604
  * @param context - the storage file server actions context
9478
9605
  * @returns an async transform-and-validate function that generates a signed download URL
9479
9606
  */ function downloadStorageFileFactory(context) {
9480
- var storageService = context.storageService, firebaseServerActionTransformFunctionFactory = context.firebaseServerActionTransformFunctionFactory, storageFileCollection = context.storageFileCollection;
9607
+ var firebaseServerActionTransformFunctionFactory = context.firebaseServerActionTransformFunctionFactory;
9608
+ var downloadMultipleStorageFiles = _downloadMultipleStorageFilesFactory(context);
9481
9609
  return firebaseServerActionTransformFunctionFactory(firebase.downloadStorageFileParamsType, function(params) {
9482
9610
  return _async_to_generator$4(function() {
9483
- var targetStorageFileDocumentKey, asAdmin, expiresAt, inputExpiresIn, responseDisposition, responseContentType;
9611
+ var key, asAdmin, expiresAt, expiresIn, responseDisposition, responseContentType;
9484
9612
  return _ts_generator$4(this, function(_state) {
9485
- targetStorageFileDocumentKey = params.key, asAdmin = params.asAdmin, expiresAt = params.expiresAt, inputExpiresIn = params.expiresIn, responseDisposition = params.responseDisposition, responseContentType = params.responseContentType;
9613
+ key = params.key, asAdmin = params.asAdmin, expiresAt = params.expiresAt, expiresIn = params.expiresIn, responseDisposition = params.responseDisposition, responseContentType = params.responseContentType;
9486
9614
  return [
9487
9615
  2,
9488
9616
  function(storageFileDocument) {
9489
9617
  return _async_to_generator$4(function() {
9490
- var storageFile, fileAccessor, result, expiresIn, expires, downloadUrlExpiresAt, maxExpirationDate, _ref, downloadUrl, metadata;
9618
+ var result;
9491
9619
  return _ts_generator$4(this, function(_state) {
9492
9620
  switch(_state.label){
9493
9621
  case 0:
9494
- // if the StorageFileDocument was not provided, set it from the target key
9495
- storageFileDocument !== null && storageFileDocument !== void 0 ? storageFileDocument : storageFileDocument = storageFileCollection.documentAccessor().loadDocumentForKey(targetStorageFileDocumentKey);
9496
9622
  return [
9497
9623
  4,
9498
- firebaseServer.assertSnapshotData(storageFileDocument)
9624
+ downloadMultipleStorageFiles({
9625
+ items: [
9626
+ {
9627
+ key: key,
9628
+ storageFileDocument: storageFileDocument
9629
+ }
9630
+ ],
9631
+ asAdmin: asAdmin,
9632
+ expiresAt: expiresAt,
9633
+ expiresIn: expiresIn,
9634
+ responseDisposition: responseDisposition,
9635
+ responseContentType: responseContentType,
9636
+ throwOnFirstError: true
9637
+ })
9499
9638
  ];
9500
9639
  case 1:
9501
- storageFile = _state.sent();
9502
- fileAccessor = storageService.file(storageFile);
9503
- if (!fileAccessor.getSignedUrl) return [
9504
- 3,
9505
- 3
9506
- ];
9507
- expiresIn = inputExpiresIn !== null && inputExpiresIn !== void 0 ? inputExpiresIn : util.MS_IN_MINUTE * 30;
9508
- expires = util.expirationDetails({
9509
- defaultExpiresFromDateToNow: true,
9510
- expiresAt: expiresAt,
9511
- expiresIn: expiresIn
9512
- });
9513
- downloadUrlExpiresAt = expires.getExpirationDate(); // always returns a Date when defaultExpiresFromDateToNow and expiresIn are set
9514
- // if they're not an admin, limit the expiration to a max of 30 days.
9515
- if (!asAdmin) {
9516
- maxExpirationDate = dateFns.addDays(new Date(), 30);
9517
- downloadUrlExpiresAt = date.findMinDate([
9518
- downloadUrlExpiresAt,
9519
- maxExpirationDate
9520
- ]);
9521
- }
9522
- return [
9523
- 4,
9524
- Promise.all([
9525
- fileAccessor.getSignedUrl({
9526
- action: 'read',
9527
- expiresAt: downloadUrlExpiresAt,
9528
- responseDisposition: responseDisposition !== null && responseDisposition !== void 0 ? responseDisposition : undefined,
9529
- responseType: asAdmin ? responseContentType !== null && responseContentType !== void 0 ? responseContentType : undefined : undefined // can only be set by admins
9530
- }),
9531
- fileAccessor.getMetadata()
9532
- ])
9533
- ];
9534
- case 2:
9535
- _ref = _sliced_to_array.apply(void 0, [
9536
- _state.sent(),
9537
- 2
9538
- ]), downloadUrl = _ref[0], metadata = _ref[1];
9539
- result = {
9540
- url: downloadUrl,
9541
- fileName: metadata.name ? util.slashPathDetails(metadata.name).end : undefined,
9542
- mimeType: responseContentType !== null && responseContentType !== void 0 ? responseContentType : metadata.contentType,
9543
- expiresAt: util.unixDateTimeSecondsNumberFromDate(downloadUrlExpiresAt)
9544
- };
9545
- return [
9546
- 3,
9547
- 4
9548
- ];
9549
- case 3:
9550
- throw firebaseServer.internalServerError('Signed url function appears to not be avalable.');
9551
- case 4:
9640
+ result = _state.sent();
9552
9641
  return [
9553
9642
  2,
9554
- result
9643
+ result.success[0]
9555
9644
  ];
9556
9645
  }
9557
9646
  });
@@ -9562,6 +9651,59 @@ function _ts_generator$4(thisArg, body) {
9562
9651
  })();
9563
9652
  });
9564
9653
  }
9654
+ /**
9655
+ * Factory for the `downloadMultipleStorageFiles` action.
9656
+ *
9657
+ * Generates signed download URLs for multiple {@link StorageFile} documents in a single call.
9658
+ * By default, individual failures are collected in the errors array rather than failing the entire batch.
9659
+ * Set `throwOnFirstError` in params to throw on the first failure instead.
9660
+ *
9661
+ * @param context - the storage file server actions context
9662
+ * @returns an async transform-and-validate function that generates signed download URLs for multiple files
9663
+ */ function downloadMultipleStorageFilesFactory(context) {
9664
+ var firebaseServerActionTransformFunctionFactory = context.firebaseServerActionTransformFunctionFactory;
9665
+ var downloadMultipleStorageFiles = _downloadMultipleStorageFilesFactory(context);
9666
+ return firebaseServerActionTransformFunctionFactory(firebase.downloadMultipleStorageFilesParamsType, function(params) {
9667
+ return _async_to_generator$4(function() {
9668
+ var files, asAdmin, expiresAt, expiresIn, responseDisposition, responseContentType, throwOnFirstError;
9669
+ return _ts_generator$4(this, function(_state) {
9670
+ files = params.files, asAdmin = params.asAdmin, expiresAt = params.expiresAt, expiresIn = params.expiresIn, responseDisposition = params.responseDisposition, responseContentType = params.responseContentType, throwOnFirstError = params.throwOnFirstError;
9671
+ return [
9672
+ 2,
9673
+ function(storageFileDocuments) {
9674
+ return _async_to_generator$4(function() {
9675
+ var items;
9676
+ return _ts_generator$4(this, function(_state) {
9677
+ items = files.map(function(file, i) {
9678
+ return {
9679
+ key: file.key,
9680
+ storageFileDocument: storageFileDocuments === null || storageFileDocuments === void 0 ? void 0 : storageFileDocuments[i],
9681
+ expiresAt: file.expiresAt,
9682
+ expiresIn: file.expiresIn,
9683
+ responseDisposition: file.responseDisposition,
9684
+ responseContentType: file.responseContentType
9685
+ };
9686
+ });
9687
+ return [
9688
+ 2,
9689
+ downloadMultipleStorageFiles({
9690
+ items: items,
9691
+ asAdmin: asAdmin,
9692
+ expiresAt: expiresAt,
9693
+ expiresIn: expiresIn,
9694
+ responseDisposition: responseDisposition,
9695
+ responseContentType: responseContentType,
9696
+ throwOnFirstError: throwOnFirstError !== null && throwOnFirstError !== void 0 ? throwOnFirstError : false
9697
+ })
9698
+ ];
9699
+ });
9700
+ })();
9701
+ }
9702
+ ];
9703
+ });
9704
+ })();
9705
+ });
9706
+ }
9565
9707
  /**
9566
9708
  * Internal factory that creates a function for creating a {@link StorageFileGroup} document
9567
9709
  * within a Firestore transaction.
@@ -12419,6 +12561,7 @@ function _ts_generator(thisArg, body) {
12419
12561
 
12420
12562
  exports.BASE_NOTIFICATION_SERVER_ACTION_CONTEXT_TOKEN = BASE_NOTIFICATION_SERVER_ACTION_CONTEXT_TOKEN;
12421
12563
  exports.BASE_STORAGE_FILE_SERVER_ACTION_CONTEXT_TOKEN = BASE_STORAGE_FILE_SERVER_ACTION_CONTEXT_TOKEN;
12564
+ exports.DEFAULT_DOWNLOAD_MULTIPLE_STORAGE_FILES_MAX_PARALLEL_TASKS = DEFAULT_DOWNLOAD_MULTIPLE_STORAGE_FILES_MAX_PARALLEL_TASKS;
12422
12565
  exports.KNOWN_BUT_UNCONFIGURED_NOTIFICATION_TEMPLATE_TYPE_DELETE_AFTER_RETRY_ATTEMPTS = KNOWN_BUT_UNCONFIGURED_NOTIFICATION_TEMPLATE_TYPE_DELETE_AFTER_RETRY_ATTEMPTS;
12423
12566
  exports.KNOWN_BUT_UNCONFIGURED_NOTIFICATION_TEMPLATE_TYPE_HOURS_DELAY = KNOWN_BUT_UNCONFIGURED_NOTIFICATION_TEMPLATE_TYPE_HOURS_DELAY;
12424
12567
  exports.MAILGUN_NOTIFICATION_EMAIL_SEND_SERVICE_DEFAULT_MAX_BATCH_SIZE_PER_REQUEST = MAILGUN_NOTIFICATION_EMAIL_SEND_SERVICE_DEFAULT_MAX_BATCH_SIZE_PER_REQUEST;
@@ -12469,6 +12612,7 @@ exports.createStorageFileGroupInTransactionFactory = createStorageFileGroupInTra
12469
12612
  exports.createStorageFileGroupInputError = createStorageFileGroupInputError;
12470
12613
  exports.deleteAllQueuedStorageFilesFactory = deleteAllQueuedStorageFilesFactory;
12471
12614
  exports.deleteStorageFileFactory = deleteStorageFileFactory;
12615
+ exports.downloadMultipleStorageFilesFactory = downloadMultipleStorageFilesFactory;
12472
12616
  exports.downloadStorageFileFactory = downloadStorageFileFactory;
12473
12617
  exports.expandNotificationRecipients = expandNotificationRecipients;
12474
12618
  exports.exportMutableNotificationExpediteService = exportMutableNotificationExpediteService;