@amplitude/session-replay-browser 1.3.0 → 1.3.2

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 (40) hide show
  1. package/lib/cjs/config/joined-config.d.ts +7 -5
  2. package/lib/cjs/config/joined-config.d.ts.map +1 -1
  3. package/lib/cjs/config/joined-config.js +53 -20
  4. package/lib/cjs/config/joined-config.js.map +1 -1
  5. package/lib/cjs/config/types.d.ts +13 -8
  6. package/lib/cjs/config/types.d.ts.map +1 -1
  7. package/lib/cjs/config/types.js.map +1 -1
  8. package/lib/cjs/session-replay.d.ts.map +1 -1
  9. package/lib/cjs/session-replay.js +19 -15
  10. package/lib/cjs/session-replay.js.map +1 -1
  11. package/lib/esm/config/joined-config.d.ts +7 -5
  12. package/lib/esm/config/joined-config.d.ts.map +1 -1
  13. package/lib/esm/config/joined-config.js +50 -19
  14. package/lib/esm/config/joined-config.js.map +1 -1
  15. package/lib/esm/config/types.d.ts +13 -8
  16. package/lib/esm/config/types.d.ts.map +1 -1
  17. package/lib/esm/config/types.js.map +1 -1
  18. package/lib/esm/session-replay.d.ts.map +1 -1
  19. package/lib/esm/session-replay.js +20 -16
  20. package/lib/esm/session-replay.js.map +1 -1
  21. package/lib/scripts/amplitude-min.js +1 -1
  22. package/lib/scripts/amplitude-min.js.gz +0 -0
  23. package/lib/scripts/amplitude-min.umd.js +1 -1
  24. package/lib/scripts/amplitude-min.umd.js.gz +0 -0
  25. package/lib/scripts/config/joined-config.d.ts +7 -5
  26. package/lib/scripts/config/joined-config.d.ts.map +1 -1
  27. package/lib/scripts/config/types.d.ts +13 -8
  28. package/lib/scripts/config/types.d.ts.map +1 -1
  29. package/lib/scripts/session-replay.d.ts.map +1 -1
  30. package/package.json +3 -2
  31. package/lib/cjs/config/remote-config.d.ts +0 -28
  32. package/lib/cjs/config/remote-config.d.ts.map +0 -1
  33. package/lib/cjs/config/remote-config.js +0 -145
  34. package/lib/cjs/config/remote-config.js.map +0 -1
  35. package/lib/esm/config/remote-config.d.ts +0 -28
  36. package/lib/esm/config/remote-config.d.ts.map +0 -1
  37. package/lib/esm/config/remote-config.js +0 -143
  38. package/lib/esm/config/remote-config.js.map +0 -1
  39. package/lib/scripts/config/remote-config.d.ts +0 -28
  40. package/lib/scripts/config/remote-config.d.ts.map +0 -1
@@ -1,10 +1,12 @@
1
- import { SessionReplaySessionIDBStore as AmplitudeSessionReplaySessionIDBStore, SessionReplayOptions } from '../typings/session-replay';
2
- import { SessionReplayLocalConfig as ISessionReplayLocalConfig, SessionReplayRemoteConfigFetch as ISessionReplayRemoteConfigFetch, SessionReplayJoinedConfig } from './types';
1
+ import { RemoteConfigFetch } from '@amplitude/analytics-remote-config';
2
+ import { SessionReplayOptions } from '../typings/session-replay';
3
+ import { SessionReplayLocalConfig as ISessionReplayLocalConfig, SessionReplayJoinedConfig, SessionReplayRemoteConfig } from './types';
3
4
  export declare class SessionReplayJoinedConfigGenerator {
4
5
  localConfig: ISessionReplayLocalConfig;
5
- remoteConfigFetch: ISessionReplayRemoteConfigFetch;
6
- sessionIDBStore: AmplitudeSessionReplaySessionIDBStore;
7
- constructor(apiKey: string, options: SessionReplayOptions, sessionIDBStore: AmplitudeSessionReplaySessionIDBStore);
6
+ remoteConfigFetch: RemoteConfigFetch<SessionReplayRemoteConfig> | undefined;
7
+ constructor(apiKey: string, options: SessionReplayOptions);
8
+ initialize(): Promise<void>;
8
9
  generateJoinedConfig(sessionId?: number): Promise<SessionReplayJoinedConfig>;
9
10
  }
11
+ export declare const createSessionReplayJoinedConfigGenerator: (apiKey: string, options: SessionReplayOptions) => Promise<SessionReplayJoinedConfigGenerator>;
10
12
  //# sourceMappingURL=joined-config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"joined-config.d.ts","sourceRoot":"","sources":["../../../src/config/joined-config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,IAAI,qCAAqC,EACrE,oBAAoB,EACrB,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EACL,wBAAwB,IAAI,yBAAyB,EACrD,8BAA8B,IAAI,+BAA+B,EACjE,yBAAyB,EAC1B,MAAM,SAAS,CAAC;AAEjB,qBAAa,kCAAkC;IAC7C,WAAW,EAAE,yBAAyB,CAAC;IACvC,iBAAiB,EAAE,+BAA+B,CAAC;IACnD,eAAe,EAAE,qCAAqC,CAAC;gBAE3C,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,qCAAqC;IAS3G,oBAAoB,CAAC,SAAS,CAAC,EAAE,MAAM;CA8B9C"}
