@blackcode_sa/metaestetics-api 1.5.29 → 1.5.31

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 (30) hide show
  1. package/dist/admin/index.d.mts +126 -1
  2. package/dist/admin/index.d.ts +126 -1
  3. package/dist/admin/index.js +347 -10
  4. package/dist/admin/index.mjs +345 -10
  5. package/dist/index.d.mts +64 -71
  6. package/dist/index.d.ts +64 -71
  7. package/dist/index.js +327 -710
  8. package/dist/index.mjs +363 -750
  9. package/package.json +2 -1
  10. package/src/admin/aggregation/README.md +79 -0
  11. package/src/admin/aggregation/clinic/README.md +52 -0
  12. package/src/admin/aggregation/patient/README.md +27 -0
  13. package/src/admin/aggregation/practitioner/README.md +42 -0
  14. package/src/admin/aggregation/procedure/README.md +43 -0
  15. package/src/admin/index.ts +17 -2
  16. package/src/admin/mailing/README.md +95 -0
  17. package/src/admin/mailing/base.mailing.service.ts +131 -0
  18. package/src/admin/mailing/index.ts +2 -0
  19. package/src/admin/mailing/practitionerInvite/index.ts +1 -0
  20. package/src/admin/mailing/practitionerInvite/practitionerInvite.mailing.ts +256 -0
  21. package/src/admin/mailing/practitionerInvite/templates/invitation.template.ts +101 -0
  22. package/src/services/README.md +106 -0
  23. package/src/services/calendar/utils/appointment.utils.ts +42 -91
  24. package/src/services/clinic/README.md +87 -0
  25. package/src/services/clinic/clinic.service.ts +3 -126
  26. package/src/services/clinic/utils/clinic.utils.ts +2 -2
  27. package/src/services/practitioner/README.md +145 -0
  28. package/src/services/practitioner/practitioner.service.ts +119 -395
  29. package/src/services/procedure/README.md +88 -0
  30. package/src/services/procedure/procedure.service.ts +332 -369
@@ -1,5 +1,6 @@
1
1
  import { Timestamp } from 'firebase/firestore';
2
2
  import * as admin from 'firebase-admin';
3
+ import * as mailgun from 'mailgun-js';
3
4
 
4
5
  /**
5
6
  * Enum for element types in documentation templates
@@ -689,6 +690,15 @@ declare enum PractitionerStatus {
689
690
  DRAFT = "draft",
690
691
  ACTIVE = "active"
691
692
  }
693
+ /**
694
+ * Token status for practitioner invitations
695
+ */
696
+ declare enum PractitionerTokenStatus {
697
+ ACTIVE = "active",
698
+ USED = "used",
699
+ EXPIRED = "expired",
700
+ REVOKED = "revoked"
701
+ }
692
702
  /**
693
703
  * Interfejs za zdravstvenog radnika
694
704
  */
@@ -709,6 +719,22 @@ interface Practitioner {
709
719
  createdAt: Timestamp;
710
720
  updatedAt: Timestamp;
711
721
  }
722
+ /**
723
+ * Token za pozivanje zdravstvenog radnika
724
+ */
725
+ interface PractitionerToken {
726
+ id: string;
727
+ token: string;
728
+ practitionerId: string;
729
+ email: string;
730
+ clinicId: string;
731
+ status: PractitionerTokenStatus;
732
+ createdBy: string;
733
+ createdAt: Timestamp;
734
+ expiresAt: Timestamp;
735
+ usedBy?: string;
736
+ usedAt?: Timestamp;
737
+ }
712
738
 
