@nodii/dev 0.6.148 → 0.6.150
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/README.md +6 -1
- package/dist/cli.js +1 -1
- package/dist/core.js +1 -1
- package/dist/flags.js +1 -1
- package/dist/review.js +59 -2
- package/dist/surface.js +24 -6
- package/dist/vendor/ds-conformance.mjs +190 -24
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -938,7 +938,7 @@ run the same command again.
|
|
|
938
938
|
### Product pages from Surfaces: `surface generate` (MW8-17)
|
|
939
939
|
|
|
940
940
|
```sh
|
|
941
|
-
nodii-dev surface generate <componentSetKey|route> [--write] [--check] [--fetch] [--figma-version V] [--report FILE] [--post-scoreboard ISSUE] [--resume]
|
|
941
|
+
nodii-dev surface generate <componentSetKey|route> [--write] [--check] [--fetch] [--figma-version V [--node ID]] [--report FILE] [--post-scoreboard ISSUE] [--resume]
|
|
942
942
|
nodii-dev surface generate --all [--module M] [--type page|dialog] [--write] [--check] [--fetch] [--figma-version V] [--report FILE] [--post-scoreboard ISSUE] [--resume]
|
|
943
943
|
```
|
|
944
944
|
|
|
@@ -959,6 +959,11 @@ product-page catalog names the Surface by its published component-set key
|
|
|
959
959
|
version unlabelled. A file with no published rows, or with no version the
|
|
960
960
|
publish closed among its newest 40, is refused with
|
|
961
961
|
`SURFACE_FILE_NOT_PUBLISHED`. `--figma-version V` names a version outright.
|
|
962
|
+
A Surface new to its file is not in the published listing yet
|
|
963
|
+
(`SURFACE_NOT_PUBLISHED`); `--node ID` (only with `--fetch --figma-version V`
|
|
964
|
+
and one named key) locates its set at V, and the read is refused with
|
|
965
|
+
`SURFACE_NODE_KEY_MISMATCH` unless that set's key is the catalog row's. The
|
|
966
|
+
key stays the reference and the node id is not stored (cli-144).
|
|
962
967
|
Without `--fetch`, the committed tree under
|
|
963
968
|
`docs/figma-ux-ds/figma/surface-trees/<fileKey>/<componentSetKey>.json` is
|
|
964
969
|
read and Figma is not called.
|
package/dist/cli.js
CHANGED
|
@@ -185,7 +185,7 @@ Usage: nodii-dev <command> [options] [--json]
|
|
|
185
185
|
# values not bound to a variable and non-DS instances; submit reports the
|
|
186
186
|
# same on any Surface node a set touches (refuses where the host enforces).
|
|
187
187
|
# Reads Figma on Dev's token; exit 1 = SURFACES_CHECK_FAILED
|
|
188
|
-
surface generate <componentSetKey|route> [--write] [--check] [--fetch] [--figma-version V] [--report FILE] [--post-scoreboard ISSUE] [--resume]
|
|
188
|
+
surface generate <componentSetKey|route> [--write] [--check] [--fetch] [--figma-version V [--node ID]] [--report FILE] [--post-scoreboard ISSUE] [--resume]
|
|
189
189
|
surface generate --all [--module M] [--type page|dialog] [--write] [--check] [--fetch] [--figma-version V] [--report FILE] [--post-scoreboard ISSUE] [--resume]
|
|
190
190
|
# a Surface -> its product page's presentational code, from Code Connect
|
|
191
191
|
# (MW8-17), in a design-system checkout. --fetch reads Figma (FIGMA_PAT, one
|
package/dist/core.js
CHANGED
|
@@ -4,7 +4,7 @@ import { chmod, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
|
4
4
|
import { homedir, platform } from "node:os";
|
|
5
5
|
import { dirname, join } from "node:path";
|
|
6
6
|
|
|
7
|
-
export const VERSION = "0.6.
|
|
7
|
+
export const VERSION = "0.6.150";
|
|
8
8
|
export const configPath = () =>
|
|
9
9
|
process.env.NODII_DEV_CONFIG_PATH ??
|
|
10
10
|
join(homedir(), ".config/nodii-dev/config.json");
|
package/dist/flags.js
CHANGED
|
@@ -77,7 +77,7 @@ export const COMMAND_FLAGS = {
|
|
|
77
77
|
"figma apply": ["file", "figma-version", "lane-reads"],
|
|
78
78
|
"figma lock": ["title", "scope", "lane-reads"],
|
|
79
79
|
"figma scope": ["scope", "lane-reads"],
|
|
80
|
-
"surface generate": ["write", "check", "fetch", "all", "module", "type", "figma-version", "report", "post-scoreboard", "resume"],
|
|
80
|
+
"surface generate": ["write", "check", "fetch", "all", "module", "type", "figma-version", "node", "report", "post-scoreboard", "resume"],
|
|
81
81
|
};
|
|
82
82
|
|
|
83
83
|
/** Refuse a flag the command does not declare (USAGE, exit 2), naming the valid ones. */
|
package/dist/review.js
CHANGED
|
@@ -12,6 +12,7 @@ import { promisify } from "node:util";
|
|
|
12
12
|
import { CliError, encode } from "./core.js";
|
|
13
13
|
import { pickerPrompt } from "./gather.js";
|
|
14
14
|
import { componentSetsIn, designCatalogSets } from "./figma-scope.js";
|
|
15
|
+
import { holdsSet, scopeText } from "./figma.js";
|
|
15
16
|
import { gitPrivatePath } from "./safety.js";
|
|
16
17
|
import { GENERATED_PAGE_GLOB, GENERATED_SUFFIX, hasGeneratedPageStamp } from "./surface.js";
|
|
17
18
|
import { VALUE_FLAGS } from "./impact.js";
|
|
@@ -639,6 +640,52 @@ export async function laneChangeSetNodes(request, agentId, fileKeys, templates =
|
|
|
639
640
|
return scoped;
|
|
640
641
|
}
|
|
641
642
|
|
|
643
|
+
/**
|
|
644
|
+
* NODII-DEV-CLI-141 (MW1-57.6): a Surfaces file whose Freeze boundary names no
|
|
645
|
+
* component set is checked on the lock scopes the lane's agent holds there
|
|
646
|
+
* (Dev's lock check), never silently as the whole shared file. Each page,
|
|
647
|
+
* section or component scope is a frame; a create scope has no node of its
|
|
648
|
+
* own, so the set's live items are. Findings in the scope still block: nothing
|
|
649
|
+
* here is file debt, and the whole file is not read. A whole-file lock, or no
|
|
650
|
+
* held set, leaves the file whole, and wholeFile says why.
|
|
651
|
+
* Returns { scoped: { fileKey: { changeSets, nodes, items, templates, lockScopes, fileDebt: false } }, wholeFile: [{ fileKey, reason }] }.
|
|
652
|
+
*/
|
|
653
|
+
export async function laneSurfaceScopes(request, agentId, boundary, templates = []) {
|
|
654
|
+
const candidates = [...new Set(boundary.filter((file) => !file.componentSetKeys?.length).map((file) => file.fileKey))];
|
|
655
|
+
const result = { scoped: {}, wholeFile: [] };
|
|
656
|
+
if (!candidates.length) return result;
|
|
657
|
+
const files = (await request("GET", "/api/v1/design/files")).data ?? [];
|
|
658
|
+
const surfaces = new Set(files.filter((file) => file.kind === "surfaces").map((file) => file.fileKey));
|
|
659
|
+
for (const fileKey of candidates.filter((key) => surfaces.has(key))) {
|
|
660
|
+
const check = agentId ? (await request("GET", `/api/v1/design/files/${encode(fileKey)}/lock/check?agentId=${encode(agentId)}`)).data : null;
|
|
661
|
+
if (!holdsSet(check)) {
|
|
662
|
+
result.wholeFile.push({ fileKey, reason: `the lane's agent holds no change set in ${fileKey}, so it has no scope to check and the whole file is checked (CLI-141)` });
|
|
663
|
+
continue;
|
|
664
|
+
}
|
|
665
|
+
const scopes = (check.scopes ?? []).filter((s) => !s.releasedAt && (!s.changeSetId || s.changeSetId === check.changeSetId));
|
|
666
|
+
if (!scopes.length || scopes.some((s) => s.kind === "file")) {
|
|
667
|
+
result.wholeFile.push({ fileKey, reason: `${check.changeSetId} holds the whole file, so the whole file is checked (CLI-141)` });
|
|
668
|
+
continue;
|
|
669
|
+
}
|
|
670
|
+
const nodes = new Set();
|
|
671
|
+
const items = [];
|
|
672
|
+
const add = (nodeId, extra) => { if (!nodes.has(nodeId)) items.push({ nodeId, ...extra }); nodes.add(nodeId); };
|
|
673
|
+
for (const s of scopes) if (s.nodeId && ["page", "section", "component"].includes(s.kind)) add(s.nodeId, { changeSet: check.changeSetId });
|
|
674
|
+
if (scopes.some((s) => !s.nodeId)) {
|
|
675
|
+
const set = (await request("GET", `/api/v1/design/change-sets/${encode(check.changeSetId)}`)).data;
|
|
676
|
+
for (const item of set?.items ?? []) if (item.decision !== "withdrawn" && item.change !== "removed" && item.figmaNodeId) add(item.figmaNodeId, { changeSet: check.changeSetId });
|
|
677
|
+
}
|
|
678
|
+
const touched = templates.filter((unit) => unit.fileKey === fileKey);
|
|
679
|
+
for (const unit of touched) add(unit.nodeId, { template: unit.template });
|
|
680
|
+
result.scoped[fileKey] = {
|
|
681
|
+
changeSets: [check.changeSetId], nodes: [...nodes], items,
|
|
682
|
+
templates: [...new Set(touched.map((unit) => unit.template))],
|
|
683
|
+
lockScopes: [...new Set(scopes.map(scopeText))], fileDebt: false,
|
|
684
|
+
};
|
|
685
|
+
}
|
|
686
|
+
return result;
|
|
687
|
+
}
|
|
688
|
+
|
|
642
689
|
/** A Figma link's file key and node id (`1-2` in a link, `1:2` in the API), or null. */
|
|
643
690
|
export function figmaLinkNode(url) {
|
|
644
691
|
let parsed;
|
|
@@ -747,7 +794,7 @@ export async function swapFor(swaps, { fileKey, nodeId }, readSet) {
|
|
|
747
794
|
* Without a Swap in Dev whose change set holds the node (swapFor), or when
|
|
748
795
|
* Dev's Swaps or change sets can't be read, the missing node stays a finding.
|
|
749
796
|
*/
|
|
750
|
-
export async function figmaFindings(figma, { catalog, check, changeSets = {}, swaps, readSet, lookupSet }) {
|
|
797
|
+
export async function figmaFindings(figma, { catalog, check, changeSets = {}, swaps, readSet, lookupSet, wholeFile = [] }) {
|
|
751
798
|
const scopedFrames = Object.entries(changeSets).flatMap(([fileKey, scoped]) => scoped.nodes.map((nodeId) => {
|
|
752
799
|
const item = scoped.items?.find((x) => x.nodeId === nodeId);
|
|
753
800
|
return { fileKey, nodeId, state: "default", ...(item ? { changeSet: item.changeSet } : {}) };
|
|
@@ -802,6 +849,8 @@ export async function figmaFindings(figma, { catalog, check, changeSets = {}, sw
|
|
|
802
849
|
// verdict as it is (a whole-file DS check is never required, MW2-38.3).
|
|
803
850
|
const fileDebt = [];
|
|
804
851
|
for (const [fileKey, scoped] of Object.entries(changeSets)) {
|
|
852
|
+
// CLI-141: a Surfaces file scoped by its lock is never read whole.
|
|
853
|
+
if (scoped.fileDebt === false) continue;
|
|
805
854
|
const units = new Set(scoped.nodes);
|
|
806
855
|
let data;
|
|
807
856
|
try { data = (await check(fileKey, {})).payload.data; }
|
|
@@ -835,6 +884,8 @@ export async function figmaFindings(figma, { catalog, check, changeSets = {}, sw
|
|
|
835
884
|
...(scopedFiles.some(([, scoped]) => scoped.changeSets.length) ? { changeSets: scopedFiles.filter(([, scoped]) => scoped.changeSets.length).map(([fileKey, scoped]) => ({ fileKey, ids: scoped.changeSets, nodes: (scoped.items ?? []).filter((x) => x.changeSet).length || scoped.nodes.length })) } : {}),
|
|
836
885
|
...(scopedFiles.some(([, scoped]) => scoped.templates?.length) ? { templates: scopedFiles.filter(([, scoped]) => scoped.templates?.length).map(([fileKey, scoped]) => ({ fileKey, paths: scoped.templates, nodes: (scoped.items ?? []).filter((x) => x.template).map((x) => x.nodeId) })) } : {}),
|
|
837
886
|
...(fileDebt.length ? { fileDebt } : {}),
|
|
887
|
+
...(scopedFiles.some(([, scoped]) => scoped.lockScopes?.length) ? { lockScopes: scopedFiles.filter(([, scoped]) => scoped.lockScopes?.length).map(([fileKey, scoped]) => ({ fileKey, changeSet: scoped.changeSets[0], scopes: scoped.lockScopes })) } : {}),
|
|
888
|
+
...(wholeFile.length ? { wholeFile } : {}),
|
|
838
889
|
},
|
|
839
890
|
};
|
|
840
891
|
}
|
|
@@ -1006,8 +1057,14 @@ export async function runLaneCheck(ref, flags, { request, lane, freeze, current,
|
|
|
1006
1057
|
catch (error) {
|
|
1007
1058
|
throw new ReviewerError(UNAVAILABLE, `the lane's change sets could not be read from Dev (${error?.code ?? "ERROR"}: ${error?.message ?? error}), so the Figma check cannot be scoped to their nodes (MW2-38.3) and did not fall back to the whole file`);
|
|
1008
1059
|
}
|
|
1060
|
+
let surfaceScopes;
|
|
1061
|
+
try { surfaceScopes = await laneSurfaceScopes(request, lane.agentId, boundary.filter((file) => !changeSets[file.fileKey]), touched); }
|
|
1062
|
+
catch (error) {
|
|
1063
|
+
throw new ReviewerError(UNAVAILABLE, `the lane's Figma lock scopes could not be read from Dev (${error?.code ?? "ERROR"}: ${error?.message ?? error}), so the Figma check cannot be scoped to them (CLI-141) and did not fall back to the whole file`);
|
|
1064
|
+
}
|
|
1065
|
+
changeSets = { ...changeSets, ...surfaceScopes.scoped };
|
|
1009
1066
|
let checked;
|
|
1010
|
-
try { checked = await figmaFindings(boundary, { catalog, check: designCheck, changeSets, swaps: () => removalSwaps(request), readSet: async (id) => (await request("GET", `/api/v1/design/change-sets/${encodeURIComponent(id)}`)).data }); }
|
|
1067
|
+
try { checked = await figmaFindings(boundary, { catalog, check: designCheck, changeSets, wholeFile: surfaceScopes.wholeFile, swaps: () => removalSwaps(request), readSet: async (id) => (await request("GET", `/api/v1/design/change-sets/${encodeURIComponent(id)}`)).data }); }
|
|
1011
1068
|
catch (error) {
|
|
1012
1069
|
if (error instanceof ReviewerError) throw error;
|
|
1013
1070
|
// A Figma outage (a read past its clock, no answer, rate limited) means
|
package/dist/surface.js
CHANGED
|
@@ -51,9 +51,11 @@ const FIGMA_API = "https://api.figma.com/v1";
|
|
|
51
51
|
export const MIN_FIGMA_INTERVAL_MS = 8_000;
|
|
52
52
|
const BACKOFF_MS = 30_000;
|
|
53
53
|
const SET_KEY = /^[0-9a-f]{40}$/;
|
|
54
|
+
/** A set's node id, as the REST API (5:0) or a Figma URL (5-0) writes it. */
|
|
55
|
+
const NODE_ID = /^(\d+)[:-](\d+)$/;
|
|
54
56
|
|
|
55
57
|
export const SURFACE_USAGE =
|
|
56
|
-
"surface generate <componentSetKey|route> [--write] [--check] [--fetch] [--figma-version V] [--report FILE] [--post-scoreboard ISSUE] [--resume]\n" +
|
|
58
|
+
"surface generate <componentSetKey|route> [--write] [--check] [--fetch] [--figma-version V [--node ID]] [--report FILE] [--post-scoreboard ISSUE] [--resume]\n" +
|
|
57
59
|
"surface generate --all [--module M] [--type page|dialog] [--write] [--check] [--fetch] [--figma-version V] [--report FILE] [--post-scoreboard ISSUE] [--resume]";
|
|
58
60
|
|
|
59
61
|
// ---------------------------------------------------------------------------
|
|
@@ -260,13 +262,21 @@ export async function lastPublishedVersion(figmaGet, fileKey, { library } = {})
|
|
|
260
262
|
throw new CliError("SURFACE_FILE_NOT_PUBLISHED", `${fileKey}: none of its newest ${MAX_VERSION_READS} versions closed at or before its last library publish (${publishedAt}); name a version with --figma-version`, 1);
|
|
261
263
|
}
|
|
262
264
|
|
|
263
|
-
/**
|
|
264
|
-
|
|
265
|
-
|
|
265
|
+
/**
|
|
266
|
+
* Read one Surface set at a file version and trim it to what the generator reads.
|
|
267
|
+
* `node` locates a set new to its file, not yet in its published listing (cli-144):
|
|
268
|
+
* the read is refused unless that node's set has the catalog row's key, which stays
|
|
269
|
+
* the reference (MW8-20); the node id is not kept.
|
|
270
|
+
*/
|
|
271
|
+
export async function fetchSurfaceTree(figmaGet, row, { index, version, node }) {
|
|
272
|
+
const nodeId = node ?? index.get(row.componentSetKey);
|
|
266
273
|
if (!nodeId) throw new CliError("SURFACE_NOT_PUBLISHED", `${row.componentSetName ?? row.id}: component set ${row.componentSetKey} is not among ${row.fileKey}'s published component sets`, 1);
|
|
267
274
|
const body = await figmaGet(`/files/${encodeURIComponent(row.fileKey)}/nodes?ids=${encodeURIComponent(nodeId)}${version ? `&version=${encodeURIComponent(version)}` : ""}`);
|
|
268
275
|
const entry = body.nodes?.[nodeId];
|
|
269
276
|
if (!entry?.document) throw new CliError("FIGMA_NOT_FOUND", `Figma returned no document for ${row.componentSetName ?? row.id}`, 1);
|
|
277
|
+
const found = node ? (entry.document.type === "COMPONENT_SET" ? (entry.componentSets?.[nodeId]?.key ?? null) : null) : row.componentSetKey;
|
|
278
|
+
if (found !== row.componentSetKey)
|
|
279
|
+
throw new CliError("SURFACE_NODE_KEY_MISMATCH", `${row.componentSetName ?? row.id}: node ${nodeId} at version ${version} is ${found ? `component set ${found}` : "not a component set"}, not the catalog's ${row.componentSetKey}; --node only locates the catalog row's own set (cli-144, MW8-20)`, 1);
|
|
270
280
|
return trimTree(entry, { row, version: version ?? body.version ?? null });
|
|
271
281
|
}
|
|
272
282
|
|
|
@@ -2722,6 +2732,14 @@ export async function surfaceCommand(action, rest, f, deps = {}) {
|
|
|
2722
2732
|
if (f.write && f.check) throw new CliError("USAGE", "--write and --check are separate runs: --write updates the files, --check refuses a difference", 2);
|
|
2723
2733
|
if (f.check && f.fetch) throw new CliError("USAGE", "--check regenerates from the committed trees and never reads Figma; drop --fetch", 2);
|
|
2724
2734
|
if (f.resume && !(f.fetch && f.write)) throw new CliError("USAGE", "--resume continues a stopped read: use it with --fetch --write", 2);
|
|
2735
|
+
// --node locates one named Surface that is new to its file at a named version (cli-144).
|
|
2736
|
+
const nodeMatch = f.node === undefined ? null : NODE_ID.exec(String(f.node));
|
|
2737
|
+
if (f.node !== undefined) {
|
|
2738
|
+
if (!nodeMatch) throw new CliError("USAGE", `--node needs a component set's node id, for example 5:0: got ${f.node === true ? "nothing" : f.node}`, 2);
|
|
2739
|
+
if (!f.fetch || !f["figma-version"] || f["figma-version"] === true) throw new CliError("USAGE", "--node reads Figma at a named version: use it with --fetch --figma-version V", 2);
|
|
2740
|
+
if (f.all || !SET_KEY.test(rest[0] ?? "")) throw new CliError("USAGE", "--node locates one Surface: name it by its component-set key, not --all or a route", 2);
|
|
2741
|
+
}
|
|
2742
|
+
const node = nodeMatch ? `${nodeMatch[1]}:${nodeMatch[2]}` : undefined;
|
|
2725
2743
|
const postTo = f["post-scoreboard"];
|
|
2726
2744
|
if (postTo === true || postTo === "") throw new CliError("USAGE", "--post-scoreboard needs an issue key, for example DESIGN-SYSTEM-249", 2);
|
|
2727
2745
|
const { env = process.env, exec = execFileSync, log = (line) => process.stderr.write(`${line}\n`), figmaGet: injected, docs, cwd } = deps;
|
|
@@ -2791,7 +2809,7 @@ export async function surfaceCommand(action, rest, f, deps = {}) {
|
|
|
2791
2809
|
continue;
|
|
2792
2810
|
}
|
|
2793
2811
|
}
|
|
2794
|
-
if (!indexes.has(row.fileKey)) indexes.set(row.fileKey, await setIndex(figmaGet, row.fileKey));
|
|
2812
|
+
if (!node && !indexes.has(row.fileKey)) indexes.set(row.fileKey, await setIndex(figmaGet, row.fileKey));
|
|
2795
2813
|
// --all covers a module: one unpublished Surface is reported, and the rest still generate.
|
|
2796
2814
|
// A Surface named on its own stays a refusal, because the run has nothing else to do.
|
|
2797
2815
|
if (f.all && !indexes.get(row.fileKey).has(row.componentSetKey)) {
|
|
@@ -2800,7 +2818,7 @@ export async function surfaceCommand(action, rest, f, deps = {}) {
|
|
|
2800
2818
|
continue;
|
|
2801
2819
|
}
|
|
2802
2820
|
log(`reading ${row.componentSetName ?? row.id} from Figma at version ${version}`);
|
|
2803
|
-
tree = await fetchSurfaceTree(figmaGet, row, { index: indexes.get(row.fileKey), version });
|
|
2821
|
+
tree = await fetchSurfaceTree(figmaGet, row, { index: indexes.get(row.fileKey), version, node });
|
|
2804
2822
|
} catch (error) {
|
|
2805
2823
|
// --all keeps what it read and scores it; a Surface named on its own has nothing to keep.
|
|
2806
2824
|
if (!f.all || error?.code !== "FIGMA_RATE_LIMITED") throw error;
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
// it until it returns [] (each round can reveal instances inside slot
|
|
31
31
|
// content).
|
|
32
32
|
|
|
33
|
-
export const VERSION = "1.0.
|
|
33
|
+
export const VERSION = "1.0.16";
|
|
34
34
|
|
|
35
35
|
/** @typedef {{ nodeId: string, check: string, detail: string }} Finding */
|
|
36
36
|
/**
|
|
@@ -140,6 +140,26 @@ const PERSON_NAME_COMPONENT_SET_KEY =
|
|
|
140
140
|
"08370f38bcbbcf88eaf3a6923dc91b5de5f38ea0";
|
|
141
141
|
const TABLE_COMPONENT_SET_KEY = "7ccc1dbb6ebd149fb9aaf42b9c638f5ce7169638";
|
|
142
142
|
const TABLE_CELL_COMPONENT_SET_KEY = "528898c19702ed4b169d023de30380e05169dfa5";
|
|
143
|
+
// The sets a product screen composes a library component from, by the name
|
|
144
|
+
// of the frame that holds them (hub-488). The library publishes the table's
|
|
145
|
+
// header, cells and tree rows as sets of their own, so a product table is a
|
|
146
|
+
// frame of rows of them. These are the Table entry's family sets in the
|
|
147
|
+
// design catalogue (figma.familySets): Table cell, Table Header, Table Rich
|
|
148
|
+
// Cell, Table Tree Branch Row, Table Tree Leaf Row. Listed by key, not by a
|
|
149
|
+
// "Table " name prefix: Alert Dialog is no part of Alert, nor Button Group
|
|
150
|
+
// of Button, and another file's set of the same name is not the library's.
|
|
151
|
+
const LIBRARY_PARTS = new Map([
|
|
152
|
+
[
|
|
153
|
+
"Table",
|
|
154
|
+
new Set([
|
|
155
|
+
TABLE_CELL_COMPONENT_SET_KEY,
|
|
156
|
+
"00021ae4ef4ba8069387315ad45ff56b7d850060",
|
|
157
|
+
"7addadd082840b7593cee54da20029fa33a30404",
|
|
158
|
+
"f6c4560fd9b9bd2d552b3b173616b3251e9f35f8",
|
|
159
|
+
"b1a781204386a699581a1a1ef332b21c8f35f454",
|
|
160
|
+
]),
|
|
161
|
+
],
|
|
162
|
+
]);
|
|
143
163
|
const ITEM_COMPONENT_SET_KEY = "46abc8cb0d57c22a365da94a03cfd72a0b089b87";
|
|
144
164
|
const SELF_COMPONENT_SET_KEYS = new Set([
|
|
145
165
|
"af8df2e85ba4d53b26b28ffa69f264758a50fe66", // Account Context
|
|
@@ -173,6 +193,20 @@ const PERSON_FIELD =
|
|
|
173
193
|
/\b(user|member|customer|recipient|applicant|employee|candidate|assignee|owner|invitee|requester|reviewer|agent|engineer|staff|rep|manager|person|personal|your|my)\b/i;
|
|
174
194
|
// A field's frame names its label: field/Caller ID, select/Sender ID.
|
|
175
195
|
const FIELD_FRAME = /^(field|select|input|textarea|kv|detail|row) ?\/ ?(.+)$/i;
|
|
196
|
+
// A field part from the library: its value, label and hint are one field.
|
|
197
|
+
const FIELD_PART = /\b(field|input|text ?area|select|kv)\b/i;
|
|
198
|
+
// A field's label or hint that says the value is the viewer's own
|
|
199
|
+
// (hub-236): "Your own address is filled in", "Your email",
|
|
200
|
+
// "Your phone number". "Your provider" or "your customer's email" is not.
|
|
201
|
+
const SELF_FIELD =
|
|
202
|
+
/\byour (own\b|(e-?mail|email address|address|phone|phone number|mobile|mobile number|name|full name)\b)/i;
|
|
203
|
+
// "(you)" marks the viewer in a list, picker or people cell (U05-7).
|
|
204
|
+
const YOU_MARKER = /\(you\)/i;
|
|
205
|
+
// An Aadhaar number: twelve digits, the first 2-9, grouped 4-4-4 as it is
|
|
206
|
+
// written. It stays last-four for every viewer, its owner too (PII-26).
|
|
207
|
+
const AADHAAR = /(?<![\w.+\-/])[2-9]\d{3}[ -]\d{4}[ -]\d{4}(?![\w\-/])/g;
|
|
208
|
+
const AADHAAR_RUN = /(?<![\w.+\-/])[2-9]\d{11}(?![\w\-/])/g;
|
|
209
|
+
const AADHAAR_FIELD = /\baadhaa?r\b/i;
|
|
176
210
|
|
|
177
211
|
/** "I12:34;56:78" -> ["12:34", "56:78"]; "12:34" -> ["12:34"]. */
|
|
178
212
|
const segments = (id) => (id.startsWith("I") ? id.slice(1) : id).split(";");
|
|
@@ -362,6 +396,8 @@ function analyse(entry, mains, library = false) {
|
|
|
362
396
|
};
|
|
363
397
|
const componentLabel = (inst) =>
|
|
364
398
|
setOf(inst)?.name ?? componentOf(inst)?.name ?? inst.name;
|
|
399
|
+
const setNameOf = (id) =>
|
|
400
|
+
componentSets[components[id]?.componentSetId]?.name;
|
|
365
401
|
// What the app-UI gate leaves out: each root, outermost first (byId is in
|
|
366
402
|
// document order, so a parent is decided before its children).
|
|
367
403
|
/** @type {Map<string, string>} */
|
|
@@ -375,7 +411,7 @@ function analyse(entry, mains, library = false) {
|
|
|
375
411
|
out.add(n.id);
|
|
376
412
|
continue;
|
|
377
413
|
}
|
|
378
|
-
const why = outOfScopeRoot(n, parent, componentLabel, placedMemo);
|
|
414
|
+
const why = outOfScopeRoot(n, parent, componentLabel, placedMemo, setNameOf);
|
|
379
415
|
if (why) {
|
|
380
416
|
out.add(n.id);
|
|
381
417
|
scopeRoots.set(n.id, why);
|
|
@@ -385,6 +421,7 @@ function analyse(entry, mains, library = false) {
|
|
|
385
421
|
root,
|
|
386
422
|
components,
|
|
387
423
|
componentSets,
|
|
424
|
+
setNameOf,
|
|
388
425
|
styles: entry.styles ?? {},
|
|
389
426
|
byId,
|
|
390
427
|
parent,
|
|
@@ -401,20 +438,27 @@ function analyse(entry, mains, library = false) {
|
|
|
401
438
|
};
|
|
402
439
|
}
|
|
403
440
|
|
|
404
|
-
const emailKitPart = (n, parent, componentLabel) =>
|
|
441
|
+
const emailKitPart = (n, parent, componentLabel, setNameOf) =>
|
|
405
442
|
(n.type === "INSTANCE" && EMAIL_KIT.test(componentLabel(n) ?? "")) ||
|
|
406
443
|
((n.type === "COMPONENT" || n.type === "COMPONENT_SET") &&
|
|
407
444
|
(EMAIL_KIT.test(n.name ?? "") ||
|
|
408
445
|
(n.type === "COMPONENT" &&
|
|
409
|
-
EMAIL_KIT.test(
|
|
446
|
+
EMAIL_KIT.test(setOfComponent(n, parent, setNameOf) ?? ""))));
|
|
447
|
+
/**
|
|
448
|
+
* The name of a variant's set: its parent in the walked tree, or, for a
|
|
449
|
+
* submitted variant that is its own root, the set Figma's components map
|
|
450
|
+
* names for it.
|
|
451
|
+
*/
|
|
452
|
+
const setOfComponent = (n, parent, setNameOf) =>
|
|
453
|
+
parent.get(n.id)?.name ?? setNameOf?.(n.id);
|
|
410
454
|
/**
|
|
411
455
|
* Why a node and everything in it is outside the app-UI gate, or null: an
|
|
412
456
|
* Email kit part, an email made of them (a frame named Email whose only
|
|
413
457
|
* placed parts, at any depth, are the kit's), or the template editor's
|
|
414
458
|
* block palette.
|
|
415
459
|
*/
|
|
416
|
-
function outOfScopeRoot(n, parent, componentLabel, memo) {
|
|
417
|
-
if (emailKitPart(n, parent, componentLabel))
|
|
460
|
+
function outOfScopeRoot(n, parent, componentLabel, memo, setNameOf) {
|
|
461
|
+
if (emailKitPart(n, parent, componentLabel, setNameOf))
|
|
418
462
|
return `Email kit part ${n.type === "INSTANCE" ? componentLabel(n) : n.name}`;
|
|
419
463
|
if (n.type !== "FRAME" && n.type !== "GROUP" && n.type !== "SECTION")
|
|
420
464
|
return null;
|
|
@@ -426,7 +470,7 @@ function outOfScopeRoot(n, parent, componentLabel, memo) {
|
|
|
426
470
|
if (hit) return hit;
|
|
427
471
|
let kind = /** @type {"kit" | "other" | "none"} */ ("none");
|
|
428
472
|
if (!visibleNode(x)) kind = "none";
|
|
429
|
-
else if (emailKitPart(x, parent, componentLabel)) kind = "kit";
|
|
473
|
+
else if (emailKitPart(x, parent, componentLabel, setNameOf)) kind = "kit";
|
|
430
474
|
else if (
|
|
431
475
|
x.type === "INSTANCE" ||
|
|
432
476
|
x.type === "TEXT" ||
|
|
@@ -505,6 +549,45 @@ function headerCell(a, inst) {
|
|
|
505
549
|
return /(^|,\s*)part=head(er)?(\s*,|$)/i.test(c?.name ?? "");
|
|
506
550
|
}
|
|
507
551
|
|
|
552
|
+
/**
|
|
553
|
+
* What a frame composed of a library component's parts holds, outside the
|
|
554
|
+
* instances it places: `held` part instances, and `rows` frames that place
|
|
555
|
+
* two or more of them side by side (a row, as the Surfaces checker reads
|
|
556
|
+
* one). Null when something in it is drawn by hand: a text or a shape that
|
|
557
|
+
* is no instance, an image paint, or a frame with a paint or an effect that
|
|
558
|
+
* holds no part. Other library instances (a pager, an empty state) and
|
|
559
|
+
* unpainted layout frames are not drawn. A hidden or fully transparent
|
|
560
|
+
* layer is not there, so a part that cannot be seen is not held.
|
|
561
|
+
*/
|
|
562
|
+
function partsHeld(a, frame, parts) {
|
|
563
|
+
if ((frame.fills ?? []).some((p) => visibleNode(p) && p.type === "IMAGE"))
|
|
564
|
+
return null;
|
|
565
|
+
let held = 0;
|
|
566
|
+
let rows = 0;
|
|
567
|
+
let placed = 0;
|
|
568
|
+
for (const child of frame.children ?? []) {
|
|
569
|
+
if (!visibleNode(child) || (child.opacity ?? 1) <= 0) continue;
|
|
570
|
+
if (child.type === "INSTANCE") {
|
|
571
|
+
const key = a.setOf(child)?.key ?? a.componentOf(child)?.key;
|
|
572
|
+
if (key && parts.has(key)) placed++;
|
|
573
|
+
continue;
|
|
574
|
+
}
|
|
575
|
+
if (child.type !== "FRAME" && child.type !== "GROUP") return null;
|
|
576
|
+
const inner = partsHeld(a, child, parts);
|
|
577
|
+
if (!inner) return null;
|
|
578
|
+
if (
|
|
579
|
+
inner.held === 0 &&
|
|
580
|
+
(visiblePaints(child.fills) ||
|
|
581
|
+
visiblePaints(child.strokes) ||
|
|
582
|
+
(child.effects ?? []).some(visibleNode))
|
|
583
|
+
)
|
|
584
|
+
return null;
|
|
585
|
+
held += inner.held;
|
|
586
|
+
rows += inner.rows;
|
|
587
|
+
}
|
|
588
|
+
return { held: held + placed, rows: rows + (placed >= 2 ? 1 : 0) };
|
|
589
|
+
}
|
|
590
|
+
|
|
508
591
|
function matchesRole(a, inst, role, library) {
|
|
509
592
|
const c = a.componentOf(inst);
|
|
510
593
|
const set = a.setOf(inst);
|
|
@@ -828,12 +911,9 @@ export function checkConformance({
|
|
|
828
911
|
// notFromLibrary: local parts and hand-drawn stand-ins, off the library.
|
|
829
912
|
if (!library && own) {
|
|
830
913
|
if (n.type === "COMPONENT" || n.type === "COMPONENT_SET") {
|
|
831
|
-
// A submitted variant is its own root, so its set is not in the
|
|
832
|
-
// walked tree; Figma's components map still names the set.
|
|
833
914
|
const setName =
|
|
834
915
|
n.type === "COMPONENT"
|
|
835
|
-
? (a.parent.
|
|
836
|
-
a.componentSets[a.components[n.id]?.componentSetId]?.name)
|
|
916
|
+
? setOfComponent(n, a.parent, a.setNameOf)
|
|
837
917
|
: null;
|
|
838
918
|
if (!SURFACE_NAME.test(n.name) && !SURFACE_NAME.test(setName ?? ""))
|
|
839
919
|
push(
|
|
@@ -858,17 +938,22 @@ export function checkConformance({
|
|
|
858
938
|
`instance of local component ${set?.name ?? c.name}`,
|
|
859
939
|
);
|
|
860
940
|
} else if (n.type === "FRAME" || n.type === "GROUP") {
|
|
861
|
-
// A frame named for a library
|
|
862
|
-
//
|
|
863
|
-
// the
|
|
941
|
+
// A frame named for a library component that holds none of it. It
|
|
942
|
+
// holds it when it places an instance of that set, or (hub-488)
|
|
943
|
+
// when it is composed of the set's parts: a "Table" frame whose
|
|
944
|
+
// rows are Table Header and Table cell instances, with nothing
|
|
945
|
+
// drawn by hand beside them, is the library's own pattern, not a
|
|
946
|
+
// stand-in.
|
|
864
947
|
const named =
|
|
865
948
|
roles.find((r) => r.componentName === n.name) ||
|
|
866
949
|
librarySetNames.has(n.name);
|
|
950
|
+
const parts = LIBRARY_PARTS.get(n.name);
|
|
867
951
|
const holdsIt =
|
|
868
952
|
named &&
|
|
869
|
-
[...indexTree(n).byId.values()].some(
|
|
953
|
+
([...indexTree(n).byId.values()].some(
|
|
870
954
|
(x) => x.type === "INSTANCE" && a.componentLabel(x) === n.name,
|
|
871
|
-
)
|
|
955
|
+
) ||
|
|
956
|
+
(parts && (partsHeld(a, n, parts)?.rows ?? 0) > 0));
|
|
872
957
|
const drawn = visiblePaints(n.fills) || visiblePaints(n.strokes);
|
|
873
958
|
if (named && !holdsIt && drawn)
|
|
874
959
|
push(
|
|
@@ -938,8 +1023,27 @@ export function checkConformance({
|
|
|
938
1023
|
}
|
|
939
1024
|
}
|
|
940
1025
|
|
|
941
|
-
//
|
|
942
|
-
//
|
|
1026
|
+
// An Aadhaar shown in full is flagged for every viewer, the viewer's
|
|
1027
|
+
// own included, and a permission reveal does not lift it (PII-26).
|
|
1028
|
+
if (screenText(a, n, overridden)) {
|
|
1029
|
+
const aadhaarField = [...fieldLabels(a, n), ...fieldWords(a, n)].some(
|
|
1030
|
+
(l) => AADHAAR_FIELD.test(l),
|
|
1031
|
+
);
|
|
1032
|
+
const full = [
|
|
1033
|
+
...text.matchAll(AADHAAR),
|
|
1034
|
+
...(aadhaarField ? text.matchAll(AADHAAR_RUN) : []),
|
|
1035
|
+
];
|
|
1036
|
+
for (const m of full)
|
|
1037
|
+
push(
|
|
1038
|
+
findings,
|
|
1039
|
+
n.id,
|
|
1040
|
+
"otherPersonRevealed",
|
|
1041
|
+
`unmasked Aadhaar ${m[0]}; Aadhaar shows only its last four digits, to its owner too (PII-26)`,
|
|
1042
|
+
);
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
// otherPersonRevealed (DEC-0045). Never the viewer's own record (R5,
|
|
1046
|
+
// P-10), never a colleague's display name on a staff surface (D1104).
|
|
943
1047
|
if (
|
|
944
1048
|
!screenText(a, n, overridden) ||
|
|
945
1049
|
isSelf(a, n) ||
|
|
@@ -957,6 +1061,8 @@ export function checkConformance({
|
|
|
957
1061
|
const digits = m[0].replace(/\D/g, "");
|
|
958
1062
|
if (DATE.test(m[0]) || MASKED.test(m[0]) || viewer.has(digits))
|
|
959
1063
|
continue;
|
|
1064
|
+
// An Aadhaar is reported once, by the Aadhaar rule above.
|
|
1065
|
+
if (new RegExp(`^${AADHAAR.source}$`).test(m[0].trim())) continue;
|
|
960
1066
|
const phoneShaped =
|
|
961
1067
|
m[0].startsWith("+") || LOCAL_PHONE.test(m[0].trim());
|
|
962
1068
|
if (phoneShaped && digits.length >= 10 && digits.length <= 15)
|
|
@@ -1269,15 +1375,75 @@ function selfRow(a, n) {
|
|
|
1269
1375
|
) ?? null
|
|
1270
1376
|
);
|
|
1271
1377
|
}
|
|
1378
|
+
/**
|
|
1379
|
+
* The field a text fills: the outermost library field part (Field, Input,
|
|
1380
|
+
* Select...) or field frame (field/Email) within four levels, so a value in
|
|
1381
|
+
* a Field's Input control reads the Field's label and hint (CS-2946's
|
|
1382
|
+
* Send to). Null when the text fills no field.
|
|
1383
|
+
*/
|
|
1384
|
+
function fieldOf(a, n) {
|
|
1385
|
+
return (
|
|
1386
|
+
a
|
|
1387
|
+
.ancestors(n)
|
|
1388
|
+
.slice(0, 4)
|
|
1389
|
+
.findLast((x) =>
|
|
1390
|
+
x.type === "INSTANCE"
|
|
1391
|
+
? FIELD_PART.test(a.componentLabel(x) ?? "")
|
|
1392
|
+
: FIELD_FRAME.test(x.name ?? ""),
|
|
1393
|
+
) ?? null
|
|
1394
|
+
);
|
|
1395
|
+
}
|
|
1396
|
+
/**
|
|
1397
|
+
* The words of the field a text fills, other than the text itself: the
|
|
1398
|
+
* field's label, hint and helper, as properties or as its own texts.
|
|
1399
|
+
*/
|
|
1400
|
+
function fieldWords(a, n) {
|
|
1401
|
+
const field = fieldOf(a, n);
|
|
1402
|
+
if (!field) return [];
|
|
1403
|
+
const words = [];
|
|
1404
|
+
for (const [prop, v] of Object.entries(field.componentProperties ?? {}))
|
|
1405
|
+
if (
|
|
1406
|
+
/^(label|hint|helper|description|caption)\b/i.test(prop) &&
|
|
1407
|
+
typeof v?.value === "string"
|
|
1408
|
+
)
|
|
1409
|
+
words.push(v.value);
|
|
1410
|
+
for (const x of indexTree(field).byId.values())
|
|
1411
|
+
if (x.type === "TEXT" && x.id !== n.id && x.visible !== false)
|
|
1412
|
+
words.push(textOf(x));
|
|
1413
|
+
return words;
|
|
1414
|
+
}
|
|
1415
|
+
/**
|
|
1416
|
+
* The viewer's own value in a field (hub-236, P-10): the field's
|
|
1417
|
+
* label or hint says so ("Your own address is filled in", "Your email").
|
|
1418
|
+
* Only the field's own words count, never the value itself.
|
|
1419
|
+
*/
|
|
1420
|
+
function selfField(a, n) {
|
|
1421
|
+
return fieldWords(a, n).some((w) => SELF_FIELD.test(w));
|
|
1422
|
+
}
|
|
1423
|
+
/** "(you)" on the value or on a text beside it (U05-7). */
|
|
1424
|
+
function markedYou(a, n) {
|
|
1425
|
+
if (YOU_MARKER.test(textOf(n))) return true;
|
|
1426
|
+
const siblings = a.parent.get(n.id)?.children ?? [];
|
|
1427
|
+
return siblings.some(
|
|
1428
|
+
(x) =>
|
|
1429
|
+
x.id !== n.id &&
|
|
1430
|
+
x.type === "TEXT" &&
|
|
1431
|
+
x.visible !== false &&
|
|
1432
|
+
/^\(you\)$/i.test(textOf(x)),
|
|
1433
|
+
);
|
|
1434
|
+
}
|
|
1435
|
+
/** The component set a node draws: an instance's, a variant's, or the set. */
|
|
1436
|
+
function drawnSet(a, x) {
|
|
1437
|
+
if (x.type === "INSTANCE") return a.setOf(x);
|
|
1438
|
+
if (x.type === "COMPONENT") return a.setOf({ componentId: x.id });
|
|
1439
|
+
if (x.type === "COMPONENT_SET") return a.componentSets[x.id] ?? null;
|
|
1440
|
+
return null;
|
|
1441
|
+
}
|
|
1272
1442
|
function isSelf(a, n) {
|
|
1273
1443
|
const up = a.ancestors(n);
|
|
1274
1444
|
if (up.some((x) => selfPersonName(a, x))) return true;
|
|
1275
|
-
if (
|
|
1276
|
-
|
|
1277
|
-
(x) =>
|
|
1278
|
-
x.type === "INSTANCE" && SELF_COMPONENT_SET_KEYS.has(a.setOf(x)?.key),
|
|
1279
|
-
)
|
|
1280
|
-
)
|
|
1445
|
+
if (selfField(a, n) || markedYou(a, n)) return true;
|
|
1446
|
+
if (up.some((x) => SELF_COMPONENT_SET_KEYS.has(drawnSet(a, x)?.key)))
|
|
1281
1447
|
return true;
|
|
1282
1448
|
|
|
1283
1449
|
// INTERIM: identify a Table row from its direct Table-cell children, or a
|