Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dow Jones ongoing changes #2836

Merged
merged 3 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/backoffice-v2/postcss.config.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
modules: true,
plugins: {
'tailwindcss/nesting': {},
tailwindcss: {},
autoprefixer: {},
},
Expand Down
2 changes: 2 additions & 0 deletions packages/common/src/schemas/documents/schemas/aml-schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Type } from '@sinclair/typebox';
import { TypeStringEnum } from '@/schemas/documents/workflow/documents/schemas/utils';

const HitDataSchema = Type.Object({
date: Type.Union([Type.Null(), Type.String()]),
Expand Down Expand Up @@ -28,5 +29,6 @@ export const AmlSchema = Type.Optional(
endUserId: Type.String(),
matchStatus: Type.String(),
checkType: Type.String({ enum: ['initial_result', 'updated_result'] }),
vendor: TypeStringEnum(['veriff', 'dow-jones']),
}),
);
2 changes: 1 addition & 1 deletion packages/common/src/schemas/workflow/end-user.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const SourceSchema = z.object({

const AmlHitSchema = z.object({
vendor: z.enum(['veriff', 'test', 'dow-jones']),
matchedName: z.string(),
matchedName: z.string().nullable(),
countries: z.array(z.string()),
matchTypes: z.array(z.string()),
warnings: z.array(SourceSchema),
Expand Down
3 changes: 2 additions & 1 deletion services/workflows-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
"db:data-migration:generate": "plop --plopfile ./prisma/data-migrations/plopfile.js --dest ./",
"db:data-migration:migrate": "rimraf ./dist && npm run build && nest start --entryFile ./src/data-migration/scripts/migrate",
"db:data-sync": "nest start --entryFile ./src/data-migration/scripts/sync/run",
"db:data-migration:import": "tsx ./src/data-migration/scripts/import"
"db:data-migration:import": "tsx ./src/data-migration/scripts/import",
"run-validation": "tsx ./scripts/run-validation.ts"
},
"dependencies": {
"@aws-sdk/client-s3": "3.347.1",
Expand Down
17 changes: 17 additions & 0 deletions services/workflows-service/scripts/run-validation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { z } from 'zod';

// 1. Define data to validate
const data = {};
Omri-Levy marked this conversation as resolved.
Show resolved Hide resolved
// 2. Import a validation schema
const result = z.object({}).parse(data);
Omri-Levy marked this conversation as resolved.
Show resolved Hide resolved

console.dir(
{
status: 'Validation passed',
// 3. Log data post transforms
data: result,
},
{
depth: Infinity,
},
);
Omri-Levy marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class WebhooksService {

const amlHits = hits.map(hit => ({
...hit,
vendor: 'veriff',
vendor: data?.vendor,
}));

await this.endUserService.updateById(endUserId, {
Expand Down
20 changes: 11 additions & 9 deletions services/workflows-service/src/workflow/workflow.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1562,15 +1562,17 @@ export class WorkflowService {

const collectionFlow = buildCollectionFlowState({
apiUrl: env.APP_API_URL,
steps: getOrderedSteps(
(uiDefinition?.definition as Prisma.JsonObject)?.definition as Record<
string,
Record<string, unknown>
>,
{ finalStates: [...WORKFLOW_FINAL_STATES] },
).map(stepName => ({
stateName: stepName,
})),
steps: uiDefinition?.definition
? getOrderedSteps(
(uiDefinition?.definition as Prisma.JsonObject)?.definition as Record<
string,
Record<string, unknown>
>,
{ finalStates: [...WORKFLOW_FINAL_STATES] },
).map(stepName => ({
stateName: stepName,
}))
: [],
Comment on lines +1566 to +1576
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Improve type safety and null checks in steps handling

The current implementation has several type safety and potential null reference issues:

  1. Multiple type assertions could lead to runtime errors
  2. Missing null check for uiDefinition before accessing definition
  3. Complex nested property access without proper type guards

Consider refactoring using this safer approach:

-            steps: uiDefinition?.definition
-              ? getOrderedSteps(
-                  (uiDefinition?.definition as Prisma.JsonObject)?.definition as Record<
-                    string,
-                    Record<string, unknown>
-                  >,
-                  { finalStates: [...WORKFLOW_FINAL_STATES] },
-                ).map(stepName => ({
-                  stateName: stepName,
-                }))
-              : [],
+            steps: (() => {
+              const definition = uiDefinition?.definition;
+              if (!definition || typeof definition !== 'object') return [];
+              
+              const stateDefinition = (definition as Prisma.JsonObject)?.definition;
+              if (!stateDefinition || typeof stateDefinition !== 'object') return [];
+              
+              return getOrderedSteps(
+                stateDefinition as Record<string, Record<string, unknown>>,
+                { finalStates: [...WORKFLOW_FINAL_STATES] }
+              ).map(stepName => ({
+                stateName: stepName,
+              }));
+            })(),

Additionally:

  1. Consider extracting the steps transformation logic into a separate method for better maintainability
  2. Add documentation for the WORKFLOW_FINAL_STATES array to clarify its purpose
  3. Consider adding validation for the step name format
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
steps: uiDefinition?.definition
? getOrderedSteps(
(uiDefinition?.definition as Prisma.JsonObject)?.definition as Record<
string,
Record<string, unknown>
>,
{ finalStates: [...WORKFLOW_FINAL_STATES] },
).map(stepName => ({
stateName: stepName,
}))
: [],
steps: (() => {
const definition = uiDefinition?.definition;
if (!definition || typeof definition !== 'object') return [];
const stateDefinition = (definition as Prisma.JsonObject)?.definition;
if (!stateDefinition || typeof stateDefinition !== 'object') return [];
return getOrderedSteps(
stateDefinition as Record<string, Record<string, unknown>>,
{ finalStates: [...WORKFLOW_FINAL_STATES] }
).map(stepName => ({
stateName: stepName,
}));
})(),

additionalInformation: {
customerCompany: customer.displayName,
},
Expand Down
Loading