@ardrive/turbo-sdk 1.29.0-alpha.1 → 1.29.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.
@@ -220959,7 +220959,7 @@ var import_winston = __toESM(require_winston(), 1);
220959
220959
  init_dirname();
220960
220960
  init_buffer2();
220961
220961
  init_process2();
220962
- var version21 = "1.28.3";
220962
+ var version21 = "1.29.0-alpha.2";
220963
220963
 
220964
220964
  // src/common/logger.ts
220965
220965
  var TurboWinstonLogger = class _TurboWinstonLogger {
@@ -225535,10 +225535,44 @@ var TurboHTTPService = class {
225535
225535
  headers,
225536
225536
  data
225537
225537
  }) {
225538
- return this.tryRequest(
225539
- () => this.axios.post(endpoint, data, { headers, signal }),
225540
- allowedStatuses
225541
- );
225538
+ if (!(data instanceof ReadableStream)) {
225539
+ return this.tryRequest(
225540
+ () => this.axios.post(endpoint, data, { headers, signal }),
225541
+ allowedStatuses
225542
+ );
225543
+ }
225544
+ const { body, duplex } = await toFetchBody(data);
225545
+ try {
225546
+ const res = await fetch(this.axios.defaults.baseURL + endpoint, {
225547
+ method: "POST",
225548
+ headers,
225549
+ body,
225550
+ signal,
225551
+ ...duplex ? { duplex } : {}
225552
+ // Use duplex only where streams are working
225553
+ });
225554
+ if (!allowedStatuses.includes(res.status)) {
225555
+ const errorText = await res.text();
225556
+ throw new FailedRequestError(
225557
+ // Return error message from server if available
225558
+ errorText || res.statusText,
225559
+ res.status
225560
+ );
225561
+ }
225562
+ return res.json();
225563
+ } catch (error) {
225564
+ if (error instanceof FailedRequestError) {
225565
+ throw error;
225566
+ }
225567
+ if (error.message.includes("The operation was aborted")) {
225568
+ throw new CanceledError2();
225569
+ }
225570
+ this.logger.error("Error posting data", { endpoint, error });
225571
+ throw new FailedRequestError(
225572
+ error instanceof Error ? error.message : "Unknown error",
225573
+ error.response?.status
225574
+ );
225575
+ }
225542
225576
  }
225543
225577
  async tryRequest(request3, allowedStatuses) {
225544
225578
  try {
@@ -225561,6 +225595,13 @@ var TurboHTTPService = class {
225561
225595
  }
225562
225596
  }
225563
225597
  };
225598
+ async function toFetchBody(data) {
225599
+ if (!navigator.userAgent.includes("Firefox") && !navigator.userAgent.includes("Safari")) {
225600
+ return { body: data, duplex: "half" };
225601
+ }
225602
+ const blob3 = await new Response(data).blob();
225603
+ return { body: blob3 };
225604
+ }
225564
225605
 
225565
225606
  // src/common/token/index.ts
225566
225607
  init_dirname();
@@ -35,7 +35,43 @@ class TurboHTTPService {
35
35
  return this.tryRequest(() => this.axios.get(endpoint, { headers, signal }), allowedStatuses);
36
36
  }
