Skip to content

Commit

Permalink
Merge pull request #164 from alkem-io/develop
Browse files Browse the repository at this point in the history
Release: Notifications-lib package
  • Loading branch information
valentinyanakiev authored Dec 7, 2022
2 parents 89f9210 + d065df7 commit d0355bf
Show file tree
Hide file tree
Showing 190 changed files with 36,874 additions and 31,765 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-deploy-k8s-dev-azure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
- uses: Azure/k8s-deploy@v1
with:
manifests: |
manifests/25-notifications-deployment-dev.yaml
service/manifests/25-notifications-deployment-dev.yaml
images: |
${{ secrets.REGISTRY_LOGIN_SERVER }}/alkemio-notifications:${{ github.sha }}
imagepullsecrets: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-deploy-k8s-test-azure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
- uses: Azure/k8s-deploy@v1
with:
manifests: |
manifests/25-notifications-deployment-dev.yaml
service/manifests/25-notifications-deployment-dev.yaml
images: |
${{ secrets.REGISTRY_LOGIN_SERVER }}/alkemio-notifications:${{ github.sha }}
imagepullsecrets: |
Expand Down
116 changes: 7 additions & 109 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,112 +1,10 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# jetbrains IDEs
.idea
# vscode
#.vscode

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm
/docs/diagrams/.$*
/service/coverage/*
/service/coverage-ci/*

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
*.log
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next
.~*

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# coverage
coverage-ci/
.vscode
.idea
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ install:
services:
- mysql
before_install:
- cd service
- npm i -g [email protected]
script:
- npm run test:ci:coverage
10 changes: 5 additions & 5 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"type": "node",
"request": "launch",
"name": "Debug Alkemio Notifications",
"args": ["${workspaceFolder}/src/main.ts"],
"args": ["${workspaceFolder}/service/src/main.ts"],
"runtimeArgs": [
"--nolazy",
"-r",
Expand All @@ -17,8 +17,8 @@
"tsconfig-paths/register"
],
"sourceMaps": true,
"envFile": "${workspaceFolder}/.env",
"cwd": "${workspaceRoot}",
"envFile": "${workspaceFolder}/service/.env",
"cwd": "${workspaceRoot}/service",
"console": "integratedTerminal",
"protocol": "inspector"
},
Expand All @@ -28,10 +28,10 @@
"request": "launch",
"runtimeArgs": [
"--inspect-brk",
"${workspaceRoot}/node_modules/.bin/jest",
"${workspaceRoot}/service/node_modules/.bin/jest",
"--runInBand",
"--config",
"${workspaceRoot}/test/config/jest.config.ci.js"
"${workspaceRoot}/service/test/config/jest.config.ci.js"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
Expand Down
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ARG ENV_ARG=production
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./
COPY ./service/package*.json ./

RUN npm i -g [email protected]
RUN npm install
Expand All @@ -23,10 +23,10 @@ RUN chmod +x /wait
# RUN npm ci --only=production

# Bundle app source & config files for TypeORM & TypeScript
COPY ./src ./src
COPY ./tsconfig.json .
COPY ./tsconfig.build.json .
COPY ./notifications.yml .
COPY ./service/src ./src
COPY ./service/tsconfig.json .
COPY ./service/tsconfig.build.json .
COPY ./service/notifications.yml .

RUN npm run build

Expand Down
107 changes: 5 additions & 102 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,109 +1,12 @@
# notifications

# Notifications
Alkemio out-of-band notifications service.

[![Build Status](https://app.travis-ci.com/alkem-io/notifications.svg?branch=develop)](https://app.travis-ci.com/alkem-io/notifications.svg?branch=develop)
[![Coverage Status](https://coveralls.io/repos/github/alkem-io/notifications/badge.svg?branch=develop)](https://coveralls.io/github/alkem-io/notifications?branch=develop)
[![BCH compliance](https://bettercodehub.com/edge/badge/alkem-io/notifications?branch=develop)](https://bettercodehub.com/)
[![Deploy to DockerHub](https://github.com/alkem-io/notifications/actions/workflows/build-release-docker-hub.yml/badge.svg)](https://github.com/alkem-io/notifications/actions/workflows/build-release-docker-hub.yml)

## To test

1. Start quickstart-services from the server repo with defaults.
2. Start mailslurper:

```
npm run start:services
```

3. Go to http://localhost:15672/#/queues/%2F/alkemio-notifications.
4. Under publish message, go to `properties` and add a new property with name `content_type` and value `application/json`.
5. Select payload:

```json
{
"data": "YOUR_DATA"
}
```

6. Click publish.
7. Navigate to http://localhost:5051/mailcount. You will see mailCount > 0 (mailslurper will reset the count on each restart).
8. Navigate to http://localhost:5051/mail. Search for YOUR_DATA. You will find it in the mail message.

## Templates

To add a template:

1. Create a file under src/templates.
2. Copy welcome.js
3. Change the template name
4. Define your channels. You can use [this](https://github.com/notifme/notifme-template/tree/master/example) as an example.
5. In the file you want to use the template, import nunjucks and notifme-template.
6. Render your template

```typescript
const notification = await render('template_name', payload, 'en-US');
```

7. Send notification

```typescript
await notifmeSdk.send(notification.channels).then(console.log);
```

To test the welcome (sample) template, you can use the following payload in RabbitMQ Management UI

```json
{
"pattern": "communityApplicationCreated",
"data": {
"applicantionCreatorID": "f0a47bad-eca5-4942-84ac-4dc9f085b7b8",
"applicantID": "f0a47bad-eca5-4942-84ac-4dc9f085b7b8",
"community": {
"name": "02 Zero Hunger",
"type": "challenge"
},
"hub": {
"id": "32818605-ef2f-4395-bb49-1dc2835c23de",
"challenge": {
"id": "7b86f954-d8c3-4fac-a652-b922c80e5c20",
"opportunity": {
"id": "636be60f-b64a-4742-8b50-69e608601935"
}
}
}
}
}
```

Note: replace applicantionCreatorID, applicantID, and hub + challenge + opportunity IDs with IDs you have in your database. You can run the following gql queries to find them:

```gql
query {
hubs {
id
displayName
challenges {
id
displayName
nameID
community {
id
displayName
}
opportunities {
displayName
id
}
}
}
}
```
##
This repository contains two core elements:
* Notifications Service: the docker container that is used to provide the run time service
* Nofications Library: used to provide a shared set of payloads and event types that is then used by both the Notifications Service and clients of the service.

```gql
query {
me {
id
}
}
```
8 changes: 8 additions & 0 deletions lib/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

# Display specific
/node_modules
/dist

*.log
.env
.~*
3 changes: 3 additions & 0 deletions lib/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
src
tsconfig.json
tsconfig.prod.json
File renamed without changes.
Loading

0 comments on commit d0355bf

Please sign in to comment.