@bytescale/sdk 1.2.0 → 1.4.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 (48) hide show
  1. package/dist/browser/cjs/main.js +904 -198
  2. package/dist/node/cjs/main.js +418 -205
  3. package/dist/node/esm/main.mjs +424 -207
  4. package/dist/types/index.d.ts +2 -0
  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/private/TypeUtils.d.ts +2 -0
  10. package/dist/types/{uploads/private → private}/UploadManagerBase.d.ts +2 -2
  11. package/dist/types/private/dtos/SetAccessTokenRequestDto.d.ts +6 -0
  12. package/dist/types/private/dtos/SetAccessTokenResponseDto.d.ts +7 -0
  13. package/dist/types/private/model/AuthManagerInterface.d.ts +44 -0
  14. package/dist/types/private/model/AuthSession.d.ts +7 -0
  15. package/dist/types/private/model/UploadManagerInterface.d.ts +5 -0
  16. package/dist/types/{uploads/private → private}/model/UploadSourceProcessed.d.ts +1 -1
  17. package/dist/types/public/browser/AuthManagerBrowser.d.ts +20 -0
  18. package/dist/types/{uploads/public → public}/browser/UploadManagerBrowser.d.ts +2 -2
  19. package/dist/types/{uploads/public → public}/browser/index.d.ts +1 -0
  20. package/dist/types/public/node/AuthManagerNode.d.ts +6 -0
  21. package/dist/types/{uploads/public → public}/node/UploadManagerNode.d.ts +2 -2
  22. package/dist/types/{uploads/public → public}/node/index.d.ts +1 -0
  23. package/dist/types/{uploads/public/shared/Model.d.ts → public/shared/CommonTypes.d.ts} +3 -9
  24. package/dist/types/public/shared/UrlBuilder.d.ts +32 -0
  25. package/dist/types/public/shared/UrlBuilderTypes.d.ts +173 -0
  26. package/dist/types/{generated → public/shared/generated}/apis/FileApi.d.ts +7 -1
  27. package/dist/types/{generated → public/shared/generated}/models/index.d.ts +6 -10
  28. package/dist/types/{generated → public/shared/generated}/runtime.d.ts +46 -16
  29. package/dist/types/public/shared/index.d.ts +4 -0
  30. package/package.json +2 -2
  31. package/tests/ChunkedStream.test.ts +1 -1
  32. package/tests/UrlBuilder.test.ts +168 -0
  33. package/dist/types/index.browser.d.ts +0 -3
  34. package/dist/types/index.node.d.ts +0 -3
  35. package/dist/types/uploads/private/TypeUtils.d.ts +0 -1
  36. package/dist/types/uploads/private/model/UploadManagerInterface.d.ts +0 -5
  37. package/dist/types/uploads/public/shared/index.d.ts +0 -1
  38. /package/dist/types/{uploads/private → private}/NodeChunkedStream.d.ts +0 -0
  39. /package/dist/types/{uploads/private → private}/StreamUtils.d.ts +0 -0
  40. /package/dist/types/{uploads/private → private}/model/AddCancellationHandler.d.ts +0 -0
  41. /package/dist/types/{uploads/private → private}/model/OnPartProgress.d.ts +0 -0
  42. /package/dist/types/{uploads/private → private}/model/PreUploadInfo.d.ts +0 -0
  43. /package/dist/types/{uploads/private → private}/model/PutUploadPartResult.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
@@ -39,26 +39,40 @@ __lib_require__.r(__lib_exports__);
39
39
 
40
40
  // EXPORTS
41
41
  __lib_require__.d(__lib_exports__, {
42
- "BASE_PATH": function() { return /* reexport */ BASE_PATH; },
42
+ "AuthManager": function() { return /* reexport */ AuthManager; },
43
43
  "BaseAPI": function() { return /* reexport */ BaseAPI; },
44
44
  "BinaryResult": function() { return /* reexport */ BinaryResult; },
45
+ "BytescaleApiClientConfigResolver": function() { return /* reexport */ BytescaleApiClientConfigResolver; },
45
46
  "BytescaleApiError": function() { return /* reexport */ BytescaleApiError; },
46
47
  "CancelledError": function() { return /* reexport */ CancelledError; },
48
+ "CommonTypesNoOp": function() { return /* reexport */ CommonTypesNoOp; },
47
49
  "FileApi": function() { return /* reexport */ FileApi; },
48
50
  "FolderApi": function() { return /* reexport */ FolderApi; },
49
51
  "JSONApiResponse": function() { return /* reexport */ JSONApiResponse; },
50
52
  "JobApi": function() { return /* reexport */ JobApi; },
51
53
  "UploadApi": function() { return /* reexport */ UploadApi; },
52
54
  "UploadManager": function() { return /* reexport */ UploadManager; },
55
+ "UrlBuilder": function() { return /* reexport */ UrlBuilder; },
56
+ "UrlBuilderTypesNoOp": function() { return /* reexport */ UrlBuilderTypesNoOp; },
53
57
  "VoidApiResponse": function() { return /* reexport */ VoidApiResponse; },
54
58
  "querystring": function() { return /* reexport */ querystring; }
55
59
  });
56
60
 
57
- ;// CONCATENATED MODULE: ./src/generated/runtime.ts
61
+ ;// CONCATENATED MODULE: ./src/private/AuthSessionState.ts
58
62
  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); }
63
+ 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); } }
64
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
65
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
66
+ 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); }
67
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
68
+ var AuthSessionState = /*#__PURE__*/_createClass(function AuthSessionState() {
69
+ _classCallCheck(this, AuthSessionState);
70
+ });
71
+ ;// CONCATENATED MODULE: ./src/public/shared/generated/runtime.ts
72
+ 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); }
59
73
  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); }
60
74
  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); }; }
61
- 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); }
75
+ 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); }
62
76
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
63
77
  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); }
64
78
  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); }
@@ -66,15 +80,6 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
66
80
  function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
67
81
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
68
82
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
69
- function _await(value, then, direct) {
70
- if (direct) {
71
- return then ? then(value) : value;
72
- }
73
- if (!value || !value.then) {
74
- value = Promise.resolve(value);
75
- }
76
- return then ? value.then(then) : value;
77
- }
78
83
  function _catch(body, recover) {
79
84
  try {
80
85
  var result = body();
@@ -86,22 +91,10 @@ function _catch(body, recover) {
86
91
  }
87
92
  return result;
88
93
  }
94
+ function _empty() {}
89
95
  function _continue(value, then) {
90
96
  return value && value.then ? value.then(then) : then(value);
91
97
  }
92
- function _async(f) {
93
- return function () {
94
- for (var args = [], i = 0; i < arguments.length; i++) {
95
- args[i] = arguments[i];
96
- }
97
- try {
98
- return Promise.resolve(f.apply(this, args));
99
- } catch (e) {
100
- return Promise.reject(e);
101
- }
102
- };
103
- }
104
- function _empty() {}
105
98
  function _invoke(body, then) {
106
99
  var result = body();
107
100
  if (result && result.then) {
@@ -109,81 +102,122 @@ function _invoke(body, then) {
109
102
  }
110
103
  return then(result);
111
104
  }
112
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
113
- 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); } }
114
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
115
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
116
- 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); }
117
- /**
118
- * @bytescale/api
119
- * Bytescale API
120
- *
121
- * The version of the OpenAPI document: 2.0.0
122
- * Contact: hello@bytescale.com
123
- *
124
- * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
125
- * https://openapi-generator.tech
126
- * Do not edit the class manually.
127
- */
128
- var BASE_PATH = "https://api.bytescale.com".replace(/\/+$/, "");
105
+ 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; }
106
+ function _await(value, then, direct) {
107
+ if (direct) {
108
+ return then ? then(value) : value;
109
+ }
110
+ if (!value || !value.then) {
111
+ value = Promise.resolve(value);
112
+ }
113
+ return then ? value.then(then) : value;
114
+ }
115
+ function runtime_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
116
+ 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); } }
117
+ 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; }
118
+ function runtime_toPropertyKey(arg) { var key = runtime_toPrimitive(arg, "string"); return runtime_typeof(key) === "symbol" ? key : String(key); }
119
+ 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); }
120
+
121
+ var BytescaleApiClientConfigResolver = /*#__PURE__*/function () {
122
+ function BytescaleApiClientConfigResolver() {
123
+ runtime_classCallCheck(this, BytescaleApiClientConfigResolver);
124
+ }
125
+ runtime_createClass(BytescaleApiClientConfigResolver, null, [{
126
+ key: "getApiUrl",
127
+ value: function getApiUrl(config) {
128
+ var _a;
129
+ return (_a = config.apiUrl) !== null && _a !== void 0 ? _a : BytescaleApiClientConfigResolver.defaultApiUrl;
130
+ }
131
+ }, {
132
+ key: "getCdnUrl",
133
+ value: function getCdnUrl(config) {
134
+ var _a;
135
+ return (_a = config.cdnUrl) !== null && _a !== void 0 ? _a : BytescaleApiClientConfigResolver.defaultCdnUrl;
136
+ }
137
+ }, {
138
+ key: "getFetchApi",
139
+ value: function getFetchApi(config) {
140
+ var _a;
141
+ return (_a = config.fetchApi) !== null && _a !== void 0 ? _a : fetch;
142
+ }
143
+ }]);
144
+ return BytescaleApiClientConfigResolver;
145
+ }();
146
+ BytescaleApiClientConfigResolver.defaultApiUrl = "https://api.bytescale.com";
147
+ BytescaleApiClientConfigResolver.defaultCdnUrl = "https://upcdn.io";
129
148
  /**
130
149
  * This is the base class for all generated API classes.
131
150
  */
