import {z} from 'zod' export type GetApiCrbsCrbIdCustomersCustomerIdArgs = {crb_id: string, customer_id: string}; export type GetApiCrbsCrbIdCustomersCustomerIdOptions = {baseUrl?: string | undefined, accessAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const uUID = z.string(); export const friendlyPosName = z.enum(["Alleaves", "Apex Trading Wholesale", "Dutchie", "Dutchie Wholesale", "Cova", "Meadow", "MJ Freeway", "MJ Freeway Wholesale", "Greenbits", "GrowFlow", "GrowFlow Wholesale", "Portal42", "Metrc S2S", "Metrc S2S Wholesale", "Flourish", "Flourish Wholesale", "Flowhub", "BioTrack", "BioTrack Wholesale", "Treez", "Blaze", "Quickbooks", "Sage Intacct", "Canix", "Brytemap", "POSaBIT", "Proteus420", "IndicaOnline", "Sweed", "Weave", "Jane", "Manual Upload Wholesale", "Cova Test Account", "Leaf Logix Test Account", "BioTrack Test Account", "Mj Freeway Test Account", "Treez IO Test Account", "Green Bits Test Account", "Manual Upload Retail", "SFTP Sales Retail", "SFTP Sales Wholesale", "Not Configured", "Unsupported", "CRBMonitor", "Plaid"]); export const gender = z.enum(["Male", "Female", "Other"]); export const medicalOrRec = z.enum(["medical", "rec"]); export const positiveDouble = z.number().gte(0); export const customer = z.object({crb_id: uUID, id: uUID, pos_type: friendlyPosName, pos_customer_id: z.string(), first_name: z.string().nullable(), last_name: z.string().nullable(), middle_name: z.string().nullable(), dob: z.string().nullable(), address_1: z.string().nullable(), address_2: z.string().nullable(), city: z.string().nullable(), state: z.string().nullable(), zip_code: z.string().nullable(), phone: z.string().nullable(), cell_phone: z.string().nullable(), email_address: z.string().nullable(), gender: gender.nullable(), pos_identification_type: z.string().nullable(), pos_customer_type: z.string().nullable(), gc_customer_type: medicalOrRec.nullable(), medical_id: z.string().nullable(), medical_id_expiration_date: z.string().nullable(), drivers_license_id: z.string().nullable(), drivers_license_expiration_date: z.string().nullable(), other_id: z.string().nullable(), other_id_expiration_date: z.string().nullable(), caregiver: z.boolean().nullable(), loyalty_member: z.boolean().nullable(), loyalty_points: positiveDouble.nullable(), anonymous: z.boolean().nullable(), pos_updated_date: z.string().nullable(), pos_updated_date_local: z.string().nullable(), gc_updated_date: z.string().nullable(), gc_created_date: 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 }; /** * Get CRB customer record by ID * * GET /crbs/{crb_id}/customers/{customer_id} */ export const getApiCrbsCrbIdCustomersCustomerId = async (args: GetApiCrbsCrbIdCustomersCustomerIdArgs, options?: GetApiCrbsCrbIdCustomersCustomerIdOptions) => { const {baseUrl = "https://sandbox-api.greencheckverified.com", fetch: fetchFn = fetch, accessAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (accessAuth !== undefined) headers.set("Authorization", accessAuth) const url = `${baseUrl.replace(/\/+$/, '')}/crbs/${encodeURIComponent(String(args.crb_id))}/customers/${encodeURIComponent(String(args.customer_id))}${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(customer, await res.json()) };