import {z} from 'zod' export type GetApiEntitiesEntityIdRepresentativesArgs = {entity_id: string}; export type GetApiEntitiesEntityIdRepresentativesOptions = {baseUrl?: string | undefined, apiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const onboardingKycStatus = z.enum(["not_started", "pending", "action_required", "approved", "rejected"]); export const onboardingKycFailedCheck = z.enum(["accept_tos", "verify_sms", "kyc_check", "documentary_verification", "selfie_check", "watchlist_screening", "risk_check"]); export const onboardingRepresentativeKyc = z.object({representative_id: z.string(), first_name: z.string().nullable(), last_name: z.string().nullable(), email: z.string(), is_primary: z.boolean(), is_beneficial_owner: z.boolean(), percent_ownership: z.string().nullable(), kyc_status: onboardingKycStatus, failed_checks: z.array(onboardingKycFailedCheck)}); export const entityRepresentativeListResponse = z.object({representatives: z.array(onboardingRepresentativeKyc)}); 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 Entity Representatives * * GET /entities/{entity_id}/representatives */ export const getApiEntitiesEntityIdRepresentatives = async (args: GetApiEntitiesEntityIdRepresentativesArgs, options?: GetApiEntitiesEntityIdRepresentativesOptions) => { const {baseUrl = "https://api.meow.com/v1", fetch: fetchFn = fetch, apiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (apiKeyAuth !== undefined) headers.set("x-api-key", apiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/entities/${encodeURIComponent(String(args.entity_id))}/representatives${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(entityRepresentativeListResponse, await res.json()) };