import {z} from 'zod' export type GetApiApiZapierTriggersOrdersNewArgs = {limit?: number | undefined}; export type GetApiApiZapierTriggersOrdersNewOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const customer = z.object({id: z.string().optional(), name: z.string().optional(), email: z.string().optional(), phone: z.string().nullable().optional()}); export const orderItem = z.object({id: z.string().optional(), productId: z.string().optional(), quantity: z.number().int().gte(1).optional(), unitPrice: z.string().optional(), totalPrice: z.string().optional()}); export const order = z.object({id: z.string().optional(), orderNumber: z.string().optional(), totalAmount: z.string().optional(), status: z.enum(["pending", "confirmed", "shipped", "delivered", "cancelled"]).optional(), paymentMethod: z.string().optional(), notes: z.string().nullable().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional(), customer: customer.optional(), items: z.array(orderItem).optional()}); export const getApiApiZapierTriggersOrdersNewResponse = z.array(order); 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 New Orders * * GET /api/zapier/triggers/orders/new */ export const getApiApiZapierTriggersOrdersNew = async (args: GetApiApiZapierTriggersOrdersNewArgs, options?: GetApiApiZapierTriggersOrdersNewOptions) => { const {baseUrl = "https://www.ordavia.com", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.limit != null) query.append("limit", String(args.limit)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/zapier/triggers/orders/new${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(getApiApiZapierTriggersOrdersNewResponse, await res.json()) };