@hushscript/sdk 1.1.0 → 1.1.2

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 -17
  2. package/package.json +11 -8
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { inspect } from 'util';
2
2
  import createClient from 'openapi-fetch';
3
+ import { getMaxListeners, defaultMaxListeners, setMaxListeners } from 'events';
3
4
  import { setImmediate } from 'timers/promises';
4
5
  import { parseBlob } from 'music-metadata';
5
6
  import { randomUUID } from 'crypto';
@@ -9,7 +10,7 @@ import { stat, open } from 'fs/promises';
9
10
 
10
11
  // package.json
11
12
  var package_default = {
12
- version: "1.1.0"};
13
+ version: "1.1.2"};
13
14
 
14
15
  // src/clock.ts
15
16
  var systemClock = {
@@ -1061,8 +1062,6 @@ function guardApi(raw) {
1061
1062
  guard("request", raw.request);
1062
1063
  return guarded2;
1063
1064
  }
1064
-
1065
- // src/http/fetch.ts
1066
1065
  var BODY_CHUNK_BYTES = 256 * 1024;
1067
1066
  var NEVER_SENT = /^(?:ECONNREFUSED|ENOTFOUND|EAI_AGAIN|UND_ERR_CONNECT_TIMEOUT|ERR_TLS_CERT_ALTNAME_INVALID|CERT_|DEPTH_ZERO_|UNABLE_TO_|SELF_SIGNED_)/;
1068
1067
  function isTransportFailure(error) {
@@ -1095,6 +1094,10 @@ function bodyStream(bytes, progress) {
1095
1094
  );
1096
1095
  }
1097
1096
  var NULL_BODY_STATUSES = /* @__PURE__ */ new Set([204, 205, 304]);
1097
+ function callerSignal(input, init) {
1098
+ if (init?.signal !== void 0) return init.signal;
1099
+ return input instanceof Request ? input.signal : null;
1100
+ }
1098
1101
  function whenAborted(signal) {
1099
1102
  return new Promise((_resolve, reject) => {
1100
1103
  if (signal.aborted) reject(signal.reason);
@@ -1138,13 +1141,13 @@ async function pause(cfg, ms, signal) {
1138
1141
  throw error;
1139
1142
  }
1140
1143
  }
1141
- async function attempt(timeoutMs, cfg, request, callerSignal) {
1144
+ async function attempt(timeoutMs, cfg, request, callerSignal2) {
1142
1145
  const controller = new AbortController();
1143
1146
  const stopTimer = new AbortController();
1144
1147
  const onCallerAbort = () => {
1145
- controller.abort(callerSignal.reason);
1148
+ controller.abort(callerSignal2.reason);
1146
1149
  };
1147
- callerSignal.addEventListener("abort", onCallerAbort);
1150
+ callerSignal2.addEventListener("abort", onCallerAbort);
1148
1151
  let timedOut = false;
1149
1152
  cfg.clock.sleep(timeoutMs, stopTimer.signal).then(
1150
1153
  () => {
@@ -1181,34 +1184,37 @@ async function attempt(timeoutMs, cfg, request, callerSignal) {
1181
1184
  return { failure: { error, sent, timedOut, foreign } };
1182
1185
  } finally {
1183
1186
  stopTimer.abort();
1184
- callerSignal.removeEventListener("abort", onCallerAbort);
1187
+ callerSignal2.removeEventListener("abort", onCallerAbort);
1185
1188
  }
1186
1189
  }
1187
- function terminalFailure(timeoutMs, retryClass, operation, failure, callerSignal) {
1190
+ function terminalFailure(timeoutMs, retryClass, operation, failure, callerSignal2) {
1188
1191
  const code = errorCode(failure.error);
1189
- const callerAborted = isAborted(callerSignal);
1192
+ const callerAborted = isAborted(callerSignal2);
1190
1193
  const reason = callerAborted ? "The request was aborted." : failure.timedOut ? `The request timed out after ${String(timeoutMs / 1e3)} s.` : `The request failed before a response arrived (${describeError(failure.error)}${code === void 0 ? "" : `; code ${code}`}).`;
1191
1194
  if (retryClass === "never" && failure.sent) {
1192
1195
  return new OutcomeUnknownError({
1193
1196
  message: `${reason} The request was sent, so its outcome is unknown.`,
1194
1197
  hint: OutcomeUnknownError.hintFor(operation),
1195
- cause: callerAborted ? aborted2(callerSignal) : failure.error
1198
+ cause: callerAborted ? aborted2(callerSignal2) : failure.error
1196
1199
  });
1197
1200
  }
1198
- if (callerAborted) return aborted2(callerSignal);
1201
+ if (callerAborted) return aborted2(callerSignal2);
1199
1202
  return new NetworkError({ message: reason, cause: failure.error });
1200
1203
  }
1201
1204
  function hardenedFetch(cfg, retryClass, options = {}) {
1202
1205
  const timeoutMs = options.timeoutMs ?? cfg.timeoutMs;
1203
- const guarded2 = async (input, init, wire) => {
1206
+ const guarded2 = async (input, init, wire, signal) => {
1204
1207
  const direct = init?.body instanceof Uint8Array ? init.body : null;
1205
- const request = new Request(input, direct === null ? init : { ...init, body: null });
1208
+ const request = new Request(input, {
1209
+ ...init,
1210
+ ...direct === null ? {} : { body: null },
1211
+ signal: null
1212
+ });
1206
1213
  const url2 = new URL(request.url);
1207
1214
  const method = request.method.toUpperCase();
1208
1215
  const operation = operationFor(method, url2.pathname);
1209
1216
  const apiOrigin = new URL(cfg.baseUrl).origin;
1210
1217
  const target = describeTarget(url2, apiOrigin);
1211
- const signal = request.signal;
1212
1218
  const buffer = direct ?? new Uint8Array(await request.arrayBuffer());
1213
1219
  const bytes = buffer.byteLength > 0 ? buffer : null;
1214
1220
  const headers = new Headers(request.headers);
@@ -1296,8 +1302,18 @@ function hardenedFetch(cfg, retryClass, options = {}) {
1296
1302
  };
1297
1303
  return async (input, init) => {
1298
1304
  const wire = { sent: false, everSent: false };
1305
+ const caller = callerSignal(input, init);
1306
+ const controller = new AbortController();
1307
+ const forward = () => {
1308
+ controller.abort(caller?.reason);
1309
+ };
1299
1310
  try {
1300
- return await guarded2(input, init, wire);
1311
+ if (caller?.aborted === true) forward();
1312
+ else if (caller !== null) {
1313
+ if (getMaxListeners(caller) === defaultMaxListeners) setMaxListeners(1500, caller);
1314
+ caller.addEventListener("abort", forward);
1315
+ }
1316
+ return await guarded2(input, init, wire, controller.signal);
1301
1317
  } catch (error) {
1302
1318
  if (error instanceof HushscriptError) throw wire.everSent ? error : markNotSent(error);
1303
1319
  if (retryClass === "never" && wire.sent) {
@@ -1308,6 +1324,8 @@ function hardenedFetch(cfg, retryClass, options = {}) {
1308
1324
  }
1309
1325
  const wrapped = asHushscriptError(error, wire.everSent);
1310
1326
  throw wire.everSent ? wrapped : markNotSent(wrapped);
1327
+ } finally {
1328
+ caller?.removeEventListener("abort", forward);
1311
1329
  }
1312
1330
  };
1313
1331
  }
@@ -1315,10 +1333,12 @@ function hardenedFetch(cfg, retryClass, options = {}) {
1315
1333
  // src/http/transport.ts
1316
1334
  function createTransport(config) {
1317
1335
  return async (input, init) => {
1318
- const request = new Request(input, init);
1336
+ const request = new Request(input, { ...init, signal: null });
1319
1337
  const pathname = new URL(request.url).pathname;
1320
1338
  const body = request.method.toUpperCase() === "POST" && pathname === "/v1/uploads" ? await request.clone().text() : null;
1321
- return hardenedFetch(config, retryClassForRequest(request.method, pathname, body))(request);
1339
+ return hardenedFetch(config, retryClassForRequest(request.method, pathname, body))(request, {
1340
+ signal: callerSignal(input, init)
1341
+ });
1322
1342
  };
1323
1343
  }
1324
1344
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hushscript/sdk",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "Official TypeScript SDK for the Hushscript transcription API.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -41,34 +41,37 @@
41
41
  "conformance": "node --disable-warning=ExperimentalWarning conformance/runner.ts"
42
42
  },
43
43
  "dependencies": {
44
- "music-metadata": "^12.2.3",
44
+ "music-metadata": "^12.3.2",
45
45
  "openapi-fetch": "^0.17.0"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@arethetypeswrong/cli": "0.18.5",
49
49
  "@eslint/js": "10.0.1",
50
- "@stryker-mutator/core": "10.0.0",
51
- "@stryker-mutator/vitest-runner": "10.0.0",
50
+ "@stryker-mutator/core": "10.1.1",
51
+ "@stryker-mutator/vitest-runner": "10.1.1",
52
52
  "@types/node": "24.19.2",
53
53
  "@vitest/coverage-v8": "5.0.5",
54
- "eslint": "10.13.0",
54
+ "eslint": "10.14.0",
55
55
  "eslint-plugin-n": "18.5.0",
56
- "eslint-plugin-regexp": "3.3.1",
56
+ "eslint-plugin-regexp": "3.3.2",
57
57
  "fast-check": "4.10.2",
58
58
  "globals": "17.13.0",
59
- "knip": "6.42.1",
59
+ "knip": "6.44.0",
60
60
  "openapi-typescript": "7.13.0",
61
61
  "prettier": "3.9.10",
62
62
  "publint": "0.3.25",
63
63
  "tsup": "9.0.0",
64
64
  "typescript": "6.0.3",
65
65
  "typescript-floor": "npm:typescript@5.5.4",
66
- "typescript-eslint": "8.72.0",
66
+ "typescript-eslint": "8.72.1",
67
67
  "vitest": "5.0.5"
68
68
  },
69
69
  "overrides": {
70
70
  "openapi-typescript": {
71
71
  "typescript": "$typescript"
72
+ },
73
+ "typed-rest-client": {
74
+ "qs": "6.16.1"
72
75
  }
73
76
  }
74
77
  }