@hyperframes/share 0.9.98 → 0.9.99

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
@@ -111,7 +111,13 @@ once per capture. Pass the resulting `ignored` function to the inventory walk as
111
111
  `listReferencedHiddenSourceAssets(projectPath, observed, { ignored })`. Private-path rules apply
112
112
  even when an ignore rule re-includes a path.
113
113
 
114
- The adapter uses the portable-source-v12 capture/manifest rules and
114
+ Editable source includes referenced WOFF, WOFF2, TTF and OTF files with dot-prefixed names, such as
115
+ `.brand/.Atlas.woff2`. The same private-path and ignore rules apply to these fonts. Preview and render servers can call
116
+ `referencedFontResponse(projectDir, relativePath, method)` from `@hyperframes/share/projectSnapshot.mjs`
117
+ to serve a selected dot-prefixed font. It returns a streaming response for a verified file and
118
+ `null` if the file cannot be served.
119
+
120
+ The adapter uses the portable-source-v13 capture/manifest rules and
115
121
  multipart transport. The pinned policy, Unicode 15.1 registry (with its license),
116
122
  and manifest test vectors are checked into this repository. Source is captured through
117
123
  verified file handles; upload bytes are streamed and checked against their hash.
@@ -1,8 +1,19 @@
1
+ /** Eligible referenced files and the disk identities observed by the scan.
2
+ * @param {string} dir @param {Map<string,string>} [observed]
3
+ * @param {{ignored: import("../sourceIgnore.mjs").SourceIgnore, ignoreSyntax?: never} |
4
+ * {ignored?: never, ignoreSyntax?: import("../sourceIgnore.mjs").SourceIgnoreSyntax}} [options] */
5
+ export function referencedHiddenSourceFiles(dir: string, observed?: Map<string, string>, { ignored, ignoreSyntax }?: {
6
+ ignored: import("../sourceIgnore.mjs").SourceIgnore;
7
+ ignoreSyntax?: never;
8
+ } | {
9
+ ignored?: never;
10
+ ignoreSyntax?: import("../sourceIgnore.mjs").SourceIgnoreSyntax;
11
+ }): Promise<import("./types.js").Found[]>;
1
12
  /** Paths included by a normal editable Share or Send. A host can reuse the project rules from its inventory walk.
2
13
  * @param {string} root @param {Map<string,string>} [observed]
3
14
  * @param {{ignored: import("../sourceIgnore.mjs").SourceIgnore, ignoreSyntax?: never} |
4
15
  * {ignored?: never, ignoreSyntax?: import("../sourceIgnore.mjs").SourceIgnoreSyntax}} [options] */
