import {z} from 'zod' export type UpdateApiCheckoutsCheckoutCodeArgs = {checkout_code: string, 'X-Idempotency-Key'?: string | undefined, body: {config?: ({payment_methods?: (Array<{payment_method_type?: string | undefined, order_to_show?: number | undefined, is_active?: boolean | undefined, active_enrollment_type?: ('ENROLLMENT' | 'NO_ENROLLMENT' | 'BOTH' | 'NONE') | undefined, conditions_to_override?: Array> | undefined, required_fields_to_override?: ({is_active?: boolean | undefined, fields?: Array> | undefined, enrollment_fields?: Array> | undefined, is_enrollment_active?: boolean | undefined}) | undefined}>) | undefined, general_settings?: ({country_documents?: (Array<{country_code?: string | undefined, documents?: Array | undefined}>) | undefined}) | undefined}) | undefined, styling?: ({styles?: Record | undefined, settings?: ({card?: ({save_on_success?: boolean | undefined, visualization_mode?: string | undefined, enable_ocr?: boolean | undefined, credit_card_only_processing?: boolean | undefined, enable_payment_retry?: boolean | undefined, default_network?: string | undefined}) | undefined, sdk_type?: Record | undefined, web_sdk?: Record | undefined, payment_method_list?: Record | undefined, ui?: Record | undefined}) | undefined, flags?: ({force_default_styles?: boolean | undefined}) | undefined, external_fonts?: Array> | undefined, payment_link_styles?: Record | undefined}) | undefined}}; export type UpdateApiCheckoutsCheckoutCodeOptions = {baseUrl?: string | undefined, publicApiKey?: string | undefined, privateSecretKey?: string | undefined, fetch?: typeof fetch | undefined}; export const updateApiCheckoutsCheckoutCodeResponse = z.object({}); 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 }; /** * Publish Checkout Configuration * * PUT /checkouts/{checkout_code} */ export const updateApiCheckoutsCheckoutCode = async (args: UpdateApiCheckoutsCheckoutCodeArgs, options?: UpdateApiCheckoutsCheckoutCodeOptions) => { const {baseUrl = "https://api-sandbox.y.uno/v1", fetch: fetchFn = fetch, publicApiKey, privateSecretKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['X-Idempotency-Key'] != null) headers.set("X-Idempotency-Key", String(args['X-Idempotency-Key'])) if (publicApiKey !== undefined) headers.set("PUBLIC-API-KEY", publicApiKey) if (privateSecretKey !== undefined) headers.set("PRIVATE-SECRET-KEY", privateSecretKey) const url = `${baseUrl.replace(/\/+$/, '')}/checkouts/${encodeURIComponent(String(args.checkout_code))}${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(updateApiCheckoutsCheckoutCodeResponse, await res.json()) };