Skip to content
Snippets Groups Projects
Commit 8dc9faae authored by Yannis Barlas's avatar Yannis Barlas
Browse files

feat(server): include send email component & update docs

parent 70dbc215
No related branches found
No related tags found
No related merge requests found
......@@ -8,7 +8,7 @@ Install package and remove the dependencies it is meant to replace.
```sh
## if migrating from an existing project
yarn remove pubsweet pubsweet-server @pubsweet/logger @pubsweet/base-model
yarn remove pubsweet pubsweet-server @pubsweet/logger @pubsweet/base-model @pubsweet/component-send-email
##
yarn add @coko/server
......@@ -155,6 +155,46 @@ cron.schedule('* * * * * *', () => {
The library that enables this is `node-cron`. Be sure to check its [documentation](https://github.com/node-cron/node-cron#node-cron) for further details.
### Queue manager
We use [`pg-boss`](https://github.com/timgit/pg-boss/blob/master/docs/usage.md#publish) to handle queues. This package exposes an instance of pg-boss, so you don't have to initiate it yourself. In other words, there's no need to use the `start` and `stop` functions. These are handled.
The following SQL code needs to have run on your database, either via a database init script or as part of a migration:
```sql
CREATE EXTENSION IF NOT EXISTS pgcrypto;
```
Use the queue manager as follows:
```js
const { boss } = require('@coko/server')
await boss.publish('my-job', { and: 'how' })
```
The above method is recommended, but if you already use pubsweet's `connectToJobQueue` and want a low-overhead way to switch to `@coko/server`, we also expose the same function for backwards compatibility.
```js
// Replace this
const { connectToJobQueue } = require('pubsweet-server')
// With this
const { connectToJobQueue } = require('@coko/server')
```
You can also disable the queue manager altogether with the following config option:
```js
// config/default.js
module.exports = {
'pubsweet-server': {
useJobQueue: false,
},
}
```
### Disable GraphQL
There are cases where you might not want a graphql server at all. eg. If you are building a sevice with a single REST api endpoint with coko server.
......@@ -213,6 +253,22 @@ Returns pubsweet's base model
const { BaseModel } = require('@coko/server')
```
##### sendEmail
Reads your mailer config and sends an email.
```js
const { sendEmail } = require('@coko/server')
sendEmail({
from: 'noreply@me.com',
html: `<p>Hello</p>`,
subject: `The hello message`,
text: 'Hello',
to: 'someone@email.com',
})
```
##### createJWT
`createJWT` is an export of a function in `pubsweet-server` that does just that.
......
......@@ -24,6 +24,7 @@
},
"dependencies": {
"@pubsweet/base-model": "^4.0.8",
"@pubsweet/component-send-email": "^0.4.11",
"@pubsweet/db-manager": "^3.1.19",
"@pubsweet/errors": "^2.0.44",
"@pubsweet/logger": "^0.2.54",
......
......@@ -5,6 +5,7 @@ const authentication = require('pubsweet-server/src/authentication')
const { pubsubManager, startServer } = require('pubsweet-server')
const logger = require('@pubsweet/logger')
const { db } = require('@pubsweet/db-manager')
const { send: sendEmail } = require('@pubsweet/component-send-email')
const app = require('./app')
const { boss, connectToJobQueue } = require('./pgboss')
......@@ -17,6 +18,8 @@ module.exports = {
pubsubManager,
startServer,
sendEmail,
BaseModel,
logger,
db,
......
......@@ -416,6 +416,13 @@
objection "^2.1.6"
uuid "^7.0.3"
"@pubsweet/component-send-email@^0.4.11":
version "0.4.11"
resolved "https://registry.yarnpkg.com/@pubsweet/component-send-email/-/component-send-email-0.4.11.tgz#9870da674881b5d13f2933ce30ef1925a011d3d3"
integrity sha512-IhKTxELx+dG2K77lcnnwg6bmm3TzhIUXtrDTvu/h+J3CNu/wfpMYowttBijVJxg69RLkA9dhBWIZEIay8TQIaw==
dependencies:
nodemailer "^6.4.18"
"@pubsweet/db-manager@^3.1.19":
version "3.1.19"
resolved "https://registry.yarnpkg.com/@pubsweet/db-manager/-/db-manager-3.1.19.tgz#0f54eea9640d66e2467d5211b8841f1b91dc107c"
......@@ -6003,6 +6010,11 @@ node-notifier@^5.4.0:
shellwords "^0.1.1"
which "^1.3.0"
nodemailer@^6.4.18:
version "6.5.0"
resolved "https://registry.yarnpkg.com/nodemailer/-/nodemailer-6.5.0.tgz#d12c28d8d48778918e25f1999d97910231b175d9"
integrity sha512-Tm4RPrrIZbnqDKAvX+/4M+zovEReiKlEXWDzG4iwtpL9X34MJY+D5LnQPH/+eghe8DLlAVshHAJZAZWBGhkguw==
normalize-package-data@^2.3.0, normalize-package-data@^2.3.2, normalize-package-data@^2.3.4, normalize-package-data@^2.3.5:
version "2.5.0"
resolved "https://registry.yarnpkg.com/normalize-package-data/-/normalize-package-data-2.5.0.tgz#e66db1838b200c1dfc233225d12cb36520e234a8"
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment