Skip to content

Commit

Permalink
Revert "Signup page leftovers (#2849)"
Browse files Browse the repository at this point in the history
This reverts commit 0f7a4d2.
  • Loading branch information
tomer-shvadron committed Dec 1, 2024
1 parent 27e0342 commit fb5e52b
Show file tree
Hide file tree
Showing 18 changed files with 175 additions and 229 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ 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
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ export const buildCollectionFlowState = (inputConfig: TCollectionFlowConfig): TC
const config: TCollectionFlow['config'] = initializeConfig(inputConfig);
const state: TCollectionFlow['state'] = initializeState(inputConfig);

return {
const collectionFlow: TCollectionFlow = {
config,
state,
additionalInformation: inputConfig.additionalInformation || {},
};

return collectionFlow;
};
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ 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,6 +229,7 @@ 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,6 +57,7 @@ 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,6 +188,7 @@ 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,6 +57,7 @@ export const composeKycChildWorkflowDefinition = ({
apiPlugins: [],
},
config: {
createCollectionFlowToken: true,
workflowLevelResolution: true,
isCaseOverviewEnabled: true,
},
Expand Down
2 changes: 1 addition & 1 deletion services/workflows-service/src/auth/auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AuthService } from './auth.service';
import { BasicStrategy } from './basic/basic.strategy';
import { PasswordService } from './password/password.service';
// eslint-disable-next-line import/no-cycle
import { UserModule } from '@/user/user.module';
import { UserModule } from '../user/user.module';
import { LocalStrategy } from '@/auth/local/local.strategy';
import { SessionSerializer } from '@/auth/session-serializer';
import { UserService } from '@/user/user.service';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Injectable } from '@nestjs/common';
import { Prisma, PrismaClient } from '@prisma/client';

import { PrismaService } from '@/prisma/prisma.service';
import { Injectable } from '@nestjs/common';
import type { PrismaTransaction, TProjectId } from '@/types';
import { PrismaService } from '@/prisma/prisma.service';

@Injectable()
export class WorkflowTokenRepository {
Expand All @@ -24,13 +23,6 @@ export class WorkflowTokenRepository {
});
}

async count(args: Prisma.WorkflowRuntimeDataTokenCountArgs, projectId: TProjectId) {
return await this.prismaService.workflowRuntimeDataToken.count({
...args,
where: { ...args.where, projectId },
});
}

