import {z} from 'zod' export type SmsSender = string; export type CreateApiApiContactsDisassociateContactIdArgs = {contact_id: string, body: {channel_id?: string | undefined, channel_type: 'sms' | 'email' | 'ios' | 'android' | 'amazon' | 'web' | 'open', email_address?: string | undefined, msisdn?: string | undefined, opt_out?: boolean | undefined, sender?: SmsSender | undefined}}; export type CreateApiApiContactsDisassociateContactIdOptions = {baseUrl?: string | undefined, oauth2Token?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiApiContactsDisassociateContactIdResponse = z.object({channel_id: z.string().optional(), contact: z.string().optional(), ok: 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 }; /** * Contact disassociation * * POST /api/contacts/disassociate/{contact_id} */ export const createApiApiContactsDisassociateContactId = async (args: CreateApiApiContactsDisassociateContactIdArgs, options?: CreateApiApiContactsDisassociateContactIdOptions) => { const {baseUrl = "https://go.urbanairship.com", fetch: fetchFn = fetch, oauth2Token} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (oauth2Token !== undefined) headers.set('authorization', `Bearer ${oauth2Token}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/contacts/disassociate/${encodeURIComponent(String(args.contact_id))}${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(createApiApiContactsDisassociateContactIdResponse, await res.json()) };