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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (253) hide show
  1. package/CHANGELOG.md +127 -16
  2. package/README.md +357 -215
  3. package/dist/apptics-pn-sw.js +3 -0
  4. package/dist/apptics-pn-sw.js.map +1 -0
  5. package/dist/apptics.esm.min.js +2 -2
  6. package/dist/apptics.esm.min.js.map +1 -1
  7. package/dist/apptics.min.js +2 -2
  8. package/dist/apptics.min.js.map +1 -1
  9. package/dist/chunks/batch-Axq9sTzR.min.js +3 -0
  10. package/dist/chunks/batch-Axq9sTzR.min.js.map +1 -0
  11. package/dist/chunks/lifecycle-Cvg78jN_.min.js +3 -0
  12. package/dist/chunks/lifecycle-Cvg78jN_.min.js.map +1 -0
  13. package/dist/chunks/send-DBpesydB.min.js +3 -0
  14. package/dist/chunks/send-DBpesydB.min.js.map +1 -0
  15. package/dist/chunks/transport-B21X39p4.min.js +3 -0
  16. package/dist/chunks/transport-B21X39p4.min.js.map +1 -0
  17. package/dist/cjs/core/attempts.js +1 -1
  18. package/dist/cjs/core/batch.js +4 -4
  19. package/dist/cjs/core/consent.d.ts +17 -4
  20. package/dist/cjs/core/consent.js +81 -14
  21. package/dist/cjs/core/console-call.d.ts +23 -0
  22. package/dist/cjs/core/console-call.js +63 -0
  23. package/dist/cjs/core/constants.d.ts +66 -17
  24. package/dist/cjs/core/constants.js +76 -19
  25. package/dist/cjs/core/db.js +31 -7
  26. package/dist/cjs/core/debug.d.ts +6 -4
  27. package/dist/cjs/core/debug.js +36 -12
  28. package/dist/cjs/core/env.d.ts +0 -3
  29. package/dist/cjs/core/env.js +1 -9
  30. package/dist/cjs/core/framework-id.d.ts +1 -1
  31. package/dist/cjs/core/framework-id.js +3 -3
  32. package/dist/cjs/core/guard.js +19 -4
  33. package/dist/cjs/core/hooks.d.ts +29 -0
  34. package/dist/cjs/core/hooks.js +12 -1
  35. package/dist/cjs/core/locks.js +1 -1
  36. package/dist/cjs/core/logger.js +1 -1
  37. package/dist/cjs/core/shield.d.ts +31 -0
  38. package/dist/cjs/core/shield.js +129 -0
  39. package/dist/cjs/core/state.d.ts +11 -5
  40. package/dist/cjs/core/state.js +4 -4
  41. package/dist/cjs/core/storage.d.ts +7 -0
  42. package/dist/cjs/core/storage.js +28 -9
  43. package/dist/cjs/core/stylesheet.js +1 -1
  44. package/dist/cjs/core/transport.d.ts +15 -4
  45. package/dist/cjs/core/transport.js +72 -25
  46. package/dist/cjs/core/utils.js +1 -1
  47. package/dist/cjs/core/validate.js +6 -5
  48. package/dist/cjs/device/appversion.d.ts +10 -1
  49. package/dist/cjs/device/appversion.js +26 -3
  50. package/dist/cjs/device/index.d.ts +17 -2
  51. package/dist/cjs/device/index.js +251 -35
  52. package/dist/cjs/engagement/api-rules.js +1 -1
  53. package/dist/cjs/engagement/auto-api.js +4 -3
  54. package/dist/cjs/engagement/auto-screen.js +10 -6
  55. package/dist/cjs/engagement/defined-events.d.ts +2 -3
  56. package/dist/cjs/engagement/defined-events.js +10 -16
  57. package/dist/cjs/engagement/send.js +7 -3
  58. package/dist/cjs/engagement/session.d.ts +17 -0
  59. package/dist/cjs/engagement/session.js +154 -23
  60. package/dist/cjs/engagement/track.d.ts +4 -4
  61. package/dist/cjs/engagement/track.js +23 -17
  62. package/dist/cjs/errors/send.js +2 -2
  63. package/dist/cjs/errors/track.d.ts +2 -1
  64. package/dist/cjs/errors/track.js +8 -5
  65. package/dist/cjs/feedback/controls.d.ts +36 -4
  66. package/dist/cjs/feedback/controls.js +302 -67
  67. package/dist/cjs/feedback/i18n/index.d.ts +31 -0
  68. package/dist/cjs/feedback/i18n/index.js +187 -0
  69. package/dist/cjs/feedback/i18n/strings.d.ts +9 -0
  70. package/dist/cjs/feedback/i18n/strings.js +8 -0
  71. package/dist/cjs/feedback/index.js +1 -1
  72. package/dist/cjs/feedback/logs.d.ts +3 -6
  73. package/dist/cjs/feedback/logs.js +12 -21
  74. package/dist/cjs/feedback/quartz.js +5 -2
  75. package/dist/cjs/feedback/send.d.ts +6 -3
  76. package/dist/cjs/feedback/send.js +59 -41
  77. package/dist/cjs/feedback/styles.js +2 -2
  78. package/dist/cjs/feedback/template.d.ts +4 -2
  79. package/dist/cjs/feedback/template.js +73 -44
  80. package/dist/cjs/feedback/ui.d.ts +47 -4
  81. package/dist/cjs/feedback/ui.js +351 -97
  82. package/dist/cjs/heatmap/send.d.ts +2 -0
  83. package/dist/cjs/heatmap/send.js +3 -5
  84. package/dist/cjs/heatmap/track.js +13 -9
  85. package/dist/cjs/index.d.ts +1 -2
  86. package/dist/cjs/index.js +55 -18
  87. package/dist/cjs/lifecycle.d.ts +13 -2
  88. package/dist/cjs/lifecycle.js +233 -118
  89. package/dist/cjs/pushnotification/display.d.ts +65 -0
  90. package/dist/cjs/pushnotification/display.js +112 -0
  91. package/dist/cjs/pushnotification/index.d.ts +20 -0
  92. package/dist/cjs/pushnotification/index.js +96 -0
  93. package/dist/cjs/pushnotification/kept-opens.d.ts +23 -0
  94. package/dist/cjs/pushnotification/kept-opens.js +64 -0
  95. package/dist/cjs/pushnotification/notify.d.ts +45 -0
  96. package/dist/cjs/pushnotification/notify.js +476 -0
  97. package/dist/cjs/pushnotification/payload.d.ts +65 -0
  98. package/dist/cjs/pushnotification/payload.js +279 -0
  99. package/dist/cjs/pushnotification/session.d.ts +46 -0
  100. package/dist/cjs/pushnotification/session.js +413 -0
  101. package/dist/cjs/pushnotification/stats.d.ts +45 -0
  102. package/dist/cjs/pushnotification/stats.js +244 -0
  103. package/dist/cjs/pushnotification/wms.d.ts +30 -0
  104. package/dist/cjs/pushnotification/wms.js +374 -0
  105. package/dist/cjs/remoteconfig/country.js +1 -1
  106. package/dist/cjs/remoteconfig/custom.js +4 -3
  107. package/dist/cjs/remoteconfig/evaluate.js +1 -1
  108. package/dist/cjs/remoteconfig/fetch.d.ts +17 -10
  109. package/dist/cjs/remoteconfig/fetch.js +146 -32
  110. package/dist/cjs/remoteconfig/index.d.ts +9 -5
  111. package/dist/cjs/remoteconfig/index.js +24 -32
  112. package/dist/cjs/remoteconfig/store.d.ts +15 -7
  113. package/dist/cjs/remoteconfig/store.js +68 -35
  114. package/dist/cjs/remoteconfig/tz-countries.js +1 -1
  115. package/dist/cjs/{core → remotelog}/callsite.d.ts +5 -4
  116. package/dist/cjs/{core → remotelog}/callsite.js +6 -5
  117. package/dist/cjs/remotelog/gate.js +1 -1
  118. package/dist/cjs/remotelog/logger.js +2 -2
  119. package/dist/cjs/remotelog/send.js +6 -5
  120. package/dist/cjs/remotelogger/index.js +1 -1
  121. package/dist/cjs/scheduler.d.ts +3 -1
  122. package/dist/cjs/scheduler.js +34 -25
  123. package/dist/cjs/sw/apptics-pn-sw.d.ts +83 -0
  124. package/dist/cjs/sw/timers.d.ts +44 -0
  125. package/dist/cjs/types.d.ts +90 -29
  126. package/dist/cjs/user/index.d.ts +7 -0
  127. package/dist/cjs/user/index.js +25 -3
  128. package/dist/esm/core/attempts.js +1 -1
  129. package/dist/esm/core/batch.js +4 -4
  130. package/dist/esm/core/consent.d.ts +17 -4
  131. package/dist/esm/core/consent.js +84 -20
  132. package/dist/esm/core/console-call.d.ts +23 -0
  133. package/dist/esm/core/console-call.js +60 -0
  134. package/dist/esm/core/constants.d.ts +66 -17
  135. package/dist/esm/core/constants.js +73 -20
  136. package/dist/esm/core/db.js +31 -7
  137. package/dist/esm/core/debug.d.ts +6 -4
  138. package/dist/esm/core/debug.js +37 -13
  139. package/dist/esm/core/env.d.ts +0 -3
  140. package/dist/esm/core/env.js +2 -9
  141. package/dist/esm/core/framework-id.d.ts +1 -1
  142. package/dist/esm/core/framework-id.js +3 -3
  143. package/dist/esm/core/guard.js +19 -4
  144. package/dist/esm/core/hooks.d.ts +29 -0
  145. package/dist/esm/core/hooks.js +12 -1
  146. package/dist/esm/core/locks.js +1 -1
  147. package/dist/esm/core/logger.js +1 -1
  148. package/dist/esm/core/shield.d.ts +31 -0
  149. package/dist/esm/core/shield.js +119 -0
  150. package/dist/esm/core/state.d.ts +11 -5
  151. package/dist/esm/core/state.js +4 -4
  152. package/dist/esm/core/storage.d.ts +7 -0
  153. package/dist/esm/core/storage.js +28 -11
  154. package/dist/esm/core/stylesheet.js +1 -1
  155. package/dist/esm/core/transport.d.ts +15 -4
  156. package/dist/esm/core/transport.js +73 -28
  157. package/dist/esm/core/utils.js +1 -1
  158. package/dist/esm/core/validate.js +6 -5
  159. package/dist/esm/device/appversion.d.ts +10 -1
  160. package/dist/esm/device/appversion.js +26 -4
  161. package/dist/esm/device/index.d.ts +17 -2
  162. package/dist/esm/device/index.js +255 -42
  163. package/dist/esm/engagement/api-rules.js +1 -1
  164. package/dist/esm/engagement/auto-api.js +4 -3
  165. package/dist/esm/engagement/auto-screen.js +10 -6
  166. package/dist/esm/engagement/defined-events.d.ts +2 -3
  167. package/dist/esm/engagement/defined-events.js +10 -16
  168. package/dist/esm/engagement/send.js +7 -3
  169. package/dist/esm/engagement/session.d.ts +17 -0
  170. package/dist/esm/engagement/session.js +152 -24
  171. package/dist/esm/engagement/track.d.ts +4 -4
  172. package/dist/esm/engagement/track.js +24 -18
  173. package/dist/esm/errors/send.js +2 -2
  174. package/dist/esm/errors/track.d.ts +2 -1
  175. package/dist/esm/errors/track.js +8 -5
  176. package/dist/esm/feedback/controls.d.ts +36 -4
  177. package/dist/esm/feedback/controls.js +298 -68
  178. package/dist/esm/feedback/i18n/index.d.ts +31 -0
  179. package/dist/esm/feedback/i18n/index.js +178 -0
  180. package/dist/esm/feedback/i18n/strings.d.ts +9 -0
  181. package/dist/esm/feedback/i18n/strings.js +4 -0
  182. package/dist/esm/feedback/index.js +1 -1
  183. package/dist/esm/feedback/logs.d.ts +3 -6
  184. package/dist/esm/feedback/logs.js +12 -21
  185. package/dist/esm/feedback/quartz.js +5 -2
  186. package/dist/esm/feedback/send.d.ts +6 -3
  187. package/dist/esm/feedback/send.js +61 -44
  188. package/dist/esm/feedback/styles.js +2 -2
  189. package/dist/esm/feedback/template.d.ts +4 -2
  190. package/dist/esm/feedback/template.js +73 -44
  191. package/dist/esm/feedback/ui.d.ts +47 -4
  192. package/dist/esm/feedback/ui.js +353 -99
  193. package/dist/esm/heatmap/send.d.ts +2 -0
  194. package/dist/esm/heatmap/send.js +3 -5
  195. package/dist/esm/heatmap/track.js +13 -9
  196. package/dist/esm/index.d.ts +1 -2
  197. package/dist/esm/index.js +58 -21
  198. package/dist/esm/lifecycle.d.ts +13 -2
  199. package/dist/esm/lifecycle.js +238 -125
  200. package/dist/esm/pushnotification/display.d.ts +65 -0
  201. package/dist/esm/pushnotification/display.js +95 -0
  202. package/dist/esm/pushnotification/index.d.ts +20 -0
  203. package/dist/esm/pushnotification/index.js +91 -0
  204. package/dist/esm/pushnotification/kept-opens.d.ts +23 -0
  205. package/dist/esm/pushnotification/kept-opens.js +62 -0
  206. package/dist/esm/pushnotification/notify.d.ts +45 -0
  207. package/dist/esm/pushnotification/notify.js +469 -0
  208. package/dist/esm/pushnotification/payload.d.ts +65 -0
  209. package/dist/esm/pushnotification/payload.js +272 -0
  210. package/dist/esm/pushnotification/session.d.ts +46 -0
  211. package/dist/esm/pushnotification/session.js +402 -0
  212. package/dist/esm/pushnotification/stats.d.ts +45 -0
  213. package/dist/esm/pushnotification/stats.js +238 -0
  214. package/dist/esm/pushnotification/wms.d.ts +30 -0
  215. package/dist/esm/pushnotification/wms.js +368 -0
  216. package/dist/esm/remoteconfig/country.js +1 -1
  217. package/dist/esm/remoteconfig/custom.js +4 -3
  218. package/dist/esm/remoteconfig/evaluate.js +1 -1
  219. package/dist/esm/remoteconfig/fetch.d.ts +17 -10
  220. package/dist/esm/remoteconfig/fetch.js +147 -33
  221. package/dist/esm/remoteconfig/index.d.ts +9 -5
  222. package/dist/esm/remoteconfig/index.js +24 -32
  223. package/dist/esm/remoteconfig/store.d.ts +15 -7
  224. package/dist/esm/remoteconfig/store.js +68 -36
  225. package/dist/esm/remoteconfig/tz-countries.js +1 -1
  226. package/dist/esm/{core → remotelog}/callsite.d.ts +5 -4
  227. package/dist/esm/{core → remotelog}/callsite.js +6 -5
  228. package/dist/esm/remotelog/gate.js +1 -1
  229. package/dist/esm/remotelog/logger.js +2 -2
  230. package/dist/esm/remotelog/send.js +6 -5
  231. package/dist/esm/remotelogger/index.js +1 -1
  232. package/dist/esm/scheduler.d.ts +3 -1
  233. package/dist/esm/scheduler.js +35 -27
  234. package/dist/esm/sw/apptics-pn-sw.d.ts +83 -0
  235. package/dist/esm/sw/timers.d.ts +44 -0
  236. package/dist/esm/types.d.ts +90 -29
  237. package/dist/esm/user/index.d.ts +7 -0
  238. package/dist/esm/user/index.js +26 -5
  239. package/dist/feedback.esm.min.js +2 -2
  240. package/dist/feedback.esm.min.js.map +1 -1
  241. package/dist/pushnotification.esm.min.js +3 -0
  242. package/dist/pushnotification.esm.min.js.map +1 -0
  243. package/dist/remoteconfig.esm.min.js +3 -0
  244. package/dist/remoteconfig.esm.min.js.map +1 -0
  245. package/dist/remotelogger.esm.min.js +3 -0
  246. package/dist/remotelogger.esm.min.js.map +1 -0
  247. package/package.json +17 -3
  248. package/dist/chunks/lifecycle-VYr43KcB.min.js +0 -3
  249. package/dist/chunks/lifecycle-VYr43KcB.min.js.map +0 -1
  250. package/dist/cjs/auto-init.d.ts +0 -8
  251. package/dist/cjs/auto-init.js +0 -32
  252. package/dist/esm/auto-init.d.ts +0 -8
  253. package/dist/esm/auto-init.js +0 -29
