@blackcode_sa/metaestetics-api 1.7.33 → 1.7.34

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.
@@ -1983,6 +1983,206 @@ declare class PractitionerAggregationService {
1983
1983
  inactivateProceduresForPractitioner(procedureIds: string[]): Promise<void>;
1984
1984
  }
1985
1985
 
1986
+ /**
1987
+ * Minimal interface for the new mailgun.js client's messages API
1988
+ * This helps avoid a direct dependency on mailgun.js in the API package if not desired,
1989
+ * or provides clearer typing if it is.
1990
+ */
1991
+ interface NewMailgunMessagesAPI$2 {
1992
+ create(domain: string, data: any): Promise<any>;
1993
+ }
1994
+ interface NewMailgunClient$2 {
1995
+ messages: NewMailgunMessagesAPI$2;
1996
+ }
1997
+ /**
1998
+ * Base mailing service class that provides common functionality for all mailing services
1999
+ * This version is updated to expect a mailgun.js v10+ client.
2000
+ */
2001
+ declare class BaseMailingService {
2002
+ protected db: FirebaseFirestore.Firestore;
2003
+ protected mailgunClient: NewMailgunClient$2;
2004
+ /**
2005
+ * Constructor for BaseMailingService
2006
+ * @param firestore Firestore instance provided by the caller
2007
+ * @param mailgunClient Mailgun client instance (mailgun.js v10+) provided by the caller
2008
+ */
2009
+ constructor(firestore: FirebaseFirestore.Firestore, mailgunClient: NewMailgunClient$2);
2010
+ /**
2011
+ * Sends an email using the new Mailgun client API.
2012
+ * @param domain The Mailgun domain to send from (e.g., mg.metaesthetics.net)
2013
+ * @param data Email data to send, compatible with mailgun.js messages.create API
2014
+ * @returns Promise with the sending result
2015
+ */
2016
+ protected sendEmail(domain: string, // The new API requires the domain as the first argument to messages.create
2017
+ data: any): Promise<any>;
2018
+ /**
2019
+ * Logs email sending attempt to Firestore for tracking
2020
+ * @param emailData Email data that was sent
2021
+ * @param success Whether the email was sent successfully
2022
+ * @param error Error object if the email failed to send
2023
+ */
2024
+ protected logEmailAttempt(emailData: {
2025
+ to: string;
2026
+ subject: string;
2027
+ templateName?: string;
2028
+ }, success: boolean, error?: any): Promise<void>;
2029
+ /**
2030
+ * Renders a simple HTML email template with variables
2031
+ * @param template HTML template string
2032
+ * @param variables Key-value pairs to replace in the template
2033
+ * @returns Rendered HTML string
2034
+ */
2035
+ protected renderTemplate(template: string, variables: Record<string, string>): string;
2036
+ }
2037
+
2038
+ interface NewMailgunMessagesAPI$1 {
2039
+ create(domain: string, data: any): Promise<any>;
2040
+ }
2041
+ interface NewMailgunClient$1 {
2042
+ messages: NewMailgunMessagesAPI$1;
2043
+ }
2044
+ /**
2045
+ * Interface for sending practitioner invitation email data
2046
+ */
2047
+ interface ExistingPractitionerInviteEmailData {
2048
+ /** The practitioner invite object */
2049
+ invite: PractitionerInvite;
2050
+ /** Practitioner details */
2051
+ practitioner: {
2052
+ firstName: string;
2053
+ lastName: string;
2054
+ email: string;
2055
+ specialties?: string[];
2056
+ profileImageUrl?: string | null;
2057
+ };
2058
+ /** Clinic details */
2059
+ clinic: {
2060
+ name: string;
2061
+ address: string;
2062
+ contactEmail: string;
2063
+ contactPhone?: string;
2064
+ };
2065
+ /** URLs for accept/reject actions */
2066
+ urls: {
2067
+ acceptUrl: string;
2068
+ rejectUrl: string;
2069
+ };
2070
+ /** Configuration options */
2071
+ options?: {
2072
+ customSubject?: string;
2073
+ fromAddress?: string;
2074
+ mailgunDomain?: string;
2075
+ };
2076
+ }
2077
+ /**
2078
+ * Interface for clinic admin notification email data
2079
+ */
2080
+ interface ClinicAdminNotificationData {
2081
+ /** The practitioner invite object */
2082
+ invite: PractitionerInvite;
2083
+ /** Practitioner details */
2084
+ practitioner: {
2085
+ firstName: string;
2086
+ lastName: string;
2087
+ specialties?: string[];
2088
+ profileImageUrl?: string | null;
2089
+ experienceYears?: number;
2090
+ };
2091
+ /** Clinic details */
2092
+ clinic: {
2093
+ name: string;
2094
+ adminName?: string;
2095
+ adminEmail: string;
2096
+ };
2097
+ /** Additional context */
2098
+ context: {
2099
+ invitationDate: string;
2100
+ responseDate: string;
2101
+ rejectionReason?: string;
2102
+ };
2103
+ /** URLs for dashboard access */
2104
+ urls: {
2105
+ clinicDashboardUrl: string;
2106
+ practitionerProfileUrl?: string;
2107
+ findPractitionersUrl?: string;
2108
+ };
2109
+ /** Configuration options */
2110
+ options?: {
2111
+ customSubject?: string;
2112
+ fromAddress?: string;
2113
+ mailgunDomain?: string;
2114
+ };
2115
+ }
2116
+ /**
2117
+ * Service for sending existing practitioner invitation emails
2118
+ * This service handles the email flow for inviting active practitioners to join clinics
2119
+ */
2120
+ declare class ExistingPractitionerInviteMailingService extends BaseMailingService {
2121
+ private readonly DEFAULT_MAILGUN_DOMAIN;
2122
+ private readonly DEFAULT_FROM_ADDRESS;
2123
+ /**
2124
+ * Constructor for ExistingPractitionerInviteMailingService
2125
+ * @param firestore Firestore instance provided by the caller
2126
+ * @param mailgunClient Mailgun client instance (mailgun.js v10+) provided by the caller
2127
+ */
2128
+ constructor(firestore: FirebaseFirestore.Firestore, mailgunClient: NewMailgunClient$1);
2129
+ /**
2130
+ * Sends an invitation email to an existing practitioner
2131
+ * @param data The invitation email data
2132
+ * @returns Promise resolved when email is sent
2133
+ */
2134
+ sendPractitionerInvitationEmail(data: ExistingPractitionerInviteEmailData): Promise<any>;
2135
+ /**
2136
+ * Sends a notification email to clinic admin when practitioner accepts invitation
2137
+ * @param data The notification email data
2138
+ * @returns Promise resolved when email is sent
2139
+ */
2140
+ sendAcceptedNotificationEmail(data: ClinicAdminNotificationData): Promise<any>;
2141
+ /**
2142
+ * Sends a notification email to clinic admin when practitioner rejects invitation
2143
+ * @param data The notification email data
2144
+ * @returns Promise resolved when email is sent
2145
+ */
2146
+ sendRejectedNotificationEmail(data: ClinicAdminNotificationData): Promise<any>;
2147
+ /**
2148
+ * Handles the practitioner invite creation event
2149
+ * Fetches necessary data and sends the invitation email to the practitioner
2150
+ * @param invite The practitioner invite object
2151
+ * @param mailgunConfig Mailgun configuration
2152
+ * @returns Promise resolved when the email is sent
2153
+ */
2154
+ handleInviteCreationEvent(invite: PractitionerInvite, mailgunConfig: {
2155
+ fromAddress: string;
2156
+ domain: string;
2157
+ acceptUrl: string;
2158
+ rejectUrl: string;
2159
+ }): Promise<void>;
2160
+ /**
2161
+ * Formats working hours for display in emails
2162
+ * @param workingHours The working hours object
2163
+ * @returns Formatted string representation
2164
+ */
2165
+ private formatWorkingHours;
2166
+ /**
2167
+ * Formats clinic address for display
2168
+ * @param location The clinic location object
2169
+ * @returns Formatted address string
2170
+ */
2171
+ private formatClinicAddress;
2172
+ /**
2173
+ * Fetches a practitioner by ID
2174
+ * @param practitionerId The practitioner ID
2175
+ * @returns The practitioner or null if not found
2176
+ */
2177
+ private fetchPractitionerById;
2178
+ /**
2179
+ * Fetches a clinic by ID
2180
+ * @param clinicId The clinic ID
2181
+ * @returns The clinic or null if not found
2182
+ */
2183
+ private fetchClinicById;
2184
+ }
2185
+
1986
2186
  /**
1987
2187
  * @class PractitionerInviteAggregationService
1988
2188
  * @description Handles aggregation tasks and side effects related to practitioner invite lifecycle events.
@@ -1991,26 +2191,41 @@ declare class PractitionerAggregationService {
1991
2191
  */
