import {z} from 'zod' export type UpdateApiPlansPlanIdArgs = {plan_id: string, body: {name: string, description?: string | undefined, currency: string, interval: string, interval_count: number, billing_type: string, billing_days?: Array | undefined, installments?: Array | undefined, statement_descriptor?: string | undefined, minimum_price?: number | undefined, status: string, shippable?: boolean | undefined, payment_methods: Array, trial_period_days?: number | undefined, metadata?: Record | undefined}}; export type UpdateApiPlansPlanIdOptions = {baseUrl?: string | undefined, sec0?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const updateApiPlansPlanIdResponse = z.object({id: z.string().optional(), name: z.string().optional(), description: z.string().optional(), url: z.string().optional(), currency: z.string().optional(), interval: z.string().optional(), interval_count: z.number().int().optional(), billing_type: z.string().optional(), installments: z.number().int().optional(), statement_descriptor: z.string().optional(), status: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), minimum_price: z.number().int().optional(), items: z.array(z.object({id: z.string().optional(), name: z.string().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()})).optional(), metadata: z.object({id: 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 }; /** * Editar plano * * PUT /plans/{plan_id} */ export const updateApiPlansPlanId = async (args: UpdateApiPlansPlanIdArgs, options?: UpdateApiPlansPlanIdOptions) => { 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(/\/+$/, '')}/plans/${encodeURIComponent(String(args.plan_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(updateApiPlansPlanIdResponse, await res.json()) };