@mistriwork/engine 1.0.0-rc.14 → 1.0.0-rc.16
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/dist/adapters/cache/cacheStore.d.ts +1 -1
- package/dist/adapters/cache/cacheStore.js +1 -1
- package/dist/server/cli/startup.js +7 -2
- package/dist/server/cli/usage.d.ts +2 -0
- package/dist/server/cli/usage.js +12 -1
- package/dist/server/clientHttp.js +20 -3
- package/dist/server/config/profile.d.ts +10 -3
- package/dist/server/config/profile.js +28 -4
- package/dist/server/connections.js +1 -1
- package/dist/server/demo.js +3 -3
- package/dist/server/http/baselineHeaders.d.ts +13 -3
- package/dist/server/http/baselineHeaders.js +6 -0
- package/dist/server/http/frontDoor.d.ts +41 -0
- package/dist/server/http/frontDoor.js +36 -0
- package/dist/server/http/rateLimit.d.ts +2 -2
- package/dist/server/http/rateLimit.js +16 -2
- package/dist/server/http/recordCompose.d.ts +3 -0
- package/dist/server/http/recordCompose.js +1 -0
- package/dist/server/http/serverCore.d.ts +2 -2
- package/dist/server/http/serverCore.js +16 -32
- package/dist/server/migrate/cli.js +8 -1
- package/dist/server/migrate/desired.js +2 -2
- package/dist/server/migrate/target.d.ts +8 -0
- package/dist/server/migrate/target.js +15 -0
- package/dist/server/seed/seed.js +46 -11
- package/dist/server/startupWarnings.js +1 -1
- package/dist/shared/appCards.d.ts +4 -0
- package/dist/shared/appCards.js +5 -0
- package/dist/shared/breakdown.js +8 -2
- package/dist/shared/computed.d.ts +16 -2
- package/dist/shared/computed.js +23 -4
- package/dist/shared/computedValue.js +23 -0
- package/dist/shared/iconWeights.js +1 -0
- package/dist/shared/listPresentations.d.ts +9 -2
- package/dist/shared/listPresentations.js +2 -0
- package/dist/shared/listQuestion.d.ts +9 -0
- package/dist/shared/listQuestion.js +18 -0
- package/dist/shared/mentionLookup.js +3 -1
- package/dist/shared/page.d.ts +8 -1
- package/dist/shared/page.js +151 -7
- package/dist/shared/pageAnatomy.js +2 -0
- package/dist/shared/pageConfig.d.ts +1 -1
- package/dist/shared/pageConfig.js +106 -19
- package/dist/shared/pageModel.d.ts +62 -5
- package/dist/shared/pagePaths.js +4 -1
- package/dist/shared/pagePlans.d.ts +4 -2
- package/dist/shared/pagePlans.js +6 -4
- package/dist/shared/recordLabel.d.ts +12 -3
- package/dist/shared/recordLabel.js +39 -18
- package/dist/shared/recordReads.d.ts +6 -30
- package/dist/shared/recordReads.js +13 -1
- package/dist/shared/rollups.d.ts +4 -4
- package/dist/shared/rollups.js +1 -1
- package/dist/shared/schema.d.ts +7 -0
- package/dist/shared/schema.js +17 -0
- package/dist/shared/servedApp.d.ts +5 -1
- package/dist/shared/viewLabels.js +22 -17
- package/package.json +3 -2
- package/schema/model.d.ts +14 -5
- package/schema/theme.d.ts +1 -1
|
@@ -71,5 +71,5 @@ export declare class ValkeyCacheStore implements CacheStore {
|
|
|
71
71
|
close(): Promise<void>;
|
|
72
72
|
private unavailable;
|
|
73
73
|
}
|
|
74
|
-
/** The same store under a key prefix: `
|
|
74
|
+
/** The same store under a key prefix: `mistri:<app>:http:<connection>:`, say. */
|
|
75
75
|
export declare function scopedCache(store: CacheStore, prefix: string): CacheStore;
|
|
@@ -147,7 +147,7 @@ export class ValkeyCacheStore {
|
|
|
147
147
|
this.onUnavailable(error instanceof CacheUnavailable || error instanceof RespReplyError ? error.message : 'the cache failed.');
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
|
-
/** The same store under a key prefix: `
|
|
150
|
+
/** The same store under a key prefix: `mistri:<app>:http:<connection>:`, say. */
|
|
151
151
|
export function scopedCache(store, prefix) {
|
|
152
152
|
return {
|
|
153
153
|
kind: store.kind,
|
|
@@ -10,7 +10,7 @@ import { configureServerSettings } from '../../adapters/serverSettings.js';
|
|
|
10
10
|
import { configurePostgresPools } from '../../adapters/postgresPool.js';
|
|
11
11
|
import { configureLockTimeout, configureWriterPool } from '../../adapters/writeLanes.js';
|
|
12
12
|
import { postgresPoolFlags, shutdownTimings } from './args.js';
|
|
13
|
-
import { didYouMean, packageVersion } from './usage.js';
|
|
13
|
+
import { commandsTaking, didYouMean, packageVersion } from './usage.js';
|
|
14
14
|
import { envName } from '../product.js';
|
|
15
15
|
/**
|
|
16
16
|
* `--help`, `--version`, a retired spelling, an unknown flag, a command one slip away: answered before anything
|
|
@@ -39,7 +39,12 @@ export async function answeredFirst(opts, product) {
|
|
|
39
39
|
line that said what was wrong. */
|
|
40
40
|
if (opts.unknown) {
|
|
41
41
|
const flag = opts.unknown.split(/[ =]/)[0];
|
|
42
|
-
|
|
42
|
+
/* A flag the usage does spell, typed where it does not apply: say where it does, not that it is unknown. A flag
|
|
43
|
+
given twice ("--jobs (may be supplied only once)") applies here; it is said as it is. */
|
|
44
|
+
const homes = product.flagWords.includes(flag) && !opts.unknown.includes('(') ? commandsTaking(product.usage, bin, flag) : [];
|
|
45
|
+
console.error(homes.length
|
|
46
|
+
? `${bin}: ${flag} is an option of ${homes.map((home) => `${bin} ${home}`).join(' and ')}, not of a start: name the command first (${bin} ${homes[0]} … ${flag}). ${bin} --help lists the options.`
|
|
47
|
+
: `${bin}: unknown option "${opts.unknown}".${opts.unknown === flag ? await didYouMean(flag, product.flagWords) : ''} ${bin} --help lists the options.`);
|
|
43
48
|
process.exit(1);
|
|
44
49
|
}
|
|
45
50
|
/* A word that is no file and is one slip from a command (`tablewalk chek`) was opened as a SQLite file of that
|
|
@@ -14,3 +14,5 @@ export declare function didYouMean(said: string, among: readonly string[]): Prom
|
|
|
14
14
|
* else the package's. Every package of the workspace carries the one version.
|
|
15
15
|
*/
|
|
16
16
|
export declare function packageVersion(): Promise<string>;
|
|
17
|
+
/** The commands whose usage spells `flag` (`mistri schema --brief`), for a flag typed where no command takes it. */
|
|
18
|
+
export declare function commandsTaking(usage: string, bin: string, flag: string): string[];
|
package/dist/server/cli/usage.js
CHANGED
|
@@ -15,7 +15,8 @@ export function flagWordsOf(usage) {
|
|
|
15
15
|
/** What was probably meant, said the way a person would type it, or nothing when nothing is near. */
|
|
16
16
|
export async function didYouMean(said, among) {
|
|
17
17
|
const { distance, nearest } = await import('../../shared/suggest.js');
|
|
18
|
-
|
|
18
|
+
/* Never the spelling that was typed: "Did you mean --brief?" to --brief is no help. */
|
|
19
|
+
const near = nearest(said, among.filter((word) => word !== said));
|
|
19
20
|
return near !== undefined && distance(said.toLowerCase(), near.toLowerCase()) <= Math.max(1, Math.floor(said.length / 3))
|
|
20
21
|
? ` Did you mean ${near}?`
|
|
21
22
|
: '';
|
|
@@ -36,3 +37,13 @@ export async function packageVersion() {
|
|
|
36
37
|
return '0.0.0';
|
|
37
38
|
}
|
|
38
39
|
}
|
|
40
|
+
/** The commands whose usage spells `flag` (`mistri schema --brief`), for a flag typed where no command takes it. */
|
|
41
|
+
export function commandsTaking(usage, bin, flag) {
|
|
42
|
+
const out = new Set();
|
|
43
|
+
for (const line of usage.split('\n')) {
|
|
44
|
+
const command = new RegExp(`^ {2}${bin} ([a-z][a-z-]*)(?=\\s|$)`).exec(line)?.[1];
|
|
45
|
+
if (command && new RegExp(`(?<![\\w-])${flag}(?![\\w-])`).test(line))
|
|
46
|
+
out.add(command);
|
|
47
|
+
}
|
|
48
|
+
return [...out];
|
|
49
|
+
}
|
|
@@ -9,6 +9,7 @@ import { headingWeight, inheritThemePreset, lookNavRole } from '../shared/themeP
|
|
|
9
9
|
import { typeTokens } from '../shared/themeType.js';
|
|
10
10
|
import { fieldEdge } from '../shared/themeColor.js';
|
|
11
11
|
import { recipeAttributes } from '../shared/themeRecipes.js';
|
|
12
|
+
import { APP_PAGE_PERMISSIONS_POLICY } from './http/baselineHeaders.js';
|
|
12
13
|
const MIME = {
|
|
13
14
|
'.html': 'text/html; charset=utf-8',
|
|
14
15
|
'.js': 'text/javascript; charset=utf-8',
|
|
@@ -112,6 +113,11 @@ function withFrameAncestors(policy, origins) {
|
|
|
112
113
|
return policy;
|
|
113
114
|
return policy.replace("frame-ancestors 'self'", ["frame-ancestors 'self'", ...origins].join(' '));
|
|
114
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* An App's page may use the camera (the scan input); the database browser's
|
|
118
|
+
* has no such input and keeps the baseline's refusal (http/baselineHeaders.ts).
|
|
119
|
+
*/
|
|
120
|
+
const pagePermissions = (shell) => shell?.workbench ? {} : { 'permissions-policy': APP_PAGE_PERMISSIONS_POLICY };
|
|
115
121
|
/** A page's whole policy: its own, the served Apps' egress, and who may frame it. */
|
|
116
122
|
const pagePolicy = (policy, shell) => shell?.unframed
|
|
117
123
|
? withEgress(policy, shell.egress).replace("frame-ancestors 'self'", "frame-ancestors 'none'")
|
|
@@ -451,6 +457,7 @@ export async function serveClient(files, req, res, shell) {
|
|
|
451
457
|
...(data || shell?.branding?.private ? { vary: 'Cookie' } : {}),
|
|
452
458
|
'x-content-type-options': 'nosniff',
|
|
453
459
|
'content-security-policy': pagePolicy(shellPolicy(html, { fromSource: true, socket: vite.socket }), shell),
|
|
460
|
+
...pagePermissions(shell),
|
|
454
461
|
});
|
|
455
462
|
res.end(head ? undefined : html);
|
|
456
463
|
}
|
|
@@ -621,7 +628,12 @@ export function builtClient(dir) {
|
|
|
621
628
|
'x-content-type-options': 'nosniff',
|
|
622
629
|
'content-type': asset.type,
|
|
623
630
|
vary: asset.variants.length > 1 ? 'Accept-Encoding, Cookie' : 'Cookie',
|
|
624
|
-
...(asset.policy
|
|
631
|
+
...(asset.policy
|
|
632
|
+
? {
|
|
633
|
+
'content-security-policy': pagePolicy(shell.mount?.base ? shellPolicy(text) : asset.policy, shell),
|
|
634
|
+
...pagePermissions(shell),
|
|
635
|
+
}
|
|
636
|
+
: {}),
|
|
625
637
|
};
|
|
626
638
|
if (head) {
|
|
627
639
|
res.writeHead(200, headers).end();
|
|
@@ -645,7 +657,12 @@ export function builtClient(dir) {
|
|
|
645
657
|
'cache-control': privately ? PERSONAL : 'no-cache',
|
|
646
658
|
...(!privately ? { etag: strongTag(body) } : {}),
|
|
647
659
|
'x-content-type-options': 'nosniff',
|
|
648
|
-
...(asset.policy
|
|
660
|
+
...(asset.policy
|
|
661
|
+
? {
|
|
662
|
+
'content-security-policy': pagePolicy(shell?.mount?.base ? shellPolicy(text) : asset.policy, shell),
|
|
663
|
+
...pagePermissions(shell),
|
|
664
|
+
}
|
|
665
|
+
: {}),
|
|
649
666
|
...(asset.variants.length > 1 || privately
|
|
650
667
|
? { vary: [asset.variants.length > 1 ? 'Accept-Encoding' : '', privately ? 'Cookie' : ''].filter(Boolean).join(', ') }
|
|
651
668
|
: {}),
|
|
@@ -669,7 +686,7 @@ export function builtClient(dir) {
|
|
|
669
686
|
'cache-control': asset.cache,
|
|
670
687
|
etag: variant.etag,
|
|
671
688
|
'x-content-type-options': 'nosniff',
|
|
672
|
-
...(asset.policy ? { 'content-security-policy': pagePolicy(asset.policy, shell) } : {}),
|
|
689
|
+
...(asset.policy ? { 'content-security-policy': pagePolicy(asset.policy, shell), ...pagePermissions(shell) } : {}),
|
|
673
690
|
};
|
|
674
691
|
if (asset.variants.length > 1)
|
|
675
692
|
headers.vary = 'Accept-Encoding';
|
|
@@ -27,7 +27,7 @@ interface ProjectContext {
|
|
|
27
27
|
};
|
|
28
28
|
readonly app?: {
|
|
29
29
|
readonly path: string;
|
|
30
|
-
readonly from: 'flag' | 'profile';
|
|
30
|
+
readonly from: 'flag' | 'profile' | 'cwd';
|
|
31
31
|
};
|
|
32
32
|
readonly entries: Partial<Record<ProfileEntry, {
|
|
33
33
|
readonly path: string;
|
|
@@ -42,13 +42,20 @@ export declare class ProfileRefusal extends Error {
|
|
|
42
42
|
/** What an App command takes of the profile: the App, and which entries. */
|
|
43
43
|
export interface ProfileTakes {
|
|
44
44
|
readonly entries: readonly ProfileEntry[];
|
|
45
|
-
/** `
|
|
46
|
-
readonly
|
|
45
|
+
/** Without `--app` or a profile's `dir`, the working directory is the App when it holds an App entry. */
|
|
46
|
+
readonly cwdApp?: boolean;
|
|
47
47
|
/** The command prints the context in its own output and `--json` (check, migrate); another says it on stderr. */
|
|
48
48
|
readonly says?: boolean;
|
|
49
49
|
/** False where the command reads no App (`migrate diff` reads schema.sql and the config's connection). */
|
|
50
50
|
readonly app?: boolean;
|
|
51
51
|
}
|
|
52
|
+
/** Whether a directory holds an App entry. */
|
|
53
|
+
export declare const holdsApp: (dir: string) => boolean;
|
|
54
|
+
/**
|
|
55
|
+
* A word typed where a database, a route or a target goes that is an App's directory: the App is named with
|
|
56
|
+
* `--app`, never by position, so it is refused rather than read as one. Undefined when the word is anything else.
|
|
57
|
+
*/
|
|
58
|
+
export declare function appDirectoryWord(command: string, word: string | undefined): string | undefined;
|
|
52
59
|
/**
|
|
53
60
|
* The config file a run reads, by the one order: `--config`, the App's own, the working directory's, the person's
|
|
54
61
|
* own. Undefined when there is none (a run on a database named by `--db`).
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* The block takes paths and nothing else: a `${NAME}` reference, a key it does not know, or a file that is not
|
|
16
16
|
* there is refused by name. It is not a second App definition: it names modules and defines nothing.
|
|
17
17
|
*/
|
|
18
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
18
|
+
import { existsSync, readFileSync, statSync } from 'node:fs';
|
|
19
19
|
import { homedir } from 'node:os';
|
|
20
20
|
import { dirname, isAbsolute, join, relative, resolve } from 'node:path';
|
|
21
21
|
import { configFileName, product } from '../product.js';
|
|
@@ -25,6 +25,26 @@ const PROFILE_KEYS = ['dir', ...Object.keys(PROFILE_ENTRIES)];
|
|
|
25
25
|
/** A profile that cannot be used: refused before anything is read. */
|
|
26
26
|
export class ProfileRefusal extends Error {
|
|
27
27
|
}
|
|
28
|
+
/** The files an App's directory is known by: the entry `loadApp` reads. */
|
|
29
|
+
const APP_ENTRY_FILES = ['app.ts', 'app.mjs', 'app.json'];
|
|
30
|
+
/** Whether a directory holds an App entry. */
|
|
31
|
+
export const holdsApp = (dir) => APP_ENTRY_FILES.some((name) => existsSync(join(dir, name)));
|
|
32
|
+
/**
|
|
33
|
+
* A word typed where a database, a route or a target goes that is an App's directory: the App is named with
|
|
34
|
+
* `--app`, never by position, so it is refused rather than read as one. Undefined when the word is anything else.
|
|
35
|
+
*/
|
|
36
|
+
export function appDirectoryWord(command, word) {
|
|
37
|
+
if (word === undefined || word.startsWith('-'))
|
|
38
|
+
return undefined;
|
|
39
|
+
try {
|
|
40
|
+
if (!statSync(word).isDirectory() || !holdsApp(word))
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
return `${word} is an App's directory, and an App is named with --app: ${command} --app ${word}`;
|
|
47
|
+
}
|
|
28
48
|
const shown = (path) => {
|
|
29
49
|
const near = relative(process.cwd(), path);
|
|
30
50
|
return !near ? '.' : near.startsWith('..') || isAbsolute(near) ? path : near;
|
|
@@ -117,8 +137,7 @@ export function applyProfile(argv, takes, env = process.env) {
|
|
|
117
137
|
/* A suite's Apps are the suite's to name (`migrate stores up --suite`): the profile's one App is not added to it. */
|
|
118
138
|
const suite = out.includes('--suite');
|
|
119
139
|
const apps = flagged(out, '--app');
|
|
120
|
-
const
|
|
121
|
-
const named = apps.length === 1 ? apps[0] : positional;
|
|
140
|
+
const named = apps.length === 1 ? apps[0] : undefined;
|
|
122
141
|
const explicit = flagged(out, '--config').at(-1);
|
|
123
142
|
const naming = out.includes('--db') || out.includes('-d');
|
|
124
143
|
const found = naming && explicit === undefined
|
|
@@ -139,6 +158,11 @@ export function applyProfile(argv, takes, env = process.env) {
|
|
|
139
158
|
app = { path: profile.dir, from: 'profile' };
|
|
140
159
|
out.push('--app', shown(profile.dir));
|
|
141
160
|
}
|
|
161
|
+
else if (apps.length === 0 && takes.cwdApp && !suite && takes.app !== false && holdsApp('.')) {
|
|
162
|
+
/* The one rule: no --app and no profile, the App is the directory the person is in, when it is one. */
|
|
163
|
+
app = { path: resolve('.'), from: 'cwd' };
|
|
164
|
+
out.push('--app', '.');
|
|
165
|
+
}
|
|
142
166
|
const entries = {};
|
|
143
167
|
if (apps.length <= 1 && !suite && takes.app !== false)
|
|
144
168
|
for (const entry of takes.entries) {
|
|
@@ -202,7 +226,7 @@ export function contextLines(context, more = {}) {
|
|
|
202
226
|
const lines = [`Context: ${where}`];
|
|
203
227
|
const row = (key, path, from) => lines.push(` ${key.padEnd(9)} ${(path ?? '—').padEnd(13)} ${from}`);
|
|
204
228
|
if (context.app)
|
|
205
|
-
row('app', shown(context.app.path), context.app.from === 'profile' ? 'mistri.json' : over(context, 'dir', 'flag'));
|
|
229
|
+
row('app', shown(context.app.path), context.app.from === 'profile' ? 'mistri.json' : context.app.from === 'cwd' ? 'the working directory' : over(context, 'dir', 'flag'));
|
|
206
230
|
for (const entry of ['commands', 'jobs', 'policy', 'entry']) {
|
|
207
231
|
const own = context.entries[entry] ?? more[entry];
|
|
208
232
|
if (!own) {
|
|
@@ -438,7 +438,7 @@ export class Registry {
|
|
|
438
438
|
const opened = await openHttp(entry.config.name, entry.config.url, entry.config.http, {
|
|
439
439
|
secrets: !entry.untrustedUrl,
|
|
440
440
|
environment: this.environment,
|
|
441
|
-
...(entry.config.http.cache ? { cache: scopedCache(this.cache(),
|
|
441
|
+
...(entry.config.http.cache ? { cache: scopedCache(this.cache(), `${product()}:http:${entry.config.id}:`) } : {}),
|
|
442
442
|
});
|
|
443
443
|
entry.secret = opened.secret;
|
|
444
444
|
entry.warning = opened.warning;
|
package/dist/server/demo.js
CHANGED
|
@@ -16,7 +16,7 @@ import { DatabaseSync } from 'node:sqlite';
|
|
|
16
16
|
import { mkdirSync, mkdtempSync, rmSync } from 'node:fs';
|
|
17
17
|
import { dirname, join } from 'node:path';
|
|
18
18
|
import { tmpdir } from 'node:os';
|
|
19
|
-
import { productEnv } from './product.js';
|
|
19
|
+
import { product, productEnv } from './product.js';
|
|
20
20
|
const SCHEMA = `
|
|
21
21
|
CREATE TABLE country (
|
|
22
22
|
code TEXT PRIMARY KEY,
|
|
@@ -134,7 +134,7 @@ INSERT INTO shipment (id, invoice_id, line_no, shipped_on) VALUES
|
|
|
134
134
|
(3,1002,1,'2025-07-04'),(4,1004,1,'2026-01-10'),(5,1004,2,NULL);
|
|
135
135
|
`;
|
|
136
136
|
/**
|
|
137
|
-
* Where `--demo` builds its database. A fixed `$TMPDIR
|
|
137
|
+
* Where `--demo` builds its database. A fixed `$TMPDIR/<product>-demo.db` was
|
|
138
138
|
* a machine-global path that every boot deletes and rebuilds, so two people —
|
|
139
139
|
* or two test runs, or a run beside a demo someone left open — silently
|
|
140
140
|
* corrupted each other. Observed as twelve browser failures that looked
|
|
@@ -152,7 +152,7 @@ export function demoDatabaseFile() {
|
|
|
152
152
|
return named;
|
|
153
153
|
if (chosen)
|
|
154
154
|
return chosen;
|
|
155
|
-
const directory = mkdtempSync(join(tmpdir(),
|
|
155
|
+
const directory = mkdtempSync(join(tmpdir(), `${product()}-demo-`));
|
|
156
156
|
// The demo is disposable by definition: nothing here outlives the process
|
|
157
157
|
// that built it, and leaving a directory per run in $TMPDIR would be litter.
|
|
158
158
|
process.on('exit', () => {
|
|
@@ -6,9 +6,13 @@
|
|
|
6
6
|
* - `Referrer-Policy: strict-origin-when-cross-origin`: an address under a
|
|
7
7
|
* record (`/compass/leads/127?search=…`) leaves this origin as the origin
|
|
8
8
|
* alone, and never over plain http.
|
|
9
|
-
* - `Permissions-Policy`: no page here uses a
|
|
10
|
-
*
|
|
11
|
-
* whatever frames or is framed.
|
|
9
|
+
* - `Permissions-Policy`: no page here uses a microphone, a location or a
|
|
10
|
+
* payment sheet, and nothing but an App's page draws a camera, so none is
|
|
11
|
+
* granted — to a component, or to whatever frames or is framed. An App's
|
|
12
|
+
* own HTML (clientHttp.ts) replaces this with `APP_PAGE_PERMISSIONS_POLICY`,
|
|
13
|
+
* which lets its own origin ask for the camera: the scan input
|
|
14
|
+
* (`field.text({ as: 'scan' })`) reads a code through `getUserMedia`, and
|
|
15
|
+
* a form with one can be a signed-in page or a public one.
|
|
12
16
|
* - `Strict-Transport-Security`, only on an answer that arrived over https
|
|
13
17
|
* (trust.ts `arrivedOverHttps`): the socket's own TLS, an https public
|
|
14
18
|
* address, or a proxy this server trusts saying it forwarded https. A
|
|
@@ -21,6 +25,12 @@ import { type ProxyRange } from './trust.js';
|
|
|
21
25
|
export declare const REFERRER_POLICY = "strict-origin-when-cross-origin";
|
|
22
26
|
/** @public the database browser's (scripts/boundary/entries.json, "host") */
|
|
23
27
|
export declare const PERMISSIONS_POLICY: string;
|
|
28
|
+
/**
|
|
29
|
+
* An App's page: `PERMISSIONS_POLICY` with the camera allowed for this origin
|
|
30
|
+
* alone. Only the HTML says it — the API, the assets and every refusal keep
|
|
31
|
+
* the baseline — and a frame from another origin is still not granted it.
|
|
32
|
+
*/
|
|
33
|
+
export declare const APP_PAGE_PERMISSIONS_POLICY: string;
|
|
24
34
|
/** A year, and the names under this one: the time browsers ask of a name kept on https. */
|
|
25
35
|
export declare const STRICT_TRANSPORT = "max-age=31536000; includeSubDomains";
|
|
26
36
|
export declare function setBaselineHeaders(req: Pick<IncomingMessage, 'headers' | 'socket'>, res: ServerResponse, trustedProxies?: readonly ProxyRange[]): void;
|
|
@@ -4,6 +4,12 @@ export const REFERRER_POLICY = 'strict-origin-when-cross-origin';
|
|
|
4
4
|
/** @public the database browser's (scripts/boundary/entries.json, "host") */
|
|
5
5
|
export const PERMISSIONS_POLICY = 'camera=(), microphone=(), geolocation=(), payment=(), usb=(), serial=(), bluetooth=(), hid=(), midi=(), ' +
|
|
6
6
|
'magnetometer=(), gyroscope=(), accelerometer=(), display-capture=(), browsing-topics=()';
|
|
7
|
+
/**
|
|
8
|
+
* An App's page: `PERMISSIONS_POLICY` with the camera allowed for this origin
|
|
9
|
+
* alone. Only the HTML says it — the API, the assets and every refusal keep
|
|
10
|
+
* the baseline — and a frame from another origin is still not granted it.
|
|
11
|
+
*/
|
|
12
|
+
export const APP_PAGE_PERMISSIONS_POLICY = PERMISSIONS_POLICY.replace('camera=()', 'camera=(self)');
|
|
7
13
|
/** A year, and the names under this one: the time browsers ask of a name kept on https. */
|
|
8
14
|
export const STRICT_TRANSPORT = 'max-age=31536000; includeSubDomains';
|
|
9
15
|
export function setBaselineHeaders(req, res, trustedProxies = []) {
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one place an HTTP server is made. Every listener that takes a person's
|
|
3
|
+
* request (the single-App server, the tenant servers and the suite) is
|
|
4
|
+
* `frontDoor(options, handle)`, so what no surface may forget is done here
|
|
5
|
+
* once, before its handler reads anything:
|
|
6
|
+
*
|
|
7
|
+
* - the request waits in a pool's line as its client's, read through the
|
|
8
|
+
* proxies this server trusts (poolAdmission.ts, trust.ts `forwardedClient`);
|
|
9
|
+
* - the baseline headers (baselineHeaders.ts), set before anything is routed
|
|
10
|
+
* so a reply that names its own still wins;
|
|
11
|
+
* - the guard (`guard`), the surface's first refusal: a Host it does not
|
|
12
|
+
* serve (trust.ts `hostRefusal`, `doorRefusal`), or a stop in progress.
|
|
13
|
+
* It runs after the headers, so a refusal carries them as an answer does.
|
|
14
|
+
*
|
|
15
|
+
* A surface's own refusals, in the shapes its callers read, stay in the
|
|
16
|
+
* surface; what they have in common is the part here. A `createServer` call
|
|
17
|
+
* anywhere else in a package's source is refused by
|
|
18
|
+
* `test/front-door-structure.test.ts`, which names the few that are not a door.
|
|
19
|
+
*/
|
|
20
|
+
import { type IncomingMessage, type Server, type ServerResponse } from 'node:http';
|
|
21
|
+
import { type ProxyRange } from './trust.js';
|
|
22
|
+
interface FrontDoorOptions {
|
|
23
|
+
/** The proxies whose forwarded address and protocol are read; read per request, so a late binding is seen. */
|
|
24
|
+
readonly trustedProxies?: readonly ProxyRange[] | (() => readonly ProxyRange[] | undefined);
|
|
25
|
+
/** False for a server nobody queues at, whose callers a front has already admitted; default true. */
|
|
26
|
+
readonly admit?: boolean;
|
|
27
|
+
/** Seen first, after admission: the operator's meters (operations/diagnostics.ts). */
|
|
28
|
+
readonly diagnostics?: {
|
|
29
|
+
observe(req: IncomingMessage, res: ServerResponse): void;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Outermost, around admission: the request's span (traceRequest.ts) covers
|
|
33
|
+
* the line it waits in. Call `run` once.
|
|
34
|
+
*/
|
|
35
|
+
readonly around?: (req: IncomingMessage, res: ServerResponse, run: () => void) => void;
|
|
36
|
+
/** The first refusal: true when it answered, and nothing further is read. */
|
|
37
|
+
readonly guard?: (req: IncomingMessage, res: ServerResponse) => boolean;
|
|
38
|
+
}
|
|
39
|
+
/** The server, made but not listening. */
|
|
40
|
+
export declare function frontDoor(options: FrontDoorOptions, handle: (req: IncomingMessage, res: ServerResponse) => void): Server;
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one place an HTTP server is made. Every listener that takes a person's
|
|
3
|
+
* request (the single-App server, the tenant servers and the suite) is
|
|
4
|
+
* `frontDoor(options, handle)`, so what no surface may forget is done here
|
|
5
|
+
* once, before its handler reads anything:
|
|
6
|
+
*
|
|
7
|
+
* - the request waits in a pool's line as its client's, read through the
|
|
8
|
+
* proxies this server trusts (poolAdmission.ts, trust.ts `forwardedClient`);
|
|
9
|
+
* - the baseline headers (baselineHeaders.ts), set before anything is routed
|
|
10
|
+
* so a reply that names its own still wins;
|
|
11
|
+
* - the guard (`guard`), the surface's first refusal: a Host it does not
|
|
12
|
+
* serve (trust.ts `hostRefusal`, `doorRefusal`), or a stop in progress.
|
|
13
|
+
* It runs after the headers, so a refusal carries them as an answer does.
|
|
14
|
+
*
|
|
15
|
+
* A surface's own refusals, in the shapes its callers read, stay in the
|
|
16
|
+
* surface; what they have in common is the part here. A `createServer` call
|
|
17
|
+
* anywhere else in a package's source is refused by
|
|
18
|
+
* `test/front-door-structure.test.ts`, which names the few that are not a door.
|
|
19
|
+
*/
|
|
20
|
+
import { createServer } from 'node:http';
|
|
21
|
+
import { withAdmission } from '../../adapters/poolAdmission.js';
|
|
22
|
+
import { setBaselineHeaders } from './baselineHeaders.js';
|
|
23
|
+
import { forwardedClient } from './trust.js';
|
|
24
|
+
/** The server, made but not listening. */
|
|
25
|
+
export function frontDoor(options, handle) {
|
|
26
|
+
const proxies = () => (typeof options.trustedProxies === 'function' ? options.trustedProxies() : options.trustedProxies) ?? [];
|
|
27
|
+
const through = (req, res) => {
|
|
28
|
+
options.diagnostics?.observe(req, res);
|
|
29
|
+
setBaselineHeaders(req, res, proxies());
|
|
30
|
+
if (options.guard?.(req, res))
|
|
31
|
+
return;
|
|
32
|
+
handle(req, res);
|
|
33
|
+
};
|
|
34
|
+
const admitted = (req, res) => options.admit === false ? through(req, res) : withAdmission(forwardedClient(req, proxies()), () => through(req, res));
|
|
35
|
+
return createServer((req, res) => (options.around ? options.around(req, res, () => admitted(req, res)) : admitted(req, res)));
|
|
36
|
+
}
|
|
@@ -117,12 +117,12 @@ export declare const PUBLIC_FORM_SUBMIT_TOTAL: readonly RateWindow[];
|
|
|
117
117
|
export declare const PUBLIC_FORM_READ_WINDOWS: readonly RateWindow[];
|
|
118
118
|
export declare const INVITATION_CLAIM_WINDOWS: readonly RateWindow[];
|
|
119
119
|
export declare const INVITATION_CLAIM_TOTAL: readonly RateWindow[];
|
|
120
|
-
export declare function publicFormLimiter(kind: 'submit' | 'read' | 'start' | 'status' | 'link' | 'code' | 'check'): FixedWindowLimiter | SharedWindowLimiter;
|
|
120
|
+
export declare function publicFormLimiter(kind: 'submit' | 'read' | 'start' | 'status' | 'link' | 'code' | 'check' | 'file'): FixedWindowLimiter | SharedWindowLimiter;
|
|
121
121
|
/** The invitation claims' own budget (tenantInvitationHttp.ts), never the forms'. */
|
|
122
122
|
export declare function invitationClaimLimiter(): FixedWindowLimiter | SharedWindowLimiter;
|
|
123
123
|
/**
|
|
124
124
|
* Count the public forms' windows in the deployment's cache, under the
|
|
125
|
-
* deployment's namespace (`
|
|
125
|
+
* deployment's namespace (`mistri:<app>:form:`, in the running product's name), or — with no cache, or the
|
|
126
126
|
* process's own — in this process, as before.
|
|
127
127
|
*/
|
|
128
128
|
export declare function configurePublicFormLimits(cache: CacheStore | undefined, namespace: string): void;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CacheUnavailable, scopedCache } from '../../adapters/cache/cacheStore.js';
|
|
2
2
|
import { forwardedClient, ipv6Groups } from './trust.js';
|
|
3
|
+
import { product } from '../product.js';
|
|
3
4
|
const MAX_CLIENTS = 10_000;
|
|
4
5
|
function assertWindows(windows) {
|
|
5
6
|
if (!windows.length || windows.some((w) => !Number.isSafeInteger(w.limit) || w.limit < 1 || !Number.isFinite(w.ms) || w.ms <= 0)) {
|
|
@@ -285,7 +286,16 @@ const CODE_TOTAL = Object.freeze([{ limit: 300, ms: 3_600_000 }]);
|
|
|
285
286
|
client, and never counted against what that client may submit. */
|
|
286
287
|
const CHECK_WINDOWS = Object.freeze([{ limit: 60, ms: 60_000 }]);
|
|
287
288
|
const CHECK_TOTAL = Object.freeze([{ limit: 6_000, ms: 60_000 }]);
|
|
289
|
+
/* A file sent to be held for a public form's command (stagedFiles.ts): a person attaches a few, so twenty a minute
|
|
290
|
+
and sixty an hour from one client; and few enough from every visitor together that the form's files cannot be made
|
|
291
|
+
a place to keep things. */
|
|
292
|
+
const FILE_WINDOWS = Object.freeze([
|
|
293
|
+
{ limit: 20, ms: 60_000 },
|
|
294
|
+
{ limit: 60, ms: 3_600_000 },
|
|
295
|
+
]);
|
|
296
|
+
const FILE_TOTAL = Object.freeze([{ limit: 1_200, ms: 3_600_000 }]);
|
|
288
297
|
const check = new FixedWindowLimiter(CHECK_WINDOWS, Date.now, { total: CHECK_TOTAL, whenFull: 'evict' });
|
|
298
|
+
const file = new FixedWindowLimiter(FILE_WINDOWS, Date.now, { total: FILE_TOTAL, whenFull: 'refuse' });
|
|
289
299
|
const submit = new FixedWindowLimiter(PUBLIC_FORM_SUBMIT_WINDOWS, Date.now, { total: PUBLIC_FORM_SUBMIT_TOTAL, whenFull: 'refuse' });
|
|
290
300
|
const read = new FixedWindowLimiter(PUBLIC_FORM_READ_WINDOWS, Date.now, { whenFull: 'evict' });
|
|
291
301
|
const claim = new FixedWindowLimiter(INVITATION_CLAIM_WINDOWS, Date.now, { total: INVITATION_CLAIM_TOTAL, whenFull: 'refuse' });
|
|
@@ -299,6 +309,8 @@ export function publicFormLimiter(kind) {
|
|
|
299
309
|
return shared[kind];
|
|
300
310
|
if (kind === 'check')
|
|
301
311
|
return check;
|
|
312
|
+
if (kind === 'file')
|
|
313
|
+
return file;
|
|
302
314
|
return kind === 'submit'
|
|
303
315
|
? submit
|
|
304
316
|
: kind === 'read'
|
|
@@ -317,7 +329,7 @@ export function invitationClaimLimiter() {
|
|
|
317
329
|
}
|
|
318
330
|
/**
|
|
319
331
|
* Count the public forms' windows in the deployment's cache, under the
|
|
320
|
-
* deployment's namespace (`
|
|
332
|
+
* deployment's namespace (`mistri:<app>:form:`, in the running product's name), or — with no cache, or the
|
|
321
333
|
* process's own — in this process, as before.
|
|
322
334
|
*/
|
|
323
335
|
export function configurePublicFormLimits(cache, namespace) {
|
|
@@ -325,7 +337,7 @@ export function configurePublicFormLimits(cache, namespace) {
|
|
|
325
337
|
shared = undefined;
|
|
326
338
|
return;
|
|
327
339
|
}
|
|
328
|
-
const scoped = scopedCache(cache,
|
|
340
|
+
const scoped = scopedCache(cache, `${product()}:${namespace}:form:`);
|
|
329
341
|
shared = {
|
|
330
342
|
submit: new SharedWindowLimiter('submit', PUBLIC_FORM_SUBMIT_WINDOWS, scoped, submit, PUBLIC_FORM_SUBMIT_TOTAL),
|
|
331
343
|
read: new SharedWindowLimiter('read', PUBLIC_FORM_READ_WINDOWS, scoped, read),
|
|
@@ -336,6 +348,7 @@ export function configurePublicFormLimits(cache, namespace) {
|
|
|
336
348
|
link: new SharedWindowLimiter('link', LINK_WINDOWS, scoped, link, LINK_TOTAL),
|
|
337
349
|
code: new SharedWindowLimiter('code', CODE_WINDOWS, scoped, code, CODE_TOTAL),
|
|
338
350
|
check: new SharedWindowLimiter('check', CHECK_WINDOWS, scoped, check, CHECK_TOTAL),
|
|
351
|
+
file: new SharedWindowLimiter('file', FILE_WINDOWS, scoped, file, FILE_TOTAL),
|
|
339
352
|
};
|
|
340
353
|
}
|
|
341
354
|
/** Forgets the forms' budgets and the claims'; tests and a policy reload use it. */
|
|
@@ -348,4 +361,5 @@ export function resetPublicFormLimits() {
|
|
|
348
361
|
link.reset();
|
|
349
362
|
code.reset();
|
|
350
363
|
check.reset();
|
|
364
|
+
file.reset();
|
|
351
365
|
}
|
|
@@ -55,6 +55,7 @@ export async function composeRecordPage({ ctx, source, body, post, hooks, }) {
|
|
|
55
55
|
app: ctx.appConfigured,
|
|
56
56
|
recordLabel: (table) => resources[table]?.recordLabel,
|
|
57
57
|
defined: (table) => resources[table]?.defined,
|
|
58
|
+
display: (table, column) => resources[table]?.display?.[column],
|
|
58
59
|
};
|
|
59
60
|
const options = { rows, history: true, ...(tab === undefined ? {} : { tab: tab }) };
|
|
60
61
|
/* What the page reads that its plan does not decide — the record's row,
|
|
@@ -12,10 +12,10 @@
|
|
|
12
12
|
* malformed target is answered with, what an error's status is, which
|
|
13
13
|
* requests a close waits for — would agree only by convention.
|
|
14
14
|
*/
|
|
15
|
-
import {
|
|
15
|
+
import type { IncomingMessage, Server, ServerResponse } from 'node:http';
|
|
16
16
|
import type { RequestDiagnostics } from '../operations/diagnostics.js';
|
|
17
17
|
import { type AddressMount } from '../../shared/mount.js';
|
|
18
|
-
import {
|
|
18
|
+
import type { Bound } from './trust.js';
|
|
19
19
|
/**
|
|
20
20
|
* The request read through the server's mounts (shared/mount.ts): the base
|
|
21
21
|
* path taken off `req.url`, which the static files, the App API and Better
|
|
@@ -1,24 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The HTTP server every product's dispatcher listens on: a `node:http`
|
|
3
|
-
* server with the request's span, the baseline headers, the address read
|
|
4
|
-
* through the mounts, the orchestrator's probes, and the error-to-status
|
|
5
|
-
* mapping the tests pin — and, in the middle, the product's own answer
|
|
6
|
-
* (`Answering`). The database browser's server (browserServer.ts) and the
|
|
7
|
-
* App framework's (server.ts) are each this, with what their product adds.
|
|
8
|
-
*
|
|
9
|
-
* Kept whole rather than rebuilt per product, for the reason `createApp`
|
|
10
|
-
* was pulled out of `main` in the first place: a wiring a product wrote for
|
|
11
|
-
* itself would be the one its tests prove, and the shared parts — what a
|
|
12
|
-
* malformed target is answered with, what an error's status is, which
|
|
13
|
-
* requests a close waits for — would agree only by convention.
|
|
14
|
-
*/
|
|
15
|
-
import { createServer } from 'node:http';
|
|
16
1
|
import { SOURCE_CLIENT, attachDevClient } from '../devclient.js';
|
|
17
2
|
import { applyServerTimeouts } from '../serverTimeouts.js';
|
|
18
3
|
import { Refusal, WriteConflict } from '../../adapters/adapter.js';
|
|
19
4
|
import { HttpSourceError } from '../../adapters/http/egress.js';
|
|
20
5
|
import { isPoolBusy } from '../../adapters/poolMetrics.js';
|
|
21
|
-
import { withAdmission } from '../../adapters/poolAdmission.js';
|
|
22
6
|
import { AppAccessDenied } from '../columnGrants.js';
|
|
23
7
|
import { wrongTypeValue } from '../constraints.js';
|
|
24
8
|
import { PathError } from '../../shared/view.js';
|
|
@@ -28,8 +12,7 @@ import { probe } from './probes.js';
|
|
|
28
12
|
import { reportRefusal } from './refusalReport.js';
|
|
29
13
|
import { HttpError, send, sendBusy } from './reply.js';
|
|
30
14
|
import { routedPath, servedApp, traceRequest } from './traceRequest.js';
|
|
31
|
-
import {
|
|
32
|
-
import { forwardedClient } from './trust.js';
|
|
15
|
+
import { frontDoor } from './frontDoor.js';
|
|
33
16
|
import { timeRequests } from '../../adapters/telemetry/serverTiming.js';
|
|
34
17
|
/* From source, Vite's modules are addressed from the root whatever the base
|
|
35
18
|
(devclient.ts): its own paths and the client's files, never a page, the
|
|
@@ -99,12 +82,13 @@ export function listen(options, answering) {
|
|
|
99
82
|
/* The span of each request (traceRequest.ts) names its route from the
|
|
100
83
|
address after routeAddress has read it inward, never as the browser
|
|
101
84
|
spelled it: under a base path or a root mount it is the same route. */
|
|
102
|
-
const server =
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
options.diagnostics
|
|
107
|
-
|
|
85
|
+
const server = frontDoor({
|
|
86
|
+
/* Its pool checkouts wait in line as its client's until its session names the account
|
|
87
|
+
(adapters/poolAdmission.ts, http/door.ts). */
|
|
88
|
+
trustedProxies: () => options.bound.trustedProxies,
|
|
89
|
+
diagnostics: options.diagnostics,
|
|
90
|
+
around: (req, res, run) => traceRequest(req, res, run),
|
|
91
|
+
}, (req, res) => {
|
|
108
92
|
// Node accepts request targets that URL cannot parse. Refuse them before
|
|
109
93
|
// dispatch, and reuse this parse in error mapping and drain tracking too.
|
|
110
94
|
let url;
|
|
@@ -112,7 +96,7 @@ export function listen(options, answering) {
|
|
|
112
96
|
url = new URL(req.url ?? '/', 'http://localhost');
|
|
113
97
|
}
|
|
114
98
|
catch {
|
|
115
|
-
return send(res, 400, { error: 'Invalid request target.' });
|
|
99
|
+
return void send(res, 400, { error: 'Invalid request target.' });
|
|
116
100
|
}
|
|
117
101
|
const mount = answering.mount();
|
|
118
102
|
if (answering.outside?.(req, res, url))
|
|
@@ -130,17 +114,17 @@ export function listen(options, answering) {
|
|
|
130
114
|
if (answering.failed?.(err, req, res, url))
|
|
131
115
|
return;
|
|
132
116
|
/* The client left: its request was cut off mid-body, or it closed the
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
117
|
+
socket before the answer, and what failed was the read it no longer
|
|
118
|
+
waits for. Nobody can be answered and nothing went wrong on this
|
|
119
|
+
side, so it is not a 500 on the operator's terminal: the request's
|
|
120
|
+
span still says it was aborted (traceRequest.ts). */
|
|
137
121
|
if (clientLeft(req, res, err)) {
|
|
138
122
|
res.destroy();
|
|
139
123
|
return;
|
|
140
124
|
}
|
|
141
125
|
/* The pool had no connection to give within its budget: the server is
|
|
142
|
-
|
|
143
|
-
|
|
126
|
+
busy, which is neither the caller's mistake nor a failure, and a 500
|
|
127
|
+
after ten seconds said both. Answered now, with when to come back. */
|
|
144
128
|
if (isPoolBusy(err) && !res.headersSent) {
|
|
145
129
|
reportRefusal(req, 503, 'server_busy', err.message, err);
|
|
146
130
|
return sendBusy(res, {}, false, err);
|
|
@@ -155,7 +139,7 @@ export function listen(options, answering) {
|
|
|
155
139
|
pending.add(operation);
|
|
156
140
|
void operation.finally(() => pending.delete(operation));
|
|
157
141
|
}
|
|
158
|
-
})
|
|
142
|
+
});
|
|
159
143
|
commandOperations.set(server, pending);
|
|
160
144
|
if (SOURCE_CLIENT && options.sourceClient !== false)
|
|
161
145
|
attachDevClient(server);
|