713
739
  /**
714
740
  * Interfejs za gamifikaciju
@@ -1350,4 +1376,103 @@ declare class PatientAggregationService {
1350
1376
  cancelUpcomingCalendarEventsForPatient(patientId: string): Promise<void>;
1351
1377
  }
1352
1378
 
1353
- export { type AppointmentNotification, type AppointmentReminderNotification, type BaseNotification, type Clinic, ClinicAggregationService, type ClinicInfo, type ClinicLocation, type DoctorInfo, NOTIFICATIONS_COLLECTION, type Notification, NotificationStatus, NotificationType, NotificationsAdmin, type PatientProfile as Patient, PatientAggregationService, type PostRequirementNotification, type Practitioner, PractitionerAggregationService, type PreRequirementNotification, type Procedure, ProcedureAggregationService, type ProcedureSummaryInfo, UserRole };
1379
+ /**
1380
+ * Base mailing service class that provides common functionality for all mailing services
1381
+ */
1382
+ declare class BaseMailingService {
1383
+ protected db: FirebaseFirestore.Firestore;
1384
+ protected mailgunClient: mailgun.Mailgun;
1385
+ /**
1386
+ * Constructor for BaseMailingService
1387
+ * @param firestore Firestore instance provided by the caller
1388
+ * @param mailgunClient Mailgun client instance provided by the caller
1389
+ */
1390
+ constructor(firestore: FirebaseFirestore.Firestore, mailgunClient: mailgun.Mailgun);
1391
+ /**
1392
+ * Sends an email using Mailgun
1393
+ * @param data Email data to send, including the 'from' address
1394
+ * @returns Promise with the sending result
1395
+ */
1396
+ protected sendEmail(data: mailgun.messages.SendData): Promise<mailgun.messages.SendResponse>;
1397
+ /**
1398
+ * Logs email sending attempt to Firestore for tracking
1399
+ * @param emailData Email data that was sent
1400
+ * @param success Whether the email was sent successfully
1401
+ * @param error Error object if the email failed to send
1402
+ */
1403
+ protected logEmailAttempt(emailData: {
1404
+ to: string;
1405
+ subject: string;
1406
+ templateName?: string;
1407
+ }, success: boolean, error?: any): Promise<void>;
1408
+ /**
1409
+ * Renders a simple HTML email template with variables
1410
+ * @param template HTML template string
1411
+ * @param variables Key-value pairs to replace in the template
1412
+ * @returns Rendered HTML string
1413
+ */
1414
+ protected renderTemplate(template: string, variables: Record<string, string>): string;
1415
+ }
1416
+
1417
+ /**
1418
+ * Interface for the data required to send a practitioner invitation email
1419
+ */
1420
+ interface PractitionerInviteEmailData {
1421
+ /** The token object from the practitioner service */
1422
+ token: {
1423
+ id: string;
1424
+ token: string;
1425
+ practitionerId: string;
1426
+ email: string;
1427
+ clinicId: string;
1428
+ expiresAt: admin.firestore.Timestamp;
1429
+ };
1430
+ /** Practitioner basic info */
1431
+ practitioner: {
1432
+ firstName: string;
1433
+ lastName: string;
1434
+ };
1435
+ /** Clinic info */
1436
+ clinic: {
1437
+ name: string;
1438
+ contactEmail: string;
1439
+ contactName?: string;
1440
+ };
1441
+ /** Config options */
1442
+ options?: {
1443
+ registrationUrl?: string;
1444
+ customSubject?: string;
1445
+ fromAddress?: string;
1446
+ };
1447
+ }
1448
+ /**
1449
+ * Service for sending practitioner invitation emails
1450
+ */
1451
+ declare class PractitionerInviteMailingService extends BaseMailingService {
1452
+ private readonly DEFAULT_REGISTRATION_URL;
1453
+ private readonly DEFAULT_SUBJECT;
1454
+ private readonly DEFAULT_FROM_ADDRESS;
1455
+ /**
1456
+ * Constructor for PractitionerInviteMailingService
1457
+ * @param firestore Firestore instance provided by the caller
1458
+ * @param mailgunClient Mailgun client instance provided by the caller
1459
+ */
1460
+ constructor(firestore: FirebaseFirestore.Firestore, mailgunClient: mailgun.Mailgun);
1461
+ /**
1462
+ * Sends a practitioner invitation email
1463
+ * @param data The practitioner invitation data
1464
+ * @returns Promise resolved when email is sent
1465
+ */
1466
+ sendInvitationEmail(data: PractitionerInviteEmailData): Promise<mailgun.messages.SendResponse>;
1467
+ /**
1468
+ * Handles the practitioner token creation event from Cloud Functions
1469
+ * Fetches necessary data using defined types and collection constants,
1470
+ * and sends the invitation email.
1471
+ * @param tokenData The fully typed token object including its id
1472
+ * @param fromAddress The 'from' email address to use, obtained from config
1473
+ * @returns Promise resolved when the email is sent
1474
+ */
1475
+ handleTokenCreationEvent(tokenData: PractitionerToken, fromAddress: string): Promise<void>;
1476
+ }
1477
+
1478
+ export { type AppointmentNotification, type AppointmentReminderNotification, BaseMailingService, type BaseNotification, type Clinic, ClinicAggregationService, type ClinicInfo, type ClinicLocation, type DoctorInfo, NOTIFICATIONS_COLLECTION, type Notification, NotificationStatus, NotificationType, NotificationsAdmin, type PatientProfile as Patient, PatientAggregationService, type PostRequirementNotification, type Practitioner, PractitionerAggregationService, PractitionerInviteMailingService, type PractitionerToken, PractitionerTokenStatus, type PreRequirementNotification, type Procedure, ProcedureAggregationService, type ProcedureSummaryInfo, UserRole };
@@ -1,5 +1,6 @@
1
1
  import { Timestamp } from 'firebase/firestore';
