mirror of
https://github.com/Unleash/unleash.git
synced 2025-08-27 13:49:10 +02:00
add quick impl
This commit is contained in:
parent
e8d2990c6c
commit
698d5287c2
@ -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<IUnleashConfig, 'flagResolver' | 'eventBus' | 'getLogger'>,
|
||||
) {
|
||||
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(
|
||||
|
Loading…
Reference in New Issue
Block a user