@cloudcare/browser-core 3.1.23 → 3.2.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.
Files changed (105) hide show
  1. package/cjs/browser/pageExitObservable.js +1 -1
  2. package/cjs/browser/pageExitObservable.js.map +1 -1
  3. package/cjs/browser/runOnReadyState.js +5 -1
  4. package/cjs/browser/runOnReadyState.js.map +1 -1
  5. package/cjs/console/consoleObservable.js +17 -9
  6. package/cjs/console/consoleObservable.js.map +1 -1
  7. package/cjs/dataMap.js +11 -2
  8. package/cjs/dataMap.js.map +1 -1
  9. package/cjs/helper/boundedBuffer.js +21 -17
  10. package/cjs/helper/boundedBuffer.js.map +1 -1
  11. package/cjs/helper/connectivity.js +16 -0
  12. package/cjs/helper/connectivity.js.map +1 -0
  13. package/cjs/helper/display.js +15 -12
  14. package/cjs/helper/display.js.map +1 -1
  15. package/cjs/helper/displayAlreadyInitializedError.js +13 -0
  16. package/cjs/helper/displayAlreadyInitializedError.js.map +1 -0
  17. package/cjs/helper/encoder.js +43 -0
  18. package/cjs/helper/encoder.js.map +1 -0
  19. package/cjs/helper/lifeCycle.js +0 -1
  20. package/cjs/helper/lifeCycle.js.map +1 -1
  21. package/cjs/helper/monitor.js +6 -6
  22. package/cjs/helper/monitor.js.map +1 -1
  23. package/cjs/helper/serialisation/jsonStringify.js.map +1 -1
  24. package/cjs/index.js +33 -0
  25. package/cjs/index.js.map +1 -1
  26. package/cjs/report/reportObservable.js +26 -20
  27. package/cjs/report/reportObservable.js.map +1 -1
  28. package/cjs/telemetry/telemetry.js +60 -31
  29. package/cjs/telemetry/telemetry.js.map +1 -1
  30. package/cjs/telemetry/types.js +2 -1
  31. package/cjs/telemetry/types.js.map +1 -1
  32. package/cjs/transport/batch.js +129 -79
  33. package/cjs/transport/batch.js.map +1 -1
  34. package/cjs/transport/flushController.js +18 -5
  35. package/cjs/transport/flushController.js.map +1 -1
  36. package/cjs/transport/httpRequest.js +35 -22
  37. package/cjs/transport/httpRequest.js.map +1 -1
  38. package/cjs/transport/index.js +4 -4
  39. package/cjs/transport/index.js.map +1 -1
  40. package/cjs/transport/startBatchWithReplica.js +26 -10
  41. package/cjs/transport/startBatchWithReplica.js.map +1 -1
  42. package/esm/browser/pageExitObservable.js +1 -1
  43. package/esm/browser/pageExitObservable.js.map +1 -1
  44. package/esm/browser/runOnReadyState.js +5 -1
  45. package/esm/browser/runOnReadyState.js.map +1 -1
  46. package/esm/console/consoleObservable.js +18 -10
  47. package/esm/console/consoleObservable.js.map +1 -1
  48. package/esm/dataMap.js +11 -2
  49. package/esm/dataMap.js.map +1 -1
  50. package/esm/helper/boundedBuffer.js +21 -16
  51. package/esm/helper/boundedBuffer.js.map +1 -1
  52. package/esm/helper/connectivity.js +10 -0
  53. package/esm/helper/connectivity.js.map +1 -0
  54. package/esm/helper/display.js +12 -11
  55. package/esm/helper/display.js.map +1 -1
  56. package/esm/helper/displayAlreadyInitializedError.js +7 -0
  57. package/esm/helper/displayAlreadyInitializedError.js.map +1 -0
  58. package/esm/helper/encoder.js +37 -0
  59. package/esm/helper/encoder.js.map +1 -0
  60. package/esm/helper/lifeCycle.js +0 -1
  61. package/esm/helper/lifeCycle.js.map +1 -1
  62. package/esm/helper/monitor.js +6 -6
  63. package/esm/helper/monitor.js.map +1 -1
  64. package/esm/helper/serialisation/jsonStringify.js.map +1 -1
  65. package/esm/index.js +3 -0
  66. package/esm/index.js.map +1 -1
  67. package/esm/report/reportObservable.js +27 -21
  68. package/esm/report/reportObservable.js.map +1 -1
  69. package/esm/telemetry/telemetry.js +57 -31
  70. package/esm/telemetry/telemetry.js.map +1 -1
  71. package/esm/telemetry/types.js +2 -1
  72. package/esm/telemetry/types.js.map +1 -1
  73. package/esm/transport/batch.js +127 -77
  74. package/esm/transport/batch.js.map +1 -1
  75. package/esm/transport/flushController.js +18 -5
  76. package/esm/transport/flushController.js.map +1 -1
  77. package/esm/transport/httpRequest.js +35 -22
  78. package/esm/transport/httpRequest.js.map +1 -1
  79. package/esm/transport/index.js +1 -1
  80. package/esm/transport/index.js.map +1 -1
  81. package/esm/transport/startBatchWithReplica.js +27 -11
  82. package/esm/transport/startBatchWithReplica.js.map +1 -1
  83. package/package.json +2 -2
  84. package/src/browser/pageExitObservable.js +2 -2
  85. package/src/browser/runOnReadyState.js +3 -1
  86. package/src/console/consoleObservable.js +22 -14
  87. package/src/dataMap.js +11 -2
  88. package/src/helper/boundedBuffer.js +21 -14
  89. package/src/helper/connectivity.js +11 -0
  90. package/src/helper/display.js +16 -14
  91. package/src/helper/displayAlreadyInitializedError.js +7 -0
  92. package/src/helper/encoder.js +43 -0
  93. package/src/helper/lifeCycle.js +0 -1
  94. package/src/helper/monitor.js +6 -6
  95. package/src/helper/serialisation/jsonStringify.js +1 -1
  96. package/src/index.js +3 -0
  97. package/src/report/reportObservable.js +43 -27
  98. package/src/telemetry/telemetry.js +60 -37
  99. package/src/telemetry/types.js +2 -1
  100. package/src/transport/batch.js +154 -89
  101. package/src/transport/flushController.js +19 -6
  102. package/src/transport/httpRequest.js +34 -35
  103. package/src/transport/index.js +1 -1
  104. package/src/transport/startBatchWithReplica.js +25 -14
  105. package/types/index.d.ts +12 -0
@@ -8,7 +8,6 @@ import { isPageExitReason } from '../browser/pageExitObservable';
8
8
  import { jsonStringify } from '../helper/serialisation/jsonStringify';
9
9
  // https://en.wikipedia.org/wiki/UTF-8
10
10
  // eslint-disable-next-line no-control-regex
11
- var HAS_MULTI_BYTES_CHARACTERS = /[^\u0000-\u007F]/;
12
11
  var CUSTOM_KEYS = 'custom_keys';
