Skip to content

Commit dd1b434

Browse files
refactor: ODP managers
1 parent 8cfb58a commit dd1b434

File tree

3 files changed

+39
-9
lines changed

3 files changed

+39
-9
lines changed

lib/core/odp/odp_manager.ts

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

17-
import { LOG_MESSAGES } from './../../utils/enums/index';
18-
import { getLogger, LogHandler, LogLevel } from '../../modules/logging';
17+
import { LogHandler, LogLevel } from '../../modules/logging';
1918
import { ERROR_MESSAGES, ODP_USER_KEY } from '../../utils/enums';
2019

2120
import { VuidManager } from '../../plugins/vuid_manager';
@@ -46,8 +45,13 @@ export interface IOdpManager {
4645
identifyUser(userId?: string, vuid?: string): void;
4746

4847
sendEvent({ type, action, identifiers, data }: OdpEvent): void;
48+
49+
registerVuid(vuid: string): void;
4950
}
5051

52+
/**
53+
* Possible statuses for the OdpManager
54+
*/
5155
export enum Status {
5256
Running,
5357
Stopped,
@@ -68,7 +72,10 @@ export abstract class OdpManager implements IOdpManager {
6872
*/
6973
private configPromise: ResolvablePromise<void>;
7074

71-
status: Status = Status.Stopped;
75+
/**
76+
* The current status of the ODP Manager
77+
*/
78+
private status: Status = Status.Stopped;
7279

7380
/**
7481
* ODP Segment Manager which provides an interface to the remote ODP server (GraphQL API) for audience segments mapping.
@@ -91,9 +98,8 @@ export abstract class OdpManager implements IOdpManager {
9198
/**
9299
* ODP configuration settings for identifying the target API and segments
93100
*/
94-
odpIntegrationConfig?: OdpIntegrationConfig;
101+
protected odpIntegrationConfig?: OdpIntegrationConfig;
95102

96-
// TODO: Consider accepting logger as a parameter and initializing it in constructor instead
97103
constructor({
98104
odpIntegrationConfig,
99105
segmentManager,
@@ -123,10 +129,23 @@ export abstract class OdpManager implements IOdpManager {
123129
}
124130
}
125131

126-
public getStatus(): Status {
132+
/**
133+
* Register a VUID with the ODP Manager in client side context
134+
* @param {string} vuid - Unique identifier of an anonymous vistor
135+
*/
136+
abstract registerVuid(vuid: string): void;
137+
138+
/**
139+
* @returns {Status} The current status of the ODP Manager
140+
*/
141+
getStatus(): Status {
127142
return this.status;
128143
}
129144

145+
/**
146+
* Starts the ODP Manager
147+
* @returns {Promise<void>} A promise that resolves when starting has completed
148+
*/
130149
async start(): Promise<void> {
131150
if (this.status === Status.Running) {
132151
return;
@@ -147,6 +166,10 @@ export abstract class OdpManager implements IOdpManager {
147166
return Promise.resolve();
148167
}
149168

169+
/**
170+
* Stops the ODP Manager
171+
* @returns A promise that resolves when stopping has completed
172+
*/
150173
async stop(): Promise<void> {
151174
if (this.status === Status.Stopped) {
152175
return;
@@ -218,7 +241,7 @@ export abstract class OdpManager implements IOdpManager {
218241
/**
219242
* Identifies a user via the ODP Event Manager
220243
* @param {string} userId (Optional) Custom unique identifier of a target user.
221-
* @param {string} vuid (Optional) Secondary unique identifier of a target user, primarily used by client SDKs.
244+
* @param {string} vuid (Optional) Secondary unique identifier of a target user, used by client SDKs.
222245
* @returns
223246
*/
224247
identifyUser(userId?: string, vuid?: string): void {

lib/plugins/odp_manager/index.browser.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ interface BrowserOdpManagerConfig {
4646

4747
// Client-side Browser Plugin for ODP Manager
4848
export class BrowserOdpManager extends OdpManager {
49+
registerVuid(vuid: string): void {
50+
throw new Error('Method not implemented.');
51+
}
4952
constructor(options: {
5053
odpIntegrationConfig?: OdpIntegrationConfig;
5154
segmentManager: IOdpSegmentManager;

lib/plugins/odp_manager/index.node.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { NodeRequestHandler } from '../../utils/http_request_handler/node_reques
1818

1919
import { ServerLRUCache } from './../../utils/lru_cache/server_lru_cache';
2020

21-
import { getLogger, LogHandler } from '../../modules/logging';
21+
import { getLogger, LogHandler, LogLevel } from '../../modules/logging';
2222
import {
2323
NODE_CLIENT_ENGINE,
2424
CLIENT_VERSION,
@@ -133,4 +133,8 @@ export class NodeOdpManager extends OdpManager {
133133
logger,
134134
});
135135
}
136-
}
136+
137+
registerVuid(vuid: string): void {
138+
this.logger.log(LogLevel.ERROR, `Unable to registerVuid ${vuid || ''} in a node server context`);
139+
}
140+
}

0 commit comments

Comments
 (0)