frakment 3.0.1 → 5.0.0

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 CHANGED
@@ -9,7 +9,7 @@ Frakment-authored CLI code is licensed under MIT, which permits commercial use,
9
9
 
10
10
  ## Requirements
11
11
 
12
- - Node.js >= 22.18.0
12
+ - Node.js >= 22.22.2
13
13
  - Tailwind CSS v4 (`@import "tailwindcss";` in your `globals.css`)
14
14
 
15
15
  ## Package managers
@@ -84,6 +84,8 @@ The default registry URL is written to `components.json` during `init`. If the p
84
84
  npx frakment@latest add badge --registry http://localhost:8765
85
85
  ```
86
86
 
87
+ The CLI verifies official registry payloads against a Sigstore-signed manifest published by the Frakment GitHub repository. Custom registry URLs are outside that signature policy and should only be used when trusted.
88
+
87
89
  ## Troubleshooting
88
90
 
89
91
  ### "Frakment requires Tailwind v4"
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "frakment",
3
- "version": "3.0.1",
3
+ "version": "5.0.0",
4
4
  "description": "MIT-licensed CLI and design system for the Frakment component registry",
5
5
  "keywords": [
6
6
  "components",
@@ -34,7 +34,8 @@
34
34
  "commander": "^15.1.0",
35
35
  "execa": "^10.2.1",
36
36
  "ora": "^10.0.0",
37
- "prompts": "^2.4.2"
37
+ "prompts": "^2.4.2",
38
+ "sigstore": "^5.0.1"
38
39
  },
39
40
  "devDependencies": {
40
41
  "@types/prompts": "^2.4.9",
@@ -44,6 +45,6 @@
44
45
  "tailwind-merge": "^3.7.1"
45
46
  },
46
47
  "engines": {
47
- "node": ">=22.18.0"
48
+ "node": ">=22.22.2"
48
49
  }
49
50
  }
@@ -12,6 +12,7 @@ var __rest = (this && this.__rest) || function (s, e) {
12
12
  import { createHash } from "node:crypto";
13
13
  import { existsSync } from "node:fs";
14
14
  import { readFile } from "node:fs/promises";
15
+ import { createRequire } from "node:module";
15
16
  import path from "node:path";
16
17
  import chalk from "chalk";
17
18
  import { execa } from "execa";
@@ -24,7 +25,20 @@ export { assertSafePath };
24
25
  const componentNamePattern = /^[a-z0-9]+(?:-[a-z0-9]+)*$/u;
25
26
  const dependencyPattern = /^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*(?:@[0-9A-Za-z*~^<>=|.+_-]+)?$/u;
26
27
  const maxRegistryPayloadBytes = 10 * 1024 * 1024;
28
+ const maxRegistryManifestBytes = 1024 * 1024;
27
29
  const defaultWebRegistry = "https://www.arrafi.dev/frakment/r";
30
+ const cliPackage = createRequire(import.meta.url)("../../package.json");
31
+ if (typeof cliPackage !== "object" ||
32
+ cliPackage === null ||
33
+ !("version" in cliPackage) ||
34
+ typeof cliPackage.version !== "string") {
35
+ throw new Error("CLI package version is unavailable");
36
+ }
37
+ const registryReleaseUrl = `https://github.com/frakment/ui/releases/download/${encodeURIComponent(`frakment@${cliPackage.version}`)}`;
38
+ const registryManifestUrl = `${registryReleaseUrl}/manifest.json`;
39
+ const registrySignatureUrl = `${registryReleaseUrl}/manifest.sigstore.json`;
40
+ const registrySignerIdentity = "^https://github\\.com/frakment/ui/\\.github/workflows/registry-sign\\.yml@refs/heads/main$";
41
+ const sigstoreIssuer = "https://token.actions.githubusercontent.com";
28
42
  const defaultAliases = {
29
43
  components: "@/components",
30
44
  ui: "@/components/ui",
@@ -66,6 +80,59 @@ const canonicalize = (value) => {
66
80
  const createIntegrity = (payload) => `sha256:${createHash("sha256")
67
81
  .update(canonicalize(payload), "utf8")
68
82
  .digest("hex")}`;
83
+ async function fetchRegistryText(url, maxBytes) {
84
+ const response = await fetch(url, { signal: AbortSignal.timeout(10000) });
85
+ if (!response.ok) {
86
+ throw new Error(`HTTP ${response.status} from ${url}`);
87
+ }
88
+ const contentLength = Number(response.headers.get("content-length"));
89
+ if (Number.isFinite(contentLength) && contentLength > maxBytes) {
90
+ throw new Error(`Response from ${url} is too large`);
91
+ }
92
+ const raw = await response.text();
93
+ if (Buffer.byteLength(raw, "utf8") > maxBytes) {
94
+ throw new Error(`Response from ${url} is too large`);
95
+ }
96
+ return raw;
97
+ }
98
+ export async function fetchSignedRegistryManifest() {
99
+ const [manifestRaw, signatureRaw] = await Promise.all([
100
+ fetchRegistryText(registryManifestUrl, maxRegistryManifestBytes),
101
+ fetchRegistryText(registrySignatureUrl, maxRegistryManifestBytes),
102
+ ]);
103
+ const manifest = JSON.parse(manifestRaw);
104
+ const signature = JSON.parse(signatureRaw);
105
+ const sigstore = await import("sigstore");
106
+ await sigstore.verify(signature, Buffer.from(manifestRaw, "utf8"), {
107
+ certificateIdentityURI: registrySignerIdentity,
108
+ certificateIssuer: sigstoreIssuer,
109
+ });
110
+ if (!isRecord(manifest) ||
111
+ manifest.version !== 1 ||
112
+ !isRecord(manifest.files)) {
113
+ throw new Error("Signed registry manifest has an invalid format");
114
+ }
115
+ const files = {};
116
+ for (const [name, digest] of Object.entries(manifest.files)) {
117
+ if (!/^(?:index|[a-z0-9]+(?:-[a-z0-9]+)*)\.json$/u.test(name) ||
118
+ typeof digest !== "string" ||
119
+ !/^sha256:[a-f0-9]{64}$/u.test(digest)) {
120
+ throw new Error("Signed registry manifest has an invalid file entry");
121
+ }
122
+ files[name] = digest;
123
+ }
124
+ return { files, version: 1 };
125
+ }
126
+ export function verifySignedRegistryFile(name, raw, manifest) {
127
+ const expectedDigest = manifest.files[name];
128
+ const actualDigest = `sha256:${createHash("sha256")
129
+ .update(raw, "utf8")
130
+ .digest("hex")}`;
131
+ if (!expectedDigest || expectedDigest !== actualDigest) {
132
+ throw new Error(`Registry file ${name} does not match the signed manifest`);
133
+ }
134
+ }
135
+ export const isOfficialRegistryUrl = (url) => url === defaultWebRegistry;
69
136
  function assertComponentName(name) {
70
137
  if (typeof name !== "string" || !componentNamePattern.test(name)) {
71
138
  throw new Error(`Invalid component name: ${String(name)}`);
@@ -161,7 +228,7 @@ export function resolveRegistryUrl(config, options = {}) {
161
228
  const configured = (_a = registry !== null && registry !== void 0 ? registry : web) !== null && _a !== void 0 ? _a : defaultWebRegistry;
162
229
  return getRegistryUrl((_b = options.registry) !== null && _b !== void 0 ? _b : configured);
163
230
  }
164
- async function fetchComponent(name, registryUrl, spinner) {
231
+ async function fetchComponent(name, registryUrl, spinner, manifest) {
165
232
  try {
166
233
  const res = await fetch(`${registryUrl}/${name}.json`, {
167
234
  signal: AbortSignal.timeout(30000),
@@ -177,6 +244,9 @@ async function fetchComponent(name, registryUrl, spinner) {
177
244
  if (Buffer.byteLength(raw, "utf8") > maxRegistryPayloadBytes) {
178
245
  throw new Error("Registry response is too large");
179
246
  }
247
+ if (manifest) {
248
+ verifySignedRegistryFile(`${name}.json`, raw, manifest);
249
+ }
180
250
  const payload = validateRegistryPayload(JSON.parse(raw), name);
181
251
  spinner.text = `Fetching ${name}...`;
182
252
  return payload;
@@ -248,6 +318,19 @@ export async function add(componentNamesInput, options = {}) {
248
318
  process.exit(1);
249
319
  }
250
320
  const registrySpinner = ora("Checking registry").start();
321
+ let signedManifest;
322
+ if (registryUrl === defaultWebRegistry) {
323
+ try {
324
+ signedManifest = await fetchSignedRegistryManifest();
325
+ }
326
+ catch (error) {
327
+ registrySpinner.fail(`Registry signature verification failed: ${error instanceof Error ? error.message : "unknown error"}`);
328
+ process.exit(1);
329
+ }
330
+ }
331
+ else {
332
+ logger.warn("Custom registry is not covered by Frakment's Sigstore signature.");
333
+ }
251
334
  const roots = new Set(componentNames);
252
335
  const queue = [...roots];
253
336
  const fetched = new Map();
@@ -260,7 +343,7 @@ export async function add(componentNamesInput, options = {}) {
260
343
  if (fetched.has(name)) {
261
344
  continue;
262
345
  }
263
- const payload = await fetchComponent(name, registryUrl, registrySpinner);
346
+ const payload = await fetchComponent(name, registryUrl, registrySpinner, signedManifest);
264
347
  fetched.set(name, payload);
265
348
  for (const d of (_a = payload.dependencies) !== null && _a !== void 0 ? _a : []) {
266
349
  const packageName = getDependencyName(d);
@@ -5,7 +5,7 @@ import chalk from "chalk";
5
5
  import ora from "ora";
6
6
  import { findProjectRoot } from "../utils/detect.js";
7
7
  import { logger } from "../utils/logger.js";
8
- import { resolveRegistryUrl } from "./add.js";
8
+ import { fetchSignedRegistryManifest, isOfficialRegistryUrl, resolveRegistryUrl, verifySignedRegistryFile, } from "./add.js";
9
9
  const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
10
10
  export const isRegistryIndex = (value) => isRecord(value) &&
11
11
  Array.isArray(value.components) &&
@@ -45,13 +45,26 @@ export async function list(options) {
45
45
  const s = ora("Fetching components").start();
46
46
  let index;
47
47
  try {
48
+ const manifest = isOfficialRegistryUrl(registryUrl)
49
+ ? await fetchSignedRegistryManifest()
50
+ : undefined;
51
+ if (!manifest) {
52
+ logger.warn("Custom registry is not covered by Frakment's Sigstore signature.");
53
+ }
48
54
  const res = await fetch(`${registryUrl}/index.json`, {
49
55
  signal: AbortSignal.timeout(30000),
50
56
  });
51
57
  if (!res.ok) {
52
58
  throw new Error(`HTTP ${res.status}`);
53
59
  }
54
- const response = await res.json();
60
+ const raw = await res.text();
61
+ if (Buffer.byteLength(raw, "utf8") > 10 * 1024 * 1024) {
62
+ throw new Error("Registry index response is too large");
63
+ }
64
+ if (manifest) {
65
+ verifySignedRegistryFile("index.json", raw, manifest);
66
+ }
67
+ const response = JSON.parse(raw);
55
68
  if (!isRegistryIndex(response)) {
56
69
  throw new Error("Registry index has an invalid shape");
57
70
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "frakment",
3
- "version": "3.0.1",
3
+ "version": "5.0.0",
4
4
  "description": "MIT-licensed CLI and design system for the Frakment component registry",
5
5
  "keywords": [
6
6
  "components",
@@ -29,7 +29,8 @@
29
29
  "commander": "^15.1.0",
30
30
  "execa": "^10.2.1",
31
31
  "ora": "^10.0.0",
32
- "prompts": "^2.4.2"
32
+ "prompts": "^2.4.2",
33
+ "sigstore": "^5.0.1"
33
34
  },
34
35
  "devDependencies": {
35
36
  "@types/prompts": "^2.4.9",
@@ -39,7 +40,7 @@
39
40
  "tailwind-merge": "^3.7.1"
40
41
  },
41
42
  "engines": {
42
- "node": ">=22.18.0"
43
+ "node": ">=22.22.2"
43
44
  },
44
45
  "scripts": {
45
46
  "build": "tsc -p tsconfig.build.json && node ../../scripts/copy-runtime-package.ts",