Skip to content

Commit

Permalink
chore(root): Release 2024-10-14 08:06 (#6686)
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored Oct 14, 2024
2 parents 72f99e3 + 371feea commit 20651c1
Show file tree
Hide file tree
Showing 78 changed files with 1,948 additions and 1,060 deletions.
1 change: 1 addition & 0 deletions .github/workflows/on-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ jobs:
test-e2e-affected: ${{ contains(fromJson(needs.get-affected.outputs.test-e2e), '@novu/api') || contains(fromJson(needs.get-affected.outputs.test-e2e), '@novu/worker') }}
test-e2e-ee-affected: ${{ contains(fromJson(needs.get-affected.outputs.test-e2e-ee), '@novu/api') || contains(fromJson(needs.get-affected.outputs.test-e2e-ee), '@novu/worker') }}
job-name: ${{ matrix.name }}
test-unit: false
secrets: inherit

test_e2e_web:
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/reusable-api-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ on:
required: false
default: true
type: boolean
test-unit:
description: 'detect if we should run unit tests'
required: false
default: true
type: boolean
ee:
description: 'use the ee version of api'
required: false
Expand Down Expand Up @@ -117,6 +122,7 @@ jobs:
run: sudo kill -9 $(sudo lsof -t -i:1342)

- name: Run unit tests
if: inputs.test-unit
run: |
cd apps/api && pnpm test
Expand Down
4 changes: 2 additions & 2 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
"helmet": "^6.0.1",
"i18next": "^23.7.6",
"ioredis": "5.3.2",
"json-schema-defaults": "^0.4.0",
"jsonwebtoken": "9.0.0",
"lodash": "^4.17.15",
"nanoid": "^3.1.20",
Expand All @@ -92,7 +91,8 @@
"shortid": "^2.2.16",
"slugify": "^1.4.6",
"swagger-ui-express": "^4.4.0",
"twilio": "^4.14.1",
"twilio": "^4.14.1",
"json-schema-to-ts": "^3.0.0",
"uuid": "^8.3.2"
},
"devDependencies": {
Expand Down
6 changes: 3 additions & 3 deletions apps/api/src/app/analytics/analytics.module.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Module } from '@nestjs/common';
import { AnalyticsService } from '@novu/application-generic';
import { HttpModule } from '@nestjs/axios';
import { AnalyticsController } from './analytics.controller';
import { HubspotIdentifyFormUsecase } from './usecases/hubspot-identify-form/hubspot-identify-form.usecase';
import { SharedModule } from '../shared/shared.module';

@Module({
imports: [HttpModule],
imports: [SharedModule, HttpModule],
controllers: [AnalyticsController],
providers: [AnalyticsService, HubspotIdentifyFormUsecase],
providers: [HubspotIdentifyFormUsecase],
})
export class AnalyticsModule {}
7 changes: 6 additions & 1 deletion apps/api/src/app/bridge/bridge.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,17 @@ export class BridgeController {
if (!workflowExist) {
throw new NotFoundException('Workflow not found');
}
const step = workflowExist?.steps.find((item) => item.stepId === stepId);

if (!step || !step._id) {
throw new NotFoundException('Step not found');
}

const result = await this.controlValuesRepository.findOne({
_environmentId: user.environmentId,
_organizationId: user.organizationId,
_workflowId: workflowExist._id,
stepId,
_stepId: step._id,
level: ControlVariablesLevelEnum.STEP_CONTROLS,
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { Injectable } from '@nestjs/common';
import defaults from 'json-schema-defaults';

import { Injectable, NotFoundException } from '@nestjs/common';
import { NotificationTemplateRepository } from '@novu/dal';
import { JsonSchema } from '@novu/framework';

import { ApiException, UpsertControlValuesCommand, UpsertControlValuesUseCase } from '@novu/application-generic';
import { UpsertControlValuesCommand, UpsertControlValuesUseCase } from '@novu/application-generic';
import { StoreControlVariablesCommand } from './store-control-variables.command';

@Injectable()
Expand All @@ -21,28 +18,22 @@ export class StoreControlVariablesUseCase {
);

if (!workflowExist) {
throw new ApiException('Workflow not found');
throw new NotFoundException('Workflow not found');
}

const step = workflowExist?.steps.find((item) => item.stepId === command.stepId);

if (!step || !step._id) {
throw new ApiException('Step not found');
throw new NotFoundException('Step not found');
}

const stepDefaultControls = defaults(
(step.template as any)?.controls?.schema || (step.template as any)?.inputs?.schema,
{}
) as JsonSchema;

return await this.upsertControlValuesUseCase.execute(
UpsertControlValuesCommand.create({
organizationId: command.organizationId,
environmentId: command.environmentId,
notificationStepEntity: step,
workflowId: workflowExist._id,
newControlValues: command.variables,
controlSchemas: { schema: stepDefaultControls },
})
);
}
Expand Down
161 changes: 88 additions & 73 deletions apps/api/src/app/bridge/usecases/sync/sync.usecase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ export class Sync {
});
}

