From 698d5287c27569fc10074f50510b37fed6dfcdc0 Mon Sep 17 00:00:00 2001 From: Thomas Heartman Date: Wed, 9 Jul 2025 15:47:17 +0200 Subject: [PATCH] add quick impl --- src/lib/services/hubspot-reporting-service.ts | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/lib/services/hubspot-reporting-service.ts b/src/lib/services/hubspot-reporting-service.ts index 7153cd901e..f9784d39c7 100644 --- a/src/lib/services/hubspot-reporting-service.ts +++ b/src/lib/services/hubspot-reporting-service.ts @@ -8,13 +8,31 @@ import type { IFlagResolver, IUnleashConfig, IEventStore, + IEnvironmentStore, } from '../types/index.js'; +type FlagEnabledEvent = { + email: string; + client_id: string; + date: Date; + project: string; + environment_type: string; +}; + +type SdkConnectedEvent = { + client_id: string; + date: Date; + sdk: string; // the same thing we report via the unleash-sdk header, e.g. unleash-client-js:1.0.0 + app_name: string; +}; + export class FeatureLifecycleService { private eventStore: IEventStore; private flagResolver: IFlagResolver; + private environmentStore: IEnvironmentStore; + private eventBus: EventEmitter; private logger: Logger; @@ -22,8 +40,10 @@ export class FeatureLifecycleService { constructor( { eventStore, + environmentStore, }: { eventStore: IEventStore; + environmentStore: IEnvironmentStore; }, { flagResolver, @@ -32,6 +52,7 @@ export class FeatureLifecycleService { }: Pick, ) { this.eventStore = eventStore; + this.environmentStore = environmentStore; this.flagResolver = flagResolver; this.eventBus = eventBus; this.logger = getLogger( @@ -42,7 +63,19 @@ export class FeatureLifecycleService { listen() { this.eventStore.on(FEATURE_ENVIRONMENT_ENABLED, async (event) => { if (this.flagResolver.isEnabled('paygTrialEvents')) { - // report to HS + const envName = event.environment; + const environment = await this.environmentStore.get(envName); + + const environmentType = + environment?.type || `Unknown type. Name was ${envName}.`; + + const hsEvent: FlagEnabledEvent = { + email: event.createdBy, + client_id: '', // todo: this.client_id? + date: event.createdAt, + project: event.project, + environment_type: environmentType, + }; } }); this.eventBus.on(