@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,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 logger = require('../core/logger.js');
@@ -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('../core/constants.js');
@@ -11,6 +11,7 @@ var index = require('../device/index.js');
11
11
  var lifecycle = require('../lifecycle.js');
12
12
  var custom = require('./custom.js');
13
13
  var store = require('./store.js');
14
+ var shield = require('../core/shield.js');
14
15
 
15
16
  /**
16
17
  * The getupdates call.
@@ -36,7 +37,7 @@ var inFlightWhole = false;
36
37
  var generation = 0;
37
38
  /**
38
39
  * When getupdates is asked again, after the first of a page load: every POLL_MS. Coming back to
39
- * the tab asks nothing; the poll's timer carries on. fetchValue() and fetchValues() never ask
40
+ * the tab asks nothing; the poll's timer carries on. fetchValues() never ask
40
41
  * themselves once a fetch has succeeded: a value read on every render must not be a request on
41
42
  * every render.
42
43
  */
@@ -49,6 +50,13 @@ const COLD_LIMIT = 3;
49
50
  const COLD_WINDOW_MS = 60 * 1000;
50
51
  /** When a fetch on this page last succeeded; 0 until one has, and the next one sends flagtime 0. */
51
52
  var fetchedAt = 0;
53
+ /**
54
+ * When a fetch last failed, or 0. Until this page has an answer of its own, fetchValues asks again
55
+ * only RETRY_AFTER_FAILURE_MS after a failure: asked at once on every call, a page that calls it on
56
+ * every render, or one whose getupdates keeps being refused, asked hundreds of times a minute.
57
+ */
58
+ var failedAt = 0;
59
+ const RETRY_AFTER_FAILURE_MS = 30 * 1000;
52
60
  /** When the coldFetch calls of the last minute went out. */
53
61
  var coldCalls = [];
54
62
  var pollTimer = null;
@@ -134,7 +142,7 @@ function fetchRemoteConfig(whole) {
134
142
  logger.Console.log(LABEL + ': switched off by the server, not asking'); // no i18n
135
143
  return Promise.resolve({});
136
144
  }
137
- var blocked = transport.rejectIfOffline(LABEL) || transport.rejectIfNoDeviceIds(LABEL);
145
+ var blocked = transport.rejectIfOffline(LABEL) || transport.rejectIfNoDeviceIds(LABEL, 'getupdates');
138
146
  if (blocked) {
139
147
  return blocked;
140
148
  }
