@nodii/dev 0.6.148 → 0.6.149

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/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.148";
7
+ export const VERSION = "0.6.149";
8
8
  export const configPath = () =>
9
9
  process.env.NODII_DEV_CONFIG_PATH ??
10
10
  join(homedir(), ".config/nodii-dev/config.json");
@@ -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.12";
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(parent.get(n.id)?.name ?? ""))));
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.get(n.id)?.name ??
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 part that holds none of it: the
862
- // Table set is the cell set, so a "Table" frame of its cells is
863
- // the library's own pattern, not a stand-in.
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
- // otherPersonRevealed (DEC-0045). Never the viewer's own record (R5),
942
- // never a colleague's display name on a staff surface (D1104).
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
- up.some(
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodii/dev",
3
- "version": "0.6.148",
3
+ "version": "0.6.149",
4
4
  "description": "Agent CLI for Nodii Dev, reached through the platform edge",
5
5
  "type": "module",
6
6
  "bin": {