import {z} from 'zod' export type GetApiV1CustomersCustomerIdAssociatedEntitiesIdArgs = {'X-API-Key'?: string | undefined, customerId: string, id: string}; export type GetApiV1CustomersCustomerIdAssociatedEntitiesIdOptions = {baseUrl?: string | undefined, bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const individualEntityDetailsDto = z.object({firstName: z.string().optional(), nickname: z.string().optional(), lastName: z.string().optional(), middleName: z.string().optional(), dateOfBirth: z.string().optional(), taxResidenceCountry: z.string().optional(), transliteratedFirstName: z.string().optional(), transliteratedMiddleName: z.string().optional(), transliteratedLastName: z.string().optional(), taxIdentificationDocumentType: z.string().optional()}); export const transliteratedAddressDto = z.object({addressLine1: z.string().min(1).max(1024).optional(), addressLine2: z.string().min(1).max(1024).optional(), city: z.string().min(1).max(256).optional(), state: z.string().min(1).max(256).optional()}); export const addressDto = z.object({addressLine1: z.string().min(1).max(1024), addressLine2: z.string().min(1).max(1024).optional(), city: z.string().min(1).max(256), state: z.string().min(1).max(256).optional(), postalCode: z.string().min(1).max(50), country: z.string().min(2).max(2), transliterated: transliteratedAddressDto.optional()}); export const businessEntityDetailsDto = z.object({businessName: z.string().optional(), registrationNumber: z.string().optional(), dateOfIncorporation: z.string().optional(), businessAddress: addressDto.optional()}); export const verificationLinkDto = z.object({sessionId: z.string(), verificationUrl: z.string(), expiresAt: z.string(), status: z.enum(["PENDING", "ACTIVE", "IN_PROGRESS", "COMPLETED", "EXPIRED", "CANCELLED", "SUBMITTED"])}); export const associatedEntityResponseDto = z.object({id: z.string(), createdAt: z.string(), updatedAt: z.string(), entityType: z.enum(["INDIVIDUAL", "BUSINESS"]), parentEntityId: z.string().optional(), details: z.union([individualEntityDetailsDto, businessEntityDetailsDto]).optional(), countryCode: z.string().optional(), email: z.string().optional(), phone: z.string().optional(), address: addressDto.optional(), hasOwnership: z.boolean(), hasControl: z.boolean(), ownershipPercentage: z.number().optional(), isSigner: z.boolean().optional(), isDirector: z.boolean().optional(), role: z.enum(["CEO", "CFO", "COO", "PRESIDENT", "GENERAL_COUNSEL", "MANAGING_MEMBER", "TREASURER", "OTHER"]).optional(), title: z.string().optional(), documents: z.array(z.string()).optional(), attestedOwnershipStructureAt: z.string().optional(), displayName: z.string().optional(), verificationLink: verificationLinkDto.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 an associated entity by id and customer * * GET /v1/customers/{customerId}/associated_entities/{id} */ export const getApiV1CustomersCustomerIdAssociatedEntitiesId = async (args: GetApiV1CustomersCustomerIdAssociatedEntitiesIdArgs, options?: GetApiV1CustomersCustomerIdAssociatedEntitiesIdOptions) => { const {baseUrl = "https://sandbox.api.infinite.dev", fetch: fetchFn = fetch, bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-API-Key'] != null) headers.set("X-API-Key", String(args['X-API-Key'])) if (bearer !== undefined) headers.set('authorization', `Bearer ${bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/customers/${encodeURIComponent(String(args.customerId))}/associated_entities/${encodeURIComponent(String(args.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(associatedEntityResponseDto, await res.json()) };