From d2a3a4a080cdcc04f50fa33fd81d361efce3f709 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Tue, 23 Jul 2024 12:31:56 +0200 Subject: [PATCH] fix(core): Fix handling of common events for relays (#10135) --- .../src/eventbus/audit-event-relay.service.ts | 16 +++++--------- packages/cli/src/eventbus/event.types.ts | 22 ++++++++++++------- .../telemetry-event-relay.service.ts | 4 ---- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/packages/cli/src/eventbus/audit-event-relay.service.ts b/packages/cli/src/eventbus/audit-event-relay.service.ts index 96cc7366f6..9c73494520 100644 --- a/packages/cli/src/eventbus/audit-event-relay.service.ts +++ b/packages/cli/src/eventbus/audit-event-relay.service.ts @@ -38,8 +38,8 @@ export class AuditEventRelay { this.eventService.on('user-password-reset-request-click', (event) => this.userPasswordResetRequestClick(event), ); - this.eventService.on('public-api-key-created', (event) => this.apiKeyCreated(event)); - this.eventService.on('public-api-key-deleted', (event) => this.apiKeyDeleted(event)); + this.eventService.on('public-api-key-created', (event) => this.publicApiKeyCreated(event)); + this.eventService.on('public-api-key-deleted', (event) => this.publicApiKeyDeleted(event)); this.eventService.on('email-failed', (event) => this.emailFailed(event)); this.eventService.on('credentials-created', (event) => this.credentialsCreated(event)); this.eventService.on('credentials-deleted', (event) => this.credentialsDeleted(event)); @@ -257,22 +257,18 @@ export class AuditEventRelay { */ @Redactable() - private apiKeyCreated(event: Event['public-api-key-created']) { - if ('publicApi' in event) return; - + private publicApiKeyCreated({ user }: Event['public-api-key-created']) { void this.eventBus.sendAuditEvent({ eventName: 'n8n.audit.user.api.created', - payload: event.user, + payload: user, }); } @Redactable() - private apiKeyDeleted(event: Event['public-api-key-deleted']) { - if ('publicApi' in event) return; - + private publicApiKeyDeleted({ user }: Event['public-api-key-deleted']) { void this.eventBus.sendAuditEvent({ eventName: 'n8n.audit.user.api.deleted', - payload: event.user, + payload: user, }); } diff --git a/packages/cli/src/eventbus/event.types.ts b/packages/cli/src/eventbus/event.types.ts index 7f512cb03d..733144a596 100644 --- a/packages/cli/src/eventbus/event.types.ts +++ b/packages/cli/src/eventbus/event.types.ts @@ -112,14 +112,6 @@ export type Event = { apiVersion: string; }; - 'public-api-key-created': - | { user: UserLike } // audit - | { user: UserLike; publicApi: boolean }; // telemetry - - 'public-api-key-deleted': - | { user: UserLike } // audit - | { user: UserLike; publicApi: boolean }; // telemetry - 'email-failed': { user: UserLike; messageType: @@ -275,4 +267,18 @@ export type Event = { isNew: boolean; errorMessage?: string; }; + + /** + * Events listened to by more than one relay + */ + + 'public-api-key-created': { + user: UserLike; // audit and telemetry + publicApi: boolean; // telemetry only + }; + + 'public-api-key-deleted': { + user: UserLike; // audit and telemetry + publicApi: boolean; // telemetry only + }; }; diff --git a/packages/cli/src/telemetry/telemetry-event-relay.service.ts b/packages/cli/src/telemetry/telemetry-event-relay.service.ts index b320b4ac35..9517ec20b1 100644 --- a/packages/cli/src/telemetry/telemetry-event-relay.service.ts +++ b/packages/cli/src/telemetry/telemetry-event-relay.service.ts @@ -219,8 +219,6 @@ export class TelemetryEventRelay { } private publicApiKeyCreated(event: Event['public-api-key-created']) { - if (!('publicApi' in event)) return; - const { user, publicApi } = event; void this.telemetry.track('API key created', { @@ -230,8 +228,6 @@ export class TelemetryEventRelay { } private publicApiKeyDeleted(event: Event['public-api-key-deleted']) { - if (!('publicApi' in event)) return; - const { user, publicApi } = event; void this.telemetry.track('API key deleted', {