Skip to content

Commit

Permalink
Merge pull request #1 from felixvo/fix/missing-data-in-webhook
Browse files Browse the repository at this point in the history
fix: missing action and item id in webhook data (directus#9518)
  • Loading branch information
felixvo committed Nov 16, 2021
2 parents 785c430 + b172c0e commit bbbd68a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions api/src/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class Emitter {

public emitAction(event: string, meta: Record<string, any>, context: HookContext): void {
const events = this.eventsToEmit(event, meta);
meta['action'] = event; // use in webhook ActionHandler
for (const event of events) {
this.actionEmitter.emitAsync(event, meta, context).catch((err) => {
logger.warn(`An error was thrown while executing action "${event}"`);
Expand Down
2 changes: 2 additions & 0 deletions api/src/services/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ export class ItemsService<Item extends AnyItem = AnyItem> implements AbstractSer
{
payload,
key: primaryKey,
keys: [primaryKey],
collection: this.collection,
},
{
Expand Down Expand Up @@ -664,6 +665,7 @@ export class ItemsService<Item extends AnyItem = AnyItem> implements AbstractSer
emitter.emitAction(
`${this.eventScope}.delete`,
{
keys: keys,
payload: keys,
collection: this.collection,
},
Expand Down
3 changes: 3 additions & 0 deletions api/src/webhooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,15 @@ function createHandler(webhook: Webhook): ActionHandler {
return async (data) => {
if (webhook.collections.includes('*') === false && webhook.collections.includes(data.collection) === false) return;

data['item'] = data['keys'];

const webhookPayload = pick(data, [
'event',
'accountability.user',
'accountability.role',
'collection',
'item',
'keys', //support both item and keys
'action',
'payload',
]);
Expand Down

0 comments on commit bbbd68a

Please sign in to comment.