import {z} from 'zod' export type PublicRestrictedFeature = 'international_payments'; export type InternationalMonthlyVolume = 'less_than_10k' | 'from_10k_to_25k' | 'from_25k_to_100k' | 'from_100k_to_500k' | 'over_500k'; export type InternationalMonthlyPaymentCount = 'ten_or_fewer' | 'from_11_to_20' | 'from_21_to_30' | 'from_31_to_40' | 'over_40'; export type InternationalPaymentPurpose = 'supplier_payments' | 'payroll' | 'customer_refunds' | 'other'; export type InternationalPaymentsEligibility = {monthly_volume: InternationalMonthlyVolume, monthly_payment_count: InternationalMonthlyPaymentCount, purposes?: (Array | null) | undefined, other_purpose?: (string | null) | undefined, countries_served: Array}; export type RequestFeatureAccessRequest = {feature: PublicRestrictedFeature, eligibility: InternationalPaymentsEligibility}; export type CreateApiFeatureAccessRequestsArgs = {'x-entity-id'?: string | undefined, body: RequestFeatureAccessRequest}; export type CreateApiFeatureAccessRequestsOptions = {baseUrl?: string | undefined, apiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const publicRestrictedFeature = z.literal("international_payments"); export const publicFeatureAccessStatus = z.enum(["pending", "approved", "rejected"]); export const publicFeatureAccessRequestResponse = z.object({feature: publicRestrictedFeature, status: publicFeatureAccessStatus}); 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 }; /** * Request access to a restricted feature * * POST /feature-access/requests */ export const createApiFeatureAccessRequests = async (args: CreateApiFeatureAccessRequestsArgs, options?: CreateApiFeatureAccessRequestsOptions) => { const {baseUrl = "https://api.meow.com/v1", fetch: fetchFn = fetch, apiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['x-entity-id'] != null) headers.set("x-entity-id", String(args['x-entity-id'])) if (apiKeyAuth !== undefined) headers.set("x-api-key", apiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/feature-access/requests${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(publicFeatureAccessRequestResponse, await res.json()) };