From 7c3c510bbc2a799e0dadbcc1ccd12738550451ce Mon Sep 17 00:00:00 2001 From: Cristian Dean Date: Thu, 2 Apr 2020 18:39:58 -0300 Subject: [PATCH] Add tenantDomain to StoryCreatedEventPayload (#2899) * Add tenantID and siteID to StoryCreatedEventPayload * fix: added tenantID to payload * Remove tenantID from StoryCreatedCoralEvent * Add tenantDomain to webhook schema * fix: small comment fixes Co-authored-by: Wyatt Johnson --- WEBHOOKS.md | 15 ++++++++++++++ src/core/server/events/events.ts | 1 + .../server/queue/tasks/webhook/processor.ts | 20 +++++++++++++++++-- src/core/server/services/stories/index.ts | 2 ++ 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/WEBHOOKS.md b/WEBHOOKS.md index be39682f24..364c552c3e 100644 --- a/WEBHOOKS.md +++ b/WEBHOOKS.md @@ -174,6 +174,16 @@ function when comparing signatures. * date when this event was created. */ createdAt: string; + + /** + * tenantID is the ID of the Tenant that this event originated at. + */ + tenantID: string; + + /** + * tenantDomain is the domain that is associated with this Tenant that this event originated at. + */ + tenantDomain: string; } ``` @@ -199,6 +209,11 @@ function when comparing signatures. * storyURL is the URL of the newly created Story. */ storyURL: string; + + /** + * siteID is the Site that the newly created Story was created on. + */ + siteID: string; } createdAt: string; } diff --git a/src/core/server/events/events.ts b/src/core/server/events/events.ts index 3eadd300d2..d7dbf7514d 100644 --- a/src/core/server/events/events.ts +++ b/src/core/server/events/events.ts @@ -79,6 +79,7 @@ export type StoryCreatedCoralEventPayload = CoralEventPayload< { storyID: string; storyURL: string; + siteID: string; } >; diff --git a/src/core/server/queue/tasks/webhook/processor.ts b/src/core/server/queue/tasks/webhook/processor.ts index dc4d4d71fd..4dff502874 100644 --- a/src/core/server/queue/tasks/webhook/processor.ts +++ b/src/core/server/queue/tasks/webhook/processor.ts @@ -82,9 +82,21 @@ export function generateSignatures( .join(","); } +type CoralWebhookEventPayload = CoralEventPayload & { + /** + * tenantID is the ID of the Tenant that this event originated at. + */ + readonly tenantID: string; + + /** + * tenantDomain is the domain that is associated with this Tenant that this event originated at. + */ + readonly tenantDomain: string; +}; + export function generateFetchOptions( endpoint: Pick, - data: CoralEventPayload, + data: CoralWebhookEventPayload, now: Date ): FetchOptions { // Serialize the body and signature to include in the request. @@ -151,7 +163,11 @@ export function createJobProcessor({ const now = new Date(); // Get the fetch options. - const options = generateFetchOptions(endpoint, event, now); + const options = generateFetchOptions( + endpoint, + { ...event, tenantID, tenantDomain: tenant.domain }, + now + ); // Send the request. const startedSendingAt = getNow(); diff --git a/src/core/server/services/stories/index.ts b/src/core/server/services/stories/index.ts index b5e787d9dc..7b2a4b9e40 100644 --- a/src/core/server/services/stories/index.ts +++ b/src/core/server/services/stories/index.ts @@ -94,6 +94,7 @@ export async function findOrCreate( StoryCreatedCoralEvent.publish(broker, { storyID: story.id, storyURL: story.url, + siteID: story.siteID, }); } @@ -222,6 +223,7 @@ export async function create( StoryCreatedCoralEvent.publish(broker, { storyID: story.id, storyURL: story.url, + siteID: site.id, }); return story;