@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,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,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 { SDK_MODULE } from '../core/constants.js';
|
|
3
3
|
import { hooks } from '../core/hooks.js';
|
|
4
4
|
import { _ZAP } from '../core/state.js';
|
|
@@ -9,6 +9,7 @@ import { deviceReady } from '../device/index.js';
|
|
|
9
9
|
import { ready } from '../lifecycle.js';
|
|
10
10
|
import { clearCustomConditionValues } from './custom.js';
|
|
11
11
|
import { store, merge, storeUnchanged, flagtime, reresolve, clearRemoteConfig } from './store.js';
|
|
12
|
+
import { shield, quietly } from '../core/shield.js';
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* The getupdates call.
|
|
@@ -34,7 +35,7 @@ var inFlightWhole = false;
|
|
|
34
35
|
var generation = 0;
|
|
35
36
|
/**
|
|
36
37
|
* When getupdates is asked again, after the first of a page load: every POLL_MS. Coming back to
|
|
37
|
-
* the tab asks nothing; the poll's timer carries on.
|
|
38
|
+
* the tab asks nothing; the poll's timer carries on. fetchValues() never ask
|
|
38
39
|
* themselves once a fetch has succeeded: a value read on every render must not be a request on
|
|
39
40
|
* every render.
|
|
40
41
|
*/
|
|
@@ -47,6 +48,13 @@ const COLD_LIMIT = 3;
|
|
|
47
48
|
const COLD_WINDOW_MS = 60 * 1000;
|
|
48
49
|
/** When a fetch on this page last succeeded; 0 until one has, and the next one sends flagtime 0. */
|
|
49
50
|
var fetchedAt = 0;
|
|
51
|
+
/**
|
|
52
|
+
* When a fetch last failed, or 0. Until this page has an answer of its own, fetchValues asks again
|
|
53
|
+
* only RETRY_AFTER_FAILURE_MS after a failure: asked at once on every call, a page that calls it on
|
|
54
|
+
* every render, or one whose getupdates keeps being refused, asked hundreds of times a minute.
|
|
55
|
+
*/
|
|
56
|
+
var failedAt = 0;
|
|
57
|
+
const RETRY_AFTER_FAILURE_MS = 30 * 1000;
|
|
50
58
|
/** When the coldFetch calls of the last minute went out. */
|
|
51
59
|
var coldCalls = [];
|
|
52
60
|
var pollTimer = null;
|
|
@@ -132,7 +140,7 @@ function fetchRemoteConfig(whole) {
|
|
|
132
140
|
Console.log(LABEL + ': switched off by the server, not asking'); // no i18n
|
|
133
141
|
return Promise.resolve({});
|
|
134
142
|
}
|
|
135
|
-
var blocked = rejectIfOffline(LABEL) || rejectIfNoDeviceIds(LABEL);
|
|
143
|
+
var blocked = rejectIfOffline(LABEL) || rejectIfNoDeviceIds(LABEL, 'getupdates');
|
|
136
144
|
if (blocked) {
|
|
137
145
|
return blocked;
|
|
138
146
|
}
|
|
@@ -150,6 +158,7 @@ function fetchRemoteConfig(whole) {
|
|
|
150
158
|
applyReportedModules(data);
|
|
151
159
|
var rules = data.remoteconfig;
|
|
152
160
|
fetchedAt = nowMs();
|
|
161
|
+
failedAt = 0;
|
|
153
162
|
if (askWhole) {
|
|
154
163
|
// with flagtime 0 the answer is the whole set, and no block means there is nothing in it
|
|
155
164
|
store(rules && typeof rules === 'object' ? rules : {}, askedAt);
|
|
@@ -167,6 +176,9 @@ function fetchRemoteConfig(whole) {
|
|
|
167
176
|
settle();
|
|
168
177
|
return data;
|
|
169
178
|
}, function (err) {
|
|
179
|
+
if (asked === generation) {
|
|
180
|
+
failedAt = nowMs();
|
|
181
|
+
}
|
|
170
182
|
settle();
|
|
171
183
|
return Promise.reject(err);
|
|
172
184
|
});
|
|
@@ -194,6 +206,7 @@ function resetRemoteConfig() {
|
|
|
194
206
|
inFlight = null;
|
|
195
207
|
inFlightWhole = false;
|
|
196
208
|
fetchedAt = 0;
|
|
209
|
+
failedAt = 0;
|
|
197
210
|
coldCalls = [];
|
|
198
211
|
if (pollTimer !== null) {
|
|
199
212
|
clearTimeout(pollTimer);
|
|
@@ -234,6 +247,12 @@ function obtain(coldFetch) {
|
|
|
234
247
|
if (fetchedAt > 0 && !cold) {
|
|
235
248
|
return true;
|
|
236
249
|
}
|
|
250
|
+
// no answer on this page yet, and the last try failed moments ago: the stored values answer
|
|
251
|
+
// until RETRY_AFTER_FAILURE_MS has passed, and the polling keeps trying meanwhile
|
|
252
|
+
if (!cold && failedAt > 0 && nowMs() - failedAt < RETRY_AFTER_FAILURE_MS) {
|
|
253
|
+
Console.log(LABEL + ': the last fetch failed ' + (nowMs() - failedAt) + ' ms ago; answering from the stored values'); // no i18n
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
237
256
|
return deviceReady().then(function () {
|
|
238
257
|
return fetchRemoteConfig(cold);
|
|
239
258
|
}).then(function () {
|
|
@@ -250,11 +269,11 @@ function refresh(reason) {
|
|
|
250
269
|
return;
|
|
251
270
|
}
|
|
252
271
|
Console.log(LABEL + ': asking for changes (' + reason + ')'); // no i18n
|
|
253
|
-
deviceReady().then(function () {
|
|
272
|
+
quietly(LABEL, deviceReady().then(function () {
|
|
254
273
|
return fetchRemoteConfig();
|
|
255
274
|
}).catch(function (err) {
|
|
256
275
|
Console.log(LABEL + ': fetch failed: ' + String(err)); // no i18n
|
|
257
|
-
}).then(keepPolling);
|
|
276
|
+
}).then(keepPolling));
|
|
258
277
|
}
|
|
259
278
|
/**
|
|
260
279
|
* A fetch that never went out (offline, the device not registered yet, the server switched it
|
|
@@ -270,14 +289,14 @@ function schedulePoll() {
|
|
|
270
289
|
if (pollTimer !== null) {
|
|
271
290
|
clearTimeout(pollTimer);
|
|
272
291
|
}
|
|
273
|
-
pollTimer = setTimeout(function () {
|
|
292
|
+
pollTimer = setTimeout(shield(LABEL, function () {
|
|
274
293
|
pollTimer = null;
|
|
275
294
|
refresh('every ' + POLL_MS + ' ms'); // no i18n
|
|
276
|
-
}, POLL_MS);
|
|
295
|
+
}), POLL_MS);
|
|
277
296
|
}
|
|
278
297
|
/** Start-up's own fetch, so values are this session's without the app asking, then the polling. */
|
|
279
298
|
function fetchOnStart() {
|
|
280
|
-
obtain().then(keepPolling);
|
|
299
|
+
quietly(LABEL, obtain().then(keepPolling));
|
|
281
300
|
}
|
|
282
301
|
hooks.resetRemoteConfig = resetRemoteConfig;
|
|
283
302
|
hooks.remoteConfigStarted = fetchOnStart;
|
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
/** AppticsRemoteConfig:
|
|
1
|
+
/** AppticsRemoteConfig: fetchValues and setCustomConditionValue, each with the parameter names the console shows. */
|
|
2
2
|
export declare const AppticsRemoteConfig: {
|
|
3
|
-
/** One parameter's value, null when there is none. coldFetch (false by default) asks the server for the whole set now. */
|
|
4
|
-
fetchValue: {
|
|
5
|
-
(name: string, callback?: (value: string | null) => void, coldFetch?: boolean): Promise<string | null>;
|
|
6
|
-
(name: string, coldFetch: boolean): Promise<string | null>;
|
|
7
|
-
};
|
|
8
3
|
/**
|
|
9
4
|
* The parameters named, or every parameter when none are: name -> value, null when there is
|
|
10
5
|
* none. coldFetch (false by default) asks the server for the whole set now.
|
|
@@ -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 { forward, guard } from '../core/guard.js';
|
|
3
3
|
import { Console } from '../core/logger.js';
|
|
4
4
|
import { obtain } from './fetch.js';
|
|
@@ -9,7 +9,7 @@ import { all } from './store.js';
|
|
|
9
9
|
* Remote config, shipped as its own entry point:
|
|
10
10
|
* import { AppticsRemoteConfig } from '@zoho_apptics/apptics-js-sdk/remote-config';
|
|
11
11
|
*
|
|
12
|
-
*
|
|
12
|
+
* fetchValues(['a']) reads one parameter, fetchValues(['a', 'b']) several, and fetchValues() every
|
|
13
13
|
* parameter the console has. Each parameter's value is the console's: the value of the first
|
|
14
14
|
* condition, in the console's order, that this device matches, else the parameter's default value.
|
|
15
15
|
* setCustomConditionValue(conditionname, 'a,b') answers the custom conditions.
|
|
@@ -38,30 +38,11 @@ function answer(value, callback) {
|
|
|
38
38
|
}
|
|
39
39
|
return value;
|
|
40
40
|
}
|
|
41
|
-
/**
|
|
42
|
-
* One parameter, fetched for this page, as Android's fetchValue: resolves with its value, or null
|
|
43
|
-
* when the console has no such parameter. A failed fetch answers with the value fetched before.
|
|
44
|
-
*
|
|
45
|
-
* `coldFetch` (false by default) asks the server now with flagtime 0, for the whole set, and
|
|
46
|
-
* answers from that instead of what this page already has. It may come in place of the callback.
|
|
47
|
-
*/
|
|
48
|
-
function fetchValue(name, callback, coldFetch) {
|
|
49
|
-
if (typeof callback === 'boolean') { // no i18n
|
|
50
|
-
// fetchValue(name, coldFetch)
|
|
51
|
-
coldFetch = callback;
|
|
52
|
-
callback = undefined;
|
|
53
|
-
}
|
|
54
|
-
var done = typeof callback === 'function' ? callback : undefined; // no i18n
|
|
55
|
-
return obtain(coldFetch === true).then(function () {
|
|
56
|
-
var value = raw(name);
|
|
57
|
-
return answer(value === undefined ? null : value, done);
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
41
|
/**
|
|
61
42
|
* Several parameters at once: `names` lists the ones wanted, and the result has exactly those
|
|
62
43
|
* names, null for one the console does not have. With no names (or an empty list), every
|
|
63
44
|
* parameter the console has. A callback may come first when there are no names, and `coldFetch`
|
|
64
|
-
* (false by default
|
|
45
|
+
* (false by default) last, in place of either.
|
|
65
46
|
*/
|
|
66
47
|
function fetchValues(names, callback, coldFetch) {
|
|
67
48
|
var args = [names, callback, coldFetch];
|
|
@@ -99,15 +80,10 @@ function wantedNames(names) {
|
|
|
99
80
|
});
|
|
100
81
|
return out.length === 0 ? null : out;
|
|
101
82
|
}
|
|
102
|
-
const fetchValueGuarded = guard('AppticsRemoteConfig.fetchValue', fetchValue); // no i18n
|
|
103
83
|
const fetchValuesGuarded = guard('AppticsRemoteConfig.fetchValues', fetchValues); // no i18n
|
|
104
84
|
const setCustomConditionValueGuarded = guard('AppticsRemoteConfig.setCustomConditionValue', setCustomConditionValue); // no i18n
|
|
105
|
-
/** AppticsRemoteConfig:
|
|
85
|
+
/** AppticsRemoteConfig: fetchValues and setCustomConditionValue, each with the parameter names the console shows. */
|
|
106
86
|
const AppticsRemoteConfig = {
|
|
107
|
-
/** One parameter's value, null when there is none. coldFetch (false by default) asks the server for the whole set now. */
|
|
108
|
-
fetchValue: function fetchValue(name, callback, coldFetch) {
|
|
109
|
-
return forward(fetchValueGuarded, arguments);
|
|
110
|
-
},
|
|
111
87
|
/**
|
|
112
88
|
* The parameters named, or every parameter when none are: name -> value, null when there is
|
|
113
89
|
* none. coldFetch (false by default) asks the server for the whole set now.
|
|
@@ -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 { user_defaults } from '../core/storage.js';
|
|
4
4
|
import { nowMs } from '../core/utils.js';
|
|
@@ -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
|
/**
|
|
3
3
|
* The country of every IANA time zone, by its ISO 3166 code: generated by
|
|
4
4
|
* scripts/tz-countries.mjs from tzdata 2026d-rearguard (zone.tab, and the old names its links keep).
|
|
@@ -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
|
/**
|
|
3
3
|
* Where in the app an AppticsLogger line was written, for logSDK's `filename`, `linenumber` and
|
|
4
4
|
* `function`: the Remote Logger page shows each line with them.
|
|
@@ -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 { is_apptics_disabled } from '../core/env.js';
|
|
4
4
|
import { shouldTrackOrSendData } from '../core/consent.js';
|
|
@@ -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 { LOG_FUNCTION_MAX } from '../core/constants.js';
|
|
3
3
|
import { callSite } from './callsite.js';
|
|
4
4
|
import { remotelog_transactions } from '../core/storage.js';
|