import {z} from 'zod' export type RoleType = 'ADMIN' | 'PROVIDER' | 'USER'; export type RoleSummary = {id: string, name: string, userType: RoleType, createdDate?: (string | null) | undefined, updatedDate?: (string | null) | undefined}; export type ProviderUpdate = {firstName?: (string | null) | undefined, lastName?: (string | null) | undefined, externalId?: (string | null) | undefined, email?: (string | null) | undefined, phoneNumber?: (string | null) | undefined, address?: (string | null) | undefined, addressLineTwo?: (string | null) | undefined, city?: (string | null) | undefined, state?: (string | null) | undefined, zipCode?: (string | null) | undefined, country?: (string | null) | undefined, addressValid?: (boolean | null) | undefined, meta?: (Record | null) | undefined, primaryLocationId?: (string | null) | undefined, bio?: (string | null) | undefined, profileImage?: (string | null) | undefined, nationalProviderIdentifier?: (string | null) | undefined, roles?: (Array | null) | undefined, bookingCapacity?: (number | null) | undefined, showIds?: (boolean | null) | undefined, showWeekendsOnCalendar?: (boolean | null) | undefined}; export type UpdateApiAdminProvidersProviderIdArgs = {TENANT: string, 'API-KEY': string, provider_id: string, body: ProviderUpdate}; export type UpdateApiAdminProvidersProviderIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const roleType = z.enum(["ADMIN", "PROVIDER", "USER"]); export const roleSummary = z.object({id: z.string(), name: z.string(), userType: roleType, createdDate: z.string().nullable().optional(), updatedDate: z.string().nullable().optional()}); export const providerSummary = z.object({id: z.string(), firstName: z.string().nullable().optional(), lastName: z.string().nullable().optional(), phoneNumber: z.string().nullable().optional(), email: z.string().nullable().optional(), type: z.string(), locationId: z.string().nullable().optional(), externalId: z.string().nullable().optional(), address: z.string().nullable().optional(), addressLineTwo: z.string().nullable().optional(), city: z.string().nullable().optional(), state: z.string().nullable().optional(), zipCode: z.string().nullable().optional(), country: z.string().nullable().optional(), createdDate: z.string(), addressValid: z.boolean().nullable().optional(), meta: z.object({}).nullable().optional(), isArchived: z.boolean().nullable().optional(), primaryLocationId: z.string().nullable().optional(), roles: z.array(roleSummary), lastActive: z.string().nullable().optional(), bio: z.string().nullable().optional(), profileImage: z.string().nullable().optional(), hasGoogleCalendar: z.boolean().optional(), nationalProviderIdentifier: z.string().nullable().optional(), bookingCapacity: z.number().int().nullable().optional(), showIds: z.boolean().optional(), showWeekendsOnCalendar: z.boolean().optional(), showCancelledAppointments: z.boolean().optional(), showMessagesBox: z.boolean().optional(), startCalendarHour: z.number().int().nullable().optional(), endCalendarHour: z.number().int().nullable().optional(), sendGcalInvites: z.boolean().optional(), calendarGridInterval: z.number().int().nullable().optional(), appointmentTimeStepMinutes: z.number().int().nullable().optional(), showTranslucentPastEvents: z.boolean().optional(), showGhostEvent: z.boolean().optional(), autoSignOffNotes: z.boolean().optional()}); 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 }; /** * Update Provider * * PUT /admin/providers/{provider_id} */ export const updateApiAdminProvidersProviderId = async (args: UpdateApiAdminProvidersProviderIdArgs, options: UpdateApiAdminProvidersProviderIdOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.TENANT != null) headers.set("TENANT", String(args.TENANT)) if (args['API-KEY'] != null) headers.set("API-KEY", String(args['API-KEY'])) const url = `${baseUrl.replace(/\/+$/, '')}/admin/providers/${encodeURIComponent(String(args.provider_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(providerSummary, await res.json()) };