@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.
- package/CHANGELOG.md +127 -16
- package/README.md +357 -215
- package/dist/apptics-pn-sw.js +3 -0
- package/dist/apptics-pn-sw.js.map +1 -0
- package/dist/apptics.esm.min.js +2 -2
- package/dist/apptics.esm.min.js.map +1 -1
- package/dist/apptics.min.js +2 -2
- package/dist/apptics.min.js.map +1 -1
- package/dist/chunks/batch-Axq9sTzR.min.js +3 -0
- package/dist/chunks/batch-Axq9sTzR.min.js.map +1 -0
- package/dist/chunks/lifecycle-Cvg78jN_.min.js +3 -0
- package/dist/chunks/lifecycle-Cvg78jN_.min.js.map +1 -0
- package/dist/chunks/send-DBpesydB.min.js +3 -0
- package/dist/chunks/send-DBpesydB.min.js.map +1 -0
- package/dist/chunks/transport-B21X39p4.min.js +3 -0
- package/dist/chunks/transport-B21X39p4.min.js.map +1 -0
- package/dist/cjs/core/attempts.js +1 -1
- package/dist/cjs/core/batch.js +4 -4
- package/dist/cjs/core/consent.d.ts +17 -4
- package/dist/cjs/core/consent.js +81 -14
- package/dist/cjs/core/console-call.d.ts +23 -0
- package/dist/cjs/core/console-call.js +63 -0
- package/dist/cjs/core/constants.d.ts +66 -17
- package/dist/cjs/core/constants.js +76 -19
- package/dist/cjs/core/db.js +31 -7
- package/dist/cjs/core/debug.d.ts +6 -4
- package/dist/cjs/core/debug.js +36 -12
- package/dist/cjs/core/env.d.ts +0 -3
- package/dist/cjs/core/env.js +1 -9
- package/dist/cjs/core/framework-id.d.ts +1 -1
- package/dist/cjs/core/framework-id.js +3 -3
- package/dist/cjs/core/guard.js +19 -4
- package/dist/cjs/core/hooks.d.ts +29 -0
- package/dist/cjs/core/hooks.js +12 -1
- package/dist/cjs/core/locks.js +1 -1
- package/dist/cjs/core/logger.js +1 -1
- package/dist/cjs/core/shield.d.ts +31 -0
- package/dist/cjs/core/shield.js +129 -0
- package/dist/cjs/core/state.d.ts +11 -5
- package/dist/cjs/core/state.js +4 -4
- package/dist/cjs/core/storage.d.ts +7 -0
- package/dist/cjs/core/storage.js +28 -9
- package/dist/cjs/core/stylesheet.js +1 -1
- package/dist/cjs/core/transport.d.ts +15 -4
- package/dist/cjs/core/transport.js +72 -25
- package/dist/cjs/core/utils.js +1 -1
- package/dist/cjs/core/validate.js +6 -5
- package/dist/cjs/device/appversion.d.ts +10 -1
- package/dist/cjs/device/appversion.js +26 -3
- package/dist/cjs/device/index.d.ts +17 -2
- package/dist/cjs/device/index.js +251 -35
- package/dist/cjs/engagement/api-rules.js +1 -1
- package/dist/cjs/engagement/auto-api.js +4 -3
- package/dist/cjs/engagement/auto-screen.js +10 -6
- package/dist/cjs/engagement/defined-events.d.ts +2 -3
- package/dist/cjs/engagement/defined-events.js +10 -16
- package/dist/cjs/engagement/send.js +7 -3
- package/dist/cjs/engagement/session.d.ts +17 -0
- package/dist/cjs/engagement/session.js +154 -23
- package/dist/cjs/engagement/track.d.ts +4 -4
- package/dist/cjs/engagement/track.js +23 -17
- package/dist/cjs/errors/send.js +2 -2
- package/dist/cjs/errors/track.d.ts +2 -1
- package/dist/cjs/errors/track.js +8 -5
- package/dist/cjs/feedback/controls.d.ts +36 -4
- package/dist/cjs/feedback/controls.js +302 -67
- package/dist/cjs/feedback/i18n/index.d.ts +31 -0
- package/dist/cjs/feedback/i18n/index.js +187 -0
- package/dist/cjs/feedback/i18n/strings.d.ts +9 -0
- package/dist/cjs/feedback/i18n/strings.js +8 -0
- package/dist/cjs/feedback/index.js +1 -1
- package/dist/cjs/feedback/logs.d.ts +3 -6
- package/dist/cjs/feedback/logs.js +12 -21
- package/dist/cjs/feedback/quartz.js +5 -2
- package/dist/cjs/feedback/send.d.ts +6 -3
- package/dist/cjs/feedback/send.js +59 -41
- package/dist/cjs/feedback/styles.js +2 -2
- package/dist/cjs/feedback/template.d.ts +4 -2
- package/dist/cjs/feedback/template.js +73 -44
- package/dist/cjs/feedback/ui.d.ts +47 -4
- package/dist/cjs/feedback/ui.js +351 -97
- package/dist/cjs/heatmap/send.d.ts +2 -0
- package/dist/cjs/heatmap/send.js +3 -5
- package/dist/cjs/heatmap/track.js +13 -9
- package/dist/cjs/index.d.ts +1 -2
- package/dist/cjs/index.js +55 -18
- package/dist/cjs/lifecycle.d.ts +13 -2
- package/dist/cjs/lifecycle.js +233 -118
- package/dist/cjs/pushnotification/display.d.ts +65 -0
- package/dist/cjs/pushnotification/display.js +112 -0
- package/dist/cjs/pushnotification/index.d.ts +20 -0
- package/dist/cjs/pushnotification/index.js +96 -0
- package/dist/cjs/pushnotification/kept-opens.d.ts +23 -0
- package/dist/cjs/pushnotification/kept-opens.js +64 -0
- package/dist/cjs/pushnotification/notify.d.ts +45 -0
- package/dist/cjs/pushnotification/notify.js +476 -0
- package/dist/cjs/pushnotification/payload.d.ts +65 -0
- package/dist/cjs/pushnotification/payload.js +279 -0
- package/dist/cjs/pushnotification/session.d.ts +46 -0
- package/dist/cjs/pushnotification/session.js +413 -0
- package/dist/cjs/pushnotification/stats.d.ts +45 -0
- package/dist/cjs/pushnotification/stats.js +244 -0
- package/dist/cjs/pushnotification/wms.d.ts +30 -0
- package/dist/cjs/pushnotification/wms.js +374 -0
- package/dist/cjs/remoteconfig/country.js +1 -1
- package/dist/cjs/remoteconfig/custom.js +4 -3
- package/dist/cjs/remoteconfig/evaluate.js +1 -1
- package/dist/cjs/remoteconfig/fetch.d.ts +17 -10
- package/dist/cjs/remoteconfig/fetch.js +146 -32
- package/dist/cjs/remoteconfig/index.d.ts +9 -5
- package/dist/cjs/remoteconfig/index.js +24 -32
- package/dist/cjs/remoteconfig/store.d.ts +15 -7
- package/dist/cjs/remoteconfig/store.js +68 -35
- package/dist/cjs/remoteconfig/tz-countries.js +1 -1
- package/dist/cjs/{core → remotelog}/callsite.d.ts +5 -4
- package/dist/cjs/{core → remotelog}/callsite.js +6 -5
- package/dist/cjs/remotelog/gate.js +1 -1
- package/dist/cjs/remotelog/logger.js +2 -2
- package/dist/cjs/remotelog/send.js +6 -5
- package/dist/cjs/remotelogger/index.js +1 -1
- package/dist/cjs/scheduler.d.ts +3 -1
- package/dist/cjs/scheduler.js +34 -25
- package/dist/cjs/sw/apptics-pn-sw.d.ts +83 -0
- package/dist/cjs/sw/timers.d.ts +44 -0
- package/dist/cjs/types.d.ts +90 -29
- package/dist/cjs/user/index.d.ts +7 -0
- package/dist/cjs/user/index.js +25 -3
- package/dist/esm/core/attempts.js +1 -1
- package/dist/esm/core/batch.js +4 -4
- package/dist/esm/core/consent.d.ts +17 -4
- package/dist/esm/core/consent.js +84 -20
- package/dist/esm/core/console-call.d.ts +23 -0
- package/dist/esm/core/console-call.js +60 -0
- package/dist/esm/core/constants.d.ts +66 -17
- package/dist/esm/core/constants.js +73 -20
- package/dist/esm/core/db.js +31 -7
- package/dist/esm/core/debug.d.ts +6 -4
- package/dist/esm/core/debug.js +37 -13
- package/dist/esm/core/env.d.ts +0 -3
- package/dist/esm/core/env.js +2 -9
- package/dist/esm/core/framework-id.d.ts +1 -1
- package/dist/esm/core/framework-id.js +3 -3
- package/dist/esm/core/guard.js +19 -4
- package/dist/esm/core/hooks.d.ts +29 -0
- package/dist/esm/core/hooks.js +12 -1
- package/dist/esm/core/locks.js +1 -1
- package/dist/esm/core/logger.js +1 -1
- package/dist/esm/core/shield.d.ts +31 -0
- package/dist/esm/core/shield.js +119 -0
- package/dist/esm/core/state.d.ts +11 -5
- package/dist/esm/core/state.js +4 -4
- package/dist/esm/core/storage.d.ts +7 -0
- package/dist/esm/core/storage.js +28 -11
- package/dist/esm/core/stylesheet.js +1 -1
- package/dist/esm/core/transport.d.ts +15 -4
- package/dist/esm/core/transport.js +73 -28
- package/dist/esm/core/utils.js +1 -1
- package/dist/esm/core/validate.js +6 -5
- package/dist/esm/device/appversion.d.ts +10 -1
- package/dist/esm/device/appversion.js +26 -4
- package/dist/esm/device/index.d.ts +17 -2
- package/dist/esm/device/index.js +255 -42
- package/dist/esm/engagement/api-rules.js +1 -1
- package/dist/esm/engagement/auto-api.js +4 -3
- package/dist/esm/engagement/auto-screen.js +10 -6
- package/dist/esm/engagement/defined-events.d.ts +2 -3
- package/dist/esm/engagement/defined-events.js +10 -16
- package/dist/esm/engagement/send.js +7 -3
- package/dist/esm/engagement/session.d.ts +17 -0
- package/dist/esm/engagement/session.js +152 -24
- package/dist/esm/engagement/track.d.ts +4 -4
- package/dist/esm/engagement/track.js +24 -18
- package/dist/esm/errors/send.js +2 -2
- package/dist/esm/errors/track.d.ts +2 -1
- package/dist/esm/errors/track.js +8 -5
- package/dist/esm/feedback/controls.d.ts +36 -4
- package/dist/esm/feedback/controls.js +298 -68
- package/dist/esm/feedback/i18n/index.d.ts +31 -0
- package/dist/esm/feedback/i18n/index.js +178 -0
- package/dist/esm/feedback/i18n/strings.d.ts +9 -0
- package/dist/esm/feedback/i18n/strings.js +4 -0
- package/dist/esm/feedback/index.js +1 -1
- package/dist/esm/feedback/logs.d.ts +3 -6
- package/dist/esm/feedback/logs.js +12 -21
- package/dist/esm/feedback/quartz.js +5 -2
- package/dist/esm/feedback/send.d.ts +6 -3
- package/dist/esm/feedback/send.js +61 -44
- package/dist/esm/feedback/styles.js +2 -2
- package/dist/esm/feedback/template.d.ts +4 -2
- package/dist/esm/feedback/template.js +73 -44
- package/dist/esm/feedback/ui.d.ts +47 -4
- package/dist/esm/feedback/ui.js +353 -99
- package/dist/esm/heatmap/send.d.ts +2 -0
- package/dist/esm/heatmap/send.js +3 -5
- package/dist/esm/heatmap/track.js +13 -9
- package/dist/esm/index.d.ts +1 -2
- package/dist/esm/index.js +58 -21
- package/dist/esm/lifecycle.d.ts +13 -2
- package/dist/esm/lifecycle.js +238 -125
- package/dist/esm/pushnotification/display.d.ts +65 -0
- package/dist/esm/pushnotification/display.js +95 -0
- package/dist/esm/pushnotification/index.d.ts +20 -0
- package/dist/esm/pushnotification/index.js +91 -0
- package/dist/esm/pushnotification/kept-opens.d.ts +23 -0
- package/dist/esm/pushnotification/kept-opens.js +62 -0
- package/dist/esm/pushnotification/notify.d.ts +45 -0
- package/dist/esm/pushnotification/notify.js +469 -0
- package/dist/esm/pushnotification/payload.d.ts +65 -0
- package/dist/esm/pushnotification/payload.js +272 -0
- package/dist/esm/pushnotification/session.d.ts +46 -0
- package/dist/esm/pushnotification/session.js +402 -0
- package/dist/esm/pushnotification/stats.d.ts +45 -0
- package/dist/esm/pushnotification/stats.js +238 -0
- package/dist/esm/pushnotification/wms.d.ts +30 -0
- package/dist/esm/pushnotification/wms.js +368 -0
- package/dist/esm/remoteconfig/country.js +1 -1
- package/dist/esm/remoteconfig/custom.js +4 -3
- package/dist/esm/remoteconfig/evaluate.js +1 -1
- package/dist/esm/remoteconfig/fetch.d.ts +17 -10
- package/dist/esm/remoteconfig/fetch.js +147 -33
- package/dist/esm/remoteconfig/index.d.ts +9 -5
- package/dist/esm/remoteconfig/index.js +24 -32
- package/dist/esm/remoteconfig/store.d.ts +15 -7
- package/dist/esm/remoteconfig/store.js +68 -36
- package/dist/esm/remoteconfig/tz-countries.js +1 -1
- package/dist/esm/{core → remotelog}/callsite.d.ts +5 -4
- package/dist/esm/{core → remotelog}/callsite.js +6 -5
- package/dist/esm/remotelog/gate.js +1 -1
- package/dist/esm/remotelog/logger.js +2 -2
- package/dist/esm/remotelog/send.js +6 -5
- package/dist/esm/remotelogger/index.js +1 -1
- package/dist/esm/scheduler.d.ts +3 -1
- package/dist/esm/scheduler.js +35 -27
- package/dist/esm/sw/apptics-pn-sw.d.ts +83 -0
- package/dist/esm/sw/timers.d.ts +44 -0
- package/dist/esm/types.d.ts +90 -29
- package/dist/esm/user/index.d.ts +7 -0
- package/dist/esm/user/index.js +26 -5
- package/dist/feedback.esm.min.js +2 -2
- package/dist/feedback.esm.min.js.map +1 -1
- package/dist/pushnotification.esm.min.js +3 -0
- package/dist/pushnotification.esm.min.js.map +1 -0
- package/dist/remoteconfig.esm.min.js +3 -0
- package/dist/remoteconfig.esm.min.js.map +1 -0
- package/dist/remotelogger.esm.min.js +3 -0
- package/dist/remotelogger.esm.min.js.map +1 -0
- package/package.json +17 -3
- package/dist/chunks/lifecycle-VYr43KcB.min.js +0 -3
- package/dist/chunks/lifecycle-VYr43KcB.min.js.map +0 -1
- package/dist/cjs/auto-init.d.ts +0 -8
- package/dist/cjs/auto-init.js +0 -32
- package/dist/esm/auto-init.d.ts +0 -8
- 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,95 @@
|
|
|
1
|
+
/*! @zoho_apptics/apptics-js-sdk v2.0.0 | (c) Zoho Corporation Private Limited | see LICENSE */
|
|
2
|
+
import { formatCountdown } from './payload.js';
|
|
3
|
+
|
|
4
|
+
/** What the service worker posts to the site's tabs. */
|
|
5
|
+
const CLICK_MESSAGE = 'apptics-notification-click'; // no i18n
|
|
6
|
+
const CLOSE_MESSAGE = 'apptics-notification-close'; // no i18n
|
|
7
|
+
/** Prev / Next pressed: the page stops that notification's auto-scroll, as the visitor took over. */
|
|
8
|
+
const STEP_MESSAGE = 'apptics-notification-step'; // no i18n
|
|
9
|
+
/** The worker gives back the timers it could not finish in its time: an open tab runs the rest. */
|
|
10
|
+
const HANDOFF_MESSAGE = 'apptics-notification-handoff'; // no i18n
|
|
11
|
+
/** What a tab posts to the service worker: run this notification's timers; stop them (one tag, or all). */
|
|
12
|
+
const TIMERS_MESSAGE = 'apptics-notification-timers'; // no i18n
|
|
13
|
+
const STOP_TIMERS_MESSAGE = 'apptics-notification-stop'; // no i18n
|
|
14
|
+
/** The worker's answer to TIMERS_MESSAGE, on the port it came with: it runs them. */
|
|
15
|
+
const TIMERS_TAKEN = 'apptics-notification-timers-taken'; // no i18n
|
|
16
|
+
const ACTION_PREV = 'apptics-prev'; // no i18n
|
|
17
|
+
const ACTION_NEXT = 'apptics-next'; // no i18n
|
|
18
|
+
const ACTION_BUTTON = 'apptics-btn-'; // no i18n
|
|
19
|
+
/** The browser's labels for the carousel's two buttons, as the console's preview shows them. */
|
|
20
|
+
const PREV_LABEL = 'Prev'; // no i18n
|
|
21
|
+
const NEXT_LABEL = 'Next'; // no i18n
|
|
22
|
+
function isCarousel(view) {
|
|
23
|
+
return view.images.length > 1;
|
|
24
|
+
}
|
|
25
|
+
/** The title shown for slide `index`: the slide number is added for a carousel. */
|
|
26
|
+
function titleFor(view, index) {
|
|
27
|
+
return isCarousel(view) ? view.title + ' (' + (index + 1) + ' / ' + view.images.length + ')' : view.title; // no i18n
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The options for showing `shown` at its slide. `update` is a re-show of one already on screen
|
|
31
|
+
* (a carousel step, a countdown tick): it makes no sound.
|
|
32
|
+
*/
|
|
33
|
+
function optionsFor(shown, update, nowMs) {
|
|
34
|
+
var view = shown.view;
|
|
35
|
+
var body = view.text;
|
|
36
|
+
if (view.countdownTo > 0) {
|
|
37
|
+
body += (body ? '\n' : '') + formatCountdown(view.countdownTo, nowMs); // no i18n
|
|
38
|
+
}
|
|
39
|
+
var options = {
|
|
40
|
+
body: body,
|
|
41
|
+
tag: shown.tag,
|
|
42
|
+
requireInteraction: view.requireInteraction,
|
|
43
|
+
silent: view.silent || update,
|
|
44
|
+
// a new message alerts even when it replaces one still on screen under the same tag (the
|
|
45
|
+
// same appticsPnID); the SDK's own updates (a slide, a countdown tick) replace it quietly
|
|
46
|
+
renotify: !update,
|
|
47
|
+
data: shown,
|
|
48
|
+
};
|
|
49
|
+
var image = view.images[shown.index] || view.images[0];
|
|
50
|
+
if (image && !supportsImage()) {
|
|
51
|
+
// no large image here (Chrome on macOS goes through the system's notifications, which have
|
|
52
|
+
// no slot for one): the slide shows as the icon, so a carousel still visibly changes
|
|
53
|
+
options.icon = image;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
if (view.icon) {
|
|
57
|
+
options.icon = view.icon;
|
|
58
|
+
}
|
|
59
|
+
if (image) {
|
|
60
|
+
options.image = image;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (isCarousel(view)) {
|
|
64
|
+
options.actions = [{ action: ACTION_PREV, title: PREV_LABEL }, { action: ACTION_NEXT, title: NEXT_LABEL }];
|
|
65
|
+
}
|
|
66
|
+
else if (view.buttons.length > 0) {
|
|
67
|
+
options.actions = view.buttons.map(function (b, i) {
|
|
68
|
+
var action = { action: ACTION_BUTTON + i, title: b.label };
|
|
69
|
+
if (b.icon) {
|
|
70
|
+
action.icon = b.icon;
|
|
71
|
+
}
|
|
72
|
+
return action;
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return options;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Whether this browser shows a notification's large image. Notification.prototype has `image`
|
|
79
|
+
* where it does; Chrome on macOS has none. Asked the same way in the page and the worker.
|
|
80
|
+
*/
|
|
81
|
+
function supportsImage() {
|
|
82
|
+
var N = typeof Notification !== 'undefined' ? Notification : undefined; // no i18n
|
|
83
|
+
return !N || !N.prototype || 'image' in N.prototype; // no i18n
|
|
84
|
+
}
|
|
85
|
+
/** Whether a notification's data is one the SDK showed. */
|
|
86
|
+
function isOurs(data) {
|
|
87
|
+
return !!data && typeof data === 'object' && data.apptics === 1; // no i18n
|
|
88
|
+
}
|
|
89
|
+
/** The slide after `index` by `step` (+1 / -1), wrapping. */
|
|
90
|
+
function stepIndex(view, index, step) {
|
|
91
|
+
var n = view.images.length;
|
|
92
|
+
return n > 0 ? ((index + step) % n + n) % n : 0;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export { ACTION_BUTTON, ACTION_NEXT, ACTION_PREV, CLICK_MESSAGE, CLOSE_MESSAGE, HANDOFF_MESSAGE, STEP_MESSAGE, STOP_TIMERS_MESSAGE, TIMERS_MESSAGE, TIMERS_TAKEN, isCarousel, isOurs, optionsFor, stepIndex, supportsImage, 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,91 @@
|
|
|
1
|
+
/*! @zoho_apptics/apptics-js-sdk v2.0.0 | (c) Zoho Corporation Private Limited | see LICENSE */
|
|
2
|
+
import { forward, guard } from '../core/guard.js';
|
|
3
|
+
import { warnAlways } from '../core/logger.js';
|
|
4
|
+
import { currentSession, whenStarted, registerPush, unregisterPush } from './session.js';
|
|
5
|
+
import './wms.js';
|
|
6
|
+
import { requestPermission as requestPermission$1 } from './notify.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Push notification, shipped as its own entry point:
|
|
10
|
+
* import { AppticsPushNotification } from '@zoho_apptics/apptics-js-sdk/push-notification';
|
|
11
|
+
*
|
|
12
|
+
* Importing it is enough for the SDK to register this browser on its own, whenever the console
|
|
13
|
+
* has push on for the app: getsdkconfig is asked about module 16, and its answer says where
|
|
14
|
+
* wmsliteapi.js loads from. Messages arrive over WMS while the page is open, and each shows as a
|
|
15
|
+
* browser notification.
|
|
16
|
+
*
|
|
17
|
+
* The visitor sees a browser notification for each message once they allow it, which
|
|
18
|
+
* requestPermission() asks for: call it from a click, as browsers require. A click on one focuses
|
|
19
|
+
* the tab and opens the message's url.
|
|
20
|
+
*
|
|
21
|
+
* setEnabled(true) registers by hand, and also undoes an earlier setEnabled(false), which
|
|
22
|
+
* otherwise holds across visits. While tracking is anonymous the browser registers by its
|
|
23
|
+
* anonymous id; with no tracking it does not register at all.
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* true registers this browser (and undoes an earlier false); false unregisters it, held across
|
|
27
|
+
* visits until true. Resolves true once done, false when it can't be (push off for the app, or
|
|
28
|
+
* the SDK didn't start).
|
|
29
|
+
*/
|
|
30
|
+
function setEnabled(enabled) {
|
|
31
|
+
if (enabled !== true && enabled !== false) {
|
|
32
|
+
warnAlways('AppticsPushNotification.setEnabled: takes true (register this browser) or false (unregister it)'); // no i18n
|
|
33
|
+
return Promise.resolve(false);
|
|
34
|
+
}
|
|
35
|
+
return whenStarted().then(function (running) {
|
|
36
|
+
if (!running) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
return enabled ? registerPush(true).then(function (session) { return session !== null; }) : unregisterPush();
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
function isEnabled() {
|
|
43
|
+
return currentSession() !== null;
|
|
44
|
+
}
|
|
45
|
+
function requestPermission() {
|
|
46
|
+
return requestPermission$1();
|
|
47
|
+
}
|
|
48
|
+
// function onNotificationClick(callback: (click: NotificationClick) => void): () => void {
|
|
49
|
+
// if (typeof callback !== 'function') { // no i18n
|
|
50
|
+
// warnAlways('AppticsPushNotification.onNotificationClick: takes a function, called with the clicked message\'s data'); // no i18n
|
|
51
|
+
// return function () {};
|
|
52
|
+
// }
|
|
53
|
+
// return addClickListener(callback);
|
|
54
|
+
// }
|
|
55
|
+
const setEnabledGuarded = guard('AppticsPushNotification.setEnabled', setEnabled); // no i18n
|
|
56
|
+
const isEnabledGuarded = guard('AppticsPushNotification.isEnabled', isEnabled); // no i18n
|
|
57
|
+
const requestPermissionGuarded = guard('AppticsPushNotification.requestPermission', requestPermission); // no i18n
|
|
58
|
+
// const onNotificationClickGuarded = guard('AppticsPushNotification.onNotificationClick', onNotificationClick); // no i18n
|
|
59
|
+
/** AppticsPushNotification: setEnabled, isEnabled, and the browser notification's requestPermission. */
|
|
60
|
+
const AppticsPushNotification = {
|
|
61
|
+
/**
|
|
62
|
+
* setEnabled(true) registers this browser for push now; setEnabled(false) unregisters it and
|
|
63
|
+
* keeps it unregistered across visits until setEnabled(true). Resolves true once done, false
|
|
64
|
+
* when push is off for the app in the console.
|
|
65
|
+
*/
|
|
66
|
+
setEnabled: function setEnabled(enabled) {
|
|
67
|
+
return forward(setEnabledGuarded, arguments);
|
|
68
|
+
},
|
|
69
|
+
/** Whether this browser holds a push session now. */
|
|
70
|
+
isEnabled: function isEnabled() {
|
|
71
|
+
return forward(isEnabledGuarded, arguments);
|
|
72
|
+
},
|
|
73
|
+
/**
|
|
74
|
+
* Asks the visitor to allow browser notifications; call it from a click. Resolves with
|
|
75
|
+
* 'granted', 'denied', 'default' (dismissed) or 'unsupported'. Once granted, each message is
|
|
76
|
+
* also shown as a notification while a tab of the site is open.
|
|
77
|
+
*/
|
|
78
|
+
requestPermission: function requestPermission() {
|
|
79
|
+
return forward(requestPermissionGuarded, arguments);
|
|
80
|
+
},
|
|
81
|
+
// /**
|
|
82
|
+
// * Calls `callback` when the visitor clicks a notification, with { action, appticsPnID,
|
|
83
|
+
// * additional, data }: the button's action id ('' for the body), the message's id and its
|
|
84
|
+
// * additional key-values, and the message's data. Returns the function that stops it.
|
|
85
|
+
// */
|
|
86
|
+
// onNotificationClick: function onNotificationClick(callback: (click: NotificationClick) => void): () => void {
|
|
87
|
+
// return forward(onNotificationClickGuarded, arguments);
|
|
88
|
+
// },
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export { AppticsPushNotification, AppticsPushNotification as default };
|
|
@@ -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,62 @@
|
|
|
1
|
+
/*! @zoho_apptics/apptics-js-sdk v2.0.0 | (c) Zoho Corporation Private Limited | see LICENSE */
|
|
2
|
+
/**
|
|
3
|
+
* Opens the service worker couldn't hand to a tab of the site: the click opened another site, and
|
|
4
|
+
* no tab of this one was open. The worker keeps them in IndexedDB (apptics-push / opens), which the
|
|
5
|
+
* page shares, and the SDK sends them as opened stats on the next visit.
|
|
6
|
+
*/
|
|
7
|
+
const DB_NAME = 'apptics-push'; // no i18n
|
|
8
|
+
const STORE = 'opens'; // no i18n
|
|
9
|
+
function idb() {
|
|
10
|
+
return typeof indexedDB !== 'undefined' ? indexedDB : undefined; // no i18n
|
|
11
|
+
}
|
|
12
|
+
function openDb() {
|
|
13
|
+
var factory = idb();
|
|
14
|
+
if (!factory) {
|
|
15
|
+
return Promise.resolve(null);
|
|
16
|
+
}
|
|
17
|
+
return new Promise(function (resolve) {
|
|
18
|
+
try {
|
|
19
|
+
var req = factory.open(DB_NAME, 1);
|
|
20
|
+
req.onupgradeneeded = function () {
|
|
21
|
+
if (!req.result.objectStoreNames.contains(STORE)) {
|
|
22
|
+
req.result.createObjectStore(STORE, { autoIncrement: true });
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
req.onsuccess = function () { resolve(req.result); };
|
|
26
|
+
req.onerror = function () { resolve(null); };
|
|
27
|
+
req.onblocked = function () { resolve(null); };
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
resolve(null);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/** Takes every kept open out of the store, in one transaction, so two tabs can't both send one. */
|
|
35
|
+
function takeOpens() {
|
|
36
|
+
return openDb().then(function (db) {
|
|
37
|
+
if (!db) {
|
|
38
|
+
return [];
|
|
39
|
+
}
|
|
40
|
+
return new Promise(function (resolve) {
|
|
41
|
+
try {
|
|
42
|
+
var tx = db.transaction(STORE, 'readwrite'); // no i18n
|
|
43
|
+
var store = tx.objectStore(STORE);
|
|
44
|
+
var got = [];
|
|
45
|
+
var all = store.getAll();
|
|
46
|
+
all.onsuccess = function () {
|
|
47
|
+
got = all.result;
|
|
48
|
+
store.clear();
|
|
49
|
+
};
|
|
50
|
+
tx.oncomplete = function () { db.close(); resolve(got); };
|
|
51
|
+
tx.onerror = function () { db.close(); resolve([]); };
|
|
52
|
+
tx.onabort = function () { db.close(); resolve([]); };
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
db.close();
|
|
56
|
+
resolve([]);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export { 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 {};
|