@cloudcare/browser-core 3.1.2 → 3.1.3

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.
Files changed (51) hide show
  1. package/cjs/browser/htmlDomUtils.js +4 -1
  2. package/cjs/browser/htmlDomUtils.js.map +1 -1
  3. package/cjs/configuration/configuration.js +2 -1
  4. package/cjs/configuration/configuration.js.map +1 -1
  5. package/cjs/dataMap.js +7 -3
  6. package/cjs/dataMap.js.map +1 -1
  7. package/cjs/helper/errorTools.js +2 -1
  8. package/cjs/helper/errorTools.js.map +1 -1
  9. package/cjs/helper/monitor.js +1 -0
  10. package/cjs/helper/monitor.js.map +1 -1
  11. package/cjs/helper/serialisation/rowData.js +7 -5
  12. package/cjs/helper/serialisation/rowData.js.map +1 -1
  13. package/cjs/helper/tools.js +1 -0
  14. package/cjs/helper/tools.js.map +1 -1
  15. package/cjs/transport/batch.js +23 -10
  16. package/cjs/transport/batch.js.map +1 -1
  17. package/cjs/transport/httpRequest.js +31 -12
  18. package/cjs/transport/httpRequest.js.map +1 -1
  19. package/cjs/transport/startBatchWithReplica.js +2 -2
  20. package/cjs/transport/startBatchWithReplica.js.map +1 -1
  21. package/esm/browser/htmlDomUtils.js +3 -1
  22. package/esm/browser/htmlDomUtils.js.map +1 -1
  23. package/esm/configuration/configuration.js +2 -1
  24. package/esm/configuration/configuration.js.map +1 -1
  25. package/esm/dataMap.js +7 -3
  26. package/esm/dataMap.js.map +1 -1
  27. package/esm/helper/errorTools.js +1 -0
  28. package/esm/helper/errorTools.js.map +1 -1
  29. package/esm/helper/monitor.js +1 -0
  30. package/esm/helper/monitor.js.map +1 -1
  31. package/esm/helper/serialisation/rowData.js +8 -6
  32. package/esm/helper/serialisation/rowData.js.map +1 -1
  33. package/esm/helper/tools.js +1 -0
  34. package/esm/helper/tools.js.map +1 -1
  35. package/esm/transport/batch.js +24 -11
  36. package/esm/transport/batch.js.map +1 -1
  37. package/esm/transport/httpRequest.js +31 -12
  38. package/esm/transport/httpRequest.js.map +1 -1
  39. package/esm/transport/startBatchWithReplica.js +2 -2
  40. package/esm/transport/startBatchWithReplica.js.map +1 -1
  41. package/package.json +2 -2
  42. package/src/browser/htmlDomUtils.js +3 -1
  43. package/src/configuration/configuration.js +2 -1
  44. package/src/dataMap.js +9 -3
  45. package/src/helper/errorTools.js +1 -0
  46. package/src/helper/monitor.js +1 -0
  47. package/src/helper/serialisation/rowData.js +9 -6
  48. package/src/helper/tools.js +1 -0
  49. package/src/transport/batch.js +28 -12
  50. package/src/transport/httpRequest.js +46 -11
  51. package/src/transport/startBatchWithReplica.js +3 -1
@@ -13,10 +13,24 @@ function addBatchPrecision(url) {
13
13
  if (!url) return url
14
14
  return url + (url.indexOf('?') === -1 ? '?' : '&') + 'precision=ms'
15
15
  }
