@ytsaurus/ui 1.12.1 → 1.13.0

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 (176) hide show
  1. package/build/cjs/@types/core.d.ts +38 -0
  2. package/build/cjs/server/components/layout-config.js +6 -1
  3. package/build/cjs/server/components/layout-config.js.map +1 -1
  4. package/build/cjs/server/components/oauth.d.ts +26 -0
  5. package/build/cjs/server/components/oauth.js +123 -0
  6. package/build/cjs/server/components/oauth.js.map +1 -0
  7. package/build/cjs/server/components/yt-auth.d.ts +6 -0
  8. package/build/cjs/server/components/yt-auth.js +23 -0
  9. package/build/cjs/server/components/yt-auth.js.map +1 -0
  10. package/build/cjs/server/controllers/login.d.ts +0 -1
  11. package/build/cjs/server/controllers/login.js +4 -26
  12. package/build/cjs/server/controllers/login.js.map +1 -1
  13. package/build/cjs/server/controllers/logout.d.ts +2 -0
  14. package/build/cjs/server/controllers/logout.js +15 -0
  15. package/build/cjs/server/controllers/logout.js.map +1 -0
  16. package/build/cjs/server/controllers/oauth-login.d.ts +4 -0
  17. package/build/cjs/server/controllers/oauth-login.js +30 -0
  18. package/build/cjs/server/controllers/oauth-login.js.map +1 -0
  19. package/build/cjs/server/index.js +9 -1
  20. package/build/cjs/server/index.js.map +1 -1
  21. package/build/cjs/server/middlewares/authorization.d.ts +2 -0
  22. package/build/cjs/server/middlewares/authorization.js +42 -0
  23. package/build/cjs/server/middlewares/authorization.js.map +1 -0
  24. package/build/cjs/server/middlewares/oauth.d.ts +2 -0
  25. package/build/cjs/server/middlewares/oauth.js +27 -0
  26. package/build/cjs/server/middlewares/oauth.js.map +1 -0
  27. package/build/cjs/server/middlewares/yt-auth.d.ts +1 -1
  28. package/build/cjs/server/middlewares/yt-auth.js +10 -42
  29. package/build/cjs/server/middlewares/yt-auth.js.map +1 -1
  30. package/build/cjs/server/routes.js +6 -1
  31. package/build/cjs/server/routes.js.map +1 -1
  32. package/build/cjs/server/utils/authorization.d.ts +6 -0
  33. package/build/cjs/server/utils/authorization.js +33 -0
  34. package/build/cjs/server/utils/authorization.js.map +1 -0
  35. package/build/cjs/shared/constants/index.d.ts +3 -0
  36. package/build/cjs/shared/constants/index.js +3 -1
  37. package/build/cjs/shared/constants/index.js.map +1 -1
  38. package/build/cjs/shared/yt-types.d.ts +2 -0
  39. package/build/cjs/ui/components/Login/LoginFormPage/LoginFormPage.js +23 -5
  40. package/build/cjs/ui/components/Login/LoginFormPage/LoginFormPage.js.map +1 -1
  41. package/build/cjs/ui/components/Login/LoginPageWrapper/LoginPageWrapper.css +8 -0
  42. package/build/cjs/ui/components/Login/LoginPageWrapper/LoginPageWrapper.css.map +1 -1
  43. package/build/cjs/ui/components/NumberInput/NumberInput.d.ts +1 -1
  44. package/build/cjs/ui/constants/docsUrls.d.ts +1 -0
  45. package/build/cjs/ui/constants/docsUrls.js +1 -0
  46. package/build/cjs/ui/constants/docsUrls.js.map +1 -1
  47. package/build/cjs/ui/containers/AppNavigation/AppNavigation.js +2 -0
  48. package/build/cjs/ui/containers/AppNavigation/AppNavigation.js.map +1 -1
  49. package/build/cjs/ui/containers/AppNavigation/AppNavigationComponent.d.ts +1 -1
  50. package/build/cjs/ui/containers/AppNavigation/AppNavigationComponent.js +5 -7
  51. package/build/cjs/ui/containers/AppNavigation/AppNavigationComponent.js.map +1 -1
  52. package/build/cjs/ui/containers/AppNavigation/AppNavigationPageLayout.d.ts +2 -0
  53. package/build/cjs/ui/containers/AppNavigation/AppNavigationPageLayout.js.map +1 -1
  54. package/build/cjs/ui/pages/tablet_cell_bundles/bundles/BundleEditorDialog/BundleEditorDialog.js +11 -7
  55. package/build/cjs/ui/pages/tablet_cell_bundles/bundles/BundleEditorDialog/BundleEditorDialog.js.map +1 -1
  56. package/build/cjs/ui/store/actions/tablet_cell_bundles/index.js +1 -1
  57. package/build/cjs/ui/store/actions/tablet_cell_bundles/index.js.map +1 -1
  58. package/build/cjs/ui/store/reducers/global/index.d.ts +1 -0
  59. package/build/cjs/ui/store/reducers/global/index.js +1 -0
  60. package/build/cjs/ui/store/reducers/global/index.js.map +1 -1
  61. package/build/cjs/ui/store/reducers/tablet_cell_bundles/index.d.ts +8 -0
  62. package/build/cjs/ui/store/reducers/tablet_cell_bundles/index.js.map +1 -1
  63. package/build/cjs/ui/store/selectors/global/index.d.ts +4 -0
  64. package/build/cjs/ui/store/selectors/global/index.js +14 -4
  65. package/build/cjs/ui/store/selectors/global/index.js.map +1 -1
  66. package/build/cjs/ui/utils/tablet_cell_bundles/bundles/bundle-editor-dialog/index.d.ts +2 -1
  67. package/build/cjs/ui/utils/tablet_cell_bundles/bundles/bundle-editor-dialog/index.js +16 -1
  68. package/build/cjs/ui/utils/tablet_cell_bundles/bundles/bundle-editor-dialog/index.js.map +1 -1
  69. package/build/esm/@types/core.d.ts +38 -0
  70. package/build/esm/server/components/layout-config.js +7 -2
  71. package/build/esm/server/components/layout-config.js.map +1 -1
  72. package/build/esm/server/components/oauth.d.ts +26 -0
  73. package/build/esm/server/components/oauth.js +169 -0
  74. package/build/esm/server/components/oauth.js.map +1 -0
  75. package/build/esm/server/components/yt-auth.d.ts +6 -0
  76. package/build/esm/server/components/yt-auth.js +17 -0
  77. package/build/esm/server/components/yt-auth.js.map +1 -0
  78. package/build/esm/server/controllers/login.d.ts +0 -1
  79. package/build/esm/server/controllers/login.js +41 -88
  80. package/build/esm/server/controllers/login.js.map +1 -1
  81. package/build/esm/server/controllers/logout.d.ts +2 -0
  82. package/build/esm/server/controllers/logout.js +11 -0
  83. package/build/esm/server/controllers/logout.js.map +1 -0
  84. package/build/esm/server/controllers/oauth-login.d.ts +4 -0
  85. package/build/esm/server/controllers/oauth-login.js +50 -0
  86. package/build/esm/server/controllers/oauth-login.js.map +1 -0
  87. package/build/esm/server/index.js +7 -2
  88. package/build/esm/server/index.js.map +1 -1
  89. package/build/esm/server/middlewares/authorization.d.ts +2 -0
  90. package/build/esm/server/middlewares/authorization.js +74 -0
  91. package/build/esm/server/middlewares/authorization.js.map +1 -0
  92. package/build/esm/server/middlewares/oauth.d.ts +2 -0
  93. package/build/esm/server/middlewares/oauth.js +50 -0
  94. package/build/esm/server/middlewares/oauth.js.map +1 -0
  95. package/build/esm/server/middlewares/yt-auth.d.ts +1 -1
  96. package/build/esm/server/middlewares/yt-auth.js +8 -58
  97. package/build/esm/server/middlewares/yt-auth.js.map +1 -1
  98. package/build/esm/server/routes.js +16 -2
  99. package/build/esm/server/routes.js.map +1 -1
  100. package/build/esm/server/utils/authorization.d.ts +6 -0
  101. package/build/esm/server/utils/authorization.js +28 -0
  102. package/build/esm/server/utils/authorization.js.map +1 -0
  103. package/build/esm/shared/constants/index.d.ts +3 -0
  104. package/build/esm/shared/constants/index.js +2 -1
  105. package/build/esm/shared/constants/index.js.map +1 -1
  106. package/build/esm/shared/yt-types.d.ts +2 -0
  107. package/build/esm/ui/components/Login/LoginFormPage/LoginFormPage.js +24 -6
  108. package/build/esm/ui/components/Login/LoginFormPage/LoginFormPage.js.map +1 -1
  109. package/build/esm/ui/components/Login/LoginPageWrapper/LoginPageWrapper.css +8 -0
  110. package/build/esm/ui/components/Login/LoginPageWrapper/LoginPageWrapper.css.map +1 -1
  111. package/build/esm/ui/components/Login/LoginPageWrapper/LoginPageWrapper.scss +12 -0
  112. package/build/esm/ui/components/NumberInput/NumberInput.d.ts +1 -1
  113. package/build/esm/ui/constants/docsUrls.d.ts +1 -0
  114. package/build/esm/ui/constants/docsUrls.js +1 -0
  115. package/build/esm/ui/constants/docsUrls.js.map +1 -1
  116. package/build/esm/ui/containers/AppNavigation/AppNavigation.js +3 -1
  117. package/build/esm/ui/containers/AppNavigation/AppNavigation.js.map +1 -1
  118. package/build/esm/ui/containers/AppNavigation/AppNavigationComponent.d.ts +1 -1
  119. package/build/esm/ui/containers/AppNavigation/AppNavigationComponent.js +5 -7
  120. package/build/esm/ui/containers/AppNavigation/AppNavigationComponent.js.map +1 -1
  121. package/build/esm/ui/containers/AppNavigation/AppNavigationPageLayout.d.ts +2 -0
  122. package/build/esm/ui/containers/AppNavigation/AppNavigationPageLayout.js.map +1 -1
  123. package/build/esm/ui/pages/tablet_cell_bundles/bundles/BundleEditorDialog/BundleEditorDialog.js +12 -8
  124. package/build/esm/ui/pages/tablet_cell_bundles/bundles/BundleEditorDialog/BundleEditorDialog.js.map +1 -1
  125. package/build/esm/ui/store/actions/tablet_cell_bundles/index.js +1 -1
  126. package/build/esm/ui/store/actions/tablet_cell_bundles/index.js.map +1 -1
  127. package/build/esm/ui/store/reducers/global/index.d.ts +1 -0
  128. package/build/esm/ui/store/reducers/global/index.js +1 -0
  129. package/build/esm/ui/store/reducers/global/index.js.map +1 -1
  130. package/build/esm/ui/store/reducers/tablet_cell_bundles/index.d.ts +8 -0
  131. package/build/esm/ui/store/reducers/tablet_cell_bundles/index.js.map +1 -1
  132. package/build/esm/ui/store/selectors/global/index.d.ts +4 -0
  133. package/build/esm/ui/store/selectors/global/index.js +12 -2
  134. package/build/esm/ui/store/selectors/global/index.js.map +1 -1
  135. package/build/esm/ui/utils/tablet_cell_bundles/bundles/bundle-editor-dialog/index.d.ts +2 -1
  136. package/build/esm/ui/utils/tablet_cell_bundles/bundles/bundle-editor-dialog/index.js +15 -0
  137. package/build/esm/ui/utils/tablet_cell_bundles/bundles/bundle-editor-dialog/index.js.map +1 -1
  138. package/dist/public/build/assets-manifest.json +12 -12
  139. package/dist/public/build/css/{main.136a49c7.css → main.e919e247.css} +2 -2
  140. package/dist/public/build/css/main.e919e247.css.map +1 -0
  141. package/dist/public/build/js/89.07445d46.chunk.js +2 -0
  142. package/dist/public/build/js/89.07445d46.chunk.js.map +1 -0
  143. package/dist/public/build/js/main.9d592639.js +3 -0
  144. package/dist/public/build/js/{main.69fdeec5.js.map → main.9d592639.js.map} +1 -1
  145. package/dist/public/build/js/{runtime.6c8d85d3.js → runtime.9491563b.js} +2 -2
  146. package/dist/public/build/js/{runtime.6c8d85d3.js.map → runtime.9491563b.js.map} +1 -1
  147. package/dist/public/build/manifest.json +8 -8
  148. package/dist/server/components/layout-config.js +6 -1
  149. package/dist/server/components/oauth.d.ts +26 -0
  150. package/dist/server/components/oauth.js +123 -0
  151. package/dist/server/components/yt-auth.d.ts +6 -0
  152. package/dist/server/components/yt-auth.js +23 -0
  153. package/dist/server/controllers/login.d.ts +0 -1
  154. package/dist/server/controllers/login.js +4 -26
  155. package/dist/server/controllers/logout.d.ts +2 -0
  156. package/dist/server/controllers/logout.js +15 -0
  157. package/dist/server/controllers/oauth-login.d.ts +4 -0
  158. package/dist/server/controllers/oauth-login.js +30 -0
  159. package/dist/server/index.js +9 -1
  160. package/dist/server/middlewares/authorization.d.ts +2 -0
  161. package/dist/server/middlewares/authorization.js +42 -0
  162. package/dist/server/middlewares/oauth.d.ts +2 -0
  163. package/dist/server/middlewares/oauth.js +27 -0
  164. package/dist/server/middlewares/yt-auth.d.ts +1 -1
  165. package/dist/server/middlewares/yt-auth.js +10 -42
  166. package/dist/server/routes.js +6 -1
  167. package/dist/server/utils/authorization.d.ts +6 -0
  168. package/dist/server/utils/authorization.js +33 -0
  169. package/dist/shared/constants/index.d.ts +3 -0
  170. package/dist/shared/constants/index.js +3 -1
  171. package/package.json +2 -2
  172. package/dist/public/build/css/main.136a49c7.css.map +0 -1
  173. package/dist/public/build/js/89.6ea87438.chunk.js +0 -2
  174. package/dist/public/build/js/89.6ea87438.chunk.js.map +0 -1
  175. package/dist/public/build/js/main.69fdeec5.js +0 -3
  176. /package/dist/public/build/js/{main.69fdeec5.js.LICENSE.txt → main.9d592639.js.LICENSE.txt} +0 -0
