@jetbrains/ring-ui 5.0.156 → 5.0.158

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