@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,272 @@
1
+ /*! @zoho_apptics/apptics-js-sdk v2.0.0 | (c) Zoho Corporation Private Limited | see LICENSE */
2
+ /**
3
+ * The web push payload, as the server sends it to browsers (the WMS message's `data`):
4
+ *
5
+ * title, msg (the console's markdown), icon, image, images[], autoScroll, timer (seconds),
6
+ * msgTimer (epoch ms), autoDismiss (seconds), requireInteraction, silent, and
7
+ * addInfo: { appticsPnID, clickAction, additional: {...}, actionButton: [{ action, label,
8
+ * clickAction, icon }] }
9
+ *
10
+ * webNotificationFrom() turns it into what the browser shows, as the console's web preview shows
11
+ * it. The flat keys sent before this format (message, body, imageUrl, url) are still read.
12
+ * Every string is read with the HTML entities the server adds decoded, and only http(s) URLs are
13
+ * kept. Nothing here touches the DOM, so the service worker shares it.
14
+ */
15
+ /** Browsers show at most two action buttons (the console's MAX_WEB_ACTION_BUTTONS). */
16
+ const MAX_BUTTONS = 2;
17
+ const ENTITIES = { amp: '&', lt: '<', gt: '>', quot: '"', apos: '\'', nbsp: ' ' }; // no i18n
18
+ /** `text` with HTML entities (named, &#n; and &#xh;) turned back into their characters. */
19
+ function decodeEntities(text) {
20
+ return text.replace(/&(#x[0-9a-f]+|#[0-9]+|[a-z]+);/gi, function (match, ref) {
21
+ if (ref.charAt(0) === '#') {
22
+ var code = ref.charAt(1).toLowerCase() === 'x' ? parseInt(ref.slice(2), 16) : parseInt(ref.slice(1), 10); // no i18n
23
+ return isFinite(code) && code > 0 && code <= 0x10ffff ? String.fromCodePoint(code) : match;
24
+ }
25
+ var named = ENTITIES[ref.toLowerCase()];
26
+ return named === undefined ? match : named;
27
+ });
28
+ }
29
+ function isObject(value) {
30
+ return !!value && typeof value === 'object' && !Array.isArray(value); // no i18n
31
+ }
32
+ function str(value) {
33
+ if (typeof value === 'string') { // no i18n
34
+ return decodeEntities(value);
35
+ }
36
+ return typeof value === 'number' && isFinite(value) ? String(value) : ''; // no i18n
37
+ }
38
+ function base() {
39
+ var loc = typeof location !== 'undefined' ? location : undefined; // no i18n
40
+ return loc ? loc.href : 'https://invalid/'; // no i18n
41
+ }
42
+ /** `value` as an absolute http(s) URL, '' for anything else. */
43
+ function safeUrl(value) {
44
+ var raw = str(value).trim();
45
+ if (raw === '') { // no i18n
46
+ return ''; // no i18n
47
+ }
48
+ try {
49
+ var url = new URL(raw, base());
50
+ return url.protocol === 'http:' || url.protocol === 'https:' ? url.href : ''; // no i18n
51
+ }
52
+ catch (e) {
53
+ return ''; // no i18n
54
+ }
55
+ }
56
+ function images(data) {
57
+ var raw = data.images;
58
+ var list = Array.isArray(raw) ? raw
59
+ : typeof raw === 'string' ? decodeEntities(raw).replace(/^\[|\]$/g, '').split(',') : []; // no i18n
60
+ var urls = list.map(function (u) {
61
+ return safeUrl(typeof u === 'string' ? u.trim().replace(/^['"]|['"]$/g, '') : u); // no i18n
62
+ }).filter(function (u) { return u !== ''; }); // no i18n
63
+ if (urls.length === 0) {
64
+ var single = safeUrl(data.image) || safeUrl(data.imageUrl);
65
+ if (single !== '') { // no i18n
66
+ urls.push(single);
67
+ }
68
+ }
69
+ return urls;
70
+ }
71
+ function buttons(addInfo) {
72
+ var raw = Array.isArray(addInfo.actionButton) ? addInfo.actionButton : [];
73
+ var out = [];
74
+ raw.forEach(function (b) {
75
+ if (out.length >= MAX_BUTTONS || !isObject(b)) {
76
+ return;
77
+ }
78
+ var label = str(b.label).trim();
79
+ if (label === '') { // no i18n
80
+ return;
81
+ }
82
+ out.push({ action: str(b.action), label: label, url: safeUrl(b.clickAction), icon: safeUrl(b.icon) });
83
+ });
84
+ return out;
85
+ }
86
+ /** `value` with every string in it decoded, objects and arrays included. */
87
+ function decodeDeep(value) {
88
+ if (typeof value === 'string') { // no i18n
89
+ return decodeEntities(value);
90
+ }
91
+ if (Array.isArray(value)) {
92
+ return value.map(decodeDeep);
93
+ }
94
+ if (isObject(value)) {
95
+ var out = {};
96
+ Object.keys(value).forEach(function (k) { out[decodeEntities(k)] = decodeDeep(value[k]); });
97
+ return out;
98
+ }
99
+ return value;
100
+ }
101
+ function parseObject(text) {
102
+ try {
103
+ var parsed = JSON.parse(text);
104
+ return isObject(parsed) ? parsed : null;
105
+ }
106
+ catch (e) {
107
+ return null;
108
+ }
109
+ }
110
+ /**
111
+ * addInfo.additional, an object or a JSON string, with its strings decoded. A JSON string is read
112
+ * as it is first, so an encoded quote inside a value doesn't break it; a string whose quotes
113
+ * themselves arrived encoded is decoded first.
114
+ */
115
+ function additional(value) {
116
+ if (isObject(value)) {
117
+ return decodeDeep(value);
118
+ }
119
+ if (typeof value !== 'string') { // no i18n
120
+ return {};
121
+ }
122
+ var parsed = parseObject(value);
123
+ if (parsed) {
124
+ return decodeDeep(parsed);
125
+ }
126
+ return parseObject(decodeEntities(value)) || {};
127
+ }
128
+ function wholeNumber(value) {
129
+ var n = typeof value === 'number' ? value : parseInt(str(value), 10); // no i18n
130
+ return isFinite(n) ? Math.floor(n) : 0;
131
+ }
132
+ /** What the browser shows for a push message's `data`. */
133
+ function webNotificationFrom(data) {
134
+ var addInfo = isObject(data.addInfo) ? data.addInfo : {};
135
+ var list = images(data);
136
+ var timer = wholeNumber(data.timer);
137
+ var autoScroll = data.autoScroll === true && list.length > 1;
138
+ var dismiss = wholeNumber(data.autoDismiss);
139
+ var countdown = wholeNumber(data.msgTimer);
140
+ var text = typeof data.msg === 'string' ? data.msg : typeof data.message === 'string' ? data.message : str(data.body); // no i18n
141
+ return {
142
+ id: str(addInfo.appticsPnID),
143
+ title: str(data.title),
144
+ text: markdownToWebText(decodeEntities(text)),
145
+ icon: safeUrl(data.icon),
146
+ images: list,
147
+ url: safeUrl(addInfo.clickAction) || safeUrl(data.url),
148
+ buttons: buttons(addInfo),
149
+ autoScrollSeconds: autoScroll ? Math.min(10, Math.max(1, timer || 1)) : 0,
150
+ countdownTo: countdown > 0 ? countdown : 0,
151
+ autoDismissSeconds: dismiss > 0 ? dismiss : 0,
152
+ requireInteraction: data.requireInteraction === true,
153
+ silent: data.silent === true,
154
+ extra: additional(addInfo.additional),
155
+ number: runNumber(addInfo.notificationNumber),
156
+ conversion: conversionEvent(addInfo.conversionEvent),
157
+ };
158
+ }
159
+ function runNumber(value) {
160
+ var n = typeof value === 'number' ? value : (typeof value === 'string' && /^\s*\d+\s*$/.test(value) ? parseInt(value, 10) : NaN); // no i18n
161
+ // the server declares notificationnumber an int: anything larger would refuse the whole batch
162
+ return isFinite(n) && n >= 0 && n <= 2147483647 && Math.floor(n) === n ? n : null;
163
+ }
164
+ function conversionEvent(value) {
165
+ if (!isObject(value)) {
166
+ return null;
167
+ }
168
+ var name = str(value.name).trim();
169
+ var group = str(value.group).trim();
170
+ return name && group ? { name: name, group: group } : null;
171
+ }
172
+ /** Unicode sans-serif letters, as the console's preview: [A, a, 0] starts; italic has no digits. */
173
+ const LETTERS = {
174
+ bold: [0x1d5d4, 0x1d5ee, 0x1d7ec],
175
+ italic: [0x1d608, 0x1d622, 0],
176
+ boldItalic: [0x1d63c, 0x1d656, 0x1d7ec],
177
+ };
178
+ function styleLetters(text, st) {
179
+ var set = st.b && st.i ? LETTERS.boldItalic : st.b ? LETTERS.bold : st.i ? LETTERS.italic : null;
180
+ if (!set) {
181
+ return text;
182
+ }
183
+ return Array.from(text, function (ch) {
184
+ var c = ch.codePointAt(0);
185
+ if (c >= 65 && c <= 90) {
186
+ return String.fromCodePoint(set[0] + c - 65);
187
+ }
188
+ if (c >= 97 && c <= 122) {
189
+ return String.fromCodePoint(set[1] + c - 97);
190
+ }
191
+ if (c >= 48 && c <= 57 && set[2]) {
192
+ return String.fromCodePoint(set[2] + c - 48);
193
+ }
194
+ return ch;
195
+ }).join(''); // no i18n
196
+ }
197
+ /** Underline (U+0332) and strike (U+0336) after each whole character, so joined scripts stay joined. */
198
+ function markCharacters(text, st) {
199
+ var marks = (st.u ? '̲' : '') + (st.s ? '̶' : ''); // no i18n
200
+ if (!marks) {
201
+ return text;
202
+ }
203
+ var Seg = (typeof Intl !== 'undefined' ? Intl.Segmenter : undefined); // no i18n
204
+ var parts = Seg ? Array.from(new Seg().segment(text), function (g) { return g.segment; }) : Array.from(text);
205
+ return parts.map(function (g) { return g.trim() ? g + marks : g; }).join(''); // no i18n
206
+ }
207
+ function escapeHtml(text) {
208
+ return text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;'); // no i18n
209
+ }
210
+ /** The console's markdown -> HTML chain, in its order, so the same text nests the same way. */
211
+ function markdownToHtml(text) {
212
+ var html = escapeHtml(text);
213
+ html = html.replace(/\{([^}]+)\}\(([^)]+)\)/g, '<font>$1</font>'); // no i18n
214
+ html = html.replace(/`([^`]+?)`/g, '<q>$1</q>'); // no i18n
215
+ html = html.replace(/\n/g, '<br>'); // no i18n
216
+ html = html.replace(/__(.+?)__/g, '<u>$1</u>'); // no i18n
217
+ html = html.replace(/\*([^*]+?)\*/g, '<b>$1</b>'); // no i18n
218
+ html = html.replace(/_([^_]+?)_/g, '<i>$1</i>'); // no i18n
219
+ html = html.replace(/~([^~]+?)~/g, '<strike>$1</strike>'); // no i18n
220
+ return html;
221
+ }
222
+ const TAG_STYLE = { b: 'b', i: 'i', u: 'u', strike: 's' }; // no i18n
223
+ /**
224
+ * The console's markdown (*bold*, _italic_, __underline__, ~strike~, `quote`, {text}(#color)) as
225
+ * the plain text a browser notification shows: bold and italic as Unicode styled letters,
226
+ * underline and strike as combining marks, quotes as “…”, colour dropped. The same output as the
227
+ * console's web preview (markdownToWebText in its pushNotificationUtils.ts).
228
+ */
229
+ function markdownToWebText(md) {
230
+ if (!md) {
231
+ return ''; // no i18n
232
+ }
233
+ var html = markdownToHtml(md);
234
+ var st = { b: 0, i: 0, u: 0, s: 0 };
235
+ var out = ''; // no i18n
236
+ var last = 0;
237
+ var tag = /<(\/?)(b|i|u|strike|q|font|br)>/g;
238
+ var m;
239
+ var flush = function (end) {
240
+ if (end > last) {
241
+ out += markCharacters(styleLetters(decodeEntities(html.slice(last, end)), st), st);
242
+ }
243
+ };
244
+ while ((m = tag.exec(html)) !== null) {
245
+ flush(m.index);
246
+ last = tag.lastIndex;
247
+ var closing = m[1] === '/'; // no i18n
248
+ var name = m[2];
249
+ if (name === 'br') { // no i18n
250
+ out += '\n'; // no i18n
251
+ }
252
+ else if (name === 'q') { // no i18n
253
+ out += closing ? '”' : '“'; // no i18n
254
+ }
255
+ else if (TAG_STYLE[name]) {
256
+ var key = TAG_STYLE[name];
257
+ st[key] = Math.max(0, st[key] + (closing ? -1 : 1));
258
+ }
259
+ }
260
+ flush(html.length);
261
+ return out;
262
+ }
263
+ /** The time left until `targetMs` as HH:MM:SS, 00:00:00 once it has passed. */
264
+ function formatCountdown(targetMs, nowMs) {
265
+ var diff = Math.max(0, targetMs - nowMs);
266
+ var h = Math.floor(diff / 3600000);
267
+ var m = Math.floor((diff % 3600000) / 60000);
268
+ var s = Math.floor((diff % 60000) / 1000);
269
+ return [h, m, s].map(function (n) { return (n < 10 ? '0' : '') + n; }).join(':'); // no i18n
270
+ }
271
+
272
+ export { MAX_BUTTONS, decodeEntities, formatCountdown, markdownToWebText, safeUrl, 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>;