@brainfish-ai/web-tracker 0.0.4-alpha.15 → 0.0.4-alpha.17
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/dist/index.js +1943 -4
- package/package.json +1 -2
- package/src/index.ts +1 -1
- package/src/redact/built-ins/NameRedactor.ts +41 -0
- package/src/redact/built-ins/SimpleRegexpRedactor.ts +22 -0
- package/src/redact/built-ins/simple-regexp-patterns.ts +20 -0
- package/src/redact/built-ins/well-known-names.json +11543 -0
- package/src/redact/composition.ts +54 -0
- package/src/redact/index.ts +21 -0
- package/src/redact/types.ts +34 -0
- package/src/redact/utils.ts +15 -0
- package/src/{utils → screenshot}/redact.ts +1 -1
- package/vite.config.ts +10 -5
- /package/src/{utils → screenshot}/capture.test.ts +0 -0
- /package/src/{utils → screenshot}/capture.ts +0 -0
- /package/src/{utils → screenshot}/redact.test.ts +0 -0
- /package/src/{utils → screenshot}/snapshot.ts +0 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { NameRedactor } from './built-ins/NameRedactor';
|
|
2
|
+
import * as simpleRegexpBuiltIns from './built-ins/simple-regexp-patterns';
|
|
3
|
+
import { SimpleRegexpRedactor } from './built-ins/SimpleRegexpRedactor';
|
|
4
|
+
import {
|
|
5
|
+
AsyncCustomRedactorConfig,
|
|
6
|
+
IAsyncRedactor,
|
|
7
|
+
CompositeRedactorOptions,
|
|
8
|
+
SyncCustomRedactorConfig,
|
|
9
|
+
ISyncRedactor,
|
|
10
|
+
} from './types';
|
|
11
|
+
import { isSimpleRegexpCustomRedactorConfig, snakeCase } from './utils';
|
|
12
|
+
|
|
13
|
+
function normalizeCustomRedactorConfig(redactorConfig: any) {
|
|
14
|
+
return isSimpleRegexpCustomRedactorConfig(redactorConfig)
|
|
15
|
+
? new SimpleRegexpRedactor({
|
|
16
|
+
regexpPattern: redactorConfig.regexpPattern,
|
|
17
|
+
replaceWith: redactorConfig.replaceWith,
|
|
18
|
+
})
|
|
19
|
+
: redactorConfig;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function composeChildRedactors<T extends AsyncCustomRedactorConfig>(opts: CompositeRedactorOptions<T> = {}) {
|
|
23
|
+
const childRedactors: T extends SyncCustomRedactorConfig
|
|
24
|
+
? Array<ISyncRedactor>
|
|
25
|
+
: Array<IAsyncRedactor | ISyncRedactor> = [] as any;
|
|
26
|
+
|
|
27
|
+
if (opts.customRedactors && opts.customRedactors.before) {
|
|
28
|
+
opts.customRedactors.before.map(normalizeCustomRedactorConfig).forEach((redactor) => childRedactors.push(redactor));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
for (const regexpName of Object.keys(simpleRegexpBuiltIns)) {
|
|
32
|
+
if (
|
|
33
|
+
!opts.builtInRedactors ||
|
|
34
|
+
!(opts.builtInRedactors as any)[regexpName] ||
|
|
35
|
+
(opts.builtInRedactors as any)[regexpName].enabled !== false
|
|
36
|
+
) {
|
|
37
|
+
childRedactors.push(
|
|
38
|
+
new SimpleRegexpRedactor({
|
|
39
|
+
regexpPattern: (simpleRegexpBuiltIns as any)[regexpName],
|
|
40
|
+
replaceWith: opts.globalReplaceWith || snakeCase(regexpName).toUpperCase(),
|
|
41
|
+
})
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!opts.builtInRedactors || !opts.builtInRedactors.names || opts.builtInRedactors.names.enabled !== false) {
|
|
47
|
+
childRedactors.push(new NameRedactor(opts.globalReplaceWith));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (opts.customRedactors && opts.customRedactors.after) {
|
|
51
|
+
opts.customRedactors.after.map(normalizeCustomRedactorConfig).forEach((redactor) => childRedactors.push(redactor));
|
|
52
|
+
}
|
|
53
|
+
return childRedactors;
|
|
54
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { composeChildRedactors } from './composition';
|
|
2
|
+
import { CompositeRedactorOptions, ISyncRedactor, SyncCustomRedactorConfig } from './types';
|
|
3
|
+
|
|
4
|
+
/** @public */
|
|
5
|
+
export interface SyncCompositeRedactorOptions extends CompositeRedactorOptions<SyncCustomRedactorConfig> {}
|
|
6
|
+
|
|
7
|
+
/** @public */
|
|
8
|
+
export class SyncRedactor implements ISyncRedactor {
|
|
9
|
+
private childRedactors: ISyncRedactor[] = [];
|
|
10
|
+
|
|
11
|
+
constructor(opts?: SyncCompositeRedactorOptions) {
|
|
12
|
+
this.childRedactors = composeChildRedactors(opts);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
redact = (textToRedact: string) => {
|
|
16
|
+
for (const redactor of this.childRedactors) {
|
|
17
|
+
textToRedact = redactor.redact(textToRedact);
|
|
18
|
+
}
|
|
19
|
+
return textToRedact;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as simpleRegexpBuiltIns from './built-ins/simple-regexp-patterns';
|
|
2
|
+
|
|
3
|
+
export interface ISyncRedactor {
|
|
4
|
+
redact(textToRedact: string): string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface IAsyncRedactor {
|
|
8
|
+
redactAsync(textToRedact: string): Promise<string>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type IRedactor = ISyncRedactor | IAsyncRedactor;
|
|
12
|
+
|
|
13
|
+
export interface SimpleRegexpCustomRedactorConfig {
|
|
14
|
+
regexpPattern: RegExp;
|
|
15
|
+
replaceWith: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type SyncCustomRedactorConfig = SimpleRegexpCustomRedactorConfig | ISyncRedactor;
|
|
19
|
+
|
|
20
|
+
export type AsyncCustomRedactorConfig = SyncCustomRedactorConfig | IAsyncRedactor;
|
|
21
|
+
|
|
22
|
+
export interface CompositeRedactorOptions<T extends AsyncCustomRedactorConfig> {
|
|
23
|
+
globalReplaceWith?: string;
|
|
24
|
+
builtInRedactors?: {
|
|
25
|
+
[RedactorName in keyof typeof simpleRegexpBuiltIns | 'names']?: {
|
|
26
|
+
enabled?: boolean;
|
|
27
|
+
replaceWith?: string;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
customRedactors?: {
|
|
31
|
+
before?: Array<T>;
|
|
32
|
+
after?: Array<T>;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SimpleRegexpCustomRedactorConfig, AsyncCustomRedactorConfig, ISyncRedactor, IRedactor } from './types';
|
|
2
|
+
|
|
3
|
+
export function isSimpleRegexpCustomRedactorConfig(
|
|
4
|
+
redactor: AsyncCustomRedactorConfig
|
|
5
|
+
): redactor is SimpleRegexpCustomRedactorConfig {
|
|
6
|
+
return typeof (redactor as SimpleRegexpCustomRedactorConfig).regexpPattern !== 'undefined';
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function isSyncRedactor(redactor: IRedactor): redactor is ISyncRedactor {
|
|
10
|
+
return typeof (redactor as ISyncRedactor).redact === 'function';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function snakeCase(str: string) {
|
|
14
|
+
return str.replace(/[A-Z]/g, (letter, index) => (index !== 0 ? `_${letter.toLowerCase()}` : letter.toLowerCase()));
|
|
15
|
+
}
|
package/vite.config.ts
CHANGED
|
@@ -21,11 +21,12 @@ export default defineConfig({
|
|
|
21
21
|
target: 'es2015',
|
|
22
22
|
sourcemap: true,
|
|
23
23
|
lib: {
|
|
24
|
-
entry:
|
|
24
|
+
entry: 'index.ts',
|
|
25
|
+
name: 'BrainfishAnalytics',
|
|
25
26
|
formats: ['es', 'cjs'],
|
|
26
|
-
fileName: (format,
|
|
27
|
+
fileName: (format, entry) => `${entry}${format === 'es' ? '' : '.cjs'}.js`,
|
|
27
28
|
},
|
|
28
|
-
minify:
|
|
29
|
+
minify: true,
|
|
29
30
|
terserOptions: {
|
|
30
31
|
compress: {
|
|
31
32
|
drop_console: true,
|
|
@@ -36,15 +37,19 @@ export default defineConfig({
|
|
|
36
37
|
treeshake: true,
|
|
37
38
|
plugins: [terser()],
|
|
38
39
|
external: ['@google-cloud/dlp'],
|
|
40
|
+
output: {
|
|
41
|
+
inlineDynamicImports: true, // Ensures all imports are inlined into the main bundle
|
|
42
|
+
manualChunks: undefined, // Disables code splitting
|
|
43
|
+
},
|
|
39
44
|
},
|
|
40
45
|
},
|
|
41
46
|
test: {
|
|
42
47
|
environment: 'jsdom',
|
|
43
48
|
},
|
|
44
49
|
define: {
|
|
45
|
-
|
|
50
|
+
'import.meta.env.PACKAGE_VERSION': JSON.stringify(version),
|
|
46
51
|
},
|
|
47
52
|
optimizeDeps: {
|
|
48
53
|
include: ['@brainfish-ai/tracker-sdk'],
|
|
49
|
-
}
|
|
54
|
+
},
|
|
50
55
|
});
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|