import {z} from 'zod' export type UpdateApiV1ExternalIdsIdArgs = {id: number, external_id?: string | undefined, integration_name?: string | undefined}; export type UpdateApiV1ExternalIdsIdOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const updateApiV1ExternalIdsIdResponse = z.object({external_id: z.object({id: z.number().int().optional(), external_id: z.string().optional(), integration_name: z.string().optional(), external_id_holder_id: z.number().int().optional(), external_id_holder_type: z.string().optional()}).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 the External ID of an Entity * * PUT /v1/external_ids/{id} */ export const updateApiV1ExternalIdsId = async (args: UpdateApiV1ExternalIdsIdArgs, options?: UpdateApiV1ExternalIdsIdOptions) => { const {baseUrl = "https://api.gomotive.com", fetch: fetchFn = fetch, sec0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.external_id != null) query.append("external_id", String(args.external_id)) if (args.integration_name != null) query.append("integration_name", String(args.integration_name)) if (sec0 !== undefined) headers.set("x-api-key", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/v1/external_ids/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(updateApiV1ExternalIdsIdResponse, await res.json()) };