Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat eazy sms #5393

Merged
merged 9 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions apps/api/src/app/integrations/dtos/credentials.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,9 @@ export class CredentialsDto implements ICredentials {
@IsString()
@IsOptional()
externalLink?: string;

@ApiPropertyOptional()
@IsString()
@IsOptional()
channelId?: string;
}
14 changes: 14 additions & 0 deletions apps/web/public/static/images/providers/dark/eazy-sms.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions apps/web/public/static/images/providers/dark/square/eazy-sms.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions apps/web/public/static/images/providers/light/eazy-sms.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions apps/web/public/static/images/providers/light/square/eazy-sms.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
SmsProviderIdEnum.Simpletexting,
SmsProviderIdEnum.BrevoSms,
SmsProviderIdEnum.ISendSms,
SmsProviderIdEnum.EazySms,

Check warning on line 78 in apps/web/src/pages/integrations/components/multi-provider/sort-providers.ts

View workflow job for this annotation

GitHub Actions / Spell check

Unknown word (Eazy)
].sort(),
],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const integrationSchema = new Schema<IntegrationDBModel>(
state: Schema.Types.String,
externalLink: Schema.Types.String,
apiToken: Schema.Types.String,
channelId: Schema.Types.String,
},
active: {
type: Schema.Types.Boolean,
Expand Down
9 changes: 9 additions & 0 deletions libs/shared/src/consts/providers/channels/sms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
iSendSmsConfig,
ringCentralConfig,
brevoSmsConfig,
eazySmsConfig,

Check warning on line 31 in libs/shared/src/consts/providers/channels/sms.ts

View workflow job for this annotation

GitHub Actions / Spell check

Unknown word (eazy)
} from '../credentials';
import { SmsProviderIdEnum } from '../provider.enum';

Expand Down Expand Up @@ -271,4 +272,12 @@
docReference: 'https://developers.brevo.com/reference/sendtransacsms',
logoFileName: { light: 'brevo.svg', dark: 'brevo.svg' },
},
{
id: SmsProviderIdEnum.EazySms,

Check warning on line 276 in libs/shared/src/consts/providers/channels/sms.ts

View workflow job for this annotation

GitHub Actions / Spell check

Unknown word (Eazy)
displayName: `Eazy`,
channel: ChannelTypeEnum.SMS,
credentials: eazySmsConfig,

Check warning on line 279 in libs/shared/src/consts/providers/channels/sms.ts

View workflow job for this annotation

GitHub Actions / Spell check

Unknown word (eazy)
docReference: 'https://developers.eazy.im/#678805af-be7b-4487-93a4-c1007b7920f5',
logoFileName: { light: 'eazy-sms.svg', dark: 'eazy-sms.svg' },

Check warning on line 281 in libs/shared/src/consts/providers/channels/sms.ts

View workflow job for this annotation

GitHub Actions / Spell check

Unknown word (eazy)

Check warning on line 281 in libs/shared/src/consts/providers/channels/sms.ts

View workflow job for this annotation

GitHub Actions / Spell check

Unknown word (eazy)
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -1104,3 +1104,19 @@
},
...smsConfigBase,
];

export const eazySmsConfig: IConfigCredentials[] = [

Check warning on line 1108 in libs/shared/src/consts/providers/credentials/provider-credentials.ts

View workflow job for this annotation

GitHub Actions / Spell check

Unknown word (eazy)
{
key: CredentialsKeyEnum.ApiKey,
displayName: 'API Key',
type: 'string',
required: true,
},
{
key: CredentialsKeyEnum.channelId,
displayName: 'SMS Channel Id',
type: 'string',
required: true,
description: 'Your SMS Channel Id',
},
];
2 changes: 2 additions & 0 deletions libs/shared/src/consts/providers/provider.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
imageUrl = 'imageUrl',
state = 'state',
externalLink = 'externalLink',
channelId = 'channelId',
}

export enum EmailProviderIdEnum {
Expand Down Expand Up @@ -100,6 +101,7 @@
AzureSms = 'azure-sms',
RingCentral = 'ring-central',
BrevoSms = 'brevo-sms',
EazySms = 'eazy-sms',

Check warning on line 104 in libs/shared/src/consts/providers/provider.enum.ts

View workflow job for this annotation

GitHub Actions / Spell check

Unknown word (Eazy)

Check warning on line 104 in libs/shared/src/consts/providers/provider.enum.ts

View workflow job for this annotation

GitHub Actions / Spell check

Unknown word (eazy)
}

