import {z} from 'zod' export type QPilotCoreModelsProcessingErrorCode = 99 | 1000 | 1001 | 1002 | 1003 | 1004 | 1005 | 2000 | 2001 | 3000 | 3001 | 3002; export type QPilotCoreModelsEmailsMessageType = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10; export type QPilotCoreModelsEmailsScheduledOrderErrorCustomerTemplate = {id?: number | undefined, processingErrorCode: QPilotCoreModelsProcessingErrorCode, messageType: QPilotCoreModelsEmailsMessageType, emailSubject?: (string | null) | undefined, template?: (string | null) | undefined, bannerText?: (string | null) | undefined, beforeContent?: (string | null) | undefined, afterContent?: (string | null) | undefined, footer?: (string | null) | undefined}; export type QPilotCoreModelsEmailsSiteScheduledOrderErrorCustomerTemplate = {id?: number | undefined, siteId?: number | undefined, bannerText?: (string | null) | undefined, beforeContent?: (string | null) | undefined, afterContent?: (string | null) | undefined, footer?: (string | null) | undefined, emailSubject?: (string | null) | undefined, scheduledOrderErrorCustomerTemplateId?: number | undefined, scheduledOrderErrorCustomerTemplate?: QPilotCoreModelsEmailsScheduledOrderErrorCustomerTemplate | undefined, enabled: boolean}; export type QPilotCoreModelsWeightUnitType = 'Pound' | 'Ounce' | 'Kilogram' | 'Gram'; export type QPilotCoreModelsLengthUnitType = 'Inch' | 'Foot' | 'Yard' | 'Milimeter' | 'Centimeter' | 'Meter'; export type QPilotCoreModelsTimeUnitType = 'Minutes' | 'Hours' | 'Days'; export type QPilotCoreModulesSitesActionsUpdateSiteActionData = {url: string, baseUrlWebHook?: (string | null) | undefined, logoUrl?: (string | null) | undefined, name: string, email: string, apiKey1?: (string | null) | undefined, apiKey2?: (string | null) | undefined, apiKey3?: (string | null) | undefined, customerEmailSettings?: (Array | null) | undefined, zipCode?: (string | null) | undefined, isProduction?: boolean | undefined, orderProcessingStartTime?: (unknown | null) | undefined, orderProcessingEndTime?: (unknown | null) | undefined, orderProcessingOffset?: (number | null) | undefined, utcOffset?: (number | null) | undefined, lockDurationDays?: (number | null) | undefined, isShowingNotes?: boolean | undefined, isShowCoupons?: boolean | undefined, noScheduleOrdersBody?: (string | null) | undefined, noScheduleOrdersLink?: (string | null) | undefined, isStackedButtons?: boolean | undefined, isDisplayScheduledOrderId?: boolean | undefined, showProductTitleOnImages?: boolean | undefined, enableProductCarouselAutoSlide?: boolean | undefined, isProcessingPaused?: boolean | undefined, metadata?: ({[key: string]: unknown} | null) | undefined, defaultWeightUnitType?: QPilotCoreModelsWeightUnitType | undefined, defaultLengthUnitType?: QPilotCoreModelsLengthUnitType | undefined, phoneNumber?: (string | null) | undefined, scheduledOrdersClientPageUrl?: (string | null) | undefined, paymentMethodsPageUrl?: (string | null) | undefined, baseUrl?: (string | null) | undefined, createOrderEndpoint?: (string | null) | undefined, orderProcessedEndpoint?: (string | null) | undefined, failOrderEndpoint?: (string | null) | undefined, updateProductAvailabilityEndpoint?: (string | null) | undefined, healthCheckPostEndpoint?: (string | null) | undefined, healthCheckPutEndpoint?: (string | null) | undefined, repeatProcessingAllowedWindow?: (number | null) | undefined, repeatProcessingAllowedWindowUnitType?: QPilotCoreModelsTimeUnitType | undefined, subscriptionStatus?: (string | null) | undefined, subscriptionPaymentMethodDescription?: (string | null) | undefined, subscriptionProductHandle?: (string | null) | undefined, subscriptionNextBillingDate?: (string | null) | undefined, subscriptionId?: (string | null) | undefined, subscriptionUpdatedUtc?: (string | null) | undefined, currencyIso?: (string | null) | undefined, fallbackToQpilotShippingWhenNextimeFails?: boolean | undefined, applyUtcToExistingScheduledOrders?: boolean | undefined, applyProcessingTimesToExistingScheduledOrders?: boolean | undefined}; export type UpdateApiSitesIdArgs = {id: number, body: QPilotCoreModulesSitesActionsUpdateSiteActionData}; export type UpdateApiSitesIdOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const qPilotCoreModelsShippingCarrier = z.enum(["FlatRate", "USPS", "ShipperHQ"]); export const qPilotCoreModelsShippingIntegration = z.object({id: z.number().int().optional(), siteId: z.number().int().optional(), shippingCarrierType: qPilotCoreModelsShippingCarrier, apiKey1: z.string().max(64), apiKey2: z.string().max(64).nullable().optional(), apiKey3: z.string().max(64).nullable().optional(), apiKey4: z.string().max(64).nullable().optional(), isTest: z.boolean(), createdUtc: z.string().optional(), updatedUtc: z.string().optional()}); export const qPilotCoreModelsEmailsEmailTemplatesStyleSettings = z.object({logoBackgroundColor: z.string().nullable().optional(), bannerBackgroundColor: z.string().nullable().optional(), bannerFontColor: z.string().nullable().optional(), scheduledOrderTableColor: z.string().nullable().optional(), scheduledOrderFontColor: z.string().nullable().optional(), contentTableColor: z.string().nullable().optional(), bodyContainerBackgroundColor: z.string().nullable().optional(), contentBackgroundColor: z.string().nullable().optional(), contentFontColor: z.string().nullable().optional(), customStyles: z.string().nullable().optional()}); export const qPilotCoreModelsEmailsResourceStyleSettings = z.object({fontFamilyName: z.string().nullable().optional(), fontSize: z.string().nullable().optional(), fontColor: z.string().nullable().optional(), textClass: z.string().nullable().optional(), backgroundColor: z.string().nullable().optional(), borderColor: z.string().nullable().optional(), borderWidthPixels: z.string().nullable().optional(), containerClass: z.string().nullable().optional(), mainClass: z.string().nullable().optional(), customCss: z.string().nullable().optional()}); export const qPilotCoreModelsEmailsSiteThemingSettings = z.object({emailSettings: qPilotCoreModelsEmailsEmailTemplatesStyleSettings.optional(), resourcesStylesSettings: z.record(z.string(), qPilotCoreModelsEmailsResourceStyleSettings).nullable().optional(), notificationsComponentGeneralInformationAreaEnabled: z.boolean().optional()}); export const qPilotCoreModelsFrequencyType = z.enum(["Days", "Weeks", "Months", "DayOfTheWeek", "DayOfTheMonth"]); export const qPilotCoreModelsFrequencyTypeValues = z.object({frequencyType: qPilotCoreModelsFrequencyType.optional(), displayName: z.string().nullable().optional(), value: z.number().int().optional()}); export const qPilotCoreModelsWeightUnitType = z.enum(["Pound", "Ounce", "Kilogram", "Gram"]); export const qPilotCoreModelsLengthUnitType = z.enum(["Inch", "Foot", "Yard", "Milimeter", "Centimeter", "Meter"]); export const qPilotCoreModelsTimeUnitType = z.enum(["Minutes", "Hours", "Days"]); export const qPilotCoreModelsDtoEntitiesSiteDto = z.object({id: z.number().int().optional(), userId: z.number().int().optional(), url: z.string().nullable().optional(), baseUrlWebHook: z.string().nullable().optional(), scheduledOrdersClientPageUrl: z.string().nullable().optional(), paymentMethodsPageUrl: z.string().nullable().optional(), logoUrl: z.string().nullable().optional(), name: z.string().nullable().optional(), email: z.string().nullable().optional(), zipCode: z.string().nullable().optional(), shippingIntegrations: z.array(qPilotCoreModelsShippingIntegration).nullable().optional(), createdUtc: z.string().optional(), updatedUtc: z.string().optional(), isProduction: z.boolean().optional(), orderProcessingStartTime: z.string().nullable().optional(), orderProcessingEndTime: z.string().nullable().optional(), orderProcessingOffset: z.number().int().nullable().optional(), utcOffset: z.number().int().nullable().optional(), lockDurationDays: z.number().int().nullable().optional(), isShowingNotes: z.boolean().optional(), isShowCoupons: z.boolean().optional(), noScheduleOrdersBody: z.string().nullable().optional(), noScheduleOrdersLink: z.string().nullable().optional(), isStackedButtons: z.boolean().optional(), isDisplayScheduledOrderId: z.boolean().optional(), showProductTitleOnImages: z.boolean().optional(), enableProductCarouselAutoSlide: z.boolean().optional(), allowRetryScheduledOrder: z.boolean().optional(), isProcessingPaused: z.boolean().optional(), lastProcessingPausedUtc: z.string().nullable().optional(), failedConnectAttempts: z.number().int().optional(), hasActiveInvalidProducts: z.boolean().nullable().optional(), themingSettings: qPilotCoreModelsEmailsSiteThemingSettings.optional(), metadata: z.record(z.string(), z.unknown()).nullable().optional(), metadataJson: z.string().nullable().optional(), availableFrequencies: z.array(qPilotCoreModelsFrequencyTypeValues).nullable().optional(), defaultWeightUnitType: qPilotCoreModelsWeightUnitType.optional(), defaultLengthUnitType: qPilotCoreModelsLengthUnitType.optional(), phoneNumber: z.string().max(30).nullable().optional(), baseUrl: z.string().nullable().optional(), createOrderEndpoint: z.string().nullable().optional(), orderProcessedEndpoint: z.string().nullable().optional(), failOrderEndpoint: z.string().nullable().optional(), updateProductAvailabilityEndpoint: z.string().nullable().optional(), healthCheckPostEndpoint: z.string().nullable().optional(), healthCheckPutEndpoint: z.string().nullable().optional(), repeatProcessingAllowedWindow: z.number().int().nullable().optional(), repeatProcessingAllowedWindowUnitType: qPilotCoreModelsTimeUnitType.optional(), supportsProcessingWindow: z.boolean().optional(), active: z.boolean().optional(), currencyIso: z.string().nullable().optional(), fallbackToQpilotShippingWhenNextimeFails: z.boolean().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 }; /** * Update Site * * PUT /Sites/{id} */ export const updateApiSitesId = async (args: UpdateApiSitesIdArgs, options?: UpdateApiSitesIdOptions) => { const {baseUrl = "https://api.qpilot.cloud", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/Sites/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(qPilotCoreModelsDtoEntitiesSiteDto, await res.json()) };