import {z} from 'zod' export type BusinessProfilePatch = {displayName?: string | undefined, vertical?: ('AUTO' | 'BEAUTY' | 'APPAREL' | 'EDU' | 'ENTERTAIN' | 'EVENT_PLAN' | 'FINANCE' | 'GROCERY' | 'GOVT' | 'HOTEL' | 'HEALTH' | 'NONPROFIT' | 'PROF_SERVICES' | 'RETAIL' | 'TRAVEL' | 'RESTAURANT' | 'NOT_A_BIZ' | 'OTHER') | undefined, description?: string | undefined, aboutShort?: string | undefined, email?: string | undefined, websites?: Array | undefined, businessHours?: {[key: string]: unknown} | undefined, profilePhotoUrl?: string | undefined, awayMessage?: string | undefined}; export type PatchApiV1OrganizationsMeBusinessProfileArgs = {body: BusinessProfilePatch}; export type PatchApiV1OrganizationsMeBusinessProfileOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const businessProfileResponse = z.object({id: z.string().nullable().optional(), displayName: z.string().nullable().optional(), vertical: z.string().nullable().optional(), description: z.string().nullable().optional(), aboutShort: z.string().nullable().optional(), email: z.string().nullable().optional(), websites: z.array(z.string()).nullable().optional(), businessHours: z.record(z.string(), z.unknown()).nullable().optional(), profilePhotoUrl: z.string().nullable().optional(), awayMessage: z.string().nullable().optional(), metaSyncStatus: z.string(), metaSyncedAt: z.string().nullable().optional(), metaSyncError: z.string().nullable().optional(), updatedAt: z.string().nullable().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 }; /** * Atualizar perfil comercial * * PATCH /v1/organizations/me/business-profile */ export const patchApiV1OrganizationsMeBusinessProfile = async (args: PatchApiV1OrganizationsMeBusinessProfileArgs, options?: PatchApiV1OrganizationsMeBusinessProfileOptions) => { const {baseUrl = "https://api.ararahq.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/organizations/me/business-profile${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(businessProfileResponse, await res.json()) };