@verdaccio/api 6.0.0-6-next.15 → 6.0.0-6-next.19

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 (58) hide show
  1. package/CHANGELOG.md +108 -0
  2. package/build/dist-tags.d.ts +1 -1
  3. package/build/dist-tags.js +10 -10
  4. package/build/dist-tags.js.map +1 -1
  5. package/build/index.js +16 -10
  6. package/build/index.js.map +1 -1
  7. package/build/package.d.ts +1 -2
  8. package/build/package.js +30 -63
  9. package/build/package.js.map +1 -1
  10. package/build/ping.js.map +1 -1
  11. package/build/publish.d.ts +2 -2
  12. package/build/publish.js +28 -34
  13. package/build/publish.js.map +1 -1
  14. package/build/search.js +2 -2
  15. package/build/search.js.map +1 -1
  16. package/build/star.d.ts +1 -1
  17. package/build/star.js +9 -15
  18. package/build/star.js.map +1 -1
  19. package/build/stars.js +3 -3
  20. package/build/stars.js.map +1 -1
  21. package/build/user.d.ts +1 -1
  22. package/build/user.js +17 -17
  23. package/build/user.js.map +1 -1
  24. package/build/utils.js.map +1 -1
  25. package/build/v1/profile.js +10 -10
  26. package/build/v1/profile.js.map +1 -1
  27. package/build/v1/search.js +16 -7
  28. package/build/v1/search.js.map +1 -1
  29. package/build/v1/token.d.ts +1 -1
  30. package/build/v1/token.js +17 -23
  31. package/build/v1/token.js.map +1 -1
  32. package/build/whoami.js +0 -1
  33. package/build/whoami.js.map +1 -1
  34. package/package.json +18 -19
  35. package/src/dist-tags.ts +14 -13
  36. package/src/index.ts +16 -10
  37. package/src/package.ts +38 -57
  38. package/src/ping.ts +2 -1
  39. package/src/publish.ts +18 -11
  40. package/src/search.ts +1 -1
  41. package/src/star.ts +4 -3
  42. package/src/stars.ts +4 -4
  43. package/src/user.ts +13 -13
  44. package/src/utils.ts +2 -1
  45. package/src/v1/profile.ts +10 -9
  46. package/src/v1/search.ts +14 -7
  47. package/src/v1/token.ts +17 -16
  48. package/src/whoami.ts +3 -3
  49. package/test/integration/_helper.ts +7 -5
  50. package/test/integration/package.spec.ts +3 -2
  51. package/test/integration/ping.spec.ts +2 -1
  52. package/test/integration/publish.spec.ts +6 -9
  53. package/test/integration/user.spec.ts +9 -11
  54. package/test/integration/whoami.spec.ts +1 -1
  55. package/test/unit/publish.spec.ts +6 -6
  56. package/test/unit/validate.api.params.middleware.spec.ts +1 -1
  57. package/tsconfig.json +0 -3
  58. package/types/custom.d.ts +2 -1
package/src/package.ts CHANGED
@@ -1,15 +1,12 @@
1
- import _ from 'lodash';
2
- import { Router } from 'express';
3
1
  import buildDebug from 'debug';
2
+ import { Router } from 'express';
4
3
 
5
- import { allow } from '@verdaccio/middleware';
6
- import { getVersion, ErrorCode } from '@verdaccio/utils';
7
- import { HEADERS, DIST_TAGS, API_ERROR } from '@verdaccio/commons-api';
8
- import { Config, Package } from '@verdaccio/types';
9
4
  import { IAuth } from '@verdaccio/auth';
5
+ import { HEADERS, errorUtils } from '@verdaccio/core';
6
+ import { allow } from '@verdaccio/middleware';
10
7
  import { Storage } from '@verdaccio/store';
11
- import { convertDistRemoteToLocalTarballUrls } from '@verdaccio/tarball';
12
- import { $RequestExtend, $ResponseExtend, $NextFunctionVer } from '../types/custom';
8
+
9
+ import { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types/custom';
13
10
 
14
11
  const debug = buildDebug('verdaccio:api:package');
15
12
 
@@ -17,7 +14,7 @@ const downloadStream = (
17
14
  packageName: string,
18
15
  filename: string,
19
16
  storage: any,
20
- req: $RequestExtend,
17
+ _req: $RequestExtend,
21
18
  res: $ResponseExtend
22
19
  ): void => {
23
20
  const stream = storage.getTarball(packageName, filename);
@@ -34,63 +31,47 @@ const downloadStream = (
34
31
  stream.pipe(res);
35
32
  };
36
33
 
37
- export default function (route: Router, auth: IAuth, storage: Storage, config: Config): void {
34
+ export default function (route: Router, auth: IAuth, storage: Storage): void {
38
35
  const can = allow(auth);
39
- // TODO: anonymous user?
36
+
40
37
  route.get(
41
38
  '/:package/:version?',
42
39
  can('access'),
43
- function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void {
40
+ async function (
41
+ req: $RequestExtend,
42
+ _res: $ResponseExtend,
43
+ next: $NextFunctionVer
44
+ ): Promise<void> {
44
45
  debug('init package by version');
45
46
  const name = req.params.package;
46
- const getPackageMetaCallback = function (err, metadata: Package): void {
47
- if (err) {
48
- debug('error on fetch metadata for %o with error %o', name, err.message);
49
- return next(err);
50
- }
51
- debug('convert dist remote to local with prefix %o', config?.url_prefix);
52
- metadata = convertDistRemoteToLocalTarballUrls(metadata, req, config?.url_prefix);
53
-
54
- let queryVersion = req.params.version;
55
- debug('query by param version: %o', queryVersion);
56
- if (_.isNil(queryVersion)) {
57
- debug('param %o version found', queryVersion);
58
- return next(metadata);
59
- }
60
-
61
- let version = getVersion(metadata, queryVersion);
62
- debug('query by latest version %o and result %o', queryVersion, version);
63
- if (_.isNil(version) === false) {
64
- debug('latest version found %o', version);
65
- return next(version);
66
- }
47
+ let queryVersion = req.params.version;
48
+ const requestOptions = {
49
+ protocol: req.protocol,
50
+ headers: req.headers as any,
51
+ // FIXME: if we migrate to req.hostname, the port is not longer included.
52
+ host: req.host,
53
+ };
67
54
 
68
- if (_.isNil(metadata[DIST_TAGS]) === false) {
69
- if (_.isNil(metadata[DIST_TAGS][queryVersion]) === false) {
70
- queryVersion = metadata[DIST_TAGS][queryVersion];
71
- debug('dist-tag version found %o', queryVersion);
72
- version = getVersion(metadata, queryVersion);
73
- if (_.isNil(version) === false) {
74
- debug('dist-tag found %o', version);
75
- return next(version);
76
- }
77
- }
78
- } else {
79
- debug('dist tag not detected');
55
+ try {
56
+ // TODO: this is just temporary while I migrate all plugins to use the new API
57
+ // the method will be renamed to getPackage again but Promise Based.
58
+ if (!storage.getPackageNext) {
59
+ throw errorUtils.getInternalError(
60
+ 'getPackageNext not implemented, check pr-2750 for more details'
61
+ );
80
62
  }
81
63
 
82
- debug('package version not found %o', queryVersion);
83
- return next(ErrorCode.getNotFound(`${API_ERROR.VERSION_NOT_EXIST}: ${queryVersion}`));
84
- };
85
-
86
- debug('get package name %o', name);
87
- debug('uplinks look up enabled');
88
- storage.getPackage({
89
- name,
90
- uplinksLook: true,
91
- req,
92
- callback: getPackageMetaCallback,
93
- });
64
+ const manifest = await storage.getPackageNext({
65
+ name,
66
+ uplinksLook: true,
67
+ req,
68
+ version: queryVersion,
69
+ requestOptions,
70
+ });
71
+ next(manifest);
72
+ } catch (err) {
73
+ next(err);
74
+ }
94
75
  }
95
76
  );
96
77
 
package/src/ping.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { Router } from 'express';
2
- import { $RequestExtend, $ResponseExtend, $NextFunctionVer } from '../types/custom';
2
+
3
+ import { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types/custom';
3
4
 
4
5
  export default function (route: Router): void {
5
6
  route.get(
package/src/publish.ts CHANGED
@@ -1,19 +1,26 @@
1
- import Path from 'path';
1
+ import buildDebug from 'debug';
2
+ import { Router } from 'express';
2
3
  import _ from 'lodash';
3
4
  import mime from 'mime';
4
- import { Router } from 'express';
5
- import buildDebug from 'debug';
5
+ import Path from 'path';
6
6
 
7
- import { API_MESSAGE, HEADERS, DIST_TAGS, API_ERROR, HTTP_STATUS } from '@verdaccio/commons-api';
8
- import { validateMetadata, isObject, ErrorCode, hasDiffOneKey } from '@verdaccio/utils';
9
- import { media, expectJson, allow } from '@verdaccio/middleware';
7
+ import { IAuth } from '@verdaccio/auth';
8
+ import {
9
+ API_ERROR,
10
+ API_MESSAGE,
11
+ DIST_TAGS,
12
+ HEADERS,
13
+ HTTP_STATUS,
14
+ errorUtils,
15
+ } from '@verdaccio/core';
10
16
  import { notify } from '@verdaccio/hooks';
11
- import { Config, Callback, MergeTags, Version, Package, CallbackAction } from '@verdaccio/types';
12
17
  import { logger } from '@verdaccio/logger';
13
- import { IAuth } from '@verdaccio/auth';
18
+ import { allow, expectJson, media } from '@verdaccio/middleware';
14
19
  import { Storage } from '@verdaccio/store';
15
- import { $RequestExtend, $ResponseExtend, $NextFunctionVer } from '../types/custom';
20
+ import { Callback, CallbackAction, Config, MergeTags, Package, Version } from '@verdaccio/types';
21
+ import { hasDiffOneKey, isObject, validateMetadata } from '@verdaccio/utils';
16
22
 
23
+ import { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types/custom';
17
24
  import star from './star';
18
25
  import { isPublishablePackage, isRelatedToDeprecation } from './utils';
19
26
 
@@ -224,7 +231,7 @@ export function publishPackage(storage: Storage, config: Config, auth: IAuth): a
224
231
  // if this happens in normal circumstances, report it as a bug
225
232
  debug('invalid body format');
226
233
  logger.info({ packageName }, `wrong package format on publish a package @{packageName}`);
227
- return next(ErrorCode.getBadRequest(API_ERROR.UNSUPORTED_REGISTRY_CALL));
234
+ return next(errorUtils.getBadRequest(API_ERROR.UNSUPORTED_REGISTRY_CALL));
228
235
  }
229
236
 
230
237
  if (error && error.status !== HTTP_STATUS.CONFLICT) {
@@ -322,7 +329,7 @@ export function publishPackage(storage: Storage, config: Config, auth: IAuth): a
322
329
  } catch (error: any) {
323
330
  debug('error on publish, bad package format %o', packageName);
324
331
  logger.error({ packageName }, 'error on publish, bad package data for @{packageName}');
325
- return next(ErrorCode.getBadData(API_ERROR.BAD_PACKAGE_DATA));
332
+ return next(errorUtils.getBadData(API_ERROR.BAD_PACKAGE_DATA));
326
333
  }
327
334
  };
328
335
  }
package/src/search.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { HTTP_STATUS } from '@verdaccio/commons-api';
1
+ import { HTTP_STATUS } from '@verdaccio/core';
2
2
  import { logger } from '@verdaccio/logger';
3
3
 
4
4
  export default function (route): void {
package/src/star.ts CHANGED
@@ -1,10 +1,11 @@
1
- import { USERS, HTTP_STATUS } from '@verdaccio/commons-api';
1
+ import buildDebug from 'debug';
2
2
  import { Response } from 'express';
3
3
  import _ from 'lodash';
4
- import buildDebug from 'debug';
5
4
 
5
+ import { HTTP_STATUS, USERS } from '@verdaccio/core';
6
6
  import { Storage } from '@verdaccio/store';
7
- import { $RequestExtend, $NextFunctionVer } from '../types/custom';
7
+
8
+ import { $NextFunctionVer, $RequestExtend } from '../types/custom';
8
9
 
9
10
  const debug = buildDebug('verdaccio:api:publish:star');
10
11
 
package/src/stars.ts CHANGED
@@ -1,11 +1,11 @@
1
- import _ from 'lodash';
2
1
  import { Response, Router } from 'express';
2
+ import _ from 'lodash';
3
3
 
4
- import { USERS, HTTP_STATUS } from '@verdaccio/commons-api';
4
+ import { HTTP_STATUS, USERS } from '@verdaccio/core';
5
+ import { Storage } from '@verdaccio/store';
5
6
  import { Package } from '@verdaccio/types';
6
7
 
7
- import { Storage } from '@verdaccio/store';
8
- import { $RequestExtend, $NextFunctionVer } from '../types/custom';
8
+ import { $NextFunctionVer, $RequestExtend } from '../types/custom';
9
9
 
10
10
  type Packages = Package[];
11
11
 
package/src/user.ts CHANGED
@@ -1,16 +1,16 @@
1
- import _ from 'lodash';
2
- import { Response, Router } from 'express';
3
1
  import buildDebug from 'debug';
2
+ import { Response, Router } from 'express';
3
+ import _ from 'lodash';
4
4
 
5
- import { getAuthenticatedMessage, validatePassword, ErrorCode } from '@verdaccio/utils';
6
5
  import { getApiToken } from '@verdaccio/auth';
7
- import { logger } from '@verdaccio/logger';
6
+ import { IAuth } from '@verdaccio/auth';
8
7
  import { createRemoteUser } from '@verdaccio/config';
9
-
8
+ import { API_ERROR, API_MESSAGE, HTTP_STATUS, errorUtils } from '@verdaccio/core';
9
+ import { logger } from '@verdaccio/logger';
10
10
  import { Config, RemoteUser } from '@verdaccio/types';
11
- import { IAuth } from '@verdaccio/auth';
12
- import { API_ERROR, API_MESSAGE, HTTP_STATUS } from '@verdaccio/commons-api';
13
- import { $RequestExtend, $NextFunctionVer } from '../types/custom';
11
+ import { getAuthenticatedMessage, validatePassword } from '@verdaccio/utils';
12
+
13
+ import { $NextFunctionVer, $RequestExtend } from '../types/custom';
14
14
 
15
15
  const debug = buildDebug('verdaccio:api:user');
16
16
 
@@ -47,7 +47,7 @@ export default function (route: Router, auth: IAuth, config: Config): void {
47
47
  'authenticating for user @{username} failed. Error: @{err.message}'
48
48
  );
49
49
  return next(
50
- ErrorCode.getCode(HTTP_STATUS.UNAUTHORIZED, API_ERROR.BAD_USERNAME_PASSWORD)
50
+ errorUtils.getCode(HTTP_STATUS.UNAUTHORIZED, API_ERROR.BAD_USERNAME_PASSWORD)
51
51
  );
52
52
  }
53
53
 
@@ -55,7 +55,7 @@ export default function (route: Router, auth: IAuth, config: Config): void {
55
55
  const token = await getApiToken(auth, config, restoredRemoteUser, password);
56
56
  debug('login: new token');
57
57
  if (!token) {
58
- return next(ErrorCode.getUnauthorized());
58
+ return next(errorUtils.getUnauthorized());
59
59
  }
60
60
 
61
61
  res.status(HTTP_STATUS.CREATED);
@@ -73,7 +73,7 @@ export default function (route: Router, auth: IAuth, config: Config): void {
73
73
  if (validatePassword(password) === false) {
74
74
  debug('adduser: invalid password');
75
75
  // eslint-disable-next-line new-cap
76
- return next(ErrorCode.getCode(HTTP_STATUS.BAD_REQUEST, API_ERROR.PASSWORD_SHORT()));
76
+ return next(errorUtils.getCode(HTTP_STATUS.BAD_REQUEST, API_ERROR.PASSWORD_SHORT()));
77
77
  }
78
78
 
79
79
  auth.add_user(name, password, async function (err, user): Promise<void> {
@@ -84,7 +84,7 @@ export default function (route: Router, auth: IAuth, config: Config): void {
84
84
  // and npm accepts only an 409 error.
85
85
  // So, changing status code here.
86
86
  return next(
87
- ErrorCode.getCode(err.status, err.message) || ErrorCode.getConflict(err.message)
87
+ errorUtils.getCode(err.status, err.message) || errorUtils.getConflict(err.message)
88
88
  );
89
89
  }
90
90
  return next(err);
@@ -94,7 +94,7 @@ export default function (route: Router, auth: IAuth, config: Config): void {
94
94
  name && password ? await getApiToken(auth, config, user, password) : undefined;
95
95
  debug('adduser: new token %o', token);
96
96
  if (!token) {
97
- return next(ErrorCode.getUnauthorized());
97
+ return next(errorUtils.getUnauthorized());
98
98
  }
99
99
 
100
100
  req.remote_user = user;
package/src/utils.ts CHANGED
@@ -1,6 +1,7 @@
1
- import { Package } from '@verdaccio/types';
2
1
  import _ from 'lodash';
3
2
 
3
+ import { Package } from '@verdaccio/types';
4
+
4
5
  /**
5
6
  * Check whether the package metadta has enough data to be published
6
7
  * @param pkg metadata
package/src/v1/profile.ts CHANGED
@@ -1,10 +1,11 @@
1
- import _ from 'lodash';
2
1
  import { Response, Router } from 'express';
2
+ import _ from 'lodash';
3
3
 
4
- import { API_ERROR, APP_ERROR, HTTP_STATUS, SUPPORT_ERRORS } from '@verdaccio/commons-api';
5
- import { ErrorCode, validatePassword } from '@verdaccio/utils';
6
4
  import { IAuth } from '@verdaccio/auth';
7
- import { $RequestExtend, $NextFunctionVer } from '../../types/custom';
5
+ import { API_ERROR, APP_ERROR, HTTP_STATUS, SUPPORT_ERRORS, errorUtils } from '@verdaccio/core';
6
+ import { validatePassword } from '@verdaccio/utils';
7
+
8
+ import { $NextFunctionVer, $RequestExtend } from '../../types/custom';
8
9
 
9
10
  export interface Profile {
10
11
  tfa: boolean;
@@ -61,7 +62,7 @@ export default function (route: Router, auth: IAuth): void {
61
62
  if (_.isNil(password) === false) {
62
63
  if (validatePassword(password.new) === false) {
63
64
  /* eslint new-cap:off */
64
- return next(ErrorCode.getCode(HTTP_STATUS.UNAUTHORIZED, API_ERROR.PASSWORD_SHORT()));
65
+ return next(errorUtils.getCode(HTTP_STATUS.UNAUTHORIZED, API_ERROR.PASSWORD_SHORT()));
65
66
  /* eslint new-cap:off */
66
67
  }
67
68
 
@@ -72,22 +73,22 @@ export default function (route: Router, auth: IAuth): void {
72
73
  (err, isUpdated): $NextFunctionVer => {
73
74
  if (_.isNull(err) === false) {
74
75
  return next(
75
- ErrorCode.getCode(err.status, err.message) || ErrorCode.getConflict(err.message)
76
+ errorUtils.getCode(err.status, err.message) || errorUtils.getConflict(err.message)
76
77
  );
77
78
  }
78
79
 
79
80
  if (isUpdated) {
80
81
  return next(buildProfile(req.remote_user.name));
81
82
  }
82
- return next(ErrorCode.getInternalError(API_ERROR.INTERNAL_SERVER_ERROR));
83
+ return next(errorUtils.getInternalError(API_ERROR.INTERNAL_SERVER_ERROR));
83
84
  }
84
85
  );
85
86
  } else if (_.isNil(tfa) === false) {
86
87
  return next(
87
- ErrorCode.getCode(HTTP_STATUS.SERVICE_UNAVAILABLE, SUPPORT_ERRORS.TFA_DISABLED)
88
+ errorUtils.getCode(HTTP_STATUS.SERVICE_UNAVAILABLE, SUPPORT_ERRORS.TFA_DISABLED)
88
89
  );
89
90
  } else {
90
- return next(ErrorCode.getCode(HTTP_STATUS.INTERNAL_ERROR, APP_ERROR.PROFILE_ERROR));
91
+ return next(errorUtils.getCode(HTTP_STATUS.INTERNAL_ERROR, APP_ERROR.PROFILE_ERROR));
91
92
  }
92
93
  }
93
94
  );
package/src/v1/search.ts CHANGED
@@ -1,9 +1,9 @@
1
- import _ from 'lodash';
2
1
  import buildDebug from 'debug';
3
- import { logger } from '@verdaccio/logger';
2
+ import _ from 'lodash';
3
+
4
4
  import { IAuth } from '@verdaccio/auth';
5
- import { searchUtils } from '@verdaccio/core';
6
- import { HTTP_STATUS } from '@verdaccio/commons-api';
5
+ import { HTTP_STATUS, searchUtils } from '@verdaccio/core';
6
+ import { logger } from '@verdaccio/logger';
7
7
  import { Storage } from '@verdaccio/store';
8
8
  import { Package } from '@verdaccio/types';
9
9
 
@@ -36,16 +36,23 @@ export default function (route, auth: IAuth, storage: Storage): void {
36
36
  }
37
37
 
38
38
  route.get('/-/v1/search', async (req, res, next) => {
39
- let [size, from] = ['size', 'from'].map((k) => req.query[k]);
39
+ const { query, url } = req;
40
+ let [size, from] = ['size', 'from'].map((k) => query[k]);
40
41
  let data;
42
+ const abort = new AbortController();
43
+
44
+ req.on('aborted', () => {
45
+ abort.abort();
46
+ });
41
47
 
42
48
  size = parseInt(size, 10) || 20;
43
49
  from = parseInt(from, 10) || 0;
44
50
 
45
51
  try {
46
52
  data = await storage.searchManager?.search({
47
- query: req.query,
48
- url: req.url,
53
+ query,
54
+ url,
55
+ abort,
49
56
  });
50
57
  debug('stream finish');
51
58
  const checkAccessPromises: searchUtils.SearchItemPkg[] = await Promise.all(
package/src/v1/token.ts CHANGED
@@ -1,14 +1,15 @@
1
- import _ from 'lodash';
2
- import { HTTP_STATUS, SUPPORT_ERRORS, getInternalError } from '@verdaccio/commons-api';
3
- import { ErrorCode, stringToMD5, mask } from '@verdaccio/utils';
4
- import { getApiToken } from '@verdaccio/auth';
5
- import { logger } from '@verdaccio/logger';
6
1
  import { Response, Router } from 'express';
2
+ import _ from 'lodash';
7
3
 
8
- import { Config, RemoteUser, Token } from '@verdaccio/types';
4
+ import { getApiToken } from '@verdaccio/auth';
9
5
  import { IAuth } from '@verdaccio/auth';
6
+ import { HTTP_STATUS, SUPPORT_ERRORS, errorUtils } from '@verdaccio/core';
7
+ import { logger } from '@verdaccio/logger';
10
8
  import { Storage } from '@verdaccio/store';
11
- import { $RequestExtend, $NextFunctionVer } from '../../types/custom';
9
+ import { Config, RemoteUser, Token } from '@verdaccio/types';
10
+ import { mask, stringToMD5 } from '@verdaccio/utils';
11
+
12
+ import { $NextFunctionVer, $RequestExtend } from '../../types/custom';
12
13
 
13
14
  export type NormalizeToken = Token & {
14
15
  created: string;
@@ -43,10 +44,10 @@ export default function (route: Router, auth: IAuth, storage: Storage, config: C
43
44
  });
44
45
  } catch (error: any) {
45
46
  logger.error({ error: error.msg }, 'token list has failed: @{error}');
46
- return next(ErrorCode.getCode(HTTP_STATUS.INTERNAL_ERROR, error.message));
47
+ return next(errorUtils.getCode(HTTP_STATUS.INTERNAL_ERROR, error.message));
47
48
  }
48
49
  }
49
- return next(ErrorCode.getUnauthorized());
50
+ return next(errorUtils.getUnauthorized());
50
51
  }
51
52
  );
52
53
 
@@ -57,27 +58,27 @@ export default function (route: Router, auth: IAuth, storage: Storage, config: C
57
58
  const { name } = req.remote_user;
58
59
 
59
60
  if (!_.isBoolean(readonly) || !_.isArray(cidr_whitelist)) {
60
- return next(ErrorCode.getCode(HTTP_STATUS.BAD_DATA, SUPPORT_ERRORS.PARAMETERS_NOT_VALID));
61
+ return next(errorUtils.getCode(HTTP_STATUS.BAD_DATA, SUPPORT_ERRORS.PARAMETERS_NOT_VALID));
61
62
  }
62
63
 
63
64
  auth.authenticate(name, password, async (err, user: RemoteUser) => {
64
65
  if (err) {
65
66
  const errorCode = err.message ? HTTP_STATUS.UNAUTHORIZED : HTTP_STATUS.INTERNAL_ERROR;
66
- return next(ErrorCode.getCode(errorCode, err.message));
67
+ return next(errorUtils.getCode(errorCode, err.message));
67
68
  }
68
69
 
69
70
  req.remote_user = user;
70
71
 
71
72
  if (!_.isFunction(storage.saveToken)) {
72
73
  return next(
73
- ErrorCode.getCode(HTTP_STATUS.NOT_IMPLEMENTED, SUPPORT_ERRORS.STORAGE_NOT_IMPLEMENT)
74
+ errorUtils.getCode(HTTP_STATUS.NOT_IMPLEMENTED, SUPPORT_ERRORS.STORAGE_NOT_IMPLEMENT)
74
75
  );
75
76
  }
76
77
 
77
78
  try {
78
79
  const token = await getApiToken(auth, config, user, password);
79
80
  if (!token) {
80
- throw getInternalError();
81
+ throw errorUtils.getInternalError();
81
82
  }
82
83
 
83
84
  const key = stringToMD5(token);
@@ -113,7 +114,7 @@ export default function (route: Router, auth: IAuth, storage: Storage, config: C
113
114
  );
114
115
  } catch (error: any) {
115
116
  logger.error({ error: error.msg }, 'token creation has failed: @{error}');
116
- return next(ErrorCode.getCode(HTTP_STATUS.INTERNAL_ERROR, error.message));
117
+ return next(errorUtils.getInternalError(error.message));
117
118
  }
118
119
  });
119
120
  }
@@ -135,10 +136,10 @@ export default function (route: Router, auth: IAuth, storage: Storage, config: C
135
136
  return next({});
136
137
  } catch (error: any) {
137
138
  logger.error({ error: error.msg }, 'token creation has failed: @{error}');
138
- return next(ErrorCode.getCode(HTTP_STATUS.INTERNAL_ERROR, error.message));
139
+ return next(errorUtils.getCode(HTTP_STATUS.INTERNAL_ERROR, error.message));
139
140
  }
140
141
  }
141
- return next(ErrorCode.getUnauthorized());
142
+ return next(errorUtils.getUnauthorized());
142
143
  }
143
144
  );
144
145
  }
package/src/whoami.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { Response, Router } from 'express';
2
1
  import buildDebug from 'debug';
3
- import { $RequestExtend, $NextFunctionVer } from '../types/custom';
4
- // import { getUnauthorized } from '@verdaccio/commons-api';
2
+ import { Response, Router } from 'express';
3
+
4
+ import { $NextFunctionVer, $RequestExtend } from '../types/custom';
5
5
 
6
6
  const debug = buildDebug('verdaccio:api:user');
7
7
 
@@ -1,13 +1,15 @@
1
- import path from 'path';
1
+ import bodyParser from 'body-parser';
2
2
  import express, { Application } from 'express';
3
+ import path from 'path';
3
4
  import supertest from 'supertest';
4
- import bodyParser from 'body-parser';
5
5
 
6
+ import { Auth, IAuth } from '@verdaccio/auth';
6
7
  import { Config, parseConfigFile } from '@verdaccio/config';
8
+ import { HEADERS, HEADER_TYPE, HTTP_STATUS } from '@verdaccio/core';
9
+ import { generatePackageMetadata } from '@verdaccio/helper';
10
+ import { errorReportingMiddleware, final, handleError } from '@verdaccio/middleware';
7
11
  import { Storage } from '@verdaccio/store';
8
- import { final, handleError, errorReportingMiddleware } from '@verdaccio/middleware';
9
- import { Auth, IAuth } from '@verdaccio/auth';
10
- import { HEADERS, HEADER_TYPE, HTTP_STATUS, generatePackageMetadata } from '@verdaccio/commons-api';
12
+
11
13
  import apiEndpoints from '../../src';
12
14
 
13
15
  const getConf = (conf) => {
@@ -1,7 +1,8 @@
1
1
  import supertest from 'supertest';
2
2
 
3
- import { HEADER_TYPE, HEADERS, HTTP_STATUS } from '@verdaccio/commons-api';
4
- import { $ResponseExtend, $RequestExtend } from '../../types/custom';
3
+ import { HEADERS, HEADER_TYPE, HTTP_STATUS } from '@verdaccio/core';
4
+
5
+ import { $RequestExtend, $ResponseExtend } from '../../types/custom';
5
6
  import { initializeServer, publishTaggedVersion, publishVersion } from './_helper';
6
7
 
7
8
  const mockApiJWTmiddleware = jest.fn(
@@ -1,6 +1,7 @@
1
1
  import supertest from 'supertest';
2
2
 
3
- import { HEADER_TYPE, HEADERS, HTTP_STATUS } from '@verdaccio/commons-api';
3
+ import { HEADERS, HEADER_TYPE, HTTP_STATUS } from '@verdaccio/core';
4
+
4
5
  import { initializeServer } from './_helper';
5
6
 
6
7
  describe('ping', () => {
@@ -1,13 +1,10 @@
1
- import { HTTP_STATUS } from '@verdaccio/commons-api';
2
1
  import supertest from 'supertest';
3
- import {
4
- API_ERROR,
5
- API_MESSAGE,
6
- generatePackageMetadata,
7
- HEADER_TYPE,
8
- HEADERS,
9
- } from '@verdaccio/commons-api';
10
- import { $ResponseExtend, $RequestExtend } from '../../types/custom';
2
+
3
+ import { HTTP_STATUS } from '@verdaccio/core';
4
+ import { API_ERROR, API_MESSAGE, HEADERS, HEADER_TYPE } from '@verdaccio/core';
5
+ import { generatePackageMetadata } from '@verdaccio/helper';
6
+
7
+ import { $RequestExtend, $ResponseExtend } from '../../types/custom';
11
8
  import { initializeServer, publishVersion } from './_helper';
12
9
 
13
10
  const mockApiJWTmiddleware = jest.fn(
@@ -1,16 +1,14 @@
1
- import supertest from 'supertest';
2
1
  import _ from 'lodash';
2
+ import supertest from 'supertest';
3
3
 
4
4
  import {
5
- getBadRequest,
6
- getConflict,
7
- getUnauthorized,
5
+ API_ERROR,
6
+ API_MESSAGE,
8
7
  HEADERS,
9
8
  HEADER_TYPE,
10
- API_MESSAGE,
11
9
  HTTP_STATUS,
12
- API_ERROR,
13
- } from '@verdaccio/commons-api';
10
+ errorUtils,
11
+ } from '@verdaccio/core';
14
12
 
15
13
  import { $RequestExtend, $ResponseExtend } from '../../types/custom';
16
14
  import { initializeServer } from './_helper';
@@ -28,7 +26,7 @@ const mockAuthenticate = jest.fn(() => (_name, _password, callback): void => {
28
26
  });
29
27
 
30
28
  const mockAddUser = jest.fn(() => (_name, _password, callback): void => {
31
- return callback(getConflict(API_ERROR.USERNAME_ALREADY_REGISTERED));
29
+ return callback(errorUtils.getConflict(API_ERROR.USERNAME_ALREADY_REGISTERED));
32
30
  });
33
31
 
34
32
  jest.mock('@verdaccio/auth', () => ({
@@ -143,7 +141,7 @@ describe('user', () => {
143
141
  }
144
142
  );
145
143
  mockAddUser.mockImplementationOnce(() => (_name, _password, callback): void => {
146
- return callback(getBadRequest(API_ERROR.USERNAME_PASSWORD_REQUIRED));
144
+ return callback(errorUtils.getBadRequest(API_ERROR.USERNAME_PASSWORD_REQUIRED));
147
145
  });
148
146
  const credentialsShort = _.cloneDeep(credentials);
149
147
  delete credentialsShort.name;
@@ -208,7 +206,7 @@ describe('user', () => {
208
206
  }
209
207
  );
210
208
  mockAuthenticate.mockImplementationOnce(() => (_name, _password, callback): void => {
211
- return callback(getUnauthorized(API_ERROR.BAD_USERNAME_PASSWORD));
209
+ return callback(errorUtils.getUnauthorized(API_ERROR.BAD_USERNAME_PASSWORD));
212
210
  });
213
211
  const credentialsShort = _.cloneDeep(credentials);
214
212
  credentialsShort.password = 'failPassword';
@@ -240,7 +238,7 @@ describe('user', () => {
240
238
  }
241
239
  );
242
240
  mockAuthenticate.mockImplementationOnce(() => (_name, _password, callback): void => {
243
- return callback(getUnauthorized(API_ERROR.BAD_USERNAME_PASSWORD));
241
+ return callback(errorUtils.getUnauthorized(API_ERROR.BAD_USERNAME_PASSWORD));
244
242
  });
245
243
  const credentialsShort = _.cloneDeep(credentials);
246
244
  credentialsShort.password = 'failPassword';
@@ -1,6 +1,6 @@
1
1
  import supertest from 'supertest';
2
2
 
3
- import { HEADERS, HTTP_STATUS } from '@verdaccio/commons-api';
3
+ import { HEADERS, HTTP_STATUS } from '@verdaccio/core';
4
4
 
5
5
  import { $RequestExtend, $ResponseExtend } from '../../types/custom';
6
6
  import { initializeServer } from './_helper';