5
- export function listReferencedHiddenSourceAssets(root: string, observed?: Map<string, string>, { ignored, ignoreSyntax }?: {
16
+ export function listReferencedHiddenSourceAssets(root: string, observed?: Map<string, string>, options?: {
6
17
  ignored: import("../sourceIgnore.mjs").SourceIgnore;
7
18
  ignoreSyntax?: never;
8
19
  } | {
@@ -0,0 +1,4 @@
1
+ /** A private-file route may serve this one project font from the descriptor checked against the
2
+ * source inventory. A caller must never use the result to authorize a second open by pathname.
3
+ * @param {string} projectDir @param {string | URL} requested @param {string} method */
4
+ export function referencedFontResponse(projectDir: string, requested: string | URL, method: string): Promise<Response | null>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/share",
3
- "version": "0.9.98",
3
+ "version": "0.9.99",
4
4
  "description": "Shared review identity, version upload and sharing state for HyperFrames hosts",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -46,6 +46,10 @@
46
46
  "import": "./src/projectSnapshot.mjs",
47
47
  "types": "./dist/projectSnapshot.d.mts"
48
48
  },
49
+ "./referencedFont.mjs": {
50
+ "import": "./src/referencedFont.mjs",
51
+ "types": "./dist/sources/referencedFont.d.mts"
52
+ },
49
53
  "./reviewAudience.mjs": {
50
54
  "import": "./src/reviewAudience.mjs",
51
55
  "types": "./dist/reviewAudience.d.mts"
@@ -109,7 +113,7 @@
109
113
  "css-tree": "^3.2.1",
110
114
  "ignore": "^5.3.2",
111
115
  "linkedom": "^0.18.12",
112
- "@hyperframes/parsers": "0.9.98"
116
+ "@hyperframes/parsers": "0.9.99"
113
117
  },
114
118
  "devDependencies": {
115
119
  "@types/css-tree": "^3.2.0",
@@ -0,0 +1,6 @@
1
+ /** Serve a dot-prefixed font selected by the current project dependency scan. */
2
+ export function referencedFontResponse(
3
+ projectDir: string,
4
+ requested: string | URL,
5
+ method: string,
6
+ ): Promise<Response | null>;
@@ -0,0 +1 @@
1
+ export { referencedFontResponse } from "./sources/referencedFont.mjs";
@@ -152,17 +152,11 @@ async function selectDependencies(root, walk) {
152
152
  return retainReferencedFiles(root, walk, openListed);
153
153
  }
154
154
 
155
- /** Paths included by a normal editable Share or Send. A host can reuse the project rules from its inventory walk.
156
- * @param {string} root @param {Map<string,string>} [observed]
155
+ /** Eligible referenced files and the disk identities observed by the scan.
156
+ * @param {string} dir @param {Map<string,string>} [observed]
157
157
  * @param {{ignored: import("../sourceIgnore.mjs").SourceIgnore, ignoreSyntax?: never} |
158
158
  * {ignored?: never, ignoreSyntax?: import("../sourceIgnore.mjs").SourceIgnoreSyntax}} [options] */
159
- export async function listReferencedHiddenSourceAssets(
160
- root,
161
- observed,
162
- { ignored, ignoreSyntax } = {},
163
- ) {
164
- observed?.clear();
165
- const dir = await realpath(root);
159
+ export async function referencedHiddenSourceFiles(dir, observed, { ignored, ignoreSyntax } = {}) {
166
160
  const walk = await walkProject(
167
161
  dir,
168
162
  await readRenderOutputs(dir),
@@ -172,10 +166,18 @@ export async function listReferencedHiddenSourceAssets(
172
166
  const hashes = await selectDependencies(dir, walk);
173
167
  if (walk.problems.length > before) throw new Error("Cannot verify project asset references");
174
168
  if (observed) for (const [path, hash] of hashes) observed.set(path, hash);
175
- return walk.files
176
- .filter((file) => file.include_hidden)
177
- .map((file) => file.path)
178
- .sort();
169
+ return walk.files.filter((file) => file.include_hidden);
170
+ }
171
+
172
+ /** Paths included by a normal editable Share or Send. A host can reuse the project rules from its inventory walk.
173
+ * @param {string} root @param {Map<string,string>} [observed]
174
+ * @param {{ignored: import("../sourceIgnore.mjs").SourceIgnore, ignoreSyntax?: never} |
175
+ * {ignored?: never, ignoreSyntax?: import("../sourceIgnore.mjs").SourceIgnoreSyntax}} [options] */
176
+ export async function listReferencedHiddenSourceAssets(root, observed, options = {}) {
177
+ observed?.clear();
178
+ const dir = await realpath(root);
179
+ const files = await referencedHiddenSourceFiles(dir, observed, options);
180
+ return files.map((file) => file.path).sort();
179
181
  }
180
182
 
181
183
  /** The manifest's canonical length, from paths and sizes alone: every SHA-256 is 64 characters.
@@ -220,12 +222,13 @@ export function hashMemo(now = Date.now) {
220
222
  * for a link after the walk is refused rather than followed. Null when it is not. @param {string} root
221
223
  * @param {Found} file @param {typeof realpath} [resolve] */
222
224
  export async function openListed(root, file, resolve = realpath) {
223
- const handle = await open(file.full, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0)).catch(
224
- (/** @type {NodeJS.ErrnoException} */ error) => {
225
- if (error.code === "ELOOP" || error.code === "EMLINK") return null;
226
- throw error;
227
- },
228
- );
225
+ const handle = await open(
226
+ file.full,
227
+ constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0),
228
+ ).catch((/** @type {NodeJS.ErrnoException} */ error) => {
229
+ if (error.code === "ELOOP" || error.code === "EMLINK") return null;
230
+ throw error;
231
+ });
229
232
  if (!handle) return null;
230
233
  try {
231
234
  const opened = await handle.stat();
@@ -1,5 +1,5 @@
1
1
  {
2
- "policy_version": "portable-source-v12",
2
+ "policy_version": "portable-source-v13",
3
3
  "manifest": {
4
4
  "format_version": 1,
5
5
  "entrypoint": "index.html",
@@ -428,10 +428,10 @@
428
428
  },
429
429
  {
430
430
  "id": "hidden-asset",
431
- "regex": "(?!.*(?:^|/)(?:\\.next|\\.nuxt|\\.output|\\.svelte-kit|\\.vercel|\\.netlify|\\.wrangler|\\.astro|\\.turbo|\\.venv|\\.github)(?:/|$))(?=(?:[^/]+/)*\\.[^/]+/)(?:[^/]+/)+[^./][^/]*\\.(?:png|jpe?g|gif|webp|avif|svg|ico|bmp|tiff?|heic|heif|mp4|m4v|mov|webm|mkv|mxf|avi|mp3|wav|m4a|aac|ogg|oga|opus|flac|woff2?|ttf|otf|css|m?js|cjs)",
431
+ "regex": "(?!.*(?:^|/)(?:\\.next|\\.nuxt|\\.output|\\.svelte-kit|\\.vercel|\\.netlify|\\.wrangler|\\.astro|\\.turbo|\\.venv|\\.github)(?:/|$))(?=(?:[^/]+/)*\\.)(?:[^/]+/)*(?:[^./][^/]*\\.(?:png|jpe?g|gif|webp|avif|svg|ico|bmp|tiff?|heic|heif|mp4|m4v|mov|webm|mkv|mxf|avi|mp3|wav|m4a|aac|ogg|oga|opus|flac|woff2?|ttf|otf|css|m?js|cjs)|\\.[^/]+\\.(?:woff2?|ttf|otf))",
432
432
  "client_action": "exclude",
433
433
  "server_action": "reject",
434
- "basis": "A referenced project asset in a hidden directory may travel only with include_hidden: true. Both the folded path and parser spelling must match this rule. Earlier exclusions take precedence."
434
+ "basis": "A referenced asset in a hidden directory or a referenced dot-prefixed font may travel with include_hidden: true. Both path spellings must match. Earlier exclusions take precedence."
435
435
  },
436
436
  {
437
437
  "id": "unrecognized-hidden",
@@ -12,7 +12,7 @@ import {
12
12
  withoutIgnorable,
13
13
  } from "./unicode.mjs";
14
14
 
15
- const PATH_POLICY_VERSION = "portable-source-v12";
15
+ const PATH_POLICY_VERSION = "portable-source-v13";
16
16
 
17
17
  /** @typedef {import("./types.js").PathRule} PathRule @typedef {import("./types.js").PolicyDocument} PolicyDocument */
18
18
 
@@ -0,0 +1,59 @@
1
+ // @ts-check
2
+ import { decodeWellFormedEscapes } from "@hyperframes/parsers/asset-paths";
3
+ import { realpath } from "node:fs/promises";
4
+ import { Readable } from "node:stream";
5
+ import { referencedHiddenSourceFiles, openListed } from "./capture.mjs";
6
+ import { isEligibleHiddenSourcePath } from "./pathPolicy.mjs";
7
+
8
+ /** Share concurrent scans of a project, then forget the result so the next preview sees edits.
9
+ * @type {Map<string, Promise<import("./types.js").Found[]>>} */
10
+ const scanning = new Map();
11
+
12
+ /** @param {string} root */
13
+ function referencedFiles(root) {
14
+ let pending = scanning.get(root);
15
+ if (!pending) {
16
+ pending = referencedHiddenSourceFiles(root, undefined, { ignoreSyntax: "gitignore" }).finally(
17
+ () => scanning.delete(root),
18
+ );
19
+ scanning.set(root, pending);
20
+ }
21
+ return pending;
22
+ }
23
+
24
+ /** A private-file route may serve this one project font from the descriptor checked against the
25
+ * source inventory. A caller must never use the result to authorize a second open by pathname.
26
+ * @param {string} projectDir @param {string | URL} requested @param {string} method */
27
+ export async function referencedFontResponse(projectDir, requested, method) {
28
+ const path =
29
+ typeof requested === "string"
30
+ ? requested
31
+ : decodeWellFormedEscapes(requested.pathname.slice(1));
32
+ const font = /(?:^|\/)\.[^/]+\.(woff2?|ttf|otf)$/i.exec(path);
33
+ if (!font || (method !== "HEAD" && method !== "GET") || !isEligibleHiddenSourcePath(path))
34
+ return null;
35
+ try {
36
+ const root = await realpath(projectDir);
37
+ const file = (await referencedFiles(root)).find((entry) => entry.path === path);
38
+ if (!file) return null;
39
+ const { size } = file;
40
+ const handle = await openListed(root, file);
41
+ if (!handle) return null;
42
+ const headers = {
43
+ "Content-Type": "font/" + font[1].toLowerCase(),
44
+ "Cache-Control": "private, no-store",
45
+ "X-Content-Type-Options": "nosniff",
46
+ };
47
+ if (method === "HEAD" || !size) {
48
+ await handle.close();
49
+ return new Response(null, { headers: { ...headers, "Content-Length": String(size) } });
50
+ }
51
+ // Node and DOM stream declarations differ across supported TypeScript lib sets.
52
+ const body = /** @type {unknown} */ (
53
+ Readable.toWeb(handle.createReadStream({ end: size - 1 }))
54
+ );
55
+ return new Response(/** @type {ReadableStream<Uint8Array<ArrayBuffer>>} */ (body), { headers });
56
+ } catch {
57
+ return null;
58
+ }
59
+ }