import {z} from 'zod' export type GetApiAppMarketV2PaymentMethodsDefaultsArgs = {ownerId: string, companyId: string}; export type GetApiAppMarketV2PaymentMethodsDefaultsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const defaultPaymentMethod = z.object({paymentMethodId: z.string().max(255)}); export const getApiAppMarketV2PaymentMethodsDefaultsResponse = z.array(defaultPaymentMethod); 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 default payment methods * * GET /appMarket/v2/paymentMethods/defaults */ export const getApiAppMarketV2PaymentMethodsDefaults = async (args: GetApiAppMarketV2PaymentMethodsDefaultsArgs, options?: GetApiAppMarketV2PaymentMethodsDefaultsOptions) => { 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)) const url = `${baseUrl.replace(/\/+$/, '')}/appMarket/v2/paymentMethods/defaults${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(getApiAppMarketV2PaymentMethodsDefaultsResponse, await res.json()) };