@atlaskit/media-client 20.0.1 → 20.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/client/collection-fetcher.js +4 -44
  3. package/dist/cjs/client/file-fetcher/error.js +3 -19
  4. package/dist/cjs/client/file-fetcher/index.js +72 -191
  5. package/dist/cjs/client/media-client.js +2 -26
  6. package/dist/cjs/client/media-store/error.js +1 -17
  7. package/dist/cjs/client/media-store/index.js +13 -103
  8. package/dist/cjs/client/media-store/resolveAuth.js +2 -23
  9. package/dist/cjs/client/mobile-upload.js +9 -22
  10. package/dist/cjs/client/stargate-client.js +0 -12
  11. package/dist/cjs/constants.js +1 -4
  12. package/dist/cjs/file-streams-cache.js +0 -11
  13. package/dist/cjs/globalMediaEventEmitter.js +0 -3
  14. package/dist/cjs/identifier.js +0 -8
  15. package/dist/cjs/index.js +0 -38
  16. package/dist/cjs/models/artifacts.js +0 -4
  17. package/dist/cjs/models/auth-headers.js +0 -2
  18. package/dist/cjs/models/auth-query-parameters.js +0 -2
  19. package/dist/cjs/models/errors/helpers.js +0 -2
  20. package/dist/cjs/models/errors/index.js +4 -20
  21. package/dist/cjs/models/file-state.js +10 -36
  22. package/dist/cjs/models/media.js +2 -8
  23. package/dist/cjs/upload-controller.js +0 -6
  24. package/dist/cjs/uploader/calculateChunkSize.js +1 -10
  25. package/dist/cjs/uploader/error.js +3 -19
  26. package/dist/cjs/uploader/index.js +3 -43
  27. package/dist/cjs/utils/checkWebpSupport.js +3 -7
  28. package/dist/cjs/utils/convertBase64ToBlob.js +0 -5
  29. package/dist/cjs/utils/createFileDataLoader.js +4 -28
  30. package/dist/cjs/utils/createMediaSubject.js +0 -4
  31. package/dist/cjs/utils/detectEmptyFile.js +8 -15
  32. package/dist/cjs/utils/getDimensionsFromBlob.js +0 -14
  33. package/dist/cjs/utils/getImageDimensionsFromBlob.js +0 -4
  34. package/dist/cjs/utils/getMediaTypeFromUploadableFile.js +0 -3
  35. package/dist/cjs/utils/getVideoDimensionsFromBlob.js +2 -8
  36. package/dist/cjs/utils/hashing/hasherCreator.js +0 -20
  37. package/dist/cjs/utils/hashing/simpleHasher.js +0 -12
  38. package/dist/cjs/utils/hashing/workerHasher.js +3 -24
  39. package/dist/cjs/utils/imageResizeModeToFileImageMode.js +0 -2
  40. package/dist/cjs/utils/isImageRemote.js +0 -5
  41. package/dist/cjs/utils/mediaSubscribable/fromObservable.js +2 -4
  42. package/dist/cjs/utils/mediaSubscribable/index.js +0 -2
  43. package/dist/cjs/utils/mediaSubscribable/toPromise.js +1 -3
  44. package/dist/cjs/utils/mobileUpload/error.js +3 -19
  45. package/dist/cjs/utils/mobileUpload/helpers.js +2 -26
  46. package/dist/cjs/utils/mobileUpload/index.js +0 -4
  47. package/dist/cjs/utils/mobileUpload/servicesCache.js +0 -2
  48. package/dist/cjs/utils/mobileUpload/stateMachine/index.js +0 -22
  49. package/dist/cjs/utils/mobileUpload/stateMachine/states/processing.js +0 -2
  50. package/dist/cjs/utils/mobileUpload/stateMachine/states/uploading.js +0 -7
  51. package/dist/cjs/utils/overrideMediaTypeIfUnknown.js +0 -4
  52. package/dist/cjs/utils/polling/errors.js +1 -17
  53. package/dist/cjs/utils/polling/index.js +1 -30
  54. package/dist/cjs/utils/request/errors.js +8 -24
  55. package/dist/cjs/utils/request/helpers.js +19 -103
  56. package/dist/cjs/utils/request/index.js +15 -26
  57. package/dist/cjs/utils/safeUnsubscribe.js +0 -2
  58. package/dist/cjs/utils/setTimeoutPromise.js +0 -4
  59. package/dist/cjs/utils/shouldFetchRemoteFileStates.js +0 -21
  60. package/dist/cjs/utils/url.js +4 -27
  61. package/dist/cjs/utils/with-media-client-hoc.js +12 -28
  62. package/dist/cjs/version.json +1 -1
  63. package/dist/es2019/client/collection-fetcher.js +6 -18
  64. package/dist/es2019/client/file-fetcher/error.js +0 -2
  65. package/dist/es2019/client/file-fetcher/index.js +49 -91
  66. package/dist/es2019/client/media-client.js +3 -13
  67. package/dist/es2019/client/media-store/error.js +0 -2
  68. package/dist/es2019/client/media-store/index.js +37 -52
  69. package/dist/es2019/client/media-store/resolveAuth.js +1 -5
  70. package/dist/es2019/client/mobile-upload.js +0 -8
  71. package/dist/es2019/client/stargate-client.js +0 -3
  72. package/dist/es2019/constants.js +1 -2
  73. package/dist/es2019/file-streams-cache.js +0 -11
  74. package/dist/es2019/globalMediaEventEmitter.js +0 -4
  75. package/dist/es2019/index.js +4 -11
  76. package/dist/es2019/models/artifacts.js +0 -2
  77. package/dist/es2019/models/errors/index.js +5 -4
  78. package/dist/es2019/models/file-state.js +6 -7
  79. package/dist/es2019/models/media.js +2 -3
  80. package/dist/es2019/upload-controller.js +0 -3
  81. package/dist/es2019/uploader/calculateChunkSize.js +1 -4
  82. package/dist/es2019/uploader/error.js +0 -2
  83. package/dist/es2019/uploader/index.js +0 -13
  84. package/dist/es2019/utils/checkWebpSupport.js +3 -4
  85. package/dist/es2019/utils/convertBase64ToBlob.js +0 -2
  86. package/dist/es2019/utils/createFileDataLoader.js +6 -9
  87. package/dist/es2019/utils/createMediaSubject.js +0 -2
  88. package/dist/es2019/utils/detectEmptyFile.js +1 -5
  89. package/dist/es2019/utils/getDimensionsFromBlob.js +0 -3
  90. package/dist/es2019/utils/getImageDimensionsFromBlob.js +0 -2
  91. package/dist/es2019/utils/getVideoDimensionsFromBlob.js +2 -1
  92. package/dist/es2019/utils/hashing/hasherCreator.js +0 -2
  93. package/dist/es2019/utils/hashing/simpleHasher.js +0 -3
  94. package/dist/es2019/utils/hashing/workerHasher.js +1 -16
  95. package/dist/es2019/utils/isImageRemote.js +0 -2
  96. package/dist/es2019/utils/mediaSubscribable/fromObservable.js +2 -1
  97. package/dist/es2019/utils/mediaSubscribable/toPromise.js +1 -1
  98. package/dist/es2019/utils/mobileUpload/error.js +0 -2
  99. package/dist/es2019/utils/mobileUpload/helpers.js +2 -7
  100. package/dist/es2019/utils/mobileUpload/stateMachine/index.js +0 -2
  101. package/dist/es2019/utils/mobileUpload/stateMachine/states/uploading.js +2 -1
  102. package/dist/es2019/utils/overrideMediaTypeIfUnknown.js +0 -1
  103. package/dist/es2019/utils/polling/errors.js +0 -2
  104. package/dist/es2019/utils/polling/index.js +3 -20
  105. package/dist/es2019/utils/request/errors.js +0 -2
  106. package/dist/es2019/utils/request/helpers.js +24 -35
  107. package/dist/es2019/utils/request/index.js +2 -2
  108. package/dist/es2019/utils/shouldFetchRemoteFileStates.js +1 -5
  109. package/dist/es2019/utils/url.js +6 -14
  110. package/dist/es2019/utils/with-media-client-hoc.js +10 -7
  111. package/dist/es2019/version.json +1 -1
  112. package/dist/esm/client/collection-fetcher.js +4 -34
  113. package/dist/esm/client/file-fetcher/error.js +3 -12
  114. package/dist/esm/client/file-fetcher/index.js +74 -161
  115. package/dist/esm/client/media-client.js +3 -16
  116. package/dist/esm/client/media-store/error.js +1 -10
  117. package/dist/esm/client/media-store/index.js +13 -89
  118. package/dist/esm/client/media-store/resolveAuth.js +2 -13
  119. package/dist/esm/client/mobile-upload.js +9 -15
  120. package/dist/esm/client/stargate-client.js +0 -7
  121. package/dist/esm/constants.js +1 -2
  122. package/dist/esm/file-streams-cache.js +0 -6
  123. package/dist/esm/globalMediaEventEmitter.js +0 -1
  124. package/dist/esm/index.js +4 -11
  125. package/dist/esm/models/artifacts.js +0 -2
  126. package/dist/esm/models/errors/index.js +5 -12
  127. package/dist/esm/models/file-state.js +10 -17
  128. package/dist/esm/models/media.js +2 -3
  129. package/dist/esm/upload-controller.js +0 -2
  130. package/dist/esm/uploader/calculateChunkSize.js +1 -4
  131. package/dist/esm/uploader/error.js +3 -12
  132. package/dist/esm/uploader/index.js +3 -32
  133. package/dist/esm/utils/checkWebpSupport.js +3 -4
  134. package/dist/esm/utils/convertBase64ToBlob.js +0 -3
  135. package/dist/esm/utils/createFileDataLoader.js +4 -18
  136. package/dist/esm/utils/createMediaSubject.js +0 -2
  137. package/dist/esm/utils/detectEmptyFile.js +8 -12
  138. package/dist/esm/utils/getDimensionsFromBlob.js +0 -7
  139. package/dist/esm/utils/getImageDimensionsFromBlob.js +0 -2
  140. package/dist/esm/utils/getVideoDimensionsFromBlob.js +2 -3
  141. package/dist/esm/utils/hashing/hasherCreator.js +0 -9
  142. package/dist/esm/utils/hashing/simpleHasher.js +0 -4
  143. package/dist/esm/utils/hashing/workerHasher.js +3 -18
  144. package/dist/esm/utils/isImageRemote.js +0 -3
  145. package/dist/esm/utils/mediaSubscribable/fromObservable.js +2 -1
  146. package/dist/esm/utils/mediaSubscribable/toPromise.js +1 -1
  147. package/dist/esm/utils/mobileUpload/error.js +3 -12
  148. package/dist/esm/utils/mobileUpload/helpers.js +2 -11
  149. package/dist/esm/utils/mobileUpload/stateMachine/index.js +0 -6
  150. package/dist/esm/utils/mobileUpload/stateMachine/states/uploading.js +0 -3
  151. package/dist/esm/utils/overrideMediaTypeIfUnknown.js +0 -1
  152. package/dist/esm/utils/polling/errors.js +1 -10
  153. package/dist/esm/utils/polling/index.js +1 -27
  154. package/dist/esm/utils/request/errors.js +8 -17
  155. package/dist/esm/utils/request/helpers.js +22 -76
  156. package/dist/esm/utils/request/index.js +15 -20
  157. package/dist/esm/utils/shouldFetchRemoteFileStates.js +1 -15
  158. package/dist/esm/utils/url.js +4 -18
  159. package/dist/esm/utils/with-media-client-hoc.js +12 -17
  160. package/dist/esm/version.json +1 -1
  161. package/package.json +7 -5
