@amplitude/plugin-session-replay-browser 1.14.0 → 1.16.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.
- package/lib/cjs/index.d.ts +2 -1
- package/lib/cjs/index.d.ts.map +1 -1
- package/lib/cjs/index.js +2 -1
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/session-replay.d.ts +7 -0
- package/lib/cjs/session-replay.d.ts.map +1 -1
- package/lib/cjs/session-replay.js +77 -34
- package/lib/cjs/session-replay.js.map +1 -1
- package/lib/cjs/version.d.ts +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/cjs/version.js.map +1 -1
- package/lib/esm/index.d.ts +2 -1
- package/lib/esm/index.d.ts.map +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/session-replay.d.ts +7 -0
- package/lib/esm/session-replay.d.ts.map +1 -1
- package/lib/esm/session-replay.js +77 -34
- package/lib/esm/session-replay.js.map +1 -1
- package/lib/esm/version.d.ts +1 -1
- package/lib/esm/version.js +1 -1
- package/lib/esm/version.js.map +1 -1
- package/lib/scripts/amplitude-min.js +1 -1
- package/lib/scripts/amplitude-min.js.gz +0 -0
- package/lib/scripts/amplitude-min.js.map +1 -1
- package/lib/scripts/amplitude-min.umd.js +1 -1
- package/lib/scripts/amplitude-min.umd.js.gz +0 -0
- package/lib/scripts/index.d.ts +2 -1
- package/lib/scripts/index.d.ts.map +1 -1
- package/lib/scripts/session-replay.d.ts +7 -0
- package/lib/scripts/session-replay.d.ts.map +1 -1
- package/lib/scripts/version.d.ts +1 -1
- package/package.json +5 -5
package/lib/cjs/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export { sessionReplayPlugin as plugin, sessionReplayPlugin } from './session-replay';
|
|
1
|
+
export { sessionReplayPlugin as plugin, sessionReplayPlugin, SessionReplayPlugin } from './session-replay';
|
|
2
|
+
export { AmplitudeSessionReplay, SessionReplayOptions } from '@amplitude/session-replay-browser';
|
|
2
3
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/cjs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,IAAI,MAAM,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,IAAI,MAAM,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC3G,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC"}
|
package/lib/cjs/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sessionReplayPlugin = exports.plugin = void 0;
|
|
3
|
+
exports.SessionReplayPlugin = exports.sessionReplayPlugin = exports.plugin = void 0;
|
|
4
4
|
var session_replay_1 = require("./session-replay");
|
|
5
5
|
Object.defineProperty(exports, "plugin", { enumerable: true, get: function () { return session_replay_1.sessionReplayPlugin; } });
|
|
6
6
|
Object.defineProperty(exports, "sessionReplayPlugin", { enumerable: true, get: function () { return session_replay_1.sessionReplayPlugin; } });
|
|
7
|
+
Object.defineProperty(exports, "SessionReplayPlugin", { enumerable: true, get: function () { return session_replay_1.SessionReplayPlugin; } });
|
|
7
8
|
//# sourceMappingURL=index.js.map
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,mDAA2G;AAAlG,wGAAA,mBAAmB,OAAU;AAAE,qHAAA,mBAAmB,OAAA;AAAE,qHAAA,mBAAmB,OAAA","sourcesContent":["export { sessionReplayPlugin as plugin, sessionReplayPlugin, SessionReplayPlugin } from './session-replay';\nexport { AmplitudeSessionReplay, SessionReplayOptions } from '@amplitude/session-replay-browser';\n"]}
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import { BrowserClient, BrowserConfig, EnrichmentPlugin, Event } from '@amplitude/analytics-core';
|
|
2
|
+
import * as sessionReplay from '@amplitude/session-replay-browser';
|
|
2
3
|
import { SessionReplayOptions } from './typings/session-replay';
|
|
4
|
+
import { AmplitudeSessionReplay } from '@amplitude/session-replay-browser';
|
|
3
5
|
export declare class SessionReplayPlugin implements EnrichmentPlugin<BrowserClient, BrowserConfig> {
|
|
6
|
+
static pluginName: string;
|
|
4
7
|
name: string;
|
|
5
8
|
type: "enrichment";
|
|
6
9
|
config: BrowserConfig;
|
|
7
10
|
options: SessionReplayOptions;
|
|
11
|
+
srInitOptions: sessionReplay.SessionReplayOptions;
|
|
12
|
+
sr: AmplitudeSessionReplay;
|
|
8
13
|
constructor(options?: SessionReplayOptions);
|
|
9
14
|
setup(config: BrowserConfig, _client: BrowserClient): Promise<void>;
|
|
15
|
+
onSessionIdChanged(sessionId: number): Promise<void>;
|
|
16
|
+
onOptOutChanged(optOut: boolean): Promise<void>;
|
|
10
17
|
execute(event: Event): Promise<Event>;
|
|
11
18
|
teardown(): Promise<void>;
|
|
12
19
|
getSessionReplayProperties(): {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-replay.d.ts","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"session-replay.d.ts","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAClG,OAAO,KAAK,aAAa,MAAM,mCAAmC,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAEhE,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAE3E,qBAAa,mBAAoB,YAAW,gBAAgB,CAAC,aAAa,EAAE,aAAa,CAAC;IACxF,MAAM,CAAC,UAAU,SAA8C;IAC/D,IAAI,SAAkC;IACtC,IAAI,eAAyB;IAI7B,MAAM,EAAE,aAAa,CAAC;IACtB,OAAO,EAAE,oBAAoB,CAAC;IAC9B,aAAa,EAAE,aAAa,CAAC,oBAAoB,CAAC;IAClD,EAAE,EAAE,sBAAsB,CAOxB;gBAEU,OAAO,CAAC,EAAE,oBAAoB;IAKpC,KAAK,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,aAAa;IA0DnD,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOpD,eAAe,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAe/C,OAAO,CAAC,KAAK,EAAE,KAAK;IA6CpB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAc/B,0BAA0B;;;CAG3B;AAED,eAAO,MAAM,mBAAmB,EAAE,CAAC,OAAO,CAAC,EAAE,oBAAoB,KAAK,gBAIrE,CAAC"}
|
|
@@ -6,9 +6,18 @@ var sessionReplay = tslib_1.__importStar(require("@amplitude/session-replay-brow
|
|
|
6
6
|
var version_1 = require("./version");
|
|
7
7
|
var SessionReplayPlugin = /** @class */ (function () {
|
|
8
8
|
function SessionReplayPlugin(options) {
|
|
9
|
-
this.name =
|
|
9
|
+
this.name = SessionReplayPlugin.pluginName;
|
|
10
10
|
this.type = 'enrichment';
|
|
11
|
+
this.sr = {
|
|
12
|
+
flush: sessionReplay.flush,
|
|
13
|
+
getSessionId: sessionReplay.getSessionId,
|
|
14
|
+
getSessionReplayProperties: sessionReplay.getSessionReplayProperties,
|
|
15
|
+
init: sessionReplay.init,
|
|
16
|
+
setSessionId: sessionReplay.setSessionId,
|
|
17
|
+
shutdown: sessionReplay.shutdown,
|
|
18
|
+
};
|
|
11
19
|
this.options = tslib_1.__assign({ forceSessionTracking: false }, options);
|
|
20
|
+
this.srInitOptions = this.options;
|
|
12
21
|
}
|
|
13
22
|
SessionReplayPlugin.prototype.setup = function (config, _client) {
|
|
14
23
|
var _a, _b, _c, _d, _e;
|
|
@@ -36,31 +45,32 @@ var SessionReplayPlugin = /** @class */ (function () {
|
|
|
36
45
|
config.defaultTracking = tslib_1.__assign(tslib_1.__assign({}, config.defaultTracking), { sessions: true });
|
|
37
46
|
}
|
|
38
47
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
48
|
+
this.srInitOptions = {
|
|
49
|
+
instanceName: this.config.instanceName,
|
|
50
|
+
deviceId: (_a = this.options.deviceId) !== null && _a !== void 0 ? _a : this.config.deviceId,
|
|
51
|
+
optOut: this.config.optOut,
|
|
52
|
+
sessionId: this.options.customSessionId ? undefined : this.config.sessionId,
|
|
53
|
+
loggerProvider: this.config.loggerProvider,
|
|
54
|
+
logLevel: this.config.logLevel,
|
|
55
|
+
flushMaxRetries: this.config.flushMaxRetries,
|
|
56
|
+
serverZone: this.config.serverZone,
|
|
57
|
+
configServerUrl: this.options.configServerUrl,
|
|
58
|
+
trackServerUrl: this.options.trackServerUrl,
|
|
59
|
+
sampleRate: this.options.sampleRate,
|
|
60
|
+
privacyConfig: {
|
|
61
|
+
blockSelector: (_b = this.options.privacyConfig) === null || _b === void 0 ? void 0 : _b.blockSelector,
|
|
62
|
+
maskSelector: (_c = this.options.privacyConfig) === null || _c === void 0 ? void 0 : _c.maskSelector,
|
|
63
|
+
unmaskSelector: (_d = this.options.privacyConfig) === null || _d === void 0 ? void 0 : _d.unmaskSelector,
|
|
64
|
+
defaultMaskLevel: (_e = this.options.privacyConfig) === null || _e === void 0 ? void 0 : _e.defaultMaskLevel,
|
|
65
|
+
},
|
|
66
|
+
debugMode: this.options.debugMode,
|
|
67
|
+
shouldInlineStylesheet: this.options.shouldInlineStylesheet,
|
|
68
|
+
version: { type: 'plugin', version: version_1.VERSION },
|
|
69
|
+
performanceConfig: this.options.performanceConfig,
|
|
70
|
+
storeType: this.options.storeType,
|
|
71
|
+
experimental: this.options.experimental,
|
|
72
|
+
};
|
|
73
|
+
return [4 /*yield*/, this.sr.init(config.apiKey, this.srInitOptions).promise];
|
|
64
74
|
case 1:
|
|
65
75
|
_f.sent();
|
|
66
76
|
return [3 /*break*/, 3];
|
|
@@ -74,6 +84,38 @@ var SessionReplayPlugin = /** @class */ (function () {
|
|
|
74
84
|
});
|
|
75
85
|
});
|
|
76
86
|
};
|
|
87
|
+
SessionReplayPlugin.prototype.onSessionIdChanged = function (sessionId) {
|
|
88
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
89
|
+
return tslib_1.__generator(this, function (_a) {
|
|
90
|
+
switch (_a.label) {
|
|
91
|
+
case 0:
|
|
92
|
+
this.config.loggerProvider.debug("Analytics session id is changed to ".concat(sessionId, ", SR session id is ").concat(String(this.sr.getSessionId()), "."));
|
|
93
|
+
return [4 /*yield*/, this.sr.setSessionId(sessionId).promise];
|
|
94
|
+
case 1:
|
|
95
|
+
_a.sent();
|
|
96
|
+
return [2 /*return*/];
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
SessionReplayPlugin.prototype.onOptOutChanged = function (optOut) {
|
|
102
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
103
|
+
return tslib_1.__generator(this, function (_a) {
|
|
104
|
+
switch (_a.label) {
|
|
105
|
+
case 0:
|
|
106
|
+
this.config.loggerProvider.debug("optOut is changed to ".concat(String(optOut), ", calling ").concat(optOut ? 'sessionReplay.shutdown()' : 'sessionReplay.init()', "."));
|
|
107
|
+
if (!optOut) return [3 /*break*/, 1];
|
|
108
|
+
this.sr.shutdown();
|
|
109
|
+
return [3 /*break*/, 3];
|
|
110
|
+
case 1: return [4 /*yield*/, this.sr.init(this.config.apiKey, this.srInitOptions).promise];
|
|
111
|
+
case 2:
|
|
112
|
+
_a.sent();
|
|
113
|
+
_a.label = 3;
|
|
114
|
+
case 3: return [2 /*return*/];
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
};
|
|
77
119
|
SessionReplayPlugin.prototype.execute = function (event) {
|
|
78
120
|
var _a;
|
|
79
121
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
@@ -85,20 +127,20 @@ var SessionReplayPlugin = /** @class */ (function () {
|
|
|
85
127
|
if (!this.options.customSessionId) return [3 /*break*/, 4];
|
|
86
128
|
sessionId = this.options.customSessionId(event);
|
|
87
129
|
if (!sessionId) return [3 /*break*/, 3];
|
|
88
|
-
if (!(sessionId !==
|
|
89
|
-
return [4 /*yield*/,
|
|
130
|
+
if (!(sessionId !== this.sr.getSessionId())) return [3 /*break*/, 2];
|
|
131
|
+
return [4 /*yield*/, this.sr.setSessionId(sessionId).promise];
|
|
90
132
|
case 1:
|
|
91
133
|
_b.sent();
|
|
92
134
|
_b.label = 2;
|
|
93
135
|
case 2:
|
|
94
|
-
sessionRecordingProperties =
|
|
136
|
+
sessionRecordingProperties = this.sr.getSessionReplayProperties();
|
|
95
137
|
event.event_properties = tslib_1.__assign(tslib_1.__assign({}, event.event_properties), sessionRecordingProperties);
|
|
96
138
|
_b.label = 3;
|
|
97
139
|
case 3: return [3 /*break*/, 7];
|
|
98
140
|
case 4:
|
|
99
141
|
sessionId = this.config.sessionId;
|
|
100
|
-
if (!(sessionId && sessionId !==
|
|
101
|
-
return [4 /*yield*/,
|
|
142
|
+
if (!(sessionId && sessionId !== this.sr.getSessionId())) return [3 /*break*/, 6];
|
|
143
|
+
return [4 /*yield*/, this.sr.setSessionId(sessionId).promise];
|
|
102
144
|
case 5:
|
|
103
145
|
_b.sent();
|
|
104
146
|
_b.label = 6;
|
|
@@ -106,7 +148,7 @@ var SessionReplayPlugin = /** @class */ (function () {
|
|
|
106
148
|
// Treating config.sessionId as source of truth, if the event's session id doesn't match, the
|
|
107
149
|
// event is not of the current session (offline/late events). In that case, don't tag the events
|
|
108
150
|
if (sessionId && sessionId === event.session_id) {
|
|
109
|
-
sessionRecordingProperties =
|
|
151
|
+
sessionRecordingProperties = this.sr.getSessionReplayProperties();
|
|
110
152
|
event.event_properties = tslib_1.__assign(tslib_1.__assign({}, event.event_properties), sessionRecordingProperties);
|
|
111
153
|
}
|
|
112
154
|
_b.label = 7;
|
|
@@ -126,7 +168,7 @@ var SessionReplayPlugin = /** @class */ (function () {
|
|
|
126
168
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
127
169
|
return tslib_1.__generator(this, function (_b) {
|
|
128
170
|
try {
|
|
129
|
-
|
|
171
|
+
this.sr.shutdown();
|
|
130
172
|
// the following are initialized in setup() which will always be called first
|
|
131
173
|
// here we reset them to null to prevent memory leaks
|
|
132
174
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
@@ -142,8 +184,9 @@ var SessionReplayPlugin = /** @class */ (function () {
|
|
|
142
184
|
});
|
|
143
185
|
};
|
|
144
186
|
SessionReplayPlugin.prototype.getSessionReplayProperties = function () {
|
|
145
|
-
return
|
|
187
|
+
return this.sr.getSessionReplayProperties();
|
|
146
188
|
};
|
|
189
|
+
SessionReplayPlugin.pluginName = '@amplitude/plugin-session-replay-browser';
|
|
147
190
|
return SessionReplayPlugin;
|
|
148
191
|
}());
|
|
149
192
|
exports.SessionReplayPlugin = SessionReplayPlugin;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-replay.js","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":";;;;AACA,uFAAmE;AAEnE,qCAAoC;AAEpC;IASE,6BAAY,OAA8B;QAR1C,SAAI,GAAG,0CAA0C,CAAC;QAClD,SAAI,GAAG,YAAqB,CAAC;QAQ3B,IAAI,CAAC,OAAO,sBAAK,oBAAoB,EAAE,KAAK,IAAK,OAAO,CAAE,CAAC;IAC7D,CAAC;IAEK,mCAAK,GAAX,UAAY,MAAqB,EAAE,OAAsB;;;;;;;;wBAErD,0BAA0B;wBAC1B,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,cAAc,CAAC,GAAG,CAAC,+DAAwD,iBAAO,MAAG,CAAC,CAAC;wBAE/F,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;wBAErB,IAAI,IAAI,CAAC,OAAO,CAAC,oBAAoB,EAAE;4BACrC,IAAI,OAAO,MAAM,CAAC,eAAe,KAAK,SAAS,EAAE;gCAC/C,IAAI,MAAM,CAAC,eAAe,KAAK,KAAK,EAAE;oCACpC,MAAM,CAAC,eAAe,GAAG;wCACvB,SAAS,EAAE,KAAK;wCAChB,gBAAgB,EAAE,KAAK;wCACvB,aAAa,EAAE,KAAK;wCACpB,QAAQ,EAAE,IAAI;qCACf,CAAC;iCACH;6BACF;iCAAM;gCACL,MAAM,CAAC,eAAe,yCACjB,MAAM,CAAC,eAAe,KACzB,QAAQ,EAAE,IAAI,GACf,CAAC;6BACH;yBACF;wBAED,qBAAM,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE;gCACtC,YAAY,EAAE,IAAI,CAAC,MAAM,CAAC,YAAY;gCACtC,QAAQ,EAAE,MAAA,IAAI,CAAC,OAAO,CAAC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;wBAC1B,MAAA,IAAI,CAAC,MAAM,0CAAE,cAAc,CAAC,KAAK,CAAC,wDAAkD,OAAe,CAAC,OAAO,CAAE,CAAC,CAAC;wBAC/G,sBAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,EAAC;;;;;KAEjC;IAEK,sCAAQ,GAAd;;;;gBACE,IAAI;oBACF,aAAa,CAAC,QAAQ,EAAE,CAAC;oBACzB,6EAA6E;oBAC7E,qDAAqD;oBACrD,6DAA6D;oBAC7D,aAAa;oBACb,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;iBACpB;gBAAC,OAAO,KAAK,EAAE;oBACd,0BAA0B;oBAC1B,MAAA,IAAI,CAAC,MAAM,0CAAE,cAAc,CAAC,KAAK,CAAC,iDAA2C,KAAe,CAAC,OAAO,CAAE,CAAC,CAAC;iBACzG;;;;KACF;IAED,wDAA0B,GAA1B;QACE,OAAO,aAAa,CAAC,0BAA0B,EAAE,CAAC;IACpD,CAAC;IACH,0BAAC;AAAD,CAAC,AAnID,IAmIC;AAnIY,kDAAmB;AAqIzB,IAAM,mBAAmB,GAAyD,UACvF,OAA8B;IAE9B,OAAO,IAAI,mBAAmB,CAAC,OAAO,CAAC,CAAC;AAC1C,CAAC,CAAC;AAJW,QAAA,mBAAmB,uBAI9B","sourcesContent":["import { BrowserClient, BrowserConfig, EnrichmentPlugin, Event } from '@amplitude/analytics-core';\nimport * as sessionReplay from '@amplitude/session-replay-browser';\nimport { SessionReplayOptions } from './typings/session-replay';\nimport { VERSION } from './version';\n\nexport class SessionReplayPlugin implements EnrichmentPlugin<BrowserClient, BrowserConfig> {\n name = '@amplitude/plugin-session-replay-browser';\n type = 'enrichment' as const;\n // this.config is defined in setup() which will always be called first\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n config: BrowserConfig;\n options: SessionReplayOptions;\n\n constructor(options?: SessionReplayOptions) {\n this.options = { forceSessionTracking: false, ...options };\n }\n\n async setup(config: BrowserConfig, _client: BrowserClient) {\n try {\n /* istanbul ignore next */\n config?.loggerProvider.log(`Installing @amplitude/plugin-session-replay, version ${VERSION}.`);\n\n this.config = config;\n\n if (this.options.forceSessionTracking) {\n if (typeof config.defaultTracking === 'boolean') {\n if (config.defaultTracking === false) {\n config.defaultTracking = {\n pageViews: false,\n formInteractions: false,\n fileDownloads: false,\n sessions: true,\n };\n }\n } else {\n config.defaultTracking = {\n ...config.defaultTracking,\n sessions: true,\n };\n }\n }\n\n await sessionReplay.init(config.apiKey, {\n instanceName: this.config.instanceName,\n deviceId: this.options.deviceId ?? this.config.deviceId,\n optOut: this.config.optOut,\n sessionId: this.options.customSessionId ? undefined : this.config.sessionId,\n loggerProvider: this.config.loggerProvider,\n logLevel: this.config.logLevel,\n flushMaxRetries: this.config.flushMaxRetries,\n serverZone: this.config.serverZone,\n configServerUrl: this.options.configServerUrl,\n trackServerUrl: this.options.trackServerUrl,\n sampleRate: this.options.sampleRate,\n privacyConfig: {\n blockSelector: this.options.privacyConfig?.blockSelector,\n maskSelector: this.options.privacyConfig?.maskSelector,\n unmaskSelector: this.options.privacyConfig?.unmaskSelector,\n defaultMaskLevel: this.options.privacyConfig?.defaultMaskLevel,\n },\n debugMode: this.options.debugMode,\n shouldInlineStylesheet: this.options.shouldInlineStylesheet,\n version: { type: 'plugin', version: VERSION },\n performanceConfig: this.options.performanceConfig,\n storeType: this.options.storeType,\n experimental: this.options.experimental,\n }).promise;\n } catch (error) {\n /* istanbul ignore next */\n config?.loggerProvider.error(`Session Replay: Failed to initialize due to ${(error as Error).message}`);\n }\n }\n\n async execute(event: Event) {\n try {\n if (this.options.customSessionId) {\n const sessionId = this.options.customSessionId(event);\n if (sessionId) {\n // On event, synchronize the session id to the custom session id from the event. This may\n // suffer from offline/delayed events messing up the state stored\n if (sessionId !== sessionReplay.getSessionId()) {\n await sessionReplay.setSessionId(sessionId).promise;\n }\n\n const sessionRecordingProperties = sessionReplay.getSessionReplayProperties();\n event.event_properties = {\n ...event.event_properties,\n ...sessionRecordingProperties,\n };\n }\n } else {\n // On event, synchronize the session id to the what's on the browserConfig (source of truth)\n // Choosing not to read from event object here, concerned about offline/delayed events messing up the state stored\n // in SR.\n const sessionId: string | number | undefined = this.config.sessionId;\n if (sessionId && sessionId !== sessionReplay.getSessionId()) {\n await sessionReplay.setSessionId(sessionId).promise;\n }\n\n // Treating config.sessionId as source of truth, if the event's session id doesn't match, the\n // event is not of the current session (offline/late events). In that case, don't tag the events\n if (sessionId && sessionId === event.session_id) {\n const sessionRecordingProperties = sessionReplay.getSessionReplayProperties();\n event.event_properties = {\n ...event.event_properties,\n ...sessionRecordingProperties,\n };\n }\n }\n\n return Promise.resolve(event);\n } catch (error) {\n /* istanbul ignore next */\n this.config?.loggerProvider.error(`Session Replay: Failed to enrich event due to ${(error as Error).message}`);\n return Promise.resolve(event);\n }\n }\n\n async teardown(): Promise<void> {\n try {\n sessionReplay.shutdown();\n // the following are initialized in setup() which will always be called first\n // here we reset them to null to prevent memory leaks\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n this.config = null;\n } catch (error) {\n /* istanbul ignore next */\n this.config?.loggerProvider.error(`Session Replay: teardown failed due to ${(error as Error).message}`);\n }\n }\n\n getSessionReplayProperties() {\n return sessionReplay.getSessionReplayProperties();\n }\n}\n\nexport const sessionReplayPlugin: (options?: SessionReplayOptions) => EnrichmentPlugin = (\n options?: SessionReplayOptions,\n) => {\n return new SessionReplayPlugin(options);\n};\n"]}
|
|
1
|
+
{"version":3,"file":"session-replay.js","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":";;;;AACA,uFAAmE;AAEnE,qCAAoC;AAGpC;IAmBE,6BAAY,OAA8B;QAjB1C,SAAI,GAAG,mBAAmB,CAAC,UAAU,CAAC;QACtC,SAAI,GAAG,YAAqB,CAAC;QAO7B,OAAE,GAA2B;YAC3B,KAAK,EAAE,aAAa,CAAC,KAAK;YAC1B,YAAY,EAAE,aAAa,CAAC,YAAY;YACxC,0B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KAAK,CAAC,iDAA2C,KAAe,CAAC,OAAO,CAAE,CAAC,CAAC;iBACzG;;;;KACF;IAED,wDAA0B,GAA1B;QACE,OAAO,IAAI,CAAC,EAAE,CAAC,0BAA0B,EAAE,CAAC;IAC9C,CAAC;IApKM,8BAAU,GAAG,0CAA0C,CAAC;IAqKjE,0BAAC;CAAA,AAtKD,IAsKC;AAtKY,kDAAmB;AAwKzB,IAAM,mBAAmB,GAAyD,UACvF,OAA8B;IAE9B,OAAO,IAAI,mBAAmB,CAAC,OAAO,CAAC,CAAC;AAC1C,CAAC,CAAC;AAJW,QAAA,mBAAmB,uBAI9B","sourcesContent":["import { BrowserClient, BrowserConfig, EnrichmentPlugin, Event } from '@amplitude/analytics-core';\nimport * as sessionReplay from '@amplitude/session-replay-browser';\nimport { SessionReplayOptions } from './typings/session-replay';\nimport { VERSION } from './version';\nimport { AmplitudeSessionReplay } from '@amplitude/session-replay-browser';\n\nexport class SessionReplayPlugin implements EnrichmentPlugin<BrowserClient, BrowserConfig> {\n static pluginName = '@amplitude/plugin-session-replay-browser';\n name = SessionReplayPlugin.pluginName;\n type = 'enrichment' as const;\n // this.config is defined in setup() which will always be called first\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n config: BrowserConfig;\n options: SessionReplayOptions;\n srInitOptions: sessionReplay.SessionReplayOptions;\n sr: AmplitudeSessionReplay = {\n flush: sessionReplay.flush,\n getSessionId: sessionReplay.getSessionId,\n getSessionReplayProperties: sessionReplay.getSessionReplayProperties,\n init: sessionReplay.init,\n setSessionId: sessionReplay.setSessionId,\n shutdown: sessionReplay.shutdown,\n };\n\n constructor(options?: SessionReplayOptions) {\n this.options = { forceSessionTracking: false, ...options };\n this.srInitOptions = this.options;\n }\n\n async setup(config: BrowserConfig, _client: BrowserClient) {\n try {\n /* istanbul ignore next */\n config?.loggerProvider.log(`Installing @amplitude/plugin-session-replay, version ${VERSION}.`);\n\n this.config = config;\n\n if (this.options.forceSessionTracking) {\n if (typeof config.defaultTracking === 'boolean') {\n if (config.defaultTracking === false) {\n config.defaultTracking = {\n pageViews: false,\n formInteractions: false,\n fileDownloads: false,\n sessions: true,\n };\n }\n } else {\n config.defaultTracking = {\n ...config.defaultTracking,\n sessions: true,\n };\n }\n }\n\n this.srInitOptions = {\n instanceName: this.config.instanceName,\n deviceId: this.options.deviceId ?? this.config.deviceId,\n optOut: this.config.optOut,\n sessionId: this.options.customSessionId ? undefined : this.config.sessionId,\n loggerProvider: this.config.loggerProvider,\n logLevel: this.config.logLevel,\n flushMaxRetries: this.config.flushMaxRetries,\n serverZone: this.config.serverZone,\n configServerUrl: this.options.configServerUrl,\n trackServerUrl: this.options.trackServerUrl,\n sampleRate: this.options.sampleRate,\n privacyConfig: {\n blockSelector: this.options.privacyConfig?.blockSelector,\n maskSelector: this.options.privacyConfig?.maskSelector,\n unmaskSelector: this.options.privacyConfig?.unmaskSelector,\n defaultMaskLevel: this.options.privacyConfig?.defaultMaskLevel,\n },\n debugMode: this.options.debugMode,\n shouldInlineStylesheet: this.options.shouldInlineStylesheet,\n version: { type: 'plugin', version: VERSION },\n performanceConfig: this.options.performanceConfig,\n storeType: this.options.storeType,\n experimental: this.options.experimental,\n };\n\n await this.sr.init(config.apiKey, this.srInitOptions).promise;\n } catch (error) {\n /* istanbul ignore next */\n config?.loggerProvider.error(`Session Replay: Failed to initialize due to ${(error as Error).message}`);\n }\n }\n\n async onSessionIdChanged(sessionId: number): Promise<void> {\n this.config.loggerProvider.debug(\n `Analytics session id is changed to ${sessionId}, SR session id is ${String(this.sr.getSessionId())}.`,\n );\n await this.sr.setSessionId(sessionId).promise;\n }\n\n async onOptOutChanged(optOut: boolean): Promise<void> {\n this.config.loggerProvider.debug(\n `optOut is changed to ${String(optOut)}, calling ${\n optOut ? 'sessionReplay.shutdown()' : 'sessionReplay.init()'\n }.`,\n );\n // TODO: compare optOut with this.sr.getOptOut().\n // Need to add getOptOut() to the interface AmplitudeSessionReplay first.\n if (optOut) {\n this.sr.shutdown();\n } else {\n await this.sr.init(this.config.apiKey, this.srInitOptions).promise;\n }\n }\n\n async execute(event: Event) {\n try {\n if (this.options.customSessionId) {\n const sessionId = this.options.customSessionId(event);\n if (sessionId) {\n // On event, synchronize the session id to the custom session id from the event. This may\n // suffer from offline/delayed events messing up the state stored\n if (sessionId !== this.sr.getSessionId()) {\n await this.sr.setSessionId(sessionId).promise;\n }\n\n const sessionRecordingProperties = this.sr.getSessionReplayProperties();\n event.event_properties = {\n ...event.event_properties,\n ...sessionRecordingProperties,\n };\n }\n } else {\n // On event, synchronize the session id to the what's on the browserConfig (source of truth)\n // Choosing not to read from event object here, concerned about offline/delayed events messing up the state stored\n // in SR.\n const sessionId: string | number | undefined = this.config.sessionId;\n if (sessionId && sessionId !== this.sr.getSessionId()) {\n await this.sr.setSessionId(sessionId).promise;\n }\n\n // Treating config.sessionId as source of truth, if the event's session id doesn't match, the\n // event is not of the current session (offline/late events). In that case, don't tag the events\n if (sessionId && sessionId === event.session_id) {\n const sessionRecordingProperties = this.sr.getSessionReplayProperties();\n event.event_properties = {\n ...event.event_properties,\n ...sessionRecordingProperties,\n };\n }\n }\n\n return Promise.resolve(event);\n } catch (error) {\n /* istanbul ignore next */\n this.config?.loggerProvider.error(`Session Replay: Failed to enrich event due to ${(error as Error).message}`);\n return Promise.resolve(event);\n }\n }\n\n async teardown(): Promise<void> {\n try {\n this.sr.shutdown();\n // the following are initialized in setup() which will always be called first\n // here we reset them to null to prevent memory leaks\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n this.config = null;\n } catch (error) {\n /* istanbul ignore next */\n this.config?.loggerProvider.error(`Session Replay: teardown failed due to ${(error as Error).message}`);\n }\n }\n\n getSessionReplayProperties() {\n return this.sr.getSessionReplayProperties();\n }\n}\n\nexport const sessionReplayPlugin: (options?: SessionReplayOptions) => EnrichmentPlugin = (\n options?: SessionReplayOptions,\n) => {\n return new SessionReplayPlugin(options);\n};\n"]}
|
package/lib/cjs/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "1.
|
|
1
|
+
export declare const VERSION = "1.16.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/lib/cjs/version.js
CHANGED
package/lib/cjs/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AAAA,oDAAoD;AACvC,QAAA,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["// Autogenerated by `yarn version-file`. DO NOT EDIT\nexport const VERSION = '1.
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AAAA,oDAAoD;AACvC,QAAA,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["// Autogenerated by `yarn version-file`. DO NOT EDIT\nexport const VERSION = '1.16.0';\n"]}
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export { sessionReplayPlugin as plugin, sessionReplayPlugin } from './session-replay';
|
|
1
|
+
export { sessionReplayPlugin as plugin, sessionReplayPlugin, SessionReplayPlugin } from './session-replay';
|
|
2
|
+
export { AmplitudeSessionReplay, SessionReplayOptions } from '@amplitude/session-replay-browser';
|
|
2
3
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,IAAI,MAAM,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,IAAI,MAAM,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC3G,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC"}
|
package/lib/esm/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { sessionReplayPlugin as plugin, sessionReplayPlugin } from './session-replay';
|
|
1
|
+
export { sessionReplayPlugin as plugin, sessionReplayPlugin, SessionReplayPlugin } from './session-replay';
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,IAAI,MAAM,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC","sourcesContent":["export { sessionReplayPlugin as plugin, sessionReplayPlugin } from './session-replay';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,IAAI,MAAM,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC","sourcesContent":["export { sessionReplayPlugin as plugin, sessionReplayPlugin, SessionReplayPlugin } from './session-replay';\nexport { AmplitudeSessionReplay, SessionReplayOptions } from '@amplitude/session-replay-browser';\n"]}
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import { BrowserClient, BrowserConfig, EnrichmentPlugin, Event } from '@amplitude/analytics-core';
|
|
2
|
+
import * as sessionReplay from '@amplitude/session-replay-browser';
|
|
2
3
|
import { SessionReplayOptions } from './typings/session-replay';
|
|
4
|
+
import { AmplitudeSessionReplay } from '@amplitude/session-replay-browser';
|
|
3
5
|
export declare class SessionReplayPlugin implements EnrichmentPlugin<BrowserClient, BrowserConfig> {
|
|
6
|
+
static pluginName: string;
|
|
4
7
|
name: string;
|
|
5
8
|
type: "enrichment";
|
|
6
9
|
config: BrowserConfig;
|
|
7
10
|
options: SessionReplayOptions;
|
|
11
|
+
srInitOptions: sessionReplay.SessionReplayOptions;
|
|
12
|
+
sr: AmplitudeSessionReplay;
|
|
8
13
|
constructor(options?: SessionReplayOptions);
|
|
9
14
|
setup(config: BrowserConfig, _client: BrowserClient): Promise<void>;
|
|
15
|
+
onSessionIdChanged(sessionId: number): Promise<void>;
|
|
16
|
+
onOptOutChanged(optOut: boolean): Promise<void>;
|
|
10
17
|
execute(event: Event): Promise<Event>;
|
|
11
18
|
teardown(): Promise<void>;
|
|
12
19
|
getSessionReplayProperties(): {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-replay.d.ts","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"session-replay.d.ts","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAClG,OAAO,KAAK,aAAa,MAAM,mCAAmC,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAEhE,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAE3E,qBAAa,mBAAoB,YAAW,gBAAgB,CAAC,aAAa,EAAE,aAAa,CAAC;IACxF,MAAM,CAAC,UAAU,SAA8C;IAC/D,IAAI,SAAkC;IACtC,IAAI,eAAyB;IAI7B,MAAM,EAAE,aAAa,CAAC;IACtB,OAAO,EAAE,oBAAoB,CAAC;IAC9B,aAAa,EAAE,aAAa,CAAC,oBAAoB,CAAC;IAClD,EAAE,EAAE,sBAAsB,CAOxB;gBAEU,OAAO,CAAC,EAAE,oBAAoB;IAKpC,KAAK,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,aAAa;IA0DnD,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOpD,eAAe,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAe/C,OAAO,CAAC,KAAK,EAAE,KAAK;IA6CpB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAc/B,0BAA0B;;;CAG3B;AAED,eAAO,MAAM,mBAAmB,EAAE,CAAC,OAAO,CAAC,EAAE,oBAAoB,KAAK,gBAIrE,CAAC"}
|
|
@@ -3,9 +3,18 @@ import * as sessionReplay from '@amplitude/session-replay-browser';
|
|
|
3
3
|
import { VERSION } from './version';
|
|
4
4
|
var SessionReplayPlugin = /** @class */ (function () {
|
|
5
5
|
function SessionReplayPlugin(options) {
|
|
6
|
-
this.name =
|
|
6
|
+
this.name = SessionReplayPlugin.pluginName;
|
|
7
7
|
this.type = 'enrichment';
|
|
8
|
+
this.sr = {
|
|
9
|
+
flush: sessionReplay.flush,
|
|
10
|
+
getSessionId: sessionReplay.getSessionId,
|
|
11
|
+
getSessionReplayProperties: sessionReplay.getSessionReplayProperties,
|
|
12
|
+
init: sessionReplay.init,
|
|
13
|
+
setSessionId: sessionReplay.setSessionId,
|
|
14
|
+
shutdown: sessionReplay.shutdown,
|
|
15
|
+
};
|
|
8
16
|
this.options = __assign({ forceSessionTracking: false }, options);
|
|
17
|
+
this.srInitOptions = this.options;
|
|
9
18
|
}
|
|
10
19
|
SessionReplayPlugin.prototype.setup = function (config, _client) {
|
|
11
20
|
var _a, _b, _c, _d, _e;
|
|
@@ -33,31 +42,32 @@ var SessionReplayPlugin = /** @class */ (function () {
|
|
|
33
42
|
config.defaultTracking = __assign(__assign({}, config.defaultTracking), { sessions: true });
|
|
34
43
|
}
|
|
35
44
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
45
|
+
this.srInitOptions = {
|
|
46
|
+
instanceName: this.config.instanceName,
|
|
47
|
+
deviceId: (_a = this.options.deviceId) !== null && _a !== void 0 ? _a : this.config.deviceId,
|
|
48
|
+
optOut: this.config.optOut,
|
|
49
|
+
sessionId: this.options.customSessionId ? undefined : this.config.sessionId,
|
|
50
|
+
loggerProvider: this.config.loggerProvider,
|
|
51
|
+
logLevel: this.config.logLevel,
|
|
52
|
+
flushMaxRetries: this.config.flushMaxRetries,
|
|
53
|
+
serverZone: this.config.serverZone,
|
|
54
|
+
configServerUrl: this.options.configServerUrl,
|
|
55
|
+
trackServerUrl: this.options.trackServerUrl,
|
|
56
|
+
sampleRate: this.options.sampleRate,
|
|
57
|
+
privacyConfig: {
|
|
58
|
+
blockSelector: (_b = this.options.privacyConfig) === null || _b === void 0 ? void 0 : _b.blockSelector,
|
|
59
|
+
maskSelector: (_c = this.options.privacyConfig) === null || _c === void 0 ? void 0 : _c.maskSelector,
|
|
60
|
+
unmaskSelector: (_d = this.options.privacyConfig) === null || _d === void 0 ? void 0 : _d.unmaskSelector,
|
|
61
|
+
defaultMaskLevel: (_e = this.options.privacyConfig) === null || _e === void 0 ? void 0 : _e.defaultMaskLevel,
|
|
62
|
+
},
|
|
63
|
+
debugMode: this.options.debugMode,
|
|
64
|
+
shouldInlineStylesheet: this.options.shouldInlineStylesheet,
|
|
65
|
+
version: { type: 'plugin', version: VERSION },
|
|
66
|
+
performanceConfig: this.options.performanceConfig,
|
|
67
|
+
storeType: this.options.storeType,
|
|
68
|
+
experimental: this.options.experimental,
|
|
69
|
+
};
|
|
70
|
+
return [4 /*yield*/, this.sr.init(config.apiKey, this.srInitOptions).promise];
|
|
61
71
|
case 1:
|
|
62
72
|
_f.sent();
|
|
63
73
|
return [3 /*break*/, 3];
|
|
@@ -71,6 +81,38 @@ var SessionReplayPlugin = /** @class */ (function () {
|
|
|
71
81
|
});
|
|
72
82
|
});
|
|
73
83
|
};
|
|
84
|
+
SessionReplayPlugin.prototype.onSessionIdChanged = function (sessionId) {
|
|
85
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
86
|
+
return __generator(this, function (_a) {
|
|
87
|
+
switch (_a.label) {
|
|
88
|
+
case 0:
|
|
89
|
+
this.config.loggerProvider.debug("Analytics session id is changed to ".concat(sessionId, ", SR session id is ").concat(String(this.sr.getSessionId()), "."));
|
|
90
|
+
return [4 /*yield*/, this.sr.setSessionId(sessionId).promise];
|
|
91
|
+
case 1:
|
|
92
|
+
_a.sent();
|
|
93
|
+
return [2 /*return*/];
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
SessionReplayPlugin.prototype.onOptOutChanged = function (optOut) {
|
|
99
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
100
|
+
return __generator(this, function (_a) {
|
|
101
|
+
switch (_a.label) {
|
|
102
|
+
case 0:
|
|
103
|
+
this.config.loggerProvider.debug("optOut is changed to ".concat(String(optOut), ", calling ").concat(optOut ? 'sessionReplay.shutdown()' : 'sessionReplay.init()', "."));
|
|
104
|
+
if (!optOut) return [3 /*break*/, 1];
|
|
105
|
+
this.sr.shutdown();
|
|
106
|
+
return [3 /*break*/, 3];
|
|
107
|
+
case 1: return [4 /*yield*/, this.sr.init(this.config.apiKey, this.srInitOptions).promise];
|
|
108
|
+
case 2:
|
|
109
|
+
_a.sent();
|
|
110
|
+
_a.label = 3;
|
|
111
|
+
case 3: return [2 /*return*/];
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
};
|
|
74
116
|
SessionReplayPlugin.prototype.execute = function (event) {
|
|
75
117
|
var _a;
|
|
76
118
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -82,20 +124,20 @@ var SessionReplayPlugin = /** @class */ (function () {
|
|
|
82
124
|
if (!this.options.customSessionId) return [3 /*break*/, 4];
|
|
83
125
|
sessionId = this.options.customSessionId(event);
|
|
84
126
|
if (!sessionId) return [3 /*break*/, 3];
|
|
85
|
-
if (!(sessionId !==
|
|
86
|
-
return [4 /*yield*/,
|
|
127
|
+
if (!(sessionId !== this.sr.getSessionId())) return [3 /*break*/, 2];
|
|
128
|
+
return [4 /*yield*/, this.sr.setSessionId(sessionId).promise];
|
|
87
129
|
case 1:
|
|
88
130
|
_b.sent();
|
|
89
131
|
_b.label = 2;
|
|
90
132
|
case 2:
|
|
91
|
-
sessionRecordingProperties =
|
|
133
|
+
sessionRecordingProperties = this.sr.getSessionReplayProperties();
|
|
92
134
|
event.event_properties = __assign(__assign({}, event.event_properties), sessionRecordingProperties);
|
|
93
135
|
_b.label = 3;
|
|
94
136
|
case 3: return [3 /*break*/, 7];
|
|
95
137
|
case 4:
|
|
96
138
|
sessionId = this.config.sessionId;
|
|
97
|
-
if (!(sessionId && sessionId !==
|
|
98
|
-
return [4 /*yield*/,
|
|
139
|
+
if (!(sessionId && sessionId !== this.sr.getSessionId())) return [3 /*break*/, 6];
|
|
140
|
+
return [4 /*yield*/, this.sr.setSessionId(sessionId).promise];
|
|
99
141
|
case 5:
|
|
100
142
|
_b.sent();
|
|
101
143
|
_b.label = 6;
|
|
@@ -103,7 +145,7 @@ var SessionReplayPlugin = /** @class */ (function () {
|
|
|
103
145
|
// Treating config.sessionId as source of truth, if the event's session id doesn't match, the
|
|
104
146
|
// event is not of the current session (offline/late events). In that case, don't tag the events
|
|
105
147
|
if (sessionId && sessionId === event.session_id) {
|
|
106
|
-
sessionRecordingProperties =
|
|
148
|
+
sessionRecordingProperties = this.sr.getSessionReplayProperties();
|
|
107
149
|
event.event_properties = __assign(__assign({}, event.event_properties), sessionRecordingProperties);
|
|
108
150
|
}
|
|
109
151
|
_b.label = 7;
|
|
@@ -123,7 +165,7 @@ var SessionReplayPlugin = /** @class */ (function () {
|
|
|
123
165
|
return __awaiter(this, void 0, void 0, function () {
|
|
124
166
|
return __generator(this, function (_b) {
|
|
125
167
|
try {
|
|
126
|
-
|
|
168
|
+
this.sr.shutdown();
|
|
127
169
|
// the following are initialized in setup() which will always be called first
|
|
128
170
|
// here we reset them to null to prevent memory leaks
|
|
129
171
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
@@ -139,8 +181,9 @@ var SessionReplayPlugin = /** @class */ (function () {
|
|
|
139
181
|
});
|
|
140
182
|
};
|
|
141
183
|
SessionReplayPlugin.prototype.getSessionReplayProperties = function () {
|
|
142
|
-
return
|
|
184
|
+
return this.sr.getSessionReplayProperties();
|
|
143
185
|
};
|
|
186
|
+
SessionReplayPlugin.pluginName = '@amplitude/plugin-session-replay-browser';
|
|
144
187
|
return SessionReplayPlugin;
|
|
145
188
|
}());
|
|
146
189
|
export { SessionReplayPlugin };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-replay.js","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,aAAa,MAAM,mCAAmC,CAAC;AAEnE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC;IASE,6BAAY,OAA8B;QAR1C,SAAI,GAAG,0CAA0C,CAAC;QAClD,SAAI,GAAG,YAAqB,CAAC;QAQ3B,IAAI,CAAC,OAAO,cAAK,oBAAoB,EAAE,KAAK,IAAK,OAAO,CAAE,CAAC;IAC7D,CAAC;IAEK,mCAAK,GAAX,UAAY,MAAqB,EAAE,OAAsB;;;;;;;;wBAErD,0BAA0B;wBAC1B,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,cAAc,CAAC,GAAG,CAAC,+DAAwD,OAAO,MAAG,CAAC,CAAC;wBAE/F,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;wBAErB,IAAI,IAAI,CAAC,OAAO,CAAC,oBAAoB,EAAE;4BACrC,IAA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mBAAmB,CAAC,OAAO,CAAC,CAAC;AAC1C,CAAC,CAAC","sourcesContent":["import { BrowserClient, BrowserConfig, EnrichmentPlugin, Event } from '@amplitude/analytics-core';\nimport * as sessionReplay from '@amplitude/session-replay-browser';\nimport { SessionReplayOptions } from './typings/session-replay';\nimport { VERSION } from './version';\n\nexport class SessionReplayPlugin implements EnrichmentPlugin<BrowserClient, BrowserConfig> {\n name = '@amplitude/plugin-session-replay-browser';\n type = 'enrichment' as const;\n // this.config is defined in setup() which will always be called first\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n config: BrowserConfig;\n options: SessionReplayOptions;\n\n constructor(options?: SessionReplayOptions) {\n this.options = { forceSessionTracking: false, ...options };\n }\n\n async setup(config: BrowserConfig, _client: BrowserClient) {\n try {\n /* istanbul ignore next */\n config?.loggerProvider.log(`Installing @amplitude/plugin-session-replay, version ${VERSION}.`);\n\n this.config = config;\n\n if (this.options.forceSessionTracking) {\n if (typeof config.defaultTracking === 'boolean') {\n if (config.defaultTracking === false) {\n config.defaultTracking = {\n pageViews: false,\n formInteractions: false,\n fileDownloads: false,\n sessions: true,\n };\n }\n } else {\n config.defaultTracking = {\n ...config.defaultTracking,\n sessions: true,\n };\n }\n }\n\n await sessionReplay.init(config.apiKey, {\n instanceName: this.config.instanceName,\n deviceId: this.options.deviceId ?? this.config.deviceId,\n optOut: this.config.optOut,\n sessionId: this.options.customSessionId ? undefined : this.config.sessionId,\n loggerProvider: this.config.loggerProvider,\n logLevel: this.config.logLevel,\n flushMaxRetries: this.config.flushMaxRetries,\n serverZone: this.config.serverZone,\n configServerUrl: this.options.configServerUrl,\n trackServerUrl: this.options.trackServerUrl,\n sampleRate: this.options.sampleRate,\n privacyConfig: {\n blockSelector: this.options.privacyConfig?.blockSelector,\n maskSelector: this.options.privacyConfig?.maskSelector,\n unmaskSelector: this.options.privacyConfig?.unmaskSelector,\n defaultMaskLevel: this.options.privacyConfig?.defaultMaskLevel,\n },\n debugMode: this.options.debugMode,\n shouldInlineStylesheet: this.options.shouldInlineStylesheet,\n version: { type: 'plugin', version: VERSION },\n performanceConfig: this.options.performanceConfig,\n storeType: this.options.storeType,\n experimental: this.options.experimental,\n }).promise;\n } catch (error) {\n /* istanbul ignore next */\n config?.loggerProvider.error(`Session Replay: Failed to initialize due to ${(error as Error).message}`);\n }\n }\n\n async execute(event: Event) {\n try {\n if (this.options.customSessionId) {\n const sessionId = this.options.customSessionId(event);\n if (sessionId) {\n // On event, synchronize the session id to the custom session id from the event. This may\n // suffer from offline/delayed events messing up the state stored\n if (sessionId !== sessionReplay.getSessionId()) {\n await sessionReplay.setSessionId(sessionId).promise;\n }\n\n const sessionRecordingProperties = sessionReplay.getSessionReplayProperties();\n event.event_properties = {\n ...event.event_properties,\n ...sessionRecordingProperties,\n };\n }\n } else {\n // On event, synchronize the session id to the what's on the browserConfig (source of truth)\n // Choosing not to read from event object here, concerned about offline/delayed events messing up the state stored\n // in SR.\n const sessionId: string | number | undefined = this.config.sessionId;\n if (sessionId && sessionId !== sessionReplay.getSessionId()) {\n await sessionReplay.setSessionId(sessionId).promise;\n }\n\n // Treating config.sessionId as source of truth, if the event's session id doesn't match, the\n // event is not of the current session (offline/late events). In that case, don't tag the events\n if (sessionId && sessionId === event.session_id) {\n const sessionRecordingProperties = sessionReplay.getSessionReplayProperties();\n event.event_properties = {\n ...event.event_properties,\n ...sessionRecordingProperties,\n };\n }\n }\n\n return Promise.resolve(event);\n } catch (error) {\n /* istanbul ignore next */\n this.config?.loggerProvider.error(`Session Replay: Failed to enrich event due to ${(error as Error).message}`);\n return Promise.resolve(event);\n }\n }\n\n async teardown(): Promise<void> {\n try {\n sessionReplay.shutdown();\n // the following are initialized in setup() which will always be called first\n // here we reset them to null to prevent memory leaks\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n this.config = null;\n } catch (error) {\n /* istanbul ignore next */\n this.config?.loggerProvider.error(`Session Replay: teardown failed due to ${(error as Error).message}`);\n }\n }\n\n getSessionReplayProperties() {\n return sessionReplay.getSessionReplayProperties();\n }\n}\n\nexport const sessionReplayPlugin: (options?: SessionReplayOptions) => EnrichmentPlugin = (\n options?: SessionReplayOptions,\n) => {\n return new SessionReplayPlugin(options);\n};\n"]}
|
|
1
|
+
{"version":3,"file":"session-replay.js","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,aAAa,MAAM,mCAAmC,CAAC;AAEnE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC;IAmBE,6BAAY,OAA8B;QAjB1C,SAAI,GAAG,mBAAmB,CAAC,UAAU,CAAC;QACtC,SAAI,GAAG,YAAqB,CAAC;QAO7B,OAAE,GAA2B;YAC3B,KAAK,EAAE,aAAa,CAAC,KAAK;YAC1B,YAAY,EAAE,aAAa,CAAC,YAAY;YACxC,0BAA0B,EAAE,aAAa,CAAC,0BAA0B;YACpE,IAAI,EAAE,aAAa,CAAC,IAAI;YACxB,YAAY,EAAE,aAAa,CAAC,YAAY;YACxC,QAAQ,EAAE,aAAa,CAAC,QAAQ;SACjC,CAAC;QAGA,IAAI,CAAC,OAAO,cAAK,oBAAoB,EAAE,KAAK,IAAK,OAAO,CAAE,CAAC;QAC3D,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC;IACpC,CAAC;IAEK,mCAAK,GAAX,UAAY,MAAqB,EAAE,OAAsB;;;;;;;;wBAErD,0BAA0B;wBAC1B,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,cAAc,CAAC,GAAG,CAAC,+DAAwD,OAAO,MAAG,CAAC,CAAC;wBAE/F,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;wBAErB,IAAI,IAAI,CAAC,OAAO,CAAC,oBAAoB,EAAE;4BACrC,IAAI,OAAO,MAAM,CAAC,eAAe,KAAK,SAAS,EAAE;gCAC/C,IAAI,MAAM,CAAC,eAAe,KAAK,KAAK,EAAE;oCACpC,MAAM,CAA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AGH,sBAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,EAAC;;;wBAE9B,0BAA0B;wBAC1B,MAAA,IAAI,CAAC,MAAM,0CAAE,cAAc,CAAC,KAAK,CAAC,wDAAkD,OAAe,CAAC,OAAO,CAAE,CAAC,CAAC;wBAC/G,sBAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,EAAC;;;;;KAEjC;IAEK,sCAAQ,GAAd;;;;gBACE,IAAI;oBACF,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC;oBACnB,6EAA6E;oBAC7E,qDAAqD;oBACrD,6DAA6D;oBAC7D,aAAa;oBACb,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;iBACpB;gBAAC,OAAO,KAAK,EAAE;oBACd,0BAA0B;oBAC1B,MAAA,IAAI,CAAC,MAAM,0CAAE,cAAc,CAAC,KAAK,CAAC,iDAA2C,KAAe,CAAC,OAAO,CAAE,CAAC,CAAC;iBACzG;;;;KACF;IAED,wDAA0B,GAA1B;QACE,OAAO,IAAI,CAAC,EAAE,CAAC,0BAA0B,EAAE,CAAC;IAC9C,CAAC;IApKM,8BAAU,GAAG,0CAA0C,CAAC;IAqKjE,0BAAC;CAAA,AAtKD,IAsKC;SAtKY,mBAAmB;AAwKhC,MAAM,CAAC,IAAM,mBAAmB,GAAyD,UACvF,OAA8B;IAE9B,OAAO,IAAI,mBAAmB,CAAC,OAAO,CAAC,CAAC;AAC1C,CAAC,CAAC","sourcesContent":["import { BrowserClient, BrowserConfig, EnrichmentPlugin, Event } from '@amplitude/analytics-core';\nimport * as sessionReplay from '@amplitude/session-replay-browser';\nimport { SessionReplayOptions } from './typings/session-replay';\nimport { VERSION } from './version';\nimport { AmplitudeSessionReplay } from '@amplitude/session-replay-browser';\n\nexport class SessionReplayPlugin implements EnrichmentPlugin<BrowserClient, BrowserConfig> {\n static pluginName = '@amplitude/plugin-session-replay-browser';\n name = SessionReplayPlugin.pluginName;\n type = 'enrichment' as const;\n // this.config is defined in setup() which will always be called first\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n config: BrowserConfig;\n options: SessionReplayOptions;\n srInitOptions: sessionReplay.SessionReplayOptions;\n sr: AmplitudeSessionReplay = {\n flush: sessionReplay.flush,\n getSessionId: sessionReplay.getSessionId,\n getSessionReplayProperties: sessionReplay.getSessionReplayProperties,\n init: sessionReplay.init,\n setSessionId: sessionReplay.setSessionId,\n shutdown: sessionReplay.shutdown,\n };\n\n constructor(options?: SessionReplayOptions) {\n this.options = { forceSessionTracking: false, ...options };\n this.srInitOptions = this.options;\n }\n\n async setup(config: BrowserConfig, _client: BrowserClient) {\n try {\n /* istanbul ignore next */\n config?.loggerProvider.log(`Installing @amplitude/plugin-session-replay, version ${VERSION}.`);\n\n this.config = config;\n\n if (this.options.forceSessionTracking) {\n if (typeof config.defaultTracking === 'boolean') {\n if (config.defaultTracking === false) {\n config.defaultTracking = {\n pageViews: false,\n formInteractions: false,\n fileDownloads: false,\n sessions: true,\n };\n }\n } else {\n config.defaultTracking = {\n ...config.defaultTracking,\n sessions: true,\n };\n }\n }\n\n this.srInitOptions = {\n instanceName: this.config.instanceName,\n deviceId: this.options.deviceId ?? this.config.deviceId,\n optOut: this.config.optOut,\n sessionId: this.options.customSessionId ? undefined : this.config.sessionId,\n loggerProvider: this.config.loggerProvider,\n logLevel: this.config.logLevel,\n flushMaxRetries: this.config.flushMaxRetries,\n serverZone: this.config.serverZone,\n configServerUrl: this.options.configServerUrl,\n trackServerUrl: this.options.trackServerUrl,\n sampleRate: this.options.sampleRate,\n privacyConfig: {\n blockSelector: this.options.privacyConfig?.blockSelector,\n maskSelector: this.options.privacyConfig?.maskSelector,\n unmaskSelector: this.options.privacyConfig?.unmaskSelector,\n defaultMaskLevel: this.options.privacyConfig?.defaultMaskLevel,\n },\n debugMode: this.options.debugMode,\n shouldInlineStylesheet: this.options.shouldInlineStylesheet,\n version: { type: 'plugin', version: VERSION },\n performanceConfig: this.options.performanceConfig,\n storeType: this.options.storeType,\n experimental: this.options.experimental,\n };\n\n await this.sr.init(config.apiKey, this.srInitOptions).promise;\n } catch (error) {\n /* istanbul ignore next */\n config?.loggerProvider.error(`Session Replay: Failed to initialize due to ${(error as Error).message}`);\n }\n }\n\n async onSessionIdChanged(sessionId: number): Promise<void> {\n this.config.loggerProvider.debug(\n `Analytics session id is changed to ${sessionId}, SR session id is ${String(this.sr.getSessionId())}.`,\n );\n await this.sr.setSessionId(sessionId).promise;\n }\n\n async onOptOutChanged(optOut: boolean): Promise<void> {\n this.config.loggerProvider.debug(\n `optOut is changed to ${String(optOut)}, calling ${\n optOut ? 'sessionReplay.shutdown()' : 'sessionReplay.init()'\n }.`,\n );\n // TODO: compare optOut with this.sr.getOptOut().\n // Need to add getOptOut() to the interface AmplitudeSessionReplay first.\n if (optOut) {\n this.sr.shutdown();\n } else {\n await this.sr.init(this.config.apiKey, this.srInitOptions).promise;\n }\n }\n\n async execute(event: Event) {\n try {\n if (this.options.customSessionId) {\n const sessionId = this.options.customSessionId(event);\n if (sessionId) {\n // On event, synchronize the session id to the custom session id from the event. This may\n // suffer from offline/delayed events messing up the state stored\n if (sessionId !== this.sr.getSessionId()) {\n await this.sr.setSessionId(sessionId).promise;\n }\n\n const sessionRecordingProperties = this.sr.getSessionReplayProperties();\n event.event_properties = {\n ...event.event_properties,\n ...sessionRecordingProperties,\n };\n }\n } else {\n // On event, synchronize the session id to the what's on the browserConfig (source of truth)\n // Choosing not to read from event object here, concerned about offline/delayed events messing up the state stored\n // in SR.\n const sessionId: string | number | undefined = this.config.sessionId;\n if (sessionId && sessionId !== this.sr.getSessionId()) {\n await this.sr.setSessionId(sessionId).promise;\n }\n\n // Treating config.sessionId as source of truth, if the event's session id doesn't match, the\n // event is not of the current session (offline/late events). In that case, don't tag the events\n if (sessionId && sessionId === event.session_id) {\n const sessionRecordingProperties = this.sr.getSessionReplayProperties();\n event.event_properties = {\n ...event.event_properties,\n ...sessionRecordingProperties,\n };\n }\n }\n\n return Promise.resolve(event);\n } catch (error) {\n /* istanbul ignore next */\n this.config?.loggerProvider.error(`Session Replay: Failed to enrich event due to ${(error as Error).message}`);\n return Promise.resolve(event);\n }\n }\n\n async teardown(): Promise<void> {\n try {\n this.sr.shutdown();\n // the following are initialized in setup() which will always be called first\n // here we reset them to null to prevent memory leaks\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n this.config = null;\n } catch (error) {\n /* istanbul ignore next */\n this.config?.loggerProvider.error(`Session Replay: teardown failed due to ${(error as Error).message}`);\n }\n }\n\n getSessionReplayProperties() {\n return this.sr.getSessionReplayProperties();\n }\n}\n\nexport const sessionReplayPlugin: (options?: SessionReplayOptions) => EnrichmentPlugin = (\n options?: SessionReplayOptions,\n) => {\n return new SessionReplayPlugin(options);\n};\n"]}
|
package/lib/esm/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "1.
|
|
1
|
+
export declare const VERSION = "1.16.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/lib/esm/version.js
CHANGED
package/lib/esm/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,oDAAoD;AACpD,MAAM,CAAC,IAAM,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["// Autogenerated by `yarn version-file`. DO NOT EDIT\nexport const VERSION = '1.
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,oDAAoD;AACpD,MAAM,CAAC,IAAM,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["// Autogenerated by `yarn version-file`. DO NOT EDIT\nexport const VERSION = '1.16.0';\n"]}
|