import {z} from 'zod' export type PositiveInteger = number; export type EntityType = 'sole' | 'partnership' | 'corporation' | 'llc'; export type ShortDate = string; export type Website = string; export type PhoneNumber = string; export type EIN = string; export type PostalCode = string; export type USStates = '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 type City = string; export type Countries = 'Afghanistan' | 'Albania' | 'Algeria' | 'American Samoa' | 'Andorra' | 'Angola' | 'Anguilla' | 'Antigua & Barbuda' | 'Argentina' | 'Armenia' | 'Aruba' | 'Australia' | 'Austria' | 'Azerbaijan' | 'Bahamas, The' | 'Bahrain' | 'Bangladesh' | 'Barbados' | 'Belarus' | 'Belgium' | 'Belize' | 'Benin' | 'Bermuda' | 'Bhutan' | 'Bolivia' | 'Bosnia & Herzegovina' | 'Botswana' | 'Brazil' | 'British Virgin Is.' | 'Brunei' | 'Bulgaria' | 'Burkina Faso' | 'Burma' | 'Burundi' | 'Cambodia' | 'Cameroon' | 'Canada' | 'Cape Verde' | 'Cayman Islands' | 'Central African Rep.' | 'Chad' | 'Chile' | 'China' | 'Colombia' | 'Comoros' | 'Congo, Dem. Rep.' | 'Congo, Repub. of the' | 'Cook Islands' | 'Costa Rica' | 'Cote d'Ivoire' | 'Croatia' | 'Cuba' | 'Cyprus' | 'Czech Republic' | 'Denmark' | 'Djibouti' | 'Dominica' | 'Dominican Republic' | 'East Timor' | 'Ecuador' | 'Egypt' | 'El Salvador' | 'Equatorial Guinea' | 'Eritrea' | 'Estonia' | 'Ethiopia' | 'Faroe Islands' | 'Fiji' | 'Finland' | 'France' | 'French Guiana' | 'French Polynesia' | 'Gabon' | 'Gambia, The' | 'Gaza Strip' | 'Georgia' | 'Germany' | 'Ghana' | 'Gibraltar' | 'Greece' | 'Greenland' | 'Grenada' | 'Guadeloupe' | 'Guam' | 'Guatemala' | 'Guernsey' | 'Guinea' | 'Guinea-Bissau' | 'Guyana' | 'Haiti' | 'Honduras' | 'Hong Kong' | 'Hungary' | 'Iceland' | 'India' | 'Indonesia' | 'Iran' | 'Iraq' | 'Ireland' | 'Isle of Man' | 'Israel' | 'Italy' | 'Jamaica' | 'Japan' | 'Jersey' | 'Jordan' | 'Kazakhstan' | 'Kenya' | 'Kiribati' | 'Korea, North' | 'Korea, South' | 'Kuwait' | 'Kyrgyzstan' | 'Laos' | 'Latvia' | 'Lebanon' | 'Lesotho' | 'Liberia' | 'Libya' | 'Liechtenstein' | 'Lithuania' | 'Luxembourg' | 'Macau' | 'Macedonia' | 'Madagascar' | 'Malawi' | 'Malaysia' | 'Maldives' | 'Mali' | 'Malta' | 'Marshall Islands' | 'Martinique' | 'Mauritania' | 'Mauritius' | 'Mayotte' | 'Mexico' | 'Micronesia, Fed. St.' | 'Moldova' | 'Monaco' | 'Mongolia' | 'Montserrat' | 'Morocco' | 'Mozambique' | 'Namibia' | 'Nauru' | 'Nepal' | 'Netherlands' | 'Netherlands Antilles' | 'New Caledonia' | 'New Zealand' | 'Nicaragua' | 'Niger' | 'Nigeria' | 'N. Mariana Islands' | 'Norway' | 'Oman' | 'Pakistan' | 'Palau' | 'Panama' | 'Papua New Guinea' | 'Paraguay' | 'Peru' | 'Philippines' | 'Poland' | 'Portugal' | 'Puerto Rico' | 'Qatar' | 'Reunion' | 'Romania' | 'Russia' | 'Rwanda' | 'Saint Helena' | 'Saint Kitts & Nevis' | 'Saint Lucia' | 'St Pierre & Miquelon' | 'Saint Vincent and the Grenadines' | 'Samoa' | 'San Marino' | 'Sao Tome & Principe' | 'Saudi Arabia' | 'Senegal' | 'Serbia' | 'Seychelles' | 'Sierra Leone' | 'Singapore' | 'Slovakia' | 'Slovenia' | 'Solomon Islands' | 'Somalia' | 'South Africa' | 'Spain' | 'Sri Lanka' | 'Sudan' | 'Suriname' | 'Swaziland' | 'Sweden' | 'Switzerland' | 'Syria' | 'Taiwan' | 'Tajikistan' | 'Tanzania' | 'Thailand' | 'Togo' | 'Tonga' | 'Trinidad & Tobago' | 'Tunisia' | 'Turkey' | 'Turkmenistan' | 'Turks & Caicos Is' | 'Tuvalu' | 'Uganda' | 'Ukraine' | 'United Arab Emirates' | 'United Kingdom' | 'United States' | 'Uruguay' | 'Uzbekistan' | 'Vanuatu' | 'Venezuela' | 'Vietnam' | 'Virgin Islands' | 'Wallis and Futuna' | 'West Bank' | 'Western Sahara' | 'Yemen' | 'Zambia' | 'Zimbabwe'; export type DispensaryBusinessType = 'retail' | 'wholesale'; export type UUID = string; export type IANATimezones = '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 type AlleavesTestAuth = {username: string, password: string}; export type BiotrackTestAuth = {username: string, password: string, server_ip: string, port: number, database_name: string}; export type BlazeTestAuth = {Authorization: string}; export type BrytemapTestAuth = {client_key: string}; export type CanixTestAuth = {key: string}; export type CovaTestAuth = {username: string, password: string, client_id: string, client_secret: string}; export type FlourishTestAuth = {api_key: string}; export type FlowhubTestAuth = {key: string, clientId: string}; export type GreenbitsTestAuth = {username: string, password: string}; export type GrowFlowTestAuth = {client_id_name: string}; export type GrowFlowWholesaleTestAuth = {state: string, license_number: string}; export type IndicaOnlineTestAuth = {apiKey: string, officeId: number}; export type IntacctTestAuth = {company_id: string, user_id: string, user_password: string}; export type DutchieTestAuth = {medApiKey?: string | undefined, recApiKey?: string | undefined}; export type MeadowTestAuth = {clientKey: string}; export type MjFreewayTestAuth = {apiKey: string, facilityId: string, orgId: string, userId: string}; export type POSaBITTestAuth = {apiToken: string}; export type Proteus420TestAuth = {apiKey: string, clientName: string}; export type TreezTestAuth = {oid: string, dispensaryName: string}; export type WeaveTestAuth = {apiKey: string}; export type PosCredentials = AlleavesTestAuth | BiotrackTestAuth | BlazeTestAuth | BrytemapTestAuth | CanixTestAuth | CovaTestAuth | FlourishTestAuth | FlowhubTestAuth | GreenbitsTestAuth | GrowFlowTestAuth | GrowFlowWholesaleTestAuth | IndicaOnlineTestAuth | IntacctTestAuth | DutchieTestAuth | MeadowTestAuth | MjFreewayTestAuth | POSaBITTestAuth | Proteus420TestAuth | TreezTestAuth | WeaveTestAuth; export type AvailablePosTypes = 'Alleaves' | 'BioTrack' | 'BioTrack Wholesale' | 'Blaze' | 'Canix' | 'Dutchie' | 'Dutchie Wholesale' | 'Flourish Wholesale' | 'Flowhub' | 'Greenbits' | 'GrowFlow' | 'GrowFlow Wholesale' | 'IndicaOnline' | 'Meadow' | 'POSaBIT' | 'Proteus420' | 'Sage Intacct' | 'Treez' | 'Weave'; export type Email = string; export type InitialCrbRole = 'dispensary_admin' | 'dispensary_user' | 'dispensary_account_owner'; export type SSN = string; export type DateOfBirth = string; export type CrbCreationUser = {firstName: string, lastName: string, email: Email, phone?: PhoneNumber | undefined, address?: string | undefined, city?: City | undefined, state?: USStates | undefined, zipcode?: PostalCode | undefined, role?: InitialCrbRole | undefined, ssn?: SSN | undefined, dateOfBirth?: DateOfBirth | undefined}; export type CrbCreationParams = {org: {monthlyCustomers?: PositiveInteger | undefined, monthlySales?: PositiveInteger | undefined, dba?: string | undefined, entityType?: EntityType | undefined, ptEmployees?: PositiveInteger | undefined, ftEmployees?: PositiveInteger | undefined, established_date?: ShortDate | undefined, website?: Website | undefined, phone_number?: PhoneNumber | undefined, ein?: EIN | undefined, mailing_postal_code?: PostalCode | undefined, mailing_state?: USStates | undefined, mailing_city?: City | undefined, mailing_street_address?: string | undefined, country?: Countries | undefined, postal_code?: PostalCode | undefined, city?: City | undefined, street_address_2?: string | undefined, street_address?: string | undefined, primary_contact_email?: string | undefined, business_type: DispensaryBusinessType, template_id?: UUID | undefined, timezone?: IANATimezones | undefined, state: USStates, name: string}, pos_info?: ({location_id?: (string | number) | undefined, pos_credentials: PosCredentials, pos_type: AvailablePosTypes}) | undefined, users?: Array | undefined, options?: ({onboarding_required?: boolean | undefined}) | undefined}; export type CreateApiServiceProvidersSpIdCrbsArgs = {sp_id: string, body: CrbCreationParams}; export type CreateApiServiceProvidersSpIdCrbsOptions = {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 cRB = 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}); 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 CRB * * POST /service-providers/{sp_id}/crbs */ export const createApiServiceProvidersSpIdCrbs = async (args: CreateApiServiceProvidersSpIdCrbsArgs, options?: CreateApiServiceProvidersSpIdCrbsOptions) => { const {baseUrl = "https://sandbox-api.greencheckverified.com", fetch: fetchFn = fetch, accessAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") 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: "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(cRB, await res.json()) };