import {z} from 'zod' export type RepresentativeTitle = 'chief executive officer' | 'chief financial officer' | 'chief operating officer' | 'finance manager' | 'general partner' | 'managing member' | 'president'; export type EntityCreateRepresentativeRequest = {is_beneficial_owner?: boolean | undefined, percent_ownership?: (number | string | null) | undefined, email: string, first_name?: (string | null) | undefined, last_name?: (string | null) | undefined, title_id: RepresentativeTitle, is_primary?: boolean | undefined}; export type CreateApiEntitiesEntityIdRepresentativesArgs = {entity_id: string, body: EntityCreateRepresentativeRequest}; export type CreateApiEntitiesEntityIdRepresentativesOptions = {baseUrl?: string | undefined, apiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const representativeTitle = z.enum(["chief executive officer", "chief financial officer", "chief operating officer", "finance manager", "general partner", "managing member", "president"]); export const onboardingKycStatus = z.enum(["not_started", "pending", "action_required", "approved", "rejected"]); export const entityRepresentativeResponse = z.object({representative_id: z.string(), email: z.string(), title_id: representativeTitle, is_beneficial_owner: z.boolean(), percent_ownership: z.string().nullable(), is_primary: z.boolean(), kyc_status: onboardingKycStatus}); 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 }; /** * Add Entity Representative * * POST /entities/{entity_id}/representatives */ export const createApiEntitiesEntityIdRepresentatives = async (args: CreateApiEntitiesEntityIdRepresentativesArgs, options?: CreateApiEntitiesEntityIdRepresentativesOptions) => { const {baseUrl = "https://api.meow.com/v1", fetch: fetchFn = fetch, apiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") 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: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(entityRepresentativeResponse, await res.json()) };