Skip to content

Commit 1c734b6

Browse files
committed
Various Implementation Fixes for Demo Build
1 parent ecaa0ee commit 1c734b6

File tree

9 files changed

+42
-24
lines changed

9 files changed

+42
-24
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ dist/
1010
# user-specific ignores ought to be defined in user's `core.excludesfile`
1111
.idea/*
1212
.DS_STORE
13+
14+
browserstack.err
15+
local.log

packages/optimizely-sdk/lib/core/odp/odp_event_manager.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,17 @@ export class OdpEventManager implements IOdpEventManager {
140140
this.clientEngine = clientEngine;
141141
this.clientVersion = clientVersion;
142142

143-
this.queueSize = queueSize || (process ? DEFAULT_SERVER_QUEUE_SIZE : DEFAULT_BROWSER_QUEUE_SIZE);
143+
let defaultQueueSize = DEFAULT_BROWSER_QUEUE_SIZE;
144+
145+
try {
146+
if (process) {
147+
defaultQueueSize = DEFAULT_SERVER_QUEUE_SIZE;
148+
}
149+
} catch (e) {
150+
// TODO: Create Browser and Non-Browser specific variants of ODP Event Manager to avoid this try/catch
151+
}
152+
153+
this.queueSize = queueSize || defaultQueueSize;
144154
this.batchSize = batchSize || DEFAULT_BATCH_SIZE;
145155
this.flushInterval = flushInterval || DEFAULT_FLUSH_INTERVAL_MSECS;
146156

@@ -381,14 +391,20 @@ export class OdpEventManager implements IOdpEventManager {
381391
return true;
382392
}
383393

384-
if (process) {
385-
// if Node/server-side context, empty queue items before ready state
386-
this.logger.log(LogLevel.WARNING, 'ODPConfig not ready. Discarding events in queue.');
387-
this.queue = new Array<OdpEvent>();
388-
} else {
389-
// in Browser/client-side context, give debug message but leave events in queue
394+
try {
395+
if (process) {
396+
// if Node/server-side context, empty queue items before ready state
397+
this.logger.log(LogLevel.WARNING, 'ODPConfig not ready. Discarding events in queue.');
398+
this.queue = new Array<OdpEvent>();
399+
} else {
400+
// in Browser/client-side context, give debug message but leave events in queue
401+
this.logger.log(LogLevel.DEBUG, 'ODPConfig not ready. Leaving events in queue.');
402+
}
403+
} catch (e) {
404+
// TODO: Create Browser and Non-Browser specific variants of ODP Event Manager to avoid this try/catch
390405
this.logger.log(LogLevel.DEBUG, 'ODPConfig not ready. Leaving events in queue.');
391406
}
407+
392408
return false;
393409
}
394410

packages/optimizely-sdk/lib/core/odp/odp_segment_api_manager.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,14 @@ export class OdpSegmentApiManager implements IOdpSegmentApiManager {
130130
*/
131131
private toGraphQLJson = (userKey: string, userValue: string, segmentsToCheck: string[]): string =>
132132
[
133-
'{"query" : "query {customer"',
134-
`(${userKey} : "${userValue}") `,
133+
'{"query" : "query {customer',
134+
`(${userKey} : \\"${userValue}\\") `,
135135
'{audiences',
136136
'(subset: [',
137137
...(segmentsToCheck?.map(
138138
(segment, index) => `\\"${segment}\\"${index < segmentsToCheck.length - 1 ? ',' : ''}`
139139
) || ''),
140-
'] {edges {node {name state}}}}}"}',
140+
']) {edges {node {name state}}}}}"}',
141141
].join('');
142142

