mirror of
https://github.com/Unleash/unleash.git
synced 2025-09-05 17:53:12 +02:00
add version service
This commit is contained in:
parent
c851ceae40
commit
981df3bdd6
@ -10,18 +10,19 @@ import type {
|
|||||||
IEventStore,
|
IEventStore,
|
||||||
IEnvironmentStore,
|
IEnvironmentStore,
|
||||||
} from '../types/index.js';
|
} from '../types/index.js';
|
||||||
|
import type VersionService from './version-service.js';
|
||||||
|
|
||||||
type FlagEnabledEvent = {
|
type FlagEnabledEvent = {
|
||||||
email: string;
|
email: string;
|
||||||
client_id: string;
|
client_id: string;
|
||||||
date: Date;
|
date: string;
|
||||||
project: string;
|
project: string;
|
||||||
environment_type: string;
|
environment_type: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
type SdkConnectedEvent = {
|
type SdkConnectedEvent = {
|
||||||
client_id: string;
|
client_id: string;
|
||||||
date: Date;
|
date: string;
|
||||||
sdk: string; // the same thing we report via the unleash-sdk header, e.g. unleash-client-js:1.0.0
|
sdk: string; // the same thing we report via the unleash-sdk header, e.g. unleash-client-js:1.0.0
|
||||||
app_name: string;
|
app_name: string;
|
||||||
};
|
};
|
||||||
@ -35,6 +36,8 @@ export class FeatureLifecycleService {
|
|||||||
|
|
||||||
private eventBus: EventEmitter;
|
private eventBus: EventEmitter;
|
||||||
|
|
||||||
|
private versionService: VersionService;
|
||||||
|
|
||||||
private logger: Logger;
|
private logger: Logger;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@ -45,6 +48,12 @@ export class FeatureLifecycleService {
|
|||||||
eventStore: IEventStore;
|
eventStore: IEventStore;
|
||||||
environmentStore: IEnvironmentStore;
|
environmentStore: IEnvironmentStore;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
versionService,
|
||||||
|
}: {
|
||||||
|
versionService: VersionService;
|
||||||
|
},
|
||||||
{
|
{
|
||||||
flagResolver,
|
flagResolver,
|
||||||
eventBus,
|
eventBus,
|
||||||
@ -55,6 +64,7 @@ export class FeatureLifecycleService {
|
|||||||
this.environmentStore = environmentStore;
|
this.environmentStore = environmentStore;
|
||||||
this.flagResolver = flagResolver;
|
this.flagResolver = flagResolver;
|
||||||
this.eventBus = eventBus;
|
this.eventBus = eventBus;
|
||||||
|
this.versionService = versionService;
|
||||||
this.logger = getLogger(
|
this.logger = getLogger(
|
||||||
'feature-lifecycle/feature-lifecycle-service.ts',
|
'feature-lifecycle/feature-lifecycle-service.ts',
|
||||||
);
|
);
|
||||||
@ -62,6 +72,7 @@ export class FeatureLifecycleService {
|
|||||||
|
|
||||||
listen() {
|
listen() {
|
||||||
this.eventStore.on(FEATURE_ENVIRONMENT_ENABLED, async (event) => {
|
this.eventStore.on(FEATURE_ENVIRONMENT_ENABLED, async (event) => {
|
||||||
|
// @ts-expect-error
|
||||||
if (this.flagResolver.isEnabled('paygTrialEvents')) {
|
if (this.flagResolver.isEnabled('paygTrialEvents')) {
|
||||||
const envName = event.environment;
|
const envName = event.environment;
|
||||||
const environment = await this.environmentStore.get(envName);
|
const environment = await this.environmentStore.get(envName);
|
||||||
@ -69,9 +80,11 @@ export class FeatureLifecycleService {
|
|||||||
const environmentType =
|
const environmentType =
|
||||||
environment?.type || `Unknown type. Name was ${envName}.`;
|
environment?.type || `Unknown type. Name was ${envName}.`;
|
||||||
|
|
||||||
|
const instanceId = await this.versionService.getInstanceId();
|
||||||
|
|
||||||
const hsEvent: FlagEnabledEvent = {
|
const hsEvent: FlagEnabledEvent = {
|
||||||
email: event.createdBy,
|
email: event.createdBy,
|
||||||
client_id: '', // todo: this.client_id?
|
client_id: instanceId ?? 'No instance ID',
|
||||||
date: event.createdAt,
|
date: event.createdAt,
|
||||||
project: event.project,
|
project: event.project,
|
||||||
environment_type: environmentType,
|
environment_type: environmentType,
|
||||||
@ -81,6 +94,7 @@ export class FeatureLifecycleService {
|
|||||||
this.eventBus.on(
|
this.eventBus.on(
|
||||||
CLIENT_METRICS, // or CLIENT_METRICS_ADDED? 🤷
|
CLIENT_METRICS, // or CLIENT_METRICS_ADDED? 🤷
|
||||||
async (event) => {
|
async (event) => {
|
||||||
|
// @ts-expect-error
|
||||||
if (this.flagResolver.isEnabled('paygTrialEvents')) {
|
if (this.flagResolver.isEnabled('paygTrialEvents')) {
|
||||||
// todo: report to HS
|
// todo: report to HS
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user