Skip to content

Commit

Permalink
Blokh/feat/generate document schema configurations (#1716)
Browse files Browse the repository at this point in the history
* added documents schema to workflow def

* updated defintion logic handling of documents

* feat: generate the functionality of showing only relevant schemas to the documents when they're set

* s

* feat: updated schema of config and docs + common bump

* minor refactoring

* updated documents schema

* packages updated new release
  • Loading branch information
Blokh authored Nov 30, 2023
1 parent 2d05cb1 commit 591c20a
Show file tree
Hide file tree
Showing 33 changed files with 350 additions and 81 deletions.
10 changes: 10 additions & 0 deletions apps/backoffice-v2/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# @ballerine/backoffice-v2

## 0.5.29

### Patch Changes

- Updated dependencies
- Updated dependencies [59afd0b4]
- @ballerine/common@0.7.27
- @ballerine/workflow-browser-sdk@0.5.26
- @ballerine/workflow-node-sdk@0.5.26

## 0.5.28

### Patch Changes
Expand Down
8 changes: 4 additions & 4 deletions apps/backoffice-v2/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ballerine/backoffice-v2",
"version": "0.5.28",
"version": "0.5.29",
"description": "Ballerine - Backoffice",
"homepage": "https://github.com/ballerine-io/ballerine",
"repository": {
Expand Down Expand Up @@ -51,9 +51,9 @@
},
"dependencies": {
"@ballerine/ui": "0.3.16",
"@ballerine/common": "0.7.26",
"@ballerine/workflow-browser-sdk": "0.5.25",
"@ballerine/workflow-node-sdk": "0.5.25",
"@ballerine/common": "0.7.27",
"@ballerine/workflow-browser-sdk": "0.5.26",
"@ballerine/workflow-node-sdk": "0.5.26",
"@fontsource/inter": "^4.5.15",
"@formkit/auto-animate": "1.0.0-beta.5",
"@hookform/resolvers": "^3.1.0",
Expand Down
1 change: 1 addition & 0 deletions apps/backoffice-v2/src/domains/workflows/fetchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export const BaseWorkflowByIdSchema = z.object({
workflowDefinition: ObjectWithIdSchema.extend({
name: z.string(),
contextSchema: z.record(z.any(), z.any()).nullable(),
documentsSchema: z.array(z.any()).optional(),
config: z.record(z.any(), z.any()).nullable(),
}),
createdAt: z.string().datetime(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ export interface IEditableDetails {
}>;
title: string;
workflowId: string;
config: Record<string, unknown>;
}
8 changes: 6 additions & 2 deletions apps/backoffice-v2/src/pages/Entity/hooks/useEntity/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ const composeDataFormCell = (
cellName: string,
categoryDropdownOptions: TDropdownOption[],
value: string,
isEditable: boolean,
) => {
return {
[cellName]: {
title: cellName,
type: 'string',
dropdownOptions: categoryDropdownOptions,
value: value,
isEditable,
},
};
};
Expand All @@ -33,6 +35,7 @@ export const composePickableCategoryType = (
categoryValue: string,
typeValue: string,
documentsSchemas: TDocument[],
config?: Record<any, any> | null,
) => {
const documentCategoryDropdownOptions: Array<TDropdownOption> = [];
const documentTypesDropdownOptions: Array<TDropdownOption> = [];
Expand All @@ -57,10 +60,11 @@ export const composePickableCategoryType = (

const categoryDropdownOptions = uniqueArrayByKey(documentCategoryDropdownOptions, 'value');
const typeDropdownOptions = documentTypesDropdownOptions;
const isEditable = !(config?.isLockedDocumentCategoryAndType === true);

return {
...composeDataFormCell('category', categoryDropdownOptions, categoryValue),
...composeDataFormCell('type', typeDropdownOptions, typeValue),
...composeDataFormCell('category', categoryDropdownOptions, categoryValue, isEditable),
...composeDataFormCell('type', typeDropdownOptions, typeValue, isEditable),
};
};
export const isExistingSchemaForDocument = (documentsSchemas: Array<TDocument>) => {
Expand Down
46 changes: 44 additions & 2 deletions apps/backoffice-v2/src/pages/Entity/hooks/useTasks/useTasks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ import {
import {
CommonWorkflowStates,
getDocumentsByCountry,
getDocumentSchemaByCountry,
isNullish,
StateTag,
TAvailableDocuments,
TDocument,
} from '@ballerine/common';
import * as React from 'react';
import { ComponentProps, useMemo } from 'react';
Expand Down Expand Up @@ -41,6 +44,35 @@ const pluginsOutputBlacklist = [
'website_monitoring',
];

function getDocumentsSchemas(issuerCountryCode, workflow: TWorkflowById) {
return (
issuerCountryCode &&
getDocumentSchemaByCountry(
issuerCountryCode,
workflow.workflowDefinition?.documentsSchema as TDocument[],
)
.concat(getDocumentsByCountry(issuerCountryCode))
.reduce((unique: TDocument[], item: TDocument) => {
const isDuplicate = unique.some(u => u.type === item.type && u.category === item.category);
if (!isDuplicate) {
unique.push(item);
}
return unique;
}, [] as TDocument[])
.filter((documentSchema: TDocument) => {
if (!workflow.workflowDefinition.config?.availableDocuments) return true;

const isIncludes = !!workflow.workflowDefinition.config?.availableDocuments.find(
(availableDocument: TAvailableDocuments[number]) =>
availableDocument.type === documentSchema.type &&
availableDocument.category === documentSchema.category,
);

return isIncludes;
})
);
}

export const useTasks = ({
workflow,
entity,
Expand Down Expand Up @@ -100,7 +132,8 @@ export const useTasks = ({
});
const { data: locations } = useNominatimQuery(address);
const issuerCountryCode = extractCountryCodeFromWorkflow(workflow);
const documentsSchemas = !!issuerCountryCode && getDocumentsByCountry(issuerCountryCode);

const documentsSchemas = getDocumentsSchemas(issuerCountryCode, workflow);

const registryInfoBlock =
Object.keys(filteredPluginsOutput ?? {}).length === 0
Expand Down Expand Up @@ -181,7 +214,12 @@ export const useTasks = ({
({ id, type: docType, category, properties, propertiesSchema, decision }, docIndex) => {
const additionProperties =
isExistingSchemaForDocument(documentsSchemas) &&
composePickableCategoryType(category, docType, documentsSchemas);
composePickableCategoryType(
category,
docType,
documentsSchemas,
workflow.workflowDefinition?.config,
);

const isDoneWithRevision =
decision?.status === 'revised' && parentMachine?.status === 'completed';
Expand Down Expand Up @@ -1567,3 +1605,7 @@ export const useTasks = ({
removeDecisionById,
]);
};

function uniqueArrayByKey(arg0: any) {
throw new Error('Function not implemented.');
}
9 changes: 9 additions & 0 deletions apps/kyb-app/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# kyb-app

## 0.1.23

### Patch Changes

- Updated dependencies
- Updated dependencies [59afd0b4]
- @ballerine/common@0.7.27
- @ballerine/workflow-browser-sdk@0.5.26

## 0.1.22

### Patch Changes
Expand Down
6 changes: 3 additions & 3 deletions apps/kyb-app/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@ballerine/kyb-app",
"private": true,
"version": "0.1.22",
"version": "0.1.23",
"type": "module",
"scripts": {
"dev": "vite",
Expand All @@ -16,8 +16,8 @@
"dependencies": {
"@ballerine/blocks": "0.1.21",
"@ballerine/ui": "0.3.16",
"@ballerine/common": "^0.7.26",
"@ballerine/workflow-browser-sdk": "0.5.25",
"@ballerine/common": "^0.7.27",
"@ballerine/workflow-browser-sdk": "0.5.26",
"@lukemorales/query-key-factory": "^1.0.3",
"@radix-ui/react-icons": "^1.3.0",
"@rjsf/core": "^5.9.0",
Expand Down
9 changes: 9 additions & 0 deletions examples/headless-example/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# @ballerine/headless-example

## 0.1.26

### Patch Changes

- Updated dependencies
- Updated dependencies [59afd0b4]
- @ballerine/common@0.7.27
- @ballerine/workflow-browser-sdk@0.5.26

## 0.1.25

### Patch Changes
Expand Down
6 changes: 3 additions & 3 deletions examples/headless-example/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@ballerine/headless-example",
"private": true,
"version": "0.1.25",
"version": "0.1.26",
"type": "module",
"scripts": {
"spellcheck": "cspell \"*\"",
Expand Down Expand Up @@ -34,8 +34,8 @@
"vite": "^4.1.0"
},
"dependencies": {
"@ballerine/common": "0.7.26",
"@ballerine/workflow-browser-sdk": "0.5.25",
"@ballerine/common": "0.7.27",
"@ballerine/workflow-browser-sdk": "0.5.26",
"@felte/reporter-svelte": "^1.1.5",
"@felte/validator-zod": "^1.0.13",
"@fontsource/inter": "^4.5.15",
Expand Down
7 changes: 7 additions & 0 deletions packages/common/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @ballerine/common

## 0.7.27

### Patch Changes

- added types and functionality to documents
- 59afd0b4: updated types and functionalities

## 0.7.26

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"private": false,
"name": "@ballerine/common",
"author": "Ballerine <[email protected]>",
"version": "0.7.26",
"version": "0.7.27",
"description": "common",
"module": "./dist/esm/index.js",
"main": "./dist/cjs/index.js",
Expand Down
8 changes: 7 additions & 1 deletion packages/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,18 @@ export {

export type { IErrorWithMessage } from './utils';
export type { Serializable, AnyRecord } from './types';
export type { DefaultContextSchema, TDefaultSchemaDocumentPage, TDocument } from './schemas';
export type {
DefaultContextSchema,
TDefaultSchemaDocumentPage,
TDocument,
TAvailableDocuments,
} from './schemas';

export {
getGhanaDocuments,
getDocumentsByCountry,
getDocumentId,
getDocumentSchemaByCountry,
defaultContextSchema,
} from './schemas';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ export const getDocumentsByCountry = (countryCode: (typeof countryCodes)[number]
return documentIdsByCountry[countryCode]?.() || [];
};

export const getDocumentSchemaByCountry = (
countryCode: (typeof countryCodes)[number],
documentsSchema: TDocument[] | undefined,
): TDocument[] => {
return (
documentsSchema?.filter(documentSchema => documentSchema.issuer.country === countryCode) || []
);
};

export const getDocumentId = (
document: TDocument | DefaultContextSchema['documents'][number],
useUuid = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ import { JSONSchema7 } from 'json-schema';
export type TDocument = Omit<DefaultContextSchema['documents'][number], 'pages' | 'properties'> & {
propertiesSchema: JSONSchema7;
};

export type TAvailableDocuments = Array<{ category: string; type: string }>;
2 changes: 2 additions & 0 deletions packages/common/src/schemas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +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 TAvailableDocuments } from './documents/workflow/documents/types';
export { getDocumentSchemaByCountry } from './documents/workflow/documents/schemas/index';
8 changes: 8 additions & 0 deletions packages/workflow-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @ballerine/workflow-core

## 0.5.26

### Patch Changes

- Updated dependencies
- Updated dependencies [59afd0b4]
- @ballerine/common@0.7.27

## 0.5.25

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/workflow-core/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@ballerine/workflow-core",
"author": "Ballerine <[email protected]>",
"version": "0.5.25",
"version": "0.5.26",
"description": "workflow-core",
"module": "./dist/esm/index.js",
"main": "./dist/cjs/index.js",
Expand Down Expand Up @@ -31,7 +31,7 @@
"node": ">=12"
},
"dependencies": {
"@ballerine/common": "0.7.26",
"@ballerine/common": "0.7.27",
"ajv": "^8.12.0",
"i18n-iso-countries": "^7.6.0",
"jmespath": "^0.16.0",
Expand Down
Loading

0 comments on commit 591c20a

Please sign in to comment.