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,
|
IFlagResolver,
|
||||||
IUnleashConfig,
|
IUnleashConfig,
|
||||||
IEventStore,
|
IEventStore,
|
||||||
|
IEnvironmentStore,
|
||||||
} from '../types/index.js';
|
} 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 {
|
export class FeatureLifecycleService {
|
||||||
private eventStore: IEventStore;
|
private eventStore: IEventStore;
|
||||||
|
|
||||||
private flagResolver: IFlagResolver;
|
private flagResolver: IFlagResolver;
|
||||||
|
|
||||||
|
private environmentStore: IEnvironmentStore;
|
||||||
|
|
||||||
private eventBus: EventEmitter;
|
private eventBus: EventEmitter;
|
||||||
|
|
||||||
private logger: Logger;
|
private logger: Logger;
|
||||||
@ -22,8 +40,10 @@ export class FeatureLifecycleService {
|
|||||||
constructor(
|
constructor(
|
||||||
{
|
{
|
||||||
eventStore,
|
eventStore,
|
||||||
|
environmentStore,
|
||||||
}: {
|
}: {
|
||||||
eventStore: IEventStore;
|
eventStore: IEventStore;
|
||||||
|
environmentStore: IEnvironmentStore;
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
flagResolver,
|
flagResolver,
|
||||||
@ -32,6 +52,7 @@ export class FeatureLifecycleService {
|
|||||||
}: Pick<IUnleashConfig, 'flagResolver' | 'eventBus' | 'getLogger'>,
|
}: Pick<IUnleashConfig, 'flagResolver' | 'eventBus' | 'getLogger'>,
|
||||||
) {
|
) {
|
||||||
this.eventStore = eventStore;
|
this.eventStore = eventStore;
|
||||||
|
this.environmentStore = environmentStore;
|
||||||
this.flagResolver = flagResolver;
|
this.flagResolver = flagResolver;
|
||||||
this.eventBus = eventBus;
|
this.eventBus = eventBus;
|
||||||
this.logger = getLogger(
|
this.logger = getLogger(
|
||||||
@ -42,7 +63,19 @@ export class FeatureLifecycleService {
|
|||||||
listen() {
|
listen() {
|
||||||
this.eventStore.on(FEATURE_ENVIRONMENT_ENABLED, async (event) => {
|
this.eventStore.on(FEATURE_ENVIRONMENT_ENABLED, async (event) => {
|
||||||
if (this.flagResolver.isEnabled('paygTrialEvents')) {
|
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(
|
this.eventBus.on(
|
||||||
|
Loading…
Reference in New Issue
Block a user