From 5e8b933a0ed4a499c94e9e526b603006f4dd2701 Mon Sep 17 00:00:00 2001 From: Md Junaed Hossain <169046794+junaed-optimizely@users.noreply.github.com> Date: Fri, 2 May 2025 22:01:52 +0600 Subject: [PATCH 1/4] [FSSDK-11197] EventTags type fix --- lib/core/event_builder/build_event_v1.ts | 8 ++------ lib/modules/event_processor/events.ts | 6 ++---- lib/modules/event_processor/v1/buildEventV1.ts | 3 ++- lib/shared_types.ts | 5 +---- lib/utils/event_tag_utils/index.ts | 11 ++++++----- 5 files changed, 13 insertions(+), 20 deletions(-) diff --git a/lib/core/event_builder/build_event_v1.ts b/lib/core/event_builder/build_event_v1.ts index b1f5b271d..a6506792b 100644 --- a/lib/core/event_builder/build_event_v1.ts +++ b/lib/core/event_builder/build_event_v1.ts @@ -13,13 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { - EventTags, - ConversionEvent, - ImpressionEvent, -} from '../../modules/event_processor'; +import { ConversionEvent, ImpressionEvent } from '../../modules/event_processor'; -import { Event } from '../../shared_types'; +import { Event, EventTags } from '../../shared_types'; type ProcessableEvent = ConversionEvent | ImpressionEvent diff --git a/lib/modules/event_processor/events.ts b/lib/modules/event_processor/events.ts index 65cce503b..61abab4e5 100644 --- a/lib/modules/event_processor/events.ts +++ b/lib/modules/event_processor/events.ts @@ -1,3 +1,5 @@ +import { EventTags } from "../../shared_types" + /** * Copyright 2022, Optimizely * @@ -82,10 +84,6 @@ export interface ConversionEvent extends BaseEvent { tags: EventTags | undefined } -export type EventTags = { - [key: string]: string | number | null -} - export function areEventContextsEqual(eventA: BaseEvent, eventB: BaseEvent): boolean { const contextA = eventA.context const contextB = eventB.context diff --git a/lib/modules/event_processor/v1/buildEventV1.ts b/lib/modules/event_processor/v1/buildEventV1.ts index 699498dc4..c0ab1aba7 100644 --- a/lib/modules/event_processor/v1/buildEventV1.ts +++ b/lib/modules/event_processor/v1/buildEventV1.ts @@ -13,9 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { EventTags, ConversionEvent, ImpressionEvent, VisitorAttribute } from '../events' +import { ConversionEvent, ImpressionEvent, VisitorAttribute } from '../events' import { ProcessableEvent } from '../eventProcessor' import { EventV1Request } from '../eventDispatcher' +import { EventTags } from '../../../shared_types' const ACTIVATE_EVENT_KEY = 'campaign_activated' const CUSTOM_ATTRIBUTE_FEATURE_TYPE = 'custom' diff --git a/lib/shared_types.ts b/lib/shared_types.ts index 495051866..c36ea7728 100644 --- a/lib/shared_types.ts +++ b/lib/shared_types.ts @@ -73,10 +73,7 @@ export interface UserProfile { experiment_bucket_map: ExperimentBucketMap; } -export type EventTags = { - [key: string]: string | number | null; -}; - +export type EventTags = Record; export interface UserProfileService { lookup(userId: string): UserProfile; save(profile: UserProfile): void; diff --git a/lib/utils/event_tag_utils/index.ts b/lib/utils/event_tag_utils/index.ts index 7917f3baa..5770ddb56 100644 --- a/lib/utils/event_tag_utils/index.ts +++ b/lib/utils/event_tag_utils/index.ts @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { EventTags } from '../../modules/event_processor'; +import { EventTags } from '../../shared_types'; import { LoggerFacade } from '../../modules/logging'; - import { LOG_LEVEL, LOG_MESSAGES, @@ -42,7 +41,8 @@ export function getRevenueValue(eventTags: EventTags, logger: LoggerFacade): num return null; } - const parsedRevenueValue = typeof rawValue === 'string' ? parseInt(rawValue) : rawValue; + const parsedRevenueValue = + typeof rawValue === 'number' ? rawValue : typeof rawValue === 'string' ? parseInt(rawValue) : NaN; if (isFinite(parsedRevenueValue)) { 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 return null; } - const parsedEventValue = typeof rawValue === 'string' ? parseFloat(rawValue) : rawValue; + const parsedEventValue = + typeof rawValue === 'number' ? rawValue : typeof rawValue === 'string' ? parseFloat(rawValue) : NaN; if (isFinite(parsedEventValue)) { 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 logger.log(LOG_LEVEL.INFO, LOG_MESSAGES.FAILED_TO_PARSE_VALUE, MODULE_NAME, rawValue); return null; } -} \ No newline at end of file +} From a98552c3cea37ddb784b4517e01694d32c9b1937 Mon Sep 17 00:00:00 2001 From: Md Junaed Hossain <169046794+junaed-optimizely@users.noreply.github.com> Date: Mon, 5 May 2025 22:43:34 +0600 Subject: [PATCH 2/4] [FSSDK-11197] EventTags type fix v5 --- lib/shared_types.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/shared_types.ts b/lib/shared_types.ts index c36ea7728..75885b83e 100644 --- a/lib/shared_types.ts +++ b/lib/shared_types.ts @@ -73,7 +73,13 @@ export interface UserProfile { experiment_bucket_map: ExperimentBucketMap; } -export type EventTags = Record; +export type EventTags = { + revenue?: string | number | null; + value?: string | number | null; + $opt_event_properties?: Record; + [key: string]: unknown; +}; + export interface UserProfileService { lookup(userId: string): UserProfile; save(profile: UserProfile): void; From 2c2344354ae5e923fac82084d59dd939159edef8 Mon Sep 17 00:00:00 2001 From: Md Junaed Hossain <169046794+junaed-optimizely@users.noreply.github.com> Date: Tue, 6 May 2025 17:30:10 +0600 Subject: [PATCH 3/4] [FSSDK-11197] condition improvement --- lib/utils/event_tag_utils/index.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/utils/event_tag_utils/index.ts b/lib/utils/event_tag_utils/index.ts index 5770ddb56..9740ed84a 100644 --- a/lib/utils/event_tag_utils/index.ts +++ b/lib/utils/event_tag_utils/index.ts @@ -41,8 +41,7 @@ export function getRevenueValue(eventTags: EventTags, logger: LoggerFacade): num return null; } - const parsedRevenueValue = - typeof rawValue === 'number' ? rawValue : typeof rawValue === 'string' ? parseInt(rawValue) : NaN; + const parsedRevenueValue = typeof rawValue === 'string' ? parseInt(rawValue) : rawValue; if (isFinite(parsedRevenueValue)) { logger.log(LOG_LEVEL.INFO, LOG_MESSAGES.PARSED_REVENUE_VALUE, MODULE_NAME, parsedRevenueValue); @@ -66,8 +65,7 @@ export function getEventValue(eventTags: EventTags, logger: LoggerFacade): numbe return null; } - const parsedEventValue = - typeof rawValue === 'number' ? rawValue : typeof rawValue === 'string' ? parseFloat(rawValue) : NaN; + const parsedEventValue = typeof rawValue === 'string' ? parseFloat(rawValue): rawValue; if (isFinite(parsedEventValue)) { logger.log(LOG_LEVEL.INFO, LOG_MESSAGES.PARSED_NUMERIC_VALUE, MODULE_NAME, parsedEventValue); From 55d90ab63d7dc430ebc69ee6e0e74fc2ccdf5ac5 Mon Sep 17 00:00:00 2001 From: Md Junaed Hossain <169046794+junaed-optimizely@users.noreply.github.com> Date: Tue, 6 May 2025 17:56:55 +0600 Subject: [PATCH 4/4] [FSSDK-11197] condition improvement --- lib/utils/event_tag_utils/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/utils/event_tag_utils/index.ts b/lib/utils/event_tag_utils/index.ts index 9740ed84a..e3550a73d 100644 --- a/lib/utils/event_tag_utils/index.ts +++ b/lib/utils/event_tag_utils/index.ts @@ -41,7 +41,7 @@ export function getRevenueValue(eventTags: EventTags, logger: LoggerFacade): num return null; } - const parsedRevenueValue = typeof rawValue === 'string' ? parseInt(rawValue) : rawValue; + const parsedRevenueValue = typeof rawValue === 'string' ? parseInt(rawValue) : Math.trunc(rawValue); if (isFinite(parsedRevenueValue)) { logger.log(LOG_LEVEL.INFO, LOG_MESSAGES.PARSED_REVENUE_VALUE, MODULE_NAME, parsedRevenueValue);