@@ -12,10 +12,8 @@ import crypto from 'crypto';
12
12
  // @ts-ignore
13
13
  import ytLib from '@ytsaurus/javascript-wrapper';
14
14
  import { getXSRFToken } from '../components/cluster-queries';
15
+ import { getAuthCluster } from '../components/yt-auth';
15
16
  var yt = ytLib();
16
- function throwAuthDisabled() {
17
- throw new Error('Cluster for password authentication is disabled. You have to define ytAuthCluster to use it.');
18
- }
19
17
  export function handleLogin(_x, _x2) {
20
18
  return _handleLogin.apply(this, arguments);
21
19
  }
@@ -26,24 +24,18 @@ function _handleLogin() {
26
24
  while (1) switch (_context2.prev = _context2.next) {
27
25
  case 0:
28
26
  _context2.prev = 0;
29
- ytAuthCluster = req.ctx.config.ytAuthCluster;
30
- if (ytAuthCluster) {
31
- _context2.next = 4;
32
- break;
33
- }
34
- return _context2.abrupt("return", throwAuthDisabled());
35
- case 4:
27
+ ytAuthCluster = getAuthCluster(req.ctx.config);
36
28
  _ref = JSON.parse(req.body) || {}, username = _ref.username, password = _ref.password;
37
29
  if (!(!username || !password)) {
38
- _context2.next = 7;
30
+ _context2.next = 5;
39
31
  break;
40
32
  }
41
33
  throw new Error('Username and password must not be empty');
42
- case 7:
34
+ case 5:
43
35
  _getYTApiClusterSetup = getYTApiClusterSetup(ytAuthCluster), proxyBaseUrl = _getYTApiClusterSetup.proxyBaseUrl;
44
36
  requestUrl = "".concat(proxyBaseUrl, "/login");
45
37
  basicAuth = Buffer.from("".concat(username, ":").concat(password)).toString('base64');
46
- _context2.next = 12;
38
+ _context2.next = 10;
47
39
  return axios.request({
48
40
  url: requestUrl,
49
41
  method: req.method,
@@ -75,22 +67,22 @@ function _handleLogin() {
75
67
  }
76
68
  }, _callee);
77
69
  }));
