@cloudcare/browser-core 3.2.28 → 3.2.29

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 (47) hide show
  1. package/cjs/dataMap.js +1 -0
  2. package/cjs/dataMap.js.map +1 -1
  3. package/cjs/index.js +7 -0
  4. package/cjs/index.js.map +1 -1
  5. package/cjs/session/sessionConstants.js +5 -1
  6. package/cjs/session/sessionConstants.js.map +1 -1
  7. package/cjs/session/sessionInCookie.js +1 -1
  8. package/cjs/session/sessionInCookie.js.map +1 -1
  9. package/cjs/session/sessionInLocalStorage.js +1 -1
  10. package/cjs/session/sessionInLocalStorage.js.map +1 -1
  11. package/cjs/session/sessionStore.js +18 -5
  12. package/cjs/session/sessionStore.js.map +1 -1
  13. package/cjs/session/sessionStoreOperations.js +34 -8
  14. package/cjs/session/sessionStoreOperations.js.map +1 -1
  15. package/cjs/transport/batch.js +3 -1
  16. package/cjs/transport/batch.js.map +1 -1
  17. package/cjs/transport/httpRequest.js +40 -6
  18. package/cjs/transport/httpRequest.js.map +1 -1
  19. package/esm/dataMap.js +1 -0
  20. package/esm/dataMap.js.map +1 -1
  21. package/esm/index.js +1 -1
  22. package/esm/index.js.map +1 -1
  23. package/esm/session/sessionConstants.js +4 -0
  24. package/esm/session/sessionConstants.js.map +1 -1
  25. package/esm/session/sessionInCookie.js +2 -2
  26. package/esm/session/sessionInCookie.js.map +1 -1
  27. package/esm/session/sessionInLocalStorage.js +2 -2
  28. package/esm/session/sessionInLocalStorage.js.map +1 -1
  29. package/esm/session/sessionStore.js +18 -5
  30. package/esm/session/sessionStore.js.map +1 -1
  31. package/esm/session/sessionStoreOperations.js +34 -9
  32. package/esm/session/sessionStoreOperations.js.map +1 -1
  33. package/esm/transport/batch.js +3 -1
  34. package/esm/transport/batch.js.map +1 -1
  35. package/esm/transport/httpRequest.js +40 -6
  36. package/esm/transport/httpRequest.js.map +1 -1
  37. package/package.json +2 -2
  38. package/src/dataMap.js +1 -0
  39. package/src/index.js +2 -1
  40. package/src/session/sessionConstants.js +4 -0
  41. package/src/session/sessionInCookie.js +3 -2
  42. package/src/session/sessionInLocalStorage.js +4 -2
  43. package/src/session/sessionStore.js +27 -8
  44. package/src/session/sessionStoreOperations.js +31 -13
  45. package/src/transport/batch.js +3 -1
  46. package/src/transport/httpRequest.js +53 -14
  47. package/types/index.d.ts +16 -2
@@ -104,22 +104,33 @@ export function fetchKeepAliveStrategy(
104
104
  keepalive: true,
105
105
  mode: 'cors'
106
106
  }
107
+ const headers = {}
108
+
107
109
  if (payload.type) {
108
- fetchOption.headers = {
109
- 'Content-Type': payload.type
110
- }
110
+ headers['Content-Type'] = payload.type
111
111
  }
112
- fetch(url, fetchOption).then(
113
- monitor(function (response) {
114
- if (typeof onResponse === 'function') {
115
- onResponse({ status: response.status, type: response.type })
116
- }
117
- }),
118
- monitor(function () {
119
- // failed to queue the request
120
- sendXHR(url, payload, onResponse)
121
- })
122
- )
112
+ if (payload.outputBase64Head) {
113
+ headers['x-base64-head'] = payload.outputBase64Head
114
+ }
115
+ if (payload.outputBase64Tail) {
116
+ headers['x-base64-tail'] = payload.outputBase64Tail
117
+ }
118
+ if (Object.keys(headers).length) {
119
+ fetchOption.headers = headers
120
+ }
121
+ fetch(url, fetchOption)
122
+ .then(
123
+ monitor(function (response) {
124
+ if (typeof onResponse === 'function') {
125
+ onResponse({ status: response.status, type: response.type })
126
+ }
127
+ })
128
+ )
129
+ .catch(
130
+ monitor(function () {
131
+ fetchStrategy(url, payload, onResponse)
132
+ })
133
+ )
123
134
  } else {
124
135
  sendXHR(url, payload, onResponse)
125
136
  }