16
- export function createHttpRequest(endpointUrl, bytesLimit, reportError) {
16
+ export function createHttpRequest(
17
+ endpointUrl,
18
+ bytesLimit,
19
+ sendContentTypeByJson,
20
+ reportError
21
+ ) {
22
+ var contentType = sendContentTypeByJson
23
+ ? 'application/json; charset=UTF-8'
24
+ : undefined
17
25
  var retryState = newRetryState()
18
26
  var sendStrategyForRetry = function (payload, onResponse) {
19
- return fetchKeepAliveStrategy(endpointUrl, bytesLimit, payload, onResponse)
27
+ return fetchKeepAliveStrategy(
28
+ endpointUrl,
29
+ bytesLimit,
30
+ contentType,
31
+ payload,
32
+ onResponse
33
+ )
20
34
  }
21
35
 
22
36
  return {
@@ -34,19 +48,28 @@ export function createHttpRequest(endpointUrl, bytesLimit, reportError) {
34
48
  * keep using sendBeaconStrategy on exit
35
49
  */
36
50
  sendOnExit: function (payload) {
37
- sendBeaconStrategy(endpointUrl, bytesLimit, payload)
51
+ sendBeaconStrategy(endpointUrl, bytesLimit, contentType, payload)
38
52
  }
39
53
  }
40
54
  }
41
55
 
42
- function sendBeaconStrategy(endpointUrl, bytesLimit, payload) {
56
+ function sendBeaconStrategy(endpointUrl, bytesLimit, contentType, payload) {
43
57
  var data = payload.data
44
58
  var bytesCount = payload.bytesCount
45
59
  var url = addBatchPrecision(endpointUrl)
46
60
  var canUseBeacon = !!navigator.sendBeacon && bytesCount < bytesLimit
47
61
  if (canUseBeacon) {
48
62
  try {
49
- var isQueued = navigator.sendBeacon(url, data)
63
+ var beaconData
64
+ if (contentType) {
65
+ beaconData = new Blob([data], {
66
+ type: contentType
67
+ })
68
+ } else {
69
+ beaconData = data
70
+ }
71
+
72
+ var isQueued = navigator.sendBeacon(url, beaconData)
50
73
 
51
74
  if (isQueued) {
52
75
  return
@@ -55,12 +78,13 @@ function sendBeaconStrategy(endpointUrl, bytesLimit, payload) {
55
78
  // reportBeaconError(e)
56
79
  }
57
80
  }
58
- sendXHR(url, data)
81
+ sendXHR(url, contentType, data)
59
82
  }
60
83
 
61
84
  export function fetchKeepAliveStrategy(
62
85
  endpointUrl,
63
86
  bytesLimit,
87
+ contentType,
64
88
  payload,
65
89
  onResponse
66
90
  ) {
@@ -69,12 +93,18 @@ export function fetchKeepAliveStrategy(
69
93
  var url = addBatchPrecision(endpointUrl)
70
94
  var canUseKeepAlive = isKeepAliveSupported() && bytesCount < bytesLimit
71
95
  if (canUseKeepAlive) {
72
- fetch(url, {
96
+ var fetchOption = {
73
97
  method: 'POST',
74
98
  body: data,
75
99
  keepalive: true,
76
100
  mode: 'cors'
77
- }).then(
101
+ }
102
+ if (contentType) {
103
+ fetchOption.headers = {
104
+ 'Content-Type': contentType
105
+ }
106
+ }
107
+ fetch(url, fetchOption).then(
78
108
  monitor(function (response) {
79
109
  if (typeof onResponse === 'function') {
80
110
  onResponse({ status: response.status, type: response.type })
@@ -82,11 +112,11 @@ export function fetchKeepAliveStrategy(
82
112
  }),
83
113
  monitor(function () {
84
114
  // failed to queue the request
85
- sendXHR(url, data, onResponse)
115
+ sendXHR(url, contentType, data, onResponse)
86
116
  })
87
117
  )
88
118
  } else {
89
- sendXHR(url, data, onResponse)
119
+ sendXHR(url, contentType, data, onResponse)
90
120
  }
91
121
  }
92
122
 
@@ -99,9 +129,14 @@ function isKeepAliveSupported() {
99
129
  }
100
130
  }
101
131
 
102
- function sendXHR(url, data, onResponse) {
132
+ function sendXHR(url, contentType, data, onResponse) {
103
133
  const request = new XMLHttpRequest()
104
134
  request.open('POST', url, true)
135
+ if (contentType) {
136
+ //application/json; charset=UTF-8
137
+ request.setRequestHeader('Content-Type', contentType)
138
+ }
139
+
105
140
  addEventListener(
106
141
  request,
107
142
  'loadend',
@@ -15,6 +15,7 @@ export function startBatchWithReplica(
15
15
  createHttpRequest(
16
16
  endpointUrl,
17
17
  configuration.batchBytesLimit,
18
+ configuration.sendContentTypeByJson,
18
19
  reportError
19
20
  ),
20
21
  createFlushController({
@@ -24,7 +25,8 @@ export function startBatchWithReplica(
24
25
  pageExitObservable: pageExitObservable,
25
26
  sessionExpireObservable: sessionExpireObservable
26
27
  }),
27
- configuration.messageBytesLimit
28
+ configuration.messageBytesLimit,
29
+ configuration.sendContentTypeByJson
28
30
  )
29
31
  }
30
32