const createdWorkflows = await this.createWorkflows(command, discover.workflows);
const persistedWorkflowsInBridge = await this.createWorkflows(command, discover.workflows);

await this.disposeOldWorkflows(command, createdWorkflows);
await this.disposeOldWorkflows(command, persistedWorkflowsInBridge);

await this.updateBridgeUrl(command);

return createdWorkflows;
return persistedWorkflowsInBridge;
}

private async updateBridgeUrl(command: SyncCommand) {
Expand All @@ -100,18 +100,12 @@ export class Sync {
}

private async disposeOldWorkflows(command: SyncCommand, createdWorkflows: NotificationTemplateEntity[]) {
const workflowIds = createdWorkflows.map((i) => i._id);
const persistedWorkflowIdsInBridge = createdWorkflows.map((i) => i._id);

const deletedWorkflows = await this.notificationTemplateRepository.find({
_environmentId: command.environmentId,
type: {
$in: [WorkflowTypeEnum.ECHO, WorkflowTypeEnum.BRIDGE],
},
_id: { $nin: workflowIds },
});
const workflowsToDelete = await this.findAllWorkflowsWithOtherIds(command, persistedWorkflowIdsInBridge);

await Promise.all(
deletedWorkflows?.map((workflow) => {
workflowsToDelete?.map((workflow) => {
return this.deleteWorkflow.execute(
DeleteWorkflowCommand.create({
environmentId: command.environmentId,
Expand All @@ -124,9 +118,22 @@ export class Sync {
);
}

private async createWorkflows(command: SyncCommand, workflows: DiscoverWorkflowOutput[]) {
private async findAllWorkflowsWithOtherIds(command: SyncCommand, persistedWorkflowIdsInBridge: string[]) {
return await this.notificationTemplateRepository.find({
_environmentId: command.environmentId,
type: {
$in: [WorkflowTypeEnum.ECHO, WorkflowTypeEnum.BRIDGE],
},
origin: {
$in: [WorkflowOriginEnum.EXTERNAL, undefined, null],
},
_id: { $nin: persistedWorkflowIdsInBridge },
});
}

private async createWorkflows(command: SyncCommand, workflowsFromBridge: DiscoverWorkflowOutput[]) {
return Promise.all(
workflows.map(async (workflow) => {
workflowsFromBridge.map(async (workflow) => {
const workflowExist = await this.notificationTemplateRepository.findByTriggerIdentifier(
command.environmentId,
workflow.workflowId
Expand All @@ -135,33 +142,7 @@ export class Sync {
let savedWorkflow: NotificationTemplateEntity | undefined;

if (workflowExist) {
savedWorkflow = await this.updateWorkflowUsecase.execute(
UpdateWorkflowCommand.create({
id: workflowExist._id,
environmentId: command.environmentId,
organizationId: command.organizationId,
userId: command.userId,
name: workflow.workflowId,
steps: this.mapSteps(workflow.steps, workflowExist),
inputs: {
schema: workflow.controls?.schema || workflow.inputs.schema,
},
controls: {
schema: workflow.controls?.schema || workflow.inputs.schema,
},
rawData: workflow,
payloadSchema:
(workflow.payload?.schema as Record<string, unknown>) ||
(workflow.options?.payloadSchema as Record<string, unknown>),
type: WorkflowTypeEnum.BRIDGE,
description: this.castToAnyNotSupportedParam(workflow.options).description,
data: this.castToAnyNotSupportedParam(workflow.options)?.data,
tags: workflow.tags,
active: this.castToAnyNotSupportedParam(workflow.options)?.active ?? true,
critical: this.castToAnyNotSupportedParam(workflow.options)?.critical ?? false,
preferenceSettings: this.castToAnyNotSupportedParam(workflow.options)?.preferenceSettings,
})
);
savedWorkflow = await this.updateWorkflow(workflowExist, command, workflow);
} else {
const notificationGroupId = await this.getNotificationGroup(
this.castToAnyNotSupportedParam(workflow.options)?.notificationGroupId,
Expand All @@ -173,38 +154,7 @@ export class Sync {
}
const isWorkflowActive = this.castToAnyNotSupportedParam(workflow.options)?.active ?? true;

savedWorkflow = await this.createWorkflowUsecase.execute(
CreateWorkflowCommand.create({
origin: WorkflowOriginEnum.EXTERNAL,
notificationGroupId,
draft: !isWorkflowActive,
environmentId: command.environmentId,
organizationId: command.organizationId,
userId: command.userId,
name: workflow.workflowId,
__source: WorkflowCreationSourceEnum.BRIDGE,
type: WorkflowTypeEnum.BRIDGE,
steps: this.mapSteps(workflow.steps),
/** @deprecated */
inputs: {
schema: workflow.controls?.schema || workflow.inputs.schema,
},
controls: {
schema: workflow.controls?.schema || workflow.inputs.schema,
},
rawData: workflow as unknown as Record<string, unknown>,
payloadSchema:
(workflow.payload?.schema as Record<string, unknown>) ||
/** @deprecated */
(workflow.options?.payloadSchema as Record<string, unknown>),
active: isWorkflowActive,
description: this.castToAnyNotSupportedParam(workflow.options).description,
data: this.castToAnyNotSupportedParam(workflow).options?.data,
tags: workflow.tags || [],
critical: this.castToAnyNotSupportedParam(workflow.options)?.critical ?? false,
preferenceSettings: this.castToAnyNotSupportedParam(workflow.options)?.preferenceSettings,
})
);
savedWorkflow = await this.createWorkflow(notificationGroupId, isWorkflowActive, command, workflow);
}

const isWorkflowPreferencesEnabled = await this.getFeatureFlag.execute(
Expand Down Expand Up @@ -232,6 +182,71 @@ export class Sync {
);
}

private async createWorkflow(notificationGroupId: string, isWorkflowActive, command: SyncCommand, workflow) {
return await this.createWorkflowUsecase.execute(
CreateWorkflowCommand.create({
origin: WorkflowOriginEnum.EXTERNAL,
type: WorkflowTypeEnum.BRIDGE,
notificationGroupId,
draft: !isWorkflowActive,
environmentId: command.environmentId,
organizationId: command.organizationId,
userId: command.userId,
name: workflow.workflowId,
__source: WorkflowCreationSourceEnum.BRIDGE,
steps: this.mapSteps(workflow.steps),
/** @deprecated */
inputs: {
schema: workflow.controls?.schema || workflow.inputs.schema,
},
controls: {
schema: workflow.controls?.schema || workflow.inputs.schema,
},
rawData: workflow as unknown as Record<string, unknown>,
payloadSchema:
(workflow.payload?.schema as Record<string, unknown>) ||
/** @deprecated */
(workflow.options?.payloadSchema as Record<string, unknown>),
active: isWorkflowActive,
description: this.castToAnyNotSupportedParam(workflow.options).description,
data: this.castToAnyNotSupportedParam(workflow).options?.data,
tags: workflow.tags || [],
critical: this.castToAnyNotSupportedParam(workflow.options)?.critical ?? false,
preferenceSettings: this.castToAnyNotSupportedParam(workflow.options)?.preferenceSettings,
})
);
}

private async updateWorkflow(workflowExist, command: SyncCommand, workflow) {
return await this.updateWorkflowUsecase.execute(
UpdateWorkflowCommand.create({
id: workflowExist._id,
environmentId: command.environmentId,
organizationId: command.organizationId,
userId: command.userId,
name: workflow.workflowId,
steps: this.mapSteps(workflow.steps, workflowExist),
inputs: {
schema: workflow.controls?.schema || workflow.inputs.schema,
},
controls: {
schema: workflow.controls?.schema || workflow.inputs.schema,
},
rawData: workflow,
payloadSchema:
(workflow.payload?.schema as Record<string, unknown>) ||
(workflow.options?.payloadSchema as Record<string, unknown>),
type: WorkflowTypeEnum.BRIDGE,
description: this.castToAnyNotSupportedParam(workflow.options).description,
data: this.castToAnyNotSupportedParam(workflow.options)?.data,
tags: workflow.tags,
active: this.castToAnyNotSupportedParam(workflow.options)?.active ?? true,
critical: this.castToAnyNotSupportedParam(workflow.options)?.critical ?? false,
preferenceSettings: this.castToAnyNotSupportedParam(workflow.options)?.preferenceSettings,
})
);
}

private mapSteps(commandWorkflowSteps: DiscoverStepOutput[], workflow?: NotificationTemplateEntity | undefined) {
const steps: NotificationStep[] = commandWorkflowSteps.map((step) => {
const foundStep = workflow?.steps?.find((workflowStep) => workflowStep.stepId === step.stepId);
Expand Down
3 changes: 0 additions & 3 deletions apps/api/src/app/step-schemas/dtos/schema-type.dto.ts

This file was deleted.

6 changes: 6 additions & 0 deletions apps/api/src/app/step-schemas/dtos/step-schema.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { JSONSchema } from 'json-schema-to-ts';

export type StepSchemaDto = {
controls: JSONSchema;
variables: JSONSchema;
};
Loading

0 comments on commit 20651c1

Please sign in to comment.