Skip to content

Commit 3379b69

Browse files
committed
upd
1 parent c7091f6 commit 3379b69

File tree

3 files changed

+31
-96
lines changed

3 files changed

+31
-96
lines changed

tests/odpEventManager.spec.ts renamed to lib/odp/event_manager/odpEventManager.spec.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@
1515
*/
1616
import { describe, beforeEach, afterEach, beforeAll, it, vi, expect } from 'vitest';
1717

18-
import { ODP_EVENT_ACTION, ODP_DEFAULT_EVENT_TYPE, ERROR_MESSAGES } from '../lib/utils/enums';
19-
import { OdpConfig } from '../lib/odp/odp_config';
20-
import { Status } from '../lib/odp/event_manager/odp_event_manager';
21-
import { BrowserOdpEventManager } from '../lib/odp/event_manager/event_manager.browser';
22-
import { NodeOdpEventManager } from '../lib/odp/event_manager/event_manager.node';
23-
import { OdpEventManager } from '../lib/odp/event_manager/odp_event_manager';
18+
import { ODP_EVENT_ACTION, ODP_DEFAULT_EVENT_TYPE, ERROR_MESSAGES } from '../../utils/enums';
19+
import { OdpConfig } from '../odp_config';
20+
import { Status } from './odp_event_manager';
21+
import { BrowserOdpEventManager } from './event_manager.browser';
22+
import { NodeOdpEventManager } from './event_manager.node';
23+
import { OdpEventManager } from './odp_event_manager';
2424
import { anything, capture, instance, mock, resetCalls, spy, verify, when } from 'ts-mockito';
25-
import { IOdpEventApiManager } from '../lib/odp/event_manager/odp_event_api_manager';
26-
import { LogHandler, LogLevel } from '../lib/modules/logging';
27-
import { OdpEvent } from '../lib/odp/event_manager/odp_event';
28-
import { IUserAgentParser } from '../lib/odp/ua_parser/user_agent_parser';
29-
import { UserAgentInfo } from '../lib/odp/ua_parser/user_agent_info';
25+
import { IOdpEventApiManager } from './odp_event_api_manager';
26+
import { LogHandler, LogLevel } from '../../modules/logging';
27+
import { OdpEvent } from './odp_event';
28+
import { IUserAgentParser } from '../ua_parser/user_agent_parser';
29+
import { UserAgentInfo } from '../ua_parser/user_agent_info';
3030
import { resolve } from 'path';
31-
import { advanceTimersByTime } from './testUtils';
31+
import { advanceTimersByTime } from '../../../tests/testUtils';
3232

3333
const API_KEY = 'test-api-key';
3434
const API_HOST = 'https://odp.example.com';
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Copyright 2024, Optimizely
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/

lib/odp/event_manager/odp_event_manager.ts

Lines changed: 4 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { LogLevel } from '../../modules/logging';
18-
1917
import { OdpEvent } from './odp_event';
2018
import { OdpConfig, OdpIntegrationConfig } from '../odp_config';
2119
import { OdpEventApiManager } from './odp_event_api_manager';
@@ -54,8 +52,6 @@ export class DefaultOdpEventManager extends BaseService implements OdpEventManag
5452

5553
private retryConfig: RetryConfig;
5654

57-
// private readonly userAgentData?: Map<string, unknown>;
58-
5955
constructor(config: OdpEventManagerConfig) {
6056
super(config.startUpLogs);
6157

@@ -65,28 +61,8 @@ export class DefaultOdpEventManager extends BaseService implements OdpEventManag
6561

6662
this.repeater = config.repeater;
6763
this.repeater.setTask(() => this.flush());
68-
69-
// if (config.userAgentParser) {
70-
// const { os, device } = config.userAgentParser.parseUserAgentInfo();
71-
72-
// const userAgentInfo: Record<string, unknown> = {
73-
// 'os': os.name,
74-
// 'os_version': os.version,
75-
// 'device_type': device.type,
76-
// 'model': device.model,
77-
// };
78-
79-
// this.userAgentData = new Map<string, unknown>(
80-
// Object.entries(userAgentInfo).filter(([_, value]) => value != null && value != undefined)
81-
// );
82-
// }
8364
}
8465

