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