@jetbrains/ring-ui-built 7.0.0-beta.1 → 7.0.0-beta.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 (241) hide show
  1. package/components/_helpers/_rollupPluginBabelHelpers.js +1 -504
  2. package/components/_helpers/anchor.js +7 -5
  3. package/components/_helpers/button__classes.js +15 -13
  4. package/components/_helpers/caption.js +11 -17
  5. package/components/_helpers/card.js +92 -96
  6. package/components/_helpers/dialog__body-scroll-preventer.js +10 -17
  7. package/components/_helpers/header.js +1 -1
  8. package/components/_helpers/icon__svg.js +27 -23
  9. package/components/_helpers/input.js +150 -171
  10. package/components/_helpers/query-assist__suggestions.js +78 -93
  11. package/components/_helpers/select__filter.js +56 -67
  12. package/components/_helpers/services-link.js +23 -29
  13. package/components/_helpers/sidebar.js +91 -93
  14. package/components/_helpers/tab-link.js +8 -6
  15. package/components/_helpers/theme.js +55 -51
  16. package/components/_helpers/title.js +59 -69
  17. package/components/alert/alert.js +112 -156
  18. package/components/alert/container.js +32 -39
  19. package/components/alert-service/alert-service.js +104 -161
  20. package/components/analytics/analytics.js +12 -20
  21. package/components/analytics/analytics__custom-plugin.js +52 -68
  22. package/components/auth/auth.js +2 -27
  23. package/components/auth/auth__core.d.ts +1 -1
  24. package/components/auth/auth__core.js +742 -1428
  25. package/components/auth/background-flow.js +84 -121
  26. package/components/auth/down-notification.js +31 -69
  27. package/components/auth/iframe-flow.js +70 -123
  28. package/components/auth/request-builder.js +46 -77
  29. package/components/auth/response-parser.js +84 -112
  30. package/components/auth/storage.js +160 -318
  31. package/components/auth/token-validator.js +132 -227
  32. package/components/auth/window-flow.js +84 -121
  33. package/components/auth-dialog/auth-dialog.js +99 -150
  34. package/components/auth-dialog-service/auth-dialog-service.js +6 -26
  35. package/components/avatar/avatar-example-datauri.js +1 -1
  36. package/components/avatar/avatar.js +94 -123
  37. package/components/avatar/fallback-avatar.js +20 -34
  38. package/components/badge/badge.js +32 -38
  39. package/components/breadcrumbs/breadcrumbs.js +13 -17
  40. package/components/button/button.js +67 -80
  41. package/components/button-group/button-group.js +27 -36
  42. package/components/button-set/button-set.js +19 -27
  43. package/components/button-toolbar/button-toolbar.js +17 -25
  44. package/components/caret/caret.js +184 -211
  45. package/components/checkbox/checkbox.js +69 -86
  46. package/components/clipboard/clipboard-fallback.js +7 -7
  47. package/components/clipboard/clipboard.js +36 -128
  48. package/components/code/code.js +83 -151
  49. package/components/collapse/collapse-content.js +42 -60
  50. package/components/collapse/collapse-context.js +2 -2
  51. package/components/collapse/collapse-control.js +12 -12
  52. package/components/collapse/collapse.js +12 -17
  53. package/components/collapse/consts.js +4 -4
  54. package/components/collapse/utils.js +1 -3
  55. package/components/confirm/confirm.js +57 -87
  56. package/components/confirm-service/confirm-service.js +23 -44
  57. package/components/content-layout/content-layout.js +41 -56
  58. package/components/content-layout/sidebar.js +1 -1
  59. package/components/contenteditable/contenteditable.js +38 -46
  60. package/components/control-help/control-help.js +5 -3
  61. package/components/control-label/control-label.js +9 -8
  62. package/components/data-list/data-list.js +113 -156
  63. package/components/data-list/data-list.mock.js +3 -5
  64. package/components/data-list/item.js +120 -140
  65. package/components/data-list/selection.js +77 -135
  66. package/components/data-list/title.js +2 -10
  67. package/components/date-picker/consts.js +16 -22
  68. package/components/date-picker/date-input.js +99 -124
  69. package/components/date-picker/date-picker.js +140 -184
  70. package/components/date-picker/date-popup.js +280 -327
  71. package/components/date-picker/day.js +71 -94
  72. package/components/date-picker/month-names.js +41 -59
  73. package/components/date-picker/month-slider.js +42 -61
  74. package/components/date-picker/month.js +17 -24
  75. package/components/date-picker/months.js +44 -49
  76. package/components/date-picker/weekdays.js +12 -21
  77. package/components/date-picker/years.js +77 -98
  78. package/components/dialog/dialog.js +151 -187
  79. package/components/dialog/dialog__body-scroll-preventer.js +0 -3
  80. package/components/dropdown/anchor.js +0 -6
  81. package/components/dropdown/dropdown.js +134 -154
  82. package/components/dropdown-menu/dropdown-menu.js +59 -87
  83. package/components/editable-heading/editable-heading.js +69 -116
  84. package/components/error-bubble/error-bubble.js +29 -54
  85. package/components/error-message/error-message.js +34 -49
  86. package/components/footer/footer.js +27 -28
  87. package/components/global/compose.js +1 -8
  88. package/components/global/composeRefs.d.ts +0 -3
  89. package/components/global/composeRefs.js +8 -15
  90. package/components/global/controls-height.js +2 -2
  91. package/components/global/create-stateful-context.js +14 -13
  92. package/components/global/data-tests.js +7 -12
  93. package/components/global/dom.js +49 -82
  94. package/components/global/focus-sensor-hoc.js +99 -106
  95. package/components/global/fuzzy-highlight.js +23 -34
  96. package/components/global/get-event-key.js +8 -8
  97. package/components/global/get-uid.js +3 -7
  98. package/components/global/inject-styles.js +7 -14
  99. package/components/global/listeners.js +28 -47
  100. package/components/global/memoize.js +6 -10
  101. package/components/global/normalize-indent.js +19 -46
  102. package/components/global/promise-with-timeout.js +6 -8
  103. package/components/global/prop-types.js +3 -5
  104. package/components/global/react-dom-renderer.js +29 -40
  105. package/components/global/rerender-hoc.js +16 -32
  106. package/components/global/schedule-raf.js +4 -4
  107. package/components/global/sniffer.js +1 -1
  108. package/components/global/theme.d.ts +3 -0
  109. package/components/global/theme.js +2 -19
  110. package/components/global/trivial-template-tag.js +4 -9
  111. package/components/global/typescript-utils.js +2 -6
  112. package/components/global/url.js +20 -23
  113. package/components/global/use-event-callback.js +7 -4
  114. package/components/grid/col.js +27 -39
  115. package/components/grid/grid.js +18 -27
  116. package/components/grid/row.js +23 -30
  117. package/components/group/group.js +16 -22
  118. package/components/header/header-icon.js +19 -31
  119. package/components/header/header.d.ts +0 -1
  120. package/components/header/header.js +30 -64
  121. package/components/header/links.d.ts +2 -0
  122. package/components/header/links.js +20 -0
  123. package/components/header/logo.js +15 -26
  124. package/components/header/profile.js +124 -150
  125. package/components/header/services-link.js +1 -3
  126. package/components/header/services.js +64 -97
  127. package/components/header/smart-profile.js +101 -178
  128. package/components/header/smart-services.js +55 -90
  129. package/components/header/tray.js +21 -30
  130. package/components/heading/heading.js +21 -20
  131. package/components/http/http.js +162 -319
  132. package/components/http/http.mock.js +50 -98
  133. package/components/hub-source/hub-source.js +77 -182
  134. package/components/hub-source/hub-source__user.js +9 -37
  135. package/components/hub-source/hub-source__users-groups.js +34 -60
  136. package/components/i18n/i18n-context.js +7 -8
  137. package/components/i18n/i18n.js +3 -6
  138. package/components/icon/icon.js +60 -74
  139. package/components/icon/icon__svg.js +0 -5
  140. package/components/icon/index.js +0 -5
  141. package/components/input/input.js +1 -11
  142. package/components/island/adaptive-island-hoc.js +29 -37
  143. package/components/island/content.js +100 -110
  144. package/components/island/header.js +56 -66
  145. package/components/island/island.js +25 -33
  146. package/components/island-legacy/content-legacy.js +16 -22
  147. package/components/island-legacy/header-legacy.js +19 -25
  148. package/components/island-legacy/island-legacy.js +16 -22
  149. package/components/link/clickableLink.js +33 -42
  150. package/components/link/link.js +47 -55
  151. package/components/list/consts.js +2 -2
  152. package/components/list/list.js +399 -486
  153. package/components/list/list__custom.js +51 -61
  154. package/components/list/list__hint.js +9 -17
  155. package/components/list/list__item.js +147 -178
  156. package/components/list/list__link.js +38 -47
  157. package/components/list/list__separator.js +15 -24
  158. package/components/list/list__title.js +25 -34
  159. package/components/list/list__users-groups-source.js +55 -121
  160. package/components/loader/loader.js +38 -60
  161. package/components/loader/loader__core.js +123 -184
  162. package/components/loader-inline/loader-inline.js +24 -32
  163. package/components/loader-screen/loader-screen.js +24 -40
  164. package/components/login-dialog/login-dialog.js +81 -121
  165. package/components/login-dialog/service.js +6 -29
  166. package/components/markdown/markdown.js +16 -24
  167. package/components/message/message.js +170 -201
  168. package/components/old-browsers-message/old-browsers-message.js +11 -14
  169. package/components/old-browsers-message/old-browsers-message__stop.js +1 -4
  170. package/components/old-browsers-message/white-list.js +8 -13
  171. package/components/pager/pager.js +212 -257
  172. package/components/panel/panel.js +16 -22
  173. package/components/permissions/permissions.js +118 -161
  174. package/components/permissions/permissions__cache.js +191 -218
  175. package/components/popup/popup.consts.js +1 -1
  176. package/components/popup/popup.js +237 -288
  177. package/components/popup/popup.target.js +9 -7
  178. package/components/popup/position.js +94 -101
  179. package/components/popup-menu/popup-menu.js +33 -67
  180. package/components/progress-bar/progress-bar.js +57 -68
  181. package/components/query-assist/query-assist.js +583 -652
  182. package/components/query-assist/query-assist__suggestions.js +2 -26
  183. package/components/radio/radio.js +15 -27
  184. package/components/radio/radio__item.js +52 -62
  185. package/components/scrollable-section/scrollable-section.js +53 -0
  186. package/components/select/select.js +701 -796
  187. package/components/select/select__filter.js +1 -26
  188. package/components/select/select__popup.js +316 -413
  189. package/components/shortcuts/core.js +147 -195
  190. package/components/shortcuts/shortcut-title.js +6 -10
  191. package/components/shortcuts/shortcuts-hoc.js +23 -41
  192. package/components/shortcuts/shortcuts.js +41 -64
  193. package/components/slider/slider.js +93 -112
  194. package/components/slider/slider.utils.js +16 -23
  195. package/components/storage/storage.js +3 -27
  196. package/components/storage/storage__fallback.js +137 -210
  197. package/components/storage/storage__local.js +89 -147
  198. package/components/style.css +1 -1
  199. package/components/tab-trap/tab-trap.js +35 -53
  200. package/components/table/cell.js +11 -21
  201. package/components/table/disable-hover-hoc.js +27 -42
  202. package/components/table/header-cell.js +59 -75
  203. package/components/table/header.js +89 -110
  204. package/components/table/multitable.js +83 -89
  205. package/components/table/row-with-focus-sensor.js +25 -57
  206. package/components/table/row.js +169 -200
  207. package/components/table/selection-adapter.js +2 -2
  208. package/components/table/selection-shortcuts-hoc.js +108 -113
  209. package/components/table/selection.js +150 -217
  210. package/components/table/simple-table.js +19 -55
  211. package/components/table/smart-table.js +42 -76
  212. package/components/table/table.js +267 -327
  213. package/components/tabs/collapsible-more.js +47 -73
  214. package/components/tabs/collapsible-tab.js +32 -36
  215. package/components/tabs/collapsible-tabs.js +89 -148
  216. package/components/tabs/custom-item.js +4 -2
  217. package/components/tabs/dumb-tabs.js +60 -92
  218. package/components/tabs/smart-tabs.js +29 -61
  219. package/components/tabs/tab-link.js +1 -3
  220. package/components/tabs/tab.js +15 -24
  221. package/components/tabs/tabs.js +1 -26
  222. package/components/tag/tag.d.ts +0 -2
  223. package/components/tag/tag.js +120 -162
  224. package/components/tags-input/tags-input.js +222 -304
  225. package/components/tags-list/tags-list.js +45 -61
  226. package/components/text/text.js +28 -37
  227. package/components/toggle/toggle.js +51 -61
  228. package/components/tooltip/tooltip.js +109 -141
  229. package/components/user-agreement/service.js +259 -400
  230. package/components/user-agreement/user-agreement.js +80 -108
  231. package/components/user-card/card.js +1 -25
  232. package/components/user-card/smart-user-card-tooltip.js +52 -103
  233. package/components/user-card/tooltip.js +35 -65
  234. package/components/user-card/user-card.js +1 -25
  235. package/package.json +1 -1
  236. package/components/global/react-render-adapter.d.ts +0 -1
  237. package/components/global/react-render-adapter.js +0 -6
  238. package/components/header/scrollable-section.js +0 -47
  239. package/components/header/tray-icon.d.ts +0 -1
  240. package/components/header/tray-icon.js +0 -26
  241. /package/components/{header → scrollable-section}/scrollable-section.d.ts +0 -0