143143
/**

packages/optimizely-sdk/lib/export_types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2022, Optimizely
2+
* Copyright 2022-2023, Optimizely
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,5 +37,5 @@ export {
3737
Client,
3838
ActivateListenerPayload,
3939
TrackListenerPayload,
40-
NotificationCenter
41-
} from './shared_types'
40+
NotificationCenter,
41+
} from './shared_types';

packages/optimizely-sdk/lib/plugins/vuid_manager/index.ts

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

130130
/**
131131
* Function used in unit testing to reset the VuidManager

packages/optimizely-sdk/lib/shared_types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,7 @@ export interface OptimizelyUserContext {
490490
getForcedDecision(context: OptimizelyDecisionContext): OptimizelyForcedDecision | null;
491491
removeForcedDecision(context: OptimizelyDecisionContext): boolean;
492492
removeAllForcedDecisions(): boolean;
493+
fetchQualifiedSegments(): Promise<boolean>;
493494
isQualifiedFor(segment: string): boolean;
494495
}
495496

packages/optimizely-sdk/lib/utils/json_schema_validator/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ const MODULE_NAME = 'JSON_SCHEMA_VALIDATOR';
2828
* @param {boolean} shouldThrowOnError Should validation throw if invalid JSON object
2929
* @return {boolean} true if the given object is valid; throws or false if invalid
3030
*/
31-
export function validate(jsonObject: unknown, validationSchema: JSONSchema4 = schema, shouldThrowOnError = true): boolean {
31+
export function validate(
32+
jsonObject: unknown,
33+
validationSchema: JSONSchema4 = schema,
34+
shouldThrowOnError = true
35+
): boolean {
3236
const moduleTitle = `${MODULE_NAME} (${validationSchema.title})`;
3337

3438
if (typeof jsonObject !== 'object' || jsonObject === null) {
@@ -46,7 +50,7 @@ export function validate(jsonObject: unknown, validationSchema: JSONSchema4 = sc
4650

4751
if (Array.isArray(result.errors)) {
4852
throw new Error(
49-
sprintf(ERROR_MESSAGES.INVALID_DATAFILE, moduleTitle, result.errors[0].property, result.errors[0].message),
53+
sprintf(ERROR_MESSAGES.INVALID_DATAFILE, moduleTitle, result.errors[0].property, result.errors[0].message)
5054
);
5155
}
5256

packages/optimizely-sdk/rollup.config.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,18 @@ const umdBundle = {
6969
commonjs({
7070
namedExports: {
7171
'@optimizely/js-sdk-event-processor': ['LogTierV1EventProcessor', 'LocalStoragePendingEventsDispatcher'],
72+
'json-schema': ['validate'],
7273
},
7374
}),
7475
typescript(typescriptPluginOptions),
7576
],
76-
external: ['json-schema'],
7777
input: 'lib/index.browser.ts',
7878
output: [
7979
{
8080
name: 'optimizelySdk',
8181
format: 'umd',
8282
file: 'dist/optimizely.browser.umd.js',
8383
exports: 'named',
84-
globals: {
85-
'json-schema': 'json-schema',
86-
},
8784
},
8885
{
8986
name: 'optimizelySdk',
@@ -92,9 +89,6 @@ const umdBundle = {
9289
exports: 'named',
9390
plugins: [terser()],
9491
sourcemap: true,
95-
globals: {
96-
'json-schema': 'json-schema',
97-
},
9892
},
9993
],
10094
};

packages/optimizely-sdk/tests/odpSegmentApiManager.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ describe('OdpSegmentApiManager', () => {
133133
const response = manager['toGraphQLJson'](USER_KEY, USER_VALUE, SEGMENTS_TO_CHECK);
134134

135135
expect(response).toBe(
136-
`{"query" : "query {customer"(${USER_KEY} : "${USER_VALUE}") {audiences(subset: [\\"has_email\\",\\"has_email_opted_in\\",\\"push_on_sale\\"] {edges {node {name state}}}}}"}`
136+
`{"query" : "query {customer(${USER_KEY} : \\"${USER_VALUE}\\") {audiences(subset: [\\"has_email\\",\\"has_email_opted_in\\",\\"push_on_sale\\"]) {edges {node {name state}}}}}"}`
137137
);
138138
});
139139

0 commit comments

Comments
 (0)