Added @tryghost/email-events package

refs https://github.com/TryGhost/Team/issues/2253
refs https://github.com/TryGhost/Team/issues/2254

This package is analogous to the @tryghost/member-events package. The
events here will be consumed by the EmailSuppressionList
implementation and used to add emails to said list. They'll be
dispatched by the code which handles events received from Mailgun.
This commit is contained in:
Fabien "egg" O'Carroll 2022-11-24 13:54:20 +07:00
parent 54f075b330
commit 90c9a03319
10 changed files with 199 additions and 0 deletions

View File

@ -0,0 +1,6 @@
module.exports = {
plugins: ['ghost'],
extends: [
'plugin:ghost/node'
]
};

View File

@ -0,0 +1,21 @@
# Email Events
## Usage
## Develop
This is a monorepo package.
Follow the instructions for the top-level repo.
1. `git clone` this repo & `cd` into it as usual
2. Run `yarn` to install top-level dependencies.
## Test
- `yarn lint` run just eslint
- `yarn test` run lint and tests

View File

@ -0,0 +1,4 @@
module.exports = {
SpamComplaintEvent: require('./lib/SpamComplaintEvent'),
EmailBouncedEvent: require('./lib/EmailBouncedEvent')
};

View File

@ -0,0 +1,46 @@
/**
* @typedef {import('bson-objectid').default} ObjectID
*/
module.exports = class EmailBouncedEvent {
/**
* @readonly
* @type {string}
*/
email;
/**
* @readonly
* @type {ObjectID}
*/
memberId;
/**
* @readonly
* @type {ObjectID}
*/
emailId;
/**
* @readonly
* @type {Date}
*/
timestamp;
/**
* @private
*/
constructor({email, memberId, emailId, timestamp}) {
this.email = email;
this.memberId = memberId;
this.emailId = emailId;
this.timestamp = timestamp;
}
static create(data) {
return new EmailBouncedEvent({
...data,
timestamp: data.timestamp || new Date
});
}
};

View File

@ -0,0 +1,46 @@
/**
* @typedef {import('bson-objectid').default} ObjectID
*/
module.exports = class SpamComplaintEvent {
/**
* @readonly
* @type {string}
*/
email;
/**
* @readonly
* @type {ObjectID}
*/
memberId;
/**
* @readonly
* @type {ObjectID}
*/
emailId;
/**
* @readonly
* @type {Date}
*/
timestamp;
/**
* @private
*/
constructor({email, memberId, emailId, timestamp}) {
this.email = email;
this.memberId = memberId;
this.emailId = emailId;
this.timestamp = timestamp;
}
static create(data) {
return new SpamComplaintEvent({
...data,
timestamp: data.timestamp || new Date
});
}
};

View File

@ -0,0 +1,27 @@
{
"name": "@tryghost/email-events",
"version": "0.0.0",
"repository": "https://github.com/TryGhost/Ghost/tree/main/packages/email-events",
"author": "Ghost Foundation",
"private": true,
"main": "index.js",
"scripts": {
"dev": "echo \"Implement me!\"",
"test:unit": "NODE_ENV=testing c8 --all --check-coverage --reporter text --reporter cobertura mocha './test/**/*.test.js'",
"test": "yarn test:unit",
"lint:code": "eslint *.js lib/ --ext .js --cache",
"lint": "yarn lint:code && yarn lint:test",
"lint:test": "eslint -c test/.eslintrc.js test/ --ext .js --cache"
},
"files": [
"index.js",
"lib"
],
"devDependencies": {
"bson-objectid": "^2.0.4",
"c8": "7.12.0",
"mocha": "10.1.0",
"sinon": "14.0.2"
},
"dependencies": {}
}

View File

@ -0,0 +1,6 @@
module.exports = {
plugins: ['ghost'],
extends: [
'plugin:ghost/test'
]
};

View File

@ -0,0 +1,13 @@
const assert = require('assert');
const events = require('../');
describe('index.js', function () {
it('exports SpamComplaintEvent', function () {
assert(events.SpamComplaintEvent);
assert(events.SpamComplaintEvent === require('../lib/SpamComplaintEvent'));
});
it('exports EmailBouncedEvent', function () {
assert(events.EmailBouncedEvent);
assert(events.EmailBouncedEvent === require('../lib/EmailBouncedEvent'));
});
});

View File

@ -0,0 +1,15 @@
const assert = require('assert');
const ObjectID = require('bson-objectid').default;
const EmailBouncedEvent = require('../../lib/EmailBouncedEvent');
describe('EmailBouncedEvent', function () {
it('exports a static create method to create instances', function () {
const event = EmailBouncedEvent.create({
email: 'test@test.test',
memberId: new ObjectID(),
emailId: new ObjectID(),
timestamp: new Date()
});
assert(event instanceof EmailBouncedEvent);
});
});

View File

@ -0,0 +1,15 @@
const assert = require('assert');
const ObjectID = require('bson-objectid').default;
const SpamComplaintEvent = require('../../lib/SpamComplaintEvent');
describe('SpamComplaintEvent', function () {
it('exports a static create method to create instances', function () {
const event = SpamComplaintEvent.create({
email: 'test@test.test',
memberId: new ObjectID(),
emailId: new ObjectID(),
timestamp: new Date()
});
assert(event instanceof SpamComplaintEvent);
});
});