Skip to content

Commit b2e28c4

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

File tree

4 files changed

+22
-30
lines changed

4 files changed

+22
-30
lines changed

lib/event_processor/event_builder/log_event.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,10 @@
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-
UserEvent,
21-
} from './user_event';
16+
import { ConversionEvent, ImpressionEvent, UserEvent } from './user_event';
2217

2318
import { LogEvent } from '../event_dispatcher/event_dispatcher';
19+
import { EventTags } from '../../shared_types';
2420

2521
const ACTIVATE_EVENT_KEY = 'campaign_activated'
2622
const CUSTOM_ATTRIBUTE_FEATURE_TYPE = 'custom'

lib/event_processor/event_builder/user_event.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
ProjectConfig,
2626
} from '../../project_config/project_config';
2727

28-
import { UserAttributes } from '../../shared_types';
28+
import { EventTags, UserAttributes } from '../../shared_types';
2929
import { LoggerFacade } from '../../logging/logger';
3030

3131
export type VisitorAttribute = {
@@ -79,10 +79,6 @@ export type ImpressionEvent = BaseUserEvent & {
7979
cmabUuid?: string;
8080
};
8181

82-
export type EventTags = {
83-
[key: string]: string | number | null;
84-
};
85-
8682
export type ConversionEvent = BaseUserEvent & {
8783
type: 'conversion';
8884

lib/shared_types.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,7 @@ export interface UserProfile {
8888
experiment_bucket_map: ExperimentBucketMap;
8989
}
9090

91-
export type EventTags = {
92-
[key: string]: string | number | null;
93-
};
91+
export type EventTags = Record<string, unknown>;
9492

9593
export interface UserProfileService {
9694
lookup(userId: string): UserProfile;

lib/utils/event_tag_utils/index.ts

+18-16
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@ import {
1919
PARSED_NUMERIC_VALUE,
2020
PARSED_REVENUE_VALUE,
2121
} from 'log_message';
22-
import { EventTags } from '../../event_processor/event_builder/user_event';
2322
import { LoggerFacade } from '../../logging/logger';
2423

25-
import {
26-
RESERVED_EVENT_KEYWORDS,
27-
} from '../enums';
24+
import { RESERVED_EVENT_KEYWORDS } from '../enums';
25+
import { EventTags } from '../../shared_types';
2826

2927
/**
3028
* Provides utility method for parsing event tag values
@@ -41,16 +39,18 @@ const VALUE_EVENT_METRIC_NAME = RESERVED_EVENT_KEYWORDS.VALUE;
4139
export function getRevenueValue(eventTags: EventTags, logger?: LoggerFacade): number | null {
4240
const rawValue = eventTags[REVENUE_EVENT_METRIC_NAME];
4341

44-
if (rawValue == null) { // null or undefined event values
42+
if (rawValue == null) {
43+
// null or undefined event values
4544
return null;
4645
}
4746

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

50-
if (isFinite(parsedRevenueValue)) {
51-
logger?.info(PARSED_REVENUE_VALUE, parsedRevenueValue);
52-
return parsedRevenueValue;
53-
} else { // NaN, +/- infinity values
49+
if (isFinite(amount)) {
50+
logger?.info(PARSED_REVENUE_VALUE, amount);
51+
return amount;
52+
} else {
53+
// NaN, +/- infinity values
5454
logger?.info(FAILED_TO_PARSE_REVENUE, rawValue);
5555
return null;
5656
}
@@ -65,16 +65,18 @@ export function getRevenueValue(eventTags: EventTags, logger?: LoggerFacade): nu
6565
export function getEventValue(eventTags: EventTags, logger?: LoggerFacade): number | null {
6666
const rawValue = eventTags[VALUE_EVENT_METRIC_NAME];
6767

68-
if (rawValue == null) { // null or undefined event values
68+
if (rawValue == null) {
69+
// null or undefined event values
6970
return null;
7071
}
7172

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

74-
if (isFinite(parsedEventValue)) {
75-
logger?.info(PARSED_NUMERIC_VALUE, parsedEventValue);
76-
return parsedEventValue;
77-
} else { // NaN, +/- infinity values
75+
if (isFinite(amount)) {
76+
logger?.info(PARSED_NUMERIC_VALUE, amount);
77+
return amount;
78+
} else {
79+
// NaN, +/- infinity values
7880
logger?.info(FAILED_TO_PARSE_VALUE, rawValue);
7981
return null;
8082
}

0 commit comments

Comments
 (0)