@nodii/dev 0.6.214 → 0.6.215

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, lstat, mkdir, readFile, rename, rm, writeFile } from "node:fs/pr
4
4
  import { homedir, platform } from "node:os";
5
5
  import { basename, dirname, join } from "node:path";
6
6
 
7
- export const VERSION = "0.6.214";
7
+ export const VERSION = "0.6.215";
8
8
  export const configPath = () =>
9
9
  process.env.NODII_DEV_CONFIG_PATH ??
10
10
  join(homedir(), ".config/nodii-dev/config.json");
package/dist/design.js CHANGED
@@ -9,7 +9,7 @@
9
9
  import { readFile } from "node:fs/promises";
10
10
  import { CliError, devRequest } from "./core.js";
11
11
  import { FIGMA_API, figmaRest } from "./figma-rest.js";
12
- import { conformanceLines, figmaConformance, figmaFileKey, laneReadsBody, submitMode, surfacesCheck, uploadSubmitImages, withCodePr } from "./figma.js";
12
+ import { conformanceLines, figmaConformance, figmaFileKey, laneReadsBody, submitEvidence, submitMode, surfacesCheck, uploadSubmitImages, withCodePr, withVersionHistoryReads } from "./figma.js";
13
13
  import { checkConformance, neededMains, VERSION as CHECK_VERSION } from "./vendor/ds-conformance.mjs";
14
14
 
15
15
  // The Figma nodes endpoint takes many ids per call; keep URLs well short of limits.
@@ -149,20 +149,6 @@ const PUBLISH_LABEL = "Components published";
149
149
  const VERSION_PAGES = 5;
150
150
  const KEY_LOOKUPS_AT_ONCE = 3;
151
151
 
152
- async function versionHistoryReads(figmaGet, path) {
153
- const reads = [];
154
- let at = `/${path}?page_size=100`;
155
- for (let page = 0; page < VERSION_PAGES && at; page++) {
156
- const body = await figmaGet(at);
157
- reads.push({ path: at.slice(1), body });
158
- const older = body?.pagination?.prev_page;
159
- if (typeof older !== "string" || !older.startsWith(`${FIGMA_API}/${path}`)) break;
160
- const next = new URL(older);
161
- at = next.origin === new URL(FIGMA_API).origin && next.pathname === `/v1/${path}` ? `${next.pathname.slice(3)}${next.search}` : null;
162
- }
163
- return reads;
164
- }
165
-
166
152
  /**
167
153
  * A library's newest "Components published" version (DEC-0047): what a
168
154
  * consuming file can have. Null when none is in its recent history; its
@@ -506,23 +492,18 @@ export async function designCheckChangeSet(target, flags, { request = devRequest
506
492
  // hub-558: images go up one by one and the body names them; --code-pr rides in the body.
507
493
  body = withCodePr(body, codePr, { ...(progress ? { progress } : {}) });
508
494
  body = await uploadSubmitImages(id, body, { request, ...(progress ? { progress } : {}) });
495
+ const set = (await request("GET", `/api/v1/design/change-sets/${encodeURIComponent(id)}`)).data;
496
+ body = { ...body, evidence: submitEvidence(body, set) };
509
497
  // Upload a large read corpus once. A versions negotiation below keeps its
510
498
  // readIds and adds only one small inline REST supplement.
511
499
  const storedReads = laneReads
512
500
  ? await laneReadsBody(id, laneReads, { request, ...(progress ? { progress } : {}), ...(laneReadsLimit ? { limit: laneReadsLimit } : {}) })
513
501
  : {};
514
- let versionReads = [];
515
- const withReads = () => {
516
- if (!versionReads.length) return { ...body, ...storedReads };
517
- if (storedReads.laneReads)
518
- return { ...body, laneReads: { ...storedReads.laneReads, rest: [...(storedReads.laneReads.rest ?? []).filter((entry) => !versionReads.some((read) => read.path === entry.path)), ...versionReads] } };
519
- return { ...body, ...storedReads, laneReads: { figmaVersion: laneReads.figmaVersion, nodes: [], rest: versionReads } };
520
- };
521
502
  let p;
522
503
  try {
523
504
  const run = (sent) => figmaConformance(id, sent, { request, sync, ...(send ? { send } : {}), ...(progress ? { progress } : {}) });
524
- const runAll = async () => {
525
- const sent = withReads();
505
+ const runAll = async (reads) => {
506
+ const sent = { ...body, ...reads };
526
507
  // A submit body past the dry run's node limit runs in parts, each under it;
527
508
  // a re-submit's can't be split, since it must name every rejected item.
528
509
  const groups = split && Array.isArray(sent.items) ? dryRunGroups(sent.items) : [];
@@ -531,15 +512,7 @@ export async function designCheckChangeSet(target, flags, { request = devRequest
531
512
  for (const items of groups) reports.push((await run({ ...sent, items })).data ?? {});
532
513
  return { data: mergedReports(reports) };
533
514
  };
534
- try {
535
- p = await runAll();
536
- } catch (error) {
537
- const path = String(error?.details?.path ?? "").replace(/^\/+/, "");
538
- if (!laneReads || error?.code !== "FIGMA_READS_NEEDED" || !/^files\/[^/]+\/versions$/.test(path)) throw error;
539
- const get = figmaGet ?? figmaClient(figmaToken(env));
540
- versionReads = await versionHistoryReads(get, path);
541
- p = await runAll();
542
- }
515
+ p = await withVersionHistoryReads({ laneReads, storedReads, run: runAll, figmaGet: () => figmaGet ?? figmaClient(figmaToken(env)) });
543
516
  } catch (error) {
544
517
  // A cold run reads every root and main from Figma and can outlast the
545
518
  // edge's gateway (504, an HTML page). Dev keeps the mains it read for 5
package/dist/figma.js CHANGED
@@ -2,6 +2,7 @@ import { createHash } from "node:crypto";
2
2
  import { readFile } from "node:fs/promises";
3
3
  import { setTimeout as delay } from "node:timers/promises";
4
4
  import { CliError, devAsyncRequest, devRequest, encode } from "./core.js";
5
+ import { FIGMA_API } from "./figma-rest.js";
5
6
  import { assertWithinLaneScope, currentLaneFigmaScope } from "./figma-scope.js";
6
7
  import { answerPlanReads, countedReads, figmaToken } from "./publish-compare.js";
7
8
  import { pacedFigma } from "./surface.js";
@@ -473,6 +474,46 @@ export function withCodePr(body, flag, { progress = stderrLine } = {}) {
473
474
  return { ...body, codePr };
474
475
  }
475
476
 
477
+ const VERSION_HISTORY_PAGES = 5;
478
+
479
+ /** The bounded, same-file version-history reads Dev asks a lane to supply. */
480
+ async function versionHistoryReads(figmaGet, path) {
481
+ const reads = [];
482
+ let at = `/${path}?page_size=100`;
483
+ for (let page = 0; page < VERSION_HISTORY_PAGES && at; page++) {
484
+ const body = await figmaGet(at);
485
+ reads.push({ path: at.slice(1), body });
486
+ const older = body?.pagination?.prev_page;
487
+ if (typeof older !== "string" || !older.startsWith(`${FIGMA_API}/${path}`)) break;
488
+ const next = new URL(older);
489
+ at = next.origin === new URL(FIGMA_API).origin && next.pathname === `/v1/${path}` ? `${next.pathname.slice(3)}${next.search}` : null;
490
+ }
491
+ return reads;
492
+ }
493
+
494
+ /**
495
+ * Run one submit-family call with the lane's reads. If Dev asks for this file's
496
+ * version history, fetch it in the lane and retry exactly once. Dry runs and
497
+ * real re-submits share this loop so they promise the same read negotiation.
498
+ */
499
+ export async function withVersionHistoryReads({ laneReads, storedReads, run, figmaGet }) {
500
+ let versionReads = [];
501
+ const reads = () => {
502
+ if (!versionReads.length) return storedReads;
503
+ if (storedReads.laneReads)
504
+ return { laneReads: { ...storedReads.laneReads, rest: [...(storedReads.laneReads.rest ?? []).filter((entry) => !versionReads.some((read) => read.path === entry.path)), ...versionReads] } };
505
+ return { ...storedReads, laneReads: { figmaVersion: laneReads.figmaVersion, nodes: [], rest: versionReads } };
506
+ };
507
+ try {
508
+ return await run(reads());
509
+ } catch (error) {
510
+ const path = String(error?.details?.path ?? "").replace(/^\/+/, "");
511
+ if (!laneReads || error?.code !== "FIGMA_READS_NEEDED" || !/^files\/[^/]+\/versions$/.test(path)) throw error;
512
+ versionReads = await versionHistoryReads(figmaGet(), path);
513
+ return run(reads());
514
+ }
515
+ }
516
+
476
517
  /** A submit or re-submit, async unless `sync`; a gateway timeout is checked against the set, not resent. */