78
- return function (_x7) {
70
+ return function (_x5) {
79
71
  return _ref2.apply(this, arguments);
80
72
  };
81
73
  }());
82
- case 12:
83
- _context2.next = 17;
74
+ case 10:
75
+ _context2.next = 15;
84
76
  break;
85
- case 14:
86
- _context2.prev = 14;
77
+ case 12:
78
+ _context2.prev = 12;
87
79
  _context2.t0 = _context2["catch"](0);
88
80
  sendAndLogError(req.ctx, res, 500, _context2.t0);
89
- case 17:
81
+ case 15:
90
82
  case "end":
91
83
  return _context2.stop();
92
84
  }
93
- }, _callee2, null, [[0, 14]]);
85
+ }, _callee2, null, [[0, 12]]);
94
86
  }));
95
87
  return _handleLogin.apply(this, arguments);
96
88
  }
@@ -115,86 +107,47 @@ function removeSecureFlagIfOriginInsecure(req, headers) {
115
107
  return acc;
116
108
  }, {});
117
109
  }
118
- export function handleLogout(_x3, _x4) {
119
- return _handleLogout.apply(this, arguments);
120
- }
121
- function _handleLogout() {
122
- _handleLogout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(req, res) {
123
- var ytAuthCluster;
124
- return _regeneratorRuntime.wrap(function _callee3$(_context3) {
125
- while (1) switch (_context3.prev = _context3.next) {
126
- case 0:
127
- _context3.prev = 0;
128
- ytAuthCluster = req.ctx.config.ytAuthCluster;
129
- if (ytAuthCluster) {
130
- _context3.next = 4;
131
- break;
132
- }
133
- return _context3.abrupt("return", throwAuthDisabled());
134
- case 4:
135
- res.setHeader('set-cookie', "".concat(YT_CYPRESS_COOKIE_NAME, "=deleted; Path=/; Max-Age=0;"));
136
- res.sendStatus(401).send('Logout');
137
- _context3.next = 11;
138
- break;
139
- case 8:
140
- _context3.prev = 8;
141
- _context3.t0 = _context3["catch"](0);
142
- sendAndLogError(req.ctx, res, 500, _context3.t0);
143
- case 11:
144
- case "end":
145
- return _context3.stop();
146
- }
147
- }, _callee3, null, [[0, 8]]);
148
- }));
149
- return _handleLogout.apply(this, arguments);
150
- }
151
- export function handleChangePassword(_x5, _x6) {
110
+ export function handleChangePassword(_x3, _x4) {
152
111
  return _handleChangePassword.apply(this, arguments);
153
112
  }
154
113
  function _handleChangePassword() {
155
- _handleChangePassword = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(req, res) {
114
+ _handleChangePassword = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(req, res) {
156
115
  var ytAuthCluster, _ref3, newPassword, currentPassword, new_password_sha256, current_password_sha256, cfg, _cfg, setup, _yield$getXSRFToken, login, csrf_token;
157
- return _regeneratorRuntime.wrap(function _callee4$(_context4) {
158
- while (1) switch (_context4.prev = _context4.next) {
116
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
117
+ while (1) switch (_context3.prev = _context3.next) {
159
118
  case 0:
160
- _context4.prev = 0;
161
- ytAuthCluster = req.ctx.config.ytAuthCluster;
162
- if (ytAuthCluster) {
163
- _context4.next = 4;
164
- break;
165
- }
166
- return _context4.abrupt("return", throwAuthDisabled());
167
- case 4:
119
+ _context3.prev = 0;
120
+ ytAuthCluster = getAuthCluster(req.ctx.config);
168
121
  _ref3 = JSON.parse(req.body) || {}, newPassword = _ref3.newPassword, currentPassword = _ref3.currentPassword;
169
122
  if (!(!newPassword || !currentPassword)) {
170
- _context4.next = 7;
123
+ _context3.next = 5;
171
124
  break;
172
125
  }
173
126
  throw new Error('New and current password must not be empty');
174
- case 7:
127
+ case 5:
175
128
  new_password_sha256 = crypto.createHash('sha256').update(newPassword).digest('hex');
176
129
  current_password_sha256 = crypto.createHash('sha256').update(currentPassword).digest('hex');
177
- _context4.prev = 9;
130
+ _context3.prev = 7;
178
131
  cfg = getUserYTApiSetup(ytAuthCluster, req);
179
- _context4.next = 17;
132
+ _context3.next = 15;
180
133
  break;
181
- case 13:
182
- _context4.prev = 13;
183
- _context4.t0 = _context4["catch"](9);
184
- sendAndLogError(req.ctx, res, 400, _context4.t0);
185
- return _context4.abrupt("return");
186
- case 17:
134
+ case 11:
135
+ _context3.prev = 11;
136
+ _context3.t0 = _context3["catch"](7);
137
+ sendAndLogError(req.ctx, res, 400, _context3.t0);
138
+ return _context3.abrupt("return");
139
+ case 15:
187
140
  _cfg = cfg, setup = _cfg.setup;
188
- _context4.next = 20;
141
+ _context3.next = 18;
189
142
  return getXSRFToken(req, cfg);
190
- case 20:
191
- _yield$getXSRFToken = _context4.sent;
143
+ case 18:
144
+ _yield$getXSRFToken = _context3.sent;
192
145
  login = _yield$getXSRFToken.login;
193
146
  csrf_token = _yield$getXSRFToken.csrf_token;
194
147
  yt.setup.createOption('requestHeaders', 'object', {
195
148
  'X-Csrf-Token': csrf_token
196
149
  });
197
- _context4.next = 26;
150
+ _context3.next = 24;
198
151
  return yt.v4.setUserPassword({
199
152
  setup: setup,
200
153
  parameters: {
@@ -209,18 +162,18 @@ function _handleChangePassword() {
209
162
  })["catch"](function (err) {
210
163
  sendAndLogError(req.ctx, res, 500, err);
211
164
  });
212
- case 26:
213
- _context4.next = 31;
165
+ case 24:
166
+ _context3.next = 29;
214
167
  break;
215
- case 28:
216
- _context4.prev = 28;
217
- _context4.t1 = _context4["catch"](0);
218
- sendAndLogError(req.ctx, res, 500, _context4.t1);
219
- case 31:
168
+ case 26:
169
+ _context3.prev = 26;
170
+ _context3.t1 = _context3["catch"](0);
171
+ sendAndLogError(req.ctx, res, 500, _context3.t1);
172
+ case 29:
220
173
  case "end":
221
- return _context4.stop();
174
+ return _context3.stop();
222
175
  }
223
- }, _callee4, null, [[0, 28], [9, 13]]);
176
+ }, _callee3, null, [[0, 26], [7, 11]]);
224
177
  }));
225
178
  return _handleChangePassword.apply(this, arguments);
226
179
  }
@@ -1 +1 @@
1
- {"version":3,"names":["axios","YT_CYPRESS_COOKIE_NAME","getUserYTApiSetup","getYTApiClusterSetup","UNEXPECTED_PIPE_AXIOS_RESPONSE","pipeAxiosResponse","sendAndLogError","crypto","ytLib","getXSRFToken","yt","throwAuthDisabled","Error","handleLogin","_x","_x2","_handleLogin","apply","arguments","_asyncToGenerator","_regeneratorRuntime","mark","_callee2","req","res","ytAuthCluster","_ref","username","password","_getYTApiClusterSetup","proxyBaseUrl","requestUrl","basicAuth","wrap","_callee2$","_context2","prev","next","ctx","config","abrupt","JSON","parse","body","concat","Buffer","from","toString","request","url","method","headers","_objectSpread","getMetadata","Authorization","timeout","responseType","then","_ref2","_callee","response","pipedSize","_callee$","_context","undefined","removeSecureFlagIfOriginInsecure","sent","stop","_x7","t0","ytAuthAllowInsecure","origin","startsWith","_reduce","acc","v","k","tmp","_map","item","replace","handleLogout","_x3","_x4","_handleLogout","_callee3","_callee3$","_context3","setHeader","sendStatus","send","handleChangePassword","_x5","_x6","_handleChangePassword","_callee4","_ref3","newPassword","currentPassword","new_password_sha256","current_password_sha256","cfg","_cfg","setup","_yield$getXSRFToken","login","csrf_token","_callee4$","_context4","createHash","update","digest","createOption","v4","setUserPassword","parameters","user","result","status","err","t1"],"sources":["login.ts"],"sourcesContent":["import type {Request, Response} from 'express';\nimport axios from 'axios';\nimport _ from 'lodash';\nimport {YT_CYPRESS_COOKIE_NAME} from '../../shared/constants';\nimport {getUserYTApiSetup, getYTApiClusterSetup} from '../components/requestsSetup';\nimport {UNEXPECTED_PIPE_AXIOS_RESPONSE, pipeAxiosResponse, sendAndLogError} from '../utils';\nimport crypto from 'crypto';\n\n// @ts-ignore\nimport ytLib from '@ytsaurus/javascript-wrapper';\nimport {getXSRFToken} from '../components/cluster-queries';\n\nconst yt = ytLib();\n\nfunction throwAuthDisabled() {\n throw new Error(\n 'Cluster for password authentication is disabled. You have to define ytAuthCluster to use it.',\n );\n}\n\nexport async function handleLogin(req: Request, res: Response) {\n try {\n const {ytAuthCluster} = req.ctx.config;\n if (!ytAuthCluster) {\n return throwAuthDisabled();\n }\n\n const {username, password} = JSON.parse(req.body) || {};\n if (!username || !password) {\n throw new Error('Username and password must not be empty');\n }\n\n const {proxyBaseUrl} = getYTApiClusterSetup(ytAuthCluster);\n const requestUrl = `${proxyBaseUrl}/login`;\n\n const basicAuth = Buffer.from(`${username}:${password}`).toString('base64');\n\n await axios\n .request({\n url: requestUrl,\n method: req.method as any,\n headers: {...req.ctx.getMetadata(), Authorization: `Basic ${basicAuth}`},\n timeout: 10000,\n responseType: 'stream',\n })\n .then(async (response) => {\n const pipedSize = await pipeAxiosResponse(\n req.ctx,\n res,\n response,\n undefined,\n (headers) => removeSecureFlagIfOriginInsecure(req, headers),\n );\n if (!pipedSize) {\n throw new Error(UNEXPECTED_PIPE_AXIOS_RESPONSE);\n }\n });\n } catch (e: any) {\n sendAndLogError(req.ctx, res, 500, e);\n }\n}\n\nfunction removeSecureFlagIfOriginInsecure(\n req: Request,\n headers: Record<string, string | Array<string>>,\n) {\n const {ytAuthAllowInsecure} = req.ctx.config;\n const {origin} = req.headers;\n\n if (!ytAuthAllowInsecure || 'string' !== typeof origin || !origin.startsWith('http://')) {\n return headers;\n }\n\n return _.reduce(\n headers,\n (acc, v, k) => {\n if (k !== 'set-cookie') {\n acc[k] = v;\n } else {\n const tmp = _.map(v as Array<string>, (item) => {\n if (item.startsWith(YT_CYPRESS_COOKIE_NAME)) {\n return item.replace(/\\s*Secure;/, '');\n }\n return item;\n });\n acc[k] = tmp;\n }\n return acc;\n },\n {} as typeof headers,\n );\n}\n\nexport async function handleLogout(req: Request, res: Response) {\n try {\n const {ytAuthCluster} = req.ctx.config;\n if (!ytAuthCluster) {\n return throwAuthDisabled();\n }\n res.setHeader('set-cookie', `${YT_CYPRESS_COOKIE_NAME}=deleted; Path=/; Max-Age=0;`);\n res.sendStatus(401).send('Logout');\n } catch (e: any) {\n sendAndLogError(req.ctx, res, 500, e);\n }\n}\n\nexport async function handleChangePassword(req: Request, res: Response) {\n try {\n const {ytAuthCluster} = req.ctx.config;\n if (!ytAuthCluster) {\n return throwAuthDisabled();\n }\n\n const {newPassword, currentPassword} = JSON.parse(req.body) || {};\n if (!newPassword || !currentPassword) {\n throw new Error('New and current password must not be empty');\n }\n\n const new_password_sha256 = crypto.createHash('sha256').update(newPassword).digest('hex');\n const current_password_sha256 = crypto\n .createHash('sha256')\n .update(currentPassword)\n .digest('hex');\n\n let cfg;\n try {\n cfg = getUserYTApiSetup(ytAuthCluster, req);\n } catch (e: any) {\n sendAndLogError(req.ctx, res, 400, e);\n return;\n }\n\n const {setup} = cfg;\n const {login, csrf_token} = await getXSRFToken(req, cfg);\n\n yt.setup.createOption('requestHeaders', 'object', {\n 'X-Csrf-Token': csrf_token,\n });\n\n await yt.v4\n .setUserPassword({\n setup,\n parameters: {user: login, new_password_sha256, current_password_sha256},\n })\n .then((result: unknown) => {\n res.status(200).send({result});\n })\n .catch((err: any) => {\n sendAndLogError(req.ctx, res, 500, err);\n });\n } catch (e: any) {\n sendAndLogError(req.ctx, res, 500, e);\n }\n}\n"],"mappings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;UAC1E,CAAC,CAAC,CACD3C,IAAI,CAAC,UAAC4D,MAAe,EAAK;YACvB7F,GAAG,CAAC8F,MAAM,CAAC,GAAG,CAAC,CAAC5B,IAAI,CAAC;cAAC2B,MAAM,EAANA;YAAM,CAAC,CAAC;UAClC,CAAC,CAAC,SACI,CAAC,UAACE,GAAQ,EAAK;YACjBjH,eAAe,CAACiB,GAAG,CAACe,GAAG,EAAEd,GAAG,EAAE,GAAG,EAAE+F,GAAG,CAAC;UAC3C,CAAC,CAAC;QAAA;UAAAX,SAAA,CAAAvE,IAAA;UAAA;QAAA;UAAAuE,SAAA,CAAAxE,IAAA;UAAAwE,SAAA,CAAAY,EAAA,GAAAZ,SAAA;UAENtG,eAAe,CAACiB,GAAG,CAACe,GAAG,EAAEd,GAAG,EAAE,GAAG,EAAAoF,SAAA,CAAAY,EAAG,CAAC;QAAC;QAAA;UAAA,OAAAZ,SAAA,CAAAzC,IAAA;MAAA;IAAA,GAAA4B,QAAA;EAAA,CAE7C;EAAA,OAAAD,qBAAA,CAAA7E,KAAA,OAAAC,SAAA;AAAA"}
1
+ {"version":3,"names":["axios","YT_CYPRESS_COOKIE_NAME","getUserYTApiSetup","getYTApiClusterSetup","UNEXPECTED_PIPE_AXIOS_RESPONSE","pipeAxiosResponse","sendAndLogError","crypto","ytLib","getXSRFToken","getAuthCluster","yt","handleLogin","_x","_x2","_handleLogin","apply","arguments","_asyncToGenerator","_regeneratorRuntime","mark","_callee2","req","res","ytAuthCluster","_ref","username","password","_getYTApiClusterSetup","proxyBaseUrl","requestUrl","basicAuth","wrap","_callee2$","_context2","prev","next","ctx","config","JSON","parse","body","Error","concat","Buffer","from","toString","request","url","method","headers","_objectSpread","getMetadata","Authorization","timeout","responseType","then","_ref2","_callee","response","pipedSize","_callee$","_context","undefined","removeSecureFlagIfOriginInsecure","sent","stop","_x5","t0","ytAuthAllowInsecure","origin","startsWith","_reduce","acc","v","k","tmp","_map","item","replace","handleChangePassword","_x3","_x4","_handleChangePassword","_callee3","_ref3","newPassword","currentPassword","new_password_sha256","current_password_sha256","cfg","_cfg","setup","_yield$getXSRFToken","login","csrf_token","_callee3$","_context3","createHash","update","digest","abrupt","createOption","v4","setUserPassword","parameters","user","result","status","send","err","t1"],"sources":["login.ts"],"sourcesContent":["import type {Request, Response} from 'express';\nimport axios from 'axios';\nimport _ from 'lodash';\nimport {YT_CYPRESS_COOKIE_NAME} from '../../shared/constants';\nimport {getUserYTApiSetup, getYTApiClusterSetup} from '../components/requestsSetup';\nimport {UNEXPECTED_PIPE_AXIOS_RESPONSE, pipeAxiosResponse, sendAndLogError} from '../utils';\nimport crypto from 'crypto';\n\n// @ts-ignore\nimport ytLib from '@ytsaurus/javascript-wrapper';\nimport {getXSRFToken} from '../components/cluster-queries';\nimport {getAuthCluster} from '../components/yt-auth';\n\nconst yt = ytLib();\n\nexport async function handleLogin(req: Request, res: Response) {\n try {\n const ytAuthCluster = getAuthCluster(req.ctx.config);\n\n const {username, password} = JSON.parse(req.body) || {};\n if (!username || !password) {\n throw new Error('Username and password must not be empty');\n }\n\n const {proxyBaseUrl} = getYTApiClusterSetup(ytAuthCluster);\n const requestUrl = `${proxyBaseUrl}/login`;\n\n const basicAuth = Buffer.from(`${username}:${password}`).toString('base64');\n\n await axios\n .request({\n url: requestUrl,\n method: req.method as any,\n headers: {...req.ctx.getMetadata(), Authorization: `Basic ${basicAuth}`},\n timeout: 10000,\n responseType: 'stream',\n })\n .then(async (response) => {\n const pipedSize = await pipeAxiosResponse(\n req.ctx,\n res,\n response,\n undefined,\n (headers) => removeSecureFlagIfOriginInsecure(req, headers),\n );\n if (!pipedSize) {\n throw new Error(UNEXPECTED_PIPE_AXIOS_RESPONSE);\n }\n });\n } catch (e: any) {\n sendAndLogError(req.ctx, res, 500, e);\n }\n}\n\nfunction removeSecureFlagIfOriginInsecure(\n req: Request,\n headers: Record<string, string | Array<string>>,\n) {\n const {ytAuthAllowInsecure} = req.ctx.config;\n const {origin} = req.headers;\n\n if (!ytAuthAllowInsecure || 'string' !== typeof origin || !origin.startsWith('http://')) {\n return headers;\n }\n\n return _.reduce(\n headers,\n (acc, v, k) => {\n if (k !== 'set-cookie') {\n acc[k] = v;\n } else {\n const tmp = _.map(v as Array<string>, (item) => {\n if (item.startsWith(YT_CYPRESS_COOKIE_NAME)) {\n return item.replace(/\\s*Secure;/, '');\n }\n return item;\n });\n acc[k] = tmp;\n }\n return acc;\n },\n {} as typeof headers,\n );\n}\n\nexport async function handleChangePassword(req: Request, res: Response) {\n try {\n const ytAuthCluster = getAuthCluster(req.ctx.config);\n\n const {newPassword, currentPassword} = JSON.parse(req.body) || {};\n if (!newPassword || !currentPassword) {\n throw new Error('New and current password must not be empty');\n }\n\n const new_password_sha256 = crypto.createHash('sha256').update(newPassword).digest('hex');\n const current_password_sha256 = crypto\n .createHash('sha256')\n .update(currentPassword)\n .digest('hex');\n\n let cfg;\n try {\n cfg = getUserYTApiSetup(ytAuthCluster, req);\n } catch (e: any) {\n sendAndLogError(req.ctx, res, 400, e);\n return;\n }\n\n const {setup} = cfg;\n const {login, csrf_token} = await getXSRFToken(req, cfg);\n\n yt.setup.createOption('requestHeaders', 'object', {\n 'X-Csrf-Token': csrf_token,\n });\n\n await yt.v4\n .setUserPassword({\n setup,\n parameters: {user: login, new_password_sha256, current_password_sha256},\n })\n .then((result: unknown) => {\n res.status(200).send({result});\n })\n .catch((err: any) => {\n sendAndLogError(req.ctx, res, 500, err);\n });\n } catch (e: any) {\n sendAndLogError(req.ctx, res, 500, e);\n }\n}\n"],"mappings":";;;;;AACA,OAAOA,KAAK,MAAM,OAAO;AAEzB,SAAQC,sBAAsB,QAAO,wBAAwB;AAC7D,SAAQC,iBAAiB,EAAEC,oBAAoB,QAAO,6BAA6B;AACnF,SAAQC,8BAA8B,EAAEC,iBAAiB,EAAEC,eAAe,QAAO,UAAU;AAC3F,OAAOC,MAAM,MAAM,QAAQ;;AAE3B;AACA,OAAOC,KAAK,MAAM,8BAA8B;AAChD,SAAQC,YAA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,GAAG,CAACe,GAAG,EAAEd,GAAG,EAAE,GAAG,EAAA0E,SAAA,CAAAc,EAAG,CAAC;QAAC;QAAA;UAAA,OAAAd,SAAA,CAAA/B,IAAA;MAAA;IAAA,GAAAkB,QAAA;EAAA,CAE7C;EAAA,OAAAD,qBAAA,CAAAnE,KAAA,OAAAC,SAAA;AAAA"}
@@ -0,0 +1,2 @@
1
+ import type { Request, Response } from 'express';
2
+ export declare function handleLogout(req: Request, res: Response): void;
@@ -0,0 +1,11 @@
1
+ import { getOAuthLogoutPath, isOAuthAllowed, isUserOAuthLogged } from '../components/oauth';
2
+ import { YTAuthLogout, isYtAuthEnabled } from '../components/yt-auth';
3
+ export function handleLogout(req, res) {
4
+ if (isOAuthAllowed(req) && isUserOAuthLogged(req)) {
5
+ res.redirect(getOAuthLogoutPath(req));
6
+ } else if (isYtAuthEnabled(req.ctx.config)) {
7
+ YTAuthLogout(res);
8
+ }
9
+ res.redirect('/');
10
+ }
11
+ // #sourceMappingURL=logout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["getOAuthLogoutPath","isOAuthAllowed","isUserOAuthLogged","YTAuthLogout","isYtAuthEnabled","handleLogout","req","res","redirect","ctx","config"],"sources":["logout.ts"],"sourcesContent":["import type {Request, Response} from 'express';\nimport {getOAuthLogoutPath, isOAuthAllowed, isUserOAuthLogged} from '../components/oauth';\nimport {YTAuthLogout, isYtAuthEnabled} from '../components/yt-auth';\n\nexport function handleLogout(req: Request, res: Response) {\n if (isOAuthAllowed(req) && isUserOAuthLogged(req)) {\n res.redirect(getOAuthLogoutPath(req));\n } else if (isYtAuthEnabled(req.ctx.config)) {\n YTAuthLogout(res);\n }\n res.redirect('/');\n}\n"],"mappings":"AACA,SAAQA,kBAAkB,EAAEC,cAAc,EAAEC,iBAAiB,QAAO,qBAAqB;AACzF,SAAQC,YAAY,EAAEC,eAAe,QAAO,uBAAuB;AAEnE,OAAO,SAASC,YAAYA,CAACC,GAAY,EAAEC,GAAa,EAAE;EACtD,IAAIN,cAAc,CAACK,GAAG,CAAC,IAAIJ,iBAAiB,CAACI,GAAG,CAAC,EAAE;IAC/CC,GAAG,CAACC,QAAQ,CAACR,kBAAkB,CAACM,GAAG,CAAC,CAAC;EACzC,CAAC,MAAM,IAAIF,eAAe,CAACE,GAAG,CAACG,GAAG,CAACC,MAAM,CAAC,EAAE;IACxCP,YAAY,CAACI,GAAG,CAAC;EACrB;EACAA,GAAG,CAACC,QAAQ,CAAC,GAAG,CAAC;AACrB"}
@@ -0,0 +1,4 @@
1
+ import type { Request, Response } from 'express';
2
+ export declare function oauthLogin(req: Request, res: Response): void;
3
+ export declare function oauthLogout(_: Request, res: Response): void;
4
+ export declare function oauthCallback(req: Request, res: Response): Promise<void>;
@@ -0,0 +1,50 @@
1
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
3
+ import { exchangeOAuthToken, getOAuthLoginPath, removeOAuthCookies, saveOAuthTokensInCookies } from '../components/oauth';
4
+ export function oauthLogin(req, res) {
5
+ res.redirect(getOAuthLoginPath(req));
6
+ }
7
+ export function oauthLogout(_, res) {
8
+ removeOAuthCookies(res);
9
+ res.redirect('/');
10
+ }
11
+ export function oauthCallback(_x, _x2) {
12
+ return _oauthCallback.apply(this, arguments);
13
+ }
14
+ function _oauthCallback() {
15
+ _oauthCallback = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(req, res) {
16
+ var code, tokens, message;
17
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
18
+ while (1) switch (_context.prev = _context.next) {
19
+ case 0:
20
+ code = req.query.code;
21
+ if (code) {
22
+ _context.next = 3;
23
+ break;
24
+ }
25
+ throw new Error('Authorization code is not specified');
26
+ case 3:
27
+ _context.prev = 3;
28
+ _context.next = 6;
29
+ return exchangeOAuthToken(req, code);
30
+ case 6:
31
+ tokens = _context.sent;
32
+ saveOAuthTokensInCookies(res, tokens);
33
+ res.redirect('/');
34
+ _context.next = 16;
35
+ break;
36
+ case 11:
37
+ _context.prev = 11;
38
+ _context.t0 = _context["catch"](3);
39
+ req.ctx.logError('exchange token error', _context.t0);
40
+ message = _context.t0 instanceof Error ? _context.t0.message : 'Unknown error';
41
+ res.status(500).send(message);
42
+ case 16:
43
+ case "end":
44
+ return _context.stop();
45
+ }
46
+ }, _callee, null, [[3, 11]]);
47
+ }));
48
+ return _oauthCallback.apply(this, arguments);
49
+ }
50
+ // #sourceMappingURL=oauth-login.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["exchangeOAuthToken","getOAuthLoginPath","removeOAuthCookies","saveOAuthTokensInCookies","oauthLogin","req","res","redirect","oauthLogout","_","oauthCallback","_x","_x2","_oauthCallback","apply","arguments","_asyncToGenerator","_regeneratorRuntime","mark","_callee","code","tokens","message","wrap","_callee$","_context","prev","next","query","Error","sent","t0","ctx","logError","status","send","stop"],"sources":["oauth-login.ts"],"sourcesContent":["import type {Request, Response} from 'express';\nimport {\n exchangeOAuthToken,\n getOAuthLoginPath,\n removeOAuthCookies,\n saveOAuthTokensInCookies,\n} from '../components/oauth';\n\nexport function oauthLogin(req: Request, res: Response) {\n res.redirect(getOAuthLoginPath(req));\n}\n\nexport function oauthLogout(_: Request, res: Response) {\n removeOAuthCookies(res);\n res.redirect('/');\n}\n\nexport async function oauthCallback(req: Request, res: Response) {\n const {code} = req.query;\n if (!code) {\n throw new Error('Authorization code is not specified');\n }\n\n try {\n const tokens = await exchangeOAuthToken(req, code as string);\n\n saveOAuthTokensInCookies(res, tokens);\n\n res.redirect('/');\n } catch (e) {\n req.ctx.logError('exchange token error', e);\n const message = e instanceof Error ? e.message : 'Unknown error';\n res.status(500).send(message);\n }\n}\n"],"mappings":";;AACA,SACIA,kBAAkB,EAClBC,iBAAiB,EACjBC,kBAAkB,EAClBC,wBAAwB,QACrB,qBAAqB;AAE5B,OAAO,SAASC,UAAUA,CAACC,GAAY,EAAEC,GAAa,EAAE;EACpDA,GAAG,CAACC,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,KAAK,GAAGJ,QAAA,CAAAM,EAAA,CAAET,OAAO,GAAG,eAAe;UAChEhB,GAAG,CAAC4B,MAAM,CAAC,GAAG,CAAC,CAACC,IAAI,CAACb,OAAO,CAAC;QAAC;QAAA;UAAA,OAAAG,QAAA,CAAAW,IAAA;MAAA;IAAA,GAAAjB,OAAA;EAAA,CAErC;EAAA,OAAAN,cAAA,CAAAC,KAAA,OAAAC,SAAA;AAAA"}
@@ -1,10 +1,14 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
1
2
  var _nodekit$config$adjus, _nodekit$config3;
