@blackcode_sa/metaestetics-api 1.14.59 → 1.14.60

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.
@@ -4723,6 +4723,12 @@ declare class NotificationsAdmin {
4723
4723
  * Kreira novu notifikaciju
4724
4724
  */
4725
4725
  createNotification(notification: Omit<Notification, "id">): Promise<string>;
4726
+ /**
4727
+ * Creates a notification and immediately attempts to send it.
4728
+ * If immediate send fails, the notification remains PENDING for cron pickup.
4729
+ * Returns the notification ID regardless of send success.
4730
+ */
4731
+ createAndSendNotificationImmediately(notification: Omit<Notification, "id">): Promise<string>;
4726
4732
  /**
4727
4733
  * Priprema Expo poruku za slanje
4728
4734
  */
@@ -4723,6 +4723,12 @@ declare class NotificationsAdmin {
4723
4723
  * Kreira novu notifikaciju
4724
4724
  */
4725
4725
  createNotification(notification: Omit<Notification, "id">): Promise<string>;
4726
+ /**
4727
+ * Creates a notification and immediately attempts to send it.
4728
+ * If immediate send fails, the notification remains PENDING for cron pickup.
4729
+ * Returns the notification ID regardless of send success.
4730
+ */
4731
+ createAndSendNotificationImmediately(notification: Omit<Notification, "id">): Promise<string>;
4726
4732
  /**
4727
4733
  * Priprema Expo poruku za slanje
4728
4734
  */
@@ -717,6 +717,37 @@ var NotificationsAdmin = class {
717
717
  });
718
718
  return docRef.id;
719
719
  }
720
+ /**
721
+ * Creates a notification and immediately attempts to send it.
722
+ * If immediate send fails, the notification remains PENDING for cron pickup.
723
+ * Returns the notification ID regardless of send success.
724
+ */
725
+ async createAndSendNotificationImmediately(notification) {
726
+ const notificationId = await this.createNotification(notification);
727
+ try {
728
+ const fullNotification = {
729
+ ...notification,
730
+ id: notificationId,
731
+ status: "pending" /* PENDING */
732
+ };
733
+ const sent = await this.sendPushNotification(fullNotification);
734
+ if (sent) {
735
+ Logger.info(
736
+ `[NotificationsAdmin] Notification ${notificationId} sent immediately`
737
+ );
738
+ } else {
739
+ Logger.info(
740
+ `[NotificationsAdmin] Notification ${notificationId} immediate send failed, will be retried by cron`
741
+ );
742
+ }
743
+ } catch (error) {
744
+ Logger.error(
745
+ `[NotificationsAdmin] Error sending notification ${notificationId} immediately, will be retried by cron:`,
746
+ error
747
+ );
748
+ }
749
+ return notificationId;
750
+ }
720
751
  /**
721
752
  * Priprema Expo poruku za slanje
722
753
  */
@@ -983,7 +1014,7 @@ var NotificationsAdmin = class {
983
1014
  appointmentId: appointment.id
984
1015
  };