@@ -1,41 +1,22 @@
1
- import { _ as _defineProperty, a as _inherits, b as _createClass, e as _classCallCheck, f as _callSuper, g as _asyncToGenerator, h as _regeneratorRuntime } from '../_helpers/_rollupPluginBabelHelpers.js';
2
- import 'core-js/modules/es.array.filter.js';
3
- import 'core-js/modules/es.array.includes.js';
4
- import 'core-js/modules/es.object.to-string.js';
5
- import 'core-js/modules/es.string.includes.js';
1
+ import { _ as _defineProperty } from '../_helpers/_rollupPluginBabelHelpers.js';
6
2
  import ExtendableError from 'es6-error';
7
3
  import { CODE } from '../http/http.js';
8
- import 'core-js/modules/es.array.concat.js';
9
- import 'core-js/modules/es.array.index-of.js';
10
- import 'core-js/modules/es.array.iterator.js';
11
- import 'core-js/modules/es.object.entries.js';
12
- import 'core-js/modules/es.promise.js';
13
- import 'core-js/modules/es.reflect.delete-property.js';
14
- import 'core-js/modules/es.weak-map.js';
15
- import 'core-js/modules/web.dom-collections.for-each.js';
16
4
  import 'core-js/modules/web.dom-collections.iterator.js';
