@@ -160,64 +160,25 @@ function makeConversionSnapshot(conversion: ConversionEvent): Snapshot {
160160 }
161161}
162162
163- /**
164- * Non-empty string validator used to normalize campaign_id and entity_id.
165- * IDs may be opaque, e.g. "default-12345" or "layer_abc".
166- */
167- function isNonEmptyString ( value : unknown ) : value is string {
168- return typeof value === 'string' && value . length > 0 ;
169- }
170-
171- /**
172- * Numeric-string validator used to normalize variation_id. Returns true if
173- * value is a non-empty string of decimal digits [0-9]. Leading zeros are
174- * allowed.
175- */
176- function isNumericString ( value : unknown ) : value is string {
177- return typeof value === 'string' && value . length > 0 && / ^ [ 0 - 9 ] + $ / . test ( value ) ;
178- }
179-
180- /**
181- * Normalize a campaign_id / entity_id field. Returns the provided id when
182- * it is a non-empty string; otherwise substitutes experimentId; otherwise
183- * returns null so the wire payload is byte-equivalent across SDKs.
184- */
185- function normalizeCampaignId ( id : unknown , experimentId : unknown ) : string | null {
186- if ( isNonEmptyString ( id ) ) {
187- return id ;
188- }
189- if ( isNonEmptyString ( experimentId ) ) {
190- return experimentId ;
191- }
192- return null ;
193- }
194-
195- /**
196- * Normalize a variation_id field. variation_id keeps the stricter
197- * numeric-string contract — non-numeric / empty input normalizes to null.
198- */
199- function normalizeVariationId ( id : unknown ) : string | null {
200- return isNumericString ( id ) ? id : null ;
163+ function normalizeVariationId ( id : string | null | undefined ) : string | null {
164+ return id && / ^ [ 0 - 9 ] + $ / . test ( id ) ? id : null
201165}
202166
203167function makeDecisionSnapshot ( event : ImpressionEvent ) : Snapshot {
204168 const { layer, experiment, variation, ruleKey, flagKey, ruleType, enabled, cmabUuid } = event
205- const layerId = layer ? layer . id : null
206- const experimentId = experiment ?. id ?? ''
207- const variationId = variation ?. id ?? ''
169+ const layerId = layer ? .id ;
170+ const experimentId = experiment ?. id ?? '' ;
171+ const variationId = normalizeVariationId ( variation ?. id ) ;
208172 const variationKey = variation ? variation . key : ''
209173
210- // entity_id on the impression event mirrors decisions[].campaign_id
211- // byte-for-byte so the two fields stay wire-equivalent.
212- const normalizedCampaignId = normalizeCampaignId ( layerId , experimentId ) ;
213- const normalizedVariationId = normalizeVariationId ( variationId ) ;
174+ const campaignId = layerId || experimentId || null ;
214175
215176 return {
216177 decisions : [
217178 {
218- campaign_id : normalizedCampaignId ,
179+ campaign_id : campaignId ,
219180 experiment_id : experimentId ,
220- variation_id : normalizedVariationId ,
181+ variation_id : variationId ,
221182 metadata : {
222183 flag_key : flagKey ,
223184 rule_key : ruleKey ,
@@ -230,7 +191,7 @@ function makeDecisionSnapshot(event: ImpressionEvent): Snapshot {
230191 ] ,
231192 events : [
232193 {
233- entity_id : normalizedCampaignId ,
194+ entity_id : campaignId ,
234195 timestamp : event . timestamp ,
235196 key : ACTIVATE_EVENT_KEY ,
236197 uuid : event . uuid ,
0 commit comments