Skip to content

Commit 5e8b933

Browse files
[FSSDK-11197] EventTags type fix
1 parent 90ef0d7 commit 5e8b933

File tree

5 files changed

+13
-20
lines changed

5 files changed

+13
-20
lines changed

lib/core/event_builder/build_event_v1.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,9 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import {
17-
EventTags,
18-
ConversionEvent,
19-
ImpressionEvent,
20-
} from '../../modules/event_processor';
16+
import { ConversionEvent, ImpressionEvent } from '../../modules/event_processor';
2117

22-
import { Event } from '../../shared_types';
18+
import { Event, EventTags } from '../../shared_types';
2319

2420
type ProcessableEvent = ConversionEvent | ImpressionEvent
2521

lib/modules/event_processor/events.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { EventTags } from "../../shared_types"
2+
13
/**
24
* Copyright 2022, Optimizely
35
*
@@ -82,10 +84,6 @@ export interface ConversionEvent extends BaseEvent {
8284
tags: EventTags | undefined
8385
}
8486

85-
export type EventTags = {
86-
[key: string]: string | number | null
87-
}
88-
8987
export function areEventContextsEqual(eventA: BaseEvent, eventB: BaseEvent): boolean {
9088
const contextA = eventA.context
9189
const contextB = eventB.context

lib/modules/event_processor/v1/buildEventV1.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import { EventTags, ConversionEvent, ImpressionEvent, VisitorAttribute } from '../events'
16+
import { ConversionEvent, ImpressionEvent, VisitorAttribute } from '../events'
1717
import { ProcessableEvent } from '../eventProcessor'
1818
import { EventV1Request } from '../eventDispatcher'
19+
import { EventTags } from '../../../shared_types'
1920

2021
const ACTIVATE_EVENT_KEY = 'campaign_activated'
2122
const CUSTOM_ATTRIBUTE_FEATURE_TYPE = 'custom'

lib/shared_types.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,7 @@ export interface UserProfile {
7373
experiment_bucket_map: ExperimentBucketMap;
7474
}
7575

76-
export type EventTags = {
77-
[key: string]: string | number | null;
78-
};
79-
76+
export type EventTags = Record<string, unknown>;
8077
export interface UserProfileService {
8178
lookup(userId: string): UserProfile;
8279
save(profile: UserProfile): void;

lib/utils/event_tag_utils/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import { EventTags } from '../../modules/event_processor';
16+
import { EventTags } from '../../shared_types';
1717
import { LoggerFacade } from '../../modules/logging';
18-
1918
import {
2019
LOG_LEVEL,
2120
LOG_MESSAGES,
@@ -42,7 +41,8 @@ export function getRevenueValue(eventTags: EventTags, logger: LoggerFacade): num
4241
return null;
4342
}
4443

45-
const parsedRevenueValue = typeof rawValue === 'string' ? parseInt(rawValue) : rawValue;
44+
const parsedRevenueValue =
45+
typeof rawValue === 'number' ? rawValue : typeof rawValue === 'string' ? parseInt(rawValue) : NaN;
4646

4747
if (isFinite(parsedRevenueValue)) {
4848
logger.log(LOG_LEVEL.INFO, LOG_MESSAGES.PARSED_REVENUE_VALUE, MODULE_NAME, parsedRevenueValue);
@@ -66,7 +66,8 @@ export function getEventValue(eventTags: EventTags, logger: LoggerFacade): numbe
6666
return null;
6767
}
6868

69-
const parsedEventValue = typeof rawValue === 'string' ? parseFloat(rawValue) : rawValue;
69+
const parsedEventValue =
70+
typeof rawValue === 'number' ? rawValue : typeof rawValue === 'string' ? parseFloat(rawValue) : NaN;
7071

7172
if (isFinite(parsedEventValue)) {
7273
logger.log(LOG_LEVEL.INFO, LOG_MESSAGES.PARSED_NUMERIC_VALUE, MODULE_NAME, parsedEventValue);
@@ -75,4 +76,4 @@ export function getEventValue(eventTags: EventTags, logger: LoggerFacade): numbe
7576
logger.log(LOG_LEVEL.INFO, LOG_MESSAGES.FAILED_TO_PARSE_VALUE, MODULE_NAME, rawValue);
7677
return null;
7778
}
78-
}
79+
}

0 commit comments

Comments
 (0)