@@ -152,6 +160,7 @@ function fetchRemoteConfig(whole) {
152
160
  applyReportedModules(data);
153
161
  var rules = data.remoteconfig;
154
162
  fetchedAt = utils.nowMs();
163
+ failedAt = 0;
155
164
  if (askWhole) {
156
165
  // with flagtime 0 the answer is the whole set, and no block means there is nothing in it
157
166
  store.store(rules && typeof rules === 'object' ? rules : {}, askedAt);
@@ -169,6 +178,9 @@ function fetchRemoteConfig(whole) {
169
178
  settle();
170
179
  return data;
171
180
  }, function (err) {
181
+ if (asked === generation) {
182
+ failedAt = utils.nowMs();
183
+ }
172
184
  settle();
173
185
  return Promise.reject(err);
174
186
  });
@@ -196,6 +208,7 @@ function resetRemoteConfig() {
196
208
  inFlight = null;
197
209
  inFlightWhole = false;
198
210
  fetchedAt = 0;
211
+ failedAt = 0;
199
212
  coldCalls = [];
200
213
  if (pollTimer !== null) {
201
214
  clearTimeout(pollTimer);
@@ -236,6 +249,12 @@ function obtain(coldFetch) {
236
249
  if (fetchedAt > 0 && !cold) {
237
250
  return true;
238
251
  }
252
+ // no answer on this page yet, and the last try failed moments ago: the stored values answer
253
+ // until RETRY_AFTER_FAILURE_MS has passed, and the polling keeps trying meanwhile
254
+ if (!cold && failedAt > 0 && utils.nowMs() - failedAt < RETRY_AFTER_FAILURE_MS) {
255
+ logger.Console.log(LABEL + ': the last fetch failed ' + (utils.nowMs() - failedAt) + ' ms ago; answering from the stored values'); // no i18n
256
+ return false;
257
+ }
239
258
  return index.deviceReady().then(function () {
240
259
  return fetchRemoteConfig(cold);
241
260
  }).then(function () {
@@ -252,11 +271,11 @@ function refresh(reason) {
252
271
  return;
253
272
  }
254
273
  logger.Console.log(LABEL + ': asking for changes (' + reason + ')'); // no i18n
255
- index.deviceReady().then(function () {
274
+ shield.quietly(LABEL, index.deviceReady().then(function () {
256
275
  return fetchRemoteConfig();
257
276
  }).catch(function (err) {
258
277
  logger.Console.log(LABEL + ': fetch failed: ' + String(err)); // no i18n
259
- }).then(keepPolling);
278
+ }).then(keepPolling));
260
279
  }
261
280
  /**
262
281
  * A fetch that never went out (offline, the device not registered yet, the server switched it
@@ -272,14 +291,14 @@ function schedulePoll() {
272
291
  if (pollTimer !== null) {
273
292
  clearTimeout(pollTimer);
274
293
  }
275
- pollTimer = setTimeout(function () {
294
+ pollTimer = setTimeout(shield.shield(LABEL, function () {
276
295
  pollTimer = null;
277
296
  refresh('every ' + POLL_MS + ' ms'); // no i18n
278
- }, POLL_MS);
297
+ }), POLL_MS);
279
298
  }
280
299
  /** Start-up's own fetch, so values are this session's without the app asking, then the polling. */
281
300
  function fetchOnStart() {
282
- obtain().then(keepPolling);
301
+ shield.quietly(LABEL, obtain().then(keepPolling));
283
302
  }
284
303
  hooks.hooks.resetRemoteConfig = resetRemoteConfig;
285
304
  hooks.hooks.remoteConfigStarted = fetchOnStart;
@@ -1,10 +1,5 @@
1
- /** AppticsRemoteConfig: fetchValue, fetchValues and setCustomConditionValue, each with the parameter names the console shows. */
1
+ /** AppticsRemoteConfig: fetchValues and setCustomConditionValue, each with the parameter names the console shows. */
2
2
  export declare const AppticsRemoteConfig: {
3
- /** One parameter's value, null when there is none. coldFetch (false by default) asks the server for the whole set now. */
4
- fetchValue: {
5
- (name: string, callback?: (value: string | null) => void, coldFetch?: boolean): Promise<string | null>;
6
- (name: string, coldFetch: boolean): Promise<string | null>;
7
- };
8
3
  /**
9
4
  * The parameters named, or every parameter when none are: name -> value, null when there is
10
5
  * none. coldFetch (false by default) asks the server for the whole set now.
@@ -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
  Object.defineProperty(exports, '__esModule', { value: true });
@@ -13,7 +13,7 @@ var store = require('./store.js');
13
13
  * Remote config, shipped as its own entry point:
14
14
  * import { AppticsRemoteConfig } from '@zoho_apptics/apptics-js-sdk/remote-config';
15
15
  *
16
- * fetchValue(name) reads one parameter, fetchValues(['a', 'b']) several, and fetchValues() every
16
+ * fetchValues(['a']) reads one parameter, fetchValues(['a', 'b']) several, and fetchValues() every
17
17
  * parameter the console has. Each parameter's value is the console's: the value of the first
18
18
  * condition, in the console's order, that this device matches, else the parameter's default value.
19
19
  * setCustomConditionValue(conditionname, 'a,b') answers the custom conditions.
@@ -42,30 +42,11 @@ function answer(value, callback) {
42
42
  }
43
43
  return value;
44
44
  }
45
- /**
46
- * One parameter, fetched for this page, as Android's fetchValue: resolves with its value, or null
47
- * when the console has no such parameter. A failed fetch answers with the value fetched before.
48
- *
49
- * `coldFetch` (false by default) asks the server now with flagtime 0, for the whole set, and
50
- * answers from that instead of what this page already has. It may come in place of the callback.
51
- */
52
- function fetchValue(name, callback, coldFetch) {
53
- if (typeof callback === 'boolean') { // no i18n
54
- // fetchValue(name, coldFetch)
55
- coldFetch = callback;
56
- callback = undefined;
57
- }
58
- var done = typeof callback === 'function' ? callback : undefined; // no i18n
59
- return fetch.obtain(coldFetch === true).then(function () {
60
- var value = raw(name);
61
- return answer(value === undefined ? null : value, done);
62
- });
63
- }
64
45
  /**
65
46
  * Several parameters at once: `names` lists the ones wanted, and the result has exactly those
66
47
  * names, null for one the console does not have. With no names (or an empty list), every
67
48
  * parameter the console has. A callback may come first when there are no names, and `coldFetch`
68
- * (false by default, as for fetchValue) last, in place of either.
49
+ * (false by default) last, in place of either.
69
50
  */
70
51
  function fetchValues(names, callback, coldFetch) {
71
52
  var args = [names, callback, coldFetch];
@@ -103,15 +84,10 @@ function wantedNames(names) {
103
84
  });
104
85
  return out.length === 0 ? null : out;
105
86
  }
106
- const fetchValueGuarded = guard.guard('AppticsRemoteConfig.fetchValue', fetchValue); // no i18n
107
87
  const fetchValuesGuarded = guard.guard('AppticsRemoteConfig.fetchValues', fetchValues); // no i18n
108
88
  const setCustomConditionValueGuarded = guard.guard('AppticsRemoteConfig.setCustomConditionValue', custom.setCustomConditionValue); // no i18n
109
- /** AppticsRemoteConfig: fetchValue, fetchValues and setCustomConditionValue, each with the parameter names the console shows. */
89
+ /** AppticsRemoteConfig: fetchValues and setCustomConditionValue, each with the parameter names the console shows. */
110
90
  const AppticsRemoteConfig = {
111
- /** One parameter's value, null when there is none. coldFetch (false by default) asks the server for the whole set now. */
112
- fetchValue: function fetchValue(name, callback, coldFetch) {
113
- return guard.forward(fetchValueGuarded, arguments);
114
- },
115
91
  /**
116
92
  * The parameters named, or every parameter when none are: name -> value, null when there is
117
93
  * none. coldFetch (false by default) asks the server for the whole set now.
@@ -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 logger = require('../core/logger.js');
@@ -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
  /**
@@ -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('../core/state.js');
@@ -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('../core/constants.js');
@@ -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('../core/constants.js');
@@ -8,6 +8,7 @@ var utils = require('../core/utils.js');
8
8
  var storage = require('../core/storage.js');
9
9
  var transport = require('../core/transport.js');
10
10
  var gate = require('./gate.js');
11
+ var shield = require('../core/shield.js');
11
12
 
12
13
  /**
13
14
  * Delivery for the remote logger.
@@ -67,10 +68,10 @@ function scheduleSend() {
67
68
  return;
68
69
  }
69
70
  sendScheduled = true;
70
- setTimeout(function () {
71
+ setTimeout(shield.shield(LABEL, function () {
71
72
  sendScheduled = false;
72
- sendStoredLogs();
73
- }, SEND_DELAY_MS);
73
+ shield.quietly(LABEL, sendStoredLogs());
74
+ }), SEND_DELAY_MS);
74
75
  }
75
76
  /** Drops the oldest lines once the queue is over MAX_STORED_BYTES, keeping the newest that fit. */
76
77
  function trim(items) {
@@ -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
  Object.defineProperty(exports, '__esModule', { value: true });
@@ -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('./core/state.js');
@@ -11,6 +11,7 @@ var send$1 = require('./errors/send.js');
11
11
  var hooks = require('./core/hooks.js');
12
12
  var index = require('./device/index.js');
13
13
  var debug = require('./core/debug.js');
14
+ var shield = require('./core/shield.js');
14
15
 
15
16
  /**
16
17
  * Sends everything queued now. With `forget`, the requests are sent without waiting for a
@@ -27,6 +28,9 @@ function flush(forget) {
27
28
  }).then(function () {
28
29
  // the hook heatmap/send.ts sets
29
30
  return hooks.hooks.sendHeatmaps(forget);
31
+ }).then(function () {
32
+ // and the one pushnotification/stats.ts sets
33
+ return hooks.hooks.sendPushStats(forget);
30
34
  });
31
35
  }
32
36
  /**
@@ -51,19 +55,21 @@ var sendingInterval = null;
51
55
  /** Starts the flush interval once; later calls do nothing until stopTimers(). */
52
56
  function startTimers() {
53
57
  if (sendingInterval === null) {
54
- sendingInterval = setInterval(function () {
58
+ sendingInterval = setInterval(shield.shield('scheduled send', function () {
55
59
  // the only tick that happens whether or not anything is being tracked, which is
56
60
  // exactly the case debug mode has to expire in
57
61
  debug.expireDebugIfIdle();
58
62
  logger.Console.log('scheduleToSendDataToServer: Scheduling to send engagement data to the server after sometime'); // no i18n
59
63
  // one after the other, as flush() does: run together, the second and third find the
60
64
  // first still sending and are deferred, and the third's retry replaces the second's
61
- send.sendEngagementData().then(function () {
65
+ shield.quietly('scheduled send', send.sendEngagementData().then(function () {
62
66
  return send$1.sendErrorData();
63
67
  }).then(function () {
64
68
  return hooks.hooks.sendHeatmaps();
65
- });
66
- }, state.getConfig('batch_flush_interval')); // no i18n
69
+ }).then(function () {
70
+ return hooks.hooks.sendPushStats();
71
+ }));
72
+ }), state.getConfig('batch_flush_interval')); // no i18n
67
73
  }
68
74
  }
69
75
  function stopTimers() {
@@ -0,0 +1,83 @@
1
+ import { CLICK_MESSAGE, CLOSE_MESSAGE, STEP_MESSAGE } from '../pushnotification/display.js';
2
+ /**
3
+ * The Apptics service worker: the part of push notifications that runs without the page. The
4
+ * site hosts a one-line worker of its own,
5
+ *
6
+ * importScripts('https://static.zohocdn.com/apptics-js-sdk/<version>/apptics-pn-sw.js');
7
+ *
8
+ * or adds that line to the worker it already has. It handles the clicks on the notifications the
9
+ * SDK showed: Prev / Next step a carousel in place, a button or the body opens its URL, and the
10
+ * click is posted to the site's open tabs for the app's onNotificationClick. Notifications that
11
+ * aren't the SDK's (data.apptics !== 1) are left to the site's own code.
12
+ *
13
+ * Timed parts (auto-scroll, the countdown, auto-dismiss) run here too, once the tab that showed
14
+ * the notification hands them over (timers.ts): they go on while that tab is in the background or
15
+ * closed. An event keeps the worker alive for a few minutes only, so what is still running after
16
+ * that goes back to an open tab.
17
+ */
18
+ interface ClientLike {
19
+ url: string;
20
+ focus?: () => Promise<unknown>;
21
+ postMessage: (message: unknown) => void;
22
+ }
23
+ /** What the handlers use of the worker's global scope; tests pass their own. */
24
+ export interface WorkerScope {
25
+ /** The site's origin (the worker's own); a tab of it gets the click report. */
26
+ origin?: string;
27
+ registration: {
28
+ showNotification: (title: string, options: NotificationOptions) => Promise<void>;
29
+ getNotifications?: (filter: {
30
+ tag: string;
31
+ }) => Promise<ReadonlyArray<{
32
+ close: () => void;
33
+ }>>;
34
+ };
35
+ clients: {
36
+ matchAll: (options: {
37
+ type: string;
38
+ includeUncontrolled: boolean;
39
+ }) => Promise<ReadonlyArray<ClientLike>>;
40
+ openWindow: (url: string) => Promise<unknown>;
41
+ };
42
+ }
43
+ interface NotificationEventLike {
44
+ action?: string;
45
+ notification: {
46
+ data?: unknown;
47
+ close: () => void;
48
+ };
49
+ waitUntil: (promise: Promise<unknown>) => void;
50
+ }
51
+ export { CLICK_MESSAGE, CLOSE_MESSAGE, STEP_MESSAGE };
52
+ export declare function onNotificationClick(event: NotificationEventLike, scope: WorkerScope): void;
53
+ export declare function onNotificationClose(event: NotificationEventLike, scope: WorkerScope): void;
54
+ interface MessageEventLike {
55
+ data?: unknown;
56
+ ports?: ReadonlyArray<{
57
+ postMessage: (message: unknown) => void;
58
+ }>;
59
+ waitUntil?: (promise: Promise<unknown>) => void;
60
+ }
61
+ /**
62
+ * What a tab of the site posts: run a notification's timers here (answered on the port it came
63
+ * with, so the tab knows not to run them itself), or stop them, one tag or all.
64
+ */
65
+ export declare function onMessage(event: MessageEventLike, scope: WorkerScope): void;
66
+ interface TakeOverScope {
67
+ location?: {
68
+ pathname?: string;
69
+ };
70
+ skipWaiting: () => Promise<void>;
71
+ clients: {
72
+ claim: () => Promise<void>;
73
+ };
74
+ addEventListener: (type: string, fn: (e: {
75
+ waitUntil: (p: Promise<unknown>) => void;
76
+ }) => void) => void;
77
+ }
78
+ /**
79
+ * As the site's own /apptics-pn-sw.js, a new version takes over at once, and the open tabs with
80
+ * it, rather than waiting until every tab of the site is closed. Inside a site's own worker it
81
+ * leaves that worker's updates as the site set them up.
82
+ */
83
+ export declare function takeOverWhenOwn(g: TakeOverScope): void;
@@ -0,0 +1,44 @@
1
+ import type { ShownNotification } from '../pushnotification/display.js';
2
+ /**
3
+ * A notification's timed parts, run by the service worker: auto-scroll steps the carousel, the
4
+ * countdown ticks every second, and auto-dismiss closes it. They run in the worker, so they go on
5
+ * while the tab that received the message is in the background, frozen or closed.
6
+ *
7
+ * A browser stops a worker once the event keeping it alive has run for about 5 minutes. So the
8
+ * worker runs them for at most RUN_BUDGET_MS, and gives what is left to one open tab of the site,
9
+ * which runs the rest as it did before the worker took them over.
10
+ */
11
+ /** How long the worker runs a notification's timers before handing what is left to a tab. */
12
+ export declare const RUN_BUDGET_MS: number;
13
+ interface ClientLike {
14
+ url: string;
15
+ postMessage: (message: unknown) => void;
16
+ }
17
+ /** What the timers use of the worker's global scope; tests pass their own. */
18
+ export interface TimerScope {
19
+ origin?: string;
20
+ registration: {
21
+ showNotification: (title: string, options: NotificationOptions) => Promise<void>;
22
+ getNotifications?: (filter: {
23
+ tag: string;
24
+ }) => Promise<ReadonlyArray<{
25
+ close: () => void;
26
+ }>>;
27
+ };
28
+ clients: {
29
+ matchAll: (options: {
30
+ type: string;
31
+ includeUncontrolled: boolean;
32
+ }) => Promise<ReadonlyArray<ClientLike>>;
33
+ };
34
+ }
35
+ /** Stops the timers of `tag`, or of every notification without one. */
36
+ export declare function stopTimers(tag?: string): void;
37
+ /** Prev / Next: the visitor took over the carousel, so auto-scroll stops; the countdown keeps their slide. */
38
+ export declare function stepTimers(tag: string, index: number): void;
39
+ /**
40
+ * Runs the timers of `shown`, already on screen, replacing any it had. Resolves once they end:
41
+ * dismissed, closed or clicked by the visitor, stopped, all done, or handed to a tab.
42
+ */
43
+ export declare function runTimers(shown: ShownNotification, scope: TimerScope): Promise<void>;
44
+ export {};
@@ -26,6 +26,8 @@ export interface UserInfo {
26
26
  userid?: string;
27
27
  groupid?: string;
28
28
  status?: number;
29
+ /** user/register's answer: false when the user's customer group is not tracked. */
30
+ customergrouptracking?: boolean;
29
31
  [key: string]: any;
30
32
  }
31
33
  export interface ServerResult<T = Dict> {
@@ -65,12 +67,6 @@ export interface AppticsConfig {
65
67
  base_domain?: string;
66
68
  /** @deprecated 1.x console-snippet name for auth_key: still read, with a warning */
67
69
  token?: string;
68
- /**
69
- * Debug mode: send engagement, exception and log payloads to their `debug/` twins, which answer
70
- * with a request id and a link to the server's own logs, for following in the Apptics web
71
- * console. Off by default; it does not change what is sent. Same as calling enableDebug().
72
- */
73
- debug?: boolean;
74
70
  /** Log the SDK's own activity to the browser console. Off by default. */
75
71
  console_log?: boolean;
76
72
  ignore_do_not_track?: boolean;
@@ -127,14 +123,22 @@ export interface AppticsConfig {
127
123
  /** Days an unsent item is kept before it is dropped. Default 7, between 1 and 30. */
128
124
  batch_request_timeout?: number;
129
125
  /**
130
- * Minutes a tab can be inactive (hidden, minimised, in the background) before its session ends,
131
- * at the moment the user left. Default 30, between 1 and 1440.
126
+ * How long a tab can be inactive (hidden, minimised, in the background) before its session
127
+ * ends, in milliseconds, counted from the moment the tab went inactive; the session then ends at
128
+ * that moment. Default 1800000 (30 minutes), between 5000 (5 seconds) and 1800000. A value
129
+ * outside that is ignored with a warning and the default is kept.
130
+ */
131
+ max_session_duration?: number;
132
+ /**
133
+ * @deprecated Use max_session_duration, in milliseconds. Still read, in minutes, when
134
+ * max_session_duration is not given, with a warning; held to the same 5 seconds to 30 minutes.
132
135
  */
133
136
  inactiveduration?: number;
134
137
  /**
135
- * How long a visit must last before its session is recorded, in milliseconds. Default 5000, at
136
- * most 60000. A shorter visit with nothing tracked in it is not reported at all; anything tracked
137
- * inside the window records the session at once, with its real start time. 0 turns the wait off.
138
+ * How long a visit must last before its session is recorded, in milliseconds. Default 5000,
139
+ * between 5000 (5 seconds) and 1800000 (30 minutes); a value outside that, 0 included, is ignored
140
+ * with a warning and 5000 is kept. A shorter visit with nothing tracked in it is not reported at
141
+ * all; anything tracked inside the window records the session at once, with its real start time.
138
142
  */
139
143
  min_session_duration?: number;
140
144
  /**
@@ -144,8 +148,6 @@ export interface AppticsConfig {
144
148
  track_heatmap?: boolean;
145
149
  /** Most heatmap records one visit may produce. Default 500; capture pauses past it. */
146
150
  heatmap_max_per_session?: number;
147
- /** @deprecated the earlier name for `debug` (debug mode); `debug` wins when both are given */
148
- debug_api?: boolean;
149
151
  /**
150
152
  * What to call this device in the debug stream, e.g. 'QA iPad 3'. Sent on engagement,
151
153
  * exception and log, the three endpoints that declare it. Unset, nothing is sent unless
@@ -339,10 +341,11 @@ export interface AppticsSdk {
339
341
  /**
340
342
  * Turns debug mode on, before or after Apptics.init(). Engagement, exception and log then go to
341
343
  * their `debug/` twins, whose answers carry a request id and a link into the server's own logs. It
342
- * switches itself off after an hour with nothing tracked.
344
+ * switches itself off after an hour with nothing tracked. Works only when typed in the browser
345
+ * console: a call from the page's code is ignored, with a warning, so an app can't ship with it on.
343
346
  */
344
347
  enableDebug(): void;
345
- /** Turns debug mode off, before or after Apptics.init(); wins over `debug` in init(). */
348
+ /** Turns debug mode off, before or after Apptics.init(). Like enableDebug(), only from the browser console. */
346
349
  disableDebug(): void;
347
350
  };
348
351
  /** Android's AppticsEvents. */
@@ -424,7 +427,20 @@ export interface AppticsSdk {
424
427
  AppticsSettings: {
425
428
  /** The states setTrackingStatus takes. */
426
429
  AP_TRACKING_STATUS: typeof AP_TRACKING_STATUS;
430
+ /** One of AP_TRACKING_STATUS, as AppticsSettings.AP_TRACKING_STATUS.ANONYMOUS. */
427
431
  setTrackingStatus(status: TrackingStatus): void;
432
+ /** @deprecated pass AP_TRACKING_STATUS.<name>; the number (1, 4, 7, -1) still works, with a console warning */
433
+ setTrackingStatus(status: number): void;
434
+ /** One of AP_TRACKING_STATUS, as 'USAGE_TRACKING_WITH_PII'. */
428
435
  getTrackingStatus(): TrackingStatus;
429
436
  };
430
437
  }
438
+ /**
439
+ * getsdkconfig's `wms` block: where wmsliteapi.js loads from, its subresource-integrity hash, and
440
+ * the hashes wmsliteapi.js checks the scripts it loads itself against.
441
+ */
442
+ export interface WmsConfig {
443
+ wms_js_url: string;
444
+ wms_sri: string;
445
+ wms_sri_values: Record<string, unknown> | null;
446
+ }
@@ -1,4 +1,11 @@
1
1
  import type { Dict, Properties, UserInfo, UserValidationResult } from '../types.js';
2
+ /**
3
+ * Whether the active user's customer group is not tracked, as user/register last answered for them
4
+ * (user_info's customergrouptracking). A user registered before it was kept has none, and counts as
5
+ * tracked. Only a user getsdkconfig is asked about can be one: the status decides whether it
6
+ * carries their userid.
7
+ */
8
+ export declare function activeUserGroupUntracked(): boolean;
2
9
  export declare function getUser(): UserInfo;
3
10
  export declare function setUser(userid?: string, groupid?: string, jsonObj?: Properties | UserValidationResult): void;
4
11
  export declare function addOrUpdateUser(user_info: Dict): void;
@@ -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('../core/constants.js');
@@ -11,6 +11,16 @@ var transport = require('../core/transport.js');
11
11
  var validate = require('../core/validate.js');
12
12
  var hooks = require('../core/hooks.js');
13
13
 
14
+ /**
15
+ * Whether the active user's customer group is not tracked, as user/register last answered for them
16
+ * (user_info's customergrouptracking). A user registered before it was kept has none, and counts as
17
+ * tracked. Only a user getsdkconfig is asked about can be one: the status decides whether it
18
+ * carries their userid.
19
+ */
20
+ function activeUserGroupUntracked() {
21
+ var user = state._ZAP._user_info;
22
+ return !!user && !utils.isEmpty(user.userid) && user.customergrouptracking === false;
23
+ }
14
24
  function getUser() {
15
25
  return state._ZAP._user_info || {}; // no i18n
16
26
  }
@@ -95,7 +105,7 @@ function registerUserWithApptics(user_info) {
95
105
  if (utils.isEmptyObj(user_info)) {
96
106
  return Promise.reject(label + ': nothing to register'); // no i18n
97
107
  }
98
- var missing = transport.rejectIfNoDeviceIds(label);
108
+ var missing = transport.rejectIfNoDeviceIds(label, 'reguser');
99
109
  if (missing) {
100
110
  return missing;
101
111
  }
@@ -104,15 +114,21 @@ function registerUserWithApptics(user_info) {
104
114
  var data = result.data || {};
105
115
  user_info.userid = data.userid;
106
116
  user_info.groupid = data.customergroupid;
107
- // stored only: user/register has told the server, and the device is registered already
108
- consent.recordTrackingStatus(constants.AP_TRACKING_STATUS.USAGE_TRACKING_WITH_PII);
117
+ // whether a change of tracking status asks getsdkconfig again depends on it (see setTrackingStatus)
118
+ user_info.customergrouptracking = data.customergrouptracking !== false;
119
+ // the tracking status is left as it is: registering a user is not consent to attach them to
120
+ // the data. Only AppticsSettings.setTrackingStatus changes it
109
121
  addOrUpdateUser(user_info);
110
122
  getUserInfo();
111
123
  // the user and their customer group are known now: remote config conditions on them re-apply
112
124
  hooks.hooks.remoteConfigUserChanged();
113
- // getsdkconfig answers for the user (with every module off for one whose customer group
114
- // is not tracked, customergrouptracking: false), so it is asked again for them now
115
- hooks.hooks.askServerSettings();
125
+ // a user whose customer group is not tracked (customergrouptracking: false) gets every
126
+ // module off from getsdkconfig, so it is asked again for them now; for any other user the
127
+ // current answer stands. Only with PII does getsdkconfig carry the userid: anonymous, or
128
+ // without PII, it answers for the device alone, and the customer group does not apply
129
+ if (data.customergrouptracking === false && consent.opt_in_status() === constants.AP_TRACKING_STATUS.USAGE_TRACKING_WITH_PII) {
130
+ hooks.hooks.askServerSettings();
131
+ }
116
132
  return data;
117
133
  });
118
134
  }
@@ -178,8 +194,10 @@ class UserBuilder {
178
194
  return validate.userValidateJSON(user);
179
195
  }
180
196
  }
197
+ hooks.hooks.activeUserGroupUntracked = activeUserGroupUntracked;
181
198
 
182
199
  exports.UserBuilder = UserBuilder;
200
+ exports.activeUserGroupUntracked = activeUserGroupUntracked;
183
201
  exports.addOrUpdateUser = addOrUpdateUser;
184
202
  exports.getUser = getUser;
185
203
  exports.getUserInfo = getUserInfo;
@@ -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
  import { RETRY_CAPABLE_PATHS } from './constants.js';
3
3
  import { user_defaults } from './storage.js';
4
4
  import { nowMs } from './utils.js';