Skip to content

Commit

Permalink
refactor(workflow): remove createCollectionFlowToken references
Browse files Browse the repository at this point in the history
- Clean up the workflow configuration schema by removing the createCollectionFlowToken option
- Update various workflow definition files to eliminate obsolete token settings

(your code was so cluttered, it looked like a toddler's art project on a bad day)
  • Loading branch information
tomer-shvadron committed Nov 18, 2024
1 parent d25cf30 commit 60e8f29
Show file tree
Hide file tree
Showing 10 changed files with 1 addition and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ export const WorkflowConfigSchema = Type.Object({
availableDocuments: Type.Optional(Type.Array(AvailableDocumentSchema)),
callbackResult: Type.Optional(CallbackResultSchema),
childCallbackResults: Type.Optional(Type.Array(ChildCallbackResultSchema)),
createCollectionFlowToken: Type.Optional(Type.Boolean()),
mainRepresentative: Type.Optional(MainRepresentativeSchema),
customerName: Type.Optional(Type.String()),
enableManualCreation: Type.Optional(Type.Boolean()),
Expand Down
2 changes: 1 addition & 1 deletion services/workflows-service/prisma/data-migrations
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ export const dynamicUiWorkflowDefinition = {
language: 'en',
supportedLanguages: ['en', 'cn'],
initialEvent: 'START',
createCollectionFlowToken: true,
childCallbackResults: [
{
definitionId: kycEmailSessionDefinition.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ export const kybKycWorkflowDefinition = {
deliverEvent: 'KYC_RESPONDED',
},
],
createCollectionFlowToken: true,
},
contextSchema: {
type: 'json-schema',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export const composeChildAssociatedCompanyDefinition = ({
apiPlugins: [],
},
config: {
createCollectionFlowToken: true,
workflowLevelResolution: true,
},
projectId: projectId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ export const composeKybWithAssociatedCompaniesDefinition = ({
},
config: {
isExample: true,
createCollectionFlowToken: true,
workflowLevelResolution: true,
childCallbackResults: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export const composeKycChildWorkflowDefinition = ({
apiPlugins: [],
},
config: {
createCollectionFlowToken: true,
workflowLevelResolution: true,
isCaseOverviewEnabled: true,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ export const ConfigSchema = z
.optional(),
)
.optional(),
createCollectionFlowToken: z
.boolean()
.optional()
.describe('Whether to create a collection flow token as part of the workflow'),
mainRepresentative: z
.object({
fullName: z.string(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,6 @@ export class WorkflowControllerExternal {
workflowDefinitionId: actionResult[0]?.workflowDefinition.id,
workflowRuntimeId: actionResult[0]?.workflowRuntimeData.id,
ballerineEntityId: actionResult[0]?.ballerineEntityId,
entities: actionResult[0]?.entities,
});
}

Expand Down
91 changes: 0 additions & 91 deletions services/workflows-service/src/workflow/workflow.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,9 @@ import {
} from '@/workflow/workflow-runtime-list-item.model';
import {
AnyRecord,
buildCollectionFlowState,
CollectionFlowStatusesEnum,
DefaultContextSchema,
getDocumentId,
getOrderedSteps,
isErrorWithMessage,
isObject,
ProcessStatus,
Expand Down Expand Up @@ -100,7 +98,6 @@ import { plainToClass } from 'class-transformer';
import dayjs from 'dayjs';
import { isEqual, merge } from 'lodash';
import mime from 'mime';
import { WORKFLOW_FINAL_STATES } from './consts';
import { WorkflowDefinitionCreateDto } from './dtos/workflow-definition-create';
import { WorkflowDefinitionFindManyArgs } from './dtos/workflow-definition-find-many-args';
import { WorkflowDefinitionUpdateInput } from './dtos/workflow-definition-update-input';
Expand Down Expand Up @@ -1444,12 +1441,6 @@ export class WorkflowService {
validatedConfig || {},
) as InputJsonValue;

const entities: Array<{
id: string;
type: 'individual' | 'business';
tags?: Array<'mainRepresentative' | 'UBO'>;
}> = [];

// Creating new workflow
if (
!existingWorkflowRuntimeData ||
Expand Down Expand Up @@ -1519,87 +1510,6 @@ export class WorkflowService {
workflowRuntimeData,
});

let endUserId: string | null = null;
const entityData =
workflowRuntimeData.context.entity?.data?.additionalInfo?.mainRepresentative;

if (mergedConfig.createCollectionFlowToken) {
if (entityType === 'endUser') {
endUserId = entityId;
entities.push({ type: 'individual', id: entityId });
} else if (entityData) {
endUserId = await this.__generateEndUserWithBusiness({
entityType,
workflowRuntimeData,
entityData: entityData,
currentProjectId,
entityId,
position: BusinessPosition.representative,
});

entities.push({
type: 'individual',
id: endUserId,
});

entities.push({ type: 'business', id: entityId });

if (entityData) {
workflowRuntimeData.context.entity.data.additionalInfo.mainRepresentative.ballerineEntityId =
endUserId;
}
}

const nowPlus30Days = new Date(Date.now() + 30 * 24 * 60 * 60 * 1000);
const workflowToken = await this.workflowTokenService.create(
currentProjectId,
{
workflowRuntimeDataId: workflowRuntimeData.id,
endUserId: endUserId ?? null,
expiresAt: nowPlus30Days,
},
transaction,
);

const collectionFlow = buildCollectionFlowState({
apiUrl: env.APP_API_URL,
steps: uiDefinition?.definition
? getOrderedSteps(
(uiDefinition?.definition as Prisma.JsonObject)?.definition as Record<
string,
Record<string, unknown>
>,
{ finalStates: [...WORKFLOW_FINAL_STATES] },
).map(stepName => ({
stateName: stepName,
}))
: [],
additionalInformation: {
customerCompany: customer.displayName,
},
});

workflowRuntimeData = await this.workflowRuntimeDataRepository.updateStateById(
workflowRuntimeData.id,
{
data: {
context: {
...workflowRuntimeData.context,
collectionFlow,
metadata: {
...(workflowRuntimeData.context.metadata ?? {}),
token: workflowToken.token,
collectionFlowUrl: env.COLLECTION_FLOW_URL,
webUiSDKUrl: env.WEB_UI_SDK_URL,
},
} as InputJsonValue,
projectId: currentProjectId,
},
},
transaction,
);
}

if (mergedConfig?.initialEvent) {
workflowRuntimeData = await this.event(
{
Expand Down Expand Up @@ -1680,7 +1590,6 @@ export class WorkflowService {
workflowDefinition,
workflowRuntimeData,
ballerineEntityId: entityId,
entities,
},
] as const;
});
Expand Down

0 comments on commit 60e8f29

Please sign in to comment.