17
5
  import '../global/url.js';
18
6
  import 'core-js/modules/es.regexp.exec.js';
19
- import 'core-js/modules/es.string.match.js';
20
7
  import 'core-js/modules/es.string.replace.js';
21
8
 
22
- var TokenValidationError = /*#__PURE__*/function (_ExtendableError) {
23
- function TokenValidationError(message, cause) {
24
- var _this;
25
- _classCallCheck(this, TokenValidationError);
26
- _this = _callSuper(this, TokenValidationError, [message]);
27
- _defineProperty(_this, "cause", void 0);
28
- _defineProperty(_this, "authRedirect", void 0);
29
- _this.cause = cause;
30
- _this.authRedirect = true;
31
- return _this;
9
+ class TokenValidationError extends ExtendableError {
10
+ constructor(message, cause) {
11
+ super(message);
12
+ _defineProperty(this, "cause", void 0);
13
+ _defineProperty(this, "authRedirect", void 0);
14
+ this.cause = cause;
15
+ this.authRedirect = true;
32
16
  }
33
- _inherits(TokenValidationError, _ExtendableError);
34
- return _createClass(TokenValidationError);
35
- }(ExtendableError);
36
- var TokenValidator = /*#__PURE__*/function () {
37
- function TokenValidator(config, getUser, storage) {
38
- _classCallCheck(this, TokenValidator);
17
+ }
18
+ class TokenValidator {
19
+ constructor(config, getUser, storage) {
39
20
  _defineProperty(this, "_getUser", void 0);
40
21
  _defineProperty(this, "_config", void 0);
41
22
  _defineProperty(this, "_storage", void 0);
@@ -49,211 +30,135 @@ var TokenValidator = /*#__PURE__*/function () {
49
30
  * @return {number} epoch, seconds since 1970
50
31
  * @private
51
32
  */
52
- return _createClass(TokenValidator, [{
53
- key: "validateTokenLocally",
54
- value:
55
- /**
56
- * Check token validity against all conditions.
57
- * @returns {Promise.<string>}
58
- */
59
- function validateTokenLocally() {
60
- return this._getValidatedToken([TokenValidator._validateExistence, TokenValidator._validateExpiration, this._validateScopes.bind(this)]);
33
+ static _epoch() {
34
+ const milliseconds = 1000.0;
35
+ return Math.round(Date.now() / milliseconds);
36
+ }
37
+ /**
38
+ * @const {number}
39
+ */
40
+ // eslint-disable-next-line @typescript-eslint/no-magic-numbers
41
+
42
+ /**
43
+ * Check token validity against all conditions.
44
+ * @returns {Promise.<string>}
45
+ */
46
+ validateTokenLocally() {
47
+ return this._getValidatedToken([TokenValidator._validateExistence, TokenValidator._validateExpiration, this._validateScopes.bind(this)]);
48
+ }
49
+ /**
50
+ * Check token validity against all conditions.
51
+ * @returns {Promise.<string>}
52
+ */
53
+ validateToken() {
54
+ return this._getValidatedToken([TokenValidator._validateExistence, TokenValidator._validateExpiration, this._validateScopes.bind(this), this._validateAgainstUser.bind(this)]);
55
+ }
56
+ /**
57
+ * Check if there is a token
58
+ * @param {StoredToken} storedToken
59
+ * @return {Promise.<StoredToken>}
60
+ * @private
61
+ */
62
+ static _validateExistence(storedToken) {
63
+ if (!storedToken || !storedToken.accessToken) {
64
+ throw new TokenValidator.TokenValidationError('Token not found');
61
65
  }
62
- /**
63
- * Check token validity against all conditions.
64
- * @returns {Promise.<string>}
65
- */
66
- }, {
67
- key: "validateToken",
68
- value: function validateToken() {
69
- return this._getValidatedToken([TokenValidator._validateExistence, TokenValidator._validateExpiration, this._validateScopes.bind(this), this._validateAgainstUser.bind(this)]);
66
+ }
67
+ /**
68
+ * Check expiration
69
+ * @param {StoredToken} storedToken
70
+ * @return {Promise.<StoredToken>}
71
+ * @private
72
+ */
73
+ static _validateExpiration(_ref) {
74
+ let {
75
+ expires,
76
+ lifeTime
77
+ } = _ref;
78
+ const REFRESH_BEFORE_RATIO = 6;
79
+ const refreshBefore = lifeTime ? Math.ceil(lifeTime / REFRESH_BEFORE_RATIO) : TokenValidator.DEFAULT_REFRESH_BEFORE;
80
+ if (expires && expires < TokenValidator._epoch() + refreshBefore) {
81
+ throw new TokenValidator.TokenValidationError('Token expired');
70
82
  }
71
- /**
72
- * Check if there is a token
73
- * @param {StoredToken} storedToken
74
- * @return {Promise.<StoredToken>}
75
- * @private
76
- */
77
- }, {
78
- key: "_validateScopes",
79
- value:
80
- /**
81
- * Check scopes
82
- * @param {StoredToken} storedToken
83
- * @return {Promise.<StoredToken>}
84
- * @private
85
- */
86
- function _validateScopes(storedToken) {
87
- var _this$_config = this._config,
88
- scope = _this$_config.scope,
89
- optionalScopes = _this$_config.optionalScopes;
90
- var requiredScopes = optionalScopes ? scope.filter(function (scopeId) {
91
- return !optionalScopes.includes(scopeId);
92
- }) : scope;
93
- var hasAllScopes = requiredScopes.every(function (scopeId) {
94
- var _storedToken$scopes;
95
- return (_storedToken$scopes = storedToken.scopes) === null || _storedToken$scopes === void 0 ? void 0 : _storedToken$scopes.includes(scopeId);
96
- });
97
- if (!hasAllScopes) {
98
- throw new TokenValidator.TokenValidationError('Token doesn\'t match required scopes');
99
- }
83
+ }
84
+ /**
85
+ * Check scopes
86
+ * @param {StoredToken} storedToken
87
+ * @return {Promise.<StoredToken>}
88
+ * @private
89
+ */
90
+ _validateScopes(storedToken) {
91
+ const {
92
+ scope,
93
+ optionalScopes
94
+ } = this._config;
95
+ const requiredScopes = optionalScopes ? scope.filter(scopeId => !optionalScopes.includes(scopeId)) : scope;
96
+ const hasAllScopes = requiredScopes.every(scopeId => {
97
+ var _storedToken$scopes;
98
+ return (_storedToken$scopes = storedToken.scopes) === null || _storedToken$scopes === void 0 ? void 0 : _storedToken$scopes.includes(scopeId);
99
+ });
100
+ if (!hasAllScopes) {
101
+ throw new TokenValidator.TokenValidationError('Token doesn\'t match required scopes');
100
102
  }
101
- /**
102
- * Check by error code if token should be refreshed
103
- * @param {string} error
104
- * @return {boolean}
105
- */
106
- }, {
107
- key: "_validateAgainstUser",
108
- value: (
109
- /**
110
- * Check scopes
111
- * @param {StoredToken} storedToken
112
- * @return {Promise.<StoredToken>}
113
- * @private
114
- */
115
- function () {
116
- var _validateAgainstUser2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(storedToken) {
117
- var response, _errorResponse$data, _errorResponse$data2;
118
- return _regeneratorRuntime().wrap(function _callee$(_context) {
119
- while (1) switch (_context.prev = _context.next) {
120
- case 0:
121
- _context.prev = 0;
122
- _context.next = 3;
123
- return this._getUser(storedToken.accessToken);
124
- case 3:
125
- return _context.abrupt("return", _context.sent);
126
- case 6:
127
- _context.prev = 6;
128
- _context.t0 = _context["catch"](0);
129
- response = {};
130
- _context.prev = 9;
131
- _context.next = 12;
132
- return _context.t0.response.json();
133
- case 12:
134
- response = _context.sent;
135
- _context.next = 17;
136
- break;
137
- case 15:
138
- _context.prev = 15;
139
- _context.t1 = _context["catch"](9);
140
- case 17:
141
- if (!(_context.t0.status === CODE.UNAUTHORIZED || TokenValidator.shouldRefreshToken(response.error))) {
142
- _context.next = 19;
143
- break;
144
- }
145
- throw new TokenValidator.TokenValidationError(response.error || _context.t0.message, (_errorResponse$data = _context.t0.data) !== null && _errorResponse$data !== void 0 && _errorResponse$data.error ? new Error((_errorResponse$data2 = _context.t0.data) === null || _errorResponse$data2 === void 0 ? void 0 : _errorResponse$data2.error) : undefined);
146
- case 19:
147
- throw _context.t0;
148
- case 20:
149
- case "end":
150
- return _context.stop();
151
- }
152
- }, _callee, this, [[0, 6], [9, 15]]);
153
- }));
154
- function _validateAgainstUser(_x) {
155
- return _validateAgainstUser2.apply(this, arguments);
103
+ }
104
+ /**
105
+ * Check by error code if token should be refreshed
106
+ * @param {string} error
107
+ * @return {boolean}
108
+ */
109
+ static shouldRefreshToken(error) {
110
+ return error === 'invalid_grant' || error === 'invalid_request' || error === 'invalid_token';
111
+ }
112
+ /**
113
+ * Check scopes
114
+ * @param {StoredToken} storedToken
115
+ * @return {Promise.<StoredToken>}
116
+ * @private
117
+ */
118
+ async _validateAgainstUser(storedToken) {
119
+ try {
120
+ return await this._getUser(storedToken.accessToken);
121
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
122
+ } catch (errorResponse) {
123
+ let response = {};
124
+ try {
125
+ response = await errorResponse.response.json();
126
+ } catch (e) {
127
+ // Skip JSON parsing errors
156
128
  }
157
- return _validateAgainstUser;
158
- }()
159
- /**
160
- * Token Validator function
161
- * @typedef {(function(StoredToken): Promise<StoredToken>)} TokenValidator
162
- */
163
- /**
164
- * Gets stored token and applies provided validators
165
- * @param {TokenValidator[]} validators An array of validation
166
- * functions to check the stored token against.
167
- * @return {Promise.<string>} promise that is resolved to access token if the stored token is valid. If it is
168
- * invalid then the promise is rejected. If invalid token should be re-requested then rejection object will
169
- * have {authRedirect: true}.
170
- * @private
171
- */
172
- )
173
- }, {
174
- key: "_getValidatedToken",
175
- value: (function () {
176
- var _getValidatedToken2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(validators) {
177
- var storedToken, i;
178
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
179
- while (1) switch (_context2.prev = _context2.next) {
180
- case 0:
181
- _context2.next = 2;
182
- return this._storage.getToken();
183
- case 2:
184
- storedToken = _context2.sent;
185
- if (!(storedToken == null)) {
186
- _context2.next = 5;
187
- break;
188
- }
189
- throw new TokenValidator.TokenValidationError('Token not found');
190
- case 5:
191
- i = 0;
192
- case 6:
193
- if (!(i < validators.length)) {
194
- _context2.next = 12;
195
- break;
196
- }
197
- _context2.next = 9;
198
- return validators[i](storedToken);
199
- case 9:
200
- i++;
201
- _context2.next = 6;
202
- break;
203
- case 12:
204
- return _context2.abrupt("return", storedToken.accessToken);
205
- case 13:
206
- case "end":
207
- return _context2.stop();
208
- }
209
- }, _callee2, this);
210
- }));
211
- function _getValidatedToken(_x2) {
212
- return _getValidatedToken2.apply(this, arguments);
129
+ if (errorResponse.status === CODE.UNAUTHORIZED || TokenValidator.shouldRefreshToken(response.error)) {
130
+ var _errorResponse$data, _errorResponse$data2;
131
+ // Token expired
132
+ throw new TokenValidator.TokenValidationError(response.error || errorResponse.message, (_errorResponse$data = errorResponse.data) !== null && _errorResponse$data !== void 0 && _errorResponse$data.error ? new Error((_errorResponse$data2 = errorResponse.data) === null || _errorResponse$data2 === void 0 ? void 0 : _errorResponse$data2.error) : undefined);
213
133
  }
214
- return _getValidatedToken;
215
- }())
216
- }], [{
217
- key: "_epoch",
218
- value: function _epoch() {
219
- var milliseconds = 1000.0;
220
- return Math.round(Date.now() / milliseconds);
134
+ // Request unexpectedly failed
135
+ throw errorResponse;
221
136
  }
222
- /**
223
- * @const {number}
224
- */
225
- // eslint-disable-next-line @typescript-eslint/no-magic-numbers
226
- }, {
227
- key: "_validateExistence",
228
- value: function _validateExistence(storedToken) {
229
- if (!storedToken || !storedToken.accessToken) {
230
- throw new TokenValidator.TokenValidationError('Token not found');
231
- }
232
- }
233
- /**
234
- * Check expiration
235
- * @param {StoredToken} storedToken
236
- * @return {Promise.<StoredToken>}
237
- * @private
238
- */
239
- }, {
240
- key: "_validateExpiration",
241
- value: function _validateExpiration(_ref) {
242
- var expires = _ref.expires,
243
- lifeTime = _ref.lifeTime;
244
- var REFRESH_BEFORE_RATIO = 6;
245
- var refreshBefore = lifeTime ? Math.ceil(lifeTime / REFRESH_BEFORE_RATIO) : TokenValidator.DEFAULT_REFRESH_BEFORE;
246
- if (expires && expires < TokenValidator._epoch() + refreshBefore) {
247
- throw new TokenValidator.TokenValidationError('Token expired');
248
- }
137
+ }
138
+ /**
139
+ * Token Validator function
140
+ * @typedef {(function(StoredToken): Promise<StoredToken>)} TokenValidator
141
+ */
142
+ /**
143
+ * Gets stored token and applies provided validators
144
+ * @param {TokenValidator[]} validators An array of validation
145
+ * functions to check the stored token against.
146
+ * @return {Promise.<string>} promise that is resolved to access token if the stored token is valid. If it is
147
+ * invalid then the promise is rejected. If invalid token should be re-requested then rejection object will
148
+ * have {authRedirect: true}.
149
+ * @private
150
+ */
151
+ async _getValidatedToken(validators) {
152
+ const storedToken = await this._storage.getToken();
153
+ if (storedToken == null) {
154
+ throw new TokenValidator.TokenValidationError('Token not found');
249
155
  }
250
- }, {
251
- key: "shouldRefreshToken",
252
- value: function shouldRefreshToken(error) {
253
- return error === 'invalid_grant' || error === 'invalid_request' || error === 'invalid_token';
156
+ for (let i = 0; i < validators.length; i++) {
157
+ await validators[i](storedToken);
254
158
  }
255
- }]);
256
- }();
159
+ return storedToken.accessToken;
160
+ }
161
+ }
257
162
  _defineProperty(TokenValidator, "DEFAULT_REFRESH_BEFORE", 10 * 60);
258
163
  // 20 min in s
259
164
  /**
@@ -1,41 +1,32 @@
1
- import { b as _createClass, e as _classCallCheck, _ as _defineProperty, g as _asyncToGenerator, h as _regeneratorRuntime } from '../_helpers/_rollupPluginBabelHelpers.js';
2
- import 'core-js/modules/es.array.concat.js';
3
- import 'core-js/modules/es.object.to-string.js';
4
- import 'core-js/modules/es.promise.js';
1
+ import { _ as _defineProperty } from '../_helpers/_rollupPluginBabelHelpers.js';
5
2
  import AuthResponseParser from './response-parser.js';
6
- import 'core-js/modules/es.array.index-of.js';
7
3
  import 'core-js/modules/es.regexp.exec.js';
8
- import 'core-js/modules/es.regexp.to-string.js';
9
4
  import 'core-js/modules/es.string.replace.js';
10
- import 'core-js/modules/web.dom-collections.for-each.js';
11
5
  import 'es6-error';
12
6
  import '../global/url.js';
13
- import 'core-js/modules/es.string.match.js';
14
7
 
15
- var NAVBAR_HEIGHT = 50;
16
- var CLOSED_CHECK_INTERVAL = 200;
17
- var WindowFlow = /*#__PURE__*/function () {
18
- function WindowFlow(requestBuilder, storage) {
19
- var _this = this;
20
- _classCallCheck(this, WindowFlow);
8
+ const NAVBAR_HEIGHT = 50;
9
+ const CLOSED_CHECK_INTERVAL = 200;
10
+ class WindowFlow {
11
+ constructor(requestBuilder, storage) {
21
12
  _defineProperty(this, "_timeoutId", undefined);
22
13
  _defineProperty(this, "_requestBuilder", void 0);
23
14
  _defineProperty(this, "_storage", void 0);
24
15
  _defineProperty(this, "reject", void 0);
25
16
  _defineProperty(this, "_loginWindow", void 0);
26
17
  _defineProperty(this, "_promise", void 0);
27
- _defineProperty(this, "checkIsClosed", function () {
18
+ _defineProperty(this, "checkIsClosed", () => {
28
19
  var _this$_loginWindow;
29
- if ((_this$_loginWindow = _this._loginWindow) !== null && _this$_loginWindow !== void 0 && _this$_loginWindow.closed) {
30
- _this.stop();
20
+ if ((_this$_loginWindow = this._loginWindow) !== null && _this$_loginWindow !== void 0 && _this$_loginWindow.closed) {
21
+ this.stop();
31
22
  return;
32
23
  }
33
- _this._timeoutId = window.setTimeout(_this.checkIsClosed, CLOSED_CHECK_INTERVAL);
24
+ this._timeoutId = window.setTimeout(this.checkIsClosed, CLOSED_CHECK_INTERVAL);
34
25
  });
35
- _defineProperty(this, "_reset", function () {
36
- _this._promise = null;
37
- _this._loginWindow = null;
38
- clearTimeout(_this._timeoutId);
26
+ _defineProperty(this, "_reset", () => {
27
+ this._promise = null;
28
+ this._loginWindow = null;
29
+ clearTimeout(this._timeoutId);
39
30
  });
40
31
  this._requestBuilder = requestBuilder;
41
32
  this._storage = storage;
@@ -46,108 +37,80 @@ var WindowFlow = /*#__PURE__*/function () {
46
37
  * @param {string} url
47
38
  * @private
48
39
  */
49
- return _createClass(WindowFlow, [{
50
- key: "_openWindow",
51
- value: function _openWindow(url) {
52
- var height = 700;
53
- var width = 750;
54
- var screenHalves = 2;
55
- var top = (window.screen.height - height - NAVBAR_HEIGHT) / screenHalves;
56
- var left = (window.screen.width - width) / screenHalves;
57
- return window.open(url, 'HubLoginWindow', "height=".concat(height, ", width=").concat(width, ", left=").concat(left, ", top=").concat(top));
58
- }
59
- /**
60
- * Initiates authorization in window
61
- */
62
- }, {
63
- key: "_load",
64
- value: (function () {
65
- var _load2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
66
- var _this2 = this;
67
- var authRequest;
68
- return _regeneratorRuntime().wrap(function _callee$(_context) {
69
- while (1) switch (_context.prev = _context.next) {
70
- case 0:
71
- _context.next = 2;
72
- return this._requestBuilder.prepareAuthRequest(
73
- // eslint-disable-next-line camelcase
74
- {
75
- request_credentials: 'required',
76
- auth_mode: 'bypass_to_login'
77
- }, {
78
- nonRedirect: true
79
- });
80
- case 2:
81
- authRequest = _context.sent;
82
- return _context.abrupt("return", new Promise(function (resolve, reject) {
83
- _this2.reject = reject;
84
- var cleanRun;
85
- var cleanUp = function cleanUp() {
86
- var _this2$_loginWindow;
87
- if (cleanRun) {
88
- return;
89
- }
90
- cleanRun = true;
91
- /* eslint-disable @typescript-eslint/no-use-before-define */
92
- removeStateListener();
93
- removeTokenListener();
94
- /* eslint-enable @typescript-eslint/no-use-before-define */
95
- (_this2$_loginWindow = _this2._loginWindow) === null || _this2$_loginWindow === void 0 || _this2$_loginWindow.close();
96
- clearTimeout(_this2._timeoutId);
97
- };
98
- var removeTokenListener = _this2._storage.onTokenChange(function (token) {
99
- if (token) {
100
- cleanUp();
101
- resolve(token.accessToken);
102
- }
103
- });
104
- var removeStateListener = _this2._storage.onStateChange(authRequest.stateId, function (state) {
105
- if (state && state.error) {
106
- cleanUp();
107
- reject(new AuthResponseParser.AuthError(state));
108
- }
109
- });
110
- if (_this2._loginWindow == null || _this2._loginWindow.closed) {
111
- _this2._loginWindow = _this2._openWindow(authRequest.url);
112
- } else {
113
- _this2._loginWindow.location.href = authRequest.url;
114
- }
115
- _this2.checkIsClosed();
116
- }));
117
- case 4:
118
- case "end":
119
- return _context.stop();
120
- }
121
- }, _callee, this);
122
- }));
123
- function _load() {
124
- return _load2.apply(this, arguments);
125
- }
126
- return _load;
127
- }())
128
- }, {
129
- key: "stop",
130
- value: function stop() {
131
- if (this._loginWindow != null) {
132
- this._loginWindow.close();
133
- }
134
- if (this.reject) {
135
- this.reject('Authorization window closed');
40
+ _openWindow(url) {
41
+ const height = 700;
42
+ const width = 750;
43
+ const screenHalves = 2;
44
+ const top = (window.screen.height - height - NAVBAR_HEIGHT) / screenHalves;
45
+ const left = (window.screen.width - width) / screenHalves;
46
+ return window.open(url, 'HubLoginWindow', "height=".concat(height, ", width=").concat(width, ", left=").concat(left, ", top=").concat(top));
47
+ }
48
+ /**
49
+ * Initiates authorization in window
50
+ */
51
+ async _load() {
52
+ const authRequest = await this._requestBuilder.prepareAuthRequest(
53
+ // eslint-disable-next-line camelcase
54
+ {
55
+ request_credentials: 'required',
56
+ auth_mode: 'bypass_to_login'
57
+ }, {
58
+ nonRedirect: true
59
+ });
60
+ return new Promise((resolve, reject) => {
61
+ this.reject = reject;
62
+ let cleanRun;
63
+ const cleanUp = () => {
64
+ var _this$_loginWindow2;
65
+ if (cleanRun) {
66
+ return;
67
+ }
68
+ cleanRun = true;
69
+ /* eslint-disable @typescript-eslint/no-use-before-define */
70
+ removeStateListener();
71
+ removeTokenListener();
72
+ /* eslint-enable @typescript-eslint/no-use-before-define */
73
+ (_this$_loginWindow2 = this._loginWindow) === null || _this$_loginWindow2 === void 0 || _this$_loginWindow2.close();
74
+ clearTimeout(this._timeoutId);
75
+ };
76
+ const removeTokenListener = this._storage.onTokenChange(token => {
77
+ if (token) {
78
+ cleanUp();
79
+ resolve(token.accessToken);
80
+ }
81
+ });
82
+ const removeStateListener = this._storage.onStateChange(authRequest.stateId, state => {
83
+ if (state && state.error) {
84
+ cleanUp();
85
+ reject(new AuthResponseParser.AuthError(state));
86
+ }
87
+ });
88
+ if (this._loginWindow == null || this._loginWindow.closed) {
89
+ this._loginWindow = this._openWindow(authRequest.url);
90
+ } else {
91
+ this._loginWindow.location.href = authRequest.url;
136
92
  }
137
- this._reset();
93
+ this.checkIsClosed();
94
+ });
95
+ }
96
+ stop() {
97
+ if (this._loginWindow != null) {
98
+ this._loginWindow.close();
138
99
  }
139
- }, {
140
- key: "authorize",
141
- value: function authorize() {
142
- if (this._promise != null && this._loginWindow != null && !this._loginWindow.closed) {
143
- this._loginWindow.focus();
144
- return this._promise;
145
- }
146
- this._promise = this._load();
147
- this._promise.then(this._reset, this._reset);
100
+ if (this.reject) {
101
+ this.reject('Authorization window closed');
102
+ }
103
+ this._reset();
104
+ }
105
+ authorize() {
106
+ if (this._promise != null && this._loginWindow != null && !this._loginWindow.closed) {
107
+ this._loginWindow.focus();
148
108
  return this._promise;
149
109
  }
150
- }]);
151
- }();
110
+ this._promise = this._load();
111
+ this._promise.then(this._reset, this._reset);
112
+ return this._promise;
113
+ }
114
+ }
152
115
 
153
116
  export { WindowFlow as default };