@graftland/plugin-remote 0.0.0-stage → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +76 -2
- package/README.zh-CN.md +71 -0
- package/README.zh-TW.md +71 -0
- package/dist/Auth-BElTC9_X.js +6 -0
- package/dist/Auth.d.ts +49 -0
- package/dist/Auth.d.ts.map +1 -0
- package/dist/Auth.js +8 -0
- package/dist/Auth.js.map +1 -0
- package/dist/Bootstrap-MCwivGN1.js +9 -0
- package/dist/ConfigDirectory-BCC6q2R4.js +5 -0
- package/dist/Contract-CcpSIJm4.js +121 -0
- package/dist/Contract.d.ts +71 -0
- package/dist/Contract.d.ts.map +1 -0
- package/dist/Contract.js +1 -0
- package/dist/Contract.js.map +1 -0
- package/dist/Errors-oPsTLY7l.js +45 -0
- package/dist/Errors.d.ts +67 -0
- package/dist/Errors.d.ts.map +1 -0
- package/dist/Errors.js +47 -0
- package/dist/Errors.js.map +1 -0
- package/dist/FailureGroup-BcH0XOBi.js +53 -0
- package/dist/Framing-zaYdOJnT.js +61 -0
- package/dist/Graft-BsYq3F-J.js +985 -0
- package/dist/Instance.d.ts +7 -0
- package/dist/Instance.d.ts.map +1 -0
- package/dist/Instance.js +14 -0
- package/dist/Instance.js.map +1 -0
- package/dist/Packages-B1TPk8pa.js +111 -0
- package/dist/Peer-IJgFK6mD.js +342 -0
- package/dist/ProcessObservation-DEGrEMfP.js +38 -0
- package/dist/ServeLifecycle-CJM0gG5B.js +24 -0
- package/dist/Testing.d.ts +26 -0
- package/dist/Testing.d.ts.map +1 -0
- package/dist/Testing.js +69 -0
- package/dist/Testing.js.map +1 -0
- package/dist/Transport-DULzpsgR.js +6 -0
- package/dist/Transport.d.ts +39 -0
- package/dist/Transport.d.ts.map +1 -0
- package/dist/Transport.js +8 -0
- package/dist/Transport.js.map +1 -0
- package/dist/WatchdogProtocol-BZmVxrBP.js +17 -0
- package/dist/_virtual/_rolldown/runtime.js +12 -0
- package/dist/bin.d.ts +1 -0
- package/dist/bin.js +28275 -0
- package/dist/bin.js.map +1 -0
- package/dist/childRuntime-DSqtFN9o.js +188 -0
- package/dist/cleanup-BPWr-5U9.js +13 -0
- package/dist/command-9zrHdbwT.js +7 -0
- package/dist/connectionEnded-DUgcobEd.js +9 -0
- package/dist/directTransport-DrexuPSm.js +5 -0
- package/dist/entry-SYsx9VNb.js +708 -0
- package/dist/host/auth/bearer.d.ts +5 -0
- package/dist/host/auth/bearer.d.ts.map +1 -0
- package/dist/host/auth/bearer.js +4 -0
- package/dist/host/auth/bearer.js.map +1 -0
- package/dist/host/auth/jwt.d.ts +5 -0
- package/dist/host/auth/jwt.d.ts.map +1 -0
- package/dist/host/auth/jwt.js +4 -0
- package/dist/host/auth/jwt.js.map +1 -0
- package/dist/host/auth/mtls.d.ts +8 -0
- package/dist/host/auth/mtls.d.ts.map +1 -0
- package/dist/host/auth/mtls.js +34 -0
- package/dist/host/auth/mtls.js.map +1 -0
- package/dist/host/auth/none.d.ts +3 -0
- package/dist/host/auth/none.d.ts.map +1 -0
- package/dist/host/auth/none.js +13 -0
- package/dist/host/auth/none.js.map +1 -0
- package/dist/host/command.d.ts +22 -0
- package/dist/host/command.d.ts.map +1 -0
- package/dist/host/command.js +61 -0
- package/dist/host/command.js.map +1 -0
- package/dist/host/local.d.ts +4 -0
- package/dist/host/local.d.ts.map +1 -0
- package/dist/host/local.js +52 -0
- package/dist/host/local.js.map +1 -0
- package/dist/host/unix.d.ts +11 -0
- package/dist/host/unix.d.ts.map +1 -0
- package/dist/host/unix.js +39 -0
- package/dist/host/unix.js.map +1 -0
- package/dist/host/websocket.d.ts +13 -0
- package/dist/host/websocket.d.ts.map +1 -0
- package/dist/host/websocket.js +36 -0
- package/dist/host/websocket.js.map +1 -0
- package/dist/host/worker.d.ts +4 -0
- package/dist/host/worker.d.ts.map +1 -0
- package/dist/host/worker.js +52 -0
- package/dist/host/worker.js.map +1 -0
- package/dist/importer-D7zSgqxq.js +347 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +86 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/Certificates.js +182 -0
- package/dist/internal/Certificates.js.map +1 -0
- package/dist/internal/FailureGroup.js +55 -0
- package/dist/internal/FailureGroup.js.map +1 -0
- package/dist/internal/Limits.d.ts +1 -0
- package/dist/internal/Limits.js +17 -0
- package/dist/internal/Limits.js.map +1 -0
- package/dist/internal/Peer.js +6 -0
- package/dist/internal/Peer.js.map +1 -0
- package/dist/internal/ServeLifecycle.js +26 -0
- package/dist/internal/ServeLifecycle.js.map +1 -0
- package/dist/internal/Supervisor.js +7 -0
- package/dist/internal/Supervisor.js.map +1 -0
- package/dist/internal/assembly.d.ts +5 -0
- package/dist/internal/assembly.js +138 -0
- package/dist/internal/assembly.js.map +1 -0
- package/dist/internal/auth/mtls.js +23 -0
- package/dist/internal/auth/mtls.js.map +1 -0
- package/dist/internal/auth/token.js +19 -0
- package/dist/internal/auth/token.js.map +1 -0
- package/dist/internal/auth/tokenCredentials.d.ts +8 -0
- package/dist/internal/auth/tokenCredentials.d.ts.map +1 -0
- package/dist/internal/auth/tokenCredentials.js +33 -0
- package/dist/internal/auth/tokenCredentials.js.map +1 -0
- package/dist/internal/child.js +125 -0
- package/dist/internal/child.js.map +1 -0
- package/dist/internal/childErrors.d.ts +33 -0
- package/dist/internal/childErrors.d.ts.map +1 -0
- package/dist/internal/childErrors.js +29 -0
- package/dist/internal/childErrors.js.map +1 -0
- package/dist/internal/childRuntime.js +59 -0
- package/dist/internal/childRuntime.js.map +1 -0
- package/dist/internal/cleanup.js +15 -0
- package/dist/internal/cleanup.js.map +1 -0
- package/dist/internal/config.js +6 -0
- package/dist/internal/config.js.map +1 -0
- package/dist/internal/control.js +42 -0
- package/dist/internal/control.js.map +1 -0
- package/dist/internal/credentials.d.ts +44 -0
- package/dist/internal/credentials.d.ts.map +1 -0
- package/dist/internal/credentials.js +54 -0
- package/dist/internal/credentials.js.map +1 -0
- package/dist/internal/directTransport.d.ts +3 -0
- package/dist/internal/directTransport.js +7 -0
- package/dist/internal/directTransport.js.map +1 -0
- package/dist/internal/entry.d.ts +9 -0
- package/dist/internal/entry.d.ts.map +1 -0
- package/dist/internal/entry.js +144 -0
- package/dist/internal/entry.js.map +1 -0
- package/dist/internal/entryConfig.d.ts +202 -0
- package/dist/internal/entryConfig.d.ts.map +1 -0
- package/dist/internal/entryConfig.js +176 -0
- package/dist/internal/entryConfig.js.map +1 -0
- package/dist/internal/execution.d.ts +5 -0
- package/dist/internal/execution.js +43 -0
- package/dist/internal/execution.js.map +1 -0
- package/dist/internal/follow.js +11 -0
- package/dist/internal/follow.js.map +1 -0
- package/dist/internal/forkTree.js +7 -0
- package/dist/internal/forkTree.js.map +1 -0
- package/dist/internal/host/local.js +28 -0
- package/dist/internal/host/local.js.map +1 -0
- package/dist/internal/host/runner.js +100 -0
- package/dist/internal/host/runner.js.map +1 -0
- package/dist/internal/host.js +71 -0
- package/dist/internal/host.js.map +1 -0
- package/dist/internal/importer.js +18 -0
- package/dist/internal/importer.js.map +1 -0
- package/dist/internal/listenerStartup.js +17 -0
- package/dist/internal/listenerStartup.js.map +1 -0
- package/dist/internal/loadModule.js +20 -0
- package/dist/internal/loadModule.js.map +1 -0
- package/dist/internal/platform.js +9 -0
- package/dist/internal/platform.js.map +1 -0
- package/dist/internal/port.d.ts +13 -0
- package/dist/internal/port.d.ts.map +1 -0
- package/dist/internal/port.js +275 -0
- package/dist/internal/port.js.map +1 -0
- package/dist/internal/release.js +25 -0
- package/dist/internal/release.js.map +1 -0
- package/dist/internal/runner/Bootstrap.js +11 -0
- package/dist/internal/runner/Bootstrap.js.map +1 -0
- package/dist/internal/runner/Connection.d.ts +11 -0
- package/dist/internal/runner/Connection.js +56 -0
- package/dist/internal/runner/Connection.js.map +1 -0
- package/dist/internal/runner/Execution.js +115 -0
- package/dist/internal/runner/Execution.js.map +1 -0
- package/dist/internal/runner/Framing.d.ts +11 -0
- package/dist/internal/runner/Framing.d.ts.map +1 -0
- package/dist/internal/runner/Framing.js +63 -0
- package/dist/internal/runner/Framing.js.map +1 -0
- package/dist/internal/runner/Local.js +46 -0
- package/dist/internal/runner/Local.js.map +1 -0
- package/dist/internal/runner/Lock.js +25 -0
- package/dist/internal/runner/Lock.js.map +1 -0
- package/dist/internal/runner/Multiplex.d.ts +5 -0
- package/dist/internal/runner/Multiplex.js +49 -0
- package/dist/internal/runner/Multiplex.js.map +1 -0
- package/dist/internal/runner/Packages.d.ts +3 -0
- package/dist/internal/runner/Packages.js +108 -0
- package/dist/internal/runner/Packages.js.map +1 -0
- package/dist/internal/runner/ProcessObservation.js +40 -0
- package/dist/internal/runner/ProcessObservation.js.map +1 -0
- package/dist/internal/runner/Processes.js +83 -0
- package/dist/internal/runner/Processes.js.map +1 -0
- package/dist/internal/runner/Retention.js +13 -0
- package/dist/internal/runner/Retention.js.map +1 -0
- package/dist/internal/runner/Store.js +78 -0
- package/dist/internal/runner/Store.js.map +1 -0
- package/dist/internal/runner/Supervisor.js +375 -0
- package/dist/internal/runner/Supervisor.js.map +1 -0
- package/dist/internal/runner/Watchdog.js +47 -0
- package/dist/internal/runner/Watchdog.js.map +1 -0
- package/dist/internal/runner/WatchdogProtocol.js +19 -0
- package/dist/internal/runner/WatchdogProtocol.js.map +1 -0
- package/dist/internal/runner/Wire.d.ts +5 -0
- package/dist/internal/runner/Wire.js +64 -0
- package/dist/internal/runner/Wire.js.map +1 -0
- package/dist/internal/runner/accept.js +57 -0
- package/dist/internal/runner/accept.js.map +1 -0
- package/dist/internal/runner/command.js +9 -0
- package/dist/internal/runner/command.js.map +1 -0
- package/dist/internal/runner/connectionEnded.js +11 -0
- package/dist/internal/runner/connectionEnded.js.map +1 -0
- package/dist/internal/runner/model.d.ts +17 -0
- package/dist/internal/runner/model.d.ts.map +1 -0
- package/dist/internal/runner/model.js +231 -0
- package/dist/internal/runner/model.js.map +1 -0
- package/dist/internal/serve.js +60 -0
- package/dist/internal/serve.js.map +1 -0
- package/dist/internal/services.d.ts +18 -0
- package/dist/internal/services.d.ts.map +1 -0
- package/dist/internal/services.js +22 -0
- package/dist/internal/services.js.map +1 -0
- package/dist/internal/socketChannel.js +24 -0
- package/dist/internal/socketChannel.js.map +1 -0
- package/dist/internal/stdioChannel.js +23 -0
- package/dist/internal/stdioChannel.js.map +1 -0
- package/dist/internal/supervisorPlugin.js +1 -0
- package/dist/internal/supervisorPlugin.js.map +1 -0
- package/dist/internal/transportOptions.d.ts +18 -0
- package/dist/internal/transportOptions.d.ts.map +1 -0
- package/dist/internal/watchdogMain.d.ts +1 -0
- package/dist/internal/watchdogMain.js +55 -0
- package/dist/internal/watchdogMain.js.map +1 -0
- package/dist/internal/websocket.js +46 -0
- package/dist/internal/websocket.js.map +1 -0
- package/dist/internal/websocketServer.js +61 -0
- package/dist/internal/websocketServer.js.map +1 -0
- package/dist/internal/workerBootstrap.js +9 -0
- package/dist/internal/workerBootstrap.js.map +1 -0
- package/dist/internal/workerChannel.js +24 -0
- package/dist/internal/workerChannel.js.map +1 -0
- package/dist/internal/workerMain.d.ts +1 -0
- package/dist/internal/workerMain.js +18 -0
- package/dist/internal/workerMain.js.map +1 -0
- package/dist/port-Blbh8tms.js +285 -0
- package/dist/release-BY4Mlluy.js +23 -0
- package/dist/rolldown-runtime-DYf_mQCB.js +34 -0
- package/dist/runner/auth/bearer.d.ts +7 -0
- package/dist/runner/auth/bearer.d.ts.map +1 -0
- package/dist/runner/auth/bearer.js +42 -0
- package/dist/runner/auth/bearer.js.map +1 -0
- package/dist/runner/auth/jwt.d.ts +19 -0
- package/dist/runner/auth/jwt.d.ts.map +1 -0
- package/dist/runner/auth/jwt.js +65 -0
- package/dist/runner/auth/jwt.js.map +1 -0
- package/dist/runner/auth/mtls.d.ts +11 -0
- package/dist/runner/auth/mtls.d.ts.map +1 -0
- package/dist/runner/auth/mtls.js +48 -0
- package/dist/runner/auth/mtls.js.map +1 -0
- package/dist/runner/auth/none.d.ts +3 -0
- package/dist/runner/auth/none.d.ts.map +1 -0
- package/dist/runner/auth/none.js +13 -0
- package/dist/runner/auth/none.js.map +1 -0
- package/dist/runner/index.d.ts +3 -0
- package/dist/runner/index.d.ts.map +1 -0
- package/dist/runner/index.js +71 -0
- package/dist/runner/index.js.map +1 -0
- package/dist/runner/stdio.d.ts +7 -0
- package/dist/runner/stdio.d.ts.map +1 -0
- package/dist/runner/stdio.js +39 -0
- package/dist/runner/stdio.js.map +1 -0
- package/dist/runner/unix.d.ts +7 -0
- package/dist/runner/unix.d.ts.map +1 -0
- package/dist/runner/unix.js +42 -0
- package/dist/runner/unix.js.map +1 -0
- package/dist/runner/websocket.d.ts +28 -0
- package/dist/runner/websocket.d.ts.map +1 -0
- package/dist/runner/websocket.js +77 -0
- package/dist/runner/websocket.js.map +1 -0
- package/dist/socketChannel-KmtzF-9G.js +3658 -0
- package/dist/supervisorPlugin-Inb1S5IV.js +737 -0
- package/dist/token-v5ne2I0-.js +17 -0
- package/dist/tokenCredentials-WUJm2AKm.js +31 -0
- package/dist/websocketServer-MXcCJx0v.js +58 -0
- package/dist/workerChannel-P82YdNjh.js +27 -0
- package/package.json +69 -3
- package/src/Auth.ts +62 -0
- package/src/Contract.ts +100 -0
- package/src/Errors.ts +82 -0
- package/src/Instance.ts +12 -0
- package/src/Testing.ts +135 -0
- package/src/Transport.ts +52 -0
- package/src/bin.ts +145 -0
- package/src/host/auth/bearer.ts +10 -0
- package/src/host/auth/jwt.ts +10 -0
- package/src/host/auth/mtls.ts +48 -0
- package/src/host/auth/none.ts +13 -0
- package/src/host/command.ts +131 -0
- package/src/host/local.ts +41 -0
- package/src/host/unix.ts +65 -0
- package/src/host/websocket.ts +66 -0
- package/src/host/worker.ts +90 -0
- package/src/index.ts +115 -0
- package/src/internal/Certificates.ts +330 -0
- package/src/internal/FailureGroup.ts +176 -0
- package/src/internal/Limits.ts +12 -0
- package/src/internal/Peer.ts +4 -0
- package/src/internal/ServeLifecycle.ts +53 -0
- package/src/internal/Supervisor.ts +14 -0
- package/src/internal/assembly.ts +337 -0
- package/src/internal/auth/mtls.ts +40 -0
- package/src/internal/auth/token.ts +26 -0
- package/src/internal/auth/tokenCredentials.ts +65 -0
- package/src/internal/child.ts +323 -0
- package/src/internal/childErrors.ts +44 -0
- package/src/internal/childRuntime.ts +111 -0
- package/src/internal/cleanup.ts +34 -0
- package/src/internal/config.ts +8 -0
- package/src/internal/control.ts +49 -0
- package/src/internal/credentials.ts +112 -0
- package/src/internal/directTransport.ts +38 -0
- package/src/internal/entry.ts +288 -0
- package/src/internal/entryConfig.ts +190 -0
- package/src/internal/execution.ts +121 -0
- package/src/internal/follow.ts +17 -0
- package/src/internal/forkTree.ts +13 -0
- package/src/internal/host/local.ts +53 -0
- package/src/internal/host/runner.ts +187 -0
- package/src/internal/host.ts +209 -0
- package/src/internal/importer.ts +27 -0
- package/src/internal/listenerStartup.ts +55 -0
- package/src/internal/loadModule.ts +23 -0
- package/src/internal/platform.ts +12 -0
- package/src/internal/port.ts +623 -0
- package/src/internal/release.ts +71 -0
- package/src/internal/runner/Bootstrap.ts +9 -0
- package/src/internal/runner/Connection.ts +184 -0
- package/src/internal/runner/Execution.ts +244 -0
- package/src/internal/runner/Framing.ts +122 -0
- package/src/internal/runner/Local.ts +73 -0
- package/src/internal/runner/Lock.ts +29 -0
- package/src/internal/runner/Multiplex.ts +120 -0
- package/src/internal/runner/Packages.ts +178 -0
- package/src/internal/runner/ProcessObservation.ts +63 -0
- package/src/internal/runner/Processes.ts +109 -0
- package/src/internal/runner/Retention.ts +49 -0
- package/src/internal/runner/Store.ts +160 -0
- package/src/internal/runner/Supervisor.ts +901 -0
- package/src/internal/runner/Watchdog.ts +83 -0
- package/src/internal/runner/WatchdogProtocol.ts +12 -0
- package/src/internal/runner/Wire.ts +99 -0
- package/src/internal/runner/accept.ts +103 -0
- package/src/internal/runner/command.ts +15 -0
- package/src/internal/runner/connectionEnded.ts +28 -0
- package/src/internal/runner/model.ts +364 -0
- package/src/internal/serve.ts +117 -0
- package/src/internal/services.ts +74 -0
- package/src/internal/socketChannel.ts +64 -0
- package/src/internal/stdioChannel.ts +25 -0
- package/src/internal/supervisorPlugin.ts +67 -0
- package/src/internal/transportOptions.ts +17 -0
- package/src/internal/watchdogMain.ts +72 -0
- package/src/internal/websocket.ts +81 -0
- package/src/internal/websocketServer.ts +152 -0
- package/src/internal/workerBootstrap.ts +6 -0
- package/src/internal/workerChannel.ts +54 -0
- package/src/internal/workerMain.ts +23 -0
- package/src/runner/auth/bearer.ts +66 -0
- package/src/runner/auth/jwt.ts +114 -0
- package/src/runner/auth/mtls.ts +37 -0
- package/src/runner/auth/none.ts +13 -0
- package/src/runner/index.ts +97 -0
- package/src/runner/stdio.ts +76 -0
- package/src/runner/unix.ts +53 -0
- package/src/runner/websocket.ts +143 -0
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
import { findSubtree, isSubtreeActive } from "./forkTree"
|
|
2
|
+
import { Peer } from "./Peer"
|
|
3
|
+
import { Graft, Plugin, type Fork } from "@graftland/graft"
|
|
4
|
+
import {
|
|
5
|
+
Array,
|
|
6
|
+
Context,
|
|
7
|
+
Deferred,
|
|
8
|
+
Effect,
|
|
9
|
+
Fiber,
|
|
10
|
+
Option,
|
|
11
|
+
Schema,
|
|
12
|
+
Stream,
|
|
13
|
+
} from "effect"
|
|
14
|
+
import {
|
|
15
|
+
Authenticator,
|
|
16
|
+
Credentials,
|
|
17
|
+
type AuthenticatorApi,
|
|
18
|
+
type CredentialsApi,
|
|
19
|
+
} from "../Auth"
|
|
20
|
+
import {
|
|
21
|
+
Connector,
|
|
22
|
+
Listener,
|
|
23
|
+
type Accept,
|
|
24
|
+
type Properties,
|
|
25
|
+
type Session,
|
|
26
|
+
} from "../Transport"
|
|
27
|
+
import { AuthenticationFailed } from "../Errors"
|
|
28
|
+
import { Supervisor } from "./Supervisor"
|
|
29
|
+
import { follow } from "./follow"
|
|
30
|
+
import { connectionEnded, closedNormally } from "./runner/connectionEnded"
|
|
31
|
+
import { ServeLifecycle } from "./ServeLifecycle"
|
|
32
|
+
|
|
33
|
+
export class ListenerConfigError extends Schema.TaggedError<
|
|
34
|
+
ListenerConfigError,
|
|
35
|
+
{ readonly brand: unique symbol }
|
|
36
|
+
>()("ListenerConfigError", { detail: Schema.String }) {
|
|
37
|
+
override get message() {
|
|
38
|
+
return this.detail
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export class CapabilityContractError extends Schema.TaggedError<
|
|
43
|
+
CapabilityContractError,
|
|
44
|
+
{ readonly brand: unique symbol }
|
|
45
|
+
>()("CapabilityContractError", { plugin: Schema.String, key: Schema.String }) {
|
|
46
|
+
override get message() {
|
|
47
|
+
return `Capability ${this.plugin} became active without providing ${this.key}`
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export class CapabilityCombinationError extends Schema.TaggedError<
|
|
51
|
+
CapabilityCombinationError,
|
|
52
|
+
{ readonly brand: unique symbol }
|
|
53
|
+
>()("CapabilityCombinationError", { detail: Schema.String }) {
|
|
54
|
+
override get message() {
|
|
55
|
+
return this.detail
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export class CapabilityFailed extends Schema.TaggedError<
|
|
60
|
+
CapabilityFailed,
|
|
61
|
+
{ readonly brand: unique symbol }
|
|
62
|
+
>()("CapabilityFailed", {
|
|
63
|
+
cause: Schema.Cause(Schema.Unknown, Schema.Unknown),
|
|
64
|
+
}) {}
|
|
65
|
+
|
|
66
|
+
const definition = Schema.declare(Plugin.isPlugin)
|
|
67
|
+
/** Entries resolve capability modules before assembling their private providers. */
|
|
68
|
+
export const Invocation = Schema.Struct({
|
|
69
|
+
plugin: definition,
|
|
70
|
+
config: Schema.Unknown,
|
|
71
|
+
})
|
|
72
|
+
const Input = Schema.Struct({
|
|
73
|
+
transport: Invocation,
|
|
74
|
+
auth: Invocation,
|
|
75
|
+
consumer: definition,
|
|
76
|
+
input: Schema.optionalKey(Schema.Unknown),
|
|
77
|
+
})
|
|
78
|
+
export type Input = typeof Input.Type
|
|
79
|
+
|
|
80
|
+
const failure = (tree: Fork.ForkTree): Effect.Effect<void, CapabilityFailed> =>
|
|
81
|
+
tree.state._tag === "Failed"
|
|
82
|
+
? Effect.fail(CapabilityFailed.make({ cause: tree.state.cause }))
|
|
83
|
+
: Effect.forEach(tree.children, failure, { discard: true })
|
|
84
|
+
|
|
85
|
+
const probe = (name: string, key: Context.Key<unknown, unknown>) =>
|
|
86
|
+
Plugin.make({
|
|
87
|
+
name: "remote-capability-contract",
|
|
88
|
+
inject: [Plugin.optional(key)],
|
|
89
|
+
apply: Effect.fnUntraced(function* () {
|
|
90
|
+
const value = yield* Effect.serviceOption(key)
|
|
91
|
+
if (Option.isNone(value))
|
|
92
|
+
return yield* CapabilityContractError.make({
|
|
93
|
+
plugin: name,
|
|
94
|
+
key: key.key,
|
|
95
|
+
})
|
|
96
|
+
}),
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
/** Resolve the key in a fresh consumer after the provider subtree settles.
|
|
100
|
+
* An optional consumer started earlier could still hold a pre-publication snapshot.
|
|
101
|
+
*/
|
|
102
|
+
const watch = (provider: Fork.Fork, key: Context.Key<unknown, unknown>) =>
|
|
103
|
+
Plugin.fork(
|
|
104
|
+
Graft.forks.pipe(
|
|
105
|
+
Stream.map((trees) => findSubtree(trees, provider.id)),
|
|
106
|
+
Stream.filter(Option.isSome),
|
|
107
|
+
Stream.map((tree) => tree.value),
|
|
108
|
+
Stream.tap(failure),
|
|
109
|
+
Stream.map((tree) => ({
|
|
110
|
+
name: tree.name,
|
|
111
|
+
active: isSubtreeActive(tree),
|
|
112
|
+
})),
|
|
113
|
+
Stream.changesWith((left, right) => left.active === right.active),
|
|
114
|
+
Stream.filter((tree) => tree.active),
|
|
115
|
+
Stream.runForEach((tree) =>
|
|
116
|
+
Effect.scoped(
|
|
117
|
+
Graft.plugin(probe(tree.name, key)).pipe(
|
|
118
|
+
Effect.flatMap((fork) => fork.await),
|
|
119
|
+
),
|
|
120
|
+
),
|
|
121
|
+
),
|
|
122
|
+
),
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
const assembly = (
|
|
126
|
+
keys: readonly [Context.Key<unknown, unknown>, Context.Key<unknown, unknown>],
|
|
127
|
+
) =>
|
|
128
|
+
Plugin.make({
|
|
129
|
+
name: "remote-assembly",
|
|
130
|
+
config: Input,
|
|
131
|
+
apply: Effect.fnUntraced(function* (input) {
|
|
132
|
+
yield* Effect.forEach(
|
|
133
|
+
[
|
|
134
|
+
{ invocation: input.transport, key: keys[0] },
|
|
135
|
+
{ invocation: input.auth, key: keys[1] },
|
|
136
|
+
],
|
|
137
|
+
Effect.fnUntraced(function* ({ invocation, key }) {
|
|
138
|
+
const provider = yield* Graft.plugin(
|
|
139
|
+
invocation.plugin,
|
|
140
|
+
invocation.config,
|
|
141
|
+
)
|
|
142
|
+
yield* watch(provider, key)
|
|
143
|
+
}),
|
|
144
|
+
)
|
|
145
|
+
const consumer = yield* Graft.plugin(input.consumer, input.input)
|
|
146
|
+
// Capability publication can leave a transient Pending snapshot; business dependencies may remain Pending.
|
|
147
|
+
yield* consumer.state.pipe(
|
|
148
|
+
Stream.filter(
|
|
149
|
+
(state) =>
|
|
150
|
+
state._tag !== "Loading" &&
|
|
151
|
+
(state._tag !== "Pending" ||
|
|
152
|
+
!Array.some(keys, (key) =>
|
|
153
|
+
Array.contains(state.missing, key.key),
|
|
154
|
+
)),
|
|
155
|
+
),
|
|
156
|
+
Stream.runHead,
|
|
157
|
+
)
|
|
158
|
+
yield* follow(consumer, (cause) =>
|
|
159
|
+
Effect.fail(CapabilityFailed.make({ cause })),
|
|
160
|
+
)
|
|
161
|
+
}),
|
|
162
|
+
})
|
|
163
|
+
const hostAssembly = assembly([Connector, Credentials])
|
|
164
|
+
const runnerAssembly = assembly([Listener, Authenticator])
|
|
165
|
+
|
|
166
|
+
export const host = (input: Input) =>
|
|
167
|
+
Graft.plugin(hostAssembly, input, { isolate: [Connector, Credentials] })
|
|
168
|
+
export const runner = (
|
|
169
|
+
input: Omit<Input, "consumer">,
|
|
170
|
+
consumer = listenerConsumer,
|
|
171
|
+
) =>
|
|
172
|
+
Graft.plugin(
|
|
173
|
+
runnerAssembly,
|
|
174
|
+
{ ...input, consumer },
|
|
175
|
+
{ isolate: [Listener, Authenticator] },
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
export const compatible = (
|
|
179
|
+
properties: Properties,
|
|
180
|
+
kind: CredentialsApi["kind"],
|
|
181
|
+
): Effect.Effect<void, CapabilityCombinationError> => {
|
|
182
|
+
if (
|
|
183
|
+
kind === "Certificate" &&
|
|
184
|
+
(properties.protocol !== "wss" ||
|
|
185
|
+
!properties.encrypted ||
|
|
186
|
+
!Array.contains(properties.carries, "certificate"))
|
|
187
|
+
)
|
|
188
|
+
return Effect.fail(
|
|
189
|
+
CapabilityCombinationError.make({
|
|
190
|
+
detail: "Mutual TLS requires encrypted wss with certificate evidence",
|
|
191
|
+
}),
|
|
192
|
+
)
|
|
193
|
+
if (kind === "Authorization" && !Array.contains(properties.carries, "header"))
|
|
194
|
+
return Effect.fail(
|
|
195
|
+
CapabilityCombinationError.make({
|
|
196
|
+
detail: "This transport cannot carry Authorization headers",
|
|
197
|
+
}),
|
|
198
|
+
)
|
|
199
|
+
return Effect.void
|
|
200
|
+
}
|
|
201
|
+
const kind = (auth: AuthenticatorApi): CredentialsApi["kind"] =>
|
|
202
|
+
auth._tag === "Mtls"
|
|
203
|
+
? "Certificate"
|
|
204
|
+
: auth._tag === "Header"
|
|
205
|
+
? "Authorization"
|
|
206
|
+
: "None"
|
|
207
|
+
const warn = (
|
|
208
|
+
properties: Properties,
|
|
209
|
+
credentials: CredentialsApi["kind"],
|
|
210
|
+
side: "host" | "runner",
|
|
211
|
+
) =>
|
|
212
|
+
Effect.all(
|
|
213
|
+
[
|
|
214
|
+
properties.network && !properties.encrypted
|
|
215
|
+
? Effect.logWarning(
|
|
216
|
+
credentials === "Authorization"
|
|
217
|
+
? `${properties.protocol}:// ${side === "host" ? "connection" : "listener"} is unencrypted; credentials are transmitted in plaintext`
|
|
218
|
+
: `${properties.protocol}:// ${side === "host" ? "connection" : "listener"} is unencrypted`,
|
|
219
|
+
)
|
|
220
|
+
: Effect.void,
|
|
221
|
+
side === "runner" && properties.network && credentials === "None"
|
|
222
|
+
? Effect.logWarning("WebSocket listener has no authentication")
|
|
223
|
+
: Effect.void,
|
|
224
|
+
],
|
|
225
|
+
{ discard: true },
|
|
226
|
+
)
|
|
227
|
+
|
|
228
|
+
export const directAuth = (properties: Properties, explicit: boolean) =>
|
|
229
|
+
explicit &&
|
|
230
|
+
(properties.protocol === "stdio" || properties.protocol === "command")
|
|
231
|
+
? Effect.fail(
|
|
232
|
+
CapabilityCombinationError.make({
|
|
233
|
+
detail: `${properties.protocol} transports do not accept auth`,
|
|
234
|
+
}),
|
|
235
|
+
)
|
|
236
|
+
: Effect.void
|
|
237
|
+
|
|
238
|
+
export const connectWith = (explicitAuth = false) =>
|
|
239
|
+
Effect.gen(function* () {
|
|
240
|
+
const connector = yield* Connector
|
|
241
|
+
const credentials = yield* Credentials
|
|
242
|
+
yield* directAuth(connector.properties, explicitAuth)
|
|
243
|
+
yield* compatible(connector.properties, credentials.kind)
|
|
244
|
+
yield* warn(connector.properties, credentials.kind, "host")
|
|
245
|
+
const prepared = yield* credentials.read
|
|
246
|
+
return yield* connector.connect(prepared)
|
|
247
|
+
})
|
|
248
|
+
|
|
249
|
+
export const accept =
|
|
250
|
+
(
|
|
251
|
+
auth: AuthenticatorApi,
|
|
252
|
+
properties: Properties,
|
|
253
|
+
session: (identity: string) => Session,
|
|
254
|
+
): Accept =>
|
|
255
|
+
(handshake) => {
|
|
256
|
+
const identity =
|
|
257
|
+
auth._tag === "Header"
|
|
258
|
+
? auth.authenticate(handshake.authorization)
|
|
259
|
+
: auth._tag === "Mtls"
|
|
260
|
+
? Option.match(handshake.certificate, {
|
|
261
|
+
onNone: () =>
|
|
262
|
+
Effect.fail(AuthenticationFailed.make({ reason: "missing" })),
|
|
263
|
+
onSome: auth.authenticate,
|
|
264
|
+
})
|
|
265
|
+
: (properties.network
|
|
266
|
+
? Effect.logWarning("WebSocket connection has no authentication")
|
|
267
|
+
: Effect.void
|
|
268
|
+
).pipe(Effect.as(auth.identity))
|
|
269
|
+
return identity.pipe(Effect.map(session))
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
export const makeListenerConsumer = (
|
|
273
|
+
prepare: (
|
|
274
|
+
properties: Properties,
|
|
275
|
+
auth: AuthenticatorApi,
|
|
276
|
+
) => Effect.Effect<void, CapabilityCombinationError> = () => Effect.void,
|
|
277
|
+
ready: Effect.Effect<void> = Effect.void,
|
|
278
|
+
) =>
|
|
279
|
+
Plugin.make({
|
|
280
|
+
name: "remote-listener-consumer",
|
|
281
|
+
inject: [
|
|
282
|
+
Listener,
|
|
283
|
+
Authenticator,
|
|
284
|
+
Supervisor,
|
|
285
|
+
Plugin.optional(ServeLifecycle),
|
|
286
|
+
],
|
|
287
|
+
apply: Effect.fnUntraced(function* () {
|
|
288
|
+
const listener = yield* Listener
|
|
289
|
+
const auth = yield* Authenticator
|
|
290
|
+
const supervisor = yield* Supervisor
|
|
291
|
+
const lifecycle = yield* Effect.serviceOption(ServeLifecycle)
|
|
292
|
+
yield* prepare(listener.properties, auth)
|
|
293
|
+
yield* compatible(listener.properties, kind(auth)).pipe(
|
|
294
|
+
Effect.mapError((error) =>
|
|
295
|
+
ListenerConfigError.make({ detail: error.detail }),
|
|
296
|
+
),
|
|
297
|
+
)
|
|
298
|
+
yield* warn(listener.properties, kind(auth), "runner")
|
|
299
|
+
const serving = yield* listener.bind(
|
|
300
|
+
auth._tag === "Mtls" ? Option.some(auth.tls) : Option.none(),
|
|
301
|
+
)
|
|
302
|
+
const running = yield* Plugin.fork(
|
|
303
|
+
serving
|
|
304
|
+
.serve(
|
|
305
|
+
accept(
|
|
306
|
+
auth,
|
|
307
|
+
listener.properties,
|
|
308
|
+
(identity) => (channel) =>
|
|
309
|
+
supervisor.accept(channel).pipe(
|
|
310
|
+
Effect.catchCause((cause) =>
|
|
311
|
+
listener.properties.protocol === "stdio"
|
|
312
|
+
? closedNormally(cause)
|
|
313
|
+
? Effect.void
|
|
314
|
+
: Effect.failCause(cause)
|
|
315
|
+
: connectionEnded(cause),
|
|
316
|
+
),
|
|
317
|
+
Effect.provideService(Peer, identity),
|
|
318
|
+
),
|
|
319
|
+
),
|
|
320
|
+
)
|
|
321
|
+
.pipe(
|
|
322
|
+
Effect.onExit((exit) =>
|
|
323
|
+
listener.properties.protocol === "stdio" &&
|
|
324
|
+
Option.isSome(lifecycle)
|
|
325
|
+
? Deferred.done(lifecycle.value.ended, exit)
|
|
326
|
+
: Effect.void,
|
|
327
|
+
),
|
|
328
|
+
),
|
|
329
|
+
)
|
|
330
|
+
yield* serving.ready.pipe(Effect.raceFirst(Fiber.join(running)))
|
|
331
|
+
yield* ready
|
|
332
|
+
}),
|
|
333
|
+
})
|
|
334
|
+
|
|
335
|
+
export const listenerConsumer = makeListenerConsumer()
|
|
336
|
+
|
|
337
|
+
export const connect = connectWith()
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Array, Cause, Effect, Schema, String } from "effect"
|
|
2
|
+
import { AuthenticationFailed } from "../../Errors"
|
|
3
|
+
|
|
4
|
+
// Node JSON-quotes SAN values containing separators, escaping commas inside the value.
|
|
5
|
+
const uriValue = (field: string) => {
|
|
6
|
+
const value = String.slice(4)(field)
|
|
7
|
+
return String.startsWith('"')(value)
|
|
8
|
+
? Schema.decodeEffect(Schema.fromJsonString(Schema.String))(value).pipe(
|
|
9
|
+
Effect.mapError((error) =>
|
|
10
|
+
AuthenticationFailed.make({
|
|
11
|
+
reason: "invalid",
|
|
12
|
+
cause: Cause.fail(error),
|
|
13
|
+
}),
|
|
14
|
+
),
|
|
15
|
+
)
|
|
16
|
+
: Effect.succeed(value)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Read exactly one graft URI from Node's plain or JSON-quoted SAN representation. */
|
|
20
|
+
export const identityFromSubjectAltName = (
|
|
21
|
+
san: string | undefined,
|
|
22
|
+
): Effect.Effect<string, AuthenticationFailed> =>
|
|
23
|
+
Effect.gen(function* () {
|
|
24
|
+
const values = yield* Effect.forEach(
|
|
25
|
+
Array.filter(String.split(san ?? "", ", "), String.startsWith("URI:")),
|
|
26
|
+
uriValue,
|
|
27
|
+
)
|
|
28
|
+
const uris = Array.filter(values, String.startsWith("graft://"))
|
|
29
|
+
const [uri] = uris
|
|
30
|
+
return yield* uris.length === 1 && uri !== undefined
|
|
31
|
+
? Effect.succeed(uri)
|
|
32
|
+
: Effect.fail(
|
|
33
|
+
AuthenticationFailed.make({
|
|
34
|
+
reason: "invalid",
|
|
35
|
+
cause: Cause.fail(
|
|
36
|
+
"The peer certificate must contain exactly one graft SAN URI",
|
|
37
|
+
),
|
|
38
|
+
}),
|
|
39
|
+
)
|
|
40
|
+
})
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Effect, Option, Redacted } from "effect"
|
|
2
|
+
import { AuthenticationFailed } from "../../Errors"
|
|
3
|
+
|
|
4
|
+
export const invalid = () =>
|
|
5
|
+
AuthenticationFailed.make({
|
|
6
|
+
reason: "invalid",
|
|
7
|
+
challenge: 'Bearer error="invalid_token"',
|
|
8
|
+
})
|
|
9
|
+
export const read = (
|
|
10
|
+
authorization: Option.Option<Redacted.Redacted<string>>,
|
|
11
|
+
): Effect.Effect<Redacted.Redacted<string>, AuthenticationFailed> => {
|
|
12
|
+
if (Option.isNone(authorization))
|
|
13
|
+
return Effect.fail(
|
|
14
|
+
AuthenticationFailed.make({
|
|
15
|
+
reason: "missing",
|
|
16
|
+
challenge: "Bearer",
|
|
17
|
+
}),
|
|
18
|
+
)
|
|
19
|
+
const match = /^Bearer +([^ ]+)$/i.exec(Redacted.value(authorization.value))
|
|
20
|
+
const token = match?.[1]
|
|
21
|
+
return token === undefined
|
|
22
|
+
? Effect.fail(invalid())
|
|
23
|
+
: Effect.succeed(Redacted.make(token))
|
|
24
|
+
}
|
|
25
|
+
export const prepare = (token: Redacted.Redacted<string>) =>
|
|
26
|
+
Effect.succeed(Redacted.make("Bearer " + Redacted.value(token)))
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Graft, Plugin } from "@graftland/graft"
|
|
2
|
+
import { ConfigDirectory } from "@graftland/loader"
|
|
3
|
+
import {
|
|
4
|
+
Cause,
|
|
5
|
+
Effect,
|
|
6
|
+
FileSystem,
|
|
7
|
+
Option,
|
|
8
|
+
Path,
|
|
9
|
+
Redacted,
|
|
10
|
+
Schema,
|
|
11
|
+
} from "effect"
|
|
12
|
+
import { Credentials, type Prepared } from "../../Auth"
|
|
13
|
+
import { CredentialsError } from "../../Errors"
|
|
14
|
+
import { prepare } from "./token"
|
|
15
|
+
|
|
16
|
+
export const Config = Schema.Struct({
|
|
17
|
+
token: Schema.Union([
|
|
18
|
+
Schema.RedactedFromValue(Schema.String),
|
|
19
|
+
Schema.Struct({ file: Schema.String }),
|
|
20
|
+
]),
|
|
21
|
+
})
|
|
22
|
+
export const plugin = (
|
|
23
|
+
name: string,
|
|
24
|
+
): Plugin.Plugin<
|
|
25
|
+
typeof Config.Type,
|
|
26
|
+
typeof Config.Encoded,
|
|
27
|
+
Graft.ServiceConflict
|
|
28
|
+
> =>
|
|
29
|
+
Plugin.make({
|
|
30
|
+
name,
|
|
31
|
+
config: Config,
|
|
32
|
+
inject: [FileSystem.FileSystem, Path.Path],
|
|
33
|
+
apply: Effect.fnUntraced(function* (config) {
|
|
34
|
+
const fs = yield* FileSystem.FileSystem
|
|
35
|
+
const path = yield* Path.Path
|
|
36
|
+
const directory = yield* ConfigDirectory
|
|
37
|
+
const token = config.token
|
|
38
|
+
const read = Redacted.isRedacted(token)
|
|
39
|
+
? Effect.succeed(token)
|
|
40
|
+
: fs
|
|
41
|
+
.readFileString(
|
|
42
|
+
path.resolve(
|
|
43
|
+
Option.getOrElse(directory, () => "."),
|
|
44
|
+
token.file,
|
|
45
|
+
),
|
|
46
|
+
)
|
|
47
|
+
.pipe(Effect.map(Redacted.make))
|
|
48
|
+
yield* Graft.provide(Credentials, {
|
|
49
|
+
kind: "Authorization",
|
|
50
|
+
read: read.pipe(
|
|
51
|
+
Effect.flatMap(prepare),
|
|
52
|
+
Effect.mapBoth({
|
|
53
|
+
onSuccess: (
|
|
54
|
+
value,
|
|
55
|
+
): Extract<Prepared, { readonly _tag: "Authorization" }> => ({
|
|
56
|
+
_tag: "Authorization",
|
|
57
|
+
value,
|
|
58
|
+
}),
|
|
59
|
+
onFailure: (error) =>
|
|
60
|
+
CredentialsError.make({ cause: Cause.fail(error) }),
|
|
61
|
+
}),
|
|
62
|
+
),
|
|
63
|
+
})
|
|
64
|
+
}),
|
|
65
|
+
})
|