@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.
Files changed (223) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/README.md +229 -174
  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 -3
  19. package/dist/cjs/core/consent.d.ts +9 -6
  20. package/dist/cjs/core/consent.js +63 -10
  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 +44 -0
  24. package/dist/cjs/core/constants.js +55 -1
  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.js +1 -1
  29. package/dist/cjs/core/framework-id.d.ts +1 -1
  30. package/dist/cjs/core/framework-id.js +3 -3
  31. package/dist/cjs/core/guard.js +19 -4
  32. package/dist/cjs/core/hooks.d.ts +25 -1
  33. package/dist/cjs/core/hooks.js +11 -1
  34. package/dist/cjs/core/locks.js +1 -1
  35. package/dist/cjs/core/logger.js +1 -1
  36. package/dist/cjs/core/shield.d.ts +31 -0
  37. package/dist/cjs/core/shield.js +129 -0
  38. package/dist/cjs/core/state.d.ts +5 -1
  39. package/dist/cjs/core/state.js +3 -1
  40. package/dist/cjs/core/storage.d.ts +7 -0
  41. package/dist/cjs/core/storage.js +28 -6
  42. package/dist/cjs/core/stylesheet.js +1 -1
  43. package/dist/cjs/core/transport.d.ts +15 -4
  44. package/dist/cjs/core/transport.js +63 -13
  45. package/dist/cjs/core/utils.js +1 -1
  46. package/dist/cjs/core/validate.js +6 -5
  47. package/dist/cjs/device/appversion.js +1 -1
  48. package/dist/cjs/device/index.js +63 -15
  49. package/dist/cjs/engagement/api-rules.js +1 -1
  50. package/dist/cjs/engagement/auto-api.js +4 -3
  51. package/dist/cjs/engagement/auto-screen.js +10 -6
  52. package/dist/cjs/engagement/defined-events.d.ts +2 -3
  53. package/dist/cjs/engagement/defined-events.js +10 -16
  54. package/dist/cjs/engagement/send.js +1 -1
  55. package/dist/cjs/engagement/session.js +77 -37
  56. package/dist/cjs/engagement/track.js +9 -6
  57. package/dist/cjs/errors/send.js +1 -1
  58. package/dist/cjs/errors/track.js +3 -2
  59. package/dist/cjs/feedback/controls.d.ts +30 -4
  60. package/dist/cjs/feedback/controls.js +237 -51
  61. package/dist/cjs/feedback/i18n/index.d.ts +31 -0
  62. package/dist/cjs/feedback/i18n/index.js +187 -0
  63. package/dist/cjs/feedback/i18n/strings.d.ts +9 -0
  64. package/dist/cjs/feedback/i18n/strings.js +8 -0
  65. package/dist/cjs/feedback/index.js +1 -1
  66. package/dist/cjs/feedback/logs.js +5 -4
  67. package/dist/cjs/feedback/quartz.js +5 -2
  68. package/dist/cjs/feedback/send.d.ts +4 -1
  69. package/dist/cjs/feedback/send.js +56 -15
  70. package/dist/cjs/feedback/styles.js +2 -2
  71. package/dist/cjs/feedback/template.d.ts +4 -2
  72. package/dist/cjs/feedback/template.js +67 -46
  73. package/dist/cjs/feedback/ui.d.ts +40 -4
  74. package/dist/cjs/feedback/ui.js +208 -89
  75. package/dist/cjs/heatmap/send.js +1 -1
  76. package/dist/cjs/heatmap/track.js +13 -9
  77. package/dist/cjs/index.js +2 -2
  78. package/dist/cjs/lifecycle.js +119 -72
  79. package/dist/cjs/pushnotification/display.d.ts +65 -0
  80. package/dist/cjs/pushnotification/display.js +112 -0
  81. package/dist/cjs/pushnotification/index.d.ts +20 -0
  82. package/dist/cjs/pushnotification/index.js +96 -0
  83. package/dist/cjs/pushnotification/kept-opens.d.ts +23 -0
  84. package/dist/cjs/pushnotification/kept-opens.js +64 -0
  85. package/dist/cjs/pushnotification/notify.d.ts +45 -0
  86. package/dist/cjs/pushnotification/notify.js +476 -0
  87. package/dist/cjs/pushnotification/payload.d.ts +65 -0
  88. package/dist/cjs/pushnotification/payload.js +279 -0
  89. package/dist/cjs/pushnotification/session.d.ts +46 -0
  90. package/dist/cjs/pushnotification/session.js +413 -0
  91. package/dist/cjs/pushnotification/stats.d.ts +45 -0
  92. package/dist/cjs/pushnotification/stats.js +244 -0
  93. package/dist/cjs/pushnotification/wms.d.ts +30 -0
  94. package/dist/cjs/pushnotification/wms.js +374 -0
  95. package/dist/cjs/remoteconfig/country.js +1 -1
  96. package/dist/cjs/remoteconfig/custom.js +4 -3
  97. package/dist/cjs/remoteconfig/evaluate.js +1 -1
  98. package/dist/cjs/remoteconfig/fetch.js +27 -8
  99. package/dist/cjs/remoteconfig/index.d.ts +1 -6
  100. package/dist/cjs/remoteconfig/index.js +4 -28
  101. package/dist/cjs/remoteconfig/store.js +1 -1
  102. package/dist/cjs/remoteconfig/tz-countries.js +1 -1
  103. package/dist/cjs/remotelog/callsite.js +1 -1
  104. package/dist/cjs/remotelog/gate.js +1 -1
  105. package/dist/cjs/remotelog/logger.js +1 -1
  106. package/dist/cjs/remotelog/send.js +5 -4
  107. package/dist/cjs/remotelogger/index.js +1 -1
  108. package/dist/cjs/scheduler.js +11 -5
  109. package/dist/cjs/sw/apptics-pn-sw.d.ts +83 -0
  110. package/dist/cjs/sw/timers.d.ts +44 -0
  111. package/dist/cjs/types.d.ts +31 -15
  112. package/dist/cjs/user/index.d.ts +7 -0
  113. package/dist/cjs/user/index.js +25 -7
  114. package/dist/esm/core/attempts.js +1 -1
  115. package/dist/esm/core/batch.js +4 -3
  116. package/dist/esm/core/consent.d.ts +9 -6
  117. package/dist/esm/core/consent.js +67 -16
  118. package/dist/esm/core/console-call.d.ts +23 -0
  119. package/dist/esm/core/console-call.js +60 -0
  120. package/dist/esm/core/constants.d.ts +44 -0
  121. package/dist/esm/core/constants.js +52 -2
  122. package/dist/esm/core/db.js +31 -7
  123. package/dist/esm/core/debug.d.ts +6 -4
  124. package/dist/esm/core/debug.js +37 -13
  125. package/dist/esm/core/env.js +1 -1
  126. package/dist/esm/core/framework-id.d.ts +1 -1
  127. package/dist/esm/core/framework-id.js +3 -3
  128. package/dist/esm/core/guard.js +19 -4
  129. package/dist/esm/core/hooks.d.ts +25 -1
  130. package/dist/esm/core/hooks.js +11 -1
  131. package/dist/esm/core/locks.js +1 -1
  132. package/dist/esm/core/logger.js +1 -1
  133. package/dist/esm/core/shield.d.ts +31 -0
  134. package/dist/esm/core/shield.js +119 -0
  135. package/dist/esm/core/state.d.ts +5 -1
  136. package/dist/esm/core/state.js +3 -1
  137. package/dist/esm/core/storage.d.ts +7 -0
  138. package/dist/esm/core/storage.js +28 -8
  139. package/dist/esm/core/stylesheet.js +1 -1
  140. package/dist/esm/core/transport.d.ts +15 -4
  141. package/dist/esm/core/transport.js +64 -16
  142. package/dist/esm/core/utils.js +1 -1
  143. package/dist/esm/core/validate.js +6 -5
  144. package/dist/esm/device/appversion.js +1 -1
  145. package/dist/esm/device/index.js +67 -19
  146. package/dist/esm/engagement/api-rules.js +1 -1
  147. package/dist/esm/engagement/auto-api.js +4 -3
  148. package/dist/esm/engagement/auto-screen.js +10 -6
  149. package/dist/esm/engagement/defined-events.d.ts +2 -3
  150. package/dist/esm/engagement/defined-events.js +10 -16
  151. package/dist/esm/engagement/send.js +1 -1
  152. package/dist/esm/engagement/session.js +77 -37
  153. package/dist/esm/engagement/track.js +9 -6
  154. package/dist/esm/errors/send.js +1 -1
  155. package/dist/esm/errors/track.js +3 -2
  156. package/dist/esm/feedback/controls.d.ts +30 -4
  157. package/dist/esm/feedback/controls.js +234 -52
  158. package/dist/esm/feedback/i18n/index.d.ts +31 -0
  159. package/dist/esm/feedback/i18n/index.js +178 -0
  160. package/dist/esm/feedback/i18n/strings.d.ts +9 -0
  161. package/dist/esm/feedback/i18n/strings.js +4 -0
  162. package/dist/esm/feedback/index.js +1 -1
  163. package/dist/esm/feedback/logs.js +5 -4
  164. package/dist/esm/feedback/quartz.js +5 -2
  165. package/dist/esm/feedback/send.d.ts +4 -1
  166. package/dist/esm/feedback/send.js +56 -16
  167. package/dist/esm/feedback/styles.js +2 -2
  168. package/dist/esm/feedback/template.d.ts +4 -2
  169. package/dist/esm/feedback/template.js +67 -46
  170. package/dist/esm/feedback/ui.d.ts +40 -4
  171. package/dist/esm/feedback/ui.js +210 -91
  172. package/dist/esm/heatmap/send.js +1 -1
  173. package/dist/esm/heatmap/track.js +13 -9
  174. package/dist/esm/index.js +2 -2
  175. package/dist/esm/lifecycle.js +120 -73
  176. package/dist/esm/pushnotification/display.d.ts +65 -0
  177. package/dist/esm/pushnotification/display.js +95 -0
  178. package/dist/esm/pushnotification/index.d.ts +20 -0
  179. package/dist/esm/pushnotification/index.js +91 -0
  180. package/dist/esm/pushnotification/kept-opens.d.ts +23 -0
  181. package/dist/esm/pushnotification/kept-opens.js +62 -0
  182. package/dist/esm/pushnotification/notify.d.ts +45 -0
  183. package/dist/esm/pushnotification/notify.js +469 -0
  184. package/dist/esm/pushnotification/payload.d.ts +65 -0
  185. package/dist/esm/pushnotification/payload.js +272 -0
  186. package/dist/esm/pushnotification/session.d.ts +46 -0
  187. package/dist/esm/pushnotification/session.js +402 -0
  188. package/dist/esm/pushnotification/stats.d.ts +45 -0
  189. package/dist/esm/pushnotification/stats.js +238 -0
  190. package/dist/esm/pushnotification/wms.d.ts +30 -0
  191. package/dist/esm/pushnotification/wms.js +368 -0
  192. package/dist/esm/remoteconfig/country.js +1 -1
  193. package/dist/esm/remoteconfig/custom.js +4 -3
  194. package/dist/esm/remoteconfig/evaluate.js +1 -1
  195. package/dist/esm/remoteconfig/fetch.js +27 -8
  196. package/dist/esm/remoteconfig/index.d.ts +1 -6
  197. package/dist/esm/remoteconfig/index.js +4 -28
  198. package/dist/esm/remoteconfig/store.js +1 -1
  199. package/dist/esm/remoteconfig/tz-countries.js +1 -1
  200. package/dist/esm/remotelog/callsite.js +1 -1
  201. package/dist/esm/remotelog/gate.js +1 -1
  202. package/dist/esm/remotelog/logger.js +1 -1
  203. package/dist/esm/remotelog/send.js +5 -4
  204. package/dist/esm/remotelogger/index.js +1 -1
  205. package/dist/esm/scheduler.js +11 -5
  206. package/dist/esm/sw/apptics-pn-sw.d.ts +83 -0
  207. package/dist/esm/sw/timers.d.ts +44 -0
  208. package/dist/esm/types.d.ts +31 -15
  209. package/dist/esm/user/index.d.ts +7 -0
  210. package/dist/esm/user/index.js +26 -9
  211. package/dist/feedback.esm.min.js +2 -2
  212. package/dist/feedback.esm.min.js.map +1 -1
  213. package/dist/pushnotification.esm.min.js +3 -0
  214. package/dist/pushnotification.esm.min.js.map +1 -0
  215. package/dist/remoteconfig.esm.min.js +2 -2
  216. package/dist/remoteconfig.esm.min.js.map +1 -1
  217. package/dist/remotelogger.esm.min.js +2 -2
  218. package/dist/remotelogger.esm.min.js.map +1 -1
  219. package/package.json +15 -2
  220. package/dist/chunks/lifecycle-C6m1W7jo.min.js +0 -3
  221. package/dist/chunks/lifecycle-C6m1W7jo.min.js.map +0 -1
  222. package/dist/chunks/send-CgUO82ne.min.js +0 -3
  223. package/dist/chunks/send-CgUO82ne.min.js.map +0 -1
