diff --git a/.changeset/lovely-elephants-dream.md b/.changeset/lovely-elephants-dream.md new file mode 100644 index 0000000000..ebcb5a14a2 --- /dev/null +++ b/.changeset/lovely-elephants-dream.md @@ -0,0 +1,5 @@ +--- +'@ballerine/common': patch +--- + +updated types and functionalities diff --git a/apps/backoffice-v2/src/domains/workflows/fetchers.ts b/apps/backoffice-v2/src/domains/workflows/fetchers.ts index 834ea7cd29..690e82bb37 100644 --- a/apps/backoffice-v2/src/domains/workflows/fetchers.ts +++ b/apps/backoffice-v2/src/domains/workflows/fetchers.ts @@ -62,7 +62,7 @@ export const BaseWorkflowByIdSchema = z.object({ workflowDefinition: ObjectWithIdSchema.extend({ name: z.string(), contextSchema: z.record(z.any(), z.any()).nullable(), - documentsSchema: z.record(z.string(), z.any()).optional(), + documentsSchema: z.array(z.any()).optional(), config: z.record(z.any(), z.any()).nullable(), }), createdAt: z.string().datetime(), diff --git a/apps/backoffice-v2/src/pages/Entity/hooks/useTasks/useTasks.tsx b/apps/backoffice-v2/src/pages/Entity/hooks/useTasks/useTasks.tsx index 8a483764af..8336b997ee 100644 --- a/apps/backoffice-v2/src/pages/Entity/hooks/useTasks/useTasks.tsx +++ b/apps/backoffice-v2/src/pages/Entity/hooks/useTasks/useTasks.tsx @@ -15,8 +15,8 @@ import { getDocumentSchemaByDefinition, isNullish, StateTag, + TAvailableDocuments, TDocument, - TDocumentsWithAvailability, } from '@ballerine/common'; import * as React from 'react'; import { ComponentProps, useMemo } from 'react'; @@ -45,12 +45,13 @@ const pluginsOutputBlacklist = [ ]; function getDocumentsSchemas(issuerCountryCode, workflow: TWorkflowById) { - return ( + const data = getDocumentSchemaByDefinition( + issuerCountryCode, + workflow.workflowDefinition?.documentsSchema as TDocument[], + ); + const filters = issuerCountryCode && - getDocumentSchemaByDefinition( - issuerCountryCode, - workflow.workflowDefinition?.documentsSchema as TDocumentsWithAvailability, - ) + data .concat(getDocumentsByCountry(issuerCountryCode)) .reduce((unique: TDocument[], item: TDocument) => { const isDuplicate = unique.some(u => u.type === item.type && u.category === item.category); @@ -58,19 +59,21 @@ function getDocumentsSchemas(issuerCountryCode, workflow: TWorkflowById) { unique.push(item); } return unique; - }, [] as TDocument[]) - .filter((documentSchema: TDocument) => { - if (!workflow.workflowDefinition.documentsSchema?.availableDocuments) return true; + }, [] as TDocument[]); - const isInside = !!workflow.workflowDefinition.documentsSchema?.availableDocuments.find( - (availableDocument: TDocumentsWithAvailability['availableDocuments'][number]) => - availableDocument.type === documentSchema.type && - availableDocument.category === documentSchema.category, - ); + const filteredDocs = filters.filter((documentSchema: TDocument) => { + if (!workflow.workflowDefinition.config?.availableDocuments) return true; - return isInside; - }) - ); + const isIncludes = !!workflow.workflowDefinition.config?.availableDocuments.find( + (availableDocument: TAvailableDocuments[number]) => + availableDocument.type === documentSchema.type && + availableDocument.category === documentSchema.category, + ); + + return isIncludes; + }); + debugger; + return filteredDocs; } export const useTasks = ({ @@ -134,7 +137,7 @@ export const useTasks = ({ const issuerCountryCode = extractCountryCodeFromWorkflow(workflow); const documentsSchemas = getDocumentsSchemas(issuerCountryCode, workflow); - + debugger; const registryInfoBlock = Object.keys(filteredPluginsOutput ?? {}).length === 0 ? [] diff --git a/packages/common/src/index.ts b/packages/common/src/index.ts index 1cb8603b5a..d3a4ddd092 100644 --- a/packages/common/src/index.ts +++ b/packages/common/src/index.ts @@ -25,7 +25,7 @@ export type { DefaultContextSchema, TDefaultSchemaDocumentPage, TDocument, - TDocumentsWithAvailability, + TAvailableDocuments, } from './schemas'; export { diff --git a/packages/common/src/schemas/documents/workflow/documents/schemas/index.ts b/packages/common/src/schemas/documents/workflow/documents/schemas/index.ts index 868412d472..e6e74a2260 100644 --- a/packages/common/src/schemas/documents/workflow/documents/schemas/index.ts +++ b/packages/common/src/schemas/documents/workflow/documents/schemas/index.ts @@ -1,5 +1,5 @@ import { getGhanaDocuments } from './GH'; -import { TDocument, TDocumentsWithAvailability } from '../types'; +import { TDocument } from '../types'; import { countryCodes } from '@/countries'; import { DefaultContextSchema } from '@/schemas'; import { getCanadaDocuments } from './CA'; @@ -19,12 +19,10 @@ export const getDocumentsByCountry = (countryCode: (typeof countryCodes)[number] export const getDocumentSchemaByDefinition = ( countryCode: (typeof countryCodes)[number], - documentsSchema: TDocumentsWithAvailability | undefined, + documentsSchema: TDocument[] | undefined, ): TDocument[] => { return ( - documentsSchema?.schema?.filter( - documentSchema => documentSchema.issuer.country === countryCode, - ) || [] + documentsSchema?.filter(documentSchema => documentSchema.issuer.country === countryCode) || [] ); }; diff --git a/packages/common/src/schemas/documents/workflow/documents/types.ts b/packages/common/src/schemas/documents/workflow/documents/types.ts index 60f2b24f99..4670437345 100644 --- a/packages/common/src/schemas/documents/workflow/documents/types.ts +++ b/packages/common/src/schemas/documents/workflow/documents/types.ts @@ -5,7 +5,4 @@ export type TDocument = Omit; - schema: TDocument[]; -}; +export type TAvailableDocuments = Array<{ category: string; type: string }>; diff --git a/packages/common/src/schemas/index.ts b/packages/common/src/schemas/index.ts index d36eac33d9..5b49c4c4d3 100644 --- a/packages/common/src/schemas/index.ts +++ b/packages/common/src/schemas/index.ts @@ -4,5 +4,5 @@ export { defaultContextSchema } from './documents/default-context-schema'; export { getGhanaDocuments } from './documents/workflow/documents/schemas/GH'; export { getDocumentsByCountry, getDocumentId } from './documents/workflow/documents/schemas/index'; export { type TDocument } from './documents/workflow/documents/types'; -export { type TDocumentsWithAvailability } from './documents/workflow/documents/types'; +export { type TAvailableDocuments } from './documents/workflow/documents/types'; export { getDocumentSchemaByDefinition } from './documents/workflow/documents/schemas/index'; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 177d0f4b29..35d80e1a89 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14160,7 +14160,7 @@ packages: '@babel/plugin-transform-react-jsx-source': 7.23.3(@babel/core@7.23.3) '@types/babel__core': 7.20.4 react-refresh: 0.14.0 - vite: 4.5.0(@types/node@18.17.19)(less@4.2.0) + vite: 4.5.0(@types/node@20.9.2)(less@4.2.0) transitivePeerDependencies: - supports-color dev: true @@ -30542,7 +30542,7 @@ packages: strip-ansi: 6.0.1 tiny-invariant: 1.3.1 typescript: 5.1.6 - vite: 4.5.0(@types/node@18.17.19)(less@4.2.0) + vite: 4.5.0(@types/node@20.9.2)(less@4.2.0) vscode-languageclient: 7.0.0 vscode-languageserver: 7.0.0 vscode-languageserver-textdocument: 1.0.11 @@ -30671,7 +30671,7 @@ packages: debug: 4.3.4(supports-color@8.1.1) globrex: 0.1.2 tsconfck: 2.1.2(typescript@5.1.6) - vite: 4.5.0(@types/node@18.17.19)(less@4.2.0) + vite: 4.5.0(@types/node@20.9.2)(less@4.2.0) transitivePeerDependencies: - supports-color - typescript diff --git a/services/workflows-service/prisma/data-migrations b/services/workflows-service/prisma/data-migrations index 15605f1283..b9abb90239 160000 --- a/services/workflows-service/prisma/data-migrations +++ b/services/workflows-service/prisma/data-migrations @@ -1 +1 @@ -Subproject commit 15605f12839444ca8f0d34381deebdacb625b38b +Subproject commit b9abb90239b0943f43f044fe0b9959ec2ae976ca diff --git a/services/workflows-service/src/workflow/schemas/zod-schemas.ts b/services/workflows-service/src/workflow/schemas/zod-schemas.ts index c0de3120d2..6ff7e0dd08 100644 --- a/services/workflows-service/src/workflow/schemas/zod-schemas.ts +++ b/services/workflows-service/src/workflow/schemas/zod-schemas.ts @@ -19,6 +19,7 @@ export const ConfigSchema = z isLockedDocumentCategoryAndType: z.boolean().optional(), allowMultipleActiveWorkflows: z.boolean().optional(), initialEvent: z.string().optional(), + availableDocuments: z.array(z.object({ category: z.string(), type: z.string() })).optional(), callbackResult: z .object({ transformers: z.array(z.any()), diff --git a/services/workflows-service/src/workflow/utils/add-properties-schema-to-document.ts b/services/workflows-service/src/workflow/utils/add-properties-schema-to-document.ts index d1af7ed9f5..fc3ee1e6d9 100644 --- a/services/workflows-service/src/workflow/utils/add-properties-schema-to-document.ts +++ b/services/workflows-service/src/workflow/utils/add-properties-schema-to-document.ts @@ -4,7 +4,6 @@ import { getDocumentsByCountry, isObject, TDocument, - type TDocumentsWithAvailability, } from '@ballerine/common'; import { WorkflowDefinition } from '@prisma/client'; @@ -17,7 +16,7 @@ export const addPropertiesSchemaToDocument = ( (documentSchema && getPropertiesFromDefinition( document, - documentSchema as TDocumentsWithAvailability, + documentSchema as TDocument[], document?.issuer?.country, )) || getPropertiesSchemaForDocument(document); @@ -37,10 +36,10 @@ function getPropertiesSchemaForDocument(document: DefaultContextSchema['document const getPropertiesFromDefinition = ( document: DefaultContextSchema['documents'][number], - documentsSchema: TDocumentsWithAvailability, + documentsSchema: TDocument[], countryCode: string, ): ReturnType | undefined => { - const localizedDocumentSchemas = documentsSchema.schema.filter( + const localizedDocumentSchemas = documentsSchema.filter( documentSchema => documentSchema.issuer.country === countryCode, );