@zoho_apptics/apptics-js-sdk 2.0.0-beta.2 → 2.0.0
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/CHANGELOG.md +47 -0
- package/README.md +229 -174
- package/dist/apptics-pn-sw.js +3 -0
- package/dist/apptics-pn-sw.js.map +1 -0
- package/dist/apptics.esm.min.js +2 -2
- package/dist/apptics.esm.min.js.map +1 -1
- package/dist/apptics.min.js +2 -2
- package/dist/apptics.min.js.map +1 -1
- package/dist/chunks/batch-Axq9sTzR.min.js +3 -0
- package/dist/chunks/batch-Axq9sTzR.min.js.map +1 -0
- package/dist/chunks/lifecycle-Cvg78jN_.min.js +3 -0
- package/dist/chunks/lifecycle-Cvg78jN_.min.js.map +1 -0
- package/dist/chunks/send-DBpesydB.min.js +3 -0
- package/dist/chunks/send-DBpesydB.min.js.map +1 -0
- package/dist/chunks/transport-B21X39p4.min.js +3 -0
- package/dist/chunks/transport-B21X39p4.min.js.map +1 -0
- package/dist/cjs/core/attempts.js +1 -1
- package/dist/cjs/core/batch.js +4 -3
- package/dist/cjs/core/consent.d.ts +9 -6
- package/dist/cjs/core/consent.js +63 -10
- package/dist/cjs/core/console-call.d.ts +23 -0
- package/dist/cjs/core/console-call.js +63 -0
- package/dist/cjs/core/constants.d.ts +44 -0
- package/dist/cjs/core/constants.js +55 -1
- package/dist/cjs/core/db.js +31 -7
- package/dist/cjs/core/debug.d.ts +6 -4
- package/dist/cjs/core/debug.js +36 -12
- package/dist/cjs/core/env.js +1 -1
- package/dist/cjs/core/framework-id.d.ts +1 -1
- package/dist/cjs/core/framework-id.js +3 -3
- package/dist/cjs/core/guard.js +19 -4
- package/dist/cjs/core/hooks.d.ts +25 -1
- package/dist/cjs/core/hooks.js +11 -1
- package/dist/cjs/core/locks.js +1 -1
- package/dist/cjs/core/logger.js +1 -1
- package/dist/cjs/core/shield.d.ts +31 -0
- package/dist/cjs/core/shield.js +129 -0
- package/dist/cjs/core/state.d.ts +5 -1
- package/dist/cjs/core/state.js +3 -1
- package/dist/cjs/core/storage.d.ts +7 -0
- package/dist/cjs/core/storage.js +28 -6
- package/dist/cjs/core/stylesheet.js +1 -1
- package/dist/cjs/core/transport.d.ts +15 -4
- package/dist/cjs/core/transport.js +63 -13
- package/dist/cjs/core/utils.js +1 -1
- package/dist/cjs/core/validate.js +6 -5
- package/dist/cjs/device/appversion.js +1 -1
- package/dist/cjs/device/index.js +63 -15
- package/dist/cjs/engagement/api-rules.js +1 -1
- package/dist/cjs/engagement/auto-api.js +4 -3
- package/dist/cjs/engagement/auto-screen.js +10 -6
- package/dist/cjs/engagement/defined-events.d.ts +2 -3
- package/dist/cjs/engagement/defined-events.js +10 -16
- package/dist/cjs/engagement/send.js +1 -1
- package/dist/cjs/engagement/session.js +77 -37
- package/dist/cjs/engagement/track.js +9 -6
- package/dist/cjs/errors/send.js +1 -1
- package/dist/cjs/errors/track.js +3 -2
- package/dist/cjs/feedback/controls.d.ts +30 -4
- package/dist/cjs/feedback/controls.js +237 -51
- package/dist/cjs/feedback/i18n/index.d.ts +31 -0
- package/dist/cjs/feedback/i18n/index.js +187 -0
- package/dist/cjs/feedback/i18n/strings.d.ts +9 -0
- package/dist/cjs/feedback/i18n/strings.js +8 -0
- package/dist/cjs/feedback/index.js +1 -1
- package/dist/cjs/feedback/logs.js +5 -4
- package/dist/cjs/feedback/quartz.js +5 -2
- package/dist/cjs/feedback/send.d.ts +4 -1
- package/dist/cjs/feedback/send.js +56 -15
- package/dist/cjs/feedback/styles.js +2 -2
- package/dist/cjs/feedback/template.d.ts +4 -2
- package/dist/cjs/feedback/template.js +67 -46
- package/dist/cjs/feedback/ui.d.ts +40 -4
- package/dist/cjs/feedback/ui.js +208 -89
- package/dist/cjs/heatmap/send.js +1 -1
- package/dist/cjs/heatmap/track.js +13 -9
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/lifecycle.js +119 -72
- package/dist/cjs/pushnotification/display.d.ts +65 -0
- package/dist/cjs/pushnotification/display.js +112 -0
- package/dist/cjs/pushnotification/index.d.ts +20 -0
- package/dist/cjs/pushnotification/index.js +96 -0
- package/dist/cjs/pushnotification/kept-opens.d.ts +23 -0
- package/dist/cjs/pushnotification/kept-opens.js +64 -0
- package/dist/cjs/pushnotification/notify.d.ts +45 -0
- package/dist/cjs/pushnotification/notify.js +476 -0
- package/dist/cjs/pushnotification/payload.d.ts +65 -0
- package/dist/cjs/pushnotification/payload.js +279 -0
- package/dist/cjs/pushnotification/session.d.ts +46 -0
- package/dist/cjs/pushnotification/session.js +413 -0
- package/dist/cjs/pushnotification/stats.d.ts +45 -0
- package/dist/cjs/pushnotification/stats.js +244 -0
- package/dist/cjs/pushnotification/wms.d.ts +30 -0
- package/dist/cjs/pushnotification/wms.js +374 -0
- package/dist/cjs/remoteconfig/country.js +1 -1
- package/dist/cjs/remoteconfig/custom.js +4 -3
- package/dist/cjs/remoteconfig/evaluate.js +1 -1
- package/dist/cjs/remoteconfig/fetch.js +27 -8
- package/dist/cjs/remoteconfig/index.d.ts +1 -6
- package/dist/cjs/remoteconfig/index.js +4 -28
- package/dist/cjs/remoteconfig/store.js +1 -1
- package/dist/cjs/remoteconfig/tz-countries.js +1 -1
- package/dist/cjs/remotelog/callsite.js +1 -1
- package/dist/cjs/remotelog/gate.js +1 -1
- package/dist/cjs/remotelog/logger.js +1 -1
- package/dist/cjs/remotelog/send.js +5 -4
- package/dist/cjs/remotelogger/index.js +1 -1
- package/dist/cjs/scheduler.js +11 -5
- package/dist/cjs/sw/apptics-pn-sw.d.ts +83 -0
- package/dist/cjs/sw/timers.d.ts +44 -0
- package/dist/cjs/types.d.ts +31 -15
- package/dist/cjs/user/index.d.ts +7 -0
- package/dist/cjs/user/index.js +25 -7
- package/dist/esm/core/attempts.js +1 -1
- package/dist/esm/core/batch.js +4 -3
- package/dist/esm/core/consent.d.ts +9 -6
- package/dist/esm/core/consent.js +67 -16
- package/dist/esm/core/console-call.d.ts +23 -0
- package/dist/esm/core/console-call.js +60 -0
- package/dist/esm/core/constants.d.ts +44 -0
- package/dist/esm/core/constants.js +52 -2
- package/dist/esm/core/db.js +31 -7
- package/dist/esm/core/debug.d.ts +6 -4
- package/dist/esm/core/debug.js +37 -13
- package/dist/esm/core/env.js +1 -1
- package/dist/esm/core/framework-id.d.ts +1 -1
- package/dist/esm/core/framework-id.js +3 -3
- package/dist/esm/core/guard.js +19 -4
- package/dist/esm/core/hooks.d.ts +25 -1
- package/dist/esm/core/hooks.js +11 -1
- package/dist/esm/core/locks.js +1 -1
- package/dist/esm/core/logger.js +1 -1
- package/dist/esm/core/shield.d.ts +31 -0
- package/dist/esm/core/shield.js +119 -0
- package/dist/esm/core/state.d.ts +5 -1
- package/dist/esm/core/state.js +3 -1
- package/dist/esm/core/storage.d.ts +7 -0
- package/dist/esm/core/storage.js +28 -8
- package/dist/esm/core/stylesheet.js +1 -1
- package/dist/esm/core/transport.d.ts +15 -4
- package/dist/esm/core/transport.js +64 -16
- package/dist/esm/core/utils.js +1 -1
- package/dist/esm/core/validate.js +6 -5
- package/dist/esm/device/appversion.js +1 -1
- package/dist/esm/device/index.js +67 -19
- package/dist/esm/engagement/api-rules.js +1 -1
- package/dist/esm/engagement/auto-api.js +4 -3
- package/dist/esm/engagement/auto-screen.js +10 -6
- package/dist/esm/engagement/defined-events.d.ts +2 -3
- package/dist/esm/engagement/defined-events.js +10 -16
- package/dist/esm/engagement/send.js +1 -1
- package/dist/esm/engagement/session.js +77 -37
- package/dist/esm/engagement/track.js +9 -6
- package/dist/esm/errors/send.js +1 -1
- package/dist/esm/errors/track.js +3 -2
- package/dist/esm/feedback/controls.d.ts +30 -4
- package/dist/esm/feedback/controls.js +234 -52
- package/dist/esm/feedback/i18n/index.d.ts +31 -0
- package/dist/esm/feedback/i18n/index.js +178 -0
- package/dist/esm/feedback/i18n/strings.d.ts +9 -0
- package/dist/esm/feedback/i18n/strings.js +4 -0
- package/dist/esm/feedback/index.js +1 -1
- package/dist/esm/feedback/logs.js +5 -4
- package/dist/esm/feedback/quartz.js +5 -2
- package/dist/esm/feedback/send.d.ts +4 -1
- package/dist/esm/feedback/send.js +56 -16
- package/dist/esm/feedback/styles.js +2 -2
- package/dist/esm/feedback/template.d.ts +4 -2
- package/dist/esm/feedback/template.js +67 -46
- package/dist/esm/feedback/ui.d.ts +40 -4
- package/dist/esm/feedback/ui.js +210 -91
- package/dist/esm/heatmap/send.js +1 -1
- package/dist/esm/heatmap/track.js +13 -9
- package/dist/esm/index.js +2 -2
- package/dist/esm/lifecycle.js +120 -73
- package/dist/esm/pushnotification/display.d.ts +65 -0
- package/dist/esm/pushnotification/display.js +95 -0
- package/dist/esm/pushnotification/index.d.ts +20 -0
- package/dist/esm/pushnotification/index.js +91 -0
- package/dist/esm/pushnotification/kept-opens.d.ts +23 -0
- package/dist/esm/pushnotification/kept-opens.js +62 -0
- package/dist/esm/pushnotification/notify.d.ts +45 -0
- package/dist/esm/pushnotification/notify.js +469 -0
- package/dist/esm/pushnotification/payload.d.ts +65 -0
- package/dist/esm/pushnotification/payload.js +272 -0
- package/dist/esm/pushnotification/session.d.ts +46 -0
- package/dist/esm/pushnotification/session.js +402 -0
- package/dist/esm/pushnotification/stats.d.ts +45 -0
- package/dist/esm/pushnotification/stats.js +238 -0
- package/dist/esm/pushnotification/wms.d.ts +30 -0
- package/dist/esm/pushnotification/wms.js +368 -0
- package/dist/esm/remoteconfig/country.js +1 -1
- package/dist/esm/remoteconfig/custom.js +4 -3
- package/dist/esm/remoteconfig/evaluate.js +1 -1
- package/dist/esm/remoteconfig/fetch.js +27 -8
- package/dist/esm/remoteconfig/index.d.ts +1 -6
- package/dist/esm/remoteconfig/index.js +4 -28
- package/dist/esm/remoteconfig/store.js +1 -1
- package/dist/esm/remoteconfig/tz-countries.js +1 -1
- package/dist/esm/remotelog/callsite.js +1 -1
- package/dist/esm/remotelog/gate.js +1 -1
- package/dist/esm/remotelog/logger.js +1 -1
- package/dist/esm/remotelog/send.js +5 -4
- package/dist/esm/remotelogger/index.js +1 -1
- package/dist/esm/scheduler.js +11 -5
- package/dist/esm/sw/apptics-pn-sw.d.ts +83 -0
- package/dist/esm/sw/timers.d.ts +44 -0
- package/dist/esm/types.d.ts +31 -15
- package/dist/esm/user/index.d.ts +7 -0
- package/dist/esm/user/index.js +26 -9
- package/dist/feedback.esm.min.js +2 -2
- package/dist/feedback.esm.min.js.map +1 -1
- package/dist/pushnotification.esm.min.js +3 -0
- package/dist/pushnotification.esm.min.js.map +1 -0
- package/dist/remoteconfig.esm.min.js +2 -2
- package/dist/remoteconfig.esm.min.js.map +1 -1
- package/dist/remotelogger.esm.min.js +2 -2
- package/dist/remotelogger.esm.min.js.map +1 -1
- package/package.json +15 -2
- package/dist/chunks/lifecycle-C6m1W7jo.min.js +0 -3
- package/dist/chunks/lifecycle-C6m1W7jo.min.js.map +0 -1
- package/dist/chunks/send-CgUO82ne.min.js +0 -3
- package/dist/chunks/send-CgUO82ne.min.js.map +0 -1
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
/*! @zoho_apptics/apptics-js-sdk v2.0.0 | (c) Zoho Corporation Private Limited | see LICENSE */
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The web push payload, as the server sends it to browsers (the WMS message's `data`):
|
|
6
|
+
*
|
|
7
|
+
* title, msg (the console's markdown), icon, image, images[], autoScroll, timer (seconds),
|
|
8
|
+
* msgTimer (epoch ms), autoDismiss (seconds), requireInteraction, silent, and
|
|
9
|
+
* addInfo: { appticsPnID, clickAction, additional: {...}, actionButton: [{ action, label,
|
|
10
|
+
* clickAction, icon }] }
|
|
11
|
+
*
|
|
12
|
+
* webNotificationFrom() turns it into what the browser shows, as the console's web preview shows
|
|
13
|
+
* it. The flat keys sent before this format (message, body, imageUrl, url) are still read.
|
|
14
|
+
* Every string is read with the HTML entities the server adds decoded, and only http(s) URLs are
|
|
15
|
+
* kept. Nothing here touches the DOM, so the service worker shares it.
|
|
16
|
+
*/
|
|
17
|
+
/** Browsers show at most two action buttons (the console's MAX_WEB_ACTION_BUTTONS). */
|
|
18
|
+
const MAX_BUTTONS = 2;
|
|
19
|
+
const ENTITIES = { amp: '&', lt: '<', gt: '>', quot: '"', apos: '\'', nbsp: ' ' }; // no i18n
|
|
20
|
+
/** `text` with HTML entities (named, &#n; and &#xh;) turned back into their characters. */
|
|
21
|
+
function decodeEntities(text) {
|
|
22
|
+
return text.replace(/&(#x[0-9a-f]+|#[0-9]+|[a-z]+);/gi, function (match, ref) {
|
|
23
|
+
if (ref.charAt(0) === '#') {
|
|
24
|
+
var code = ref.charAt(1).toLowerCase() === 'x' ? parseInt(ref.slice(2), 16) : parseInt(ref.slice(1), 10); // no i18n
|
|
25
|
+
return isFinite(code) && code > 0 && code <= 0x10ffff ? String.fromCodePoint(code) : match;
|
|
26
|
+
}
|
|
27
|
+
var named = ENTITIES[ref.toLowerCase()];
|
|
28
|
+
return named === undefined ? match : named;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
function isObject(value) {
|
|
32
|
+
return !!value && typeof value === 'object' && !Array.isArray(value); // no i18n
|
|
33
|
+
}
|
|
34
|
+
function str(value) {
|
|
35
|
+
if (typeof value === 'string') { // no i18n
|
|
36
|
+
return decodeEntities(value);
|
|
37
|
+
}
|
|
38
|
+
return typeof value === 'number' && isFinite(value) ? String(value) : ''; // no i18n
|
|
39
|
+
}
|
|
40
|
+
function base() {
|
|
41
|
+
var loc = typeof location !== 'undefined' ? location : undefined; // no i18n
|
|
42
|
+
return loc ? loc.href : 'https://invalid/'; // no i18n
|
|
43
|
+
}
|
|
44
|
+
/** `value` as an absolute http(s) URL, '' for anything else. */
|
|
45
|
+
function safeUrl(value) {
|
|
46
|
+
var raw = str(value).trim();
|
|
47
|
+
if (raw === '') { // no i18n
|
|
48
|
+
return ''; // no i18n
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
var url = new URL(raw, base());
|
|
52
|
+
return url.protocol === 'http:' || url.protocol === 'https:' ? url.href : ''; // no i18n
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
return ''; // no i18n
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function images(data) {
|
|
59
|
+
var raw = data.images;
|
|
60
|
+
var list = Array.isArray(raw) ? raw
|
|
61
|
+
: typeof raw === 'string' ? decodeEntities(raw).replace(/^\[|\]$/g, '').split(',') : []; // no i18n
|
|
62
|
+
var urls = list.map(function (u) {
|
|
63
|
+
return safeUrl(typeof u === 'string' ? u.trim().replace(/^['"]|['"]$/g, '') : u); // no i18n
|
|
64
|
+
}).filter(function (u) { return u !== ''; }); // no i18n
|
|
65
|
+
if (urls.length === 0) {
|
|
66
|
+
var single = safeUrl(data.image) || safeUrl(data.imageUrl);
|
|
67
|
+
if (single !== '') { // no i18n
|
|
68
|
+
urls.push(single);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return urls;
|
|
72
|
+
}
|
|
73
|
+
function buttons(addInfo) {
|
|
74
|
+
var raw = Array.isArray(addInfo.actionButton) ? addInfo.actionButton : [];
|
|
75
|
+
var out = [];
|
|
76
|
+
raw.forEach(function (b) {
|
|
77
|
+
if (out.length >= MAX_BUTTONS || !isObject(b)) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
var label = str(b.label).trim();
|
|
81
|
+
if (label === '') { // no i18n
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
out.push({ action: str(b.action), label: label, url: safeUrl(b.clickAction), icon: safeUrl(b.icon) });
|
|
85
|
+
});
|
|
86
|
+
return out;
|
|
87
|
+
}
|
|
88
|
+
/** `value` with every string in it decoded, objects and arrays included. */
|
|
89
|
+
function decodeDeep(value) {
|
|
90
|
+
if (typeof value === 'string') { // no i18n
|
|
91
|
+
return decodeEntities(value);
|
|
92
|
+
}
|
|
93
|
+
if (Array.isArray(value)) {
|
|
94
|
+
return value.map(decodeDeep);
|
|
95
|
+
}
|
|
96
|
+
if (isObject(value)) {
|
|
97
|
+
var out = {};
|
|
98
|
+
Object.keys(value).forEach(function (k) { out[decodeEntities(k)] = decodeDeep(value[k]); });
|
|
99
|
+
return out;
|
|
100
|
+
}
|
|
101
|
+
return value;
|
|
102
|
+
}
|
|
103
|
+
function parseObject(text) {
|
|
104
|
+
try {
|
|
105
|
+
var parsed = JSON.parse(text);
|
|
106
|
+
return isObject(parsed) ? parsed : null;
|
|
107
|
+
}
|
|
108
|
+
catch (e) {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* addInfo.additional, an object or a JSON string, with its strings decoded. A JSON string is read
|
|
114
|
+
* as it is first, so an encoded quote inside a value doesn't break it; a string whose quotes
|
|
115
|
+
* themselves arrived encoded is decoded first.
|
|
116
|
+
*/
|
|
117
|
+
function additional(value) {
|
|
118
|
+
if (isObject(value)) {
|
|
119
|
+
return decodeDeep(value);
|
|
120
|
+
}
|
|
121
|
+
if (typeof value !== 'string') { // no i18n
|
|
122
|
+
return {};
|
|
123
|
+
}
|
|
124
|
+
var parsed = parseObject(value);
|
|
125
|
+
if (parsed) {
|
|
126
|
+
return decodeDeep(parsed);
|
|
127
|
+
}
|
|
128
|
+
return parseObject(decodeEntities(value)) || {};
|
|
129
|
+
}
|
|
130
|
+
function wholeNumber(value) {
|
|
131
|
+
var n = typeof value === 'number' ? value : parseInt(str(value), 10); // no i18n
|
|
132
|
+
return isFinite(n) ? Math.floor(n) : 0;
|
|
133
|
+
}
|
|
134
|
+
/** What the browser shows for a push message's `data`. */
|
|
135
|
+
function webNotificationFrom(data) {
|
|
136
|
+
var addInfo = isObject(data.addInfo) ? data.addInfo : {};
|
|
137
|
+
var list = images(data);
|
|
138
|
+
var timer = wholeNumber(data.timer);
|
|
139
|
+
var autoScroll = data.autoScroll === true && list.length > 1;
|
|
140
|
+
var dismiss = wholeNumber(data.autoDismiss);
|
|
141
|
+
var countdown = wholeNumber(data.msgTimer);
|
|
142
|
+
var text = typeof data.msg === 'string' ? data.msg : typeof data.message === 'string' ? data.message : str(data.body); // no i18n
|
|
143
|
+
return {
|
|
144
|
+
id: str(addInfo.appticsPnID),
|
|
145
|
+
title: str(data.title),
|
|
146
|
+
text: markdownToWebText(decodeEntities(text)),
|
|
147
|
+
icon: safeUrl(data.icon),
|
|
148
|
+
images: list,
|
|
149
|
+
url: safeUrl(addInfo.clickAction) || safeUrl(data.url),
|
|
150
|
+
buttons: buttons(addInfo),
|
|
151
|
+
autoScrollSeconds: autoScroll ? Math.min(10, Math.max(1, timer || 1)) : 0,
|
|
152
|
+
countdownTo: countdown > 0 ? countdown : 0,
|
|
153
|
+
autoDismissSeconds: dismiss > 0 ? dismiss : 0,
|
|
154
|
+
requireInteraction: data.requireInteraction === true,
|
|
155
|
+
silent: data.silent === true,
|
|
156
|
+
extra: additional(addInfo.additional),
|
|
157
|
+
number: runNumber(addInfo.notificationNumber),
|
|
158
|
+
conversion: conversionEvent(addInfo.conversionEvent),
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
function runNumber(value) {
|
|
162
|
+
var n = typeof value === 'number' ? value : (typeof value === 'string' && /^\s*\d+\s*$/.test(value) ? parseInt(value, 10) : NaN); // no i18n
|
|
163
|
+
// the server declares notificationnumber an int: anything larger would refuse the whole batch
|
|
164
|
+
return isFinite(n) && n >= 0 && n <= 2147483647 && Math.floor(n) === n ? n : null;
|
|
165
|
+
}
|
|
166
|
+
function conversionEvent(value) {
|
|
167
|
+
if (!isObject(value)) {
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
var name = str(value.name).trim();
|
|
171
|
+
var group = str(value.group).trim();
|
|
172
|
+
return name && group ? { name: name, group: group } : null;
|
|
173
|
+
}
|
|
174
|
+
/** Unicode sans-serif letters, as the console's preview: [A, a, 0] starts; italic has no digits. */
|
|
175
|
+
const LETTERS = {
|
|
176
|
+
bold: [0x1d5d4, 0x1d5ee, 0x1d7ec],
|
|
177
|
+
italic: [0x1d608, 0x1d622, 0],
|
|
178
|
+
boldItalic: [0x1d63c, 0x1d656, 0x1d7ec],
|
|
179
|
+
};
|
|
180
|
+
function styleLetters(text, st) {
|
|
181
|
+
var set = st.b && st.i ? LETTERS.boldItalic : st.b ? LETTERS.bold : st.i ? LETTERS.italic : null;
|
|
182
|
+
if (!set) {
|
|
183
|
+
return text;
|
|
184
|
+
}
|
|
185
|
+
return Array.from(text, function (ch) {
|
|
186
|
+
var c = ch.codePointAt(0);
|
|
187
|
+
if (c >= 65 && c <= 90) {
|
|
188
|
+
return String.fromCodePoint(set[0] + c - 65);
|
|
189
|
+
}
|
|
190
|
+
if (c >= 97 && c <= 122) {
|
|
191
|
+
return String.fromCodePoint(set[1] + c - 97);
|
|
192
|
+
}
|
|
193
|
+
if (c >= 48 && c <= 57 && set[2]) {
|
|
194
|
+
return String.fromCodePoint(set[2] + c - 48);
|
|
195
|
+
}
|
|
196
|
+
return ch;
|
|
197
|
+
}).join(''); // no i18n
|
|
198
|
+
}
|
|
199
|
+
/** Underline (U+0332) and strike (U+0336) after each whole character, so joined scripts stay joined. */
|
|
200
|
+
function markCharacters(text, st) {
|
|
201
|
+
var marks = (st.u ? '̲' : '') + (st.s ? '̶' : ''); // no i18n
|
|
202
|
+
if (!marks) {
|
|
203
|
+
return text;
|
|
204
|
+
}
|
|
205
|
+
var Seg = (typeof Intl !== 'undefined' ? Intl.Segmenter : undefined); // no i18n
|
|
206
|
+
var parts = Seg ? Array.from(new Seg().segment(text), function (g) { return g.segment; }) : Array.from(text);
|
|
207
|
+
return parts.map(function (g) { return g.trim() ? g + marks : g; }).join(''); // no i18n
|
|
208
|
+
}
|
|
209
|
+
function escapeHtml(text) {
|
|
210
|
+
return text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"'); // no i18n
|
|
211
|
+
}
|
|
212
|
+
/** The console's markdown -> HTML chain, in its order, so the same text nests the same way. */
|
|
213
|
+
function markdownToHtml(text) {
|
|
214
|
+
var html = escapeHtml(text);
|
|
215
|
+
html = html.replace(/\{([^}]+)\}\(([^)]+)\)/g, '<font>$1</font>'); // no i18n
|
|
216
|
+
html = html.replace(/`([^`]+?)`/g, '<q>$1</q>'); // no i18n
|
|
217
|
+
html = html.replace(/\n/g, '<br>'); // no i18n
|
|
218
|
+
html = html.replace(/__(.+?)__/g, '<u>$1</u>'); // no i18n
|
|
219
|
+
html = html.replace(/\*([^*]+?)\*/g, '<b>$1</b>'); // no i18n
|
|
220
|
+
html = html.replace(/_([^_]+?)_/g, '<i>$1</i>'); // no i18n
|
|
221
|
+
html = html.replace(/~([^~]+?)~/g, '<strike>$1</strike>'); // no i18n
|
|
222
|
+
return html;
|
|
223
|
+
}
|
|
224
|
+
const TAG_STYLE = { b: 'b', i: 'i', u: 'u', strike: 's' }; // no i18n
|
|
225
|
+
/**
|
|
226
|
+
* The console's markdown (*bold*, _italic_, __underline__, ~strike~, `quote`, {text}(#color)) as
|
|
227
|
+
* the plain text a browser notification shows: bold and italic as Unicode styled letters,
|
|
228
|
+
* underline and strike as combining marks, quotes as “…”, colour dropped. The same output as the
|
|
229
|
+
* console's web preview (markdownToWebText in its pushNotificationUtils.ts).
|
|
230
|
+
*/
|
|
231
|
+
function markdownToWebText(md) {
|
|
232
|
+
if (!md) {
|
|
233
|
+
return ''; // no i18n
|
|
234
|
+
}
|
|
235
|
+
var html = markdownToHtml(md);
|
|
236
|
+
var st = { b: 0, i: 0, u: 0, s: 0 };
|
|
237
|
+
var out = ''; // no i18n
|
|
238
|
+
var last = 0;
|
|
239
|
+
var tag = /<(\/?)(b|i|u|strike|q|font|br)>/g;
|
|
240
|
+
var m;
|
|
241
|
+
var flush = function (end) {
|
|
242
|
+
if (end > last) {
|
|
243
|
+
out += markCharacters(styleLetters(decodeEntities(html.slice(last, end)), st), st);
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
while ((m = tag.exec(html)) !== null) {
|
|
247
|
+
flush(m.index);
|
|
248
|
+
last = tag.lastIndex;
|
|
249
|
+
var closing = m[1] === '/'; // no i18n
|
|
250
|
+
var name = m[2];
|
|
251
|
+
if (name === 'br') { // no i18n
|
|
252
|
+
out += '\n'; // no i18n
|
|
253
|
+
}
|
|
254
|
+
else if (name === 'q') { // no i18n
|
|
255
|
+
out += closing ? '”' : '“'; // no i18n
|
|
256
|
+
}
|
|
257
|
+
else if (TAG_STYLE[name]) {
|
|
258
|
+
var key = TAG_STYLE[name];
|
|
259
|
+
st[key] = Math.max(0, st[key] + (closing ? -1 : 1));
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
flush(html.length);
|
|
263
|
+
return out;
|
|
264
|
+
}
|
|
265
|
+
/** The time left until `targetMs` as HH:MM:SS, 00:00:00 once it has passed. */
|
|
266
|
+
function formatCountdown(targetMs, nowMs) {
|
|
267
|
+
var diff = Math.max(0, targetMs - nowMs);
|
|
268
|
+
var h = Math.floor(diff / 3600000);
|
|
269
|
+
var m = Math.floor((diff % 3600000) / 60000);
|
|
270
|
+
var s = Math.floor((diff % 60000) / 1000);
|
|
271
|
+
return [h, m, s].map(function (n) { return (n < 10 ? '0' : '') + n; }).join(':'); // no i18n
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
exports.MAX_BUTTONS = MAX_BUTTONS;
|
|
275
|
+
exports.decodeEntities = decodeEntities;
|
|
276
|
+
exports.formatCountdown = formatCountdown;
|
|
277
|
+
exports.markdownToWebText = markdownToWebText;
|
|
278
|
+
exports.safeUrl = safeUrl;
|
|
279
|
+
exports.webNotificationFrom = webNotificationFrom;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/** The most registers WMS refusing the token may cause before it connects again. */
|
|
2
|
+
export declare const AUTH_RETRY_MAX = 5;
|
|
3
|
+
/**
|
|
4
|
+
* How long a reused saved session has to connect (serverup) before it is dropped for a fresh one.
|
|
5
|
+
* WMS may have ended it already: the last page's unload unregisters its WMS session, and then
|
|
6
|
+
* register still answers but the connection never comes up. Tests shorten it.
|
|
7
|
+
*/
|
|
8
|
+
export declare const timing: {
|
|
9
|
+
savedConnectMs: number;
|
|
10
|
+
};
|
|
11
|
+
export interface PushSession {
|
|
12
|
+
prdId: string;
|
|
13
|
+
sessionID: string;
|
|
14
|
+
token: string;
|
|
15
|
+
displayName: string;
|
|
16
|
+
/** Registered by the anonymousid (anonymous tracking) rather than the deviceid. */
|
|
17
|
+
byAnonymousId: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Who hears about a new session (connect) and a dropped one (null: disconnect). `manual` is true
|
|
21
|
+
* when the app asked, which is what may retry a connection that failed to load.
|
|
22
|
+
*/
|
|
23
|
+
export declare function setSessionListener(fn: (session: PushSession | null, manual: boolean) => void): void;
|
|
24
|
+
export declare function currentSession(): PushSession | null;
|
|
25
|
+
/** Forgets the session, saved one included, so the next register asks for a new one. */
|
|
26
|
+
export declare function dropSession(): void;
|
|
27
|
+
/**
|
|
28
|
+
* WMS refused the session's token: forgets it and registers again, while fewer than
|
|
29
|
+
* AUTH_RETRY_MAX registers were caused this way since WMS last connected.
|
|
30
|
+
*/
|
|
31
|
+
export declare function sessionRefused(): void;
|
|
32
|
+
/** WMS connected: the token was taken, so refusals count again from 0. */
|
|
33
|
+
export declare function sessionConnected(): void;
|
|
34
|
+
/**
|
|
35
|
+
* Registers this browser for push. `manual` is the app asking (AppticsPushNotification.setEnabled(true)):
|
|
36
|
+
* it clears an earlier unregister, and waits for getsdkconfig when nothing has answered yet.
|
|
37
|
+
* Resolves with the session, or null when the console has push off or registering failed.
|
|
38
|
+
*/
|
|
39
|
+
export declare function registerPush(manual: boolean): Promise<PushSession | null>;
|
|
40
|
+
/** Unregisters this browser, and keeps it unregistered across visits. Resolves true on success. */
|
|
41
|
+
export declare function unregisterPush(): Promise<boolean>;
|
|
42
|
+
/**
|
|
43
|
+
* Resolves true once the SDK is running, false when its start-up failed: right away when it has
|
|
44
|
+
* started, on init()'s start-up when that is under way, and on the next init() when none was made.
|
|
45
|
+
*/
|
|
46
|
+
export declare function whenStarted(): Promise<boolean>;
|