@bytescale/sdk 1.1.0 → 1.3.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.
Files changed (49) hide show
  1. package/dist/browser/cjs/main.js +1152 -1094
  2. package/dist/node/cjs/main.js +1156 -952
  3. package/dist/node/esm/main.mjs +1167 -933
  4. package/dist/types/index.d.ts +2 -2
  5. package/dist/types/private/AuthSessionState.d.ts +13 -0
  6. package/dist/types/private/ConsoleUtils.d.ts +5 -0
  7. package/dist/types/private/EnvChecker.d.ts +4 -0
  8. package/dist/types/private/Mutex.d.ts +16 -0
  9. package/dist/types/{uploads/ChunkedStream.d.ts → private/NodeChunkedStream.d.ts} +11 -4
  10. package/dist/types/private/StreamUtils.d.ts +8 -0
  11. package/dist/types/private/TypeUtils.d.ts +2 -0
  12. package/dist/types/private/UploadManagerBase.d.ts +43 -0
  13. package/dist/types/private/dtos/SetAccessTokenRequestDto.d.ts +6 -0
  14. package/dist/types/private/dtos/SetAccessTokenResponseDto.d.ts +7 -0
  15. package/dist/types/private/model/AddCancellationHandler.d.ts +1 -0
  16. package/dist/types/private/model/AuthManagerInterface.d.ts +44 -0
  17. package/dist/types/private/model/AuthSession.d.ts +7 -0
  18. package/dist/types/private/model/OnPartProgress.d.ts +1 -0
  19. package/dist/types/private/model/PreUploadInfo.d.ts +6 -0
  20. package/dist/types/private/model/PutUploadPartResult.d.ts +4 -0
  21. package/dist/types/private/model/UploadManagerInterface.d.ts +5 -0
  22. package/dist/types/private/model/UploadSourceProcessed.d.ts +18 -0
  23. package/dist/types/public/browser/AuthManagerBrowser.d.ts +20 -0
  24. package/dist/types/public/browser/UploadManagerBrowser.d.ts +17 -0
  25. package/dist/types/public/browser/index.d.ts +2 -0
  26. package/dist/types/public/node/AuthManagerNode.d.ts +6 -0
  27. package/dist/types/public/node/UploadManagerNode.d.ts +26 -0
  28. package/dist/types/public/node/index.d.ts +2 -0
  29. package/dist/types/{uploads/UploadModel.d.ts → public/shared/CommonTypes.d.ts} +8 -11
  30. package/dist/types/public/shared/UrlBuilder.d.ts +28 -0
  31. package/dist/types/public/shared/UrlBuilderTypes.d.ts +173 -0
  32. package/dist/types/{generated → public/shared/generated}/runtime.d.ts +44 -29
  33. package/dist/types/public/shared/index.d.ts +4 -0
  34. package/package.json +2 -2
  35. package/tests/ChunkedStream.test.ts +3 -3
  36. package/tests/UploadManager.test.ts +1 -1
  37. package/tests/UrlBuilder.test.ts +168 -0
  38. package/dist/browser/cjs/_70b2.main.js +0 -10
  39. package/dist/browser/cjs/_7392.main.js +0 -10
  40. package/dist/types/uploads/NodeUtils.d.ts +0 -13
  41. package/dist/types/uploads/UploadManager.d.ts +0 -39
  42. package/dist/types/uploads/index.d.ts +0 -3
  43. /package/dist/types/{generated → public/shared/generated}/apis/FileApi.d.ts +0 -0
  44. /package/dist/types/{generated → public/shared/generated}/apis/FolderApi.d.ts +0 -0
  45. /package/dist/types/{generated → public/shared/generated}/apis/JobApi.d.ts +0 -0
  46. /package/dist/types/{generated → public/shared/generated}/apis/UploadApi.d.ts +0 -0
  47. /package/dist/types/{generated → public/shared/generated}/apis/index.d.ts +0 -0
  48. /package/dist/types/{generated → public/shared/generated}/index.d.ts +0 -0
  49. /package/dist/types/{generated → public/shared/generated}/models/index.d.ts +0 -0
@@ -22,79 +22,10 @@
22
22
  //
23
23
  /******/ (function() { // webpackBootstrap
24
24
  /******/ "use strict";
25
- /******/ var __lib_modules__ = ({
26
-
27
- /***/ "buffer":
28
- /***/ (function(module) {
29
-
30
- module.exports = require("buffer");
31
-
32
- /***/ }),
33
-
34
- /***/ "stream":
35
- /***/ (function(module) {
36
-
37
- module.exports = require("stream");
38
-
39
- /***/ })
40
-
41
- /******/ });
42
- /************************************************************************/
43
- /******/ // The module cache
44
- /******/ var __lib_module_cache__ = {};
45
- /******/
46
- /******/ // The require function
47
- /******/ function __lib_require__(moduleId) {
48
- /******/ // Check if module is in cache
49
- /******/ var cachedModule = __lib_module_cache__[moduleId];
50
- /******/ if (cachedModule !== undefined) {
51
- /******/ return cachedModule.exports;
52
- /******/ }
53
- /******/ // Create a new module (and put it into the cache)
54
- /******/ var module = __lib_module_cache__[moduleId] = {
55
- /******/ // no module.id needed
56
- /******/ // no module.loaded needed
57
- /******/ exports: {}
58
- /******/ };
59
- /******/
60
- /******/ // Execute the module function
61
- /******/ __lib_modules__[moduleId](module, module.exports, __lib_require__);
62
- /******/
63
- /******/ // Return the exports of the module
64
- /******/ return module.exports;
65
- /******/ }
25
+ /******/ // The require scope
26
+ /******/ var __lib_require__ = {};
66
27
  /******/
67
28
  /************************************************************************/
68
- /******/ /* webpack/runtime/create fake namespace object */
69
- /******/ !function() {
70
- /******/ var getProto = Object.getPrototypeOf ? function(obj) { return Object.getPrototypeOf(obj); } : function(obj) { return obj.__proto__; };
71
- /******/ var leafPrototypes;
72
- /******/ // create a fake namespace object
73
- /******/ // mode & 1: value is a module id, require it
74
- /******/ // mode & 2: merge all properties of value into the ns
75
- /******/ // mode & 4: return value when already ns object
76
- /******/ // mode & 16: return value when it's Promise-like
77
- /******/ // mode & 8|1: behave like require
78
- /******/ __lib_require__.t = function(value, mode) {
79
- /******/ if(mode & 1) value = this(value);
80
- /******/ if(mode & 8) return value;
81
- /******/ if(typeof value === 'object' && value) {
82
- /******/ if((mode & 4) && value.__esModule) return value;
83
- /******/ if((mode & 16) && typeof value.then === 'function') return value;
84
- /******/ }
85
- /******/ var ns = Object.create(null);
86
- /******/ __lib_require__.r(ns);
87
- /******/ var def = {};
88
- /******/ leafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)];
89
- /******/ for(var current = mode & 2 && value; typeof current == 'object' && !~leafPrototypes.indexOf(current); current = getProto(current)) {
90
- /******/ Object.getOwnPropertyNames(current).forEach(function(key) { def[key] = function() { return value[key]; }; });
91
- /******/ }
92
- /******/ def['default'] = function() { return value; };
93
- /******/ __lib_require__.d(ns, def);
94
- /******/ return ns;
95
- /******/ };
96
- /******/ }();
97
- /******/
98
29
  /******/ /* webpack/runtime/define property getters */
99
30
  /******/ !function() {
100
31
  /******/ // define getter functions for harmony exports
@@ -125,37 +56,45 @@ module.exports = require("stream");
125
56
  /******/
126
57
  /************************************************************************/
127
58
  var __lib_exports__ = {};
128
- // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
129
- !function() {
130
59
  // ESM COMPAT FLAG
131
60
  __lib_require__.r(__lib_exports__);
132
61
 
133
62
  // EXPORTS
134
63
  __lib_require__.d(__lib_exports__, {
135
- "BASE_PATH": function() { return /* reexport */ BASE_PATH; },
64
+ "AuthManager": function() { return /* reexport */ AuthManager; },
136
65
  "BaseAPI": function() { return /* reexport */ BaseAPI; },
137
66
  "BinaryResult": function() { return /* reexport */ BinaryResult; },
67
+ "BytescaleApiClientConfigResolver": function() { return /* reexport */ BytescaleApiClientConfigResolver; },
138
68
  "BytescaleApiError": function() { return /* reexport */ BytescaleApiError; },
139
69
  "CancelledError": function() { return /* reexport */ CancelledError; },
140
- "ChunkedStream": function() { return /* reexport */ ChunkedStream; },
141
- "FetchError": function() { return /* reexport */ FetchError; },
70
+ "CommonTypesNoOp": function() { return /* reexport */ CommonTypesNoOp; },
142
71
  "FileApi": function() { return /* reexport */ FileApi; },
143
72
  "FolderApi": function() { return /* reexport */ FolderApi; },
144
73
  "JSONApiResponse": function() { return /* reexport */ JSONApiResponse; },
145
74
  "JobApi": function() { return /* reexport */ JobApi; },
146
- "RequiredError": function() { return /* reexport */ RequiredError; },
147
- "ResponseError": function() { return /* reexport */ ResponseError; },
148
75
  "UploadApi": function() { return /* reexport */ UploadApi; },
149
76
  "UploadManager": function() { return /* reexport */ UploadManager; },
77
+ "UrlBuilder": function() { return /* reexport */ UrlBuilder; },
78
+ "UrlBuilderTypesNoOp": function() { return /* reexport */ UrlBuilderTypesNoOp; },
150
79
  "VoidApiResponse": function() { return /* reexport */ VoidApiResponse; },
151
80
  "querystring": function() { return /* reexport */ querystring; }
152
81
  });
153
82
 
154
- ;// CONCATENATED MODULE: ./src/generated/runtime.ts
83
+ ;// CONCATENATED MODULE: ./src/private/AuthSessionState.ts
155
84
  function _typeof(obj) { "@babel/helpers - typeof"; return _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; }, _typeof(obj); }
85
+ function _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, _toPropertyKey(descriptor.key), descriptor); } }
86
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
87
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
88
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
89
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
90
+ var AuthSessionState = /*#__PURE__*/_createClass(function AuthSessionState() {
91
+ _classCallCheck(this, AuthSessionState);
92
+ });
93
+ ;// CONCATENATED MODULE: ./src/public/shared/generated/runtime.ts
94
+ function runtime_typeof(obj) { "@babel/helpers - typeof"; return runtime_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; }, runtime_typeof(obj); }
156
95
  function _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) _setPrototypeOf(subClass, superClass); }
