import {z} from 'zod' export type GetApiServiceProvidersSpIdCrbsArgs = {sp_id: string}; export type GetApiServiceProvidersSpIdCrbsOptions = {baseUrl?: string | undefined, accessAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const uUID = z.string(); export const city = z.string(); export const eIN = z.string(); export const phoneNumber = z.string(); export const postalCode = z.string(); export const uSStates = z.enum(["AL", "AK", "AZ", "AR", "AS", "CA", "CO", "CT", "DE", "DC", "FM", "FL", "GA", "GU", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD", "MA", "MH", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "MP", "OH", "OK", "OR", "PW", "PA", "PR", "RI", "SC", "SD", "TN", "TX", "UM", "UT", "VT", "VA", "VI", "WA", "WV", "WI", "WY", "AA", "AE", "AP"]); export const website = z.string(); export const iANATimezones = z.enum(["America/New_York", "America/Detroit", "America/Kentucky/Louisville", "America/Kentucky/Monticello", "America/Indiana/Indianapolis", "America/Indiana/Vincennes", "America/Indiana/Winamac", "America/Indiana/Marengo", "America/Indiana/Petersburg", "America/Indiana/Vevay", "America/Chicago", "America/Indiana/Tell_City", "America/Indiana/Knox", "America/Menominee", "America/North_Dakota/Center", "America/North_Dakota/New_Salem", "America/North_Dakota/Beulah", "America/Denver", "America/Boise", "America/Phoenix", "America/Los_Angeles", "America/Anchorage", "America/Juneau", "America/Puerto_Rico", "America/Sitka", "America/St_Thomas", "America/Metlakatla", "America/Yakutat", "America/Nome", "America/Adak", "Pacific/Honolulu", "Pacific/Guam", "Pacific/Kosrae", "Pacific/Midway", "Pacific/Pago_Pago", "Pacific/Palau", "Pacific/Kwajalein", "Pacific/Saipan"]); export const shortDate = z.string(); export const nullablePositiveInteger = z.number().int().gte(0).nullable(); export const entityType = z.enum(["sole", "partnership", "corporation", "llc"]); export const organizationType = z.enum(["bank", "dispensary", "gcv", "transport_vendor", "muo", "data_integrator_client"]); export const dispensaryBusinessType = z.enum(["retail", "wholesale"]); export const dueDiligenceStatus = z.enum(["bank_disconnected", "bank_approved", "bank_review_in_progress", "bank_awaiting_review", "bank_in_progress", "bank_pending", "gcv_approved", "gcv_awaiting_review", "gcv_in_progress", "gcv_pending", "update_required"]); 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 posConnectionStatus = z.enum(["Connected", "Not Connected", "Needs Attention", "Pending"]); export const utcDateTime = z.string(); export const accessPosConfig = z.object({name: friendlyPosName, status: posConnectionStatus.optional(), updated_date: utcDateTime}); export const accessCrb = z.object({id: uUID, name: z.string(), street_address: z.string(), street_address_2: z.string().nullable(), city: city.nullable(), ein: eIN.nullable(), phone_number: phoneNumber.nullable(), postal_code: postalCode.nullable(), country: z.string().nullable(), state: uSStates, website: website.nullable(), timezone: iANATimezones, mailing_street_address: z.string().nullable(), mailing_city: city.nullable(), mailing_state: uSStates.nullable(), mailing_postal_code: postalCode.nullable(), established_date: shortDate.nullable(), ftEmployees: nullablePositiveInteger, ptEmployees: nullablePositiveInteger, entityType: entityType.nullable(), dba: z.string().nullable(), monthlySales: z.string().nullable(), monthlyCustomers: nullablePositiveInteger, org_type: organizationType, business_type: dispensaryBusinessType.nullable(), template_id: uUID, template_result_id: uUID, status: dueDiligenceStatus, pos_configs: z.array(accessPosConfig)}); export const serviceProviderCrbs = z.record(z.string(), accessCrb); 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 service provider CRBs * * GET /service-providers/{sp_id}/crbs */ export const getApiServiceProvidersSpIdCrbs = async (args: GetApiServiceProvidersSpIdCrbsArgs, options?: GetApiServiceProvidersSpIdCrbsOptions) => { 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(/\/+$/, '')}/service-providers/${encodeURIComponent(String(args.sp_id))}/crbs${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(serviceProviderCrbs, await res.json()) };