import {z} from 'zod' export type QPilotCoreModelsWeightUnitType = 'Pound' | 'Ounce' | 'Kilogram' | 'Gram'; export type QPilotCoreModelsLengthUnitType = 'Inch' | 'Foot' | 'Yard' | 'Milimeter' | 'Centimeter' | 'Meter'; export type QPilotCoreModelsAvailability = 'Undefined' | 'InStock' | 'OutOfStock' | 'Preorder'; export type QPilotCoreModelsFrequencyType = 'Days' | 'Weeks' | 'Months' | 'DayOfTheWeek' | 'DayOfTheMonth'; export type QPilotCoreModelsFrequencyTypeValues = {frequencyType?: QPilotCoreModelsFrequencyType | undefined, displayName?: (string | null) | undefined, value?: number | undefined}; export type QPilotCoreModelsDtoRequestsPostPutProductDto = {id: string, title: string, price: number, parentProductId?: (string | null) | undefined, sku?: (string | null) | undefined, gtin?: (string | null) | undefined, mpn?: (string | null) | undefined, description?: (string | null) | undefined, salePrice?: (number | null) | undefined, length?: (string | null) | undefined, width?: (string | null) | undefined, height?: (string | null) | undefined, weight?: (string | null) | undefined, weightUnitType?: QPilotCoreModelsWeightUnitType | undefined, lengthUnitType?: QPilotCoreModelsLengthUnitType | undefined, shippingClass?: (string | null) | undefined, taxClass?: (string | null) | undefined, addToScheduledOrder?: boolean | undefined, processScheduledOrder?: boolean | undefined, availability?: QPilotCoreModelsAvailability | undefined, stock?: (number | null) | undefined, productGroupIds?: (Array | null) | undefined, availableFrequencies?: (Array | null) | undefined, backordersAllowed?: (boolean | null) | undefined, metadata?: ({[key: string]: unknown} | null) | undefined, active?: (boolean | null) | undefined, valid?: (boolean | null) | undefined, syncOnUpdate?: (boolean | null) | undefined}; export type UpdateApiSitesSiteIdProductsIdArgs = {siteId: number, id: string, body: QPilotCoreModelsDtoRequestsPostPutProductDto}; export type UpdateApiSitesSiteIdProductsIdOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const qPilotCoreModelsProductValidationErrorCode = z.union([z.literal(1), z.literal(2), z.literal(3), z.literal(4)]); export const qPilotCoreModelsWeightUnitType = z.enum(["Pound", "Ounce", "Kilogram", "Gram"]); export const qPilotCoreModelsLengthUnitType = z.enum(["Inch", "Foot", "Yard", "Milimeter", "Centimeter", "Meter"]); export const qPilotCoreModelsAvailability = z.enum(["Undefined", "InStock", "OutOfStock", "Preorder"]); 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 qPilotCoreModelsDtoEntitiesProductDto: z.ZodType = z.object({productId: z.number().int().optional(), siteId: z.number().int().optional(), parentProduct: z.lazy(() => qPilotCoreModelsDtoEntitiesProductDto.optional()), createdUtc: z.string().optional(), updatedUtc: z.string().optional(), lifetimeValue: z.number().nullable().optional(), validationErrorCode: qPilotCoreModelsProductValidationErrorCode.optional(), syncOnUpdate: z.boolean().nullable().optional(), imageUrl: z.string().nullable().optional(), id: z.string().max(50), title: z.string().max(200), price: z.number(), parentProductId: z.string().nullable().optional(), sku: z.string().max(50).nullable().optional(), gtin: z.string().max(50).nullable().optional(), mpn: z.string().max(70).nullable().optional(), description: z.string().nullable().optional(), salePrice: z.number().nullable().optional(), length: z.string().max(10).nullable().optional(), width: z.string().max(10).nullable().optional(), height: z.string().max(10).nullable().optional(), weight: z.string().max(10).nullable().optional(), weightUnitType: qPilotCoreModelsWeightUnitType.optional(), lengthUnitType: qPilotCoreModelsLengthUnitType.optional(), shippingClass: z.string().max(100).nullable().optional(), taxClass: z.string().max(100).nullable().optional(), addToScheduledOrder: z.boolean().optional(), processScheduledOrder: z.boolean().optional(), availability: qPilotCoreModelsAvailability.optional(), stock: z.number().int().nullable().optional(), productGroupIds: z.array(z.number().int()).nullable().optional(), availableFrequencies: z.array(qPilotCoreModelsFrequencyTypeValues).nullable().optional(), backordersAllowed: z.boolean().nullable().optional(), metadata: z.record(z.string(), z.unknown()).nullable().optional(), active: z.boolean().nullable().optional(), valid: z.boolean().nullable().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 Product * * PUT /Sites/{siteId}/Products/{id} */ export const updateApiSitesSiteIdProductsId = async (args: UpdateApiSitesSiteIdProductsIdArgs, options?: UpdateApiSitesSiteIdProductsIdOptions) => { 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.siteId))}/Products/${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(qPilotCoreModelsDtoEntitiesProductDto, await res.json()) };