@ninetailed/experience.js 7.5.3-beta.2 → 7.5.3-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{index.esm.js → index.js} +122 -117
- package/package.json +8 -5
- package/index.cjs.d.ts +0 -1
- /package/{index.cjs.js → index.cjs} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FEATURES, logger, ConsoleLogSink, buildPageEvent, buildTrackEvent, buildIdentifyEvent, unionBy,
|
|
1
|
+
import { FEATURES, logger, ConsoleLogSink, buildPageEvent, buildTrackEvent, buildIdentifyEvent, unionBy, NinetailedApiClient, OnLogLogSink, OnErrorLogSink, PageviewProperties, Properties, Traits, pipe } from '@ninetailed/experience.js-shared';
|
|
2
2
|
export { EXPERIENCE_TRAIT_PREFIX, isExperienceMatch, selectActiveExperiments, selectDistribution, selectExperience, selectBaselineWithVariants as selectExperienceBaselineWithVariants, selectVariant as selectExperienceVariant, selectVariants as selectExperienceVariants, selectHasVariants as selectHasExperienceVariants } from '@ninetailed/experience.js-shared';
|
|
3
3
|
import Analytics from 'analytics';
|
|
4
4
|
import { z } from 'zod';
|
|
@@ -9,6 +9,43 @@ const COMPONENT = 'component';
|
|
|
9
9
|
const COMPONENT_START = 'componentStart';
|
|
10
10
|
const PAGE_HIDDEN = 'page_hidden';
|
|
11
11
|
|
|
12
|
+
/******************************************************************************
|
|
13
|
+
Copyright (c) Microsoft Corporation.
|
|
14
|
+
|
|
15
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
16
|
+
purpose with or without fee is hereby granted.
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
19
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
20
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
21
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
22
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
23
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
24
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
25
|
+
***************************************************************************** */
|
|
26
|
+
|
|
27
|
+
function __rest(s, e) {
|
|
28
|
+
var t = {};
|
|
29
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
30
|
+
t[p] = s[p];
|
|
31
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
32
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
33
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
34
|
+
t[p[i]] = s[p[i]];
|
|
35
|
+
}
|
|
36
|
+
return t;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
40
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
41
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
42
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
43
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
44
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
45
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
12
49
|
const buildClientLocale = () => navigator.languages && navigator.languages.length ? navigator.languages[0] : navigator.language;
|
|
13
50
|
|
|
14
51
|
const buildClientNinetailedRequestContext = () => ({
|
|
@@ -21,15 +58,15 @@ const buildClientNinetailedRequestContext = () => ({
|
|
|
21
58
|
}
|
|
22
59
|
});
|
|
23
60
|
|
|
24
|
-
/**
|
|
25
|
-
* Similar to _.throttle but waits for the promise to resolve.
|
|
26
|
-
* There is no "wait time" because you can simply await `Promise.timeout` inside `fn` to wait some time before the next call.
|
|
61
|
+
/**
|
|
62
|
+
* Similar to _.throttle but waits for the promise to resolve.
|
|
63
|
+
* There is no "wait time" because you can simply await `Promise.timeout` inside `fn` to wait some time before the next call.
|
|
27
64
|
*/
|
|
28
65
|
function asyncThrottle(fn) {
|
|
29
66
|
let runningPromise;
|
|
30
67
|
let queuedPromise;
|
|
31
68
|
let nextArgs;
|
|
32
|
-
return
|
|
69
|
+
return args => __awaiter(this, void 0, void 0, function* () {
|
|
33
70
|
if (runningPromise) {
|
|
34
71
|
nextArgs = args;
|
|
35
72
|
if (queuedPromise) {
|
|
@@ -46,7 +83,7 @@ function asyncThrottle(fn) {
|
|
|
46
83
|
runningPromise = fn(args);
|
|
47
84
|
return runningPromise;
|
|
48
85
|
}
|
|
49
|
-
};
|
|
86
|
+
});
|
|
50
87
|
}
|
|
51
88
|
|
|
52
89
|
const LEGACY_ANONYMOUS_ID = '__anon_id';
|
|
@@ -73,7 +110,7 @@ const ninetailedCorePlugin = ({
|
|
|
73
110
|
let queue = [];
|
|
74
111
|
let enabledFeatures = Object.values(FEATURES);
|
|
75
112
|
const buildContext = buildClientContext || buildClientNinetailedRequestContext;
|
|
76
|
-
const flush =
|
|
113
|
+
const flush = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
77
114
|
const events = Object.assign([], queue);
|
|
78
115
|
logger.info('Start flushing events.');
|
|
79
116
|
queue = [];
|
|
@@ -87,7 +124,7 @@ const ninetailedCorePlugin = ({
|
|
|
87
124
|
const {
|
|
88
125
|
profile,
|
|
89
126
|
experiences
|
|
90
|
-
} =
|
|
127
|
+
} = yield apiClient.upsertProfile({
|
|
91
128
|
profileId: anonymousId,
|
|
92
129
|
events
|
|
93
130
|
}, {
|
|
@@ -104,7 +141,7 @@ const ninetailedCorePlugin = ({
|
|
|
104
141
|
profile,
|
|
105
142
|
experiences
|
|
106
143
|
});
|
|
107
|
-
|
|
144
|
+
yield delay(20);
|
|
108
145
|
return {
|
|
109
146
|
success: true
|
|
110
147
|
};
|
|
@@ -132,10 +169,10 @@ const ninetailedCorePlugin = ({
|
|
|
132
169
|
success: false
|
|
133
170
|
};
|
|
134
171
|
}
|
|
135
|
-
};
|
|
136
|
-
const enqueueEvent =
|
|
172
|
+
});
|
|
173
|
+
const enqueueEvent = event => __awaiter(void 0, void 0, void 0, function* () {
|
|
137
174
|
queue = unionBy([event], queue, 'messageId');
|
|
138
|
-
};
|
|
175
|
+
});
|
|
139
176
|
const abortNonClientEvents = ({
|
|
140
177
|
abort,
|
|
141
178
|
payload
|
|
@@ -148,15 +185,14 @@ const ninetailedCorePlugin = ({
|
|
|
148
185
|
return {
|
|
149
186
|
name: 'ninetailed',
|
|
150
187
|
config: {},
|
|
151
|
-
initialize:
|
|
188
|
+
initialize: ({
|
|
152
189
|
instance
|
|
153
|
-
}) => {
|
|
190
|
+
}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
154
191
|
_instance = instance;
|
|
155
192
|
if (instance.storage.getItem(DEBUG_FLAG)) {
|
|
156
193
|
logger.addSink(new ConsoleLogSink());
|
|
157
194
|
logger.info('Ninetailed Debug Mode is enabled.');
|
|
158
195
|
}
|
|
159
|
-
|
|
160
196
|
// legacy support for the old anonymousId
|
|
161
197
|
const legacyAnonymousId = instance.storage.getItem(LEGACY_ANONYMOUS_ID);
|
|
162
198
|
if (legacyAnonymousId) {
|
|
@@ -165,7 +201,7 @@ const ninetailedCorePlugin = ({
|
|
|
165
201
|
instance.storage.removeItem(LEGACY_ANONYMOUS_ID);
|
|
166
202
|
}
|
|
167
203
|
if (typeof onInitProfileId === 'function') {
|
|
168
|
-
const profileId =
|
|
204
|
+
const profileId = yield onInitProfileId(instance.storage.getItem(ANONYMOUS_ID));
|
|
169
205
|
if (typeof profileId === 'string') {
|
|
170
206
|
instance.storage.setItem(ANONYMOUS_ID, profileId);
|
|
171
207
|
}
|
|
@@ -176,14 +212,14 @@ const ninetailedCorePlugin = ({
|
|
|
176
212
|
enabledFeatures = payload.features || [];
|
|
177
213
|
});
|
|
178
214
|
logger.debug('Ninetailed Core plugin initialized.');
|
|
179
|
-
},
|
|
215
|
+
}),
|
|
180
216
|
flush: asyncThrottle(flush),
|
|
181
217
|
pageStart: params => {
|
|
182
218
|
return abortNonClientEvents(params);
|
|
183
219
|
},
|
|
184
|
-
page:
|
|
220
|
+
page: ({
|
|
185
221
|
payload
|
|
186
|
-
}) => {
|
|
222
|
+
}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
187
223
|
logger.info('Sending Page event.');
|
|
188
224
|
const ctx = buildContext();
|
|
189
225
|
return enqueueEvent(buildPageEvent({
|
|
@@ -192,13 +228,13 @@ const ninetailedCorePlugin = ({
|
|
|
192
228
|
properties: payload.properties,
|
|
193
229
|
ctx
|
|
194
230
|
}));
|
|
195
|
-
},
|
|
231
|
+
}),
|
|
196
232
|
trackStart: params => {
|
|
197
233
|
return abortNonClientEvents(params);
|
|
198
234
|
},
|
|
199
|
-
track:
|
|
235
|
+
track: ({
|
|
200
236
|
payload
|
|
201
|
-
}) => {
|
|
237
|
+
}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
202
238
|
logger.info('Sending Track event.');
|
|
203
239
|
const ctx = buildContext();
|
|
204
240
|
return enqueueEvent(buildTrackEvent({
|
|
@@ -208,13 +244,13 @@ const ninetailedCorePlugin = ({
|
|
|
208
244
|
properties: payload.properties,
|
|
209
245
|
ctx
|
|
210
246
|
}));
|
|
211
|
-
},
|
|
247
|
+
}),
|
|
212
248
|
identifyStart: params => {
|
|
213
249
|
return abortNonClientEvents(params);
|
|
214
250
|
},
|
|
215
|
-
identify:
|
|
251
|
+
identify: ({
|
|
216
252
|
payload
|
|
217
|
-
}) => {
|
|
253
|
+
}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
218
254
|
logger.info('Sending Identify event.');
|
|
219
255
|
const ctx = buildContext();
|
|
220
256
|
if (payload.userId === EMPTY_MERGE_ID && (!payload.traits || typeof payload.traits === 'object' && Object.keys(payload.traits).length === 0)) {
|
|
@@ -228,7 +264,7 @@ const ninetailedCorePlugin = ({
|
|
|
228
264
|
userId: payload.userId === EMPTY_MERGE_ID ? '' : payload.userId,
|
|
229
265
|
ctx
|
|
230
266
|
}));
|
|
231
|
-
},
|
|
267
|
+
}),
|
|
232
268
|
setItemStart: ({
|
|
233
269
|
abort,
|
|
234
270
|
payload
|
|
@@ -239,7 +275,7 @@ const ninetailedCorePlugin = ({
|
|
|
239
275
|
return payload;
|
|
240
276
|
},
|
|
241
277
|
methods: {
|
|
242
|
-
reset:
|
|
278
|
+
reset: (...args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
243
279
|
logger.debug('Resetting profile.');
|
|
244
280
|
const instance = args[args.length - 1];
|
|
245
281
|
instance.dispatch({
|
|
@@ -250,16 +286,16 @@ const ninetailedCorePlugin = ({
|
|
|
250
286
|
instance.storage.removeItem(EXPERIENCES_FALLBACK_CACHE);
|
|
251
287
|
logger.debug('Removed old profile data from localstorage.');
|
|
252
288
|
if (typeof onInitProfileId === 'function') {
|
|
253
|
-
const profileId =
|
|
289
|
+
const profileId = yield onInitProfileId(undefined);
|
|
254
290
|
if (typeof profileId === 'string') {
|
|
255
291
|
instance.storage.setItem(ANONYMOUS_ID, profileId);
|
|
256
292
|
}
|
|
257
293
|
}
|
|
258
|
-
|
|
294
|
+
yield ninetailed.track('nt_reset');
|
|
259
295
|
logger.info('Profile reset successful.');
|
|
260
|
-
|
|
261
|
-
},
|
|
262
|
-
debug:
|
|
296
|
+
yield delay(10);
|
|
297
|
+
}),
|
|
298
|
+
debug: (...args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
263
299
|
const enabled = args[0];
|
|
264
300
|
const instance = args[args.length - 1];
|
|
265
301
|
const consoleLogSink = new ConsoleLogSink();
|
|
@@ -272,29 +308,13 @@ const ninetailedCorePlugin = ({
|
|
|
272
308
|
logger.info('Debug mode disabled.');
|
|
273
309
|
logger.removeSink(consoleLogSink.name);
|
|
274
310
|
}
|
|
275
|
-
}
|
|
311
|
+
})
|
|
276
312
|
}
|
|
277
313
|
};
|
|
278
314
|
};
|
|
279
315
|
|
|
280
|
-
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
281
|
-
if (source == null) return {};
|
|
282
|
-
var target = {};
|
|
283
|
-
var sourceKeys = Object.keys(source);
|
|
284
|
-
var key, i;
|
|
285
|
-
for (i = 0; i < sourceKeys.length; i++) {
|
|
286
|
-
key = sourceKeys[i];
|
|
287
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
288
|
-
target[key] = source[key];
|
|
289
|
-
}
|
|
290
|
-
return target;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
316
|
class ElementSeenObserver {
|
|
294
317
|
constructor(_options) {
|
|
295
|
-
this._intersectionObserver = void 0;
|
|
296
|
-
this._elementDelays = void 0;
|
|
297
|
-
this._intersectionTimers = void 0;
|
|
298
318
|
this._options = _options;
|
|
299
319
|
this._elementDelays = new WeakMap();
|
|
300
320
|
this._intersectionTimers = new WeakMap();
|
|
@@ -323,13 +343,13 @@ class ElementSeenObserver {
|
|
|
323
343
|
});
|
|
324
344
|
}
|
|
325
345
|
observe(element, options) {
|
|
326
|
-
var
|
|
327
|
-
this._elementDelays.set(element, (
|
|
328
|
-
(
|
|
346
|
+
var _a, _b;
|
|
347
|
+
this._elementDelays.set(element, (_a = options === null || options === void 0 ? void 0 : options.delay) !== null && _a !== void 0 ? _a : 2000);
|
|
348
|
+
(_b = this._intersectionObserver) === null || _b === void 0 ? void 0 : _b.observe(element);
|
|
329
349
|
}
|
|
330
350
|
unobserve(element) {
|
|
331
|
-
var
|
|
332
|
-
(
|
|
351
|
+
var _a;
|
|
352
|
+
(_a = this._intersectionObserver) === null || _a === void 0 ? void 0 : _a.unobserve(element);
|
|
333
353
|
}
|
|
334
354
|
}
|
|
335
355
|
|
|
@@ -341,7 +361,6 @@ const isInterestedInHiddenPage = arg => {
|
|
|
341
361
|
return typeof arg === 'object' && arg !== null && PAGE_HIDDEN in arg && typeof arg[PAGE_HIDDEN] === 'function';
|
|
342
362
|
};
|
|
343
363
|
|
|
344
|
-
const _excluded = ["element"];
|
|
345
364
|
class Ninetailed {
|
|
346
365
|
constructor(ninetailedApiClientInstanceOrOptions, {
|
|
347
366
|
plugins,
|
|
@@ -355,28 +374,16 @@ class Ninetailed {
|
|
|
355
374
|
componentViewTrackingThreshold = 2000,
|
|
356
375
|
storageImpl
|
|
357
376
|
} = {}) {
|
|
358
|
-
var _this = this;
|
|
359
|
-
this.instance = void 0;
|
|
360
|
-
this._profileState = void 0;
|
|
361
377
|
this.isInitialized = false;
|
|
362
|
-
this.
|
|
363
|
-
this.ninetailedCorePlugin = void 0;
|
|
364
|
-
this.elementSeenObserver = void 0;
|
|
365
|
-
this.observedElements = void 0;
|
|
366
|
-
this.clientId = void 0;
|
|
367
|
-
this.environment = void 0;
|
|
368
|
-
this.plugins = void 0;
|
|
369
|
-
this.logger = void 0;
|
|
370
|
-
this.componentViewTrackingThreshold = void 0;
|
|
371
|
-
this.page = async function (data, options) {
|
|
378
|
+
this.page = (data, options) => __awaiter(this, void 0, void 0, function* () {
|
|
372
379
|
try {
|
|
373
380
|
const result = PageviewProperties.partial().default({}).safeParse(data);
|
|
374
381
|
if (!result.success) {
|
|
375
382
|
throw new Error(`[Validation Error] "page" was called with invalid params. Page data is not valid: ${result.error.format()}`);
|
|
376
383
|
}
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
return
|
|
384
|
+
yield this.waitUntilInitialized();
|
|
385
|
+
yield this.instance.page(data, this.buildOptions(options));
|
|
386
|
+
return this.ninetailedCorePlugin.flush();
|
|
380
387
|
} catch (error) {
|
|
381
388
|
logger.error(error);
|
|
382
389
|
if (error instanceof RangeError) {
|
|
@@ -384,16 +391,16 @@ class Ninetailed {
|
|
|
384
391
|
}
|
|
385
392
|
throw error;
|
|
386
393
|
}
|
|
387
|
-
};
|
|
388
|
-
this.track =
|
|
394
|
+
});
|
|
395
|
+
this.track = (event, properties, options) => __awaiter(this, void 0, void 0, function* () {
|
|
389
396
|
try {
|
|
390
397
|
const result = Properties.default({}).safeParse(properties);
|
|
391
398
|
if (!result.success) {
|
|
392
399
|
throw new Error(`[Validation Error] "track" was called with invalid params. Properties are no valid json object: ${result.error.format()}`);
|
|
393
400
|
}
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
return
|
|
401
|
+
yield this.waitUntilInitialized();
|
|
402
|
+
yield this.instance.track(event.toString(), result.data, this.buildOptions(options));
|
|
403
|
+
return this.ninetailedCorePlugin.flush();
|
|
397
404
|
} catch (error) {
|
|
398
405
|
logger.error(error);
|
|
399
406
|
if (error instanceof RangeError) {
|
|
@@ -401,18 +408,18 @@ class Ninetailed {
|
|
|
401
408
|
}
|
|
402
409
|
throw error;
|
|
403
410
|
}
|
|
404
|
-
};
|
|
405
|
-
/**
|
|
406
|
-
* @deprecated The legacy datamodel is not recommended anymore
|
|
407
|
-
* Will be removed in the next version of the SDK
|
|
411
|
+
});
|
|
412
|
+
/**
|
|
413
|
+
* @deprecated The legacy datamodel is not recommended anymore
|
|
414
|
+
* Will be removed in the next version of the SDK
|
|
408
415
|
*/
|
|
409
|
-
this.trackHasSeenComponent =
|
|
410
|
-
return
|
|
416
|
+
this.trackHasSeenComponent = properties => __awaiter(this, void 0, void 0, function* () {
|
|
417
|
+
return this.instance.dispatch(Object.assign(Object.assign({}, properties), {
|
|
411
418
|
type: HAS_SEEN_COMPONENT
|
|
412
419
|
}));
|
|
413
|
-
};
|
|
420
|
+
});
|
|
414
421
|
this.trackComponentView = properties => {
|
|
415
|
-
return this.instance.dispatch(Object.assign({}, properties, {
|
|
422
|
+
return this.instance.dispatch(Object.assign(Object.assign({}, properties), {
|
|
416
423
|
type: HAS_SEEN_ELEMENT
|
|
417
424
|
}));
|
|
418
425
|
};
|
|
@@ -420,7 +427,7 @@ class Ninetailed {
|
|
|
420
427
|
const {
|
|
421
428
|
element
|
|
422
429
|
} = payload,
|
|
423
|
-
remaingPayload =
|
|
430
|
+
remaingPayload = __rest(payload, ["element"]);
|
|
424
431
|
if (!(element instanceof Element)) {
|
|
425
432
|
const isObject = typeof element === 'object' && element !== null;
|
|
426
433
|
const constructorName = isObject ? element.constructor.name : '';
|
|
@@ -445,15 +452,15 @@ class Ninetailed {
|
|
|
445
452
|
}, payload));
|
|
446
453
|
}
|
|
447
454
|
};
|
|
448
|
-
this.identify =
|
|
455
|
+
this.identify = (uid, traits, options) => __awaiter(this, void 0, void 0, function* () {
|
|
449
456
|
try {
|
|
450
457
|
const result = Traits.default({}).safeParse(traits);
|
|
451
458
|
if (!result.success) {
|
|
452
459
|
throw new Error(`[Validation Error] "identify" was called with invalid params. Traits are no valid json: ${result.error.format()}`);
|
|
453
460
|
}
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
return
|
|
461
|
+
yield this.waitUntilInitialized();
|
|
462
|
+
yield this.instance.identify(uid && uid.toString() !== '' ? uid.toString() : EMPTY_MERGE_ID, result.data, this.buildOptions(options));
|
|
463
|
+
return this.ninetailedCorePlugin.flush();
|
|
457
464
|
} catch (error) {
|
|
458
465
|
logger.error(error);
|
|
459
466
|
if (error instanceof RangeError) {
|
|
@@ -461,33 +468,33 @@ class Ninetailed {
|
|
|
461
468
|
}
|
|
462
469
|
throw error;
|
|
463
470
|
}
|
|
464
|
-
};
|
|
465
|
-
this.reset =
|
|
466
|
-
|
|
471
|
+
});
|
|
472
|
+
this.reset = () => __awaiter(this, void 0, void 0, function* () {
|
|
473
|
+
yield this.waitUntilInitialized();
|
|
467
474
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
468
475
|
// @ts-ignore
|
|
469
|
-
|
|
470
|
-
};
|
|
471
|
-
this.debug =
|
|
472
|
-
|
|
476
|
+
this.instance.plugins[PLUGIN_NAME].reset();
|
|
477
|
+
});
|
|
478
|
+
this.debug = enabled => __awaiter(this, void 0, void 0, function* () {
|
|
479
|
+
yield this.waitUntilInitialized();
|
|
473
480
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
474
481
|
// @ts-ignore
|
|
475
|
-
|
|
476
|
-
};
|
|
482
|
+
this.instance.plugins[PLUGIN_NAME].debug(enabled);
|
|
483
|
+
});
|
|
477
484
|
this.onProfileChange = cb => {
|
|
478
485
|
cb(this.profileState);
|
|
479
486
|
return this.instance.on(PROFILE_CHANGE, ({
|
|
480
487
|
payload
|
|
481
488
|
}) => {
|
|
482
489
|
if (payload.error) {
|
|
483
|
-
cb(Object.assign({}, this._profileState, {
|
|
490
|
+
cb(Object.assign(Object.assign({}, this._profileState), {
|
|
484
491
|
status: 'error',
|
|
485
492
|
profile: payload.profile,
|
|
486
493
|
experiences: payload.experiences,
|
|
487
494
|
error: payload.error
|
|
488
495
|
}));
|
|
489
496
|
} else {
|
|
490
|
-
cb(Object.assign({}, this._profileState, {
|
|
497
|
+
cb(Object.assign(Object.assign({}, this._profileState), {
|
|
491
498
|
status: 'success',
|
|
492
499
|
profile: payload.profile,
|
|
493
500
|
experiences: payload.experiences,
|
|
@@ -543,7 +550,7 @@ class Ninetailed {
|
|
|
543
550
|
preview
|
|
544
551
|
});
|
|
545
552
|
}
|
|
546
|
-
this.plugins = (plugins
|
|
553
|
+
this.plugins = (plugins !== null && plugins !== void 0 ? plugins : []).flat();
|
|
547
554
|
this.plugins.forEach(plugin => {
|
|
548
555
|
if (acceptsCredentials(plugin) && this.clientId && this.environment) {
|
|
549
556
|
plugin.setCredentials({
|
|
@@ -580,12 +587,11 @@ class Ninetailed {
|
|
|
580
587
|
}, storageImpl ? {
|
|
581
588
|
storage: storageImpl
|
|
582
589
|
} : {}));
|
|
583
|
-
const
|
|
590
|
+
const detachOnReadyListener = this.instance.on('ready', () => {
|
|
584
591
|
this.isInitialized = true;
|
|
585
592
|
logger.info('Ninetailed Experience.js SDK is completely initialized.');
|
|
586
|
-
|
|
593
|
+
detachOnReadyListener();
|
|
587
594
|
});
|
|
588
|
-
|
|
589
595
|
// put in private method
|
|
590
596
|
this.onProfileChange(profileState => {
|
|
591
597
|
this._profileState = profileState;
|
|
@@ -637,7 +643,7 @@ const selectVariant = (baseline, variants, {
|
|
|
637
643
|
if (status === 'loading') {
|
|
638
644
|
return {
|
|
639
645
|
loading: true,
|
|
640
|
-
variant: Object.assign({}, baseline, {
|
|
646
|
+
variant: Object.assign(Object.assign({}, baseline), {
|
|
641
647
|
id: 'baseline',
|
|
642
648
|
audience: {
|
|
643
649
|
id: 'baseline'
|
|
@@ -653,7 +659,7 @@ const selectVariant = (baseline, variants, {
|
|
|
653
659
|
if (status === 'error') {
|
|
654
660
|
return {
|
|
655
661
|
loading: false,
|
|
656
|
-
variant: Object.assign({}, baseline, {
|
|
662
|
+
variant: Object.assign(Object.assign({}, baseline), {
|
|
657
663
|
id: 'baseline',
|
|
658
664
|
audience: {
|
|
659
665
|
id: 'baseline'
|
|
@@ -667,19 +673,19 @@ const selectVariant = (baseline, variants, {
|
|
|
667
673
|
};
|
|
668
674
|
}
|
|
669
675
|
const variant = variants.find(variant => {
|
|
670
|
-
var
|
|
671
|
-
return profile
|
|
676
|
+
var _a, _b;
|
|
677
|
+
return (_a = profile === null || profile === void 0 ? void 0 : profile.audiences) === null || _a === void 0 ? void 0 : _a.includes((_b = variant.audience) === null || _b === void 0 ? void 0 : _b.id);
|
|
672
678
|
});
|
|
673
679
|
if (variant) {
|
|
674
|
-
if (options
|
|
680
|
+
if ((options === null || options === void 0 ? void 0 : options.holdout) || -1 > ((profile === null || profile === void 0 ? void 0 : profile.random) || 0)) {
|
|
675
681
|
return {
|
|
676
682
|
loading: false,
|
|
677
|
-
variant: Object.assign({}, baseline, {
|
|
683
|
+
variant: Object.assign(Object.assign({}, baseline), {
|
|
678
684
|
audience: {
|
|
679
685
|
id: 'baseline'
|
|
680
686
|
}
|
|
681
687
|
}),
|
|
682
|
-
audience: Object.assign({}, variant.audience, {
|
|
688
|
+
audience: Object.assign(Object.assign({}, variant.audience), {
|
|
683
689
|
id: variant.audience.id
|
|
684
690
|
}),
|
|
685
691
|
isPersonalized: false,
|
|
@@ -689,20 +695,19 @@ const selectVariant = (baseline, variants, {
|
|
|
689
695
|
return {
|
|
690
696
|
loading: false,
|
|
691
697
|
variant,
|
|
692
|
-
audience: Object.assign({}, variant.audience, {
|
|
698
|
+
audience: Object.assign(Object.assign({}, variant.audience), {
|
|
693
699
|
id: variant.audience.id
|
|
694
700
|
}),
|
|
695
701
|
isPersonalized: true,
|
|
696
702
|
error: null
|
|
697
703
|
};
|
|
698
704
|
}
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
* There was no matching audience found.
|
|
705
|
+
/**
|
|
706
|
+
* There was no matching audience found.
|
|
702
707
|
*/
|
|
703
708
|
return {
|
|
704
709
|
loading: false,
|
|
705
|
-
variant: Object.assign({}, baseline, {
|
|
710
|
+
variant: Object.assign(Object.assign({}, baseline), {
|
|
706
711
|
id: 'baseline',
|
|
707
712
|
audience: {
|
|
708
713
|
id: 'baseline'
|
|
@@ -762,7 +767,7 @@ const decodeExperienceVariantsMap = encodedExperienceVariantsMap => {
|
|
|
762
767
|
experienceId,
|
|
763
768
|
variantIndex
|
|
764
769
|
};
|
|
765
|
-
}).filter(x => !!x).reduce((acc, curr) => Object.assign({}, acc, {
|
|
770
|
+
}).filter(x => !!x).reduce((acc, curr) => Object.assign(Object.assign({}, acc), {
|
|
766
771
|
[curr.experienceId]: curr.variantIndex
|
|
767
772
|
}), {});
|
|
768
773
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ninetailed/experience.js",
|
|
3
|
-
"version": "7.5.3-beta.
|
|
3
|
+
"version": "7.5.3-beta.4",
|
|
4
4
|
"description": "Ninetailed SDK for javascript",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -8,11 +8,14 @@
|
|
|
8
8
|
"url": "https://github.com/ninetailed-inc/experience.js.git",
|
|
9
9
|
"directory": "packages/sdks/javascript"
|
|
10
10
|
},
|
|
11
|
+
"module": "./index.js",
|
|
12
|
+
"main": "./index.cjs",
|
|
13
|
+
"type": "module",
|
|
14
|
+
"types": "./src/index.d.ts",
|
|
11
15
|
"dependencies": {
|
|
16
|
+
"@ninetailed/experience.js-shared": "7.5.3-beta.4",
|
|
12
17
|
"analytics": "0.8.1",
|
|
13
|
-
"zod": "3.21.4"
|
|
14
|
-
"@ninetailed/experience.js-shared": "*"
|
|
18
|
+
"zod": "3.21.4"
|
|
15
19
|
},
|
|
16
|
-
"
|
|
17
|
-
"main": "./index.cjs.js"
|
|
20
|
+
"peerDependencies": {}
|
|
18
21
|
}
|
package/index.cjs.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src/index";
|
|
File without changes
|