import {z} from 'zod' export type GetApiAppResellerV1PaymentMethodsArgs = {ownerId: string, companyId: string, number?: number | undefined, size?: number | undefined, paymentMethodType?: string | undefined}; export type GetApiAppResellerV1PaymentMethodsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const pageMetadata = z.object({number: z.number(), size: z.number(), totalElements: z.number(), totalPages: z.number()}); export const billingAddress = z.object({street1: z.string(), street2: z.string().nullable().optional(), city: z.string(), country: z.string(), state: z.string(), zip: z.string(), phone: z.string().nullable().optional(), salutation: z.string().nullable().optional(), companyName: z.string().nullable().optional(), fax: z.string().nullable().optional(), faxExtension: z.string().nullable().optional(), poBox: z.string().nullable().optional()}); export const userAssociation = z.object({id: z.string(), firstName: z.string(), lastName: z.string()}); export const appResellerPaymentMethod = z.object({id: z.string(), accountDisplay: z.string().optional(), default: z.boolean(), paymentMethodType: z.string(), properties: z.record(z.string(), z.string()).optional(), billingAddress: billingAddress, owner: userAssociation}); export const appResellerPaymentMethodPagedReadResponse = z.object({page: pageMetadata, content: z.array(appResellerPaymentMethod)}); 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 }; /** * List payment methods * * GET /appReseller/v1/paymentMethods */ export const getApiAppResellerV1PaymentMethods = async (args: GetApiAppResellerV1PaymentMethodsArgs, options?: GetApiAppResellerV1PaymentMethodsOptions) => { const {baseUrl = "https://marketplace.appdirect.com/api", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.ownerId != null) query.append("ownerId", String(args.ownerId)) if (args.companyId != null) query.append("companyId", String(args.companyId)) if (args.number != null) query.append("number", String(args.number)) if (args.size != null) query.append("size", String(args.size)) if (args.paymentMethodType != null) query.append("paymentMethodType", String(args.paymentMethodType)) const url = `${baseUrl.replace(/\/+$/, '')}/appReseller/v1/paymentMethods${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(appResellerPaymentMethodPagedReadResponse, await res.json()) };