@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,286 @@
1
+ /*! @zoho_apptics/apptics-js-sdk v2.0.0-beta | (c) Zoho Corporation Private Limited | see LICENSE */
2
+ 'use strict';
3
+
4
+ var logger = require('../core/logger.js');
5
+ var hooks = require('../core/hooks.js');
6
+ var storage = require('../core/storage.js');
7
+ var utils = require('../core/utils.js');
8
+ var logs = require('./logs.js');
9
+
10
+ /**
11
+ * The three controls at the top and bottom of the feedback form: the user picker, the
12
+ * log/diagnostics toggles with their data viewer, and dragging the dialog by its header.
13
+ *
14
+ * They live here rather than in ui.ts so that init() stays about assembling the modal, and each
15
+ * control can be wired (and read back) on its own.
16
+ */
17
+ const ANONYMOUS = 'anonymous'; // no i18n
18
+ const ANONYMOUS_LABEL = 'Anonymous'; // no i18n
19
+ /** Read by core/transport when it builds the feedback request's parameters. */
20
+ const userChoice = { anonymous: true, userid: '', groupid: '' }; // no i18n
21
+ /** Whether the next submission carries the stored logs and diagnostics. Unset means "decide from what is stored". */
22
+ const logChoice = {};
23
+ function resetUserChoice() {
24
+ userChoice.anonymous = true;
25
+ userChoice.userid = ''; // no i18n
26
+ userChoice.groupid = ''; // no i18n
27
+ }
28
+ /** Every distinct registered user, by the address the picker shows. */
29
+ function storedUsers() {
30
+ var users = storage.user_defaults.item('users'); // no i18n
31
+ return Array.isArray(users) ? users : [];
32
+ }
33
+ function pickerItems(users) {
34
+ var items = [{ value: ANONYMOUS, label: ANONYMOUS_LABEL }];
35
+ var seen = {};
36
+ users.forEach(function (user) {
37
+ var mam = user && user.mam;
38
+ if (!utils.isEmpty(mam) && !seen[mam]) {
39
+ seen[mam] = true;
40
+ items.push({ value: String(mam), label: String(mam) });
41
+ }
42
+ });
43
+ return items;
44
+ }
45
+ const SVG_NS = 'http://www.w3.org/2000/svg'; // no i18n
46
+ /** The tick beside the picked option. */
47
+ function tickIcon() {
48
+ var svg = document.createElementNS(SVG_NS, 'svg'); // no i18n
49
+ svg.setAttribute('viewBox', '0 0 14 10'); // no i18n
50
+ svg.setAttribute('width', '14'); // no i18n
51
+ svg.setAttribute('height', '10'); // no i18n
52
+ svg.setAttribute('fill', 'none'); // no i18n
53
+ var path = document.createElementNS(SVG_NS, 'path'); // no i18n
54
+ path.setAttribute('d', 'M1 5l4 4 8-8'); // no i18n
55
+ path.setAttribute('stroke', '#0078d4'); // no i18n
56
+ path.setAttribute('stroke-width', '2'); // no i18n
57
+ path.setAttribute('stroke-linecap', 'round'); // no i18n
58
+ path.setAttribute('stroke-linejoin', 'round'); // no i18n
59
+ svg.appendChild(path);
60
+ return svg;
61
+ }
62
+ /**
63
+ * The "User" dropdown above the description. It lists Anonymous plus every registered user, and
64
+ * starts on the active one (status 1) unless the caller asked for anonymous.
65
+ */
66
+ function wireUserPicker(modal, forceAnonymous) {
67
+ var trigger = modal.querySelector('#zasdkEmailTrigger'); // no i18n
68
+ var panel = modal.querySelector('#zasdkEmailPanel'); // no i18n
69
+ var label = modal.querySelector('#zasdkEmailLabel'); // no i18n
70
+ var list = modal.querySelector('#zasdkEmailList'); // no i18n
71
+ var dropdown = modal.querySelector('#zasdkEmailDropdown'); // no i18n
72
+ if (!trigger || !panel || !label || !list || !dropdown) {
73
+ return;
74
+ }
75
+ var users = storedUsers();
76
+ var items = pickerItems(users);
77
+ var selected = ANONYMOUS;
78
+ resetUserChoice();
79
+ if (!forceAnonymous) {
80
+ var active = null;
81
+ users.forEach(function (user) {
82
+ if (!active && user && user.status == 1 && !utils.isEmpty(user.mam)) {
83
+ active = user;
84
+ }
85
+ });
86
+ if (active) {
87
+ select(String(active.mam));
88
+ }
89
+ }
90
+ function select(value) {
91
+ selected = value;
92
+ userChoice.anonymous = value === ANONYMOUS;
93
+ var matched = null;
94
+ if (!userChoice.anonymous) {
95
+ users.forEach(function (user) {
96
+ if (!matched && user && user.mam === value) {
97
+ matched = user;
98
+ }
99
+ });
100
+ }
101
+ userChoice.userid = matched ? String(matched.userid || '') : ''; // no i18n
102
+ userChoice.groupid = matched ? String(matched.groupid || '') : ''; // no i18n
103
+ label.textContent = userChoice.anonymous ? ANONYMOUS_LABEL : value;
104
+ render();
105
+ }
106
+ function render() {
107
+ list.innerHTML = ''; // no i18n
108
+ if (items.length === 0) {
109
+ var empty = document.createElement('div'); // no i18n
110
+ empty.className = 'zasdk-select-empty'; // no i18n
111
+ empty.textContent = 'No users to choose from'; // no i18n
112
+ list.appendChild(empty);
113
+ return;
114
+ }
115
+ items.forEach(function (item) {
116
+ var isSelected = item.value === selected;
117
+ var option = document.createElement('li'); // no i18n
118
+ option.className = 'zasdk-select-option' + (isSelected ? ' zasdk-option-selected' : ''); // no i18n
119
+ option.setAttribute('data-value', item.value); // no i18n
120
+ var text = document.createElement('span'); // no i18n
121
+ text.textContent = item.label;
122
+ option.appendChild(text);
123
+ if (isSelected) {
124
+ option.appendChild(tickIcon());
125
+ }
126
+ list.appendChild(option);
127
+ });
128
+ }
129
+ trigger.addEventListener('click', function (event) {
130
+ event.stopPropagation();
131
+ var open = panel.style.display !== 'none'; // no i18n
132
+ panel.style.display = open ? 'none' : 'block'; // no i18n
133
+ if (!open) {
134
+ render();
135
+ }
136
+ });
137
+ list.addEventListener('click', function (event) {
138
+ var option = event.target.closest('.zasdk-select-option'); // no i18n
139
+ if (!option) {
140
+ return;
141
+ }
142
+ select(String(option.getAttribute('data-value'))); // no i18n
143
+ panel.style.display = 'none'; // no i18n
144
+ });
145
+ // closing on focusout rather than a document click keeps it working inside a shadow root
146
+ dropdown.setAttribute('tabindex', '0'); // no i18n
147
+ dropdown.addEventListener('focusout', function (event) {
148
+ if (!dropdown.contains(event.relatedTarget)) {
149
+ panel.style.display = 'none'; // no i18n
150
+ }
151
+ });
152
+ render();
153
+ }
154
+ /** Shows `content` in the viewer panel over the form. */
155
+ function openViewer(modal, title, content) {
156
+ var viewer = modal.querySelector('#zasdkDataViewer'); // no i18n
157
+ var viewerTitle = modal.querySelector('#zasdkViewerTitle'); // no i18n
158
+ var viewerContent = modal.querySelector('#zasdkViewerContent'); // no i18n
159
+ if (!viewer || !viewerTitle || !viewerContent) {
160
+ return;
161
+ }
162
+ viewerTitle.textContent = title;
163
+ viewerContent.textContent = content || '(No data available)'; // no i18n
164
+ viewer.style.display = 'flex'; // no i18n
165
+ }
166
+ /**
167
+ * The two "Include …" switches and the viewer behind their View links. A row is shown only when
168
+ * there is something to include, and is then on by default, so a submission carries what the app
169
+ * recorded unless the user turns it off.
170
+ */
171
+ function wireLogControls(modal, opts) {
172
+ var logToggle = modal.querySelector('#zasdkIncludeLogToggle'); // no i18n
173
+ var diagToggle = modal.querySelector('#zasdkIncludeDiagToggle'); // no i18n
174
+ var section = modal.querySelector('.zasdk-toggles-section'); // no i18n
175
+ var separator = modal.querySelector('.zasdk-toggle-separator'); // no i18n
176
+ var viewLogs = modal.querySelector('#zasdkViewLogsBtn'); // no i18n
177
+ var viewDiag = modal.querySelector('#zasdkViewDiagBtn'); // no i18n
178
+ var viewerClose = modal.querySelector('#zasdkViewerClose'); // no i18n
179
+ var viewer = modal.querySelector('#zasdkDataViewer'); // no i18n
180
+ if (!logToggle || !diagToggle || !section) {
181
+ return;
182
+ }
183
+ var logRow = logToggle.closest('.zasdk-toggle-row'); // no i18n
184
+ var diagRow = diagToggle.closest('.zasdk-toggle-row'); // no i18n
185
+ logChoice.includeLog = opts.includeLog === true ? true : undefined;
186
+ logChoice.includeDyninfo = opts.includeDyninfo === true ? true : undefined;
187
+ // hidden until the reads come back, so an empty section never flashes into view
188
+ section.style.display = 'none'; // no i18n
189
+ Promise.all([logs.hasLogLines(), logs.hasDiagnostics()]).then(function ([anyLogs, anyDiagnostics]) {
190
+ if (logRow)
191
+ logRow.style.display = anyLogs ? '' : 'none'; // no i18n
192
+ if (diagRow)
193
+ diagRow.style.display = anyDiagnostics ? '' : 'none'; // no i18n
194
+ if (separator)
195
+ separator.style.display = anyLogs && anyDiagnostics ? '' : 'none'; // no i18n
196
+ section.style.display = anyLogs || anyDiagnostics ? '' : 'none'; // no i18n
197
+ // on when there is data, unless the caller already decided
198
+ logToggle.checked = opts.includeLog === true || anyLogs;
199
+ diagToggle.checked = opts.includeDyninfo === true || anyDiagnostics;
200
+ logChoice.includeLog = logToggle.checked;
201
+ logChoice.includeDyninfo = diagToggle.checked;
202
+ }).catch(function (err) {
203
+ logger.Console.warn('apptics: could not read the stored logs: ' + String(err)); // no i18n
204
+ });
205
+ logToggle.addEventListener('change', function () {
206
+ logChoice.includeLog = logToggle.checked;
207
+ });
208
+ diagToggle.addEventListener('change', function () {
209
+ logChoice.includeDyninfo = diagToggle.checked;
210
+ });
211
+ if (viewLogs) {
212
+ viewLogs.addEventListener('click', function () {
213
+ logs.logText().then(function (text) {
214
+ openViewer(modal, 'System Logs', text); // no i18n
215
+ });
216
+ });
217
+ }
218
+ if (viewDiag) {
219
+ viewDiag.addEventListener('click', function () {
220
+ logs.diagnosticsText().then(function (text) {
221
+ openViewer(modal, 'Diagnostic Information', text); // no i18n
222
+ });
223
+ });
224
+ }
225
+ if (viewerClose && viewer) {
226
+ viewerClose.addEventListener('click', function () {
227
+ viewer.style.display = 'none'; // no i18n
228
+ });
229
+ }
230
+ }
231
+ /**
232
+ * Drags the dialog by its header. The right/bottom placement from the stylesheet is converted to
233
+ * an explicit left/top on the first drag, so the offsets have something to add to, and the box is
234
+ * kept inside the viewport.
235
+ */
236
+ function wireDrag(box) {
237
+ var header = box.querySelector('.zasdk-header'); // no i18n
238
+ if (!header) {
239
+ return;
240
+ }
241
+ var startX = 0, startY = 0, boxLeft = 0, boxTop = 0, dragging = false;
242
+ header.addEventListener('mousedown', function (event) {
243
+ if (event.target.closest('.zasdk-close')) { // no i18n
244
+ return; // the close button is not a drag handle
245
+ }
246
+ if (!box.style.left || box.style.left === 'auto') { // no i18n
247
+ var rect = box.getBoundingClientRect();
248
+ box.style.right = 'auto'; // no i18n
249
+ box.style.bottom = 'auto'; // no i18n
250
+ box.style.left = rect.left + 'px'; // no i18n
251
+ box.style.top = rect.top + 'px'; // no i18n
252
+ }
253
+ dragging = true;
254
+ startX = event.clientX;
255
+ startY = event.clientY;
256
+ boxLeft = parseInt(box.style.left, 10);
257
+ boxTop = parseInt(box.style.top, 10);
258
+ header.style.cursor = 'grabbing'; // no i18n
259
+ event.preventDefault();
260
+ });
261
+ document.addEventListener('mousemove', function (event) {
262
+ if (!dragging) {
263
+ return;
264
+ }
265
+ var left = boxLeft + (event.clientX - startX);
266
+ var top = boxTop + (event.clientY - startY);
267
+ box.style.left = Math.max(0, Math.min(left, window.innerWidth - box.offsetWidth)) + 'px'; // no i18n
268
+ box.style.top = Math.max(0, Math.min(top, window.innerHeight - box.offsetHeight)) + 'px'; // no i18n
269
+ });
270
+ document.addEventListener('mouseup', function () {
271
+ if (dragging) {
272
+ dragging = false;
273
+ header.style.cursor = 'grab'; // no i18n
274
+ }
275
+ });
276
+ }
277
+ // core/transport asks for the picked user when it builds the feedback request's parameters
278
+ hooks.hooks.feedbackUser = function () {
279
+ return userChoice.anonymous || utils.isEmpty(userChoice.userid) ? null : userChoice;
280
+ };
281
+
282
+ exports.logChoice = logChoice;
283
+ exports.userChoice = userChoice;
284
+ exports.wireDrag = wireDrag;
285
+ exports.wireLogControls = wireLogControls;
286
+ exports.wireUserPicker = wireUserPicker;
@@ -0,0 +1,8 @@
1
+ import { feedbackClose as feedbackCloseImpl } from './ui.js';
2
+ import type { AppticsFeedbackApi } from '../types.js';
3
+ export declare const feedbackOpen: AppticsFeedbackApi["feedbackOpen"];
4
+ export declare const feedbackClose: typeof feedbackCloseImpl;
5
+ /** Resolves once the feedback is sent; rejects when it wasn't (SDK not started, offline, refused). */
6
+ export declare const sendFeedback: AppticsFeedbackApi["sendFeedback"];
7
+ declare const feedback: AppticsFeedbackApi;
8
+ export default feedback;
@@ -0,0 +1,37 @@
1
+ /*! @zoho_apptics/apptics-js-sdk v2.0.0-beta | (c) Zoho Corporation Private Limited | see LICENSE */
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var guard = require('../core/guard.js');
7
+ var logger = require('../core/logger.js');
8
+ var lifecycle = require('../lifecycle.js');
9
+ var ui = require('./ui.js');
10
+
11
+ /**
12
+ * Optional feedback modal, shipped as its own entry point:
13
+ * import { feedbackOpen } from '@zoho_apptics/apptics-js-sdk/feedback';
14
+ * import '@zoho_apptics/apptics-js-sdk/style.css';
15
+ * Apps that never import it don't pay for the modal or its markup.
16
+ * The <script> build includes it, so snippet users are unaffected.
17
+ */
18
+ const feedbackOpen = guard.guard('feedbackOpen', ui.feedbackOpen); // no i18n
19
+ const feedbackClose = guard.guard('feedbackClose', ui.feedbackClose); // no i18n
20
+ /** Resolves once the feedback is sent; rejects when it wasn't (SDK not started, offline, refused). */
21
+ const sendFeedback = guard.guard('sendFeedback', function (...args) {
22
+ return lifecycle.ready().then(function (started) {
23
+ if (!started) {
24
+ throw new Error('apptics.sendFeedback: not sent, the SDK has not started; call init() first'); // no i18n
25
+ }
26
+ return ui.sendFeedback(...args);
27
+ }).catch(function (err) {
28
+ logger.Console.error('apptics.sendFeedback failed:', err); // no i18n
29
+ throw err;
30
+ });
31
+ });
32
+ const feedback = { feedbackOpen, feedbackClose, sendFeedback };
33
+
34
+ exports.default = feedback;
35
+ exports.feedbackClose = feedbackClose;
36
+ exports.feedbackOpen = feedbackOpen;
37
+ exports.sendFeedback = sendFeedback;
@@ -0,0 +1,40 @@
1
+ /** Neither rendered file is sent above this size (the 1.x limit). */
2
+ export declare const MAX_LOG_FILE_SIZE: number;
3
+ export declare const LOG_FILE_NAME = "feedbacklog.txt";
4
+ export declare const DYNINFO_FILE_NAME = "dyninfo.txt";
5
+ /** One rendered file, with the ids to remove once the server has it. */
6
+ export interface RenderedFile {
7
+ file: File;
8
+ ids: string[];
9
+ }
10
+ /** Drops the oldest entries once the store is over MAX_ENTRIES. */
11
+ export declare function trimStoredLogs(): Promise<void>;
12
+ /**
13
+ * Records a timestamped line for the next feedback submission, sent as feedbacklog.txt.
14
+ * Ignores anything that isn't a non-empty string, as 1.x did.
15
+ */
16
+ export declare function addFeedbackLog(message: string): void;
17
+ /**
18
+ * Records a diagnostics key/value under a heading, sent inside dyninfo.txt.
19
+ * Entries sharing a heading are grouped together in the file.
20
+ */
21
+ export declare function addDiagnosticsInfo(heading: string, key: string, value?: unknown): void;
22
+ /** Removes every stored entry. */
23
+ export declare function clearFeedbackLogs(): Promise<void>;
24
+ /** Removes the entries a submission carried, by the ids the rendered files reported. */
25
+ export declare function log_transactions_remove(sentIds: string[]): Promise<void>;
26
+ /** feedbacklog.txt from the stored log lines, or null when there are none. */
27
+ export declare function toLogFile(): Promise<RenderedFile | null>;
28
+ /** The log lines as the file would carry them, for showing in the modal before sending. */
29
+ export declare function logText(): Promise<string>;
30
+ /** The diagnostics entries as dyninfo.txt would carry them, without the device info block. */
31
+ export declare function diagnosticsText(): Promise<string>;
32
+ /** True when any log line is waiting, so the modal knows whether to offer the toggle. */
33
+ export declare function hasLogLines(): Promise<boolean>;
34
+ /**
35
+ * dyninfo.txt: the stored diagnostics entries followed by a [Device Info] block holding
36
+ * `deviceInfo`. Returns null only when there is nothing at all to put in it.
37
+ */
38
+ export declare function toDyninfoFile(deviceInfo: string | null): Promise<RenderedFile | null>;
39
+ /** True when any diagnostics entry is waiting, so a submission knows to send dyninfo unasked. */
40
+ export declare function hasDiagnostics(): Promise<boolean>;
@@ -0,0 +1,202 @@
1
+ /*! @zoho_apptics/apptics-js-sdk v2.0.0-beta | (c) Zoho Corporation Private Limited | see LICENSE */
2
+ 'use strict';
3
+
4
+ var logger = require('../core/logger.js');
5
+ var storage = require('../core/storage.js');
6
+ var state = require('../core/state.js');
7
+ var utils = require('../core/utils.js');
8
+
9
+ /**
10
+ * Log lines and diagnostics entries an app records for its next feedback submission.
11
+ *
12
+ * addFeedbackLog() and addDiagnosticsInfo() accumulate entries in the `logs` store; a feedback
13
+ * submission renders them into the files feedback/add carries (feedbacklog.txt and dyninfo.txt)
14
+ * and removes the ones it took with it, so entries added while a submission is in flight survive.
15
+ *
16
+ * This module deliberately depends on core only, never on the modal, so the main entry point can
17
+ * expose the two collection functions without pulling the feedback UI into an app's bundle.
18
+ */
19
+ /** Entries beyond this are dropped oldest-first, so an app that never submits can't grow forever. */
20
+ const MAX_ENTRIES = 1000;
21
+ /** A single message longer than this is truncated rather than stored whole. */
22
+ const MAX_MESSAGE_LENGTH = 10000;
23
+ /** Neither rendered file is sent above this size (the 1.x limit). */
24
+ const MAX_LOG_FILE_SIZE = 2 * 1024 * 1024;
25
+ /** Bursts of addFeedbackLog() calls coalesce into one trim. */
26
+ const TRIM_DELAY_MS = 2000;
27
+ const LOG_FILE_NAME = 'feedbacklog.txt'; // no i18n
28
+ const DYNINFO_FILE_NAME = 'dyninfo.txt'; // no i18n
29
+ const LOG = 'log'; // no i18n
30
+ const DIAGNOSTICS = 'diagnostics'; // no i18n
31
+ let trimScheduled = false;
32
+ /** Drops the oldest entries once the store is over MAX_ENTRIES. */
33
+ function trimStoredLogs() {
34
+ return storage.log_transactions.all().then(function (items) {
35
+ const excess = items.length - MAX_ENTRIES;
36
+ if (excess <= 0) {
37
+ return undefined;
38
+ }
39
+ logger.Console.warn('apptics: dropping ' + excess + ' oldest feedback log entries (cap is ' + MAX_ENTRIES + ')'); // no i18n
40
+ return storage.log_transactions.remove(items.slice(0, excess));
41
+ });
42
+ }
43
+ /** One trim per burst of adds, so a chatty app pays for one pass over the store, not one per line. */
44
+ function scheduleTrim() {
45
+ if (trimScheduled) {
46
+ return;
47
+ }
48
+ trimScheduled = true;
49
+ setTimeout(function () {
50
+ trimScheduled = false;
51
+ trimStoredLogs();
52
+ }, TRIM_DELAY_MS);
53
+ }
54
+ function store(item) {
55
+ storage.log_transactions.add(item);
56
+ scheduleTrim();
57
+ }
58
+ function truncate(text) {
59
+ return text.length > MAX_MESSAGE_LENGTH ? text.slice(0, MAX_MESSAGE_LENGTH) + '…' : text;
60
+ }
61
+ /**
62
+ * Records a timestamped line for the next feedback submission, sent as feedbacklog.txt.
63
+ * Ignores anything that isn't a non-empty string, as 1.x did.
64
+ */
65
+ function addFeedbackLog(message) {
66
+ if (typeof message !== 'string' || message.length === 0) { // no i18n
67
+ return;
68
+ }
69
+ store({ type: LOG, happenedat: utils.nowMs(), message: truncate(message) });
70
+ }
71
+ /**
72
+ * Records a diagnostics key/value under a heading, sent inside dyninfo.txt.
73
+ * Entries sharing a heading are grouped together in the file.
74
+ */
75
+ function addDiagnosticsInfo(heading, key, value) {
76
+ if (typeof heading !== 'string' || heading.length === 0) { // no i18n
77
+ return;
78
+ }
79
+ if (typeof key !== 'string' || key.length === 0) { // no i18n
80
+ return;
81
+ }
82
+ store({
83
+ type: DIAGNOSTICS,
84
+ happenedat: utils.nowMs(),
85
+ heading: heading,
86
+ key: key,
87
+ value: truncate(String(value === undefined ? '' : value)), // no i18n
88
+ });
89
+ }
90
+ /** Removes the entries a submission carried, by the ids the rendered files reported. */
91
+ function log_transactions_remove(sentIds) {
92
+ return storage.log_transactions.remove(sentIds.map(function (id) { return { id: id }; }));
93
+ }
94
+ /** Entries of one type, oldest first, skipping any that have passed batch_request_timeout. */
95
+ function entriesOfType(type) {
96
+ return storage.log_transactions.all().then(function (items) {
97
+ return items.filter(function (item) {
98
+ return item.type === type && !state.isExpired(item.happenedat);
99
+ });
100
+ });
101
+ }
102
+ /** ISO 8601, from the stored time or a 1.x entry's own timestamp string. */
103
+ function stamp(item) {
104
+ if (typeof item.timestamp === 'string' && item.timestamp.length > 0) {
105
+ return item.timestamp; // migrated from 1.x, which stored the ISO string
106
+ }
107
+ return new Date(typeof item.happenedat === 'number' ? item.happenedat : utils.nowMs()).toISOString();
108
+ }
109
+ function ids(items) {
110
+ return items.map(function (item) { return String(item.id); });
111
+ }
112
+ /** `[heading]` blocks of `key: value` lines, in the order the headings first appeared. */
113
+ function groupDiagnostics(items) {
114
+ const order = [];
115
+ const grouped = {};
116
+ items.forEach(function (item) {
117
+ const heading = String(item.heading);
118
+ if (!grouped[heading]) {
119
+ grouped[heading] = [];
120
+ order.push(heading);
121
+ }
122
+ grouped[heading].push(item.key + ': ' + item.value); // no i18n
123
+ });
124
+ return order.map(function (heading) {
125
+ return '[' + heading + ']\n' + grouped[heading].join('\n'); // no i18n
126
+ }).join('\n\n'); // no i18n
127
+ }
128
+ function asFile(name, content, items) {
129
+ const file = new File([content], name, { type: 'text/plain' }); // no i18n
130
+ if (file.size > MAX_LOG_FILE_SIZE) {
131
+ logger.Console.warn('apptics: ' + name + ' is over ' + (MAX_LOG_FILE_SIZE / (1024 * 1024)) + ' MB, not sending it'); // no i18n
132
+ return null;
133
+ }
134
+ return { file: file, ids: ids(items) };
135
+ }
136
+ function renderLogLines(items) {
137
+ return items.map(function (item) {
138
+ return '[' + stamp(item) + '] ' + item.message; // no i18n
139
+ }).join('\n'); // no i18n
140
+ }
141
+ /** feedbacklog.txt from the stored log lines, or null when there are none. */
142
+ function toLogFile() {
143
+ return entriesOfType(LOG).then(function (items) {
144
+ if (items.length === 0) {
145
+ return null;
146
+ }
147
+ return asFile(LOG_FILE_NAME, renderLogLines(items), items);
148
+ });
149
+ }
150
+ /** The log lines as the file would carry them, for showing in the modal before sending. */
151
+ function logText() {
152
+ return entriesOfType(LOG).then(renderLogLines);
153
+ }
154
+ /** The diagnostics entries as dyninfo.txt would carry them, without the device info block. */
155
+ function diagnosticsText() {
156
+ return entriesOfType(DIAGNOSTICS).then(groupDiagnostics);
157
+ }
158
+ /** True when any log line is waiting, so the modal knows whether to offer the toggle. */
159
+ function hasLogLines() {
160
+ return entriesOfType(LOG).then(function (items) {
161
+ return items.length > 0;
162
+ });
163
+ }
164
+ /**
165
+ * dyninfo.txt: the stored diagnostics entries followed by a [Device Info] block holding
166
+ * `deviceInfo`. Returns null only when there is nothing at all to put in it.
167
+ */
168
+ function toDyninfoFile(deviceInfo) {
169
+ return entriesOfType(DIAGNOSTICS).then(function (items) {
170
+ const blocks = [];
171
+ if (items.length > 0) {
172
+ blocks.push(groupDiagnostics(items));
173
+ }
174
+ if (deviceInfo) {
175
+ blocks.push('[Device Info]\n' + deviceInfo); // no i18n
176
+ }
177
+ if (blocks.length === 0) {
178
+ return null;
179
+ }
180
+ return asFile(DYNINFO_FILE_NAME, blocks.join('\n\n'), items); // no i18n
181
+ });
182
+ }
183
+ /** True when any diagnostics entry is waiting, so a submission knows to send dyninfo unasked. */
184
+ function hasDiagnostics() {
185
+ return entriesOfType(DIAGNOSTICS).then(function (items) {
186
+ return items.length > 0;
187
+ });
188
+ }
189
+
190
+ exports.DYNINFO_FILE_NAME = DYNINFO_FILE_NAME;
191
+ exports.LOG_FILE_NAME = LOG_FILE_NAME;
192
+ exports.MAX_LOG_FILE_SIZE = MAX_LOG_FILE_SIZE;
193
+ exports.addDiagnosticsInfo = addDiagnosticsInfo;
194
+ exports.addFeedbackLog = addFeedbackLog;
195
+ exports.diagnosticsText = diagnosticsText;
196
+ exports.hasDiagnostics = hasDiagnostics;
197
+ exports.hasLogLines = hasLogLines;
198
+ exports.logText = logText;
199
+ exports.log_transactions_remove = log_transactions_remove;
200
+ exports.toDyninfoFile = toDyninfoFile;
201
+ exports.toLogFile = toLogFile;
202
+ exports.trimStoredLogs = trimStoredLogs;
@@ -0,0 +1,25 @@
1
+ import type { FeedbackType, ServerResult } from '../types.js';
2
+ export interface FeedbackRequest {
3
+ type: FeedbackType;
4
+ message: string;
5
+ attachment?: FileList | File[] | null;
6
+ logsFiles?: FileList | File[] | null;
7
+ /** Stored addFeedbackLog() lines: true or unset sends them when there are any, false never does. */
8
+ includeLog?: boolean;
9
+ /**
10
+ * dyninfo.txt, holding addDiagnosticsInfo() entries and the device info dump.
11
+ * True always sends it, false never does, unset sends it when diagnostics are waiting.
12
+ */
13
+ includeDyninfo?: boolean;
14
+ quartzid: string;
15
+ }
16
+ export interface FeedbackResult {
17
+ ok: boolean;
18
+ message: string;
19
+ }
20
+ /**
21
+ * Sends feedback to the Apptics API.
22
+ * Resolves with the outcome, or null when nothing was sent (disabled client or offline).
23
+ */
24
+ export declare function sendFeedbackData(obj: FeedbackRequest): Promise<FeedbackResult | null>;
25
+ export declare function requestToSendFeedback(_payload: FormData): Promise<ServerResult>;