@amplitude/session-replay-dom-privacy 0.0.1 → 0.2.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/LICENSE +21 -0
- package/README.md +34 -0
- package/lib/cjs/get-input-type.d.ts +9 -0
- package/lib/cjs/get-input-type.d.ts.map +1 -0
- package/lib/cjs/get-input-type.js +25 -0
- package/lib/cjs/get-input-type.js.map +1 -0
- package/lib/cjs/index.d.ts +7 -0
- package/lib/cjs/index.d.ts.map +1 -0
- package/lib/cjs/index.js +14 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/policy.d.ts +17 -0
- package/lib/cjs/policy.d.ts.map +1 -0
- package/lib/cjs/policy.js +125 -0
- package/lib/cjs/policy.js.map +1 -0
- package/lib/cjs/recorder-options.d.ts +15 -0
- package/lib/cjs/recorder-options.d.ts.map +1 -0
- package/lib/cjs/recorder-options.js +40 -0
- package/lib/cjs/recorder-options.js.map +1 -0
- package/lib/cjs/types.d.ts +26 -0
- package/lib/cjs/types.d.ts.map +1 -0
- package/lib/cjs/types.js +5 -0
- package/lib/cjs/types.js.map +1 -0
- package/lib/cjs/url.d.ts +2 -0
- package/lib/cjs/url.d.ts.map +1 -0
- package/lib/cjs/url.js +45 -0
- package/lib/cjs/url.js.map +1 -0
- package/lib/cjs/validation.d.ts +6 -0
- package/lib/cjs/validation.d.ts.map +1 -0
- package/lib/cjs/validation.js +95 -0
- package/lib/cjs/validation.js.map +1 -0
- package/lib/esm/get-input-type.d.ts +9 -0
- package/lib/esm/get-input-type.d.ts.map +1 -0
- package/lib/esm/get-input-type.js +20 -0
- package/lib/esm/get-input-type.js.map +1 -0
- package/lib/esm/index.d.ts +7 -0
- package/lib/esm/index.d.ts.map +1 -0
- package/lib/esm/index.js +7 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/policy.d.ts +17 -0
- package/lib/esm/policy.d.ts.map +1 -0
- package/lib/esm/policy.js +118 -0
- package/lib/esm/policy.js.map +1 -0
- package/lib/esm/recorder-options.d.ts +15 -0
- package/lib/esm/recorder-options.d.ts.map +1 -0
- package/lib/esm/recorder-options.js +34 -0
- package/lib/esm/recorder-options.js.map +1 -0
- package/lib/esm/types.d.ts +26 -0
- package/lib/esm/types.d.ts.map +1 -0
- package/lib/esm/types.js +2 -0
- package/lib/esm/types.js.map +1 -0
- package/lib/esm/url.d.ts +2 -0
- package/lib/esm/url.d.ts.map +1 -0
- package/lib/esm/url.js +41 -0
- package/lib/esm/url.js.map +1 -0
- package/lib/esm/validation.d.ts +6 -0
- package/lib/esm/validation.d.ts.map +1 -0
- package/lib/esm/validation.js +90 -0
- package/lib/esm/validation.js.map +1 -0
- package/package.json +27 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Amplitude Analytics
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Session Replay DOM privacy
|
|
2
|
+
|
|
3
|
+
Shared privacy schema, DOM policy evaluation, URL matching, validation and rrweb
|
|
4
|
+
privacy options for browser replay and native WebView recorders. This package has
|
|
5
|
+
no recorder, analytics, transport, storage or remote-config client dependency.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { parsePrivacyConfig, createPrivacyRecorderOptions } from '@amplitude/session-replay-dom-privacy';
|
|
9
|
+
|
|
10
|
+
const fragment = document.createDocumentFragment();
|
|
11
|
+
const policy = parsePrivacyConfig(remotePolicy, selector => { fragment.querySelector(selector); });
|
|
12
|
+
const options = createPrivacyRecorderOptions(policy, () => location.href);
|
|
13
|
+
// record({ ...options, emit });
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
`parsePrivacyConfig` rejects malformed known fields and invalid selectors. Unknown
|
|
17
|
+
fields are ignored for forward compatibility. On validation failure, the host must
|
|
18
|
+
not start recording. Missing remote configuration is a host lifecycle decision;
|
|
19
|
+
passing an empty policy explicitly selects the default medium mask level.
|
|
20
|
+
|
|
21
|
+
`data-amp-block`, `data-amp-mask`, and `data-amp-unmask` always work alongside
|
|
22
|
+
`amp-block`, `amp-mask`, and `amp-unmask` classes. Attribute presence is what
|
|
23
|
+
matters, including a value of `false`. Explicit masking on an element or ancestor wins over unmasking.
|
|
24
|
+
Blocking excludes the subtree regardless of unmasking annotations.
|
|
25
|
+
|
|
26
|
+
The host resolves local/remote precedence, observes navigation and owns recorder
|
|
27
|
+
lifecycle. Supply the current URL to callbacks. On policy replacement, stop the
|
|
28
|
+
old recorder and start a new one with a fresh baseline before accepting events;
|
|
29
|
+
already emitted content cannot be retroactively redacted. This package does not
|
|
30
|
+
implement native bridges or recorder lifecycle.
|
|
31
|
+
|
|
32
|
+
Browser retains its legacy invalid-selector warning/drop behavior using
|
|
33
|
+
`validatePrivacySelectors` with an explicit error callback. New remote-only
|
|
34
|
+
consumers should use the strict parser.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare function toLowerCase<T extends string>(str: T): Lowercase<T>;
|
|
2
|
+
/**
|
|
3
|
+
* Get the type of an input element.
|
|
4
|
+
* This takes care of the case where a password input is changed to a text input.
|
|
5
|
+
* In this case, we continue to consider this of type password, in order to avoid leaking sensitive data
|
|
6
|
+
* where passwords should be masked.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getInputType(element: HTMLElement): Lowercase<string> | null;
|
|
9
|
+
//# sourceMappingURL=get-input-type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-input-type.d.ts","sourceRoot":"","sources":["../../src/get-input-type.ts"],"names":[],"mappings":"AAAA,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAElE;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,WAAW,GAAG,SAAS,CAAC,MAAM,CAAC,GAAG,IAAI,CAU3E"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getInputType = exports.toLowerCase = void 0;
|
|
4
|
+
function toLowerCase(str) {
|
|
5
|
+
return str.toLowerCase();
|
|
6
|
+
}
|
|
7
|
+
exports.toLowerCase = toLowerCase;
|
|
8
|
+
/**
|
|
9
|
+
* Get the type of an input element.
|
|
10
|
+
* This takes care of the case where a password input is changed to a text input.
|
|
11
|
+
* In this case, we continue to consider this of type password, in order to avoid leaking sensitive data
|
|
12
|
+
* where passwords should be masked.
|
|
13
|
+
*/
|
|
14
|
+
function getInputType(element) {
|
|
15
|
+
// when omitting the type of input element(e.g. <input />), the type is treated as text
|
|
16
|
+
var type = element.type;
|
|
17
|
+
return element.hasAttribute('data-rr-is-password')
|
|
18
|
+
? 'password'
|
|
19
|
+
: type
|
|
20
|
+
? // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
21
|
+
toLowerCase(type)
|
|
22
|
+
: null;
|
|
23
|
+
}
|
|
24
|
+
exports.getInputType = getInputType;
|
|
25
|
+
//# sourceMappingURL=get-input-type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-input-type.js","sourceRoot":"","sources":["../../src/get-input-type.ts"],"names":[],"mappings":";;;AAAA,SAAgB,WAAW,CAAmB,GAAM;IAClD,OAAO,GAAG,CAAC,WAAW,EAA6B,CAAC;AACtD,CAAC;AAFD,kCAEC;AAED;;;;;GAKG;AACH,SAAgB,YAAY,CAAC,OAAoB;IAC/C,uFAAuF;IACvF,IAAM,IAAI,GAAI,OAA4B,CAAC,IAAI,CAAC;IAEhD,OAAO,OAAO,CAAC,YAAY,CAAC,qBAAqB,CAAC;QAChD,CAAC,CAAC,UAAU;QACZ,CAAC,CAAC,IAAI;YACN,CAAC,CAAC,4EAA4E;gBAC5E,WAAW,CAAC,IAAI,CAAC;YACnB,CAAC,CAAC,IAAI,CAAC;AACX,CAAC;AAVD,oCAUC","sourcesContent":["export function toLowerCase<T extends string>(str: T): Lowercase<T> {\n return str.toLowerCase() as unknown as Lowercase<T>;\n}\n\n/**\n * Get the type of an input element.\n * This takes care of the case where a password input is changed to a text input.\n * In this case, we continue to consider this of type password, in order to avoid leaking sensitive data\n * where passwords should be masked.\n */\nexport function getInputType(element: HTMLElement): Lowercase<string> | null {\n // when omitting the type of input element(e.g. <input />), the type is treated as text\n const type = (element as HTMLInputElement).type;\n\n return element.hasAttribute('data-rr-is-password')\n ? 'password'\n : type\n ? // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n toLowerCase(type)\n : null;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC"}
|
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toLowerCase = exports.getInputType = exports.globToRegex = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
tslib_1.__exportStar(require("./types"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./policy"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./recorder-options"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./validation"), exports);
|
|
9
|
+
var url_1 = require("./url");
|
|
10
|
+
Object.defineProperty(exports, "globToRegex", { enumerable: true, get: function () { return url_1.globToRegex; } });
|
|
11
|
+
var get_input_type_1 = require("./get-input-type");
|
|
12
|
+
Object.defineProperty(exports, "getInputType", { enumerable: true, get: function () { return get_input_type_1.getInputType; } });
|
|
13
|
+
Object.defineProperty(exports, "toLowerCase", { enumerable: true, get: function () { return get_input_type_1.toLowerCase; } });
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;AAAA,kDAAwB;AACxB,mDAAyB;AACzB,6DAAmC;AACnC,uDAA6B;AAC7B,6BAAoC;AAA3B,kGAAA,WAAW,OAAA;AACpB,mDAA6D;AAApD,8GAAA,YAAY,OAAA;AAAE,6GAAA,WAAW,OAAA","sourcesContent":["export * from './types';\nexport * from './policy';\nexport * from './recorder-options';\nexport * from './validation';\nexport { globToRegex } from './url';\nexport { getInputType, toLowerCase } from './get-input-type';\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { MaskLevel, PrivacyConfig } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Returns the effective mask level for a given URL by checking `urlMaskLevels`
|
|
4
|
+
* (first match wins) and falling back to `defaultMaskLevel`.
|
|
5
|
+
*/
|
|
6
|
+
export declare const getEffectiveMaskLevel: (url: string | undefined, config: PrivacyConfig) => MaskLevel;
|
|
7
|
+
/**
|
|
8
|
+
* Checks if the given element set to be masked by rrweb
|
|
9
|
+
*
|
|
10
|
+
* Priority is:
|
|
11
|
+
* 1. [In code] Element/class based masking/unmasking <> [Config based] Selector based masking/unmasking
|
|
12
|
+
* 2. Use app defaults
|
|
13
|
+
*/
|
|
14
|
+
export declare const isMasked: (elementType: 'input' | 'text', config: PrivacyConfig | undefined, element: HTMLElement | null, currentUrl?: string) => boolean;
|
|
15
|
+
export declare const maskFn: (elementType: 'text' | 'input', config?: PrivacyConfig, getCurrentUrl?: () => string) => (text: string, element: HTMLElement | null) => string;
|
|
16
|
+
export declare const maskAttributeFn: (config?: PrivacyConfig, getCurrentUrl?: () => string) => (key: string, value: string, element: HTMLElement) => string;
|
|
17
|
+
//# sourceMappingURL=policy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../../src/policy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAyCvE;;;GAGG;AACH,eAAO,MAAM,qBAAqB,QAAS,MAAM,GAAG,SAAS,UAAU,aAAa,KAAG,SAStF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,gBACN,OAAO,GAAG,MAAM,8CAEpB,WAAW,GAAG,IAAI,eACd,MAAM,KAClB,OA2BF,CAAC;AAEF,eAAO,MAAM,MAAM,gBACH,MAAM,GAAG,OAAO,WAAW,aAAa,kBAAkB,MAAM,MAAM,YAC7E,MAAM,WAAW,WAAW,GAAG,IAAI,KAAG,MAE5C,CAAC;AAEJ,eAAO,MAAM,eAAe,YAAa,aAAa,kBAAkB,MAAM,MAAM,WACrE,MAAM,SAAS,MAAM,WAAW,WAAW,KAAG,MAc5D,CAAC"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.maskAttributeFn = exports.maskFn = exports.isMasked = exports.getEffectiveMaskLevel = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var types_1 = require("./types");
|
|
6
|
+
var get_input_type_1 = require("./get-input-type");
|
|
7
|
+
var url_1 = require("./url");
|
|
8
|
+
/**
|
|
9
|
+
* Light: Subset of inputs (sensitive types only — password, hidden, email, tel, cc-*)
|
|
10
|
+
* Medium: All inputs (form fields), text is NOT masked
|
|
11
|
+
* Conservative: All inputs and all texts
|
|
12
|
+
*/
|
|
13
|
+
var isMaskedForLevel = function (elementType, level, element) {
|
|
14
|
+
switch (level) {
|
|
15
|
+
case 'light': {
|
|
16
|
+
if (elementType !== 'input') {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
var inputType = element ? (0, get_input_type_1.getInputType)(element) : '';
|
|
20
|
+
/* istanbul ignore if */ // TODO(lew): For some reason it's impossible to test this.
|
|
21
|
+
if (!inputType) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
if (['password', 'hidden', 'email', 'tel'].includes(inputType)) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
if (element.autocomplete.startsWith('cc-')) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
case 'medium':
|
|
33
|
+
return elementType === 'input';
|
|
34
|
+
case 'conservative':
|
|
35
|
+
return true;
|
|
36
|
+
default:
|
|
37
|
+
return isMaskedForLevel(elementType, types_1.DEFAULT_MASK_LEVEL, element);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Returns the effective mask level for a given URL by checking `urlMaskLevels`
|
|
42
|
+
* (first match wins) and falling back to `defaultMaskLevel`.
|
|
43
|
+
*/
|
|
44
|
+
var getEffectiveMaskLevel = function (url, config) {
|
|
45
|
+
var e_1, _a;
|
|
46
|
+
var _b;
|
|
47
|
+
if (url && config.urlMaskLevels) {
|
|
48
|
+
try {
|
|
49
|
+
for (var _c = tslib_1.__values(config.urlMaskLevels), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
50
|
+
var rule = _d.value;
|
|
51
|
+
if ((0, url_1.globToRegex)(rule.match).test(url)) {
|
|
52
|
+
return rule.maskLevel;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
57
|
+
finally {
|
|
58
|
+
try {
|
|
59
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
60
|
+
}
|
|
61
|
+
finally { if (e_1) throw e_1.error; }
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return (_b = config.defaultMaskLevel) !== null && _b !== void 0 ? _b : types_1.DEFAULT_MASK_LEVEL;
|
|
65
|
+
};
|
|
66
|
+
exports.getEffectiveMaskLevel = getEffectiveMaskLevel;
|
|
67
|
+
/**
|
|
68
|
+
* Checks if the given element set to be masked by rrweb
|
|
69
|
+
*
|
|
70
|
+
* Priority is:
|
|
71
|
+
* 1. [In code] Element/class based masking/unmasking <> [Config based] Selector based masking/unmasking
|
|
72
|
+
* 2. Use app defaults
|
|
73
|
+
*/
|
|
74
|
+
var isMasked = function (elementType, config, element, currentUrl) {
|
|
75
|
+
var _a, _b;
|
|
76
|
+
if (config === void 0) { config = { defaultMaskLevel: types_1.DEFAULT_MASK_LEVEL }; }
|
|
77
|
+
if (element) {
|
|
78
|
+
// Element or parent is explicitly instrumented in code to mask
|
|
79
|
+
if (element.closest('.amp-mask, [data-amp-mask]')) {
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
// Config has override for mask
|
|
83
|
+
var shouldMask = ((_a = config.maskSelector) !== null && _a !== void 0 ? _a : []).some(function (selector) { return element.closest(selector); });
|
|
84
|
+
if (shouldMask) {
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
// Code or config has override to unmask
|
|
88
|
+
if (element.closest('.amp-unmask, [data-amp-unmask]')) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
// Here we are probably sent an element, but we want to match if they have a
|
|
92
|
+
// parent with an unmask selector.
|
|
93
|
+
var shouldUnmask = ((_b = config.unmaskSelector) !== null && _b !== void 0 ? _b : []).some(function (selector) { return element.closest(selector); });
|
|
94
|
+
if (shouldUnmask) {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return isMaskedForLevel(elementType, (0, exports.getEffectiveMaskLevel)(currentUrl, config), element);
|
|
99
|
+
};
|
|
100
|
+
exports.isMasked = isMasked;
|
|
101
|
+
var maskFn = function (elementType, config, getCurrentUrl) {
|
|
102
|
+
return function (text, element) {
|
|
103
|
+
return (0, exports.isMasked)(elementType, config, element, getCurrentUrl === null || getCurrentUrl === void 0 ? void 0 : getCurrentUrl()) ? text.replace(/[^\s]/g, '*') : text;
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
exports.maskFn = maskFn;
|
|
107
|
+
var maskAttributeFn = function (config, getCurrentUrl) {
|
|
108
|
+
return function (key, value, element) {
|
|
109
|
+
var _a;
|
|
110
|
+
// Never mask style — rrweb has a separate styleDiff path for attribute mutations
|
|
111
|
+
// that reads directly from the DOM, bypassing maskAttributeFn.
|
|
112
|
+
if (key === 'style')
|
|
113
|
+
return value;
|
|
114
|
+
// Short-circuit: only proceed if this attribute is in the allowlist.
|
|
115
|
+
if (!((_a = config === null || config === void 0 ? void 0 : config.maskAttributes) !== null && _a !== void 0 ? _a : []).includes(key))
|
|
116
|
+
return value;
|
|
117
|
+
// Use 'input' for form elements so that `medium` (which masks inputs but not text)
|
|
118
|
+
// still masks attributes on inputs/selects/textareas. For non-form elements, use
|
|
119
|
+
// 'text' so medium leaves them visible.
|
|
120
|
+
var elementType = ['INPUT', 'SELECT', 'TEXTAREA'].includes(element.tagName) ? 'input' : 'text';
|
|
121
|
+
return (0, exports.isMasked)(elementType, config, element, getCurrentUrl === null || getCurrentUrl === void 0 ? void 0 : getCurrentUrl()) ? value.replace(/[^\s]/g, '*') : value;
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
exports.maskAttributeFn = maskAttributeFn;
|
|
125
|
+
//# sourceMappingURL=policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy.js","sourceRoot":"","sources":["../../src/policy.ts"],"names":[],"mappings":";;;;AAAA,iCAAuE;AACvE,mDAAgD;AAChD,6BAAoC;AAEpC;;;;GAIG;AACH,IAAM,gBAAgB,GAAG,UAAC,WAA6B,EAAE,KAAgB,EAAE,OAA2B;IACpG,QAAQ,KAAK,EAAE;QACb,KAAK,OAAO,CAAC,CAAC;YACZ,IAAI,WAAW,KAAK,OAAO,EAAE;gBAC3B,OAAO,KAAK,CAAC;aACd;YAED,IAAM,SAAS,GAAG,OAAO,CAAC,CAAC,CAAC,IAAA,6BAAY,EAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YACvD,wBAAwB,CAAC,2DAA2D;YACpF,IAAI,CAAC,SAAS,EAAE;gBACd,OAAO,KAAK,CAAC;aACd;YAED,IAAI,CAAC,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;gBAC9D,OAAO,IAAI,CAAC;aACb;YAED,IAAK,OAA4B,CAAC,YAAY,CAAC,UAAU,CAAC,KAAK,CAA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AAC;YAAE,OAAO,KAAK,CAAC;QAEhE,mFAAmF;QACnF,iFAAiF;QACjF,wCAAwC;QACxC,IAAM,WAAW,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;QACjG,OAAO,IAAA,gBAAQ,EAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,aAAb,aAAa,uBAAb,aAAa,EAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAC1G,CAAC,CAAC;AACJ,CAAC,CAAC;AAfW,QAAA,eAAe,mBAe1B","sourcesContent":["import { DEFAULT_MASK_LEVEL, MaskLevel, PrivacyConfig } from './types';\nimport { getInputType } from './get-input-type';\nimport { globToRegex } from './url';\n\n/**\n * Light: Subset of inputs (sensitive types only — password, hidden, email, tel, cc-*)\n * Medium: All inputs (form fields), text is NOT masked\n * Conservative: All inputs and all texts\n */\nconst isMaskedForLevel = (elementType: 'input' | 'text', level: MaskLevel, element: HTMLElement | null): boolean => {\n switch (level) {\n case 'light': {\n if (elementType !== 'input') {\n return false;\n }\n\n const inputType = element ? getInputType(element) : '';\n /* istanbul ignore if */ // TODO(lew): For some reason it's impossible to test this.\n if (!inputType) {\n return false;\n }\n\n if (['password', 'hidden', 'email', 'tel'].includes(inputType)) {\n return true;\n }\n\n if ((element as HTMLInputElement).autocomplete.startsWith('cc-')) {\n return true;\n }\n\n return false;\n }\n case 'medium':\n return elementType === 'input';\n case 'conservative':\n return true;\n default:\n return isMaskedForLevel(elementType, DEFAULT_MASK_LEVEL, element);\n }\n};\n\n/**\n * Returns the effective mask level for a given URL by checking `urlMaskLevels`\n * (first match wins) and falling back to `defaultMaskLevel`.\n */\nexport const getEffectiveMaskLevel = (url: string | undefined, config: PrivacyConfig): MaskLevel => {\n if (url && config.urlMaskLevels) {\n for (const rule of config.urlMaskLevels) {\n if (globToRegex(rule.match).test(url)) {\n return rule.maskLevel;\n }\n }\n }\n return config.defaultMaskLevel ?? DEFAULT_MASK_LEVEL;\n};\n\n/**\n * Checks if the given element set to be masked by rrweb\n *\n * Priority is:\n * 1. [In code] Element/class based masking/unmasking <> [Config based] Selector based masking/unmasking\n * 2. Use app defaults\n */\nexport const isMasked = (\n elementType: 'input' | 'text',\n config: PrivacyConfig = { defaultMaskLevel: DEFAULT_MASK_LEVEL },\n element: HTMLElement | null,\n currentUrl?: string,\n): boolean => {\n if (element) {\n // Element or parent is explicitly instrumented in code to mask\n if (element.closest('.amp-mask, [data-amp-mask]')) {\n return true;\n }\n\n // Config has override for mask\n const shouldMask = (config.maskSelector ?? []).some((selector) => element.closest(selector));\n if (shouldMask) {\n return true;\n }\n\n // Code or config has override to unmask\n if (element.closest('.amp-unmask, [data-amp-unmask]')) {\n return false;\n }\n\n // Here we are probably sent an element, but we want to match if they have a\n // parent with an unmask selector.\n const shouldUnmask = (config.unmaskSelector ?? []).some((selector) => element.closest(selector));\n if (shouldUnmask) {\n return false;\n }\n }\n\n return isMaskedForLevel(elementType, getEffectiveMaskLevel(currentUrl, config), element);\n};\n\nexport const maskFn =\n (elementType: 'text' | 'input', config?: PrivacyConfig, getCurrentUrl?: () => string) =>\n (text: string, element: HTMLElement | null): string => {\n return isMasked(elementType, config, element, getCurrentUrl?.()) ? text.replace(/[^\\s]/g, '*') : text;\n };\n\nexport const maskAttributeFn = (config?: PrivacyConfig, getCurrentUrl?: () => string) => {\n return (key: string, value: string, element: HTMLElement): string => {\n // Never mask style — rrweb has a separate styleDiff path for attribute mutations\n // that reads directly from the DOM, bypassing maskAttributeFn.\n if (key === 'style') return value;\n\n // Short-circuit: only proceed if this attribute is in the allowlist.\n if (!(config?.maskAttributes ?? []).includes(key)) return value;\n\n // Use 'input' for form elements so that `medium` (which masks inputs but not text)\n // still masks attributes on inputs/selects/textareas. For non-form elements, use\n // 'text' so medium leaves them visible.\n const elementType = ['INPUT', 'SELECT', 'TEXTAREA'].includes(element.tagName) ? 'input' : 'text';\n return isMasked(elementType, config, element, getCurrentUrl?.()) ? value.replace(/[^\\s]/g, '*') : value;\n };\n};\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { PrivacyConfig } from './types';
|
|
2
|
+
export declare const getBlockSelectors: (config?: PrivacyConfig) => string;
|
|
3
|
+
export declare const getMaskTextSelectors: (config?: PrivacyConfig, url?: string) => string;
|
|
4
|
+
/** Lifecycle and URL observation belong to the caller. Replace the recorder when policy changes. */
|
|
5
|
+
export declare const createPrivacyRecorderOptions: (config?: PrivacyConfig, getCurrentUrl?: () => string) => {
|
|
6
|
+
maskAllInputs: boolean;
|
|
7
|
+
maskTextClass: string;
|
|
8
|
+
blockClass: string;
|
|
9
|
+
blockSelector: string;
|
|
10
|
+
maskTextSelector: string;
|
|
11
|
+
maskInputFn: (text: string, element: HTMLElement | null) => string;
|
|
12
|
+
maskTextFn: (text: string, element: HTMLElement | null) => string;
|
|
13
|
+
maskAttributeFn: (key: string, value: string, element: HTMLElement) => string;
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=recorder-options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recorder-options.d.ts","sourceRoot":"","sources":["../../src/recorder-options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGxC,eAAO,MAAM,iBAAiB,YAAa,aAAa,KAAG,MAI1D,CAAC;AAEF,eAAO,MAAM,oBAAoB,YAAa,aAAa,QAAQ,MAAM,KAAG,MAW3E,CAAC;AAEF,oGAAoG;AACpG,eAAO,MAAM,4BAA4B,YAAa,aAAa,kBAAiB,MAAM,MAAM;;;;;;;;;CAY/F,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createPrivacyRecorderOptions = exports.getMaskTextSelectors = exports.getBlockSelectors = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var policy_1 = require("./policy");
|
|
6
|
+
var getBlockSelectors = function (config) {
|
|
7
|
+
var configured = config === null || config === void 0 ? void 0 : config.blockSelector;
|
|
8
|
+
var selectors = typeof configured === 'string' ? (configured ? [configured] : []) : configured !== null && configured !== void 0 ? configured : [];
|
|
9
|
+
return tslib_1.__spreadArray(tslib_1.__spreadArray([], tslib_1.__read(selectors), false), ['[data-amp-block]'], false).join(',');
|
|
10
|
+
};
|
|
11
|
+
exports.getBlockSelectors = getBlockSelectors;
|
|
12
|
+
var getMaskTextSelectors = function (config, url) {
|
|
13
|
+
var _a, _b;
|
|
14
|
+
// rrweb selects which text reaches the callback at recorder startup. Include all
|
|
15
|
+
// text if any route can require conservative masking; callbacks resolve the URL dynamically.
|
|
16
|
+
if (config &&
|
|
17
|
+
((0, policy_1.getEffectiveMaskLevel)(url, config) === 'conservative' ||
|
|
18
|
+
config.defaultMaskLevel === 'conservative' ||
|
|
19
|
+
((_a = config.urlMaskLevels) === null || _a === void 0 ? void 0 : _a.some(function (rule) { return rule.maskLevel === 'conservative'; }))))
|
|
20
|
+
return '*';
|
|
21
|
+
return tslib_1.__spreadArray(tslib_1.__spreadArray([], tslib_1.__read(((_b = config === null || config === void 0 ? void 0 : config.maskSelector) !== null && _b !== void 0 ? _b : [])), false), ['[data-amp-mask]'], false).join(',');
|
|
22
|
+
};
|
|
23
|
+
exports.getMaskTextSelectors = getMaskTextSelectors;
|
|
24
|
+
/** Lifecycle and URL observation belong to the caller. Replace the recorder when policy changes. */
|
|
25
|
+
var createPrivacyRecorderOptions = function (config, getCurrentUrl) {
|
|
26
|
+
if (getCurrentUrl === void 0) { getCurrentUrl = function () { return ''; }; }
|
|
27
|
+
var blockSelector = (0, exports.getBlockSelectors)(config);
|
|
28
|
+
return {
|
|
29
|
+
maskAllInputs: true,
|
|
30
|
+
maskTextClass: 'amp-mask',
|
|
31
|
+
blockClass: 'amp-block',
|
|
32
|
+
blockSelector: blockSelector,
|
|
33
|
+
maskTextSelector: (0, exports.getMaskTextSelectors)(config, getCurrentUrl()),
|
|
34
|
+
maskInputFn: (0, policy_1.maskFn)('input', config, getCurrentUrl),
|
|
35
|
+
maskTextFn: (0, policy_1.maskFn)('text', config, getCurrentUrl),
|
|
36
|
+
maskAttributeFn: (0, policy_1.maskAttributeFn)(config, getCurrentUrl),
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
exports.createPrivacyRecorderOptions = createPrivacyRecorderOptions;
|
|
40
|
+
//# sourceMappingURL=recorder-options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recorder-options.js","sourceRoot":"","sources":["../../src/recorder-options.ts"],"names":[],"mappings":";;;;AACA,mCAA0E;AAEnE,IAAM,iBAAiB,GAAG,UAAC,MAAsB;IACtD,IAAM,UAAU,GAAG,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,aAAa,CAAC;IACzC,IAAM,SAAS,GAAG,OAAO,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,aAAV,UAAU,cAAV,UAAU,GAAI,EAAE,CAAC;IACvG,OAAO,+DAAI,SAAS,YAAE,kBAAkB,UAAE,IAAI,CAAC,GAAG,CAAC,CAAC;AACtD,CAAC,CAAC;AAJW,QAAA,iBAAiB,qBAI5B;AAEK,IAAM,oBAAoB,GAAG,UAAC,MAAsB,EAAE,GAAY;;IACvE,iFAAiF;IACjF,6FAA6F;IAC7F,IACE,MAAM;QACN,CAAC,IAAA,8BAAqB,EAAC,GAAG,EAAE,MAAM,CAAC,KAAK,cAAc;YACpD,MAAM,CAAC,gBAAgB,KAAK,cAAc;aAC1C,MAAA,MAAM,CAAC,aAAa,0CAAE,IAAI,CAAC,UAAC,IAAI,IAAK,OAAA,IAAI,CAAC,SAAS,KAAK,cAAc,EAAjC,CAAiC,CAAC,CAAA,CAAC;QAE1E,OAAO,GAAG,CAAC;IACb,OAAO,+DAAI,CAAC,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,YAAY,mCAAI,EAAE,CAAC,YAAE,iBAAiB,UAAE,IAAI,CAAC,GAAG,CAAC,CAAC;AACxE,CAAC,CAAC;AAXW,QAAA,oBAAoB,wBAW/B;AAEF,oGAAoG;AAC7F,IAAM,4BAA4B,GAAG,UAAC,MAAsB,EAAE,aAAsC;IAAtC,8BAAA,EAAA,8BAAoC,OAAA,EAAE,EAAF,CAAE;IACzG,IAAM,aAAa,GAAG,IAAA,yBAAiB,EAAC,MAAM,CAAC,CAAC;IAChD,OAAO;QACL,aAAa,EAAE,IAAI;QACnB,aAAa,EAAE,UAAU;QACzB,UAAU,EAAE,WAAW;QACvB,aAAa,eAAA;QACb,gBAAgB,EAAE,IAAA,4BAAoB,EAAC,MAAM,EAAE,aAAa,EAAE,CAAC;QAC/D,WAAW,EAAE,IAAA,eAAM,EAAC,OAAO,EAAE,MAAM,EAAE,aAAa,CAAC;QACnD,UAAU,EAAE,IAAA,eAAM,EAAC,MAAM,EAAE,MAAM,EAAE,aAAa,CAAC;QACjD,eAAe,EAAE,IAAA,wBAAe,EAAC,MAAM,EAAE,aAAa,CAAC;KACxD,CAAC;AACJ,CAAC,CAAC;AAZW,QAAA,4BAA4B,gCAYvC","sourcesContent":["import { PrivacyConfig } from './types';\nimport { getEffectiveMaskLevel, maskFn, maskAttributeFn } from './policy';\n\nexport const getBlockSelectors = (config?: PrivacyConfig): string => {\n const configured = config?.blockSelector;\n const selectors = typeof configured === 'string' ? (configured ? [configured] : []) : configured ?? [];\n return [...selectors, '[data-amp-block]'].join(',');\n};\n\nexport const getMaskTextSelectors = (config?: PrivacyConfig, url?: string): string => {\n // rrweb selects which text reaches the callback at recorder startup. Include all\n // text if any route can require conservative masking; callbacks resolve the URL dynamically.\n if (\n config &&\n (getEffectiveMaskLevel(url, config) === 'conservative' ||\n config.defaultMaskLevel === 'conservative' ||\n config.urlMaskLevels?.some((rule) => rule.maskLevel === 'conservative'))\n )\n return '*';\n return [...(config?.maskSelector ?? []), '[data-amp-mask]'].join(',');\n};\n\n/** Lifecycle and URL observation belong to the caller. Replace the recorder when policy changes. */\nexport const createPrivacyRecorderOptions = (config?: PrivacyConfig, getCurrentUrl: () => string = () => '') => {\n const blockSelector = getBlockSelectors(config);\n return {\n maskAllInputs: true,\n maskTextClass: 'amp-mask',\n blockClass: 'amp-block',\n blockSelector,\n maskTextSelector: getMaskTextSelectors(config, getCurrentUrl()),\n maskInputFn: maskFn('input', config, getCurrentUrl),\n maskTextFn: maskFn('text', config, getCurrentUrl),\n maskAttributeFn: maskAttributeFn(config, getCurrentUrl),\n };\n};\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type MaskLevel = 'light' | 'medium' | 'conservative';
|
|
2
|
+
export declare const DEFAULT_MASK_LEVEL = "medium";
|
|
3
|
+
export type PrivacyConfig = {
|
|
4
|
+
blockSelector?: string | string[];
|
|
5
|
+
defaultMaskLevel?: MaskLevel;
|
|
6
|
+
maskSelector?: string[];
|
|
7
|
+
unmaskSelector?: string[];
|
|
8
|
+
maskAttributes?: string[];
|
|
9
|
+
/**
|
|
10
|
+
* Per-URL overrides for `defaultMaskLevel`. Each entry contains a glob pattern (`match`)
|
|
11
|
+
* and a `maskLevel` to apply when the current page URL matches that pattern.
|
|
12
|
+
* Rules are evaluated in order; the first match wins. Remote rules take precedence
|
|
13
|
+
* over local rules (remote entries are prepended before local entries).
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* urlMaskLevels: [
|
|
17
|
+
* { match: 'https://example.com/checkout/*', maskLevel: 'conservative' },
|
|
18
|
+
* { match: 'https://example.com/public/*', maskLevel: 'light' },
|
|
19
|
+
* ]
|
|
20
|
+
*/
|
|
21
|
+
urlMaskLevels?: Array<{
|
|
22
|
+
match: string;
|
|
23
|
+
maskLevel: MaskLevel;
|
|
24
|
+
}>;
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GACjB,OAAO,GACP,QAAQ,GACR,cAAc,CAAC;AAEnB,eAAO,MAAM,kBAAkB,WAAW,CAAC;AAG3C,MAAM,MAAM,aAAa,GAAG;IAC1B,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAClC,gBAAgB,CAAC,EAAE,SAAS,CAAC;IAC7B,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B;;;;;;;;;;;OAWG;IACH,aAAa,CAAC,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,SAAS,CAAA;KAAE,CAAC,CAAC;CAChE,CAAC"}
|
package/lib/cjs/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";;;AAKa,QAAA,kBAAkB,GAAG,QAAQ,CAAC","sourcesContent":["export type MaskLevel =\n | 'light' // only mask a subset of inputs that's deemed sensitive - password, credit card, telephone #, email. These are information we never want to capture.\n | 'medium' // mask all form fields (inputs); page text is captured as-is\n | 'conservative'; // mask all inputs and all texts\n\nexport const DEFAULT_MASK_LEVEL = 'medium';\n\n// err on the side of excluding more\nexport type PrivacyConfig = {\n blockSelector?: string | string[]; // exclude in the UI\n defaultMaskLevel?: MaskLevel;\n maskSelector?: string[];\n unmaskSelector?: string[];\n maskAttributes?: string[]; // HTML attribute names to mask (e.g. [\"placeholder\", \"aria-label\"])\n /**\n * Per-URL overrides for `defaultMaskLevel`. Each entry contains a glob pattern (`match`)\n * and a `maskLevel` to apply when the current page URL matches that pattern.\n * Rules are evaluated in order; the first match wins. Remote rules take precedence\n * over local rules (remote entries are prepended before local entries).\n *\n * @example\n * urlMaskLevels: [\n * { match: 'https://example.com/checkout/*', maskLevel: 'conservative' },\n * { match: 'https://example.com/public/*', maskLevel: 'light' },\n * ]\n */\n urlMaskLevels?: Array<{ match: string; maskLevel: MaskLevel }>;\n};\n"]}
|
package/lib/cjs/url.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../../src/url.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW,SAAU,MAAM,KAAG,MA0C1C,CAAC"}
|
package/lib/cjs/url.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.globToRegex = void 0;
|
|
4
|
+
var globRegexCache = new Map();
|
|
5
|
+
var globToRegex = function (glob) {
|
|
6
|
+
var cached = globRegexCache.get(glob);
|
|
7
|
+
if (cached)
|
|
8
|
+
return cached;
|
|
9
|
+
// Glob → regex conversion. Glob substitution must happen BEFORE regex escaping so that
|
|
10
|
+
// the escaper does not corrupt the glob characters (e.g. turning `/**` into `/\*\*`).
|
|
11
|
+
// Placeholder tokens use null bytes, which are illegal in HTTP URLs and therefore can
|
|
12
|
+
// never collide with real pattern content.
|
|
13
|
+
//
|
|
14
|
+
// Substitution order (most-specific first):
|
|
15
|
+
// trailing /** → (/.*)? — path with or without a trailing slash/subpath
|
|
16
|
+
// middle /**/ → /(.*\/)? — zero-or-more path segments (including zero)
|
|
17
|
+
// bare ** → .* — graceful fallback for ** not adjacent to /
|
|
18
|
+
// single * → .* — any characters (preserves existing behaviour)
|
|
19
|
+
// ? → . — single character wildcard
|
|
20
|
+
var T_TRAILING = '\x00TRAIL\x00';
|
|
21
|
+
var T_MIDDLE = '\x00MID\x00';
|
|
22
|
+
var T_DSTAR = '\x00DS\x00';
|
|
23
|
+
var T_STAR = '\x00ST\x00';
|
|
24
|
+
var T_QUEST = '\x00QU\x00';
|
|
25
|
+
var s = glob;
|
|
26
|
+
s = s.replace(/\/\*\*$/, T_TRAILING); // trailing /**
|
|
27
|
+
s = s.replace(/\/\*\*\//g, T_MIDDLE); // /**/ in the middle
|
|
28
|
+
s = s.replace(/\*\*/g, T_DSTAR); // bare ** (e.g. **.example.com)
|
|
29
|
+
s = s.replace(/\*/g, T_STAR); // single *
|
|
30
|
+
s = s.replace(/\?/g, T_QUEST); // ?
|
|
31
|
+
// Escape all remaining regex special characters.
|
|
32
|
+
s = s.replace(/[.+^${}()|[\]\\]/g, '\\$&');
|
|
33
|
+
// Expand tokens into their regex equivalents.
|
|
34
|
+
// Use split/join (not regex) to avoid the no-control-regex lint rule on the token strings.
|
|
35
|
+
s = s.split(T_TRAILING).join('(/.*)?'); // /** → optional /anything
|
|
36
|
+
s = s.split(T_MIDDLE).join('/(.*\\/)?'); // /**/ → /zero-or-more-segments/
|
|
37
|
+
s = s.split(T_DSTAR).join('.*'); // bare ** → .*
|
|
38
|
+
s = s.split(T_STAR).join('.*'); // * → .*
|
|
39
|
+
s = s.split(T_QUEST).join('.'); // ? → .
|
|
40
|
+
var regex = new RegExp("^".concat(s, "$"));
|
|
41
|
+
globRegexCache.set(glob, regex);
|
|
42
|
+
return regex;
|
|
43
|
+
};
|
|
44
|
+
exports.globToRegex = globToRegex;
|
|
45
|
+
//# sourceMappingURL=url.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url.js","sourceRoot":"","sources":["../../src/url.ts"],"names":[],"mappings":";;;AAAA,IAAM,cAAc,GAAG,IAAI,GAAG,EAAkB,CAAC;AAE1C,IAAM,WAAW,GAAG,UAAC,IAAY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CAAC,CAAC,iCAAiC;IAC1E,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,eAAe;IAChD,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;IACzC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ;IAExC,IAAM,KAAK,GAAG,IAAI,MAAM,CAAC,WAAI,CAAC,MAAG,CAAC,CAAC;IACnC,cAAc,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAChC,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AA1CW,QAAA,WAAW,eA0CtB","sourcesContent":["const globRegexCache = new Map<string, RegExp>();\n\nexport const globToRegex = (glob: string): RegExp => {\n const cached = globRegexCache.get(glob);\n if (cached) return cached;\n\n // Glob → regex conversion. Glob substitution must happen BEFORE regex escaping so that\n // the escaper does not corrupt the glob characters (e.g. turning `/**` into `/\\*\\*`).\n // Placeholder tokens use null bytes, which are illegal in HTTP URLs and therefore can\n // never collide with real pattern content.\n //\n // Substitution order (most-specific first):\n // trailing /** → (/.*)? — path with or without a trailing slash/subpath\n // middle /**/ → /(.*\\/)? — zero-or-more path segments (including zero)\n // bare ** → .* — graceful fallback for ** not adjacent to /\n // single * → .* — any characters (preserves existing behaviour)\n // ? → . — single character wildcard\n const T_TRAILING = '\\x00TRAIL\\x00';\n const T_MIDDLE = '\\x00MID\\x00';\n const T_DSTAR = '\\x00DS\\x00';\n const T_STAR = '\\x00ST\\x00';\n const T_QUEST = '\\x00QU\\x00';\n\n let s = glob;\n s = s.replace(/\\/\\*\\*$/, T_TRAILING); // trailing /**\n s = s.replace(/\\/\\*\\*\\//g, T_MIDDLE); // /**/ in the middle\n s = s.replace(/\\*\\*/g, T_DSTAR); // bare ** (e.g. **.example.com)\n s = s.replace(/\\*/g, T_STAR); // single *\n s = s.replace(/\\?/g, T_QUEST); // ?\n\n // Escape all remaining regex special characters.\n s = s.replace(/[.+^${}()|[\\]\\\\]/g, '\\\\$&');\n\n // Expand tokens into their regex equivalents.\n // Use split/join (not regex) to avoid the no-control-regex lint rule on the token strings.\n s = s.split(T_TRAILING).join('(/.*)?'); // /** → optional /anything\n s = s.split(T_MIDDLE).join('/(.*\\\\/)?'); // /**/ → /zero-or-more-segments/\n s = s.split(T_DSTAR).join('.*'); // bare ** → .*\n s = s.split(T_STAR).join('.*'); // * → .*\n s = s.split(T_QUEST).join('.'); // ? → .\n\n const regex = new RegExp(`^${s}$`);\n globRegexCache.set(glob, regex);\n return regex;\n};\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { PrivacyConfig } from './types';
|
|
2
|
+
/** Returns a copy. The caller supplies a validator for the target DOM's CSS syntax. */
|
|
3
|
+
export declare const validatePrivacySelectors: (config: PrivacyConfig, validate: (selector: string) => void, onInvalid?: ((selector: string) => void) | undefined) => PrivacyConfig;
|
|
4
|
+
/** Strict remote-policy boundary. Invalid policy throws; callers must not start capture on failure. */
|
|
5
|
+
export declare const parsePrivacyConfig: (value: unknown, validateSelector: (selector: string) => void) => PrivacyConfig;
|
|
6
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,aAAa,EAAE,MAAM,SAAS,CAAC;AAQnD,uFAAuF;AACvF,eAAO,MAAM,wBAAwB,WAC3B,aAAa,uBACA,MAAM,KAAK,IAAI,0BACb,MAAM,KAAK,IAAI,kBACrC,aAkBF,CAAC;AAEF,uGAAuG;AACvG,eAAO,MAAM,kBAAkB,UAAW,OAAO,+BAA+B,MAAM,KAAK,IAAI,KAAG,aA8BjG,CAAC"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parsePrivacyConfig = exports.validatePrivacySelectors = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var isStringArray = function (value) {
|
|
6
|
+
return Array.isArray(value) && value.every(function (item) { return typeof item === 'string'; });
|
|
7
|
+
};
|
|
8
|
+
var isLevel = function (value) {
|
|
9
|
+
return value === 'light' || value === 'medium' || value === 'conservative';
|
|
10
|
+
};
|
|
11
|
+
/** Returns a copy. The caller supplies a validator for the target DOM's CSS syntax. */
|
|
12
|
+
var validatePrivacySelectors = function (config, validate, onInvalid) {
|
|
13
|
+
var e_1, _a;
|
|
14
|
+
var result = tslib_1.__assign({}, config);
|
|
15
|
+
try {
|
|
16
|
+
for (var _b = tslib_1.__values(['blockSelector', 'maskSelector', 'unmaskSelector']), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
17
|
+
var key = _c.value;
|
|
18
|
+
var value = config[key];
|
|
19
|
+
var selectors = typeof value === 'string' ? [value] : value !== null && value !== void 0 ? value : [];
|
|
20
|
+
var valid = selectors.filter(function (selector) {
|
|
21
|
+
try {
|
|
22
|
+
validate(selector);
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
catch (_a) {
|
|
26
|
+
if (!onInvalid)
|
|
27
|
+
throw new Error("Invalid privacy selector: ".concat(selector));
|
|
28
|
+
onInvalid(selector);
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
result[key] = valid.length ? valid : undefined;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
36
|
+
finally {
|
|
37
|
+
try {
|
|
38
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
39
|
+
}
|
|
40
|
+
finally { if (e_1) throw e_1.error; }
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
};
|
|
44
|
+
exports.validatePrivacySelectors = validatePrivacySelectors;
|
|
45
|
+
/** Strict remote-policy boundary. Invalid policy throws; callers must not start capture on failure. */
|
|
46
|
+
var parsePrivacyConfig = function (value, validateSelector) {
|
|
47
|
+
var e_2, _a;
|
|
48
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
49
|
+
throw new Error('Invalid privacy config');
|
|
50
|
+
var input = value;
|
|
51
|
+
var config = {};
|
|
52
|
+
if (input.defaultMaskLevel !== undefined) {
|
|
53
|
+
if (!isLevel(input.defaultMaskLevel))
|
|
54
|
+
throw new Error('Invalid defaultMaskLevel');
|
|
55
|
+
config.defaultMaskLevel = input.defaultMaskLevel;
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
for (var _b = tslib_1.__values(['blockSelector', 'maskSelector', 'unmaskSelector', 'maskAttributes']), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
59
|
+
var key = _c.value;
|
|
60
|
+
var entry = input[key];
|
|
61
|
+
if (entry === undefined)
|
|
62
|
+
continue;
|
|
63
|
+
if (key === 'blockSelector' && typeof entry === 'string') {
|
|
64
|
+
config[key] = entry;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (!isStringArray(entry))
|
|
68
|
+
throw new Error("Invalid ".concat(key));
|
|
69
|
+
config[key] = tslib_1.__spreadArray([], tslib_1.__read(entry), false);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
73
|
+
finally {
|
|
74
|
+
try {
|
|
75
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
76
|
+
}
|
|
77
|
+
finally { if (e_2) throw e_2.error; }
|
|
78
|
+
}
|
|
79
|
+
if (input.urlMaskLevels !== undefined) {
|
|
80
|
+
if (!Array.isArray(input.urlMaskLevels))
|
|
81
|
+
throw new Error('Invalid urlMaskLevels');
|
|
82
|
+
config.urlMaskLevels = input.urlMaskLevels.map(function (rule) {
|
|
83
|
+
if (!rule || typeof rule !== 'object')
|
|
84
|
+
throw new Error('Invalid URL mask rule');
|
|
85
|
+
var entry = rule;
|
|
86
|
+
if (typeof entry.match !== 'string' || !entry.match.trim() || !isLevel(entry.maskLevel)) {
|
|
87
|
+
throw new Error('Invalid URL mask rule');
|
|
88
|
+
}
|
|
89
|
+
return { match: entry.match, maskLevel: entry.maskLevel };
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
return (0, exports.validatePrivacySelectors)(config, validateSelector);
|
|
93
|
+
};
|
|
94
|
+
exports.parsePrivacyConfig = parsePrivacyConfig;
|
|
95
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/validation.ts"],"names":[],"mappings":";;;;AAEA,IAAM,aAAa,GAAG,UAAC,KAAc;IACnC,OAAA,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,UAAC,IAAa,IAAK,OAAA,OAAO,IAAI,KAAK,QAAQ,EAAxB,CAAwB,CAAC;AAAhF,CAAgF,CAAC;AAEnF,IAAM,OAAO,GAAG,UAAC,KAAc;IAC7B,OAAA,KAAK,KAAK,OAAO,IAAI,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,cAAc;AAAnE,CAAmE,CAAC;AAEtE,uFAAuF;AAChF,IAAM,wBAAwB,GAAG,UACtC,MAAqB,EACrB,QAAoC,EACpC,SAAsC;;IAEtC,IAAM,MAAM,wBAAQ,MAAM,CAAE,CAAC;;QAC7B,KAAkB,IAAA,KAAA,iBAAA,CAAC,eAAe,EAAE,cAAc,EAAE,gBAAgB,CAAU,CAAA,gBAAA,4BAAE;YAA3E,IAAM,GAAG,WAAA;YACZ,IAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;YAC1B,IAAM,SAAS,GAAG,OAAO,KAAK,KAAK,QAAQ,C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AE,gBAAgB,CAAC,CAAC;AAC5D,CAAC,CAAC;AA9BW,QAAA,kBAAkB,sBA8B7B","sourcesContent":["import { MaskLevel, PrivacyConfig } from './types';\n\nconst isStringArray = (value: unknown): value is string[] =>\n Array.isArray(value) && value.every((item: unknown) => typeof item === 'string');\n\nconst isLevel = (value: unknown): value is MaskLevel =>\n value === 'light' || value === 'medium' || value === 'conservative';\n\n/** Returns a copy. The caller supplies a validator for the target DOM's CSS syntax. */\nexport const validatePrivacySelectors = (\n config: PrivacyConfig,\n validate: (selector: string) => void,\n onInvalid?: (selector: string) => void,\n): PrivacyConfig => {\n const result = { ...config };\n for (const key of ['blockSelector', 'maskSelector', 'unmaskSelector'] as const) {\n const value = config[key];\n const selectors = typeof value === 'string' ? [value] : value ?? [];\n const valid = selectors.filter((selector) => {\n try {\n validate(selector);\n return true;\n } catch {\n if (!onInvalid) throw new Error(`Invalid privacy selector: ${selector}`);\n onInvalid(selector);\n return false;\n }\n });\n result[key] = valid.length ? valid : undefined;\n }\n return result;\n};\n\n/** Strict remote-policy boundary. Invalid policy throws; callers must not start capture on failure. */\nexport const parsePrivacyConfig = (value: unknown, validateSelector: (selector: string) => void): PrivacyConfig => {\n if (!value || typeof value !== 'object' || Array.isArray(value)) throw new Error('Invalid privacy config');\n const input = value as Record<string, unknown>;\n const config: PrivacyConfig = {};\n if (input.defaultMaskLevel !== undefined) {\n if (!isLevel(input.defaultMaskLevel)) throw new Error('Invalid defaultMaskLevel');\n config.defaultMaskLevel = input.defaultMaskLevel;\n }\n for (const key of ['blockSelector', 'maskSelector', 'unmaskSelector', 'maskAttributes'] as const) {\n const entry = input[key];\n if (entry === undefined) continue;\n if (key === 'blockSelector' && typeof entry === 'string') {\n config[key] = entry;\n continue;\n }\n if (!isStringArray(entry)) throw new Error(`Invalid ${key}`);\n config[key] = [...entry];\n }\n if (input.urlMaskLevels !== undefined) {\n if (!Array.isArray(input.urlMaskLevels)) throw new Error('Invalid urlMaskLevels');\n config.urlMaskLevels = input.urlMaskLevels.map((rule: unknown) => {\n if (!rule || typeof rule !== 'object') throw new Error('Invalid URL mask rule');\n const entry = rule as Record<string, unknown>;\n if (typeof entry.match !== 'string' || !entry.match.trim() || !isLevel(entry.maskLevel)) {\n throw new Error('Invalid URL mask rule');\n }\n return { match: entry.match, maskLevel: entry.maskLevel };\n });\n }\n return validatePrivacySelectors(config, validateSelector);\n};\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare function toLowerCase<T extends string>(str: T): Lowercase<T>;
|
|
2
|
+
/**
|
|
3
|
+
* Get the type of an input element.
|
|
4
|
+
* This takes care of the case where a password input is changed to a text input.
|
|
5
|
+
* In this case, we continue to consider this of type password, in order to avoid leaking sensitive data
|
|
6
|
+
* where passwords should be masked.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getInputType(element: HTMLElement): Lowercase<string> | null;
|
|
9
|
+
//# sourceMappingURL=get-input-type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-input-type.d.ts","sourceRoot":"","sources":["../../src/get-input-type.ts"],"names":[],"mappings":"AAAA,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAElE;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,WAAW,GAAG,SAAS,CAAC,MAAM,CAAC,GAAG,IAAI,CAU3E"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export function toLowerCase(str) {
|
|
2
|
+
return str.toLowerCase();
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Get the type of an input element.
|
|
6
|
+
* This takes care of the case where a password input is changed to a text input.
|
|
7
|
+
* In this case, we continue to consider this of type password, in order to avoid leaking sensitive data
|
|
8
|
+
* where passwords should be masked.
|
|
9
|
+
*/
|
|
10
|
+
export function getInputType(element) {
|
|
11
|
+
// when omitting the type of input element(e.g. <input />), the type is treated as text
|
|
12
|
+
var type = element.type;
|
|
13
|
+
return element.hasAttribute('data-rr-is-password')
|
|
14
|
+
? 'password'
|
|
15
|
+
: type
|
|
16
|
+
? // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
17
|
+
toLowerCase(type)
|
|
18
|
+
: null;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=get-input-type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-input-type.js","sourceRoot":"","sources":["../../src/get-input-type.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,WAAW,CAAmB,GAAM;IAClD,OAAO,GAAG,CAAC,WAAW,EAA6B,CAAC;AACtD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,OAAoB;IAC/C,uFAAuF;IACvF,IAAM,IAAI,GAAI,OAA4B,CAAC,IAAI,CAAC;IAEhD,OAAO,OAAO,CAAC,YAAY,CAAC,qBAAqB,CAAC;QAChD,CAAC,CAAC,UAAU;QACZ,CAAC,CAAC,IAAI;YACN,CAAC,CAAC,4EAA4E;gBAC5E,WAAW,CAAC,IAAI,CAAC;YACnB,CAAC,CAAC,IAAI,CAAC;AACX,CAAC","sourcesContent":["export function toLowerCase<T extends string>(str: T): Lowercase<T> {\n return str.toLowerCase() as unknown as Lowercase<T>;\n}\n\n/**\n * Get the type of an input element.\n * This takes care of the case where a password input is changed to a text input.\n * In this case, we continue to consider this of type password, in order to avoid leaking sensitive data\n * where passwords should be masked.\n */\nexport function getInputType(element: HTMLElement): Lowercase<string> | null {\n // when omitting the type of input element(e.g. <input />), the type is treated as text\n const type = (element as HTMLInputElement).type;\n\n return element.hasAttribute('data-rr-is-password')\n ? 'password'\n : type\n ? // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n toLowerCase(type)\n : null;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC"}
|
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC","sourcesContent":["export * from './types';\nexport * from './policy';\nexport * from './recorder-options';\nexport * from './validation';\nexport { globToRegex } from './url';\nexport { getInputType, toLowerCase } from './get-input-type';\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { MaskLevel, PrivacyConfig } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Returns the effective mask level for a given URL by checking `urlMaskLevels`
|
|
4
|
+
* (first match wins) and falling back to `defaultMaskLevel`.
|
|
5
|
+
*/
|
|
6
|
+
export declare const getEffectiveMaskLevel: (url: string | undefined, config: PrivacyConfig) => MaskLevel;
|
|
7
|
+
/**
|
|
8
|
+
* Checks if the given element set to be masked by rrweb
|
|
9
|
+
*
|
|
10
|
+
* Priority is:
|
|
11
|
+
* 1. [In code] Element/class based masking/unmasking <> [Config based] Selector based masking/unmasking
|
|
12
|
+
* 2. Use app defaults
|
|
13
|
+
*/
|
|
14
|
+
export declare const isMasked: (elementType: 'input' | 'text', config: PrivacyConfig | undefined, element: HTMLElement | null, currentUrl?: string) => boolean;
|
|
15
|
+
export declare const maskFn: (elementType: 'text' | 'input', config?: PrivacyConfig, getCurrentUrl?: () => string) => (text: string, element: HTMLElement | null) => string;
|
|
16
|
+
export declare const maskAttributeFn: (config?: PrivacyConfig, getCurrentUrl?: () => string) => (key: string, value: string, element: HTMLElement) => string;
|
|
17
|
+
//# sourceMappingURL=policy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../../src/policy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAyCvE;;;GAGG;AACH,eAAO,MAAM,qBAAqB,QAAS,MAAM,GAAG,SAAS,UAAU,aAAa,KAAG,SAStF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,gBACN,OAAO,GAAG,MAAM,8CAEpB,WAAW,GAAG,IAAI,eACd,MAAM,KAClB,OA2BF,CAAC;AAEF,eAAO,MAAM,MAAM,gBACH,MAAM,GAAG,OAAO,WAAW,aAAa,kBAAkB,MAAM,MAAM,YAC7E,MAAM,WAAW,WAAW,GAAG,IAAI,KAAG,MAE5C,CAAC;AAEJ,eAAO,MAAM,eAAe,YAAa,aAAa,kBAAkB,MAAM,MAAM,WACrE,MAAM,SAAS,MAAM,WAAW,WAAW,KAAG,MAc5D,CAAC"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { __values } from "tslib";
|
|
2
|
+
import { DEFAULT_MASK_LEVEL } from './types';
|
|
3
|
+
import { getInputType } from './get-input-type';
|
|
4
|
+
import { globToRegex } from './url';
|
|
5
|
+
/**
|
|
6
|
+
* Light: Subset of inputs (sensitive types only — password, hidden, email, tel, cc-*)
|
|
7
|
+
* Medium: All inputs (form fields), text is NOT masked
|
|
8
|
+
* Conservative: All inputs and all texts
|
|
9
|
+
*/
|
|
10
|
+
var isMaskedForLevel = function (elementType, level, element) {
|
|
11
|
+
switch (level) {
|
|
12
|
+
case 'light': {
|
|
13
|
+
if (elementType !== 'input') {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
var inputType = element ? getInputType(element) : '';
|
|
17
|
+
/* istanbul ignore if */ // TODO(lew): For some reason it's impossible to test this.
|
|
18
|
+
if (!inputType) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
if (['password', 'hidden', 'email', 'tel'].includes(inputType)) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
if (element.autocomplete.startsWith('cc-')) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
case 'medium':
|
|
30
|
+
return elementType === 'input';
|
|
31
|
+
case 'conservative':
|
|
32
|
+
return true;
|
|
33
|
+
default:
|
|
34
|
+
return isMaskedForLevel(elementType, DEFAULT_MASK_LEVEL, element);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Returns the effective mask level for a given URL by checking `urlMaskLevels`
|
|
39
|
+
* (first match wins) and falling back to `defaultMaskLevel`.
|
|
40
|
+
*/
|
|
41
|
+
export var getEffectiveMaskLevel = function (url, config) {
|
|
42
|
+
var e_1, _a;
|
|
43
|
+
var _b;
|
|
44
|
+
if (url && config.urlMaskLevels) {
|
|
45
|
+
try {
|
|
46
|
+
for (var _c = __values(config.urlMaskLevels), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
47
|
+
var rule = _d.value;
|
|
48
|
+
if (globToRegex(rule.match).test(url)) {
|
|
49
|
+
return rule.maskLevel;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
54
|
+
finally {
|
|
55
|
+
try {
|
|
56
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
57
|
+
}
|
|
58
|
+
finally { if (e_1) throw e_1.error; }
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return (_b = config.defaultMaskLevel) !== null && _b !== void 0 ? _b : DEFAULT_MASK_LEVEL;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Checks if the given element set to be masked by rrweb
|
|
65
|
+
*
|
|
66
|
+
* Priority is:
|
|
67
|
+
* 1. [In code] Element/class based masking/unmasking <> [Config based] Selector based masking/unmasking
|
|
68
|
+
* 2. Use app defaults
|
|
69
|
+
*/
|
|
70
|
+
export var isMasked = function (elementType, config, element, currentUrl) {
|
|
71
|
+
var _a, _b;
|
|
72
|
+
if (config === void 0) { config = { defaultMaskLevel: DEFAULT_MASK_LEVEL }; }
|
|
73
|
+
if (element) {
|
|
74
|
+
// Element or parent is explicitly instrumented in code to mask
|
|
75
|
+
if (element.closest('.amp-mask, [data-amp-mask]')) {
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
// Config has override for mask
|
|
79
|
+
var shouldMask = ((_a = config.maskSelector) !== null && _a !== void 0 ? _a : []).some(function (selector) { return element.closest(selector); });
|
|
80
|
+
if (shouldMask) {
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
// Code or config has override to unmask
|
|
84
|
+
if (element.closest('.amp-unmask, [data-amp-unmask]')) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
// Here we are probably sent an element, but we want to match if they have a
|
|
88
|
+
// parent with an unmask selector.
|
|
89
|
+
var shouldUnmask = ((_b = config.unmaskSelector) !== null && _b !== void 0 ? _b : []).some(function (selector) { return element.closest(selector); });
|
|
90
|
+
if (shouldUnmask) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return isMaskedForLevel(elementType, getEffectiveMaskLevel(currentUrl, config), element);
|
|
95
|
+
};
|
|
96
|
+
export var maskFn = function (elementType, config, getCurrentUrl) {
|
|
97
|
+
return function (text, element) {
|
|
98
|
+
return isMasked(elementType, config, element, getCurrentUrl === null || getCurrentUrl === void 0 ? void 0 : getCurrentUrl()) ? text.replace(/[^\s]/g, '*') : text;
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
export var maskAttributeFn = function (config, getCurrentUrl) {
|
|
102
|
+
return function (key, value, element) {
|
|
103
|
+
var _a;
|
|
104
|
+
// Never mask style — rrweb has a separate styleDiff path for attribute mutations
|
|
105
|
+
// that reads directly from the DOM, bypassing maskAttributeFn.
|
|
106
|
+
if (key === 'style')
|
|
107
|
+
return value;
|
|
108
|
+
// Short-circuit: only proceed if this attribute is in the allowlist.
|
|
109
|
+
if (!((_a = config === null || config === void 0 ? void 0 : config.maskAttributes) !== null && _a !== void 0 ? _a : []).includes(key))
|
|
110
|
+
return value;
|
|
111
|
+
// Use 'input' for form elements so that `medium` (which masks inputs but not text)
|
|
112
|
+
// still masks attributes on inputs/selects/textareas. For non-form elements, use
|
|
113
|
+
// 'text' so medium leaves them visible.
|
|
114
|
+
var elementType = ['INPUT', 'SELECT', 'TEXTAREA'].includes(element.tagName) ? 'input' : 'text';
|
|
115
|
+
return isMasked(elementType, config, element, getCurrentUrl === null || getCurrentUrl === void 0 ? void 0 : getCurrentUrl()) ? value.replace(/[^\s]/g, '*') : value;
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
//# sourceMappingURL=policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy.js","sourceRoot":"","sources":["../../src/policy.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,kBAAkB,EAA4B,MAAM,SAAS,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAEpC;;;;GAIG;AACH,IAAM,gBAAgB,GAAG,UAAC,WAA6B,EAAE,KAAgB,EAAE,OAA2B;IACpG,QAAQ,KAAK,EAAE;QACb,KAAK,OAAO,CAAC,CAAC;YACZ,IAAI,WAAW,KAAK,OAAO,EAAE;gBAC3B,OAAO,KAAK,CAAC;aACd;YAED,IAAM,SAAS,GAAG,OAAO,CAAC,CAAC,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MAAsB,EAAE,aAA4B;IAClF,OAAO,UAAC,GAAW,EAAE,KAAa,EAAE,OAAoB;;QACtD,iFAAiF;QACjF,+DAA+D;QAC/D,IAAI,GAAG,KAAK,OAAO;YAAE,OAAO,KAAK,CAAC;QAElC,qEAAqE;QACrE,IAAI,CAAC,CAAC,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,cAAc,mCAAI,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC;YAAE,OAAO,KAAK,CAAC;QAEhE,mFAAmF;QACnF,iFAAiF;QACjF,wCAAwC;QACxC,IAAM,WAAW,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;QACjG,OAAO,QAAQ,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,aAAb,aAAa,uBAAb,aAAa,EAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAC1G,CAAC,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { DEFAULT_MASK_LEVEL, MaskLevel, PrivacyConfig } from './types';\nimport { getInputType } from './get-input-type';\nimport { globToRegex } from './url';\n\n/**\n * Light: Subset of inputs (sensitive types only — password, hidden, email, tel, cc-*)\n * Medium: All inputs (form fields), text is NOT masked\n * Conservative: All inputs and all texts\n */\nconst isMaskedForLevel = (elementType: 'input' | 'text', level: MaskLevel, element: HTMLElement | null): boolean => {\n switch (level) {\n case 'light': {\n if (elementType !== 'input') {\n return false;\n }\n\n const inputType = element ? getInputType(element) : '';\n /* istanbul ignore if */ // TODO(lew): For some reason it's impossible to test this.\n if (!inputType) {\n return false;\n }\n\n if (['password', 'hidden', 'email', 'tel'].includes(inputType)) {\n return true;\n }\n\n if ((element as HTMLInputElement).autocomplete.startsWith('cc-')) {\n return true;\n }\n\n return false;\n }\n case 'medium':\n return elementType === 'input';\n case 'conservative':\n return true;\n default:\n return isMaskedForLevel(elementType, DEFAULT_MASK_LEVEL, element);\n }\n};\n\n/**\n * Returns the effective mask level for a given URL by checking `urlMaskLevels`\n * (first match wins) and falling back to `defaultMaskLevel`.\n */\nexport const getEffectiveMaskLevel = (url: string | undefined, config: PrivacyConfig): MaskLevel => {\n if (url && config.urlMaskLevels) {\n for (const rule of config.urlMaskLevels) {\n if (globToRegex(rule.match).test(url)) {\n return rule.maskLevel;\n }\n }\n }\n return config.defaultMaskLevel ?? DEFAULT_MASK_LEVEL;\n};\n\n/**\n * Checks if the given element set to be masked by rrweb\n *\n * Priority is:\n * 1. [In code] Element/class based masking/unmasking <> [Config based] Selector based masking/unmasking\n * 2. Use app defaults\n */\nexport const isMasked = (\n elementType: 'input' | 'text',\n config: PrivacyConfig = { defaultMaskLevel: DEFAULT_MASK_LEVEL },\n element: HTMLElement | null,\n currentUrl?: string,\n): boolean => {\n if (element) {\n // Element or parent is explicitly instrumented in code to mask\n if (element.closest('.amp-mask, [data-amp-mask]')) {\n return true;\n }\n\n // Config has override for mask\n const shouldMask = (config.maskSelector ?? []).some((selector) => element.closest(selector));\n if (shouldMask) {\n return true;\n }\n\n // Code or config has override to unmask\n if (element.closest('.amp-unmask, [data-amp-unmask]')) {\n return false;\n }\n\n // Here we are probably sent an element, but we want to match if they have a\n // parent with an unmask selector.\n const shouldUnmask = (config.unmaskSelector ?? []).some((selector) => element.closest(selector));\n if (shouldUnmask) {\n return false;\n }\n }\n\n return isMaskedForLevel(elementType, getEffectiveMaskLevel(currentUrl, config), element);\n};\n\nexport const maskFn =\n (elementType: 'text' | 'input', config?: PrivacyConfig, getCurrentUrl?: () => string) =>\n (text: string, element: HTMLElement | null): string => {\n return isMasked(elementType, config, element, getCurrentUrl?.()) ? text.replace(/[^\\s]/g, '*') : text;\n };\n\nexport const maskAttributeFn = (config?: PrivacyConfig, getCurrentUrl?: () => string) => {\n return (key: string, value: string, element: HTMLElement): string => {\n // Never mask style — rrweb has a separate styleDiff path for attribute mutations\n // that reads directly from the DOM, bypassing maskAttributeFn.\n if (key === 'style') return value;\n\n // Short-circuit: only proceed if this attribute is in the allowlist.\n if (!(config?.maskAttributes ?? []).includes(key)) return value;\n\n // Use 'input' for form elements so that `medium` (which masks inputs but not text)\n // still masks attributes on inputs/selects/textareas. For non-form elements, use\n // 'text' so medium leaves them visible.\n const elementType = ['INPUT', 'SELECT', 'TEXTAREA'].includes(element.tagName) ? 'input' : 'text';\n return isMasked(elementType, config, element, getCurrentUrl?.()) ? value.replace(/[^\\s]/g, '*') : value;\n };\n};\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { PrivacyConfig } from './types';
|
|
2
|
+
export declare const getBlockSelectors: (config?: PrivacyConfig) => string;
|
|
3
|
+
export declare const getMaskTextSelectors: (config?: PrivacyConfig, url?: string) => string;
|
|
4
|
+
/** Lifecycle and URL observation belong to the caller. Replace the recorder when policy changes. */
|
|
5
|
+
export declare const createPrivacyRecorderOptions: (config?: PrivacyConfig, getCurrentUrl?: () => string) => {
|
|
6
|
+
maskAllInputs: boolean;
|
|
7
|
+
maskTextClass: string;
|
|
8
|
+
blockClass: string;
|
|
9
|
+
blockSelector: string;
|
|
10
|
+
maskTextSelector: string;
|
|
11
|
+
maskInputFn: (text: string, element: HTMLElement | null) => string;
|
|
12
|
+
maskTextFn: (text: string, element: HTMLElement | null) => string;
|
|
13
|
+
maskAttributeFn: (key: string, value: string, element: HTMLElement) => string;
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=recorder-options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recorder-options.d.ts","sourceRoot":"","sources":["../../src/recorder-options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGxC,eAAO,MAAM,iBAAiB,YAAa,aAAa,KAAG,MAI1D,CAAC;AAEF,eAAO,MAAM,oBAAoB,YAAa,aAAa,QAAQ,MAAM,KAAG,MAW3E,CAAC;AAEF,oGAAoG;AACpG,eAAO,MAAM,4BAA4B,YAAa,aAAa,kBAAiB,MAAM,MAAM;;;;;;;;;CAY/F,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { __read, __spreadArray } from "tslib";
|
|
2
|
+
import { getEffectiveMaskLevel, maskFn, maskAttributeFn } from './policy';
|
|
3
|
+
export var getBlockSelectors = function (config) {
|
|
4
|
+
var configured = config === null || config === void 0 ? void 0 : config.blockSelector;
|
|
5
|
+
var selectors = typeof configured === 'string' ? (configured ? [configured] : []) : configured !== null && configured !== void 0 ? configured : [];
|
|
6
|
+
return __spreadArray(__spreadArray([], __read(selectors), false), ['[data-amp-block]'], false).join(',');
|
|
7
|
+
};
|
|
8
|
+
export var getMaskTextSelectors = function (config, url) {
|
|
9
|
+
var _a, _b;
|
|
10
|
+
// rrweb selects which text reaches the callback at recorder startup. Include all
|
|
11
|
+
// text if any route can require conservative masking; callbacks resolve the URL dynamically.
|
|
12
|
+
if (config &&
|
|
13
|
+
(getEffectiveMaskLevel(url, config) === 'conservative' ||
|
|
14
|
+
config.defaultMaskLevel === 'conservative' ||
|
|
15
|
+
((_a = config.urlMaskLevels) === null || _a === void 0 ? void 0 : _a.some(function (rule) { return rule.maskLevel === 'conservative'; }))))
|
|
16
|
+
return '*';
|
|
17
|
+
return __spreadArray(__spreadArray([], __read(((_b = config === null || config === void 0 ? void 0 : config.maskSelector) !== null && _b !== void 0 ? _b : [])), false), ['[data-amp-mask]'], false).join(',');
|
|
18
|
+
};
|
|
19
|
+
/** Lifecycle and URL observation belong to the caller. Replace the recorder when policy changes. */
|
|
20
|
+
export var createPrivacyRecorderOptions = function (config, getCurrentUrl) {
|
|
21
|
+
if (getCurrentUrl === void 0) { getCurrentUrl = function () { return ''; }; }
|
|
22
|
+
var blockSelector = getBlockSelectors(config);
|
|
23
|
+
return {
|
|
24
|
+
maskAllInputs: true,
|
|
25
|
+
maskTextClass: 'amp-mask',
|
|
26
|
+
blockClass: 'amp-block',
|
|
27
|
+
blockSelector: blockSelector,
|
|
28
|
+
maskTextSelector: getMaskTextSelectors(config, getCurrentUrl()),
|
|
29
|
+
maskInputFn: maskFn('input', config, getCurrentUrl),
|
|
30
|
+
maskTextFn: maskFn('text', config, getCurrentUrl),
|
|
31
|
+
maskAttributeFn: maskAttributeFn(config, getCurrentUrl),
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=recorder-options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recorder-options.js","sourceRoot":"","sources":["../../src/recorder-options.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE1E,MAAM,CAAC,IAAM,iBAAiB,GAAG,UAAC,MAAsB;IACtD,IAAM,UAAU,GAAG,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,aAAa,CAAC;IACzC,IAAM,SAAS,GAAG,OAAO,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,aAAV,UAAU,cAAV,UAAU,GAAI,EAAE,CAAC;IACvG,OAAO,uCAAI,SAAS,YAAE,kBAAkB,UAAE,IAAI,CAAC,GAAG,CAAC,CAAC;AACtD,CAAC,CAAC;AAEF,MAAM,CAAC,IAAM,oBAAoB,GAAG,UAAC,MAAsB,EAAE,GAAY;;IACvE,iFAAiF;IACjF,6FAA6F;IAC7F,IACE,MAAM;QACN,CAAC,qBAAqB,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,cAAc;YACpD,MAAM,CAAC,gBAAgB,KAAK,cAAc;aAC1C,MAAA,MAAM,CAAC,aAAa,0CAAE,IAAI,CAAC,UAAC,IAAI,IAAK,OAAA,IAAI,CAAC,SAAS,KAAK,cAAc,EAAjC,CAAiC,CAAC,CAAA,CAAC;QAE1E,OAAO,GAAG,CAAC;IACb,OAAO,uCAAI,CAAC,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,YAAY,mCAAI,EAAE,CAAC,YAAE,iBAAiB,UAAE,IAAI,CAAC,GAAG,CAAC,CAAC;AACxE,CAAC,CAAC;AAEF,oGAAoG;AACpG,MAAM,CAAC,IAAM,4BAA4B,GAAG,UAAC,MAAsB,EAAE,aAAsC;IAAtC,8BAAA,EAAA,8BAAoC,OAAA,EAAE,EAAF,CAAE;IACzG,IAAM,aAAa,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAChD,OAAO;QACL,aAAa,EAAE,IAAI;QACnB,aAAa,EAAE,UAAU;QACzB,UAAU,EAAE,WAAW;QACvB,aAAa,eAAA;QACb,gBAAgB,EAAE,oBAAoB,CAAC,MAAM,EAAE,aAAa,EAAE,CAAC;QAC/D,WAAW,EAAE,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,aAAa,CAAC;QACnD,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,aAAa,CAAC;QACjD,eAAe,EAAE,eAAe,CAAC,MAAM,EAAE,aAAa,CAAC;KACxD,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { PrivacyConfig } from './types';\nimport { getEffectiveMaskLevel, maskFn, maskAttributeFn } from './policy';\n\nexport const getBlockSelectors = (config?: PrivacyConfig): string => {\n const configured = config?.blockSelector;\n const selectors = typeof configured === 'string' ? (configured ? [configured] : []) : configured ?? [];\n return [...selectors, '[data-amp-block]'].join(',');\n};\n\nexport const getMaskTextSelectors = (config?: PrivacyConfig, url?: string): string => {\n // rrweb selects which text reaches the callback at recorder startup. Include all\n // text if any route can require conservative masking; callbacks resolve the URL dynamically.\n if (\n config &&\n (getEffectiveMaskLevel(url, config) === 'conservative' ||\n config.defaultMaskLevel === 'conservative' ||\n config.urlMaskLevels?.some((rule) => rule.maskLevel === 'conservative'))\n )\n return '*';\n return [...(config?.maskSelector ?? []), '[data-amp-mask]'].join(',');\n};\n\n/** Lifecycle and URL observation belong to the caller. Replace the recorder when policy changes. */\nexport const createPrivacyRecorderOptions = (config?: PrivacyConfig, getCurrentUrl: () => string = () => '') => {\n const blockSelector = getBlockSelectors(config);\n return {\n maskAllInputs: true,\n maskTextClass: 'amp-mask',\n blockClass: 'amp-block',\n blockSelector,\n maskTextSelector: getMaskTextSelectors(config, getCurrentUrl()),\n maskInputFn: maskFn('input', config, getCurrentUrl),\n maskTextFn: maskFn('text', config, getCurrentUrl),\n maskAttributeFn: maskAttributeFn(config, getCurrentUrl),\n };\n};\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type MaskLevel = 'light' | 'medium' | 'conservative';
|
|
2
|
+
export declare const DEFAULT_MASK_LEVEL = "medium";
|
|
3
|
+
export type PrivacyConfig = {
|
|
4
|
+
blockSelector?: string | string[];
|
|
5
|
+
defaultMaskLevel?: MaskLevel;
|
|
6
|
+
maskSelector?: string[];
|
|
7
|
+
unmaskSelector?: string[];
|
|
8
|
+
maskAttributes?: string[];
|
|
9
|
+
/**
|
|
10
|
+
* Per-URL overrides for `defaultMaskLevel`. Each entry contains a glob pattern (`match`)
|
|
11
|
+
* and a `maskLevel` to apply when the current page URL matches that pattern.
|
|
12
|
+
* Rules are evaluated in order; the first match wins. Remote rules take precedence
|
|
13
|
+
* over local rules (remote entries are prepended before local entries).
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* urlMaskLevels: [
|
|
17
|
+
* { match: 'https://example.com/checkout/*', maskLevel: 'conservative' },
|
|
18
|
+
* { match: 'https://example.com/public/*', maskLevel: 'light' },
|
|
19
|
+
* ]
|
|
20
|
+
*/
|
|
21
|
+
urlMaskLevels?: Array<{
|
|
22
|
+
match: string;
|
|
23
|
+
maskLevel: MaskLevel;
|
|
24
|
+
}>;
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GACjB,OAAO,GACP,QAAQ,GACR,cAAc,CAAC;AAEnB,eAAO,MAAM,kBAAkB,WAAW,CAAC;AAG3C,MAAM,MAAM,aAAa,GAAG;IAC1B,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAClC,gBAAgB,CAAC,EAAE,SAAS,CAAC;IAC7B,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B;;;;;;;;;;;OAWG;IACH,aAAa,CAAC,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,SAAS,CAAA;KAAE,CAAC,CAAC;CAChE,CAAC"}
|
package/lib/esm/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAKA,MAAM,CAAC,IAAM,kBAAkB,GAAG,QAAQ,CAAC","sourcesContent":["export type MaskLevel =\n | 'light' // only mask a subset of inputs that's deemed sensitive - password, credit card, telephone #, email. These are information we never want to capture.\n | 'medium' // mask all form fields (inputs); page text is captured as-is\n | 'conservative'; // mask all inputs and all texts\n\nexport const DEFAULT_MASK_LEVEL = 'medium';\n\n// err on the side of excluding more\nexport type PrivacyConfig = {\n blockSelector?: string | string[]; // exclude in the UI\n defaultMaskLevel?: MaskLevel;\n maskSelector?: string[];\n unmaskSelector?: string[];\n maskAttributes?: string[]; // HTML attribute names to mask (e.g. [\"placeholder\", \"aria-label\"])\n /**\n * Per-URL overrides for `defaultMaskLevel`. Each entry contains a glob pattern (`match`)\n * and a `maskLevel` to apply when the current page URL matches that pattern.\n * Rules are evaluated in order; the first match wins. Remote rules take precedence\n * over local rules (remote entries are prepended before local entries).\n *\n * @example\n * urlMaskLevels: [\n * { match: 'https://example.com/checkout/*', maskLevel: 'conservative' },\n * { match: 'https://example.com/public/*', maskLevel: 'light' },\n * ]\n */\n urlMaskLevels?: Array<{ match: string; maskLevel: MaskLevel }>;\n};\n"]}
|
package/lib/esm/url.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../../src/url.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW,SAAU,MAAM,KAAG,MA0C1C,CAAC"}
|
package/lib/esm/url.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
var globRegexCache = new Map();
|
|
2
|
+
export var globToRegex = function (glob) {
|
|
3
|
+
var cached = globRegexCache.get(glob);
|
|
4
|
+
if (cached)
|
|
5
|
+
return cached;
|
|
6
|
+
// Glob → regex conversion. Glob substitution must happen BEFORE regex escaping so that
|
|
7
|
+
// the escaper does not corrupt the glob characters (e.g. turning `/**` into `/\*\*`).
|
|
8
|
+
// Placeholder tokens use null bytes, which are illegal in HTTP URLs and therefore can
|
|
9
|
+
// never collide with real pattern content.
|
|
10
|
+
//
|
|
11
|
+
// Substitution order (most-specific first):
|
|
12
|
+
// trailing /** → (/.*)? — path with or without a trailing slash/subpath
|
|
13
|
+
// middle /**/ → /(.*\/)? — zero-or-more path segments (including zero)
|
|
14
|
+
// bare ** → .* — graceful fallback for ** not adjacent to /
|
|
15
|
+
// single * → .* — any characters (preserves existing behaviour)
|
|
16
|
+
// ? → . — single character wildcard
|
|
17
|
+
var T_TRAILING = '\x00TRAIL\x00';
|
|
18
|
+
var T_MIDDLE = '\x00MID\x00';
|
|
19
|
+
var T_DSTAR = '\x00DS\x00';
|
|
20
|
+
var T_STAR = '\x00ST\x00';
|
|
21
|
+
var T_QUEST = '\x00QU\x00';
|
|
22
|
+
var s = glob;
|
|
23
|
+
s = s.replace(/\/\*\*$/, T_TRAILING); // trailing /**
|
|
24
|
+
s = s.replace(/\/\*\*\//g, T_MIDDLE); // /**/ in the middle
|
|
25
|
+
s = s.replace(/\*\*/g, T_DSTAR); // bare ** (e.g. **.example.com)
|
|
26
|
+
s = s.replace(/\*/g, T_STAR); // single *
|
|
27
|
+
s = s.replace(/\?/g, T_QUEST); // ?
|
|
28
|
+
// Escape all remaining regex special characters.
|
|
29
|
+
s = s.replace(/[.+^${}()|[\]\\]/g, '\\$&');
|
|
30
|
+
// Expand tokens into their regex equivalents.
|
|
31
|
+
// Use split/join (not regex) to avoid the no-control-regex lint rule on the token strings.
|
|
32
|
+
s = s.split(T_TRAILING).join('(/.*)?'); // /** → optional /anything
|
|
33
|
+
s = s.split(T_MIDDLE).join('/(.*\\/)?'); // /**/ → /zero-or-more-segments/
|
|
34
|
+
s = s.split(T_DSTAR).join('.*'); // bare ** → .*
|
|
35
|
+
s = s.split(T_STAR).join('.*'); // * → .*
|
|
36
|
+
s = s.split(T_QUEST).join('.'); // ? → .
|
|
37
|
+
var regex = new RegExp("^".concat(s, "$"));
|
|
38
|
+
globRegexCache.set(glob, regex);
|
|
39
|
+
return regex;
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=url.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url.js","sourceRoot":"","sources":["../../src/url.ts"],"names":[],"mappings":"AAAA,IAAM,cAAc,GAAG,IAAI,GAAG,EAAkB,CAAC;AAEjD,MAAM,CAAC,IAAM,WAAW,GAAG,UAAC,IAAY;IACtC,IAAM,MAAM,GAAG,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACxC,IAAI,MAAM;QAAE,OAAO,MAAM,CAAC;IAE1B,uFAAuF;IACvF,sFAAsF;IACtF,sFAAsF;IACtF,2CAA2C;IAC3C,EAAE;IACF,4CAA4C;IAC5C,qFAAqF;I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C,CAAC,SAAS;IACzC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ;IAExC,IAAM,KAAK,GAAG,IAAI,MAAM,CAAC,WAAI,CAAC,MAAG,CAAC,CAAC;IACnC,cAAc,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAChC,OAAO,KAAK,CAAC;AACf,CAAC,CAAC","sourcesContent":["const globRegexCache = new Map<string, RegExp>();\n\nexport const globToRegex = (glob: string): RegExp => {\n const cached = globRegexCache.get(glob);\n if (cached) return cached;\n\n // Glob → regex conversion. Glob substitution must happen BEFORE regex escaping so that\n // the escaper does not corrupt the glob characters (e.g. turning `/**` into `/\\*\\*`).\n // Placeholder tokens use null bytes, which are illegal in HTTP URLs and therefore can\n // never collide with real pattern content.\n //\n // Substitution order (most-specific first):\n // trailing /** → (/.*)? — path with or without a trailing slash/subpath\n // middle /**/ → /(.*\\/)? — zero-or-more path segments (including zero)\n // bare ** → .* — graceful fallback for ** not adjacent to /\n // single * → .* — any characters (preserves existing behaviour)\n // ? → . — single character wildcard\n const T_TRAILING = '\\x00TRAIL\\x00';\n const T_MIDDLE = '\\x00MID\\x00';\n const T_DSTAR = '\\x00DS\\x00';\n const T_STAR = '\\x00ST\\x00';\n const T_QUEST = '\\x00QU\\x00';\n\n let s = glob;\n s = s.replace(/\\/\\*\\*$/, T_TRAILING); // trailing /**\n s = s.replace(/\\/\\*\\*\\//g, T_MIDDLE); // /**/ in the middle\n s = s.replace(/\\*\\*/g, T_DSTAR); // bare ** (e.g. **.example.com)\n s = s.replace(/\\*/g, T_STAR); // single *\n s = s.replace(/\\?/g, T_QUEST); // ?\n\n // Escape all remaining regex special characters.\n s = s.replace(/[.+^${}()|[\\]\\\\]/g, '\\\\$&');\n\n // Expand tokens into their regex equivalents.\n // Use split/join (not regex) to avoid the no-control-regex lint rule on the token strings.\n s = s.split(T_TRAILING).join('(/.*)?'); // /** → optional /anything\n s = s.split(T_MIDDLE).join('/(.*\\\\/)?'); // /**/ → /zero-or-more-segments/\n s = s.split(T_DSTAR).join('.*'); // bare ** → .*\n s = s.split(T_STAR).join('.*'); // * → .*\n s = s.split(T_QUEST).join('.'); // ? → .\n\n const regex = new RegExp(`^${s}$`);\n globRegexCache.set(glob, regex);\n return regex;\n};\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { PrivacyConfig } from './types';
|
|
2
|
+
/** Returns a copy. The caller supplies a validator for the target DOM's CSS syntax. */
|
|
3
|
+
export declare const validatePrivacySelectors: (config: PrivacyConfig, validate: (selector: string) => void, onInvalid?: ((selector: string) => void) | undefined) => PrivacyConfig;
|
|
4
|
+
/** Strict remote-policy boundary. Invalid policy throws; callers must not start capture on failure. */
|
|
5
|
+
export declare const parsePrivacyConfig: (value: unknown, validateSelector: (selector: string) => void) => PrivacyConfig;
|
|
6
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,aAAa,EAAE,MAAM,SAAS,CAAC;AAQnD,uFAAuF;AACvF,eAAO,MAAM,wBAAwB,WAC3B,aAAa,uBACA,MAAM,KAAK,IAAI,0BACb,MAAM,KAAK,IAAI,kBACrC,aAkBF,CAAC;AAEF,uGAAuG;AACvG,eAAO,MAAM,kBAAkB,UAAW,OAAO,+BAA+B,MAAM,KAAK,IAAI,KAAG,aA8BjG,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { __assign, __read, __spreadArray, __values } from "tslib";
|
|
2
|
+
var isStringArray = function (value) {
|
|
3
|
+
return Array.isArray(value) && value.every(function (item) { return typeof item === 'string'; });
|
|
4
|
+
};
|
|
5
|
+
var isLevel = function (value) {
|
|
6
|
+
return value === 'light' || value === 'medium' || value === 'conservative';
|
|
7
|
+
};
|
|
8
|
+
/** Returns a copy. The caller supplies a validator for the target DOM's CSS syntax. */
|
|
9
|
+
export var validatePrivacySelectors = function (config, validate, onInvalid) {
|
|
10
|
+
var e_1, _a;
|
|
11
|
+
var result = __assign({}, config);
|
|
12
|
+
try {
|
|
13
|
+
for (var _b = __values(['blockSelector', 'maskSelector', 'unmaskSelector']), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
14
|
+
var key = _c.value;
|
|
15
|
+
var value = config[key];
|
|
16
|
+
var selectors = typeof value === 'string' ? [value] : value !== null && value !== void 0 ? value : [];
|
|
17
|
+
var valid = selectors.filter(function (selector) {
|
|
18
|
+
try {
|
|
19
|
+
validate(selector);
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
catch (_a) {
|
|
23
|
+
if (!onInvalid)
|
|
24
|
+
throw new Error("Invalid privacy selector: ".concat(selector));
|
|
25
|
+
onInvalid(selector);
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
result[key] = valid.length ? valid : undefined;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
33
|
+
finally {
|
|
34
|
+
try {
|
|
35
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
36
|
+
}
|
|
37
|
+
finally { if (e_1) throw e_1.error; }
|
|
38
|
+
}
|
|
39
|
+
return result;
|
|
40
|
+
};
|
|
41
|
+
/** Strict remote-policy boundary. Invalid policy throws; callers must not start capture on failure. */
|
|
42
|
+
export var parsePrivacyConfig = function (value, validateSelector) {
|
|
43
|
+
var e_2, _a;
|
|
44
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
45
|
+
throw new Error('Invalid privacy config');
|
|
46
|
+
var input = value;
|
|
47
|
+
var config = {};
|
|
48
|
+
if (input.defaultMaskLevel !== undefined) {
|
|
49
|
+
if (!isLevel(input.defaultMaskLevel))
|
|
50
|
+
throw new Error('Invalid defaultMaskLevel');
|
|
51
|
+
config.defaultMaskLevel = input.defaultMaskLevel;
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
for (var _b = __values(['blockSelector', 'maskSelector', 'unmaskSelector', 'maskAttributes']), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
55
|
+
var key = _c.value;
|
|
56
|
+
var entry = input[key];
|
|
57
|
+
if (entry === undefined)
|
|
58
|
+
continue;
|
|
59
|
+
if (key === 'blockSelector' && typeof entry === 'string') {
|
|
60
|
+
config[key] = entry;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (!isStringArray(entry))
|
|
64
|
+
throw new Error("Invalid ".concat(key));
|
|
65
|
+
config[key] = __spreadArray([], __read(entry), false);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
69
|
+
finally {
|
|
70
|
+
try {
|
|
71
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
72
|
+
}
|
|
73
|
+
finally { if (e_2) throw e_2.error; }
|
|
74
|
+
}
|
|
75
|
+
if (input.urlMaskLevels !== undefined) {
|
|
76
|
+
if (!Array.isArray(input.urlMaskLevels))
|
|
77
|
+
throw new Error('Invalid urlMaskLevels');
|
|
78
|
+
config.urlMaskLevels = input.urlMaskLevels.map(function (rule) {
|
|
79
|
+
if (!rule || typeof rule !== 'object')
|
|
80
|
+
throw new Error('Invalid URL mask rule');
|
|
81
|
+
var entry = rule;
|
|
82
|
+
if (typeof entry.match !== 'string' || !entry.match.trim() || !isLevel(entry.maskLevel)) {
|
|
83
|
+
throw new Error('Invalid URL mask rule');
|
|
84
|
+
}
|
|
85
|
+
return { match: entry.match, maskLevel: entry.maskLevel };
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return validatePrivacySelectors(config, validateSelector);
|
|
89
|
+
};
|
|
90
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{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AK,CAAC,aAAa,KAAK,SAAS,EAAE;QACrC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;QAClF,MAAM,CAAC,aAAa,GAAG,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,UAAC,IAAa;YAC3D,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ;gBAAE,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;YAChF,IAAM,KAAK,GAAG,IAA+B,CAAC;YAC9C,IAAI,OAAO,KAAK,CAAC,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE;gBACvF,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;aAC1C;YACD,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC;QAC5D,CAAC,CAAC,CAAC;KACJ;IACD,OAAO,wBAAwB,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;AAC5D,CAAC,CAAC","sourcesContent":["import { MaskLevel, PrivacyConfig } from './types';\n\nconst isStringArray = (value: unknown): value is string[] =>\n Array.isArray(value) && value.every((item: unknown) => typeof item === 'string');\n\nconst isLevel = (value: unknown): value is MaskLevel =>\n value === 'light' || value === 'medium' || value === 'conservative';\n\n/** Returns a copy. The caller supplies a validator for the target DOM's CSS syntax. */\nexport const validatePrivacySelectors = (\n config: PrivacyConfig,\n validate: (selector: string) => void,\n onInvalid?: (selector: string) => void,\n): PrivacyConfig => {\n const result = { ...config };\n for (const key of ['blockSelector', 'maskSelector', 'unmaskSelector'] as const) {\n const value = config[key];\n const selectors = typeof value === 'string' ? [value] : value ?? [];\n const valid = selectors.filter((selector) => {\n try {\n validate(selector);\n return true;\n } catch {\n if (!onInvalid) throw new Error(`Invalid privacy selector: ${selector}`);\n onInvalid(selector);\n return false;\n }\n });\n result[key] = valid.length ? valid : undefined;\n }\n return result;\n};\n\n/** Strict remote-policy boundary. Invalid policy throws; callers must not start capture on failure. */\nexport const parsePrivacyConfig = (value: unknown, validateSelector: (selector: string) => void): PrivacyConfig => {\n if (!value || typeof value !== 'object' || Array.isArray(value)) throw new Error('Invalid privacy config');\n const input = value as Record<string, unknown>;\n const config: PrivacyConfig = {};\n if (input.defaultMaskLevel !== undefined) {\n if (!isLevel(input.defaultMaskLevel)) throw new Error('Invalid defaultMaskLevel');\n config.defaultMaskLevel = input.defaultMaskLevel;\n }\n for (const key of ['blockSelector', 'maskSelector', 'unmaskSelector', 'maskAttributes'] as const) {\n const entry = input[key];\n if (entry === undefined) continue;\n if (key === 'blockSelector' && typeof entry === 'string') {\n config[key] = entry;\n continue;\n }\n if (!isStringArray(entry)) throw new Error(`Invalid ${key}`);\n config[key] = [...entry];\n }\n if (input.urlMaskLevels !== undefined) {\n if (!Array.isArray(input.urlMaskLevels)) throw new Error('Invalid urlMaskLevels');\n config.urlMaskLevels = input.urlMaskLevels.map((rule: unknown) => {\n if (!rule || typeof rule !== 'object') throw new Error('Invalid URL mask rule');\n const entry = rule as Record<string, unknown>;\n if (typeof entry.match !== 'string' || !entry.match.trim() || !isLevel(entry.maskLevel)) {\n throw new Error('Invalid URL mask rule');\n }\n return { match: entry.match, maskLevel: entry.maskLevel };\n });\n }\n return validatePrivacySelectors(config, validateSelector);\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,9 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amplitude/session-replay-dom-privacy",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Shared DOM privacy policy and rrweb options for Amplitude Session Replay",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"main": "lib/cjs/index.js",
|
|
7
|
+
"module": "lib/esm/index.js",
|
|
8
|
+
"types": "lib/esm/index.d.ts",
|
|
9
|
+
"sideEffects": false,
|
|
10
|
+
"files": [
|
|
11
|
+
"lib"
|
|
12
|
+
],
|
|
6
13
|
"publishConfig": {
|
|
7
14
|
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"tslib": "^2.4.1"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/amplitude/Amplitude-TypeScript.git"
|
|
22
|
+
},
|
|
23
|
+
"homepage": "https://github.com/amplitude/Amplitude-TypeScript",
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "pnpm build:es5 && pnpm build:esm",
|
|
26
|
+
"build:es5": "tsc -p tsconfig.es5.json",
|
|
27
|
+
"build:esm": "tsc -p tsconfig.esm.json",
|
|
28
|
+
"test": "jest",
|
|
29
|
+
"lint": "eslint '{src,test}/**/*.ts'",
|
|
30
|
+
"typecheck": "tsc -p tsconfig.json"
|
|
8
31
|
}
|
|
9
|
-
}
|
|
32
|
+
}
|