Skip to content

Commit

Permalink
Merge pull request novuhq#134 from sms77io/master
Browse files Browse the repository at this point in the history
Added sms77 as a sms provider & fix docs typo
  • Loading branch information
scopsy authored Dec 15, 2021
2 parents 27d3a06 + 4d60de5 commit 78be2db
Show file tree
Hide file tree
Showing 22 changed files with 381 additions and 23 deletions.
3 changes: 3 additions & 0 deletions .gitpod.dockerfile
Original file line number Diff line number Diff line change
@@ -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/*
26 changes: 26 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
image:
file: .gitpod.dockerfile
tasks:
- init: yarn install && yarn run build
command: mkdir -p /workspace/data && mongod --dbpath /workspace/data
- command: redis-server
- command: yarn start
ports:
- port: 4200
onOpen: open-preview
- port: 4500
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
4 changes: 2 additions & 2 deletions _templates/provider/new/.eslintrc.json.ejs.t
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
to: providers/<%= name %>/.eslintrc.json
to: providers/<%= name %>/.eslintrc.js
---

{
"extends": "../../.eslintrc.json"
"extends": "../../.eslintrc.js"
}
5 changes: 3 additions & 2 deletions _templates/provider/new/README.ejs.t
Original file line number Diff line number Diff line change
@@ -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

Expand Down
18 changes: 12 additions & 6 deletions _templates/provider/new/prompt.js
Original file line number Diff line number Diff line change
@@ -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:',
},
];
15 changes: 9 additions & 6 deletions _templates/provider/new/src/lib/provider.ejs.t
Original file line number Diff line number Diff line change
Expand Up @@ -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<ISendMessageSuccessResponse> {


Expand Down
4 changes: 3 additions & 1 deletion _templates/provider/new/src/lib/test.provider.spec.ejs.t
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {

Expand Down
2 changes: 1 addition & 1 deletion apps/widget/public/iframeResizer.contentWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}

Expand Down
85 changes: 85 additions & 0 deletions docs/docs/community/create-provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 others). To get started with adding a new provider let's 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:provider
```

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 the test alongside your provider. See below for template examples 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<ISendMessageSuccessResponse> {


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.
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/templates/messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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.
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,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": {
Expand Down
3 changes: 3 additions & 0 deletions providers/sms77/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../.eslintrc.js"
}
9 changes: 9 additions & 0 deletions providers/sms77/.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/sms77/README.md
Original file line number Diff line number Diff line change
@@ -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
});
```
5 changes: 5 additions & 0 deletions providers/sms77/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};
90 changes: 90 additions & 0 deletions providers/sms77/package.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
1 change: 1 addition & 0 deletions providers/sms77/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './lib/sms77.provider';
Loading

0 comments on commit 78be2db

Please sign in to comment.