@textback/notification-widget 2.0.0 → 2.0.1-102913
Sign up to get free protection for your applications and to get access to all the features.
- package/.eslintrc.js +291 -291
- package/build/index.js +12 -0
- package/build/sdk.js +9 -0
- package/package.json +70 -68
- package/promote_tag.sh +1 -1
- package/readme.md +569 -490
- package/server.js +8 -4
- package/src/libraries/ai.1.0.11.js +4088 -4088
- package/src/libraries/localization/locales/cs.js +14 -12
- package/src/libraries/localization/locales/en.js +14 -12
- package/src/libraries/localization/locales/index.js +8 -8
- package/src/libraries/localization/locales/pl.js +14 -12
- package/src/libraries/localization/locales/ro.js +14 -12
- package/src/libraries/localization/locales/ru.js +13 -12
- package/src/libraries/localization/locales/uk.js +14 -12
- package/src/libraries/localization/text.js +9 -9
- package/src/libraries/t.js +82 -82
- package/src/sdk/channels/channel.js +30 -30
- package/src/sdk/channels/facebook.js +13 -13
- package/src/sdk/channels/factory.js +3 -3
- package/src/sdk/channels/skype.js +12 -12
- package/src/sdk/channels/telegram.js +18 -18
- package/src/sdk/channels/viber.js +12 -12
- package/src/sdk/channels/vk-modal/vk-modal.html +17 -17
- package/src/sdk/channels/vk-modal/vk-modal.js +25 -25
- package/src/sdk/channels/vk-modal/vk-modal.scss +116 -116
- package/src/sdk/channels/vk.js +195 -184
- package/src/sdk/channels/whatsapp.js +16 -10
- package/src/sdk/channels/whatsappb.js +27 -0
- package/src/sdk/events/observer.js +46 -46
- package/src/sdk/index.js +5 -5
- package/src/sdk/sdk.js +67 -30
- package/src/sdk/utils/apiErrorHandler.js +11 -11
- package/src/sdk/utils/appInsights.js +88 -88
- package/src/sdk/utils/browserInfo.js +8 -8
- package/src/sdk/utils/constants.js +17 -17
- package/src/sdk/utils/cookies.js +67 -50
- package/src/sdk/utils/find.js +7 -7
- package/src/sdk/utils/loadConfig.js +20 -20
- package/src/sdk/utils/loadDeepLink.js +48 -21
- package/src/sdk/utils/loadScript.js +25 -25
- package/src/sdk/utils/loadSubscriptions.js +6 -6
- package/src/sdk/utils/parseQueryString.js +33 -33
- package/src/sdk/utils/windowHelper.js +25 -25
- package/src/sdk/widget/widget.js +192 -140
- package/src/widget/components/index.js +6 -2
- package/src/widget/components/tb-notification-button/facebook.js +9 -2
- package/src/widget/components/tb-notification-button/index.js +34 -34
- package/src/widget/components/tb-notification-button/styles.scss +657 -433
- package/src/widget/components/tb-notification-button/telegram.js +9 -2
- package/src/widget/components/tb-notification-button/viber.js +9 -2
- package/src/widget/components/tb-notification-button/vk.js +59 -50
- package/src/widget/components/tb-notification-button/whatsapp.js +15 -8
- package/src/widget/components/tb-notification-button/whatsappb.js +58 -0
- package/src/widget/components/tb-notification-widget/index.js +589 -384
- package/src/widget/components/tb-notification-widget/normalize.scss +395 -394
- package/src/widget/components/tb-notification-widget/styles.scss +502 -139
- package/src/widget/components/tb-nw-wahunter/index.js +259 -0
- package/src/widget/components/tb-nw-wahunter/styles.scss +471 -0
- package/src/widget/config.js +5 -5
- package/src/widget/icons/icon_chat_window.svg +1 -0
- package/src/widget/icons/icon_close.svg +1 -0
- package/src/widget/icons/icon_facebook.svg +7 -7
- package/src/widget/icons/icon_facebook_circle.svg +7 -9
- package/src/widget/icons/icon_instagram_circle.svg +95 -95
- package/src/widget/icons/icon_skype.svg +44 -44
- package/src/widget/icons/icon_skype_circle.svg +46 -46
- package/src/widget/icons/icon_skype_new.svg +113 -113
- package/src/widget/icons/icon_tg.svg +25 -25
- package/src/widget/icons/icon_tg_circle.svg +17 -27
- package/src/widget/icons/icon_viber.svg +75 -75
- package/src/widget/icons/icon_viber_circle.svg +67 -77
- package/src/widget/icons/icon_viber_new.svg +102 -102
- package/src/widget/icons/icon_vk.svg +14 -14
- package/src/widget/icons/icon_vk_circle.svg +16 -16
- package/src/widget/icons/icon_whatsapp.svg +147 -147
- package/src/widget/icons/icon_whatsapp_circle.svg +3 -3
- package/src/widget/icons/icon_whatsapp_hollow.svg +128 -0
- package/src/widget/icons/icon_whatsapp_new.svg +127 -127
- package/src/widget/icons/icon_whatsappb.svg +147 -0
- package/src/widget/icons/icon_whatsappb_circle.svg +4 -0
- package/src/widget/icons/icon_whatsappb_new.svg +127 -0
- package/src/widget/icons/paper-plane-arrow.svg +3 -0
- package/src/widget/icons/tb-logo.svg +21 -0
- package/src/widget/index.js +28 -28
- package/src/widget/locales/cs.js +42 -0
- package/src/widget/locales/en.js +42 -20
- package/src/widget/locales/index.js +2 -2
- package/src/widget/locales/pl.js +41 -19
- package/src/widget/locales/ro.js +41 -20
- package/src/widget/locales/ru.js +40 -19
- package/src/widget/locales/uk.js +40 -19
- package/src/widget/utils/cookiesEx.js +41 -41
- package/src/widget/utils/getLocale.js +4 -2
- package/src/widget/utils/stringifyAttributes.js +19 -19
- package/src/widget/utils/text.js +2 -1
- package/src/widget/utils/widgetsStorage.js +28 -28
- package/src/widget/widget.entry.js +3 -4
- package/tests/gf.html +35 -35
- package/tests/gf.js +21 -21
- package/tests/index.js +61 -61
- package/views/examples.ejs +7 -3
- package/views/sdk.html +274 -256
- package/webpack.common.js +72 -72
- package/webpack.dev.js +15 -15
- package/webpack.prod.js +10 -10
- package/src/widget/components/tb-notification-button/skype.js +0 -47
- package/src/widget/icons/text-back-badge.png +0 -0
- package/src/widget/locales/cz.js +0 -20
@@ -1,12 +1,12 @@
|
|
1
|
-
export default function apiErrorHandler(res) {
|
2
|
-
return res.json()
|
3
|
-
.then(data => {
|
4
|
-
if (data.$error) {
|
5
|
-
return Promise.reject(data.$error.msg || data.$error.scn);
|
6
|
-
}
|
7
|
-
data.headers = res.headers;
|
8
|
-
|
9
|
-
return data;
|
10
|
-
})
|
11
|
-
.catch(() => Promise.reject(`widget error: ${res.status}`));
|
1
|
+
export default function apiErrorHandler(res) {
|
2
|
+
return res.json()
|
3
|
+
.then(data => {
|
4
|
+
if (data.$error) {
|
5
|
+
return Promise.reject(data.$error.msg || data.$error.scn);
|
6
|
+
}
|
7
|
+
data.headers = res.headers;
|
8
|
+
|
9
|
+
return data;
|
10
|
+
})
|
11
|
+
.catch(() => Promise.reject(`widget error: ${res.status}`));
|
12
12
|
};
|
@@ -1,88 +1,88 @@
|
|
1
|
-
const appInsights = {
|
2
|
-
init(aiKey, userId, accountId) {
|
3
|
-
return new Promise((resolve, reject) => {
|
4
|
-
window.TextBack = window.TextBack || {};
|
5
|
-
let context = window.TextBack;
|
6
|
-
if (aiKey) {
|
7
|
-
let appInsights = context.appInsights || function (config) {
|
8
|
-
//basically most below code is got from MS so it's kinda unreadable hmm.. see MS instructions on appinsigths
|
9
|
-
function r(config) {
|
10
|
-
t[config] = function () {
|
11
|
-
let i = arguments;
|
12
|
-
t.queue.push(function () {
|
13
|
-
t[config].apply(t, i)
|
14
|
-
})
|
15
|
-
}
|
16
|
-
}
|
17
|
-
|
18
|
-
let t = {
|
19
|
-
config: config
|
20
|
-
},
|
21
|
-
u = document,
|
22
|
-
e = context,
|
23
|
-
o = "script",
|
24
|
-
s = u.createElement(o),
|
25
|
-
i, f;
|
26
|
-
for (s.src = config.url || "//az416426.vo.msecnd.net/scripts/a/ai.0.js", u.getElementsByTagName(o)[0].parentNode.appendChild(s), t.cookie = u.cookie, t.queue = [], i = ["Event", "Exception", "Metric", "PageView", "Trace"]; i.length;) r("track" + i.pop());
|
27
|
-
return r("setAuthenticatedUserContext"), r("clearAuthenticatedUserContext"), config.disableExceptionTracking || (i = "onerror", r("_" + i), f = e[i], e[i] = function (config, r, u, e, o) {
|
28
|
-
let s = f && f(config, r, u, e, o);
|
29
|
-
return s !== !0 && t["_" + i](config, r, u, e, o), s
|
30
|
-
}), t
|
31
|
-
}({
|
32
|
-
instrumentationKey: aiKey,
|
33
|
-
// Don't log browser exceptions.
|
34
|
-
disableExceptionTracking: true,
|
35
|
-
// Don't log ajax calls.
|
36
|
-
disableAjaxTracking: true,
|
37
|
-
//this url will point to the library - use @dev for testing when updating\editing lib - use @latest for production version of lib
|
38
|
-
//keep in mind that prod widget should always use @latest
|
39
|
-
url: '//
|
40
|
-
// url: '//
|
41
|
-
//url: '//localhost:8080/src/libraries/ai.1.0.11.js',
|
42
|
-
});
|
43
|
-
|
44
|
-
|
45
|
-
this.accountId = accountId;
|
46
|
-
context.appInsights = appInsights;
|
47
|
-
//ensure appinsights is fully loaded
|
48
|
-
let timer = setInterval(function () {
|
49
|
-
if(appInsights._onerror){
|
50
|
-
clearInterval(timer);
|
51
|
-
appInsights.setAuthenticatedUserContext(userId);
|
52
|
-
resolve(true);
|
53
|
-
}
|
54
|
-
}, 50);
|
55
|
-
|
56
|
-
}
|
57
|
-
//no aiKey - no telemetry
|
58
|
-
else{
|
59
|
-
resolve(true);
|
60
|
-
}
|
61
|
-
});
|
62
|
-
},
|
63
|
-
trackEvent(eventName, data) {
|
64
|
-
let context = window.TextBack;
|
65
|
-
context.appInsights && context.appInsights.trackEvent(eventName, data);
|
66
|
-
},
|
67
|
-
trackButtonClick(widgetId, eventName, channelType) {
|
68
|
-
let payload = {
|
69
|
-
channelType,
|
70
|
-
widgetId,
|
71
|
-
accountId: this.accountId,
|
72
|
-
widgetUrl: window.location.href
|
73
|
-
};
|
74
|
-
this.trackEvent(eventName, payload);
|
75
|
-
},
|
76
|
-
trackWidgetEvent(widgetId, eventName, reason) {
|
77
|
-
let payload = {
|
78
|
-
reason,
|
79
|
-
widgetId,
|
80
|
-
accountId: this.accountId,
|
81
|
-
widgetUrl: window.location.href
|
82
|
-
};
|
83
|
-
this.trackEvent(eventName, payload);
|
84
|
-
}
|
85
|
-
};
|
86
|
-
|
87
|
-
export default appInsights;
|
88
|
-
|
1
|
+
const appInsights = {
|
2
|
+
init(aiKey, userId, accountId) {
|
3
|
+
return new Promise((resolve, reject) => {
|
4
|
+
window.TextBack = window.TextBack || {};
|
5
|
+
let context = window.TextBack;
|
6
|
+
if (aiKey) {
|
7
|
+
let appInsights = context.appInsights || function (config) {
|
8
|
+
//basically most below code is got from MS so it's kinda unreadable hmm.. see MS instructions on appinsigths
|
9
|
+
function r(config) {
|
10
|
+
t[config] = function () {
|
11
|
+
let i = arguments;
|
12
|
+
t.queue.push(function () {
|
13
|
+
t[config].apply(t, i)
|
14
|
+
})
|
15
|
+
}
|
16
|
+
}
|
17
|
+
|
18
|
+
let t = {
|
19
|
+
config: config
|
20
|
+
},
|
21
|
+
u = document,
|
22
|
+
e = context,
|
23
|
+
o = "script",
|
24
|
+
s = u.createElement(o),
|
25
|
+
i, f;
|
26
|
+
for (s.src = config.url || "//az416426.vo.msecnd.net/scripts/a/ai.0.js", u.getElementsByTagName(o)[0].parentNode.appendChild(s), t.cookie = u.cookie, t.queue = [], i = ["Event", "Exception", "Metric", "PageView", "Trace"]; i.length;) r("track" + i.pop());
|
27
|
+
return r("setAuthenticatedUserContext"), r("clearAuthenticatedUserContext"), config.disableExceptionTracking || (i = "onerror", r("_" + i), f = e[i], e[i] = function (config, r, u, e, o) {
|
28
|
+
let s = f && f(config, r, u, e, o);
|
29
|
+
return s !== !0 && t["_" + i](config, r, u, e, o), s
|
30
|
+
}), t
|
31
|
+
}({
|
32
|
+
instrumentationKey: aiKey,
|
33
|
+
// Don't log browser exceptions.
|
34
|
+
disableExceptionTracking: true,
|
35
|
+
// Don't log ajax calls.
|
36
|
+
disableAjaxTracking: true,
|
37
|
+
//this url will point to the library - use @dev for testing when updating\editing lib - use @latest for production version of lib
|
38
|
+
//keep in mind that prod widget should always use @latest
|
39
|
+
url: '//cdn.jsdelivr.net/npm/@textback/notification-widget@latest/src/libraries/ai.1.0.11.js'
|
40
|
+
// url: '//cdn.jsdelivr.net/npm/@textback/notification-widget@dev/src/libraries/ai.1.0.11.js'
|
41
|
+
//url: '//localhost:8080/src/libraries/ai.1.0.11.js',
|
42
|
+
});
|
43
|
+
|
44
|
+
|
45
|
+
this.accountId = accountId;
|
46
|
+
context.appInsights = appInsights;
|
47
|
+
//ensure appinsights is fully loaded
|
48
|
+
let timer = setInterval(function () {
|
49
|
+
if(appInsights._onerror){
|
50
|
+
clearInterval(timer);
|
51
|
+
appInsights.setAuthenticatedUserContext(userId);
|
52
|
+
resolve(true);
|
53
|
+
}
|
54
|
+
}, 50);
|
55
|
+
|
56
|
+
}
|
57
|
+
//no aiKey - no telemetry
|
58
|
+
else{
|
59
|
+
resolve(true);
|
60
|
+
}
|
61
|
+
});
|
62
|
+
},
|
63
|
+
trackEvent(eventName, data) {
|
64
|
+
let context = window.TextBack;
|
65
|
+
context.appInsights && context.appInsights.trackEvent(eventName, data);
|
66
|
+
},
|
67
|
+
trackButtonClick(widgetId, eventName, channelType) {
|
68
|
+
let payload = {
|
69
|
+
channelType,
|
70
|
+
widgetId,
|
71
|
+
accountId: this.accountId,
|
72
|
+
widgetUrl: window.location.href
|
73
|
+
};
|
74
|
+
this.trackEvent(eventName, payload);
|
75
|
+
},
|
76
|
+
trackWidgetEvent(widgetId, eventName, reason) {
|
77
|
+
let payload = {
|
78
|
+
reason,
|
79
|
+
widgetId,
|
80
|
+
accountId: this.accountId,
|
81
|
+
widgetUrl: window.location.href
|
82
|
+
};
|
83
|
+
this.trackEvent(eventName, payload);
|
84
|
+
}
|
85
|
+
};
|
86
|
+
|
87
|
+
export default appInsights;
|
88
|
+
|
@@ -1,9 +1,9 @@
|
|
1
|
-
const isMobile = /Android|webOS|iPhone|iPad|BlackBerry|Windows Phone|Opera Mini|IEMobile|Mobile/i.test(navigator.userAgent);
|
2
|
-
|
3
|
-
const browserInfo = {
|
4
|
-
isMobile() {
|
5
|
-
return isMobile;
|
6
|
-
},
|
7
|
-
};
|
8
|
-
|
1
|
+
const isMobile = /Android|webOS|iPhone|iPad|BlackBerry|Windows Phone|Opera Mini|IEMobile|Mobile/i.test(navigator.userAgent);
|
2
|
+
|
3
|
+
const browserInfo = {
|
4
|
+
isMobile() {
|
5
|
+
return isMobile;
|
6
|
+
},
|
7
|
+
};
|
8
|
+
|
9
9
|
export default browserInfo;
|
@@ -1,18 +1,18 @@
|
|
1
|
-
const COOKIE_NAME_PREFIX = 'tb_notif_widget_';
|
2
|
-
const constants = {
|
3
|
-
COOKIE_NAME_PREFIX: COOKIE_NAME_PREFIX,
|
4
|
-
/**
|
5
|
-
* 10 years
|
6
|
-
*/
|
7
|
-
WIDGET_USER_ID_COOKIE_TTL: 315360000,
|
8
|
-
COOKIE_WIDGET_USER_ID: `${COOKIE_NAME_PREFIX}widgetUserId`,
|
9
|
-
SECONDS_IN_DAY: 86400,
|
10
|
-
// make subscription using API call
|
11
|
-
WIDGET_TYPE_API_CALL : 'apiCall',
|
12
|
-
// make subscription using native social widget
|
13
|
-
WIDGET_TYPE_WIDGET : 'widget',
|
14
|
-
DEFAULT_WIDGET_TYPE : 'widget',
|
15
|
-
SUBSCRIPTION_WINDOW_PROPS: 'width=600,height=800',
|
16
|
-
};
|
17
|
-
|
1
|
+
const COOKIE_NAME_PREFIX = 'tb_notif_widget_';
|
2
|
+
const constants = {
|
3
|
+
COOKIE_NAME_PREFIX: COOKIE_NAME_PREFIX,
|
4
|
+
/**
|
5
|
+
* 10 years
|
6
|
+
*/
|
7
|
+
WIDGET_USER_ID_COOKIE_TTL: 315360000,
|
8
|
+
COOKIE_WIDGET_USER_ID: `${COOKIE_NAME_PREFIX}widgetUserId`,
|
9
|
+
SECONDS_IN_DAY: 86400,
|
10
|
+
// make subscription using API call
|
11
|
+
WIDGET_TYPE_API_CALL : 'apiCall',
|
12
|
+
// make subscription using native social widget
|
13
|
+
WIDGET_TYPE_WIDGET : 'widget',
|
14
|
+
DEFAULT_WIDGET_TYPE : 'widget',
|
15
|
+
SUBSCRIPTION_WINDOW_PROPS: 'width=600,height=800',
|
16
|
+
};
|
17
|
+
|
18
18
|
export default constants;
|
package/src/sdk/utils/cookies.js
CHANGED
@@ -1,50 +1,67 @@
|
|
1
|
-
/**
|
2
|
-
* Created by martb on 28.06.2017.
|
3
|
-
* Module for work with cookies
|
4
|
-
*/
|
5
|
-
|
6
|
-
const cookies = {
|
7
|
-
/**
|
8
|
-
* возвращает cookie с именем name, если есть, если нет, то null
|
9
|
-
* @param name {String}
|
10
|
-
* @returns {String|null}
|
11
|
-
*/
|
12
|
-
getCookie: function (name) {
|
13
|
-
let nameEQ = name + "=";
|
14
|
-
let ca = document.cookie.split(';');
|
15
|
-
for (let i = 0; i < ca.length; i++) {
|
16
|
-
let c = ca[i];
|
17
|
-
while (c.charAt(0) === ' ') c = c.substring(1, c.length);
|
18
|
-
if (c.indexOf(nameEQ) === 0) return decodeURIComponent(c.substring(nameEQ.length, c.length));
|
19
|
-
}
|
20
|
-
return null;
|
21
|
-
},
|
22
|
-
|
23
|
-
/**
|
24
|
-
* устанавливает куку
|
25
|
-
* @param name - имя куки
|
26
|
-
* @param value - значение куки
|
27
|
-
* @param t - время в секундах
|
28
|
-
*/
|
29
|
-
setCookie: function (name, value, t) {
|
30
|
-
let expires = "";
|
31
|
-
if (t) {
|
32
|
-
let date = new Date();
|
33
|
-
t *= 1000;
|
34
|
-
date.setTime(date.getTime() + t);
|
35
|
-
expires = "; expires=" + date.toUTCString();
|
36
|
-
}
|
37
|
-
document.cookie = name + "=" + encodeURIComponent(value) + expires + "; path=/";
|
38
|
-
},
|
39
|
-
|
40
|
-
|
41
|
-
/*
|
42
|
-
* удаляет куку по имени
|
43
|
-
* @param name {String}
|
44
|
-
*/
|
45
|
-
deleteCookie: function (name) {
|
46
|
-
setCookie(name, "", -1);
|
47
|
-
}
|
48
|
-
|
49
|
-
|
50
|
-
|
1
|
+
/**
|
2
|
+
* Created by martb on 28.06.2017.
|
3
|
+
* Module for work with cookies
|
4
|
+
*/
|
5
|
+
|
6
|
+
const cookies = {
|
7
|
+
/**
|
8
|
+
* возвращает cookie с именем name, если есть, если нет, то null
|
9
|
+
* @param name {String}
|
10
|
+
* @returns {String|null}
|
11
|
+
*/
|
12
|
+
getCookie: function (name) {
|
13
|
+
let nameEQ = name + "=";
|
14
|
+
let ca = document.cookie.split(';');
|
15
|
+
for (let i = 0; i < ca.length; i++) {
|
16
|
+
let c = ca[i];
|
17
|
+
while (c.charAt(0) === ' ') c = c.substring(1, c.length);
|
18
|
+
if (c.indexOf(nameEQ) === 0) return decodeURIComponent(c.substring(nameEQ.length, c.length));
|
19
|
+
}
|
20
|
+
return null;
|
21
|
+
},
|
22
|
+
|
23
|
+
/**
|
24
|
+
* устанавливает куку
|
25
|
+
* @param name - имя куки
|
26
|
+
* @param value - значение куки
|
27
|
+
* @param t - время в секундах
|
28
|
+
*/
|
29
|
+
setCookie: function (name, value, t) {
|
30
|
+
let expires = "";
|
31
|
+
if (t) {
|
32
|
+
let date = new Date();
|
33
|
+
t *= 1000;
|
34
|
+
date.setTime(date.getTime() + t);
|
35
|
+
expires = "; expires=" + date.toUTCString();
|
36
|
+
}
|
37
|
+
document.cookie = name + "=" + encodeURIComponent(value) + expires + "; path=/";
|
38
|
+
},
|
39
|
+
|
40
|
+
|
41
|
+
/*
|
42
|
+
* удаляет куку по имени
|
43
|
+
* @param name {String}
|
44
|
+
*/
|
45
|
+
deleteCookie: function (name) {
|
46
|
+
setCookie(name, "", -1);
|
47
|
+
},
|
48
|
+
|
49
|
+
|
50
|
+
getCookieObject: function () {
|
51
|
+
const result = {};
|
52
|
+
|
53
|
+
document.cookie
|
54
|
+
.split(';')
|
55
|
+
.forEach((cookieItem) => {
|
56
|
+
const separatorPos = cookieItem.indexOf('=');
|
57
|
+
const key = cookieItem.slice(0, separatorPos).trim();
|
58
|
+
const value = cookieItem.slice(separatorPos + 1);
|
59
|
+
|
60
|
+
result[key] = value;
|
61
|
+
});
|
62
|
+
|
63
|
+
return result;
|
64
|
+
}
|
65
|
+
};
|
66
|
+
|
67
|
+
export default cookies;
|
package/src/sdk/utils/find.js
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
export default function find(array, predicate) {
|
2
|
-
for (let i = 0; i < array.length; i++) {
|
3
|
-
if (predicate(array[i], i, array)) {
|
4
|
-
return array[i];
|
5
|
-
}
|
6
|
-
}
|
7
|
-
return undefined;
|
1
|
+
export default function find(array, predicate) {
|
2
|
+
for (let i = 0; i < array.length; i++) {
|
3
|
+
if (predicate(array[i], i, array)) {
|
4
|
+
return array[i];
|
5
|
+
}
|
6
|
+
}
|
7
|
+
return undefined;
|
8
8
|
}
|
@@ -1,21 +1,21 @@
|
|
1
|
-
import apiErrorHandler from './apiErrorHandler.js';
|
2
|
-
|
3
|
-
const cache = {};
|
4
|
-
|
5
|
-
|
6
|
-
export default function loadConfig(widgetId, apiPath) {
|
7
|
-
if (!widgetId) {
|
8
|
-
return Promise.reject('Widget id required');
|
9
|
-
}
|
10
|
-
|
11
|
-
if (cache[widgetId]) {
|
12
|
-
return cache[widgetId];
|
13
|
-
}
|
14
|
-
|
15
|
-
const loadingPromise = fetch(`${apiPath}/endUserNotifications/widgets/${widgetId}`).then(apiErrorHandler);
|
16
|
-
loadingPromise.then(() => {
|
17
|
-
cache[widgetId] = loadingPromise;
|
18
|
-
});
|
19
|
-
|
20
|
-
return loadingPromise;
|
1
|
+
import apiErrorHandler from './apiErrorHandler.js';
|
2
|
+
|
3
|
+
const cache = {};
|
4
|
+
|
5
|
+
|
6
|
+
export default function loadConfig(widgetId, apiPath) {
|
7
|
+
if (!widgetId) {
|
8
|
+
return Promise.reject('Widget id required');
|
9
|
+
}
|
10
|
+
|
11
|
+
if (cache[widgetId]) {
|
12
|
+
return cache[widgetId];
|
13
|
+
}
|
14
|
+
|
15
|
+
const loadingPromise = fetch(`${apiPath}/endUserNotifications/widgets/${widgetId}`).then(apiErrorHandler);
|
16
|
+
loadingPromise.then(() => {
|
17
|
+
cache[widgetId] = loadingPromise;
|
18
|
+
});
|
19
|
+
|
20
|
+
return loadingPromise;
|
21
21
|
};
|
@@ -1,21 +1,48 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
import apiErrorHandler from './apiErrorHandler.js';
|
4
|
+
|
5
|
+
const cache = {};
|
6
|
+
|
7
|
+
export const deeplinkUpdater = (apiPath, deeplink) => {
|
8
|
+
let _promises = [];
|
9
|
+
|
10
|
+
return data => {
|
11
|
+
Promise.all(_promises).then(() => {
|
12
|
+
let _data = JSON.stringify({
|
13
|
+
id: deeplink,
|
14
|
+
insecureContext: { data: data }
|
15
|
+
});
|
16
|
+
|
17
|
+
let _promise = fetch(
|
18
|
+
`${apiPath}/endUserNotifications/deepLinks`,
|
19
|
+
{
|
20
|
+
method: 'PATCH',
|
21
|
+
body: _data
|
22
|
+
}
|
23
|
+
);
|
24
|
+
|
25
|
+
_promises.push(_promise);
|
26
|
+
|
27
|
+
return _promises;
|
28
|
+
});
|
29
|
+
};
|
30
|
+
};
|
31
|
+
|
32
|
+
export default function loadDeepLink(apiPath, options = {}) {
|
33
|
+
const body = JSON.stringify(options);
|
34
|
+
|
35
|
+
if (cache[body]) {
|
36
|
+
return cache[body];
|
37
|
+
}
|
38
|
+
|
39
|
+
cache[body] = fetch(`${apiPath}/endUserNotifications/deepLinks`, {
|
40
|
+
method: 'POST',
|
41
|
+
headers: {
|
42
|
+
'Content-Type': 'application/json'
|
43
|
+
},
|
44
|
+
body
|
45
|
+
}).then(apiErrorHandler);
|
46
|
+
|
47
|
+
return cache[body];
|
48
|
+
};
|
@@ -1,26 +1,26 @@
|
|
1
|
-
const cache = {};
|
2
|
-
|
3
|
-
export default function loadScript(url) {
|
4
|
-
if (cache[url]){
|
5
|
-
return cache[url];
|
6
|
-
}
|
7
|
-
|
8
|
-
cache[url] = new Promise((resolve, reject) => {
|
9
|
-
let ready = false;
|
10
|
-
const scriptElement = document.createElement("script");
|
11
|
-
|
12
|
-
scriptElement.type = "text/javascript";
|
13
|
-
scriptElement.src = url;
|
14
|
-
scriptElement.async = true;
|
15
|
-
scriptElement.onload = scriptElement.onreadystatechange = function() {
|
16
|
-
if (!ready && (!this.readyState || this.readyState == "complete")) {
|
17
|
-
ready = true;
|
18
|
-
resolve();
|
19
|
-
}
|
20
|
-
};
|
21
|
-
scriptElement.onerror = scriptElement.onabort = reject;
|
22
|
-
document.head.appendChild(scriptElement);
|
23
|
-
});
|
24
|
-
|
25
|
-
return cache[url];
|
1
|
+
const cache = {};
|
2
|
+
|
3
|
+
export default function loadScript(url) {
|
4
|
+
if (cache[url]){
|
5
|
+
return cache[url];
|
6
|
+
}
|
7
|
+
|
8
|
+
cache[url] = new Promise((resolve, reject) => {
|
9
|
+
let ready = false;
|
10
|
+
const scriptElement = document.createElement("script");
|
11
|
+
|
12
|
+
scriptElement.type = "text/javascript";
|
13
|
+
scriptElement.src = url;
|
14
|
+
scriptElement.async = true;
|
15
|
+
scriptElement.onload = scriptElement.onreadystatechange = function() {
|
16
|
+
if (!ready && (!this.readyState || this.readyState == "complete")) {
|
17
|
+
ready = true;
|
18
|
+
resolve();
|
19
|
+
}
|
20
|
+
};
|
21
|
+
scriptElement.onerror = scriptElement.onabort = reject;
|
22
|
+
document.head.appendChild(scriptElement);
|
23
|
+
});
|
24
|
+
|
25
|
+
return cache[url];
|
26
26
|
}
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import apiErrorHandler from './apiErrorHandler.js';
|
2
|
-
|
3
|
-
export default function loadSubscriptions(uuid, widgetId, apiPath){
|
4
|
-
const subscribedUsers = fetch(`${apiPath}/endUserNotifications/widgets/${widgetId}/subscribedUsers/${uuid}`).then(apiErrorHandler);
|
5
|
-
return subscribedUsers;
|
6
|
-
}
|
1
|
+
import apiErrorHandler from './apiErrorHandler.js';
|
2
|
+
|
3
|
+
export default function loadSubscriptions(uuid, widgetId, apiPath){
|
4
|
+
const subscribedUsers = fetch(`${apiPath}/endUserNotifications/widgets/${widgetId}/subscribedUsers/${uuid}`).then(apiErrorHandler);
|
5
|
+
return subscribedUsers;
|
6
|
+
}
|
@@ -1,34 +1,34 @@
|
|
1
|
-
function parseQueryString(query) {
|
2
|
-
const vars = query.split('&'),
|
3
|
-
queryString = {};
|
4
|
-
|
5
|
-
if (query.length > 0) {
|
6
|
-
for (var i = 0; i < vars.length; i++) {
|
7
|
-
const pair = vars[i].split('='),
|
8
|
-
key = decodeURIComponent(pair[0]),
|
9
|
-
value = decodeURIComponent(pair[1]);
|
10
|
-
|
11
|
-
if (!key)
|
12
|
-
continue;
|
13
|
-
|
14
|
-
switch ( typeof queryString[key] ) {
|
15
|
-
// If first entry with this name
|
16
|
-
case 'undefined':
|
17
|
-
queryString[key] = value;
|
18
|
-
break;
|
19
|
-
// If second entry with this name
|
20
|
-
case 'string': {
|
21
|
-
const arr = [ queryString[key], value ];
|
22
|
-
queryString[ key ] = arr;
|
23
|
-
break;
|
24
|
-
}
|
25
|
-
// If third or later entry with this name
|
26
|
-
default:
|
27
|
-
queryString[key].push(value);
|
28
|
-
}
|
29
|
-
}
|
30
|
-
}
|
31
|
-
return queryString;
|
32
|
-
}
|
33
|
-
|
1
|
+
function parseQueryString(query) {
|
2
|
+
const vars = query.split('&'),
|
3
|
+
queryString = {};
|
4
|
+
|
5
|
+
if (query.length > 0) {
|
6
|
+
for (var i = 0; i < vars.length; i++) {
|
7
|
+
const pair = vars[i].split('='),
|
8
|
+
key = decodeURIComponent(pair[0]),
|
9
|
+
value = decodeURIComponent(pair[1]);
|
10
|
+
|
11
|
+
if (!key)
|
12
|
+
continue;
|
13
|
+
|
14
|
+
switch ( typeof queryString[key] ) {
|
15
|
+
// If first entry with this name
|
16
|
+
case 'undefined':
|
17
|
+
queryString[key] = value;
|
18
|
+
break;
|
19
|
+
// If second entry with this name
|
20
|
+
case 'string': {
|
21
|
+
const arr = [ queryString[key], value ];
|
22
|
+
queryString[ key ] = arr;
|
23
|
+
break;
|
24
|
+
}
|
25
|
+
// If third or later entry with this name
|
26
|
+
default:
|
27
|
+
queryString[key].push(value);
|
28
|
+
}
|
29
|
+
}
|
30
|
+
}
|
31
|
+
return queryString;
|
32
|
+
}
|
33
|
+
|
34
34
|
export default parseQueryString;
|