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

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 (243) hide show
  1. package/CHANGELOG.md +193 -0
  2. package/LICENSE +13 -0
  3. package/README.md +846 -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/lifecycle-VYr43KcB.min.js +3 -0
  9. package/dist/chunks/lifecycle-VYr43KcB.min.js.map +1 -0
  10. package/dist/cjs/auto-init.d.ts +8 -0
  11. package/dist/cjs/auto-init.js +32 -0
  12. package/dist/cjs/core/attempts.d.ts +28 -0
  13. package/dist/cjs/core/attempts.js +113 -0
  14. package/dist/cjs/core/batch.d.ts +32 -0
  15. package/dist/cjs/core/batch.js +116 -0
  16. package/dist/cjs/core/callsite.d.ts +34 -0
  17. package/dist/cjs/core/callsite.js +115 -0
  18. package/dist/cjs/core/consent.d.ts +27 -0
  19. package/dist/cjs/core/consent.js +132 -0
  20. package/dist/cjs/core/constants.d.ts +237 -0
  21. package/dist/cjs/core/constants.js +315 -0
  22. package/dist/cjs/core/db.d.ts +48 -0
  23. package/dist/cjs/core/db.js +467 -0
  24. package/dist/cjs/core/debug.d.ts +22 -0
  25. package/dist/cjs/core/debug.js +88 -0
  26. package/dist/cjs/core/env.d.ts +28 -0
  27. package/dist/cjs/core/env.js +267 -0
  28. package/dist/cjs/core/framework-id.d.ts +1 -0
  29. package/dist/cjs/core/framework-id.js +9 -0
  30. package/dist/cjs/core/guard.d.ts +11 -0
  31. package/dist/cjs/core/guard.js +86 -0
  32. package/dist/cjs/core/hooks.d.ts +39 -0
  33. package/dist/cjs/core/hooks.js +22 -0
  34. package/dist/cjs/core/locks.d.ts +9 -0
  35. package/dist/cjs/core/locks.js +22 -0
  36. package/dist/cjs/core/logger.d.ts +15 -0
  37. package/dist/cjs/core/logger.js +50 -0
  38. package/dist/cjs/core/state.d.ts +70 -0
  39. package/dist/cjs/core/state.js +78 -0
  40. package/dist/cjs/core/storage.d.ts +61 -0
  41. package/dist/cjs/core/storage.js +327 -0
  42. package/dist/cjs/core/stylesheet.d.ts +8 -0
  43. package/dist/cjs/core/stylesheet.js +29 -0
  44. package/dist/cjs/core/transport.d.ts +85 -0
  45. package/dist/cjs/core/transport.js +456 -0
  46. package/dist/cjs/core/utils.d.ts +26 -0
  47. package/dist/cjs/core/utils.js +175 -0
  48. package/dist/cjs/core/validate.d.ts +18 -0
  49. package/dist/cjs/core/validate.js +233 -0
  50. package/dist/cjs/device/appversion.d.ts +15 -0
  51. package/dist/cjs/device/appversion.js +170 -0
  52. package/dist/cjs/device/index.d.ts +34 -0
  53. package/dist/cjs/device/index.js +472 -0
  54. package/dist/cjs/engagement/api-rules.d.ts +49 -0
  55. package/dist/cjs/engagement/api-rules.js +206 -0
  56. package/dist/cjs/engagement/auto-api.d.ts +7 -0
  57. package/dist/cjs/engagement/auto-api.js +200 -0
  58. package/dist/cjs/engagement/auto-screen.d.ts +18 -0
  59. package/dist/cjs/engagement/auto-screen.js +305 -0
  60. package/dist/cjs/engagement/defined-events.d.ts +23 -0
  61. package/dist/cjs/engagement/defined-events.js +58 -0
  62. package/dist/cjs/engagement/send.d.ts +6 -0
  63. package/dist/cjs/engagement/send.js +104 -0
  64. package/dist/cjs/engagement/session.d.ts +51 -0
  65. package/dist/cjs/engagement/session.js +463 -0
  66. package/dist/cjs/engagement/track.d.ts +56 -0
  67. package/dist/cjs/engagement/track.js +375 -0
  68. package/dist/cjs/errors/send.d.ts +6 -0
  69. package/dist/cjs/errors/send.js +73 -0
  70. package/dist/cjs/errors/track.d.ts +4 -0
  71. package/dist/cjs/errors/track.js +167 -0
  72. package/dist/cjs/feedback/controls.d.ts +37 -0
  73. package/dist/cjs/feedback/controls.js +316 -0
  74. package/dist/cjs/feedback/index.d.ts +9 -0
  75. package/dist/cjs/feedback/index.js +56 -0
  76. package/dist/cjs/feedback/logs.d.ts +45 -0
  77. package/dist/cjs/feedback/logs.js +241 -0
  78. package/dist/cjs/feedback/quartz.d.ts +18 -0
  79. package/dist/cjs/feedback/quartz.js +105 -0
  80. package/dist/cjs/feedback/send.d.ts +28 -0
  81. package/dist/cjs/feedback/send.js +203 -0
  82. package/dist/cjs/feedback/styles.d.ts +10 -0
  83. package/dist/cjs/feedback/styles.js +8 -0
  84. package/dist/cjs/feedback/template.d.ts +2 -0
  85. package/dist/cjs/feedback/template.js +162 -0
  86. package/dist/cjs/feedback/ui.d.ts +63 -0
  87. package/dist/cjs/feedback/ui.js +709 -0
  88. package/dist/cjs/heatmap/send.d.ts +13 -0
  89. package/dist/cjs/heatmap/send.js +82 -0
  90. package/dist/cjs/heatmap/track.d.ts +4 -0
  91. package/dist/cjs/heatmap/track.js +448 -0
  92. package/dist/cjs/index.d.ts +22 -0
  93. package/dist/cjs/index.js +162 -0
  94. package/dist/cjs/lifecycle.d.ts +21 -0
  95. package/dist/cjs/lifecycle.js +734 -0
  96. package/dist/cjs/package.json +3 -0
  97. package/dist/cjs/remoteconfig/country.d.ts +4 -0
  98. package/dist/cjs/remoteconfig/country.js +73 -0
  99. package/dist/cjs/remoteconfig/custom.d.ts +10 -0
  100. package/dist/cjs/remoteconfig/custom.js +58 -0
  101. package/dist/cjs/remoteconfig/evaluate.d.ts +24 -0
  102. package/dist/cjs/remoteconfig/evaluate.js +184 -0
  103. package/dist/cjs/remoteconfig/fetch.d.ts +24 -0
  104. package/dist/cjs/remoteconfig/fetch.js +200 -0
  105. package/dist/cjs/remoteconfig/index.d.ts +15 -0
  106. package/dist/cjs/remoteconfig/index.js +116 -0
  107. package/dist/cjs/remoteconfig/store.d.ts +18 -0
  108. package/dist/cjs/remoteconfig/store.js +98 -0
  109. package/dist/cjs/remoteconfig/tz-countries.d.ts +8 -0
  110. package/dist/cjs/remoteconfig/tz-countries.js +13 -0
  111. package/dist/cjs/remotelog/gate.d.ts +2 -0
  112. package/dist/cjs/remotelog/gate.js +28 -0
  113. package/dist/cjs/remotelog/index.d.ts +8 -0
  114. package/dist/cjs/remotelog/logger.d.ts +22 -0
  115. package/dist/cjs/remotelog/logger.js +111 -0
  116. package/dist/cjs/remotelog/send.d.ts +13 -0
  117. package/dist/cjs/remotelog/send.js +153 -0
  118. package/dist/cjs/remotelogger/index.d.ts +12 -0
  119. package/dist/cjs/remotelogger/index.js +18 -0
  120. package/dist/cjs/scheduler.d.ts +8 -0
  121. package/dist/cjs/scheduler.js +78 -0
  122. package/dist/cjs/types.d.ts +385 -0
  123. package/dist/cjs/user/index.d.ts +33 -0
  124. package/dist/cjs/user/index.js +183 -0
  125. package/dist/esm/auto-init.d.ts +8 -0
  126. package/dist/esm/auto-init.js +29 -0
  127. package/dist/esm/core/attempts.d.ts +28 -0
  128. package/dist/esm/core/attempts.js +106 -0
  129. package/dist/esm/core/batch.d.ts +32 -0
  130. package/dist/esm/core/batch.js +109 -0
  131. package/dist/esm/core/callsite.d.ts +34 -0
  132. package/dist/esm/core/callsite.js +110 -0
  133. package/dist/esm/core/consent.d.ts +27 -0
  134. package/dist/esm/core/consent.js +122 -0
  135. package/dist/esm/core/constants.d.ts +237 -0
  136. package/dist/esm/core/constants.js +292 -0
  137. package/dist/esm/core/db.d.ts +48 -0
  138. package/dist/esm/core/db.js +453 -0
  139. package/dist/esm/core/debug.d.ts +22 -0
  140. package/dist/esm/core/debug.js +81 -0
  141. package/dist/esm/core/env.d.ts +28 -0
  142. package/dist/esm/core/env.js +251 -0
  143. package/dist/esm/core/framework-id.d.ts +1 -0
  144. package/dist/esm/core/framework-id.js +7 -0
  145. package/dist/esm/core/guard.d.ts +11 -0
  146. package/dist/esm/core/guard.js +83 -0
  147. package/dist/esm/core/hooks.d.ts +39 -0
  148. package/dist/esm/core/hooks.js +20 -0
  149. package/dist/esm/core/locks.d.ts +9 -0
  150. package/dist/esm/core/locks.js +20 -0
  151. package/dist/esm/core/logger.d.ts +15 -0
  152. package/dist/esm/core/logger.js +46 -0
  153. package/dist/esm/core/state.d.ts +70 -0
  154. package/dist/esm/core/state.js +73 -0
  155. package/dist/esm/core/storage.d.ts +61 -0
  156. package/dist/esm/core/storage.js +314 -0
  157. package/dist/esm/core/stylesheet.d.ts +8 -0
  158. package/dist/esm/core/stylesheet.js +27 -0
  159. package/dist/esm/core/transport.d.ts +85 -0
  160. package/dist/esm/core/transport.js +439 -0
  161. package/dist/esm/core/utils.d.ts +26 -0
  162. package/dist/esm/core/utils.js +161 -0
  163. package/dist/esm/core/validate.d.ts +18 -0
  164. package/dist/esm/core/validate.js +226 -0
  165. package/dist/esm/device/appversion.d.ts +15 -0
  166. package/dist/esm/device/appversion.js +164 -0
  167. package/dist/esm/device/index.d.ts +34 -0
  168. package/dist/esm/device/index.js +461 -0
  169. package/dist/esm/engagement/api-rules.d.ts +49 -0
  170. package/dist/esm/engagement/api-rules.js +199 -0
  171. package/dist/esm/engagement/auto-api.d.ts +7 -0
  172. package/dist/esm/engagement/auto-api.js +198 -0
  173. package/dist/esm/engagement/auto-screen.d.ts +18 -0
  174. package/dist/esm/engagement/auto-screen.js +301 -0
  175. package/dist/esm/engagement/defined-events.d.ts +23 -0
  176. package/dist/esm/engagement/defined-events.js +55 -0
  177. package/dist/esm/engagement/send.d.ts +6 -0
  178. package/dist/esm/engagement/send.js +101 -0
  179. package/dist/esm/engagement/session.d.ts +51 -0
  180. package/dist/esm/engagement/session.js +448 -0
  181. package/dist/esm/engagement/track.d.ts +56 -0
  182. package/dist/esm/engagement/track.js +365 -0
  183. package/dist/esm/errors/send.d.ts +6 -0
  184. package/dist/esm/errors/send.js +70 -0
  185. package/dist/esm/errors/track.d.ts +4 -0
  186. package/dist/esm/errors/track.js +163 -0
  187. package/dist/esm/feedback/controls.d.ts +37 -0
  188. package/dist/esm/feedback/controls.js +309 -0
  189. package/dist/esm/feedback/index.d.ts +9 -0
  190. package/dist/esm/feedback/index.js +51 -0
  191. package/dist/esm/feedback/logs.d.ts +45 -0
  192. package/dist/esm/feedback/logs.js +227 -0
  193. package/dist/esm/feedback/quartz.d.ts +18 -0
  194. package/dist/esm/feedback/quartz.js +99 -0
  195. package/dist/esm/feedback/send.d.ts +28 -0
  196. package/dist/esm/feedback/send.js +198 -0
  197. package/dist/esm/feedback/styles.d.ts +10 -0
  198. package/dist/esm/feedback/styles.js +4 -0
  199. package/dist/esm/feedback/template.d.ts +2 -0
  200. package/dist/esm/feedback/template.js +159 -0
  201. package/dist/esm/feedback/ui.d.ts +63 -0
  202. package/dist/esm/feedback/ui.js +703 -0
  203. package/dist/esm/heatmap/send.d.ts +13 -0
  204. package/dist/esm/heatmap/send.js +79 -0
  205. package/dist/esm/heatmap/track.d.ts +4 -0
  206. package/dist/esm/heatmap/track.js +445 -0
  207. package/dist/esm/index.d.ts +22 -0
  208. package/dist/esm/index.js +150 -0
  209. package/dist/esm/lifecycle.d.ts +21 -0
  210. package/dist/esm/lifecycle.js +729 -0
  211. package/dist/esm/package.json +3 -0
  212. package/dist/esm/remoteconfig/country.d.ts +4 -0
  213. package/dist/esm/remoteconfig/country.js +70 -0
  214. package/dist/esm/remoteconfig/custom.d.ts +10 -0
  215. package/dist/esm/remoteconfig/custom.js +54 -0
  216. package/dist/esm/remoteconfig/evaluate.d.ts +24 -0
  217. package/dist/esm/remoteconfig/evaluate.js +179 -0
  218. package/dist/esm/remoteconfig/fetch.d.ts +24 -0
  219. package/dist/esm/remoteconfig/fetch.js +196 -0
  220. package/dist/esm/remoteconfig/index.d.ts +15 -0
  221. package/dist/esm/remoteconfig/index.js +111 -0
  222. package/dist/esm/remoteconfig/store.d.ts +18 -0
  223. package/dist/esm/remoteconfig/store.js +91 -0
  224. package/dist/esm/remoteconfig/tz-countries.d.ts +8 -0
  225. package/dist/esm/remoteconfig/tz-countries.js +11 -0
  226. package/dist/esm/remotelog/gate.d.ts +2 -0
  227. package/dist/esm/remotelog/gate.js +26 -0
  228. package/dist/esm/remotelog/index.d.ts +8 -0
  229. package/dist/esm/remotelog/logger.d.ts +22 -0
  230. package/dist/esm/remotelog/logger.js +108 -0
  231. package/dist/esm/remotelog/send.d.ts +13 -0
  232. package/dist/esm/remotelog/send.js +149 -0
  233. package/dist/esm/remotelogger/index.d.ts +12 -0
  234. package/dist/esm/remotelogger/index.js +13 -0
  235. package/dist/esm/scheduler.d.ts +8 -0
  236. package/dist/esm/scheduler.js +74 -0
  237. package/dist/esm/types.d.ts +385 -0
  238. package/dist/esm/user/index.d.ts +33 -0
  239. package/dist/esm/user/index.js +176 -0
  240. package/dist/feedback.esm.min.js +3 -0
  241. package/dist/feedback.esm.min.js.map +1 -0
  242. package/package.json +122 -7
  243. package/src/appticssdk.js +0 -1