37
37
  async post({ endpoint, signal, allowedStatuses = [200, 202], headers, data, }) {
38
- return this.tryRequest(() => this.axios.post(endpoint, data, { headers, signal }), allowedStatuses);
38
+ // Buffer and Readable keep Axios (streams work fine there)
39
+ if (!(data instanceof ReadableStream)) {
40
+ return this.tryRequest(() => this.axios.post(endpoint, data, { headers, signal }), allowedStatuses);
41
+ }
42
+ // Browser ReadableStream → use fetch with progressive enhancement of duplex
43
+ // Note: fetch does not support streams in Safari and Firefox, so we convert to Blob
44
+ // and use the `duplex` option only in browsers that support it (Chrome, Edge, Opera).
45
+ // See: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API#body
46
+ const { body, duplex } = await toFetchBody(data);
47
+ try {
48
+ const res = await fetch(this.axios.defaults.baseURL + endpoint, {
49
+ method: 'POST',
50
+ headers,
51
+ body,
52
+ signal,
53
+ ...(duplex ? { duplex } : {}), // Use duplex only where streams are working
54
+ });
55
+ if (!allowedStatuses.includes(res.status)) {
56
+ const errorText = await res.text();
57
+ throw new errors_js_1.FailedRequestError(
58
+ // Return error message from server if available
59
+ errorText || res.statusText, res.status);
60
+ }
61
+ return res.json();
62
+ }
63
+ catch (error) {
64
+ if (error instanceof errors_js_1.FailedRequestError) {
65
+ throw error; // rethrow FailedRequestError
66
+ }
67
+ // Handle CanceledError specifically
68
+ if (error.message.includes('The operation was aborted')) {
69
+ throw new axios_1.CanceledError();
70
+ }
71
+ // Log the error and throw a FailedRequestError
72
+ this.logger.error('Error posting data', { endpoint, error });
73
+ throw new errors_js_1.FailedRequestError(error instanceof Error ? error.message : 'Unknown error', error.response?.status);
74
+ }
39
75
  }
