@floegence/flowersec-core 0.27.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +91 -22
- package/THIRD_PARTY_NOTICES.md +141 -0
- package/dist/browser/connectSession.d.ts +13 -0
- package/dist/browser/connectSession.js +40 -0
- package/dist/browser/index.d.ts +3 -10
- package/dist/browser/index.js +2 -5
- package/dist/browser/runtimeCapability.d.ts +13 -0
- package/dist/browser/runtimeCapability.js +27 -0
- package/dist/browser/sessionRuntime.d.ts +2 -0
- package/dist/browser/sessionRuntime.js +21 -0
- package/dist/browser/webTransportClient.d.ts +8 -0
- package/dist/browser/webTransportClient.js +55 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +126 -0
- package/dist/cliSpendMarker.d.ts +1 -0
- package/dist/cliSpendMarker.js +22 -0
- package/dist/connectionController.d.ts +54 -0
- package/dist/connectionController.js +438 -0
- package/dist/connector/adapters/webSocketCandidate.d.ts +7 -0
- package/dist/connector/adapters/webSocketCandidate.js +116 -0
- package/dist/connector/adapters/webTransportCandidate.d.ts +5 -0
- package/dist/connector/adapters/webTransportCandidate.js +73 -0
- package/dist/connector/admissionCommit.d.ts +31 -0
- package/dist/connector/admissionCommit.js +239 -0
- package/dist/connector/sessionAcceptor.d.ts +16 -0
- package/dist/connector/sessionAcceptor.js +114 -0
- package/dist/connector/sessionConfig.d.ts +3 -0
- package/dist/connector/sessionConfig.js +30 -0
- package/dist/connector/sessionConnector.d.ts +45 -0
- package/dist/connector/sessionConnector.js +603 -0
- package/dist/defaults.d.ts +7 -7
- package/dist/defaults.js +7 -7
- package/dist/facade.d.ts +12 -27
- package/dist/facade.js +6 -24
- package/dist/node/connectSession.d.ts +21 -0
- package/dist/node/connectSession.js +62 -0
- package/dist/node/index.d.ts +3 -11
- package/dist/node/index.js +2 -8
- package/dist/node/runtimeCapability.d.ts +7 -0
- package/dist/node/runtimeCapability.js +10 -0
- package/dist/node/sessionRuntime.d.ts +2 -0
- package/dist/node/sessionRuntime.js +13 -0
- package/dist/node/webTransportClient.d.ts +9 -0
- package/dist/node/webTransportClient.js +56 -0
- package/dist/node/webTransportServer.d.ts +22 -0
- package/dist/node/webTransportServer.js +100 -0
- package/dist/node/wsFactory.d.ts +3 -1
- package/dist/node/wsFactory.js +4 -3
- package/dist/proxy/controllerGuard.d.ts +4 -4
- package/dist/proxy/controllerGuard.js +83 -177
- package/dist/proxy/disableUpstreamServiceWorkerRegister.d.ts +3 -1
- package/dist/proxy/disableUpstreamServiceWorkerRegister.js +19 -17
- package/dist/proxy/index.d.ts +16 -15
- package/dist/proxy/index.js +8 -14
- package/dist/proxy/integration.d.ts +23 -71
- package/dist/proxy/integration.js +37 -340
- package/dist/proxy/registerServiceWorker.d.ts +1 -10
- package/dist/proxy/registerServiceWorker.js +43 -105
- package/dist/proxy/runtime.d.ts +3 -63
- package/dist/proxy/runtime.js +349 -462
- package/dist/proxy/scope.d.ts +6 -0
- package/dist/proxy/scope.js +131 -0
- package/dist/proxy/serviceWorker.d.ts +5 -16
- package/dist/proxy/serviceWorker.js +230 -617
- package/dist/proxy/stream.d.ts +9 -0
- package/dist/proxy/stream.js +40 -0
- package/dist/proxy/types.d.ts +78 -30
- package/dist/proxy/windowBridge.d.ts +61 -0
- package/dist/proxy/windowBridge.js +344 -0
- package/dist/proxy/wsPatch.d.ts +4 -14
- package/dist/proxy/wsPatch.js +173 -268
- package/dist/public/artifact.d.ts +11 -0
- package/dist/public/artifact.js +44 -0
- package/dist/public/artifactLease.d.ts +10 -0
- package/dist/public/artifactLease.js +48 -0
- package/dist/public/connectError.d.ts +6 -0
- package/dist/public/connectError.js +9 -0
- package/dist/public/contract.d.ts +83 -0
- package/dist/public/contract.js +17 -0
- package/dist/public/streamMetadata.d.ts +10 -0
- package/dist/public/streamMetadata.js +40 -0
- package/dist/rpc/caller.d.ts +1 -1
- package/dist/rpc/client.d.ts +1 -4
- package/dist/rpc/client.js +0 -21
- package/dist/rpc/rpcProxy.d.ts +1 -1
- package/dist/rpc/server.d.ts +1 -1
- package/dist/rpc/validate.d.ts +1 -1
- package/dist/rpc/wire.d.ts +15 -0
- package/dist/runtime/errors.d.ts +6 -0
- package/dist/runtime/errors.js +10 -0
- package/dist/transport/webSocketAdapter.d.ts +24 -0
- package/dist/transport/webSocketAdapter.js +234 -0
- package/dist/transport/webTransportAdapter.d.ts +27 -0
- package/dist/transport/webTransportAdapter.js +519 -0
- package/dist/utils/errors.d.ts +2 -20
- package/dist/utils/errors.js +73 -20
- package/dist/v2/admissionError.d.ts +4 -0
- package/dist/v2/admissionError.js +8 -0
- package/dist/v2/artifact.d.ts +128 -0
- package/dist/v2/artifact.js +1126 -0
- package/dist/v2/artifactLease.d.ts +1 -0
- package/dist/v2/artifactLease.js +7 -0
- package/dist/v2/capability.d.ts +29 -0
- package/dist/v2/capability.js +190 -0
- package/dist/v2/carrier.d.ts +79 -0
- package/dist/v2/carrier.js +405 -0
- package/dist/v2/contract.d.ts +37 -0
- package/dist/v2/contract.js +1 -0
- package/dist/v2/handshake.d.ts +80 -0
- package/dist/v2/handshake.js +470 -0
- package/dist/v2/opaqueArtifact.d.ts +1 -0
- package/dist/v2/opaqueArtifact.js +2 -0
- package/dist/v2/protocol.d.ts +99 -0
- package/dist/v2/protocol.js +739 -0
- package/dist/v2/publicSession.d.ts +1 -0
- package/dist/v2/publicSession.js +179 -0
- package/dist/v2/retryDisposition.d.ts +16 -0
- package/dist/v2/retryDisposition.js +30 -0
- package/dist/v2/session.d.ts +277 -0
- package/dist/v2/session.js +1879 -0
- package/dist/v2/streamLifetimeLedger.d.ts +31 -0
- package/dist/v2/streamLifetimeLedger.js +131 -0
- package/dist/v2/streamMetadata.d.ts +1 -0
- package/dist/v2/streamMetadata.js +7 -0
- package/dist/v2/unreliableMessage.d.ts +43 -0
- package/dist/v2/unreliableMessage.js +252 -0
- package/dist/vendor/tr46.d.ts +10 -0
- package/dist/vendor/tr46.js +501 -0
- package/dist/ws-client/binaryTransport.d.ts +0 -3
- package/dist/ws-client/binaryTransport.js +15 -39
- package/dist/yamux/errors.d.ts +0 -4
- package/dist/yamux/errors.js +0 -9
- package/dist/yamux/session.d.ts +0 -5
- package/dist/yamux/session.js +4 -70
- package/dist/yamux/stream.d.ts +1 -0
- package/dist/yamux/stream.js +4 -0
- package/package.json +29 -81
- package/sbom/cyclonedx.json +2764 -0
- package/sbom/spdx.json +1947 -0
- package/YAMUX_ALIGNMENT.md +0 -127
- package/dist/_examples/flowersec/demo/v1.facade.gen.d.ts +0 -12
- package/dist/_examples/flowersec/demo/v1.facade.gen.js +0 -15
- package/dist/_examples/flowersec/demo/v1.gen.d.ts +0 -16
- package/dist/_examples/flowersec/demo/v1.gen.js +0 -86
- package/dist/_examples/flowersec/demo/v1.rpc.gen.d.ts +0 -11
- package/dist/_examples/flowersec/demo/v1.rpc.gen.js +0 -22
- package/dist/browser/connect.d.ts +0 -13
- package/dist/browser/connect.js +0 -31
- package/dist/browser/reconnectConfig.d.ts +0 -15
- package/dist/browser/reconnectConfig.js +0 -20
- package/dist/client-connect/common.d.ts +0 -26
- package/dist/client-connect/common.js +0 -167
- package/dist/client-connect/connectCore.d.ts +0 -61
- package/dist/client-connect/connectCore.js +0 -572
- package/dist/client-connect/contract.d.ts +0 -8
- package/dist/client-connect/contract.js +0 -51
- package/dist/client-connect/termination.d.ts +0 -6
- package/dist/client-connect/termination.js +0 -7
- package/dist/client-connect/transportSecurity.d.ts +0 -27
- package/dist/client-connect/transportSecurity.js +0 -199
- package/dist/client-connect/tunnelAttachCloseReason.d.ts +0 -3
- package/dist/client-connect/tunnelAttachCloseReason.js +0 -23
- package/dist/client.d.ts +0 -23
- package/dist/connect/artifact.d.ts +0 -36
- package/dist/connect/artifact.js +0 -213
- package/dist/connect/resolveArtifact.d.ts +0 -22
- package/dist/connect/resolveArtifact.js +0 -87
- package/dist/controlplane/channelInit.d.ts +0 -27
- package/dist/controlplane/channelInit.js +0 -116
- package/dist/controlplane/http.d.ts +0 -16
- package/dist/controlplane/http.js +0 -59
- package/dist/controlplane/index.d.ts +0 -6
- package/dist/controlplane/index.js +0 -5
- package/dist/controlplane/issuer.d.ts +0 -18
- package/dist/controlplane/issuer.js +0 -113
- package/dist/controlplane/request.d.ts +0 -51
- package/dist/controlplane/request.js +0 -273
- package/dist/controlplane/token.d.ts +0 -33
- package/dist/controlplane/token.js +0 -119
- package/dist/direct-client/connect.d.ts +0 -9
- package/dist/direct-client/connect.js +0 -90
- package/dist/direct-client/index.d.ts +0 -1
- package/dist/direct-client/index.js +0 -1
- package/dist/e2ee/constants.d.ts +0 -9
- package/dist/e2ee/constants.js +0 -18
- package/dist/e2ee/errors.d.ts +0 -5
- package/dist/e2ee/errors.js +0 -8
- package/dist/e2ee/framing.d.ts +0 -12
- package/dist/e2ee/framing.js +0 -57
- package/dist/e2ee/handshake.d.ts +0 -88
- package/dist/e2ee/handshake.js +0 -353
- package/dist/e2ee/index.d.ts +0 -7
- package/dist/e2ee/index.js +0 -7
- package/dist/e2ee/kdf.d.ts +0 -15
- package/dist/e2ee/kdf.js +0 -39
- package/dist/e2ee/record.d.ts +0 -11
- package/dist/e2ee/record.js +0 -80
- package/dist/e2ee/secureChannel.d.ts +0 -93
- package/dist/e2ee/secureChannel.js +0 -342
- package/dist/e2ee/transcript.d.ts +0 -23
- package/dist/e2ee/transcript.js +0 -31
- package/dist/endpoint/index.d.ts +0 -84
- package/dist/endpoint/index.js +0 -557
- package/dist/endpoint/node.d.ts +0 -9
- package/dist/endpoint/node.js +0 -51
- package/dist/gen/flowersec/controlplane/v1.gen.d.ts +0 -36
- package/dist/gen/flowersec/controlplane/v1.gen.js +0 -135
- package/dist/gen/flowersec/direct/v1.gen.d.ts +0 -21
- package/dist/gen/flowersec/direct/v1.gen.js +0 -101
- package/dist/gen/flowersec/e2ee/v1.gen.d.ts +0 -68
- package/dist/gen/flowersec/e2ee/v1.gen.js +0 -194
- package/dist/gen/flowersec/rpc/v1.gen.d.ts +0 -30
- package/dist/gen/flowersec/rpc/v1.gen.js +0 -107
- package/dist/gen/flowersec/tunnel/v1.gen.d.ts +0 -23
- package/dist/gen/flowersec/tunnel/v1.gen.js +0 -104
- package/dist/index.d.ts +0 -22
- package/dist/index.js +0 -22
- package/dist/node/connect.d.ts +0 -10
- package/dist/node/connect.js +0 -29
- package/dist/node/reconnectConfig.d.ts +0 -16
- package/dist/node/reconnectConfig.js +0 -20
- package/dist/observability/index.d.ts +0 -1
- package/dist/observability/index.js +0 -1
- package/dist/observability/observer.d.ts +0 -52
- package/dist/observability/observer.js +0 -314
- package/dist/proxy/appWindow.d.ts +0 -37
- package/dist/proxy/appWindow.js +0 -273
- package/dist/proxy/bootstrap.d.ts +0 -35
- package/dist/proxy/bootstrap.js +0 -119
- package/dist/proxy/constants.d.ts +0 -7
- package/dist/proxy/constants.js +0 -8
- package/dist/proxy/controllerWindow.d.ts +0 -12
- package/dist/proxy/controllerWindow.js +0 -384
- package/dist/proxy/cookieJar.d.ts +0 -7
- package/dist/proxy/cookieJar.js +0 -136
- package/dist/proxy/headerPolicy.d.ts +0 -14
- package/dist/proxy/headerPolicy.js +0 -134
- package/dist/proxy/portStream.d.ts +0 -5
- package/dist/proxy/portStream.js +0 -256
- package/dist/proxy/preset.d.ts +0 -29
- package/dist/proxy/preset.js +0 -111
- package/dist/proxy/runtimeScope.d.ts +0 -57
- package/dist/proxy/runtimeScope.js +0 -218
- package/dist/proxy/server.d.ts +0 -28
- package/dist/proxy/server.js +0 -833
- package/dist/proxy/windowBridgeProtocol.d.ts +0 -65
- package/dist/proxy/windowBridgeProtocol.js +0 -11
- package/dist/reconnect/artifactControlplane.d.ts +0 -16
- package/dist/reconnect/artifactControlplane.js +0 -35
- package/dist/reconnect/index.d.ts +0 -36
- package/dist/reconnect/index.js +0 -388
- package/dist/rpc-proxy/index.d.ts +0 -1
- package/dist/rpc-proxy/index.js +0 -1
- package/dist/rpc-proxy/rpcProxy.d.ts +0 -1
- package/dist/rpc-proxy/rpcProxy.js +0 -1
- package/dist/streamhello/index.d.ts +0 -1
- package/dist/streamhello/index.js +0 -1
- package/dist/streamhello/streamHello.d.ts +0 -3
- package/dist/streamhello/streamHello.js +0 -13
- package/dist/streamio/index.d.ts +0 -32
- package/dist/streamio/index.js +0 -87
- package/dist/tunnel-client/connect.d.ts +0 -9
- package/dist/tunnel-client/connect.js +0 -147
- package/dist/tunnel-client/index.d.ts +0 -1
- package/dist/tunnel-client/index.js +0 -1
- package/dist/ws/index.d.ts +0 -1
- package/dist/ws/index.js +0 -1
- /package/dist/{client.js → rpc/wire.js} +0 -0
package/dist/defaults.js
CHANGED
|
@@ -4,6 +4,13 @@ export const SDK_DEFAULTS = Object.freeze({
|
|
|
4
4
|
handshakeTimeoutMs: 10_000,
|
|
5
5
|
handshakeClockSkewMs: 30_000,
|
|
6
6
|
}),
|
|
7
|
+
connectionController: Object.freeze({
|
|
8
|
+
initialDelayMs: 250,
|
|
9
|
+
maxDelayMs: 30_000,
|
|
10
|
+
factor: 2,
|
|
11
|
+
jitterRatio: 0,
|
|
12
|
+
defaultAttemptLimit: null,
|
|
13
|
+
}),
|
|
7
14
|
e2ee: Object.freeze({
|
|
8
15
|
maxHandshakePayloadBytes: 8 * 1024,
|
|
9
16
|
maxRecordBytes: 1024 * 1024,
|
|
@@ -39,11 +46,4 @@ export const SDK_DEFAULTS = Object.freeze({
|
|
|
39
46
|
defaultTimeoutMs: 30_000,
|
|
40
47
|
maxTimeoutMs: 300_000,
|
|
41
48
|
}),
|
|
42
|
-
reconnect: Object.freeze({
|
|
43
|
-
maxAttempts: 5,
|
|
44
|
-
initialDelayMs: 500,
|
|
45
|
-
maxDelayMs: 10_000,
|
|
46
|
-
factor: 1.8,
|
|
47
|
-
jitterRatio: 0.2,
|
|
48
|
-
}),
|
|
49
49
|
});
|
package/dist/facade.d.ts
CHANGED
|
@@ -1,27 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export
|
|
8
|
-
export {
|
|
9
|
-
export type {
|
|
10
|
-
export {
|
|
11
|
-
export
|
|
12
|
-
export {
|
|
13
|
-
export type { ClientObserverLike } from "./observability/observer.js";
|
|
14
|
-
export type { Client, ClientPath } from "./client.js";
|
|
15
|
-
export type { LivenessOptions } from "./client-connect/connectCore.js";
|
|
16
|
-
export type { WebSocketLimits } from "./ws-client/binaryTransport.js";
|
|
17
|
-
export type { YamuxLimits } from "./yamux/session.js";
|
|
18
|
-
export type { FlowersecErrorCode, FlowersecPath, FlowersecStage } from "./utils/errors.js";
|
|
19
|
-
export { FlowersecError } from "./utils/errors.js";
|
|
20
|
-
export { AllowPlaintextForLoopback, createNetworkPlaintextPolicy, PlaintextRiskAcceptance, RequireTLS, } from "./client-connect/transportSecurity.js";
|
|
21
|
-
export type { NetworkPlaintextPolicyOptions, TransportSecurityPolicy, TransportSecurityPolicyInput, TransportSecurityPolicyPreset, } from "./client-connect/transportSecurity.js";
|
|
22
|
-
export type { TunnelConnectOptions } from "./tunnel-client/connect.js";
|
|
23
|
-
export type { DirectConnectOptions } from "./direct-client/connect.js";
|
|
24
|
-
export type ConnectOptions = TunnelConnectOptions | DirectConnectOptions;
|
|
25
|
-
export declare function connectTunnel(grant: ChannelInitGrant, opts: TunnelConnectOptions): Promise<Client>;
|
|
26
|
-
export declare function connectDirect(info: DirectConnectInfo, opts: DirectConnectOptions): Promise<Client>;
|
|
27
|
-
export declare function connect(input: ConnectArtifact, opts: ConnectOptions): Promise<Client>;
|
|
1
|
+
export type { ByteStream, IncomingStream, JsonObject, JsonPrimitive, JsonValue, OperationOptions, RpcPeer, RpcResult, SessionErrorCode, StreamOpenOptions, UnreliableMessageChannel, UnreliableMessageSendOptions, UnreliableMessageSendResult, SessionTermination, Session, } from "./public/contract.js";
|
|
2
|
+
export { SessionError, UnreliableMessageError } from "./public/contract.js";
|
|
3
|
+
export { createStreamMetadata, StreamMetadataError } from "./public/streamMetadata.js";
|
|
4
|
+
export type { StreamMetadata } from "./public/streamMetadata.js";
|
|
5
|
+
export { ArtifactLeaseError, createArtifactLease, } from "./public/artifactLease.js";
|
|
6
|
+
export type { ArtifactLease } from "./public/artifactLease.js";
|
|
7
|
+
export { Artifact, ArtifactError, parseArtifact } from "./public/artifact.js";
|
|
8
|
+
export type { ArtifactErrorCode } from "./public/artifact.js";
|
|
9
|
+
export type { ConnectErrorCode } from "./public/connectError.js";
|
|
10
|
+
export { ConnectError } from "./public/connectError.js";
|
|
11
|
+
export { ConnectionControllerError } from "./connectionController.js";
|
|
12
|
+
export type { ArtifactSource, ArtifactSourceResult, ConnectionController, ConnectionControllerFailure, ConnectionControllerOptions, ConnectionSnapshot, ConnectionState, RetryDisposition, } from "./connectionController.js";
|
package/dist/facade.js
CHANGED
|
@@ -1,24 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
export { FlowersecError } from "./utils/errors.js";
|
|
8
|
-
export { AllowPlaintextForLoopback, createNetworkPlaintextPolicy, PlaintextRiskAcceptance, RequireTLS, } from "./client-connect/transportSecurity.js";
|
|
9
|
-
export async function connectTunnel(grant, opts) {
|
|
10
|
-
return await connectTunnelInternal(grant, opts);
|
|
11
|
-
}
|
|
12
|
-
export async function connectDirect(info, opts) {
|
|
13
|
-
return await connectDirectInternal(info, opts);
|
|
14
|
-
}
|
|
15
|
-
// connect resolves an artifact to its explicit direct or tunnel transport.
|
|
16
|
-
export async function connect(input, opts) {
|
|
17
|
-
const normalized = await resolveConnectArtifact(input, opts);
|
|
18
|
-
const nextObserver = normalized.observer ?? opts.observer;
|
|
19
|
-
const nextOpts = (nextObserver === opts.observer ? opts : { ...opts, observer: nextObserver });
|
|
20
|
-
if (normalized.kind === "direct") {
|
|
21
|
-
return await connectDirectInternal(normalized.input, nextOpts);
|
|
22
|
-
}
|
|
23
|
-
return await connectTunnelInternal(normalized.input, nextOpts);
|
|
24
|
-
}
|
|
1
|
+
export { SessionError, UnreliableMessageError } from "./public/contract.js";
|
|
2
|
+
export { createStreamMetadata, StreamMetadataError } from "./public/streamMetadata.js";
|
|
3
|
+
export { ArtifactLeaseError, createArtifactLease, } from "./public/artifactLease.js";
|
|
4
|
+
export { Artifact, ArtifactError, parseArtifact } from "./public/artifact.js";
|
|
5
|
+
export { ConnectError } from "./public/connectError.js";
|
|
6
|
+
export { ConnectionControllerError } from "./connectionController.js";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ArtifactLease } from "../public/artifactLease.js";
|
|
2
|
+
import type { Session } from "../public/contract.js";
|
|
3
|
+
import { type ArtifactSource, type ConnectionController } from "../connectionController.js";
|
|
4
|
+
export type SessionTLSOptions = Readonly<{
|
|
5
|
+
ca?: string | Uint8Array;
|
|
6
|
+
serverCertificateHash?: Uint8Array;
|
|
7
|
+
}>;
|
|
8
|
+
export type SessionOptions = Readonly<{
|
|
9
|
+
origin: string;
|
|
10
|
+
signal?: AbortSignal;
|
|
11
|
+
connectTimeoutMs?: number;
|
|
12
|
+
tls?: SessionTLSOptions;
|
|
13
|
+
}>;
|
|
14
|
+
export type ConnectionControllerOptions = Readonly<{
|
|
15
|
+
origin: string;
|
|
16
|
+
connectTimeoutMs?: number;
|
|
17
|
+
tls?: SessionTLSOptions;
|
|
18
|
+
maximumAttempts?: number;
|
|
19
|
+
}>;
|
|
20
|
+
export declare function createConnectionController(source: ArtifactSource, options: ConnectionControllerOptions): ConnectionController;
|
|
21
|
+
export declare function connect(lease: ArtifactLease, options: SessionOptions): Promise<Session>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { NODE_RUNTIME_CAPABILITY_V2 } from "./runtimeCapability.js";
|
|
2
|
+
import { composeCandidateAttemptFactoryV2, SessionConnectorV2, } from "../connector/sessionConnector.js";
|
|
3
|
+
import { createWebSocketCandidateFactoryV2 } from "../connector/adapters/webSocketCandidate.js";
|
|
4
|
+
import { createWebTransportCandidateFactoryV2 } from "../connector/adapters/webTransportCandidate.js";
|
|
5
|
+
import { createNodeWsFactory } from "./wsFactory.js";
|
|
6
|
+
import { createNodeWebTransportClientV2 } from "./webTransportClient.js";
|
|
7
|
+
import { projectSessionV2 } from "../v2/publicSession.js";
|
|
8
|
+
import { ConnectError } from "../public/connectError.js";
|
|
9
|
+
import { nodeSessionRuntimeV2 } from "./sessionRuntime.js";
|
|
10
|
+
import { createConnectionControllerV2, } from "../connectionController.js";
|
|
11
|
+
export function createConnectionController(source, options) {
|
|
12
|
+
const controllerOptions = options.maximumAttempts === undefined
|
|
13
|
+
? {}
|
|
14
|
+
: { maximumAttempts: options.maximumAttempts };
|
|
15
|
+
return createConnectionControllerV2(source, async (lease, signal) => await connect(lease, {
|
|
16
|
+
origin: options.origin,
|
|
17
|
+
signal,
|
|
18
|
+
...(options.connectTimeoutMs === undefined ? {} : { connectTimeoutMs: options.connectTimeoutMs }),
|
|
19
|
+
...(options.tls === undefined ? {} : { tls: options.tls }),
|
|
20
|
+
}), controllerOptions);
|
|
21
|
+
}
|
|
22
|
+
export async function connect(lease, options) {
|
|
23
|
+
let origin;
|
|
24
|
+
let wsFactory;
|
|
25
|
+
try {
|
|
26
|
+
origin = normalizeOrigin(options.origin);
|
|
27
|
+
wsFactory = createNodeWsFactory(options.tls);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
throw new ConnectError("invalid_options");
|
|
31
|
+
}
|
|
32
|
+
const connector = new SessionConnectorV2(lease, composeCandidateAttemptFactoryV2({
|
|
33
|
+
websocket: createWebSocketCandidateFactoryV2((url, subprotocol) => wsFactory(url, origin, subprotocol)),
|
|
34
|
+
webtransport: createWebTransportCandidateFactoryV2(async (candidate, artifact, signal) => await createNodeWebTransportClientV2(candidate.normalized_url, {
|
|
35
|
+
path: artifact.path.kind,
|
|
36
|
+
inboundBidirectionalStreamCapacity: artifact.session.max_inbound_streams + 2,
|
|
37
|
+
signal,
|
|
38
|
+
...(options.tls?.serverCertificateHash === undefined
|
|
39
|
+
? {}
|
|
40
|
+
: { serverCertificateHash: options.tls.serverCertificateHash }),
|
|
41
|
+
})),
|
|
42
|
+
}), {
|
|
43
|
+
capability: NODE_RUNTIME_CAPABILITY_V2,
|
|
44
|
+
runtime: nodeSessionRuntimeV2,
|
|
45
|
+
...(options.connectTimeoutMs === undefined ? {} : { connectTimeoutMs: options.connectTimeoutMs }),
|
|
46
|
+
});
|
|
47
|
+
const result = await connector.connect(options.signal === undefined ? {} : { signal: options.signal });
|
|
48
|
+
return projectSessionV2(result.session);
|
|
49
|
+
}
|
|
50
|
+
function normalizeOrigin(input) {
|
|
51
|
+
let parsed;
|
|
52
|
+
try {
|
|
53
|
+
parsed = new URL(input);
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
throw new TypeError("origin must be an absolute HTTP(S) origin");
|
|
57
|
+
}
|
|
58
|
+
if ((parsed.protocol !== "https:" && parsed.protocol !== "http:") || parsed.origin !== input || parsed.username !== "" || parsed.password !== "") {
|
|
59
|
+
throw new TypeError("origin must be an absolute HTTP(S) origin without path, query, or credentials");
|
|
60
|
+
}
|
|
61
|
+
return parsed.origin;
|
|
62
|
+
}
|
package/dist/node/index.d.ts
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export
|
|
4
|
-
export { connectDirectNode, connectNode, connectTunnelNode } from "./connect.js";
|
|
5
|
-
export type { DirectNodeReconnectConfig, NodeReconnectConfig, TunnelNodeReconnectConfig, } from "./reconnectConfig.js";
|
|
6
|
-
export { createDirectNodeReconnectConfig, createNodeReconnectConfig, createTunnelNodeReconnectConfig, } from "./reconnectConfig.js";
|
|
7
|
-
export * from "../endpoint/index.js";
|
|
8
|
-
export * from "../endpoint/node.js";
|
|
9
|
-
export * from "../proxy/server.js";
|
|
10
|
-
export type { ConnectArtifact, CorrelationContext, CorrelationKV, DirectClientConnectArtifact, ScopeMetadataEntry, TunnelClientConnectArtifact, } from "../connect/artifact.js";
|
|
11
|
-
export { assertConnectArtifact } from "../connect/artifact.js";
|
|
1
|
+
export { connect, createConnectionController } from "./connectSession.js";
|
|
2
|
+
export type { ConnectionControllerOptions, SessionOptions, SessionTLSOptions, } from "./connectSession.js";
|
|
3
|
+
export * from "../facade.js";
|
package/dist/node/index.js
CHANGED
|
@@ -1,8 +1,2 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export
|
|
3
|
-
export { connectDirectNode, connectNode, connectTunnelNode } from "./connect.js";
|
|
4
|
-
export { createDirectNodeReconnectConfig, createNodeReconnectConfig, createTunnelNodeReconnectConfig, } from "./reconnectConfig.js";
|
|
5
|
-
export * from "../endpoint/index.js";
|
|
6
|
-
export * from "../endpoint/node.js";
|
|
7
|
-
export * from "../proxy/server.js";
|
|
8
|
-
export { assertConnectArtifact } from "../connect/artifact.js";
|
|
1
|
+
export { connect, createConnectionController } from "./connectSession.js";
|
|
2
|
+
export * from "../facade.js";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const NODE_RUNTIME_CAPABILITY_V2: Readonly<{
|
|
2
|
+
language: string;
|
|
3
|
+
runtime: string;
|
|
4
|
+
schemaVersion: 2;
|
|
5
|
+
tuples: readonly import("../v2/capability.js").RuntimeCapabilityTupleV2[];
|
|
6
|
+
unsupported: readonly import("../v2/capability.js").UnsupportedRuntimeCarrierV2[];
|
|
7
|
+
}>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { defineRuntimeCapabilityDescriptorV2 } from "../v2/capability.js";
|
|
2
|
+
export const NODE_RUNTIME_CAPABILITY_V2 = defineRuntimeCapabilityDescriptorV2("node", [
|
|
3
|
+
{ carrier: "websocket", datagrams: false, migration: false, networkMode: "dial", path: "direct", reliableStreams: true, sessionRole: "client" },
|
|
4
|
+
{ carrier: "websocket", datagrams: false, migration: false, networkMode: "dial", path: "tunnel", reliableStreams: true, sessionRole: "client" },
|
|
5
|
+
{ carrier: "websocket", datagrams: false, migration: false, networkMode: "dial", path: "tunnel", reliableStreams: true, sessionRole: "server" },
|
|
6
|
+
{ carrier: "webtransport", datagrams: true, migration: false, networkMode: "dial", path: "direct", reliableStreams: true, sessionRole: "client" },
|
|
7
|
+
{ carrier: "webtransport", datagrams: true, migration: false, networkMode: "dial", path: "tunnel", reliableStreams: true, sessionRole: "client" },
|
|
8
|
+
{ carrier: "webtransport", datagrams: true, migration: false, networkMode: "dial", path: "tunnel", reliableStreams: true, sessionRole: "server" },
|
|
9
|
+
{ carrier: "webtransport", datagrams: true, migration: false, networkMode: "listen", path: "direct", reliableStreams: true, sessionRole: "server" },
|
|
10
|
+
], [{ carrier: "raw_quic", reason: "raw_quic_adapter_not_implemented" }]);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
import { performance } from "node:perf_hooks";
|
|
3
|
+
export const nodeSessionRuntimeV2 = Object.freeze({
|
|
4
|
+
entropy(length) {
|
|
5
|
+
if (!Number.isSafeInteger(length) || length < 1 || length > 65_536) {
|
|
6
|
+
throw new RangeError("entropy length must be an integer from 1 to 65536");
|
|
7
|
+
}
|
|
8
|
+
return Uint8Array.from(randomBytes(length));
|
|
9
|
+
},
|
|
10
|
+
monotonicMilliseconds() {
|
|
11
|
+
return performance.now();
|
|
12
|
+
},
|
|
13
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { NativeCarrierSessionV2 } from "../v2/carrier.js";
|
|
2
|
+
import type { PathKind } from "../v2/contract.js";
|
|
3
|
+
export type NodeWebTransportClientOptionsV2 = Readonly<{
|
|
4
|
+
path: PathKind;
|
|
5
|
+
inboundBidirectionalStreamCapacity: number;
|
|
6
|
+
signal?: AbortSignal;
|
|
7
|
+
serverCertificateHash?: Uint8Array;
|
|
8
|
+
}>;
|
|
9
|
+
export declare function createNodeWebTransportClientV2(url: string, options: NodeWebTransportClientOptionsV2): Promise<NativeCarrierSessionV2>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { adaptWebTransportCarrierSessionV2 } from "../transport/webTransportAdapter.js";
|
|
2
|
+
import { RuntimeError } from "../runtime/errors.js";
|
|
3
|
+
export async function createNodeWebTransportClientV2(url, options) {
|
|
4
|
+
let parsed;
|
|
5
|
+
try {
|
|
6
|
+
parsed = new URL(url);
|
|
7
|
+
}
|
|
8
|
+
catch (error) {
|
|
9
|
+
throw new RuntimeError("runtime_start_failed", "Node WebTransport URL is invalid", error);
|
|
10
|
+
}
|
|
11
|
+
if (parsed.protocol !== "https:" || parsed.username !== "" || parsed.password !== "") {
|
|
12
|
+
throw new RuntimeError("runtime_start_failed", "Node WebTransport requires an HTTPS URL without credentials");
|
|
13
|
+
}
|
|
14
|
+
if (options.signal?.aborted === true)
|
|
15
|
+
throw options.signal.reason;
|
|
16
|
+
let transport;
|
|
17
|
+
try {
|
|
18
|
+
const runtime = await loadNodeWebTransportRuntime();
|
|
19
|
+
await raceAbort(runtime.quicheLoaded, options.signal);
|
|
20
|
+
transport = new runtime.WebTransport(parsed.href, {
|
|
21
|
+
requireUnreliable: true,
|
|
22
|
+
...(options.serverCertificateHash === undefined
|
|
23
|
+
? {}
|
|
24
|
+
: { serverCertificateHashes: [{ algorithm: "sha-256", value: options.serverCertificateHash.slice() }] }),
|
|
25
|
+
});
|
|
26
|
+
await raceAbort(transport.ready, options.signal);
|
|
27
|
+
return adaptWebTransportCarrierSessionV2(transport, {
|
|
28
|
+
path: options.path,
|
|
29
|
+
inboundBidirectionalStreamCapacity: options.inboundBidirectionalStreamCapacity,
|
|
30
|
+
datagramMaxSize: 1_200,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
transport?.close({ closeCode: 6, reason: "Node WebTransport start failed" });
|
|
35
|
+
if (error instanceof RuntimeError)
|
|
36
|
+
throw error;
|
|
37
|
+
throw new RuntimeError("runtime_start_failed", "Node WebTransport failed to start", error);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const NODE_WEBTRANSPORT_MODULE = "@fails-components/webtransport";
|
|
41
|
+
let runtimePromise;
|
|
42
|
+
function loadNodeWebTransportRuntime() {
|
|
43
|
+
runtimePromise ??= import(NODE_WEBTRANSPORT_MODULE).then((value) => value);
|
|
44
|
+
return runtimePromise;
|
|
45
|
+
}
|
|
46
|
+
async function raceAbort(promise, signal) {
|
|
47
|
+
if (signal === undefined)
|
|
48
|
+
return await promise;
|
|
49
|
+
if (signal.aborted)
|
|
50
|
+
throw signal.reason;
|
|
51
|
+
return await new Promise((resolve, reject) => {
|
|
52
|
+
const abort = () => reject(signal.reason);
|
|
53
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
54
|
+
void promise.then(resolve, reject).finally(() => signal.removeEventListener("abort", abort));
|
|
55
|
+
});
|
|
56
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { NativeCarrierSessionV2 } from "../v2/carrier.js";
|
|
2
|
+
import type { PathKind } from "../v2/contract.js";
|
|
3
|
+
export type NodeWebTransportServerOptionsV2 = Readonly<{
|
|
4
|
+
host: string;
|
|
5
|
+
port: number;
|
|
6
|
+
path: string;
|
|
7
|
+
certificate: string;
|
|
8
|
+
privateKey: string;
|
|
9
|
+
carrierPath: PathKind;
|
|
10
|
+
inboundBidirectionalStreamCapacity: number;
|
|
11
|
+
}>;
|
|
12
|
+
export type NodeWebTransportServerV2 = Readonly<{
|
|
13
|
+
address(): Readonly<{
|
|
14
|
+
host: string;
|
|
15
|
+
port: number;
|
|
16
|
+
}>;
|
|
17
|
+
accept(options?: Readonly<{
|
|
18
|
+
signal?: AbortSignal;
|
|
19
|
+
}>): Promise<NativeCarrierSessionV2>;
|
|
20
|
+
close(): Promise<void>;
|
|
21
|
+
}>;
|
|
22
|
+
export declare function startNodeWebTransportServerV2(options: NodeWebTransportServerOptionsV2): Promise<NodeWebTransportServerV2>;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
import { adaptWebTransportCarrierSessionV2 } from "../transport/webTransportAdapter.js";
|
|
3
|
+
import { RuntimeError } from "../runtime/errors.js";
|
|
4
|
+
export async function startNodeWebTransportServerV2(options) {
|
|
5
|
+
if (!options.path.startsWith("/") || options.path.includes("?") || options.path.includes("#")) {
|
|
6
|
+
throw new TypeError("Node WebTransport server path must be an absolute path");
|
|
7
|
+
}
|
|
8
|
+
if (!Number.isInteger(options.port) || options.port < 0 || options.port > 65_535) {
|
|
9
|
+
throw new RangeError("Node WebTransport server port is invalid");
|
|
10
|
+
}
|
|
11
|
+
let runtime;
|
|
12
|
+
try {
|
|
13
|
+
runtime = await loadNodeWebTransportRuntime();
|
|
14
|
+
await runtime.quicheLoaded;
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
throw new RuntimeError("runtime_start_failed", "Node WebTransport runtime failed to load", error);
|
|
18
|
+
}
|
|
19
|
+
let server;
|
|
20
|
+
try {
|
|
21
|
+
server = new runtime.Http3Server({
|
|
22
|
+
host: options.host,
|
|
23
|
+
port: options.port,
|
|
24
|
+
secret: randomBytes(32).toString("hex"),
|
|
25
|
+
cert: options.certificate,
|
|
26
|
+
privKey: options.privateKey,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
throw new RuntimeError("runtime_start_failed", "Node WebTransport server could not be created", error);
|
|
31
|
+
}
|
|
32
|
+
const sessions = server.sessionStream(options.path).getReader();
|
|
33
|
+
server.startServer();
|
|
34
|
+
try {
|
|
35
|
+
await server.ready;
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
server.stopServer();
|
|
39
|
+
throw new RuntimeError("runtime_start_failed", "Node WebTransport server failed to start", error);
|
|
40
|
+
}
|
|
41
|
+
let closed = false;
|
|
42
|
+
return {
|
|
43
|
+
address() {
|
|
44
|
+
const address = server.address();
|
|
45
|
+
if (address === null)
|
|
46
|
+
throw new Error("Node WebTransport server is not listening");
|
|
47
|
+
return Object.freeze({ host: address.host, port: address.port });
|
|
48
|
+
},
|
|
49
|
+
async accept(acceptOptions = {}) {
|
|
50
|
+
if (closed)
|
|
51
|
+
throw new Error("Node WebTransport server is closed");
|
|
52
|
+
try {
|
|
53
|
+
const result = await raceAbort(sessions.read(), acceptOptions.signal);
|
|
54
|
+
if (result.done || result.value === undefined) {
|
|
55
|
+
throw new RuntimeError("runtime_crashed", "Node WebTransport server session stream closed");
|
|
56
|
+
}
|
|
57
|
+
await raceAbort(result.value.ready, acceptOptions.signal);
|
|
58
|
+
return adaptWebTransportCarrierSessionV2(result.value, {
|
|
59
|
+
path: options.carrierPath,
|
|
60
|
+
inboundBidirectionalStreamCapacity: options.inboundBidirectionalStreamCapacity,
|
|
61
|
+
datagramMaxSize: 1_200,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
if (error instanceof RuntimeError)
|
|
66
|
+
throw error;
|
|
67
|
+
throw new RuntimeError("runtime_crashed", "Node WebTransport server failed while accepting a session", error);
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
async close() {
|
|
71
|
+
if (closed)
|
|
72
|
+
return;
|
|
73
|
+
closed = true;
|
|
74
|
+
server.stopServer();
|
|
75
|
+
try {
|
|
76
|
+
await server.closed;
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
throw new RuntimeError("runtime_crashed", "Node WebTransport server failed while closing", error);
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
const NODE_WEBTRANSPORT_MODULE = "@fails-components/webtransport";
|
|
85
|
+
let runtimePromise;
|
|
86
|
+
function loadNodeWebTransportRuntime() {
|
|
87
|
+
runtimePromise ??= import(NODE_WEBTRANSPORT_MODULE).then((value) => value);
|
|
88
|
+
return runtimePromise;
|
|
89
|
+
}
|
|
90
|
+
async function raceAbort(promise, signal) {
|
|
91
|
+
if (signal === undefined)
|
|
92
|
+
return await promise;
|
|
93
|
+
if (signal.aborted)
|
|
94
|
+
throw signal.reason;
|
|
95
|
+
return await new Promise((resolve, reject) => {
|
|
96
|
+
const abort = () => reject(signal.reason);
|
|
97
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
98
|
+
void promise.then(resolve, reject).finally(() => signal.removeEventListener("abort", abort));
|
|
99
|
+
});
|
|
100
|
+
}
|
package/dist/node/wsFactory.d.ts
CHANGED
|
@@ -2,5 +2,7 @@ import type { WebSocketLike } from "../ws-client/binaryTransport.js";
|
|
|
2
2
|
export type NodeWsFactoryOptions = Readonly<{
|
|
3
3
|
maxPayload?: number;
|
|
4
4
|
perMessageDeflate?: boolean;
|
|
5
|
+
/** Additional trusted CA certificate(s) for private WSS deployments. */
|
|
6
|
+
ca?: string | Uint8Array;
|
|
5
7
|
}>;
|
|
6
|
-
export declare function createNodeWsFactory(opts?: NodeWsFactoryOptions): (url: string, origin: string) => WebSocketLike;
|
|
8
|
+
export declare function createNodeWsFactory(opts?: NodeWsFactoryOptions): (url: string, origin: string, subprotocol?: string) => WebSocketLike;
|
package/dist/node/wsFactory.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
2
|
import { defaultWsMaxPayload } from "./wsDefaults.js";
|
|
3
|
-
// createNodeWsFactory
|
|
3
|
+
// createNodeWsFactory adapts the Node WebSocket runtime for candidate dialing.
|
|
4
4
|
//
|
|
5
5
|
// It uses the "ws" package to set the Origin header explicitly (browsers set Origin automatically).
|
|
6
6
|
export function createNodeWsFactory(opts = {}) {
|
|
@@ -13,11 +13,12 @@ export function createNodeWsFactory(opts = {}) {
|
|
|
13
13
|
}
|
|
14
14
|
const maxPayload = maxPayloadRaw;
|
|
15
15
|
const perMessageDeflate = opts.perMessageDeflate ?? false;
|
|
16
|
-
return (url, origin) => {
|
|
17
|
-
const raw = new WebSocketCtor(url, {
|
|
16
|
+
return (url, origin, subprotocol) => {
|
|
17
|
+
const raw = new WebSocketCtor(url, subprotocol === undefined ? undefined : [subprotocol], {
|
|
18
18
|
headers: { Origin: origin },
|
|
19
19
|
maxPayload,
|
|
20
20
|
perMessageDeflate,
|
|
21
|
+
...(opts.ca === undefined ? {} : { ca: opts.ca }),
|
|
21
22
|
});
|
|
22
23
|
// Map (type -> user listener -> wrapped listener) so removeEventListener works.
|
|
23
24
|
const listeners = new Map();
|
|
@@ -24,10 +24,10 @@ export type ServiceWorkerControllerGuardOptions = Readonly<{
|
|
|
24
24
|
repair?: ServiceWorkerControllerGuardRepairOptions;
|
|
25
25
|
monitor?: ServiceWorkerControllerGuardMonitorOptions;
|
|
26
26
|
conflicts?: ServiceWorkerControllerGuardConflictPolicy;
|
|
27
|
-
onControllerMismatch?: (
|
|
27
|
+
onControllerMismatch?: (context: ServiceWorkerControllerGuardMismatchContext) => "repair" | "ignore" | void;
|
|
28
28
|
}>;
|
|
29
29
|
export type ServiceWorkerControllerGuardHandle = Readonly<{
|
|
30
|
-
ensure
|
|
31
|
-
dispose
|
|
30
|
+
ensure(): Promise<void>;
|
|
31
|
+
dispose(): void;
|
|
32
32
|
}>;
|
|
33
|
-
export declare function createServiceWorkerControllerGuard(
|
|
33
|
+
export declare function createServiceWorkerControllerGuard(options: ServiceWorkerControllerGuardOptions): ServiceWorkerControllerGuardHandle;
|