477
518
  async function submitCall(id, kind, body, { sync = false, request = devRequest, progress = stderrLine, ...job } = {}) {
478
519
  const path = `/api/v1/design/change-sets/${encode(id)}/${kind}`;
@@ -487,7 +528,7 @@ async function submitCall(id, kind, body, { sync = false, request = devRequest,
487
528
  }
488
529
  }
489
530
 
490
- export async function figmaResubmit(id, file, { request = devRequest, read = (f) => readFile(f, "utf8"), laneReads, codePr, ...options } = {}) {
531
+ export async function figmaResubmit(id, file, { request = devRequest, read = (f) => readFile(f, "utf8"), laneReads, codePr, env = process.env, figmaGet, laneReadsLimit, ...options } = {}) {
491
532
  if (!id || !file) throw new CliError("USAGE", "figma resubmit CHANGE_SET PAYLOAD.json", 2);
492
533
  let text;
493
534
  try {
@@ -501,8 +542,13 @@ export async function figmaResubmit(id, file, { request = devRequest, read = (f)
501
542
  const body = await uploadSubmitImages(id, flagged, { request, ...(options.progress ? { progress: options.progress } : {}) });
502
543
  // On the lane's reads Dev runs the gate as a submit job too (hub-448), so
503
544
  // they go async like any re-submit; --sync still sends the plain call.
504
- const reads = await laneReadsBody(id, laneReads, { request, ...(options.progress ? { progress: options.progress } : {}) });
505
- return await submitCall(id, "resubmit", { ...body, ...reads }, { request, ...options });
545
+ const reads = await laneReadsBody(id, laneReads, { request, ...(options.progress ? { progress: options.progress } : {}), ...(laneReadsLimit ? { limit: laneReadsLimit } : {}) });
546
+ return await withVersionHistoryReads({
547
+ laneReads,
548
+ storedReads: reads,
549
+ run: (supplemented) => submitCall(id, "resubmit", { ...body, ...supplemented }, { request, ...options }),
550
+ figmaGet: () => figmaGet ?? pacedFigma(figmaToken(env), { log: options.progress }),
551
+ });
506
552
  } catch (error) {
507
553
  if (error?.code === "FIGMA_READS_NEEDED") throw laneReadsRefusal(error);
508
554
  const say = RESUBMIT_REFUSALS[error?.code];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodii/dev",
3
- "version": "0.6.214",
3
+ "version": "0.6.215",
4
4
  "description": "Agent CLI for Nodii Dev, reached through the platform edge",
5
5
  "type": "module",
6
6
  "bin": {