85-
// setClientInfo(clientEngine: string, clientVersion: string): void {
86-
// this.clientEngine = clientEngine;
87-
// this.clientVersion = clientVersion;
88-
// }
89-
9066
private async executeDispatch(odpConfig: OdpConfig, batch: OdpEvent[]): Promise<unknown> {
9167
const res = await this.apiManager.sendEvents(odpConfig, batch);
9268
if (res.statusCode && !isSuccessStatusCode(res.statusCode)) {
@@ -106,8 +82,8 @@ export class DefaultOdpEventManager extends BaseService implements OdpEventManag
10682
const batch = this.queue;
10783
this.queue = [];
10884

109-
// as the current queue has been emptied, stop repeating flus
110-
// until more events becomes availabe
85+
// as the queue has been emptied, stop repeating flush
86+
// until more events become available
11187
this.repeater.reset();
11288

11389
return runWithRetry(
@@ -129,18 +105,6 @@ export class DefaultOdpEventManager extends BaseService implements OdpEventManag
129105
} else {
130106
this.state = ServiceState.Starting;
131107
}
132-
133-
// if (!this.odpIntegrationConfig) {
134-
// this.logger.log(LogLevel.ERROR, ERROR_MESSAGES.ODP_CONFIG_NOT_AVAILABLE);
135-
// return;
136-
// }
137-
138-
// this.status = Status.Running;
139-
140-
// // no need of periodic flush if batchSize is 1
141-
// if (this.batchSize > 1) {
142-
// this.setNewTimeout();
143-
// }
144108
}
145109

146110
updateConfig(odpIntegrationConfig: OdpIntegrationConfig): void {
@@ -183,31 +147,6 @@ export class DefaultOdpEventManager extends BaseService implements OdpEventManag
183147
this.stopPromise.resolve();
184148
}
185149

186-
// TODO: move this to ODP manager
187-
/**
188-
* Associate a full-stack userid with an established VUID
189-
* @param {string} userId (Optional) Full-stack User ID
190-
* @param {string} vuid (Optional) Visitor User ID
191-
*/
192-
// identifyUser(userId?: string, vuid?: string): void {
193-
// const identifiers = new Map<string, string>();
194-
// if (!userId && !vuid) {
195-
// this.logger.log(LogLevel.ERROR, ERROR_MESSAGES.ODP_SEND_EVENT_FAILED_UID_MISSING);
196-
// return;
197-
// }
198-
199-
// if (vuid) {
200-
// identifiers.set(ODP_USER_KEY.VUID, vuid);
201-
// }
202-
203-
// if (userId) {
204-
// identifiers.set(ODP_USER_KEY.FS_USER_ID, userId);
205-
// }
206-
207-
// const event = new OdpEvent(ODP_DEFAULT_EVENT_TYPE, ODP_EVENT_ACTION.IDENTIFIED, identifiers);
208-
// this.sendEvent(event);
209-
// }
210-
211150
sendEvent(event: OdpEvent): void {
212151
if (!this.isRunning()) {
213152
this.logger?.error('ODP event manager is not running.');
@@ -220,7 +159,7 @@ export class DefaultOdpEventManager extends BaseService implements OdpEventManag
220159
}
221160

222161
if (event.identifiers.size === 0) {
223-
this.logger?.log(LogLevel.ERROR, 'ODP events should have at least one key-value pair in identifiers.');
162+
this.logger?.error('ODP events should have at least one key-value pair in identifiers.');
224163
return;
225164
}
226165

@@ -235,7 +174,7 @@ export class DefaultOdpEventManager extends BaseService implements OdpEventManag
235174
}
236175

237176
if (event.type === '') {
238-
event.action = ODP_DEFAULT_EVENT_TYPE;
177+
event.type = ODP_DEFAULT_EVENT_TYPE;
239178
}
240179

241180
event.identifiers.forEach((key, value) => {
@@ -270,23 +209,4 @@ export class DefaultOdpEventManager extends BaseService implements OdpEventManag
270209
this.repeater.start();
271210
}
272211
}
273-
274-
// TODO: move to ODP maanger
275-
/**
276-
* Add additional common data including an idempotent ID and execution context to event data
277-
* @param sourceData Existing event data to augment
278-
* @returns Augmented event data
279-
* @private
280-
*/
281-
// private augmentCommonData(sourceData: Map<string, unknown>): Map<string, unknown> {
282-
// const data = new Map<string, unknown>(this.userAgentData);
283-
284-
// data.set('idempotence_id', uuidV4());
285-
// data.set('data_source_type', 'sdk');
286-
// data.set('data_source', this.clientEngine);
287-
// data.set('data_source_version', this.clientVersion);
288-
289-
// sourceData.forEach((value, key) => data.set(key, value));
290-
// return data;
291-
// }
292212
}

0 commit comments

Comments
 (0)