@zoho_apptics/apptics-js-sdk 2.0.0-beta.2 → 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 +47 -0
- package/README.md +229 -174
- 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 -3
- package/dist/cjs/core/consent.d.ts +9 -6
- package/dist/cjs/core/consent.js +63 -10
- 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 +44 -0
- package/dist/cjs/core/constants.js +55 -1
- 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.js +1 -1
- 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 +25 -1
- package/dist/cjs/core/hooks.js +11 -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 +5 -1
- package/dist/cjs/core/state.js +3 -1
- package/dist/cjs/core/storage.d.ts +7 -0
- package/dist/cjs/core/storage.js +28 -6
- package/dist/cjs/core/stylesheet.js +1 -1
- package/dist/cjs/core/transport.d.ts +15 -4
- package/dist/cjs/core/transport.js +63 -13
- package/dist/cjs/core/utils.js +1 -1
- package/dist/cjs/core/validate.js +6 -5
- package/dist/cjs/device/appversion.js +1 -1
- package/dist/cjs/device/index.js +63 -15
- 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 +1 -1
- package/dist/cjs/engagement/session.js +77 -37
- package/dist/cjs/engagement/track.js +9 -6
- package/dist/cjs/errors/send.js +1 -1
- package/dist/cjs/errors/track.js +3 -2
- package/dist/cjs/feedback/controls.d.ts +30 -4
- package/dist/cjs/feedback/controls.js +237 -51
- 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.js +5 -4
- package/dist/cjs/feedback/quartz.js +5 -2
- package/dist/cjs/feedback/send.d.ts +4 -1
- package/dist/cjs/feedback/send.js +56 -15
- package/dist/cjs/feedback/styles.js +2 -2
- package/dist/cjs/feedback/template.d.ts +4 -2
- package/dist/cjs/feedback/template.js +67 -46
- package/dist/cjs/feedback/ui.d.ts +40 -4
- package/dist/cjs/feedback/ui.js +208 -89
- package/dist/cjs/heatmap/send.js +1 -1
- package/dist/cjs/heatmap/track.js +13 -9
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/lifecycle.js +119 -72
- 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.js +27 -8
- package/dist/cjs/remoteconfig/index.d.ts +1 -6
- package/dist/cjs/remoteconfig/index.js +4 -28
- package/dist/cjs/remoteconfig/store.js +1 -1
- package/dist/cjs/remoteconfig/tz-countries.js +1 -1
- package/dist/cjs/remotelog/callsite.js +1 -1
- package/dist/cjs/remotelog/gate.js +1 -1
- package/dist/cjs/remotelog/logger.js +1 -1
- package/dist/cjs/remotelog/send.js +5 -4
- package/dist/cjs/remotelogger/index.js +1 -1
- package/dist/cjs/scheduler.js +11 -5
- 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 +31 -15
- package/dist/cjs/user/index.d.ts +7 -0
- package/dist/cjs/user/index.js +25 -7
- package/dist/esm/core/attempts.js +1 -1
- package/dist/esm/core/batch.js +4 -3
- package/dist/esm/core/consent.d.ts +9 -6
- package/dist/esm/core/consent.js +67 -16
- 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 +44 -0
- package/dist/esm/core/constants.js +52 -2
- 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.js +1 -1
- 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 +25 -1
- package/dist/esm/core/hooks.js +11 -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 +5 -1
- package/dist/esm/core/state.js +3 -1
- package/dist/esm/core/storage.d.ts +7 -0
- package/dist/esm/core/storage.js +28 -8
- package/dist/esm/core/stylesheet.js +1 -1
- package/dist/esm/core/transport.d.ts +15 -4
- package/dist/esm/core/transport.js +64 -16
- package/dist/esm/core/utils.js +1 -1
- package/dist/esm/core/validate.js +6 -5
- package/dist/esm/device/appversion.js +1 -1
- package/dist/esm/device/index.js +67 -19
- 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 +1 -1
- package/dist/esm/engagement/session.js +77 -37
- package/dist/esm/engagement/track.js +9 -6
- package/dist/esm/errors/send.js +1 -1
- package/dist/esm/errors/track.js +3 -2
- package/dist/esm/feedback/controls.d.ts +30 -4
- package/dist/esm/feedback/controls.js +234 -52
- 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.js +5 -4
- package/dist/esm/feedback/quartz.js +5 -2
- package/dist/esm/feedback/send.d.ts +4 -1
- package/dist/esm/feedback/send.js +56 -16
- package/dist/esm/feedback/styles.js +2 -2
- package/dist/esm/feedback/template.d.ts +4 -2
- package/dist/esm/feedback/template.js +67 -46
- package/dist/esm/feedback/ui.d.ts +40 -4
- package/dist/esm/feedback/ui.js +210 -91
- package/dist/esm/heatmap/send.js +1 -1
- package/dist/esm/heatmap/track.js +13 -9
- package/dist/esm/index.js +2 -2
- package/dist/esm/lifecycle.js +120 -73
- 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.js +27 -8
- package/dist/esm/remoteconfig/index.d.ts +1 -6
- package/dist/esm/remoteconfig/index.js +4 -28
- package/dist/esm/remoteconfig/store.js +1 -1
- package/dist/esm/remoteconfig/tz-countries.js +1 -1
- package/dist/esm/remotelog/callsite.js +1 -1
- package/dist/esm/remotelog/gate.js +1 -1
- package/dist/esm/remotelog/logger.js +1 -1
- package/dist/esm/remotelog/send.js +5 -4
- package/dist/esm/remotelogger/index.js +1 -1
- package/dist/esm/scheduler.js +11 -5
- 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 +31 -15
- package/dist/esm/user/index.d.ts +7 -0
- package/dist/esm/user/index.js +26 -9
- 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 +2 -2
- package/dist/remoteconfig.esm.min.js.map +1 -1
- package/dist/remotelogger.esm.min.js +2 -2
- package/dist/remotelogger.esm.min.js.map +1 -1
- package/package.json +15 -2
- package/dist/chunks/lifecycle-C6m1W7jo.min.js +0 -3
- package/dist/chunks/lifecycle-C6m1W7jo.min.js.map +0 -1
- package/dist/chunks/send-CgUO82ne.min.js +0 -3
- package/dist/chunks/send-CgUO82ne.min.js.map +0 -1
|
@@ -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 {};
|