From 7188cd96bbcff160782ca1b61fab90729ddf0e64 Mon Sep 17 00:00:00 2001 From: Raju Ahmed Date: Fri, 22 Nov 2024 23:31:00 +0600 Subject: [PATCH 1/4] init cleanup --- .../batch_event_processor.react_native.spec.ts | 8 ++++---- lib/event_processor/batch_event_processor.spec.ts | 4 ++-- lib/event_processor/batch_event_processor.ts | 4 ++-- lib/event_processor/default_dispatcher.browser.ts | 2 +- lib/event_processor/default_dispatcher.node.ts | 2 +- lib/event_processor/default_dispatcher.spec.ts | 2 +- lib/event_processor/default_dispatcher.ts | 2 +- .../{eventDispatcher.ts => event_dispatcher.ts} | 0 .../{eventProcessor.ts => event_processor.ts} | 2 +- .../event_processor_factory.browser.ts | 4 ++-- .../event_processor_factory.node.ts | 4 ++-- .../event_processor_factory.react_native.ts | 4 ++-- lib/event_processor/event_processor_factory.ts | 4 ++-- .../forwarding_event_processor.spec.ts | 2 +- lib/event_processor/forwarding_event_processor.ts | 4 ++-- lib/event_processor/v1/buildEventV1.ts | 4 ++-- lib/optimizely/index.ts | 2 +- .../event_dispatcher/send_beacon_dispatcher.ts | 2 +- lib/shared_types.ts | 8 ++++---- tsconfig.spec.json | 14 +++++++++++++- 20 files changed, 45 insertions(+), 33 deletions(-) rename lib/event_processor/{eventDispatcher.ts => event_dispatcher.ts} (100%) rename lib/event_processor/{eventProcessor.ts => event_processor.ts} (95%) diff --git a/lib/event_processor/batch_event_processor.react_native.spec.ts b/lib/event_processor/batch_event_processor.react_native.spec.ts index 68ccd6016..2765853da 100644 --- a/lib/event_processor/batch_event_processor.react_native.spec.ts +++ b/lib/event_processor/batch_event_processor.react_native.spec.ts @@ -18,8 +18,8 @@ import { vi, describe, it, expect, beforeEach } from 'vitest'; const mockNetInfo = vi.hoisted(() => { const netInfo = { - listeners: [], - unsubs: [], + listeners: [] as any[], + unsubs: [] as any[], addEventListener(fn: any) { this.listeners.push(fn); const unsub = vi.fn(); @@ -51,10 +51,10 @@ import { getMockRepeater } from '../tests/mock/mock_repeater'; import { getMockAsyncCache } from '../tests/mock/mock_cache'; import { EventWithId } from './batch_event_processor'; -import { EventDispatcher } from './eventDispatcher'; +import { EventDispatcher } from './event_dispatcher'; import { formatEvents } from './v1/buildEventV1'; import { createImpressionEvent } from '../tests/mock/create_event'; -import { ProcessableEvent } from './eventProcessor'; +import { ProcessableEvent } from './event_processor'; const getMockDispatcher = () => { return { diff --git a/lib/event_processor/batch_event_processor.spec.ts b/lib/event_processor/batch_event_processor.spec.ts index 715b4452b..6db9cd3e5 100644 --- a/lib/event_processor/batch_event_processor.spec.ts +++ b/lib/event_processor/batch_event_processor.spec.ts @@ -18,8 +18,8 @@ import { expect, describe, it, vi, beforeEach, afterEach, MockInstance } from 'v import { EventWithId, BatchEventProcessor } from './batch_event_processor'; import { getMockSyncCache } from '../tests/mock/mock_cache'; import { createImpressionEvent } from '../tests/mock/create_event'; -import { ProcessableEvent } from './eventProcessor'; -import { EventDispatcher } from './eventDispatcher'; +import { ProcessableEvent } from './event_processor'; +import { EventDispatcher } from './event_dispatcher'; import { formatEvents } from './v1/buildEventV1'; import { ResolvablePromise, resolvablePromise } from '../utils/promise/resolvablePromise'; import { advanceTimersByTime } from '../../tests/testUtils'; diff --git a/lib/event_processor/batch_event_processor.ts b/lib/event_processor/batch_event_processor.ts index 7cad445cd..a96f2cf8d 100644 --- a/lib/event_processor/batch_event_processor.ts +++ b/lib/event_processor/batch_event_processor.ts @@ -14,9 +14,9 @@ * limitations under the License. */ -import { EventProcessor, ProcessableEvent } from "./eventProcessor"; +import { EventProcessor, ProcessableEvent } from "./event_processor"; import { Cache } from "../utils/cache/cache"; -import { EventDispatcher, EventDispatcherResponse, EventV1Request } from "./eventDispatcher"; +import { EventDispatcher, EventDispatcherResponse, EventV1Request } from "./event_dispatcher"; import { formatEvents } from "../core/event_builder/build_event_v1"; import { BackoffController, ExponentialBackoff, IntervalRepeater, Repeater } from "../utils/repeater/repeater"; import { LoggerFacade } from "../modules/logging"; diff --git a/lib/event_processor/default_dispatcher.browser.ts b/lib/event_processor/default_dispatcher.browser.ts index d4601700c..1dd72ab00 100644 --- a/lib/event_processor/default_dispatcher.browser.ts +++ b/lib/event_processor/default_dispatcher.browser.ts @@ -15,7 +15,7 @@ */ import { BrowserRequestHandler } from "../utils/http_request_handler/browser_request_handler"; -import { EventDispatcher } from '../event_processor/eventDispatcher'; +import { EventDispatcher } from './event_dispatcher'; import { DefaultEventDispatcher } from './default_dispatcher'; const eventDispatcher: EventDispatcher = new DefaultEventDispatcher(new BrowserRequestHandler()); diff --git a/lib/event_processor/default_dispatcher.node.ts b/lib/event_processor/default_dispatcher.node.ts index 75e00aff3..130eaa6d2 100644 --- a/lib/event_processor/default_dispatcher.node.ts +++ b/lib/event_processor/default_dispatcher.node.ts @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { EventDispatcher } from '../event_processor/eventDispatcher'; +import { EventDispatcher } from './event_dispatcher'; import { NodeRequestHandler } from '../utils/http_request_handler/node_request_handler'; import { DefaultEventDispatcher } from './default_dispatcher'; diff --git a/lib/event_processor/default_dispatcher.spec.ts b/lib/event_processor/default_dispatcher.spec.ts index 0616ba3bf..bccaf0a22 100644 --- a/lib/event_processor/default_dispatcher.spec.ts +++ b/lib/event_processor/default_dispatcher.spec.ts @@ -15,7 +15,7 @@ */ import { expect, vi, describe, it } from 'vitest'; import { DefaultEventDispatcher } from './default_dispatcher'; -import { EventV1 } from '../event_processor'; +import { EventV1 } from './v1/buildEventV1'; const getEvent = (): EventV1 => { return { diff --git a/lib/event_processor/default_dispatcher.ts b/lib/event_processor/default_dispatcher.ts index ce8dd5b59..3105b49e1 100644 --- a/lib/event_processor/default_dispatcher.ts +++ b/lib/event_processor/default_dispatcher.ts @@ -14,7 +14,7 @@ * limitations under the License. */ import { RequestHandler } from '../utils/http_request_handler/http'; -import { EventDispatcher, EventDispatcherResponse, EventV1Request } from '../event_processor/eventDispatcher'; +import { EventDispatcher, EventDispatcherResponse, EventV1Request } from './event_dispatcher'; export class DefaultEventDispatcher implements EventDispatcher { private requestHandler: RequestHandler; diff --git a/lib/event_processor/eventDispatcher.ts b/lib/event_processor/event_dispatcher.ts similarity index 100% rename from lib/event_processor/eventDispatcher.ts rename to lib/event_processor/event_dispatcher.ts diff --git a/lib/event_processor/eventProcessor.ts b/lib/event_processor/event_processor.ts similarity index 95% rename from lib/event_processor/eventProcessor.ts rename to lib/event_processor/event_processor.ts index 656beab90..1aee1a857 100644 --- a/lib/event_processor/eventProcessor.ts +++ b/lib/event_processor/event_processor.ts @@ -14,7 +14,7 @@ * limitations under the License. */ import { ConversionEvent, ImpressionEvent } from './events' -import { EventV1Request } from './eventDispatcher' +import { EventV1Request } from './event_dispatcher' import { getLogger } from '../modules/logging' import { Service } from '../service' import { Consumer, Fn } from '../utils/type'; diff --git a/lib/event_processor/event_processor_factory.browser.ts b/lib/event_processor/event_processor_factory.browser.ts index 476186030..ee6d4516b 100644 --- a/lib/event_processor/event_processor_factory.browser.ts +++ b/lib/event_processor/event_processor_factory.browser.ts @@ -15,8 +15,8 @@ */ import { getForwardingEventProcessor } from './forwarding_event_processor'; -import { EventDispatcher } from './eventDispatcher'; -import { EventProcessor } from './eventProcessor'; +import { EventDispatcher } from './event_dispatcher'; +import { EventProcessor } from './event_processor'; import { EventWithId } from './batch_event_processor'; import { getBatchEventProcessor, BatchEventProcessorOptions } from './event_processor_factory'; import defaultEventDispatcher from './default_dispatcher.browser'; diff --git a/lib/event_processor/event_processor_factory.node.ts b/lib/event_processor/event_processor_factory.node.ts index 7bfd43c6a..1a21fbf60 100644 --- a/lib/event_processor/event_processor_factory.node.ts +++ b/lib/event_processor/event_processor_factory.node.ts @@ -14,8 +14,8 @@ * limitations under the License. */ import { getForwardingEventProcessor } from './forwarding_event_processor'; -import { EventDispatcher } from './eventDispatcher'; -import { EventProcessor } from './eventProcessor'; +import { EventDispatcher } from './event_dispatcher'; +import { EventProcessor } from './event_processor'; import defaultEventDispatcher from './default_dispatcher.node'; import { BatchEventProcessorOptions, FAILED_EVENT_RETRY_INTERVAL, getBatchEventProcessor, getPrefixEventStore } from './event_processor_factory'; diff --git a/lib/event_processor/event_processor_factory.react_native.ts b/lib/event_processor/event_processor_factory.react_native.ts index 84c11e375..a007501a5 100644 --- a/lib/event_processor/event_processor_factory.react_native.ts +++ b/lib/event_processor/event_processor_factory.react_native.ts @@ -14,8 +14,8 @@ * limitations under the License. */ import { getForwardingEventProcessor } from './forwarding_event_processor'; -import { EventDispatcher } from './eventDispatcher'; -import { EventProcessor } from './eventProcessor'; +import { EventDispatcher } from './event_dispatcher'; +import { EventProcessor } from './event_processor'; import defaultEventDispatcher from './default_dispatcher.browser'; import { BatchEventProcessorOptions, getBatchEventProcessor, getPrefixEventStore } from './event_processor_factory'; import { EVENT_STORE_PREFIX, FAILED_EVENT_RETRY_INTERVAL } from './event_processor_factory'; diff --git a/lib/event_processor/event_processor_factory.ts b/lib/event_processor/event_processor_factory.ts index 3e2cc0d7c..adba35c1d 100644 --- a/lib/event_processor/event_processor_factory.ts +++ b/lib/event_processor/event_processor_factory.ts @@ -17,8 +17,8 @@ import { LogLevel } from "../common_exports"; import { StartupLog } from "../service"; import { ExponentialBackoff, IntervalRepeater } from "../utils/repeater/repeater"; -import { EventDispatcher } from "./eventDispatcher"; -import { EventProcessor } from "./eventProcessor"; +import { EventDispatcher } from "./event_dispatcher"; +import { EventProcessor } from "./event_processor"; import { BatchEventProcessor, EventWithId, RetryConfig } from "./batch_event_processor"; import { AsyncPrefixCache, Cache, SyncPrefixCache } from "../utils/cache/cache"; diff --git a/lib/event_processor/forwarding_event_processor.spec.ts b/lib/event_processor/forwarding_event_processor.spec.ts index 41393109a..fa0192568 100644 --- a/lib/event_processor/forwarding_event_processor.spec.ts +++ b/lib/event_processor/forwarding_event_processor.spec.ts @@ -16,7 +16,7 @@ import { expect, describe, it, vi } from 'vitest'; import { getForwardingEventProcessor } from './forwarding_event_processor'; -import { EventDispatcher } from './eventDispatcher'; +import { EventDispatcher } from './event_dispatcher'; import { formatEvents, makeBatchedEventV1 } from './v1/buildEventV1'; import { createImpressionEvent } from '../tests/mock/create_event'; import { ServiceState } from '../service'; diff --git a/lib/event_processor/forwarding_event_processor.ts b/lib/event_processor/forwarding_event_processor.ts index 1fc06ebc9..0ebe22ad0 100644 --- a/lib/event_processor/forwarding_event_processor.ts +++ b/lib/event_processor/forwarding_event_processor.ts @@ -15,8 +15,8 @@ */ -import { EventV1Request } from './eventDispatcher'; -import { EventProcessor, ProcessableEvent } from './eventProcessor'; +import { EventV1Request } from './event_dispatcher'; +import { EventProcessor, ProcessableEvent } from './event_processor'; import { EventDispatcher } from '../shared_types'; import { formatEvents } from '../core/event_builder/build_event_v1'; diff --git a/lib/event_processor/v1/buildEventV1.ts b/lib/event_processor/v1/buildEventV1.ts index 1232d52ec..51fd49ada 100644 --- a/lib/event_processor/v1/buildEventV1.ts +++ b/lib/event_processor/v1/buildEventV1.ts @@ -14,8 +14,8 @@ * limitations under the License. */ import { EventTags, ConversionEvent, ImpressionEvent, VisitorAttribute } from '../events' -import { ProcessableEvent } from '../eventProcessor' -import { EventV1Request } from '../eventDispatcher' +import { ProcessableEvent } from '../event_processor' +import { EventV1Request } from '../event_dispatcher' const ACTIVATE_EVENT_KEY = 'campaign_activated' const CUSTOM_ATTRIBUTE_FEATURE_TYPE = 'custom' diff --git a/lib/optimizely/index.ts b/lib/optimizely/index.ts index a15a7711f..7112c902c 100644 --- a/lib/optimizely/index.ts +++ b/lib/optimizely/index.ts @@ -17,7 +17,7 @@ import { LoggerFacade, ErrorHandler } from '../modules/logging'; import { sprintf, objectValues } from '../utils/fns'; import { NotificationCenter } from '../core/notification_center'; -import { EventProcessor } from '../event_processor/eventProcessor'; +import { EventProcessor } from '../event_processor/event_processor'; import { IOdpManager } from '../core/odp/odp_manager'; import { OdpEvent } from '../core/odp/odp_event'; diff --git a/lib/plugins/event_dispatcher/send_beacon_dispatcher.ts b/lib/plugins/event_dispatcher/send_beacon_dispatcher.ts index 1e8c04577..7a70b279e 100644 --- a/lib/plugins/event_dispatcher/send_beacon_dispatcher.ts +++ b/lib/plugins/event_dispatcher/send_beacon_dispatcher.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { EventDispatcher, EventDispatcherResponse } from '../../event_processor/eventDispatcher'; +import { EventDispatcher, EventDispatcherResponse } from '../../event_processor/event_dispatcher'; export type Event = { url: string; diff --git a/lib/shared_types.ts b/lib/shared_types.ts index b5249266f..1b26d51ad 100644 --- a/lib/shared_types.ts +++ b/lib/shared_types.ts @@ -38,11 +38,11 @@ import { IUserAgentParser } from './core/odp/user_agent_parser'; import PersistentCache from './plugins/key_value_cache/persistentKeyValueCache'; import { ProjectConfig } from './project_config/project_config'; import { ProjectConfigManager } from './project_config/project_config_manager'; -import { EventDispatcher } from './event_processor/eventDispatcher'; -import { EventProcessor } from './event_processor/eventProcessor'; +import { EventDispatcher } from './event_processor/event_dispatcher'; +import { EventProcessor } from './event_processor/event_processor'; -export { EventDispatcher } from './event_processor/eventDispatcher'; -export { EventProcessor } from './event_processor/eventProcessor'; +export { EventDispatcher } from './event_processor/event_dispatcher'; +export { EventProcessor } from './event_processor/event_processor'; export interface BucketerParams { experimentId: string; experimentKey: string; diff --git a/tsconfig.spec.json b/tsconfig.spec.json index d27f5db0d..f61c713df 100644 --- a/tsconfig.spec.json +++ b/tsconfig.spec.json @@ -6,9 +6,21 @@ ], "typeRoots": [ "./node_modules/@types" - ] + ], + "target": "ESNext" }, + "exclude": [ + "./dist", + "./lib/**/*.tests.js", + "./lib/**/*.tests.ts", + "./lib/**/*.umdtests.js", + "node_modules" + ], "include": [ + "./lib/**/*.ts", + "./lib/**/*.js", + "./lib/modules/**/*.ts", + "./lib/modules/**/**/*.ts", "tests/**/*.ts", "**/*.spec.ts" ] From bc45abd549710ffdeb5b462bfc1b4b581eb79316 Mon Sep 17 00:00:00 2001 From: Raju Ahmed Date: Sat, 23 Nov 2024 02:10:55 +0600 Subject: [PATCH 2/4] [FSSDK-10941] event processor files and directories cleanup --- ...batch_event_processor.react_native.spec.ts | 4 +- .../batch_event_processor.spec.ts | 5 +- lib/event_processor/batch_event_processor.ts | 2 +- .../default_dispatcher.spec.ts | 2 +- .../event_builder/build_event_v1.spec.ts | 812 ++++++++++++++++++ .../event_builder/build_event_v1.ts | 2 +- .../event_builder/event_helpers.tests.js | 2 +- .../event_builder/event_helpers.ts | 4 +- .../event_builder/index.tests.js | 0 .../event_builder/index.ts | 2 +- lib/event_processor/event_dispatcher.ts | 2 +- .../forwarding_event_processor.spec.ts | 2 +- .../forwarding_event_processor.ts | 2 +- lib/event_processor/v1/buildEventV1.ts | 272 ------ lib/optimizely/index.ts | 4 +- tests/buildEventV1.spec.ts | 812 ------------------ 16 files changed, 827 insertions(+), 1102 deletions(-) create mode 100644 lib/event_processor/event_builder/build_event_v1.spec.ts rename lib/{core => event_processor}/event_builder/build_event_v1.ts (99%) rename lib/{core => event_processor}/event_builder/event_helpers.tests.js (99%) rename lib/{core => event_processor}/event_builder/event_helpers.ts (98%) rename lib/{core => event_processor}/event_builder/index.tests.js (100%) rename lib/{core => event_processor}/event_builder/index.ts (99%) delete mode 100644 lib/event_processor/v1/buildEventV1.ts delete mode 100644 tests/buildEventV1.spec.ts diff --git a/lib/event_processor/batch_event_processor.react_native.spec.ts b/lib/event_processor/batch_event_processor.react_native.spec.ts index 2765853da..ea1612f4c 100644 --- a/lib/event_processor/batch_event_processor.react_native.spec.ts +++ b/lib/event_processor/batch_event_processor.react_native.spec.ts @@ -46,13 +46,11 @@ vi.mock('../utils/import.react_native/@react-native-community/netinfo', () => { }); import { ReactNativeNetInfoEventProcessor } from './batch_event_processor.react_native'; -import { getMockLogger } from '../tests/mock/mock_logger'; import { getMockRepeater } from '../tests/mock/mock_repeater'; import { getMockAsyncCache } from '../tests/mock/mock_cache'; import { EventWithId } from './batch_event_processor'; -import { EventDispatcher } from './event_dispatcher'; -import { formatEvents } from './v1/buildEventV1'; +import { formatEvents } from './event_builder/build_event_v1'; import { createImpressionEvent } from '../tests/mock/create_event'; import { ProcessableEvent } from './event_processor'; diff --git a/lib/event_processor/batch_event_processor.spec.ts b/lib/event_processor/batch_event_processor.spec.ts index 6db9cd3e5..2c81f9215 100644 --- a/lib/event_processor/batch_event_processor.spec.ts +++ b/lib/event_processor/batch_event_processor.spec.ts @@ -19,9 +19,8 @@ import { EventWithId, BatchEventProcessor } from './batch_event_processor'; import { getMockSyncCache } from '../tests/mock/mock_cache'; import { createImpressionEvent } from '../tests/mock/create_event'; import { ProcessableEvent } from './event_processor'; -import { EventDispatcher } from './event_dispatcher'; -import { formatEvents } from './v1/buildEventV1'; -import { ResolvablePromise, resolvablePromise } from '../utils/promise/resolvablePromise'; +import { formatEvents } from './event_builder/build_event_v1'; +import { resolvablePromise } from '../utils/promise/resolvablePromise'; import { advanceTimersByTime } from '../../tests/testUtils'; import { getMockLogger } from '../tests/mock/mock_logger'; import { getMockRepeater } from '../tests/mock/mock_repeater'; diff --git a/lib/event_processor/batch_event_processor.ts b/lib/event_processor/batch_event_processor.ts index a96f2cf8d..3d000a5df 100644 --- a/lib/event_processor/batch_event_processor.ts +++ b/lib/event_processor/batch_event_processor.ts @@ -17,7 +17,7 @@ import { EventProcessor, ProcessableEvent } from "./event_processor"; import { Cache } from "../utils/cache/cache"; import { EventDispatcher, EventDispatcherResponse, EventV1Request } from "./event_dispatcher"; -import { formatEvents } from "../core/event_builder/build_event_v1"; +import { formatEvents } from "./event_builder/build_event_v1"; import { BackoffController, ExponentialBackoff, IntervalRepeater, Repeater } from "../utils/repeater/repeater"; import { LoggerFacade } from "../modules/logging"; import { BaseService, ServiceState, StartupLog } from "../service"; diff --git a/lib/event_processor/default_dispatcher.spec.ts b/lib/event_processor/default_dispatcher.spec.ts index bccaf0a22..f7cdc718f 100644 --- a/lib/event_processor/default_dispatcher.spec.ts +++ b/lib/event_processor/default_dispatcher.spec.ts @@ -15,7 +15,7 @@ */ import { expect, vi, describe, it } from 'vitest'; import { DefaultEventDispatcher } from './default_dispatcher'; -import { EventV1 } from './v1/buildEventV1'; +import { EventV1 } from './event_builder/build_event_v1'; const getEvent = (): EventV1 => { return { diff --git a/lib/event_processor/event_builder/build_event_v1.spec.ts b/lib/event_processor/event_builder/build_event_v1.spec.ts new file mode 100644 index 000000000..b1082dc7e --- /dev/null +++ b/lib/event_processor/event_builder/build_event_v1.spec.ts @@ -0,0 +1,812 @@ +/** + * Copyright 2022, 2024, Optimizely + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { describe, it, expect } from 'vitest'; + +import { + buildConversionEventV1, + buildImpressionEventV1, + makeBatchedEventV1, +} from './build_event_v1'; + +import { ImpressionEvent, ConversionEvent } from '../events' + +describe('buildImpressionEventV1', () => { + it('should build an ImpressionEventV1 when experiment and variation are defined', () => { + const impressionEvent: ImpressionEvent = { + type: 'impression', + timestamp: 69, + uuid: 'uuid', + + context: { + accountId: 'accountId', + projectId: 'projectId', + clientName: 'node-sdk', + clientVersion: '3.0.0', + revision: 'revision', + botFiltering: true, + anonymizeIP: true, + }, + + user: { + id: 'userId', + attributes: [{ entityId: 'attr1-id', key: 'attr1-key', value: 'attr1-value' }], + }, + + layer: { + id: 'layerId', + }, + + experiment: { + id: 'expId', + key: 'expKey', + }, + + variation: { + id: 'varId', + key: 'varKey', + }, + + ruleKey: 'expKey', + flagKey: 'flagKey1', + ruleType: 'experiment', + enabled: true, + } + + const result = buildImpressionEventV1(impressionEvent) + expect(result).toEqual({ + client_name: 'node-sdk', + client_version: '3.0.0', + account_id: 'accountId', + project_id: 'projectId', + revision: 'revision', + anonymize_ip: true, + enrich_decisions: true, + + visitors: [ + { + snapshots: [ + { + decisions: [ + { + campaign_id: 'layerId', + experiment_id: 'expId', + variation_id: 'varId', + metadata: { + flag_key: 'flagKey1', + rule_key: 'expKey', + rule_type: 'experiment', + variation_key: 'varKey', + enabled: true, + }, + }, + ], + events: [ + { + entity_id: 'layerId', + timestamp: 69, + key: 'campaign_activated', + uuid: 'uuid', + }, + ], + }, + ], + visitor_id: 'userId', + attributes: [ + { + entity_id: 'attr1-id', + key: 'attr1-key', + type: 'custom', + value: 'attr1-value', + }, + { + entity_id: '$opt_bot_filtering', + key: '$opt_bot_filtering', + type: 'custom', + value: true, + }, + ], + }, + ], + }) + }) + + it('should build an ImpressionEventV1 when experiment and variation are not defined', () => { + const impressionEvent: ImpressionEvent = { + type: 'impression', + timestamp: 69, + uuid: 'uuid', + + context: { + accountId: 'accountId', + projectId: 'projectId', + clientName: 'node-sdk', + clientVersion: '3.0.0', + revision: 'revision', + botFiltering: true, + anonymizeIP: true, + }, + + user: { + id: 'userId', + attributes: [{ entityId: 'attr1-id', key: 'attr1-key', value: 'attr1-value' }], + }, + + layer: { + id: null, + }, + + experiment: { + id: null, + key: '', + }, + + variation: { + id: null, + key: '', + }, + + ruleKey: '', + flagKey: 'flagKey1', + ruleType: 'rollout', + enabled: true, + } + + const result = buildImpressionEventV1(impressionEvent) + expect(result).toEqual({ + client_name: 'node-sdk', + client_version: '3.0.0', + account_id: 'accountId', + project_id: 'projectId', + revision: 'revision', + anonymize_ip: true, + enrich_decisions: true, + + visitors: [ + { + snapshots: [ + { + decisions: [ + { + campaign_id: null, + experiment_id: "", + variation_id: "", + metadata: { + flag_key: 'flagKey1', + rule_key: '', + rule_type: 'rollout', + variation_key: '', + enabled: true, + }, + }, + ], + events: [ + { + entity_id: null, + timestamp: 69, + key: 'campaign_activated', + uuid: 'uuid', + }, + ], + }, + ], + visitor_id: 'userId', + attributes: [ + { + entity_id: 'attr1-id', + key: 'attr1-key', + type: 'custom', + value: 'attr1-value', + }, + { + entity_id: '$opt_bot_filtering', + key: '$opt_bot_filtering', + type: 'custom', + value: true, + }, + ], + }, + ], + }) + }) +}) + +describe('buildConversionEventV1', () => { + it('should build a ConversionEventV1 when tags object is defined', () => { + const conversionEvent: ConversionEvent = { + type: 'conversion', + timestamp: 69, + uuid: 'uuid', + + context: { + accountId: 'accountId', + projectId: 'projectId', + clientName: 'node-sdk', + clientVersion: '3.0.0', + revision: 'revision', + botFiltering: true, + anonymizeIP: true, + }, + + user: { + id: 'userId', + attributes: [{ entityId: 'attr1-id', key: 'attr1-key', value: 'attr1-value' }], + }, + + event: { + id: 'event-id', + key: 'event-key', + }, + + tags: { + foo: 'bar', + value: '123', + revenue: '1000', + }, + + revenue: 1000, + value: 123, + } + + const result = buildConversionEventV1(conversionEvent) + expect(result).toEqual({ + client_name: 'node-sdk', + client_version: '3.0.0', + account_id: 'accountId', + project_id: 'projectId', + revision: 'revision', + anonymize_ip: true, + enrich_decisions: true, + + visitors: [ + { + snapshots: [ + { + events: [ + { + entity_id: 'event-id', + timestamp: 69, + key: 'event-key', + uuid: 'uuid', + tags: { + foo: 'bar', + value: '123', + revenue: '1000', + }, + revenue: 1000, + value: 123, + }, + ], + }, + ], + visitor_id: 'userId', + attributes: [ + { + entity_id: 'attr1-id', + key: 'attr1-key', + type: 'custom', + value: 'attr1-value', + }, + { + entity_id: '$opt_bot_filtering', + key: '$opt_bot_filtering', + type: 'custom', + value: true, + }, + ], + }, + ], + }) + }) + + it('should build a ConversionEventV1 when tags object is undefined', () => { + const conversionEvent: ConversionEvent = { + type: 'conversion', + timestamp: 69, + uuid: 'uuid', + + context: { + accountId: 'accountId', + projectId: 'projectId', + clientName: 'node-sdk', + clientVersion: '3.0.0', + revision: 'revision', + botFiltering: true, + anonymizeIP: true, + }, + + user: { + id: 'userId', + attributes: [{ entityId: 'attr1-id', key: 'attr1-key', value: 'attr1-value' }], + }, + + event: { + id: 'event-id', + key: 'event-key', + }, + + tags: undefined, + + revenue: 1000, + value: 123, + } + + const result = buildConversionEventV1(conversionEvent) + expect(result).toEqual({ + client_name: 'node-sdk', + client_version: '3.0.0', + account_id: 'accountId', + project_id: 'projectId', + revision: 'revision', + anonymize_ip: true, + enrich_decisions: true, + + visitors: [ + { + snapshots: [ + { + events: [ + { + entity_id: 'event-id', + timestamp: 69, + key: 'event-key', + uuid: 'uuid', + tags: undefined, + revenue: 1000, + value: 123, + }, + ], + }, + ], + visitor_id: 'userId', + attributes: [ + { + entity_id: 'attr1-id', + key: 'attr1-key', + type: 'custom', + value: 'attr1-value', + }, + { + entity_id: '$opt_bot_filtering', + key: '$opt_bot_filtering', + type: 'custom', + value: true, + }, + ], + }, + ], + }) + }) + + it('should build a ConversionEventV1 when event id is null', () => { + const conversionEvent: ConversionEvent = { + type: 'conversion', + timestamp: 69, + uuid: 'uuid', + + context: { + accountId: 'accountId', + projectId: 'projectId', + clientName: 'node-sdk', + clientVersion: '3.0.0', + revision: 'revision', + botFiltering: true, + anonymizeIP: true, + }, + + user: { + id: 'userId', + attributes: [{ entityId: 'attr1-id', key: 'attr1-key', value: 'attr1-value' }], + }, + + event: { + id: null, + key: 'event-key', + }, + + tags: undefined, + + revenue: 1000, + value: 123, + } + + const result = buildConversionEventV1(conversionEvent) + expect(result).toEqual({ + client_name: 'node-sdk', + client_version: '3.0.0', + account_id: 'accountId', + project_id: 'projectId', + revision: 'revision', + anonymize_ip: true, + enrich_decisions: true, + + visitors: [ + { + snapshots: [ + { + events: [ + { + entity_id: null, + timestamp: 69, + key: 'event-key', + uuid: 'uuid', + tags: undefined, + revenue: 1000, + value: 123, + }, + ], + }, + ], + visitor_id: 'userId', + attributes: [ + { + entity_id: 'attr1-id', + key: 'attr1-key', + type: 'custom', + value: 'attr1-value', + }, + { + entity_id: '$opt_bot_filtering', + key: '$opt_bot_filtering', + type: 'custom', + value: true, + }, + ], + }, + ], + }) + }) + + it('should include revenue and value if they are 0', () => { + const conversionEvent: ConversionEvent = { + type: 'conversion', + timestamp: 69, + uuid: 'uuid', + + context: { + accountId: 'accountId', + projectId: 'projectId', + clientName: 'node-sdk', + clientVersion: '3.0.0', + revision: 'revision', + botFiltering: true, + anonymizeIP: true, + }, + + user: { + id: 'userId', + attributes: [{ entityId: 'attr1-id', key: 'attr1-key', value: 'attr1-value' }], + }, + + event: { + id: 'event-id', + key: 'event-key', + }, + + tags: { + foo: 'bar', + value: 0, + revenue: 0, + }, + + revenue: 0, + value: 0, + } + + const result = buildConversionEventV1(conversionEvent) + expect(result).toEqual({ + client_name: 'node-sdk', + client_version: '3.0.0', + account_id: 'accountId', + project_id: 'projectId', + revision: 'revision', + anonymize_ip: true, + enrich_decisions: true, + + visitors: [ + { + snapshots: [ + { + events: [ + { + entity_id: 'event-id', + timestamp: 69, + key: 'event-key', + uuid: 'uuid', + tags: { + foo: 'bar', + value: 0, + revenue: 0, + }, + revenue: 0, + value: 0, + }, + ], + }, + ], + visitor_id: 'userId', + attributes: [ + { + entity_id: 'attr1-id', + key: 'attr1-key', + type: 'custom', + value: 'attr1-value', + }, + { + entity_id: '$opt_bot_filtering', + key: '$opt_bot_filtering', + type: 'custom', + value: true, + }, + ], + }, + ], + }) + }) + + it('should not include $opt_bot_filtering attribute if context.botFiltering is undefined', () => { + const conversionEvent: ConversionEvent = { + type: 'conversion', + timestamp: 69, + uuid: 'uuid', + + context: { + accountId: 'accountId', + projectId: 'projectId', + clientName: 'node-sdk', + clientVersion: '3.0.0', + revision: 'revision', + anonymizeIP: true, + }, + + user: { + id: 'userId', + attributes: [{ entityId: 'attr1-id', key: 'attr1-key', value: 'attr1-value' }], + }, + + event: { + id: 'event-id', + key: 'event-key', + }, + + tags: { + foo: 'bar', + value: '123', + revenue: '1000', + }, + + revenue: 1000, + value: 123, + } + + const result = buildConversionEventV1(conversionEvent) + expect(result).toEqual({ + client_name: 'node-sdk', + client_version: '3.0.0', + account_id: 'accountId', + project_id: 'projectId', + revision: 'revision', + anonymize_ip: true, + enrich_decisions: true, + + visitors: [ + { + snapshots: [ + { + events: [ + { + entity_id: 'event-id', + timestamp: 69, + key: 'event-key', + uuid: 'uuid', + tags: { + foo: 'bar', + value: '123', + revenue: '1000', + }, + revenue: 1000, + value: 123, + }, + ], + }, + ], + visitor_id: 'userId', + attributes: [ + { + entity_id: 'attr1-id', + key: 'attr1-key', + type: 'custom', + value: 'attr1-value', + }, + ], + }, + ], + }) + }) +}) + +describe('makeBatchedEventV1', () => { + it('should batch Conversion and Impression events together', () => { + const conversionEvent: ConversionEvent = { + type: 'conversion', + timestamp: 69, + uuid: 'uuid', + + context: { + accountId: 'accountId', + projectId: 'projectId', + clientName: 'node-sdk', + clientVersion: '3.0.0', + revision: 'revision', + botFiltering: true, + anonymizeIP: true, + }, + + user: { + id: 'userId', + attributes: [{ entityId: 'attr1-id', key: 'attr1-key', value: 'attr1-value' }], + }, + + event: { + id: 'event-id', + key: 'event-key', + }, + + tags: { + foo: 'bar', + value: '123', + revenue: '1000', + }, + + revenue: 1000, + value: 123, + } + + const impressionEvent: ImpressionEvent = { + type: 'impression', + timestamp: 69, + uuid: 'uuid', + + context: { + accountId: 'accountId', + projectId: 'projectId', + clientName: 'node-sdk', + clientVersion: '3.0.0', + revision: 'revision', + botFiltering: true, + anonymizeIP: true, + }, + + user: { + id: 'userId', + attributes: [{ entityId: 'attr1-id', key: 'attr1-key', value: 'attr1-value' }], + }, + + layer: { + id: 'layerId', + }, + + experiment: { + id: 'expId', + key: 'expKey', + }, + + variation: { + id: 'varId', + key: 'varKey', + }, + + ruleKey: 'expKey', + flagKey: 'flagKey1', + ruleType: 'experiment', + enabled: true, + } + + const result = makeBatchedEventV1([impressionEvent, conversionEvent]) + + expect(result).toEqual({ + client_name: 'node-sdk', + client_version: '3.0.0', + account_id: 'accountId', + project_id: 'projectId', + revision: 'revision', + anonymize_ip: true, + enrich_decisions: true, + + visitors: [ + { + snapshots: [ + { + decisions: [ + { + campaign_id: 'layerId', + experiment_id: 'expId', + variation_id: 'varId', + metadata: { + flag_key: 'flagKey1', + rule_key: 'expKey', + rule_type: 'experiment', + variation_key: 'varKey', + enabled: true, + }, + }, + ], + events: [ + { + entity_id: 'layerId', + timestamp: 69, + key: 'campaign_activated', + uuid: 'uuid', + }, + ], + }, + ], + visitor_id: 'userId', + attributes: [ + { + entity_id: 'attr1-id', + key: 'attr1-key', + type: 'custom', + value: 'attr1-value', + }, + { + entity_id: '$opt_bot_filtering', + key: '$opt_bot_filtering', + type: 'custom', + value: true, + }, + ], + }, + { + snapshots: [ + { + events: [ + { + entity_id: 'event-id', + timestamp: 69, + key: 'event-key', + uuid: 'uuid', + tags: { + foo: 'bar', + value: '123', + revenue: '1000', + }, + revenue: 1000, + value: 123, + }, + ], + }, + ], + visitor_id: 'userId', + attributes: [ + { + entity_id: 'attr1-id', + key: 'attr1-key', + type: 'custom', + value: 'attr1-value', + }, + { + entity_id: '$opt_bot_filtering', + key: '$opt_bot_filtering', + type: 'custom', + value: true, + }, + ], + }, + ], + }) + }) +}) + diff --git a/lib/core/event_builder/build_event_v1.ts b/lib/event_processor/event_builder/build_event_v1.ts similarity index 99% rename from lib/core/event_builder/build_event_v1.ts rename to lib/event_processor/event_builder/build_event_v1.ts index 0479dc79a..2cd794ca0 100644 --- a/lib/core/event_builder/build_event_v1.ts +++ b/lib/event_processor/event_builder/build_event_v1.ts @@ -17,7 +17,7 @@ import { EventTags, ConversionEvent, ImpressionEvent, -} from '../../event_processor/events'; +} from '../events'; import { Event } from '../../shared_types'; diff --git a/lib/core/event_builder/event_helpers.tests.js b/lib/event_processor/event_builder/event_helpers.tests.js similarity index 99% rename from lib/core/event_builder/event_helpers.tests.js rename to lib/event_processor/event_builder/event_helpers.tests.js index 552a72e24..b241ecaf0 100644 --- a/lib/core/event_builder/event_helpers.tests.js +++ b/lib/event_processor/event_builder/event_helpers.tests.js @@ -18,7 +18,7 @@ import { assert } from 'chai'; import fns from '../../utils/fns'; import * as projectConfig from '../../project_config/project_config'; -import * as decision from '../decision'; +import * as decision from '../../core/decision'; import { buildImpressionEvent, buildConversionEvent } from './event_helpers'; describe('lib/event_builder/event_helpers', function() { diff --git a/lib/core/event_builder/event_helpers.ts b/lib/event_processor/event_builder/event_helpers.ts similarity index 98% rename from lib/core/event_builder/event_helpers.ts rename to lib/event_processor/event_builder/event_helpers.ts index 9c0fc8257..58b5cdb08 100644 --- a/lib/core/event_builder/event_helpers.ts +++ b/lib/event_processor/event_builder/event_helpers.ts @@ -18,10 +18,10 @@ import { getLogger } from '../../modules/logging'; import fns from '../../utils/fns'; import * as eventTagUtils from '../../utils/event_tag_utils'; import * as attributesValidator from '../../utils/attributes_validator'; -import * as decision from '../decision'; +import * as decision from '../../core/decision'; import { EventTags, UserAttributes } from '../../shared_types'; -import { DecisionObj } from '../decision_service'; +import { DecisionObj } from '../../core/decision_service'; import { getAttributeId, getEventId, diff --git a/lib/core/event_builder/index.tests.js b/lib/event_processor/event_builder/index.tests.js similarity index 100% rename from lib/core/event_builder/index.tests.js rename to lib/event_processor/event_builder/index.tests.js diff --git a/lib/core/event_builder/index.ts b/lib/event_processor/event_builder/index.ts similarity index 99% rename from lib/core/event_builder/index.ts rename to lib/event_processor/event_builder/index.ts index 20efd53c7..813038f05 100644 --- a/lib/core/event_builder/index.ts +++ b/lib/event_processor/event_builder/index.ts @@ -14,7 +14,7 @@ * limitations under the License. */ import { LoggerFacade } from '../../modules/logging'; -import { EventV1 as CommonEventParams } from '../../event_processor/v1/buildEventV1'; +import { EventV1 as CommonEventParams } from '../event_builder/build_event_v1'; import fns from '../../utils/fns'; import { CONTROL_ATTRIBUTES, RESERVED_EVENT_KEYWORDS } from '../../utils/enums'; diff --git a/lib/event_processor/event_dispatcher.ts b/lib/event_processor/event_dispatcher.ts index 90b036862..3872e6e90 100644 --- a/lib/event_processor/event_dispatcher.ts +++ b/lib/event_processor/event_dispatcher.ts @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { EventV1 } from "./v1/buildEventV1"; +import { EventV1 } from "./event_builder/build_event_v1"; export type EventDispatcherResponse = { statusCode?: number diff --git a/lib/event_processor/forwarding_event_processor.spec.ts b/lib/event_processor/forwarding_event_processor.spec.ts index fa0192568..3675c010f 100644 --- a/lib/event_processor/forwarding_event_processor.spec.ts +++ b/lib/event_processor/forwarding_event_processor.spec.ts @@ -17,7 +17,7 @@ import { expect, describe, it, vi } from 'vitest'; import { getForwardingEventProcessor } from './forwarding_event_processor'; import { EventDispatcher } from './event_dispatcher'; -import { formatEvents, makeBatchedEventV1 } from './v1/buildEventV1'; +import { formatEvents, makeBatchedEventV1 } from './event_builder/build_event_v1'; import { createImpressionEvent } from '../tests/mock/create_event'; import { ServiceState } from '../service'; diff --git a/lib/event_processor/forwarding_event_processor.ts b/lib/event_processor/forwarding_event_processor.ts index 0ebe22ad0..99bccabd2 100644 --- a/lib/event_processor/forwarding_event_processor.ts +++ b/lib/event_processor/forwarding_event_processor.ts @@ -19,7 +19,7 @@ import { EventV1Request } from './event_dispatcher'; import { EventProcessor, ProcessableEvent } from './event_processor'; import { EventDispatcher } from '../shared_types'; -import { formatEvents } from '../core/event_builder/build_event_v1'; +import { formatEvents } from './event_builder/build_event_v1'; import { BaseService, ServiceState } from '../service'; import { EventEmitter } from '../utils/event_emitter/event_emitter'; import { Consumer, Fn } from '../utils/type'; diff --git a/lib/event_processor/v1/buildEventV1.ts b/lib/event_processor/v1/buildEventV1.ts deleted file mode 100644 index 51fd49ada..000000000 --- a/lib/event_processor/v1/buildEventV1.ts +++ /dev/null @@ -1,272 +0,0 @@ -/** - * Copyright 2022, 2024, Optimizely - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import { EventTags, ConversionEvent, ImpressionEvent, VisitorAttribute } from '../events' -import { ProcessableEvent } from '../event_processor' -import { EventV1Request } from '../event_dispatcher' - -const ACTIVATE_EVENT_KEY = 'campaign_activated' -const CUSTOM_ATTRIBUTE_FEATURE_TYPE = 'custom' -const BOT_FILTERING_KEY = '$opt_bot_filtering' - -export type EventV1 = { - account_id: string - project_id: string - revision: string - client_name: string - client_version: string - anonymize_ip: boolean - enrich_decisions: boolean - visitors: Visitor[] -} - -type Visitor = { - snapshots: Visitor.Snapshot[] - visitor_id: string - attributes: Visitor.Attribute[] -} - -// eslint-disable-next-line @typescript-eslint/no-namespace -namespace Visitor { - type AttributeType = 'custom' - - export type Attribute = { - // attribute id - entity_id: string - // attribute key - key: string - type: AttributeType - value: string | number | boolean - } - - export type Snapshot = { - decisions?: Decision[] - events: SnapshotEvent[] - } - - type Decision = { - campaign_id: string | null - experiment_id: string | null - variation_id: string | null - metadata: Metadata - } - - type Metadata = { - flag_key: string; - rule_key: string; - rule_type: string; - variation_key: string; - enabled: boolean; - } - - export type SnapshotEvent = { - entity_id: string | null - timestamp: number - uuid: string - key: string - revenue?: number - value?: number - tags?: EventTags - } -} - - - -type Attributes = { - [key: string]: string | number | boolean -} - -/** - * Given an array of batchable Decision or ConversionEvent events it returns - * a single EventV1 with proper batching - * - * @param {ProcessableEvent[]} events - * @returns {EventV1} - */ -export function makeBatchedEventV1(events: ProcessableEvent[]): EventV1 { - const visitors: Visitor[] = [] - const data = events[0] - - events.forEach(event => { - if (event.type === 'conversion' || event.type === 'impression') { - const visitor = makeVisitor(event) - - if (event.type === 'impression') { - visitor.snapshots.push(makeDecisionSnapshot(event)) - } else if (event.type === 'conversion') { - visitor.snapshots.push(makeConversionSnapshot(event)) - } - - visitors.push(visitor) - } - }) - - return { - client_name: data.context.clientName, - client_version: data.context.clientVersion, - - account_id: data.context.accountId, - project_id: data.context.projectId, - revision: data.context.revision, - anonymize_ip: data.context.anonymizeIP, - enrich_decisions: true, - - visitors, - } -} - -function makeConversionSnapshot(conversion: ConversionEvent): Visitor.Snapshot { - const tags: EventTags = { - ...conversion.tags, - } - - delete tags['revenue'] - delete tags['value'] - - const event: Visitor.SnapshotEvent = { - entity_id: conversion.event.id, - key: conversion.event.key, - timestamp: conversion.timestamp, - uuid: conversion.uuid, - } - - if (conversion.tags) { - event.tags = conversion.tags - } - - if (conversion.value != null) { - event.value = conversion.value - } - - if (conversion.revenue != null) { - event.revenue = conversion.revenue - } - - return { - events: [event], - } -} - -function makeDecisionSnapshot(event: ImpressionEvent): Visitor.Snapshot { - const { layer, experiment, variation, ruleKey, flagKey, ruleType, enabled } = event - const layerId = layer ? layer.id : null - const experimentId = experiment?.id ?? '' - const variationId = variation?.id ?? '' - const variationKey = variation ? variation.key : '' - - return { - decisions: [ - { - campaign_id: layerId, - experiment_id: experimentId, - variation_id: variationId, - metadata: { - flag_key: flagKey, - rule_key: ruleKey, - rule_type: ruleType, - variation_key: variationKey, - enabled: enabled, - }, - }, - ], - events: [ - { - entity_id: layerId, - timestamp: event.timestamp, - key: ACTIVATE_EVENT_KEY, - uuid: event.uuid, - }, - ], - } -} - -function makeVisitor(data: ImpressionEvent | ConversionEvent): Visitor { - const visitor: Visitor = { - snapshots: [], - visitor_id: data.user.id, - attributes: [], - } - - const type = 'custom' - data.user.attributes.forEach(attr => { - visitor.attributes.push({ - entity_id: attr.entityId, - key: attr.key, - type: type as 'custom', // tell the compiler this is always string "custom" - value: attr.value, - }) - }) - - if (typeof data.context.botFiltering === 'boolean') { - visitor.attributes.push({ - entity_id: BOT_FILTERING_KEY, - key: BOT_FILTERING_KEY, - type: CUSTOM_ATTRIBUTE_FEATURE_TYPE, - value: data.context.botFiltering, - }) - } - return visitor -} - -/** - * Event for usage with v1 logtier - * - * @export - * @interface EventBuilderV1 - */ - -export function buildImpressionEventV1(data: ImpressionEvent): EventV1 { - const visitor = makeVisitor(data) - visitor.snapshots.push(makeDecisionSnapshot(data)) - - return { - client_name: data.context.clientName, - client_version: data.context.clientVersion, - - account_id: data.context.accountId, - project_id: data.context.projectId, - revision: data.context.revision, - anonymize_ip: data.context.anonymizeIP, - enrich_decisions: true, - - visitors: [visitor], - } -} - -export function buildConversionEventV1(data: ConversionEvent): EventV1 { - const visitor = makeVisitor(data) - visitor.snapshots.push(makeConversionSnapshot(data)) - - return { - client_name: data.context.clientName, - client_version: data.context.clientVersion, - - account_id: data.context.accountId, - project_id: data.context.projectId, - revision: data.context.revision, - anonymize_ip: data.context.anonymizeIP, - enrich_decisions: true, - - visitors: [visitor], - } -} - -export function formatEvents(events: ProcessableEvent[]): EventV1Request { - return { - url: 'https://logx.optimizely.com/v1/events', - httpVerb: 'POST', - params: makeBatchedEventV1(events), - } -} diff --git a/lib/optimizely/index.ts b/lib/optimizely/index.ts index 7112c902c..c2d247b1d 100644 --- a/lib/optimizely/index.ts +++ b/lib/optimizely/index.ts @@ -41,8 +41,8 @@ import { newErrorDecision } from '../optimizely_decision'; import OptimizelyUserContext from '../optimizely_user_context'; import { ProjectConfigManager } from '../project_config/project_config_manager'; import { createDecisionService, DecisionService, DecisionObj } from '../core/decision_service'; -import { getImpressionEvent, getConversionEvent } from '../core/event_builder'; -import { buildImpressionEvent, buildConversionEvent } from '../core/event_builder/event_helpers'; +import { getImpressionEvent, getConversionEvent } from '../event_processor/event_builder'; +import { buildImpressionEvent, buildConversionEvent } from '../event_processor/event_builder/event_helpers'; import fns from '../utils/fns'; import { validate } from '../utils/attributes_validator'; import * as eventTagsValidator from '../utils/event_tags_validator'; diff --git a/tests/buildEventV1.spec.ts b/tests/buildEventV1.spec.ts deleted file mode 100644 index dafa67e60..000000000 --- a/tests/buildEventV1.spec.ts +++ /dev/null @@ -1,812 +0,0 @@ -/** - * Copyright 2022, 2024, Optimizely - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import { describe, it, expect } from 'vitest'; - -import { - buildConversionEventV1, - buildImpressionEventV1, - makeBatchedEventV1, -} from '../lib/event_processor/v1/buildEventV1' -import { ImpressionEvent, ConversionEvent } from '../lib/event_processor/events' - -describe('buildEventV1', () => { - describe('buildImpressionEventV1', () => { - it('should build an ImpressionEventV1 when experiment and variation are defined', () => { - const impressionEvent: ImpressionEvent = { - type: 'impression', - timestamp: 69, - uuid: 'uuid', - - context: { - accountId: 'accountId', - projectId: 'projectId', - clientName: 'node-sdk', - clientVersion: '3.0.0', - revision: 'revision', - botFiltering: true, - anonymizeIP: true, - }, - - user: { - id: 'userId', - attributes: [{ entityId: 'attr1-id', key: 'attr1-key', value: 'attr1-value' }], - }, - - layer: { - id: 'layerId', - }, - - experiment: { - id: 'expId', - key: 'expKey', - }, - - variation: { - id: 'varId', - key: 'varKey', - }, - - ruleKey: 'expKey', - flagKey: 'flagKey1', - ruleType: 'experiment', - enabled: true, - } - - const result = buildImpressionEventV1(impressionEvent) - expect(result).toEqual({ - client_name: 'node-sdk', - client_version: '3.0.0', - account_id: 'accountId', - project_id: 'projectId', - revision: 'revision', - anonymize_ip: true, - enrich_decisions: true, - - visitors: [ - { - snapshots: [ - { - decisions: [ - { - campaign_id: 'layerId', - experiment_id: 'expId', - variation_id: 'varId', - metadata: { - flag_key: 'flagKey1', - rule_key: 'expKey', - rule_type: 'experiment', - variation_key: 'varKey', - enabled: true, - }, - }, - ], - events: [ - { - entity_id: 'layerId', - timestamp: 69, - key: 'campaign_activated', - uuid: 'uuid', - }, - ], - }, - ], - visitor_id: 'userId', - attributes: [ - { - entity_id: 'attr1-id', - key: 'attr1-key', - type: 'custom', - value: 'attr1-value', - }, - { - entity_id: '$opt_bot_filtering', - key: '$opt_bot_filtering', - type: 'custom', - value: true, - }, - ], - }, - ], - }) - }) - - it('should build an ImpressionEventV1 when experiment and variation are not defined', () => { - const impressionEvent: ImpressionEvent = { - type: 'impression', - timestamp: 69, - uuid: 'uuid', - - context: { - accountId: 'accountId', - projectId: 'projectId', - clientName: 'node-sdk', - clientVersion: '3.0.0', - revision: 'revision', - botFiltering: true, - anonymizeIP: true, - }, - - user: { - id: 'userId', - attributes: [{ entityId: 'attr1-id', key: 'attr1-key', value: 'attr1-value' }], - }, - - layer: { - id: null, - }, - - experiment: { - id: null, - key: '', - }, - - variation: { - id: null, - key: '', - }, - - ruleKey: '', - flagKey: 'flagKey1', - ruleType: 'rollout', - enabled: true, - } - - const result = buildImpressionEventV1(impressionEvent) - expect(result).toEqual({ - client_name: 'node-sdk', - client_version: '3.0.0', - account_id: 'accountId', - project_id: 'projectId', - revision: 'revision', - anonymize_ip: true, - enrich_decisions: true, - - visitors: [ - { - snapshots: [ - { - decisions: [ - { - campaign_id: null, - experiment_id: "", - variation_id: "", - metadata: { - flag_key: 'flagKey1', - rule_key: '', - rule_type: 'rollout', - variation_key: '', - enabled: true, - }, - }, - ], - events: [ - { - entity_id: null, - timestamp: 69, - key: 'campaign_activated', - uuid: 'uuid', - }, - ], - }, - ], - visitor_id: 'userId', - attributes: [ - { - entity_id: 'attr1-id', - key: 'attr1-key', - type: 'custom', - value: 'attr1-value', - }, - { - entity_id: '$opt_bot_filtering', - key: '$opt_bot_filtering', - type: 'custom', - value: true, - }, - ], - }, - ], - }) - }) - }) - - describe('buildConversionEventV1', () => { - it('should build a ConversionEventV1 when tags object is defined', () => { - const conversionEvent: ConversionEvent = { - type: 'conversion', - timestamp: 69, - uuid: 'uuid', - - context: { - accountId: 'accountId', - projectId: 'projectId', - clientName: 'node-sdk', - clientVersion: '3.0.0', - revision: 'revision', - botFiltering: true, - anonymizeIP: true, - }, - - user: { - id: 'userId', - attributes: [{ entityId: 'attr1-id', key: 'attr1-key', value: 'attr1-value' }], - }, - - event: { - id: 'event-id', - key: 'event-key', - }, - - tags: { - foo: 'bar', - value: '123', - revenue: '1000', - }, - - revenue: 1000, - value: 123, - } - - const result = buildConversionEventV1(conversionEvent) - expect(result).toEqual({ - client_name: 'node-sdk', - client_version: '3.0.0', - account_id: 'accountId', - project_id: 'projectId', - revision: 'revision', - anonymize_ip: true, - enrich_decisions: true, - - visitors: [ - { - snapshots: [ - { - events: [ - { - entity_id: 'event-id', - timestamp: 69, - key: 'event-key', - uuid: 'uuid', - tags: { - foo: 'bar', - value: '123', - revenue: '1000', - }, - revenue: 1000, - value: 123, - }, - ], - }, - ], - visitor_id: 'userId', - attributes: [ - { - entity_id: 'attr1-id', - key: 'attr1-key', - type: 'custom', - value: 'attr1-value', - }, - { - entity_id: '$opt_bot_filtering', - key: '$opt_bot_filtering', - type: 'custom', - value: true, - }, - ], - }, - ], - }) - }) - - it('should build a ConversionEventV1 when tags object is undefined', () => { - const conversionEvent: ConversionEvent = { - type: 'conversion', - timestamp: 69, - uuid: 'uuid', - - context: { - accountId: 'accountId', - projectId: 'projectId', - clientName: 'node-sdk', - clientVersion: '3.0.0', - revision: 'revision', - botFiltering: true, - anonymizeIP: true, - }, - - user: { - id: 'userId', - attributes: [{ entityId: 'attr1-id', key: 'attr1-key', value: 'attr1-value' }], - }, - - event: { - id: 'event-id', - key: 'event-key', - }, - - tags: undefined, - - revenue: 1000, - value: 123, - } - - const result = buildConversionEventV1(conversionEvent) - expect(result).toEqual({ - client_name: 'node-sdk', - client_version: '3.0.0', - account_id: 'accountId', - project_id: 'projectId', - revision: 'revision', - anonymize_ip: true, - enrich_decisions: true, - - visitors: [ - { - snapshots: [ - { - events: [ - { - entity_id: 'event-id', - timestamp: 69, - key: 'event-key', - uuid: 'uuid', - tags: undefined, - revenue: 1000, - value: 123, - }, - ], - }, - ], - visitor_id: 'userId', - attributes: [ - { - entity_id: 'attr1-id', - key: 'attr1-key', - type: 'custom', - value: 'attr1-value', - }, - { - entity_id: '$opt_bot_filtering', - key: '$opt_bot_filtering', - type: 'custom', - value: true, - }, - ], - }, - ], - }) - }) - - it('should build a ConversionEventV1 when event id is null', () => { - const conversionEvent: ConversionEvent = { - type: 'conversion', - timestamp: 69, - uuid: 'uuid', - - context: { - accountId: 'accountId', - projectId: 'projectId', - clientName: 'node-sdk', - clientVersion: '3.0.0', - revision: 'revision', - botFiltering: true, - anonymizeIP: true, - }, - - user: { - id: 'userId', - attributes: [{ entityId: 'attr1-id', key: 'attr1-key', value: 'attr1-value' }], - }, - - event: { - id: null, - key: 'event-key', - }, - - tags: undefined, - - revenue: 1000, - value: 123, - } - - const result = buildConversionEventV1(conversionEvent) - expect(result).toEqual({ - client_name: 'node-sdk', - client_version: '3.0.0', - account_id: 'accountId', - project_id: 'projectId', - revision: 'revision', - anonymize_ip: true, - enrich_decisions: true, - - visitors: [ - { - snapshots: [ - { - events: [ - { - entity_id: null, - timestamp: 69, - key: 'event-key', - uuid: 'uuid', - tags: undefined, - revenue: 1000, - value: 123, - }, - ], - }, - ], - visitor_id: 'userId', - attributes: [ - { - entity_id: 'attr1-id', - key: 'attr1-key', - type: 'custom', - value: 'attr1-value', - }, - { - entity_id: '$opt_bot_filtering', - key: '$opt_bot_filtering', - type: 'custom', - value: true, - }, - ], - }, - ], - }) - }) - - it('should include revenue and value if they are 0', () => { - const conversionEvent: ConversionEvent = { - type: 'conversion', - timestamp: 69, - uuid: 'uuid', - - context: { - accountId: 'accountId', - projectId: 'projectId', - clientName: 'node-sdk', - clientVersion: '3.0.0', - revision: 'revision', - botFiltering: true, - anonymizeIP: true, - }, - - user: { - id: 'userId', - attributes: [{ entityId: 'attr1-id', key: 'attr1-key', value: 'attr1-value' }], - }, - - event: { - id: 'event-id', - key: 'event-key', - }, - - tags: { - foo: 'bar', - value: 0, - revenue: 0, - }, - - revenue: 0, - value: 0, - } - - const result = buildConversionEventV1(conversionEvent) - expect(result).toEqual({ - client_name: 'node-sdk', - client_version: '3.0.0', - account_id: 'accountId', - project_id: 'projectId', - revision: 'revision', - anonymize_ip: true, - enrich_decisions: true, - - visitors: [ - { - snapshots: [ - { - events: [ - { - entity_id: 'event-id', - timestamp: 69, - key: 'event-key', - uuid: 'uuid', - tags: { - foo: 'bar', - value: 0, - revenue: 0, - }, - revenue: 0, - value: 0, - }, - ], - }, - ], - visitor_id: 'userId', - attributes: [ - { - entity_id: 'attr1-id', - key: 'attr1-key', - type: 'custom', - value: 'attr1-value', - }, - { - entity_id: '$opt_bot_filtering', - key: '$opt_bot_filtering', - type: 'custom', - value: true, - }, - ], - }, - ], - }) - }) - - it('should not include $opt_bot_filtering attribute if context.botFiltering is undefined', () => { - const conversionEvent: ConversionEvent = { - type: 'conversion', - timestamp: 69, - uuid: 'uuid', - - context: { - accountId: 'accountId', - projectId: 'projectId', - clientName: 'node-sdk', - clientVersion: '3.0.0', - revision: 'revision', - anonymizeIP: true, - }, - - user: { - id: 'userId', - attributes: [{ entityId: 'attr1-id', key: 'attr1-key', value: 'attr1-value' }], - }, - - event: { - id: 'event-id', - key: 'event-key', - }, - - tags: { - foo: 'bar', - value: '123', - revenue: '1000', - }, - - revenue: 1000, - value: 123, - } - - const result = buildConversionEventV1(conversionEvent) - expect(result).toEqual({ - client_name: 'node-sdk', - client_version: '3.0.0', - account_id: 'accountId', - project_id: 'projectId', - revision: 'revision', - anonymize_ip: true, - enrich_decisions: true, - - visitors: [ - { - snapshots: [ - { - events: [ - { - entity_id: 'event-id', - timestamp: 69, - key: 'event-key', - uuid: 'uuid', - tags: { - foo: 'bar', - value: '123', - revenue: '1000', - }, - revenue: 1000, - value: 123, - }, - ], - }, - ], - visitor_id: 'userId', - attributes: [ - { - entity_id: 'attr1-id', - key: 'attr1-key', - type: 'custom', - value: 'attr1-value', - }, - ], - }, - ], - }) - }) - }) - - describe('makeBatchedEventV1', () => { - it('should batch Conversion and Impression events together', () => { - const conversionEvent: ConversionEvent = { - type: 'conversion', - timestamp: 69, - uuid: 'uuid', - - context: { - accountId: 'accountId', - projectId: 'projectId', - clientName: 'node-sdk', - clientVersion: '3.0.0', - revision: 'revision', - botFiltering: true, - anonymizeIP: true, - }, - - user: { - id: 'userId', - attributes: [{ entityId: 'attr1-id', key: 'attr1-key', value: 'attr1-value' }], - }, - - event: { - id: 'event-id', - key: 'event-key', - }, - - tags: { - foo: 'bar', - value: '123', - revenue: '1000', - }, - - revenue: 1000, - value: 123, - } - - const impressionEvent: ImpressionEvent = { - type: 'impression', - timestamp: 69, - uuid: 'uuid', - - context: { - accountId: 'accountId', - projectId: 'projectId', - clientName: 'node-sdk', - clientVersion: '3.0.0', - revision: 'revision', - botFiltering: true, - anonymizeIP: true, - }, - - user: { - id: 'userId', - attributes: [{ entityId: 'attr1-id', key: 'attr1-key', value: 'attr1-value' }], - }, - - layer: { - id: 'layerId', - }, - - experiment: { - id: 'expId', - key: 'expKey', - }, - - variation: { - id: 'varId', - key: 'varKey', - }, - - ruleKey: 'expKey', - flagKey: 'flagKey1', - ruleType: 'experiment', - enabled: true, - } - - const result = makeBatchedEventV1([impressionEvent, conversionEvent]) - - expect(result).toEqual({ - client_name: 'node-sdk', - client_version: '3.0.0', - account_id: 'accountId', - project_id: 'projectId', - revision: 'revision', - anonymize_ip: true, - enrich_decisions: true, - - visitors: [ - { - snapshots: [ - { - decisions: [ - { - campaign_id: 'layerId', - experiment_id: 'expId', - variation_id: 'varId', - metadata: { - flag_key: 'flagKey1', - rule_key: 'expKey', - rule_type: 'experiment', - variation_key: 'varKey', - enabled: true, - }, - }, - ], - events: [ - { - entity_id: 'layerId', - timestamp: 69, - key: 'campaign_activated', - uuid: 'uuid', - }, - ], - }, - ], - visitor_id: 'userId', - attributes: [ - { - entity_id: 'attr1-id', - key: 'attr1-key', - type: 'custom', - value: 'attr1-value', - }, - { - entity_id: '$opt_bot_filtering', - key: '$opt_bot_filtering', - type: 'custom', - value: true, - }, - ], - }, - { - snapshots: [ - { - events: [ - { - entity_id: 'event-id', - timestamp: 69, - key: 'event-key', - uuid: 'uuid', - tags: { - foo: 'bar', - value: '123', - revenue: '1000', - }, - revenue: 1000, - value: 123, - }, - ], - }, - ], - visitor_id: 'userId', - attributes: [ - { - entity_id: 'attr1-id', - key: 'attr1-key', - type: 'custom', - value: 'attr1-value', - }, - { - entity_id: '$opt_bot_filtering', - key: '$opt_bot_filtering', - type: 'custom', - value: true, - }, - ], - }, - ], - }) - }) - }) -}) From 0e97838f11b809e13994c191e768f61a4e311d3a Mon Sep 17 00:00:00 2001 From: Raju Ahmed Date: Sat, 23 Nov 2024 02:33:51 +0600 Subject: [PATCH 3/4] beacon --- lib/event_processor/event_processor_factory.browser.spec.ts | 2 +- lib/event_processor/event_processor_factory.browser.ts | 2 +- .../event_processor/send_beacon_dispatcher.browser.spec.ts | 6 +++--- .../send_beacon_dispatcher.browser.ts} | 2 +- lib/index.browser.ts | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) rename tests/sendBeaconDispatcher.spec.ts => lib/event_processor/send_beacon_dispatcher.browser.spec.ts (92%) rename lib/{plugins/event_dispatcher/send_beacon_dispatcher.ts => event_processor/send_beacon_dispatcher.browser.ts} (93%) diff --git a/lib/event_processor/event_processor_factory.browser.spec.ts b/lib/event_processor/event_processor_factory.browser.spec.ts index 5bd615ebe..e35dd1908 100644 --- a/lib/event_processor/event_processor_factory.browser.spec.ts +++ b/lib/event_processor/event_processor_factory.browser.spec.ts @@ -48,7 +48,7 @@ import { LocalStorageCache } from '../utils/cache/local_storage_cache.browser'; import { SyncPrefixCache } from '../utils/cache/cache'; import { createForwardingEventProcessor, createBatchEventProcessor } from './event_processor_factory.browser'; import { EVENT_STORE_PREFIX, FAILED_EVENT_RETRY_INTERVAL } from './event_processor_factory'; -import sendBeaconEventDispatcher from '../plugins/event_dispatcher/send_beacon_dispatcher'; +import sendBeaconEventDispatcher from './send_beacon_dispatcher.browser'; import { getForwardingEventProcessor } from './forwarding_event_processor'; import browserDefaultEventDispatcher from './default_dispatcher.browser'; import { getBatchEventProcessor } from './event_processor_factory'; diff --git a/lib/event_processor/event_processor_factory.browser.ts b/lib/event_processor/event_processor_factory.browser.ts index ee6d4516b..9456d06b1 100644 --- a/lib/event_processor/event_processor_factory.browser.ts +++ b/lib/event_processor/event_processor_factory.browser.ts @@ -20,7 +20,7 @@ import { EventProcessor } from './event_processor'; import { EventWithId } from './batch_event_processor'; import { getBatchEventProcessor, BatchEventProcessorOptions } from './event_processor_factory'; import defaultEventDispatcher from './default_dispatcher.browser'; -import sendBeaconEventDispatcher from '../plugins/event_dispatcher/send_beacon_dispatcher'; +import sendBeaconEventDispatcher from './send_beacon_dispatcher.browser'; import { LocalStorageCache } from '../utils/cache/local_storage_cache.browser'; import { SyncPrefixCache } from '../utils/cache/cache'; import { EVENT_STORE_PREFIX, FAILED_EVENT_RETRY_INTERVAL } from './event_processor_factory'; diff --git a/tests/sendBeaconDispatcher.spec.ts b/lib/event_processor/send_beacon_dispatcher.browser.spec.ts similarity index 92% rename from tests/sendBeaconDispatcher.spec.ts rename to lib/event_processor/send_beacon_dispatcher.browser.spec.ts index 3b69ffc27..06bd5bd1f 100644 --- a/tests/sendBeaconDispatcher.spec.ts +++ b/lib/event_processor/send_beacon_dispatcher.browser.spec.ts @@ -15,7 +15,7 @@ */ import { describe, beforeEach, it, expect, vi, MockInstance } from 'vitest'; -import sendBeaconDispatcher, { Event } from '../lib/plugins/event_dispatcher/send_beacon_dispatcher'; +import sendBeaconDispatcher, { Event } from './send_beacon_dispatcher.browser'; describe('dispatchEvent', function() { let sendBeaconSpy: MockInstance; @@ -26,8 +26,8 @@ describe('dispatchEvent', function() { }); it('should call sendBeacon with correct url, data and type', async () => { - var eventParams = { testParam: 'testParamValue' }; - var eventObj: Event = { + const eventParams = { testParam: 'testParamValue' }; + const eventObj: Event = { url: 'https://cdn.com/event', httpVerb: 'POST', params: eventParams, diff --git a/lib/plugins/event_dispatcher/send_beacon_dispatcher.ts b/lib/event_processor/send_beacon_dispatcher.browser.ts similarity index 93% rename from lib/plugins/event_dispatcher/send_beacon_dispatcher.ts rename to lib/event_processor/send_beacon_dispatcher.browser.ts index 7a70b279e..a2686b316 100644 --- a/lib/plugins/event_dispatcher/send_beacon_dispatcher.ts +++ b/lib/event_processor/send_beacon_dispatcher.browser.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { EventDispatcher, EventDispatcherResponse } from '../../event_processor/event_dispatcher'; +import { EventDispatcher, EventDispatcherResponse } from './event_dispatcher'; export type Event = { url: string; diff --git a/lib/index.browser.ts b/lib/index.browser.ts index f7b7ba98c..5821d0aa0 100644 --- a/lib/index.browser.ts +++ b/lib/index.browser.ts @@ -19,7 +19,7 @@ import { getLogger, setErrorHandler, getErrorHandler, LogLevel } from './modules import configValidator from './utils/config_validator'; import defaultErrorHandler from './plugins/error_handler'; import defaultEventDispatcher from './event_processor/default_dispatcher.browser'; -import sendBeaconEventDispatcher from './plugins/event_dispatcher/send_beacon_dispatcher'; +import sendBeaconEventDispatcher from './event_processor/send_beacon_dispatcher.browser'; import * as enums from './utils/enums'; import * as loggerPlugin from './plugins/logger'; import { createNotificationCenter } from './core/notification_center'; From 0e3292b7f6c5c4b210c2954b6cc36a0b7b1d890c Mon Sep 17 00:00:00 2001 From: Raju Ahmed Date: Sat, 23 Nov 2024 02:36:18 +0600 Subject: [PATCH 4/4] rem --- lib/index.lite.tests.js | 1 - lib/index.lite.ts | 3 --- lib/plugins/event_dispatcher/no_op.ts | 33 --------------------------- 3 files changed, 37 deletions(-) delete mode 100644 lib/plugins/event_dispatcher/no_op.ts diff --git a/lib/index.lite.tests.js b/lib/index.lite.tests.js index ba67811bd..076934eda 100644 --- a/lib/index.lite.tests.js +++ b/lib/index.lite.tests.js @@ -30,7 +30,6 @@ describe('optimizelyFactory', function() { assert.isDefined(optimizelyFactory.logging.createLogger); assert.isDefined(optimizelyFactory.logging.createNoOpLogger); assert.isDefined(optimizelyFactory.errorHandler); - assert.isDefined(optimizelyFactory.eventDispatcher); assert.isDefined(optimizelyFactory.enums); }); diff --git a/lib/index.lite.ts b/lib/index.lite.ts index b7fb41def..5aec89ecb 100644 --- a/lib/index.lite.ts +++ b/lib/index.lite.ts @@ -23,7 +23,6 @@ } from './modules/logging'; import configValidator from './utils/config_validator'; import defaultErrorHandler from './plugins/error_handler'; -import noOpEventDispatcher from './plugins/event_dispatcher/no_op'; import * as enums from './utils/enums'; import * as loggerPlugin from './plugins/logger'; import Optimizely from './optimizely'; @@ -89,7 +88,6 @@ setLogLevel(LogLevel.ERROR); export { loggerPlugin as logging, defaultErrorHandler as errorHandler, - noOpEventDispatcher as eventDispatcher, enums, setLogHandler as setLogger, setLogLevel, @@ -103,7 +101,6 @@ export default { ...commonExports, logging: loggerPlugin, errorHandler: defaultErrorHandler, - eventDispatcher: noOpEventDispatcher, enums, setLogger: setLogHandler, setLogLevel, diff --git a/lib/plugins/event_dispatcher/no_op.ts b/lib/plugins/event_dispatcher/no_op.ts deleted file mode 100644 index cbe2473d7..000000000 --- a/lib/plugins/event_dispatcher/no_op.ts +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Copyright 2021, 2024, Optimizely - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { Event } from '../../shared_types'; - -/** - * No Op Event dispatcher for non standard platforms like edge workers etc - * @param {Event} eventObj - * @param {Function} callback - */ -/* eslint-disable @typescript-eslint/no-unused-vars */ -export const dispatchEvent = function( - eventObj: Event, -): any { - // NoOp Event dispatcher. It does nothing really. -} - -export default { - dispatchEvent, -};