@jetbrains/ring-ui 4.1.1 → 4.1.2

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 (314) hide show
  1. package/dist/_helpers/_rollupPluginBabelHelpers.js +34 -0
  2. package/dist/_helpers/anchor.js +32 -0
  3. package/dist/_helpers/badge.js +3 -0
  4. package/dist/_helpers/button-group.js +3 -0
  5. package/dist/_helpers/button-set.js +3 -0
  6. package/dist/_helpers/button-toolbar.js +3 -0
  7. package/dist/_helpers/button__classes.js +39 -0
  8. package/dist/_helpers/card.js +75 -0
  9. package/dist/_helpers/checkbox.js +3 -0
  10. package/dist/_helpers/date-picker.js +3 -0
  11. package/dist/_helpers/dialog__body-scroll-preventer.js +57 -0
  12. package/dist/_helpers/error-message.js +3 -0
  13. package/dist/_helpers/footer.js +121 -0
  14. package/dist/_helpers/grid.js +3 -0
  15. package/dist/_helpers/group.js +3 -0
  16. package/dist/_helpers/header.js +3 -0
  17. package/dist/_helpers/icon.js +3 -0
  18. package/dist/_helpers/inject-styles.js +22 -0
  19. package/dist/_helpers/input.js +3 -0
  20. package/dist/_helpers/island.js +3 -0
  21. package/dist/_helpers/link.js +3 -0
  22. package/dist/_helpers/list.js +3 -0
  23. package/dist/_helpers/loader-screen.js +3 -0
  24. package/dist/_helpers/panel.js +3 -0
  25. package/dist/_helpers/query-assist__suggestions.js +95 -0
  26. package/dist/_helpers/radio.js +3 -0
  27. package/dist/_helpers/select__filter.js +76 -0
  28. package/dist/_helpers/services-link.js +40 -0
  29. package/dist/_helpers/sidebar.js +125 -0
  30. package/dist/_helpers/table.js +3 -0
  31. package/dist/_helpers/tabs.js +3 -0
  32. package/dist/_helpers/title.js +99 -0
  33. package/dist/alert/alert.js +260 -0
  34. package/dist/alert/container.js +48 -0
  35. package/dist/alert-service/alert-service.js +170 -0
  36. package/dist/analytics/analytics.js +116 -0
  37. package/dist/analytics/analytics__custom-plugin.js +127 -0
  38. package/dist/analytics/analytics__fus-plugin.js +101 -0
  39. package/dist/analytics/analytics__ga-plugin.js +66 -0
  40. package/dist/analytics/analytics__plugin-utils.js +79 -0
  41. package/dist/analytics-ng/analytics-ng.js +94 -0
  42. package/dist/auth/auth.js +93 -0
  43. package/dist/auth/auth__core.js +1025 -0
  44. package/dist/auth/background-flow.js +122 -0
  45. package/dist/auth/down-notification.js +114 -0
  46. package/dist/auth/iframe-flow.js +150 -0
  47. package/dist/auth/landing-entry.js +5 -0
  48. package/dist/auth/landing.js +87 -0
  49. package/dist/auth/request-builder.js +75 -0
  50. package/dist/auth/response-parser.js +117 -0
  51. package/dist/auth/storage.js +280 -0
  52. package/dist/auth/token-validator.js +176 -0
  53. package/dist/auth/window-flow.js +133 -0
  54. package/dist/auth-dialog/auth-dialog.js +134 -0
  55. package/dist/auth-dialog-service/auth-dialog-service.js +68 -0
  56. package/dist/auth-ng/auth-ng.js +203 -0
  57. package/dist/auth-ng/auth-ng.mock.js +33 -0
  58. package/dist/autofocus-ng/autofocus-ng.js +50 -0
  59. package/dist/avatar/avatar-example-datauri.js +26 -0
  60. package/dist/avatar/avatar.js +161 -0
  61. package/dist/avatar/fallback-avatar.js +141 -0
  62. package/dist/avatar-editor-ng/avatar-editor-ng.js +164 -0
  63. package/dist/avatar-editor-ng/avatar-editor-ng__template.js +30 -0
  64. package/dist/avatar-ng/avatar-ng.js +18 -0
  65. package/dist/badge/badge.js +50 -0
  66. package/dist/badge-ng/badge-ng.js +16 -0
  67. package/dist/breadcrumb-ng/breadcrumb-ng.js +61 -0
  68. package/dist/button/button.js +123 -0
  69. package/dist/button/button__classes.js +5 -0
  70. package/dist/button-group/button-group.js +30 -0
  71. package/dist/button-group/caption.js +24 -0
  72. package/dist/button-group-ng/button-group-ng.js +38 -0
  73. package/dist/button-ng/button-ng.js +223 -0
  74. package/dist/button-set/button-set.js +26 -0
  75. package/dist/button-set-ng/button-set-ng.js +19 -0
  76. package/dist/button-toolbar/button-toolbar.js +29 -0
  77. package/dist/button-toolbar-ng/button-toolbar-ng.js +23 -0
  78. package/dist/caret/caret.js +264 -0
  79. package/dist/checkbox/checkbox.js +108 -0
  80. package/dist/checkbox-ng/checkbox-ng.js +55 -0
  81. package/dist/code/code.js +136 -0
  82. package/dist/compiler-ng/compiler-ng.js +53 -0
  83. package/dist/confirm/confirm.js +125 -0
  84. package/dist/confirm-ng/confirm-ng.js +66 -0
  85. package/dist/confirm-service/confirm-service.js +114 -0
  86. package/dist/content-layout/content-layout.js +65 -0
  87. package/dist/content-layout/sidebar.js +6 -0
  88. package/dist/contenteditable/contenteditable.js +78 -0
  89. package/dist/data-list/data-list.js +206 -0
  90. package/dist/data-list/data-list.mock.js +190 -0
  91. package/dist/data-list/item.js +227 -0
  92. package/dist/data-list/selection.js +101 -0
  93. package/dist/data-list/title.js +18 -0
  94. package/dist/data-list-ng/data-list-ng.js +59 -0
  95. package/dist/date-picker/consts.js +69 -0
  96. package/dist/date-picker/date-input.js +173 -0
  97. package/dist/date-picker/date-picker.js +365 -0
  98. package/dist/date-picker/date-popup.js +482 -0
  99. package/dist/date-picker/day.js +119 -0
  100. package/dist/date-picker/formats.js +3 -0
  101. package/dist/date-picker/month-names.js +99 -0
  102. package/dist/date-picker/month-slider.js +83 -0
  103. package/dist/date-picker/month.js +54 -0
  104. package/dist/date-picker/months.js +121 -0
  105. package/dist/date-picker/weekdays.js +32 -0
  106. package/dist/date-picker/years.js +109 -0
  107. package/dist/dialog/dialog.js +200 -0
  108. package/dist/dialog/dialog__body-scroll-preventer.js +2 -0
  109. package/dist/dialog-ng/dialog-ng.js +601 -0
  110. package/dist/dialog-ng/dialog-ng__template.js +71 -0
  111. package/dist/docked-panel-ng/docked-panel-ng.js +170 -0
  112. package/dist/dropdown/anchor.js +17 -0
  113. package/dist/dropdown/dropdown.js +234 -0
  114. package/dist/dropdown-menu/dropdown-menu.js +175 -0
  115. package/dist/error-bubble/error-bubble.js +57 -0
  116. package/dist/error-message/error-message.js +55 -0
  117. package/dist/error-message-ng/error-message-ng.js +53 -0
  118. package/dist/footer/footer.js +11 -0
  119. package/dist/footer-ng/footer-ng.js +75 -0
  120. package/dist/form-ng/form-ng.js +169 -0
  121. package/dist/global/angular-component-factory.js +82 -0
  122. package/dist/global/compose.js +9 -0
  123. package/dist/global/composeRefs.js +15 -0
  124. package/dist/global/conic-gradient.js +35 -0
  125. package/dist/global/create-stateful-context.js +54 -0
  126. package/dist/global/data-tests.js +22 -0
  127. package/dist/global/dom.js +124 -0
  128. package/dist/global/focus-sensor-hoc.js +145 -0
  129. package/dist/global/fuzzy-highlight.js +67 -0
  130. package/dist/global/get-event-key.js +111 -0
  131. package/dist/global/get-uid.js +15 -0
  132. package/dist/global/inject-styles.js +17 -0
  133. package/dist/global/linear-function.js +17 -0
  134. package/dist/global/listeners.js +42 -0
  135. package/dist/global/memoize.js +18 -0
  136. package/dist/global/normalize-indent.js +28 -0
  137. package/dist/global/promise-with-timeout.js +13 -0
  138. package/dist/global/radial-gradient-mask.js +49 -0
  139. package/dist/global/react-dom-renderer.js +45 -0
  140. package/dist/global/rerender-hoc.js +51 -0
  141. package/dist/global/ring-angular-component.js +24 -0
  142. package/dist/global/schedule-raf.js +31 -0
  143. package/dist/global/sniffer.js +6 -0
  144. package/dist/global/supports-css.js +20 -0
  145. package/dist/global/theme.js +54 -0
  146. package/dist/global/trivial-template-tag.js +15 -0
  147. package/dist/global/url.js +163 -0
  148. package/dist/global/variables_dark.js +57 -0
  149. package/dist/grid/col.js +60 -0
  150. package/dist/grid/grid.js +33 -0
  151. package/dist/grid/row.js +64 -0
  152. package/dist/group/group.js +31 -0
  153. package/dist/group-ng/group-ng.js +11 -0
  154. package/dist/header/header.js +147 -0
  155. package/dist/header/logo.js +38 -0
  156. package/dist/header/profile.js +217 -0
  157. package/dist/header/services-link.js +11 -0
  158. package/dist/header/services.js +136 -0
  159. package/dist/header/smart-profile.js +230 -0
  160. package/dist/header/smart-services.js +160 -0
  161. package/dist/header/tray-icon.js +45 -0
  162. package/dist/header/tray.js +31 -0
  163. package/dist/heading/heading.js +73 -0
  164. package/dist/http/http.js +216 -0
  165. package/dist/http/http.mock.js +65 -0
  166. package/dist/hub-source/hub-source.js +130 -0
  167. package/dist/hub-source/hub-source__user.js +28 -0
  168. package/dist/hub-source/hub-source__users-groups.js +62 -0
  169. package/dist/icon/icon.js +105 -0
  170. package/dist/icon/icon__constants.js +33 -0
  171. package/dist/icon/icon__svg.js +81 -0
  172. package/dist/icon/index.js +10 -0
  173. package/dist/icon-ng/icon-ng.js +89 -0
  174. package/dist/input/input.js +228 -0
  175. package/dist/input-ng/input-ng.js +166 -0
  176. package/dist/island/adaptive-island-hoc.js +47 -0
  177. package/dist/island/content.js +156 -0
  178. package/dist/island/header.js +83 -0
  179. package/dist/island/island.js +50 -0
  180. package/dist/island-legacy/content-legacy.js +26 -0
  181. package/dist/island-legacy/header-legacy.js +28 -0
  182. package/dist/island-legacy/island-legacy.js +28 -0
  183. package/dist/island-ng/island-content-ng.js +56 -0
  184. package/dist/island-ng/island-header-ng.js +32 -0
  185. package/dist/island-ng/island-ng-class-fixer.js +9 -0
  186. package/dist/island-ng/island-ng.js +31 -0
  187. package/dist/link/clickableLink.js +63 -0
  188. package/dist/link/link.js +114 -0
  189. package/dist/link-ng/link-ng.js +25 -0
  190. package/dist/list/consts.js +26 -0
  191. package/dist/list/list.js +812 -0
  192. package/dist/list/list__custom.js +85 -0
  193. package/dist/list/list__hint.js +26 -0
  194. package/dist/list/list__item.js +204 -0
  195. package/dist/list/list__link.js +64 -0
  196. package/dist/list/list__separator.js +30 -0
  197. package/dist/list/list__title.js +39 -0
  198. package/dist/list/list__users-groups-source.js +128 -0
  199. package/dist/loader/loader.js +70 -0
  200. package/dist/loader/loader__core.js +272 -0
  201. package/dist/loader-inline/inject-styles.js +11 -0
  202. package/dist/loader-inline/loader-inline.js +56 -0
  203. package/dist/loader-inline-ng/loader-inline-ng.js +42 -0
  204. package/dist/loader-ng/loader-ng.js +43 -0
  205. package/dist/loader-screen/loader-screen.js +43 -0
  206. package/dist/loader-screen-ng/loader-screen-ng.js +99 -0
  207. package/dist/login-dialog/login-dialog.js +186 -0
  208. package/dist/login-dialog/service.js +69 -0
  209. package/dist/markdown/code.js +30 -0
  210. package/dist/markdown/heading.js +23 -0
  211. package/dist/markdown/link.js +30 -0
  212. package/dist/markdown/markdown.js +73 -0
  213. package/dist/message/message.js +233 -0
  214. package/dist/message-bundle-ng/message-bundle-ng.js +111 -0
  215. package/dist/old-browsers-message/old-browsers-message.js +100 -0
  216. package/dist/old-browsers-message/old-browsers-message__stop.js +4 -0
  217. package/dist/old-browsers-message/white-list.js +33 -0
  218. package/dist/pager/pager.js +361 -0
  219. package/dist/pager-ng/pager-ng.js +96 -0
  220. package/dist/panel/panel.js +31 -0
  221. package/dist/panel-ng/panel-ng.js +16 -0
  222. package/dist/permissions/permissions.js +200 -0
  223. package/dist/permissions/permissions__cache.js +272 -0
  224. package/dist/permissions-ng/permissions-ng.js +274 -0
  225. package/dist/place-under-ng/place-under-ng.js +157 -0
  226. package/dist/popup/popup.consts.js +41 -0
  227. package/dist/popup/popup.js +389 -0
  228. package/dist/popup/popup.target.js +26 -0
  229. package/dist/popup/position.js +279 -0
  230. package/dist/popup-menu/popup-menu.js +115 -0
  231. package/dist/progress-bar/progress-bar.js +113 -0
  232. package/dist/progress-bar-ng/progress-bar-ng.js +15 -0
  233. package/dist/promised-click-ng/promised-click-ng.js +126 -0
  234. package/dist/proxy-attrs/proxy-attrs.js +19 -0
  235. package/dist/query-assist/query-assist.js +1092 -0
  236. package/dist/query-assist/query-assist__suggestions.js +47 -0
  237. package/dist/query-assist-ng/query-assist-ng.js +82 -0
  238. package/dist/radio/radio.js +41 -0
  239. package/dist/radio/radio__item.js +77 -0
  240. package/dist/radio-ng/radio-ng.js +63 -0
  241. package/dist/save-field-ng/save-field-ng.js +335 -0
  242. package/dist/save-field-ng/save-field-ng__template.js +34 -0
  243. package/dist/select/select.js +1336 -0
  244. package/dist/select/select__filter.js +54 -0
  245. package/dist/select/select__popup.js +546 -0
  246. package/dist/select-ng/select-ng.js +621 -0
  247. package/dist/select-ng/select-ng__lazy.js +150 -0
  248. package/dist/select-ng/select-ng__options.js +145 -0
  249. package/dist/shortcuts/core.js +245 -0
  250. package/dist/shortcuts/shortcut-title.js +51 -0
  251. package/dist/shortcuts/shortcuts-hoc.js +41 -0
  252. package/dist/shortcuts/shortcuts.js +72 -0
  253. package/dist/shortcuts-hint-ng/shortcuts-hint-ng.js +120 -0
  254. package/dist/shortcuts-hint-ng/shortcuts-hint-ng__template.js +50 -0
  255. package/dist/shortcuts-ng/shortcuts-ng.js +261 -0
  256. package/dist/sidebar-ng/sidebar-ng.js +111 -0
  257. package/dist/sidebar-ng/sidebar-ng__button-template.js +20 -0
  258. package/dist/sidebar-ng/sidebar-ng__template.js +12 -0
  259. package/dist/storage/storage.js +56 -0
  260. package/dist/storage/storage__fallback.js +214 -0
  261. package/dist/storage/storage__local.js +151 -0
  262. package/dist/style.css +1 -0
  263. package/dist/tab-trap/tab-trap.js +176 -0
  264. package/dist/table/cell.js +25 -0
  265. package/dist/table/disable-hover-hoc.js +53 -0
  266. package/dist/table/header-cell.js +90 -0
  267. package/dist/table/header.js +191 -0
  268. package/dist/table/multitable.js +140 -0
  269. package/dist/table/row-with-focus-sensor.js +81 -0
  270. package/dist/table/row.js +271 -0
  271. package/dist/table/selection-adapter.js +14 -0
  272. package/dist/table/selection-shortcuts-hoc.js +214 -0
  273. package/dist/table/selection.js +221 -0
  274. package/dist/table/smart-table.js +119 -0
  275. package/dist/table/table.js +404 -0
  276. package/dist/table-legacy-ng/table-legacy-ng.js +501 -0
  277. package/dist/table-legacy-ng/table-legacy-ng__pager.js +122 -0
  278. package/dist/table-legacy-ng/table-legacy-ng__selection-navigate-actions.js +123 -0
  279. package/dist/table-legacy-ng/table-legacy-ng__selection.js +179 -0
  280. package/dist/table-legacy-ng/table-legacy-ng__toolbar.js +56 -0
  281. package/dist/table-ng/smart-table-ng.js +65 -0
  282. package/dist/table-ng/table-ng.js +64 -0
  283. package/dist/tabs/collapsible-more.js +196 -0
  284. package/dist/tabs/collapsible-tab.js +90 -0
  285. package/dist/tabs/collapsible-tabs.js +360 -0
  286. package/dist/tabs/custom-item.js +13 -0
  287. package/dist/tabs/dumb-tabs.js +161 -0
  288. package/dist/tabs/smart-tabs.js +104 -0
  289. package/dist/tabs/tab-link.js +41 -0
  290. package/dist/tabs/tab.js +32 -0
  291. package/dist/tabs/tabs.js +69 -0
  292. package/dist/tabs-ng/tabs-ng.js +193 -0
  293. package/dist/tabs-ng/tabs-ng__template.js +40 -0
  294. package/dist/tag/tag.js +196 -0
  295. package/dist/tags-input/tags-input.js +478 -0
  296. package/dist/tags-input-ng/tags-input-ng.js +89 -0
  297. package/dist/tags-list/tags-list.js +93 -0
  298. package/dist/template-ng/template-ng.js +70 -0
  299. package/dist/text/text.js +36 -0
  300. package/dist/theme-ng/theme-ng.js +44 -0
  301. package/dist/title-ng/title-ng.js +114 -0
  302. package/dist/toggle/toggle.js +77 -0
  303. package/dist/toggle-ng/toggle-ng.js +16 -0
  304. package/dist/tooltip/tooltip.js +207 -0
  305. package/dist/tooltip-ng/tooltip-ng.js +98 -0
  306. package/dist/user-agreement/service.js +409 -0
  307. package/dist/user-agreement/toolbox.eula.js +162 -0
  308. package/dist/user-agreement/user-agreement.js +167 -0
  309. package/dist/user-card/card.js +17 -0
  310. package/dist/user-card/smart-user-card-tooltip.js +112 -0
  311. package/dist/user-card/tooltip.js +93 -0
  312. package/dist/user-card/user-card.js +49 -0
  313. package/dist/user-card-ng/user-card-ng.js +59 -0
  314. package/package.json +2 -2
