@valbuild/server 0.150.14 → 0.150.17
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/CHANGELOG.md +37 -0
- package/browser/dist/valbuild-server-browser.cjs.dev.js +1 -1
- package/browser/dist/valbuild-server-browser.cjs.prod.js +1 -1
- package/browser/dist/valbuild-server-browser.esm.js +1 -1
- package/dist/{ValRouterCore-83973a50.cjs.prod.js → ValRouterCore-6cae8ef3.cjs.prod.js} +601 -7
- package/dist/{ValRouterCore-c4b07665.cjs.dev.js → ValRouterCore-71b88a4c.cjs.dev.js} +601 -7
- package/dist/{ValRouterCore-26bf9ed9.esm.js → ValRouterCore-8ec75007.esm.js} +596 -9
- package/dist/declarations/src/ValOps.d.ts +6 -0
- package/dist/declarations/src/ValOpsFS.d.ts +3 -0
- package/dist/declarations/src/ValOpsHttp.d.ts +3 -0
- package/dist/declarations/src/ValOpsMemory.d.ts +3 -0
- package/dist/declarations/src/ValRouter.d.ts +12 -0
- package/dist/declarations/src/ValServer.d.ts +7 -0
- package/dist/declarations/src/sketchpads/SketchpadStore.d.ts +76 -0
- package/dist/declarations/src/valServerConfig.d.ts +5 -4
- package/dist/{getJsonEntryAtCommit-64632fba.cjs.prod.js → getJsonEntryAtCommit-4649bb37.cjs.prod.js} +1 -1
- package/dist/{getJsonEntryAtCommit-7d550e7f.cjs.dev.js → getJsonEntryAtCommit-54478fa6.cjs.dev.js} +1 -1
- package/dist/{getJsonEntryAtCommit-28be5ffd.esm.js → getJsonEntryAtCommit-a5932dc3.esm.js} +1 -1
- package/dist/valbuild-server.cjs.dev.js +234 -7
- package/dist/valbuild-server.cjs.prod.js +234 -7
- package/dist/valbuild-server.esm.js +236 -9
- package/package.json +3 -3
|
@@ -12,7 +12,7 @@ var path = require('path');
|
|
|
12
12
|
var fs = require('fs');
|
|
13
13
|
var vm = require('node:vm');
|
|
14
14
|
var node_module = require('node:module');
|
|
15
|
-
var ValRouterCore = require('./ValRouterCore-
|
|
15
|
+
var ValRouterCore = require('./ValRouterCore-6cae8ef3.cjs.prod.js');
|
|
16
16
|
var server = require('@valbuild/ui/server');
|
|
17
17
|
var z = require('zod');
|
|
18
18
|
var zodValidationError = require('zod-validation-error');
|
|
@@ -2469,6 +2469,88 @@ async function withPatchLock(lockFilePath, options, fn) {
|
|
|
2469
2469
|
}
|
|
2470
2470
|
}
|
|
2471
2471
|
|
|
2472
|
+
/**
|
|
2473
|
+
* Sketchpads in `fs` mode: one JSON file each, in `.val/sketchpads/` beside
|
|
2474
|
+
* the patch store (and nothing to do with it -- a sketchpad is not an edit
|
|
2475
|
+
* and is never published).
|
|
2476
|
+
*
|
|
2477
|
+
* A file is replaced by writing a temporary one and renaming it over, so a
|
|
2478
|
+
* reader never sees half of one. Changes to one sketchpad are queued in this
|
|
2479
|
+
* process, so its version check and its write are one step. Two dev servers
|
|
2480
|
+
* writing the same sketchpad at the same instant could still race; that is
|
|
2481
|
+
* a cost local development can carry, and the content service, which hosts
|
|
2482
|
+
* every real project's, does the check in one database statement.
|
|
2483
|
+
*/
|
|
2484
|
+
function createFsSketchpadStore(rootDir, now = () => new Date()) {
|
|
2485
|
+
const dir = path__default["default"].join(rootDir, ".val", "sketchpads");
|
|
2486
|
+
const fileOf = id => path__default["default"].join(dir, `${id}.json`);
|
|
2487
|
+
const queues = new Map();
|
|
2488
|
+
const read = async id => {
|
|
2489
|
+
if (!ValRouterCore.isSketchpadId(id)) {
|
|
2490
|
+
return null;
|
|
2491
|
+
}
|
|
2492
|
+
let raw;
|
|
2493
|
+
try {
|
|
2494
|
+
raw = await fs__default["default"].promises.readFile(fileOf(id), "utf8");
|
|
2495
|
+
} catch {
|
|
2496
|
+
return null;
|
|
2497
|
+
}
|
|
2498
|
+
try {
|
|
2499
|
+
const parsed = internal.Sketchpad.safeParse(JSON.parse(raw));
|
|
2500
|
+
if (parsed.success) {
|
|
2501
|
+
return parsed.data;
|
|
2502
|
+
}
|
|
2503
|
+
} catch {
|
|
2504
|
+
// Reported below, as for a file that parsed and was not a sketchpad.
|
|
2505
|
+
}
|
|
2506
|
+
core.Internal.log.warn(`${fileOf(id)} is not a sketchpad, so it is left out. Move it away to stop this message.`);
|
|
2507
|
+
return null;
|
|
2508
|
+
};
|
|
2509
|
+
const write = async sketchpad => {
|
|
2510
|
+
await fs__default["default"].promises.mkdir(dir, {
|
|
2511
|
+
recursive: true
|
|
2512
|
+
});
|
|
2513
|
+
const temporary = `${fileOf(sketchpad.id)}.${process.pid}.tmp`;
|
|
2514
|
+
await fs__default["default"].promises.writeFile(temporary, JSON.stringify(sketchpad, null, 2));
|
|
2515
|
+
await fs__default["default"].promises.rename(temporary, fileOf(sketchpad.id));
|
|
2516
|
+
};
|
|
2517
|
+
|
|
2518
|
+
/** Runs `task` after every earlier change to `id` has finished. */
|
|
2519
|
+
const queued = (id, task) => {
|
|
2520
|
+
const previous = queues.get(id) ?? Promise.resolve();
|
|
2521
|
+
const next = previous.then(task, task);
|
|
2522
|
+
queues.set(id, next.catch(() => undefined));
|
|
2523
|
+
return next;
|
|
2524
|
+
};
|
|
2525
|
+
return {
|
|
2526
|
+
async list(filter) {
|
|
2527
|
+
let names;
|
|
2528
|
+
try {
|
|
2529
|
+
names = await fs__default["default"].promises.readdir(dir);
|
|
2530
|
+
} catch {
|
|
2531
|
+
return [];
|
|
2532
|
+
}
|
|
2533
|
+
const all = await Promise.all(names.filter(name => name.endsWith(".json")).map(name => read(name.slice(0, -".json".length))));
|
|
2534
|
+
return all.filter(sketchpad => sketchpad !== null).map(ValRouterCore.summaryOf).filter(sketchpad => ValRouterCore.matchesFilter(sketchpad, filter)).sort(ValRouterCore.byUpdatedAt);
|
|
2535
|
+
},
|
|
2536
|
+
get: read,
|
|
2537
|
+
async create(input) {
|
|
2538
|
+
const sketchpad = ValRouterCore.newSketchpad(input, now());
|
|
2539
|
+
await write(sketchpad);
|
|
2540
|
+
return sketchpad;
|
|
2541
|
+
},
|
|
2542
|
+
update(id, change) {
|
|
2543
|
+
return queued(id, async () => {
|
|
2544
|
+
const result = ValRouterCore.applySketchpadChange(await read(id), change, now());
|
|
2545
|
+
if (result.status === "updated") {
|
|
2546
|
+
await write(result.sketchpad);
|
|
2547
|
+
}
|
|
2548
|
+
return result;
|
|
2549
|
+
});
|
|
2550
|
+
}
|
|
2551
|
+
};
|
|
2552
|
+
}
|
|
2553
|
+
|
|
2472
2554
|
/** Serializes a schema, or gives up quietly — serialization errors are reported elsewhere. */
|
|
2473
2555
|
function serializeSchemaSafely(schema) {
|
|
2474
2556
|
try {
|
|
@@ -2494,8 +2576,12 @@ class ValOpsFS extends ValRouterCore.ValOps {
|
|
|
2494
2576
|
this.rootDir = rootDir;
|
|
2495
2577
|
this.host = new FSOpsHost();
|
|
2496
2578
|
this.jsonEntryFilesFingerprint = new JsonEntryFilesFingerprint(rootDir);
|
|
2579
|
+
this.sketchpads = createFsSketchpadStore(rootDir);
|
|
2497
2580
|
}
|
|
2498
2581
|
|
|
2582
|
+
/** In `.val/sketchpads`. See `sketchpads/fsSketchpadStore.ts`. */
|
|
2583
|
+
sketchpads;
|
|
2584
|
+
|
|
2499
2585
|
/**
|
|
2500
2586
|
* Change detection for `.jsonValues()` entry files, which no sha can see (their
|
|
2501
2587
|
* content lives behind a thunk that `JSON.stringify` drops).
|
|
@@ -5117,6 +5203,124 @@ function movesAtMerge(inputs, schemas) {
|
|
|
5117
5203
|
};
|
|
5118
5204
|
}
|
|
5119
5205
|
|
|
5206
|
+
/**
|
|
5207
|
+
* Sketchpads in `http` mode: the content service keeps them, per project, at
|
|
5208
|
+
* `/v1/{project}/sketchpads` (valbuild/home). This only carries requests
|
|
5209
|
+
* there and reads the answers; the version check is the service's, done in
|
|
5210
|
+
* one statement.
|
|
5211
|
+
*/
|
|
5212
|
+
function createHttpSketchpadStore(options) {
|
|
5213
|
+
const request = async (path, init) => fetch(`${options.url}${path}`, {
|
|
5214
|
+
method: init.method,
|
|
5215
|
+
headers: {
|
|
5216
|
+
...options.headers,
|
|
5217
|
+
// WHO, as for a proposal or a commit: the key names the project.
|
|
5218
|
+
...(init.by ? {
|
|
5219
|
+
"x-val-profile-id": init.by
|
|
5220
|
+
} : {}),
|
|
5221
|
+
...(init.body !== undefined ? {
|
|
5222
|
+
"Content-Type": "application/json"
|
|
5223
|
+
} : {})
|
|
5224
|
+
},
|
|
5225
|
+
...(init.body !== undefined ? {
|
|
5226
|
+
body: JSON.stringify(init.body)
|
|
5227
|
+
} : {})
|
|
5228
|
+
});
|
|
5229
|
+
const failed = async (res, doing) => new Error(`Val Build could not ${doing} (HTTP ${res.status}): ${await res.text().catch(() => "")}`);
|
|
5230
|
+
return {
|
|
5231
|
+
async list(filter) {
|
|
5232
|
+
const query = new URLSearchParams({
|
|
5233
|
+
archived: filter.archived
|
|
5234
|
+
});
|
|
5235
|
+
if (filter.page !== undefined) {
|
|
5236
|
+
query.set("page", filter.page);
|
|
5237
|
+
}
|
|
5238
|
+
const res = await request(`?${query}`, {
|
|
5239
|
+
method: "GET"
|
|
5240
|
+
});
|
|
5241
|
+
if (!res.ok) {
|
|
5242
|
+
throw await failed(res, "list the sketchpads");
|
|
5243
|
+
}
|
|
5244
|
+
return z.z.object({
|
|
5245
|
+
sketchpads: z.z.array(internal.SketchpadSummary)
|
|
5246
|
+
}).parse(await res.json()).sketchpads;
|
|
5247
|
+
},
|
|
5248
|
+
async get(id) {
|
|
5249
|
+
if (!ValRouterCore.isSketchpadId(id)) {
|
|
5250
|
+
return null;
|
|
5251
|
+
}
|
|
5252
|
+
const res = await request(`/${encodeURIComponent(id)}`, {
|
|
5253
|
+
method: "GET"
|
|
5254
|
+
});
|
|
5255
|
+
if (res.status === 404) {
|
|
5256
|
+
return null;
|
|
5257
|
+
}
|
|
5258
|
+
if (!res.ok) {
|
|
5259
|
+
throw await failed(res, "read the sketchpad");
|
|
5260
|
+
}
|
|
5261
|
+
return z.z.object({
|
|
5262
|
+
sketchpad: internal.Sketchpad
|
|
5263
|
+
}).parse(await res.json()).sketchpad;
|
|
5264
|
+
},
|
|
5265
|
+
async create(input) {
|
|
5266
|
+
const res = await request("", {
|
|
5267
|
+
method: "POST",
|
|
5268
|
+
body: {
|
|
5269
|
+
text: input.text,
|
|
5270
|
+
title: input.title,
|
|
5271
|
+
page: input.page
|
|
5272
|
+
},
|
|
5273
|
+
by: input.by
|
|
5274
|
+
});
|
|
5275
|
+
if (!res.ok) {
|
|
5276
|
+
throw await failed(res, "make the sketchpad");
|
|
5277
|
+
}
|
|
5278
|
+
return z.z.object({
|
|
5279
|
+
sketchpad: internal.Sketchpad
|
|
5280
|
+
}).parse(await res.json()).sketchpad;
|
|
5281
|
+
},
|
|
5282
|
+
async update(id, change) {
|
|
5283
|
+
if (!ValRouterCore.isSketchpadId(id)) {
|
|
5284
|
+
return {
|
|
5285
|
+
status: "not-found"
|
|
5286
|
+
};
|
|
5287
|
+
}
|
|
5288
|
+
const {
|
|
5289
|
+
by,
|
|
5290
|
+
...body
|
|
5291
|
+
} = change;
|
|
5292
|
+
const res = await request(`/${encodeURIComponent(id)}`, {
|
|
5293
|
+
method: "PATCH",
|
|
5294
|
+
body,
|
|
5295
|
+
by
|
|
5296
|
+
});
|
|
5297
|
+
if (res.status === 404) {
|
|
5298
|
+
return {
|
|
5299
|
+
status: "not-found"
|
|
5300
|
+
};
|
|
5301
|
+
}
|
|
5302
|
+
if (res.status === 409) {
|
|
5303
|
+
const current = z.z.object({
|
|
5304
|
+
sketchpad: internal.Sketchpad
|
|
5305
|
+
}).parse(await res.json()).sketchpad;
|
|
5306
|
+
return {
|
|
5307
|
+
status: "conflict",
|
|
5308
|
+
sketchpad: current
|
|
5309
|
+
};
|
|
5310
|
+
}
|
|
5311
|
+
if (!res.ok) {
|
|
5312
|
+
throw await failed(res, "save the sketchpad");
|
|
5313
|
+
}
|
|
5314
|
+
return {
|
|
5315
|
+
status: "updated",
|
|
5316
|
+
sketchpad: z.z.object({
|
|
5317
|
+
sketchpad: internal.Sketchpad
|
|
5318
|
+
}).parse(await res.json()).sketchpad
|
|
5319
|
+
};
|
|
5320
|
+
}
|
|
5321
|
+
};
|
|
5322
|
+
}
|
|
5323
|
+
|
|
5120
5324
|
const textEncoder$2 = new TextEncoder();
|
|
5121
5325
|
|
|
5122
5326
|
/** The body of the content API's 403 for a write the project's plan refuses. */
|
|
@@ -5418,6 +5622,8 @@ class ValOpsHttp extends ValRouterCore.ValOps {
|
|
|
5418
5622
|
/** Val's content service owns the store. See {@link ValOps.patchesAreLocal}. */
|
|
5419
5623
|
patchesAreLocal = false;
|
|
5420
5624
|
kind = "http";
|
|
5625
|
+
/** The content service's. See `sketchpads/httpSketchpadStore.ts`. */
|
|
5626
|
+
sketchpads;
|
|
5421
5627
|
/** See {@link ValOps.requiresAuth}. */
|
|
5422
5628
|
requiresAuth = true;
|
|
5423
5629
|
/**
|
|
@@ -5545,6 +5751,10 @@ class ValOpsHttp extends ValRouterCore.ValOps {
|
|
|
5545
5751
|
Authorization: `Bearer ${auth.apiKey}`
|
|
5546
5752
|
};
|
|
5547
5753
|
this.root = (options === null || options === void 0 ? void 0 : options.root) ?? "";
|
|
5754
|
+
this.sketchpads = createHttpSketchpadStore({
|
|
5755
|
+
url: `${contentUrl}/v1/${project}/sketchpads`,
|
|
5756
|
+
headers: this.authHeaders
|
|
5757
|
+
});
|
|
5548
5758
|
this.proposal = (options === null || options === void 0 ? void 0 : options.proposal) ?? null;
|
|
5549
5759
|
this.contentVersion = this.proposal === null ? (options === null || options === void 0 ? void 0 : options.contentVersion) ?? null : null;
|
|
5550
5760
|
/*
|
|
@@ -8405,6 +8615,16 @@ async function initHandlerOptions(route, opts, config) {
|
|
|
8405
8615
|
});
|
|
8406
8616
|
if (isProxyMode) {
|
|
8407
8617
|
var _config$files, _opts$versions, _opts$versions2;
|
|
8618
|
+
/*
|
|
8619
|
+
* Where a self-hosted site's analytics beacons are counted. Only http mode
|
|
8620
|
+
* forwards them -- it is the mode with the project's api key -- so only
|
|
8621
|
+
* it resolves this, and only here is it checked for a plain-http host:
|
|
8622
|
+
* the api key goes with every beacon.
|
|
8623
|
+
*/
|
|
8624
|
+
const valAnalyticsIngestUrl = opts.valAnalyticsIngestUrl || process.env.VAL_ANALYTICS_INGEST_URL || ValRouterCore.DEFAULT_ANALYTICS_INGEST_URL;
|
|
8625
|
+
warnIfInsecureUrls({
|
|
8626
|
+
valAnalyticsIngestUrl
|
|
8627
|
+
});
|
|
8408
8628
|
/*
|
|
8409
8629
|
* Why this app is in http mode, in the message that says what is missing.
|
|
8410
8630
|
*
|
|
@@ -8525,6 +8745,7 @@ async function initHandlerOptions(route, opts, config) {
|
|
|
8525
8745
|
valDisableRedirectUrl,
|
|
8526
8746
|
valContentUrl,
|
|
8527
8747
|
valBuildUrl,
|
|
8748
|
+
valAnalyticsIngestUrl,
|
|
8528
8749
|
config
|
|
8529
8750
|
};
|
|
8530
8751
|
} else {
|
|
@@ -8639,10 +8860,11 @@ function createValOps(valModules, options) {
|
|
|
8639
8860
|
* so a single shared sentence would overstate one and understate the other.
|
|
8640
8861
|
*/
|
|
8641
8862
|
|
|
8642
|
-
const CREDENTIAL_BEARING_URLS = ["valBuildUrl", "valContentUrl"];
|
|
8863
|
+
const CREDENTIAL_BEARING_URLS = ["valBuildUrl", "valContentUrl", "valAnalyticsIngestUrl"];
|
|
8643
8864
|
const WHAT_IS_AT_RISK = {
|
|
8644
8865
|
valBuildUrl: "Val's api key is sent to this host, and the token it returns is what this server signs into the session cookie, " + "so both can be read - and the token replaced - by anyone on the network path.",
|
|
8645
|
-
valContentUrl: "Val's api key, or the caller's personal access token, is sent to this host, " + "so it can be read by anyone on the network path."
|
|
8866
|
+
valContentUrl: "Val's api key, or the caller's personal access token, is sent to this host, " + "so it can be read by anyone on the network path.",
|
|
8867
|
+
valAnalyticsIngestUrl: "Val's api key is sent to this host with every analytics beacon, " + "so it can be read by anyone on the network path."
|
|
8646
8868
|
};
|
|
8647
8869
|
|
|
8648
8870
|
// NOTE: `URL.hostname` keeps the brackets on an IPv6 literal, so this is
|
|
@@ -8670,9 +8892,10 @@ function forLog(parsed) {
|
|
|
8670
8892
|
* Returns a warning if `url` would send credentials somewhere they can be read
|
|
8671
8893
|
* off the wire, or null if it is fine.
|
|
8672
8894
|
*
|
|
8673
|
-
*
|
|
8674
|
-
* `VAL_BUILD_URL`, `opts.valContentUrl` / `VAL_CONTENT_URL
|
|
8675
|
-
*
|
|
8895
|
+
* Each URL defaults to https, but each is overridable - `opts.valBuildUrl` /
|
|
8896
|
+
* `VAL_BUILD_URL`, `opts.valContentUrl` / `VAL_CONTENT_URL`,
|
|
8897
|
+
* `opts.valAnalyticsIngestUrl` / `VAL_ANALYTICS_INGEST_URL` - and no override
|
|
8898
|
+
* was scheme-checked before this. Point one at a plain http host and the
|
|
8676
8899
|
* api key goes out in clear text, and whatever comes back is whatever the
|
|
8677
8900
|
* network says: for `valBuildUrl` that includes the app token this server
|
|
8678
8901
|
* re-signs into the session cookie.
|
|
@@ -8704,7 +8927,11 @@ function insecureUrlWarning(name, url) {
|
|
|
8704
8927
|
}
|
|
8705
8928
|
function warnIfInsecureUrls(urls) {
|
|
8706
8929
|
for (const name of CREDENTIAL_BEARING_URLS) {
|
|
8707
|
-
const
|
|
8930
|
+
const url = urls[name];
|
|
8931
|
+
if (url === undefined) {
|
|
8932
|
+
continue;
|
|
8933
|
+
}
|
|
8934
|
+
const warning = insecureUrlWarning(name, url);
|
|
8708
8935
|
if (warning) {
|
|
8709
8936
|
core.Internal.log.warn(warning);
|
|
8710
8937
|
}
|
|
@@ -10,12 +10,12 @@ import path from 'path';
|
|
|
10
10
|
import fs from 'fs';
|
|
11
11
|
import vm from 'node:vm';
|
|
12
12
|
import { Module } from 'node:module';
|
|
13
|
-
import { r as resolveExistingJsonPath, f as findNestedJsonValuesRecords, v as validateJsonValuesEntries, i as isJsonValuesRootOp, a as rebaseContentOp, c as classifyJsonValuesOp, V as ValOps,
|
|
14
|
-
export {
|
|
13
|
+
import { r as resolveExistingJsonPath, f as findNestedJsonValuesRecords, v as validateJsonValuesEntries, i as isJsonValuesRootOp, a as rebaseContentOp, c as classifyJsonValuesOp, s as summaryOf, m as matchesFilter, b as byUpdatedAt, n as newSketchpad, d as isSketchpadId, e as applySketchpadChange, V as ValOps, g as bufferFromDataUrl, h as getFieldsForType, u as uploadRemoteFile, j as getFileExt, k as guessMimeTypeFromPath, l as createMetadataFromBuffer, D as DEFAULT_ANALYTICS_INGEST_URL, o as ValOpsMemory, p as isHlsMasterPlaylist, q as sumHlsSegmentDurations, t as parseHlsMasterVariants, w as largestHlsVariant, x as fallbackRefOf, y as mapHlsUris, z as movedRemoteHost, A as needsHostCheck, B as rewriteRefHost, C as fallbackRemoteHost, E as checkRemoteFiles, F as ValServer, G as createValRequestHandler, H as getNewJsonEntryPaths, I as formatPatchSourceError } from './ValRouterCore-8ec75007.esm.js';
|
|
14
|
+
export { L as InMemoryPatchStore, o as ValOpsMemory, J as askOncePerHost, c as classifyJsonValuesOp, I as formatPatchSourceError, j as getFileExt, K as getSettings, a as rebaseContentOp, u as uploadRemoteFile } from './ValRouterCore-8ec75007.esm.js';
|
|
15
15
|
import { createUIRequestHandler } from '@valbuild/ui/server';
|
|
16
16
|
import z$1, { z } from 'zod';
|
|
17
17
|
import { fromError } from 'zod-validation-error';
|
|
18
|
-
import { Patch, schemaErrorsOf, PatchSets, joinSharedChanges, schemaTypesOfPath, sideFiles, sideSource, JSONValue, PlanRefusalError, PatchId as PatchId$1, SerializedSchema, getErrorMessageFromUnknownJson, newestCommitSha, LOCAL_FILE_IN_REMOTE_PROJECT_WARNING, LOCAL_FILE_IN_REMOTE_PROJECT_HINT, traverseSchemaSource, richTextImageSchema, forEachRichTextImage, isStudioFix } from '@valbuild/shared/internal';
|
|
18
|
+
import { Patch, Sketchpad, schemaErrorsOf, PatchSets, joinSharedChanges, schemaTypesOfPath, sideFiles, sideSource, JSONValue, SketchpadSummary, PlanRefusalError, PatchId as PatchId$1, SerializedSchema, getErrorMessageFromUnknownJson, newestCommitSha, LOCAL_FILE_IN_REMOTE_PROJECT_WARNING, LOCAL_FILE_IN_REMOTE_PROJECT_HINT, traverseSchemaSource, richTextImageSchema, forEachRichTextImage, isStudioFix } from '@valbuild/shared/internal';
|
|
19
19
|
import os from 'os';
|
|
20
20
|
import crypto$1, { createHash } from 'crypto';
|
|
21
21
|
import { Buffer as Buffer$1 } from 'buffer';
|
|
@@ -2433,6 +2433,88 @@ async function withPatchLock(lockFilePath, options, fn) {
|
|
|
2433
2433
|
}
|
|
2434
2434
|
}
|
|
2435
2435
|
|
|
2436
|
+
/**
|
|
2437
|
+
* Sketchpads in `fs` mode: one JSON file each, in `.val/sketchpads/` beside
|
|
2438
|
+
* the patch store (and nothing to do with it -- a sketchpad is not an edit
|
|
2439
|
+
* and is never published).
|
|
2440
|
+
*
|
|
2441
|
+
* A file is replaced by writing a temporary one and renaming it over, so a
|
|
2442
|
+
* reader never sees half of one. Changes to one sketchpad are queued in this
|
|
2443
|
+
* process, so its version check and its write are one step. Two dev servers
|
|
2444
|
+
* writing the same sketchpad at the same instant could still race; that is
|
|
2445
|
+
* a cost local development can carry, and the content service, which hosts
|
|
2446
|
+
* every real project's, does the check in one database statement.
|
|
2447
|
+
*/
|
|
2448
|
+
function createFsSketchpadStore(rootDir, now = () => new Date()) {
|
|
2449
|
+
const dir = path.join(rootDir, ".val", "sketchpads");
|
|
2450
|
+
const fileOf = id => path.join(dir, `${id}.json`);
|
|
2451
|
+
const queues = new Map();
|
|
2452
|
+
const read = async id => {
|
|
2453
|
+
if (!isSketchpadId(id)) {
|
|
2454
|
+
return null;
|
|
2455
|
+
}
|
|
2456
|
+
let raw;
|
|
2457
|
+
try {
|
|
2458
|
+
raw = await fs.promises.readFile(fileOf(id), "utf8");
|
|
2459
|
+
} catch {
|
|
2460
|
+
return null;
|
|
2461
|
+
}
|
|
2462
|
+
try {
|
|
2463
|
+
const parsed = Sketchpad.safeParse(JSON.parse(raw));
|
|
2464
|
+
if (parsed.success) {
|
|
2465
|
+
return parsed.data;
|
|
2466
|
+
}
|
|
2467
|
+
} catch {
|
|
2468
|
+
// Reported below, as for a file that parsed and was not a sketchpad.
|
|
2469
|
+
}
|
|
2470
|
+
Internal.log.warn(`${fileOf(id)} is not a sketchpad, so it is left out. Move it away to stop this message.`);
|
|
2471
|
+
return null;
|
|
2472
|
+
};
|
|
2473
|
+
const write = async sketchpad => {
|
|
2474
|
+
await fs.promises.mkdir(dir, {
|
|
2475
|
+
recursive: true
|
|
2476
|
+
});
|
|
2477
|
+
const temporary = `${fileOf(sketchpad.id)}.${process.pid}.tmp`;
|
|
2478
|
+
await fs.promises.writeFile(temporary, JSON.stringify(sketchpad, null, 2));
|
|
2479
|
+
await fs.promises.rename(temporary, fileOf(sketchpad.id));
|
|
2480
|
+
};
|
|
2481
|
+
|
|
2482
|
+
/** Runs `task` after every earlier change to `id` has finished. */
|
|
2483
|
+
const queued = (id, task) => {
|
|
2484
|
+
const previous = queues.get(id) ?? Promise.resolve();
|
|
2485
|
+
const next = previous.then(task, task);
|
|
2486
|
+
queues.set(id, next.catch(() => undefined));
|
|
2487
|
+
return next;
|
|
2488
|
+
};
|
|
2489
|
+
return {
|
|
2490
|
+
async list(filter) {
|
|
2491
|
+
let names;
|
|
2492
|
+
try {
|
|
2493
|
+
names = await fs.promises.readdir(dir);
|
|
2494
|
+
} catch {
|
|
2495
|
+
return [];
|
|
2496
|
+
}
|
|
2497
|
+
const all = await Promise.all(names.filter(name => name.endsWith(".json")).map(name => read(name.slice(0, -".json".length))));
|
|
2498
|
+
return all.filter(sketchpad => sketchpad !== null).map(summaryOf).filter(sketchpad => matchesFilter(sketchpad, filter)).sort(byUpdatedAt);
|
|
2499
|
+
},
|
|
2500
|
+
get: read,
|
|
2501
|
+
async create(input) {
|
|
2502
|
+
const sketchpad = newSketchpad(input, now());
|
|
2503
|
+
await write(sketchpad);
|
|
2504
|
+
return sketchpad;
|
|
2505
|
+
},
|
|
2506
|
+
update(id, change) {
|
|
2507
|
+
return queued(id, async () => {
|
|
2508
|
+
const result = applySketchpadChange(await read(id), change, now());
|
|
2509
|
+
if (result.status === "updated") {
|
|
2510
|
+
await write(result.sketchpad);
|
|
2511
|
+
}
|
|
2512
|
+
return result;
|
|
2513
|
+
});
|
|
2514
|
+
}
|
|
2515
|
+
};
|
|
2516
|
+
}
|
|
2517
|
+
|
|
2436
2518
|
/** Serializes a schema, or gives up quietly — serialization errors are reported elsewhere. */
|
|
2437
2519
|
function serializeSchemaSafely(schema) {
|
|
2438
2520
|
try {
|
|
@@ -2458,8 +2540,12 @@ class ValOpsFS extends ValOps {
|
|
|
2458
2540
|
this.rootDir = rootDir;
|
|
2459
2541
|
this.host = new FSOpsHost();
|
|
2460
2542
|
this.jsonEntryFilesFingerprint = new JsonEntryFilesFingerprint(rootDir);
|
|
2543
|
+
this.sketchpads = createFsSketchpadStore(rootDir);
|
|
2461
2544
|
}
|
|
2462
2545
|
|
|
2546
|
+
/** In `.val/sketchpads`. See `sketchpads/fsSketchpadStore.ts`. */
|
|
2547
|
+
sketchpads;
|
|
2548
|
+
|
|
2463
2549
|
/**
|
|
2464
2550
|
* Change detection for `.jsonValues()` entry files, which no sha can see (their
|
|
2465
2551
|
* content lives behind a thunk that `JSON.stringify` drops).
|
|
@@ -5081,6 +5167,124 @@ function movesAtMerge(inputs, schemas) {
|
|
|
5081
5167
|
};
|
|
5082
5168
|
}
|
|
5083
5169
|
|
|
5170
|
+
/**
|
|
5171
|
+
* Sketchpads in `http` mode: the content service keeps them, per project, at
|
|
5172
|
+
* `/v1/{project}/sketchpads` (valbuild/home). This only carries requests
|
|
5173
|
+
* there and reads the answers; the version check is the service's, done in
|
|
5174
|
+
* one statement.
|
|
5175
|
+
*/
|
|
5176
|
+
function createHttpSketchpadStore(options) {
|
|
5177
|
+
const request = async (path, init) => fetch(`${options.url}${path}`, {
|
|
5178
|
+
method: init.method,
|
|
5179
|
+
headers: {
|
|
5180
|
+
...options.headers,
|
|
5181
|
+
// WHO, as for a proposal or a commit: the key names the project.
|
|
5182
|
+
...(init.by ? {
|
|
5183
|
+
"x-val-profile-id": init.by
|
|
5184
|
+
} : {}),
|
|
5185
|
+
...(init.body !== undefined ? {
|
|
5186
|
+
"Content-Type": "application/json"
|
|
5187
|
+
} : {})
|
|
5188
|
+
},
|
|
5189
|
+
...(init.body !== undefined ? {
|
|
5190
|
+
body: JSON.stringify(init.body)
|
|
5191
|
+
} : {})
|
|
5192
|
+
});
|
|
5193
|
+
const failed = async (res, doing) => new Error(`Val Build could not ${doing} (HTTP ${res.status}): ${await res.text().catch(() => "")}`);
|
|
5194
|
+
return {
|
|
5195
|
+
async list(filter) {
|
|
5196
|
+
const query = new URLSearchParams({
|
|
5197
|
+
archived: filter.archived
|
|
5198
|
+
});
|
|
5199
|
+
if (filter.page !== undefined) {
|
|
5200
|
+
query.set("page", filter.page);
|
|
5201
|
+
}
|
|
5202
|
+
const res = await request(`?${query}`, {
|
|
5203
|
+
method: "GET"
|
|
5204
|
+
});
|
|
5205
|
+
if (!res.ok) {
|
|
5206
|
+
throw await failed(res, "list the sketchpads");
|
|
5207
|
+
}
|
|
5208
|
+
return z.object({
|
|
5209
|
+
sketchpads: z.array(SketchpadSummary)
|
|
5210
|
+
}).parse(await res.json()).sketchpads;
|
|
5211
|
+
},
|
|
5212
|
+
async get(id) {
|
|
5213
|
+
if (!isSketchpadId(id)) {
|
|
5214
|
+
return null;
|
|
5215
|
+
}
|
|
5216
|
+
const res = await request(`/${encodeURIComponent(id)}`, {
|
|
5217
|
+
method: "GET"
|
|
5218
|
+
});
|
|
5219
|
+
if (res.status === 404) {
|
|
5220
|
+
return null;
|
|
5221
|
+
}
|
|
5222
|
+
if (!res.ok) {
|
|
5223
|
+
throw await failed(res, "read the sketchpad");
|
|
5224
|
+
}
|
|
5225
|
+
return z.object({
|
|
5226
|
+
sketchpad: Sketchpad
|
|
5227
|
+
}).parse(await res.json()).sketchpad;
|
|
5228
|
+
},
|
|
5229
|
+
async create(input) {
|
|
5230
|
+
const res = await request("", {
|
|
5231
|
+
method: "POST",
|
|
5232
|
+
body: {
|
|
5233
|
+
text: input.text,
|
|
5234
|
+
title: input.title,
|
|
5235
|
+
page: input.page
|
|
5236
|
+
},
|
|
5237
|
+
by: input.by
|
|
5238
|
+
});
|
|
5239
|
+
if (!res.ok) {
|
|
5240
|
+
throw await failed(res, "make the sketchpad");
|
|
5241
|
+
}
|
|
5242
|
+
return z.object({
|
|
5243
|
+
sketchpad: Sketchpad
|
|
5244
|
+
}).parse(await res.json()).sketchpad;
|
|
5245
|
+
},
|
|
5246
|
+
async update(id, change) {
|
|
5247
|
+
if (!isSketchpadId(id)) {
|
|
5248
|
+
return {
|
|
5249
|
+
status: "not-found"
|
|
5250
|
+
};
|
|
5251
|
+
}
|
|
5252
|
+
const {
|
|
5253
|
+
by,
|
|
5254
|
+
...body
|
|
5255
|
+
} = change;
|
|
5256
|
+
const res = await request(`/${encodeURIComponent(id)}`, {
|
|
5257
|
+
method: "PATCH",
|
|
5258
|
+
body,
|
|
5259
|
+
by
|
|
5260
|
+
});
|
|
5261
|
+
if (res.status === 404) {
|
|
5262
|
+
return {
|
|
5263
|
+
status: "not-found"
|
|
5264
|
+
};
|
|
5265
|
+
}
|
|
5266
|
+
if (res.status === 409) {
|
|
5267
|
+
const current = z.object({
|
|
5268
|
+
sketchpad: Sketchpad
|
|
5269
|
+
}).parse(await res.json()).sketchpad;
|
|
5270
|
+
return {
|
|
5271
|
+
status: "conflict",
|
|
5272
|
+
sketchpad: current
|
|
5273
|
+
};
|
|
5274
|
+
}
|
|
5275
|
+
if (!res.ok) {
|
|
5276
|
+
throw await failed(res, "save the sketchpad");
|
|
5277
|
+
}
|
|
5278
|
+
return {
|
|
5279
|
+
status: "updated",
|
|
5280
|
+
sketchpad: z.object({
|
|
5281
|
+
sketchpad: Sketchpad
|
|
5282
|
+
}).parse(await res.json()).sketchpad
|
|
5283
|
+
};
|
|
5284
|
+
}
|
|
5285
|
+
};
|
|
5286
|
+
}
|
|
5287
|
+
|
|
5084
5288
|
const textEncoder$2 = new TextEncoder();
|
|
5085
5289
|
|
|
5086
5290
|
/** The body of the content API's 403 for a write the project's plan refuses. */
|
|
@@ -5382,6 +5586,8 @@ class ValOpsHttp extends ValOps {
|
|
|
5382
5586
|
/** Val's content service owns the store. See {@link ValOps.patchesAreLocal}. */
|
|
5383
5587
|
patchesAreLocal = false;
|
|
5384
5588
|
kind = "http";
|
|
5589
|
+
/** The content service's. See `sketchpads/httpSketchpadStore.ts`. */
|
|
5590
|
+
sketchpads;
|
|
5385
5591
|
/** See {@link ValOps.requiresAuth}. */
|
|
5386
5592
|
requiresAuth = true;
|
|
5387
5593
|
/**
|
|
@@ -5509,6 +5715,10 @@ class ValOpsHttp extends ValOps {
|
|
|
5509
5715
|
Authorization: `Bearer ${auth.apiKey}`
|
|
5510
5716
|
};
|
|
5511
5717
|
this.root = (options === null || options === void 0 ? void 0 : options.root) ?? "";
|
|
5718
|
+
this.sketchpads = createHttpSketchpadStore({
|
|
5719
|
+
url: `${contentUrl}/v1/${project}/sketchpads`,
|
|
5720
|
+
headers: this.authHeaders
|
|
5721
|
+
});
|
|
5512
5722
|
this.proposal = (options === null || options === void 0 ? void 0 : options.proposal) ?? null;
|
|
5513
5723
|
this.contentVersion = this.proposal === null ? (options === null || options === void 0 ? void 0 : options.contentVersion) ?? null : null;
|
|
5514
5724
|
/*
|
|
@@ -8369,6 +8579,16 @@ async function initHandlerOptions(route, opts, config) {
|
|
|
8369
8579
|
});
|
|
8370
8580
|
if (isProxyMode) {
|
|
8371
8581
|
var _config$files, _opts$versions, _opts$versions2;
|
|
8582
|
+
/*
|
|
8583
|
+
* Where a self-hosted site's analytics beacons are counted. Only http mode
|
|
8584
|
+
* forwards them -- it is the mode with the project's api key -- so only
|
|
8585
|
+
* it resolves this, and only here is it checked for a plain-http host:
|
|
8586
|
+
* the api key goes with every beacon.
|
|
8587
|
+
*/
|
|
8588
|
+
const valAnalyticsIngestUrl = opts.valAnalyticsIngestUrl || process.env.VAL_ANALYTICS_INGEST_URL || DEFAULT_ANALYTICS_INGEST_URL;
|
|
8589
|
+
warnIfInsecureUrls({
|
|
8590
|
+
valAnalyticsIngestUrl
|
|
8591
|
+
});
|
|
8372
8592
|
/*
|
|
8373
8593
|
* Why this app is in http mode, in the message that says what is missing.
|
|
8374
8594
|
*
|
|
@@ -8489,6 +8709,7 @@ async function initHandlerOptions(route, opts, config) {
|
|
|
8489
8709
|
valDisableRedirectUrl,
|
|
8490
8710
|
valContentUrl,
|
|
8491
8711
|
valBuildUrl,
|
|
8712
|
+
valAnalyticsIngestUrl,
|
|
8492
8713
|
config
|
|
8493
8714
|
};
|
|
8494
8715
|
} else {
|
|
@@ -8603,10 +8824,11 @@ function createValOps(valModules, options) {
|
|
|
8603
8824
|
* so a single shared sentence would overstate one and understate the other.
|
|
8604
8825
|
*/
|
|
8605
8826
|
|
|
8606
|
-
const CREDENTIAL_BEARING_URLS = ["valBuildUrl", "valContentUrl"];
|
|
8827
|
+
const CREDENTIAL_BEARING_URLS = ["valBuildUrl", "valContentUrl", "valAnalyticsIngestUrl"];
|
|
8607
8828
|
const WHAT_IS_AT_RISK = {
|
|
8608
8829
|
valBuildUrl: "Val's api key is sent to this host, and the token it returns is what this server signs into the session cookie, " + "so both can be read - and the token replaced - by anyone on the network path.",
|
|
8609
|
-
valContentUrl: "Val's api key, or the caller's personal access token, is sent to this host, " + "so it can be read by anyone on the network path."
|
|
8830
|
+
valContentUrl: "Val's api key, or the caller's personal access token, is sent to this host, " + "so it can be read by anyone on the network path.",
|
|
8831
|
+
valAnalyticsIngestUrl: "Val's api key is sent to this host with every analytics beacon, " + "so it can be read by anyone on the network path."
|
|
8610
8832
|
};
|
|
8611
8833
|
|
|
8612
8834
|
// NOTE: `URL.hostname` keeps the brackets on an IPv6 literal, so this is
|
|
@@ -8634,9 +8856,10 @@ function forLog(parsed) {
|
|
|
8634
8856
|
* Returns a warning if `url` would send credentials somewhere they can be read
|
|
8635
8857
|
* off the wire, or null if it is fine.
|
|
8636
8858
|
*
|
|
8637
|
-
*
|
|
8638
|
-
* `VAL_BUILD_URL`, `opts.valContentUrl` / `VAL_CONTENT_URL
|
|
8639
|
-
*
|
|
8859
|
+
* Each URL defaults to https, but each is overridable - `opts.valBuildUrl` /
|
|
8860
|
+
* `VAL_BUILD_URL`, `opts.valContentUrl` / `VAL_CONTENT_URL`,
|
|
8861
|
+
* `opts.valAnalyticsIngestUrl` / `VAL_ANALYTICS_INGEST_URL` - and no override
|
|
8862
|
+
* was scheme-checked before this. Point one at a plain http host and the
|
|
8640
8863
|
* api key goes out in clear text, and whatever comes back is whatever the
|
|
8641
8864
|
* network says: for `valBuildUrl` that includes the app token this server
|
|
8642
8865
|
* re-signs into the session cookie.
|
|
@@ -8668,7 +8891,11 @@ function insecureUrlWarning(name, url) {
|
|
|
8668
8891
|
}
|
|
8669
8892
|
function warnIfInsecureUrls(urls) {
|
|
8670
8893
|
for (const name of CREDENTIAL_BEARING_URLS) {
|
|
8671
|
-
const
|
|
8894
|
+
const url = urls[name];
|
|
8895
|
+
if (url === undefined) {
|
|
8896
|
+
continue;
|
|
8897
|
+
}
|
|
8898
|
+
const warning = insecureUrlWarning(name, url);
|
|
8672
8899
|
if (warning) {
|
|
8673
8900
|
Internal.log.warn(warning);
|
|
8674
8901
|
}
|
package/package.json
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
],
|
|
28
28
|
"exports": true
|
|
29
29
|
},
|
|
30
|
-
"version": "0.150.
|
|
30
|
+
"version": "0.150.17",
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@prettier/sync": "^0.6.1",
|
|
33
33
|
"@types/jest": "^30.0.0",
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"zod": "^4.4.3",
|
|
43
43
|
"zod-validation-error": "^5.0.0",
|
|
44
44
|
"@valbuild/core": "0.150.3",
|
|
45
|
-
"@valbuild/shared": "0.150.
|
|
46
|
-
"@valbuild/ui": "0.150.
|
|
45
|
+
"@valbuild/shared": "0.150.17",
|
|
46
|
+
"@valbuild/ui": "0.150.16"
|
|
47
47
|
},
|
|
48
48
|
"engines": {
|
|
49
49
|
"node": "^20.19.0 || >=22"
|