132
151
  var BaseAPI = /*#__PURE__*/function () {
133
152
  function BaseAPI(config) {
134
- var _this = this;
135
- _classCallCheck(this, BaseAPI);
153
+ runtime_classCallCheck(this, BaseAPI);
136
154
  this.config = config;
137
- this.fetchApi = _async(function (url, init) {
138
- var _exit = false;
139
- var fetchParams = {
140
- url: url,
141
- init: init
142
- };
143
- var response = undefined;
144
- return _continue(_catch(function () {
145
- return _await((_this.config.fetchApi || fetch)(fetchParams.url, fetchParams.init), function (_temp) {
146
- response = _temp;
147
- });
148
- }, function (e) {
149
- if (response === undefined) {
150
- throw e;
151
- }
152
- }), function (_result) {
153
- return _exit ? _result : response;
154
- });
155
- });
156
155
  }
157
- _createClass(BaseAPI, [{
156
+ runtime_createClass(BaseAPI, [{
158
157
  key: "request",
159
- value: function request(context, initOverrides, operationBasePathOverride) {
158
+ value: function request(context, initOverrides, baseUrlOverride) {
160
159
  try {
161
- var _this3 = this;
162
- var _a;
163
- var apiKey = _this3.config.apiKey;
160
+ var _this2 = this;
161
+ var _a, _b;
162
+ var apiKey = _this2.config.apiKey;
164
163
  context.headers["Authorization"] = "Bearer ".concat(apiKey); // authorization-header authentication
165
- return _await(_this3.createFetchParams(context, initOverrides, operationBasePathOverride), function (_ref) {
164
+ if (((_a = AuthSessionState.session) === null || _a === void 0 ? void 0 : _a.accessToken) !== undefined) {
165
+ context.headers["Authorization-Token"] = AuthSessionState.session.accessToken;
166
+ }
167
+ // Key: any possible value for 'baseUrlOverride'
168
+ // Value: user-overridden value for that base URL from the config.
169
+ var nonDefaultBasePaths = _defineProperty({}, BytescaleApiClientConfigResolver.defaultCdnUrl, BytescaleApiClientConfigResolver.getCdnUrl(_this2.config));
170
+ return _await(_this2.createFetchParams(context, initOverrides, baseUrlOverride === undefined ? undefined : (_b = nonDefaultBasePaths[baseUrlOverride]) !== null && _b !== void 0 ? _b : baseUrlOverride), function (_ref) {
166
171
  var url = _ref.url,
167
172
  init = _ref.init;
168
- return _await(_this3.fetchApi(url, init), function (response) {
169
- var _exit2 = false;
170
- return response && response.status >= 200 && response.status < 300 ? response : _invoke(function () {
171
- if (response !== undefined) {
172
- var jsonError = undefined;
173
- return _continue(_catch(function () {
174
- return _await(response.json(), function (_response$json) {
175
- jsonError = _response$json;
176
- });
177
- }, _empty), function () {
178
- if (typeof ((_a = jsonError === null || jsonError === void 0 ? void 0 : jsonError.error) === null || _a === void 0 ? void 0 : _a.code) === "string") {
179
- throw new BytescaleApiError(jsonError);
180
- }
173
+ return _this2.doFetch(url, init, true);
174
+ });
175
+ } catch (e) {
176
+ return Promise.reject(e);
177
+ }
178
+ }
179
+ /**
180
+ * Returns a successful response (2**) else throws an error.
181
+ */
182
+ }, {
183
+ key: "doFetch",
184
+ value: function doFetch(url, init, isBytescaleApi) {
185
+ try {
186
+ var _exit3 = false;
187
+ var _this4 = this;
188
+ var _a, _b;
189
+ var response;
190
+ return _continue(_catch(function () {
191
+ return _await(BytescaleApiClientConfigResolver.getFetchApi(_this4.config)(url, init), function (_BytescaleApiClientCo) {
192
+ response = _BytescaleApiClientCo;
193
+ });
194
+ }, function (e) {
195
+ // Network-level errors, CORS errors, or HTTP-level errors from intermediary services (e.g. AWS or the user's own infrastructure/proxies).
196
+ // 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.
197
+ 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));
198
+ }), function (_result) {
199
+ var _exit2 = false;
200
+ if (_exit3) return _result;
201
+ return response.status >= 200 && response.status < 300 ? response : _invoke(function () {
202
+ if (isBytescaleApi) {
203
+ var jsonError = undefined;
204
+ return _continue(_catch(function () {
205
+ return _await(response.json(), function (_response$json) {
206
+ jsonError = _response$json;
181
207
  });
182
- }
183
- }, function (_result2) {
184
- if (_exit2) return _result2;
185
- throw new Error("Unable to connect to the Bytescale API: please try again.");
186
- });
208
+ }, _empty), function () {
209
+ if (typeof ((_a = jsonError === null || jsonError === void 0 ? void 0 : jsonError.error) === null || _a === void 0 ? void 0 : _a.code) === "string") {
210
+ throw new BytescaleApiError(jsonError);
211
+ }
212
+ // HTTP-level errors from intermediary services (e.g. AWS or the user's own infrastructure/proxies). On the browser,
213
+ // this error is unlikely to be triggered since these errors will masqurade as CORS errors (see above) but in Node.js
214
+ // this error will appear from any intermediary service failure.
215
+ throw new Error("Unable to connect to the Bytescale API (".concat(response.status, "): please try again."));
216
+ });
217
+ }
218
+ }, function (_result2) {
219
+ if (_exit2) return _result2;
220
+ throw new Error("Failure status code (".concat(response.status, ") received for request: ").concat((_b = init.method) !== null && _b !== void 0 ? _b : "GET", " ").concat(url));
187
221
  });
188
222
  });
189
223
  } catch (e) {
@@ -205,17 +239,17 @@ var BaseAPI = /*#__PURE__*/function () {
205
239
  }
206
240
  }, {
207
241
  key: "createFetchParams",
208
- value: function createFetchParams(context, initOverrides, operationBasePathOverride) {
242
+ value: function createFetchParams(context, initOverrides, baseUrlOverride) {
209
243
  try {
210
- var _this5 = this;
211
- var url = (operationBasePathOverride !== null && operationBasePathOverride !== void 0 ? operationBasePathOverride : BASE_PATH) + context.path;
244
+ var _this6 = this;
245
+ var url = (baseUrlOverride !== null && baseUrlOverride !== void 0 ? baseUrlOverride : BytescaleApiClientConfigResolver.getApiUrl(_this6.config)) + context.path;
212
246
  if (context.query !== undefined && Object.keys(context.query).length !== 0) {
213
247
  // only add the querystring to the URL if there are query parameters.
214
248
  // this is done to avoid urls ending with a "?" character which buggy webservers
215
249
  // do not handle correctly sometimes.
216
250
  url += "?" + querystring(context.query);
217
251
  }
218
- var configHeaders = _this5.config.headers;
252
+ var configHeaders = _this6.config.headers;
219
253
  var _Object$assign3 = Object.assign({}, context.headers);
220
254
  return _await(configHeaders === undefined ? {} : configHeaders(), function (_configHeaders) {
221
255
  var headers = Object.assign(_Object$assign3, _configHeaders);
@@ -252,67 +286,59 @@ var BaseAPI = /*#__PURE__*/function () {
252
286
  }]);
253
287
  return BaseAPI;
254
288
  }();
255
- var BytescaleApiError = /*#__PURE__*/function (_Error) {
256
- _inherits(BytescaleApiError, _Error);
257
- var _super = _createSuper(BytescaleApiError);
289
+ BaseAPI.specialApiKeys = ["free", "demo"];
290
+ BaseAPI.specialApiKeyAccountId = "W142hJk";
291
+ BaseAPI.accountIdLength = 7; // Sync with: upload/shared/**/AccountIdUtils
292
+ var CancelledError = /*#__PURE__*/function (_Error) {
293
+ _inherits(CancelledError, _Error);
294
+ var _super = _createSuper(CancelledError);
295
+ function CancelledError() {
296
+ var _this7;
297
+ runtime_classCallCheck(this, CancelledError);
298
+ _this7 = _super.call(this, "Operation cancelled by caller.");
299
+ _this7.name = "CancelledError";
300
+ return _this7;
301
+ }
302
+ return runtime_createClass(CancelledError);
303
+ }( /*#__PURE__*/_wrapNativeSuper(Error));
304
+ var BytescaleApiError = /*#__PURE__*/function (_Error2) {
305
+ _inherits(BytescaleApiError, _Error2);
306
+ var _super2 = _createSuper(BytescaleApiError);
258
307
  function BytescaleApiError(response) {
259
- var _this6;
260
- _classCallCheck(this, BytescaleApiError);
261
- _this6 = _super.call(this, response.error.message);
262
- _this6.name = "BytescaleApiError";
263
- _this6.errorCode = response.error.code;
264
- _this6.details = response.error.details;
265
- return _this6;
266
- }
267
- return _createClass(BytescaleApiError);
308
+ var _this8;
309
+ runtime_classCallCheck(this, BytescaleApiError);
310
+ _this8 = _super2.call(this, response.error.message);
311
+ _this8.name = "BytescaleApiError";
312
+ _this8.errorCode = response.error.code;
313
+ _this8.details = response.error.details;
314
+ return _this8;
315
+ }
316
+ return runtime_createClass(BytescaleApiError);
268
317
  }( /*#__PURE__*/_wrapNativeSuper(Error));
269
318
  function querystring(params) {
270
- var prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
271
319
  return Object.keys(params).map(function (key) {
272
- return querystringSingleKey(key, params[key], prefix);
320
+ return querystringSingleKey(key, params[key]);
273
321
  }).filter(function (part) {
274
322
  return part.length > 0;
275
323
  }).join("&");
276
324
  }
277
325
  function querystringSingleKey(key, value) {
278
- var keyPrefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "";
279
- var fullKey = keyPrefix + (keyPrefix.length ? "[".concat(key, "]") : key);
280
- if (value instanceof Array) {
281
- var multiValue = value.map(function (singleValue) {
282
- return encodeURIComponent(String(singleValue));
283
- }).join("&".concat(encodeURIComponent(fullKey), "="));
284
- return "".concat(encodeURIComponent(fullKey), "=").concat(multiValue);
285
- }
286
- if (value instanceof Set) {
287
- var valueAsArray = Array.from(value);
288
- return querystringSingleKey(key, valueAsArray, keyPrefix);
289
- }
290
- if (value instanceof Date) {
291
- return "".concat(encodeURIComponent(fullKey), "=").concat(encodeURIComponent(value.toISOString()));
292
- }
293
326
  if (value instanceof Object) {
294
- return querystring(value, fullKey);
327
+ return querystring(value);
295
328
  }
296
- return "".concat(encodeURIComponent(fullKey), "=").concat(encodeURIComponent(String(value)));
329
+ return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(String(value)));
297
330
  }
298
331
  var JSONApiResponse = /*#__PURE__*/function () {
299
332
  function JSONApiResponse(raw) {
300
- var transformer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (jsonValue) {
301
- return jsonValue;
302
- };
303
- _classCallCheck(this, JSONApiResponse);
333
+ runtime_classCallCheck(this, JSONApiResponse);
304
334
  this.raw = raw;
305
- this.transformer = transformer;
306
335
  }
307
- _createClass(JSONApiResponse, [{
336
+ runtime_createClass(JSONApiResponse, [{
308
337
  key: "value",
309
338
  value: function value() {
310
339
  try {
311
- var _this8 = this;
312
- var _transformer2 = _this8.transformer;
313
- return _await(_this8.raw.json(), function (_this7$raw$json) {
314
- return _transformer2.call(_this8, _this7$raw$json);
315
- });
340
+ var _this10 = this;
341
+ return _await(_this10.raw.json());
316
342
  } catch (e) {
317
343
  return Promise.reject(e);
318
344
  }
@@ -322,10 +348,10 @@ var JSONApiResponse = /*#__PURE__*/function () {
322
348
  }();
323
349
  var VoidApiResponse = /*#__PURE__*/function () {
324
350
  function VoidApiResponse(raw) {
325
- _classCallCheck(this, VoidApiResponse);
351
+ runtime_classCallCheck(this, VoidApiResponse);
326
352
  this.raw = raw;
327
353
  }
328
- _createClass(VoidApiResponse, [{
354
+ runtime_createClass(VoidApiResponse, [{
329
355
  key: "value",
330
356
  value: function value() {
331
357
  return _await(undefined);
@@ -335,10 +361,10 @@ var VoidApiResponse = /*#__PURE__*/function () {
335
361
  }();
336
362
  var BinaryResult = /*#__PURE__*/function () {
337
363
  function BinaryResult(raw) {
338
- _classCallCheck(this, BinaryResult);
364
+ runtime_classCallCheck(this, BinaryResult);
339
365
  this.raw = raw;
340
366
  }
341
- _createClass(BinaryResult, [{
367
+ runtime_createClass(BinaryResult, [{
342
368
  key: "stream",
343
369
  value: function stream() {
344
370
  if (this.raw.bodyUsed) {
@@ -353,8 +379,8 @@ var BinaryResult = /*#__PURE__*/function () {
353
379
  key: "text",
354
380
  value: function text() {
355
381
  try {
356
- var _this10 = this;
357
- return _await(_this10.raw.text());
382
+ var _this12 = this;
383
+ return _await(_this12.raw.text());
358
384
  } catch (e) {
359
385
  return Promise.reject(e);
360
386
  }
@@ -363,8 +389,8 @@ var BinaryResult = /*#__PURE__*/function () {
363
389
  key: "blob",
364
390
  value: function blob() {
365
391
  try {
366
- var _this12 = this;
367
- return _await(_this12.raw.blob());
392
+ var _this14 = this;
393
+ return _await(_this14.raw.blob());
368
394
  } catch (e) {
369
395
  return Promise.reject(e);
370
396
  }
@@ -373,8 +399,8 @@ var BinaryResult = /*#__PURE__*/function () {
373
399
  key: "json",
374
400
  value: function json() {
375
401
  try {
376
- var _this14 = this;
377
- return _await(_this14.raw.json());
402
+ var _this16 = this;
403
+ return _await(_this16.raw.json());
378
404
  } catch (e) {
379
405
  return Promise.reject(e);
380
406
  }
@@ -382,7 +408,7 @@ var BinaryResult = /*#__PURE__*/function () {
382
408
  }]);
383
409
  return BinaryResult;
384
410
  }();
385
- ;// CONCATENATED MODULE: ./src/generated/apis/FileApi.ts
411
+ ;// CONCATENATED MODULE: ./src/public/shared/generated/apis/FileApi.ts
386
412
  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); }
387
413
  function FileApi_await(value, then, direct) {
388
414
  if (direct) {
@@ -622,6 +648,9 @@ var FileApi = /*#__PURE__*/function (_runtime$BaseAPI) {
622
648
  if (params.large !== undefined) {
623
649
  query["large"] = params.large;
624
650
  }
651
+ if (params.transformationParams !== undefined) {
652
+ query["transformationParams"] = params.transformationParams;
653
+ }
625
654
  if (params.version !== undefined) {
626
655
  query["version"] = params.version;
627
656
  }
@@ -653,6 +682,9 @@ var FileApi = /*#__PURE__*/function (_runtime$BaseAPI) {
653
682
  try {
654
683
  var _this16 = this;
655
684
  var query = {};
685
+ if (params.transformationParams !== undefined) {
686
+ query["transformationParams"] = params.transformationParams;
687
+ }
656
688
  var headers = {};
657
689
  headers["Content-Type"] = "application/json";
658
690
  return FileApi_await(_this16.request({
@@ -677,7 +709,7 @@ var FileApi = /*#__PURE__*/function (_runtime$BaseAPI) {
677
709
  }]);
678
710
  return FileApi;
679
711
  }(BaseAPI);
680
- ;// CONCATENATED MODULE: ./src/generated/apis/FolderApi.ts
712
+ ;// CONCATENATED MODULE: ./src/public/shared/generated/apis/FolderApi.ts
681
713
  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); }
682
714
  function FolderApi_await(value, then, direct) {
683
715
  if (direct) {
@@ -937,7 +969,7 @@ var FolderApi = /*#__PURE__*/function (_runtime$BaseAPI) {
937
969
  }]);
938
970
  return FolderApi;
939
971
  }(BaseAPI);
940
- ;// CONCATENATED MODULE: ./src/generated/apis/JobApi.ts
972
+ ;// CONCATENATED MODULE: ./src/public/shared/generated/apis/JobApi.ts
941
973
  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); }
942
974
  function JobApi_await(value, then, direct) {
943
975
  if (direct) {
@@ -1072,7 +1104,7 @@ var JobApi = /*#__PURE__*/function (_runtime$BaseAPI) {
1072
1104
  }]);
1073
1105
  return JobApi;
1074
1106
  }(BaseAPI);
1075
- ;// CONCATENATED MODULE: ./src/generated/apis/UploadApi.ts
1107
+ ;// CONCATENATED MODULE: ./src/public/shared/generated/apis/UploadApi.ts
1076
1108
  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); }
1077
1109
  function UploadApi_await(value, then, direct) {
1078
1110
  if (direct) {
@@ -1260,53 +1292,174 @@ var UploadApi = /*#__PURE__*/function (_runtime$BaseAPI) {
1260
1292
  }]);
1261
1293
  return UploadApi;
1262
1294
  }(BaseAPI);
1263
- ;// CONCATENATED MODULE: ./src/generated/apis/index.ts
1295
+ ;// CONCATENATED MODULE: ./src/public/shared/generated/apis/index.ts
1264
1296
  /* tslint:disable */
1265
1297
  /* eslint-disable */
1266
1298
 
1267
1299
 
1268
1300
 
1269
1301
 
1270
- ;// CONCATENATED MODULE: ./src/generated/index.ts
1302
+ ;// CONCATENATED MODULE: ./src/public/shared/generated/index.ts
1271
1303
  /* tslint:disable */
1272
1304
  /* eslint-disable */
1273
1305
 
1274
1306
 
1275
1307
 
1276
- ;// CONCATENATED MODULE: ./src/uploads/public/shared/Model.ts
1277
- function Model_typeof(obj) { "@babel/helpers - typeof"; return Model_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; }, Model_typeof(obj); }
1278
- function Model_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, Model_toPropertyKey(descriptor.key), descriptor); } }
1279
- function Model_createClass(Constructor, protoProps, staticProps) { if (protoProps) Model_defineProperties(Constructor.prototype, protoProps); if (staticProps) Model_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
1280
- function Model_toPropertyKey(arg) { var key = Model_toPrimitive(arg, "string"); return Model_typeof(key) === "symbol" ? key : String(key); }
1281
- function Model_toPrimitive(input, hint) { if (Model_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (Model_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
1282
- function Model_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1283
- function Model_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) Model_setPrototypeOf(subClass, superClass); }
1284
- function Model_createSuper(Derived) { var hasNativeReflectConstruct = Model_isNativeReflectConstruct(); return function _createSuperInternal() { var Super = Model_getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = Model_getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return Model_possibleConstructorReturn(this, result); }; }
1285
- function Model_possibleConstructorReturn(self, call) { if (call && (Model_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 Model_assertThisInitialized(self); }
1286
- function Model_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
1287
- function Model_wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; Model_wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !Model_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 Model_construct(Class, arguments, Model_getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return Model_setPrototypeOf(Wrapper, Class); }; return Model_wrapNativeSuper(Class); }
1288
- function Model_construct(Parent, args, Class) { if (Model_isNativeReflectConstruct()) { Model_construct = Reflect.construct.bind(); } else { Model_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) Model_setPrototypeOf(instance, Class.prototype); return instance; }; } return Model_construct.apply(null, arguments); }
1289
- function Model_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; } }
1290
- function Model_isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
1291
- function Model_setPrototypeOf(o, p) { Model_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return Model_setPrototypeOf(o, p); }
1292
- function Model_getPrototypeOf(o) { Model_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return Model_getPrototypeOf(o); }
1293
- var CancelledError = /*#__PURE__*/function (_Error) {
1294
- Model_inherits(CancelledError, _Error);
1295
- var _super = Model_createSuper(CancelledError);
1296
- function CancelledError() {
1297
- var _this;
1298
- Model_classCallCheck(this, CancelledError);
1299
- _this = _super.call(this, "Upload cancelled by user.");
1300
- _this.name = "CancelledError";
1301
- return _this;
1308
+ ;// CONCATENATED MODULE: ./src/public/shared/CommonTypes.ts
1309
+ /**
1310
+ * Workaround for tsc aliases, where we cannot export implementation-less modules in our dists.
1311
+ */
1312
+ var CommonTypesNoOp = false;
1313
+ ;// CONCATENATED MODULE: ./src/private/TypeUtils.ts
1314
+ function assertUnreachable(x) {
1315
+ throw new Error("Didn't expect to get here: ".concat(JSON.stringify(x)));
1316
+ }
1317
+ function isDefinedEntry(object) {
1318
+ return object[1] !== undefined && object[1] !== null;
1319
+ }
1320
+ ;// CONCATENATED MODULE: ./src/public/shared/UrlBuilder.ts
1321
+ 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); }
1322
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
1323
+ 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."); }
1324
+ 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; } }
1325
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
1326
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
1327
+ 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."); }
1328
+ 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); }
1329
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
1330
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
1331
+ 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; }
1332
+ function UrlBuilder_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1333
+ 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); } }
1334
+ 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; }
1335
+ function UrlBuilder_toPropertyKey(arg) { var key = UrlBuilder_toPrimitive(arg, "string"); return UrlBuilder_typeof(key) === "symbol" ? key : String(key); }
1336
+ 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); }
1337
+
1338
+
1339
+ var UrlBuilder = /*#__PURE__*/function () {
1340
+ function UrlBuilder(config) {
1341
+ UrlBuilder_classCallCheck(this, UrlBuilder);
1342
+ var _a;
1343
+ this.cdnUrl = (_a = config === null || config === void 0 ? void 0 : config.cdnUrl) !== null && _a !== void 0 ? _a : BytescaleApiClientConfigResolver.defaultCdnUrl;
1302
1344
  }
1303
- return Model_createClass(CancelledError);
1304
- }( /*#__PURE__*/Model_wrapNativeSuper(Error));
1305
- ;// CONCATENATED MODULE: ./src/uploads/public/shared/index.ts
1345
+ /**
1346
+ * Builds a URL to either a raw file or a transformed file.
1347
+ *
1348
+ * Example 1) Getting a publicly-accessible raw file URL:
1349
+ *
1350
+ * new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg" })
1351
+ *
1352
+ * Example 2) Getting a publicly-accessible image URL, resized to 500x500:
1353
+ *
1354
+ * new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "image", params: { w: 500, h: 500, fit: "crop" } } } })
1355
+ *
1356
+ * Example 3) Getting a privately-accessible image URL, resized to 500x500 (requires 'AuthManager.beginAuthSession' to be called before accessing the URL):
1357
+ *
1358
+ * new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "image", params: { w: 500, h: 500, fit: "crop" } }, auth: true } })
1359
+ *
1360
+ * Example 4) Getting a publicly-accessible image URL, resized using a transformation preset called "thumbnail" that was created manually in the Bytescale Dashboard:
1361
+ *
1362
+ * new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "preset", preset: "thumbnail" } } })
1363
+ */
1364
+ UrlBuilder_createClass(UrlBuilder, [{
1365
+ key: "url",
1366
+ value: function url(params) {
1367
+ var _a;
1368
+ return ((_a = params.options) === null || _a === void 0 ? void 0 : _a.transformation) === undefined ? this.raw(params) : this.transformation(params, params.options.transformation);
1369
+ }
1370
+ }, {
1371
+ key: "raw",
1372
+ value: function raw(params) {
1373
+ var _a;
1374
+ var baseUrl = this.getBaseUrl(params, "raw");
1375
+ var commonParams = this.getCommonQueryParams((_a = params.options) !== null && _a !== void 0 ? _a : {});
1376
+ return this.addQueryParams(baseUrl, commonParams);
1377
+ }
1378
+ }, {
1379
+ key: "transformation",
1380
+ value: function transformation(params, trans) {
1381
+ var _a;
1382
+ var baseUrl = this.getBaseUrl(params, trans.type === "preset" ? trans.preset : trans.type);
1383
+ var transParams = this.getTransformationParams(trans, {
1384
+ cachePermanently: "cache_perm"
1385
+ });
1386
+ var commonParams = this.getCommonQueryParams((_a = params.options) !== null && _a !== void 0 ? _a : {});
1387
+ return this.addQueryParams(baseUrl, [].concat(_toConsumableArray(commonParams), _toConsumableArray(transParams)));
1388
+ }
1389
+ }, {
1390
+ key: "getBaseUrl",
1391
+ value: function getBaseUrl(params, prefix) {
1392
+ return "".concat(this.cdnUrl, "/").concat(params.accountId, "/").concat(prefix).concat(params.filePath);
1393
+ }
1394
+ }, {
1395
+ key: "getCommonQueryParams",
1396
+ value: function getCommonQueryParams(params) {
1397
+ return this.makeQueryParams(["auth", "cache", "cacheTtl", "version", "forceDownloadPrompt"], {
1398
+ cacheTtl: "cache_ttl",
1399
+ forceDownloadPrompt: "download"
1400
+ })(params);
1401
+ }
1402
+ }, {
1403
+ key: "makeQueryParams",
1404
+ value: function makeQueryParams(keys, keyOverrides) {
1405
+ return function (data) {
1406
+ var result = [];
1407
+ keys.forEach(function (key) {
1408
+ var _a;
1409
+ var value = data[key];
1410
+ if (value !== undefined) {
1411
+ result.push([(_a = keyOverrides[key]) !== null && _a !== void 0 ? _a : key, value.toString()]);
1412
+ }
1413
+ });
1414
+ return result;
1415
+ };
1416
+ }
1417
+ }, {
1418
+ key: "getTransformationParams",
1419
+ value: function getTransformationParams(trans, keyRewrites) {
1420
+ if (trans.params === undefined) {
1421
+ return [];
1422
+ }
1423
+ var serializeObj = function serializeObj(obj) {
1424
+ return Object.entries(obj).filter(isDefinedEntry).map(function (_ref) {
1425
+ var _ref2 = _slicedToArray(_ref, 2),
1426
+ key = _ref2[0],
1427
+ value = _ref2[1];
1428
+ var _a;
1429
+ return [(_a = keyRewrites[key]) !== null && _a !== void 0 ? _a : key, value.toString()];
1430
+ });
1431
+ };
1432
+ return Array.isArray(trans.params) ? trans.params.flatMap(serializeObj) : serializeObj(trans.params);
1433
+ }
1434
+ }, {
1435
+ key: "addQueryParams",
1436
+ value: function addQueryParams(baseUrl, params) {
1437
+ if (params.length === 0) {
1438
+ return baseUrl;
1439
+ }
1440
+ return "".concat(baseUrl, "?").concat(params.map(function (_ref3) {
1441
+ var _ref4 = _slicedToArray(_ref3, 2),
1442
+ key = _ref4[0],
1443
+ value = _ref4[1];
1444
+ return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(value));
1445
+ }).join("&"));
1446
+ }
1447
+ }]);
1448
+ return UrlBuilder;
1449
+ }();
1450
+ ;// CONCATENATED MODULE: ./src/public/shared/UrlBuilderTypes.ts
1451
+ /**
1452
+ * Workaround for tsc aliases, where we cannot export implementation-less modules in our dists.
1453
+ */
1454
+ var UrlBuilderTypesNoOp = false;
1455
+ ;// CONCATENATED MODULE: ./src/public/shared/index.ts
1456
+
1457
+
1306
1458
 
1307
- ;// CONCATENATED MODULE: ./src/uploads/private/UploadManagerBase.ts
1459
+
1460
+ ;// CONCATENATED MODULE: ./src/private/UploadManagerBase.ts
1308
1461
  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); }
1309
- function UploadManagerBase_async(f) {
1462
+ function _async(f) {
1310
1463
  return function () {
1311
1464
  for (var args = [], i = 0; i < arguments.length; i++) {
1312
1465
  args[i] = arguments[i];
@@ -1478,12 +1631,12 @@ function _continueIgnored(value) {
1478
1631
  return value.then(UploadManagerBase_empty);
1479
1632
  }
1480
1633
  }
1481
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
1482
- 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."); }
1483
- 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); }
1484
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
1485
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
1486
- 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; }
1634
+ function UploadManagerBase_toConsumableArray(arr) { return UploadManagerBase_arrayWithoutHoles(arr) || UploadManagerBase_iterableToArray(arr) || UploadManagerBase_unsupportedIterableToArray(arr) || UploadManagerBase_nonIterableSpread(); }
1635
+ 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."); }
1636
+ 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); }
1637
+ function UploadManagerBase_iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
1638
+ function UploadManagerBase_arrayWithoutHoles(arr) { if (Array.isArray(arr)) return UploadManagerBase_arrayLikeToArray(arr); }
1639
+ 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; }
1487
1640
  function UploadManagerBase_empty() {}
1488
1641
  function _awaitIgnored(value, direct) {
1489
1642
  if (!direct) {
@@ -1523,7 +1676,6 @@ function UploadManagerBase_createClass(Constructor, protoProps, staticProps) { i
1523
1676
  function UploadManagerBase_toPropertyKey(arg) { var key = UploadManagerBase_toPrimitive(arg, "string"); return UploadManagerBase_typeof(key) === "symbol" ? key : String(key); }
1524
1677
  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); }
1525
1678
 
1526
-
1527
1679
  /**
1528
1680
  * Methods common to UploadManagerNode and UploadManagerBrowser.
1529
1681
  */
@@ -1550,13 +1702,13 @@ var UploadManagerBase = /*#__PURE__*/function () {
1550
1702
  onProgress(0);
1551
1703
  return UploadManagerBase_await(_this2.beginUpload(request, preUploadInfo), function (uploadInfo) {
1552
1704
  var partCount = uploadInfo.uploadParts.count;
1553
- var parts = _toConsumableArray(Array(partCount).keys());
1705
+ var parts = UploadManagerBase_toConsumableArray(Array(partCount).keys());
1554
1706
  var _this2$makeCancellati = _this2.makeCancellationMethods(),
1555
1707
  cancel = _this2$makeCancellati.cancel,
1556
1708
  addCancellationHandler = _this2$makeCancellati.addCancellationHandler;
1557
1709
  var intervalHandle = setInterval(_this2.onIntervalTick(request, cancel), _this2.intervalMs);
1558
1710
  return UploadManagerBase_continue(_finallyRethrows(function () {
1559
- return UploadManagerBase_await(_this2.mapAsync(parts, preUploadInfo.maxConcurrentUploadParts, UploadManagerBase_async(function (part) {
1711
+ return UploadManagerBase_await(_this2.mapAsync(parts, preUploadInfo.maxConcurrentUploadParts, _async(function (part) {
1560
1712
  return _this2.uploadPart(request, source, part, uploadInfo, onProgress, addCancellationHandler);
1561
1713
  })), function () {
1562
1714
  return _awaitIgnored(_this2.postUpload(init));
@@ -1748,8 +1900,8 @@ var UploadManagerBase = /*#__PURE__*/function () {
1748
1900
  key: "mapAsync",
1749
1901
  value: function mapAsync(items, concurrency, callback) {
1750
1902
  try {
1751
- var workQueue = _toConsumableArray(items);
1752
- return _awaitIgnored(Promise.all(_toConsumableArray(Array(concurrency).keys()).map(UploadManagerBase_async(function () {
1903
+ var workQueue = UploadManagerBase_toConsumableArray(items);
1904
+ return _awaitIgnored(Promise.all(UploadManagerBase_toConsumableArray(Array(concurrency).keys()).map(_async(function () {
1753
1905
  return _continueIgnored(_for(function () {
1754
1906
  return workQueue.length > 0;
1755
1907
  }, void 0, function () {
@@ -1768,11 +1920,7 @@ var UploadManagerBase = /*#__PURE__*/function () {
1768
1920
  }]);
1769
1921
  return UploadManagerBase;
1770
1922
  }();
1771
- ;// CONCATENATED MODULE: ./src/uploads/private/TypeUtils.ts
1772
- function assertUnreachable(x) {
1773
- throw new Error("Didn't expect to get here: ".concat(JSON.stringify(x)));
1774
- }
1775
- ;// CONCATENATED MODULE: ./src/uploads/public/browser/UploadManagerBrowser.ts
1923
+ ;// CONCATENATED MODULE: ./src/public/browser/UploadManagerBrowser.ts
1776
1924
  function UploadManagerBrowser_typeof(obj) { "@babel/helpers - typeof"; return UploadManagerBrowser_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; }, UploadManagerBrowser_typeof(obj); }
1777
1925
  function UploadManagerBrowser_await(value, then, direct) {
1778
1926
  if (direct) {
@@ -1923,14 +2071,572 @@ var UploadManager = /*#__PURE__*/function (_UploadManagerBase) {
1923
2071
  }]);
1924
2072
  return UploadManager;
1925
2073
  }(UploadManagerBase);
1926
- ;// CONCATENATED MODULE: ./src/uploads/public/browser/index.ts
2074
+ ;// CONCATENATED MODULE: ./src/private/ConsoleUtils.ts
2075
+ function ConsoleUtils_typeof(obj) { "@babel/helpers - typeof"; return ConsoleUtils_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; }, ConsoleUtils_typeof(obj); }
2076
+ function ConsoleUtils_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2077
+ function ConsoleUtils_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, ConsoleUtils_toPropertyKey(descriptor.key), descriptor); } }
2078
+ function ConsoleUtils_createClass(Constructor, protoProps, staticProps) { if (protoProps) ConsoleUtils_defineProperties(Constructor.prototype, protoProps); if (staticProps) ConsoleUtils_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
2079
+ function ConsoleUtils_toPropertyKey(arg) { var key = ConsoleUtils_toPrimitive(arg, "string"); return ConsoleUtils_typeof(key) === "symbol" ? key : String(key); }
2080
+ function ConsoleUtils_toPrimitive(input, hint) { if (ConsoleUtils_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (ConsoleUtils_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
2081
+ var ConsoleUtils = /*#__PURE__*/function () {
2082
+ function ConsoleUtils() {
2083
+ ConsoleUtils_classCallCheck(this, ConsoleUtils);
2084
+ }
2085
+ ConsoleUtils_createClass(ConsoleUtils, null, [{
2086
+ key: "error",
2087
+ value: function error(message) {
2088
+ console.error(ConsoleUtils.prefix(message));
2089
+ }
2090
+ }, {
2091
+ key: "warn",
2092
+ value: function warn(message) {
2093
+ console.warn(ConsoleUtils.prefix(message));
2094
+ }
2095
+ }, {
2096
+ key: "prefix",
2097
+ value: function prefix(message) {
2098
+ return "[bytescale-sdk] ".concat(message);
2099
+ }
2100
+ }]);
2101
+ return ConsoleUtils;
2102
+ }();
2103
+ ;// CONCATENATED MODULE: ./src/private/Mutex.ts
2104
+ function Mutex_typeof(obj) { "@babel/helpers - typeof"; return Mutex_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; }, Mutex_typeof(obj); }
2105
+ function _call(body, then, direct) {
2106
+ if (direct) {
2107
+ return then ? then(body()) : body();
2108
+ }
2109
+ try {
2110
+ var result = Promise.resolve(body());
2111
+ return then ? result.then(then) : result;
2112
+ } catch (e) {
2113
+ return Promise.reject(e);
2114
+ }
2115
+ }
2116
+ function Mutex_rethrow(thrown, value) {
2117
+ if (thrown) throw value;
2118
+ return value;
2119
+ }
2120
+ function Mutex_finallyRethrows(body, finalizer) {
2121
+ try {
2122
+ var result = body();
2123
+ } catch (e) {
2124
+ return finalizer(true, e);
2125
+ }
2126
+ if (result && result.then) {
2127
+ return result.then(finalizer.bind(null, false), finalizer.bind(null, true));
2128
+ }
2129
+ return finalizer(false, result);
2130
+ }
2131
+ function Mutex_await(value, then, direct) {
2132
+ if (direct) {
2133
+ return then ? then(value) : value;
2134
+ }
2135
+ if (!value || !value.then) {
2136
+ value = Promise.resolve(value);
2137
+ }
2138
+ return then ? value.then(then) : value;
2139
+ }
2140
+ function Mutex_empty() {}
2141
+ function Mutex_awaitIgnored(value, direct) {
2142
+ if (!direct) {
2143
+ return value && value.then ? value.then(Mutex_empty) : Promise.resolve();
2144
+ }
2145
+ }
2146
+ function Mutex_settle(pact, state, value) {
2147
+ if (!pact.s) {
2148
+ if (value instanceof Mutex_Pact) {
2149
+ if (value.s) {
2150
+ if (state & 1) {
2151
+ state = value.s;
2152
+ }
2153
+ value = value.v;
2154
+ } else {
2155
+ value.o = Mutex_settle.bind(null, pact, state);
2156
+ return;
2157
+ }
2158
+ }
2159
+ if (value && value.then) {
2160
+ value.then(Mutex_settle.bind(null, pact, state), Mutex_settle.bind(null, pact, 2));
2161
+ return;
2162
+ }
2163
+ pact.s = state;
2164
+ pact.v = value;
2165
+ var observer = pact.o;
2166
+ if (observer) {
2167
+ observer(pact);
2168
+ }
2169
+ }
2170
+ }
2171
+ var Mutex_Pact = /*#__PURE__*/function () {
2172
+ function _Pact() {}
2173
+ _Pact.prototype.then = function (onFulfilled, onRejected) {
2174
+ var result = new _Pact();
2175
+ var state = this.s;
2176
+ if (state) {
2177
+ var callback = state & 1 ? onFulfilled : onRejected;
2178
+ if (callback) {
2179
+ try {
2180
+ Mutex_settle(result, 1, callback(this.v));
2181
+ } catch (e) {
2182
+ Mutex_settle(result, 2, e);
2183
+ }
2184
+ return result;
2185
+ } else {
2186
+ return this;
2187
+ }
2188
+ }
2189
+ this.o = function (_this) {
2190
+ try {
2191
+ var value = _this.v;
2192
+ if (_this.s & 1) {
2193
+ Mutex_settle(result, 1, onFulfilled ? onFulfilled(value) : value);
2194
+ } else if (onRejected) {
2195
+ Mutex_settle(result, 1, onRejected(value));
2196
+ } else {
2197
+ Mutex_settle(result, 2, value);
2198
+ }
2199
+ } catch (e) {
2200
+ Mutex_settle(result, 2, e);
2201
+ }
2202
+ };
2203
+ return result;
2204
+ };
2205
+ return _Pact;
2206
+ }();
2207
+ function Mutex_isSettledPact(thenable) {
2208
+ return thenable instanceof Mutex_Pact && thenable.s & 1;
2209
+ }
2210
+ function Mutex_for(test, update, body) {
2211
+ var stage;
2212
+ for (;;) {
2213
+ var shouldContinue = test();
2214
+ if (Mutex_isSettledPact(shouldContinue)) {
2215
+ shouldContinue = shouldContinue.v;
2216
+ }
2217
+ if (!shouldContinue) {
2218
+ return result;
2219
+ }
2220
+ if (shouldContinue.then) {
2221
+ stage = 0;
2222
+ break;
2223
+ }
2224
+ var result = body();
2225
+ if (result && result.then) {
2226
+ if (Mutex_isSettledPact(result)) {
2227
+ result = result.s;
2228
+ } else {
2229
+ stage = 1;
2230
+ break;
2231
+ }
2232
+ }
2233
+ if (update) {
2234
+ var updateValue = update();
2235
+ if (updateValue && updateValue.then && !Mutex_isSettledPact(updateValue)) {
2236
+ stage = 2;
2237
+ break;
2238
+ }
2239
+ }
2240
+ }
2241
+ var pact = new Mutex_Pact();
2242
+ var reject = Mutex_settle.bind(null, pact, 2);
2243
+ (stage === 0 ? shouldContinue.then(_resumeAfterTest) : stage === 1 ? result.then(_resumeAfterBody) : updateValue.then(_resumeAfterUpdate)).then(void 0, reject);
2244
+ return pact;
2245
+ function _resumeAfterBody(value) {
2246
+ result = value;
2247
+ do {
2248
+ if (update) {
2249
+ updateValue = update();
2250
+ if (updateValue && updateValue.then && !Mutex_isSettledPact(updateValue)) {
2251
+ updateValue.then(_resumeAfterUpdate).then(void 0, reject);
2252
+ return;
2253
+ }
2254
+ }
2255
+ shouldContinue = test();
2256
+ if (!shouldContinue || Mutex_isSettledPact(shouldContinue) && !shouldContinue.v) {
2257
+ Mutex_settle(pact, 1, result);
2258
+ return;
2259
+ }
2260
+ if (shouldContinue.then) {
2261
+ shouldContinue.then(_resumeAfterTest).then(void 0, reject);
2262
+ return;
2263
+ }
2264
+ result = body();
2265
+ if (Mutex_isSettledPact(result)) {
2266
+ result = result.v;
2267
+ }
2268
+ } while (!result || !result.then);
2269
+ result.then(_resumeAfterBody).then(void 0, reject);
2270
+ }
2271
+ function _resumeAfterTest(shouldContinue) {
2272
+ if (shouldContinue) {
2273
+ result = body();
2274
+ if (result && result.then) {
2275
+ result.then(_resumeAfterBody).then(void 0, reject);
2276
+ } else {
2277
+ _resumeAfterBody(result);
2278
+ }
2279
+ } else {
2280
+ Mutex_settle(pact, 1, result);
2281
+ }
2282
+ }
2283
+ function _resumeAfterUpdate() {
2284
+ if (shouldContinue = test()) {
2285
+ if (shouldContinue.then) {
2286
+ shouldContinue.then(_resumeAfterTest).then(void 0, reject);
2287
+ } else {
2288
+ _resumeAfterTest(shouldContinue);
2289
+ }
2290
+ } else {
2291
+ Mutex_settle(pact, 1, result);
2292
+ }
2293
+ }
2294
+ }
2295
+ function Mutex_continue(value, then) {
2296
+ return value && value.then ? value.then(then) : then(value);
2297
+ }
2298
+ function Mutex_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2299
+ function Mutex_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, Mutex_toPropertyKey(descriptor.key), descriptor); } }
2300
+ function Mutex_createClass(Constructor, protoProps, staticProps) { if (protoProps) Mutex_defineProperties(Constructor.prototype, protoProps); if (staticProps) Mutex_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
2301
+ function Mutex_toPropertyKey(arg) { var key = Mutex_toPrimitive(arg, "string"); return Mutex_typeof(key) === "symbol" ? key : String(key); }
2302
+ function Mutex_toPrimitive(input, hint) { if (Mutex_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (Mutex_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
2303
+ /**
2304
+ * A lightweight mutex. (Other libraries contain too many features and we want to keep the size upload-js down).
2305
+ *
2306
+ * Characteristics:
2307
+ * - Non-reentrant.
2308
+ * - Unfair. (Multiple callers awaiting 'acquire' will be granted the mutex in no order.)
2309
+ * - When calling `safe` consecutively with no 'awaits' in-between, the current context will synchronously acquire
2310
+ * the mutex every time.
2311
+ */
2312
+ var Mutex = /*#__PURE__*/function () {
2313
+ function Mutex() {
2314
+ Mutex_classCallCheck(this, Mutex);
2315
+ this.mutex = undefined;
2316
+ this.resolver = undefined;
2317
+ }
2318
+ Mutex_createClass(Mutex, [{
2319
+ key: "safe",
2320
+ value: function safe(callback) {
2321
+ try {
2322
+ var _this2 = this;
2323
+ return Mutex_await(_this2.acquire(), function () {
2324
+ return Mutex_finallyRethrows(callback, function (_wasThrown, _result) {
2325
+ _this2.release();
2326
+ return Mutex_rethrow(_wasThrown, _result);
2327
+ });
2328
+ });
2329
+ } catch (e) {
2330
+ return Promise.reject(e);
2331
+ }
2332
+ }
2333
+ }, {
2334
+ key: "acquire",
2335
+ value: function acquire() {
2336
+ try {
2337
+ var _this4 = this;
2338
+ // Loop necessary for when multiple calls are made to 'acquire' before a 'release' is called, else the call to
2339
+ // 'release' will resume every caller currently waiting on 'acquire'.
2340
+ return Mutex_continue(Mutex_for(function () {
2341
+ return _this4.mutex !== undefined;
2342
+ }, void 0, function () {
2343
+ return Mutex_awaitIgnored(_this4.mutex);
2344
+ }), function () {
2345
+ _this4.mutex = new Promise(function (resolve) {
2346
+ _this4.resolver = resolve;
2347
+ });
2348
+ });
2349
+ } catch (e) {
2350
+ return Promise.reject(e);
2351
+ }
2352
+ }
2353
+ }, {
2354
+ key: "release",
2355
+ value: function release() {
2356
+ if (this.resolver === undefined) {
2357
+ throw new Error("Unable to release mutex: already released.");
2358
+ }
2359
+ this.resolver();
2360
+ this.resolver = undefined;
2361
+ this.mutex = undefined;
2362
+ }
2363
+ }]);
2364
+ return Mutex;
2365
+ }();
2366
+ ;// CONCATENATED MODULE: ./src/public/browser/AuthManagerBrowser.ts
2367
+ function AuthManagerBrowser_typeof(obj) { "@babel/helpers - typeof"; return AuthManagerBrowser_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; }, AuthManagerBrowser_typeof(obj); }
2368
+ function AuthManagerBrowser_defineProperty(obj, key, value) { key = AuthManagerBrowser_toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2369
+ function AuthManagerBrowser_empty() {}
2370
+ function AuthManagerBrowser_awaitIgnored(value, direct) {
2371
+ if (!direct) {
2372
+ return value && value.then ? value.then(AuthManagerBrowser_empty) : Promise.resolve();
2373
+ }
2374
+ }
2375
+ function AuthManagerBrowser_await(value, then, direct) {
2376
+ if (direct) {
2377
+ return then ? then(value) : value;
2378
+ }
2379
+ if (!value || !value.then) {
2380
+ value = Promise.resolve(value);
2381
+ }
2382
+ return then ? value.then(then) : value;
2383
+ }
2384
+ function AuthManagerBrowser_async(f) {
2385
+ return function () {
2386
+ for (var args = [], i = 0; i < arguments.length; i++) {
2387
+ args[i] = arguments[i];
2388
+ }
2389
+ try {
2390
+ return Promise.resolve(f.apply(this, args));
2391
+ } catch (e) {
2392
+ return Promise.reject(e);
2393
+ }
2394
+ };
2395
+ }
2396
+ function AuthManagerBrowser_catch(body, recover) {
2397
+ try {
2398
+ var result = body();
2399
+ } catch (e) {
2400
+ return recover(e);
2401
+ }
2402
+ if (result && result.then) {
2403
+ return result.then(void 0, recover);
2404
+ }
2405
+ return result;
2406
+ }
2407
+ function AuthManagerBrowser_rethrow(thrown, value) {
2408
+ if (thrown) throw value;
2409
+ return value;
2410
+ }
2411
+ function AuthManagerBrowser_finallyRethrows(body, finalizer) {
2412
+ try {
2413
+ var result = body();
2414
+ } catch (e) {
2415
+ return finalizer(true, e);
2416
+ }
2417
+ if (result && result.then) {
2418
+ return result.then(finalizer.bind(null, false), finalizer.bind(null, true));
2419
+ }
2420
+ return finalizer(false, result);
2421
+ }
2422
+ function AuthManagerBrowser_continueIgnored(value) {
2423
+ if (value && value.then) {
2424
+ return value.then(AuthManagerBrowser_empty);
2425
+ }
2426
+ }
2427
+ function AuthManagerBrowser_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2428
+ function AuthManagerBrowser_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, AuthManagerBrowser_toPropertyKey(descriptor.key), descriptor); } }
2429
+ function AuthManagerBrowser_createClass(Constructor, protoProps, staticProps) { if (protoProps) AuthManagerBrowser_defineProperties(Constructor.prototype, protoProps); if (staticProps) AuthManagerBrowser_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
2430
+ function AuthManagerBrowser_toPropertyKey(arg) { var key = AuthManagerBrowser_toPrimitive(arg, "string"); return AuthManagerBrowser_typeof(key) === "symbol" ? key : String(key); }
2431
+ function AuthManagerBrowser_toPrimitive(input, hint) { if (AuthManagerBrowser_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (AuthManagerBrowser_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
2432
+ function AuthManagerBrowser_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) AuthManagerBrowser_setPrototypeOf(subClass, superClass); }
2433
+ function AuthManagerBrowser_setPrototypeOf(o, p) { AuthManagerBrowser_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return AuthManagerBrowser_setPrototypeOf(o, p); }
2434
+ function AuthManagerBrowser_createSuper(Derived) { var hasNativeReflectConstruct = AuthManagerBrowser_isNativeReflectConstruct(); return function _createSuperInternal() { var Super = AuthManagerBrowser_getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = AuthManagerBrowser_getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return AuthManagerBrowser_possibleConstructorReturn(this, result); }; }
2435
+ function AuthManagerBrowser_possibleConstructorReturn(self, call) { if (call && (AuthManagerBrowser_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 AuthManagerBrowser_assertThisInitialized(self); }
2436
+ function AuthManagerBrowser_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
2437
+ function AuthManagerBrowser_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; } }
2438
+ function AuthManagerBrowser_getPrototypeOf(o) { AuthManagerBrowser_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return AuthManagerBrowser_getPrototypeOf(o); }
2439
+
2440
+
2441
+
2442
+
2443
+ var AuthManager = /*#__PURE__*/function (_BaseAPI) {
2444
+ AuthManagerBrowser_inherits(AuthManager, _BaseAPI);
2445
+ var _super = AuthManagerBrowser_createSuper(AuthManager);
2446
+ function AuthManager(config) {
2447
+ var _this;
2448
+ AuthManagerBrowser_classCallCheck(this, AuthManager);
2449
+ var _a, _b;
2450
+ _this = _super.call(this, config);
2451
+ _this.authSessionMutex = new Mutex();
2452
+ _this.contentType = "content-type";
2453
+ _this.contentTypeJson = "application/json";
2454
+ _this.contentTypeText = "text/plain";
2455
+ _this.minJwtTtlSeconds = 10;
2456
+ _this.retryAuthAfterErrorSeconds = 5;
2457
+ _this.refreshBeforeExpirySeconds = 20;
2458
+ var accountId;
2459
+ if (BaseAPI.specialApiKeys.includes(config.apiKey)) {
2460
+ accountId = BaseAPI.specialApiKeyAccountId;
2461
+ } else {
2462
+ accountId = (_b = (_a = config.apiKey.split("_")[1]) === null || _a === void 0 ? void 0 : _a.substr(0, BaseAPI.accountIdLength)) !== null && _b !== void 0 ? _b : "";
2463
+ if (accountId.length !== BaseAPI.accountIdLength) {
2464
+ throw new Error("Invalid Bytescale API key.");
2465
+ }
2466
+ }
2467
+ _this.accessTokenUrl = "".concat(BytescaleApiClientConfigResolver.getCdnUrl(config), "/api/v1/access_tokens/").concat(accountId);
2468
+ return _this;
2469
+ }
2470
+ AuthManagerBrowser_createClass(AuthManager, [{
2471
+ key: "isAuthSessionActive",
2472
+ value: function isAuthSessionActive() {
2473
+ return AuthSessionState.session !== undefined;
2474
+ }
2475
+ }, {
2476
+ key: "beginAuthSession",
2477
+ value: function beginAuthSession(authUrl, authHeaders) {
2478
+ try {
2479
+ var _this3 = this;
2480
+ var newSession = {
2481
+ accessToken: undefined,
2482
+ accessTokenRefreshHandle: undefined,
2483
+ authUrl: authUrl,
2484
+ authHeaders: authHeaders,
2485
+ isActive: true
2486
+ };
2487
+ return AuthManagerBrowser_await(_this3.authSessionMutex.safe(AuthManagerBrowser_async(function () {
2488
+ // We check both 'session' and 'sessionDisposing' here, as we don't want to call 'beginAuthSession' until the session is fully disposed.
2489
+ if (_this3.isAuthSessionActive()) {
2490
+ throw new Error("Auth session already active: see AuthManager.isAuthSessionActive(). Please call 'await endAuthSession()' and then 'await beginAuthSession(...)' if you want to start a new auth session.");
2491
+ }
2492
+ AuthSessionState.session = newSession;
2493
+ return AuthManagerBrowser_await();
2494
+ })), function () {
2495
+ // IMPORTANT: must be called outside the above, else re-entrant deadlock will occur.
2496
+ return AuthManagerBrowser_awaitIgnored(_this3.refreshAccessToken(newSession));
2497
+ });
2498
+ } catch (e) {
2499
+ return Promise.reject(e);
2500
+ }
2501
+ }
2502
+ }, {
2503
+ key: "endAuthSession",
2504
+ value: function endAuthSession() {
2505
+ try {
2506
+ var _this5 = this;
2507
+ return AuthManagerBrowser_awaitIgnored(_this5.authSessionMutex.safe(AuthManagerBrowser_async(function () {
2508
+ if (AuthSessionState.session === undefined) {
2509
+ return;
2510
+ }
2511
+ var session = AuthSessionState.session;
2512
+ AuthSessionState.session = undefined;
2513
+ session.isActive = false;
2514
+ if (session.accessTokenRefreshHandle !== undefined) {
2515
+ clearTimeout(session.accessTokenRefreshHandle);
2516
+ }
2517
+ return AuthManagerBrowser_awaitIgnored(_this5.deleteAccessToken());
2518
+ })));
2519
+ } catch (e) {
2520
+ return Promise.reject(e);
2521
+ }
2522
+ }
2523
+ }, {
2524
+ key: "refreshAccessToken",
2525
+ value: function refreshAccessToken(session) {
2526
+ try {
2527
+ var _this7 = this;
2528
+ return AuthManagerBrowser_awaitIgnored(_this7.authSessionMutex.safe(AuthManagerBrowser_async(function () {
2529
+ if (!session.isActive) {
2530
+ return;
2531
+ }
2532
+ var timeout = _this7.retryAuthAfterErrorSeconds;
2533
+ return AuthManagerBrowser_continueIgnored(AuthManagerBrowser_finallyRethrows(function () {
2534
+ return AuthManagerBrowser_catch(function () {
2535
+ var _getAccessToken = _this7.getAccessToken,
2536
+ _session$authUrl = session.authUrl;
2537
+ return AuthManagerBrowser_await(session.authHeaders(), function (_session$authHeaders) {
2538
+ return AuthManagerBrowser_await(_getAccessToken.call(_this7, _session$authUrl, _session$authHeaders), function (jwt) {
2539
+ return AuthManagerBrowser_await(_this7.setAccessToken(jwt), function (setTokenResult) {
2540
+ var desiredTtl = setTokenResult.ttlSeconds - _this7.refreshBeforeExpirySeconds;
2541
+ timeout = Math.max(desiredTtl, _this7.minJwtTtlSeconds);
2542
+ if (desiredTtl !== timeout) {
2543
+ ConsoleUtils.warn("JWT expiration is too short: waiting for ".concat(timeout, " seconds before refreshing."));
2544
+ }
2545
+ session.accessToken = setTokenResult.accessToken;
2546
+ });
2547
+ });
2548
+ });
2549
+ }, function (e) {
2550
+ // Use 'error' instead of 'debug' so that the user sees error messages.
2551
+ ConsoleUtils.error("Error when refreshing access token: ".concat(e));
2552
+ });
2553
+ }, function (_wasThrown, _result) {
2554
+ session.accessTokenRefreshHandle = window.setTimeout(function () {
2555
+ _this7.refreshAccessToken(session).then(function () {}, function (e) {
2556
+ return ConsoleUtils.error("Unexpected error when refreshing access token: ".concat(e));
2557
+ });
2558
+ }, timeout * 1000);
2559
+ return AuthManagerBrowser_rethrow(_wasThrown, _result);
2560
+ }));
2561
+ })));
2562
+ } catch (e) {
2563
+ return Promise.reject(e);
2564
+ }
2565
+ }
2566
+ }, {
2567
+ key: "deleteAccessToken",
2568
+ value: function deleteAccessToken() {
2569
+ try {
2570
+ var _this9 = this;
2571
+ return AuthManagerBrowser_awaitIgnored(_this9.doFetch(_this9.accessTokenUrl, {
2572
+ method: "DELETE",
2573
+ credentials: "include",
2574
+ headers: {}
2575
+ }, true));
2576
+ } catch (e) {
2577
+ return Promise.reject(e);
2578
+ }
2579
+ }
2580
+ }, {
2581
+ key: "setAccessToken",
2582
+ value: function setAccessToken(jwt) {
2583
+ try {
2584
+ var _this11 = this;
2585
+ var request = {
2586
+ accessToken: jwt
2587
+ };
2588
+ return AuthManagerBrowser_await(_this11.doFetch(_this11.accessTokenUrl, {
2589
+ method: "PUT",
2590
+ credentials: "include",
2591
+ headers: AuthManagerBrowser_defineProperty({}, _this11.contentType, _this11.contentTypeJson),
2592
+ body: JSON.stringify(request)
2593
+ }, true), function (response) {
2594
+ return AuthManagerBrowser_await(response.json());
2595
+ });
2596
+ } catch (e) {
2597
+ return Promise.reject(e);
2598
+ }
2599
+ }
2600
+ }, {
2601
+ key: "getAccessToken",
2602
+ value: function getAccessToken(authUrl, headers) {
2603
+ try {
2604
+ var _this13 = this;
2605
+ var endpointName = "Your auth API endpoint";
2606
+ var requiredContentType = _this13.contentTypeText;
2607
+ return AuthManagerBrowser_await(_this13.doFetch(authUrl, {
2608
+ method: "GET",
2609
+ headers: headers
2610
+ }, false), function (result) {
2611
+ if (result.headers.get(_this13.contentType) !== requiredContentType) {
2612
+ throw new Error("".concat(endpointName, " returned an unsupported '").concat(_this13.contentType, "' response header: please return '").concat(requiredContentType, "'."));
2613
+ }
2614
+ return AuthManagerBrowser_await(result.text(), function (jwt) {
2615
+ if (jwt.length === 0) {
2616
+ throw new Error("".concat(endpointName, " returned an empty string. Please return a valid JWT instead."));
2617
+ }
2618
+ if (jwt.trim().length !== jwt.length) {
2619
+ // Whitespace can be a nightmare to spot/debug, so we fail early here.
2620
+ throw new Error("".concat(endpointName, " returned whitespace around the JWT, please remove it."));
2621
+ }
2622
+ return jwt;
2623
+ });
2624
+ });
2625
+ } catch (e) {
2626
+ return Promise.reject(e);
2627
+ }
2628
+ }
2629
+ }]);
2630
+ return AuthManager;
2631
+ }(BaseAPI);
2632
+ ;// CONCATENATED MODULE: ./src/public/browser/index.ts
2633
+
1927
2634
 
1928
2635
  ;// CONCATENATED MODULE: ./src/index.browser.ts
1929
2636
  /* tslint:disable */
1930
2637
  /* eslint-disable */
1931
2638
 
1932
2639
 
1933
-
1934
2640
  module.exports = __lib_exports__;
1935
2641
  /******/ })()
1936
2642
  ;