import {z} from 'zod' export type CreateApiV1JobsJobIdTasksTaskIdRefreshQuotesArgs = {jobId: string, taskId: string}; export type CreateApiV1JobsJobIdTasksTaskIdRefreshQuotesOptions = {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 refreshQuotesOutputSerializer = z.object({jobId: z.string(), 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 Quotes by Job ID and Task ID * * POST /v1/jobs/{jobId}/tasks/{taskId}/refresh_quotes */ export const createApiV1JobsJobIdTasksTaskIdRefreshQuotes = async (args: CreateApiV1JobsJobIdTasksTaskIdRefreshQuotesArgs, options?: CreateApiV1JobsJobIdTasksTaskIdRefreshQuotesOptions) => { const {baseUrl = "https://api.sandbox.usenash.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v1/jobs/${encodeURIComponent(String(args.jobId))}/tasks/${encodeURIComponent(String(args.taskId))}/refresh_quotes${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(refreshQuotesOutputSerializer, await res.json()) };