13
12
  export var processedMessageByDataMap = function processedMessageByDataMap(message) {
14
13
  if (!message || !message.type) return {
@@ -101,93 +100,144 @@ export var processedMessageByDataMap = function processedMessageByDataMap(messag
101
100
  rowData: hasFileds ? rowData : undefined
102
101
  };
103
102
  };
104
- var batch = function batch(request, flushController, messageBytesLimit, sendContentTypeByJson) {
105
- this.pushOnlyBuffer = [];
106
- this.upsertBuffer = {};
107
- this.request = request;
108
- this.flushController = flushController;
109
- this.messageBytesLimit = messageBytesLimit;
110
- this.sendContentTypeByJson = sendContentTypeByJson;
111
- var _this = this;
112
- this.flushController.flushObservable.subscribe(function (event) {
113
- _this.flush(event);
103
+ export function createBatch(options) {
104
+ var encoder = options.encoder;
105
+ var request = options.request;
106
+ var messageBytesLimit = options.messageBytesLimit;
107
+ var sendContentTypeByJson = options.sendContentTypeByJson;
108
+ var flushController = options.flushController;
109
+ var upsertBuffer = {};
110
+ var flushSubscription = flushController.flushObservable.subscribe(function (event) {
111
+ flush(event);
114
112
  });
115
- };
116
- batch.prototype.add = function (message) {
117
- this.addOrUpdate(message);
118
- };
119
- batch.prototype.upsert = function (message, key) {
120
- this.addOrUpdate(message, key);
121
- };
122
- batch.prototype.flush = function (event) {
123
- var messages = this.pushOnlyBuffer.concat(values(this.upsertBuffer));
124
- this.pushOnlyBuffer = [];
125
- this.upsertBuffer = {};
126
- if (messages.length > 0) {
127
- var payloadData = '';
128
- if (this.sendContentTypeByJson) {
129
- payloadData = '[' + messages.join(',') + ']';
113
+ function getMessageText(messages) {
114
+ var isEmpty = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
115
+ if (sendContentTypeByJson) {
116
+ if (isEmpty) {
117
+ return '[' + messages.join(',');
118
+ } else {
119
+ return ',' + messages.join(',');
120
+ }
130
121
  } else {
131
- payloadData = messages.join('\n');
122
+ if (isEmpty) {
123
+ return messages.join('\n');
124
+ } else {
125
+ return '\n' + messages.join('\n');
126
+ }
132
127
  }
133
- var payload = {
134
- data: payloadData,
135
- bytesCount: event.bytesCount,
136
- flushReason: event.reason
137
- };
138
- if (isPageExitReason(event.reason)) {
139
- this.request.sendOnExit(payload);
128
+ }
129
+ function push(serializedMessage, estimatedMessageBytesCount, key) {
130
+ flushController.notifyBeforeAddMessage(estimatedMessageBytesCount);
131
+ if (key !== undefined) {
132
+ upsertBuffer[key] = serializedMessage;
133
+ flushController.notifyAfterAddMessage();
140
134
  } else {
141
- this.request.send(payload);
135
+ encoder.write(getMessageText([serializedMessage], encoder.isEmpty()), function (realMessageBytesCount) {
136
+ flushController.notifyAfterAddMessage(realMessageBytesCount - estimatedMessageBytesCount);
137
+ });
142
138
  }
143
139
  }
144
- };
145
- batch.prototype.addOrUpdate = function (message, key) {
146
- var _process = this.process(message);
147
- var processedMessage = _process.processedMessage;
148
- var messageBytesCount = _process.messageBytesCount;
149
- if (messageBytesCount >= this.messageBytesLimit) {
150
- display.warn('Discarded a message whose size was bigger than the maximum allowed size ' + this.messageBytesLimit + 'KB.');
151
- return;
140
+ function hasMessageFor(key) {
141
+ return key !== undefined && upsertBuffer[key] !== undefined;
152
142
  }
153
- if (this.hasMessageFor(key)) {
154
- this.remove(key);
143
+ function remove(key) {
144
+ var removedMessage = upsertBuffer[key];
145
+ delete upsertBuffer[key];
146
+ var messageBytesCount = encoder.estimateEncodedBytesCount(removedMessage);
147
+ flushController.notifyAfterRemoveMessage(messageBytesCount);
155
148
  }
156
- this.push(processedMessage, messageBytesCount, key);
157
- };
158
- batch.prototype.process = function (message) {
159
- var processedMessage = '';
160
- if (this.sendContentTypeByJson) {
161
- processedMessage = jsonStringify(processedMessageByDataMap(message).rowData);
162
- } else {
163
- processedMessage = processedMessageByDataMap(message).rowStr;
149
+ function process(message) {
150
+ var processedMessage = '';
151
+ if (sendContentTypeByJson) {
152
+ processedMessage = jsonStringify(processedMessageByDataMap(message).rowData);
153
+ } else {
154
+ processedMessage = processedMessageByDataMap(message).rowStr;
155
+ }
156
+ return processedMessage;
157
+ }
158
+ function addOrUpdate(message, key) {
159
+ var serializedMessage = process(message);
160
+ var estimatedMessageBytesCount = encoder.estimateEncodedBytesCount(serializedMessage);
161
+ if (estimatedMessageBytesCount >= messageBytesLimit) {
162
+ display.warn("Discarded a message whose size was bigger than the maximum allowed size ".concat(messageBytesLimit, "KB."));
163
+ return;
164
+ }
165
+ if (hasMessageFor(key)) {
166
+ remove(key);
167
+ }
168
+ push(serializedMessage, estimatedMessageBytesCount, key);
169
+ }
170
+ function flush(event) {
171
+ var upsertMessages = values(upsertBuffer).join(sendContentTypeByJson ? ',' : '\n');
172
+ upsertBuffer = {};
173
+ var isPageExit = isPageExitReason(event.reason);
174
+ var send = isPageExit ? request.sendOnExit : request.send;
175
+ if (isPageExit &&
176
+ // Note: checking that the encoder is async is not strictly needed, but it's an optimization:
177
+ // if the encoder is async we need to send two requests in some cases (one for encoded data
178
+ // and the other for non-encoded data). But if it's not async, we don't have to worry about
179
+ // it and always send a single request.
180
+ encoder.isAsync) {
181
+ // 咱不支持json 模式
182
+ var encoderResult = encoder.finishSync();
183
+
184
+ // Send encoded messages
185
+ if (encoderResult.outputBytesCount) {
186
+ send(formatPayloadFromEncoder(encoderResult, sendContentTypeByJson));
187
+ }
188
+
189
+ // Send messages that are not yet encoded at this point
190
+ var pendingMessages = [encoderResult.pendingData, upsertMessages].filter(Boolean).join('\n');
191
+ if (pendingMessages) {
192
+ send({
193
+ data: pendingMessages,
194
+ bytesCount: computeBytesCount(pendingMessages)
195
+ });
196
+ }
197
+ } else {
198
+ if (upsertMessages) {
199
+ var text = getMessageText([upsertMessages], encoder.isEmpty());
200
+ if (sendContentTypeByJson) {
201
+ text += ']';
202
+ }
203
+ encoder.write(text);
204
+ } else {
205
+ if (sendContentTypeByJson) {
206
+ encoder.write(']');
207
+ }
208
+ }
209
+ encoder.finish(function (encoderResult) {
210
+ send(formatPayloadFromEncoder(encoderResult));
211
+ });
212
+ }
164
213
  }
165
- var messageBytesCount = computeBytesCount(processedMessage);
166
214
  return {
167
- processedMessage: processedMessage,
168
- messageBytesCount: messageBytesCount
215
+ flushController: flushController,
216
+ add: addOrUpdate,
217
+ upsert: addOrUpdate,
218
+ stop: flushSubscription.unsubscribe
169
219
  };
170
- };
171
- batch.prototype.push = function (processedMessage, messageBytesCount, key) {
172
- var separatorBytesCount = this.flushController.getMessagesCount() > 0 ? 1 : 0;
173
- this.flushController.notifyBeforeAddMessage(messageBytesCount + separatorBytesCount);
174
- if (key !== undefined) {
175
- this.upsertBuffer[key] = processedMessage;
220
+ }
221
+ function formatPayloadFromEncoder(encoderResult, sendContentTypeByJson) {
222
+ var data;
223
+ if (typeof encoderResult.output === 'string') {
224
+ data = encoderResult.output;
176
225
  } else {
177
- this.pushOnlyBuffer.push(processedMessage);
226
+ data = new Blob([encoderResult.output], {
227
+ // This will set the 'Content-Type: text/plain' header. Reasoning:
228
+ // * The intake rejects the request if there is no content type.
229
+ // * The browser will issue CORS preflight requests if we set it to 'application/json', which
230
+ // could induce higher intake load (and maybe has other impacts).
231
+ // * Also it's not quite JSON, since we are concatenating multiple JSON objects separated by
232
+ // new lines.
233
+ type: 'text/plain'
234
+ });
178
235
  }
179
- this.flushController.notifyAfterAddMessage();
180
- };
181
- batch.prototype.remove = function (key) {
182
- var removedMessage = this.upsertBuffer[key];
183
- delete this.upsertBuffer[key];
184
- var messageBytesCount = computeBytesCount(removedMessage);
185
- // If there are other messages, a '\n' will be added at serialization
186
- var separatorBytesCount = this.flushController.getMessagesCount() > 1 ? 1 : 0;
187
- this.flushController.notifyAfterRemoveMessage(messageBytesCount + separatorBytesCount);
188
- };
189
- batch.prototype.hasMessageFor = function (key) {
190
- return key !== undefined && this.upsertBuffer[key] !== undefined;
191
- };
192
- export var Batch = batch;
236
+ return {
237
+ data: data,
238
+ type: sendContentTypeByJson ? 'application/json;UTF-8' : undefined,
239
+ bytesCount: encoderResult.outputBytesCount,
240
+ encoding: encoderResult.encoding
241
+ };
242
+ }
193
243
  //# sourceMappingURL=batch.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"batch.js","names":["display","values","findByPath","each","isNumber","isArray","extend","isString","isEmptyObject","isObject","escapeJsonValue","escapeRowField","escapeRowData","commonTags","dataMap","commonFields","RumEventType","computeBytesCount","isPageExitReason","jsonStringify","HAS_MULTI_BYTES_CHARACTERS","CUSTOM_KEYS","processedMessageByDataMap","message","type","rowStr","rowData","undefined","tags","fields","hasFileds","value","key","measurement","tagsStr","filterFileds","value_path","_key","_value","push","fieldsStr","length","_valueData","context","_tagKeys","indexOf","LOGGER","join","date","time","batch","request","flushController","messageBytesLimit","sendContentTypeByJson","pushOnlyBuffer","upsertBuffer","_this","flushObservable","subscribe","event","flush","prototype","add","addOrUpdate","upsert","messages","concat","payloadData","payload","data","bytesCount","flushReason","reason","sendOnExit","send","_process","process","processedMessage","messageBytesCount","warn","hasMessageFor","remove","separatorBytesCount","getMessagesCount","notifyBeforeAddMessage","notifyAfterAddMessage","removedMessage","notifyAfterRemoveMessage","Batch"],"sources":["../../src/transport/batch.js"],"sourcesContent":["import { display } from '../helper/display'\nimport {\n values,\n findByPath,\n each,\n isNumber,\n isArray,\n extend,\n isString,\n isEmptyObject,\n isObject\n} from '../helper/tools'\nimport {\n escapeJsonValue,\n escapeRowField,\n escapeRowData\n} from '../helper/serialisation/rowData'\nimport { commonTags, dataMap, commonFields } from '../dataMap'\nimport { RumEventType } from '../helper/enums'\nimport { computeBytesCount } from '../helper/byteUtils'\nimport { isPageExitReason } from '../browser/pageExitObservable'\nimport { jsonStringify } from '../helper/serialisation/jsonStringify'\n// https://en.wikipedia.org/wiki/UTF-8\n// eslint-disable-next-line no-control-regex\nvar HAS_MULTI_BYTES_CHARACTERS = /[^\\u0000-\\u007F]/\nvar CUSTOM_KEYS = 'custom_keys'\nexport var processedMessageByDataMap = function (message) {\n if (!message || !message.type)\n return {\n rowStr: '',\n rowData: undefined\n }\n\n var rowData = { tags: {}, fields: {} }\n var hasFileds = false\n var rowStr = ''\n each(dataMap, function (value, key) {\n if (value.type === message.type) {\n rowStr += key + ','\n rowData.measurement = key\n var tagsStr = []\n var tags = extend({}, commonTags, value.tags)\n var filterFileds = ['date', 'type', CUSTOM_KEYS] // 已经在datamap中定义过的fields和tags\n each(tags, function (value_path, _key) {\n var _value = findByPath(message, value_path)\n filterFileds.push(_key)\n if (_value || isNumber(_value)) {\n rowData.tags[_key] = escapeJsonValue(_value, true)\n tagsStr.push(escapeRowData(_key) + '=' + escapeRowData(_value))\n }\n })\n\n var fieldsStr = []\n var fields = extend({}, commonFields, value.fields)\n each(fields, function (_value, _key) {\n if (isArray(_value) && _value.length === 2) {\n var value_path = _value[1]\n var _valueData = findByPath(message, value_path)\n filterFileds.push(_key)\n if (_valueData !== undefined && _valueData !== null) {\n rowData.fields[_key] = escapeJsonValue(_valueData) // 这里不需要转译\n fieldsStr.push(\n escapeRowData(_key) + '=' + escapeRowField(_valueData)\n )\n }\n } else if (isString(_value)) {\n var _valueData = findByPath(message, _value)\n filterFileds.push(_key)\n if (_valueData !== undefined && _valueData !== null) {\n rowData.fields[_key] = escapeJsonValue(_valueData) // 这里不需要转译\n fieldsStr.push(\n escapeRowData(_key) + '=' + escapeRowField(_valueData)\n )\n }\n }\n })\n if (\n message.context &&\n isObject(message.context) &&\n !isEmptyObject(message.context)\n ) {\n // 自定义tag, 存储成field\n var _tagKeys = []\n each(message.context, function (_value, _key) {\n // 如果和之前tag重名,则舍弃\n if (filterFileds.indexOf(_key) > -1) return\n filterFileds.push(_key)\n if (_value !== undefined && _value !== null) {\n _tagKeys.push(_key)\n rowData.fields[_key] = escapeJsonValue(_value) // 这里不需要转译\n fieldsStr.push(escapeRowData(_key) + '=' + escapeRowField(_value))\n }\n })\n if (_tagKeys.length) {\n rowData.fields[CUSTOM_KEYS] = escapeJsonValue(_tagKeys)\n fieldsStr.push(\n escapeRowData(CUSTOM_KEYS) + '=' + escapeRowField(_tagKeys)\n )\n }\n }\n if (message.type === RumEventType.LOGGER) {\n // 这里处理日志类型数据自定义字段\n each(message, function (value, key) {\n if (\n filterFileds.indexOf(key) === -1 &&\n value !== undefined &&\n value !== null\n ) {\n rowData.fields[key] = escapeJsonValue(value) // 这里不需要转译\n fieldsStr.push(escapeRowData(key) + '=' + escapeRowField(value))\n }\n })\n }\n if (tagsStr.length) {\n rowStr += tagsStr.join(',')\n }\n if (fieldsStr.length) {\n rowStr += ' '\n rowStr += fieldsStr.join(',')\n hasFileds = true\n }\n rowStr = rowStr + ' ' + message.date\n rowData.time = message.date // 这里不需要转译\n }\n })\n return {\n rowStr: hasFileds ? rowStr : '',\n rowData: hasFileds ? rowData : undefined\n }\n}\nvar batch = function (\n request,\n flushController,\n messageBytesLimit,\n sendContentTypeByJson\n) {\n this.pushOnlyBuffer = []\n this.upsertBuffer = {}\n this.request = request\n this.flushController = flushController\n this.messageBytesLimit = messageBytesLimit\n this.sendContentTypeByJson = sendContentTypeByJson\n var _this = this\n this.flushController.flushObservable.subscribe(function (event) {\n _this.flush(event)\n })\n}\nbatch.prototype.add = function (message) {\n this.addOrUpdate(message)\n}\nbatch.prototype.upsert = function (message, key) {\n this.addOrUpdate(message, key)\n}\nbatch.prototype.flush = function (event) {\n var messages = this.pushOnlyBuffer.concat(values(this.upsertBuffer))\n this.pushOnlyBuffer = []\n this.upsertBuffer = {}\n if (messages.length > 0) {\n var payloadData = ''\n if (this.sendContentTypeByJson) {\n payloadData = '[' + messages.join(',') + ']'\n } else {\n payloadData = messages.join('\\n')\n }\n var payload = {\n data: payloadData,\n bytesCount: event.bytesCount,\n flushReason: event.reason\n }\n if (isPageExitReason(event.reason)) {\n this.request.sendOnExit(payload)\n } else {\n this.request.send(payload)\n }\n }\n}\n\nbatch.prototype.addOrUpdate = function (message, key) {\n var _process = this.process(message)\n var processedMessage = _process.processedMessage\n var messageBytesCount = _process.messageBytesCount\n if (messageBytesCount >= this.messageBytesLimit) {\n display.warn(\n 'Discarded a message whose size was bigger than the maximum allowed size ' +\n this.messageBytesLimit +\n 'KB.'\n )\n return\n }\n if (this.hasMessageFor(key)) {\n this.remove(key)\n }\n this.push(processedMessage, messageBytesCount, key)\n}\nbatch.prototype.process = function (message) {\n var processedMessage = ''\n if (this.sendContentTypeByJson) {\n processedMessage = jsonStringify(processedMessageByDataMap(message).rowData)\n } else {\n processedMessage = processedMessageByDataMap(message).rowStr\n }\n var messageBytesCount = computeBytesCount(processedMessage)\n return {\n processedMessage: processedMessage,\n messageBytesCount: messageBytesCount\n }\n}\n\nbatch.prototype.push = function (processedMessage, messageBytesCount, key) {\n var separatorBytesCount = this.flushController.getMessagesCount() > 0 ? 1 : 0\n this.flushController.notifyBeforeAddMessage(\n messageBytesCount + separatorBytesCount\n )\n if (key !== undefined) {\n this.upsertBuffer[key] = processedMessage\n } else {\n this.pushOnlyBuffer.push(processedMessage)\n }\n this.flushController.notifyAfterAddMessage()\n}\n\nbatch.prototype.remove = function (key) {\n var removedMessage = this.upsertBuffer[key]\n delete this.upsertBuffer[key]\n var messageBytesCount = computeBytesCount(removedMessage)\n // If there are other messages, a '\\n' will be added at serialization\n var separatorBytesCount = this.flushController.getMessagesCount() > 1 ? 1 : 0\n this.flushController.notifyAfterRemoveMessage(\n messageBytesCount + separatorBytesCount\n )\n}\n\nbatch.prototype.hasMessageFor = function (key) {\n return key !== undefined && this.upsertBuffer[key] !== undefined\n}\nexport var Batch = batch\n"],"mappings":"AAAA,SAASA,OAAO,QAAQ,mBAAmB;AAC3C,SACEC,MAAM,EACNC,UAAU,EACVC,IAAI,EACJC,QAAQ,EACRC,OAAO,EACPC,MAAM,EACNC,QAAQ,EACRC,aAAa,EACbC,QAAQ,QACH,iBAAiB;AACxB,SACEC,eAAe,EACfC,cAAc,EACdC,aAAa,QACR,iCAAiC;AACxC,SAASC,UAAU,EAAEC,OAAO,EAAEC,YAAY,QAAQ,YAAY;AAC9D,SAASC,YAAY,QAAQ,iBAAiB;AAC9C,SAASC,iBAAiB,QAAQ,qBAAqB;AACvD,SAASC,gBAAgB,QAAQ,+BAA+B;AAChE,SAASC,aAAa,QAAQ,uCAAuC;AACrE;AACA;AACA,IAAIC,0BAA0B,GAAG,kBAAkB;AACnD,IAAIC,WAAW,GAAG,aAAa;AAC/B,OAAO,IAAIC,yBAAyB,GAAG,SAA5BA,yBAAyBA,CAAaC,OAAO,EAAE;EACxD,IAAI,CAACA,OAAO,IAAI,CAACA,OAAO,CAACC,IAAI,EAC3B,OAAO;IACLC,MAAM,EAAE,EAAE;IACVC,OAAO,EAA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C,qBAAqB,CAAC,CAAC;AAC9C,CAAC;AAEDpC,KAAK,CAACY,SAAS,CAACoB,MAAM,GAAG,UAAUlD,GAAG,EAAE;EACtC,IAAIuD,cAAc,GAAG,IAAI,CAAC/B,YAAY,CAACxB,GAAG,CAAC;EAC3C,OAAO,IAAI,CAACwB,YAAY,CAACxB,GAAG,CAAC;EAC7B,IAAI+C,iBAAiB,GAAG9D,iBAAiB,CAACsE,cAAc,CAAC;EACzD;EACA,IAAIJ,mBAAmB,GAAG,IAAI,CAAC/B,eAAe,CAACgC,gBAAgB,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC;EAC7E,IAAI,CAAChC,eAAe,CAACoC,wBAAwB,CAC3CT,iBAAiB,GAAGI,mBACtB,CAAC;AACH,CAAC;AAEDjC,KAAK,CAACY,SAAS,CAACmB,aAAa,GAAG,UAAUjD,GAAG,EAAE;EAC7C,OAAOA,GAAG,KAAKL,SAAS,IAAI,IAAI,CAAC6B,YAAY,CAACxB,GAAG,CAAC,KAAKL,SAAS;AAClE,CAAC;AACD,OAAO,IAAI8D,KAAK,GAAGvC,KAAK","ignoreList":[]}
1
+ {"version":3,"file":"batch.js","names":["display","values","findByPath","each","isNumber","isArray","extend","isString","isEmptyObject","isObject","escapeJsonValue","escapeRowField","escapeRowData","commonTags","dataMap","commonFields","RumEventType","computeBytesCount","isPageExitReason","jsonStringify","CUSTOM_KEYS","processedMessageByDataMap","message","type","rowStr","rowData","undefined","tags","fields","hasFileds","value","key","measurement","tagsStr","filterFileds","value_path","_key","_value","push","fieldsStr","length","_valueData","context","_tagKeys","indexOf","LOGGER","join","date","time","createBatch","options","encoder","request","messageBytesLimit","sendContentTypeByJson","flushController","upsertBuffer","flushSubscription","flushObservable","subscribe","event","flush","getMessageText","messages","isEmpty","arguments","serializedMessage","estimatedMessageBytesCount","notifyBeforeAddMessage","notifyAfterAddMessage","write","realMessageBytesCount","hasMessageFor","remove","removedMessage","messageBytesCount","estimateEncodedBytesCount","notifyAfterRemoveMessage","process","processedMessage","addOrUpdate","warn","concat","upsertMessages","isPageExit","reason","send","sendOnExit","isAsync","encoderResult","finishSync","outputBytesCount","formatPayloadFromEncoder","pendingMessages","pendingData","filter","Boolean","data","bytesCount","text","finish","add","upsert","stop","unsubscribe","output","Blob","encoding"],"sources":["../../src/transport/batch.js"],"sourcesContent":["import { display } from '../helper/display'\nimport {\n values,\n findByPath,\n each,\n isNumber,\n isArray,\n extend,\n isString,\n isEmptyObject,\n isObject\n} from '../helper/tools'\nimport {\n escapeJsonValue,\n escapeRowField,\n escapeRowData\n} from '../helper/serialisation/rowData'\nimport { commonTags, dataMap, commonFields } from '../dataMap'\nimport { RumEventType } from '../helper/enums'\nimport { computeBytesCount } from '../helper/byteUtils'\nimport { isPageExitReason } from '../browser/pageExitObservable'\nimport { jsonStringify } from '../helper/serialisation/jsonStringify'\n// https://en.wikipedia.org/wiki/UTF-8\n// eslint-disable-next-line no-control-regex\nvar CUSTOM_KEYS = 'custom_keys'\nexport var processedMessageByDataMap = function (message) {\n if (!message || !message.type)\n return {\n rowStr: '',\n rowData: undefined\n }\n\n var rowData = { tags: {}, fields: {} }\n var hasFileds = false\n var rowStr = ''\n each(dataMap, function (value, key) {\n if (value.type === message.type) {\n rowStr += key + ','\n rowData.measurement = key\n var tagsStr = []\n var tags = extend({}, commonTags, value.tags)\n var filterFileds = ['date', 'type', CUSTOM_KEYS] // 已经在datamap中定义过的fields和tags\n each(tags, function (value_path, _key) {\n var _value = findByPath(message, value_path)\n filterFileds.push(_key)\n if (_value || isNumber(_value)) {\n rowData.tags[_key] = escapeJsonValue(_value, true)\n tagsStr.push(escapeRowData(_key) + '=' + escapeRowData(_value))\n }\n })\n\n var fieldsStr = []\n var fields = extend({}, commonFields, value.fields)\n each(fields, function (_value, _key) {\n if (isArray(_value) && _value.length === 2) {\n var value_path = _value[1]\n var _valueData = findByPath(message, value_path)\n filterFileds.push(_key)\n if (_valueData !== undefined && _valueData !== null) {\n rowData.fields[_key] = escapeJsonValue(_valueData) // 这里不需要转译\n fieldsStr.push(\n escapeRowData(_key) + '=' + escapeRowField(_valueData)\n )\n }\n } else if (isString(_value)) {\n var _valueData = findByPath(message, _value)\n filterFileds.push(_key)\n if (_valueData !== undefined && _valueData !== null) {\n rowData.fields[_key] = escapeJsonValue(_valueData) // 这里不需要转译\n fieldsStr.push(\n escapeRowData(_key) + '=' + escapeRowField(_valueData)\n )\n }\n }\n })\n if (\n message.context &&\n isObject(message.context) &&\n !isEmptyObject(message.context)\n ) {\n // 自定义tag, 存储成field\n var _tagKeys = []\n each(message.context, function (_value, _key) {\n // 如果和之前tag重名,则舍弃\n if (filterFileds.indexOf(_key) > -1) return\n filterFileds.push(_key)\n if (_value !== undefined && _value !== null) {\n _tagKeys.push(_key)\n rowData.fields[_key] = escapeJsonValue(_value) // 这里不需要转译\n fieldsStr.push(escapeRowData(_key) + '=' + escapeRowField(_value))\n }\n })\n if (_tagKeys.length) {\n rowData.fields[CUSTOM_KEYS] = escapeJsonValue(_tagKeys)\n fieldsStr.push(\n escapeRowData(CUSTOM_KEYS) + '=' + escapeRowField(_tagKeys)\n )\n }\n }\n if (message.type === RumEventType.LOGGER) {\n // 这里处理日志类型数据自定义字段\n each(message, function (value, key) {\n if (\n filterFileds.indexOf(key) === -1 &&\n value !== undefined &&\n value !== null\n ) {\n rowData.fields[key] = escapeJsonValue(value) // 这里不需要转译\n fieldsStr.push(escapeRowData(key) + '=' + escapeRowField(value))\n }\n })\n }\n if (tagsStr.length) {\n rowStr += tagsStr.join(',')\n }\n if (fieldsStr.length) {\n rowStr += ' '\n rowStr += fieldsStr.join(',')\n hasFileds = true\n }\n rowStr = rowStr + ' ' + message.date\n rowData.time = message.date // 这里不需要转译\n }\n })\n return {\n rowStr: hasFileds ? rowStr : '',\n rowData: hasFileds ? rowData : undefined\n }\n}\n\nexport function createBatch(options) {\n var encoder = options.encoder\n var request = options.request\n var messageBytesLimit = options.messageBytesLimit\n var sendContentTypeByJson = options.sendContentTypeByJson\n var flushController = options.flushController\n var upsertBuffer = {}\n var flushSubscription = flushController.flushObservable.subscribe(function (\n event\n ) {\n flush(event)\n })\n function getMessageText(messages, isEmpty = false) {\n if (sendContentTypeByJson) {\n if (isEmpty) {\n return '[' + messages.join(',')\n } else {\n return ',' + messages.join(',')\n }\n } else {\n if (isEmpty) {\n return messages.join('\\n')\n } else {\n return '\\n' + messages.join('\\n')\n }\n }\n }\n function push(serializedMessage, estimatedMessageBytesCount, key) {\n flushController.notifyBeforeAddMessage(estimatedMessageBytesCount)\n\n if (key !== undefined) {\n upsertBuffer[key] = serializedMessage\n flushController.notifyAfterAddMessage()\n } else {\n encoder.write(\n getMessageText([serializedMessage], encoder.isEmpty()),\n function (realMessageBytesCount) {\n flushController.notifyAfterAddMessage(\n realMessageBytesCount - estimatedMessageBytesCount\n )\n }\n )\n }\n }\n\n function hasMessageFor(key) {\n return key !== undefined && upsertBuffer[key] !== undefined\n }\n\n function remove(key) {\n var removedMessage = upsertBuffer[key]\n delete upsertBuffer[key]\n var messageBytesCount = encoder.estimateEncodedBytesCount(removedMessage)\n flushController.notifyAfterRemoveMessage(messageBytesCount)\n }\n function process(message) {\n var processedMessage = ''\n if (sendContentTypeByJson) {\n processedMessage = jsonStringify(\n processedMessageByDataMap(message).rowData\n )\n } else {\n processedMessage = processedMessageByDataMap(message).rowStr\n }\n return processedMessage\n }\n function addOrUpdate(message, key) {\n const serializedMessage = process(message)\n\n const estimatedMessageBytesCount =\n encoder.estimateEncodedBytesCount(serializedMessage)\n\n if (estimatedMessageBytesCount >= messageBytesLimit) {\n display.warn(\n `Discarded a message whose size was bigger than the maximum allowed size ${messageBytesLimit}KB.`\n )\n return\n }\n\n if (hasMessageFor(key)) {\n remove(key)\n }\n\n push(serializedMessage, estimatedMessageBytesCount, key)\n }\n\n function flush(event) {\n var upsertMessages = values(upsertBuffer).join(\n sendContentTypeByJson ? ',' : '\\n'\n )\n upsertBuffer = {}\n\n var isPageExit = isPageExitReason(event.reason)\n var send = isPageExit ? request.sendOnExit : request.send\n\n if (\n isPageExit &&\n // Note: checking that the encoder is async is not strictly needed, but it's an optimization:\n // if the encoder is async we need to send two requests in some cases (one for encoded data\n // and the other for non-encoded data). But if it's not async, we don't have to worry about\n // it and always send a single request.\n encoder.isAsync\n ) {\n // 咱不支持json 模式\n var encoderResult = encoder.finishSync()\n\n // Send encoded messages\n if (encoderResult.outputBytesCount) {\n send(formatPayloadFromEncoder(encoderResult, sendContentTypeByJson))\n }\n\n // Send messages that are not yet encoded at this point\n var pendingMessages = [encoderResult.pendingData, upsertMessages]\n .filter(Boolean)\n .join('\\n')\n\n if (pendingMessages) {\n send({\n data: pendingMessages,\n bytesCount: computeBytesCount(pendingMessages)\n })\n }\n } else {\n if (upsertMessages) {\n var text = getMessageText([upsertMessages], encoder.isEmpty())\n if (sendContentTypeByJson) {\n text += ']'\n }\n encoder.write(text)\n } else {\n if (sendContentTypeByJson) {\n encoder.write(']')\n }\n }\n encoder.finish(function (encoderResult) {\n send(formatPayloadFromEncoder(encoderResult))\n })\n }\n }\n\n return {\n flushController: flushController,\n add: addOrUpdate,\n upsert: addOrUpdate,\n stop: flushSubscription.unsubscribe\n }\n}\n\nfunction formatPayloadFromEncoder(encoderResult, sendContentTypeByJson) {\n var data\n if (typeof encoderResult.output === 'string') {\n data = encoderResult.output\n } else {\n data = new Blob([encoderResult.output], {\n // This will set the 'Content-Type: text/plain' header. Reasoning:\n // * The intake rejects the request if there is no content type.\n // * The browser will issue CORS preflight requests if we set it to 'application/json', which\n // could induce higher intake load (and maybe has other impacts).\n // * Also it's not quite JSON, since we are concatenating multiple JSON objects separated by\n // new lines.\n type: 'text/plain'\n })\n }\n\n return {\n data: data,\n type: sendContentTypeByJson ? 'application/json;UTF-8' : undefined,\n bytesCount: encoderResult.outputBytesCount,\n encoding: encoderResult.encoding\n }\n}\n"],"mappings":"AAAA,SAASA,OAAO,QAAQ,mBAAmB;AAC3C,SACEC,MAAM,EACNC,UAAU,EACVC,I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,MAAM,CAAC,UAAUX,aAAa,EAAE;QACtCH,IAAI,CAACM,wBAAwB,CAACH,aAAa,CAAC,CAAC;MAC/C,CAAC,CAAC;IACJ;EACF;EAEA,OAAO;IACLlC,eAAe,EAAEA,eAAe;IAChC8C,GAAG,EAAErB,WAAW;IAChBsB,MAAM,EAAEtB,WAAW;IACnBuB,IAAI,EAAE9C,iBAAiB,CAAC+C;EAC1B,CAAC;AACH;AAEA,SAASZ,wBAAwBA,CAACH,aAAa,EAAEnC,qBAAqB,EAAE;EACtE,IAAI2C,IAAI;EACR,IAAI,OAAOR,aAAa,CAACgB,MAAM,KAAK,QAAQ,EAAE;IAC5CR,IAAI,GAAGR,aAAa,CAACgB,MAAM;EAC7B,CAAC,MAAM;IACLR,IAAI,GAAG,IAAIS,IAAI,CAAC,CAACjB,aAAa,CAACgB,MAAM,CAAC,EAAE;MACtC;MACA;MACA;MACA;MACA;MACA;MACAlF,IAAI,EAAE;IACR,CAAC,CAAC;EACJ;EAEA,OAAO;IACL0E,IAAI,EAAEA,IAAI;IACV1E,IAAI,EAAE+B,qBAAqB,GAAG,wBAAwB,GAAG5B,SAAS;IAClEwE,UAAU,EAAET,aAAa,CAACE,gBAAgB;IAC1CgB,QAAQ,EAAElB,aAAa,CAACkB;EAC1B,CAAC;AACH","ignoreList":[]}
@@ -14,13 +14,18 @@ export function createFlushController(_ref) {
14
14
  durationLimit = _ref.durationLimit,
15
15
  pageExitObservable = _ref.pageExitObservable,
16
16
  sessionExpireObservable = _ref.sessionExpireObservable;
17
- var flushObservable = new Observable();
18
17
  pageExitObservable.subscribe(function (event) {
19
18
  return flush(event.reason);
20
19
  });
21
20
  sessionExpireObservable.subscribe(function () {
22
21
  return flush('session_expire');
23
22
  });
23
+ var flushObservable = new Observable(function () {
24
+ return function () {
25
+ pageExitSubscription.unsubscribe();
26
+ sessionExpireSubscription.unsubscribe();
27
+ };
28
+ });
24
29
  var currentBytesCount = 0;
25
30
  var currentMessagesCount = 0;
26
31
  function flush(flushReason) {
@@ -61,15 +66,15 @@ export function createFlushController(_ref) {
61
66
  * This function needs to be called synchronously, right before adding the message, so no flush
62
67
  * event can happen after `notifyBeforeAddMessage` and before adding the message.
63
68
  */
64
- notifyBeforeAddMessage: function notifyBeforeAddMessage(messageBytesCount) {
65
- if (currentBytesCount + messageBytesCount >= bytesLimit) {
69
+ notifyBeforeAddMessage: function notifyBeforeAddMessage(estimatedMessageBytesCount) {
70
+ if (currentBytesCount + estimatedMessageBytesCount >= bytesLimit) {
66
71
  flush('bytes_limit');
67
72
  }
68
73
  // Consider the message to be added now rather than in `notifyAfterAddMessage`, because if no
69
74
  // message was added yet and `notifyAfterAddMessage` is called asynchronously, we still want
70
75
  // to notify when a flush is needed (for example on page exit).
71
76
  currentMessagesCount += 1;
72
- currentBytesCount += messageBytesCount;
77
+ currentBytesCount += estimatedMessageBytesCount;
73
78
  scheduleDurationLimitTimeout();
74
79
  },
75
80
  /**
@@ -78,7 +83,11 @@ export function createFlushController(_ref) {
78
83
  * This function can be called asynchronously after the message was added, but in this case it
79
84
  * should not be called if a flush event occurred in between.
80
85
  */
81
- notifyAfterAddMessage: function notifyAfterAddMessage() {
86
+ notifyAfterAddMessage: function notifyAfterAddMessage(messageBytesCountDiff) {
87
+ if (messageBytesCountDiff === undefined) {
88
+ messageBytesCountDiff = 0;
89
+ }
90
+ currentBytesCount += messageBytesCountDiff;
82
91
  if (currentMessagesCount >= messagesLimit) {
83
92
  flush('messages_limit');
84
93
  } else if (currentBytesCount >= bytesLimit) {
@@ -90,6 +99,10 @@ export function createFlushController(_ref) {
90
99
  *
91
100
  * This function needs to be called synchronously, right after removing the message, so no flush
92
101
  * event can happen after removing the message and before `notifyAfterRemoveMessage`.
102
+ *
103
+ * @param messageBytesCount: the message bytes count that was added to the pool. Should
104
+ * correspond to the sum of bytes counts passed to `notifyBeforeAddMessage` and
105
+ * `notifyAfterAddMessage`.
93
106
  */
94
107
  notifyAfterRemoveMessage: function notifyAfterRemoveMessage(messageBytesCount) {
95
108
  currentBytesCount -= messageBytesCount;
@@ -1 +1 @@
1
- {"version":3,"file":"flushController.js","names":["Observable","clearTimeout","setTimeout","createFlushController","_ref","messagesLimit","bytesLimit","durationLimit","pageExitObservable","sessionExpireObservable","flushObservable","subscribe","event","flush","reason","currentBytesCount","currentMessagesCount","flushReason","messagesCount","bytesCount","cancelDurationLimitTimeout","notify","durationLimitTimeoutId","scheduleDurationLimitTimeout","undefined","getMessagesCount","notifyBeforeAddMessage","messageBytesCount","notifyAfterAddMessage","notifyAfterRemoveMessage"],"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 flushObservable = new Observable()\n\n pageExitObservable.subscribe(function (event) {\n return flush(event.reason)\n })\n sessionExpireObservable.subscribe(function () {\n return flush('session_expire')\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 (messageBytesCount) {\n if (currentBytesCount + messageBytesCount >= 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 += messageBytesCount\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 () {\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 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,uBA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AAE,SAAAA,uBAAUC,iBAAiB,EAAE;MACnD,IAAIZ,iBAAiB,GAAGY,iBAAiB,IAAIrB,UAAU,EAAE;QACvDO,KAAK,CAAC,aAAa,CAAC;MACtB;MACA;MACA;MACA;MACAG,oBAAoB,IAAI,CAAC;MACzBD,iBAAiB,IAAIY,iBAAiB;MACtCJ,4BAA4B,CAAC,CAAC;IAChC,CAAC;IAED;AACJ;AACA;AACA;AACA;AACA;IACIK,qBAAqB,EAAE,SAAAA,sBAAA,EAAY;MACjC,IAAIZ,oBAAoB,IAAIX,aAAa,EAAE;QACzCQ,KAAK,CAAC,gBAAgB,CAAC;MACzB,CAAC,MAAM,IAAIE,iBAAiB,IAAIT,UAAU,EAAE;QAC1CO,KAAK,CAAC,aAAa,CAAC;MACtB;IACF,CAAC;IAED;AACJ;AACA;AACA;AACA;AACA;IACIgB,wBAAwB,EAAE,SAAAA,yBAAUF,iBAAiB,EAAE;MACrDZ,iBAAiB,IAAIY,iBAAiB;MACtCX,oBAAoB,IAAI,CAAC;MACzB,IAAIA,oBAAoB,KAAK,CAAC,EAAE;QAC9BI,0BAA0B,CAAC,CAAC;MAC9B;IACF;EACF,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"file":"flushController.js","names":["Observable","clearTimeout","setTimeout","createFlushController","_ref","messagesLimit","bytesLimit","durationLimit","pageExitObservable","sessionExpireObservable","subscribe","event","flush","reason","flushObservable","pageExitSubscription","unsubscribe","sessionExpireSubscription","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 pageExitObservable.subscribe(function (event) {\n return flush(event.reason)\n })\n sessionExpireObservable.subscribe(function () {\n return flush('session_expire')\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;EAEvBD,kBAAkB,CAACE,SAAS,CAAC,UAAUC,KAAK,EAAE;IAC5C,OAAOC,KAAK,CAACD,KAAK,CAACE,MAAM,CAAC;EAC5B,CAAC,CAAC;EACFJ,uBAAuB,CAACC,SAAS,CAAC,YAAY;IAC5C,OAA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UAAU,EAAE;QAChEM,KAAK,CAAC,aAAa,CAAC;MACtB;MACA;MACA;MACA;MACAO,oBAAoB,IAAI,CAAC;MACzBD,iBAAiB,IAAIY,0BAA0B;MAC/CJ,4BAA4B,CAAC,CAAC;IAChC,CAAC;IAED;AACJ;AACA;AACA;AACA;AACA;IACIK,qBAAqB,EAAE,SAAAA,sBAAUC,qBAAqB,EAAE;MACtD,IAAIA,qBAAqB,KAAKL,SAAS,EAAE;QACvCK,qBAAqB,GAAG,CAAC;MAC3B;MACAd,iBAAiB,IAAIc,qBAAqB;MAE1C,IAAIb,oBAAoB,IAAId,aAAa,EAAE;QACzCO,KAAK,CAAC,gBAAgB,CAAC;MACzB,CAAC,MAAM,IAAIM,iBAAiB,IAAIZ,UAAU,EAAE;QAC1CM,KAAK,CAAC,aAAa,CAAC;MACtB;IACF,CAAC;IAED;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;IACIqB,wBAAwB,EAAE,SAAAA,yBAAUC,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":[]}
@@ -1,6 +1,7 @@
1
1
  import { newRetryState, sendWithRetryStrategy } from './sendWithRetryStrategy';
2
2
  import { addEventListener } from '../browser/addEventListener';
3
3
  import { monitor } from '../helper/monitor';
4
+ import { addTelemetryError } from '../telemetry/telemetry';
4
5
  /**
5
6
  * Use POST request without content type to:
6
7
  * - avoid CORS preflight requests
@@ -9,15 +10,18 @@ import { monitor } from '../helper/monitor';
9
10
  * multiple elements are sent separated by \n in order
10
11
  * to be parsed correctly without content type header
11
12
  */
12
- function addBatchPrecision(url) {
13
+ function addBatchPrecision(url, encoding) {
13
14
  if (!url) return url;
14
- return url + (url.indexOf('?') === -1 ? '?' : '&') + 'precision=ms';
15
+ url = url + (url.indexOf('?') === -1 ? '?' : '&') + 'precision=ms';
16
+ if (encoding) {
17
+ url = url + '&encoding=' + encoding;
18
+ }
19
+ return url;
15
20
  }
16
- export function createHttpRequest(endpointUrl, bytesLimit, sendContentTypeByJson, reportError) {
17
- var contentType = sendContentTypeByJson ? 'application/json; charset=UTF-8' : undefined;
21
+ export function createHttpRequest(endpointUrl, bytesLimit, reportError) {
18
22
  var retryState = newRetryState();
19
23
  var sendStrategyForRetry = function sendStrategyForRetry(payload, onResponse) {
20
- return fetchKeepAliveStrategy(endpointUrl, bytesLimit, contentType, payload, onResponse);
24
+ return fetchKeepAliveStrategy(endpointUrl, bytesLimit, payload, onResponse);
21
25
  };
22
26
  return {
23
27
  send: function send(payload) {
@@ -28,21 +32,21 @@ export function createHttpRequest(endpointUrl, bytesLimit, sendContentTypeByJson
28
32
  * keep using sendBeaconStrategy on exit
29
33
  */
30
34
  sendOnExit: function sendOnExit(payload) {
31
- sendBeaconStrategy(endpointUrl, bytesLimit, contentType, payload);
35
+ sendBeaconStrategy(endpointUrl, bytesLimit, payload);
32
36
  }
33
37
  };
34
38
  }
35
- function sendBeaconStrategy(endpointUrl, bytesLimit, contentType, payload) {
39
+ function sendBeaconStrategy(endpointUrl, bytesLimit, payload) {
36
40
  var data = payload.data;
37
41
  var bytesCount = payload.bytesCount;
38
- var url = addBatchPrecision(endpointUrl);
42
+ var url = addBatchPrecision(endpointUrl, payload.encoding);
39
43
  var canUseBeacon = !!navigator.sendBeacon && bytesCount < bytesLimit;
40
44
  if (canUseBeacon) {
41
45
  try {
42
46
  var beaconData;
43
- if (contentType) {
47
+ if (payload.type) {
44
48
  beaconData = new Blob([data], {
45
- type: contentType
49
+ type: payload.type
46
50
  });
47
51
  } else {
48
52
  beaconData = data;
@@ -52,15 +56,22 @@ function sendBeaconStrategy(endpointUrl, bytesLimit, contentType, payload) {
52
56
  return;
53
57
  }
54
58
  } catch (e) {
55
- // reportBeaconError(e)
59
+ reportBeaconError(e);
56
60
  }
57
61
  }
58
- sendXHR(url, contentType, data);
62
+ sendXHR(url, payload);
63
+ }
64
+ var hasReportedBeaconError = false;
65
+ function reportBeaconError(e) {
66
+ if (!hasReportedBeaconError) {
67
+ hasReportedBeaconError = true;
68
+ addTelemetryError(e);
69
+ }
59
70
  }
60
- export function fetchKeepAliveStrategy(endpointUrl, bytesLimit, contentType, payload, onResponse) {
71
+ export function fetchKeepAliveStrategy(endpointUrl, bytesLimit, payload, onResponse) {
61
72
  var data = payload.data;
62
73
  var bytesCount = payload.bytesCount;
63
- var url = addBatchPrecision(endpointUrl);
74
+ var url = addBatchPrecision(endpointUrl, payload.encoding);
64
75
  var canUseKeepAlive = isKeepAliveSupported() && bytesCount < bytesLimit;
65
76
  if (canUseKeepAlive) {
66
77
  var fetchOption = {
@@ -69,9 +80,9 @@ export function fetchKeepAliveStrategy(endpointUrl, bytesLimit, contentType, pay
69
80
  keepalive: true,
70
81
  mode: 'cors'
71
82
  };
72
- if (contentType) {
83
+ if (payload.type) {
73
84
  fetchOption.headers = {
74
- 'Content-Type': contentType
85
+ 'Content-Type': payload.type
75
86
  };
76
87
  }
77
88
  fetch(url, fetchOption).then(monitor(function (response) {
@@ -83,10 +94,10 @@ export function fetchKeepAliveStrategy(endpointUrl, bytesLimit, contentType, pay
83
94
  }
84
95
  }), monitor(function () {
85
96
  // failed to queue the request
86
- sendXHR(url, contentType, data, onResponse);
97
+ sendXHR(url, payload, onResponse);
87
98
  }));
88
99
  } else {
89
- sendXHR(url, contentType, data, onResponse);
100
+ sendXHR(url, payload, onResponse);
90
101
  }
91
102
  }
92
103
  function isKeepAliveSupported() {
@@ -97,12 +108,14 @@ function isKeepAliveSupported() {
97
108
  return false;
98
109
  }
99
110
  }
100
- function sendXHR(url, contentType, data, onResponse) {
111
+ function sendXHR(url, payload, onResponse) {
112
+ var data = payload.data;
101
113
  var request = new XMLHttpRequest();
102
114
  request.open('POST', url, true);
103
- if (contentType) {
104
- //application/json; charset=UTF-8
105
- request.setRequestHeader('Content-Type', contentType);
115
+ if (data instanceof Blob) {
116
+ request.setRequestHeader('Content-Type', data.type);
117
+ } else if (payload.type) {
118
+ request.setRequestHeader('Content-Type', payload.type);
106
119
  }
107
120
  addEventListener(request, 'loadend', function () {
108
121
  if (typeof onResponse === 'function') {
@@ -1 +1 @@
1
- {"version":3,"file":"httpRequest.js","names":["newRetryState","sendWithRetryStrategy","addEventListener","monitor","addBatchPrecision","url","indexOf","createHttpRequest","endpointUrl","bytesLimit","sendContentTypeByJson","reportError","contentType","undefined","retryState","sendStrategyForRetry","payload","onResponse","fetchKeepAliveStrategy","send","sendOnExit","sendBeaconStrategy","data","bytesCount","canUseBeacon","navigator","sendBeacon","beaconData","Blob","type","isQueued","e","sendXHR","canUseKeepAlive","isKeepAliveSupported","fetchOption","method","body","keepalive","mode","headers","fetch","then","response","status","window","Request","_unused","request","XMLHttpRequest","open","setRequestHeader","once"],"sources":["../../src/transport/httpRequest.js"],"sourcesContent":["import { newRetryState, sendWithRetryStrategy } from './sendWithRetryStrategy'\nimport { addEventListener } from '../browser/addEventListener'\nimport { monitor } from '../helper/monitor'\n/**\n * Use POST request without content type to:\n * - avoid CORS preflight requests\n * - allow usage of sendBeacon\n *\n * multiple elements are sent separated by \\n in order\n * to be parsed correctly without content type header\n */\nfunction addBatchPrecision(url) {\n if (!url) return url\n return url + (url.indexOf('?') === -1 ? '?' : '&') + 'precision=ms'\n}\nexport function createHttpRequest(\n endpointUrl,\n bytesLimit,\n sendContentTypeByJson,\n reportError\n) {\n var contentType = sendContentTypeByJson\n ? 'application/json; charset=UTF-8'\n : undefined\n var retryState = newRetryState()\n var sendStrategyForRetry = function (payload, onResponse) {\n return fetchKeepAliveStrategy(\n endpointUrl,\n bytesLimit,\n contentType,\n payload,\n onResponse\n )\n }\n\n return {\n send: function (payload) {\n sendWithRetryStrategy(\n payload,\n retryState,\n sendStrategyForRetry,\n endpointUrl,\n reportError\n )\n },\n /**\n * Since fetch keepalive behaves like regular fetch on Firefox,\n * keep using sendBeaconStrategy on exit\n */\n sendOnExit: function (payload) {\n sendBeaconStrategy(endpointUrl, bytesLimit, contentType, payload)\n }\n }\n}\n\nfunction sendBeaconStrategy(endpointUrl, bytesLimit, contentType, payload) {\n var data = payload.data\n var bytesCount = payload.bytesCount\n var url = addBatchPrecision(endpointUrl)\n var canUseBeacon = !!navigator.sendBeacon && bytesCount < bytesLimit\n if (canUseBeacon) {\n try {\n var beaconData\n if (contentType) {\n beaconData = new Blob([data], {\n type: contentType\n })\n } else {\n beaconData = data\n }\n\n var isQueued = navigator.sendBeacon(url, beaconData)\n\n if (isQueued) {\n return\n }\n } catch (e) {\n // reportBeaconError(e)\n }\n }\n sendXHR(url, contentType, data)\n}\n\nexport function fetchKeepAliveStrategy(\n endpointUrl,\n bytesLimit,\n contentType,\n payload,\n onResponse\n) {\n var data = payload.data\n var bytesCount = payload.bytesCount\n var url = addBatchPrecision(endpointUrl)\n var canUseKeepAlive = isKeepAliveSupported() && bytesCount < bytesLimit\n if (canUseKeepAlive) {\n var fetchOption = {\n method: 'POST',\n body: data,\n keepalive: true,\n mode: 'cors'\n }\n if (contentType) {\n fetchOption.headers = {\n 'Content-Type': contentType\n }\n }\n fetch(url, fetchOption).then(\n monitor(function (response) {\n if (typeof onResponse === 'function') {\n onResponse({ status: response.status, type: response.type })\n }\n }),\n monitor(function () {\n // failed to queue the request\n sendXHR(url, contentType, data, onResponse)\n })\n )\n } else {\n sendXHR(url, contentType, data, onResponse)\n }\n}\n\nfunction isKeepAliveSupported() {\n // Request can throw, cf https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#errors\n try {\n return window.Request && 'keepalive' in new Request('http://a')\n } catch {\n return false\n }\n}\n\nfunction sendXHR(url, contentType, data, onResponse) {\n const request = new XMLHttpRequest()\n request.open('POST', url, true)\n if (contentType) {\n //application/json; charset=UTF-8\n request.setRequestHeader('Content-Type', contentType)\n }\n\n addEventListener(\n request,\n 'loadend',\n function () {\n if (typeof onResponse === 'function') {\n onResponse({ status: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,IAAI,CAACG,IAAI,CAAC;AACpB","ignoreList":[]}
1
+ {"version":3,"file":"httpRequest.js","names":["newRetryState","sendWithRetryStrategy","addEventListener","monitor","addTelemetryError","addBatchPrecision","url","encoding","indexOf","createHttpRequest","endpointUrl","bytesLimit","reportError","retryState","sendStrategyForRetry","payload","onResponse","fetchKeepAliveStrategy","send","sendOnExit","sendBeaconStrategy","data","bytesCount","canUseBeacon","navigator","sendBeacon","beaconData","type","Blob","isQueued","e","reportBeaconError","sendXHR","hasReportedBeaconError","canUseKeepAlive","isKeepAliveSupported","fetchOption","method","body","keepalive","mode","headers","fetch","then","response","status","window","Request","_unused","request","XMLHttpRequest","open","setRequestHeader","once"],"sources":["../../src/transport/httpRequest.js"],"sourcesContent":["import { newRetryState, sendWithRetryStrategy } from './sendWithRetryStrategy'\nimport { addEventListener } from '../browser/addEventListener'\nimport { monitor } from '../helper/monitor'\nimport { addTelemetryError } from '../telemetry/telemetry'\n/**\n * Use POST request without content type to:\n * - avoid CORS preflight requests\n * - allow usage of sendBeacon\n *\n * multiple elements are sent separated by \\n in order\n * to be parsed correctly without content type header\n */\nfunction addBatchPrecision(url, encoding) {\n if (!url) return url\n url = url + (url.indexOf('?') === -1 ? '?' : '&') + 'precision=ms'\n if (encoding) {\n url = url + '&encoding=' + encoding\n }\n return url\n}\nexport function createHttpRequest(endpointUrl, bytesLimit, reportError) {\n var retryState = newRetryState()\n var sendStrategyForRetry = function (payload, onResponse) {\n return fetchKeepAliveStrategy(endpointUrl, bytesLimit, payload, onResponse)\n }\n\n return {\n send: function (payload) {\n sendWithRetryStrategy(\n payload,\n retryState,\n sendStrategyForRetry,\n endpointUrl,\n reportError\n )\n },\n /**\n * Since fetch keepalive behaves like regular fetch on Firefox,\n * keep using sendBeaconStrategy on exit\n */\n sendOnExit: function (payload) {\n sendBeaconStrategy(endpointUrl, bytesLimit, payload)\n }\n }\n}\n\nfunction sendBeaconStrategy(endpointUrl, bytesLimit, payload) {\n var data = payload.data\n var bytesCount = payload.bytesCount\n var url = addBatchPrecision(endpointUrl, payload.encoding)\n var canUseBeacon = !!navigator.sendBeacon && bytesCount < bytesLimit\n if (canUseBeacon) {\n try {\n var beaconData\n if (payload.type) {\n beaconData = new Blob([data], {\n type: payload.type\n })\n } else {\n beaconData = data\n }\n\n var isQueued = navigator.sendBeacon(url, beaconData)\n\n if (isQueued) {\n return\n }\n } catch (e) {\n reportBeaconError(e)\n }\n }\n sendXHR(url, payload)\n}\nvar hasReportedBeaconError = false\n\nfunction reportBeaconError(e) {\n if (!hasReportedBeaconError) {\n hasReportedBeaconError = true\n addTelemetryError(e)\n }\n}\nexport function fetchKeepAliveStrategy(\n endpointUrl,\n bytesLimit,\n payload,\n onResponse\n) {\n var data = payload.data\n var bytesCount = payload.bytesCount\n var url = addBatchPrecision(endpointUrl, payload.encoding)\n var canUseKeepAlive = isKeepAliveSupported() && bytesCount < bytesLimit\n if (canUseKeepAlive) {\n var fetchOption = {\n method: 'POST',\n body: data,\n keepalive: true,\n mode: 'cors'\n }\n if (payload.type) {\n fetchOption.headers = {\n 'Content-Type': payload.type\n }\n }\n fetch(url, fetchOption).then(\n monitor(function (response) {\n if (typeof onResponse === 'function') {\n onResponse({ status: response.status, type: response.type })\n }\n }),\n monitor(function () {\n // failed to queue the request\n sendXHR(url, payload, onResponse)\n })\n )\n } else {\n sendXHR(url, payload, onResponse)\n }\n}\n\nfunction isKeepAliveSupported() {\n // Request can throw, cf https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#errors\n try {\n return window.Request && 'keepalive' in new Request('http://a')\n } catch {\n return false\n }\n}\n\nfunction sendXHR(url, payload, onResponse) {\n const data = payload.data\n const request = new XMLHttpRequest()\n request.open('POST', url, true)\n if (data instanceof Blob) {\n request.setRequestHeader('Content-Type', data.type)\n } else if (payload.type) {\n request.setRequestHeader('Content-Type', payload.type)\n }\n\n addEventListener(\n request,\n 'loadend',\n function () {\n if (typeof onResponse === 'function') {\n onResponse({ status: request.status })\n }\n },\n {\n once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IAAI,YAAYO,IAAI,EAAE;IACxBqB,OAAO,CAACG,gBAAgB,CAAC,cAAc,EAAE/B,IAAI,CAACM,IAAI,CAAC;EACrD,CAAC,MAAM,IAAIZ,OAAO,CAACY,IAAI,EAAE;IACvBsB,OAAO,CAACG,gBAAgB,CAAC,cAAc,EAAErC,OAAO,CAACY,IAAI,CAAC;EACxD;EAEAzB,gBAAgB,CACd+C,OAAO,EACP,SAAS,EACT,YAAY;IACV,IAAI,OAAOjC,UAAU,KAAK,UAAU,EAAE;MACpCA,UAAU,CAAC;QAAE6B,MAAM,EAAEI,OAAO,CAACJ;MAAO,CAAC,CAAC;IACxC;EACF,CAAC,EACD;IACEQ,IAAI,EAAE;EACR,CACF,CAAC;EACDJ,OAAO,CAAC/B,IAAI,CAACG,IAAI,CAAC;AACpB","ignoreList":[]}
@@ -1,5 +1,5 @@
1
1
  export { createHttpRequest } from './httpRequest';
2
- export { Batch, processedMessageByDataMap } from './batch';
2
+ export { createBatch, processedMessageByDataMap } from './batch';
3
3
  export { startBatchWithReplica } from './startBatchWithReplica';
4
4
  export { createFlushController } from './flushController';
5
5
  export { getEventBridge, canUseEventBridge } from './eventBridge';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["createHttpRequest","Batch","processedMessageByDataMap","startBatchWithReplica","createFlushController","getEventBridge","canUseEventBridge"],"sources":["../../src/transport/index.js"],"sourcesContent":["export { createHttpRequest } from './httpRequest'\nexport { Batch, processedMessageByDataMap } from './batch'\nexport { startBatchWithReplica } from './startBatchWithReplica'\nexport { createFlushController } from './flushController'\nexport { getEventBridge, canUseEventBridge } from './eventBridge'\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,eAAe;AACjD,SAASC,KAAK,EAAEC,yBAAyB,QAAQ,SAAS;AAC1D,SAASC,qBAAqB,QAAQ,yBAAyB;AAC/D,SAASC,qBAAqB,QAAQ,mBAAmB;AACzD,SAASC,cAAc,EAAEC,iBAAiB,QAAQ,eAAe","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["createHttpRequest","createBatch","processedMessageByDataMap","startBatchWithReplica","createFlushController","getEventBridge","canUseEventBridge"],"sources":["../../src/transport/index.js"],"sourcesContent":["export { createHttpRequest } from './httpRequest'\nexport { createBatch, processedMessageByDataMap } from './batch'\nexport { startBatchWithReplica } from './startBatchWithReplica'\nexport { createFlushController } from './flushController'\nexport { getEventBridge, canUseEventBridge } from './eventBridge'\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,eAAe;AACjD,SAASC,WAAW,EAAEC,yBAAyB,QAAQ,SAAS;AAChE,SAASC,qBAAqB,QAAQ,yBAAyB;AAC/D,SAASC,qBAAqB,QAAQ,mBAAmB;AACzD,SAASC,cAAc,EAAEC,iBAAiB,QAAQ,eAAe","ignoreList":[]}