@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
|
@@ -1,7 +1,7 @@
|
|
|
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
|
// Generated by scripts/register-version.mjs — do not edit by hand.
|
|
3
3
|
// The framework id Apptics issued for this SDK, from POST /sdk/web/v1/framework/addversion
|
|
4
|
-
// (version 2.0.0
|
|
5
|
-
const FRAMEWORK_ID =
|
|
4
|
+
// (version 2.0.0, platform Browser). Regenerated on every npm pack.
|
|
5
|
+
const FRAMEWORK_ID = 6012;
|
|
6
6
|
|
|
7
7
|
export { FRAMEWORK_ID };
|
package/dist/esm/core/guard.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
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 './state.js';
|
|
3
3
|
import { warnAlways, logFailure } from './logger.js';
|
|
4
|
+
import { markSdkRejection } from './shield.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Calls that run immediately while storage is loading. Everything else is buffered and replayed in order.
|
|
@@ -16,9 +17,14 @@ const RUN_BEFORE_READY = {
|
|
|
16
17
|
// a switch, and a call that hands back the id endTrackApi needs: neither can wait in a queue
|
|
17
18
|
'AppticsApi.configure': true, 'AppticsApi.startTrackApi': true,
|
|
18
19
|
// these wait for ready() themselves, and a queued call would hand back undefined, not a Promise
|
|
19
|
-
'AppticsRemoteConfig.
|
|
20
|
+
'AppticsRemoteConfig.fetchValues': true,
|
|
20
21
|
'AppticsRemoteConfig.setCustomConditionValue': true,
|
|
21
22
|
'Apptics.enableDebug': true, 'Apptics.disableDebug': true,
|
|
23
|
+
// these wait for start-up themselves, for the same reason as remote config's
|
|
24
|
+
'AppticsPushNotification.setEnabled': true,
|
|
25
|
+
'AppticsPushNotification.isEnabled': true,
|
|
26
|
+
'AppticsPushNotification.requestPermission': true,
|
|
27
|
+
// 'AppticsPushNotification.onNotificationClick': true, (held back; see pushnotification/index.ts)
|
|
22
28
|
};
|
|
23
29
|
/**
|
|
24
30
|
* Calls that record or send something, and so are lost when the SDK hasn't started. Calls that only
|
|
@@ -29,7 +35,7 @@ const RUN_BEFORE_READY = {
|
|
|
29
35
|
const NEEDS_INIT = {
|
|
30
36
|
'AppticsEvent.addEvent': true, 'AppticsScreen.inScreen': true, 'AppticsScreen.outScreen': true,
|
|
31
37
|
'AppticsApi.endTrackApi': true, 'AppticsError.trackError': true, 'AppticsUser.setUser': true,
|
|
32
|
-
'Apptics.flush': true, AppticsLogger: true, 'AppticsFeedback.sendFeedback': true,
|
|
38
|
+
'Apptics.flush': true, AppticsLogger: true, 'AppticsFeedback.sendFeedback': true,
|
|
33
39
|
'AppticsRemoteConfig.fetchValues': true,
|
|
34
40
|
};
|
|
35
41
|
/** How a call is named in a message: every public call is named after its object, as `AppticsEvent.addEvent`. */
|
|
@@ -54,7 +60,16 @@ function guard(name, fn) {
|
|
|
54
60
|
return undefined;
|
|
55
61
|
}
|
|
56
62
|
try {
|
|
57
|
-
|
|
63
|
+
var result = fn(...args);
|
|
64
|
+
if (result && typeof result.then === 'function') { // no i18n
|
|
65
|
+
// a rejection the app leaves unhandled is still the SDK's failure, not the app's
|
|
66
|
+
// JS error (lifecycle's unhandledrejection listener)
|
|
67
|
+
return result.then(undefined, function (reason) {
|
|
68
|
+
markSdkRejection(reason);
|
|
69
|
+
throw reason;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return result;
|
|
58
73
|
}
|
|
59
74
|
catch (err) {
|
|
60
75
|
// a public call swallowing its own exception into a debug-gated console line is how
|
package/dist/esm/core/hooks.d.ts
CHANGED
|
@@ -38,7 +38,31 @@ export declare const hooks: {
|
|
|
38
38
|
remoteConfigUserChanged: () => void;
|
|
39
39
|
/**
|
|
40
40
|
* Set by device/index.ts: getsdkconfig is asked now, outside its next_check_after. setUser calls
|
|
41
|
-
* it
|
|
41
|
+
* it for a user whose customer group is not tracked, setTrackingStatus for that user when PII
|
|
42
|
+
* starts or stops, and remote config when getupdates reports a module changed.
|
|
42
43
|
*/
|
|
43
44
|
askServerSettings: () => void;
|
|
45
|
+
/** Set by user/index.ts: whether user/register answered customergrouptracking: false for the active user. */
|
|
46
|
+
activeUserGroupUntracked: () => boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Set by pushnotification/session.ts: the module ids getsdkconfig is asked about in `moduleids`.
|
|
49
|
+
* Push's 16 is what makes the answer carry the `wms` block; without the push entry, none.
|
|
50
|
+
*/
|
|
51
|
+
sdkConfigModuleIds: () => string[];
|
|
52
|
+
/** Set by pushnotification/session.ts: getsdkconfig's push flag or wms block was applied, live or restored. */
|
|
53
|
+
pushConfigChanged: () => void;
|
|
54
|
+
/** Set by pushnotification/session.ts: the visitor's tracking status changed. */
|
|
55
|
+
pushTrackingChanged: () => void;
|
|
56
|
+
/** Set by pushnotification/session.ts: start-up has finished. */
|
|
57
|
+
pushStarted: () => void;
|
|
58
|
+
/** Set by pushnotification/session.ts, so reset() can forget the push session without importing it. */
|
|
59
|
+
resetPush: () => void;
|
|
60
|
+
/** Set by pushnotification/session.ts: device/add's ids are stored, the anonymousid among them. */
|
|
61
|
+
pushDeviceIdsChanged: () => void;
|
|
62
|
+
/** Set by pushnotification/session.ts: init() has begun start-up, so _ZAP._readyPromise exists. */
|
|
63
|
+
pushInitCalled: () => void;
|
|
64
|
+
/** Set by pushnotification/stats.ts, so flush() and the send interval send push stats too. */
|
|
65
|
+
sendPushStats: (forget?: boolean) => Promise<void>;
|
|
66
|
+
/** Set by pushnotification/stats.ts: the app tracked an event, which may be a push's conversion. */
|
|
67
|
+
pushEventTracked: (eventName: string, groupName: string) => void;
|
|
44
68
|
};
|
package/dist/esm/core/hooks.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
|
/**
|
|
3
3
|
* Late-bound calls from lower modules up to the modules above them (see spec §5). device.ts and
|
|
4
4
|
* remotelog/index.ts assign these when they are evaluated; the defaults only run if that module
|
|
@@ -16,6 +16,16 @@ const hooks = {
|
|
|
16
16
|
remoteConfigStarted: () => { },
|
|
17
17
|
remoteConfigUserChanged: () => { },
|
|
18
18
|
askServerSettings: () => { },
|
|
19
|
+
activeUserGroupUntracked: () => false,
|
|
20
|
+
sdkConfigModuleIds: () => [],
|
|
21
|
+
pushConfigChanged: () => { },
|
|
22
|
+
pushTrackingChanged: () => { },
|
|
23
|
+
pushStarted: () => { },
|
|
24
|
+
resetPush: () => { },
|
|
25
|
+
pushDeviceIdsChanged: () => { },
|
|
26
|
+
pushInitCalled: () => { },
|
|
27
|
+
sendPushStats: () => Promise.resolve(),
|
|
28
|
+
pushEventTracked: () => { },
|
|
19
29
|
};
|
|
20
30
|
|
|
21
31
|
export { hooks };
|
package/dist/esm/core/locks.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
|
/**
|
|
3
3
|
* Runs `run` while holding the Web Lock `name`, waiting for it if another tab of this site holds
|
|
4
4
|
* it. Locks are shared by every tab of an origin, which is what keeps two tabs from registering
|
package/dist/esm/core/logger.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 { _ZAP } from './state.js';
|
|
3
3
|
import { each } from './utils.js';
|
|
4
4
|
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The SDK's own failures stay the SDK's. A throw in one of its timers or listeners, or a rejection
|
|
3
|
+
* no one in the SDK waits on, would otherwise reach the page's `error` and `unhandledrejection`
|
|
4
|
+
* events, where the SDK's error tracking records it as the app's JS error and sends it.
|
|
5
|
+
*
|
|
6
|
+
* guard() shields the public calls; shield() and quietly() shield everything the SDK runs later.
|
|
7
|
+
* Element errors (the SDK's script, style and form elements) are told apart by isSdkElement.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Said in the console and nowhere else. An Error is a real failure (a bug, storage refusing), said
|
|
11
|
+
* whether or not debug is on; anything else is one of the SDK's own reasons for not doing
|
|
12
|
+
* something, as "nothing to send", said in debug mode.
|
|
13
|
+
*/
|
|
14
|
+
export declare function sdkFailed(label: string, err: unknown): void;
|
|
15
|
+
/**
|
|
16
|
+
* A callback the SDK hands to the browser (a timer, a listener, a storage or network callback)
|
|
17
|
+
* that never throws into it. A promise it returns is waited on the same way, so an async
|
|
18
|
+
* listener's rejection is not left unhandled either. Wrap once and keep the wrapped function where
|
|
19
|
+
* it is removed again later: removeEventListener needs the same reference.
|
|
20
|
+
*/
|
|
21
|
+
export declare function shield<F extends (...args: any[]) => any>(label: string, fn: F): F;
|
|
22
|
+
/** A promise the SDK starts and does not wait on: its rejection is said in the console, not left unhandled. */
|
|
23
|
+
export declare function quietly(label: string, promise: PromiseLike<unknown> | unknown): void;
|
|
24
|
+
export declare function markSdkRejection(reason: unknown): void;
|
|
25
|
+
export declare function isSdkRejection(reason: unknown): boolean;
|
|
26
|
+
/** Marks the elements the SDK adds to the page; isSdkElement knows them and what is inside them. */
|
|
27
|
+
export declare const SDK_ELEMENT_ATTR = "data-apptics";
|
|
28
|
+
/** Whether an element is the SDK's own: its style, the Quartz script, the feedback form or the recording timer. */
|
|
29
|
+
export declare function isSdkElement(target: unknown): boolean;
|
|
30
|
+
export declare function noteSdkScript(src: string | null | undefined): void;
|
|
31
|
+
export declare function isSdkScript(filename: string | null | undefined): boolean;
|
|
@@ -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
1
|
import { type ApConfig, type EngagementType } from './constants.js';
|
|
2
|
-
import type { DeviceInfo, Dict, QuartzSettings, TrackingStatus, UserInfo } from '../types.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;
|
|
@@ -46,6 +46,10 @@ export interface State {
|
|
|
46
46
|
_remoteConfigReported: boolean;
|
|
47
47
|
/** getsdkconfig module 12. */
|
|
48
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;
|
|
49
53
|
/** getsdkconfig's `quartz` block: screen recording in the feedback form. Off until it says otherwise. */
|
|
50
54
|
_quartz: QuartzSettings;
|
|
51
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';
|
|
@@ -38,6 +38,8 @@ function initialState() {
|
|
|
38
38
|
_remoteConfigEnabled: true,
|
|
39
39
|
_remoteConfigReported: true,
|
|
40
40
|
_feedbackEnabled: true,
|
|
41
|
+
_pushEnabled: false,
|
|
42
|
+
_wmsConfig: null,
|
|
41
43
|
_nextConfigCheck: 0,
|
|
42
44
|
_debugUntil: 0,
|
|
43
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,10 +309,12 @@ const tracking_preference = {
|
|
|
291
309
|
},
|
|
292
310
|
update_status(tracking_status) {
|
|
293
311
|
_ZAP._devicestatus = tracking_status;
|
|
312
|
+
// stored as its number, which earlier builds read back the same way
|
|
313
|
+
var code = trackingStatusCode(tracking_status);
|
|
294
314
|
var track = Object.assign({}, settings.trackinfo && typeof settings.trackinfo === 'object' ? settings.trackinfo : {}); // no i18n
|
|
295
|
-
track.tracking_status =
|
|
315
|
+
track.tracking_status = code;
|
|
296
316
|
if (_ZAP._trackinfo && typeof _ZAP._trackinfo === 'object') { // no i18n
|
|
297
|
-
_ZAP._trackinfo.tracking_status =
|
|
317
|
+
_ZAP._trackinfo.tracking_status = code;
|
|
298
318
|
}
|
|
299
319
|
setSetting('trackinfo', track); // no i18n
|
|
300
320
|
},
|
|
@@ -308,4 +328,4 @@ function getKeyFromDeviceInfo(key) {
|
|
|
308
328
|
return null;
|
|
309
329
|
}
|
|
310
330
|
|
|
311
|
-
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,24 +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.
|
|
142
|
-
// isanonrequired
|
|
143
|
-
//
|
|
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
|
|
144
158
|
if (path == 'regdevice') { // no i18n
|
|
145
|
-
returnVal = '?isanonrequired=
|
|
159
|
+
returnVal = '?isanonrequired=' + isAnonymous() + '&devicestatus=' + deviceStatusFor(tracking_preference.opt_in_status()); // no i18n
|
|
146
160
|
if (!isEmpty(_ZAP._device_info.deviceid)) {
|
|
147
161
|
returnVal += '&deviceid=' + encodeURIComponent(String(_ZAP._device_info.deviceid)); // no i18n
|
|
148
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
|
+
}
|
|
149
167
|
return returnVal + mandatoryParams(returnVal);
|
|
150
168
|
}
|
|
151
169
|
// getsdkconfig carries no deviceid: the user's ids below are what it answers for
|
|
152
170
|
if (path != 'sdkconfig') { // no i18n
|
|
153
|
-
|
|
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])) {
|
|
154
175
|
hooks.refreshDeviceInfo();
|
|
155
176
|
// the device is missing, but appversionid and frameworkid are mandatory regardless:
|
|
156
177
|
// dropping them turns one missing id into a refusal that names the wrong param
|
|
157
178
|
return returnVal + mandatoryParams(returnVal);
|
|
158
179
|
}
|
|
159
|
-
returnVal = '?deviceid=' + encodeURIComponent(String(_ZAP._device_info
|
|
180
|
+
returnVal = (anonymous ? '?anondeviceid=' : '?deviceid=') + encodeURIComponent(String(_ZAP._device_info[key])); // no i18n
|
|
160
181
|
}
|
|
161
182
|
// feedback is attributed to whoever the form's user picker selected, not to the active user:
|
|
162
183
|
// the person reporting may not be the one the app last registered, and may choose Anonymous
|
|
@@ -170,10 +191,12 @@ function getParameters(path) {
|
|
|
170
191
|
}
|
|
171
192
|
return returnVal + mandatoryParams(returnVal);
|
|
172
193
|
}
|
|
173
|
-
// 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
|
|
174
196
|
// them, and refuses userid as EXTRA_PARAM_FOUND; it has no use for them either, since remote
|
|
175
197
|
// config conditions on the user are evaluated here, against the rule set it answers with
|
|
176
|
-
|
|
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
|
|
177
200
|
if (carriesUser && opt_in_status() == AP_TRACKING_STATUS.USAGE_TRACKING_WITH_PII) {
|
|
178
201
|
if (_ZAP._user_info.hasOwnProperty('userid') && !isEmpty(_ZAP._user_info.userid)) { // no i18n
|
|
179
202
|
// getsdkconfig has no deviceid before it, so its userid starts the query
|
|
@@ -184,6 +207,13 @@ function getParameters(path) {
|
|
|
184
207
|
}
|
|
185
208
|
}
|
|
186
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
|
+
}
|
|
187
217
|
return returnVal + mandatoryParams(returnVal);
|
|
188
218
|
}
|
|
189
219
|
/**
|
|
@@ -291,7 +321,7 @@ function settle(path, label, response) {
|
|
|
291
321
|
* nothing orders one behind another.
|
|
292
322
|
*/
|
|
293
323
|
function postToApptics(path, payload, headers, label, extra) {
|
|
294
|
-
var url = getUrlWithParams(path, Object.assign(beginAttempt(path), {}));
|
|
324
|
+
var url = getUrlWithParams(path, Object.assign(beginAttempt(path), extra || {}));
|
|
295
325
|
return makeRequest(url, getConfig('method'), payload, headers).then(function (response) {
|
|
296
326
|
return settle(path, label, response);
|
|
297
327
|
}, function (err) {
|
|
@@ -410,11 +440,12 @@ function getMetaObj() {
|
|
|
410
440
|
};
|
|
411
441
|
}
|
|
412
442
|
/**
|
|
413
|
-
* Calls made after registration need apid/mapid
|
|
414
|
-
*
|
|
415
|
-
*
|
|
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).
|
|
416
447
|
*/
|
|
417
|
-
function rejectIfNoDeviceIds(label) {
|
|
448
|
+
function rejectIfNoDeviceIds(label, path) {
|
|
418
449
|
if (isEmpty(getHeaderParams('apid')) && isEmpty(getHeaderParams('mapid'))) { // no i18n
|
|
419
450
|
hooks.refreshDeviceInfo();
|
|
420
451
|
return Promise.reject(label + ': You must call Apptics.init() first'); // no i18n
|
|
@@ -426,11 +457,28 @@ function rejectIfNoDeviceIds(label) {
|
|
|
426
457
|
hooks.refreshDeviceInfo();
|
|
427
458
|
return Promise.reject(label + ': the device is not registered yet, kept for the next send'); // no i18n
|
|
428
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
|
+
}
|
|
429
466
|
return null;
|
|
430
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
|
+
}
|
|
431
472
|
/** Whether device/add has given this browser its deviceid. */
|
|
432
473
|
function hasDeviceId() {
|
|
433
474
|
return !isEmpty(_ZAP._device_info && _ZAP._device_info.deviceid) || !isEmpty(getKeyFromDeviceInfo('deviceid')); // no i18n
|
|
434
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
|
+
}
|
|
435
483
|
|
|
436
|
-
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
|