Skip to content

Commit d85ec98

Browse files
refactor: handle registerVuid
1 parent e84d353 commit d85ec98

File tree

5 files changed

+31
-10
lines changed

5 files changed

+31
-10
lines changed

lib/core/odp/odp_manager.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export interface IOdpManager {
4646

4747
sendEvent({ type, action, identifiers, data }: OdpEvent): void;
4848

49-
registerVuid(vuid: string): void;
49+
registerVuid(vuid: string | undefined): void;
5050
}
5151

5252
/**
@@ -87,7 +87,7 @@ export abstract class OdpManager implements IOdpManager {
8787
* ODP Event Manager which provides an interface to the remote ODP server (REST API) for events.
8888
* It will queue all pending events (persistent) and send them (in batches of up to 10 events) to the ODP server when possible.
8989
*/
90-
private eventManager: IOdpEventManager;
90+
protected readonly eventManager: IOdpEventManager;
9191

9292
/**
9393
* Handler for recording execution logs
@@ -133,7 +133,7 @@ export abstract class OdpManager implements IOdpManager {
133133
* Register a VUID with the ODP Manager in client side context
134134
* @param {string} vuid - Unique identifier of an anonymous vistor
135135
*/
136-
abstract registerVuid(vuid: string): void;
136+
abstract registerVuid(vuid: string | undefined): void;
137137

138138
/**
139139
* @returns {Status} The current status of the ODP Manager

lib/optimizely/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1424,7 +1424,7 @@ export default class Optimizely implements Client {
14241424
resolveTimeoutPromise({
14251425
success: true,
14261426
});
1427-
this.vuidManager?.registerUser();
1427+
this.odpManager?.registerVuid(this.vuidManager?.vuid)
14281428
});
14291429

14301430
return Promise.race([this.readyPromise, timeoutPromise]);

lib/plugins/odp_manager/index.browser.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ import {
1919
JAVASCRIPT_CLIENT_ENGINE,
2020
REQUEST_TIMEOUT_ODP_SEGMENTS_MS,
2121
REQUEST_TIMEOUT_ODP_EVENTS_MS,
22+
ERROR_MESSAGES,
2223
} from '../../utils/enums';
23-
import { getLogger, LogHandler } from '../../modules/logging';
24+
import { getLogger, LogHandler, LogLevel } from '../../modules/logging';
2425

2526
import { BrowserRequestHandler } from './../../utils/http_request_handler/browser_request_handler';
2627

@@ -46,9 +47,6 @@ interface BrowserOdpManagerConfig {
4647

4748
// Client-side Browser Plugin for ODP Manager
4849
export class BrowserOdpManager extends OdpManager {
49-
registerVuid(vuid: string): void {
50-
throw new Error('Method not implemented.');
51-
}
5250
constructor(options: {
5351
odpIntegrationConfig?: OdpIntegrationConfig;
5452
segmentManager: IOdpSegmentManager;
@@ -151,4 +149,27 @@ export class BrowserOdpManager extends OdpManager {
151149

152150
super.identifyUser(fsUserId, vuid);
153151
}
152+
153+
registerVuid(vuid: string | undefined): void {
154+
if (!this.odpIntegrationConfig) {
155+
this.logger.log(LogLevel.ERROR, ERROR_MESSAGES.ODP_CONFIG_NOT_AVAILABLE);
156+
return;
157+
}
158+
159+
if (!this.odpIntegrationConfig.integrated) {
160+
this.logger.log(LogLevel.INFO, ERROR_MESSAGES.ODP_NOT_INTEGRATED);
161+
return;
162+
}
163+
164+
if (!vuid || !VuidManager.isVuid(vuid)) {
165+
this.logger.log(LogLevel.ERROR, `The provided VUID ${vuid} is invalid.`);
166+
return;
167+
}
168+
169+
try {
170+
this.eventManager.registerVuid(vuid);
171+
} catch (e) {
172+
this.logger.log(LogLevel.ERROR, ERROR_MESSAGES.ODP_VUID_REGISTRATION_FAILED);
173+
}
174+
}
154175
}

lib/plugins/odp_manager/index.node.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export class NodeOdpManager extends OdpManager {
134134
});
135135
}
136136

137-
registerVuid(vuid: string): void {
137+
registerVuid(vuid: string | undefined): void {
138138
this.logger.log(LogLevel.ERROR, `Unable to registerVuid ${vuid || ''} in a node server context`);
139139
}
140140
}

lib/plugins/vuid_manager/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ export class VuidManager implements IVuidManager {
167167
* @param vuid VistorId to check
168168
* @returns *true* if the VisitorId is valid otherwise *false* for invalid
169169
*/
170-
static isVuid = (vuid: string): boolean => vuid?.startsWith(VuidManager.vuid_prefix) || false;
170+
static isVuid = (vuid: string | undefined): boolean => vuid?.startsWith(VuidManager.vuid_prefix) || false;
171171

172172
/**
173173
* Function used in unit testing to reset the VuidManager

0 commit comments

Comments
 (0)