@floegence/flowersec-core 0.27.0 → 2.1.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.
Files changed (268) hide show
  1. package/README.md +91 -22
  2. package/THIRD_PARTY_NOTICES.md +141 -0
  3. package/dist/browser/connectSession.d.ts +13 -0
  4. package/dist/browser/connectSession.js +40 -0
  5. package/dist/browser/index.d.ts +3 -10
  6. package/dist/browser/index.js +2 -5
  7. package/dist/browser/runtimeCapability.d.ts +13 -0
  8. package/dist/browser/runtimeCapability.js +27 -0
  9. package/dist/browser/sessionRuntime.d.ts +2 -0
  10. package/dist/browser/sessionRuntime.js +21 -0
  11. package/dist/browser/webTransportClient.d.ts +8 -0
  12. package/dist/browser/webTransportClient.js +55 -0
  13. package/dist/cli.d.ts +2 -0
  14. package/dist/cli.js +126 -0
  15. package/dist/cliSpendMarker.d.ts +1 -0
  16. package/dist/cliSpendMarker.js +22 -0
  17. package/dist/connectionController.d.ts +54 -0
  18. package/dist/connectionController.js +438 -0
  19. package/dist/connector/adapters/webSocketCandidate.d.ts +7 -0
  20. package/dist/connector/adapters/webSocketCandidate.js +116 -0
  21. package/dist/connector/adapters/webTransportCandidate.d.ts +5 -0
  22. package/dist/connector/adapters/webTransportCandidate.js +73 -0
  23. package/dist/connector/admissionCommit.d.ts +31 -0
  24. package/dist/connector/admissionCommit.js +239 -0
  25. package/dist/connector/sessionAcceptor.d.ts +16 -0
  26. package/dist/connector/sessionAcceptor.js +114 -0
  27. package/dist/connector/sessionConfig.d.ts +3 -0
  28. package/dist/connector/sessionConfig.js +30 -0
  29. package/dist/connector/sessionConnector.d.ts +45 -0
  30. package/dist/connector/sessionConnector.js +603 -0
  31. package/dist/defaults.d.ts +7 -7
  32. package/dist/defaults.js +7 -7
  33. package/dist/facade.d.ts +12 -27
  34. package/dist/facade.js +6 -24
  35. package/dist/node/connectSession.d.ts +21 -0
  36. package/dist/node/connectSession.js +62 -0
  37. package/dist/node/index.d.ts +3 -11
  38. package/dist/node/index.js +2 -8
  39. package/dist/node/runtimeCapability.d.ts +7 -0
  40. package/dist/node/runtimeCapability.js +10 -0
  41. package/dist/node/sessionRuntime.d.ts +2 -0
  42. package/dist/node/sessionRuntime.js +13 -0
  43. package/dist/node/webTransportClient.d.ts +9 -0
  44. package/dist/node/webTransportClient.js +56 -0
  45. package/dist/node/webTransportServer.d.ts +22 -0
  46. package/dist/node/webTransportServer.js +100 -0
  47. package/dist/node/wsFactory.d.ts +3 -1
  48. package/dist/node/wsFactory.js +4 -3
  49. package/dist/proxy/controllerGuard.d.ts +4 -4
  50. package/dist/proxy/controllerGuard.js +83 -177
  51. package/dist/proxy/disableUpstreamServiceWorkerRegister.d.ts +3 -1
  52. package/dist/proxy/disableUpstreamServiceWorkerRegister.js +19 -17
  53. package/dist/proxy/index.d.ts +16 -15
  54. package/dist/proxy/index.js +8 -14
  55. package/dist/proxy/integration.d.ts +23 -71
  56. package/dist/proxy/integration.js +37 -340
  57. package/dist/proxy/registerServiceWorker.d.ts +1 -10
  58. package/dist/proxy/registerServiceWorker.js +43 -105
  59. package/dist/proxy/runtime.d.ts +3 -63
  60. package/dist/proxy/runtime.js +349 -462
  61. package/dist/proxy/scope.d.ts +6 -0
  62. package/dist/proxy/scope.js +131 -0
  63. package/dist/proxy/serviceWorker.d.ts +5 -16
  64. package/dist/proxy/serviceWorker.js +230 -617
  65. package/dist/proxy/stream.d.ts +9 -0
  66. package/dist/proxy/stream.js +40 -0
  67. package/dist/proxy/types.d.ts +78 -30
  68. package/dist/proxy/windowBridge.d.ts +61 -0
  69. package/dist/proxy/windowBridge.js +344 -0
  70. package/dist/proxy/wsPatch.d.ts +4 -14
  71. package/dist/proxy/wsPatch.js +173 -268
  72. package/dist/public/artifact.d.ts +11 -0
  73. package/dist/public/artifact.js +44 -0
  74. package/dist/public/artifactLease.d.ts +10 -0
  75. package/dist/public/artifactLease.js +48 -0
  76. package/dist/public/connectError.d.ts +6 -0
  77. package/dist/public/connectError.js +9 -0
  78. package/dist/public/contract.d.ts +83 -0
  79. package/dist/public/contract.js +17 -0
  80. package/dist/public/streamMetadata.d.ts +10 -0
  81. package/dist/public/streamMetadata.js +40 -0
  82. package/dist/rpc/caller.d.ts +1 -1
  83. package/dist/rpc/client.d.ts +1 -4
  84. package/dist/rpc/client.js +0 -21
  85. package/dist/rpc/rpcProxy.d.ts +1 -1
  86. package/dist/rpc/server.d.ts +1 -1
  87. package/dist/rpc/validate.d.ts +1 -1
  88. package/dist/rpc/wire.d.ts +15 -0
  89. package/dist/runtime/errors.d.ts +6 -0
  90. package/dist/runtime/errors.js +10 -0
  91. package/dist/transport/webSocketAdapter.d.ts +24 -0
  92. package/dist/transport/webSocketAdapter.js +234 -0
  93. package/dist/transport/webTransportAdapter.d.ts +27 -0
  94. package/dist/transport/webTransportAdapter.js +519 -0
  95. package/dist/utils/errors.d.ts +2 -20
  96. package/dist/utils/errors.js +73 -20
  97. package/dist/v2/admissionError.d.ts +4 -0
  98. package/dist/v2/admissionError.js +8 -0
  99. package/dist/v2/artifact.d.ts +128 -0
  100. package/dist/v2/artifact.js +1126 -0
  101. package/dist/v2/artifactLease.d.ts +1 -0
  102. package/dist/v2/artifactLease.js +7 -0
  103. package/dist/v2/capability.d.ts +29 -0
  104. package/dist/v2/capability.js +190 -0
  105. package/dist/v2/carrier.d.ts +79 -0
  106. package/dist/v2/carrier.js +405 -0
  107. package/dist/v2/contract.d.ts +37 -0
  108. package/dist/v2/contract.js +1 -0
  109. package/dist/v2/handshake.d.ts +80 -0
  110. package/dist/v2/handshake.js +470 -0
  111. package/dist/v2/opaqueArtifact.d.ts +1 -0
  112. package/dist/v2/opaqueArtifact.js +2 -0
  113. package/dist/v2/protocol.d.ts +99 -0
  114. package/dist/v2/protocol.js +739 -0
  115. package/dist/v2/publicSession.d.ts +1 -0
  116. package/dist/v2/publicSession.js +179 -0
  117. package/dist/v2/retryDisposition.d.ts +16 -0
  118. package/dist/v2/retryDisposition.js +30 -0
  119. package/dist/v2/session.d.ts +277 -0
  120. package/dist/v2/session.js +1879 -0
  121. package/dist/v2/streamLifetimeLedger.d.ts +31 -0
  122. package/dist/v2/streamLifetimeLedger.js +131 -0
  123. package/dist/v2/streamMetadata.d.ts +1 -0
  124. package/dist/v2/streamMetadata.js +7 -0
  125. package/dist/v2/unreliableMessage.d.ts +43 -0
  126. package/dist/v2/unreliableMessage.js +252 -0
  127. package/dist/vendor/tr46.d.ts +10 -0
  128. package/dist/vendor/tr46.js +501 -0
  129. package/dist/ws-client/binaryTransport.d.ts +0 -3
  130. package/dist/ws-client/binaryTransport.js +15 -39
  131. package/dist/yamux/errors.d.ts +0 -4
  132. package/dist/yamux/errors.js +0 -9
  133. package/dist/yamux/session.d.ts +0 -5
  134. package/dist/yamux/session.js +4 -70
  135. package/dist/yamux/stream.d.ts +1 -0
  136. package/dist/yamux/stream.js +4 -0
  137. package/package.json +29 -81
  138. package/sbom/cyclonedx.json +2764 -0
  139. package/sbom/spdx.json +1947 -0
  140. package/YAMUX_ALIGNMENT.md +0 -127
  141. package/dist/_examples/flowersec/demo/v1.facade.gen.d.ts +0 -12
  142. package/dist/_examples/flowersec/demo/v1.facade.gen.js +0 -15
  143. package/dist/_examples/flowersec/demo/v1.gen.d.ts +0 -16
  144. package/dist/_examples/flowersec/demo/v1.gen.js +0 -86
  145. package/dist/_examples/flowersec/demo/v1.rpc.gen.d.ts +0 -11
  146. package/dist/_examples/flowersec/demo/v1.rpc.gen.js +0 -22
  147. package/dist/browser/connect.d.ts +0 -13
  148. package/dist/browser/connect.js +0 -31
  149. package/dist/browser/reconnectConfig.d.ts +0 -15
  150. package/dist/browser/reconnectConfig.js +0 -20
  151. package/dist/client-connect/common.d.ts +0 -26
  152. package/dist/client-connect/common.js +0 -167
  153. package/dist/client-connect/connectCore.d.ts +0 -61
  154. package/dist/client-connect/connectCore.js +0 -572
  155. package/dist/client-connect/contract.d.ts +0 -8
  156. package/dist/client-connect/contract.js +0 -51
  157. package/dist/client-connect/termination.d.ts +0 -6
  158. package/dist/client-connect/termination.js +0 -7
  159. package/dist/client-connect/transportSecurity.d.ts +0 -27
  160. package/dist/client-connect/transportSecurity.js +0 -199
  161. package/dist/client-connect/tunnelAttachCloseReason.d.ts +0 -3
  162. package/dist/client-connect/tunnelAttachCloseReason.js +0 -23
  163. package/dist/client.d.ts +0 -23
  164. package/dist/connect/artifact.d.ts +0 -36
  165. package/dist/connect/artifact.js +0 -213
  166. package/dist/connect/resolveArtifact.d.ts +0 -22
  167. package/dist/connect/resolveArtifact.js +0 -87
  168. package/dist/controlplane/channelInit.d.ts +0 -27
  169. package/dist/controlplane/channelInit.js +0 -116
  170. package/dist/controlplane/http.d.ts +0 -16
  171. package/dist/controlplane/http.js +0 -59
  172. package/dist/controlplane/index.d.ts +0 -6
  173. package/dist/controlplane/index.js +0 -5
  174. package/dist/controlplane/issuer.d.ts +0 -18
  175. package/dist/controlplane/issuer.js +0 -113
  176. package/dist/controlplane/request.d.ts +0 -51
  177. package/dist/controlplane/request.js +0 -273
  178. package/dist/controlplane/token.d.ts +0 -33
  179. package/dist/controlplane/token.js +0 -119
  180. package/dist/direct-client/connect.d.ts +0 -9
  181. package/dist/direct-client/connect.js +0 -90
  182. package/dist/direct-client/index.d.ts +0 -1
  183. package/dist/direct-client/index.js +0 -1
  184. package/dist/e2ee/constants.d.ts +0 -9
  185. package/dist/e2ee/constants.js +0 -18
  186. package/dist/e2ee/errors.d.ts +0 -5
  187. package/dist/e2ee/errors.js +0 -8
  188. package/dist/e2ee/framing.d.ts +0 -12
  189. package/dist/e2ee/framing.js +0 -57
  190. package/dist/e2ee/handshake.d.ts +0 -88
  191. package/dist/e2ee/handshake.js +0 -353
  192. package/dist/e2ee/index.d.ts +0 -7
  193. package/dist/e2ee/index.js +0 -7
  194. package/dist/e2ee/kdf.d.ts +0 -15
  195. package/dist/e2ee/kdf.js +0 -39
  196. package/dist/e2ee/record.d.ts +0 -11
  197. package/dist/e2ee/record.js +0 -80
  198. package/dist/e2ee/secureChannel.d.ts +0 -93
  199. package/dist/e2ee/secureChannel.js +0 -342
  200. package/dist/e2ee/transcript.d.ts +0 -23
  201. package/dist/e2ee/transcript.js +0 -31
  202. package/dist/endpoint/index.d.ts +0 -84
  203. package/dist/endpoint/index.js +0 -557
  204. package/dist/endpoint/node.d.ts +0 -9
  205. package/dist/endpoint/node.js +0 -51
  206. package/dist/gen/flowersec/controlplane/v1.gen.d.ts +0 -36
  207. package/dist/gen/flowersec/controlplane/v1.gen.js +0 -135
  208. package/dist/gen/flowersec/direct/v1.gen.d.ts +0 -21
  209. package/dist/gen/flowersec/direct/v1.gen.js +0 -101
  210. package/dist/gen/flowersec/e2ee/v1.gen.d.ts +0 -68
  211. package/dist/gen/flowersec/e2ee/v1.gen.js +0 -194
  212. package/dist/gen/flowersec/rpc/v1.gen.d.ts +0 -30
  213. package/dist/gen/flowersec/rpc/v1.gen.js +0 -107
  214. package/dist/gen/flowersec/tunnel/v1.gen.d.ts +0 -23
  215. package/dist/gen/flowersec/tunnel/v1.gen.js +0 -104
  216. package/dist/index.d.ts +0 -22
  217. package/dist/index.js +0 -22
  218. package/dist/node/connect.d.ts +0 -10
  219. package/dist/node/connect.js +0 -29
  220. package/dist/node/reconnectConfig.d.ts +0 -16
  221. package/dist/node/reconnectConfig.js +0 -20
  222. package/dist/observability/index.d.ts +0 -1
  223. package/dist/observability/index.js +0 -1
  224. package/dist/observability/observer.d.ts +0 -52
  225. package/dist/observability/observer.js +0 -314
  226. package/dist/proxy/appWindow.d.ts +0 -37
  227. package/dist/proxy/appWindow.js +0 -273
  228. package/dist/proxy/bootstrap.d.ts +0 -35
  229. package/dist/proxy/bootstrap.js +0 -119
  230. package/dist/proxy/constants.d.ts +0 -7
  231. package/dist/proxy/constants.js +0 -8
  232. package/dist/proxy/controllerWindow.d.ts +0 -12
  233. package/dist/proxy/controllerWindow.js +0 -384
  234. package/dist/proxy/cookieJar.d.ts +0 -7
  235. package/dist/proxy/cookieJar.js +0 -136
  236. package/dist/proxy/headerPolicy.d.ts +0 -14
  237. package/dist/proxy/headerPolicy.js +0 -134
  238. package/dist/proxy/portStream.d.ts +0 -5
  239. package/dist/proxy/portStream.js +0 -256
  240. package/dist/proxy/preset.d.ts +0 -29
  241. package/dist/proxy/preset.js +0 -111
  242. package/dist/proxy/runtimeScope.d.ts +0 -57
  243. package/dist/proxy/runtimeScope.js +0 -218
  244. package/dist/proxy/server.d.ts +0 -28
  245. package/dist/proxy/server.js +0 -833
  246. package/dist/proxy/windowBridgeProtocol.d.ts +0 -65
  247. package/dist/proxy/windowBridgeProtocol.js +0 -11
  248. package/dist/reconnect/artifactControlplane.d.ts +0 -16
  249. package/dist/reconnect/artifactControlplane.js +0 -35
  250. package/dist/reconnect/index.d.ts +0 -36
  251. package/dist/reconnect/index.js +0 -388
  252. package/dist/rpc-proxy/index.d.ts +0 -1
  253. package/dist/rpc-proxy/index.js +0 -1
  254. package/dist/rpc-proxy/rpcProxy.d.ts +0 -1
  255. package/dist/rpc-proxy/rpcProxy.js +0 -1
  256. package/dist/streamhello/index.d.ts +0 -1
  257. package/dist/streamhello/index.js +0 -1
  258. package/dist/streamhello/streamHello.d.ts +0 -3
  259. package/dist/streamhello/streamHello.js +0 -13
  260. package/dist/streamio/index.d.ts +0 -32
  261. package/dist/streamio/index.js +0 -87
  262. package/dist/tunnel-client/connect.d.ts +0 -9
  263. package/dist/tunnel-client/connect.js +0 -147
  264. package/dist/tunnel-client/index.d.ts +0 -1
  265. package/dist/tunnel-client/index.js +0 -1
  266. package/dist/ws/index.d.ts +0 -1
  267. package/dist/ws/index.js +0 -1
  268. /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, "send_buffer_exceeded");
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"), "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"), "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"), "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"), "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"), "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, "error");
212
+ this.fail(e);
222
213
  });
