import {z} from 'zod' export type CustomerSer = {customer_id: string, email: string, first_name: string, last_name: string, reference?: (string | null) | undefined, address?: (string | null) | undefined, city?: (string | null) | undefined, state?: (string | null) | undefined, zipcode?: (string | null) | undefined, country?: ('KE' | 'GH' | 'NG' | 'UG' | 'TZ' | 'CM' | 'BF' | 'CI' | '' | unknown | null) | undefined, created_at: string | null, updated_at: string | null}; export type CreateApiApiV1SubscriptionsCustomersArgs = {body: CustomerSer}; export type CreateApiApiV1SubscriptionsCustomersOptions = {baseUrl?: string | undefined, IntaSendBearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const customerSer = z.object({customer_id: z.string(), email: z.string().max(254), first_name: z.string(), last_name: z.string(), reference: z.string().max(45).nullable().optional(), address: z.string().max(50).nullable().optional(), city: z.string().max(50).nullable().optional(), state: z.string().max(50).nullable().optional(), zipcode: z.string().max(10).nullable().optional(), country: z.union([z.enum(["KE", "GH", "NG", "UG", "TZ", "CM", "BF", "CI"]), z.literal(""), z.unknown()]).nullable().optional(), created_at: z.string().nullable(), updated_at: z.string().nullable()}); 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 }; /** * Create Subscriptions customers * * POST /api/v1/subscriptions-customers/ */ export const createApiApiV1SubscriptionsCustomers = async (args: CreateApiApiV1SubscriptionsCustomersArgs, options?: CreateApiApiV1SubscriptionsCustomersOptions) => { const {baseUrl = "https://api.intasend.com", fetch: fetchFn = fetch, IntaSendBearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (IntaSendBearerAuth !== undefined) headers.set('authorization', `Bearer ${IntaSendBearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/subscriptions-customers/${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(customerSer, await res.json()) };