import {z} from 'zod' export type GetApiV0OrganizationsOrganizationIdLegalPersonsArgs = {sort?: ('-status-changed-at' | 'status-changed-at' | '-created-at' | 'created-at') | undefined, include?: (Array<'company-roles' | 'latest-risk-rating' | 'latest-verification'>) | undefined, 'filter[legal-person-status][in][]'?: (Array<'restricted' | 'onboarding-declined' | 'onboarded' | 'verified' | 'onboarding'>) | undefined, 'filter[application-status][eq]'?: ('referred' | 'errored' | 'declined' | 'submitted' | 'accepted') | undefined, 'filter[has][]'?: Array<'application-status'> | undefined, 'page[size]'?: number | undefined, 'page[after]'?: string | undefined, 'page[before]'?: string | undefined, 'organization-id': string}; export type GetApiV0OrganizationsOrganizationIdLegalPersonsOptions = {baseUrl?: string | undefined, apiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV0OrganizationsOrganizationIdLegalPersonsResponse = z.object({"legal-persons": z.array(z.object({"latest-decision": z.object({"decision-outcome": z.enum(["accepted", "declined"]), "decision-notes": z.string(), "verification-url": z.string(), "legal-person-url": z.union([z.string(), z.string()]), "created-at": z.string(), "decision-maker": z.enum(["system", "ops-user", "user"]), "decision-user-url": z.string().optional(), "decision-ops-user": z.literal("griffin-ops-user").optional(), "decision-user-username": z.string().optional()}).optional(), "legal-person-type": z.enum(["individual", "corporation"]), "latest-risk-rating-url": z.string().optional(), "display-name": z.string().min(1).max(64), "application-status": z.enum(["referred", "errored", "declined", "submitted", "accepted"]).optional(), "legal-person-status": z.enum(["restricted", "onboarding-declined", "onboarded", "verified", "onboarding"]).optional(), "legal-person-url": z.union([z.string(), z.string()]), "legal-person-decisions-url": z.union([z.string(), z.string()]), "status-changed-at": z.string().optional(), "created-at": z.string(), "legal-person-claims-url": z.union([z.string(), z.string()]).optional(), "legal-person-bank-payees-url": z.union([z.string(), z.string()]).optional(), "legal-person-verifications-url": z.union([z.string(), z.string()]), "legal-name": z.string().optional(), "legal-person-documents-url": z.union([z.string(), z.string()])})), links: z.object({prev: z.string().nullable(), next: z.string().nullable()}), meta: z.object({page: z.object({total: z.number().int().gte(0).optional(), "estimated-total": z.object({"at-least": z.literal(10000).optional()}).optional()}).optional()}).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 }; /** * List legal persons * * GET /v0/organizations/{organization-id}/legal-persons */ export const getApiV0OrganizationsOrganizationIdLegalPersons = async (args: GetApiV0OrganizationsOrganizationIdLegalPersonsArgs, options?: GetApiV0OrganizationsOrganizationIdLegalPersonsOptions) => { 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.sort != null) query.append("sort", String(args.sort)) for (const item of args.include ?? []) query.append("include", String(item)) for (const item of args['filter[legal-person-status][in][]'] ?? []) query.append("filter[legal-person-status][in][]", String(item)) if (args['filter[application-status][eq]'] != null) query.append("filter[application-status][eq]", String(args['filter[application-status][eq]'])) for (const item of args['filter[has][]'] ?? []) query.append("filter[has][]", String(item)) 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/organizations/${encodeURIComponent(String(args['organization-id']))}/legal-persons${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(getApiV0OrganizationsOrganizationIdLegalPersonsResponse, await res.json()) };