import {z} from 'zod' 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 City = string; export type PostalCode = 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 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 EIN = string; export type PhoneNumber = string; export type Website = string; export type ShortDate = string; export type PositiveInteger = number; export type EntityType = 'sole' | 'partnership' | 'corporation' | 'llc'; export type UpdateCrbInput = {timezone?: IANATimezones | undefined, street_address?: string | undefined, street_address_2?: string | undefined, city?: City | undefined, postal_code?: PostalCode | undefined, country?: Countries | undefined, mailing_street_address?: string | undefined, mailing_city?: City | undefined, mailing_state?: USStates | undefined, mailing_postal_code?: PostalCode | undefined, ein?: EIN | undefined, phone_number?: PhoneNumber | undefined, website?: Website | undefined, established_date?: ShortDate | undefined, ftEmployees?: PositiveInteger | undefined, ptEmployees?: PositiveInteger | undefined, entityType?: EntityType | undefined, dba?: string | undefined, monthlySales?: PositiveInteger | undefined, monthlyCustomers?: PositiveInteger | undefined}; export type UpdateApiServiceProvidersSpIdCrbsCrbIdArgs = {sp_id: string, crb_id: string, body: UpdateCrbInput}; export type UpdateApiServiceProvidersSpIdCrbsCrbIdOptions = {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 serviceProviderCRB = 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 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 }; /** * Update business details of a CRB * * PUT /service-providers/{sp_id}/crbs/{crb_id} */ export const updateApiServiceProvidersSpIdCrbsCrbId = async (args: UpdateApiServiceProvidersSpIdCrbsCrbIdArgs, options?: UpdateApiServiceProvidersSpIdCrbsCrbIdOptions) => { 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/${encodeURIComponent(String(args.crb_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(serviceProviderCRB, await res.json()) };