import {z} from 'zod' export type GetApiComplianceOrchestratorWorkflowsWorkflowIdArgs = {workflowId: string}; export type GetApiComplianceOrchestratorWorkflowsWorkflowIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const workflowStatusEnum = z.enum(["ACTIVE", "DRAFT"]); export const screeningOperationEnum = z.enum(["ADDRESS_SCREENING", "TRANSACTION_SCREENING", "REGISTER_TRANSACTION"]); export const ruleConditionOperatorEnum = z.enum(["EQUALS", "NOT_EQUALS", "GT", "GTE", "LT", "LTE"]); export const ruleCondition = z.object({field: z.string(), operator: ruleConditionOperatorEnum, value: z.string()}); export const ruleActionEnum = z.enum(["SCREEN", "PASS", "FREEZE", "ACCEPT", "REJECT", "ALERT", "WAIT"]); export const rule = z.object({ruleId: z.string().optional(), conditions: z.array(ruleCondition).optional(), ruleAction: ruleActionEnum.optional(), order: z.number().int().optional(), title: z.string().nullable().optional()}).nullable(); export const ruleSet = z.object({rules: z.array(rule).optional()}); export const stepOperationConfig = z.object({operation: screeningOperationEnum.optional(), requiredParameters: z.array(z.string()).optional(), optionalParameters: z.array(z.string()).optional(), triggerRuleParameters: z.array(z.string()).optional(), outcomeEvaluationParameters: z.array(z.string()).optional(), outcomeMetaParameters: z.array(z.string()).optional(), triggerRuleSetStruct: ruleSet.optional(), triggerRuleSetJson: z.string().nullable().optional(), outcomeRuleSetStruct: ruleSet.optional(), outcomeRuleSetJson: z.string().nullable().optional()}); export const stepConfig = z.object({stepId: z.string(), connectorId: z.string(), operations: z.array(stepOperationConfig), order: z.number().int()}); export const getWorkflowResponse = z.object({workflowId: z.string(), templateId: z.string().nullable().optional(), status: workflowStatusEnum, title: z.string(), description: z.string().nullable().optional(), createdAt: z.string(), steps: z.array(stepConfig)}); 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 a Compliance Orchestrator workflow * * GET /compliance/orchestrator/workflows/{workflowId} */ export const getApiComplianceOrchestratorWorkflowsWorkflowId = async (args: GetApiComplianceOrchestratorWorkflowsWorkflowIdArgs, options?: GetApiComplianceOrchestratorWorkflowsWorkflowIdOptions) => { const {baseUrl = "https://api.fireblocks.io/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/compliance/orchestrator/workflows/${encodeURIComponent(String(args.workflowId))}${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(getWorkflowResponse, await res.json()) };