Skip to content

Commit

Permalink
Merge branch 'main' into NV-337-Read-only-environments
Browse files Browse the repository at this point in the history
  • Loading branch information
scopsy committed May 2, 2022
2 parents e52e8ca + cfc9a41 commit c589e0e
Show file tree
Hide file tree
Showing 181 changed files with 3,047 additions and 1,863 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/dev-deploy-web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ jobs:
run: |
touch .env
echo REACT_APP_API_URL="https://dev.api.novu.co" >> .env
echo REACT_APP_WS_URL="https://dev.ws.novu.co" >> .env
echo REACT_APP_WIDGET_EMBED_PATH="https://dev.embed.novu.co/embed.umd.min.js" >> .env
echo REACT_APP_NOVU_APP_ID=${{ secrets.NOVU_APP_ID }} >> .env
echo REACT_APP_SENTRY_DSN="https://[email protected]/6250907" >> .env
Expand All @@ -71,6 +72,7 @@ jobs:
- name: Build
env:
REACT_APP_API_URL: https://dev.api.novu.co
REACT_APP_WS_URL: https://dev.ws.novu.co
REACT_APP_WIDGET_EMBED_PATH: https://dev.embed.novu.co/embed.umd.min.js
REACT_APP_NOVU_APP_ID: ${{ secrets.NOVU_APP_ID }}
REACT_APP_SENTRY_DSN: https://[email protected]/6250907
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dev-deploy-widget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ jobs:
run: |
touch .env
echo REACT_APP_API_URL="https://dev.api.novu.co" >> .env
echo REACT_APP_SENTRY_DSN="https://[email protected]/625116" >> .env
echo REACT_APP_WS_URL="https://dev.ws.novu.co" >> .env
echo REACT_APP_SENTRY_DSN="https://[email protected]/625116" >> .env
echo REACT_APP_ENVIRONMENT=dev >> .env
- name: Envsetup
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/prod-deploy-web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ jobs:
run: |
touch .env
echo REACT_APP_API_URL="https://api.novu.co" >> .env
echo REACT_APP_WS_URL="https://ws.novu.co" >> .env
echo REACT_APP_WIDGET_EMBED_PATH="https://embed.novu.co/embed.umd.min.js" >> .env
echo REACT_APP_NOVU_APP_ID=${{ secrets.NOVU_APP_ID }} >> .env
echo REACT_APP_SENTRY_DSN="https://[email protected]/6250907" >> .env
Expand All @@ -69,6 +70,7 @@ jobs:
- name: Build
env:
REACT_APP_API_URL: https://api.novu.co
REACT_APP_WS_URL: https://ws.novu.co
REACT_APP_WIDGET_EMBED_PATH: https://embed.novu.co/embed.umd.min.js
REACT_APP_NOVU_APP_ID: ${{ secrets.NOVU_APP_ID }}
REACT_APP_SENTRY_DSN: https://[email protected]/6250907
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/reusable-widget-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:

# Runs a single command using the runners shell
- name: Build
run: CI='' pnpm build:widget
run: CI=false pnpm build:widget

- name: Build API
run: CI='' pnpm build:api
Expand All @@ -75,7 +75,7 @@ jobs:
with:
working-directory: apps/widget
start: pnpm start:api
wait-on: http://localhost:3500/v1/health-check
wait-on: http://localhost:1336/v1/health-check, http://localhost:3500
browser: chrome
install: false
headless: true
Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/test-notification-center.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Test @novu/notification-center
on:
push:
paths:
- "packages/notification-center/**"
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: "14"
- run: rm -rf build

- name: Cache pnpm modules
uses: actions/cache@v2
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-
- uses: pnpm/[email protected]
with:
version: 6.0.2
run_install: true

- name: Build
run: pnpm build

4 changes: 2 additions & 2 deletions .idea/notifire.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/runConfigurations/DOCS.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/webResources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 5 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@

<div align="center">