157
96
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
158
- function _possibleConstructorReturn(self, call) { if (call && (_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 _assertThisInitialized(self); }
97
+ function _possibleConstructorReturn(self, call) { if (call && (runtime_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 _assertThisInitialized(self); }
159
98
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
160
99
  function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
161
100
  function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct.bind(); } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
@@ -163,15 +102,6 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
163
102
  function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
164
103
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
165
104
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
166
- function _await(value, then, direct) {
167
- if (direct) {
168
- return then ? then(value) : value;
169
- }
170
- if (!value || !value.then) {
171
- value = Promise.resolve(value);
172
- }
173
- return then ? value.then(then) : value;
174
- }
175
105
  function _catch(body, recover) {
176
106
  try {
177
107
  var result = body();
@@ -183,22 +113,10 @@ function _catch(body, recover) {
183
113
  }
184
114
  return result;
185
115
  }
116
+ function _empty() {}
186
117
  function _continue(value, then) {
187
118
  return value && value.then ? value.then(then) : then(value);
188
119
  }
189
- function _async(f) {
190
- return function () {
191
- for (var args = [], i = 0; i < arguments.length; i++) {
192
- args[i] = arguments[i];
193
- }
194
- try {
195
- return Promise.resolve(f.apply(this, args));
196
- } catch (e) {
197
- return Promise.reject(e);
198
- }
199
- };
200
- }
201
- function _empty() {}
202
120
  function _invoke(body, then) {
203
121
  var result = body();
204
122
  if (result && result.then) {
@@ -206,85 +124,122 @@ function _invoke(body, then) {
206
124
  }
207
125
  return then(result);
208
126
  }
209
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
210
- function _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, _toPropertyKey(descriptor.key), descriptor); } }
211
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
212
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
213
- function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
214
- /**
215
- * @bytescale/api
216
- * Bytescale API
217
- *
218
- * The version of the OpenAPI document: 2.0.0
219
- * Contact: hello@bytescale.com
220
- *
221
- * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
222
- * https://openapi-generator.tech
223
- * Do not edit the class manually.
224
- */
225
- var BASE_PATH = "https://api.bytescale.com".replace(/\/+$/, "");
127
+ function _defineProperty(obj, key, value) { key = runtime_toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
128
+ function _await(value, then, direct) {
129
+ if (direct) {
130
+ return then ? then(value) : value;
131
+ }
132
+ if (!value || !value.then) {
133
+ value = Promise.resolve(value);
134
+ }
135
+ return then ? value.then(then) : value;
136
+ }
137
+ function runtime_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
138
+ function runtime_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, runtime_toPropertyKey(descriptor.key), descriptor); } }
139
+ function runtime_createClass(Constructor, protoProps, staticProps) { if (protoProps) runtime_defineProperties(Constructor.prototype, protoProps); if (staticProps) runtime_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
140
+ function runtime_toPropertyKey(arg) { var key = runtime_toPrimitive(arg, "string"); return runtime_typeof(key) === "symbol" ? key : String(key); }
141
+ function runtime_toPrimitive(input, hint) { if (runtime_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (runtime_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
142
+
143
+ var BytescaleApiClientConfigResolver = /*#__PURE__*/function () {
144
+ function BytescaleApiClientConfigResolver() {
145
+ runtime_classCallCheck(this, BytescaleApiClientConfigResolver);
146
+ }
147
+ runtime_createClass(BytescaleApiClientConfigResolver, null, [{
148
+ key: "getApiUrl",
149
+ value: function getApiUrl(config) {
150
+ var _a;
151
+ return (_a = config.apiUrl) !== null && _a !== void 0 ? _a : BytescaleApiClientConfigResolver.defaultApiUrl;
152
+ }
153
+ }, {
154
+ key: "getCdnUrl",
155
+ value: function getCdnUrl(config) {
156
+ var _a;
157
+ return (_a = config.cdnUrl) !== null && _a !== void 0 ? _a : BytescaleApiClientConfigResolver.defaultCdnUrl;
158
+ }
159
+ }, {
160
+ key: "getFetchApi",
161
+ value: function getFetchApi(config) {
162
+ var _a;
163
+ return (_a = config.fetchApi) !== null && _a !== void 0 ? _a : fetch;
164
+ }
165
+ }]);
166
+ return BytescaleApiClientConfigResolver;
167
+ }();
168
+ BytescaleApiClientConfigResolver.defaultApiUrl = "https://api.bytescale.com";
169
+ BytescaleApiClientConfigResolver.defaultCdnUrl = "https://upcdn.io";
226
170
  /**
227
171
  * This is the base class for all generated API classes.
228
172
  */
229
173
  var BaseAPI = /*#__PURE__*/function () {
230
174
  function BaseAPI(config) {
231
- var _this = this;
232
- _classCallCheck(this, BaseAPI);
175
+ runtime_classCallCheck(this, BaseAPI);
233
176
  this.config = config;
234
- this.fetchApi = _async(function (url, init) {
235
- var _exit = false;
236
- var fetchParams = {
237
- url: url,
238
- init: init
239
- };
240
- var response = undefined;
241
- return _continue(_catch(function () {
242
- return _await((_this.config.fetchApi || fetch)(fetchParams.url, fetchParams.init), function (_temp) {
243
- response = _temp;
244
- });
245
- }, function (e) {
246
- if (response === undefined) {
247
- if (e instanceof Error) {
248
- throw new FetchError(e, "The request failed and the interceptors did not return an alternative response");
249
- } else {
250
- throw e;
251
- }
252
- }
253
- }), function (_result) {
254
- return _exit ? _result : response;
255
- });
256
- });
257
177
  }
258
- _createClass(BaseAPI, [{
178
+ runtime_createClass(BaseAPI, [{
259
179
  key: "request",
260
- value: function request(context, initOverrides, operationBasePathOverride) {
180
+ value: function request(context, initOverrides, baseUrlOverride) {
261
181
  try {
262
- var _this3 = this;
263
- var _a;
264
- var apiKey = _this3.config.apiKey;
182
+ var _this2 = this;
183
+ var _a, _b;
184
+ var apiKey = _this2.config.apiKey;
265
185
  context.headers["Authorization"] = "Bearer ".concat(apiKey); // authorization-header authentication
266
- return _await(_this3.createFetchParams(context, initOverrides, operationBasePathOverride), function (_ref) {
186
+ if (((_a = AuthSessionState.session) === null || _a === void 0 ? void 0 : _a.accessToken) !== undefined) {
187
+ context.headers["Authorization-Token"] = AuthSessionState.session.accessToken;
188
+ }
189
+ // Key: any possible value for 'baseUrlOverride'
190
+ // Value: user-overridden value for that base URL from the config.
191
+ var nonDefaultBasePaths = _defineProperty({}, BytescaleApiClientConfigResolver.defaultCdnUrl, BytescaleApiClientConfigResolver.getCdnUrl(_this2.config));
192
+ return _await(_this2.createFetchParams(context, initOverrides, baseUrlOverride === undefined ? undefined : (_b = nonDefaultBasePaths[baseUrlOverride]) !== null && _b !== void 0 ? _b : baseUrlOverride), function (_ref) {
267
193
  var url = _ref.url,
268
194
  init = _ref.init;
269
- return _await(_this3.fetchApi(url, init), function (response) {
270
- var _exit2 = false;
271
- return response && response.status >= 200 && response.status < 300 ? response : _invoke(function () {
272
- if (response !== undefined) {
273
- var jsonError = undefined;
274
- return _continue(_catch(function () {
275
- return _await(response.json(), function (_response$json) {
276
- jsonError = _response$json;
277
- });
278
- }, _empty), function () {
279
- if (typeof ((_a = jsonError === null || jsonError === void 0 ? void 0 : jsonError.error) === null || _a === void 0 ? void 0 : _a.code) === "string") {
280
- throw new BytescaleApiError(jsonError);
281
- }
195
+ return _this2.doFetch(url, init, true);
196
+ });
197
+ } catch (e) {
198
+ return Promise.reject(e);
199
+ }
200
+ }
201
+ /**
202
+ * Returns a successful response (2**) else throws an error.
203
+ */
204
+ }, {
205
+ key: "doFetch",
206
+ value: function doFetch(url, init, isBytescaleApi) {
207
+ try {
208
+ var _exit3 = false;
209
+ var _this4 = this;
210
+ var _a, _b;
211
+ var response;
212
+ return _continue(_catch(function () {
213
+ return _await(BytescaleApiClientConfigResolver.getFetchApi(_this4.config)(url, init), function (_BytescaleApiClientCo) {
214
+ response = _BytescaleApiClientCo;
215
+ });
216
+ }, function (e) {
217
+ // Network-level errors, CORS errors, or HTTP-level errors from intermediary services (e.g. AWS or the user's own infrastructure/proxies).
218
+ // HTTP-level errors from external services (e.g. AWS or the user's own proxy) will appear as CORS errors as their response headers won't include the appropriate CORS values.
219
+ throw new Error(isBytescaleApi ? "Unable to resolve the Bytescale API: ".concat(e.message, " If the problem persists, and your network connection is OK, then please contact support@bytescale.com and provide: (a) time of failed request in UTC (b) screenshot of failed network response header + body (c) screenshot of failed network request header + body (d) browser and OS version.") : "Unable to resolve URL (".concat(url, "): ").concat(e.message));
220
+ }), function (_result) {
221
+ var _exit2 = false;
222
+ if (_exit3) return _result;
223
+ return response.status >= 200 && response.status < 300 ? response : _invoke(function () {
224
+ if (isBytescaleApi) {
225
+ var jsonError = undefined;
226
+ return _continue(_catch(function () {
227
+ return _await(response.json(), function (_response$json) {
228
+ jsonError = _response$json;
282
229
  });
283
- }
284
- }, function (_result2) {
285
- if (_exit2) return _result2;
286
- throw new ResponseError(response, "Response returned an error code");
287
- });
230
+ }, _empty), function () {
231
+ if (typeof ((_a = jsonError === null || jsonError === void 0 ? void 0 : jsonError.error) === null || _a === void 0 ? void 0 : _a.code) === "string") {
232
+ throw new BytescaleApiError(jsonError);
233
+ }
234
+ // HTTP-level errors from intermediary services (e.g. AWS or the user's own infrastructure/proxies). On the browser,
235
+ // this error is unlikely to be triggered since these errors will masqurade as CORS errors (see above) but in Node.js
236
+ // this error will appear from any intermediary service failure.
237
+ throw new Error("Unable to connect to the Bytescale API (".concat(response.status, "): please try again."));
238
+ });
239
+ }
240
+ }, function (_result2) {
241
+ if (_exit2) return _result2;
242
+ throw new Error("Failure status code (".concat(response.status, ") received for request: ").concat((_b = init.method) !== null && _b !== void 0 ? _b : "GET", " ").concat(url));
288
243
  });
289
244
  });
290
245
  } catch (e) {
@@ -306,17 +261,17 @@ var BaseAPI = /*#__PURE__*/function () {
306
261
  }
307
262
  }, {
308
263
  key: "createFetchParams",
309
- value: function createFetchParams(context, initOverrides, operationBasePathOverride) {
264
+ value: function createFetchParams(context, initOverrides, baseUrlOverride) {
310
265
  try {
311
- var _this5 = this;
312
- var url = (operationBasePathOverride !== null && operationBasePathOverride !== void 0 ? operationBasePathOverride : BASE_PATH) + context.path;
266
+ var _this6 = this;
267
+ var url = (baseUrlOverride !== null && baseUrlOverride !== void 0 ? baseUrlOverride : BytescaleApiClientConfigResolver.getApiUrl(_this6.config)) + context.path;
313
268
  if (context.query !== undefined && Object.keys(context.query).length !== 0) {
314
269
  // only add the querystring to the URL if there are query parameters.
315
270
  // this is done to avoid urls ending with a "?" character which buggy webservers
316
271
  // do not handle correctly sometimes.
317
272
  url += "?" + querystring(context.query);
318
273
  }
319
- var configHeaders = _this5.config.headers;
274
+ var configHeaders = _this6.config.headers;
320
275
  var _Object$assign3 = Object.assign({}, context.headers);
321
276
  return _await(configHeaders === undefined ? {} : configHeaders(), function (_configHeaders) {
322
277
  var headers = Object.assign(_Object$assign3, _configHeaders);
@@ -338,7 +293,7 @@ var BaseAPI = /*#__PURE__*/function () {
338
293
  }), function (_initOverrideFn) {
339
294
  var overriddenInit = Object.assign(_Object$assign2, _initOverrideFn);
340
295
  var init = Object.assign(Object.assign({}, overriddenInit), {
341
- body: isFormData(overriddenInit.body) || overriddenInit.body instanceof URLSearchParams || isBlob(overriddenInit.body) ? overriddenInit.body : JSON.stringify(overriddenInit.body)
296
+ body: JSON.stringify(overriddenInit.body)
342
297
  });
343
298
  return {
344
299
  url: url,
@@ -353,64 +308,34 @@ var BaseAPI = /*#__PURE__*/function () {
353
308
  }]);
354
309
  return BaseAPI;
355
310
  }();
356
- function isBlob(value) {
357
- return typeof Blob !== "undefined" && value instanceof Blob;
358
- }
359
- function isFormData(value) {
360
- return typeof FormData !== "undefined" && value instanceof FormData;
361
- }
362
- var BytescaleApiError = /*#__PURE__*/function (_Error) {
363
- _inherits(BytescaleApiError, _Error);
364
- var _super = _createSuper(BytescaleApiError);
365
- function BytescaleApiError(response) {
366
- var _this6;
367
- _classCallCheck(this, BytescaleApiError);
368
- _this6 = _super.call(this, response.error.message);
369
- _this6.name = "BytescaleApiError";
370
- _this6.errorCode = response.error.code;
371
- _this6.details = response.error.details;
372
- return _this6;
373
- }
374
- return _createClass(BytescaleApiError);
375
- }( /*#__PURE__*/_wrapNativeSuper(Error));
376
- var ResponseError = /*#__PURE__*/function (_Error2) {
377
- _inherits(ResponseError, _Error2);
378
- var _super2 = _createSuper(ResponseError);
379
- function ResponseError(response, msg) {
311
+ BaseAPI.specialApiKeys = ["free", "demo"];
312
+ BaseAPI.specialApiKeyAccountId = "W142hJk";
313
+ BaseAPI.accountIdLength = 7; // Sync with: upload/shared/**/AccountIdUtils
314
+ var CancelledError = /*#__PURE__*/function (_Error) {
315
+ _inherits(CancelledError, _Error);
316
+ var _super = _createSuper(CancelledError);
317
+ function CancelledError() {
380
318
  var _this7;
381
- _classCallCheck(this, ResponseError);
382
- _this7 = _super2.call(this, msg);
383
- _this7.response = response;
384
- _this7.name = "ResponseError";
319
+ runtime_classCallCheck(this, CancelledError);
320
+ _this7 = _super.call(this, "Operation cancelled by caller.");
321
+ _this7.name = "CancelledError";
385
322
  return _this7;
386
323
  }
387
- return _createClass(ResponseError);
324
+ return runtime_createClass(CancelledError);
388
325
  }( /*#__PURE__*/_wrapNativeSuper(Error));
389
- var FetchError = /*#__PURE__*/function (_Error3) {
390
- _inherits(FetchError, _Error3);
391
- var _super3 = _createSuper(FetchError);
392
- function FetchError(cause, msg) {
326
+ var BytescaleApiError = /*#__PURE__*/function (_Error2) {
327
+ _inherits(BytescaleApiError, _Error2);
328
+ var _super2 = _createSuper(BytescaleApiError);
329
+ function BytescaleApiError(response) {
393
330
  var _this8;
394
- _classCallCheck(this, FetchError);
395
- _this8 = _super3.call(this, msg);
396
- _this8.cause = cause;
397
- _this8.name = "FetchError";
331
+ runtime_classCallCheck(this, BytescaleApiError);
332
+ _this8 = _super2.call(this, response.error.message);
333
+ _this8.name = "BytescaleApiError";
334
+ _this8.errorCode = response.error.code;
335
+ _this8.details = response.error.details;
398
336
  return _this8;
399
337
  }
400
- return _createClass(FetchError);
401
- }( /*#__PURE__*/_wrapNativeSuper(Error));
402
- var RequiredError = /*#__PURE__*/function (_Error4) {
403
- _inherits(RequiredError, _Error4);
404
- var _super4 = _createSuper(RequiredError);
405
- function RequiredError(field, msg) {
406
- var _this9;
407
- _classCallCheck(this, RequiredError);
408
- _this9 = _super4.call(this, msg);
409
- _this9.field = field;
410
- _this9.name = "RequiredError";
411
- return _this9;
412
- }
413
- return _createClass(RequiredError);
338
+ return runtime_createClass(BytescaleApiError);
414
339
  }( /*#__PURE__*/_wrapNativeSuper(Error));
415
340
  function querystring(params) {
416
341
  var prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
@@ -443,22 +368,15 @@ function querystringSingleKey(key, value) {
443
368
  }
444
369
  var JSONApiResponse = /*#__PURE__*/function () {
445
370
  function JSONApiResponse(raw) {
446
- var transformer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (jsonValue) {
447
- return jsonValue;
448
- };
449
- _classCallCheck(this, JSONApiResponse);
371
+ runtime_classCallCheck(this, JSONApiResponse);
450
372
  this.raw = raw;
451
- this.transformer = transformer;
452
373
  }
453
- _createClass(JSONApiResponse, [{
374
+ runtime_createClass(JSONApiResponse, [{
454
375
  key: "value",
455
376
  value: function value() {
456
377
  try {
457
- var _this11 = this;
458
- var _transformer2 = _this11.transformer;
459
- return _await(_this11.raw.json(), function (_this10$raw$json) {
460
- return _transformer2.call(_this11, _this10$raw$json);
461
- });
378
+ var _this10 = this;
379
+ return _await(_this10.raw.json());
462
380
  } catch (e) {
463
381
  return Promise.reject(e);
464
382
  }
@@ -468,10 +386,10 @@ var JSONApiResponse = /*#__PURE__*/function () {
468
386
  }();
469
387
  var VoidApiResponse = /*#__PURE__*/function () {
470
388
  function VoidApiResponse(raw) {
471
- _classCallCheck(this, VoidApiResponse);
389
+ runtime_classCallCheck(this, VoidApiResponse);
472
390
  this.raw = raw;
473
391
  }
474
- _createClass(VoidApiResponse, [{
392
+ runtime_createClass(VoidApiResponse, [{
475
393
  key: "value",
476
394
  value: function value() {
477
395
  return _await(undefined);
@@ -481,10 +399,10 @@ var VoidApiResponse = /*#__PURE__*/function () {
481
399
  }();
482
400
  var BinaryResult = /*#__PURE__*/function () {
483
401
  function BinaryResult(raw) {
484
- _classCallCheck(this, BinaryResult);
402
+ runtime_classCallCheck(this, BinaryResult);
485
403
  this.raw = raw;
486
404
  }
487
- _createClass(BinaryResult, [{
405
+ runtime_createClass(BinaryResult, [{
488
406
  key: "stream",
489
407
  value: function stream() {
490
408
  if (this.raw.bodyUsed) {
@@ -499,8 +417,8 @@ var BinaryResult = /*#__PURE__*/function () {
499
417
  key: "text",
500
418
  value: function text() {
501
419
  try {
502
- var _this13 = this;
503
- return _await(_this13.raw.text());
420
+ var _this12 = this;
421
+ return _await(_this12.raw.text());
504
422
  } catch (e) {
505
423
  return Promise.reject(e);
506
424
  }
@@ -509,8 +427,8 @@ var BinaryResult = /*#__PURE__*/function () {
509
427
  key: "blob",
510
428
  value: function blob() {
511
429
  try {
512
- var _this15 = this;
513
- return _await(_this15.raw.blob());
430
+ var _this14 = this;
431
+ return _await(_this14.raw.blob());
514
432
  } catch (e) {
515
433
  return Promise.reject(e);
516
434
  }
@@ -519,8 +437,8 @@ var BinaryResult = /*#__PURE__*/function () {
519
437
  key: "json",
520
438
  value: function json() {
521
439
  try {
522
- var _this17 = this;
523
- return _await(_this17.raw.json());
440
+ var _this16 = this;
441
+ return _await(_this16.raw.json());
524
442
  } catch (e) {
525
443
  return Promise.reject(e);
526
444
  }
@@ -528,7 +446,7 @@ var BinaryResult = /*#__PURE__*/function () {
528
446
  }]);
529
447
  return BinaryResult;
530
448
  }();
531
- ;// CONCATENATED MODULE: ./src/generated/apis/FileApi.ts
449
+ ;// CONCATENATED MODULE: ./src/public/shared/generated/apis/FileApi.ts
532
450
  function FileApi_typeof(obj) { "@babel/helpers - typeof"; return FileApi_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; }, FileApi_typeof(obj); }
533
451
  function FileApi_await(value, then, direct) {
534
452
  if (direct) {
@@ -823,7 +741,7 @@ var FileApi = /*#__PURE__*/function (_runtime$BaseAPI) {
823
741
  }]);
824
742
  return FileApi;
825
743
  }(BaseAPI);
826
- ;// CONCATENATED MODULE: ./src/generated/apis/FolderApi.ts
744
+ ;// CONCATENATED MODULE: ./src/public/shared/generated/apis/FolderApi.ts
827
745
  function FolderApi_typeof(obj) { "@babel/helpers - typeof"; return FolderApi_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; }, FolderApi_typeof(obj); }
828
746
  function FolderApi_await(value, then, direct) {
829
747
  if (direct) {
@@ -1083,7 +1001,7 @@ var FolderApi = /*#__PURE__*/function (_runtime$BaseAPI) {
1083
1001
  }]);
1084
1002
  return FolderApi;
1085
1003
  }(BaseAPI);
1086
- ;// CONCATENATED MODULE: ./src/generated/apis/JobApi.ts
1004
+ ;// CONCATENATED MODULE: ./src/public/shared/generated/apis/JobApi.ts
1087
1005
  function JobApi_typeof(obj) { "@babel/helpers - typeof"; return JobApi_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; }, JobApi_typeof(obj); }
1088
1006
  function JobApi_await(value, then, direct) {
1089
1007
  if (direct) {
@@ -1218,7 +1136,7 @@ var JobApi = /*#__PURE__*/function (_runtime$BaseAPI) {
1218
1136
  }]);
1219
1137
  return JobApi;
1220
1138
  }(BaseAPI);
1221
- ;// CONCATENATED MODULE: ./src/generated/apis/UploadApi.ts
1139
+ ;// CONCATENATED MODULE: ./src/public/shared/generated/apis/UploadApi.ts
1222
1140
  function UploadApi_typeof(obj) { "@babel/helpers - typeof"; return UploadApi_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; }, UploadApi_typeof(obj); }
1223
1141
  function UploadApi_await(value, then, direct) {
1224
1142
  if (direct) {
@@ -1406,366 +1324,198 @@ var UploadApi = /*#__PURE__*/function (_runtime$BaseAPI) {
1406
1324
  }]);
1407
1325
  return UploadApi;
1408
1326
  }(BaseAPI);
1409
- ;// CONCATENATED MODULE: ./src/generated/apis/index.ts
1327
+ ;// CONCATENATED MODULE: ./src/public/shared/generated/apis/index.ts
1410
1328
  /* tslint:disable */
1411
1329
  /* eslint-disable */
1412
1330
 
1413
1331
 
1414
1332
 
1415
1333
 
1416
- ;// CONCATENATED MODULE: ./src/generated/index.ts
1334
+ ;// CONCATENATED MODULE: ./src/public/shared/generated/index.ts
1417
1335
  /* tslint:disable */
1418
1336
  /* eslint-disable */
1419
1337
 
1420
1338
 
1421
1339
 
1422
- ;// CONCATENATED MODULE: ./src/uploads/NodeUtils.ts
1423
- function NodeUtils_typeof(obj) { "@babel/helpers - typeof"; return NodeUtils_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; }, NodeUtils_typeof(obj); }
1424
- function NodeUtils_await(value, then, direct) {
1425
- if (direct) {
1426
- return then ? then(value) : value;
1427
- }
1428
- if (!value || !value.then) {
1429
- value = Promise.resolve(value);
1430
- }
1431
- return then ? value.then(then) : value;
1432
- }
1433
- function NodeUtils_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1434
- function NodeUtils_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, NodeUtils_toPropertyKey(descriptor.key), descriptor); } }
1435
- function NodeUtils_createClass(Constructor, protoProps, staticProps) { if (protoProps) NodeUtils_defineProperties(Constructor.prototype, protoProps); if (staticProps) NodeUtils_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
1436
- function NodeUtils_toPropertyKey(arg) { var key = NodeUtils_toPrimitive(arg, "string"); return NodeUtils_typeof(key) === "symbol" ? key : String(key); }
1437
- function NodeUtils_toPrimitive(input, hint) { if (NodeUtils_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (NodeUtils_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
1340
+ ;// CONCATENATED MODULE: ./src/public/shared/CommonTypes.ts
1438
1341
  /**
1439
- * Provides access to Node.js built-in libraries. Should only be called when we're certain we're running in Node.js.
1440
- *
1441
- * We import lazily to support browsers, which don't have these modules, but also won't call these methods so won't trigger the imports.
1342
+ * Workaround for tsc aliases, where we cannot export implementation-less modules in our dists.
1442
1343
  */
1443
- var NodeUtils = /*#__PURE__*/function () {
1444
- function NodeUtils() {
1445
- NodeUtils_classCallCheck(this, NodeUtils);
1344
+ var CommonTypesNoOp = false;
1345
+ ;// CONCATENATED MODULE: ./src/private/TypeUtils.ts
1346
+ function assertUnreachable(x) {
1347
+ throw new Error("Didn't expect to get here: ".concat(JSON.stringify(x)));
1348
+ }
1349
+ function isDefinedEntry(object) {
1350
+ return object[1] !== undefined && object[1] !== null;
1351
+ }
1352
+ ;// CONCATENATED MODULE: ./src/public/shared/UrlBuilder.ts
1353
+ function UrlBuilder_typeof(obj) { "@babel/helpers - typeof"; return UrlBuilder_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; }, UrlBuilder_typeof(obj); }
1354
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
1355
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
1356
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0) { ; } } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
1357
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
1358
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
1359
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
1360
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
1361
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
1362
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
1363
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
1364
+ function UrlBuilder_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1365
+ function UrlBuilder_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, UrlBuilder_toPropertyKey(descriptor.key), descriptor); } }
1366
+ function UrlBuilder_createClass(Constructor, protoProps, staticProps) { if (protoProps) UrlBuilder_defineProperties(Constructor.prototype, protoProps); if (staticProps) UrlBuilder_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
1367
+ function UrlBuilder_toPropertyKey(arg) { var key = UrlBuilder_toPrimitive(arg, "string"); return UrlBuilder_typeof(key) === "symbol" ? key : String(key); }
1368
+ function UrlBuilder_toPrimitive(input, hint) { if (UrlBuilder_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (UrlBuilder_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
1369
+
1370
+
1371
+ var UrlBuilder = /*#__PURE__*/function () {
1372
+ function UrlBuilder(config) {
1373
+ UrlBuilder_classCallCheck(this, UrlBuilder);
1374
+ var _a;
1375
+ this.cdnUrl = (_a = config === null || config === void 0 ? void 0 : config.cdnUrl) !== null && _a !== void 0 ? _a : BytescaleApiClientConfigResolver.defaultCdnUrl;
1446
1376
  }
1447
- NodeUtils_createClass(NodeUtils, null, [{
1448
- key: "createStream",
1449
- value: function createStream() {
1450
- try {
1451
- return NodeUtils_await(Promise.resolve(/* import() */).then(__lib_require__.t.bind(__lib_require__, "stream", 23)), function (_import) {
1452
- var streamModule = _import["default"];
1453
- var Readable = streamModule.Readable;
1454
- var readable = new Readable();
1455
- readable._read = function () {}; // _read is required but you can noop it
1456
- return readable;
1377
+ /**
1378
+ * Builds a URL to either a raw file or a transformed file.
1379
+ *
1380
+ * Example 1) Raw file:
1381
+ *
1382
+ * new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg" })
1383
+ *
1384
+ * Example 2) Image resized to 500x500:
1385
+ *
1386
+ * new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", transformation: { type: "image", params: { w: 500, h: 500, fit: "crop" } } })
1387
+ *
1388
+ * Example 3) Image resized to 500x500, which is privately accessible (i.e. requires 'AuthManager.beginAuthSession' before it can be accessed):
1389
+ *
1390
+ * new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", transformation: { type: "image", params: { w: 500, h: 500, fit: "crop" } }, auth: true })
1391
+ */
1392
+ UrlBuilder_createClass(UrlBuilder, [{
1393
+ key: "url",
1394
+ value: function url(params) {
1395
+ var _a;
1396
+ return ((_a = params.options) === null || _a === void 0 ? void 0 : _a.transformation) === undefined ? this.raw(params) : this.transformation(params, params.options.transformation);
1397
+ }
1398
+ }, {
1399
+ key: "raw",
1400
+ value: function raw(params) {
1401
+ var _a;
1402
+ var baseUrl = this.getBaseUrl(params, "raw");
1403
+ var commonParams = this.getCommonQueryParams((_a = params.options) !== null && _a !== void 0 ? _a : {});
1404
+ return this.addQueryParams(baseUrl, commonParams);
1405
+ }
1406
+ }, {
1407
+ key: "transformation",
1408
+ value: function transformation(params, trans) {
1409
+ var _a;
1410
+ var baseUrl = this.getBaseUrl(params, trans.type === "preset" ? trans.preset : trans.type);
1411
+ var transParams = this.getTransformationParams(trans, {
1412
+ cachePermanently: "cache_perm"
1413
+ });
1414
+ var commonParams = this.getCommonQueryParams((_a = params.options) !== null && _a !== void 0 ? _a : {});
1415
+ return this.addQueryParams(baseUrl, [].concat(_toConsumableArray(commonParams), _toConsumableArray(transParams)));
1416
+ }
1417
+ }, {
1418
+ key: "getBaseUrl",
1419
+ value: function getBaseUrl(params, prefix) {
1420
+ return "".concat(this.cdnUrl, "/").concat(params.accountId, "/").concat(prefix).concat(params.filePath);
1421
+ }
1422
+ }, {
1423
+ key: "getCommonQueryParams",
1424
+ value: function getCommonQueryParams(params) {
1425
+ return this.makeQueryParams(["auth", "cache", "cacheTtl", "version", "forceDownloadPrompt"], {
1426
+ cacheTtl: "cache_ttl",
1427
+ forceDownloadPrompt: "download"
1428
+ })(params);
1429
+ }
1430
+ }, {
1431
+ key: "makeQueryParams",
1432
+ value: function makeQueryParams(keys, keyOverrides) {
1433
+ return function (data) {
1434
+ var result = [];
1435
+ keys.forEach(function (key) {
1436
+ var _a;
1437
+ var value = data[key];
1438
+ if (value !== undefined) {
1439
+ result.push([(_a = keyOverrides[key]) !== null && _a !== void 0 ? _a : key, value.toString()]);
1440
+ }
1457
1441
  });
1458
- } catch (e) {
1459
- return Promise.reject(e);
1460
- }
1442
+ return result;
1443
+ };
1461
1444
  }
1462
1445
  }, {
1463
- key: "createBlob",
1464
- value: function createBlob(sources, options) {
1465
- try {
1466
- return NodeUtils_await(Promise.resolve(/* import() */).then(__lib_require__.t.bind(__lib_require__, "buffer", 23)), function (_import2) {
1467
- var bufferModule = _import2["default"];
1468
- var B = bufferModule.Blob;
1469
- return new B(sources, options);
1446
+ key: "getTransformationParams",
1447
+ value: function getTransformationParams(trans, keyRewrites) {
1448
+ if (trans.params === undefined) {
1449
+ return [];
1450
+ }
1451
+ var serializeObj = function serializeObj(obj) {
1452
+ return Object.entries(obj).filter(isDefinedEntry).map(function (_ref) {
1453
+ var _ref2 = _slicedToArray(_ref, 2),
1454
+ key = _ref2[0],
1455
+ value = _ref2[1];
1456
+ var _a;
1457
+ return [(_a = keyRewrites[key]) !== null && _a !== void 0 ? _a : key, value.toString()];
1470
1458
  });
1471
- } catch (e) {
1472
- return Promise.reject(e);
1473
- }
1459
+ };
1460
+ return Array.isArray(trans.params) ? trans.params.flatMap(serializeObj) : serializeObj(trans.params);
1461
+ }
1462
+ }, {
1463
+ key: "addQueryParams",
1464
+ value: function addQueryParams(baseUrl, params) {
1465
+ if (params.length === 0) {
1466
+ return baseUrl;
1467
+ }
1468
+ return "".concat(baseUrl, "?").concat(params.map(function (_ref3) {
1469
+ var _ref4 = _slicedToArray(_ref3, 2),
1470
+ key = _ref4[0],
1471
+ value = _ref4[1];
1472
+ return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(value));
1473
+ }).join("&"));
1474
1474
  }
1475
1475
  }]);
1476
- return NodeUtils;
1476
+ return UrlBuilder;
1477
1477
  }();
1478
- ;// CONCATENATED MODULE: ./src/uploads/ChunkedStream.ts
1479
- function ChunkedStream_typeof(obj) { "@babel/helpers - typeof"; return ChunkedStream_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; }, ChunkedStream_typeof(obj); }
1480
- function ChunkedStream_invoke(body, then) {
1478
+ ;// CONCATENATED MODULE: ./src/public/shared/UrlBuilderTypes.ts
1479
+ /**
1480
+ * Workaround for tsc aliases, where we cannot export implementation-less modules in our dists.
1481
+ */
1482
+ var UrlBuilderTypesNoOp = false;
1483
+ ;// CONCATENATED MODULE: ./src/public/shared/index.ts
1484
+
1485
+
1486
+
1487
+
1488
+ ;// CONCATENATED MODULE: ./src/private/UploadManagerBase.ts
1489
+ function UploadManagerBase_typeof(obj) { "@babel/helpers - typeof"; return UploadManagerBase_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; }, UploadManagerBase_typeof(obj); }
1490
+ function _async(f) {
1491
+ return function () {
1492
+ for (var args = [], i = 0; i < arguments.length; i++) {
1493
+ args[i] = arguments[i];
1494
+ }
1495
+ try {
1496
+ return Promise.resolve(f.apply(this, args));
1497
+ } catch (e) {
1498
+ return Promise.reject(e);
1499
+ }
1500
+ };
1501
+ }
1502
+ function _invokeIgnored(body) {
1481
1503
  var result = body();
1482
1504
  if (result && result.then) {
1483
- return result.then(then);
1484
- }
1485
- return then(result);
1486
- }
1487
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
1488
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
1489
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
1490
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
1491
- function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0) { ; } } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
1492
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
1493
- function ChunkedStream_await(value, then, direct) {
1494
- if (direct) {
1495
- return then ? then(value) : value;
1496
- }
1497
- if (!value || !value.then) {
1498
- value = Promise.resolve(value);
1505
+ return result.then(UploadManagerBase_empty);
1499
1506
  }
1500
- return then ? value.then(then) : value;
1501
1507
  }
1502
- function ChunkedStream_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1503
- function ChunkedStream_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, ChunkedStream_toPropertyKey(descriptor.key), descriptor); } }
1504
- function ChunkedStream_createClass(Constructor, protoProps, staticProps) { if (protoProps) ChunkedStream_defineProperties(Constructor.prototype, protoProps); if (staticProps) ChunkedStream_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
1505
- function ChunkedStream_toPropertyKey(arg) { var key = ChunkedStream_toPrimitive(arg, "string"); return ChunkedStream_typeof(key) === "symbol" ? key : String(key); }
1506
- function ChunkedStream_toPrimitive(input, hint) { if (ChunkedStream_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (ChunkedStream_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
1507
-
1508
- var ChunkedStream = /*#__PURE__*/function () {
1509
- function ChunkedStream(source) {
1510
- ChunkedStream_classCallCheck(this, ChunkedStream);
1511
- this.source = source;
1512
- this.buffer = Buffer.alloc(0);
1513
- this.isSourceFullyConsumed = false; // true if the source stream indicates it has finished.
1514
- this.isFinishedConsuming = false; // true if _we_ indicate we have finished reading all we want from the stream.
1515
- this.resolver = undefined;
1516
- }
1517
- /**
1518
- * If the source stream is larger than the 'size' the user is consuming (i.e. they're only wanting to upload a subset
1519
- * of the stream) then the stream won't be resolved by the 'end' event inside 'runChunkPipeline', so calling this
1520
- * method is necessary.
1521
- */
1522
- ChunkedStream_createClass(ChunkedStream, [{
1523
- key: "finishedConsuming",
1524
- value: function finishedConsuming() {
1525
- this.isFinishedConsuming = true;
1526
- if (this.resolver !== undefined) {
1527
- this.resolver();
1528
- }
1529
- }
1530
- /**
1531
- * Promise resolves when the entire stream has finished processing, or an error occurs.
1532
- * You must call 'take' a sufficient number of times after calling this method in order for this promise to resolve.
1533
- */
1534
- }, {
1535
- key: "runChunkPipeline",
1536
- value: function runChunkPipeline() {
1537
- try {
1538
- var _this2 = this;
1539
- return ChunkedStream_await(new Promise(function (resolve, reject) {
1540
- _this2.resolver = resolve;
1541
- var onError = function onError(error) {
1542
- removeListeners();
1543
- reject(error);
1544
- };
1545
- var onEnd = function onEnd() {
1546
- _this2.isSourceFullyConsumed = true;
1547
- removeListeners();
1548
- resolve();
1549
- };
1550
- var onData = function onData(buffer) {
1551
- try {
1552
- if (_this2.isFinishedConsuming) {
1553
- return;
1554
- }
1555
- if (_this2.consumer === undefined) {
1556
- console.warn("Stream yielded data while paused. The data will be buffered, but excessive buffering can cause memory issues.");
1557
- _this2.buffer = Buffer.concat([_this2.buffer, buffer]);
1558
- return;
1559
- }
1560
- if (_this2.consumer.bytesRemaining <= 0) {
1561
- throw new Error("Consumer requires zero bytes, so should not be consuming from the stream.");
1562
- }
1563
- if (_this2.buffer.byteLength > 0) {
1564
- throw new Error("Buffer was expected to be empty (as it should have been flushed to the consumer when '.take' was called).");
1565
- }
1566
- var splitResult = _this2.splitBuffer(buffer, _this2.consumer.bytesRemaining);
1567
- if (splitResult === undefined) {
1568
- return; // Received empty data.
1569
- }
1570
-
1571
- var _splitResult = _slicedToArray(splitResult, 2),
1572
- consumed = _splitResult[0],
1573
- remaining = _splitResult[1];
1574
- _this2.buffer = remaining;
1575
- _this2.consumer.bytesRemaining -= consumed.byteLength;
1576
- _this2.consumer.stream.push(consumed);
1577
- if (_this2.consumer.bytesRemaining === 0) {
1578
- _this2.finishStream(_this2.consumer.stream);
1579
- _this2.consumer = undefined;
1580
- _this2.source.pause();
1581
- }
1582
- } catch (e) {
1583
- removeListeners();
1584
- reject(e);
1585
- }
1586
- };
1587
- var removeListeners = function removeListeners() {
1588
- _this2.source.removeListener("data", onData);
1589
- _this2.source.removeListener("error", onError);
1590
- _this2.source.removeListener("end", onEnd);
1591
- };
1592
- _this2.source.on("data", onData);
1593
- _this2.source.on("error", onError);
1594
- _this2.source.on("end", onEnd);
1595
- _this2.source.pause(); // Resumed when 'take' is called.
1596
- }));
1597
- } catch (e) {
1598
- return Promise.reject(e);
1599
- }
1600
- }
1601
- /**
1602
- * Only call 'take' after the previously returned stream has been fully consumed.
1603
- */
1604
- }, {
1605
- key: "take",
1606
- value: function take(bytes) {
1607
- try {
1608
- var _exit2 = false;
1609
- var _this4 = this;
1610
- var _a;
1611
- if (_this4.consumer !== undefined) {
1612
- throw new Error("The stream from the previous 'take' call must be fully consumed before calling 'take' again.");
1613
- }
1614
- return ChunkedStream_invoke(function () {
1615
- if (bytes <= 0) {
1616
- _exit2 = true;
1617
- return ChunkedStream_await(_this4.emptyStream());
1618
- }
1619
- }, function (_result) {
1620
- return _exit2 ? _result : ChunkedStream_await(NodeUtils.createStream(), function (readable) {
1621
- var consumedFromBuffer = _this4.consumeFromBuffer(bytes);
1622
- var consumedFromBufferLength = (_a = consumedFromBuffer === null || consumedFromBuffer === void 0 ? void 0 : consumedFromBuffer.length) !== null && _a !== void 0 ? _a : 0;
1623
- var bytesToConsumeFromStream = bytes - consumedFromBufferLength;
1624
- if (consumedFromBuffer !== undefined) {
1625
- readable.push(consumedFromBuffer);
1626
- }
1627
- if (bytesToConsumeFromStream > 0) {
1628
- if (_this4.isSourceFullyConsumed) {
1629
- throw new Error("Stream finished processing earlier than expected. The \"size\" parameter is likely larger than the stream's actual contents.");
1630
- }
1631
- _this4.consumer = {
1632
- bytesRemaining: bytesToConsumeFromStream,
1633
- stream: readable
1634
- };
1635
- _this4.source.resume();
1636
- } else {
1637
- _this4.finishStream(readable);
1638
- }
1639
- return readable;
1640
- });
1641
- });
1642
- } catch (e) {
1643
- return Promise.reject(e);
1644
- }
1645
- }
1646
- }, {
1647
- key: "consumeFromBuffer",
1648
- value: function consumeFromBuffer(bytes) {
1649
- var splitResult = this.splitBuffer(this.buffer, bytes);
1650
- if (splitResult === undefined) {
1651
- return undefined;
1652
- }
1653
- var _splitResult2 = _slicedToArray(splitResult, 2),
1654
- consumed = _splitResult2[0],
1655
- remaining = _splitResult2[1];
1656
- this.buffer = remaining;
1657
- return consumed;
1658
- }
1659
- }, {
1660
- key: "splitBuffer",
1661
- value: function splitBuffer(buffer, maxBytes) {
1662
- if (buffer.byteLength === 0) {
1663
- return undefined;
1664
- }
1665
- var bytesToConsume = Math.min(maxBytes, buffer.byteLength);
1666
- if (bytesToConsume === buffer.byteLength) {
1667
- return [buffer, Buffer.alloc(0)]; // Optimization
1668
- }
1669
-
1670
- var consumed = buffer.subarray(0, bytesToConsume);
1671
- var remaining = buffer.subarray(bytesToConsume);
1672
- return [consumed, remaining];
1673
- }
1674
- }, {
1675
- key: "emptyStream",
1676
- value: function emptyStream() {
1677
- try {
1678
- var _this6 = this;
1679
- return ChunkedStream_await(NodeUtils.createStream(), function (readable) {
1680
- _this6.finishStream(readable);
1681
- return readable;
1682
- });
1683
- } catch (e) {
1684
- return Promise.reject(e);
1685
- }
1686
- }
1687
- }, {
1688
- key: "finishStream",
1689
- value: function finishStream(readable) {
1690
- readable.push(null);
1691
- }
1692
- }]);
1693
- return ChunkedStream;
1694
- }();
1695
- ;// CONCATENATED MODULE: ./src/uploads/UploadModel.ts
1696
- function UploadModel_typeof(obj) { "@babel/helpers - typeof"; return UploadModel_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; }, UploadModel_typeof(obj); }
1697
- function UploadModel_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, UploadModel_toPropertyKey(descriptor.key), descriptor); } }
1698
- function UploadModel_createClass(Constructor, protoProps, staticProps) { if (protoProps) UploadModel_defineProperties(Constructor.prototype, protoProps); if (staticProps) UploadModel_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
1699
- function UploadModel_toPropertyKey(arg) { var key = UploadModel_toPrimitive(arg, "string"); return UploadModel_typeof(key) === "symbol" ? key : String(key); }
1700
- function UploadModel_toPrimitive(input, hint) { if (UploadModel_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (UploadModel_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
1701
- function UploadModel_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1702
- function UploadModel_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) UploadModel_setPrototypeOf(subClass, superClass); }
1703
- function UploadModel_createSuper(Derived) { var hasNativeReflectConstruct = UploadModel_isNativeReflectConstruct(); return function _createSuperInternal() { var Super = UploadModel_getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = UploadModel_getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return UploadModel_possibleConstructorReturn(this, result); }; }
1704
- function UploadModel_possibleConstructorReturn(self, call) { if (call && (UploadModel_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 UploadModel_assertThisInitialized(self); }
1705
- function UploadModel_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
1706
- function UploadModel_wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; UploadModel_wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !UploadModel_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return UploadModel_construct(Class, arguments, UploadModel_getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return UploadModel_setPrototypeOf(Wrapper, Class); }; return UploadModel_wrapNativeSuper(Class); }
1707
- function UploadModel_construct(Parent, args, Class) { if (UploadModel_isNativeReflectConstruct()) { UploadModel_construct = Reflect.construct.bind(); } else { UploadModel_construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) UploadModel_setPrototypeOf(instance, Class.prototype); return instance; }; } return UploadModel_construct.apply(null, arguments); }
1708
- function UploadModel_isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
1709
- function UploadModel_isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
1710
- function UploadModel_setPrototypeOf(o, p) { UploadModel_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return UploadModel_setPrototypeOf(o, p); }
1711
- function UploadModel_getPrototypeOf(o) { UploadModel_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return UploadModel_getPrototypeOf(o); }
1712
- var CancelledError = /*#__PURE__*/function (_Error) {
1713
- UploadModel_inherits(CancelledError, _Error);
1714
- var _super = UploadModel_createSuper(CancelledError);
1715
- function CancelledError(msg) {
1716
- var _this;
1717
- UploadModel_classCallCheck(this, CancelledError);
1718
- _this = _super.call(this, msg);
1719
- _this.msg = msg;
1720
- _this.name = "CancelledError";
1721
- return _this;
1722
- }
1723
- return UploadModel_createClass(CancelledError);
1724
- }( /*#__PURE__*/UploadModel_wrapNativeSuper(Error));
1725
- ;// CONCATENATED MODULE: ./src/uploads/UploadManager.ts
1726
- function UploadManager_typeof(obj) { "@babel/helpers - typeof"; return UploadManager_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; }, UploadManager_typeof(obj); }
1727
- function UploadManager_async(f) {
1728
- return function () {
1729
- for (var args = [], i = 0; i < arguments.length; i++) {
1730
- args[i] = arguments[i];
1731
- }
1732
- try {
1733
- return Promise.resolve(f.apply(this, args));
1734
- } catch (e) {
1735
- return Promise.reject(e);
1736
- }
1737
- };
1738
- }
1739
- function UploadManager_empty() {}
1740
- function _awaitIgnored(value, direct) {
1741
- if (!direct) {
1742
- return value && value.then ? value.then(UploadManager_empty) : Promise.resolve();
1743
- }
1744
- }
1745
- function UploadManager_invoke(body, then) {
1746
- var result = body();
1747
- if (result && result.then) {
1748
- return result.then(then);
1749
- }
1750
- return then(result);
1751
- }
1752
- function _invokeIgnored(body) {
1753
- var result = body();
1754
- if (result && result.then) {
1755
- return result.then(UploadManager_empty);
1756
- }
1757
- }
1758
- function _settle(pact, state, value) {
1759
- if (!pact.s) {
1760
- if (value instanceof _Pact) {
1761
- if (value.s) {
1762
- if (state & 1) {
1763
- state = value.s;
1764
- }
1765
- value = value.v;
1766
- } else {
1767
- value.o = _settle.bind(null, pact, state);
1768
- return;
1508
+ function _settle(pact, state, value) {
1509
+ if (!pact.s) {
1510
+ if (value instanceof _Pact) {
1511
+ if (value.s) {
1512
+ if (state & 1) {
1513
+ state = value.s;
1514
+ }
1515
+ value = value.v;
1516
+ } else {
1517
+ value.o = _settle.bind(null, pact, state);
1518
+ return;
1769
1519
  }
1770
1520
  }
1771
1521
  if (value && value.then) {
@@ -1906,16 +1656,22 @@ function _for(test, update, body) {
1906
1656
  }
1907
1657
  function _continueIgnored(value) {
1908
1658
  if (value && value.then) {
1909
- return value.then(UploadManager_empty);
1659
+ return value.then(UploadManagerBase_empty);
1910
1660
  }
1911
1661
  }
1912
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || UploadManager_unsupportedIterableToArray(arr) || _nonIterableSpread(); }
1913
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
1914
- function UploadManager_unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return UploadManager_arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return UploadManager_arrayLikeToArray(o, minLen); }
1915
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
1916
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return UploadManager_arrayLikeToArray(arr); }
1917
- function UploadManager_arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
1918
- function UploadManager_await(value, then, direct) {
1662
+ function UploadManagerBase_toConsumableArray(arr) { return UploadManagerBase_arrayWithoutHoles(arr) || UploadManagerBase_iterableToArray(arr) || UploadManagerBase_unsupportedIterableToArray(arr) || UploadManagerBase_nonIterableSpread(); }
1663
+ function UploadManagerBase_nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
1664
+ function UploadManagerBase_unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return UploadManagerBase_arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return UploadManagerBase_arrayLikeToArray(o, minLen); }
1665
+ function UploadManagerBase_iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
1666
+ function UploadManagerBase_arrayWithoutHoles(arr) { if (Array.isArray(arr)) return UploadManagerBase_arrayLikeToArray(arr); }
1667
+ function UploadManagerBase_arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
1668
+ function UploadManagerBase_empty() {}
1669
+ function _awaitIgnored(value, direct) {
1670
+ if (!direct) {
1671
+ return value && value.then ? value.then(UploadManagerBase_empty) : Promise.resolve();
1672
+ }
1673
+ }
1674
+ function UploadManagerBase_await(value, then, direct) {
1919
1675
  if (direct) {
1920
1676
  return then ? then(value) : value;
1921
1677
  }
@@ -1924,46 +1680,72 @@ function UploadManager_await(value, then, direct) {
1924
1680
  }
1925
1681
  return then ? value.then(then) : value;
1926
1682
  }
1927
- function UploadManager_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1928
- function UploadManager_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, UploadManager_toPropertyKey(descriptor.key), descriptor); } }
1929
- function UploadManager_createClass(Constructor, protoProps, staticProps) { if (protoProps) UploadManager_defineProperties(Constructor.prototype, protoProps); if (staticProps) UploadManager_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
1930
- function UploadManager_toPropertyKey(arg) { var key = UploadManager_toPrimitive(arg, "string"); return UploadManager_typeof(key) === "symbol" ? key : String(key); }
1931
- function UploadManager_toPrimitive(input, hint) { if (UploadManager_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (UploadManager_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
1932
-
1933
-
1934
-
1683
+ function _rethrow(thrown, value) {
1684
+ if (thrown) throw value;
1685
+ return value;
1686
+ }
1687
+ function _finallyRethrows(body, finalizer) {
1688
+ try {
1689
+ var result = body();
1690
+ } catch (e) {
1691
+ return finalizer(true, e);
1692
+ }
1693
+ if (result && result.then) {
1694
+ return result.then(finalizer.bind(null, false), finalizer.bind(null, true));
1695
+ }
1696
+ return finalizer(false, result);
1697
+ }
1698
+ function UploadManagerBase_continue(value, then) {
1699
+ return value && value.then ? value.then(then) : then(value);
1700
+ }
1701
+ function UploadManagerBase_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1702
+ function UploadManagerBase_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, UploadManagerBase_toPropertyKey(descriptor.key), descriptor); } }
1703
+ function UploadManagerBase_createClass(Constructor, protoProps, staticProps) { if (protoProps) UploadManagerBase_defineProperties(Constructor.prototype, protoProps); if (staticProps) UploadManagerBase_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
1704
+ function UploadManagerBase_toPropertyKey(arg) { var key = UploadManagerBase_toPrimitive(arg, "string"); return UploadManagerBase_typeof(key) === "symbol" ? key : String(key); }
1705
+ function UploadManagerBase_toPrimitive(input, hint) { if (UploadManagerBase_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (UploadManagerBase_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
1935
1706
 
1936
- var UploadManager = /*#__PURE__*/function () {
1937
- function UploadManager(config) {
1938
- UploadManager_classCallCheck(this, UploadManager);
1707
+ /**
1708
+ * Methods common to UploadManagerNode and UploadManagerBrowser.
1709
+ */
1710
+ var UploadManagerBase = /*#__PURE__*/function () {
1711
+ function UploadManagerBase(config) {
1712
+ UploadManagerBase_classCallCheck(this, UploadManagerBase);
1939
1713
  this.config = config;
1940
1714
  this.stringMimeType = "text/plain";
1941
1715
  this.defaultMaxConcurrentUploadParts = 4;
1716
+ this.intervalMs = 500;
1942
1717
  this.uploadApi = new UploadApi(config);
1943
1718
  }
1944
- UploadManager_createClass(UploadManager, [{
1719
+ UploadManagerBase_createClass(UploadManagerBase, [{
1945
1720
  key: "upload",
1946
1721
  value: function upload(request) {
1947
1722
  try {
1948
1723
  var _this2 = this;
1949
- return UploadManager_await(_this2.processUploadSource(request.data), function (data) {
1950
- var chunkedStream = _this2.getChunkedStream(data);
1951
- return UploadManager_await(_this2.beginUpload(request, data), function (uploadInfo) {
1952
- _this2.checkIfCancelled(request);
1953
- var maxConcurrency = _this2.calculateMaxConcurrency(request, data);
1954
- var partCount = uploadInfo.uploadParts.count;
1955
- var parts = _toConsumableArray(Array(partCount).keys());
1956
- var runSourceStreamPump = chunkedStream === null || chunkedStream === void 0 ? void 0 : chunkedStream.runChunkPipeline();
1957
- return UploadManager_await(_this2.mapAsync(parts, maxConcurrency, UploadManager_async(function (part) {
1958
- return _this2.uploadPart(request, data, part, uploadInfo);
1724
+ _this2.assertNotCancelled(request);
1725
+ var source = _this2.processUploadSource(request.data);
1726
+ var preUploadInfo = _this2.getPreUploadInfo(request, source);
1727
+ var onProgress = _this2.makeProgressCallback(request, preUploadInfo.size);
1728
+ var init = _this2.preUpload(source);
1729
+ // Raise initial progress event SYNCHRONOUSLY.
1730
+ onProgress(0);
1731
+ return UploadManagerBase_await(_this2.beginUpload(request, preUploadInfo), function (uploadInfo) {
1732
+ var partCount = uploadInfo.uploadParts.count;
1733
+ var parts = UploadManagerBase_toConsumableArray(Array(partCount).keys());
1734
+ var _this2$makeCancellati = _this2.makeCancellationMethods(),
1735
+ cancel = _this2$makeCancellati.cancel,
1736
+ addCancellationHandler = _this2$makeCancellati.addCancellationHandler;
1737
+ var intervalHandle = setInterval(_this2.onIntervalTick(request, cancel), _this2.intervalMs);
1738
+ return UploadManagerBase_continue(_finallyRethrows(function () {
1739
+ return UploadManagerBase_await(_this2.mapAsync(parts, preUploadInfo.maxConcurrentUploadParts, _async(function (part) {
1740
+ return _this2.uploadPart(request, source, part, uploadInfo, onProgress, addCancellationHandler);
1959
1741
  })), function () {
1960
- if (chunkedStream !== undefined) {
1961
- chunkedStream.finishedConsuming();
1962
- }
1963
- return UploadManager_await(runSourceStreamPump, function () {
1964
- return uploadInfo.file;
1965
- });
1742
+ return _awaitIgnored(_this2.postUpload(init));
1966
1743
  });
1744
+ }, function (_wasThrown, _result) {
1745
+ clearInterval(intervalHandle);
1746
+ return _rethrow(_wasThrown, _result);
1747
+ }), function () {
1748
+ return uploadInfo.file;
1967
1749
  });
1968
1750
  });
1969
1751
  } catch (e) {
@@ -1971,22 +1753,85 @@ var UploadManager = /*#__PURE__*/function () {
1971
1753
  }
1972
1754
  }
1973
1755
  }, {
1974
- key: "checkIfCancelled",
1975
- value: function checkIfCancelled(request) {
1976
- var _a;
1977
- if (((_a = request.cancellationToken) === null || _a === void 0 ? void 0 : _a.isCancelled) === true) {
1978
- throw new CancelledError("Upload cancelled by user.");
1756
+ key: "getBlobInfo",
1757
+ value: function getBlobInfo(_ref) {
1758
+ var _ref$value = _ref.value,
1759
+ name = _ref$value.name,
1760
+ size = _ref$value.size,
1761
+ type = _ref$value.type;
1762
+ return {
1763
+ mime: type,
1764
+ size: size,
1765
+ originalFileName: name,
1766
+ maxConcurrentUploadParts: undefined
1767
+ };
1768
+ }
1769
+ }, {
1770
+ key: "onIntervalTick",
1771
+ value: function onIntervalTick(request, cancel) {
1772
+ var _this3 = this;
1773
+ return function () {
1774
+ if (_this3.isCancelled(request)) {
1775
+ cancel();
1776
+ }
1777
+ };
1778
+ }
1779
+ }, {
1780
+ key: "makeCancellationMethods",
1781
+ value: function makeCancellationMethods() {
1782
+ var cancellationHandlers = [];
1783
+ var addCancellationHandler = function addCancellationHandler(ca) {
1784
+ cancellationHandlers.push(ca);
1785
+ };
1786
+ var cancel = function cancel() {
1787
+ return cancellationHandlers.forEach(function (x) {
1788
+ return x();
1789
+ });
1790
+ };
1791
+ return {
1792
+ cancel: cancel,
1793
+ addCancellationHandler: addCancellationHandler
1794
+ };
1795
+ }
1796
+ }, {
1797
+ key: "makeProgressCallback",
1798
+ value: function makeProgressCallback(request, bytesTotal) {
1799
+ var onProgress = request.onProgress;
1800
+ if (onProgress === undefined) {
1801
+ return function () {};
1802
+ }
1803
+ var bytesSent = 0;
1804
+ return function (bytesSentDelta) {
1805
+ bytesSent += bytesSentDelta;
1806
+ onProgress({
1807
+ bytesTotal: bytesTotal,
1808
+ bytesSent: bytesSent,
1809
+ progress: Math.round(bytesSent / bytesTotal * 100)
1810
+ });
1811
+ };
1812
+ }
1813
+ }, {
1814
+ key: "assertNotCancelled",
1815
+ value: function assertNotCancelled(request) {
1816
+ if (this.isCancelled(request)) {
1817
+ throw new CancelledError();
1979
1818
  }
1980
1819
  }
1820
+ }, {
1821
+ key: "isCancelled",
1822
+ value: function isCancelled(request) {
1823
+ var _a;
1824
+ return ((_a = request.cancellationToken) === null || _a === void 0 ? void 0 : _a.isCancelled) === true;
1825
+ }
1981
1826
  }, {
1982
1827
  key: "beginUpload",
1983
- value: function beginUpload(request, data) {
1828
+ value: function beginUpload(request, _ref2) {
1829
+ var size = _ref2.size,
1830
+ mime = _ref2.mime,
1831
+ originalFileName = _ref2.originalFileName;
1984
1832
  try {
1985
- var _this4 = this;
1986
- var size = _this4.calculateSize(request, data);
1987
- var mime = _this4.calculateMime(request, data);
1988
- var originalFileName = _this4.calculateOriginalFileName(request, data);
1989
- return UploadManager_await(_this4.uploadApi.beginMultipartUpload({
1833
+ var _this5 = this;
1834
+ return UploadManagerBase_await(_this5.uploadApi.beginMultipartUpload({
1990
1835
  accountId: request.accountId,
1991
1836
  beginMultipartUploadRequest: {
1992
1837
  metadata: request.metadata,
@@ -2004,15 +1849,15 @@ var UploadManager = /*#__PURE__*/function () {
2004
1849
  }
2005
1850
  }, {
2006
1851
  key: "uploadPart",
2007
- value: function uploadPart(request, data, partIndex, uploadInfo) {
1852
+ value: function uploadPart(request, source, partIndex, uploadInfo, onProgress, addCancellationHandler) {
2008
1853
  try {
2009
- var _this6 = this;
2010
- _this6.checkIfCancelled(request);
2011
- return UploadManager_await(_this6.getUploadPart(request, partIndex, uploadInfo), function (part) {
2012
- _this6.checkIfCancelled(request);
2013
- return UploadManager_await(_this6.putUploadPart(part, data), function (etag) {
2014
- _this6.checkIfCancelled(request);
2015
- return _awaitIgnored(_this6.uploadApi.completeUploadPart({
1854
+ var _this7 = this;
1855
+ _this7.assertNotCancelled(request);
1856
+ return UploadManagerBase_await(_this7.getUploadPart(request, partIndex, uploadInfo), function (part) {
1857
+ _this7.assertNotCancelled(request);
1858
+ return UploadManagerBase_await(_this7.putUploadPart(part, source, onProgress, addCancellationHandler), function (etag) {
1859
+ _this7.assertNotCancelled(request);
1860
+ return _awaitIgnored(_this7.uploadApi.completeUploadPart({
2016
1861
  accountId: request.accountId,
2017
1862
  uploadId: uploadInfo.uploadId,
2018
1863
  uploadPartIndex: partIndex,
@@ -2031,407 +1876,766 @@ var UploadManager = /*#__PURE__*/function () {
2031
1876
  */
2032
1877
  }, {
2033
1878
  key: "putUploadPart",
2034
- value: function putUploadPart(part, data) {
1879
+ value: function putUploadPart(part, source, onProgress, addCancellationHandler) {
2035
1880
  try {
2036
- var _this8 = this;
2037
- var _a, _b;
2038
- var fetchApi = (_a = _this8.config.fetchApi) !== null && _a !== void 0 ? _a : fetch;
2039
- var headers = {
2040
- // Required to prevent fetch using "Transfer-Encoding: Chunked" when body is a stream.
2041
- "content-length": (part.range.inclusiveEnd + 1 - part.range.inclusiveStart).toString()
2042
- };
2043
- var _part$uploadUrl2 = part.uploadUrl,
2044
- _coerceRequestBody2 = _this8.coerceRequestBody;
2045
- return UploadManager_await(_this8.makeRequestBody(part, data), function (_this7$makeRequestBod) {
2046
- return UploadManager_await(fetchApi(_part$uploadUrl2, {
2047
- method: "PUT",
2048
- headers: headers,
2049
- body: _coerceRequestBody2.call(_this8, _this7$makeRequestBod)
2050
- }), function (response) {
2051
- var _exit = false;
2052
- var etag = (_b = response.headers.get("etag")) !== null && _b !== void 0 ? _b : undefined;
2053
- return UploadManager_invoke(function () {
2054
- if (Math.floor(response.status / 100) !== 2) {
2055
- return UploadManager_await(response.text(), function (_response$text) {
2056
- console.error("Failed to upload part (".concat(response.status, "). Response from server:\n").concat(_response$text));
2057
- throw new Error("Failed to upload part (".concat(response.status, ")."));
2058
- });
2059
- }
2060
- }, function (_result) {
2061
- if (_exit) return _result;
2062
- if (etag === undefined) {
2063
- throw new Error("No 'etag' response header found in upload part response.");
2064
- }
2065
- return etag;
2066
- });
2067
- });
1881
+ var _this9 = this;
1882
+ var contentLength = part.range.inclusiveEnd + 1 - part.range.inclusiveStart;
1883
+ return UploadManagerBase_await(_this9.doPutUploadPart(part, contentLength, source, onProgress, addCancellationHandler), function (_ref3) {
1884
+ var status = _ref3.status,
1885
+ etag = _ref3.etag;
1886
+ if (Math.floor(status / 100) !== 2) {
1887
+ throw new Error("Failed to upload part (".concat(status, ")."));
1888
+ }
1889
+ if (etag === undefined) {
1890
+ throw new Error("No 'etag' response header found in upload part response.");
1891
+ }
1892
+ return etag;
2068
1893
  });
2069
1894
  } catch (e) {
2070
1895
  return Promise.reject(e);
2071
1896
  }
2072
1897
  }
2073
1898
  }, {
2074
- key: "coerceRequestBody",
2075
- value: function coerceRequestBody(data) {
2076
- return data; // node-fetch supports 'NodeJS.ReadableStream'
2077
- }
2078
- }, {
2079
- key: "makeRequestBody",
2080
- value: function makeRequestBody(part, data) {
1899
+ key: "getUploadPart",
1900
+ value: function getUploadPart(request, partIndex, uploadInfo) {
2081
1901
  try {
2082
- var _this10 = this;
2083
- return UploadManager_await(_this10.sliceDataForRequest(data, part), function (slicedData) {
2084
- var isNodeJs = _this10.isNodeJs();
2085
- // node-fetch requires 'NodeJS.ReadableStream' for the body.
2086
- // browser fetch supports blobs and buffers.
2087
- return UploadManager_await(_this10.foldDataRaw(slicedData, {
2088
- ifBuffer: UploadManager_async(function (buffer) {
2089
- return isNodeJs ? _this10.bufferToStream(buffer) : buffer;
2090
- }),
2091
- ifBlob: UploadManager_async(function (blob) {
2092
- var _bufferToStream = isNodeJs && _this10.bufferToStream;
2093
- return UploadManager_await(isNodeJs ? _this10.blobToBuffer(blob) : blob, function (_this10$blobToBuffer) {
2094
- return UploadManager_await(isNodeJs ? _bufferToStream.call(_this10, _this10$blobToBuffer) : _this10$blobToBuffer, void 0, !isNodeJs);
2095
- }, !isNodeJs);
2096
- }),
2097
- ifNodeJsStream: function (stream) {
2098
- return UploadManager_await(stream);
2099
- }
2100
- }));
2101
- });
1902
+ var _this11 = this;
1903
+ if (partIndex === 0) {
1904
+ return uploadInfo.uploadParts.first;
1905
+ }
1906
+ return UploadManagerBase_await(_this11.uploadApi.getUploadPart({
1907
+ uploadId: uploadInfo.uploadId,
1908
+ accountId: request.accountId,
1909
+ uploadPartIndex: partIndex
1910
+ }));
2102
1911
  } catch (e) {
2103
1912
  return Promise.reject(e);
2104
1913
  }
2105
1914
  }
2106
1915
  }, {
2107
- key: "bufferToStream",
2108
- value: function bufferToStream(buffer) {
1916
+ key: "getPreUploadInfo",
1917
+ value: function getPreUploadInfo(request, source) {
1918
+ var _a, _b, _c;
1919
+ var partial = this.getPreUploadInfoPartial(request, source);
1920
+ return {
1921
+ maxConcurrentUploadParts: (_a = partial.maxConcurrentUploadParts) !== null && _a !== void 0 ? _a : this.defaultMaxConcurrentUploadParts,
1922
+ originalFileName: (_b = request.originalFileName) !== null && _b !== void 0 ? _b : partial.originalFileName,
1923
+ mime: (_c = request.mime) !== null && _c !== void 0 ? _c : partial.mime,
1924
+ size: partial.size
1925
+ };
1926
+ }
1927
+ }, {
1928
+ key: "mapAsync",
1929
+ value: function mapAsync(items, concurrency, callback) {
2109
1930
  try {
2110
- return UploadManager_await(NodeUtils.createStream(), function (readable) {
2111
- readable.push(buffer);
2112
- readable.push(null);
2113
- return readable;
2114
- });
1931
+ var workQueue = UploadManagerBase_toConsumableArray(items);
1932
+ return _awaitIgnored(Promise.all(UploadManagerBase_toConsumableArray(Array(concurrency).keys()).map(_async(function () {
1933
+ return _continueIgnored(_for(function () {
1934
+ return workQueue.length > 0;
1935
+ }, void 0, function () {
1936
+ var work = workQueue.shift(); // IMPORTANT: use 'shift' instead of 'pop' to ensure 'items' are processed in order when 'concurrency = 1'.
1937
+ return _invokeIgnored(function () {
1938
+ if (work !== undefined) {
1939
+ return _awaitIgnored(callback(work));
1940
+ }
1941
+ });
1942
+ }));
1943
+ }))));
2115
1944
  } catch (e) {
2116
1945
  return Promise.reject(e);
2117
1946
  }
2118
1947
  }
2119
- /**
2120
- * Only expected to be called in Node.js environments, and as such, we can assume 'BlobLike' is not a DOM 'File' object.
2121
- */
2122
- }, {
2123
- key: "blobToBuffer",
2124
- value: function blobToBuffer(blob) {
2125
- try {
2126
- var _exit3 = false;
2127
- // DOM Blob and Node.js Blob both have 'arrayBuffer' with the same signature...
2128
- return UploadManager_invoke(function () {
2129
- if (blob.arrayBuffer !== undefined) {
2130
- _exit3 = true;
2131
- var _Buffer2 = Buffer,
2132
- _from2 = _Buffer2.from;
2133
- return UploadManager_await(blob.arrayBuffer(), function (_blob$arrayBuffer) {
2134
- return _from2.call(_Buffer2, _blob$arrayBuffer);
2135
- });
2136
- }
2137
- }, function (_result2) {
2138
- if (_exit3) return _result2;
2139
- throw new Error("The provided 'data' field was treated as a BLOB, but it does not have an 'arrayBuffer' method.");
2140
- });
2141
- } catch (e) {
2142
- return Promise.reject(e);
1948
+ }]);
1949
+ return UploadManagerBase;
1950
+ }();
1951
+ ;// CONCATENATED MODULE: external "stream"
1952
+ var external_stream_namespaceObject = require("stream");
1953
+ ;// CONCATENATED MODULE: ./src/private/StreamUtils.ts
1954
+ function StreamUtils_typeof(obj) { "@babel/helpers - typeof"; return StreamUtils_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; }, StreamUtils_typeof(obj); }
1955
+ function StreamUtils_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1956
+ function StreamUtils_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, StreamUtils_toPropertyKey(descriptor.key), descriptor); } }
1957
+ function StreamUtils_createClass(Constructor, protoProps, staticProps) { if (protoProps) StreamUtils_defineProperties(Constructor.prototype, protoProps); if (staticProps) StreamUtils_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
1958
+ function StreamUtils_toPropertyKey(arg) { var key = StreamUtils_toPrimitive(arg, "string"); return StreamUtils_typeof(key) === "symbol" ? key : String(key); }
1959
+ function StreamUtils_toPrimitive(input, hint) { if (StreamUtils_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (StreamUtils_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
1960
+
1961
+ var StreamUtils = /*#__PURE__*/function () {
1962
+ function StreamUtils() {
1963
+ StreamUtils_classCallCheck(this, StreamUtils);
1964
+ }
1965
+ StreamUtils_createClass(StreamUtils, null, [{
1966
+ key: "create",
1967
+ value: function create() {
1968
+ var readable = new external_stream_namespaceObject.Readable();
1969
+ readable._read = function () {}; // _read is required but you can noop it
1970
+ return readable;
1971
+ }
1972
+ }, {
1973
+ key: "empty",
1974
+ value: function empty() {
1975
+ var readable = StreamUtils.create();
1976
+ StreamUtils.endStream(readable);
1977
+ return readable;
1978
+ }
1979
+ }, {
1980
+ key: "fromBuffer",
1981
+ value: function fromBuffer(buffer) {
1982
+ var readable = StreamUtils.create();
1983
+ readable.push(buffer);
1984
+ StreamUtils.endStream(readable);
1985
+ return readable;
1986
+ }
1987
+ }, {
1988
+ key: "endStream",
1989
+ value: function endStream(readable) {
1990
+ readable.push(null);
1991
+ }
1992
+ }]);
1993
+ return StreamUtils;
1994
+ }();
1995
+ ;// CONCATENATED MODULE: ./src/private/NodeChunkedStream.ts
1996
+ function NodeChunkedStream_typeof(obj) { "@babel/helpers - typeof"; return NodeChunkedStream_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; }, NodeChunkedStream_typeof(obj); }
1997
+ function NodeChunkedStream_slicedToArray(arr, i) { return NodeChunkedStream_arrayWithHoles(arr) || NodeChunkedStream_iterableToArrayLimit(arr, i) || NodeChunkedStream_unsupportedIterableToArray(arr, i) || NodeChunkedStream_nonIterableRest(); }
1998
+ function NodeChunkedStream_nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
1999
+ function NodeChunkedStream_unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return NodeChunkedStream_arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return NodeChunkedStream_arrayLikeToArray(o, minLen); }
2000
+ function NodeChunkedStream_arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
2001
+ function NodeChunkedStream_iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0) { ; } } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
2002
+ function NodeChunkedStream_arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
2003
+ function NodeChunkedStream_await(value, then, direct) {
2004
+ if (direct) {
2005
+ return then ? then(value) : value;
2006
+ }
2007
+ if (!value || !value.then) {
2008
+ value = Promise.resolve(value);
2009
+ }
2010
+ return then ? value.then(then) : value;
2011
+ }
2012
+ function NodeChunkedStream_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2013
+ function NodeChunkedStream_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, NodeChunkedStream_toPropertyKey(descriptor.key), descriptor); } }
2014
+ function NodeChunkedStream_createClass(Constructor, protoProps, staticProps) { if (protoProps) NodeChunkedStream_defineProperties(Constructor.prototype, protoProps); if (staticProps) NodeChunkedStream_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
2015
+ function NodeChunkedStream_toPropertyKey(arg) { var key = NodeChunkedStream_toPrimitive(arg, "string"); return NodeChunkedStream_typeof(key) === "symbol" ? key : String(key); }
2016
+ function NodeChunkedStream_toPrimitive(input, hint) { if (NodeChunkedStream_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (NodeChunkedStream_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
2017
+
2018
+ /**
2019
+ * For Node.js streams only:
2020
+ *
2021
+ * Converts a stream into a stream of streams, where the next stream is requested via '.take(sizeInBytes: number): Stream'
2022
+ *
2023
+ * This allows the source stream to be sequentially read (in serial) as a sequence of sub-streams, for the purpose of
2024
+ * issuing PutObject requests for a multipart upload, whereby each request requires its own stream, but where that stream
2025
+ * needs to be a slice of the source stream.
2026
+ */
2027
+ var NodeChunkedStream = /*#__PURE__*/function () {
2028
+ function NodeChunkedStream(source) {
2029
+ NodeChunkedStream_classCallCheck(this, NodeChunkedStream);
2030
+ this.source = source;
2031
+ this.buffer = Buffer.alloc(0);
2032
+ this.isSourceFullyConsumed = false; // true if the source stream indicates it has finished.
2033
+ this.isFinishedConsuming = false; // true if _we_ indicate we have finished reading all we want from the stream.
2034
+ this.resolver = undefined;
2035
+ }
2036
+ /**
2037
+ * If the source stream is larger than the 'size' the user is consuming (i.e. they're only wanting to upload a subset
2038
+ * of the stream) then the stream won't be resolved by the 'end' event inside 'runChunkPipeline', so calling this
2039
+ * method is necessary.
2040
+ */
2041
+ NodeChunkedStream_createClass(NodeChunkedStream, [{
2042
+ key: "finishedConsuming",
2043
+ value: function finishedConsuming() {
2044
+ this.isFinishedConsuming = true;
2045
+ if (this.resolver !== undefined) {
2046
+ this.resolver();
2143
2047
  }
2144
2048
  }
2049
+ /**
2050
+ * Promise resolves when the entire stream has finished processing, or an error occurs.
2051
+ * You must call 'take' a sufficient number of times after calling this method in order for this promise to resolve.
2052
+ */
2145
2053
  }, {
2146
- key: "sliceDataForRequest",
2147
- value: function sliceDataForRequest(data, part) {
2054
+ key: "runChunkPipeline",
2055
+ value: function runChunkPipeline() {
2148
2056
  try {
2149
- var _this12 = this;
2150
- if (part.range.inclusiveEnd === -1) {
2151
- return "";
2152
- }
2153
- var start = part.range.inclusiveStart;
2154
- var endExclusive = part.range.inclusiveEnd + 1;
2155
- var partSize = endExclusive - start;
2156
- return UploadManager_await(_this12.foldData(data, {
2157
- ifBlob: UploadManager_async(function (blob) {
2158
- return blob.slice(start, endExclusive);
2159
- }),
2160
- ifBuffer: UploadManager_async(function (buffer) {
2161
- return buffer.subarray(start, endExclusive);
2162
- }),
2163
- ifNodeJsStream: UploadManager_async(function (stream) {
2164
- return stream.take(partSize);
2165
- }) // Assumes stream is read using one worker (which it is).
2057
+ var _this2 = this;
2058
+ return NodeChunkedStream_await(new Promise(function (resolve, reject) {
2059
+ _this2.resolver = resolve;
2060
+ var onError = function onError(error) {
2061
+ removeListeners();
2062
+ reject(error);
2063
+ };
2064
+ var onEnd = function onEnd() {
2065
+ _this2.isSourceFullyConsumed = true;
2066
+ removeListeners();
2067
+ resolve();
2068
+ };
2069
+ var onData = function onData(buffer) {
2070
+ try {
2071
+ if (_this2.isFinishedConsuming) {
2072
+ return;
2073
+ }
2074
+ if (_this2.consumer === undefined) {
2075
+ console.warn("Stream yielded data while paused. The data will be buffered, but excessive buffering can cause memory issues.");
2076
+ _this2.buffer = Buffer.concat([_this2.buffer, buffer]);
2077
+ return;
2078
+ }
2079
+ if (_this2.consumer.bytesRemaining <= 0) {
2080
+ throw new Error("Consumer requires zero bytes, so should not be consuming from the stream.");
2081
+ }
2082
+ if (_this2.buffer.byteLength > 0) {
2083
+ throw new Error("Buffer was expected to be empty (as it should have been flushed to the consumer when '.take' was called).");
2084
+ }
2085
+ var splitResult = _this2.splitBuffer(buffer, _this2.consumer.bytesRemaining);
2086
+ if (splitResult === undefined) {
2087
+ return; // Received empty data.
2088
+ }
2089
+
2090
+ var _splitResult = NodeChunkedStream_slicedToArray(splitResult, 2),
2091
+ consumed = _splitResult[0],
2092
+ remaining = _splitResult[1];
2093
+ _this2.buffer = remaining;
2094
+ _this2.consumer.bytesRemaining -= consumed.byteLength;
2095
+ _this2.consumer.stream.push(consumed);
2096
+ if (_this2.consumer.bytesRemaining === 0) {
2097
+ StreamUtils.endStream(_this2.consumer.stream);
2098
+ _this2.consumer = undefined;
2099
+ _this2.source.pause();
2100
+ }
2101
+ } catch (e) {
2102
+ removeListeners();
2103
+ reject(e);
2104
+ }
2105
+ };
2106
+ var removeListeners = function removeListeners() {
2107
+ _this2.source.removeListener("data", onData);
2108
+ _this2.source.removeListener("error", onError);
2109
+ _this2.source.removeListener("end", onEnd);
2110
+ };
2111
+ _this2.source.on("data", onData);
2112
+ _this2.source.on("error", onError);
2113
+ _this2.source.on("end", onEnd);
2114
+ _this2.source.pause(); // Resumed when 'take' is called.
2166
2115
  }));
2167
2116
  } catch (e) {
2168
2117
  return Promise.reject(e);
2169
2118
  }
2170
2119
  }
2120
+ /**
2121
+ * Only call 'take' after the previously returned stream has been fully consumed.
2122
+ */
2171
2123
  }, {
2172
- key: "isNodeJs",
2173
- value: function isNodeJs() {
2174
- return typeof process !== "undefined" && process.versions !== undefined && process.versions.node !== undefined;
2124
+ key: "take",
2125
+ value: function take(bytes) {
2126
+ var _a;
2127
+ if (this.consumer !== undefined) {
2128
+ throw new Error("The stream from the previous 'take' call must be fully consumed before calling 'take' again.");
2129
+ }
2130
+ if (bytes <= 0) {
2131
+ return StreamUtils.empty();
2132
+ }
2133
+ var readable = StreamUtils.create();
2134
+ var consumedFromBuffer = this.consumeFromBuffer(bytes);
2135
+ var consumedFromBufferLength = (_a = consumedFromBuffer === null || consumedFromBuffer === void 0 ? void 0 : consumedFromBuffer.length) !== null && _a !== void 0 ? _a : 0;
2136
+ var bytesToConsumeFromStream = bytes - consumedFromBufferLength;
2137
+ if (consumedFromBuffer !== undefined) {
2138
+ readable.push(consumedFromBuffer);
2139
+ }
2140
+ if (bytesToConsumeFromStream > 0) {
2141
+ if (this.isSourceFullyConsumed) {
2142
+ throw new Error("Stream finished processing earlier than expected. The \"size\" parameter is likely larger than the stream's actual contents.");
2143
+ }
2144
+ this.consumer = {
2145
+ bytesRemaining: bytesToConsumeFromStream,
2146
+ stream: readable
2147
+ };
2148
+ this.source.resume();
2149
+ } else {
2150
+ StreamUtils.endStream(readable);
2151
+ }
2152
+ return readable;
2175
2153
  }
2176
2154
  }, {
2177
- key: "getUploadPart",
2178
- value: function getUploadPart(request, partIndex, uploadInfo) {
2179
- try {
2180
- var _this14 = this;
2181
- if (partIndex === 0) {
2182
- return uploadInfo.uploadParts.first;
2183
- }
2184
- return UploadManager_await(_this14.uploadApi.getUploadPart({
2185
- uploadId: uploadInfo.uploadId,
2186
- accountId: request.accountId,
2187
- uploadPartIndex: partIndex
2188
- }));
2189
- } catch (e) {
2190
- return Promise.reject(e);
2155
+ key: "consumeFromBuffer",
2156
+ value: function consumeFromBuffer(bytes) {
2157
+ var splitResult = this.splitBuffer(this.buffer, bytes);
2158
+ if (splitResult === undefined) {
2159
+ return undefined;
2191
2160
  }
2161
+ var _splitResult2 = NodeChunkedStream_slicedToArray(splitResult, 2),
2162
+ consumed = _splitResult2[0],
2163
+ remaining = _splitResult2[1];
2164
+ this.buffer = remaining;
2165
+ return consumed;
2192
2166
  }
2193
2167
  }, {
2194
- key: "calculateSize",
2195
- value: function calculateSize(request, data) {
2196
- return this.foldData(data, {
2197
- ifBlob: function ifBlob(blob) {
2198
- return blob.size;
2199
- },
2200
- ifBuffer: function ifBuffer(buffer) {
2201
- return buffer.length;
2202
- },
2203
- ifNodeJsStream: function ifNodeJsStream(_) {
2204
- if (request.size === undefined) {
2205
- throw new Error("You must include the 'size' parameter when using a stream for the 'data' parameter.");
2206
- }
2207
- return request.size;
2168
+ key: "splitBuffer",
2169
+ value: function splitBuffer(buffer, maxBytes) {
2170
+ if (buffer.byteLength === 0) {
2171
+ return undefined;
2172
+ }
2173
+ var bytesToConsume = Math.min(maxBytes, buffer.byteLength);
2174
+ if (bytesToConsume === buffer.byteLength) {
2175
+ return [buffer, Buffer.alloc(0)]; // Optimization
2176
+ }
2177
+
2178
+ var consumed = buffer.subarray(0, bytesToConsume);
2179
+ var remaining = buffer.subarray(bytesToConsume);
2180
+ return [consumed, remaining];
2181
+ }
2182
+ }]);
2183
+ return NodeChunkedStream;
2184
+ }();
2185
+ ;// CONCATENATED MODULE: external "buffer"
2186
+ var external_buffer_namespaceObject = require("buffer");
2187
+ ;// CONCATENATED MODULE: ./src/public/node/UploadManagerNode.ts
2188
+ 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); }
2189
+ function UploadManagerNode_empty() {}
2190
+ function UploadManagerNode_awaitIgnored(value, direct) {
2191
+ if (!direct) {
2192
+ return value && value.then ? value.then(UploadManagerNode_empty) : Promise.resolve();
2193
+ }
2194
+ }
2195
+ function UploadManagerNode_await(value, then, direct) {
2196
+ if (direct) {
2197
+ return then ? then(value) : value;
2198
+ }
2199
+ if (!value || !value.then) {
2200
+ value = Promise.resolve(value);
2201
+ }
2202
+ return then ? value.then(then) : value;
2203
+ }
2204
+ function UploadManagerNode_settle(pact, state, value) {
2205
+ if (!pact.s) {
2206
+ if (value instanceof UploadManagerNode_Pact) {
2207
+ if (value.s) {
2208
+ if (state & 1) {
2209
+ state = value.s;
2208
2210
  }
2209
- });
2211
+ value = value.v;
2212
+ } else {
2213
+ value.o = UploadManagerNode_settle.bind(null, pact, state);
2214
+ return;
2215
+ }
2210
2216
  }
2211
- }, {
2212
- key: "calculateMime",
2213
- value: function calculateMime(request, data) {
2214
- var _a;
2215
- return (_a = request.mime) !== null && _a !== void 0 ? _a : this.foldData(data, {
2216
- ifBlob: function ifBlob(blob) {
2217
- return blob.type;
2218
- },
2219
- ifBuffer: function ifBuffer(_) {
2220
- return undefined;
2221
- },
2222
- ifNodeJsStream: function ifNodeJsStream(_) {
2223
- return undefined;
2217
+ if (value && value.then) {
2218
+ value.then(UploadManagerNode_settle.bind(null, pact, state), UploadManagerNode_settle.bind(null, pact, 2));
2219
+ return;
2220
+ }
2221
+ pact.s = state;
2222
+ pact.v = value;
2223
+ var observer = pact.o;
2224
+ if (observer) {
2225
+ observer(pact);
2226
+ }
2227
+ }
2228
+ }
2229
+ var UploadManagerNode_Pact = /*#__PURE__*/function () {
2230
+ function _Pact() {}
2231
+ _Pact.prototype.then = function (onFulfilled, onRejected) {
2232
+ var result = new _Pact();
2233
+ var state = this.s;
2234
+ if (state) {
2235
+ var callback = state & 1 ? onFulfilled : onRejected;
2236
+ if (callback) {
2237
+ try {
2238
+ UploadManagerNode_settle(result, 1, callback(this.v));
2239
+ } catch (e) {
2240
+ UploadManagerNode_settle(result, 2, e);
2224
2241
  }
2225
- });
2242
+ return result;
2243
+ } else {
2244
+ return this;
2245
+ }
2226
2246
  }
2227
- }, {
2228
- key: "calculateOriginalFileName",
2229
- value: function calculateOriginalFileName(request, data) {
2230
- var _a;
2231
- return (_a = request.originalFileName) !== null && _a !== void 0 ? _a : this.foldData(data, {
2232
- ifBlob: function ifBlob(blob) {
2233
- return blob.name;
2234
- },
2235
- ifBuffer: function ifBuffer(_) {
2236
- return undefined;
2237
- },
2238
- ifNodeJsStream: function ifNodeJsStream(_) {
2239
- return undefined;
2247
+ this.o = function (_this) {
2248
+ try {
2249
+ var value = _this.v;
2250
+ if (_this.s & 1) {
2251
+ UploadManagerNode_settle(result, 1, onFulfilled ? onFulfilled(value) : value);
2252
+ } else if (onRejected) {
2253
+ UploadManagerNode_settle(result, 1, onRejected(value));
2254
+ } else {
2255
+ UploadManagerNode_settle(result, 2, value);
2240
2256
  }
2241
- });
2257
+ } catch (e) {
2258
+ UploadManagerNode_settle(result, 2, e);
2259
+ }
2260
+ };
2261
+ return result;
2262
+ };
2263
+ return _Pact;
2264
+ }();
2265
+ function _switch(discriminant, cases) {
2266
+ var dispatchIndex = -1;
2267
+ var awaitBody;
2268
+ outer: {
2269
+ for (var i = 0; i < cases.length; i++) {
2270
+ var test = cases[i][0];
2271
+ if (test) {
2272
+ var testValue = test();
2273
+ if (testValue && testValue.then) {
2274
+ break outer;
2275
+ }
2276
+ if (testValue === discriminant) {
2277
+ dispatchIndex = i;
2278
+ break;
2279
+ }
2280
+ } else {
2281
+ // Found the default case, set it as the pending dispatch case
2282
+ dispatchIndex = i;
2283
+ }
2242
2284
  }
2243
- }, {
2244
- key: "calculateMaxConcurrency",
2245
- value: function calculateMaxConcurrency(request, data) {
2246
- var _a;
2247
- return (_a = this.foldData(data, {
2248
- ifBlob: function ifBlob(_) {
2249
- return request.maxConcurrentUploadParts;
2250
- },
2251
- ifBuffer: function ifBuffer(_) {
2252
- return request.maxConcurrentUploadParts;
2253
- },
2254
- ifNodeJsStream: function ifNodeJsStream(_) {
2255
- return 1;
2256
- } // Uploading from a stream concurrently is more complex, as would require buffering parts in memory, so we serialize.
2257
- })) !== null && _a !== void 0 ? _a : this.defaultMaxConcurrentUploadParts;
2285
+ if (dispatchIndex !== -1) {
2286
+ do {
2287
+ var body = cases[dispatchIndex][1];
2288
+ while (!body) {
2289
+ dispatchIndex++;
2290
+ body = cases[dispatchIndex][1];
2291
+ }
2292
+ var result = body();
2293
+ if (result && result.then) {
2294
+ awaitBody = true;
2295
+ break outer;
2296
+ }
2297
+ var fallthroughCheck = cases[dispatchIndex][2];
2298
+ dispatchIndex++;
2299
+ } while (fallthroughCheck && !fallthroughCheck());
2300
+ return result;
2258
2301
  }
2259
- }, {
2260
- key: "getChunkedStream",
2261
- value: function getChunkedStream(data) {
2262
- return this.foldData(data, {
2263
- ifBlob: function ifBlob(_) {
2264
- return undefined;
2265
- },
2266
- ifBuffer: function ifBuffer(_) {
2267
- return undefined;
2268
- },
2269
- ifNodeJsStream: function ifNodeJsStream(x) {
2270
- return x;
2302
+ }
2303
+ var pact = new UploadManagerNode_Pact();
2304
+ var reject = UploadManagerNode_settle.bind(null, pact, 2);
2305
+ (awaitBody ? result.then(_resumeAfterBody) : testValue.then(_resumeAfterTest)).then(void 0, reject);
2306
+ return pact;
2307
+ function _resumeAfterTest(value) {
2308
+ for (;;) {
2309
+ if (value === discriminant) {
2310
+ dispatchIndex = i;
2311
+ break;
2312
+ }
2313
+ if (++i === cases.length) {
2314
+ if (dispatchIndex !== -1) {
2315
+ break;
2316
+ } else {
2317
+ UploadManagerNode_settle(pact, 1, result);
2318
+ return;
2271
2319
  }
2272
- });
2320
+ }
2321
+ test = cases[i][0];
2322
+ if (test) {
2323
+ value = test();
2324
+ if (value && value.then) {
2325
+ value.then(_resumeAfterTest).then(void 0, reject);
2326
+ return;
2327
+ }
2328
+ } else {
2329
+ dispatchIndex = i;
2330
+ }
2273
2331
  }
2274
- }, {
2275
- key: "foldData",
2276
- value: function foldData(data, handle) {
2277
- if (data instanceof ChunkedStream) {
2278
- return handle.ifNodeJsStream(data);
2332
+ do {
2333
+ var body = cases[dispatchIndex][1];
2334
+ while (!body) {
2335
+ dispatchIndex++;
2336
+ body = cases[dispatchIndex][1];
2337
+ }
2338
+ var result = body();
2339
+ if (result && result.then) {
2340
+ result.then(_resumeAfterBody).then(void 0, reject);
2341
+ return;
2342
+ }
2343
+ var fallthroughCheck = cases[dispatchIndex][2];
2344
+ dispatchIndex++;
2345
+ } while (fallthroughCheck && !fallthroughCheck());
2346
+ UploadManagerNode_settle(pact, 1, result);
2347
+ }
2348
+ function _resumeAfterBody(result) {
2349
+ for (;;) {
2350
+ var fallthroughCheck = cases[dispatchIndex][2];
2351
+ if (!fallthroughCheck || fallthroughCheck()) {
2352
+ break;
2353
+ }
2354
+ dispatchIndex++;
2355
+ var body = cases[dispatchIndex][1];
2356
+ while (!body) {
2357
+ dispatchIndex++;
2358
+ body = cases[dispatchIndex][1];
2359
+ }
2360
+ result = body();
2361
+ if (result && result.then) {
2362
+ result.then(_resumeAfterBody).then(void 0, reject);
2363
+ return;
2364
+ }
2365
+ }
2366
+ UploadManagerNode_settle(pact, 1, result);
2367
+ }
2368
+ }
2369
+ function UploadManagerNode_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2370
+ function UploadManagerNode_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, UploadManagerNode_toPropertyKey(descriptor.key), descriptor); } }
2371
+ function UploadManagerNode_createClass(Constructor, protoProps, staticProps) { if (protoProps) UploadManagerNode_defineProperties(Constructor.prototype, protoProps); if (staticProps) UploadManagerNode_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
2372
+ function UploadManagerNode_toPropertyKey(arg) { var key = UploadManagerNode_toPrimitive(arg, "string"); return UploadManagerNode_typeof(key) === "symbol" ? key : String(key); }
2373
+ function UploadManagerNode_toPrimitive(input, hint) { if (UploadManagerNode_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (UploadManagerNode_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
2374
+ function UploadManagerNode_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) UploadManagerNode_setPrototypeOf(subClass, superClass); }
2375
+ function UploadManagerNode_setPrototypeOf(o, p) { UploadManagerNode_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return UploadManagerNode_setPrototypeOf(o, p); }
2376
+ function UploadManagerNode_createSuper(Derived) { var hasNativeReflectConstruct = UploadManagerNode_isNativeReflectConstruct(); return function _createSuperInternal() { var Super = UploadManagerNode_getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = UploadManagerNode_getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return UploadManagerNode_possibleConstructorReturn(this, result); }; }
2377
+ function UploadManagerNode_possibleConstructorReturn(self, call) { if (call && (UploadManagerNode_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 UploadManagerNode_assertThisInitialized(self); }
2378
+ function UploadManagerNode_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
2379
+ function UploadManagerNode_isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
2380
+ function UploadManagerNode_getPrototypeOf(o) { UploadManagerNode_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return UploadManagerNode_getPrototypeOf(o); }
2381
+
2382
+
2383
+
2384
+
2385
+
2386
+ var UploadManager = /*#__PURE__*/function (_UploadManagerBase) {
2387
+ UploadManagerNode_inherits(UploadManager, _UploadManagerBase);
2388
+ var _super = UploadManagerNode_createSuper(UploadManager);
2389
+ function UploadManager() {
2390
+ UploadManagerNode_classCallCheck(this, UploadManager);
2391
+ return _super.apply(this, arguments);
2392
+ }
2393
+ UploadManagerNode_createClass(UploadManager, [{
2394
+ key: "processUploadSource",
2395
+ value: function processUploadSource(data) {
2396
+ if (typeof data === "string") {
2397
+ // 'Blob' must be from 'buffer' as we're in a node context here, so isn't globally available.
2398
+ return {
2399
+ type: "Blob",
2400
+ value: new external_buffer_namespaceObject.Blob([data], {
2401
+ type: this.stringMimeType
2402
+ })
2403
+ };
2404
+ }
2405
+ if (data.on !== undefined) {
2406
+ return {
2407
+ type: "Stream",
2408
+ value: new NodeChunkedStream(data)
2409
+ };
2279
2410
  }
2280
2411
  if (data.subarray !== undefined) {
2281
- return handle.ifBuffer(data);
2412
+ return {
2413
+ type: "Buffer",
2414
+ value: data
2415
+ };
2282
2416
  }
2283
- if (data.slice !== undefined) {
2284
- return handle.ifBlob(data);
2417
+ if (data.size !== undefined) {
2418
+ return {
2419
+ type: "Blob",
2420
+ value: data
2421
+ };
2285
2422
  }
2286
2423
  throw new Error("Unsupported type for 'data' parameter. Please provide a String, Blob, or Readable (Node.js).");
2287
2424
  }
2288
2425
  }, {
2289
- key: "foldDataRaw",
2290
- value: function foldDataRaw(data, handle) {
2291
- try {
2292
- var _exit8 = false;
2293
- var _this16 = this;
2294
- return UploadManager_invoke(function () {
2295
- if (typeof data === "string") {
2296
- _exit8 = true;
2297
- var _ifBlob2 = handle.ifBlob;
2298
- return UploadManager_await(_this16.stringToBlob(data), function (_this15$stringToBlob) {
2299
- return UploadManager_await(_ifBlob2.call(handle, _this15$stringToBlob));
2300
- });
2426
+ key: "getPreUploadInfoPartial",
2427
+ value: function getPreUploadInfoPartial(request, data) {
2428
+ switch (data.type) {
2429
+ case "Blob":
2430
+ return this.getBlobInfo(data);
2431
+ case "Buffer":
2432
+ return {
2433
+ mime: undefined,
2434
+ size: data.value.length,
2435
+ originalFileName: undefined,
2436
+ maxConcurrentUploadParts: undefined
2437
+ };
2438
+ case "Stream":
2439
+ if (request.size === undefined) {
2440
+ throw new Error("You must include the 'size' parameter when using a stream for the 'data' parameter.");
2301
2441
  }
2302
- }, function (_result3) {
2303
- var _exit5 = false;
2304
- if (_exit8) return _result3;
2305
- return UploadManager_invoke(function () {
2306
- if (data.on !== undefined) {
2307
- _exit5 = true;
2308
- return UploadManager_await(handle.ifNodeJsStream(data));
2309
- }
2310
- }, function (_result4) {
2311
- var _exit6 = false;
2312
- if (_exit5) return _result4;
2313
- return UploadManager_invoke(function () {
2314
- if (data.subarray !== undefined) {
2315
- _exit6 = true;
2316
- return UploadManager_await(handle.ifBuffer(data));
2317
- }
2318
- }, function (_result5) {
2319
- var _exit7 = false;
2320
- if (_exit6) return _result5;
2321
- return UploadManager_invoke(function () {
2322
- if (data.slice !== undefined) {
2323
- _exit7 = true;
2324
- return UploadManager_await(handle.ifBlob(data));
2325
- }
2326
- }, function (_result6) {
2327
- if (_exit7) return _result6;
2328
- throw new Error("Unsupported type for 'data' parameter. Please provide a String, Blob, or Readable (Node.js).");
2329
- });
2330
- });
2331
- });
2332
- });
2442
+ return {
2443
+ mime: undefined,
2444
+ size: request.size,
2445
+ originalFileName: undefined,
2446
+ maxConcurrentUploadParts: 1 // Uploading from a stream concurrently is complex, so we serialize it.
2447
+ };
2448
+
2449
+ default:
2450
+ assertUnreachable(data);
2451
+ }
2452
+ }
2453
+ }, {
2454
+ key: "preUpload",
2455
+ value: function preUpload(source) {
2456
+ if (source.type !== "Stream") {
2457
+ return undefined;
2458
+ }
2459
+ var chunkedStream = source.value;
2460
+ var chunkedStreamPromise = chunkedStream.runChunkPipeline();
2461
+ return {
2462
+ chunkedStreamPromise: chunkedStreamPromise,
2463
+ chunkedStream: chunkedStream
2464
+ };
2465
+ }
2466
+ }, {
2467
+ key: "postUpload",
2468
+ value: function postUpload(init) {
2469
+ try {
2470
+ if (init === undefined) {
2471
+ return;
2472
+ }
2473
+ init.chunkedStream.finishedConsuming();
2474
+ // Raise any errors from the stream chunking task.
2475
+ return UploadManagerNode_awaitIgnored(init.chunkedStreamPromise);
2333
2476
  } catch (e) {
2334
2477
  return Promise.reject(e);
2335
2478
  }
2336
2479
  }
2337
2480
  }, {
2338
- key: "processUploadSource",
2339
- value: function processUploadSource(data) {
2481
+ key: "doPutUploadPart",
2482
+ value: function doPutUploadPart(part, contentLength, source, onProgress, addCancellationHandler) {
2340
2483
  try {
2341
- var _exit10 = false;
2342
- var _this18 = this;
2343
- return UploadManager_invoke(function () {
2344
- if (typeof data === "string") {
2345
- _exit10 = true;
2346
- return UploadManager_await(_this18.stringToBlob(data));
2347
- }
2348
- }, function (_result7) {
2349
- if (_exit10) return _result7;
2350
- if (data.on !== undefined) {
2351
- return new ChunkedStream(data);
2352
- }
2353
- if (data.subarray !== undefined) {
2354
- return data;
2355
- }
2356
- if (data.slice !== undefined) {
2357
- return data;
2358
- }
2359
- throw new Error("Unsupported type for 'data' parameter. Please provide a String, Blob, or Readable (Node.js).");
2484
+ var _this2 = this;
2485
+ var _a, _b;
2486
+ var fetchApi = (_a = _this2.config.fetchApi) !== null && _a !== void 0 ? _a : fetch;
2487
+ var headers = {
2488
+ // Required to prevent fetch using "Transfer-Encoding: Chunked" when body is a stream.
2489
+ "content-length": contentLength.toString()
2490
+ };
2491
+ // Configure cancellation:
2492
+ var controller = new AbortController();
2493
+ var signal = controller.signal;
2494
+ addCancellationHandler(function () {
2495
+ return controller.abort();
2496
+ });
2497
+ // Report progress:
2498
+ var hasWarned = false;
2499
+ return UploadManagerNode_await(_this2.sliceDataForRequest(source, part), function (stream) {
2500
+ var streamWithProgress = stream.on("data", function (data) {
2501
+ if (data.length !== undefined) {
2502
+ onProgress(data.length);
2503
+ } else if (!hasWarned) {
2504
+ hasWarned = true;
2505
+ console.warn("Expected stream to contain buffers, but it did not, so upload progress won't be reported.");
2506
+ }
2507
+ });
2508
+ return UploadManagerNode_await(fetchApi(part.uploadUrl, {
2509
+ method: "PUT",
2510
+ headers: headers,
2511
+ body: _this2.coerceRequestBody(streamWithProgress),
2512
+ signal: signal
2513
+ }), function (response) {
2514
+ return {
2515
+ etag: (_b = response.headers.get("etag")) !== null && _b !== void 0 ? _b : undefined,
2516
+ status: response.status
2517
+ };
2518
+ });
2360
2519
  });
2361
2520
  } catch (e) {
2362
2521
  return Promise.reject(e);
2363
2522
  }
2364
2523
  }
2365
2524
  }, {
2366
- key: "stringToBlob",
2367
- value: function stringToBlob(data) {
2525
+ key: "coerceRequestBody",
2526
+ value: function coerceRequestBody(data) {
2527
+ return data; // node-fetch supports 'NodeJS.ReadableStream'
2528
+ }
2529
+ }, {
2530
+ key: "sliceDataForRequest",
2531
+ value: function sliceDataForRequest(data, part) {
2368
2532
  try {
2369
- var _this20 = this;
2370
- var _a;
2371
- var _temp2 = (_a = _this20.globalBlob(data)) !== null && _a !== void 0;
2372
- return UploadManager_await(_temp2 ? _a : _this20.nodeJsBlob(data), void 0, _temp2);
2533
+ if (part.range.inclusiveEnd === -1) {
2534
+ return StreamUtils.empty();
2535
+ }
2536
+ var start = part.range.inclusiveStart;
2537
+ var endExclusive = part.range.inclusiveEnd + 1;
2538
+ var partSize = endExclusive - start;
2539
+ return _switch(data.type, [[function () {
2540
+ return "Blob";
2541
+ }, function () {
2542
+ var _fromBuffer = StreamUtils.fromBuffer,
2543
+ _Buffer = Buffer,
2544
+ _from = _Buffer.from;
2545
+ return UploadManagerNode_await(data.value.slice(start, endExclusive).arrayBuffer(), function (_data$value$slice$arr) {
2546
+ return _fromBuffer.call(StreamUtils, _from.call(_Buffer, _data$value$slice$arr));
2547
+ });
2548
+ }], [function () {
2549
+ return "Buffer";
2550
+ }, function () {
2551
+ return StreamUtils.fromBuffer(data.value.subarray(start, endExclusive));
2552
+ }], [function () {
2553
+ return "Stream";
2554
+ }, function () {
2555
+ return data.value.take(partSize);
2556
+ }], [void 0, function () {
2557
+ assertUnreachable(data);
2558
+ }, UploadManagerNode_empty]]);
2373
2559
  } catch (e) {
2374
2560
  return Promise.reject(e);
2375
2561
  }
2376
- } // Supported by browsers & newer versions of Node.js.
2562
+ }
2563
+ }]);
2564
+ return UploadManager;
2565
+ }(UploadManagerBase);
2566
+ ;// CONCATENATED MODULE: ./src/private/EnvChecker.ts
2567
+ function EnvChecker_typeof(obj) { "@babel/helpers - typeof"; return EnvChecker_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; }, EnvChecker_typeof(obj); }
2568
+ function EnvChecker_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2569
+ function EnvChecker_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, EnvChecker_toPropertyKey(descriptor.key), descriptor); } }
2570
+ function EnvChecker_createClass(Constructor, protoProps, staticProps) { if (protoProps) EnvChecker_defineProperties(Constructor.prototype, protoProps); if (staticProps) EnvChecker_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
2571
+ function EnvChecker_toPropertyKey(arg) { var key = EnvChecker_toPrimitive(arg, "string"); return EnvChecker_typeof(key) === "symbol" ? key : String(key); }
2572
+ function EnvChecker_toPrimitive(input, hint) { if (EnvChecker_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (EnvChecker_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
2573
+ var EnvChecker = /*#__PURE__*/function () {
2574
+ function EnvChecker() {
2575
+ EnvChecker_classCallCheck(this, EnvChecker);
2576
+ }
2577
+ EnvChecker_createClass(EnvChecker, null, [{
2578
+ key: "isNodeJs",
2579
+ value: function isNodeJs() {
2580
+ return typeof process !== "undefined" && process.versions !== undefined && process.versions.node !== undefined;
2581
+ }
2377
2582
  }, {
2378
- key: "globalBlob",
2379
- value: function globalBlob(data) {
2380
- var B = globalThis.Blob;
2381
- if (B === undefined) {
2382
- return undefined;
2583
+ key: "methodRequiresBrowser",
2584
+ value: function methodRequiresBrowser(methodName) {
2585
+ if (EnvChecker.isNodeJs()) {
2586
+ return new Error("You must call '".concat(methodName, "' in the browser. (You are currently in Node.js.)"));
2383
2587
  }
2384
- return new B([data], {
2385
- type: this.stringMimeType
2386
- });
2588
+ 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."));
2387
2589
  }
2388
- // Fallback for Node.js
2389
- }, {
2390
- key: "nodeJsBlob",
2391
- value: function nodeJsBlob(data) {
2590
+ }]);
2591
+ return EnvChecker;
2592
+ }();
2593
+ ;// CONCATENATED MODULE: ./src/public/node/AuthManagerNode.ts
2594
+ function AuthManagerNode_typeof(obj) { "@babel/helpers - typeof"; return AuthManagerNode_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; }, AuthManagerNode_typeof(obj); }
2595
+ function AuthManagerNode_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2596
+ function AuthManagerNode_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, AuthManagerNode_toPropertyKey(descriptor.key), descriptor); } }
2597
+ function AuthManagerNode_createClass(Constructor, protoProps, staticProps) { if (protoProps) AuthManagerNode_defineProperties(Constructor.prototype, protoProps); if (staticProps) AuthManagerNode_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
2598
+ function AuthManagerNode_toPropertyKey(arg) { var key = AuthManagerNode_toPrimitive(arg, "string"); return AuthManagerNode_typeof(key) === "symbol" ? key : String(key); }
2599
+ function AuthManagerNode_toPrimitive(input, hint) { if (AuthManagerNode_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (AuthManagerNode_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
2600
+
2601
+ var AuthManager = /*#__PURE__*/function () {
2602
+ function AuthManager() {
2603
+ AuthManagerNode_classCallCheck(this, AuthManager);
2604
+ }
2605
+ AuthManagerNode_createClass(AuthManager, [{
2606
+ key: "beginAuthSession",
2607
+ value: function beginAuthSession(_authUrl, _authHeaders) {
2392
2608
  try {
2393
- var _this22 = this;
2394
- return UploadManager_await(NodeUtils.createBlob([data], {
2395
- type: _this22.stringMimeType
2396
- }));
2609
+ throw EnvChecker.methodRequiresBrowser("beginAuthSession");
2397
2610
  } catch (e) {
2398
2611
  return Promise.reject(e);
2399
2612
  }
2400
2613
  }
2401
2614
  }, {
2402
- key: "mapAsync",
2403
- value: function mapAsync(items, concurrency, callback) {
2615
+ key: "endAuthSession",
2616
+ value: function endAuthSession() {
2404
2617
  try {
2405
- var workQueue = _toConsumableArray(items);
2406
- return _awaitIgnored(Promise.all(_toConsumableArray(Array(concurrency).keys()).map(UploadManager_async(function () {
2407
- return _continueIgnored(_for(function () {
2408
- return workQueue.length > 0;
2409
- }, void 0, function () {
2410
- var work = workQueue.shift(); // IMPORTANT: use 'shift' instead of 'pop' to ensure 'items' are processed in order when 'concurrency = 1'.
2411
- return _invokeIgnored(function () {
2412
- if (work !== undefined) {
2413
- return _awaitIgnored(callback(work));
2414
- }
2415
- });
2416
- }));
2417
- }))));
2618
+ throw EnvChecker.methodRequiresBrowser("endAuthSession");
2418
2619
  } catch (e) {
2419
2620
  return Promise.reject(e);
2420
2621
  }
2421
2622
  }
2623
+ }, {
2624
+ key: "isAuthSessionActive",
2625
+ value: function isAuthSessionActive() {
2626
+ return false;
2627
+ }
2422
2628
  }]);
2423
- return UploadManager;
2629
+ return AuthManager;
2424
2630
  }();
2425
- ;// CONCATENATED MODULE: ./src/uploads/index.ts
2631
+ ;// CONCATENATED MODULE: ./src/public/node/index.ts
2426
2632
 
2427
2633
 
2428
-
2429
- ;// CONCATENATED MODULE: ./src/index.ts
2634
+ ;// CONCATENATED MODULE: ./src/index.node.ts
2430
2635
  /* tslint:disable */
2431
2636
  /* eslint-disable */
2432
2637
 
2433
2638
 
2434
- }();
2435
2639
  module.exports = __lib_exports__;
2436
2640
  /******/ })()
2437
2641
  ;