Added @tryghost/member-events
refs https://github.com/TryGhost/Team/issues/1054 This will hold all of the event definitions used in members so that they can be used across packages.
This commit is contained in:
parent
6c01ff2a3d
commit
3f9af4f554
6
ghost/member-events/.eslintrc.js
Normal file
6
ghost/member-events/.eslintrc.js
Normal file
@ -0,0 +1,6 @@
|
||||
module.exports = {
|
||||
plugins: ['ghost'],
|
||||
extends: [
|
||||
'plugin:ghost/node'
|
||||
]
|
||||
};
|
21
ghost/member-events/LICENSE
Normal file
21
ghost/member-events/LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2013-2021 Ghost Foundation
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
49
ghost/member-events/README.md
Normal file
49
ghost/member-events/README.md
Normal file
@ -0,0 +1,49 @@
|
||||
# Member Events
|
||||
|
||||
## Install
|
||||
|
||||
`npm install @tryghost/member-events --save`
|
||||
|
||||
or
|
||||
|
||||
`yarn add @tryghost/member-events`
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```
|
||||
const {MemberEntryViewEvent} = require('@tryghost/member-events');
|
||||
|
||||
const event = MemberEntryViewEvent.create({
|
||||
memberId: member.id,
|
||||
memberStatus: member.status,
|
||||
entryId: post.id,
|
||||
entryUrl: post.url
|
||||
});
|
||||
|
||||
const DomainEvents = require('@tryghost/domain-events');
|
||||
|
||||
DomainEvents.dispatch(event);
|
||||
```
|
||||
|
||||
|
||||
## Develop
|
||||
|
||||
This is a mono repository, managed with [lerna](https://lernajs.io/).
|
||||
|
||||
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.
|
||||
|
||||
|
||||
## Run
|
||||
|
||||
- `yarn dev`
|
||||
|
||||
|
||||
## Test
|
||||
|
||||
- `yarn lint` run just eslint
|
||||
- `yarn test` run lint and tests
|
||||
|
||||
|
3
ghost/member-events/index.js
Normal file
3
ghost/member-events/index.js
Normal file
@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
MemberEntryViewEvent: require('./lib/MemberEntryViewEvent')
|
||||
};
|
26
ghost/member-events/lib/MemberEntryViewEvent.js
Normal file
26
ghost/member-events/lib/MemberEntryViewEvent.js
Normal file
@ -0,0 +1,26 @@
|
||||
/**
|
||||
* @typedef {object} MemberEntryViewEventData
|
||||
* @prop {string} memberId
|
||||
* @prop {string} memberStatus
|
||||
* @prop {string} entryId
|
||||
* @prop {string} entryUrl
|
||||
*/
|
||||
|
||||
module.exports = class MemberEntryViewEvent {
|
||||
/**
|
||||
* @param {MemberEntryViewEventData} data
|
||||
* @param {Date} timestamp
|
||||
*/
|
||||
constructor(data, timestamp) {
|
||||
this.data = data;
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {MemberEntryViewEventData} data
|
||||
* @param {Date} [timestamp]
|
||||
*/
|
||||
static create(data, timestamp) {
|
||||
return new MemberEntryViewEvent(data, timestamp || new Date);
|
||||
}
|
||||
};
|
28
ghost/member-events/package.json
Normal file
28
ghost/member-events/package.json
Normal file
@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "@tryghost/member-events",
|
||||
"version": "0.0.0",
|
||||
"repository": "https://github.com/TryGhost/Members/tree/main/packages/member-events",
|
||||
"author": "Ghost Foundation",
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"dev": "echo \"Implement me!\"",
|
||||
"test": "NODE_ENV=testing c8 --check-coverage mocha './test/**/*.test.js'",
|
||||
"lint": "eslint . --ext .js --cache",
|
||||
"posttest": "yarn lint"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"lib"
|
||||
],
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"devDependencies": {
|
||||
"c8": "7.9.0",
|
||||
"mocha": "9.1.1",
|
||||
"should": "13.2.3",
|
||||
"sinon": "11.1.2"
|
||||
},
|
||||
"dependencies": {}
|
||||
}
|
6
ghost/member-events/test/.eslintrc.js
Normal file
6
ghost/member-events/test/.eslintrc.js
Normal file
@ -0,0 +1,6 @@
|
||||
module.exports = {
|
||||
plugins: ['ghost'],
|
||||
extends: [
|
||||
'plugin:ghost/test'
|
||||
]
|
||||
};
|
10
ghost/member-events/test/hello.test.js
Normal file
10
ghost/member-events/test/hello.test.js
Normal file
@ -0,0 +1,10 @@
|
||||
// Switch these lines once there are useful utils
|
||||
// const testUtils = require('./utils');
|
||||
require('./utils');
|
||||
|
||||
describe('Hello world', function () {
|
||||
it('Runs a test', function () {
|
||||
// TODO: Write me!
|
||||
'hello'.should.eql('hello');
|
||||
});
|
||||
});
|
11
ghost/member-events/test/utils/assertions.js
Normal file
11
ghost/member-events/test/utils/assertions.js
Normal file
@ -0,0 +1,11 @@
|
||||
/**
|
||||
* Custom Should Assertions
|
||||
*
|
||||
* Add any custom assertions to this file.
|
||||
*/
|
||||
|
||||
// Example Assertion
|
||||
// should.Assertion.add('ExampleAssertion', function () {
|
||||
// this.params = {operator: 'to be a valid Example Assertion'};
|
||||
// this.obj.should.be.an.Object;
|
||||
// });
|
11
ghost/member-events/test/utils/index.js
Normal file
11
ghost/member-events/test/utils/index.js
Normal file
@ -0,0 +1,11 @@
|
||||
/**
|
||||
* Test Utilities
|
||||
*
|
||||
* Shared utils for writing tests
|
||||
*/
|
||||
|
||||
// Require overrides - these add globals for tests
|
||||
require('./overrides');
|
||||
|
||||
// Require assertions - adds custom should assertions
|
||||
require('./assertions');
|
10
ghost/member-events/test/utils/overrides.js
Normal file
10
ghost/member-events/test/utils/overrides.js
Normal file
@ -0,0 +1,10 @@
|
||||
// This file is required before any test is run
|
||||
|
||||
// Taken from the should wiki, this is how to make should global
|
||||
// Should is a global in our eslint test config
|
||||
global.should = require('should').noConflict();
|
||||
should.extend();
|
||||
|
||||
// Sinon is a simple case
|
||||
// Sinon is a global in our eslint test config
|
||||
global.sinon = require('sinon');
|
Loading…
Reference in New Issue
Block a user