From 70d85b65b64aced28d9c1c94b08b8aa84966973f Mon Sep 17 00:00:00 2001 From: Tim Gates Date: Mon, 15 Nov 2021 22:03:36 +1100 Subject: [PATCH 01/11] docs: Fix a few typos There are small typos in: - apps/widget/public/iframeResizer.contentWindow.js - docs/docs/templates/messages.md Fixes: - Should read `whether` rather than `wether`. - Should read `notification` rather than `notificaton`. - Should read `compatibility` rather than `compatibity`. --- apps/api/src/.env.development | 12 +++++++ apps/api/src/.env.local | 18 +++++++++++ apps/api/src/.env.production | 12 +++++++ apps/api/src/.env.test | 32 +++++++++++++++++++ .../public/iframeResizer.contentWindow.js | 2 +- apps/ws/src/.env.development | 8 +++++ apps/ws/src/.env.local | 8 +++++ apps/ws/src/.env.production | 6 ++++ apps/ws/src/.env.test | 7 ++++ docs/docs/templates/messages.md | 4 +-- 10 files changed, 106 insertions(+), 3 deletions(-) create mode 100644 apps/api/src/.env.development create mode 100644 apps/api/src/.env.local create mode 100644 apps/api/src/.env.production create mode 100644 apps/api/src/.env.test create mode 100644 apps/ws/src/.env.development create mode 100644 apps/ws/src/.env.local create mode 100644 apps/ws/src/.env.production create mode 100644 apps/ws/src/.env.test diff --git a/apps/api/src/.env.development b/apps/api/src/.env.development new file mode 100644 index 00000000000..cb328b98948 --- /dev/null +++ b/apps/api/src/.env.development @@ -0,0 +1,12 @@ +NODE_ENV=dev +PORT=3000 +API_ROOT_URL=https://dev.api.notifire.co +FRONT_BASE_URL=https://dev.web.notifire.co +NEST_STARTER_MAIL=support@notifire.co + +REDIS_PORT=6379 +REDIS_HOST=localhost +REDIS_DB_INDEX=2 + +NEW_RELIC_ENABLED=true +NEW_RELIC_APP_NAME="[DEV] - api" diff --git a/apps/api/src/.env.local b/apps/api/src/.env.local new file mode 100644 index 00000000000..fe49be0afb3 --- /dev/null +++ b/apps/api/src/.env.local @@ -0,0 +1,18 @@ +NODE_ENV=local +PORT=3000 +API_ROOT_URL=http://localhost:3000 +FRONT_BASE_URL=http://localhost:4200 + +MONGO_URL=mongodb://localhost:27017/notifire-db +REDIS_PORT=6379 +REDIS_HOST=localhost +REDIS_DB_INDEX=2 + +JWT_SECRET=%LOCAL_TEST&@Ub4&9s + +S3_LOCAL_STACK=http://localhost:4566 +S3_BUCKET_NAME=notifire-local +S3_REGION=us-east-1 +AWS_ACCESS_KEY_ID=test +AWS_SECRET_ACCESS_KEY=test +NEW_RELIC_ENABLED=false diff --git a/apps/api/src/.env.production b/apps/api/src/.env.production new file mode 100644 index 00000000000..c5bdacca0f9 --- /dev/null +++ b/apps/api/src/.env.production @@ -0,0 +1,12 @@ +NODE_ENV=prod +PORT=3000 +API_ROOT_URL=https://api.notifire.co +FRONT_BASE_URL=https://web.notifire.co +WIDGET_BASE_URL=https://widget.notifire.co +NEST_STARTER_MAIL=support@notifire.co + +REDIS_PORT=6379 +REDIS_DB_INDEX=2 + +NEW_RELIC_ENABLED=true +NEW_RELIC_APP_NAME="[PROD] - api" diff --git a/apps/api/src/.env.test b/apps/api/src/.env.test new file mode 100644 index 00000000000..40a54ee9a4c --- /dev/null +++ b/apps/api/src/.env.test @@ -0,0 +1,32 @@ +OOGLE_OAUTH_CLIENT_ID=11 +GOOGLE_OAUTH_CLIENT_SECRET=11 +GOOGLE_OAUTH_REDIRECT=http://localhost:3000/v1/auth/google/callback + +CLIENT_SUCCESS_AUTH_REDIRECT=http://localhost:4200/login + +MONGO_URL=mongodb://localhost:27017/notifire-test +REDIS_PORT=6379 +REDIS_HOST=localhost +REDIS_DB_INDEX=1 +SYNC_PATH=http://localhost:3001 +API_ROOT_URL=http://localhost:3000 +PORT=1337 +JWT_SECRET=ASD#asda23DFEFSFHG%fg +NODE_ENV=test +SENDGRID_API_KEY= +S3_ACCESS_KEY= +S3_SECRET= +REDIS_ARENA_PORT=4568 +FRONT_BASE_URL=http://localhost:4200 +RELEASLY_MAIL=support@starter.co +BACK_OFFICE_URL=http://localhost:5200 +MIXPANEL_TOKEN=123123 +INTERCOM_API_KEY= + +S3_LOCAL_STACK=http://localhost:4566 +S3_BUCKET_NAME=notifire-test +S3_REGION=us-east-1 +AWS_ACCESS_KEY_ID=test +AWS_SECRET_ACCESS_KEY=test +NEW_RELIC_ENABLED=false +NOTIFIRE_API_KEY=test diff --git a/apps/widget/public/iframeResizer.contentWindow.js b/apps/widget/public/iframeResizer.contentWindow.js index ad54e80331c..14b633b85a5 100644 --- a/apps/widget/public/iframeResizer.contentWindow.js +++ b/apps/widget/public/iframeResizer.contentWindow.js @@ -1261,7 +1261,7 @@ function isInitMsg() { // Test if this message is from a child below us. This is an ugly test, however, updating - // the message format would break backwards compatibity. + // the message format would break backwards compatibility. return event.data.split(':')[2] in { true: 1, false: 1 } } diff --git a/apps/ws/src/.env.development b/apps/ws/src/.env.development new file mode 100644 index 00000000000..ad290518984 --- /dev/null +++ b/apps/ws/src/.env.development @@ -0,0 +1,8 @@ +NODE_ENV=dev +PORT=3002 +WS_PORT=3003 +MONGO_URL=mongodb://localhost:27017/notifire-db +REDIS_PORT=6379 +REDIS_HOST=localhost +REDIS_DB_INDEX=2 +JWT_SECRET=TEST_CHANGE9s diff --git a/apps/ws/src/.env.local b/apps/ws/src/.env.local new file mode 100644 index 00000000000..8619157754e --- /dev/null +++ b/apps/ws/src/.env.local @@ -0,0 +1,8 @@ +NODE_ENV=dev +PORT=3002 +WS_PORT=3003 +MONGO_URL=mongodb://localhost:27017/notifire-db +REDIS_PORT=6379 +REDIS_HOST=localhost +REDIS_DB_INDEX=2 +JWT_SECRET=%ASTEST_CHANGE9s diff --git a/apps/ws/src/.env.production b/apps/ws/src/.env.production new file mode 100644 index 00000000000..f11753ff904 --- /dev/null +++ b/apps/ws/src/.env.production @@ -0,0 +1,6 @@ +NODE_ENV=prod +PORT=3002 +WS_PORT=3003 +REDIS_PORT=6379 +REDIS_DB_INDEX=2 +WIDGET_BASE_URL=https://widget.notifire.co diff --git a/apps/ws/src/.env.test b/apps/ws/src/.env.test new file mode 100644 index 00000000000..e84444e0aba --- /dev/null +++ b/apps/ws/src/.env.test @@ -0,0 +1,7 @@ +MONGO_URL=mongodb://localhost:27017/notifire-test +REDIS_PORT=6379 +REDIS_HOST=localhost +REDIS_DB_INDEX=1 +PORT=1340 +JWT_SECRET=ASD#asda23DFEFSFHG%fg +NODE_ENV=test diff --git a/docs/docs/templates/messages.md b/docs/docs/templates/messages.md index fd07231a827..569e6a1f946 100644 --- a/docs/docs/templates/messages.md +++ b/docs/docs/templates/messages.md @@ -4,7 +4,7 @@ sidebar_position: 6 # Messages -Messages are part of the notificaton template configuration. Each message is tied to a specific channel but not to specific provider. You customize the channel experience by adding channel related metadata (like subject in email, and CTA buttons in Direct messaging). +Messages are part of the notification template configuration. Each message is tied to a specific channel but not to specific provider. You customize the channel experience by adding channel related metadata (like subject in email, and CTA buttons in Direct messaging). Here's an example of a template with a single message: @@ -52,5 +52,5 @@ The template is the main content area of the notification. In case of other chan ## Active -A switch to indicate wether this message should be sent or not. This can be a simple boolean, function or a promise that returns a boolean. +A switch to indicate whether this message should be sent or not. This can be a simple boolean, function or a promise that returns a boolean. You can use it to conditionally send a message based on the trigger inputs. From 73ee60b0f43d80ceba4740acc1def32ef414088b Mon Sep 17 00:00:00 2001 From: Dima Grossman Date: Mon, 29 Nov 2021 23:14:03 +0200 Subject: [PATCH 02/11] Added gitpod configs Added gitpod image --- .gitpod.dockerfile | 3 +++ .gitpod.yml | 12 ++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 .gitpod.dockerfile create mode 100644 .gitpod.yml diff --git a/.gitpod.dockerfile b/.gitpod.dockerfile new file mode 100644 index 00000000000..83e4fb06481 --- /dev/null +++ b/.gitpod.dockerfile @@ -0,0 +1,3 @@ +FROM gitpod/workspace-mongodb + +RUN sudo apt-get update && sudo apt-get install -y redis-server && sudo rm -rf /var/lib/apt/lists/* diff --git a/.gitpod.yml b/.gitpod.yml new file mode 100644 index 00000000000..ebc9915e142 --- /dev/null +++ b/.gitpod.yml @@ -0,0 +1,12 @@ +image: + file: .gitpod.dockerfile +tasks: + - init: yarn install && yarn run build + command: yarn run start && mkdir -p /workspace/data && mongod --dbpath /workspace/data && redis-server +ports: + - port: 4200 + onOpen: open-preview + - port: 4500 + onOpen: open-preview + - port: 3000 + onOpen: open-preview From dc7d9a72ae989039a6aa6a8c9391c66b76a4d23f Mon Sep 17 00:00:00 2001 From: Dima Grossman Date: Tue, 30 Nov 2021 09:53:24 +0200 Subject: [PATCH 03/11] Update .gitpod.yml --- .gitpod.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitpod.yml b/.gitpod.yml index ebc9915e142..6008fca2876 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -2,7 +2,9 @@ image: file: .gitpod.dockerfile tasks: - init: yarn install && yarn run build - command: yarn run start && mkdir -p /workspace/data && mongod --dbpath /workspace/data && redis-server + command: mkdir -p /workspace/data && mongod --dbpath /workspace/data + - command: redis-server + - command: yarn start ports: - port: 4200 onOpen: open-preview From 0ed0b4e1ef244743a0e3e573120c3ce7695ab07d Mon Sep 17 00:00:00 2001 From: galezra Date: Wed, 1 Dec 2021 00:43:58 +0200 Subject: [PATCH 04/11] feat: support for optional types in Hygen script generator (SMS/EMAIL) --- _templates/provider/new/.eslintrc.json.ejs.t | 4 ++-- _templates/provider/new/README.ejs.t | 5 +++-- _templates/provider/new/prompt.js | 18 ++++++++++++------ _templates/provider/new/src/lib/provider.ejs.t | 15 +++++++++------ .../new/src/lib/test.provider.spec.ejs.t | 4 +++- 5 files changed, 29 insertions(+), 17 deletions(-) diff --git a/_templates/provider/new/.eslintrc.json.ejs.t b/_templates/provider/new/.eslintrc.json.ejs.t index ce538ab24c3..0a61a1bd42c 100644 --- a/_templates/provider/new/.eslintrc.json.ejs.t +++ b/_templates/provider/new/.eslintrc.json.ejs.t @@ -1,7 +1,7 @@ --- - to: providers/<%= name %>/.eslintrc.json + to: providers/<%= name %>/.eslintrc.js --- { - "extends": "../../.eslintrc.json" + "extends": "../../.eslintrc.js" } diff --git a/_templates/provider/new/README.ejs.t b/_templates/provider/new/README.ejs.t index ec6bed45558..352012f7d87 100644 --- a/_templates/provider/new/README.ejs.t +++ b/_templates/provider/new/README.ejs.t @@ -1,10 +1,11 @@ --- to: providers/<%= name %>/README.md --- - +<% LowerType = h.changeCase.lower(type) -%> +<% PascalName = h.changeCase.pascal(name) -%> # Notifire <%= h.changeCase.pascal(name) %> Provider -A <%= h.changeCase.pascal(name) %> email provider library for [@notifire/core](https://github.com/notifirehq/notifire) +A <%= PascalName %> <%= LowerType %> provider library for [@notifire/core](https://github.com/notifirehq/notifire) ## Usage diff --git a/_templates/provider/new/prompt.js b/_templates/provider/new/prompt.js index 47e275cfdfd..ea43070d0c2 100644 --- a/_templates/provider/new/prompt.js +++ b/_templates/provider/new/prompt.js @@ -1,7 +1,13 @@ module.exports = [ - { - type: 'input', - name: 'name', - message: "Write the provider name camelCased:" - } -] + { + type: 'select', + name: 'type', + message: 'What type of provider is this?', + choices: ['EMAIL', 'SMS'], + }, + { + type: 'input', + name: 'name', + message: 'Write the provider name camelCased:', + }, +]; diff --git a/_templates/provider/new/src/lib/provider.ejs.t b/_templates/provider/new/src/lib/provider.ejs.t index 07e0f21c39d..41f2347c449 100644 --- a/_templates/provider/new/src/lib/provider.ejs.t +++ b/_templates/provider/new/src/lib/provider.ejs.t @@ -2,25 +2,28 @@ to: providers/<%= name %>/src/lib/<%= name %>.provider.ts --- +<% PascalType = h.changeCase.pascal(type) -%> +<% UpperType = h.changeCase.upper(type) -%> +<% PascalName = h.changeCase.pascal(name) -%> import { ChannelTypeEnum, - IEmailOptions, - IEmailProvider, ISendMessageSuccessResponse, + I<%= PascalType %>Options, + I<%= PascalType %>Provider, } from '@notifire/core'; -export class <%= h.changeCase.pascal(name) %>EmailProvider implements IEmailProvider { - channelType = ChannelTypeEnum.EMAIL as ChannelTypeEnum.EMAIL; +export class <%= PascalName %><%= PascalType %>Provider implements I<%= PascalType %>Provider { + channelType = ChannelTypeEnum.<%= UpperType %> as ChannelTypeEnum.<%= UpperType %>; constructor( private config: { - apiKey: string; + <%= UpperType === 'EMAIL' ? 'apiKey: string;' : null %> } ) { } async sendMessage( - options: IEmailOptions + options: I<%= PascalType %>Options ): Promise { diff --git a/_templates/provider/new/src/lib/test.provider.spec.ejs.t b/_templates/provider/new/src/lib/test.provider.spec.ejs.t index df9d91eca9f..8a7c7674573 100644 --- a/_templates/provider/new/src/lib/test.provider.spec.ejs.t +++ b/_templates/provider/new/src/lib/test.provider.spec.ejs.t @@ -2,7 +2,9 @@ to: providers/<%= name %>/src/lib/<%= name %>.provider.spec.ts --- -import { <%= h.changeCase.pascal(name) %>EmailProvider } from './<%= name %>.provider'; +<% PascalName = h.changeCase.pascal(name) -%> +<% PascalType = h.changeCase.pascal(type) -%> +import { <%= PascalName %><%= PascalType %>Provider } from './<%= name %>.provider'; test('should trigger <%= name %> library correctly', async () => { From 5be20dde4960e54580a09361b34bcfc3061e5a87 Mon Sep 17 00:00:00 2001 From: Dima Grossman Date: Sat, 4 Dec 2021 21:04:45 +0000 Subject: [PATCH 05/11] Updated gitpod prebuild --- .gitpod.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.gitpod.yml b/.gitpod.yml index 6008fca2876..a854dd46443 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -12,3 +12,15 @@ ports: onOpen: open-preview - port: 3000 onOpen: open-preview +github: + prebuilds: + # enable for the master/default branch (defaults to true) + master: true + # enable for all branches in this repo (defaults to false) + branches: true + # enable for pull requests coming from this repo (defaults to true) + pullRequests: true + # add a check to pull requests (defaults to true) + addCheck: true + # add a "Review in Gitpod" button as a comment to pull requests (defaults to false) + addComment: true \ No newline at end of file From 46b034ab5ad1fb95151de17c6128ecf389eeb43f Mon Sep 17 00:00:00 2001 From: Dima Grossman Date: Mon, 6 Dec 2021 09:47:07 +0200 Subject: [PATCH 06/11] Remove commitizen hooks --- package.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/package.json b/package.json index 717f89f794f..44077ca1b33 100644 --- a/package.json +++ b/package.json @@ -77,9 +77,7 @@ }, "husky": { "hooks": { - "pre-commit": "lerna run --concurrency 1 --stream precommit --since HEAD --exclude-dependents", - "prepare-commit-msg": "exec < /dev/tty && git cz --hook || true", - "commit-msg": "commitlint -c .commitlintrc.json -E HUSKY_GIT_PARAMS" + "pre-commit": "lerna run --concurrency 1 --stream precommit --since HEAD --exclude-dependents" } }, "lint-staged": { From 2b9009700ca4b6b3e91eebe76fbdd35f6443ad4b Mon Sep 17 00:00:00 2001 From: cloudguruab Date: Mon, 6 Dec 2021 06:05:50 -0500 Subject: [PATCH 07/11] update to docs --- docs/docs/community/create-provider.md | 85 ++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/docs/docs/community/create-provider.md b/docs/docs/community/create-provider.md index 8583a5ebd7c..fa6a3aa5706 100644 --- a/docs/docs/community/create-provider.md +++ b/docs/docs/community/create-provider.md @@ -7,6 +7,91 @@ All of our providers need to implement one or more of our provider interfaces, b For a provider template you can copy one of our existing provider in the `providers` folder in the notifire project, make the relevant changes and create a PR against the monorepo. +## Description + +Providers allow us to handle message delivery over multiple channels. We have multiple providers for each channel (SMS, Email, Push, Direct, and orthers). To get started with adding a new provider lets look at setting up our repository. + +## Initialization + +To setup the repository, be sure to install the required packages. + +```zsh +yarn install +``` + +At the root of the project build the `core` package to get started. + +```zsh +cd packages/core && yarn run build +``` + +## Snippets + +After the project is initialized creating a new provider is achievable with the following. + +```zsh +yarn run generate:provide +``` + +Choose the provider type. + +```zsh +yarn run v1.22.17 +$ npx hygen provider new +? What type of provider is this? … +❯ EMAIL + SMS +``` + +For this example we will be selecting `EMAIL` as our provider type. The name for our provider will be exampleProvider. + +```zsh +? Write the provider name camelCased: › exampleProvider +``` + +Once our exampleProvider is generated we will need to begin working from within `/providers/exampleProvider` to begin adding our provider. Be sure to write test alongside your provider. See below for template instances for our `exampleProvider`. + +```ts +import { + ChannelTypeEnum, + ISendMessageSuccessResponse, + IEmailOptions, + IEmailProvider, +} from '@notifire/core'; + +export class ExampleProviderEmailProvider implements IEmailProvider { + channelType = ChannelTypeEnum.EMAIL as ChannelTypeEnum.EMAIL; + + constructor( + private config: { + apiKey: string; + } + ) { + } + + async sendMessage( + options: IEmailOptions + ): Promise { + + + return { + id: 'PLACEHOLDER', + date: 'PLACEHOLDER' + }; + } +} +``` + +Template test case for `emailProvider`. + +```ts +import { ExampleProviderEmailProvider } from './exampleProvider.provider'; + +test('should trigger exampleProvider library correctly', async () => { + +}); +``` + ## Email Provider This is a code example of a basic email provider, with minimal fields required by our ``` IEmailProvider ``` interface. From 0d68d6ec3fc46d7c1ed3bf276e8331203398d04f Mon Sep 17 00:00:00 2001 From: cloudguruab Date: Mon, 6 Dec 2021 06:07:50 -0500 Subject: [PATCH 08/11] #67 updating create provider documentation --- docs/docs/community/create-provider.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/community/create-provider.md b/docs/docs/community/create-provider.md index fa6a3aa5706..f83fbb23701 100644 --- a/docs/docs/community/create-provider.md +++ b/docs/docs/community/create-provider.md @@ -49,7 +49,7 @@ For this example we will be selecting `EMAIL` as our provider type. The name for ? Write the provider name camelCased: › exampleProvider ``` -Once our exampleProvider is generated we will need to begin working from within `/providers/exampleProvider` to begin adding our provider. Be sure to write test alongside your provider. See below for template instances for our `exampleProvider`. +Once our exampleProvider is generated we will need to begin working from within `/providers/exampleProvider` to begin adding our provider. Be sure to write test alongside your provider. See below for template examples for our `exampleProvider`. ```ts import { From 20c431f1e3b28741380af5667a4dc93613417714 Mon Sep 17 00:00:00 2001 From: cloudguruab Date: Mon, 6 Dec 2021 11:06:11 -0500 Subject: [PATCH 09/11] typo fixes to PR --- docs/docs/community/create-provider.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/docs/community/create-provider.md b/docs/docs/community/create-provider.md index f83fbb23701..2b12b3de3c8 100644 --- a/docs/docs/community/create-provider.md +++ b/docs/docs/community/create-provider.md @@ -9,7 +9,7 @@ For a provider template you can copy one of our existing provider in the `provid ## Description -Providers allow us to handle message delivery over multiple channels. We have multiple providers for each channel (SMS, Email, Push, Direct, and orthers). To get started with adding a new provider lets look at setting up our repository. +Providers allow us to handle message delivery over multiple channels. We have multiple providers for each channel (SMS, Email, Push, Direct, and others). To get started with adding a new provider let's look at setting up our repository. ## Initialization @@ -43,13 +43,13 @@ $ npx hygen provider new SMS ``` -For this example we will be selecting `EMAIL` as our provider type. The name for our provider will be exampleProvider. +For this example, we will be selecting `EMAIL` as our provider type. The name for our provider will be exampleProvider. ```zsh ? Write the provider name camelCased: › exampleProvider ``` -Once our exampleProvider is generated we will need to begin working from within `/providers/exampleProvider` to begin adding our provider. Be sure to write test alongside your provider. See below for template examples for our `exampleProvider`. +Once our exampleProvider is generated we will need to begin working from within `/providers/exampleProvider` to begin adding our provider. Be sure to write the test alongside your provider. See below for template examples for our `exampleProvider`. ```ts import { From 6168ebf57c903a0104a4045245a90555ade0e713 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Matthies?= <12965261+matthiez@users.noreply.github.com> Date: Tue, 14 Dec 2021 12:07:03 +0100 Subject: [PATCH 10/11] docs: fix typo --- docs/docs/community/create-provider.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/community/create-provider.md b/docs/docs/community/create-provider.md index 2b12b3de3c8..4a3b9b70afe 100644 --- a/docs/docs/community/create-provider.md +++ b/docs/docs/community/create-provider.md @@ -30,7 +30,7 @@ cd packages/core && yarn run build After the project is initialized creating a new provider is achievable with the following. ```zsh -yarn run generate:provide +yarn run generate:provider ``` Choose the provider type. From 4d60de58497fadc12396b0284b33a16e3f1ea1b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Matthies?= <12965261+matthiez@users.noreply.github.com> Date: Tue, 14 Dec 2021 12:52:50 +0100 Subject: [PATCH 11/11] add sms provider sms77 --- providers/sms77/.eslintrc.js | 3 + providers/sms77/.gitignore | 9 ++ providers/sms77/README.md | 14 +++ providers/sms77/jest.config.js | 5 ++ providers/sms77/package.json | 90 +++++++++++++++++++ providers/sms77/src/index.ts | 1 + .../sms77/src/lib/sms77.provider.spec.ts | 27 ++++++ providers/sms77/src/lib/sms77.provider.ts | 45 ++++++++++ providers/sms77/tsconfig.json | 10 +++ providers/sms77/tsconfig.module.json | 11 +++ yarn.lock | 19 ++++ 11 files changed, 234 insertions(+) create mode 100644 providers/sms77/.eslintrc.js create mode 100644 providers/sms77/.gitignore create mode 100644 providers/sms77/README.md create mode 100644 providers/sms77/jest.config.js create mode 100644 providers/sms77/package.json create mode 100644 providers/sms77/src/index.ts create mode 100644 providers/sms77/src/lib/sms77.provider.spec.ts create mode 100644 providers/sms77/src/lib/sms77.provider.ts create mode 100644 providers/sms77/tsconfig.json create mode 100644 providers/sms77/tsconfig.module.json diff --git a/providers/sms77/.eslintrc.js b/providers/sms77/.eslintrc.js new file mode 100644 index 00000000000..ec40100be69 --- /dev/null +++ b/providers/sms77/.eslintrc.js @@ -0,0 +1,3 @@ +{ + "extends": "../../.eslintrc.js" +} diff --git a/providers/sms77/.gitignore b/providers/sms77/.gitignore new file mode 100644 index 00000000000..963d5292865 --- /dev/null +++ b/providers/sms77/.gitignore @@ -0,0 +1,9 @@ +.idea/* +.nyc_output +build +node_modules +test +src/**.js +coverage +*.log +package-lock.json diff --git a/providers/sms77/README.md b/providers/sms77/README.md new file mode 100644 index 00000000000..f60d5b758af --- /dev/null +++ b/providers/sms77/README.md @@ -0,0 +1,14 @@ +# Notifire sms77 Provider + +A sms77 sms provider library for [@notifire/core](https://github.com/notifirehq/notifire) + +## Usage + +```javascript +import { Sms77SmsProvider } from '@notifire/sms77'; + +const provider = new Sms77SmsProvider({ + apiKey: process.env.SMS77_API_KEY, + from: process.env.SMS77_FROM, // optional +}); +``` diff --git a/providers/sms77/jest.config.js b/providers/sms77/jest.config.js new file mode 100644 index 00000000000..e86e13bab91 --- /dev/null +++ b/providers/sms77/jest.config.js @@ -0,0 +1,5 @@ +/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ +module.exports = { + preset: 'ts-jest', + testEnvironment: 'node', +}; diff --git a/providers/sms77/package.json b/providers/sms77/package.json new file mode 100644 index 00000000000..2f844f046ac --- /dev/null +++ b/providers/sms77/package.json @@ -0,0 +1,90 @@ +{ + "name": "@notifire/sms77", + "version": "0.2.3", + "description": "A sms77 wrapper for notifire", + "main": "build/main/index.js", + "typings": "build/main/index.d.ts", + "module": "build/module/index.js", + "private": false, + "repository": "https://github.com/notifirehq/notifire", + "license": "MIT", + "keywords": [], + "scripts": { + "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 build test:*", + "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" + }, + "engines": { + "node": ">=10" + }, + "dependencies": { + "@notifire/core": "^0.2.3", + "sms77-client": "^2.14.0", + "node-fetch": "^2.6.6" + }, + "devDependencies": { + "@istanbuljs/nyc-config-typescript": "^1.0.1", + "@types/jest": "^27.0.1", + "codecov": "^3.5.0", + "cspell": "^4.1.0", + "cz-conventional-changelog": "^3.3.0", + "gh-pages": "^3.1.0", + "jest": "^27.1.0", + "npm-run-all": "^4.1.5", + "nyc": "^15.1.0", + "open-cli": "^6.0.1", + "prettier": "^2.1.1", + "standard-version": "^9.0.0", + "ts-jest": "^27.0.5", + "ts-node": "^9.0.0", + "typedoc": "^0.19.0" + }, + "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/**" + ] + }, + "config": { + "commitizen": { + "path": "cz-conventional-changelog" + } + }, + "prettier": { + "singleQuote": true + }, + "nyc": { + "extends": "@istanbuljs/nyc-config-typescript", + "exclude": [ + "**/*.spec.js" + ] + } +} diff --git a/providers/sms77/src/index.ts b/providers/sms77/src/index.ts new file mode 100644 index 00000000000..694fa1dc51e --- /dev/null +++ b/providers/sms77/src/index.ts @@ -0,0 +1 @@ +export * from './lib/sms77.provider'; diff --git a/providers/sms77/src/lib/sms77.provider.spec.ts b/providers/sms77/src/lib/sms77.provider.spec.ts new file mode 100644 index 00000000000..8fba469a9f5 --- /dev/null +++ b/providers/sms77/src/lib/sms77.provider.spec.ts @@ -0,0 +1,27 @@ +import { Sms77SmsProvider } from './sms77.provider'; + +test('should trigger sms77 correctly', async () => { + const provider = new Sms77SmsProvider({ + apiKey: '', + from: '+1145678', + }); + const spy = jest + .spyOn(provider['sms77Client'], 'sms') + .mockImplementation(async () => { + return { + messages: [{ id: null }], + // eslint-disable-next-line @typescript-eslint/no-explicit-any + } as any; + }); + await provider.sendMessage({ + to: '+187654', + content: 'Test', + }); + expect(spy).toHaveBeenCalled(); + expect(spy).toHaveBeenCalledWith({ + from: '+1145678', + json: true, + text: 'Test', + to: '+187654', + }); +}); diff --git a/providers/sms77/src/lib/sms77.provider.ts b/providers/sms77/src/lib/sms77.provider.ts new file mode 100644 index 00000000000..171405ccdd8 --- /dev/null +++ b/providers/sms77/src/lib/sms77.provider.ts @@ -0,0 +1,45 @@ +import { + ChannelTypeEnum, + ISendMessageSuccessResponse, + ISmsOptions, + ISmsProvider, +} from '@notifire/core'; + +import Sms77Client, { SmsJsonResponse, SmsParams } from 'sms77-client'; + +if (!globalThis.fetch) { + globalThis.fetch = require('node-fetch'); +} + +export class Sms77SmsProvider implements ISmsProvider { + id = 'sms77'; + channelType = ChannelTypeEnum.SMS as ChannelTypeEnum.SMS; + private sms77Client: Sms77Client; + + constructor( + private config: { + apiKey: string; + from?: string; + } + ) { + this.sms77Client = new Sms77Client(config.apiKey, 'Notifire'); + } + + async sendMessage( + options: ISmsOptions + ): Promise { + const params: SmsParams = { + from: this.config.from, + json: true, + text: options.content, + to: options.to, + }; + + const sms77Response = await this.sms77Client.sms(params); + + return { + id: sms77Response.messages[0].id, + date: new Date().toISOString(), + }; + } +} diff --git a/providers/sms77/tsconfig.json b/providers/sms77/tsconfig.json new file mode 100644 index 00000000000..5b8120fea36 --- /dev/null +++ b/providers/sms77/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "build/main", + "rootDir": "src", + "types": ["node", "jest"] + }, + "include": ["src/**/*.ts"], + "exclude": ["node_modules/**"] +} diff --git a/providers/sms77/tsconfig.module.json b/providers/sms77/tsconfig.module.json new file mode 100644 index 00000000000..dfb74fa3a35 --- /dev/null +++ b/providers/sms77/tsconfig.module.json @@ -0,0 +1,11 @@ +{ + "extends": "./tsconfig", + "compilerOptions": { + "target": "esnext", + "outDir": "build/module", + "module": "esnext" + }, + "exclude": [ + "node_modules/**" + ] +} diff --git a/yarn.lock b/yarn.lock index 21d7b1cde93..9836e3517d7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11766,6 +11766,11 @@ date-fns@^1.27.2: resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-1.30.1.tgz#2e71bf0b119153dbb4cc4e88d9ea5acfb50dc05c" integrity sha512-hBSVCvSmWC+QypYObzwGOd9wqdDpOt+0wl0KbU+R+uuZBS1jN8VsD1ss3irQDknRj5NvxiTF6oj/nDRnN/UQNw== +date-fns@^2.25.0: + version "2.27.0" + resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.27.0.tgz#e1ff3c3ddbbab8a2eaadbb6106be2929a5a2d92b" + integrity sha512-sj+J0Mo2p2X1e306MHq282WS4/A8Pz/95GIFcsPNMPMZVI3EUrAdSv90al1k+p74WGLCruMXk23bfEDZa71X9Q== + date.js@~0.3.3: version "0.3.3" resolved "https://registry.yarnpkg.com/date.js/-/date.js-0.3.3.tgz#ef1e92332f507a638795dbb985e951882e50bbda" @@ -21170,6 +21175,13 @@ node-fetch@^2.5.0, node-fetch@^2.6.5: dependencies: whatwg-url "^5.0.0" +node-fetch@^2.6.6: + version "2.6.6" + resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.6.tgz#1751a7c01834e8e1697758732e9efb6eeadfaf89" + integrity sha512-Z8/6vRlTUChSdIgMa51jxQ4lrw/Jy5SOW10ObaA47/RElsAN2c5Pn8bTgFGWn/ibwzXTE8qwr1Yzx28vsecXEA== + dependencies: + whatwg-url "^5.0.0" + node-forge@^0.10.0: version "0.10.0" resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-0.10.0.tgz#32dea2afb3e9926f02ee5ce8794902691a676bf3" @@ -26480,6 +26492,13 @@ smart-buffer@^4.1.0: resolved "https://registry.yarnpkg.com/smart-buffer/-/smart-buffer-4.2.0.tgz#6e1d71fa4f18c05f7d0ff216dd16a481d0e8d9ae" integrity sha512-94hK0Hh8rPqQl2xXc3HsaBoOXKV20MToPkcXvwbISWLEs+64sBq5kFgn2kJDHb1Pry9yrP0dxrCI9RRci7RXKg== +sms77-client@^2.14.0: + version "2.14.0" + resolved "https://registry.yarnpkg.com/sms77-client/-/sms77-client-2.14.0.tgz#4f4455fe3c2ba1675b9d2ca8022ad3f7a1917d95" + integrity sha512-+fqcfNCatSe02CKOap4awJNYAvEwlNZuaNtT1iwFyl781ct4O7tJr7MyZOP5dTxC1vlkV1l3x7WS2E6E1LAkCA== + dependencies: + date-fns "^2.25.0" + snake-case@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/snake-case/-/snake-case-2.1.0.tgz#41bdb1b73f30ec66a04d4e2cad1b76387d4d6d9f"