@zoho_apptics/apptics-js-sdk 1.0.2 → 2.0.0-beta

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 (226) hide show
  1. package/CHANGELOG.md +87 -0
  2. package/LICENSE +13 -0
  3. package/README.md +747 -11
  4. package/dist/apptics.esm.min.js +3 -0
  5. package/dist/apptics.esm.min.js.map +1 -0
  6. package/dist/apptics.min.js +3 -0
  7. package/dist/apptics.min.js.map +1 -0
  8. package/dist/chunks/batch-BU_mTpm1.min.js +3 -0
  9. package/dist/chunks/batch-BU_mTpm1.min.js.map +1 -0
  10. package/dist/chunks/logs-Bea5zUW_.min.js +3 -0
  11. package/dist/chunks/logs-Bea5zUW_.min.js.map +1 -0
  12. package/dist/cjs/auto-init.d.ts +8 -0
  13. package/dist/cjs/auto-init.js +32 -0
  14. package/dist/cjs/core/attempts.d.ts +28 -0
  15. package/dist/cjs/core/attempts.js +113 -0
  16. package/dist/cjs/core/batch.d.ts +32 -0
  17. package/dist/cjs/core/batch.js +115 -0
  18. package/dist/cjs/core/callsite.d.ts +28 -0
  19. package/dist/cjs/core/callsite.js +93 -0
  20. package/dist/cjs/core/consent.d.ts +23 -0
  21. package/dist/cjs/core/consent.js +130 -0
  22. package/dist/cjs/core/constants.d.ts +212 -0
  23. package/dist/cjs/core/constants.js +299 -0
  24. package/dist/cjs/core/db.d.ts +40 -0
  25. package/dist/cjs/core/db.js +334 -0
  26. package/dist/cjs/core/debug.d.ts +22 -0
  27. package/dist/cjs/core/debug.js +88 -0
  28. package/dist/cjs/core/env.d.ts +28 -0
  29. package/dist/cjs/core/env.js +267 -0
  30. package/dist/cjs/core/framework-id.d.ts +1 -0
  31. package/dist/cjs/core/framework-id.js +9 -0
  32. package/dist/cjs/core/guard.d.ts +2 -0
  33. package/dist/cjs/core/guard.js +72 -0
  34. package/dist/cjs/core/hooks.d.ts +41 -0
  35. package/dist/cjs/core/hooks.js +23 -0
  36. package/dist/cjs/core/logger.d.ts +16 -0
  37. package/dist/cjs/core/logger.js +86 -0
  38. package/dist/cjs/core/state.d.ts +69 -0
  39. package/dist/cjs/core/state.js +78 -0
  40. package/dist/cjs/core/storage.d.ts +46 -0
  41. package/dist/cjs/core/storage.js +229 -0
  42. package/dist/cjs/core/transport.d.ts +83 -0
  43. package/dist/cjs/core/transport.js +441 -0
  44. package/dist/cjs/core/utils.d.ts +26 -0
  45. package/dist/cjs/core/utils.js +175 -0
  46. package/dist/cjs/core/validate.d.ts +18 -0
  47. package/dist/cjs/core/validate.js +233 -0
  48. package/dist/cjs/device/appversion.d.ts +20 -0
  49. package/dist/cjs/device/appversion.js +158 -0
  50. package/dist/cjs/device/index.d.ts +23 -0
  51. package/dist/cjs/device/index.js +372 -0
  52. package/dist/cjs/engagement/api-rules.d.ts +84 -0
  53. package/dist/cjs/engagement/api-rules.js +219 -0
  54. package/dist/cjs/engagement/auto-api.d.ts +7 -0
  55. package/dist/cjs/engagement/auto-api.js +200 -0
  56. package/dist/cjs/engagement/auto-screen.d.ts +16 -0
  57. package/dist/cjs/engagement/auto-screen.js +241 -0
  58. package/dist/cjs/engagement/defined-events.d.ts +23 -0
  59. package/dist/cjs/engagement/defined-events.js +58 -0
  60. package/dist/cjs/engagement/send.d.ts +6 -0
  61. package/dist/cjs/engagement/send.js +99 -0
  62. package/dist/cjs/engagement/session.d.ts +42 -0
  63. package/dist/cjs/engagement/session.js +327 -0
  64. package/dist/cjs/engagement/track.d.ts +56 -0
  65. package/dist/cjs/engagement/track.js +350 -0
  66. package/dist/cjs/errors/send.d.ts +6 -0
  67. package/dist/cjs/errors/send.js +73 -0
  68. package/dist/cjs/errors/track.d.ts +4 -0
  69. package/dist/cjs/errors/track.js +127 -0
  70. package/dist/cjs/feedback/controls.d.ts +31 -0
  71. package/dist/cjs/feedback/controls.js +286 -0
  72. package/dist/cjs/feedback/index.d.ts +8 -0
  73. package/dist/cjs/feedback/index.js +37 -0
  74. package/dist/cjs/feedback/logs.d.ts +40 -0
  75. package/dist/cjs/feedback/logs.js +202 -0
  76. package/dist/cjs/feedback/send.d.ts +25 -0
  77. package/dist/cjs/feedback/send.js +178 -0
  78. package/dist/cjs/feedback/template.d.ts +2 -0
  79. package/dist/cjs/feedback/template.js +162 -0
  80. package/dist/cjs/feedback/ui.d.ts +55 -0
  81. package/dist/cjs/feedback/ui.js +631 -0
  82. package/dist/cjs/heatmap/index.d.ts +16 -0
  83. package/dist/cjs/heatmap/index.js +22 -0
  84. package/dist/cjs/heatmap/send.d.ts +13 -0
  85. package/dist/cjs/heatmap/send.js +82 -0
  86. package/dist/cjs/heatmap/track.d.ts +4 -0
  87. package/dist/cjs/heatmap/track.js +377 -0
  88. package/dist/cjs/index.d.ts +68 -0
  89. package/dist/cjs/index.js +150 -0
  90. package/dist/cjs/lifecycle.d.ts +14 -0
  91. package/dist/cjs/lifecycle.js +538 -0
  92. package/dist/cjs/package.json +3 -0
  93. package/dist/cjs/remoteconfig/custom.d.ts +10 -0
  94. package/dist/cjs/remoteconfig/custom.js +78 -0
  95. package/dist/cjs/remoteconfig/evaluate.d.ts +24 -0
  96. package/dist/cjs/remoteconfig/evaluate.js +171 -0
  97. package/dist/cjs/remoteconfig/fetch.d.ts +24 -0
  98. package/dist/cjs/remoteconfig/fetch.js +214 -0
  99. package/dist/cjs/remoteconfig/index.d.ts +13 -0
  100. package/dist/cjs/remoteconfig/index.js +90 -0
  101. package/dist/cjs/remoteconfig/store.d.ts +18 -0
  102. package/dist/cjs/remoteconfig/store.js +98 -0
  103. package/dist/cjs/remotelog/gate.d.ts +11 -0
  104. package/dist/cjs/remotelog/gate.js +54 -0
  105. package/dist/cjs/remotelog/index.d.ts +25 -0
  106. package/dist/cjs/remotelog/index.js +55 -0
  107. package/dist/cjs/remotelog/logger.d.ts +28 -0
  108. package/dist/cjs/remotelog/logger.js +139 -0
  109. package/dist/cjs/remotelog/send.d.ts +13 -0
  110. package/dist/cjs/remotelog/send.js +153 -0
  111. package/dist/cjs/scheduler.d.ts +8 -0
  112. package/dist/cjs/scheduler.js +78 -0
  113. package/dist/cjs/types.d.ts +312 -0
  114. package/dist/cjs/user/index.d.ts +33 -0
  115. package/dist/cjs/user/index.js +178 -0
  116. package/dist/esm/auto-init.d.ts +8 -0
  117. package/dist/esm/auto-init.js +29 -0
  118. package/dist/esm/core/attempts.d.ts +28 -0
  119. package/dist/esm/core/attempts.js +106 -0
  120. package/dist/esm/core/batch.d.ts +32 -0
  121. package/dist/esm/core/batch.js +108 -0
  122. package/dist/esm/core/callsite.d.ts +28 -0
  123. package/dist/esm/core/callsite.js +89 -0
  124. package/dist/esm/core/consent.d.ts +23 -0
  125. package/dist/esm/core/consent.js +120 -0
  126. package/dist/esm/core/constants.d.ts +212 -0
  127. package/dist/esm/core/constants.js +277 -0
  128. package/dist/esm/core/db.d.ts +40 -0
  129. package/dist/esm/core/db.js +324 -0
  130. package/dist/esm/core/debug.d.ts +22 -0
  131. package/dist/esm/core/debug.js +81 -0
  132. package/dist/esm/core/env.d.ts +28 -0
  133. package/dist/esm/core/env.js +251 -0
  134. package/dist/esm/core/framework-id.d.ts +1 -0
  135. package/dist/esm/core/framework-id.js +7 -0
  136. package/dist/esm/core/guard.d.ts +2 -0
  137. package/dist/esm/core/guard.js +70 -0
  138. package/dist/esm/core/hooks.d.ts +41 -0
  139. package/dist/esm/core/hooks.js +21 -0
  140. package/dist/esm/core/logger.d.ts +16 -0
  141. package/dist/esm/core/logger.js +82 -0
  142. package/dist/esm/core/state.d.ts +69 -0
  143. package/dist/esm/core/state.js +73 -0
  144. package/dist/esm/core/storage.d.ts +46 -0
  145. package/dist/esm/core/storage.js +219 -0
  146. package/dist/esm/core/transport.d.ts +83 -0
  147. package/dist/esm/core/transport.js +425 -0
  148. package/dist/esm/core/utils.d.ts +26 -0
  149. package/dist/esm/core/utils.js +161 -0
  150. package/dist/esm/core/validate.d.ts +18 -0
  151. package/dist/esm/core/validate.js +226 -0
  152. package/dist/esm/device/appversion.d.ts +20 -0
  153. package/dist/esm/device/appversion.js +153 -0
  154. package/dist/esm/device/index.d.ts +23 -0
  155. package/dist/esm/device/index.js +362 -0
  156. package/dist/esm/engagement/api-rules.d.ts +84 -0
  157. package/dist/esm/engagement/api-rules.js +211 -0
  158. package/dist/esm/engagement/auto-api.d.ts +7 -0
  159. package/dist/esm/engagement/auto-api.js +198 -0
  160. package/dist/esm/engagement/auto-screen.d.ts +16 -0
  161. package/dist/esm/engagement/auto-screen.js +238 -0
  162. package/dist/esm/engagement/defined-events.d.ts +23 -0
  163. package/dist/esm/engagement/defined-events.js +55 -0
  164. package/dist/esm/engagement/send.d.ts +6 -0
  165. package/dist/esm/engagement/send.js +96 -0
  166. package/dist/esm/engagement/session.d.ts +42 -0
  167. package/dist/esm/engagement/session.js +315 -0
  168. package/dist/esm/engagement/track.d.ts +56 -0
  169. package/dist/esm/engagement/track.js +340 -0
  170. package/dist/esm/errors/send.d.ts +6 -0
  171. package/dist/esm/errors/send.js +70 -0
  172. package/dist/esm/errors/track.d.ts +4 -0
  173. package/dist/esm/errors/track.js +123 -0
  174. package/dist/esm/feedback/controls.d.ts +31 -0
  175. package/dist/esm/feedback/controls.js +280 -0
  176. package/dist/esm/feedback/index.d.ts +8 -0
  177. package/dist/esm/feedback/index.js +30 -0
  178. package/dist/esm/feedback/logs.d.ts +40 -0
  179. package/dist/esm/feedback/logs.js +188 -0
  180. package/dist/esm/feedback/send.d.ts +25 -0
  181. package/dist/esm/feedback/send.js +175 -0
  182. package/dist/esm/feedback/template.d.ts +2 -0
  183. package/dist/esm/feedback/template.js +159 -0
  184. package/dist/esm/feedback/ui.d.ts +55 -0
  185. package/dist/esm/feedback/ui.js +626 -0
  186. package/dist/esm/heatmap/index.d.ts +16 -0
  187. package/dist/esm/heatmap/index.js +17 -0
  188. package/dist/esm/heatmap/send.d.ts +13 -0
  189. package/dist/esm/heatmap/send.js +79 -0
  190. package/dist/esm/heatmap/track.d.ts +4 -0
  191. package/dist/esm/heatmap/track.js +374 -0
  192. package/dist/esm/index.d.ts +68 -0
  193. package/dist/esm/index.js +122 -0
  194. package/dist/esm/lifecycle.d.ts +14 -0
  195. package/dist/esm/lifecycle.js +534 -0
  196. package/dist/esm/package.json +3 -0
  197. package/dist/esm/remoteconfig/custom.d.ts +10 -0
  198. package/dist/esm/remoteconfig/custom.js +74 -0
  199. package/dist/esm/remoteconfig/evaluate.d.ts +24 -0
  200. package/dist/esm/remoteconfig/evaluate.js +166 -0
  201. package/dist/esm/remoteconfig/fetch.d.ts +24 -0
  202. package/dist/esm/remoteconfig/fetch.js +210 -0
  203. package/dist/esm/remoteconfig/index.d.ts +13 -0
  204. package/dist/esm/remoteconfig/index.js +85 -0
  205. package/dist/esm/remoteconfig/store.d.ts +18 -0
  206. package/dist/esm/remoteconfig/store.js +91 -0
  207. package/dist/esm/remotelog/gate.d.ts +11 -0
  208. package/dist/esm/remotelog/gate.js +48 -0
  209. package/dist/esm/remotelog/index.d.ts +25 -0
  210. package/dist/esm/remotelog/index.js +51 -0
  211. package/dist/esm/remotelog/logger.d.ts +28 -0
  212. package/dist/esm/remotelog/logger.js +136 -0
  213. package/dist/esm/remotelog/send.d.ts +13 -0
  214. package/dist/esm/remotelog/send.js +149 -0
  215. package/dist/esm/scheduler.d.ts +8 -0
  216. package/dist/esm/scheduler.js +74 -0
  217. package/dist/esm/types.d.ts +312 -0
  218. package/dist/esm/user/index.d.ts +33 -0
  219. package/dist/esm/user/index.js +170 -0
  220. package/dist/feedback.esm.min.js +3 -0
  221. package/dist/feedback.esm.min.js.map +1 -0
  222. package/dist/heatmap.esm.min.js +3 -0
  223. package/dist/heatmap.esm.min.js.map +1 -0
  224. package/dist/style.css +1 -0
  225. package/package.json +124 -7
  226. package/src/appticssdk.js +0 -1
