From ed9eccd74326955c7854da254106a8290f3aa00d Mon Sep 17 00:00:00 2001 From: Thomas Heartman Date: Mon, 14 Jul 2025 13:02:29 +0200 Subject: [PATCH] chore: add application_created event type (#10351) This is primarily to facilitate reading and processing these events in the payg cloud section of Unleash. We only emit these in one place, so I added the types in there. --- .../metrics/instance/instance-service.ts | 22 ++++++++++++------- src/lib/types/events.ts | 13 +++++++++++ 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/lib/features/metrics/instance/instance-service.ts b/src/lib/features/metrics/instance/instance-service.ts index acc4ef4c53..30773e59f7 100644 --- a/src/lib/features/metrics/instance/instance-service.ts +++ b/src/lib/features/metrics/instance/instance-service.ts @@ -24,7 +24,11 @@ import type { IClientMetricsStoreV2 } from '../client-metrics/client-metrics-sto import { clientMetricsSchema } from '../shared/schema.js'; import type { PartialSome } from '../../../types/partial.js'; import type { IPrivateProjectChecker } from '../../private-project/privateProjectCheckerType.js'; -import { type IFlagResolver, SYSTEM_USER } from '../../../types/index.js'; +import { + type ApplicationCreatedEvent, + type IFlagResolver, + SYSTEM_USER, +} from '../../../types/index.js'; import { ALL_PROJECTS, parseStrictSemVer } from '../../../util/index.js'; import type { Logger } from '../../../logger.js'; import { findOutdatedSDKs, isOutdatedSdk } from './findOutdatedSdks.js'; @@ -148,13 +152,15 @@ export default class ClientInstanceService { const appsToAnnounce = await this.clientApplicationsStore.setUnannouncedToAnnounced(); if (appsToAnnounce.length > 0) { - const events = appsToAnnounce.map((app) => ({ - type: APPLICATION_CREATED, - createdBy: app.createdBy || SYSTEM_USER.username!, - data: app, - createdByUserId: app.createdByUserId || SYSTEM_USER.id, - ip: '', // TODO: fix this, how do we get the ip from the client? This comes from a row in the DB - })); + const events: ApplicationCreatedEvent[] = appsToAnnounce.map( + (app) => ({ + type: APPLICATION_CREATED, + createdBy: app.createdBy || SYSTEM_USER.username!, + data: app, + createdByUserId: app.createdByUserId || SYSTEM_USER.id, + ip: '', // TODO: fix this, how do we get the ip from the client? This comes from a row in the DB + }), + ); await this.eventStore.batchStore(events); } } diff --git a/src/lib/types/events.ts b/src/lib/types/events.ts index 8baae7ce85..6d5d038067 100644 --- a/src/lib/types/events.ts +++ b/src/lib/types/events.ts @@ -120,8 +120,10 @@ import { FEATURE_LINK_REMOVED, FEATURE_LINK_UPDATED, FEATURE_LINK_ADDED, + APPLICATION_CREATED, } from '../events/index.js'; import type { ITag } from '../tags/index.js'; +import type { IClientApplication } from './stores/client-applications-store.js'; export class BaseEvent implements IBaseEvent { readonly type: IEventType; @@ -1917,6 +1919,17 @@ export class ReleasePlanMilestoneStartedEvent extends BaseEvent { } } +export class ApplicationCreatedEvent extends BaseEvent { + readonly data: IClientApplication; + constructor(eventData: { + data: IClientApplication; + auditUser: IAuditUser; + }) { + super(APPLICATION_CREATED, eventData.auditUser); + this.data = eventData.data; + } +} + interface IUserEventData extends Pick< IUserWithRootRole,