40
76
  async tryRequest(request, allowedStatuses) {
41
77
  try {
@@ -60,3 +96,12 @@ class TurboHTTPService {
60
96
  }
61
97
  }
62
98
  exports.TurboHTTPService = TurboHTTPService;
99
+ async function toFetchBody(data) {
100
+ if (!navigator.userAgent.includes('Firefox') &&
101
+ !navigator.userAgent.includes('Safari')) {
102
+ return { body: data, duplex: 'half' }; // Chrome / Edge / Opera
103
+ }
104
+ // Firefox / Safari fallback: stream → Blob
105
+ const blob = await new Response(data).blob();
106
+ return { body: blob }; // browser sets length
107
+ }
@@ -17,4 +17,4 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.version = void 0;
19
19
  // AUTOMATICALLY GENERATED FILE - DO NOT TOUCH
20
- exports.version = '1.29.0-alpha.1';
20
+ exports.version = '1.29.0';
@@ -32,7 +32,43 @@ export class TurboHTTPService {
32
32
  return this.tryRequest(() => this.axios.get(endpoint, { headers, signal }), allowedStatuses);
33
33
  }
34
34
  async post({ endpoint, signal, allowedStatuses = [200, 202], headers, data, }) {
35
- return this.tryRequest(() => this.axios.post(endpoint, data, { headers, signal }), allowedStatuses);
35
+ // Buffer and Readable keep Axios (streams work fine there)
36
+ if (!(data instanceof ReadableStream)) {
37
+ return this.tryRequest(() => this.axios.post(endpoint, data, { headers, signal }), allowedStatuses);
38
+ }
39
+ // Browser ReadableStream → use fetch with progressive enhancement of duplex
40
+ // Note: fetch does not support streams in Safari and Firefox, so we convert to Blob
41
+ // and use the `duplex` option only in browsers that support it (Chrome, Edge, Opera).
42
+ // See: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API#body
43
+ const { body, duplex } = await toFetchBody(data);
44
+ try {
45
+ const res = await fetch(this.axios.defaults.baseURL + endpoint, {
46
+ method: 'POST',
47
+ headers,
48
+ body,
49
+ signal,
50
+ ...(duplex ? { duplex } : {}), // Use duplex only where streams are working
51
+ });
52
+ if (!allowedStatuses.includes(res.status)) {
53
+ const errorText = await res.text();
54
+ throw new FailedRequestError(
55
+ // Return error message from server if available
56
+ errorText || res.statusText, res.status);
57
+ }
58
+ return res.json();
59
+ }
60
+ catch (error) {
61
+ if (error instanceof FailedRequestError) {
62
+ throw error; // rethrow FailedRequestError
63
+ }
64
+ // Handle CanceledError specifically
65
+ if (error.message.includes('The operation was aborted')) {
66
+ throw new CanceledError();
67
+ }
68
+ // Log the error and throw a FailedRequestError
69
+ this.logger.error('Error posting data', { endpoint, error });
70
+ throw new FailedRequestError(error instanceof Error ? error.message : 'Unknown error', error.response?.status);
71
+ }
36
72
  }
37
73
  async tryRequest(request, allowedStatuses) {
38
74
  try {
@@ -56,3 +92,12 @@ export class TurboHTTPService {
56
92
  }
57
93
  }
58
94
  }
95
+ async function toFetchBody(data) {
96
+ if (!navigator.userAgent.includes('Firefox') &&
97
+ !navigator.userAgent.includes('Safari')) {
98
+ return { body: data, duplex: 'half' }; // Chrome / Edge / Opera
99
+ }
100
+ // Firefox / Safari fallback: stream → Blob
101
+ const blob = await new Response(data).blob();
102
+ return { body: blob }; // browser sets length
103
+ }
@@ -14,4 +14,4 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  // AUTOMATICALLY GENERATED FILE - DO NOT TOUCH
17
- export const version = '1.29.0-alpha.1';
17
+ export const version = '1.29.0';
@@ -1 +1 @@
1
- {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/common/http.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAc,aAAa,EAAgC,MAAM,OAAO,CAAC;AAChF,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,OAAO,EACL,yBAAyB,EACzB,WAAW,EACX,yBAAyB,EAC1B,MAAM,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AAa,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,OAAO,EACL,yBAAyB,EACzB,WAAW,EACX,yBAAyB,EAC1B,MAAM,aAAa,CAAC;AAIrB,qBAAa,gBAAiB,YAAW,yBAAyB;IAChE,SAAS,CAAC,KAAK,EAAE,aAAa,CAAC;IAC/B,SAAS,CAAC,MAAM,EAAE,WAAW,CAAC;gBAElB,EACV,GAAG,EACH,WAAW,EACX,MAAM,GACP,EAAE;QACD,GAAG,EAAE,MAAM,CAAC;QACZ,WAAW,CAAC,EAAE,iBAAiB,CAAC;QAChC,MAAM,EAAE,WAAW,CAAC;KACrB;IAYK,GAAG,CAAC,CAAC,EAAE,EACX,QAAQ,EACR,MAAM,EACN,eAA4B,EAC5B,OAAO,GACR,EAAE;QACD,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,CAAC,EAAE,WAAW,CAAC;QACrB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;QAC3B,OAAO,CAAC,EAAE,OAAO,CAAC,yBAAyB,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KACvE,GAAG,OAAO,CAAC,CAAC,CAAC;IAOR,IAAI,CAAC,CAAC,EAAE,EACZ,QAAQ,EACR,MAAM,EACN,eAA4B,EAC5B,OAAO,EACP,IAAI,GACL,EAAE;QACD,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,CAAC,EAAE,WAAW,CAAC;QACrB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;QAC3B,OAAO,CAAC,EAAE,OAAO,CAAC,yBAAyB,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACtE,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,cAAc,CAAC;KAC1C,GAAG,OAAO,CAAC,CAAC,CAAC;YAmDA,UAAU;CA0BzB"}
@@ -13,5 +13,5 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export declare const version = "1.28.3";
16
+ export declare const version = "1.29.0-alpha.2";
17
17
  //# sourceMappingURL=version.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,eAAO,MAAM,OAAO,WAAW,CAAC"}
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,eAAO,MAAM,OAAO,mBAAmB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ardrive/turbo-sdk",
3
- "version": "1.29.0-alpha.1",
3
+ "version": "1.29.0",
4
4
  "main": "./lib/cjs/node/index.js",
5
5
  "types": "./lib/types/node/index.d.ts",
6
6
  "module": "./lib/esm/node/index.js",