@sentry/browser 6.18.0 → 6.18.1

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.
@@ -1,4 +1,4 @@
1
- /*! @sentry/browser 6.18.0 (70c1d77) | https://github.com/getsentry/sentry-javascript */
1
+ /*! @sentry/browser 6.18.1 (cb18c43) | https://github.com/getsentry/sentry-javascript */
2
2
  var Sentry = (function (exports) {
3
3
 
4
4
  /**
@@ -2190,6 +2190,47 @@ var Sentry = (function (exports) {
2190
2190
  return dateNow;
2191
2191
  })();
2192
2192
 
2193
+ /**
2194
+ * Creates an envelope.
2195
+ * Make sure to always explicitly provide the generic to this function
2196
+ * so that the envelope types resolve correctly.
2197
+ */
2198
+ function createEnvelope(headers, items = []) {
2199
+ return [headers, items];
2200
+ }
2201
+ /**
2202
+ * Serializes an envelope into a string.
2203
+ */
2204
+ function serializeEnvelope(envelope) {
2205
+ const [headers, items] = envelope;
2206
+ const serializedHeaders = JSON.stringify(headers);
2207
+ // Have to cast items to any here since Envelope is a union type
2208
+ // Fixed in Typescript 4.2
2209
+ // TODO: Remove any[] cast when we upgrade to TS 4.2
2210
+ // https://github.com/microsoft/TypeScript/issues/36390
2211
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2212
+ return items.reduce((acc, item) => {
2213
+ const [itemHeaders, payload] = item;
2214
+ return `${acc}\n${JSON.stringify(itemHeaders)}\n${JSON.stringify(payload)}`;
2215
+ }, serializedHeaders);
2216
+ }
2217
+
2218
+ /**
2219
+ * Creates client report envelope
2220
+ * @param discarded_events An array of discard events
2221
+ * @param dsn A DSN that can be set on the header. Optional.
2222
+ */
2223
+ function createClientReportEnvelope(discarded_events, dsn, timestamp) {
2224
+ const clientReportItem = [
2225
+ { type: 'client_report' },
2226
+ {
2227
+ timestamp: timestamp || dateTimestampInSeconds(),
2228
+ discarded_events,
2229
+ },
2230
+ ];
2231
+ return createEnvelope(dsn ? { dsn } : {}, [clientReportItem]);
2232
+ }
2233
+
2193
2234
  /**
2194
2235
  * Absolute maximum number of breadcrumbs added to an event.
2195
2236
  * The `maxBreadcrumbs` option cannot be higher than this value.
@@ -4244,7 +4285,7 @@ var Sentry = (function (exports) {
4244
4285
  hub.bindClient(client);
4245
4286
  }
4246
4287
 
4247
- const SDK_VERSION = '6.18.0';
4288
+ const SDK_VERSION = '6.18.1';
4248
4289
 
4249
4290
  let originalFunctionToString;
4250
4291
  /** Patch toString calls to return proper name for wrapped functions */
@@ -4972,25 +5013,18 @@ var Sentry = (function (exports) {
4972
5013
  }
4973
5014
  logger.log(`Flushing outcomes:\n${JSON.stringify(outcomes, null, 2)}`);
4974
5015
  const url = getEnvelopeEndpointWithUrlEncodedAuth(this._api.dsn, this._api.tunnel);
4975
- // Envelope header is required to be at least an empty object
4976
- const envelopeHeader = JSON.stringify(Object.assign({}, (this._api.tunnel && { dsn: dsnToString(this._api.dsn) })));
4977
- const itemHeaders = JSON.stringify({
4978
- type: 'client_report',
4979
- });
4980
- const item = JSON.stringify({
4981
- timestamp: dateTimestampInSeconds(),
4982
- discarded_events: Object.keys(outcomes).map(key => {
4983
- const [category, reason] = key.split(':');
4984
- return {
4985
- reason,
4986
- category,
4987
- quantity: outcomes[key],
4988
- };
4989
- }),
5016
+ const discardedEvents = Object.keys(outcomes).map(key => {
5017
+ const [category, reason] = key.split(':');
5018
+ return {
5019
+ reason,
5020
+ category,
5021
+ quantity: outcomes[key],
5022
+ };
5023
+ // TODO: Improve types on discarded_events to get rid of cast
4990
5024
  });
4991
- const envelope = `${envelopeHeader}\n${itemHeaders}\n${item}`;
5025
+ const envelope = createClientReportEnvelope(discardedEvents, this._api.tunnel && dsnToString(this._api.dsn));
4992
5026
  try {
4993
- sendReport(url, envelope);
5027
+ sendReport(url, serializeEnvelope(envelope));
4994
5028
  }
4995
5029
  catch (e) {
4996
5030
  logger.error(e);