985
1016
  try {
986
- const notificationId = await this.createNotification(
1017
+ const notificationId = await this.createAndSendNotificationImmediately(
987
1018
  notificationData
988
1019
  );
989
1020
  console.log(
@@ -1034,7 +1065,7 @@ var NotificationsAdmin = class {
1034
1065
  appointmentId: appointment.id
1035
1066
  };
1036
1067
  try {
1037
- const notificationId = await this.createNotification(
1068
+ const notificationId = await this.createAndSendNotificationImmediately(
1038
1069
  notificationData
1039
1070
  );
1040
1071
  console.log(
@@ -1070,7 +1101,7 @@ var NotificationsAdmin = class {
1070
1101
  appointmentId: appointment.id
1071
1102
  };
1072
1103
  try {
1073
- const notificationId = await this.createNotification(
1104
+ const notificationId = await this.createAndSendNotificationImmediately(
1074
1105
  notificationData
1075
1106
  );
1076
1107
  console.log(
@@ -1107,7 +1138,7 @@ var NotificationsAdmin = class {
1107
1138
  appointmentId: appointment.id
1108
1139
  };
1109
1140
  try {
1110
- const notificationId = await this.createNotification(
1141
+ const notificationId = await this.createAndSendNotificationImmediately(
1111
1142
  notificationData
1112
1143
  );
1113
1144
  console.log(
@@ -1143,7 +1174,7 @@ var NotificationsAdmin = class {
1143
1174
  appointmentId: appointment.id
1144
1175
  };
1145
1176
  try {
1146
- const notificationId = await this.createNotification(
1177
+ const notificationId = await this.createAndSendNotificationImmediately(
1147
1178
  notificationData
1148
1179
  );
1149
1180
  console.log(
@@ -1186,7 +1217,7 @@ var NotificationsAdmin = class {
1186
1217
  appointmentId: appointment.id
1187
1218
  };
1188
1219
  try {
1189
- const notificationId = await this.createNotification(
1220
+ const notificationId = await this.createAndSendNotificationImmediately(
1190
1221
  notificationData
1191
1222
  );
1192
1223
  console.log(
@@ -1230,7 +1261,7 @@ var NotificationsAdmin = class {
1230
1261
  appointmentId: appointment.id
1231
1262
  };
1232
1263
  try {
1233
- const notificationId = await this.createNotification(
1264
+ const notificationId = await this.createAndSendNotificationImmediately(
1234
1265
  notificationData
1235
1266
  );
1236
1267
  console.log(
@@ -3735,12 +3766,11 @@ var AppointmentAggregationService = class {
3735
3766
  const patientCancellationData = {
3736
3767
  appointment: after,
3737
3768
  recipientProfile: after.patientInfo,
3738
- recipientRole: "patient"
3739
- // cancellationReason: after.cancellationReason, // TODO: Add if cancellationReason is available on 'after' Appointment
3769
+ recipientRole: "patient",
3770
+ cancellationReason: after.cancellationReason
3740
3771
  };
3741
3772
  await this.appointmentMailingService.sendAppointmentCancelledEmail(
3742
3773
  patientCancellationData
3743
- // TODO: Properly import types
3744
3774
  );
3745
3775
  }
3746
3776
  if ((_c = practitionerProfile == null ? void 0 : practitionerProfile.basicInfo) == null ? void 0 : _c.email) {
@@ -3750,12 +3780,22 @@ var AppointmentAggregationService = class {
3750
3780
  const practitionerCancellationData = {
3751
3781
  appointment: after,
3752
3782
  recipientProfile: after.practitionerInfo,
3753
- recipientRole: "practitioner"
3754
- // cancellationReason: after.cancellationReason, // TODO: Add if cancellationReason is available on 'after' Appointment
3783
+ recipientRole: "practitioner",
3784
+ cancellationReason: after.cancellationReason
3755
3785
  };
3756
3786
  await this.appointmentMailingService.sendAppointmentCancelledEmail(
3757
3787
  practitionerCancellationData
3758
- // TODO: Properly import types
3788
+ );
3789
+ }
3790
+ if ((patientProfile == null ? void 0 : patientProfile.expoTokens) && patientProfile.expoTokens.length > 0) {
3791
+ Logger.info(
3792
+ `[AggService] Sending cancellation push notification to patient ${after.patientId}`
3793
+ );
3794
+ await this.notificationsAdmin.sendAppointmentCancelledPush(
3795
+ after,
3796
+ after.patientId,
3797
+ patientProfile.expoTokens,
3798
+ "patient" /* PATIENT */
3759
3799
  );
3760
3800
  }
3761
3801
  } else if (after.status === "completed" /* COMPLETED */) {
@@ -641,6 +641,37 @@ var NotificationsAdmin = class {
641
641
  });
642
642
  return docRef.id;
643
643
  }
644
+ /**
645
+ * Creates a notification and immediately attempts to send it.
646
+ * If immediate send fails, the notification remains PENDING for cron pickup.
647
+ * Returns the notification ID regardless of send success.
648
+ */
649
+ async createAndSendNotificationImmediately(notification) {
650
+ const notificationId = await this.createNotification(notification);
651
+ try {
652
+ const fullNotification = {
653
+ ...notification,
654
+ id: notificationId,
655
+ status: "pending" /* PENDING */
656
+ };
657
+ const sent = await this.sendPushNotification(fullNotification);
658
+ if (sent) {
659
+ Logger.info(
660
+ `[NotificationsAdmin] Notification ${notificationId} sent immediately`
661
+ );
662
+ } else {
663
+ Logger.info(
664
+ `[NotificationsAdmin] Notification ${notificationId} immediate send failed, will be retried by cron`
665
+ );
666
+ }
667
+ } catch (error) {
668
+ Logger.error(
669
+ `[NotificationsAdmin] Error sending notification ${notificationId} immediately, will be retried by cron:`,
670
+ error
671
+ );
672
+ }
673
+ return notificationId;
674
+ }
644
675
  /**
645
676
  * Priprema Expo poruku za slanje
646
677
  */
@@ -907,7 +938,7 @@ var NotificationsAdmin = class {
907
938
  appointmentId: appointment.id
908
939
  };
909
940
  try {
910
- const notificationId = await this.createNotification(
941
+ const notificationId = await this.createAndSendNotificationImmediately(
911
942
  notificationData
912
943
  );
913
944
  console.log(
@@ -958,7 +989,7 @@ var NotificationsAdmin = class {
958
989
  appointmentId: appointment.id
959
990
  };
960
991
  try {
961
- const notificationId = await this.createNotification(
992
+ const notificationId = await this.createAndSendNotificationImmediately(
962
993
  notificationData
963
994
  );
964
995
  console.log(
@@ -994,7 +1025,7 @@ var NotificationsAdmin = class {
994
1025
  appointmentId: appointment.id
995
1026
  };
996
1027
  try {
997
- const notificationId = await this.createNotification(
1028
+ const notificationId = await this.createAndSendNotificationImmediately(
998
1029
  notificationData
999
1030
  );
1000
1031
  console.log(
@@ -1031,7 +1062,7 @@ var NotificationsAdmin = class {
1031
1062
  appointmentId: appointment.id
1032
1063
  };
1033
1064
  try {
1034
- const notificationId = await this.createNotification(
1065
+ const notificationId = await this.createAndSendNotificationImmediately(
1035
1066
  notificationData
1036
1067
  );
1037
1068
  console.log(
@@ -1067,7 +1098,7 @@ var NotificationsAdmin = class {
1067
1098
  appointmentId: appointment.id
1068
1099
  };
1069
1100
  try {
1070
- const notificationId = await this.createNotification(
1101
+ const notificationId = await this.createAndSendNotificationImmediately(
1071
1102
  notificationData
1072
1103
  );
1073
1104
  console.log(
@@ -1110,7 +1141,7 @@ var NotificationsAdmin = class {
1110
1141
  appointmentId: appointment.id
1111
1142
  };
1112
1143
  try {
1113
- const notificationId = await this.createNotification(
1144
+ const notificationId = await this.createAndSendNotificationImmediately(
1114
1145
  notificationData
1115
1146
  );
1116
1147
  console.log(
@@ -1154,7 +1185,7 @@ var NotificationsAdmin = class {
1154
1185
  appointmentId: appointment.id
1155
1186
  };
1156
1187
  try {
1157
- const notificationId = await this.createNotification(
1188
+ const notificationId = await this.createAndSendNotificationImmediately(
1158
1189
  notificationData
1159
1190
  );
1160
1191
  console.log(
@@ -3659,12 +3690,11 @@ var AppointmentAggregationService = class {
3659
3690
  const patientCancellationData = {
3660
3691
  appointment: after,
3661
3692
  recipientProfile: after.patientInfo,
3662
- recipientRole: "patient"
3663
- // cancellationReason: after.cancellationReason, // TODO: Add if cancellationReason is available on 'after' Appointment
3693
+ recipientRole: "patient",
3694
+ cancellationReason: after.cancellationReason
3664
3695
  };
3665
3696
  await this.appointmentMailingService.sendAppointmentCancelledEmail(
3666
3697
  patientCancellationData
3667
- // TODO: Properly import types
3668
3698
  );
3669
3699
  }
3670
3700
  if ((_c = practitionerProfile == null ? void 0 : practitionerProfile.basicInfo) == null ? void 0 : _c.email) {
@@ -3674,12 +3704,22 @@ var AppointmentAggregationService = class {
3674
3704
  const practitionerCancellationData = {
3675
3705
  appointment: after,
3676
3706
  recipientProfile: after.practitionerInfo,
3677
- recipientRole: "practitioner"
3678
- // cancellationReason: after.cancellationReason, // TODO: Add if cancellationReason is available on 'after' Appointment
3707
+ recipientRole: "practitioner",
3708
+ cancellationReason: after.cancellationReason
3679
3709
  };
3680
3710
  await this.appointmentMailingService.sendAppointmentCancelledEmail(
3681
3711
  practitionerCancellationData
3682
- // TODO: Properly import types
3712
+ );
3713
+ }
3714
+ if ((patientProfile == null ? void 0 : patientProfile.expoTokens) && patientProfile.expoTokens.length > 0) {
3715
+ Logger.info(
3716
+ `[AggService] Sending cancellation push notification to patient ${after.patientId}`
3717
+ );
3718
+ await this.notificationsAdmin.sendAppointmentCancelledPush(
3719
+ after,
3720
+ after.patientId,
3721
+ patientProfile.expoTokens,
3722
+ "patient" /* PATIENT */
3683
3723
  );
3684
3724
  }
3685
3725
  } else if (after.status === "completed" /* COMPLETED */) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@blackcode_sa/metaestetics-api",
3
3
  "private": false,
4
- "version": "1.14.59",
4
+ "version": "1.14.60",
5
5
  "description": "Firebase authentication service with anonymous upgrade support",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.mjs",
@@ -408,10 +408,10 @@ export class AppointmentAggregationService {
408
408
  appointment: after,
409
409
  recipientProfile: after.patientInfo,
410
410
  recipientRole: 'patient' as const,
411
- // cancellationReason: after.cancellationReason, // TODO: Add if cancellationReason is available on 'after' Appointment
411
+ cancellationReason: after.cancellationReason,
412
412
  };
413
413
  await this.appointmentMailingService.sendAppointmentCancelledEmail(
414
- patientCancellationData as any, // TODO: Properly import types
414
+ patientCancellationData as any,
415
415
  );
416
416
  }
417
417
 
@@ -424,15 +424,25 @@ export class AppointmentAggregationService {
424
424
  appointment: after,
425
425
  recipientProfile: after.practitionerInfo,
426
426
  recipientRole: 'practitioner' as const,
427
- // cancellationReason: after.cancellationReason, // TODO: Add if cancellationReason is available on 'after' Appointment
427
+ cancellationReason: after.cancellationReason,
428
428
  };
429
429
  await this.appointmentMailingService.sendAppointmentCancelledEmail(
430
- practitionerCancellationData as any, // TODO: Properly import types
430
+ practitionerCancellationData as any,
431
431
  );
432
432
  }
433
433
 
434
- // TODO: Send cancellation push notifications (patient, practitioner) via notificationsAdmin
435
- // TODO: Update/cancel calendar event via calendarAdminService.updateAppointmentCalendarEventStatus(after, CalendarEventStatus.CANCELED)
434
+ // Send cancellation push notification to Patient
435
+ if (patientProfile?.expoTokens && patientProfile.expoTokens.length > 0) {
436
+ Logger.info(
437
+ `[AggService] Sending cancellation push notification to patient ${after.patientId}`,
438
+ );
439
+ await this.notificationsAdmin.sendAppointmentCancelledPush(
440
+ after,
441
+ after.patientId,
442
+ patientProfile.expoTokens,
443
+ UserRole.PATIENT,
444
+ );
445
+ }
436
446
  }
437
447
  // --- Any -> COMPLETED ---
438
448
  else if (after.status === AppointmentStatus.COMPLETED) {
@@ -43,6 +43,47 @@ export class NotificationsAdmin {
43
43
  return docRef.id;
44
44
  }
45
45
 
46
+ /**
47
+ * Creates a notification and immediately attempts to send it.
48
+ * If immediate send fails, the notification remains PENDING for cron pickup.
49
+ * Returns the notification ID regardless of send success.
50
+ */
51
+ async createAndSendNotificationImmediately(
52
+ notification: Omit<Notification, "id">
53
+ ): Promise<string> {
54
+ // Create the notification first
55
+ const notificationId = await this.createNotification(notification);
56
+
57
+ // Immediately try to send it
58
+ try {
59
+ const fullNotification: Notification = {
60
+ ...notification,
61
+ id: notificationId,
62
+ status: NotificationStatus.PENDING,
63
+ } as Notification;
64
+
65
+ const sent = await this.sendPushNotification(fullNotification);
66
+
67
+ if (sent) {
68
+ Logger.info(
69
+ `[NotificationsAdmin] Notification ${notificationId} sent immediately`
70
+ );
71
+ } else {
72
+ Logger.info(
73
+ `[NotificationsAdmin] Notification ${notificationId} immediate send failed, will be retried by cron`
74
+ );
75
+ }
76
+ } catch (error) {
77
+ // Don't throw - notification is created, cron will pick it up
78
+ Logger.error(
79
+ `[NotificationsAdmin] Error sending notification ${notificationId} immediately, will be retried by cron:`,
80
+ error
81
+ );
82
+ }
83
+
84
+ return notificationId;
85
+ }
86
+
46
87
  /**
47
88
  * Priprema Expo poruku za slanje
48
89
  */
@@ -406,7 +447,7 @@ export class NotificationsAdmin {
406
447
  };
407
448
 
408
449
  try {
409
- const notificationId = await this.createNotification(
450
+ const notificationId = await this.createAndSendNotificationImmediately(
410
451
  notificationData as Notification
411
452
  );
412
453
  console.log(
@@ -479,7 +520,7 @@ export class NotificationsAdmin {
479
520
  };
480
521
 
481
522
  try {
482
- const notificationId = await this.createNotification(
523
+ const notificationId = await this.createAndSendNotificationImmediately(
483
524
  notificationData as Notification
484
525
  );
485
526
  console.log(
@@ -527,7 +568,7 @@ export class NotificationsAdmin {
527
568
  };
528
569
 
529
570
  try {
530
- const notificationId = await this.createNotification(
571
+ const notificationId = await this.createAndSendNotificationImmediately(
531
572
  notificationData as Notification
532
573
  );
533
574
  console.log(
@@ -583,7 +624,7 @@ export class NotificationsAdmin {
583
624
  };
584
625
 
585
626
  try {
586
- const notificationId = await this.createNotification(
627
+ const notificationId = await this.createAndSendNotificationImmediately(
587
628
  notificationData as Notification
588
629
  );
589
630
  console.log(
@@ -631,7 +672,7 @@ export class NotificationsAdmin {
631
672
  };
632
673
 
633
674
  try {
634
- const notificationId = await this.createNotification(
675
+ const notificationId = await this.createAndSendNotificationImmediately(
635
676
  notificationData as Notification
636
677
  );
637
678
  console.log(
@@ -692,7 +733,7 @@ export class NotificationsAdmin {
692
733
  };
693
734
 
694
735
  try {
695
- const notificationId = await this.createNotification(
736
+ const notificationId = await this.createAndSendNotificationImmediately(
696
737
  notificationData as Notification
697
738
  );
698
739
  console.log(
@@ -749,7 +790,7 @@ export class NotificationsAdmin {
749
790
  };
750
791
 
751
792
  try {
752
- const notificationId = await this.createNotification(
793
+ const notificationId = await this.createAndSendNotificationImmediately(
753
794
  notificationData as Notification
754
795
  );
755
796
  console.log(