@bytescale/sdk 3.0.0-alpha.12 → 3.0.0-alpha.13

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.
@@ -1,25 +1,3 @@
1
- // ----------------------------------------
2
- // POLYFILL GUIDE:
3
- // ----------------------------------------
4
- //
5
- // "buffer" & "stream" are not required for browser environments.
6
- //
7
- // They are only used when the code detects it's running in Node.js (at runtime).
8
- //
9
- // You may polyfill them with empty objects (for browser environments):
10
- //
11
- // ----------------------------------------
12
- // Webpack:
13
- // {
14
- // resolve: {
15
- // fallback: {
16
- // buffer: false,
17
- // stream: false
18
- // }
19
- // }
20
- // }
21
- // ----------------------------------------
22
- //
23
1
  /******/ (function() { // webpackBootstrap
24
2
  /******/ "use strict";
25
3
  /******/ // The require scope
@@ -2318,6 +2296,11 @@ var StreamUtils = /*#__PURE__*/function () {
2318
2296
  StreamUtils.endStream(readable);
2319
2297
  return readable;
2320
2298
  }
2299
+ }, {
2300
+ key: "fromArrayBuffer",
2301
+ value: function fromArrayBuffer(buffer) {
2302
+ return StreamUtils.fromBuffer(Buffer.from(buffer));
2303
+ }
2321
2304
  }, {
2322
2305
  key: "fromBuffer",
2323
2306
  value: function fromBuffer(buffer) {
@@ -2526,6 +2509,61 @@ var NodeChunkedStream = /*#__PURE__*/function () {
2526
2509
  }();
2527
2510
  ;// CONCATENATED MODULE: external "buffer"
2528
2511
  var external_buffer_namespaceObject = require("buffer");
2512
+ ;// CONCATENATED MODULE: ./src/private/UploadManagerFetchUtils.ts
2513
+ function UploadManagerFetchUtils_typeof(obj) { "@babel/helpers - typeof"; return UploadManagerFetchUtils_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, UploadManagerFetchUtils_typeof(obj); }
2514
+ function UploadManagerFetchUtils_await(value, then, direct) {
2515
+ if (direct) {
2516
+ return then ? then(value) : value;
2517
+ }
2518
+ if (!value || !value.then) {
2519
+ value = Promise.resolve(value);
2520
+ }
2521
+ return then ? value.then(then) : value;
2522
+ }
2523
+ function UploadManagerFetchUtils_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2524
+ function UploadManagerFetchUtils_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, UploadManagerFetchUtils_toPropertyKey(descriptor.key), descriptor); } }
2525
+ function UploadManagerFetchUtils_createClass(Constructor, protoProps, staticProps) { if (protoProps) UploadManagerFetchUtils_defineProperties(Constructor.prototype, protoProps); if (staticProps) UploadManagerFetchUtils_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
2526
+ function UploadManagerFetchUtils_toPropertyKey(arg) { var key = UploadManagerFetchUtils_toPrimitive(arg, "string"); return UploadManagerFetchUtils_typeof(key) === "symbol" ? key : String(key); }
2527
+ function UploadManagerFetchUtils_toPrimitive(input, hint) { if (UploadManagerFetchUtils_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (UploadManagerFetchUtils_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
2528
+
2529
+ var UploadManagerFetchUtils = /*#__PURE__*/function () {
2530
+ function UploadManagerFetchUtils() {
2531
+ UploadManagerFetchUtils_classCallCheck(this, UploadManagerFetchUtils);
2532
+ }
2533
+ UploadManagerFetchUtils_createClass(UploadManagerFetchUtils, null, [{
2534
+ key: "doPutUploadPart",
2535
+ value: function doPutUploadPart(config, part, content, contentLength, addCancellationHandler) {
2536
+ try {
2537
+ var _a;
2538
+ var fetchApi = BytescaleApiClientConfigUtils.getFetchApi(config);
2539
+ // Configure cancellation:
2540
+ var controller = new AbortController();
2541
+ var signal = controller.signal;
2542
+ addCancellationHandler(function () {
2543
+ return controller.abort();
2544
+ });
2545
+ var headers = {
2546
+ // Required to prevent fetch using "Transfer-Encoding: Chunked" when body is a stream.
2547
+ "content-length": contentLength.toString()
2548
+ };
2549
+ return UploadManagerFetchUtils_await(fetchApi(part.uploadUrl, {
2550
+ method: "PUT",
2551
+ headers: headers,
2552
+ body: content,
2553
+ signal: signal
2554
+ }), function (response) {
2555
+ return {
2556
+ etag: (_a = response.headers.get("etag")) !== null && _a !== void 0 ? _a : undefined,
2557
+ status: response.status
2558
+ };
2559
+ });
2560
+ } catch (e) {
2561
+ return Promise.reject(e);
2562
+ }
2563
+ }
2564
+ }]);
2565
+ return UploadManagerFetchUtils;
2566
+ }();
2529
2567
  ;// CONCATENATED MODULE: ./src/public/node/UploadManagerNode.ts
2530
2568
  function UploadManagerNode_typeof(obj) { "@babel/helpers - typeof"; return UploadManagerNode_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, UploadManagerNode_typeof(obj); }
2531
2569
  function UploadManagerNode_empty() {}
@@ -2725,6 +2763,7 @@ function UploadManagerNode_getPrototypeOf(o) { UploadManagerNode_getPrototypeOf
2725
2763
 
2726
2764
 
2727
2765
 
2766
+
2728
2767
  var UploadManager = /*#__PURE__*/function (_UploadManagerBase) {
2729
2768
  UploadManagerNode_inherits(UploadManager, _UploadManagerBase);
2730
2769
  var _super = UploadManagerNode_createSuper(UploadManager);
@@ -2756,13 +2795,19 @@ var UploadManager = /*#__PURE__*/function (_UploadManagerBase) {
2756
2795
  value: data
2757
2796
  };
2758
2797
  }
2798
+ if (data.byteLength !== undefined) {
2799
+ return {
2800
+ type: "ArrayBuffer",
2801
+ value: data
2802
+ };
2803
+ }
2759
2804
  if (data.size !== undefined) {
2760
2805
  return {
2761
2806
  type: "Blob",
2762
2807
  value: data
2763
2808
  };
2764
2809
  }
2765
- throw new Error("Unsupported type for 'data' parameter. Please provide a String, Blob, or Readable (Node.js).");
2810
+ throw new Error("Unsupported type for 'data' parameter. Please provide a String, Blob, Buffer, ArrayBuffer, or ReadableStream (Node.js).");
2766
2811
  }
2767
2812
  }, {
2768
2813
  key: "getPreUploadInfoPartial",
@@ -2771,9 +2816,10 @@ var UploadManager = /*#__PURE__*/function (_UploadManagerBase) {
2771
2816
  case "Blob":
2772
2817
  return this.getBlobInfo(data);
2773
2818
  case "Buffer":
2819
+ case "ArrayBuffer":
2774
2820
  return {
2775
2821
  mime: undefined,
2776
- size: data.value.length,
2822
+ size: data.value.byteLength,
2777
2823
  originalFileName: undefined,
2778
2824
  maxConcurrentUploadParts: undefined
2779
2825
  };
@@ -2824,18 +2870,6 @@ var UploadManager = /*#__PURE__*/function (_UploadManagerBase) {
2824
2870
  value: function doPutUploadPart(part, contentLength, source, onProgress, addCancellationHandler) {
2825
2871
  try {
2826
2872
  var _this2 = this;
2827
- var _a, _b;
2828
- var fetchApi = (_a = _this2.config.fetchApi) !== null && _a !== void 0 ? _a : fetch;
2829
- var headers = {
2830
- // Required to prevent fetch using "Transfer-Encoding: Chunked" when body is a stream.
2831
- "content-length": contentLength.toString()
2832
- };
2833
- // Configure cancellation:
2834
- var controller = new AbortController();
2835
- var signal = controller.signal;
2836
- addCancellationHandler(function () {
2837
- return controller.abort();
2838
- });
2839
2873
  // Report progress:
2840
2874
  var hasWarned = false;
2841
2875
  return UploadManagerNode_await(_this2.sliceDataForRequest(source, part), function (stream) {
@@ -2847,17 +2881,7 @@ var UploadManager = /*#__PURE__*/function (_UploadManagerBase) {
2847
2881
  console.warn("Expected stream to contain buffers, but it did not, so upload progress won't be reported.");
2848
2882
  }
2849
2883
  });
2850
- return UploadManagerNode_await(fetchApi(part.uploadUrl, {
2851
- method: "PUT",
2852
- headers: headers,
2853
- body: _this2.coerceRequestBody(streamWithProgress),
2854
- signal: signal
2855
- }), function (response) {
2856
- return {
2857
- etag: (_b = response.headers.get("etag")) !== null && _b !== void 0 ? _b : undefined,
2858
- status: response.status
2859
- };
2860
- });
2884
+ return UploadManagerNode_await(UploadManagerFetchUtils.doPutUploadPart(_this2.config, part, _this2.coerceRequestBody(streamWithProgress), contentLength, addCancellationHandler));
2861
2885
  });
2862
2886
  } catch (e) {
2863
2887
  return Promise.reject(e);
@@ -2881,12 +2905,14 @@ var UploadManager = /*#__PURE__*/function (_UploadManagerBase) {
2881
2905
  return _switch(data.type, [[function () {
2882
2906
  return "Blob";
2883
2907
  }, function () {
2884
- var _fromBuffer = StreamUtils.fromBuffer,
2885
- _Buffer = Buffer,
2886
- _from = _Buffer.from;
2908
+ var _fromArrayBuffer = StreamUtils.fromArrayBuffer;
2887
2909
  return UploadManagerNode_await(data.value.slice(start, endExclusive).arrayBuffer(), function (_data$value$slice$arr) {
2888
- return _fromBuffer.call(StreamUtils, _from.call(_Buffer, _data$value$slice$arr));
2910
+ return _fromArrayBuffer.call(StreamUtils, _data$value$slice$arr);
2889
2911
  });
2912
+ }], [function () {
2913
+ return "ArrayBuffer";
2914
+ }, function () {
2915
+ return StreamUtils.fromArrayBuffer(data.value.slice(start, endExclusive));
2890
2916
  }], [function () {
2891
2917
  return "Buffer";
2892
2918
  }, function () {
@@ -2917,17 +2943,17 @@ var EnvChecker = /*#__PURE__*/function () {
2917
2943
  EnvChecker_classCallCheck(this, EnvChecker);
2918
2944
  }
2919
2945
  EnvChecker_createClass(EnvChecker, null, [{
2920
- key: "isNodeJs",
2921
- value: function isNodeJs() {
2922
- return typeof process !== "undefined" && process.versions !== undefined && process.versions.node !== undefined;
2946
+ key: "isBrowser",
2947
+ value: function isBrowser() {
2948
+ return typeof window !== "undefined";
2923
2949
  }
2924
2950
  }, {
2925
2951
  key: "methodRequiresBrowser",
2926
2952
  value: function methodRequiresBrowser(methodName) {
2927
- if (EnvChecker.isNodeJs()) {
2928
- return new Error("You must call '".concat(methodName, "' in the browser. (You are currently in Node.js.)"));
2953
+ if (!EnvChecker.isBrowser()) {
2954
+ return new Error("You must call '".concat(methodName, "' in your client-side code. (You have called it in your server-side code.)"));
2929
2955
  }
2930
- return new Error("The '".concat(methodName, "' method cannot be called because you have bundled the Node.js implementation of the Bytescale JavaScript SDK into your client-side code. Please ensure your bundling tool (Webpack, Rollup, etc.) is honouring the \"browser\" field of the \"package.json\" file for this package, as this will allow the browser implementation of the Bytescale JavaScript SDK to be included in your client-side code."));
2956
+ return new Error("The '".concat(methodName, "' method cannot be called because you have bundled a non-browser implementation of the Bytescale JavaScript SDK into your client-side code. Please ensure your bundling tool (Webpack, Rollup, etc.) is honouring the \"browser\" field of the \"package.json\" file for this package, as this will allow the browser implementation of the Bytescale JavaScript SDK to be included in your client-side code."));
2931
2957
  }
2932
2958
  }]);
2933
2959
  return EnvChecker;
@@ -1,25 +1,3 @@
1
- // ----------------------------------------
2
- // POLYFILL GUIDE:
3
- // ----------------------------------------
4
- //
5
- // "buffer" & "stream" are not required for browser environments.
6
- //
7
- // They are only used when the code detects it's running in Node.js (at runtime).
8
- //
9
- // You may polyfill them with empty objects (for browser environments):
10
- //
11
- // ----------------------------------------
12
- // Webpack:
13
- // {
14
- // resolve: {
15
- // fallback: {
16
- // buffer: false,
17
- // stream: false
18
- // }
19
- // }
20
- // }
21
- // ----------------------------------------
22
- //
23
1
  import * as __WEBPACK_EXTERNAL_MODULE_stream__ from "stream";
24
2
  import * as __WEBPACK_EXTERNAL_MODULE_buffer__ from "buffer";
25
3
  /******/ // The require scope
@@ -2307,6 +2285,11 @@ var StreamUtils = /*#__PURE__*/function () {
2307
2285
  StreamUtils.endStream(readable);
2308
2286
  return readable;
2309
2287
  }
2288
+ }, {
2289
+ key: "fromArrayBuffer",
2290
+ value: function fromArrayBuffer(buffer) {
2291
+ return StreamUtils.fromBuffer(Buffer.from(buffer));
2292
+ }
2310
2293
  }, {
2311
2294
  key: "fromBuffer",
2312
2295
  value: function fromBuffer(buffer) {
@@ -2517,6 +2500,61 @@ var NodeChunkedStream = /*#__PURE__*/function () {
2517
2500
  var external_buffer_x = y => { var x = {}; __lib_require__.d(x, y); return x; }
2518
2501
  var external_buffer_y = x => () => x
2519
2502
  var external_buffer_namespaceObject = external_buffer_x({ ["Blob"]: () => __WEBPACK_EXTERNAL_MODULE_buffer__.Blob });
2503
+ ;// CONCATENATED MODULE: ./src/private/UploadManagerFetchUtils.ts
2504
+ function UploadManagerFetchUtils_typeof(obj) { "@babel/helpers - typeof"; return UploadManagerFetchUtils_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, UploadManagerFetchUtils_typeof(obj); }
2505
+ function UploadManagerFetchUtils_await(value, then, direct) {
2506
+ if (direct) {
2507
+ return then ? then(value) : value;
2508
+ }
2509
+ if (!value || !value.then) {
2510
+ value = Promise.resolve(value);
2511
+ }
2512
+ return then ? value.then(then) : value;
2513
+ }
2514
+ function UploadManagerFetchUtils_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2515
+ function UploadManagerFetchUtils_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, UploadManagerFetchUtils_toPropertyKey(descriptor.key), descriptor); } }
2516
+ function UploadManagerFetchUtils_createClass(Constructor, protoProps, staticProps) { if (protoProps) UploadManagerFetchUtils_defineProperties(Constructor.prototype, protoProps); if (staticProps) UploadManagerFetchUtils_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
2517
+ function UploadManagerFetchUtils_toPropertyKey(arg) { var key = UploadManagerFetchUtils_toPrimitive(arg, "string"); return UploadManagerFetchUtils_typeof(key) === "symbol" ? key : String(key); }
2518
+ function UploadManagerFetchUtils_toPrimitive(input, hint) { if (UploadManagerFetchUtils_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (UploadManagerFetchUtils_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
2519
+
2520
+ var UploadManagerFetchUtils = /*#__PURE__*/function () {
2521
+ function UploadManagerFetchUtils() {
2522
+ UploadManagerFetchUtils_classCallCheck(this, UploadManagerFetchUtils);
2523
+ }
2524
+ UploadManagerFetchUtils_createClass(UploadManagerFetchUtils, null, [{
2525
+ key: "doPutUploadPart",
2526
+ value: function doPutUploadPart(config, part, content, contentLength, addCancellationHandler) {
2527
+ try {
2528
+ var _a;
2529
+ var fetchApi = BytescaleApiClientConfigUtils.getFetchApi(config);
2530
+ // Configure cancellation:
2531
+ var controller = new AbortController();
2532
+ var signal = controller.signal;
2533
+ addCancellationHandler(function () {
2534
+ return controller.abort();
2535
+ });
2536
+ var headers = {
2537
+ // Required to prevent fetch using "Transfer-Encoding: Chunked" when body is a stream.
2538
+ "content-length": contentLength.toString()
2539
+ };
2540
+ return UploadManagerFetchUtils_await(fetchApi(part.uploadUrl, {
2541
+ method: "PUT",
2542
+ headers: headers,
2543
+ body: content,
2544
+ signal: signal
2545
+ }), function (response) {
2546
+ return {
2547
+ etag: (_a = response.headers.get("etag")) !== null && _a !== void 0 ? _a : undefined,
2548
+ status: response.status
2549
+ };
2550
+ });
2551
+ } catch (e) {
2552
+ return Promise.reject(e);
2553
+ }
2554
+ }
2555
+ }]);
2556
+ return UploadManagerFetchUtils;
2557
+ }();
2520
2558
  ;// CONCATENATED MODULE: ./src/public/node/UploadManagerNode.ts
2521
2559
  function UploadManagerNode_typeof(obj) { "@babel/helpers - typeof"; return UploadManagerNode_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, UploadManagerNode_typeof(obj); }
2522
2560
  function UploadManagerNode_empty() {}
@@ -2716,6 +2754,7 @@ function UploadManagerNode_getPrototypeOf(o) { UploadManagerNode_getPrototypeOf
2716
2754
 
2717
2755
 
2718
2756
 
2757
+
2719
2758
  var UploadManager = /*#__PURE__*/function (_UploadManagerBase) {
2720
2759
  UploadManagerNode_inherits(UploadManager, _UploadManagerBase);
2721
2760
  var _super = UploadManagerNode_createSuper(UploadManager);
@@ -2747,13 +2786,19 @@ var UploadManager = /*#__PURE__*/function (_UploadManagerBase) {
2747
2786
  value: data
2748
2787
  };
2749
2788
  }
2789
+ if (data.byteLength !== undefined) {
2790
+ return {
2791
+ type: "ArrayBuffer",
2792
+ value: data
2793
+ };
2794
+ }
2750
2795
  if (data.size !== undefined) {
2751
2796
  return {
2752
2797
  type: "Blob",
2753
2798
  value: data
2754
2799
  };
2755
2800
  }
2756
- throw new Error("Unsupported type for 'data' parameter. Please provide a String, Blob, or Readable (Node.js).");
2801
+ throw new Error("Unsupported type for 'data' parameter. Please provide a String, Blob, Buffer, ArrayBuffer, or ReadableStream (Node.js).");
2757
2802
  }
2758
2803
  }, {
2759
2804
  key: "getPreUploadInfoPartial",
@@ -2762,9 +2807,10 @@ var UploadManager = /*#__PURE__*/function (_UploadManagerBase) {
2762
2807
  case "Blob":
2763
2808
  return this.getBlobInfo(data);
2764
2809
  case "Buffer":
2810
+ case "ArrayBuffer":
2765
2811
  return {
2766
2812
  mime: undefined,
2767
- size: data.value.length,
2813
+ size: data.value.byteLength,
2768
2814
  originalFileName: undefined,
2769
2815
  maxConcurrentUploadParts: undefined
2770
2816
  };
@@ -2815,18 +2861,6 @@ var UploadManager = /*#__PURE__*/function (_UploadManagerBase) {
2815
2861
  value: function doPutUploadPart(part, contentLength, source, onProgress, addCancellationHandler) {
2816
2862
  try {
2817
2863
  var _this2 = this;
2818
- var _a, _b;
2819
- var fetchApi = (_a = _this2.config.fetchApi) !== null && _a !== void 0 ? _a : fetch;
2820
- var headers = {
2821
- // Required to prevent fetch using "Transfer-Encoding: Chunked" when body is a stream.
2822
- "content-length": contentLength.toString()
2823
- };
2824
- // Configure cancellation:
2825
- var controller = new AbortController();
2826
- var signal = controller.signal;
2827
- addCancellationHandler(function () {
2828
- return controller.abort();
2829
- });
2830
2864
  // Report progress:
2831
2865
  var hasWarned = false;
2832
2866
  return UploadManagerNode_await(_this2.sliceDataForRequest(source, part), function (stream) {
@@ -2838,17 +2872,7 @@ var UploadManager = /*#__PURE__*/function (_UploadManagerBase) {
2838
2872
  console.warn("Expected stream to contain buffers, but it did not, so upload progress won't be reported.");
2839
2873
  }
2840
2874
  });
2841
- return UploadManagerNode_await(fetchApi(part.uploadUrl, {
2842
- method: "PUT",
2843
- headers: headers,
2844
- body: _this2.coerceRequestBody(streamWithProgress),
2845
- signal: signal
2846
- }), function (response) {
2847
- return {
2848
- etag: (_b = response.headers.get("etag")) !== null && _b !== void 0 ? _b : undefined,
2849
- status: response.status
2850
- };
2851
- });
2875
+ return UploadManagerNode_await(UploadManagerFetchUtils.doPutUploadPart(_this2.config, part, _this2.coerceRequestBody(streamWithProgress), contentLength, addCancellationHandler));
2852
2876
  });
2853
2877
  } catch (e) {
2854
2878
  return Promise.reject(e);
@@ -2872,12 +2896,14 @@ var UploadManager = /*#__PURE__*/function (_UploadManagerBase) {
2872
2896
  return _switch(data.type, [[function () {
2873
2897
  return "Blob";
2874
2898
  }, function () {
2875
- var _fromBuffer = StreamUtils.fromBuffer,
2876
- _Buffer = Buffer,
2877
- _from = _Buffer.from;
2899
+ var _fromArrayBuffer = StreamUtils.fromArrayBuffer;
2878
2900
  return UploadManagerNode_await(data.value.slice(start, endExclusive).arrayBuffer(), function (_data$value$slice$arr) {
2879
- return _fromBuffer.call(StreamUtils, _from.call(_Buffer, _data$value$slice$arr));
2901
+ return _fromArrayBuffer.call(StreamUtils, _data$value$slice$arr);
2880
2902
  });
2903
+ }], [function () {
2904
+ return "ArrayBuffer";
2905
+ }, function () {
2906
+ return StreamUtils.fromArrayBuffer(data.value.slice(start, endExclusive));
2881
2907
  }], [function () {
2882
2908
  return "Buffer";
2883
2909
  }, function () {
@@ -2908,17 +2934,17 @@ var EnvChecker = /*#__PURE__*/function () {
2908
2934
  EnvChecker_classCallCheck(this, EnvChecker);
2909
2935
  }
2910
2936
  EnvChecker_createClass(EnvChecker, null, [{
2911
- key: "isNodeJs",
2912
- value: function isNodeJs() {
2913
- return typeof process !== "undefined" && process.versions !== undefined && process.versions.node !== undefined;
2937
+ key: "isBrowser",
2938
+ value: function isBrowser() {
2939
+ return typeof window !== "undefined";
2914
2940
  }
2915
2941
  }, {
2916
2942
  key: "methodRequiresBrowser",
2917
2943
  value: function methodRequiresBrowser(methodName) {
2918
- if (EnvChecker.isNodeJs()) {
2919
- return new Error("You must call '".concat(methodName, "' in the browser. (You are currently in Node.js.)"));
2944
+ if (!EnvChecker.isBrowser()) {
2945
+ return new Error("You must call '".concat(methodName, "' in your client-side code. (You have called it in your server-side code.)"));
2920
2946
  }
2921
- return new Error("The '".concat(methodName, "' method cannot be called because you have bundled the Node.js implementation of the Bytescale JavaScript SDK into your client-side code. Please ensure your bundling tool (Webpack, Rollup, etc.) is honouring the \"browser\" field of the \"package.json\" file for this package, as this will allow the browser implementation of the Bytescale JavaScript SDK to be included in your client-side code."));
2947
+ return new Error("The '".concat(methodName, "' method cannot be called because you have bundled a non-browser implementation of the Bytescale JavaScript SDK into your client-side code. Please ensure your bundling tool (Webpack, Rollup, etc.) is honouring the \"browser\" field of the \"package.json\" file for this package, as this will allow the browser implementation of the Bytescale JavaScript SDK to be included in your client-side code."));
2922
2948
  }
2923
2949
  }]);
2924
2950
  return EnvChecker;
@@ -0,0 +1,2 @@
1
+ export * from "./public/shared";
2
+ export * from "./public/worker";
@@ -1,4 +1,4 @@
1
1
  export declare class EnvChecker {
2
- static isNodeJs(): boolean;
2
+ static isBrowser(): boolean;
3
3
  static methodRequiresBrowser(methodName: string): Error;
4
4
  }
@@ -3,6 +3,7 @@ import type * as stream from "stream";
3
3
  export declare class StreamUtils {
4
4
  static create(): stream.Readable;
5
5
  static empty(): NodeJS.ReadableStream;
6
+ static fromArrayBuffer(buffer: ArrayBuffer): NodeJS.ReadableStream;
6
7
  static fromBuffer(buffer: Buffer): NodeJS.ReadableStream;
7
8
  static endStream(readable: stream.Readable): void;
8
9
  }
@@ -0,0 +1,19 @@
1
+ import { UploadManagerBase } from "./UploadManagerBase";
2
+ import { UploadSourceProcessedBrowser, UploadSourceProcessedWorker } from "./model/UploadSourceProcessed";
3
+ import { PreUploadInfo } from "./model/PreUploadInfo";
4
+ import { UploadPart } from "../public/shared/generated";
5
+ import { UploadManagerParams, UploadSource } from "../public/shared/CommonTypes";
6
+ declare type BrowserOrWorkerUploadSource = UploadSourceProcessedBrowser | UploadSourceProcessedWorker;
7
+ /**
8
+ * The "browser" and "worker" runtimes support the same input types, but the former uses XHR and the latter uses Fetch.
9
+ */
10
+ export declare abstract class UploadManagerBrowserWorkerBase extends UploadManagerBase<BrowserOrWorkerUploadSource, undefined> {
11
+ protected processUploadSource(data: UploadSource): BrowserOrWorkerUploadSource;
12
+ protected getPreUploadInfoPartial(_request: UploadManagerParams, data: BrowserOrWorkerUploadSource): Partial<PreUploadInfo> & {
13
+ size: number;
14
+ };
15
+ protected preUpload(_source: BrowserOrWorkerUploadSource): undefined;
16
+ protected postUpload(_init: undefined): Promise<void>;
17
+ protected getRequestBody(part: UploadPart, blob: BrowserOrWorkerUploadSource): Blob | ArrayBuffer;
18
+ }
19
+ export {};
@@ -0,0 +1,8 @@
1
+ import { BytescaleApiClientConfig, UploadPart } from "../public/shared";
2
+ import { AddCancellationHandler } from "./model/AddCancellationHandler";
3
+ export declare class UploadManagerFetchUtils {
4
+ static doPutUploadPart(config: BytescaleApiClientConfig, part: UploadPart, content: BodyInit, contentLength: number, addCancellationHandler: AddCancellationHandler): Promise<{
5
+ etag: string | undefined;
6
+ status: number;
7
+ }>;
8
+ }
@@ -9,10 +9,15 @@ export interface UploadSourceBuffer {
9
9
  type: "Buffer";
10
10
  value: Buffer;
11
11
  }
12
+ export interface UploadSourceArrayBuffer {
13
+ type: "ArrayBuffer";
14
+ value: ArrayBuffer;
15
+ }
12
16
  export interface UploadSourceStream {
13
17
  type: "Stream";
14
18
  value: NodeChunkedStream;
15
19
  }
16
- export declare type UploadSourceProcessedIsomorphic = UploadSourceBlob;
20
+ export declare type UploadSourceProcessedIsomorphic = UploadSourceBlob | UploadSourceArrayBuffer;
17
21
  export declare type UploadSourceProcessedBrowser = UploadSourceProcessedIsomorphic;
22
+ export declare type UploadSourceProcessedWorker = UploadSourceProcessedIsomorphic;
18
23
  export declare type UploadSourceProcessedNode = UploadSourceStream | UploadSourceBuffer | UploadSourceProcessedIsomorphic;
@@ -1,17 +1,8 @@
1
- import { UploadManagerBase } from "../../private/UploadManagerBase";
2
1
  import { UploadSourceProcessedBrowser } from "../../private/model/UploadSourceProcessed";
3
- import { PreUploadInfo } from "../../private/model/PreUploadInfo";
4
2
  import { UploadPart } from "../shared/generated";
5
3
  import { PutUploadPartResult } from "../../private/model/PutUploadPartResult";
6
4
  import { AddCancellationHandler } from "../../private/model/AddCancellationHandler";
7
- import { UploadManagerParams, UploadSource } from "../shared/CommonTypes";
8
- export declare class UploadManager extends UploadManagerBase<UploadSourceProcessedBrowser, undefined> {
9
- protected processUploadSource(data: UploadSource): UploadSourceProcessedBrowser;
10
- protected getPreUploadInfoPartial(_request: UploadManagerParams, data: UploadSourceProcessedBrowser): Partial<PreUploadInfo> & {
11
- size: number;
12
- };
13
- protected preUpload(_source: UploadSourceProcessedBrowser): undefined;
14
- protected postUpload(_init: undefined): Promise<void>;
5
+ import { UploadManagerBrowserWorkerBase } from "../../private/UploadManagerBrowserWorkerBase";
6
+ export declare class UploadManager extends UploadManagerBrowserWorkerBase {
15
7
  protected doPutUploadPart(part: UploadPart, contentLength: number, source: UploadSourceProcessedBrowser, onProgress: (bytesSentDelta: number) => void, addCancellationHandler: AddCancellationHandler): Promise<PutUploadPartResult>;
16
- private getRequestBody;
17
8
  }
@@ -0,0 +1,8 @@
1
+ import { UploadSourceProcessedWorker } from "../../private/model/UploadSourceProcessed";
2
+ import { UploadPart } from "../shared/generated";
3
+ import { PutUploadPartResult } from "../../private/model/PutUploadPartResult";
4
+ import { AddCancellationHandler } from "../../private/model/AddCancellationHandler";
5
+ import { UploadManagerBrowserWorkerBase } from "../../private/UploadManagerBrowserWorkerBase";
6
+ export declare class UploadManager extends UploadManagerBrowserWorkerBase {
7
+ protected doPutUploadPart(part: UploadPart, contentLength: number, source: UploadSourceProcessedWorker, _onProgress: (bytesSentDelta: number) => void, addCancellationHandler: AddCancellationHandler): Promise<PutUploadPartResult>;
8
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./UploadManagerWorker";
2
+ export * from "../node/AuthManagerNode";