diff --git a/packages/cli/src/Interfaces.ts b/packages/cli/src/Interfaces.ts index 3f373e9d9f..cd3738815b 100644 --- a/packages/cli/src/Interfaces.ts +++ b/packages/cli/src/Interfaces.ts @@ -348,6 +348,8 @@ export interface IDiagnosticInfo { smtp_set_up: boolean; ldap_allowed: boolean; saml_enabled: boolean; + licensePlanName?: string; + licenseTenantId?: number; } export interface ITelemetryUserDeletionData { diff --git a/packages/cli/src/InternalHooks.ts b/packages/cli/src/InternalHooks.ts index 128616e4de..6e3911de87 100644 --- a/packages/cli/src/InternalHooks.ts +++ b/packages/cli/src/InternalHooks.ts @@ -97,6 +97,8 @@ export class InternalHooks implements IInternalHooksClass { smtp_set_up: diagnosticInfo.smtp_set_up, ldap_allowed: diagnosticInfo.ldap_allowed, saml_enabled: diagnosticInfo.saml_enabled, + license_plan_name: diagnosticInfo.licensePlanName, + license_tenant_id: diagnosticInfo.licenseTenantId, }; return Promise.all([ diff --git a/packages/cli/src/Server.ts b/packages/cli/src/Server.ts index 7f28c4d0e4..944ce74e81 100644 --- a/packages/cli/src/Server.ts +++ b/packages/cli/src/Server.ts @@ -410,6 +410,8 @@ export class Server extends AbstractServer { smtp_set_up: config.getEnv('userManagement.emails.mode') === 'smtp', ldap_allowed: isLdapCurrentAuthenticationMethod(), saml_enabled: isSamlCurrentAuthenticationMethod(), + licensePlanName: Container.get(License).getPlanName(), + licenseTenantId: config.getEnv('license.tenantId'), }; if (inDevelopment && process.env.N8N_DEV_RELOAD === 'true') { diff --git a/packages/cli/test/unit/InternalHooks.test.ts b/packages/cli/test/unit/InternalHooks.test.ts new file mode 100644 index 0000000000..5d240f0239 --- /dev/null +++ b/packages/cli/test/unit/InternalHooks.test.ts @@ -0,0 +1,74 @@ +import { Telemetry } from '@/telemetry'; +import { RoleService } from '@/services/role.service'; +import { InternalHooks } from '@/InternalHooks'; +import { NodeTypes } from '@/NodeTypes'; +import { ExecutionRepository } from '@/databases/repositories'; +import { EventsService } from '@/services/events.service'; +import { mockInstance } from '../integration/shared/utils'; +import type { IDiagnosticInfo } from '@/Interfaces'; + +jest.mock('@/telemetry'); + +let internalHooks: InternalHooks; +let telemetry: Telemetry; + +describe('InternalHooks', () => { + beforeAll(() => { + telemetry = mockInstance(Telemetry); + internalHooks = new InternalHooks( + telemetry, + mockInstance(NodeTypes), + mockInstance(RoleService), + mockInstance(ExecutionRepository), + mockInstance(EventsService), + ); + }); + + it('Should be defined', () => { + expect(internalHooks).toBeDefined(); + }); + + it('Should forward license plan name and tenant id to identify when provided', async () => { + const licensePlanName = 'license-plan-name'; + const licenseTenantId = 1001; + + const diagnosticInfo: IDiagnosticInfo = { + versionCli: '1.2.3', + databaseType: 'sqlite', + notificationsEnabled: true, + disableProductionWebhooksOnMainProcess: false, + systemInfo: { + os: {}, + cpus: {}, + }, + executionVariables: {}, + deploymentType: 'testing', + binaryDataMode: 'default', + smtp_set_up: false, + ldap_allowed: true, + saml_enabled: true, + licensePlanName, + licenseTenantId, + }; + + const parameters = { + version_cli: diagnosticInfo.versionCli, + db_type: diagnosticInfo.databaseType, + n8n_version_notifications_enabled: diagnosticInfo.notificationsEnabled, + n8n_disable_production_main_process: diagnosticInfo.disableProductionWebhooksOnMainProcess, + system_info: diagnosticInfo.systemInfo, + execution_variables: diagnosticInfo.executionVariables, + n8n_deployment_type: diagnosticInfo.deploymentType, + n8n_binary_data_mode: diagnosticInfo.binaryDataMode, + smtp_set_up: diagnosticInfo.smtp_set_up, + ldap_allowed: diagnosticInfo.ldap_allowed, + saml_enabled: diagnosticInfo.saml_enabled, + license_plan_name: diagnosticInfo.licensePlanName, + license_tenant_id: diagnosticInfo.licenseTenantId, + }; + + await internalHooks.onServerStarted(diagnosticInfo); + + expect(telemetry.identify).toHaveBeenCalledWith(parameters); + }); +});