import {z} from 'zod' export type GetApiV2WorkflowsArgs = {api_key: string, 'X-Frankie-CustomerID': string, 'X-Frankie-CustomerChildID'?: string | undefined, 'X-Frankie-Channel'?: string | undefined, 'X-Frankie-Username'?: string | undefined, serviceName?: string | undefined, include?: Array<'workflowDefinition'> | undefined}; export type GetApiV2WorkflowsOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const requestID = z.string(); export const workflowLifecyclePhaseEnum = z.enum(["ONBOARDING", "MONITORING", "OTHER"]); export const monitoringType = z.enum(["AML", "ACTIVITY"]); export const workflowStepType = z.enum(["BLOCKLIST", "DUPLICATE", "DECISION", "BRANCH", "MONITOR_TOGGLE", "OTHER", "KYC", "AML", "IDV", "START", "FINISH"]); export const workflowStep = z.object({name: z.string().optional(), description: z.string().optional(), version: z.string().optional(), type: workflowStepType.optional(), configuration: z.object({}).optional(), dependsOn: z.array(z.string()).optional()}); export const workflowDefinition = z.object({definitionUpdatedAt: z.string().optional(), version: z.string().optional(), steps: z.array(workflowStep).optional()}); export const workflowLookup = z.object({serviceName: z.string().optional(), workflowId: z.string().optional(), workflowName: z.string().optional(), type: z.string().optional(), lifecyclePhase: workflowLifecyclePhaseEnum.optional(), monitoringTypes: z.array(monitoringType).optional(), definition: workflowDefinition.optional()}); export const getApiV2WorkflowsResponse = z.object({requestId: requestID.optional(), workflows: z.array(workflowLookup).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 a list of executable workflows * * GET /v2/workflows * * Also accepts auth: jwt */ export const getApiV2Workflows = async (args: GetApiV2WorkflowsArgs, options?: GetApiV2WorkflowsOptions) => { const {baseUrl = "https://api.uat.frankie.one", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.api_key != null) headers.set("api_key", String(args.api_key)) if (args['X-Frankie-CustomerID'] != null) headers.set("X-Frankie-CustomerID", String(args['X-Frankie-CustomerID'])) if (args['X-Frankie-CustomerChildID'] != null) headers.set("X-Frankie-CustomerChildID", String(args['X-Frankie-CustomerChildID'])) if (args['X-Frankie-Channel'] != null) headers.set("X-Frankie-Channel", String(args['X-Frankie-Channel'])) if (args['X-Frankie-Username'] != null) headers.set("X-Frankie-Username", String(args['X-Frankie-Username'])) if (args.serviceName != null) query.append("serviceName", String(args.serviceName)) if (args.include != null) query.append("include", args.include.join(',')) if (ApiKey !== undefined) headers.set("api_key", ApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/v2/workflows${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(getApiV2WorkflowsResponse, await res.json()) };