Skip to content

Commit

Permalink
fix(core): Add 'user_id' to license-community-plus-registered telem…
Browse files Browse the repository at this point in the history
…etry event (#11430)
  • Loading branch information
cstuncsik authored Oct 29, 2024
1 parent 4f511aa commit 7a8dafe
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1061,13 +1061,15 @@ describe('TelemetryEventRelay', () => {
describe('Community+ registered', () => {
it('should track `license-community-plus-registered` event', () => {
const event: RelayEventMap['license-community-plus-registered'] = {
userId: 'user123',
email: 'user@example.com',
licenseKey: 'license123',
};

eventService.emit('license-community-plus-registered', event);

expect(telemetry.track).toHaveBeenCalledWith('User registered for license community plus', {
user_id: 'user123',
email: 'user@example.com',
licenseKey: 'license123',
});
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/events/maps/relay.event-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {

import type { AuthProviderType } from '@/databases/entities/auth-identity';
import type { ProjectRole } from '@/databases/entities/project-relation';
import type { GlobalRole } from '@/databases/entities/user';
import type { GlobalRole, User } from '@/databases/entities/user';
import type { IWorkflowDb } from '@/interfaces';

import type { AiEventMap } from './ai.event-map';
Expand Down Expand Up @@ -421,6 +421,7 @@ export type RelayEventMap = {
};

'license-community-plus-registered': {
userId: User['id'];
email: string;
licenseKey: string;
};
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/events/relays/telemetry.event-relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,12 @@ export class TelemetryEventRelay extends EventRelay {
}

private licenseCommunityPlusRegistered({
userId,
email,
licenseKey,
}: RelayEventMap['license-community-plus-registered']) {
this.telemetry.track('User registered for license community plus', {
user_id: userId,
email,
licenseKey,
});
Expand Down
3 changes: 3 additions & 0 deletions packages/cli/src/license/__tests__/license.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ describe('LicenseService', () => {
.spyOn(axios, 'post')
.mockResolvedValueOnce({ data: { title: 'Title', text: 'Text', licenseKey: 'abc-123' } });
const data = await licenseService.registerCommunityEdition({
userId: '123',
email: 'test@ema.il',
instanceId: '123',
instanceUrl: 'http://localhost',
Expand All @@ -102,6 +103,7 @@ describe('LicenseService', () => {

expect(data).toEqual({ title: 'Title', text: 'Text' });
expect(eventService.emit).toHaveBeenCalledWith('license-community-plus-registered', {
userId: '123',
email: 'test@ema.il',
licenseKey: 'abc-123',
});
Expand All @@ -111,6 +113,7 @@ describe('LicenseService', () => {
jest.spyOn(axios, 'post').mockRejectedValueOnce(new AxiosError('Failed'));
await expect(
licenseService.registerCommunityEdition({
userId: '123',
email: 'test@ema.il',
instanceId: '123',
instanceUrl: 'http://localhost',
Expand Down
5 changes: 3 additions & 2 deletions packages/cli/src/license/license.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { InstanceSettings } from 'n8n-core';

import { Get, Post, RestController, GlobalScope, Body } from '@/decorators';
import { BadRequestError } from '@/errors/response-errors/bad-request.error';
import { AuthenticatedRequest, AuthlessRequest, LicenseRequest } from '@/requests';
import { AuthenticatedRequest, LicenseRequest } from '@/requests';
import { UrlService } from '@/services/url.service';

import { LicenseService } from './license.service';
Expand Down Expand Up @@ -41,11 +41,12 @@ export class LicenseController {

@Post('/enterprise/community-registered')
async registerCommunityEdition(
_req: AuthlessRequest,
req: AuthenticatedRequest,
_res: Response,
@Body payload: CommunityRegisteredRequestDto,
) {
return await this.licenseService.registerCommunityEdition({
userId: req.user.id,
email: payload.email,
instanceId: this.instanceSettings.instanceId,
instanceUrl: this.urlService.getInstanceBaseUrl(),
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/src/license/license.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@ export class LicenseService {
}

async registerCommunityEdition({
userId,
email,
instanceId,
instanceUrl,
licenseType,
}: {
userId: User['id'];
email: string;
instanceId: string;
instanceUrl: string;
Expand All @@ -83,7 +85,7 @@ export class LicenseService {
licenseType,
},
);
this.eventService.emit('license-community-plus-registered', { email, licenseKey });
this.eventService.emit('license-community-plus-registered', { userId, email, licenseKey });
return rest;
} catch (e: unknown) {
if (e instanceof AxiosError) {
Expand Down

0 comments on commit 7a8dafe

Please sign in to comment.