import {z} from 'zod' export type PhoneNumberServiceNormalizedPhoneNumberNormalizedE164PhoneNumber = {value: string}; export type Point = {latitude: number, longitude: number}; export type DayId = 1 | 2 | 3 | 4 | 5 | 6 | 7; export type UpdateApiUsersUserIdAddressesDeliveryArgs = {userId: number, body: {name: string, line1: string, line2?: string | undefined, city: string, province: string, postalCode: string, telephone: PhoneNumberServiceNormalizedPhoneNumberNormalizedE164PhoneNumber, instructions?: string | undefined, buildingType?: number | undefined, location?: Point | undefined, defaultDayId: DayId}}; export type UpdateApiUsersUserIdAddressesDeliveryOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const streetAddressType = z.enum(["USER", "GUEST", "STORE"]); export const province = z.enum(["ALBERTA", "BRITISH_COLUMBIA", "MANITOBA", "NEW_BRUNSWICK", "NEWFOUNDLAND_AND_LABRADOR", "NORTHWEST_TERRITORIES", "NOVA_SCOTIA", "NUNAVUT", "ONTARIO", "PRINCE_EDWARD_ISLAND", "QUEBEC", "SASKATCHEWAN", "YUKON_TERRITORY"]); export const phoneNumberServiceNormalizedPhoneNumberNormalizedE164PhoneNumber = z.object({value: z.string()}); export const userStreetAddress = z.object({type: streetAddressType, name: z.string(), line1: z.string(), line2: z.string(), city: z.string(), province: province, postalCode: z.string(), telephone: phoneNumberServiceNormalizedPhoneNumberNormalizedE164PhoneNumber, instructions: z.string(), buildingType: z.number().int(), latitude: z.number(), longitude: z.number(), id: z.number().int().optional(), userId: z.number().int().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 }; /** * PUT /users/{userId}/addresses/delivery */ export const updateApiUsersUserIdAddressesDelivery = async (args: UpdateApiUsersUserIdAddressesDeliveryArgs, options: UpdateApiUsersUserIdAddressesDeliveryOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/users/${encodeURIComponent(String(args.userId))}/addresses/delivery${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(userStreetAddress, await res.json()) };