import {z} from 'zod' export type OrganizationAddress = {companyName?: string | undefined, firstname: string, lastname: string, street: string, postCode: string, city: string, countryCode: string, countryName?: string | undefined, telephone?: string | undefined}; export type UpdateApiApiV1OrganizationsOrganizationIdAddressesDefaultArgs = {organizationId: string, body: OrganizationAddress}; export type UpdateApiApiV1OrganizationsOrganizationIdAddressesDefaultOptions = {baseUrl: string, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; export const organizationAddress = z.object({companyName: z.string().max(254).optional(), firstname: z.string().max(255), lastname: z.string().max(255), street: z.string().min(3).max(254), postCode: z.string().min(2).max(40), city: z.string().min(2).max(99), countryCode: z.string().max(2), countryName: z.string().optional(), telephone: z.string().max(99).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 }; /** * Store address * * PUT /api/v1/organizations/{organizationId}/addresses/default */ export const updateApiApiV1OrganizationsOrganizationIdAddressesDefault = async (args: UpdateApiApiV1OrganizationsOrganizationIdAddressesDefaultArgs, options: UpdateApiApiV1OrganizationsOrganizationIdAddressesDefaultOptions) => { const {baseUrl, fetch: fetchFn = fetch, Authorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Authorization !== undefined) headers.set("Authorization", Authorization) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/organizations/${encodeURIComponent(String(args.organizationId))}/addresses/default${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(organizationAddress, await res.json()) };