2
2
  import * as admin from 'firebase-admin';
3
+ import * as mailgun from 'mailgun-js';
3
4
 
4
5
  /**
5
6
  * Enum for element types in documentation templates
@@ -689,6 +690,15 @@ declare enum PractitionerStatus {
689
690
  DRAFT = "draft",
690
691
  ACTIVE = "active"
691
692
  }
693
+ /**
694
+ * Token status for practitioner invitations
695
+ */
696
+ declare enum PractitionerTokenStatus {
697
+ ACTIVE = "active",
698
+ USED = "used",
699
+ EXPIRED = "expired",
700
+ REVOKED = "revoked"
701
+ }
692
702
  /**
693
703
  * Interfejs za zdravstvenog radnika
694
704
  */
@@ -709,6 +719,22 @@ interface Practitioner {
709
719
  createdAt: Timestamp;
710
720
  updatedAt: Timestamp;
711
721
  }
722
+ /**
723
+ * Token za pozivanje zdravstvenog radnika
724
+ */
725
+ interface PractitionerToken {
726
+ id: string;
727
+ token: string;
728
+ practitionerId: string;
729
+ email: string;
730
+ clinicId: string;
731
+ status: PractitionerTokenStatus;
732
+ createdBy: string;
733
+ createdAt: Timestamp;
734
+ expiresAt: Timestamp;
735
+ usedBy?: string;
736
+ usedAt?: Timestamp;
737
+ }
712
738
 
