@cloudcare/browser-core 3.2.39 → 3.2.40
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/cjs/browser/xhrObservable.js +13 -0
- package/cjs/browser/xhrObservable.js.map +1 -1
- package/cjs/configuration/remoteConfiguration.js +7 -2
- package/cjs/configuration/remoteConfiguration.js.map +1 -1
- package/cjs/dataMap.js +2 -0
- package/cjs/dataMap.js.map +1 -1
- package/cjs/helper/deviceInfo.js +2 -1
- package/cjs/helper/deviceInfo.js.map +1 -1
- package/cjs/index.js +7 -0
- package/cjs/index.js.map +1 -1
- package/cjs/session/sessionConstants.js +2 -1
- package/cjs/session/sessionConstants.js.map +1 -1
- package/cjs/session/sessionManagement.js +13 -3
- package/cjs/session/sessionManagement.js.map +1 -1
- package/cjs/session/sessionStore.js +1 -1
- package/cjs/session/sessionStore.js.map +1 -1
- package/cjs/transport/flushController.js +2 -2
- package/cjs/transport/flushController.js.map +1 -1
- package/esm/browser/xhrObservable.js +13 -0
- package/esm/browser/xhrObservable.js.map +1 -1
- package/esm/configuration/remoteConfiguration.js +6 -2
- package/esm/configuration/remoteConfiguration.js.map +1 -1
- package/esm/dataMap.js +2 -0
- package/esm/dataMap.js.map +1 -1
- package/esm/helper/deviceInfo.js +2 -1
- package/esm/helper/deviceInfo.js.map +1 -1
- package/esm/index.js +1 -1
- package/esm/index.js.map +1 -1
- package/esm/session/sessionConstants.js +1 -0
- package/esm/session/sessionConstants.js.map +1 -1
- package/esm/session/sessionManagement.js +14 -4
- package/esm/session/sessionManagement.js.map +1 -1
- package/esm/session/sessionStore.js +1 -1
- package/esm/session/sessionStore.js.map +1 -1
- package/esm/transport/flushController.js +2 -2
- package/esm/transport/flushController.js.map +1 -1
- package/package.json +3 -3
- package/src/browser/xhrObservable.js +17 -2
- package/src/configuration/remoteConfiguration.js +13 -2
- package/src/dataMap.js +2 -0
- package/src/helper/deviceInfo.js +2 -1
- package/src/index.js +2 -1
- package/src/session/sessionConstants.js +1 -0
- package/src/session/sessionManagement.js +14 -4
- package/src/session/sessionStore.js +1 -1
- package/src/transport/flushController.js +6 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flushController.js","names":["Observable","clearTimeout","setTimeout","createFlushController","_ref","messagesLimit","bytesLimit","durationLimit","pageExitObservable","sessionExpireObservable","subscribe","event","flush","reason","
|
|
1
|
+
{"version":3,"file":"flushController.js","names":["Observable","clearTimeout","setTimeout","createFlushController","_ref","messagesLimit","bytesLimit","durationLimit","pageExitObservable","sessionExpireObservable","pageExitSubscription","subscribe","event","flush","reason","sessionExpireSubscription","flushObservable","unsubscribe","currentBytesCount","currentMessagesCount","flushReason","messagesCount","bytesCount","cancelDurationLimitTimeout","notify","durationLimitTimeoutId","scheduleDurationLimitTimeout","undefined","getMessagesCount","notifyBeforeAddMessage","estimatedMessageBytesCount","notifyAfterAddMessage","messageBytesCountDiff","notifyAfterRemoveMessage","messageBytesCount"],"sources":["../../src/transport/flushController.js"],"sourcesContent":["import { Observable } from '../helper/observable'\nimport { clearTimeout, setTimeout } from '../helper/timer'\n\n// type FlushReason = PageExitReason | 'duration_limit' | 'bytes_limit' | 'messages_limit' | 'session_expire'\n\n/**\n * Returns a \"flush controller\", responsible of notifying when flushing a pool of pending data needs\n * to happen. The implementation is designed to support both synchronous and asynchronous usages,\n * but relies on invariants described in each method documentation to keep a coherent state.\n */\nexport function createFlushController({\n messagesLimit,\n bytesLimit,\n durationLimit,\n pageExitObservable,\n sessionExpireObservable\n}) {\n var pageExitSubscription = pageExitObservable.subscribe(function (event) {\n return flush(event.reason)\n })\n var sessionExpireSubscription = sessionExpireObservable.subscribe(\n function () {\n return flush('session_expire')\n }\n )\n var flushObservable = new Observable(function () {\n return function () {\n pageExitSubscription.unsubscribe()\n sessionExpireSubscription.unsubscribe()\n }\n })\n\n var currentBytesCount = 0\n var currentMessagesCount = 0\n\n function flush(flushReason) {\n if (currentMessagesCount === 0) {\n return\n }\n\n var messagesCount = currentMessagesCount\n var bytesCount = currentBytesCount\n\n currentMessagesCount = 0\n currentBytesCount = 0\n cancelDurationLimitTimeout()\n\n flushObservable.notify({\n reason: flushReason,\n messagesCount: messagesCount,\n bytesCount: bytesCount\n })\n }\n\n var durationLimitTimeoutId\n function scheduleDurationLimitTimeout() {\n if (durationLimitTimeoutId === undefined) {\n durationLimitTimeoutId = setTimeout(function () {\n flush('duration_limit')\n }, durationLimit)\n }\n }\n\n function cancelDurationLimitTimeout() {\n clearTimeout(durationLimitTimeoutId)\n durationLimitTimeoutId = undefined\n }\n\n return {\n flushObservable: flushObservable,\n getMessagesCount: function () {\n return currentMessagesCount\n },\n\n /**\n * Notifies that a message will be added to a pool of pending messages waiting to be flushed.\n *\n * This function needs to be called synchronously, right before adding the message, so no flush\n * event can happen after `notifyBeforeAddMessage` and before adding the message.\n */\n notifyBeforeAddMessage: function (estimatedMessageBytesCount) {\n if (currentBytesCount + estimatedMessageBytesCount >= bytesLimit) {\n flush('bytes_limit')\n }\n // Consider the message to be added now rather than in `notifyAfterAddMessage`, because if no\n // message was added yet and `notifyAfterAddMessage` is called asynchronously, we still want\n // to notify when a flush is needed (for example on page exit).\n currentMessagesCount += 1\n currentBytesCount += estimatedMessageBytesCount\n scheduleDurationLimitTimeout()\n },\n\n /**\n * Notifies that a message *was* added to a pool of pending messages waiting to be flushed.\n *\n * This function can be called asynchronously after the message was added, but in this case it\n * should not be called if a flush event occurred in between.\n */\n notifyAfterAddMessage: function (messageBytesCountDiff) {\n if (messageBytesCountDiff === undefined) {\n messageBytesCountDiff = 0\n }\n currentBytesCount += messageBytesCountDiff\n\n if (currentMessagesCount >= messagesLimit) {\n flush('messages_limit')\n } else if (currentBytesCount >= bytesLimit) {\n flush('bytes_limit')\n }\n },\n\n /**\n * Notifies that a message was removed from a pool of pending messages waiting to be flushed.\n *\n * This function needs to be called synchronously, right after removing the message, so no flush\n * event can happen after removing the message and before `notifyAfterRemoveMessage`.\n *\n * @param messageBytesCount: the message bytes count that was added to the pool. Should\n * correspond to the sum of bytes counts passed to `notifyBeforeAddMessage` and\n * `notifyAfterAddMessage`.\n */\n notifyAfterRemoveMessage: function (messageBytesCount) {\n currentBytesCount -= messageBytesCount\n currentMessagesCount -= 1\n if (currentMessagesCount === 0) {\n cancelDurationLimitTimeout()\n }\n }\n }\n}\n"],"mappings":"AAAA,SAASA,UAAU,QAAQ,sBAAsB;AACjD,SAASC,YAAY,EAAEC,UAAU,QAAQ,iBAAiB;;AAE1D;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,qBAAqBA,CAAAC,IAAA,EAMlC;EAAA,IALDC,aAAa,GAAAD,IAAA,CAAbC,aAAa;IACbC,UAAU,GAAAF,IAAA,CAAVE,UAAU;IACVC,aAAa,GAAAH,IAAA,CAAbG,aAAa;IACbC,kBAAkB,GAAAJ,IAAA,CAAlBI,kBAAkB;IAClBC,uBAAuB,GAAAL,IAAA,CAAvBK,uBAAuB;EAEvB,IAAIC,oBAAoB,GAAGF,kBAAkB,CAACG,SAAS,CAAC,UAAUC,KAAK,EAAE;IACvE,OAAOC,KAAK,CAACD,KAAK,CAACE,MAAM,CAAC;EAC5B,CAAC,CAAC;EACF,IAAIC,yBAAyB,GAAGN,uBAAuB,CAACE,SAAS,CAC/D,YAAY;IACV,OAAOE,KAAK,CAAC,gBAAgB,CAAC;EAChC,CACF,CAAC;EACD,IAAIG,eAAe,GAAG,IAAIhB,UAAU,CAAC,YAAY;IAC/C,OAAO,YAAY;MACjBU,oBAAoB,CAACO,WAAW,CAAC,CAAC;MAClCF,yBAAyB,CAACE,WAAW,CAAC,CAAC;IACzC,CAAC;EACH,CAAC,CAAC;EAEF,IAAIC,iBAAiB,GAAG,CAAC;EACzB,IAAIC,oBAAoB,GAAG,CAAC;EAE5B,SAASN,KAAKA,CAACO,WAAW,EAAE;IAC1B,IAAID,oBAAoB,KAAK,CAAC,EAAE;MAC9B;IACF;IAEA,IAAIE,aAAa,GAAGF,oBAAoB;IACxC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ACzCQ,KAAK,CAAC,gBAAgB,CAAC;MACzB,CAAC,MAAM,IAAIK,iBAAiB,IAAIZ,UAAU,EAAE;QAC1CO,KAAK,CAAC,aAAa,CAAC;MACtB;IACF,CAAC;IAED;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;IACIoB,wBAAwB,EAAE,SAA1BA,wBAAwBA,CAAYC,iBAAiB,EAAE;MACrDhB,iBAAiB,IAAIgB,iBAAiB;MACtCf,oBAAoB,IAAI,CAAC;MACzB,IAAIA,oBAAoB,KAAK,CAAC,EAAE;QAC9BI,0BAA0B,CAAC,CAAC;MAC9B;IACF;EACF,CAAC;AACH","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudcare/browser-core",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.40",
|
|
4
4
|
"main": "cjs/index.js",
|
|
5
5
|
"module": "esm/index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -15,11 +15,11 @@
|
|
|
15
15
|
"sdk"
|
|
16
16
|
],
|
|
17
17
|
"repository": {
|
|
18
|
-
"url": "https://github.com/
|
|
18
|
+
"url": "https://github.com/GuanceCloud/datakit-js",
|
|
19
19
|
"type": "git",
|
|
20
20
|
"directory": "packages/core"
|
|
21
21
|
},
|
|
22
22
|
"author": "dataflux",
|
|
23
23
|
"license": "MIT",
|
|
24
|
-
"gitHead": "
|
|
24
|
+
"gitHead": "73b515d510f5195a7d748a767c5b6685bab67606"
|
|
25
25
|
}
|
|
@@ -28,7 +28,11 @@ function createXhrObservable() {
|
|
|
28
28
|
},
|
|
29
29
|
{ computeHandlingStack: true }
|
|
30
30
|
)
|
|
31
|
-
|
|
31
|
+
var setRequestHeaderInstrumentMethod = instrumentMethod(
|
|
32
|
+
XMLHttpRequest.prototype,
|
|
33
|
+
'setRequestHeader',
|
|
34
|
+
setRequestHeaderXhr
|
|
35
|
+
)
|
|
32
36
|
var abortInstrumentMethod = instrumentMethod(
|
|
33
37
|
XMLHttpRequest.prototype,
|
|
34
38
|
'abort',
|
|
@@ -39,6 +43,7 @@ function createXhrObservable() {
|
|
|
39
43
|
openInstrumentMethod.stop()
|
|
40
44
|
sendInstrumentMethod.stop()
|
|
41
45
|
abortInstrumentMethod.stop()
|
|
46
|
+
setRequestHeaderInstrumentMethod.stop()
|
|
42
47
|
}
|
|
43
48
|
})
|
|
44
49
|
}
|
|
@@ -53,7 +58,17 @@ function openXhr(params) {
|
|
|
53
58
|
url: normalizeUrl(String(url))
|
|
54
59
|
})
|
|
55
60
|
}
|
|
56
|
-
|
|
61
|
+
function setRequestHeaderXhr(params) {
|
|
62
|
+
var xhr = params.target
|
|
63
|
+
var headerKey = params.parameters[0]
|
|
64
|
+
var headerValue = params.parameters[1]
|
|
65
|
+
var context = xhrContexts.get(xhr)
|
|
66
|
+
if (context && headerKey) {
|
|
67
|
+
var requestHeaderContexts = context.requestHeaderContexts || {}
|
|
68
|
+
requestHeaderContexts[headerKey] = headerValue
|
|
69
|
+
context.requestHeaderContexts = requestHeaderContexts
|
|
70
|
+
}
|
|
71
|
+
}
|
|
57
72
|
function sendXhr(params, observable) {
|
|
58
73
|
var xhr = params.target
|
|
59
74
|
var handlingStack = params.handlingStack
|
|
@@ -5,7 +5,8 @@ import { objectEntries, getType } from '../helper/tools'
|
|
|
5
5
|
export function fetchAndApplyRemoteConfiguration(initConfiguration, callback) {
|
|
6
6
|
fetchRemoteConfiguration(initConfiguration, (remoteInitConfiguration) => {
|
|
7
7
|
callback(
|
|
8
|
-
applyRemoteConfiguration(initConfiguration, remoteInitConfiguration)
|
|
8
|
+
applyRemoteConfiguration(initConfiguration, remoteInitConfiguration),
|
|
9
|
+
getSimpleRemoteConfiguration(initConfiguration, remoteInitConfiguration)
|
|
9
10
|
)
|
|
10
11
|
})
|
|
11
12
|
}
|
|
@@ -48,7 +49,7 @@ function modificationByFieldsPath(remoteConfiguration, modifiableFieldPaths) {
|
|
|
48
49
|
})
|
|
49
50
|
return result
|
|
50
51
|
}
|
|
51
|
-
export function
|
|
52
|
+
export function getSimpleRemoteConfiguration(
|
|
52
53
|
initConfiguration,
|
|
53
54
|
remoteInitConfiguration
|
|
54
55
|
) {
|
|
@@ -70,6 +71,16 @@ export function applyRemoteConfiguration(
|
|
|
70
71
|
simpleRemoteInitConfiguration[simpleKey] = remoteInitConfiguration[key]
|
|
71
72
|
}
|
|
72
73
|
}
|
|
74
|
+
return simpleRemoteInitConfiguration
|
|
75
|
+
}
|
|
76
|
+
export function applyRemoteConfiguration(
|
|
77
|
+
initConfiguration,
|
|
78
|
+
remoteInitConfiguration
|
|
79
|
+
) {
|
|
80
|
+
const simpleRemoteInitConfiguration = getSimpleRemoteConfiguration(
|
|
81
|
+
initConfiguration,
|
|
82
|
+
remoteInitConfiguration
|
|
83
|
+
)
|
|
73
84
|
return {
|
|
74
85
|
...initConfiguration,
|
|
75
86
|
...modificationByFieldsPath(
|
package/src/dataMap.js
CHANGED
|
@@ -12,6 +12,7 @@ export var commonTags = {
|
|
|
12
12
|
user_name: 'user.name',
|
|
13
13
|
session_id: 'session.id',
|
|
14
14
|
session_type: 'session.type',
|
|
15
|
+
session_is_forced: 'session.is_forced_session',
|
|
15
16
|
session_sampling: 'session.is_sampling',
|
|
16
17
|
is_signin: 'user.is_signin',
|
|
17
18
|
os: 'device.os',
|
|
@@ -24,6 +25,7 @@ export var commonTags = {
|
|
|
24
25
|
network_type: 'device.network_type',
|
|
25
26
|
time_zone: 'device.time_zone',
|
|
26
27
|
device: 'device.device',
|
|
28
|
+
user_agent: 'device.user_agent',
|
|
27
29
|
view_id: 'view.id',
|
|
28
30
|
view_referrer: 'view.referrer',
|
|
29
31
|
view_url: 'view.url',
|
package/src/helper/deviceInfo.js
CHANGED
|
@@ -601,7 +601,8 @@ if (typeof window !== 'undefined') {
|
|
|
601
601
|
screenSize: window.screen.width + '*' + window.screen.height,
|
|
602
602
|
networkType: MethodLibrary.getNetwork(),
|
|
603
603
|
device: MethodLibrary.getDeviceType(),
|
|
604
|
-
timeZone: MethodLibrary.getTimeZone()
|
|
604
|
+
timeZone: MethodLibrary.getTimeZone(),
|
|
605
|
+
userAgent: VariableLibrary.navigator.userAgent || ''
|
|
605
606
|
}
|
|
606
607
|
}
|
|
607
608
|
export var deviceInfo = _deviceInfo
|
package/src/index.js
CHANGED
|
@@ -46,7 +46,8 @@ export {
|
|
|
46
46
|
export {
|
|
47
47
|
SESSION_TIME_OUT_DELAY,
|
|
48
48
|
SESSION_STORE_KEY,
|
|
49
|
-
SessionPersistence
|
|
49
|
+
SessionPersistence,
|
|
50
|
+
SESSION_NOT_TRACKED
|
|
50
51
|
} from './session/sessionConstants'
|
|
51
52
|
export { STORAGE_POLL_DELAY } from './session/sessionStore'
|
|
52
53
|
export * from './transport'
|
|
@@ -2,6 +2,7 @@ import { ONE_HOUR, ONE_MINUTE } from '../helper/tools'
|
|
|
2
2
|
export var SESSION_TIME_OUT_DELAY = 4 * ONE_HOUR
|
|
3
3
|
export var SESSION_EXPIRATION_DELAY = 15 * ONE_MINUTE
|
|
4
4
|
export var SESSION_STORE_KEY = '_gc_s'
|
|
5
|
+
export const SESSION_NOT_TRACKED = '0'
|
|
5
6
|
export const SessionPersistence = {
|
|
6
7
|
COOKIE: 'cookie',
|
|
7
8
|
LOCAL_STORAGE: 'local-storage'
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
addEventListeners
|
|
8
8
|
} from '../browser/addEventListener'
|
|
9
9
|
import { clearInterval, setInterval } from '../helper/timer'
|
|
10
|
-
import { SESSION_TIME_OUT_DELAY } from './sessionConstants'
|
|
10
|
+
import { SESSION_TIME_OUT_DELAY, SESSION_NOT_TRACKED } from './sessionConstants'
|
|
11
11
|
import { startSessionStore } from './sessionStore'
|
|
12
12
|
|
|
13
13
|
export const VISIBILITY_CHECK_DELAY = ONE_MINUTE
|
|
@@ -62,10 +62,20 @@ export function startSessionManager(
|
|
|
62
62
|
})
|
|
63
63
|
|
|
64
64
|
function buildSessionContext() {
|
|
65
|
+
const session = sessionStore.getSession()
|
|
66
|
+
if (!session) {
|
|
67
|
+
return {
|
|
68
|
+
id: 'invalid',
|
|
69
|
+
trackingType: SESSION_NOT_TRACKED,
|
|
70
|
+
isSessionForced: false,
|
|
71
|
+
hasError: false
|
|
72
|
+
}
|
|
73
|
+
}
|
|
65
74
|
return {
|
|
66
|
-
id:
|
|
67
|
-
trackingType:
|
|
68
|
-
hasError: !!
|
|
75
|
+
id: session.id,
|
|
76
|
+
trackingType: session[productKey],
|
|
77
|
+
hasError: !!session.hasError,
|
|
78
|
+
isSessionForced: !!session.forcedSession
|
|
69
79
|
}
|
|
70
80
|
}
|
|
71
81
|
|
|
@@ -15,12 +15,14 @@ export function createFlushController({
|
|
|
15
15
|
pageExitObservable,
|
|
16
16
|
sessionExpireObservable
|
|
17
17
|
}) {
|
|
18
|
-
pageExitObservable.subscribe(function (event) {
|
|
18
|
+
var pageExitSubscription = pageExitObservable.subscribe(function (event) {
|
|
19
19
|
return flush(event.reason)
|
|
20
20
|
})
|
|
21
|
-
sessionExpireObservable.subscribe(
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
var sessionExpireSubscription = sessionExpireObservable.subscribe(
|
|
22
|
+
function () {
|
|
23
|
+
return flush('session_expire')
|
|
24
|
+
}
|
|
25
|
+
)
|
|
24
26
|
var flushObservable = new Observable(function () {
|
|
25
27
|
return function () {
|
|
26
28
|
pageExitSubscription.unsubscribe()
|