@dereekb/firebase-server 13.11.1 → 13.11.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/index.cjs.js +29 -2
  2. package/index.esm.js +30 -3
  3. package/mailgun/package.json +9 -9
  4. package/model/index.cjs.js +330 -43
  5. package/model/index.esm.js +332 -46
  6. package/model/package.json +9 -9
  7. package/model/src/lib/notification/notification.action.server.d.ts +16 -1
  8. package/model/src/lib/notification/notification.module.d.ts +4 -0
  9. package/oidc/index.cjs.js +2 -52
  10. package/oidc/index.esm.js +2 -47
  11. package/oidc/package.json +10 -10
  12. package/oidc/src/lib/scope.d.ts +1 -41
  13. package/package.json +10 -10
  14. package/src/lib/firestore/array.d.ts +1 -0
  15. package/src/lib/firestore/driver.accessor.batch.d.ts +1 -0
  16. package/src/lib/firestore/driver.accessor.default.d.ts +1 -0
  17. package/src/lib/firestore/driver.accessor.transaction.d.ts +1 -0
  18. package/src/lib/firestore/driver.query.d.ts +1 -0
  19. package/src/lib/firestore/increment.d.ts +1 -0
  20. package/src/lib/firestore/snapshot/snapshot.field.encrypt.d.ts +2 -0
  21. package/src/lib/nest/app.module.d.ts +1 -0
  22. package/src/lib/nest/auth/auth.module.d.ts +1 -0
  23. package/src/lib/nest/development/development.app.function.d.ts +1 -0
  24. package/src/lib/nest/development/development.function.d.ts +1 -0
  25. package/src/lib/nest/development/development.schedule.function.d.ts +1 -0
  26. package/src/lib/nest/development/development.schedule.function.error.d.ts +1 -0
  27. package/src/lib/nest/function/call.d.ts +1 -0
  28. package/src/lib/nest/function/context.d.ts +1 -0
  29. package/src/lib/nest/function/v2/blocking.d.ts +2 -0
  30. package/src/lib/nest/function/v2/call.d.ts +2 -0
  31. package/src/lib/nest/function/v2/event.d.ts +1 -0
  32. package/src/lib/nest/function/v2/schedule.d.ts +3 -0
  33. package/src/lib/nest/function/v2/taskqueue.d.ts +1 -0
  34. package/src/lib/nest/model/analytics.handler.d.ts +1 -0
  35. package/src/lib/nest/model/call.model.function.d.ts +1 -0
  36. package/src/lib/nest/model/create.model.function.d.ts +1 -0
  37. package/src/lib/nest/storage/storage.module.d.ts +1 -0
  38. package/test/package.json +11 -11
  39. package/zoho/package.json +9 -9
@@ -1514,7 +1514,8 @@ function _ts_generator$d(thisArg, body) {
1514
1514
  updateNotificationBoxRecipient: updateNotificationBoxRecipientFactory(context),
1515
1515
  sendNotification: sendNotificationFactory(context),
1516
1516
  sendQueuedNotifications: sendQueuedNotificationsFactory(context),
1517
- cleanupSentNotifications: cleanupSentNotificationsFactory(context)
1517
+ cleanupSentNotifications: cleanupSentNotificationsFactory(context),
1518
+ cleanupOldNotificationLoggedEventDays: cleanupOldNotificationLoggedEventDaysFactory(context)
1518
1519
  };
1519
1520
  }
1520
1521
  // MARK: Actions
