Skip to content

Commit 7e40a55

Browse files
[FSSDK-11197] EventTags type fix
1 parent b2e28c4 commit 7e40a55

File tree

5 files changed

+28
-11
lines changed

5 files changed

+28
-11
lines changed

lib/event_processor/event_builder/log_event.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@ describe('buildConversionEventV1', () => {
251251
},
252252

253253
tags: {
254+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
255+
// @ts-ignore
254256
foo: 'bar',
255257
value: '123',
256258
revenue: '1000',
@@ -496,6 +498,8 @@ describe('buildConversionEventV1', () => {
496498
},
497499

498500
tags: {
501+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
502+
// @ts-ignore
499503
foo: 'bar',
500504
value: 0,
501505
revenue: 0,
@@ -582,6 +586,8 @@ describe('buildConversionEventV1', () => {
582586
},
583587

584588
tags: {
589+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
590+
// @ts-ignore
585591
foo: 'bar',
586592
value: '123',
587593
revenue: '1000',
@@ -665,6 +671,8 @@ describe('makeEventBatch', () => {
665671
},
666672

667673
tags: {
674+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
675+
// @ts-ignore
668676
foo: 'bar',
669677
value: '123',
670678
revenue: '1000',

lib/optimizely/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -607,8 +607,9 @@ export default class Optimizely extends BaseService implements Client {
607607
*/
608608
private filterEmptyValues(map: EventTags | undefined): EventTags | undefined {
609609
for (const key in map) {
610-
if (map.hasOwnProperty(key) && (map[key] === null || map[key] === undefined)) {
611-
delete map[key];
610+
const typedKey = key as keyof EventTags;
611+
if (map.hasOwnProperty(typedKey) && (map[typedKey] === null || map[typedKey] === undefined)) {
612+
delete map[typedKey];
612613
}
613614
}
614615
return map;

lib/shared_types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,11 @@ export interface UserProfile {
8888
experiment_bucket_map: ExperimentBucketMap;
8989
}
9090

91-
export type EventTags = Record<string, unknown>;
91+
export type EventTags = {
92+
revenue?: string | number | null;
93+
value?: string | number | null;
94+
$opt_event_properties?: Record<string, unknown>;
95+
};
9296

9397
export interface UserProfileService {
9498
lookup(userId: string): UserProfile;

lib/utils/event_tag_utils/index.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ describe('getRevenueValue', () => {
5050
});
5151

5252
it('should return null if the revenue value is not present in the event tags', () => {
53+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
54+
// @ts-ignore
5355
const parsedRevenueValue = eventTagUtils.getRevenueValue({ not_revenue: '1337' }, logger);
5456

5557
expect(parsedRevenueValue).toBe(null);
@@ -81,6 +83,8 @@ describe('getEventValue', () => {
8183
});
8284

8385
it('should return null if the value is not present in the event tags', () => {
86+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
87+
// @ts-ignore
8488
const parsedNumericValue = eventTagUtils.getEventValue({ not_value: '13.37' }, logger);
8589

8690
expect(parsedNumericValue).toBe(null);

lib/utils/event_tag_utils/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ export function getRevenueValue(eventTags: EventTags, logger?: LoggerFacade): nu
4444
return null;
4545
}
4646

47-
const amount = typeof rawValue === 'number' ? rawValue : typeof rawValue === 'string' ? parseInt(rawValue) : NaN;
47+
const parsedRevenueValue = typeof rawValue === 'string' ? parseInt(rawValue) : rawValue;
4848

49-
if (isFinite(amount)) {
50-
logger?.info(PARSED_REVENUE_VALUE, amount);
51-
return amount;
49+
if (isFinite(parsedRevenueValue)) {
50+
logger?.info(PARSED_REVENUE_VALUE, parsedRevenueValue);
51+
return parsedRevenueValue;
5252
} else {
5353
// NaN, +/- infinity values
5454
logger?.info(FAILED_TO_PARSE_REVENUE, rawValue);
@@ -70,11 +70,11 @@ export function getEventValue(eventTags: EventTags, logger?: LoggerFacade): numb
7070
return null;
7171
}
7272

73-
const amount = typeof rawValue === 'number' ? rawValue : typeof rawValue === 'string' ? parseFloat(rawValue) : NaN;
73+
const parsedEventValue = typeof rawValue === 'string' ? parseFloat(rawValue) : rawValue;
7474

75-
if (isFinite(amount)) {
76-
logger?.info(PARSED_NUMERIC_VALUE, amount);
77-
return amount;
75+
if (isFinite(parsedEventValue)) {
76+
logger?.info(PARSED_NUMERIC_VALUE, parsedEventValue);
77+
return parsedEventValue;
7878
} else {
7979
// NaN, +/- infinity values
8080
logger?.info(FAILED_TO_PARSE_VALUE, rawValue);

0 commit comments

Comments
 (0)