@amplitude/session-replay-browser
Advanced tools
Comparing version 1.3.0 to 1.3.1
@@ -20,4 +20,5 @@ import { SessionReplaySessionIDBStore as AmplitudeSessionReplaySessionIDBStore } from '../typings/session-replay'; | ||
getServerUrl(): "https://sr-client-cfg.amplitude.com/config" | "https://sr-client-cfg.stag2.amplitude.com/config" | "https://sr-client-cfg.eu.amplitude.com/config"; | ||
fetchRemoteConfig: (sessionId?: number) => Promise<ISessionReplayRemoteConfig | void>; | ||
retryFetch: (sessionId?: number) => Promise<ISessionReplayRemoteConfig | void>; | ||
fetchWithTimeout: (sessionId?: number) => Promise<ISessionReplayRemoteConfig | void>; | ||
fetchRemoteConfig: (signal: AbortController['signal'], sessionId?: number) => Promise<ISessionReplayRemoteConfig | void>; | ||
retryFetch: (signal: AbortController['signal'], sessionId?: number) => Promise<ISessionReplayRemoteConfig | void>; | ||
parseAndStoreConfig: (res: Response, sessionId?: number) => Promise<ISessionReplayRemoteConfig>; | ||
@@ -24,0 +25,0 @@ completeRequest({ err, success }: { |
@@ -10,2 +10,3 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
var MAX_RETRIES_EXCEEDED_MESSAGE = 'Session replay remote config fetch rejected due to exceeded retry count'; | ||
var TIMEOUT_MESSAGE = 'Session replay remote config fetch rejected due to timeout after 5 seconds'; | ||
exports.REMOTE_CONFIG_SERVER_URL = 'https://sr-client-cfg.amplitude.com/config'; | ||
@@ -32,3 +33,3 @@ exports.REMOTE_CONFIG_SERVER_URL_STAGING = 'https://sr-client-cfg.stag2.amplitude.com/config'; | ||
// Finally fetch via API | ||
return [2 /*return*/, this.fetchRemoteConfig(sessionId)]; | ||
return [2 /*return*/, this.fetchWithTimeout(sessionId)]; | ||
} | ||
@@ -48,10 +49,28 @@ }); | ||
}); }; | ||
this.fetchRemoteConfig = function (sessionId) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
var urlParams, options, serverUrl, res, parsedStatus, e_1; | ||
this.fetchWithTimeout = function (sessionId) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
var controller, timeoutId, remoteConfig; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
controller = new AbortController(); | ||
timeoutId = setTimeout(function () { return controller.abort(); }, 5000); | ||
return [4 /*yield*/, this.fetchRemoteConfig(controller.signal, sessionId)]; | ||
case 1: | ||
remoteConfig = _a.sent(); | ||
clearTimeout(timeoutId); | ||
return [2 /*return*/, remoteConfig]; | ||
} | ||
}); | ||
}); }; | ||
this.fetchRemoteConfig = function (signal, sessionId) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
var urlParams, options, serverUrl, res, parsedStatus, e_1, knownError; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (sessionId === this.lastFetchedSessionId && this.attempts >= this.localConfig.flushMaxRetries) { | ||
return [2 /*return*/, this.completeRequest({ err: MAX_RETRIES_EXCEEDED_MESSAGE })]; | ||
} | ||
else if (signal.aborted) { | ||
return [2 /*return*/, this.completeRequest({ err: TIMEOUT_MESSAGE })]; | ||
} | ||
else if (sessionId !== this.lastFetchedSessionId) { | ||
@@ -77,3 +96,3 @@ this.lastFetchedSessionId = sessionId; | ||
this.attempts += 1; | ||
return [4 /*yield*/, fetch(serverUrl, options)]; | ||
return [4 /*yield*/, fetch(serverUrl, tslib_1.__assign(tslib_1.__assign({}, options), { signal: signal }))]; | ||
case 2: | ||
@@ -89,3 +108,3 @@ res = _a.sent(); | ||
case analytics_types_1.Status.Failed: | ||
return [2 /*return*/, this.retryFetch(sessionId)]; | ||
return [2 /*return*/, this.retryFetch(signal, sessionId)]; | ||
default: | ||
@@ -97,3 +116,7 @@ return [2 /*return*/, this.completeRequest({ err: UNEXPECTED_NETWORK_ERROR_MESSAGE })]; | ||
e_1 = _a.sent(); | ||
return [2 /*return*/, this.completeRequest({ err: e_1 })]; | ||
knownError = e_1; | ||
if (signal.aborted) { | ||
return [2 /*return*/, this.completeRequest({ err: TIMEOUT_MESSAGE })]; | ||
} | ||
return [2 /*return*/, this.completeRequest({ err: knownError.message })]; | ||
case 4: return [2 /*return*/]; | ||
@@ -103,3 +126,3 @@ } | ||
}); }; | ||
this.retryFetch = function (sessionId) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
this.retryFetch = function (signal, sessionId) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
var _this = this; | ||
@@ -111,3 +134,3 @@ return tslib_1.__generator(this, function (_a) { | ||
_a.sent(); | ||
return [2 /*return*/, this.fetchRemoteConfig(sessionId)]; | ||
return [2 /*return*/, this.fetchRemoteConfig(signal, sessionId)]; | ||
} | ||
@@ -114,0 +137,0 @@ }); |
@@ -83,8 +83,9 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var deviceIdForReplayId, _a; | ||
var previousSessionId, deviceIdForReplayId, _a; | ||
return tslib_1.__generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
if (this.identifiers && this.identifiers.sessionId) { | ||
this.stopRecordingAndSendEvents(this.identifiers.sessionId); | ||
previousSessionId = this.identifiers && this.identifiers.sessionId; | ||
if (previousSessionId) { | ||
this.stopRecordingAndSendEvents(previousSessionId); | ||
} | ||
@@ -97,3 +98,3 @@ deviceIdForReplayId = deviceId || this.getDeviceId(); | ||
this.eventsManager && this.eventsManager.resetSequence(); | ||
if (!this.joinedConfigGenerator) return [3 /*break*/, 2]; | ||
if (!(this.joinedConfigGenerator && previousSessionId)) return [3 /*break*/, 2]; | ||
_a = this; | ||
@@ -100,0 +101,0 @@ return [4 /*yield*/, this.joinedConfigGenerator.generateJoinedConfig(this.identifiers.sessionId)]; |
@@ -20,4 +20,5 @@ import { SessionReplaySessionIDBStore as AmplitudeSessionReplaySessionIDBStore } from '../typings/session-replay'; | ||
getServerUrl(): "https://sr-client-cfg.amplitude.com/config" | "https://sr-client-cfg.stag2.amplitude.com/config" | "https://sr-client-cfg.eu.amplitude.com/config"; | ||
fetchRemoteConfig: (sessionId?: number) => Promise<ISessionReplayRemoteConfig | void>; | ||
retryFetch: (sessionId?: number) => Promise<ISessionReplayRemoteConfig | void>; | ||
fetchWithTimeout: (sessionId?: number) => Promise<ISessionReplayRemoteConfig | void>; | ||
fetchRemoteConfig: (signal: AbortController['signal'], sessionId?: number) => Promise<ISessionReplayRemoteConfig | void>; | ||
retryFetch: (signal: AbortController['signal'], sessionId?: number) => Promise<ISessionReplayRemoteConfig | void>; | ||
parseAndStoreConfig: (res: Response, sessionId?: number) => Promise<ISessionReplayRemoteConfig>; | ||
@@ -24,0 +25,0 @@ completeRequest({ err, success }: { |
@@ -1,2 +0,2 @@ | ||
import { __awaiter, __generator } from "tslib"; | ||
import { __assign, __awaiter, __generator } from "tslib"; | ||
import { BaseTransport } from '@amplitude/analytics-core'; | ||
@@ -8,2 +8,3 @@ import { ServerZone, Status } from '@amplitude/analytics-types'; | ||
var MAX_RETRIES_EXCEEDED_MESSAGE = 'Session replay remote config fetch rejected due to exceeded retry count'; | ||
var TIMEOUT_MESSAGE = 'Session replay remote config fetch rejected due to timeout after 5 seconds'; | ||
export var REMOTE_CONFIG_SERVER_URL = 'https://sr-client-cfg.amplitude.com/config'; | ||
@@ -30,3 +31,3 @@ export var REMOTE_CONFIG_SERVER_URL_STAGING = 'https://sr-client-cfg.stag2.amplitude.com/config'; | ||
// Finally fetch via API | ||
return [2 /*return*/, this.fetchRemoteConfig(sessionId)]; | ||
return [2 /*return*/, this.fetchWithTimeout(sessionId)]; | ||
} | ||
@@ -46,10 +47,28 @@ }); | ||
}); }; | ||
this.fetchRemoteConfig = function (sessionId) { return __awaiter(_this, void 0, void 0, function () { | ||
var urlParams, options, serverUrl, res, parsedStatus, e_1; | ||
this.fetchWithTimeout = function (sessionId) { return __awaiter(_this, void 0, void 0, function () { | ||
var controller, timeoutId, remoteConfig; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
controller = new AbortController(); | ||
timeoutId = setTimeout(function () { return controller.abort(); }, 5000); | ||
return [4 /*yield*/, this.fetchRemoteConfig(controller.signal, sessionId)]; | ||
case 1: | ||
remoteConfig = _a.sent(); | ||
clearTimeout(timeoutId); | ||
return [2 /*return*/, remoteConfig]; | ||
} | ||
}); | ||
}); }; | ||
this.fetchRemoteConfig = function (signal, sessionId) { return __awaiter(_this, void 0, void 0, function () { | ||
var urlParams, options, serverUrl, res, parsedStatus, e_1, knownError; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (sessionId === this.lastFetchedSessionId && this.attempts >= this.localConfig.flushMaxRetries) { | ||
return [2 /*return*/, this.completeRequest({ err: MAX_RETRIES_EXCEEDED_MESSAGE })]; | ||
} | ||
else if (signal.aborted) { | ||
return [2 /*return*/, this.completeRequest({ err: TIMEOUT_MESSAGE })]; | ||
} | ||
else if (sessionId !== this.lastFetchedSessionId) { | ||
@@ -75,3 +94,3 @@ this.lastFetchedSessionId = sessionId; | ||
this.attempts += 1; | ||
return [4 /*yield*/, fetch(serverUrl, options)]; | ||
return [4 /*yield*/, fetch(serverUrl, __assign(__assign({}, options), { signal: signal }))]; | ||
case 2: | ||
@@ -87,3 +106,3 @@ res = _a.sent(); | ||
case Status.Failed: | ||
return [2 /*return*/, this.retryFetch(sessionId)]; | ||
return [2 /*return*/, this.retryFetch(signal, sessionId)]; | ||
default: | ||
@@ -95,3 +114,7 @@ return [2 /*return*/, this.completeRequest({ err: UNEXPECTED_NETWORK_ERROR_MESSAGE })]; | ||
e_1 = _a.sent(); | ||
return [2 /*return*/, this.completeRequest({ err: e_1 })]; | ||
knownError = e_1; | ||
if (signal.aborted) { | ||
return [2 /*return*/, this.completeRequest({ err: TIMEOUT_MESSAGE })]; | ||
} | ||
return [2 /*return*/, this.completeRequest({ err: knownError.message })]; | ||
case 4: return [2 /*return*/]; | ||
@@ -101,3 +124,3 @@ } | ||
}); }; | ||
this.retryFetch = function (sessionId) { return __awaiter(_this, void 0, void 0, function () { | ||
this.retryFetch = function (signal, sessionId) { return __awaiter(_this, void 0, void 0, function () { | ||
var _this = this; | ||
@@ -109,3 +132,3 @@ return __generator(this, function (_a) { | ||
_a.sent(); | ||
return [2 /*return*/, this.fetchRemoteConfig(sessionId)]; | ||
return [2 /*return*/, this.fetchRemoteConfig(signal, sessionId)]; | ||
} | ||
@@ -112,0 +135,0 @@ }); |
@@ -81,8 +81,9 @@ import { __awaiter, __generator } from "tslib"; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var deviceIdForReplayId, _a; | ||
var previousSessionId, deviceIdForReplayId, _a; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
if (this.identifiers && this.identifiers.sessionId) { | ||
this.stopRecordingAndSendEvents(this.identifiers.sessionId); | ||
previousSessionId = this.identifiers && this.identifiers.sessionId; | ||
if (previousSessionId) { | ||
this.stopRecordingAndSendEvents(previousSessionId); | ||
} | ||
@@ -95,3 +96,3 @@ deviceIdForReplayId = deviceId || this.getDeviceId(); | ||
this.eventsManager && this.eventsManager.resetSequence(); | ||
if (!this.joinedConfigGenerator) return [3 /*break*/, 2]; | ||
if (!(this.joinedConfigGenerator && previousSessionId)) return [3 /*break*/, 2]; | ||
_a = this; | ||
@@ -98,0 +99,0 @@ return [4 /*yield*/, this.joinedConfigGenerator.generateJoinedConfig(this.identifiers.sessionId)]; |
@@ -20,4 +20,5 @@ import { SessionReplaySessionIDBStore as AmplitudeSessionReplaySessionIDBStore } from '../typings/session-replay'; | ||
getServerUrl(): "https://sr-client-cfg.amplitude.com/config" | "https://sr-client-cfg.stag2.amplitude.com/config" | "https://sr-client-cfg.eu.amplitude.com/config"; | ||
fetchRemoteConfig: (sessionId?: number) => Promise<ISessionReplayRemoteConfig | void>; | ||
retryFetch: (sessionId?: number) => Promise<ISessionReplayRemoteConfig | void>; | ||
fetchWithTimeout: (sessionId?: number) => Promise<ISessionReplayRemoteConfig | void>; | ||
fetchRemoteConfig: (signal: AbortController['signal'], sessionId?: number) => Promise<ISessionReplayRemoteConfig | void>; | ||
retryFetch: (signal: AbortController['signal'], sessionId?: number) => Promise<ISessionReplayRemoteConfig | void>; | ||
parseAndStoreConfig: (res: Response, sessionId?: number) => Promise<ISessionReplayRemoteConfig>; | ||
@@ -24,0 +25,0 @@ completeRequest({ err, success }: { |
{ | ||
"name": "@amplitude/session-replay-browser", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "", | ||
@@ -60,3 +60,3 @@ "author": "Amplitude Inc", | ||
], | ||
"gitHead": "9f230d02b960bab009c34c8f66d19967e4e090b2" | ||
"gitHead": "917318fd9a32afaf01301e59fe375bbc398ef9b3" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
679556
4285