@volter/world-core 3.0.29 → 3.0.31
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/host-routing.cjs +106 -0
- package/dist/host-routing.d.cts +7 -0
- package/dist/inject.cjs +5 -8
- package/dist/src/actions.d.ts +3 -1
- package/dist/src/actions.js +4 -2
- package/dist/src/board-keys.d.ts +6 -0
- package/dist/src/board-keys.js +4 -0
- package/dist/src/browser-cookie-jar.d.ts +9 -0
- package/dist/src/browser-cookie-jar.js +104 -0
- package/dist/src/browser-session.d.ts +9 -0
- package/dist/src/browser-session.js +30 -0
- package/dist/src/browser-state.d.ts +52 -0
- package/dist/src/browser-state.js +105 -0
- package/dist/src/browser.d.ts +12 -0
- package/dist/src/browser.js +135 -0
- package/dist/src/derived-core.d.ts +3 -1
- package/dist/src/derived-core.js +26 -19
- package/dist/src/derived.d.ts +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +2 -0
- package/dist/src/pack-fetch.js +2 -2
- package/dist/src/public-suffixes.json +1 -0
- package/dist/src/runtime.d.ts +2 -1
- package/dist/src/runtime.js +2 -1
- package/dist/src/serve.d.ts +3 -1
- package/dist/src/serve.js +4 -2
- package/dist/src/twin-fetch.d.ts +1 -1
- package/dist/src/twin-fetch.js +23 -4
- package/dist/vendor-hosts.cjs +13 -105
- package/dist/vendor-hosts.d.cts +3 -0
- package/host-routing.cjs +106 -0
- package/host-routing.d.cts +7 -0
- package/inject.cjs +5 -8
- package/package.json +11 -1
- package/src/actions.ts +3 -1
- package/src/board-keys.ts +4 -0
- package/src/browser-cookie-jar.ts +77 -0
- package/src/browser-session.ts +31 -0
- package/src/browser-state.ts +89 -0
- package/src/browser.ts +115 -0
- package/src/derived-core.ts +26 -16
- package/src/derived.ts +1 -1
- package/src/index.ts +4 -0
- package/src/pack-fetch.ts +2 -2
- package/src/public-suffixes.json +1 -0
- package/src/runtime.ts +4 -1
- package/src/serve.ts +3 -1
- package/src/twin-fetch.ts +9 -4
- package/vendor-hosts.cjs +13 -105
- package/vendor-hosts.d.cts +3 -0
package/src/runtime.ts
CHANGED
|
@@ -13,7 +13,7 @@ export { parseScenarioDocument, scenarioFaultResult, ScenarioEngine, ScenarioErr
|
|
|
13
13
|
export { WORLD_CLOCK_ENV, worldNow } from './world-clock.ts';
|
|
14
14
|
export { WORLD_ENV_NAMES_ENV, worldEnvValue } from './world-env.ts';
|
|
15
15
|
export { ORIGINAL_PATH_HEADER } from './sigv4.ts';
|
|
16
|
-
export { createTwinFetchFromHandler, TWIN_PREFIX_HEADER, TWIN_REQUEST_SCOPES, TWIN_SITES_HEADER, siteLabel, siteUrlOf, twinPublicBase, twinSiteUrl, withRequestScopes } from './twin-fetch.ts';
|
|
16
|
+
export { createTwinFetchFromHandler, placedCookies, TWIN_PREFIX_HEADER, TWIN_REQUEST_SCOPES, TWIN_SITES_HEADER, siteLabel, siteUrlOf, twinPublicBase, twinSiteUrl, withRequestScopes } from './twin-fetch.ts';
|
|
17
17
|
export { isReadOnlyRequest, READ_ONLY_REQUEST_HEADER, ReadOnlyRequestError, runAsReadOnlyRequest, runAsVendorMove, writesRefused } from './request-scope.ts';
|
|
18
18
|
export { compileSurface, createDerivedFetch, matchOperation } from './derived.ts';
|
|
19
19
|
export { currentTraceparent, deliveryTraceHeaders, newTraceparent, parseTraceparent, runWithRequestTrace, runWithTraceparent, TRACEPARENT_HEADER, traceparentForDelivery, validTraceparent } from './trace-context.ts';
|
|
@@ -343,3 +343,6 @@ export { captureHistory, captureParentHistory, historyChanges, historyAtInstant,
|
|
|
343
343
|
export type { HistoryView, HistoryLayout, HistoryReference, HistoryOrigin } from './history.ts';
|
|
344
344
|
export { foldHistory } from './log.ts';
|
|
345
345
|
export { volterHome } from './volter-home.ts';
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
export { boardFrameKey } from './board-keys.ts';
|
package/src/serve.ts
CHANGED
|
@@ -594,6 +594,8 @@ export async function applyTwinWriteAtomic<T>(
|
|
|
594
594
|
service: string,
|
|
595
595
|
prepare: (resources: readonly TwinResource[]) => AtomicTwinWriteDecision<T>,
|
|
596
596
|
root?: string,
|
|
597
|
+
/** A type index when the decision and its preconditions need only that type, read inside the state lock. */
|
|
598
|
+
read?: () => TwinResource[],
|
|
597
599
|
): Promise<{ value: T; result?: TwinWriteResult }> {
|
|
598
600
|
// Same ruling as applyTwinWrite: a local write is an OCCURRENCE unless the caller supplied
|
|
599
601
|
// identity. The mode rides on the decision because only the callback knows which write it chose.
|
|
@@ -606,7 +608,7 @@ export async function applyTwinWriteAtomic<T>(
|
|
|
606
608
|
action: actionForTwinWrite(service, decision.write),
|
|
607
609
|
identity: decision.write.idempotencyKey || decision.write.actionId ? 'caller' : 'occurrence',
|
|
608
610
|
};
|
|
609
|
-
}, root);
|
|
611
|
+
}, root, read);
|
|
610
612
|
// as applyTwinWrite: a seed's write is the placeholder's default data, never performed
|
|
611
613
|
const head = committed.action && committed.appended && !committed.placeholder ? await performAtHead(service, committed.action, root) : { performed: false };
|
|
612
614
|
return {
|
package/src/twin-fetch.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { assertBrowserName } from './browser-state.ts';
|
|
1
2
|
// THE ONE HTTP ADAPTATION (runtime contract R12b): most packs' serve path is the same
|
|
2
3
|
// ~20 lines of glue — the keyless GET /twin manifest door, the body read, a header map,
|
|
3
4
|
// the dispatch into `handle<Vendor>TwinRequest` with the WORLD instant, and a JSON
|
|
@@ -55,12 +56,14 @@ export const siteLabel = (hostname: string): string => hostname.toLowerCase().re
|
|
|
55
56
|
|
|
56
57
|
/** The address a sites template gives `hostname`, or null where the template is not one or the name makes no address
|
|
57
58
|
* (a label over 63 characters). */
|
|
58
|
-
export function siteUrlOf(template: string, hostname: string): string | null {
|
|
59
|
+
export function siteUrlOf(template: string, hostname: string, browser?: string): string | null {
|
|
59
60
|
const host = hostname.toLowerCase();
|
|
61
|
+
if (browser) { try { assertBrowserName(browser); } catch { return null; } }
|
|
62
|
+
const label = `${browser ? `${browser}--` : ''}${siteLabel(host)}`;
|
|
60
63
|
if (!/^[a-z0-9.-]+$/.test(host)) return null;
|
|
61
64
|
// a one-label site is never an IDN's (`xn--…` would be read as punycode, and is no address)
|
|
62
|
-
const filled = /^https?:\/\/\{host\}\.[A-Za-z0-9.-]+(:\d+)?$/.test(template) ? template.replace('{host}', host)
|
|
63
|
-
: /^https?:\/\/\{site\}--[A-Za-z0-9.-]+(:\d+)?$/.test(template) && !host.startsWith('xn--') ? template.replace('{site}',
|
|
65
|
+
const filled = /^https?:\/\/\{host\}\.[A-Za-z0-9.-]+(:\d+)?$/.test(template) ? template.replace('{host}', browser ? label : host)
|
|
66
|
+
: /^https?:\/\/\{site\}--[A-Za-z0-9.-]+(:\d+)?$/.test(template) && !host.startsWith('xn--') ? template.replace('{site}', label) : null;
|
|
64
67
|
try { return filled && new URL(filled).hostname.split('.').every((l) => l.length > 0 && l.length <= 63) ? filled : null; } catch { return null; }
|
|
65
68
|
}
|
|
66
69
|
|
|
@@ -69,7 +72,9 @@ export function siteUrlOf(template: string, hostname: string): string | null {
|
|
|
69
72
|
* mints its own URLs from twinPublicBase. */
|
|
70
73
|
export function twinSiteUrl(request: Request, hostname: string): string {
|
|
71
74
|
const at = request.headers.get(TWIN_SITES_HEADER);
|
|
72
|
-
|
|
75
|
+
let browser = request.headers.get('x-volter-world-browser') ?? undefined;
|
|
76
|
+
if (browser) { try { assertBrowserName(browser); } catch { browser = undefined; } }
|
|
77
|
+
return (at ? siteUrlOf(at, hostname, browser) : null) ?? `https://${hostname.toLowerCase()}`;
|
|
73
78
|
}
|
|
74
79
|
|
|
75
80
|
/** A twin's BYTE-STREAM door: a pack whose clients speak a TCP protocol (SMTP, the MySQL wire) serves
|
package/vendor-hosts.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
// THE VENDOR HOST TABLE — which vendor's twin serves a hostname (and, where two vendors share a host, which path), the
|
|
3
|
-
//
|
|
3
|
+
// Node process's loaded facts. The pure compiler and resolver are host-routing.cjs; this loader reads Node facts.
|
|
4
|
+
// The injector (inject.cjs) routes by the table; the
|
|
4
5
|
// application route (app-route.cjs) never answers a name it gives a vendor, in the injector or in a twin's delivery.
|
|
5
|
-
// Moved out of inject.cjs unchanged (2026-09-27).
|
|
6
6
|
// ── PATH-AWARE DISAMBIGUATION (the shared-host case) ─────────────────────────────────────────
|
|
7
7
|
// A predicate is called as `(hostname, pathname)`. `pathname` is OPTIONAL and is `undefined`
|
|
8
8
|
// wherever the caller genuinely does not have one yet — most importantly the proxy's CONNECT
|
|
@@ -25,108 +25,12 @@
|
|
|
25
25
|
// `browserassets` and `googlefavicon`; kernel packages carry no pack descriptor). Every vendor
|
|
26
26
|
// pack's hosts live on its descriptor as DATA — host | suffix | hostPattern, pathPattern,
|
|
27
27
|
// exclude, key — compiled from pack-facts.json.
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
h === 'connect.facebook.net' ||
|
|
35
|
-
h === 'snap.licdn.com' ||
|
|
36
|
-
h === 'px.ads.linkedin.com' ||
|
|
37
|
-
h === 'static.hotjar.com' ||
|
|
38
|
-
h === 'fonts.googleapis.com' ||
|
|
39
|
-
h === 'fonts.gstatic.com' ||
|
|
40
|
-
h === 'api.fontshare.com' ||
|
|
41
|
-
h === 'images.subscribe.dev' ||
|
|
42
|
-
h === 'www.youtube.com' ||
|
|
43
|
-
h === 'www.youtube-nocookie.com' ||
|
|
44
|
-
h === 'i.ytimg.com',
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
// descriptor-first migration (architecture.md, "The descriptor"): packs now declare their hosts as DATA on their descriptor
|
|
48
|
-
// (`hosts` on TwinPack), compiled into the committed pack-facts artifact — a plain JSON this
|
|
49
|
-
// preloaded, dependency-free module can `require` natively. The hand table above shrinks toward
|
|
50
|
-
// empty as entries move; a vendor present in both homes throws (dual declaration is the drift
|
|
51
|
-
// this migration ends, and a broken checkout should refuse to inject rather than half-route).
|
|
52
|
-
/** The keys each pack's compiled rules answer under, by vendor: a pack's own facts learned later (addPackHosts) replace
|
|
53
|
-
* that vendor's rules, never another's. */
|
|
54
|
-
const COMPILED = new Map();
|
|
55
|
-
/** The hand table's keys, before any pack's rules: a pack installed later replaces its hand entry in place (keeping its
|
|
56
|
-
* position, which decides who answers a shared host first), where the built-in facts may not declare one twice. */
|
|
57
|
-
const HAND = new Set(Object.keys(VENDOR_HOSTS));
|
|
58
|
-
/** One host rule as a predicate over (hostname, pathname?): its one selector (host | suffix | hostPattern) and its
|
|
59
|
-
* pathPattern, a path left out matching any. */
|
|
60
|
-
function compileHostRule(rule, where) {
|
|
61
|
-
const selectors = ['host', 'suffix', 'hostPattern'].filter((k) => rule[k] !== undefined).length;
|
|
62
|
-
if (selectors !== 1) throw new Error(`inject: ${where} rule ${JSON.stringify(rule)} — exactly one of host | suffix | hostPattern (pack-facts.json is hand-edited or stale)`);
|
|
63
|
-
const hostRe = rule.hostPattern === undefined ? null : new RegExp(rule.hostPattern);
|
|
64
|
-
const pathRe = rule.pathPattern === undefined ? null : new RegExp(rule.pathPattern);
|
|
65
|
-
return (h, p) =>
|
|
66
|
-
(rule.host !== undefined ? h === rule.host : rule.suffix !== undefined ? h.endsWith(rule.suffix) : hostRe.test(h))
|
|
67
|
-
&& (pathRe === null || p === undefined || pathRe.test(p));
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/** A pack's host rules (its descriptor's `hosts`) read as the injector reads them: `names(host)`, whether any include
|
|
71
|
-
* rule's selector names the host, whatever the path; `takes(host, path)`, whether the request is the pack's (under
|
|
72
|
-
* one of its keys, an include matches and no exclude does). The content route at a World's place holds a
|
|
73
|
-
* `<base>/@<host>/<path>` to it (pack-fetch.ts). */
|
|
74
|
-
function hostRules(rules) {
|
|
75
|
-
const byKey = new Map();
|
|
76
|
-
for (const rule of rules || []) {
|
|
77
|
-
const key = rule.key === undefined ? '' : rule.key;
|
|
78
|
-
if (!byKey.has(key)) byKey.set(key, []);
|
|
79
|
-
byKey.get(key).push(rule);
|
|
80
|
-
}
|
|
81
|
-
const keys = [...byKey.values()].map((keyRules) => ({
|
|
82
|
-
includes: keyRules.filter((r) => r.exclude !== true).map((r) => compileHostRule(r, 'a pack')),
|
|
83
|
-
excludes: keyRules.filter((r) => r.exclude === true).map((r) => compileHostRule(r, 'a pack')),
|
|
84
|
-
}));
|
|
85
|
-
return {
|
|
86
|
-
names: (h) => keys.some((k) => k.includes.some((m) => m(h))),
|
|
87
|
-
takes: (h, p) => keys.some((k) => k.includes.some((m) => m(h, p)) && !k.excludes.some((m) => m(h, p))),
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function compilePackHosts(packs, overlay) {
|
|
92
|
-
for (const vendor of Object.keys(packs)) {
|
|
93
|
-
const rules = packs[vendor].hosts;
|
|
94
|
-
if (!rules || rules.length === 0) continue;
|
|
95
|
-
for (const key of COMPILED.get(vendor) || []) delete VENDOR_HOSTS[key];
|
|
96
|
-
COMPILED.delete(vendor);
|
|
97
|
-
if (VENDOR_HOSTS[vendor] && !(overlay && HAND.has(vendor))) {
|
|
98
|
-
throw new Error(`inject: vendor "${vendor}" declares hosts on its pack descriptor AND in the hand VENDOR_HOSTS table — one home per fact; delete the hand entry.`);
|
|
99
|
-
}
|
|
100
|
-
// Rules group by `key` (default: the vendor id) — aws's descriptor declares the s3 and
|
|
101
|
-
// secretsmanager routing identities its twin answers under. A key matches when ANY include
|
|
102
|
-
// rule matches AND NO exclude rule matches.
|
|
103
|
-
const byKey = new Map();
|
|
104
|
-
for (const rule of rules) {
|
|
105
|
-
const key = rule.key === undefined ? vendor : rule.key;
|
|
106
|
-
if (!byKey.has(key)) byKey.set(key, []);
|
|
107
|
-
byKey.get(key).push(rule);
|
|
108
|
-
}
|
|
109
|
-
for (const [key, keyRules] of byKey) {
|
|
110
|
-
if (VENDOR_HOSTS[key] && !(overlay && HAND.has(key))) {
|
|
111
|
-
throw new Error(`inject: key "${key}" (pack ${vendor}) is declared twice — on this descriptor and in the hand VENDOR_HOSTS table or another pack's descriptor; a key has one home.`);
|
|
112
|
-
}
|
|
113
|
-
const compile = (rule) => compileHostRule(rule, `key "${key}" (pack ${vendor})`);
|
|
114
|
-
const includes = keyRules.filter((r) => r.exclude !== true).map(compile);
|
|
115
|
-
const excludes = keyRules.filter((r) => r.exclude === true).map(compile);
|
|
116
|
-
VENDOR_HOSTS[key] = (h, p) => includes.some((m) => m(h, p)) && !excludes.some((m) => m(h, p));
|
|
117
|
-
COMPILED.set(vendor, [...(COMPILED.get(vendor) || []), key]);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
{
|
|
122
|
-
const facts = require('./pack-facts.cjs').packFacts();
|
|
123
|
-
const installed = new Set(facts.installed || []);
|
|
124
|
-
compilePackHosts(Object.fromEntries(Object.entries(facts.packs).filter(([vendor]) => !installed.has(vendor))), false);
|
|
125
|
-
compilePackHosts(Object.fromEntries(Object.entries(facts.packs).filter(([vendor]) => installed.has(vendor))), true);
|
|
126
|
-
}
|
|
127
|
-
/** Rules from packs' facts learned after this module loaded (a runtime told the facts of the World it boots): each
|
|
128
|
-
* vendor's replace its earlier rules. */
|
|
129
|
-
function addPackHosts(packs) { compilePackHosts(packs || {}, true); }
|
|
28
|
+
const routing = require('./host-routing.cjs');
|
|
29
|
+
const facts = require('./pack-facts.cjs').packFacts();
|
|
30
|
+
const table = routing.createHostTable(facts.packs, facts.installed);
|
|
31
|
+
const VENDOR_HOSTS = table.hosts;
|
|
32
|
+
const hostRules = routing.hostRules;
|
|
33
|
+
function addPackHosts(packs) { table.addPackHosts(packs); }
|
|
130
34
|
|
|
131
35
|
/** Whether any vendor's host rule names `host` (at the host level, whatever the path), whether or not its twin runs. */
|
|
132
36
|
function isVendorHost(host) {
|
|
@@ -166,4 +70,8 @@ function twinOrigins(env) {
|
|
|
166
70
|
return map;
|
|
167
71
|
}
|
|
168
72
|
|
|
169
|
-
|
|
73
|
+
/** Resolve using this Node process's loaded facts. */
|
|
74
|
+
function resolveTwinHost(hostname, map, pathname, claimed) {
|
|
75
|
+
return routing.resolveTwinHost(VENDOR_HOSTS, hostname, map, pathname, claimed);
|
|
76
|
+
}
|
|
77
|
+
module.exports = { resolveTwinHost, VENDOR_HOSTS, hostRules, addPackHosts, isVendorHost, vendorsOfHost, twinEnvStem, twinOrigins };
|
package/vendor-hosts.d.cts
CHANGED
|
@@ -9,3 +9,6 @@ export function twinOrigins(env: Readonly<Record<string, string | undefined>>):
|
|
|
9
9
|
/** A pack's host rules (its descriptor's `hosts`, as data) read as the injector reads them: whether any include names a
|
|
10
10
|
* host whatever the path, and whether a request to a host and path is the pack's. */
|
|
11
11
|
export function hostRules(rules: ReadonlyArray<{ host?: string; suffix?: string; hostPattern?: string; pathPattern?: string; key?: string; exclude?: true }> | undefined): { names(hostname: string): boolean; takes(hostname: string, pathname: string): boolean };
|
|
12
|
+
|
|
13
|
+
/** Resolve an active twin exactly as the proxy, first declared host/path rules, then claimed hosts. */
|
|
14
|
+
export function resolveTwinHost(hostname: string, map: Readonly<Record<string, string>>, pathname?: string, claimed?: Readonly<Record<string, ReadonlySet<string> | (() => ReadonlySet<string>)>>): { vendor: string; origin: string } | null;
|