@@ -0,0 +1,65 @@
1
+ import type { WebNotification } from './payload.js';
2
+ /**
3
+ * How a push notification is shown, for the page and the service worker alike: the title, the
4
+ * options for showNotification(), and what the notification carries in its data so the worker
5
+ * can step a carousel and open a button's URL after the tab has closed.
6
+ */
7
+ /** What a shown notification carries in its data. `apptics: 1` marks it as the SDK's. */
8
+ export interface ShownNotification {
9
+ apptics: 1;
10
+ view: WebNotification;
11
+ /** The carousel slide on show. */
12
+ index: number;
13
+ tag: string;
14
+ /** The message's data as it arrived, for the app's click callback. */
15
+ message: Record<string, unknown>;
16
+ /**
17
+ * Which run of the message this is: the envelope's timestamp, the server's send time. A
18
+ * recurring push sends the same appticsPnID every run, and without a notificationNumber this is
19
+ * what tells the runs' stats apart. Never sent.
20
+ */
21
+ run?: string;
22
+ }
23
+ /** Notification options with the parts some DOM typings leave out. */
24
+ export type ShowOptions = NotificationOptions & {
25
+ actions?: Array<{
26
+ action: string;
27
+ title: string;
28
+ icon?: string;
29
+ }>;
30
+ image?: string;
31
+ renotify?: boolean;
32
+ data?: ShownNotification;
33
+ };
34
+ /** What the service worker posts to the site's tabs. */
35
+ export declare const CLICK_MESSAGE = "apptics-notification-click";
36
+ export declare const CLOSE_MESSAGE = "apptics-notification-close";
37
+ /** Prev / Next pressed: the page stops that notification's auto-scroll, as the visitor took over. */
38
+ export declare const STEP_MESSAGE = "apptics-notification-step";
39
+ /** The worker gives back the timers it could not finish in its time: an open tab runs the rest. */
40
+ export declare const HANDOFF_MESSAGE = "apptics-notification-handoff";
41
+ /** What a tab posts to the service worker: run this notification's timers; stop them (one tag, or all). */
42
+ export declare const TIMERS_MESSAGE = "apptics-notification-timers";
43
+ export declare const STOP_TIMERS_MESSAGE = "apptics-notification-stop";
44
+ /** The worker's answer to TIMERS_MESSAGE, on the port it came with: it runs them. */
45
+ export declare const TIMERS_TAKEN = "apptics-notification-timers-taken";
46
+ export declare const ACTION_PREV = "apptics-prev";
47
+ export declare const ACTION_NEXT = "apptics-next";
48
+ export declare const ACTION_BUTTON = "apptics-btn-";
49
+ export declare function isCarousel(view: WebNotification): boolean;
50
+ /** The title shown for slide `index`: the slide number is added for a carousel. */
51
+ export declare function titleFor(view: WebNotification, index: number): string;
52
+ /**
53
+ * The options for showing `shown` at its slide. `update` is a re-show of one already on screen
54
+ * (a carousel step, a countdown tick): it makes no sound.
55
+ */
56
+ export declare function optionsFor(shown: ShownNotification, update: boolean, nowMs: number): ShowOptions;
57
+ /**
58
+ * Whether this browser shows a notification's large image. Notification.prototype has `image`
59
+ * where it does; Chrome on macOS has none. Asked the same way in the page and the worker.
60
+ */
61
+ export declare function supportsImage(): boolean;
62
+ /** Whether a notification's data is one the SDK showed. */
63
+ export declare function isOurs(data: unknown): data is ShownNotification;
64
+ /** The slide after `index` by `step` (+1 / -1), wrapping. */
65
+ export declare function stepIndex(view: WebNotification, index: number, step: number): number;
@@ -0,0 +1,112 @@
1
+ /*! @zoho_apptics/apptics-js-sdk v2.0.0 | (c) Zoho Corporation Private Limited | see LICENSE */
2
+ 'use strict';
3
+
4
+ var payload = require('./payload.js');
5
+
6
+ /** What the service worker posts to the site's tabs. */
7
+ const CLICK_MESSAGE = 'apptics-notification-click'; // no i18n
8
+ const CLOSE_MESSAGE = 'apptics-notification-close'; // no i18n
9
+ /** Prev / Next pressed: the page stops that notification's auto-scroll, as the visitor took over. */
10
+ const STEP_MESSAGE = 'apptics-notification-step'; // no i18n
11
+ /** The worker gives back the timers it could not finish in its time: an open tab runs the rest. */
12
+ const HANDOFF_MESSAGE = 'apptics-notification-handoff'; // no i18n
13
+ /** What a tab posts to the service worker: run this notification's timers; stop them (one tag, or all). */
14
+ const TIMERS_MESSAGE = 'apptics-notification-timers'; // no i18n
15
+ const STOP_TIMERS_MESSAGE = 'apptics-notification-stop'; // no i18n
16
+ /** The worker's answer to TIMERS_MESSAGE, on the port it came with: it runs them. */
17
+ const TIMERS_TAKEN = 'apptics-notification-timers-taken'; // no i18n
18
+ const ACTION_PREV = 'apptics-prev'; // no i18n
19
+ const ACTION_NEXT = 'apptics-next'; // no i18n
20
+ const ACTION_BUTTON = 'apptics-btn-'; // no i18n
21
+ /** The browser's labels for the carousel's two buttons, as the console's preview shows them. */
22
+ const PREV_LABEL = 'Prev'; // no i18n
23
+ const NEXT_LABEL = 'Next'; // no i18n
24
+ function isCarousel(view) {
25
+ return view.images.length > 1;
26
+ }
27
+ /** The title shown for slide `index`: the slide number is added for a carousel. */
28
+ function titleFor(view, index) {
29
+ return isCarousel(view) ? view.title + ' (' + (index + 1) + ' / ' + view.images.length + ')' : view.title; // no i18n
30
+ }
31
+ /**
32
+ * The options for showing `shown` at its slide. `update` is a re-show of one already on screen
33
+ * (a carousel step, a countdown tick): it makes no sound.
34
+ */
35
+ function optionsFor(shown, update, nowMs) {
36
+ var view = shown.view;
37
+ var body = view.text;
38
+ if (view.countdownTo > 0) {
39
+ body += (body ? '\n' : '') + payload.formatCountdown(view.countdownTo, nowMs); // no i18n
40
+ }
41
+ var options = {
42
+ body: body,
43
+ tag: shown.tag,
44
+ requireInteraction: view.requireInteraction,
45
+ silent: view.silent || update,
46
+ // a new message alerts even when it replaces one still on screen under the same tag (the
47
+ // same appticsPnID); the SDK's own updates (a slide, a countdown tick) replace it quietly
48
+ renotify: !update,
49
+ data: shown,
50
+ };
51
+ var image = view.images[shown.index] || view.images[0];
52
+ if (image && !supportsImage()) {
53
+ // no large image here (Chrome on macOS goes through the system's notifications, which have
54
+ // no slot for one): the slide shows as the icon, so a carousel still visibly changes
55
+ options.icon = image;
56
+ }
57
+ else {
58
+ if (view.icon) {
59
+ options.icon = view.icon;
60
+ }
61
+ if (image) {
62
+ options.image = image;
63
+ }
64
+ }
65
+ if (isCarousel(view)) {
66
+ options.actions = [{ action: ACTION_PREV, title: PREV_LABEL }, { action: ACTION_NEXT, title: NEXT_LABEL }];
67
+ }
68
+ else if (view.buttons.length > 0) {
69
+ options.actions = view.buttons.map(function (b, i) {
70
+ var action = { action: ACTION_BUTTON + i, title: b.label };
71
+ if (b.icon) {
72
+ action.icon = b.icon;
73
+ }
74
+ return action;
75
+ });
76
+ }
77
+ return options;
78
+ }
79
+ /**
80
+ * Whether this browser shows a notification's large image. Notification.prototype has `image`
81
+ * where it does; Chrome on macOS has none. Asked the same way in the page and the worker.
82
+ */
83
+ function supportsImage() {
84
+ var N = typeof Notification !== 'undefined' ? Notification : undefined; // no i18n
85
+ return !N || !N.prototype || 'image' in N.prototype; // no i18n
86
+ }
87
+ /** Whether a notification's data is one the SDK showed. */
88
+ function isOurs(data) {
89
+ return !!data && typeof data === 'object' && data.apptics === 1; // no i18n
90
+ }
91
+ /** The slide after `index` by `step` (+1 / -1), wrapping. */
92
+ function stepIndex(view, index, step) {
93
+ var n = view.images.length;
94
+ return n > 0 ? ((index + step) % n + n) % n : 0;
95
+ }
96
+
97
+ exports.ACTION_BUTTON = ACTION_BUTTON;
98
+ exports.ACTION_NEXT = ACTION_NEXT;
99
+ exports.ACTION_PREV = ACTION_PREV;
100
+ exports.CLICK_MESSAGE = CLICK_MESSAGE;
101
+ exports.CLOSE_MESSAGE = CLOSE_MESSAGE;
102
+ exports.HANDOFF_MESSAGE = HANDOFF_MESSAGE;
103
+ exports.STEP_MESSAGE = STEP_MESSAGE;
104
+ exports.STOP_TIMERS_MESSAGE = STOP_TIMERS_MESSAGE;
105
+ exports.TIMERS_MESSAGE = TIMERS_MESSAGE;
106
+ exports.TIMERS_TAKEN = TIMERS_TAKEN;
107
+ exports.isCarousel = isCarousel;
108
+ exports.isOurs = isOurs;
109
+ exports.optionsFor = optionsFor;
110
+ exports.stepIndex = stepIndex;
111
+ exports.supportsImage = supportsImage;
112
+ exports.titleFor = titleFor;
@@ -0,0 +1,20 @@
1
+ import './wms.js';
2
+ import type { PermissionAnswer } from './notify.js';
3
+ /** AppticsPushNotification: setEnabled, isEnabled, and the browser notification's requestPermission. */
4
+ export declare const AppticsPushNotification: {
5
+ /**
6
+ * setEnabled(true) registers this browser for push now; setEnabled(false) unregisters it and
7
+ * keeps it unregistered across visits until setEnabled(true). Resolves true once done, false
8
+ * when push is off for the app in the console.
9
+ */
10
+ setEnabled: (enabled: boolean) => Promise<boolean>;
11
+ /** Whether this browser holds a push session now. */
12
+ isEnabled: () => boolean;
13
+ /**
14
+ * Asks the visitor to allow browser notifications; call it from a click. Resolves with
15
+ * 'granted', 'denied', 'default' (dismissed) or 'unsupported'. Once granted, each message is
16
+ * also shown as a notification while a tab of the site is open.
17
+ */
18
+ requestPermission: () => Promise<PermissionAnswer>;
19
+ };
20
+ export default AppticsPushNotification;
@@ -0,0 +1,96 @@
1
+ /*! @zoho_apptics/apptics-js-sdk v2.0.0 | (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 session = require('./session.js');
9
+ require('./wms.js');
10
+ var notify = require('./notify.js');
11
+
12
+ /**
13
+ * Push notification, shipped as its own entry point:
14
+ * import { AppticsPushNotification } from '@zoho_apptics/apptics-js-sdk/push-notification';
15
+ *
16
+ * Importing it is enough for the SDK to register this browser on its own, whenever the console
17
+ * has push on for the app: getsdkconfig is asked about module 16, and its answer says where
18
+ * wmsliteapi.js loads from. Messages arrive over WMS while the page is open, and each shows as a
19
+ * browser notification.
20
+ *
21
+ * The visitor sees a browser notification for each message once they allow it, which
22
+ * requestPermission() asks for: call it from a click, as browsers require. A click on one focuses
23
+ * the tab and opens the message's url.
24
+ *
25
+ * setEnabled(true) registers by hand, and also undoes an earlier setEnabled(false), which
26
+ * otherwise holds across visits. While tracking is anonymous the browser registers by its
27
+ * anonymous id; with no tracking it does not register at all.
28
+ */
29
+ /**
30
+ * true registers this browser (and undoes an earlier false); false unregisters it, held across
31
+ * visits until true. Resolves true once done, false when it can't be (push off for the app, or
32
+ * the SDK didn't start).
33
+ */
34
+ function setEnabled(enabled) {
35
+ if (enabled !== true && enabled !== false) {
36
+ logger.warnAlways('AppticsPushNotification.setEnabled: takes true (register this browser) or false (unregister it)'); // no i18n
37
+ return Promise.resolve(false);
38
+ }
39
+ return session.whenStarted().then(function (running) {
40
+ if (!running) {
41
+ return false;
42
+ }
43
+ return enabled ? session.registerPush(true).then(function (session) { return session !== null; }) : session.unregisterPush();
44
+ });
45
+ }
46
+ function isEnabled() {
47
+ return session.currentSession() !== null;
48
+ }
49
+ function requestPermission() {
50
+ return notify.requestPermission();
51
+ }
52
+ // function onNotificationClick(callback: (click: NotificationClick) => void): () => void {
53
+ // if (typeof callback !== 'function') { // no i18n
54
+ // warnAlways('AppticsPushNotification.onNotificationClick: takes a function, called with the clicked message\'s data'); // no i18n
55
+ // return function () {};
56
+ // }
57
+ // return addClickListener(callback);
58
+ // }
59
+ const setEnabledGuarded = guard.guard('AppticsPushNotification.setEnabled', setEnabled); // no i18n
60
+ const isEnabledGuarded = guard.guard('AppticsPushNotification.isEnabled', isEnabled); // no i18n
61
+ const requestPermissionGuarded = guard.guard('AppticsPushNotification.requestPermission', requestPermission); // no i18n
62
+ // const onNotificationClickGuarded = guard('AppticsPushNotification.onNotificationClick', onNotificationClick); // no i18n
63
+ /** AppticsPushNotification: setEnabled, isEnabled, and the browser notification's requestPermission. */
64
+ const AppticsPushNotification = {
65
+ /**
66
+ * setEnabled(true) registers this browser for push now; setEnabled(false) unregisters it and
67
+ * keeps it unregistered across visits until setEnabled(true). Resolves true once done, false
68
+ * when push is off for the app in the console.
69
+ */
70
+ setEnabled: function setEnabled(enabled) {
71
+ return guard.forward(setEnabledGuarded, arguments);
72
+ },
73
+ /** Whether this browser holds a push session now. */
74
+ isEnabled: function isEnabled() {
75
+ return guard.forward(isEnabledGuarded, arguments);
76
+ },
77
+ /**
78
+ * Asks the visitor to allow browser notifications; call it from a click. Resolves with
79
+ * 'granted', 'denied', 'default' (dismissed) or 'unsupported'. Once granted, each message is
80
+ * also shown as a notification while a tab of the site is open.
81
+ */
82
+ requestPermission: function requestPermission() {
83
+ return guard.forward(requestPermissionGuarded, arguments);
84
+ },
85
+ // /**
86
+ // * Calls `callback` when the visitor clicks a notification, with { action, appticsPnID,
87
+ // * additional, data }: the button's action id ('' for the body), the message's id and its
88
+ // * additional key-values, and the message's data. Returns the function that stops it.
89
+ // */
90
+ // onNotificationClick: function onNotificationClick(callback: (click: NotificationClick) => void): () => void {
91
+ // return forward(onNotificationClickGuarded, arguments);
92
+ // },
93
+ };
94
+
95
+ exports.AppticsPushNotification = AppticsPushNotification;
96
+ exports.default = AppticsPushNotification;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Opens the service worker couldn't hand to a tab of the site: the click opened another site, and
3
+ * no tab of this one was open. The worker keeps them in IndexedDB (apptics-push / opens), which the
4
+ * page shares, and the SDK sends them as opened stats on the next visit.
5
+ */
6
+ export interface KeptOpen {
7
+ notificationid: string;
8
+ notificationnumber: number | null;
9
+ /** The button's action id, '' for the body. */
10
+ actionid: string;
11
+ timestamp: number;
12
+ /** The message's conversion event, which waits from the open. */
13
+ conversion: {
14
+ name: string;
15
+ group: string;
16
+ } | null;
17
+ /** The run's send time, for a recurring push without a run number. */
18
+ run?: string;
19
+ }
20
+ /** Keeps an open for the next visit. Resolves either way: losing one stat breaks nothing else. */
21
+ export declare function keepOpen(open: KeptOpen): Promise<void>;
22
+ /** Takes every kept open out of the store, in one transaction, so two tabs can't both send one. */
23
+ export declare function takeOpens(): Promise<KeptOpen[]>;
@@ -0,0 +1,64 @@
1
+ /*! @zoho_apptics/apptics-js-sdk v2.0.0 | (c) Zoho Corporation Private Limited | see LICENSE */
2
+ 'use strict';
3
+
4
+ /**
5
+ * Opens the service worker couldn't hand to a tab of the site: the click opened another site, and
6
+ * no tab of this one was open. The worker keeps them in IndexedDB (apptics-push / opens), which the
7
+ * page shares, and the SDK sends them as opened stats on the next visit.
8
+ */
9
+ const DB_NAME = 'apptics-push'; // no i18n
10
+ const STORE = 'opens'; // no i18n
11
+ function idb() {
12
+ return typeof indexedDB !== 'undefined' ? indexedDB : undefined; // no i18n
13
+ }
14
+ function openDb() {
15
+ var factory = idb();
16
+ if (!factory) {
17
+ return Promise.resolve(null);
18
+ }
19
+ return new Promise(function (resolve) {
20
+ try {
21
+ var req = factory.open(DB_NAME, 1);
22
+ req.onupgradeneeded = function () {
23
+ if (!req.result.objectStoreNames.contains(STORE)) {
24
+ req.result.createObjectStore(STORE, { autoIncrement: true });
25
+ }
26
+ };
27
+ req.onsuccess = function () { resolve(req.result); };
28
+ req.onerror = function () { resolve(null); };
29
+ req.onblocked = function () { resolve(null); };
30
+ }
31
+ catch (e) {
32
+ resolve(null);
33
+ }
34
+ });
35
+ }
36
+ /** Takes every kept open out of the store, in one transaction, so two tabs can't both send one. */
37
+ function takeOpens() {
38
+ return openDb().then(function (db) {
39
+ if (!db) {
40
+ return [];
41
+ }
42
+ return new Promise(function (resolve) {
43
+ try {
44
+ var tx = db.transaction(STORE, 'readwrite'); // no i18n
45
+ var store = tx.objectStore(STORE);
46
+ var got = [];
47
+ var all = store.getAll();
48
+ all.onsuccess = function () {
49
+ got = all.result;
50
+ store.clear();
51
+ };
52
+ tx.oncomplete = function () { db.close(); resolve(got); };
53
+ tx.onerror = function () { db.close(); resolve([]); };
54
+ tx.onabort = function () { db.close(); resolve([]); };
55
+ }
56
+ catch (e) {
57
+ db.close();
58
+ resolve([]);
59
+ }
60
+ });
61
+ });
62
+ }
63
+
64
+ exports.takeOpens = takeOpens;
@@ -0,0 +1,45 @@
1
+ export type PermissionAnswer = NotificationPermission | 'unsupported';
2
+ type Message = Record<string, unknown>;
3
+ /** What the app's onNotificationClick gets. */
4
+ export interface NotificationClick {
5
+ /** The clicked button's action id, or '' for the notification's body. */
6
+ action: string;
7
+ appticsPnID: string;
8
+ /** addInfo.additional: the console's key-values. */
9
+ additional: Message;
10
+ /** The message's data as it arrived. */
11
+ data: Message;
12
+ }
13
+ /** How a url on this site is opened: a seam, since a test page cannot navigate. */
14
+ export declare const _openUrlForTest: {
15
+ assign: (url: string) => void;
16
+ };
17
+ /** Asks the browser for permission to show notifications; resolves with its answer. */
18
+ export declare function requestPermission(): Promise<PermissionAnswer>;
19
+ /** Calls `fn` when the visitor clicks a notification, with the button and the message. */
20
+ export declare function addClickListener(fn: (click: NotificationClick) => void): () => void;
21
+ /**
22
+ * A notification was clicked (a button's action id, or '' for the body): the opened stat, and the
23
+ * conversion event it waits for from now.
24
+ */
25
+ declare function opened(data: Message, action: string, run?: string): void;
26
+ /** Test seams: the click path, and listening again after a test stubs the worker container. */
27
+ export declare const _openedForTest: typeof opened;
28
+ export declare function _listenForTest(): void;
29
+ /** The Apptics service worker: the site's /apptics-pn-sw.js, which imports apptics-pn-sw.js. */
30
+ export declare const SERVICE_WORKER = "/apptics-pn-sw.js";
31
+ /**
32
+ * The site's /apptics-pn-sw.js registration, or null when there is none: the browser has no service
33
+ * workers, the site has no /apptics-pn-sw.js (a plain notification shows; only logged, as many sites
34
+ * won't have it), or another worker of the site's controls its root. Registered once.
35
+ */
36
+ export declare function serviceWorkerReady(): Promise<ServiceWorkerRegistration | null>;
37
+ /** Stops the timers of every notification, the worker's too. Disconnecting (and reset) calls it. */
38
+ export declare function stopAllNotifications(): void;
39
+ /**
40
+ * Shows the notification for a message's `data`, when the visitor has granted permission. It is
41
+ * tagged by addInfo.appticsPnID, else the envelope's `timestamp`, so the same message shown by two
42
+ * tabs appears once.
43
+ */
44
+ export declare function showNotification(data: Message, timestamp?: unknown): void;
45
+ export {};