![Logo Dark](https://user-images.githubusercontent.com/8872447/161003447-dab96279-a832-41a9-8a69-24967fdd64cd.png#gh-light-mode-only)
![Logo Dark](https://user-images.githubusercontent.com/8872447/165779319-34962ccc-3149-466c-b1da-97fd93254520.png#gh-dark-mode-only)


</div>

<div align="center">

![Logo Light](https://user-images.githubusercontent.com/8872447/161003750-0c71e956-7448-4876-a446-876fdb7017af.png#gh-dark-mode-only)
![Logo Light](https://user-images.githubusercontent.com/8872447/165779274-22a190da-3284-487e-bd1e-14983df12cbb.png#gh-light-mode-only)

</div>

Expand All @@ -22,14 +23,15 @@ The ultimate service for managing multi-channel notifications with a single API.
<br />
<a href="https://docs.novu.co" rel="dofollow"><strong>Explore the docs »</strong></a>
<br />

<br/>
<a href="https://github.com/novuhq/novu/issues">Report Bug</a>
·
<a href="https://github.com/novuhq/novu/discussions">Request Feature</a>
·
<a href="https://discord.gg/TT6TttXjRe">Join Our Discord</a>
·
<a href="https://blog.novu.co/">Read our blog</a>
<a href="https://github.com/orgs/novuhq/projects/2">Roadmap</a>
</p>

## ⭐️ Why
Expand Down Expand Up @@ -80,64 +82,6 @@ await novu.trigger('<TRIGGER_NAME>',
);
```

# 📦 Stateless mode
For simpler use cases, you can use the `@novu/stateless` library. This will require you to manage the templates content and providers registration.

## 📦 Install

```bash
npm install @novu/stateless
```

```bash
yarn add @novu/stateless
```

## 🔨 Usage

```ts
import { NovuStateless, ChannelTypeEnum } from '@novu/stateless';
import { SendgridEmailProvider } from '@novu/sendgrid';

const novu = new NovuStateless();

await novu.registerProvider(
new SendgridEmailProvider({
apiKey: process.env.SENDGRID_API_KEY,
from: '[email protected]'
})
);

const passwordResetTemplate = await novu.registerTemplate({
id: 'password-reset',
messages: [
{
subject: 'Your password reset request',
channel: ChannelTypeEnum.EMAIL,
template: `
Hi {{firstName}}!
To reset your password click <a href="{{resetLink}}">here.</a>
{{#if organization}}
<img src="{{organization.logo}}" />
{{/if}}
`
},
]
});

await novu.trigger('<REPLACE_WITH_EVENT_NAME>', {
$user_id: "<USER IDENTIFIER>",
$email: "[email protected]",
firstName: "John",
lastName: "Doe",
organization: {
logo: 'https://evilcorp.com/logo.png'
}
});
```

## Providers
Novu provides a single API to manage providers across multiple channels with a simple to use interface.

Expand Down
8 changes: 4 additions & 4 deletions apps/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@novu/api",
"version": "0.4.0-alpha.8",
"version": "0.4.0-alpha.10",
"description": "description",
"author": "",
"private": "true",
Expand Down Expand Up @@ -32,7 +32,7 @@
"@nestjs/swagger": "^4.7.12",
"@nestjs/terminus": "^7.1.0",
"@nestjsx/crud": "^4.6.2",
"@novu/dal": "^0.4.0-alpha.8",
"@novu/dal": "^0.4.0-alpha.10",
"@novu/emailjs": "^0.4.0-alpha.8",
"@novu/mailgun": "^0.4.0-alpha.8",
"@novu/mailjet": "^0.4.0-alpha.8",
Expand All @@ -49,7 +49,7 @@
"@novu/sns": "^0.4.0-alpha.8",
"@novu/stateless": "^0.4.0-alpha.8",
"@novu/telnyx": "^0.4.0-alpha.8",
"@novu/testing": "^0.4.0-alpha.8",
"@novu/testing": "^0.4.0-alpha.10",
"@novu/twilio": "^0.4.0-alpha.8",
"@sendgrid/mail": "^7.6.0",
"@sentry/node": "^6.1.0",
Expand Down Expand Up @@ -112,4 +112,4 @@
"eslint --fix"
]
}
}
}
8 changes: 4 additions & 4 deletions apps/api/src/app/activity/e2e/get-activity-feed.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ describe('Get activity feed - /activity (GET)', async () => {
.post('/v1/widgets/session/initialize')
.send({
applicationIdentifier: session.environment.identifier,
$user_id: '12345',
$first_name: 'Test',
$last_name: 'User',
$email: '[email protected]',
subscriberId: '12345',
firstName: 'Test',
lastName: 'User',
email: '[email protected]',
})
.expect(201);
});
Expand Down
8 changes: 4 additions & 4 deletions apps/api/src/app/activity/e2e/get-activity-stats.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ describe('Get activity stats - /activity/stats (GET)', async () => {
.post('/v1/widgets/session/initialize')
.send({
applicationIdentifier: session.environment.identifier,
$user_id: '12345',
$first_name: 'Test',
$last_name: 'User',
$email: '[email protected]',
subscriberId: '12345',
firstName: 'Test',
lastName: 'User',
email: '[email protected]',
})
.expect(201);
});
Expand Down
9 changes: 8 additions & 1 deletion apps/api/src/app/auth/usecases/login/login.usecase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ import { ApiException } from '../../../shared/exceptions/api.exception';

import { normalizeEmail } from '../../../shared/helpers/email-normalization.service';
import { AuthService } from '../../services/auth.service';
import { AnalyticsService } from '../../../shared/services/analytics/analytics.service';

@Injectable()
export class Login {
constructor(private userRepository: UserRepository, private authService: AuthService) {}
constructor(
private userRepository: UserRepository,
private authService: AuthService,
private analyticsService: AnalyticsService
) {}

async execute(command: LoginCommand) {
const email = normalizeEmail(command.email);
Expand All @@ -20,6 +25,8 @@ export class Login {
const isMatching = await bcrypt.compare(command.password, user.password);
if (!isMatching) throw new ApiException('Wrong credentials provided');

this.analyticsService.upsertUser(user, user._id);

return {
token: await this.authService.generateUserToken(user),
};
Expand Down
10 changes: 5 additions & 5 deletions apps/api/src/app/widgets/dtos/session-initialize.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@ import { IsDefined, IsEmail, IsOptional, IsString } from 'class-validator';
export class SessionInitializeBodyDto {
@IsString()
@IsDefined()
$user_id: string;
subscriberId: string;

@IsString()
@IsDefined()
applicationIdentifier: string;

@IsString()
@IsOptional()
$first_name: string;
firstName: string;

@IsString()
@IsOptional()
$last_name: string;
lastName: string;

@IsEmail()
@IsOptional()
$email: string;
email: string;

@IsString()
@IsOptional()
$phone: string;
phone: string;
}
21 changes: 10 additions & 11 deletions apps/api/src/app/widgets/e2e/initialize-widget-session.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { UserSession } from '@novu/testing';
import * as jwt from 'jsonwebtoken';
import { expect } from 'chai';

describe('Initialize Session - /widgets/session/initialize (POST)', async () => {
Expand All @@ -15,11 +14,11 @@ describe('Initialize Session - /widgets/session/initialize (POST)', async () =>
.post('/v1/widgets/session/initialize')
.send({
applicationIdentifier: session.environment.identifier,
$user_id: '12345',
$first_name: 'Test',
$last_name: 'User',
$email: '[email protected]',
$phone: '054777777',
subscriberId: '12345',
firstName: 'Test',
lastName: 'User',
email: '[email protected]',
phone: '054777777',
})
.expect(201);

Expand All @@ -33,11 +32,11 @@ describe('Initialize Session - /widgets/session/initialize (POST)', async () =>
it('should throw an error when an invalid environment Id passed', async function () {
const { body } = await session.testAgent.post('/v1/widgets/session/initialize').send({
applicationIdentifier: 'some-not-existing-id',
$user_id: '12345',
$first_name: 'Test',
$last_name: 'User',
$email: '[email protected]',
$phone: '054777777',
subscriberId: '12345',
firstName: 'Test',
lastName: 'User',
email: '[email protected]',
phone: '054777777',
});

expect(body.message).to.contain('Please provide a valid app identifier');
Expand Down
Loading

0 comments on commit c589e0e

Please sign in to comment.