2
3
  import path from 'path';
3
4
  import { NodeKit } from '@gravity-ui/nodekit';
4
5
  import { ExpressKit } from '@gravity-ui/expresskit';
5
6
  import { configureApp } from './configure-app';
6
- import { createYTAuthMiddleware } from './middlewares/yt-auth';
7
+ import { createYTAuthorizationResolver } from './middlewares/yt-auth';
7
8
  import routes from './routes';
9
+ import { createOAuthAuthorizationResolver } from './middlewares/oauth';
10
+ import { createAuthMiddleware } from './middlewares/authorization';
11
+ import { authorizationResolver } from './utils/authorization';
8
12
  var nodekit = new NodeKit({
9
13
  configsPath: path.resolve(__dirname, './configs')
10
14
  });
@@ -26,7 +30,8 @@ if (ytAuthCluster) {
26
30
  if (appAuthHandler) {
27
31
  nodekit.ctx.fail(new Error('"appAuthHandler" option will be ignored cause "ytAuthCluster" option is provided.'));
28
32
  }
29
- nodekit.config.appAuthHandler = createYTAuthMiddleware(ytAuthCluster);
33
+ nodekit.config.appBeforeAuthMiddleware = [].concat(_toConsumableArray(nodekit.config.appBeforeAuthMiddleware || []), [authorizationResolver(createOAuthAuthorizationResolver()), authorizationResolver(createYTAuthorizationResolver())]);
34
+ nodekit.config.appAuthHandler = createAuthMiddleware(ytAuthCluster);
30
35
  }