713
739
  /**
714
740
  * Interfejs za gamifikaciju
@@ -1350,4 +1376,103 @@ declare class PatientAggregationService {
1350
1376
  cancelUpcomingCalendarEventsForPatient(patientId: string): Promise<void>;
1351
1377
  }
1352
1378
 
1353
- export { type AppointmentNotification, type AppointmentReminderNotification, type BaseNotification, type Clinic, ClinicAggregationService, type ClinicInfo, type ClinicLocation, type DoctorInfo, NOTIFICATIONS_COLLECTION, type Notification, NotificationStatus, NotificationType, NotificationsAdmin, type PatientProfile as Patient, PatientAggregationService, type PostRequirementNotification, type Practitioner, PractitionerAggregationService, type PreRequirementNotification, type Procedure, ProcedureAggregationService, type ProcedureSummaryInfo, UserRole };
1379
+ /**
1380
+ * Base mailing service class that provides common functionality for all mailing services
1381
+ */
1382
+ declare class BaseMailingService {
1383
+ protected db: FirebaseFirestore.Firestore;
1384
+ protected mailgunClient: mailgun.Mailgun;
1385
+ /**
1386
+ * Constructor for BaseMailingService
1387
+ * @param firestore Firestore instance provided by the caller
1388
+ * @param mailgunClient Mailgun client instance provided by the caller
1389
+ */
1390
+ constructor(firestore: FirebaseFirestore.Firestore, mailgunClient: mailgun.Mailgun);
1391
+ /**
1392
+ * Sends an email using Mailgun
1393
+ * @param data Email data to send, including the 'from' address
1394
+ * @returns Promise with the sending result
1395
+ */
1396
+ protected sendEmail(data: mailgun.messages.SendData): Promise<mailgun.messages.SendResponse>;
1397
+ /**
1398
+ * Logs email sending attempt to Firestore for tracking
1399
+ * @param emailData Email data that was sent
1400
+ * @param success Whether the email was sent successfully
1401
+ * @param error Error object if the email failed to send
1402
+ */
1403
+ protected logEmailAttempt(emailData: {
1404
+ to: string;
1405
+ subject: string;
1406
+ templateName?: string;
1407
+ }, success: boolean, error?: any): Promise<void>;
1408
+ /**
1409
+ * Renders a simple HTML email template with variables
1410
+ * @param template HTML template string
1411
+ * @param variables Key-value pairs to replace in the template
1412
+ * @returns Rendered HTML string
1413
+ */
1414
+ protected renderTemplate(template: string, variables: Record<string, string>): string;
1415
+ }
1416
+
1417
+ /**
1418
+ * Interface for the data required to send a practitioner invitation email
1419
+ */
1420
+ interface PractitionerInviteEmailData {
1421
+ /** The token object from the practitioner service */
1422
+ token: {
1423
+ id: string;
1424
+ token: string;
1425
+ practitionerId: string;
1426
+ email: string;
1427
+ clinicId: string;
1428
+ expiresAt: admin.firestore.Timestamp;
1429
+ };
1430
+ /** Practitioner basic info */
1431
+ practitioner: {
1432
+ firstName: string;
1433
+ lastName: string;
1434
+ };
1435
+ /** Clinic info */
1436
+ clinic: {
1437
+ name: string;
1438
+ contactEmail: string;
1439
+ contactName?: string;
1440
+ };
1441
+ /** Config options */
1442
+ options?: {
1443
+ registrationUrl?: string;
1444
+ customSubject?: string;
1445
+ fromAddress?: string;
1446
+ };
1447
+ }
1448
+ /**
1449
+ * Service for sending practitioner invitation emails
1450
+ */
1451
+ declare class PractitionerInviteMailingService extends BaseMailingService {
1452
+ private readonly DEFAULT_REGISTRATION_URL;
1453
+ private readonly DEFAULT_SUBJECT;
1454
+ private readonly DEFAULT_FROM_ADDRESS;
1455
+ /**
1456
+ * Constructor for PractitionerInviteMailingService
1457
+ * @param firestore Firestore instance provided by the caller
1458
+ * @param mailgunClient Mailgun client instance provided by the caller
1459
+ */
1460
+ constructor(firestore: FirebaseFirestore.Firestore, mailgunClient: mailgun.Mailgun);
1461
+ /**
1462
+ * Sends a practitioner invitation email
1463
+ * @param data The practitioner invitation data
1464
+ * @returns Promise resolved when email is sent
1465
+ */
1466
+ sendInvitationEmail(data: PractitionerInviteEmailData): Promise<mailgun.messages.SendResponse>;
1467
+ /**
1468
+ * Handles the practitioner token creation event from Cloud Functions
1469
+ * Fetches necessary data using defined types and collection constants,
1470
+ * and sends the invitation email.
1471
+ * @param tokenData The fully typed token object including its id
1472
+ * @param fromAddress The 'from' email address to use, obtained from config
1473
+ * @returns Promise resolved when the email is sent
1474
+ */
1475
+ handleTokenCreationEvent(tokenData: PractitionerToken, fromAddress: string): Promise<void>;
1476
+ }
1477
+
1478
+ export { type AppointmentNotification, type AppointmentReminderNotification, BaseMailingService, type BaseNotification, type Clinic, ClinicAggregationService, type ClinicInfo, type ClinicLocation, type DoctorInfo, NOTIFICATIONS_COLLECTION, type Notification, NotificationStatus, NotificationType, NotificationsAdmin, type PatientProfile as Patient, PatientAggregationService, type PostRequirementNotification, type Practitioner, PractitionerAggregationService, PractitionerInviteMailingService, type PractitionerToken, PractitionerTokenStatus, type PreRequirementNotification, type Procedure, ProcedureAggregationService, type ProcedureSummaryInfo, UserRole };