@sprig-technologies/sprig-browser 2.14.2 → 2.14.5
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/controller/controller.d.ts +13 -0
- package/controller/controller.d.ts.map +1 -0
- package/controller/controller.js +34 -32
- package/controller/encodedViewJs.d.ts +2 -0
- package/controller/encodedViewJs.d.ts.map +1 -0
- package/controller/encodedViewJs.js +1 -1
- package/controller/iframe.d.ts +9 -0
- package/controller/iframe.d.ts.map +1 -0
- package/controller/queue.d.ts +18 -0
- package/controller/queue.d.ts.map +1 -0
- package/controller/queue.js +1 -2
- package/index.d.ts +127 -0
- package/index.d.ts.map +1 -0
- package/index.js +2 -1
- package/package.json +1 -1
- package/shared/conflicting_widgets/index.d.ts +5 -0
- package/shared/conflicting_widgets/index.d.ts.map +1 -0
- package/shared/conflicting_widgets/intercom.d.ts +3 -0
- package/shared/conflicting_widgets/intercom.d.ts.map +1 -0
- package/shared/constants.d.ts +47 -0
- package/shared/constants.d.ts.map +1 -0
- package/shared/deferred.d.ts +10 -0
- package/shared/deferred.d.ts.map +1 -0
- package/shared/eventEmitter.d.ts +10 -0
- package/shared/eventEmitter.d.ts.map +1 -0
- package/shared/network.d.ts +8 -0
- package/shared/network.d.ts.map +1 -0
- package/shared/network.js +2 -2
- package/shared/networkHelper.d.ts +5 -0
- package/shared/networkHelper.d.ts.map +1 -0
- package/shared/shouldDirectEmbed.d.ts +7 -0
- package/shared/shouldDirectEmbed.d.ts.map +1 -0
- package/shared/tool.d.ts +3 -0
- package/shared/tool.d.ts.map +1 -0
- package/shared/ulEvents.d.ts +33 -0
- package/shared/ulEvents.d.ts.map +1 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Initialize frame and bootstrap data
|
|
3
|
+
* @param {Object} config this is included in the compilation step (points to the default viewSDKURL)
|
|
4
|
+
* @param {String} config.envId Environment Id
|
|
5
|
+
* @param {String} config.path Frame script url
|
|
6
|
+
* @param {String} [config.border] Border color
|
|
7
|
+
*/
|
|
8
|
+
export default function sprigInitializer(config?: {
|
|
9
|
+
envId: string;
|
|
10
|
+
path: string;
|
|
11
|
+
border?: string;
|
|
12
|
+
}): void;
|
|
13
|
+
//# sourceMappingURL=controller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../../sprig-browser/controller/controller.js"],"names":[],"mappings":"AA68BA;;;;;;GAMG;AACH;IAJ0B,KAAK;IACL,IAAI;IACH,MAAM;SAkFhC"}
|
package/controller/controller.js
CHANGED
|
@@ -7,7 +7,7 @@ import ConflictingWidgets from '../shared/conflicting_widgets';
|
|
|
7
7
|
import { APP_MODES, CSS_CONSTANTS } from '../shared/constants';
|
|
8
8
|
import { ulFetch, killNetworkRequests, getHttpHeaders } from '../shared/network';
|
|
9
9
|
import { createFrame, createContainer, removeContainerOnClose, removeContainer } from '../controller/iframe';
|
|
10
|
-
import './queue';
|
|
10
|
+
import { UserLeapQueue } from './queue';
|
|
11
11
|
import eventEmitter from '../shared/eventEmitter';
|
|
12
12
|
import { ulEvents, DISMISS_REASONS, SURVEY_STATE, internalEvents } from '../shared/ulEvents';
|
|
13
13
|
import { calculateFrameHeight, overrideStyles } from '../shared/tool';
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
MOBILE_PLATFORM_HEADERS,
|
|
21
21
|
INSTALLATION_METHOD,
|
|
22
22
|
} from '../shared/constants';
|
|
23
|
+
import { encodedViewJs } from './encodedViewJs';
|
|
23
24
|
|
|
24
25
|
const credentialsStorageKey = 'userleap.ids';
|
|
25
26
|
const pageViewsStorageKey = 'userleap.pageviews';
|
|
@@ -66,7 +67,7 @@ function shouldDisplaySurveyAfterDelay(triggeringEventId, trackStartUrl) {
|
|
|
66
67
|
function locationChangeHandler(event) {
|
|
67
68
|
const { pageUrlEvents, interactiveEvents, dismissOnPageChange, platform } = UserLeap._config;
|
|
68
69
|
if (platform && platform !== 'web') return; // we should clean this up during web sdk controller refactor along with the should direct embed
|
|
69
|
-
if (pageUrlEvents)
|
|
70
|
+
if (pageUrlEvents) trackPageView(window.location.href);
|
|
70
71
|
if (interactiveEvents) {
|
|
71
72
|
// need to remove old listeners bc current page may not be targeted
|
|
72
73
|
removeInteractiveEventListener();
|
|
@@ -117,7 +118,7 @@ function apiUrl(version, fillPaths, trailing) {
|
|
|
117
118
|
fillPaths.forEach((p) => {
|
|
118
119
|
components.push(p);
|
|
119
120
|
if (p === PATH_ENV) components.push(UserLeap.envId);
|
|
120
|
-
else if (p === PATH_VISITOR) components.push(
|
|
121
|
+
else if (p === PATH_VISITOR) components.push(widgetGetVID());
|
|
121
122
|
});
|
|
122
123
|
}
|
|
123
124
|
if (trailing) components.push(trailing);
|
|
@@ -209,13 +210,11 @@ function generateVisitorId() {
|
|
|
209
210
|
eventEmitter.emit(ulEvents.VISITOR_ID_UPDATED, { visitorId: UserLeap.visitorId });
|
|
210
211
|
}
|
|
211
212
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
UserLeap.widgetGetVID = function() {
|
|
213
|
+
function widgetGetVID() {
|
|
215
214
|
return window.previewMode ? 0 : UserLeap.visitorId;
|
|
216
|
-
}
|
|
215
|
+
}
|
|
217
216
|
|
|
218
|
-
|
|
217
|
+
function trackPageView(location) {
|
|
219
218
|
if (!UserLeap.localStorageAvailable) return;
|
|
220
219
|
if (location.endsWith('mock_snippet.html')) {
|
|
221
220
|
return;
|
|
@@ -283,7 +282,7 @@ UserLeap.trackPageView = function(location) {
|
|
|
283
282
|
console.warn(`[Sprig] (ERR-425) Failed to update page views in local storage`);
|
|
284
283
|
UserLeap.reportError('trackPageView', err);
|
|
285
284
|
}
|
|
286
|
-
}
|
|
285
|
+
}
|
|
287
286
|
|
|
288
287
|
function bindTrackingEvents() {
|
|
289
288
|
const historyRef = 'Backbone' in window && window.Backbone && Backbone.history ? Backbone.history : window.history;
|
|
@@ -308,8 +307,8 @@ function bindTrackingEvents() {
|
|
|
308
307
|
registerEventListeners();
|
|
309
308
|
}
|
|
310
309
|
|
|
311
|
-
|
|
312
|
-
const visitorId =
|
|
310
|
+
async function getQuestions(options, submitAnswers) {
|
|
311
|
+
const visitorId = widgetGetVID();
|
|
313
312
|
if (options && !submitAnswers) {
|
|
314
313
|
UserLeap._config.mode = APP_MODES.test;
|
|
315
314
|
}
|
|
@@ -322,10 +321,10 @@ UserLeap.getQuestions = async function(options, submitAnswers) {
|
|
|
322
321
|
return { success: false, surveyState: SURVEY_STATE.NO_SURVEY };
|
|
323
322
|
}
|
|
324
323
|
response.json.delay && (await delay(response.json.delay));
|
|
325
|
-
return
|
|
326
|
-
}
|
|
324
|
+
return displayQuestions(response.json);
|
|
325
|
+
}
|
|
327
326
|
|
|
328
|
-
|
|
327
|
+
function displayQuestions(responseJson) {
|
|
329
328
|
const { vid, uuid, questions, surveyId, context, locale, responseGroupUid, endCard, productConfig } = responseJson;
|
|
330
329
|
const experimentFlags = responseJson.experimentFlags || {};
|
|
331
330
|
const headers = getHttpHeaders(UserLeap);
|
|
@@ -435,8 +434,7 @@ UserLeap.displayQuestions = function(responseJson) {
|
|
|
435
434
|
}
|
|
436
435
|
|
|
437
436
|
if (config.installationMethod === INSTALLATION_METHOD.NPM) {
|
|
438
|
-
|
|
439
|
-
frameScript.textContent = atob(encodedViewJs.default);
|
|
437
|
+
frameScript.textContent = atob(encodedViewJs);
|
|
440
438
|
} else {
|
|
441
439
|
frameScript.src = frameSrc;
|
|
442
440
|
contentWindow.addEventListener(
|
|
@@ -454,7 +452,7 @@ UserLeap.displayQuestions = function(responseJson) {
|
|
|
454
452
|
}
|
|
455
453
|
contentWinDocHead.appendChild(frameScript);
|
|
456
454
|
return { success: true, surveyState: SURVEY_STATE.READY };
|
|
457
|
-
}
|
|
455
|
+
}
|
|
458
456
|
|
|
459
457
|
function calculateUseMobileStyling(headers) {
|
|
460
458
|
if (UserLeap.useMobileStyling !== undefined) return UserLeap.useMobileStyling;
|
|
@@ -486,9 +484,10 @@ function shuffleInteractiveEvents(events) {
|
|
|
486
484
|
* Gather identifier data, retrieve questions, and render widget
|
|
487
485
|
* @param {Object} config [description]
|
|
488
486
|
*/
|
|
489
|
-
|
|
487
|
+
function widgetInitialize(config) {
|
|
490
488
|
if (!config) return;
|
|
491
489
|
UserLeap._config = config;
|
|
490
|
+
|
|
492
491
|
if (config.mute) {
|
|
493
492
|
// Userleap.mute isn't defined yet
|
|
494
493
|
UserLeap._queue.pause();
|
|
@@ -501,7 +500,7 @@ UserLeap.widgetInitialize = function(config) {
|
|
|
501
500
|
bindTrackingEvents();
|
|
502
501
|
locationChangeHandler();
|
|
503
502
|
}
|
|
504
|
-
}
|
|
503
|
+
}
|
|
505
504
|
|
|
506
505
|
async function authenticatedFetch(url, options, attempt = 0, shouldDropOnRateLimit = false) {
|
|
507
506
|
options.headers = Object.assign(getHttpHeaders(UserLeap), options.headers);
|
|
@@ -588,7 +587,7 @@ const __enableUserLeapAPIActions = function(config) {
|
|
|
588
587
|
const responseBody = result.json;
|
|
589
588
|
responseBody.delay && (await delay(responseBody.delay));
|
|
590
589
|
if (shouldDisplaySurveyAfterDelay(responseBody.eventId, trackStartUrl)) {
|
|
591
|
-
return
|
|
590
|
+
return displayQuestions(responseBody);
|
|
592
591
|
} else {
|
|
593
592
|
return {
|
|
594
593
|
success: false,
|
|
@@ -602,17 +601,17 @@ const __enableUserLeapAPIActions = function(config) {
|
|
|
602
601
|
// Triggers displaying specified survey. Does submit answers!
|
|
603
602
|
async displaySurvey(surveyId) {
|
|
604
603
|
UserLeap('dismissActiveSurvey', DISMISS_REASONS.OVERRIDE);
|
|
605
|
-
return
|
|
604
|
+
return getQuestions({ surveyId }, true);
|
|
606
605
|
},
|
|
607
606
|
// Triggers displaying specified survey template. Does not submit answers
|
|
608
607
|
previewSurvey(surveyTemplateId) {
|
|
609
608
|
UserLeap('dismissActiveSurvey', DISMISS_REASONS.OVERRIDE);
|
|
610
|
-
|
|
609
|
+
getQuestions({ surveyTemplateId }, false);
|
|
611
610
|
},
|
|
612
611
|
// Triggers displaying specified survey. Does not submit answers
|
|
613
612
|
reviewSurvey(surveyId) {
|
|
614
613
|
UserLeap('dismissActiveSurvey', DISMISS_REASONS.OVERRIDE);
|
|
615
|
-
|
|
614
|
+
getQuestions({ surveyId }, false);
|
|
616
615
|
},
|
|
617
616
|
mute() {
|
|
618
617
|
UserLeap._queue.pause();
|
|
@@ -885,7 +884,7 @@ const __enableUserLeapAPIActions = function(config) {
|
|
|
885
884
|
* Pulls down presentation config settings from server and
|
|
886
885
|
* applies them to supplied config dict
|
|
887
886
|
*/
|
|
888
|
-
|
|
887
|
+
async function applyRemoteConfig(config) {
|
|
889
888
|
const headers = UserLeap.mobileHeadersJSON ? JSON.parse(UserLeap.mobileHeadersJSON) : {};
|
|
890
889
|
let response = await ulFetch(apiUrl(1, [PATH_ENV], 'config'), { headers });
|
|
891
890
|
|
|
@@ -914,10 +913,10 @@ UserLeap.applyRemoteConfig = async function(config) {
|
|
|
914
913
|
return newConfig;
|
|
915
914
|
};
|
|
916
915
|
|
|
917
|
-
|
|
916
|
+
async function reportError(action, err) {
|
|
918
917
|
const mode = window.__cfg && window.__cfg.mode;
|
|
919
918
|
const fetchFreshIfNotSet = false;
|
|
920
|
-
const vid =
|
|
919
|
+
const vid = widgetGetVID(fetchFreshIfNotSet);
|
|
921
920
|
const envId = UserLeap.envId;
|
|
922
921
|
const pde = window.document.documentElement;
|
|
923
922
|
const meta = {
|
|
@@ -949,9 +948,9 @@ UserLeap.reportError = async function(action, err) {
|
|
|
949
948
|
if (!result.ok) {
|
|
950
949
|
console.warn(`[Sprig] (ERR-444) Failed to report error to API`, err);
|
|
951
950
|
}
|
|
952
|
-
}
|
|
951
|
+
}
|
|
953
952
|
|
|
954
|
-
|
|
953
|
+
function logoutUser() {
|
|
955
954
|
if (UserLeap.debugMode) console.log('[DEBUG] Sprig logout');
|
|
956
955
|
//clear in-memory
|
|
957
956
|
UserLeap.visitorId = null;
|
|
@@ -970,7 +969,7 @@ UserLeap.logoutUser = function() {
|
|
|
970
969
|
if (UserLeap._queue.isPaused()) UserLeap._queue.empty();
|
|
971
970
|
generateVisitorId();
|
|
972
971
|
UserLeap._queue.unpause();
|
|
973
|
-
}
|
|
972
|
+
}
|
|
974
973
|
|
|
975
974
|
/**
|
|
976
975
|
* Initialize frame and bootstrap data
|
|
@@ -982,6 +981,9 @@ UserLeap.logoutUser = function() {
|
|
|
982
981
|
export default function sprigInitializer(config = {}) {
|
|
983
982
|
async function load() {
|
|
984
983
|
if (UserLeap.loaded) return;
|
|
984
|
+
UserLeap.UPDATES = ulEvents;
|
|
985
|
+
UserLeap.reportError = reportError;
|
|
986
|
+
UserLeap.logoutUser = logoutUser;
|
|
985
987
|
UserLeap.loaded = true;
|
|
986
988
|
//combine compile-provided config and installation-snippet config
|
|
987
989
|
UserLeap._config = Object.assign({}, config, UserLeap.config);
|
|
@@ -1026,7 +1028,7 @@ export default function sprigInitializer(config = {}) {
|
|
|
1026
1028
|
//Note: UserLeap._queue is an array at this point (defined in installation snippet)
|
|
1027
1029
|
const queueItems = [...UserLeap._queue];
|
|
1028
1030
|
//converts [] -> Queue()
|
|
1029
|
-
UserLeap._queue = new
|
|
1031
|
+
UserLeap._queue = new UserLeapQueue(UserLeap, []);
|
|
1030
1032
|
UserLeap._queue.pause();
|
|
1031
1033
|
for (let i = 0; i < queueItems.length; i++) {
|
|
1032
1034
|
UserLeap._queue.push(queueItems[i]);
|
|
@@ -1042,9 +1044,9 @@ export default function sprigInitializer(config = {}) {
|
|
|
1042
1044
|
if (UserLeap.localStorageAvailable) localStorage.removeItem(credentialsStorageKey);
|
|
1043
1045
|
generateVisitorId();
|
|
1044
1046
|
}
|
|
1045
|
-
const remoteConfig = await
|
|
1047
|
+
const remoteConfig = await applyRemoteConfig(config);
|
|
1046
1048
|
__enableUserLeapAPIActions(remoteConfig);
|
|
1047
|
-
await
|
|
1049
|
+
await widgetInitialize(remoteConfig);
|
|
1048
1050
|
UserLeap._queue.unpause();
|
|
1049
1051
|
eventEmitter.emit(ulEvents.SDK_READY);
|
|
1050
1052
|
eventEmitter.emit(ulEvents.VISITOR_ID_UPDATED, { visitorId: UserLeap.visitorId });
|