@zoho_apptics/apptics-js-sdk 2.0.0-beta.1 → 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.
Files changed (253) hide show
  1. package/CHANGELOG.md +127 -16
  2. package/README.md +357 -215
  3. package/dist/apptics-pn-sw.js +3 -0
  4. package/dist/apptics-pn-sw.js.map +1 -0
  5. package/dist/apptics.esm.min.js +2 -2
  6. package/dist/apptics.esm.min.js.map +1 -1
  7. package/dist/apptics.min.js +2 -2
  8. package/dist/apptics.min.js.map +1 -1
  9. package/dist/chunks/batch-Axq9sTzR.min.js +3 -0
  10. package/dist/chunks/batch-Axq9sTzR.min.js.map +1 -0
  11. package/dist/chunks/lifecycle-Cvg78jN_.min.js +3 -0
  12. package/dist/chunks/lifecycle-Cvg78jN_.min.js.map +1 -0
  13. package/dist/chunks/send-DBpesydB.min.js +3 -0
  14. package/dist/chunks/send-DBpesydB.min.js.map +1 -0
  15. package/dist/chunks/transport-B21X39p4.min.js +3 -0
  16. package/dist/chunks/transport-B21X39p4.min.js.map +1 -0
  17. package/dist/cjs/core/attempts.js +1 -1
  18. package/dist/cjs/core/batch.js +4 -4
  19. package/dist/cjs/core/consent.d.ts +17 -4
  20. package/dist/cjs/core/consent.js +81 -14
  21. package/dist/cjs/core/console-call.d.ts +23 -0
  22. package/dist/cjs/core/console-call.js +63 -0
  23. package/dist/cjs/core/constants.d.ts +66 -17
  24. package/dist/cjs/core/constants.js +76 -19
  25. package/dist/cjs/core/db.js +31 -7
  26. package/dist/cjs/core/debug.d.ts +6 -4
  27. package/dist/cjs/core/debug.js +36 -12
  28. package/dist/cjs/core/env.d.ts +0 -3
  29. package/dist/cjs/core/env.js +1 -9
  30. package/dist/cjs/core/framework-id.d.ts +1 -1
  31. package/dist/cjs/core/framework-id.js +3 -3
  32. package/dist/cjs/core/guard.js +19 -4
  33. package/dist/cjs/core/hooks.d.ts +29 -0
  34. package/dist/cjs/core/hooks.js +12 -1
  35. package/dist/cjs/core/locks.js +1 -1
  36. package/dist/cjs/core/logger.js +1 -1
  37. package/dist/cjs/core/shield.d.ts +31 -0
  38. package/dist/cjs/core/shield.js +129 -0
  39. package/dist/cjs/core/state.d.ts +11 -5
  40. package/dist/cjs/core/state.js +4 -4
  41. package/dist/cjs/core/storage.d.ts +7 -0
  42. package/dist/cjs/core/storage.js +28 -9
  43. package/dist/cjs/core/stylesheet.js +1 -1
  44. package/dist/cjs/core/transport.d.ts +15 -4
  45. package/dist/cjs/core/transport.js +72 -25
  46. package/dist/cjs/core/utils.js +1 -1
  47. package/dist/cjs/core/validate.js +6 -5
  48. package/dist/cjs/device/appversion.d.ts +10 -1
  49. package/dist/cjs/device/appversion.js +26 -3
  50. package/dist/cjs/device/index.d.ts +17 -2
  51. package/dist/cjs/device/index.js +251 -35
  52. package/dist/cjs/engagement/api-rules.js +1 -1
  53. package/dist/cjs/engagement/auto-api.js +4 -3
  54. package/dist/cjs/engagement/auto-screen.js +10 -6
  55. package/dist/cjs/engagement/defined-events.d.ts +2 -3
  56. package/dist/cjs/engagement/defined-events.js +10 -16
  57. package/dist/cjs/engagement/send.js +7 -3
  58. package/dist/cjs/engagement/session.d.ts +17 -0
  59. package/dist/cjs/engagement/session.js +154 -23
  60. package/dist/cjs/engagement/track.d.ts +4 -4
  61. package/dist/cjs/engagement/track.js +23 -17
  62. package/dist/cjs/errors/send.js +2 -2
  63. package/dist/cjs/errors/track.d.ts +2 -1
  64. package/dist/cjs/errors/track.js +8 -5
  65. package/dist/cjs/feedback/controls.d.ts +36 -4
  66. package/dist/cjs/feedback/controls.js +302 -67
  67. package/dist/cjs/feedback/i18n/index.d.ts +31 -0
  68. package/dist/cjs/feedback/i18n/index.js +187 -0
  69. package/dist/cjs/feedback/i18n/strings.d.ts +9 -0
  70. package/dist/cjs/feedback/i18n/strings.js +8 -0
  71. package/dist/cjs/feedback/index.js +1 -1
  72. package/dist/cjs/feedback/logs.d.ts +3 -6
  73. package/dist/cjs/feedback/logs.js +12 -21
  74. package/dist/cjs/feedback/quartz.js +5 -2
  75. package/dist/cjs/feedback/send.d.ts +6 -3
  76. package/dist/cjs/feedback/send.js +59 -41
  77. package/dist/cjs/feedback/styles.js +2 -2
  78. package/dist/cjs/feedback/template.d.ts +4 -2
  79. package/dist/cjs/feedback/template.js +73 -44
  80. package/dist/cjs/feedback/ui.d.ts +47 -4
  81. package/dist/cjs/feedback/ui.js +351 -97
  82. package/dist/cjs/heatmap/send.d.ts +2 -0
  83. package/dist/cjs/heatmap/send.js +3 -5
  84. package/dist/cjs/heatmap/track.js +13 -9
  85. package/dist/cjs/index.d.ts +1 -2
  86. package/dist/cjs/index.js +55 -18
  87. package/dist/cjs/lifecycle.d.ts +13 -2
  88. package/dist/cjs/lifecycle.js +233 -118
  89. package/dist/cjs/pushnotification/display.d.ts +65 -0
  90. package/dist/cjs/pushnotification/display.js +112 -0
  91. package/dist/cjs/pushnotification/index.d.ts +20 -0
  92. package/dist/cjs/pushnotification/index.js +96 -0
  93. package/dist/cjs/pushnotification/kept-opens.d.ts +23 -0
  94. package/dist/cjs/pushnotification/kept-opens.js +64 -0
  95. package/dist/cjs/pushnotification/notify.d.ts +45 -0
  96. package/dist/cjs/pushnotification/notify.js +476 -0
  97. package/dist/cjs/pushnotification/payload.d.ts +65 -0
  98. package/dist/cjs/pushnotification/payload.js +279 -0
  99. package/dist/cjs/pushnotification/session.d.ts +46 -0
  100. package/dist/cjs/pushnotification/session.js +413 -0
  101. package/dist/cjs/pushnotification/stats.d.ts +45 -0
  102. package/dist/cjs/pushnotification/stats.js +244 -0
  103. package/dist/cjs/pushnotification/wms.d.ts +30 -0
  104. package/dist/cjs/pushnotification/wms.js +374 -0
  105. package/dist/cjs/remoteconfig/country.js +1 -1
  106. package/dist/cjs/remoteconfig/custom.js +4 -3
  107. package/dist/cjs/remoteconfig/evaluate.js +1 -1
  108. package/dist/cjs/remoteconfig/fetch.d.ts +17 -10
  109. package/dist/cjs/remoteconfig/fetch.js +146 -32
  110. package/dist/cjs/remoteconfig/index.d.ts +9 -5
  111. package/dist/cjs/remoteconfig/index.js +24 -32
  112. package/dist/cjs/remoteconfig/store.d.ts +15 -7
  113. package/dist/cjs/remoteconfig/store.js +68 -35
  114. package/dist/cjs/remoteconfig/tz-countries.js +1 -1
  115. package/dist/cjs/{core → remotelog}/callsite.d.ts +5 -4
  116. package/dist/cjs/{core → remotelog}/callsite.js +6 -5
  117. package/dist/cjs/remotelog/gate.js +1 -1
  118. package/dist/cjs/remotelog/logger.js +2 -2
  119. package/dist/cjs/remotelog/send.js +6 -5
  120. package/dist/cjs/remotelogger/index.js +1 -1
  121. package/dist/cjs/scheduler.d.ts +3 -1
  122. package/dist/cjs/scheduler.js +34 -25
  123. package/dist/cjs/sw/apptics-pn-sw.d.ts +83 -0
  124. package/dist/cjs/sw/timers.d.ts +44 -0
  125. package/dist/cjs/types.d.ts +90 -29
  126. package/dist/cjs/user/index.d.ts +7 -0
  127. package/dist/cjs/user/index.js +25 -3
  128. package/dist/esm/core/attempts.js +1 -1
  129. package/dist/esm/core/batch.js +4 -4
  130. package/dist/esm/core/consent.d.ts +17 -4
  131. package/dist/esm/core/consent.js +84 -20
  132. package/dist/esm/core/console-call.d.ts +23 -0
  133. package/dist/esm/core/console-call.js +60 -0
  134. package/dist/esm/core/constants.d.ts +66 -17
  135. package/dist/esm/core/constants.js +73 -20
  136. package/dist/esm/core/db.js +31 -7
  137. package/dist/esm/core/debug.d.ts +6 -4
  138. package/dist/esm/core/debug.js +37 -13
  139. package/dist/esm/core/env.d.ts +0 -3
  140. package/dist/esm/core/env.js +2 -9
  141. package/dist/esm/core/framework-id.d.ts +1 -1
  142. package/dist/esm/core/framework-id.js +3 -3
  143. package/dist/esm/core/guard.js +19 -4
  144. package/dist/esm/core/hooks.d.ts +29 -0
  145. package/dist/esm/core/hooks.js +12 -1
  146. package/dist/esm/core/locks.js +1 -1
  147. package/dist/esm/core/logger.js +1 -1
  148. package/dist/esm/core/shield.d.ts +31 -0
  149. package/dist/esm/core/shield.js +119 -0
  150. package/dist/esm/core/state.d.ts +11 -5
  151. package/dist/esm/core/state.js +4 -4
  152. package/dist/esm/core/storage.d.ts +7 -0
  153. package/dist/esm/core/storage.js +28 -11
  154. package/dist/esm/core/stylesheet.js +1 -1
  155. package/dist/esm/core/transport.d.ts +15 -4
  156. package/dist/esm/core/transport.js +73 -28
  157. package/dist/esm/core/utils.js +1 -1
  158. package/dist/esm/core/validate.js +6 -5
  159. package/dist/esm/device/appversion.d.ts +10 -1
  160. package/dist/esm/device/appversion.js +26 -4
  161. package/dist/esm/device/index.d.ts +17 -2
  162. package/dist/esm/device/index.js +255 -42
  163. package/dist/esm/engagement/api-rules.js +1 -1
  164. package/dist/esm/engagement/auto-api.js +4 -3
  165. package/dist/esm/engagement/auto-screen.js +10 -6
  166. package/dist/esm/engagement/defined-events.d.ts +2 -3
  167. package/dist/esm/engagement/defined-events.js +10 -16
  168. package/dist/esm/engagement/send.js +7 -3
  169. package/dist/esm/engagement/session.d.ts +17 -0
  170. package/dist/esm/engagement/session.js +152 -24
  171. package/dist/esm/engagement/track.d.ts +4 -4
  172. package/dist/esm/engagement/track.js +24 -18
  173. package/dist/esm/errors/send.js +2 -2
  174. package/dist/esm/errors/track.d.ts +2 -1
  175. package/dist/esm/errors/track.js +8 -5
  176. package/dist/esm/feedback/controls.d.ts +36 -4
  177. package/dist/esm/feedback/controls.js +298 -68
  178. package/dist/esm/feedback/i18n/index.d.ts +31 -0
  179. package/dist/esm/feedback/i18n/index.js +178 -0
  180. package/dist/esm/feedback/i18n/strings.d.ts +9 -0
  181. package/dist/esm/feedback/i18n/strings.js +4 -0
  182. package/dist/esm/feedback/index.js +1 -1
  183. package/dist/esm/feedback/logs.d.ts +3 -6
  184. package/dist/esm/feedback/logs.js +12 -21
  185. package/dist/esm/feedback/quartz.js +5 -2
  186. package/dist/esm/feedback/send.d.ts +6 -3
  187. package/dist/esm/feedback/send.js +61 -44
  188. package/dist/esm/feedback/styles.js +2 -2
  189. package/dist/esm/feedback/template.d.ts +4 -2
  190. package/dist/esm/feedback/template.js +73 -44
  191. package/dist/esm/feedback/ui.d.ts +47 -4
  192. package/dist/esm/feedback/ui.js +353 -99
  193. package/dist/esm/heatmap/send.d.ts +2 -0
  194. package/dist/esm/heatmap/send.js +3 -5
  195. package/dist/esm/heatmap/track.js +13 -9
  196. package/dist/esm/index.d.ts +1 -2
  197. package/dist/esm/index.js +58 -21
  198. package/dist/esm/lifecycle.d.ts +13 -2
  199. package/dist/esm/lifecycle.js +238 -125
  200. package/dist/esm/pushnotification/display.d.ts +65 -0
  201. package/dist/esm/pushnotification/display.js +95 -0
  202. package/dist/esm/pushnotification/index.d.ts +20 -0
  203. package/dist/esm/pushnotification/index.js +91 -0
  204. package/dist/esm/pushnotification/kept-opens.d.ts +23 -0
  205. package/dist/esm/pushnotification/kept-opens.js +62 -0
  206. package/dist/esm/pushnotification/notify.d.ts +45 -0
  207. package/dist/esm/pushnotification/notify.js +469 -0
  208. package/dist/esm/pushnotification/payload.d.ts +65 -0
  209. package/dist/esm/pushnotification/payload.js +272 -0
  210. package/dist/esm/pushnotification/session.d.ts +46 -0
  211. package/dist/esm/pushnotification/session.js +402 -0
  212. package/dist/esm/pushnotification/stats.d.ts +45 -0
  213. package/dist/esm/pushnotification/stats.js +238 -0
  214. package/dist/esm/pushnotification/wms.d.ts +30 -0
  215. package/dist/esm/pushnotification/wms.js +368 -0
  216. package/dist/esm/remoteconfig/country.js +1 -1
  217. package/dist/esm/remoteconfig/custom.js +4 -3
  218. package/dist/esm/remoteconfig/evaluate.js +1 -1
  219. package/dist/esm/remoteconfig/fetch.d.ts +17 -10
  220. package/dist/esm/remoteconfig/fetch.js +147 -33
  221. package/dist/esm/remoteconfig/index.d.ts +9 -5
  222. package/dist/esm/remoteconfig/index.js +24 -32
  223. package/dist/esm/remoteconfig/store.d.ts +15 -7
  224. package/dist/esm/remoteconfig/store.js +68 -36
  225. package/dist/esm/remoteconfig/tz-countries.js +1 -1
  226. package/dist/esm/{core → remotelog}/callsite.d.ts +5 -4
  227. package/dist/esm/{core → remotelog}/callsite.js +6 -5
  228. package/dist/esm/remotelog/gate.js +1 -1
  229. package/dist/esm/remotelog/logger.js +2 -2
  230. package/dist/esm/remotelog/send.js +6 -5
  231. package/dist/esm/remotelogger/index.js +1 -1
  232. package/dist/esm/scheduler.d.ts +3 -1
  233. package/dist/esm/scheduler.js +35 -27
  234. package/dist/esm/sw/apptics-pn-sw.d.ts +83 -0
  235. package/dist/esm/sw/timers.d.ts +44 -0
  236. package/dist/esm/types.d.ts +90 -29
  237. package/dist/esm/user/index.d.ts +7 -0
  238. package/dist/esm/user/index.js +26 -5
  239. package/dist/feedback.esm.min.js +2 -2
  240. package/dist/feedback.esm.min.js.map +1 -1
  241. package/dist/pushnotification.esm.min.js +3 -0
  242. package/dist/pushnotification.esm.min.js.map +1 -0
  243. package/dist/remoteconfig.esm.min.js +3 -0
  244. package/dist/remoteconfig.esm.min.js.map +1 -0
  245. package/dist/remotelogger.esm.min.js +3 -0
  246. package/dist/remotelogger.esm.min.js.map +1 -0
  247. package/package.json +17 -3
  248. package/dist/chunks/lifecycle-VYr43KcB.min.js +0 -3
  249. package/dist/chunks/lifecycle-VYr43KcB.min.js.map +0 -1
  250. package/dist/cjs/auto-init.d.ts +0 -8
  251. package/dist/cjs/auto-init.js +0 -32
  252. package/dist/esm/auto-init.d.ts +0 -8
  253. package/dist/esm/auto-init.js +0 -29
@@ -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, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;'); // 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>;