From 07a69c0f4b6c85d865285f9629dbf22fd4e45d16 Mon Sep 17 00:00:00 2001 From: Alena Khineika Date: Sat, 27 Jun 2026 20:56:56 +0200 Subject: [PATCH 1/2] refactor(tracking-plan): identifyTraits must have payload --- packages/tracking-plan/src/index.ts | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/packages/tracking-plan/src/index.ts b/packages/tracking-plan/src/index.ts index 5727fdae..40fc1a59 100644 --- a/packages/tracking-plan/src/index.ts +++ b/packages/tracking-plan/src/index.ts @@ -59,24 +59,23 @@ function getTelemetryEventNames( function buildInMemorySource( originalSource: ts.SourceFile, eventTypeNames: string[], - identifyTraitsName: string, commonPropertiesName?: string, ): ts.SourceFile { // Appends "Resolved*" type aliases that flatten intersections and type references // into basic types. The TypeChecker then emits fully-expanded, readable types // for each event property in the tracking plan. + // All events (including identity events) must have a `payload` field. const resolvedEvents = eventTypeNames .map( (name) => ` type Resolved${name} = { name: ${name}['name']; - payload: ResolveType<${name} extends { payload: infer P } ? P : Record>; + payload: ResolveType<${name}['payload']>; };`, ) .join('\n'); const resolvedSections = [ - `type Resolved${identifyTraitsName} = ResolveType<${identifyTraitsName}>;`, commonPropertiesName ? `type Resolved${commonPropertiesName} = ResolveType<${commonPropertiesName}>;` : '', @@ -305,7 +304,6 @@ function renderSection( function generateMarkdown( config: GenerateTrackingPlanConfig, events: EventInfo[], - identifyTraits: SectionInfo, commonProperties?: SectionInfo, ): string { const lines: string[] = []; @@ -333,7 +331,6 @@ function generateMarkdown( if (commonProperties) { lines.push('- [Common Properties](#common-properties)'); } - lines.push('- [Identity](#identity)'); for (const cat of sortedCategories) { lines.push(`- [${cat}](#${slugify(cat)})`); for (const event of byCategory.get(cat)!) { @@ -346,8 +343,6 @@ function generateMarkdown( renderSection('Common Properties', commonProperties, lines); } - renderSection('Identity', identifyTraits, lines); - for (const cat of sortedCategories) { lines.push(''); lines.push(`## ${cat}`); @@ -378,22 +373,15 @@ export function generateTrackingPlan( ); const unionTypeName = 'TelemetryEvent'; - const identifyTraitsName = 'IdentifyTraits'; const commonPropertiesName = 'CommonEventProperties'; const eventTypeNames = getTelemetryEventNames(originalSource, unionTypeName); const inMemorySource = buildInMemorySource( originalSource, eventTypeNames, - identifyTraitsName, commonPropertiesName, ); const checker = createChecker(inMemorySource); - const identifyTraits = parseSectionType( - identifyTraitsName, - inMemorySource, - checker, - ); const hasCommonProperties = originalSource.statements.some( (n) => (ts.isTypeAliasDeclaration(n) || ts.isInterfaceDeclaration(n)) && @@ -407,5 +395,5 @@ export function generateTrackingPlan( parseTelemetryEvent(name, inMemorySource, checker), ); - return generateMarkdown(config, events, identifyTraits, commonProperties); + return generateMarkdown(config, events, commonProperties); } From 2c3b22ac812e61cde626d71d6ef532123c504dfa Mon Sep 17 00:00:00 2001 From: Alena Khineika Date: Sat, 27 Jun 2026 21:00:45 +0200 Subject: [PATCH 2/2] test: update tests --- .../test/fixtures/telemetry-events.ts | 23 ++++++++++++------- packages/tracking-plan/test/index.test.ts | 4 ++-- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/packages/tracking-plan/test/fixtures/telemetry-events.ts b/packages/tracking-plan/test/fixtures/telemetry-events.ts index c2f5069a..b71dd655 100644 --- a/packages/tracking-plan/test/fixtures/telemetry-events.ts +++ b/packages/tracking-plan/test/fixtures/telemetry-events.ts @@ -4,13 +4,19 @@ export interface CommonEventProperties { session_id: string; } -/** Traits sent with identify calls. */ -export interface IdentifyTraits { - /** Unique identifier for the device. */ - device_id: string; - /** The operating system platform. */ - platform: string; -} +/** + * Fired when a user is identified. + * @category Identity + */ +export type IdentifyEvent = { + name: 'Identify'; + payload: { + /** Unique identifier for the device. */ + device_id: string; + /** The operating system platform. */ + platform: string; + }; +}; /** * Fired when a connection to the server is established. @@ -50,4 +56,5 @@ export type ApplicationLaunchedEvent = { export type TelemetryEvent = | ConnectionEvent | QueryExecutedEvent - | ApplicationLaunchedEvent; + | ApplicationLaunchedEvent + | IdentifyEvent; diff --git a/packages/tracking-plan/test/index.test.ts b/packages/tracking-plan/test/index.test.ts index 774d6685..51c8f428 100644 --- a/packages/tracking-plan/test/index.test.ts +++ b/packages/tracking-plan/test/index.test.ts @@ -45,8 +45,8 @@ describe('TrackingPlan', function () { assert.ok(result.includes('Do not edit manually')); }); - it('renders the Identity section with trait properties', function () { - assert.ok(result.includes('## Identity')); + it('renders the identify event alongside other events with its payload properties', function () { + assert.ok(result.includes('### Identify')); assert.ok(result.includes('`device_id`')); assert.ok(result.includes('`platform`')); });