@@ -0,0 +1,237 @@
1
+ /**
2
+ * A screen_routes entry as init() keeps it, ready to match: a route pattern, or an exact path or a
3
+ * regular expression with the name it records.
4
+ */
5
+ export type ScreenRouteRule = {
6
+ kind: 'pattern';
7
+ pattern: string;
8
+ } | {
9
+ kind: 'equals';
10
+ path: string;
11
+ name: string;
12
+ } | {
13
+ kind: 'regex';
14
+ regex: RegExp;
15
+ name: string;
16
+ };
17
+ export declare const AP_TRACKING_STATUS: Readonly<{
18
+ readonly USAGE_TRACKING_WITH_PII: 1;
19
+ readonly USAGE_TRACKING_WITHOUT_PII: 4;
20
+ readonly NO_TRACKING: -1;
21
+ }>;
22
+ export declare const AP_FEEDBACK_TYPE: Readonly<{
23
+ readonly BUG: 0;
24
+ readonly FEEDBACK: 1;
25
+ readonly HELP: 2;
26
+ readonly REPORT: 3;
27
+ }>;
28
+ export declare const AP_CONSTANTS: Readonly<{
29
+ readonly SCREEN: "screen";
30
+ readonly SESSION: "session";
31
+ readonly EVENT: "event";
32
+ readonly API: "api";
33
+ readonly ERROR: "error";
34
+ readonly SUCCESS: "success";
35
+ readonly BROWSER: "Browser";
36
+ }>;
37
+ export declare const DEFAULT_API_PATHS: Readonly<{
38
+ readonly addversion: "app/addversion";
39
+ readonly regdevice: "device/add";
40
+ readonly reguser: "user/register";
41
+ readonly engagement: "engagement/add";
42
+ readonly error: "exception/error";
43
+ readonly feedback: "feedback/add";
44
+ readonly sdkconfig: "getsdkconfig";
45
+ readonly getupdates: "getupdates";
46
+ readonly consolelog: "log/add";
47
+ readonly heatmap: "heatmap/add";
48
+ }>;
49
+ /**
50
+ * Which API version each path lives under.
51
+ *
52
+ * Every path the SDK calls is defined under v2 in the proxy's security-sdk.xml, and four of them —
53
+ * app/addversion, getsdkconfig, heatmap/add and log/add — are defined there *only* under v2: there
54
+ * is no v1 url for them to fall back to, so sending v1 reaches nothing. It stays a per-path map
55
+ * rather than one shared prefix because v1 urls do still exist for the other five, so a path can
56
+ * be moved back on its own if one of them turns out not to be ready.
57
+ */
58
+ export declare const API_VERSIONS: Readonly<Record<keyof typeof DEFAULT_API_PATHS, string>>;
59
+ /**
60
+ * The SDK subsystem a remote log line is about, as console/addlog's `module` param.
61
+ * These are the server's own names, so they are sent exactly as written here.
62
+ */
63
+ export declare const AP_LOG_MODULE: Readonly<{
64
+ readonly SESSION: "Session";
65
+ readonly SCREEN: "Screen";
66
+ readonly EVENT: "Event";
67
+ readonly API: "API";
68
+ readonly HEATMAP: "Heatmap";
69
+ readonly PROPERTIES: "Properties";
70
+ }>;
71
+ /**
72
+ * The modules getsdkconfig reports on, by the ids it keys them with. The SDK acts on the ones it
73
+ * has something to switch off; anything else the server sends is stored but unused.
74
+ */
75
+ export declare const SDK_MODULE: Readonly<{
76
+ /**
77
+ * Remote config. It is the one module both answers report on: getupdates names it in
78
+ * `moduleids` and reports its flag back, and getsdkconfig reports the same flag as the
79
+ * authority. Where they disagree, getsdkconfig wins.
80
+ */
81
+ readonly REMOTE_CONFIG: "2";
82
+ readonly SESSION: "11";
83
+ readonly FEEDBACK: "12";
84
+ readonly CRASH: "13";
85
+ readonly REMOTE_LOGGER: "17";
86
+ readonly HEATMAP: "18";
87
+ }>;
88
+ /** logSDK declares max-len="10000" on logmessage, so a line is trimmed to fit that. */
89
+ export declare const CONSOLE_LOG_MAX_BODY = 10000;
90
+ /** logSDK caps `function` at 100 characters. */
91
+ export declare const LOG_FUNCTION_MAX = 100;
92
+ /** logSDK caps `filename` at 100 too, which is why a call site carries a basename, not a url. */
93
+ export declare const LOG_FILENAME_MAX = 100;
94
+ /**
95
+ * How much of `devicename` is sent. The url declares no max-len, only safe_string, but this is a
96
+ * label a person reads in a list: anything longer is a paragraph, not a name.
97
+ */
98
+ export declare const DEVICE_NAME_MAX = 100;
99
+ /**
100
+ * The `level` every line goes out with. Everything the remote logger carries is a failure inside
101
+ * the SDK — logFailure is its only caller — so the level never varies. 3 is what the v2 reference
102
+ * shows in its only example; the scale itself is not documented anywhere we can see.
103
+ */
104
+ export declare const REMOTE_LOG_LEVEL = 3;
105
+ /**
106
+ * How long debug mode survives with nothing tracked, before switching itself off.
107
+ *
108
+ * An hour is long enough to cover reading a payload, changing the app and reloading, and short
109
+ * enough that a tab left open overnight is not still sending every call to its debug twin.
110
+ */
111
+ export declare const DEBUG_IDLE_MS: number;
112
+ /** Idle minutes that end a session. Lives on state, not in _config, but defaults here. */
113
+ export declare const DEFAULT_INACTIVE_MINUTES = 30;
114
+ /** Global defaults. `state._config` holds a mutable copy per init. */
115
+ export declare const AP_CONFIG: Readonly<{
116
+ endpoint: "/sdk/web/";
117
+ method: "POST";
118
+ transport: "XHR";
119
+ track_link_timeout: 300;
120
+ cookie_expiration_days: 365;
121
+ storage_type: "localStorage";
122
+ enable_batch_requests: true;
123
+ batch_size: 50;
124
+ batch_flush_interval: 30000;
125
+ getupdates_interval: 120000;
126
+ batch_request_timeout: 7;
127
+ auto_starts_batch: true;
128
+ mode: 1;
129
+ default_group_name: "default";
130
+ default_optin_status: number;
131
+ enable_pageview_tracking: false;
132
+ save_referrer: true;
133
+ debug: boolean;
134
+ track_by_default: true;
135
+ ignore_do_not_track: boolean;
136
+ /**
137
+ * Wrap XHR and fetch to record the app's API calls without it calling startTrackApi(). Off by
138
+ * default: the hostnames and paths of every request an app makes is a wider grant than events
139
+ * and screens, so the app opts in.
140
+ */
141
+ track_api: boolean;
142
+ /**
143
+ * Record a screen view for the first page and every navigation after it, from the url. On by
144
+ * default; the app's own inScreen() during a navigation replaces that navigation's view.
145
+ */
146
+ track_screen: boolean;
147
+ /**
148
+ * How automatic screen tracking names a path, as init() keeps the config's screen_routes: route
149
+ * patterns (`/users/{id}/orders`, each id recorded as a star), exact paths and regular
150
+ * expressions with a name. Tried in order; a path none matches keeps its own name.
151
+ */
152
+ screen_routes: ScreenRouteRule[];
153
+ /**
154
+ * The feedback form's theme: 'light', 'dark', or 'auto' to follow the visitor's system setting.
155
+ * 'auto' by default.
156
+ */
157
+ feedback_theme: "light" | "dark" | "auto";
158
+ /**
159
+ * How long a visit must last before its session is stored, in milliseconds. A shorter visit with
160
+ * nothing tracked in it is dropped: a bounce or a crawler is not a session. Anything tracked
161
+ * inside the window writes the session immediately, keeping its original start time. 0 disables
162
+ * the wait and stores every session as it starts.
163
+ */
164
+ min_session_duration: number;
165
+ /**
166
+ * Record where people click and how far they scroll, for the console's heatmaps. Off by default:
167
+ * coordinates and element labels are a wider grant than events and screens, so the app opts in.
168
+ */
169
+ track_heatmap: boolean;
170
+ /**
171
+ * Send engagement, exception and log payloads to their `debug/` twins, which answer with a
172
+ * request id and a link to the server's own logs for that request. For tracing a payload that
173
+ * is not showing up in the console; off in normal use, and it does not change what is sent.
174
+ */
175
+ debug_api: boolean;
176
+ /**
177
+ * What to call this device in the debug stream. Engagement, exception and log are the three
178
+ * urls that declare `devicename`, and it is what tells one tester's browser from another's
179
+ * when several are tracing the same build. Empty by default: it rides on every one of those
180
+ * calls, so an app that is not tracing should not pay for it. With `debug_api` on and nothing
181
+ * set here, a label is derived from the browser and OS instead, since an unnamed row in the
182
+ * debug stream is no use to whoever is reading it.
183
+ */
184
+ device_name: string;
185
+ /**
186
+ * Most heatmap records one visit may produce. Clicks are cheap, but a page that scrolls a lot
187
+ * can produce them faster than they are sent, and an unbounded queue is a memory leak on a tab
188
+ * left open for a day. Reached, capture stops for the rest of the session.
189
+ */
190
+ heatmap_max_per_session: number;
191
+ }>;
192
+ export type ApConfig = {
193
+ -readonly [K in keyof typeof AP_CONFIG]: (typeof AP_CONFIG)[K];
194
+ };
195
+ /**
196
+ * Config keys `init()` refuses to start without (after the snippet aliases are resolved).
197
+ *
198
+ * `appversion` is here rather than defaulted on purpose. Every error, every device registration
199
+ * and every uploaded source map is only meaningful against the build it came from, and a default
200
+ * would answer that question wrongly and silently for every app that forgot to set it.
201
+ */
202
+ /**
203
+ * What init() must be given. Everything else the SDK needs — aaid, the portal and project ids that
204
+ * go in every url — comes back from app/addversion, which these four are enough to call.
205
+ */
206
+ export declare const REQUIRED_CONFIG: readonly ["base_url", "auth_key", "app_domain", "appversion"];
207
+ /**
208
+ * The init() keys and the names the SDK keeps them under inside (and in app_version_info, which
209
+ * already-visited browsers have stored): base_url is the host, auth_key the `zak` header, and
210
+ * app_domain the app's identifier.
211
+ */
212
+ export declare const CONFIG_KEYS: Readonly<Record<string, string>>;
213
+ /**
214
+ * Paths with a `debug/` twin. The debug endpoints take the same body and answer with a request id
215
+ * and a link to the server-side logs for that request, which is how a payload is traced end to
216
+ * end when the console does not show what was expected.
217
+ */
218
+ export declare const DEBUG_CAPABLE_PATHS: Readonly<Record<string, boolean>>;
219
+ /**
220
+ * Paths that declare `attempt`, `firstattempttime` and `lst`.
221
+ *
222
+ * Every url that carries data declares all three. app/addversion and getsdkconfig declare none:
223
+ * they are start-up calls whose answers the SDK needs, not payloads it is pushing, and sending
224
+ * an undeclared param is refused outright as EXTRA_PARAM_FOUND.
225
+ */
226
+ export declare const RETRY_CAPABLE_PATHS: Readonly<Record<string, boolean>>;
227
+ /**
228
+ * Paths that live directly under the version, with no org and project segments. app/addversion is
229
+ * called before those ids are known, so it cannot carry them.
230
+ */
231
+ export declare const PATHS_WITHOUT_ORG: Readonly<Record<string, boolean>>;
232
+ /**
233
+ * Earlier names of the init() keys: 2.0.0-beta's serviceUrl, zak and identifier, and the 1.x
234
+ * console snippet's base_domain and token. Still read, with a warning naming the key to use.
235
+ */
236
+ export declare const RETIRED_CONFIG_NAMES: Readonly<Record<string, string>>;
237
+ export declare const BLOCKED_WS: readonly string[];
@@ -0,0 +1,315 @@
1
+ /*! @zoho_apptics/apptics-js-sdk v2.0.0-beta.1 | (c) Zoho Corporation Private Limited | see LICENSE */
2
+ 'use strict';
3
+
4
+ const AP_TRACKING_STATUS = Object.freeze({
5
+ USAGE_TRACKING_WITH_PII: 1,
6
+ USAGE_TRACKING_WITHOUT_PII: 4,
7
+ NO_TRACKING: -1,
8
+ });
9
+ const AP_FEEDBACK_TYPE = Object.freeze({
10
+ BUG: 0,
11
+ FEEDBACK: 1,
12
+ HELP: 2,
13
+ REPORT: 3,
14
+ });
15
+ const AP_CONSTANTS = Object.freeze({
16
+ SCREEN: 'screen', // no i18n
17
+ SESSION: 'session', // no i18n
18
+ EVENT: 'event', // no i18n
19
+ API: 'api', // no i18n
20
+ ERROR: 'error', // no i18n
21
+ SUCCESS: 'success', // no i18n
22
+ BROWSER: 'Browser', // no i18n
23
+ });
24
+ const DEFAULT_API_PATHS = Object.freeze({
25
+ // the first call: registers the build and answers with the ids every later call needs
26
+ addversion: 'app/addversion', // no i18n
27
+ regdevice: 'device/add', // no i18n
28
+ reguser: 'user/register', // no i18n
29
+ engagement: 'engagement/add', // no i18n
30
+ // the exception group is part of the path, and the proxy matches it with [a-z]+ — no
31
+ // underscore, so js_error cannot route. 'error' is in the accepted set and is what we send
32
+ error: 'exception/error', // no i18n
33
+ feedback: 'feedback/add', // no i18n
34
+ // the source of truth for which modules are on. v2 replaced the old getupdates answer: it is
35
+ // per-module flags keyed by id now, not loose booleans
36
+ sdkconfig: 'getsdkconfig', // no i18n
37
+ // still its own endpoint, and not a synonym for the one above: it takes a body naming the
38
+ // modules being asked about, and answers with their payloads - remote config among them
39
+ getupdates: 'getupdates', // no i18n
40
+ // v2 replaced console/addlog: one call now carries a batch of lines, not one line
41
+ consolelog: 'log/add', // no i18n
42
+ heatmap: 'heatmap/add', // no i18n
43
+ });
44
+ /**
45
+ * Which API version each path lives under.
46
+ *
47
+ * Every path the SDK calls is defined under v2 in the proxy's security-sdk.xml, and four of them —
48
+ * app/addversion, getsdkconfig, heatmap/add and log/add — are defined there *only* under v2: there
49
+ * is no v1 url for them to fall back to, so sending v1 reaches nothing. It stays a per-path map
50
+ * rather than one shared prefix because v1 urls do still exist for the other five, so a path can
51
+ * be moved back on its own if one of them turns out not to be ready.
52
+ */
53
+ const API_VERSIONS = Object.freeze({
54
+ addversion: 'v2', // no i18n
55
+ regdevice: 'v2', // no i18n
56
+ engagement: 'v2', // no i18n
57
+ error: 'v2', // no i18n
58
+ reguser: 'v2', // no i18n
59
+ feedback: 'v2', // no i18n
60
+ sdkconfig: 'v2', // no i18n
61
+ getupdates: 'v2', // no i18n
62
+ consolelog: 'v2', // no i18n
63
+ heatmap: 'v2', // no i18n
64
+ });
65
+ /**
66
+ * The SDK subsystem a remote log line is about, as console/addlog's `module` param.
67
+ * These are the server's own names, so they are sent exactly as written here.
68
+ */
69
+ const AP_LOG_MODULE = Object.freeze({
70
+ SESSION: 'Session', // no i18n
71
+ SCREEN: 'Screen', // no i18n
72
+ EVENT: 'Event', // no i18n
73
+ API: 'API', // no i18n
74
+ HEATMAP: 'Heatmap', // no i18n
75
+ PROPERTIES: 'Properties', // no i18n
76
+ });
77
+ /**
78
+ * The modules getsdkconfig reports on, by the ids it keys them with. The SDK acts on the ones it
79
+ * has something to switch off; anything else the server sends is stored but unused.
80
+ */
81
+ const SDK_MODULE = Object.freeze({
82
+ /**
83
+ * Remote config. It is the one module both answers report on: getupdates names it in
84
+ * `moduleids` and reports its flag back, and getsdkconfig reports the same flag as the
85
+ * authority. Where they disagree, getsdkconfig wins.
86
+ */
87
+ REMOTE_CONFIG: '2', // no i18n
88
+ SESSION: '11', // no i18n
89
+ FEEDBACK: '12', // no i18n
90
+ CRASH: '13', // no i18n
91
+ REMOTE_LOGGER: '17', // no i18n
92
+ HEATMAP: '18', // no i18n
93
+ });
94
+ /** logSDK declares max-len="10000" on logmessage, so a line is trimmed to fit that. */
95
+ const CONSOLE_LOG_MAX_BODY = 10000;
96
+ /** logSDK caps `function` at 100 characters. */
97
+ const LOG_FUNCTION_MAX = 100;
98
+ /** logSDK caps `filename` at 100 too, which is why a call site carries a basename, not a url. */
99
+ const LOG_FILENAME_MAX = 100;
100
+ /**
101
+ * How much of `devicename` is sent. The url declares no max-len, only safe_string, but this is a
102
+ * label a person reads in a list: anything longer is a paragraph, not a name.
103
+ */
104
+ const DEVICE_NAME_MAX = 100;
105
+ /**
106
+ * The `level` every line goes out with. Everything the remote logger carries is a failure inside
107
+ * the SDK — logFailure is its only caller — so the level never varies. 3 is what the v2 reference
108
+ * shows in its only example; the scale itself is not documented anywhere we can see.
109
+ */
110
+ const REMOTE_LOG_LEVEL = 3;
111
+ /**
112
+ * How long debug mode survives with nothing tracked, before switching itself off.
113
+ *
114
+ * An hour is long enough to cover reading a payload, changing the app and reloading, and short
115
+ * enough that a tab left open overnight is not still sending every call to its debug twin.
116
+ */
117
+ const DEBUG_IDLE_MS = 60 * 60 * 1000;
118
+ /** Idle minutes that end a session. Lives on state, not in _config, but defaults here. */
119
+ const DEFAULT_INACTIVE_MINUTES = 30;
120
+ /** Global defaults. `state._config` holds a mutable copy per init. */
121
+ const AP_CONFIG = Object.freeze({
122
+ // the version is per path (API_VERSIONS); this is only the part before it
123
+ endpoint: '/sdk/web/', // no i18n
124
+ method: 'POST', // no i18n
125
+ transport: 'XHR', // no i18n
126
+ track_link_timeout: 300,
127
+ cookie_expiration_days: 365,
128
+ storage_type: 'localStorage', // no i18n
129
+ enable_batch_requests: true,
130
+ batch_size: 50,
131
+ batch_flush_interval: 30000,
132
+ getupdates_interval: 120000, // 2 minutes in milliseconds
133
+ batch_request_timeout: 7,
134
+ auto_starts_batch: true,
135
+ mode: 1,
136
+ default_group_name: 'default', // no i18n
137
+ default_optin_status: AP_TRACKING_STATUS.USAGE_TRACKING_WITHOUT_PII,
138
+ enable_pageview_tracking: false,
139
+ save_referrer: true,
140
+ debug: false,
141
+ track_by_default: true,
142
+ ignore_do_not_track: false,
143
+ /**
144
+ * Wrap XHR and fetch to record the app's API calls without it calling startTrackApi(). Off by
145
+ * default: the hostnames and paths of every request an app makes is a wider grant than events
146
+ * and screens, so the app opts in.
147
+ */
148
+ track_api: false,
149
+ /**
150
+ * Record a screen view for the first page and every navigation after it, from the url. On by
151
+ * default; the app's own inScreen() during a navigation replaces that navigation's view.
152
+ */
153
+ track_screen: true,
154
+ /**
155
+ * How automatic screen tracking names a path, as init() keeps the config's screen_routes: route
156
+ * patterns (`/users/{id}/orders`, each id recorded as a star), exact paths and regular
157
+ * expressions with a name. Tried in order; a path none matches keeps its own name.
158
+ */
159
+ screen_routes: [],
160
+ /**
161
+ * The feedback form's theme: 'light', 'dark', or 'auto' to follow the visitor's system setting.
162
+ * 'auto' by default.
163
+ */
164
+ feedback_theme: 'auto',
165
+ /**
166
+ * How long a visit must last before its session is stored, in milliseconds. A shorter visit with
167
+ * nothing tracked in it is dropped: a bounce or a crawler is not a session. Anything tracked
168
+ * inside the window writes the session immediately, keeping its original start time. 0 disables
169
+ * the wait and stores every session as it starts.
170
+ */
171
+ min_session_duration: 5000,
172
+ /**
173
+ * Record where people click and how far they scroll, for the console's heatmaps. Off by default:
174
+ * coordinates and element labels are a wider grant than events and screens, so the app opts in.
175
+ */
176
+ track_heatmap: false,
177
+ /**
178
+ * Send engagement, exception and log payloads to their `debug/` twins, which answer with a
179
+ * request id and a link to the server's own logs for that request. For tracing a payload that
180
+ * is not showing up in the console; off in normal use, and it does not change what is sent.
181
+ */
182
+ debug_api: false,
183
+ /**
184
+ * What to call this device in the debug stream. Engagement, exception and log are the three
185
+ * urls that declare `devicename`, and it is what tells one tester's browser from another's
186
+ * when several are tracing the same build. Empty by default: it rides on every one of those
187
+ * calls, so an app that is not tracing should not pay for it. With `debug_api` on and nothing
188
+ * set here, a label is derived from the browser and OS instead, since an unnamed row in the
189
+ * debug stream is no use to whoever is reading it.
190
+ */
191
+ device_name: '',
192
+ /**
193
+ * Most heatmap records one visit may produce. Clicks are cheap, but a page that scrolls a lot
194
+ * can produce them faster than they are sent, and an unbounded queue is a memory leak on a tab
195
+ * left open for a day. Reached, capture stops for the rest of the session.
196
+ */
197
+ heatmap_max_per_session: 500,
198
+ });
199
+ /**
200
+ * Config keys `init()` refuses to start without (after the snippet aliases are resolved).
201
+ *
202
+ * `appversion` is here rather than defaulted on purpose. Every error, every device registration
203
+ * and every uploaded source map is only meaningful against the build it came from, and a default
204
+ * would answer that question wrongly and silently for every app that forgot to set it.
205
+ */
206
+ /**
207
+ * What init() must be given. Everything else the SDK needs — aaid, the portal and project ids that
208
+ * go in every url — comes back from app/addversion, which these four are enough to call.
209
+ */
210
+ const REQUIRED_CONFIG = Object.freeze(['base_url', 'auth_key', 'app_domain', 'appversion']); // no i18n
211
+ /**
212
+ * The init() keys and the names the SDK keeps them under inside (and in app_version_info, which
213
+ * already-visited browsers have stored): base_url is the host, auth_key the `zak` header, and
214
+ * app_domain the app's identifier.
215
+ */
216
+ const CONFIG_KEYS = Object.freeze({
217
+ base_url: 'serviceUrl', // no i18n
218
+ auth_key: 'zak', // no i18n
219
+ app_domain: 'identifier', // no i18n
220
+ });
221
+ /**
222
+ * Paths with a `debug/` twin. The debug endpoints take the same body and answer with a request id
223
+ * and a link to the server-side logs for that request, which is how a payload is traced end to
224
+ * end when the console does not show what was expected.
225
+ */
226
+ const DEBUG_CAPABLE_PATHS = Object.freeze({
227
+ engagement: true, // no i18n
228
+ error: true, // no i18n
229
+ consolelog: true, // no i18n
230
+ });
231
+ /**
232
+ * Paths that declare `attempt`, `firstattempttime` and `lst`.
233
+ *
234
+ * Every url that carries data declares all three. app/addversion and getsdkconfig declare none:
235
+ * they are start-up calls whose answers the SDK needs, not payloads it is pushing, and sending
236
+ * an undeclared param is refused outright as EXTRA_PARAM_FOUND.
237
+ */
238
+ const RETRY_CAPABLE_PATHS = Object.freeze({
239
+ regdevice: true, // no i18n
240
+ reguser: true, // no i18n
241
+ engagement: true, // no i18n
242
+ error: true, // no i18n
243
+ heatmap: true, // no i18n
244
+ consolelog: true, // no i18n
245
+ feedback: true, // no i18n
246
+ getupdates: true, // no i18n
247
+ });
248
+ /**
249
+ * Paths that live directly under the version, with no org and project segments. app/addversion is
250
+ * called before those ids are known, so it cannot carry them.
251
+ */
252
+ const PATHS_WITHOUT_ORG = Object.freeze({
253
+ addversion: true, // no i18n
254
+ });
255
+ /**
256
+ * Earlier names of the init() keys: 2.0.0-beta's serviceUrl, zak and identifier, and the 1.x
257
+ * console snippet's base_domain and token. Still read, with a warning naming the key to use.
258
+ */
259
+ const RETIRED_CONFIG_NAMES = Object.freeze({
260
+ serviceUrl: 'base_url', // no i18n
261
+ base_domain: 'base_url', // no i18n
262
+ zak: 'auth_key', // no i18n
263
+ token: 'auth_key', // no i18n
264
+ identifier: 'app_domain', // no i18n
265
+ });
266
+ // crawlers reference
267
+ // https://developers.google.com/search/docs/advanced/crawling/overview-google-crawlers
268
+ const BLOCKED_WS = Object.freeze([
269
+ 'ahrefsbot', // no i18n
270
+ 'ahrefssiteaudit', // no i18n
271
+ 'baiduspider', // no i18n
272
+ 'bingbot', // no i18n
273
+ 'bingpreview', // no i18n
274
+ 'chrome-lighthouse', // no i18n
275
+ 'facebookexternal', // no i18n
276
+ 'petalbot', // no i18n
277
+ 'pinterest', // no i18n
278
+ 'screaming frog', // no i18n
279
+ 'yahoo! slurp', // no i18n
280
+ 'yandexbot', // no i18n
281
+ 'adsbot-google', // no i18n
282
+ 'apis-google', // no i18n
283
+ 'duplexweb-google', // no i18n
284
+ 'feedfetcher-google', // no i18n
285
+ 'google favicon', // no i18n
286
+ 'google web preview', // no i18n
287
+ 'google-read-aloud', // no i18n
288
+ 'googlebot', // no i18n
289
+ 'googleweblight', // no i18n
290
+ 'mediapartners-google', // no i18n
291
+ 'storebot-google', // no i18n
292
+ ]);
293
+
294
+ exports.API_VERSIONS = API_VERSIONS;
295
+ exports.AP_CONFIG = AP_CONFIG;
296
+ exports.AP_CONSTANTS = AP_CONSTANTS;
297
+ exports.AP_FEEDBACK_TYPE = AP_FEEDBACK_TYPE;
298
+ exports.AP_LOG_MODULE = AP_LOG_MODULE;
299
+ exports.AP_TRACKING_STATUS = AP_TRACKING_STATUS;
300
+ exports.BLOCKED_WS = BLOCKED_WS;
301
+ exports.CONFIG_KEYS = CONFIG_KEYS;
302
+ exports.CONSOLE_LOG_MAX_BODY = CONSOLE_LOG_MAX_BODY;
303
+ exports.DEBUG_CAPABLE_PATHS = DEBUG_CAPABLE_PATHS;
304
+ exports.DEBUG_IDLE_MS = DEBUG_IDLE_MS;
305
+ exports.DEFAULT_API_PATHS = DEFAULT_API_PATHS;
306
+ exports.DEFAULT_INACTIVE_MINUTES = DEFAULT_INACTIVE_MINUTES;
307
+ exports.DEVICE_NAME_MAX = DEVICE_NAME_MAX;
308
+ exports.LOG_FILENAME_MAX = LOG_FILENAME_MAX;
309
+ exports.LOG_FUNCTION_MAX = LOG_FUNCTION_MAX;
310
+ exports.PATHS_WITHOUT_ORG = PATHS_WITHOUT_ORG;
311
+ exports.REMOTE_LOG_LEVEL = REMOTE_LOG_LEVEL;
312
+ exports.REQUIRED_CONFIG = REQUIRED_CONFIG;
313
+ exports.RETIRED_CONFIG_NAMES = RETIRED_CONFIG_NAMES;
314
+ exports.RETRY_CAPABLE_PATHS = RETRY_CAPABLE_PATHS;
315
+ exports.SDK_MODULE = SDK_MODULE;
@@ -0,0 +1,48 @@
1
+ import type { Dict, QueueItem } from '../types.js';
2
+ export type QueueName = 'engagements' | 'errors' | 'feedbacklogs' | 'remotelogs' | 'heatmaps';
3
+ /** One storage implementation. storage.ts talks only to this interface. */
4
+ export interface Backend {
5
+ readonly kind: 'indexeddb' | 'localstorage';
6
+ loadSettings(): Promise<Dict>;
7
+ putSetting(key: string, value: unknown): Promise<void>;
8
+ /** Removes the key itself, so it is no longer in storage at all. */
9
+ deleteSetting(key: string): Promise<void>;
10
+ clearSettings(): Promise<void>;
11
+ /** Items in insertion order. */
12
+ queueAll(store: QueueName): Promise<QueueItem[]>;
13
+ /** Adds items, or replaces the item with the same id (keeping its position). */
14
+ queuePut(store: QueueName, items: QueueItem[]): Promise<void>;
15
+ queueDelete(store: QueueName, ids: string[]): Promise<void>;
16
+ queueClear(store: QueueName): Promise<void>;
17
+ /** One-transaction import of 1.x data; existing settings and items win. IndexedDB only. */
18
+ importAll?(settings: Dict, queues: Record<QueueName, QueueItem[]>): Promise<void>;
19
+ }
20
+ export declare const DB_NAME = "apptics";
21
+ export declare const DB_VERSION = 4;
22
+ /** The types a feedback entry is stored under: an addFeedbackLog() line, an addDiagnosticsInfo() entry. */
23
+ export declare const FEEDBACK_LOG = "feedbacklog";
24
+ export declare const FEEDBACK_DIAGNOSTICS = "feedbackdiagnostics";
25
+ /** A feedback entry from 1.x or 2.0.0-beta, with the type it is stored under now. */
26
+ export declare function renameFeedbackType(item: QueueItem): QueueItem;
27
+ /** 1.x localStorage keys, read once to bring 1.x data into IndexedDB (see migrateLegacy). */
28
+ export declare const LEGACY_KEYS: Readonly<{
29
+ readonly settings: "apptics-device-info";
30
+ readonly engagements: "apptics-engagements-transactions";
31
+ readonly errors: "apptics-errors-transactions";
32
+ readonly logs: "apptics-log-transactions";
33
+ readonly consolelogs: "apptics-consolelog-transactions";
34
+ }>;
35
+ /** The localStorage backend's layout, for a browser where IndexedDB will not open. */
36
+ export declare const LOCAL_KEYS: Readonly<Record<'settings' | QueueName, string>>;
37
+ /** Shape guards shared by both backends and the 1.x migration. */
38
+ export declare function asList(value: unknown): QueueItem[];
39
+ export declare function asDict(value: unknown): Dict;
40
+ export declare function createLocalStorageBackend(): Backend;
41
+ /**
42
+ * Opens the database, and repairs it once if something else created an "apptics" database
43
+ * without our stores (then onupgradeneeded never fires and every read would fail).
44
+ */
45
+ export declare function openIndexedDB(factory?: IDBFactory, timeoutMs?: number): Promise<IDBDatabase>;
46
+ export declare function createIndexedDBBackend(db: IDBDatabase): Backend;
47
+ /** IndexedDB when it opens, otherwise localStorage, otherwise null. Never rejects. */
48
+ export declare function openBackend(): Promise<Backend | null>;