import {z} from 'zod' export type GetApiSitesSiteIdScheduledOrdersHistoryArgs = {siteId: number, startDate?: string | undefined, endDate?: string | undefined, page?: number | undefined, pageSize?: number | undefined, orderBy?: string | undefined, order?: string | undefined}; export type GetApiSitesSiteIdScheduledOrdersHistoryOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const qPilotCoreModelsFrequencyType = z.enum(["Days", "Weeks", "Months", "DayOfTheWeek", "DayOfTheMonth"]); export const qPilotCoreModelsScheduledTaskStatus = z.enum(["Processing", "Success", "Failed", "Retry", "Active", "Paused", "Deleted", "Queued", "Snoozed"]); export const qPilotCoreModelsDtoResponsesScheduledOrderHistoryItemDto = z.object({createdUtc: z.string().optional(), source: z.string().nullable().optional(), referrer: z.string().nullable().optional(), id: z.number().int().optional(), originalExternalId: z.string().nullable().optional(), customerId: z.number().int().optional(), customerEmail: z.string().nullable().optional(), frequencyType: qPilotCoreModelsFrequencyType.optional(), frequency: z.number().int().optional(), cycles: z.number().int().optional(), subtotal: z.number().nullable().optional(), avgSubtotal: z.number().nullable().optional(), lifetimeValue: z.number().optional(), lastPausedDate: z.string().nullable().optional(), deletedDate: z.string().nullable().optional(), lastOccurrenceUtc: z.string().nullable().optional(), status: qPilotCoreModelsScheduledTaskStatus.optional(), origin: z.string().nullable().optional()}); export const qPilotCoreModelsDtoResponsesScheduledOrdersHistoryDto = z.object({scheduledOrderHistoryItems: z.array(qPilotCoreModelsDtoResponsesScheduledOrderHistoryItemDto).nullable().optional(), count: z.number().int().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 }; /** * GET /Sites/{siteId}/ScheduledOrdersHistory */ export const getApiSitesSiteIdScheduledOrdersHistory = async (args: GetApiSitesSiteIdScheduledOrdersHistoryArgs, options?: GetApiSitesSiteIdScheduledOrdersHistoryOptions) => { const {baseUrl = "https://api.qpilot.cloud", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.startDate != null) query.append("startDate", String(args.startDate)) if (args.endDate != null) query.append("endDate", String(args.endDate)) if (args.page != null) query.append("page", String(args.page)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.orderBy != null) query.append("orderBy", String(args.orderBy)) if (args.order != null) query.append("order", String(args.order)) if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/Sites/${encodeURIComponent(String(args.siteId))}/ScheduledOrdersHistory${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(qPilotCoreModelsDtoResponsesScheduledOrdersHistoryDto, await res.json()) };