@@ -158,3 +169,31 @@ function sendXHR(url, payload, onResponse) {
158
169
  )
159
170
  request.send(data)
160
171
  }
172
+ function fetchStrategy(url, payload, onResponse) {
173
+ const fetchOption = {
174
+ method: 'POST',
175
+ body: payload.data,
176
+ keepalive: true,
177
+ mode: 'cors'
178
+ }
179
+ if (payload.type) {
180
+ fetchOption.headers = {
181
+ 'Content-Type': payload.type
182
+ }
183
+ }
184
+ fetch(url, fetchOption)
185
+ .then(
186
+ monitor(function (response) {
187
+ if (typeof onResponse === 'function') {
188
+ onResponse({ status: response.status, type: response.type })
189
+ }
190
+ })
191
+ )
192
+ .catch(
193
+ monitor(function () {
194
+ if (typeof onResponse === 'function') {
195
+ onResponse({ status: 0 })
196
+ }
197
+ })
198
+ )
199
+ }
package/types/index.d.ts CHANGED
@@ -7,6 +7,8 @@ export interface User {
7
7
  name?: string | undefined
8
8
  [key: string]: unknown
9
9
  }
10
+ export type SessionPersistence = 'cookie' | 'local-storage'
11
+
10
12
  export declare const ConsoleApiName: {
11
13
  readonly log: 'log'
12
14
  readonly debug: 'debug'
@@ -91,6 +93,13 @@ export interface InitConfiguration {
91
93
  * When cookies are not available, you can enable this option to store data in localStorage
92
94
  */
93
95
  allowFallbackToLocalStorage?: boolean | undefined
96
+ /**
97
+ * Which storage strategy to use for persisting sessions. Can be either 'cookie' or 'local-storage'.
98
+ *
99
+ * Important: If you are using the RUM and Logs Browser SDKs, this option must be configured with identical values
100
+ * @default "cookie"
101
+ */
102
+ sessionPersistence?: SessionPersistence | undefined
94
103
  }
95
104
  export enum TraceType {
96
105
  DDTRACE = 'ddtrace',
@@ -118,7 +127,7 @@ export const NodePrivacyLevel = {
118
127
  } as const
119
128
  export type NodePrivacyLevel =
120
129
  (typeof NodePrivacyLevel)[keyof typeof NodePrivacyLevel]
121
-
130
+ export type OriginMatchOption = string | RegExp
122
131
  export type MatchOption = string | RegExp | ((value: string) => boolean)
123
132
  export type TracingOption = {
124
133
  match: MatchOption
@@ -145,11 +154,16 @@ export interface RumBaseInitConfiguration extends InitConfiguration {
145
154
  * https://docs.truewatch.com/security/page-performance/#_3
146
155
  */
147
156
  excludedActivityUrls?: MatchOption[] | undefined
157
+ /**
158
+ * List of all requests allowed to inject trace collector required headers. For example:
159
+ ["https://api.example.com/test", /https:\\/\\/.*\\.my-api-domain\\.com/, (url) => { return true }].
160
+ */
161
+ allowedTracingUrls?: Array<MatchOption | TracingOption> | undefined
148
162
  /**
149
163
  * List of all requests allowed to inject trace collector required headers. Can be the request origin or a regex. Origin: protocol (including ://), domain name (or IP address) [and port number]. For example:
150
164
  ["https://api.example.com", /https:\\/\\/.*\\.my-api-domain\\.com/].
151
165
  */
152
- allowedTracingUrls?: Array<MatchOption | TracingOption> | undefined
166
+ allowedTracingOrigins?: Array<OriginMatchOption> | undefined
153
167
  defaultPrivacyLevel?: DefaultPrivacyLevel | undefined
154
168
  /**
155
169
  * Error session compensation sample rate: