@bytescale/sdk 3.45.0 → 3.47.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.
@@ -520,7 +520,11 @@ var BaseAPI = /*#__PURE__*/function () {
520
520
  //
521
521
  // However, this is probably a good idea, even for all GET requests, as if the user is refreshing a JWT
522
522
  // or downloading a file via 'FileApi.downloadFile', then they'll likely want the latest.
523
- cache: "no-store"
523
+ cache: "no-store",
524
+ // Node does not support full duplex, so default fetch implementations will fail with "RequestInit: duplex option is required when sending a body"
525
+ // unless the following is set.
526
+ // https://github.com/nodejs/node/issues/46221#issuecomment-1383246036
527
+ duplex: "half"
524
528
  })), function (_BytescaleApiClientCo) {
525
529
  response = _BytescaleApiClientCo;
526
530
  });
@@ -505,7 +505,11 @@ var BaseAPI = /*#__PURE__*/function () {
505
505
  //
506
506
  // However, this is probably a good idea, even for all GET requests, as if the user is refreshing a JWT
507
507
  // or downloading a file via 'FileApi.downloadFile', then they'll likely want the latest.
508
- cache: "no-store"
508
+ cache: "no-store",
509
+ // Node does not support full duplex, so default fetch implementations will fail with "RequestInit: duplex option is required when sending a body"
510
+ // unless the following is set.
511
+ // https://github.com/nodejs/node/issues/46221#issuecomment-1383246036
512
+ duplex: "half"
509
513
  })), function (_BytescaleApiClientCo) {
510
514
  response = _BytescaleApiClientCo;
511
515
  });
@@ -520,7 +520,11 @@ var BaseAPI = /*#__PURE__*/function () {
520
520
  //
521
521
  // However, this is probably a good idea, even for all GET requests, as if the user is refreshing a JWT
522
522
  // or downloading a file via 'FileApi.downloadFile', then they'll likely want the latest.
523
- cache: "no-store"
523
+ cache: "no-store",
524
+ // Node does not support full duplex, so default fetch implementations will fail with "RequestInit: duplex option is required when sending a body"
525
+ // unless the following is set.
526
+ // https://github.com/nodejs/node/issues/46221#issuecomment-1383246036
527
+ duplex: "half"
524
528
  })), function (_BytescaleApiClientCo) {
525
529
  response = _BytescaleApiClientCo;
526
530
  });
@@ -2390,34 +2394,32 @@ var StreamUtils = /*#__PURE__*/function () {
2390
2394
  return StreamUtils_createClass(StreamUtils, null, [{
2391
2395
  key: "create",
2392
2396
  value: function create() {
2393
- var readable = new external_stream_namespaceObject.Readable();
2394
- readable._read = function () {}; // _read is required but you can noop it
2395
- return readable;
2397
+ return new external_stream_namespaceObject.Readable({
2398
+ read: function read(_size) {
2399
+ // No implementation needed here.
2400
+ // The stream will wait for data to be pushed externally.
2401
+ }
2402
+ });
2396
2403
  }
2397
2404
  }, {
2398
- key: "empty",
2399
- value: function empty() {
2400
- var readable = StreamUtils.create();
2401
- StreamUtils.endStream(readable);
2402
- return readable;
2405
+ key: "endStream",
2406
+ value: function endStream(readable) {
2407
+ readable.push(null);
2403
2408
  }
2404
2409
  }, {
2405
- key: "fromArrayBuffer",
2406
- value: function fromArrayBuffer(buffer) {
2407
- return StreamUtils.fromBuffer(Buffer.from(buffer));
2410
+ key: "empty",
2411
+ value: function empty() {
2412
+ return external_stream_namespaceObject.Readable.from([]);
2408
2413
  }
2409
2414
  }, {
2410
2415
  key: "fromBuffer",
2411
2416
  value: function fromBuffer(buffer) {
2412
- var readable = StreamUtils.create();
2413
- readable.push(buffer);
2414
- StreamUtils.endStream(readable);
2415
- return readable;
2417
+ return external_stream_namespaceObject.Readable.from(buffer);
2416
2418
  }
2417
2419
  }, {
2418
- key: "endStream",
2419
- value: function endStream(readable) {
2420
- readable.push(null);
2420
+ key: "fromArrayBuffer",
2421
+ value: function fromArrayBuffer(buffer) {
2422
+ return StreamUtils.fromBuffer(Buffer.from(buffer));
2421
2423
  }
2422
2424
  }]);
2423
2425
  }();
@@ -2652,6 +2654,7 @@ var UploadManagerFetchUtils = /*#__PURE__*/function () {
2652
2654
  headers: headers,
2653
2655
  body: content,
2654
2656
  signal: signal,
2657
+ duplex: "half",
2655
2658
  cache: "no-store" // Required for Next.js's Fetch implementation, which caches POST/PUT requests by default.
2656
2659
  }), function (response) {
2657
2660
  return {
@@ -2665,6 +2668,45 @@ var UploadManagerFetchUtils = /*#__PURE__*/function () {
2665
2668
  }
2666
2669
  }]);
2667
2670
  }();
