import {z} from 'zod' export type MindbodyRestApiDtoModelsClientClientsProfileRequest = {ClientIds?: Array | undefined}; export type CreateApiUsersClientClientsProfileArgs = {Authorization: string, SiteId: number, includeImage?: boolean | undefined, body: MindbodyRestApiDtoModelsClientClientsProfileRequest}; export type CreateApiUsersClientClientsProfileOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const mindbodyRestApiDtoModelsLocationLocation = z.object({Id: z.number().int().optional(), Name: z.string().optional(), BillingAccountId: z.string().optional(), MerchantAccountProcessingId: z.string().optional()}); export const mindbodyRestApiDtoModelsClientClientCreditCard = z.object({CardType: z.string().optional(), CardLastFour: z.string().optional()}); export const mindbodyRestApiDtoModelsClientClientProfileAndImage = z.object({ImageUrl: z.string().optional(), Id: z.number().int().optional(), ExternalId: z.string().optional(), FirstName: z.string().optional(), LastName: z.string().optional(), MiddleName: z.string().optional(), Email: z.string().optional(), HomePhone: z.string().optional(), WorkPhone: z.string().optional(), MobilePhone: z.string().optional(), Address: z.string().optional(), Address2: z.string().optional(), City: z.string().optional(), State: z.string().optional(), Country: z.string().optional(), PostalCode: z.string().optional(), Gender: z.string().optional(), BirthDate: z.string().optional(), ReferredBy: z.string().optional(), EmergencyContactInfoName: z.string().optional(), EmergencyContactInfoRelationship: z.string().optional(), EmergencyContactInfoPhone: z.string().optional(), EmergencyContactInfoEmail: z.string().optional(), HomeLocation: mindbodyRestApiDtoModelsLocationLocation.optional(), ClientCreditCard: mindbodyRestApiDtoModelsClientClientCreditCard.optional()}); export const createApiUsersClientClientsProfileResponse = z.array(mindbodyRestApiDtoModelsClientClientProfileAndImage); 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 }; /** * Gets multiple client profile with image url at a studio * * POST /users/client/ClientsProfile */ export const createApiUsersClientClientsProfile = async (args: CreateApiUsersClientClientsProfileArgs, options?: CreateApiUsersClientClientsProfileOptions) => { const {baseUrl = "https://api.mindbodyonline.com", 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.Authorization != null) headers.set("Authorization", String(args.Authorization)) if (args.SiteId != null) headers.set("SiteId", String(args.SiteId)) if (args.includeImage != null) query.append("includeImage", String(args.includeImage)) const url = `${baseUrl.replace(/\/+$/, '')}/users/client/ClientsProfile${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(createApiUsersClientClientsProfileResponse, await res.json()) };