@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,119 @@
|
|
|
1
|
+
/*! @zoho_apptics/apptics-js-sdk v2.0.0 | (c) Zoho Corporation Private Limited | see LICENSE */
|
|
2
|
+
import { warnAlways, logFailure, Console } from './logger.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The SDK's own failures stay the SDK's. A throw in one of its timers or listeners, or a rejection
|
|
6
|
+
* no one in the SDK waits on, would otherwise reach the page's `error` and `unhandledrejection`
|
|
7
|
+
* events, where the SDK's error tracking records it as the app's JS error and sends it.
|
|
8
|
+
*
|
|
9
|
+
* guard() shields the public calls; shield() and quietly() shield everything the SDK runs later.
|
|
10
|
+
* Element errors (the SDK's script, style and form elements) are told apart by isSdkElement.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Said in the console and nowhere else. An Error is a real failure (a bug, storage refusing), said
|
|
14
|
+
* whether or not debug is on; anything else is one of the SDK's own reasons for not doing
|
|
15
|
+
* something, as "nothing to send", said in debug mode.
|
|
16
|
+
*/
|
|
17
|
+
function sdkFailed(label, err) {
|
|
18
|
+
try {
|
|
19
|
+
if (err instanceof Error) {
|
|
20
|
+
warnAlways('apptics: ' + label + ' failed:', err); // no i18n
|
|
21
|
+
logFailure(label, err);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
Console.log('apptics: ' + label + ': ' + String(err)); // no i18n
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
catch (e) {
|
|
28
|
+
// the console itself failing must not turn into the error this keeps off the page
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A callback the SDK hands to the browser (a timer, a listener, a storage or network callback)
|
|
33
|
+
* that never throws into it. A promise it returns is waited on the same way, so an async
|
|
34
|
+
* listener's rejection is not left unhandled either. Wrap once and keep the wrapped function where
|
|
35
|
+
* it is removed again later: removeEventListener needs the same reference.
|
|
36
|
+
*/
|
|
37
|
+
function shield(label, fn) {
|
|
38
|
+
return function () {
|
|
39
|
+
try {
|
|
40
|
+
var result = fn.apply(this, arguments);
|
|
41
|
+
if (result && typeof result.then === 'function') { // no i18n
|
|
42
|
+
quietly(label, result);
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
sdkFailed(label, err);
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/** A promise the SDK starts and does not wait on: its rejection is said in the console, not left unhandled. */
|
|
53
|
+
function quietly(label, promise) {
|
|
54
|
+
if (!promise || typeof promise.then !== 'function') { // no i18n
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
promise.then(undefined, function (err) {
|
|
58
|
+
sdkFailed(label, err);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Reasons the SDK rejected one of the app's promises with (sendFeedback, ready, flush, fetchValues):
|
|
63
|
+
* the app may not handle them, and then the rejection is still the SDK's failure, not the app's.
|
|
64
|
+
* Objects by identity; strings and other primitives by value, a few dozen at most.
|
|
65
|
+
*/
|
|
66
|
+
const sdkReasonObjects = typeof WeakSet === 'function' ? new WeakSet() : undefined; // no i18n
|
|
67
|
+
const sdkReasonValues = [];
|
|
68
|
+
const MAX_REASON_VALUES = 50;
|
|
69
|
+
function markSdkRejection(reason) {
|
|
70
|
+
if (reason !== null && (typeof reason === 'object' || typeof reason === 'function')) { // no i18n
|
|
71
|
+
if (sdkReasonObjects) {
|
|
72
|
+
sdkReasonObjects.add(reason);
|
|
73
|
+
}
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (sdkReasonValues.indexOf(reason) === -1) {
|
|
77
|
+
sdkReasonValues.push(reason);
|
|
78
|
+
if (sdkReasonValues.length > MAX_REASON_VALUES) {
|
|
79
|
+
sdkReasonValues.shift();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function isSdkRejection(reason) {
|
|
84
|
+
if (reason !== null && (typeof reason === 'object' || typeof reason === 'function')) { // no i18n
|
|
85
|
+
return !!sdkReasonObjects && sdkReasonObjects.has(reason);
|
|
86
|
+
}
|
|
87
|
+
return reason !== undefined && sdkReasonValues.indexOf(reason) !== -1;
|
|
88
|
+
}
|
|
89
|
+
/** Marks the elements the SDK adds to the page; isSdkElement knows them and what is inside them. */
|
|
90
|
+
const SDK_ELEMENT_ATTR = 'data-apptics'; // no i18n
|
|
91
|
+
/** Whether an element is the SDK's own: its style, the Quartz script, the feedback form or the recording timer. */
|
|
92
|
+
function isSdkElement(target) {
|
|
93
|
+
var el = target;
|
|
94
|
+
if (!el || typeof el.closest !== 'function') { // no i18n
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
return !!el.closest('[' + SDK_ELEMENT_ATTR + '], #zasdkFeedbackModal, #zasdkrectimer'); // no i18n
|
|
99
|
+
}
|
|
100
|
+
catch (err) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Scripts whose own errors are the SDK's: the SDK file, when it was loaded as a plain script, and
|
|
106
|
+
* the Quartz recorder it loads. An npm build is part of the app's own bundle, so its file says
|
|
107
|
+
* nothing; shield() and quietly() are what keep its failures off the page.
|
|
108
|
+
*/
|
|
109
|
+
const sdkScripts = [];
|
|
110
|
+
function noteSdkScript(src) {
|
|
111
|
+
if (src && sdkScripts.indexOf(src) === -1) {
|
|
112
|
+
sdkScripts.push(src);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function isSdkScript(filename) {
|
|
116
|
+
return !!filename && sdkScripts.indexOf(filename) !== -1;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export { SDK_ELEMENT_ATTR, isSdkElement, isSdkRejection, isSdkScript, markSdkRejection, noteSdkScript, quietly, sdkFailed, shield };
|
package/dist/esm/core/state.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type ApConfig } from './constants.js';
|
|
2
|
-
import type { DeviceInfo, Dict, QuartzSettings, TrackingStatus, UserInfo } from '../types.js';
|
|
1
|
+
import { type ApConfig, type EngagementType } from './constants.js';
|
|
2
|
+
import type { DeviceInfo, Dict, QuartzSettings, TrackingStatus, UserInfo, WmsConfig } from '../types.js';
|
|
3
3
|
/** Runtime state shared by every module (the former `_ZAP` object). */
|
|
4
4
|
export interface State {
|
|
5
5
|
_initialised: boolean;
|
|
@@ -19,7 +19,6 @@ export interface State {
|
|
|
19
19
|
_token: string;
|
|
20
20
|
_frameworkID: number;
|
|
21
21
|
_platform: string;
|
|
22
|
-
_isanonrequired: boolean;
|
|
23
22
|
_devicestatus: TrackingStatus;
|
|
24
23
|
_uuid: string;
|
|
25
24
|
_apid: string;
|
|
@@ -30,9 +29,12 @@ export interface State {
|
|
|
30
29
|
_current_session: Dict;
|
|
31
30
|
_properties: Dict;
|
|
32
31
|
_ignoreDnt: boolean;
|
|
33
|
-
_isGlobalErrorTracking: boolean;
|
|
34
32
|
_shouldTrack: boolean;
|
|
35
|
-
|
|
33
|
+
/**
|
|
34
|
+
* getsdkconfig's engagement modules, one per kind of item, keyed by the item's type: event (5),
|
|
35
|
+
* api (6), screen (10) and session (11).
|
|
36
|
+
*/
|
|
37
|
+
_engagementTracking: Record<EngagementType, boolean>;
|
|
36
38
|
_errorTracking: boolean;
|
|
37
39
|
/** getsdkconfig module 18. Heatmap has its own flag in v2; before that it rode engagement. */
|
|
38
40
|
_heatmapTracking: boolean;
|
|
@@ -44,6 +46,10 @@ export interface State {
|
|
|
44
46
|
_remoteConfigReported: boolean;
|
|
45
47
|
/** getsdkconfig module 12. */
|
|
46
48
|
_feedbackEnabled: boolean;
|
|
49
|
+
/** getsdkconfig module 16, and a usable `wms` block with it: off until both say otherwise. */
|
|
50
|
+
_pushEnabled: boolean;
|
|
51
|
+
/** getsdkconfig's `wms` block, null until an answer carries a usable one. */
|
|
52
|
+
_wmsConfig: WmsConfig | null;
|
|
47
53
|
/** getsdkconfig's `quartz` block: screen recording in the feedback form. Off until it says otherwise. */
|
|
48
54
|
_quartz: QuartzSettings;
|
|
49
55
|
/** Epoch ms getsdkconfig asked us to wait until before asking again. 0 means no answer yet. */
|
package/dist/esm/core/state.js
CHANGED
|
@@ -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 { AP_TRACKING_STATUS, AP_CONSTANTS, DEFAULT_INACTIVE_MINUTES, AP_CONFIG } from './constants.js';
|
|
3
3
|
import { nowMs } from './utils.js';
|
|
4
4
|
import { FRAMEWORK_ID } from './framework-id.js';
|
|
@@ -21,7 +21,6 @@ function initialState() {
|
|
|
21
21
|
// issued by Apptics at pack time; see scripts/register-version.mjs
|
|
22
22
|
_frameworkID: FRAMEWORK_ID,
|
|
23
23
|
_platform: AP_CONSTANTS.BROWSER,
|
|
24
|
-
_isanonrequired: true,
|
|
25
24
|
_devicestatus: AP_TRACKING_STATUS.USAGE_TRACKING_WITHOUT_PII,
|
|
26
25
|
_uuid: '', // no i18n
|
|
27
26
|
_apid: '', // no i18n
|
|
@@ -32,14 +31,15 @@ function initialState() {
|
|
|
32
31
|
_current_session: {},
|
|
33
32
|
_properties: {},
|
|
34
33
|
_ignoreDnt: false,
|
|
35
|
-
_isGlobalErrorTracking: true,
|
|
36
34
|
_shouldTrack: true,
|
|
37
|
-
_engagementTracking: true,
|
|
35
|
+
_engagementTracking: { event: true, screen: true, session: true, api: true },
|
|
38
36
|
_heatmapTracking: true,
|
|
39
37
|
_remoteLoggerEnabled: true,
|
|
40
38
|
_remoteConfigEnabled: true,
|
|
41
39
|
_remoteConfigReported: true,
|
|
42
40
|
_feedbackEnabled: true,
|
|
41
|
+
_pushEnabled: false,
|
|
42
|
+
_wmsConfig: null,
|
|
43
43
|
_nextConfigCheck: 0,
|
|
44
44
|
_debugUntil: 0,
|
|
45
45
|
_errorTracking: true,
|
|
@@ -49,6 +49,13 @@ export declare const user_defaults: {
|
|
|
49
49
|
* A key storage doesn't hold keeps this tab's value.
|
|
50
50
|
*/
|
|
51
51
|
export declare function reloadSettings(keys: string[]): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* The tracking status a value names: one of AP_TRACKING_STATUS, or the number it is stored as
|
|
54
|
+
* (TRACKING_STATUS_CODE). Anything else names none.
|
|
55
|
+
*/
|
|
56
|
+
export declare function trackingStatusFrom(value: unknown): TrackingStatus | undefined;
|
|
57
|
+
/** The number a tracking status is stored as. */
|
|
58
|
+
export declare function trackingStatusCode(status: TrackingStatus): number;
|
|
52
59
|
/** The visitor's tracking status, stored in trackinfo as tracking_status. */
|
|
53
60
|
export declare function storedTrackingStatus(): TrackingStatus | undefined;
|
|
54
61
|
/** Opt-in status, stored in the trackinfo setting as tracking_status. */
|
package/dist/esm/core/storage.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/*! @zoho_apptics/apptics-js-sdk v2.0.0
|
|
2
|
-
import { AP_TRACKING_STATUS } from './constants.js';
|
|
1
|
+
/*! @zoho_apptics/apptics-js-sdk v2.0.0 | (c) Zoho Corporation Private Limited | see LICENSE */
|
|
2
|
+
import { AP_TRACKING_STATUS, TRACKING_STATUS_CODE } from './constants.js';
|
|
3
3
|
import { _ZAP, isExpired, getConfig } from './state.js';
|
|
4
4
|
import { Console } from './logger.js';
|
|
5
5
|
import { cloneObject, getNewUUID, isEmpty, sizeof } from './utils.js';
|
|
@@ -271,14 +271,32 @@ function reloadSettings(keys) {
|
|
|
271
271
|
});
|
|
272
272
|
});
|
|
273
273
|
}
|
|
274
|
+
/**
|
|
275
|
+
* The tracking status a value names: one of AP_TRACKING_STATUS, or the number it is stored as
|
|
276
|
+
* (TRACKING_STATUS_CODE). Anything else names none.
|
|
277
|
+
*/
|
|
278
|
+
function trackingStatusFrom(value) {
|
|
279
|
+
if (typeof value === 'string' && TRACKING_STATUS_CODE.hasOwnProperty(value)) { // no i18n
|
|
280
|
+
return value;
|
|
281
|
+
}
|
|
282
|
+
var names = Object.keys(TRACKING_STATUS_CODE);
|
|
283
|
+
for (var i = 0; i < names.length; i++) {
|
|
284
|
+
if (TRACKING_STATUS_CODE[names[i]] === value) {
|
|
285
|
+
return names[i];
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return undefined;
|
|
289
|
+
}
|
|
290
|
+
/** The number a tracking status is stored as. */
|
|
291
|
+
function trackingStatusCode(status) {
|
|
292
|
+
return TRACKING_STATUS_CODE[status];
|
|
293
|
+
}
|
|
274
294
|
/** The visitor's tracking status, stored in trackinfo as tracking_status. */
|
|
275
295
|
function storedTrackingStatus() {
|
|
276
296
|
var track = settings.trackinfo;
|
|
277
|
-
var status = track && typeof track === 'object' ? track.tracking_status : undefined; // no i18n
|
|
278
297
|
// a status only: getsdkconfig's own answer uses the same key for its per-module flags, and
|
|
279
298
|
// one stored by mistake must not read as a consent and stop all tracking
|
|
280
|
-
return
|
|
281
|
-
|| status === AP_TRACKING_STATUS.NO_TRACKING ? status : undefined;
|
|
299
|
+
return trackingStatusFrom(track && typeof track === 'object' ? track.tracking_status : undefined); // no i18n
|
|
282
300
|
}
|
|
283
301
|
/** Opt-in status, stored in the trackinfo setting as tracking_status. */
|
|
284
302
|
const tracking_preference = {
|
|
@@ -291,13 +309,12 @@ const tracking_preference = {
|
|
|
291
309
|
},
|
|
292
310
|
update_status(tracking_status) {
|
|
293
311
|
_ZAP._devicestatus = tracking_status;
|
|
294
|
-
//
|
|
295
|
-
|
|
296
|
-
tracking_preference.opt_in_status() == AP_TRACKING_STATUS.USAGE_TRACKING_WITH_PII ? false : _ZAP._isanonrequired;
|
|
312
|
+
// stored as its number, which earlier builds read back the same way
|
|
313
|
+
var code = trackingStatusCode(tracking_status);
|
|
297
314
|
var track = Object.assign({}, settings.trackinfo && typeof settings.trackinfo === 'object' ? settings.trackinfo : {}); // no i18n
|
|
298
|
-
track.tracking_status =
|
|
315
|
+
track.tracking_status = code;
|
|
299
316
|
if (_ZAP._trackinfo && typeof _ZAP._trackinfo === 'object') { // no i18n
|
|
300
|
-
_ZAP._trackinfo.tracking_status =
|
|
317
|
+
_ZAP._trackinfo.tracking_status = code;
|
|
301
318
|
}
|
|
302
319
|
setSetting('trackinfo', track); // no i18n
|
|
303
320
|
},
|
|
@@ -311,4 +328,4 @@ function getKeyFromDeviceInfo(key) {
|
|
|
311
328
|
return null;
|
|
312
329
|
}
|
|
313
330
|
|
|
314
|
-
export { engagement_transactions, error_transactions, feedbacklog_transactions, getKeyFromDeviceInfo, heatmap_transactions, reloadSettings, remotelog_transactions, setDeviceInfoKey, storageReady, storedTrackingStatus, tracking_preference, user_defaults };
|
|
331
|
+
export { engagement_transactions, error_transactions, feedbacklog_transactions, getKeyFromDeviceInfo, heatmap_transactions, reloadSettings, remotelog_transactions, setDeviceInfoKey, storageReady, storedTrackingStatus, trackingStatusCode, trackingStatusFrom, tracking_preference, user_defaults };
|
|
@@ -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
|
* Adds the feedback form's styles to the page, once, as a <style> element, so no app imports or
|
|
4
4
|
* links a stylesheet: the css is carried in the JavaScript, for npm and the CDN builds alike.
|
|
@@ -10,6 +10,14 @@ export type RequestBody = XMLHttpRequestBodyInit | null;
|
|
|
10
10
|
export declare const REQUEST_TIMEOUT_MS = 30000;
|
|
11
11
|
export declare function makeRequest(url: string, method: string, payload: RequestBody, headers?: RequestHeaders): Promise<string>;
|
|
12
12
|
export declare function getHeaderParams(key: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* Whether a call names the browser by its anonymousid rather than its deviceid: every call an
|
|
15
|
+
* anonymous browser makes, except the two that tie a person to the device. user/register registers
|
|
16
|
+
* the user against the deviceid, and feedback the reporter picked themselves on goes with their
|
|
17
|
+
* userid, so with the deviceid too. Feedback sent as Anonymous goes by the anonymousid.
|
|
18
|
+
* getsdkconfig names no device at all.
|
|
19
|
+
*/
|
|
20
|
+
export declare function sendsByAnonymousId(path: ApiPath): boolean;
|
|
13
21
|
export declare function getParameters(path: ApiPath): string;
|
|
14
22
|
/**
|
|
15
23
|
* `extra` appends params the path needs per call rather than per state, which console/addlog does
|
|
@@ -76,10 +84,13 @@ export declare function rejectIfOffline(label: string): Promise<never> | null;
|
|
|
76
84
|
/** Device ids sent alongside every payload. */
|
|
77
85
|
export declare function getMetaObj(): Dict;
|
|
78
86
|
/**
|
|
79
|
-
* Calls made after registration need apid/mapid
|
|
80
|
-
*
|
|
81
|
-
*
|
|
87
|
+
* Calls made after registration need apid/mapid, and the id `path` goes out by: the deviceid, or
|
|
88
|
+
* while tracking is anonymous the anonymousid for the calls sendsByAnonymousId names. Without them
|
|
89
|
+
* this asks device.ts to refresh device info (which registers) and returns a labelled rejection;
|
|
90
|
+
* otherwise null. Shared by sender, user and feedback (P11).
|
|
82
91
|
*/
|
|
83
|
-
export declare function rejectIfNoDeviceIds(label: string): Promise<never> | null;
|
|
92
|
+
export declare function rejectIfNoDeviceIds(label: string, path: ApiPath): Promise<never> | null;
|
|
84
93
|
/** Whether device/add has given this browser its deviceid. */
|
|
85
94
|
export declare function hasDeviceId(): boolean;
|
|
95
|
+
/** The ids data goes out by: the deviceid, and the anonymousid too while tracking is anonymous. */
|
|
96
|
+
export declare function hasSendIds(): boolean;
|
|
@@ -1,11 +1,11 @@
|
|
|
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 { API_VERSIONS, PATHS_WITHOUT_ORG, DEFAULT_API_PATHS, DEBUG_CAPABLE_PATHS, AP_TRACKING_STATUS, DEVICE_NAME_MAX } from './constants.js';
|
|
3
3
|
import { getConfig, _ZAP } from './state.js';
|
|
4
4
|
import { Console } from './logger.js';
|
|
5
5
|
import { isEmpty, isSuccess } from './utils.js';
|
|
6
|
-
import { getKeyFromDeviceInfo } from './storage.js';
|
|
6
|
+
import { getKeyFromDeviceInfo, tracking_preference } from './storage.js';
|
|
7
7
|
import { is_apptics_disabled } from './env.js';
|
|
8
|
-
import { opt_in_status } from './consent.js';
|
|
8
|
+
import { isAnonymous, deviceStatusFor, opt_in_status } from './consent.js';
|
|
9
9
|
import { beginAttempt, attemptSucceeded } from './attempts.js';
|
|
10
10
|
import { debugEnabled } from './debug.js';
|
|
11
11
|
import { hooks } from './hooks.js';
|
|
@@ -126,6 +126,19 @@ function deviceNameParam(path, existing) {
|
|
|
126
126
|
var param = 'devicename=' + encodeURIComponent(name.slice(0, DEVICE_NAME_MAX)); // no i18n
|
|
127
127
|
return (existing === '' ? '?' : '&') + param; // no i18n
|
|
128
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* Whether a call names the browser by its anonymousid rather than its deviceid: every call an
|
|
131
|
+
* anonymous browser makes, except the two that tie a person to the device. user/register registers
|
|
132
|
+
* the user against the deviceid, and feedback the reporter picked themselves on goes with their
|
|
133
|
+
* userid, so with the deviceid too. Feedback sent as Anonymous goes by the anonymousid.
|
|
134
|
+
* getsdkconfig names no device at all.
|
|
135
|
+
*/
|
|
136
|
+
function sendsByAnonymousId(path) {
|
|
137
|
+
if (!isAnonymous() || path === 'reguser' || path === 'sdkconfig') { // no i18n
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
return !(path === 'feedback' && hooks.feedbackUser()); // no i18n
|
|
141
|
+
}
|
|
129
142
|
function getParameters(path) {
|
|
130
143
|
let returnVal = ''; // no i18n
|
|
131
144
|
// app/addversion runs before any id exists: it identifies the build, not the device
|
|
@@ -139,26 +152,32 @@ function getParameters(path) {
|
|
|
139
152
|
// v2 device/add declares neither identifier, platform nor appversion: the build is already
|
|
140
153
|
// known from app/addversion, and sending an undeclared param is refused as EXTRA_PARAM_FOUND.
|
|
141
154
|
// What it does declare as mandatory is appversionid, which v1 treated as optional.
|
|
155
|
+
// isanonrequired asks for the anonymousid that an anonymous browser's data goes out by.
|
|
156
|
+
// devicestatus is the server's device preference for the stored status, read from storage:
|
|
157
|
+
// _devicestatus is only set when the status changes, so after a reload it is the default
|
|
142
158
|
if (path == 'regdevice') { // no i18n
|
|
143
|
-
returnVal = '?isanonrequired=' +
|
|
159
|
+
returnVal = '?isanonrequired=' + isAnonymous() + '&devicestatus=' + deviceStatusFor(tracking_preference.opt_in_status()); // no i18n
|
|
144
160
|
if (!isEmpty(_ZAP._device_info.deviceid)) {
|
|
145
161
|
returnVal += '&deviceid=' + encodeURIComponent(String(_ZAP._device_info.deviceid)); // no i18n
|
|
146
162
|
}
|
|
163
|
+
// and the anonymous record it already has, so that one is amended rather than another made
|
|
164
|
+
if (isAnonymous() && !isEmpty(_ZAP._device_info.anonymousid)) {
|
|
165
|
+
returnVal += '&anondeviceid=' + encodeURIComponent(String(_ZAP._device_info.anonymousid)); // no i18n
|
|
166
|
+
}
|
|
147
167
|
return returnVal + mandatoryParams(returnVal);
|
|
148
168
|
}
|
|
149
|
-
// getsdkconfig
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
if (isEmpty(_ZAP._device_info.deviceid)) {
|
|
169
|
+
// getsdkconfig carries no deviceid: the user's ids below are what it answers for
|
|
170
|
+
if (path != 'sdkconfig') { // no i18n
|
|
171
|
+
// device/add answers with the anonymousid; the data urls declare it as anondeviceid
|
|
172
|
+
var anonymous = sendsByAnonymousId(path);
|
|
173
|
+
var key = anonymous ? 'anonymousid' : 'deviceid'; // no i18n
|
|
174
|
+
if (isEmpty(_ZAP._device_info[key])) {
|
|
156
175
|
hooks.refreshDeviceInfo();
|
|
157
176
|
// the device is missing, but appversionid and frameworkid are mandatory regardless:
|
|
158
177
|
// dropping them turns one missing id into a refusal that names the wrong param
|
|
159
178
|
return returnVal + mandatoryParams(returnVal);
|
|
160
179
|
}
|
|
161
|
-
returnVal = '?deviceid=' + encodeURIComponent(String(_ZAP._device_info
|
|
180
|
+
returnVal = (anonymous ? '?anondeviceid=' : '?deviceid=') + encodeURIComponent(String(_ZAP._device_info[key])); // no i18n
|
|
162
181
|
}
|
|
163
182
|
// feedback is attributed to whoever the form's user picker selected, not to the active user:
|
|
164
183
|
// the person reporting may not be the one the app last registered, and may choose Anonymous
|
|
@@ -172,21 +191,29 @@ function getParameters(path) {
|
|
|
172
191
|
}
|
|
173
192
|
return returnVal + mandatoryParams(returnVal);
|
|
174
193
|
}
|
|
175
|
-
// add userid and groupid if opt_in_status is USAGE_TRACKING_WITH_PII
|
|
194
|
+
// add userid and groupid if opt_in_status is USAGE_TRACKING_WITH_PII: never while anonymous,
|
|
195
|
+
// and not without PII either, with a user registered. getupdates doesn't declare
|
|
176
196
|
// them, and refuses userid as EXTRA_PARAM_FOUND; it has no use for them either, since remote
|
|
177
197
|
// config conditions on the user are evaluated here, against the rule set it answers with
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
198
|
+
// pushnotification/device declares no user either: it registers the browser, not a person
|
|
199
|
+
var carriesUser = path != 'reguser' && path != 'getupdates' && path != 'pushnotification' && path != 'pnstats'; // no i18n
|
|
200
|
+
if (carriesUser && opt_in_status() == AP_TRACKING_STATUS.USAGE_TRACKING_WITH_PII) {
|
|
201
|
+
if (_ZAP._user_info.hasOwnProperty('userid') && !isEmpty(_ZAP._user_info.userid)) { // no i18n
|
|
202
|
+
// getsdkconfig has no deviceid before it, so its userid starts the query
|
|
203
|
+
returnVal += (returnVal === '' ? '?' : '&') + 'userid=' + encodeURIComponent(String(_ZAP._user_info.userid)); // no i18n
|
|
204
|
+
}
|
|
205
|
+
if (_ZAP._user_info.hasOwnProperty('groupid') && !isEmpty(_ZAP._user_info.groupid)) { // no i18n
|
|
206
|
+
returnVal += (returnVal === '' ? '?' : '&') + 'customergroupid=' + encodeURIComponent(String(_ZAP._user_info.groupid)); // no i18n
|
|
187
207
|
}
|
|
188
208
|
}
|
|
189
209
|
returnVal += deviceNameParam(path, returnVal);
|
|
210
|
+
// the modules getsdkconfig is asked about; it declares moduleids as at most 2, comma-split
|
|
211
|
+
if (path == 'sdkconfig') { // no i18n
|
|
212
|
+
var modules = hooks.sdkConfigModuleIds();
|
|
213
|
+
if (modules.length > 0) {
|
|
214
|
+
returnVal += (returnVal === '' ? '?' : '&') + 'moduleids=' + encodeURIComponent(modules.slice(0, 2).join(',')); // no i18n
|
|
215
|
+
}
|
|
216
|
+
}
|
|
190
217
|
return returnVal + mandatoryParams(returnVal);
|
|
191
218
|
}
|
|
192
219
|
/**
|
|
@@ -294,7 +321,7 @@ function settle(path, label, response) {
|
|
|
294
321
|
* nothing orders one behind another.
|
|
295
322
|
*/
|
|
296
323
|
function postToApptics(path, payload, headers, label, extra) {
|
|
297
|
-
var url = getUrlWithParams(path, Object.assign(beginAttempt(path), {}));
|
|
324
|
+
var url = getUrlWithParams(path, Object.assign(beginAttempt(path), extra || {}));
|
|
298
325
|
return makeRequest(url, getConfig('method'), payload, headers).then(function (response) {
|
|
299
326
|
return settle(path, label, response);
|
|
300
327
|
}, function (err) {
|
|
@@ -413,11 +440,12 @@ function getMetaObj() {
|
|
|
413
440
|
};
|
|
414
441
|
}
|
|
415
442
|
/**
|
|
416
|
-
* Calls made after registration need apid/mapid
|
|
417
|
-
*
|
|
418
|
-
*
|
|
443
|
+
* Calls made after registration need apid/mapid, and the id `path` goes out by: the deviceid, or
|
|
444
|
+
* while tracking is anonymous the anonymousid for the calls sendsByAnonymousId names. Without them
|
|
445
|
+
* this asks device.ts to refresh device info (which registers) and returns a labelled rejection;
|
|
446
|
+
* otherwise null. Shared by sender, user and feedback (P11).
|
|
419
447
|
*/
|
|
420
|
-
function rejectIfNoDeviceIds(label) {
|
|
448
|
+
function rejectIfNoDeviceIds(label, path) {
|
|
421
449
|
if (isEmpty(getHeaderParams('apid')) && isEmpty(getHeaderParams('mapid'))) { // no i18n
|
|
422
450
|
hooks.refreshDeviceInfo();
|
|
423
451
|
return Promise.reject(label + ': You must call Apptics.init() first'); // no i18n
|
|
@@ -429,11 +457,28 @@ function rejectIfNoDeviceIds(label) {
|
|
|
429
457
|
hooks.refreshDeviceInfo();
|
|
430
458
|
return Promise.reject(label + ': the device is not registered yet, kept for the next send'); // no i18n
|
|
431
459
|
}
|
|
460
|
+
// anonymous, and device/add has not answered with the anonymousid yet: the call waits for it
|
|
461
|
+
// rather than go out by the deviceid it is meant to leave out
|
|
462
|
+
if (sendsByAnonymousId(path) && !hasAnonymousId()) {
|
|
463
|
+
hooks.refreshDeviceInfo();
|
|
464
|
+
return Promise.reject(label + ': the anonymous id has not arrived yet, kept for the next send'); // no i18n
|
|
465
|
+
}
|
|
432
466
|
return null;
|
|
433
467
|
}
|
|
468
|
+
/** Whether device/add has given this browser its anonymousid. */
|
|
469
|
+
function hasAnonymousId() {
|
|
470
|
+
return !isEmpty(_ZAP._device_info && _ZAP._device_info.anonymousid) || !isEmpty(getKeyFromDeviceInfo('anonymousid')); // no i18n
|
|
471
|
+
}
|
|
434
472
|
/** Whether device/add has given this browser its deviceid. */
|
|
435
473
|
function hasDeviceId() {
|
|
436
474
|
return !isEmpty(_ZAP._device_info && _ZAP._device_info.deviceid) || !isEmpty(getKeyFromDeviceInfo('deviceid')); // no i18n
|
|
437
475
|
}
|
|
476
|
+
/** The ids data goes out by: the deviceid, and the anonymousid too while tracking is anonymous. */
|
|
477
|
+
function hasSendIds() {
|
|
478
|
+
if (!hasDeviceId()) {
|
|
479
|
+
return false;
|
|
480
|
+
}
|
|
481
|
+
return !isAnonymous() || hasAnonymousId();
|
|
482
|
+
}
|
|
438
483
|
|
|
439
|
-
export { KEEPALIVE_BUDGET, REQUEST_TIMEOUT_MS, apiHeaders, getHeaderParams, getMetaObj, getParameters, getUrlWithParams, hasDeviceId, isPermanentRefusal, makeRequest, postKeepalive, postToApptics, rejectIfDisabled, rejectIfNoDeviceIds, rejectIfOffline, usesDebugApi };
|
|
484
|
+
export { KEEPALIVE_BUDGET, REQUEST_TIMEOUT_MS, apiHeaders, getHeaderParams, getMetaObj, getParameters, getUrlWithParams, hasDeviceId, hasSendIds, isPermanentRefusal, makeRequest, postKeepalive, postToApptics, rejectIfDisabled, rejectIfNoDeviceIds, rejectIfOffline, sendsByAnonymousId, usesDebugApi };
|
package/dist/esm/core/utils.js
CHANGED
|
@@ -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 { AP_CONSTANTS } from './constants.js';
|
|
3
3
|
|
|
4
4
|
/** Returned from an `each` iterator to stop iterating objects and array-likes. */
|
|
@@ -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 './logger.js';
|
|
3
3
|
import { isEmpty, isEmptyObj } from './utils.js';
|
|
4
4
|
|
|
@@ -29,16 +29,17 @@ const MAX_PROPERTIES_LENGTH = 7666;
|
|
|
29
29
|
/** At most this many characters in one value. */
|
|
30
30
|
const MAX_VALUE_LENGTH = 250;
|
|
31
31
|
/**
|
|
32
|
-
* A value as the payload carries it, with its type.
|
|
33
|
-
* as
|
|
34
|
-
* array, null) is turned into text,
|
|
32
|
+
* A value as the payload carries it, with its type. Only true and false are Boolean, and they go
|
|
33
|
+
* as true and false; every number is Number and goes as the number, 1 and 0 included, so the two
|
|
34
|
+
* can't be mistaken for each other. Anything else (an object, an array, null) is turned into text,
|
|
35
|
+
* as on Android, rather than dropped.
|
|
35
36
|
*/
|
|
36
37
|
function typedValue(value) {
|
|
37
38
|
if (typeof value === 'number' && isFinite(value)) { // no i18n
|
|
38
39
|
return { value: value, type: 'Number' }; // no i18n
|
|
39
40
|
}
|
|
40
41
|
if (typeof value === 'boolean') { // no i18n
|
|
41
|
-
return { value: value
|
|
42
|
+
return { value: value, type: 'Boolean' }; // no i18n
|
|
42
43
|
}
|
|
43
44
|
if (typeof value === 'string') { // no i18n
|
|
44
45
|
return { value: value, type: 'String' }; // no i18n
|
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* A fingerprint of the auth key, which is what is stored to tell one key from another: enough to
|
|
3
|
+
* notice that init() was given a different one, without keeping a second copy of the key itself.
|
|
4
|
+
* FNV-1a, 32 bits, as hex; '' for no key.
|
|
5
|
+
*/
|
|
6
|
+
export declare function keyFingerprint(key: unknown): string;
|
|
7
|
+
/**
|
|
8
|
+
* Whether we already hold usable ids for the app, auth key and version running now. Ids stored by
|
|
9
|
+
* a build that kept no key fingerprint register again once, and the answer then records it.
|
|
10
|
+
*/
|
|
2
11
|
export declare function hasAppVersion(): boolean;
|
|
3
12
|
export declare function appVersionFailedForNetwork(): boolean;
|
|
4
13
|
export declare function registerAppVersion(): Promise<boolean>;
|
|
@@ -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 { Console, warnAlways } from '../core/logger.js';
|
|
4
4
|
import { isEmpty, isSuccess } from '../core/utils.js';
|
|
@@ -37,13 +37,34 @@ const REQUIRED_KEYS = ['aaid', 'portalid', 'projectid', 'apid', 'mapid', 'appver
|
|
|
37
37
|
function missingKeys(data) {
|
|
38
38
|
return REQUIRED_KEYS.filter(function (key) { return isEmpty(data[key]); });
|
|
39
39
|
}
|
|
40
|
-
/**
|
|
40
|
+
/**
|
|
41
|
+
* A fingerprint of the auth key, which is what is stored to tell one key from another: enough to
|
|
42
|
+
* notice that init() was given a different one, without keeping a second copy of the key itself.
|
|
43
|
+
* FNV-1a, 32 bits, as hex; '' for no key.
|
|
44
|
+
*/
|
|
45
|
+
function keyFingerprint(key) {
|
|
46
|
+
var text = isEmpty(key) ? '' : String(key); // no i18n
|
|
47
|
+
if (text === '') { // no i18n
|
|
48
|
+
return ''; // no i18n
|
|
49
|
+
}
|
|
50
|
+
var hash = 0x811c9dc5;
|
|
51
|
+
for (var i = 0; i < text.length; i++) {
|
|
52
|
+
hash ^= text.charCodeAt(i);
|
|
53
|
+
hash = Math.imul(hash, 0x01000193) >>> 0;
|
|
54
|
+
}
|
|
55
|
+
return ('0000000' + hash.toString(16)).slice(-8); // no i18n
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Whether we already hold usable ids for the app, auth key and version running now. Ids stored by
|
|
59
|
+
* a build that kept no key fingerprint register again once, and the answer then records it.
|
|
60
|
+
*/
|
|
41
61
|
function hasAppVersion() {
|
|
42
62
|
var saved = stored();
|
|
43
63
|
return missingKeys(saved).length === 0
|
|
44
64
|
&& saved.appversion === _ZAP._defaultoptions.appversion
|
|
45
65
|
&& saved.identifier === _ZAP._defaultoptions.identifier
|
|
46
|
-
&& saved.serviceUrl === _ZAP._defaultoptions.serviceUrl
|
|
66
|
+
&& saved.serviceUrl === _ZAP._defaultoptions.serviceUrl
|
|
67
|
+
&& saved.zakhash === keyFingerprint(_ZAP._defaultoptions.zak);
|
|
47
68
|
}
|
|
48
69
|
/** Puts the ids where the rest of the SDK reads them from. */
|
|
49
70
|
function apply(data) {
|
|
@@ -124,6 +145,7 @@ function registerAppVersion() {
|
|
|
124
145
|
appversion: _ZAP._defaultoptions.appversion,
|
|
125
146
|
identifier: _ZAP._defaultoptions.identifier,
|
|
126
147
|
serviceUrl: _ZAP._defaultoptions.serviceUrl,
|
|
148
|
+
zakhash: keyFingerprint(_ZAP._defaultoptions.zak),
|
|
127
149
|
};
|
|
128
150
|
RESULT_KEYS.forEach(function (key) {
|
|
129
151
|
if (!isEmpty(data[key])) {
|
|
@@ -161,4 +183,4 @@ function clearAppVersion() {
|
|
|
161
183
|
user_defaults.add(STORE_KEY, undefined);
|
|
162
184
|
}
|
|
163
185
|
|
|
164
|
-
export { appVersionFailedForNetwork, applyStoredAppVersion, clearAppVersion, hasAppVersion, registerAppVersion };
|
|
186
|
+
export { appVersionFailedForNetwork, applyStoredAppVersion, clearAppVersion, hasAppVersion, keyFingerprint, registerAppVersion };
|
|
@@ -28,7 +28,22 @@ export declare function getUpdatesFromServer(): Promise<Dict>;
|
|
|
28
28
|
*/
|
|
29
29
|
export declare function restoreServerSettings(): void;
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
31
|
+
* next_check_after as a time: the server's value is milliseconds, either a timestamp or a wait
|
|
32
|
+
* from now. Anything below 1e12 (2001 as a timestamp) can only be a wait.
|
|
33
|
+
*/
|
|
34
|
+
export declare function nextCheckTime(value: unknown, now: number): number;
|
|
35
|
+
/**
|
|
36
|
+
* Asks for the server settings now if the device is registered, then schedules the next ask
|
|
37
|
+
* for the time the answer gave in next_check_after. On a first visit the ids don't exist yet;
|
|
38
|
+
* registerDeviceWithApptics calls this as soon as device/add succeeds.
|
|
33
39
|
*/
|
|
34
40
|
export declare function refreshServerSettings(): void;
|
|
41
|
+
/**
|
|
42
|
+
* Start-up's getsdkconfig. Asked on a first visit and on the first page load in each tab; any
|
|
43
|
+
* other load (a reload, a link to another page of the site, back/forward) uses the saved answer
|
|
44
|
+
* and waits for its next_check_after, unless that has already passed. Nothing happens if one has
|
|
45
|
+
* gone out already on this load (after device/add).
|
|
46
|
+
*/
|
|
47
|
+
export declare function startServerSettingChecks(): void;
|
|
48
|
+
/** reset(): no more checks, and the next init() asks again straight away. */
|
|
49
|
+
export declare function stopServerSettingChecks(): void;
|