Skip to content

Commit

Permalink
Associated companies fixes (#2159)
Browse files Browse the repository at this point in the history
* fix(*): associated companies bug fixes

* feat(*): added a flag to enable the initiate kyb button for associated

* feat(*): version packages

* fix(workflows-service): fixed missing test dependency
  • Loading branch information
Omri-Levy authored Mar 6, 2024
1 parent ed96e21 commit efa2017
Show file tree
Hide file tree
Showing 48 changed files with 385 additions and 58 deletions.
9 changes: 9 additions & 0 deletions apps/backoffice-v2/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# @ballerine/backoffice-v2

## 0.5.53

### Patch Changes

- Updated dependencies
- @ballerine/common@0.7.47
- @ballerine/workflow-browser-sdk@0.5.47
- @ballerine/workflow-node-sdk@0.5.47

## 0.5.52

### 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.52",
"version": "0.5.53",
"description": "Ballerine - Backoffice",
"homepage": "https://github.com/ballerine-io/ballerine",
"repository": {
Expand Down Expand Up @@ -51,10 +51,10 @@
},
"dependencies": {
"@ballerine/blocks": "0.1.28",
"@ballerine/common": "0.7.46",
"@ballerine/common": "0.7.47",
"@ballerine/ui": "^0.3.30",
"@ballerine/workflow-browser-sdk": "0.5.46",
"@ballerine/workflow-node-sdk": "0.5.46",
"@ballerine/workflow-browser-sdk": "0.5.47",
"@ballerine/workflow-node-sdk": "0.5.47",
"@fontsource/inter": "^4.5.15",
"@formkit/auto-animate": "1.0.0-beta.5",
"@hookform/resolvers": "^3.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const WorkflowDefinitionConfigSchema = z
.object({
enableManualCreation: z.boolean().default(false),
isManualCreation: z.boolean().default(false),
isAssociatedCompanyKybEnabled: z.boolean().default(false),
})
.passthrough()
.nullable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const motionButtonProps = {
export const useAssociatedCompaniesBlock = ({
workflows,
dialog,
isAssociatedCompanyKybEnabled,
}: {
workflows: TWorkflowById[];
dialog: {
Expand All @@ -30,6 +31,7 @@ export const useAssociatedCompaniesBlock = ({
}>;
Close: FunctionComponent<{ associatedCompany: ReturnType<typeof associatedCompanyAdapter> }>;
};
isAssociatedCompanyKybEnabled: boolean;
}) => {
const transformedAssociatedCompanies = useMemo(
() => workflows?.map(workflow => associatedCompanyAdapter(workflow)),
Expand Down Expand Up @@ -143,7 +145,8 @@ export const useAssociatedCompaniesBlock = ({
})
.build()
.flat(1),
...(associatedCompany?.nextEvents?.includes('START_ASSOCIATED_COMPANY_KYB')
...(isAssociatedCompanyKybEnabled &&
associatedCompany?.nextEvents?.includes('START_ASSOCIATED_COMPANY_KYB')
? createBlocksTyped()
.addBlock()
.addCell({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@ export const useDefaultBlocksLogic = () => {
</Button>
),
},
isAssociatedCompanyKybEnabled:
!!workflow?.workflowDefinition?.config?.isAssociatedCompanyKybEnabled,
});

const associatedCompaniesInformationBlock = useAssociatedCompaniesInformationBlock(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ export const useKybExampleBlocksLogic = () => {
</>
),
},
isAssociatedCompanyKybEnabled:
!!workflow?.workflowDefinition?.config?.isAssociatedCompanyKybEnabled,
});
const associatedCompaniesInformationBlock = useAssociatedCompaniesInformationBlock(
kybChildWorkflows ?? [],
Expand Down
8 changes: 8 additions & 0 deletions apps/kyb-app/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# kyb-app

## 0.1.48

### Patch Changes

- Updated dependencies
- @ballerine/common@0.7.47
- @ballerine/workflow-browser-sdk@0.5.47

## 0.1.47

### 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.47",
"version": "0.1.48",
"type": "module",
"scripts": {
"dev": "vite",
Expand All @@ -15,9 +15,9 @@
},
"dependencies": {
"@ballerine/blocks": "0.1.28",
"@ballerine/common": "^0.7.46",
"@ballerine/common": "^0.7.47",
"@ballerine/ui": "0.3.30",
"@ballerine/workflow-browser-sdk": "0.5.46",
"@ballerine/workflow-browser-sdk": "0.5.47",
"@lukemorales/query-key-factory": "^1.0.3",
"@radix-ui/react-icons": "^1.3.0",
"@rjsf/core": "^5.9.0",
Expand Down
8 changes: 8 additions & 0 deletions examples/headless-example/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @ballerine/headless-example

## 0.1.47

### Patch Changes

- Updated dependencies
- @ballerine/common@0.7.47
- @ballerine/workflow-browser-sdk@0.5.47

## 0.1.46

### 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.46",
"version": "0.1.47",
"type": "module",
"scripts": {
"spellcheck": "cspell \"*\"",
Expand Down Expand Up @@ -34,8 +34,8 @@
"vite": "^4.1.0"
},
"dependencies": {
"@ballerine/common": "0.7.46",
"@ballerine/workflow-browser-sdk": "0.5.46",
"@ballerine/common": "0.7.47",
"@ballerine/workflow-browser-sdk": "0.5.47",
"@felte/reporter-svelte": "^1.1.5",
"@felte/validator-zod": "^1.0.13",
"@fontsource/inter": "^4.5.15",
Expand Down
6 changes: 6 additions & 0 deletions packages/common/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @ballerine/common

## 0.7.47

### Patch Changes

- Version bump existing changes

## 0.7.46

### 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.46",
"version": "0.7.47",
"description": "common",
"module": "./dist/esm/index.js",
"main": "./dist/cjs/index.js",
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export {
uniqueArray,
zodErrorToReadable,
isNonEmptyArray,
zodBuilder,
} from './utils';

export type { IErrorWithMessage } from './utils';
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ export { log } from './log';
export { replaceNullsWithUndefined } from './replace-null-with-undefined';
export { dump } from './dump';
export { isNonEmptyArray } from './is-non-empty-array';
export { zodBuilder } from './zod-builder';
export { type IErrorWithMessage } from './is-error-with-message';
1 change: 1 addition & 0 deletions packages/common/src/utils/zod-builder/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './zod-builder';
6 changes: 6 additions & 0 deletions packages/common/src/utils/zod-builder/zod-builder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { ZodTypeAny } from 'zod';

export const zodBuilder =
<TType>() =>
<TSchema extends ZodTypeAny & { _output: TType }>(schema: TSchema) =>
schema;
3 changes: 3 additions & 0 deletions packages/workflow-core/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/** @type {import('eslint').Linter.Config} */
module.exports = {
extends: ['@ballerine/eslint-config'],
parserOptions: {
project: './tsconfig.eslint.json',
},
};
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.47

### Patch Changes

- Version bump existing changes
- Updated dependencies
- @ballerine/common@0.7.47

## 0.5.46

### 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.46",
"version": "0.5.47",
"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.46",
"@ballerine/common": "0.7.47",
"ajv": "^8.12.0",
"i18n-iso-countries": "^7.6.0",
"jmespath": "^0.16.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export class IterativePlugin {
}

console.log('All actions completed successfully');

return { callbackAction: this.successAction };
}

Expand All @@ -51,11 +52,14 @@ export class IterativePlugin {
for (const transformer of transformers) {
mutatedRecord = await this.transformByTransformer(transformer, mutatedRecord);
}

return mutatedRecord;
}

async transformByTransformer(transformer: Transformer, record: AnyRecord) {
console.log(`transformByTransformer() called for mapping: ${transformer.mapping}`);
console.log(
`transformByTransformer() called for mapping: ${JSON.stringify(transformer.mapping)}`,
);

try {
return (await transformer.transform(record, { input: 'json', output: 'json' })) as AnyRecord;
Expand All @@ -71,6 +75,7 @@ export class IterativePlugin {

composeErrorResponse(errorMessage: string) {
console.error(`Composing error response with message: ${errorMessage}`);

return { callbackAction: this.errorAction, error: errorMessage };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import { search } from 'jmespath';
import { AnyRecord } from '@ballerine/common';
import merge from 'lodash.merge';

export type THelperMethod = 'regex' | 'imageUrlToBase64' | 'remove' | 'mergeArrayEachItemWithValue';
export type THelperMethod =
| 'regex'
| 'imageUrlToBase64'
| 'remove'
| 'mergeArrayEachItemWithValue'
| 'omit';
export class HelpersTransformer extends BaseContextTransformer {
name = 'helpers-transformer';
mapping: THelperFormatingLogic;
Expand Down Expand Up @@ -36,12 +41,13 @@ export class HelpersTransformer extends BaseContextTransformer {

mergeArrayEachItemWithValue(
context: Parameters<typeof this.transform>[0],
attribute: Array<AnyRecord>,
attribute: AnyRecord[],
_value: string,
options: { mapJmespath: string; mergeWithJmespath: string },
) {
const jmespathResult = search(context, options.mapJmespath);
const mergeWithResult = search(context, options.mergeWithJmespath);

if (!jmespathResult || !mergeWithResult) {
console.warn(
'mergeArrayEachItemWithValue: jmespathResult or mergeWithResult is null',
Expand All @@ -61,7 +67,7 @@ export class HelpersTransformer extends BaseContextTransformer {
return jmespathResult.map((item: AnyRecord) => merge(item, mergeWithResult));
}

remove(..._args: Array<any>) {
remove(..._args: any[]) {
return undefined;
}

Expand Down Expand Up @@ -93,14 +99,15 @@ export class HelpersTransformer extends BaseContextTransformer {
return base64Prefix + base64Image;
}

getNestedProperty(record: Record<string, any>, path: Array<string>) {
getNestedProperty(record: Record<string, any>, path: string[]) {
return path.reduce((prev, curr) => {
return prev ? prev[curr] : null;
}, record);
}

setNestedProperty(obj: Record<string, any>, path: Array<string>, value: unknown) {
setNestedProperty(obj: Record<string, any>, path: string[], value: unknown) {
let current = obj;

for (let i = 0; i < path.length; i++) {
if (i === path.length - 1) {
current[path[i] as keyof typeof current] = value;
Expand All @@ -111,4 +118,14 @@ export class HelpersTransformer extends BaseContextTransformer {
}
}
}

omit(_context: TContext, attribute: AnyRecord, value: string[]) {
const result = structuredClone(attribute);

for (const key of value) {
delete result[key];
}

return result;
}
}
Loading

0 comments on commit efa2017

Please sign in to comment.