@@ -1,8 +1,9 @@
1
- /*! @zoho_apptics/apptics-js-sdk v2.0.0-beta.2 | (c) Zoho Corporation Private Limited | see LICENSE */
1
+ /*! @zoho_apptics/apptics-js-sdk v2.0.0 | (c) Zoho Corporation Private Limited | see LICENSE */
2
2
  'use strict';
3
3
 
4
4
  var logger = require('./logger.js');
5
5
  var utils = require('./utils.js');
6
+ var shield = require('./shield.js');
6
7
 
7
8
  const DB_NAME = 'apptics'; // no i18n
8
9
  // 3 added the heatmaps store. 4 renamed: each record's order key `seq` to `queue`, the logs store
@@ -189,12 +190,33 @@ function recordType(storeName, item) {
189
190
  function putRecord(store, item, keepExisting) {
190
191
  const id = String(item.id);
191
192
  const lookup = store.get(id);
192
- lookup.onsuccess = function () {
193
+ lookup.onsuccess = inTransaction(store.transaction, function () {
193
194
  const existing = lookup.result;
194
195
  if (existing && keepExisting) {
195
196
  return;
196
197
  }
197
198
  store.put({ id: id, queue: existing ? existing.queue : nextQueue(), type: recordType(store.name, item), item: item });
199
+ });
200
+ }
201
+ /**
202
+ * An IndexedDB callback that never throws into the page (core/shield.ts). A throw in one aborts its
203
+ * transaction, which is how its caller hears that the write failed; that is kept, by aborting it here.
204
+ */
205
+ function inTransaction(tx, fn) {
206
+ return function () {
207
+ try {
208
+ fn();
209
+ }
210
+ catch (err) {
211
+ shield.sdkFailed('storage', err); // no i18n
212
+ try {
213
+ if (tx)
214
+ tx.abort();
215
+ }
216
+ catch (e) {
217
+ // already finished: nothing left to undo
218
+ }
219
+ }
198
220
  };
199
221
  }
200
222
  /** Our stores, as created by onupgradeneeded. */
@@ -255,7 +277,9 @@ function openOnce(factory, timeoutMs) {
255
277
  return;
256
278
  }
257
279
  req.onupgradeneeded = function () {
258
- upgrade(req.result, req.transaction);
280
+ inTransaction(req.transaction, function () {
281
+ upgrade(req.result, req.transaction);
282
+ })();
259
283
  };
260
284
  req.onsuccess = function () {
261
285
  if (settled) {
@@ -333,7 +357,7 @@ function upgrade(db, tx) {
333
357
  /** Calls `each` for every record of `store`, then `done`, inside the transaction `store` is in. */
334
358
  function eachRecord(store, each, done) {
335
359
  const req = store.openCursor();
336
- req.onsuccess = function () {
360
+ req.onsuccess = inTransaction(store.transaction, function () {
337
361
  const cursor = req.result;
338
362
  if (!cursor) {
339
363
  if (done)
@@ -342,7 +366,7 @@ function eachRecord(store, each, done) {
342
366
  }
343
367
  each(cursor.value, cursor);
344
368
  cursor.continue();
345
- };
369
+ });
346
370
  }
347
371
  /** A version 3 record under version 4's names: `queue` for `seq`, and the feedback types renamed. */
348
372
  function renamedRecord(record, feedback, storeName) {
@@ -408,11 +432,11 @@ function createIndexedDBBackend(db) {
408
432
  const settingsStore = tx.objectStore('settings'); // no i18n
409
433
  Object.keys(settings).forEach(function (key) {
410
434
  const lookup = settingsStore.get(key);
411
- lookup.onsuccess = function () {
435
+ lookup.onsuccess = inTransaction(tx, function () {
412
436
  if (lookup.result === undefined) {
413
437
  settingsStore.put(settings[key], key);
414
438
  }
415
- };
439
+ });
416
440
  });
417
441
  QUEUES.forEach(function (name) {
418
442
  const objectStore = tx.objectStore(name);
@@ -13,10 +13,12 @@ export declare function noteDebugActivity(): void;
13
13
  export declare function expireDebugIfIdle(): void;
14
14
  /**
15
15
  * Turns debug mode on, at any time: before init(), during start-up or while the SDK runs. The
16
- * choice holds over `debug` in init() for the rest of the page's life.
16
+ * choice holds through init() and reset() for the rest of the page's life. Only from the console.
17
17
  */
18
18
  export declare function enableDebug(): void;
19
- /** Turns debug mode off, at any time, with the same hold over `debug` as enableDebug(). */
19
+ /**
20
+ * Turns debug mode off, at any time, holding as enableDebug() does. Only from the console.
21
+ */
20
22
  export declare function disableDebug(): void;
21
- /** What init() applies for `debug`: the config's value, unless the app has already chosen. */
22
- export declare function applyDebugConfig(configured: boolean): void;
23
+ /** What init() applies: off, unless enableDebug() or disableDebug() already chose. */
24
+ export declare function applyDebugConfig(): void;
@@ -1,9 +1,10 @@
1
- /*! @zoho_apptics/apptics-js-sdk v2.0.0-beta.2 | (c) Zoho Corporation Private Limited | see LICENSE */
1
+ /*! @zoho_apptics/apptics-js-sdk v2.0.0 | (c) Zoho Corporation Private Limited | see LICENSE */
2
2
  'use strict';
3
3
 
4
4
  var constants = require('./constants.js');
5
5
  var state = require('./state.js');
6
6
  var logger = require('./logger.js');
7
+ var consoleCall = require('./console-call.js');
7
8
  var utils = require('./utils.js');
8
9
 
9
10
  /**
@@ -16,8 +17,8 @@ var utils = require('./utils.js');
16
17
  * not a deliberate switch-off. So the SDK closes it: an hour with nothing tracked turns debug
17
18
  * back off by itself, and anything tracked pushes that hour out again.
18
19
  *
19
- * It lives in core because every send asks it: `debug: true` in init(), or enableDebug(), is
20
- * enough to turn the twins on, and that alone must expire.
20
+ * It lives in core because every send asks it: enableDebug(), typed in the browser console, is
21
+ * the only way to turn the twins on, and that alone must expire.
21
22
  */
22
23
  /** Whether debug mode is on right now, idle hour included. */
23
24
  function debugEnabled() {
@@ -50,10 +51,9 @@ function expireDebugIfIdle() {
50
51
  setDebug(false);
51
52
  }
52
53
  /**
53
- * The app's own choice, from enableDebug() or disableDebug(). It wins over `debug` in init(),
54
- * so debug mode can be switched on or off with one call, before init() runs or while the SDK is
55
- * running, and an init() or reset() that comes after doesn't switch it back. null until the app
56
- * has chosen.
54
+ * The choice made in the console, by enableDebug() or disableDebug(): before init() runs or while
55
+ * the SDK is running, and an init() or reset() that comes after doesn't switch it back. null until
56
+ * one is called.
57
57
  */
58
58
  var chosen = null;
59
59
  /** Turning it on starts the idle hour; turning it off clears it, so the next on gets a whole hour. */
@@ -62,22 +62,46 @@ function setDebug(on) {
62
62
  state._ZAP._debugUntil = on ? utils.nowMs() + constants.DEBUG_IDLE_MS : 0;
63
63
  logger.Console.log('apptics: debug mode ' + (on ? 'on' : 'off')); // no i18n
64
64
  }
65
+ /** The calls already refused for coming from code: said once per page each, not once per call. */
66
+ var refusedSaid = {};
67
+ /**
68
+ * Whether `call` was typed into the browser console. A call from the page's code is ignored and
69
+ * said once, debug or not, so a debug switch left in an app's code does nothing in production.
70
+ */
71
+ function fromConsole(call) {
72
+ if (consoleCall.calledFromConsole()) {
73
+ return true;
74
+ }
75
+ if (!refusedSaid[call]) {
76
+ refusedSaid[call] = true;
77
+ logger.warnAlways('apptics: ' + call + '() works only when typed in the browser console; this call from code is ignored'); // no i18n
78
+ }
79
+ return false;
80
+ }
65
81
  /**
66
82
  * Turns debug mode on, at any time: before init(), during start-up or while the SDK runs. The
67
- * choice holds over `debug` in init() for the rest of the page's life.
83
+ * choice holds through init() and reset() for the rest of the page's life. Only from the console.
68
84
  */
69
85
  function enableDebug() {
86
+ if (!fromConsole('Apptics.enableDebug')) { // no i18n
87
+ return;
88
+ }
70
89
  chosen = true;
71
90
  setDebug(true);
72
91
  }
73
- /** Turns debug mode off, at any time, with the same hold over `debug` as enableDebug(). */
92
+ /**
93
+ * Turns debug mode off, at any time, holding as enableDebug() does. Only from the console.
94
+ */
74
95
  function disableDebug() {
96
+ if (!fromConsole('Apptics.disableDebug')) { // no i18n
97
+ return;
98
+ }
75
99
  chosen = false;
76
100
  setDebug(false);
77
101
  }
78
- /** What init() applies for `debug`: the config's value, unless the app has already chosen. */
79
- function applyDebugConfig(configured) {
80
- setDebug(chosen !== null ? chosen : configured);
102
+ /** What init() applies: off, unless enableDebug() or disableDebug() already chose. */
103
+ function applyDebugConfig() {
104
+ setDebug(chosen === true);
81
105
  }
82
106
 
83
107
  exports.applyDebugConfig = applyDebugConfig;
@@ -1,4 +1,4 @@
1
- /*! @zoho_apptics/apptics-js-sdk v2.0.0-beta.2 | (c) Zoho Corporation Private Limited | see LICENSE */
1
+ /*! @zoho_apptics/apptics-js-sdk v2.0.0 | (c) Zoho Corporation Private Limited | see LICENSE */
2
2
  'use strict';
3
3
 
4
4
  var constants = require('./constants.js');
@@ -1 +1 @@
1
- export declare const FRAMEWORK_ID = 6003;
1
+ export declare const FRAMEWORK_ID = 6012;
@@ -1,9 +1,9 @@
1
- /*! @zoho_apptics/apptics-js-sdk v2.0.0-beta.2 | (c) Zoho Corporation Private Limited | see LICENSE */
1
+ /*! @zoho_apptics/apptics-js-sdk v2.0.0 | (c) Zoho Corporation Private Limited | see LICENSE */
2
2
  'use strict';
3
3
 
4
4
  // Generated by scripts/register-version.mjs — do not edit by hand.
5
5
  // The framework id Apptics issued for this SDK, from POST /sdk/web/v1/framework/addversion
6
- // (version 2.0.0-beta.2, platform Browser). Regenerated on every npm pack.
7
- const FRAMEWORK_ID = 6003;
6
+ // (version 2.0.0, platform Browser). Regenerated on every npm pack.
7
+ const FRAMEWORK_ID = 6012;
8
8
 
9
9
  exports.FRAMEWORK_ID = FRAMEWORK_ID;
@@ -1,8 +1,9 @@
1
- /*! @zoho_apptics/apptics-js-sdk v2.0.0-beta.2 | (c) Zoho Corporation Private Limited | see LICENSE */
1
+ /*! @zoho_apptics/apptics-js-sdk v2.0.0 | (c) Zoho Corporation Private Limited | see LICENSE */
2
2
  'use strict';
3
3
 
4
4
  var state = require('./state.js');
5
5
  var logger = require('./logger.js');
6
+ var shield = require('./shield.js');
6
7
 
7
8
  /**
8
9
  * Calls that run immediately while storage is loading. Everything else is buffered and replayed in order.
@@ -18,9 +19,14 @@ const RUN_BEFORE_READY = {
18
19
  // a switch, and a call that hands back the id endTrackApi needs: neither can wait in a queue
19
20
  'AppticsApi.configure': true, 'AppticsApi.startTrackApi': true,
20
21
  // these wait for ready() themselves, and a queued call would hand back undefined, not a Promise
21
- 'AppticsRemoteConfig.fetchValue': true, 'AppticsRemoteConfig.fetchValues': true,
22
+ 'AppticsRemoteConfig.fetchValues': true,
22
23
  'AppticsRemoteConfig.setCustomConditionValue': true,
23
24
  'Apptics.enableDebug': true, 'Apptics.disableDebug': true,
25
+ // these wait for start-up themselves, for the same reason as remote config's
26
+ 'AppticsPushNotification.setEnabled': true,
27
+ 'AppticsPushNotification.isEnabled': true,
28
+ 'AppticsPushNotification.requestPermission': true,
29
+ // 'AppticsPushNotification.onNotificationClick': true, (held back; see pushnotification/index.ts)
24
30
  };
25
31
  /**
26
32
  * Calls that record or send something, and so are lost when the SDK hasn't started. Calls that only
@@ -31,7 +37,7 @@ const RUN_BEFORE_READY = {
31
37
  const NEEDS_INIT = {
32
38
  'AppticsEvent.addEvent': true, 'AppticsScreen.inScreen': true, 'AppticsScreen.outScreen': true,
33
39
  'AppticsApi.endTrackApi': true, 'AppticsError.trackError': true, 'AppticsUser.setUser': true,
34
- 'Apptics.flush': true, AppticsLogger: true, 'AppticsFeedback.sendFeedback': true, 'AppticsRemoteConfig.fetchValue': true,
40
+ 'Apptics.flush': true, AppticsLogger: true, 'AppticsFeedback.sendFeedback': true,
35
41
  'AppticsRemoteConfig.fetchValues': true,
36
42
  };
37
43
  /** How a call is named in a message: every public call is named after its object, as `AppticsEvent.addEvent`. */
@@ -56,7 +62,16 @@ function guard(name, fn) {
56
62
  return undefined;
57
63
  }
58
64
  try {
59
- return fn(...args);
65
+ var result = fn(...args);
66
+ if (result && typeof result.then === 'function') { // no i18n
67
+ // a rejection the app leaves unhandled is still the SDK's failure, not the app's
68
+ // JS error (lifecycle's unhandledrejection listener)
69
+ return result.then(undefined, function (reason) {
70
+ shield.markSdkRejection(reason);
71
+ throw reason;
72
+ });
73
+ }
74
+ return result;
60
75
  }
61
76
  catch (err) {
62
77
  // a public call swallowing its own exception into a debug-gated console line is how
@@ -38,7 +38,31 @@ export declare const hooks: {
38
38
  remoteConfigUserChanged: () => void;
39
39
  /**
40
40
  * Set by device/index.ts: getsdkconfig is asked now, outside its next_check_after. setUser calls
41
- * it once a user is registered, and remote config when getupdates reports a module changed.
41
+ * it for a user whose customer group is not tracked, setTrackingStatus for that user when PII
42
+ * starts or stops, and remote config when getupdates reports a module changed.
42
43
  */
43
44
  askServerSettings: () => void;
45
+ /** Set by user/index.ts: whether user/register answered customergrouptracking: false for the active user. */
46
+ activeUserGroupUntracked: () => boolean;
47
+ /**
48
+ * Set by pushnotification/session.ts: the module ids getsdkconfig is asked about in `moduleids`.
49
+ * Push's 16 is what makes the answer carry the `wms` block; without the push entry, none.
50
+ */
51
+ sdkConfigModuleIds: () => string[];
52
+ /** Set by pushnotification/session.ts: getsdkconfig's push flag or wms block was applied, live or restored. */
53
+ pushConfigChanged: () => void;
54
+ /** Set by pushnotification/session.ts: the visitor's tracking status changed. */
55
+ pushTrackingChanged: () => void;
56
+ /** Set by pushnotification/session.ts: start-up has finished. */
57
+ pushStarted: () => void;
58
+ /** Set by pushnotification/session.ts, so reset() can forget the push session without importing it. */
59
+ resetPush: () => void;
60
+ /** Set by pushnotification/session.ts: device/add's ids are stored, the anonymousid among them. */
61
+ pushDeviceIdsChanged: () => void;
62
+ /** Set by pushnotification/session.ts: init() has begun start-up, so _ZAP._readyPromise exists. */
63
+ pushInitCalled: () => void;
64
+ /** Set by pushnotification/stats.ts, so flush() and the send interval send push stats too. */
65
+ sendPushStats: (forget?: boolean) => Promise<void>;
66
+ /** Set by pushnotification/stats.ts: the app tracked an event, which may be a push's conversion. */
67
+ pushEventTracked: (eventName: string, groupName: string) => void;
44
68
  };
@@ -1,4 +1,4 @@
1
- /*! @zoho_apptics/apptics-js-sdk v2.0.0-beta.2 | (c) Zoho Corporation Private Limited | see LICENSE */
1
+ /*! @zoho_apptics/apptics-js-sdk v2.0.0 | (c) Zoho Corporation Private Limited | see LICENSE */
2
2
  'use strict';
3
3
 
4
4
  /**
@@ -18,6 +18,16 @@ const hooks = {
18
18
  remoteConfigStarted: () => { },
19
19
  remoteConfigUserChanged: () => { },
20
20
  askServerSettings: () => { },
21
+ activeUserGroupUntracked: () => false,
22
+ sdkConfigModuleIds: () => [],
23
+ pushConfigChanged: () => { },
24
+ pushTrackingChanged: () => { },
25
+ pushStarted: () => { },
26
+ resetPush: () => { },
27
+ pushDeviceIdsChanged: () => { },
28
+ pushInitCalled: () => { },
29
+ sendPushStats: () => Promise.resolve(),
30
+ pushEventTracked: () => { },
21
31
  };
22
32
 
23
33
  exports.hooks = hooks;
@@ -1,4 +1,4 @@
1
- /*! @zoho_apptics/apptics-js-sdk v2.0.0-beta.2 | (c) Zoho Corporation Private Limited | see LICENSE */
1
+ /*! @zoho_apptics/apptics-js-sdk v2.0.0 | (c) Zoho Corporation Private Limited | see LICENSE */
2
2
  'use strict';
3
3
 
4
4
  /**
@@ -1,4 +1,4 @@
1
- /*! @zoho_apptics/apptics-js-sdk v2.0.0-beta.2 | (c) Zoho Corporation Private Limited | see LICENSE */
1
+ /*! @zoho_apptics/apptics-js-sdk v2.0.0 | (c) Zoho Corporation Private Limited | see LICENSE */
2
2
  'use strict';
3
3
 
4
4
  var state = require('./state.js');
@@ -0,0 +1,31 @@
1
+ /**
2
+ * The SDK's own failures stay the SDK's. A throw in one of its timers or listeners, or a rejection
3
+ * no one in the SDK waits on, would otherwise reach the page's `error` and `unhandledrejection`
4
+ * events, where the SDK's error tracking records it as the app's JS error and sends it.
5
+ *
6
+ * guard() shields the public calls; shield() and quietly() shield everything the SDK runs later.
7
+ * Element errors (the SDK's script, style and form elements) are told apart by isSdkElement.
8
+ */
9
+ /**
10
+ * Said in the console and nowhere else. An Error is a real failure (a bug, storage refusing), said
11
+ * whether or not debug is on; anything else is one of the SDK's own reasons for not doing
12
+ * something, as "nothing to send", said in debug mode.
13
+ */
14
+ export declare function sdkFailed(label: string, err: unknown): void;
15
+ /**
16
+ * A callback the SDK hands to the browser (a timer, a listener, a storage or network callback)
17
+ * that never throws into it. A promise it returns is waited on the same way, so an async
18
+ * listener's rejection is not left unhandled either. Wrap once and keep the wrapped function where
19
+ * it is removed again later: removeEventListener needs the same reference.
20
+ */
21
+ export declare function shield<F extends (...args: any[]) => any>(label: string, fn: F): F;
22
+ /** A promise the SDK starts and does not wait on: its rejection is said in the console, not left unhandled. */
23
+ export declare function quietly(label: string, promise: PromiseLike<unknown> | unknown): void;
24
+ export declare function markSdkRejection(reason: unknown): void;
25
+ export declare function isSdkRejection(reason: unknown): boolean;
26
+ /** Marks the elements the SDK adds to the page; isSdkElement knows them and what is inside them. */
27
+ export declare const SDK_ELEMENT_ATTR = "data-apptics";
28
+ /** Whether an element is the SDK's own: its style, the Quartz script, the feedback form or the recording timer. */
29
+ export declare function isSdkElement(target: unknown): boolean;
30
+ export declare function noteSdkScript(src: string | null | undefined): void;
31
+ export declare function isSdkScript(filename: string | null | undefined): boolean;
@@ -0,0 +1,129 @@
1
+ /*! @zoho_apptics/apptics-js-sdk v2.0.0 | (c) Zoho Corporation Private Limited | see LICENSE */
2
+ 'use strict';
3
+
4
+ var logger = require('./logger.js');
5
+
6
+ /**
7
+ * The SDK's own failures stay the SDK's. A throw in one of its timers or listeners, or a rejection
8
+ * no one in the SDK waits on, would otherwise reach the page's `error` and `unhandledrejection`
9
+ * events, where the SDK's error tracking records it as the app's JS error and sends it.
10
+ *
11
+ * guard() shields the public calls; shield() and quietly() shield everything the SDK runs later.
12
+ * Element errors (the SDK's script, style and form elements) are told apart by isSdkElement.
13
+ */
14
+ /**
15
+ * Said in the console and nowhere else. An Error is a real failure (a bug, storage refusing), said
16
+ * whether or not debug is on; anything else is one of the SDK's own reasons for not doing
17
+ * something, as "nothing to send", said in debug mode.
18
+ */
19
+ function sdkFailed(label, err) {
20
+ try {
21
+ if (err instanceof Error) {
22
+ logger.warnAlways('apptics: ' + label + ' failed:', err); // no i18n
23
+ logger.logFailure(label, err);
24
+ }
25
+ else {
26
+ logger.Console.log('apptics: ' + label + ': ' + String(err)); // no i18n
27
+ }
28
+ }
29
+ catch (e) {
30
+ // the console itself failing must not turn into the error this keeps off the page
31
+ }
32
+ }
33
+ /**
34
+ * A callback the SDK hands to the browser (a timer, a listener, a storage or network callback)
35
+ * that never throws into it. A promise it returns is waited on the same way, so an async
36
+ * listener's rejection is not left unhandled either. Wrap once and keep the wrapped function where
37
+ * it is removed again later: removeEventListener needs the same reference.
38
+ */
39
+ function shield(label, fn) {
40
+ return function () {
41
+ try {
42
+ var result = fn.apply(this, arguments);
43
+ if (result && typeof result.then === 'function') { // no i18n
44
+ quietly(label, result);
45
+ }
46
+ return result;
47
+ }
48
+ catch (err) {
49
+ sdkFailed(label, err);
50
+ return undefined;
51
+ }
52
+ };
53
+ }
54
+ /** A promise the SDK starts and does not wait on: its rejection is said in the console, not left unhandled. */
55
+ function quietly(label, promise) {
56
+ if (!promise || typeof promise.then !== 'function') { // no i18n
57
+ return;
58
+ }
59
+ promise.then(undefined, function (err) {
60
+ sdkFailed(label, err);
61
+ });
62
+ }
63
+ /**
64
+ * Reasons the SDK rejected one of the app's promises with (sendFeedback, ready, flush, fetchValues):
65
+ * the app may not handle them, and then the rejection is still the SDK's failure, not the app's.
66
+ * Objects by identity; strings and other primitives by value, a few dozen at most.
67
+ */
68
+ const sdkReasonObjects = typeof WeakSet === 'function' ? new WeakSet() : undefined; // no i18n
69
+ const sdkReasonValues = [];
70
+ const MAX_REASON_VALUES = 50;
71
+ function markSdkRejection(reason) {
72
+ if (reason !== null && (typeof reason === 'object' || typeof reason === 'function')) { // no i18n
73
+ if (sdkReasonObjects) {
74
+ sdkReasonObjects.add(reason);
75
+ }
76
+ return;
77
+ }
78
+ if (sdkReasonValues.indexOf(reason) === -1) {
79
+ sdkReasonValues.push(reason);
80
+ if (sdkReasonValues.length > MAX_REASON_VALUES) {
81
+ sdkReasonValues.shift();
82
+ }
83
+ }
84
+ }
85
+ function isSdkRejection(reason) {
86
+ if (reason !== null && (typeof reason === 'object' || typeof reason === 'function')) { // no i18n
87
+ return !!sdkReasonObjects && sdkReasonObjects.has(reason);
88
+ }
89
+ return reason !== undefined && sdkReasonValues.indexOf(reason) !== -1;
90
+ }
91
+ /** Marks the elements the SDK adds to the page; isSdkElement knows them and what is inside them. */
92
+ const SDK_ELEMENT_ATTR = 'data-apptics'; // no i18n
93
+ /** Whether an element is the SDK's own: its style, the Quartz script, the feedback form or the recording timer. */
94
+ function isSdkElement(target) {
95
+ var el = target;
96
+ if (!el || typeof el.closest !== 'function') { // no i18n
97
+ return false;
98
+ }
99
+ try {
100
+ return !!el.closest('[' + SDK_ELEMENT_ATTR + '], #zasdkFeedbackModal, #zasdkrectimer'); // no i18n
101
+ }
102
+ catch (err) {
103
+ return false;
104
+ }
105
+ }
106
+ /**
107
+ * Scripts whose own errors are the SDK's: the SDK file, when it was loaded as a plain script, and
108
+ * the Quartz recorder it loads. An npm build is part of the app's own bundle, so its file says
109
+ * nothing; shield() and quietly() are what keep its failures off the page.
110
+ */
111
+ const sdkScripts = [];
112
+ function noteSdkScript(src) {
113
+ if (src && sdkScripts.indexOf(src) === -1) {
114
+ sdkScripts.push(src);
115
+ }
116
+ }
117
+ function isSdkScript(filename) {
118
+ return !!filename && sdkScripts.indexOf(filename) !== -1;
119
+ }
120
+
121
+ exports.SDK_ELEMENT_ATTR = SDK_ELEMENT_ATTR;
122
+ exports.isSdkElement = isSdkElement;
123
+ exports.isSdkRejection = isSdkRejection;
124
+ exports.isSdkScript = isSdkScript;
125
+ exports.markSdkRejection = markSdkRejection;
126
+ exports.noteSdkScript = noteSdkScript;
127
+ exports.quietly = quietly;
128
+ exports.sdkFailed = sdkFailed;
129
+ exports.shield = shield;
@@ -1,5 +1,5 @@
1
1
  import { type ApConfig, type EngagementType } from './constants.js';
2
- import type { DeviceInfo, Dict, QuartzSettings, TrackingStatus, UserInfo } from '../types.js';
2
+ import type { DeviceInfo, Dict, QuartzSettings, TrackingStatus, UserInfo, WmsConfig } from '../types.js';
3
3
  /** Runtime state shared by every module (the former `_ZAP` object). */
4
4
  export interface State {
5
5
  _initialised: boolean;
@@ -46,6 +46,10 @@ export interface State {
46
46
  _remoteConfigReported: boolean;
47
47
  /** getsdkconfig module 12. */
48
48
  _feedbackEnabled: boolean;
49
+ /** getsdkconfig module 16, and a usable `wms` block with it: off until both say otherwise. */
50
+ _pushEnabled: boolean;
51
+ /** getsdkconfig's `wms` block, null until an answer carries a usable one. */
52
+ _wmsConfig: WmsConfig | null;
49
53
  /** getsdkconfig's `quartz` block: screen recording in the feedback form. Off until it says otherwise. */
50
54
  _quartz: QuartzSettings;
51
55
  /** Epoch ms getsdkconfig asked us to wait until before asking again. 0 means no answer yet. */
@@ -1,4 +1,4 @@
1
- /*! @zoho_apptics/apptics-js-sdk v2.0.0-beta.2 | (c) Zoho Corporation Private Limited | see LICENSE */
1
+ /*! @zoho_apptics/apptics-js-sdk v2.0.0 | (c) Zoho Corporation Private Limited | see LICENSE */
2
2
  'use strict';
3
3
 
4
4
  var constants = require('./constants.js');
@@ -40,6 +40,8 @@ function initialState() {
40
40
  _remoteConfigEnabled: true,
41
41
  _remoteConfigReported: true,
42
42
  _feedbackEnabled: true,
43
+ _pushEnabled: false,
44
+ _wmsConfig: null,
43
45
  _nextConfigCheck: 0,
44
46
  _debugUntil: 0,
45
47
  _errorTracking: true,
@@ -49,6 +49,13 @@ export declare const user_defaults: {
49
49
  * A key storage doesn't hold keeps this tab's value.
50
50
  */
51
51
  export declare function reloadSettings(keys: string[]): Promise<void>;
52
+ /**
53
+ * The tracking status a value names: one of AP_TRACKING_STATUS, or the number it is stored as
54
+ * (TRACKING_STATUS_CODE). Anything else names none.
55
+ */
56
+ export declare function trackingStatusFrom(value: unknown): TrackingStatus | undefined;
57
+ /** The number a tracking status is stored as. */
58
+ export declare function trackingStatusCode(status: TrackingStatus): number;
52
59
  /** The visitor's tracking status, stored in trackinfo as tracking_status. */
53
60
  export declare function storedTrackingStatus(): TrackingStatus | undefined;
54
61
  /** Opt-in status, stored in the trackinfo setting as tracking_status. */
@@ -1,4 +1,4 @@
1
- /*! @zoho_apptics/apptics-js-sdk v2.0.0-beta.2 | (c) Zoho Corporation Private Limited | see LICENSE */
1
+ /*! @zoho_apptics/apptics-js-sdk v2.0.0 | (c) Zoho Corporation Private Limited | see LICENSE */
2
2
  'use strict';
3
3
 
4
4
  var constants = require('./constants.js');
@@ -273,14 +273,32 @@ function reloadSettings(keys) {
273
273
  });
274
274
  });
275
275
  }
276
+ /**
277
+ * The tracking status a value names: one of AP_TRACKING_STATUS, or the number it is stored as
278
+ * (TRACKING_STATUS_CODE). Anything else names none.
279
+ */
280
+ function trackingStatusFrom(value) {
281
+ if (typeof value === 'string' && constants.TRACKING_STATUS_CODE.hasOwnProperty(value)) { // no i18n
282
+ return value;
283
+ }
284
+ var names = Object.keys(constants.TRACKING_STATUS_CODE);
285
+ for (var i = 0; i < names.length; i++) {
286
+ if (constants.TRACKING_STATUS_CODE[names[i]] === value) {
287
+ return names[i];
288
+ }
289
+ }
290
+ return undefined;
291
+ }
292
+ /** The number a tracking status is stored as. */
293
+ function trackingStatusCode(status) {
294
+ return constants.TRACKING_STATUS_CODE[status];
295
+ }
276
296
  /** The visitor's tracking status, stored in trackinfo as tracking_status. */
277
297
  function storedTrackingStatus() {
278
298
  var track = settings.trackinfo;
279
- var status = track && typeof track === 'object' ? track.tracking_status : undefined; // no i18n
280
299
  // a status only: getsdkconfig's own answer uses the same key for its per-module flags, and
281
300
  // one stored by mistake must not read as a consent and stop all tracking
282
- return status === constants.AP_TRACKING_STATUS.USAGE_TRACKING_WITH_PII || status === constants.AP_TRACKING_STATUS.USAGE_TRACKING_WITHOUT_PII
283
- || status === constants.AP_TRACKING_STATUS.NO_TRACKING ? status : undefined;
301
+ return trackingStatusFrom(track && typeof track === 'object' ? track.tracking_status : undefined); // no i18n
284
302
  }
285
303
  /** Opt-in status, stored in the trackinfo setting as tracking_status. */
286
304
  const tracking_preference = {
@@ -293,10 +311,12 @@ const tracking_preference = {
293
311
  },
294
312
  update_status(tracking_status) {
295
313
  state._ZAP._devicestatus = tracking_status;
314
+ // stored as its number, which earlier builds read back the same way
315
+ var code = trackingStatusCode(tracking_status);
296
316
  var track = Object.assign({}, settings.trackinfo && typeof settings.trackinfo === 'object' ? settings.trackinfo : {}); // no i18n
297
- track.tracking_status = tracking_status;
317
+ track.tracking_status = code;
298
318
  if (state._ZAP._trackinfo && typeof state._ZAP._trackinfo === 'object') { // no i18n
299
- state._ZAP._trackinfo.tracking_status = tracking_status;
319
+ state._ZAP._trackinfo.tracking_status = code;
300
320
  }
301
321
  setSetting('trackinfo', track); // no i18n
302
322
  },
@@ -320,5 +340,7 @@ exports.remotelog_transactions = remotelog_transactions;
320
340
  exports.setDeviceInfoKey = setDeviceInfoKey;
321
341
  exports.storageReady = storageReady;
322
342
  exports.storedTrackingStatus = storedTrackingStatus;
343
+ exports.trackingStatusCode = trackingStatusCode;
344
+ exports.trackingStatusFrom = trackingStatusFrom;
323
345
  exports.tracking_preference = tracking_preference;
324
346
  exports.user_defaults = user_defaults;
@@ -1,4 +1,4 @@
1
- /*! @zoho_apptics/apptics-js-sdk v2.0.0-beta.2 | (c) Zoho Corporation Private Limited | see LICENSE */
1
+ /*! @zoho_apptics/apptics-js-sdk v2.0.0 | (c) Zoho Corporation Private Limited | see LICENSE */
2
2
  'use strict';
3
3
 
4
4
  /**