@@ -3,40 +3,31 @@ import _createClass from "@babel/runtime/helpers/createClass";
3
3
  import _inherits from "@babel/runtime/helpers/inherits";
4
4
  import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
5
5
  import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
6
-
7
6
  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); }; }
8
-
9
7
  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; } }
10
-
11
8
  import { BaseMediaClientError } from '../../models/errors';
12
9
  export var PollingError = /*#__PURE__*/function (_BaseMediaClientError) {
13
10
  _inherits(PollingError, _BaseMediaClientError);
14
-
15
11
  var _super = _createSuper(PollingError);
16
-
17
12
  function PollingError(reason, attempts) {
18
13
  var _this;
19
-
20
14
  _classCallCheck(this, PollingError);
21
-
22
15
  _this = _super.call(this, reason);
23
16
  _this.reason = reason;
24
17
  _this.attempts = attempts;
25
18
  return _this;
26
19
  }
27
-
28
20
  _createClass(PollingError, [{
29
21
  key: "attributes",
30
22
  get: function get() {
31
23
  var reason = this.reason,
32
- attempts = this.attempts;
24
+ attempts = this.attempts;
33
25
  return {
34
26
  reason: reason,
35
27
  attempts: attempts
36
28
  };
37
29
  }
38
30
  }]);
39
-
40
31
  return PollingError;
41
32
  }(BaseMediaClientError);
