import {z} from 'zod' export type GetApiUsersUserIdPendingLogisticsStopRequestArgs = {userId: number}; export type GetApiUsersUserIdPendingLogisticsStopRequestOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const userBasic = z.object({active: z.boolean().optional()}); export const deliveryProvider = z.object({code: z.string(), name: z.string()}); export const logisticsStopRequestStatus = z.enum(["PENDING", "SCHEDULED", "CANCELLED", "COMPLETED"]); 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 streetAddress = 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()}); export const deliveryDriver = z.object({externalId: z.string(), displayName: z.string()}); export const deliveryRouteInfo = z.object({date: z.string(), code: z.string(), routeSequence: z.number().int(), stopSequence: z.number().int(), barcode: z.string(), provider: deliveryProvider, driver: deliveryDriver}); export const logisticsStopRequest = z.object({id: z.number().int(), user: userBasic, admin: userBasic, provider: deliveryProvider.nullable().optional(), packingOrder: z.number().int().nullable(), deliveryRoutingBatchId: z.number().int(), scheduleByDate: z.string(), created: z.string(), modified: z.string(), providerTransmittedAt: z.string(), completedAt: z.string(), cancelledAt: z.string(), autoCancel: z.boolean(), status: logisticsStopRequestStatus, address: streetAddress, routeInfo: deliveryRouteInfo.nullable()}); 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 }; /** * GET /users/{userId}/pending-logistics-stop-request */ export const getApiUsersUserIdPendingLogisticsStopRequest = async (args: GetApiUsersUserIdPendingLogisticsStopRequestArgs, options: GetApiUsersUserIdPendingLogisticsStopRequestOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/users/${encodeURIComponent(String(args.userId))}/pending-logistics-stop-request${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(logisticsStopRequest, await res.json()) };