@bytescale/sdk 3.1.0 → 3.2.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.
@@ -0,0 +1,2803 @@
1
+ /******/ // The require scope
2
+ /******/ var __lib_require__ = {};
3
+ /******/
4
+ /************************************************************************/
5
+ /******/ /* webpack/runtime/define property getters */
6
+ /******/ !function() {
7
+ /******/ // define getter functions for harmony exports
8
+ /******/ __lib_require__.d = function(exports, definition) {
9
+ /******/ for(var key in definition) {
10
+ /******/ if(__lib_require__.o(definition, key) && !__lib_require__.o(exports, key)) {
11
+ /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
12
+ /******/ }
13
+ /******/ }
14
+ /******/ };
15
+ /******/ }();
16
+ /******/
17
+ /******/ /* webpack/runtime/hasOwnProperty shorthand */
18
+ /******/ !function() {
19
+ /******/ __lib_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
20
+ /******/ }();
21
+ /******/
22
+ /************************************************************************/
23
+ var __lib_exports__ = {};
24
+
25
+ // EXPORTS
26
+ __lib_require__.d(__lib_exports__, {
27
+ "AuthManager": function() { return /* reexport */ AuthManager; },
28
+ "BaseAPI": function() { return /* reexport */ BaseAPI; },
29
+ "BinaryResult": function() { return /* reexport */ BinaryResult; },
30
+ "BytescaleApiClientConfigUtils": function() { return /* reexport */ BytescaleApiClientConfigUtils; },
31
+ "BytescaleApiError": function() { return /* reexport */ BytescaleApiError; },
32
+ "CancelledError": function() { return /* reexport */ CancelledError; },
33
+ "CommonTypesNoOp": function() { return /* reexport */ CommonTypesNoOp; },
34
+ "FileApi": function() { return /* reexport */ FileApi; },
35
+ "FolderApi": function() { return /* reexport */ FolderApi; },
36
+ "JSONApiResponse": function() { return /* reexport */ JSONApiResponse; },
37
+ "JobApi": function() { return /* reexport */ JobApi; },
38
+ "UploadApi": function() { return /* reexport */ UploadApi; },
39
+ "UploadManager": function() { return /* reexport */ UploadManager; },
40
+ "UrlBuilder": function() { return /* reexport */ UrlBuilder; },
41
+ "UrlBuilderTypesNoOp": function() { return /* reexport */ UrlBuilderTypesNoOp; },
42
+ "VoidApiResponse": function() { return /* reexport */ VoidApiResponse; },
43
+ "querystring": function() { return /* reexport */ querystring; }
44
+ });
45
+
46
+ ;// CONCATENATED MODULE: ./src/private/Mutex.ts
47
+ 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); }
48
+ function _call(body, then, direct) {
49
+ if (direct) {
50
+ return then ? then(body()) : body();
51
+ }
52
+ try {
53
+ var result = Promise.resolve(body());
54
+ return then ? result.then(then) : result;
55
+ } catch (e) {
56
+ return Promise.reject(e);
57
+ }
58
+ }
59
+ function _rethrow(thrown, value) {
60
+ if (thrown) throw value;
61
+ return value;
62
+ }
63
+ function _finallyRethrows(body, finalizer) {
64
+ try {
65
+ var result = body();
66
+ } catch (e) {
67
+ return finalizer(true, e);
68
+ }
69
+ if (result && result.then) {
70
+ return result.then(finalizer.bind(null, false), finalizer.bind(null, true));
71
+ }
72
+ return finalizer(false, result);
73
+ }
74
+ function _await(value, then, direct) {
75
+ if (direct) {
76
+ return then ? then(value) : value;
77
+ }
78
+ if (!value || !value.then) {
79
+ value = Promise.resolve(value);
80
+ }
81
+ return then ? value.then(then) : value;
82
+ }
83
+ function _empty() {}
84
+ function _awaitIgnored(value, direct) {
85
+ if (!direct) {
86
+ return value && value.then ? value.then(_empty) : Promise.resolve();
87
+ }
88
+ }
89
+ function _settle(pact, state, value) {
90
+ if (!pact.s) {
91
+ if (value instanceof _Pact) {
92
+ if (value.s) {
93
+ if (state & 1) {
94
+ state = value.s;
95
+ }
96
+ value = value.v;
97
+ } else {
98
+ value.o = _settle.bind(null, pact, state);
99
+ return;
100
+ }
101
+ }
102
+ if (value && value.then) {
103
+ value.then(_settle.bind(null, pact, state), _settle.bind(null, pact, 2));
104
+ return;
105
+ }
106
+ pact.s = state;
107
+ pact.v = value;
108
+ var observer = pact.o;
109
+ if (observer) {
110
+ observer(pact);
111
+ }
112
+ }
113
+ }
114
+ var _Pact = /*#__PURE__*/function () {
115
+ function _Pact() {}
116
+ _Pact.prototype.then = function (onFulfilled, onRejected) {
117
+ var result = new _Pact();
118
+ var state = this.s;
119
+ if (state) {
120
+ var callback = state & 1 ? onFulfilled : onRejected;
121
+ if (callback) {
122
+ try {
123
+ _settle(result, 1, callback(this.v));
124
+ } catch (e) {
125
+ _settle(result, 2, e);
126
+ }
127
+ return result;
128
+ } else {
129
+ return this;
130
+ }
131
+ }
132
+ this.o = function (_this) {
133
+ try {
134
+ var value = _this.v;
135
+ if (_this.s & 1) {
136
+ _settle(result, 1, onFulfilled ? onFulfilled(value) : value);
137
+ } else if (onRejected) {
138
+ _settle(result, 1, onRejected(value));
139
+ } else {
140
+ _settle(result, 2, value);
141
+ }
142
+ } catch (e) {
143
+ _settle(result, 2, e);
144
+ }
145
+ };
146
+ return result;
147
+ };
148
+ return _Pact;
149
+ }();
150
+ function _isSettledPact(thenable) {
151
+ return thenable instanceof _Pact && thenable.s & 1;
152
+ }
153
+ function _for(test, update, body) {
154
+ var stage;
155
+ for (;;) {
156
+ var shouldContinue = test();
157
+ if (_isSettledPact(shouldContinue)) {
158
+ shouldContinue = shouldContinue.v;
159
+ }
160
+ if (!shouldContinue) {
161
+ return result;
162
+ }
163
+ if (shouldContinue.then) {
164
+ stage = 0;
165
+ break;
166
+ }
167
+ var result = body();
168
+ if (result && result.then) {
169
+ if (_isSettledPact(result)) {
170
+ result = result.s;
171
+ } else {
172
+ stage = 1;
173
+ break;
174
+ }
175
+ }
176
+ if (update) {
177
+ var updateValue = update();
178
+ if (updateValue && updateValue.then && !_isSettledPact(updateValue)) {
179
+ stage = 2;
180
+ break;
181
+ }
182
+ }
183
+ }
184
+ var pact = new _Pact();
185
+ var reject = _settle.bind(null, pact, 2);
186
+ (stage === 0 ? shouldContinue.then(_resumeAfterTest) : stage === 1 ? result.then(_resumeAfterBody) : updateValue.then(_resumeAfterUpdate)).then(void 0, reject);
187
+ return pact;
188
+ function _resumeAfterBody(value) {
189
+ result = value;
190
+ do {
191
+ if (update) {
192
+ updateValue = update();
193
+ if (updateValue && updateValue.then && !_isSettledPact(updateValue)) {
194
+ updateValue.then(_resumeAfterUpdate).then(void 0, reject);
195
+ return;
196
+ }
197
+ }
198
+ shouldContinue = test();
199
+ if (!shouldContinue || _isSettledPact(shouldContinue) && !shouldContinue.v) {
200
+ _settle(pact, 1, result);
201
+ return;
202
+ }
203
+ if (shouldContinue.then) {
204
+ shouldContinue.then(_resumeAfterTest).then(void 0, reject);
205
+ return;
206
+ }
207
+ result = body();
208
+ if (_isSettledPact(result)) {
209
+ result = result.v;
210
+ }
211
+ } while (!result || !result.then);
212
+ result.then(_resumeAfterBody).then(void 0, reject);
213
+ }
214
+ function _resumeAfterTest(shouldContinue) {
215
+ if (shouldContinue) {
216
+ result = body();
217
+ if (result && result.then) {
218
+ result.then(_resumeAfterBody).then(void 0, reject);
219
+ } else {
220
+ _resumeAfterBody(result);
221
+ }
222
+ } else {
223
+ _settle(pact, 1, result);
224
+ }
225
+ }
226
+ function _resumeAfterUpdate() {
227
+ if (shouldContinue = test()) {
228
+ if (shouldContinue.then) {
229
+ shouldContinue.then(_resumeAfterTest).then(void 0, reject);
230
+ } else {
231
+ _resumeAfterTest(shouldContinue);
232
+ }
233
+ } else {
234
+ _settle(pact, 1, result);
235
+ }
236
+ }
237
+ }
238
+ function _continue(value, then) {
239
+ return value && value.then ? value.then(then) : then(value);
240
+ }
241
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
242
+ 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); } }
243
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
244
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
245
+ 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); }
246
+ /**
247
+ * A lightweight mutex. (Other libraries contain too many features and we want to keep size down).
248
+ *
249
+ * Characteristics:
250
+ * - Non-reentrant.
251
+ * - Unfair. (Multiple callers awaiting 'acquire' will be granted the mutex in no order.)
252
+ * - When calling `safe` consecutively with no 'awaits' in-between, the current context will synchronously acquire
253
+ * the mutex every time.
254
+ */
255
+ var Mutex = /*#__PURE__*/function () {
256
+ function Mutex() {
257
+ _classCallCheck(this, Mutex);
258
+ this.mutex = undefined;
259
+ this.resolver = undefined;
260
+ }
261
+ _createClass(Mutex, [{
262
+ key: "safe",
263
+ value: function safe(callback) {
264
+ try {
265
+ var _this2 = this;
266
+ return _await(_this2.acquire(), function () {
267
+ return _finallyRethrows(callback, function (_wasThrown, _result) {
268
+ _this2.release();
269
+ return _rethrow(_wasThrown, _result);
270
+ });
271
+ });
272
+ } catch (e) {
273
+ return Promise.reject(e);
274
+ }
275
+ }
276
+ }, {
277
+ key: "acquire",
278
+ value: function acquire() {
279
+ try {
280
+ var _this4 = this;
281
+ // Loop necessary for when multiple calls are made to 'acquire' before a 'release' is called, else the call to
282
+ // 'release' will resume every caller currently waiting on 'acquire'.
283
+ return _continue(_for(function () {
284
+ return _this4.mutex !== undefined;
285
+ }, void 0, function () {
286
+ return _awaitIgnored(_this4.mutex);
287
+ }), function () {
288
+ _this4.mutex = new Promise(function (resolve) {
289
+ _this4.resolver = resolve;
290
+ });
291
+ });
292
+ } catch (e) {
293
+ return Promise.reject(e);
294
+ }
295
+ }
296
+ }, {
297
+ key: "release",
298
+ value: function release() {
299
+ if (this.resolver === undefined) {
300
+ throw new Error("Unable to release mutex: already released.");
301
+ }
302
+ this.resolver();
303
+ this.resolver = undefined;
304
+ this.mutex = undefined;
305
+ }
306
+ }]);
307
+ return Mutex;
308
+ }();
309
+ ;// CONCATENATED MODULE: ./src/private/AuthSessionState.ts
310
+ function AuthSessionState_typeof(obj) { "@babel/helpers - typeof"; return AuthSessionState_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; }, AuthSessionState_typeof(obj); }
311
+ function AuthSessionState_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
312
+ function AuthSessionState_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, AuthSessionState_toPropertyKey(descriptor.key), descriptor); } }
313
+ function AuthSessionState_createClass(Constructor, protoProps, staticProps) { if (protoProps) AuthSessionState_defineProperties(Constructor.prototype, protoProps); if (staticProps) AuthSessionState_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
314
+ function AuthSessionState_toPropertyKey(arg) { var key = AuthSessionState_toPrimitive(arg, "string"); return AuthSessionState_typeof(key) === "symbol" ? key : String(key); }
315
+ function AuthSessionState_toPrimitive(input, hint) { if (AuthSessionState_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (AuthSessionState_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
316
+
317
+ /**
318
+ * Maintains a global session state, even across package versions.
319
+ *
320
+ * This is to allow users to start auth sessions via the Bytescale JavaScript SDK, where due to versioning or other
321
+ * bundling issues, the Bytescale Upload Widget has been bundled with a different Bytescale JavaScript SDK. In this
322
+ * scenario, the user wouldn't be able to start an auth session with the Bytescale Upload Widget. Therefore, we use
323
+ * global state (i.e. on the window) to ensure the session state can be shared between the user's instance of the
324
+ * Bytescale JavaScript SDK and the Upload Widget's version of the Bytescale JavaScript SDK.
325
+ *
326
+ * Users also frequently have problems caused by them not keeping track of *Api and *Manager instances correctly, so
327
+ * making this global prevents a lot of common mistakes.
328
+ */
329
+ var AuthSessionState = /*#__PURE__*/function () {
330
+ function AuthSessionState() {
331
+ AuthSessionState_classCallCheck(this, AuthSessionState);
332
+ }
333
+ AuthSessionState_createClass(AuthSessionState, null, [{
334
+ key: "getMutex",
335
+ value:
336
+ /**
337
+ * Called in the browser only.
338
+ */
339
+ function getMutex() {
340
+ var key = AuthSessionState.mutexKey;
341
+ var mutex = window[key];
342
+ if (mutex === undefined) {
343
+ mutex = new Mutex();
344
+ window[key] = mutex;
345
+ }
346
+ return mutex;
347
+ }
348
+ /**
349
+ * Called in the browser only.
350
+ */
351
+ }, {
352
+ key: "setSession",
353
+ value: function setSession(session) {
354
+ window[AuthSessionState.stateKey] = session;
355
+ }
356
+ /**
357
+ * Called in the browser and in Node.js (so we check the env before calling env-specific code).
358
+ */
359
+ }, {
360
+ key: "getSession",
361
+ value: function getSession() {
362
+ if (typeof window === "undefined") {
363
+ return undefined;
364
+ }
365
+ return window[AuthSessionState.stateKey];
366
+ }
367
+ }]);
368
+ return AuthSessionState;
369
+ }();
370
+ AuthSessionState.stateKey = "BytescaleSessionState";
371
+ AuthSessionState.mutexKey = "BytescaleSessionStateMutex";
372
+ ;// CONCATENATED MODULE: ./src/public/shared/generated/runtime.ts
373
+ 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); }
374
+ 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); }
375
+ 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); }; }
376
+ 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); }
377
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
378
+ 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); }
379
+ 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); }
380
+ function _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; } }
381
+ function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
382
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
383
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
384
+ function _catch(body, recover) {
385
+ try {
386
+ var result = body();
387
+ } catch (e) {
388
+ return recover(e);
389
+ }
390
+ if (result && result.then) {
391
+ return result.then(void 0, recover);
392
+ }
393
+ return result;
394
+ }
395
+ function runtime_empty() {}
396
+ function runtime_continue(value, then) {
397
+ return value && value.then ? value.then(then) : then(value);
398
+ }
399
+ function _invoke(body, then) {
400
+ var result = body();
401
+ if (result && result.then) {
402
+ return result.then(then);
403
+ }
404
+ return then(result);
405
+ }
406
+ 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; }
407
+ function runtime_await(value, then, direct) {
408
+ if (direct) {
409
+ return then ? then(value) : value;
410
+ }
411
+ if (!value || !value.then) {
412
+ value = Promise.resolve(value);
413
+ }
414
+ return then ? value.then(then) : value;
415
+ }
416
+ function runtime_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
417
+ 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); } }
418
+ 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; }
419
+ function runtime_toPropertyKey(arg) { var key = runtime_toPrimitive(arg, "string"); return runtime_typeof(key) === "symbol" ? key : String(key); }
420
+ 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); }
421
+
422
+ var BytescaleApiClientConfigUtils = /*#__PURE__*/function () {
423
+ function BytescaleApiClientConfigUtils() {
424
+ runtime_classCallCheck(this, BytescaleApiClientConfigUtils);
425
+ }
426
+ runtime_createClass(BytescaleApiClientConfigUtils, null, [{
427
+ key: "getApiUrl",
428
+ value: function getApiUrl(config) {
429
+ var _a;
430
+ return (_a = config.apiUrl) !== null && _a !== void 0 ? _a : BytescaleApiClientConfigUtils.defaultApiUrl;
431
+ }
432
+ }, {
433
+ key: "getCdnUrl",
434
+ value: function getCdnUrl(config) {
435
+ var _a;
436
+ return (_a = config.cdnUrl) !== null && _a !== void 0 ? _a : BytescaleApiClientConfigUtils.defaultCdnUrl;
437
+ }
438
+ }, {
439
+ key: "getFetchApi",
440
+ value: function getFetchApi(config) {
441
+ var _a;
442
+ return (_a = config.fetchApi) !== null && _a !== void 0 ? _a : fetch;
443
+ }
444
+ }, {
445
+ key: "getAccountId",
446
+ value: function getAccountId(config) {
447
+ var _a, _b;
448
+ var accountId;
449
+ if (BytescaleApiClientConfigUtils.specialApiKeys.includes(config.apiKey)) {
450
+ accountId = BytescaleApiClientConfigUtils.specialApiKeyAccountId;
451
+ } else {
452
+ accountId = (_b = (_a = config.apiKey.split("_")[1]) === null || _a === void 0 ? void 0 : _a.substr(0, BytescaleApiClientConfigUtils.accountIdLength)) !== null && _b !== void 0 ? _b : "";
453
+ if (accountId.length !== BytescaleApiClientConfigUtils.accountIdLength) {
454
+ throw new Error("Invalid Bytescale API key.");
455
+ }
456
+ }
457
+ return accountId;
458
+ }
459
+ }, {
460
+ key: "validate",
461
+ value: function validate(config) {
462
+ var _a;
463
+ // Defensive programming, for users not using TypeScript. Mainly because this is used by UploadWidget users.
464
+ if ((config !== null && config !== void 0 ? config : undefined) === undefined) {
465
+ throw new Error("Config parameter required.");
466
+ }
467
+ if (((_a = config.apiKey) !== null && _a !== void 0 ? _a : undefined) === undefined) {
468
+ throw new Error("Please provide an API key via the 'apiKey' config parameter.");
469
+ }
470
+ if (config.apiKey.trim() !== config.apiKey) {
471
+ // We do not support API keys with whitespace (by trimming ourselves) because otherwise we'd need to support this
472
+ // everywhere in perpetuity (since removing the trimming would be a breaking change).
473
+ throw new Error("API key needs trimming (whitespace detected).");
474
+ }
475
+ // This performs futher validation on the API key...
476
+ BytescaleApiClientConfigUtils.getAccountId(config);
477
+ }
478
+ }]);
479
+ return BytescaleApiClientConfigUtils;
480
+ }();
481
+ BytescaleApiClientConfigUtils.defaultApiUrl = "https://api.bytescale.com";
482
+ BytescaleApiClientConfigUtils.defaultCdnUrl = "https://upcdn.io";
483
+ BytescaleApiClientConfigUtils.specialApiKeys = ["free", "demo"];
484
+ BytescaleApiClientConfigUtils.specialApiKeyAccountId = "W142hJk";
485
+ BytescaleApiClientConfigUtils.accountIdLength = 7; // Sync with: upload/shared/**/AccountIdUtils
486
+ /**
487
+ * This is the base class for all generated API classes.
488
+ */
489
+ var BaseAPI = /*#__PURE__*/function () {
490
+ function BaseAPI(config) {
491
+ runtime_classCallCheck(this, BaseAPI);
492
+ this.config = config;
493
+ BytescaleApiClientConfigUtils.validate(config);
494
+ }
495
+ /**
496
+ * Returns a successful response (2**) else throws an error.
497
+ */
498
+ runtime_createClass(BaseAPI, [{
499
+ key: "request",
500
+ value: function request(context, initOverrides, baseUrlOverride) {
501
+ try {
502
+ var _this2 = this;
503
+ var _a;
504
+ var apiKey = _this2.config.apiKey;
505
+ context.headers["Authorization"] = "Bearer ".concat(apiKey); // authorization-header authentication
506
+ var session = AuthSessionState.getSession();
507
+ if ((session === null || session === void 0 ? void 0 : session.accessToken) !== undefined) {
508
+ context.headers["Authorization-Token"] = session.accessToken;
509
+ }
510
+ // Key: any possible value for 'baseUrlOverride'
511
+ // Value: user-overridden value for that base URL from the config.
512
+ var nonDefaultBasePaths = _defineProperty({}, BytescaleApiClientConfigUtils.defaultCdnUrl, BytescaleApiClientConfigUtils.getCdnUrl(_this2.config));
513
+ return runtime_await(_this2.createFetchParams(context, initOverrides, baseUrlOverride === undefined ? undefined : (_a = nonDefaultBasePaths[baseUrlOverride]) !== null && _a !== void 0 ? _a : baseUrlOverride), function (_ref) {
514
+ var url = _ref.url,
515
+ init = _ref.init;
516
+ return BaseAPI.fetch(url, init, Object.assign(Object.assign({}, _this2.config), {
517
+ isBytescaleApi: true
518
+ }));
519
+ });
520
+ } catch (e) {
521
+ return Promise.reject(e);
522
+ }
523
+ }
524
+ }, {
525
+ key: "encodeParam",
526
+ value: function encodeParam(paramName, paramValue) {
527
+ if (paramName === "filePath") {
528
+ if (!paramValue.startsWith("/")) {
529
+ // Non-obvious errors are returned by the Bytescale CDN if forward slashes are omitted, so catch it client-side:
530
+ throw new Error("The 'filePath' parameter must begin with a '/' character.");
531
+ }
532
+ // We must not encode the filePath param (as slashes are valid).
533
+ return paramValue;
534
+ }
535
+ return encodeURIComponent(paramValue);
536
+ }
537
+ }, {
538
+ key: "createFetchParams",
539
+ value: function createFetchParams(context, initOverrides, baseUrlOverride) {
540
+ try {
541
+ var _this4 = this;
542
+ var url = (baseUrlOverride !== null && baseUrlOverride !== void 0 ? baseUrlOverride : BytescaleApiClientConfigUtils.getApiUrl(_this4.config)) + context.path;
543
+ if (context.query !== undefined && Object.keys(context.query).length !== 0) {
544
+ // only add the querystring to the URL if there are query parameters.
545
+ // this is done to avoid urls ending with a "?" character which buggy webservers
546
+ // do not handle correctly sometimes.
547
+ url += "?" + querystring(context.query);
548
+ }
549
+ var configHeaders = _this4.config.headers;
550
+ var _Object$assign3 = Object.assign({}, context.headers);
551
+ return runtime_await(configHeaders === undefined ? {} : configHeaders(), function (_configHeaders) {
552
+ var headers = Object.assign(_Object$assign3, _configHeaders);
553
+ Object.keys(headers).forEach(function (key) {
554
+ return headers[key] === undefined ? delete headers[key] : {};
555
+ });
556
+ var initOverrideFn = typeof initOverrides === "function" ? initOverrides : function () {
557
+ return runtime_await(initOverrides);
558
+ };
559
+ var initParams = {
560
+ method: context.method,
561
+ headers: headers,
562
+ body: context.body
563
+ };
564
+ var _Object$assign2 = Object.assign({}, initParams);
565
+ return runtime_await(initOverrideFn({
566
+ init: initParams,
567
+ context: context
568
+ }), function (_initOverrideFn) {
569
+ var overriddenInit = Object.assign(_Object$assign2, _initOverrideFn);
570
+ var init = Object.assign(Object.assign({}, overriddenInit), {
571
+ body: JSON.stringify(overriddenInit.body)
572
+ });
573
+ return {
574
+ url: url,
575
+ init: init
576
+ };
577
+ });
578
+ }, configHeaders === undefined);
579
+ } catch (e) {
580
+ return Promise.reject(e);
581
+ }
582
+ }
583
+ }], [{
584
+ key: "fetch",
585
+ value: function fetch(url, init, config) {
586
+ try {
587
+ var _exit3 = false;
588
+ var _a, _b;
589
+ var response;
590
+ return runtime_continue(_catch(function () {
591
+ return runtime_await(BytescaleApiClientConfigUtils.getFetchApi(config)(url, Object.assign(Object.assign({}, init), {
592
+ // This is specifically added to cater for Next.js's Fetch implementation, which caches POST requests...
593
+ //
594
+ // "fetch requests that use the POST method are also automatically cached."
595
+ // - https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#caching-data
596
+ //
597
+ // However, this is probably a good idea, even for all GET requests, as if the user is refreshing a JWT
598
+ // or downloading a file via 'FileApi.downloadFile', then they'll likely want the latest.
599
+ cache: "no-store"
600
+ })), function (_BytescaleApiClientCo) {
601
+ response = _BytescaleApiClientCo;
602
+ });
603
+ }, function (e) {
604
+ // Network-level errors, CORS errors, or HTTP-level errors from intermediary services (e.g. AWS or the user's own infrastructure/proxies).
605
+ // 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.
606
+ throw new Error(config.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));
607
+ }), function (_result) {
608
+ var _exit2 = false;
609
+ if (_exit3) return _result;
610
+ return response.status >= 200 && response.status < 300 ? response : _invoke(function () {
611
+ if (config.isBytescaleApi) {
612
+ var jsonError = undefined;
613
+ return runtime_continue(_catch(function () {
614
+ return runtime_await(response.json(), function (_response$json) {
615
+ jsonError = _response$json;
616
+ });
617
+ }, runtime_empty), function () {
618
+ if (typeof ((_a = jsonError === null || jsonError === void 0 ? void 0 : jsonError.error) === null || _a === void 0 ? void 0 : _a.code) === "string") {
619
+ throw new BytescaleApiError(jsonError);
620
+ }
621
+ // HTTP-level errors from intermediary services (e.g. AWS or the user's own infrastructure/proxies). On the browser,
622
+ // this error is unlikely to be triggered since these errors will masqurade as CORS errors (see above) but in Node.js
623
+ // this error will appear from any intermediary service failure.
624
+ throw new Error("Unable to connect to the Bytescale API (".concat(response.status, "): please try again."));
625
+ });
626
+ }
627
+ }, function (_result2) {
628
+ if (_exit2) return _result2;
629
+ throw new Error("Failure status code (".concat(response.status, ") received for request: ").concat((_b = init.method) !== null && _b !== void 0 ? _b : "GET", " ").concat(url));
630
+ });
631
+ });
632
+ } catch (e) {
633
+ return Promise.reject(e);
634
+ }
635
+ }
636
+ }]);
637
+ return BaseAPI;
638
+ }();
639
+ var CancelledError = /*#__PURE__*/function (_Error) {
640
+ _inherits(CancelledError, _Error);
641
+ var _super = _createSuper(CancelledError);
642
+ function CancelledError() {
643
+ var _this5;
644
+ runtime_classCallCheck(this, CancelledError);
645
+ _this5 = _super.call(this, "Operation cancelled by caller.");
646
+ _this5.name = "CancelledError";
647
+ return _this5;
648
+ }
649
+ return runtime_createClass(CancelledError);
650
+ }( /*#__PURE__*/_wrapNativeSuper(Error));
651
+ var BytescaleApiError = /*#__PURE__*/function (_Error2) {
652
+ _inherits(BytescaleApiError, _Error2);
653
+ var _super2 = _createSuper(BytescaleApiError);
654
+ function BytescaleApiError(response) {
655
+ var _this6;
656
+ runtime_classCallCheck(this, BytescaleApiError);
657
+ _this6 = _super2.call(this, response.error.message);
658
+ _this6.name = "BytescaleApiError";
659
+ _this6.errorCode = response.error.code;
660
+ _this6.details = response.error.details;
661
+ return _this6;
662
+ }
663
+ return runtime_createClass(BytescaleApiError);
664
+ }( /*#__PURE__*/_wrapNativeSuper(Error));
665
+ function querystring(params) {
666
+ return Object.keys(params).map(function (key) {
667
+ return querystringSingleKey(key, params[key]);
668
+ }).filter(function (part) {
669
+ return part.length > 0;
670
+ }).join("&");
671
+ }
672
+ function querystringSingleKey(key, value) {
673
+ if (value instanceof Object) {
674
+ return querystring(value);
675
+ }
676
+ return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(String(value)));
677
+ }
678
+ var JSONApiResponse = /*#__PURE__*/function () {
679
+ function JSONApiResponse(raw) {
680
+ runtime_classCallCheck(this, JSONApiResponse);
681
+ this.raw = raw;
682
+ }
683
+ runtime_createClass(JSONApiResponse, [{
684
+ key: "value",
685
+ value: function value() {
686
+ try {
687
+ var _this8 = this;
688
+ return runtime_await(_this8.raw.json());
689
+ } catch (e) {
690
+ return Promise.reject(e);
691
+ }
692
+ }
693
+ }]);
694
+ return JSONApiResponse;
695
+ }();
696
+ var VoidApiResponse = /*#__PURE__*/function () {
697
+ function VoidApiResponse(raw) {
698
+ runtime_classCallCheck(this, VoidApiResponse);
699
+ this.raw = raw;
700
+ }
701
+ runtime_createClass(VoidApiResponse, [{
702
+ key: "value",
703
+ value: function value() {
704
+ return runtime_await(undefined);
705
+ }
706
+ }]);
707
+ return VoidApiResponse;
708
+ }();
709
+ var BinaryResult = /*#__PURE__*/function () {
710
+ function BinaryResult(raw) {
711
+ runtime_classCallCheck(this, BinaryResult);
712
+ this.raw = raw;
713
+ }
714
+ runtime_createClass(BinaryResult, [{
715
+ key: "stream",
716
+ value: function stream() {
717
+ if (this.raw.bodyUsed) {
718
+ throw new Error("Response body has already been consumed.");
719
+ }
720
+ if (this.raw.body === null) {
721
+ throw new Error("Response body does not exist.");
722
+ }
723
+ return this.raw.body;
724
+ }
725
+ }, {
726
+ key: "text",
727
+ value: function text() {
728
+ try {
729
+ var _this10 = this;
730
+ return runtime_await(_this10.raw.text());
731
+ } catch (e) {
732
+ return Promise.reject(e);
733
+ }
734
+ }
735
+ }, {
736
+ key: "blob",
737
+ value: function blob() {
738
+ try {
739
+ var _this12 = this;
740
+ return runtime_await(_this12.raw.blob());
741
+ } catch (e) {
742
+ return Promise.reject(e);
743
+ }
744
+ }
745
+ }, {
746
+ key: "json",
747
+ value: function json() {
748
+ try {
749
+ var _this14 = this;
750
+ return runtime_await(_this14.raw.json());
751
+ } catch (e) {
752
+ return Promise.reject(e);
753
+ }
754
+ }
755
+ }]);
756
+ return BinaryResult;
757
+ }();
758
+ ;// CONCATENATED MODULE: ./src/public/shared/generated/apis/FileApi.ts
759
+ 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); }
760
+ function FileApi_await(value, then, direct) {
761
+ if (direct) {
762
+ return then ? then(value) : value;
763
+ }
764
+ if (!value || !value.then) {
765
+ value = Promise.resolve(value);
766
+ }
767
+ return then ? value.then(then) : value;
768
+ }
769
+ function FileApi_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
770
+ function FileApi_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, FileApi_toPropertyKey(descriptor.key), descriptor); } }
771
+ function FileApi_createClass(Constructor, protoProps, staticProps) { if (protoProps) FileApi_defineProperties(Constructor.prototype, protoProps); if (staticProps) FileApi_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
772
+ function FileApi_toPropertyKey(arg) { var key = FileApi_toPrimitive(arg, "string"); return FileApi_typeof(key) === "symbol" ? key : String(key); }
773
+ function FileApi_toPrimitive(input, hint) { if (FileApi_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (FileApi_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
774
+ function FileApi_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) FileApi_setPrototypeOf(subClass, superClass); }
775
+ function FileApi_setPrototypeOf(o, p) { FileApi_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return FileApi_setPrototypeOf(o, p); }
776
+ function FileApi_createSuper(Derived) { var hasNativeReflectConstruct = FileApi_isNativeReflectConstruct(); return function _createSuperInternal() { var Super = FileApi_getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = FileApi_getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return FileApi_possibleConstructorReturn(this, result); }; }
777
+ function FileApi_possibleConstructorReturn(self, call) { if (call && (FileApi_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 FileApi_assertThisInitialized(self); }
778
+ function FileApi_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
779
+ function FileApi_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; } }
780
+ function FileApi_getPrototypeOf(o) { FileApi_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return FileApi_getPrototypeOf(o); }
781
+ /* tslint:disable */
782
+ /* eslint-disable */
783
+ /**
784
+ * @bytescale/api
785
+ * Bytescale API
786
+ *
787
+ * The version of the OpenAPI document: 2.0.0
788
+ * Contact: hello@bytescale.com
789
+ *
790
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
791
+ * https://openapi-generator.tech
792
+ * Do not edit the class manually.
793
+ */
794
+ // @ts-ignore
795
+
796
+ var FileApi = /*#__PURE__*/function (_runtime$BaseAPI) {
797
+ FileApi_inherits(FileApi, _runtime$BaseAPI);
798
+ var _super = FileApi_createSuper(FileApi);
799
+ function FileApi() {
800
+ FileApi_classCallCheck(this, FileApi);
801
+ return _super.apply(this, arguments);
802
+ }
803
+ FileApi_createClass(FileApi, [{
804
+ key: "copyFile",
805
+ value:
806
+ /**
807
+ * Copies a file synchronously.
808
+ */
809
+ function copyFile(params) {
810
+ try {
811
+ var _this2 = this;
812
+ var query = {};
813
+ var headers = {};
814
+ headers["Content-Type"] = "application/json";
815
+ return FileApi_await(_this2.request({
816
+ path: "/v2/accounts/{accountId}/files/copy".replace("{".concat("accountId", "}"),
817
+ // @ts-ignore
818
+ _this2.encodeParam("accountId", params.accountId)),
819
+ method: "POST",
820
+ headers: headers,
821
+ query: query,
822
+ body: params.copyFileRequest
823
+ }, undefined, [][0]), function (response) {
824
+ return FileApi_await(new JSONApiResponse(response).value());
825
+ });
826
+ } catch (e) {
827
+ return Promise.reject(e);
828
+ }
829
+ }
830
+ /**
831
+ * Copies multiple files asynchronously.
832
+ */
833
+ }, {
834
+ key: "copyFileBatch",
835
+ value: function copyFileBatch(params) {
836
+ try {
837
+ var _this4 = this;
838
+ var query = {};
839
+ var headers = {};
840
+ headers["Content-Type"] = "application/json";
841
+ return FileApi_await(_this4.request({
842
+ path: "/v2/accounts/{accountId}/files/copy/batch".replace("{".concat("accountId", "}"),
843
+ // @ts-ignore
844
+ _this4.encodeParam("accountId", params.accountId)),
845
+ method: "POST",
846
+ headers: headers,
847
+ query: query,
848
+ body: params.copyFileBatchRequest
849
+ }, undefined, [][0]), function (response) {
850
+ return FileApi_await(new JSONApiResponse(response).value());
851
+ });
852
+ } catch (e) {
853
+ return Promise.reject(e);
854
+ }
855
+ }
856
+ /**
857
+ * Deletes a file synchronously.
858
+ */
859
+ }, {
860
+ key: "deleteFile",
861
+ value: function deleteFile(params) {
862
+ try {
863
+ var _this6 = this;
864
+ var query = {};
865
+ if (params.filePath !== undefined) {
866
+ query["filePath"] = params.filePath;
867
+ }
868
+ var headers = {};
869
+ return FileApi_await(_this6.request({
870
+ path: "/v2/accounts/{accountId}/files".replace("{".concat("accountId", "}"),
871
+ // @ts-ignore
872
+ _this6.encodeParam("accountId", params.accountId)),
873
+ method: "DELETE",
874
+ headers: headers,
875
+ query: query
876
+ }, undefined, [][0]), function (response) {
877
+ return FileApi_await(new VoidApiResponse(response).value());
878
+ });
879
+ } catch (e) {
880
+ return Promise.reject(e);
881
+ }
882
+ }
883
+ /**
884
+ * Deletes multiple files asynchronously.
885
+ */
886
+ }, {
887
+ key: "deleteFileBatch",
888
+ value: function deleteFileBatch(params) {
889
+ try {
890
+ var _this8 = this;
891
+ var query = {};
892
+ var headers = {};
893
+ headers["Content-Type"] = "application/json";
894
+ return FileApi_await(_this8.request({
895
+ path: "/v2/accounts/{accountId}/files/batch".replace("{".concat("accountId", "}"),
896
+ // @ts-ignore
897
+ _this8.encodeParam("accountId", params.accountId)),
898
+ method: "DELETE",
899
+ headers: headers,
900
+ query: query,
901
+ body: params.deleteFileBatchRequest
902
+ }, undefined, [][0]), function (response) {
903
+ return FileApi_await(new JSONApiResponse(response).value());
904
+ });
905
+ } catch (e) {
906
+ return Promise.reject(e);
907
+ }
908
+ }
909
+ /**
910
+ * Downloads a file in its original/unprocessed state.
911
+ */
912
+ }, {
913
+ key: "downloadFile",
914
+ value: function downloadFile(params) {
915
+ try {
916
+ var _this10 = this;
917
+ var query = {};
918
+ if (params.cache !== undefined) {
919
+ query["cache"] = params.cache;
920
+ }
921
+ if (params.cacheTtl !== undefined) {
922
+ query["cache_ttl"] = params.cacheTtl;
923
+ }
924
+ if (params.version !== undefined) {
925
+ query["version"] = params.version;
926
+ }
927
+ var headers = {};
928
+ return FileApi_await(_this10.request({
929
+ path: "/{accountId}/raw{filePath}".replace("{".concat("accountId", "}"),
930
+ // @ts-ignore
931
+ _this10.encodeParam("accountId", params.accountId)).replace("{".concat("filePath", "}"),
932
+ // @ts-ignore
933
+ _this10.encodeParam("filePath", params.filePath)),
934
+ method: "GET",
935
+ headers: headers,
936
+ query: query
937
+ }, undefined, ["https://upcdn.io"][0]), function (response) {
938
+ return new BinaryResult(response);
939
+ });
940
+ } catch (e) {
941
+ return Promise.reject(e);
942
+ }
943
+ }
944
+ /**
945
+ * Gets the full details (e.g. metadata, tags, etc.) for a file.
946
+ */
947
+ }, {
948
+ key: "getFileDetails",
949
+ value: function getFileDetails(params) {
950
+ try {
951
+ var _this12 = this;
952
+ var query = {};
953
+ if (params.filePath !== undefined) {
954
+ query["filePath"] = params.filePath;
955
+ }
956
+ var headers = {};
957
+ return FileApi_await(_this12.request({
958
+ path: "/v2/accounts/{accountId}/files/details".replace("{".concat("accountId", "}"),
959
+ // @ts-ignore
960
+ _this12.encodeParam("accountId", params.accountId)),
961
+ method: "GET",
962
+ headers: headers,
963
+ query: query
964
+ }, undefined, [][0]), function (response) {
965
+ return FileApi_await(new JSONApiResponse(response).value());
966
+ });
967
+ } catch (e) {
968
+ return Promise.reject(e);
969
+ }
970
+ }
971
+ /**
972
+ * Processes a file and returns the result.
973
+ */
974
+ }, {
975
+ key: "processFile",
976
+ value: function processFile(params) {
977
+ try {
978
+ var _this14 = this;
979
+ var query = {};
980
+ if (params.artifact !== undefined) {
981
+ query["artifact"] = params.artifact;
982
+ }
983
+ if (params.cache !== undefined) {
984
+ query["cache"] = params.cache;
985
+ }
986
+ if (params.cachePerm !== undefined) {
987
+ query["cache_perm"] = params.cachePerm;
988
+ }
989
+ if (params.cacheTtl !== undefined) {
990
+ query["cache_ttl"] = params.cacheTtl;
991
+ }
992
+ if (params.large !== undefined) {
993
+ query["large"] = params.large;
994
+ }
995
+ if (params.transformationParams !== undefined) {
996
+ query["transformationParams"] = params.transformationParams;
997
+ }
998
+ if (params.version !== undefined) {
999
+ query["version"] = params.version;
1000
+ }
1001
+ var headers = {};
1002
+ return FileApi_await(_this14.request({
1003
+ path: "/{accountId}/{transformation}{filePath}".replace("{".concat("accountId", "}"),
1004
+ // @ts-ignore
1005
+ _this14.encodeParam("accountId", params.accountId)).replace("{".concat("filePath", "}"),
1006
+ // @ts-ignore
1007
+ _this14.encodeParam("filePath", params.filePath)).replace("{".concat("transformation", "}"),
1008
+ // @ts-ignore
1009
+ _this14.encodeParam("transformation", params.transformation)),
1010
+ method: "GET",
1011
+ headers: headers,
1012
+ query: query
1013
+ }, undefined, ["https://upcdn.io"][0]), function (response) {
1014
+ return new BinaryResult(response);
1015
+ });
1016
+ } catch (e) {
1017
+ return Promise.reject(e);
1018
+ }
1019
+ }
1020
+ /**
1021
+ * Processes a file and saves the result.
1022
+ */
1023
+ }, {
1024
+ key: "processFileAndSave",
1025
+ value: function processFileAndSave(params) {
1026
+ try {
1027
+ var _this16 = this;
1028
+ var query = {};
1029
+ if (params.transformationParams !== undefined) {
1030
+ query["transformationParams"] = params.transformationParams;
1031
+ }
1032
+ var headers = {};
1033
+ headers["Content-Type"] = "application/json";
1034
+ return FileApi_await(_this16.request({
1035
+ path: "/{accountId}/save/{transformation}{filePath}".replace("{".concat("accountId", "}"),
1036
+ // @ts-ignore
1037
+ _this16.encodeParam("accountId", params.accountId)).replace("{".concat("filePath", "}"),
1038
+ // @ts-ignore
1039
+ _this16.encodeParam("filePath", params.filePath)).replace("{".concat("transformation", "}"),
1040
+ // @ts-ignore
1041
+ _this16.encodeParam("transformation", params.transformation)),
1042
+ method: "POST",
1043
+ headers: headers,
1044
+ query: query,
1045
+ body: params.processFileAndSaveRequest
1046
+ }, undefined, ["https://upcdn.io"][0]), function (response) {
1047
+ return FileApi_await(new JSONApiResponse(response).value());
1048
+ });
1049
+ } catch (e) {
1050
+ return Promise.reject(e);
1051
+ }
1052
+ }
1053
+ }]);
1054
+ return FileApi;
1055
+ }(BaseAPI);
1056
+ ;// CONCATENATED MODULE: ./src/public/shared/generated/apis/FolderApi.ts
1057
+ 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); }
1058
+ function FolderApi_await(value, then, direct) {
1059
+ if (direct) {
1060
+ return then ? then(value) : value;
1061
+ }
1062
+ if (!value || !value.then) {
1063
+ value = Promise.resolve(value);
1064
+ }
1065
+ return then ? value.then(then) : value;
1066
+ }
1067
+ function FolderApi_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1068
+ function FolderApi_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, FolderApi_toPropertyKey(descriptor.key), descriptor); } }
1069
+ function FolderApi_createClass(Constructor, protoProps, staticProps) { if (protoProps) FolderApi_defineProperties(Constructor.prototype, protoProps); if (staticProps) FolderApi_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
1070
+ function FolderApi_toPropertyKey(arg) { var key = FolderApi_toPrimitive(arg, "string"); return FolderApi_typeof(key) === "symbol" ? key : String(key); }
1071
+ function FolderApi_toPrimitive(input, hint) { if (FolderApi_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (FolderApi_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
1072
+ function FolderApi_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) FolderApi_setPrototypeOf(subClass, superClass); }
1073
+ function FolderApi_setPrototypeOf(o, p) { FolderApi_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return FolderApi_setPrototypeOf(o, p); }
1074
+ function FolderApi_createSuper(Derived) { var hasNativeReflectConstruct = FolderApi_isNativeReflectConstruct(); return function _createSuperInternal() { var Super = FolderApi_getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = FolderApi_getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return FolderApi_possibleConstructorReturn(this, result); }; }
1075
+ function FolderApi_possibleConstructorReturn(self, call) { if (call && (FolderApi_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 FolderApi_assertThisInitialized(self); }
1076
+ function FolderApi_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
1077
+ function FolderApi_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; } }
1078
+ function FolderApi_getPrototypeOf(o) { FolderApi_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return FolderApi_getPrototypeOf(o); }
1079
+ /* tslint:disable */
1080
+ /* eslint-disable */
1081
+ /**
1082
+ * @bytescale/api
1083
+ * Bytescale API
1084
+ *
1085
+ * The version of the OpenAPI document: 2.0.0
1086
+ * Contact: hello@bytescale.com
1087
+ *
1088
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
1089
+ * https://openapi-generator.tech
1090
+ * Do not edit the class manually.
1091
+ */
1092
+ // @ts-ignore
1093
+
1094
+ var FolderApi = /*#__PURE__*/function (_runtime$BaseAPI) {
1095
+ FolderApi_inherits(FolderApi, _runtime$BaseAPI);
1096
+ var _super = FolderApi_createSuper(FolderApi);
1097
+ function FolderApi() {
1098
+ FolderApi_classCallCheck(this, FolderApi);
1099
+ return _super.apply(this, arguments);
1100
+ }
1101
+ FolderApi_createClass(FolderApi, [{
1102
+ key: "copyFolder",
1103
+ value:
1104
+ /**
1105
+ * Copies a folder asynchronously. You can use ListFolder to preview the operation: set `dryRun=true` with ```recursive```, ```includeFiles```, ```includeOverriddenStorage``` and ```includeVirtualFolders``` set to match the values you\'re using here. Leave all other flags unset.
1106
+ */
1107
+ function copyFolder(params) {
1108
+ try {
1109
+ var _this2 = this;
1110
+ var query = {};
1111
+ var headers = {};
1112
+ headers["Content-Type"] = "application/json";
1113
+ return FolderApi_await(_this2.request({
1114
+ path: "/v2/accounts/{accountId}/folders/copy".replace("{".concat("accountId", "}"),
1115
+ // @ts-ignore
1116
+ _this2.encodeParam("accountId", params.accountId)),
1117
+ method: "POST",
1118
+ headers: headers,
1119
+ query: query,
1120
+ body: params.copyFolderRequest
1121
+ }, undefined, [][0]), function (response) {
1122
+ return FolderApi_await(new JSONApiResponse(response).value());
1123
+ });
1124
+ } catch (e) {
1125
+ return Promise.reject(e);
1126
+ }
1127
+ }
1128
+ /**
1129
+ * Copies multiple folders asynchronously. You can use ListFolder to preview the operation: set `dryRun=true` with ```recursive```, ```includeFiles```, ```includeOverriddenStorage``` and ```includeVirtualFolders``` set to match the values you\'re using here. Leave all other flags unset.
1130
+ */
1131
+ }, {
1132
+ key: "copyFolderBatch",
1133
+ value: function copyFolderBatch(params) {
1134
+ try {
1135
+ var _this4 = this;
1136
+ var query = {};
1137
+ var headers = {};
1138
+ headers["Content-Type"] = "application/json";
1139
+ return FolderApi_await(_this4.request({
1140
+ path: "/v2/accounts/{accountId}/folders/copy/batch".replace("{".concat("accountId", "}"),
1141
+ // @ts-ignore
1142
+ _this4.encodeParam("accountId", params.accountId)),
1143
+ method: "POST",
1144
+ headers: headers,
1145
+ query: query,
1146
+ body: params.copyFolderBatchRequest
1147
+ }, undefined, [][0]), function (response) {
1148
+ return FolderApi_await(new JSONApiResponse(response).value());
1149
+ });
1150
+ } catch (e) {
1151
+ return Promise.reject(e);
1152
+ }
1153
+ }
1154
+ /**
1155
+ * Deletes a folder asynchronously. If the folder has overridden storage settings, then no files will be deleted. You can use ListFolder to preview the operation: set `dryRun=true` with ```recursive```, ```includeFiles``` and ```includeVirtualFolders``` set to match the values you\'re using here. Leave all other flags unset.
1156
+ */
1157
+ }, {
1158
+ key: "deleteFolder",
1159
+ value: function deleteFolder(params) {
1160
+ try {
1161
+ var _this6 = this;
1162
+ var query = {};
1163
+ var headers = {};
1164
+ headers["Content-Type"] = "application/json";
1165
+ return FolderApi_await(_this6.request({
1166
+ path: "/v2/accounts/{accountId}/folders".replace("{".concat("accountId", "}"),
1167
+ // @ts-ignore
1168
+ _this6.encodeParam("accountId", params.accountId)),
1169
+ method: "DELETE",
1170
+ headers: headers,
1171
+ query: query,
1172
+ body: params.deleteFolderRequest
1173
+ }, undefined, [][0]), function (response) {
1174
+ return FolderApi_await(new JSONApiResponse(response).value());
1175
+ });
1176
+ } catch (e) {
1177
+ return Promise.reject(e);
1178
+ }
1179
+ }
1180
+ /**
1181
+ * Deletes multiple folders asynchronously. If the folder has overridden storage settings, then no files will be deleted. You can use ListFolder to preview the operation: set `dryRun=true` with ```recursive```, ```includeFiles``` and ```includeVirtualFolders``` set to match the values you\'re using here. Leave all other flags unset.
1182
+ */
1183
+ }, {
1184
+ key: "deleteFolderBatch",
1185
+ value: function deleteFolderBatch(params) {
1186
+ try {
1187
+ var _this8 = this;
1188
+ var query = {};
1189
+ var headers = {};
1190
+ headers["Content-Type"] = "application/json";
1191
+ return FolderApi_await(_this8.request({
1192
+ path: "/v2/accounts/{accountId}/folders/batch".replace("{".concat("accountId", "}"),
1193
+ // @ts-ignore
1194
+ _this8.encodeParam("accountId", params.accountId)),
1195
+ method: "DELETE",
1196
+ headers: headers,
1197
+ query: query,
1198
+ body: params.deleteFolderBatchRequest
1199
+ }, undefined, [][0]), function (response) {
1200
+ return FolderApi_await(new JSONApiResponse(response).value());
1201
+ });
1202
+ } catch (e) {
1203
+ return Promise.reject(e);
1204
+ }
1205
+ }
1206
+ /**
1207
+ * Gets the full details (e.g. permission, storage layer, etc.) for a folder. Returns an empty object if no settings have been configured for this folder.
1208
+ */
1209
+ }, {
1210
+ key: "getFolderDetails",
1211
+ value: function getFolderDetails(params) {
1212
+ try {
1213
+ var _this10 = this;
1214
+ var query = {};
1215
+ if (params.folderPath !== undefined) {
1216
+ query["folderPath"] = params.folderPath;
1217
+ }
1218
+ var headers = {};
1219
+ return FolderApi_await(_this10.request({
1220
+ path: "/v2/accounts/{accountId}/folders".replace("{".concat("accountId", "}"),
1221
+ // @ts-ignore
1222
+ _this10.encodeParam("accountId", params.accountId)),
1223
+ method: "GET",
1224
+ headers: headers,
1225
+ query: query
1226
+ }, undefined, [][0]), function (response) {
1227
+ return FolderApi_await(new JSONApiResponse(response).value());
1228
+ });
1229
+ } catch (e) {
1230
+ return Promise.reject(e);
1231
+ }
1232
+ }
1233
+ /**
1234
+ * Lists the folder\'s contents. The result may be paginated: subsequent pages can be requested by passing the ```cursor``` from the response into the ```cursor``` request parameter. Pagination is complete when the response includes `isPaginationComplete=true`.
1235
+ */
1236
+ }, {
1237
+ key: "listFolder",
1238
+ value: function listFolder(params) {
1239
+ try {
1240
+ var _this12 = this;
1241
+ var query = {};
1242
+ if (params.cursor !== undefined) {
1243
+ query["cursor"] = params.cursor;
1244
+ }
1245
+ if (params.dryRun !== undefined) {
1246
+ query["dryRun"] = params.dryRun;
1247
+ }
1248
+ if (params.folderPath !== undefined) {
1249
+ query["folderPath"] = params.folderPath;
1250
+ }
1251
+ if (params.includeFiles !== undefined) {
1252
+ query["includeFiles"] = params.includeFiles;
1253
+ }
1254
+ if (params.includeOverriddenStorage !== undefined) {
1255
+ query["includeOverriddenStorage"] = params.includeOverriddenStorage;
1256
+ }
1257
+ if (params.includePhysicalFolders !== undefined) {
1258
+ query["includePhysicalFolders"] = params.includePhysicalFolders;
1259
+ }
1260
+ if (params.includeVirtualFolders !== undefined) {
1261
+ query["includeVirtualFolders"] = params.includeVirtualFolders;
1262
+ }
1263
+ if (params.limit !== undefined) {
1264
+ query["limit"] = params.limit;
1265
+ }
1266
+ if (params.recursive !== undefined) {
1267
+ query["recursive"] = params.recursive;
1268
+ }
1269
+ var headers = {};
1270
+ return FolderApi_await(_this12.request({
1271
+ path: "/v2/accounts/{accountId}/folders/list".replace("{".concat("accountId", "}"),
1272
+ // @ts-ignore
1273
+ _this12.encodeParam("accountId", params.accountId)),
1274
+ method: "GET",
1275
+ headers: headers,
1276
+ query: query
1277
+ }, undefined, [][0]), function (response) {
1278
+ return FolderApi_await(new JSONApiResponse(response).value());
1279
+ });
1280
+ } catch (e) {
1281
+ return Promise.reject(e);
1282
+ }
1283
+ }
1284
+ /**
1285
+ * Creates or updates the folder specified by the `folderPath`. If the folder\'s ancestors do not exist, they will be created automatically (with empty FolderSettings). Note: you don\'t need to create folders before uploading files to them.
1286
+ */
1287
+ }, {
1288
+ key: "putFolder",
1289
+ value: function putFolder(params) {
1290
+ try {
1291
+ var _this14 = this;
1292
+ var query = {};
1293
+ var headers = {};
1294
+ headers["Content-Type"] = "application/json";
1295
+ return FolderApi_await(_this14.request({
1296
+ path: "/v2/accounts/{accountId}/folders".replace("{".concat("accountId", "}"),
1297
+ // @ts-ignore
1298
+ _this14.encodeParam("accountId", params.accountId)),
1299
+ method: "PUT",
1300
+ headers: headers,
1301
+ query: query,
1302
+ body: params.putFolderRequest
1303
+ }, undefined, [][0]), function (response) {
1304
+ return FolderApi_await(new JSONApiResponse(response).value());
1305
+ });
1306
+ } catch (e) {
1307
+ return Promise.reject(e);
1308
+ }
1309
+ }
1310
+ }]);
1311
+ return FolderApi;
1312
+ }(BaseAPI);
1313
+ ;// CONCATENATED MODULE: ./src/public/shared/generated/apis/JobApi.ts
1314
+ 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); }
1315
+ function JobApi_await(value, then, direct) {
1316
+ if (direct) {
1317
+ return then ? then(value) : value;
1318
+ }
1319
+ if (!value || !value.then) {
1320
+ value = Promise.resolve(value);
1321
+ }
1322
+ return then ? value.then(then) : value;
1323
+ }
1324
+ function JobApi_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1325
+ function JobApi_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, JobApi_toPropertyKey(descriptor.key), descriptor); } }
1326
+ function JobApi_createClass(Constructor, protoProps, staticProps) { if (protoProps) JobApi_defineProperties(Constructor.prototype, protoProps); if (staticProps) JobApi_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
1327
+ function JobApi_toPropertyKey(arg) { var key = JobApi_toPrimitive(arg, "string"); return JobApi_typeof(key) === "symbol" ? key : String(key); }
1328
+ function JobApi_toPrimitive(input, hint) { if (JobApi_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (JobApi_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
1329
+ function JobApi_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) JobApi_setPrototypeOf(subClass, superClass); }
1330
+ function JobApi_setPrototypeOf(o, p) { JobApi_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return JobApi_setPrototypeOf(o, p); }
1331
+ function JobApi_createSuper(Derived) { var hasNativeReflectConstruct = JobApi_isNativeReflectConstruct(); return function _createSuperInternal() { var Super = JobApi_getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = JobApi_getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return JobApi_possibleConstructorReturn(this, result); }; }
1332
+ function JobApi_possibleConstructorReturn(self, call) { if (call && (JobApi_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 JobApi_assertThisInitialized(self); }
1333
+ function JobApi_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
1334
+ function JobApi_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; } }
1335
+ function JobApi_getPrototypeOf(o) { JobApi_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return JobApi_getPrototypeOf(o); }
1336
+ /* tslint:disable */
1337
+ /* eslint-disable */
1338
+ /**
1339
+ * @bytescale/api
1340
+ * Bytescale API
1341
+ *
1342
+ * The version of the OpenAPI document: 2.0.0
1343
+ * Contact: hello@bytescale.com
1344
+ *
1345
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
1346
+ * https://openapi-generator.tech
1347
+ * Do not edit the class manually.
1348
+ */
1349
+ // @ts-ignore
1350
+
1351
+ var JobApi = /*#__PURE__*/function (_runtime$BaseAPI) {
1352
+ JobApi_inherits(JobApi, _runtime$BaseAPI);
1353
+ var _super = JobApi_createSuper(JobApi);
1354
+ function JobApi() {
1355
+ JobApi_classCallCheck(this, JobApi);
1356
+ return _super.apply(this, arguments);
1357
+ }
1358
+ JobApi_createClass(JobApi, [{
1359
+ key: "cancelJob",
1360
+ value:
1361
+ /**
1362
+ * Cancels an in-progress background job. Requires a `secret_*` API key.
1363
+ */
1364
+ function cancelJob(params) {
1365
+ try {
1366
+ var _this2 = this;
1367
+ var query = {};
1368
+ var headers = {};
1369
+ return JobApi_await(_this2.request({
1370
+ path: "/v2/accounts/{accountId}/jobs/{jobType}/{jobId}".replace("{".concat("accountId", "}"),
1371
+ // @ts-ignore
1372
+ _this2.encodeParam("accountId", params.accountId)).replace("{".concat("jobId", "}"),
1373
+ // @ts-ignore
1374
+ _this2.encodeParam("jobId", params.jobId)).replace("{".concat("jobType", "}"),
1375
+ // @ts-ignore
1376
+ _this2.encodeParam("jobType", params.jobType)),
1377
+ method: "DELETE",
1378
+ headers: headers,
1379
+ query: query
1380
+ }, undefined, [][0]), function (response) {
1381
+ return JobApi_await(new VoidApiResponse(response).value());
1382
+ });
1383
+ } catch (e) {
1384
+ return Promise.reject(e);
1385
+ }
1386
+ }
1387
+ /**
1388
+ * Gets information on a background job. Requires a `secret_*` API key.
1389
+ */
1390
+ }, {
1391
+ key: "getJob",
1392
+ value: function getJob(params) {
1393
+ try {
1394
+ var _this4 = this;
1395
+ var query = {};
1396
+ var headers = {};
1397
+ return JobApi_await(_this4.request({
1398
+ path: "/v2/accounts/{accountId}/jobs/{jobType}/{jobId}".replace("{".concat("accountId", "}"),
1399
+ // @ts-ignore
1400
+ _this4.encodeParam("accountId", params.accountId)).replace("{".concat("jobId", "}"),
1401
+ // @ts-ignore
1402
+ _this4.encodeParam("jobId", params.jobId)).replace("{".concat("jobType", "}"),
1403
+ // @ts-ignore
1404
+ _this4.encodeParam("jobType", params.jobType)),
1405
+ method: "GET",
1406
+ headers: headers,
1407
+ query: query
1408
+ }, undefined, [][0]), function (response) {
1409
+ return JobApi_await(new JSONApiResponse(response).value());
1410
+ });
1411
+ } catch (e) {
1412
+ return Promise.reject(e);
1413
+ }
1414
+ }
1415
+ /**
1416
+ * Lists the most recently issued background jobs. Requires a `secret_*` API key.
1417
+ */
1418
+ }, {
1419
+ key: "listRecentJobs",
1420
+ value: function listRecentJobs(params) {
1421
+ try {
1422
+ var _this6 = this;
1423
+ var query = {};
1424
+ if (params.jobType) {
1425
+ query["jobType"] = params.jobType;
1426
+ }
1427
+ var headers = {};
1428
+ return JobApi_await(_this6.request({
1429
+ path: "/v2/accounts/{accountId}/jobs".replace("{".concat("accountId", "}"),
1430
+ // @ts-ignore
1431
+ _this6.encodeParam("accountId", params.accountId)),
1432
+ method: "GET",
1433
+ headers: headers,
1434
+ query: query
1435
+ }, undefined, [][0]), function (response) {
1436
+ return JobApi_await(new JSONApiResponse(response).value());
1437
+ });
1438
+ } catch (e) {
1439
+ return Promise.reject(e);
1440
+ }
1441
+ }
1442
+ }]);
1443
+ return JobApi;
1444
+ }(BaseAPI);
1445
+ ;// CONCATENATED MODULE: ./src/public/shared/generated/apis/UploadApi.ts
1446
+ 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); }
1447
+ function UploadApi_await(value, then, direct) {
1448
+ if (direct) {
1449
+ return then ? then(value) : value;
1450
+ }
1451
+ if (!value || !value.then) {
1452
+ value = Promise.resolve(value);
1453
+ }
1454
+ return then ? value.then(then) : value;
1455
+ }
1456
+ function UploadApi_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1457
+ function UploadApi_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, UploadApi_toPropertyKey(descriptor.key), descriptor); } }
1458
+ function UploadApi_createClass(Constructor, protoProps, staticProps) { if (protoProps) UploadApi_defineProperties(Constructor.prototype, protoProps); if (staticProps) UploadApi_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
1459
+ function UploadApi_toPropertyKey(arg) { var key = UploadApi_toPrimitive(arg, "string"); return UploadApi_typeof(key) === "symbol" ? key : String(key); }
1460
+ function UploadApi_toPrimitive(input, hint) { if (UploadApi_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (UploadApi_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
1461
+ function UploadApi_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) UploadApi_setPrototypeOf(subClass, superClass); }
1462
+ function UploadApi_setPrototypeOf(o, p) { UploadApi_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return UploadApi_setPrototypeOf(o, p); }
1463
+ function UploadApi_createSuper(Derived) { var hasNativeReflectConstruct = UploadApi_isNativeReflectConstruct(); return function _createSuperInternal() { var Super = UploadApi_getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = UploadApi_getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return UploadApi_possibleConstructorReturn(this, result); }; }
1464
+ function UploadApi_possibleConstructorReturn(self, call) { if (call && (UploadApi_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 UploadApi_assertThisInitialized(self); }
1465
+ function UploadApi_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
1466
+ function UploadApi_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; } }
1467
+ function UploadApi_getPrototypeOf(o) { UploadApi_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return UploadApi_getPrototypeOf(o); }
1468
+ /* tslint:disable */
1469
+ /* eslint-disable */
1470
+ /**
1471
+ * @bytescale/api
1472
+ * Bytescale API
1473
+ *
1474
+ * The version of the OpenAPI document: 2.0.0
1475
+ * Contact: hello@bytescale.com
1476
+ *
1477
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
1478
+ * https://openapi-generator.tech
1479
+ * Do not edit the class manually.
1480
+ */
1481
+ // @ts-ignore
1482
+
1483
+ var UploadApi = /*#__PURE__*/function (_runtime$BaseAPI) {
1484
+ UploadApi_inherits(UploadApi, _runtime$BaseAPI);
1485
+ var _super = UploadApi_createSuper(UploadApi);
1486
+ function UploadApi() {
1487
+ UploadApi_classCallCheck(this, UploadApi);
1488
+ return _super.apply(this, arguments);
1489
+ }
1490
+ UploadApi_createClass(UploadApi, [{
1491
+ key: "beginMultipartUpload",
1492
+ value:
1493
+ /**
1494
+ * Begins a new multipart file upload process.
1495
+ */
1496
+ function beginMultipartUpload(params) {
1497
+ try {
1498
+ var _this2 = this;
1499
+ var query = {};
1500
+ var headers = {};
1501
+ headers["Content-Type"] = "application/json";
1502
+ return UploadApi_await(_this2.request({
1503
+ path: "/v2/accounts/{accountId}/uploads".replace("{".concat("accountId", "}"),
1504
+ // @ts-ignore
1505
+ _this2.encodeParam("accountId", params.accountId)),
1506
+ method: "POST",
1507
+ headers: headers,
1508
+ query: query,
1509
+ body: params.beginMultipartUploadRequest
1510
+ }, undefined, [][0]), function (response) {
1511
+ return UploadApi_await(new JSONApiResponse(response).value());
1512
+ });
1513
+ } catch (e) {
1514
+ return Promise.reject(e);
1515
+ }
1516
+ }
1517
+ /**
1518
+ * Marks an upload part as uploaded. You must call this endpoint after you have successfully issued a `PUT` request to the `uploadUrl` on the corresponding UploadPart.
1519
+ */
1520
+ }, {
1521
+ key: "completeUploadPart",
1522
+ value: function completeUploadPart(params) {
1523
+ try {
1524
+ var _this4 = this;
1525
+ var query = {};
1526
+ var headers = {};
1527
+ headers["Content-Type"] = "application/json";
1528
+ return UploadApi_await(_this4.request({
1529
+ path: "/v2/accounts/{accountId}/uploads/{uploadId}/parts/{uploadPartIndex}".replace("{".concat("accountId", "}"),
1530
+ // @ts-ignore
1531
+ _this4.encodeParam("accountId", params.accountId)).replace("{".concat("uploadId", "}"),
1532
+ // @ts-ignore
1533
+ _this4.encodeParam("uploadId", params.uploadId)).replace("{".concat("uploadPartIndex", "}"),
1534
+ // @ts-ignore
1535
+ _this4.encodeParam("uploadPartIndex", params.uploadPartIndex)),
1536
+ method: "PUT",
1537
+ headers: headers,
1538
+ query: query,
1539
+ body: params.completeUploadPartRequest
1540
+ }, undefined, [][0]), function (response) {
1541
+ return UploadApi_await(new VoidApiResponse(response).value());
1542
+ });
1543
+ } catch (e) {
1544
+ return Promise.reject(e);
1545
+ }
1546
+ }
1547
+ /**
1548
+ * Gets a remaining upload part for a multipart file upload.
1549
+ */
1550
+ }, {
1551
+ key: "getUploadPart",
1552
+ value: function getUploadPart(params) {
1553
+ try {
1554
+ var _this6 = this;
1555
+ var query = {};
1556
+ var headers = {};
1557
+ return UploadApi_await(_this6.request({
1558
+ path: "/v2/accounts/{accountId}/uploads/{uploadId}/parts/{uploadPartIndex}".replace("{".concat("accountId", "}"),
1559
+ // @ts-ignore
1560
+ _this6.encodeParam("accountId", params.accountId)).replace("{".concat("uploadId", "}"),
1561
+ // @ts-ignore
1562
+ _this6.encodeParam("uploadId", params.uploadId)).replace("{".concat("uploadPartIndex", "}"),
1563
+ // @ts-ignore
1564
+ _this6.encodeParam("uploadPartIndex", params.uploadPartIndex)),
1565
+ method: "GET",
1566
+ headers: headers,
1567
+ query: query
1568
+ }, undefined, [][0]), function (response) {
1569
+ return UploadApi_await(new JSONApiResponse(response).value());
1570
+ });
1571
+ } catch (e) {
1572
+ return Promise.reject(e);
1573
+ }
1574
+ }
1575
+ /**
1576
+ * Lists the remaining upload parts for a multipart file upload. An empty array is returned when the upload is complete.
1577
+ */
1578
+ }, {
1579
+ key: "listUploadParts",
1580
+ value: function listUploadParts(params) {
1581
+ try {
1582
+ var _this8 = this;
1583
+ var query = {};
1584
+ var headers = {};
1585
+ return UploadApi_await(_this8.request({
1586
+ path: "/v2/accounts/{accountId}/uploads/{uploadId}/parts".replace("{".concat("accountId", "}"),
1587
+ // @ts-ignore
1588
+ _this8.encodeParam("accountId", params.accountId)).replace("{".concat("uploadId", "}"),
1589
+ // @ts-ignore
1590
+ _this8.encodeParam("uploadId", params.uploadId)),
1591
+ method: "GET",
1592
+ headers: headers,
1593
+ query: query
1594
+ }, undefined, [][0]), function (response) {
1595
+ return UploadApi_await(new JSONApiResponse(response).value());
1596
+ });
1597
+ } catch (e) {
1598
+ return Promise.reject(e);
1599
+ }
1600
+ }
1601
+ /**
1602
+ * Upload from a URL with a single HTTP request:
1603
+ */
1604
+ }, {
1605
+ key: "uploadFromUrl",
1606
+ value: function uploadFromUrl(params) {
1607
+ try {
1608
+ var _this10 = this;
1609
+ var query = {};
1610
+ var headers = {};
1611
+ headers["Content-Type"] = "application/json";
1612
+ return UploadApi_await(_this10.request({
1613
+ path: "/v2/accounts/{accountId}/uploads/url".replace("{".concat("accountId", "}"),
1614
+ // @ts-ignore
1615
+ _this10.encodeParam("accountId", params.accountId)),
1616
+ method: "POST",
1617
+ headers: headers,
1618
+ query: query,
1619
+ body: params.uploadFromUrlRequest
1620
+ }, undefined, [][0]), function (response) {
1621
+ return UploadApi_await(new JSONApiResponse(response).value());
1622
+ });
1623
+ } catch (e) {
1624
+ return Promise.reject(e);
1625
+ }
1626
+ }
1627
+ }]);
1628
+ return UploadApi;
1629
+ }(BaseAPI);
1630
+ ;// CONCATENATED MODULE: ./src/public/shared/generated/apis/index.ts
1631
+ /* tslint:disable */
1632
+ /* eslint-disable */
1633
+
1634
+
1635
+
1636
+
1637
+ ;// CONCATENATED MODULE: ./src/public/shared/generated/index.ts
1638
+ /* tslint:disable */
1639
+ /* eslint-disable */
1640
+
1641
+
1642
+
1643
+ ;// CONCATENATED MODULE: ./src/public/shared/CommonTypes.ts
1644
+ /**
1645
+ * Workaround for tsc aliases, where we cannot export implementation-less libs in our dists.
1646
+ */
1647
+ var CommonTypesNoOp = false;
1648
+ ;// CONCATENATED MODULE: ./src/private/TypeUtils.ts
1649
+ function assertUnreachable(x) {
1650
+ throw new Error("Didn't expect to get here: ".concat(JSON.stringify(x)));
1651
+ }
1652
+ function isDefinedEntry(object) {
1653
+ return object[1] !== undefined && object[1] !== null;
1654
+ }
1655
+ ;// CONCATENATED MODULE: ./src/public/shared/UrlBuilder.ts
1656
+ 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); }
1657
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
1658
+ 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."); }
1659
+ 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; } }
1660
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
1661
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
1662
+ 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."); }
1663
+ 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); }
1664
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
1665
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
1666
+ 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; }
1667
+ function UrlBuilder_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1668
+ 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); } }
1669
+ 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; }
1670
+ function UrlBuilder_toPropertyKey(arg) { var key = UrlBuilder_toPrimitive(arg, "string"); return UrlBuilder_typeof(key) === "symbol" ? key : String(key); }
1671
+ 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); }
1672
+
1673
+
1674
+ var UrlBuilder = /*#__PURE__*/function () {
1675
+ function UrlBuilder() {
1676
+ UrlBuilder_classCallCheck(this, UrlBuilder);
1677
+ }
1678
+ UrlBuilder_createClass(UrlBuilder, null, [{
1679
+ key: "url",
1680
+ value:
1681
+ /**
1682
+ * Builds a URL to either a raw file or a transformed file.
1683
+ *
1684
+ * Example 1) Getting a publicly-accessible raw file URL:
1685
+ *
1686
+ * new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg" })
1687
+ *
1688
+ * Example 2) Getting a publicly-accessible image URL, resized to 500x500:
1689
+ *
1690
+ * new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "image", params: { w: 500, h: 500, fit: "crop" } } } })
1691
+ *
1692
+ * Example 3) Getting a privately-accessible image URL, resized to 500x500 (requires 'AuthManager.beginAuthSession' to be called before accessing the URL):
1693
+ *
1694
+ * new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "image", params: { w: 500, h: 500, fit: "crop" } }, auth: true } })
1695
+ *
1696
+ * Example 4) Getting a publicly-accessible image URL, resized using a transformation preset called "thumbnail" that was created manually in the Bytescale Dashboard:
1697
+ *
1698
+ * new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "preset", preset: "thumbnail" } } })
1699
+ */
1700
+ function url(params) {
1701
+ var _a;
1702
+ return ((_a = params.options) === null || _a === void 0 ? void 0 : _a.transformation) === undefined ? this.raw(params) : this.transformation(params, params.options);
1703
+ }
1704
+ }, {
1705
+ key: "raw",
1706
+ value: function raw(params) {
1707
+ var _a;
1708
+ var baseUrl = this.getBaseUrl(params, "raw");
1709
+ var commonParams = this.getCommonQueryParams((_a = params.options) !== null && _a !== void 0 ? _a : {});
1710
+ return this.addQueryParams(baseUrl, commonParams);
1711
+ }
1712
+ }, {
1713
+ key: "transformation",
1714
+ value: function transformation(params, trans) {
1715
+ var _a;
1716
+ var baseUrl = this.getBaseUrl(params, trans.transformation === "preset" ? trans.transformationPreset : trans.transformation);
1717
+ var transParams = trans.transformation === "preset" ? [] : this.getTransformationParams(trans);
1718
+ var commonParams = this.getCommonQueryParams((_a = params.options) !== null && _a !== void 0 ? _a : {});
1719
+ var transCommonParams = this.getCommonTransformationQueryParams(trans);
1720
+ // This format puts "artifact" at the end, which isn't required, but is convention.
1721
+ return this.addQueryParams(baseUrl, [].concat(_toConsumableArray(transParams), _toConsumableArray(commonParams), _toConsumableArray(transCommonParams)));
1722
+ }
1723
+ }, {
1724
+ key: "getBaseUrl",
1725
+ value: function getBaseUrl(params, prefix) {
1726
+ var cdnUrl = BytescaleApiClientConfigUtils.defaultCdnUrl;
1727
+ return "".concat(cdnUrl, "/").concat(params.accountId, "/").concat(prefix).concat(params.filePath);
1728
+ }
1729
+ }, {
1730
+ key: "getCommonTransformationQueryParams",
1731
+ value: function getCommonTransformationQueryParams(trans) {
1732
+ return this.makeQueryParams(["cachePermanently", "large", "artifact"], {
1733
+ cachePermanently: "cache_perm"
1734
+ })(trans);
1735
+ }
1736
+ }, {
1737
+ key: "getCommonQueryParams",
1738
+ value: function getCommonQueryParams(params) {
1739
+ return this.makeQueryParams(["auth", "cache", "cacheTtl", "version", "forceDownloadPrompt"], {
1740
+ cacheTtl: "cache_ttl",
1741
+ forceDownloadPrompt: "download"
1742
+ })(params);
1743
+ }
1744
+ }, {
1745
+ key: "makeQueryParams",
1746
+ value: function makeQueryParams(keys, keyOverrides) {
1747
+ return function (data) {
1748
+ var result = [];
1749
+ keys.forEach(function (key) {
1750
+ var _a;
1751
+ var value = data[key];
1752
+ if (value !== undefined) {
1753
+ result.push([(_a = keyOverrides[key]) !== null && _a !== void 0 ? _a : key, value.toString()]);
1754
+ }
1755
+ });
1756
+ return result;
1757
+ };
1758
+ }
1759
+ }, {
1760
+ key: "getTransformationParams",
1761
+ value: function getTransformationParams(trans) {
1762
+ var params = trans.transformationParams;
1763
+ if (params === undefined) {
1764
+ return [];
1765
+ }
1766
+ var serializeObj = function serializeObj(obj) {
1767
+ return Object.entries(obj).filter(isDefinedEntry).map(function (_ref) {
1768
+ var _ref2 = _slicedToArray(_ref, 2),
1769
+ key = _ref2[0],
1770
+ value = _ref2[1];
1771
+ return [key, value.toString()];
1772
+ });
1773
+ };
1774
+ return Array.isArray(params) ? params.flatMap(serializeObj) : serializeObj(params);
1775
+ }
1776
+ }, {
1777
+ key: "addQueryParams",
1778
+ value: function addQueryParams(baseUrl, params) {
1779
+ if (params.length === 0) {
1780
+ return baseUrl;
1781
+ }
1782
+ return "".concat(baseUrl, "?").concat(params.map(function (_ref3) {
1783
+ var _ref4 = _slicedToArray(_ref3, 2),
1784
+ key = _ref4[0],
1785
+ value = _ref4[1];
1786
+ return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(value));
1787
+ }).join("&"));
1788
+ }
1789
+ }]);
1790
+ return UrlBuilder;
1791
+ }();
1792
+ ;// CONCATENATED MODULE: ./src/public/shared/UrlBuilderTypes.ts
1793
+ /**
1794
+ * Workaround for tsc aliases, where we cannot export implementation-less libs in our dists.
1795
+ */
1796
+ var UrlBuilderTypesNoOp = false;
1797
+ ;// CONCATENATED MODULE: ./src/public/shared/index.ts
1798
+
1799
+
1800
+
1801
+
1802
+ ;// CONCATENATED MODULE: ./src/private/UploadManagerBase.ts
1803
+ 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); }
1804
+ function _async(f) {
1805
+ return function () {
1806
+ for (var args = [], i = 0; i < arguments.length; i++) {
1807
+ args[i] = arguments[i];
1808
+ }
1809
+ try {
1810
+ return Promise.resolve(f.apply(this, args));
1811
+ } catch (e) {
1812
+ return Promise.reject(e);
1813
+ }
1814
+ };
1815
+ }
1816
+ function _invokeIgnored(body) {
1817
+ var result = body();
1818
+ if (result && result.then) {
1819
+ return result.then(UploadManagerBase_empty);
1820
+ }
1821
+ }
1822
+ function UploadManagerBase_settle(pact, state, value) {
1823
+ if (!pact.s) {
1824
+ if (value instanceof UploadManagerBase_Pact) {
1825
+ if (value.s) {
1826
+ if (state & 1) {
1827
+ state = value.s;
1828
+ }
1829
+ value = value.v;
1830
+ } else {
1831
+ value.o = UploadManagerBase_settle.bind(null, pact, state);
1832
+ return;
1833
+ }
1834
+ }
1835
+ if (value && value.then) {
1836
+ value.then(UploadManagerBase_settle.bind(null, pact, state), UploadManagerBase_settle.bind(null, pact, 2));
1837
+ return;
1838
+ }
1839
+ pact.s = state;
1840
+ pact.v = value;
1841
+ var observer = pact.o;
1842
+ if (observer) {
1843
+ observer(pact);
1844
+ }
1845
+ }
1846
+ }
1847
+ var UploadManagerBase_Pact = /*#__PURE__*/function () {
1848
+ function _Pact() {}
1849
+ _Pact.prototype.then = function (onFulfilled, onRejected) {
1850
+ var result = new _Pact();
1851
+ var state = this.s;
1852
+ if (state) {
1853
+ var callback = state & 1 ? onFulfilled : onRejected;
1854
+ if (callback) {
1855
+ try {
1856
+ UploadManagerBase_settle(result, 1, callback(this.v));
1857
+ } catch (e) {
1858
+ UploadManagerBase_settle(result, 2, e);
1859
+ }
1860
+ return result;
1861
+ } else {
1862
+ return this;
1863
+ }
1864
+ }
1865
+ this.o = function (_this) {
1866
+ try {
1867
+ var value = _this.v;
1868
+ if (_this.s & 1) {
1869
+ UploadManagerBase_settle(result, 1, onFulfilled ? onFulfilled(value) : value);
1870
+ } else if (onRejected) {
1871
+ UploadManagerBase_settle(result, 1, onRejected(value));
1872
+ } else {
1873
+ UploadManagerBase_settle(result, 2, value);
1874
+ }
1875
+ } catch (e) {
1876
+ UploadManagerBase_settle(result, 2, e);
1877
+ }
1878
+ };
1879
+ return result;
1880
+ };
1881
+ return _Pact;
1882
+ }();
1883
+ function UploadManagerBase_isSettledPact(thenable) {
1884
+ return thenable instanceof UploadManagerBase_Pact && thenable.s & 1;
1885
+ }
1886
+ function UploadManagerBase_for(test, update, body) {
1887
+ var stage;
1888
+ for (;;) {
1889
+ var shouldContinue = test();
1890
+ if (UploadManagerBase_isSettledPact(shouldContinue)) {
1891
+ shouldContinue = shouldContinue.v;
1892
+ }
1893
+ if (!shouldContinue) {
1894
+ return result;
1895
+ }
1896
+ if (shouldContinue.then) {
1897
+ stage = 0;
1898
+ break;
1899
+ }
1900
+ var result = body();
1901
+ if (result && result.then) {
1902
+ if (UploadManagerBase_isSettledPact(result)) {
1903
+ result = result.s;
1904
+ } else {
1905
+ stage = 1;
1906
+ break;
1907
+ }
1908
+ }
1909
+ if (update) {
1910
+ var updateValue = update();
1911
+ if (updateValue && updateValue.then && !UploadManagerBase_isSettledPact(updateValue)) {
1912
+ stage = 2;
1913
+ break;
1914
+ }
1915
+ }
1916
+ }
1917
+ var pact = new UploadManagerBase_Pact();
1918
+ var reject = UploadManagerBase_settle.bind(null, pact, 2);
1919
+ (stage === 0 ? shouldContinue.then(_resumeAfterTest) : stage === 1 ? result.then(_resumeAfterBody) : updateValue.then(_resumeAfterUpdate)).then(void 0, reject);
1920
+ return pact;
1921
+ function _resumeAfterBody(value) {
1922
+ result = value;
1923
+ do {
1924
+ if (update) {
1925
+ updateValue = update();
1926
+ if (updateValue && updateValue.then && !UploadManagerBase_isSettledPact(updateValue)) {
1927
+ updateValue.then(_resumeAfterUpdate).then(void 0, reject);
1928
+ return;
1929
+ }
1930
+ }
1931
+ shouldContinue = test();
1932
+ if (!shouldContinue || UploadManagerBase_isSettledPact(shouldContinue) && !shouldContinue.v) {
1933
+ UploadManagerBase_settle(pact, 1, result);
1934
+ return;
1935
+ }
1936
+ if (shouldContinue.then) {
1937
+ shouldContinue.then(_resumeAfterTest).then(void 0, reject);
1938
+ return;
1939
+ }
1940
+ result = body();
1941
+ if (UploadManagerBase_isSettledPact(result)) {
1942
+ result = result.v;
1943
+ }
1944
+ } while (!result || !result.then);
1945
+ result.then(_resumeAfterBody).then(void 0, reject);
1946
+ }
1947
+ function _resumeAfterTest(shouldContinue) {
1948
+ if (shouldContinue) {
1949
+ result = body();
1950
+ if (result && result.then) {
1951
+ result.then(_resumeAfterBody).then(void 0, reject);
1952
+ } else {
1953
+ _resumeAfterBody(result);
1954
+ }
1955
+ } else {
1956
+ UploadManagerBase_settle(pact, 1, result);
1957
+ }
1958
+ }
1959
+ function _resumeAfterUpdate() {
1960
+ if (shouldContinue = test()) {
1961
+ if (shouldContinue.then) {
1962
+ shouldContinue.then(_resumeAfterTest).then(void 0, reject);
1963
+ } else {
1964
+ _resumeAfterTest(shouldContinue);
1965
+ }
1966
+ } else {
1967
+ UploadManagerBase_settle(pact, 1, result);
1968
+ }
1969
+ }
1970
+ }
1971
+ function _continueIgnored(value) {
1972
+ if (value && value.then) {
1973
+ return value.then(UploadManagerBase_empty);
1974
+ }
1975
+ }
1976
+ function UploadManagerBase_toConsumableArray(arr) { return UploadManagerBase_arrayWithoutHoles(arr) || UploadManagerBase_iterableToArray(arr) || UploadManagerBase_unsupportedIterableToArray(arr) || UploadManagerBase_nonIterableSpread(); }
1977
+ 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."); }
1978
+ 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); }
1979
+ function UploadManagerBase_iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
1980
+ function UploadManagerBase_arrayWithoutHoles(arr) { if (Array.isArray(arr)) return UploadManagerBase_arrayLikeToArray(arr); }
1981
+ 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; }
1982
+ function UploadManagerBase_empty() {}
1983
+ function UploadManagerBase_awaitIgnored(value, direct) {
1984
+ if (!direct) {
1985
+ return value && value.then ? value.then(UploadManagerBase_empty) : Promise.resolve();
1986
+ }
1987
+ }
1988
+ function UploadManagerBase_await(value, then, direct) {
1989
+ if (direct) {
1990
+ return then ? then(value) : value;
1991
+ }
1992
+ if (!value || !value.then) {
1993
+ value = Promise.resolve(value);
1994
+ }
1995
+ return then ? value.then(then) : value;
1996
+ }
1997
+ function UploadManagerBase_rethrow(thrown, value) {
1998
+ if (thrown) throw value;
1999
+ return value;
2000
+ }
2001
+ function UploadManagerBase_finallyRethrows(body, finalizer) {
2002
+ try {
2003
+ var result = body();
2004
+ } catch (e) {
2005
+ return finalizer(true, e);
2006
+ }
2007
+ if (result && result.then) {
2008
+ return result.then(finalizer.bind(null, false), finalizer.bind(null, true));
2009
+ }
2010
+ return finalizer(false, result);
2011
+ }
2012
+ function UploadManagerBase_continue(value, then) {
2013
+ return value && value.then ? value.then(then) : then(value);
2014
+ }
2015
+ function UploadManagerBase_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2016
+ function UploadManagerBase_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, UploadManagerBase_toPropertyKey(descriptor.key), descriptor); } }
2017
+ function UploadManagerBase_createClass(Constructor, protoProps, staticProps) { if (protoProps) UploadManagerBase_defineProperties(Constructor.prototype, protoProps); if (staticProps) UploadManagerBase_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
2018
+ function UploadManagerBase_toPropertyKey(arg) { var key = UploadManagerBase_toPrimitive(arg, "string"); return UploadManagerBase_typeof(key) === "symbol" ? key : String(key); }
2019
+ 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); }
2020
+
2021
+ /**
2022
+ * Methods common to UploadManagerNode and UploadManagerBrowser.
2023
+ */
2024
+ var UploadManagerBase = /*#__PURE__*/function () {
2025
+ function UploadManagerBase(config) {
2026
+ UploadManagerBase_classCallCheck(this, UploadManagerBase);
2027
+ this.config = config;
2028
+ this.stringMimeType = "text/plain";
2029
+ this.defaultMaxConcurrentUploadParts = 4;
2030
+ this.intervalMs = 500;
2031
+ this.uploadApi = new UploadApi(config);
2032
+ this.accountId = BytescaleApiClientConfigUtils.getAccountId(config);
2033
+ }
2034
+ UploadManagerBase_createClass(UploadManagerBase, [{
2035
+ key: "upload",
2036
+ value: function upload(request) {
2037
+ try {
2038
+ var _this2 = this;
2039
+ _this2.assertNotCancelled(request);
2040
+ var source = _this2.processUploadSource(request.data);
2041
+ var preUploadInfo = _this2.getPreUploadInfo(request, source);
2042
+ var bytesTotal = preUploadInfo.size;
2043
+ var makeOnProgressForPart = _this2.makeOnProgressForPartFactory(request, bytesTotal);
2044
+ var init = _this2.preUpload(source);
2045
+ // Raise initial progress event SYNCHRONOUSLY.
2046
+ if (request.onProgress !== undefined) {
2047
+ request.onProgress(_this2.makeProgressEvent(0, bytesTotal));
2048
+ }
2049
+ return UploadManagerBase_await(_this2.beginUpload(request, preUploadInfo), function (uploadInfo) {
2050
+ var partCount = uploadInfo.uploadParts.count;
2051
+ var parts = UploadManagerBase_toConsumableArray(Array(partCount).keys());
2052
+ var _this2$makeCancellati = _this2.makeCancellationMethods(),
2053
+ cancel = _this2$makeCancellati.cancel,
2054
+ addCancellationHandler = _this2$makeCancellati.addCancellationHandler;
2055
+ var intervalHandle = setInterval(_this2.onIntervalTick(request, cancel), _this2.intervalMs);
2056
+ return UploadManagerBase_continue(UploadManagerBase_finallyRethrows(function () {
2057
+ return UploadManagerBase_await(_this2.mapAsync(parts, preUploadInfo.maxConcurrentUploadParts, _async(function (part) {
2058
+ return _this2.uploadPart(request, source, part, uploadInfo, makeOnProgressForPart(), addCancellationHandler);
2059
+ })), function () {
2060
+ return UploadManagerBase_awaitIgnored(_this2.postUpload(init));
2061
+ });
2062
+ }, function (_wasThrown, _result) {
2063
+ clearInterval(intervalHandle);
2064
+ return UploadManagerBase_rethrow(_wasThrown, _result);
2065
+ }), function () {
2066
+ return uploadInfo.file;
2067
+ });
2068
+ });
2069
+ } catch (e) {
2070
+ return Promise.reject(e);
2071
+ }
2072
+ }
2073
+ }, {
2074
+ key: "getBlobInfo",
2075
+ value: function getBlobInfo(_ref) {
2076
+ var _ref$value = _ref.value,
2077
+ name = _ref$value.name,
2078
+ size = _ref$value.size,
2079
+ type = _ref$value.type;
2080
+ return {
2081
+ mime: type,
2082
+ size: size,
2083
+ originalFileName: name,
2084
+ maxConcurrentUploadParts: undefined
2085
+ };
2086
+ }
2087
+ }, {
2088
+ key: "onIntervalTick",
2089
+ value: function onIntervalTick(request, cancel) {
2090
+ var _this3 = this;
2091
+ return function () {
2092
+ if (_this3.isCancelled(request)) {
2093
+ cancel();
2094
+ }
2095
+ };
2096
+ }
2097
+ }, {
2098
+ key: "makeCancellationMethods",
2099
+ value: function makeCancellationMethods() {
2100
+ var cancellationHandlers = [];
2101
+ var addCancellationHandler = function addCancellationHandler(ca) {
2102
+ cancellationHandlers.push(ca);
2103
+ };
2104
+ var cancel = function cancel() {
2105
+ return cancellationHandlers.forEach(function (x) {
2106
+ return x();
2107
+ });
2108
+ };
2109
+ return {
2110
+ cancel: cancel,
2111
+ addCancellationHandler: addCancellationHandler
2112
+ };
2113
+ }
2114
+ /**
2115
+ * Returns a callback, which when called, returns a callback that can be used by ONE specific part to report its progress.
2116
+ */
2117
+ }, {
2118
+ key: "makeOnProgressForPartFactory",
2119
+ value: function makeOnProgressForPartFactory(request, bytesTotal) {
2120
+ var _this4 = this;
2121
+ var onProgress = request.onProgress;
2122
+ if (onProgress === undefined) {
2123
+ return function () {
2124
+ return function () {};
2125
+ };
2126
+ }
2127
+ var bytesSent = 0;
2128
+ return function () {
2129
+ var bytesSentForPart = 0;
2130
+ return function (bytesSentTotalForPart) {
2131
+ var delta = bytesSentTotalForPart - bytesSentForPart;
2132
+ bytesSentForPart += delta;
2133
+ bytesSent += delta;
2134
+ onProgress(_this4.makeProgressEvent(bytesSent, bytesTotal));
2135
+ };
2136
+ };
2137
+ }
2138
+ }, {
2139
+ key: "makeProgressEvent",
2140
+ value: function makeProgressEvent(bytesSent, bytesTotal) {
2141
+ return {
2142
+ bytesTotal: bytesTotal,
2143
+ bytesSent: bytesSent,
2144
+ progress: Math.round(bytesSent / bytesTotal * 100)
2145
+ };
2146
+ }
2147
+ }, {
2148
+ key: "assertNotCancelled",
2149
+ value: function assertNotCancelled(request) {
2150
+ if (this.isCancelled(request)) {
2151
+ throw new CancelledError();
2152
+ }
2153
+ }
2154
+ }, {
2155
+ key: "isCancelled",
2156
+ value: function isCancelled(request) {
2157
+ var _a;
2158
+ return ((_a = request.cancellationToken) === null || _a === void 0 ? void 0 : _a.isCancelled) === true;
2159
+ }
2160
+ }, {
2161
+ key: "beginUpload",
2162
+ value: function beginUpload(request, _ref2) {
2163
+ var size = _ref2.size,
2164
+ mime = _ref2.mime,
2165
+ originalFileName = _ref2.originalFileName;
2166
+ try {
2167
+ var _this6 = this;
2168
+ return UploadManagerBase_await(_this6.uploadApi.beginMultipartUpload({
2169
+ accountId: _this6.accountId,
2170
+ beginMultipartUploadRequest: {
2171
+ metadata: request.metadata,
2172
+ mime: mime,
2173
+ originalFileName: originalFileName,
2174
+ path: request.path,
2175
+ protocol: "1.1",
2176
+ size: size,
2177
+ tags: request.tags
2178
+ }
2179
+ }));
2180
+ } catch (e) {
2181
+ return Promise.reject(e);
2182
+ }
2183
+ }
2184
+ }, {
2185
+ key: "uploadPart",
2186
+ value: function uploadPart(request, source, partIndex, uploadInfo, onProgress, addCancellationHandler) {
2187
+ try {
2188
+ var _this8 = this;
2189
+ _this8.assertNotCancelled(request);
2190
+ return UploadManagerBase_await(_this8.getUploadPart(partIndex, uploadInfo), function (part) {
2191
+ _this8.assertNotCancelled(request);
2192
+ return UploadManagerBase_await(_this8.putUploadPart(part, source, onProgress, addCancellationHandler), function (etag) {
2193
+ _this8.assertNotCancelled(request);
2194
+ return UploadManagerBase_awaitIgnored(_this8.uploadApi.completeUploadPart({
2195
+ accountId: _this8.accountId,
2196
+ uploadId: uploadInfo.uploadId,
2197
+ uploadPartIndex: partIndex,
2198
+ completeUploadPartRequest: {
2199
+ etag: etag
2200
+ }
2201
+ }));
2202
+ });
2203
+ });
2204
+ } catch (e) {
2205
+ return Promise.reject(e);
2206
+ }
2207
+ }
2208
+ /**
2209
+ * Returns etag for the part.
2210
+ */
2211
+ }, {
2212
+ key: "putUploadPart",
2213
+ value: function putUploadPart(part, source, onProgress, addCancellationHandler) {
2214
+ try {
2215
+ var _this10 = this;
2216
+ var contentLength = part.range.inclusiveEnd + 1 - part.range.inclusiveStart;
2217
+ return UploadManagerBase_await(_this10.doPutUploadPart(part, contentLength, source, onProgress, addCancellationHandler), function (_ref3) {
2218
+ var status = _ref3.status,
2219
+ etag = _ref3.etag;
2220
+ if (Math.floor(status / 100) !== 2) {
2221
+ throw new Error("Failed to upload part (".concat(status, ")."));
2222
+ }
2223
+ if (etag === undefined) {
2224
+ throw new Error("No 'etag' response header found in upload part response.");
2225
+ }
2226
+ // Always send 100% for part, as some UploadManager implementations either don't report progress, or may not report the last chunk uploaded.
2227
+ onProgress(contentLength);
2228
+ return etag;
2229
+ });
2230
+ } catch (e) {
2231
+ return Promise.reject(e);
2232
+ }
2233
+ }
2234
+ }, {
2235
+ key: "getUploadPart",
2236
+ value: function getUploadPart(partIndex, uploadInfo) {
2237
+ try {
2238
+ var _this12 = this;
2239
+ if (partIndex === 0) {
2240
+ return uploadInfo.uploadParts.first;
2241
+ }
2242
+ return UploadManagerBase_await(_this12.uploadApi.getUploadPart({
2243
+ uploadId: uploadInfo.uploadId,
2244
+ accountId: _this12.accountId,
2245
+ uploadPartIndex: partIndex
2246
+ }));
2247
+ } catch (e) {
2248
+ return Promise.reject(e);
2249
+ }
2250
+ }
2251
+ }, {
2252
+ key: "getPreUploadInfo",
2253
+ value: function getPreUploadInfo(request, source) {
2254
+ var _a, _b, _c;
2255
+ var partial = this.getPreUploadInfoPartial(request, source);
2256
+ return {
2257
+ maxConcurrentUploadParts: (_a = partial.maxConcurrentUploadParts) !== null && _a !== void 0 ? _a : this.defaultMaxConcurrentUploadParts,
2258
+ originalFileName: (_b = request.originalFileName) !== null && _b !== void 0 ? _b : partial.originalFileName,
2259
+ mime: (_c = request.mime) !== null && _c !== void 0 ? _c : partial.mime,
2260
+ size: partial.size
2261
+ };
2262
+ }
2263
+ }, {
2264
+ key: "mapAsync",
2265
+ value: function mapAsync(items, concurrency, callback) {
2266
+ try {
2267
+ var workQueue = UploadManagerBase_toConsumableArray(items);
2268
+ return UploadManagerBase_awaitIgnored(Promise.all(UploadManagerBase_toConsumableArray(Array(concurrency).keys()).map(_async(function () {
2269
+ return _continueIgnored(UploadManagerBase_for(function () {
2270
+ return workQueue.length > 0;
2271
+ }, void 0, function () {
2272
+ var work = workQueue.shift(); // IMPORTANT: use 'shift' instead of 'pop' to ensure 'items' are processed in order when 'concurrency = 1'.
2273
+ return _invokeIgnored(function () {
2274
+ if (work !== undefined) {
2275
+ return UploadManagerBase_awaitIgnored(callback(work));
2276
+ }
2277
+ });
2278
+ }));
2279
+ }))));
2280
+ } catch (e) {
2281
+ return Promise.reject(e);
2282
+ }
2283
+ }
2284
+ }]);
2285
+ return UploadManagerBase;
2286
+ }();
2287
+ ;// CONCATENATED MODULE: ./src/private/UploadManagerBrowserWorkerBase.ts
2288
+ function UploadManagerBrowserWorkerBase_typeof(obj) { "@babel/helpers - typeof"; return UploadManagerBrowserWorkerBase_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; }, UploadManagerBrowserWorkerBase_typeof(obj); }
2289
+ function UploadManagerBrowserWorkerBase_await(value, then, direct) {
2290
+ if (direct) {
2291
+ return then ? then(value) : value;
2292
+ }
2293
+ if (!value || !value.then) {
2294
+ value = Promise.resolve(value);
2295
+ }
2296
+ return then ? value.then(then) : value;
2297
+ }
2298
+ function UploadManagerBrowserWorkerBase_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2299
+ function UploadManagerBrowserWorkerBase_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, UploadManagerBrowserWorkerBase_toPropertyKey(descriptor.key), descriptor); } }
2300
+ function UploadManagerBrowserWorkerBase_createClass(Constructor, protoProps, staticProps) { if (protoProps) UploadManagerBrowserWorkerBase_defineProperties(Constructor.prototype, protoProps); if (staticProps) UploadManagerBrowserWorkerBase_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
2301
+ function UploadManagerBrowserWorkerBase_toPropertyKey(arg) { var key = UploadManagerBrowserWorkerBase_toPrimitive(arg, "string"); return UploadManagerBrowserWorkerBase_typeof(key) === "symbol" ? key : String(key); }
2302
+ function UploadManagerBrowserWorkerBase_toPrimitive(input, hint) { if (UploadManagerBrowserWorkerBase_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (UploadManagerBrowserWorkerBase_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
2303
+ function UploadManagerBrowserWorkerBase_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) UploadManagerBrowserWorkerBase_setPrototypeOf(subClass, superClass); }
2304
+ function UploadManagerBrowserWorkerBase_setPrototypeOf(o, p) { UploadManagerBrowserWorkerBase_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return UploadManagerBrowserWorkerBase_setPrototypeOf(o, p); }
2305
+ function UploadManagerBrowserWorkerBase_createSuper(Derived) { var hasNativeReflectConstruct = UploadManagerBrowserWorkerBase_isNativeReflectConstruct(); return function _createSuperInternal() { var Super = UploadManagerBrowserWorkerBase_getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = UploadManagerBrowserWorkerBase_getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return UploadManagerBrowserWorkerBase_possibleConstructorReturn(this, result); }; }
2306
+ function UploadManagerBrowserWorkerBase_possibleConstructorReturn(self, call) { if (call && (UploadManagerBrowserWorkerBase_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 UploadManagerBrowserWorkerBase_assertThisInitialized(self); }
2307
+ function UploadManagerBrowserWorkerBase_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
2308
+ function UploadManagerBrowserWorkerBase_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; } }
2309
+ function UploadManagerBrowserWorkerBase_getPrototypeOf(o) { UploadManagerBrowserWorkerBase_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return UploadManagerBrowserWorkerBase_getPrototypeOf(o); }
2310
+
2311
+
2312
+ /**
2313
+ * The "browser" and "worker" runtimes support the same input types, but the former uses XHR and the latter uses Fetch.
2314
+ */
2315
+ var UploadManagerBrowserWorkerBase = /*#__PURE__*/function (_UploadManagerBase) {
2316
+ UploadManagerBrowserWorkerBase_inherits(UploadManagerBrowserWorkerBase, _UploadManagerBase);
2317
+ var _super = UploadManagerBrowserWorkerBase_createSuper(UploadManagerBrowserWorkerBase);
2318
+ function UploadManagerBrowserWorkerBase() {
2319
+ UploadManagerBrowserWorkerBase_classCallCheck(this, UploadManagerBrowserWorkerBase);
2320
+ return _super.apply(this, arguments);
2321
+ }
2322
+ UploadManagerBrowserWorkerBase_createClass(UploadManagerBrowserWorkerBase, [{
2323
+ key: "processUploadSource",
2324
+ value: function processUploadSource(data) {
2325
+ if (typeof data === "string") {
2326
+ // 'Blob' must be from 'global' (i.e. not imported) as we're in a browser context here, so is globally available.
2327
+ return {
2328
+ type: "Blob",
2329
+ value: new Blob([data], {
2330
+ type: this.stringMimeType
2331
+ })
2332
+ };
2333
+ }
2334
+ if (data.byteLength !== undefined) {
2335
+ return {
2336
+ type: "ArrayBuffer",
2337
+ value: data
2338
+ };
2339
+ }
2340
+ if (data.size !== undefined) {
2341
+ return {
2342
+ type: "Blob",
2343
+ value: data
2344
+ };
2345
+ }
2346
+ throw new Error("Unsupported type for 'data' parameter. Please provide a String, Blob, ArrayBuffer, or File object (from a file input element).");
2347
+ }
2348
+ }, {
2349
+ key: "getPreUploadInfoPartial",
2350
+ value: function getPreUploadInfoPartial(_request, data) {
2351
+ switch (data.type) {
2352
+ case "Blob":
2353
+ return this.getBlobInfo(data);
2354
+ case "ArrayBuffer":
2355
+ return {
2356
+ mime: undefined,
2357
+ size: data.value.byteLength,
2358
+ originalFileName: undefined,
2359
+ maxConcurrentUploadParts: undefined
2360
+ };
2361
+ default:
2362
+ assertUnreachable(data);
2363
+ }
2364
+ }
2365
+ }, {
2366
+ key: "preUpload",
2367
+ value: function preUpload(_source) {
2368
+ return undefined;
2369
+ }
2370
+ }, {
2371
+ key: "postUpload",
2372
+ value: function postUpload(_init) {
2373
+ return UploadManagerBrowserWorkerBase_await();
2374
+ } // NO-OP.
2375
+ }, {
2376
+ key: "getRequestBody",
2377
+ value: function getRequestBody(part, blob) {
2378
+ return part.range.inclusiveEnd === -1 ? new Blob() : blob.value.slice(part.range.inclusiveStart, part.range.inclusiveEnd + 1);
2379
+ }
2380
+ }]);
2381
+ return UploadManagerBrowserWorkerBase;
2382
+ }(UploadManagerBase);
2383
+ ;// CONCATENATED MODULE: ./src/public/browser/UploadManagerBrowser.ts
2384
+ 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); }
2385
+ function UploadManagerBrowser_await(value, then, direct) {
2386
+ if (direct) {
2387
+ return then ? then(value) : value;
2388
+ }
2389
+ if (!value || !value.then) {
2390
+ value = Promise.resolve(value);
2391
+ }
2392
+ return then ? value.then(then) : value;
2393
+ }
2394
+ function UploadManagerBrowser_rethrow(thrown, value) {
2395
+ if (thrown) throw value;
2396
+ return value;
2397
+ }
2398
+ function UploadManagerBrowser_finallyRethrows(body, finalizer) {
2399
+ try {
2400
+ var result = body();
2401
+ } catch (e) {
2402
+ return finalizer(true, e);
2403
+ }
2404
+ if (result && result.then) {
2405
+ return result.then(finalizer.bind(null, false), finalizer.bind(null, true));
2406
+ }
2407
+ return finalizer(false, result);
2408
+ }
2409
+ function UploadManagerBrowser_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2410
+ function UploadManagerBrowser_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, UploadManagerBrowser_toPropertyKey(descriptor.key), descriptor); } }
2411
+ function UploadManagerBrowser_createClass(Constructor, protoProps, staticProps) { if (protoProps) UploadManagerBrowser_defineProperties(Constructor.prototype, protoProps); if (staticProps) UploadManagerBrowser_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
2412
+ function UploadManagerBrowser_toPropertyKey(arg) { var key = UploadManagerBrowser_toPrimitive(arg, "string"); return UploadManagerBrowser_typeof(key) === "symbol" ? key : String(key); }
2413
+ function UploadManagerBrowser_toPrimitive(input, hint) { if (UploadManagerBrowser_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (UploadManagerBrowser_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
2414
+ function UploadManagerBrowser_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) UploadManagerBrowser_setPrototypeOf(subClass, superClass); }
2415
+ function UploadManagerBrowser_setPrototypeOf(o, p) { UploadManagerBrowser_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return UploadManagerBrowser_setPrototypeOf(o, p); }
2416
+ function UploadManagerBrowser_createSuper(Derived) { var hasNativeReflectConstruct = UploadManagerBrowser_isNativeReflectConstruct(); return function _createSuperInternal() { var Super = UploadManagerBrowser_getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = UploadManagerBrowser_getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return UploadManagerBrowser_possibleConstructorReturn(this, result); }; }
2417
+ function UploadManagerBrowser_possibleConstructorReturn(self, call) { if (call && (UploadManagerBrowser_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 UploadManagerBrowser_assertThisInitialized(self); }
2418
+ function UploadManagerBrowser_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
2419
+ function UploadManagerBrowser_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; } }
2420
+ function UploadManagerBrowser_getPrototypeOf(o) { UploadManagerBrowser_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return UploadManagerBrowser_getPrototypeOf(o); }
2421
+
2422
+
2423
+ var UploadManager = /*#__PURE__*/function (_UploadManagerBrowser) {
2424
+ UploadManagerBrowser_inherits(UploadManager, _UploadManagerBrowser);
2425
+ var _super = UploadManagerBrowser_createSuper(UploadManager);
2426
+ function UploadManager() {
2427
+ UploadManagerBrowser_classCallCheck(this, UploadManager);
2428
+ return _super.apply(this, arguments);
2429
+ }
2430
+ UploadManagerBrowser_createClass(UploadManager, [{
2431
+ key: "doPutUploadPart",
2432
+ value: function doPutUploadPart(part, _contentLength, source, onProgress, addCancellationHandler) {
2433
+ try {
2434
+ var _this2 = this;
2435
+ var xhr = new XMLHttpRequest();
2436
+ var pending = true;
2437
+ addCancellationHandler(function () {
2438
+ if (pending) {
2439
+ xhr.abort();
2440
+ }
2441
+ });
2442
+ return UploadManagerBrowser_finallyRethrows(function () {
2443
+ return UploadManagerBrowser_await(new Promise(function (resolve, reject) {
2444
+ xhr.upload.addEventListener("progress", function (evt) {
2445
+ if (evt.lengthComputable) {
2446
+ onProgress(evt.loaded);
2447
+ }
2448
+ }, false);
2449
+ xhr.addEventListener("load", function () {
2450
+ var _a;
2451
+ var etag = (_a = xhr.getResponseHeader("etag")) !== null && _a !== void 0 ? _a : undefined;
2452
+ resolve({
2453
+ etag: etag,
2454
+ status: xhr.status
2455
+ });
2456
+ });
2457
+ xhr.onabort = function () {
2458
+ return reject(new CancelledError());
2459
+ };
2460
+ xhr.onerror = function () {
2461
+ return reject(new Error("File upload error."));
2462
+ };
2463
+ xhr.ontimeout = function () {
2464
+ return reject(new Error("File upload timeout."));
2465
+ };
2466
+ xhr.open("PUT", part.uploadUrl);
2467
+ xhr.send(_this2.getRequestBody(part, source));
2468
+ }));
2469
+ }, function (_wasThrown, _result) {
2470
+ pending = false;
2471
+ return UploadManagerBrowser_rethrow(_wasThrown, _result);
2472
+ });
2473
+ } catch (e) {
2474
+ return Promise.reject(e);
2475
+ }
2476
+ }
2477
+ }]);
2478
+ return UploadManager;
2479
+ }(UploadManagerBrowserWorkerBase);
2480
+ ;// CONCATENATED MODULE: ./src/private/ConsoleUtils.ts
2481
+ 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); }
2482
+ function ConsoleUtils_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2483
+ 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); } }
2484
+ 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; }
2485
+ function ConsoleUtils_toPropertyKey(arg) { var key = ConsoleUtils_toPrimitive(arg, "string"); return ConsoleUtils_typeof(key) === "symbol" ? key : String(key); }
2486
+ 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); }
2487
+ var ConsoleUtils = /*#__PURE__*/function () {
2488
+ function ConsoleUtils() {
2489
+ ConsoleUtils_classCallCheck(this, ConsoleUtils);
2490
+ }
2491
+ ConsoleUtils_createClass(ConsoleUtils, null, [{
2492
+ key: "error",
2493
+ value: function error(message) {
2494
+ console.error(ConsoleUtils.prefix(message));
2495
+ }
2496
+ }, {
2497
+ key: "warn",
2498
+ value: function warn(message) {
2499
+ console.warn(ConsoleUtils.prefix(message));
2500
+ }
2501
+ }, {
2502
+ key: "prefix",
2503
+ value: function prefix(message) {
2504
+ return "[bytescale-sdk] ".concat(message);
2505
+ }
2506
+ }]);
2507
+ return ConsoleUtils;
2508
+ }();
2509
+ ;// CONCATENATED MODULE: ./src/public/browser/AuthManagerBrowser.ts
2510
+ 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); }
2511
+ 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; }
2512
+ function AuthManagerBrowser_empty() {}
2513
+ function AuthManagerBrowser_awaitIgnored(value, direct) {
2514
+ if (!direct) {
2515
+ return value && value.then ? value.then(AuthManagerBrowser_empty) : Promise.resolve();
2516
+ }
2517
+ }
2518
+ function AuthManagerBrowser_await(value, then, direct) {
2519
+ if (direct) {
2520
+ return then ? then(value) : value;
2521
+ }
2522
+ if (!value || !value.then) {
2523
+ value = Promise.resolve(value);
2524
+ }
2525
+ return then ? value.then(then) : value;
2526
+ }
2527
+ function AuthManagerBrowser_async(f) {
2528
+ return function () {
2529
+ for (var args = [], i = 0; i < arguments.length; i++) {
2530
+ args[i] = arguments[i];
2531
+ }
2532
+ try {
2533
+ return Promise.resolve(f.apply(this, args));
2534
+ } catch (e) {
2535
+ return Promise.reject(e);
2536
+ }
2537
+ };
2538
+ }
2539
+ function AuthManagerBrowser_catch(body, recover) {
2540
+ try {
2541
+ var result = body();
2542
+ } catch (e) {
2543
+ return recover(e);
2544
+ }
2545
+ if (result && result.then) {
2546
+ return result.then(void 0, recover);
2547
+ }
2548
+ return result;
2549
+ }
2550
+ function AuthManagerBrowser_rethrow(thrown, value) {
2551
+ if (thrown) throw value;
2552
+ return value;
2553
+ }
2554
+ function AuthManagerBrowser_finallyRethrows(body, finalizer) {
2555
+ try {
2556
+ var result = body();
2557
+ } catch (e) {
2558
+ return finalizer(true, e);
2559
+ }
2560
+ if (result && result.then) {
2561
+ return result.then(finalizer.bind(null, false), finalizer.bind(null, true));
2562
+ }
2563
+ return finalizer(false, result);
2564
+ }
2565
+ function AuthManagerBrowser_continueIgnored(value) {
2566
+ if (value && value.then) {
2567
+ return value.then(AuthManagerBrowser_empty);
2568
+ }
2569
+ }
2570
+ function AuthManagerBrowser_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2571
+ 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); } }
2572
+ 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; }
2573
+ function AuthManagerBrowser_toPropertyKey(arg) { var key = AuthManagerBrowser_toPrimitive(arg, "string"); return AuthManagerBrowser_typeof(key) === "symbol" ? key : String(key); }
2574
+ 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); }
2575
+
2576
+
2577
+
2578
+ var AuthManagerImpl = /*#__PURE__*/function () {
2579
+ function AuthManagerImpl() {
2580
+ AuthManagerBrowser_classCallCheck(this, AuthManagerImpl);
2581
+ this.contentType = "content-type";
2582
+ this.contentTypeJson = "application/json";
2583
+ this.contentTypeText = "text/plain";
2584
+ this.minJwtTtlSeconds = 10;
2585
+ this.maxJwtTtlSeconds = 2147483; // Max value for window.setTimeout is 2147483647ms -- if we go over this, the timeout fires immediately.
2586
+ this.retryAuthAfterErrorSeconds = 5;
2587
+ this.refreshBeforeExpirySeconds = 20;
2588
+ this.authSessionMutex = AuthSessionState.getMutex();
2589
+ }
2590
+ AuthManagerBrowser_createClass(AuthManagerImpl, [{
2591
+ key: "isAuthSessionActive",
2592
+ value: function isAuthSessionActive() {
2593
+ return AuthSessionState.getSession() !== undefined;
2594
+ }
2595
+ }, {
2596
+ key: "beginAuthSession",
2597
+ value: function beginAuthSession(params) {
2598
+ try {
2599
+ var _this2 = this;
2600
+ var newSession = {
2601
+ accessToken: undefined,
2602
+ accessTokenRefreshHandle: undefined,
2603
+ params: params,
2604
+ isActive: true
2605
+ };
2606
+ return AuthManagerBrowser_await(_this2.authSessionMutex.safe(AuthManagerBrowser_async(function () {
2607
+ // We check both 'session' and 'sessionDisposing' here, as we don't want to call 'beginAuthSession' until the session is fully disposed.
2608
+ if (_this2.isAuthSessionActive()) {
2609
+ 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.");
2610
+ }
2611
+ AuthSessionState.setSession(newSession);
2612
+ return AuthManagerBrowser_await();
2613
+ })), function () {
2614
+ // IMPORTANT: must be called outside the above, else re-entrant deadlock will occur.
2615
+ return AuthManagerBrowser_awaitIgnored(_this2.refreshAccessToken(newSession));
2616
+ });
2617
+ } catch (e) {
2618
+ return Promise.reject(e);
2619
+ }
2620
+ }
2621
+ }, {
2622
+ key: "endAuthSession",
2623
+ value: function endAuthSession() {
2624
+ try {
2625
+ var _this4 = this;
2626
+ return AuthManagerBrowser_awaitIgnored(_this4.authSessionMutex.safe(AuthManagerBrowser_async(function () {
2627
+ var session = AuthSessionState.getSession();
2628
+ if (session === undefined) {
2629
+ return;
2630
+ }
2631
+ AuthSessionState.setSession(undefined);
2632
+ session.isActive = false;
2633
+ if (session.accessTokenRefreshHandle !== undefined) {
2634
+ clearTimeout(session.accessTokenRefreshHandle);
2635
+ }
2636
+ return AuthManagerBrowser_awaitIgnored(_this4.deleteAccessToken(session.params));
2637
+ })));
2638
+ } catch (e) {
2639
+ return Promise.reject(e);
2640
+ }
2641
+ }
2642
+ }, {
2643
+ key: "refreshAccessToken",
2644
+ value: function refreshAccessToken(session) {
2645
+ try {
2646
+ var _this6 = this;
2647
+ return AuthManagerBrowser_awaitIgnored(_this6.authSessionMutex.safe(AuthManagerBrowser_async(function () {
2648
+ if (!session.isActive) {
2649
+ return;
2650
+ }
2651
+ var timeout = _this6.retryAuthAfterErrorSeconds;
2652
+ return AuthManagerBrowser_continueIgnored(AuthManagerBrowser_finallyRethrows(function () {
2653
+ return AuthManagerBrowser_catch(function () {
2654
+ var _getAccessToken = _this6.getAccessToken,
2655
+ _session$params = session.params;
2656
+ return AuthManagerBrowser_await(session.params.authHeaders(), function (_session$params$authH) {
2657
+ return AuthManagerBrowser_await(_getAccessToken.call(_this6, _session$params, _session$params$authH), function (jwt) {
2658
+ return AuthManagerBrowser_await(_this6.setAccessToken(session.params, jwt), function (setTokenResult) {
2659
+ var desiredTtl = setTokenResult.ttlSeconds - _this6.refreshBeforeExpirySeconds;
2660
+ timeout = Math.max(desiredTtl, _this6.minJwtTtlSeconds);
2661
+ if (desiredTtl !== timeout) {
2662
+ ConsoleUtils.warn("JWT expiration is too short: waiting for ".concat(timeout, " seconds before refreshing."));
2663
+ }
2664
+ // There's need to print a warning for this: it's OK to silently request the JWT before it expires. Also, this is 24 days in this case!
2665
+ timeout = Math.min(timeout, _this6.maxJwtTtlSeconds);
2666
+ session.accessToken = setTokenResult.accessToken;
2667
+ });
2668
+ });
2669
+ });
2670
+ }, function (e) {
2671
+ // Use 'error' instead of 'debug' so that the user sees error messages.
2672
+ ConsoleUtils.error("Error when refreshing access token: ".concat(e));
2673
+ });
2674
+ }, function (_wasThrown, _result) {
2675
+ session.accessTokenRefreshHandle = window.setTimeout(function () {
2676
+ _this6.refreshAccessToken(session).then(function () {}, function (e) {
2677
+ return ConsoleUtils.error("Unexpected error when refreshing access token: ".concat(e));
2678
+ });
2679
+ }, timeout * 1000);
2680
+ return AuthManagerBrowser_rethrow(_wasThrown, _result);
2681
+ }));
2682
+ })));
2683
+ } catch (e) {
2684
+ return Promise.reject(e);
2685
+ }
2686
+ }
2687
+ }, {
2688
+ key: "getAccessTokenUrl",
2689
+ value: function getAccessTokenUrl(params) {
2690
+ var _a;
2691
+ var cdnUrl = BytescaleApiClientConfigUtils.getCdnUrl((_a = params.options) !== null && _a !== void 0 ? _a : {});
2692
+ return "".concat(cdnUrl, "/api/v1/access_tokens/").concat(params.accountId);
2693
+ }
2694
+ }, {
2695
+ key: "deleteAccessToken",
2696
+ value: function deleteAccessToken(params) {
2697
+ try {
2698
+ var _this8 = this;
2699
+ var _a;
2700
+ return AuthManagerBrowser_awaitIgnored(BaseAPI.fetch(_this8.getAccessTokenUrl(params), {
2701
+ method: "DELETE",
2702
+ credentials: "include",
2703
+ headers: {}
2704
+ }, {
2705
+ isBytescaleApi: true,
2706
+ fetchApi: (_a = params.options) === null || _a === void 0 ? void 0 : _a.fetchApi
2707
+ }));
2708
+ } catch (e) {
2709
+ return Promise.reject(e);
2710
+ }
2711
+ }
2712
+ }, {
2713
+ key: "setAccessToken",
2714
+ value: function setAccessToken(params, jwt) {
2715
+ try {
2716
+ var _this10 = this;
2717
+ var _a;
2718
+ var request = {
2719
+ accessToken: jwt
2720
+ };
2721
+ return AuthManagerBrowser_await(BaseAPI.fetch(_this10.getAccessTokenUrl(params), {
2722
+ method: "PUT",
2723
+ credentials: "include",
2724
+ headers: AuthManagerBrowser_defineProperty({}, _this10.contentType, _this10.contentTypeJson),
2725
+ body: JSON.stringify(request)
2726
+ }, {
2727
+ isBytescaleApi: true,
2728
+ fetchApi: (_a = params.options) === null || _a === void 0 ? void 0 : _a.fetchApi
2729
+ }), function (response) {
2730
+ return AuthManagerBrowser_await(response.json());
2731
+ });
2732
+ } catch (e) {
2733
+ return Promise.reject(e);
2734
+ }
2735
+ }
2736
+ }, {
2737
+ key: "getAccessToken",
2738
+ value: function getAccessToken(params, headers) {
2739
+ try {
2740
+ var _this12 = this;
2741
+ var _a, _b;
2742
+ var endpointName = "Your auth API endpoint";
2743
+ var requiredContentType = _this12.contentTypeText;
2744
+ return AuthManagerBrowser_await(BaseAPI.fetch(params.authUrl, {
2745
+ method: "GET",
2746
+ headers: headers
2747
+ }, {
2748
+ isBytescaleApi: false,
2749
+ fetchApi: (_a = params.options) === null || _a === void 0 ? void 0 : _a.fetchApi
2750
+ }), function (result) {
2751
+ var actualContentType = (_b = result.headers.get(_this12.contentType)) !== null && _b !== void 0 ? _b : "";
2752
+ // Support content types like "text/plain; charset=utf-8" and "text/plain"
2753
+ if (actualContentType.split(";")[0] !== requiredContentType) {
2754
+ throw new Error("".concat(endpointName, " returned \"").concat(actualContentType, "\" for the ").concat(_this12.contentType, " response header, but the Bytescale SDK requires \"").concat(requiredContentType, "\"."));
2755
+ }
2756
+ return AuthManagerBrowser_await(result.text(), function (jwt) {
2757
+ if (jwt.length === 0) {
2758
+ throw new Error("".concat(endpointName, " returned an empty string. Please return a valid JWT instead."));
2759
+ }
2760
+ if (jwt.trim().length !== jwt.length) {
2761
+ // Whitespace can be a nightmare to spot/debug, so we fail early here.
2762
+ throw new Error("".concat(endpointName, " returned whitespace around the JWT, please remove it."));
2763
+ }
2764
+ return jwt;
2765
+ });
2766
+ });
2767
+ } catch (e) {
2768
+ return Promise.reject(e);
2769
+ }
2770
+ }
2771
+ }]);
2772
+ return AuthManagerImpl;
2773
+ }();
2774
+ /**
2775
+ * Alternative way of implementing a static class (i.e. all methods static). We do this so we can use a interface on the class (interfaces can't define static methods).
2776
+ */
2777
+ var AuthManager = new AuthManagerImpl();
2778
+ ;// CONCATENATED MODULE: ./src/public/browser/index.ts
2779
+
2780
+
2781
+ ;// CONCATENATED MODULE: ./src/index.browser.ts
2782
+ /* tslint:disable */
2783
+ /* eslint-disable */
2784
+
2785
+
2786
+ var __lib_exports__AuthManager = __lib_exports__.AuthManager;
2787
+ var __lib_exports__BaseAPI = __lib_exports__.BaseAPI;
2788
+ var __lib_exports__BinaryResult = __lib_exports__.BinaryResult;
2789
+ var __lib_exports__BytescaleApiClientConfigUtils = __lib_exports__.BytescaleApiClientConfigUtils;
2790
+ var __lib_exports__BytescaleApiError = __lib_exports__.BytescaleApiError;
2791
+ var __lib_exports__CancelledError = __lib_exports__.CancelledError;
2792
+ var __lib_exports__CommonTypesNoOp = __lib_exports__.CommonTypesNoOp;
2793
+ var __lib_exports__FileApi = __lib_exports__.FileApi;
2794
+ var __lib_exports__FolderApi = __lib_exports__.FolderApi;
2795
+ var __lib_exports__JSONApiResponse = __lib_exports__.JSONApiResponse;
2796
+ var __lib_exports__JobApi = __lib_exports__.JobApi;
2797
+ var __lib_exports__UploadApi = __lib_exports__.UploadApi;
2798
+ var __lib_exports__UploadManager = __lib_exports__.UploadManager;
2799
+ var __lib_exports__UrlBuilder = __lib_exports__.UrlBuilder;
2800
+ var __lib_exports__UrlBuilderTypesNoOp = __lib_exports__.UrlBuilderTypesNoOp;
2801
+ var __lib_exports__VoidApiResponse = __lib_exports__.VoidApiResponse;
2802
+ var __lib_exports__querystring = __lib_exports__.querystring;
2803
+ export { __lib_exports__AuthManager as AuthManager, __lib_exports__BaseAPI as BaseAPI, __lib_exports__BinaryResult as BinaryResult, __lib_exports__BytescaleApiClientConfigUtils as BytescaleApiClientConfigUtils, __lib_exports__BytescaleApiError as BytescaleApiError, __lib_exports__CancelledError as CancelledError, __lib_exports__CommonTypesNoOp as CommonTypesNoOp, __lib_exports__FileApi as FileApi, __lib_exports__FolderApi as FolderApi, __lib_exports__JSONApiResponse as JSONApiResponse, __lib_exports__JobApi as JobApi, __lib_exports__UploadApi as UploadApi, __lib_exports__UploadManager as UploadManager, __lib_exports__UrlBuilder as UrlBuilder, __lib_exports__UrlBuilderTypesNoOp as UrlBuilderTypesNoOp, __lib_exports__VoidApiResponse as VoidApiResponse, __lib_exports__querystring as querystring };