@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,30 @@
|
|
|
1
|
+
import type { PushSession } from './session.js';
|
|
2
|
+
type Message = Record<string, unknown>;
|
|
3
|
+
/** A message as the key-value object it carries, or null when it is not a JSON object. */
|
|
4
|
+
export declare function decodeMessage(msg: unknown): Message | null;
|
|
5
|
+
/**
|
|
6
|
+
* Adds a listener for each message's key-value object. The first one also gets the messages that
|
|
7
|
+
* arrived before it. Returns the function that removes it.
|
|
8
|
+
*/
|
|
9
|
+
export declare function addMessageListener(fn: (data: Message) => void): () => void;
|
|
10
|
+
/**
|
|
11
|
+
* Whether `hostname` is a Zoho-owned application domain, where WMS reaches its servers as
|
|
12
|
+
* zmp-wms.<domain>. Anything else is a custom domain to WMS: its requests go to the site's own
|
|
13
|
+
* /wmssrv, which the site must route to WMS.
|
|
14
|
+
*/
|
|
15
|
+
export declare function isZohoDomain(hostname: string): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* The origin WMS's cross-origin flow loads its connector from (<origin>/wms/pconnect.sas): base_url's
|
|
18
|
+
* own host when that is a Zoho domain (apptics.zoho.in, preapptics.zoho.in, apptics.localzoho.com),
|
|
19
|
+
* else the US one. With the scheme: WmsLite puts it before the path as it is, so a bare host would
|
|
20
|
+
* load the frame from the page's own site.
|
|
21
|
+
*/
|
|
22
|
+
export declare function crossOriginHost(serviceUrl: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* Connects `session` to WMS, loading wmsliteapi.js the first time. A load that failed is tried
|
|
25
|
+
* again only when the app asked (`manual`), never on its own.
|
|
26
|
+
*/
|
|
27
|
+
export declare function connect(session: PushSession, manual?: boolean): void;
|
|
28
|
+
/** Stops delivering this session's messages, closing the connection where WmsLite can. */
|
|
29
|
+
export declare function disconnect(): void;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
/*! @zoho_apptics/apptics-js-sdk v2.0.0 | (c) Zoho Corporation Private Limited | see LICENSE */
|
|
2
|
+
import { _ZAP } from '../core/state.js';
|
|
3
|
+
import { Console, warnAlways } from '../core/logger.js';
|
|
4
|
+
import { nowMs } from '../core/utils.js';
|
|
5
|
+
import { setSessionListener, sessionConnected, sessionRefused } from './session.js';
|
|
6
|
+
import { stopAllNotifications, showNotification } from './notify.js';
|
|
7
|
+
import { recordStat, STATUS } from './stats.js';
|
|
8
|
+
import { webNotificationFrom } from './payload.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The WMS connection a push session is delivered over: wmsliteapi.js, loaded from getsdkconfig's
|
|
12
|
+
* wms_js_url with its SRI hash, connected with WmsLite.registerAnnon, and called back on
|
|
13
|
+
* window.WmsliteImpl. Each message is key-value JSON for the app, handed to every listener.
|
|
14
|
+
*
|
|
15
|
+
* WmsLite and WmsliteImpl are the page's globals: a Zoho product page may use WMS itself. Its
|
|
16
|
+
* callbacks are kept, and every message that is not for this session's product goes to them. A
|
|
17
|
+
* WmsLite the page loaded is never disabled: only one this SDK loaded.
|
|
18
|
+
*
|
|
19
|
+
* wmsliteapi.js also declares a global `function push`, which its frame calls to deliver
|
|
20
|
+
* messages: a page with a top-level `let`, `const` or `class` named push stops it loading.
|
|
21
|
+
*/
|
|
22
|
+
const LABEL = 'AppticsPushNotification'; // no i18n
|
|
23
|
+
/** The shortest wait between two registers after WMS refused the session's token. */
|
|
24
|
+
const AUTH_RETRY_MS = 60000;
|
|
25
|
+
const DEFAULT_DISPLAY_NAME = 'Apptics Web Device'; // no i18n
|
|
26
|
+
var active = null;
|
|
27
|
+
/** The session WmsLite was last registered with, so the same one is not registered twice. */
|
|
28
|
+
var connectedSessionId = ''; // no i18n
|
|
29
|
+
var scriptState = 'none'; // no i18n
|
|
30
|
+
/** Whether the WmsLite in use is the one this SDK loaded, the only one it may close. */
|
|
31
|
+
var loadedByUs = false;
|
|
32
|
+
/** Set while a page handler runs, so a page that wrapped ours cannot send a message round again. */
|
|
33
|
+
var inPrevious = false;
|
|
34
|
+
var warnedLoadFailure = false;
|
|
35
|
+
var lastAuthRetry = -Infinity;
|
|
36
|
+
var listeners = [];
|
|
37
|
+
/** The page's own WmsliteImpl callbacks, from before ours went on. */
|
|
38
|
+
var previous = {};
|
|
39
|
+
var installed = {};
|
|
40
|
+
function wmsLite() {
|
|
41
|
+
var api = window.WmsLite;
|
|
42
|
+
return api && typeof api.registerAnnon === 'function' ? api : undefined; // no i18n
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Calls the page's own callback, on WmsliteImpl as WMS would. What it throws is the page's, kept
|
|
46
|
+
* from stopping ours; a page handler that calls back into ours is not sent round again.
|
|
47
|
+
*/
|
|
48
|
+
function callPrevious(name, args) {
|
|
49
|
+
var fn = previous[name];
|
|
50
|
+
if (typeof fn !== 'function' || inPrevious) { // no i18n
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
inPrevious = true;
|
|
54
|
+
try {
|
|
55
|
+
fn.apply(window.WmsliteImpl, args);
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
Console.warn(LABEL + ': the page\'s WmsliteImpl.' + name + ' threw', err); // no i18n
|
|
59
|
+
}
|
|
60
|
+
finally {
|
|
61
|
+
inPrevious = false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/** \xNN and \uNNNN escapes, as WMS can send a message, back to their characters. */
|
|
65
|
+
function unescape(text) {
|
|
66
|
+
return text.replace(/\\x([0-9A-Fa-f]{2})|\\u([0-9A-Fa-f]{4})/g, function (_match, hex, uni) {
|
|
67
|
+
return String.fromCharCode(parseInt(hex || uni, 16));
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Drops the backslash of an escape JSON doesn't have (WMS sends - as \-), keeping \\ and the
|
|
72
|
+
* escapes JSON allows (\" \\ \/ \b \f \n \r \t \uNNNN) as they are.
|
|
73
|
+
*/
|
|
74
|
+
function dropInvalidEscapes(text) {
|
|
75
|
+
return text.replace(/\\(\\|["\/bfnrtu]|.)/g, function (match, next) {
|
|
76
|
+
return next === '\\' || '"/bfnrtu'.indexOf(next) !== -1 ? match : next; // no i18n
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
function isPlainObject(value) {
|
|
80
|
+
return !!value && typeof value === 'object' && !Array.isArray(value); // no i18n
|
|
81
|
+
}
|
|
82
|
+
/** A message as the key-value object it carries, or null when it is not a JSON object. */
|
|
83
|
+
function decodeMessage(msg) {
|
|
84
|
+
if (isPlainObject(msg)) {
|
|
85
|
+
return msg;
|
|
86
|
+
}
|
|
87
|
+
if (typeof msg !== 'string') { // no i18n
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
// valid JSON as it came; only text that is not gets its \x and \u escapes undone first, and
|
|
91
|
+
// then the backslash dropped from escapes JSON doesn't have (\- in a URL or text)
|
|
92
|
+
var parsed = parseJson(msg);
|
|
93
|
+
if (parsed === undefined) {
|
|
94
|
+
parsed = parseJson(unescape(msg));
|
|
95
|
+
}
|
|
96
|
+
if (parsed === undefined) {
|
|
97
|
+
parsed = parseJson(dropInvalidEscapes(unescape(msg)));
|
|
98
|
+
}
|
|
99
|
+
return isPlainObject(parsed) ? parsed : null;
|
|
100
|
+
}
|
|
101
|
+
function parseJson(text) {
|
|
102
|
+
try {
|
|
103
|
+
return JSON.parse(text);
|
|
104
|
+
}
|
|
105
|
+
catch (e) {
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function deliver(data) {
|
|
110
|
+
if (listeners.length === 0) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
listeners.slice().forEach(function (fn) {
|
|
114
|
+
try {
|
|
115
|
+
fn(data);
|
|
116
|
+
}
|
|
117
|
+
catch (err) {
|
|
118
|
+
Console.warn(LABEL + ': a message listener threw', err); // no i18n
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
function handleMessage(mtype, msg, _meta, prd) {
|
|
123
|
+
if (active === null || String(prd) !== active.prdId) {
|
|
124
|
+
// exactly as WMS called it: the page's handler sees what it would without us
|
|
125
|
+
callPrevious('handleMessage', Array.prototype.slice.call(arguments)); // no i18n
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
// WMS's control messages come with a negative mtype (-3 Re-Register, after each reconnect):
|
|
129
|
+
// not a push, not shown
|
|
130
|
+
if (Number(mtype) < 0) {
|
|
131
|
+
Console.log(LABEL + ': a WMS control message (mtype ' + String(mtype) + ') was ignored'); // no i18n
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
var decoded = decodeMessage(msg);
|
|
135
|
+
if (decoded === null) {
|
|
136
|
+
Console.log(LABEL + ': a message that is not a JSON object was dropped'); // no i18n
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
// the server wraps the console's key-value data as { type, module, action, timestamp, data }
|
|
140
|
+
var envelope = isEnvelope(decoded) ? decoded : null;
|
|
141
|
+
var data = envelope ? envelope.data : decoded;
|
|
142
|
+
// WMS sends a new session messages of its own ({ ac, uctime, uc }): not a push, not shown
|
|
143
|
+
if (!envelope && isWmsOwn(data)) {
|
|
144
|
+
Console.log(LABEL + ': a WMS message that is not a push was ignored'); // no i18n
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
// received: counted whether or not a notification can be shown
|
|
148
|
+
var view = webNotificationFrom(data);
|
|
149
|
+
// a recurring push repeats its appticsPnID: the envelope's send time tells the runs apart
|
|
150
|
+
var run = envelope && (typeof envelope.timestamp === 'number' || typeof envelope.timestamp === 'string') ? String(envelope.timestamp) : undefined; // no i18n
|
|
151
|
+
recordStat({ id: view.id, number: view.number, run: run }, STATUS.RECEIVED);
|
|
152
|
+
deliver(data);
|
|
153
|
+
showNotification(data, envelope ? envelope.timestamp : undefined);
|
|
154
|
+
}
|
|
155
|
+
/** The keys of the message WMS sends each new session on its own ({ ac, uctime, uc }). */
|
|
156
|
+
const WMS_OWN_KEYS = ['ac', 'uc', 'uctime']; // no i18n
|
|
157
|
+
/** WMS's own session message: every key one of its own. Custom key-value data is kept. */
|
|
158
|
+
function isWmsOwn(value) {
|
|
159
|
+
var keys = Object.keys(value);
|
|
160
|
+
return keys.length > 0 && keys.every(function (k) { return WMS_OWN_KEYS.indexOf(k) !== -1; });
|
|
161
|
+
}
|
|
162
|
+
function isEnvelope(value) {
|
|
163
|
+
return isPlainObject(value.data) && (value.type !== undefined || value.module !== undefined);
|
|
164
|
+
}
|
|
165
|
+
function handleAuthFailure() {
|
|
166
|
+
callPrevious('handleAuthFailure', Array.prototype.slice.call(arguments)); // no i18n
|
|
167
|
+
if (active === null || nowMs() - lastAuthRetry < AUTH_RETRY_MS) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
lastAuthRetry = nowMs();
|
|
171
|
+
sessionRefused();
|
|
172
|
+
}
|
|
173
|
+
/** Puts our callbacks on window.WmsliteImpl, keeping whatever the page had there. */
|
|
174
|
+
function installCallbacks() {
|
|
175
|
+
var win = window;
|
|
176
|
+
// the page's object, or wmsliteapi.js's own `function WmsliteImpl(){}` with its defaults:
|
|
177
|
+
// decorated in place, so whatever else is on it stays
|
|
178
|
+
var current = win.WmsliteImpl;
|
|
179
|
+
var impl = current && (typeof current === 'object' || typeof current === 'function') ? current : {}; // no i18n
|
|
180
|
+
win.WmsliteImpl = impl;
|
|
181
|
+
var ours = {
|
|
182
|
+
serverup: function () { Console.log(LABEL + ': WMS connected'); sessionConnected(); callPrevious('serverup', Array.prototype.slice.call(arguments)); }, // no i18n
|
|
183
|
+
serverdown: function () { Console.log(LABEL + ': WMS disconnected'); callPrevious('serverdown', Array.prototype.slice.call(arguments)); }, // no i18n
|
|
184
|
+
connectionup: function () { callPrevious('connectionup', Array.prototype.slice.call(arguments)); }, // no i18n
|
|
185
|
+
handleMessage: handleMessage,
|
|
186
|
+
handleAuthFailure: handleAuthFailure,
|
|
187
|
+
};
|
|
188
|
+
Object.keys(ours).forEach(function (name) {
|
|
189
|
+
if (impl[name] === installed[name] && installed[name] !== undefined) {
|
|
190
|
+
return; // already ours
|
|
191
|
+
}
|
|
192
|
+
previous[name] = typeof impl[name] === 'function' ? impl[name] : undefined; // no i18n
|
|
193
|
+
impl[name] = ours[name];
|
|
194
|
+
installed[name] = ours[name];
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
/** The labels a Zoho-owned domain is named by, before its top-level domain: zoho.com, zohocloud.ca, localzoho.com. */
|
|
198
|
+
const ZOHO_LABELS = ['zoho', 'zohocloud', 'localzoho']; // no i18n
|
|
199
|
+
/** Zoho-owned domains named otherwise, matched with their subdomains. */
|
|
200
|
+
const ZOHO_DOMAINS = ['arattai.in', 'charmtracker.com']; // no i18n
|
|
201
|
+
/**
|
|
202
|
+
* Whether `hostname` is a Zoho-owned application domain, where WMS reaches its servers as
|
|
203
|
+
* zmp-wms.<domain>. Anything else is a custom domain to WMS: its requests go to the site's own
|
|
204
|
+
* /wmssrv, which the site must route to WMS.
|
|
205
|
+
*/
|
|
206
|
+
function isZohoDomain(hostname) {
|
|
207
|
+
var host = String(hostname || '').toLowerCase().replace(/\.$/, ''); // no i18n
|
|
208
|
+
for (var d = 0; d < ZOHO_DOMAINS.length; d++) {
|
|
209
|
+
if (host === ZOHO_DOMAINS[d] || host.slice(-(ZOHO_DOMAINS[d].length + 1)) === '.' + ZOHO_DOMAINS[d]) { // no i18n
|
|
210
|
+
return true;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
var labels = host.split('.'); // no i18n
|
|
214
|
+
for (var i = 0; i < labels.length - 1; i++) {
|
|
215
|
+
if (ZOHO_LABELS.indexOf(labels[i]) === -1) {
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
// what follows is the top-level domain: one label (zoho.eu), or com/co and one (zoho.com.au)
|
|
219
|
+
var rest = labels.slice(i + 1);
|
|
220
|
+
if (rest.length === 1 || (rest.length === 2 && (rest[0] === 'com' || rest[0] === 'co'))) { // no i18n
|
|
221
|
+
return true;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
/** The Apptics host US apps' WMS connector loads from, and the one used when base_url names no Zoho host. */
|
|
227
|
+
const DEFAULT_CROSS_ORIGIN_HOST = 'https://apptics.zoho.com'; // no i18n
|
|
228
|
+
/**
|
|
229
|
+
* The origin WMS's cross-origin flow loads its connector from (<origin>/wms/pconnect.sas): base_url's
|
|
230
|
+
* own host when that is a Zoho domain (apptics.zoho.in, preapptics.zoho.in, apptics.localzoho.com),
|
|
231
|
+
* else the US one. With the scheme: WmsLite puts it before the path as it is, so a bare host would
|
|
232
|
+
* load the frame from the page's own site.
|
|
233
|
+
*/
|
|
234
|
+
function crossOriginHost(serviceUrl) {
|
|
235
|
+
try {
|
|
236
|
+
var host = new URL(serviceUrl).hostname.toLowerCase();
|
|
237
|
+
return isZohoDomain(host) ? 'https://' + host : DEFAULT_CROSS_ORIGIN_HOST; // no i18n
|
|
238
|
+
}
|
|
239
|
+
catch (e) {
|
|
240
|
+
return DEFAULT_CROSS_ORIGIN_HOST;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
function registerWithWms(session) {
|
|
244
|
+
var api = wmsLite();
|
|
245
|
+
if (!api || connectedSessionId === session.sessionID) {
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
var wms = _ZAP._wmsConfig;
|
|
249
|
+
try {
|
|
250
|
+
// a disable() of ours is undone only by the script's own start: undo it before connecting
|
|
251
|
+
if (loadedByUs && api.disablewms === true) {
|
|
252
|
+
api.disablewms = false;
|
|
253
|
+
}
|
|
254
|
+
if (wms && wms.wms_sri_values && typeof api.setClientSRIValues === 'function') { // no i18n
|
|
255
|
+
api.setClientSRIValues(wms.wms_sri_values);
|
|
256
|
+
}
|
|
257
|
+
// as the WMS docs and the reference page do; this wmsliteapi.js already starts with it on
|
|
258
|
+
if (typeof api.setNoDomainChange === 'function') { // no i18n
|
|
259
|
+
api.setNoDomainChange();
|
|
260
|
+
}
|
|
261
|
+
// a customer's own site. Only on a WmsLite this SDK loaded, since the setting is the whole page's
|
|
262
|
+
if (loadedByUs && !isZohoDomain(window.location.hostname)) {
|
|
263
|
+
if (typeof api.allowCrossOrigin === 'function') { // no i18n
|
|
264
|
+
// WMS's cross-origin flow, for anonymous sessions ($ ids): its connector loads from
|
|
265
|
+
// the Apptics host, so the site needs no /wmssrv of its own
|
|
266
|
+
api.allowCrossOrigin(crossOriginHost(String(_ZAP._defaultoptions.serviceUrl || ''))); // no i18n
|
|
267
|
+
}
|
|
268
|
+
else if (typeof api.enableCustomDomain === 'function') { // no i18n
|
|
269
|
+
// an older WmsLite: everything goes through the site's own /wmssrv
|
|
270
|
+
api.enableCustomDomain();
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
api.registerAnnon(session.prdId, session.sessionID, session.displayName || DEFAULT_DISPLAY_NAME, true, session.token);
|
|
274
|
+
connectedSessionId = session.sessionID;
|
|
275
|
+
}
|
|
276
|
+
catch (err) {
|
|
277
|
+
Console.warn(LABEL + ': WmsLite.registerAnnon failed', err); // no i18n
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
function loadScript() {
|
|
281
|
+
var wms = _ZAP._wmsConfig;
|
|
282
|
+
if (!wms || scriptState === 'loading') { // no i18n
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
scriptState = 'loading'; // no i18n
|
|
286
|
+
var script = document.createElement('script'); // no i18n
|
|
287
|
+
script.src = wms.wms_js_url;
|
|
288
|
+
if (wms.wms_sri) {
|
|
289
|
+
script.integrity = wms.wms_sri;
|
|
290
|
+
script.crossOrigin = 'anonymous'; // no i18n
|
|
291
|
+
}
|
|
292
|
+
script.onload = function () {
|
|
293
|
+
if (!wmsLite()) {
|
|
294
|
+
failed('wmsliteapi.js loaded without WmsLite'); // no i18n
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
scriptState = 'loaded'; // no i18n
|
|
298
|
+
loadedByUs = true;
|
|
299
|
+
// wmsliteapi.js declares a global `function WmsliteImpl(){}` with empty defaults, which
|
|
300
|
+
// replaces the object our callbacks were on: they go on again, onto the script's own
|
|
301
|
+
installCallbacks();
|
|
302
|
+
if (active !== null) {
|
|
303
|
+
registerWithWms(active);
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
script.onerror = function () {
|
|
307
|
+
failed('wmsliteapi.js failed to load from ' + wms.wms_js_url + ' (network, integrity or Content-Security-Policy)'); // no i18n
|
|
308
|
+
};
|
|
309
|
+
document.head.appendChild(script);
|
|
310
|
+
}
|
|
311
|
+
function failed(reason) {
|
|
312
|
+
scriptState = 'failed'; // no i18n
|
|
313
|
+
if (!warnedLoadFailure) {
|
|
314
|
+
warnedLoadFailure = true;
|
|
315
|
+
warnAlways(LABEL + ': ' + reason + '; push messages are off for this page'); // no i18n
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Connects `session` to WMS, loading wmsliteapi.js the first time. A load that failed is tried
|
|
320
|
+
* again only when the app asked (`manual`), never on its own.
|
|
321
|
+
*/
|
|
322
|
+
function connect(session, manual) {
|
|
323
|
+
active = session;
|
|
324
|
+
installCallbacks();
|
|
325
|
+
if (wmsLite()) {
|
|
326
|
+
scriptState = 'loaded'; // no i18n
|
|
327
|
+
registerWithWms(session);
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
if (scriptState === 'failed' && !manual) { // no i18n
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
loadScript();
|
|
334
|
+
}
|
|
335
|
+
/** Stops delivering this session's messages, closing the connection where WmsLite can. */
|
|
336
|
+
function disconnect() {
|
|
337
|
+
// the timers of what is on screen go with the session
|
|
338
|
+
stopAllNotifications();
|
|
339
|
+
if (active === null) {
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
active = null;
|
|
343
|
+
connectedSessionId = ''; // no i18n
|
|
344
|
+
var api = wmsLite();
|
|
345
|
+
// a WmsLite the page loaded is the page's connection: closing it would log the page out
|
|
346
|
+
if (!api || !loadedByUs) {
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
// wmsliteapi.js has no logout or close: disable() sets disablewms and aborts the connection
|
|
350
|
+
if (typeof api.disable === 'function') { // no i18n
|
|
351
|
+
try {
|
|
352
|
+
api.disable();
|
|
353
|
+
}
|
|
354
|
+
catch (err) {
|
|
355
|
+
Console.warn(LABEL + ': WmsLite.disable failed', err); // no i18n
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
setSessionListener(function (session, manual) {
|
|
360
|
+
if (session) {
|
|
361
|
+
connect(session, manual);
|
|
362
|
+
}
|
|
363
|
+
else {
|
|
364
|
+
disconnect();
|
|
365
|
+
}
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
export { connect, crossOriginHost, decodeMessage, disconnect, isZohoDomain };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @zoho_apptics/apptics-js-sdk v2.0.0
|
|
1
|
+
/*! @zoho_apptics/apptics-js-sdk v2.0.0 | (c) Zoho Corporation Private Limited | see LICENSE */
|
|
2
2
|
import { _ZAP } from '../core/state.js';
|
|
3
3
|
import { getTimeZone } from '../core/env.js';
|
|
4
4
|
import { TZ_COUNTRIES } from './tz-countries.js';
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
/*! @zoho_apptics/apptics-js-sdk v2.0.0
|
|
1
|
+
/*! @zoho_apptics/apptics-js-sdk v2.0.0 | (c) Zoho Corporation Private Limited | see LICENSE */
|
|
2
2
|
import { storageReady } from '../core/storage.js';
|
|
3
3
|
import { Console } from '../core/logger.js';
|
|
4
4
|
import { reresolve } from './store.js';
|
|
5
|
+
import { quietly } from '../core/shield.js';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Custom condition values: a console condition on the custom criteria (`custom_sdk_value`) is
|
|
@@ -39,12 +40,12 @@ function setCustomConditionValue(conditionname, value) {
|
|
|
39
40
|
else {
|
|
40
41
|
mine[name] = values;
|
|
41
42
|
}
|
|
42
|
-
storageReady().then(function (backend) {
|
|
43
|
+
quietly('remote config', storageReady().then(function (backend) {
|
|
43
44
|
// only once storage has loaded: re-resolving before it would read an empty rule set and keep it
|
|
44
45
|
if (backend) {
|
|
45
46
|
reresolve();
|
|
46
47
|
}
|
|
47
|
-
});
|
|
48
|
+
}));
|
|
48
49
|
}
|
|
49
50
|
/** reset(): forgets the values set on this page. */
|
|
50
51
|
function clearCustomConditionValues() {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @zoho_apptics/apptics-js-sdk v2.0.0
|
|
1
|
+
/*! @zoho_apptics/apptics-js-sdk v2.0.0 | (c) Zoho Corporation Private Limited | see LICENSE */
|
|
2
2
|
import { Console } from '../core/logger.js';
|
|
3
3
|
import { _ZAP } from '../core/state.js';
|
|
4
4
|
import { isEmpty } from '../core/utils.js';
|
|
@@ -1,24 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Asks for the rule set
|
|
2
|
+
* Asks for the rule set: the whole of it with flagtime 0 on the first fetch of a page load, then
|
|
3
|
+
* only what changed since the last answered request, which is merged into what is stored.
|
|
3
4
|
*
|
|
4
|
-
* Resolves with the
|
|
5
|
-
*
|
|
6
|
-
* normal case and not a failure.
|
|
5
|
+
* Resolves with the answer, whether or not it carried a rule set — a later answer with no
|
|
6
|
+
* `remoteconfig` block means nothing has changed, which is the normal case and not a failure.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
8
|
+
* With `whole`, a cold fetch: flagtime 0 whatever this page has fetched already, and the answer
|
|
9
|
+
* replaces the stored set as the first fetch of a page load does.
|
|
10
|
+
*
|
|
11
|
+
* A second caller joins the first rather than making another request. A cold fetch joins one
|
|
12
|
+
* only when it asked with flagtime 0 too, and otherwise asks once it has answered.
|
|
9
13
|
*/
|
|
10
|
-
export declare function fetchRemoteConfig(): Promise<Record<string, unknown>>;
|
|
14
|
+
export declare function fetchRemoteConfig(whole?: boolean): Promise<Record<string, unknown>>;
|
|
11
15
|
/**
|
|
12
16
|
* reset(): forgets the rule set, its values and what the server last reported, and disowns a
|
|
13
17
|
* request still in flight, whose answer would otherwise put the old rule set back.
|
|
14
18
|
*/
|
|
15
19
|
export declare function resetRemoteConfig(): void;
|
|
16
20
|
/**
|
|
17
|
-
* Makes sure the values are this page's own: from a fetch that
|
|
18
|
-
*
|
|
19
|
-
*
|
|
21
|
+
* Makes sure the values are this page's own: from a fetch on this page that succeeded, kept up to
|
|
22
|
+
* date by the polling after it. With `coldFetch`, a fetch with flagtime 0 now, whatever this page
|
|
23
|
+
* already has, whose answer replaces what is stored: at most COLD_LIMIT a minute, and one past
|
|
24
|
+
* that answers from what this page has. Resolves true when they are, false when the
|
|
25
|
+
* fetch failed or could not be made — the caller then decides whether stored values will do.
|
|
26
|
+
* Never rejects.
|
|
20
27
|
*
|
|
21
28
|
* Waits for start-up and for the device to be registered, which a first visit is still doing
|
|
22
29
|
* when ready() resolves: getupdates is refused without the device ids.
|
|
23
30
|
*/
|
|
24
|
-
export declare function obtain(): Promise<boolean>;
|
|
31
|
+
export declare function obtain(coldFetch?: boolean): Promise<boolean>;
|