@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,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
- import { type ApConfig } from './constants.js';
2
- import type { DeviceInfo, Dict, QuartzSettings, TrackingStatus, UserInfo } from '../types.js';
1
+ import { type ApConfig, type EngagementType } from './constants.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;
@@ -19,7 +19,6 @@ export interface State {
19
19
  _token: string;
20
20
  _frameworkID: number;
21
21
  _platform: string;
22
- _isanonrequired: boolean;
23
22
  _devicestatus: TrackingStatus;
24
23
  _uuid: string;
25
24
  _apid: string;
@@ -30,9 +29,12 @@ export interface State {
30
29
  _current_session: Dict;
31
30
  _properties: Dict;
32
31
  _ignoreDnt: boolean;
33
- _isGlobalErrorTracking: boolean;
34
32
  _shouldTrack: boolean;
35
- _engagementTracking: boolean;
33
+ /**
34
+ * getsdkconfig's engagement modules, one per kind of item, keyed by the item's type: event (5),
35
+ * api (6), screen (10) and session (11).
36
+ */
37
+ _engagementTracking: Record<EngagementType, boolean>;
36
38
  _errorTracking: boolean;
37
39
  /** getsdkconfig module 18. Heatmap has its own flag in v2; before that it rode engagement. */
38
40
  _heatmapTracking: boolean;
@@ -44,6 +46,10 @@ export interface State {
44
46
  _remoteConfigReported: boolean;
45
47
  /** getsdkconfig module 12. */
46
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;
47
53
  /** getsdkconfig's `quartz` block: screen recording in the feedback form. Off until it says otherwise. */
48
54
  _quartz: QuartzSettings;
49
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.1 | (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');
@@ -23,7 +23,6 @@ function initialState() {
23
23
  // issued by Apptics at pack time; see scripts/register-version.mjs
24
24
  _frameworkID: frameworkId.FRAMEWORK_ID,
25
25
  _platform: constants.AP_CONSTANTS.BROWSER,
26
- _isanonrequired: true,
27
26
  _devicestatus: constants.AP_TRACKING_STATUS.USAGE_TRACKING_WITHOUT_PII,
28
27
  _uuid: '', // no i18n
29
28
  _apid: '', // no i18n
@@ -34,14 +33,15 @@ function initialState() {
34
33
  _current_session: {},
35
34
  _properties: {},
36
35
  _ignoreDnt: false,
37
- _isGlobalErrorTracking: true,
38
36
  _shouldTrack: true,
39
- _engagementTracking: true,
37
+ _engagementTracking: { event: true, screen: true, session: true, api: true },
40
38
  _heatmapTracking: true,
41
39
  _remoteLoggerEnabled: true,
42
40
  _remoteConfigEnabled: true,
43
41
  _remoteConfigReported: true,
44
42
  _feedbackEnabled: true,
43
+ _pushEnabled: false,
44
+ _wmsConfig: null,
45
45
  _nextConfigCheck: 0,
46
46
  _debugUntil: 0,
47
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.1 | (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,13 +311,12 @@ const tracking_preference = {
293
311
  },
294
312
  update_status(tracking_status) {
295
313
  state._ZAP._devicestatus = tracking_status;
296
- // Legacy order kept: this reads the status *before* the write below (setTrackingStatus recomputes it after).
297
- state._ZAP._isanonrequired =
298
- tracking_preference.opt_in_status() == constants.AP_TRACKING_STATUS.USAGE_TRACKING_WITH_PII ? false : state._ZAP._isanonrequired;
314
+ // stored as its number, which earlier builds read back the same way
315
+ var code = trackingStatusCode(tracking_status);
299
316
  var track = Object.assign({}, settings.trackinfo && typeof settings.trackinfo === 'object' ? settings.trackinfo : {}); // no i18n
300
- track.tracking_status = tracking_status;
317
+ track.tracking_status = code;
301
318
  if (state._ZAP._trackinfo && typeof state._ZAP._trackinfo === 'object') { // no i18n
302
- state._ZAP._trackinfo.tracking_status = tracking_status;
319
+ state._ZAP._trackinfo.tracking_status = code;
303
320
  }
304
321
  setSetting('trackinfo', track); // no i18n
305
322
  },
@@ -323,5 +340,7 @@ exports.remotelog_transactions = remotelog_transactions;
323
340
  exports.setDeviceInfoKey = setDeviceInfoKey;
324
341
  exports.storageReady = storageReady;
325
342
  exports.storedTrackingStatus = storedTrackingStatus;
343
+ exports.trackingStatusCode = trackingStatusCode;
344
+ exports.trackingStatusFrom = trackingStatusFrom;
326
345
  exports.tracking_preference = tracking_preference;
327
346
  exports.user_defaults = user_defaults;
@@ -1,4 +1,4 @@
1
- /*! @zoho_apptics/apptics-js-sdk v2.0.0-beta.1 | (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
  /**
@@ -10,6 +10,14 @@ export type RequestBody = XMLHttpRequestBodyInit | null;
10
10
  export declare const REQUEST_TIMEOUT_MS = 30000;
11
11
  export declare function makeRequest(url: string, method: string, payload: RequestBody, headers?: RequestHeaders): Promise<string>;
12
12
  export declare function getHeaderParams(key: string): string;
13
+ /**
14
+ * Whether a call names the browser by its anonymousid rather than its deviceid: every call an
15
+ * anonymous browser makes, except the two that tie a person to the device. user/register registers
16
+ * the user against the deviceid, and feedback the reporter picked themselves on goes with their
17
+ * userid, so with the deviceid too. Feedback sent as Anonymous goes by the anonymousid.
18
+ * getsdkconfig names no device at all.
19
+ */
20
+ export declare function sendsByAnonymousId(path: ApiPath): boolean;
13
21
  export declare function getParameters(path: ApiPath): string;
14
22
  /**
15
23
  * `extra` appends params the path needs per call rather than per state, which console/addlog does
@@ -76,10 +84,13 @@ export declare function rejectIfOffline(label: string): Promise<never> | null;
76
84
  /** Device ids sent alongside every payload. */
77
85
  export declare function getMetaObj(): Dict;
78
86
  /**
79
- * Calls made after registration need apid/mapid. Without them this asks device.ts to
80
- * refresh device info (which registers) and returns a labelled rejection; otherwise null. Shared by sender, user
81
- * and feedback (P11).
87
+ * Calls made after registration need apid/mapid, and the id `path` goes out by: the deviceid, or
88
+ * while tracking is anonymous the anonymousid for the calls sendsByAnonymousId names. Without them
89
+ * this asks device.ts to refresh device info (which registers) and returns a labelled rejection;
90
+ * otherwise null. Shared by sender, user and feedback (P11).
82
91
  */
83
- export declare function rejectIfNoDeviceIds(label: string): Promise<never> | null;
92
+ export declare function rejectIfNoDeviceIds(label: string, path: ApiPath): Promise<never> | null;
84
93
  /** Whether device/add has given this browser its deviceid. */
85
94
  export declare function hasDeviceId(): boolean;
95
+ /** The ids data goes out by: the deviceid, and the anonymousid too while tracking is anonymous. */
96
+ export declare function hasSendIds(): boolean;
@@ -1,4 +1,4 @@
1
- /*! @zoho_apptics/apptics-js-sdk v2.0.0-beta.1 | (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');
@@ -128,6 +128,19 @@ function deviceNameParam(path, existing) {
128
128
  var param = 'devicename=' + encodeURIComponent(name.slice(0, constants.DEVICE_NAME_MAX)); // no i18n
129
129
  return (existing === '' ? '?' : '&') + param; // no i18n
130
130
  }
131
+ /**
132
+ * Whether a call names the browser by its anonymousid rather than its deviceid: every call an
133
+ * anonymous browser makes, except the two that tie a person to the device. user/register registers
134
+ * the user against the deviceid, and feedback the reporter picked themselves on goes with their
135
+ * userid, so with the deviceid too. Feedback sent as Anonymous goes by the anonymousid.
136
+ * getsdkconfig names no device at all.
137
+ */
138
+ function sendsByAnonymousId(path) {
139
+ if (!consent.isAnonymous() || path === 'reguser' || path === 'sdkconfig') { // no i18n
140
+ return false;
141
+ }
142
+ return !(path === 'feedback' && hooks.hooks.feedbackUser()); // no i18n
143
+ }
131
144
  function getParameters(path) {
132
145
  let returnVal = ''; // no i18n
133
146
  // app/addversion runs before any id exists: it identifies the build, not the device
@@ -141,26 +154,32 @@ function getParameters(path) {
141
154
  // v2 device/add declares neither identifier, platform nor appversion: the build is already
142
155
  // known from app/addversion, and sending an undeclared param is refused as EXTRA_PARAM_FOUND.
143
156
  // What it does declare as mandatory is appversionid, which v1 treated as optional.
157
+ // isanonrequired asks for the anonymousid that an anonymous browser's data goes out by.
158
+ // devicestatus is the server's device preference for the stored status, read from storage:
159
+ // _devicestatus is only set when the status changes, so after a reload it is the default
144
160
  if (path == 'regdevice') { // no i18n
145
- returnVal = '?isanonrequired=' + state._ZAP._isanonrequired + '&devicestatus=' + state._ZAP._devicestatus; // no i18n
161
+ returnVal = '?isanonrequired=' + consent.isAnonymous() + '&devicestatus=' + consent.deviceStatusFor(storage.tracking_preference.opt_in_status()); // no i18n
146
162
  if (!utils.isEmpty(state._ZAP._device_info.deviceid)) {
147
163
  returnVal += '&deviceid=' + encodeURIComponent(String(state._ZAP._device_info.deviceid)); // no i18n
148
164
  }
165
+ // and the anonymous record it already has, so that one is amended rather than another made
166
+ if (consent.isAnonymous() && !utils.isEmpty(state._ZAP._device_info.anonymousid)) {
167
+ returnVal += '&anondeviceid=' + encodeURIComponent(String(state._ZAP._device_info.anonymousid)); // no i18n
168
+ }
149
169
  return returnVal + mandatoryParams(returnVal);
150
170
  }
151
- // getsdkconfig is the one call that must NOT carry deviceid: it declares the param with
152
- // decrypt-label="authenticate", which a web SDK cannot satisfy, and sending it is answered
153
- // with NOT_AUTHENTICATED. getupdates declares the same param with plain paramdecrypt, so it
154
- // does carry one. It still needs appversionid and frameworkid, added at the end.
155
- var identifiesDevice = path != 'sdkconfig'; // no i18n
156
- if (identifiesDevice) {
157
- if (utils.isEmpty(state._ZAP._device_info.deviceid)) {
171
+ // getsdkconfig carries no deviceid: the user's ids below are what it answers for
172
+ if (path != 'sdkconfig') { // no i18n
173
+ // device/add answers with the anonymousid; the data urls declare it as anondeviceid
174
+ var anonymous = sendsByAnonymousId(path);
175
+ var key = anonymous ? 'anonymousid' : 'deviceid'; // no i18n
176
+ if (utils.isEmpty(state._ZAP._device_info[key])) {
158
177
  hooks.hooks.refreshDeviceInfo();
159
178
  // the device is missing, but appversionid and frameworkid are mandatory regardless:
160
179
  // dropping them turns one missing id into a refusal that names the wrong param
161
180
  return returnVal + mandatoryParams(returnVal);
162
181
  }
163
- returnVal = '?deviceid=' + encodeURIComponent(String(state._ZAP._device_info.deviceid)); // no i18n
182
+ returnVal = (anonymous ? '?anondeviceid=' : '?deviceid=') + encodeURIComponent(String(state._ZAP._device_info[key])); // no i18n
164
183
  }
165
184
  // feedback is attributed to whoever the form's user picker selected, not to the active user:
166
185
  // the person reporting may not be the one the app last registered, and may choose Anonymous
@@ -174,21 +193,29 @@ function getParameters(path) {
174
193
  }
175
194
  return returnVal + mandatoryParams(returnVal);
176
195
  }
177
- // add userid and groupid if opt_in_status is USAGE_TRACKING_WITH_PII. getupdates doesn't declare
196
+ // add userid and groupid if opt_in_status is USAGE_TRACKING_WITH_PII: never while anonymous,
197
+ // and not without PII either, with a user registered. getupdates doesn't declare
178
198
  // them, and refuses userid as EXTRA_PARAM_FOUND; it has no use for them either, since remote
179
199
  // config conditions on the user are evaluated here, against the rule set it answers with
180
- var carriesUser = path != 'reguser' && path != 'getupdates'; // no i18n
181
- if (carriesUser && identifiesDevice) {
182
- if (consent.opt_in_status() == constants.AP_TRACKING_STATUS.USAGE_TRACKING_WITH_PII) {
183
- if (state._ZAP._user_info.hasOwnProperty('userid') && !utils.isEmpty(state._ZAP._user_info.userid)) { // no i18n
184
- returnVal += '&userid=' + encodeURIComponent(String(state._ZAP._user_info.userid)); // no i18n
185
- }
186
- if (state._ZAP._user_info.hasOwnProperty('groupid') && !utils.isEmpty(state._ZAP._user_info.groupid)) { // no i18n
187
- returnVal += '&customergroupid=' + encodeURIComponent(String(state._ZAP._user_info.groupid)); // no i18n
188
- }
200
+ // pushnotification/device declares no user either: it registers the browser, not a person
201
+ var carriesUser = path != 'reguser' && path != 'getupdates' && path != 'pushnotification' && path != 'pnstats'; // no i18n
202
+ if (carriesUser && consent.opt_in_status() == constants.AP_TRACKING_STATUS.USAGE_TRACKING_WITH_PII) {
203
+ if (state._ZAP._user_info.hasOwnProperty('userid') && !utils.isEmpty(state._ZAP._user_info.userid)) { // no i18n
204
+ // getsdkconfig has no deviceid before it, so its userid starts the query
205
+ returnVal += (returnVal === '' ? '?' : '&') + 'userid=' + encodeURIComponent(String(state._ZAP._user_info.userid)); // no i18n
206
+ }
207
+ if (state._ZAP._user_info.hasOwnProperty('groupid') && !utils.isEmpty(state._ZAP._user_info.groupid)) { // no i18n
208
+ returnVal += (returnVal === '' ? '?' : '&') + 'customergroupid=' + encodeURIComponent(String(state._ZAP._user_info.groupid)); // no i18n
189
209
  }
190
210
  }
191
211
  returnVal += deviceNameParam(path, returnVal);
212
+ // the modules getsdkconfig is asked about; it declares moduleids as at most 2, comma-split
213
+ if (path == 'sdkconfig') { // no i18n
214
+ var modules = hooks.hooks.sdkConfigModuleIds();
215
+ if (modules.length > 0) {
216
+ returnVal += (returnVal === '' ? '?' : '&') + 'moduleids=' + encodeURIComponent(modules.slice(0, 2).join(',')); // no i18n
217
+ }
218
+ }
192
219
  return returnVal + mandatoryParams(returnVal);
193
220
  }
194
221
  /**
@@ -296,7 +323,7 @@ function settle(path, label, response) {
296
323
  * nothing orders one behind another.
297
324
  */
298
325
  function postToApptics(path, payload, headers, label, extra) {
299
- var url = getUrlWithParams(path, Object.assign(attempts.beginAttempt(path), {}));
326
+ var url = getUrlWithParams(path, Object.assign(attempts.beginAttempt(path), extra || {}));
300
327
  return makeRequest(url, state.getConfig('method'), payload, headers).then(function (response) {
301
328
  return settle(path, label, response);
302
329
  }, function (err) {
@@ -415,11 +442,12 @@ function getMetaObj() {
415
442
  };
416
443
  }
417
444
  /**
418
- * Calls made after registration need apid/mapid. Without them this asks device.ts to
419
- * refresh device info (which registers) and returns a labelled rejection; otherwise null. Shared by sender, user
420
- * and feedback (P11).
445
+ * Calls made after registration need apid/mapid, and the id `path` goes out by: the deviceid, or
446
+ * while tracking is anonymous the anonymousid for the calls sendsByAnonymousId names. Without them
447
+ * this asks device.ts to refresh device info (which registers) and returns a labelled rejection;
448
+ * otherwise null. Shared by sender, user and feedback (P11).
421
449
  */
422
- function rejectIfNoDeviceIds(label) {
450
+ function rejectIfNoDeviceIds(label, path) {
423
451
  if (utils.isEmpty(getHeaderParams('apid')) && utils.isEmpty(getHeaderParams('mapid'))) { // no i18n
424
452
  hooks.hooks.refreshDeviceInfo();
425
453
  return Promise.reject(label + ': You must call Apptics.init() first'); // no i18n
@@ -431,12 +459,29 @@ function rejectIfNoDeviceIds(label) {
431
459
  hooks.hooks.refreshDeviceInfo();
432
460
  return Promise.reject(label + ': the device is not registered yet, kept for the next send'); // no i18n
433
461
  }
462
+ // anonymous, and device/add has not answered with the anonymousid yet: the call waits for it
463
+ // rather than go out by the deviceid it is meant to leave out
464
+ if (sendsByAnonymousId(path) && !hasAnonymousId()) {
465
+ hooks.hooks.refreshDeviceInfo();
466
+ return Promise.reject(label + ': the anonymous id has not arrived yet, kept for the next send'); // no i18n
467
+ }
434
468
  return null;
435
469
  }
470
+ /** Whether device/add has given this browser its anonymousid. */
471
+ function hasAnonymousId() {
472
+ return !utils.isEmpty(state._ZAP._device_info && state._ZAP._device_info.anonymousid) || !utils.isEmpty(storage.getKeyFromDeviceInfo('anonymousid')); // no i18n
473
+ }
436
474
  /** Whether device/add has given this browser its deviceid. */
437
475
  function hasDeviceId() {
438
476
  return !utils.isEmpty(state._ZAP._device_info && state._ZAP._device_info.deviceid) || !utils.isEmpty(storage.getKeyFromDeviceInfo('deviceid')); // no i18n
439
477
  }
478
+ /** The ids data goes out by: the deviceid, and the anonymousid too while tracking is anonymous. */
479
+ function hasSendIds() {
480
+ if (!hasDeviceId()) {
481
+ return false;
482
+ }
483
+ return !consent.isAnonymous() || hasAnonymousId();
484
+ }
440
485
 
441
486
  exports.KEEPALIVE_BUDGET = KEEPALIVE_BUDGET;
442
487
  exports.REQUEST_TIMEOUT_MS = REQUEST_TIMEOUT_MS;
@@ -446,6 +491,7 @@ exports.getMetaObj = getMetaObj;
446
491
  exports.getParameters = getParameters;
447
492
  exports.getUrlWithParams = getUrlWithParams;
448
493
  exports.hasDeviceId = hasDeviceId;
494
+ exports.hasSendIds = hasSendIds;
449
495
  exports.isPermanentRefusal = isPermanentRefusal;
450
496
  exports.makeRequest = makeRequest;
451
497
  exports.postKeepalive = postKeepalive;
@@ -453,4 +499,5 @@ exports.postToApptics = postToApptics;
453
499
  exports.rejectIfDisabled = rejectIfDisabled;
454
500
  exports.rejectIfNoDeviceIds = rejectIfNoDeviceIds;
455
501
  exports.rejectIfOffline = rejectIfOffline;
502
+ exports.sendsByAnonymousId = sendsByAnonymousId;
456
503
  exports.usesDebugApi = usesDebugApi;
@@ -1,4 +1,4 @@
1
- /*! @zoho_apptics/apptics-js-sdk v2.0.0-beta.1 | (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,4 +1,4 @@
1
- /*! @zoho_apptics/apptics-js-sdk v2.0.0-beta.1 | (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');
@@ -31,16 +31,17 @@ const MAX_PROPERTIES_LENGTH = 7666;
31
31
  /** At most this many characters in one value. */
32
32
  const MAX_VALUE_LENGTH = 250;
33
33
  /**
34
- * A value as the payload carries it, with its type. Numbers are Number and booleans Boolean, sent
35
- * as 1 and 0 — the form the server has always received a Boolean in. Anything else (an object, an
36
- * array, null) is turned into text, as on Android, rather than dropped.
34
+ * A value as the payload carries it, with its type. Only true and false are Boolean, and they go
35
+ * as true and false; every number is Number and goes as the number, 1 and 0 included, so the two
36
+ * can't be mistaken for each other. Anything else (an object, an array, null) is turned into text,
37
+ * as on Android, rather than dropped.
37
38
  */
38
39
  function typedValue(value) {
39
40
  if (typeof value === 'number' && isFinite(value)) { // no i18n
40
41
  return { value: value, type: 'Number' }; // no i18n
41
42
  }
42
43
  if (typeof value === 'boolean') { // no i18n
43
- return { value: value ? 1 : 0, type: 'Boolean' }; // no i18n
44
+ return { value: value, type: 'Boolean' }; // no i18n
44
45
  }
45
46
  if (typeof value === 'string') { // no i18n
46
47
  return { value: value, type: 'String' }; // no i18n
@@ -1,4 +1,13 @@
1
- /** Whether we already hold usable ids for the app and version running now. */
1
+ /**
2
+ * A fingerprint of the auth key, which is what is stored to tell one key from another: enough to
3
+ * notice that init() was given a different one, without keeping a second copy of the key itself.
4
+ * FNV-1a, 32 bits, as hex; '' for no key.
5
+ */
6
+ export declare function keyFingerprint(key: unknown): string;
7
+ /**
8
+ * Whether we already hold usable ids for the app, auth key and version running now. Ids stored by
9
+ * a build that kept no key fingerprint register again once, and the answer then records it.
10
+ */
2
11
  export declare function hasAppVersion(): boolean;
3
12
  export declare function appVersionFailedForNetwork(): boolean;
4
13
  export declare function registerAppVersion(): Promise<boolean>;
@@ -1,4 +1,4 @@
1
- /*! @zoho_apptics/apptics-js-sdk v2.0.0-beta.1 | (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');
@@ -39,13 +39,34 @@ const REQUIRED_KEYS = ['aaid', 'portalid', 'projectid', 'apid', 'mapid', 'appver
39
39
  function missingKeys(data) {
40
40
  return REQUIRED_KEYS.filter(function (key) { return utils.isEmpty(data[key]); });
41
41
  }
42
- /** Whether we already hold usable ids for the app and version running now. */
42
+ /**
43
+ * A fingerprint of the auth key, which is what is stored to tell one key from another: enough to
44
+ * notice that init() was given a different one, without keeping a second copy of the key itself.
45
+ * FNV-1a, 32 bits, as hex; '' for no key.
46
+ */
47
+ function keyFingerprint(key) {
48
+ var text = utils.isEmpty(key) ? '' : String(key); // no i18n
49
+ if (text === '') { // no i18n
50
+ return ''; // no i18n
51
+ }
52
+ var hash = 0x811c9dc5;
53
+ for (var i = 0; i < text.length; i++) {
54
+ hash ^= text.charCodeAt(i);
55
+ hash = Math.imul(hash, 0x01000193) >>> 0;
56
+ }
57
+ return ('0000000' + hash.toString(16)).slice(-8); // no i18n
58
+ }
59
+ /**
60
+ * Whether we already hold usable ids for the app, auth key and version running now. Ids stored by
61
+ * a build that kept no key fingerprint register again once, and the answer then records it.
62
+ */
43
63
  function hasAppVersion() {
44
64
  var saved = stored();
45
65
  return missingKeys(saved).length === 0
46
66
  && saved.appversion === state._ZAP._defaultoptions.appversion
47
67
  && saved.identifier === state._ZAP._defaultoptions.identifier
48
- && saved.serviceUrl === state._ZAP._defaultoptions.serviceUrl;
68
+ && saved.serviceUrl === state._ZAP._defaultoptions.serviceUrl
69
+ && saved.zakhash === keyFingerprint(state._ZAP._defaultoptions.zak);
49
70
  }
50
71
  /** Puts the ids where the rest of the SDK reads them from. */
51
72
  function apply(data) {
@@ -126,6 +147,7 @@ function registerAppVersion() {
126
147
  appversion: state._ZAP._defaultoptions.appversion,
127
148
  identifier: state._ZAP._defaultoptions.identifier,
128
149
  serviceUrl: state._ZAP._defaultoptions.serviceUrl,
150
+ zakhash: keyFingerprint(state._ZAP._defaultoptions.zak),
129
151
  };
130
152
  RESULT_KEYS.forEach(function (key) {
131
153
  if (!utils.isEmpty(data[key])) {
@@ -167,4 +189,5 @@ exports.appVersionFailedForNetwork = appVersionFailedForNetwork;
167
189
  exports.applyStoredAppVersion = applyStoredAppVersion;
168
190
  exports.clearAppVersion = clearAppVersion;
169
191
  exports.hasAppVersion = hasAppVersion;
192
+ exports.keyFingerprint = keyFingerprint;
170
193
  exports.registerAppVersion = registerAppVersion;
@@ -28,7 +28,22 @@ export declare function getUpdatesFromServer(): Promise<Dict>;
28
28
  */
29
29
  export declare function restoreServerSettings(): void;
30
30
  /**
31
- * Fetches the server settings now if the device is registered. On a first visit the ids don't
32
- * exist yet; registerDeviceWithApptics calls this as soon as device/add succeeds.
31
+ * next_check_after as a time: the server's value is milliseconds, either a timestamp or a wait
32
+ * from now. Anything below 1e12 (2001 as a timestamp) can only be a wait.
33
+ */
34
+ export declare function nextCheckTime(value: unknown, now: number): number;
35
+ /**
36
+ * Asks for the server settings now if the device is registered, then schedules the next ask
37
+ * for the time the answer gave in next_check_after. On a first visit the ids don't exist yet;
38
+ * registerDeviceWithApptics calls this as soon as device/add succeeds.
33
39
  */
34
40
  export declare function refreshServerSettings(): void;
41
+ /**
42
+ * Start-up's getsdkconfig. Asked on a first visit and on the first page load in each tab; any
43
+ * other load (a reload, a link to another page of the site, back/forward) uses the saved answer
44
+ * and waits for its next_check_after, unless that has already passed. Nothing happens if one has
45
+ * gone out already on this load (after device/add).
46
+ */
47
+ export declare function startServerSettingChecks(): void;
48
+ /** reset(): no more checks, and the next init() asks again straight away. */
49
+ export declare function stopServerSettingChecks(): void;