import {z} from 'zod' export type CreateApiV1AuthoritiesIdVendorsVendorIdAttachmentsArgs = {id: string, vendorId: string, body: BodyInit}; export type CreateApiV1AuthoritiesIdVendorsVendorIdAttachmentsOptions = {baseUrl?: string | undefined, apikey?: string | undefined, fetch?: typeof fetch | undefined}; export const authoritiesV1VendorAttachments = z.object({id: z.string().optional(), attachment: z.string().optional()}); export const createApiV1AuthoritiesIdVendorsVendorIdAttachmentsResponse = z.array(authoritiesV1VendorAttachments); 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 }; /** * Upload multiple files to be attached to a specific vendor in an authority. * * POST /v1/authorities/{id}/vendors/{vendorId}/attachments * * Also accepts auth: oauth2 */ export const createApiV1AuthoritiesIdVendorsVendorIdAttachments = async (args: CreateApiV1AuthoritiesIdVendorsVendorIdAttachmentsArgs, options?: CreateApiV1AuthoritiesIdVendorsVendorIdAttachmentsOptions) => { const {baseUrl = "https://api.domain.com.au", fetch: fetchFn = fetch, apikey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/vnd.realtimeagent.authorities.v1+json") if (apikey !== undefined) headers.set("x-api-key", apikey) const url = `${baseUrl.replace(/\/+$/, '')}/v1/authorities/${encodeURIComponent(String(args.id))}/vendors/${encodeURIComponent(String(args.vendorId))}/attachments${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: args.body}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiV1AuthoritiesIdVendorsVendorIdAttachmentsResponse, await res.json()) };