@floegence/flowersec-core 0.26.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 -30
- package/dist/facade.js +6 -30
- 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 -83
- 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 -12
- package/dist/browser/connect.js +0 -31
- package/dist/browser/controlplane.d.ts +0 -15
- package/dist/browser/controlplane.js +0 -64
- 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 -37
- package/dist/connect/artifact.js +0 -217
- package/dist/connect/internalNormalize.d.ts +0 -22
- package/dist/connect/internalNormalize.js +0 -173
- 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 -76
- package/dist/e2ee/secureChannel.d.ts +0 -92
- package/dist/e2ee/secureChannel.js +0 -328
- 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 -12
- 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 -157
- 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
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { type ClientObserverLike } from "../observability/observer.js";
|
|
2
1
|
export declare class WsCloseError extends Error {
|
|
3
2
|
readonly code: number | undefined;
|
|
4
3
|
readonly reason: string | undefined;
|
|
@@ -24,11 +23,9 @@ export type WebSocketLimits = Readonly<{
|
|
|
24
23
|
export declare const DEFAULT_WEB_SOCKET_LIMITS: WebSocketLimits;
|
|
25
24
|
export type WebSocketBinaryTransportOptions = Readonly<{
|
|
26
25
|
webSocketLimits?: Partial<WebSocketLimits>;
|
|
27
|
-
observer?: ClientObserverLike;
|
|
28
26
|
}>;
|
|
29
27
|
export declare class WebSocketBinaryTransport {
|
|
30
28
|
private readonly ws;
|
|
31
|
-
private readonly observer;
|
|
32
29
|
private readonly queue;
|
|
33
30
|
private queueHead;
|
|
34
31
|
private queueBytes;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { emitObserverDiagnostic, normalizeObserver } from "../observability/observer.js";
|
|
2
1
|
import { AbortError, TimeoutError, throwIfAborted } from "../utils/errors.js";
|
|
3
2
|
export class WsCloseError extends Error {
|
|
4
3
|
code;
|
|
@@ -28,8 +27,6 @@ export const DEFAULT_WEB_SOCKET_LIMITS = Object.freeze({
|
|
|
28
27
|
export class WebSocketBinaryTransport {
|
|
29
28
|
// Underlying WebSocket instance (browser or polyfill).
|
|
30
29
|
ws;
|
|
31
|
-
// Observer for websocket-level errors.
|
|
32
|
-
observer;
|
|
33
30
|
// Buffered inbound frames when no reader is waiting.
|
|
34
31
|
queue = [];
|
|
35
32
|
// Read cursor for queue to avoid Array.shift() O(n).
|
|
@@ -55,7 +52,6 @@ export class WebSocketBinaryTransport {
|
|
|
55
52
|
pendingOutboundBytes = 0;
|
|
56
53
|
constructor(ws, opts = {}) {
|
|
57
54
|
this.ws = ws;
|
|
58
|
-
this.observer = normalizeObserver(opts.observer);
|
|
59
55
|
this.limits = normalizeWebSocketLimits(opts.webSocketLimits);
|
|
60
56
|
this.ws.binaryType = "arraybuffer";
|
|
61
57
|
this.ws.addEventListener("message", this.onMessage);
|
|
@@ -129,7 +125,7 @@ export class WebSocketBinaryTransport {
|
|
|
129
125
|
if (frame.byteLength > this.limits.outboundHardLimitBytes ||
|
|
130
126
|
this.pendingOutboundBytes + this.ws.bufferedAmount + frame.byteLength > this.limits.outboundHardLimitBytes) {
|
|
131
127
|
const err = new Error("ws send queue exceeds hard limit");
|
|
132
|
-
this.failAndClose(err
|
|
128
|
+
this.failAndClose(err);
|
|
133
129
|
throw err;
|
|
134
130
|
}
|
|
135
131
|
this.pendingOutboundBytes += frame.byteLength;
|
|
@@ -151,8 +147,6 @@ export class WebSocketBinaryTransport {
|
|
|
151
147
|
close() {
|
|
152
148
|
if (!this.localCloseRequested) {
|
|
153
149
|
this.localCloseRequested = true;
|
|
154
|
-
if (this.error == null)
|
|
155
|
-
this.observer.onWsClose("local");
|
|
156
150
|
}
|
|
157
151
|
this.fail(new Error("websocket closed"));
|
|
158
152
|
this.ws.removeEventListener("message", this.onMessage);
|
|
@@ -168,7 +162,7 @@ export class WebSocketBinaryTransport {
|
|
|
168
162
|
if (this.error != null)
|
|
169
163
|
return;
|
|
170
164
|
if (typeof data === "string") {
|
|
171
|
-
this.fail(new Error("unexpected text frame")
|
|
165
|
+
this.fail(new Error("unexpected text frame"));
|
|
172
166
|
return;
|
|
173
167
|
}
|
|
174
168
|
if (data instanceof Uint8Array) {
|
|
@@ -177,9 +171,8 @@ export class WebSocketBinaryTransport {
|
|
|
177
171
|
}
|
|
178
172
|
if (data instanceof ArrayBuffer) {
|
|
179
173
|
if (this.queueBytes + data.byteLength > this.limits.maxInboundQueuedBytes) {
|
|
180
|
-
this.fail(new Error("ws recv buffer exceeded")
|
|
174
|
+
this.fail(new Error("ws recv buffer exceeded"));
|
|
181
175
|
this.localCloseRequested = true;
|
|
182
|
-
this.observer.onWsClose("local");
|
|
183
176
|
this.ws.close();
|
|
184
177
|
return;
|
|
185
178
|
}
|
|
@@ -189,9 +182,8 @@ export class WebSocketBinaryTransport {
|
|
|
189
182
|
if (ArrayBuffer.isView(data)) {
|
|
190
183
|
const view = data;
|
|
191
184
|
if (this.queueBytes + view.byteLength > this.limits.maxInboundQueuedBytes) {
|
|
192
|
-
this.fail(new Error("ws recv buffer exceeded")
|
|
185
|
+
this.fail(new Error("ws recv buffer exceeded"));
|
|
193
186
|
this.localCloseRequested = true;
|
|
194
|
-
this.observer.onWsClose("local");
|
|
195
187
|
this.ws.close();
|
|
196
188
|
return;
|
|
197
189
|
}
|
|
@@ -200,9 +192,8 @@ export class WebSocketBinaryTransport {
|
|
|
200
192
|
}
|
|
201
193
|
if (typeof Blob !== "undefined" && data instanceof Blob) {
|
|
202
194
|
if (this.queueBytes + data.size > this.limits.maxInboundQueuedBytes) {
|
|
203
|
-
this.fail(new Error("ws recv buffer exceeded")
|
|
195
|
+
this.fail(new Error("ws recv buffer exceeded"));
|
|
204
196
|
this.localCloseRequested = true;
|
|
205
|
-
this.observer.onWsClose("local");
|
|
206
197
|
this.ws.close();
|
|
207
198
|
return;
|
|
208
199
|
}
|
|
@@ -212,23 +203,22 @@ export class WebSocketBinaryTransport {
|
|
|
212
203
|
this.push(new Uint8Array(ab));
|
|
213
204
|
return;
|
|
214
205
|
}
|
|
215
|
-
this.fail(new Error("unexpected message type")
|
|
206
|
+
this.fail(new Error("unexpected message type"));
|
|
216
207
|
}
|
|
217
208
|
onMessage = (ev) => {
|
|
218
209
|
const data = ev.data;
|
|
219
210
|
this.messageChain = this.messageChain.then(() => this.handleMessage(data)).catch((err) => {
|
|
220
211
|
const e = err instanceof Error ? err : new Error(String(err));
|
|
221
|
-
this.fail(e
|
|
212
|
+
this.fail(e);
|
|
222
213
|
});
|
|
223
214
|
};
|
|
224
215
|
onError = () => {
|
|
225
|
-
this.fail(new Error("websocket error")
|
|
216
|
+
this.fail(new Error("websocket error"));
|
|
226
217
|
};
|
|
227
218
|
onClose = (ev) => {
|
|
228
219
|
if (!this.localCloseRequested) {
|
|
229
220
|
const code = typeof ev?.code === "number" ? ev.code : undefined;
|
|
230
221
|
const reason = typeof ev?.reason === "string" ? ev.reason : undefined;
|
|
231
|
-
this.observer.onWsClose("peer_or_error", code);
|
|
232
222
|
this.fail(new WsCloseError(code, reason));
|
|
233
223
|
return;
|
|
234
224
|
}
|
|
@@ -246,9 +236,8 @@ export class WebSocketBinaryTransport {
|
|
|
246
236
|
return;
|
|
247
237
|
}
|
|
248
238
|
if (this.queueBytes + b.length > this.limits.maxInboundQueuedBytes) {
|
|
249
|
-
this.fail(new Error("ws recv buffer exceeded")
|
|
239
|
+
this.fail(new Error("ws recv buffer exceeded"));
|
|
250
240
|
this.localCloseRequested = true;
|
|
251
|
-
this.observer.onWsClose("local");
|
|
252
241
|
this.ws.close();
|
|
253
242
|
return;
|
|
254
243
|
}
|
|
@@ -261,7 +250,7 @@ export class WebSocketBinaryTransport {
|
|
|
261
250
|
throw this.error;
|
|
262
251
|
if (frame.byteLength > this.limits.outboundHardLimitBytes) {
|
|
263
252
|
const err = new Error("ws send frame exceeds hard limit");
|
|
264
|
-
this.failAndClose(err
|
|
253
|
+
this.failAndClose(err);
|
|
265
254
|
throw err;
|
|
266
255
|
}
|
|
267
256
|
const startedAt = Date.now();
|
|
@@ -273,7 +262,7 @@ export class WebSocketBinaryTransport {
|
|
|
273
262
|
throw this.error;
|
|
274
263
|
if (Date.now() - startedAt >= this.limits.outboundDrainTimeoutMs) {
|
|
275
264
|
const err = new TimeoutError("ws send buffer drain timeout");
|
|
276
|
-
this.failAndClose(err
|
|
265
|
+
this.failAndClose(err);
|
|
277
266
|
throw err;
|
|
278
267
|
}
|
|
279
268
|
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
@@ -286,24 +275,14 @@ export class WebSocketBinaryTransport {
|
|
|
286
275
|
onHandedToWebSocket();
|
|
287
276
|
if (this.ws.bufferedAmount > this.limits.outboundHardLimitBytes) {
|
|
288
277
|
const err = new Error("ws send buffer exceeded");
|
|
289
|
-
this.failAndClose(err
|
|
278
|
+
this.failAndClose(err);
|
|
290
279
|
throw err;
|
|
291
280
|
}
|
|
292
281
|
}
|
|
293
|
-
failAndClose(err
|
|
294
|
-
|
|
295
|
-
stage: "transport",
|
|
296
|
-
code_domain: "event",
|
|
297
|
-
code: reason === "send_buffer_timeout" ? "queue_pressure" : "resource_limit_reached",
|
|
298
|
-
result: "fail",
|
|
299
|
-
resource: "websocket_outbound_bytes",
|
|
300
|
-
current: this.ws.bufferedAmount + this.pendingOutboundBytes,
|
|
301
|
-
limit: this.limits.outboundHardLimitBytes,
|
|
302
|
-
});
|
|
303
|
-
this.fail(err, reason);
|
|
282
|
+
failAndClose(err) {
|
|
283
|
+
this.fail(err);
|
|
304
284
|
if (!this.localCloseRequested) {
|
|
305
285
|
this.localCloseRequested = true;
|
|
306
|
-
this.observer.onWsClose("local");
|
|
307
286
|
this.ws.close();
|
|
308
287
|
}
|
|
309
288
|
}
|
|
@@ -359,13 +338,10 @@ export class WebSocketBinaryTransport {
|
|
|
359
338
|
this.waitersSettled = 0;
|
|
360
339
|
}
|
|
361
340
|
// fail transitions the transport into a permanent error state.
|
|
362
|
-
fail(err
|
|
341
|
+
fail(err) {
|
|
363
342
|
if (this.error != null)
|
|
364
343
|
return;
|
|
365
344
|
this.error = err;
|
|
366
|
-
if (reason != null) {
|
|
367
|
-
this.observer.onWsError(reason);
|
|
368
|
-
}
|
|
369
345
|
const ws = this.waiters;
|
|
370
346
|
const start = this.waitersHead;
|
|
371
347
|
this.waiters = [];
|
package/dist/yamux/errors.d.ts
CHANGED
|
@@ -13,7 +13,3 @@ export declare class YamuxResourceExhaustedError extends Error {
|
|
|
13
13
|
constructor(resource: string, current: number, limit: number);
|
|
14
14
|
}
|
|
15
15
|
export declare function isYamuxResourceExhaustedError(error: unknown): error is YamuxResourceExhaustedError;
|
|
16
|
-
export declare class YamuxPingTimeoutError extends Error {
|
|
17
|
-
constructor();
|
|
18
|
-
}
|
|
19
|
-
export declare function isYamuxPingTimeoutError(error: unknown): error is YamuxPingTimeoutError;
|
package/dist/yamux/errors.js
CHANGED
|
@@ -32,12 +32,3 @@ export class YamuxResourceExhaustedError extends Error {
|
|
|
32
32
|
export function isYamuxResourceExhaustedError(error) {
|
|
33
33
|
return error instanceof YamuxResourceExhaustedError;
|
|
34
34
|
}
|
|
35
|
-
export class YamuxPingTimeoutError extends Error {
|
|
36
|
-
constructor() {
|
|
37
|
-
super("yamux ping timeout");
|
|
38
|
-
this.name = "YamuxPingTimeoutError";
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
export function isYamuxPingTimeoutError(error) {
|
|
42
|
-
return error instanceof YamuxPingTimeoutError;
|
|
43
|
-
}
|
package/dist/yamux/session.d.ts
CHANGED
|
@@ -53,9 +53,6 @@ export declare class YamuxSession {
|
|
|
53
53
|
private readonly sendWindowWaiters;
|
|
54
54
|
private readonly inboundStreams;
|
|
55
55
|
private sessionReceiveBytes;
|
|
56
|
-
private nextPingId;
|
|
57
|
-
private readonly pingWaiters;
|
|
58
|
-
private activeProbe;
|
|
59
56
|
constructor(conn: ByteDuplex, opts: YamuxSessionOptions);
|
|
60
57
|
openStream(opts?: Readonly<{
|
|
61
58
|
signal?: AbortSignal;
|
|
@@ -65,8 +62,6 @@ export declare class YamuxSession {
|
|
|
65
62
|
outboundFrameBytes(): number;
|
|
66
63
|
streamWriteQueueBytes(): number;
|
|
67
64
|
releaseReceiveBytes(bytes: number): void;
|
|
68
|
-
probeLiveness(timeoutMs?: number): Promise<number>;
|
|
69
|
-
private startLivenessProbe;
|
|
70
65
|
sendRst(id: number): Promise<void>;
|
|
71
66
|
notifySendWindow(streamId: number): void;
|
|
72
67
|
waitForSendWindow(streamId: number): Promise<void>;
|
package/dist/yamux/session.js
CHANGED
|
@@ -2,7 +2,7 @@ import { ByteReader } from "./byteReader.js";
|
|
|
2
2
|
import { decodeHeader, encodeHeader, HEADER_LEN } from "./header.js";
|
|
3
3
|
import { FLAG_ACK, FLAG_RST, FLAG_SYN, TYPE_DATA, TYPE_GO_AWAY, TYPE_PING, TYPE_WINDOW_UPDATE, YAMUX_VERSION } from "./constants.js";
|
|
4
4
|
import { YamuxStream } from "./stream.js";
|
|
5
|
-
import {
|
|
5
|
+
import { YamuxResourceExhaustedError } from "./errors.js";
|
|
6
6
|
import { SDK_DEFAULTS } from "../defaults.js";
|
|
7
7
|
export const DEFAULT_YAMUX_LIMITS = Object.freeze({
|
|
8
8
|
maxActiveStreams: SDK_DEFAULTS.yamux.maxActiveStreams,
|
|
@@ -37,9 +37,6 @@ export class YamuxSession {
|
|
|
37
37
|
sendWindowWaiters = new Map();
|
|
38
38
|
inboundStreams = new Set();
|
|
39
39
|
sessionReceiveBytes = 0;
|
|
40
|
-
nextPingId = 1;
|
|
41
|
-
pingWaiters = new Map();
|
|
42
|
-
activeProbe;
|
|
43
40
|
constructor(conn, opts) {
|
|
44
41
|
this.conn = conn;
|
|
45
42
|
this.reader = new ByteReader(() => this.conn.read());
|
|
@@ -100,53 +97,6 @@ export class YamuxSession {
|
|
|
100
97
|
releaseReceiveBytes(bytes) {
|
|
101
98
|
this.sessionReceiveBytes = Math.max(0, this.sessionReceiveBytes - Math.max(0, bytes));
|
|
102
99
|
}
|
|
103
|
-
// probeLiveness performs a correlated yamux PING SYN/ACK round trip.
|
|
104
|
-
async probeLiveness(timeoutMs = 10_000) {
|
|
105
|
-
if (this.activeProbe != null)
|
|
106
|
-
return await this.activeProbe;
|
|
107
|
-
const probe = this.startLivenessProbe(timeoutMs);
|
|
108
|
-
this.activeProbe = probe;
|
|
109
|
-
try {
|
|
110
|
-
return await probe;
|
|
111
|
-
}
|
|
112
|
-
finally {
|
|
113
|
-
if (this.activeProbe === probe)
|
|
114
|
-
this.activeProbe = undefined;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
async startLivenessProbe(timeoutMs) {
|
|
118
|
-
if (this.closed)
|
|
119
|
-
throw new Error("session closed");
|
|
120
|
-
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0)
|
|
121
|
-
throw new RangeError("timeoutMs must be positive");
|
|
122
|
-
let opaque = this.nextPingId >>> 0;
|
|
123
|
-
do {
|
|
124
|
-
opaque = this.nextPingId++ >>> 0;
|
|
125
|
-
if (this.nextPingId > 0xffffffff)
|
|
126
|
-
this.nextPingId = 1;
|
|
127
|
-
} while (opaque === 0 || this.pingWaiters.has(opaque));
|
|
128
|
-
const startedAt = monotonicMilliseconds();
|
|
129
|
-
return await new Promise((resolve, reject) => {
|
|
130
|
-
const timer = setTimeout(() => {
|
|
131
|
-
this.pingWaiters.delete(opaque);
|
|
132
|
-
const error = new YamuxPingTimeoutError();
|
|
133
|
-
reject(error);
|
|
134
|
-
this.fail(error);
|
|
135
|
-
}, timeoutMs);
|
|
136
|
-
timer?.unref?.();
|
|
137
|
-
this.pingWaiters.set(opaque, { startedAt, resolve, reject, timer });
|
|
138
|
-
const hdr = encodeHeader({ type: TYPE_PING, flags: FLAG_SYN, streamId: 0, length: opaque });
|
|
139
|
-
void this.writeRaw(hdr).catch((err) => {
|
|
140
|
-
const waiter = this.pingWaiters.get(opaque);
|
|
141
|
-
if (waiter == null)
|
|
142
|
-
return;
|
|
143
|
-
this.pingWaiters.delete(opaque);
|
|
144
|
-
clearTimeout(waiter.timer);
|
|
145
|
-
reject(err);
|
|
146
|
-
this.fail(err);
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
100
|
// sendRst sends a reset frame and removes the stream.
|
|
151
101
|
async sendRst(id) {
|
|
152
102
|
const hdr = encodeHeader({ type: TYPE_WINDOW_UPDATE, flags: FLAG_RST, streamId: id, length: 0 });
|
|
@@ -222,17 +172,10 @@ export class YamuxSession {
|
|
|
222
172
|
this.closed = true;
|
|
223
173
|
this.conn.close();
|
|
224
174
|
this.wakeSendWindowWaiters();
|
|
225
|
-
for (const waiter of this.pingWaiters.values()) {
|
|
226
|
-
clearTimeout(waiter.timer);
|
|
227
|
-
waiter.reject(new Error("session closed"));
|
|
228
|
-
}
|
|
229
|
-
this.pingWaiters.clear();
|
|
230
175
|
const streams = Array.from(this.streams.values());
|
|
231
176
|
this.streams.clear();
|
|
232
177
|
for (const s of streams) {
|
|
233
|
-
|
|
234
|
-
// Session shutdown has already made the stream terminal.
|
|
235
|
-
});
|
|
178
|
+
s.abort(new Error("session closed"));
|
|
236
179
|
}
|
|
237
180
|
}
|
|
238
181
|
wakeSendWindowWaiters() {
|
|
@@ -321,14 +264,8 @@ export class YamuxSession {
|
|
|
321
264
|
await this.writeRaw(hdr);
|
|
322
265
|
return;
|
|
323
266
|
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
if (waiter == null)
|
|
327
|
-
return;
|
|
328
|
-
this.pingWaiters.delete(opaque >>> 0);
|
|
329
|
-
clearTimeout(waiter.timer);
|
|
330
|
-
waiter.resolve(Math.max(0, monotonicMilliseconds() - waiter.startedAt));
|
|
331
|
-
}
|
|
267
|
+
// Yamux PING ACKs are accepted for protocol interoperability. Active
|
|
268
|
+
// liveness belongs to the established Flowersec session protocol.
|
|
332
269
|
}
|
|
333
270
|
async handleDataFrame(streamId, flags, data) {
|
|
334
271
|
if (streamId === 0) {
|
|
@@ -462,6 +399,3 @@ function normalizeYamuxLimits(input) {
|
|
|
462
399
|
throw new RangeError("maxStreamReceiveBytes must not exceed maxSessionReceiveBytes");
|
|
463
400
|
return Object.freeze(limits);
|
|
464
401
|
}
|
|
465
|
-
function monotonicMilliseconds() {
|
|
466
|
-
return typeof performance !== "undefined" ? performance.now() : Date.now();
|
|
467
|
-
}
|
package/dist/yamux/stream.d.ts
CHANGED
package/dist/yamux/stream.js
CHANGED
|
@@ -160,6 +160,10 @@ export class YamuxStream {
|
|
|
160
160
|
this.resetTask = this.session.sendRst(this.id);
|
|
161
161
|
return this.resetTask;
|
|
162
162
|
}
|
|
163
|
+
abort(err = new Error("stream aborted")) {
|
|
164
|
+
if (this.fail(err))
|
|
165
|
+
this.session.onStreamClosed(this.id);
|
|
166
|
+
}
|
|
163
167
|
fail(err) {
|
|
164
168
|
if (this.state === "reset")
|
|
165
169
|
return false;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@floegence/flowersec-core",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Flowersec core TypeScript library
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Flowersec core TypeScript library for carrier-neutral encrypted sessions and multiplexed streams.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -14,11 +14,15 @@
|
|
|
14
14
|
"type": "module",
|
|
15
15
|
"main": "./dist/facade.js",
|
|
16
16
|
"types": "./dist/facade.d.ts",
|
|
17
|
+
"bin": {
|
|
18
|
+
"flowersec-ts-cli": "./dist/cli.js"
|
|
19
|
+
},
|
|
17
20
|
"files": [
|
|
18
21
|
"dist/**",
|
|
19
22
|
"README.md",
|
|
20
23
|
"LICENSE",
|
|
21
|
-
"
|
|
24
|
+
"THIRD_PARTY_NOTICES.md",
|
|
25
|
+
"sbom/**"
|
|
22
26
|
],
|
|
23
27
|
"publishConfig": {
|
|
24
28
|
"access": "public"
|
|
@@ -36,93 +40,29 @@
|
|
|
36
40
|
"types": "./dist/browser/index.d.ts",
|
|
37
41
|
"default": "./dist/browser/index.js"
|
|
38
42
|
},
|
|
39
|
-
"./controlplane": {
|
|
40
|
-
"types": "./dist/controlplane/index.d.ts",
|
|
41
|
-
"default": "./dist/controlplane/index.js"
|
|
42
|
-
},
|
|
43
|
-
"./endpoint": {
|
|
44
|
-
"types": "./dist/endpoint/index.d.ts",
|
|
45
|
-
"default": "./dist/endpoint/index.js"
|
|
46
|
-
},
|
|
47
|
-
"./framing": {
|
|
48
|
-
"types": "./dist/framing/index.d.ts",
|
|
49
|
-
"default": "./dist/framing/index.js"
|
|
50
|
-
},
|
|
51
|
-
"./streamio": {
|
|
52
|
-
"types": "./dist/streamio/index.d.ts",
|
|
53
|
-
"default": "./dist/streamio/index.js"
|
|
54
|
-
},
|
|
55
43
|
"./proxy": {
|
|
56
44
|
"types": "./dist/proxy/index.d.ts",
|
|
57
45
|
"default": "./dist/proxy/index.js"
|
|
58
|
-
},
|
|
59
|
-
"./reconnect": {
|
|
60
|
-
"types": "./dist/reconnect/index.d.ts",
|
|
61
|
-
"default": "./dist/reconnect/index.js"
|
|
62
|
-
},
|
|
63
|
-
"./rpc": {
|
|
64
|
-
"types": "./dist/rpc/index.d.ts",
|
|
65
|
-
"default": "./dist/rpc/index.js"
|
|
66
|
-
},
|
|
67
|
-
"./yamux": {
|
|
68
|
-
"types": "./dist/yamux/index.d.ts",
|
|
69
|
-
"default": "./dist/yamux/index.js"
|
|
70
|
-
},
|
|
71
|
-
"./e2ee": {
|
|
72
|
-
"types": "./dist/e2ee/index.d.ts",
|
|
73
|
-
"default": "./dist/e2ee/index.js"
|
|
74
|
-
},
|
|
75
|
-
"./ws": {
|
|
76
|
-
"types": "./dist/ws/index.d.ts",
|
|
77
|
-
"default": "./dist/ws/index.js"
|
|
78
|
-
},
|
|
79
|
-
"./observability": {
|
|
80
|
-
"types": "./dist/observability/index.d.ts",
|
|
81
|
-
"default": "./dist/observability/index.js"
|
|
82
|
-
},
|
|
83
|
-
"./streamhello": {
|
|
84
|
-
"types": "./dist/streamhello/index.d.ts",
|
|
85
|
-
"default": "./dist/streamhello/index.js"
|
|
86
|
-
},
|
|
87
|
-
"./gen/flowersec/controlplane/*": {
|
|
88
|
-
"types": "./dist/gen/flowersec/controlplane/*.d.ts",
|
|
89
|
-
"default": "./dist/gen/flowersec/controlplane/*.js"
|
|
90
|
-
},
|
|
91
|
-
"./gen/flowersec/direct/*": {
|
|
92
|
-
"types": "./dist/gen/flowersec/direct/*.d.ts",
|
|
93
|
-
"default": "./dist/gen/flowersec/direct/*.js"
|
|
94
|
-
},
|
|
95
|
-
"./gen/flowersec/e2ee/*": {
|
|
96
|
-
"types": "./dist/gen/flowersec/e2ee/*.d.ts",
|
|
97
|
-
"default": "./dist/gen/flowersec/e2ee/*.js"
|
|
98
|
-
},
|
|
99
|
-
"./gen/flowersec/rpc/*": {
|
|
100
|
-
"types": "./dist/gen/flowersec/rpc/*.d.ts",
|
|
101
|
-
"default": "./dist/gen/flowersec/rpc/*.js"
|
|
102
|
-
},
|
|
103
|
-
"./gen/flowersec/tunnel/*": {
|
|
104
|
-
"types": "./dist/gen/flowersec/tunnel/*.d.ts",
|
|
105
|
-
"default": "./dist/gen/flowersec/tunnel/*.js"
|
|
106
|
-
},
|
|
107
|
-
"./internal": {
|
|
108
|
-
"types": "./dist/index.d.ts",
|
|
109
|
-
"default": "./dist/index.js"
|
|
110
46
|
}
|
|
111
47
|
},
|
|
112
48
|
"engines": {
|
|
113
|
-
"node": ">=
|
|
49
|
+
"node": ">=20.0.0"
|
|
114
50
|
},
|
|
115
51
|
"overrides": {
|
|
116
|
-
"
|
|
117
|
-
"
|
|
118
|
-
"postcss": "^8.5.12"
|
|
52
|
+
"js-yaml": "^4.3.0",
|
|
53
|
+
"postcss": "^8.5.23"
|
|
119
54
|
},
|
|
120
55
|
"scripts": {
|
|
121
|
-
"build": "tsc -p tsconfig.build.json",
|
|
56
|
+
"build": "node ./scripts/clean-dist.mjs && tsc -p tsconfig.build.json && node ./scripts/build-browser-vendor.mjs",
|
|
122
57
|
"bench": "vitest bench --run",
|
|
123
|
-
"test": "npm run build && vitest run",
|
|
124
|
-
"test:browser": "npm run
|
|
125
|
-
"
|
|
58
|
+
"test": "npm run build && vitest run --exclude 'src/**/*.integration.test.ts'",
|
|
59
|
+
"test:browser": "npm run test:browser:chromium",
|
|
60
|
+
"test:browser:chromium": "npm run ensure:browser && npm run build && playwright test --project=chromium",
|
|
61
|
+
"test:browser:firefox": "npm run ensure:browser:firefox && npm run build && playwright test --project=firefox-compat",
|
|
62
|
+
"test:browser:webkit": "npm run ensure:browser:webkit && npm run build && playwright test --project=webkit-smoke",
|
|
63
|
+
"ensure:browser": "node ./scripts/ensure-playwright-browsers.mjs chromium",
|
|
64
|
+
"ensure:browser:firefox": "node ./scripts/ensure-playwright-browsers.mjs firefox",
|
|
65
|
+
"ensure:browser:webkit": "node ./scripts/ensure-playwright-browsers.mjs webkit",
|
|
126
66
|
"test:coverage": "npm run build && vitest run --coverage",
|
|
127
67
|
"lint": "eslint .",
|
|
128
68
|
"verify:package": "node ./scripts/verify-package-exports.mjs",
|
|
@@ -130,19 +70,25 @@
|
|
|
130
70
|
"prepublishOnly": "npm run build && npm run verify:package"
|
|
131
71
|
},
|
|
132
72
|
"dependencies": {
|
|
73
|
+
"@fails-components/webtransport": "1.6.7",
|
|
74
|
+
"@fails-components/webtransport-transport-http3-quiche": "1.6.7",
|
|
133
75
|
"@noble/ciphers": "^0.6.0",
|
|
134
76
|
"@noble/curves": "^1.9.0",
|
|
135
77
|
"@noble/hashes": "^1.8.0",
|
|
78
|
+
"tr46": "5.0.0",
|
|
136
79
|
"ws": "^8.21.0"
|
|
137
80
|
},
|
|
138
81
|
"devDependencies": {
|
|
82
|
+
"@playwright/test": "1.62.0",
|
|
139
83
|
"@types/node": "^24.0.0",
|
|
140
84
|
"@types/ws": "^8.5.12",
|
|
141
|
-
"@
|
|
142
|
-
"@typescript-eslint/
|
|
143
|
-
"@typescript-eslint/parser": "^8.18.0",
|
|
85
|
+
"@typescript-eslint/eslint-plugin": "^8.65.0",
|
|
86
|
+
"@typescript-eslint/parser": "^8.65.0",
|
|
144
87
|
"@vitest/coverage-v8": "4.1.0",
|
|
145
|
-
"
|
|
88
|
+
"ajv": "8.20.0",
|
|
89
|
+
"ajv-formats": "3.0.1",
|
|
90
|
+
"ajv-formats-draft2019": "1.6.1",
|
|
91
|
+
"eslint": "^10.8.0",
|
|
146
92
|
"typescript": "^5.7.2",
|
|
147
93
|
"vite": "^8.0.16",
|
|
148
94
|
"vitest": "4.1.0"
|