import {z} from 'zod' export type GetApiSettingsAutoEmailArgs = {SiteId: number}; export type GetApiSettingsAutoEmailOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const mindbodyRestApiDtoModelsSiteAutoEmailSetting = z.object({StudioId: z.number().int().optional(), EmailType: z.enum(["NewClientWelcomeConsumerMode", "CancellationNotificationEarly", "CancellationNotificationLate", "ReservationConfirmationsSingle", "ReservationConfirmationsRecurring", "EnrollmentConfirmationsPaymentPlan", "EnrollmentConfirmationsPaymentPlanResourceType", "AppointmentRequestConfirmationsSingle", "AppointmentRequestConfirmationsRecurring", "AppointmentBookingConfirmationsSingle", "AppointmentBookingConfirmationsRecurring", "ClassEventCancellationNotifications", "AutoPayPurchaseConfirmation", "PurchaseReceiptBizMode", "NoShowNotification", "ReservationAddedFromWaitlistNotification", "GiftCardRecipientNotification", "SeriesNotificationTimeRunningOut", "SeriesNotificationVisitsRemainingLow", "PurchaseReceiptConsumerMode", "SecurityVerificationApproved", "EnrollmentConfirmations", "NewClientWelcomeBizMode", "AppointmentChangeNotification", "AppointmentBookingConfirmationsManual", "ContactLogFollowUpNotification", "NewLeadGenerated", "ContractBizMode", "OpenTicketQuote", "AppointmentRequestNotification", "AppointmentRequestDenial", "BirthdayEmail", "PartnerStorePurchaseReceipt", "PartnerStoreOrderNotification", "OrderShippedNotification", "ContractAutoPayCreditCardExpiring", "AutoPayFailedNotification", "ContractReminder", "ClientClosed", "CloseFollowup", "ForgotLoginInformation", "ContractUnsuspended", "AppointmentReminder", "ReservationReminder", "CourseEnrollmentConfirmations", "CourseEnrollmentConfirmationsPaymentPlan", "FirstVisitReservation", "FirstVisitAppointment", "TeacherSubReminder", "ClientScheduleManual", "AppointmentFollowUp", "FirstVisitAnniversary", "AppointmentCancellationEarly", "AppointmentCancellationLate", "EnrollmentWaitlistNotification", "ContractRenewalNotification", "TeacherSubNotification", "ActiveClient", "LostClient", "LostPayingClient", "LostNonPayingClient", "ActivePayingClient", "ActiveNonPayingClient", "LostWelcomeBackClient", "InvoiceEmail", "ClientFormsNotification", "ContractDateUpdateNotification", "AppointmentFromWaitlist", "AppointmentFirstToClaim"]).optional(), Active: z.boolean().optional(), AlwaysSend: z.boolean().optional(), SendStudioMode: z.boolean().optional()}); export const getApiSettingsAutoEmailResponse = z.array(mindbodyRestApiDtoModelsSiteAutoEmailSetting); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Retrieves a subscriber's Auto Email Settings * * GET /Settings/AutoEmail */ export const getApiSettingsAutoEmail = async (args: GetApiSettingsAutoEmailArgs, options?: GetApiSettingsAutoEmailOptions) => { const {baseUrl = "https://api.mindbodyonline.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.SiteId != null) headers.set("SiteId", String(args.SiteId)) const url = `${baseUrl.replace(/\/+$/, '')}/Settings/AutoEmail${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiSettingsAutoEmailResponse, await res.json()) };