@bytescale/sdk 3.9.0 → 3.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -43,7 +43,7 @@ __lib_require__.d(__lib_exports__, {
43
43
  "querystring": function() { return /* reexport */ querystring; }
44
44
  });
45
45
 
46
- ;// CONCATENATED MODULE: ./src/private/Mutex.ts
46
+ ;// CONCATENATED MODULE: ./src/private/FairMutex.ts
47
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
48
  function _call(body, then, direct) {
49
49
  if (direct) {
@@ -86,157 +86,12 @@ function _awaitIgnored(value, direct) {
86
86
  return value && value.then ? value.then(_empty) : Promise.resolve();
87
87
  }
88
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
- }
89
+ function _invoke(body, then) {
90
+ var result = body();
91
+ if (result && result.then) {
92
+ return result.then(then);
236
93
  }
237
- }
238
- function _continue(value, then) {
239
- return value && value.then ? value.then(then) : then(value);
94
+ return then(result);
240
95
  }
241
96
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
242
97
  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); } }
@@ -244,28 +99,31 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
244
99
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
245
100
  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
101
  /**
247
- * A lightweight mutex. (Other libraries contain too many features and we want to keep size down).
102
+ * A lightweight fair mutex. (Other libraries contain too many features and we want to keep size down).
248
103
  *
249
104
  * Characteristics:
250
105
  * - Non-reentrant.
251
- * - Unfair. (Multiple callers awaiting 'acquire' will be granted the mutex in no order.)
106
+ * - Fair.
107
+ * - This means multiple callers awaiting 'lock' will be granted the mutex in the order they requested it.
108
+ * - This is important, as in React, developers calling 'AuthManager.endAuthSession' in a 'useEffect' cleanup need it
109
+ * to take effect immediately, such that subsequent 'AuthManager.beginAuthSession' calls will always succeed.
252
110
  * - When calling `safe` consecutively with no 'awaits' in-between, the current context will synchronously acquire
253
111
  * the mutex every time.
254
112
  */