export enum ChatProviderIdEnum {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ export interface ICredentials {
imageUrl?: string;
state?: string;
externalLink?: string;
channelId?: string;
}
1 change: 1 addition & 0 deletions packages/application-generic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
"@novu/testing": "^0.24.1",
"@novu/twilio": "^0.24.1",
"@novu/zulip": "^0.24.1",
"@novu/eazy-sms": "^0.24.1",
"@opentelemetry/api": "^1.7.0",
"@opentelemetry/auto-instrumentations-node": "^0.40.2",
"@opentelemetry/context-async-hooks": "^1.19.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { ChannelTypeEnum, ICredentials } from '@novu/shared';
import { EazySmsProvider } from '@novu/eazy-sms';

Check warning on line 2 in packages/application-generic/src/factories/sms/handlers/eazy-sms.handler.ts

View workflow job for this annotation

GitHub Actions / Spell check

Unknown word (Eazy)
import { BaseSmsHandler } from './base.handler';

export class EazySmsHandler extends BaseSmsHandler {
constructor() {
super('eazy-sms', ChannelTypeEnum.SMS);
}

buildProvider(credentials: ICredentials) {
const config = {
apiKey: credentials.apiKey,
channelId: credentials.channelId,
};
this.provider = new EazySmsProvider(config);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ export * from './nexmo.handler';
export * from './isend-sms.handler';
export * from './ring-central.handler';
export * from './brevo-sms.handler';
export * from './eazy-sms.handler';
2 changes: 2 additions & 0 deletions packages/application-generic/src/factories/sms/sms.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
ISendSmsHandler,
RingCentralHandler,
BrevoSmsHandler,
EazySmsHandler,
} from './handlers';

export class SmsFactory implements ISmsFactory {
Expand Down Expand Up @@ -61,6 +62,7 @@ export class SmsFactory implements ISmsFactory {
new ISendSmsHandler(),
new RingCentralHandler(),
new BrevoSmsHandler(),
new EazySmsHandler(),
];

getHandler(integration: IntegrationEntity) {
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

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

3 changes: 3 additions & 0 deletions providers/eazy-sms/.czrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"path": "cz-conventional-changelog"
}
3 changes: 3 additions & 0 deletions providers/eazy-sms/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../.eslintrc.js"
}
9 changes: 9 additions & 0 deletions providers/eazy-sms/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.idea/*
.nyc_output
build
node_modules
test
src/**.js
coverage
*.log
package-lock.json
14 changes: 14 additions & 0 deletions providers/eazy-sms/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Novu Eazy SMS Provider

A EazySms sms provider library for [@novu/node](https://github.com/novuhq/novu)

## Usage

```javascript
import { EazySmsProvider } from '@novu/eazy-sms';

const provider = new EazySmsProvider({
apiKey: process.env.API_KEY,
channelId: process.env.CHANNEL_ID,
});
```
8 changes: 8 additions & 0 deletions providers/eazy-sms/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
moduleNameMapper: {
axios: 'axios/dist/node/axios.cjs',
},
};
78 changes: 78 additions & 0 deletions providers/eazy-sms/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"name": "@novu/eazy-sms",
"version": "0.24.1",
"description": "A eazy-sms wrapper for novu",
"main": "build/main/index.js",
"typings": "build/main/index.d.ts",
"module": "build/module/index.js",
"private": false,
"repository": "https://github.com/novuhq/novu",
"license": "MIT",
"keywords": [],
"scripts": {
"prebuild": "rimraf build",
"build": "run-p build:*",
"build:main": "tsc -p tsconfig.json",
"build:module": "tsc -p tsconfig.module.json",
"fix": "run-s fix:*",
"fix:prettier": "prettier \"src/**/*.ts\" --write",
"fix:lint": "eslint src --ext .ts --fix",
"test": "run-s test:*",
"lint": "eslint src --ext .ts",
"test:unit": "jest src",
"watch:build": "tsc -p tsconfig.json -w",
"watch:test": "jest src --watch",
"reset-hard": "git clean -dfx && git reset --hard && yarn",
"prepare-release": "run-s reset-hard test"
},
"publishConfig": {
"access": "public"
},
"dependencies": {
"@novu/stateless": "0.24.1",
"axios": "^1.6.0"
},
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "~1.0.1",
"@types/jest": "~27.5.2",
"cspell": "~6.19.2",
"jest": "~27.5.1",
"npm-run-all": "^4.1.5",
"nyc": "~15.1.0",
"prettier": "~2.8.0",
"rimraf": "~3.0.2",
"ts-jest": "~27.1.5",
"ts-node": "~10.9.1",
"typescript": "4.9.5"
},
"files": [
"build/main",
"build/module",
"!**/*.spec.*",
"!**/*.json",
"CHANGELOG.md",
"LICENSE",
"README.md"
],
"ava": {
"failFast": true,
"timeout": "60s",
"typescript": {
"rewritePaths": {
"src/": "build/main/"
}
},
"files": [
"!build/module/**"
]
},
"prettier": {
"singleQuote": true
},
"nyc": {
"extends": "@istanbuljs/nyc-config-typescript",
"exclude": [
"**/*.spec.js"
]
}
}
1 change: 1 addition & 0 deletions providers/eazy-sms/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './lib/eazy-sms.provider';
31 changes: 31 additions & 0 deletions providers/eazy-sms/src/lib/eazy-sms.provider.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { EazySmsProvider } from './eazy-sms.provider';

const mockConfig = {
apiKey: 'test-key',
channelId: '[email protected]',
};

const mockSMSMessage = {
to: '1234567890',
content: 'sms content',
};

test('should trigger eazy-sms library correctly', async () => {
const smsProvider = new EazySmsProvider(mockConfig);
const spy = jest
.spyOn(smsProvider, 'sendMessage')
.mockImplementation(async () => {
return {
id: '2574a339-86ff',
date: new Date().toISOString(),
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any;
});

await smsProvider.sendMessage(mockSMSMessage);
expect(spy).toHaveBeenCalled();
expect(spy).toHaveBeenCalledWith({
content: 'sms content',
to: '1234567890',
});
});
Comment on lines +1 to +31
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test for the EazySmsProvider is well-structured and covers the basic functionality of the sendMessage method. The use of Jest for spying and mocking the method ensures that the test is isolated and reliable. However, consider adding more test cases to cover error handling and edge cases to ensure robustness.

Would you like me to help in writing additional test cases for error scenarios and edge cases?

Loading
Loading