@@ -2747,7 +2748,7 @@ var NOTIFICATION_TASK_TYPE_FAILURE_DELAY_MS = dateFns.hoursToMilliseconds(NOTIFI
2747
2748
  2,
2748
2749
  function(inputNotificationDocument) {
2749
2750
  return _async_to_generator$d(function() {
2750
- var now, notificationDocument, _ref, nextSat, throttled, tryRun, isNotificationTask, notificationTaskHandler, notification, createdBox, notificationBoxNeedsInitialization, notificationBox, notificationBoxModelKey, deletedNotification, templateInstance, isConfiguredTemplateType, isKnownTemplateType, onlySendToExplicitlyEnabledRecipients, onlyTextExplicitlyEnabledRecipients, success, isUniqueNotificationTask, uniqueNotificationTaskConflict, sendEmailsResult, sendTextsResult, sendNotificationSummaryResult, loadMessageFunctionFailure, buildMessageFailure, notificationMarkedDone, notificationTaskCompletionType, notificationTaskPartsRunCount, notificationTaskLoopingProtectionTriggered, onSendAttemptedResult, onSendSuccessResult, notificationTemplateType, result;
2751
+ var now, notificationDocument, _ref, nextSat, throttled, tryRun, isNotificationTask, isLoggedEvent, notificationTaskHandler, notification, createdBox, notificationBoxNeedsInitialization, notificationBox, notificationBoxModelKey, deletedNotification, templateInstance, isConfiguredTemplateType, isKnownTemplateType, onlySendToExplicitlyEnabledRecipients, onlyTextExplicitlyEnabledRecipients, success, isUniqueNotificationTask, uniqueNotificationTaskConflict, sendEmailsResult, sendTextsResult, sendNotificationSummaryResult, loadMessageFunctionFailure, buildMessageFailure, notificationMarkedDone, notificationTaskCompletionType, notificationTaskPartsRunCount, notificationTaskLoopingProtectionTriggered, onSendAttemptedResult, onSendSuccessResult, notificationTemplateType, result;
2751
2752
  function _runNotificationTaskNextPart(input) {
2752
2753
  return _async_to_generator$d(function() {
2753
2754
  var _notification_at, notification, notificationTaskHandler, previouslyCompleteSubTasks, item, cat, ut, tryRunNextPart, partNotificationTaskCompletionType, partNotificationMarkedDone, partTprReversal, partSuccess, nextCompleteSubTasks, unique, notificationTask, notificationTemplate, handleTaskResult, completion, updateMetadata, delayUntil, canRunNextCheckpoint, allCompletedSubTasks, _notification_at1, _notification_at2, tprChanged, subtaskTprChanged, _findMaxDate, minimumNextSatTime, e, saveTaskResult, latestNotification;
@@ -3499,6 +3500,7 @@ var NOTIFICATION_TASK_TYPE_FAILURE_DELAY_MS = dateFns.hoursToMilliseconds(NOTIFI
3499
3500
  case firebase.NotificationSendType.INIT_BOX_AND_SEND:
3500
3501
  case firebase.NotificationSendType.SEND_WITHOUT_CREATING_BOX:
3501
3502
  case firebase.NotificationSendType.TASK_NOTIFICATION:
3503
+ case firebase.NotificationSendType.LOGGED_EVENT:
3502
3504
  break;
3503
3505
  }
3504
3506
  _state.label = 48;
@@ -3520,7 +3522,7 @@ var NOTIFICATION_TASK_TYPE_FAILURE_DELAY_MS = dateFns.hoursToMilliseconds(NOTIFI
3520
3522
  4,
3521
3523
  firestoreContext.runTransaction(function(transaction) {
3522
3524
  return _async_to_generator$d(function() {
3523
- var notificationBoxDocument, notificationDocumentInTransaction, _ref, initialNotificationBox, notification, notificationBox, model, isNotificationTask, tryRun, throttled, nextSat, createdBox, deletedNotification, notificationBoxNeedsInitialization, isKnownTemplateType, isConfiguredTemplateType, onlySendToExplicitlyEnabledRecipients, onlyTextExplicitlyEnabledRecipients, templateInstance, notificationTaskHandler, t // notification task/template type
3525
+ var notificationBoxDocument, notificationDocumentInTransaction, _ref, initialNotificationBox, notification, notificationBox, model, isNotificationTask, isLoggedEvent, tryRun, throttled, nextSat, createdBox, deletedNotification, notificationBoxNeedsInitialization, isKnownTemplateType, isConfiguredTemplateType, onlySendToExplicitlyEnabledRecipients, onlyTextExplicitlyEnabledRecipients, templateInstance, notificationTaskHandler, t // notification task/template type
3524
3526
  , delay, _notification_ois, _notification_ots, templateTypeInfo, retryAttempts, delay1, _, notificationBoxTemplate, isAtMaxAttempts, a;
3525
3527
  function deleteNotification() {
3526
3528
  return _async_to_generator$d(function() {
@@ -3562,9 +3564,13 @@ var NOTIFICATION_TASK_TYPE_FAILURE_DELAY_MS = dateFns.hoursToMilliseconds(NOTIFI
3562
3564
  notificationBox = initialNotificationBox;
3563
3565
  model = firebase.inferKeyFromTwoWayFlatFirestoreModelKey(notificationBoxDocument.id);
3564
3566
  isNotificationTask = (notification === null || notification === void 0 ? void 0 : notification.st) === firebase.NotificationSendType.TASK_NOTIFICATION;
3567
+ // Defensive short-circuit. Logged events are persisted with d=true and NO_TRY channel
3568
+ // states from creation, so the send queue never returns them. This branch only triggers
3569
+ // when sendNotification() is invoked directly on a logged-event document.
3570
+ isLoggedEvent = (notification === null || notification === void 0 ? void 0 : notification.st) === firebase.NotificationSendType.LOGGED_EVENT;
3565
3571
  tryRun = true;
3566
3572
  throttled = false;
3567
- if (!notification) {
3573
+ if (!notification || isLoggedEvent) {
3568
3574
  tryRun = false;
3569
3575
  } else if (!ignoreSendAtThrottle) {
3570
3576
  tryRun = !dateFns.isFuture(notification.sat);
@@ -3587,7 +3593,7 @@ var NOTIFICATION_TASK_TYPE_FAILURE_DELAY_MS = dateFns.hoursToMilliseconds(NOTIFI
3587
3593
  notificationBoxNeedsInitialization = false;
3588
3594
  if (!(notification && tryRun)) return [
3589
3595
  3,
3590
- 19
3596
+ 20
3591
3597
  ];
3592
3598
  // if we're still trying to run, check the template is ok. If not, cancel the run.
3593
3599
  t = notification.n.t;
@@ -3644,7 +3650,7 @@ var NOTIFICATION_TASK_TYPE_FAILURE_DELAY_MS = dateFns.hoursToMilliseconds(NOTIFI
3644
3650
  case 7:
3645
3651
  return [
3646
3652
  3,
3647
- 19
3653
+ 20
3648
3654
  ];
3649
3655
  case 8:
3650
3656
  templateInstance = notificationTemplateService.templateInstanceForType(t);
@@ -3689,7 +3695,7 @@ var NOTIFICATION_TASK_TYPE_FAILURE_DELAY_MS = dateFns.hoursToMilliseconds(NOTIFI
3689
3695
  case 11:
3690
3696
  if (!(!notificationBox && tryRun)) return [
3691
3697
  3,
3692
- 18
3698
+ 19
3693
3699
  ];
3694
3700
  _ = notification.st;
3695
3701
  switch(_){
@@ -3713,10 +3719,15 @@ var NOTIFICATION_TASK_TYPE_FAILURE_DELAY_MS = dateFns.hoursToMilliseconds(NOTIFI
3713
3719
  3,
3714
3720
  17
3715
3721
  ];
3722
+ case firebase.NotificationSendType.LOGGED_EVENT:
3723
+ return [
3724
+ 3,
3725
+ 18
3726
+ ];
3716
3727
  }
3717
3728
  return [
3718
3729
  3,
3719
- 18
3730
+ 19
3720
3731
  ];
3721
3732
  case 12:
3722
3733
  return [
@@ -3731,7 +3742,7 @@ var NOTIFICATION_TASK_TYPE_FAILURE_DELAY_MS = dateFns.hoursToMilliseconds(NOTIFI
3731
3742
  createdBox = true;
3732
3743
  return [
3733
3744
  3,
3734
- 18
3745
+ 19
3735
3746
  ];
3736
3747
  case 14:
3737
3748
  // delete the notification since it won't get sent.
@@ -3743,49 +3754,56 @@ var NOTIFICATION_TASK_TYPE_FAILURE_DELAY_MS = dateFns.hoursToMilliseconds(NOTIFI
3743
3754
  _state.sent();
3744
3755
  return [
3745
3756
  3,
3746
- 18
3757
+ 19
3747
3758
  ];
3748
3759
  case 16:
3749
3760
  // continue with current tryRun
3750
3761
  return [
3751
3762
  3,
3752
- 18
3763
+ 19
3753
3764
  ];
3754
3765
  case 17:
3755
3766
  // task notifications do not require a notification box; continue with current tryRun
3756
3767
  return [
3757
3768
  3,
3758
- 18
3769
+ 19
3759
3770
  ];
3760
3771
  case 18:
3772
+ // unreachable in normal operation — logged events are short-circuited above. Kept
3773
+ // here so the enum exhaustiveness check stays satisfied.
3774
+ return [
3775
+ 3,
3776
+ 19
3777
+ ];
3778
+ case 19:
3761
3779
  // if the notification box is not initialized/synchronized yet, do not run.
3762
3780
  if (tryRun && (notificationBox === null || notificationBox === void 0 ? void 0 : notificationBox.s)) {
3763
3781
  notificationBoxNeedsInitialization = true;
3764
3782
  tryRun = false;
3765
3783
  nextSat = dateFns.addMinutes(now, NOTIFICATION_BOX_NOT_INITIALIZED_DELAY_MINUTES);
3766
3784
  }
3767
- _state.label = 19;
3768
- case 19:
3785
+ _state.label = 20;
3786
+ case 20:
3769
3787
  if (!(notification != null && nextSat != null && !deletedNotification)) return [
3770
3788
  3,
3771
- 23
3789
+ 24
3772
3790
  ];
3773
3791
  isAtMaxAttempts = notification.a >= NOTIFICATION_MAX_SEND_ATTEMPTS;
3774
3792
  if (!(isAtMaxAttempts && notificationBoxNeedsInitialization)) return [
3775
3793
  3,
3776
- 21
3794
+ 22
3777
3795
  ];
3778
3796
  return [
3779
3797
  4,
3780
3798
  deleteNotification()
3781
3799
  ];
3782
- case 20:
3783
- _state.sent(); // just delete the notification if the box still hasn't been initialized successfully at this point.
3784
- _state.label = 21;
3785
3800
  case 21:
3801
+ _state.sent(); // just delete the notification if the box still hasn't been initialized successfully at this point.
3802
+ _state.label = 22;
3803
+ case 22:
3786
3804
  if (!!deletedNotification) return [
3787
3805
  3,
3788
- 23
3806
+ 24
3789
3807
  ];
3790
3808
  a = isNotificationTask && tryRun ? notification.a : notification.a + 1; // do not update a notification task's attempt count here, unless tryRun fails
3791
3809
  // NOTE: It is important to update sat so the notification task queue running doesn't get stuck in a query loop by notifications/tasks that have a sat value that is in the past, but was just run.
@@ -3796,16 +3814,17 @@ var NOTIFICATION_TASK_TYPE_FAILURE_DELAY_MS = dateFns.hoursToMilliseconds(NOTIFI
3796
3814
  a: a
3797
3815
  })
3798
3816
  ];
3799
- case 22:
3800
- _state.sent();
3801
- _state.label = 23;
3802
3817
  case 23:
3818
+ _state.sent();
3819
+ _state.label = 24;
3820
+ case 24:
3803
3821
  return [
3804
3822
  2,
3805
3823
  {
3806
3824
  nextSat: nextSat,
3807
3825
  throttled: throttled,
3808
3826
  isNotificationTask: isNotificationTask,
3827
+ isLoggedEvent: isLoggedEvent,
3809
3828
  deletedNotification: deletedNotification,
3810
3829
  createdBox: createdBox,
3811
3830
  notificationBoxModelKey: model,
@@ -3827,7 +3846,7 @@ var NOTIFICATION_TASK_TYPE_FAILURE_DELAY_MS = dateFns.hoursToMilliseconds(NOTIFI
3827
3846
  })
3828
3847
  ];
3829
3848
  case 1:
3830
- _ref = _state.sent(), nextSat = _ref.nextSat, throttled = _ref.throttled, tryRun = _ref.tryRun, isNotificationTask = _ref.isNotificationTask, notificationTaskHandler = _ref.notificationTaskHandler, notification = _ref.notification, createdBox = _ref.createdBox, notificationBoxNeedsInitialization = _ref.notificationBoxNeedsInitialization, notificationBox = _ref.notificationBox, notificationBoxModelKey = _ref.notificationBoxModelKey, deletedNotification = _ref.deletedNotification, templateInstance = _ref.templateInstance, isConfiguredTemplateType = _ref.isConfiguredTemplateType, isKnownTemplateType = _ref.isKnownTemplateType, onlySendToExplicitlyEnabledRecipients = _ref.onlySendToExplicitlyEnabledRecipients, onlyTextExplicitlyEnabledRecipients = _ref.onlyTextExplicitlyEnabledRecipients;
3849
+ _ref = _state.sent(), nextSat = _ref.nextSat, throttled = _ref.throttled, tryRun = _ref.tryRun, isNotificationTask = _ref.isNotificationTask, isLoggedEvent = _ref.isLoggedEvent, notificationTaskHandler = _ref.notificationTaskHandler, notification = _ref.notification, createdBox = _ref.createdBox, notificationBoxNeedsInitialization = _ref.notificationBoxNeedsInitialization, notificationBox = _ref.notificationBox, notificationBoxModelKey = _ref.notificationBoxModelKey, deletedNotification = _ref.deletedNotification, templateInstance = _ref.templateInstance, isConfiguredTemplateType = _ref.isConfiguredTemplateType, isKnownTemplateType = _ref.isKnownTemplateType, onlySendToExplicitlyEnabledRecipients = _ref.onlySendToExplicitlyEnabledRecipients, onlyTextExplicitlyEnabledRecipients = _ref.onlyTextExplicitlyEnabledRecipients;
3831
3850
  success = false;
3832
3851
  isUniqueNotificationTask = false;
3833
3852
  uniqueNotificationTaskConflict = false;
@@ -3836,33 +3855,48 @@ var NOTIFICATION_TASK_TYPE_FAILURE_DELAY_MS = dateFns.hoursToMilliseconds(NOTIFI
3836
3855
  notificationMarkedDone = false;
3837
3856
  notificationTaskPartsRunCount = 0;
3838
3857
  notificationTemplateType = templateInstance === null || templateInstance === void 0 ? void 0 : templateInstance.type;
3858
+ if (!isLoggedEvent) return [
3859
+ 3,
3860
+ 2
3861
+ ];
3862
+ // Logged events bypass the send pipeline entirely. The document is persisted with d=true
3863
+ // and NO_TRY channel states from creation, so there's nothing to dispatch — just report
3864
+ // success so the result lands in the cleanup pile rather than the failure pile.
3865
+ success = true;
3866
+ notificationMarkedDone = (notification === null || notification === void 0 ? void 0 : notification.d) === true;
3867
+ return [
3868
+ 3,
3869
+ 6
3870
+ ];
3871
+ case 2:
3839
3872
  if (!isNotificationTask) return [
3840
3873
  3,
3841
- 3
3874
+ 4
3842
3875
  ];
3843
3876
  return [
3844
3877
  4,
3845
3878
  handleNotificationTask()
3846
3879
  ];
3847
- case 2:
3880
+ case 3:
3848
3881
  _state.sent();
3849
3882
  return [
3850
3883
  3,
3851
- 5
3884
+ 6
3852
3885
  ];
3853
- case 3:
3886
+ case 4:
3854
3887
  return [
3855
3888
  4,
3856
3889
  handleNormalNotification()
3857
3890
  ];
3858
- case 4:
3859
- _state.sent();
3860
- _state.label = 5;
3861
3891
  case 5:
3892
+ _state.sent();
3893
+ _state.label = 6;
3894
+ case 6:
3862
3895
  result = {
3863
3896
  notificationTemplateType: notificationTemplateType,
3864
3897
  isKnownTemplateType: isKnownTemplateType,
3865
3898
  isNotificationTask: isNotificationTask,
3899
+ isLoggedEvent: isLoggedEvent,
3866
3900
  isUniqueNotificationTask: isUniqueNotificationTask,
3867
3901
  uniqueNotificationTaskConflict: uniqueNotificationTaskConflict,
3868
3902
  isConfiguredTemplateType: isConfiguredTemplateType,
@@ -4085,7 +4119,7 @@ var NOTIFICATION_TASK_TYPE_FAILURE_DELAY_MS = dateFns.hoursToMilliseconds(NOTIFI
4085
4119
  * @param context - the notification server actions context with Firestore and collection access
4086
4120
  * @returns a transform-and-validate function that cleans up sent notification documents and returns aggregate results
4087
4121
  */ function cleanupSentNotificationsFactory(context) {
4088
- var firestoreContext = context.firestoreContext, firebaseServerActionTransformFunctionFactory = context.firebaseServerActionTransformFunctionFactory, notificationCollectionGroup = context.notificationCollectionGroup, notificationBoxCollection = context.notificationBoxCollection, notificationWeekCollectionFactory = context.notificationWeekCollectionFactory;
4122
+ var firestoreContext = context.firestoreContext, firebaseServerActionTransformFunctionFactory = context.firebaseServerActionTransformFunctionFactory, notificationCollectionGroup = context.notificationCollectionGroup, notificationBoxCollection = context.notificationBoxCollection, notificationWeekCollectionFactory = context.notificationWeekCollectionFactory, notificationLoggedEventDayCollectionFactory = context.notificationLoggedEventDayCollectionFactory, notificationLoggedEventDayPagedItemsCollectionFactory = context.notificationLoggedEventDayPagedItemsCollectionFactory;
4089
4123
  return firebaseServerActionTransformFunctionFactory(firebase.cleanupSentNotificationsParamsType, function() {
4090
4124
  return _async_to_generator$d(function() {
4091
4125
  return _ts_generator$d(this, function(_state) {
@@ -4093,7 +4127,7 @@ var NOTIFICATION_TASK_TYPE_FAILURE_DELAY_MS = dateFns.hoursToMilliseconds(NOTIFI
4093
4127
  2,
4094
4128
  function() {
4095
4129
  return _async_to_generator$d(function() {
4096
- var notificationBoxesUpdatesCount, notificationsDeleted, notificationTasksDeletedCount, notificationWeeksCreated, notificationWeeksUpdated, cleanupSentNotificationsResults, notificationBoxesUpdated, result;
4130
+ var notificationBoxesUpdatesCount, notificationsDeleted, notificationTasksDeletedCount, notificationWeeksCreated, notificationWeeksUpdated, notificationLoggedEventsCleanedUp, cleanupSentNotificationsResults, notificationBoxesUpdated, result;
4097
4131
  function cleanupSentNotifications() {
4098
4132
  return _async_to_generator$d(function() {
4099
4133
  var query, notificationDocuments, notificationDocumentsGroupedByNotificationBox;
@@ -4114,7 +4148,7 @@ var NOTIFICATION_TASK_TYPE_FAILURE_DELAY_MS = dateFns.hoursToMilliseconds(NOTIFI
4114
4148
  2,
4115
4149
  util.performAsyncTasks(notificationDocumentsGroupedByNotificationBox, function(notificationDocumentsInSameBox) {
4116
4150
  return _async_to_generator$d(function() {
4117
- var allPairs, allPairsWithDataAndMarkedDeleted, _separateValues, taskPairsWithDataAndMarkedDeleted, normalPairsWithDataAndMarkedDeleted, pairsGroupedByWeek, pairsGroupedByWeekInBatches, notificationBoxDocument, notificationWeekResults, writeBatch, writeBatchAccessor, weeksCreated, weeksUpdated, tasksDeleted;
4151
+ var allPairs, allPairsWithDataAndMarkedDeleted, taskPairsWithDataAndMarkedDeleted, loggedEventPairsWithDataAndMarkedDeleted, normalPairsWithDataAndMarkedDeleted, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, pair, _pair_data, pairsGroupedByWeek, pairsGroupedByWeekInBatches, pairsGroupedByLoggedEventDay, pairsGroupedByLoggedEventDayInBatches, notificationBoxDocument, notificationWeekResults, loggedEventDayResults, writeBatch, writeBatchAccessor, weeksCreated, weeksUpdated, tasksDeleted, loggedEventsCleanedUp;
4118
4152
  return _ts_generator$d(this, function(_state) {
4119
4153
  switch(_state.label){
4120
4154
  case 0:
@@ -4128,10 +4162,41 @@ var NOTIFICATION_TASK_TYPE_FAILURE_DELAY_MS = dateFns.hoursToMilliseconds(NOTIFI
4128
4162
  var _x_data;
4129
4163
  return (_x_data = x.data) === null || _x_data === void 0 ? void 0 : _x_data.d;
4130
4164
  });
4131
- _separateValues = util.separateValues(allPairsWithDataAndMarkedDeleted, function(x) {
4132
- var _x_data;
4133
- return ((_x_data = x.data) === null || _x_data === void 0 ? void 0 : _x_data.st) === firebase.NotificationSendType.TASK_NOTIFICATION;
4134
- }), taskPairsWithDataAndMarkedDeleted = _separateValues.included, normalPairsWithDataAndMarkedDeleted = _separateValues.excluded;
4165
+ // 3-way split: tasks → direct delete; logged events → archive to NotificationLoggedEventDay; rest → archive to NotificationWeek.
4166
+ taskPairsWithDataAndMarkedDeleted = [];
4167
+ loggedEventPairsWithDataAndMarkedDeleted = [];
4168
+ normalPairsWithDataAndMarkedDeleted = [];
4169
+ _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
4170
+ try {
4171
+ for(_iterator = allPairsWithDataAndMarkedDeleted[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
4172
+ pair = _step.value;
4173
+ ;
4174
+ switch((_pair_data = pair.data) === null || _pair_data === void 0 ? void 0 : _pair_data.st){
4175
+ case firebase.NotificationSendType.TASK_NOTIFICATION:
4176
+ taskPairsWithDataAndMarkedDeleted.push(pair);
4177
+ break;
4178
+ case firebase.NotificationSendType.LOGGED_EVENT:
4179
+ loggedEventPairsWithDataAndMarkedDeleted.push(pair);
4180
+ break;
4181
+ default:
4182
+ normalPairsWithDataAndMarkedDeleted.push(pair);
4183
+ break;
4184
+ }
4185
+ }
4186
+ } catch (err) {
4187
+ _didIteratorError = true;
4188
+ _iteratorError = err;
4189
+ } finally{
4190
+ try {
4191
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
4192
+ _iterator.return();
4193
+ }
4194
+ } finally{
4195
+ if (_didIteratorError) {
4196
+ throw _iteratorError;
4197
+ }
4198
+ }
4199
+ }
4135
4200
  pairsGroupedByWeek = _to_consumable_array$5(util.makeValuesGroupMap(normalPairsWithDataAndMarkedDeleted, function(x) {
4136
4201
  return date.yearWeekCode(x.data.sat);
4137
4202
  }).entries());
@@ -4145,6 +4210,20 @@ var NOTIFICATION_TASK_TYPE_FAILURE_DELAY_MS = dateFns.hoursToMilliseconds(NOTIFI
4145
4210
  ];
4146
4211
  });
4147
4212
  });
4213
+ // group logged events by ISO day string (derived from sat) for archival into NotificationLoggedEventDay.
4214
+ pairsGroupedByLoggedEventDay = _to_consumable_array$5(util.makeValuesGroupMap(loggedEventPairsWithDataAndMarkedDeleted, function(x) {
4215
+ return firebase.notificationLoggedEventDayId(x.data.sat);
4216
+ }).entries());
4217
+ // batch incase there are a lot of new logged events to move to a single day
4218
+ pairsGroupedByLoggedEventDayInBatches = pairsGroupedByLoggedEventDay.flatMap(function(x) {
4219
+ var batches = util.batch(x[1], 40);
4220
+ return batches.map(function(batchEntries) {
4221
+ return [
4222
+ x[0],
4223
+ batchEntries
4224
+ ];
4225
+ });
4226
+ });
4148
4227
  notificationBoxDocument = notificationBoxCollection.documentAccessor().loadDocument(notificationDocumentsInSameBox[0].parent);
4149
4228
  return [
4150
4229
  4,
@@ -4232,6 +4311,87 @@ var NOTIFICATION_TASK_TYPE_FAILURE_DELAY_MS = dateFns.hoursToMilliseconds(NOTIFI
4232
4311
  ];
4233
4312
  case 2:
4234
4313
  notificationWeekResults = _state.sent();
4314
+ return [
4315
+ 4,
4316
+ util.performAsyncTasks(pairsGroupedByLoggedEventDayInBatches, function(param) {
4317
+ var _param = _sliced_to_array$2(param, 2), dayId = _param[0], notificationDocumentsInSameDay = _param[1];
4318
+ return _async_to_generator$d(function() {
4319
+ return _ts_generator$d(this, function(_state) {
4320
+ return [
4321
+ 2,
4322
+ firestoreContext.runTransaction(function(transaction) {
4323
+ return _async_to_generator$d(function() {
4324
+ var dayCollection, dayDocument, notificationDocumentsInTransaction, pagedItems, _ref, dayWrapper, existingItems, newItems;
4325
+ return _ts_generator$d(this, function(_state) {
4326
+ switch(_state.label){
4327
+ case 0:
4328
+ dayCollection = notificationLoggedEventDayCollectionFactory(notificationBoxDocument);
4329
+ dayDocument = dayCollection.documentAccessorForTransaction(transaction).loadDocumentForId(dayId);
4330
+ notificationDocumentsInTransaction = firebase.loadDocumentsForDocumentReferencesFromValues(notificationCollectionGroup.documentAccessorForTransaction(transaction), notificationDocumentsInSameDay, function(x) {
4331
+ return x.snapshot.ref;
4332
+ });
4333
+ pagedItems = notificationLoggedEventDayPagedItemsCollectionFactory(dayDocument);
4334
+ return [
4335
+ 4,
4336
+ Promise.all([
4337
+ dayDocument.snapshotData(),
4338
+ pagedItems.loadAllItems()
4339
+ ])
4340
+ ];
4341
+ case 1:
4342
+ _ref = _sliced_to_array$2.apply(void 0, [
4343
+ _state.sent(),
4344
+ 2
4345
+ ]), dayWrapper = _ref[0], existingItems = _ref[1];
4346
+ newItems = notificationDocumentsInSameDay.map(function(x) {
4347
+ return x.data.n;
4348
+ });
4349
+ return [
4350
+ 4,
4351
+ pagedItems.writeAllItemsInTransaction(transaction, _to_consumable_array$5(existingItems).concat(_to_consumable_array$5(newItems)))
4352
+ ];
4353
+ case 2:
4354
+ _state.sent();
4355
+ if (!!dayWrapper) return [
4356
+ 3,
4357
+ 4
4358
+ ];
4359
+ return [
4360
+ 4,
4361
+ dayDocument.create({
4362
+ d: dayId
4363
+ })
4364
+ ];
4365
+ case 3:
4366
+ _state.sent();
4367
+ _state.label = 4;
4368
+ case 4:
4369
+ // delete the source notification docs in the same transaction
4370
+ return [
4371
+ 4,
4372
+ Promise.all(notificationDocumentsInTransaction.map(function(x) {
4373
+ return x.accessor.delete();
4374
+ }))
4375
+ ];
4376
+ case 5:
4377
+ _state.sent();
4378
+ return [
4379
+ 2,
4380
+ {
4381
+ itemsAppended: newItems.length
4382
+ }
4383
+ ];
4384
+ }
4385
+ });
4386
+ })();
4387
+ })
4388
+ ];
4389
+ });
4390
+ })();
4391
+ })
4392
+ ];
4393
+ case 3:
4394
+ loggedEventDayResults = _state.sent();
4235
4395
  // delete all the task notifications
4236
4396
  writeBatch = firestoreContext.batch();
4237
4397
  writeBatchAccessor = notificationCollectionGroup.documentAccessorForTransaction(writeBatch);
@@ -4241,17 +4401,18 @@ var NOTIFICATION_TASK_TYPE_FAILURE_DELAY_MS = dateFns.hoursToMilliseconds(NOTIFI
4241
4401
  return writeBatchAccessor.loadDocumentFrom(x.document).accessor.delete();
4242
4402
  }))
4243
4403
  ];
4244
- case 3:
4404
+ case 4:
4245
4405
  _state.sent();
4246
4406
  return [
4247
4407
  4,
4248
4408
  writeBatch.commit()
4249
4409
  ];
4250
- case 4:
4410
+ case 5:
4251
4411
  _state.sent();
4252
4412
  weeksCreated = 0;
4253
4413
  weeksUpdated = 0;
4254
4414
  tasksDeleted = taskPairsWithDataAndMarkedDeleted.length;
4415
+ loggedEventsCleanedUp = 0;
4255
4416
  notificationWeekResults.results.forEach(function(x) {
4256
4417
  if (x[1].created) {
4257
4418
  weeksCreated += 1;
@@ -4259,13 +4420,17 @@ var NOTIFICATION_TASK_TYPE_FAILURE_DELAY_MS = dateFns.hoursToMilliseconds(NOTIFI
4259
4420
  weeksUpdated += 1;
4260
4421
  }
4261
4422
  });
4423
+ loggedEventDayResults.results.forEach(function(x) {
4424
+ loggedEventsCleanedUp += x[1].itemsAppended;
4425
+ });
4262
4426
  return [
4263
4427
  2,
4264
4428
  {
4265
4429
  weeksCreated: weeksCreated,
4266
4430
  weeksUpdated: weeksUpdated,
4267
4431
  itemsDeleted: allPairsWithDataAndMarkedDeleted.length,
4268
- tasksDeleted: tasksDeleted
4432
+ tasksDeleted: tasksDeleted,
4433
+ loggedEventsCleanedUp: loggedEventsCleanedUp
4269
4434
  }
4270
4435
  ];
4271
4436
  }
@@ -4287,6 +4452,7 @@ var NOTIFICATION_TASK_TYPE_FAILURE_DELAY_MS = dateFns.hoursToMilliseconds(NOTIFI
4287
4452
  notificationTasksDeletedCount = 0;
4288
4453
  notificationWeeksCreated = 0;
4289
4454
  notificationWeeksUpdated = 0;
4455
+ notificationLoggedEventsCleanedUp = 0;
4290
4456
  _state.label = 1;
4291
4457
  case 1:
4292
4458
  return [
@@ -4296,10 +4462,11 @@ var NOTIFICATION_TASK_TYPE_FAILURE_DELAY_MS = dateFns.hoursToMilliseconds(NOTIFI
4296
4462
  case 2:
4297
4463
  cleanupSentNotificationsResults = _state.sent();
4298
4464
  cleanupSentNotificationsResults.results.forEach(function(x) {
4299
- var _x_ = x[1], itemsDeleted = _x_.itemsDeleted, weeksCreated = _x_.weeksCreated, weeksUpdated = _x_.weeksUpdated;
4465
+ var _x_ = x[1], itemsDeleted = _x_.itemsDeleted, weeksCreated = _x_.weeksCreated, weeksUpdated = _x_.weeksUpdated, loggedEventsCleanedUp = _x_.loggedEventsCleanedUp;
4300
4466
  notificationsDeleted += itemsDeleted;
4301
4467
  notificationWeeksCreated += weeksCreated;
4302
4468
  notificationWeeksUpdated += weeksUpdated;
4469
+ notificationLoggedEventsCleanedUp += loggedEventsCleanedUp;
4303
4470
  });
4304
4471
  notificationBoxesUpdated = cleanupSentNotificationsResults.results.length;
4305
4472
  notificationBoxesUpdatesCount += notificationBoxesUpdated;
@@ -4319,7 +4486,126 @@ var NOTIFICATION_TASK_TYPE_FAILURE_DELAY_MS = dateFns.hoursToMilliseconds(NOTIFI
4319
4486
  notificationTasksDeletedCount: notificationTasksDeletedCount,
4320
4487
  notificationsDeleted: notificationsDeleted,
4321
4488
  notificationWeeksCreated: notificationWeeksCreated,
4322
- notificationWeeksUpdated: notificationWeeksUpdated
4489
+ notificationWeeksUpdated: notificationWeeksUpdated,
4490
+ notificationLoggedEventsCleanedUp: notificationLoggedEventsCleanedUp
4491
+ };
4492
+ return [
4493
+ 2,
4494
+ result
4495
+ ];
4496
+ }
4497
+ });
4498
+ })();
4499
+ }
4500
+ ];
4501
+ });
4502
+ })();
4503
+ });
4504
+ }
4505
+ /**
4506
+ * Factory for the `cleanupOldNotificationLoggedEventDays` action.
4507
+ *
4508
+ * Queries the {@link NotificationLoggedEventDayFirestoreCollectionGroup} for day documents whose
4509
+ * ISO day string ID is older than `now - retentionDays`, then deletes each old day's wrapper doc
4510
+ * and all of its nested page documents (the paged `_index` plus every page).
4511
+ *
4512
+ * For each old day, all docs in the day's paged subcollection are deleted before the wrapper doc
4513
+ * itself, so a partial failure leaves the index pointing at zero pages rather than orphaned ones.
4514
+ *
4515
+ * @param context - the notification server actions context with paged-items collection access
4516
+ * @returns a transform-and-validate function that purges old logged-event days and returns aggregate counts
4517
+ */ function cleanupOldNotificationLoggedEventDaysFactory(context) {
4518
+ var firestoreContext = context.firestoreContext, firebaseServerActionTransformFunctionFactory = context.firebaseServerActionTransformFunctionFactory, notificationLoggedEventDayCollectionGroup = context.notificationLoggedEventDayCollectionGroup, notificationLoggedEventDayPagedItemsCollectionFactory = context.notificationLoggedEventDayPagedItemsCollectionFactory;
4519
+ function deleteOldLoggedEventDay(dayDocument) {
4520
+ return _async_to_generator$d(function() {
4521
+ var pagesCollection, allPageDocs;
4522
+ return _ts_generator$d(this, function(_state) {
4523
+ switch(_state.label){
4524
+ case 0:
4525
+ pagesCollection = notificationLoggedEventDayPagedItemsCollectionFactory(dayDocument);
4526
+ return [
4527
+ 4,
4528
+ pagesCollection.queryDocument().getDocs()
4529
+ ];
4530
+ case 1:
4531
+ allPageDocs = _state.sent();
4532
+ return [
4533
+ 2,
4534
+ firestoreContext.runTransaction(function(transaction) {
4535
+ return _async_to_generator$d(function() {
4536
+ var pageTxAccessor, dayTxAccessor;
4537
+ return _ts_generator$d(this, function(_state) {
4538
+ switch(_state.label){
4539
+ case 0:
4540
+ pageTxAccessor = pagesCollection.documentAccessorForTransaction(transaction);
4541
+ dayTxAccessor = notificationLoggedEventDayCollectionGroup.documentAccessorForTransaction(transaction);
4542
+ // Delete every page (numbered pages first; the `_index` is included in the same batch).
4543
+ return [
4544
+ 4,
4545
+ Promise.all(allPageDocs.map(function(pageDoc) {
4546
+ return pageTxAccessor.loadDocumentFrom(pageDoc).accessor.delete();
4547
+ }))
4548
+ ];
4549
+ case 1:
4550
+ _state.sent();
4551
+ // Delete the day wrapper itself last.
4552
+ return [
4553
+ 4,
4554
+ dayTxAccessor.loadDocumentFrom(dayDocument).accessor.delete()
4555
+ ];
4556
+ case 2:
4557
+ _state.sent();
4558
+ return [
4559
+ 2,
4560
+ {
4561
+ pageDocsDeleted: allPageDocs.length
4562
+ }
4563
+ ];
4564
+ }
4565
+ });
4566
+ })();
4567
+ })
4568
+ ];
4569
+ }
4570
+ });
4571
+ })();
4572
+ }
4573
+ return firebaseServerActionTransformFunctionFactory(firebase.cleanupOldNotificationLoggedEventDaysParamsType, function(params) {
4574
+ return _async_to_generator$d(function() {
4575
+ return _ts_generator$d(this, function(_state) {
4576
+ return [
4577
+ 2,
4578
+ function() {
4579
+ return _async_to_generator$d(function() {
4580
+ var now, oldDaysQuery, oldDayDocuments, daysDeleted, pagesDeleted, deleteResults, result;
4581
+ return _ts_generator$d(this, function(_state) {
4582
+ switch(_state.label){
4583
+ case 0:
4584
+ now = new Date();
4585
+ oldDaysQuery = notificationLoggedEventDayCollectionGroup.queryDocument(firebase.notificationLoggedEventDaysOlderThanQuery(params.retentionDays, now));
4586
+ return [
4587
+ 4,
4588
+ oldDaysQuery.getDocs()
4589
+ ];
4590
+ case 1:
4591
+ oldDayDocuments = _state.sent();
4592
+ daysDeleted = 0;
4593
+ pagesDeleted = 0;
4594
+ return [
4595
+ 4,
4596
+ util.performAsyncTasks(oldDayDocuments, deleteOldLoggedEventDay, {
4597
+ maxParallelTasks: 10
4598
+ })
4599
+ ];
4600
+ case 2:
4601
+ deleteResults = _state.sent();
4602
+ deleteResults.results.forEach(function(entry) {
4603
+ daysDeleted += 1;
4604
+ pagesDeleted += entry[1].pageDocsDeleted;
4605
+ });
4606
+ result = {
4607
+ daysDeleted: daysDeleted,
4608
+ pagesDeleted: pagesDeleted
4323
4609
  };
4324
4610
  return [
4325
4611
  2,
@@ -12602,6 +12888,7 @@ exports._syncStorageFileWithGroupsInTransactionFactory = _syncStorageFileWithGro
12602
12888
  exports.allStorageFileGroupStorageFileProcessingPurposeSubtaskProcessors = allStorageFileGroupStorageFileProcessingPurposeSubtaskProcessors;
12603
12889
  exports.appNotificationModuleMetadata = appNotificationModuleMetadata;
12604
12890
  exports.appStorageFileModuleMetadata = appStorageFileModuleMetadata;
12891
+ exports.cleanupOldNotificationLoggedEventDaysFactory = cleanupOldNotificationLoggedEventDaysFactory;
12605
12892
  exports.cleanupSentNotificationsFactory = cleanupSentNotificationsFactory;
12606
12893
  exports.createNotificationBoxFactory = createNotificationBoxFactory;
12607
12894
  exports.createNotificationBoxInTransactionFactory = createNotificationBoxInTransactionFactory;