@sprig-technologies/sprig-browser 2.14.8 → 2.15.1
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.d.ts +30 -7
- package/index.js +697 -181
- package/package.json +1 -1
- package/LICENSE +0 -22
- package/controller/controller.d.ts +0 -13
- package/controller/controller.d.ts.map +0 -1
- package/controller/controller.js +0 -1061
- package/controller/encodedViewJs.d.ts +0 -3
- package/controller/encodedViewJs.d.ts.map +0 -1
- package/controller/encodedViewJs.js +0 -1
- package/controller/iframe.d.ts +0 -9
- package/controller/iframe.d.ts.map +0 -1
- package/controller/iframe.js +0 -184
- package/controller/index.js +0 -3
- package/controller/queue.d.ts +0 -2
- package/controller/queue.d.ts.map +0 -1
- package/controller/queue.js +0 -95
- package/index.d.ts.map +0 -1
- package/shared/conflicting_widgets/index.d.ts +0 -5
- package/shared/conflicting_widgets/index.d.ts.map +0 -1
- package/shared/conflicting_widgets/index.js +0 -13
- package/shared/conflicting_widgets/intercom.d.ts +0 -3
- package/shared/conflicting_widgets/intercom.d.ts.map +0 -1
- package/shared/conflicting_widgets/intercom.js +0 -28
- package/shared/constants.d.ts +0 -49
- package/shared/constants.d.ts.map +0 -1
- package/shared/constants.js +0 -65
- package/shared/deferred.d.ts +0 -10
- package/shared/deferred.d.ts.map +0 -1
- package/shared/deferred.js +0 -15
- package/shared/eventEmitter.d.ts +0 -10
- package/shared/eventEmitter.d.ts.map +0 -1
- package/shared/eventEmitter.js +0 -52
- package/shared/network.d.ts +0 -8
- package/shared/network.d.ts.map +0 -1
- package/shared/network.js +0 -130
- package/shared/networkHelper.d.ts +0 -5
- package/shared/networkHelper.d.ts.map +0 -1
- package/shared/networkHelper.js +0 -9
- package/shared/shouldDirectEmbed.d.ts +0 -7
- package/shared/shouldDirectEmbed.d.ts.map +0 -1
- package/shared/shouldDirectEmbed.js +0 -8
- package/shared/tool.d.ts +0 -3
- package/shared/tool.d.ts.map +0 -1
- package/shared/tool.js +0 -19
- package/shared/ulEvents.d.ts +0 -33
- package/shared/ulEvents.d.ts.map +0 -1
- package/shared/ulEvents.js +0 -45
package/shared/network.js
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
/*global fetch */
|
|
2
|
-
import 'whatwg-fetch';
|
|
3
|
-
import { HEADERS, INSTALLATION_METHOD } from './constants';
|
|
4
|
-
import Deferred from './deferred';
|
|
5
|
-
import { delay, NETWORK_CONFIG } from './networkHelper';
|
|
6
|
-
|
|
7
|
-
let killswitch = false;
|
|
8
|
-
let killswitchReason = '';
|
|
9
|
-
let isRateLimited = false;
|
|
10
|
-
let pendingRequestQueue = [];
|
|
11
|
-
|
|
12
|
-
function getInstallationMethodHeader(Sprig) {
|
|
13
|
-
if (Sprig._config && Sprig._config.installationMethod) return Sprig._config.installationMethod;
|
|
14
|
-
if (Sprig._gtm) return INSTALLATION_METHOD.GTM;
|
|
15
|
-
if (Sprig._segment) return INSTALLATION_METHOD.SEGMENT;
|
|
16
|
-
return INSTALLATION_METHOD.SNIPPET;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function killNetworkRequests(reason) {
|
|
20
|
-
killswitch = true;
|
|
21
|
-
killswitchReason = reason;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function getHttpHeaders(Sprig = {}) {
|
|
25
|
-
const headers = {
|
|
26
|
-
'Content-Type': 'application/json',
|
|
27
|
-
'userleap-platform': 'web',
|
|
28
|
-
'x-ul-sdk-version': '2.14.8', //version here doesn't matter. it is string-replaced when compiled
|
|
29
|
-
};
|
|
30
|
-
if (Sprig.envId) headers[HEADERS.ENVIRONMENT_ID] = Sprig.envId;
|
|
31
|
-
if (Sprig.token) headers['Authorization'] = 'Bearer ' + Sprig.token;
|
|
32
|
-
if (Sprig.userId) headers[HEADERS.USER_ID] = Sprig.userId;
|
|
33
|
-
if (Sprig.visitorId) headers[HEADERS.VISITOR_ID] = Sprig.visitorId;
|
|
34
|
-
if (Sprig.partnerAnonymousId) headers[HEADERS.PARTNER_ANONYMOUS_ID] = Sprig.partnerAnonymousId;
|
|
35
|
-
if (Sprig.mobileHeadersJSON) {
|
|
36
|
-
const mobileHeaders = JSON.parse(Sprig.mobileHeadersJSON);
|
|
37
|
-
Object.assign(headers, mobileHeaders);
|
|
38
|
-
}
|
|
39
|
-
headers[HEADERS.INSTALLATION_METHOD] = getInstallationMethodHeader(Sprig);
|
|
40
|
-
if (Sprig.locale) headers['accept-language'] = Sprig.locale; // custom set locale overrides original header locales
|
|
41
|
-
|
|
42
|
-
return headers;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
async function dropOrQueueRequest(shouldDropOnRateLimit, isRateLimitRetry, requestInfo) {
|
|
46
|
-
if (shouldDropOnRateLimit) {
|
|
47
|
-
return { status: 429 };
|
|
48
|
-
} else {
|
|
49
|
-
const deferredRequest = new Deferred(requestInfo);
|
|
50
|
-
pendingRequestQueue.push(deferredRequest);
|
|
51
|
-
return deferredRequest.promise;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export async function ulFetch(url, options, attempt = 0, shouldDropOnRateLimit = false, shouldRetryRequest = false) {
|
|
56
|
-
// drop or queue request based on the current rate limit status
|
|
57
|
-
const requestInfo = { url, options, attempt, shouldDropOnRateLimit };
|
|
58
|
-
if (isRateLimited && !shouldRetryRequest) {
|
|
59
|
-
return dropOrQueueRequest(shouldDropOnRateLimit, shouldRetryRequest, requestInfo);
|
|
60
|
-
}
|
|
61
|
-
const killswitchResponse = { ok: false, reportError: false };
|
|
62
|
-
if (killswitch) {
|
|
63
|
-
console.log(`UserLeap - ${killswitchReason}`);
|
|
64
|
-
return killswitchResponse;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
try {
|
|
68
|
-
options.headers = Object.assign(getHttpHeaders(), options.headers);
|
|
69
|
-
const result = await fetch(url, options);
|
|
70
|
-
if (result.status === 429) {
|
|
71
|
-
// retry if rate limit is not in effect yet and the request is not droppable
|
|
72
|
-
const shouldRetryCurrentRequest = (!isRateLimited && !shouldDropOnRateLimit) || shouldRetryRequest;
|
|
73
|
-
if (shouldRetryCurrentRequest) {
|
|
74
|
-
isRateLimited = true;
|
|
75
|
-
const rateLimitResetTime = result.headers.has('ratelimit-reset')
|
|
76
|
-
? Number(result.headers.get('ratelimit-reset'))
|
|
77
|
-
: NETWORK_CONFIG.RATELIMIT_RESET_DEFAULT;
|
|
78
|
-
return delay(rateLimitResetTime * 1000).then(async () => {
|
|
79
|
-
return ulFetch(url, options, 0, shouldDropOnRateLimit, true);
|
|
80
|
-
});
|
|
81
|
-
} else {
|
|
82
|
-
return dropOrQueueRequest(shouldDropOnRateLimit, false, requestInfo);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
isRateLimited = false;
|
|
86
|
-
if (pendingRequestQueue.length) {
|
|
87
|
-
pendingRequestQueue.map((deferredRequest) => {
|
|
88
|
-
const { url, options, attempt, shouldDropOnRateLimit } = deferredRequest.payload;
|
|
89
|
-
ulFetch(url, options, attempt, shouldDropOnRateLimit).then((result) => {
|
|
90
|
-
deferredRequest.resolveRequest(result);
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
pendingRequestQueue = [];
|
|
94
|
-
}
|
|
95
|
-
if (result.ok) {
|
|
96
|
-
if (result.status === 249) {
|
|
97
|
-
killNetworkRequests();
|
|
98
|
-
return killswitchResponse;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const responseText = await result.text();
|
|
102
|
-
try {
|
|
103
|
-
if (responseText && responseText !== 'OK') {
|
|
104
|
-
result.json = JSON.parse(responseText);
|
|
105
|
-
}
|
|
106
|
-
return result;
|
|
107
|
-
} catch (err) {
|
|
108
|
-
return {
|
|
109
|
-
ok: false,
|
|
110
|
-
reportError: true,
|
|
111
|
-
error: new Error(`failed parsing response json for ${url} - ${responseText}`),
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
return result;
|
|
116
|
-
} catch (err) {
|
|
117
|
-
//retry
|
|
118
|
-
const newAttempt = attempt + 1;
|
|
119
|
-
if (newAttempt > 2) {
|
|
120
|
-
return {
|
|
121
|
-
ok: false,
|
|
122
|
-
reportError: false,
|
|
123
|
-
error: err,
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
return delay(newAttempt * 1000).then(() => {
|
|
127
|
-
return ulFetch(url, options, newAttempt);
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"networkHelper.d.ts","sourceRoot":"","sources":["../../../sprig-browser/shared/networkHelper.js"],"names":[],"mappings":"AAAA,oDAIC"}
|
package/shared/networkHelper.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get true or false for whether to direct embed from platform headers
|
|
3
|
-
* @param {Object} [options = {}]
|
|
4
|
-
* @return {Object} User meta information
|
|
5
|
-
*/
|
|
6
|
-
export default function shouldDirectEmbed({ "userleap-platform": platform }?: any): any;
|
|
7
|
-
//# sourceMappingURL=shouldDirectEmbed.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"shouldDirectEmbed.d.ts","sourceRoot":"","sources":["../../../sprig-browser/shared/shouldDirectEmbed.js"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wFAEC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get true or false for whether to direct embed from platform headers
|
|
3
|
-
* @param {Object} [options = {}]
|
|
4
|
-
* @return {Object} User meta information
|
|
5
|
-
*/
|
|
6
|
-
export default function shouldDirectEmbed({ 'userleap-platform': platform }) {
|
|
7
|
-
return platform !== 'web';
|
|
8
|
-
}
|
package/shared/tool.d.ts
DELETED
package/shared/tool.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../../sprig-browser/shared/tool.js"],"names":[],"mappings":"AAIO,sEAMN;AAEM,yDAMN"}
|
package/shared/tool.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
// for shared functions across the sdk
|
|
2
|
-
|
|
3
|
-
import { CSS_CONSTANTS } from './constants';
|
|
4
|
-
|
|
5
|
-
export const overrideStyles = (document, styleString) => {
|
|
6
|
-
const overrideStyles = document.createElement('style');
|
|
7
|
-
overrideStyles.type = 'text/css';
|
|
8
|
-
overrideStyles.textContent = styleString;
|
|
9
|
-
overrideStyles.id = CSS_CONSTANTS.CUSTOM_STYLE_TAG_ID;
|
|
10
|
-
document.head.appendChild(overrideStyles);
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export const calculateFrameHeight = (document) => {
|
|
14
|
-
const container = document.querySelector(`.${CSS_CONSTANTS.CARD_CONTAINER_CLASS}`);
|
|
15
|
-
const containerHeight = container ? container.scrollHeight : 600;
|
|
16
|
-
const whiteSpace =
|
|
17
|
-
container && container.parentElement ? container.parentElement.clientHeight - container.clientHeight : 0;
|
|
18
|
-
return containerHeight + whiteSpace;
|
|
19
|
-
};
|
package/shared/ulEvents.d.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
export namespace ulEvents {
|
|
2
|
-
const SURVEY_LIFE_CYCLE: string;
|
|
3
|
-
const SURVEY_DIMENSIONS: string;
|
|
4
|
-
const SURVEY_HEIGHT: string;
|
|
5
|
-
const SURVEY_PRESENTED: string;
|
|
6
|
-
const SURVEY_APPEARED: string;
|
|
7
|
-
const SURVEY_FADING_OUT: string;
|
|
8
|
-
const SURVEY_WILL_CLOSE: string;
|
|
9
|
-
const SURVEY_CLOSED: string;
|
|
10
|
-
const SDK_READY: string;
|
|
11
|
-
const CLOSE_SURVEY_ON_OVERLAY_CLICK: string;
|
|
12
|
-
const VISITOR_ID_UPDATED: string;
|
|
13
|
-
}
|
|
14
|
-
export namespace internalEvents {
|
|
15
|
-
namespace name {
|
|
16
|
-
const VERIFY_VIEW_VERSION: string;
|
|
17
|
-
}
|
|
18
|
-
namespace data {
|
|
19
|
-
const VIEW_VERSION: string;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
export namespace DISMISS_REASONS {
|
|
23
|
-
const CLOSED: string;
|
|
24
|
-
const COMPLETE: string;
|
|
25
|
-
const PAGE_CHANGE: string;
|
|
26
|
-
const API: string;
|
|
27
|
-
const OVERRIDE: string;
|
|
28
|
-
}
|
|
29
|
-
export namespace SURVEY_STATE {
|
|
30
|
-
const READY: string;
|
|
31
|
-
const NO_SURVEY: string;
|
|
32
|
-
}
|
|
33
|
-
//# sourceMappingURL=ulEvents.d.ts.map
|
package/shared/ulEvents.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ulEvents.d.ts","sourceRoot":"","sources":["../../../sprig-browser/shared/ulEvents.js"],"names":[],"mappings":""}
|
package/shared/ulEvents.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
// UserLeap event constants
|
|
2
|
-
// event convention
|
|
3
|
-
// event name: descriptive name of the event that happened
|
|
4
|
-
// payload: {
|
|
5
|
-
// name: 'event name',
|
|
6
|
-
// descriptiveDataName: data
|
|
7
|
-
// }
|
|
8
|
-
export const ulEvents = {
|
|
9
|
-
// passing into controller
|
|
10
|
-
SURVEY_LIFE_CYCLE: 'survey.lifeCycle',
|
|
11
|
-
SURVEY_DIMENSIONS: 'survey.dimensions',
|
|
12
|
-
SURVEY_HEIGHT: 'survey.height',
|
|
13
|
-
SURVEY_PRESENTED: 'survey.presented',
|
|
14
|
-
SURVEY_APPEARED: 'survey.appeared',
|
|
15
|
-
SURVEY_FADING_OUT: 'survey.fadingOut',
|
|
16
|
-
SURVEY_WILL_CLOSE: 'survey.willClose',
|
|
17
|
-
SURVEY_CLOSED: 'survey.closed',
|
|
18
|
-
SDK_READY: 'sdk.ready',
|
|
19
|
-
// passing into view
|
|
20
|
-
CLOSE_SURVEY_ON_OVERLAY_CLICK: 'close.survey.overlayClick',
|
|
21
|
-
VISITOR_ID_UPDATED: 'visitor.id.updated',
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
// events not emitted externally and not in the documentation
|
|
25
|
-
export const internalEvents = {
|
|
26
|
-
name: {
|
|
27
|
-
VERIFY_VIEW_VERSION: 'verify.view.version',
|
|
28
|
-
},
|
|
29
|
-
data: {
|
|
30
|
-
VIEW_VERSION: 'view.version',
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export const DISMISS_REASONS = {
|
|
35
|
-
CLOSED: 'close.click', // user clicked the close button
|
|
36
|
-
COMPLETE: 'survey.completed', // user answered all questions
|
|
37
|
-
PAGE_CHANGE: 'page.change', // productConfig.dismissOnPageChange == true and we detected a page change (excludes hash/query param changes)
|
|
38
|
-
API: 'api', // JS called Sprig('dismissActiveSurvey')
|
|
39
|
-
OVERRIDE: 'override', // JS called Sprig('displaySurvey', SURVEY_ID)
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export const SURVEY_STATE = {
|
|
43
|
-
READY: 'ready',
|
|
44
|
-
NO_SURVEY: 'no survey',
|
|
45
|
-
};
|