Skip to content

Commit

Permalink
Add tenantDomain to StoryCreatedEventPayload (#2899)
Browse files Browse the repository at this point in the history
* 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 <me@wyattjoh.ca>
  • Loading branch information
cristiandean and wyattjoh committed Apr 2, 2020
1 parent 94ece10 commit 7c3c510
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
15 changes: 15 additions & 0 deletions WEBHOOKS.md
Expand Up @@ -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;
}
```

Expand All @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions src/core/server/events/events.ts
Expand Up @@ -79,6 +79,7 @@ export type StoryCreatedCoralEventPayload = CoralEventPayload<
{
storyID: string;
storyURL: string;
siteID: string;
}
>;

Expand Down
20 changes: 18 additions & 2 deletions src/core/server/queue/tasks/webhook/processor.ts
Expand Up @@ -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<Endpoint, "signingSecrets">,
data: CoralEventPayload,
data: CoralWebhookEventPayload,
now: Date
): FetchOptions {
// Serialize the body and signature to include in the request.
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions src/core/server/services/stories/index.ts
Expand Up @@ -94,6 +94,7 @@ export async function findOrCreate(
StoryCreatedCoralEvent.publish(broker, {
storyID: story.id,
storyURL: story.url,
siteID: story.siteID,
});
}

Expand Down Expand Up @@ -222,6 +223,7 @@ export async function create(
StoryCreatedCoralEvent.publish(broker, {
storyID: story.id,
storyURL: story.url,
siteID: site.id,
});

return story;
Expand Down

0 comments on commit 7c3c510

Please sign in to comment.