@@ -0,0 +1,280 @@
1
+ import ActualStorage from '../storage/storage.js';
2
+ import '../storage/storage__local.js';
3
+ import '../alert-service/alert-service.js';
4
+ import '../_helpers/_rollupPluginBabelHelpers.js';
5
+ import 'react';
6
+ import 'react-dom';
7
+ import '../global/get-uid.js';
8
+ import '../alert/alert.js';
9
+ import 'classnames';
10
+ import 'prop-types';
11
+ import '@jetbrains/icons/exception';
12
+ import '@jetbrains/icons/checkmark';
13
+ import '@jetbrains/icons/warning';
14
+ import '@jetbrains/icons/close';
15
+ import '../icon/icon.js';
16
+ import 'util-deprecate';
17
+ import '../icon/icon__constants.js';
18
+ import '../_helpers/icon.js';
19
+ import '../icon/icon__svg.js';
20
+ import '../global/memoize.js';
21
+ import '../loader-inline/loader-inline.js';
22
+ import '../global/theme.js';
23
+ import '../global/data-tests.js';
24
+ import '../_helpers/inject-styles.js';
25
+ import '../global/conic-gradient.js';
26
+ import 'conic-gradient';
27
+ import '../global/supports-css.js';
28
+ import '../global/inject-styles.js';
29
+ import '../global/radial-gradient-mask.js';
30
+ import '../global/dom.js';
31
+ import '../alert/container.js';
32
+ import '../storage/storage__fallback.js';
33
+ import 'deep-equal';
34
+
35
+ /**
36
+ * @typedef {Object} StoredToken
37
+ * @property {string} accessToken
38
+ * @property {string[]} scopes
39
+ * @property {number} expires
40
+ */
41
+
42
+ /**
43
+ * @typedef {Object} StoredState
44
+ * @property {Date} created
45
+ * @property {string} restoreLocation
46
+ * @property {string[]} scopes
47
+ */
48
+
49
+ const DEFAULT_STATE_QUOTA = 102400; // 100 kb ~~ 200 tabs with a large list of scopes
50
+ // eslint-disable-next-line no-magic-numbers
51
+
52
+ const DEFAULT_STATE_TTL = 1000 * 60 * 60 * 24; // nobody will need auth state after a day
53
+
54
+ const UPDATE_USER_TIMEOUT = 1000;
55
+ class AuthStorage {
56
+ /**
57
+ * Custom storage for Auth
58
+ * @param {{stateKeyPrefix: string, tokenKey: string, onTokenRemove: Function}} config
59
+ */
60
+ constructor(config) {
61
+ this.messagePrefix = config.messagePrefix || '';
62
+ this.stateKeyPrefix = config.stateKeyPrefix;
63
+ this.tokenKey = config.tokenKey;
64
+ this.userKey = config.userKey || 'user-key';
65
+ this.stateTTL = config.stateTTL || DEFAULT_STATE_TTL;
66
+ this._lastMessage = null;
67
+ const StorageConstructor = config.storage || ActualStorage;
68
+ this.stateQuota = Math.min(config.stateQuota || DEFAULT_STATE_QUOTA, StorageConstructor.QUOTA || Infinity);
69
+ this._stateStorage = new StorageConstructor({
70
+ cookieName: 'ring-state'
71
+ });
72
+ this._tokenStorage = new StorageConstructor({
73
+ cookieName: 'ring-token'
74
+ });
75
+ this._messagesStorage = new StorageConstructor({
76
+ cookieName: 'ring-message'
77
+ });
78
+ this._currentUserStorage = new StorageConstructor({
79
+ cookieName: 'ring-user'
80
+ });
81
+ }
82
+ /**
83
+ * Add token change listener
84
+ * @param {function(string)} fn Token change listener
85
+ * @return {function()} remove listener function
86
+ */
87
+
88
+
89
+ onTokenChange(fn) {
90
+ return this._tokenStorage.on(this.tokenKey, fn);
91
+ }
92
+ /**
93
+ * Add state change listener
94
+ * @param {string} stateKey State key
95
+ * @param {function(string)} fn State change listener
96
+ * @return {function()} remove listener function
97
+ */
98
+
99
+
100
+ onStateChange(stateKey, fn) {
101
+ return this._stateStorage.on(this.stateKeyPrefix + stateKey, fn);
102
+ }
103
+ /**
104
+ * Add state change listener
105
+ * @param {string} key State key
106
+ * @param {function(string)} fn State change listener
107
+ * @return {function()} remove listener function
108
+ */
109
+
110
+
111
+ onMessage(key, fn) {
112
+ return this._messagesStorage.on(this.messagePrefix + key, message => fn(message));
113
+ }
114
+
115
+ sendMessage(key) {
116
+ let message = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
117
+ this._lastMessage = message;
118
+
119
+ this._messagesStorage.set(this.messagePrefix + key, message);
120
+ }
121
+ /**
122
+ * Save authentication request state.
123
+ *
124
+ * @param {string} id Unique state identifier
125
+ * @param {StoredState} state State to store
126
+ * @param {boolean=} dontCleanAndRetryOnFail If falsy then remove all stored states and try again to save state
127
+ */
128
+
129
+
130
+ async saveState(id, state, dontCleanAndRetryOnFail) {
131
+ state.created = Date.now();
132
+
133
+ try {
134
+ await this._stateStorage.set(this.stateKeyPrefix + id, state);
135
+ } catch (e) {
136
+ if (!dontCleanAndRetryOnFail) {
137
+ await this.cleanStates();
138
+ return this.saveState(id, state, true);
139
+ } else {
140
+ throw e;
141
+ }
142
+ }
143
+
144
+ return undefined;
145
+ }
146
+ /**
147
+ * Remove all stored states
148
+ *
149
+ * @return {Promise} promise that is resolved when OLD states [and some selected] are removed
150
+ */
151
+
152
+
153
+ async cleanStates(removeStateId) {
154
+ const now = Date.now();
155
+ const removalResult = await this._stateStorage.each((key, state) => {
156
+ // Remove requested state
157
+ if (key === this.stateKeyPrefix + removeStateId) {
158
+ return this._stateStorage.remove(key);
159
+ }
160
+
161
+ if (key.indexOf(this.stateKeyPrefix) === 0) {
162
+ // Clean old states
163
+ if (state.created + this.stateTTL < now) {
164
+ return this._stateStorage.remove(key);
165
+ } // Data to clean up due quota
166
+
167
+
168
+ return {
169
+ key,
170
+ created: state.created,
171
+ size: JSON.stringify(state).length
172
+ };
173
+ }
174
+
175
+ return undefined;
176
+ });
177
+ const currentStates = removalResult.filter(state => state);
178
+ let stateStorageSize = currentStates.reduce((overallSize, state) => state.size + overallSize, 0);
179
+
180
+ if (stateStorageSize > this.stateQuota) {
181
+ currentStates.sort((a, b) => a.created > b.created);
182
+ const removalPromises = currentStates.filter(state => {
183
+ if (stateStorageSize > this.stateQuota) {
184
+ stateStorageSize -= state.size;
185
+ return true;
186
+ }
187
+
188
+ return false;
189
+ }).map(state => this._stateStorage.remove(state.key));
190
+ return removalPromises.length && Promise.all(removalPromises);
191
+ }
192
+
193
+ return undefined;
194
+ }
195
+ /**
196
+ * Get state by id and remove stored states from the storage.
197
+ *
198
+ * @param {string} id unique state identifier
199
+ * @return {Promise.<StoredState>}
200
+ */
201
+
202
+
203
+ async getState(id) {
204
+ try {
205
+ const result = await this._stateStorage.get(this.stateKeyPrefix + id);
206
+ await this.cleanStates(id);
207
+ return result;
208
+ } catch (e) {
209
+ await this.cleanStates(id);
210
+ throw e;
211
+ }
212
+ }
213
+ /**
214
+ * @param {StoredToken} token
215
+ * @return {Promise} promise that is resolved when the token is saved
216
+ */
217
+
218
+
219
+ saveToken(token) {
220
+ return this._tokenStorage.set(this.tokenKey, token);
221
+ }
222
+ /**
223
+ * @return {Promise.<StoredToken>} promise that is resolved to the stored token
224
+ */
225
+
226
+
227
+ getToken() {
228
+ return this._tokenStorage.get(this.tokenKey);
229
+ }
230
+ /**
231
+ * Remove stored token if any.
232
+ * @return {Promise} promise that is resolved when the token is wiped.
233
+ */
234
+
235
+
236
+ wipeToken() {
237
+ return this._tokenStorage.remove(this.tokenKey);
238
+ }
239
+ /**
240
+ * @param {function} loadUser user loader
241
+ * @return {Promise.<object>>} promise that is resolved to stored current user
242
+ */
243
+
244
+
245
+ async getCachedUser(loadUser) {
246
+ const user = await this._currentUserStorage.get(this.userKey);
247
+
248
+ const loadAndCache = () => loadUser().then(response => {
249
+ this._currentUserStorage.set(this.userKey, response);
250
+
251
+ return response;
252
+ });
253
+
254
+ if (user && user.id) {
255
+ setTimeout(loadAndCache, UPDATE_USER_TIMEOUT);
256
+ return user;
257
+ } else {
258
+ return loadAndCache();
259
+ }
260
+ }
261
+ /**
262
+ * Remove cached user if any
263
+ */
264
+
265
+
266
+ wipeCachedCurrentUser() {
267
+ return this._currentUserStorage.remove(this.userKey);
268
+ }
269
+ /**
270
+ * Wipes cache if user has changed
271
+ */
272
+
273
+
274
+ onUserChanged() {
275
+ this.wipeCachedCurrentUser();
276
+ }
277
+
278
+ }
279
+
280
+ export { AuthStorage as default };
@@ -0,0 +1,176 @@
1
+ import { _ as _defineProperty } from '../_helpers/_rollupPluginBabelHelpers.js';
2
+ import ExtendableError from 'es6-error';
3
+ import { CODE } from '../http/http.js';
4
+ import '../global/url.js';
5
+
6
+ class TokenValidator {
7
+ constructor(config, getUser, storage) {
8
+ this._getUser = getUser;
9
+ this._config = config;
10
+ this._storage = storage;
11
+ }
12
+ /**
13
+ * Returns epoch - seconds since 1970.
14
+ * Used for calculation of expire times.
15
+ * @return {number} epoch, seconds since 1970
16
+ * @private
17
+ */
18
+
19
+
20
+ static _epoch() {
21
+ const milliseconds = 1000.0;
22
+ return Math.round(Date.now() / milliseconds);
23
+ }
24
+ /**
25
+ * @const {number}
26
+ */
27
+ // eslint-disable-next-line no-magic-numbers
28
+
29
+
30
+ /**
31
+ * Check token validity against all conditions.
32
+ * @returns {Promise.<string>}
33
+ */
34
+ validateTokenLocally() {
35
+ return this._getValidatedToken([TokenValidator._validateExistence, TokenValidator._validateExpiration, this._validateScopes.bind(this)]);
36
+ }
37
+ /**
38
+ * Check token validity against all conditions.
39
+ * @returns {Promise.<string>}
40
+ */
41
+
42
+
43
+ validateToken() {
44
+ return this._getValidatedToken([TokenValidator._validateExistence, TokenValidator._validateExpiration, this._validateScopes.bind(this), this._validateAgainstUser.bind(this)]);
45
+ }
46
+ /**
47
+ * Check if there is a token
48
+ * @param {StoredToken} storedToken
49
+ * @return {Promise.<StoredToken>}
50
+ * @private
51
+ */
52
+
53
+
54
+ static _validateExistence(storedToken) {
55
+ if (!storedToken || !storedToken.accessToken) {
56
+ throw new TokenValidator.TokenValidationError('Token not found');
57
+ }
58
+ }
59
+ /**
60
+ * Check expiration
61
+ * @param {StoredToken} storedToken
62
+ * @return {Promise.<StoredToken>}
63
+ * @private
64
+ */
65
+
66
+
67
+ static _validateExpiration(_ref) {
68
+ let {
69
+ expires,
70
+ lifeTime
71
+ } = _ref;
72
+ const REFRESH_BEFORE_RATIO = 6;
73
+ const refreshBefore = lifeTime ? Math.ceil(lifeTime / REFRESH_BEFORE_RATIO) : TokenValidator.DEFAULT_REFRESH_BEFORE;
74
+
75
+ if (expires && expires < TokenValidator._epoch() + refreshBefore) {
76
+ throw new TokenValidator.TokenValidationError('Token expired');
77
+ }
78
+ }
79
+ /**
80
+ * Check scopes
81
+ * @param {StoredToken} storedToken
82
+ * @return {Promise.<StoredToken>}
83
+ * @private
84
+ */
85
+
86
+
87
+ _validateScopes(storedToken) {
88
+ const {
89
+ scope,
90
+ optionalScopes
91
+ } = this._config;
92
+ const requiredScopes = optionalScopes ? scope.filter(scopeId => !optionalScopes.includes(scopeId)) : scope;
93
+ const hasAllScopes = requiredScopes.every(scopeId => storedToken.scopes.includes(scopeId));
94
+
95
+ if (!hasAllScopes) {
96
+ throw new TokenValidator.TokenValidationError('Token doesn\'t match required scopes');
97
+ }
98
+ }
99
+ /**
100
+ * Check by error code if token should be refreshed
101
+ * @param {string} error
102
+ * @return {boolean}
103
+ */
104
+
105
+
106
+ static shouldRefreshToken(error) {
107
+ return error === 'invalid_grant' || error === 'invalid_request' || error === 'invalid_token';
108
+ }
109
+ /**
110
+ * Check scopes
111
+ * @param {StoredToken} storedToken
112
+ * @return {Promise.<StoredToken>}
113
+ * @private
114
+ */
115
+
116
+
117
+ async _validateAgainstUser(storedToken) {
118
+ try {
119
+ return await this._getUser(storedToken.accessToken);
120
+ } catch (errorResponse) {
121
+ let response = {};
122
+
123
+ try {
124
+ response = await errorResponse.response.json();
125
+ } catch (e) {// Skip JSON parsing errors
126
+ }
127
+
128
+ if (errorResponse.status === CODE.UNAUTHORIZED || TokenValidator.shouldRefreshToken(response.error)) {
129
+ // Token expired
130
+ throw new TokenValidator.TokenValidationError(response.error || errorResponse.message);
131
+ } // Request unexpectedly failed
132
+
133
+
134
+ throw errorResponse;
135
+ }
136
+ }
137
+ /**
138
+ * Token Validator function
139
+ * @typedef {(function(StoredToken): Promise<StoredToken>)} TokenValidator
140
+ */
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
+
152
+
153
+ async _getValidatedToken(validators) {
154
+ const storedToken = await this._storage.getToken();
155
+
156
+ for (let i = 0; i < validators.length; i++) {
157
+ await validators[i](storedToken);
158
+ }
159
+
160
+ return storedToken.accessToken;
161
+ }
162
+
163
+ }
164
+
165
+ _defineProperty(TokenValidator, "DEFAULT_REFRESH_BEFORE", 10 * 60);
166
+
167
+ _defineProperty(TokenValidator, "TokenValidationError", class TokenValidationError extends ExtendableError {
168
+ constructor(message, cause) {
169
+ super(message);
170
+ this.cause = cause;
171
+ this.authRedirect = true;
172
+ }
173
+
174
+ });
175
+
176
+ export { TokenValidator as default };
@@ -0,0 +1,133 @@
1
+ import { _ as _defineProperty } from '../_helpers/_rollupPluginBabelHelpers.js';
2
+ import AuthResponseParser from './response-parser.js';
3
+ import 'es6-error';
4
+ import '../global/url.js';
5
+
6
+ const NAVBAR_HEIGHT = 50;
7
+ const CLOSED_CHECK_INTERVAL = 200;
8
+ class WindowFlow {
9
+ constructor(requestBuilder, storage) {
10
+ _defineProperty(this, "_timeoutId", null);
11
+
12
+ _defineProperty(this, "checkIsClosed", () => {
13
+ if (this._loginWindow.closed) {
14
+ this.stop();
15
+ return;
16
+ }
17
+
18
+ this._timeoutId = setTimeout(this.checkIsClosed, CLOSED_CHECK_INTERVAL);
19
+ });
20
+
21
+ _defineProperty(this, "_reset", () => {
22
+ this._promise = null;
23
+ this._loginWindow = null;
24
+ clearTimeout(this._timeoutId);
25
+ });
26
+
27
+ this._requestBuilder = requestBuilder;
28
+ this._storage = storage;
29
+
30
+ this._reset();
31
+ }
32
+ /**
33
+ * Opens window with the given URL
34
+ * @param {string} url
35
+ * @private
36
+ */
37
+
38
+
39
+ _openWindow(url) {
40
+ const height = 700;
41
+ const width = 750;
42
+ const screenHalves = 2;
43
+ const top = (window.screen.height - height - NAVBAR_HEIGHT) / screenHalves;
44
+ const left = (window.screen.width - width) / screenHalves;
45
+ return window.open(url, 'HubLoginWindow', `height=${height}, width=${width}, left=${left}, top=${top}`);
46
+ }
47
+ /**
48
+ * Initiates authorization in window
49
+ */
50
+
51
+
52
+ async _load() {
53
+ const authRequest = await this._requestBuilder.prepareAuthRequest( // 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
+
64
+ const cleanUp = () => {
65
+ if (cleanRun) {
66
+ return;
67
+ }
68
+
69
+ cleanRun = true;
70
+ /* eslint-disable no-use-before-define */
71
+
72
+ removeStateListener();
73
+ removeTokenListener();
74
+ /* eslint-enable no-use-before-define */
75
+
76
+ this._loginWindow.close();
77
+
78
+ clearTimeout(this._timeoutId);
79
+ };
80
+
81
+ const removeTokenListener = this._storage.onTokenChange(token => {
82
+ if (token) {
83
+ cleanUp();
84
+ resolve(token.accessToken);
85
+ }
86
+ });
87
+
88
+ const removeStateListener = this._storage.onStateChange(authRequest.stateId, state => {
89
+ if (state && state.error) {
90
+ cleanUp();
91
+ reject(new AuthResponseParser.AuthError(state));
92
+ }
93
+ });
94
+
95
+ if (this._loginWindow === null || this._loginWindow.closed === true) {
96
+ this._loginWindow = this._openWindow(authRequest.url);
97
+ } else {
98
+ this._loginWindow.location = authRequest.url;
99
+ }
100
+
101
+ this.checkIsClosed();
102
+ });
103
+ }
104
+
105
+ stop() {
106
+ if (this._loginWindow !== null) {
107
+ this._loginWindow.close();
108
+ }
109
+
110
+ if (this.reject) {
111
+ this.reject('Authorization window closed');
112
+ }
113
+
114
+ this._reset();
115
+ }
116
+
117
+ authorize() {
118
+ if (this._promise !== null && this._loginWindow !== null && this._loginWindow.closed !== true) {
119
+ this._loginWindow.focus();
120
+
121
+ return this._promise;
122
+ }
123
+
124
+ this._promise = this._load();
125
+
126
+ this._promise.then(this._reset, this._reset);
127
+
128
+ return this._promise;
129
+ }
130
+
131
+ }
132
+
133
+ export { WindowFlow as default };