@tdacorp/hyle-sdk 0.21.0 → 0.23.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 +141 -18
- package/dist/check-routes-bin.js +174 -42
- package/dist/{chunk-56Y24XBV.js → chunk-JHZJOJDC.js} +4 -3
- package/dist/{chunk-K5VDLROQ.js → chunk-SFFBZFEN.js} +34 -1
- package/dist/{chunk-HJX57NLI.js → chunk-UFMKLCXS.js} +246 -225
- package/dist/{chunk-X2TLYM7Y.js → chunk-VUML2UPD.js} +1 -1
- package/dist/chunk-VXARM37R.js +68 -0
- package/dist/{chunk-75JFLML4.js → chunk-YHXE3TGS.js} +94 -12
- package/dist/{client-41fU6OY2.d.cts → client--ighAWaj.d.ts} +13 -1
- package/dist/{client-LwzHwqpM.d.ts → client-DK-S2580.d.cts} +13 -1
- package/dist/code-copy.cjs +4 -2
- package/dist/code-copy.d.cts +5 -2
- package/dist/code-copy.d.ts +5 -2
- package/dist/code-copy.js +5 -3
- package/dist/comments.cjs +14 -6
- package/dist/comments.js +14 -6
- package/dist/docs-enhance.cjs +7 -4
- package/dist/docs-enhance.d.cts +5 -3
- package/dist/docs-enhance.d.ts +5 -3
- package/dist/docs-enhance.js +8 -5
- package/dist/{embed-BUFRQboD.d.ts → embed-XT0x_Jaa.d.cts} +4 -2
- package/dist/{embed-CYt-q13P.d.cts → embed-g7NT1CyB.d.ts} +4 -2
- package/dist/html.cjs +14 -6
- package/dist/html.d.cts +1 -1
- package/dist/html.d.ts +1 -1
- package/dist/html.js +2 -2
- package/dist/index.cjs +85 -12
- package/dist/index.d.cts +13 -11
- package/dist/index.d.ts +13 -11
- package/dist/index.js +2 -2
- package/dist/mermaid-diagram.cjs +46 -6
- package/dist/mermaid-diagram.js +15 -6
- package/dist/mermaid-image.cjs +4 -1
- package/dist/mermaid-image.js +1 -1
- package/dist/next.cjs +521 -242
- package/dist/next.d.cts +74 -17
- package/dist/next.d.ts +74 -17
- package/dist/next.js +207 -33
- package/dist/print-coordinator.js +1 -1
- package/dist/react.cjs +233 -197
- package/dist/react.d.cts +17 -6
- package/dist/react.d.ts +17 -6
- package/dist/react.js +5 -3
- package/dist/{resolve-BjAK0k_Y.d.ts → resolve-BqC9l5RH.d.ts} +1 -1
- package/dist/{resolve-eI1muCKL.d.cts → resolve-CiZCPysX.d.cts} +1 -1
- package/dist/{sanitize-ijiWjEm9.d.cts → sanitize-BpY_AdZh.d.cts} +1 -1
- package/dist/{sanitize-ijiWjEm9.d.ts → sanitize-BpY_AdZh.d.ts} +1 -1
- package/dist/styles.css +4 -4
- package/dist/toc-spy.cjs +2 -1
- package/dist/toc-spy.js +2 -1
- package/dist/{types-3F0wqD-o.d.cts → types-b9QbmEDd.d.cts} +44 -1
- package/dist/{types-3F0wqD-o.d.ts → types-b9QbmEDd.d.ts} +44 -1
- package/dist/use-cache.cjs +73 -3
- package/dist/use-cache.d.cts +3 -3
- package/dist/use-cache.d.ts +3 -3
- package/dist/use-cache.js +3 -3
- package/package.json +3 -3
- package/dist/chunk-67IOIAVW.js +0 -35
package/dist/check-routes-bin.js
CHANGED
|
@@ -6,9 +6,20 @@ import { join } from "path";
|
|
|
6
6
|
var ASSET_ROUTE_PREFIX = "/api/hyle/assets";
|
|
7
7
|
var ASSET_RESERVED_PATH = "/api/hyle/*";
|
|
8
8
|
var UUID = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
|
|
9
|
-
var EXTENSIONS = "png|jpg|gif|webp|svg|pdf|mp4|webm|mp3|ogg";
|
|
9
|
+
var EXTENSIONS = "png|jpg|gif|webp|svg|pdf|mp4|webm|mp3|ogg|woff2";
|
|
10
10
|
var ASSET_FILE = new RegExp(`^${UUID}(?:\\.(?:${EXTENSIONS}))?$`);
|
|
11
|
-
var
|
|
11
|
+
var THEME_FONT = new RegExp(`^/assets/${UUID}\\.woff2$`);
|
|
12
|
+
var PREVIEW_TOKEN_SOURCE = "hyle_pv_[A-Za-z0-9_-]{43}";
|
|
13
|
+
var PREVIEW_TOKEN = new RegExp(`^${PREVIEW_TOKEN_SOURCE}$`);
|
|
14
|
+
var PREVIEW_HEADER = "cp-preview";
|
|
15
|
+
var PREVIEW_PARAM = "hyle_preview";
|
|
16
|
+
var PREVIEW_QUERY_SOURCE = `\\?${PREVIEW_PARAM}=${PREVIEW_TOKEN_SOURCE}`;
|
|
17
|
+
var PROTECTED_PARAM = "hyle_protected";
|
|
18
|
+
var PROTECTED_HEADER = "cp-protected";
|
|
19
|
+
var PROTECTED_ID = new RegExp(`^${UUID}$`);
|
|
20
|
+
var PROTECTED_PASSWORD = /^[A-Za-z0-9]{16}$/;
|
|
21
|
+
var PROTECTED_QUERY_SOURCE = `\\?${PROTECTED_PARAM}=${UUID}`;
|
|
22
|
+
var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)(${PREVIEW_QUERY_SOURCE}|${PROTECTED_QUERY_SOURCE})?$`, "i");
|
|
12
23
|
|
|
13
24
|
// src/errors.ts
|
|
14
25
|
var Cp1ClientError = class extends Error {
|
|
@@ -26,6 +37,30 @@ var Cp1ClientError = class extends Error {
|
|
|
26
37
|
}
|
|
27
38
|
};
|
|
28
39
|
|
|
40
|
+
// src/preview.ts
|
|
41
|
+
var ASSET_PATH = /^\/assets\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}(?:\.[a-z0-9]+)?(?= |$)/i;
|
|
42
|
+
var ASSET_PROPERTIES = ["src", "dataLight", "dataDark"];
|
|
43
|
+
var MAX_DEPTH = 200;
|
|
44
|
+
function mapNode(node, mark, depth) {
|
|
45
|
+
if (typeof node !== "object" || node === null || depth > MAX_DEPTH) return node;
|
|
46
|
+
const { properties, children } = node;
|
|
47
|
+
const marked = properties && Object.fromEntries(ASSET_PROPERTIES.filter((name) => name in properties).map((name) => [name, mark(properties[name])]));
|
|
48
|
+
return {
|
|
49
|
+
...node,
|
|
50
|
+
...properties ? { properties: { ...properties, ...marked } } : {},
|
|
51
|
+
...Array.isArray(children) ? { children: children.map((child) => mapNode(child, mark, depth + 1)) } : {}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function withAssetQuery(article, query) {
|
|
55
|
+
const mark = (value) => typeof value === "string" ? value.replace(ASSET_PATH, (path) => `${path}?${query}`) : value;
|
|
56
|
+
const { publication, content } = article;
|
|
57
|
+
return {
|
|
58
|
+
...article,
|
|
59
|
+
publication: publication.cover ? { ...publication, cover: { path: String(mark(publication.cover.path)) } } : publication,
|
|
60
|
+
content: content.format === "hast" ? { ...content, tree: mapNode(content.tree, mark, 0) } : content
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
29
64
|
// src/client.ts
|
|
30
65
|
var RENDERER_VERSION = "4";
|
|
31
66
|
function applyCredential(headers, credential, method, url) {
|
|
@@ -138,8 +173,31 @@ function createHyleClient(options) {
|
|
|
138
173
|
if (data?.cp === 1 && data.kind === "push_posts" && Array.isArray(data.posts) && typeof data.complete === "boolean") return data;
|
|
139
174
|
throw failure(reply);
|
|
140
175
|
}
|
|
176
|
+
async function preview(token) {
|
|
177
|
+
if (typeof token !== "string" || !PREVIEW_TOKEN.test(token)) return { kind: "notfound" };
|
|
178
|
+
const reply = await get("/cp1/read/_preview", new URLSearchParams(), { headers: { [PREVIEW_HEADER]: token }, cache: "no-store" });
|
|
179
|
+
if (reply.status === 404 && reply.parsed?.error?.code === "NOT_FOUND") return { kind: "notfound" };
|
|
180
|
+
const data = reply.parsed?.data;
|
|
181
|
+
if (data?.cp === 1 && data.kind === "disabled") return { kind: "disabled" };
|
|
182
|
+
const article = data?.article;
|
|
183
|
+
if (data?.cp !== 1 || data.kind !== "preview" || typeof data.expires_at !== "string" || article?.kind !== "article" || article.content?.format !== "hast" || !article.publication) throw failure(reply);
|
|
184
|
+
return { kind: "preview", expires_at: data.expires_at, article: withAssetQuery(article, `${PREVIEW_PARAM}=${token}`) };
|
|
185
|
+
}
|
|
186
|
+
async function protectedPage(pageId, password) {
|
|
187
|
+
if (!PROTECTED_ID.test(pageId) || !PROTECTED_PASSWORD.test(password)) return { kind: "notfound" };
|
|
188
|
+
const reply = await get("/cp1/read/_protected", new URLSearchParams(), { headers: { [PROTECTED_HEADER]: `${pageId}.${password}` }, cache: "no-store" });
|
|
189
|
+
if (reply.status === 404 && reply.parsed?.error?.code === "NOT_FOUND") return { kind: "notfound" };
|
|
190
|
+
const data = reply.parsed?.data;
|
|
191
|
+
if (data?.cp === 1 && data.kind === "disabled") return { kind: "disabled" };
|
|
192
|
+
const article = data?.article;
|
|
193
|
+
const expires = data?.expires_at;
|
|
194
|
+
if (data?.cp !== 1 || data.kind !== "protected" || typeof expires !== "string" && expires !== null || article?.kind !== "article" || article.content?.format !== "hast" || !article.publication) throw failure(reply);
|
|
195
|
+
return { kind: "protected", expires_at: expires, article: withAssetQuery(article, `${PROTECTED_PARAM}=${pageId}`) };
|
|
196
|
+
}
|
|
141
197
|
async function asset(file, opts = {}) {
|
|
142
198
|
if (!ASSET_FILE.test(file)) throw new TypeError("asset file must be <uuid>[.<ext>]");
|
|
199
|
+
const { previewToken } = opts;
|
|
200
|
+
if (previewToken !== void 0 && !PREVIEW_TOKEN.test(previewToken)) throw new TypeError("previewToken is not a preview token");
|
|
143
201
|
const url = `${base}/cp1/read/assets/${file}`;
|
|
144
202
|
const headers = new Headers();
|
|
145
203
|
const applied = applyCredential(headers, options, "GET", url);
|
|
@@ -148,23 +206,34 @@ function createHyleClient(options) {
|
|
|
148
206
|
const value = opts.headers?.[name];
|
|
149
207
|
if (value) headers.set(name, value);
|
|
150
208
|
}
|
|
209
|
+
const { protectedAccess } = opts;
|
|
210
|
+
if (protectedAccess !== void 0 && !(PROTECTED_ID.test(protectedAccess.pageId) && PROTECTED_PASSWORD.test(protectedAccess.password))) throw new TypeError("protectedAccess is not a page id and password");
|
|
211
|
+
if (previewToken !== void 0) headers.set(PREVIEW_HEADER, previewToken);
|
|
212
|
+
if (protectedAccess !== void 0) headers.set(PROTECTED_HEADER, `${protectedAccess.pageId}.${protectedAccess.password}`);
|
|
213
|
+
const uncached = previewToken !== void 0 || protectedAccess !== void 0;
|
|
214
|
+
return fetchImpl(url, { method: "GET", headers, redirect: "error", signal: AbortSignal.timeout(opts.timeoutMs ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS), ...uncached ? { cache: "no-store" } : {} });
|
|
215
|
+
}
|
|
216
|
+
async function theme(opts = {}) {
|
|
217
|
+
const url = `${base}/cp1/read/theme.css`;
|
|
218
|
+
const headers = new Headers();
|
|
219
|
+
const applied = applyCredential(headers, options, "GET", url);
|
|
220
|
+
if (applied) await applied;
|
|
151
221
|
return fetchImpl(url, { method: "GET", headers, redirect: "error", signal: AbortSignal.timeout(opts.timeoutMs ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS) });
|
|
152
222
|
}
|
|
153
|
-
return { resolve, mounts, pushPosts, asset };
|
|
223
|
+
return { resolve, mounts, pushPosts, preview, protected: protectedPage, asset, theme };
|
|
154
224
|
}
|
|
155
225
|
|
|
156
226
|
// src/host-sync.ts
|
|
157
227
|
var CONTROL_TOKEN_PREFIX = "hyle_tc_";
|
|
158
228
|
var DEFAULT_TIMEOUT_MS2 = 1e4;
|
|
159
229
|
var MAX_RESPONSE_BYTES = 1024 * 1024;
|
|
160
|
-
|
|
161
|
-
async function syncHostReserved(input) {
|
|
230
|
+
async function put(input, path, body, read) {
|
|
162
231
|
checkBaseUrl(input.baseUrl, input.allowInsecureHttp);
|
|
163
232
|
if (input.token !== void 0 && !input.token.startsWith(CONTROL_TOKEN_PREFIX)) {
|
|
164
233
|
throw new TypeError("syncing needs a control credential (hyle_tc_...); a target token is read-only and cannot write");
|
|
165
234
|
}
|
|
166
235
|
const fetchImpl = input.fetch ?? fetch;
|
|
167
|
-
const url = `${input.baseUrl.replace(/\/+$/, "")}${
|
|
236
|
+
const url = `${input.baseUrl.replace(/\/+$/, "")}${path}`;
|
|
168
237
|
const headers = new Headers({ "content-type": "application/json", "idempotency-key": `sync-${crypto.randomUUID()}` });
|
|
169
238
|
await applyCredential(headers, input.auth ? { auth: input.auth, workspaceId: input.workspaceId } : { token: input.token }, "PUT", url);
|
|
170
239
|
headers.set("cp-workspace", input.workspaceId);
|
|
@@ -174,7 +243,7 @@ async function syncHostReserved(input) {
|
|
|
174
243
|
redirect: "error",
|
|
175
244
|
signal: AbortSignal.timeout(input.timeoutMs ?? DEFAULT_TIMEOUT_MS2),
|
|
176
245
|
headers,
|
|
177
|
-
body: JSON.stringify(
|
|
246
|
+
body: JSON.stringify(body)
|
|
178
247
|
});
|
|
179
248
|
const text = await readCapped(res, MAX_RESPONSE_BYTES);
|
|
180
249
|
let parsed;
|
|
@@ -183,14 +252,24 @@ async function syncHostReserved(input) {
|
|
|
183
252
|
} catch {
|
|
184
253
|
parsed = void 0;
|
|
185
254
|
}
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
if (res.ok && data && Array.isArray(data.paths) && typeof data.changed === "boolean" && typeof data.synced_at === "string" && typeof conflicts?.total === "number" && Array.isArray(conflicts.offenders)) {
|
|
189
|
-
return { paths: data.paths, changed: data.changed, syncedAt: data.synced_at, conflicts: { total: conflicts.total, offenders: conflicts.offenders } };
|
|
190
|
-
}
|
|
255
|
+
const result = res.ok && parsed?.data ? read(parsed.data) : void 0;
|
|
256
|
+
if (result !== void 0) return result;
|
|
191
257
|
const err = parsed?.error;
|
|
192
258
|
throw new Cp1ClientError(err?.code ?? "INVALID_RESPONSE", err?.message ?? `Unexpected response from hyle (HTTP ${res.status})`, res.status, err?.request_id ?? "", err?.details);
|
|
193
259
|
}
|
|
260
|
+
function syncHostReserved(input) {
|
|
261
|
+
return put(input, "/cp1/control/workspace/host-reserved-paths", { paths: input.paths, host: input.host, build_id: input.buildId }, (data) => {
|
|
262
|
+
const conflicts = data.conflicts;
|
|
263
|
+
if (!Array.isArray(data.paths) || typeof data.changed !== "boolean" || typeof data.synced_at !== "string" || typeof conflicts?.total !== "number" || !Array.isArray(conflicts.offenders)) return void 0;
|
|
264
|
+
return { paths: data.paths, changed: data.changed, syncedAt: data.synced_at, conflicts: { total: conflicts.total, offenders: conflicts.offenders } };
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
function syncCodeTheme(input) {
|
|
268
|
+
return put(input, "/cp1/control/workspace/code-theme", { theme: input.theme, host: input.host, build_id: input.buildId }, ({ changed, cssChanged, hash, ignored }) => {
|
|
269
|
+
if (typeof changed !== "boolean" || typeof cssChanged !== "boolean" || hash !== null && typeof hash !== "string" || !Array.isArray(ignored)) return void 0;
|
|
270
|
+
return { changed, cssChanged, hash, ignored: ignored.map(String) };
|
|
271
|
+
});
|
|
272
|
+
}
|
|
194
273
|
|
|
195
274
|
// src/next/paths.ts
|
|
196
275
|
function normalizeBasePath(basePath) {
|
|
@@ -421,7 +500,7 @@ async function listPublicationPaths(options) {
|
|
|
421
500
|
|
|
422
501
|
// src/check-routes-cli.ts
|
|
423
502
|
var USAGE = `hyle-sdk-check-routes [--next-dir .next] [--base-url URL] [--json] [--print-reserved]
|
|
424
|
-
[--sync [--strict] [--no-check] [--host ID] [--build-id ID] [--allow-empty] [--allow-non-production]]
|
|
503
|
+
[--sync [--theme] [--strict] [--no-check] [--host ID] [--build-id ID] [--allow-empty] [--allow-non-production]]
|
|
425
504
|
[--locales en,fr,es --default-locale en --locale-prefix as-needed|always|never] [--hyle-param hyle]
|
|
426
505
|
|
|
427
506
|
Run after \`next build\`. Reads the build's route manifests and hyle's read-only endpoints (mounts, and the published pages of each mount).
|
|
@@ -429,17 +508,20 @@ Credentials: HYLE_TARGET_BASE_URL (or --base-url) and HYLE_TARGET_TOKEN. The tok
|
|
|
429
508
|
(a) hyle pages a host static route shadows, (b) host dynamic routes that match hyle URLs, (c) mounts that are host static routes.
|
|
430
509
|
--print-reserved print the host's routes in hyle's "Reserved paths" format and exit.
|
|
431
510
|
--sync report that list to hyle (ADR 0016) so nobody maintains it by hand, then run the check. Needs HYLE_CONTROL_TOKEN
|
|
432
|
-
(a hyle_tc_ control credential with hyle.workspace.
|
|
511
|
+
(a hyle_tc_ control credential with hyle.workspace.sync_host; the read token cannot write), read from the environment only.
|
|
433
512
|
A failed sync only warns, so it never fails a deploy, unless --strict (exit 3). Skipped on a non-production Vercel
|
|
434
513
|
build (VERCEL_ENV) unless --allow-non-production. --no-check syncs without the collision check. The host id comes
|
|
435
514
|
from --host, HYLE_HOST_ID or VERCEL_PROJECT_PRODUCTION_URL; the build id from <next-dir>/BUILD_ID or --build-id.
|
|
436
515
|
An empty list is refused unless --allow-empty.
|
|
516
|
+
--theme with --sync: also send ./hyle.theme.json as the workspace's code theme (ADR 0036), with the same
|
|
517
|
+
credential and the same failure, preview and --strict rules. The file replaces the code theme.
|
|
437
518
|
Exit: 0 no collision, 1 collision (a) or (c), 2 cannot run, 3 sync failed under --strict.`;
|
|
438
519
|
var FLAGS = /* @__PURE__ */ new Set(["--next-dir", "--base-url", "--locales", "--default-locale", "--locale-prefix", "--hyle-param", "--host", "--build-id"]);
|
|
439
|
-
var BOOLEAN = /* @__PURE__ */ new Set(["--json", "--print-reserved", "--help", "--sync", "--strict", "--no-check", "--allow-empty", "--allow-non-production"]);
|
|
520
|
+
var BOOLEAN = /* @__PURE__ */ new Set(["--json", "--print-reserved", "--help", "--sync", "--theme", "--strict", "--no-check", "--allow-empty", "--allow-non-production"]);
|
|
440
521
|
var CANNOT_RUN = 2;
|
|
441
522
|
var SYNC_FAILED = 3;
|
|
442
523
|
var MAX_SYNCED_PATHS = 512;
|
|
524
|
+
var THEME_FILE = "hyle.theme.json";
|
|
443
525
|
function parseArgs(argv) {
|
|
444
526
|
const args = /* @__PURE__ */ new Map();
|
|
445
527
|
for (let i = 0; i < argv.length; i++) {
|
|
@@ -452,35 +534,36 @@ function parseArgs(argv) {
|
|
|
452
534
|
}
|
|
453
535
|
var readJson = (file) => JSON.parse(readFileSync(file, "utf8"));
|
|
454
536
|
var SAFE_ID = /[^A-Za-z0-9._-]/g;
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
}
|
|
462
|
-
const { baseUrl, mounts } = ctx.plan;
|
|
537
|
+
function failed(io, step, reason) {
|
|
538
|
+
io.err(`${step}: ${printable(reason)}`);
|
|
539
|
+
return { status: "failed", reason };
|
|
540
|
+
}
|
|
541
|
+
var errorText = (error) => error instanceof Error ? `${error.name}: ${error.message}` : "unknown error";
|
|
542
|
+
function syncTarget(args, io, nextDir, { baseUrl, mounts, mountsError }) {
|
|
463
543
|
const token = io.env.HYLE_CONTROL_TOKEN;
|
|
464
|
-
if (!token) return
|
|
465
|
-
if (!baseUrl || !mounts) return
|
|
544
|
+
if (!token) return "set HYLE_CONTROL_TOKEN (a hyle_tc_ control credential with hyle.workspace.sync_host; the read token cannot write)";
|
|
545
|
+
if (!baseUrl || !mounts) return mountsError ?? "set HYLE_TARGET_BASE_URL (or --base-url) and HYLE_TARGET_TOKEN so the workspace can be found";
|
|
466
546
|
const host = (args.get("--host") ?? io.env.HYLE_HOST_ID ?? io.env.VERCEL_PROJECT_PRODUCTION_URL)?.replace(SAFE_ID, "-").slice(0, 128);
|
|
467
|
-
if (!host) return
|
|
547
|
+
if (!host) return "name this host with --host, HYLE_HOST_ID or VERCEL_PROJECT_PRODUCTION_URL";
|
|
468
548
|
let buildId = args.get("--build-id") ?? io.env.VERCEL_GIT_COMMIT_SHA;
|
|
469
549
|
try {
|
|
470
|
-
buildId = readFileSync(join(
|
|
550
|
+
buildId = readFileSync(join(nextDir, "BUILD_ID"), "utf8").trim();
|
|
471
551
|
} catch {
|
|
472
552
|
}
|
|
473
553
|
buildId = buildId?.replace(SAFE_ID, "-").slice(0, 128);
|
|
474
|
-
if (!buildId) return
|
|
475
|
-
|
|
476
|
-
|
|
554
|
+
if (!buildId) return "no build id: <next-dir>/BUILD_ID is missing; pass --build-id";
|
|
555
|
+
return { baseUrl, token, workspaceId: mounts.workspaceId, host, buildId, ...io.fetch ? { fetch: io.fetch } : {} };
|
|
556
|
+
}
|
|
557
|
+
async function pathsStep(args, io, target, ctx) {
|
|
558
|
+
const rootMount = ctx.prefixes.includes("/");
|
|
559
|
+
const fromHost = reservedFor(ctx.hostRoutes, { ...ctx.locale ? { locale: ctx.locale } : {}, mounts: ctx.prefixes, hyleParam: ctx.hyleParam }).filter((p) => !(rootMount && p === "/"));
|
|
477
560
|
const reserved = [.../* @__PURE__ */ new Set([...fromHost, ...SDK_OWN_RESERVED])].sort();
|
|
478
|
-
if (fromHost.length === 0 && !args.has("--allow-empty")) return
|
|
479
|
-
if (reserved.length > MAX_SYNCED_PATHS) return
|
|
561
|
+
if (fromHost.length === 0 && !args.has("--allow-empty")) return failed(io, "sync", "the build has no reservable routes; refusing to replace hyle's list with an empty one (--allow-empty overrides)");
|
|
562
|
+
if (reserved.length > MAX_SYNCED_PATHS) return failed(io, "sync", `${reserved.length} reserved paths exceed hyle's limit of ${MAX_SYNCED_PATHS}`);
|
|
480
563
|
try {
|
|
481
|
-
const result = await syncHostReserved({
|
|
564
|
+
const result = await syncHostReserved({ ...target, paths: reserved });
|
|
482
565
|
if (!args.has("--json")) {
|
|
483
|
-
io.out(`sync: ${result.paths.length} reserved paths ${result.changed ? "updated" : "unchanged"} in hyle (host ${printable(host)}, build ${printable(buildId)})`);
|
|
566
|
+
io.out(`sync: ${result.paths.length} reserved paths ${result.changed ? "updated" : "unchanged"} in hyle (host ${printable(target.host)}, build ${printable(target.buildId)})`);
|
|
484
567
|
if (result.conflicts.total > 0) {
|
|
485
568
|
io.out(`sync: ${result.conflicts.total} published hyle URL(s) are on paths this host owns (hyle unpublished nothing):`);
|
|
486
569
|
for (const path of result.conflicts.offenders) io.out(` ${printable(path)}`);
|
|
@@ -488,13 +571,62 @@ async function syncStep(args, io, ctx) {
|
|
|
488
571
|
}
|
|
489
572
|
return { status: "ok", result };
|
|
490
573
|
} catch (error) {
|
|
491
|
-
return
|
|
574
|
+
return failed(io, "sync", errorText(error));
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
function refusalLines(error) {
|
|
578
|
+
const details = error instanceof Cp1ClientError ? error.details : void 0;
|
|
579
|
+
if (details?.reason !== "theme_refused" || typeof details.keys !== "string") return void 0;
|
|
580
|
+
const messages = typeof details.messages === "string" ? details.messages.split("\n") : [];
|
|
581
|
+
return details.keys.split("\n").map((key, i) => ` ${printable(key) || "(the file)"}: ${printable(messages[i] ?? "not accepted")}`);
|
|
582
|
+
}
|
|
583
|
+
async function themeStep(args, io, target) {
|
|
584
|
+
const dir = io.cwd ?? process.cwd();
|
|
585
|
+
let text;
|
|
586
|
+
try {
|
|
587
|
+
text = readFileSync(join(dir, THEME_FILE), "utf8");
|
|
588
|
+
} catch {
|
|
589
|
+
return failed(io, "theme", `no ${THEME_FILE} in ${dir} (or it cannot be read); run this where the file is`);
|
|
590
|
+
}
|
|
591
|
+
let theme;
|
|
592
|
+
try {
|
|
593
|
+
theme = JSON.parse(text);
|
|
594
|
+
} catch (error) {
|
|
595
|
+
return failed(io, "theme", `${THEME_FILE} is not valid JSON: ${error instanceof Error ? error.message : "unknown error"}`);
|
|
596
|
+
}
|
|
597
|
+
try {
|
|
598
|
+
const result = await syncCodeTheme({ ...target, theme });
|
|
599
|
+
if (result.ignored.length > 0) io.err(`theme: hyle ignored unknown keys: ${printable(result.ignored.join(", "))}`);
|
|
600
|
+
if (!args.has("--json")) io.out(`theme: ${THEME_FILE} synced, the stylesheet ${result.cssChanged ? "changed" : "is unchanged"} (host ${printable(target.host)}, build ${printable(target.buildId)})`);
|
|
601
|
+
return { status: "ok", result };
|
|
602
|
+
} catch (error) {
|
|
603
|
+
const lines = refusalLines(error);
|
|
604
|
+
if (lines) {
|
|
605
|
+
const reason = `hyle refused ${THEME_FILE}, so the theme was not changed:`;
|
|
606
|
+
io.err([`theme: ${reason}`, ...lines].join("\n"));
|
|
607
|
+
return { status: "failed", reason: [reason, ...lines].join("\n") };
|
|
608
|
+
}
|
|
609
|
+
const hint = error instanceof Cp1ClientError && error.status === 404 ? " (does the credential hold hyle.workspace.sync_host on this workspace, and does this hyle have themes?)" : "";
|
|
610
|
+
return failed(io, "theme", `${errorText(error)}${hint}`);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
async function syncSteps(args, io, ctx) {
|
|
614
|
+
const wantsTheme = args.has("--theme");
|
|
615
|
+
const vercelEnv = io.env.VERCEL_ENV;
|
|
616
|
+
if (vercelEnv !== void 0 && vercelEnv !== "production" && !args.has("--allow-non-production")) {
|
|
617
|
+
io.err(`sync: skipped, this is a ${printable(vercelEnv)} build (a preview must not replace what production synced; --allow-non-production overrides)`);
|
|
618
|
+
return { sync: { status: "skipped" }, ...wantsTheme ? { theme: { status: "skipped" } } : {} };
|
|
492
619
|
}
|
|
620
|
+
const target = syncTarget(args, io, ctx.nextDir, ctx.plan);
|
|
621
|
+
if (typeof target === "string") return { sync: failed(io, "sync", target), ...wantsTheme ? { theme: failed(io, "theme", target) } : {} };
|
|
622
|
+
const sync = await pathsStep(args, io, target, ctx);
|
|
623
|
+
return { sync, ...wantsTheme ? { theme: await themeStep(args, io, target) } : {} };
|
|
493
624
|
}
|
|
494
625
|
async function runCli(argv, io) {
|
|
495
626
|
try {
|
|
496
627
|
const args = parseArgs(argv);
|
|
497
628
|
if (args.has("--help")) return io.out(USAGE), 0;
|
|
629
|
+
if (args.has("--theme") && !args.has("--sync")) throw new Error("--theme needs --sync");
|
|
498
630
|
const nextDir = args.get("--next-dir") ?? ".next";
|
|
499
631
|
const hyleParam = args.get("--hyle-param") ?? "hyle";
|
|
500
632
|
let locale;
|
|
@@ -536,12 +668,13 @@ async function runCli(argv, io) {
|
|
|
536
668
|
}
|
|
537
669
|
const prefixes = mounts?.mounts.map((m) => m.prefix);
|
|
538
670
|
const strict = args.has("--strict");
|
|
539
|
-
let
|
|
671
|
+
let synced;
|
|
672
|
+
const exitAfterSync = () => strict && (synced?.sync.status === "failed" || synced?.theme?.status === "failed") ? SYNC_FAILED : 0;
|
|
540
673
|
if (args.has("--sync")) {
|
|
541
|
-
|
|
674
|
+
synced = await syncSteps(args, io, { nextDir, hostRoutes, locale, hyleParam, prefixes: prefixes ?? [], plan: { baseUrl, mounts: mounts?.kind === "mounts" ? { workspaceId: mounts.workspace_id } : void 0, ...mountsError instanceof Error ? { mountsError: errorText(mountsError) } : {} } });
|
|
542
675
|
if (args.has("--no-check")) {
|
|
543
|
-
if (args.has("--json")) io.out(JSON.stringify(
|
|
544
|
-
return
|
|
676
|
+
if (args.has("--json")) io.out(JSON.stringify(synced));
|
|
677
|
+
return exitAfterSync();
|
|
545
678
|
}
|
|
546
679
|
}
|
|
547
680
|
if (args.has("--print-reserved")) {
|
|
@@ -567,9 +700,8 @@ async function runCli(argv, io) {
|
|
|
567
700
|
}
|
|
568
701
|
}
|
|
569
702
|
const report = checkRoutes({ hostRoutes, mounts: mounts.mounts.map((m) => m.prefix), hylePaths: [...hylePaths], hyleParam, ...locale ? { locale } : {} });
|
|
570
|
-
io.out(args.has("--json") ? JSON.stringify(
|
|
571
|
-
|
|
572
|
-
return sync?.status === "failed" && strict ? SYNC_FAILED : 0;
|
|
703
|
+
io.out(args.has("--json") ? JSON.stringify({ ...report, ...synced }, null, 2) : formatReport(report));
|
|
704
|
+
return report.ok ? exitAfterSync() : 1;
|
|
573
705
|
} catch (error) {
|
|
574
706
|
io.err(`CANNOT RUN: ${error instanceof Error ? printable(`${error.name}: ${error.message}`) : "unknown error"}`);
|
|
575
707
|
return CANNOT_RUN;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
+
PREVIEW_QUERY_SOURCE,
|
|
2
3
|
hostAssetSrc
|
|
3
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-VXARM37R.js";
|
|
4
5
|
|
|
5
6
|
// src/react/sanitize.ts
|
|
6
7
|
var HastLimitError = class extends Error {
|
|
@@ -77,7 +78,7 @@ var ENTITIES = { "<": "<", "&": "&", "<": "<", ">": ">", "&"
|
|
|
77
78
|
function mermaidSource(srcDoc) {
|
|
78
79
|
return MERMAID_SRCDOC.exec(srcDoc)?.[1]?.replace(/&(?:#x3c|#x26|#x27|lt|gt|amp|quot);/gi, (e) => ENTITIES[e.toLowerCase()]);
|
|
79
80
|
}
|
|
80
|
-
var RENDER_REF =
|
|
81
|
+
var RENDER_REF = new RegExp(`^(/assets/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\\.svg(?:${PREVIEW_QUERY_SOURCE})?) ([1-9]\\d{0,5}) ([1-9]\\d{0,5})$`);
|
|
81
82
|
var isRenderRef = matches(RENDER_REF);
|
|
82
83
|
function diagramRender(value) {
|
|
83
84
|
const m = typeof value === "string" ? RENDER_REF.exec(value) : null;
|
|
@@ -214,7 +215,7 @@ function sanitizeHast(tree, title, description) {
|
|
|
214
215
|
const [first] = elements;
|
|
215
216
|
const skip = title !== void 0 && isObject(first) && first.tagName === "h1" && collapse(textOf(first)) === collapse(title) ? first : void 0;
|
|
216
217
|
const lead = elements[skip ? 1 : 0];
|
|
217
|
-
const repeat = description && isObject(lead) && lead.tagName === "p" && collapse(textOf(lead))
|
|
218
|
+
const repeat = description && isObject(lead) && lead.tagName === "p" && collapse(textOf(lead)) === collapse(description) && !holdsEmbed(lead) ? lead : void 0;
|
|
218
219
|
const budget = { nodes: 0, text: 0 };
|
|
219
220
|
return { type: "root", children: raw.filter((n) => n !== skip && n !== repeat).flatMap((n) => clean(n, 0, { katex: false }, budget)) };
|
|
220
221
|
}
|
|
@@ -9,6 +9,37 @@ var AUTO_RENDER_GROUPS = 25;
|
|
|
9
9
|
var CLAMP_LINES = 12;
|
|
10
10
|
var isClampedSource = (source) => source.trimEnd().split("\n").length > CLAMP_LINES;
|
|
11
11
|
var DARK_VARIABLES = { edgeLabelBackground: "#333333" };
|
|
12
|
+
var DIAGRAM_COLOUR_ROLES = ["bg", "node", "node-text", "node-border", "line", "accent", "muted"];
|
|
13
|
+
var THEME_COLOUR = /^(?:#[0-9a-f]{6}(?:[0-9a-f]{2})?|transparent)$/;
|
|
14
|
+
function diagramThemeVariables(colours, dark) {
|
|
15
|
+
const [bg, node, text, border, line, accent, muted] = colours;
|
|
16
|
+
return {
|
|
17
|
+
darkMode: dark,
|
|
18
|
+
background: bg,
|
|
19
|
+
primaryColor: node,
|
|
20
|
+
primaryTextColor: text,
|
|
21
|
+
primaryBorderColor: border,
|
|
22
|
+
secondaryColor: bg,
|
|
23
|
+
secondaryTextColor: text,
|
|
24
|
+
secondaryBorderColor: muted,
|
|
25
|
+
tertiaryColor: bg,
|
|
26
|
+
tertiaryTextColor: text,
|
|
27
|
+
tertiaryBorderColor: muted,
|
|
28
|
+
lineColor: line,
|
|
29
|
+
textColor: text,
|
|
30
|
+
titleColor: text,
|
|
31
|
+
edgeLabelBackground: bg,
|
|
32
|
+
clusterBkg: bg,
|
|
33
|
+
clusterBorder: muted,
|
|
34
|
+
noteBkgColor: bg,
|
|
35
|
+
noteTextColor: text,
|
|
36
|
+
noteBorderColor: accent,
|
|
37
|
+
activationBorderColor: accent,
|
|
38
|
+
actorLineColor: muted,
|
|
39
|
+
signalColor: line,
|
|
40
|
+
signalTextColor: text
|
|
41
|
+
};
|
|
42
|
+
}
|
|
12
43
|
var COLOR = /^(rgba?|oklab|oklch|lab|lch)\(([^)]*)\)$|^color\(srgb ([^)]*)\)$/;
|
|
13
44
|
function isDark(css) {
|
|
14
45
|
const m = COLOR.exec(css.trim());
|
|
@@ -31,7 +62,8 @@ function watchPageTheme(el, onTheme) {
|
|
|
31
62
|
const scheme = window.matchMedia("(prefers-color-scheme: dark)");
|
|
32
63
|
const update = () => {
|
|
33
64
|
const style = getComputedStyle(el);
|
|
34
|
-
|
|
65
|
+
const colours = DIAGRAM_COLOUR_ROLES.map((role) => style.getPropertyValue(`--hyle-diagram-${role}`).trim());
|
|
66
|
+
onTheme(pickMermaidTheme(style.backgroundColor, scheme.matches, style.colorScheme), colours.every((c) => THEME_COLOUR.test(c)) ? colours.join(" ") : "");
|
|
35
67
|
};
|
|
36
68
|
update();
|
|
37
69
|
const observer = new MutationObserver(update);
|
|
@@ -134,6 +166,7 @@ export {
|
|
|
134
166
|
MAX_MERMAID_EDGES,
|
|
135
167
|
isClampedSource,
|
|
136
168
|
DARK_VARIABLES,
|
|
169
|
+
diagramThemeVariables,
|
|
137
170
|
watchPageTheme,
|
|
138
171
|
RENDER_TIMEOUT_MS,
|
|
139
172
|
stripMermaidConfig,
|