@volter/world-core 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +29 -0
- package/app-route.cjs +154 -0
- package/app-route.d.cts +7 -0
- package/attach.cjs +80 -0
- package/dist/app-route.cjs +154 -0
- package/dist/app-route.d.cts +7 -0
- package/dist/attach.cjs +80 -0
- package/dist/generated/pack-facts.json +4306 -0
- package/dist/inject.cjs +1097 -0
- package/dist/network-policy.cjs +92 -0
- package/dist/network-policy.d.cts +10 -0
- package/dist/src/actions.d.ts +276 -0
- package/dist/src/actions.js +436 -0
- package/dist/src/ancestry.d.ts +22 -0
- package/dist/src/ancestry.js +238 -0
- package/dist/src/args.d.ts +3 -0
- package/dist/src/args.js +12 -0
- package/dist/src/blob-store.d.ts +55 -0
- package/dist/src/blob-store.js +186 -0
- package/dist/src/brand-tokens.d.ts +2 -0
- package/dist/src/brand-tokens.js +17 -0
- package/dist/src/changeset.d.ts +431 -0
- package/dist/src/changeset.js +0 -0
- package/dist/src/client-bundle.d.ts +1 -0
- package/dist/src/client-bundle.js +28 -0
- package/dist/src/credential.d.ts +38 -0
- package/dist/src/credential.js +114 -0
- package/dist/src/derived-core.d.ts +452 -0
- package/dist/src/derived-core.js +782 -0
- package/dist/src/derived.d.ts +84 -0
- package/dist/src/derived.js +122 -0
- package/dist/src/emit.d.ts +106 -0
- package/dist/src/emit.js +157 -0
- package/dist/src/executor.d.ts +120 -0
- package/dist/src/executor.js +387 -0
- package/dist/src/file-response.d.ts +3 -0
- package/dist/src/file-response.js +22 -0
- package/dist/src/fork.d.ts +26 -0
- package/dist/src/fork.js +68 -0
- package/dist/src/git/history.d.ts +36 -0
- package/dist/src/git/history.js +298 -0
- package/dist/src/git/index.d.ts +6 -0
- package/dist/src/git/index.js +6 -0
- package/dist/src/git/inflate.d.ts +11 -0
- package/dist/src/git/inflate.js +194 -0
- package/dist/src/git/objects.d.ts +64 -0
- package/dist/src/git/objects.js +161 -0
- package/dist/src/git/pack.d.ts +14 -0
- package/dist/src/git/pack.js +199 -0
- package/dist/src/git/refs.d.ts +19 -0
- package/dist/src/git/refs.js +35 -0
- package/dist/src/git/smart-http.d.ts +45 -0
- package/dist/src/git/smart-http.js +223 -0
- package/dist/src/hash.d.ts +38 -0
- package/dist/src/hash.js +48 -0
- package/dist/src/head.d.ts +140 -0
- package/dist/src/head.js +313 -0
- package/dist/src/history.d.ts +76 -0
- package/dist/src/history.js +322 -0
- package/dist/src/index.d.ts +73 -0
- package/dist/src/index.js +98 -0
- package/dist/src/lifecycle.d.ts +1 -0
- package/dist/src/lifecycle.js +8 -0
- package/dist/src/log.d.ts +254 -0
- package/dist/src/log.js +801 -0
- package/dist/src/mirror-shell.d.ts +2 -0
- package/dist/src/mirror-shell.js +13 -0
- package/dist/src/observe.d.ts +49 -0
- package/dist/src/observe.js +148 -0
- package/dist/src/pack-assets.d.ts +30 -0
- package/dist/src/pack-assets.js +88 -0
- package/dist/src/packRegistry.d.ts +374 -0
- package/dist/src/packRegistry.js +142 -0
- package/dist/src/placeholder-remote.d.ts +22 -0
- package/dist/src/placeholder-remote.js +86 -0
- package/dist/src/proxy.d.ts +25 -0
- package/dist/src/proxy.js +155 -0
- package/dist/src/rateBudget.d.ts +367 -0
- package/dist/src/rateBudget.js +925 -0
- package/dist/src/references.d.ts +18 -0
- package/dist/src/references.js +27 -0
- package/dist/src/remote-execute.d.ts +22 -0
- package/dist/src/remote-execute.js +1 -0
- package/dist/src/resource-blob.d.ts +10 -0
- package/dist/src/resource-blob.js +56 -0
- package/dist/src/scenario.d.ts +197 -0
- package/dist/src/scenario.js +425 -0
- package/dist/src/schemas.d.ts +78 -0
- package/dist/src/schemas.js +50 -0
- package/dist/src/serve-http.d.ts +48 -0
- package/dist/src/serve-http.js +340 -0
- package/dist/src/serve.d.ts +147 -0
- package/dist/src/serve.js +507 -0
- package/dist/src/shared-blob-index.d.ts +4 -0
- package/dist/src/shared-blob-index.js +126 -0
- package/dist/src/state-system.d.ts +70 -0
- package/dist/src/state-system.js +90 -0
- package/dist/src/storage.d.ts +101 -0
- package/dist/src/storage.js +337 -0
- package/dist/src/twin-fetch.d.ts +64 -0
- package/dist/src/twin-fetch.js +91 -0
- package/dist/src/types.d.ts +40 -0
- package/dist/src/types.js +1 -0
- package/dist/src/v1-removed.d.ts +159 -0
- package/dist/src/v1-removed.js +124 -0
- package/dist/src/volter-home.d.ts +5 -0
- package/dist/src/volter-home.js +10 -0
- package/dist/src/world-clock.d.ts +4 -0
- package/dist/src/world-clock.js +32 -0
- package/dist/src/world-env.d.ts +3 -0
- package/dist/src/world-env.js +22 -0
- package/dist/src/world-store-sql.d.ts +27 -0
- package/dist/src/world-store-sql.js +86 -0
- package/dist/src/world-store.d.ts +168 -0
- package/dist/src/world-store.js +475 -0
- package/dist/src/worldConfig.d.ts +9 -0
- package/dist/src/worldConfig.js +17 -0
- package/dist/stream-bridge.cjs +80 -0
- package/dist/vendor-hosts.cjs +200 -0
- package/generated/pack-facts.json +4306 -0
- package/inject.cjs +1097 -0
- package/network-policy.cjs +92 -0
- package/network-policy.d.cts +10 -0
- package/package.json +103 -0
- package/src/actions.ts +564 -0
- package/src/ancestry.ts +213 -0
- package/src/args.ts +14 -0
- package/src/blob-store.ts +185 -0
- package/src/brand-tokens.ts +17 -0
- package/src/changeset.ts +1032 -0
- package/src/client-bundle.ts +29 -0
- package/src/credential.ts +140 -0
- package/src/derived-core.ts +1004 -0
- package/src/derived.ts +176 -0
- package/src/emit.ts +242 -0
- package/src/executor.ts +431 -0
- package/src/file-response.ts +22 -0
- package/src/fork.ts +89 -0
- package/src/git/history.ts +177 -0
- package/src/git/index.ts +6 -0
- package/src/git/inflate.ts +125 -0
- package/src/git/objects.ts +110 -0
- package/src/git/pack.ts +105 -0
- package/src/git/refs.ts +25 -0
- package/src/git/smart-http.ts +149 -0
- package/src/hash.ts +66 -0
- package/src/head.ts +318 -0
- package/src/history.ts +246 -0
- package/src/index.ts +323 -0
- package/src/lifecycle.ts +8 -0
- package/src/log.ts +793 -0
- package/src/mirror-shell.ts +15 -0
- package/src/observe.ts +130 -0
- package/src/pack-assets.ts +81 -0
- package/src/packRegistry.ts +408 -0
- package/src/placeholder-remote.ts +81 -0
- package/src/proxy.ts +183 -0
- package/src/rateBudget.ts +1115 -0
- package/src/references.ts +46 -0
- package/src/remote-execute.ts +26 -0
- package/src/resource-blob.ts +57 -0
- package/src/scenario.ts +479 -0
- package/src/schemas.ts +56 -0
- package/src/serve-http.ts +299 -0
- package/src/serve.ts +618 -0
- package/src/shared-blob-index.ts +108 -0
- package/src/state-system.ts +115 -0
- package/src/storage.ts +407 -0
- package/src/twin-fetch.ts +147 -0
- package/src/types.ts +50 -0
- package/src/v1-removed.ts +172 -0
- package/src/volter-home.ts +11 -0
- package/src/world-clock.ts +33 -0
- package/src/world-env.ts +18 -0
- package/src/world-store-sql.ts +118 -0
- package/src/world-store.ts +572 -0
- package/src/worldConfig.ts +27 -0
- package/stream-bridge.cjs +80 -0
- package/vendor-hosts.cjs +200 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const WORLD_NETWORK_POLICY_ENV = 'VOLTER_WORLD_NETWORK_POLICY';
|
|
4
|
+
|
|
5
|
+
function object(value, keys, label) {
|
|
6
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)
|
|
7
|
+
|| Object.keys(value).some(key => !keys.includes(key))) {
|
|
8
|
+
throw new Error(`${label} has an invalid shape`);
|
|
9
|
+
}
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function origins(value) {
|
|
14
|
+
if (!Array.isArray(value) || value.length > 256) throw new Error('World network egress must be an array of at most 256 exact HTTPS origins');
|
|
15
|
+
const normalized = value.map(origin => {
|
|
16
|
+
if (typeof origin !== 'string' || origin.length > 2048) throw new Error('World network egress origins must be strings');
|
|
17
|
+
let url;
|
|
18
|
+
try { url = new URL(origin); } catch { throw new Error(`Invalid World network origin: ${origin}`); }
|
|
19
|
+
if (url.protocol !== 'https:' || url.origin !== origin || url.username || url.password
|
|
20
|
+
|| !/^[a-z0-9](?:[a-z0-9.-]*[a-z0-9])?$/.test(url.hostname)
|
|
21
|
+
|| url.hostname.split('.').some(label => !label || label.length > 63 || label.startsWith('-') || label.endsWith('-'))
|
|
22
|
+
|| /^[\d.]+$/.test(url.hostname) || url.hostname === 'localhost' || url.hostname.endsWith('.localhost')) {
|
|
23
|
+
throw new Error(`World network requires an exact canonical HTTPS origin: ${origin}`);
|
|
24
|
+
}
|
|
25
|
+
return origin;
|
|
26
|
+
});
|
|
27
|
+
return Object.freeze([...new Set(normalized)].sort());
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function normalizeWorldNetwork(value) {
|
|
31
|
+
const network = object(value, ['egress'], 'World network');
|
|
32
|
+
return Object.freeze({ egress: origins(network.egress) });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function createWorldNetworkPolicy(world, network) {
|
|
36
|
+
if (typeof world !== 'string' || !world || world.length > 256) throw new Error('World network policy requires its World identity');
|
|
37
|
+
return Object.freeze({ version: 1, world, egress: normalizeWorldNetwork(network).egress });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function parseWorldNetworkPolicy(value) {
|
|
41
|
+
const policy = object(value, ['version', 'world', 'egress'], 'World network policy');
|
|
42
|
+
if (policy.version !== 1) throw new Error('Unsupported World network policy version');
|
|
43
|
+
return createWorldNetworkPolicy(policy.world, { egress: policy.egress });
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function worldNetworkPolicyFromEnv(env) {
|
|
47
|
+
const serialized = env[WORLD_NETWORK_POLICY_ENV];
|
|
48
|
+
if (serialized === undefined) return undefined;
|
|
49
|
+
if (typeof serialized !== 'string' || serialized.length > 65536) throw new Error('Invalid published World network policy');
|
|
50
|
+
const policy = parseWorldNetworkPolicy(JSON.parse(serialized));
|
|
51
|
+
if (!env.VOLTER_WORLD || policy.world !== env.VOLTER_WORLD) throw new Error('World network policy does not belong to the attached World');
|
|
52
|
+
return policy;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function allowsWorldNetworkEgress(policy, value) {
|
|
56
|
+
let url;
|
|
57
|
+
try { url = new URL(String(value)); } catch { return false; }
|
|
58
|
+
return url.protocol === 'https:' && !url.username && !url.password && policy.egress.includes(url.origin);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Loopback and private addresses stay inside the machine a World runs on: never refused. */
|
|
62
|
+
function isWorldInternalHost(hostname) {
|
|
63
|
+
const h = String(hostname || '').toLowerCase().replace(/^\[|\]$/g, '');
|
|
64
|
+
if (!h) return true;
|
|
65
|
+
if (h === 'localhost' || h.endsWith('.localhost') || h.endsWith('.test') || h === '0.0.0.0' || h === '::1') return true;
|
|
66
|
+
const v4 = /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/.exec(h);
|
|
67
|
+
if (v4) {
|
|
68
|
+
const a = Number(v4[1]); const b = Number(v4[2]);
|
|
69
|
+
return a === 127 || a === 10 || (a === 172 && b >= 16 && b <= 31) || (a === 192 && b === 168) || (a === 169 && b === 254);
|
|
70
|
+
}
|
|
71
|
+
return h.includes(':') && (h.startsWith('fc') || h.startsWith('fd') || h.startsWith('fe80:'));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Why this World refuses an outbound request to `value`, or null when it allows it. The one rule
|
|
76
|
+
* every enforcement point applies: the injector for application processes, and a twin's own
|
|
77
|
+
* World-internal outbound calls (a queue delivering to its destination), which run in a host the
|
|
78
|
+
* injector does not attach to. Internal addresses pass; strict egress refuses everything else; a
|
|
79
|
+
* published network policy refuses what it does not list. An unreadable policy refuses.
|
|
80
|
+
*/
|
|
81
|
+
function worldEgressRefusal(value, env = process.env) {
|
|
82
|
+
let url;
|
|
83
|
+
try { url = new URL(String(value)); } catch { return `unparseable destination ${String(value)}`; }
|
|
84
|
+
if (isWorldInternalHost(url.hostname)) return null;
|
|
85
|
+
if (env.VOLTER_TWIN_STRICT_EGRESS === '1' || env.VOLTER_TWIN_STRICT_EGRESS === 'true') return `sealed World refuses untwinned host ${url.hostname}`;
|
|
86
|
+
let policy;
|
|
87
|
+
try { policy = worldNetworkPolicyFromEnv(env); } catch (error) { return `World network policy unreadable (${error.message}); refusing ${url.hostname}`; }
|
|
88
|
+
if (policy !== undefined && !allowsWorldNetworkEgress(policy, url)) return `World network policy does not allow ${url.origin}`;
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
module.exports = { isWorldInternalHost, worldEgressRefusal, WORLD_NETWORK_POLICY_ENV, normalizeWorldNetwork, createWorldNetworkPolicy, parseWorldNetworkPolicy, worldNetworkPolicyFromEnv, allowsWorldNetworkEgress };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface WorldNetwork { readonly egress: readonly string[] }
|
|
2
|
+
export interface WorldNetworkPolicy extends WorldNetwork { readonly version: 1; readonly world: string }
|
|
3
|
+
export const WORLD_NETWORK_POLICY_ENV: 'VOLTER_WORLD_NETWORK_POLICY';
|
|
4
|
+
export function normalizeWorldNetwork(value: unknown): WorldNetwork;
|
|
5
|
+
export function createWorldNetworkPolicy(world: string, network: WorldNetwork): WorldNetworkPolicy;
|
|
6
|
+
export function parseWorldNetworkPolicy(value: unknown): WorldNetworkPolicy;
|
|
7
|
+
export function worldNetworkPolicyFromEnv(env: Readonly<Record<string, string | undefined>>): WorldNetworkPolicy | undefined;
|
|
8
|
+
export function allowsWorldNetworkEgress(policy: WorldNetworkPolicy, value: string | URL): boolean;
|
|
9
|
+
export function isWorldInternalHost(hostname: string): boolean;
|
|
10
|
+
export function worldEgressRefusal(value: string | URL, env?: Readonly<Record<string, string | undefined>>): string | null;
|
package/package.json
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@volter/world-core",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "The kernel of Volter World: one log per twin, branches as pointers, checkpoints, the fold that keeps a twin current, the head that performs a write against the vendor, references, and the git plane. A twin package builds on it; the runtime serves it.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"twin",
|
|
7
|
+
"local",
|
|
8
|
+
"mock",
|
|
9
|
+
"mirror",
|
|
10
|
+
"simulator",
|
|
11
|
+
"fixtures",
|
|
12
|
+
"testing",
|
|
13
|
+
"sdk",
|
|
14
|
+
"api",
|
|
15
|
+
"localstack",
|
|
16
|
+
"event-sourcing",
|
|
17
|
+
"kernel"
|
|
18
|
+
],
|
|
19
|
+
"author": "Volter (https://github.com/volter-ai)",
|
|
20
|
+
"license": "Apache-2.0",
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"inject.cjs",
|
|
26
|
+
"attach.cjs",
|
|
27
|
+
"stream-bridge.cjs",
|
|
28
|
+
"network-policy.cjs",
|
|
29
|
+
"network-policy.d.cts",
|
|
30
|
+
"app-route.cjs",
|
|
31
|
+
"vendor-hosts.cjs",
|
|
32
|
+
"app-route.d.cts",
|
|
33
|
+
"generated",
|
|
34
|
+
"src",
|
|
35
|
+
"client",
|
|
36
|
+
"test-fixtures",
|
|
37
|
+
"README.md",
|
|
38
|
+
"LICENSE",
|
|
39
|
+
"!test-fixtures/*.SOURCE.md",
|
|
40
|
+
"!**/*.test.ts",
|
|
41
|
+
"!**/*.test.tsx",
|
|
42
|
+
"dist"
|
|
43
|
+
],
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "git+https://github.com/volter-ai/twin.git",
|
|
47
|
+
"directory": "packages/world-core"
|
|
48
|
+
},
|
|
49
|
+
"homepage": "https://github.com/volter-ai/twin/tree/main/packages/world-core#readme",
|
|
50
|
+
"type": "module",
|
|
51
|
+
"exports": {
|
|
52
|
+
".": {
|
|
53
|
+
"types": "./dist/src/index.d.ts",
|
|
54
|
+
"default": "./dist/src/index.js"
|
|
55
|
+
},
|
|
56
|
+
"./args": {
|
|
57
|
+
"types": "./dist/src/args.d.ts",
|
|
58
|
+
"default": "./dist/src/args.js"
|
|
59
|
+
},
|
|
60
|
+
"./schemas": {
|
|
61
|
+
"types": "./dist/src/schemas.d.ts",
|
|
62
|
+
"default": "./dist/src/schemas.js"
|
|
63
|
+
},
|
|
64
|
+
"./inject": "./inject.cjs",
|
|
65
|
+
"./attach": "./attach.cjs",
|
|
66
|
+
"./stream-bridge": "./stream-bridge.cjs",
|
|
67
|
+
"./network-policy": {
|
|
68
|
+
"types": "./network-policy.d.cts",
|
|
69
|
+
"default": "./network-policy.cjs"
|
|
70
|
+
},
|
|
71
|
+
"./app-route": {
|
|
72
|
+
"types": "./app-route.d.cts",
|
|
73
|
+
"default": "./app-route.cjs"
|
|
74
|
+
},
|
|
75
|
+
"./vendor-hosts": "./vendor-hosts.cjs",
|
|
76
|
+
"./generated/pack-facts.json": "./generated/pack-facts.json",
|
|
77
|
+
"./lifecycle": {
|
|
78
|
+
"types": "./dist/src/lifecycle.d.ts",
|
|
79
|
+
"default": "./dist/src/lifecycle.js"
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
"scripts": {
|
|
83
|
+
"cli": "bun run src/cli.ts",
|
|
84
|
+
"test": "bun test src/*.test.ts",
|
|
85
|
+
"typecheck": "tsc --noEmit",
|
|
86
|
+
"build": "node ../../scripts/publish/build.mjs",
|
|
87
|
+
"prepack": "node ../../scripts/publish/prepare-publish.mjs prepack",
|
|
88
|
+
"postpack": "node ../../scripts/publish/prepare-publish.mjs postpack"
|
|
89
|
+
},
|
|
90
|
+
"dependencies": {
|
|
91
|
+
"zod": "^4.4.2",
|
|
92
|
+
"ws": "^8.18.0"
|
|
93
|
+
},
|
|
94
|
+
"devDependencies": {
|
|
95
|
+
"@types/bun": "^1.2.20",
|
|
96
|
+
"@types/node": "^24.0.0",
|
|
97
|
+
"typescript": "^5.9.0",
|
|
98
|
+
"@types/ws": "^8.5.0"
|
|
99
|
+
},
|
|
100
|
+
"engines": {
|
|
101
|
+
"node": ">=22.3"
|
|
102
|
+
}
|
|
103
|
+
}
|