Skip to content

Commit

Permalink
Merge branch 'next' into fix/novuhq#4245
Browse files Browse the repository at this point in the history
  • Loading branch information
deependrasingh002 authored Oct 3, 2023
2 parents 42912e0 + e0dc84e commit cb113dd
Show file tree
Hide file tree
Showing 159 changed files with 2,713 additions and 1,474 deletions.
9 changes: 0 additions & 9 deletions .github/workflows/dev-deploy-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ jobs:
steps:
- run: echo ${{ matrix.projectName }}
- uses: actions/checkout@v3
- uses: ./.github/actions/checkout-submodules
with:
submodule_token: ${{ secrets.SUBMODULES_TOKEN }}
submodule_branch: "next"
- uses: ./.github/actions/setup-project
- uses: ./.github/actions/setup-redis-cluster
- uses: mansagroup/nrwl-nx-action@v3
Expand Down Expand Up @@ -88,11 +84,6 @@ jobs:
name: ['novu/api-ee', 'novu/api']
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/checkout-submodules
with:
enabled: ${{ contains (matrix.name,'ee') }}
submodule_token: ${{ secrets.SUBMODULES_TOKEN }}
submodule_branch: "next"
- uses: ./.github/actions/setup-project
- uses: ./.github/actions/docker/build-api
id: docker_build
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/dev-deploy-worker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ jobs:
name: ['novu/worker-ee', 'novu/worker']
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/checkout-submodules
with:
enabled: ${{ contains (matrix.name,'ee') }}
submodule_token: ${{ secrets.SUBMODULES_TOKEN }}
submodule_branch: "next"
- uses: ./.github/actions/setup-project
- uses: ./.github/actions/docker/build-worker
id: docker_build
Expand Down
9 changes: 0 additions & 9 deletions .github/workflows/prod-deploy-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ jobs:
steps:
- run: echo ${{ matrix.projectName }}
- uses: actions/checkout@v3
- uses: ./.github/actions/checkout-submodules
with:
submodule_token: ${{ secrets.SUBMODULES_TOKEN }}
submodule_branch: "next"
- uses: ./.github/actions/setup-project
- uses: ./.github/actions/setup-redis-cluster
- uses: mansagroup/nrwl-nx-action@v3
Expand Down Expand Up @@ -79,11 +75,6 @@ jobs:
id-token: write
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/checkout-submodules
with:
enabled: ${{ contains (matrix.name,'ee') }}
submodule_token: ${{ secrets.SUBMODULES_TOKEN }}
submodule_branch: "main"
- uses: ./.github/actions/setup-project

- name: build api
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/prod-deploy-worker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ jobs:
id-token: write
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/checkout-submodules
with:
enabled: ${{ contains (matrix.name,'ee') }}
submodule_token: ${{ secrets.SUBMODULES_TOKEN }}
submodule_branch: "main"
- uses: ./.github/actions/setup-project

- name: build worker
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/prod-deploy-ws.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 80
environment: Production
needs:
- test_ws
strategy:
matrix:
name: [ 'novu/ws-ee', 'novu/ws' ]
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/reusable-api-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ jobs:
fi
- uses: actions/checkout@v3
# checkout with submodules if token is provided
- uses: ./.github/actions/checkout-submodules
with:
enabled: ${{ steps.setup.outputs.has_token == 'true' }}
submodule_token: ${{ secrets.SUBMODULES_TOKEN }}
submodule_branch: ${{ inputs.submodule_branch }}
- uses: ./.github/actions/setup-project
- uses: ./.github/actions/setup-redis-cluster
- uses: mansagroup/nrwl-nx-action@v3
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/reusable-inbound-mail-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ jobs:
steps:
# checkout with submodules if token is provided
- uses: actions/checkout@v3
- uses: ./.github/actions/checkout-submodules
with:
enabled: ${{ steps.setup.outputs.has_token == 'true' }}
submodule_token: ${{ secrets.SUBMODULES_TOKEN }}
submodule_branch: ${{ inputs.submodule_branch }}
- uses: ./.github/actions/setup-project
- uses: ./.github/actions/setup-redis-cluster
- uses: mansagroup/nrwl-nx-action@v3
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/reusable-web-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ jobs:
- uses: actions/checkout@v3
# checkout with submodules if token is provided
- uses: ./.github/actions/checkout-submodules
with:
enabled: ${{ steps.setup.outputs.has_token == 'true' }}
submodule_token: ${{ secrets.SUBMODULES_TOKEN }}
submodule_branch: ${{ inputs.submodule_branch }}
- uses: ./.github/actions/setup-project
id: setup-project
with:
Expand Down
6 changes: 0 additions & 6 deletions .github/workflows/reusable-widget-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@ jobs:
fi
- uses: actions/checkout@v3
# checkout with submodules if token is provided
- uses: ./.github/actions/checkout-submodules
with:
enabled: ${{ steps.setup.outputs.has_token == 'true' }}
submodule_token: ${{ secrets.SUBMODULES_TOKEN }}
submodule_branch: ${{ inputs.submodule_branch }}

