@brud/kernel 0.0.0-stage → 0.0.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/LICENSE +201 -0
- package/README.md +63 -2
- package/dist/index.d.ts +15 -0
- package/dist/index.js +13 -0
- package/dist/serviceModules/events.d.ts +1 -0
- package/dist/serviceModules/events.js +1 -0
- package/dist/serviceModules/exposedApiRegistry.d.ts +1 -0
- package/dist/serviceModules/exposedApiRegistry.js +1 -0
- package/dist/serviceModules/identityRegistry.d.ts +1 -0
- package/dist/serviceModules/identityRegistry.js +1 -0
- package/dist/serviceModules/interception.d.ts +1 -0
- package/dist/serviceModules/interception.js +1 -0
- package/dist/serviceModules/parser.d.ts +1 -0
- package/dist/serviceModules/parser.js +1 -0
- package/dist/serviceModules/router.d.ts +1 -0
- package/dist/serviceModules/router.js +1 -0
- package/dist/serviceModules/wasmCage.d.ts +1 -0
- package/dist/serviceModules/wasmCage.js +1 -0
- package/dist/services/Events/contracts/IEventsService.d.ts +64 -0
- package/dist/services/Events/contracts/IEventsService.js +1 -0
- package/dist/services/Events/contracts/errors.d.ts +31 -0
- package/dist/services/Events/contracts/errors.js +40 -0
- package/dist/services/Events/contracts/index.d.ts +3 -0
- package/dist/services/Events/contracts/index.js +3 -0
- package/dist/services/Events/contracts/tokens.d.ts +2 -0
- package/dist/services/Events/contracts/tokens.js +2 -0
- package/dist/services/Events/descriptor/EventsDescriptor.d.ts +9 -0
- package/dist/services/Events/descriptor/EventsDescriptor.js +56 -0
- package/dist/services/Events/descriptor/tokens.d.ts +1 -0
- package/dist/services/Events/descriptor/tokens.js +1 -0
- package/dist/services/Events/index.d.ts +4 -0
- package/dist/services/Events/index.js +4 -0
- package/dist/services/Events/orchestrator/EventsService.d.ts +51 -0
- package/dist/services/Events/orchestrator/EventsService.js +339 -0
- package/dist/services/Events/orchestrator/index.d.ts +2 -0
- package/dist/services/Events/orchestrator/index.js +2 -0
- package/dist/services/Events/orchestrator/limits.d.ts +22 -0
- package/dist/services/Events/orchestrator/limits.js +33 -0
- package/dist/services/Events/serviceModule.d.ts +2 -0
- package/dist/services/Events/serviceModule.js +5 -0
- package/dist/services/ExposedApiRegistry/contracts/IExposedApiRegistry.d.ts +44 -0
- package/dist/services/ExposedApiRegistry/contracts/IExposedApiRegistry.js +1 -0
- package/dist/services/ExposedApiRegistry/contracts/errors.d.ts +132 -0
- package/dist/services/ExposedApiRegistry/contracts/errors.js +195 -0
- package/dist/services/ExposedApiRegistry/contracts/index.d.ts +9 -0
- package/dist/services/ExposedApiRegistry/contracts/index.js +4 -0
- package/dist/services/ExposedApiRegistry/contracts/policy.d.ts +90 -0
- package/dist/services/ExposedApiRegistry/contracts/policy.js +169 -0
- package/dist/services/ExposedApiRegistry/contracts/registrant.d.ts +37 -0
- package/dist/services/ExposedApiRegistry/contracts/registrant.js +36 -0
- package/dist/services/ExposedApiRegistry/contracts/types.d.ts +112 -0
- package/dist/services/ExposedApiRegistry/contracts/types.js +73 -0
- package/dist/services/ExposedApiRegistry/descriptor/ExposedApiRegistryDescriptor.d.ts +44 -0
- package/dist/services/ExposedApiRegistry/descriptor/ExposedApiRegistryDescriptor.js +58 -0
- package/dist/services/ExposedApiRegistry/descriptor/tokens.d.ts +8 -0
- package/dist/services/ExposedApiRegistry/descriptor/tokens.js +8 -0
- package/dist/services/ExposedApiRegistry/index.d.ts +6 -0
- package/dist/services/ExposedApiRegistry/index.js +5 -0
- package/dist/services/ExposedApiRegistry/orchestrator/ExposedApiRegistryService.d.ts +61 -0
- package/dist/services/ExposedApiRegistry/orchestrator/ExposedApiRegistryService.js +407 -0
- package/dist/services/ExposedApiRegistry/orchestrator/index.d.ts +2 -0
- package/dist/services/ExposedApiRegistry/orchestrator/index.js +1 -0
- package/dist/services/ExposedApiRegistry/serviceModule.d.ts +10 -0
- package/dist/services/ExposedApiRegistry/serviceModule.js +20 -0
- package/dist/services/ExposedApiRegistry/storage/protection.d.ts +21 -0
- package/dist/services/ExposedApiRegistry/storage/protection.js +35 -0
- package/dist/services/ExposedApiRegistry/storage/scopeRecord.d.ts +45 -0
- package/dist/services/ExposedApiRegistry/storage/scopeRecord.js +178 -0
- package/dist/services/IdentityRegistry/contracts/errors.d.ts +88 -0
- package/dist/services/IdentityRegistry/contracts/errors.js +128 -0
- package/dist/services/IdentityRegistry/contracts/index.d.ts +5 -0
- package/dist/services/IdentityRegistry/contracts/index.js +3 -0
- package/dist/services/IdentityRegistry/contracts/types.d.ts +77 -0
- package/dist/services/IdentityRegistry/contracts/types.js +18 -0
- package/dist/services/IdentityRegistry/descriptor/descriptor.d.ts +36 -0
- package/dist/services/IdentityRegistry/descriptor/descriptor.js +44 -0
- package/dist/services/IdentityRegistry/descriptor/tokens.d.ts +8 -0
- package/dist/services/IdentityRegistry/descriptor/tokens.js +8 -0
- package/dist/services/IdentityRegistry/index.d.ts +11 -0
- package/dist/services/IdentityRegistry/index.js +6 -0
- package/dist/services/IdentityRegistry/orchestrator/IdentityRegistryService.d.ts +47 -0
- package/dist/services/IdentityRegistry/orchestrator/IdentityRegistryService.js +240 -0
- package/dist/services/IdentityRegistry/serviceModule.d.ts +10 -0
- package/dist/services/IdentityRegistry/serviceModule.js +24 -0
- package/dist/services/IdentityRegistry/storage/registryDocument.d.ts +55 -0
- package/dist/services/IdentityRegistry/storage/registryDocument.js +235 -0
- package/dist/services/Interception/contracts/IInterceptionService.d.ts +65 -0
- package/dist/services/Interception/contracts/IInterceptionService.js +1 -0
- package/dist/services/Interception/contracts/errors.d.ts +26 -0
- package/dist/services/Interception/contracts/errors.js +35 -0
- package/dist/services/Interception/contracts/index.d.ts +3 -0
- package/dist/services/Interception/contracts/index.js +3 -0
- package/dist/services/Interception/contracts/tokens.d.ts +2 -0
- package/dist/services/Interception/contracts/tokens.js +2 -0
- package/dist/services/Interception/descriptor/InterceptionDescriptor.d.ts +9 -0
- package/dist/services/Interception/descriptor/InterceptionDescriptor.js +49 -0
- package/dist/services/Interception/descriptor/tokens.d.ts +1 -0
- package/dist/services/Interception/descriptor/tokens.js +1 -0
- package/dist/services/Interception/index.d.ts +4 -0
- package/dist/services/Interception/index.js +4 -0
- package/dist/services/Interception/orchestrator/InterceptionService.d.ts +32 -0
- package/dist/services/Interception/orchestrator/InterceptionService.js +180 -0
- package/dist/services/Interception/orchestrator/index.d.ts +1 -0
- package/dist/services/Interception/orchestrator/index.js +1 -0
- package/dist/services/Interception/serviceModule.d.ts +2 -0
- package/dist/services/Interception/serviceModule.js +5 -0
- package/dist/services/Parser/contracts/IParserService.d.ts +21 -0
- package/dist/services/Parser/contracts/IParserService.js +1 -0
- package/dist/services/Parser/contracts/errors.d.ts +25 -0
- package/dist/services/Parser/contracts/errors.js +33 -0
- package/dist/services/Parser/contracts/index.d.ts +4 -0
- package/dist/services/Parser/contracts/index.js +1 -0
- package/dist/services/Parser/contracts/types.d.ts +42 -0
- package/dist/services/Parser/contracts/types.js +1 -0
- package/dist/services/Parser/descriptor/ParserDescriptor.d.ts +23 -0
- package/dist/services/Parser/descriptor/ParserDescriptor.js +50 -0
- package/dist/services/Parser/descriptor/tokens.d.ts +8 -0
- package/dist/services/Parser/descriptor/tokens.js +8 -0
- package/dist/services/Parser/index.d.ts +8 -0
- package/dist/services/Parser/index.js +8 -0
- package/dist/services/Parser/orchestrator/ParserService.d.ts +20 -0
- package/dist/services/Parser/orchestrator/ParserService.js +105 -0
- package/dist/services/Parser/orchestrator/index.d.ts +1 -0
- package/dist/services/Parser/orchestrator/index.js +1 -0
- package/dist/services/Parser/parser/indexSynthesis.d.ts +11 -0
- package/dist/services/Parser/parser/indexSynthesis.js +13 -0
- package/dist/services/Parser/parser/parameters.d.ts +14 -0
- package/dist/services/Parser/parser/parameters.js +89 -0
- package/dist/services/Parser/parser/scanner.d.ts +48 -0
- package/dist/services/Parser/parser/scanner.js +156 -0
- package/dist/services/Parser/parser/syntax.d.ts +30 -0
- package/dist/services/Parser/parser/syntax.js +34 -0
- package/dist/services/Parser/serviceModule.d.ts +2 -0
- package/dist/services/Parser/serviceModule.js +5 -0
- package/dist/services/Router/bootOptions.d.ts +2 -0
- package/dist/services/Router/bootOptions.js +2 -0
- package/dist/services/Router/contracts/IRouterService.d.ts +43 -0
- package/dist/services/Router/contracts/IRouterService.js +1 -0
- package/dist/services/Router/contracts/caller.d.ts +6 -0
- package/dist/services/Router/contracts/caller.js +6 -0
- package/dist/services/Router/contracts/errors.d.ts +56 -0
- package/dist/services/Router/contracts/errors.js +75 -0
- package/dist/services/Router/contracts/index.d.ts +8 -0
- package/dist/services/Router/contracts/index.js +4 -0
- package/dist/services/Router/contracts/kind.d.ts +7 -0
- package/dist/services/Router/contracts/kind.js +10 -0
- package/dist/services/Router/contracts/registrant.d.ts +23 -0
- package/dist/services/Router/contracts/registrant.js +13 -0
- package/dist/services/Router/contracts/types.d.ts +90 -0
- package/dist/services/Router/contracts/types.js +1 -0
- package/dist/services/Router/descriptor/RouterDescriptor.d.ts +32 -0
- package/dist/services/Router/descriptor/RouterDescriptor.js +92 -0
- package/dist/services/Router/descriptor/tokens.d.ts +9 -0
- package/dist/services/Router/descriptor/tokens.js +9 -0
- package/dist/services/Router/index.d.ts +4 -0
- package/dist/services/Router/index.js +4 -0
- package/dist/services/Router/orchestrator/RouterService.d.ts +74 -0
- package/dist/services/Router/orchestrator/RouterService.js +332 -0
- package/dist/services/Router/orchestrator/index.d.ts +2 -0
- package/dist/services/Router/orchestrator/index.js +1 -0
- package/dist/services/Router/serviceModule.d.ts +4 -0
- package/dist/services/Router/serviceModule.js +22 -0
- package/dist/services/WasmCage/index.d.ts +7 -0
- package/dist/services/WasmCage/index.js +4 -0
- package/dist/services/WasmCage/scripts/prepin.d.ts +1 -0
- package/dist/services/WasmCage/scripts/prepin.js +38 -0
- package/dist/services/WasmCage/serviceModule.d.ts +12 -0
- package/dist/services/WasmCage/serviceModule.js +18 -0
- package/dist/services/WasmCage/src/caged.d.ts +104 -0
- package/dist/services/WasmCage/src/caged.js +381 -0
- package/dist/services/WasmCage/src/descriptor.d.ts +47 -0
- package/dist/services/WasmCage/src/descriptor.js +56 -0
- package/dist/services/WasmCage/src/native.d.ts +29 -0
- package/dist/services/WasmCage/src/native.js +66 -0
- package/dist/services/WasmCage/src/nativeDigests.d.ts +9 -0
- package/dist/services/WasmCage/src/nativeDigests.js +15 -0
- package/dist/services/WasmCage/src/package.d.ts +36 -0
- package/dist/services/WasmCage/src/package.js +122 -0
- package/dist/services/shared/canonicalJson.d.ts +29 -0
- package/dist/services/shared/canonicalJson.js +93 -0
- package/dist/services/shared/documentStore.d.ts +16 -0
- package/dist/services/shared/documentStore.js +98 -0
- package/dist/src/bootstrap/bootKernelInternal.d.ts +18 -0
- package/dist/src/bootstrap/bootKernelInternal.js +420 -0
- package/dist/src/bootstrap/bootTypes.d.ts +89 -0
- package/dist/src/bootstrap/bootTypes.js +1 -0
- package/dist/src/bootstrap/config/index.d.ts +3 -0
- package/dist/src/bootstrap/config/index.js +2 -0
- package/dist/src/bootstrap/config/integrity.d.ts +34 -0
- package/dist/src/bootstrap/config/integrity.js +79 -0
- package/dist/src/bootstrap/config/parse.d.ts +15 -0
- package/dist/src/bootstrap/config/parse.js +81 -0
- package/dist/src/bootstrap/config/pathWriteGuard.d.ts +20 -0
- package/dist/src/bootstrap/config/pathWriteGuard.js +349 -0
- package/dist/src/bootstrap/config/types.d.ts +41 -0
- package/dist/src/bootstrap/config/types.js +15 -0
- package/dist/src/bootstrap/hardcore.d.ts +212 -0
- package/dist/src/bootstrap/hardcore.js +312 -0
- package/dist/src/bootstrap/hardcoreServices.d.ts +10 -0
- package/dist/src/bootstrap/hardcoreServices.js +258 -0
- package/dist/src/bootstrap/index.d.ts +8 -0
- package/dist/src/bootstrap/index.js +5 -0
- package/dist/src/bootstrap/packageRequirements.d.ts +26 -0
- package/dist/src/bootstrap/packageRequirements.js +52 -0
- package/dist/src/contracts/accessBroker.d.ts +53 -0
- package/dist/src/contracts/accessBroker.js +1 -0
- package/dist/src/contracts/brudOperation.d.ts +20 -0
- package/dist/src/contracts/brudOperation.js +20 -0
- package/dist/src/contracts/callChain.d.ts +161 -0
- package/dist/src/contracts/callChain.js +19 -0
- package/dist/src/contracts/capability.d.ts +26 -0
- package/dist/src/contracts/capability.js +26 -0
- package/dist/src/contracts/container.d.ts +17 -0
- package/dist/src/contracts/container.js +8 -0
- package/dist/src/contracts/context.d.ts +19 -0
- package/dist/src/contracts/context.js +1 -0
- package/dist/src/contracts/contextContract.d.ts +129 -0
- package/dist/src/contracts/contextContract.js +285 -0
- package/dist/src/contracts/dispatchView.d.ts +21 -0
- package/dist/src/contracts/dispatchView.js +1 -0
- package/dist/src/contracts/handler.d.ts +28 -0
- package/dist/src/contracts/handler.js +1 -0
- package/dist/src/contracts/index.d.ts +25 -0
- package/dist/src/contracts/index.js +8 -0
- package/dist/src/contracts/kernel.d.ts +60 -0
- package/dist/src/contracts/kernel.js +1 -0
- package/dist/src/contracts/lifecycle.d.ts +59 -0
- package/dist/src/contracts/lifecycle.js +1 -0
- package/dist/src/contracts/manifest.d.ts +145 -0
- package/dist/src/contracts/manifest.js +295 -0
- package/dist/src/contracts/pipeline.d.ts +8 -0
- package/dist/src/contracts/pipeline.js +1 -0
- package/dist/src/contracts/policy.d.ts +75 -0
- package/dist/src/contracts/policy.js +77 -0
- package/dist/src/contracts/registry.d.ts +7 -0
- package/dist/src/contracts/registry.js +1 -0
- package/dist/src/contracts/serviceDescriptor.d.ts +67 -0
- package/dist/src/contracts/serviceDescriptor.js +1 -0
- package/dist/src/contracts/serviceToken.d.ts +36 -0
- package/dist/src/contracts/serviceToken.js +16 -0
- package/dist/src/engine/BrudKernel.d.ts +118 -0
- package/dist/src/engine/BrudKernel.js +366 -0
- package/dist/src/engine/ExecutionPipeline.d.ts +13 -0
- package/dist/src/engine/ExecutionPipeline.js +62 -0
- package/dist/src/engine/KernelAccessBroker.d.ts +47 -0
- package/dist/src/engine/KernelAccessBroker.js +107 -0
- package/dist/src/engine/KernelRegistry.d.ts +14 -0
- package/dist/src/engine/KernelRegistry.js +33 -0
- package/dist/src/engine/OperationRegistry.d.ts +9 -0
- package/dist/src/engine/OperationRegistry.js +18 -0
- package/dist/src/engine/ServiceContainer.d.ts +13 -0
- package/dist/src/engine/ServiceContainer.js +53 -0
- package/dist/src/engine/callChain.d.ts +68 -0
- package/dist/src/engine/callChain.js +180 -0
- package/dist/src/engine/dag.d.ts +2 -0
- package/dist/src/engine/dag.js +34 -0
- package/dist/src/engine/errors.d.ts +26 -0
- package/dist/src/engine/errors.js +52 -0
- package/dist/src/engine/index.d.ts +11 -0
- package/dist/src/engine/index.js +8 -0
- package/dist/src/engine/state.d.ts +1 -0
- package/dist/src/engine/state.js +1 -0
- package/dist/src/validation/jsonSchema/compile.d.ts +8 -0
- package/dist/src/validation/jsonSchema/compile.js +386 -0
- package/dist/src/validation/jsonSchema/index.d.ts +3 -0
- package/dist/src/validation/jsonSchema/index.js +2 -0
- package/dist/src/validation/jsonSchema/jsonValue.d.ts +29 -0
- package/dist/src/validation/jsonSchema/jsonValue.js +190 -0
- package/dist/src/validation/jsonSchema/pattern.d.ts +28 -0
- package/dist/src/validation/jsonSchema/pattern.js +155 -0
- package/dist/src/validation/jsonSchema/types.d.ts +71 -0
- package/dist/src/validation/jsonSchema/types.js +15 -0
- package/package.json +59 -4
- package/services/WasmCage/native/brud-wasm-cage.darwin-arm64.node +0 -0
- package/services/WasmCage/native/brud-wasm-cage.darwin-x64.node +0 -0
- package/services/WasmCage/native/brud-wasm-cage.linux-arm64-gnu.node +0 -0
- package/services/WasmCage/native/brud-wasm-cage.linux-x64-gnu.node +0 -0
- package/services/WasmCage/native/brud-wasm-cage.win32-x64-msvc.node +0 -0
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/** Base class for every Registry domain failure. */
|
|
2
|
+
export class ExposedApiError extends Error {
|
|
3
|
+
constructor(message, options) {
|
|
4
|
+
super(message, options);
|
|
5
|
+
this.name = 'ExposedApiError';
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
/** Raised when an exposure is registered after the boot window closed. */
|
|
9
|
+
export class ExposedApiRegistrationClosedError extends ExposedApiError {
|
|
10
|
+
code = 'EXPOSED_API_REGISTRATION_CLOSED';
|
|
11
|
+
/** Rejected API name. */
|
|
12
|
+
apiName;
|
|
13
|
+
constructor(apiName) {
|
|
14
|
+
super(`Exposed API registration window is closed; "${apiName}" was rejected`);
|
|
15
|
+
this.name = 'ExposedApiRegistrationClosedError';
|
|
16
|
+
this.apiName = apiName;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Raised when a second identity registers a name another identity owns.
|
|
21
|
+
*
|
|
22
|
+
* A name is owned by the identity that first registered it, across every major
|
|
23
|
+
* version: a version upgrade keeps ownership.
|
|
24
|
+
*/
|
|
25
|
+
export class ExposedApiNameCollisionError extends ExposedApiError {
|
|
26
|
+
code = 'EXPOSED_API_NAME_COLLISION';
|
|
27
|
+
/** Contested API name. */
|
|
28
|
+
apiName;
|
|
29
|
+
/** Identity token that owns the name. */
|
|
30
|
+
owner;
|
|
31
|
+
constructor(apiName, owner) {
|
|
32
|
+
super(`Exposed API "${apiName}" is already owned by another identity`);
|
|
33
|
+
this.name = 'ExposedApiNameCollisionError';
|
|
34
|
+
this.apiName = apiName;
|
|
35
|
+
this.owner = owner;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/** Raised when a registration contradicts the composition's owner pin. */
|
|
39
|
+
export class ExposedApiOwnerPinError extends ExposedApiError {
|
|
40
|
+
code = 'EXPOSED_API_OWNER_PIN';
|
|
41
|
+
/** Pinned API name. */
|
|
42
|
+
apiName;
|
|
43
|
+
constructor(apiName) {
|
|
44
|
+
super(`Exposed API "${apiName}" is pinned to a different owner identity by the composition`);
|
|
45
|
+
this.name = 'ExposedApiOwnerPinError';
|
|
46
|
+
this.apiName = apiName;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/** Raised when one identity declares the same name and major version twice. */
|
|
50
|
+
export class ExposedApiDuplicateExposureError extends ExposedApiError {
|
|
51
|
+
code = 'EXPOSED_API_DUPLICATE_EXPOSURE';
|
|
52
|
+
/** API name. */
|
|
53
|
+
apiName;
|
|
54
|
+
/** Duplicated major version. */
|
|
55
|
+
major;
|
|
56
|
+
constructor(apiName, major) {
|
|
57
|
+
super(`Exposed API "${apiName}" major version ${String(major)} is declared twice`);
|
|
58
|
+
this.name = 'ExposedApiDuplicateExposureError';
|
|
59
|
+
this.apiName = apiName;
|
|
60
|
+
this.major = major;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/** Raised when admission runs before the kernel attached its call authority. */
|
|
64
|
+
export class ExposedApiNotAttachedError extends ExposedApiError {
|
|
65
|
+
code = 'EXPOSED_API_NOT_ATTACHED';
|
|
66
|
+
constructor() {
|
|
67
|
+
super('Exposed API Registry has no kernel call authority attached');
|
|
68
|
+
this.name = 'ExposedApiNotAttachedError';
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Raised when an exposure handle is used by a caller the exposure's policy
|
|
73
|
+
* does not permit at the time of use.
|
|
74
|
+
*
|
|
75
|
+
* Carries no reason. The detailed reason is on the kernel's observation
|
|
76
|
+
* stream, so a refused caller learns nothing about why.
|
|
77
|
+
*/
|
|
78
|
+
export class ExposedApiUnavailableError extends ExposedApiError {
|
|
79
|
+
code = 'EXPOSED_API_UNAVAILABLE';
|
|
80
|
+
constructor() {
|
|
81
|
+
super('Exposed API is unavailable');
|
|
82
|
+
this.name = 'ExposedApiUnavailableError';
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/** Raised when an API name is malformed. */
|
|
86
|
+
export class ExposedApiInvalidNameError extends ExposedApiError {
|
|
87
|
+
code = 'EXPOSED_API_INVALID_NAME';
|
|
88
|
+
/** Rejected name. */
|
|
89
|
+
apiName;
|
|
90
|
+
constructor(apiName) {
|
|
91
|
+
super(`Invalid exposed API name "${apiName}"`);
|
|
92
|
+
this.name = 'ExposedApiInvalidNameError';
|
|
93
|
+
this.apiName = apiName;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/** Raised when the Registry is used after disposal. */
|
|
97
|
+
export class ExposedApiDisposedError extends ExposedApiError {
|
|
98
|
+
code = 'EXPOSED_API_DISPOSED';
|
|
99
|
+
constructor() {
|
|
100
|
+
super('Exposed API Registry has been disposed');
|
|
101
|
+
this.name = 'ExposedApiDisposedError';
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/** Raised when a registration declares an invalid API version. */
|
|
105
|
+
export class ExposedApiInvalidVersionError extends ExposedApiError {
|
|
106
|
+
code = 'EXPOSED_API_INVALID_VERSION';
|
|
107
|
+
/** Rejected version. */
|
|
108
|
+
version;
|
|
109
|
+
constructor(version) {
|
|
110
|
+
super(`Invalid exposed API version "${String(version)}"`);
|
|
111
|
+
this.name = 'ExposedApiInvalidVersionError';
|
|
112
|
+
this.version = version;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/** Raised when a registration declares an unsupported scope. */
|
|
116
|
+
export class ExposedApiInvalidScopeError extends ExposedApiError {
|
|
117
|
+
code = 'EXPOSED_API_INVALID_SCOPE';
|
|
118
|
+
/** Rejected scope. */
|
|
119
|
+
scope;
|
|
120
|
+
constructor(scope) {
|
|
121
|
+
super(`Invalid exposed API scope "${String(scope)}"`);
|
|
122
|
+
this.name = 'ExposedApiInvalidScopeError';
|
|
123
|
+
this.scope = scope;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/** Raised when a registration declares a malformed policy. */
|
|
127
|
+
export class ExposedApiInvalidPolicyError extends ExposedApiError {
|
|
128
|
+
code = 'EXPOSED_API_INVALID_POLICY';
|
|
129
|
+
/** Human-readable reason. */
|
|
130
|
+
reason;
|
|
131
|
+
constructor(reason) {
|
|
132
|
+
super(`Invalid exposed API policy: ${reason}`);
|
|
133
|
+
this.name = 'ExposedApiInvalidPolicyError';
|
|
134
|
+
this.reason = reason;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/** Raised when a registration narrows a persisted scope within one version. */
|
|
138
|
+
export class ExposedApiScopeNarrowingError extends ExposedApiError {
|
|
139
|
+
code = 'EXPOSED_API_SCOPE_NARROWED';
|
|
140
|
+
/** API name. */
|
|
141
|
+
apiName;
|
|
142
|
+
/** API version. */
|
|
143
|
+
version;
|
|
144
|
+
/** Scope already recorded for the identity. */
|
|
145
|
+
persistedScope;
|
|
146
|
+
/** Scope the registration requested. */
|
|
147
|
+
requestedScope;
|
|
148
|
+
constructor(apiName, version, persistedScope, requestedScope) {
|
|
149
|
+
super(`Exposed API "${apiName}" version "${version}" cannot narrow its scope from "${persistedScope}" to "${requestedScope}"`);
|
|
150
|
+
this.name = 'ExposedApiScopeNarrowingError';
|
|
151
|
+
this.apiName = apiName;
|
|
152
|
+
this.version = version;
|
|
153
|
+
this.persistedScope = persistedScope;
|
|
154
|
+
this.requestedScope = requestedScope;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/** Raised when the protected scope record cannot be parsed or verified. */
|
|
158
|
+
export class ExposedApiScopeRecordCorruptError extends ExposedApiError {
|
|
159
|
+
code = 'EXPOSED_API_SCOPE_RECORD_CORRUPT';
|
|
160
|
+
/** Absolute storage path. */
|
|
161
|
+
storagePath;
|
|
162
|
+
/** Human-readable reason. */
|
|
163
|
+
reason;
|
|
164
|
+
constructor(storagePath, reason) {
|
|
165
|
+
super(`Exposed API scope record "${storagePath}" is corrupt: ${reason}`);
|
|
166
|
+
this.name = 'ExposedApiScopeRecordCorruptError';
|
|
167
|
+
this.storagePath = storagePath;
|
|
168
|
+
this.reason = reason;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/** Raised when a scope-record storage path is not an absolute file path. */
|
|
172
|
+
export class ExposedApiScopeRecordPathError extends ExposedApiError {
|
|
173
|
+
code = 'EXPOSED_API_SCOPE_RECORD_PATH';
|
|
174
|
+
/** Rejected path. */
|
|
175
|
+
storagePath;
|
|
176
|
+
constructor(storagePath) {
|
|
177
|
+
super(`Invalid exposed API scope record path "${storagePath}"`);
|
|
178
|
+
this.name = 'ExposedApiScopeRecordPathError';
|
|
179
|
+
this.storagePath = storagePath;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/** Raised when the protected scope record cannot be written. */
|
|
183
|
+
export class ExposedApiScopeRecordWriteError extends ExposedApiError {
|
|
184
|
+
code = 'EXPOSED_API_SCOPE_RECORD_WRITE';
|
|
185
|
+
/** Absolute storage path. */
|
|
186
|
+
storagePath;
|
|
187
|
+
/** Filesystem error code, when available. */
|
|
188
|
+
reason;
|
|
189
|
+
constructor(storagePath, reason) {
|
|
190
|
+
super(`Cannot write exposed API scope record "${storagePath}": ${reason}`);
|
|
191
|
+
this.name = 'ExposedApiScopeRecordWriteError';
|
|
192
|
+
this.storagePath = storagePath;
|
|
193
|
+
this.reason = reason;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type { IExposedApiAdmission, IExposedApiRegistry } from './IExposedApiRegistry.js';
|
|
2
|
+
export type { IExposureProvider } from './registrant.js';
|
|
3
|
+
export { exposureBindingKey, isExposureProvider, withExposureBindings, } from './registrant.js';
|
|
4
|
+
export { EXPOSED_API_MAX_POLICY_BYTES, EXPOSED_API_POLICY_VERSION, evaluateExposedApiPolicy, parseExposedApiPolicy, } from './policy.js';
|
|
5
|
+
export type { ExposedApiPolicy, ExposedApiPolicyDecision } from './policy.js';
|
|
6
|
+
export { EXPOSED_API_NAME_PATTERN, EXPOSED_API_ORIGINS, EXPOSED_API_SCOPES, exposedApiMajor, exposedApiScopeAllowsOrigin, exposedApiScopeRank, isExposedApiOrigin, isExposedApiScope, isExposedApiVersion, } from './types.js';
|
|
7
|
+
export type { ExposedApiBinding, ExposedApiCaller, ExposedApiIdentity, ExposedApiOrigin, ExposedApiProjection, ExposedApiResolveOptions, ExposedApiScope, ExposedApiVersion, } from './types.js';
|
|
8
|
+
export type { ExposedApiErrorCode } from './errors.js';
|
|
9
|
+
export { ExposedApiDisposedError, ExposedApiDuplicateExposureError, ExposedApiError, ExposedApiInvalidNameError, ExposedApiInvalidPolicyError, ExposedApiInvalidScopeError, ExposedApiInvalidVersionError, ExposedApiNameCollisionError, ExposedApiNotAttachedError, ExposedApiOwnerPinError, ExposedApiRegistrationClosedError, ExposedApiScopeNarrowingError, ExposedApiScopeRecordCorruptError, ExposedApiScopeRecordPathError, ExposedApiScopeRecordWriteError, ExposedApiUnavailableError, } from './errors.js';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { exposureBindingKey, isExposureProvider, withExposureBindings, } from './registrant.js';
|
|
2
|
+
export { EXPOSED_API_MAX_POLICY_BYTES, EXPOSED_API_POLICY_VERSION, evaluateExposedApiPolicy, parseExposedApiPolicy, } from './policy.js';
|
|
3
|
+
export { EXPOSED_API_NAME_PATTERN, EXPOSED_API_ORIGINS, EXPOSED_API_SCOPES, exposedApiMajor, exposedApiScopeAllowsOrigin, exposedApiScopeRank, isExposedApiOrigin, isExposedApiScope, isExposedApiVersion, } from './types.js';
|
|
4
|
+
export { ExposedApiDisposedError, ExposedApiDuplicateExposureError, ExposedApiError, ExposedApiInvalidNameError, ExposedApiInvalidPolicyError, ExposedApiInvalidScopeError, ExposedApiInvalidVersionError, ExposedApiNameCollisionError, ExposedApiNotAttachedError, ExposedApiOwnerPinError, ExposedApiRegistrationClosedError, ExposedApiScopeNarrowingError, ExposedApiScopeRecordCorruptError, ExposedApiScopeRecordPathError, ExposedApiScopeRecordWriteError, ExposedApiUnavailableError, } from './errors.js';
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { type CallOrigin, type CallerClass, type KernelCallContext } from '../../../src/contracts/callChain.js';
|
|
2
|
+
import { type ExposedApiScope } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Layer 1 policy language.
|
|
5
|
+
*
|
|
6
|
+
* A Layer 1 policy is declarative data the giver states in its manifest. The
|
|
7
|
+
* registry evaluates it mechanically and the kernel enforces the result before
|
|
8
|
+
* any of the giver's code runs. The language is small, versioned, and
|
|
9
|
+
* deterministic, carries no executable code, and fails closed: an unknown
|
|
10
|
+
* version, an unknown field, or a malformed field refuses the declaration.
|
|
11
|
+
*
|
|
12
|
+
* Inputs, all assigned by the kernel: the caller's identity class, the chain's
|
|
13
|
+
* root origin, the exposure's scope, the caller's declared capabilities, and
|
|
14
|
+
* the caller's official status in the composition.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* The only policy language version this registry evaluates.
|
|
18
|
+
*
|
|
19
|
+
* Version 2 adds `parentCallerClasses`. A version-1 policy is refused by the
|
|
20
|
+
* version-2 evaluator, fail-closed, the same way an unknown version is refused:
|
|
21
|
+
* `parseExposedApiPolicy` requires `policyVersion === EXPOSED_API_POLICY_VERSION`.
|
|
22
|
+
* The bump is intentional. A version-1 declaration predates the parent-class
|
|
23
|
+
* check and must be re-declared at version 2 to be evaluated, so no version-1
|
|
24
|
+
* policy can reach the evaluator without having passed the version check.
|
|
25
|
+
*/
|
|
26
|
+
export declare const EXPOSED_API_POLICY_VERSION = 2;
|
|
27
|
+
/** Largest accepted canonical policy size in bytes. */
|
|
28
|
+
export declare const EXPOSED_API_MAX_POLICY_BYTES = 65536;
|
|
29
|
+
/** A validated Layer 1 policy. */
|
|
30
|
+
export interface ExposedApiPolicy {
|
|
31
|
+
/** Policy language version. */
|
|
32
|
+
readonly policyVersion: typeof EXPOSED_API_POLICY_VERSION;
|
|
33
|
+
/** Root origins admitted, inside what the scope already admits. */
|
|
34
|
+
readonly origins?: readonly CallOrigin[];
|
|
35
|
+
/** Identity classes admitted. */
|
|
36
|
+
readonly callerClasses?: readonly CallerClass[];
|
|
37
|
+
/**
|
|
38
|
+
* Identity classes the caller's parent must belong to.
|
|
39
|
+
*
|
|
40
|
+
* Names the class of the caller's parent, never a participant's name. A
|
|
41
|
+
* top-level caller has no parent and does not satisfy a policy that names
|
|
42
|
+
* `parentCallerClasses`. Evaluated after the `callerClasses` check; the other
|
|
43
|
+
* checks continue to apply.
|
|
44
|
+
*/
|
|
45
|
+
readonly parentCallerClasses?: readonly CallerClass[];
|
|
46
|
+
/** Capabilities the caller must have declared. Every one is required. */
|
|
47
|
+
readonly capabilities?: readonly string[];
|
|
48
|
+
/** Official status the caller must hold in this composition. */
|
|
49
|
+
readonly official?: boolean;
|
|
50
|
+
}
|
|
51
|
+
/** Outcome of one Layer 1 evaluation. */
|
|
52
|
+
export type ExposedApiPolicyDecision = {
|
|
53
|
+
readonly allowed: true;
|
|
54
|
+
} | {
|
|
55
|
+
readonly allowed: false;
|
|
56
|
+
readonly reason: string;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Validates and freezes a Layer 1 policy declaration.
|
|
60
|
+
*
|
|
61
|
+
* An omitted policy is the empty version-1 policy: the exposure's scope alone
|
|
62
|
+
* decides reachability.
|
|
63
|
+
*
|
|
64
|
+
* @param value - Declared policy, or `undefined`.
|
|
65
|
+
* @throws {ExposedApiInvalidPolicyError} When the declaration is not a valid
|
|
66
|
+
* version-1 policy.
|
|
67
|
+
*/
|
|
68
|
+
export declare function parseExposedApiPolicy(value: unknown): ExposedApiPolicy;
|
|
69
|
+
/**
|
|
70
|
+
* The kernel-provided context of one evaluation, plus the parent's class.
|
|
71
|
+
*
|
|
72
|
+
* `parentCallerClass` is resolved by the kernel from the caller frame's
|
|
73
|
+
* `parentIdentity` against the admission record, never from the caller's
|
|
74
|
+
* request. It is `undefined` when the caller has no parent.
|
|
75
|
+
*/
|
|
76
|
+
export interface ExposedApiEvaluationContext extends KernelCallContext {
|
|
77
|
+
/** Class of the caller's parent, when the caller is a caged child. */
|
|
78
|
+
readonly parentCallerClass?: CallerClass;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Evaluates a Layer 1 policy for one call.
|
|
82
|
+
*
|
|
83
|
+
* Deterministic: the same policy, scope, and kernel-provided context always
|
|
84
|
+
* produce the same decision. Nothing a caller supplies is an input.
|
|
85
|
+
*
|
|
86
|
+
* @param policy - Validated policy.
|
|
87
|
+
* @param scope - The exposure's recorded scope.
|
|
88
|
+
* @param context - The kernel-provided context of the call.
|
|
89
|
+
*/
|
|
90
|
+
export declare function evaluateExposedApiPolicy(policy: ExposedApiPolicy, scope: ExposedApiScope, context: ExposedApiEvaluationContext): ExposedApiPolicyDecision;
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { CALLER_CLASSES, CALL_ORIGINS, } from '../../../src/contracts/callChain.js';
|
|
2
|
+
import { isCapabilityToken } from '../../../src/contracts/capability.js';
|
|
3
|
+
import { canonicalJson, cloneJsonRecord, JsonValueError } from '../../shared/canonicalJson.js';
|
|
4
|
+
import { ExposedApiInvalidPolicyError } from './errors.js';
|
|
5
|
+
import { exposedApiScopeAllowsOrigin } from './types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Layer 1 policy language.
|
|
8
|
+
*
|
|
9
|
+
* A Layer 1 policy is declarative data the giver states in its manifest. The
|
|
10
|
+
* registry evaluates it mechanically and the kernel enforces the result before
|
|
11
|
+
* any of the giver's code runs. The language is small, versioned, and
|
|
12
|
+
* deterministic, carries no executable code, and fails closed: an unknown
|
|
13
|
+
* version, an unknown field, or a malformed field refuses the declaration.
|
|
14
|
+
*
|
|
15
|
+
* Inputs, all assigned by the kernel: the caller's identity class, the chain's
|
|
16
|
+
* root origin, the exposure's scope, the caller's declared capabilities, and
|
|
17
|
+
* the caller's official status in the composition.
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* The only policy language version this registry evaluates.
|
|
21
|
+
*
|
|
22
|
+
* Version 2 adds `parentCallerClasses`. A version-1 policy is refused by the
|
|
23
|
+
* version-2 evaluator, fail-closed, the same way an unknown version is refused:
|
|
24
|
+
* `parseExposedApiPolicy` requires `policyVersion === EXPOSED_API_POLICY_VERSION`.
|
|
25
|
+
* The bump is intentional. A version-1 declaration predates the parent-class
|
|
26
|
+
* check and must be re-declared at version 2 to be evaluated, so no version-1
|
|
27
|
+
* policy can reach the evaluator without having passed the version check.
|
|
28
|
+
*/
|
|
29
|
+
export const EXPOSED_API_POLICY_VERSION = 2;
|
|
30
|
+
/** Largest accepted canonical policy size in bytes. */
|
|
31
|
+
export const EXPOSED_API_MAX_POLICY_BYTES = 65_536;
|
|
32
|
+
const POLICY_KEYS = new Set([
|
|
33
|
+
'policyVersion',
|
|
34
|
+
'origins',
|
|
35
|
+
'callerClasses',
|
|
36
|
+
'parentCallerClasses',
|
|
37
|
+
'capabilities',
|
|
38
|
+
'official',
|
|
39
|
+
]);
|
|
40
|
+
function stringList(value, field, accept) {
|
|
41
|
+
if (!Array.isArray(value) || value.length === 0) {
|
|
42
|
+
throw new ExposedApiInvalidPolicyError(`${field} must be a non-empty array`);
|
|
43
|
+
}
|
|
44
|
+
const seen = new Set();
|
|
45
|
+
for (const item of value) {
|
|
46
|
+
if (typeof item !== 'string' || !accept(item)) {
|
|
47
|
+
throw new ExposedApiInvalidPolicyError(`${field} contains an unsupported value`);
|
|
48
|
+
}
|
|
49
|
+
if (seen.has(item)) {
|
|
50
|
+
throw new ExposedApiInvalidPolicyError(`${field} contains a duplicate value`);
|
|
51
|
+
}
|
|
52
|
+
seen.add(item);
|
|
53
|
+
}
|
|
54
|
+
return Object.freeze([...seen]);
|
|
55
|
+
}
|
|
56
|
+
function isOrigin(value) {
|
|
57
|
+
return CALL_ORIGINS.includes(value);
|
|
58
|
+
}
|
|
59
|
+
function isCallerClass(value) {
|
|
60
|
+
return CALLER_CLASSES.includes(value);
|
|
61
|
+
}
|
|
62
|
+
function isCapability(value) {
|
|
63
|
+
return isCapabilityToken(value);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Validates and freezes a Layer 1 policy declaration.
|
|
67
|
+
*
|
|
68
|
+
* An omitted policy is the empty version-1 policy: the exposure's scope alone
|
|
69
|
+
* decides reachability.
|
|
70
|
+
*
|
|
71
|
+
* @param value - Declared policy, or `undefined`.
|
|
72
|
+
* @throws {ExposedApiInvalidPolicyError} When the declaration is not a valid
|
|
73
|
+
* version-1 policy.
|
|
74
|
+
*/
|
|
75
|
+
export function parseExposedApiPolicy(value) {
|
|
76
|
+
if (value === undefined) {
|
|
77
|
+
return Object.freeze({ policyVersion: EXPOSED_API_POLICY_VERSION });
|
|
78
|
+
}
|
|
79
|
+
let record;
|
|
80
|
+
try {
|
|
81
|
+
record = cloneJsonRecord(value);
|
|
82
|
+
if (Buffer.byteLength(canonicalJson(record), 'utf8') > EXPOSED_API_MAX_POLICY_BYTES) {
|
|
83
|
+
throw new ExposedApiInvalidPolicyError(`must be at most ${String(EXPOSED_API_MAX_POLICY_BYTES)} canonical bytes`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
if (error instanceof ExposedApiInvalidPolicyError) {
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
throw new ExposedApiInvalidPolicyError(error instanceof JsonValueError ? error.message : 'must be a JSON object');
|
|
91
|
+
}
|
|
92
|
+
for (const key of Object.keys(record)) {
|
|
93
|
+
if (!POLICY_KEYS.has(key)) {
|
|
94
|
+
throw new ExposedApiInvalidPolicyError(`unknown field "${key}"`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (record.policyVersion !== EXPOSED_API_POLICY_VERSION) {
|
|
98
|
+
throw new ExposedApiInvalidPolicyError(`policyVersion must be ${String(EXPOSED_API_POLICY_VERSION)}`);
|
|
99
|
+
}
|
|
100
|
+
const policy = { policyVersion: EXPOSED_API_POLICY_VERSION };
|
|
101
|
+
if (record.origins !== undefined) {
|
|
102
|
+
policy.origins = stringList(record.origins, 'origins', isOrigin);
|
|
103
|
+
}
|
|
104
|
+
if (record.callerClasses !== undefined) {
|
|
105
|
+
policy.callerClasses = stringList(record.callerClasses, 'callerClasses', isCallerClass);
|
|
106
|
+
}
|
|
107
|
+
if (record.parentCallerClasses !== undefined) {
|
|
108
|
+
policy.parentCallerClasses = stringList(record.parentCallerClasses, 'parentCallerClasses', isCallerClass);
|
|
109
|
+
}
|
|
110
|
+
if (record.capabilities !== undefined) {
|
|
111
|
+
policy.capabilities = stringList(record.capabilities, 'capabilities', isCapability);
|
|
112
|
+
}
|
|
113
|
+
if (record.official !== undefined) {
|
|
114
|
+
if (typeof record.official !== 'boolean') {
|
|
115
|
+
throw new ExposedApiInvalidPolicyError('official must be a boolean');
|
|
116
|
+
}
|
|
117
|
+
policy.official = record.official;
|
|
118
|
+
}
|
|
119
|
+
return Object.freeze(policy);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Evaluates a Layer 1 policy for one call.
|
|
123
|
+
*
|
|
124
|
+
* Deterministic: the same policy, scope, and kernel-provided context always
|
|
125
|
+
* produce the same decision. Nothing a caller supplies is an input.
|
|
126
|
+
*
|
|
127
|
+
* @param policy - Validated policy.
|
|
128
|
+
* @param scope - The exposure's recorded scope.
|
|
129
|
+
* @param context - The kernel-provided context of the call.
|
|
130
|
+
*/
|
|
131
|
+
export function evaluateExposedApiPolicy(policy, scope, context) {
|
|
132
|
+
if (!exposedApiScopeAllowsOrigin(scope, context.origin)) {
|
|
133
|
+
return { allowed: false, reason: `scope "${scope}" does not admit origin "${context.origin}"` };
|
|
134
|
+
}
|
|
135
|
+
if (policy.origins !== undefined && !policy.origins.includes(context.origin)) {
|
|
136
|
+
return { allowed: false, reason: `policy does not admit origin "${context.origin}"` };
|
|
137
|
+
}
|
|
138
|
+
if (policy.callerClasses !== undefined
|
|
139
|
+
&& !policy.callerClasses.includes(context.caller.callerClass)) {
|
|
140
|
+
return {
|
|
141
|
+
allowed: false,
|
|
142
|
+
reason: `policy does not admit caller class "${context.caller.callerClass}"`,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
if (policy.parentCallerClasses !== undefined) {
|
|
146
|
+
if (context.parentCallerClass === undefined
|
|
147
|
+
|| !policy.parentCallerClasses.includes(context.parentCallerClass)) {
|
|
148
|
+
return {
|
|
149
|
+
allowed: false,
|
|
150
|
+
reason: context.parentCallerClass === undefined
|
|
151
|
+
? 'policy admits only callers with a parent, and the caller has none'
|
|
152
|
+
: `policy does not admit parent caller class "${context.parentCallerClass}"`,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (policy.capabilities !== undefined) {
|
|
157
|
+
const missing = policy.capabilities.filter((capability) => !context.caller.capabilities.has(capability));
|
|
158
|
+
if (missing.length > 0) {
|
|
159
|
+
return { allowed: false, reason: `caller lacks capabilities ${missing.join(', ')}` };
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
if (policy.official !== undefined && context.caller.official !== policy.official) {
|
|
163
|
+
return {
|
|
164
|
+
allowed: false,
|
|
165
|
+
reason: `policy requires official status ${String(policy.official)}`,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
return { allowed: true };
|
|
169
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ExposedApiBinding } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Implemented by a participant whose code binds its declared exposures.
|
|
4
|
+
*
|
|
5
|
+
* The participant's manifest declares its exposures; the kernel registers them
|
|
6
|
+
* at boot from that data. On the first resolve of an exposure, the registry
|
|
7
|
+
* asks the owner's code for the binding of that declared exposure. Code can
|
|
8
|
+
* only bind what the manifest declared: it cannot add an exposure.
|
|
9
|
+
*/
|
|
10
|
+
export interface IExposureProvider {
|
|
11
|
+
/**
|
|
12
|
+
* Returns the binding for one declared exposure, or `undefined` when the
|
|
13
|
+
* code does not provide it.
|
|
14
|
+
*
|
|
15
|
+
* @param name - Declared exposure name.
|
|
16
|
+
* @param major - Declared major version.
|
|
17
|
+
*/
|
|
18
|
+
provideExposure(name: string, major: number): ExposedApiBinding | undefined;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Narrows an initialized instance to {@link IExposureProvider}.
|
|
22
|
+
*
|
|
23
|
+
* @param value - Initialized participant instance.
|
|
24
|
+
*/
|
|
25
|
+
export declare function isExposureProvider(value: unknown): value is IExposureProvider;
|
|
26
|
+
/** Key of one binding: `name@major`. */
|
|
27
|
+
export declare function exposureBindingKey(name: string, major: number): string;
|
|
28
|
+
/**
|
|
29
|
+
* Attaches exposure bindings to an instance its factory returns.
|
|
30
|
+
*
|
|
31
|
+
* The method is non-enumerable so it never appears in projections or
|
|
32
|
+
* diagnostics. A binding key is `name@major`.
|
|
33
|
+
*
|
|
34
|
+
* @param instance - Instance returned by a descriptor factory.
|
|
35
|
+
* @param bindings - Bindings for the exposures the manifest declares.
|
|
36
|
+
*/
|
|
37
|
+
export declare function withExposureBindings<T extends object>(instance: T, bindings: Readonly<Record<string, ExposedApiBinding>>): T;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Narrows an initialized instance to {@link IExposureProvider}.
|
|
3
|
+
*
|
|
4
|
+
* @param value - Initialized participant instance.
|
|
5
|
+
*/
|
|
6
|
+
export function isExposureProvider(value) {
|
|
7
|
+
if (value === null || (typeof value !== 'object' && typeof value !== 'function')) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
return typeof value.provideExposure === 'function';
|
|
11
|
+
}
|
|
12
|
+
/** Key of one binding: `name@major`. */
|
|
13
|
+
export function exposureBindingKey(name, major) {
|
|
14
|
+
return `${name}@${String(major)}`;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Attaches exposure bindings to an instance its factory returns.
|
|
18
|
+
*
|
|
19
|
+
* The method is non-enumerable so it never appears in projections or
|
|
20
|
+
* diagnostics. A binding key is `name@major`.
|
|
21
|
+
*
|
|
22
|
+
* @param instance - Instance returned by a descriptor factory.
|
|
23
|
+
* @param bindings - Bindings for the exposures the manifest declares.
|
|
24
|
+
*/
|
|
25
|
+
export function withExposureBindings(instance, bindings) {
|
|
26
|
+
const frozen = Object.freeze({ ...bindings });
|
|
27
|
+
Object.defineProperty(instance, 'provideExposure', {
|
|
28
|
+
value: (name, major) => Object.prototype.hasOwnProperty.call(frozen, exposureBindingKey(name, major))
|
|
29
|
+
? frozen[exposureBindingKey(name, major)]
|
|
30
|
+
: undefined,
|
|
31
|
+
enumerable: false,
|
|
32
|
+
configurable: false,
|
|
33
|
+
writable: false,
|
|
34
|
+
});
|
|
35
|
+
return instance;
|
|
36
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { type CallOrigin, type CallerClass } from '../../../src/contracts/callChain.js';
|
|
2
|
+
/** API names accept dotted, kebab, and snake segments. */
|
|
3
|
+
export declare const EXPOSED_API_NAME_PATTERN: RegExp;
|
|
4
|
+
/** The four reachability scopes, ordered from narrowest to widest. */
|
|
5
|
+
export declare const EXPOSED_API_SCOPES: readonly ["kernel", "runtime", "host", "any"];
|
|
6
|
+
/** Reachability scope declared by an exposed API identity. */
|
|
7
|
+
export type ExposedApiScope = (typeof EXPOSED_API_SCOPES)[number];
|
|
8
|
+
/** The three root origins a call chain can carry. Assigned by the kernel. */
|
|
9
|
+
export declare const EXPOSED_API_ORIGINS: readonly ["kernel", "runtime", "host"];
|
|
10
|
+
/** Root origin of a call chain. */
|
|
11
|
+
export type ExposedApiOrigin = CallOrigin;
|
|
12
|
+
/**
|
|
13
|
+
* API version.
|
|
14
|
+
*
|
|
15
|
+
* A positive integer is a major version. A string must be a semantic version.
|
|
16
|
+
*/
|
|
17
|
+
export type ExposedApiVersion = number | string;
|
|
18
|
+
/** Identity of one exposed API. */
|
|
19
|
+
export interface ExposedApiIdentity {
|
|
20
|
+
readonly name: string;
|
|
21
|
+
readonly version: ExposedApiVersion;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Reports whether a value is a supported scope.
|
|
25
|
+
*
|
|
26
|
+
* @param value - Candidate value.
|
|
27
|
+
*/
|
|
28
|
+
export declare function isExposedApiScope(value: unknown): value is ExposedApiScope;
|
|
29
|
+
/**
|
|
30
|
+
* Reports whether a value is a supported root origin.
|
|
31
|
+
*
|
|
32
|
+
* @param value - Candidate value.
|
|
33
|
+
*/
|
|
34
|
+
export declare function isExposedApiOrigin(value: unknown): value is ExposedApiOrigin;
|
|
35
|
+
/**
|
|
36
|
+
* Reports whether a value is a valid API version.
|
|
37
|
+
*
|
|
38
|
+
* @param value - Candidate value.
|
|
39
|
+
*/
|
|
40
|
+
export declare function isExposedApiVersion(value: unknown): value is ExposedApiVersion;
|
|
41
|
+
/**
|
|
42
|
+
* Returns the order rank of a scope. Higher is wider.
|
|
43
|
+
*
|
|
44
|
+
* @param scope - Supported scope.
|
|
45
|
+
*/
|
|
46
|
+
export declare function exposedApiScopeRank(scope: ExposedApiScope): number;
|
|
47
|
+
/**
|
|
48
|
+
* Applies the four-case origin-and-scope rule.
|
|
49
|
+
*
|
|
50
|
+
* @param scope - Scope declared by the API identity.
|
|
51
|
+
* @param origin - Root origin of the call chain.
|
|
52
|
+
*/
|
|
53
|
+
export declare function exposedApiScopeAllowsOrigin(scope: ExposedApiScope, origin: ExposedApiOrigin): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Caller view handed to a giver's projection.
|
|
56
|
+
*
|
|
57
|
+
* Every field is assigned by the kernel and read from the kernel-provided
|
|
58
|
+
* execution context. Namespace-scoped projections bind to {@link identity}.
|
|
59
|
+
*/
|
|
60
|
+
export interface ExposedApiCaller {
|
|
61
|
+
/**
|
|
62
|
+
* The caller's kernel-issued identity token.
|
|
63
|
+
*
|
|
64
|
+
* `null` for the kernel itself and for a host session, which carry no
|
|
65
|
+
* participant identity and are distinguished by {@link callerClass}.
|
|
66
|
+
*/
|
|
67
|
+
readonly identity: string | null;
|
|
68
|
+
/** The caller's identity class. */
|
|
69
|
+
readonly callerClass: CallerClass;
|
|
70
|
+
/**
|
|
71
|
+
* The caller's official status in this composition.
|
|
72
|
+
*
|
|
73
|
+
* Kernel-derived from the identity-to-official mapping the kernel builds at
|
|
74
|
+
* boot from the composition's frozen config. Never supplied by the caller.
|
|
75
|
+
* A Layer 1 policy input.
|
|
76
|
+
*/
|
|
77
|
+
readonly official: boolean;
|
|
78
|
+
/** Capabilities the caller declared it wants. */
|
|
79
|
+
readonly capabilities: ReadonlySet<string>;
|
|
80
|
+
/** Root origin of the call chain. */
|
|
81
|
+
readonly origin: ExposedApiOrigin;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Projects a giver's instance into the view one caller receives.
|
|
85
|
+
*
|
|
86
|
+
* This is Layer 2: optional narrowing by the giver. It runs only after the
|
|
87
|
+
* kernel has enforced Layer 1, and it can never widen what Layer 1 decided,
|
|
88
|
+
* because Layer 1 is evaluated again on every use of the handle.
|
|
89
|
+
*/
|
|
90
|
+
export type ExposedApiProjection = (service: unknown, caller: ExposedApiCaller) => unknown;
|
|
91
|
+
/** How a giver's code binds one declared exposure. */
|
|
92
|
+
export interface ExposedApiBinding {
|
|
93
|
+
/** Layer 2 projection. Defaults to the giver's instance itself. */
|
|
94
|
+
readonly projection?: ExposedApiProjection;
|
|
95
|
+
}
|
|
96
|
+
/** Options for one resolve. */
|
|
97
|
+
export interface ExposedApiResolveOptions {
|
|
98
|
+
/** API version: a major version or a semantic version. Defaults to 1. */
|
|
99
|
+
readonly version?: ExposedApiVersion;
|
|
100
|
+
/**
|
|
101
|
+
* Identity token the caller expects to own the exposure.
|
|
102
|
+
*
|
|
103
|
+
* The resolve fails when the registered owner differs.
|
|
104
|
+
*/
|
|
105
|
+
readonly expectedOwner?: string;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Returns the major version of a valid API version.
|
|
109
|
+
*
|
|
110
|
+
* @param version - A valid API version.
|
|
111
|
+
*/
|
|
112
|
+
export declare function exposedApiMajor(version: ExposedApiVersion): number;
|