223
214
  };
224
215
  onError = () => {
225
- this.fail(new Error("websocket error"), "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"), "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, "send_buffer_exceeded");
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, "send_buffer_timeout");
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, "send_buffer_exceeded");
278
+ this.failAndClose(err);
290
279
  throw err;
291
280
  }
292
281
  }
293
- failAndClose(err, reason) {
294
- emitObserverDiagnostic(this.observer, {
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, reason) {
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 = [];
@@ -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;
@@ -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
- }
@@ -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>;
@@ -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 { YamuxPingTimeoutError, YamuxResourceExhaustedError } from "./errors.js";
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
- void Promise.resolve(s.reset(new Error("session closed"))).catch(() => {
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
- if ((flags & FLAG_ACK) !== 0) {
325
- const waiter = this.pingWaiters.get(opaque >>> 0);
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
- }
@@ -24,6 +24,7 @@ export declare class YamuxStream {
24
24
  private writeSerial;
25
25
  close(): Promise<void>;
26
26
  reset(err?: Error): Promise<void>;
27
+ abort(err?: Error): void;
27
28
  private fail;
28
29
  bufferedReceiveBytes(): number;
29
30
  releaseBufferedReceiveBytes(): number;
@@ -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.27.0",
4
- "description": "Flowersec core TypeScript library (browser-friendly E2EE + multiplexing over WebSocket).",
3
+ "version": "2.1.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
- "YAMUX_ALIGNMENT.md"
24
+ "THIRD_PARTY_NOTICES.md",
25
+ "sbom/**"
22
26
  ],
23
27
  "publishConfig": {
24
28
  "access": "public"
@@ -36,91 +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
46
  }
107
47
  },
108
48
  "engines": {
109
- "node": ">=24.0.0"
49
+ "node": ">=20.0.0"
110
50
  },
111
51
  "overrides": {
112
- "brace-expansion@^1.1.7": "^1.1.13",
113
- "brace-expansion@^2.0.1": "^2.0.3",
114
- "postcss": "^8.5.12"
52
+ "js-yaml": "^4.3.0",
53
+ "postcss": "^8.5.23"
115
54
  },
116
55
  "scripts": {
117
- "build": "tsc -p tsconfig.build.json",
56
+ "build": "node ./scripts/clean-dist.mjs && tsc -p tsconfig.build.json && node ./scripts/build-browser-vendor.mjs",
118
57
  "bench": "vitest bench --run",
119
- "test": "npm run build && vitest run",
120
- "test:browser": "npm run build && playwright test",
121
- "test:browser:chromium": "npm run build && playwright test --project=chromium",
122
- "test:browser:webkit": "npm run build && playwright test --project=webkit-smoke",
123
- "ensure:browser": "node ./scripts/ensure-playwright-browsers.mjs",
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",
124
66
  "test:coverage": "npm run build && vitest run --coverage",
125
67
  "lint": "eslint .",
126
68
  "verify:package": "node ./scripts/verify-package-exports.mjs",
@@ -128,19 +70,25 @@
128
70
  "prepublishOnly": "npm run build && npm run verify:package"
129
71
  },
130
72
  "dependencies": {
73
+ "@fails-components/webtransport": "1.6.7",
74
+ "@fails-components/webtransport-transport-http3-quiche": "1.6.7",
131
75
  "@noble/ciphers": "^0.6.0",
132
76
  "@noble/curves": "^1.9.0",
133
77
  "@noble/hashes": "^1.8.0",
78
+ "tr46": "5.0.0",
134
79
  "ws": "^8.21.0"
135
80
  },
136
81
  "devDependencies": {
82
+ "@playwright/test": "1.62.0",
137
83
  "@types/node": "^24.0.0",
138
84
  "@types/ws": "^8.5.12",
139
- "@playwright/test": "1.58.2",
140
- "@typescript-eslint/eslint-plugin": "^8.18.0",
141
- "@typescript-eslint/parser": "^8.18.0",
85
+ "@typescript-eslint/eslint-plugin": "^8.65.0",
86
+ "@typescript-eslint/parser": "^8.65.0",
142
87
  "@vitest/coverage-v8": "4.1.0",
143
- "eslint": "^9.17.0",
88
+ "ajv": "8.20.0",
89
+ "ajv-formats": "3.0.1",
90
+ "ajv-formats-draft2019": "1.6.1",
91
+ "eslint": "^10.8.0",
144
92
  "typescript": "^5.7.2",
145
93
  "vite": "^8.0.16",
146
94
  "vitest": "4.1.0"