- uses: ./.github/actions/setup-project
id: setup-project
with:
Expand Down
6 changes: 1 addition & 5 deletions .github/workflows/reusable-worker-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@ jobs:
fi
- uses: actions/checkout@v3
# checkout with submodules if token is provided
- uses: ./.github/actions/checkout-submodules
with:
enabled: ${{ steps.setup.outputs.has_token == 'true' }}
submodule_token: ${{ secrets.SUBMODULES_TOKEN }}
submodule_branch: ${{ inputs.submodule_branch }}

- uses: ./.github/actions/setup-project

- uses: ./.github/actions/setup-redis-cluster
Expand Down
6 changes: 0 additions & 6 deletions .github/workflows/reusable-ws-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@ jobs:
echo "has_token=false" >> $GITHUB_OUTPUT
fi
- uses: actions/checkout@v3
# checkout with submodules if token is provided
- uses: ./.github/actions/checkout-submodules
with:
enabled: ${{ steps.setup.outputs.has_token == 'true' }}
submodule_token: ${{ secrets.SUBMODULES_TOKEN }}
submodule_branch: ${{ inputs.submodule_branch }}
- uses: ./.github/actions/setup-project
- uses: mansagroup/nrwl-nx-action@v3
with:
Expand Down
6 changes: 1 addition & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ jobs:
else
echo "::set-output name=has_token::false"
fi
test_e2e_ee:
name: Test E2E EE
runs-on: ubuntu-latest
Expand All @@ -260,10 +260,6 @@ jobs:
steps:
- run: echo ${{ matrix.projectName }}
- uses: actions/checkout@v3
- uses: ./.github/actions/checkout-submodules
with:
submodule_token: ${{ secrets.SUBMODULES_TOKEN }}
submodule_branch: "next"
- uses: ./.github/actions/setup-project
- uses: ./.github/actions/setup-redis-cluster
- uses: mansagroup/nrwl-nx-action@v3
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ You can open a new issue with this [issue form](https://github.com/novuhq/novu/i

### Requirements

- Node.js version v14.19.3
- Node.js version v16.15.1
- MongoDB
- Redis. To install Redis on your O.S, please follow the below guides
- [To install Redis on Windows](https://redis.io/docs/getting-started/installation/install-redis-on-windows/)
Expand All @@ -33,8 +33,8 @@ You can open a new issue with this [issue form](https://github.com/novuhq/novu/i

The project is a monorepo, meaning that it is a collection of multiple packages managed in the same repository.

To learn more about the project structure visit [https://docs.novu.co/community/monorepo-structure](https://docs.novu.co/community/monorepo-structure).

To learn more about the project structure and running the project locally, please have a look [here](https://docs.novu.co/community-support/introduction#run-novu-locally).
After cloning your fork, you will need to run the `npm run setup:project` command to install and build all dependencies.

To learn a detailed guide on running the project locally, checkout our guide on [how to run novu in local machine](https://docs.novu.co/community/run-in-local-machine).
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import '../../src/config';

import { NestFactory } from '@nestjs/core';
import { PreferenceLevelEnum, SubscriberPreferenceRepository } from '@novu/dal';

import { AppModule } from '../../src/app.module';

export async function addLevelPropertyToSubscriberPreferences() {
// eslint-disable-next-line no-console
console.log('start migration - add level property to subscriber preferences');
const app = await NestFactory.create(AppModule, {
logger: false,
});

const subscriberPreferenceRepository = app.get(SubscriberPreferenceRepository);
// eslint-disable-next-line no-console
console.log('add level: PreferenceLevelEnum.TEMPLATE to all subscriber preferences without level property');

await subscriberPreferenceRepository._model.collection.updateMany(
{ level: { $exists: false }, _templateId: { $exists: true } },
{
$set: { level: PreferenceLevelEnum.TEMPLATE },
}
);

// eslint-disable-next-line no-console
console.log('end migration- add level property to subscriber preferences');

app.close();
process.exit(0);
}

addLevelPropertyToSubscriberPreferences();
18 changes: 10 additions & 8 deletions apps/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@novu/api",
"version": "0.19.0",
"version": "0.20.0-alpha.0",
"description": "description",
"author": "",
"private": "true",
Expand Down Expand Up @@ -38,12 +38,12 @@
"@nestjs/platform-express": "^10.2.2",
"@nestjs/swagger": "^7.1.8",
"@nestjs/terminus": "^10.0.1",
"@novu/application-generic": "^0.19.0",
"@novu/dal": "^0.19.0",
"@novu/node": "^0.19.0",
"@novu/shared": "^0.19.0",
"@novu/stateless": "^0.19.0",
"@novu/testing": "^0.19.0",
"@novu/application-generic": "^0.20.0-alpha.0",
"@novu/dal": "^0.20.0-alpha.0",
"@novu/node": "^0.20.0-alpha.0",
"@novu/shared": "^0.20.0-alpha.0",
"@novu/stateless": "^0.20.0-alpha.0",
"@novu/testing": "^0.20.0-alpha.0",
"@sendgrid/mail": "^7.6.0",
"@sentry/hub": "^7.40.0",
"@sentry/node": "^7.40.0",
Expand Down Expand Up @@ -113,7 +113,9 @@
"@novu/ee-auth": "^0.19.0"
},
"nx": {
"implicitDependencies": ["@novu/ee-auth"]
"implicitDependencies": [
"@novu/ee-auth"
]
},
"lint-staged": {
"*.{js,jsx,ts,tsx}": [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { Test } from '@nestjs/testing';
import { expect } from 'chai';
import { v4 as uuid } from 'uuid';

import { SubscribersService, UserSession } from '@novu/testing';
import { SubscriberRepository, NotificationTemplateEntity } from '@novu/dal';
import { TriggerRecipients } from '@novu/shared';

import { SharedModule } from '../../../shared/shared.module';
import { EventsModule } from '../../events.module';
import { ParseEventRequestCommand } from './parse-event-request.command';
import { ParseEventRequest } from './parse-event-request.usecase';

describe('ParseEventRequest Usecase', () => {
let session: UserSession;
let subscribersService: SubscribersService;
let parseEventRequestUsecase: ParseEventRequest;
let template: NotificationTemplateEntity;

beforeEach(async () => {
const moduleRef = await Test.createTestingModule({
imports: [SharedModule, EventsModule],
providers: [],
}).compile();

session = new UserSession();
await session.initialize();

template = await session.createTemplate();
parseEventRequestUsecase = moduleRef.get<ParseEventRequest>(ParseEventRequest);
subscribersService = new SubscribersService(session.organization._id, session.environment._id);
});

it('should throw exception when subscriber id sent as array', async () => {
const transactionId = uuid();
const subscriberId = [SubscriberRepository.createObjectId()];

const command = buildCommand(
session,
transactionId,
[{ subscriberId: subscriberId } as unknown as string],
template.triggers[0].identifier
);

try {
await parseEventRequestUsecase.execute(command);
} catch (error) {
expect(error.message).to.be.eql(
'subscriberId under property to is type array, which is not allowed please make sure all subscribers ids are strings'
);
}
});
});

const buildCommand = (
session: UserSession,
transactionId: string,
to: TriggerRecipients,
identifier: string
): ParseEventRequestCommand => {
return ParseEventRequestCommand.create({
organizationId: session.organization._id,
environmentId: session.environment._id,
to,
transactionId,
userId: session.user._id,
identifier,
payload: {},
overrides: {},
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ export class ParseEventRequest {
for (const subscriber of to) {
const subscriberIdExists = typeof subscriber === 'string' ? subscriber : subscriber.subscriberId;

if (Array.isArray(subscriberIdExists)) {
throw new ApiException(
'subscriberId under property to is type array, which is not allowed please make sure all subscribers ids are strings'
);
}

if (!subscriberIdExists) {
throw new ApiException(
'subscriberId under property to is not configured, please make sure all subscribers contains subscriberId property'
Expand Down
Loading

0 comments on commit cb113dd

Please sign in to comment.