@amplitude/session-replay-browser 1.4.0 → 1.5.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/config/joined-config.d.ts.map +1 -1
- package/lib/cjs/config/joined-config.js +47 -18
- package/lib/cjs/config/joined-config.js.map +1 -1
- package/lib/cjs/config/local-config.d.ts +3 -2
- package/lib/cjs/config/local-config.d.ts.map +1 -1
- package/lib/cjs/config/local-config.js +1 -0
- package/lib/cjs/config/local-config.js.map +1 -1
- package/lib/cjs/config/types.d.ts +10 -7
- package/lib/cjs/config/types.d.ts.map +1 -1
- package/lib/cjs/config/types.js.map +1 -1
- package/lib/esm/config/joined-config.d.ts.map +1 -1
- package/lib/esm/config/joined-config.js +47 -18
- package/lib/esm/config/joined-config.js.map +1 -1
- package/lib/esm/config/local-config.d.ts +3 -2
- package/lib/esm/config/local-config.d.ts.map +1 -1
- package/lib/esm/config/local-config.js +1 -0
- package/lib/esm/config/local-config.js.map +1 -1
- package/lib/esm/config/types.d.ts +10 -7
- package/lib/esm/config/types.d.ts.map +1 -1
- package/lib/esm/config/types.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.umd.js +1 -1
- package/lib/scripts/amplitude-min.umd.js.gz +0 -0
- package/lib/scripts/config/joined-config.d.ts.map +1 -1
- package/lib/scripts/config/local-config.d.ts +3 -2
- package/lib/scripts/config/local-config.d.ts.map +1 -1
- package/lib/scripts/config/types.d.ts +10 -7
- package/lib/scripts/config/types.d.ts.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"joined-config.d.ts","sourceRoot":"","sources":["../../../src/config/joined-config.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"joined-config.d.ts","sourceRoot":"","sources":["../../../src/config/joined-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAA2B,MAAM,oCAAoC,CAAC;AAChG,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,OAAO,EACL,wBAAwB,IAAI,yBAAyB,EACrD,yBAAyB,EAEzB,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,GAAG,OAAO,CAAC,yBAAyB,CAAC;CA+EnF;AAED,eAAO,MAAM,wCAAwC,WAAkB,MAAM,WAAW,oBAAoB,gDAI3G,CAAC"}
|
|
@@ -28,24 +28,49 @@ var SessionReplayJoinedConfigGenerator = /** @class */ (function () {
|
|
|
28
28
|
};
|
|
29
29
|
SessionReplayJoinedConfigGenerator.prototype.generateJoinedConfig = function (sessionId) {
|
|
30
30
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
31
|
-
var config,
|
|
32
|
-
return tslib_1.__generator(this, function (
|
|
33
|
-
switch (
|
|
31
|
+
var config, remoteConfig, samplingConfig_1, privacyConfig_1, err_1, knownError, samplingConfig, privacyConfig, key, k;
|
|
32
|
+
return tslib_1.__generator(this, function (_a) {
|
|
33
|
+
switch (_a.label) {
|
|
34
34
|
case 0:
|
|
35
35
|
config = tslib_1.__assign({}, this.localConfig);
|
|
36
36
|
// Special case here as optOut is implemented via getter/setter
|
|
37
37
|
config.optOut = this.localConfig.optOut;
|
|
38
|
-
|
|
38
|
+
// We always want captureEnabled to be true, unless there's an override
|
|
39
|
+
// in the remote config.
|
|
40
|
+
config.captureEnabled = true;
|
|
41
|
+
_a.label = 1;
|
|
39
42
|
case 1:
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
_a.trys.push([1, 4, , 5]);
|
|
44
|
+
if (!this.remoteConfigFetch) {
|
|
45
|
+
return [2 /*return*/, config];
|
|
46
|
+
}
|
|
43
47
|
return [4 /*yield*/, this.remoteConfigFetch.getRemoteConfig('sessionReplay', 'sr_sampling_config', sessionId)];
|
|
44
48
|
case 2:
|
|
45
|
-
|
|
46
|
-
|
|
49
|
+
samplingConfig_1 = _a.sent();
|
|
50
|
+
return [4 /*yield*/, this.remoteConfigFetch.getRemoteConfig('sessionReplay', 'sr_privacy_config', sessionId)];
|
|
47
51
|
case 3:
|
|
48
|
-
|
|
52
|
+
privacyConfig_1 = _a.sent();
|
|
53
|
+
if (samplingConfig_1 || privacyConfig_1) {
|
|
54
|
+
remoteConfig = {};
|
|
55
|
+
if (samplingConfig_1) {
|
|
56
|
+
remoteConfig.sr_sampling_config = samplingConfig_1;
|
|
57
|
+
}
|
|
58
|
+
if (privacyConfig_1) {
|
|
59
|
+
remoteConfig.sr_privacy_config = privacyConfig_1;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return [3 /*break*/, 5];
|
|
63
|
+
case 4:
|
|
64
|
+
err_1 = _a.sent();
|
|
65
|
+
knownError = err_1;
|
|
66
|
+
this.localConfig.loggerProvider.warn(knownError.message);
|
|
67
|
+
config.captureEnabled = true;
|
|
68
|
+
return [3 /*break*/, 5];
|
|
69
|
+
case 5:
|
|
70
|
+
if (!remoteConfig) {
|
|
71
|
+
return [2 /*return*/, config];
|
|
72
|
+
}
|
|
73
|
+
samplingConfig = remoteConfig.sr_sampling_config, privacyConfig = remoteConfig.sr_privacy_config;
|
|
49
74
|
if (samplingConfig && Object.keys(samplingConfig).length > 0) {
|
|
50
75
|
if (Object.prototype.hasOwnProperty.call(samplingConfig, 'capture_enabled')) {
|
|
51
76
|
config.captureEnabled = samplingConfig.capture_enabled;
|
|
@@ -62,15 +87,19 @@ var SessionReplayJoinedConfigGenerator = /** @class */ (function () {
|
|
|
62
87
|
// customer has not yet set up config, and use sample rate from SDK options,
|
|
63
88
|
// allowing for immediate replay capture
|
|
64
89
|
config.captureEnabled = true;
|
|
90
|
+
this.localConfig.loggerProvider.debug('Remote config successfully fetched, but no values set for project, Session Replay capture enabled.');
|
|
65
91
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
92
|
+
// Override all keys in the local config with the remote privacy config.
|
|
93
|
+
if (privacyConfig && Object.keys(privacyConfig).length > 0) {
|
|
94
|
+
if (!config.privacyConfig) {
|
|
95
|
+
config.privacyConfig = {};
|
|
96
|
+
}
|
|
97
|
+
for (key in privacyConfig) {
|
|
98
|
+
k = key;
|
|
99
|
+
config.privacyConfig[k] = privacyConfig[k];
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return [2 /*return*/, config];
|
|
74
103
|
}
|
|
75
104
|
});
|
|
76
105
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"joined-config.js","sourceRoot":"","sources":["../../../src/config/joined-config.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"joined-config.js","sourceRoot":"","sources":["../../../src/config/joined-config.ts"],"names":[],"mappings":"AAAA,iBA+GA;;;;AA/GA,8EAAgG;AAEhG,+CAA0D;AAQ1D;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;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import { SessionReplayOptions } from '../typings/session-replay';\nimport { SessionReplayLocalConfig } from './local-config';\nimport {\n SessionReplayLocalConfig as ISessionReplayLocalConfig,\n SessionReplayJoinedConfig,\n PrivacyConfig,\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): Promise<SessionReplayJoinedConfig> {\n const config: SessionReplayJoinedConfig = { ...this.localConfig };\n // Special case here as optOut is implemented via getter/setter\n config.optOut = this.localConfig.optOut;\n // We always want captureEnabled to be true, unless there's an override\n // in the remote config.\n config.captureEnabled = true;\n let remoteConfig: SessionReplayRemoteConfig | undefined;\n try {\n if (!this.remoteConfigFetch) {\n return config;\n }\n\n const samplingConfig = await this.remoteConfigFetch.getRemoteConfig(\n 'sessionReplay',\n 'sr_sampling_config',\n sessionId,\n );\n\n const privacyConfig = await this.remoteConfigFetch.getRemoteConfig(\n 'sessionReplay',\n 'sr_privacy_config',\n sessionId,\n );\n\n if (samplingConfig || privacyConfig) {\n remoteConfig = {};\n if (samplingConfig) {\n remoteConfig.sr_sampling_config = samplingConfig;\n }\n if (privacyConfig) {\n remoteConfig.sr_privacy_config = privacyConfig;\n }\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 if (!remoteConfig) {\n return config;\n }\n\n const { sr_sampling_config: samplingConfig, sr_privacy_config: privacyConfig } = remoteConfig;\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 this.localConfig.loggerProvider.debug(\n 'Remote config successfully fetched, but no values set for project, Session Replay capture enabled.',\n );\n }\n\n // Override all keys in the local config with the remote privacy config.\n if (privacyConfig && Object.keys(privacyConfig).length > 0) {\n if (!config.privacyConfig) {\n config.privacyConfig = {};\n }\n\n for (const key in privacyConfig) {\n const k = key as keyof PrivacyConfig;\n config.privacyConfig[k] = privacyConfig[k];\n }\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"]}
|
|
@@ -2,7 +2,7 @@ import { FetchTransport } from '@amplitude/analytics-client-common';
|
|
|
2
2
|
import { Config, Logger } from '@amplitude/analytics-core';
|
|
3
3
|
import { LogLevel } from '@amplitude/analytics-types';
|
|
4
4
|
import { SessionReplayOptions } from '../typings/session-replay';
|
|
5
|
-
import { SessionReplayLocalConfig as ISessionReplayLocalConfig,
|
|
5
|
+
import { SessionReplayLocalConfig as ISessionReplayLocalConfig, PrivacyConfig } from './types';
|
|
6
6
|
export declare const getDefaultConfig: () => {
|
|
7
7
|
flushMaxRetries: number;
|
|
8
8
|
logLevel: LogLevel;
|
|
@@ -12,8 +12,9 @@ export declare const getDefaultConfig: () => {
|
|
|
12
12
|
export declare class SessionReplayLocalConfig extends Config implements ISessionReplayLocalConfig {
|
|
13
13
|
apiKey: string;
|
|
14
14
|
sampleRate: number;
|
|
15
|
-
privacyConfig?:
|
|
15
|
+
privacyConfig?: PrivacyConfig;
|
|
16
16
|
debugMode?: boolean;
|
|
17
|
+
configEndpointUrl?: string;
|
|
17
18
|
constructor(apiKey: string, options: SessionReplayOptions);
|
|
18
19
|
}
|
|
19
20
|
//# sourceMappingURL=local-config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local-config.d.ts","sourceRoot":"","sources":["../../../src/config/local-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAEtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,wBAAwB,IAAI,yBAAyB,EAAE,
|
|
1
|
+
{"version":3,"file":"local-config.d.ts","sourceRoot":"","sources":["../../../src/config/local-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAEtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,wBAAwB,IAAI,yBAAyB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE/F,eAAO,MAAM,gBAAgB;;;;;CAK3B,CAAC;AAEH,qBAAa,wBAAyB,SAAQ,MAAO,YAAW,yBAAyB;IACvF,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,iBAAiB,CAAC,EAAE,MAAM,CAAC;gBAEf,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,oBAAoB;CAwB1D"}
|
|
@@ -25,6 +25,7 @@ var SessionReplayLocalConfig = /** @class */ (function (_super) {
|
|
|
25
25
|
_this.apiKey = apiKey;
|
|
26
26
|
_this.sampleRate = options.sampleRate || constants_1.DEFAULT_SAMPLE_RATE;
|
|
27
27
|
_this.serverZone = options.serverZone || constants_1.DEFAULT_SERVER_ZONE;
|
|
28
|
+
_this.configEndpointUrl = options.configEndpointUrl;
|
|
28
29
|
if (options.privacyConfig) {
|
|
29
30
|
_this.privacyConfig = options.privacyConfig;
|
|
30
31
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local-config.js","sourceRoot":"","sources":["../../../src/config/local-config.ts"],"names":[],"mappings":";;;AAAA,8EAAoE;AACpE,4DAA2D;AAC3D,8DAAsD;AACtD,0CAAwE;AAIjE,IAAM,gBAAgB,GAAG,cAAM,OAAA,CAAC;IACrC,eAAe,EAAE,CAAC;IAClB,QAAQ,EAAE,0BAAQ,CAAC,IAAI;IACvB,cAAc,EAAE,IAAI,uBAAM,EAAE;IAC5B,iBAAiB,EAAE,IAAI,wCAAc,EAAE;CACxC,CAAC,EALoC,CAKpC,CAAC;AALU,QAAA,gBAAgB,oBAK1B;AAEH;IAA8C,oDAAM;
|
|
1
|
+
{"version":3,"file":"local-config.js","sourceRoot":"","sources":["../../../src/config/local-config.ts"],"names":[],"mappings":";;;AAAA,8EAAoE;AACpE,4DAA2D;AAC3D,8DAAsD;AACtD,0CAAwE;AAIjE,IAAM,gBAAgB,GAAG,cAAM,OAAA,CAAC;IACrC,eAAe,EAAE,CAAC;IAClB,QAAQ,EAAE,0BAAQ,CAAC,IAAI;IACvB,cAAc,EAAE,IAAI,uBAAM,EAAE;IAC5B,iBAAiB,EAAE,IAAI,wCAAc,EAAE;CACxC,CAAC,EALoC,CAKpC,CAAC;AALU,QAAA,gBAAgB,oBAK1B;AAEH;IAA8C,oDAAM;IAOlD,kCAAY,MAAc,EAAE,OAA6B;QAAzD,iBAuBC;QAtBC,IAAM,aAAa,GAAG,IAAA,wBAAgB,GAAE,CAAC;gBACzC,sDACE,iBAAiB,EAAE,aAAa,CAAC,iBAAiB,IAC/C,OAAO,KACV,MAAM,QAAA,IACN;QACF,KAAI,CAAC,eAAe;YAClB,OAAO,CAAC,eAAe,KAAK,SAAS,IAAI,OAAO,CAAC,eAAe,IAAI,aAAa,CAAC,eAAe;gBAC/F,CAAC,CAAC,OAAO,CAAC,eAAe;gBACzB,CAAC,CAAC,aAAa,CAAC,eAAe,CAAC;QAEpC,KAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,KAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,+BAAmB,CAAC;QAC5D,KAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,+BAAmB,CAAC;QAC5D,KAAI,CAAC,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC;QAEnD,IAAI,OAAO,CAAC,aAAa,EAAE;YACzB,KAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;SAC5C;QACD,IAAI,OAAO,CAAC,SAAS,EAAE;YACrB,KAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;SACpC;;IACH,CAAC;IACH,+BAAC;AAAD,CAAC,AA/BD,CAA8C,uBAAM,GA+BnD;AA/BY,4DAAwB","sourcesContent":["import { FetchTransport } from '@amplitude/analytics-client-common';\nimport { Config, Logger } from '@amplitude/analytics-core';\nimport { LogLevel } from '@amplitude/analytics-types';\nimport { DEFAULT_SAMPLE_RATE, DEFAULT_SERVER_ZONE } from '../constants';\nimport { SessionReplayOptions } from '../typings/session-replay';\nimport { SessionReplayLocalConfig as ISessionReplayLocalConfig, PrivacyConfig } from './types';\n\nexport const getDefaultConfig = () => ({\n flushMaxRetries: 2,\n logLevel: LogLevel.Warn,\n loggerProvider: new Logger(),\n transportProvider: new FetchTransport(),\n});\n\nexport class SessionReplayLocalConfig extends Config implements ISessionReplayLocalConfig {\n apiKey: string;\n sampleRate: number;\n privacyConfig?: PrivacyConfig;\n debugMode?: boolean;\n configEndpointUrl?: string;\n\n constructor(apiKey: string, options: SessionReplayOptions) {\n const defaultConfig = getDefaultConfig();\n super({\n transportProvider: defaultConfig.transportProvider,\n ...options,\n apiKey,\n });\n this.flushMaxRetries =\n options.flushMaxRetries !== undefined && options.flushMaxRetries <= defaultConfig.flushMaxRetries\n ? options.flushMaxRetries\n : defaultConfig.flushMaxRetries;\n\n this.apiKey = apiKey;\n this.sampleRate = options.sampleRate || DEFAULT_SAMPLE_RATE;\n this.serverZone = options.serverZone || DEFAULT_SERVER_ZONE;\n this.configEndpointUrl = options.configEndpointUrl;\n\n if (options.privacyConfig) {\n this.privacyConfig = options.privacyConfig;\n }\n if (options.debugMode) {\n this.debugMode = options.debugMode;\n }\n }\n}\n"]}
|
|
@@ -1,26 +1,29 @@
|
|
|
1
1
|
import { Config, LogLevel, Logger } from '@amplitude/analytics-types';
|
|
2
|
+
export interface SamplingConfig {
|
|
3
|
+
sample_rate: number;
|
|
4
|
+
capture_enabled: boolean;
|
|
5
|
+
}
|
|
2
6
|
export type SessionReplayRemoteConfig = {
|
|
3
|
-
sr_sampling_config
|
|
4
|
-
|
|
5
|
-
capture_enabled: boolean;
|
|
6
|
-
};
|
|
7
|
+
sr_sampling_config?: SamplingConfig;
|
|
8
|
+
sr_privacy_config?: PrivacyConfig;
|
|
7
9
|
};
|
|
8
10
|
export interface SessionReplayRemoteConfigAPIResponse {
|
|
9
11
|
configs: {
|
|
10
12
|
sessionReplay: SessionReplayRemoteConfig;
|
|
11
13
|
};
|
|
12
14
|
}
|
|
13
|
-
export
|
|
15
|
+
export type PrivacyConfig = {
|
|
14
16
|
blockSelector?: string | string[];
|
|
15
|
-
}
|
|
17
|
+
};
|
|
16
18
|
export interface SessionReplayLocalConfig extends Config {
|
|
17
19
|
apiKey: string;
|
|
18
20
|
loggerProvider: Logger;
|
|
19
21
|
logLevel: LogLevel;
|
|
20
22
|
flushMaxRetries: number;
|
|
21
23
|
sampleRate: number;
|
|
22
|
-
privacyConfig?:
|
|
24
|
+
privacyConfig?: PrivacyConfig;
|
|
23
25
|
debugMode?: boolean;
|
|
26
|
+
configEndpointUrl?: string;
|
|
24
27
|
}
|
|
25
28
|
export interface SessionReplayJoinedConfig extends SessionReplayLocalConfig {
|
|
26
29
|
captureEnabled?: boolean;
|
|
@@ -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,MAAM,yBAAyB,GAAG;IACtC,kBAAkB,
|
|
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;AAED,MAAM,MAAM,yBAAyB,GAAG;IACtC,kBAAkB,CAAC,EAAE,cAAc,CAAC;IACpC,iBAAiB,CAAC,EAAE,aAAa,CAAC;CACnC,CAAC;AAEF,MAAM,WAAW,oCAAoC;IACnD,OAAO,EAAE;QACP,aAAa,EAAE,yBAAyB,CAAC;KAC1C,CAAC;CACH;AAED,MAAM,MAAM,aAAa,GAAG;IAC1B,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CACnC,CAAC;AAEF,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,aAAa,CAAC;IAC9B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,yBAA0B,SAAQ,wBAAwB;IACzE,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,8BAA8B;IAC7C,YAAY,EAAE,MAAM,IAAI,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
|
|
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}\n\nexport type SessionReplayRemoteConfig = {\n sr_sampling_config?: SamplingConfig;\n sr_privacy_config?: PrivacyConfig;\n};\n\nexport interface SessionReplayRemoteConfigAPIResponse {\n configs: {\n sessionReplay: SessionReplayRemoteConfig;\n };\n}\n\nexport type PrivacyConfig = {\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?: PrivacyConfig;\n debugMode?: boolean;\n configEndpointUrl?: string;\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":"joined-config.d.ts","sourceRoot":"","sources":["../../../src/config/joined-config.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"joined-config.d.ts","sourceRoot":"","sources":["../../../src/config/joined-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAA2B,MAAM,oCAAoC,CAAC;AAChG,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,OAAO,EACL,wBAAwB,IAAI,yBAAyB,EACrD,yBAAyB,EAEzB,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,GAAG,OAAO,CAAC,yBAAyB,CAAC;CA+EnF;AAED,eAAO,MAAM,wCAAwC,WAAkB,MAAM,WAAW,oBAAoB,gDAI3G,CAAC"}
|
|
@@ -25,24 +25,49 @@ var SessionReplayJoinedConfigGenerator = /** @class */ (function () {
|
|
|
25
25
|
};
|
|
26
26
|
SessionReplayJoinedConfigGenerator.prototype.generateJoinedConfig = function (sessionId) {
|
|
27
27
|
return __awaiter(this, void 0, void 0, function () {
|
|
28
|
-
var config,
|
|
29
|
-
return __generator(this, function (
|
|
30
|
-
switch (
|
|
28
|
+
var config, remoteConfig, samplingConfig_1, privacyConfig_1, err_1, knownError, samplingConfig, privacyConfig, key, k;
|
|
29
|
+
return __generator(this, function (_a) {
|
|
30
|
+
switch (_a.label) {
|
|
31
31
|
case 0:
|
|
32
32
|
config = __assign({}, this.localConfig);
|
|
33
33
|
// Special case here as optOut is implemented via getter/setter
|
|
34
34
|
config.optOut = this.localConfig.optOut;
|
|
35
|
-
|
|
35
|
+
// We always want captureEnabled to be true, unless there's an override
|
|
36
|
+
// in the remote config.
|
|
37
|
+
config.captureEnabled = true;
|
|
38
|
+
_a.label = 1;
|
|
36
39
|
case 1:
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
_a.trys.push([1, 4, , 5]);
|
|
41
|
+
if (!this.remoteConfigFetch) {
|
|
42
|
+
return [2 /*return*/, config];
|
|
43
|
+
}
|
|
40
44
|
return [4 /*yield*/, this.remoteConfigFetch.getRemoteConfig('sessionReplay', 'sr_sampling_config', sessionId)];
|
|
41
45
|
case 2:
|
|
42
|
-
|
|
43
|
-
|
|
46
|
+
samplingConfig_1 = _a.sent();
|
|
47
|
+
return [4 /*yield*/, this.remoteConfigFetch.getRemoteConfig('sessionReplay', 'sr_privacy_config', sessionId)];
|
|
44
48
|
case 3:
|
|
45
|
-
|
|
49
|
+
privacyConfig_1 = _a.sent();
|
|
50
|
+
if (samplingConfig_1 || privacyConfig_1) {
|
|
51
|
+
remoteConfig = {};
|
|
52
|
+
if (samplingConfig_1) {
|
|
53
|
+
remoteConfig.sr_sampling_config = samplingConfig_1;
|
|
54
|
+
}
|
|
55
|
+
if (privacyConfig_1) {
|
|
56
|
+
remoteConfig.sr_privacy_config = privacyConfig_1;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return [3 /*break*/, 5];
|
|
60
|
+
case 4:
|
|
61
|
+
err_1 = _a.sent();
|
|
62
|
+
knownError = err_1;
|
|
63
|
+
this.localConfig.loggerProvider.warn(knownError.message);
|
|
64
|
+
config.captureEnabled = true;
|
|
65
|
+
return [3 /*break*/, 5];
|
|
66
|
+
case 5:
|
|
67
|
+
if (!remoteConfig) {
|
|
68
|
+
return [2 /*return*/, config];
|
|
69
|
+
}
|
|
70
|
+
samplingConfig = remoteConfig.sr_sampling_config, privacyConfig = remoteConfig.sr_privacy_config;
|
|
46
71
|
if (samplingConfig && Object.keys(samplingConfig).length > 0) {
|
|
47
72
|
if (Object.prototype.hasOwnProperty.call(samplingConfig, 'capture_enabled')) {
|
|
48
73
|
config.captureEnabled = samplingConfig.capture_enabled;
|
|
@@ -59,15 +84,19 @@ var SessionReplayJoinedConfigGenerator = /** @class */ (function () {
|
|
|
59
84
|
// customer has not yet set up config, and use sample rate from SDK options,
|
|
60
85
|
// allowing for immediate replay capture
|
|
61
86
|
config.captureEnabled = true;
|
|
87
|
+
this.localConfig.loggerProvider.debug('Remote config successfully fetched, but no values set for project, Session Replay capture enabled.');
|
|
62
88
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
89
|
+
// Override all keys in the local config with the remote privacy config.
|
|
90
|
+
if (privacyConfig && Object.keys(privacyConfig).length > 0) {
|
|
91
|
+
if (!config.privacyConfig) {
|
|
92
|
+
config.privacyConfig = {};
|
|
93
|
+
}
|
|
94
|
+
for (key in privacyConfig) {
|
|
95
|
+
k = key;
|
|
96
|
+
config.privacyConfig[k] = privacyConfig[k];
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return [2 /*return*/, config];
|
|
71
100
|
}
|
|
72
101
|
});
|
|
73
102
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"joined-config.js","sourceRoot":"","sources":["../../../src/config/joined-config.ts"],"names":[],"mappings":";AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"joined-config.js","sourceRoot":"","sources":["../../../src/config/joined-config.ts"],"names":[],"mappings":";AAAA,OAAO,EAAqB,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAEhG,OAAO,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAQ1D;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;wBACxC,uEAAuE;wBACvE,wBAAwB;wBACxB,MAAM,CAAC,cAAc,GAAG,IAAI,CAAC;;;;wBAG3B,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE;4BAC3B,sBAAO,MAAM,EAAC;yBACf;wBAEsB,qBAAM,IAAI,CAAC,iBAAiB,CAAC,eAAe,CACjE,eAAe,EACf,oBAAoB,EACpB,SAAS,CACV,EAAA;;wBAJK,mBAAiB,SAItB;wBAEqB,qBAAM,IAAI,CAAC,iBAAiB,CAAC,eAAe,CAChE,eAAe,EACf,mBAAmB,EACnB,SAAS,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C,aAAa,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;4BAC1D,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE;gCACzB,MAAM,CAAC,aAAa,GAAG,EAAE,CAAC;6BAC3B;4BAED,KAAW,GAAG,IAAI,aAAa,EAAE;gCACzB,CAAC,GAAG,GAA0B,CAAC;gCACrC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;6BAC5C;yBACF;wBAED,sBAAO,MAAM,EAAC;;;;KACf;IACH,yCAAC;AAAD,CAAC,AA9FD,IA8FC;;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 { RemoteConfigFetch, createRemoteConfigFetch } from '@amplitude/analytics-remote-config';\nimport { SessionReplayOptions } from '../typings/session-replay';\nimport { SessionReplayLocalConfig } from './local-config';\nimport {\n SessionReplayLocalConfig as ISessionReplayLocalConfig,\n SessionReplayJoinedConfig,\n PrivacyConfig,\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): Promise<SessionReplayJoinedConfig> {\n const config: SessionReplayJoinedConfig = { ...this.localConfig };\n // Special case here as optOut is implemented via getter/setter\n config.optOut = this.localConfig.optOut;\n // We always want captureEnabled to be true, unless there's an override\n // in the remote config.\n config.captureEnabled = true;\n let remoteConfig: SessionReplayRemoteConfig | undefined;\n try {\n if (!this.remoteConfigFetch) {\n return config;\n }\n\n const samplingConfig = await this.remoteConfigFetch.getRemoteConfig(\n 'sessionReplay',\n 'sr_sampling_config',\n sessionId,\n );\n\n const privacyConfig = await this.remoteConfigFetch.getRemoteConfig(\n 'sessionReplay',\n 'sr_privacy_config',\n sessionId,\n );\n\n if (samplingConfig || privacyConfig) {\n remoteConfig = {};\n if (samplingConfig) {\n remoteConfig.sr_sampling_config = samplingConfig;\n }\n if (privacyConfig) {\n remoteConfig.sr_privacy_config = privacyConfig;\n }\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 if (!remoteConfig) {\n return config;\n }\n\n const { sr_sampling_config: samplingConfig, sr_privacy_config: privacyConfig } = remoteConfig;\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 this.localConfig.loggerProvider.debug(\n 'Remote config successfully fetched, but no values set for project, Session Replay capture enabled.',\n );\n }\n\n // Override all keys in the local config with the remote privacy config.\n if (privacyConfig && Object.keys(privacyConfig).length > 0) {\n if (!config.privacyConfig) {\n config.privacyConfig = {};\n }\n\n for (const key in privacyConfig) {\n const k = key as keyof PrivacyConfig;\n config.privacyConfig[k] = privacyConfig[k];\n }\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"]}
|
|
@@ -2,7 +2,7 @@ import { FetchTransport } from '@amplitude/analytics-client-common';
|
|
|
2
2
|
import { Config, Logger } from '@amplitude/analytics-core';
|
|
3
3
|
import { LogLevel } from '@amplitude/analytics-types';
|
|
4
4
|
import { SessionReplayOptions } from '../typings/session-replay';
|
|
5
|
-
import { SessionReplayLocalConfig as ISessionReplayLocalConfig,
|
|
5
|
+
import { SessionReplayLocalConfig as ISessionReplayLocalConfig, PrivacyConfig } from './types';
|
|
6
6
|
export declare const getDefaultConfig: () => {
|
|
7
7
|
flushMaxRetries: number;
|
|
8
8
|
logLevel: LogLevel;
|
|
@@ -12,8 +12,9 @@ export declare const getDefaultConfig: () => {
|
|
|
12
12
|
export declare class SessionReplayLocalConfig extends Config implements ISessionReplayLocalConfig {
|
|
13
13
|
apiKey: string;
|
|
14
14
|
sampleRate: number;
|
|
15
|
-
privacyConfig?:
|
|
15
|
+
privacyConfig?: PrivacyConfig;
|
|
16
16
|
debugMode?: boolean;
|
|
17
|
+
configEndpointUrl?: string;
|
|
17
18
|
constructor(apiKey: string, options: SessionReplayOptions);
|
|
18
19
|
}
|
|
19
20
|
//# sourceMappingURL=local-config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local-config.d.ts","sourceRoot":"","sources":["../../../src/config/local-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAEtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,wBAAwB,IAAI,yBAAyB,EAAE,
|
|
1
|
+
{"version":3,"file":"local-config.d.ts","sourceRoot":"","sources":["../../../src/config/local-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAEtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,wBAAwB,IAAI,yBAAyB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE/F,eAAO,MAAM,gBAAgB;;;;;CAK3B,CAAC;AAEH,qBAAa,wBAAyB,SAAQ,MAAO,YAAW,yBAAyB;IACvF,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,iBAAiB,CAAC,EAAE,MAAM,CAAC;gBAEf,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,oBAAoB;CAwB1D"}
|
|
@@ -22,6 +22,7 @@ var SessionReplayLocalConfig = /** @class */ (function (_super) {
|
|
|
22
22
|
_this.apiKey = apiKey;
|
|
23
23
|
_this.sampleRate = options.sampleRate || DEFAULT_SAMPLE_RATE;
|
|
24
24
|
_this.serverZone = options.serverZone || DEFAULT_SERVER_ZONE;
|
|
25
|
+
_this.configEndpointUrl = options.configEndpointUrl;
|
|
25
26
|
if (options.privacyConfig) {
|
|
26
27
|
_this.privacyConfig = options.privacyConfig;
|
|
27
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local-config.js","sourceRoot":"","sources":["../../../src/config/local-config.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE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ACzB,CAAC,CAAC,aAAa,CAAC,eAAe,CAAC;QAEpC,KAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,KAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,mBAAmB,CAAC;QAC5D,KAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,mBAAmB,CAAC;QAC5D,KAAI,CAAC,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC;QAEnD,IAAI,OAAO,CAAC,aAAa,EAAE;YACzB,KAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;SAC5C;QACD,IAAI,OAAO,CAAC,SAAS,EAAE;YACrB,KAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;SACpC;;IACH,CAAC;IACH,+BAAC;AAAD,CAAC,AA/BD,CAA8C,MAAM,GA+BnD","sourcesContent":["import { FetchTransport } from '@amplitude/analytics-client-common';\nimport { Config, Logger } from '@amplitude/analytics-core';\nimport { LogLevel } from '@amplitude/analytics-types';\nimport { DEFAULT_SAMPLE_RATE, DEFAULT_SERVER_ZONE } from '../constants';\nimport { SessionReplayOptions } from '../typings/session-replay';\nimport { SessionReplayLocalConfig as ISessionReplayLocalConfig, PrivacyConfig } from './types';\n\nexport const getDefaultConfig = () => ({\n flushMaxRetries: 2,\n logLevel: LogLevel.Warn,\n loggerProvider: new Logger(),\n transportProvider: new FetchTransport(),\n});\n\nexport class SessionReplayLocalConfig extends Config implements ISessionReplayLocalConfig {\n apiKey: string;\n sampleRate: number;\n privacyConfig?: PrivacyConfig;\n debugMode?: boolean;\n configEndpointUrl?: string;\n\n constructor(apiKey: string, options: SessionReplayOptions) {\n const defaultConfig = getDefaultConfig();\n super({\n transportProvider: defaultConfig.transportProvider,\n ...options,\n apiKey,\n });\n this.flushMaxRetries =\n options.flushMaxRetries !== undefined && options.flushMaxRetries <= defaultConfig.flushMaxRetries\n ? options.flushMaxRetries\n : defaultConfig.flushMaxRetries;\n\n this.apiKey = apiKey;\n this.sampleRate = options.sampleRate || DEFAULT_SAMPLE_RATE;\n this.serverZone = options.serverZone || DEFAULT_SERVER_ZONE;\n this.configEndpointUrl = options.configEndpointUrl;\n\n if (options.privacyConfig) {\n this.privacyConfig = options.privacyConfig;\n }\n if (options.debugMode) {\n this.debugMode = options.debugMode;\n }\n }\n}\n"]}
|
|
@@ -1,26 +1,29 @@
|
|
|
1
1
|
import { Config, LogLevel, Logger } from '@amplitude/analytics-types';
|
|
2
|
+
export interface SamplingConfig {
|
|
3
|
+
sample_rate: number;
|
|
4
|
+
capture_enabled: boolean;
|
|
5
|
+
}
|
|
2
6
|
export type SessionReplayRemoteConfig = {
|
|
3
|
-
sr_sampling_config
|
|
4
|
-
|
|
5
|
-
capture_enabled: boolean;
|
|
6
|
-
};
|
|
7
|
+
sr_sampling_config?: SamplingConfig;
|
|
8
|
+
sr_privacy_config?: PrivacyConfig;
|
|
7
9
|
};
|
|
8
10
|
export interface SessionReplayRemoteConfigAPIResponse {
|
|
9
11
|
configs: {
|
|
10
12
|
sessionReplay: SessionReplayRemoteConfig;
|
|
11
13
|
};
|
|
12
14
|
}
|
|
13
|
-
export
|
|
15
|
+
export type PrivacyConfig = {
|
|
14
16
|
blockSelector?: string | string[];
|
|
15
|
-
}
|
|
17
|
+
};
|
|
16
18
|
export interface SessionReplayLocalConfig extends Config {
|
|
17
19
|
apiKey: string;
|
|
18
20
|
loggerProvider: Logger;
|
|
19
21
|
logLevel: LogLevel;
|
|
20
22
|
flushMaxRetries: number;
|
|
21
23
|
sampleRate: number;
|
|
22
|
-
privacyConfig?:
|
|
24
|
+
privacyConfig?: PrivacyConfig;
|
|
23
25
|
debugMode?: boolean;
|
|
26
|
+
configEndpointUrl?: string;
|
|
24
27
|
}
|
|
25
28
|
export interface SessionReplayJoinedConfig extends SessionReplayLocalConfig {
|
|
26
29
|
captureEnabled?: boolean;
|
|
@@ -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,MAAM,yBAAyB,GAAG;IACtC,kBAAkB,
|
|
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;AAED,MAAM,MAAM,yBAAyB,GAAG;IACtC,kBAAkB,CAAC,EAAE,cAAc,CAAC;IACpC,iBAAiB,CAAC,EAAE,aAAa,CAAC;CACnC,CAAC;AAEF,MAAM,WAAW,oCAAoC;IACnD,OAAO,EAAE;QACP,aAAa,EAAE,yBAAyB,CAAC;KAC1C,CAAC;CACH;AAED,MAAM,MAAM,aAAa,GAAG;IAC1B,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CACnC,CAAC;AAEF,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,aAAa,CAAC;IAC9B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,yBAA0B,SAAQ,wBAAwB;IACzE,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,8BAA8B;IAC7C,YAAY,EAAE,MAAM,IAAI,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
|
|
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}\n\nexport type SessionReplayRemoteConfig = {\n sr_sampling_config?: SamplingConfig;\n sr_privacy_config?: PrivacyConfig;\n};\n\nexport interface SessionReplayRemoteConfigAPIResponse {\n configs: {\n sessionReplay: SessionReplayRemoteConfig;\n };\n}\n\nexport type PrivacyConfig = {\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?: PrivacyConfig;\n debugMode?: boolean;\n configEndpointUrl?: string;\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"]}
|