import {z} from 'zod' export type ProductsPriceParametersUpdate = {name?: (string | null) | undefined, amount?: string | undefined, cost?: (string | null) | undefined, currency?: string | undefined, duration?: (number | null) | undefined, interval?: ('days' | 'weeks' | 'months' | 'quarters' | 'years' | 'null' | null) | undefined, trial_interval?: ('days' | 'weeks' | 'months' | 'quarters' | 'years' | 'null' | null) | undefined, trial_duration?: (number | null) | undefined, trial_amount?: (string | null) | undefined, setup_amount?: (string | null) | undefined, self_cancel?: (boolean | null) | undefined, self_upgrade?: (boolean | null) | undefined, self_downgrade?: (boolean | null) | undefined, self_reactivate?: (boolean | null) | undefined, interval_count?: (number | null) | undefined, payment_type?: ('one_time' | 'subscription' | 'payment_plan' | 'null' | null) | undefined, visible?: (boolean | null) | undefined, compare_at_amount?: (string | null) | undefined, key?: (string | null) | undefined, archived?: (boolean | null) | undefined}; export type UpdateApiProductsPricesIdArgs = {id: string, body: {products_price?: ProductsPriceParametersUpdate | undefined}}; export type UpdateApiProductsPricesIdOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const productsPriceAttributes = z.object({id: z.number().int().optional(), public_id: z.string().nullable().optional(), variant_id: z.number().int().nullable().optional(), name: z.string().nullable().optional(), amount: z.string().optional(), cost: z.string().nullable().optional(), currency: z.string().optional(), duration: z.number().int().nullable().optional(), interval: z.string().nullable().optional(), trial_interval: z.string().nullable().optional(), trial_duration: z.number().int().nullable().optional(), trial_amount: z.string().optional(), setup_amount: z.string().nullable().optional(), self_cancel: z.boolean().nullable().optional(), self_upgrade: z.boolean().nullable().optional(), self_downgrade: z.boolean().nullable().optional(), self_reactivate: z.boolean().nullable().optional(), interval_count: z.number().int().nullable().optional(), payment_type: z.enum(["one_time", "subscription", "payment_plan", "null"]).nullable().optional(), visible: z.boolean().nullable().optional(), compare_at_amount: z.string().nullable().optional(), key: z.string().nullable().optional(), archived: z.boolean().nullable().optional(), created_at: z.string().nullable().optional(), updated_at: z.string().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 Price * * PUT /products/prices/{id} * * Also accepts auth: OAuth2 */ export const updateApiProductsPricesId = async (args: UpdateApiProductsPricesIdArgs, options?: UpdateApiProductsPricesIdOptions) => { 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/prices/${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(productsPriceAttributes, await res.json()) };