async findFirstByWorkflowruntimeDataIdUnscoped(workflowRuntimeDataId: string) {
return await this.prismaService.workflowRuntimeDataToken.findFirst({
select: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,94 +1,16 @@
import { Injectable } from '@nestjs/common';
import { WorkflowTokenRepository } from '@/auth/workflow-token/workflow-token.repository';
import type { InputJsonValue, PrismaTransaction, TProjectId } from '@/types';
import { Prisma, UiDefinitionContext } from '@prisma/client';
import { buildCollectionFlowState, getOrderedSteps } from '@ballerine/common';
import { env } from '@/env';
import { WORKFLOW_FINAL_STATES } from '@/workflow/consts';
import { UiDefinitionService } from '@/ui-definition/ui-definition.service';
import { WorkflowRuntimeDataRepository } from '@/workflow/workflow-runtime-data.repository';
import { CustomerService } from '@/customer/customer.service';
import type { PrismaTransaction, TProjectId } from '@/types';

@Injectable()
export class WorkflowTokenService {
constructor(
private readonly customerService: CustomerService,
private readonly uiDefinitionService: UiDefinitionService,
private readonly workflowTokenRepository: WorkflowTokenRepository,
private readonly workflowRuntimeDataRepository: WorkflowRuntimeDataRepository,
) {}
constructor(private readonly workflowTokenRepository: WorkflowTokenRepository) {}

async create(
projectId: TProjectId,
data: Parameters<typeof this.workflowTokenRepository.create>[1],
transaction?: PrismaTransaction,
) {
const { workflowRuntimeDataId } = data;

const existingTokensForWorkflowRuntime = await this.count(
{ where: { workflowRuntimeDataId } },
projectId,
);

if (existingTokensForWorkflowRuntime === 0) {
const { workflowDefinitionId, context } = await this.workflowRuntimeDataRepository.findById(
workflowRuntimeDataId,
{ select: { workflowDefinitionId: true, context: true } },
[projectId],
);

const [uiDefinition, customer] = await Promise.all([
this.uiDefinitionService.getByWorkflowDefinitionId(
workflowDefinitionId,
UiDefinitionContext.collection_flow,
[projectId],
),
this.customerService.getByProjectId(projectId),
]);

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,
},
});

const workflowToken = await this.workflowTokenRepository.create(projectId, data, transaction);

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

return workflowToken;
}

return await this.workflowTokenRepository.create(projectId, data, transaction);
}

Expand All @@ -104,13 +26,6 @@ export class WorkflowTokenService {
return await this.workflowTokenRepository.findByTokenWithExpiredUnscoped(token);
}

async count(
args: Parameters<typeof this.workflowTokenRepository.count>[0],
projectId: TProjectId,
) {
return await this.workflowTokenRepository.count(args, projectId);
}

async deleteByToken(token: string) {
return await this.workflowTokenRepository.deleteByTokenUnscoped(token);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import { Customer, EndUser, PrismaClient, Project } from '@prisma/client';
import { noop } from 'lodash';
import { CollectionFlowService } from './collection-flow.service';
import { MerchantMonitoringClient } from '@/business-report/merchant-monitoring-client';
import { env } from '@/env';

const deps: Provider[] = [
{
Expand Down Expand Up @@ -122,7 +121,6 @@ describe('CollectionFlowService', () => {
let workflowRuntimeDataRepository: WorkflowRuntimeDataRepository;
let customerRepository: CustomerRepository;
let endUserRepository: EndUserRepository;
let uiDefinitionRepository: UiDefinitionRepository;

let customer: Customer;
let project: Project;
Expand Down Expand Up @@ -161,7 +159,6 @@ describe('CollectionFlowService', () => {
);
customerRepository = module.get<CustomerRepository>(CustomerRepository);
endUserRepository = module.get<EndUserRepository>(EndUserRepository);
uiDefinitionRepository = module.get<UiDefinitionRepository>(UiDefinitionRepository);
});

beforeEach(async () => {
Expand Down Expand Up @@ -205,16 +202,6 @@ describe('CollectionFlowService', () => {
},
});

await uiDefinitionRepository.create({
data: {
uiSchema: {},
projectId: project.id,
name: 'test-ui-definition',
uiContext: 'collection_flow',
workflowDefinitionId: workflowDefinition.id,
},
});

const workflowRuntimeData = await workflowRuntimeDataRepository.create({
data: {
workflowDefinitionId: workflowDefinition.id,
Expand All @@ -233,28 +220,7 @@ describe('CollectionFlowService', () => {

const context = await collectionFlowService.getCollectionFlowContext(token);

const expectedContext = {
metadata: {
token: token.token,
webUiSDKUrl: env.WEB_UI_SDK_URL,
collectionFlowUrl: env.COLLECTION_FLOW_URL,
},
collectionFlow: {
state: {
steps: [],
status: 'pending',
currentStep: '',
},
config: {
apiUrl: env.APP_API_URL,
},
additionalInformation: {
customerCompany: customer.displayName,
},
},
};

expect(context.context).toEqual(expectedContext);
expect(context.context).toEqual(workflowContext);
expect(context.config).toEqual(workflowConfig);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,12 @@ import { WorkflowEventEmitterService } from '@/workflow/workflow-event-emitter.s
import { WorkflowRuntimeDataRepository } from '@/workflow/workflow-runtime-data.repository';
import { WorkflowService } from '@/workflow/workflow.service';
import { CollectionFlowNoUserController } from './collection-flow.no-user.controller';
import { UiDefinitionRepository } from '@/ui-definition/ui-definition.repository';
import { ApiKeyService } from '@/customer/api-key/api-key.service';
import { ApiKeyRepository } from '@/customer/api-key/api-key.repository';

describe('CollectionFlowSignupController', () => {
let app: INestApplication;
let prismaClient: PrismaService;
let workflowTokenService: WorkflowTokenService;
let workflowDefinitionRepository: WorkflowDefinitionRepository;
let uiDefinitionRepository: UiDefinitionRepository;
let workflowRuntimeDataRepository: WorkflowRuntimeDataRepository;
let customerRepository: CustomerRepository;
let endUserRepository: EndUserRepository;
Expand All @@ -59,6 +55,8 @@ describe('CollectionFlowSignupController', () => {
controllers: [CollectionFlowNoUserController],
providers: [
{ provide: BusinessService, useValue: noop },
{ provide: UiDefinitionService, useValue: noop },
{ provide: CustomerService, useValue: noop },
{ provide: FileService, useValue: noop },
{ provide: SalesforceService, useValue: noop },
{ provide: RiskRuleService, useValue: noop },
Expand All @@ -74,11 +72,6 @@ describe('CollectionFlowSignupController', () => {
{ provide: WorkflowEventEmitterService, useValue: { emit: noop } },
WorkflowService,
EndUserService,
UiDefinitionService,
UiDefinitionRepository,
CustomerService,
ApiKeyService,
ApiKeyRepository,
BusinessReportService,
BusinessRepository,
EntityRepository,
Expand All @@ -102,7 +95,6 @@ describe('CollectionFlowSignupController', () => {
workflowDefinitionRepository = module.get<WorkflowDefinitionRepository>(
WorkflowDefinitionRepository,
);
uiDefinitionRepository = module.get<UiDefinitionRepository>(UiDefinitionRepository);
workflowRuntimeDataRepository = module.get<WorkflowRuntimeDataRepository>(
WorkflowRuntimeDataRepository,
);
Expand Down Expand Up @@ -132,16 +124,6 @@ describe('CollectionFlowSignupController', () => {
},
});

await uiDefinitionRepository.create({
data: {
uiSchema: {},
projectId: project.id,
uiContext: 'collection_flow',
name: 'signup-test-ui-definition',
workflowDefinitionId: workflowDefinition.id,
},
});

const { id: workflowRuntimeDataId } = await workflowRuntimeDataRepository.create({
data: {
workflowDefinitionId: workflowDefinition.id,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,10 @@
import { Module } from '@nestjs/common';

import { CustomerService } from '@/customer/customer.service';
import { ApiKeyService } from '@/customer/api-key/api-key.service';
import { CustomerRepository } from '@/customer/customer.repository';
import { ProjectScopeService } from '@/project/project-scope.service';
import { ApiKeyRepository } from '@/customer/api-key/api-key.repository';
import { UiDefinitionService } from '@/ui-definition/ui-definition.service';
import { TokenAuthGuard } from '@/common/guards/token-guard/token-auth.guard';
import { UiDefinitionRepository } from '@/ui-definition/ui-definition.repository';
import { WorkflowTokenService } from '@/auth/workflow-token/workflow-token.service';
import { WorkflowTokenRepository } from '@/auth/workflow-token/workflow-token.repository';
import { WorkflowRuntimeDataRepository } from '@/workflow/workflow-runtime-data.repository';
import { WorkflowTokenService } from '@/auth/workflow-token/workflow-token.service';
import { TokenAuthGuard } from '@/common/guards/token-guard/token-auth.guard';
import { Module } from '@nestjs/common';

@Module({
providers: [
WorkflowTokenRepository,
WorkflowTokenService,
TokenAuthGuard,
CustomerService,
CustomerRepository,
UiDefinitionService,
ProjectScopeService,
UiDefinitionRepository,
WorkflowRuntimeDataRepository,
ApiKeyService,
ApiKeyRepository,
],
providers: [WorkflowTokenRepository, WorkflowTokenService, TokenAuthGuard],
exports: [WorkflowTokenRepository, WorkflowTokenService, TokenAuthGuard],
})
export class TokenAuthModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ 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
Loading

0 comments on commit fb5e52b

Please sign in to comment.