@bytescale/sdk 1.2.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 (48) hide show
  1. package/dist/browser/cjs/main.js +891 -179
  2. package/dist/node/cjs/main.js +405 -186
  3. package/dist/node/esm/main.mjs +411 -188
  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 +28 -0
  25. package/dist/types/public/shared/UrlBuilderTypes.d.ts +173 -0
  26. package/dist/types/{generated → public/shared/generated}/runtime.d.ts +44 -14
  27. package/dist/types/public/shared/index.d.ts +4 -0
  28. package/package.json +2 -2
  29. package/tests/ChunkedStream.test.ts +1 -1
  30. package/tests/UrlBuilder.test.ts +168 -0
  31. package/dist/types/index.browser.d.ts +0 -3
  32. package/dist/types/index.node.d.ts +0 -3
  33. package/dist/types/uploads/private/TypeUtils.d.ts +0 -1
  34. package/dist/types/uploads/private/model/UploadManagerInterface.d.ts +0 -5
  35. package/dist/types/uploads/public/shared/index.d.ts +0 -1
  36. /package/dist/types/{uploads/private → private}/NodeChunkedStream.d.ts +0 -0
  37. /package/dist/types/{uploads/private → private}/StreamUtils.d.ts +0 -0
  38. /package/dist/types/{uploads/private → private}/model/AddCancellationHandler.d.ts +0 -0
  39. /package/dist/types/{uploads/private → private}/model/OnPartProgress.d.ts +0 -0
  40. /package/dist/types/{uploads/private → private}/model/PreUploadInfo.d.ts +0 -0
  41. /package/dist/types/{uploads/private → private}/model/PutUploadPartResult.d.ts +0 -0
  42. /package/dist/types/{generated → public/shared/generated}/apis/FileApi.d.ts +0 -0
  43. /package/dist/types/{generated → public/shared/generated}/apis/FolderApi.d.ts +0 -0
  44. /package/dist/types/{generated → public/shared/generated}/apis/JobApi.d.ts +0 -0
  45. /package/dist/types/{generated → public/shared/generated}/apis/UploadApi.d.ts +0 -0
  46. /package/dist/types/{generated → public/shared/generated}/apis/index.d.ts +0 -0
  47. /package/dist/types/{generated → public/shared/generated}/index.d.ts +0 -0
  48. /package/dist/types/{generated → public/shared/generated}/models/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,19 +286,34 @@ 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
319
  var prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
@@ -297,22 +346,15 @@ function querystringSingleKey(key, value) {
297
346
  }
