mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-23 03:42:27 +03:00
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:
parent
54f075b330
commit
90c9a03319
6
ghost/email-events/.eslintrc.js
Normal file
6
ghost/email-events/.eslintrc.js
Normal file
@ -0,0 +1,6 @@
|
||||
module.exports = {
|
||||
plugins: ['ghost'],
|
||||
extends: [
|
||||
'plugin:ghost/node'
|
||||
]
|
||||
};
|
21
ghost/email-events/README.md
Normal file
21
ghost/email-events/README.md
Normal 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
|
||||
|
4
ghost/email-events/index.js
Normal file
4
ghost/email-events/index.js
Normal file
@ -0,0 +1,4 @@
|
||||
module.exports = {
|
||||
SpamComplaintEvent: require('./lib/SpamComplaintEvent'),
|
||||
EmailBouncedEvent: require('./lib/EmailBouncedEvent')
|
||||
};
|
46
ghost/email-events/lib/EmailBouncedEvent.js
Normal file
46
ghost/email-events/lib/EmailBouncedEvent.js
Normal 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
|
||||
});
|
||||
}
|
||||
};
|
46
ghost/email-events/lib/SpamComplaintEvent.js
Normal file
46
ghost/email-events/lib/SpamComplaintEvent.js
Normal 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
|
||||
});
|
||||
}
|
||||
};
|
27
ghost/email-events/package.json
Normal file
27
ghost/email-events/package.json
Normal 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": {}
|
||||
}
|
6
ghost/email-events/test/.eslintrc.js
Normal file
6
ghost/email-events/test/.eslintrc.js
Normal file
@ -0,0 +1,6 @@
|
||||
module.exports = {
|
||||
plugins: ['ghost'],
|
||||
extends: [
|
||||
'plugin:ghost/test'
|
||||
]
|
||||
};
|
13
ghost/email-events/test/index.test.js
Normal file
13
ghost/email-events/test/index.test.js
Normal 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'));
|
||||
});
|
||||
});
|
15
ghost/email-events/test/lib/EmailBouncedEvent.test.js
Normal file
15
ghost/email-events/test/lib/EmailBouncedEvent.test.js
Normal 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);
|
||||
});
|
||||
});
|
15
ghost/email-events/test/lib/SpamComplaintEvent.test.js
Normal file
15
ghost/email-events/test/lib/SpamComplaintEvent.test.js
Normal 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);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user