import {z} from 'zod' export type TRLinkDiscoverableStatus = 'anonymous' | 'hidden' | 'discoverable' | null; export type TRLinkGeographicAddressRequest = {addressLine?: (Array | null) | undefined, streetName?: (string | null) | undefined, buildingNumber?: (string | null) | undefined, floor?: (string | null) | undefined, postBox?: (string | null) | undefined, postCode?: (string | null) | undefined, townName?: (string | null) | undefined, districtName?: (string | null) | undefined, countrySubDivision?: (string | null) | undefined, country?: (string | null) | undefined} | null; export type TRLinkUpdateCustomerRequest = {discoverable?: TRLinkDiscoverableStatus | undefined, shortName: string, fullLegalName?: (string | null) | undefined, geographicAddress?: TRLinkGeographicAddressRequest | undefined, countryOfRegistration?: (string | null) | undefined, nationalIdentification?: (string | null) | undefined, dateOfIncorporation?: (string | null) | undefined, vaults?: (Array | null) | undefined, trPrimaryPurpose?: string | undefined}; export type UpdateApiScreeningTrlinkCustomersCustomerIdArgs = {customerId: string, 'Idempotency-Key'?: string | undefined, body: TRLinkUpdateCustomerRequest}; export type UpdateApiScreeningTrlinkCustomersCustomerIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const tRLinkDiscoverableStatus = z.enum(["anonymous", "hidden", "discoverable"]).nullable(); export const tRLinkGeographicAddressRequest = z.object({addressLine: z.array(z.string().max(70)).nullable().optional(), streetName: z.string().max(70).nullable().optional(), buildingNumber: z.string().max(255).nullable().optional(), floor: z.string().max(70).nullable().optional(), postBox: z.string().max(16).nullable().optional(), postCode: z.string().max(16).nullable().optional(), townName: z.string().max(35).nullable().optional(), districtName: z.string().max(35).nullable().optional(), countrySubDivision: z.string().max(35).nullable().optional(), country: z.string().nullable().optional()}).nullable(); export const tRLinkCustomerResponse = z.object({id: z.string(), discoverable: tRLinkDiscoverableStatus, shortName: z.string(), fullLegalName: z.string(), geographicAddress: tRLinkGeographicAddressRequest.optional(), countryOfRegistration: z.string(), nationalIdentification: z.string().nullable().optional(), dateOfIncorporation: z.string().nullable().optional(), vaults: z.array(z.number().int()).nullable().optional(), trPrimaryPurpose: z.string(), createDate: z.string(), lastUpdate: z.string()}); 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 }; /** * Update customer * * PUT /screening/trlink/customers/{customerId} */ export const updateApiScreeningTrlinkCustomersCustomerId = async (args: UpdateApiScreeningTrlinkCustomersCustomerIdArgs, options?: UpdateApiScreeningTrlinkCustomersCustomerIdOptions) => { const {baseUrl = "https://api.fireblocks.io/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) const url = `${baseUrl.replace(/\/+$/, '')}/screening/trlink/customers/${encodeURIComponent(String(args.customerId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(tRLinkCustomerResponse, await res.json()) };