import {z} from 'zod' export type GetApiV0VerificationsVerificationIdResourcesArgs = {'page[size]'?: number | undefined, 'page[after]'?: string | undefined, 'page[before]'?: string | undefined, 'verification-id': string}; export type GetApiV0VerificationsVerificationIdResourcesOptions = {baseUrl?: string | undefined, apiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV0VerificationsVerificationIdResourcesResponse = z.object({"verification-url": z.string(), "legal-person-url": z.union([z.string(), z.string()]), "organization-url": z.string(), "verification-resources": z.array(z.object({"verification-resource-type": z.literal("idv-check"), "verification-resource-id": z.string(), "idv-check-status": z.enum(["pending", "errored", "expired", "complete"]), "idv-check-url": z.string(), "idv-check-expires-at": z.string(), "display-name": z.string().min(1), "legal-person-url": z.union([z.string(), z.string()])})), links: z.object({prev: z.string().nullable(), next: z.string().nullable()})}); 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 resources * * GET /v0/verifications/{verification-id}/resources */ export const getApiV0VerificationsVerificationIdResources = async (args: GetApiV0VerificationsVerificationIdResourcesArgs, options?: GetApiV0VerificationsVerificationIdResourcesOptions) => { 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 (args['page[size]'] != null) query.append("page[size]", String(args['page[size]'])) if (args['page[after]'] != null) query.append("page[after]", String(args['page[after]'])) if (args['page[before]'] != null) query.append("page[before]", String(args['page[before]'])) if (apiKeyAuth !== undefined) headers.set("Authorization", apiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v0/verifications/${encodeURIComponent(String(args['verification-id']))}/resources${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(getApiV0VerificationsVerificationIdResourcesResponse, await res.json()) };