@bytescale/sdk 3.0.0-alpha.12 → 3.0.0-alpha.13

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,2771 @@
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 the size upload-js 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
+ runtime_createClass(BaseAPI, [{
496
+ key: "request",
497
+ value: function request(context, initOverrides, baseUrlOverride) {
498
+ try {
499
+ var _this2 = this;
500
+ var _a;
501
+ var apiKey = _this2.config.apiKey;
502
+ context.headers["Authorization"] = "Bearer ".concat(apiKey); // authorization-header authentication
503
+ var session = AuthSessionState.getSession();
504
+ if ((session === null || session === void 0 ? void 0 : session.accessToken) !== undefined) {
505
+ context.headers["Authorization-Token"] = session.accessToken;
506
+ }
507
+ // Key: any possible value for 'baseUrlOverride'
508
+ // Value: user-overridden value for that base URL from the config.
509
+ var nonDefaultBasePaths = _defineProperty({}, BytescaleApiClientConfigUtils.defaultCdnUrl, BytescaleApiClientConfigUtils.getCdnUrl(_this2.config));
510
+ return runtime_await(_this2.createFetchParams(context, initOverrides, baseUrlOverride === undefined ? undefined : (_a = nonDefaultBasePaths[baseUrlOverride]) !== null && _a !== void 0 ? _a : baseUrlOverride), function (_ref) {
511
+ var url = _ref.url,
512
+ init = _ref.init;
513
+ return _this2.doFetch(url, init, true);
514
+ });
515
+ } catch (e) {
516
+ return Promise.reject(e);
517
+ }
518
+ }
519
+ /**
520
+ * Returns a successful response (2**) else throws an error.
521
+ */
522
+ }, {
523
+ key: "doFetch",
524
+ value: function doFetch(url, init, isBytescaleApi) {
525
+ try {
526
+ var _exit3 = false;
527
+ var _this4 = this;
528
+ var _a, _b;
529
+ var response;
530
+ return runtime_continue(_catch(function () {
531
+ return runtime_await(BytescaleApiClientConfigUtils.getFetchApi(_this4.config)(url, init), function (_BytescaleApiClientCo) {
532
+ response = _BytescaleApiClientCo;
533
+ });
534
+ }, function (e) {
535
+ // Network-level errors, CORS errors, or HTTP-level errors from intermediary services (e.g. AWS or the user's own infrastructure/proxies).
536
+ // 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.
537
+ throw new Error(isBytescaleApi ? "Unable to resolve the Bytescale API: ".concat(e.message, " If the problem persists, and your network connection is OK, then please contact support@bytescale.com and provide: (a) time of failed request in UTC (b) screenshot of failed network response header + body (c) screenshot of failed network request header + body (d) browser and OS version.") : "Unable to resolve URL (".concat(url, "): ").concat(e.message));
538
+ }), function (_result) {
539
+ var _exit2 = false;
540
+ if (_exit3) return _result;
541
+ return response.status >= 200 && response.status < 300 ? response : _invoke(function () {
542
+ if (isBytescaleApi) {
543
+ var jsonError = undefined;
544
+ return runtime_continue(_catch(function () {
545
+ return runtime_await(response.json(), function (_response$json) {
546
+ jsonError = _response$json;
547
+ });
548
+ }, runtime_empty), function () {
549
+ if (typeof ((_a = jsonError === null || jsonError === void 0 ? void 0 : jsonError.error) === null || _a === void 0 ? void 0 : _a.code) === "string") {
550
+ throw new BytescaleApiError(jsonError);
551
+ }
552
+ // HTTP-level errors from intermediary services (e.g. AWS or the user's own infrastructure/proxies). On the browser,
553
+ // this error is unlikely to be triggered since these errors will masqurade as CORS errors (see above) but in Node.js
554
+ // this error will appear from any intermediary service failure.
555
+ throw new Error("Unable to connect to the Bytescale API (".concat(response.status, "): please try again."));
556
+ });
557
+ }
558
+ }, function (_result2) {
559
+ if (_exit2) return _result2;
560
+ throw new Error("Failure status code (".concat(response.status, ") received for request: ").concat((_b = init.method) !== null && _b !== void 0 ? _b : "GET", " ").concat(url));
561
+ });
562
+ });
563
+ } catch (e) {
564
+ return Promise.reject(e);
565
+ }
566
+ }
567
+ }, {
568
+ key: "encodeParam",
569
+ value: function encodeParam(paramName, paramValue) {
570
+ if (paramName === "filePath") {
571
+ if (!paramValue.startsWith("/")) {
572
+ // Non-obvious errors are returned by the Bytescale CDN if forward slashes are omitted, so catch it client-side:
573
+ throw new Error("The 'filePath' parameter must begin with a '/' character.");
574
+ }
575
+ // We must not encode the filePath param (as slashes are valid).
576
+ return paramValue;
577
+ }
578
+ return encodeURIComponent(paramValue);
579
+ }
580
+ }, {
581
+ key: "createFetchParams",
582
+ value: function createFetchParams(context, initOverrides, baseUrlOverride) {
583
+ try {
584
+ var _this6 = this;
585
+ var url = (baseUrlOverride !== null && baseUrlOverride !== void 0 ? baseUrlOverride : BytescaleApiClientConfigUtils.getApiUrl(_this6.config)) + context.path;
586
+ if (context.query !== undefined && Object.keys(context.query).length !== 0) {
587
+ // only add the querystring to the URL if there are query parameters.
588
+ // this is done to avoid urls ending with a "?" character which buggy webservers
589
+ // do not handle correctly sometimes.
590
+ url += "?" + querystring(context.query);
591
+ }
592
+ var configHeaders = _this6.config.headers;
593
+ var _Object$assign3 = Object.assign({}, context.headers);
594
+ return runtime_await(configHeaders === undefined ? {} : configHeaders(), function (_configHeaders) {
595
+ var headers = Object.assign(_Object$assign3, _configHeaders);
596
+ Object.keys(headers).forEach(function (key) {
597
+ return headers[key] === undefined ? delete headers[key] : {};
598
+ });
599
+ var initOverrideFn = typeof initOverrides === "function" ? initOverrides : function () {
600
+ return runtime_await(initOverrides);
601
+ };
602
+ var initParams = {
603
+ method: context.method,
604
+ headers: headers,
605
+ body: context.body
606
+ };
607
+ var _Object$assign2 = Object.assign({}, initParams);
608
+ return runtime_await(initOverrideFn({
609
+ init: initParams,
610
+ context: context
611
+ }), function (_initOverrideFn) {
612
+ var overriddenInit = Object.assign(_Object$assign2, _initOverrideFn);
613
+ var init = Object.assign(Object.assign({}, overriddenInit), {
614
+ body: JSON.stringify(overriddenInit.body)
615
+ });
616
+ return {
617
+ url: url,
618
+ init: init
619
+ };
620
+ });
621
+ }, configHeaders === undefined);
622
+ } catch (e) {
623
+ return Promise.reject(e);
624
+ }
625
+ }
626
+ }]);
627
+ return BaseAPI;
628
+ }();
629
+ var CancelledError = /*#__PURE__*/function (_Error) {
630
+ _inherits(CancelledError, _Error);
631
+ var _super = _createSuper(CancelledError);
632
+ function CancelledError() {
633
+ var _this7;
634
+ runtime_classCallCheck(this, CancelledError);
635
+ _this7 = _super.call(this, "Operation cancelled by caller.");
636
+ _this7.name = "CancelledError";
637
+ return _this7;
638
+ }
639
+ return runtime_createClass(CancelledError);
640
+ }( /*#__PURE__*/_wrapNativeSuper(Error));
641
+ var BytescaleApiError = /*#__PURE__*/function (_Error2) {
642
+ _inherits(BytescaleApiError, _Error2);
643
+ var _super2 = _createSuper(BytescaleApiError);
644
+ function BytescaleApiError(response) {
645
+ var _this8;
646
+ runtime_classCallCheck(this, BytescaleApiError);
647
+ _this8 = _super2.call(this, response.error.message);
648
+ _this8.name = "BytescaleApiError";
649
+ _this8.errorCode = response.error.code;
650
+ _this8.details = response.error.details;
651
+ return _this8;
652
+ }
653
+ return runtime_createClass(BytescaleApiError);
654
+ }( /*#__PURE__*/_wrapNativeSuper(Error));
655
+ function querystring(params) {
656
+ return Object.keys(params).map(function (key) {
657
+ return querystringSingleKey(key, params[key]);
658
+ }).filter(function (part) {
659
+ return part.length > 0;
660
+ }).join("&");
661
+ }
662
+ function querystringSingleKey(key, value) {
663
+ if (value instanceof Object) {
664
+ return querystring(value);
665
+ }
666
+ return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(String(value)));
667
+ }
668
+ var JSONApiResponse = /*#__PURE__*/function () {
669
+ function JSONApiResponse(raw) {
670
+ runtime_classCallCheck(this, JSONApiResponse);
671
+ this.raw = raw;
672
+ }
673
+ runtime_createClass(JSONApiResponse, [{
674
+ key: "value",
675
+ value: function value() {
676
+ try {
677
+ var _this10 = this;
678
+ return runtime_await(_this10.raw.json());
679
+ } catch (e) {
680
+ return Promise.reject(e);
681
+ }
682
+ }
683
+ }]);
684
+ return JSONApiResponse;
685
+ }();
686
+ var VoidApiResponse = /*#__PURE__*/function () {
687
+ function VoidApiResponse(raw) {
688
+ runtime_classCallCheck(this, VoidApiResponse);
689
+ this.raw = raw;
690
+ }
691
+ runtime_createClass(VoidApiResponse, [{
692
+ key: "value",
693
+ value: function value() {
694
+ return runtime_await(undefined);
695
+ }
696
+ }]);
697
+ return VoidApiResponse;
698
+ }();
699
+ var BinaryResult = /*#__PURE__*/function () {
700
+ function BinaryResult(raw) {
701
+ runtime_classCallCheck(this, BinaryResult);
702
+ this.raw = raw;
703
+ }
704
+ runtime_createClass(BinaryResult, [{
705
+ key: "stream",
706
+ value: function stream() {
707
+ if (this.raw.bodyUsed) {
708
+ throw new Error("Response body has already been consumed.");
709
+ }
710
+ if (this.raw.body === null) {
711
+ throw new Error("Response body does not exist.");
712
+ }
713
+ return this.raw.body;
714
+ }
715
+ }, {
716
+ key: "text",
717
+ value: function text() {
718
+ try {
719
+ var _this12 = this;
720
+ return runtime_await(_this12.raw.text());
721
+ } catch (e) {
722
+ return Promise.reject(e);
723
+ }
724
+ }
725
+ }, {
726
+ key: "blob",
727
+ value: function blob() {
728
+ try {
729
+ var _this14 = this;
730
+ return runtime_await(_this14.raw.blob());
731
+ } catch (e) {
732
+ return Promise.reject(e);
733
+ }
734
+ }
735
+ }, {
736
+ key: "json",
737
+ value: function json() {
738
+ try {
739
+ var _this16 = this;
740
+ return runtime_await(_this16.raw.json());
741
+ } catch (e) {
742
+ return Promise.reject(e);
743
+ }
744
+ }
745
+ }]);
746
+ return BinaryResult;
747
+ }();
748
+ ;// CONCATENATED MODULE: ./src/public/shared/generated/apis/FileApi.ts
749
+ 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); }
750
+ function FileApi_await(value, then, direct) {
751
+ if (direct) {
752
+ return then ? then(value) : value;
753
+ }
754
+ if (!value || !value.then) {
755
+ value = Promise.resolve(value);
756
+ }
757
+ return then ? value.then(then) : value;
758
+ }
759
+ function FileApi_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
760
+ 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); } }
761
+ 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; }
762
+ function FileApi_toPropertyKey(arg) { var key = FileApi_toPrimitive(arg, "string"); return FileApi_typeof(key) === "symbol" ? key : String(key); }
763
+ 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); }
764
+ 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); }
765
+ 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); }
766
+ 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); }; }
767
+ 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); }
768
+ function FileApi_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
769
+ 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; } }
770
+ function FileApi_getPrototypeOf(o) { FileApi_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return FileApi_getPrototypeOf(o); }
771
+ /* tslint:disable */
772
+ /* eslint-disable */
773
+ /**
774
+ * @bytescale/api
775
+ * Bytescale API
776
+ *
777
+ * The version of the OpenAPI document: 2.0.0
778
+ * Contact: hello@bytescale.com
779
+ *
780
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
781
+ * https://openapi-generator.tech
782
+ * Do not edit the class manually.
783
+ */
784
+ // @ts-ignore
785
+
786
+ var FileApi = /*#__PURE__*/function (_runtime$BaseAPI) {
787
+ FileApi_inherits(FileApi, _runtime$BaseAPI);
788
+ var _super = FileApi_createSuper(FileApi);
789
+ function FileApi() {
790
+ FileApi_classCallCheck(this, FileApi);
791
+ return _super.apply(this, arguments);
792
+ }
793
+ FileApi_createClass(FileApi, [{
794
+ key: "copyFile",
795
+ value:
796
+ /**
797
+ * Copies a file synchronously.
798
+ */
799
+ function copyFile(params) {
800
+ try {
801
+ var _this2 = this;
802
+ var query = {};
803
+ var headers = {};
804
+ headers["Content-Type"] = "application/json";
805
+ return FileApi_await(_this2.request({
806
+ path: "/v2/accounts/{accountId}/files/copy".replace("{".concat("accountId", "}"),
807
+ // @ts-ignore
808
+ _this2.encodeParam("accountId", params.accountId)),
809
+ method: "POST",
810
+ headers: headers,
811
+ query: query,
812
+ body: params.copyFileRequest
813
+ }, undefined, [][0]), function (response) {
814
+ return FileApi_await(new JSONApiResponse(response).value());
815
+ });
816
+ } catch (e) {
817
+ return Promise.reject(e);
818
+ }
819
+ }
820
+ /**
821
+ * Copies multiple files asynchronously.
822
+ */
823
+ }, {
824
+ key: "copyFileBatch",
825
+ value: function copyFileBatch(params) {
826
+ try {
827
+ var _this4 = this;
828
+ var query = {};
829
+ var headers = {};
830
+ headers["Content-Type"] = "application/json";
831
+ return FileApi_await(_this4.request({
832
+ path: "/v2/accounts/{accountId}/files/copy/batch".replace("{".concat("accountId", "}"),
833
+ // @ts-ignore
834
+ _this4.encodeParam("accountId", params.accountId)),
835
+ method: "POST",
836
+ headers: headers,
837
+ query: query,
838
+ body: params.copyFileBatchRequest
839
+ }, undefined, [][0]), function (response) {
840
+ return FileApi_await(new JSONApiResponse(response).value());
841
+ });
842
+ } catch (e) {
843
+ return Promise.reject(e);
844
+ }
845
+ }
846
+ /**
847
+ * Deletes a file synchronously.
848
+ */
849
+ }, {
850
+ key: "deleteFile",
851
+ value: function deleteFile(params) {
852
+ try {
853
+ var _this6 = this;
854
+ var query = {};
855
+ if (params.filePath !== undefined) {
856
+ query["filePath"] = params.filePath;
857
+ }
858
+ var headers = {};
859
+ return FileApi_await(_this6.request({
860
+ path: "/v2/accounts/{accountId}/files".replace("{".concat("accountId", "}"),
861
+ // @ts-ignore
862
+ _this6.encodeParam("accountId", params.accountId)),
863
+ method: "DELETE",
864
+ headers: headers,
865
+ query: query
866
+ }, undefined, [][0]), function (response) {
867
+ return FileApi_await(new VoidApiResponse(response).value());
868
+ });
869
+ } catch (e) {
870
+ return Promise.reject(e);
871
+ }
872
+ }
873
+ /**
874
+ * Deletes multiple files asynchronously.
875
+ */
876
+ }, {
877
+ key: "deleteFileBatch",
878
+ value: function deleteFileBatch(params) {
879
+ try {
880
+ var _this8 = this;
881
+ var query = {};
882
+ var headers = {};
883
+ headers["Content-Type"] = "application/json";
884
+ return FileApi_await(_this8.request({
885
+ path: "/v2/accounts/{accountId}/files/batch".replace("{".concat("accountId", "}"),
886
+ // @ts-ignore
887
+ _this8.encodeParam("accountId", params.accountId)),
888
+ method: "DELETE",
889
+ headers: headers,
890
+ query: query,
891
+ body: params.deleteFileBatchRequest
892
+ }, undefined, [][0]), function (response) {
893
+ return FileApi_await(new JSONApiResponse(response).value());
894
+ });
895
+ } catch (e) {
896
+ return Promise.reject(e);
897
+ }
898
+ }
899
+ /**
900
+ * Downloads a file in its original/unprocessed state.
901
+ */
902
+ }, {
903
+ key: "downloadFile",
904
+ value: function downloadFile(params) {
905
+ try {
906
+ var _this10 = this;
907
+ var query = {};
908
+ if (params.cache !== undefined) {
909
+ query["cache"] = params.cache;
910
+ }
911
+ if (params.cacheTtl !== undefined) {
912
+ query["cache_ttl"] = params.cacheTtl;
913
+ }
914
+ if (params.version !== undefined) {
915
+ query["version"] = params.version;
916
+ }
917
+ var headers = {};
918
+ return FileApi_await(_this10.request({
919
+ path: "/{accountId}/raw{filePath}".replace("{".concat("accountId", "}"),
920
+ // @ts-ignore
921
+ _this10.encodeParam("accountId", params.accountId)).replace("{".concat("filePath", "}"),
922
+ // @ts-ignore
923
+ _this10.encodeParam("filePath", params.filePath)),
924
+ method: "GET",
925
+ headers: headers,
926
+ query: query
927
+ }, undefined, ["https://upcdn.io"][0]), function (response) {
928
+ return new BinaryResult(response);
929
+ });
930
+ } catch (e) {
931
+ return Promise.reject(e);
932
+ }
933
+ }
934
+ /**
935
+ * Gets the full details (e.g. metadata, tags, etc.) for a file.
936
+ */
937
+ }, {
938
+ key: "getFileDetails",
939
+ value: function getFileDetails(params) {
940
+ try {
941
+ var _this12 = this;
942
+ var query = {};
943
+ if (params.filePath !== undefined) {
944
+ query["filePath"] = params.filePath;
945
+ }
946
+ var headers = {};
947
+ return FileApi_await(_this12.request({
948
+ path: "/v2/accounts/{accountId}/files/details".replace("{".concat("accountId", "}"),
949
+ // @ts-ignore
950
+ _this12.encodeParam("accountId", params.accountId)),
951
+ method: "GET",
952
+ headers: headers,
953
+ query: query
954
+ }, undefined, [][0]), function (response) {
955
+ return FileApi_await(new JSONApiResponse(response).value());
956
+ });
957
+ } catch (e) {
958
+ return Promise.reject(e);
959
+ }
960
+ }
961
+ /**
962
+ * Processes a file and returns the result.
963
+ */
964
+ }, {
965
+ key: "processFile",
966
+ value: function processFile(params) {
967
+ try {
968
+ var _this14 = this;
969
+ var query = {};
970
+ if (params.artifact !== undefined) {
971
+ query["artifact"] = params.artifact;
972
+ }
973
+ if (params.cache !== undefined) {
974
+ query["cache"] = params.cache;
975
+ }
976
+ if (params.cachePerm !== undefined) {
977
+ query["cache_perm"] = params.cachePerm;
978
+ }
979
+ if (params.cacheTtl !== undefined) {
980
+ query["cache_ttl"] = params.cacheTtl;
981
+ }
982
+ if (params.large !== undefined) {
983
+ query["large"] = params.large;
984
+ }
985
+ if (params.transformationParams !== undefined) {
986
+ query["transformationParams"] = params.transformationParams;
987
+ }
988
+ if (params.version !== undefined) {
989
+ query["version"] = params.version;
990
+ }
991
+ var headers = {};
992
+ return FileApi_await(_this14.request({
993
+ path: "/{accountId}/{transformation}{filePath}".replace("{".concat("accountId", "}"),
994
+ // @ts-ignore
995
+ _this14.encodeParam("accountId", params.accountId)).replace("{".concat("filePath", "}"),
996
+ // @ts-ignore
997
+ _this14.encodeParam("filePath", params.filePath)).replace("{".concat("transformation", "}"),
998
+ // @ts-ignore
999
+ _this14.encodeParam("transformation", params.transformation)),
1000
+ method: "GET",
1001
+ headers: headers,
1002
+ query: query
1003
+ }, undefined, ["https://upcdn.io"][0]), function (response) {
1004
+ return new BinaryResult(response);
1005
+ });
1006
+ } catch (e) {
1007
+ return Promise.reject(e);
1008
+ }
1009
+ }
1010
+ /**
1011
+ * Processes a file and saves the result.
1012
+ */
1013
+ }, {
1014
+ key: "processFileAndSave",
1015
+ value: function processFileAndSave(params) {
1016
+ try {
1017
+ var _this16 = this;
1018
+ var query = {};
1019
+ if (params.transformationParams !== undefined) {
1020
+ query["transformationParams"] = params.transformationParams;
1021
+ }
1022
+ var headers = {};
1023
+ headers["Content-Type"] = "application/json";
1024
+ return FileApi_await(_this16.request({
1025
+ path: "/{accountId}/save/{transformation}{filePath}".replace("{".concat("accountId", "}"),
1026
+ // @ts-ignore
1027
+ _this16.encodeParam("accountId", params.accountId)).replace("{".concat("filePath", "}"),
1028
+ // @ts-ignore
1029
+ _this16.encodeParam("filePath", params.filePath)).replace("{".concat("transformation", "}"),
1030
+ // @ts-ignore
1031
+ _this16.encodeParam("transformation", params.transformation)),
1032
+ method: "POST",
1033
+ headers: headers,
1034
+ query: query,
1035
+ body: params.processFileAndSaveRequest
1036
+ }, undefined, ["https://upcdn.io"][0]), function (response) {
1037
+ return FileApi_await(new JSONApiResponse(response).value());
1038
+ });
1039
+ } catch (e) {
1040
+ return Promise.reject(e);
1041
+ }
1042
+ }
1043
+ }]);
1044
+ return FileApi;
1045
+ }(BaseAPI);
1046
+ ;// CONCATENATED MODULE: ./src/public/shared/generated/apis/FolderApi.ts
1047
+ 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); }
1048
+ function FolderApi_await(value, then, direct) {
1049
+ if (direct) {
1050
+ return then ? then(value) : value;
1051
+ }
1052
+ if (!value || !value.then) {
1053
+ value = Promise.resolve(value);
1054
+ }
1055
+ return then ? value.then(then) : value;
1056
+ }
1057
+ function FolderApi_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1058
+ 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); } }
1059
+ 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; }
1060
+ function FolderApi_toPropertyKey(arg) { var key = FolderApi_toPrimitive(arg, "string"); return FolderApi_typeof(key) === "symbol" ? key : String(key); }
1061
+ 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); }
1062
+ 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); }
1063
+ 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); }
1064
+ 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); }; }
1065
+ 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); }
1066
+ function FolderApi_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
1067
+ 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; } }
1068
+ function FolderApi_getPrototypeOf(o) { FolderApi_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return FolderApi_getPrototypeOf(o); }
1069
+ /* tslint:disable */
1070
+ /* eslint-disable */
1071
+ /**
1072
+ * @bytescale/api
1073
+ * Bytescale API
1074
+ *
1075
+ * The version of the OpenAPI document: 2.0.0
1076
+ * Contact: hello@bytescale.com
1077
+ *
1078
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
1079
+ * https://openapi-generator.tech
1080
+ * Do not edit the class manually.
1081
+ */
1082
+ // @ts-ignore
1083
+
1084
+ var FolderApi = /*#__PURE__*/function (_runtime$BaseAPI) {
1085
+ FolderApi_inherits(FolderApi, _runtime$BaseAPI);
1086
+ var _super = FolderApi_createSuper(FolderApi);
1087
+ function FolderApi() {
1088
+ FolderApi_classCallCheck(this, FolderApi);
1089
+ return _super.apply(this, arguments);
1090
+ }
1091
+ FolderApi_createClass(FolderApi, [{
1092
+ key: "copyFolder",
1093
+ value:
1094
+ /**
1095
+ * 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.
1096
+ */
1097
+ function copyFolder(params) {
1098
+ try {
1099
+ var _this2 = this;
1100
+ var query = {};
1101
+ var headers = {};
1102
+ headers["Content-Type"] = "application/json";
1103
+ return FolderApi_await(_this2.request({
1104
+ path: "/v2/accounts/{accountId}/folders/copy".replace("{".concat("accountId", "}"),
1105
+ // @ts-ignore
1106
+ _this2.encodeParam("accountId", params.accountId)),
1107
+ method: "POST",
1108
+ headers: headers,
1109
+ query: query,
1110
+ body: params.copyFolderRequest
1111
+ }, undefined, [][0]), function (response) {
1112
+ return FolderApi_await(new JSONApiResponse(response).value());
1113
+ });
1114
+ } catch (e) {
1115
+ return Promise.reject(e);
1116
+ }
1117
+ }
1118
+ /**
1119
+ * 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.
1120
+ */
1121
+ }, {
1122
+ key: "copyFolderBatch",
1123
+ value: function copyFolderBatch(params) {
1124
+ try {
1125
+ var _this4 = this;
1126
+ var query = {};
1127
+ var headers = {};
1128
+ headers["Content-Type"] = "application/json";
1129
+ return FolderApi_await(_this4.request({
1130
+ path: "/v2/accounts/{accountId}/folders/copy/batch".replace("{".concat("accountId", "}"),
1131
+ // @ts-ignore
1132
+ _this4.encodeParam("accountId", params.accountId)),
1133
+ method: "POST",
1134
+ headers: headers,
1135
+ query: query,
1136
+ body: params.copyFolderBatchRequest
1137
+ }, undefined, [][0]), function (response) {
1138
+ return FolderApi_await(new JSONApiResponse(response).value());
1139
+ });
1140
+ } catch (e) {
1141
+ return Promise.reject(e);
1142
+ }
1143
+ }
1144
+ /**
1145
+ * 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.
1146
+ */
1147
+ }, {
1148
+ key: "deleteFolder",
1149
+ value: function deleteFolder(params) {
1150
+ try {
1151
+ var _this6 = this;
1152
+ var query = {};
1153
+ var headers = {};
1154
+ headers["Content-Type"] = "application/json";
1155
+ return FolderApi_await(_this6.request({
1156
+ path: "/v2/accounts/{accountId}/folders".replace("{".concat("accountId", "}"),
1157
+ // @ts-ignore
1158
+ _this6.encodeParam("accountId", params.accountId)),
1159
+ method: "DELETE",
1160
+ headers: headers,
1161
+ query: query,
1162
+ body: params.deleteFolderRequest
1163
+ }, undefined, [][0]), function (response) {
1164
+ return FolderApi_await(new JSONApiResponse(response).value());
1165
+ });
1166
+ } catch (e) {
1167
+ return Promise.reject(e);
1168
+ }
1169
+ }
1170
+ /**
1171
+ * 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.
1172
+ */
1173
+ }, {
1174
+ key: "deleteFolderBatch",
1175
+ value: function deleteFolderBatch(params) {
1176
+ try {
1177
+ var _this8 = this;
1178
+ var query = {};
1179
+ var headers = {};
1180
+ headers["Content-Type"] = "application/json";
1181
+ return FolderApi_await(_this8.request({
1182
+ path: "/v2/accounts/{accountId}/folders/batch".replace("{".concat("accountId", "}"),
1183
+ // @ts-ignore
1184
+ _this8.encodeParam("accountId", params.accountId)),
1185
+ method: "DELETE",
1186
+ headers: headers,
1187
+ query: query,
1188
+ body: params.deleteFolderBatchRequest
1189
+ }, undefined, [][0]), function (response) {
1190
+ return FolderApi_await(new JSONApiResponse(response).value());
1191
+ });
1192
+ } catch (e) {
1193
+ return Promise.reject(e);
1194
+ }
1195
+ }
1196
+ /**
1197
+ * 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.
1198
+ */
1199
+ }, {
1200
+ key: "getFolderDetails",
1201
+ value: function getFolderDetails(params) {
1202
+ try {
1203
+ var _this10 = this;
1204
+ var query = {};
1205
+ if (params.folderPath !== undefined) {
1206
+ query["folderPath"] = params.folderPath;
1207
+ }
1208
+ var headers = {};
1209
+ return FolderApi_await(_this10.request({
1210
+ path: "/v2/accounts/{accountId}/folders".replace("{".concat("accountId", "}"),
1211
+ // @ts-ignore
1212
+ _this10.encodeParam("accountId", params.accountId)),
1213
+ method: "GET",
1214
+ headers: headers,
1215
+ query: query
1216
+ }, undefined, [][0]), function (response) {
1217
+ return FolderApi_await(new JSONApiResponse(response).value());
1218
+ });
1219
+ } catch (e) {
1220
+ return Promise.reject(e);
1221
+ }
1222
+ }
1223
+ /**
1224
+ * 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`.
1225
+ */
1226
+ }, {
1227
+ key: "listFolder",
1228
+ value: function listFolder(params) {
1229
+ try {
1230
+ var _this12 = this;
1231
+ var query = {};
1232
+ if (params.cursor !== undefined) {
1233
+ query["cursor"] = params.cursor;
1234
+ }
1235
+ if (params.dryRun !== undefined) {
1236
+ query["dryRun"] = params.dryRun;
1237
+ }
1238
+ if (params.folderPath !== undefined) {
1239
+ query["folderPath"] = params.folderPath;
1240
+ }
1241
+ if (params.includeFiles !== undefined) {
1242
+ query["includeFiles"] = params.includeFiles;
1243
+ }
1244
+ if (params.includeOverriddenStorage !== undefined) {
1245
+ query["includeOverriddenStorage"] = params.includeOverriddenStorage;
1246
+ }
1247
+ if (params.includePhysicalFolders !== undefined) {
1248
+ query["includePhysicalFolders"] = params.includePhysicalFolders;
1249
+ }
1250
+ if (params.includeVirtualFolders !== undefined) {
1251
+ query["includeVirtualFolders"] = params.includeVirtualFolders;
1252
+ }
1253
+ if (params.limit !== undefined) {
1254
+ query["limit"] = params.limit;
1255
+ }
1256
+ if (params.recursive !== undefined) {
1257
+ query["recursive"] = params.recursive;
1258
+ }
1259
+ var headers = {};
1260
+ return FolderApi_await(_this12.request({
1261
+ path: "/v2/accounts/{accountId}/folders/list".replace("{".concat("accountId", "}"),
1262
+ // @ts-ignore
1263
+ _this12.encodeParam("accountId", params.accountId)),
1264
+ method: "GET",
1265
+ headers: headers,
1266
+ query: query
1267
+ }, undefined, [][0]), function (response) {
1268
+ return FolderApi_await(new JSONApiResponse(response).value());
1269
+ });
1270
+ } catch (e) {
1271
+ return Promise.reject(e);
1272
+ }
1273
+ }
1274
+ /**
1275
+ * 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.
1276
+ */
1277
+ }, {
1278
+ key: "putFolder",
1279
+ value: function putFolder(params) {
1280
+ try {
1281
+ var _this14 = this;
1282
+ var query = {};
1283
+ var headers = {};
1284
+ headers["Content-Type"] = "application/json";
1285
+ return FolderApi_await(_this14.request({
1286
+ path: "/v2/accounts/{accountId}/folders".replace("{".concat("accountId", "}"),
1287
+ // @ts-ignore
1288
+ _this14.encodeParam("accountId", params.accountId)),
1289
+ method: "PUT",
1290
+ headers: headers,
1291
+ query: query,
1292
+ body: params.putFolderRequest
1293
+ }, undefined, [][0]), function (response) {
1294
+ return FolderApi_await(new JSONApiResponse(response).value());
1295
+ });
1296
+ } catch (e) {
1297
+ return Promise.reject(e);
1298
+ }
1299
+ }
1300
+ }]);
1301
+ return FolderApi;
1302
+ }(BaseAPI);
1303
+ ;// CONCATENATED MODULE: ./src/public/shared/generated/apis/JobApi.ts
1304
+ 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); }
1305
+ function JobApi_await(value, then, direct) {
1306
+ if (direct) {
1307
+ return then ? then(value) : value;
1308
+ }
1309
+ if (!value || !value.then) {
1310
+ value = Promise.resolve(value);
1311
+ }
1312
+ return then ? value.then(then) : value;
1313
+ }
1314
+ function JobApi_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1315
+ 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); } }
1316
+ 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; }
1317
+ function JobApi_toPropertyKey(arg) { var key = JobApi_toPrimitive(arg, "string"); return JobApi_typeof(key) === "symbol" ? key : String(key); }
1318
+ 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); }
1319
+ 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); }
1320
+ 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); }
1321
+ 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); }; }
1322
+ 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); }
1323
+ function JobApi_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
1324
+ 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; } }
1325
+ function JobApi_getPrototypeOf(o) { JobApi_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return JobApi_getPrototypeOf(o); }
1326
+ /* tslint:disable */
1327
+ /* eslint-disable */
1328
+ /**
1329
+ * @bytescale/api
1330
+ * Bytescale API
1331
+ *
1332
+ * The version of the OpenAPI document: 2.0.0
1333
+ * Contact: hello@bytescale.com
1334
+ *
1335
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
1336
+ * https://openapi-generator.tech
1337
+ * Do not edit the class manually.
1338
+ */
1339
+ // @ts-ignore
1340
+
1341
+ var JobApi = /*#__PURE__*/function (_runtime$BaseAPI) {
1342
+ JobApi_inherits(JobApi, _runtime$BaseAPI);
1343
+ var _super = JobApi_createSuper(JobApi);
1344
+ function JobApi() {
1345
+ JobApi_classCallCheck(this, JobApi);
1346
+ return _super.apply(this, arguments);
1347
+ }
1348
+ JobApi_createClass(JobApi, [{
1349
+ key: "cancelJob",
1350
+ value:
1351
+ /**
1352
+ * Cancels an in-progress background job. Requires a `secret_*` API key.
1353
+ */
1354
+ function cancelJob(params) {
1355
+ try {
1356
+ var _this2 = this;
1357
+ var query = {};
1358
+ var headers = {};
1359
+ return JobApi_await(_this2.request({
1360
+ path: "/v2/accounts/{accountId}/jobs/{jobType}/{jobId}".replace("{".concat("accountId", "}"),
1361
+ // @ts-ignore
1362
+ _this2.encodeParam("accountId", params.accountId)).replace("{".concat("jobId", "}"),
1363
+ // @ts-ignore
1364
+ _this2.encodeParam("jobId", params.jobId)).replace("{".concat("jobType", "}"),
1365
+ // @ts-ignore
1366
+ _this2.encodeParam("jobType", params.jobType)),
1367
+ method: "DELETE",
1368
+ headers: headers,
1369
+ query: query
1370
+ }, undefined, [][0]), function (response) {
1371
+ return JobApi_await(new VoidApiResponse(response).value());
1372
+ });
1373
+ } catch (e) {
1374
+ return Promise.reject(e);
1375
+ }
1376
+ }
1377
+ /**
1378
+ * Gets information on a background job. Requires a `secret_*` API key.
1379
+ */
1380
+ }, {
1381
+ key: "getJob",
1382
+ value: function getJob(params) {
1383
+ try {
1384
+ var _this4 = this;
1385
+ var query = {};
1386
+ var headers = {};
1387
+ return JobApi_await(_this4.request({
1388
+ path: "/v2/accounts/{accountId}/jobs/{jobType}/{jobId}".replace("{".concat("accountId", "}"),
1389
+ // @ts-ignore
1390
+ _this4.encodeParam("accountId", params.accountId)).replace("{".concat("jobId", "}"),
1391
+ // @ts-ignore
1392
+ _this4.encodeParam("jobId", params.jobId)).replace("{".concat("jobType", "}"),
1393
+ // @ts-ignore
1394
+ _this4.encodeParam("jobType", params.jobType)),
1395
+ method: "GET",
1396
+ headers: headers,
1397
+ query: query
1398
+ }, undefined, [][0]), function (response) {
1399
+ return JobApi_await(new JSONApiResponse(response).value());
1400
+ });
1401
+ } catch (e) {
1402
+ return Promise.reject(e);
1403
+ }
1404
+ }
1405
+ /**
1406
+ * Lists the most recently issued background jobs. Requires a `secret_*` API key.
1407
+ */
1408
+ }, {
1409
+ key: "listRecentJobs",
1410
+ value: function listRecentJobs(params) {
1411
+ try {
1412
+ var _this6 = this;
1413
+ var query = {};
1414
+ if (params.jobType) {
1415
+ query["jobType"] = params.jobType;
1416
+ }
1417
+ var headers = {};
1418
+ return JobApi_await(_this6.request({
1419
+ path: "/v2/accounts/{accountId}/jobs".replace("{".concat("accountId", "}"),
1420
+ // @ts-ignore
1421
+ _this6.encodeParam("accountId", params.accountId)),
1422
+ method: "GET",
1423
+ headers: headers,
1424
+ query: query
1425
+ }, undefined, [][0]), function (response) {
1426
+ return JobApi_await(new JSONApiResponse(response).value());
1427
+ });
1428
+ } catch (e) {
1429
+ return Promise.reject(e);
1430
+ }
1431
+ }
1432
+ }]);
1433
+ return JobApi;
1434
+ }(BaseAPI);
1435
+ ;// CONCATENATED MODULE: ./src/public/shared/generated/apis/UploadApi.ts
1436
+ 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); }
1437
+ function UploadApi_await(value, then, direct) {
1438
+ if (direct) {
1439
+ return then ? then(value) : value;
1440
+ }
1441
+ if (!value || !value.then) {
1442
+ value = Promise.resolve(value);
1443
+ }
1444
+ return then ? value.then(then) : value;
1445
+ }
1446
+ function UploadApi_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1447
+ 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); } }
1448
+ 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; }
1449
+ function UploadApi_toPropertyKey(arg) { var key = UploadApi_toPrimitive(arg, "string"); return UploadApi_typeof(key) === "symbol" ? key : String(key); }
1450
+ 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); }
1451
+ 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); }
1452
+ 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); }
1453
+ 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); }; }
1454
+ 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); }
1455
+ function UploadApi_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
1456
+ 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; } }
1457
+ function UploadApi_getPrototypeOf(o) { UploadApi_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return UploadApi_getPrototypeOf(o); }
1458
+ /* tslint:disable */
1459
+ /* eslint-disable */
1460
+ /**
1461
+ * @bytescale/api
1462
+ * Bytescale API
1463
+ *
1464
+ * The version of the OpenAPI document: 2.0.0
1465
+ * Contact: hello@bytescale.com
1466
+ *
1467
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
1468
+ * https://openapi-generator.tech
1469
+ * Do not edit the class manually.
1470
+ */
1471
+ // @ts-ignore
1472
+
1473
+ var UploadApi = /*#__PURE__*/function (_runtime$BaseAPI) {
1474
+ UploadApi_inherits(UploadApi, _runtime$BaseAPI);
1475
+ var _super = UploadApi_createSuper(UploadApi);
1476
+ function UploadApi() {
1477
+ UploadApi_classCallCheck(this, UploadApi);
1478
+ return _super.apply(this, arguments);
1479
+ }
1480
+ UploadApi_createClass(UploadApi, [{
1481
+ key: "beginMultipartUpload",
1482
+ value:
1483
+ /**
1484
+ * Begins a new multipart file upload process.
1485
+ */
1486
+ function beginMultipartUpload(params) {
1487
+ try {
1488
+ var _this2 = this;
1489
+ var query = {};
1490
+ var headers = {};
1491
+ headers["Content-Type"] = "application/json";
1492
+ return UploadApi_await(_this2.request({
1493
+ path: "/v2/accounts/{accountId}/uploads".replace("{".concat("accountId", "}"),
1494
+ // @ts-ignore
1495
+ _this2.encodeParam("accountId", params.accountId)),
1496
+ method: "POST",
1497
+ headers: headers,
1498
+ query: query,
1499
+ body: params.beginMultipartUploadRequest
1500
+ }, undefined, [][0]), function (response) {
1501
+ return UploadApi_await(new JSONApiResponse(response).value());
1502
+ });
1503
+ } catch (e) {
1504
+ return Promise.reject(e);
1505
+ }
1506
+ }
1507
+ /**
1508
+ * 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.
1509
+ */
1510
+ }, {
1511
+ key: "completeUploadPart",
1512
+ value: function completeUploadPart(params) {
1513
+ try {
1514
+ var _this4 = this;
1515
+ var query = {};
1516
+ var headers = {};
1517
+ headers["Content-Type"] = "application/json";
1518
+ return UploadApi_await(_this4.request({
1519
+ path: "/v2/accounts/{accountId}/uploads/{uploadId}/parts/{uploadPartIndex}".replace("{".concat("accountId", "}"),
1520
+ // @ts-ignore
1521
+ _this4.encodeParam("accountId", params.accountId)).replace("{".concat("uploadId", "}"),
1522
+ // @ts-ignore
1523
+ _this4.encodeParam("uploadId", params.uploadId)).replace("{".concat("uploadPartIndex", "}"),
1524
+ // @ts-ignore
1525
+ _this4.encodeParam("uploadPartIndex", params.uploadPartIndex)),
1526
+ method: "PUT",
1527
+ headers: headers,
1528
+ query: query,
1529
+ body: params.completeUploadPartRequest
1530
+ }, undefined, [][0]), function (response) {
1531
+ return UploadApi_await(new VoidApiResponse(response).value());
1532
+ });
1533
+ } catch (e) {
1534
+ return Promise.reject(e);
1535
+ }
1536
+ }
1537
+ /**
1538
+ * Gets a remaining upload part for a multipart file upload.
1539
+ */
1540
+ }, {
1541
+ key: "getUploadPart",
1542
+ value: function getUploadPart(params) {
1543
+ try {
1544
+ var _this6 = this;
1545
+ var query = {};
1546
+ var headers = {};
1547
+ return UploadApi_await(_this6.request({
1548
+ path: "/v2/accounts/{accountId}/uploads/{uploadId}/parts/{uploadPartIndex}".replace("{".concat("accountId", "}"),
1549
+ // @ts-ignore
1550
+ _this6.encodeParam("accountId", params.accountId)).replace("{".concat("uploadId", "}"),
1551
+ // @ts-ignore
1552
+ _this6.encodeParam("uploadId", params.uploadId)).replace("{".concat("uploadPartIndex", "}"),
1553
+ // @ts-ignore
1554
+ _this6.encodeParam("uploadPartIndex", params.uploadPartIndex)),
1555
+ method: "GET",
1556
+ headers: headers,
1557
+ query: query
1558
+ }, undefined, [][0]), function (response) {
1559
+ return UploadApi_await(new JSONApiResponse(response).value());
1560
+ });
1561
+ } catch (e) {
1562
+ return Promise.reject(e);
1563
+ }
1564
+ }
1565
+ /**
1566
+ * Lists the remaining upload parts for a multipart file upload. An empty array is returned when the upload is complete.
1567
+ */
1568
+ }, {
1569
+ key: "listUploadParts",
1570
+ value: function listUploadParts(params) {
1571
+ try {
1572
+ var _this8 = this;
1573
+ var query = {};
1574
+ var headers = {};
1575
+ return UploadApi_await(_this8.request({
1576
+ path: "/v2/accounts/{accountId}/uploads/{uploadId}/parts".replace("{".concat("accountId", "}"),
1577
+ // @ts-ignore
1578
+ _this8.encodeParam("accountId", params.accountId)).replace("{".concat("uploadId", "}"),
1579
+ // @ts-ignore
1580
+ _this8.encodeParam("uploadId", params.uploadId)),
1581
+ method: "GET",
1582
+ headers: headers,
1583
+ query: query
1584
+ }, undefined, [][0]), function (response) {
1585
+ return UploadApi_await(new JSONApiResponse(response).value());
1586
+ });
1587
+ } catch (e) {
1588
+ return Promise.reject(e);
1589
+ }
1590
+ }
1591
+ /**
1592
+ * Upload from a URL with a single HTTP request:
1593
+ */
1594
+ }, {
1595
+ key: "uploadFromUrl",
1596
+ value: function uploadFromUrl(params) {
1597
+ try {
1598
+ var _this10 = this;
1599
+ var query = {};
1600
+ var headers = {};
1601
+ headers["Content-Type"] = "application/json";
1602
+ return UploadApi_await(_this10.request({
1603
+ path: "/v2/accounts/{accountId}/uploads/url".replace("{".concat("accountId", "}"),
1604
+ // @ts-ignore
1605
+ _this10.encodeParam("accountId", params.accountId)),
1606
+ method: "POST",
1607
+ headers: headers,
1608
+ query: query,
1609
+ body: params.uploadFromUrlRequest
1610
+ }, undefined, [][0]), function (response) {
1611
+ return UploadApi_await(new JSONApiResponse(response).value());
1612
+ });
1613
+ } catch (e) {
1614
+ return Promise.reject(e);
1615
+ }
1616
+ }
1617
+ }]);
1618
+ return UploadApi;
1619
+ }(BaseAPI);
1620
+ ;// CONCATENATED MODULE: ./src/public/shared/generated/apis/index.ts
1621
+ /* tslint:disable */
1622
+ /* eslint-disable */
1623
+
1624
+
1625
+
1626
+
1627
+ ;// CONCATENATED MODULE: ./src/public/shared/generated/index.ts
1628
+ /* tslint:disable */
1629
+ /* eslint-disable */
1630
+
1631
+
1632
+
1633
+ ;// CONCATENATED MODULE: ./src/public/shared/CommonTypes.ts
1634
+ /**
1635
+ * Workaround for tsc aliases, where we cannot export implementation-less libs in our dists.
1636
+ */
1637
+ var CommonTypesNoOp = false;
1638
+ ;// CONCATENATED MODULE: ./src/private/TypeUtils.ts
1639
+ function assertUnreachable(x) {
1640
+ throw new Error("Didn't expect to get here: ".concat(JSON.stringify(x)));
1641
+ }
1642
+ function isDefinedEntry(object) {
1643
+ return object[1] !== undefined && object[1] !== null;
1644
+ }
1645
+ ;// CONCATENATED MODULE: ./src/public/shared/UrlBuilder.ts
1646
+ 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); }
1647
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
1648
+ 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."); }
1649
+ 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; } }
1650
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
1651
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
1652
+ 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."); }
1653
+ 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); }
1654
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
1655
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
1656
+ 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; }
1657
+ function UrlBuilder_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1658
+ 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); } }
1659
+ 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; }
1660
+ function UrlBuilder_toPropertyKey(arg) { var key = UrlBuilder_toPrimitive(arg, "string"); return UrlBuilder_typeof(key) === "symbol" ? key : String(key); }
1661
+ 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); }
1662
+
1663
+
1664
+ var UrlBuilder = /*#__PURE__*/function () {
1665
+ function UrlBuilder(config) {
1666
+ UrlBuilder_classCallCheck(this, UrlBuilder);
1667
+ var _a;
1668
+ this.cdnUrl = (_a = config === null || config === void 0 ? void 0 : config.cdnUrl) !== null && _a !== void 0 ? _a : BytescaleApiClientConfigUtils.defaultCdnUrl;
1669
+ }
1670
+ /**
1671
+ * Builds a URL to either a raw file or a transformed file.
1672
+ *
1673
+ * Example 1) Getting a publicly-accessible raw file URL:
1674
+ *
1675
+ * new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg" })
1676
+ *
1677
+ * Example 2) Getting a publicly-accessible image URL, resized to 500x500:
1678
+ *
1679
+ * new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "image", params: { w: 500, h: 500, fit: "crop" } } } })
1680
+ *
1681
+ * Example 3) Getting a privately-accessible image URL, resized to 500x500 (requires 'AuthManager.beginAuthSession' to be called before accessing the URL):
1682
+ *
1683
+ * new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "image", params: { w: 500, h: 500, fit: "crop" } }, auth: true } })
1684
+ *
1685
+ * Example 4) Getting a publicly-accessible image URL, resized using a transformation preset called "thumbnail" that was created manually in the Bytescale Dashboard:
1686
+ *
1687
+ * new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "preset", preset: "thumbnail" } } })
1688
+ */
1689
+ UrlBuilder_createClass(UrlBuilder, [{
1690
+ key: "url",
1691
+ value: function url(params) {
1692
+ var _a;
1693
+ return ((_a = params.options) === null || _a === void 0 ? void 0 : _a.transformation) === undefined ? this.raw(params) : this.transformation(params, params.options);
1694
+ }
1695
+ }, {
1696
+ key: "raw",
1697
+ value: function raw(params) {
1698
+ var _a;
1699
+ var baseUrl = this.getBaseUrl(params, "raw");
1700
+ var commonParams = this.getCommonQueryParams((_a = params.options) !== null && _a !== void 0 ? _a : {});
1701
+ return this.addQueryParams(baseUrl, commonParams);
1702
+ }
1703
+ }, {
1704
+ key: "transformation",
1705
+ value: function transformation(params, trans) {
1706
+ var _a;
1707
+ var baseUrl = this.getBaseUrl(params, trans.transformation === "preset" ? trans.transformationPreset : trans.transformation);
1708
+ var transParams = trans.transformation === "preset" ? [] : this.getTransformationParams(trans);
1709
+ var commonParams = this.getCommonQueryParams((_a = params.options) !== null && _a !== void 0 ? _a : {});
1710
+ var transCommonParams = this.getCommonTransformationQueryParams(trans);
1711
+ // This format puts "artifact" at the end, which isn't required, but is convention.
1712
+ return this.addQueryParams(baseUrl, [].concat(_toConsumableArray(transParams), _toConsumableArray(commonParams), _toConsumableArray(transCommonParams)));
1713
+ }
1714
+ }, {
1715
+ key: "getBaseUrl",
1716
+ value: function getBaseUrl(params, prefix) {
1717
+ return "".concat(this.cdnUrl, "/").concat(params.accountId, "/").concat(prefix).concat(params.filePath);
1718
+ }
1719
+ }, {
1720
+ key: "getCommonTransformationQueryParams",
1721
+ value: function getCommonTransformationQueryParams(trans) {
1722
+ return this.makeQueryParams(["cachePermanently", "large", "artifact"], {
1723
+ cachePermanently: "cache_perm"
1724
+ })(trans);
1725
+ }
1726
+ }, {
1727
+ key: "getCommonQueryParams",
1728
+ value: function getCommonQueryParams(params) {
1729
+ return this.makeQueryParams(["auth", "cache", "cacheTtl", "version", "forceDownloadPrompt"], {
1730
+ cacheTtl: "cache_ttl",
1731
+ forceDownloadPrompt: "download"
1732
+ })(params);
1733
+ }
1734
+ }, {
1735
+ key: "makeQueryParams",
1736
+ value: function makeQueryParams(keys, keyOverrides) {
1737
+ return function (data) {
1738
+ var result = [];
1739
+ keys.forEach(function (key) {
1740
+ var _a;
1741
+ var value = data[key];
1742
+ if (value !== undefined) {
1743
+ result.push([(_a = keyOverrides[key]) !== null && _a !== void 0 ? _a : key, value.toString()]);
1744
+ }
1745
+ });
1746
+ return result;
1747
+ };
1748
+ }
1749
+ }, {
1750
+ key: "getTransformationParams",
1751
+ value: function getTransformationParams(trans) {
1752
+ var params = trans.transformationParams;
1753
+ if (params === undefined) {
1754
+ return [];
1755
+ }
1756
+ var serializeObj = function serializeObj(obj) {
1757
+ return Object.entries(obj).filter(isDefinedEntry).map(function (_ref) {
1758
+ var _ref2 = _slicedToArray(_ref, 2),
1759
+ key = _ref2[0],
1760
+ value = _ref2[1];
1761
+ return [key, value.toString()];
1762
+ });
1763
+ };
1764
+ return Array.isArray(params) ? params.flatMap(serializeObj) : serializeObj(params);
1765
+ }
1766
+ }, {
1767
+ key: "addQueryParams",
1768
+ value: function addQueryParams(baseUrl, params) {
1769
+ if (params.length === 0) {
1770
+ return baseUrl;
1771
+ }
1772
+ return "".concat(baseUrl, "?").concat(params.map(function (_ref3) {
1773
+ var _ref4 = _slicedToArray(_ref3, 2),
1774
+ key = _ref4[0],
1775
+ value = _ref4[1];
1776
+ return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(value));
1777
+ }).join("&"));
1778
+ }
1779
+ }]);
1780
+ return UrlBuilder;
1781
+ }();
1782
+ ;// CONCATENATED MODULE: ./src/public/shared/UrlBuilderTypes.ts
1783
+ /**
1784
+ * Workaround for tsc aliases, where we cannot export implementation-less libs in our dists.
1785
+ */
1786
+ var UrlBuilderTypesNoOp = false;
1787
+ ;// CONCATENATED MODULE: ./src/public/shared/index.ts
1788
+
1789
+
1790
+
1791
+
1792
+ ;// CONCATENATED MODULE: ./src/private/UploadManagerBase.ts
1793
+ 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); }
1794
+ function _async(f) {
1795
+ return function () {
1796
+ for (var args = [], i = 0; i < arguments.length; i++) {
1797
+ args[i] = arguments[i];
1798
+ }
1799
+ try {
1800
+ return Promise.resolve(f.apply(this, args));
1801
+ } catch (e) {
1802
+ return Promise.reject(e);
1803
+ }
1804
+ };
1805
+ }
1806
+ function _invokeIgnored(body) {
1807
+ var result = body();
1808
+ if (result && result.then) {
1809
+ return result.then(UploadManagerBase_empty);
1810
+ }
1811
+ }
1812
+ function UploadManagerBase_settle(pact, state, value) {
1813
+ if (!pact.s) {
1814
+ if (value instanceof UploadManagerBase_Pact) {
1815
+ if (value.s) {
1816
+ if (state & 1) {
1817
+ state = value.s;
1818
+ }
1819
+ value = value.v;
1820
+ } else {
1821
+ value.o = UploadManagerBase_settle.bind(null, pact, state);
1822
+ return;
1823
+ }
1824
+ }
1825
+ if (value && value.then) {
1826
+ value.then(UploadManagerBase_settle.bind(null, pact, state), UploadManagerBase_settle.bind(null, pact, 2));
1827
+ return;
1828
+ }
1829
+ pact.s = state;
1830
+ pact.v = value;
1831
+ var observer = pact.o;
1832
+ if (observer) {
1833
+ observer(pact);
1834
+ }
1835
+ }
1836
+ }
1837
+ var UploadManagerBase_Pact = /*#__PURE__*/function () {
1838
+ function _Pact() {}
1839
+ _Pact.prototype.then = function (onFulfilled, onRejected) {
1840
+ var result = new _Pact();
1841
+ var state = this.s;
1842
+ if (state) {
1843
+ var callback = state & 1 ? onFulfilled : onRejected;
1844
+ if (callback) {
1845
+ try {
1846
+ UploadManagerBase_settle(result, 1, callback(this.v));
1847
+ } catch (e) {
1848
+ UploadManagerBase_settle(result, 2, e);
1849
+ }
1850
+ return result;
1851
+ } else {
1852
+ return this;
1853
+ }
1854
+ }
1855
+ this.o = function (_this) {
1856
+ try {
1857
+ var value = _this.v;
1858
+ if (_this.s & 1) {
1859
+ UploadManagerBase_settle(result, 1, onFulfilled ? onFulfilled(value) : value);
1860
+ } else if (onRejected) {
1861
+ UploadManagerBase_settle(result, 1, onRejected(value));
1862
+ } else {
1863
+ UploadManagerBase_settle(result, 2, value);
1864
+ }
1865
+ } catch (e) {
1866
+ UploadManagerBase_settle(result, 2, e);
1867
+ }
1868
+ };
1869
+ return result;
1870
+ };
1871
+ return _Pact;
1872
+ }();
1873
+ function UploadManagerBase_isSettledPact(thenable) {
1874
+ return thenable instanceof UploadManagerBase_Pact && thenable.s & 1;
1875
+ }
1876
+ function UploadManagerBase_for(test, update, body) {
1877
+ var stage;
1878
+ for (;;) {
1879
+ var shouldContinue = test();
1880
+ if (UploadManagerBase_isSettledPact(shouldContinue)) {
1881
+ shouldContinue = shouldContinue.v;
1882
+ }
1883
+ if (!shouldContinue) {
1884
+ return result;
1885
+ }
1886
+ if (shouldContinue.then) {
1887
+ stage = 0;
1888
+ break;
1889
+ }
1890
+ var result = body();
1891
+ if (result && result.then) {
1892
+ if (UploadManagerBase_isSettledPact(result)) {
1893
+ result = result.s;
1894
+ } else {
1895
+ stage = 1;
1896
+ break;
1897
+ }
1898
+ }
1899
+ if (update) {
1900
+ var updateValue = update();
1901
+ if (updateValue && updateValue.then && !UploadManagerBase_isSettledPact(updateValue)) {
1902
+ stage = 2;
1903
+ break;
1904
+ }
1905
+ }
1906
+ }
1907
+ var pact = new UploadManagerBase_Pact();
1908
+ var reject = UploadManagerBase_settle.bind(null, pact, 2);
1909
+ (stage === 0 ? shouldContinue.then(_resumeAfterTest) : stage === 1 ? result.then(_resumeAfterBody) : updateValue.then(_resumeAfterUpdate)).then(void 0, reject);
1910
+ return pact;
1911
+ function _resumeAfterBody(value) {
1912
+ result = value;
1913
+ do {
1914
+ if (update) {
1915
+ updateValue = update();
1916
+ if (updateValue && updateValue.then && !UploadManagerBase_isSettledPact(updateValue)) {
1917
+ updateValue.then(_resumeAfterUpdate).then(void 0, reject);
1918
+ return;
1919
+ }
1920
+ }
1921
+ shouldContinue = test();
1922
+ if (!shouldContinue || UploadManagerBase_isSettledPact(shouldContinue) && !shouldContinue.v) {
1923
+ UploadManagerBase_settle(pact, 1, result);
1924
+ return;
1925
+ }
1926
+ if (shouldContinue.then) {
1927
+ shouldContinue.then(_resumeAfterTest).then(void 0, reject);
1928
+ return;
1929
+ }
1930
+ result = body();
1931
+ if (UploadManagerBase_isSettledPact(result)) {
1932
+ result = result.v;
1933
+ }
1934
+ } while (!result || !result.then);
1935
+ result.then(_resumeAfterBody).then(void 0, reject);
1936
+ }
1937
+ function _resumeAfterTest(shouldContinue) {
1938
+ if (shouldContinue) {
1939
+ result = body();
1940
+ if (result && result.then) {
1941
+ result.then(_resumeAfterBody).then(void 0, reject);
1942
+ } else {
1943
+ _resumeAfterBody(result);
1944
+ }
1945
+ } else {
1946
+ UploadManagerBase_settle(pact, 1, result);
1947
+ }
1948
+ }
1949
+ function _resumeAfterUpdate() {
1950
+ if (shouldContinue = test()) {
1951
+ if (shouldContinue.then) {
1952
+ shouldContinue.then(_resumeAfterTest).then(void 0, reject);
1953
+ } else {
1954
+ _resumeAfterTest(shouldContinue);
1955
+ }
1956
+ } else {
1957
+ UploadManagerBase_settle(pact, 1, result);
1958
+ }
1959
+ }
1960
+ }
1961
+ function _continueIgnored(value) {
1962
+ if (value && value.then) {
1963
+ return value.then(UploadManagerBase_empty);
1964
+ }
1965
+ }
1966
+ function UploadManagerBase_toConsumableArray(arr) { return UploadManagerBase_arrayWithoutHoles(arr) || UploadManagerBase_iterableToArray(arr) || UploadManagerBase_unsupportedIterableToArray(arr) || UploadManagerBase_nonIterableSpread(); }
1967
+ 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."); }
1968
+ 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); }
1969
+ function UploadManagerBase_iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
1970
+ function UploadManagerBase_arrayWithoutHoles(arr) { if (Array.isArray(arr)) return UploadManagerBase_arrayLikeToArray(arr); }
1971
+ 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; }
1972
+ function UploadManagerBase_empty() {}
1973
+ function UploadManagerBase_awaitIgnored(value, direct) {
1974
+ if (!direct) {
1975
+ return value && value.then ? value.then(UploadManagerBase_empty) : Promise.resolve();
1976
+ }
1977
+ }
1978
+ function UploadManagerBase_await(value, then, direct) {
1979
+ if (direct) {
1980
+ return then ? then(value) : value;
1981
+ }
1982
+ if (!value || !value.then) {
1983
+ value = Promise.resolve(value);
1984
+ }
1985
+ return then ? value.then(then) : value;
1986
+ }
1987
+ function UploadManagerBase_rethrow(thrown, value) {
1988
+ if (thrown) throw value;
1989
+ return value;
1990
+ }
1991
+ function UploadManagerBase_finallyRethrows(body, finalizer) {
1992
+ try {
1993
+ var result = body();
1994
+ } catch (e) {
1995
+ return finalizer(true, e);
1996
+ }
1997
+ if (result && result.then) {
1998
+ return result.then(finalizer.bind(null, false), finalizer.bind(null, true));
1999
+ }
2000
+ return finalizer(false, result);
2001
+ }
2002
+ function UploadManagerBase_continue(value, then) {
2003
+ return value && value.then ? value.then(then) : then(value);
2004
+ }
2005
+ function UploadManagerBase_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2006
+ 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); } }
2007
+ 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; }
2008
+ function UploadManagerBase_toPropertyKey(arg) { var key = UploadManagerBase_toPrimitive(arg, "string"); return UploadManagerBase_typeof(key) === "symbol" ? key : String(key); }
2009
+ 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); }
2010
+
2011
+ /**
2012
+ * Methods common to UploadManagerNode and UploadManagerBrowser.
2013
+ */
2014
+ var UploadManagerBase = /*#__PURE__*/function () {
2015
+ function UploadManagerBase(config) {
2016
+ UploadManagerBase_classCallCheck(this, UploadManagerBase);
2017
+ this.config = config;
2018
+ this.stringMimeType = "text/plain";
2019
+ this.defaultMaxConcurrentUploadParts = 4;
2020
+ this.intervalMs = 500;
2021
+ this.uploadApi = new UploadApi(config);
2022
+ this.accountId = BytescaleApiClientConfigUtils.getAccountId(config);
2023
+ }
2024
+ UploadManagerBase_createClass(UploadManagerBase, [{
2025
+ key: "upload",
2026
+ value: function upload(request) {
2027
+ try {
2028
+ var _this2 = this;
2029
+ _this2.assertNotCancelled(request);
2030
+ var source = _this2.processUploadSource(request.data);
2031
+ var preUploadInfo = _this2.getPreUploadInfo(request, source);
2032
+ var onProgress = _this2.makeProgressCallback(request, preUploadInfo.size);
2033
+ var init = _this2.preUpload(source);
2034
+ // Raise initial progress event SYNCHRONOUSLY.
2035
+ onProgress(0);
2036
+ return UploadManagerBase_await(_this2.beginUpload(request, preUploadInfo), function (uploadInfo) {
2037
+ var partCount = uploadInfo.uploadParts.count;
2038
+ var parts = UploadManagerBase_toConsumableArray(Array(partCount).keys());
2039
+ var _this2$makeCancellati = _this2.makeCancellationMethods(),
2040
+ cancel = _this2$makeCancellati.cancel,
2041
+ addCancellationHandler = _this2$makeCancellati.addCancellationHandler;
2042
+ var intervalHandle = setInterval(_this2.onIntervalTick(request, cancel), _this2.intervalMs);
2043
+ return UploadManagerBase_continue(UploadManagerBase_finallyRethrows(function () {
2044
+ return UploadManagerBase_await(_this2.mapAsync(parts, preUploadInfo.maxConcurrentUploadParts, _async(function (part) {
2045
+ return _this2.uploadPart(request, source, part, uploadInfo, onProgress, addCancellationHandler);
2046
+ })), function () {
2047
+ return UploadManagerBase_awaitIgnored(_this2.postUpload(init));
2048
+ });
2049
+ }, function (_wasThrown, _result) {
2050
+ clearInterval(intervalHandle);
2051
+ return UploadManagerBase_rethrow(_wasThrown, _result);
2052
+ }), function () {
2053
+ return uploadInfo.file;
2054
+ });
2055
+ });
2056
+ } catch (e) {
2057
+ return Promise.reject(e);
2058
+ }
2059
+ }
2060
+ }, {
2061
+ key: "getBlobInfo",
2062
+ value: function getBlobInfo(_ref) {
2063
+ var _ref$value = _ref.value,
2064
+ name = _ref$value.name,
2065
+ size = _ref$value.size,
2066
+ type = _ref$value.type;
2067
+ return {
2068
+ mime: type,
2069
+ size: size,
2070
+ originalFileName: name,
2071
+ maxConcurrentUploadParts: undefined
2072
+ };
2073
+ }
2074
+ }, {
2075
+ key: "onIntervalTick",
2076
+ value: function onIntervalTick(request, cancel) {
2077
+ var _this3 = this;
2078
+ return function () {
2079
+ if (_this3.isCancelled(request)) {
2080
+ cancel();
2081
+ }
2082
+ };
2083
+ }
2084
+ }, {
2085
+ key: "makeCancellationMethods",
2086
+ value: function makeCancellationMethods() {
2087
+ var cancellationHandlers = [];
2088
+ var addCancellationHandler = function addCancellationHandler(ca) {
2089
+ cancellationHandlers.push(ca);
2090
+ };
2091
+ var cancel = function cancel() {
2092
+ return cancellationHandlers.forEach(function (x) {
2093
+ return x();
2094
+ });
2095
+ };
2096
+ return {
2097
+ cancel: cancel,
2098
+ addCancellationHandler: addCancellationHandler
2099
+ };
2100
+ }
2101
+ }, {
2102
+ key: "makeProgressCallback",
2103
+ value: function makeProgressCallback(request, bytesTotal) {
2104
+ var onProgress = request.onProgress;
2105
+ if (onProgress === undefined) {
2106
+ return function () {};
2107
+ }
2108
+ var bytesSent = 0;
2109
+ return function (bytesSentDelta) {
2110
+ bytesSent += bytesSentDelta;
2111
+ onProgress({
2112
+ bytesTotal: bytesTotal,
2113
+ bytesSent: bytesSent,
2114
+ progress: Math.round(bytesSent / bytesTotal * 100)
2115
+ });
2116
+ };
2117
+ }
2118
+ }, {
2119
+ key: "assertNotCancelled",
2120
+ value: function assertNotCancelled(request) {
2121
+ if (this.isCancelled(request)) {
2122
+ throw new CancelledError();
2123
+ }
2124
+ }
2125
+ }, {
2126
+ key: "isCancelled",
2127
+ value: function isCancelled(request) {
2128
+ var _a;
2129
+ return ((_a = request.cancellationToken) === null || _a === void 0 ? void 0 : _a.isCancelled) === true;
2130
+ }
2131
+ }, {
2132
+ key: "beginUpload",
2133
+ value: function beginUpload(request, _ref2) {
2134
+ var size = _ref2.size,
2135
+ mime = _ref2.mime,
2136
+ originalFileName = _ref2.originalFileName;
2137
+ try {
2138
+ var _this5 = this;
2139
+ return UploadManagerBase_await(_this5.uploadApi.beginMultipartUpload({
2140
+ accountId: _this5.accountId,
2141
+ beginMultipartUploadRequest: {
2142
+ metadata: request.metadata,
2143
+ mime: mime,
2144
+ originalFileName: originalFileName,
2145
+ path: request.path,
2146
+ protocol: "1.1",
2147
+ size: size,
2148
+ tags: request.tags
2149
+ }
2150
+ }));
2151
+ } catch (e) {
2152
+ return Promise.reject(e);
2153
+ }
2154
+ }
2155
+ }, {
2156
+ key: "uploadPart",
2157
+ value: function uploadPart(request, source, partIndex, uploadInfo, onProgress, addCancellationHandler) {
2158
+ try {
2159
+ var _this7 = this;
2160
+ _this7.assertNotCancelled(request);
2161
+ return UploadManagerBase_await(_this7.getUploadPart(partIndex, uploadInfo), function (part) {
2162
+ _this7.assertNotCancelled(request);
2163
+ return UploadManagerBase_await(_this7.putUploadPart(part, source, onProgress, addCancellationHandler), function (etag) {
2164
+ _this7.assertNotCancelled(request);
2165
+ return UploadManagerBase_awaitIgnored(_this7.uploadApi.completeUploadPart({
2166
+ accountId: _this7.accountId,
2167
+ uploadId: uploadInfo.uploadId,
2168
+ uploadPartIndex: partIndex,
2169
+ completeUploadPartRequest: {
2170
+ etag: etag
2171
+ }
2172
+ }));
2173
+ });
2174
+ });
2175
+ } catch (e) {
2176
+ return Promise.reject(e);
2177
+ }
2178
+ }
2179
+ /**
2180
+ * Returns etag for the part.
2181
+ */
2182
+ }, {
2183
+ key: "putUploadPart",
2184
+ value: function putUploadPart(part, source, onProgress, addCancellationHandler) {
2185
+ try {
2186
+ var _this9 = this;
2187
+ var contentLength = part.range.inclusiveEnd + 1 - part.range.inclusiveStart;
2188
+ return UploadManagerBase_await(_this9.doPutUploadPart(part, contentLength, source, onProgress, addCancellationHandler), function (_ref3) {
2189
+ var status = _ref3.status,
2190
+ etag = _ref3.etag;
2191
+ if (Math.floor(status / 100) !== 2) {
2192
+ throw new Error("Failed to upload part (".concat(status, ")."));
2193
+ }
2194
+ if (etag === undefined) {
2195
+ throw new Error("No 'etag' response header found in upload part response.");
2196
+ }
2197
+ return etag;
2198
+ });
2199
+ } catch (e) {
2200
+ return Promise.reject(e);
2201
+ }
2202
+ }
2203
+ }, {
2204
+ key: "getUploadPart",
2205
+ value: function getUploadPart(partIndex, uploadInfo) {
2206
+ try {
2207
+ var _this11 = this;
2208
+ if (partIndex === 0) {
2209
+ return uploadInfo.uploadParts.first;
2210
+ }
2211
+ return UploadManagerBase_await(_this11.uploadApi.getUploadPart({
2212
+ uploadId: uploadInfo.uploadId,
2213
+ accountId: _this11.accountId,
2214
+ uploadPartIndex: partIndex
2215
+ }));
2216
+ } catch (e) {
2217
+ return Promise.reject(e);
2218
+ }
2219
+ }
2220
+ }, {
2221
+ key: "getPreUploadInfo",
2222
+ value: function getPreUploadInfo(request, source) {
2223
+ var _a, _b, _c;
2224
+ var partial = this.getPreUploadInfoPartial(request, source);
2225
+ return {
2226
+ maxConcurrentUploadParts: (_a = partial.maxConcurrentUploadParts) !== null && _a !== void 0 ? _a : this.defaultMaxConcurrentUploadParts,
2227
+ originalFileName: (_b = request.originalFileName) !== null && _b !== void 0 ? _b : partial.originalFileName,
2228
+ mime: (_c = request.mime) !== null && _c !== void 0 ? _c : partial.mime,
2229
+ size: partial.size
2230
+ };
2231
+ }
2232
+ }, {
2233
+ key: "mapAsync",
2234
+ value: function mapAsync(items, concurrency, callback) {
2235
+ try {
2236
+ var workQueue = UploadManagerBase_toConsumableArray(items);
2237
+ return UploadManagerBase_awaitIgnored(Promise.all(UploadManagerBase_toConsumableArray(Array(concurrency).keys()).map(_async(function () {
2238
+ return _continueIgnored(UploadManagerBase_for(function () {
2239
+ return workQueue.length > 0;
2240
+ }, void 0, function () {
2241
+ var work = workQueue.shift(); // IMPORTANT: use 'shift' instead of 'pop' to ensure 'items' are processed in order when 'concurrency = 1'.
2242
+ return _invokeIgnored(function () {
2243
+ if (work !== undefined) {
2244
+ return UploadManagerBase_awaitIgnored(callback(work));
2245
+ }
2246
+ });
2247
+ }));
2248
+ }))));
2249
+ } catch (e) {
2250
+ return Promise.reject(e);
2251
+ }
2252
+ }
2253
+ }]);
2254
+ return UploadManagerBase;
2255
+ }();
2256
+ ;// CONCATENATED MODULE: ./src/private/UploadManagerBrowserWorkerBase.ts
2257
+ 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); }
2258
+ function UploadManagerBrowserWorkerBase_await(value, then, direct) {
2259
+ if (direct) {
2260
+ return then ? then(value) : value;
2261
+ }
2262
+ if (!value || !value.then) {
2263
+ value = Promise.resolve(value);
2264
+ }
2265
+ return then ? value.then(then) : value;
2266
+ }
2267
+ function UploadManagerBrowserWorkerBase_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2268
+ 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); } }
2269
+ 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; }
2270
+ function UploadManagerBrowserWorkerBase_toPropertyKey(arg) { var key = UploadManagerBrowserWorkerBase_toPrimitive(arg, "string"); return UploadManagerBrowserWorkerBase_typeof(key) === "symbol" ? key : String(key); }
2271
+ 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); }
2272
+ 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); }
2273
+ 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); }
2274
+ 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); }; }
2275
+ 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); }
2276
+ function UploadManagerBrowserWorkerBase_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
2277
+ 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; } }
2278
+ function UploadManagerBrowserWorkerBase_getPrototypeOf(o) { UploadManagerBrowserWorkerBase_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return UploadManagerBrowserWorkerBase_getPrototypeOf(o); }
2279
+
2280
+
2281
+ /**
2282
+ * The "browser" and "worker" runtimes support the same input types, but the former uses XHR and the latter uses Fetch.
2283
+ */
2284
+ var UploadManagerBrowserWorkerBase = /*#__PURE__*/function (_UploadManagerBase) {
2285
+ UploadManagerBrowserWorkerBase_inherits(UploadManagerBrowserWorkerBase, _UploadManagerBase);
2286
+ var _super = UploadManagerBrowserWorkerBase_createSuper(UploadManagerBrowserWorkerBase);
2287
+ function UploadManagerBrowserWorkerBase() {
2288
+ UploadManagerBrowserWorkerBase_classCallCheck(this, UploadManagerBrowserWorkerBase);
2289
+ return _super.apply(this, arguments);
2290
+ }
2291
+ UploadManagerBrowserWorkerBase_createClass(UploadManagerBrowserWorkerBase, [{
2292
+ key: "processUploadSource",
2293
+ value: function processUploadSource(data) {
2294
+ if (typeof data === "string") {
2295
+ // 'Blob' must be from 'global' (i.e. not imported) as we're in a browser context here, so is globally available.
2296
+ return {
2297
+ type: "Blob",
2298
+ value: new Blob([data], {
2299
+ type: this.stringMimeType
2300
+ })
2301
+ };
2302
+ }
2303
+ if (data.byteLength !== undefined) {
2304
+ return {
2305
+ type: "ArrayBuffer",
2306
+ value: data
2307
+ };
2308
+ }
2309
+ if (data.size !== undefined) {
2310
+ return {
2311
+ type: "Blob",
2312
+ value: data
2313
+ };
2314
+ }
2315
+ throw new Error("Unsupported type for 'data' parameter. Please provide a String, Blob, ArrayBuffer, or File object (from a file input element).");
2316
+ }
2317
+ }, {
2318
+ key: "getPreUploadInfoPartial",
2319
+ value: function getPreUploadInfoPartial(_request, data) {
2320
+ switch (data.type) {
2321
+ case "Blob":
2322
+ return this.getBlobInfo(data);
2323
+ case "ArrayBuffer":
2324
+ return {
2325
+ mime: undefined,
2326
+ size: data.value.byteLength,
2327
+ originalFileName: undefined,
2328
+ maxConcurrentUploadParts: undefined
2329
+ };
2330
+ default:
2331
+ assertUnreachable(data);
2332
+ }
2333
+ }
2334
+ }, {
2335
+ key: "preUpload",
2336
+ value: function preUpload(_source) {
2337
+ return undefined;
2338
+ }
2339
+ }, {
2340
+ key: "postUpload",
2341
+ value: function postUpload(_init) {
2342
+ return UploadManagerBrowserWorkerBase_await();
2343
+ } // NO-OP.
2344
+ }, {
2345
+ key: "getRequestBody",
2346
+ value: function getRequestBody(part, blob) {
2347
+ return part.range.inclusiveEnd === -1 ? new Blob() : blob.value.slice(part.range.inclusiveStart, part.range.inclusiveEnd + 1);
2348
+ }
2349
+ }]);
2350
+ return UploadManagerBrowserWorkerBase;
2351
+ }(UploadManagerBase);
2352
+ ;// CONCATENATED MODULE: ./src/public/browser/UploadManagerBrowser.ts
2353
+ 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); }
2354
+ function UploadManagerBrowser_await(value, then, direct) {
2355
+ if (direct) {
2356
+ return then ? then(value) : value;
2357
+ }
2358
+ if (!value || !value.then) {
2359
+ value = Promise.resolve(value);
2360
+ }
2361
+ return then ? value.then(then) : value;
2362
+ }
2363
+ function UploadManagerBrowser_rethrow(thrown, value) {
2364
+ if (thrown) throw value;
2365
+ return value;
2366
+ }
2367
+ function UploadManagerBrowser_finallyRethrows(body, finalizer) {
2368
+ try {
2369
+ var result = body();
2370
+ } catch (e) {
2371
+ return finalizer(true, e);
2372
+ }
2373
+ if (result && result.then) {
2374
+ return result.then(finalizer.bind(null, false), finalizer.bind(null, true));
2375
+ }
2376
+ return finalizer(false, result);
2377
+ }
2378
+ function UploadManagerBrowser_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2379
+ 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); } }
2380
+ 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; }
2381
+ function UploadManagerBrowser_toPropertyKey(arg) { var key = UploadManagerBrowser_toPrimitive(arg, "string"); return UploadManagerBrowser_typeof(key) === "symbol" ? key : String(key); }
2382
+ 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); }
2383
+ 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); }
2384
+ 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); }
2385
+ 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); }; }
2386
+ 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); }
2387
+ function UploadManagerBrowser_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
2388
+ 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; } }
2389
+ function UploadManagerBrowser_getPrototypeOf(o) { UploadManagerBrowser_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return UploadManagerBrowser_getPrototypeOf(o); }
2390
+
2391
+
2392
+ var UploadManager = /*#__PURE__*/function (_UploadManagerBrowser) {
2393
+ UploadManagerBrowser_inherits(UploadManager, _UploadManagerBrowser);
2394
+ var _super = UploadManagerBrowser_createSuper(UploadManager);
2395
+ function UploadManager() {
2396
+ UploadManagerBrowser_classCallCheck(this, UploadManager);
2397
+ return _super.apply(this, arguments);
2398
+ }
2399
+ UploadManagerBrowser_createClass(UploadManager, [{
2400
+ key: "doPutUploadPart",
2401
+ value: function doPutUploadPart(part, contentLength, source, onProgress, addCancellationHandler) {
2402
+ try {
2403
+ var _this2 = this;
2404
+ var xhr = new XMLHttpRequest();
2405
+ var pending = true;
2406
+ addCancellationHandler(function () {
2407
+ if (pending) {
2408
+ xhr.abort();
2409
+ }
2410
+ });
2411
+ var lastBytesSent = 0;
2412
+ var setBytesSent = function setBytesSent(newBytesSent) {
2413
+ var delta = newBytesSent - lastBytesSent;
2414
+ lastBytesSent = newBytesSent;
2415
+ onProgress(delta);
2416
+ };
2417
+ return UploadManagerBrowser_finallyRethrows(function () {
2418
+ return UploadManagerBrowser_await(new Promise(function (resolve, reject) {
2419
+ xhr.upload.addEventListener("progress", function (evt) {
2420
+ if (evt.lengthComputable) {
2421
+ setBytesSent(evt.loaded);
2422
+ }
2423
+ }, false);
2424
+ xhr.addEventListener("load", function () {
2425
+ var _a;
2426
+ // Ensure we always report the progress of a finished upload as 100%.
2427
+ setBytesSent(contentLength);
2428
+ var etag = (_a = xhr.getResponseHeader("etag")) !== null && _a !== void 0 ? _a : undefined;
2429
+ resolve({
2430
+ etag: etag,
2431
+ status: xhr.status
2432
+ });
2433
+ });
2434
+ xhr.onabort = function () {
2435
+ return reject(new CancelledError());
2436
+ };
2437
+ xhr.onerror = function () {
2438
+ return reject(new Error("File upload error."));
2439
+ };
2440
+ xhr.ontimeout = function () {
2441
+ return reject(new Error("File upload timeout."));
2442
+ };
2443
+ xhr.open("PUT", part.uploadUrl);
2444
+ xhr.send(_this2.getRequestBody(part, source));
2445
+ }));
2446
+ }, function (_wasThrown, _result) {
2447
+ pending = false;
2448
+ return UploadManagerBrowser_rethrow(_wasThrown, _result);
2449
+ });
2450
+ } catch (e) {
2451
+ return Promise.reject(e);
2452
+ }
2453
+ }
2454
+ }]);
2455
+ return UploadManager;
2456
+ }(UploadManagerBrowserWorkerBase);
2457
+ ;// CONCATENATED MODULE: ./src/private/ConsoleUtils.ts
2458
+ 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); }
2459
+ function ConsoleUtils_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2460
+ 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); } }
2461
+ 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; }
2462
+ function ConsoleUtils_toPropertyKey(arg) { var key = ConsoleUtils_toPrimitive(arg, "string"); return ConsoleUtils_typeof(key) === "symbol" ? key : String(key); }
2463
+ 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); }
2464
+ var ConsoleUtils = /*#__PURE__*/function () {
2465
+ function ConsoleUtils() {
2466
+ ConsoleUtils_classCallCheck(this, ConsoleUtils);
2467
+ }
2468
+ ConsoleUtils_createClass(ConsoleUtils, null, [{
2469
+ key: "error",
2470
+ value: function error(message) {
2471
+ console.error(ConsoleUtils.prefix(message));
2472
+ }
2473
+ }, {
2474
+ key: "warn",
2475
+ value: function warn(message) {
2476
+ console.warn(ConsoleUtils.prefix(message));
2477
+ }
2478
+ }, {
2479
+ key: "prefix",
2480
+ value: function prefix(message) {
2481
+ return "[bytescale-sdk] ".concat(message);
2482
+ }
2483
+ }]);
2484
+ return ConsoleUtils;
2485
+ }();
2486
+ ;// CONCATENATED MODULE: ./src/public/browser/AuthManagerBrowser.ts
2487
+ 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); }
2488
+ 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; }
2489
+ function AuthManagerBrowser_empty() {}
2490
+ function AuthManagerBrowser_awaitIgnored(value, direct) {
2491
+ if (!direct) {
2492
+ return value && value.then ? value.then(AuthManagerBrowser_empty) : Promise.resolve();
2493
+ }
2494
+ }
2495
+ function AuthManagerBrowser_await(value, then, direct) {
2496
+ if (direct) {
2497
+ return then ? then(value) : value;
2498
+ }
2499
+ if (!value || !value.then) {
2500
+ value = Promise.resolve(value);
2501
+ }
2502
+ return then ? value.then(then) : value;
2503
+ }
2504
+ function AuthManagerBrowser_async(f) {
2505
+ return function () {
2506
+ for (var args = [], i = 0; i < arguments.length; i++) {
2507
+ args[i] = arguments[i];
2508
+ }
2509
+ try {
2510
+ return Promise.resolve(f.apply(this, args));
2511
+ } catch (e) {
2512
+ return Promise.reject(e);
2513
+ }
2514
+ };
2515
+ }
2516
+ function AuthManagerBrowser_catch(body, recover) {
2517
+ try {
2518
+ var result = body();
2519
+ } catch (e) {
2520
+ return recover(e);
2521
+ }
2522
+ if (result && result.then) {
2523
+ return result.then(void 0, recover);
2524
+ }
2525
+ return result;
2526
+ }
2527
+ function AuthManagerBrowser_rethrow(thrown, value) {
2528
+ if (thrown) throw value;
2529
+ return value;
2530
+ }
2531
+ function AuthManagerBrowser_finallyRethrows(body, finalizer) {
2532
+ try {
2533
+ var result = body();
2534
+ } catch (e) {
2535
+ return finalizer(true, e);
2536
+ }
2537
+ if (result && result.then) {
2538
+ return result.then(finalizer.bind(null, false), finalizer.bind(null, true));
2539
+ }
2540
+ return finalizer(false, result);
2541
+ }
2542
+ function AuthManagerBrowser_continueIgnored(value) {
2543
+ if (value && value.then) {
2544
+ return value.then(AuthManagerBrowser_empty);
2545
+ }
2546
+ }
2547
+ function AuthManagerBrowser_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2548
+ 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); } }
2549
+ 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; }
2550
+ function AuthManagerBrowser_toPropertyKey(arg) { var key = AuthManagerBrowser_toPrimitive(arg, "string"); return AuthManagerBrowser_typeof(key) === "symbol" ? key : String(key); }
2551
+ 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); }
2552
+ function AuthManagerBrowser_inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) AuthManagerBrowser_setPrototypeOf(subClass, superClass); }
2553
+ function AuthManagerBrowser_setPrototypeOf(o, p) { AuthManagerBrowser_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return AuthManagerBrowser_setPrototypeOf(o, p); }
2554
+ function AuthManagerBrowser_createSuper(Derived) { var hasNativeReflectConstruct = AuthManagerBrowser_isNativeReflectConstruct(); return function _createSuperInternal() { var Super = AuthManagerBrowser_getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = AuthManagerBrowser_getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return AuthManagerBrowser_possibleConstructorReturn(this, result); }; }
2555
+ function AuthManagerBrowser_possibleConstructorReturn(self, call) { if (call && (AuthManagerBrowser_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return AuthManagerBrowser_assertThisInitialized(self); }
2556
+ function AuthManagerBrowser_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
2557
+ function AuthManagerBrowser_isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
2558
+ function AuthManagerBrowser_getPrototypeOf(o) { AuthManagerBrowser_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return AuthManagerBrowser_getPrototypeOf(o); }
2559
+
2560
+
2561
+
2562
+ var AuthManager = /*#__PURE__*/function (_BaseAPI) {
2563
+ AuthManagerBrowser_inherits(AuthManager, _BaseAPI);
2564
+ var _super = AuthManagerBrowser_createSuper(AuthManager);
2565
+ function AuthManager(config) {
2566
+ var _this;
2567
+ AuthManagerBrowser_classCallCheck(this, AuthManager);
2568
+ _this = _super.call(this, config);
2569
+ _this.contentType = "content-type";
2570
+ _this.contentTypeJson = "application/json";
2571
+ _this.contentTypeText = "text/plain";
2572
+ _this.minJwtTtlSeconds = 10;
2573
+ _this.maxJwtTtlSeconds = 2147483; // Max value for window.setTimeout is 2147483647ms -- if we go over this, the timeout fires immediately.
2574
+ _this.retryAuthAfterErrorSeconds = 5;
2575
+ _this.refreshBeforeExpirySeconds = 20;
2576
+ var cdnUrl = BytescaleApiClientConfigUtils.getCdnUrl(config);
2577
+ var accountId = BytescaleApiClientConfigUtils.getAccountId(config);
2578
+ _this.accessTokenUrl = "".concat(cdnUrl, "/api/v1/access_tokens/").concat(accountId);
2579
+ _this.authSessionMutex = AuthSessionState.getMutex();
2580
+ return _this;
2581
+ }
2582
+ AuthManagerBrowser_createClass(AuthManager, [{
2583
+ key: "isAuthSessionActive",
2584
+ value: function isAuthSessionActive() {
2585
+ return AuthSessionState.getSession() !== undefined;
2586
+ }
2587
+ }, {
2588
+ key: "beginAuthSession",
2589
+ value: function beginAuthSession(authUrl, authHeaders) {
2590
+ try {
2591
+ var _this3 = this;
2592
+ var newSession = {
2593
+ accessToken: undefined,
2594
+ accessTokenRefreshHandle: undefined,
2595
+ authUrl: authUrl,
2596
+ authHeaders: authHeaders,
2597
+ isActive: true
2598
+ };
2599
+ return AuthManagerBrowser_await(_this3.authSessionMutex.safe(AuthManagerBrowser_async(function () {
2600
+ // We check both 'session' and 'sessionDisposing' here, as we don't want to call 'beginAuthSession' until the session is fully disposed.
2601
+ if (_this3.isAuthSessionActive()) {
2602
+ 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.");
2603
+ }
2604
+ AuthSessionState.setSession(newSession);
2605
+ return AuthManagerBrowser_await();
2606
+ })), function () {
2607
+ // IMPORTANT: must be called outside the above, else re-entrant deadlock will occur.
2608
+ return AuthManagerBrowser_awaitIgnored(_this3.refreshAccessToken(newSession));
2609
+ });
2610
+ } catch (e) {
2611
+ return Promise.reject(e);
2612
+ }
2613
+ }
2614
+ }, {
2615
+ key: "endAuthSession",
2616
+ value: function endAuthSession() {
2617
+ try {
2618
+ var _this5 = this;
2619
+ return AuthManagerBrowser_awaitIgnored(_this5.authSessionMutex.safe(AuthManagerBrowser_async(function () {
2620
+ var session = AuthSessionState.getSession();
2621
+ if (session === undefined) {
2622
+ return;
2623
+ }
2624
+ AuthSessionState.setSession(undefined);
2625
+ session.isActive = false;
2626
+ if (session.accessTokenRefreshHandle !== undefined) {
2627
+ clearTimeout(session.accessTokenRefreshHandle);
2628
+ }
2629
+ return AuthManagerBrowser_awaitIgnored(_this5.deleteAccessToken());
2630
+ })));
2631
+ } catch (e) {
2632
+ return Promise.reject(e);
2633
+ }
2634
+ }
2635
+ }, {
2636
+ key: "refreshAccessToken",
2637
+ value: function refreshAccessToken(session) {
2638
+ try {
2639
+ var _this7 = this;
2640
+ return AuthManagerBrowser_awaitIgnored(_this7.authSessionMutex.safe(AuthManagerBrowser_async(function () {
2641
+ if (!session.isActive) {
2642
+ return;
2643
+ }
2644
+ var timeout = _this7.retryAuthAfterErrorSeconds;
2645
+ return AuthManagerBrowser_continueIgnored(AuthManagerBrowser_finallyRethrows(function () {
2646
+ return AuthManagerBrowser_catch(function () {
2647
+ var _getAccessToken = _this7.getAccessToken,
2648
+ _session$authUrl = session.authUrl;
2649
+ return AuthManagerBrowser_await(session.authHeaders(), function (_session$authHeaders) {
2650
+ return AuthManagerBrowser_await(_getAccessToken.call(_this7, _session$authUrl, _session$authHeaders), function (jwt) {
2651
+ return AuthManagerBrowser_await(_this7.setAccessToken(jwt), function (setTokenResult) {
2652
+ var desiredTtl = setTokenResult.ttlSeconds - _this7.refreshBeforeExpirySeconds;
2653
+ timeout = Math.max(desiredTtl, _this7.minJwtTtlSeconds);
2654
+ if (desiredTtl !== timeout) {
2655
+ ConsoleUtils.warn("JWT expiration is too short: waiting for ".concat(timeout, " seconds before refreshing."));
2656
+ }
2657
+ // 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!
2658
+ timeout = Math.min(timeout, _this7.maxJwtTtlSeconds);
2659
+ session.accessToken = setTokenResult.accessToken;
2660
+ });
2661
+ });
2662
+ });
2663
+ }, function (e) {
2664
+ // Use 'error' instead of 'debug' so that the user sees error messages.
2665
+ ConsoleUtils.error("Error when refreshing access token: ".concat(e));
2666
+ });
2667
+ }, function (_wasThrown, _result) {
2668
+ session.accessTokenRefreshHandle = window.setTimeout(function () {
2669
+ _this7.refreshAccessToken(session).then(function () {}, function (e) {
2670
+ return ConsoleUtils.error("Unexpected error when refreshing access token: ".concat(e));
2671
+ });
2672
+ }, timeout * 1000);
2673
+ return AuthManagerBrowser_rethrow(_wasThrown, _result);
2674
+ }));
2675
+ })));
2676
+ } catch (e) {
2677
+ return Promise.reject(e);
2678
+ }
2679
+ }
2680
+ }, {
2681
+ key: "deleteAccessToken",
2682
+ value: function deleteAccessToken() {
2683
+ try {
2684
+ var _this9 = this;
2685
+ return AuthManagerBrowser_awaitIgnored(_this9.doFetch(_this9.accessTokenUrl, {
2686
+ method: "DELETE",
2687
+ credentials: "include",
2688
+ headers: {}
2689
+ }, true));
2690
+ } catch (e) {
2691
+ return Promise.reject(e);
2692
+ }
2693
+ }
2694
+ }, {
2695
+ key: "setAccessToken",
2696
+ value: function setAccessToken(jwt) {
2697
+ try {
2698
+ var _this11 = this;
2699
+ var request = {
2700
+ accessToken: jwt
2701
+ };
2702
+ return AuthManagerBrowser_await(_this11.doFetch(_this11.accessTokenUrl, {
2703
+ method: "PUT",
2704
+ credentials: "include",
2705
+ headers: AuthManagerBrowser_defineProperty({}, _this11.contentType, _this11.contentTypeJson),
2706
+ body: JSON.stringify(request)
2707
+ }, true), function (response) {
2708
+ return AuthManagerBrowser_await(response.json());
2709
+ });
2710
+ } catch (e) {
2711
+ return Promise.reject(e);
2712
+ }
2713
+ }
2714
+ }, {
2715
+ key: "getAccessToken",
2716
+ value: function getAccessToken(authUrl, headers) {
2717
+ try {
2718
+ var _this13 = this;
2719
+ var endpointName = "Your auth API endpoint";
2720
+ var requiredContentType = _this13.contentTypeText;
2721
+ return AuthManagerBrowser_await(_this13.doFetch(authUrl, {
2722
+ method: "GET",
2723
+ headers: headers
2724
+ }, false), function (result) {
2725
+ if (result.headers.get(_this13.contentType) !== requiredContentType) {
2726
+ throw new Error("".concat(endpointName, " returned an unsupported '").concat(_this13.contentType, "' response header: please return '").concat(requiredContentType, "'."));
2727
+ }
2728
+ return AuthManagerBrowser_await(result.text(), function (jwt) {
2729
+ if (jwt.length === 0) {
2730
+ throw new Error("".concat(endpointName, " returned an empty string. Please return a valid JWT instead."));
2731
+ }
2732
+ if (jwt.trim().length !== jwt.length) {
2733
+ // Whitespace can be a nightmare to spot/debug, so we fail early here.
2734
+ throw new Error("".concat(endpointName, " returned whitespace around the JWT, please remove it."));
2735
+ }
2736
+ return jwt;
2737
+ });
2738
+ });
2739
+ } catch (e) {
2740
+ return Promise.reject(e);
2741
+ }
2742
+ }
2743
+ }]);
2744
+ return AuthManager;
2745
+ }(BaseAPI);
2746
+ ;// CONCATENATED MODULE: ./src/public/browser/index.ts
2747
+
2748
+
2749
+ ;// CONCATENATED MODULE: ./src/index.browser.ts
2750
+ /* tslint:disable */
2751
+ /* eslint-disable */
2752
+
2753
+
2754
+ var __lib_exports__AuthManager = __lib_exports__.AuthManager;
2755
+ var __lib_exports__BaseAPI = __lib_exports__.BaseAPI;
2756
+ var __lib_exports__BinaryResult = __lib_exports__.BinaryResult;
2757
+ var __lib_exports__BytescaleApiClientConfigUtils = __lib_exports__.BytescaleApiClientConfigUtils;
2758
+ var __lib_exports__BytescaleApiError = __lib_exports__.BytescaleApiError;
2759
+ var __lib_exports__CancelledError = __lib_exports__.CancelledError;
2760
+ var __lib_exports__CommonTypesNoOp = __lib_exports__.CommonTypesNoOp;
2761
+ var __lib_exports__FileApi = __lib_exports__.FileApi;
2762
+ var __lib_exports__FolderApi = __lib_exports__.FolderApi;
2763
+ var __lib_exports__JSONApiResponse = __lib_exports__.JSONApiResponse;
2764
+ var __lib_exports__JobApi = __lib_exports__.JobApi;
2765
+ var __lib_exports__UploadApi = __lib_exports__.UploadApi;
2766
+ var __lib_exports__UploadManager = __lib_exports__.UploadManager;
2767
+ var __lib_exports__UrlBuilder = __lib_exports__.UrlBuilder;
2768
+ var __lib_exports__UrlBuilderTypesNoOp = __lib_exports__.UrlBuilderTypesNoOp;
2769
+ var __lib_exports__VoidApiResponse = __lib_exports__.VoidApiResponse;
2770
+ var __lib_exports__querystring = __lib_exports__.querystring;
2771
+ 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 };