import {z} from 'zod' export type GetApiServiceProvidersSpIdPosCredentialsSchemaArgs = {sp_id: string}; export type GetApiServiceProvidersSpIdPosCredentialsSchemaOptions = {baseUrl?: string | undefined, accessAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const credentialsSchema = z.object({credentials_name: z.string(), credentials_description: z.string(), credentials_properties: z.record(z.string(), z.object({type: z.enum(["string", "number"])})), required_properties: z.array(z.string())}); export const dispensaryBusinessType = z.enum(["retail", "wholesale"]); export const availablePosTypes = z.enum(["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 const posCredentialInformation = z.object({Alleaves: z.object({pos_credentials_schema: credentialsSchema, location_required: z.boolean(), business_type: dispensaryBusinessType, pos_type: availablePosTypes}), Dutchie: z.object({pos_credentials_schema: credentialsSchema, location_required: z.boolean(), business_type: dispensaryBusinessType, pos_type: availablePosTypes}), "Dutchie Wholesale": z.object({pos_credentials_schema: credentialsSchema, location_required: z.boolean(), business_type: dispensaryBusinessType, pos_type: availablePosTypes}), Meadow: z.object({pos_credentials_schema: credentialsSchema, location_required: z.boolean(), business_type: dispensaryBusinessType, pos_type: availablePosTypes}), Greenbits: z.object({pos_credentials_schema: credentialsSchema, location_required: z.boolean(), business_type: dispensaryBusinessType, pos_type: availablePosTypes}), GrowFlow: z.object({pos_credentials_schema: credentialsSchema, location_required: z.boolean(), business_type: dispensaryBusinessType, pos_type: availablePosTypes}), "GrowFlow Wholesale": z.object({pos_credentials_schema: credentialsSchema, location_required: z.boolean(), business_type: dispensaryBusinessType, pos_type: availablePosTypes}), "Flourish Wholesale": z.object({pos_credentials_schema: credentialsSchema, location_required: z.boolean(), business_type: dispensaryBusinessType, pos_type: availablePosTypes}), Flowhub: z.object({pos_credentials_schema: credentialsSchema, location_required: z.boolean(), business_type: dispensaryBusinessType, pos_type: availablePosTypes}), BioTrack: z.object({pos_credentials_schema: credentialsSchema, location_required: z.boolean(), business_type: dispensaryBusinessType, pos_type: availablePosTypes}), "BioTrack Wholesale": z.object({pos_credentials_schema: credentialsSchema, location_required: z.boolean(), business_type: dispensaryBusinessType, pos_type: availablePosTypes}), Treez: z.object({pos_credentials_schema: credentialsSchema, location_required: z.boolean(), business_type: dispensaryBusinessType, pos_type: availablePosTypes}), Blaze: z.object({pos_credentials_schema: credentialsSchema, location_required: z.boolean(), business_type: dispensaryBusinessType, pos_type: availablePosTypes}), "Sage Intacct": z.object({pos_credentials_schema: credentialsSchema, location_required: z.boolean(), business_type: dispensaryBusinessType, pos_type: availablePosTypes}), Canix: z.object({pos_credentials_schema: credentialsSchema, location_required: z.boolean(), business_type: dispensaryBusinessType, pos_type: availablePosTypes}), POSaBIT: z.object({pos_credentials_schema: credentialsSchema, location_required: z.boolean(), business_type: dispensaryBusinessType, pos_type: availablePosTypes}), Proteus420: z.object({pos_credentials_schema: credentialsSchema, location_required: z.boolean(), business_type: dispensaryBusinessType, pos_type: availablePosTypes}), IndicaOnline: z.object({pos_credentials_schema: credentialsSchema, location_required: z.boolean(), business_type: dispensaryBusinessType, pos_type: availablePosTypes}), Weave: z.object({pos_credentials_schema: credentialsSchema, location_required: z.boolean(), business_type: dispensaryBusinessType, pos_type: availablePosTypes})}); 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 POS Credentials Schema * * GET /service-providers/{sp_id}/pos-credentials-schema */ export const getApiServiceProvidersSpIdPosCredentialsSchema = async (args: GetApiServiceProvidersSpIdPosCredentialsSchemaArgs, options?: GetApiServiceProvidersSpIdPosCredentialsSchemaOptions) => { 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))}/pos-credentials-schema${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(posCredentialInformation, await res.json()) };