import {z} from 'zod' export type ProductsVariantParametersUpdate = {name?: string | undefined, description?: (string | null) | undefined, sku?: (string | null) | undefined, product_type?: string | undefined, out_of_stock_sales?: (boolean | null) | undefined, weight?: (number | null) | undefined, weight_unit?: string | undefined, height?: (number | null) | undefined, width?: (number | null) | undefined, length?: (number | null) | undefined, dimensions_unit?: (string | null) | undefined, tax_category_id?: (string | null) | undefined, taxable?: (string | null) | undefined, track_quantity?: (boolean | null) | undefined, archived?: (boolean | null) | undefined, visible?: (boolean | null) | undefined, fulfillment_required?: (boolean | null) | undefined, country_of_manufacture_id?: (string | null) | undefined, image_ids?: (Array | null) | undefined, fulfillments_location_ids?: (Array | null) | undefined, properties_values?: (Array<{property_id?: number | undefined, value?: string | undefined}>) | undefined, has_access_to_all_valid_assets?: (boolean | null) | undefined, asset_ids?: (Array | null) | undefined, included_courses_attributes?: (Array<{id?: number | undefined, _destroy?: boolean | undefined, course_id?: number | undefined, included_sections_attributes?: (Array<{id?: number | undefined, _destroy?: boolean | undefined, courses_section_id?: number | undefined}>) | undefined}>) | undefined, included_space_groups_attributes?: (Array<{id?: number | undefined, _destroy?: boolean | undefined, communities_space_group_id?: number | undefined}>) | undefined}; export type UpdateApiProductsVariantsIdArgs = {id: string, body: {products_variant?: ProductsVariantParametersUpdate | undefined}}; export type UpdateApiProductsVariantsIdOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const productsVariantAttributes = z.object({id: z.number().int().optional(), public_id: z.string().nullable().optional(), product_id: z.number().int().optional(), name: z.string().optional(), description: z.string().nullable().optional(), sku: z.string().nullable().optional(), product_type: z.enum(["physical", "digital"]).optional(), properties_value_ids: z.array(z.unknown()).nullable().optional(), out_of_stock_sales: z.string().nullable().optional(), weight: z.number().nullable().optional(), weight_unit: z.string().optional(), height: z.number().nullable().optional(), width: z.number().nullable().optional(), length: z.number().nullable().optional(), dimensions_unit: z.string().nullable().optional(), quantity: z.number().int().nullable().optional(), tag_ids: z.array(z.unknown()).nullable().optional(), tax_category_id: z.string().nullable().optional(), asset_ids: z.array(z.number().int()).nullable().optional(), has_access_to_all_valid_assets: z.boolean().nullable().optional(), included_courses: z.array(z.object({id: z.number().int().optional(), course_id: z.number().int().optional(), full_access: z.boolean().optional(), included_section_ids: z.array(z.number().int()).optional()})).nullable().optional(), included_space_groups: z.array(z.object({id: z.number().int().optional(), communities_space_group_id: z.number().int().optional(), spaces_mode: z.string().optional(), included_space_ids: z.array(z.number().int()).optional()})).nullable().optional(), taxable: z.string().nullable().optional(), track_quantity: z.boolean().nullable().optional(), archived: z.boolean().nullable().optional(), visible: z.boolean().nullable().optional(), price_ids: z.array(z.unknown()).nullable().optional(), fulfillment_required: z.boolean().nullable().optional(), country_of_manufacture_id: z.string().nullable().optional(), image_ids: z.array(z.unknown()).nullable().optional(), fulfillments_location_ids: z.array(z.unknown()).nullable().optional(), created_at: z.string().nullable().optional(), updated_at: z.string().nullable().optional(), default: z.boolean().nullable().optional(), properties_values: z.array(z.object({property_id: z.number().int().nullable().optional(), value: z.string().nullable().optional()})).nullable().optional(), created_by_platform_application: z.object({public_id: z.string().optional(), trusted_skus: z.array(z.string()).optional()}).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 Variant * * PUT /products/variants/{id} * * Also accepts auth: OAuth2 */ export const updateApiProductsVariantsId = async (args: UpdateApiProductsVariantsIdArgs, options?: UpdateApiProductsVariantsIdOptions) => { const {baseUrl = "https://myworkspace.myclickfunnels.com/api/v2", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/products/variants/${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(productsVariantAttributes, await res.json()) };