diff --git a/ghost/email-events/.eslintrc.js b/ghost/email-events/.eslintrc.js new file mode 100644 index 0000000000..c9c1bcb522 --- /dev/null +++ b/ghost/email-events/.eslintrc.js @@ -0,0 +1,6 @@ +module.exports = { + plugins: ['ghost'], + extends: [ + 'plugin:ghost/node' + ] +}; diff --git a/ghost/email-events/README.md b/ghost/email-events/README.md new file mode 100644 index 0000000000..f8d9173259 --- /dev/null +++ b/ghost/email-events/README.md @@ -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 + diff --git a/ghost/email-events/index.js b/ghost/email-events/index.js new file mode 100644 index 0000000000..7ddb7d4965 --- /dev/null +++ b/ghost/email-events/index.js @@ -0,0 +1,4 @@ +module.exports = { + SpamComplaintEvent: require('./lib/SpamComplaintEvent'), + EmailBouncedEvent: require('./lib/EmailBouncedEvent') +}; diff --git a/ghost/email-events/lib/EmailBouncedEvent.js b/ghost/email-events/lib/EmailBouncedEvent.js new file mode 100644 index 0000000000..d3bba8dbdd --- /dev/null +++ b/ghost/email-events/lib/EmailBouncedEvent.js @@ -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 + }); + } +}; diff --git a/ghost/email-events/lib/SpamComplaintEvent.js b/ghost/email-events/lib/SpamComplaintEvent.js new file mode 100644 index 0000000000..f16f647fa3 --- /dev/null +++ b/ghost/email-events/lib/SpamComplaintEvent.js @@ -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 + }); + } +}; diff --git a/ghost/email-events/package.json b/ghost/email-events/package.json new file mode 100644 index 0000000000..36e0f99eea --- /dev/null +++ b/ghost/email-events/package.json @@ -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": {} +} diff --git a/ghost/email-events/test/.eslintrc.js b/ghost/email-events/test/.eslintrc.js new file mode 100644 index 0000000000..829b601eb0 --- /dev/null +++ b/ghost/email-events/test/.eslintrc.js @@ -0,0 +1,6 @@ +module.exports = { + plugins: ['ghost'], + extends: [ + 'plugin:ghost/test' + ] +}; diff --git a/ghost/email-events/test/index.test.js b/ghost/email-events/test/index.test.js new file mode 100644 index 0000000000..32110b42ec --- /dev/null +++ b/ghost/email-events/test/index.test.js @@ -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')); + }); +}); diff --git a/ghost/email-events/test/lib/EmailBouncedEvent.test.js b/ghost/email-events/test/lib/EmailBouncedEvent.test.js new file mode 100644 index 0000000000..a93c875c36 --- /dev/null +++ b/ghost/email-events/test/lib/EmailBouncedEvent.test.js @@ -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); + }); +}); diff --git a/ghost/email-events/test/lib/SpamComplaintEvent.test.js b/ghost/email-events/test/lib/SpamComplaintEvent.test.js new file mode 100644 index 0000000000..252131ff33 --- /dev/null +++ b/ghost/email-events/test/lib/SpamComplaintEvent.test.js @@ -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); + }); +});