import {z} from 'zod' export type Subscription = {id?: string | undefined, integration?: string | undefined, srcId?: string | undefined, status?: (boolean | null) | undefined, balance?: (number | null) | undefined, totalRevenue?: (number | null) | undefined, productPrice?: (number | null) | undefined, currencyCode?: (string | null) | undefined, currentPeriodStart?: (string | null) | undefined, currentPeriodEnd?: (string | null) | undefined, nextPeriodStart?: (string | null) | undefined, cancelAtEndOfPeriod?: (boolean | null) | undefined, signupId?: (string | null) | undefined, signupRevenue?: (string | null) | undefined, couponCode?: (string | null) | undefined, customerId?: (string | null) | undefined, productId?: (string | null) | undefined, creditCardId?: (string | null) | undefined, created?: (string | null) | undefined, modified?: (string | null) | undefined, customerFirstName?: (string | null) | undefined, customerLastName?: (string | null) | undefined, startDate?: (string | null) | undefined, endDate?: (string | null) | undefined, planName?: (string | null) | undefined, activated?: (string | null) | undefined, remainingIntervals?: (number | null) | undefined, monthlyRevenue?: (number | null) | undefined, netMonthlyRevenue?: (number | null) | undefined, contractStartDate?: (string | null) | undefined, expiredTimestamp?: (string | null) | undefined, planInterval?: (string | null) | undefined, numOfIntervals?: (number | null) | undefined}; export type UpdateApiSubscriptionsIdArgs = {id: string, body: Subscription}; export type UpdateApiSubscriptionsIdOptions = {baseUrl?: string | undefined, BasicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const subscription = z.object({id: z.string().optional(), integration: z.string().optional(), srcId: z.string().optional(), status: z.boolean().nullable().optional(), balance: z.number().int().nullable().optional(), totalRevenue: z.number().int().nullable().optional(), productPrice: z.number().int().nullable().optional(), currencyCode: z.string().nullable().optional(), currentPeriodStart: z.string().nullable().optional(), currentPeriodEnd: z.string().nullable().optional(), nextPeriodStart: z.string().nullable().optional(), cancelAtEndOfPeriod: z.boolean().nullable().optional(), signupId: z.string().nullable().optional(), signupRevenue: z.string().nullable().optional(), couponCode: z.string().nullable().optional(), customerId: z.string().nullable().optional(), productId: z.string().nullable().optional(), creditCardId: z.string().nullable().optional(), created: z.string().nullable().optional(), modified: z.string().nullable().optional(), customerFirstName: z.string().nullable().optional(), customerLastName: z.string().nullable().optional(), startDate: z.string().nullable().optional(), endDate: z.string().nullable().optional(), planName: z.string().nullable().optional(), activated: z.string().nullable().optional(), remainingIntervals: z.number().int().nullable().optional(), monthlyRevenue: z.number().int().nullable().optional(), netMonthlyRevenue: z.number().int().nullable().optional(), contractStartDate: z.string().nullable().optional(), expiredTimestamp: z.string().nullable().optional(), planInterval: z.string().nullable().optional(), numOfIntervals: z.number().int().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 Subscription resource. * * PUT /subscriptions/{id} */ export const updateApiSubscriptionsId = async (args: UpdateApiSubscriptionsIdArgs, options?: UpdateApiSubscriptionsIdOptions) => { 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(/\/+$/, '')}/subscriptions/${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(subscription, await res.json()) };