@fire-spark/core 0.36.8 → 0.36.9

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 (2) hide show
  1. package/dist/index.js +37 -8
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -4214,9 +4214,15 @@ const createNodePinnedFetch = (pins, options = {}) => {
4214
4214
  const isIp = net.isIP(host) !== 0;
4215
4215
  return new Promise((resolve, reject) => {
4216
4216
  let settled = false;
4217
+ let activeTlsSocket = null;
4218
+ let timer = null;
4217
4219
  const done = (fn) => {
4218
4220
  if (settled) return;
4219
4221
  settled = true;
4222
+ if (timer) {
4223
+ clearTimeout(timer);
4224
+ timer = null;
4225
+ }
4220
4226
  signal?.removeEventListener("abort", onAbort);
4221
4227
  fn();
4222
4228
  };
@@ -4228,23 +4234,32 @@ const createNodePinnedFetch = (pins, options = {}) => {
4228
4234
  };
4229
4235
  if (!isIp) tlsOpts.servername = host;
4230
4236
  const socket = tls.connect(tlsOpts);
4237
+ activeTlsSocket = socket;
4231
4238
  let handedOff = false;
4232
4239
  socket.once("secureConnect", () => {
4240
+ if (settled) {
4241
+ handedOff = true;
4242
+ socket.destroy(makeAbortError());
4243
+ return;
4244
+ }
4233
4245
  const rawFp = socket.getPeerCertificate(false)?.fingerprint256 ?? null;
4234
4246
  const actual = rawFp ? normalizeCertFingerprint(rawFp) : null;
4235
4247
  if (!certMatchesAnyPin(normalizedPins, actual)) {
4236
4248
  const err = new TlsFingerprintMismatchError(href, expectedSummary, actual);
4237
4249
  handedOff = true;
4250
+ activeTlsSocket = null;
4238
4251
  socket.destroy(err);
4239
4252
  onConnect(err);
4240
4253
  return;
4241
4254
  }
4242
4255
  handedOff = true;
4256
+ activeTlsSocket = null;
4243
4257
  onConnect(null, socket);
4244
4258
  });
4245
4259
  socket.once("error", (rawErr) => {
4246
4260
  if (handedOff) return;
4247
4261
  handedOff = true;
4262
+ activeTlsSocket = null;
4248
4263
  onConnect(rawErr instanceof Error ? rawErr : new Error(String(rawErr)));
4249
4264
  });
4250
4265
  };
@@ -4284,17 +4299,27 @@ const createNodePinnedFetch = (pins, options = {}) => {
4284
4299
  done(() => reject(err));
4285
4300
  });
4286
4301
  });
4287
- const onAbort = () => {
4288
- const err = makeAbortError();
4302
+ const cancelActive = (err) => {
4303
+ if (activeTlsSocket) {
4304
+ const sock = activeTlsSocket;
4305
+ activeTlsSocket = null;
4306
+ sock.destroy(err);
4307
+ }
4289
4308
  req.destroy(err);
4290
4309
  done(() => reject(err));
4291
4310
  };
4311
+ const onAbort = () => {
4312
+ cancelActive(makeAbortError());
4313
+ };
4292
4314
  if (signal) signal.addEventListener("abort", onAbort, { once: true });
4293
- if (options.timeoutMs && options.timeoutMs > 0) req.setTimeout(options.timeoutMs, () => {
4294
- const err = makeAbortError();
4295
- req.destroy(err);
4296
- done(() => reject(err));
4297
- });
4315
+ if (options.timeoutMs && options.timeoutMs > 0) {
4316
+ timer = setTimeout(() => {
4317
+ cancelActive(makeAbortError());
4318
+ }, options.timeoutMs);
4319
+ req.setTimeout(options.timeoutMs, () => {
4320
+ cancelActive(makeAbortError());
4321
+ });
4322
+ }
4298
4323
  req.on("error", (err) => {
4299
4324
  done(() => reject(err));
4300
4325
  });
@@ -7273,7 +7298,11 @@ const markRouteDown = (input) => {
7273
7298
  snapshotStale,
7274
7299
  tlsMismatch
7275
7300
  });
7276
- if (input.route === "local") verifiedPins.delete(input.baseUrl.replace(/\/+$/, ""));
7301
+ if (input.route === "local") {
7302
+ const normalizedBase = input.baseUrl.replace(/\/+$/, "");
7303
+ const prefix = `${normalizedBase}\n`;
7304
+ for (const cachedKey of verifiedPins.keys()) if (cachedKey === normalizedBase || cachedKey.startsWith(prefix)) verifiedPins.delete(cachedKey);
7305
+ }
7277
7306
  emit$1(event, input.listener);
7278
7307
  return event;
7279
7308
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fire-spark/core",
3
- "version": "0.36.8",
3
+ "version": "0.36.9",
4
4
  "description": "Fire Spark headless SDK",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -20,8 +20,8 @@
20
20
  "big.js": "6.2.1",
21
21
  "dayjs": "1.11.9",
22
22
  "@types/big.js": "6.2.2",
23
- "@fire-spark/payments": "^0.36.8",
24
- "@fire-spark/types": "^0.36.8"
23
+ "@fire-spark/payments": "^0.36.9",
24
+ "@fire-spark/types": "^0.36.9"
25
25
  },
26
26
  "devDependencies": {
27
27
  "tsdown": "^0.22.14",