import {z} from 'zod' export type GetApiV0VerificationsVerificationIdArgs = {'verification-id': string}; export type GetApiV0VerificationsVerificationIdOptions = {baseUrl?: string | undefined, apiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV0VerificationsVerificationIdResponse = z.object({"verification-profiles-url": z.union([z.string(), z.string()]).optional(), "verification-url": z.string(), "verification-resources-url": z.string().optional(), "updated-at": z.string().optional(), "legal-person-url": z.union([z.string(), z.string()]), "workflow-url": z.string().optional(), "created-at": z.string(), "verification-checks-url": z.string(), "risk-rating": z.enum(["high-risk", "prohibited-risk", "medium-risk", "low-risk"]).optional(), "verification-status": z.enum(["in-progress", "pending", "checks-declined", "checks-complete", "failed"]), "verification-risk-assessments-url": z.string().optional()}); 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 verification * * GET /v0/verifications/{verification-id} */ export const getApiV0VerificationsVerificationId = async (args: GetApiV0VerificationsVerificationIdArgs, options?: GetApiV0VerificationsVerificationIdOptions) => { const {baseUrl = "https://api.griffin.com", fetch: fetchFn = fetch, apiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (apiKeyAuth !== undefined) headers.set("Authorization", apiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v0/verifications/${encodeURIComponent(String(args['verification-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(getApiV0VerificationsVerificationIdResponse, await res.json()) };