import {z} from 'zod' export type RefreshOrderQuotesInput = {orderId?: (string | null) | undefined, externalOrderId?: (string | null) | undefined}; export type CreateApiV1OrderRefreshQuotesArgs = {body: RefreshOrderQuotesInput}; export type CreateApiV1OrderRefreshQuotesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const quoteSerializer = z.object({id: z.string(), type: z.string().nullable().optional(), providerId: z.string(), providerName: z.string(), providerLogo: z.string().nullable().optional(), providerIsInternal: z.boolean().nullable().optional(), createdTime: z.string(), expireTime: z.string().nullable().optional(), priceCents: z.number().int(), taxAmountCents: z.number().int().nullable().optional(), tollFeeCents: z.number().int().nullable().optional(), nashFeeCents: z.number().int().nullable().optional(), insuranceFeeCents: z.number().int().nullable().optional(), currency: z.string().nullable().optional(), pickupWindow: z.string().nullable().optional(), dropoffEta: z.string().nullable().optional(), tags: z.array(z.string()).nullable().optional(), costSplitCustomerCents: z.number().int().nullable().optional(), costSplitBusinessCents: z.number().int().nullable().optional(), totalPriceBreakdown: z.record(z.string(), z.unknown()).nullable().optional(), totalPriceCents: z.number().int().nullable().optional(), rank: z.number().int().nullable().optional(), price: z.number().nullable().optional(), isSuccessful: z.boolean().nullable().optional(), errorMessage: z.string().nullable().optional(), errorCode: z.string().nullable().optional(), errorDetails: z.record(z.string(), z.unknown()).nullable().optional()}); export const refreshOrderQuotesOutputExample = z.object({quotes: z.array(quoteSerializer)}); 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 }; /** * Refresh order quotes * * POST /v1/order/refresh_quotes */ export const createApiV1OrderRefreshQuotes = async (args: CreateApiV1OrderRefreshQuotesArgs, options?: CreateApiV1OrderRefreshQuotesOptions) => { const {baseUrl = "https://api.sandbox.usenash.com", 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(/\/+$/, '')}/v1/order/refresh_quotes${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(refreshOrderQuotesOutputExample, await res.json()) };