@jetbrains/ring-ui-built 6.0.32 → 6.0.33
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.
- package/components/_helpers/_rollupPluginBabelHelpers.js +567 -1
- package/components/_helpers/anchor.js +6 -7
- package/components/_helpers/button__classes.js +14 -16
- package/components/_helpers/caption.js +20 -14
- package/components/_helpers/card.js +105 -95
- package/components/_helpers/dialog__body-scroll-preventer.js +19 -11
- package/components/_helpers/icon__svg.js +25 -22
- package/components/_helpers/input.js +177 -146
- package/components/_helpers/query-assist__suggestions.js +90 -74
- package/components/_helpers/select__filter.js +69 -48
- package/components/_helpers/services-link.js +37 -29
- package/components/_helpers/sidebar.js +107 -99
- package/components/_helpers/tab-link.js +7 -7
- package/components/_helpers/theme.js +40 -31
- package/components/_helpers/title.js +72 -57
- package/components/alert/alert.js +202 -150
- package/components/alert/container.js +41 -32
- package/components/alert-service/alert-service.js +170 -105
- package/components/analytics/analytics.js +22 -12
- package/components/analytics/analytics__custom-plugin.js +75 -54
- package/components/auth/auth.js +36 -4
- package/components/auth/auth__core.js +1471 -746
- package/components/auth/background-flow.js +127 -87
- package/components/auth/down-notification.js +73 -30
- package/components/auth/iframe-flow.js +133 -75
- package/components/auth/request-builder.js +82 -46
- package/components/auth/response-parser.js +116 -86
- package/components/auth/storage.js +334 -171
- package/components/auth/token-validator.js +242 -137
- package/components/auth/window-flow.js +134 -92
- package/components/auth-dialog/auth-dialog.js +172 -114
- package/components/auth-dialog-service/auth-dialog-service.js +31 -8
- package/components/avatar/avatar-example-datauri.js +1 -23
- package/components/avatar/avatar.js +152 -119
- package/components/avatar/fallback-avatar.js +38 -22
- package/components/badge/badge.js +45 -35
- package/components/button/button.js +107 -86
- package/components/button-group/button-group.js +33 -19
- package/components/button-set/button-set.js +32 -20
- package/components/button-toolbar/button-toolbar.js +31 -19
- package/components/caret/caret.js +220 -186
- package/components/checkbox/checkbox.js +101 -76
- package/components/clipboard/clipboard-fallback.js +10 -10
- package/components/clipboard/clipboard.js +132 -35
- package/components/code/code.js +166 -92
- package/components/collapse/collapse-content.js +64 -42
- package/components/collapse/collapse-context.js +2 -2
- package/components/collapse/collapse-control.js +14 -12
- package/components/collapse/collapse.js +17 -11
- package/components/collapse/consts.js +4 -4
- package/components/collapse/utils.js +3 -1
- package/components/confirm/confirm.js +104 -66
- package/components/confirm-service/confirm-service.js +59 -37
- package/components/content-layout/content-layout.js +64 -43
- package/components/content-layout/sidebar.js +1 -0
- package/components/contenteditable/contenteditable.js +59 -50
- package/components/control-label/control-label.js +9 -9
- package/components/data-list/data-list.js +182 -129
- package/components/data-list/data-list.mock.js +6 -2
- package/components/data-list/item.js +170 -143
- package/components/data-list/selection.js +136 -76
- package/components/data-list/title.js +12 -1
- package/components/date-picker/consts.js +26 -19
- package/components/date-picker/date-input.js +144 -113
- package/components/date-picker/date-picker.js +282 -227
- package/components/date-picker/date-popup.js +395 -350
- package/components/date-picker/day.js +116 -87
- package/components/date-picker/month-names.js +66 -43
- package/components/date-picker/month-slider.js +76 -51
- package/components/date-picker/month.js +25 -16
- package/components/date-picker/months.js +50 -43
- package/components/date-picker/weekdays.js +22 -12
- package/components/date-picker/years.js +110 -83
- package/components/dialog/dialog.js +190 -142
- package/components/dialog/dialog__body-scroll-preventer.js +4 -0
- package/components/dropdown/anchor.js +9 -0
- package/components/dropdown/dropdown.js +213 -182
- package/components/dropdown-menu/dropdown-menu.js +97 -71
- package/components/editable-heading/editable-heading.js +127 -75
- package/components/error-bubble/error-bubble.js +60 -31
- package/components/error-message/error-message.js +59 -39
- package/components/footer/footer.js +30 -27
- package/components/global/compose.js +10 -1
- package/components/global/composeRefs.js +12 -7
- package/components/global/controls-height.js +2 -2
- package/components/global/create-stateful-context.js +15 -15
- package/components/global/data-tests.js +14 -6
- package/components/global/dom.js +86 -47
- package/components/global/focus-sensor-hoc.js +132 -122
- package/components/global/fuzzy-highlight.js +36 -22
- package/components/global/get-event-key.js +8 -8
- package/components/global/get-uid.js +8 -4
- package/components/global/inject-styles.js +15 -10
- package/components/global/listeners.js +51 -27
- package/components/global/memoize.js +12 -6
- package/components/global/normalize-indent.js +50 -19
- package/components/global/promise-with-timeout.js +8 -6
- package/components/global/prop-types.js +5 -3
- package/components/global/react-dom-renderer.js +44 -28
- package/components/global/react-render-adapter.js +1 -1
- package/components/global/rerender-hoc.js +30 -12
- package/components/global/schedule-raf.js +6 -5
- package/components/global/sniffer.js +1 -1
- package/components/global/theme.js +22 -0
- package/components/global/trivial-template-tag.js +10 -3
- package/components/global/typescript-utils.js +6 -2
- package/components/global/url.js +26 -20
- package/components/global/use-event-callback.js +4 -6
- package/components/grid/col.js +52 -35
- package/components/grid/grid.js +31 -17
- package/components/grid/row.js +47 -35
- package/components/group/group.js +25 -17
- package/components/header/header.js +78 -33
- package/components/header/logo.js +36 -20
- package/components/header/profile.js +199 -166
- package/components/header/services-link.js +4 -0
- package/components/header/services.js +116 -73
- package/components/header/smart-profile.js +203 -111
- package/components/header/smart-services.js +113 -62
- package/components/header/tray-icon.js +37 -21
- package/components/header/tray.js +32 -21
- package/components/heading/heading.js +25 -24
- package/components/http/http.js +353 -203
- package/components/http/http.mock.js +101 -49
- package/components/hub-source/hub-source.js +190 -83
- package/components/hub-source/hub-source__user.js +44 -11
- package/components/hub-source/hub-source__users-groups.js +65 -37
- package/components/i18n/i18n-context.js +10 -7
- package/components/i18n/i18n.js +10 -7
- package/components/icon/icon.js +93 -76
- package/components/icon/icon__svg.js +8 -0
- package/components/icon/index.js +8 -0
- package/components/input/input.js +13 -0
- package/components/island/adaptive-island-hoc.js +43 -30
- package/components/island/content.js +132 -115
- package/components/island/header.js +70 -57
- package/components/island/island.js +40 -28
- package/components/island-legacy/content-legacy.js +25 -17
- package/components/island-legacy/header-legacy.js +27 -19
- package/components/island-legacy/island-legacy.js +25 -17
- package/components/link/clickableLink.js +59 -44
- package/components/link/link.js +68 -57
- package/components/list/consts.js +2 -2
- package/components/list/list.js +698 -611
- package/components/list/list__custom.js +62 -44
- package/components/list/list__hint.js +19 -10
- package/components/list/list__item.js +174 -133
- package/components/list/list__link.js +50 -37
- package/components/list/list__separator.js +24 -14
- package/components/list/list__title.js +32 -22
- package/components/list/list__users-groups-source.js +126 -54
- package/components/loader/loader.js +74 -43
- package/components/loader/loader__core.js +263 -198
- package/components/loader-inline/loader-inline.js +35 -23
- package/components/loader-screen/loader-screen.js +46 -25
- package/components/login-dialog/login-dialog.js +158 -111
- package/components/login-dialog/service.js +34 -8
- package/components/markdown/markdown.js +23 -15
- package/components/message/message.js +203 -161
- package/components/old-browsers-message/old-browsers-message.js +18 -11
- package/components/old-browsers-message/old-browsers-message__stop.js +7 -0
- package/components/old-browsers-message/white-list.js +16 -8
- package/components/pager/pager.js +271 -212
- package/components/panel/panel.js +25 -17
- package/components/permissions/permissions.js +172 -127
- package/components/permissions/permissions__cache.js +224 -194
- package/components/popup/popup.consts.js +1 -1
- package/components/popup/popup.js +343 -284
- package/components/popup/popup.target.js +8 -9
- package/components/popup/position.js +106 -96
- package/components/popup-menu/popup-menu.js +81 -44
- package/components/progress-bar/progress-bar.js +104 -87
- package/components/query-assist/query-assist.js +916 -838
- package/components/query-assist/query-assist__suggestions.js +30 -1
- package/components/radio/radio.js +34 -19
- package/components/radio/radio__item.js +69 -52
- package/components/select/select.js +957 -852
- package/components/select/select__filter.js +30 -0
- package/components/select/select__popup.js +487 -373
- package/components/shortcuts/core.js +217 -166
- package/components/shortcuts/shortcut-title.js +11 -6
- package/components/shortcuts/shortcuts-hoc.js +45 -19
- package/components/shortcuts/shortcuts.js +75 -50
- package/components/slider/slider.js +122 -99
- package/components/slider/slider.utils.js +24 -14
- package/components/storage/storage.js +33 -4
- package/components/storage/storage__fallback.js +224 -149
- package/components/storage/storage__local.js +153 -90
- package/components/tab-trap/tab-trap.js +153 -122
- package/components/table/cell.js +26 -14
- package/components/table/disable-hover-hoc.js +51 -33
- package/components/table/header-cell.js +89 -64
- package/components/table/header.js +132 -104
- package/components/table/multitable.js +125 -107
- package/components/table/row-with-focus-sensor.js +69 -25
- package/components/table/row.js +216 -175
- package/components/table/selection-adapter.js +3 -1
- package/components/table/selection-shortcuts-hoc.js +181 -180
- package/components/table/selection.js +226 -156
- package/components/table/smart-table.js +88 -50
- package/components/table/table.js +358 -289
- package/components/tabs/collapsible-more.js +79 -46
- package/components/tabs/collapsible-tab.js +38 -31
- package/components/tabs/collapsible-tabs.js +153 -88
- package/components/tabs/custom-item.js +2 -4
- package/components/tabs/dumb-tabs.js +117 -74
- package/components/tabs/smart-tabs.js +69 -29
- package/components/tabs/tab-link.js +5 -1
- package/components/tabs/tab.js +31 -19
- package/components/tabs/tabs.js +31 -0
- package/components/tag/tag.js +173 -133
- package/components/tags-input/tags-input.js +427 -329
- package/components/tags-list/tags-list.js +78 -57
- package/components/text/text.js +39 -28
- package/components/toggle/toggle.js +70 -56
- package/components/tooltip/tooltip.js +190 -146
- package/components/user-agreement/service.js +371 -228
- package/components/user-agreement/toolbox.eula.js +1 -160
- package/components/user-agreement/user-agreement.js +120 -85
- package/components/user-card/card.js +29 -0
- package/components/user-card/smart-user-card-tooltip.js +111 -51
- package/components/user-card/tooltip.js +84 -47
- package/components/user-card/user-card.js +29 -0
- package/package.json +1 -1
package/components/http/http.js
CHANGED
@@ -1,234 +1,384 @@
|
|
1
|
+
import { a as _inherits, b as _createClass, c as _objectWithoutProperties, d as _objectSpread2, j as _slicedToArray, f as _classCallCheck, g as _callSuper, _ as _defineProperty, h as _asyncToGenerator, i as _regeneratorRuntime } from '../_helpers/_rollupPluginBabelHelpers.js';
|
2
|
+
import 'core-js/modules/es.array.concat.js';
|
3
|
+
import 'core-js/modules/es.array.index-of.js';
|
4
|
+
import 'core-js/modules/es.array.iterator.js';
|
5
|
+
import 'core-js/modules/es.object.entries.js';
|
6
|
+
import 'core-js/modules/es.object.to-string.js';
|
7
|
+
import 'core-js/modules/es.promise.js';
|
8
|
+
import 'core-js/modules/es.reflect.delete-property.js';
|
9
|
+
import 'core-js/modules/es.weak-map.js';
|
10
|
+
import 'core-js/modules/web.dom-collections.for-each.js';
|
11
|
+
import 'core-js/modules/web.dom-collections.iterator.js';
|
1
12
|
import ExtendableError from 'es6-error';
|
2
13
|
import { encodeURL, joinBaseURLAndPath } from '../global/url.js';
|
14
|
+
import 'core-js/modules/es.regexp.exec.js';
|
15
|
+
import 'core-js/modules/es.string.match.js';
|
16
|
+
import 'core-js/modules/es.string.replace.js';
|
3
17
|
|
18
|
+
var _excluded = ["body", "query"],
|
19
|
+
_excluded2 = ["headers"],
|
20
|
+
_excluded3 = ["headers", "body", "query", "sendRawBody"];
|
4
21
|
/**
|
5
22
|
* @name HTTP
|
6
23
|
*/
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
24
|
+
var TOKEN_TYPE = 'Bearer';
|
25
|
+
var STATUS_OK_IF_MORE_THAN = 200;
|
26
|
+
var STATUS_BAD_IF_MORE_THAN = 300;
|
27
|
+
var defaultFetchConfig = {
|
11
28
|
headers: {
|
12
29
|
'Content-Type': 'application/json',
|
13
30
|
Accept: 'application/json'
|
14
31
|
},
|
15
32
|
credentials: 'same-origin'
|
16
33
|
};
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
34
|
+
var HTTPError = /*#__PURE__*/function (_ExtendableError) {
|
35
|
+
function HTTPError(response) {
|
36
|
+
var _this;
|
37
|
+
var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
38
|
+
_classCallCheck(this, HTTPError);
|
39
|
+
_this = _callSuper(this, HTTPError, ["".concat(response.status, " ").concat(response.statusText || '')]);
|
40
|
+
_defineProperty(_this, "data", void 0);
|
41
|
+
_defineProperty(_this, "status", void 0);
|
42
|
+
_this.data = data;
|
43
|
+
_this.status = response.status;
|
44
|
+
return _this;
|
25
45
|
}
|
26
|
-
|
27
|
-
|
46
|
+
_inherits(HTTPError, _ExtendableError);
|
47
|
+
return _createClass(HTTPError);
|
48
|
+
}(ExtendableError);
|
49
|
+
var CODE = {
|
28
50
|
UNAUTHORIZED: 401
|
29
51
|
};
|
30
52
|
function isRawBody(params) {
|
31
53
|
return params.sendRawBody === true;
|
32
54
|
}
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
...fetchConfig,
|
53
|
-
headers: {
|
54
|
-
...headers,
|
55
|
-
...fetchConfig.headers
|
56
|
-
}
|
57
|
-
};
|
58
|
-
}
|
59
|
-
setAuth = auth => {
|
60
|
-
this.requestToken = () => auth.requestToken();
|
61
|
-
this.shouldRefreshToken = auth.constructor.shouldRefreshToken;
|
62
|
-
this.forceTokenUpdate = () => auth.forceTokenUpdate();
|
63
|
-
};
|
64
|
-
setBaseUrl = baseUrl => {
|
65
|
-
this.baseUrl = baseUrl;
|
66
|
-
};
|
67
|
-
_fetch() {
|
68
|
-
return fetch(...arguments);
|
69
|
-
}
|
70
|
-
_makeRequestUrl(url, queryObject) {
|
71
|
-
const urlWithQuery = encodeURL(url, queryObject);
|
72
|
-
return joinBaseURLAndPath(this.baseUrl, urlWithQuery);
|
73
|
-
}
|
74
|
-
_performRequest(url, token) {
|
75
|
-
let params = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
76
|
-
const {
|
77
|
-
headers,
|
78
|
-
body,
|
79
|
-
query = {},
|
80
|
-
sendRawBody,
|
81
|
-
...fetchConfig
|
82
|
-
} = params;
|
83
|
-
const combinedHeaders = {
|
84
|
-
...this.fetchConfig.headers,
|
85
|
-
...(token ? {
|
86
|
-
Authorization: `${TOKEN_TYPE} ${token}`
|
87
|
-
} : {}),
|
88
|
-
...headers
|
89
|
-
};
|
90
|
-
Object.entries(combinedHeaders).forEach(_ref => {
|
91
|
-
let [key, header] = _ref;
|
92
|
-
if (header === null || header === undefined) {
|
93
|
-
Reflect.deleteProperty(combinedHeaders, key);
|
94
|
-
}
|
55
|
+
var HTTP = /*#__PURE__*/function () {
|
56
|
+
function HTTP(_auth, _baseUrl) {
|
57
|
+
var _this2 = this;
|
58
|
+
var _fetchConfig = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
59
|
+
_classCallCheck(this, HTTP);
|
60
|
+
_defineProperty(this, "baseUrl", null);
|
61
|
+
_defineProperty(this, "_requestsMeta", new WeakMap());
|
62
|
+
_defineProperty(this, "fetchConfig", void 0);
|
63
|
+
_defineProperty(this, "requestToken", void 0);
|
64
|
+
_defineProperty(this, "shouldRefreshToken", void 0);
|
65
|
+
_defineProperty(this, "forceTokenUpdate", void 0);
|
66
|
+
_defineProperty(this, "setAuth", function (auth) {
|
67
|
+
_this2.requestToken = function () {
|
68
|
+
return auth.requestToken();
|
69
|
+
};
|
70
|
+
_this2.shouldRefreshToken = auth.constructor.shouldRefreshToken;
|
71
|
+
_this2.forceTokenUpdate = function () {
|
72
|
+
return auth.forceTokenUpdate();
|
73
|
+
};
|
95
74
|
});
|
96
|
-
|
97
|
-
|
98
|
-
bodyToSend = params.body;
|
99
|
-
} else {
|
100
|
-
bodyToSend = params.body === null || params.body === undefined || params.body === '' ? params.body : JSON.stringify(body);
|
101
|
-
}
|
102
|
-
return this._fetch(this._makeRequestUrl(url, query), {
|
103
|
-
...this.fetchConfig,
|
104
|
-
headers: combinedHeaders,
|
105
|
-
...fetchConfig,
|
106
|
-
body: bodyToSend
|
75
|
+
_defineProperty(this, "setBaseUrl", function (baseUrl) {
|
76
|
+
_this2.baseUrl = baseUrl;
|
107
77
|
});
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
78
|
+
_defineProperty(this, "fetch", /*#__PURE__*/function () {
|
79
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(url) {
|
80
|
+
var params,
|
81
|
+
body,
|
82
|
+
_params$query,
|
83
|
+
query,
|
84
|
+
fetchConfig,
|
85
|
+
response,
|
86
|
+
_args = arguments;
|
87
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
88
|
+
while (1) switch (_context.prev = _context.next) {
|
89
|
+
case 0:
|
90
|
+
params = _args.length > 1 && _args[1] !== undefined ? _args[1] : {};
|
91
|
+
body = params.body, _params$query = params.query, query = _params$query === void 0 ? {} : _params$query, fetchConfig = _objectWithoutProperties(params, _excluded);
|
92
|
+
_context.next = 4;
|
93
|
+
return _this2._fetch(_this2._makeRequestUrl(url, query), _objectSpread2(_objectSpread2({}, fetchConfig), {}, {
|
94
|
+
headers: fetchConfig.headers,
|
95
|
+
body: body !== null && body !== undefined && body !== '' ? JSON.stringify(body) : body
|
96
|
+
}));
|
97
|
+
case 4:
|
98
|
+
response = _context.sent;
|
99
|
+
return _context.abrupt("return", _this2._processResponse(response));
|
100
|
+
case 6:
|
101
|
+
case "end":
|
102
|
+
return _context.stop();
|
103
|
+
}
|
104
|
+
}, _callee);
|
105
|
+
}));
|
106
|
+
return function (_x) {
|
107
|
+
return _ref.apply(this, arguments);
|
108
|
+
};
|
109
|
+
}());
|
110
|
+
_defineProperty(this, "request", /*#__PURE__*/function () {
|
111
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(url, params) {
|
112
|
+
var _this2$requestToken;
|
113
|
+
var token, response, _this2$shouldRefreshT, shouldRefreshToken, _this2$forceTokenUpda;
|
114
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
115
|
+
while (1) switch (_context2.prev = _context2.next) {
|
116
|
+
case 0:
|
117
|
+
_context2.next = 2;
|
118
|
+
return (_this2$requestToken = _this2.requestToken) === null || _this2$requestToken === void 0 ? void 0 : _this2$requestToken.call(_this2);
|
119
|
+
case 2:
|
120
|
+
token = _context2.sent;
|
121
|
+
_context2.next = 5;
|
122
|
+
return _this2._performRequest(url, token, params);
|
123
|
+
case 5:
|
124
|
+
response = _context2.sent;
|
125
|
+
_context2.prev = 6;
|
126
|
+
_context2.next = 9;
|
127
|
+
return _this2._processResponse(response);
|
128
|
+
case 9:
|
129
|
+
return _context2.abrupt("return", _context2.sent);
|
130
|
+
case 12:
|
131
|
+
_context2.prev = 12;
|
132
|
+
_context2.t0 = _context2["catch"](6);
|
133
|
+
if (_context2.t0 instanceof HTTPError) {
|
134
|
+
_context2.next = 16;
|
135
|
+
break;
|
136
|
+
}
|
137
|
+
throw _context2.t0;
|
138
|
+
case 16:
|
139
|
+
shouldRefreshToken = typeof _context2.t0.data.error === 'string' ? (_this2$shouldRefreshT = _this2.shouldRefreshToken) === null || _this2$shouldRefreshT === void 0 ? void 0 : _this2$shouldRefreshT.call(_this2, _context2.t0.data.error) : false;
|
140
|
+
if (!shouldRefreshToken) {
|
141
|
+
_context2.next = 25;
|
142
|
+
break;
|
143
|
+
}
|
144
|
+
_context2.next = 20;
|
145
|
+
return (_this2$forceTokenUpda = _this2.forceTokenUpdate) === null || _this2$forceTokenUpda === void 0 ? void 0 : _this2$forceTokenUpda.call(_this2);
|
146
|
+
case 20:
|
147
|
+
token = _context2.sent;
|
148
|
+
_context2.next = 23;
|
149
|
+
return _this2._performRequest(url, token, params);
|
150
|
+
case 23:
|
151
|
+
response = _context2.sent;
|
152
|
+
return _context2.abrupt("return", _this2._processResponse(response));
|
153
|
+
case 25:
|
154
|
+
throw _context2.t0;
|
155
|
+
case 26:
|
156
|
+
case "end":
|
157
|
+
return _context2.stop();
|
158
|
+
}
|
159
|
+
}, _callee2, null, [[6, 12]]);
|
160
|
+
}));
|
161
|
+
return function (_x2, _x3) {
|
162
|
+
return _ref2.apply(this, arguments);
|
163
|
+
};
|
164
|
+
}());
|
165
|
+
_defineProperty(this, "getMetaForResponse", function (response) {
|
166
|
+
return _this2._requestsMeta.get(response);
|
167
|
+
});
|
168
|
+
_defineProperty(this, "get", function (url, params) {
|
169
|
+
return _this2.request(url, _objectSpread2(_objectSpread2({}, params), {}, {
|
170
|
+
method: 'GET'
|
171
|
+
}));
|
172
|
+
});
|
173
|
+
_defineProperty(this, "post", function (url, params) {
|
174
|
+
return _this2.request(url, _objectSpread2(_objectSpread2({}, params), {}, {
|
175
|
+
method: 'POST'
|
176
|
+
}));
|
177
|
+
});
|
178
|
+
_defineProperty(this, "delete", function (url, params) {
|
179
|
+
return _this2.request(url, _objectSpread2(_objectSpread2({}, params), {}, {
|
180
|
+
method: 'DELETE'
|
181
|
+
}));
|
182
|
+
});
|
183
|
+
_defineProperty(this, "put", function (url, params) {
|
184
|
+
return _this2.request(url, _objectSpread2(_objectSpread2({}, params), {}, {
|
185
|
+
method: 'PUT'
|
186
|
+
}));
|
187
|
+
});
|
188
|
+
/**
|
189
|
+
* Usage: const {promise, abort} = http.abortify(http.get<{id: string}>)('http://test.com');
|
190
|
+
* @param method
|
191
|
+
*/
|
192
|
+
_defineProperty(this, "abortify", function (method) {
|
193
|
+
return function () {
|
194
|
+
for (var _len = arguments.length, _ref3 = new Array(_len), _key = 0; _key < _len; _key++) {
|
195
|
+
_ref3[_key] = arguments[_key];
|
196
|
+
}
|
197
|
+
var url = _ref3[0],
|
198
|
+
params = _ref3[1];
|
199
|
+
var ctrl = new AbortController();
|
200
|
+
if (params && !('signal' in params)) {
|
201
|
+
params.signal = ctrl.signal;
|
202
|
+
}
|
203
|
+
return {
|
204
|
+
promise: method.call(_this2, url, params),
|
205
|
+
abort: function abort() {
|
206
|
+
return ctrl.abort();
|
207
|
+
}
|
208
|
+
};
|
209
|
+
};
|
210
|
+
});
|
211
|
+
if (_auth) {
|
212
|
+
this.setAuth(_auth);
|
213
|
+
}
|
214
|
+
this.setBaseUrl(_baseUrl);
|
215
|
+
var headers = defaultFetchConfig.headers,
|
216
|
+
defaultConfig = _objectWithoutProperties(defaultFetchConfig, _excluded2);
|
217
|
+
this.fetchConfig = _objectSpread2(_objectSpread2(_objectSpread2({}, defaultConfig), _fetchConfig), {}, {
|
218
|
+
headers: _objectSpread2(_objectSpread2({}, headers), _fetchConfig.headers)
|
127
219
|
});
|
128
220
|
}
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
let resJson;
|
134
|
-
try {
|
135
|
-
resJson = await (isJson ? response.json?.() : response.text?.());
|
136
|
-
} catch (err) {
|
137
|
-
// noop
|
138
|
-
}
|
139
|
-
throw new HTTPError(response, resJson);
|
221
|
+
return _createClass(HTTP, [{
|
222
|
+
key: "_fetch",
|
223
|
+
value: function _fetch() {
|
224
|
+
return fetch.apply(void 0, arguments);
|
140
225
|
}
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
this.
|
146
|
-
return parsedResponse;
|
147
|
-
} catch (err) {
|
148
|
-
return response;
|
226
|
+
}, {
|
227
|
+
key: "_makeRequestUrl",
|
228
|
+
value: function _makeRequestUrl(url, queryObject) {
|
229
|
+
var urlWithQuery = encodeURL(url, queryObject);
|
230
|
+
return joinBaseURLAndPath(this.baseUrl, urlWithQuery);
|
149
231
|
}
|
150
|
-
}
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
}
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
232
|
+
}, {
|
233
|
+
key: "_performRequest",
|
234
|
+
value: function _performRequest(url, token) {
|
235
|
+
var params = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
236
|
+
var headers = params.headers,
|
237
|
+
body = params.body,
|
238
|
+
_params$query2 = params.query,
|
239
|
+
query = _params$query2 === void 0 ? {} : _params$query2;
|
240
|
+
params.sendRawBody;
|
241
|
+
var fetchConfig = _objectWithoutProperties(params, _excluded3);
|
242
|
+
var combinedHeaders = _objectSpread2(_objectSpread2(_objectSpread2({}, this.fetchConfig.headers), token ? {
|
243
|
+
Authorization: "".concat(TOKEN_TYPE, " ").concat(token)
|
244
|
+
} : {}), headers);
|
245
|
+
Object.entries(combinedHeaders).forEach(function (_ref4) {
|
246
|
+
var _ref5 = _slicedToArray(_ref4, 2),
|
247
|
+
key = _ref5[0],
|
248
|
+
header = _ref5[1];
|
249
|
+
if (header === null || header === undefined) {
|
250
|
+
Reflect.deleteProperty(combinedHeaders, key);
|
251
|
+
}
|
167
252
|
});
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
return this._processResponse(response);
|
174
|
-
}
|
175
|
-
request = async (url, params) => {
|
176
|
-
let token = await this.requestToken?.();
|
177
|
-
let response = await this._performRequest(url, token, params);
|
178
|
-
try {
|
179
|
-
// Wait for result to catch an HTTP error
|
180
|
-
return await this._processResponse(response);
|
181
|
-
} catch (error) {
|
182
|
-
if (!(error instanceof HTTPError)) {
|
183
|
-
throw error;
|
184
|
-
}
|
185
|
-
const shouldRefreshToken = typeof error.data.error === 'string' ? this.shouldRefreshToken?.(error.data.error) : false;
|
186
|
-
if (shouldRefreshToken) {
|
187
|
-
token = await this.forceTokenUpdate?.();
|
188
|
-
response = await this._performRequest(url, token, params);
|
189
|
-
return this._processResponse(response);
|
253
|
+
var bodyToSend;
|
254
|
+
if (isRawBody(params)) {
|
255
|
+
bodyToSend = params.body;
|
256
|
+
} else {
|
257
|
+
bodyToSend = params.body === null || params.body === undefined || params.body === '' ? params.body : JSON.stringify(body);
|
190
258
|
}
|
191
|
-
|
259
|
+
return this._fetch(this._makeRequestUrl(url, query), _objectSpread2(_objectSpread2(_objectSpread2({}, this.fetchConfig), {}, {
|
260
|
+
headers: combinedHeaders
|
261
|
+
}, fetchConfig), {}, {
|
262
|
+
body: bodyToSend
|
263
|
+
}));
|
192
264
|
}
|
193
|
-
}
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
265
|
+
}, {
|
266
|
+
key: "_storeRequestMeta",
|
267
|
+
value: function _storeRequestMeta(parsedResponse, rawResponse) {
|
268
|
+
var headers = rawResponse.headers,
|
269
|
+
ok = rawResponse.ok,
|
270
|
+
redirected = rawResponse.redirected,
|
271
|
+
status = rawResponse.status,
|
272
|
+
statusText = rawResponse.statusText,
|
273
|
+
type = rawResponse.type,
|
274
|
+
url = rawResponse.url;
|
275
|
+
this._requestsMeta.set(parsedResponse, {
|
276
|
+
headers,
|
277
|
+
ok,
|
278
|
+
redirected,
|
279
|
+
status,
|
280
|
+
statusText,
|
281
|
+
type,
|
282
|
+
url
|
283
|
+
});
|
284
|
+
}
|
285
|
+
}, {
|
286
|
+
key: "_processResponse",
|
287
|
+
value: function () {
|
288
|
+
var _processResponse2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(response) {
|
289
|
+
var _response$headers;
|
290
|
+
var contentType, isJson, resJson, _response$json, _response$text, _response$json2, _response$text2, parsedResponse;
|
291
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
292
|
+
while (1) switch (_context3.prev = _context3.next) {
|
293
|
+
case 0:
|
294
|
+
contentType = (_response$headers = response.headers) === null || _response$headers === void 0 ? void 0 : _response$headers.get('content-type');
|
295
|
+
isJson = contentType && contentType.indexOf('application/json') !== -1;
|
296
|
+
if (!(response.status != null && HTTP._isErrorStatus(response.status))) {
|
297
|
+
_context3.next = 12;
|
298
|
+
break;
|
299
|
+
}
|
300
|
+
_context3.prev = 3;
|
301
|
+
_context3.next = 6;
|
302
|
+
return isJson ? (_response$json = response.json) === null || _response$json === void 0 ? void 0 : _response$json.call(response) : (_response$text = response.text) === null || _response$text === void 0 ? void 0 : _response$text.call(response);
|
303
|
+
case 6:
|
304
|
+
resJson = _context3.sent;
|
305
|
+
_context3.next = 11;
|
306
|
+
break;
|
307
|
+
case 9:
|
308
|
+
_context3.prev = 9;
|
309
|
+
_context3.t0 = _context3["catch"](3);
|
310
|
+
case 11:
|
311
|
+
throw new HTTPError(response, resJson);
|
312
|
+
case 12:
|
313
|
+
_context3.prev = 12;
|
314
|
+
if (!isJson) {
|
315
|
+
_context3.next = 17;
|
316
|
+
break;
|
317
|
+
}
|
318
|
+
_context3.t1 = (_response$json2 = response.json) === null || _response$json2 === void 0 ? void 0 : _response$json2.call(response);
|
319
|
+
_context3.next = 21;
|
320
|
+
break;
|
321
|
+
case 17:
|
322
|
+
_context3.next = 19;
|
323
|
+
return (_response$text2 = response.text) === null || _response$text2 === void 0 ? void 0 : _response$text2.call(response);
|
324
|
+
case 19:
|
325
|
+
_context3.t2 = _context3.sent;
|
326
|
+
_context3.t1 = {
|
327
|
+
data: _context3.t2
|
328
|
+
};
|
329
|
+
case 21:
|
330
|
+
_context3.next = 23;
|
331
|
+
return _context3.t1;
|
332
|
+
case 23:
|
333
|
+
parsedResponse = _context3.sent;
|
334
|
+
this._storeRequestMeta(parsedResponse, response);
|
335
|
+
return _context3.abrupt("return", parsedResponse);
|
336
|
+
case 28:
|
337
|
+
_context3.prev = 28;
|
338
|
+
_context3.t3 = _context3["catch"](12);
|
339
|
+
return _context3.abrupt("return", response);
|
340
|
+
case 31:
|
341
|
+
case "end":
|
342
|
+
return _context3.stop();
|
343
|
+
}
|
344
|
+
}, _callee3, this, [[3, 9], [12, 28]]);
|
345
|
+
}));
|
346
|
+
function _processResponse(_x4) {
|
347
|
+
return _processResponse2.apply(this, arguments);
|
220
348
|
}
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
349
|
+
return _processResponse;
|
350
|
+
}()
|
351
|
+
}, {
|
352
|
+
key: "authorizedFetch",
|
353
|
+
value: function () {
|
354
|
+
var _authorizedFetch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
355
|
+
var response,
|
356
|
+
_args4 = arguments;
|
357
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
358
|
+
while (1) switch (_context4.prev = _context4.next) {
|
359
|
+
case 0:
|
360
|
+
_context4.next = 2;
|
361
|
+
return this._performRequest.apply(this, _args4);
|
362
|
+
case 2:
|
363
|
+
response = _context4.sent;
|
364
|
+
return _context4.abrupt("return", this._processResponse(response));
|
365
|
+
case 4:
|
366
|
+
case "end":
|
367
|
+
return _context4.stop();
|
368
|
+
}
|
369
|
+
}, _callee4, this);
|
370
|
+
}));
|
371
|
+
function authorizedFetch() {
|
372
|
+
return _authorizedFetch.apply(this, arguments);
|
225
373
|
}
|
226
|
-
return
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
}
|
374
|
+
return authorizedFetch;
|
375
|
+
}()
|
376
|
+
}], [{
|
377
|
+
key: "_isErrorStatus",
|
378
|
+
value: function _isErrorStatus(status) {
|
379
|
+
return status < STATUS_OK_IF_MORE_THAN || status >= STATUS_BAD_IF_MORE_THAN;
|
380
|
+
}
|
381
|
+
}]);
|
382
|
+
}();
|
233
383
|
|
234
384
|
export { CODE, HTTPError, HTTP as default, defaultFetchConfig };
|