@sentry/replay 0.5.5 → 0.5.6

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 (54) hide show
  1. package/dist/index.es.js +78 -48
  2. package/dist/index.js +78 -48
  3. package/dist/index.js.map +1 -1
  4. package/dist/jest.config.d.ts +3 -0
  5. package/dist/jest.setup.d.ts +10 -0
  6. package/dist/{types/src → src}/api/captureReplay.d.ts +0 -0
  7. package/dist/{types/src → src}/api/captureReplayUpdate.d.ts +0 -0
  8. package/dist/{types/src → src}/coreHandlers/getBreadcrumbHandler.d.ts +0 -0
  9. package/dist/{types/src → src}/coreHandlers/getSpanHandler.d.ts +0 -0
  10. package/dist/{types/src → src}/coreHandlers/handleDom.d.ts +0 -0
  11. package/dist/{types/src → src}/coreHandlers/handleFetch.d.ts +1 -1
  12. package/dist/src/coreHandlers/handleFetch.test.d.ts +1 -0
  13. package/dist/{types/src → src}/coreHandlers/handleHistory.d.ts +0 -0
  14. package/dist/src/coreHandlers/handleScope-unit.test.d.ts +1 -0
  15. package/dist/{types/src → src}/coreHandlers/handleScope.d.ts +0 -0
  16. package/dist/src/coreHandlers/handleScope.test.d.ts +1 -0
  17. package/dist/{types/src → src}/coreHandlers/handleXhr.d.ts +2 -2
  18. package/dist/{types/src → src}/createPerformanceEntry.d.ts +0 -0
  19. package/dist/src/createPerformanceEntry.test.d.ts +1 -0
  20. package/dist/{types/src → src}/eventBuffer.d.ts +0 -0
  21. package/dist/src/eventBuffer.test.d.ts +1 -0
  22. package/dist/{types/src → src}/flags.d.ts +0 -0
  23. package/dist/src/index-captureOnlyOnError.test.d.ts +1 -0
  24. package/dist/src/index-noSticky.test.d.ts +1 -0
  25. package/dist/src/index-sampling.test.d.ts +1 -0
  26. package/dist/{types/src → src}/index.d.ts +0 -0
  27. package/dist/src/index.test.d.ts +1 -0
  28. package/dist/{types/src → src}/session/Session.d.ts +2 -2
  29. package/dist/src/session/Session.test.d.ts +1 -0
  30. package/dist/{types/src → src}/session/constants.d.ts +0 -0
  31. package/dist/{types/src → src}/session/createSession.d.ts +0 -0
  32. package/dist/src/session/createSession.test.d.ts +1 -0
  33. package/dist/{types/src → src}/session/fetchSession.d.ts +0 -0
  34. package/dist/src/session/fetchSession.test.d.ts +1 -0
  35. package/dist/{types/src → src}/session/getSession.d.ts +0 -0
  36. package/dist/src/session/getSession.test.d.ts +1 -0
  37. package/dist/{types/src → src}/session/index.d.ts +0 -0
  38. package/dist/{types/src → src}/session/saveSession.d.ts +0 -0
  39. package/dist/src/session/saveSession.test.d.ts +1 -0
  40. package/dist/{types/src → src}/types.d.ts +0 -0
  41. package/dist/{types/src → src}/util/createBreadcrumb.d.ts +0 -0
  42. package/dist/{types/src → src}/util/createPayload.d.ts +0 -0
  43. package/dist/{types/src → src}/util/isExpired.d.ts +1 -1
  44. package/dist/src/util/isExpired.test.d.ts +1 -0
  45. package/dist/{types/src → src}/util/isIngestHost.d.ts +0 -0
  46. package/dist/{types/src → src}/util/isSampled.d.ts +0 -0
  47. package/dist/src/util/isSampled.test.d.ts +1 -0
  48. package/dist/{types/src → src}/util/isSessionExpired.d.ts +0 -0
  49. package/dist/src/util/isSessionExpired.test.d.ts +1 -0
  50. package/dist/{types/src → src}/util/logger.d.ts +0 -0
  51. package/dist/test/index.d.ts +3 -0
  52. package/dist/test/mocks/mockRrweb.d.ts +15 -0
  53. package/dist/test/mocks/mockSdk.d.ts +11 -0
  54. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -184,7 +184,8 @@ function getBreadcrumbHandler(type) {
184
184
  * Checks is `targetHost` is a Sentry ingestion host
185
185
  */
186
186
  function isIngestHost(targetHost) {
187
- var _a = core.getCurrentHub().getClient().getDsn(), protocol = _a.protocol, host = _a.host;
187
+ var _a;
188
+ var _b = ((_a = core.getCurrentHub().getClient()) === null || _a === void 0 ? void 0 : _a.getDsn()) || {}, protocol = _b.protocol, host = _b.host;
188
189
  return targetHost.startsWith("".concat(protocol, "://").concat(host));
189
190
  }
190
191
 
@@ -224,6 +225,7 @@ function handleHistory(handlerData) {
224
225
  }
225
226
 
226
227
  function handleXhr(handlerData) {
228
+ var _a;
227
229
  if (handlerData.xhr.__sentry_own_request__) {
228
230
  // Taken from sentry-javascript
229
231
  // Only capture non-sentry requests
@@ -231,20 +233,21 @@ function handleXhr(handlerData) {
231
233
  }
232
234
  if (handlerData.startTimestamp) {
233
235
  // TODO: See if this is still needed
236
+ handlerData.xhr.__sentry_xhr__ = handlerData.xhr.__sentry_xhr__ || {};
234
237
  handlerData.xhr.__sentry_xhr__.startTimestamp = handlerData.startTimestamp;
235
238
  }
236
239
  if (!handlerData.endTimestamp) {
237
240
  return null;
238
241
  }
239
- var _a = handlerData.xhr.__sentry_xhr__ || {}, method = _a.method, url = _a.url, statusCode = _a.status_code;
242
+ var _b = handlerData.xhr.__sentry_xhr__ || {}, method = _b.method, url = _b.url, statusCode = _b.status_code;
240
243
  // Do not capture fetches to Sentry ingestion endpoint
241
- if (isIngestHost(url)) {
244
+ if (url === undefined || isIngestHost(url)) {
242
245
  return null;
243
246
  }
244
247
  return {
245
248
  type: 'resource.xhr',
246
249
  name: url,
247
- start: handlerData.xhr.__sentry_xhr__.startTimestamp / 1000 ||
250
+ start: (((_a = handlerData.xhr.__sentry_xhr__) === null || _a === void 0 ? void 0 : _a.startTimestamp) || 0) / 1000 ||
248
251
  handlerData.endTimestamp / 1000.0,
249
252
  end: handlerData.endTimestamp / 1000.0,
250
253
  data: {
@@ -271,7 +274,7 @@ function getSpanHandler(type) {
271
274
  function isExpired(initialTime, expiry, targetTime) {
272
275
  if (targetTime === void 0) { targetTime = +new Date(); }
273
276
  // Always expired if < 0
274
- if (expiry < 0) {
277
+ if (initialTime === null || expiry === undefined || expiry < 0) {
275
278
  return true;
276
279
  }
277
280
  // Never expires if == 0
@@ -286,7 +289,7 @@ function isExpired(initialTime, expiry, targetTime) {
286
289
  */
287
290
  function isSessionExpired(session, expiry, targetTime) {
288
291
  if (targetTime === void 0) { targetTime = +new Date(); }
289
- return isExpired(session.lastActivity, expiry, targetTime);
292
+ return isExpired(session === null || session === void 0 ? void 0 : session.lastActivity, expiry, targetTime);
290
293
  }
291
294
 
292
295
  function wrapLogger(logFn) {
@@ -435,7 +438,9 @@ function fetchSession() {
435
438
  return null;
436
439
  }
437
440
  try {
438
- return new Session(JSON.parse(window.sessionStorage.getItem(REPLAY_SESSION_KEY)),
441
+ return new Session(
442
+ // @ts-expect-error: Type 'null' is not assignable to type 'string'.ts(2345)
443
+ JSON.parse(window.sessionStorage.getItem(REPLAY_SESSION_KEY)),
439
444
  // We are assuming that if there is a saved item, then the session is sticky,
440
445
  // however this could break down if we used a different storage mechanism (e.g. localstorage)
441
446
  { stickySession: true });
@@ -497,7 +502,9 @@ var ENTRY_TYPES = (_a = {
497
502
  _a['largest-contentful-paint'] = createLargestContentfulPaint,
498
503
  _a);
499
504
  function createPerformanceEntries(entries) {
500
- return entries.map(createPerformanceEntry).filter(Boolean);
505
+ return entries
506
+ .map(createPerformanceEntry)
507
+ .filter(Boolean);
501
508
  }
502
509
  function createPerformanceEntry(entry) {
503
510
  if (ENTRY_TYPES[entry.entryType] === undefined) {
@@ -691,7 +698,9 @@ var EventBufferCompressionWorker = /** @class */ (function () {
691
698
  var _this = this;
692
699
  var id = _a.id, method = _a.method, args = _a.args;
693
700
  return new Promise(function (resolve, reject) {
701
+ var _a, _b;
694
702
  var listener = function (_a) {
703
+ var _b;
695
704
  var data = _a.data;
696
705
  if (data.method !== method) {
697
706
  return;
@@ -702,7 +711,7 @@ var EventBufferCompressionWorker = /** @class */ (function () {
702
711
  return;
703
712
  }
704
713
  // At this point, we'll always want to remove listener regardless of result status
705
- _this.worker.removeEventListener('message', listener);
714
+ (_b = _this.worker) === null || _b === void 0 ? void 0 : _b.removeEventListener('message', listener);
706
715
  if (!data.success) {
707
716
  // TODO: Do some error handling, not sure what
708
717
  logger.error(data.response);
@@ -713,8 +722,8 @@ var EventBufferCompressionWorker = /** @class */ (function () {
713
722
  };
714
723
  // Note: we can't use `once` option because it's possible it needs to
715
724
  // listen to multiple messages
716
- _this.worker.addEventListener('message', listener);
717
- _this.worker.postMessage({ id: id, method: method, args: args });
725
+ (_a = _this.worker) === null || _a === void 0 ? void 0 : _a.addEventListener('message', listener);
726
+ (_b = _this.worker) === null || _b === void 0 ? void 0 : _b.postMessage({ id: id, method: method, args: args });
718
727
  });
719
728
  };
720
729
  EventBufferCompressionWorker.prototype.init = function () {
@@ -722,8 +731,9 @@ var EventBufferCompressionWorker = /** @class */ (function () {
722
731
  logger.log('Initialized compression worker');
723
732
  };
724
733
  EventBufferCompressionWorker.prototype.destroy = function () {
734
+ var _a;
725
735
  logger.log('Destroying compression worker');
726
- this.worker.terminate();
736
+ (_a = this.worker) === null || _a === void 0 ? void 0 : _a.terminate();
727
737
  this.worker = null;
728
738
  };
729
739
  Object.defineProperty(EventBufferCompressionWorker.prototype, "length", {
@@ -816,7 +826,7 @@ var SentryReplay = /** @class */ (function () {
816
826
  * when an error occurs.
817
827
  **/
818
828
  this.handleGlobalEvent = function (event) {
819
- var _a;
829
+ var _a, _b;
820
830
  // Do not apply replayId to the root event
821
831
  if (
822
832
  // @ts-expect-error new event type
@@ -826,12 +836,13 @@ var SentryReplay = /** @class */ (function () {
826
836
  delete event.breadcrumbs;
827
837
  return event;
828
838
  }
829
- event.tags = __assign(__assign({}, event.tags), { replayId: _this.session.id });
839
+ event.tags = __assign(__assign({}, event.tags), { replayId: (_a = _this.session) === null || _a === void 0 ? void 0 : _a.id });
830
840
  if (event.type === 'transaction') {
831
- _this.context.traceIds.add(String(((_a = event.contexts) === null || _a === void 0 ? void 0 : _a.trace.trace_id) || ''));
841
+ _this.context.traceIds.add(String(((_b = event.contexts) === null || _b === void 0 ? void 0 : _b.trace.trace_id) || ''));
832
842
  return event;
833
843
  }
834
844
  // XXX: Is it safe to assume that all other events are error events?
845
+ // @ts-expect-error: Type 'undefined' is not assignable to type 'string'.ts(2345)
835
846
  _this.context.errorIds.add(event.event_id);
836
847
  // Need to be very careful that this does not cause an infinite loop
837
848
  if (_this.options.captureOnlyOnError &&
@@ -856,6 +867,7 @@ var SentryReplay = /** @class */ (function () {
856
867
  return;
857
868
  }
858
869
  _this.addUpdate(function () {
870
+ var _a;
859
871
  // We need to clear existing events on a checkout, otherwise they are
860
872
  // incremental event updates and should be appended
861
873
  _this.addEvent(event, isCheckout);
@@ -870,7 +882,7 @@ var SentryReplay = /** @class */ (function () {
870
882
  // of the previous session. Do not immediately flush in this case
871
883
  // to avoid capturing only the checkout and instead the replay will
872
884
  // be captured if they perform any follow-up actions.
873
- if (_this.session.previousSessionId) {
885
+ if ((_a = _this.session) === null || _a === void 0 ? void 0 : _a.previousSessionId) {
874
886
  return true;
875
887
  }
876
888
  // If the full snapshot is due to an initial load, we will not have
@@ -941,6 +953,10 @@ var SentryReplay = /** @class */ (function () {
941
953
  }
942
954
  _this.addUpdate(function () {
943
955
  _this.createPerformanceSpans([result]);
956
+ // Returning true will cause `addUpdate` to not flush
957
+ // We do not want network requests to cause a flush. This will prevent
958
+ // recurring/polling requests from keeping the replay session alive.
959
+ return ['xhr', 'fetch'].includes(type);
944
960
  });
945
961
  }; };
946
962
  /**
@@ -962,7 +978,7 @@ var SentryReplay = /** @class */ (function () {
962
978
  type: rrweb.EventType.Custom,
963
979
  // TODO: We were converting from ms to seconds for breadcrumbs, spans,
964
980
  // but maybe we should just keep them as milliseconds
965
- timestamp: result.timestamp * 1000,
981
+ timestamp: (result.timestamp || 0) * 1000,
966
982
  data: {
967
983
  tag: 'breadcrumb',
968
984
  payload: result,
@@ -1025,7 +1041,7 @@ var SentryReplay = /** @class */ (function () {
1025
1041
  return;
1026
1042
  }
1027
1043
  this.eventBuffer = createEventBuffer({
1028
- useCompression: this.options.useCompression,
1044
+ useCompression: Boolean(this.options.useCompression),
1029
1045
  });
1030
1046
  this.addListeners();
1031
1047
  // Tag all (non replay) events that get sent to Sentry with the current
@@ -1090,7 +1106,7 @@ var SentryReplay = /** @class */ (function () {
1090
1106
  this.removeListeners();
1091
1107
  };
1092
1108
  SentryReplay.prototype.clearSession = function () {
1093
- this.session = null;
1109
+ this.session = undefined;
1094
1110
  };
1095
1111
  /**
1096
1112
  * Loads a session from storage, or creates a new one if it does not exist or
@@ -1101,7 +1117,7 @@ var SentryReplay = /** @class */ (function () {
1101
1117
  var expiry = _a.expiry;
1102
1118
  var _d = getSession({
1103
1119
  expiry: expiry,
1104
- stickySession: this.options.stickySession,
1120
+ stickySession: Boolean(this.options.stickySession),
1105
1121
  currentSession: this.session,
1106
1122
  samplingRate: this.options.replaysSamplingRate,
1107
1123
  }), type = _d.type, session = _d.session;
@@ -1143,7 +1159,7 @@ var SentryReplay = /** @class */ (function () {
1143
1159
  window.addEventListener('beforeunload', this.handleWindowUnload);
1144
1160
  // Listeners from core SDK //
1145
1161
  var scope = core.getCurrentHub().getScope();
1146
- scope.addScopeListener(this.handleCoreBreadcrumbListener('scope'));
1162
+ scope === null || scope === void 0 ? void 0 : scope.addScopeListener(this.handleCoreBreadcrumbListener('scope'));
1147
1163
  utils.addInstrumentationHandler('dom', this.handleCoreBreadcrumbListener('dom'));
1148
1164
  utils.addInstrumentationHandler('fetch', this.handleCoreSpanListener('fetch'));
1149
1165
  utils.addInstrumentationHandler('xhr', this.handleCoreSpanListener('xhr'));
@@ -1165,7 +1181,8 @@ var SentryReplay = /** @class */ (function () {
1165
1181
  'paint',
1166
1182
  'resource',
1167
1183
  ].forEach(function (type) {
1168
- return _this.performanceObserver.observe({
1184
+ var _a;
1185
+ return (_a = _this.performanceObserver) === null || _a === void 0 ? void 0 : _a.observe({
1169
1186
  type: type,
1170
1187
  buffered: true,
1171
1188
  });
@@ -1188,6 +1205,9 @@ var SentryReplay = /** @class */ (function () {
1188
1205
  * Tasks to run when we consider a page to be hidden (via blurring and/or visibility)
1189
1206
  */
1190
1207
  SentryReplay.prototype.doChangeToBackgroundTasks = function (breadcrumb) {
1208
+ if (!this.session) {
1209
+ return;
1210
+ }
1191
1211
  var isExpired = isSessionExpired(this.session, VISIBILITY_CHANGE_TIMEOUT);
1192
1212
  if (breadcrumb) {
1193
1213
  this.createCustomBreadcrumb(__assign(__assign({}, breadcrumb), {
@@ -1205,6 +1225,9 @@ var SentryReplay = /** @class */ (function () {
1205
1225
  * Tasks to run when we consider a page to be visible (via focus and/or visibility)
1206
1226
  */
1207
1227
  SentryReplay.prototype.doChangeToForegroundTasks = function (breadcrumb) {
1228
+ if (!this.session) {
1229
+ return;
1230
+ }
1208
1231
  var isExpired = isSessionExpired(this.session, VISIBILITY_CHANGE_TIMEOUT);
1209
1232
  if (breadcrumb) {
1210
1233
  this.createCustomBreadcrumb(__assign(__assign({}, breadcrumb), { timestamp: isExpired
@@ -1250,7 +1273,9 @@ var SentryReplay = /** @class */ (function () {
1250
1273
  */
1251
1274
  SentryReplay.prototype.updateLastActivity = function (lastActivity) {
1252
1275
  if (lastActivity === void 0) { lastActivity = new Date().getTime(); }
1253
- this.session.lastActivity = lastActivity;
1276
+ if (this.session) {
1277
+ this.session.lastActivity = lastActivity;
1278
+ }
1254
1279
  };
1255
1280
  /**
1256
1281
  * Helper to create (and buffer) a replay breadcrumb from a core SDK breadcrumb
@@ -1260,7 +1285,7 @@ var SentryReplay = /** @class */ (function () {
1260
1285
  this.addUpdate(function () {
1261
1286
  _this.addEvent({
1262
1287
  type: rrweb.EventType.Custom,
1263
- timestamp: breadcrumb.timestamp,
1288
+ timestamp: breadcrumb.timestamp || 0,
1264
1289
  data: {
1265
1290
  tag: 'breadcrumb',
1266
1291
  payload: breadcrumb,
@@ -1322,12 +1347,13 @@ var SentryReplay = /** @class */ (function () {
1322
1347
  * Returns true if session is not expired, false otherwise.
1323
1348
  */
1324
1349
  SentryReplay.prototype.checkAndHandleExpiredSession = function (expiry) {
1350
+ var _a, _b;
1325
1351
  if (expiry === void 0) { expiry = SESSION_IDLE_DURATION; }
1326
- var oldSessionId = this.session.id;
1352
+ var oldSessionId = (_a = this.session) === null || _a === void 0 ? void 0 : _a.id;
1327
1353
  // This will create a new session if expired, based on expiry length
1328
1354
  this.loadSession({ expiry: expiry });
1329
1355
  // Session was expired if session ids do not match
1330
- var isExpired = oldSessionId !== this.session.id;
1356
+ var isExpired = oldSessionId !== ((_b = this.session) === null || _b === void 0 ? void 0 : _b.id);
1331
1357
  if (!isExpired) {
1332
1358
  return true;
1333
1359
  }
@@ -1371,6 +1397,7 @@ var SentryReplay = /** @class */ (function () {
1371
1397
  this.context.traceIds.clear();
1372
1398
  this.context.urls = [];
1373
1399
  this.context.earliestEvent = null;
1400
+ // @ts-expect-error: Type 'undefined' is not assignable to type 'Session'.ts(2322)
1374
1401
  return context;
1375
1402
  };
1376
1403
  /**
@@ -1380,16 +1407,17 @@ var SentryReplay = /** @class */ (function () {
1380
1407
  * due to the buffered performance observer events.
1381
1408
  */
1382
1409
  SentryReplay.prototype.flushUpdate = function (lastActivity) {
1410
+ var _a;
1383
1411
  return __awaiter(this, void 0, void 0, function () {
1384
1412
  var timestamp, recordingData, err_1;
1385
- return __generator(this, function (_a) {
1386
- switch (_a.label) {
1413
+ return __generator(this, function (_b) {
1414
+ switch (_b.label) {
1387
1415
  case 0:
1388
1416
  if (!this.checkAndHandleExpiredSession()) {
1389
1417
  logger.error(new Error('Attempting to finish replay event after session expired.'));
1390
1418
  return [2 /*return*/];
1391
1419
  }
1392
- if (!this.session.id) {
1420
+ if (!((_a = this.session) === null || _a === void 0 ? void 0 : _a.id)) {
1393
1421
  console.error(new Error('[Sentry]: No transaction, no replay'));
1394
1422
  return [2 /*return*/];
1395
1423
  }
@@ -1397,7 +1425,7 @@ var SentryReplay = /** @class */ (function () {
1397
1425
  clearTimeout(this.timeout);
1398
1426
  return [4 /*yield*/, this.addPerformanceEntries()];
1399
1427
  case 1:
1400
- _a.sent();
1428
+ _b.sent();
1401
1429
  if (!this.eventBuffer.length) {
1402
1430
  return [2 /*return*/];
1403
1431
  }
@@ -1405,7 +1433,7 @@ var SentryReplay = /** @class */ (function () {
1405
1433
  return [4 /*yield*/, this.addMemoryEntry()];
1406
1434
  case 2:
1407
1435
  // Only attach memory event if eventBuffer is not empty
1408
- _a.sent();
1436
+ _b.sent();
1409
1437
  timestamp = lastActivity !== null && lastActivity !== void 0 ? lastActivity : new Date().getTime();
1410
1438
  // Only want to create replay event if session is new
1411
1439
  if (this.needsCaptureReplay) {
@@ -1416,15 +1444,15 @@ var SentryReplay = /** @class */ (function () {
1416
1444
  // Reset this to null regardless of `sendReplay` result so that future
1417
1445
  // events will get flushed properly
1418
1446
  this.initialEventTimestampSinceFlush = null;
1419
- _a.label = 3;
1447
+ _b.label = 3;
1420
1448
  case 3:
1421
- _a.trys.push([3, 6, , 7]);
1449
+ _b.trys.push([3, 6, , 7]);
1422
1450
  return [4 /*yield*/, this.eventBuffer.finish()];
1423
1451
  case 4:
1424
- recordingData = _a.sent();
1452
+ recordingData = _b.sent();
1425
1453
  return [4 /*yield*/, this.sendReplay(this.session.id, recordingData)];
1426
1454
  case 5:
1427
- _a.sent();
1455
+ _b.sent();
1428
1456
  // The below will only happen after successfully sending replay //
1429
1457
  // TBD: Alternatively we could update this after every rrweb event
1430
1458
  // `timestamp` should reflect when the event happens. e.g. the timestamp
@@ -1434,7 +1462,7 @@ var SentryReplay = /** @class */ (function () {
1434
1462
  captureReplayUpdate(this.popEventContext({ timestamp: timestamp }));
1435
1463
  return [3 /*break*/, 7];
1436
1464
  case 6:
1437
- err_1 = _a.sent();
1465
+ err_1 = _b.sent();
1438
1466
  core.captureException(err_1);
1439
1467
  console.error(err_1);
1440
1468
  return [3 /*break*/, 7];
@@ -1447,21 +1475,22 @@ var SentryReplay = /** @class */ (function () {
1447
1475
  * Send replay attachment using `fetch()`
1448
1476
  */
1449
1477
  SentryReplay.prototype.sendReplayRequest = function (_a) {
1478
+ var _b, _c;
1450
1479
  var endpoint = _a.endpoint, events = _a.events;
1451
1480
  return __awaiter(this, void 0, void 0, function () {
1452
- var payloadWithSequence, envelope, response, _b, _c;
1453
- var _d;
1454
- return __generator(this, function (_e) {
1455
- switch (_e.label) {
1481
+ var payloadWithSequence, envelope, response, _d, _e;
1482
+ var _f;
1483
+ return __generator(this, function (_g) {
1484
+ switch (_g.label) {
1456
1485
  case 0:
1457
1486
  payloadWithSequence = createPayload({
1458
1487
  events: events,
1459
1488
  headers: {
1460
- segment_id: this.session.segmentId,
1489
+ segment_id: (_b = this.session) === null || _b === void 0 ? void 0 : _b.segmentId,
1461
1490
  },
1462
1491
  });
1463
1492
  envelope = utils.createEnvelope({
1464
- event_id: this.session.id,
1493
+ event_id: (_c = this.session) === null || _c === void 0 ? void 0 : _c.id,
1465
1494
  sent_at: new Date().toISOString(),
1466
1495
  sdk: { name: 'sentry.javascript.integration.replay', version: '1.0.0' },
1467
1496
  }, [
@@ -1471,6 +1500,7 @@ var SentryReplay = /** @class */ (function () {
1471
1500
  type: 'replay_recording',
1472
1501
  length: payloadWithSequence.length,
1473
1502
  },
1503
+ // @ts-expect-error: Type 'string' is not assignable to type 'ClientReport'.ts(2322)
1474
1504
  payloadWithSequence,
1475
1505
  ],
1476
1506
  ]);
@@ -1481,17 +1511,17 @@ var SentryReplay = /** @class */ (function () {
1481
1511
  body: utils.serializeEnvelope(envelope),
1482
1512
  })];
1483
1513
  case 1:
1484
- response = _e.sent();
1514
+ response = _g.sent();
1485
1515
  if (!(response.status !== 200)) return [3 /*break*/, 3];
1486
- _b = core.setContext;
1487
- _c = ['Send Replay Response'];
1488
- _d = {
1516
+ _d = core.setContext;
1517
+ _e = ['Send Replay Response'];
1518
+ _f = {
1489
1519
  status: response.status
1490
1520
  };
1491
1521
  return [4 /*yield*/, response.text()];
1492
1522
  case 2:
1493
- _b.apply(void 0, _c.concat([(_d.body = _e.sent(),
1494
- _d)]));
1523
+ _d.apply(void 0, _e.concat([(_f.body = _g.sent(),
1524
+ _f)]));
1495
1525
  throw new Error(UNABLE_TO_SEND_REPLAY);
1496
1526
  case 3: return [2 /*return*/];
1497
1527
  }