Skip to content

Commit 24e2b36

Browse files
fix: PR requested updates
1 parent 1196193 commit 24e2b36

File tree

5 files changed

+32
-27
lines changed

5 files changed

+32
-27
lines changed

lib/core/odp/odp_manager.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { OptimizelySegmentOption } from './optimizely_segment_option';
2727
import { invalidOdpDataFound } from './odp_utils';
2828
import { OdpEvent } from './odp_event';
2929
import { resolvablePromise, ResolvablePromise } from '../../utils/promise/resolvablePromise';
30-
import { OdpOptions } from '../../shared_types';
30+
import { VuidManagerOptions } from '../../shared_types';
3131

3232
/**
3333
* Manager for handling internal all business logic related to
@@ -99,28 +99,28 @@ export abstract class OdpManager implements IOdpManager {
9999
odpIntegrationConfig?: OdpIntegrationConfig;
100100

101101
/**
102-
* ODP initialization options
102+
* Options for handling VUID Manager
103103
*/
104-
protected odpOptions?: OdpOptions;
104+
protected vuidManagerOptions?: VuidManagerOptions;
105105

106106
// TODO: Consider accepting logger as a parameter and initializing it in constructor instead
107107
constructor({
108108
odpIntegrationConfig,
109109
segmentManager,
110110
eventManager,
111111
logger,
112-
odpOptions,
112+
vuidManagerOptions,
113113
}: {
114114
odpIntegrationConfig?: OdpIntegrationConfig;
115115
segmentManager: IOdpSegmentManager;
116116
eventManager: IOdpEventManager;
117117
logger: LogHandler;
118-
odpOptions?: OdpOptions;
118+
vuidManagerOptions?: VuidManagerOptions;
119119
}) {
120120
this.segmentManager = segmentManager;
121121
this.eventManager = eventManager;
122122
this.logger = logger;
123-
this.odpOptions = odpOptions;
123+
this.vuidManagerOptions = vuidManagerOptions;
124124
this.configPromise = resolvablePromise();
125125

126126
const readinessDependencies: PromiseLike<unknown>[] = [this.configPromise];

lib/plugins/odp_manager/index.browser.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { VuidManager } from './../vuid_manager/index';
3333

3434
import { OdpManager } from '../../core/odp/odp_manager';
3535
import { OdpEvent } from '../../core/odp/odp_event';
36-
import { IOdpEventManager, OdpOptions } from '../../shared_types';
36+
import { IOdpEventManager, OdpOptions, VuidManagerOptions } from '../../shared_types';
3737
import { BrowserOdpEventApiManager } from '../odp/event_api_manager/index.browser';
3838
import { BrowserOdpEventManager } from '../odp/event_manager/index.browser';
3939
import { IOdpSegmentManager, OdpSegmentManager } from '../../core/odp/odp_segment_manager';
@@ -46,25 +46,26 @@ interface BrowserOdpManagerConfig {
4646
logger?: LogHandler;
4747
odpOptions?: OdpOptions;
4848
odpIntegrationConfig?: OdpIntegrationConfig;
49+
vuidManagerOptions?: VuidManagerOptions;
4950
}
5051

5152
// Client-side Browser Plugin for ODP Manager
5253
export class BrowserOdpManager extends OdpManager {
5354
static cache = new BrowserAsyncStorageCache();
54-
vuid?: string = "";
55+
vuid?: string;
5556

5657
constructor(options: {
5758
odpIntegrationConfig?: OdpIntegrationConfig;
5859
segmentManager: IOdpSegmentManager;
5960
eventManager: IOdpEventManager;
6061
logger: LogHandler;
61-
odpOptions?: OdpOptions;
62+
vuidManagerOptions?: VuidManagerOptions;
6263
}) {
6364
super(options);
6465
}
6566

6667
static createInstance({
67-
logger, odpOptions, odpIntegrationConfig, clientEngine, clientVersion
68+
logger, odpOptions, odpIntegrationConfig, clientEngine, clientVersion, vuidManagerOptions,
6869
}: BrowserOdpManagerConfig): BrowserOdpManager {
6970
logger = logger || getLogger();
7071

@@ -134,7 +135,7 @@ export class BrowserOdpManager extends OdpManager {
134135
segmentManager,
135136
eventManager,
136137
logger,
137-
odpOptions,
138+
vuidManagerOptions,
138139
});
139140
}
140141

@@ -143,7 +144,7 @@ export class BrowserOdpManager extends OdpManager {
143144
* accesses or creates new VUID from Browser cache
144145
*/
145146
protected async initializeVuid(): Promise<void> {
146-
const vuidManager = await VuidManager.instance(BrowserOdpManager.cache, this.odpOptions);
147+
const vuidManager = await VuidManager.instance(BrowserOdpManager.cache, this.vuidManagerOptions);
147148
this.vuid = vuidManager.vuid;
148149
}
149150

@@ -189,7 +190,7 @@ export class BrowserOdpManager extends OdpManager {
189190
}
190191

191192
isVuidEnabled(): boolean {
192-
return this.odpOptions?.enableVuid || false;
193+
return this.vuidManagerOptions?.enableVuid || false;
193194
}
194195

195196
getVuid(): string | undefined {

lib/plugins/vuid_manager/index.ts

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

17-
import { OdpOptions } from '../../shared_types';
17+
import { VuidManagerOptions } from '../../shared_types';
1818
import { uuid } from '../../utils/fns';
1919
import PersistentKeyValueCache from '../key_value_cache/persistentKeyValueCache';
2020

@@ -44,7 +44,7 @@ export class VuidManager implements IVuidManager {
4444
* Current VUID value being used
4545
* @private
4646
*/
47-
private _vuid = '';
47+
private _vuid: string;
4848

4949
/**
5050
* Get the current VUID value being used
@@ -53,7 +53,9 @@ export class VuidManager implements IVuidManager {
5353
return this._vuid;
5454
}
5555

56-
private constructor() { }
56+
private constructor() {
57+
this._vuid = '';
58+
}
5759

5860
/**
5961
* Instance of the VUID Manager
@@ -63,10 +65,11 @@ export class VuidManager implements IVuidManager {
6365

6466
/**
6567
* Gets the current instance of the VUID Manager, initializing if needed
66-
* @param cache Caching mechanism to use for persisting the VUID outside working memory *
68+
* @param cache Caching mechanism to use for persisting the VUID outside working memory
69+
* @param options Options for the VUID Manager
6770
* @returns An instance of VuidManager
6871
*/
69-
static async instance(cache: PersistentKeyValueCache, options?: OdpOptions): Promise<VuidManager> {
72+
static async instance(cache: PersistentKeyValueCache, options?: VuidManagerOptions): Promise<VuidManager> {
7073
if (!this._instance) {
7174
this._instance = new VuidManager();
7275
}

lib/shared_types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ export interface DatafileOptions {
9696

9797
export interface OdpOptions {
9898
disabled?: boolean;
99-
enableVuid?: boolean;
10099
segmentsCache?: ICache<string, string[]>;
101100
segmentsCacheSize?: number;
102101
segmentsCacheTimeout?: number;
@@ -112,6 +111,10 @@ export interface OdpOptions {
112111
userAgentParser?: IUserAgentParser;
113112
}
114113

114+
export type VuidManagerOptions = {
115+
enableVuid: boolean;
116+
}
117+
115118
export interface ListenerPayload {
116119
userId: string;
117120
attributes?: UserAttributes;

tests/odpManager.browser.spec.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,28 +107,26 @@ describe('OdpManager', () => {
107107
resetCalls(mockSegmentManager);
108108
});
109109

110-
it('should have an empty string for VUID on BrowserOdpManager initialization', async () => {
110+
it('should have undefined VUID on BrowserOdpManager initialization', async () => {
111111
const browserOdpManager = BrowserOdpManager.createInstance({
112112
odpOptions: {
113113
eventManager: fakeEventManager,
114114
segmentManager: fakeSegmentManager,
115-
// enableVuid: false, // Note: VUID is not explicitly enabled
116-
},
115+
}
117116
});
118117

119-
const vuidManager = await VuidManager.instance(BrowserOdpManager.cache);
120-
121-
expect(vuidManager.vuid).toBe("");
122-
expect(browserOdpManager.vuid).toBe("")
118+
expect(browserOdpManager.vuid).toBeUndefined();
123119
});
124120

125121
it('should create VUID automatically on BrowserOdpManager initialization if VUID is explicitly enabled', async () => {
126122
const browserOdpManager = BrowserOdpManager.createInstance({
127123
odpOptions: {
128124
eventManager: fakeEventManager,
129125
segmentManager: fakeSegmentManager,
130-
enableVuid: true,
131126
},
127+
vuidManagerOptions: {
128+
enableVuid: true,
129+
}
132130
});
133131

134132
const vuidManager = await VuidManager.instance(BrowserOdpManager.cache, {enableVuid: true});

0 commit comments

Comments
 (0)