From 8d07d6e93b0e6f33391620f5c0056623e32e5732 Mon Sep 17 00:00:00 2001 From: Rishabh Date: Fri, 9 Sep 2022 19:55:25 +0530 Subject: [PATCH] Updated subscription created/canceled events data refs https://github.com/TryGhost/Team/issues/1865 - adds new subscription canceled event - updates existing subscription created event to include tier id and source data --- ghost/member-events/index.js | 3 ++- .../lib/SubscriptionCancelledEvent.js | 26 +++++++++++++++++++ .../lib/SubscriptionCreatedEvent.js | 2 ++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 ghost/member-events/lib/SubscriptionCancelledEvent.js diff --git a/ghost/member-events/index.js b/ghost/member-events/index.js index a028f44adc..e99c4e1c42 100644 --- a/ghost/member-events/index.js +++ b/ghost/member-events/index.js @@ -8,5 +8,6 @@ module.exports = { MemberPaidCancellationEvent: require('./lib/MemberPaidCancellationEvent'), MemberPageViewEvent: require('./lib/MemberPageViewEvent'), SubscriptionCreatedEvent: require('./lib/SubscriptionCreatedEvent'), - MemberCommentEvent: require('./lib/MemberCommentEvent') + MemberCommentEvent: require('./lib/MemberCommentEvent'), + SubscriptionCancelledEvent: require('./lib/SubscriptionCancelledEvent') }; diff --git a/ghost/member-events/lib/SubscriptionCancelledEvent.js b/ghost/member-events/lib/SubscriptionCancelledEvent.js new file mode 100644 index 0000000000..184a4399bf --- /dev/null +++ b/ghost/member-events/lib/SubscriptionCancelledEvent.js @@ -0,0 +1,26 @@ +/** + * @typedef {object} SubscriptionCancelledEventData + * @prop {string} source + * @prop {string} memberId + * @prop {string} tierId + * @prop {string} subscriptionId + */ + +module.exports = class SubscriptionCancelledEvent { + /** + * @param {SubscriptionCancelledEventData} data + * @param {Date} timestamp + */ + constructor(data, timestamp) { + this.data = data; + this.timestamp = timestamp; + } + + /** + * @param {SubscriptionCancelledEventData} data + * @param {Date} [timestamp] + */ + static create(data, timestamp) { + return new SubscriptionCancelledEvent(data, timestamp || new Date); + } +}; diff --git a/ghost/member-events/lib/SubscriptionCreatedEvent.js b/ghost/member-events/lib/SubscriptionCreatedEvent.js index 30f242a35e..afa3479b40 100644 --- a/ghost/member-events/lib/SubscriptionCreatedEvent.js +++ b/ghost/member-events/lib/SubscriptionCreatedEvent.js @@ -1,6 +1,8 @@ /** * @typedef {object} SubscriptionCreatedEventData + * @prop {string} source * @prop {string} memberId + * @prop {string} tierId * @prop {string} subscriptionId * @prop {string} offerId * @prop {import('@tryghost/member-attribution/lib/attribution').Attribution} [attribution]