@popcorn245/cornfield 0.32.0 → 0.33.1
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/core/config.js +19 -2
- package/core/strings.js +1 -0
- package/explorer/explorer.css +2 -1
- package/explorer/file-url.js +40 -0
- package/explorer/index.html +1 -0
- package/explorer/main.js +1 -0
- package/explorer/panels.js +13 -9
- package/explorer/proposal.js +1 -0
- package/explorer/state.js +2 -0
- package/package.json +1 -1
- package/server/forge.js +2 -1
- package/server/server.js +1 -1
package/core/config.js
CHANGED
|
@@ -190,6 +190,20 @@ const isObject = (v) => v !== null && typeof v === 'object' && !Array.isArray(v)
|
|
|
190
190
|
const isText = (v) => typeof v === 'string' && v.trim() !== '';
|
|
191
191
|
/** A path inside the repo: relative, forward slashes, no `..` segment */
|
|
192
192
|
const inRepo = (p) => isText(p) && !path.isAbsolute(p) && !p.split(/[\\/]/).includes('..');
|
|
193
|
+
/** A forge's origin: http(s), a host name or a bracketed IPv6 address, and a port; no user name, path, query, fragment or backslash */
|
|
194
|
+
const FORGE_ORIGIN = /^https?:\/\/([A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?(?:\.[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?)*|\[[0-9A-Fa-f:.]+\])(?::\d{1,5})?\/?$/;
|
|
195
|
+
/**
|
|
196
|
+
* Whether `url` is a forge's origin, and one the URL parser keeps as written: a host it would rewrite to another
|
|
197
|
+
* (`https://2130706433` and `https://0x7f.1` are 127.0.0.1), an IPv6 address it cannot read, or a port past 65535 is not one
|
|
198
|
+
*/
|
|
199
|
+
const isForgeOrigin = (url) => {
|
|
200
|
+
const m = typeof url === 'string' ? FORGE_ORIGIN.exec(url) : null;
|
|
201
|
+
if (!m) return false;
|
|
202
|
+
try {
|
|
203
|
+
const u = new URL(url);
|
|
204
|
+
return m[1].startsWith('[') || u.hostname === m[1].toLowerCase();
|
|
205
|
+
} catch { return false; }
|
|
206
|
+
};
|
|
193
207
|
|
|
194
208
|
/**
|
|
195
209
|
* What is wrong with a config object (as the file exports it, before defaults).
|
|
@@ -238,8 +252,11 @@ export function configProblems(c) {
|
|
|
238
252
|
if (!isObject(c.forge)) out.push('"forge" is { type, url, repo }.');
|
|
239
253
|
else {
|
|
240
254
|
if (!FORGE_TYPES.includes(c.forge.type)) out.push(`forge.type is one of ${FORGE_TYPES.join(', ')}.`);
|
|
241
|
-
if (c.forge.url !== undefined &&
|
|
242
|
-
|
|
255
|
+
if (c.forge.url !== undefined && !isForgeOrigin(c.forge.url)) out.push('forge.url is the forge\'s origin, like https://github.com.');
|
|
256
|
+
// GitHub and GitHub Enterprise only speak https; a token over http would travel in the clear
|
|
257
|
+
else if (c.forge.url !== undefined && c.forge.type === 'github' && !/^https:/i.test(String(c.forge.url)) && !/^http:\/\/(?:localhost|127\.0\.0\.1|\[::1\])(?::\d+)?\/?$/i.test(String(c.forge.url))) out.push('forge.url for GitHub is https (http only for localhost): the token would otherwise travel in the clear.');
|
|
258
|
+
const repoParts = String(c.forge.repo || '').split('/');
|
|
259
|
+
if (!/^[\w.-]+\/[\w.-]+$/.test(String(c.forge.repo || '')) || repoParts.some((p) => /^\.+$/.test(p))) out.push('forge.repo is "owner/name".');
|
|
243
260
|
if (c.forge.mergeMethod !== undefined && !MERGE_METHODS.includes(c.forge.mergeMethod)) out.push(`forge.mergeMethod is one of ${MERGE_METHODS.join(', ')}.`);
|
|
244
261
|
if (c.forge.baseBranch !== undefined && !(typeof c.forge.baseBranch === 'string' && /^[A-Za-z0-9][A-Za-z0-9._-]*(?:\/[A-Za-z0-9][A-Za-z0-9._-]*)*$/.test(c.forge.baseBranch) && !c.forge.baseBranch.includes('..'))) out.push('forge.baseBranch is the branch spec pull requests go into, like "main".');
|
|
245
262
|
}
|
package/core/strings.js
CHANGED
package/explorer/explorer.css
CHANGED
|
@@ -966,6 +966,7 @@ a.hx-forge-row:hover, button.hx-forge-row:hover { background: var(--corn-surface
|
|
|
966
966
|
/* ---- the node panel (panels.js, #138): type · name · one line · facts · mockups · threads · the diff · the actions ------------ */
|
|
967
967
|
.hx-drawer-id { flex: 1; min-width: 0; }
|
|
968
968
|
.hx-kicker { display: flex; flex-wrap: wrap; align-items: center; margin: 0 0 var(--corn-space-2); font-size: var(--corn-text-sm); color: var(--corn-text-3); }
|
|
969
|
+
#drawer-host { white-space: pre; } /* the kicker is a flex row, which drops a leading space: keep " · host" */
|
|
969
970
|
.hx-diffpill { margin-left: var(--corn-space-3); padding: 0 var(--corn-space-3); border-radius: var(--corn-radius-pill); border: var(--corn-border) dashed var(--corn-added); color: var(--corn-added-text); font-size: var(--corn-text-xs); }
|
|
970
971
|
.hx-drawer-id .hx-drawer-title { font-size: var(--corn-text-xl); font-weight: 650; letter-spacing: -0.01em; line-height: 1.25; }
|
|
971
972
|
.hx-drawer-id .hx-drawer-title.hx-mono { font-family: var(--corn-mono); }
|
|
@@ -1012,7 +1013,7 @@ a.hx-forge-row:hover, button.hx-forge-row:hover { background: var(--corn-surface
|
|
|
1012
1013
|
}
|
|
1013
1014
|
.hx-drawer .hx-whatif-drawer { font-size: var(--corn-text-md); color: var(--corn-text-2); }
|
|
1014
1015
|
.hx-drawer .hx-whatif-drawer select { max-width: 100%; }
|
|
1015
|
-
.hx-drawer-foot .hx-btn--quiet { border-color: transparent; background: none; }
|
|
1016
|
+
.hx-drawer-foot .hx-btn--quiet { border-color: transparent; background: none; text-decoration: none; }
|
|
1016
1017
|
.hx-more { display: contents; }
|
|
1017
1018
|
.hx-more[hidden] { display: none; }
|
|
1018
1019
|
.hx-more-btn { display: block; margin-top: var(--corn-space-1); min-height: 0; padding: 0; font-size: var(--corn-text-sm); }
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/file-url
|
|
3
|
+
*
|
|
4
|
+
* `fileUrl(forge, path, ref)`: where a node's file is on the forge's web site, or null. `forge` is the client config's
|
|
5
|
+
* `{ type, url, repo }` (server/server.js); `ref` a branch name, or `HEAD` (the repo's default branch, on GitHub and on
|
|
6
|
+
* Forgejo/Gitea 1.21 and later) when none is given. Only GitHub and Forgejo/Gitea exist (server/forge-*.js).
|
|
7
|
+
* The path must be repo-relative: no `..`, no absolute path, no scheme, no backslash, no control character. The URL is
|
|
8
|
+
* built with `URL`, each segment encoded, and only `https:` is allowed, with no user name and no backslash in `forge.url`
|
|
9
|
+
* (`https://github.com@evil.test` is evil.test).
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
// The page of a file at a branch, per forge
|
|
13
|
+
const SHAPE = { github: 'blob', forgejo: 'src/branch' };
|
|
14
|
+
|
|
15
|
+
/** The segments of a repo-relative path (or branch name), or null when it is not one */
|
|
16
|
+
function segments(path) {
|
|
17
|
+
if (typeof path !== 'string' || !path || /[\\\u0000-\u001f\u007f]/.test(path) || path.startsWith('/') || /^[A-Za-z][A-Za-z0-9+.-]*:/.test(path)) return null;
|
|
18
|
+
const parts = path.split('/');
|
|
19
|
+
return parts.every((s) => s && s !== '.' && s !== '..') ? parts : null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** @returns {string | null} */
|
|
23
|
+
export function fileUrl(forge, path, ref) {
|
|
24
|
+
const kind = forge && Object.hasOwn(SHAPE, forge.type) && SHAPE[forge.type];
|
|
25
|
+
const file = segments(path);
|
|
26
|
+
const branch = segments(ref || 'HEAD');
|
|
27
|
+
const repo = segments(forge && forge.repo);
|
|
28
|
+
if (!kind || !file || !branch || !repo || repo.length !== 2) return null;
|
|
29
|
+
try {
|
|
30
|
+
const base = new URL(forge.url);
|
|
31
|
+
if (base.protocol !== 'https:' || base.username || base.password || String(forge.url).includes('\\')) return null;
|
|
32
|
+
const enc = (s) => s.map(encodeURIComponent).join('/');
|
|
33
|
+
base.pathname = `${base.pathname.replace(/\/+$/, '')}/${enc(repo)}/${kind}/${enc(branch)}/${enc(file)}`;
|
|
34
|
+
base.search = '';
|
|
35
|
+
base.hash = '';
|
|
36
|
+
return base.href;
|
|
37
|
+
} catch {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
}
|
package/explorer/index.html
CHANGED
|
@@ -342,6 +342,7 @@
|
|
|
342
342
|
</div>
|
|
343
343
|
|
|
344
344
|
<div class="hx-drawer-foot">
|
|
345
|
+
<a id="drawer-file-btn" class="hx-open" href="#" target="_blank" rel="noreferrer" hidden>Open file ↗</a>
|
|
345
346
|
<a id="drawer-open-btn" class="hx-open" href="#" target="_blank" rel="noreferrer" hidden>Open route ↗</a>
|
|
346
347
|
<button type="button" id="drawer-run-btn" class="hx-btn hx-foot-btn" data-action="start-run" data-corn-string="startRun" hidden>Start a run</button>
|
|
347
348
|
<button type="button" class="hx-btn hx-btn--quiet hx-foot-btn" data-action="copy-spec" data-corn-string="copySpec">Copy Spec</button>
|
package/explorer/main.js
CHANGED
|
@@ -215,6 +215,7 @@ loadTopology().then(async (ok) => {
|
|
|
215
215
|
if (!ok) return;
|
|
216
216
|
// The sources the repo's cornfield.config.js names (plugins.js): a live layer, a house, devices, a checker; each optional
|
|
217
217
|
const config = await configReady;
|
|
218
|
+
state.forge = config.forge || null;
|
|
218
219
|
const { liveSource, floorRenderer, checker } = await loadSources(config);
|
|
219
220
|
const forgeOn = initForgePanel(config); // issues and PRs: only when the config names a forge (forge-panel.js)
|
|
220
221
|
initReviewTokens(config); // review tokens for the review API: only for somebody signed in (review-tokens.js)
|
package/explorer/panels.js
CHANGED
|
@@ -16,6 +16,7 @@ import { collapseSheet } from './sheets.js';
|
|
|
16
16
|
import { liveSection, hydrateLivePhotos } from './live.js';
|
|
17
17
|
import { cloudPanelHtml } from './cloud-model.js';
|
|
18
18
|
import { t } from './strings.js';
|
|
19
|
+
import { fileUrl } from './file-url.js';
|
|
19
20
|
import { capped, toggleCapped } from './capped.js';
|
|
20
21
|
import { canStartAgent, openProposalStart } from './forge-panel.js';
|
|
21
22
|
|
|
@@ -253,15 +254,18 @@ export async function selectNode(node) {
|
|
|
253
254
|
if (state.threadIndex) state.threadIndex.ensure();
|
|
254
255
|
hydrateLivePhotos($('drawer-live'));
|
|
255
256
|
|
|
256
|
-
// The actions: Open (
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
257
|
+
// The actions: Open file (the node's file on the forge) is the primary one; with an address too, Open route is the quiet one.
|
|
258
|
+
// The proposal's head branch is not known here (the proposals list does not carry it): the file is at the default branch.
|
|
259
|
+
const fileBtn = $('drawer-file-btn');
|
|
260
|
+
const file = node.file && state.forge ? fileUrl(state.forge, node.file, state.forge.baseBranch) : null;
|
|
261
|
+
fileBtn.hidden = !file;
|
|
262
|
+
if (file) fileBtn.href = file; else fileBtn.removeAttribute('href');
|
|
263
|
+
const route = !!(node.url && /^https?:\/\//.test(node.url));
|
|
264
|
+
if (route) openBtn.href = node.url; else openBtn.removeAttribute('href');
|
|
265
|
+
openBtn.hidden = !route;
|
|
266
|
+
openBtn.className = file ? 'hx-btn hx-btn--quiet hx-foot-btn' : 'hx-open';
|
|
267
|
+
openBtn.textContent = `${t('openRoute')} ↗`;
|
|
268
|
+
fileBtn.textContent = `${t('openFile')} ↗`;
|
|
265
269
|
const run = $('drawer-run-btn');
|
|
266
270
|
run.hidden = !(state.proposalSlug && canStartAgent());
|
|
267
271
|
|
package/explorer/proposal.js
CHANGED
|
@@ -493,6 +493,7 @@ export function showEdgePanel(edge) {
|
|
|
493
493
|
<div class="hx-fact"><div class="hx-fact-k">To</div><div class="hx-fact-v"><button type="button" class="hx-linkbtn" data-action="select-node" data-id="${escHtml(edge.to)}">${escHtml(nameOf(edge.to))}</button></div></div>
|
|
494
494
|
</div>${proposalPanelHtml(edge)}`;
|
|
495
495
|
$('drawer-open-btn').hidden = true;
|
|
496
|
+
$('drawer-file-btn').hidden = true;
|
|
496
497
|
$('drawer-run-btn').hidden = true;
|
|
497
498
|
$('spec-drawer').classList.add('drawer-open');
|
|
498
499
|
$('drawer-backdrop').hidden = false;
|
package/explorer/state.js
CHANGED
|
@@ -36,6 +36,8 @@ export const state = {
|
|
|
36
36
|
|
|
37
37
|
camera: { x: 0, y: 0, zoom: 1 },
|
|
38
38
|
selectedNode: null,
|
|
39
|
+
/** The config's `forge` (`{ type, url, repo, baseBranch? }`), or null: where a node's file is opened (file-url.js) */
|
|
40
|
+
forge: null,
|
|
39
41
|
searchQuery: '',
|
|
40
42
|
|
|
41
43
|
isFreeform: false,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@popcorn245/cornfield",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.33.1",
|
|
4
4
|
"description": "A self-hostable dev dashboard with the topology map at its centre: proposals on the map, scenarios, outages and what-if edits, for any repo.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "popcorn245 (https://github.com/popcorn245)",
|
package/server/forge.js
CHANGED
|
@@ -141,7 +141,8 @@ const MAX_LABELS = 5;
|
|
|
141
141
|
const ISO_TIME = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:\d{2})$/;
|
|
142
142
|
const MERGE_METHODS = ['merge', 'squash', 'rebase'];
|
|
143
143
|
const STATES = ['open', 'closed', 'all'];
|
|
144
|
-
|
|
144
|
+
/** owner/name, neither made only of dots (`..` would walk out of `repos/` in the API's path) */
|
|
145
|
+
const REPO = /^(?!\.+\/)[\w.-]+\/(?!\.+$)[\w.-]+$/;
|
|
145
146
|
/** A tag name a release draft may carry: no spaces, no `..`, no leading dash, at most 100 characters */
|
|
146
147
|
const TAG_NAME = /^[\w][\w./+-]{0,99}$/;
|
|
147
148
|
/** The most a release's body may hold (GitHub's own limit) */
|
package/server/server.js
CHANGED
|
@@ -269,7 +269,7 @@ export function clientConfig(config, signIn = false) {
|
|
|
269
269
|
brand: clientBrand(config.brand, PKG.homepage),
|
|
270
270
|
// Only the labels the config overrides, as text (core/strings.js); the defaults are in the browser
|
|
271
271
|
strings: clientStrings(config.strings),
|
|
272
|
-
forge: config.forge ? { type: config.forge.type, url: config.forge.url || (config.forge.type === 'github' ? 'https://github.com' : null), repo: config.forge.repo, mergeMethod: config.forge.mergeMethod || 'merge', ...(config.approveLands ? { approveLands: true } : {}) } : null,
|
|
272
|
+
forge: config.forge ? { type: config.forge.type, url: config.forge.url || (config.forge.type === 'github' ? 'https://github.com' : null), repo: config.forge.repo, mergeMethod: config.forge.mergeMethod || 'merge', ...(config.forge.baseBranch ? { baseBranch: config.forge.baseBranch } : {}), ...(config.approveLands ? { approveLands: true } : {}) } : null,
|
|
273
273
|
// Threads (docs/threads.md): the idea label, or false when `threads: false` turns the Threads tab off
|
|
274
274
|
threads: config.threads === false ? false : { label: ideaLabel(config) },
|
|
275
275
|
sources: browserSources(config),
|