import {z} from 'zod' export type RecurringCharge = {id?: string | undefined, integration?: string | undefined, name?: (string | null) | undefined, srcId?: (string | null) | undefined, apiClientId?: (string | null) | undefined, price?: (number | null) | undefined, status?: (string | null) | undefined, returnUrl?: (string | null) | undefined, billingDate?: (string | null) | undefined, created?: (string | null) | undefined, modified?: (string | null) | undefined, activationDate?: (string | null) | undefined, cancellationDate?: (string | null) | undefined, trialDays?: (number | null) | undefined, trialEndsOn?: (string | null) | undefined, decoratedReturnUrl?: (string | null) | undefined}; export type UpdateApiRecurringChargesIdArgs = {id: string, body: RecurringCharge}; export type UpdateApiRecurringChargesIdOptions = {baseUrl?: string | undefined, BasicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const recurringCharge = z.object({id: z.string().optional(), integration: z.string().optional(), name: z.string().nullable().optional(), srcId: z.string().nullable().optional(), apiClientId: z.string().nullable().optional(), price: z.number().int().nullable().optional(), status: z.string().nullable().optional(), returnUrl: z.string().nullable().optional(), billingDate: z.string().nullable().optional(), created: z.string().nullable().optional(), modified: z.string().nullable().optional(), activationDate: z.string().nullable().optional(), cancellationDate: z.string().nullable().optional(), trialDays: z.number().int().nullable().optional(), trialEndsOn: z.string().nullable().optional(), decoratedReturnUrl: 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 }; /** * Replaces the RecurringCharge resource. * * PUT /recurring_charges/{id} */ export const updateApiRecurringChargesId = async (args: UpdateApiRecurringChargesIdArgs, options?: UpdateApiRecurringChargesIdOptions) => { const {baseUrl = "https://example.myintranetapps.com/api", fetch: fetchFn = fetch, BasicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BasicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${BasicAuth.username}:${BasicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/recurring_charges/${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(recurringCharge, await res.json()) };