298
347
  var JSONApiResponse = /*#__PURE__*/function () {
299
348
  function JSONApiResponse(raw) {
300
- var transformer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (jsonValue) {
301
- return jsonValue;
302
- };
303
- _classCallCheck(this, JSONApiResponse);
349
+ runtime_classCallCheck(this, JSONApiResponse);
304
350
  this.raw = raw;
305
- this.transformer = transformer;
306
351
  }
307
- _createClass(JSONApiResponse, [{
352
+ runtime_createClass(JSONApiResponse, [{
308
353
  key: "value",
309
354
  value: function value() {
310
355
  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
- });
356
+ var _this10 = this;
357
+ return _await(_this10.raw.json());
316
358
  } catch (e) {
317
359
  return Promise.reject(e);
318
360
  }
@@ -322,10 +364,10 @@ var JSONApiResponse = /*#__PURE__*/function () {
322
364
  }();
323
365
  var VoidApiResponse = /*#__PURE__*/function () {
324
366
  function VoidApiResponse(raw) {
325
- _classCallCheck(this, VoidApiResponse);
367
+ runtime_classCallCheck(this, VoidApiResponse);
326
368
  this.raw = raw;
327
369
  }
328
- _createClass(VoidApiResponse, [{
370
+ runtime_createClass(VoidApiResponse, [{
329
371
  key: "value",
330
372
  value: function value() {
331
373
  return _await(undefined);
@@ -335,10 +377,10 @@ var VoidApiResponse = /*#__PURE__*/function () {
335
377
  }();
336
378
  var BinaryResult = /*#__PURE__*/function () {
337
379
  function BinaryResult(raw) {
338
- _classCallCheck(this, BinaryResult);
380
+ runtime_classCallCheck(this, BinaryResult);
339
381
  this.raw = raw;
340
382
  }
341
- _createClass(BinaryResult, [{
383
+ runtime_createClass(BinaryResult, [{
342
384
  key: "stream",
343
385
  value: function stream() {
344
386
  if (this.raw.bodyUsed) {
@@ -353,8 +395,8 @@ var BinaryResult = /*#__PURE__*/function () {
353
395
  key: "text",
354
396
  value: function text() {
355
397
  try {
356
- var _this10 = this;
357
- return _await(_this10.raw.text());
398
+ var _this12 = this;
399
+ return _await(_this12.raw.text());
358
400
  } catch (e) {
359
401
  return Promise.reject(e);
360
402
  }
@@ -363,8 +405,8 @@ var BinaryResult = /*#__PURE__*/function () {
363
405
  key: "blob",
364
406
  value: function blob() {
365
407
  try {
366
- var _this12 = this;
367
- return _await(_this12.raw.blob());
408
+ var _this14 = this;
409
+ return _await(_this14.raw.blob());
368
410
  } catch (e) {
369
411
  return Promise.reject(e);
370
412
  }
@@ -373,8 +415,8 @@ var BinaryResult = /*#__PURE__*/function () {
373
415
  key: "json",
374
416
  value: function json() {
375
417
  try {
376
- var _this14 = this;
377
- return _await(_this14.raw.json());
418
+ var _this16 = this;
419
+ return _await(_this16.raw.json());
378
420
  } catch (e) {
379
421
  return Promise.reject(e);
380
422
  }
@@ -382,7 +424,7 @@ var BinaryResult = /*#__PURE__*/function () {
382
424
  }]);
383
425
  return BinaryResult;
384
426
  }();
385
- ;// CONCATENATED MODULE: ./src/generated/apis/FileApi.ts
427
+ ;// CONCATENATED MODULE: ./src/public/shared/generated/apis/FileApi.ts
386
428
  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
429
  function FileApi_await(value, then, direct) {
388
430
  if (direct) {
@@ -677,7 +719,7 @@ var FileApi = /*#__PURE__*/function (_runtime$BaseAPI) {
677
719
  }]);
678
720
  return FileApi;
679
721
  }(BaseAPI);
680
- ;// CONCATENATED MODULE: ./src/generated/apis/FolderApi.ts
722
+ ;// CONCATENATED MODULE: ./src/public/shared/generated/apis/FolderApi.ts
681
723
  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
724
  function FolderApi_await(value, then, direct) {
683
725
  if (direct) {
@@ -937,7 +979,7 @@ var FolderApi = /*#__PURE__*/function (_runtime$BaseAPI) {
937
979
  }]);
938
980
  return FolderApi;
939
981
  }(BaseAPI);
940
- ;// CONCATENATED MODULE: ./src/generated/apis/JobApi.ts
982
+ ;// CONCATENATED MODULE: ./src/public/shared/generated/apis/JobApi.ts
941
983
  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
984
  function JobApi_await(value, then, direct) {
943
985
  if (direct) {
@@ -1072,7 +1114,7 @@ var JobApi = /*#__PURE__*/function (_runtime$BaseAPI) {
1072
1114
  }]);
1073
1115
  return JobApi;
1074
1116
  }(BaseAPI);
1075
- ;// CONCATENATED MODULE: ./src/generated/apis/UploadApi.ts
1117
+ ;// CONCATENATED MODULE: ./src/public/shared/generated/apis/UploadApi.ts
1076
1118
  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
1119
  function UploadApi_await(value, then, direct) {
1078
1120
  if (direct) {
@@ -1260,53 +1302,170 @@ var UploadApi = /*#__PURE__*/function (_runtime$BaseAPI) {
1260
1302
  }]);
1261
1303
  return UploadApi;
1262
1304
  }(BaseAPI);
1263
- ;// CONCATENATED MODULE: ./src/generated/apis/index.ts
1305
+ ;// CONCATENATED MODULE: ./src/public/shared/generated/apis/index.ts
1264
1306
  /* tslint:disable */
1265
1307
  /* eslint-disable */
1266
1308
 
1267
1309
 
1268
1310
 
1269
1311
 
1270
- ;// CONCATENATED MODULE: ./src/generated/index.ts
1312
+ ;// CONCATENATED MODULE: ./src/public/shared/generated/index.ts
1271
1313
  /* tslint:disable */
1272
1314
  /* eslint-disable */
1273
1315
 
1274
1316
 
1275
1317
 
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;
1318
+ ;// CONCATENATED MODULE: ./src/public/shared/CommonTypes.ts
1319
+ /**
1320
+ * Workaround for tsc aliases, where we cannot export implementation-less modules in our dists.
1321
+ */
1322
+ var CommonTypesNoOp = false;
1323
+ ;// CONCATENATED MODULE: ./src/private/TypeUtils.ts
1324
+ function assertUnreachable(x) {
1325
+ throw new Error("Didn't expect to get here: ".concat(JSON.stringify(x)));
1326
+ }
1327
+ function isDefinedEntry(object) {
1328
+ return object[1] !== undefined && object[1] !== null;
1329
+ }
1330
+ ;// CONCATENATED MODULE: ./src/public/shared/UrlBuilder.ts
1331
+ 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); }
1332
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
1333
+ 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."); }
1334
+ 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; } }
1335
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
1336
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
1337
+ 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."); }
1338
+ 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); }
1339
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
1340
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
1341
+ 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; }
1342
+ function UrlBuilder_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1343
+ 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); } }
1344
+ 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; }
1345
+ function UrlBuilder_toPropertyKey(arg) { var key = UrlBuilder_toPrimitive(arg, "string"); return UrlBuilder_typeof(key) === "symbol" ? key : String(key); }
1346
+ 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); }
1347
+
1348
+
1349
+ var UrlBuilder = /*#__PURE__*/function () {
1350
+ function UrlBuilder(config) {
1351
+ UrlBuilder_classCallCheck(this, UrlBuilder);
1352
+ var _a;
1353
+ this.cdnUrl = (_a = config === null || config === void 0 ? void 0 : config.cdnUrl) !== null && _a !== void 0 ? _a : BytescaleApiClientConfigResolver.defaultCdnUrl;
1302
1354
  }
1303
- return Model_createClass(CancelledError);
1304
- }( /*#__PURE__*/Model_wrapNativeSuper(Error));
1305
- ;// CONCATENATED MODULE: ./src/uploads/public/shared/index.ts
1355
+ /**
1356
+ * Builds a URL to either a raw file or a transformed file.
1357
+ *
1358
+ * Example 1) Raw file:
1359
+ *
1360
+ * new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg" })
1361
+ *
1362
+ * Example 2) Image resized to 500x500:
1363
+ *
1364
+ * new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", transformation: { type: "image", params: { w: 500, h: 500, fit: "crop" } } })
1365
+ *
1366
+ * Example 3) Image resized to 500x500, which is privately accessible (i.e. requires 'AuthManager.beginAuthSession' before it can be accessed):
1367
+ *
1368
+ * new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", transformation: { type: "image", params: { w: 500, h: 500, fit: "crop" } }, auth: true })
1369
+ */
1370
+ UrlBuilder_createClass(UrlBuilder, [{
1371
+ key: "url",
1372
+ value: function url(params) {
1373
+ var _a;
1374
+ return ((_a = params.options) === null || _a === void 0 ? void 0 : _a.transformation) === undefined ? this.raw(params) : this.transformation(params, params.options.transformation);
1375
+ }
1376
+ }, {
1377
+ key: "raw",
1378
+ value: function raw(params) {
1379
+ var _a;
1380
+ var baseUrl = this.getBaseUrl(params, "raw");
1381
+ var commonParams = this.getCommonQueryParams((_a = params.options) !== null && _a !== void 0 ? _a : {});
1382
+ return this.addQueryParams(baseUrl, commonParams);
1383
+ }
1384
+ }, {
1385
+ key: "transformation",
1386
+ value: function transformation(params, trans) {
1387
+ var _a;
1388
+ var baseUrl = this.getBaseUrl(params, trans.type === "preset" ? trans.preset : trans.type);
1389
+ var transParams = this.getTransformationParams(trans, {
1390
+ cachePermanently: "cache_perm"
1391
+ });
1392
+ var commonParams = this.getCommonQueryParams((_a = params.options) !== null && _a !== void 0 ? _a : {});
1393
+ return this.addQueryParams(baseUrl, [].concat(_toConsumableArray(commonParams), _toConsumableArray(transParams)));
1394
+ }
1395
+ }, {
1396
+ key: "getBaseUrl",
1397
+ value: function getBaseUrl(params, prefix) {
1398
+ return "".concat(this.cdnUrl, "/").concat(params.accountId, "/").concat(prefix).concat(params.filePath);
1399
+ }
1400
+ }, {
1401
+ key: "getCommonQueryParams",
1402
+ value: function getCommonQueryParams(params) {
1403
+ return this.makeQueryParams(["auth", "cache", "cacheTtl", "version", "forceDownloadPrompt"], {
1404
+ cacheTtl: "cache_ttl",
1405
+ forceDownloadPrompt: "download"
1406
+ })(params);
1407
+ }
1408
+ }, {
1409
+ key: "makeQueryParams",
1410
+ value: function makeQueryParams(keys, keyOverrides) {
1411
+ return function (data) {
1412
+ var result = [];
1413
+ keys.forEach(function (key) {
1414
+ var _a;
1415
+ var value = data[key];
1416
+ if (value !== undefined) {
1417
+ result.push([(_a = keyOverrides[key]) !== null && _a !== void 0 ? _a : key, value.toString()]);
1418
+ }
1419
+ });
1420
+ return result;
1421
+ };
1422
+ }
1423
+ }, {
1424
+ key: "getTransformationParams",
1425
+ value: function getTransformationParams(trans, keyRewrites) {
1426
+ if (trans.params === undefined) {
1427
+ return [];
1428
+ }
1429
+ var serializeObj = function serializeObj(obj) {
1430
+ return Object.entries(obj).filter(isDefinedEntry).map(function (_ref) {
1431
+ var _ref2 = _slicedToArray(_ref, 2),
1432
+ key = _ref2[0],
1433
+ value = _ref2[1];
1434
+ var _a;
1435
+ return [(_a = keyRewrites[key]) !== null && _a !== void 0 ? _a : key, value.toString()];
1436
+ });
1437
+ };
1438
+ return Array.isArray(trans.params) ? trans.params.flatMap(serializeObj) : serializeObj(trans.params);
1439
+ }
1440
+ }, {
1441
+ key: "addQueryParams",
1442
+ value: function addQueryParams(baseUrl, params) {
1443
+ if (params.length === 0) {
1444
+ return baseUrl;
1445
+ }
1446
+ return "".concat(baseUrl, "?").concat(params.map(function (_ref3) {
1447
+ var _ref4 = _slicedToArray(_ref3, 2),
1448
+ key = _ref4[0],
1449
+ value = _ref4[1];
1450
+ return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(value));
1451
+ }).join("&"));
1452
+ }
1453
+ }]);
1454
+ return UrlBuilder;
1455
+ }();
1456
+ ;// CONCATENATED MODULE: ./src/public/shared/UrlBuilderTypes.ts
1457
+ /**
1458
+ * Workaround for tsc aliases, where we cannot export implementation-less modules in our dists.
1459
+ */
1460
+ var UrlBuilderTypesNoOp = false;
1461
+ ;// CONCATENATED MODULE: ./src/public/shared/index.ts
1462
+
1463
+
1306
1464
 
1307
- ;// CONCATENATED MODULE: ./src/uploads/private/UploadManagerBase.ts
1465
+
1466
+ ;// CONCATENATED MODULE: ./src/private/UploadManagerBase.ts
1308
1467
  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) {
1468
+ function _async(f) {
1310
1469
  return function () {
1311
1470
  for (var args = [], i = 0; i < arguments.length; i++) {
1312
1471
  args[i] = arguments[i];
@@ -1478,12 +1637,12 @@ function _continueIgnored(value) {
1478
1637
  return value.then(UploadManagerBase_empty);
1479
1638
  }
1480
1639
  }
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; }
1640
+ function UploadManagerBase_toConsumableArray(arr) { return UploadManagerBase_arrayWithoutHoles(arr) || UploadManagerBase_iterableToArray(arr) || UploadManagerBase_unsupportedIterableToArray(arr) || UploadManagerBase_nonIterableSpread(); }
1641
+ 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."); }
1642
+ 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); }
1643
+ function UploadManagerBase_iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
1644
+ function UploadManagerBase_arrayWithoutHoles(arr) { if (Array.isArray(arr)) return UploadManagerBase_arrayLikeToArray(arr); }
1645
+ 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
1646
  function UploadManagerBase_empty() {}
1488
1647
  function _awaitIgnored(value, direct) {
1489
1648
  if (!direct) {
@@ -1523,7 +1682,6 @@ function UploadManagerBase_createClass(Constructor, protoProps, staticProps) { i
1523
1682
  function UploadManagerBase_toPropertyKey(arg) { var key = UploadManagerBase_toPrimitive(arg, "string"); return UploadManagerBase_typeof(key) === "symbol" ? key : String(key); }
1524
1683
  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
1684
 
1526
-
1527
1685
  /**
1528
1686
  * Methods common to UploadManagerNode and UploadManagerBrowser.
1529
1687
  */
@@ -1550,13 +1708,13 @@ var UploadManagerBase = /*#__PURE__*/function () {
1550
1708
  onProgress(0);
1551
1709
  return UploadManagerBase_await(_this2.beginUpload(request, preUploadInfo), function (uploadInfo) {
1552
1710
  var partCount = uploadInfo.uploadParts.count;
1553
- var parts = _toConsumableArray(Array(partCount).keys());
1711
+ var parts = UploadManagerBase_toConsumableArray(Array(partCount).keys());
1554
1712
  var _this2$makeCancellati = _this2.makeCancellationMethods(),
1555
1713
  cancel = _this2$makeCancellati.cancel,
1556
1714
  addCancellationHandler = _this2$makeCancellati.addCancellationHandler;
1557
1715
  var intervalHandle = setInterval(_this2.onIntervalTick(request, cancel), _this2.intervalMs);
1558
1716
  return UploadManagerBase_continue(_finallyRethrows(function () {
1559
- return UploadManagerBase_await(_this2.mapAsync(parts, preUploadInfo.maxConcurrentUploadParts, UploadManagerBase_async(function (part) {
1717
+ return UploadManagerBase_await(_this2.mapAsync(parts, preUploadInfo.maxConcurrentUploadParts, _async(function (part) {
1560
1718
  return _this2.uploadPart(request, source, part, uploadInfo, onProgress, addCancellationHandler);
1561
1719
  })), function () {
1562
1720
  return _awaitIgnored(_this2.postUpload(init));
@@ -1748,8 +1906,8 @@ var UploadManagerBase = /*#__PURE__*/function () {
1748
1906
  key: "mapAsync",
1749
1907
  value: function mapAsync(items, concurrency, callback) {
1750
1908
  try {
1751
- var workQueue = _toConsumableArray(items);
1752
- return _awaitIgnored(Promise.all(_toConsumableArray(Array(concurrency).keys()).map(UploadManagerBase_async(function () {
1909
+ var workQueue = UploadManagerBase_toConsumableArray(items);
1910
+ return _awaitIgnored(Promise.all(UploadManagerBase_toConsumableArray(Array(concurrency).keys()).map(_async(function () {
1753
1911
  return _continueIgnored(_for(function () {
1754
1912
  return workQueue.length > 0;
1755
1913
  }, void 0, function () {
@@ -1768,11 +1926,7 @@ var UploadManagerBase = /*#__PURE__*/function () {
1768
1926
  }]);
1769
1927
  return UploadManagerBase;
1770
1928
  }();
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
1929
+ ;// CONCATENATED MODULE: ./src/public/browser/UploadManagerBrowser.ts
1776
1930
  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
1931
  function UploadManagerBrowser_await(value, then, direct) {
1778
1932
  if (direct) {
@@ -1923,14 +2077,572 @@ var UploadManager = /*#__PURE__*/function (_UploadManagerBase) {
1923
2077
  }]);
1924
2078
  return UploadManager;
1925
2079
  }(UploadManagerBase);
1926
- ;// CONCATENATED MODULE: ./src/uploads/public/browser/index.ts
2080
+ ;// CONCATENATED MODULE: ./src/private/ConsoleUtils.ts
2081
+ 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); }
2082
+ function ConsoleUtils_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2083
+ 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); } }
2084
+ 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; }
2085
+ function ConsoleUtils_toPropertyKey(arg) { var key = ConsoleUtils_toPrimitive(arg, "string"); return ConsoleUtils_typeof(key) === "symbol" ? key : String(key); }
2086
+ 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); }
2087
+ var ConsoleUtils = /*#__PURE__*/function () {
2088
+ function ConsoleUtils() {
2089
+ ConsoleUtils_classCallCheck(this, ConsoleUtils);
2090
+ }
2091
+ ConsoleUtils_createClass(ConsoleUtils, null, [{
2092
+ key: "error",
2093
+ value: function error(message) {
2094
+ console.error(ConsoleUtils.prefix(message));
2095
+ }
2096
+ }, {
2097
+ key: "warn",
2098
+ value: function warn(message) {
2099
+ console.warn(ConsoleUtils.prefix(message));
2100
+ }
2101
+ }, {
2102
+ key: "prefix",
2103
+ value: function prefix(message) {
2104
+ return "[bytescale-sdk] ".concat(message);
2105
+ }
2106
+ }]);
2107
+ return ConsoleUtils;
2108
+ }();
2109
+ ;// CONCATENATED MODULE: ./src/private/Mutex.ts
2110
+ 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); }
2111
+ function _call(body, then, direct) {
2112
+ if (direct) {
2113
+ return then ? then(body()) : body();
2114
+ }
2115
+ try {
2116
+ var result = Promise.resolve(body());
2117
+ return then ? result.then(then) : result;
2118
+ } catch (e) {
2119
+ return Promise.reject(e);
2120
+ }
2121
+ }
2122
+ function Mutex_rethrow(thrown, value) {
2123
+ if (thrown) throw value;
2124
+ return value;
2125
+ }
2126
+ function Mutex_finallyRethrows(body, finalizer) {
2127
+ try {
2128
+ var result = body();
2129
+ } catch (e) {
2130
+ return finalizer(true, e);
2131
+ }
2132
+ if (result && result.then) {
2133
+ return result.then(finalizer.bind(null, false), finalizer.bind(null, true));
2134
+ }
2135
+ return finalizer(false, result);
2136
+ }
2137
+ function Mutex_await(value, then, direct) {
2138
+ if (direct) {
2139
+ return then ? then(value) : value;
2140
+ }
2141
+ if (!value || !value.then) {
2142
+ value = Promise.resolve(value);
2143
+ }
2144
+ return then ? value.then(then) : value;
2145
+ }
2146
+ function Mutex_empty() {}
2147
+ function Mutex_awaitIgnored(value, direct) {
2148
+ if (!direct) {
2149
+ return value && value.then ? value.then(Mutex_empty) : Promise.resolve();
2150
+ }
2151
+ }
2152
+ function Mutex_settle(pact, state, value) {
2153
+ if (!pact.s) {
2154
+ if (value instanceof Mutex_Pact) {
2155
+ if (value.s) {
2156
+ if (state & 1) {
2157
+ state = value.s;
2158
+ }
2159
+ value = value.v;
2160
+ } else {
2161
+ value.o = Mutex_settle.bind(null, pact, state);
2162
+ return;
2163
+ }
2164
+ }
2165
+ if (value && value.then) {
2166
+ value.then(Mutex_settle.bind(null, pact, state), Mutex_settle.bind(null, pact, 2));
2167
+ return;
2168
+ }
2169
+ pact.s = state;
2170
+ pact.v = value;
2171
+ var observer = pact.o;
2172
+ if (observer) {
2173
+ observer(pact);
2174
+ }
2175
+ }
2176
+ }
2177
+ var Mutex_Pact = /*#__PURE__*/function () {
2178
+ function _Pact() {}
2179
+ _Pact.prototype.then = function (onFulfilled, onRejected) {
2180
+ var result = new _Pact();
2181
+ var state = this.s;
2182
+ if (state) {
2183
+ var callback = state & 1 ? onFulfilled : onRejected;
2184
+ if (callback) {
2185
+ try {
2186
+ Mutex_settle(result, 1, callback(this.v));
2187
+ } catch (e) {
2188
+ Mutex_settle(result, 2, e);
2189
+ }
2190
+ return result;
2191
+ } else {
2192
+ return this;
2193
+ }
2194
+ }
2195
+ this.o = function (_this) {
2196
+ try {
2197
+ var value = _this.v;
2198
+ if (_this.s & 1) {
2199
+ Mutex_settle(result, 1, onFulfilled ? onFulfilled(value) : value);
2200
+ } else if (onRejected) {
2201
+ Mutex_settle(result, 1, onRejected(value));
2202
+ } else {
2203
+ Mutex_settle(result, 2, value);
2204
+ }
2205
+ } catch (e) {
2206
+ Mutex_settle(result, 2, e);
2207
+ }
2208
+ };
2209
+ return result;
2210
+ };
2211
+ return _Pact;
2212
+ }();
2213
+ function Mutex_isSettledPact(thenable) {
2214
+ return thenable instanceof Mutex_Pact && thenable.s & 1;
2215
+ }
2216
+ function Mutex_for(test, update, body) {
2217
+ var stage;
2218
+ for (;;) {
2219
+ var shouldContinue = test();
2220
+ if (Mutex_isSettledPact(shouldContinue)) {
2221
+ shouldContinue = shouldContinue.v;
2222
+ }
2223
+ if (!shouldContinue) {
2224
+ return result;
2225
+ }
2226
+ if (shouldContinue.then) {
2227
+ stage = 0;
2228
+ break;
2229
+ }
2230
+ var result = body();
2231
+ if (result && result.then) {
2232
+ if (Mutex_isSettledPact(result)) {
2233
+ result = result.s;
2234
+ } else {
2235
+ stage = 1;
2236
+ break;
2237
+ }
2238
+ }
2239
+ if (update) {
2240
+ var updateValue = update();
2241
+ if (updateValue && updateValue.then && !Mutex_isSettledPact(updateValue)) {
2242
+ stage = 2;
2243
+ break;
2244
+ }
2245
+ }
2246
+ }
2247
+ var pact = new Mutex_Pact();
2248
+ var reject = Mutex_settle.bind(null, pact, 2);
2249
+ (stage === 0 ? shouldContinue.then(_resumeAfterTest) : stage === 1 ? result.then(_resumeAfterBody) : updateValue.then(_resumeAfterUpdate)).then(void 0, reject);
2250
+ return pact;
2251
+ function _resumeAfterBody(value) {
2252
+ result = value;
2253
+ do {
2254
+ if (update) {
2255
+ updateValue = update();
2256
+ if (updateValue && updateValue.then && !Mutex_isSettledPact(updateValue)) {
2257
+ updateValue.then(_resumeAfterUpdate).then(void 0, reject);
2258
+ return;
2259
+ }
2260
+ }
2261
+ shouldContinue = test();
2262
+ if (!shouldContinue || Mutex_isSettledPact(shouldContinue) && !shouldContinue.v) {
2263
+ Mutex_settle(pact, 1, result);
2264
+ return;
2265
+ }
2266
+ if (shouldContinue.then) {
2267
+ shouldContinue.then(_resumeAfterTest).then(void 0, reject);
2268
+ return;
2269
+ }
2270
+ result = body();
2271
+ if (Mutex_isSettledPact(result)) {
2272
+ result = result.v;
2273
+ }
2274
+ } while (!result || !result.then);
2275
+ result.then(_resumeAfterBody).then(void 0, reject);
2276
+ }
2277
+ function _resumeAfterTest(shouldContinue) {
2278
+ if (shouldContinue) {
2279
+ result = body();
2280
+ if (result && result.then) {
2281
+ result.then(_resumeAfterBody).then(void 0, reject);
2282
+ } else {
2283
+ _resumeAfterBody(result);
2284
+ }
2285
+ } else {
2286
+ Mutex_settle(pact, 1, result);
2287
+ }
2288
+ }
2289
+ function _resumeAfterUpdate() {
2290
+ if (shouldContinue = test()) {
2291
+ if (shouldContinue.then) {
2292
+ shouldContinue.then(_resumeAfterTest).then(void 0, reject);
2293
+ } else {
2294
+ _resumeAfterTest(shouldContinue);
2295
+ }
2296
+ } else {
2297
+ Mutex_settle(pact, 1, result);
2298
+ }
2299
+ }
2300
+ }
2301
+ function Mutex_continue(value, then) {
2302
+ return value && value.then ? value.then(then) : then(value);
2303
+ }
2304
+ function Mutex_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2305
+ 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); } }
2306
+ 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; }
2307
+ function Mutex_toPropertyKey(arg) { var key = Mutex_toPrimitive(arg, "string"); return Mutex_typeof(key) === "symbol" ? key : String(key); }
2308
+ 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); }
2309
+ /**
2310
+ * A lightweight mutex. (Other libraries contain too many features and we want to keep the size upload-js down).
2311
+ *
2312
+ * Characteristics:
2313
+ * - Non-reentrant.
2314
+ * - Unfair. (Multiple callers awaiting 'acquire' will be granted the mutex in no order.)
2315
+ * - When calling `safe` consecutively with no 'awaits' in-between, the current context will synchronously acquire
2316
+ * the mutex every time.
2317
+ */
2318
+ var Mutex = /*#__PURE__*/function () {
2319
+ function Mutex() {
2320
+ Mutex_classCallCheck(this, Mutex);
2321
+ this.mutex = undefined;
2322
+ this.resolver = undefined;
2323
+ }
2324
+ Mutex_createClass(Mutex, [{
2325
+ key: "safe",
2326
+ value: function safe(callback) {
2327
+ try {
2328
+ var _this2 = this;
2329
+ return Mutex_await(_this2.acquire(), function () {
2330
+ return Mutex_finallyRethrows(callback, function (_wasThrown, _result) {
2331
+ _this2.release();
2332
+ return Mutex_rethrow(_wasThrown, _result);
2333
+ });
2334
+ });
2335
+ } catch (e) {
2336
+ return Promise.reject(e);
2337
+ }
2338
+ }
2339
+ }, {
2340
+ key: "acquire",
2341
+ value: function acquire() {
2342
+ try {
2343
+ var _this4 = this;
2344
+ // Loop necessary for when multiple calls are made to 'acquire' before a 'release' is called, else the call to
2345
+ // 'release' will resume every caller currently waiting on 'acquire'.
2346
+ return Mutex_continue(Mutex_for(function () {
2347
+ return _this4.mutex !== undefined;
2348
+ }, void 0, function () {
2349
+ return Mutex_awaitIgnored(_this4.mutex);
2350
+ }), function () {
2351
+ _this4.mutex = new Promise(function (resolve) {
2352
+ _this4.resolver = resolve;
2353
+ });
2354
+ });
2355
+ } catch (e) {
2356
+ return Promise.reject(e);
2357
+ }
2358
+ }
2359
+ }, {
2360
+ key: "release",
2361
+ value: function release() {
2362
+ if (this.resolver === undefined) {
2363
+ throw new Error("Unable to release mutex: already released.");
2364
+ }
2365
+ this.resolver();
2366
+ this.resolver = undefined;
2367
+ this.mutex = undefined;
2368
+ }
2369
+ }]);
2370
+ return Mutex;
2371
+ }();
2372
+ ;// CONCATENATED MODULE: ./src/public/browser/AuthManagerBrowser.ts
2373
+ 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); }
2374
+ 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; }
2375
+ function AuthManagerBrowser_empty() {}
2376
+ function AuthManagerBrowser_awaitIgnored(value, direct) {
2377
+ if (!direct) {
2378
+ return value && value.then ? value.then(AuthManagerBrowser_empty) : Promise.resolve();
2379
+ }
2380
+ }
2381
+ function AuthManagerBrowser_await(value, then, direct) {
2382
+ if (direct) {
2383
+ return then ? then(value) : value;
2384
+ }
2385
+ if (!value || !value.then) {
2386
+ value = Promise.resolve(value);
2387
+ }
2388
+ return then ? value.then(then) : value;
2389
+ }
2390
+ function AuthManagerBrowser_async(f) {
2391
+ return function () {
2392
+ for (var args = [], i = 0; i < arguments.length; i++) {
2393
+ args[i] = arguments[i];
2394
+ }
2395
+ try {
2396
+ return Promise.resolve(f.apply(this, args));
2397
+ } catch (e) {
2398
+ return Promise.reject(e);
2399
+ }
2400
+ };
2401
+ }
2402
+ function AuthManagerBrowser_catch(body, recover) {
2403
+ try {
2404
+ var result = body();
2405
+ } catch (e) {
2406
+ return recover(e);
2407
+ }
2408
+ if (result && result.then) {
2409
+ return result.then(void 0, recover);
2410
+ }
2411
+ return result;
2412
+ }
2413
+ function AuthManagerBrowser_rethrow(thrown, value) {
2414
+ if (thrown) throw value;
2415
+ return value;
2416
+ }
2417
+ function AuthManagerBrowser_finallyRethrows(body, finalizer) {
2418
+ try {
2419
+ var result = body();
2420
+ } catch (e) {
2421
+ return finalizer(true, e);
2422
+ }
2423
+ if (result && result.then) {
2424
+ return result.then(finalizer.bind(null, false), finalizer.bind(null, true));
2425
+ }
2426
+ return finalizer(false, result);
2427
+ }
2428
+ function AuthManagerBrowser_continueIgnored(value) {
2429
+ if (value && value.then) {
2430
+ return value.then(AuthManagerBrowser_empty);
2431
+ }
2432
+ }
2433
+ function AuthManagerBrowser_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2434
+ 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); } }
2435
+ 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; }
2436
+ function AuthManagerBrowser_toPropertyKey(arg) { var key = AuthManagerBrowser_toPrimitive(arg, "string"); return AuthManagerBrowser_typeof(key) === "symbol" ? key : String(key); }
2437
+ 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); }
2438
+ 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); }
2439
+ 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); }
2440
+ 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); }; }
2441
+ 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); }
2442
+ function AuthManagerBrowser_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
2443
+ 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; } }
2444
+ function AuthManagerBrowser_getPrototypeOf(o) { AuthManagerBrowser_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return AuthManagerBrowser_getPrototypeOf(o); }
2445
+
2446
+
2447
+
2448
+
2449
+ var AuthManager = /*#__PURE__*/function (_BaseAPI) {
2450
+ AuthManagerBrowser_inherits(AuthManager, _BaseAPI);
2451
+ var _super = AuthManagerBrowser_createSuper(AuthManager);
2452
+ function AuthManager(config) {
2453
+ var _this;
2454
+ AuthManagerBrowser_classCallCheck(this, AuthManager);
2455
+ var _a, _b;
2456
+ _this = _super.call(this, config);
2457
+ _this.authSessionMutex = new Mutex();
2458
+ _this.contentType = "content-type";
2459
+ _this.contentTypeJson = "application/json";
2460
+ _this.contentTypeText = "text/plain";
2461
+ _this.minJwtTtlSeconds = 10;
2462
+ _this.retryAuthAfterErrorSeconds = 5;
2463
+ _this.refreshBeforeExpirySeconds = 20;
2464
+ var accountId;
2465
+ if (BaseAPI.specialApiKeys.includes(config.apiKey)) {
2466
+ accountId = BaseAPI.specialApiKeyAccountId;
2467
+ } else {
2468
+ accountId = (_b = (_a = config.apiKey.split("_")[1]) === null || _a === void 0 ? void 0 : _a.substr(0, BaseAPI.accountIdLength)) !== null && _b !== void 0 ? _b : "";
2469
+ if (accountId.length !== BaseAPI.accountIdLength) {
2470
+ throw new Error("Invalid Bytescale API key.");
2471
+ }
2472
+ }
2473
+ _this.accessTokenUrl = "".concat(BytescaleApiClientConfigResolver.getCdnUrl(config), "/api/v1/access_tokens/").concat(accountId);
2474
+ return _this;
2475
+ }
2476
+ AuthManagerBrowser_createClass(AuthManager, [{
2477
+ key: "isAuthSessionActive",
2478
+ value: function isAuthSessionActive() {
2479
+ return AuthSessionState.session !== undefined;
2480
+ }
2481
+ }, {
2482
+ key: "beginAuthSession",
2483
+ value: function beginAuthSession(authUrl, authHeaders) {
2484
+ try {
2485
+ var _this3 = this;
2486
+ var newSession = {
2487
+ accessToken: undefined,
2488
+ accessTokenRefreshHandle: undefined,
2489
+ authUrl: authUrl,
2490
+ authHeaders: authHeaders,
2491
+ isActive: true
2492
+ };
2493
+ return AuthManagerBrowser_await(_this3.authSessionMutex.safe(AuthManagerBrowser_async(function () {
2494
+ // We check both 'session' and 'sessionDisposing' here, as we don't want to call 'beginAuthSession' until the session is fully disposed.
2495
+ if (_this3.isAuthSessionActive()) {
2496
+ 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.");
2497
+ }
2498
+ AuthSessionState.session = newSession;
2499
+ return AuthManagerBrowser_await();
2500
+ })), function () {
2501
+ // IMPORTANT: must be called outside the above, else re-entrant deadlock will occur.
2502
+ return AuthManagerBrowser_awaitIgnored(_this3.refreshAccessToken(newSession));
2503
+ });
2504
+ } catch (e) {
2505
+ return Promise.reject(e);
2506
+ }
2507
+ }
2508
+ }, {
2509
+ key: "endAuthSession",
2510
+ value: function endAuthSession() {
2511
+ try {
2512
+ var _this5 = this;
2513
+ return AuthManagerBrowser_awaitIgnored(_this5.authSessionMutex.safe(AuthManagerBrowser_async(function () {
2514
+ if (AuthSessionState.session === undefined) {
2515
+ return;
2516
+ }
2517
+ var session = AuthSessionState.session;
2518
+ AuthSessionState.session = undefined;
2519
+ session.isActive = false;
2520
+ if (session.accessTokenRefreshHandle !== undefined) {
2521
+ clearTimeout(session.accessTokenRefreshHandle);
2522
+ }
2523
+ return AuthManagerBrowser_awaitIgnored(_this5.deleteAccessToken());
2524
+ })));
2525
+ } catch (e) {
2526
+ return Promise.reject(e);
2527
+ }
2528
+ }
2529
+ }, {
2530
+ key: "refreshAccessToken",
2531
+ value: function refreshAccessToken(session) {
2532
+ try {
2533
+ var _this7 = this;
2534
+ return AuthManagerBrowser_awaitIgnored(_this7.authSessionMutex.safe(AuthManagerBrowser_async(function () {
2535
+ if (!session.isActive) {
2536
+ return;
2537
+ }
2538
+ var timeout = _this7.retryAuthAfterErrorSeconds;
2539
+ return AuthManagerBrowser_continueIgnored(AuthManagerBrowser_finallyRethrows(function () {
2540
+ return AuthManagerBrowser_catch(function () {
2541
+ var _getAccessToken = _this7.getAccessToken,
2542
+ _session$authUrl = session.authUrl;
2543
+ return AuthManagerBrowser_await(session.authHeaders(), function (_session$authHeaders) {
2544
+ return AuthManagerBrowser_await(_getAccessToken.call(_this7, _session$authUrl, _session$authHeaders), function (jwt) {
2545
+ return AuthManagerBrowser_await(_this7.setAccessToken(jwt), function (setTokenResult) {
2546
+ var desiredTtl = setTokenResult.ttlSeconds - _this7.refreshBeforeExpirySeconds;
2547
+ timeout = Math.max(desiredTtl, _this7.minJwtTtlSeconds);
2548
+ if (desiredTtl !== timeout) {
2549
+ ConsoleUtils.warn("JWT expiration is too short: waiting for ".concat(timeout, " seconds before refreshing."));
2550
+ }
2551
+ session.accessToken = setTokenResult.accessToken;
2552
+ });
2553
+ });
2554
+ });
2555
+ }, function (e) {
2556
+ // Use 'error' instead of 'debug' so that the user sees error messages.
2557
+ ConsoleUtils.error("Error when refreshing access token: ".concat(e));
2558
+ });
2559
+ }, function (_wasThrown, _result) {
2560
+ session.accessTokenRefreshHandle = window.setTimeout(function () {
2561
+ _this7.refreshAccessToken(session).then(function () {}, function (e) {
2562
+ return ConsoleUtils.error("Unexpected error when refreshing access token: ".concat(e));
2563
+ });
2564
+ }, timeout * 1000);
2565
+ return AuthManagerBrowser_rethrow(_wasThrown, _result);
2566
+ }));
2567
+ })));
2568
+ } catch (e) {
2569
+ return Promise.reject(e);
2570
+ }
2571
+ }
2572
+ }, {
2573
+ key: "deleteAccessToken",
2574
+ value: function deleteAccessToken() {
2575
+ try {
2576
+ var _this9 = this;
2577
+ return AuthManagerBrowser_awaitIgnored(_this9.doFetch(_this9.accessTokenUrl, {
2578
+ method: "DELETE",
2579
+ credentials: "include",
2580
+ headers: {}
2581
+ }, true));
2582
+ } catch (e) {
2583
+ return Promise.reject(e);
2584
+ }
2585
+ }
2586
+ }, {
2587
+ key: "setAccessToken",
2588
+ value: function setAccessToken(jwt) {
2589
+ try {
2590
+ var _this11 = this;
2591
+ var request = {
2592
+ accessToken: jwt
2593
+ };
2594
+ return AuthManagerBrowser_await(_this11.doFetch(_this11.accessTokenUrl, {
2595
+ method: "PUT",
2596
+ credentials: "include",
2597
+ headers: AuthManagerBrowser_defineProperty({}, _this11.contentType, _this11.contentTypeJson),
2598
+ body: JSON.stringify(request)
2599
+ }, true), function (response) {
2600
+ return AuthManagerBrowser_await(response.json());
2601
+ });
2602
+ } catch (e) {
2603
+ return Promise.reject(e);
2604
+ }
2605
+ }
2606
+ }, {
2607
+ key: "getAccessToken",
2608
+ value: function getAccessToken(authUrl, headers) {
2609
+ try {
2610
+ var _this13 = this;
2611
+ var endpointName = "Your auth API endpoint";
2612
+ var requiredContentType = _this13.contentTypeText;
2613
+ return AuthManagerBrowser_await(_this13.doFetch(authUrl, {
2614
+ method: "GET",
2615
+ headers: headers
2616
+ }, false), function (result) {
2617
+ if (result.headers.get(_this13.contentType) !== requiredContentType) {
2618
+ throw new Error("".concat(endpointName, " returned an unsupported '").concat(_this13.contentType, "' response header: please return '").concat(requiredContentType, "'."));
2619
+ }
2620
+ return AuthManagerBrowser_await(result.text(), function (jwt) {
2621
+ if (jwt.length === 0) {
2622
+ throw new Error("".concat(endpointName, " returned an empty string. Please return a valid JWT instead."));
2623
+ }
2624
+ if (jwt.trim().length !== jwt.length) {
2625
+ // Whitespace can be a nightmare to spot/debug, so we fail early here.
2626
+ throw new Error("".concat(endpointName, " returned whitespace around the JWT, please remove it."));
2627
+ }
2628
+ return jwt;
2629
+ });
2630
+ });
2631
+ } catch (e) {
2632
+ return Promise.reject(e);
2633
+ }
2634
+ }
2635
+ }]);
2636
+ return AuthManager;
2637
+ }(BaseAPI);
2638
+ ;// CONCATENATED MODULE: ./src/public/browser/index.ts
2639
+
1927
2640
 
1928
2641
  ;// CONCATENATED MODULE: ./src/index.browser.ts
1929
2642
  /* tslint:disable */
1930
2643
  /* eslint-disable */
1931
2644
 
1932
2645
 
1933
-
1934
2646
  module.exports = __lib_exports__;
1935
2647
  /******/ })()
1936
2648
  ;