31
36
  (_nodekit$config$adjus = (_nodekit$config3 = nodekit.config).adjustAppConfig) === null || _nodekit$config$adjus === void 0 || _nodekit$config$adjus.call(_nodekit$config3, nodekit);
32
37
  var app = new ExpressKit(nodekit, routes);
@@ -1 +1 @@
1
- {"version":3,"names":["path","NodeKit","ExpressKit","configureApp","createYTAuthMiddleware","routes","nodekit","configsPath","resolve","__dirname","_nodekit$config","config","appName","appEnv","appInstallation","appDevMode","ctx","log","_nodekit$config2","ytAuthCluster","appAuthHandler","fail","Error","_nodekit$config$adjus","_nodekit$config3","adjustAppConfig","call","app","require","main","module","run"],"sources":["index.ts"],"sourcesContent":["import path from 'path';\nimport _reduce from 'lodash/reduce';\nimport {NodeKit} from '@gravity-ui/nodekit';\nimport {ExpressKit} from '@gravity-ui/expresskit';\n\nimport {configureApp} from './configure-app';\n\nimport {createYTAuthMiddleware} from './middlewares/yt-auth';\nimport routes from './routes';\n\nconst nodekit = new NodeKit({configsPath: path.resolve(__dirname, './configs')});\n\nconst {appName, appEnv, appInstallation, appDevMode} = nodekit.config;\nnodekit.ctx.log('AppConfig details', {\n appName,\n appEnv,\n appInstallation,\n appDevMode,\n});\n\nconst {ytAuthCluster, appAuthHandler} = nodekit.config;\n\nif (ytAuthCluster) {\n if (appAuthHandler) {\n nodekit.ctx.fail(\n new Error(\n '\"appAuthHandler\" option will be ignored cause \"ytAuthCluster\" option is provided.',\n ),\n );\n }\n\n nodekit.config.appAuthHandler = createYTAuthMiddleware(ytAuthCluster);\n}\n\nnodekit.config.adjustAppConfig?.(nodekit);\n\nconst app = new ExpressKit(nodekit, routes);\nconfigureApp(app);\n\nif (require.main === module) {\n app.run();\n}\n\nexport default app;\n"],"mappings":";AAAA,OAAOA,IAAI,MAAM,MAAM;AAEvB,SAAQC,OAAO,QAAO,qBAAqB;AAC3C,SAAQC,UAAU,QAAO,wBAAwB;AAEjD,SAAQC,YAAY,QAAO,iBAAiB;AAE5C,SAAQC,sBAAsB,QAAO,uBAAuB;AAC5D,OAAOC,MAAM,MAAM,UAAU;AAE7B,IAAMC,OAAO,GAAG,IAAIL,OAAO,CAAC;EAACM,WAAW,EAAEP,IAAI,CAACQ,OAAO,CAACC,SAAS,EAAE,WAAW;AAAC,CAAC,CAAC;AAEhF,IAAAC,eAAA,GAAuDJ,OAAO,CAACK,MAAM;EAA9DC,OAAO,GAAAF,eAAA,CAAPE,OAAO;EAAEC,MAAM,GAAAH,eAAA,CAANG,MAAM;EAAEC,eAAe,GAAAJ,eAAA,CAAfI,eAAe;EAAEC,UAAU,GAAAL,eAAA,CAAVK,UAAU;AACnDT,OAAO,CAACU,GAAG,CAACC,GAAG,CAAC,mBAAmB,EAAE;EACjCL,OAAO,EAAPA,OAAO;EACPC,MAAM,EAANA,MAAM;EACNC,eAAe,EAAfA,eAAe;EACfC,UAAU,EAAVA;AACJ,CAAC,CAAC;AAEF,IAAAG,gBAAA,GAAwCZ,OAAO,CAACK,MAAM;EAA/CQ,aAAa,GAAAD,gBAAA,CAAbC,aAAa;EAAEC,cAAc,GAAAF,gBAAA,CAAdE,cAAc;AAEpC,IAAID,aAAa,EAAE;EACf,IAAIC,cAAc,EAAE;IAChBd,OAAO,CAACU,GAAG,CAACK,IAAI,CACZ,IAAIC,KAAK,CACL,mFACJ,CACJ,CAAC;EACL;EAEAhB,OAAO,CAACK,MAAM,CAACS,cAAc,GAAGhB,sBAAsB,CAACe,aAAa,CAAC;AACzE;AAEA,CAAAI,qBAAA,IAAAC,gBAAA,GAAAlB,OAAO,CAACK,MAAM,EAACc,eAAe,cAAAF,qBAAA,eAA9BA,qBAAA,CAAAG,IAAA,CAAAF,gBAAA,EAAiClB,OAAO,CAAC;AAEzC,IAAMqB,GAAG,GAAG,IAAIzB,UAAU,CAACI,OAAO,EAAED,MAAM,CAAC;AAC3CF,YAAY,CAACwB,GAAG,CAAC;AAEjB,IAAIC,OAAO,CAACC,IAAI,KAAKC,MAAM,EAAE;EACzBH,GAAG,CAACI,GAAG,CAAC,CAAC;AACb;AAEA,eAAeJ,GAAG"}
1
+ {"version":3,"names":["path","NodeKit","ExpressKit","configureApp","createYTAuthorizationResolver","routes","createOAuthAuthorizationResolver","createAuthMiddleware","authorizationResolver","nodekit","configsPath","resolve","__dirname","_nodekit$config","config","appName","appEnv","appInstallation","appDevMode","ctx","log","_nodekit$config2","ytAuthCluster","appAuthHandler","fail","Error","appBeforeAuthMiddleware","concat","_toConsumableArray","_nodekit$config$adjus","_nodekit$config3","adjustAppConfig","call","app","require","main","module","run"],"sources":["index.ts"],"sourcesContent":["import path from 'path';\nimport _reduce from 'lodash/reduce';\nimport {NodeKit} from '@gravity-ui/nodekit';\nimport {ExpressKit} from '@gravity-ui/expresskit';\n\nimport {configureApp} from './configure-app';\n\nimport {createYTAuthorizationResolver} from './middlewares/yt-auth';\nimport routes from './routes';\nimport {createOAuthAuthorizationResolver} from './middlewares/oauth';\nimport {createAuthMiddleware} from './middlewares/authorization';\nimport {authorizationResolver} from './utils/authorization';\n\nconst nodekit = new NodeKit({configsPath: path.resolve(__dirname, './configs')});\n\nconst {appName, appEnv, appInstallation, appDevMode} = nodekit.config;\nnodekit.ctx.log('AppConfig details', {\n appName,\n appEnv,\n appInstallation,\n appDevMode,\n});\n\nconst {ytAuthCluster, appAuthHandler} = nodekit.config;\n\nif (ytAuthCluster) {\n if (appAuthHandler) {\n nodekit.ctx.fail(\n new Error(\n '\"appAuthHandler\" option will be ignored cause \"ytAuthCluster\" option is provided.',\n ),\n );\n }\n\n nodekit.config.appBeforeAuthMiddleware = [\n ...(nodekit.config.appBeforeAuthMiddleware || []),\n authorizationResolver(createOAuthAuthorizationResolver()),\n authorizationResolver(createYTAuthorizationResolver()),\n ];\n nodekit.config.appAuthHandler = createAuthMiddleware(ytAuthCluster);\n}\n\nnodekit.config.adjustAppConfig?.(nodekit);\n\nconst app = new ExpressKit(nodekit, routes);\nconfigureApp(app);\n\nif (require.main === module) {\n app.run();\n}\n\nexport default app;\n"],"mappings":";;AAAA,OAAOA,IAAI,MAAM,MAAM;AAEvB,SAAQC,OAAO,QAAO,qBAAqB;AAC3C,SAAQC,UAAU,QAAO,wBAAwB;AAEjD,SAAQC,YAAY,QAAO,iBAAiB;AAE5C,SAAQC,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;AACvE;AAEA,CAAAO,qBAAA,IAAAC,gBAAA,GAAArB,OAAO,CAACK,MAAM,EAACiB,eAAe,cAAAF,qBAAA,eAA9BA,qBAAA,CAAAG,IAAA,CAAAF,gBAAA,EAAiCrB,OAAO,CAAC;AAEzC,IAAMwB,GAAG,GAAG,IAAI/B,UAAU,CAACO,OAAO,EAAEJ,MAAM,CAAC;AAC3CF,YAAY,CAAC8B,GAAG,CAAC;AAEjB,IAAIC,OAAO,CAACC,IAAI,KAAKC,MAAM,EAAE;EACzBH,GAAG,CAACI,GAAG,CAAC,CAAC;AACb;AAEA,eAAeJ,GAAG"}
@@ -0,0 +1,2 @@
1
+ import { AppMiddleware } from '@gravity-ui/expresskit';
2
+ export declare function createAuthMiddleware(ytAuthCluster: string): AppMiddleware;
@@ -0,0 +1,74 @@
1
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
+ import _createClass from "@babel/runtime/helpers/createClass";
3
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
4
+ import _inherits from "@babel/runtime/helpers/inherits";
5
+ import _createSuper from "@babel/runtime/helpers/createSuper";
6
+ import _wrapNativeSuper from "@babel/runtime/helpers/wrapNativeSuper";
7
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
8
+ import axios from 'axios';
9
+ import { isAuthorized } from '../utils/authorization';
10
+ import { getUserYTApiSetup } from '../components/requestsSetup';
11
+ import { getXSRFToken } from '../components/cluster-queries';
12
+ import { sendError } from '../utils';
13
+ var AuthError = /*#__PURE__*/function (_Error) {
14
+ _inherits(AuthError, _Error);
15
+ var _super = _createSuper(AuthError);
16
+ function AuthError() {
17
+ _classCallCheck(this, AuthError);
18
+ return _super.call(this, 'Authorization required');
19
+ }
20
+ return _createClass(AuthError);
21
+ }( /*#__PURE__*/_wrapNativeSuper(Error));
22
+ function isAuthError(e) {
23
+ var _e$response;
24
+ return e instanceof AuthError || axios.isAxiosError(e) && ((_e$response = e.response) === null || _e$response === void 0 ? void 0 : _e$response.status) === 401;
25
+ }
26
+ export function createAuthMiddleware(ytAuthCluster) {
27
+ return /*#__PURE__*/function () {
28
+ var _authMiddleware = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(req, res, next) {
29
+ var cfg, _yield$getXSRFToken, login, isAuthFailed, error;
30
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
31
+ while (1) switch (_context.prev = _context.next) {
32
+ case 0:
33
+ _context.prev = 0;
34
+ if (isAuthorized(req)) {
35
+ _context.next = 3;
36
+ break;
37
+ }
38
+ throw new AuthError();
39
+ case 3:
40
+ cfg = getUserYTApiSetup(ytAuthCluster, req);
41
+ _context.next = 6;
42
+ return getXSRFToken(req, cfg);
43
+ case 6:
44
+ _yield$getXSRFToken = _context.sent;
45
+ login = _yield$getXSRFToken.login;
46
+ req.yt.login = login;
47
+ _context.next = 18;
48
+ break;
49
+ case 11:
50
+ _context.prev = 11;
51
+ _context.t0 = _context["catch"](0);
52
+ isAuthFailed = isAuthError(_context.t0);
53
+ error = isAuthFailed ? undefined : _context.t0;
54
+ if (!(!req.routeInfo.ui && isAuthFailed)) {
55
+ _context.next = 18;
56
+ break;
57
+ }
58
+ sendError(res, error, 401);
59
+ return _context.abrupt("return");
60
+ case 18:
61
+ next();
62
+ case 19:
63
+ case "end":
64
+ return _context.stop();
65
+ }
66
+ }, _callee, null, [[0, 11]]);
67
+ }));
68
+ function authMiddleware(_x, _x2, _x3) {
69
+ return _authMiddleware.apply(this, arguments);
70
+ }
71
+ return authMiddleware;
72
+ }();
73
+ }
74
+ // #sourceMappingURL=authorization.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["axios","isAuthorized","getUserYTApiSetup","getXSRFToken","sendError","AuthError","_Error","_inherits","_super","_createSuper","_classCallCheck","call","_createClass","_wrapNativeSuper","Error","isAuthError","e","_e$response","isAxiosError","response","status","createAuthMiddleware","ytAuthCluster","_authMiddleware","_asyncToGenerator","_regeneratorRuntime","mark","_callee","req","res","next","cfg","_yield$getXSRFToken","login","isAuthFailed","error","wrap","_callee$","_context","prev","sent","yt","t0","undefined","routeInfo","ui","abrupt","stop","authMiddleware","_x","_x2","_x3","apply","arguments"],"sources":["authorization.ts"],"sourcesContent":["import axios from 'axios';\nimport {isAuthorized} from '../utils/authorization';\nimport {getUserYTApiSetup} from '../components/requestsSetup';\nimport {AppMiddleware} from '@gravity-ui/expresskit';\nimport {getXSRFToken} from '../components/cluster-queries';\nimport {sendError} from '../utils';\n\nclass AuthError extends Error {\n constructor() {\n super('Authorization required');\n }\n}\n\nfunction isAuthError(e: unknown) {\n return e instanceof AuthError || (axios.isAxiosError(e) && e.response?.status === 401);\n}\n\nexport function createAuthMiddleware(ytAuthCluster: string): AppMiddleware {\n return async function authMiddleware(req, res, next) {\n try {\n if (!isAuthorized(req)) {\n throw new AuthError();\n }\n\n const cfg = getUserYTApiSetup(ytAuthCluster, req);\n const {login} = await getXSRFToken(req, cfg);\n req.yt.login = login;\n } catch (e) {\n const isAuthFailed = isAuthError(e);\n const error = isAuthFailed ? undefined : e;\n\n if (!req.routeInfo.ui && isAuthFailed) {\n sendError(res, error, 401);\n return;\n }\n }\n\n next();\n };\n}\n"],"mappings":";;;;;;;AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAAQC,YAAY,QAAO,wBAAwB;AACnD,SAAQC,iBAAiB,QAAO,6BAA6B;AAE7D,SAAQC,YAAY,QAAO,+BAA+B;AAC1D,SAAQC,SAAS,QAAO,UAAU;AAAC,IAE7BC,SAAS,0BAAAC,MAAA;EAAAC,SAAA,CAAAF,SAAA,EAAAC,MAAA;EAAA,IAAAE,MAAA,GAAAC,YAAA,CAAAJ,SAAA;EACX,SAAAA,UAAA,EAAc;IAAAK,eAAA,OAAAL,SAAA;IAAA,OAAAG,MAAA,CAAAG,IAAA,OACJ,wBAAwB;EAClC;EAAC,OAAAC,YAAA,CAAAP,SAAA;AAAA,gBAAAQ,gBAAA,CAHmBC,KAAK;AAM7B,SAASC,WAAWA,CAACC,CAA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CAAAI,EAAI;YAAA,MAEtC,CAACd,GAAG,CAACgB,SAAS,CAACC,EAAE,IAAIX,YAAY;cAAAI,QAAA,CAAAR,IAAA;cAAA;YAAA;YACjC1B,SAAS,CAACyB,GAAG,EAAEM,KAAK,EAAE,GAAG,CAAC;YAAC,OAAAG,QAAA,CAAAQ,MAAA;UAAA;YAKnChB,IAAI,CAAC,CAAC;UAAC;UAAA;YAAA,OAAAQ,QAAA,CAAAS,IAAA;QAAA;MAAA,GAAApB,OAAA;IAAA,CACV;IAAA,SApBqBqB,cAAcA,CAAAC,EAAA,EAAAC,GAAA,EAAAC,GAAA;MAAA,OAAA5B,eAAA,CAAA6B,KAAA,OAAAC,SAAA;IAAA;IAAA,OAAdL,cAAc;EAAA;AAqBxC"}
@@ -0,0 +1,2 @@
1
+ import { AppMiddleware } from '@gravity-ui/expresskit';
2
+ export declare function createOAuthAuthorizationResolver(): AppMiddleware;
@@ -0,0 +1,50 @@
1
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
3
+ import { getOAuthAccessToken, isOAuthAllowed, isUserOAuthLogged } from '../components/oauth';
4
+ export function createOAuthAuthorizationResolver() {
5
+ return /*#__PURE__*/function () {
6
+ var _resoleOAuthAuthorize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(req, res, next) {
7
+ var token;
8
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
9
+ while (1) switch (_context.prev = _context.next) {
10
+ case 0:
11
+ if (!(!isOAuthAllowed(req) || !isUserOAuthLogged(req))) {
12
+ _context.next = 3;
13
+ break;
14
+ }
15
+ next();
16
+ return _context.abrupt("return");
17
+ case 3:
18
+ _context.prev = 3;
19
+ _context.next = 6;
20
+ return getOAuthAccessToken(req, res);
21
+ case 6:
22
+ token = _context.sent;
23
+ req.yt = {
24
+ ytApiAuthHeaders: {
25
+ Authorization: "OAuth ".concat(token)
26
+ }
27
+ };
28
+ req.ctx.log('OAuth: provide a token');
29
+ _context.next = 14;
30
+ break;
31
+ case 11:
32
+ _context.prev = 11;
33
+ _context.t0 = _context["catch"](3);
34
+ req.ctx.logError('Can not resolve access token', _context.t0);
35
+ case 14:
36
+ next();
37
+ return _context.abrupt("return");
38
+ case 16:
39
+ case "end":
40
+ return _context.stop();
41
+ }
42
+ }, _callee, null, [[3, 11]]);
43
+ }));
44
+ function resoleOAuthAuthorize(_x, _x2, _x3) {
45
+ return _resoleOAuthAuthorize.apply(this, arguments);
46
+ }
47
+ return resoleOAuthAuthorize;
48
+ }();
49
+ }
50
+ // #sourceMappingURL=oauth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["getOAuthAccessToken","isOAuthAllowed","isUserOAuthLogged","createOAuthAuthorizationResolver","_resoleOAuthAuthorize","_asyncToGenerator","_regeneratorRuntime","mark","_callee","req","res","next","token","wrap","_callee$","_context","prev","abrupt","sent","yt","ytApiAuthHeaders","Authorization","concat","ctx","log","t0","logError","stop","resoleOAuthAuthorize","_x","_x2","_x3","apply","arguments"],"sources":["oauth.ts"],"sourcesContent":["import {AppMiddleware} from '@gravity-ui/expresskit';\nimport type {Request, Response} from 'express';\nimport {getOAuthAccessToken, isOAuthAllowed, isUserOAuthLogged} from '../components/oauth';\n\nexport function createOAuthAuthorizationResolver(): AppMiddleware {\n return async function resoleOAuthAuthorize(req: Request, res: Response, next) {\n if (!isOAuthAllowed(req) || !isUserOAuthLogged(req)) {\n next();\n return;\n }\n try {\n const token = await getOAuthAccessToken(req, res);\n req.yt = {\n ytApiAuthHeaders: {\n Authorization: `OAuth ${token}`,\n },\n };\n req.ctx.log('OAuth: provide a token');\n } catch (e) {\n req.ctx.logError('Can not resolve access token', e);\n }\n next();\n return;\n };\n}\n"],"mappings":";;AAEA,SAAQA,mBAAmB,EAAEC,cAAc,EAAEC,iBAAiB,QAAO,qBAAqB;AAE1F,OAAO,SAASC,gCAAgCA,CAAA,EAAkB;EAC9D;IAAA,IAAAC,qBAAA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AmB9C"}
@@ -1,2 +1,2 @@
1
1
  import { AppMiddleware } from '@gravity-ui/expresskit';
2
- export declare function createYTAuthMiddleware(ytAuthCluster: string): AppMiddleware;
2
+ export declare function createYTAuthorizationResolver(): AppMiddleware;