@@ -0,0 +1,115 @@
1
+ /*! @zoho_apptics/apptics-js-sdk v2.0.0-beta | (c) Zoho Corporation Private Limited | see LICENSE */
2
+ 'use strict';
3
+
4
+ var state = require('./state.js');
5
+ var logger = require('./logger.js');
6
+ var utils = require('./utils.js');
7
+ require('./constants.js');
8
+ var consent = require('./consent.js');
9
+ var attempts = require('./attempts.js');
10
+ var transport = require('./transport.js');
11
+
12
+ /** Retries `send` in 500 ms, replacing any retry already scheduled. */
13
+ function defer(send) {
14
+ if (state._ZAP._deferSendTimer) {
15
+ clearTimeout(state._ZAP._deferSendTimer);
16
+ }
17
+ state._ZAP._deferSendTimer = setTimeout(send, 500);
18
+ }
19
+ function clearDefer() {
20
+ if (state._ZAP._deferSendTimer) {
21
+ clearTimeout(state._ZAP._deferSendTimer);
22
+ state._ZAP._deferSendTimer = null;
23
+ }
24
+ }
25
+ /** Only one tab sends a queue at a time. Without the Web Locks API, runs directly (1.x behaviour). */
26
+ function withSendLock(name, run) {
27
+ var locks = typeof navigator !== 'undefined' ? navigator.locks : undefined; // no i18n
28
+ if (!locks || typeof locks.request !== 'function') { // no i18n
29
+ return run();
30
+ }
31
+ return locks.request('apptics-send-' + name, { ifAvailable: true }, function (lock) {
32
+ return lock ? run() : undefined;
33
+ }).then(function () { return undefined; });
34
+ }
35
+ /**
36
+ * The batch to send: closed items within batch_request_timeout days.
37
+ * Expired items are removed from the queue without being sent.
38
+ */
39
+ function freshItems(queue, isClosed, timeOf) {
40
+ return queue.payload().then(function (items) {
41
+ var fresh = [];
42
+ var expired = [];
43
+ items.forEach(function (item) {
44
+ if (!isClosed(item)) {
45
+ return;
46
+ }
47
+ (state.isExpired(timeOf(item)) ? expired : fresh).push(item);
48
+ });
49
+ return expired.length ? queue.remove(expired).then(function () { return fresh; }) : fresh;
50
+ });
51
+ }
52
+ /**
53
+ * Sends one batch of queued items. Resolves only when the server has accepted it, so the caller
54
+ * removes the items then and not before: a batch that fails stays queued and goes again on the
55
+ * next pass, as attempt 2, which `attempt` and `firstattempttime` let the server recognise as a
56
+ * copy rather than store twice.
57
+ *
58
+ * With `forget` (the page is closing) it goes by keepalive, and the promise settles if the answer
59
+ * arrives before the page is gone. See postKeepalive.
60
+ *
61
+ * Five attempts is the cap, because `attempt` is declared regex="[1-5]" and a sixth would be
62
+ * refused for the param rather than for the payload.
63
+ */
64
+ function sendBatch(path, label, _payload, forget) {
65
+ var blocked = transport.rejectIfDisabled(label);
66
+ if (blocked) {
67
+ return blocked;
68
+ }
69
+ if (!consent.shouldTrackOrSendData()) {
70
+ return Promise.reject(label + ': tracking is off'); // no i18n
71
+ }
72
+ if (utils.isEmptyObj(_payload)) {
73
+ return Promise.reject(label + ': nothing to send'); // no i18n
74
+ }
75
+ var missing = transport.rejectIfNoDeviceIds(label);
76
+ if (missing) {
77
+ return missing;
78
+ }
79
+ if (!_payload.hasOwnProperty('meta')) { // no i18n
80
+ _payload.meta = transport.getMetaObj();
81
+ }
82
+ if (attempts.attemptsExhausted(path)) {
83
+ // five passes without a confirmed landing. Keeping it would block every later batch
84
+ // behind a payload the proxy will now refuse for its attempt number alone
85
+ logger.warnAlways('apptics: dropping a ' + label + ' batch after ' + attempts.MAX_ATTEMPTS + ' attempts'); // no i18n
86
+ attempts.resetAttempts(path);
87
+ return Promise.resolve({ result: 'success' }); // no i18n
88
+ }
89
+ logger.Console.log(label + ': Payload size : ' + (utils.sizeof(_payload) / 1024)); // no i18n
90
+ var body = JSON.stringify(_payload);
91
+ return forget
92
+ ? transport.postKeepalive(path, body, transport.apiHeaders(), label)
93
+ : transport.postToApptics(path, body, transport.apiHeaders(), label);
94
+ }
95
+ /**
96
+ * Hands a send's outcome back to a sender. Normally the sender waits for it. While the page
97
+ * closes it does not: the request is already out, and waiting would hold the next queue's send
98
+ * until after the page has gone. The outcome is still handled whenever it arrives.
99
+ */
100
+ function awaitUnlessClosing(landed, forget, label) {
101
+ if (!forget) {
102
+ return landed.then(function () { return undefined; });
103
+ }
104
+ landed.catch(function (err) {
105
+ logger.Console.log(label + ': not confirmed before the page closed, kept for the next send: ' + String(err)); // no i18n
106
+ });
107
+ return undefined;
108
+ }
109
+
110
+ exports.awaitUnlessClosing = awaitUnlessClosing;
111
+ exports.clearDefer = clearDefer;
112
+ exports.defer = defer;
113
+ exports.freshItems = freshItems;
114
+ exports.sendBatch = sendBatch;
115
+ exports.withSendLock = withSendLock;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Where a log line was raised, for logSDK's `filename` and `linenumber`.
3
+ *
4
+ * There is no caller introspection in a browser, so the only way to answer "which line was this"
5
+ * is to throw an Error nobody catches and read its stack. That is cheap enough for a channel that
6
+ * only carries the SDK's own failures, but it is never on the app's path: everything here is
7
+ * wrapped so a stack we cannot parse costs a line its call site and nothing more.
8
+ */
9
+ export interface CallSite {
10
+ /** The script's basename, not its url: logSDK caps filename at 100 characters. */
11
+ filename: string;
12
+ /** 0 when the stack gave us nothing — see entryFor() for why it is still sent. */
13
+ linenumber: number;
14
+ /** The calling function's name, when the frame has one. Anonymous callers have none. */
15
+ fn?: string;
16
+ }
17
+ export declare const NO_CALL_SITE: CallSite;
18
+ /**
19
+ * The frame `skip` frames down a stack, counting only the ones that name a file — V8 heads its
20
+ * stacks with an `Error` line and Firefox does not, so counting raw lines would read a different
21
+ * frame in each browser.
22
+ */
23
+ export declare function callSiteFromStack(stack: string | undefined, skip: number): CallSite;
24
+ /**
25
+ * Where the caller `skip` levels above this call sits. `skip` is 0 for this function's own
26
+ * caller; each wrapper between that caller and the place worth reporting adds one.
27
+ */
28
+ export declare function callSite(skip: number): CallSite;
@@ -0,0 +1,93 @@
1
+ /*! @zoho_apptics/apptics-js-sdk v2.0.0-beta | (c) Zoho Corporation Private Limited | see LICENSE */
2
+ 'use strict';
3
+
4
+ /**
5
+ * Where a log line was raised, for logSDK's `filename` and `linenumber`.
6
+ *
7
+ * There is no caller introspection in a browser, so the only way to answer "which line was this"
8
+ * is to throw an Error nobody catches and read its stack. That is cheap enough for a channel that
9
+ * only carries the SDK's own failures, but it is never on the app's path: everything here is
10
+ * wrapped so a stack we cannot parse costs a line its call site and nothing more.
11
+ */
12
+ const NO_CALL_SITE = { filename: '', linenumber: 0, fn: '' };
13
+ /** logSDK declares max-len="100" on filename. */
14
+ const FILENAME_MAX = 100;
15
+ /**
16
+ * The file and line out of one stack frame, in either shape a browser produces:
17
+ * V8: ` at doThing (https://host/app.js:12:34)`
18
+ * Firefox/Safari: `doThing@https://host/app.js:12:34`
19
+ * Both end in `:line:column`, which is the only part that is the same everywhere, so the match is
20
+ * anchored there and the column is read only so that it can be thrown away — without it the
21
+ * pattern would take the column for the line.
22
+ */
23
+ const FRAME = /([^\s(@]+):(\d+):(\d+)\)?$/;
24
+ /** `https://host/path/app.js?v=2` -> `app.js`. The url would not fit in 100 characters. */
25
+ function basename(url) {
26
+ var path = url.split(/[?#]/)[0] || url;
27
+ var parts = path.split('/');
28
+ return (parts[parts.length - 1] || path).slice(0, FILENAME_MAX);
29
+ }
30
+ /**
31
+ * The function a frame names, in either shape:
32
+ * V8: `at doThing (` — or `at async doThing (`
33
+ * Firefox/Safari: `doThing@`
34
+ * A frame without one (`at https://…` or `@https://…`) is an anonymous caller, and gets ''.
35
+ */
36
+ const FRAME_FN_V8 = /^at\s+(?:async\s+)?(.+?)\s+\(/;
37
+ const FRAME_FN_OTHER = /^([^@\s]+)@/;
38
+ function frameFunction(frame) {
39
+ var match = FRAME_FN_V8.exec(frame) || FRAME_FN_OTHER.exec(frame);
40
+ return match ? (match[1] || '') : ''; // no i18n
41
+ }
42
+ function parseFrame(line) {
43
+ var trimmed = line.trim();
44
+ var match = FRAME.exec(trimmed);
45
+ if (match === null) {
46
+ return null;
47
+ }
48
+ var line_no = Number(match[2]);
49
+ if (!isFinite(line_no)) {
50
+ return null;
51
+ }
52
+ return { filename: basename(match[1] || ''), linenumber: line_no, fn: frameFunction(trimmed) };
53
+ }
54
+ /**
55
+ * The frame `skip` frames down a stack, counting only the ones that name a file — V8 heads its
56
+ * stacks with an `Error` line and Firefox does not, so counting raw lines would read a different
57
+ * frame in each browser.
58
+ */
59
+ function callSiteFromStack(stack, skip) {
60
+ if (!stack) {
61
+ return NO_CALL_SITE;
62
+ }
63
+ var lines = stack.split('\n');
64
+ var seen = 0;
65
+ for (var i = 0; i < lines.length; i++) {
66
+ var frame = parseFrame(lines[i] || '');
67
+ if (frame === null) {
68
+ continue;
69
+ }
70
+ if (seen++ < skip) {
71
+ continue;
72
+ }
73
+ return frame;
74
+ }
75
+ return NO_CALL_SITE;
76
+ }
77
+ /**
78
+ * Where the caller `skip` levels above this call sits. `skip` is 0 for this function's own
79
+ * caller; each wrapper between that caller and the place worth reporting adds one.
80
+ */
81
+ function callSite(skip) {
82
+ try {
83
+ // +1 for this function's own frame, which is never the answer
84
+ return callSiteFromStack(new Error().stack, skip + 1);
85
+ }
86
+ catch (err) {
87
+ return NO_CALL_SITE;
88
+ }
89
+ }
90
+
91
+ exports.NO_CALL_SITE = NO_CALL_SITE;
92
+ exports.callSite = callSite;
93
+ exports.callSiteFromStack = callSiteFromStack;
@@ -0,0 +1,23 @@
1
+ import type { TrackingStatus } from '../types.js';
2
+ /** DNT counts only when not ignored; when it counts, tracking switches to NO_TRACKING. */
3
+ export declare function hasDoNotTrackEnabled(): boolean;
4
+ export declare function opt_in_status(): TrackingStatus;
5
+ export declare function shouldTrackOrSendData(): boolean;
6
+ /**
7
+ * The guard every tracking call starts with: init() has run, the client isn't a crawler,
8
+ * and consent / server flags allow tracking.
9
+ */
10
+ export declare function canTrack(caller: string): boolean;
11
+ /** canTrack plus the server's `engagementtracking` flag from getupdates (events, screens, sessions, api calls). */
12
+ export declare function canTrackEngagement(caller: string): boolean;
13
+ /**
14
+ * canTrack plus the server's heatmap flag (getsdkconfig module 18).
15
+ *
16
+ * Heatmap rode the engagement flag until v2 gave it one of its own, which matters: an app may
17
+ * well want events while declining to have every click's coordinates recorded.
18
+ */
19
+ export declare function canTrackHeatmap(caller: string): boolean;
20
+ /** canTrack plus the server's `errortracking` flag from getupdates. */
21
+ export declare function canTrackErrors(caller: string): boolean;
22
+ export declare function setTrackingStatus(trackingState: TrackingStatus): void;
23
+ export declare function getTrackingStatus(): TrackingStatus;
@@ -0,0 +1,130 @@
1
+ /*! @zoho_apptics/apptics-js-sdk v2.0.0-beta | (c) Zoho Corporation Private Limited | see LICENSE */
2
+ 'use strict';
3
+
4
+ var constants = require('./constants.js');
5
+ var state = require('./state.js');
6
+ var logger = require('./logger.js');
7
+ var utils = require('./utils.js');
8
+ var storage = require('./storage.js');
9
+ var env = require('./env.js');
10
+ var hooks = require('./hooks.js');
11
+
12
+ /** DNT counts only when not ignored; when it counts, tracking switches to NO_TRACKING. */
13
+ function hasDoNotTrackEnabled() {
14
+ if (state._ZAP._ignoreDnt) {
15
+ return false;
16
+ }
17
+ if (env.isDntOn()) {
18
+ logger.Console.warn('hasDoNotTrackEnabled: DoNotTrack is enabled'); // no i18n
19
+ setTrackingStatus(constants.AP_TRACKING_STATUS.NO_TRACKING);
20
+ logger.Console.log('hasDoNotTrackEnabled: Setting tracking status to NO_TRACKING'); // no i18n
21
+ return true;
22
+ }
23
+ return false;
24
+ }
25
+ function opt_in_status() {
26
+ if (hasDoNotTrackEnabled()) {
27
+ logger.Console.warn('opt_in_status: It seems "Do Not Track" is enabled in this browser. Please enable tracking in the browser settings to continue tracking.'); // no i18n
28
+ return constants.AP_TRACKING_STATUS.NO_TRACKING;
29
+ }
30
+ var status = storage.tracking_preference.opt_in_status();
31
+ if (status == -1) {
32
+ logger.Console.warn('opt_in_status: You are opted out of Apptics tracking. This will prevent the our SDK from sending no data to our server.'); // no i18n
33
+ }
34
+ return status;
35
+ }
36
+ function shouldTrackOrSendData() {
37
+ var optInStatus = opt_in_status();
38
+ return optInStatus > -1 && state._ZAP._shouldTrack;
39
+ }
40
+ /**
41
+ * The guard every tracking call starts with: init() has run, the client isn't a crawler,
42
+ * and consent / server flags allow tracking.
43
+ */
44
+ function canTrack(caller) {
45
+ if (!state._ZAP._token) {
46
+ logger.Console.warn('apptics.' + caller + ': You must call apptics.init() first'); // no i18n
47
+ return false;
48
+ }
49
+ if (env.is_apptics_disabled()) {
50
+ return false;
51
+ }
52
+ return shouldTrackOrSendData();
53
+ }
54
+ /** canTrack plus the server's `engagementtracking` flag from getupdates (events, screens, sessions, api calls). */
55
+ function canTrackEngagement(caller) {
56
+ if (!canTrack(caller)) {
57
+ return false;
58
+ }
59
+ if (!state._ZAP._engagementTracking) {
60
+ logger.Console.log('apptics.' + caller + ': engagement tracking is turned off by the server'); // no i18n
61
+ return false;
62
+ }
63
+ return true;
64
+ }
65
+ /**
66
+ * canTrack plus the server's heatmap flag (getsdkconfig module 18).
67
+ *
68
+ * Heatmap rode the engagement flag until v2 gave it one of its own, which matters: an app may
69
+ * well want events while declining to have every click's coordinates recorded.
70
+ */
71
+ function canTrackHeatmap(caller) {
72
+ if (!canTrack(caller)) {
73
+ return false;
74
+ }
75
+ if (!state._ZAP._heatmapTracking) {
76
+ logger.Console.log('apptics.' + caller + ': heatmap tracking is turned off by the server'); // no i18n
77
+ return false;
78
+ }
79
+ return true;
80
+ }
81
+ /** canTrack plus the server's `errortracking` flag from getupdates. */
82
+ function canTrackErrors(caller) {
83
+ if (!canTrack(caller)) {
84
+ return false;
85
+ }
86
+ if (!state._ZAP._errorTracking) {
87
+ logger.Console.log('apptics.' + caller + ': error tracking is turned off by the server'); // no i18n
88
+ return false;
89
+ }
90
+ return true;
91
+ }
92
+ function setTrackingStatus(trackingState) {
93
+ if (utils.isEmpty(trackingState)) {
94
+ logger.Console.warn('setTrackingStatus: trackingStatus is Empty'); // no i18n
95
+ return;
96
+ }
97
+ if (storage.tracking_preference.opt_in_status() == trackingState) {
98
+ return;
99
+ }
100
+ storage.tracking_preference.update_status(trackingState);
101
+ state._ZAP._devicestatus = storage.tracking_preference.opt_in_status();
102
+ state._ZAP._isanonrequired = storage.tracking_preference.opt_in_status() == constants.AP_TRACKING_STATUS.USAGE_TRACKING_WITH_PII ? false : state._ZAP._isanonrequired;
103
+ if (storage.tracking_preference.opt_in_status() != constants.AP_TRACKING_STATUS.NO_TRACKING) {
104
+ logger.Console.log('setTrackingStatus: Updating device info with new tracking status'); // no i18n
105
+ hooks.hooks.updateDevice(state._ZAP._device_info).then(function (result) {
106
+ if (utils.isSuccess(result)) {
107
+ logger.Console.log('setTrackingStatus: Device info updated with new tracking status' + JSON.stringify(result.data)); // no i18n
108
+ logger.Console.dir(result.data);
109
+ }
110
+ else {
111
+ logger.Console.log('setTrackingStatus: Error updating device info with new tracking status: ' + JSON.stringify(result)); // no i18n
112
+ }
113
+ }).catch(function (err) {
114
+ logger.Console.warn('setTrackingStatus: Error updating device info with new tracking status: ' + JSON.stringify(err)); // no i18n
115
+ });
116
+ }
117
+ }
118
+ function getTrackingStatus() {
119
+ return opt_in_status();
120
+ }
121
+
122
+ exports.canTrack = canTrack;
123
+ exports.canTrackEngagement = canTrackEngagement;
124
+ exports.canTrackErrors = canTrackErrors;
125
+ exports.canTrackHeatmap = canTrackHeatmap;
126
+ exports.getTrackingStatus = getTrackingStatus;
127
+ exports.hasDoNotTrackEnabled = hasDoNotTrackEnabled;
128
+ exports.opt_in_status = opt_in_status;
129
+ exports.setTrackingStatus = setTrackingStatus;
130
+ exports.shouldTrackOrSendData = shouldTrackOrSendData;
@@ -0,0 +1,212 @@
1
+ export declare const AP_TRACKING_STATUS: Readonly<{
2
+ readonly USAGE_TRACKING_WITH_PII: 1;
3
+ readonly USAGE_TRACKING_WITHOUT_PII: 4;
4
+ readonly NO_TRACKING: -1;
5
+ }>;
6
+ export declare const AP_FEEDBACK_TYPE: Readonly<{
7
+ readonly BUG: 0;
8
+ readonly FEEDBACK: 1;
9
+ readonly HELP: 2;
10
+ readonly REPORT: 3;
11
+ }>;
12
+ export declare const AP_CONSTANTS: Readonly<{
13
+ readonly SCREEN: "screen";
14
+ readonly SESSION: "session";
15
+ readonly EVENT: "event";
16
+ readonly API: "api";
17
+ readonly ERROR: "error";
18
+ readonly SUCCESS: "success";
19
+ readonly BROWSER: "Browser";
20
+ }>;
21
+ export declare const DEFAULT_API_PATHS: Readonly<{
22
+ readonly addversion: "app/addversion";
23
+ readonly regdevice: "device/add";
24
+ readonly reguser: "user/register";
25
+ readonly engagement: "engagement/add";
26
+ readonly error: "exception/error";
27
+ readonly feedback: "feedback/add";
28
+ readonly sdkconfig: "getsdkconfig";
29
+ readonly getupdates: "getupdates";
30
+ readonly consolelog: "log/add";
31
+ readonly heatmap: "heatmap/add";
32
+ }>;
33
+ /**
34
+ * Which API version each path lives under.
35
+ *
36
+ * Every path the SDK calls is defined under v2 in the proxy's security-sdk.xml, and four of them —
37
+ * app/addversion, getsdkconfig, heatmap/add and log/add — are defined there *only* under v2: there
38
+ * is no v1 url for them to fall back to, so sending v1 reaches nothing. It stays a per-path map
39
+ * rather than one shared prefix because v1 urls do still exist for the other five, so a path can
40
+ * be moved back on its own if one of them turns out not to be ready.
41
+ */
42
+ export declare const API_VERSIONS: Readonly<Record<keyof typeof DEFAULT_API_PATHS, string>>;
43
+ /**
44
+ * The SDK subsystem a remote log line is about, as console/addlog's `module` param.
45
+ * These are the server's own names, so they are sent exactly as written here.
46
+ */
47
+ export declare const AP_LOG_MODULE: Readonly<{
48
+ readonly SESSION: "Session";
49
+ readonly SCREEN: "Screen";
50
+ readonly EVENT: "Event";
51
+ readonly API: "API";
52
+ readonly HEATMAP: "Heatmap";
53
+ readonly PROPERTIES: "Properties";
54
+ }>;
55
+ /**
56
+ * The modules getsdkconfig reports on, by the ids it keys them with. The SDK acts on the ones it
57
+ * has something to switch off; anything else the server sends is stored but unused.
58
+ */
59
+ export declare const SDK_MODULE: Readonly<{
60
+ /**
61
+ * Remote config. It is the one module both answers report on: getupdates names it in
62
+ * `moduleids` and reports its flag back, and getsdkconfig reports the same flag as the
63
+ * authority. Where they disagree, getsdkconfig wins.
64
+ */
65
+ readonly REMOTE_CONFIG: "2";
66
+ readonly SESSION: "11";
67
+ readonly FEEDBACK: "12";
68
+ readonly CRASH: "13";
69
+ readonly REMOTE_LOGGER: "17";
70
+ readonly HEATMAP: "18";
71
+ }>;
72
+ /** logSDK declares max-len="10000" on logmessage, so a line is trimmed to fit that. */
73
+ export declare const CONSOLE_LOG_MAX_BODY = 10000;
74
+ /** logSDK caps `function` at 100 characters. */
75
+ export declare const LOG_FUNCTION_MAX = 100;
76
+ /** logSDK caps `filename` at 100 too, which is why a call site carries a basename, not a url. */
77
+ export declare const LOG_FILENAME_MAX = 100;
78
+ /**
79
+ * How much of `devicename` is sent. The url declares no max-len, only safe_string, but this is a
80
+ * label a person reads in a list: anything longer is a paragraph, not a name.
81
+ */
82
+ export declare const DEVICE_NAME_MAX = 100;
83
+ /**
84
+ * The `level` every line goes out with. Everything the remote logger carries is a failure inside
85
+ * the SDK — logFailure is its only caller — so the level never varies. 3 is what the v2 reference
86
+ * shows in its only example; the scale itself is not documented anywhere we can see.
87
+ */
88
+ export declare const REMOTE_LOG_LEVEL = 3;
89
+ /**
90
+ * How long debug mode survives with nothing tracked, before switching itself off.
91
+ *
92
+ * An hour is long enough to cover reading a payload, changing the app and reloading, and short
93
+ * enough that a tab left open overnight is not still sending every call to its debug twin.
94
+ */
95
+ export declare const DEBUG_IDLE_MS: number;
96
+ /** Idle minutes that end a session. Lives on state, not in _config, but defaults here. */
97
+ export declare const DEFAULT_INACTIVE_MINUTES = 30;
98
+ /** Global defaults. `state._config` holds a mutable copy per init. */
99
+ export declare const AP_CONFIG: Readonly<{
100
+ endpoint: "/sdk/web/";
101
+ method: "POST";
102
+ transport: "XHR";
103
+ track_link_timeout: 300;
104
+ cookie_expiration_days: 365;
105
+ storage_type: "localStorage";
106
+ enable_batch_requests: true;
107
+ batch_size: 50;
108
+ batch_flush_interval: 30000;
109
+ getupdates_interval: 120000;
110
+ batch_request_timeout: 7;
111
+ auto_starts_batch: true;
112
+ mode: 1;
113
+ default_group_name: "default";
114
+ default_optin_status: number;
115
+ enable_pageview_tracking: false;
116
+ save_referrer: true;
117
+ debug: boolean;
118
+ track_by_default: true;
119
+ ignore_do_not_track: boolean;
120
+ remote_log: boolean;
121
+ /**
122
+ * Wrap XHR and fetch to record the app's API calls without it calling startTrackApi(). Off by
123
+ * default: the hostnames and paths of every request an app makes is a wider grant than events
124
+ * and screens, so the app opts in.
125
+ */
126
+ track_api: boolean;
127
+ /**
128
+ * Record a screen view for the first page and every navigation after it, from the url. On by
129
+ * default; the app's own inScreen() during a navigation replaces that navigation's view.
130
+ */
131
+ track_screen: boolean;
132
+ /**
133
+ * Print each app logger line to the browser console as well, as Android's showLogs prints to
134
+ * Logcat. Off by default; console_log is the SDK's own activity, this is the app's lines.
135
+ */
136
+ show_logs: boolean;
137
+ /**
138
+ * Record sessions automatically. On by default; false is Android's
139
+ * automaticSessionsTrackingStatus = false: no sessions, while events and screens still are.
140
+ */
141
+ track_session: boolean;
142
+ /**
143
+ * How long a visit must last before its session is stored, in milliseconds. A shorter visit with
144
+ * nothing tracked in it is dropped: a bounce or a crawler is not a session. Anything tracked
145
+ * inside the window writes the session immediately, keeping its original start time. 0 disables
146
+ * the wait and stores every session as it starts.
147
+ */
148
+ min_session_duration: number;
149
+ /**
150
+ * Record where people click and how far they scroll, for the console's heatmaps. Off by default:
151
+ * coordinates and element labels are a wider grant than events and screens, so the app opts in.
152
+ */
153
+ track_heatmap: boolean;
154
+ /**
155
+ * Send engagement, exception and log payloads to their `debug/` twins, which answer with a
156
+ * request id and a link to the server's own logs for that request. For tracing a payload that
157
+ * is not showing up in the console; off in normal use, and it does not change what is sent.
158
+ */
159
+ debug_api: boolean;
160
+ /**
161
+ * What to call this device in the debug stream. Engagement, exception and log are the three
162
+ * urls that declare `devicename`, and it is what tells one tester's browser from another's
163
+ * when several are tracing the same build. Empty by default: it rides on every one of those
164
+ * calls, so an app that is not tracing should not pay for it. With `debug_api` on and nothing
165
+ * set here, a label is derived from the browser and OS instead, since an unnamed row in the
166
+ * debug stream is no use to whoever is reading it.
167
+ */
168
+ device_name: string;
169
+ /**
170
+ * Most heatmap records one visit may produce. Clicks are cheap, but a page that scrolls a lot
171
+ * can produce them faster than they are sent, and an unbounded queue is a memory leak on a tab
172
+ * left open for a day. Reached, capture stops for the rest of the session.
173
+ */
174
+ heatmap_max_per_session: number;
175
+ }>;
176
+ export type ApConfig = {
177
+ -readonly [K in keyof typeof AP_CONFIG]: (typeof AP_CONFIG)[K];
178
+ };
179
+ /**
180
+ * Config keys `init()` refuses to start without (after the snippet aliases are resolved).
181
+ *
182
+ * `appversion` is here rather than defaulted on purpose. Every error, every device registration
183
+ * and every uploaded source map is only meaningful against the build it came from, and a default
184
+ * would answer that question wrongly and silently for every app that forgot to set it.
185
+ */
186
+ /**
187
+ * What init() must be given. Everything else the SDK needs — aaid, the portal and project ids that
188
+ * go in every url — comes back from app/addversion, which these four are enough to call.
189
+ */
190
+ export declare const REQUIRED_CONFIG: readonly ["serviceUrl", "zak", "identifier", "appversion"];
191
+ /**
192
+ * Paths with a `debug/` twin. The debug endpoints take the same body and answer with a request id
193
+ * and a link to the server-side logs for that request, which is how a payload is traced end to
194
+ * end when the console does not show what was expected.
195
+ */
196
+ export declare const DEBUG_CAPABLE_PATHS: Readonly<Record<string, boolean>>;
197
+ /**
198
+ * Paths that declare `attempt`, `firstattempttime` and `lst`.
199
+ *
200
+ * Every url that carries data declares all three. app/addversion and getsdkconfig declare none:
201
+ * they are start-up calls whose answers the SDK needs, not payloads it is pushing, and sending
202
+ * an undeclared param is refused outright as EXTRA_PARAM_FOUND.
203
+ */
204
+ export declare const RETRY_CAPABLE_PATHS: Readonly<Record<string, boolean>>;
205
+ /**
206
+ * Paths that live directly under the version, with no org and project segments. app/addversion is
207
+ * called before those ids are known, so it cannot carry them.
208
+ */
209
+ export declare const PATHS_WITHOUT_ORG: Readonly<Record<string, boolean>>;
210
+ /** Console-snippet names accepted for the canonical keys above. */
211
+ export declare const CONFIG_ALIASES: Readonly<Record<string, string>>;
212
+ export declare const BLOCKED_WS: readonly string[];