@ya-accelerators/nextjs-framework 0.0.120 → 0.0.122

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.
@@ -0,0 +1,7 @@
1
+ export declare const SANITIZE_DECLARATION_FIELD = "sanitizeKeys";
2
+ export type SanitizeDeclaration = {
3
+ keywords: string[];
4
+ exactKeys: string[];
5
+ };
6
+ export declare const emptySanitizeDeclaration: () => SanitizeDeclaration;
7
+ export declare const parseSanitizeDeclaration: (declared: unknown, source: string) => SanitizeDeclaration;
@@ -0,0 +1,44 @@
1
+ // A package adds the log keys its own domain needs redacted, as the `sanitizeKeys` field of its own
2
+ // `package.json`. `Util.sanitize` and the sanitize-coverage gate both read it through this module and
3
+ // `sanitize-declaration-file.ts` beside it, so a declaration one accepted and the other refused cannot
4
+ // make the set the gate judges differ from the set in force.
5
+ //
6
+ // It is additive: the framework's own lists decide what is redacted everywhere, and a package only adds
7
+ // to them for itself. It lives in `package.json` because the release image copies that file for every
8
+ // package it carries.
9
+ //
10
+ // This module is copied into `nextjs-framework`, whose `Util.sanitize` is reachable from Next's client
11
+ // bundle, so it imports no Node built-in. Reading a manifest is `sanitize-declaration-file.ts`, which no
12
+ // client bundle reaches.
13
+ export const SANITIZE_DECLARATION_FIELD = 'sanitizeKeys';
14
+ export const emptySanitizeDeclaration = () => ({ keywords: [], exactKeys: [] });
15
+ export const parseSanitizeDeclaration = (declared, source) => {
16
+ if (declared === undefined) {
17
+ return emptySanitizeDeclaration();
18
+ }
19
+ if (typeof declared !== 'object' || declared === null || Array.isArray(declared)) {
20
+ throw new Error(`${source} must be an object carrying "keywords" and / or "exactKeys"`);
21
+ }
22
+ const listOf = (name) => {
23
+ const value = declared[name] ?? [];
24
+ if (!Array.isArray(value) || value.some((entry) => typeof entry !== 'string')) {
25
+ throw new Error(`${source}: "${name}" must be an array of strings`);
26
+ }
27
+ return value;
28
+ };
29
+ const declaration = { keywords: listOf('keywords'), exactKeys: listOf('exactKeys') };
30
+ const entries = [...declaration.keywords, ...declaration.exactKeys];
31
+ // An empty keyword makes `key.includes(entry)` true for every key, so one blank entry redacts every
32
+ // value the package logs while the gate reports every column covered.
33
+ if (entries.some((entry) => entry !== entry.trim() || entry === '')) {
34
+ throw new Error(`${source}: an entry must not be empty or padded`);
35
+ }
36
+ // The key matcher lowercases the key and compares it against the entry as given, so an entry that is
37
+ // not itself lowercase matches nothing while reading as covering a column.
38
+ const uppercase = entries.filter((entry) => entry !== entry.toLowerCase());
39
+ if (uppercase.length > 0) {
40
+ throw new Error(`${source}: every entry must be lowercase (${uppercase.join(', ')})`);
41
+ }
42
+ return declaration;
43
+ };
44
+ //# sourceMappingURL=sanitize-declaration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sanitize-declaration.js","sourceRoot":"","sources":["../../../../src/.generated/policy/sanitize-declaration.ts"],"names":[],"mappings":"AAAA,oGAAoG;AACpG,sGAAsG;AACtG,uGAAuG;AACvG,6DAA6D;AAC7D,EAAE;AACF,wGAAwG;AACxG,sGAAsG;AACtG,sBAAsB;AACtB,EAAE;AACF,uGAAuG;AACvG,yGAAyG;AACzG,yBAAyB;AACzB,MAAM,CAAC,MAAM,0BAA0B,GAAG,cAAc,CAAA;AAIxD,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAwB,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CAAA;AAEpG,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,QAAiB,EAAE,MAAc,EAAE,EAAE;IAC5E,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,OAAO,wBAAwB,EAAE,CAAA;IACnC,CAAC;IACD,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QACjF,MAAM,IAAI,KAAK,CAAC,GAAG,MAAM,6DA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OAAO,WAAW,CAAA;AACpB,CAAC,CAAA"}
@@ -0,0 +1 @@
1
+ export declare const consumerSanitizeKeys: import("./.generated/policy/sanitize-declaration").SanitizeDeclaration;
@@ -0,0 +1,10 @@
1
+ import { emptySanitizeDeclaration, parseSanitizeDeclaration } from './.generated/policy/sanitize-declaration';
2
+ // The running package's own additions, inlined by the shared Next config at build time. The manifest is
3
+ // read there rather than here because a client bundle reaches this module and has no file system. Next
4
+ // substitutes `process.env.NEXT_PUBLIC_SANITIZE_KEYS` only where it is written as that member expression,
5
+ // so reading it through a variable or a helper leaves the browser bundle with no declaration and nothing
6
+ // reporting it.
7
+ export const consumerSanitizeKeys = process.env.NEXT_PUBLIC_SANITIZE_KEYS
8
+ ? parseSanitizeDeclaration(JSON.parse(process.env.NEXT_PUBLIC_SANITIZE_KEYS), 'NEXT_PUBLIC_SANITIZE_KEYS')
9
+ : emptySanitizeDeclaration();
10
+ //# sourceMappingURL=sanitize-keys.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sanitize-keys.js","sourceRoot":"","sources":["../../src/sanitize-keys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,MAAM,0CAA0C,CAAA;AAE7G,wGAAwG;AACxG,uGAAuG;AACvG,0GAA0G;AAC1G,yGAAyG;AACzG,gBAAgB;AAChB,MAAM,CAAC,MAAM,oBAAoB,GAAG,OAAO,CAAC,GAAG,CAAC,yBAAyB;IACvE,CAAC,CAAC,wBAAwB,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC,EAAE,2BAA2B,CAAC;IAC1G,CAAC,CAAC,wBAAwB,EAAE,CAAA"}