42
33
  export function isPollingError(err) {
@@ -3,11 +3,8 @@ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
3
  import _createClass from "@babel/runtime/helpers/createClass";
4
4
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
5
5
  import _regeneratorRuntime from "@babel/runtime/regenerator";
6
-
7
6
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
8
-
9
7
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
10
-
11
8
  import { PollingError } from './errors';
12
9
  // default polling options without using feature flags
13
10
  export var defaultPollingOptions = {
@@ -16,6 +13,7 @@ export var defaultPollingOptions = {
16
13
  poll_backoffFactor: 1.25,
17
14
  poll_maxIntervalMs: 200000
18
15
  };
16
+
19
17
  /**
20
18
  * This class encapsulates polling functionality with the following features:
21
19
  *
@@ -27,66 +25,50 @@ export var defaultPollingOptions = {
27
25
  *
28
26
  * IMPORTANT! the executor function must explicitly call ".next()" for the next iteration to run
29
27
  */
30
-
31
28
  export var PollingFunction = /*#__PURE__*/function () {
32
29
  function PollingFunction(options) {
33
30
  _classCallCheck(this, PollingFunction);
34
-
35
31
  _defineProperty(this, "poll_intervalMs", 0);
36
-
37
32
  _defineProperty(this, "attempt", 1);
38
-
39
33
  _defineProperty(this, "shouldIterate", true);
40
-
41
34
  _defineProperty(this, "timeoutId", 0);
42
-
43
35
  this.options = _objectSpread(_objectSpread({}, defaultPollingOptions), options);
44
36
  this.poll_intervalMs = this.options.poll_intervalMs;
45
37
  }
46
-
47
38
  _createClass(PollingFunction, [{
48
39
  key: "execute",
49
40
  value: function () {
50
41
  var _execute = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(executor) {
51
42
  var _this = this;
52
-
53
43
  var poll_maxAttempts;
54
44
  return _regeneratorRuntime.wrap(function _callee$(_context) {
55
45
  while (1) {
56
46
  switch (_context.prev = _context.next) {
57
47
  case 0:
58
48
  poll_maxAttempts = this.options.poll_maxAttempts;
59
-
60
49
  if (!(poll_maxAttempts === 0)) {
61
50
  _context.next = 3;
62
51
  break;
63
52
  }
64
-
65
53
  return _context.abrupt("return", this.fail(new PollingError('pollingMaxAttemptsExceeded', this.attempt)));
66
-
67
54
  case 3:
68
55
  _context.prev = 3;
69
56
  // executor must explicitly call this.next() for triggering next iteration (pull)
70
57
  this.shouldIterate = false;
71
58
  _context.next = 7;
72
59
  return executor();
73
-
74
60
  case 7:
75
61
  if (this.shouldIterate) {
76
62
  _context.next = 9;
77
63
  break;
78
64
  }
79
-
80
65
  return _context.abrupt("return");
81
-
82
66
  case 9:
83
67
  if (!(this.attempt >= poll_maxAttempts)) {
84
68
  _context.next = 11;
85
69
  break;
86
70
  }
87
-
88
71
  return _context.abrupt("return", this.fail(new PollingError('pollingMaxAttemptsExceeded', this.attempt)));
89
-
90
72
  case 11:
91
73
  this.poll_intervalMs = this.getIntervalMsForIteration(this.attempt);
92
74
  this.attempt++;
@@ -95,12 +77,10 @@ export var PollingFunction = /*#__PURE__*/function () {
95
77
  }, this.poll_intervalMs);
96
78
  _context.next = 19;
97
79
  break;
98
-
99
80
  case 16:
100
81
  _context.prev = 16;
101
82
  _context.t0 = _context["catch"](3);
102
83
  this.fail(_context.t0);
103
-
104
84
  case 19:
105
85
  case "end":
106
86
  return _context.stop();
@@ -108,11 +88,9 @@ export var PollingFunction = /*#__PURE__*/function () {
108
88
  }
109
89
  }, _callee, this, [[3, 16]]);
110
90
  }));
111
-
112
91
  function execute(_x) {
113
92
  return _execute.apply(this, arguments);
114
93
  }
115
-
116
94
  return execute;
117
95
  }()
118
96
  }, {
@@ -126,15 +104,12 @@ export var PollingFunction = /*#__PURE__*/function () {
126
104
  key: "getIntervalMsForIteration",
127
105
  value: function getIntervalMsForIteration(iteration) {
128
106
  var poll_intervalMs = this.options.poll_intervalMs;
129
-
130
107
  if (iteration === 1) {
131
108
  return poll_intervalMs;
132
109
  }
133
-
134
110
  for (var i = 2; i <= iteration; i++) {
135
111
  poll_intervalMs = poll_intervalMs * this.options.poll_backoffFactor;
136
112
  }
137
-
138
113
  return Math.min(Math.round(poll_intervalMs), this.options.poll_maxIntervalMs);
139
114
  }
140
115
  }, {
@@ -149,6 +124,5 @@ export var PollingFunction = /*#__PURE__*/function () {
149
124
  this.timeoutId = 0;
150
125
  }
151
126
  }]);
152
-
153
127
  return PollingFunction;
154
128
  }();
@@ -3,43 +3,35 @@ import _createClass from "@babel/runtime/helpers/createClass";
3
3
  import _inherits from "@babel/runtime/helpers/inherits";
4
4
  import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
5
5
  import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
6
-
7
6
  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); }; }
