Skip to content

Commit

Permalink
chore(root): Release 2024-10-31 08:05 (#6811)
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored Oct 31, 2024
2 parents 04f061c + 031881a commit f92f5a4
Show file tree
Hide file tree
Showing 41 changed files with 446 additions and 336 deletions.
29 changes: 7 additions & 22 deletions apps/api/src/app/bridge/usecases/sync/sync.usecase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,13 @@ import {
CreateWorkflow,
CreateWorkflowCommand,
ExecuteBridgeRequest,
GetFeatureFlag,
GetFeatureFlagCommand,
NotificationStep,
UpdateWorkflow,
UpdateWorkflowCommand,
UpsertPreferences,
UpsertWorkflowPreferencesCommand,
} from '@novu/application-generic';
import {
FeatureFlagsKeysEnum,
WorkflowCreationSourceEnum,
WorkflowOriginEnum,
WorkflowTypeEnum,
Expand All @@ -43,8 +40,7 @@ export class Sync {
private environmentRepository: EnvironmentRepository,
private executeBridgeRequest: ExecuteBridgeRequest,
private analyticsService: AnalyticsService,
private upsertPreferences: UpsertPreferences,
private getFeatureFlag: GetFeatureFlag
private upsertPreferences: UpsertPreferences
) {}
async execute(command: SyncCommand): Promise<CreateBridgeResponseDto> {
const environment = await this.environmentRepository.findOne({ _id: command.environmentId });
Expand Down Expand Up @@ -177,26 +173,15 @@ export class Sync {
savedWorkflow = await this.createWorkflow(notificationGroupId, isWorkflowActive, command, workflow);
}

const isWorkflowPreferencesEnabled = await this.getFeatureFlag.execute(
GetFeatureFlagCommand.create({
key: FeatureFlagsKeysEnum.IS_WORKFLOW_PREFERENCES_ENABLED,
environmentId: command.environmentId,
organizationId: command.organizationId,
userId: command.userId,
await this.upsertPreferences.upsertWorkflowPreferences(
UpsertWorkflowPreferencesCommand.create({
environmentId: savedWorkflow._environmentId,
organizationId: savedWorkflow._organizationId,
templateId: savedWorkflow._id,
preferences: this.getWorkflowPreferences(workflow),
})
);

if (isWorkflowPreferencesEnabled) {
await this.upsertPreferences.upsertWorkflowPreferences(
UpsertWorkflowPreferencesCommand.create({
environmentId: savedWorkflow._environmentId,
organizationId: savedWorkflow._organizationId,
templateId: savedWorkflow._id,
preferences: this.getWorkflowPreferences(workflow),
})
);
}

return savedWorkflow;
})
);
Expand Down
4 changes: 0 additions & 4 deletions apps/api/src/app/events/e2e/bridge-sync.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,13 @@ describe('Bridge Sync - /bridge/sync (POST)', async () => {

let bridgeServer: BridgeServer;
beforeEach(async () => {
// @ts-ignore
process.env[FeatureFlagsKeysEnum.IS_WORKFLOW_PREFERENCES_ENABLED] = 'true';
session = new UserSession();
await session.initialize();
bridgeServer = new BridgeServer();
});

afterEach(async () => {
await bridgeServer.stop();
// @ts-ignore
process.env[FeatureFlagsKeysEnum.IS_WORKFLOW_PREFERENCES_ENABLED] = 'false';
});

it('should update bridge url', async () => {
Expand Down
32 changes: 14 additions & 18 deletions apps/api/src/app/events/e2e/bridge-trigger.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ contexts.forEach((context: Context) => {
await syncWorkflow(session, workflowsRepository, workflowIdSkipByStatic, bridgeServer);
}

await triggerEvent(session, workflowIdSkipByStatic, subscriber.subscriberId, null, bridge);
await triggerEvent(session, workflowIdSkipByStatic, subscriber.subscriberId, {}, bridge);
await session.awaitRunningJobs();

const executedMessageByStatic = await messageRepository.find({
Expand Down Expand Up @@ -264,7 +264,7 @@ contexts.forEach((context: Context) => {
await syncWorkflow(session, workflowsRepository, workflowIdSkipByVariable, bridgeServer);
}

await triggerEvent(session, workflowIdSkipByVariable, subscriber.subscriberId, null, bridge);
await triggerEvent(session, workflowIdSkipByVariable, subscriber.subscriberId, {}, bridge);
await session.awaitRunningJobs();

const executedMessage = await messageRepository.find({
Expand Down Expand Up @@ -556,7 +556,7 @@ contexts.forEach((context: Context) => {
await discoverAndSyncBridge(session, workflowsRepository, workflowId, bridgeServer);
}

await triggerEvent(session, workflowId, subscriber.subscriberId, null, bridge);
await triggerEvent(session, workflowId, subscriber.subscriberId, {}, bridge);

await session.awaitRunningJobs();

Expand Down Expand Up @@ -672,7 +672,7 @@ contexts.forEach((context: Context) => {
}

const controls = { steps: { [stepId]: { name: 'stored_control_name' } } };
await triggerEvent(session, workflowId, subscriber.subscriberId, undefined, bridge, controls);
await triggerEvent(session, workflowId, subscriber.subscriberId, {}, bridge, controls);
await session.awaitRunningJobs();

const sentMessage = await messageRepository.find({
Expand Down Expand Up @@ -715,7 +715,6 @@ contexts.forEach((context: Context) => {
});

it(`should deliver message if the Workflow Definition doesn't contain preferences [${context.name}]`, async () => {
process.env.IS_WORKFLOW_PREFERENCES_ENABLED = 'true';
const workflowId = `without-preferences-workflow-${`${context.name}-${uuidv4()}`}`;
const newWorkflow = workflow(workflowId, async ({ step }) => {
await step.inApp('send-in-app', () => ({ body: 'Hello there 1' }));
Expand All @@ -725,6 +724,7 @@ contexts.forEach((context: Context) => {
* Delete `preferences` from the Workflow Definition to simulate an old
* Workflow Definition (i.e. from old Framework version) that doesn't have the `preferences` property.
*/
// @ts-ignore - The operand of a 'delete' operator must be optional.
delete newWorkflow.definition.preferences;

await bridgeServer.start({ workflows: [newWorkflow] });
Expand All @@ -747,7 +747,6 @@ contexts.forEach((context: Context) => {
});

it(`should deliver message if inApp is enabled via workflow preferences [${context.name}]`, async () => {
process.env.IS_WORKFLOW_PREFERENCES_ENABLED = 'true';
const workflowId = `enabled-inapp-workflow-${`${context.name}-${uuidv4()}`}`;
const newWorkflow = workflow(
workflowId,
Expand Down Expand Up @@ -785,7 +784,6 @@ contexts.forEach((context: Context) => {
});

it(`should NOT deliver message if inApp is disabled via workflow preferences [${context.name}]`, async () => {
process.env.IS_WORKFLOW_PREFERENCES_ENABLED = 'true';
const workflowId = `disabled-inapp-workflow-${`${context.name}-${uuidv4()}`}`;
const newWorkflow = workflow(
workflowId,
Expand Down Expand Up @@ -834,7 +832,6 @@ contexts.forEach((context: Context) => {
});

it(`should deliver inApp message if workflow is disabled via workflow preferences and inApp is enabled [${context.name}]`, async () => {
process.env.IS_WORKFLOW_PREFERENCES_ENABLED = 'true';
const workflowId = `disabled-workflow-${`${context.name}-${uuidv4()}`}`;
const newWorkflow = workflow(
workflowId,
Expand Down Expand Up @@ -875,7 +872,6 @@ contexts.forEach((context: Context) => {
});

it(`should NOT deliver inApp message if workflow is disabled via workflow preferences [${context.name}]`, async () => {
process.env.IS_WORKFLOW_PREFERENCES_ENABLED = 'true';
const workflowId = `disabled-workflow-${`${context.name}-${uuidv4()}`}`;
const newWorkflow = workflow(
workflowId,
Expand Down Expand Up @@ -921,8 +917,8 @@ contexts.forEach((context: Context) => {
expect(executionDetailsWorkflowFiltered.length).to.be.eq(1);
});

// eslint-disable-next-line max-len
it(`should deliver inApp message if subscriber disabled inApp channel for readOnly workflow with inApp enabled [${context.name}]`, async () => {
process.env.IS_WORKFLOW_PREFERENCES_ENABLED = 'true';
const workflowId = `enabled-readonly-workflow-level-${`${context.name}-${uuidv4()}`}`;
const newWorkflow = workflow(
workflowId,
Expand Down Expand Up @@ -974,8 +970,8 @@ contexts.forEach((context: Context) => {
expect(sentMessages.length).to.be.eq(1);
});

// eslint-disable-next-line max-len
it(`should NOT deliver inApp message if subscriber enables inApp channel for readOnly workflow with inApp disabled [${context.name}]`, async () => {
process.env.IS_WORKFLOW_PREFERENCES_ENABLED = 'true';
const workflowId = `disabled-readonly-workflow-level-${`${context.name}-${uuidv4()}`}`;
const newWorkflow = workflow(
workflowId,
Expand Down Expand Up @@ -1038,8 +1034,8 @@ contexts.forEach((context: Context) => {
expect(executionDetailsWorkflowFiltered.length).to.be.eq(1);
});

// eslint-disable-next-line max-len
it(`should deliver inApp message if subscriber disabled inApp channel globally for readOnly workflow with inApp enabled [${context.name}]`, async () => {
process.env.IS_WORKFLOW_PREFERENCES_ENABLED = 'true';
const workflowId = `enabled-readonly-global-level-${`${context.name}-${uuidv4()}`}`;
const newWorkflow = workflow(
workflowId,
Expand Down Expand Up @@ -1089,8 +1085,8 @@ contexts.forEach((context: Context) => {
expect(sentMessages.length).to.be.eq(1);
});

// eslint-disable-next-line max-len
it(`should NOT deliver inApp message if subscriber enabled inApp channel globally for readOnly workflow with inApp disabled [${context.name}]`, async () => {
process.env.IS_WORKFLOW_PREFERENCES_ENABLED = 'true';
const workflowId = `disabled-readonly-global-level-${`${context.name}-${uuidv4()}`}`;
const newWorkflow = workflow(
workflowId,
Expand Down Expand Up @@ -1151,6 +1147,7 @@ contexts.forEach((context: Context) => {
expect(executionDetailsWorkflowFiltered.length).to.be.eq(1);
});

// eslint-disable-next-line max-len
it(`should deliver inApp message if subscriber enabled inApp channel globally for workflow with inApp disabled [${context.name}]`, async () => {
if (!context.isStateful) {
/*
Expand All @@ -1159,7 +1156,6 @@ contexts.forEach((context: Context) => {
*/
expect(true).to.equal(true);
} else {
process.env.IS_WORKFLOW_PREFERENCES_ENABLED = 'true';
const workflowId = `disabled-editable-global-level-${`${context.name}-${uuidv4()}`}`;
const newWorkflow = workflow(
workflowId,
Expand Down Expand Up @@ -1206,6 +1202,7 @@ contexts.forEach((context: Context) => {
}
});

// eslint-disable-next-line max-len
it(`should NOT deliver inApp message if subscriber disabled inApp channel globally for workflow with inApp enabled [${context.name}]`, async () => {
if (!context.isStateful) {
/*
Expand All @@ -1214,7 +1211,6 @@ contexts.forEach((context: Context) => {
*/
expect(true).to.equal(true);
} else {
process.env.IS_WORKFLOW_PREFERENCES_ENABLED = 'true';
const workflowId = `enabled-editable-global-level-${`${context.name}-${uuidv4()}`}`;
const newWorkflow = workflow(
workflowId,
Expand Down Expand Up @@ -1272,6 +1268,7 @@ contexts.forEach((context: Context) => {
}
});

// eslint-disable-next-line max-len
it(`should deliver inApp message if subscriber disabled inApp channel globally but enabled inApp for workflow with inApp disabled [${context.name}]`, async () => {
if (!context.isStateful) {
/*
Expand All @@ -1280,7 +1277,6 @@ contexts.forEach((context: Context) => {
*/
expect(true).to.equal(true);
} else {
process.env.IS_WORKFLOW_PREFERENCES_ENABLED = 'true';
const workflowId = `disabled-editable-global-workflow-level-${`${context.name}-${uuidv4()}`}`;
const newWorkflow = workflow(
workflowId,
Expand Down Expand Up @@ -1336,6 +1332,7 @@ contexts.forEach((context: Context) => {
}
});

// eslint-disable-next-line max-len
it(`should NOT deliver inApp message if subscriber enabled inApp channel globally but disabled inApp for workflow with inApp enabled [${context.name}]`, async () => {
if (!context.isStateful) {
/*
Expand All @@ -1344,7 +1341,6 @@ contexts.forEach((context: Context) => {
*/
expect(true).to.equal(true);
} else {
process.env.IS_WORKFLOW_PREFERENCES_ENABLED = 'true';
const workflowId = `enabled-editable-global-workflow-level-${`${context.name}-${uuidv4()}`}`;
const newWorkflow = workflow(
workflowId,
Expand Down Expand Up @@ -1546,7 +1542,7 @@ async function saveControlValues(
session: UserSession,
workflowIdentifier?: string,
stepIdentifier?: string,
payloadBody?: any
payloadBody?: Record<string, unknown>
) {
return await session.testAgent.put(`/v1/bridge/controls/${workflowIdentifier}/${stepIdentifier}`).send(payloadBody);
}
Expand Down
6 changes: 5 additions & 1 deletion apps/api/src/app/events/e2e/trigger-event.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3406,7 +3406,11 @@ describe(`Trigger event - ${eventTriggerPath} (POST)`, function () {
expect(messages2.length).to.equal(0);
});

it('should override - active true', async function () {
/*
* TODO: we need to add support for Tenants in V2 Preferences
* This test is skipped for now as the tenant-level active flag is not taken into account for V2 Preferences
*/
it.skip('should override - active true', async function () {
const subscriberOverride = SubscriberRepository.createObjectId();

// Create active workflow
Expand Down
29 changes: 2 additions & 27 deletions apps/api/src/app/preferences/preferences.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,20 @@ import {
Controller,
Delete,
Get,
NotFoundException,
Post,
Query,
UseGuards,
UseInterceptors,
} from '@nestjs/common';
import {
GetFeatureFlag,
GetFeatureFlagCommand,
GetPreferences,
GetPreferencesCommand,
UpsertPreferences,
UpsertUserWorkflowPreferencesCommand,
UserAuthGuard,
UserSession,
} from '@novu/application-generic';
import { FeatureFlagsKeysEnum, UserSessionData } from '@novu/shared';
import { UserSessionData } from '@novu/shared';
import { ApiExcludeController } from '@nestjs/swagger';
import { UpsertPreferencesDto } from './dtos/upsert-preferences.dto';

Expand All @@ -30,15 +27,12 @@ import { UpsertPreferencesDto } from './dtos/upsert-preferences.dto';
export class PreferencesController {
constructor(
private upsertPreferences: UpsertPreferences,
private getPreferences: GetPreferences,
private getFeatureFlag: GetFeatureFlag
private getPreferences: GetPreferences
) {}

@Get('/')
@UseGuards(UserAuthGuard)
async get(@UserSession() user: UserSessionData, @Query('workflowId') workflowId: string) {
await this.verifyPreferencesApiAvailability(user);

return this.getPreferences.execute(
GetPreferencesCommand.create({
templateId: workflowId,
Expand All @@ -51,8 +45,6 @@ export class PreferencesController {
@Post('/')
@UseGuards(UserAuthGuard)
async upsert(@Body() data: UpsertPreferencesDto, @UserSession() user: UserSessionData) {
await this.verifyPreferencesApiAvailability(user);

return this.upsertPreferences.upsertUserWorkflowPreferences(
UpsertUserWorkflowPreferencesCommand.create({
environmentId: user.environmentId,
Expand All @@ -67,8 +59,6 @@ export class PreferencesController {
@Delete('/')
@UseGuards(UserAuthGuard)
async delete(@UserSession() user: UserSessionData, @Query('workflowId') workflowId: string) {
await this.verifyPreferencesApiAvailability(user);

return this.upsertPreferences.upsertUserWorkflowPreferences(
UpsertUserWorkflowPreferencesCommand.create({
environmentId: user.environmentId,
Expand All @@ -79,19 +69,4 @@ export class PreferencesController {
})
);
}

private async verifyPreferencesApiAvailability(user: UserSessionData) {
const isEnabled = await this.getFeatureFlag.execute(
GetFeatureFlagCommand.create({
userId: user._id,
environmentId: user.environmentId,
organizationId: user.organizationId,
key: FeatureFlagsKeysEnum.IS_WORKFLOW_PREFERENCES_ENABLED,
})
);

if (!isEnabled) {
throw new NotFoundException();
}
}
}
2 changes: 0 additions & 2 deletions apps/api/src/app/preferences/preferences.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ describe('Preferences', function () {
let session: UserSession;

beforeEach(async () => {
// @ts-ignore
process.env[FeatureFlagsKeysEnum.IS_WORKFLOW_PREFERENCES_ENABLED] = 'true';
const moduleRef = await Test.createTestingModule({
imports: [PreferencesModule, AuthModule],
providers: [],
Expand Down
2 changes: 0 additions & 2 deletions apps/api/src/app/workflows-v2/generate-preview.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ describe('Generate Preview', () => {
session = new UserSession();
await session.initialize();
workflowsClient = createWorkflowClient(session.serverUrl, getHeaders());
// @ts-ignore
process.env[FeatureFlagsKeysEnum.IS_WORKFLOW_PREFERENCES_ENABLED] = 'true';
});
after(async () => {
await sleep(1000);
Expand Down
Loading

0 comments on commit f92f5a4

Please sign in to comment.