1992
2192
  declare class PractitionerInviteAggregationService {
1993
2193
  private db;
2194
+ private mailingService?;
1994
2195
  /**
1995
2196
  * Constructor for PractitionerInviteAggregationService.
1996
2197
  * @param firestore Optional Firestore instance. If not provided, it uses the default admin SDK instance.
2198
+ * @param mailingService Optional mailing service for sending emails
1997
2199
  */
1998
- constructor(firestore?: admin.firestore.Firestore);
2200
+ constructor(firestore?: admin.firestore.Firestore, mailingService?: ExistingPractitionerInviteMailingService);
1999
2201
  /**
2000
2202
  * Handles side effects when a practitioner invite is first created.
2001
2203
  * This function would typically be called by a Firestore onCreate trigger.
2002
2204
  * @param {PractitionerInvite} invite - The newly created PractitionerInvite object.
2205
+ * @param {object} emailConfig - Optional email configuration for sending invite emails
2003
2206
  * @returns {Promise<void>}
2004
2207
  */
2005
- handleInviteCreate(invite: PractitionerInvite): Promise<void>;
2208
+ handleInviteCreate(invite: PractitionerInvite, emailConfig?: {
2209
+ fromAddress: string;
2210
+ domain: string;
2211
+ acceptUrl: string;
2212
+ rejectUrl: string;
2213
+ }): Promise<void>;
2006
2214
  /**
2007
2215
  * Handles side effects when a practitioner invite is updated.
2008
2216
  * This function would typically be called by a Firestore onUpdate trigger.
2009
2217
  * @param {PractitionerInvite} before - The PractitionerInvite object before the update.
2010
2218
  * @param {PractitionerInvite} after - The PractitionerInvite object after the update.
2219
+ * @param {object} emailConfig - Optional email configuration for sending notification emails
2011
2220
  * @returns {Promise<void>}
2012
2221
  */
2013
- handleInviteUpdate(before: PractitionerInvite, after: PractitionerInvite): Promise<void>;
2222
+ handleInviteUpdate(before: PractitionerInvite, after: PractitionerInvite, emailConfig?: {
2223
+ fromAddress: string;
2224
+ domain: string;
2225
+ clinicDashboardUrl: string;
2226
+ practitionerProfileUrl?: string;
2227
+ findPractitionersUrl?: string;
2228
+ }): Promise<void>;
2014
2229
  /**
2015
2230
  * Handles side effects when a practitioner invite is deleted.
2016
2231
  * @param deletedInvite - The PractitionerInvite object that was deleted.
@@ -2021,12 +2236,14 @@ declare class PractitionerInviteAggregationService {
2021
2236
  * Handles the business logic when a practitioner accepts an invite.
2022
2237
  * This includes adding the practitioner to the clinic and the clinic to the practitioner.
2023
2238
  * @param {PractitionerInvite} invite - The accepted invite
2239
+ * @param {object} emailConfig - Optional email configuration for sending notification emails
2024
2240
  * @returns {Promise<void>}
2025
2241
  */
2026
2242
  private handleInviteAccepted;
2027
2243
  /**
2028
2244
  * Handles the business logic when a practitioner rejects an invite.
2029
2245
  * @param {PractitionerInvite} invite - The rejected invite
2246
+ * @param {object} emailConfig - Optional email configuration for sending notification emails
2030
2247
  * @returns {Promise<void>}
2031
2248
  */
2032
2249
  private handleInviteRejected;
@@ -2077,6 +2294,22 @@ declare class PractitionerInviteAggregationService {
2077
2294
  * @returns {Promise<Clinic | null>} The clinic or null if not found.
2078
2295
  */
2079
2296
  private fetchClinicById;
2297
+ /**
2298
+ * Sends acceptance notification email to clinic admin
2299
+ * @param invite The accepted invite
2300
+ * @param practitioner The practitioner who accepted
2301
+ * @param clinic The clinic that sent the invite
2302
+ * @param emailConfig Email configuration
2303
+ */
2304
+ private sendAcceptanceNotificationEmail;
2305
+ /**
2306
+ * Sends rejection notification email to clinic admin
2307
+ * @param invite The rejected invite
2308
+ * @param practitioner The practitioner who rejected
2309
+ * @param clinic The clinic that sent the invite
2310
+ * @param emailConfig Email configuration
2311
+ */
2312
+ private sendRejectionNotificationEmail;
2080
2313
  }
2081
2314
 
2082
2315
  /**
@@ -2409,58 +2642,6 @@ declare class ReviewsAggregationService {
2409
2642
  calculateEntityReviewInfo(entityId: string, entityType: "clinic" | "practitioner" | "procedure"): Promise<ClinicReviewInfo | PractitionerReviewInfo | ProcedureReviewInfo>;
2410
2643
  }
2411
2644
 
2412
- /**
2413
- * Minimal interface for the new mailgun.js client's messages API
2414
- * This helps avoid a direct dependency on mailgun.js in the API package if not desired,
2415
- * or provides clearer typing if it is.
2416
- */
2417
- interface NewMailgunMessagesAPI$1 {
2418
- create(domain: string, data: any): Promise<any>;
2419
- }
2420
- interface NewMailgunClient$1 {
2421
- messages: NewMailgunMessagesAPI$1;
2422
- }
2423
- /**
2424
- * Base mailing service class that provides common functionality for all mailing services
2425
- * This version is updated to expect a mailgun.js v10+ client.
2426
- */
2427
- declare class BaseMailingService {
2428
- protected db: FirebaseFirestore.Firestore;
2429
- protected mailgunClient: NewMailgunClient$1;
2430
- /**
2431
- * Constructor for BaseMailingService
2432
- * @param firestore Firestore instance provided by the caller
2433
- * @param mailgunClient Mailgun client instance (mailgun.js v10+) provided by the caller
2434
- */
2435
- constructor(firestore: FirebaseFirestore.Firestore, mailgunClient: NewMailgunClient$1);
2436
- /**
2437
- * Sends an email using the new Mailgun client API.
2438
- * @param domain The Mailgun domain to send from (e.g., mg.metaesthetics.net)
2439
- * @param data Email data to send, compatible with mailgun.js messages.create API
2440
- * @returns Promise with the sending result
2441
- */
2442
- protected sendEmail(domain: string, // The new API requires the domain as the first argument to messages.create
2443
- data: any): Promise<any>;
2444
- /**
2445
- * Logs email sending attempt to Firestore for tracking
2446
- * @param emailData Email data that was sent
2447
- * @param success Whether the email was sent successfully
2448
- * @param error Error object if the email failed to send
2449
- */
2450
- protected logEmailAttempt(emailData: {
2451
- to: string;
2452
- subject: string;
2453
- templateName?: string;
2454
- }, success: boolean, error?: any): Promise<void>;
2455
- /**
2456
- * Renders a simple HTML email template with variables
2457
- * @param template HTML template string
2458
- * @param variables Key-value pairs to replace in the template
2459
- * @returns Rendered HTML string
2460
- */
2461
- protected renderTemplate(template: string, variables: Record<string, string>): string;
2462
- }
2463
-
2464
2645
  interface NewMailgunMessagesAPI {
2465
2646
  create(domain: string, data: any): Promise<any>;
2466
2647
  }
@@ -3047,7 +3228,7 @@ interface ReviewAddedEmailData extends AppointmentEmailDataBase {
3047
3228
  */
3048
3229
  declare class AppointmentMailingService extends BaseMailingService {
3049
3230
  private readonly DEFAULT_MAILGUN_DOMAIN;
3050
- constructor(firestore: admin.firestore.Firestore, mailgunClient: NewMailgunClient$1);
3231
+ constructor(firestore: admin.firestore.Firestore, mailgunClient: NewMailgunClient$2);
3051
3232
  sendAppointmentConfirmedEmail(data: AppointmentConfirmationEmailData): Promise<any>;
3052
3233
  sendAppointmentRequestedEmailToClinic(data: AppointmentRequestedEmailData): Promise<any>;
3053
3234
  sendAppointmentCancelledEmail(data: AppointmentCancellationEmailData): Promise<any>;
@@ -3064,4 +3245,4 @@ declare class AppointmentMailingService extends BaseMailingService {
3064
3245
  */
3065
3246
  declare function freeConsultationInfrastructure(db?: admin.firestore.Firestore): Promise<boolean>;
3066
3247
 
3067
- export { APPOINTMENTS_COLLECTION, type Appointment, AppointmentAggregationService, type AppointmentCancellationEmailData, type AppointmentConfirmationEmailData, type AppointmentEmailDataBase, AppointmentMailingService, type AppointmentMediaItem, type AppointmentReminderNotification, type AppointmentRequestedEmailData, type AppointmentRescheduledProposalEmailData, AppointmentStatus, type AvailableSlot, BaseMailingService, type BaseNotification, BookingAdmin, BookingAvailabilityCalculator, type BookingAvailabilityRequest, type BookingAvailabilityResponse, CalendarAdminService, type Clinic, ClinicAggregationService, type ClinicInfo, type ClinicLocation, type CreateAppointmentData, type CreateAppointmentHttpData, type DoctorInfo, DocumentManagerAdminService, type FilledDocument, FilledFormsAggregationService, type InitializeAppointmentFormsResult, type LinkedFormInfo, Logger, MediaType, NOTIFICATIONS_COLLECTION, type Notification, NotificationStatus, NotificationType, NotificationsAdmin, type OrchestrateAppointmentCreationData, PATIENT_REQUIREMENTS_SUBCOLLECTION_NAME, type PatientProfile as Patient, PatientAggregationService, PatientInstructionStatus, type PatientRequirementInstance, type PatientRequirementInstruction, PatientRequirementOverallStatus, PatientRequirementsAdminService, type PatientReviewInfo, PaymentStatus, type PostRequirementNotification, type Practitioner, PractitionerAggregationService, type PractitionerInvite, PractitionerInviteAggregationService, PractitionerInviteMailingService, PractitionerInviteStatus, type PractitionerToken, PractitionerTokenStatus, type PreRequirementNotification, type Procedure, ProcedureAggregationService, type ProcedureExtendedInfo, type ProcedureSummaryInfo, type Review, type ReviewAddedEmailData, type ReviewRequestEmailData, ReviewsAggregationService, type SearchAppointmentsParams, type TimeInterval, type UpdateAppointmentData, UserRole, freeConsultationInfrastructure };
3248
+ export { APPOINTMENTS_COLLECTION, type Appointment, AppointmentAggregationService, type AppointmentCancellationEmailData, type AppointmentConfirmationEmailData, type AppointmentEmailDataBase, AppointmentMailingService, type AppointmentMediaItem, type AppointmentReminderNotification, type AppointmentRequestedEmailData, type AppointmentRescheduledProposalEmailData, AppointmentStatus, type AvailableSlot, BaseMailingService, type BaseNotification, BookingAdmin, BookingAvailabilityCalculator, type BookingAvailabilityRequest, type BookingAvailabilityResponse, CalendarAdminService, type Clinic, type ClinicAdminNotificationData, ClinicAggregationService, type ClinicInfo, type ClinicLocation, type CreateAppointmentData, type CreateAppointmentHttpData, type DoctorInfo, DocumentManagerAdminService, type ExistingPractitionerInviteEmailData, ExistingPractitionerInviteMailingService, type FilledDocument, FilledFormsAggregationService, type InitializeAppointmentFormsResult, type LinkedFormInfo, Logger, MediaType, NOTIFICATIONS_COLLECTION, type Notification, NotificationStatus, NotificationType, NotificationsAdmin, type OrchestrateAppointmentCreationData, PATIENT_REQUIREMENTS_SUBCOLLECTION_NAME, type PatientProfile as Patient, PatientAggregationService, PatientInstructionStatus, type PatientRequirementInstance, type PatientRequirementInstruction, PatientRequirementOverallStatus, PatientRequirementsAdminService, type PatientReviewInfo, PaymentStatus, type PostRequirementNotification, type Practitioner, PractitionerAggregationService, type PractitionerInvite, PractitionerInviteAggregationService, PractitionerInviteMailingService, PractitionerInviteStatus, type PractitionerToken, PractitionerTokenStatus, type PreRequirementNotification, type Procedure, ProcedureAggregationService, type ProcedureExtendedInfo, type ProcedureSummaryInfo, type Review, type ReviewAddedEmailData, type ReviewRequestEmailData, ReviewsAggregationService, type SearchAppointmentsParams, type TimeInterval, type UpdateAppointmentData, UserRole, freeConsultationInfrastructure };