import {z} from 'zod' export type GetApiApiV1DeliveryexperienceOrderSearchArgs = {shipiumTenantId?: string | undefined, associatedIdentifiers?: Array | undefined, fromDate?: string | undefined, toDate?: string | undefined, orderStatuses?: (Array<'open' | 'open_split' | 'complete' | 'complete_multiship' | 'cancelled' | 'partial_ship' | 'error'>) | undefined, include?: Array | undefined, anchor?: string | undefined, count?: number | undefined}; export type GetApiApiV1DeliveryexperienceOrderSearchOptions = {baseUrl?: string | undefined, oauth2Scheme?: string | undefined, fetch?: typeof fetch | undefined}; export const orchestrationLedger = z.object({generatedAssets: z.record(z.string(), z.string()).optional(), resultIds: z.array(z.string()).optional(), log: z.array(z.string()).optional()}); export const orchestratedAssetMetadata = z.object({orchestrationId: z.string().optional(), orchestrationTimeStamp: z.string().optional(), orchestrationLedger: orchestrationLedger.optional()}); export const orchestratedAssetBatchResults = z.object({orchestratedAssetMetadata: orchestratedAssetMetadata.optional(), results: z.array(z.object({})).optional(), failures: z.array(z.object({})).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 }; /** * Search for existing orders. * * GET /api/v1/deliveryexperience/order/search */ export const getApiApiV1DeliveryexperienceOrderSearch = async (args: GetApiApiV1DeliveryexperienceOrderSearchArgs, options?: GetApiApiV1DeliveryexperienceOrderSearchOptions) => { const {baseUrl = "https://api.shipium.com", fetch: fetchFn = fetch, oauth2Scheme} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.shipiumTenantId != null) query.append("shipiumTenantId", String(args.shipiumTenantId)) for (const item of args.associatedIdentifiers ?? []) query.append("associatedIdentifiers", String(item)) if (args.fromDate != null) query.append("fromDate", String(args.fromDate)) if (args.toDate != null) query.append("toDate", String(args.toDate)) for (const item of args.orderStatuses ?? []) query.append("orderStatuses", String(item)) for (const item of args.include ?? []) query.append("include", String(item)) if (args.anchor != null) query.append("anchor", String(args.anchor)) if (args.count != null) query.append("count", String(args.count)) if (oauth2Scheme !== undefined) headers.set('authorization', `Bearer ${oauth2Scheme}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/deliveryexperience/order/search${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(orchestratedAssetBatchResults, await res.json()) };