import {z} from 'zod' export type TRLinkOneTimeAddress = {address: string, tag?: (string | null) | undefined}; export type TRLinkDestinationTransferPeerPath = {type: string, id?: (string | null) | undefined, walletId?: (string | null) | undefined, oneTimeAddress?: TRLinkOneTimeAddress | undefined}; export type TRLinkSourceTransferPeerPath = {type: string, id?: (string | null) | undefined, walletId?: (string | null) | undefined}; export type TRLinkTransactionDirection = 'INBOUND' | 'OUTBOUND'; export type TRLinkAssessTravelRuleRequest = {txId?: (string | null) | undefined, amount?: (string | null) | undefined, amountUSD?: (string | null) | undefined, destination?: TRLinkDestinationTransferPeerPath | undefined, destAddress?: (string | null) | undefined, destTag?: (string | null) | undefined, source?: TRLinkSourceTransferPeerPath | undefined, srcAddress?: (string | null) | undefined, assetId?: (string | null) | undefined, direction?: TRLinkTransactionDirection | undefined, txHash?: (string | null) | undefined, originatorVaspId?: (string | null) | undefined, beneficiaryVaspId?: (string | null) | undefined}; export type CreateApiScreeningTrlinkCustomersIntegrationCustomerIntegrationIdTrmAssessArgs = {customerIntegrationId: string, 'Idempotency-Key'?: string | undefined, body: TRLinkAssessTravelRuleRequest}; export type CreateApiScreeningTrlinkCustomersIntegrationCustomerIntegrationIdTrmAssessOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const tRLinkAssessmentDecision = z.enum(["REQUIRED", "NOT_REQUIRED", "NEED_MORE_INFO"]); export const tRLinkThresholds = z.object({amount: z.string().optional(), currency: z.string().optional()}); export const tRLinkAssessTravelRuleResponse = z.object({decision: tRLinkAssessmentDecision, reason: z.string(), requiredFields: z.array(z.string()).nullable().optional(), missingInfo: z.array(z.string()).nullable().optional(), thresholds: tRLinkThresholds.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 }; /** * Assess Travel Rule requirement * * POST /screening/trlink/customers/integration/{customerIntegrationId}/trm/assess */ export const createApiScreeningTrlinkCustomersIntegrationCustomerIntegrationIdTrmAssess = async (args: CreateApiScreeningTrlinkCustomersIntegrationCustomerIntegrationIdTrmAssessArgs, options?: CreateApiScreeningTrlinkCustomersIntegrationCustomerIntegrationIdTrmAssessOptions) => { 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/integration/${encodeURIComponent(String(args.customerIntegrationId))}/trm/assess${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(tRLinkAssessTravelRuleResponse, await res.json()) };