@floegence/flowersec-core 0.14.0 → 0.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,6 +14,19 @@ export async function connectCore(args) {
14
14
  const observer = normalizeObserver(args.opts.observer);
15
15
  const signal = args.opts.signal;
16
16
  const connectStart = nowSeconds();
17
+ let attachState = args.path === "tunnel" ? "not_started" : "accepted";
18
+ const reportAttachSuccess = () => {
19
+ if (args.path !== "tunnel" || attachState !== "sent")
20
+ return;
21
+ observer.onAttach("ok", undefined);
22
+ attachState = "accepted";
23
+ };
24
+ const reportAttachFailure = (reason) => {
25
+ if (args.path !== "tunnel" || attachState !== "sent")
26
+ return;
27
+ observer.onAttach("fail", reason);
28
+ attachState = "failed";
29
+ };
17
30
  const origin = typeof args.opts.origin === "string" ? args.opts.origin.trim() : "";
18
31
  if (origin === "") {
19
32
  throw new FlowersecError({ path: args.path, stage: "validate", code: "missing_origin", message: "missing origin" });
@@ -131,9 +144,11 @@ export async function connectCore(args) {
131
144
  if (args.path === "tunnel") {
132
145
  try {
133
146
  ws.send(args.attach.attachJson);
147
+ attachState = "sent";
134
148
  }
135
149
  catch (err) {
136
150
  observer.onAttach("fail", "send_failed");
151
+ attachState = "failed";
137
152
  try {
138
153
  transport.close();
139
154
  }
@@ -161,9 +176,7 @@ export async function connectCore(args) {
161
176
  ...(signal !== undefined ? { signal } : {}),
162
177
  onCancel: () => transport.close(),
163
178
  });
164
- if (args.path === "tunnel") {
165
- observer.onAttach("ok", undefined);
166
- }
179
+ reportAttachSuccess();
167
180
  observer.onHandshake(args.path, "ok", undefined, nowSeconds() - handshakeStart);
168
181
  }
169
182
  catch (err) {
@@ -173,12 +186,12 @@ export async function connectCore(args) {
173
186
  if (args.path === "tunnel" && err instanceof WsCloseError) {
174
187
  const reason = err.reason;
175
188
  if (isTunnelAttachCloseReason(reason)) {
176
- observer.onAttach("fail", reason);
189
+ reportAttachFailure(reason);
177
190
  throw new FlowersecError({ path: args.path, stage: "attach", code: reason, message: "tunnel rejected attach", cause: err });
178
191
  }
179
192
  }
180
193
  if (args.path === "tunnel") {
181
- observer.onAttach("ok", undefined);
194
+ reportAttachFailure(handshakeCode === "timeout" ? "timeout" : handshakeCode === "canceled" ? "canceled" : "attach_failed");
182
195
  }
183
196
  observer.onHandshake(args.path, "fail", handshakeCode, handshakeElapsedSeconds);
184
197
  throw new FlowersecError({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@floegence/flowersec-core",
3
- "version": "0.14.0",
3
+ "version": "0.14.1",
4
4
  "description": "Flowersec core TypeScript library (browser-friendly E2EE + multiplexing over WebSocket).",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -108,7 +108,10 @@
108
108
  "build": "tsc -p tsconfig.build.json",
109
109
  "bench": "vitest bench --run",
110
110
  "test": "vitest run",
111
- "lint": "eslint ."
111
+ "lint": "eslint .",
112
+ "verify:package": "node ./scripts/verify-package-exports.mjs",
113
+ "prepack": "npm run build",
114
+ "prepublishOnly": "npm run build && npm run verify:package"
112
115
  },
113
116
  "dependencies": {
114
117
  "@noble/ciphers": "^0.6.0",