@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,362 @@
1
+ /*! @zoho_apptics/apptics-js-sdk v2.0.0-beta | (c) Zoho Corporation Private Limited | see LICENSE */
2
+ import { SDK_MODULE } from '../core/constants.js';
3
+ import { _ZAP } from '../core/state.js';
4
+ import { Console } from '../core/logger.js';
5
+ import { isEmpty, isSuccess, compareTwoObjects } from '../core/utils.js';
6
+ import { user_defaults, getKeyFromDeviceInfo } from '../core/storage.js';
7
+ import { getTimeZone, getConnectionType, getReferringURL, getDevice, getBrowserVersion, getBrowser, getOS } from '../core/env.js';
8
+ import { hasDoNotTrackEnabled } from '../core/consent.js';
9
+ import { getHeaderParams, rejectIfDisabled, rejectIfOffline, apiHeaders, postToApptics, rejectIfNoDeviceIds } from '../core/transport.js';
10
+ import { hooks } from '../core/hooks.js';
11
+ import { applyStoredAppVersion } from './appversion.js';
12
+
13
+ /** Server-assigned ids, never sent back in device payloads. */
14
+ /**
15
+ * Exactly the keys deviceInfoWebSDKV2 declares, which is exactly what device/add accepts.
16
+ *
17
+ * An allow-list rather than an exclusion list: the template is a closed set of eleven mandatory
18
+ * keys, so anything else on device_info is refused as EXTRA_PARAM_FOUND and takes the whole
19
+ * registration with it. v1 carried `frameworkid` in the body; v2 moved it to a query param, and
20
+ * `platformid` — which v1 left out — became mandatory here. It comes from app/addversion, which
21
+ * is why that call has to land first.
22
+ */
23
+ const DEVICE_BODY_KEYS = ['devicetype', 'osversion', 'timezone', 'screenheight', 'screenwidth', 'referrer', 'referringdomain', 'browser', 'browserversion', 'donottrackenabled', 'platformid']; // no i18n
24
+ /** The ones the template types as int, so an empty value has to become 0 rather than ''. */
25
+ const DEVICE_BODY_NUMERIC = ['screenheight', 'screenwidth', 'donottrackenabled', 'platformid']; // no i18n
26
+ /**
27
+ * The device/add body: all eleven declared keys, always.
28
+ *
29
+ * Every one is min-occurrences="1", so a key is sent even when its value is empty — `referrer` is
30
+ * empty on any direct visit, and leaving it out would refuse the registration over a blank the
31
+ * server is happy to receive.
32
+ */
33
+ function deviceBody(info) {
34
+ var out = {};
35
+ DEVICE_BODY_KEYS.forEach(function (key) {
36
+ var value = info[key];
37
+ var numeric = DEVICE_BODY_NUMERIC.indexOf(key) !== -1;
38
+ out[key] = isEmpty(value) ? (numeric ? 0 : '') : value; // no i18n
39
+ });
40
+ return JSON.stringify(out);
41
+ }
42
+ /**
43
+ * The fields that describe the device itself, and so the only ones worth a device/add when they
44
+ * change: a browser or OS upgrade, a new screen, a move between timezones, a do-not-track switch.
45
+ *
46
+ * `referrer` and `connectionType` are deliberately absent. Both change constantly — the referrer on
47
+ * most navigations, the connection on every network switch — so including them would send a
48
+ * device/add on nearly every page load. The server-assigned ids are absent for the opposite reason:
49
+ * they arrive from the server, so comparing them would report a change the moment registration
50
+ * fills them in.
51
+ */
52
+ const DEVICE_IDENTITY_KEYS = ['osversion', 'browser', 'browserversion', 'devicetype', 'screenheight', 'screenwidth', 'timezone', 'donottrackenabled',
53
+ // the SDK build this device runs: an upgrade to a new SDK version is a change the server is told about
54
+ 'frameworkid']; // no i18n
55
+ /** The identity fields alone, for comparing one stored device_info against a fresh one. */
56
+ function deviceIdentity(info) {
57
+ var identity = {};
58
+ DEVICE_IDENTITY_KEYS.forEach(function (key) {
59
+ identity[key] = info ? info[key] : undefined;
60
+ });
61
+ return identity;
62
+ }
63
+ function checkAndUpdateDeviceInfo() {
64
+ // read the stored info before it is overwritten below: addOrUpdateDeviceID compares the two to
65
+ // decide whether the server needs telling, and cannot do that once the new info has replaced it
66
+ var previous = user_defaults.item('device_info'); // no i18n
67
+ // params -> https://help.apptics.com/hc/en-us/articles/115004613766-Default-Properties-Collected-by-apptics
68
+ _ZAP._device_info = {
69
+ osversion: getOS(),
70
+ browser: getBrowser(),
71
+ browserversion: String(getBrowserVersion()),
72
+ donottrackenabled: hasDoNotTrackEnabled() ? 1 : 0, // no i18n
73
+ devicetype: getDevice(),
74
+ screenheight: screen.height,
75
+ screenwidth: screen.width,
76
+ referrer: getReferringURL(),
77
+ connectionType: getConnectionType(),
78
+ referringdomain: window.location.hostname || '', // no i18n
79
+ deviceid: getKeyFromDeviceInfo('deviceid'), // no i18n
80
+ anonymousid: getKeyFromDeviceInfo('anonymousid'), // no i18n
81
+ // the id of the SDK build running now, never the stored one: a stored id is the build this
82
+ // device first registered with, and every later SDK version would go on reporting it
83
+ frameworkid: _ZAP._frameworkID,
84
+ mapid: getKeyFromDeviceInfo('mapid'), // no i18n
85
+ aaid: getKeyFromDeviceInfo('aaid'), // no i18n
86
+ apid: getKeyFromDeviceInfo('apid'), // no i18n
87
+ appversionid: getKeyFromDeviceInfo('appversionid'), // no i18n
88
+ platformid: getKeyFromDeviceInfo('platformid'), // no i18n
89
+ devicetypeid: getKeyFromDeviceInfo('devicetypeid'), // no i18n
90
+ osversionid: getKeyFromDeviceInfo('osversionid'), // no i18n
91
+ timezoneid: getKeyFromDeviceInfo('timezoneid'), // no i18n
92
+ // metaWebSDKV2 needs both of these on every call: modelid comes from device/add,
93
+ // appreleaseversionid from app/addversion
94
+ modelid: getKeyFromDeviceInfo('modelid'), // no i18n
95
+ appreleaseversionid: getKeyFromDeviceInfo('appreleaseversionid'), // no i18n
96
+ timezone: getTimeZone()
97
+ };
98
+ // the rebuild above starts from browser facts, so the ids app/addversion returned are put
99
+ // back before anything is stored or compared
100
+ applyStoredAppVersion();
101
+ user_defaults.add('device_info', _ZAP._device_info); // no i18n
102
+ addOrUpdateDeviceID(_ZAP._device_info, previous);
103
+ }
104
+ function addOrUpdateDeviceID(device_info, previous) {
105
+ var old_device_info = previous !== undefined ? previous : user_defaults.item('device_info') || {}; // no i18n
106
+ // Compare the old and new device infos and update the server if anything changed in the new.
107
+ if (device_info.deviceid == null || device_info.frameworkid == null || device_info.anonymousid == null) {
108
+ device_info.frameworkid = _ZAP._frameworkID;
109
+ Console.log('addOrUpdateDeviceID: Initiated register the device'); // no i18n
110
+ registerDeviceWithApptics().then(function (result_device_info) {
111
+ if (isSuccess(result_device_info)) {
112
+ Console.log('addOrUpdateDeviceID: Success register the device ' + JSON.stringify(result_device_info.data)); // no i18n
113
+ Console.dir(result_device_info.data);
114
+ }
115
+ else {
116
+ Console.log('addOrUpdateDeviceID: Error registering the device: ' + result_device_info); // no i18n
117
+ }
118
+ }).catch(function (err) {
119
+ Console.log('addOrUpdateDeviceID: Error registering the device: ' + err); // no i18n
120
+ });
121
+ }
122
+ else if (!isEmpty(old_device_info) && !compareTwoObjects(deviceIdentity(device_info), deviceIdentity(old_device_info))) {
123
+ // the device itself changed — a browser or OS upgrade, a new screen, a different timezone.
124
+ // The update carries the stored deviceid as a param and the stored uuid as a header, so the
125
+ // server amends this device rather than creating another one: same device, new details
126
+ Console.log('addOrUpdateDeviceID: Device info changed, so updating new changes'); // no i18n
127
+ Console.dir(deviceIdentity(device_info));
128
+ updateDeviceWithApptics(device_info).catch(function (err) {
129
+ Console.log('addOrUpdateDeviceID: Error updating the device: ' + err); // no i18n
130
+ });
131
+ }
132
+ }
133
+ /**
134
+ * The ids device/add is allowed to set. Each is taken only when the answer actually carries it.
135
+ *
136
+ * device/add is not the only source of these: app/addversion runs first and is the *only* source
137
+ * of aaid, mapid, appversionid and appreleaseversionid. Its answer is already on _device_info by
138
+ * the time registration replies, and v2's device/add does not repeat all of it - it answers about
139
+ * the device, not the build. Assigning every key unconditionally therefore overwrote ids we had
140
+ * with undefined, which is how aaid and appversionid reached metaWebSDKV2 as null and mapid went
141
+ * out as an empty header.
142
+ */
143
+ const DEVICE_RESPONSE_KEYS = ['deviceid', 'anonymousid', 'aaid', 'apid', 'mapid', 'appversionid', 'osversionid', 'timezoneid', 'platformid', 'devicetypeid', 'modelid']; // no i18n
144
+ /** Copies server-assigned ids into state and persists device info. */
145
+ function applyDeviceResponse(data) {
146
+ DEVICE_RESPONSE_KEYS.forEach(function (key) {
147
+ // an id the answer does not mention is one we already hold, or one we never had:
148
+ // either way what is on _device_info is better than undefined
149
+ if (!isEmpty(data[key])) {
150
+ _ZAP._device_info[key] = data[key];
151
+ }
152
+ });
153
+ // apid and mapid are also read straight off state for the request headers
154
+ if (!isEmpty(data.apid)) {
155
+ _ZAP._apid = data.apid;
156
+ }
157
+ if (!isEmpty(data.mapid)) {
158
+ _ZAP._mapid = data.mapid;
159
+ }
160
+ // Update the new device info into the localstorage
161
+ user_defaults.add('device_info', _ZAP._device_info); // no i18n
162
+ }
163
+ /** True while the device has no server ids, so nothing can be sent yet. */
164
+ function needsDevice() {
165
+ return isEmpty(getHeaderParams('apid')) && isEmpty(getHeaderParams('mapid')); // no i18n
166
+ }
167
+ /**
168
+ * Resolves once a registration that is in flight has settled, succeeded or not, and right away
169
+ * when none is running. Callers use it to wait for the ids rather than poll for them.
170
+ */
171
+ function deviceReady() {
172
+ if (!_ZAP._regDeviceSending) {
173
+ return Promise.resolve();
174
+ }
175
+ return new Promise(function (resolve) {
176
+ _ZAP._regDeviceResolve.push(function () { resolve(); });
177
+ _ZAP._regDeviceReject.push(function () { resolve(); });
178
+ });
179
+ }
180
+ /** Ends an in-flight registration: clears the flag and settles every caller that waited on it. */
181
+ function settleRegistration(ok, value) {
182
+ var waiters = ok ? _ZAP._regDeviceResolve : _ZAP._regDeviceReject;
183
+ _ZAP._regDeviceSending = false;
184
+ _ZAP._regDeviceResolve = [];
185
+ _ZAP._regDeviceReject = [];
186
+ waiters.forEach(function (fn) {
187
+ fn(value);
188
+ });
189
+ }
190
+ // Function to register the device
191
+ function registerDeviceWithApptics() {
192
+ var label = 'registerDeviceWithApptics'; // no i18n
193
+ var blocked = rejectIfDisabled(label);
194
+ if (blocked) {
195
+ return blocked;
196
+ }
197
+ if (!_ZAP._token) {
198
+ Console.warn(label + ': You must call apptics.init() first'); // no i18n
199
+ return Promise.reject(label + ': You must call apptics.init() first'); // no i18n
200
+ }
201
+ var offline = rejectIfOffline(label);
202
+ if (offline) {
203
+ return offline;
204
+ }
205
+ if (_ZAP._device_info.deviceid && _ZAP._device_info.anonymousid) {
206
+ return Promise.resolve(_ZAP._device_info);
207
+ }
208
+ return new Promise((resolve, reject) => {
209
+ if (_ZAP._regDeviceSending) {
210
+ // a registration is already in flight; settle together with it
211
+ _ZAP._regDeviceResolve.push(resolve);
212
+ _ZAP._regDeviceReject.push(reject);
213
+ return;
214
+ }
215
+ _ZAP._regDeviceSending = true;
216
+ var payload = deviceBody(_ZAP._device_info);
217
+ // device/add is the one url that allows all four: zak and uuid identify the caller,
218
+ // apid and mapid the app. app/addversion has already answered with apid and mapid by
219
+ // the time registration runs, so the first call can carry them like every later one.
220
+ var headers = { zak: getHeaderParams('zak'), uuid: getHeaderParams('uuid'), ...apiHeaders() }; // no i18n
221
+ postToApptics('regdevice', payload, headers, label).then(function (result) {
222
+ applyDeviceResponse(result.data || {});
223
+ settleRegistration(true, result);
224
+ resolve(result);
225
+ // first visit: the ids exist now, so fetch the server settings right away
226
+ refreshServerSettings();
227
+ }).catch(function (err) {
228
+ settleRegistration(false, err);
229
+ reject(err);
230
+ });
231
+ });
232
+ }
233
+ // Function to update the device
234
+ function updateDeviceWithApptics(device_info) {
235
+ var label = 'updateDeviceWithApptics'; // no i18n
236
+ var blocked = rejectIfDisabled(label) || rejectIfOffline(label);
237
+ if (blocked) {
238
+ return blocked;
239
+ }
240
+ var payload = deviceBody(device_info);
241
+ var headers = { zak: getHeaderParams('zak'), uuid: getHeaderParams('uuid'), ...apiHeaders() }; // no i18n
242
+ return postToApptics('regdevice', payload, headers, label).then(function (result) {
243
+ applyDeviceResponse(result.data || {});
244
+ return result;
245
+ });
246
+ }
247
+ // Function to get updates from the server
248
+ function getUpdatesFromServer() {
249
+ var label = 'getUpdatesFromServer'; // no i18n
250
+ var blocked = rejectIfOffline(label) || rejectIfNoDeviceIds(label);
251
+ if (blocked) {
252
+ return blocked;
253
+ }
254
+ // getsdkconfig takes no body: the ids it needs are parameters
255
+ return postToApptics('sdkconfig', '', apiHeaders(), label).then(function (result) {
256
+ var data = result.data || {};
257
+ applyServerFlags(data);
258
+ user_defaults.add('trackinfo', _ZAP._trackinfo); // no i18n
259
+ Console.log('getUpdatesFromServer: ' + JSON.stringify(_ZAP._trackinfo)); // no i18n
260
+ return data;
261
+ });
262
+ }
263
+ /**
264
+ * Whether getsdkconfig says a module is on.
265
+ *
266
+ * Absent means on: a server that does not report a module has not turned it off, and an SDK that
267
+ * went quiet because of a key it had never heard of would be impossible to diagnose.
268
+ */
269
+ function moduleEnabled(status, id) {
270
+ var entry = status[id];
271
+ if (!entry || typeof entry !== 'object') {
272
+ return true;
273
+ }
274
+ return entry.enabled !== false;
275
+ }
276
+ /**
277
+ * Applies the server's tracking flags, from a getsdkconfig response or the saved trackinfo.
278
+ *
279
+ * v2 reports a flag per module, keyed by a numeric id, rather than the loose booleans getupdates
280
+ * answered with. Both shapes are read: the stored trackinfo from a previous version of this SDK
281
+ * is in the old shape, and discarding it would mean a visit tracking things the server had
282
+ * already said to stop.
283
+ */
284
+ function applyServerFlags(data) {
285
+ var status = (data.tracking_status && typeof data.tracking_status === 'object'
286
+ ? data.tracking_status : {});
287
+ var hasModules = Object.keys(status).length > 0;
288
+ if (data.hasOwnProperty('tracking_enabled')) { // no i18n
289
+ _ZAP._shouldTrack = data.tracking_enabled !== false;
290
+ }
291
+ else {
292
+ // the old shape: archived versions and untracked customer groups
293
+ var versionArchived = !data.hasOwnProperty('versionarchivestatus') || isEmpty(data.versionarchivestatus)
294
+ ? true : data.versionarchivestatus;
295
+ var customerGroupTracking = !data.hasOwnProperty('customergrouptracking') || isEmpty(data.customergrouptracking)
296
+ ? true : data.customergrouptracking;
297
+ _ZAP._shouldTrack = versionArchived || !customerGroupTracking;
298
+ }
299
+ if (hasModules) {
300
+ // sessions carry screens, events and api calls, so module 11 gates all of engagement
301
+ _ZAP._engagementTracking = moduleEnabled(status, SDK_MODULE.SESSION);
302
+ _ZAP._errorTracking = moduleEnabled(status, SDK_MODULE.CRASH);
303
+ _ZAP._heatmapTracking = moduleEnabled(status, SDK_MODULE.HEATMAP);
304
+ _ZAP._remoteLoggerEnabled = moduleEnabled(status, SDK_MODULE.REMOTE_LOGGER);
305
+ _ZAP._feedbackEnabled = moduleEnabled(status, SDK_MODULE.FEEDBACK);
306
+ // getsdkconfig is the authority on this one: getupdates reports it too and the two can
307
+ // disagree while both are in flight, so what is read here wins
308
+ _ZAP._remoteConfigEnabled = moduleEnabled(status, SDK_MODULE.REMOTE_CONFIG);
309
+ }
310
+ else {
311
+ _ZAP._engagementTracking = data.engagementtracking !== false;
312
+ _ZAP._errorTracking = data.errortracking !== false;
313
+ _ZAP._heatmapTracking = data.heatmaptracking !== false;
314
+ _ZAP._remoteLoggerEnabled = data.remoteloggerenabled !== false;
315
+ _ZAP._feedbackEnabled = data.feedbackenabled !== false;
316
+ }
317
+ var quartz = (data.quartz && typeof data.quartz === 'object' ? data.quartz : {});
318
+ _ZAP._quartzEnabled = quartz.hasOwnProperty('quartz_enabled') // no i18n
319
+ ? quartz.quartz_enabled !== false
320
+ : data.quartzenabled !== false;
321
+ // when to ask again, which replaces polling on a fixed interval
322
+ if (typeof data.next_check_after === 'number' && data.next_check_after > 0) {
323
+ _ZAP._nextConfigCheck = data.next_check_after;
324
+ }
325
+ _ZAP._trackinfo = {
326
+ engagementtracking: _ZAP._engagementTracking,
327
+ errortracking: _ZAP._errorTracking,
328
+ heatmaptracking: _ZAP._heatmapTracking,
329
+ remoteloggerenabled: _ZAP._remoteLoggerEnabled,
330
+ feedbackenabled: _ZAP._feedbackEnabled,
331
+ quartzenabled: _ZAP._quartzEnabled,
332
+ shouldtrack: _ZAP._shouldTrack,
333
+ next_check_after: _ZAP._nextConfigCheck
334
+ };
335
+ }
336
+ /**
337
+ * Start-up: applies the server settings saved by the last getupdates, so a "stop tracking"
338
+ * answer holds across page loads instead of resetting to "on" until the next check.
339
+ */
340
+ function restoreServerSettings() {
341
+ var saved = user_defaults.item('trackinfo'); // no i18n
342
+ if (saved && typeof saved === 'object') { // no i18n
343
+ applyServerFlags(saved);
344
+ Console.log('restoreServerSettings: ' + JSON.stringify(_ZAP._trackinfo)); // no i18n
345
+ }
346
+ }
347
+ /**
348
+ * Fetches the server settings now if the device is registered. On a first visit the ids don't
349
+ * exist yet; registerDeviceWithApptics calls this as soon as device/add succeeds.
350
+ */
351
+ function refreshServerSettings() {
352
+ if (isEmpty(getHeaderParams('apid')) && isEmpty(getHeaderParams('mapid'))) { // no i18n
353
+ return;
354
+ }
355
+ getUpdatesFromServer().catch(function (err) {
356
+ Console.log(err);
357
+ });
358
+ }
359
+ hooks.updateDevice = updateDeviceWithApptics;
360
+ hooks.refreshDeviceInfo = checkAndUpdateDeviceInfo;
361
+
362
+ export { addOrUpdateDeviceID, checkAndUpdateDeviceInfo, deviceReady, getUpdatesFromServer, needsDevice, refreshServerSettings, registerDeviceWithApptics, restoreServerSettings, updateDeviceWithApptics };
@@ -0,0 +1,84 @@
1
+ /**
2
+ * What API tracking records, and under what name — Android's AppticsApiTracker.configure, built
3
+ * with ApiTrackingBuilder the way user properties are built with UserBuilder:
4
+ *
5
+ * configureApiTracking(new ApiTrackingBuilder()
6
+ * .allowOnlyDomains('api.zylker.com', 'api.zylker.in')
7
+ * .groupDomains('api.zylker.*')
8
+ * .ignoreEndpoint('/health', '/internal/**')
9
+ * .addPattern('/v2/catalog/{categoryId}/items/{itemId}')
10
+ * .build());
11
+ *
12
+ * Two jobs. Filtering decides whether a call is recorded at all: ignore rules first, and they
13
+ * always win, then the allow lists. Normalization decides the path it is recorded under, so that
14
+ * `/users/42/orders` and `/users/43/orders` are one endpoint on the console rather than two: the
15
+ * query string goes, an explicit pattern is used when one matches, and otherwise numeric ids,
16
+ * UUIDs and JWTs become `*`.
17
+ *
18
+ * Both apply to every call, the ones the fetch/XHR wrappers catch and the ones the app reports
19
+ * with trackApi() or startTrackApi(), so one set of rules decides what the API page shows.
20
+ */
21
+ /** The rules, as ApiTrackingBuilder.build() returns them. Every list may be empty. */
22
+ export interface ApiTrackingConfig {
23
+ ignoreDomains: string[];
24
+ allowOnlyDomains: string[];
25
+ allowOnlyTLDs: string[];
26
+ ignoreTLDs: string[];
27
+ ignoreDomainPrefixes: string[];
28
+ ignoreDomainSuffixes: string[];
29
+ groupDomains: string[];
30
+ ignoreEndpoints: string[];
31
+ patterns: string[];
32
+ preserveSegments: string[];
33
+ autoDetection: boolean;
34
+ }
35
+ /** Builds the rules for configureApiTracking, with AppticsApiTracker.configure's names. */
36
+ export declare class ApiTrackingBuilder {
37
+ private rules;
38
+ /** Never records these hosts. */
39
+ ignoreDomains(...domains: string[]): this;
40
+ /** Records only these hosts; every other is skipped. */
41
+ allowOnlyDomains(...domains: string[]): this;
42
+ /** Records only hosts ending in these TLDs, e.g. `.com`. */
43
+ allowOnlyTLDs(...tlds: string[]): this;
44
+ /** Never records hosts ending in these TLDs, e.g. `.local`. */
45
+ ignoreTLDs(...tlds: string[]): this;
46
+ /** Never records hosts starting with these, e.g. `dev.`. */
47
+ ignoreDomainPrefixes(...prefixes: string[]): this;
48
+ /** Never records hosts ending with these, e.g. `.cdn.net`. */
49
+ ignoreDomainSuffixes(...suffixes: string[]): this;
50
+ /** Records the hosts a pattern such as `api.myapp.*` matches under that one name. */
51
+ groupDomains(...patterns: string[]): this;
52
+ /** Never records these paths: exact, `*` or `{name}` for one segment, `**` at the end for a prefix. */
53
+ ignoreEndpoint(...paths: string[]): this;
54
+ /** Records a path this pattern matches as the pattern, with each `{name}` as `*`. Tried before auto-detection. */
55
+ addPattern(...patterns: string[]): this;
56
+ /** Segments never turned into `*`, e.g. `v1` or `404`. */
57
+ preserveSegments(...segments: string[]): this;
58
+ /** `false`: only addPattern paths are normalized; every other path is recorded as it is. */
59
+ autoDetection(enabled: boolean): this;
60
+ build(): ApiTrackingConfig;
61
+ }
62
+ /**
63
+ * Applies the rules, replacing any given before. Takes what build() returned, or the builder
64
+ * itself. Call it once, before the requests it should cover; it works before init().
65
+ */
66
+ export declare function configureApiTracking(config: ApiTrackingConfig | ApiTrackingBuilder): void;
67
+ /** The rules in force, for tests and the playground. */
68
+ export declare function apiTrackingConfig(): ApiTrackingConfig;
69
+ /** Whether calls to this host are recorded. Ignore rules are checked first and always win. */
70
+ export declare function hostAllowed(hostname: string): boolean;
71
+ /** The name a host is recorded under: the first groupDomains pattern it matches, or itself. */
72
+ export declare function groupedHost(hostname: string): string;
73
+ /** Whether a host is one of the groupDomains names, which carry a `*` no real host has. */
74
+ export declare function isGroupedHost(hostname: string): boolean;
75
+ /** The path without its query string or fragment, which is where ids and tokens travel. */
76
+ export declare function withoutQuery(path: string): string;
77
+ /** Whether ignoreEndpoint leaves this path out. Matched on the path as called, query removed. */
78
+ export declare function endpointIgnored(path: string): boolean;
79
+ /**
80
+ * The path a call is recorded under. The query goes; then the first addPattern that matches is
81
+ * used, with each `{name}` as `*` (the server's path rule has no room for braces); otherwise, with
82
+ * autoDetection on, numeric ids, UUIDs and JWTs become `*`, except preserveSegments.
83
+ */
84
+ export declare function normalizeApiPath(path: string): string;
@@ -0,0 +1,211 @@
1
+ /*! @zoho_apptics/apptics-js-sdk v2.0.0-beta | (c) Zoho Corporation Private Limited | see LICENSE */
2
+ /**
3
+ * What API tracking records, and under what name — Android's AppticsApiTracker.configure, built
4
+ * with ApiTrackingBuilder the way user properties are built with UserBuilder:
5
+ *
6
+ * configureApiTracking(new ApiTrackingBuilder()
7
+ * .allowOnlyDomains('api.zylker.com', 'api.zylker.in')
8
+ * .groupDomains('api.zylker.*')
9
+ * .ignoreEndpoint('/health', '/internal/**')
10
+ * .addPattern('/v2/catalog/{categoryId}/items/{itemId}')
11
+ * .build());
12
+ *
13
+ * Two jobs. Filtering decides whether a call is recorded at all: ignore rules first, and they
14
+ * always win, then the allow lists. Normalization decides the path it is recorded under, so that
15
+ * `/users/42/orders` and `/users/43/orders` are one endpoint on the console rather than two: the
16
+ * query string goes, an explicit pattern is used when one matches, and otherwise numeric ids,
17
+ * UUIDs and JWTs become `*`.
18
+ *
19
+ * Both apply to every call, the ones the fetch/XHR wrappers catch and the ones the app reports
20
+ * with trackApi() or startTrackApi(), so one set of rules decides what the API page shows.
21
+ */
22
+ function emptyConfig() {
23
+ return {
24
+ ignoreDomains: [], allowOnlyDomains: [], allowOnlyTLDs: [], ignoreTLDs: [],
25
+ ignoreDomainPrefixes: [], ignoreDomainSuffixes: [], groupDomains: [], ignoreEndpoints: [],
26
+ patterns: [], preserveSegments: [], autoDetection: true,
27
+ };
28
+ }
29
+ /** Lower-cased, trimmed, non-empty strings: a host list is compared case-insensitively. */
30
+ function cleanList(values, lower) {
31
+ var out = [];
32
+ values.forEach(function (value) {
33
+ if (typeof value !== 'string') { // no i18n
34
+ return;
35
+ }
36
+ var one = value.trim();
37
+ if (one !== '') { // no i18n
38
+ out.push(lower ? one.toLowerCase() : one);
39
+ }
40
+ });
41
+ return out;
42
+ }
43
+ /** A TLD as `.com`, whether it was given as `.com` or `com`. */
44
+ function asTld(value) {
45
+ return value.charAt(0) === '.' ? value : '.' + value; // no i18n
46
+ }
47
+ /** Builds the rules for configureApiTracking, with AppticsApiTracker.configure's names. */
48
+ class ApiTrackingBuilder {
49
+ constructor() {
50
+ this.rules = emptyConfig();
51
+ }
52
+ /** Never records these hosts. */
53
+ ignoreDomains(...domains) { this.rules.ignoreDomains.push(...cleanList(domains, true)); return this; }
54
+ /** Records only these hosts; every other is skipped. */
55
+ allowOnlyDomains(...domains) { this.rules.allowOnlyDomains.push(...cleanList(domains, true)); return this; }
56
+ /** Records only hosts ending in these TLDs, e.g. `.com`. */
57
+ allowOnlyTLDs(...tlds) { this.rules.allowOnlyTLDs.push(...cleanList(tlds, true).map(asTld)); return this; }
58
+ /** Never records hosts ending in these TLDs, e.g. `.local`. */
59
+ ignoreTLDs(...tlds) { this.rules.ignoreTLDs.push(...cleanList(tlds, true).map(asTld)); return this; }
60
+ /** Never records hosts starting with these, e.g. `dev.`. */
61
+ ignoreDomainPrefixes(...prefixes) { this.rules.ignoreDomainPrefixes.push(...cleanList(prefixes, true)); return this; }
62
+ /** Never records hosts ending with these, e.g. `.cdn.net`. */
63
+ ignoreDomainSuffixes(...suffixes) { this.rules.ignoreDomainSuffixes.push(...cleanList(suffixes, true)); return this; }
64
+ /** Records the hosts a pattern such as `api.myapp.*` matches under that one name. */
65
+ groupDomains(...patterns) { this.rules.groupDomains.push(...cleanList(patterns, true)); return this; }
66
+ /** Never records these paths: exact, `*` or `{name}` for one segment, `**` at the end for a prefix. */
67
+ ignoreEndpoint(...paths) { this.rules.ignoreEndpoints.push(...cleanList(paths, false)); return this; }
68
+ /** Records a path this pattern matches as the pattern, with each `{name}` as `*`. Tried before auto-detection. */
69
+ addPattern(...patterns) { this.rules.patterns.push(...cleanList(patterns, false)); return this; }
70
+ /** Segments never turned into `*`, e.g. `v1` or `404`. */
71
+ preserveSegments(...segments) { this.rules.preserveSegments.push(...cleanList(segments, false)); return this; }
72
+ /** `false`: only addPattern paths are normalized; every other path is recorded as it is. */
73
+ autoDetection(enabled) { this.rules.autoDetection = enabled !== false; return this; }
74
+ build() {
75
+ var built = emptyConfig();
76
+ Object.keys(built).forEach((key) => {
77
+ var value = this.rules[key];
78
+ built[key] = Array.isArray(value) ? value.slice() : value;
79
+ });
80
+ return built;
81
+ }
82
+ }
83
+ var current = emptyConfig();
84
+ /**
85
+ * Applies the rules, replacing any given before. Takes what build() returned, or the builder
86
+ * itself. Call it once, before the requests it should cover; it works before init().
87
+ */
88
+ function configureApiTracking(config) {
89
+ var built = config instanceof ApiTrackingBuilder ? config.build() : config;
90
+ var next = emptyConfig();
91
+ if (built && typeof built === 'object') { // no i18n
92
+ Object.keys(next).forEach(function (key) {
93
+ var value = built[key];
94
+ if (key === 'autoDetection') { // no i18n
95
+ next.autoDetection = value !== false;
96
+ }
97
+ else if (Array.isArray(value)) {
98
+ next[key] = value.slice();
99
+ }
100
+ });
101
+ }
102
+ current = next;
103
+ }
104
+ /* ---------------- hosts ---------------- */
105
+ function endsWithAny(host, list) {
106
+ return list.some(function (one) { return host.length >= one.length && host.slice(host.length - one.length) === one; });
107
+ }
108
+ /** Whether calls to this host are recorded. Ignore rules are checked first and always win. */
109
+ function hostAllowed(hostname) {
110
+ var host = String(hostname || '').toLowerCase(); // no i18n
111
+ if (current.ignoreDomains.indexOf(host) !== -1
112
+ || endsWithAny(host, current.ignoreTLDs)
113
+ || endsWithAny(host, current.ignoreDomainSuffixes)
114
+ || current.ignoreDomainPrefixes.some(function (prefix) { return host.indexOf(prefix) === 0; })) {
115
+ return false;
116
+ }
117
+ if (current.allowOnlyDomains.length > 0 && current.allowOnlyDomains.indexOf(host) === -1) {
118
+ return false;
119
+ }
120
+ if (current.allowOnlyTLDs.length > 0 && !endsWithAny(host, current.allowOnlyTLDs)) {
121
+ return false;
122
+ }
123
+ return true;
124
+ }
125
+ function wildcardHost(pattern) {
126
+ var source = pattern.split('*').map(function (part) {
127
+ return part.replace(/[.+?^${}()|[\]\\]/g, '\\$&'); // no i18n
128
+ }).join('[a-z0-9.-]+'); // no i18n
129
+ return new RegExp('^' + source + '$'); // no i18n
130
+ }
131
+ /** The name a host is recorded under: the first groupDomains pattern it matches, or itself. */
132
+ function groupedHost(hostname) {
133
+ var host = String(hostname || '').toLowerCase(); // no i18n
134
+ for (var i = 0; i < current.groupDomains.length; i++) {
135
+ var pattern = current.groupDomains[i];
136
+ if (pattern.indexOf('*') !== -1 && wildcardHost(pattern).test(host)) { // no i18n
137
+ return pattern;
138
+ }
139
+ }
140
+ return hostname;
141
+ }
142
+ /* ---------------- paths ---------------- */
143
+ /** The path without its query string or fragment, which is where ids and tokens travel. */
144
+ function withoutQuery(path) {
145
+ var cut = String(path || '').split(/[?#]/)[0]; // no i18n
146
+ return cut === '' ? '/' : cut; // no i18n
147
+ }
148
+ function segmentsOf(path) {
149
+ var trimmed = path.length > 1 ? path.replace(/\/+$/, '') : path; // no i18n
150
+ return trimmed.split('/').slice(1); // no i18n
151
+ }
152
+ const ONE_SEGMENT = /^(\*|\{[^/{}]*\})$/;
153
+ /** Whether a path matches a pattern: `*` and `{name}` are one segment, a final `**` is the rest. */
154
+ function matches(pattern, path) {
155
+ var want = segmentsOf(pattern);
156
+ var have = segmentsOf(path);
157
+ for (var i = 0; i < want.length; i++) {
158
+ var part = want[i];
159
+ if (part === '**' && i === want.length - 1) { // no i18n
160
+ return true;
161
+ }
162
+ if (i >= have.length) {
163
+ return false;
164
+ }
165
+ if (ONE_SEGMENT.test(part)) {
166
+ if (have[i] === '') { // no i18n
167
+ return false;
168
+ }
169
+ continue;
170
+ }
171
+ if (part !== have[i]) {
172
+ return false;
173
+ }
174
+ }
175
+ return want.length === have.length;
176
+ }
177
+ /** Whether ignoreEndpoint leaves this path out. Matched on the path as called, query removed. */
178
+ function endpointIgnored(path) {
179
+ var bare = withoutQuery(path);
180
+ return current.ignoreEndpoints.some(function (pattern) { return matches(pattern, bare); });
181
+ }
182
+ const NUMERIC = /^\d+$/;
183
+ const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
184
+ // three base64url parts, the first starting eyJ — the encoding of '{"' every JWT header opens
185
+ // with. Without that start, a file name such as jquery.min.js would pass for a token
186
+ const JWT = /^eyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/;
187
+ /**
188
+ * The path a call is recorded under. The query goes; then the first addPattern that matches is
189
+ * used, with each `{name}` as `*` (the server's path rule has no room for braces); otherwise, with
190
+ * autoDetection on, numeric ids, UUIDs and JWTs become `*`, except preserveSegments.
191
+ */
192
+ function normalizeApiPath(path) {
193
+ var bare = withoutQuery(path);
194
+ for (var i = 0; i < current.patterns.length; i++) {
195
+ var pattern = current.patterns[i];
196
+ if (matches(pattern, bare)) {
197
+ return pattern.replace(/\{[^/{}]*\}/g, '*'); // no i18n
198
+ }
199
+ }
200
+ if (!current.autoDetection) {
201
+ return bare;
202
+ }
203
+ return bare.split('/').map(function (segment) {
204
+ if (segment === '' || current.preserveSegments.indexOf(segment) !== -1) { // no i18n
205
+ return segment;
206
+ }
207
+ return NUMERIC.test(segment) || UUID.test(segment) || JWT.test(segment) ? '*' : segment; // no i18n
208
+ }).join('/'); // no i18n
209
+ }
210
+
211
+ export { ApiTrackingBuilder, configureApiTracking, endpointIgnored, groupedHost, hostAllowed, normalizeApiPath, withoutQuery };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Starts or stops automatic tracking. Safe to call repeatedly: installing twice would report each
3
+ * call twice, so the second call is a no-op.
4
+ */
5
+ export declare function enableApiTracking(enabled?: boolean): void;
6
+ /** Whether the wrappers are currently in place. */
7
+ export declare function isApiTrackingEnabled(): boolean;