255
- var Mutex = /*#__PURE__*/function () {
256
- function Mutex() {
257
- _classCallCheck(this, Mutex);
258
- this.mutex = undefined;
259
- this.resolver = undefined;
113
+ var FairMutex = /*#__PURE__*/function () {
114
+ function FairMutex() {
115
+ _classCallCheck(this, FairMutex);
116
+ this.locked = false;
117
+ this.queue = [];
260
118
  }
261
- _createClass(Mutex, [{
119
+ _createClass(FairMutex, [{
262
120
  key: "safe",
263
121
  value: function safe(callback) {
264
122
  try {
265
123
  var _this2 = this;
266
- return _await(_this2.acquire(), function () {
124
+ return _await(_this2.lock(), function () {
267
125
  return _finallyRethrows(callback, function (_wasThrown, _result) {
268
- _this2.release();
126
+ _this2.unlock();
269
127
  return _rethrow(_wasThrown, _result);
270
128
  });
271
129
  });
@@ -274,37 +132,48 @@ var Mutex = /*#__PURE__*/function () {
274
132
  }
275
133
  }
276
134
  }, {
277
- key: "acquire",
278
- value: function acquire() {
135
+ key: "lock",
136
+ value: function lock() {
279
137
  try {
138
+ var _exit2 = false;
280
139
  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
- });
140
+ return _invoke(function () {
141
+ if (_this4.locked) {
142
+ var unlockNext;
143
+ var lockPromise = new Promise(function (resolve) {
144
+ unlockNext = resolve;
145
+ });
146
+ if (unlockNext === undefined) {
147
+ throw new Error("unlockNext was undefined");
148
+ }
149
+ _this4.queue.push({
150
+ resolve: unlockNext
151
+ });
152
+ return _awaitIgnored(lockPromise);
153
+ }
154
+ }, function (_result2) {
155
+ if (_exit2) return _result2;
156
+ _this4.locked = true;
291
157
  });
292
158
  } catch (e) {
293
159
  return Promise.reject(e);
294
160
  }
295
161
  }
296
162
  }, {
297
- key: "release",
298
- value: function release() {
299
- if (this.resolver === undefined) {
300
- throw new Error("Unable to release mutex: already released.");
163
+ key: "unlock",
164
+ value: function unlock() {
165
+ if (!this.locked) {
166
+ throw new Error("Mutex is not locked.");
167
+ }
168
+ var nextInQueue = this.queue.shift();
169
+ if (nextInQueue !== undefined) {
170
+ nextInQueue.resolve();
171
+ } else {
172
+ this.locked = false;
301
173
  }
302
- this.resolver();
303
- this.resolver = undefined;
304
- this.mutex = undefined;
305
174
  }
306
175
  }]);
307
- return Mutex;
176
+ return FairMutex;
308
177
  }();
309
178
  ;// CONCATENATED MODULE: ./src/private/AuthSessionState.ts
310
179
  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); }
@@ -340,7 +209,7 @@ var AuthSessionState = /*#__PURE__*/function () {
340
209
  var key = AuthSessionState.mutexKey;
341
210
  var mutex = window[key];
342
211
  if (mutex === undefined) {
343
- mutex = new Mutex();
212
+ mutex = new FairMutex();
344
213
  window[key] = mutex;
345
214
  }
346
215
  return mutex;
@@ -393,10 +262,10 @@ function _catch(body, recover) {
393
262
  return result;
394
263
  }
395
264
  function runtime_empty() {}
396
- function runtime_continue(value, then) {
265
+ function _continue(value, then) {
397
266
  return value && value.then ? value.then(then) : then(value);
398
267
  }
399
- function _invoke(body, then) {
268
+ function runtime_invoke(body, then) {
400
269
  var result = body();
401
270
  if (result && result.then) {
402
271
  return result.then(then);
@@ -587,7 +456,7 @@ var BaseAPI = /*#__PURE__*/function () {
587
456
  var _exit3 = false;
588
457
  var _a, _b;
589
458
  var response;
590
- return runtime_continue(_catch(function () {
459
+ return _continue(_catch(function () {
591
460
  return runtime_await(BytescaleApiClientConfigUtils.getFetchApi(config)(url, Object.assign(Object.assign({}, init), {
592
461
  // This is specifically added to cater for Next.js's Fetch implementation, which caches POST requests...
593
462
  //
@@ -607,10 +476,10 @@ var BaseAPI = /*#__PURE__*/function () {
607
476
  }), function (_result) {
608
477
  var _exit2 = false;
609
478
  if (_exit3) return _result;
610
- return response.status >= 200 && response.status < 300 ? response : _invoke(function () {
479
+ return response.status >= 200 && response.status < 300 ? response : runtime_invoke(function () {
611
480
  if (config.isBytescaleApi) {
612
481
  var jsonError = undefined;
613
- return runtime_continue(_catch(function () {
482
+ return _continue(_catch(function () {
614
483
  return runtime_await(response.json(), function (_response$json) {
615
484
  jsonError = _response$json;
616
485
  });
@@ -1816,21 +1685,21 @@ function _invokeIgnored(body) {
1816
1685
  return result.then(UploadManagerBase_empty);
1817
1686
  }
1818
1687
  }
1819
- function UploadManagerBase_settle(pact, state, value) {
1688
+ function _settle(pact, state, value) {
1820
1689
  if (!pact.s) {
1821
- if (value instanceof UploadManagerBase_Pact) {
1690
+ if (value instanceof _Pact) {
1822
1691
  if (value.s) {
1823
1692
  if (state & 1) {
1824
1693
  state = value.s;
1825
1694
  }
1826
1695
  value = value.v;
1827
1696
  } else {
1828
- value.o = UploadManagerBase_settle.bind(null, pact, state);
1697
+ value.o = _settle.bind(null, pact, state);
1829
1698
  return;
1830
1699
  }
1831
1700
  }
1832
1701
  if (value && value.then) {
1833
- value.then(UploadManagerBase_settle.bind(null, pact, state), UploadManagerBase_settle.bind(null, pact, 2));
1702
+ value.then(_settle.bind(null, pact, state), _settle.bind(null, pact, 2));
1834
1703
  return;
1835
1704
  }
1836
1705
  pact.s = state;
@@ -1841,7 +1710,7 @@ function UploadManagerBase_settle(pact, state, value) {
1841
1710
  }
1842
1711
  }
1843
1712
  }
1844
- var UploadManagerBase_Pact = /*#__PURE__*/function () {
1713
+ var _Pact = /*#__PURE__*/function () {
1845
1714
  function _Pact() {}
1846
1715
  _Pact.prototype.then = function (onFulfilled, onRejected) {
1847
1716
  var result = new _Pact();
@@ -1850,9 +1719,9 @@ var UploadManagerBase_Pact = /*#__PURE__*/function () {
1850
1719
  var callback = state & 1 ? onFulfilled : onRejected;
1851
1720
  if (callback) {
1852
1721
  try {
1853
- UploadManagerBase_settle(result, 1, callback(this.v));
1722
+ _settle(result, 1, callback(this.v));
1854
1723
  } catch (e) {
1855
- UploadManagerBase_settle(result, 2, e);
1724
+ _settle(result, 2, e);
1856
1725
  }
1857
1726
  return result;
1858
1727
  } else {
@@ -1863,28 +1732,28 @@ var UploadManagerBase_Pact = /*#__PURE__*/function () {
1863
1732
  try {
1864
1733
  var value = _this.v;
1865
1734
  if (_this.s & 1) {
1866
- UploadManagerBase_settle(result, 1, onFulfilled ? onFulfilled(value) : value);
1735
+ _settle(result, 1, onFulfilled ? onFulfilled(value) : value);
1867
1736
  } else if (onRejected) {
1868
- UploadManagerBase_settle(result, 1, onRejected(value));
1737
+ _settle(result, 1, onRejected(value));
1869
1738
  } else {
1870
- UploadManagerBase_settle(result, 2, value);
1739
+ _settle(result, 2, value);
1871
1740
  }
1872
1741
  } catch (e) {
1873
- UploadManagerBase_settle(result, 2, e);
1742
+ _settle(result, 2, e);
1874
1743
  }
1875
1744
  };
1876
1745
  return result;
1877
1746
  };
1878
1747
  return _Pact;
1879
1748
  }();
1880
- function UploadManagerBase_isSettledPact(thenable) {
1881
- return thenable instanceof UploadManagerBase_Pact && thenable.s & 1;
1749
+ function _isSettledPact(thenable) {
1750
+ return thenable instanceof _Pact && thenable.s & 1;
1882
1751
  }
1883
- function UploadManagerBase_for(test, update, body) {
1752
+ function _for(test, update, body) {
1884
1753
  var stage;
1885
1754
  for (;;) {
1886
1755
  var shouldContinue = test();
1887
- if (UploadManagerBase_isSettledPact(shouldContinue)) {
1756
+ if (_isSettledPact(shouldContinue)) {
1888
1757
  shouldContinue = shouldContinue.v;
1889
1758
  }
1890
1759
  if (!shouldContinue) {
@@ -1896,7 +1765,7 @@ function UploadManagerBase_for(test, update, body) {
1896
1765
  }
1897
1766
  var result = body();
1898
1767
  if (result && result.then) {
1899
- if (UploadManagerBase_isSettledPact(result)) {
1768
+ if (_isSettledPact(result)) {
1900
1769
  result = result.s;
1901
1770
  } else {
1902
1771
  stage = 1;
@@ -1905,14 +1774,14 @@ function UploadManagerBase_for(test, update, body) {
1905
1774
  }
1906
1775
  if (update) {
1907
1776
  var updateValue = update();
1908
- if (updateValue && updateValue.then && !UploadManagerBase_isSettledPact(updateValue)) {
1777
+ if (updateValue && updateValue.then && !_isSettledPact(updateValue)) {
1909
1778
  stage = 2;
1910
1779
  break;
1911
1780
  }
1912
1781
  }
1913
1782
  }
1914
- var pact = new UploadManagerBase_Pact();
1915
- var reject = UploadManagerBase_settle.bind(null, pact, 2);
1783
+ var pact = new _Pact();
1784
+ var reject = _settle.bind(null, pact, 2);
1916
1785
  (stage === 0 ? shouldContinue.then(_resumeAfterTest) : stage === 1 ? result.then(_resumeAfterBody) : updateValue.then(_resumeAfterUpdate)).then(void 0, reject);
1917
1786
  return pact;
1918
1787
  function _resumeAfterBody(value) {
@@ -1920,14 +1789,14 @@ function UploadManagerBase_for(test, update, body) {
1920
1789
  do {
1921
1790
  if (update) {
1922
1791
  updateValue = update();
1923
- if (updateValue && updateValue.then && !UploadManagerBase_isSettledPact(updateValue)) {
1792
+ if (updateValue && updateValue.then && !_isSettledPact(updateValue)) {
1924
1793
  updateValue.then(_resumeAfterUpdate).then(void 0, reject);
1925
1794
  return;
1926
1795
  }
1927
1796
  }
1928
1797
  shouldContinue = test();
1929
- if (!shouldContinue || UploadManagerBase_isSettledPact(shouldContinue) && !shouldContinue.v) {
1930
- UploadManagerBase_settle(pact, 1, result);
1798
+ if (!shouldContinue || _isSettledPact(shouldContinue) && !shouldContinue.v) {
1799
+ _settle(pact, 1, result);
1931
1800
  return;
1932
1801
  }
1933
1802
  if (shouldContinue.then) {
@@ -1935,7 +1804,7 @@ function UploadManagerBase_for(test, update, body) {
1935
1804
  return;
1936
1805
  }
1937
1806
  result = body();
1938
- if (UploadManagerBase_isSettledPact(result)) {
1807
+ if (_isSettledPact(result)) {
1939
1808
  result = result.v;
1940
1809
  }
1941
1810
  } while (!result || !result.then);
@@ -1950,7 +1819,7 @@ function UploadManagerBase_for(test, update, body) {
1950
1819
  _resumeAfterBody(result);
1951
1820
  }
1952
1821
  } else {
1953
- UploadManagerBase_settle(pact, 1, result);
1822
+ _settle(pact, 1, result);
1954
1823
  }
1955
1824
  }
1956
1825
  function _resumeAfterUpdate() {
@@ -1961,7 +1830,7 @@ function UploadManagerBase_for(test, update, body) {
1961
1830
  _resumeAfterTest(shouldContinue);
1962
1831
  }
1963
1832
  } else {
1964
- UploadManagerBase_settle(pact, 1, result);
1833
+ _settle(pact, 1, result);
1965
1834
  }
1966
1835
  }
1967
1836
  }
@@ -2075,7 +1944,9 @@ var UploadManagerBase = /*#__PURE__*/function () {
2075
1944
  size = _ref$value.size,
2076
1945
  type = _ref$value.type;
2077
1946
  return {
2078
- mime: type,
1947
+ // Some browsers/OSs return 'type: ""' for files with unknown MIME types, like HEICs, which causes a validation
1948
+ // error from the Bytescale API as "" is not a valid MIME type, so we coalesce to undefined here.
1949
+ mime: type === "" ? undefined : type,
2079
1950
  size: size,
2080
1951
  originalFileName: name,
2081
1952
  maxConcurrentUploadParts: undefined
@@ -2263,7 +2134,7 @@ var UploadManagerBase = /*#__PURE__*/function () {
2263
2134
  try {
2264
2135
  var workQueue = UploadManagerBase_toConsumableArray(items);
2265
2136
  return UploadManagerBase_awaitIgnored(Promise.all(UploadManagerBase_toConsumableArray(Array(concurrency).keys()).map(_async(function () {
2266
- return _continueIgnored(UploadManagerBase_for(function () {
2137
+ return _continueIgnored(_for(function () {
2267
2138
  return workQueue.length > 0;
2268
2139
  }, void 0, function () {
2269
2140
  var work = workQueue.shift(); // IMPORTANT: use 'shift' instead of 'pop' to ensure 'items' are processed in order when 'concurrency = 1'.
@@ -2603,7 +2474,7 @@ var AuthManagerImpl = /*#__PURE__*/function () {
2603
2474
  return AuthManagerBrowser_await(_this2.authSessionMutex.safe(AuthManagerBrowser_async(function () {
2604
2475
  // We check both 'session' and 'sessionDisposing' here, as we don't want to call 'beginAuthSession' until the session is fully disposed.
2605
2476
  if (_this2.isAuthSessionActive()) {
2606
- 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.");
2477
+ throw new Error("Auth session already active. Please call 'await endAuthSession()' and then call 'await beginAuthSession(...)' to start a new auth session.");
2607
2478
  }
2608
2479
  AuthSessionState.setSession(newSession);
2609
2480
  return AuthManagerBrowser_await();