1
+ {"version":3,"file":"joined-config.d.ts","sourceRoot":"","sources":["../../../src/config/joined-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AAChG,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,OAAO,EACL,wBAAwB,IAAI,yBAAyB,EACrD,yBAAyB,EACzB,yBAAyB,EAC1B,MAAM,SAAS,CAAC;AAEjB,qBAAa,kCAAkC;IAC7C,WAAW,EAAE,yBAAyB,CAAC;IACvC,iBAAiB,EAAE,iBAAiB,CAAC,yBAAyB,CAAC,GAAG,SAAS,CAAC;gBAEhE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,oBAAoB;IAInD,UAAU;IAOV,oBAAoB,CAAC,SAAS,CAAC,EAAE,MAAM;CAqC9C;AAED,eAAO,MAAM,wCAAwC,WAAkB,MAAM,WAAW,oBAAoB,gDAI3G,CAAC"}
@@ -1,32 +1,51 @@
1
+ var _this = this;
1
2
  Object.defineProperty(exports, "__esModule", { value: true });
2
- exports.SessionReplayJoinedConfigGenerator = void 0;
3
+ exports.createSessionReplayJoinedConfigGenerator = exports.SessionReplayJoinedConfigGenerator = void 0;
3
4
  var tslib_1 = require("tslib");
5
+ var analytics_remote_config_1 = require("@amplitude/analytics-remote-config");
4
6
  var local_config_1 = require("./local-config");
5
- var remote_config_1 = require("./remote-config");
6
7
  var SessionReplayJoinedConfigGenerator = /** @class */ (function () {
7
- function SessionReplayJoinedConfigGenerator(apiKey, options, sessionIDBStore) {
8
- this.sessionIDBStore = sessionIDBStore;
8
+ function SessionReplayJoinedConfigGenerator(apiKey, options) {
9
9
  this.localConfig = new local_config_1.SessionReplayLocalConfig(apiKey, options);
10
- this.remoteConfigFetch = new remote_config_1.SessionReplayRemoteConfigFetch({
11
- localConfig: this.localConfig,
12
- sessionIDBStore: this.sessionIDBStore,
13
- });
14
10
  }
11
+ SessionReplayJoinedConfigGenerator.prototype.initialize = function () {
12
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
13
+ var _a;
14
+ return tslib_1.__generator(this, function (_b) {
15
+ switch (_b.label) {
16
+ case 0:
17
+ _a = this;
18
+ return [4 /*yield*/, (0, analytics_remote_config_1.createRemoteConfigFetch)({
19
+ localConfig: this.localConfig,
20
+ configKeys: ['sessionReplay'],
21
+ })];
22
+ case 1:
23
+ _a.remoteConfigFetch = _b.sent();
24
+ return [2 /*return*/];
25
+ }
26
+ });
27
+ });
28
+ };
15
29
  SessionReplayJoinedConfigGenerator.prototype.generateJoinedConfig = function (sessionId) {
16
30
  return tslib_1.__awaiter(this, void 0, void 0, function () {
17
- var config, samplingConfig, err_1, knownError;
18
- return tslib_1.__generator(this, function (_a) {
19
- switch (_a.label) {
31
+ var config, samplingConfig, _a, err_1, knownError;
32
+ return tslib_1.__generator(this, function (_b) {
33
+ switch (_b.label) {
20
34
  case 0:
21
35
  config = tslib_1.__assign({}, this.localConfig);
22
36
  // Special case here as optOut is implemented via getter/setter
23
37
  config.optOut = this.localConfig.optOut;
24
- _a.label = 1;
38
+ _b.label = 1;
25
39
  case 1:
26
- _a.trys.push([1, 3, , 4]);
27
- return [4 /*yield*/, this.remoteConfigFetch.getSamplingConfig(sessionId)];
40
+ _b.trys.push([1, 4, , 5]);
41
+ _a = this.remoteConfigFetch;
42
+ if (!_a) return [3 /*break*/, 3];
43
+ return [4 /*yield*/, this.remoteConfigFetch.getRemoteConfig('sessionReplay', 'sr_sampling_config', sessionId)];
28
44
  case 2:
29
- samplingConfig = _a.sent();
45
+ _a = (_b.sent());
46
+ _b.label = 3;
47
+ case 3:
48
+ samplingConfig = _a;
30
49
  if (samplingConfig && Object.keys(samplingConfig).length > 0) {
31
50
  if (Object.prototype.hasOwnProperty.call(samplingConfig, 'capture_enabled')) {
32
51
  config.captureEnabled = samplingConfig.capture_enabled;
@@ -44,14 +63,14 @@ var SessionReplayJoinedConfigGenerator = /** @class */ (function () {
44
63
  // allowing for immediate replay capture
45
64
  config.captureEnabled = true;
46
65
  }
47
- return [3 /*break*/, 4];
48
- case 3:
49
- err_1 = _a.sent();
66
+ return [3 /*break*/, 5];
67
+ case 4:
68
+ err_1 = _b.sent();
50
69
  knownError = err_1;
51
70
  this.localConfig.loggerProvider.warn(knownError.message);
52
71
  config.captureEnabled = true;
53
- return [3 /*break*/, 4];
54
- case 4: return [2 /*return*/, config];
72
+ return [3 /*break*/, 5];
73
+ case 5: return [2 /*return*/, config];
55
74
  }
56
75
  });
57
76
  });
@@ -59,4 +78,18 @@ var SessionReplayJoinedConfigGenerator = /** @class */ (function () {
59
78
  return SessionReplayJoinedConfigGenerator;
60
79
  }());
61
80
  exports.SessionReplayJoinedConfigGenerator = SessionReplayJoinedConfigGenerator;
81
+ var createSessionReplayJoinedConfigGenerator = function (apiKey, options) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
82
+ var joinedConfigGenerator;
83
+ return tslib_1.__generator(this, function (_a) {
84
+ switch (_a.label) {
85
+ case 0:
86
+ joinedConfigGenerator = new SessionReplayJoinedConfigGenerator(apiKey, options);
87
+ return [4 /*yield*/, joinedConfigGenerator.initialize()];
88
+ case 1:
89
+ _a.sent();
90
+ return [2 /*return*/, joinedConfigGenerator];
91
+ }
92
+ });
93
+ }); };
94
+ exports.createSessionReplayJoinedConfigGenerator = createSessionReplayJoinedConfigGenerator;
62
95
  //# sourceMappingURL=joined-config.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c,GAAG,IAAI,CAAC;yBAC9B;;;;wBAEK,UAAU,GAAG,KAAY,CAAC;wBAChC,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;wBACzD,MAAM,CAAC,cAAc,GAAG,IAAI,CAAC;;4BAG/B,sBAAO,MAAM,EAAC;;;;KACf;IACH,yCAAC;AAAD,CAAC,AA5CD,IA4CC;AA5CY,gFAAkC","sourcesContent":["import {\n SessionReplaySessionIDBStore as AmplitudeSessionReplaySessionIDBStore,\n SessionReplayOptions,\n} from '../typings/session-replay';\nimport { SessionReplayLocalConfig } from './local-config';\nimport { SessionReplayRemoteConfigFetch } from './remote-config';\nimport {\n SessionReplayLocalConfig as ISessionReplayLocalConfig,\n SessionReplayRemoteConfigFetch as ISessionReplayRemoteConfigFetch,\n SessionReplayJoinedConfig,\n} from './types';\n\nexport class SessionReplayJoinedConfigGenerator {\n localConfig: ISessionReplayLocalConfig;\n remoteConfigFetch: ISessionReplayRemoteConfigFetch;\n sessionIDBStore: AmplitudeSessionReplaySessionIDBStore;\n\n constructor(apiKey: string, options: SessionReplayOptions, sessionIDBStore: AmplitudeSessionReplaySessionIDBStore) {\n this.sessionIDBStore = sessionIDBStore;\n this.localConfig = new SessionReplayLocalConfig(apiKey, options);\n this.remoteConfigFetch = new SessionReplayRemoteConfigFetch({\n localConfig: this.localConfig,\n sessionIDBStore: this.sessionIDBStore,\n });\n }\n\n async generateJoinedConfig(sessionId?: number) {\n const config: SessionReplayJoinedConfig = { ...this.localConfig };\n // Special case here as optOut is implemented via getter/setter\n config.optOut = this.localConfig.optOut;\n try {\n const samplingConfig = await this.remoteConfigFetch.getSamplingConfig(sessionId);\n if (samplingConfig && Object.keys(samplingConfig).length > 0) {\n if (Object.prototype.hasOwnProperty.call(samplingConfig, 'capture_enabled')) {\n config.captureEnabled = samplingConfig.capture_enabled;\n } else {\n config.captureEnabled = false;\n }\n\n if (samplingConfig.sample_rate) {\n config.sampleRate = samplingConfig.sample_rate;\n }\n } else {\n // If config API response was valid (ie 200), but no config returned, assume that\n // customer has not yet set up config, and use sample rate from SDK options,\n // allowing for immediate replay capture\n config.captureEnabled = true;\n }\n } catch (err: unknown) {\n const knownError = err as Error;\n this.localConfig.loggerProvider.warn(knownError.message);\n config.captureEnabled = true;\n }\n\n return config;\n }\n}\n"]}
1
+ {"version":3,"file":"joined-config.js","sourceRoot":"","sources":["../../../src/config/joined-config.ts"],"names":[],"mappings":"AAAA,iBAoEA;;;;AApEA,8EAAgG;AAEhG,+CAA0D;AAO1D;IAIE,4CAAY,MAAc,EAAE,OAA6B;QACvD,IAAI,CAAC,WAAW,GAAG,IAAI,uCAAwB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnE,CAAC;IAEK,uDAAU,GAAhB;;;;;;wBACE,KAAA,IAAI,CAAA;wBAAqB,qBAAM,IAAA,iDAAuB,EAA4B;gCAChF,WAAW,EAAE,IAAI,CAAC,WAAW;gCAC7B,UAAU,EAAE,CAAC,eAAe,CAAC;6BAC9B,CAAC,EAAA;;wBAHF,GAAK,iBAAiB,GAAG,SAGvB,CAAC;;;;;KACJ;IAEK,iEAAoB,GAA1B,UAA2B,SAAkB;;;;;;wBACrC,MAAM,wBAAmC,IAAI,CAAC,WAAW,CAAE,CAAC;wBAClE,+DAA+D;wBAC/D,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;;;;wBAGpC,KAAA,IAAI,CAAC,iBAAiB,CAAA;iCAAtB,wBAAsB;wBACpB,qBAAM,IAAI,CAAC,iBAAiB,CAAC,eAAe,CAC5C,eAAe,EACf,oBAAoB,EACpB,SAAS,CACV,EAAA;;wBAJD,KAAC,CAAC,SAID,CAAqD,CAAA;;;wBANlD,cAAc,KAMoC;wBAExD,IAAI,cAAc,IAAI,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;4BAC5D,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,cAAc,EAAE,iBAAiB,CAAC,EAAE;gCAC3E,MAAM,CAAC,cAAc,GAAG,cAAc,CAAC,eAAe,CAAC;6BACxD;iCAAM;gCACL,MAAM,CAAC,cAAc,GAAG,KAAK,CAAC;6BAC/B;4BAED,IAAI,cAAc,CAAC,WAAW,EAAE;gCAC9B,MAAM,CAAC,UAAU,GAAG,cAAc,CAAC,WAAW,CAAC;6BAChD;yBACF;6BAAM;4BACL,iFAAiF;4BACjF,4EAA4E;4BAC5E,wCAAwC;4BACxC,MAAM,CAAC,cAAc,GAAG,IAAI,CAAC;yBAC9B;;;;wBAEK,UAAU,GAAG,KAAY,CAAC;wBAChC,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;wBACzD,MAAM,CAAC,cAAc,GAAG,IAAI,CAAC;;4BAG/B,sBAAO,MAAM,EAAC;;;;KACf;IACH,yCAAC;AAAD,CAAC,AApDD,IAoDC;AApDY,gFAAkC;AAsDxC,IAAM,wCAAwC,GAAG,UAAO,MAAc,EAAE,OAA6B;;;;;gBACpG,qBAAqB,GAAG,IAAI,kCAAkC,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBACtF,qBAAM,qBAAqB,CAAC,UAAU,EAAE,EAAA;;gBAAxC,SAAwC,CAAC;gBACzC,sBAAO,qBAAqB,EAAC;;;KAC9B,CAAC;AAJW,QAAA,wCAAwC,4CAInD","sourcesContent":["import { createRemoteConfigFetch, RemoteConfigFetch } from '@amplitude/analytics-remote-config';\nimport { SessionReplayOptions } from '../typings/session-replay';\nimport { SessionReplayLocalConfig } from './local-config';\nimport {\n SessionReplayLocalConfig as ISessionReplayLocalConfig,\n SessionReplayJoinedConfig,\n SessionReplayRemoteConfig,\n} from './types';\n\nexport class SessionReplayJoinedConfigGenerator {\n localConfig: ISessionReplayLocalConfig;\n remoteConfigFetch: RemoteConfigFetch<SessionReplayRemoteConfig> | undefined;\n\n constructor(apiKey: string, options: SessionReplayOptions) {\n this.localConfig = new SessionReplayLocalConfig(apiKey, options);\n }\n\n async initialize() {\n this.remoteConfigFetch = await createRemoteConfigFetch<SessionReplayRemoteConfig>({\n localConfig: this.localConfig,\n configKeys: ['sessionReplay'],\n });\n }\n\n async generateJoinedConfig(sessionId?: number) {\n const config: SessionReplayJoinedConfig = { ...this.localConfig };\n // Special case here as optOut is implemented via getter/setter\n config.optOut = this.localConfig.optOut;\n try {\n const samplingConfig =\n this.remoteConfigFetch &&\n ((await this.remoteConfigFetch.getRemoteConfig(\n 'sessionReplay',\n 'sr_sampling_config',\n sessionId,\n )) as SessionReplayRemoteConfig['sr_sampling_config']);\n\n if (samplingConfig && Object.keys(samplingConfig).length > 0) {\n if (Object.prototype.hasOwnProperty.call(samplingConfig, 'capture_enabled')) {\n config.captureEnabled = samplingConfig.capture_enabled;\n } else {\n config.captureEnabled = false;\n }\n\n if (samplingConfig.sample_rate) {\n config.sampleRate = samplingConfig.sample_rate;\n }\n } else {\n // If config API response was valid (ie 200), but no config returned, assume that\n // customer has not yet set up config, and use sample rate from SDK options,\n // allowing for immediate replay capture\n config.captureEnabled = true;\n }\n } catch (err: unknown) {\n const knownError = err as Error;\n this.localConfig.loggerProvider.warn(knownError.message);\n config.captureEnabled = true;\n }\n\n return config;\n }\n}\n\nexport const createSessionReplayJoinedConfigGenerator = async (apiKey: string, options: SessionReplayOptions) => {\n const joinedConfigGenerator = new SessionReplayJoinedConfigGenerator(apiKey, options);\n await joinedConfigGenerator.initialize();\n return joinedConfigGenerator;\n};\n"]}
@@ -1,11 +1,10 @@
1
1
  import { Config, LogLevel, Logger } from '@amplitude/analytics-types';
2
- export interface SamplingConfig {
3
- sample_rate: number;
4
- capture_enabled: boolean;
5
- }
6
- export interface SessionReplayRemoteConfig {
7
- sr_sampling_config: SamplingConfig;
8
- }
2
+ export type SessionReplayRemoteConfig = {
3
+ sr_sampling_config: {
4
+ sample_rate: number;
5
+ capture_enabled: boolean;
6
+ };
7
+ };
9
8
  export interface SessionReplayRemoteConfigAPIResponse {
10
9
  configs: {
11
10
  sessionReplay: SessionReplayRemoteConfig;
@@ -27,6 +26,12 @@ export interface SessionReplayJoinedConfig extends SessionReplayLocalConfig {
27
26
  captureEnabled?: boolean;
28
27
  }
29
28
  export interface SessionReplayRemoteConfigFetch {
30
- getSamplingConfig: (sessionId?: number) => Promise<SamplingConfig | void>;
29
+ getServerUrl: () => void;
30
+ getSamplingConfig: (sessionId?: number) => Promise<SessionReplayRemoteConfig['sr_sampling_config'] | void>;
31
+ fetchRemoteConfig: (sessionId?: number) => Promise<SessionReplayRemoteConfig | void>;
32
+ getRemoteConfig: (sessionId?: number) => Promise<SessionReplayRemoteConfig | void>;
33
+ }
34
+ export interface SessionReplayJoinedConfigGenerator {
35
+ generateJoinedConfig: (sessionId?: number) => Promise<SessionReplayJoinedConfig>;
31
36
  }
32
37
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/config/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAEtE,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,OAAO,CAAC;CAC1B;AACD,MAAM,WAAW,yBAAyB;IACxC,kBAAkB,EAAE,cAAc,CAAC;CACpC;AAED,MAAM,WAAW,oCAAoC;IACnD,OAAO,EAAE;QACP,aAAa,EAAE,yBAAyB,CAAC;KAC1C,CAAC;CACH;AACD,MAAM,WAAW,0BAA0B;IACzC,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CACnC;AAED,MAAM,WAAW,wBAAyB,SAAQ,MAAM;IACtD,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,QAAQ,CAAC;IACnB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CAAC;IACzB,iBAAiB,EAAE,CAAC,SAAS,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,yBAAyB,CAAC,oBAAoB,CAAC,GAAG,IAAI,CAAC,CAAC;IAC3G,iBAAiB,EAAE,CAAC,SAAS,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,yBAAyB,GAAG,IAAI,CAAC,CAAC;IACrF,eAAe,EAAE,CAAC,SAAS,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,yBAAyB,GAAG,IAAI,CAAC,CAAC;CACpF;AAED,MAAM,WAAW,kCAAkC;IACjD,oBAAoB,EAAE,CAAC,SAAS,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,yBAAyB,CAAC,CAAC;CAClF"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/config/types.ts"],"names":[],"mappings":"","sourcesContent":["import { Config, LogLevel, Logger } from '@amplitude/analytics-types';\n\nexport interface SamplingConfig {\n sample_rate: number;\n capture_enabled: boolean;\n}\nexport interface SessionReplayRemoteConfig {\n sr_sampling_config: SamplingConfig;\n}\n\nexport interface SessionReplayRemoteConfigAPIResponse {\n configs: {\n sessionReplay: SessionReplayRemoteConfig;\n };\n}\nexport interface SessionReplayPrivacyConfig {\n blockSelector?: string | string[];\n}\n\nexport interface SessionReplayLocalConfig extends Config {\n apiKey: string;\n loggerProvider: Logger;\n logLevel: LogLevel;\n flushMaxRetries: number;\n sampleRate: number;\n privacyConfig?: SessionReplayPrivacyConfig;\n debugMode?: boolean;\n}\n\nexport interface SessionReplayJoinedConfig extends SessionReplayLocalConfig {\n captureEnabled?: boolean;\n}\n\nexport interface SessionReplayRemoteConfigFetch {\n getSamplingConfig: (sessionId?: number) => Promise<SamplingConfig | void>;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/config/types.ts"],"names":[],"mappings":"","sourcesContent":["import { Config, LogLevel, Logger } from '@amplitude/analytics-types';\n\nexport type SessionReplayRemoteConfig = {\n sr_sampling_config: {\n sample_rate: number;\n capture_enabled: boolean;\n };\n};\n\nexport interface SessionReplayRemoteConfigAPIResponse {\n configs: {\n sessionReplay: SessionReplayRemoteConfig;\n };\n}\nexport interface SessionReplayPrivacyConfig {\n blockSelector?: string | string[];\n}\n\nexport interface SessionReplayLocalConfig extends Config {\n apiKey: string;\n loggerProvider: Logger;\n logLevel: LogLevel;\n flushMaxRetries: number;\n sampleRate: number;\n privacyConfig?: SessionReplayPrivacyConfig;\n debugMode?: boolean;\n}\n\nexport interface SessionReplayJoinedConfig extends SessionReplayLocalConfig {\n captureEnabled?: boolean;\n}\n\nexport interface SessionReplayRemoteConfigFetch {\n getServerUrl: () => void;\n getSamplingConfig: (sessionId?: number) => Promise<SessionReplayRemoteConfig['sr_sampling_config'] | void>;\n fetchRemoteConfig: (sessionId?: number) => Promise<SessionReplayRemoteConfig | void>;\n getRemoteConfig: (sessionId?: number) => Promise<SessionReplayRemoteConfig | void>;\n}\n\nexport interface SessionReplayJoinedConfigGenerator {\n generateJoinedConfig: (sessionId?: number) => Promise<SessionReplayJoinedConfig>;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"session-replay.d.ts","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,IAAI,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAQ,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,kCAAkC,EAAE,MAAM,wBAAwB,CAAC;AAC5E,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAW3D,OAAO,EACL,sBAAsB,EACtB,0BAA0B,IAAI,mCAAmC,EACjE,4BAA4B,IAAI,qCAAqC,EACrE,kBAAkB,IAAI,mBAAmB,EACzC,oBAAoB,EACrB,MAAM,0BAA0B,CAAC;AAElC,qBAAa,aAAc,YAAW,sBAAsB;IAC1D,IAAI,SAAuC;IAC3C,MAAM,EAA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** @class */ (function () {
38
38
  };
39
39
  SessionReplay.prototype._init = function (apiKey, options) {
40
40
  return tslib_1.__awaiter(this, void 0, void 0, function () {
41
- var _a, globalScope;
42
- return tslib_1.__generator(this, function (_b) {
43
- switch (_b.label) {
41
+ var _a, _b, globalScope;
42
+ return tslib_1.__generator(this, function (_c) {
43
+ switch (_c.label) {
44
44
  case 0:
45
45
  this.loggerProvider = options.loggerProvider || new analytics_core_1.Logger();
46
46
  this.sessionIDBStore = new session_idb_store_1.SessionReplaySessionIDBStore({
@@ -48,11 +48,14 @@ var SessionReplay = /** @class */ (function () {
48
48
  apiKey: apiKey,
49
49
  });
50
50
  this.identifiers = new identifiers_1.SessionIdentifiers({ sessionId: options.sessionId, deviceId: options.deviceId });
51
- this.joinedConfigGenerator = new joined_config_1.SessionReplayJoinedConfigGenerator(apiKey, options, this.sessionIDBStore);
52
51
  _a = this;
53
- return [4 /*yield*/, this.joinedConfigGenerator.generateJoinedConfig(this.identifiers.sessionId)];
52
+ return [4 /*yield*/, (0, joined_config_1.createSessionReplayJoinedConfigGenerator)(apiKey, options)];
54
53
  case 1:
55
- _a.config = _b.sent();
54
+ _a.joinedConfigGenerator = _c.sent();
55
+ _b = this;
56
+ return [4 /*yield*/, this.joinedConfigGenerator.generateJoinedConfig(this.identifiers.sessionId)];
57
+ case 2:
58
+ _b.config = _c.sent();
56
59
  this.eventsManager = new events_manager_1.SessionReplayEventsManager({
57
60
  config: this.config,
58
61
  sessionIDBStore: this.sessionIDBStore,
@@ -65,12 +68,12 @@ var SessionReplay = /** @class */ (function () {
65
68
  globalScope.addEventListener('blur', this.blurListener);
66
69
  globalScope.addEventListener('focus', this.focusListener);
67
70
  }
68
- if (!(globalScope && globalScope.document && globalScope.document.hasFocus())) return [3 /*break*/, 3];
71
+ if (!(globalScope && globalScope.document && globalScope.document.hasFocus())) return [3 /*break*/, 4];
69
72
  return [4 /*yield*/, this.initialize(true)];
70
- case 2:
71
- _b.sent();
72
- _b.label = 3;
73
- case 3: return [2 /*return*/];
73
+ case 3:
74
+ _c.sent();
75
+ _c.label = 4;
76
+ case 4: return [2 /*return*/];
74
77
  }
75
78
  });
76
79
  });
@@ -80,12 +83,13 @@ var SessionReplay = /** @class */ (function () {
80
83
  };
81
84
  SessionReplay.prototype.asyncSetSessionId = function (sessionId, deviceId) {
82
85
  return tslib_1.__awaiter(this, void 0, void 0, function () {
83
- var deviceIdForReplayId, _a;
86
+ var previousSessionId, deviceIdForReplayId, _a;
84
87
  return tslib_1.__generator(this, function (_b) {
85
88
  switch (_b.label) {
86
89
  case 0:
87
- if (this.identifiers && this.identifiers.sessionId) {
88
- this.stopRecordingAndSendEvents(this.identifiers.sessionId);
90
+ previousSessionId = this.identifiers && this.identifiers.sessionId;
91
+ if (previousSessionId) {
92
+ this.stopRecordingAndSendEvents(previousSessionId);
89
93
  }
90
94
  deviceIdForReplayId = deviceId || this.getDeviceId();
91
95
  this.identifiers = new identifiers_1.SessionIdentifiers({
@@ -93,7 +97,7 @@ var SessionReplay = /** @class */ (function () {
93
97
  deviceId: deviceIdForReplayId,
94
98
  });
95
99
  this.eventsManager && this.eventsManager.resetSequence();
96
- if (!this.joinedConfigGenerator) return [3 /*break*/, 2];
100
+ if (!(this.joinedConfigGenerator && previousSessionId)) return [3 /*break*/, 2];
97
101
  _a = this;
98
102
  return [4 /*yield*/, this.joinedConfigGenerator.generateJoinedConfig(this.identifiers.sessionId)];
99
103
  case 1:
@@ -1 +1 @@
1
- {"version":3,"file":"session-replay.js","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":";;;AAAA,8EAA2F;AAC3F,4DAAkE;AAElE,0CAAgD;AAChD,wDAA4E;AAE5E,yCAKqB;AACrB,mDAA8D;AAC9D,qCAA6E;AAC7E,6CAAmD;AACnD,yDAAmE;AASnE;IAUE;QAAA,iBAEC;QAXD,SAAI,GAAG,mCAAmC,CAAC;QAO3C,yBAAoB,GAAqC,IAAI,CAAC;QAgG9D,iBAAY,GAAG;YACb,KAAI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,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC;SAC9D;QAED,OAAO,qBAAqB,KAAI,MAAA,IAAI,CAAC,WAAW,0CAAE,QAAQ,CAAA,CAAC;IAC7D,CAAC;IAED,oCAAY,GAAZ;;QACE,OAAO,MAAA,IAAI,CAAC,WAAW,0CAAE,SAAS,CAAC;IACrC,CAAC;IAEK,6BAAK,GAAX,UAAY,QAAgB;QAAhB,yBAAA,EAAA,gBAAgB;;;gBAC1B,IAAI,IAAI,CAAC,aAAa,EAAE;oBACtB,sBAAO,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAC;iBAC3C;;;;KACF;IAED,gCAAQ,GAAR;QACE,IAAM,WAAW,GAAG,IAAA,wCAAc,GAAE,CAAC;QACrC,IAAI,WAAW,EAAE;YACf,WAAW,CAAC,mBAAmB,CAAC,MAAM,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;YAC3D,WAAW,CAAC,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;SAC9D;QAED,IAAI,CAAC,0BAA0B,EAAE,CAAC;IACpC,CAAC;IACH,oBAAC;AAAD,CAAC,AA9QD,IA8QC;AA9QY,sCAAa","sourcesContent":["import { getAnalyticsConnector, getGlobalScope } from '@amplitude/analytics-client-common';\nimport { Logger, returnWrapper } from '@amplitude/analytics-core';\nimport { Logger as ILogger } from '@amplitude/analytics-types';\nimport { pack, record } from '@amplitude/rrweb';\nimport { SessionReplayJoinedConfigGenerator } from './config/joined-config';\nimport { SessionReplayJoinedConfig } from './config/types';\nimport {\n BLOCK_CLASS,\n DEFAULT_SESSION_REPLAY_PROPERTY,\n MASK_TEXT_CLASS,\n SESSION_REPLAY_DEBUG_PROPERTY,\n} from './constants';\nimport { SessionReplayEventsManager } from './events-manager';\nimport { generateHashCode, isSessionInSample, maskInputFn } from './helpers';\nimport { SessionIdentifiers } from './identifiers';\nimport { SessionReplaySessionIDBStore } from './session-idb-store';\nimport {\n AmplitudeSessionReplay,\n SessionReplayEventsManager as AmplitudeSessionReplayEventsManager,\n SessionReplaySessionIDBStore as AmplitudeSessionReplaySessionIDBStore,\n SessionIdentifiers as ISessionIdentifiers,\n SessionReplayOptions,\n} from './typings/session-replay';\n\nexport class SessionReplay implements AmplitudeSessionReplay {\n name = '@amplitude/session-replay-browser';\n config: SessionReplayJoinedConfig | undefined;\n joinedConfigGenerator: SessionReplayJoinedConfigGenerator | undefined;\n identifiers: ISessionIdentifiers | undefined;\n eventsManager: AmplitudeSessionReplayEventsManager | undefined;\n sessionIDBStore: AmplitudeSessionReplaySessionIDBStore | undefined;\n loggerProvider: ILogger;\n recordCancelCallback: ReturnType<typeof record> | null = null;\n\n constructor() {\n this.loggerProvider = new Logger();\n }\n\n init(apiKey: string, options: SessionReplayOptions) {\n return returnWrapper(this._init(apiKey, options));\n }\n\n protected async _init(apiKey: string, options: SessionReplayOptions) {\n this.loggerProvider = options.loggerProvider || new Logger();\n this.sessionIDBStore = new SessionReplaySessionIDBStore({\n loggerProvider: this.loggerProvider,\n apiKey: apiKey,\n });\n this.identifiers = new SessionIdentifiers({ sessionId: options.sessionId, deviceId: options.deviceId });\n this.joinedConfigGenerator = new SessionReplayJoinedConfigGenerator(apiKey, options, this.sessionIDBStore);\n this.config = await this.joinedConfigGenerator.generateJoinedConfig(this.identifiers.sessionId);\n\n this.eventsManager = new SessionReplayEventsManager({\n config: this.config,\n sessionIDBStore: this.sessionIDBStore,\n });\n\n this.loggerProvider.log('Installing @amplitude/session-replay-browser.');\n\n const globalScope = getGlobalScope();\n if (globalScope) {\n globalScope.removeEventListener('blur', this.blurListener);\n globalScope.removeEventListener('focus', this.focusListener);\n globalScope.addEventListener('blur', this.blurListener);\n globalScope.addEventListener('focus', this.focusListener);\n }\n\n if (globalScope && globalScope.document && globalScope.document.hasFocus()) {\n await this.initialize(true);\n }\n }\n\n setSessionId(sessionId: number, deviceId?: string) {\n return returnWrapper(this.asyncSetSessionId(sessionId, deviceId));\n }\n\n async asyncSetSessionId(sessionId: number, deviceId?: string) {\n if (this.identifiers && this.identifiers.sessionId) {\n this.stopRecordingAndSendEvents(this.identifiers.sessionId);\n }\n\n const deviceIdForReplayId = deviceId || this.getDeviceId();\n this.identifiers = new SessionIdentifiers({\n sessionId: sessionId,\n deviceId: deviceIdForReplayId,\n });\n\n this.eventsManager && this.eventsManager.resetSequence();\n if (this.joinedConfigGenerator) {\n this.config = await this.joinedConfigGenerator.generateJoinedConfig(this.identifiers.sessionId);\n }\n this.recordEvents();\n }\n\n getSessionReplayDebugPropertyValue() {\n let apiKeyHash = '';\n if (this.config) {\n apiKeyHash = generateHashCode(this.config.apiKey).toString();\n }\n return JSON.stringify({\n appHash: apiKeyHash,\n });\n }\n\n getSessionReplayProperties() {\n if (!this.config || !this.identifiers) {\n this.loggerProvider.error('Session replay init has not been called, cannot get session recording properties.');\n return {};\n }\n\n // If the user is in debug mode, ignore the focus handler when tagging events.\n // this is a common mishap when someone is developing locally and not seeing events getting tagged.\n const ignoreFocus = !!this.config.debugMode;\n const shouldRecord = this.getShouldRecord(ignoreFocus);\n\n if (shouldRecord) {\n const eventProperties: { [key: string]: string | null } = {\n [DEFAULT_SESSION_REPLAY_PROPERTY]: this.identifiers.sessionReplayId ? this.identifiers.sessionReplayId : null,\n };\n if (this.config.debugMode) {\n eventProperties[SESSION_REPLAY_DEBUG_PROPERTY] = this.getSessionReplayDebugPropertyValue();\n }\n return eventProperties;\n }\n\n return {};\n }\n\n blurListener = () => {\n this.stopRecordingAndSendEvents();\n };\n\n focusListener = () => {\n void this.initialize();\n };\n\n stopRecordingAndSendEvents(sessionId?: number) {\n this.stopRecordingEvents();\n\n const sessionIdToSend = sessionId || this.identifiers?.sessionId;\n const deviceId = this.getDeviceId();\n this.eventsManager &&\n sessionIdToSend &&\n deviceId &&\n this.eventsManager.sendEvents({ sessionId: sessionIdToSend, deviceId });\n }\n\n async initialize(shouldSendStoredEvents = false) {\n if (!this.identifiers?.sessionId) {\n this.loggerProvider.log(`Session is not being recorded due to lack of session id.`);\n return;\n }\n\n const deviceId = this.getDeviceId();\n if (!deviceId) {\n this.loggerProvider.log(`Session is not being recorded due to lack of device id.`);\n return;\n }\n\n this.eventsManager &&\n (await this.eventsManager.initialize({\n sessionId: this.identifiers.sessionId,\n shouldSendStoredEvents: shouldSendStoredEvents,\n deviceId,\n }));\n\n this.recordEvents();\n }\n\n shouldOptOut() {\n let identityStoreOptOut: boolean | undefined;\n if (this.config?.instanceName) {\n const identityStore = getAnalyticsConnector(this.config.instanceName).identityStore;\n identityStoreOptOut = identityStore.getIdentity().optOut;\n }\n\n return identityStoreOptOut !== undefined ? identityStoreOptOut : this.config?.optOut;\n }\n\n getShouldRecord(ignoreFocus = false) {\n if (!this.identifiers || !this.config || !this.identifiers.sessionId) {\n this.loggerProvider.error(`Session is not being recorded due to lack of config, please call sessionReplay.init.`);\n return false;\n }\n if (!this.config.captureEnabled) {\n this.loggerProvider.log(\n `Session ${this.identifiers.sessionId} not being captured due to capture being disabled for project.`,\n );\n return false;\n }\n\n const globalScope = getGlobalScope();\n if (!ignoreFocus && globalScope && globalScope.document && !globalScope.document.hasFocus()) {\n this.loggerProvider.log(\n `Session ${this.identifiers.sessionId} temporarily not recording due to lack of browser focus.`,\n );\n return false;\n }\n\n if (this.shouldOptOut()) {\n this.loggerProvider.log(`Opting session ${this.identifiers.sessionId} out of recording due to optOut config.`);\n return false;\n }\n\n const isInSample = isSessionInSample(this.identifiers.sessionId, this.config.sampleRate);\n if (!isInSample) {\n this.loggerProvider.log(`Opting session ${this.identifiers.sessionId} out of recording due to sample rate.`);\n }\n return isInSample;\n }\n\n getBlockSelectors(): string | string[] | undefined {\n return this.config?.privacyConfig?.blockSelector;\n }\n\n recordEvents() {\n const shouldRecord = this.getShouldRecord();\n const sessionId = this.identifiers?.sessionId;\n if (!shouldRecord || !sessionId) {\n return;\n }\n this.stopRecordingEvents();\n this.recordCancelCallback = record({\n emit: (event) => {\n const globalScope = getGlobalScope();\n if ((globalScope && globalScope.document && !globalScope.document.hasFocus()) || !this.getShouldRecord()) {\n this.stopRecordingAndSendEvents();\n return;\n }\n const eventString = JSON.stringify(event);\n const deviceId = this.getDeviceId();\n deviceId && this.eventsManager && this.eventsManager.addEvent({ event: eventString, sessionId, deviceId });\n },\n packFn: pack,\n maskAllInputs: true,\n maskTextClass: MASK_TEXT_CLASS,\n blockClass: BLOCK_CLASS,\n // rrweb only exposes array type through its types, but arrays are also be supported. #class, ['#class', 'id']\n blockSelector: this.getBlockSelectors() as string,\n maskInputFn,\n recordCanvas: false,\n errorHandler: (error) => {\n const typedError = error as Error;\n\n // styled-components relies on this error being thrown and bubbled up, rrweb is otherwise suppressing it\n if (typedError.message.includes('insertRule') && typedError.message.includes('CSSStyleSheet')) {\n throw typedError;\n }\n this.loggerProvider.warn('Error while recording: ', typedError.toString());\n // Return true so that we don't clutter user's consoles with internal rrweb errors\n return true;\n },\n });\n }\n\n stopRecordingEvents = () => {\n try {\n this.recordCancelCallback && this.recordCancelCallback();\n this.recordCancelCallback = null;\n } catch (error) {\n const typedError = error as Error;\n this.loggerProvider.warn(`Error occurred while stopping recording: ${typedError.toString()}`);\n }\n };\n\n getDeviceId() {\n let identityStoreDeviceId: string | undefined;\n if (this.config?.instanceName) {\n const identityStore = getAnalyticsConnector(this.config.instanceName).identityStore;\n identityStoreDeviceId = identityStore.getIdentity().deviceId;\n }\n\n return identityStoreDeviceId || this.identifiers?.deviceId;\n }\n\n getSessionId() {\n return this.identifiers?.sessionId;\n }\n\n async flush(useRetry = false) {\n if (this.eventsManager) {\n return this.eventsManager.flush(useRetry);\n }\n }\n\n shutdown() {\n const globalScope = getGlobalScope();\n if (globalScope) {\n globalScope.removeEventListener('blur', this.blurListener);\n globalScope.removeEventListener('focus', this.focusListener);\n }\n\n this.stopRecordingAndSendEvents();\n }\n}\n"]}
1
+ {"version":3,"file":"session-replay.js","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":";;;AAAA,8EAA2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AAC;gBAC3E,kFAAkF;gBAClF,OAAO,IAAI,CAAC;YACd,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IAYD,mCAAW,GAAX;;QACE,IAAI,qBAAyC,CAAC;QAC9C,IAAI,MAAA,IAAI,CAAC,MAAM,0CAAE,YAAY,EAAE;YAC7B,IAAM,aAAa,GAAG,IAAA,+CAAqB,EAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,aAAa,CAAC;YACpF,qBAAqB,GAAG,aAAa,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC;SAC9D;QAED,OAAO,qBAAqB,KAAI,MAAA,IAAI,CAAC,WAAW,0CAAE,QAAQ,CAAA,CAAC;IAC7D,CAAC;IAED,oCAAY,GAAZ;;QACE,OAAO,MAAA,IAAI,CAAC,WAAW,0CAAE,SAAS,CAAC;IACrC,CAAC;IAEK,6BAAK,GAAX,UAAY,QAAgB;QAAhB,yBAAA,EAAA,gBAAgB;;;gBAC1B,IAAI,IAAI,CAAC,aAAa,EAAE;oBACtB,sBAAO,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAC;iBAC3C;;;;KACF;IAED,gCAAQ,GAAR;QACE,IAAM,WAAW,GAAG,IAAA,wCAAc,GAAE,CAAC;QACrC,IAAI,WAAW,EAAE;YACf,WAAW,CAAC,mBAAmB,CAAC,MAAM,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;YAC3D,WAAW,CAAC,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;SAC9D;QAED,IAAI,CAAC,0BAA0B,EAAE,CAAC;IACpC,CAAC;IACH,oBAAC;AAAD,CAAC,AAjRD,IAiRC;AAjRY,sCAAa","sourcesContent":["import { getAnalyticsConnector, getGlobalScope } from '@amplitude/analytics-client-common';\nimport { Logger, returnWrapper } from '@amplitude/analytics-core';\nimport { Logger as ILogger } from '@amplitude/analytics-types';\nimport { pack, record } from '@amplitude/rrweb';\nimport { SessionReplayJoinedConfigGenerator, createSessionReplayJoinedConfigGenerator } from './config/joined-config';\nimport { SessionReplayJoinedConfig } from './config/types';\nimport {\n BLOCK_CLASS,\n DEFAULT_SESSION_REPLAY_PROPERTY,\n MASK_TEXT_CLASS,\n SESSION_REPLAY_DEBUG_PROPERTY,\n} from './constants';\nimport { SessionReplayEventsManager } from './events-manager';\nimport { generateHashCode, isSessionInSample, maskInputFn } from './helpers';\nimport { SessionIdentifiers } from './identifiers';\nimport { SessionReplaySessionIDBStore } from './session-idb-store';\nimport {\n AmplitudeSessionReplay,\n SessionReplayEventsManager as AmplitudeSessionReplayEventsManager,\n SessionReplaySessionIDBStore as AmplitudeSessionReplaySessionIDBStore,\n SessionIdentifiers as ISessionIdentifiers,\n SessionReplayOptions,\n} from './typings/session-replay';\n\nexport class SessionReplay implements AmplitudeSessionReplay {\n name = '@amplitude/session-replay-browser';\n config: SessionReplayJoinedConfig | undefined;\n joinedConfigGenerator: SessionReplayJoinedConfigGenerator | undefined;\n identifiers: ISessionIdentifiers | undefined;\n eventsManager: AmplitudeSessionReplayEventsManager | undefined;\n sessionIDBStore: AmplitudeSessionReplaySessionIDBStore | undefined;\n loggerProvider: ILogger;\n recordCancelCallback: ReturnType<typeof record> | null = null;\n\n constructor() {\n this.loggerProvider = new Logger();\n }\n\n init(apiKey: string, options: SessionReplayOptions) {\n return returnWrapper(this._init(apiKey, options));\n }\n\n protected async _init(apiKey: string, options: SessionReplayOptions) {\n this.loggerProvider = options.loggerProvider || new Logger();\n this.sessionIDBStore = new SessionReplaySessionIDBStore({\n loggerProvider: this.loggerProvider,\n apiKey: apiKey,\n });\n this.identifiers = new SessionIdentifiers({ sessionId: options.sessionId, deviceId: options.deviceId });\n this.joinedConfigGenerator = await createSessionReplayJoinedConfigGenerator(apiKey, options);\n this.config = await this.joinedConfigGenerator.generateJoinedConfig(this.identifiers.sessionId);\n\n this.eventsManager = new SessionReplayEventsManager({\n config: this.config,\n sessionIDBStore: this.sessionIDBStore,\n });\n\n this.loggerProvider.log('Installing @amplitude/session-replay-browser.');\n\n const globalScope = getGlobalScope();\n if (globalScope) {\n globalScope.removeEventListener('blur', this.blurListener);\n globalScope.removeEventListener('focus', this.focusListener);\n globalScope.addEventListener('blur', this.blurListener);\n globalScope.addEventListener('focus', this.focusListener);\n }\n\n if (globalScope && globalScope.document && globalScope.document.hasFocus()) {\n await this.initialize(true);\n }\n }\n\n setSessionId(sessionId: number, deviceId?: string) {\n return returnWrapper(this.asyncSetSessionId(sessionId, deviceId));\n }\n\n async asyncSetSessionId(sessionId: number, deviceId?: string) {\n const previousSessionId = this.identifiers && this.identifiers.sessionId;\n if (previousSessionId) {\n this.stopRecordingAndSendEvents(previousSessionId);\n }\n\n const deviceIdForReplayId = deviceId || this.getDeviceId();\n this.identifiers = new SessionIdentifiers({\n sessionId: sessionId,\n deviceId: deviceIdForReplayId,\n });\n\n this.eventsManager && this.eventsManager.resetSequence();\n // If there is no previous session id, SDK is being initialized for the first time,\n // and config was just fetched in initialization, so no need to fetch it a second time\n if (this.joinedConfigGenerator && previousSessionId) {\n this.config = await this.joinedConfigGenerator.generateJoinedConfig(this.identifiers.sessionId);\n }\n this.recordEvents();\n }\n\n getSessionReplayDebugPropertyValue() {\n let apiKeyHash = '';\n if (this.config) {\n apiKeyHash = generateHashCode(this.config.apiKey).toString();\n }\n return JSON.stringify({\n appHash: apiKeyHash,\n });\n }\n\n getSessionReplayProperties() {\n if (!this.config || !this.identifiers) {\n this.loggerProvider.error('Session replay init has not been called, cannot get session recording properties.');\n return {};\n }\n\n // If the user is in debug mode, ignore the focus handler when tagging events.\n // this is a common mishap when someone is developing locally and not seeing events getting tagged.\n const ignoreFocus = !!this.config.debugMode;\n const shouldRecord = this.getShouldRecord(ignoreFocus);\n\n if (shouldRecord) {\n const eventProperties: { [key: string]: string | null } = {\n [DEFAULT_SESSION_REPLAY_PROPERTY]: this.identifiers.sessionReplayId ? this.identifiers.sessionReplayId : null,\n };\n if (this.config.debugMode) {\n eventProperties[SESSION_REPLAY_DEBUG_PROPERTY] = this.getSessionReplayDebugPropertyValue();\n }\n return eventProperties;\n }\n\n return {};\n }\n\n blurListener = () => {\n this.stopRecordingAndSendEvents();\n };\n\n focusListener = () => {\n void this.initialize();\n };\n\n stopRecordingAndSendEvents(sessionId?: number) {\n this.stopRecordingEvents();\n\n const sessionIdToSend = sessionId || this.identifiers?.sessionId;\n const deviceId = this.getDeviceId();\n this.eventsManager &&\n sessionIdToSend &&\n deviceId &&\n this.eventsManager.sendEvents({ sessionId: sessionIdToSend, deviceId });\n }\n\n async initialize(shouldSendStoredEvents = false) {\n if (!this.identifiers?.sessionId) {\n this.loggerProvider.log(`Session is not being recorded due to lack of session id.`);\n return;\n }\n\n const deviceId = this.getDeviceId();\n if (!deviceId) {\n this.loggerProvider.log(`Session is not being recorded due to lack of device id.`);\n return;\n }\n\n this.eventsManager &&\n (await this.eventsManager.initialize({\n sessionId: this.identifiers.sessionId,\n shouldSendStoredEvents: shouldSendStoredEvents,\n deviceId,\n }));\n\n this.recordEvents();\n }\n\n shouldOptOut() {\n let identityStoreOptOut: boolean | undefined;\n if (this.config?.instanceName) {\n const identityStore = getAnalyticsConnector(this.config.instanceName).identityStore;\n identityStoreOptOut = identityStore.getIdentity().optOut;\n }\n\n return identityStoreOptOut !== undefined ? identityStoreOptOut : this.config?.optOut;\n }\n\n getShouldRecord(ignoreFocus = false) {\n if (!this.identifiers || !this.config || !this.identifiers.sessionId) {\n this.loggerProvider.error(`Session is not being recorded due to lack of config, please call sessionReplay.init.`);\n return false;\n }\n if (!this.config.captureEnabled) {\n this.loggerProvider.log(\n `Session ${this.identifiers.sessionId} not being captured due to capture being disabled for project.`,\n );\n return false;\n }\n\n const globalScope = getGlobalScope();\n if (!ignoreFocus && globalScope && globalScope.document && !globalScope.document.hasFocus()) {\n this.loggerProvider.log(\n `Session ${this.identifiers.sessionId} temporarily not recording due to lack of browser focus.`,\n );\n return false;\n }\n\n if (this.shouldOptOut()) {\n this.loggerProvider.log(`Opting session ${this.identifiers.sessionId} out of recording due to optOut config.`);\n return false;\n }\n\n const isInSample = isSessionInSample(this.identifiers.sessionId, this.config.sampleRate);\n if (!isInSample) {\n this.loggerProvider.log(`Opting session ${this.identifiers.sessionId} out of recording due to sample rate.`);\n }\n return isInSample;\n }\n\n getBlockSelectors(): string | string[] | undefined {\n return this.config?.privacyConfig?.blockSelector;\n }\n\n recordEvents() {\n const shouldRecord = this.getShouldRecord();\n const sessionId = this.identifiers?.sessionId;\n if (!shouldRecord || !sessionId) {\n return;\n }\n this.stopRecordingEvents();\n this.recordCancelCallback = record({\n emit: (event) => {\n const globalScope = getGlobalScope();\n if ((globalScope && globalScope.document && !globalScope.document.hasFocus()) || !this.getShouldRecord()) {\n this.stopRecordingAndSendEvents();\n return;\n }\n const eventString = JSON.stringify(event);\n const deviceId = this.getDeviceId();\n deviceId && this.eventsManager && this.eventsManager.addEvent({ event: eventString, sessionId, deviceId });\n },\n packFn: pack,\n maskAllInputs: true,\n maskTextClass: MASK_TEXT_CLASS,\n blockClass: BLOCK_CLASS,\n // rrweb only exposes array type through its types, but arrays are also be supported. #class, ['#class', 'id']\n blockSelector: this.getBlockSelectors() as string,\n maskInputFn,\n recordCanvas: false,\n errorHandler: (error) => {\n const typedError = error as Error;\n\n // styled-components relies on this error being thrown and bubbled up, rrweb is otherwise suppressing it\n if (typedError.message.includes('insertRule') && typedError.message.includes('CSSStyleSheet')) {\n throw typedError;\n }\n this.loggerProvider.warn('Error while recording: ', typedError.toString());\n // Return true so that we don't clutter user's consoles with internal rrweb errors\n return true;\n },\n });\n }\n\n stopRecordingEvents = () => {\n try {\n this.recordCancelCallback && this.recordCancelCallback();\n this.recordCancelCallback = null;\n } catch (error) {\n const typedError = error as Error;\n this.loggerProvider.warn(`Error occurred while stopping recording: ${typedError.toString()}`);\n }\n };\n\n getDeviceId() {\n let identityStoreDeviceId: string | undefined;\n if (this.config?.instanceName) {\n const identityStore = getAnalyticsConnector(this.config.instanceName).identityStore;\n identityStoreDeviceId = identityStore.getIdentity().deviceId;\n }\n\n return identityStoreDeviceId || this.identifiers?.deviceId;\n }\n\n getSessionId() {\n return this.identifiers?.sessionId;\n }\n\n async flush(useRetry = false) {\n if (this.eventsManager) {\n return this.eventsManager.flush(useRetry);\n }\n }\n\n shutdown() {\n const globalScope = getGlobalScope();\n if (globalScope) {\n globalScope.removeEventListener('blur', this.blurListener);\n globalScope.removeEventListener('focus', this.focusListener);\n }\n\n this.stopRecordingAndSendEvents();\n }\n}\n"]}
@@ -1,10 +1,12 @@
1
- import { SessionReplaySessionIDBStore as AmplitudeSessionReplaySessionIDBStore, SessionReplayOptions } from '../typings/session-replay';
2
- import { SessionReplayLocalConfig as ISessionReplayLocalConfig, SessionReplayRemoteConfigFetch as ISessionReplayRemoteConfigFetch, SessionReplayJoinedConfig } from './types';
1
+ import { RemoteConfigFetch } from '@amplitude/analytics-remote-config';
2
+ import { SessionReplayOptions } from '../typings/session-replay';
3
+ import { SessionReplayLocalConfig as ISessionReplayLocalConfig, SessionReplayJoinedConfig, SessionReplayRemoteConfig } from './types';
3
4
  export declare class SessionReplayJoinedConfigGenerator {
4
5
  localConfig: ISessionReplayLocalConfig;
5
- remoteConfigFetch: ISessionReplayRemoteConfigFetch;
6
- sessionIDBStore: AmplitudeSessionReplaySessionIDBStore;
7
- constructor(apiKey: string, options: SessionReplayOptions, sessionIDBStore: AmplitudeSessionReplaySessionIDBStore);
6
+ remoteConfigFetch: RemoteConfigFetch<SessionReplayRemoteConfig> | undefined;
7
+ constructor(apiKey: string, options: SessionReplayOptions);
8
+ initialize(): Promise<void>;
8
9
  generateJoinedConfig(sessionId?: number): Promise<SessionReplayJoinedConfig>;
9
10
  }
11
+ export declare const createSessionReplayJoinedConfigGenerator: (apiKey: string, options: SessionReplayOptions) => Promise<SessionReplayJoinedConfigGenerator>;
10
12
  //# sourceMappingURL=joined-config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"joined-config.d.ts","sourceRoot":"","sources":["../../../src/config/joined-config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,IAAI,qCAAqC,EACrE,oBAAoB,EACrB,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EACL,wBAAwB,IAAI,yBAAyB,EACrD,8BAA8B,IAAI,+BAA+B,EACjE,yBAAyB,EAC1B,MAAM,SAAS,CAAC;AAEjB,qBAAa,kCAAkC;IAC7C,WAAW,EAAE,yBAAyB,CAAC;IACvC,iBAAiB,EAAE,+BAA+B,CAAC;IACnD,eAAe,EAAE,qCAAqC,CAAC;gBAE3C,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,qCAAqC;IAS3G,oBAAoB,CAAC,SAAS,CAAC,EAAE,MAAM;CA8B9C"}
1
+ {"version":3,"file":"joined-config.d.ts","sourceRoot":"","sources":["../../../src/config/joined-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AAChG,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,OAAO,EACL,wBAAwB,IAAI,yBAAyB,EACrD,yBAAyB,EACzB,yBAAyB,EAC1B,MAAM,SAAS,CAAC;AAEjB,qBAAa,kCAAkC;IAC7C,WAAW,EAAE,yBAAyB,CAAC;IACvC,iBAAiB,EAAE,iBAAiB,CAAC,yBAAyB,CAAC,GAAG,SAAS,CAAC;gBAEhE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,oBAAoB;IAInD,UAAU;IAOV,oBAAoB,CAAC,SAAS,CAAC,EAAE,MAAM;CAqC9C;AAED,eAAO,MAAM,wCAAwC,WAAkB,MAAM,WAAW,oBAAoB,gDAI3G,CAAC"}
@@ -1,30 +1,48 @@
1
1
  import { __assign, __awaiter, __generator } from "tslib";
2
+ import { createRemoteConfigFetch } from '@amplitude/analytics-remote-config';
2
3
  import { SessionReplayLocalConfig } from './local-config';
3
- import { SessionReplayRemoteConfigFetch } from './remote-config';
4
4
  var SessionReplayJoinedConfigGenerator = /** @class */ (function () {
5
- function SessionReplayJoinedConfigGenerator(apiKey, options, sessionIDBStore) {
6
- this.sessionIDBStore = sessionIDBStore;
5
+ function SessionReplayJoinedConfigGenerator(apiKey, options) {
7
6
  this.localConfig = new SessionReplayLocalConfig(apiKey, options);
8
- this.remoteConfigFetch = new SessionReplayRemoteConfigFetch({
9
- localConfig: this.localConfig,
10
- sessionIDBStore: this.sessionIDBStore,
11
- });
12
7
  }
8
+ SessionReplayJoinedConfigGenerator.prototype.initialize = function () {
9
+ return __awaiter(this, void 0, void 0, function () {
10
+ var _a;
11
+ return __generator(this, function (_b) {
12
+ switch (_b.label) {
13
+ case 0:
14
+ _a = this;
15
+ return [4 /*yield*/, createRemoteConfigFetch({
16
+ localConfig: this.localConfig,
17
+ configKeys: ['sessionReplay'],
18
+ })];
19
+ case 1:
20
+ _a.remoteConfigFetch = _b.sent();
21
+ return [2 /*return*/];
22
+ }
23
+ });
24
+ });
25
+ };
13
26
  SessionReplayJoinedConfigGenerator.prototype.generateJoinedConfig = function (sessionId) {
14
27
  return __awaiter(this, void 0, void 0, function () {
15
- var config, samplingConfig, err_1, knownError;
16
- return __generator(this, function (_a) {
17
- switch (_a.label) {
28
+ var config, samplingConfig, _a, err_1, knownError;
29
+ return __generator(this, function (_b) {
30
+ switch (_b.label) {
18
31
  case 0:
19
32
  config = __assign({}, this.localConfig);
20
33
  // Special case here as optOut is implemented via getter/setter
21
34
  config.optOut = this.localConfig.optOut;
22
- _a.label = 1;
35
+ _b.label = 1;
23
36
  case 1:
24
- _a.trys.push([1, 3, , 4]);
25
- return [4 /*yield*/, this.remoteConfigFetch.getSamplingConfig(sessionId)];
37
+ _b.trys.push([1, 4, , 5]);
38
+ _a = this.remoteConfigFetch;
39
+ if (!_a) return [3 /*break*/, 3];
40
+ return [4 /*yield*/, this.remoteConfigFetch.getRemoteConfig('sessionReplay', 'sr_sampling_config', sessionId)];
26
41
  case 2:
27
- samplingConfig = _a.sent();
42
+ _a = (_b.sent());
43
+ _b.label = 3;
44
+ case 3:
45
+ samplingConfig = _a;
28
46
  if (samplingConfig && Object.keys(samplingConfig).length > 0) {
29
47
  if (Object.prototype.hasOwnProperty.call(samplingConfig, 'capture_enabled')) {
30
48
  config.captureEnabled = samplingConfig.capture_enabled;
@@ -42,14 +60,14 @@ var SessionReplayJoinedConfigGenerator = /** @class */ (function () {
42
60
  // allowing for immediate replay capture
43
61
  config.captureEnabled = true;
44
62
  }
45
- return [3 /*break*/, 4];
46
- case 3:
47
- err_1 = _a.sent();
63
+ return [3 /*break*/, 5];
64
+ case 4:
65
+ err_1 = _b.sent();
48
66
  knownError = err_1;
49
67
  this.localConfig.loggerProvider.warn(knownError.message);
50
68
  config.captureEnabled = true;
51
- return [3 /*break*/, 4];
52
- case 4: return [2 /*return*/, config];
69
+ return [3 /*break*/, 5];
70
+ case 5: return [2 /*return*/, config];
53
71
  }
54
72
  });
55
73
  });
@@ -57,4 +75,17 @@ var SessionReplayJoinedConfigGenerator = /** @class */ (function () {
57
75
  return SessionReplayJoinedConfigGenerator;
58
76
  }());
59
77
  export { SessionReplayJoinedConfigGenerator };
78
+ export var createSessionReplayJoinedConfigGenerator = function (apiKey, options) { return __awaiter(void 0, void 0, void 0, function () {
79
+ var joinedConfigGenerator;
80
+ return __generator(this, function (_a) {
81
+ switch (_a.label) {
82
+ case 0:
83
+ joinedConfigGenerator = new SessionReplayJoinedConfigGenerator(apiKey, options);
84
+ return [4 /*yield*/, joinedConfigGenerator.initialize()];
85
+ case 1:
86
+ _a.sent();
87
+ return [2 /*return*/, joinedConfigGenerator];
88
+ }
89
+ });
90
+ }); };
60
91
  //# sourceMappingURL=joined-config.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"joined-config.js","sourceRoot":"","sources":["../../../src/config/joined-config.ts"],"names":[],"mappings":";AAIA,OAAO,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,8BAA8B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AAc,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;wBACzD,MAAM,CAAC,cAAc,GAAG,IAAI,CAAC;;4BAG/B,sBAAO,MAAM,EAAC;;;;KACf;IACH,yCAAC;AAAD,CAAC,AA5CD,IA4CC","sourcesContent":["import {\n SessionReplaySessionIDBStore as AmplitudeSessionReplaySessionIDBStore,\n SessionReplayOptions,\n} from '../typings/session-replay';\nimport { SessionReplayLocalConfig } from './local-config';\nimport { SessionReplayRemoteConfigFetch } from './remote-config';\nimport {\n SessionReplayLocalConfig as ISessionReplayLocalConfig,\n SessionReplayRemoteConfigFetch as ISessionReplayRemoteConfigFetch,\n SessionReplayJoinedConfig,\n} from './types';\n\nexport class SessionReplayJoinedConfigGenerator {\n localConfig: ISessionReplayLocalConfig;\n remoteConfigFetch: ISessionReplayRemoteConfigFetch;\n sessionIDBStore: AmplitudeSessionReplaySessionIDBStore;\n\n constructor(apiKey: string, options: SessionReplayOptions, sessionIDBStore: AmplitudeSessionReplaySessionIDBStore) {\n this.sessionIDBStore = sessionIDBStore;\n this.localConfig = new SessionReplayLocalConfig(apiKey, options);\n this.remoteConfigFetch = new SessionReplayRemoteConfigFetch({\n localConfig: this.localConfig,\n sessionIDBStore: this.sessionIDBStore,\n });\n }\n\n async generateJoinedConfig(sessionId?: number) {\n const config: SessionReplayJoinedConfig = { ...this.localConfig };\n // Special case here as optOut is implemented via getter/setter\n config.optOut = this.localConfig.optOut;\n try {\n const samplingConfig = await this.remoteConfigFetch.getSamplingConfig(sessionId);\n if (samplingConfig && Object.keys(samplingConfig).length > 0) {\n if (Object.prototype.hasOwnProperty.call(samplingConfig, 'capture_enabled')) {\n config.captureEnabled = samplingConfig.capture_enabled;\n } else {\n config.captureEnabled = false;\n }\n\n if (samplingConfig.sample_rate) {\n config.sampleRate = samplingConfig.sample_rate;\n }\n } else {\n // If config API response was valid (ie 200), but no config returned, assume that\n // customer has not yet set up config, and use sample rate from SDK options,\n // allowing for immediate replay capture\n config.captureEnabled = true;\n }\n } catch (err: unknown) {\n const knownError = err as Error;\n this.localConfig.loggerProvider.warn(knownError.message);\n config.captureEnabled = true;\n }\n\n return config;\n }\n}\n"]}
1
+ {"version":3,"file":"joined-config.js","sourceRoot":"","sources":["../../../src/config/joined-config.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,uBAAuB,EAAqB,MAAM,oCAAoC,CAAC;AAEhG,OAAO,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAO1D;IAIE,4CAAY,MAAc,EAAE,OAA6B;QACvD,IAAI,CAAC,WAAW,GAAG,IAAI,wBAAwB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnE,CAAC;IAEK,uDAAU,GAAhB;;;;;;wBACE,KAAA,IAAI,CAAA;wBAAqB,qBAAM,uBAAuB,CAA4B;gCAChF,WAAW,EAAE,IAAI,CAAC,WAAW;gCAC7B,UAAU,EAAE,CAAC,eAAe,CAAC;6BAC9B,CAAC,EAAA;;wBAHF,GAAK,iBAAiB,GAAG,SAGvB,CAAC;;;;;KACJ;IAEK,iEAAoB,GAA1B,UAA2B,SAAkB;;;;;;wBACrC,MAAM,gBAAmC,IAAI,CAAC,WAAW,CAAE,CAAC;wBAClE,+DAA+D;wBAC/D,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;;;;wBAGpC,KAAA,IAAI,CAAC,iBAAiB,CAAA;iCAAtB,wBAAsB;wBACpB,qBAAM,IAAI,CAAC,iBAAiB,CAAC,eAAe,CAC5C,eAAe,EACf,oBAAoB,EACpB,SAAS,CACV,EAAA;;wBAJD,KAAC,CAAC,SAID,CAAqD,CAAA;;;wBANlD,cAAc,KAMoC;wBAExD,IAAI,cAAc,IAAI,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;4BAC5D,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,cAAc,EAAE,iBAAiB,CAAC,EAAE;gCAC3E,MAAM,CAAC,cAAc,GAAG,cAAc,CAAC,eAAe,CAAC;6BACxD;iCAAM;gCACL,MAAM,CAAC,cAAc,GAAG,KAAK,CAAC;6BAC/B;4BAED,IAAI,cAAc,CAAC,WAAW,EAAE;gCAC9B,MAAM,CAAC,UAAU,GAAG,cAAc,CAAC,WAAW,CAAC;6BAChD;yBACF;6BAAM;4BACL,iFAAiF;4BACjF,4EAA4E;4BAC5E,wCAAwC;4BACxC,MAAM,CAAC,cAAc,GAAG,IAAI,CAAC;yBAC9B;;;;wBAEK,UAAU,GAAG,KAAY,CAAC;wBAChC,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;wBACzD,MAAM,CAAC,cAAc,GAAG,IAAI,CAAC;;4BAG/B,sBAAO,MAAM,EAAC;;;;KACf;IACH,yCAAC;AAAD,CAAC,AApDD,IAoDC;;AAED,MAAM,CAAC,IAAM,wCAAwC,GAAG,UAAO,MAAc,EAAE,OAA6B;;;;;gBACpG,qBAAqB,GAAG,IAAI,kCAAkC,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBACtF,qBAAM,qBAAqB,CAAC,UAAU,EAAE,EAAA;;gBAAxC,SAAwC,CAAC;gBACzC,sBAAO,qBAAqB,EAAC;;;KAC9B,CAAC","sourcesContent":["import { createRemoteConfigFetch, RemoteConfigFetch } from '@amplitude/analytics-remote-config';\nimport { SessionReplayOptions } from '../typings/session-replay';\nimport { SessionReplayLocalConfig } from './local-config';\nimport {\n SessionReplayLocalConfig as ISessionReplayLocalConfig,\n SessionReplayJoinedConfig,\n SessionReplayRemoteConfig,\n} from './types';\n\nexport class SessionReplayJoinedConfigGenerator {\n localConfig: ISessionReplayLocalConfig;\n remoteConfigFetch: RemoteConfigFetch<SessionReplayRemoteConfig> | undefined;\n\n constructor(apiKey: string, options: SessionReplayOptions) {\n this.localConfig = new SessionReplayLocalConfig(apiKey, options);\n }\n\n async initialize() {\n this.remoteConfigFetch = await createRemoteConfigFetch<SessionReplayRemoteConfig>({\n localConfig: this.localConfig,\n configKeys: ['sessionReplay'],\n });\n }\n\n async generateJoinedConfig(sessionId?: number) {\n const config: SessionReplayJoinedConfig = { ...this.localConfig };\n // Special case here as optOut is implemented via getter/setter\n config.optOut = this.localConfig.optOut;\n try {\n const samplingConfig =\n this.remoteConfigFetch &&\n ((await this.remoteConfigFetch.getRemoteConfig(\n 'sessionReplay',\n 'sr_sampling_config',\n sessionId,\n )) as SessionReplayRemoteConfig['sr_sampling_config']);\n\n if (samplingConfig && Object.keys(samplingConfig).length > 0) {\n if (Object.prototype.hasOwnProperty.call(samplingConfig, 'capture_enabled')) {\n config.captureEnabled = samplingConfig.capture_enabled;\n } else {\n config.captureEnabled = false;\n }\n\n if (samplingConfig.sample_rate) {\n config.sampleRate = samplingConfig.sample_rate;\n }\n } else {\n // If config API response was valid (ie 200), but no config returned, assume that\n // customer has not yet set up config, and use sample rate from SDK options,\n // allowing for immediate replay capture\n config.captureEnabled = true;\n }\n } catch (err: unknown) {\n const knownError = err as Error;\n this.localConfig.loggerProvider.warn(knownError.message);\n config.captureEnabled = true;\n }\n\n return config;\n }\n}\n\nexport const createSessionReplayJoinedConfigGenerator = async (apiKey: string, options: SessionReplayOptions) => {\n const joinedConfigGenerator = new SessionReplayJoinedConfigGenerator(apiKey, options);\n await joinedConfigGenerator.initialize();\n return joinedConfigGenerator;\n};\n"]}
@@ -1,11 +1,10 @@
1
1
  import { Config, LogLevel, Logger } from '@amplitude/analytics-types';
2
- export interface SamplingConfig {
3
- sample_rate: number;
4
- capture_enabled: boolean;
5
- }
6
- export interface SessionReplayRemoteConfig {
7
- sr_sampling_config: SamplingConfig;
8
- }
2
+ export type SessionReplayRemoteConfig = {
3
+ sr_sampling_config: {
4
+ sample_rate: number;
5
+ capture_enabled: boolean;
6
+ };
7
+ };
9
8
  export interface SessionReplayRemoteConfigAPIResponse {
10
9
  configs: {
11
10
  sessionReplay: SessionReplayRemoteConfig;
@@ -27,6 +26,12 @@ export interface SessionReplayJoinedConfig extends SessionReplayLocalConfig {
27
26
  captureEnabled?: boolean;
28
27
  }
29
28
  export interface SessionReplayRemoteConfigFetch {
30
- getSamplingConfig: (sessionId?: number) => Promise<SamplingConfig | void>;
29
+ getServerUrl: () => void;
30
+ getSamplingConfig: (sessionId?: number) => Promise<SessionReplayRemoteConfig['sr_sampling_config'] | void>;
31
+ fetchRemoteConfig: (sessionId?: number) => Promise<SessionReplayRemoteConfig | void>;
32
+ getRemoteConfig: (sessionId?: number) => Promise<SessionReplayRemoteConfig | void>;
33
+ }
34
+ export interface SessionReplayJoinedConfigGenerator {
35
+ generateJoinedConfig: (sessionId?: number) => Promise<SessionReplayJoinedConfig>;
31
36
  }
32
37
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/config/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAEtE,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,OAAO,CAAC;CAC1B;AACD,MAAM,WAAW,yBAAyB;IACxC,kBAAkB,EAAE,cAAc,CAAC;CACpC;AAED,MAAM,WAAW,oCAAoC;IACnD,OAAO,EAAE;QACP,aAAa,EAAE,yBAAyB,CAAC;KAC1C,CAAC;CACH;AACD,MAAM,WAAW,0BAA0B;IACzC,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CACnC;AAED,MAAM,WAAW,wBAAyB,SAAQ,MAAM;IACtD,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,QAAQ,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,0BAA0B,CA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BAAoB,CAAC,GAAG,IAAI,CAAC,CAAC;IAC3G,iBAAiB,EAAE,CAAC,SAAS,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,yBAAyB,GAAG,IAAI,CAAC,CAAC;IACrF,eAAe,EAAE,CAAC,SAAS,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,yBAAyB,GAAG,IAAI,CAAC,CAAC;CACpF;AAED,MAAM,WAAW,kCAAkC;IACjD,oBAAoB,EAAE,CAAC,SAAS,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,yBAAyB,CAAC,CAAC;CAClF"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/config/types.ts"],"names":[],"mappings":"","sourcesContent":["import { Config, LogLevel, Logger } from '@amplitude/analytics-types';\n\nexport interface SamplingConfig {\n sample_rate: number;\n capture_enabled: boolean;\n}\nexport interface SessionReplayRemoteConfig {\n sr_sampling_config: SamplingConfig;\n}\n\nexport interface SessionReplayRemoteConfigAPIResponse {\n configs: {\n sessionReplay: SessionReplayRemoteConfig;\n };\n}\nexport interface SessionReplayPrivacyConfig {\n blockSelector?: string | string[];\n}\n\nexport interface SessionReplayLocalConfig extends Config {\n apiKey: string;\n loggerProvider: Logger;\n logLevel: LogLevel;\n flushMaxRetries: number;\n sampleRate: number;\n privacyConfig?: SessionReplayPrivacyConfig;\n debugMode?: boolean;\n}\n\nexport interface SessionReplayJoinedConfig extends SessionReplayLocalConfig {\n captureEnabled?: boolean;\n}\n\nexport interface SessionReplayRemoteConfigFetch {\n getSamplingConfig: (sessionId?: number) => Promise<SamplingConfig | void>;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/config/types.ts"],"names":[],"mappings":"","sourcesContent":["import { Config, LogLevel, Logger } from '@amplitude/analytics-types';\n\nexport type SessionReplayRemoteConfig = {\n sr_sampling_config: {\n sample_rate: number;\n capture_enabled: boolean;\n };\n};\n\nexport interface SessionReplayRemoteConfigAPIResponse {\n configs: {\n sessionReplay: SessionReplayRemoteConfig;\n };\n}\nexport interface SessionReplayPrivacyConfig {\n blockSelector?: string | string[];\n}\n\nexport interface SessionReplayLocalConfig extends Config {\n apiKey: string;\n loggerProvider: Logger;\n logLevel: LogLevel;\n flushMaxRetries: number;\n sampleRate: number;\n privacyConfig?: SessionReplayPrivacyConfig;\n debugMode?: boolean;\n}\n\nexport interface SessionReplayJoinedConfig extends SessionReplayLocalConfig {\n captureEnabled?: boolean;\n}\n\nexport interface SessionReplayRemoteConfigFetch {\n getServerUrl: () => void;\n getSamplingConfig: (sessionId?: number) => Promise<SessionReplayRemoteConfig['sr_sampling_config'] | void>;\n fetchRemoteConfig: (sessionId?: number) => Promise<SessionReplayRemoteConfig | void>;\n getRemoteConfig: (sessionId?: number) => Promise<SessionReplayRemoteConfig | void>;\n}\n\nexport interface SessionReplayJoinedConfigGenerator {\n generateJoinedConfig: (sessionId?: number) => Promise<SessionReplayJoinedConfig>;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"session-replay.d.ts","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,IAAI,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAQ,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,kCAAkC,EAAE,MAAM,wBAAwB,CAAC;AAC5E,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAW3D,OAAO,EACL,sBAAsB,EACtB,0BAA0B,IAAI,mCAAmC,EACjE,4BAA4B,IAAI,qCAAqC,EACrE,kBAAkB,IAAI,mBAAmB,EACzC,oBAAoB,EACrB,MAAM,0BAA0B,CAAC;AAElC,qBAAa,aAAc,YAAW,sBAAsB;IAC1D,IAAI,SAAuC;IAC3C,MAAM,EAAE,yBAAyB,GAAG,SAAS,CAAC;IAC9C,qBAAqB,EAAE,kCAAkC,GAAG,SAAS,CAAC;IACtE,WAAW,E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