@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,59 @@
|
|
|
1
|
+
import type { IKernelAccessBroker } from './accessBroker.js';
|
|
2
|
+
/**
|
|
3
|
+
* Privilege tier a service belongs to, ordered from most to least trusted.
|
|
4
|
+
*/
|
|
5
|
+
export type ServiceTier = 'kernel' | 'core' | 'userland';
|
|
6
|
+
/**
|
|
7
|
+
* Minimal diagnostic logger surface a kernel can inject into services.
|
|
8
|
+
*
|
|
9
|
+
* Services treat it as an optional sink: the kernel supplies it during boot,
|
|
10
|
+
* but standalone construction (tests, adapters) may omit it.
|
|
11
|
+
*/
|
|
12
|
+
export interface KernelLogger {
|
|
13
|
+
/** Emits a structured, non-fatal diagnostic warning. */
|
|
14
|
+
warn(message: string, meta?: Record<string, unknown>): void;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Ambient context supplied to a service at construction and access time.
|
|
18
|
+
*/
|
|
19
|
+
export interface ServiceContext {
|
|
20
|
+
/** Identifier of the caller or service this context describes. */
|
|
21
|
+
readonly callerId: string;
|
|
22
|
+
/** Privilege tier of the caller. */
|
|
23
|
+
readonly tier: ServiceTier;
|
|
24
|
+
/**
|
|
25
|
+
* Opaque host-supplied options bag.
|
|
26
|
+
*
|
|
27
|
+
* The kernel stores the bag at boot and attaches it unchanged to every
|
|
28
|
+
* service context. The core never inspects a key; services read the options
|
|
29
|
+
* their own domain owns.
|
|
30
|
+
*/
|
|
31
|
+
readonly options: Readonly<Record<string, unknown>>;
|
|
32
|
+
/** Kernel diagnostic sink. Absent in standalone construction. */
|
|
33
|
+
readonly logger?: KernelLogger;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Optional lifecycle hooks a service may implement.
|
|
37
|
+
*/
|
|
38
|
+
export interface IServiceLifecycle {
|
|
39
|
+
/**
|
|
40
|
+
* Prepares the service for use. Called once during kernel boot.
|
|
41
|
+
*
|
|
42
|
+
* @param broker - Mediated access broker for resolving dependencies.
|
|
43
|
+
*/
|
|
44
|
+
initialize?(broker: IKernelAccessBroker): Promise<void> | void;
|
|
45
|
+
/**
|
|
46
|
+
* Starts work that needs other services through the broker. Called once,
|
|
47
|
+
* after the kernel enters `RUNNING` and before `boot()` resolves, in the same
|
|
48
|
+
* dependency order as {@link IServiceLifecycle.initialize}.
|
|
49
|
+
*
|
|
50
|
+
* The broker grants access here, unlike during `initialize()`. If this hook
|
|
51
|
+
* throws, the kernel disposes every initialized service in reverse order,
|
|
52
|
+
* ends `DISPOSED`, and `boot()` rejects with the original error.
|
|
53
|
+
*
|
|
54
|
+
* @param broker - Mediated access broker for resolving dependencies.
|
|
55
|
+
*/
|
|
56
|
+
onRunning?(broker: IKernelAccessBroker): Promise<void> | void;
|
|
57
|
+
/** Releases resources held by the service. Called once during shutdown. */
|
|
58
|
+
dispose?(): Promise<void> | void;
|
|
59
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Participant manifest.
|
|
3
|
+
*
|
|
4
|
+
* A manifest is declarative data. It states what a participant requests and
|
|
5
|
+
* which exposures it gives, with the scope and policy of each. It contains no
|
|
6
|
+
* executable code. The kernel admits it at boot without invoking the
|
|
7
|
+
* participant's factory, and the participant's code cannot add, change, or
|
|
8
|
+
* remove an exposure afterwards.
|
|
9
|
+
*/
|
|
10
|
+
/** What a participant requests. A request is not a grant; the giver decides. */
|
|
11
|
+
export interface ParticipantRequests {
|
|
12
|
+
/** Capability tokens the participant asks for. */
|
|
13
|
+
readonly capabilities?: readonly string[];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* One exposure a participant declares.
|
|
17
|
+
*
|
|
18
|
+
* The resolution primitive interprets and validates every field. The kernel
|
|
19
|
+
* core carries the declaration unchanged.
|
|
20
|
+
*/
|
|
21
|
+
export interface ExposureDeclaration {
|
|
22
|
+
/** Stable exposure name. */
|
|
23
|
+
readonly name: string;
|
|
24
|
+
/** Version: a positive integer major version or a semantic version. */
|
|
25
|
+
readonly version?: number | string;
|
|
26
|
+
/** Reachability scope. */
|
|
27
|
+
readonly scope?: string;
|
|
28
|
+
/** Declarative Layer 1 policy for this exposure. */
|
|
29
|
+
readonly policy?: Readonly<Record<string, unknown>>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* One event a participant declares.
|
|
33
|
+
*
|
|
34
|
+
* A separate type from {@link ExposureDeclaration}: events are a push-model
|
|
35
|
+
* observable, not a pull-model callable. For Step 3 the field set matches the
|
|
36
|
+
* exposure declaration; the payload schema is deferred to the delivery step.
|
|
37
|
+
*/
|
|
38
|
+
export interface EventDeclaration {
|
|
39
|
+
/** Stable event name. */
|
|
40
|
+
readonly name: string;
|
|
41
|
+
/** Version: a positive integer major version or a semantic version. */
|
|
42
|
+
readonly version?: number | string;
|
|
43
|
+
/** Reachability scope. */
|
|
44
|
+
readonly scope?: string;
|
|
45
|
+
/** Declarative Layer 1 policy for this event. */
|
|
46
|
+
readonly policy?: Readonly<Record<string, unknown>>;
|
|
47
|
+
/**
|
|
48
|
+
* JSON Schema subset the emitted payload must satisfy. Admission checks only
|
|
49
|
+
* that it is an object; the schema itself is compiled and enforced at emit.
|
|
50
|
+
*/
|
|
51
|
+
readonly payloadSchema?: Readonly<Record<string, unknown>>;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* One interception a participant declares: it asks to intercept calls to an
|
|
55
|
+
* exposure another participant gives. Held only by the interception hardcore;
|
|
56
|
+
* it is not an exposure and is not reachable through `resolve`.
|
|
57
|
+
*/
|
|
58
|
+
export interface InterceptionDeclaration {
|
|
59
|
+
/** Exposure name to intercept. */
|
|
60
|
+
readonly target: string;
|
|
61
|
+
/** Major version of the target; defaults to 1. */
|
|
62
|
+
readonly version?: number | string;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* One interception point a giver declares on one of its own exposures, naming
|
|
66
|
+
* (by service token) the interceptors it admits, in the order they run.
|
|
67
|
+
*/
|
|
68
|
+
export interface InterceptionPointDeclaration {
|
|
69
|
+
/** The giver's own exposure name. */
|
|
70
|
+
readonly exposure: string;
|
|
71
|
+
/** Major version of the exposure; defaults to 1. */
|
|
72
|
+
readonly version?: number | string;
|
|
73
|
+
/** Optional public description of the kind (shown to remote clients). */
|
|
74
|
+
readonly description?: string;
|
|
75
|
+
/**
|
|
76
|
+
* Optional public operations of the kind: name → description and a JSON
|
|
77
|
+
* Schema for its input. Plain JSON data; the owner may serve more.
|
|
78
|
+
*/
|
|
79
|
+
readonly operations?: Readonly<Record<string, KindOperationDescription>>;
|
|
80
|
+
/** Service tokens of the admitted interceptors, in run order. */
|
|
81
|
+
readonly admit: readonly string[];
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* One Brud Syntax kind a participant claims, served by one of its own
|
|
85
|
+
* exposures (which must provide `dispatch(operation, context)`).
|
|
86
|
+
*/
|
|
87
|
+
/** Public description of one operation of a kind. */
|
|
88
|
+
export interface KindOperationDescription {
|
|
89
|
+
readonly description?: string;
|
|
90
|
+
/** JSON Schema of the operation's input (plain JSON). */
|
|
91
|
+
readonly input?: Readonly<Record<string, unknown>>;
|
|
92
|
+
}
|
|
93
|
+
export interface KindDeclaration {
|
|
94
|
+
/** The kind word written after `[CALL`, e.g. `tool`. */
|
|
95
|
+
readonly kind: string;
|
|
96
|
+
/** The participant's own exposure name that dispatches the kind. */
|
|
97
|
+
readonly exposure: string;
|
|
98
|
+
/** Major version of the exposure; defaults to 1. */
|
|
99
|
+
readonly version?: number | string;
|
|
100
|
+
}
|
|
101
|
+
/** A participant's manifest. */
|
|
102
|
+
export interface ParticipantManifest {
|
|
103
|
+
/** What the participant requests. */
|
|
104
|
+
readonly requests?: ParticipantRequests;
|
|
105
|
+
/** Exposures the participant gives. */
|
|
106
|
+
readonly exposures?: readonly ExposureDeclaration[];
|
|
107
|
+
/** Events the participant declares. */
|
|
108
|
+
readonly events?: readonly EventDeclaration[];
|
|
109
|
+
/** Interceptions the participant asks for. */
|
|
110
|
+
readonly interceptions?: readonly InterceptionDeclaration[];
|
|
111
|
+
/** Interception points the participant opens on its own exposures. */
|
|
112
|
+
readonly interceptionPoints?: readonly InterceptionPointDeclaration[];
|
|
113
|
+
readonly kinds?: readonly KindDeclaration[];
|
|
114
|
+
}
|
|
115
|
+
/** A manifest after the kernel has validated and frozen it. */
|
|
116
|
+
export interface AdmittedManifest {
|
|
117
|
+
/** Requested capability tokens, deduplicated, in declaration order. */
|
|
118
|
+
readonly capabilities: readonly string[];
|
|
119
|
+
/** Declared exposures, deep-copied and frozen. */
|
|
120
|
+
readonly exposures: readonly ExposureDeclaration[];
|
|
121
|
+
/** Declared events, deep-copied and frozen. */
|
|
122
|
+
readonly events: readonly EventDeclaration[];
|
|
123
|
+
/** Declared interceptions, deep-copied and frozen. */
|
|
124
|
+
readonly interceptions: readonly InterceptionDeclaration[];
|
|
125
|
+
/** Declared interception points, deep-copied and frozen. */
|
|
126
|
+
readonly interceptionPoints: readonly InterceptionPointDeclaration[];
|
|
127
|
+
readonly kinds: readonly KindDeclaration[];
|
|
128
|
+
}
|
|
129
|
+
/** Raised when a manifest is not valid declarative data. */
|
|
130
|
+
export declare class ParticipantManifestError extends Error {
|
|
131
|
+
readonly code: "PARTICIPANT_MANIFEST_INVALID";
|
|
132
|
+
/** Token id of the participant whose manifest was refused. */
|
|
133
|
+
readonly participant: string;
|
|
134
|
+
constructor(participant: string, reason: string);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Validates and freezes a participant's manifest.
|
|
138
|
+
*
|
|
139
|
+
* Fails closed: an unknown field, a non-data value, or a malformed shape refuses
|
|
140
|
+
* the manifest. An absent manifest admits no requests and no exposures.
|
|
141
|
+
*
|
|
142
|
+
* @param participant - Token id of the participant, used in diagnostics.
|
|
143
|
+
* @param manifest - The declared manifest, or `undefined`.
|
|
144
|
+
*/
|
|
145
|
+
export declare function admitParticipantManifest(participant: string, manifest: unknown): AdmittedManifest;
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Participant manifest.
|
|
3
|
+
*
|
|
4
|
+
* A manifest is declarative data. It states what a participant requests and
|
|
5
|
+
* which exposures it gives, with the scope and policy of each. It contains no
|
|
6
|
+
* executable code. The kernel admits it at boot without invoking the
|
|
7
|
+
* participant's factory, and the participant's code cannot add, change, or
|
|
8
|
+
* remove an exposure afterwards.
|
|
9
|
+
*/
|
|
10
|
+
/** Raised when a manifest is not valid declarative data. */
|
|
11
|
+
export class ParticipantManifestError extends Error {
|
|
12
|
+
code = 'PARTICIPANT_MANIFEST_INVALID';
|
|
13
|
+
/** Token id of the participant whose manifest was refused. */
|
|
14
|
+
participant;
|
|
15
|
+
constructor(participant, reason) {
|
|
16
|
+
super(`Manifest of participant "${participant}" is invalid: ${reason}`);
|
|
17
|
+
this.name = 'ParticipantManifestError';
|
|
18
|
+
this.participant = participant;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const MANIFEST_KEYS = new Set(['requests', 'exposures', 'events', 'interceptions', 'interceptionPoints', 'kinds']);
|
|
22
|
+
const KIND_KEYS = new Set(['kind', 'exposure', 'version', 'description', 'operations']);
|
|
23
|
+
const KIND_OPERATION_KEYS = new Set(['description', 'input']);
|
|
24
|
+
const KIND_PATTERN = /^[a-z][a-z0-9_-]*$/u;
|
|
25
|
+
const REQUEST_KEYS = new Set(['capabilities']);
|
|
26
|
+
const EXPOSURE_KEYS = new Set(['name', 'version', 'scope', 'policy']);
|
|
27
|
+
const EVENT_KEYS = new Set(['name', 'version', 'scope', 'policy', 'payloadSchema']);
|
|
28
|
+
const INTERCEPTION_KEYS = new Set(['target', 'version']);
|
|
29
|
+
const INTERCEPTION_POINT_KEYS = new Set(['exposure', 'version', 'admit']);
|
|
30
|
+
function isPlainObject(value) {
|
|
31
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value)) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
const prototype = Object.getPrototypeOf(value);
|
|
35
|
+
return prototype === Object.prototype || prototype === null;
|
|
36
|
+
}
|
|
37
|
+
/** Deep-copies plain JSON data, refusing anything that is not plain data. */
|
|
38
|
+
function cloneData(value, path, participant) {
|
|
39
|
+
if (value === null || typeof value === 'string' || typeof value === 'boolean') {
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
if (typeof value === 'number') {
|
|
43
|
+
if (!Number.isFinite(value)) {
|
|
44
|
+
throw new ParticipantManifestError(participant, `${path} must be a finite number`);
|
|
45
|
+
}
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
if (Array.isArray(value)) {
|
|
49
|
+
return Object.freeze(value.map((item, index) => cloneData(item, `${path}[${String(index)}]`, participant)));
|
|
50
|
+
}
|
|
51
|
+
if (isPlainObject(value)) {
|
|
52
|
+
const copy = {};
|
|
53
|
+
for (const [key, item] of Object.entries(value)) {
|
|
54
|
+
copy[key] = cloneData(item, `${path}.${key}`, participant);
|
|
55
|
+
}
|
|
56
|
+
return Object.freeze(copy);
|
|
57
|
+
}
|
|
58
|
+
throw new ParticipantManifestError(participant, `${path} must be declarative data, not code`);
|
|
59
|
+
}
|
|
60
|
+
function assertKnownKeys(value, allowed, path, participant) {
|
|
61
|
+
for (const key of Object.keys(value)) {
|
|
62
|
+
if (!allowed.has(key)) {
|
|
63
|
+
throw new ParticipantManifestError(participant, `${path} has unknown field "${key}"`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Validates and freezes a participant's manifest.
|
|
69
|
+
*
|
|
70
|
+
* Fails closed: an unknown field, a non-data value, or a malformed shape refuses
|
|
71
|
+
* the manifest. An absent manifest admits no requests and no exposures.
|
|
72
|
+
*
|
|
73
|
+
* @param participant - Token id of the participant, used in diagnostics.
|
|
74
|
+
* @param manifest - The declared manifest, or `undefined`.
|
|
75
|
+
*/
|
|
76
|
+
export function admitParticipantManifest(participant, manifest) {
|
|
77
|
+
if (manifest === undefined) {
|
|
78
|
+
return Object.freeze({
|
|
79
|
+
capabilities: Object.freeze([]),
|
|
80
|
+
exposures: Object.freeze([]),
|
|
81
|
+
events: Object.freeze([]),
|
|
82
|
+
interceptions: Object.freeze([]),
|
|
83
|
+
interceptionPoints: Object.freeze([]),
|
|
84
|
+
kinds: Object.freeze([]),
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
const data = cloneData(manifest, 'manifest', participant);
|
|
88
|
+
if (!isPlainObject(data)) {
|
|
89
|
+
throw new ParticipantManifestError(participant, 'manifest must be an object');
|
|
90
|
+
}
|
|
91
|
+
assertKnownKeys(data, MANIFEST_KEYS, 'manifest', participant);
|
|
92
|
+
const capabilities = [];
|
|
93
|
+
const requests = data.requests;
|
|
94
|
+
if (requests !== undefined) {
|
|
95
|
+
if (!isPlainObject(requests)) {
|
|
96
|
+
throw new ParticipantManifestError(participant, 'manifest.requests must be an object');
|
|
97
|
+
}
|
|
98
|
+
assertKnownKeys(requests, REQUEST_KEYS, 'manifest.requests', participant);
|
|
99
|
+
const requested = requests.capabilities;
|
|
100
|
+
if (requested !== undefined) {
|
|
101
|
+
if (!Array.isArray(requested)) {
|
|
102
|
+
throw new ParticipantManifestError(participant, 'manifest.requests.capabilities must be an array');
|
|
103
|
+
}
|
|
104
|
+
for (const capability of requested) {
|
|
105
|
+
if (typeof capability !== 'string' || capability.length === 0) {
|
|
106
|
+
throw new ParticipantManifestError(participant, 'manifest.requests.capabilities must contain non-empty strings');
|
|
107
|
+
}
|
|
108
|
+
if (!capabilities.includes(capability)) {
|
|
109
|
+
capabilities.push(capability);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const exposures = [];
|
|
115
|
+
const declared = data.exposures;
|
|
116
|
+
if (declared !== undefined) {
|
|
117
|
+
if (!Array.isArray(declared)) {
|
|
118
|
+
throw new ParticipantManifestError(participant, 'manifest.exposures must be an array');
|
|
119
|
+
}
|
|
120
|
+
declared.forEach((exposure, index) => {
|
|
121
|
+
const path = `manifest.exposures[${String(index)}]`;
|
|
122
|
+
if (!isPlainObject(exposure)) {
|
|
123
|
+
throw new ParticipantManifestError(participant, `${path} must be an object`);
|
|
124
|
+
}
|
|
125
|
+
assertKnownKeys(exposure, EXPOSURE_KEYS, path, participant);
|
|
126
|
+
if (typeof exposure.name !== 'string' || exposure.name.length === 0) {
|
|
127
|
+
throw new ParticipantManifestError(participant, `${path}.name must be a non-empty string`);
|
|
128
|
+
}
|
|
129
|
+
if (exposure.version !== undefined
|
|
130
|
+
&& typeof exposure.version !== 'number'
|
|
131
|
+
&& typeof exposure.version !== 'string') {
|
|
132
|
+
throw new ParticipantManifestError(participant, `${path}.version must be a number or string`);
|
|
133
|
+
}
|
|
134
|
+
if (exposure.scope !== undefined && typeof exposure.scope !== 'string') {
|
|
135
|
+
throw new ParticipantManifestError(participant, `${path}.scope must be a string`);
|
|
136
|
+
}
|
|
137
|
+
if (exposure.policy !== undefined && !isPlainObject(exposure.policy)) {
|
|
138
|
+
throw new ParticipantManifestError(participant, `${path}.policy must be an object`);
|
|
139
|
+
}
|
|
140
|
+
exposures.push(exposure);
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
const events = [];
|
|
144
|
+
const declaredEvents = data.events;
|
|
145
|
+
if (declaredEvents !== undefined) {
|
|
146
|
+
if (!Array.isArray(declaredEvents)) {
|
|
147
|
+
throw new ParticipantManifestError(participant, 'manifest.events must be an array');
|
|
148
|
+
}
|
|
149
|
+
declaredEvents.forEach((event, index) => {
|
|
150
|
+
const path = `manifest.events[${String(index)}]`;
|
|
151
|
+
if (!isPlainObject(event)) {
|
|
152
|
+
throw new ParticipantManifestError(participant, `${path} must be an object`);
|
|
153
|
+
}
|
|
154
|
+
assertKnownKeys(event, EVENT_KEYS, path, participant);
|
|
155
|
+
if (typeof event.name !== 'string' || event.name.length === 0) {
|
|
156
|
+
throw new ParticipantManifestError(participant, `${path}.name must be a non-empty string`);
|
|
157
|
+
}
|
|
158
|
+
if (event.version !== undefined
|
|
159
|
+
&& typeof event.version !== 'number'
|
|
160
|
+
&& typeof event.version !== 'string') {
|
|
161
|
+
throw new ParticipantManifestError(participant, `${path}.version must be a number or string`);
|
|
162
|
+
}
|
|
163
|
+
if (event.scope !== undefined && typeof event.scope !== 'string') {
|
|
164
|
+
throw new ParticipantManifestError(participant, `${path}.scope must be a string`);
|
|
165
|
+
}
|
|
166
|
+
if (event.policy !== undefined && !isPlainObject(event.policy)) {
|
|
167
|
+
throw new ParticipantManifestError(participant, `${path}.policy must be an object`);
|
|
168
|
+
}
|
|
169
|
+
if (event.payloadSchema !== undefined && !isPlainObject(event.payloadSchema)) {
|
|
170
|
+
throw new ParticipantManifestError(participant, `${path}.payloadSchema must be an object`);
|
|
171
|
+
}
|
|
172
|
+
events.push(event);
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
const interceptions = admitInterceptions(data.interceptions, participant);
|
|
176
|
+
const interceptionPoints = admitInterceptionPoints(data.interceptionPoints, participant);
|
|
177
|
+
const kinds = admitKinds(data.kinds, exposures, participant);
|
|
178
|
+
return Object.freeze({
|
|
179
|
+
capabilities: Object.freeze(capabilities),
|
|
180
|
+
exposures: Object.freeze(exposures),
|
|
181
|
+
events: Object.freeze(events),
|
|
182
|
+
interceptions,
|
|
183
|
+
interceptionPoints,
|
|
184
|
+
kinds,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
function assertVersion(value, path, participant) {
|
|
188
|
+
if (value !== undefined && typeof value !== 'number' && typeof value !== 'string') {
|
|
189
|
+
throw new ParticipantManifestError(participant, `${path}.version must be a number or string`);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
function admitInterceptions(value, participant) {
|
|
193
|
+
if (value === undefined) {
|
|
194
|
+
return Object.freeze([]);
|
|
195
|
+
}
|
|
196
|
+
if (!Array.isArray(value)) {
|
|
197
|
+
throw new ParticipantManifestError(participant, 'manifest.interceptions must be an array');
|
|
198
|
+
}
|
|
199
|
+
return Object.freeze(value.map((entry, index) => {
|
|
200
|
+
const path = `manifest.interceptions[${String(index)}]`;
|
|
201
|
+
if (!isPlainObject(entry)) {
|
|
202
|
+
throw new ParticipantManifestError(participant, `${path} must be an object`);
|
|
203
|
+
}
|
|
204
|
+
assertKnownKeys(entry, INTERCEPTION_KEYS, path, participant);
|
|
205
|
+
if (typeof entry.target !== 'string' || entry.target.length === 0) {
|
|
206
|
+
throw new ParticipantManifestError(participant, `${path}.target must be a non-empty string`);
|
|
207
|
+
}
|
|
208
|
+
assertVersion(entry.version, path, participant);
|
|
209
|
+
return Object.freeze(entry);
|
|
210
|
+
}));
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Admits `manifest.kinds`. Each kind names one of the participant's own
|
|
214
|
+
* declared exposures; a kind may be claimed once per manifest.
|
|
215
|
+
*/
|
|
216
|
+
function admitKinds(value, exposures, participant) {
|
|
217
|
+
if (value === undefined) {
|
|
218
|
+
return Object.freeze([]);
|
|
219
|
+
}
|
|
220
|
+
if (!Array.isArray(value)) {
|
|
221
|
+
throw new ParticipantManifestError(participant, 'manifest.kinds must be an array');
|
|
222
|
+
}
|
|
223
|
+
const seen = new Set();
|
|
224
|
+
return Object.freeze(value.map((entry, index) => {
|
|
225
|
+
const path = `manifest.kinds[${String(index)}]`;
|
|
226
|
+
if (!isPlainObject(entry)) {
|
|
227
|
+
throw new ParticipantManifestError(participant, `${path} must be an object`);
|
|
228
|
+
}
|
|
229
|
+
assertKnownKeys(entry, KIND_KEYS, path, participant);
|
|
230
|
+
if (typeof entry.kind !== 'string' || !KIND_PATTERN.test(entry.kind)) {
|
|
231
|
+
throw new ParticipantManifestError(participant, `${path}.kind must be a lower-case kind word`);
|
|
232
|
+
}
|
|
233
|
+
if (seen.has(entry.kind)) {
|
|
234
|
+
throw new ParticipantManifestError(participant, `${path}.kind "${entry.kind}" is claimed twice`);
|
|
235
|
+
}
|
|
236
|
+
seen.add(entry.kind);
|
|
237
|
+
if (typeof entry.exposure !== 'string' || entry.exposure.length === 0) {
|
|
238
|
+
throw new ParticipantManifestError(participant, `${path}.exposure must be a non-empty string`);
|
|
239
|
+
}
|
|
240
|
+
assertVersion(entry.version, path, participant);
|
|
241
|
+
const major = String(entry.version ?? 1);
|
|
242
|
+
if (!exposures.some((exposure) => exposure.name === entry.exposure && String(exposure.version ?? 1) === major)) {
|
|
243
|
+
throw new ParticipantManifestError(participant, `${path}.exposure must name one of the participant's own declared exposures`);
|
|
244
|
+
}
|
|
245
|
+
if (entry.description !== undefined && typeof entry.description !== 'string') {
|
|
246
|
+
throw new ParticipantManifestError(participant, `${path}.description must be a string`);
|
|
247
|
+
}
|
|
248
|
+
if (entry.operations !== undefined) {
|
|
249
|
+
if (!isPlainObject(entry.operations)) {
|
|
250
|
+
throw new ParticipantManifestError(participant, `${path}.operations must be an object`);
|
|
251
|
+
}
|
|
252
|
+
for (const [name, operation] of Object.entries(entry.operations)) {
|
|
253
|
+
const at = `${path}.operations.${name}`;
|
|
254
|
+
if (!isPlainObject(operation)) {
|
|
255
|
+
throw new ParticipantManifestError(participant, `${at} must be an object`);
|
|
256
|
+
}
|
|
257
|
+
assertKnownKeys(operation, KIND_OPERATION_KEYS, at, participant);
|
|
258
|
+
if (operation.description !== undefined && typeof operation.description !== 'string') {
|
|
259
|
+
throw new ParticipantManifestError(participant, `${at}.description must be a string`);
|
|
260
|
+
}
|
|
261
|
+
if (operation.input !== undefined && !isPlainObject(operation.input)) {
|
|
262
|
+
throw new ParticipantManifestError(participant, `${at}.input must be a JSON Schema object`);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
// Deep copy so the admitted declaration is plain, frozen data.
|
|
267
|
+
return Object.freeze(JSON.parse(JSON.stringify(entry)));
|
|
268
|
+
}));
|
|
269
|
+
}
|
|
270
|
+
function admitInterceptionPoints(value, participant) {
|
|
271
|
+
if (value === undefined) {
|
|
272
|
+
return Object.freeze([]);
|
|
273
|
+
}
|
|
274
|
+
if (!Array.isArray(value)) {
|
|
275
|
+
throw new ParticipantManifestError(participant, 'manifest.interceptionPoints must be an array');
|
|
276
|
+
}
|
|
277
|
+
return Object.freeze(value.map((entry, index) => {
|
|
278
|
+
const path = `manifest.interceptionPoints[${String(index)}]`;
|
|
279
|
+
if (!isPlainObject(entry)) {
|
|
280
|
+
throw new ParticipantManifestError(participant, `${path} must be an object`);
|
|
281
|
+
}
|
|
282
|
+
assertKnownKeys(entry, INTERCEPTION_POINT_KEYS, path, participant);
|
|
283
|
+
if (typeof entry.exposure !== 'string' || entry.exposure.length === 0) {
|
|
284
|
+
throw new ParticipantManifestError(participant, `${path}.exposure must be a non-empty string`);
|
|
285
|
+
}
|
|
286
|
+
assertVersion(entry.version, path, participant);
|
|
287
|
+
const admit = entry.admit;
|
|
288
|
+
if (!Array.isArray(admit)
|
|
289
|
+
|| admit.some((token) => typeof token !== 'string' || token.length === 0)
|
|
290
|
+
|| new Set(admit).size !== admit.length) {
|
|
291
|
+
throw new ParticipantManifestError(participant, `${path}.admit must be an array of unique non-empty service tokens`);
|
|
292
|
+
}
|
|
293
|
+
return Object.freeze({ ...entry, admit: Object.freeze([...admit]) });
|
|
294
|
+
}));
|
|
295
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ExecutionContext } from './context.js';
|
|
2
|
+
import type { OperationHandler, OperationResult } from './handler.js';
|
|
3
|
+
export type MiddlewareNext = () => Promise<OperationResult>;
|
|
4
|
+
export type Middleware = (context: ExecutionContext, input: unknown, next: MiddlewareNext) => Promise<OperationResult>;
|
|
5
|
+
export interface IExecutionPipeline {
|
|
6
|
+
use(middleware: Middleware): void;
|
|
7
|
+
execute<TInput, TOutput>(handler: OperationHandler<TInput, TOutput>, context: ExecutionContext, input: TInput): Promise<OperationResult<TOutput>>;
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { ServiceToken } from './serviceToken.js';
|
|
2
|
+
/**
|
|
3
|
+
* Declarative access control rules applied when a caller requests a service.
|
|
4
|
+
*
|
|
5
|
+
* A denied caller is always rejected. When `allowedCallers` is provided, only
|
|
6
|
+
* the listed callers may access the service; otherwise access is open.
|
|
7
|
+
*/
|
|
8
|
+
export interface ServiceAccessPolicy {
|
|
9
|
+
/** Callers that can never access the service. */
|
|
10
|
+
readonly deniedCallers?: readonly (string | ServiceToken<unknown>)[];
|
|
11
|
+
/** Callers explicitly permitted to access the service. */
|
|
12
|
+
readonly allowedCallers?: readonly (string | ServiceToken<unknown>)[];
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Base class for every rejection produced by a service access policy.
|
|
16
|
+
*
|
|
17
|
+
* Callers should branch on this type when they only need to know that the
|
|
18
|
+
* broker refused access; the concrete subclasses carry the finer reason.
|
|
19
|
+
*/
|
|
20
|
+
export declare abstract class AccessDeniedError extends Error {
|
|
21
|
+
/** Stable, machine-readable error code. */
|
|
22
|
+
abstract readonly code: string;
|
|
23
|
+
/** Identifier of the caller that attempted access. */
|
|
24
|
+
readonly callerId: string;
|
|
25
|
+
/** Identifier of the service that denied access. */
|
|
26
|
+
readonly targetServiceId: string;
|
|
27
|
+
/**
|
|
28
|
+
* @param message - Path-free, human-readable denial description.
|
|
29
|
+
* @param callerId - Identifier of the caller that attempted access.
|
|
30
|
+
* @param targetServiceId - Identifier of the service that denied access.
|
|
31
|
+
*/
|
|
32
|
+
protected constructor(message: string, callerId: string, targetServiceId: string);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Raised when a caller matches the deny list of a service's access policy.
|
|
36
|
+
*/
|
|
37
|
+
export declare class BlacklistedAccessViolationError extends AccessDeniedError {
|
|
38
|
+
/** Stable, machine-readable error code. */
|
|
39
|
+
readonly code: "BLACKLISTED_ACCESS";
|
|
40
|
+
/** Explanation of why the caller was denied. */
|
|
41
|
+
readonly reason: string;
|
|
42
|
+
/**
|
|
43
|
+
* @param callerId - Identifier of the caller that attempted access.
|
|
44
|
+
* @param targetServiceId - Identifier of the service that denied access.
|
|
45
|
+
* @param reason - Explanation of why the caller was denied.
|
|
46
|
+
*/
|
|
47
|
+
constructor(callerId: string, targetServiceId: string, reason: string);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Raised when a caller is not present in a service's allow list.
|
|
51
|
+
*/
|
|
52
|
+
/**
|
|
53
|
+
* Raised when a caller inside a kernel call chain asserts a caller id that is
|
|
54
|
+
* not the identity the kernel admitted it with. Token access binds to the
|
|
55
|
+
* call chain: a participant can only ever be itself.
|
|
56
|
+
*/
|
|
57
|
+
export declare class CallerIdentityMismatchError extends AccessDeniedError {
|
|
58
|
+
/** Stable, machine-readable error code. */
|
|
59
|
+
readonly code: "CALLER_IDENTITY_MISMATCH";
|
|
60
|
+
/**
|
|
61
|
+
* @param assertedCallerId - Caller id the requester supplied.
|
|
62
|
+
* @param targetServiceId - Identifier of the service requested.
|
|
63
|
+
* @param boundCallerId - Caller id the call chain binds the requester to, if any.
|
|
64
|
+
*/
|
|
65
|
+
constructor(assertedCallerId: string, targetServiceId: string, boundCallerId: string | undefined);
|
|
66
|
+
}
|
|
67
|
+
export declare class AllowlistViolationError extends AccessDeniedError {
|
|
68
|
+
/** Stable, machine-readable error code. */
|
|
69
|
+
readonly code: "NOT_IN_ALLOWLIST";
|
|
70
|
+
/**
|
|
71
|
+
* @param callerId - Identifier of the caller that attempted access.
|
|
72
|
+
* @param targetServiceId - Identifier of the service that denied access.
|
|
73
|
+
*/
|
|
74
|
+
constructor(callerId: string, targetServiceId: string);
|
|
75
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base class for every rejection produced by a service access policy.
|
|
3
|
+
*
|
|
4
|
+
* Callers should branch on this type when they only need to know that the
|
|
5
|
+
* broker refused access; the concrete subclasses carry the finer reason.
|
|
6
|
+
*/
|
|
7
|
+
export class AccessDeniedError extends Error {
|
|
8
|
+
/** Identifier of the caller that attempted access. */
|
|
9
|
+
callerId;
|
|
10
|
+
/** Identifier of the service that denied access. */
|
|
11
|
+
targetServiceId;
|
|
12
|
+
/**
|
|
13
|
+
* @param message - Path-free, human-readable denial description.
|
|
14
|
+
* @param callerId - Identifier of the caller that attempted access.
|
|
15
|
+
* @param targetServiceId - Identifier of the service that denied access.
|
|
16
|
+
*/
|
|
17
|
+
constructor(message, callerId, targetServiceId) {
|
|
18
|
+
super(message);
|
|
19
|
+
this.name = 'AccessDeniedError';
|
|
20
|
+
this.callerId = callerId;
|
|
21
|
+
this.targetServiceId = targetServiceId;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Raised when a caller matches the deny list of a service's access policy.
|
|
26
|
+
*/
|
|
27
|
+
export class BlacklistedAccessViolationError extends AccessDeniedError {
|
|
28
|
+
/** Stable, machine-readable error code. */
|
|
29
|
+
code = 'BLACKLISTED_ACCESS';
|
|
30
|
+
/** Explanation of why the caller was denied. */
|
|
31
|
+
reason;
|
|
32
|
+
/**
|
|
33
|
+
* @param callerId - Identifier of the caller that attempted access.
|
|
34
|
+
* @param targetServiceId - Identifier of the service that denied access.
|
|
35
|
+
* @param reason - Explanation of why the caller was denied.
|
|
36
|
+
*/
|
|
37
|
+
constructor(callerId, targetServiceId, reason) {
|
|
38
|
+
super(`Caller "${callerId}" is blacklisted from service "${targetServiceId}": ${reason}`, callerId, targetServiceId);
|
|
39
|
+
this.name = 'BlacklistedAccessViolationError';
|
|
40
|
+
this.reason = reason;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Raised when a caller is not present in a service's allow list.
|
|
45
|
+
*/
|
|
46
|
+
/**
|
|
47
|
+
* Raised when a caller inside a kernel call chain asserts a caller id that is
|
|
48
|
+
* not the identity the kernel admitted it with. Token access binds to the
|
|
49
|
+
* call chain: a participant can only ever be itself.
|
|
50
|
+
*/
|
|
51
|
+
export class CallerIdentityMismatchError extends AccessDeniedError {
|
|
52
|
+
/** Stable, machine-readable error code. */
|
|
53
|
+
code = 'CALLER_IDENTITY_MISMATCH';
|
|
54
|
+
/**
|
|
55
|
+
* @param assertedCallerId - Caller id the requester supplied.
|
|
56
|
+
* @param targetServiceId - Identifier of the service requested.
|
|
57
|
+
* @param boundCallerId - Caller id the call chain binds the requester to, if any.
|
|
58
|
+
*/
|
|
59
|
+
constructor(assertedCallerId, targetServiceId, boundCallerId) {
|
|
60
|
+
super(boundCallerId === undefined
|
|
61
|
+
? `Caller "${assertedCallerId}" is not an admitted identity in this call chain (service "${targetServiceId}")`
|
|
62
|
+
: `Caller "${assertedCallerId}" does not match its call-chain identity "${boundCallerId}" (service "${targetServiceId}")`, assertedCallerId, targetServiceId);
|
|
63
|
+
this.name = 'CallerIdentityMismatchError';
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
export class AllowlistViolationError extends AccessDeniedError {
|
|
67
|
+
/** Stable, machine-readable error code. */
|
|
68
|
+
code = 'NOT_IN_ALLOWLIST';
|
|
69
|
+
/**
|
|
70
|
+
* @param callerId - Identifier of the caller that attempted access.
|
|
71
|
+
* @param targetServiceId - Identifier of the service that denied access.
|
|
72
|
+
*/
|
|
73
|
+
constructor(callerId, targetServiceId) {
|
|
74
|
+
super(`Caller "${callerId}" is not in the allowlist for service "${targetServiceId}"`, callerId, targetServiceId);
|
|
75
|
+
this.name = 'AllowlistViolationError';
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { OperationHandler } from './handler.js';
|
|
2
|
+
export interface IOperationRegistry {
|
|
3
|
+
register(handler: OperationHandler): void;
|
|
4
|
+
get<TInput = unknown, TOutput = unknown>(kind: string): OperationHandler<TInput, TOutput> | undefined;
|
|
5
|
+
has(kind: string): boolean;
|
|
6
|
+
list(): readonly OperationHandler[];
|
|
7
|
+
}
|