8
-
9
7
  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; } }
10
-
11
8
  import { BaseMediaClientError } from '../../models/errors';
12
9
  export var RequestError = /*#__PURE__*/function (_BaseMediaClientError) {
13
10
  _inherits(RequestError, _BaseMediaClientError);
14
-
15
11
  var _super = _createSuper(RequestError);
16
-
17
12
  function RequestError(reason, metadata, innerError) {
18
13
  var _this;
19
-
20
14
  _classCallCheck(this, RequestError);
21
-
22
15
  _this = _super.call(this, reason);
23
16
  _this.reason = reason;
24
17
  _this.metadata = metadata;
25
18
  _this.innerError = innerError;
26
19
  return _this;
27
20
  }
28
-
29
21
  _createClass(RequestError, [{
30
22
  key: "attributes",
31
23
  get: function get() {
32
24
  var reason = this.reason,
33
- _this$metadata = this.metadata;
25
+ _this$metadata = this.metadata;
34
26
  _this$metadata = _this$metadata === void 0 ? {} : _this$metadata;
35
27
  var method = _this$metadata.method,
36
- endpoint = _this$metadata.endpoint,
37
- mediaRegion = _this$metadata.mediaRegion,
38
- mediaEnv = _this$metadata.mediaEnv,
39
- attempts = _this$metadata.attempts,
40
- clientExhaustedRetries = _this$metadata.clientExhaustedRetries,
41
- statusCode = _this$metadata.statusCode,
42
- innerError = this.innerError;
28
+ endpoint = _this$metadata.endpoint,
29
+ mediaRegion = _this$metadata.mediaRegion,
30
+ mediaEnv = _this$metadata.mediaEnv,
31
+ attempts = _this$metadata.attempts,
32
+ clientExhaustedRetries = _this$metadata.clientExhaustedRetries,
33
+ statusCode = _this$metadata.statusCode,
34
+ innerError = this.innerError;
43
35
  return {
44
36
  reason: reason,
45
37
  method: method,
@@ -53,7 +45,6 @@ export var RequestError = /*#__PURE__*/function (_BaseMediaClientError) {
53
45
  };
54
46
  }
55
47
  }]);
56
-
57
48
  return RequestError;
58
49
  }(BaseMediaClientError);
59
50
  export function isRequestError(err) {
@@ -3,11 +3,8 @@ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
3
3
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
4
4
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
5
5
  import _regeneratorRuntime from "@babel/runtime/regenerator";
6
-
7
6
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
8
-
9
7
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
10
-
11
8
  import { isClientBasedAuth } from '@atlaskit/media-core';
12
9
  import { mapAuthToQueryParameters } from '../../models/auth-query-parameters';
13
10
  import { RequestError, isRequestError } from './errors';
@@ -23,8 +20,9 @@ export function waitPromise(timeout) {
23
20
  }
24
21
  export function isAbortedRequestError(err) {
25
22
  return err instanceof Error && err.message === 'request_cancelled' || !!err && err.name === 'AbortError';
26
- } // fetch throws TypeError for network errors
23
+ }
27
24
 
25
+ // fetch throws TypeError for network errors
28
26
  export function isFetchNetworkError(err) {
29
27
  return err instanceof TypeError;
30
28
  }
@@ -38,25 +36,20 @@ export var ZipkinHeaderKeys = {
38
36
  sampled: 'x-b3-sampled',
39
37
  flags: 'x-b3-flags'
40
38
  };
41
-
42
39
  var mapTraceIdToRequestHeaders = function mapTraceIdToRequestHeaders(traceContext) {
43
40
  var _ref;
44
-
45
41
  return traceContext ? (_ref = {}, _defineProperty(_ref, ZipkinHeaderKeys.traceId, traceContext.traceId), _defineProperty(_ref, ZipkinHeaderKeys.spanId, traceContext.spanId), _ref) : {};
46
42
  };
47
-
48
43
  export function mapAuthToRequestHeaders(auth) {
49
44
  if (!auth) {
50
45
  return {};
51
46
  }
52
-
53
47
  if (isClientBasedAuth(auth)) {
54
48
  return {
55
49
  'X-Client-Id': auth.clientId,
56
50
  Authorization: "Bearer ".concat(auth.token)
57
51
  };
58
52
  }
59
-
60
53
  return {
61
54
  'X-Issuer': auth.asapIssuer,
62
55
  Authorization: "Bearer ".concat(auth.token)
@@ -64,21 +57,17 @@ export function mapAuthToRequestHeaders(auth) {
64
57
  }
65
58
  export function createUrl(url, _ref2) {
66
59
  var params = _ref2.params,
67
- auth = _ref2.auth;
60
+ auth = _ref2.auth;
68
61
  var parsedUrl = new URL(url);
69
62
  var authParams = auth && mapAuthToQueryParameters(auth) || {};
70
-
71
63
  var paramsToAppend = _objectSpread(_objectSpread({}, params), authParams);
72
-
73
64
  Object.entries(paramsToAppend).filter(function (_ref3) {
74
65
  var _ref4 = _slicedToArray(_ref3, 2),
75
- _ = _ref4[0],
76
- value = _ref4[1];
77
-
66
+ _ = _ref4[0],
67
+ value = _ref4[1];
78
68
  return value != null;
79
69
  }).forEach(function (pair) {
80
70
  var _parsedUrl$searchPara;
81
-
82
71
  (_parsedUrl$searchPara = parsedUrl.searchParams).append.apply(_parsedUrl$searchPara, _toConsumableArray(pair));
83
72
  });
84
73
  parsedUrl.searchParams.sort();
@@ -88,22 +77,21 @@ export function extendHeaders(headers, auth, traceContext) {
88
77
  if (!auth && !traceContext && !headers) {
89
78
  return undefined;
90
79
  }
91
-
92
80
  return _objectSpread(_objectSpread(_objectSpread({}, headers !== null && headers !== void 0 ? headers : {}), mapAuthToRequestHeaders(auth)), mapTraceIdToRequestHeaders(traceContext));
93
81
  }
82
+
94
83
  /**
95
84
  * @deprecated Helper is deprecated and will be removed in the next major version.
96
85
  * TODO: https://product-fabric.atlassian.net/browse/BMPT-1354
97
86
  */
98
-
99
87
  export function mapResponseToJson(_x) {
100
88
  return _mapResponseToJson.apply(this, arguments);
101
89
  }
90
+
102
91
  /**
103
92
  * @deprecated Helper is deprecated and will be removed in the next major version.
104
93
  * TODO: https://product-fabric.atlassian.net/browse/BMPT-1354
105
94
  */
106
-
107
95
  function _mapResponseToJson() {
108
96
  _mapResponseToJson = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(response) {
109
97
  return _regeneratorRuntime.wrap(function _callee3$(_context3) {
@@ -115,17 +103,14 @@ function _mapResponseToJson() {
115
103
  _context3.prev = 1;
116
104
  _context3.next = 4;
117
105
  return response.json();
118
-
119
106
  case 4:
120
107
  return _context3.abrupt("return", _context3.sent);
121
-
122
108
  case 7:
123
109
  _context3.prev = 7;
124
110
  _context3.t0 = _context3["catch"](1);
125
111
  throw new RequestError('serverInvalidBody', {
126
112
  statusCode: response.status
127
113
  }, _context3.t0 instanceof Error ? _context3.t0 : undefined);
128
-
129
114
  case 10:
130
115
  case "end":
131
116
  return _context3.stop();
@@ -135,15 +120,14 @@ function _mapResponseToJson() {
135
120
  }));
136
121
  return _mapResponseToJson.apply(this, arguments);
137
122
  }
138
-
139
123
  export function mapResponseToBlob(_x2) {
140
124
  return _mapResponseToBlob.apply(this, arguments);
141
125
  }
126
+
142
127
  /**
143
128
  * @deprecated Helper is deprecated and will be removed in the next major version.
144
129
  * TODO: https://product-fabric.atlassian.net/browse/BMPT-1354
145
130
  */
146
-
147
131
  function _mapResponseToBlob() {
148
132
  _mapResponseToBlob = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(response) {
149
133
  return _regeneratorRuntime.wrap(function _callee4$(_context4) {
@@ -155,17 +139,14 @@ function _mapResponseToBlob() {
155
139
  _context4.prev = 1;
156
140
  _context4.next = 4;
157
141
  return response.blob();
158
-
159
142
  case 4:
160
143
  return _context4.abrupt("return", _context4.sent);
161
-
162
144
  case 7:
163
145
  _context4.prev = 7;
164
146
  _context4.t0 = _context4["catch"](1);
165
147
  throw new RequestError('serverInvalidBody', {
166
148
  statusCode: response.status
167
149
  }, _context4.t0 instanceof Error ? _context4.t0 : undefined);
168
-
169
150
  case 10:
170
151
  case "end":
171
152
  return _context4.stop();
@@ -175,7 +156,6 @@ function _mapResponseToBlob() {
175
156
  }));
176
157
  return _mapResponseToBlob.apply(this, arguments);
177
158
  }
178
-
179
159
  export function mapResponseToVoid() {
180
160
  // eslint-disable-next-line no-console
181
161
  console.warn('Helper is deprecated and will be remove in the next major version');
@@ -191,17 +171,14 @@ export function createMapResponseToJson(metadata) {
191
171
  _context.prev = 0;
192
172
  _context.next = 3;
193
173
  return response.json();
194
-
195
174
  case 3:
196
175
  return _context.abrupt("return", _context.sent);
197
-
198
176
  case 6:
199
177
  _context.prev = 6;
200
178
  _context.t0 = _context["catch"](0);
201
179
  throw new RequestError('serverInvalidBody', _objectSpread(_objectSpread(_objectSpread({}, metadata), extractMediaHeaders(response)), {}, {
202
180
  statusCode: response.status
203
181
  }), _context.t0 instanceof Error ? _context.t0 : undefined);
204
-
205
182
  case 9:
206
183
  case "end":
207
184
  return _context.stop();
@@ -209,7 +186,6 @@ export function createMapResponseToJson(metadata) {
209
186
  }
210
187
  }, _callee, null, [[0, 6]]);
211
188
  }));
212
-
213
189
  return function (_x3) {
214
190
  return _ref5.apply(this, arguments);
215
191
  };
@@ -225,17 +201,14 @@ export function createMapResponseToBlob(metadata) {
225
201
  _context2.prev = 0;
226
202
  _context2.next = 3;
227
203
  return response.blob();
228
-
229
204
  case 3:
230
205
  return _context2.abrupt("return", _context2.sent);
231
-
232
206
  case 6:
233
207
  _context2.prev = 6;
234
208
  _context2.t0 = _context2["catch"](0);
235
209
  throw new RequestError('serverInvalidBody', _objectSpread(_objectSpread(_objectSpread({}, metadata), extractMediaHeaders(response)), {}, {
236
210
  statusCode: response.status
237
211
  }), _context2.t0 instanceof Error ? _context2.t0 : undefined);
238
-
239
212
  case 9:
240
213
  case "end":
241
214
  return _context2.stop();
@@ -243,7 +216,6 @@ export function createMapResponseToBlob(metadata) {
243
216
  }
244
217
  }, _callee2, null, [[0, 6]]);
245
218
  }));
246
-
247
219
  return function (_x4) {
248
220
  return _ref6.apply(this, arguments);
249
221
  };
@@ -255,30 +227,29 @@ export var DEFAULT_RETRY_OPTIONS = {
255
227
  maxAttempts: 5,
256
228
  // Current test delay is 60s, so retries should finish before if a promise takes < 1s
257
229
  factor: 2 // Good for polling, which is out main use case
258
-
259
230
  };
231
+
260
232
  export function cloneRequestError(error, extraMetadata) {
261
233
  var reason = error.reason,
262
- metadata = error.metadata,
263
- innerError = error.innerError;
234
+ metadata = error.metadata,
235
+ innerError = error.innerError;
264
236
  return new RequestError(reason, _objectSpread(_objectSpread({}, metadata), extraMetadata), innerError);
265
237
  }
266
238
  export function fetchRetry(_x5, _x6) {
267
239
  return _fetchRetry.apply(this, arguments);
268
240
  }
269
-
270
241
  function _fetchRetry() {
271
242
  _fetchRetry = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(functionToRetry, metadata) {
272
243
  var overwriteOptions,
273
- options,
274
- startTimeoutInMs,
275
- maxAttempts,
276
- factor,
277
- attempts,
278
- timeoutInMs,
279
- lastError,
280
- waitAndBumpTimeout,
281
- _args6 = arguments;
244
+ options,
245
+ startTimeoutInMs,
246
+ maxAttempts,
247
+ factor,
248
+ attempts,
249
+ timeoutInMs,
250
+ lastError,
251
+ waitAndBumpTimeout,
252
+ _args6 = arguments;
282
253
  return _regeneratorRuntime.wrap(function _callee6$(_context6) {
283
254
  while (1) {
284
255
  switch (_context6.prev = _context6.next) {
@@ -288,7 +259,6 @@ function _fetchRetry() {
288
259
  startTimeoutInMs = options.startTimeoutInMs, maxAttempts = options.maxAttempts, factor = options.factor;
289
260
  attempts = 0;
290
261
  timeoutInMs = startTimeoutInMs;
291
-
292
262
  waitAndBumpTimeout = /*#__PURE__*/function () {
293
263
  var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
294
264
  return _regeneratorRuntime.wrap(function _callee5$(_context5) {
@@ -297,11 +267,9 @@ function _fetchRetry() {
297
267
  case 0:
298
268
  _context5.next = 2;
299
269
  return waitPromise(timeoutInMs);
300
-
301
270
  case 2:
302
271
  timeoutInMs *= factor;
303
272
  attempts += 1;
304
-
305
273
  case 4:
306
274
  case "end":
307
275
  return _context5.stop();
@@ -309,70 +277,57 @@ function _fetchRetry() {
309
277
  }
310
278
  }, _callee5);
311
279
  }));
312
-
313
280
  return function waitAndBumpTimeout() {
314
281
  return _ref7.apply(this, arguments);
315
282
  };
316
283
  }();
317
-
318
284
  case 6:
319
285
  if (!(attempts < maxAttempts)) {
320
286
  _context6.next = 24;
321
287
  break;
322
288
  }
323
-
324
289
  _context6.prev = 7;
325
290
  _context6.next = 10;
326
291
  return functionToRetry();
327
-
328
292
  case 10:
329
293
  return _context6.abrupt("return", _context6.sent);
330
-
331
294
  case 13:
332
295
  _context6.prev = 13;
333
296
  _context6.t0 = _context6["catch"](7);
334
- lastError = _context6.t0; // don't retry if request was aborted by user
297
+ lastError = _context6.t0;
335
298
 
299
+ // don't retry if request was aborted by user
336
300
  if (!isAbortedRequestError(_context6.t0)) {
337
301
  _context6.next = 18;
338
302
  break;
339
303
  }
340
-
341
304
  throw new RequestError('clientAbortedRequest', metadata, _context6.t0);
342
-
343
305
  case 18:
344
306
  if (!(!isFetchNetworkError(_context6.t0) && !isRequestError(_context6.t0) || isRequestError(_context6.t0) && (!_context6.t0.metadata || !_context6.t0.metadata.statusCode || _context6.t0.metadata.statusCode < 500))) {
345
307
  _context6.next = 20;
346
308
  break;
347
309
  }
348
-
349
310
  throw _context6.t0;
350
-
351
311
  case 20:
352
312
  _context6.next = 22;
353
313
  return waitAndBumpTimeout();
354
-
355
314
  case 22:
356
315
  _context6.next = 6;
357
316
  break;
358
-
359
317
  case 24:
360
318
  if (!isRequestError(lastError)) {
361
319
  _context6.next = 26;
362
320
  break;
363
321
  }
364
-
365
322
  throw cloneRequestError(lastError, {
366
323
  attempts: attempts,
367
324
  clientExhaustedRetries: true
368
325
  });
369
-
370
326
  case 26:
371
327
  throw new RequestError('serverUnexpectedError', _objectSpread(_objectSpread({}, metadata), {}, {
372
328
  attempts: attempts,
373
329
  clientExhaustedRetries: true
374
330
  }), lastError);
375
-
376
331
  case 27:
377
332
  case "end":
378
333
  return _context6.stop();
@@ -382,30 +337,22 @@ function _fetchRetry() {
382
337
  }));
383
338
  return _fetchRetry.apply(this, arguments);
384
339
  }
385
-
386
340
  export function createRequestErrorReason(statusCode) {
387
341
  switch (statusCode) {
388
342
  case 400:
389
343
  return 'serverBadRequest';
390
-
391
344
  case 401:
392
345
  return 'serverUnauthorized';
393
-
394
346
  case 403:
395
347
  return 'serverForbidden';
396
-
397
348
  case 404:
398
349
  return 'serverNotFound';
399
-
400
350
  case 429:
401
351
  return 'serverRateLimited';
402
-
403
352
  case 500:
404
353
  return 'serverInternalError';
405
-
406
354
  case 502:
407
355
  return 'serverBadGateway';
408
-
409
356
  default:
410
357
  return 'serverUnexpectedError';
411
358
  }
@@ -422,7 +369,6 @@ export function createProcessFetchResponse(metadata) {
422
369
  if (response.ok || response.status < 400) {
423
370
  return response;
424
371
  }
425
-
426
372
  var requestError = createRequestErrorFromResponse(metadata, response);
427
373
  throw requestError;
428
374
  };
@@ -6,26 +6,24 @@ import { createUrl, fetchRetry, createProcessFetchResponse, extendHeaders } from
6
6
  export function request(_x) {
7
7
  return _request.apply(this, arguments);
8
8
  }
9
-
10
9
  function _request() {
11
10
  _request = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(url) {
12
11
  var options,
13
- controller,
14
- _options$method,
15
- method,
16
- endpoint,
17
- auth,
18
- params,
19
- headers,
20
- body,
21
- _options$clientOption,
22
- clientOptions,
23
- traceContext,
24
- retryOptions,
25
- metadata,
26
- doFetch,
27
- _args = arguments;
28
-
12
+ controller,
13
+ _options$method,
14
+ method,
15
+ endpoint,
16
+ auth,
17
+ params,
18
+ headers,
19
+ body,
20
+ _options$clientOption,
21
+ clientOptions,
22
+ traceContext,
23
+ retryOptions,
24
+ metadata,
25
+ doFetch,
26
+ _args = arguments;
29
27
  return _regeneratorRuntime.wrap(function _callee$(_context) {
30
28
  while (1) {
31
29
  switch (_context.prev = _context.next) {
@@ -39,7 +37,6 @@ function _request() {
39
37
  endpoint: endpoint,
40
38
  traceContext: traceContext
41
39
  }; // TODO BMPT-918: add client timeout feature behing a FF (using clientOptions.clientTimeout + Promise.race)
42
-
43
40
  doFetch = function doFetch() {
44
41
  return fetch(createUrl(url, {
45
42
  params: params
@@ -50,9 +47,7 @@ function _request() {
50
47
  signal: controller && controller.signal
51
48
  }).then(createProcessFetchResponse(metadata));
52
49
  };
53
-
54
50
  return _context.abrupt("return", fetchRetry(doFetch, metadata, retryOptions));
55
-
56
51
  case 7:
57
52
  case "end":
58
53
  return _context.stop();