2671
+ ;// CONCATENATED MODULE: ./src/public/node/ProgressStream.ts
2672
+ function ProgressStream_typeof(o) { "@babel/helpers - typeof"; return ProgressStream_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, ProgressStream_typeof(o); }
2673
+ function ProgressStream_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2674
+ function ProgressStream_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, ProgressStream_toPropertyKey(descriptor.key), descriptor); } }
2675
+ function ProgressStream_createClass(Constructor, protoProps, staticProps) { if (protoProps) ProgressStream_defineProperties(Constructor.prototype, protoProps); if (staticProps) ProgressStream_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
2676
+ function ProgressStream_toPropertyKey(t) { var i = ProgressStream_toPrimitive(t, "string"); return "symbol" == ProgressStream_typeof(i) ? i : i + ""; }
2677
+ function ProgressStream_toPrimitive(t, r) { if ("object" != ProgressStream_typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != ProgressStream_typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
2678
+ function ProgressStream_callSuper(t, o, e) { return o = ProgressStream_getPrototypeOf(o), ProgressStream_possibleConstructorReturn(t, ProgressStream_isNativeReflectConstruct() ? Reflect.construct(o, e || [], ProgressStream_getPrototypeOf(t).constructor) : o.apply(t, e)); }
2679
+ function ProgressStream_possibleConstructorReturn(self, call) { if (call && (ProgressStream_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return ProgressStream_assertThisInitialized(self); }
2680
+ function ProgressStream_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
2681
+ function ProgressStream_isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (ProgressStream_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
2682
+ function ProgressStream_getPrototypeOf(o) { ProgressStream_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return ProgressStream_getPrototypeOf(o); }
2683
+ function ProgressStream_inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) ProgressStream_setPrototypeOf(subClass, superClass); }
2684
+ function ProgressStream_setPrototypeOf(o, p) { ProgressStream_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return ProgressStream_setPrototypeOf(o, p); }
2685
+
2686
+ var ProgressStream = /*#__PURE__*/function (_Transform) {
2687
+ function ProgressStream(options) {
2688
+ var _this;
2689
+ ProgressStream_classCallCheck(this, ProgressStream);
2690
+ _this = ProgressStream_callSuper(this, ProgressStream, [options]);
2691
+ _this.totalBytes = 0;
2692
+ _this.onProgress = options === null || options === void 0 ? void 0 : options.onProgress;
2693
+ return _this;
2694
+ }
2695
+ ProgressStream_inherits(ProgressStream, _Transform);
2696
+ return ProgressStream_createClass(ProgressStream, [{
2697
+ key: "_transform",
2698
+ value: function _transform(chunk, _encoding, callback) {
2699
+ this.totalBytes += chunk.length;
2700
+ // Invoke the progress callback if provided
2701
+ if (this.onProgress !== undefined) {
2702
+ this.onProgress(this.totalBytes);
2703
+ }
2704
+ // Pass the chunk along
2705
+ this.push(chunk);
2706
+ callback();
2707
+ }
2708
+ }]);
2709
+ }(external_stream_namespaceObject.Transform);
2668
2710
  ;// CONCATENATED MODULE: ./src/public/node/UploadManagerNode.ts
2669
2711
  function UploadManagerNode_typeof(o) { "@babel/helpers - typeof"; return UploadManagerNode_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, UploadManagerNode_typeof(o); }
2670
2712
  function UploadManagerNode_empty() {}
@@ -2865,6 +2907,7 @@ function UploadManagerNode_setPrototypeOf(o, p) { UploadManagerNode_setPrototype
2865
2907
 
2866
2908
 
2867
2909
 
2910
+
2868
2911
  var UploadManager = /*#__PURE__*/function (_UploadManagerBase) {
2869
2912
  function UploadManager() {
2870
2913
  UploadManagerNode_classCallCheck(this, UploadManager);
@@ -2969,20 +3012,12 @@ var UploadManager = /*#__PURE__*/function (_UploadManagerBase) {
2969
3012
  value: function doPutUploadPart(part, contentLength, source, onProgress, addCancellationHandler) {
2970
3013
  try {
2971
3014
  var _this = this;
2972
- // Report progress:
2973
- var hasWarned = false;
2974
- var bytesSent = 0;
2975
- return UploadManagerNode_await(_this.sliceDataForRequest(source, part), function (stream) {
2976
- var streamWithProgress = stream.on("data", function (data) {
2977
- if (data.byteLength !== undefined) {
2978
- bytesSent += data.byteLength;
2979
- onProgress(bytesSent);
2980
- } else if (!hasWarned) {
2981
- hasWarned = true;
2982
- console.warn("Expected stream to contain buffers, but it did not, so upload progress won't be reported.");
2983
- }
3015
+ return UploadManagerNode_await(_this.sliceDataForRequest(source, part), function (inputStream) {
3016
+ var progressStream = new ProgressStream({
3017
+ onProgress: onProgress
2984
3018
  });
2985
- return UploadManagerNode_await(UploadManagerFetchUtils.doPutUploadPart(_this.config, part, _this.coerceRequestBody(streamWithProgress), contentLength, addCancellationHandler));
3019
+ inputStream.pipe(progressStream);
3020
+ return UploadManagerNode_await(UploadManagerFetchUtils.doPutUploadPart(_this.config, part, _this.coerceRequestBody(progressStream), contentLength, addCancellationHandler));
2986
3021
  });
2987
3022
  } catch (e) {
2988
3023
  return Promise.reject(e);
@@ -507,7 +507,11 @@ var BaseAPI = /*#__PURE__*/function () {
507
507
  //
508
508
  // However, this is probably a good idea, even for all GET requests, as if the user is refreshing a JWT
509
509
  // or downloading a file via 'FileApi.downloadFile', then they'll likely want the latest.
510
- cache: "no-store"
510
+ cache: "no-store",
511
+ // Node does not support full duplex, so default fetch implementations will fail with "RequestInit: duplex option is required when sending a body"
512
+ // unless the following is set.
513
+ // https://github.com/nodejs/node/issues/46221#issuecomment-1383246036
514
+ duplex: "half"
511
515
  })), function (_BytescaleApiClientCo) {
512
516
  response = _BytescaleApiClientCo;
513
517
  });
@@ -2365,7 +2369,7 @@ var x = function(y) {
2365
2369
  var x = {}; __lib_require__.d(x, y); return x
2366
2370
  }
2367
2371
  var y = function(x) { return function() { return x; }; }
2368
- var external_stream_namespaceObject = x({ ["Readable"]: function() { return __WEBPACK_EXTERNAL_MODULE_stream__.Readable; } });
2372
+ var external_stream_namespaceObject = x({ ["Readable"]: function() { return __WEBPACK_EXTERNAL_MODULE_stream__.Readable; }, ["Transform"]: function() { return __WEBPACK_EXTERNAL_MODULE_stream__.Transform; } });
2369
2373
  ;// CONCATENATED MODULE: ./src/private/StreamUtils.ts
2370
2374
  function StreamUtils_typeof(o) { "@babel/helpers - typeof"; return StreamUtils_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, StreamUtils_typeof(o); }
2371
2375
  function StreamUtils_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
@@ -2381,34 +2385,32 @@ var StreamUtils = /*#__PURE__*/function () {
2381
2385
  return StreamUtils_createClass(StreamUtils, null, [{
2382
2386
  key: "create",
2383
2387
  value: function create() {
2384
- var readable = new external_stream_namespaceObject.Readable();
2385
- readable._read = function () {}; // _read is required but you can noop it
2386
- return readable;
2388
+ return new external_stream_namespaceObject.Readable({
2389
+ read: function read(_size) {
2390
+ // No implementation needed here.
2391
+ // The stream will wait for data to be pushed externally.
2392
+ }
2393
+ });
2387
2394
  }
2388
2395
  }, {
2389
- key: "empty",
2390
- value: function empty() {
2391
- var readable = StreamUtils.create();
2392
- StreamUtils.endStream(readable);
2393
- return readable;
2396
+ key: "endStream",
2397
+ value: function endStream(readable) {
2398
+ readable.push(null);
2394
2399
  }
2395
2400
  }, {
2396
- key: "fromArrayBuffer",
2397
- value: function fromArrayBuffer(buffer) {
2398
- return StreamUtils.fromBuffer(Buffer.from(buffer));
2401
+ key: "empty",
2402
+ value: function empty() {
2403
+ return external_stream_namespaceObject.Readable.from([]);
2399
2404
  }
2400
2405
  }, {
2401
2406
  key: "fromBuffer",
2402
2407
  value: function fromBuffer(buffer) {
2403
- var readable = StreamUtils.create();
2404
- readable.push(buffer);
2405
- StreamUtils.endStream(readable);
2406
- return readable;
2408
+ return external_stream_namespaceObject.Readable.from(buffer);
2407
2409
  }
2408
2410
  }, {
2409
- key: "endStream",
2410
- value: function endStream(readable) {
2411
- readable.push(null);
2411
+ key: "fromArrayBuffer",
2412
+ value: function fromArrayBuffer(buffer) {
2413
+ return StreamUtils.fromBuffer(Buffer.from(buffer));
2412
2414
  }
2413
2415
  }]);
2414
2416
  }();
@@ -2647,6 +2649,7 @@ var UploadManagerFetchUtils = /*#__PURE__*/function () {
2647
2649
  headers: headers,
2648
2650
  body: content,
2649
2651
  signal: signal,
2652
+ duplex: "half",
2650
2653
  cache: "no-store" // Required for Next.js's Fetch implementation, which caches POST/PUT requests by default.
2651
2654
  }), function (response) {
2652
2655
  return {
@@ -2660,6 +2663,45 @@ var UploadManagerFetchUtils = /*#__PURE__*/function () {
2660
2663
  }
2661
2664
  }]);
2662
2665
  }();
2666
+ ;// CONCATENATED MODULE: ./src/public/node/ProgressStream.ts
2667
+ function ProgressStream_typeof(o) { "@babel/helpers - typeof"; return ProgressStream_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, ProgressStream_typeof(o); }
2668
+ function ProgressStream_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2669
+ function ProgressStream_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, ProgressStream_toPropertyKey(descriptor.key), descriptor); } }
2670
+ function ProgressStream_createClass(Constructor, protoProps, staticProps) { if (protoProps) ProgressStream_defineProperties(Constructor.prototype, protoProps); if (staticProps) ProgressStream_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
2671
+ function ProgressStream_toPropertyKey(t) { var i = ProgressStream_toPrimitive(t, "string"); return "symbol" == ProgressStream_typeof(i) ? i : i + ""; }
2672
+ function ProgressStream_toPrimitive(t, r) { if ("object" != ProgressStream_typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != ProgressStream_typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
2673
+ function ProgressStream_callSuper(t, o, e) { return o = ProgressStream_getPrototypeOf(o), ProgressStream_possibleConstructorReturn(t, ProgressStream_isNativeReflectConstruct() ? Reflect.construct(o, e || [], ProgressStream_getPrototypeOf(t).constructor) : o.apply(t, e)); }
2674
+ function ProgressStream_possibleConstructorReturn(self, call) { if (call && (ProgressStream_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return ProgressStream_assertThisInitialized(self); }
2675
+ function ProgressStream_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
2676
+ function ProgressStream_isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (ProgressStream_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
2677
+ function ProgressStream_getPrototypeOf(o) { ProgressStream_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return ProgressStream_getPrototypeOf(o); }
2678
+ function ProgressStream_inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) ProgressStream_setPrototypeOf(subClass, superClass); }
2679
+ function ProgressStream_setPrototypeOf(o, p) { ProgressStream_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return ProgressStream_setPrototypeOf(o, p); }
2680
+
2681
+ var ProgressStream = /*#__PURE__*/function (_Transform) {
2682
+ function ProgressStream(options) {
2683
+ var _this;
2684
+ ProgressStream_classCallCheck(this, ProgressStream);
2685
+ _this = ProgressStream_callSuper(this, ProgressStream, [options]);
2686
+ _this.totalBytes = 0;
2687
+ _this.onProgress = options === null || options === void 0 ? void 0 : options.onProgress;
2688
+ return _this;
2689
+ }
2690
+ ProgressStream_inherits(ProgressStream, _Transform);
2691
+ return ProgressStream_createClass(ProgressStream, [{
2692
+ key: "_transform",
2693
+ value: function _transform(chunk, _encoding, callback) {
2694
+ this.totalBytes += chunk.length;
2695
+ // Invoke the progress callback if provided
2696
+ if (this.onProgress !== undefined) {
2697
+ this.onProgress(this.totalBytes);
2698
+ }
2699
+ // Pass the chunk along
2700
+ this.push(chunk);
2701
+ callback();
2702
+ }
2703
+ }]);
2704
+ }(external_stream_namespaceObject.Transform);
2663
2705
  ;// CONCATENATED MODULE: ./src/public/node/UploadManagerNode.ts
2664
2706
  function UploadManagerNode_typeof(o) { "@babel/helpers - typeof"; return UploadManagerNode_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, UploadManagerNode_typeof(o); }
2665
2707
  function UploadManagerNode_empty() {}
@@ -2860,6 +2902,7 @@ function UploadManagerNode_setPrototypeOf(o, p) { UploadManagerNode_setPrototype
2860
2902
 
2861
2903
 
2862
2904
 
2905
+
2863
2906
  var UploadManager = /*#__PURE__*/function (_UploadManagerBase) {
2864
2907
  function UploadManager() {
2865
2908
  UploadManagerNode_classCallCheck(this, UploadManager);
@@ -2964,20 +3007,12 @@ var UploadManager = /*#__PURE__*/function (_UploadManagerBase) {
2964
3007
  value: function doPutUploadPart(part, contentLength, source, onProgress, addCancellationHandler) {
2965
3008
  try {
2966
3009
  var _this = this;
2967
- // Report progress:
2968
- var hasWarned = false;
2969
- var bytesSent = 0;
2970
- return UploadManagerNode_await(_this.sliceDataForRequest(source, part), function (stream) {
2971
- var streamWithProgress = stream.on("data", function (data) {
2972
- if (data.byteLength !== undefined) {
2973
- bytesSent += data.byteLength;
2974
- onProgress(bytesSent);
2975
- } else if (!hasWarned) {
2976
- hasWarned = true;
2977
- console.warn("Expected stream to contain buffers, but it did not, so upload progress won't be reported.");
2978
- }
3010
+ return UploadManagerNode_await(_this.sliceDataForRequest(source, part), function (inputStream) {
3011
+ var progressStream = new ProgressStream({
3012
+ onProgress: onProgress
2979
3013
  });
2980
- return UploadManagerNode_await(UploadManagerFetchUtils.doPutUploadPart(_this.config, part, _this.coerceRequestBody(streamWithProgress), contentLength, addCancellationHandler));
3014
+ inputStream.pipe(progressStream);
3015
+ return UploadManagerNode_await(UploadManagerFetchUtils.doPutUploadPart(_this.config, part, _this.coerceRequestBody(progressStream), contentLength, addCancellationHandler));
2981
3016
  });
2982
3017
  } catch (e) {
2983
3018
  return Promise.reject(e);
@@ -4,8 +4,8 @@
4
4
  import type * as stream from "stream";
5
5
  export declare class StreamUtils {
6
6
  static create(): stream.Readable;
7
+ static endStream(readable: stream.Readable): void;
7
8
  static empty(): NodeJS.ReadableStream;
8
- static fromArrayBuffer(buffer: ArrayBuffer): NodeJS.ReadableStream;
9
9
  static fromBuffer(buffer: Buffer): NodeJS.ReadableStream;
10
- static endStream(readable: stream.Readable): void;
10
+ static fromArrayBuffer(buffer: ArrayBuffer): NodeJS.ReadableStream;
11
11
  }
@@ -26,7 +26,7 @@ export declare abstract class UploadManagerBase<TSource, TInit> implements Uploa
26
26
  };
27
27
  protected abstract preUpload(source: TSource): TInit;
28
28
  protected abstract postUpload(init: TInit): Promise<void>;
29
- protected abstract doPutUploadPart(part: UploadPart, contentLength: number, source: TSource, onProgress: (bytesSentDelta: number) => void, addCancellationHandler: AddCancellationHandler): Promise<PutUploadPartResult>;
29
+ protected abstract doPutUploadPart(part: UploadPart, contentLength: number, source: TSource, onProgress: (totalBytesTransferred: number) => void, addCancellationHandler: AddCancellationHandler): Promise<PutUploadPartResult>;
30
30
  private onIntervalTick;
31
31
  private makeCancellationMethods;
32
32
  /**
@@ -0,0 +1,17 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import { Transform, TransformCallback, TransformOptions } from "stream";
4
+ interface ProgressStreamOptions extends TransformOptions {
5
+ /**
6
+ * Optional callback to handle progress updates.
7
+ * @param totalBytesTransferred - The total number of bytes transferred so far.
8
+ */
9
+ onProgress?: (totalBytesTransferred: number) => void;
10
+ }
11
+ export declare class ProgressStream extends Transform {
12
+ private readonly onProgress;
13
+ private totalBytes;
14
+ constructor(options?: ProgressStreamOptions);
15
+ _transform(chunk: Buffer, _encoding: BufferEncoding, callback: TransformCallback): void;
16
+ }
17
+ export {};
@@ -16,7 +16,7 @@ export declare class UploadManager extends UploadManagerBase<UploadSourceProcess
16
16
  };
17
17
  protected preUpload(source: UploadSourceProcessedNode): UploadManagerNodeInit;
18
18
  protected postUpload(init: UploadManagerNodeInit): Promise<void>;
19
- protected doPutUploadPart(part: UploadPart, contentLength: number, source: UploadSourceProcessedNode, onProgress: (bytesSentDelta: number) => void, addCancellationHandler: AddCancellationHandler): Promise<{
19
+ protected doPutUploadPart(part: UploadPart, contentLength: number, source: UploadSourceProcessedNode, onProgress: (totalBytesTransferred: number) => void, addCancellationHandler: AddCancellationHandler): Promise<{
20
20
  etag: string | undefined;
21
21
  status: number;
22
22
  }>;
@@ -93,7 +93,9 @@ export declare class BytescaleApiError extends Error {
93
93
  readonly details: any | undefined;
94
94
  constructor(response: ErrorResponse);
95
95
  }
96
- export type FetchAPI = WindowOrWorkerGlobalScope["fetch"];
96
+ export type FetchAPI = (input: RequestInfo | URL, init?: RequestInit & {
97
+ duplex: "half";
98
+ }) => Promise<Response>;
97
99
  export type Json = any;
98
100
  export type HTTPMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS" | "HEAD";
99
101
  export type HTTPHeaders = {
@@ -520,7 +520,11 @@ var BaseAPI = /*#__PURE__*/function () {
520
520
  //
521
521
  // However, this is probably a good idea, even for all GET requests, as if the user is refreshing a JWT
522
522
  // or downloading a file via 'FileApi.downloadFile', then they'll likely want the latest.
523
- cache: "no-store"
523
+ cache: "no-store",
524
+ // Node does not support full duplex, so default fetch implementations will fail with "RequestInit: duplex option is required when sending a body"
525
+ // unless the following is set.
526
+ // https://github.com/nodejs/node/issues/46221#issuecomment-1383246036
527
+ duplex: "half"
524
528
  })), function (_BytescaleApiClientCo) {
525
529
  response = _BytescaleApiClientCo;
526
530
  });
@@ -2509,6 +2513,7 @@ var UploadManagerFetchUtils = /*#__PURE__*/function () {
2509
2513
  headers: headers,
2510
2514
  body: content,
2511
2515
  signal: signal,
2516
+ duplex: "half",
2512
2517
  cache: "no-store" // Required for Next.js's Fetch implementation, which caches POST/PUT requests by default.
2513
2518
  }), function (response) {
2514
2519
  return {
@@ -505,7 +505,11 @@ var BaseAPI = /*#__PURE__*/function () {
505
505
  //
506
506
  // However, this is probably a good idea, even for all GET requests, as if the user is refreshing a JWT
507
507
  // or downloading a file via 'FileApi.downloadFile', then they'll likely want the latest.
508
- cache: "no-store"
508
+ cache: "no-store",
509
+ // Node does not support full duplex, so default fetch implementations will fail with "RequestInit: duplex option is required when sending a body"
510
+ // unless the following is set.
511
+ // https://github.com/nodejs/node/issues/46221#issuecomment-1383246036
512
+ duplex: "half"
509
513
  })), function (_BytescaleApiClientCo) {
510
514
  response = _BytescaleApiClientCo;
511
515
  });
@@ -2494,6 +2498,7 @@ var UploadManagerFetchUtils = /*#__PURE__*/function () {
2494
2498
  headers: headers,
2495
2499
  body: content,
2496
2500
  signal: signal,
2501
+ duplex: "half",
2497
2502
  cache: "no-store" // Required for Next.js's Fetch implementation, which caches POST/PUT requests by default.
2498
2503
  }), function (response) {
2499
2504
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bytescale/sdk",
3
- "version": "3.45.0",
3
+ "version": "3.47.0",
4
4
  "description": "Bytescale JavaScript SDK",
5
5
  "author": "Bytescale <hello@bytescale.com> (https://www.bytescale.com)",
6
6
  "license": "MIT",
@@ -110,7 +110,7 @@
110
110
  "ts-loader": "9.5.1",
111
111
  "tsc-alias": "1.2.10",
112
112
  "typescript": "4.9.5",
113
- "webpack": "5.90.3",
113
+ "webpack": "5.94.0",
114
114
  "webpack-cli": "4.10.0",
115
115
  "webpack-node-externals": "2.5.2",
116
116
  "webpack-shell-plugin-next": "2.3.1"