import {z} from 'zod' export type CreateApiSubscriptionsSubscriptionIdItemsArgs = {subscription_id: string, body: {plan_item_id?: string | undefined, description: string, cycles?: number | undefined, pricing_scheme?: Record | undefined, discounts?: Array | undefined, quantity: number, name?: string | undefined, increments?: Array | undefined}}; export type CreateApiSubscriptionsSubscriptionIdItemsOptions = {baseUrl?: string | undefined, sec0?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const createApiSubscriptionsSubscriptionIdItemsResponse = z.object({id: z.string().optional(), description: z.string().optional(), cycles: z.number().int().optional(), quantity: z.number().int().optional(), status: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), pricing_scheme: z.object({price: z.number().int().optional(), scheme_type: z.string().optional()}).optional(), subscription: z.object({id: z.string().optional(), code: z.string().optional(), start_at: z.string().optional(), interval: z.string().optional(), interval_count: z.number().int().optional(), billing_type: z.string().optional(), next_billing_at: z.string().optional(), payment_method: z.string().optional(), currency: z.string().optional(), installments: z.number().int().optional(), status: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), metadata: z.object({id: z.string().optional()}).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 }; /** * Incluir item * * POST /subscriptions/{subscription_id}/items */ export const createApiSubscriptionsSubscriptionIdItems = async (args: CreateApiSubscriptionsSubscriptionIdItemsArgs, options?: CreateApiSubscriptionsSubscriptionIdItemsOptions) => { const {baseUrl = "https://api.mundipagg.com/core/v1", fetch: fetchFn = fetch, sec0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (sec0 !== undefined) headers.set('authorization', `Basic ${btoa(`${sec0.username}:${sec0.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/subscriptions/${encodeURIComponent(String(args.subscription_id))}/items${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(createApiSubscriptionsSubscriptionIdItemsResponse, await res.json()) };