diff --git a/.changeset/perfect-candles-clap.md b/.changeset/perfect-candles-clap.md new file mode 100644 index 000000000..dcbe628c7 --- /dev/null +++ b/.changeset/perfect-candles-clap.md @@ -0,0 +1,35 @@ +--- +'@verdaccio/api': minor +'@verdaccio/auth': minor +'@verdaccio/cli': minor +'@verdaccio/config': minor +'@verdaccio/core': minor +'verdaccio-htpasswd': minor +'@verdaccio/local-storage': minor +'@verdaccio/fastify-migration': minor +'@verdaccio/tarball': minor +'@verdaccio/types': minor +'@verdaccio/url': minor +'@verdaccio/hooks': minor +'@verdaccio/loaders': minor +'@verdaccio/logger': minor +'@verdaccio/middleware': minor +'@verdaccio/mock': minor +'@verdaccio/node-api': minor +'@verdaccio/active-directory': minor +'verdaccio-auth-memory': minor +'verdaccio-aws-s3-storage': minor +'verdaccio-google-cloud': minor +'verdaccio-memory': minor +'@verdaccio/ui-theme': minor +'@verdaccio/proxy': minor +'@verdaccio/server': minor +'@verdaccio/cli-standalone': minor +'@verdaccio/store': minor +'@verdaccio/utils': minor +'verdaccio': minor +'@verdaccio/web': minor +'@verdaccio/e2e-ui': minor +--- + +refactor: remove @verdaccio/commons-api in favor @verdaccio/core and remove duplications diff --git a/.changeset/pre.json b/.changeset/pre.json index ed9b413c1..85aedd8dd 100644 --- a/.changeset/pre.json +++ b/.changeset/pre.json @@ -6,7 +6,6 @@ "@verdaccio/auth": "6.0.0-alpha.0", "@verdaccio/cli": "6.0.0-alpha.0", "@verdaccio/config": "6.0.0-alpha.0", - "@verdaccio/commons-api": "11.0.0-alpha.0", "@verdaccio/file-locking": "11.0.0-alpha.0", "verdaccio-htpasswd": "11.0.0-alpha.0", "@verdaccio/local-storage": "11.0.0-alpha.0", diff --git a/.vscode/settings.json b/.vscode/settings.json index 26b80da16..00d3805a1 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,7 +2,7 @@ { "files.exclude": { "**/.nyc_output": true, - "**/build": true, + "**/build": false, "**/coverage": true, ".idea": true, "storage_default_storage": true, diff --git a/docs/migration-v5-to-v6.md b/docs/migration-v5-to-v6.md index 3114e833f..e4f441382 100644 --- a/docs/migration-v5-to-v6.md +++ b/docs/migration-v5-to-v6.md @@ -74,3 +74,7 @@ Introduce environment variables for legacy tokens. - `VERDACCIO_LEGACY_ALGORITHM`: Allows to define the specific algorithm for the token signature which by default is `aes-256-ctr` - `VERDACCIO_LEGACY_ENCRYPTION_KEY`: By default, the token stores in the database, but using this variable allows to get it from memory + +#### @verdaccio/commons-api migration + +The package has been removed in favor of `@verdaccio/core` with a similar API, check API documentation for further details. diff --git a/packages/api/package.json b/packages/api/package.json index db028dc25..06dc30842 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -40,7 +40,6 @@ "license": "MIT", "dependencies": { "@verdaccio/auth": "workspace:6.0.0-6-next.12", - "@verdaccio/commons-api": "workspace:11.0.0-6-next.4", "@verdaccio/config": "workspace:6.0.0-6-next.8", "@verdaccio/core": "workspace:6.0.0-6-next.1", "@verdaccio/hooks": "workspace:6.0.0-6-next.7", @@ -60,6 +59,7 @@ "@types/node": "16.9.1", "@verdaccio/server": "workspace:6.0.0-6-next.20", "@verdaccio/types": "workspace:11.0.0-6-next.8", + "@verdaccio/helper": "1.0.0", "body-parser": "1.19.0", "lodash": "4.17.21", "supertest": "6.1.6" diff --git a/packages/api/src/dist-tags.ts b/packages/api/src/dist-tags.ts index bbc0ec99f..d7fa76440 100644 --- a/packages/api/src/dist-tags.ts +++ b/packages/api/src/dist-tags.ts @@ -3,7 +3,7 @@ import _ from 'lodash'; import { Router } from 'express'; import { media, allow } from '@verdaccio/middleware'; -import { API_MESSAGE, HTTP_STATUS, DIST_TAGS, VerdaccioError } from '@verdaccio/commons-api'; +import { constants, VerdaccioError } from '@verdaccio/core'; import { Package } from '@verdaccio/types'; import { Storage } from '@verdaccio/store'; import { IAuth } from '@verdaccio/auth'; @@ -26,8 +26,8 @@ export default function (route: Router, auth: IAuth, storage: Storage): void { if (err) { return next(err); } - res.status(HTTP_STATUS.CREATED); - return next({ ok: API_MESSAGE.TAG_ADDED }); + res.status(constants.HTTP_STATUS.CREATED); + return next({ ok: constants.API_MESSAGE.TAG_ADDED }); }); }; @@ -58,9 +58,9 @@ export default function (route: Router, auth: IAuth, storage: Storage): void { if (err) { return next(err); } - res.status(HTTP_STATUS.CREATED); + res.status(constants.HTTP_STATUS.CREATED); return next({ - ok: API_MESSAGE.TAG_REMOVED, + ok: constants.API_MESSAGE.TAG_REMOVED, }); }); } @@ -79,7 +79,7 @@ export default function (route: Router, auth: IAuth, storage: Storage): void { return next(err); } - next(info[DIST_TAGS]); + next(info[constants.DIST_TAGS]); }, }); } @@ -96,9 +96,9 @@ export default function (route: Router, auth: IAuth, storage: Storage): void { if (err) { return next(err); } - res.status(HTTP_STATUS.CREATED); + res.status(constants.HTTP_STATUS.CREATED); return next({ - ok: API_MESSAGE.TAG_UPDATED, + ok: constants.API_MESSAGE.TAG_UPDATED, }); } ); diff --git a/packages/api/src/package.ts b/packages/api/src/package.ts index 2e40bd0ce..73d8d8b3a 100644 --- a/packages/api/src/package.ts +++ b/packages/api/src/package.ts @@ -3,8 +3,8 @@ import { Router } from 'express'; import buildDebug from 'debug'; import { allow } from '@verdaccio/middleware'; -import { getVersion, ErrorCode } from '@verdaccio/utils'; -import { HEADERS, DIST_TAGS, API_ERROR } from '@verdaccio/commons-api'; +import { getVersion } from '@verdaccio/utils'; +import { HEADERS, DIST_TAGS, API_ERROR, errorUtils } from '@verdaccio/core'; import { Config, Package } from '@verdaccio/types'; import { IAuth } from '@verdaccio/auth'; import { Storage } from '@verdaccio/store'; @@ -80,7 +80,7 @@ export default function (route: Router, auth: IAuth, storage: Storage, config: C } debug('package version not found %o', queryVersion); - return next(ErrorCode.getNotFound(`${API_ERROR.VERSION_NOT_EXIST}: ${queryVersion}`)); + return next(errorUtils.getNotFound(`${API_ERROR.VERSION_NOT_EXIST}: ${queryVersion}`)); }; debug('get package name %o', name); diff --git a/packages/api/src/publish.ts b/packages/api/src/publish.ts index 103e05422..302257db2 100644 --- a/packages/api/src/publish.ts +++ b/packages/api/src/publish.ts @@ -4,8 +4,15 @@ import mime from 'mime'; import { Router } from 'express'; import buildDebug from 'debug'; -import { API_MESSAGE, HEADERS, DIST_TAGS, API_ERROR, HTTP_STATUS } from '@verdaccio/commons-api'; -import { validateMetadata, isObject, ErrorCode, hasDiffOneKey } from '@verdaccio/utils'; +import { + API_MESSAGE, + HEADERS, + DIST_TAGS, + API_ERROR, + HTTP_STATUS, + errorUtils, +} from '@verdaccio/core'; +import { validateMetadata, isObject, hasDiffOneKey } from '@verdaccio/utils'; import { media, expectJson, allow } from '@verdaccio/middleware'; import { notify } from '@verdaccio/hooks'; import { Config, Callback, MergeTags, Version, Package, CallbackAction } from '@verdaccio/types'; @@ -224,7 +231,7 @@ export function publishPackage(storage: Storage, config: Config, auth: IAuth): a // if this happens in normal circumstances, report it as a bug debug('invalid body format'); logger.info({ packageName }, `wrong package format on publish a package @{packageName}`); - return next(ErrorCode.getBadRequest(API_ERROR.UNSUPORTED_REGISTRY_CALL)); + return next(errorUtils.getBadRequest(API_ERROR.UNSUPORTED_REGISTRY_CALL)); } if (error && error.status !== HTTP_STATUS.CONFLICT) { @@ -322,7 +329,7 @@ export function publishPackage(storage: Storage, config: Config, auth: IAuth): a } catch (error: any) { debug('error on publish, bad package format %o', packageName); logger.error({ packageName }, 'error on publish, bad package data for @{packageName}'); - return next(ErrorCode.getBadData(API_ERROR.BAD_PACKAGE_DATA)); + return next(errorUtils.getBadData(API_ERROR.BAD_PACKAGE_DATA)); } }; } diff --git a/packages/api/src/search.ts b/packages/api/src/search.ts index 472f05c95..3a119cce4 100644 --- a/packages/api/src/search.ts +++ b/packages/api/src/search.ts @@ -1,4 +1,4 @@ -import { HTTP_STATUS } from '@verdaccio/commons-api'; +import { HTTP_STATUS } from '@verdaccio/core'; import { logger } from '@verdaccio/logger'; export default function (route): void { diff --git a/packages/api/src/star.ts b/packages/api/src/star.ts index 38d899fba..336faa560 100644 --- a/packages/api/src/star.ts +++ b/packages/api/src/star.ts @@ -1,4 +1,4 @@ -import { USERS, HTTP_STATUS } from '@verdaccio/commons-api'; +import { USERS, HTTP_STATUS } from '@verdaccio/core'; import { Response } from 'express'; import _ from 'lodash'; import buildDebug from 'debug'; diff --git a/packages/api/src/stars.ts b/packages/api/src/stars.ts index d65abcccd..2a72cd4ce 100644 --- a/packages/api/src/stars.ts +++ b/packages/api/src/stars.ts @@ -1,7 +1,7 @@ import _ from 'lodash'; import { Response, Router } from 'express'; -import { USERS, HTTP_STATUS } from '@verdaccio/commons-api'; +import { USERS, HTTP_STATUS } from '@verdaccio/core'; import { Package } from '@verdaccio/types'; import { Storage } from '@verdaccio/store'; diff --git a/packages/api/src/user.ts b/packages/api/src/user.ts index 58272528e..b8d9e8ece 100644 --- a/packages/api/src/user.ts +++ b/packages/api/src/user.ts @@ -2,14 +2,14 @@ import _ from 'lodash'; import { Response, Router } from 'express'; import buildDebug from 'debug'; -import { getAuthenticatedMessage, validatePassword, ErrorCode } from '@verdaccio/utils'; +import { getAuthenticatedMessage, validatePassword } from '@verdaccio/utils'; import { getApiToken } from '@verdaccio/auth'; import { logger } from '@verdaccio/logger'; import { createRemoteUser } from '@verdaccio/config'; import { Config, RemoteUser } from '@verdaccio/types'; import { IAuth } from '@verdaccio/auth'; -import { API_ERROR, API_MESSAGE, HTTP_STATUS } from '@verdaccio/commons-api'; +import { API_ERROR, API_MESSAGE, HTTP_STATUS, errorUtils } from '@verdaccio/core'; import { $RequestExtend, $NextFunctionVer } from '../types/custom'; const debug = buildDebug('verdaccio:api:user'); @@ -47,7 +47,7 @@ export default function (route: Router, auth: IAuth, config: Config): void { 'authenticating for user @{username} failed. Error: @{err.message}' ); return next( - ErrorCode.getCode(HTTP_STATUS.UNAUTHORIZED, API_ERROR.BAD_USERNAME_PASSWORD) + errorUtils.getCode(HTTP_STATUS.UNAUTHORIZED, API_ERROR.BAD_USERNAME_PASSWORD) ); } @@ -55,7 +55,7 @@ export default function (route: Router, auth: IAuth, config: Config): void { const token = await getApiToken(auth, config, restoredRemoteUser, password); debug('login: new token'); if (!token) { - return next(ErrorCode.getUnauthorized()); + return next(errorUtils.getUnauthorized()); } res.status(HTTP_STATUS.CREATED); @@ -73,7 +73,7 @@ export default function (route: Router, auth: IAuth, config: Config): void { if (validatePassword(password) === false) { debug('adduser: invalid password'); // eslint-disable-next-line new-cap - return next(ErrorCode.getCode(HTTP_STATUS.BAD_REQUEST, API_ERROR.PASSWORD_SHORT())); + return next(errorUtils.getCode(HTTP_STATUS.BAD_REQUEST, API_ERROR.PASSWORD_SHORT())); } auth.add_user(name, password, async function (err, user): Promise { @@ -84,7 +84,7 @@ export default function (route: Router, auth: IAuth, config: Config): void { // and npm accepts only an 409 error. // So, changing status code here. return next( - ErrorCode.getCode(err.status, err.message) || ErrorCode.getConflict(err.message) + errorUtils.getCode(err.status, err.message) || errorUtils.getConflict(err.message) ); } return next(err); @@ -94,7 +94,7 @@ export default function (route: Router, auth: IAuth, config: Config): void { name && password ? await getApiToken(auth, config, user, password) : undefined; debug('adduser: new token %o', token); if (!token) { - return next(ErrorCode.getUnauthorized()); + return next(errorUtils.getUnauthorized()); } req.remote_user = user; diff --git a/packages/api/src/v1/profile.ts b/packages/api/src/v1/profile.ts index b55e81878..dd8e8a7bc 100644 --- a/packages/api/src/v1/profile.ts +++ b/packages/api/src/v1/profile.ts @@ -1,8 +1,8 @@ import _ from 'lodash'; import { Response, Router } from 'express'; -import { API_ERROR, APP_ERROR, HTTP_STATUS, SUPPORT_ERRORS } from '@verdaccio/commons-api'; -import { ErrorCode, validatePassword } from '@verdaccio/utils'; +import { API_ERROR, APP_ERROR, HTTP_STATUS, SUPPORT_ERRORS, errorUtils } from '@verdaccio/core'; +import { validatePassword } from '@verdaccio/utils'; import { IAuth } from '@verdaccio/auth'; import { $RequestExtend, $NextFunctionVer } from '../../types/custom'; @@ -61,7 +61,7 @@ export default function (route: Router, auth: IAuth): void { if (_.isNil(password) === false) { if (validatePassword(password.new) === false) { /* eslint new-cap:off */ - return next(ErrorCode.getCode(HTTP_STATUS.UNAUTHORIZED, API_ERROR.PASSWORD_SHORT())); + return next(errorUtils.getCode(HTTP_STATUS.UNAUTHORIZED, API_ERROR.PASSWORD_SHORT())); /* eslint new-cap:off */ } @@ -72,22 +72,22 @@ export default function (route: Router, auth: IAuth): void { (err, isUpdated): $NextFunctionVer => { if (_.isNull(err) === false) { return next( - ErrorCode.getCode(err.status, err.message) || ErrorCode.getConflict(err.message) + errorUtils.getCode(err.status, err.message) || errorUtils.getConflict(err.message) ); } if (isUpdated) { return next(buildProfile(req.remote_user.name)); } - return next(ErrorCode.getInternalError(API_ERROR.INTERNAL_SERVER_ERROR)); + return next(errorUtils.getInternalError(API_ERROR.INTERNAL_SERVER_ERROR)); } ); } else if (_.isNil(tfa) === false) { return next( - ErrorCode.getCode(HTTP_STATUS.SERVICE_UNAVAILABLE, SUPPORT_ERRORS.TFA_DISABLED) + errorUtils.getCode(HTTP_STATUS.SERVICE_UNAVAILABLE, SUPPORT_ERRORS.TFA_DISABLED) ); } else { - return next(ErrorCode.getCode(HTTP_STATUS.INTERNAL_ERROR, APP_ERROR.PROFILE_ERROR)); + return next(errorUtils.getCode(HTTP_STATUS.INTERNAL_ERROR, APP_ERROR.PROFILE_ERROR)); } } ); diff --git a/packages/api/src/v1/search.ts b/packages/api/src/v1/search.ts index 82594623b..524e011cf 100644 --- a/packages/api/src/v1/search.ts +++ b/packages/api/src/v1/search.ts @@ -2,8 +2,7 @@ import _ from 'lodash'; import buildDebug from 'debug'; import { logger } from '@verdaccio/logger'; import { IAuth } from '@verdaccio/auth'; -import { searchUtils } from '@verdaccio/core'; -import { HTTP_STATUS } from '@verdaccio/commons-api'; +import { HTTP_STATUS, searchUtils } from '@verdaccio/core'; import { Storage } from '@verdaccio/store'; import { Package } from '@verdaccio/types'; diff --git a/packages/api/src/v1/token.ts b/packages/api/src/v1/token.ts index 53540ed98..3700eeab7 100644 --- a/packages/api/src/v1/token.ts +++ b/packages/api/src/v1/token.ts @@ -1,6 +1,6 @@ import _ from 'lodash'; -import { HTTP_STATUS, SUPPORT_ERRORS, getInternalError } from '@verdaccio/commons-api'; -import { ErrorCode, stringToMD5, mask } from '@verdaccio/utils'; +import { errorUtils, HTTP_STATUS, SUPPORT_ERRORS } from '@verdaccio/core'; +import { stringToMD5, mask } from '@verdaccio/utils'; import { getApiToken } from '@verdaccio/auth'; import { logger } from '@verdaccio/logger'; import { Response, Router } from 'express'; @@ -43,10 +43,10 @@ export default function (route: Router, auth: IAuth, storage: Storage, config: C }); } catch (error: any) { logger.error({ error: error.msg }, 'token list has failed: @{error}'); - return next(ErrorCode.getCode(HTTP_STATUS.INTERNAL_ERROR, error.message)); + return next(errorUtils.getCode(HTTP_STATUS.INTERNAL_ERROR, error.message)); } } - return next(ErrorCode.getUnauthorized()); + return next(errorUtils.getUnauthorized()); } ); @@ -57,27 +57,27 @@ export default function (route: Router, auth: IAuth, storage: Storage, config: C const { name } = req.remote_user; if (!_.isBoolean(readonly) || !_.isArray(cidr_whitelist)) { - return next(ErrorCode.getCode(HTTP_STATUS.BAD_DATA, SUPPORT_ERRORS.PARAMETERS_NOT_VALID)); + return next(errorUtils.getCode(HTTP_STATUS.BAD_DATA, SUPPORT_ERRORS.PARAMETERS_NOT_VALID)); } auth.authenticate(name, password, async (err, user: RemoteUser) => { if (err) { const errorCode = err.message ? HTTP_STATUS.UNAUTHORIZED : HTTP_STATUS.INTERNAL_ERROR; - return next(ErrorCode.getCode(errorCode, err.message)); + return next(errorUtils.getCode(errorCode, err.message)); } req.remote_user = user; if (!_.isFunction(storage.saveToken)) { return next( - ErrorCode.getCode(HTTP_STATUS.NOT_IMPLEMENTED, SUPPORT_ERRORS.STORAGE_NOT_IMPLEMENT) + errorUtils.getCode(HTTP_STATUS.NOT_IMPLEMENTED, SUPPORT_ERRORS.STORAGE_NOT_IMPLEMENT) ); } try { const token = await getApiToken(auth, config, user, password); if (!token) { - throw getInternalError(); + throw errorUtils.getInternalError(); } const key = stringToMD5(token); @@ -113,7 +113,7 @@ export default function (route: Router, auth: IAuth, storage: Storage, config: C ); } catch (error: any) { logger.error({ error: error.msg }, 'token creation has failed: @{error}'); - return next(ErrorCode.getCode(HTTP_STATUS.INTERNAL_ERROR, error.message)); + return next(errorUtils.getInternalError(error.message)); } }); } @@ -135,10 +135,10 @@ export default function (route: Router, auth: IAuth, storage: Storage, config: C return next({}); } catch (error: any) { logger.error({ error: error.msg }, 'token creation has failed: @{error}'); - return next(ErrorCode.getCode(HTTP_STATUS.INTERNAL_ERROR, error.message)); + return next(errorUtils.getCode(HTTP_STATUS.INTERNAL_ERROR, error.message)); } } - return next(ErrorCode.getUnauthorized()); + return next(errorUtils.getUnauthorized()); } ); } diff --git a/packages/api/src/whoami.ts b/packages/api/src/whoami.ts index beb740c30..1731a80b9 100644 --- a/packages/api/src/whoami.ts +++ b/packages/api/src/whoami.ts @@ -1,7 +1,6 @@ import { Response, Router } from 'express'; import buildDebug from 'debug'; import { $RequestExtend, $NextFunctionVer } from '../types/custom'; -// import { getUnauthorized } from '@verdaccio/commons-api'; const debug = buildDebug('verdaccio:api:user'); diff --git a/packages/api/test/integration/_helper.ts b/packages/api/test/integration/_helper.ts index 18bc0c1db..08907f06a 100644 --- a/packages/api/test/integration/_helper.ts +++ b/packages/api/test/integration/_helper.ts @@ -5,9 +5,10 @@ import bodyParser from 'body-parser'; import { Config, parseConfigFile } from '@verdaccio/config'; import { Storage } from '@verdaccio/store'; +import { generatePackageMetadata } from '@verdaccio/helper'; import { final, handleError, errorReportingMiddleware } from '@verdaccio/middleware'; import { Auth, IAuth } from '@verdaccio/auth'; -import { HEADERS, HEADER_TYPE, HTTP_STATUS, generatePackageMetadata } from '@verdaccio/commons-api'; +import { HEADERS, HEADER_TYPE, HTTP_STATUS } from '@verdaccio/core'; import apiEndpoints from '../../src'; const getConf = (conf) => { diff --git a/packages/api/test/integration/package.spec.ts b/packages/api/test/integration/package.spec.ts index cde57d9d0..2b9a96579 100644 --- a/packages/api/test/integration/package.spec.ts +++ b/packages/api/test/integration/package.spec.ts @@ -1,6 +1,6 @@ import supertest from 'supertest'; -import { HEADER_TYPE, HEADERS, HTTP_STATUS } from '@verdaccio/commons-api'; +import { HEADER_TYPE, HEADERS, HTTP_STATUS } from '@verdaccio/core'; import { $ResponseExtend, $RequestExtend } from '../../types/custom'; import { initializeServer, publishTaggedVersion, publishVersion } from './_helper'; diff --git a/packages/api/test/integration/ping.spec.ts b/packages/api/test/integration/ping.spec.ts index 5dc090c7d..9c843d19e 100644 --- a/packages/api/test/integration/ping.spec.ts +++ b/packages/api/test/integration/ping.spec.ts @@ -1,6 +1,6 @@ import supertest from 'supertest'; -import { HEADER_TYPE, HEADERS, HTTP_STATUS } from '@verdaccio/commons-api'; +import { HEADER_TYPE, HEADERS, HTTP_STATUS } from '@verdaccio/core'; import { initializeServer } from './_helper'; describe('ping', () => { diff --git a/packages/api/test/integration/publish.spec.ts b/packages/api/test/integration/publish.spec.ts index 2619f49c7..362a55b37 100644 --- a/packages/api/test/integration/publish.spec.ts +++ b/packages/api/test/integration/publish.spec.ts @@ -1,12 +1,7 @@ -import { HTTP_STATUS } from '@verdaccio/commons-api'; +import { HTTP_STATUS } from '@verdaccio/core'; import supertest from 'supertest'; -import { - API_ERROR, - API_MESSAGE, - generatePackageMetadata, - HEADER_TYPE, - HEADERS, -} from '@verdaccio/commons-api'; +import { API_ERROR, API_MESSAGE, HEADER_TYPE, HEADERS } from '@verdaccio/core'; +import { generatePackageMetadata } from '@verdaccio/helper'; import { $ResponseExtend, $RequestExtend } from '../../types/custom'; import { initializeServer, publishVersion } from './_helper'; diff --git a/packages/api/test/integration/user.spec.ts b/packages/api/test/integration/user.spec.ts index b396050c1..ab53c734a 100644 --- a/packages/api/test/integration/user.spec.ts +++ b/packages/api/test/integration/user.spec.ts @@ -2,15 +2,13 @@ import supertest from 'supertest'; import _ from 'lodash'; import { - getBadRequest, - getConflict, - getUnauthorized, + errorUtils, HEADERS, HEADER_TYPE, API_MESSAGE, HTTP_STATUS, API_ERROR, -} from '@verdaccio/commons-api'; +} from '@verdaccio/core'; import { $RequestExtend, $ResponseExtend } from '../../types/custom'; import { initializeServer } from './_helper'; @@ -28,7 +26,7 @@ const mockAuthenticate = jest.fn(() => (_name, _password, callback): void => { }); const mockAddUser = jest.fn(() => (_name, _password, callback): void => { - return callback(getConflict(API_ERROR.USERNAME_ALREADY_REGISTERED)); + return callback(errorUtils.getConflict(API_ERROR.USERNAME_ALREADY_REGISTERED)); }); jest.mock('@verdaccio/auth', () => ({ @@ -143,7 +141,7 @@ describe('user', () => { } ); mockAddUser.mockImplementationOnce(() => (_name, _password, callback): void => { - return callback(getBadRequest(API_ERROR.USERNAME_PASSWORD_REQUIRED)); + return callback(errorUtils.getBadRequest(API_ERROR.USERNAME_PASSWORD_REQUIRED)); }); const credentialsShort = _.cloneDeep(credentials); delete credentialsShort.name; @@ -208,7 +206,7 @@ describe('user', () => { } ); mockAuthenticate.mockImplementationOnce(() => (_name, _password, callback): void => { - return callback(getUnauthorized(API_ERROR.BAD_USERNAME_PASSWORD)); + return callback(errorUtils.getUnauthorized(API_ERROR.BAD_USERNAME_PASSWORD)); }); const credentialsShort = _.cloneDeep(credentials); credentialsShort.password = 'failPassword'; @@ -240,7 +238,7 @@ describe('user', () => { } ); mockAuthenticate.mockImplementationOnce(() => (_name, _password, callback): void => { - return callback(getUnauthorized(API_ERROR.BAD_USERNAME_PASSWORD)); + return callback(errorUtils.getUnauthorized(API_ERROR.BAD_USERNAME_PASSWORD)); }); const credentialsShort = _.cloneDeep(credentials); credentialsShort.password = 'failPassword'; diff --git a/packages/api/test/integration/whoami.spec.ts b/packages/api/test/integration/whoami.spec.ts index 78dd47b95..6a8065edf 100644 --- a/packages/api/test/integration/whoami.spec.ts +++ b/packages/api/test/integration/whoami.spec.ts @@ -1,6 +1,6 @@ import supertest from 'supertest'; -import { HEADERS, HTTP_STATUS } from '@verdaccio/commons-api'; +import { HEADERS, HTTP_STATUS } from '@verdaccio/core'; import { $RequestExtend, $ResponseExtend } from '../../types/custom'; import { initializeServer } from './_helper'; diff --git a/packages/api/test/unit/publish.spec.ts b/packages/api/test/unit/publish.spec.ts index b912718e7..0c72ec9ba 100644 --- a/packages/api/test/unit/publish.spec.ts +++ b/packages/api/test/unit/publish.spec.ts @@ -1,5 +1,4 @@ -import { HTTP_STATUS, API_ERROR } from '@verdaccio/commons-api'; -import { ErrorCode } from '@verdaccio/utils'; +import { errorUtils, HTTP_STATUS, API_ERROR } from '@verdaccio/core'; import { addVersion, uploadPackageTarball, @@ -202,13 +201,13 @@ describe('Publish endpoints - un-publish package', () => { const storage = { removePackage(packageName) { expect(packageName).toEqual(req.params.package); - return Promise.reject(ErrorCode.getInternalError()); + return Promise.reject(errorUtils.getInternalError()); }, }; // @ts-ignore await unPublishPackage(storage)(req, res, next); - expect(next).toHaveBeenCalledWith(ErrorCode.getInternalError()); + expect(next).toHaveBeenCalledWith(errorUtils.getInternalError()); }); }); diff --git a/packages/api/tsconfig.json b/packages/api/tsconfig.json index a658ddadd..058556094 100644 --- a/packages/api/tsconfig.json +++ b/packages/api/tsconfig.json @@ -13,9 +13,6 @@ { "path": "../config" }, - { - "path": "../core/commons-api" - }, { "path": "../core/core" }, diff --git a/packages/auth/package.json b/packages/auth/package.json index b943ed3ab..7e58fa9b8 100644 --- a/packages/auth/package.json +++ b/packages/auth/package.json @@ -39,7 +39,7 @@ }, "license": "MIT", "dependencies": { - "@verdaccio/commons-api": "workspace:11.0.0-6-next.4", + "@verdaccio/core": "workspace:6.0.0-6-next.1", "@verdaccio/config": "workspace:6.0.0-6-next.8", "@verdaccio/loaders": "workspace:6.0.0-6-next.5", "@verdaccio/logger": "workspace:6.0.0-6-next.5", diff --git a/packages/auth/src/auth.ts b/packages/auth/src/auth.ts index 0086c7ce2..29eef4381 100644 --- a/packages/auth/src/auth.ts +++ b/packages/auth/src/auth.ts @@ -8,10 +8,8 @@ import { TOKEN_BASIC, TOKEN_BEARER, VerdaccioError, - getBadRequest, - getInternalError, - getForbidden, -} from '@verdaccio/commons-api'; + errorUtils, +} from '@verdaccio/core'; import { loadPlugin } from '@verdaccio/loaders'; import { HTPasswd, HTPasswdConfig } from 'verdaccio-htpasswd'; @@ -153,7 +151,7 @@ class Auth implements IAuth { const validPlugins = _.filter(this.plugins, (plugin) => isFunction(plugin.changePassword)); if (_.isEmpty(validPlugins)) { - return cb(getInternalError(SUPPORT_ERRORS.PLUGIN_MISSING_INTERFACE)); + return cb(errorUtils.getInternalError(SUPPORT_ERRORS.PLUGIN_MISSING_INTERFACE)); } for (const plugin of validPlugins) { @@ -425,7 +423,7 @@ class Auth implements IAuth { if (!isAuthHeaderValid(authorization)) { debug('api middleware authentication heather is invalid'); - return next(getBadRequest(API_ERROR.BAD_AUTH_HEADER)); + return next(errorUtils.getBadRequest(API_ERROR.BAD_AUTH_HEADER)); } const { secret, security } = this.config; @@ -476,7 +474,7 @@ class Auth implements IAuth { } else { // with JWT throw 401 debug('jwt invalid token'); - next(getForbidden(API_ERROR.BAD_USERNAME_PASSWORD)); + next(errorUtils.getForbidden(API_ERROR.BAD_USERNAME_PASSWORD)); } } } @@ -510,7 +508,7 @@ class Auth implements IAuth { } else { // we force npm client to ask again with basic authentication debug('legacy invalid header'); - return next(getBadRequest(API_ERROR.BAD_AUTH_HEADER)); + return next(errorUtils.getBadRequest(API_ERROR.BAD_AUTH_HEADER)); } } @@ -544,7 +542,7 @@ class Auth implements IAuth { } if (!isAuthHeaderValid(authorization)) { - return next(getBadRequest(API_ERROR.BAD_AUTH_HEADER)); + return next(errorUtils.getBadRequest(API_ERROR.BAD_AUTH_HEADER)); } const token = (authorization || '').replace(`${TOKEN_BEARER} `, ''); diff --git a/packages/auth/src/utils.ts b/packages/auth/src/utils.ts index 2491585c1..80c0c2d8a 100644 --- a/packages/auth/src/utils.ts +++ b/packages/auth/src/utils.ts @@ -13,12 +13,9 @@ import { TOKEN_BASIC, TOKEN_BEARER, API_ERROR, - getForbidden, - getUnauthorized, - getConflict, - getCode, -} from '@verdaccio/commons-api'; -import { VerdaccioError } from '@verdaccio/commons-api'; + VerdaccioError, + errorUtils, +} from '@verdaccio/core'; import { createAnonymousRemoteUser } from '@verdaccio/config'; import { TokenEncryption, AESPayload } from './auth'; @@ -155,7 +152,7 @@ export function verifyJWTPayload(token: string, secret: string): RemoteUser { // we return an anonymous user to force log in. return createAnonymousRemoteUser(); } - throw getCode(HTTP_STATUS.UNAUTHORIZED, error.message); + throw errorUtils.getCode(HTTP_STATUS.UNAUTHORIZED, error.message); } } @@ -166,11 +163,11 @@ export function isAuthHeaderValid(authorization: string): boolean { export function getDefaultPlugins(logger: any): IPluginAuth { return { authenticate(user: string, password: string, cb: Callback): void { - cb(getForbidden(API_ERROR.BAD_USERNAME_PASSWORD)); + cb(errorUtils.getForbidden(API_ERROR.BAD_USERNAME_PASSWORD)); }, adduser(user: string, password: string, cb: Callback): void { - return cb(getConflict(API_ERROR.BAD_USERNAME_PASSWORD)); + return cb(errorUtils.getConflict(API_ERROR.BAD_USERNAME_PASSWORD)); }, // FIXME: allow_action and allow_publish should be in the @verdaccio/types @@ -205,9 +202,13 @@ export function allow_action(action: ActionsAllowed, logger): AllowAction { } if (name) { - callback(getForbidden(`user ${name} is not allowed to ${action} package ${pkg.name}`)); + callback( + errorUtils.getForbidden(`user ${name} is not allowed to ${action} package ${pkg.name}`) + ); } else { - callback(getUnauthorized(`authorization required to ${action} package ${pkg.name}`)); + callback( + errorUtils.getUnauthorized(`authorization required to ${action} package ${pkg.name}`) + ); } }; } diff --git a/packages/auth/test/auth-utils.spec.ts b/packages/auth/test/auth-utils.spec.ts index 248e2af8f..7d48c7323 100644 --- a/packages/auth/test/auth-utils.spec.ts +++ b/packages/auth/test/auth-utils.spec.ts @@ -1,8 +1,6 @@ import path from 'path'; import _ from 'lodash'; -import { CHARACTER_ENCODING, TOKEN_BEARER, API_ERROR } from '@verdaccio/commons-api'; - import { configExample } from '@verdaccio/mock'; import { Config as AppConfig, @@ -20,7 +18,13 @@ import { } from '@verdaccio/utils'; import { Config, Security, RemoteUser } from '@verdaccio/types'; -import { VerdaccioError, getForbidden } from '@verdaccio/commons-api'; +import { + VerdaccioError, + CHARACTER_ENCODING, + TOKEN_BEARER, + API_ERROR, + errorUtils, +} from '@verdaccio/core'; import { setup } from '@verdaccio/logger'; import { IAuth, @@ -110,7 +114,7 @@ describe('Auth utilities', () => { test('authentication should fail by default (default)', () => { const plugin = getDefaultPlugins({ trace: jest.fn() }); plugin.authenticate('foo', 'bar', (error: any) => { - expect(error).toEqual(getForbidden(API_ERROR.BAD_USERNAME_PASSWORD)); + expect(error).toEqual(errorUtils.getForbidden(API_ERROR.BAD_USERNAME_PASSWORD)); }); }); @@ -118,7 +122,7 @@ describe('Auth utilities', () => { const plugin = getDefaultPlugins({ trace: jest.fn() }); // @ts-ignore plugin.adduser('foo', 'bar', (error: any) => { - expect(error).toEqual(getForbidden(API_ERROR.BAD_USERNAME_PASSWORD)); + expect(error).toEqual(errorUtils.getForbidden(API_ERROR.BAD_USERNAME_PASSWORD)); }); }); }); diff --git a/packages/auth/test/auth.spec.ts b/packages/auth/test/auth.spec.ts index f8cbde577..7d0574a72 100644 --- a/packages/auth/test/auth.spec.ts +++ b/packages/auth/test/auth.spec.ts @@ -3,7 +3,7 @@ import { ROLES, Config as AppConfig } from '@verdaccio/config'; import { setup } from '@verdaccio/logger'; import { IAuth } from '@verdaccio/auth'; import { Config } from '@verdaccio/types'; -import { getInternalError } from '@verdaccio/commons-api'; +import { errorUtils } from '@verdaccio/core'; import { Auth } from '../src'; @@ -57,7 +57,7 @@ describe('AuthTest', () => { auth.authenticate('foo', 'bar', callback); expect(callback).toHaveBeenCalledTimes(1); - expect(callback).toHaveBeenCalledWith(getInternalError()); + expect(callback).toHaveBeenCalledWith(errorUtils.getInternalError()); }); }); diff --git a/packages/auth/tsconfig.json b/packages/auth/tsconfig.json index 1e0299d3a..bdb027917 100644 --- a/packages/auth/tsconfig.json +++ b/packages/auth/tsconfig.json @@ -10,9 +10,6 @@ { "path": "../config" }, - { - "path": "../core/commons-api" - }, { "path": "../core/htpasswd" }, diff --git a/packages/config/package.json b/packages/config/package.json index 1761f1c67..f21c4255d 100644 --- a/packages/config/package.json +++ b/packages/config/package.json @@ -39,7 +39,7 @@ "build": "pnpm run build:js && pnpm run build:types" }, "dependencies": { - "@verdaccio/commons-api": "workspace:11.0.0-6-next.4", + "@verdaccio/core": "workspace:6.0.0-6-next.1", "@verdaccio/utils": "workspace:6.0.0-6-next.6", "debug": "4.3.2", "js-yaml": "3.14.1", diff --git a/packages/config/src/config-path.ts b/packages/config/src/config-path.ts index d084f77ed..1845f4a38 100644 --- a/packages/config/src/config-path.ts +++ b/packages/config/src/config-path.ts @@ -3,7 +3,7 @@ import path from 'path'; import _ from 'lodash'; import buildDebug from 'debug'; -import { CHARACTER_ENCODING } from '@verdaccio/commons-api'; +import { CHARACTER_ENCODING } from '@verdaccio/core'; import { folderExists, fileExists } from './config-utils'; const CONFIG_FILE = 'config.yaml'; diff --git a/packages/config/src/config.ts b/packages/config/src/config.ts index e7dfff0aa..55f855643 100644 --- a/packages/config/src/config.ts +++ b/packages/config/src/config.ts @@ -3,7 +3,7 @@ import _ from 'lodash'; import buildDebug from 'debug'; import { getMatchedPackagesSpec, generateRandomHexString, isObject } from '@verdaccio/utils'; -import { APP_ERROR } from '@verdaccio/commons-api'; +import { APP_ERROR } from '@verdaccio/core'; import { PackageList, Config as AppConfig, diff --git a/packages/config/src/package-access.ts b/packages/config/src/package-access.ts index 7c33fc99f..13cf52d98 100644 --- a/packages/config/src/package-access.ts +++ b/packages/config/src/package-access.ts @@ -1,7 +1,7 @@ import assert from 'assert'; import _ from 'lodash'; import { PackageAccess } from '@verdaccio/types'; -import { ErrorCode } from '@verdaccio/utils'; +import { errorUtils } from '@verdaccio/core'; export interface LegacyPackageList { [key: string]: PackageAccess; } @@ -35,7 +35,7 @@ export function normalizeUserList(groupsList: any): any { } else if (Array.isArray(groupsList)) { result.push(groupsList); } else { - throw ErrorCode.getInternalError( + throw errorUtils.getInternalError( 'CONFIG: bad package acl (array or string expected): ' + JSON.stringify(groupsList) ); } diff --git a/packages/config/src/parse.ts b/packages/config/src/parse.ts index 3523bf7b2..b98569062 100644 --- a/packages/config/src/parse.ts +++ b/packages/config/src/parse.ts @@ -1,6 +1,6 @@ import fs from 'fs'; import YAML from 'js-yaml'; -import { APP_ERROR } from '@verdaccio/commons-api'; +import { APP_ERROR } from '@verdaccio/core'; import { ConfigRuntime, ConfigYaml } from '@verdaccio/types'; /** diff --git a/packages/config/tsconfig.json b/packages/config/tsconfig.json index 132aef0cc..ce4e6177f 100644 --- a/packages/config/tsconfig.json +++ b/packages/config/tsconfig.json @@ -7,9 +7,6 @@ "include": ["src/**/*.ts"], "exclude": ["src/**/*.test.ts"], "references": [ - { - "path": "../core/commons-api" - }, { "path": "../utils" } diff --git a/packages/core/commons-api/README.md b/packages/core/commons-api/README.md deleted file mode 100644 index 027b119f2..000000000 --- a/packages/core/commons-api/README.md +++ /dev/null @@ -1,15 +0,0 @@ -# @verdaccio/commons-api - -commons api utilities for verdaccio - -[![verdaccio (latest)](https://img.shields.io/npm/v/@verdaccio/commons-api/latest.svg)](https://www.npmjs.com/package/@verdaccio/commons-api) -[![docker pulls](https://img.shields.io/docker/pulls/verdaccio/verdaccio.svg?maxAge=43200)](https://verdaccio.org/docs/en/docker.html) -[![backers](https://opencollective.com/verdaccio/tiers/backer/badge.svg?label=Backer&color=brightgreen)](https://opencollective.com/verdaccio) -[![stackshare](https://img.shields.io/badge/Follow%20on-StackShare-blue.svg?logo=stackshare&style=flat)](https://stackshare.io/verdaccio) -[![discord](https://img.shields.io/discord/388674437219745793.svg)](http://chat.verdaccio.org/) -[![node](https://img.shields.io/node/v/@verdaccio/commons-api/latest.svg)](https://www.npmjs.com/package/@verdaccio/commons-api) -![MIT](https://img.shields.io/github/license/mashape/apistatus.svg) -[![Crowdin](https://d322cqt584bo4o.cloudfront.net/verdaccio/localized.svg)](https://crowdin.com/project/verdaccio) - -[![Twitter followers](https://img.shields.io/twitter/follow/verdaccio_npm.svg?style=social&label=Follow)](https://twitter.com/verdaccio_npm) -[![Github](https://img.shields.io/github/stars/verdaccio/verdaccio.svg?style=social&label=Stars)](https://github.com/verdaccio/verdaccio/stargazers) diff --git a/packages/core/commons-api/jest.config.js b/packages/core/commons-api/jest.config.js deleted file mode 100644 index 1c3fbdb05..000000000 --- a/packages/core/commons-api/jest.config.js +++ /dev/null @@ -1,3 +0,0 @@ -const config = require('../../../jest/config'); - -module.exports = Object.assign({}, config, {}); diff --git a/packages/core/commons-api/package.json b/packages/core/commons-api/package.json deleted file mode 100644 index 8af0138f5..000000000 --- a/packages/core/commons-api/package.json +++ /dev/null @@ -1,55 +0,0 @@ -{ - "name": "@verdaccio/commons-api", - "version": "11.0.0-6-next.4", - "description": "Commons API utilities for Verdaccio", - "keywords": [ - "private", - "package", - "repository", - "registry", - "enterprise", - "modules", - "proxy", - "server", - "verdaccio" - ], - "author": "Juan Picado ", - "license": "MIT", - "homepage": "https://verdaccio.org", - "repository": { - "type": "https", - "url": "https://github.com/verdaccio/verdaccio", - "directory": "packages/core/commons-api" - }, - "bugs": { - "url": "https://github.com/verdaccio/verdaccio/issues" - }, - "publishConfig": { - "access": "public" - }, - "main": "build/index.js", - "types": "build/index.d.ts", - "files": [ - "build" - ], - "engines": { - "node": ">=10", - "npm": ">=6" - }, - "dependencies": { - "http-errors": "1.8.0", - "http-status-codes": "2.1.4" - }, - "scripts": { - "clean": "rimraf ./build", - "test": "cross-env NODE_ENV=test BABEL_ENV=test jest", - "build:types": "tsc --emitDeclarationOnly -p tsconfig.build.json", - "build:js": "babel src/ --out-dir build/ --copy-files --extensions \".ts,.tsx\" --source-maps", - "watch": "pnpm build:js -- --watch", - "build": "pnpm run build:js && pnpm run build:types" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/verdaccio" - } -} diff --git a/packages/core/commons-api/src/index.ts b/packages/core/commons-api/src/index.ts deleted file mode 100644 index cb7ef2996..000000000 --- a/packages/core/commons-api/src/index.ts +++ /dev/null @@ -1,200 +0,0 @@ -import createError, { HttpError } from 'http-errors'; -import httpCodes from 'http-status-codes'; - -export const DEFAULT_MIN_LIMIT_PASSWORD = 3; - -export const HEADER_TYPE = { - CONTENT_ENCODING: 'content-encoding', - CONTENT_TYPE: 'content-type', - CONTENT_LENGTH: 'content-length', - ACCEPT_ENCODING: 'accept-encoding', -}; - -export const HTTP_STATUS = { - OK: httpCodes.OK, - CREATED: httpCodes.CREATED, - MULTIPLE_CHOICES: httpCodes.MULTIPLE_CHOICES, - NOT_MODIFIED: httpCodes.NOT_MODIFIED, - BAD_REQUEST: httpCodes.BAD_REQUEST, - UNAUTHORIZED: httpCodes.UNAUTHORIZED, - FORBIDDEN: httpCodes.FORBIDDEN, - NOT_FOUND: httpCodes.NOT_FOUND, - CONFLICT: httpCodes.CONFLICT, - NOT_IMPLEMENTED: httpCodes.NOT_IMPLEMENTED, - UNSUPPORTED_MEDIA: httpCodes.UNSUPPORTED_MEDIA_TYPE, - BAD_DATA: httpCodes.UNPROCESSABLE_ENTITY, - INTERNAL_ERROR: httpCodes.INTERNAL_SERVER_ERROR, - SERVICE_UNAVAILABLE: httpCodes.SERVICE_UNAVAILABLE, - LOOP_DETECTED: 508, -}; - -export const CHARACTER_ENCODING = { - UTF8: 'utf8', -}; - -export const ERROR_CODE = { - token_required: 'token is required', -}; - -export const TOKEN_BASIC = 'Basic'; -export const TOKEN_BEARER = 'Bearer'; - -export const HEADERS = { - ACCEPT: 'Accept', - ACCEPT_ENCODING: 'Accept-Encoding', - USER_AGENT: 'User-Agent', - JSON: 'application/json', - CONTENT_TYPE: 'Content-type', - CONTENT_LENGTH: 'content-length', - TEXT_PLAIN: 'text/plain', - TEXT_PLAIN_UTF8: 'text/plain; charset=utf-8', - TEXT_HTML_UTF8: 'text/html; charset=utf-8', - TEXT_HTML: 'text/html', - AUTHORIZATION: 'authorization', - // only set with proxy that setup HTTPS - // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Proto - FORWARDED_PROTO: 'X-Forwarded-Proto', - FORWARDED_FOR: 'X-Forwarded-For', - FRAMES_OPTIONS: 'X-Frame-Options', - CSP: 'Content-Security-Policy', - CTO: 'X-Content-Type-Options', - XSS: 'X-XSS-Protection', - ETAG: 'ETag', - JSON_CHARSET: 'application/json; charset=utf-8', - OCTET_STREAM: 'application/octet-stream; charset=utf-8', - TEXT_CHARSET: 'text/plain; charset=utf-8', - WWW_AUTH: 'WWW-Authenticate', - GZIP: 'gzip', -}; - -export const API_MESSAGE = { - PKG_CREATED: 'created new package', - PKG_CHANGED: 'package changed', - PKG_REMOVED: 'package removed', - PKG_PUBLISHED: 'package published', - TARBALL_UPLOADED: 'tarball uploaded successfully', - TARBALL_REMOVED: 'tarball removed', - TAG_UPDATED: 'tags updated', - TAG_REMOVED: 'tag removed', - TAG_ADDED: 'package tagged', - LOGGED_OUT: 'Logged out', -}; - -// @deprecated -export const SUPPORT_ERRORS = { - PLUGIN_MISSING_INTERFACE: 'the plugin does not provide implementation of the requested feature', - TFA_DISABLED: 'the two-factor authentication is not yet supported', - STORAGE_NOT_IMPLEMENT: 'the storage does not support token saving', - PARAMETERS_NOT_VALID: 'the parameters are not valid', -}; - -// @deprecated -export const API_ERROR = { - PASSWORD_SHORT: (passLength = DEFAULT_MIN_LIMIT_PASSWORD): string => - `The provided password is too short. Please pick a password longer than ` + - `${passLength} characters.`, - MUST_BE_LOGGED: 'You must be logged in to publish packages.', - PLUGIN_ERROR: 'bug in the auth plugin system', - CONFIG_BAD_FORMAT: 'config file must be an object', - BAD_USERNAME_PASSWORD: 'bad username/password, access denied', - NO_PACKAGE: 'no such package available', - PACKAGE_CANNOT_BE_ADDED: 'this package cannot be added', - BAD_DATA: 'bad data', - NOT_ALLOWED: 'not allowed to access package', - NOT_ALLOWED_PUBLISH: 'not allowed to publish package', - INTERNAL_SERVER_ERROR: 'internal server error', - UNKNOWN_ERROR: 'unknown error', - NOT_PACKAGE_UPLINK: 'package does not exist on uplink', - UPLINK_OFFLINE_PUBLISH: 'one of the uplinks is down, refuse to publish', - UPLINK_OFFLINE: 'uplink is offline', - CONTENT_MISMATCH: 'content length mismatch', - NOT_FILE_UPLINK: "file doesn't exist on uplink", - MAX_USERS_REACHED: 'maximum amount of users reached', - VERSION_NOT_EXIST: "this version doesn't exist", - UNSUPORTED_REGISTRY_CALL: 'unsupported registry call', - FILE_NOT_FOUND: 'File not found', - REGISTRATION_DISABLED: 'user registration disabled', - UNAUTHORIZED_ACCESS: 'unauthorized access', - BAD_STATUS_CODE: 'bad status code', - PACKAGE_EXIST: 'this package is already present', - BAD_AUTH_HEADER: 'bad authorization header', - WEB_DISABLED: 'Web interface is disabled in the config file', - DEPRECATED_BASIC_HEADER: 'basic authentication is deprecated, please use JWT instead', - BAD_FORMAT_USER_GROUP: 'user groups is different than an array', - RESOURCE_UNAVAILABLE: 'resource unavailable', - BAD_PACKAGE_DATA: 'bad incoming package data', - USERNAME_PASSWORD_REQUIRED: 'username and password is required', - USERNAME_ALREADY_REGISTERED: 'username is already registered', -}; - -// @deprecated -export const APP_ERROR = { - CONFIG_NOT_VALID: 'CONFIG: it does not look like a valid config file', - PROFILE_ERROR: 'profile unexpected error', - PASSWORD_VALIDATION: 'not valid password', -}; - -// @deprecated -export type VerdaccioError = HttpError & { code: number }; - -function getError(code: number, message: string): VerdaccioError { - const httpError = createError(code, message); - - httpError.code = code; - - return httpError as VerdaccioError; -} - -export function getConflict(message: string = API_ERROR.PACKAGE_EXIST): VerdaccioError { - return getError(HTTP_STATUS.CONFLICT, message); -} - -export function getBadData(customMessage?: string): VerdaccioError { - return getError(HTTP_STATUS.BAD_DATA, customMessage || API_ERROR.BAD_DATA); -} - -export function getBadRequest(customMessage: string): VerdaccioError { - return getError(HTTP_STATUS.BAD_REQUEST, customMessage); -} - -export function getInternalError(customMessage?: string): VerdaccioError { - return customMessage - ? getError(HTTP_STATUS.INTERNAL_ERROR, customMessage) - : getError(HTTP_STATUS.INTERNAL_ERROR, API_ERROR.UNKNOWN_ERROR); -} - -export function getUnauthorized(message = 'no credentials provided'): VerdaccioError { - return getError(HTTP_STATUS.UNAUTHORIZED, message); -} - -export function getForbidden(message = "can't use this filename"): VerdaccioError { - return getError(HTTP_STATUS.FORBIDDEN, message); -} - -export function getServiceUnavailable( - message: string = API_ERROR.RESOURCE_UNAVAILABLE -): VerdaccioError { - return getError(HTTP_STATUS.SERVICE_UNAVAILABLE, message); -} - -export function getNotFound(customMessage?: string): VerdaccioError { - return getError(HTTP_STATUS.NOT_FOUND, customMessage || API_ERROR.NO_PACKAGE); -} - -export function getCode(statusCode: number, customMessage: string): VerdaccioError { - return getError(statusCode, customMessage); -} - -export const TIME_EXPIRATION_24H = '24h'; -export const TIME_EXPIRATION_7D = '7d'; -export const DIST_TAGS = 'dist-tags'; -export const LATEST = 'latest'; -export const USERS = 'users'; -export const DEFAULT_USER = 'Anonymous'; - -export const LOG_STATUS_MESSAGE = - "@{status}, user: @{user}(@{remoteIP}), req: '@{request.method} @{request.url}'"; -export const LOG_VERDACCIO_ERROR = `${LOG_STATUS_MESSAGE}, error: @{!error}`; -export const LOG_VERDACCIO_BYTES = `${LOG_STATUS_MESSAGE}, bytes: @{bytes.in}/@{bytes.out}`; - -export * from './helpers/pkg'; diff --git a/packages/core/commons-api/test/errors.spec.ts b/packages/core/commons-api/test/errors.spec.ts deleted file mode 100644 index 32b34564c..000000000 --- a/packages/core/commons-api/test/errors.spec.ts +++ /dev/null @@ -1,108 +0,0 @@ -import _ from 'lodash'; - -import { - getNotFound, - VerdaccioError, - HTTP_STATUS, - getConflict, - getBadData, - getInternalError, - API_ERROR, - getUnauthorized, - getForbidden, - getServiceUnavailable, - getCode, -} from '../src/index'; - -describe('testing errors', () => { - test('should qualify as an native error', () => { - expect(_.isError(getNotFound())).toBeTruthy(); - expect(_.isError(getConflict())).toBeTruthy(); - expect(_.isError(getBadData())).toBeTruthy(); - expect(_.isError(getInternalError())).toBeTruthy(); - expect(_.isError(getUnauthorized())).toBeTruthy(); - expect(_.isError(getForbidden())).toBeTruthy(); - expect(_.isError(getServiceUnavailable())).toBeTruthy(); - expect(_.isError(getCode(400, 'fooError'))).toBeTruthy(); - }); - - test('should test not found', () => { - const err: VerdaccioError = getNotFound('foo'); - - expect(err.code).toBeDefined(); - expect(err.code).toEqual(HTTP_STATUS.NOT_FOUND); - expect(err.statusCode).toEqual(HTTP_STATUS.NOT_FOUND); - expect(err.message).toEqual('foo'); - }); - - test('should test conflict', () => { - const err: VerdaccioError = getConflict('foo'); - - expect(err.code).toBeDefined(); - expect(err.code).toEqual(HTTP_STATUS.CONFLICT); - expect(err.message).toEqual('foo'); - }); - - test('should test bad data', () => { - const err: VerdaccioError = getBadData('foo'); - - expect(err.code).toBeDefined(); - expect(err.code).toEqual(HTTP_STATUS.BAD_DATA); - expect(err.message).toEqual('foo'); - }); - - test('should test internal error custom message', () => { - const err: VerdaccioError = getInternalError('foo'); - - expect(err.code).toBeDefined(); - expect(err.code).toEqual(HTTP_STATUS.INTERNAL_ERROR); - expect(err.message).toEqual('foo'); - }); - - test('should test internal error', () => { - const err: VerdaccioError = getInternalError(); - - expect(err.code).toBeDefined(); - expect(err.code).toEqual(HTTP_STATUS.INTERNAL_ERROR); - expect(err.message).toEqual(API_ERROR.UNKNOWN_ERROR); - }); - - test('should test Unauthorized message', () => { - const err: VerdaccioError = getUnauthorized('foo'); - - expect(err.code).toBeDefined(); - expect(err.code).toEqual(HTTP_STATUS.UNAUTHORIZED); - expect(err.message).toEqual('foo'); - }); - - test('should test forbidden message', () => { - const err: VerdaccioError = getForbidden('foo'); - - expect(err.code).toBeDefined(); - expect(err.code).toEqual(HTTP_STATUS.FORBIDDEN); - expect(err.message).toEqual('foo'); - }); - - test('should test service unavailable message', () => { - const err: VerdaccioError = getServiceUnavailable('foo'); - - expect(err.code).toBeDefined(); - expect(err.code).toEqual(HTTP_STATUS.SERVICE_UNAVAILABLE); - expect(err.message).toEqual('foo'); - }); - - test('should test custom code error message', () => { - const err: VerdaccioError = getCode(HTTP_STATUS.NOT_FOUND, 'foo'); - - expect(err.code).toBeDefined(); - expect(err.code).toEqual(HTTP_STATUS.NOT_FOUND); - expect(err.message).toEqual('foo'); - }); - - test('should test custom code ok message', () => { - const err: VerdaccioError = getCode(HTTP_STATUS.OK, 'foo'); - - expect(err.code).toBeDefined(); - expect(err.code).toEqual(HTTP_STATUS.OK); - }); -}); diff --git a/packages/core/commons-api/types/lockfile.d.ts b/packages/core/commons-api/types/lockfile.d.ts deleted file mode 100644 index 0ed7246a8..000000000 --- a/packages/core/commons-api/types/lockfile.d.ts +++ /dev/null @@ -1,20 +0,0 @@ -declare module 'lockfile' { - type Callback = (err?: Error) => void; - - interface LockOptions { - wait?: number; - pollPeriod?: number; - stale?: number; - retries?: number; - retryWait?: number; - } - - interface LockFileExport { - lock(fileName: string, opts: LockOptions, cb: Callback): void; - unlock(fileName: string, cb: Callback): void; - } - - const lockFileExport: LockFileExport; - - export default lockFileExport; -} diff --git a/packages/core/core/src/constants.ts b/packages/core/core/src/constants.ts index b61cc1280..73deca2f1 100644 --- a/packages/core/core/src/constants.ts +++ b/packages/core/core/src/constants.ts @@ -1,3 +1,5 @@ +import httpCodes from 'http-status-codes'; + export const DEFAULT_MIN_LIMIT_PASSWORD = 3; export const TIME_EXPIRATION_24H = '24h'; export const TIME_EXPIRATION_7D = '7d'; @@ -47,3 +49,43 @@ export const HEADERS = { WWW_AUTH: 'WWW-Authenticate', GZIP: 'gzip', }; + +export const HTTP_STATUS = { + OK: httpCodes.OK, + CREATED: httpCodes.CREATED, + MULTIPLE_CHOICES: httpCodes.MULTIPLE_CHOICES, + NOT_MODIFIED: httpCodes.NOT_MODIFIED, + BAD_REQUEST: httpCodes.BAD_REQUEST, + UNAUTHORIZED: httpCodes.UNAUTHORIZED, + FORBIDDEN: httpCodes.FORBIDDEN, + NOT_FOUND: httpCodes.NOT_FOUND, + CONFLICT: httpCodes.CONFLICT, + NOT_IMPLEMENTED: httpCodes.NOT_IMPLEMENTED, + UNSUPPORTED_MEDIA: httpCodes.UNSUPPORTED_MEDIA_TYPE, + BAD_DATA: httpCodes.UNPROCESSABLE_ENTITY, + INTERNAL_ERROR: httpCodes.INTERNAL_SERVER_ERROR, + SERVICE_UNAVAILABLE: httpCodes.SERVICE_UNAVAILABLE, + LOOP_DETECTED: 508, +}; + +export const ERROR_CODE = { + token_required: 'token is required', +}; + +export const API_MESSAGE = { + PKG_CREATED: 'created new package', + PKG_CHANGED: 'package changed', + PKG_REMOVED: 'package removed', + PKG_PUBLISHED: 'package published', + TARBALL_UPLOADED: 'tarball uploaded successfully', + TARBALL_REMOVED: 'tarball removed', + TAG_UPDATED: 'tags updated', + TAG_REMOVED: 'tag removed', + TAG_ADDED: 'package tagged', + LOGGED_OUT: 'Logged out', +}; + +export const LOG_STATUS_MESSAGE = + "@{status}, user: @{user}(@{remoteIP}), req: '@{request.method} @{request.url}'"; +export const LOG_VERDACCIO_ERROR = `${LOG_STATUS_MESSAGE}, error: @{!error}`; +export const LOG_VERDACCIO_BYTES = `${LOG_STATUS_MESSAGE}, bytes: @{bytes.in}/@{bytes.out}`; diff --git a/packages/core/core/src/error-utils.ts b/packages/core/core/src/error-utils.ts index c36e0f24a..d5ba2cd0a 100644 --- a/packages/core/core/src/error-utils.ts +++ b/packages/core/core/src/error-utils.ts @@ -1,48 +1,5 @@ import createError, { HttpError } from 'http-errors'; -import httpCodes from 'http-status-codes'; -import { DEFAULT_MIN_LIMIT_PASSWORD } from './constants'; - -export const HTTP_STATUS = { - OK: httpCodes.OK, - CREATED: httpCodes.CREATED, - MULTIPLE_CHOICES: httpCodes.MULTIPLE_CHOICES, - NOT_MODIFIED: httpCodes.NOT_MODIFIED, - BAD_REQUEST: httpCodes.BAD_REQUEST, - UNAUTHORIZED: httpCodes.UNAUTHORIZED, - FORBIDDEN: httpCodes.FORBIDDEN, - NOT_FOUND: httpCodes.NOT_FOUND, - CONFLICT: httpCodes.CONFLICT, - NOT_IMPLEMENTED: httpCodes.NOT_IMPLEMENTED, - UNSUPPORTED_MEDIA: httpCodes.UNSUPPORTED_MEDIA_TYPE, - BAD_DATA: httpCodes.UNPROCESSABLE_ENTITY, - INTERNAL_ERROR: httpCodes.INTERNAL_SERVER_ERROR, - SERVICE_UNAVAILABLE: httpCodes.SERVICE_UNAVAILABLE, - LOOP_DETECTED: 508, -}; - -export const ERROR_CODE = { - token_required: 'token is required', -}; - -export const API_MESSAGE = { - PKG_CREATED: 'created new package', - PKG_CHANGED: 'package changed', - PKG_REMOVED: 'package removed', - PKG_PUBLISHED: 'package published', - TARBALL_UPLOADED: 'tarball uploaded successfully', - TARBALL_REMOVED: 'tarball removed', - TAG_UPDATED: 'tags updated', - TAG_REMOVED: 'tag removed', - TAG_ADDED: 'package tagged', - LOGGED_OUT: 'Logged out', -}; - -export const SUPPORT_ERRORS = { - PLUGIN_MISSING_INTERFACE: 'the plugin does not provide implementation of the requested feature', - TFA_DISABLED: 'the two-factor authentication is not yet supported', - STORAGE_NOT_IMPLEMENT: 'the storage does not support token saving', - PARAMETERS_NOT_VALID: 'the parameters are not valid', -}; +import { DEFAULT_MIN_LIMIT_PASSWORD, HTTP_STATUS } from './constants'; export const API_ERROR = { PASSWORD_SHORT: (passLength = DEFAULT_MIN_LIMIT_PASSWORD): string => @@ -82,6 +39,13 @@ export const API_ERROR = { USERNAME_ALREADY_REGISTERED: 'username is already registered', }; +export const SUPPORT_ERRORS = { + PLUGIN_MISSING_INTERFACE: 'the plugin does not provide implementation of the requested feature', + TFA_DISABLED: 'the two-factor authentication is not yet supported', + STORAGE_NOT_IMPLEMENT: 'the storage does not support token saving', + PARAMETERS_NOT_VALID: 'the parameters are not valid', +}; + export const APP_ERROR = { CONFIG_NOT_VALID: 'CONFIG: it does not look like a valid config file', PROFILE_ERROR: 'profile unexpected error', @@ -137,8 +101,3 @@ export function getNotFound(customMessage?: string): VerdaccioError { export function getCode(statusCode: number, customMessage: string): VerdaccioError { return getError(statusCode, customMessage); } - -export const LOG_STATUS_MESSAGE = - "@{status}, user: @{user}(@{remoteIP}), req: '@{request.method} @{request.url}'"; -export const LOG_VERDACCIO_ERROR = `${LOG_STATUS_MESSAGE}, error: @{!error}`; -export const LOG_VERDACCIO_BYTES = `${LOG_STATUS_MESSAGE}, bytes: @{bytes.in}/@{bytes.out}`; diff --git a/packages/core/core/src/index.ts b/packages/core/core/src/index.ts index c67a16777..bec3a3083 100644 --- a/packages/core/core/src/index.ts +++ b/packages/core/core/src/index.ts @@ -7,6 +7,22 @@ import * as pluginUtils from './plugin-utils'; import * as fileUtils from './file-utils'; import * as pkgUtils from './pkg-utils'; +export { VerdaccioError, API_ERROR, SUPPORT_ERRORS, APP_ERROR } from './error-utils'; +export { + TOKEN_BASIC, + TOKEN_BEARER, + HTTP_STATUS, + API_MESSAGE, + HEADERS, + DIST_TAGS, + CHARACTER_ENCODING, + HEADER_TYPE, + LATEST, + DEFAULT_MIN_LIMIT_PASSWORD, + DEFAULT_USER, + USERS, +} from './constants'; + export { fileUtils, pkgUtils, diff --git a/packages/core/core/test/errors.spec.ts b/packages/core/core/test/errors.spec.ts index f20bb44ad..b3158ca49 100644 --- a/packages/core/core/test/errors.spec.ts +++ b/packages/core/core/test/errors.spec.ts @@ -1,9 +1,9 @@ import _ from 'lodash'; +import { HTTP_STATUS } from '../src/constants'; import { getNotFound, VerdaccioError, - HTTP_STATUS, getConflict, getBadData, getInternalError, diff --git a/packages/core/htpasswd/package.json b/packages/core/htpasswd/package.json index 1f5047ae5..8140807c3 100644 --- a/packages/core/htpasswd/package.json +++ b/packages/core/htpasswd/package.json @@ -34,7 +34,7 @@ "npm": ">=6" }, "dependencies": { - "@verdaccio/commons-api": "workspace:11.0.0-6-next.4", + "@verdaccio/core": "workspace:6.0.0-6-next.1", "@verdaccio/file-locking": "workspace:11.0.0-alpha.3", "apache-md5": "1.1.7", "bcryptjs": "2.4.3", diff --git a/packages/core/htpasswd/src/utils.ts b/packages/core/htpasswd/src/utils.ts index c3bec075f..22bb54a67 100644 --- a/packages/core/htpasswd/src/utils.ts +++ b/packages/core/htpasswd/src/utils.ts @@ -5,7 +5,7 @@ import bcrypt from 'bcryptjs'; import createError, { HttpError } from 'http-errors'; import { readFile } from '@verdaccio/file-locking'; import { Callback } from '@verdaccio/types'; -import { API_ERROR, HTTP_STATUS } from '@verdaccio/commons-api'; +import { API_ERROR, HTTP_STATUS } from '@verdaccio/core'; import crypt3 from './crypt3'; diff --git a/packages/core/htpasswd/tsconfig.json b/packages/core/htpasswd/tsconfig.json index ae14c1afc..bbaf68bd5 100644 --- a/packages/core/htpasswd/tsconfig.json +++ b/packages/core/htpasswd/tsconfig.json @@ -7,9 +7,6 @@ "include": ["src/**/*"], "exclude": ["src/**/*.test.ts"], "references": [ - { - "path": "../commons-api" - }, { "path": "../file-locking" } diff --git a/packages/core/local-storage/package.json b/packages/core/local-storage/package.json index a882336a2..40d4b6d3e 100644 --- a/packages/core/local-storage/package.json +++ b/packages/core/local-storage/package.json @@ -37,7 +37,6 @@ "npm": ">=7" }, "dependencies": { - "@verdaccio/commons-api": "workspace:11.0.0-6-next.4", "@verdaccio/core": "workspace:6.0.0-6-next.1", "@verdaccio/file-locking": "workspace:11.0.0-alpha.3", "@verdaccio/streams": "workspace:11.0.0-6-next.4", diff --git a/packages/core/local-storage/src/local-fs.ts b/packages/core/local-storage/src/local-fs.ts index 156bcc7a6..cf2319880 100644 --- a/packages/core/local-storage/src/local-fs.ts +++ b/packages/core/local-storage/src/local-fs.ts @@ -8,7 +8,7 @@ import _ from 'lodash'; import { UploadTarball, ReadTarball } from '@verdaccio/streams'; import { unlockFile, readFile } from '@verdaccio/file-locking'; import { Callback, Logger, Package, ILocalPackageManager, IUploadTarball } from '@verdaccio/types'; -import { getCode, getInternalError, getNotFound, VerdaccioError } from '@verdaccio/commons-api'; +import { VerdaccioError, errorUtils } from '@verdaccio/core'; import { unlinkPromise, rmdirPromise, readFilePromise } from './fs'; export const fileExist = 'EEXISTS'; @@ -19,7 +19,7 @@ export const packageJSONFileName = 'package.json'; const debug = buildDebug('verdaccio:plugin:local-storage:local-fs'); export const fSError = function (message: string, code = 409): VerdaccioError { - const err: VerdaccioError = getCode(code, message); + const err: VerdaccioError = errorUtils.getCode(code, message); // FIXME: we should return http-status codes here instead, future improvement // @ts-ignore err.code = message; @@ -118,9 +118,9 @@ export default class LocalFS implements ILocalFSPackageManager { if (_.isNil(err) === false) { if (err.code === resourceNotAvailable) { - return unLockCallback(getInternalError('resource temporarily unavailable')); + return unLockCallback(errorUtils.getInternalError('resource temporarily unavailable')); } else if (err.code === noSuchFile) { - return unLockCallback(getNotFound()); + return unLockCallback(errorUtils.getNotFound()); } else { return unLockCallback(err); } diff --git a/packages/core/local-storage/tsconfig.json b/packages/core/local-storage/tsconfig.json index 0504afe27..ee16e3a1a 100644 --- a/packages/core/local-storage/tsconfig.json +++ b/packages/core/local-storage/tsconfig.json @@ -7,9 +7,6 @@ "include": ["src/**/*"], "exclude": ["src/**/*.test.ts"], "references": [ - { - "path": "../commons-api" - }, { "path": "../file-locking" }, diff --git a/packages/core/tarball/package.json b/packages/core/tarball/package.json index 06e42083c..3831466eb 100644 --- a/packages/core/tarball/package.json +++ b/packages/core/tarball/package.json @@ -34,7 +34,7 @@ "access": "public" }, "dependencies": { - "@verdaccio/commons-api": "workspace:11.0.0-6-next.4", + "@verdaccio/core": "workspace:6.0.0-6-next.1", "@verdaccio/url": "workspace:11.0.0-6-next.5", "@verdaccio/utils": "workspace:6.0.0-6-next.6", "lodash": "4.17.21" diff --git a/packages/core/tarball/tests/convertDistRemoteToLocalTarballUrls.spec.ts b/packages/core/tarball/tests/convertDistRemoteToLocalTarballUrls.spec.ts index cb8b6b820..557635335 100644 --- a/packages/core/tarball/tests/convertDistRemoteToLocalTarballUrls.spec.ts +++ b/packages/core/tarball/tests/convertDistRemoteToLocalTarballUrls.spec.ts @@ -1,5 +1,5 @@ import * as httpMocks from 'node-mocks-http'; -import { HEADERS } from '@verdaccio/commons-api'; +import { HEADERS } from '@verdaccio/core'; import { convertDistRemoteToLocalTarballUrls } from '../src'; describe('convertDistRemoteToLocalTarballUrls', () => { diff --git a/packages/core/tarball/tsconfig.json b/packages/core/tarball/tsconfig.json index 818a55711..eeee84ecb 100644 --- a/packages/core/tarball/tsconfig.json +++ b/packages/core/tarball/tsconfig.json @@ -10,9 +10,6 @@ { "path": "../../utils" }, - { - "path": "../commons-api" - }, { "path": "../url" } diff --git a/packages/core/types/index.d.ts b/packages/core/types/index.d.ts index 5e181f8b7..5674cb217 100644 --- a/packages/core/types/index.d.ts +++ b/packages/core/types/index.d.ts @@ -532,7 +532,7 @@ declare module '@verdaccio/types' { // FIXME: error should be export type `VerdaccioError = HttpError & { code: number };` // instead of AuthError - // but this type is on @verdaccio/commons-api and cannot be used here yet (I don't know why) + // but this type is on @verdaccio/core and cannot be used here yet (I don't know why) interface HttpError extends Error { status: number; statusCode: number; diff --git a/packages/core/url/package.json b/packages/core/url/package.json index 5f758ea81..72953aeaa 100644 --- a/packages/core/url/package.json +++ b/packages/core/url/package.json @@ -34,7 +34,7 @@ "access": "public" }, "dependencies": { - "@verdaccio/commons-api": "workspace:11.0.0-6-next.4", + "@verdaccio/core": "workspace:6.0.0-6-next.1", "debug": "4.3.2", "lodash": "4.17.21", "validator": "13.6.0" diff --git a/packages/core/url/src/index.ts b/packages/core/url/src/index.ts index 3349a884b..0476894d4 100644 --- a/packages/core/url/src/index.ts +++ b/packages/core/url/src/index.ts @@ -1,7 +1,7 @@ import { URL } from 'url'; import buildDebug from 'debug'; import isURLValidator from 'validator/lib/isURL'; -import { HEADERS } from '@verdaccio/commons-api'; +import { HEADERS } from '@verdaccio/core'; const debug = buildDebug('verdaccio:core:url'); diff --git a/packages/core/url/tests/getPublicUrl.spec.ts b/packages/core/url/tests/getPublicUrl.spec.ts index 97f4ec062..4516db042 100644 --- a/packages/core/url/tests/getPublicUrl.spec.ts +++ b/packages/core/url/tests/getPublicUrl.spec.ts @@ -1,6 +1,6 @@ import * as httpMocks from 'node-mocks-http'; -import { HEADERS } from '@verdaccio/commons-api'; +import { HEADERS } from '@verdaccio/core'; import { getPublicUrl } from '../src'; describe('host', () => { diff --git a/packages/core/url/tsconfig.json b/packages/core/url/tsconfig.json index 092466714..35b3cee58 100644 --- a/packages/core/url/tsconfig.json +++ b/packages/core/url/tsconfig.json @@ -5,10 +5,5 @@ "outDir": "./build" }, "include": ["src/**/*"], - "exclude": ["src/**/*.test.ts"], - "references": [ - { - "path": "../commons-api" - } - ] + "exclude": ["src/**/*.test.ts"] } diff --git a/packages/hooks/package.json b/packages/hooks/package.json index d4a11265f..ac120b027 100644 --- a/packages/hooks/package.json +++ b/packages/hooks/package.json @@ -30,7 +30,7 @@ "npm": ">=6" }, "dependencies": { - "@verdaccio/commons-api": "workspace:11.0.0-6-next.4", + "@verdaccio/core": "workspace:6.0.0-6-next.1", "@verdaccio/logger": "workspace:6.0.0-6-next.5", "core-js": "3.17.2", "debug": "4.3.2", @@ -41,7 +41,6 @@ "devDependencies": { "@types/node": "16.9.1", "@verdaccio/auth": "workspace:6.0.0-6-next.12", - "@verdaccio/commons-api": "workspace:11.0.0-6-next.4", "@verdaccio/config": "workspace:6.0.0-6-next.8", "@verdaccio/types": "workspace:11.0.0-6-next.8" }, diff --git a/packages/hooks/src/notify-request.ts b/packages/hooks/src/notify-request.ts index 41817d602..b97005896 100644 --- a/packages/hooks/src/notify-request.ts +++ b/packages/hooks/src/notify-request.ts @@ -1,7 +1,7 @@ import buildDebug from 'debug'; import { logger } from '@verdaccio/logger'; -import { HTTP_STATUS } from '@verdaccio/commons-api'; +import { HTTP_STATUS } from '@verdaccio/core'; const debug = buildDebug('verdaccio:hooks:request'); const fetch = require('undici-fetch'); diff --git a/packages/hooks/tsconfig.json b/packages/hooks/tsconfig.json index 83ed126cd..4f5b13c0b 100644 --- a/packages/hooks/tsconfig.json +++ b/packages/hooks/tsconfig.json @@ -13,9 +13,6 @@ { "path": "../config" }, - { - "path": "../core/commons-api" - }, { "path": "../logger" } diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 65c7d18b7..41069dceb 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -18,7 +18,7 @@ "lodash": "4.17.21" }, "devDependencies": { - "@verdaccio/commons-api": "workspace:11.0.0-6-next.4", + "@verdaccio/core": "workspace:6.0.0-6-next.1", "@verdaccio/config": "workspace:6.0.0-6-next.8", "@verdaccio/mock": "workspace:6.0.0-6-next.9", "@verdaccio/types": "workspace:11.0.0-6-next.8" diff --git a/packages/loaders/tsconfig.json b/packages/loaders/tsconfig.json index 294682cde..eaefd3634 100644 --- a/packages/loaders/tsconfig.json +++ b/packages/loaders/tsconfig.json @@ -11,7 +11,7 @@ "path": "../config" }, { - "path": "../core/commons-api" + "path": "../core/core" }, { "path": "../logger" diff --git a/packages/middleware/package.json b/packages/middleware/package.json index 7eff6845e..f1f7eee3d 100644 --- a/packages/middleware/package.json +++ b/packages/middleware/package.json @@ -40,7 +40,7 @@ "dependencies": { "debug": "4.3.2", "@verdaccio/auth": "workspace:6.0.0-6-next.12", - "@verdaccio/commons-api": "workspace:11.0.0-6-next.4", + "@verdaccio/core": "workspace:6.0.0-6-next.1", "@verdaccio/logger": "workspace:6.0.0-6-next.5", "@verdaccio/utils": "workspace:6.0.0-6-next.6", "lodash": "4.17.21" diff --git a/packages/middleware/src/middleware.ts b/packages/middleware/src/middleware.ts index 02641aaa7..1ab55abb6 100644 --- a/packages/middleware/src/middleware.ts +++ b/packages/middleware/src/middleware.ts @@ -6,7 +6,6 @@ import { validatePackage as utilValidatePackage, isObject, stringToMD5, - ErrorCode, } from '@verdaccio/utils'; import { NextFunction, Request, Response } from 'express'; @@ -15,6 +14,7 @@ import { Config, Package, RemoteUser, Logger } from '@verdaccio/types'; import { logger } from '@verdaccio/logger'; import { IAuth } from '@verdaccio/auth'; import { + errorUtils, API_ERROR, HEADER_TYPE, HEADERS, @@ -22,7 +22,7 @@ import { TOKEN_BASIC, TOKEN_BEARER, VerdaccioError, -} from '@verdaccio/commons-api'; +} from '@verdaccio/core'; import { HttpError } from 'http-errors'; import { getVersionFromTarball } from './middleware-utils'; @@ -78,7 +78,7 @@ export function validateName( } else if (utilValidateName(value)) { next(); } else { - next(ErrorCode.getForbidden('invalid ' + name)); + next(errorUtils.getForbidden('invalid ' + name)); } } @@ -95,7 +95,7 @@ export function validatePackage( } else if (utilValidatePackage(value)) { next(); } else { - next(ErrorCode.getForbidden('invalid ' + name)); + next(errorUtils.getForbidden('invalid ' + name)); } } @@ -103,7 +103,7 @@ export function media(expect: string | null): any { return function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void { if (req.headers[HEADER_TYPE.CONTENT_TYPE] !== expect) { next( - ErrorCode.getCode( + errorUtils.getCode( HTTP_STATUS.UNSUPPORTED_MEDIA, 'wrong content-type, expect: ' + expect + @@ -135,7 +135,7 @@ export function expectJson( next: $NextFunctionVer ): void { if (!isObject(req.body)) { - return next(ErrorCode.getBadRequest("can't parse incoming json")); + return next(errorUtils.getBadRequest("can't parse incoming json")); } next(); } @@ -148,7 +148,7 @@ export function antiLoop(config: Config): Function { for (let i = 0; i < arr.length; i++) { const m = arr[i].match(/\s*(\S+)\s+(\S+)/); if (m && m[2] === config.server_id) { - return next(ErrorCode.getCode(HTTP_STATUS.LOOP_DETECTED, 'loop detected')); + return next(errorUtils.getCode(HTTP_STATUS.LOOP_DETECTED, 'loop detected')); } } } @@ -183,7 +183,7 @@ export function allow(auth: IAuth): Function { } else { // last plugin (that's our built-in one) returns either // cb(err) or cb(null, true), so this should never happen - throw ErrorCode.getInternalError(API_ERROR.PLUGIN_ERROR); + throw errorUtils.getInternalError(API_ERROR.PLUGIN_ERROR); } } ); diff --git a/packages/mock/package.json b/packages/mock/package.json index 66ef664fc..e4bdf8e71 100644 --- a/packages/mock/package.json +++ b/packages/mock/package.json @@ -39,7 +39,7 @@ "build": "pnpm run build:js && pnpm run build:types" }, "dependencies": { - "@verdaccio/commons-api": "workspace:11.0.0-6-next.4", + "@verdaccio/core": "workspace:6.0.0-6-next.1", "@verdaccio/config": "workspace:6.0.0-6-next.8", "@verdaccio/utils": "workspace:6.0.0-6-next.6", "core-js": "3.17.2", diff --git a/packages/mock/src/mock-api.ts b/packages/mock/src/mock-api.ts index a6df3b670..e5104278a 100644 --- a/packages/mock/src/mock-api.ts +++ b/packages/mock/src/mock-api.ts @@ -9,7 +9,7 @@ import { HEADERS, HTTP_STATUS, TOKEN_BEARER, -} from '@verdaccio/commons-api'; +} from '@verdaccio/core'; import { buildToken } from '@verdaccio/utils'; import { generateRandomHexString } from '@verdaccio/utils'; import { Package } from '@verdaccio/types'; diff --git a/packages/mock/src/server.ts b/packages/mock/src/server.ts index d41cd80b7..fd393a378 100644 --- a/packages/mock/src/server.ts +++ b/packages/mock/src/server.ts @@ -2,7 +2,7 @@ import assert from 'assert'; import _ from 'lodash'; import buildDebug from 'debug'; -import { API_MESSAGE, HEADERS, HTTP_STATUS, TOKEN_BASIC } from '@verdaccio/commons-api'; +import { API_MESSAGE, HEADERS, HTTP_STATUS, TOKEN_BASIC } from '@verdaccio/core'; import { buildToken } from '@verdaccio/utils'; import smartRequest, { PromiseAssert } from './request'; diff --git a/packages/mock/src/server_process.ts b/packages/mock/src/server_process.ts index 95a99a85e..87b99ebcc 100644 --- a/packages/mock/src/server_process.ts +++ b/packages/mock/src/server_process.ts @@ -1,7 +1,7 @@ import assert from 'assert'; import { fork } from 'child_process'; -import { HTTP_STATUS } from '@verdaccio/commons-api'; +import { HTTP_STATUS } from '@verdaccio/core'; import { CREDENTIALS } from './constants'; import { IVerdaccioConfig, IServerProcess } from './types'; diff --git a/packages/mock/test/request.spec.ts b/packages/mock/test/request.spec.ts index 262ccdaed..c6948a97c 100644 --- a/packages/mock/test/request.spec.ts +++ b/packages/mock/test/request.spec.ts @@ -1,5 +1,5 @@ import _ from 'lodash'; -import { HTTP_STATUS, VerdaccioError } from '@verdaccio/commons-api'; +import { HTTP_STATUS, VerdaccioError } from '@verdaccio/core'; import smartRequest, { PromiseAssert } from '../src/request'; import { mockServer } from '../src/mock'; diff --git a/packages/node-api/package.json b/packages/node-api/package.json index 1115f58dd..afa59dc39 100644 --- a/packages/node-api/package.json +++ b/packages/node-api/package.json @@ -39,7 +39,7 @@ }, "license": "MIT", "dependencies": { - "@verdaccio/commons-api": "workspace:11.0.0-6-next.4", + "@verdaccio/core": "workspace:6.0.0-6-next.1", "@verdaccio/config": "workspace:6.0.0-6-next.8", "@verdaccio/logger": "workspace:6.0.0-6-next.5", "@verdaccio/server": "workspace:6.0.0-6-next.20", diff --git a/packages/node-api/src/server.ts b/packages/node-api/src/server.ts index d5318ccef..6e153a74d 100644 --- a/packages/node-api/src/server.ts +++ b/packages/node-api/src/server.ts @@ -8,7 +8,7 @@ import fs from 'fs'; import url from 'url'; import { findConfigFile, parseConfigFile } from '@verdaccio/config'; -import { API_ERROR } from '@verdaccio/commons-api'; +import { API_ERROR } from '@verdaccio/core'; import { ConfigRuntime, HttpsConfKeyCert, HttpsConfPfx } from '@verdaccio/types'; import { setup, logger } from '@verdaccio/logger'; import server from '@verdaccio/server'; diff --git a/packages/plugins/active-directory/package.json b/packages/plugins/active-directory/package.json index e3305980f..7739671b3 100644 --- a/packages/plugins/active-directory/package.json +++ b/packages/plugins/active-directory/package.json @@ -34,7 +34,7 @@ "npm": ">=6" }, "dependencies": { - "@verdaccio/commons-api": "workspace:11.0.0-6-next.4", + "@verdaccio/core": "workspace:6.0.0-6-next.1", "activedirectory2": "2.1.0" }, "devDependencies": { diff --git a/packages/plugins/active-directory/src/active-directory.ts b/packages/plugins/active-directory/src/active-directory.ts index 71a192175..c2a8ec128 100644 --- a/packages/plugins/active-directory/src/active-directory.ts +++ b/packages/plugins/active-directory/src/active-directory.ts @@ -1,4 +1,4 @@ -import { getForbidden, getInternalError, getUnauthorized } from '@verdaccio/commons-api'; +import { errorUtils } from '@verdaccio/core'; import { Callback, IPluginAuth, Logger } from '@verdaccio/types'; import ActiveDirectory from 'activedirectory2'; @@ -35,12 +35,12 @@ class ActiveDirectoryPlugin implements IPluginAuth { connection.authenticate(username, password, (err, isAuthenticated): void => { if (err) { this.logger.warn(`AD - Active Directory authentication failed with error: ${err}`); - return cb(getInternalError(err)); + return cb(errorUtils.getInternalError(err)); } if (!isAuthenticated) { this.logger.warn(NotAuthMessage); - return cb(getUnauthorized(NotAuthMessage)); + return cb(errorUtils.getUnauthorized(NotAuthMessage)); } const { groupName } = this.config; @@ -51,7 +51,7 @@ class ActiveDirectoryPlugin implements IPluginAuth { connection.getGroupMembershipForUser(username, (err, groups: object[]): void => { if (err) { this.logger.warn(`AD - Active Directory group check failed with error: ${err}`); - return cb(getInternalError(err as unknown as string)); + return cb(errorUtils.getInternalError(err as unknown as string)); } const requestedGroups = Array.isArray(groupName) ? groupName : [groupName]; @@ -69,7 +69,7 @@ class ActiveDirectoryPlugin implements IPluginAuth { )}`; this.logger.warn(notMemberMessage); - cb(getForbidden(notMemberMessage)); + cb(errorUtils.getForbidden(notMemberMessage)); } else { this.logger.info( `AD - Active Directory authentication succeeded in group(s): ${matchingGroups.join( diff --git a/packages/plugins/active-directory/tests/active-directory.test.ts b/packages/plugins/active-directory/tests/active-directory.test.ts index ceb690887..2082bc824 100644 --- a/packages/plugins/active-directory/tests/active-directory.test.ts +++ b/packages/plugins/active-directory/tests/active-directory.test.ts @@ -1,5 +1,5 @@ import ActiveDirectory from 'activedirectory2'; -import { HTTP_STATUS } from '@verdaccio/commons-api'; +import { HTTP_STATUS } from '@verdaccio/core'; import ActiveDirectoryPlugin, { NotAuthMessage } from '../src/active-directory'; diff --git a/packages/plugins/auth-memory/package.json b/packages/plugins/auth-memory/package.json index 55867bbf7..32f465bd8 100644 --- a/packages/plugins/auth-memory/package.json +++ b/packages/plugins/auth-memory/package.json @@ -32,7 +32,7 @@ }, "dependencies": { "debug": "4.3.2", - "@verdaccio/commons-api": "workspace:11.0.0-6-next.4" + "@verdaccio/core": "workspace:6.0.0-6-next.1" }, "devDependencies": { "@verdaccio/types": "workspace:11.0.0-6-next.8" diff --git a/packages/plugins/auth-memory/src/Memory.ts b/packages/plugins/auth-memory/src/Memory.ts index 45bd7e5f9..59111ec70 100644 --- a/packages/plugins/auth-memory/src/Memory.ts +++ b/packages/plugins/auth-memory/src/Memory.ts @@ -7,13 +7,7 @@ import { RemoteUser, Logger, } from '@verdaccio/types'; -import { - getConflict, - getForbidden, - getNotFound, - getUnauthorized, - API_ERROR, -} from '@verdaccio/commons-api'; +import { errorUtils, API_ERROR } from '@verdaccio/core'; import { VerdaccioMemoryConfig, Users, UserMemory } from './types'; @@ -46,7 +40,7 @@ export default class Memory implements IPluginAuth { } if (password !== userCredentials.password) { - const err = getUnauthorized(API_ERROR.BAD_USERNAME_PASSWORD); + const err = errorUtils.getUnauthorized(API_ERROR.BAD_USERNAME_PASSWORD); debug('password invalid for: %o', user); return done(err); @@ -66,7 +60,7 @@ export default class Memory implements IPluginAuth { if (this._app_config.max_users) { if (Object.keys(this._users).length >= this._app_config.max_users) { - const err = getConflict(API_ERROR.MAX_USERS_REACHED); + const err = errorUtils.getConflict(API_ERROR.MAX_USERS_REACHED); debug(API_ERROR.MAX_USERS_REACHED); return done(err); } @@ -93,7 +87,7 @@ export default class Memory implements IPluginAuth { debug('user changed password succeeded for %o', user?.name); cb(null, user); } else { - const err = getNotFound('user not found'); + const err = errorUtils.getNotFound('user not found'); this._logger.debug({ user: username }, 'change password user @{user} not found'); debug('change password user for %o not found', user?.name); return cb(err); @@ -109,7 +103,7 @@ export default class Memory implements IPluginAuth { } if (!user?.name) { - const err = getForbidden('not allowed to access package'); + const err = errorUtils.getForbidden('not allowed to access package'); this._logger.debug({ user: user.name }, 'user: @{user} not allowed to access package'); debug('%o not allowed to access package err', user?.name, err.message); return cb(err); @@ -120,7 +114,7 @@ export default class Memory implements IPluginAuth { return cb(null, true); } - const err = getForbidden('not allowed to access package'); + const err = errorUtils.getForbidden('not allowed to access package'); debug('%o not allowed to access package err', user?.name, err?.message); return cb(err); } @@ -132,7 +126,7 @@ export default class Memory implements IPluginAuth { } if (!user?.name) { - const err = getForbidden('not allowed to publish package'); + const err = errorUtils.getForbidden('not allowed to publish package'); debug('%o not allowed to publish package err %o', user?.name, err.message); return cb(err); } @@ -141,7 +135,7 @@ export default class Memory implements IPluginAuth { return cb(null, true); } - const err = getForbidden('not allowed to publish package'); + const err = errorUtils.getForbidden('not allowed to publish package'); debug('%o not allowed to publish package err %o', user?.name, err.message); return cb(err); diff --git a/packages/plugins/aws-storage/package.json b/packages/plugins/aws-storage/package.json index 681beac00..bedc8179a 100644 --- a/packages/plugins/aws-storage/package.json +++ b/packages/plugins/aws-storage/package.json @@ -31,7 +31,7 @@ "main": "build/index.js", "types": "build/index.d.ts", "dependencies": { - "@verdaccio/commons-api": "workspace:11.0.0-6-next.4", + "@verdaccio/core": "workspace:6.0.0-6-next.1", "@verdaccio/streams": "workspace:11.0.0-6-next.4", "aws-sdk": "2.981.0" }, diff --git a/packages/plugins/aws-storage/src/index.ts b/packages/plugins/aws-storage/src/index.ts index d8f3afefc..bdd0f9bd3 100644 --- a/packages/plugins/aws-storage/src/index.ts +++ b/packages/plugins/aws-storage/src/index.ts @@ -7,7 +7,7 @@ import { Token, TokenFilter, } from '@verdaccio/types'; -import { getInternalError, VerdaccioError, getServiceUnavailable } from '@verdaccio/commons-api'; +import { errorUtils, VerdaccioError } from '@verdaccio/core'; import { S3 } from 'aws-sdk'; import { S3Config } from './config'; @@ -149,7 +149,7 @@ export default class S3Database implements IPluginStorage { data = await this.get(); } catch (err) { this.logger.error({ err }, 's3: [remove] error: @{err}'); - throw getInternalError('something went wrong on remove a package'); + throw errorUtils.getInternalError('something went wrong on remove a package'); } const pkgName = data.indexOf(name); @@ -252,18 +252,18 @@ export default class S3Database implements IPluginStorage { public saveToken(token: Token): Promise { this.logger.warn({ token }, 'save token has not been implemented yet @{token}'); - return Promise.reject(getServiceUnavailable('[saveToken] method not implemented')); + return Promise.reject(errorUtils.getServiceUnavailable('[saveToken] method not implemented')); } public deleteToken(user: string, tokenKey: string): Promise { this.logger.warn({ tokenKey, user }, 'delete token has not been implemented yet @{user}'); - return Promise.reject(getServiceUnavailable('[deleteToken] method not implemented')); + return Promise.reject(errorUtils.getServiceUnavailable('[deleteToken] method not implemented')); } public readTokens(filter: TokenFilter): Promise { this.logger.warn({ filter }, 'read tokens has not been implemented yet @{filter}'); - return Promise.reject(getServiceUnavailable('[readTokens] method not implemented')); + return Promise.reject(errorUtils.getServiceUnavailable('[readTokens] method not implemented')); } } diff --git a/packages/plugins/aws-storage/src/s3Errors.ts b/packages/plugins/aws-storage/src/s3Errors.ts index d390491dc..ad5de8926 100644 --- a/packages/plugins/aws-storage/src/s3Errors.ts +++ b/packages/plugins/aws-storage/src/s3Errors.ts @@ -1,20 +1,12 @@ import { AWSError } from 'aws-sdk'; -import { - getNotFound, - getCode, - getInternalError, - getConflict, - API_ERROR, - HTTP_STATUS, - VerdaccioError, -} from '@verdaccio/commons-api'; +import { errorUtils, API_ERROR, HTTP_STATUS, VerdaccioError } from '@verdaccio/core'; export function is404Error(err: VerdaccioError): boolean { return err.code === HTTP_STATUS.NOT_FOUND; } export function create404Error(): VerdaccioError { - return getNotFound('no such package available'); + return errorUtils.getNotFound('no such package available'); } export function is409Error(err: VerdaccioError): boolean { @@ -22,7 +14,7 @@ export function is409Error(err: VerdaccioError): boolean { } export function create409Error(): VerdaccioError { - return getConflict('file already exists'); + return errorUtils.getConflict('file already exists'); } export function is503Error(err: VerdaccioError): boolean { @@ -30,19 +22,19 @@ export function is503Error(err: VerdaccioError): boolean { } export function create503Error(): VerdaccioError { - return getCode(HTTP_STATUS.SERVICE_UNAVAILABLE, 'resource temporarily unavailable'); + return errorUtils.getCode(HTTP_STATUS.SERVICE_UNAVAILABLE, 'resource temporarily unavailable'); } export function convertS3Error(err: AWSError): VerdaccioError { switch (err.code) { case 'NoSuchKey': case 'NotFound': - return getNotFound(); + return errorUtils.getNotFound(); case 'StreamContentLengthMismatch': - return getInternalError(API_ERROR.CONTENT_MISMATCH); + return errorUtils.getInternalError(API_ERROR.CONTENT_MISMATCH); case 'RequestAbortedError': - return getInternalError('request aborted'); + return errorUtils.getInternalError('request aborted'); default: - return getCode(err.statusCode!, err.message); + return errorUtils.getCode(err.statusCode!, err.message); } } diff --git a/packages/plugins/aws-storage/src/s3PackageManager.ts b/packages/plugins/aws-storage/src/s3PackageManager.ts index a397ece09..70ce47dea 100644 --- a/packages/plugins/aws-storage/src/s3PackageManager.ts +++ b/packages/plugins/aws-storage/src/s3PackageManager.ts @@ -1,6 +1,6 @@ import { S3, AWSError } from 'aws-sdk'; import { UploadTarball, ReadTarball } from '@verdaccio/streams'; -import { HEADERS, HTTP_STATUS, VerdaccioError } from '@verdaccio/commons-api'; +import { HEADERS, HTTP_STATUS, VerdaccioError } from '@verdaccio/core'; import { Callback, Logger, Package, ILocalPackageManager, CallbackAction } from '@verdaccio/types'; import { HttpError } from 'http-errors'; diff --git a/packages/plugins/google-cloud-storage/package.json b/packages/plugins/google-cloud-storage/package.json index f000d2c7b..3b189a1c4 100644 --- a/packages/plugins/google-cloud-storage/package.json +++ b/packages/plugins/google-cloud-storage/package.json @@ -33,7 +33,7 @@ "dependencies": { "@google-cloud/datastore": "6.5.0", "@google-cloud/storage": "5.14.0", - "@verdaccio/commons-api": "11.0.0-6-next.4", + "@verdaccio/core": "workspace:6.0.0-6-next.1", "@verdaccio/streams": "workspace:11.0.0-6-next.4" }, "devDependencies": { diff --git a/packages/plugins/google-cloud-storage/src/data-storage.ts b/packages/plugins/google-cloud-storage/src/data-storage.ts index 239eafa60..db96e89a6 100644 --- a/packages/plugins/google-cloud-storage/src/data-storage.ts +++ b/packages/plugins/google-cloud-storage/src/data-storage.ts @@ -1,6 +1,6 @@ import { Storage } from '@google-cloud/storage'; import { Datastore, DatastoreOptions } from '@google-cloud/datastore'; -import { getServiceUnavailable, getInternalError, VerdaccioError } from '@verdaccio/commons-api'; +import { errorUtils, VerdaccioError } from '@verdaccio/core'; import { Logger, Callback, @@ -87,19 +87,19 @@ class GoogleCloudDatabase implements IPluginStorage { this.logger.warn({ token }, 'save token has not been implemented yet @{token}'); - return Promise.reject(getServiceUnavailable('[saveToken] method not implemented')); + return Promise.reject(errorUtils.getServiceUnavailable('[saveToken] method not implemented')); } public deleteToken(user: string, tokenKey: string): Promise { this.logger.warn({ tokenKey, user }, 'delete token has not been implemented yet @{user}'); - return Promise.reject(getServiceUnavailable('[deleteToken] method not implemented')); + return Promise.reject(errorUtils.getServiceUnavailable('[deleteToken] method not implemented')); } public readTokens(filter: TokenFilter): Promise { this.logger.warn({ filter }, 'read tokens has not been implemented yet @{filter}'); - return Promise.reject(getServiceUnavailable('[readTokens] method not implemented')); + return Promise.reject(errorUtils.getServiceUnavailable('[readTokens] method not implemented')); } public getSecret(): Promise { @@ -119,10 +119,10 @@ class GoogleCloudDatabase implements IPluginStorage => { - const error: VerdaccioError = getInternalError(err.message); + const error: VerdaccioError = errorUtils.getInternalError(err.message); this.logger.warn({ error }, 'gcloud: [datastore getSecret] init error @{error}'); - return Promise.reject(getServiceUnavailable('[getSecret] permissions error')); + return Promise.reject(errorUtils.getServiceUnavailable('[getSecret] permissions error')); }); } @@ -160,10 +160,10 @@ class GoogleCloudDatabase implements IPluginStorage { - const error: VerdaccioError = getInternalError(err.message); + const error: VerdaccioError = errorUtils.getInternalError(err.message); this.logger.debug({ error }, 'gcloud: [datastore add] @{name} error @{error}'); - reject(getInternalError(error.message)); + reject(errorUtils.getInternalError(error.message)); }); }); } @@ -174,7 +174,7 @@ class GoogleCloudDatabase implements IPluginStorage { @@ -96,7 +89,7 @@ class GoogleCloudStorageHandler implements IPackageStorageManager { 'gcloud: trying to update @{name} and was not found on storage err: @{error}' ); // @ts-ignore - return onEnd(getNotFound()); + return onEnd(errorUtils.getNotFound()); }); } @@ -123,14 +116,14 @@ class GoogleCloudStorageHandler implements IPackageStorageManager { { name: file.name, err: err.message }, 'gcloud: delete @{name} file has failed err: @{err}' ); - reject(getInternalError(err.message)); + reject(errorUtils.getInternalError(err.message)); }); } catch (err: any) { this.logger.error( { name: file.name, err: err.message }, 'gcloud: delete @{name} file has failed err: @{err}' ); - reject(getInternalError('something went wrong')); + reject(errorUtils.getInternalError('something went wrong')); } }); } @@ -154,7 +147,7 @@ class GoogleCloudStorageHandler implements IPackageStorageManager { { name: file.name, err: err.message }, 'gcloud: delete @{name} package has failed err: @{err}' ); - reject(getInternalError(err.message)); + reject(errorUtils.getInternalError(err.message)); } ); }); @@ -177,7 +170,7 @@ class GoogleCloudStorageHandler implements IPackageStorageManager { { name: name, err: err.message }, 'gcloud: create package @{name} has failed err: @{err}' ); - cb(getInternalError(err.message)); + cb(errorUtils.getInternalError(err.message)); } ); } @@ -217,7 +210,7 @@ class GoogleCloudStorageHandler implements IPackageStorageManager { }); resolve(null); } catch (err: any) { - reject(getInternalError(err.message)); + reject(errorUtils.getInternalError(err.message)); } }); } @@ -263,7 +256,7 @@ class GoogleCloudStorageHandler implements IPackageStorageManager { 'gcloud: check exist package @{name} has failed, cause: @{err}' ); - reject(getInternalError(err.message)); + reject(errorUtils.getInternalError(err.message)); } }); } @@ -280,7 +273,7 @@ class GoogleCloudStorageHandler implements IPackageStorageManager { resolve(response); } catch (err: any) { this.logger.debug({ name: this.name }, 'gcloud: @{name} package not found on storage'); - reject(getNotFound()); + reject(errorUtils.getNotFound()); } }); } @@ -324,7 +317,7 @@ class GoogleCloudStorageHandler implements IPackageStorageManager { // [BadRequestError: Could not authenticate request // getaddrinfo ENOTFOUND www.googleapis.com www.googleapis.com:443] if (err) { - uploadStream.emit('error', getBadRequest(err.message)); + uploadStream.emit('error', errorUtils.getBadRequest(err.message)); fileStream.emit('close'); } }; @@ -340,7 +333,7 @@ class GoogleCloudStorageHandler implements IPackageStorageManager { fileStream.on('error', (err: Error): void => { this.logger.error({ url: file.name }, 'gcloud: upload stream has failed for @{url}'); fileStream.end(); - uploadStream.emit('error', getBadRequest(err.message)); + uploadStream.emit('error', errorUtils.getBadRequest(err.message)); }); uploadStream.abort = (): void => { @@ -356,7 +349,7 @@ class GoogleCloudStorageHandler implements IPackageStorageManager { } }, (err: Error): void => { - uploadStream.emit('error', getInternalError(err.message)); + uploadStream.emit('error', errorUtils.getInternalError(err.message)); } ); } catch (err: any) { @@ -379,13 +372,13 @@ class GoogleCloudStorageHandler implements IPackageStorageManager { .on('error', (err: VerdaccioError): void => { if (err.code === HTTP_STATUS.NOT_FOUND) { this.logger.debug({ url: file.name }, 'gcloud: tarball @{url} do not found on storage'); - localReadStream.emit('error', getNotFound()); + localReadStream.emit('error', errorUtils.getNotFound()); } else { this.logger.error( { url: file.name }, 'gcloud: tarball @{url} has failed to be retrieved from storage' ); - localReadStream.emit('error', getBadRequest(err.message)); + localReadStream.emit('error', errorUtils.getBadRequest(err.message)); } }) .on('response', (response): void => { @@ -401,13 +394,13 @@ class GoogleCloudStorageHandler implements IPackageStorageManager { { url: file.name }, 'gcloud: tarball @{url} was fetched from storage and it is empty' ); - localReadStream.emit('error', getInternalError('file content empty')); + localReadStream.emit('error', errorUtils.getInternalError('file content empty')); } else if (parseInt(size, 10) > 0 && statusCode === HTTP_STATUS.OK) { localReadStream.emit('content-length', response.headers['content-length']); } } else { this.logger.debug({ url: file.name }, 'gcloud: tarball @{url} do not found on storage'); - localReadStream.emit('error', getNotFound()); + localReadStream.emit('error', errorUtils.getNotFound()); } }) .pipe(localReadStream); diff --git a/packages/plugins/google-cloud-storage/tests/datastore.spec.ts b/packages/plugins/google-cloud-storage/tests/datastore.spec.ts index 8a40b6a98..37195dd61 100644 --- a/packages/plugins/google-cloud-storage/tests/datastore.spec.ts +++ b/packages/plugins/google-cloud-storage/tests/datastore.spec.ts @@ -1,7 +1,6 @@ import _ from 'lodash'; import { Logger, ILocalPackageManager } from '@verdaccio/types'; -import { VerdaccioError } from '@verdaccio/commons-api'; -import { HTTP_STATUS } from '@verdaccio/commons-api'; +import { VerdaccioError, HTTP_STATUS } from '@verdaccio/core'; import { ERROR_MISSING_CONFIG } from '../src/data-storage'; import { VerdaccioConfigGoogleStorage } from '../src/types'; diff --git a/packages/plugins/google-cloud-storage/tests/storage.spec.ts b/packages/plugins/google-cloud-storage/tests/storage.spec.ts index f482c32de..b2582a35b 100644 --- a/packages/plugins/google-cloud-storage/tests/storage.spec.ts +++ b/packages/plugins/google-cloud-storage/tests/storage.spec.ts @@ -5,7 +5,7 @@ import { Writable } from 'stream'; import { DownloadResponse } from '@google-cloud/storage'; import { IPackageStorageManager } from '@verdaccio/types'; import { Logger, ILocalData, Callback, Package, IPackageStorage } from '@verdaccio/types'; -import { HTTP_STATUS, API_ERROR, VerdaccioError } from '@verdaccio/commons-api'; +import { HTTP_STATUS, API_ERROR, VerdaccioError } from '@verdaccio/core'; import { pkgFileName } from '../src/storage'; import { VerdaccioConfigGoogleStorage } from '../src/types'; diff --git a/packages/plugins/memory/package.json b/packages/plugins/memory/package.json index 1d0baaa6b..294319ec4 100644 --- a/packages/plugins/memory/package.json +++ b/packages/plugins/memory/package.json @@ -31,7 +31,7 @@ "npm": ">=6" }, "dependencies": { - "@verdaccio/commons-api": "workspace:11.0.0-6-next.4", + "@verdaccio/core": "workspace:6.0.0-6-next.1", "@verdaccio/streams": "workspace:11.0.0-6-next.4", "memory-fs": "0.5.0", "debug": "4.3.2", diff --git a/packages/plugins/memory/src/local-memory.ts b/packages/plugins/memory/src/local-memory.ts index 77e758055..b3bc06975 100644 --- a/packages/plugins/memory/src/local-memory.ts +++ b/packages/plugins/memory/src/local-memory.ts @@ -1,4 +1,4 @@ -import { getServiceUnavailable } from '@verdaccio/commons-api'; +import { errorUtils } from '@verdaccio/core'; import { Logger, Callback, Config, IPluginStorage, Token, PluginOptions } from '@verdaccio/types'; import buildDebug from 'debug'; @@ -107,7 +107,7 @@ class LocalMemory implements IPluginStorage { public saveToken(): Promise { this.logger.warn('[verdaccio/memory][saveToken] save token has not been implemented yet'); - return Promise.reject(getServiceUnavailable('method not implemented')); + return Promise.reject(errorUtils.getServiceUnavailable('method not implemented')); } public deleteToken(user: string, tokenKey: string): Promise { @@ -116,13 +116,13 @@ class LocalMemory implements IPluginStorage { '[verdaccio/memory][deleteToken] delete token has not been implemented yet @{user}' ); - return Promise.reject(getServiceUnavailable('method not implemented')); + return Promise.reject(errorUtils.getServiceUnavailable('method not implemented')); } public readTokens(): Promise { this.logger.warn('[verdaccio/memory][readTokens] read tokens has not been implemented yet '); - return Promise.reject(getServiceUnavailable('method not implemented')); + return Promise.reject(errorUtils.getServiceUnavailable('method not implemented')); } } diff --git a/packages/plugins/memory/src/memory-handler.ts b/packages/plugins/memory/src/memory-handler.ts index 7a39af422..706a2201a 100644 --- a/packages/plugins/memory/src/memory-handler.ts +++ b/packages/plugins/memory/src/memory-handler.ts @@ -1,11 +1,5 @@ import buildDebug from 'debug'; -import { - VerdaccioError, - getBadRequest, - getInternalError, - getConflict, - getNotFound, -} from '@verdaccio/commons-api'; +import { VerdaccioError, errorUtils } from '@verdaccio/core'; import { fs } from 'memfs'; import { UploadTarball, ReadTarball } from '@verdaccio/streams'; import { @@ -67,7 +61,7 @@ class MemoryHandler implements IPackageStorageManager { try { onWrite(pkgFileName, transformPackage(pkg), onEnd); } catch (err: any) { - return onEnd(getInternalError('error on parse the metadata')); + return onEnd(errorUtils.getInternalError('error on parse the metadata')); } }); } @@ -92,7 +86,7 @@ class MemoryHandler implements IPackageStorageManager { this.data[name] = stringifyPackage(value); return cb(null); } catch (err: any) { - return cb(getInternalError(err.message)); + return cb(errorUtils.getInternalError(err.message)); } } @@ -102,9 +96,9 @@ class MemoryHandler implements IPackageStorageManager { const isJson = typeof json === 'undefined'; try { - return cb(isJson ? getNotFound() : null, parsePackage(json)); + return cb(isJson ? errorUtils.getNotFound() : null, parsePackage(json)); } catch (err: any) { - return cb(getNotFound()); + return cb(errorUtils.getNotFound()); } } @@ -116,7 +110,7 @@ class MemoryHandler implements IPackageStorageManager { process.nextTick(function () { fs.stat(temporalName, function (fileError, stats) { if (!fileError && stats) { - return uploadStream.emit('error', getConflict()); + return uploadStream.emit('error', errorUtils.getConflict()); } try { @@ -133,7 +127,7 @@ class MemoryHandler implements IPackageStorageManager { }; uploadStream.abort = function (): void { - uploadStream.emit('error', getBadRequest('transmision aborted')); + uploadStream.emit('error', errorUtils.getBadRequest('transmision aborted')); file.end(); }; @@ -158,7 +152,7 @@ class MemoryHandler implements IPackageStorageManager { process.nextTick(function () { fs.stat(pathName, function (error, stats) { if (error && !stats) { - return readTarballStream.emit('error', getNotFound()); + return readTarballStream.emit('error', errorUtils.getNotFound()); } try { @@ -172,7 +166,7 @@ class MemoryHandler implements IPackageStorageManager { }); readTarballStream.abort = function (): void { - readStream.destroy(getBadRequest('read has been aborted')); + readStream.destroy(errorUtils.getBadRequest('read has been aborted')); }; return; } catch (err: any) { diff --git a/packages/plugins/memory/test/memory.spec.ts b/packages/plugins/memory/test/memory.spec.ts index 1d2b8ce36..23449927d 100644 --- a/packages/plugins/memory/test/memory.spec.ts +++ b/packages/plugins/memory/test/memory.spec.ts @@ -1,5 +1,5 @@ import { Logger, IPluginStorage, IPackageStorage, ILocalPackageManager } from '@verdaccio/types'; -import { getInternalError } from '@verdaccio/commons-api'; +import { errorUtils } from '@verdaccio/core'; import { ConfigMemory } from '../src/local-memory'; import MemoryHandler from '../src/memory-handler'; @@ -76,7 +76,7 @@ describe('memory unit test .', () => { const handler: IPackageStorage = localMemory.getPackageStorage(pkgName) as ILocalPackageManager; handler.savePackage(pkgName, pkgExample, (err) => { - expect(err).toEqual(getInternalError('error on parse')); + expect(err).toEqual(errorUtils.getInternalError('error on parse')); done(); }); }); @@ -146,7 +146,7 @@ describe('memory unit test .', () => { expect(handler).toBeDefined(); const onEnd = jest.fn((err) => { expect(err).not.toBeNull(); - expect(err).toEqual(getInternalError('error on parse')); + expect(err).toEqual(errorUtils.getInternalError('error on parse')); done(); }); @@ -173,7 +173,7 @@ describe('memory unit test .', () => { expect(handler).toBeDefined(); const onEnd = jest.fn((err) => { expect(err).not.toBeNull(); - expect(err).toEqual(getInternalError('some error')); + expect(err).toEqual(errorUtils.getInternalError('some error')); done(); }); @@ -187,7 +187,7 @@ describe('memory unit test .', () => { expect(json).toBeDefined(); expect(json.name).toBe(pkgExample.name); expect(callback).toBeDefined(); - callback(getInternalError('some error')); + callback(errorUtils.getInternalError('some error')); }, () => {}, // @ts-ignore @@ -206,7 +206,7 @@ describe('memory unit test .', () => { expect(handler).toBeDefined(); const onEnd = jest.fn((err) => { expect(err).not.toBeNull(); - expect(err).toEqual(getInternalError('error on parse the metadata')); + expect(err).toEqual(errorUtils.getInternalError('error on parse the metadata')); done(); }); diff --git a/packages/proxy/package.json b/packages/proxy/package.json index 40b93cd58..041913693 100644 --- a/packages/proxy/package.json +++ b/packages/proxy/package.json @@ -39,7 +39,6 @@ "build": "pnpm run build:js && pnpm run build:types" }, "dependencies": { - "@verdaccio/commons-api": "workspace:11.0.0-6-next.4", "@verdaccio/config": "workspace:6.0.0-6-next.8", "@verdaccio/core": "workspace:6.0.0-6-next.1", "@verdaccio/local-storage": "workspace:11.0.0-6-next.8", diff --git a/packages/proxy/src/up-storage.ts b/packages/proxy/src/up-storage.ts index 35fc64e38..1ab737f72 100644 --- a/packages/proxy/src/up-storage.ts +++ b/packages/proxy/src/up-storage.ts @@ -10,15 +10,18 @@ import request from 'request'; import { buildToken } from '@verdaccio/utils'; import { ReadTarball } from '@verdaccio/streams'; import { + constants, + errorUtils, + validatioUtils, + searchUtils, TOKEN_BASIC, TOKEN_BEARER, HEADERS, HTTP_STATUS, HEADER_TYPE, CHARACTER_ENCODING, -} from '@verdaccio/commons-api'; +} from '@verdaccio/core'; import { Config, Callback, Logger, UpLinkConf, IReadTarball } from '@verdaccio/types'; -import { errorUtils, validatioUtils, searchUtils } from '@verdaccio/core'; import { parseInterval } from './proxy-utils'; const LoggerApi = require('@verdaccio/logger'); @@ -358,15 +361,15 @@ class ProxyStorage implements IProxy { } else if (_.isBoolean(tokenConf.token_env) && tokenConf.token_env) { token = process.env.NPM_TOKEN; } else { - this.logger.error(errorUtils.ERROR_CODE.token_required); - this._throwErrorAuth(errorUtils.ERROR_CODE.token_required); + this.logger.error(constants.ERROR_CODE.token_required); + this._throwErrorAuth(constants.ERROR_CODE.token_required); } } else { token = process.env.NPM_TOKEN; } if (_.isNil(token)) { - this._throwErrorAuth(errorUtils.ERROR_CODE.token_required); + this._throwErrorAuth(constants.ERROR_CODE.token_required); } // define type Auth allow basic and bearer diff --git a/packages/proxy/test/headers.auth.spec.ts b/packages/proxy/test/headers.auth.spec.ts index a4cff0d51..0635e894c 100644 --- a/packages/proxy/test/headers.auth.spec.ts +++ b/packages/proxy/test/headers.auth.spec.ts @@ -1,6 +1,6 @@ import { buildToken } from '@verdaccio/utils'; -import { ERROR_CODE, TOKEN_BASIC, TOKEN_BEARER, HEADERS } from '@verdaccio/commons-api'; +import { constants, TOKEN_BASIC, TOKEN_BEARER, HEADERS } from '@verdaccio/core'; import { setup } from '@verdaccio/logger'; import { DEFAULT_REGISTRY } from '@verdaccio/config'; @@ -150,6 +150,6 @@ describe('uplink headers auth test', () => { expect(function () { fnError(); - }).toThrow(ERROR_CODE.token_required); + }).toThrow(constants.ERROR_CODE.token_required); }); }); diff --git a/packages/proxy/test/proxy.error.spec.ts b/packages/proxy/test/proxy.error.spec.ts index 052e6f404..40d60d1b7 100644 --- a/packages/proxy/test/proxy.error.spec.ts +++ b/packages/proxy/test/proxy.error.spec.ts @@ -1,8 +1,7 @@ import path from 'path'; import nock from 'nock'; import { Config, parseConfigFile } from '@verdaccio/config'; -import { ErrorCode } from '@verdaccio/utils'; -import { API_ERROR, HEADER_TYPE, HTTP_STATUS, VerdaccioError } from '@verdaccio/commons-api'; +import { API_ERROR, HEADER_TYPE, HTTP_STATUS, VerdaccioError, errorUtils } from '@verdaccio/core'; import { ProxyStorage } from '../src/up-storage'; const getConf = (name) => path.join(__dirname, '/conf', name); @@ -81,7 +80,7 @@ describe('proxy', () => { const prox1 = new ProxyStorage(defaultRequestOptions, conf); const stream = prox1.fetchTarball('https://registry.npmjs.org/jquery/-/jquery-0.0.1.tgz'); stream.on('error', (response) => { - expect(response).toEqual(ErrorCode.getNotFound(API_ERROR.NOT_FILE_UPLINK)); + expect(response).toEqual(errorUtils.getNotFound(API_ERROR.NOT_FILE_UPLINK)); done(); }); }); @@ -101,7 +100,7 @@ describe('proxy', () => { const prox1 = new ProxyStorage(defaultRequestOptions, conf); const stream = prox1.fetchTarball('https://registry.npmjs.org/jquery/-/jquery-0.0.1.tgz'); stream.on('error', (response) => { - expect(response).toEqual(ErrorCode.getInternalError(`bad uplink status code: 409`)); + expect(response).toEqual(errorUtils.getInternalError(`bad uplink status code: 409`)); done(); }); }); @@ -117,7 +116,7 @@ describe('proxy', () => { const prox1 = new ProxyStorage(defaultRequestOptions, conf); const stream = prox1.fetchTarball('https://registry.npmjs.org/jquery/-/jquery-0.0.1.tgz'); stream.on('error', (response) => { - expect(response).toEqual(ErrorCode.getInternalError(API_ERROR.CONTENT_MISMATCH)); + expect(response).toEqual(errorUtils.getInternalError(API_ERROR.CONTENT_MISMATCH)); done(); }); }); diff --git a/packages/proxy/test/proxy.metadata.ts b/packages/proxy/test/proxy.metadata.ts index 78aa28d7d..f31fb9947 100644 --- a/packages/proxy/test/proxy.metadata.ts +++ b/packages/proxy/test/proxy.metadata.ts @@ -1,8 +1,7 @@ import path from 'path'; import nock from 'nock'; import { Config, parseConfigFile } from '@verdaccio/config'; -import { ErrorCode } from '@verdaccio/utils'; -import { API_ERROR } from '@verdaccio/commons-api'; +import { API_ERROR, errorUtils } from '@verdaccio/core'; import { ProxyStorage } from '../src/up-storage'; const getConf = (name) => path.join(__dirname, '/conf', name); @@ -82,7 +81,7 @@ describe('proxy', () => { nock(domain).get('/jquery').reply(404); const prox1 = new ProxyStorage(defaultRequestOptions, conf); prox1.getRemoteMetadata('jquery', { etag: 'rev_3333' }, (error) => { - expect(error).toEqual(ErrorCode.getNotFound(API_ERROR.NOT_PACKAGE_UPLINK)); + expect(error).toEqual(errorUtils.getNotFound(API_ERROR.NOT_PACKAGE_UPLINK)); done(); }); }); diff --git a/packages/proxy/test/proxy.tarball.spec.ts b/packages/proxy/test/proxy.tarball.spec.ts index 770a5a3b7..95558fa14 100644 --- a/packages/proxy/test/proxy.tarball.spec.ts +++ b/packages/proxy/test/proxy.tarball.spec.ts @@ -1,8 +1,7 @@ import path from 'path'; import nock from 'nock'; import { Config, parseConfigFile } from '@verdaccio/config'; -import { ErrorCode } from '@verdaccio/utils'; -import { API_ERROR, HEADER_TYPE, HTTP_STATUS, VerdaccioError } from '@verdaccio/commons-api'; +import { errorUtils, API_ERROR, HEADER_TYPE, HTTP_STATUS, VerdaccioError } from '@verdaccio/core'; import { ProxyStorage } from '../src/up-storage'; const getConf = (name) => path.join(__dirname, '/conf', name); @@ -112,7 +111,7 @@ describe('proxy', () => { const prox1 = new ProxyStorage(defaultRequestOptions, conf); const stream = prox1.fetchTarball('https://registry.npmjs.org/jquery/-/jquery-0.0.1.tgz'); stream.on('error', (response) => { - expect(response).toEqual(ErrorCode.getNotFound(API_ERROR.NOT_FILE_UPLINK)); + expect(response).toEqual(errorUtils.getNotFound(API_ERROR.NOT_FILE_UPLINK)); done(); }); }); @@ -132,7 +131,7 @@ describe('proxy', () => { const prox1 = new ProxyStorage(defaultRequestOptions, conf); const stream = prox1.fetchTarball('https://registry.npmjs.org/jquery/-/jquery-0.0.1.tgz'); stream.on('error', (response) => { - expect(response).toEqual(ErrorCode.getInternalError(`bad uplink status code: 409`)); + expect(response).toEqual(errorUtils.getInternalError(`bad uplink status code: 409`)); done(); }); }); @@ -148,7 +147,7 @@ describe('proxy', () => { const prox1 = new ProxyStorage(defaultRequestOptions, conf); const stream = prox1.fetchTarball('https://registry.npmjs.org/jquery/-/jquery-0.0.1.tgz'); stream.on('error', (response) => { - expect(response).toEqual(ErrorCode.getInternalError(API_ERROR.CONTENT_MISMATCH)); + expect(response).toEqual(errorUtils.getInternalError(API_ERROR.CONTENT_MISMATCH)); done(); }); }); @@ -197,7 +196,7 @@ describe('proxy', () => { nock(domain).get('/jquery').reply(404); const prox1 = new ProxyStorage(defaultRequestOptions, conf); prox1.getRemoteMetadata('jquery', { etag: 'rev_3333' }, (error) => { - expect(error).toEqual(ErrorCode.getNotFound(API_ERROR.NOT_PACKAGE_UPLINK)); + expect(error).toEqual(errorUtils.getNotFound(API_ERROR.NOT_PACKAGE_UPLINK)); done(); }); }); diff --git a/packages/server/package.json b/packages/server/package.json index e1a48fce4..88ddf7325 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -32,7 +32,7 @@ "dependencies": { "@verdaccio/api": "workspace:6.0.0-6-next.15", "@verdaccio/auth": "workspace:6.0.0-6-next.12", - "@verdaccio/commons-api": "workspace:11.0.0-6-next.4", + "@verdaccio/core": "workspace:6.0.0-6-next.1", "@verdaccio/config": "workspace:6.0.0-6-next.8", "@verdaccio/loaders": "workspace:6.0.0-6-next.5", "@verdaccio/logger": "workspace:6.0.0-6-next.5", @@ -52,6 +52,7 @@ "@types/node": "16.9.1", "@verdaccio/mock": "workspace:6.0.0-6-next.9", "@verdaccio/proxy": "workspace:6.0.0-6-next.12", + "@verdaccio/helper": "1.0.0", "http-errors": "1.8.0", "request": "2.87.0" }, diff --git a/packages/server/src/server.ts b/packages/server/src/server.ts index ca72977c1..7dbdce453 100644 --- a/packages/server/src/server.ts +++ b/packages/server/src/server.ts @@ -9,8 +9,7 @@ import { HttpError } from 'http-errors'; import { loadPlugin } from '@verdaccio/loaders'; import { Auth } from '@verdaccio/auth'; import apiEndpoint from '@verdaccio/api'; -import { ErrorCode } from '@verdaccio/utils'; -import { API_ERROR, HTTP_STATUS } from '@verdaccio/commons-api'; +import { API_ERROR, HTTP_STATUS, errorUtils } from '@verdaccio/core'; import { Config as AppConfig } from '@verdaccio/config'; import webMiddleware from '@verdaccio/web'; @@ -103,13 +102,13 @@ const defineAPI = function (config: IConfig, storage: Storage): any { app.use(webMiddleware(config, auth, storage)); } else { app.get('/', function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer) { - next(ErrorCode.getNotFound(API_ERROR.WEB_DISABLED)); + next(errorUtils.getNotFound(API_ERROR.WEB_DISABLED)); }); } // Catch 404 app.get('/*', function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer) { - next(ErrorCode.getNotFound(API_ERROR.FILE_NOT_FOUND)); + next(errorUtils.getNotFound(API_ERROR.FILE_NOT_FOUND)); }); app.use(function ( diff --git a/packages/server/test/api/index.spec.ts b/packages/server/test/api/index.spec.ts index 4398ccf2e..4553b1cd0 100644 --- a/packages/server/test/api/index.spec.ts +++ b/packages/server/test/api/index.spec.ts @@ -2,13 +2,8 @@ import path from 'path'; import request from 'supertest'; import _ from 'lodash'; -import { - HEADERS, - HTTP_STATUS, - HEADER_TYPE, - API_MESSAGE, - TOKEN_BEARER, -} from '@verdaccio/commons-api'; +import { HEADERS, HTTP_STATUS, HEADER_TYPE, API_MESSAGE, TOKEN_BEARER } from '@verdaccio/core'; +// import { generatePackageMetadata } from '@verdaccio/helper'; import { buildToken } from '@verdaccio/utils'; import { setup, logger } from '@verdaccio/logger'; diff --git a/packages/server/test/basic/index.spec.ts b/packages/server/test/basic/index.spec.ts index 078f746d2..78caa547a 100644 --- a/packages/server/test/basic/index.spec.ts +++ b/packages/server/test/basic/index.spec.ts @@ -2,7 +2,7 @@ import path from 'path'; import express from 'express'; import request from 'request'; -import { API_ERROR } from '@verdaccio/commons-api'; +import { API_ERROR } from '@verdaccio/core'; import { parseConfigFile } from '@verdaccio/config'; import { setup } from '@verdaccio/logger'; diff --git a/packages/server/test/jwt/index.spec.ts b/packages/server/test/jwt/index.spec.ts index 7a4e8322f..ec8b05509 100644 --- a/packages/server/test/jwt/index.spec.ts +++ b/packages/server/test/jwt/index.spec.ts @@ -8,7 +8,7 @@ import { TOKEN_BEARER, TOKEN_BASIC, API_ERROR, -} from '@verdaccio/commons-api'; +} from '@verdaccio/core'; import { mockServer, generateRamdonStorage } from '@verdaccio/mock'; import { buildUserBuffer, buildToken } from '@verdaccio/utils'; import { diff --git a/packages/server/test/package-access/index.spec.ts b/packages/server/test/package-access/index.spec.ts index e316fd4f1..01bd1d355 100644 --- a/packages/server/test/package-access/index.spec.ts +++ b/packages/server/test/package-access/index.spec.ts @@ -5,7 +5,7 @@ import { setup, logger } from '@verdaccio/logger'; setup([]); -import { HEADERS, HTTP_STATUS } from '@verdaccio/commons-api'; +import { HEADERS, HTTP_STATUS } from '@verdaccio/core'; import { generateRamdonStorage, mockServer, configExample, DOMAIN_SERVERS } from '@verdaccio/mock'; import endPointAPI from '../../src'; diff --git a/packages/server/test/profile/index.spec.ts b/packages/server/test/profile/index.spec.ts index 69e58e80e..5c5b99a9b 100644 --- a/packages/server/test/profile/index.spec.ts +++ b/packages/server/test/profile/index.spec.ts @@ -2,7 +2,7 @@ import path from 'path'; import request from 'supertest'; import { mockServer } from '@verdaccio/mock'; -import { API_ERROR, HTTP_STATUS, SUPPORT_ERRORS } from '@verdaccio/commons-api'; +import { API_ERROR, HTTP_STATUS, SUPPORT_ERRORS } from '@verdaccio/core'; import { setup, logger } from '@verdaccio/logger'; import { diff --git a/packages/server/test/storage/index.spec.ts b/packages/server/test/storage/index.spec.ts index 97f7210a0..5779e91d6 100644 --- a/packages/server/test/storage/index.spec.ts +++ b/packages/server/test/storage/index.spec.ts @@ -5,7 +5,7 @@ import { Config as AppConfig } from '@verdaccio/config'; import { Storage } from '@verdaccio/store'; import { Config } from '@verdaccio/types'; -import { API_ERROR, HTTP_STATUS } from '@verdaccio/commons-api'; +import { API_ERROR, HTTP_STATUS } from '@verdaccio/core'; import { mockServer, configExample, DOMAIN_SERVERS, generateRamdonStorage } from '@verdaccio/mock'; import { setup, logger } from '@verdaccio/logger'; diff --git a/packages/server/test/token/index.spec.ts b/packages/server/test/token/index.spec.ts index b5c4fbc73..5ba992c23 100644 --- a/packages/server/test/token/index.spec.ts +++ b/packages/server/test/token/index.spec.ts @@ -9,7 +9,7 @@ import { TOKEN_BEARER, API_ERROR, SUPPORT_ERRORS, -} from '@verdaccio/commons-api'; +} from '@verdaccio/core'; import { buildToken } from '@verdaccio/utils'; import { diff --git a/packages/server/test/web/index.spec.ts b/packages/server/test/web/index.spec.ts index 9e567f4f7..8dedcfe21 100644 --- a/packages/server/test/web/index.spec.ts +++ b/packages/server/test/web/index.spec.ts @@ -1,7 +1,7 @@ import path from 'path'; import request from 'supertest'; -import { HEADERS, HTTP_STATUS, HEADER_TYPE, DIST_TAGS } from '@verdaccio/commons-api'; +import { HEADERS, HTTP_STATUS, HEADER_TYPE, DIST_TAGS } from '@verdaccio/core'; import { mockServer, DOMAIN_SERVERS, configExample, generateRamdonStorage } from '@verdaccio/mock'; diff --git a/packages/store/package.json b/packages/store/package.json index ad64903b4..8ce8fe099 100644 --- a/packages/store/package.json +++ b/packages/store/package.json @@ -39,7 +39,6 @@ "build": "pnpm run build:js && pnpm run build:types" }, "dependencies": { - "@verdaccio/commons-api": "workspace:11.0.0-6-next.4", "@verdaccio/config": "workspace:6.0.0-6-next.8", "@verdaccio/core": "workspace:6.0.0-6-next.1", "@verdaccio/loaders": "workspace:6.0.0-6-next.5", diff --git a/packages/store/src/local-storage.ts b/packages/store/src/local-storage.ts index 34631a328..203b4410a 100644 --- a/packages/store/src/local-storage.ts +++ b/packages/store/src/local-storage.ts @@ -4,9 +4,9 @@ import { PassThrough } from 'stream'; import _ from 'lodash'; import buildDebug from 'debug'; -import { ErrorCode, isObject, getLatestVersion } from '@verdaccio/utils'; -import { searchUtils, pluginUtils, pkgUtils, validatioUtils } from '@verdaccio/core'; -import { API_ERROR, DIST_TAGS, HTTP_STATUS, SUPPORT_ERRORS, USERS } from '@verdaccio/commons-api'; +import { isObject, getLatestVersion } from '@verdaccio/utils'; +import { errorUtils, searchUtils, pluginUtils, pkgUtils, validatioUtils } from '@verdaccio/core'; +import { API_ERROR, DIST_TAGS, HTTP_STATUS, SUPPORT_ERRORS, USERS } from '@verdaccio/core'; import { createTarballHash } from '@verdaccio/utils'; import { loadPlugin } from '@verdaccio/loaders'; import LocalDatabase from '@verdaccio/local-storage'; @@ -29,7 +29,7 @@ import { StringValue, StorageUpdateCallback, } from '@verdaccio/types'; -import { VerdaccioError } from '@verdaccio/commons-api'; +import { VerdaccioError } from '@verdaccio/core'; import { generatePackageTemplate, @@ -116,7 +116,7 @@ class LocalStorage { if (_.isNil(storage)) { debug(`storage is missing for %o package cannot be added`, name); - return callback(ErrorCode.getNotFound('this package cannot be added')); + return callback(errorUtils.getNotFound('this package cannot be added')); } storage.createPackage(name, generatePackageTemplate(name), (err) => { @@ -125,7 +125,7 @@ class LocalStorage { (err.code === STORAGE.FILE_EXIST_ERROR || err.code === HTTP_STATUS.CONFLICT) ) { debug(`error on creating a package for %o with error %o`, name, err.message); - return callback(ErrorCode.getConflict()); + return callback(errorUtils.getConflict()); } const latest = getLatestVersion(pkg); @@ -147,7 +147,7 @@ class LocalStorage { const storage: any = this._getLocalStorage(name); if (_.isNil(storage)) { - throw ErrorCode.getNotFound(); + throw errorUtils.getNotFound(); } return new Promise((resolve, reject) => { @@ -155,7 +155,7 @@ class LocalStorage { if (_.isNil(err) === false) { if (err.code === STORAGE.NO_SUCH_FILE_ERROR || err.code === HTTP_STATUS.NOT_FOUND) { debug(`error on not found %o with error %o`, name, err.message); - return reject(ErrorCode.getNotFound()); + return reject(errorUtils.getNotFound()); } return reject(err); } @@ -180,7 +180,7 @@ class LocalStorage { resolve(); } catch (err: any) { this.logger.error({ err }, 'removed package has failed @{err.message}'); - throw ErrorCode.getBadData(err.message); + throw errorUtils.getBadData(err.message); } }); }); @@ -312,7 +312,7 @@ class LocalStorage { const hasVersion = data.versions[version] != null; if (hasVersion) { debug('%s version %s already exists', name, version); - return cb(ErrorCode.getConflict()); + return cb(errorUtils.getConflict()); } // if uploaded tarball has a different shasum, it's very likely that we @@ -329,7 +329,7 @@ class LocalStorage { const errorMessage = `shasum error, ` + `${data._attachments[tarball].shasum} != ${metadata.dist.shasum}`; - return cb(ErrorCode.getBadRequest(errorMessage)); + return cb(errorUtils.getBadRequest(errorMessage)); } } @@ -359,7 +359,7 @@ class LocalStorage { await this.storagePlugin.add(name); cb(); } catch (err: any) { - cb(ErrorCode.getBadData(err.message)); + cb(errorUtils.getBadData(err.message)); } }, callback @@ -386,7 +386,7 @@ class LocalStorage { } if (_.isNil(data.versions[tags[tag]])) { - return cb(ErrorCode.getNotFound(API_ERROR.VERSION_NOT_EXIST)); + return cb(errorUtils.getNotFound(API_ERROR.VERSION_NOT_EXIST)); } const version: string = tags[tag]; tagVersion(data, version, tag); @@ -418,7 +418,7 @@ class LocalStorage { !validatioUtils.isObject(incomingPkg[DIST_TAGS]) ) { debug(`change package bad data for %o`, name); - return callback(ErrorCode.getBadData()); + return callback(errorUtils.getBadData()); } debug(`change package udapting package for %o`, name); @@ -495,7 +495,7 @@ class LocalStorage { delete data._attachments[filename]; cb(null); } else { - cb(ErrorCode.getNotFound('no such file available')); + cb(errorUtils.getNotFound('no such file available')); } }, (err: VerdaccioError) => { @@ -518,7 +518,7 @@ class LocalStorage { return callback(null); }); } else { - callback(ErrorCode.getInternalError()); + callback(errorUtils.getInternalError()); } } ); @@ -555,7 +555,7 @@ class LocalStorage { if (name === PROTO_NAME) { process.nextTick((): void => { - uploadStream.emit('error', ErrorCode.getForbidden()); + uploadStream.emit('error', errorUtils.getForbidden()); }); return uploadStream; } @@ -573,7 +573,7 @@ class LocalStorage { writeStream.on('error', (err) => { // @ts-ignore if (err.code === STORAGE.FILE_EXIST_ERROR || err.code === HTTP_STATUS.CONFLICT) { - uploadStream.emit('error', ErrorCode.getConflict()); + uploadStream.emit('error', errorUtils.getConflict()); uploadStream.abort(); // @ts-ignore } else if (err.code === STORAGE.NO_SUCH_FILE_ERROR || err.code === HTTP_STATUS.NOT_FOUND) { @@ -623,7 +623,7 @@ class LocalStorage { uploadStream.done = function (): void { if (!length) { - uploadStream.emit('error', ErrorCode.getBadData('refusing to accept zero-length file')); + uploadStream.emit('error', errorUtils.getBadData('refusing to accept zero-length file')); writeStream.abort(); } else { writeStream.done(); @@ -662,7 +662,7 @@ class LocalStorage { const stream: IReadTarball = new ReadTarball({}); process.nextTick((): void => { - stream.emit('error', ErrorCode.getNotFound('no such file available')); + stream.emit('error', errorUtils.getNotFound('no such file available')); }); return stream; } @@ -677,7 +677,7 @@ class LocalStorage { private _streamSuccessReadTarBall(storage: any, filename: string): IReadTarball { const stream: IReadTarball = new ReadTarball({}); const readTarballStream = storage.readTarball(filename); - const e404 = ErrorCode.getNotFound; + const e404 = errorUtils.getNotFound; stream.abort = function (): void { if (_.isNil(readTarballStream) === false) { @@ -717,7 +717,7 @@ class LocalStorage { const storage: IPackageStorage = this._getLocalStorage(name); debug('get package metadata for %o', name); if (typeof storage === 'undefined') { - return callback(ErrorCode.getNotFound()); + return callback(errorUtils.getNotFound()); } this._readPackage(name, storage, callback); @@ -797,7 +797,7 @@ class LocalStorage { if (err) { if (err.code === STORAGE.NO_SUCH_FILE_ERROR || err.code === HTTP_STATUS.NOT_FOUND) { debug('package %s not found', name); - return callback(ErrorCode.getNotFound()); + return callback(errorUtils.getNotFound()); } return callback(this._internalError(err, STORAGE.PACKAGE_FILE_NAME, 'error reading')); } @@ -847,7 +847,7 @@ class LocalStorage { private _internalError(err: string, file: string, message: string): VerdaccioError { this.logger.error({ err: err, file: file }, `${message} @{file}: @{!err.message}`); - return ErrorCode.getInternalError(); + return errorUtils.getInternalError(); } /** @@ -864,7 +864,7 @@ class LocalStorage { const storage: IPackageStorage = this._getLocalStorage(name); if (!storage) { - return callback(ErrorCode.getNotFound()); + return callback(errorUtils.getNotFound()); } storage.updatePackage( @@ -984,7 +984,7 @@ class LocalStorage { public saveToken(token: Token): Promise { if (_.isFunction(this.storagePlugin.saveToken) === false) { return Promise.reject( - ErrorCode.getCode(HTTP_STATUS.SERVICE_UNAVAILABLE, SUPPORT_ERRORS.PLUGIN_MISSING_INTERFACE) + errorUtils.getCode(HTTP_STATUS.SERVICE_UNAVAILABLE, SUPPORT_ERRORS.PLUGIN_MISSING_INTERFACE) ); } @@ -994,7 +994,7 @@ class LocalStorage { public deleteToken(user: string, tokenKey: string): Promise { if (_.isFunction(this.storagePlugin.deleteToken) === false) { return Promise.reject( - ErrorCode.getCode(HTTP_STATUS.SERVICE_UNAVAILABLE, SUPPORT_ERRORS.PLUGIN_MISSING_INTERFACE) + errorUtils.getCode(HTTP_STATUS.SERVICE_UNAVAILABLE, SUPPORT_ERRORS.PLUGIN_MISSING_INTERFACE) ); } @@ -1004,7 +1004,7 @@ class LocalStorage { public readTokens(filter: TokenFilter): Promise { if (_.isFunction(this.storagePlugin.readTokens) === false) { return Promise.reject( - ErrorCode.getCode(HTTP_STATUS.SERVICE_UNAVAILABLE, SUPPORT_ERRORS.PLUGIN_MISSING_INTERFACE) + errorUtils.getCode(HTTP_STATUS.SERVICE_UNAVAILABLE, SUPPORT_ERRORS.PLUGIN_MISSING_INTERFACE) ); } diff --git a/packages/store/src/search.ts b/packages/store/src/search.ts index 04641a705..fa1d274f2 100644 --- a/packages/store/src/search.ts +++ b/packages/store/src/search.ts @@ -9,7 +9,7 @@ import buildDebug from 'debug'; import { logger } from '@verdaccio/logger'; import { Version } from '@verdaccio/types'; import { IProxy, ProxyList, ProxySearchParams } from '@verdaccio/proxy'; -import { VerdaccioError } from '@verdaccio/commons-api'; +import { VerdaccioError } from '@verdaccio/core'; import { searchUtils, errorUtils } from '@verdaccio/core'; import { LocalStorage } from './local-storage'; import { Storage } from './storage'; diff --git a/packages/store/src/storage-utils.ts b/packages/store/src/storage-utils.ts index bb6bc41b3..e67d2dc68 100644 --- a/packages/store/src/storage-utils.ts +++ b/packages/store/src/storage-utils.ts @@ -1,11 +1,11 @@ import _ from 'lodash'; import semver from 'semver'; -import { ErrorCode, normalizeDistTags, generateRandomHexString, isNil } from '@verdaccio/utils'; +import { normalizeDistTags, generateRandomHexString, isNil } from '@verdaccio/utils'; import { Package, Version, Author, StringValue } from '@verdaccio/types'; -import { pkgUtils, validatioUtils } from '@verdaccio/core'; -import { API_ERROR, HTTP_STATUS, DIST_TAGS, USERS } from '@verdaccio/commons-api'; +import { pkgUtils, validatioUtils, errorUtils } from '@verdaccio/core'; +import { API_ERROR, HTTP_STATUS, DIST_TAGS, USERS } from '@verdaccio/core'; import { SearchInstance } from './search'; import { LocalStorage } from './local-storage'; @@ -155,7 +155,7 @@ export function checkPackageLocal(name: string, localStorage: LocalStorage): Pro return reject(err); } if (results) { - return reject(ErrorCode.getConflict(API_ERROR.PACKAGE_EXIST)); + return reject(errorUtils.getConflict(API_ERROR.PACKAGE_EXIST)); } return resolve(); }); @@ -193,7 +193,7 @@ export function checkPackageRemote( // checking package exist already if (isNil(packageJsonLocal) === false) { - return reject(ErrorCode.getConflict(API_ERROR.PACKAGE_EXIST)); + return reject(errorUtils.getConflict(API_ERROR.PACKAGE_EXIST)); } for (let errorItem = 0; errorItem < upLinksErrors.length; errorItem++) { @@ -205,7 +205,7 @@ export function checkPackageRemote( return resolve(); } - return reject(ErrorCode.getServiceUnavailable(API_ERROR.UPLINK_OFFLINE_PUBLISH)); + return reject(errorUtils.getServiceUnavailable(API_ERROR.UPLINK_OFFLINE_PUBLISH)); } } } diff --git a/packages/store/src/storage.ts b/packages/store/src/storage.ts index cea26809e..4e229cf93 100644 --- a/packages/store/src/storage.ts +++ b/packages/store/src/storage.ts @@ -5,9 +5,9 @@ import buildDebug from 'debug'; import semver from 'semver'; import { ProxyStorage } from '@verdaccio/proxy'; -import { API_ERROR, HTTP_STATUS, DIST_TAGS } from '@verdaccio/commons-api'; +import { errorUtils, API_ERROR, HTTP_STATUS, DIST_TAGS } from '@verdaccio/core'; import { ReadTarball } from '@verdaccio/streams'; -import { ErrorCode, normalizeDistTags } from '@verdaccio/utils'; +import { normalizeDistTags } from '@verdaccio/utils'; import { ProxyList, IProxy } from '@verdaccio/proxy'; import { IReadTarball, @@ -503,7 +503,7 @@ class Storage { } if (err || !upLinkResponse) { - return cb(null, [err || ErrorCode.getInternalError('no data')]); + return cb(null, [err || errorUtils.getInternalError('no data')]); } try { @@ -570,9 +570,9 @@ class Storage { } if (uplinkTimeoutError) { - return callback(ErrorCode.getServiceUnavailable(), null, upLinksErrors); + return callback(errorUtils.getServiceUnavailable(), null, upLinksErrors); } - return callback(ErrorCode.getNotFound(API_ERROR.NO_PACKAGE), null, upLinksErrors); + return callback(errorUtils.getNotFound(API_ERROR.NO_PACKAGE), null, upLinksErrors); } if (upLinks.length === 0) { diff --git a/packages/store/test/local-storage.spec.ts b/packages/store/test/local-storage.spec.ts index 6d23b41cb..773a03f23 100644 --- a/packages/store/test/local-storage.spec.ts +++ b/packages/store/test/local-storage.spec.ts @@ -8,8 +8,8 @@ import { configExample, generateNewVersion } from '@verdaccio/mock'; const readMetadata = (fileName = 'metadata') => readFile(`../fixtures/${fileName}`).toString(); import { Config, MergeTags, Package } from '@verdaccio/types'; -import { API_ERROR, HTTP_STATUS, DIST_TAGS } from '@verdaccio/commons-api'; -import { VerdaccioError } from '@verdaccio/commons-api'; +import { API_ERROR, HTTP_STATUS, DIST_TAGS } from '@verdaccio/core'; +import { VerdaccioError } from '@verdaccio/core'; import { LocalStorage, PROTO_NAME } from '../src/local-storage'; import { generatePackageTemplate } from '../src/storage-utils'; import { readFile } from './fixtures/test.utils'; diff --git a/packages/store/test/storage-utils.spec.ts b/packages/store/test/storage-utils.spec.ts index cffbb4c81..1e9a84342 100644 --- a/packages/store/test/storage-utils.spec.ts +++ b/packages/store/test/storage-utils.spec.ts @@ -1,6 +1,6 @@ import assert from 'assert'; import { Package } from '@verdaccio/types'; -import { DIST_TAGS } from '@verdaccio/commons-api'; +import { DIST_TAGS } from '@verdaccio/core'; import { normalizePackage, mergeUplinkTimeIntoLocal, STORAGE } from '../src/storage-utils'; import { tagVersion } from '../src/storage-utils'; diff --git a/packages/core/commons-api/.babelrc b/packages/tools/helpers/.babelrc similarity index 100% rename from packages/core/commons-api/.babelrc rename to packages/tools/helpers/.babelrc diff --git a/packages/core/commons-api/.eslintignore b/packages/tools/helpers/.eslintignore similarity index 100% rename from packages/core/commons-api/.eslintignore rename to packages/tools/helpers/.eslintignore diff --git a/packages/core/commons-api/.gitignore b/packages/tools/helpers/.gitignore similarity index 100% rename from packages/core/commons-api/.gitignore rename to packages/tools/helpers/.gitignore diff --git a/packages/core/commons-api/CHANGELOG.md b/packages/tools/helpers/CHANGELOG.md similarity index 100% rename from packages/core/commons-api/CHANGELOG.md rename to packages/tools/helpers/CHANGELOG.md diff --git a/packages/core/commons-api/LICENSE b/packages/tools/helpers/LICENSE similarity index 100% rename from packages/core/commons-api/LICENSE rename to packages/tools/helpers/LICENSE diff --git a/packages/tools/helpers/package.json b/packages/tools/helpers/package.json new file mode 100644 index 000000000..244f1cdd7 --- /dev/null +++ b/packages/tools/helpers/package.json @@ -0,0 +1,25 @@ +{ + "name": "@verdaccio/helper", + "version": "1.0.0", + "private": true, + "description": "test helpers", + "author": "Juan Picado ", + "license": "MIT", + "homepage": "https://verdaccio.org", + "main": "build/index.js", + "types": "build/index.d.ts", + "files": [ + "build" + ], + "devDependencies": { + "@verdaccio/types": "workspace:11.0.0-6-next.8" + }, + "scripts": { + "clean": "rimraf ./build", + "type-check": "tsc --noEmit -p tsconfig.build.json", + "build:types": "tsc --emitDeclarationOnly -p tsconfig.build.json", + "build:js": "babel src/ --out-dir build/ --copy-files --extensions \".ts,.tsx\" --source-maps", + "watch": "pnpm build:js -- --watch", + "build": "pnpm run build:js && pnpm run build:types" + } +} diff --git a/packages/core/commons-api/src/helpers/pkg.ts b/packages/tools/helpers/src/index.ts similarity index 100% rename from packages/core/commons-api/src/helpers/pkg.ts rename to packages/tools/helpers/src/index.ts diff --git a/packages/core/commons-api/tsconfig.build.json b/packages/tools/helpers/tsconfig.build.json similarity index 77% rename from packages/core/commons-api/tsconfig.build.json rename to packages/tools/helpers/tsconfig.build.json index 79f1f81e0..7cefab588 100644 --- a/packages/core/commons-api/tsconfig.build.json +++ b/packages/tools/helpers/tsconfig.build.json @@ -4,6 +4,6 @@ "rootDir": "./src", "outDir": "./build" }, - "include": ["src/**/*"], + "include": ["src/**/*.ts", "types/*.d.ts"], "exclude": ["src/**/*.test.ts"] } diff --git a/packages/core/commons-api/tsconfig.json b/packages/tools/helpers/tsconfig.json similarity index 73% rename from packages/core/commons-api/tsconfig.json rename to packages/tools/helpers/tsconfig.json index aa2b9fa6a..cebb0c257 100644 --- a/packages/core/commons-api/tsconfig.json +++ b/packages/tools/helpers/tsconfig.json @@ -6,6 +6,5 @@ "composite": true, "declaration": true }, - "include": ["src/**/*.ts"], - "exclude": ["src/**/*.test.ts"] + "include": ["src/**/*.ts"] } diff --git a/packages/utils/package.json b/packages/utils/package.json index 1d9f80b08..eafadf580 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -30,7 +30,7 @@ "npm": ">=6" }, "dependencies": { - "@verdaccio/commons-api": "workspace:11.0.0-6-next.4", + "@verdaccio/core": "workspace:6.0.0-6-next.1", "minimatch": "3.0.4", "semver": "7.3.5" }, diff --git a/packages/utils/src/auth-utils.ts b/packages/utils/src/auth-utils.ts index 97fd42d34..ac943e513 100644 --- a/packages/utils/src/auth-utils.ts +++ b/packages/utils/src/auth-utils.ts @@ -1,4 +1,4 @@ -import { DEFAULT_MIN_LIMIT_PASSWORD } from '@verdaccio/commons-api'; +import { DEFAULT_MIN_LIMIT_PASSWORD } from '@verdaccio/core'; export interface CookieSessionToken { expires: Date; diff --git a/packages/utils/src/utils.ts b/packages/utils/src/utils.ts index 5af531c8b..3cb470da5 100644 --- a/packages/utils/src/utils.ts +++ b/packages/utils/src/utils.ts @@ -2,19 +2,7 @@ import assert from 'assert'; import _ from 'lodash'; import semver from 'semver'; import { Package, Version, Author } from '@verdaccio/types'; -import { - DIST_TAGS, - DEFAULT_USER, - getConflict, - getBadData, - getBadRequest, - getInternalError, - getUnauthorized, - getForbidden, - getServiceUnavailable, - getNotFound, - getCode, -} from '@verdaccio/commons-api'; +import { DIST_TAGS, DEFAULT_USER } from '@verdaccio/core'; /** * From normalize-package-data/lib/fixer.js @@ -190,18 +178,6 @@ export function getLatestVersion(pkgInfo: Package): string { return pkgInfo[DIST_TAGS].latest; } -export const ErrorCode = { - getConflict, - getBadData, - getBadRequest, - getInternalError, - getUnauthorized, - getForbidden, - getServiceUnavailable, - getNotFound, - getCode, -}; - export function buildToken(type: string, token: string): string { return `${_.capitalize(type)} ${token}`; } diff --git a/packages/utils/test/utils.spec.ts b/packages/utils/test/utils.spec.ts index 13830c34c..fca2b24ce 100644 --- a/packages/utils/test/utils.spec.ts +++ b/packages/utils/test/utils.spec.ts @@ -1,12 +1,5 @@ -import { DIST_TAGS, DEFAULT_USER } from '@verdaccio/commons-api'; -import { - validateName, - validatePackage, - validateMetadata, - getVersion, - normalizeDistTags, - formatAuthor, -} from '../src/index'; +import { DIST_TAGS, DEFAULT_USER } from '@verdaccio/core'; +import { validateMetadata, getVersion, normalizeDistTags, formatAuthor } from '../src/index'; describe('Utilities', () => { const metadata: any = { diff --git a/packages/verdaccio/package.json b/packages/verdaccio/package.json index 4e0a87102..33d7853a1 100644 --- a/packages/verdaccio/package.json +++ b/packages/verdaccio/package.json @@ -49,7 +49,7 @@ }, "devDependencies": { "@verdaccio/auth": "workspace:6.0.0-6-next.12", - "@verdaccio/commons-api": "workspace:11.0.0-6-next.4", + "@verdaccio/core": "workspace:6.0.0-6-next.1", "@verdaccio/config": "workspace:6.0.0-6-next.8", "@verdaccio/store": "workspace:6.0.0-6-next.13", "fastify": "3.20.2" diff --git a/packages/verdaccio/test/functional/basic/basic.ts b/packages/verdaccio/test/functional/basic/basic.ts index 3e61ece27..24e470c64 100644 --- a/packages/verdaccio/test/functional/basic/basic.ts +++ b/packages/verdaccio/test/functional/basic/basic.ts @@ -1,7 +1,7 @@ import fs from 'fs'; import path from 'path'; import { createTarballHash } from '@verdaccio/utils'; -import { HTTP_STATUS, DIST_TAGS } from '@verdaccio/commons-api'; +import { HTTP_STATUS, DIST_TAGS } from '@verdaccio/core'; import { CREDENTIALS, diff --git a/packages/verdaccio/test/functional/package/access.ts b/packages/verdaccio/test/functional/package/access.ts index ee818ec1f..99f66a30d 100644 --- a/packages/verdaccio/test/functional/package/access.ts +++ b/packages/verdaccio/test/functional/package/access.ts @@ -1,5 +1,5 @@ import { buildToken } from '@verdaccio/utils'; -import { API_ERROR, HTTP_STATUS, TOKEN_BASIC } from '@verdaccio/commons-api'; +import { API_ERROR, HTTP_STATUS, TOKEN_BASIC } from '@verdaccio/core'; import { CREDENTIALS } from '../config.functional'; import fixturePkg from '../fixtures/package'; diff --git a/packages/verdaccio/test/functional/package/gzip.ts b/packages/verdaccio/test/functional/package/gzip.ts index 5b77b62e3..44b054b9c 100644 --- a/packages/verdaccio/test/functional/package/gzip.ts +++ b/packages/verdaccio/test/functional/package/gzip.ts @@ -1,6 +1,6 @@ import zlib from 'zlib'; import { readFile } from '../lib/test.utils'; -import { HEADER_TYPE, HEADERS, HTTP_STATUS, CHARACTER_ENCODING } from '@verdaccio/commons-api'; +import { HEADER_TYPE, HEADERS, HTTP_STATUS, CHARACTER_ENCODING } from '@verdaccio/core'; export default function (server, express) { const PKG_NAME = 'testexp_gzip'; diff --git a/packages/verdaccio/test/functional/package/scoped.ts b/packages/verdaccio/test/functional/package/scoped.ts index 2f5479b71..dc0dddfc4 100644 --- a/packages/verdaccio/test/functional/package/scoped.ts +++ b/packages/verdaccio/test/functional/package/scoped.ts @@ -1,8 +1,8 @@ import { DOMAIN_SERVERS, PORT_SERVER_1, PORT_SERVER_2 } from '../config.functional'; import { generateSha } from '../lib/test.utils'; -import { HEADERS, HTTP_STATUS } from '@verdaccio/commons-api'; -import { DIST_TAGS } from '@verdaccio/commons-api'; +import { HEADERS, HTTP_STATUS } from '@verdaccio/core'; +import { DIST_TAGS } from '@verdaccio/core'; export default function (server, server2) { const SCOPE = '@test/scoped'; diff --git a/packages/verdaccio/test/functional/performance/race.ts b/packages/verdaccio/test/functional/performance/race.ts index 175d99c99..8af7eb6f3 100644 --- a/packages/verdaccio/test/functional/performance/race.ts +++ b/packages/verdaccio/test/functional/performance/race.ts @@ -1,5 +1,5 @@ import async from 'async'; -import { HTTP_STATUS } from '@verdaccio/commons-api'; +import { HTTP_STATUS } from '@verdaccio/core'; let okTotalSum = 0; import racePkg from '../fixtures/package'; diff --git a/packages/verdaccio/test/functional/plugins/auth.ts b/packages/verdaccio/test/functional/plugins/auth.ts index 59cb0b705..bb3e48514 100644 --- a/packages/verdaccio/test/functional/plugins/auth.ts +++ b/packages/verdaccio/test/functional/plugins/auth.ts @@ -1,4 +1,4 @@ -import { HTTP_STATUS, API_ERROR } from '@verdaccio/commons-api'; +import { HTTP_STATUS, API_ERROR } from '@verdaccio/core'; export default function (server2) { // credentials diff --git a/packages/verdaccio/test/functional/plugins/middleware.ts b/packages/verdaccio/test/functional/plugins/middleware.ts index 8cdd7e7c6..7f25ee560 100644 --- a/packages/verdaccio/test/functional/plugins/middleware.ts +++ b/packages/verdaccio/test/functional/plugins/middleware.ts @@ -1,4 +1,4 @@ -import { HTTP_STATUS } from '@verdaccio/commons-api'; +import { HTTP_STATUS } from '@verdaccio/core'; export default function (server2) { describe('test plugin middlewares', () => { diff --git a/packages/verdaccio/test/functional/readme/readme.ts b/packages/verdaccio/test/functional/readme/readme.ts index c485ff2b0..eece64113 100644 --- a/packages/verdaccio/test/functional/readme/readme.ts +++ b/packages/verdaccio/test/functional/readme/readme.ts @@ -1,4 +1,4 @@ -import { HTTP_STATUS } from '@verdaccio/commons-api'; +import { HTTP_STATUS } from '@verdaccio/core'; import pkgReadmeJSON from './pkg-readme.json'; import pkgNoReadmeJSON from './pkg-no-readme.json'; diff --git a/packages/verdaccio/test/functional/sanity/incomplete.ts b/packages/verdaccio/test/functional/sanity/incomplete.ts index f48a7f127..1b0d7e435 100644 --- a/packages/verdaccio/test/functional/sanity/incomplete.ts +++ b/packages/verdaccio/test/functional/sanity/incomplete.ts @@ -1,4 +1,4 @@ -import { API_ERROR, HEADER_TYPE, HTTP_STATUS } from '@verdaccio/commons-api'; +import { API_ERROR, HEADER_TYPE, HTTP_STATUS } from '@verdaccio/core'; import { DOMAIN_SERVERS, PORT_SERVER_APP } from '../config.functional'; diff --git a/packages/verdaccio/test/functional/sanity/mirror.ts b/packages/verdaccio/test/functional/sanity/mirror.ts index 807537618..54cb370dc 100644 --- a/packages/verdaccio/test/functional/sanity/mirror.ts +++ b/packages/verdaccio/test/functional/sanity/mirror.ts @@ -1,4 +1,4 @@ -import { API_MESSAGE, HTTP_STATUS } from '@verdaccio/commons-api'; +import { API_MESSAGE, HTTP_STATUS } from '@verdaccio/core'; import generatePkg from '../fixtures/package'; import { readFile } from '../lib/test.utils'; diff --git a/packages/verdaccio/test/functional/sanity/nullstorage.ts b/packages/verdaccio/test/functional/sanity/nullstorage.ts index a4f03b294..85b67e778 100644 --- a/packages/verdaccio/test/functional/sanity/nullstorage.ts +++ b/packages/verdaccio/test/functional/sanity/nullstorage.ts @@ -1,6 +1,5 @@ import { createTarballHash } from '@verdaccio/utils'; -import { API_ERROR, HTTP_STATUS } from '@verdaccio/commons-api'; -import { DIST_TAGS } from '@verdaccio/commons-api'; +import { DIST_TAGS, API_ERROR, HTTP_STATUS } from '@verdaccio/core'; import { DOMAIN_SERVERS, PORT_SERVER_1, TARBALL } from '../config.functional'; import generatePkg from '../fixtures/package'; diff --git a/packages/verdaccio/test/functional/sanity/racycrash.ts b/packages/verdaccio/test/functional/sanity/racycrash.ts index d5f25a194..00ec9166e 100644 --- a/packages/verdaccio/test/functional/sanity/racycrash.ts +++ b/packages/verdaccio/test/functional/sanity/racycrash.ts @@ -1,5 +1,5 @@ import { DOMAIN_SERVERS, PORT_SERVER_APP } from '../config.functional'; -import { API_ERROR, HEADER_TYPE, HTTP_STATUS } from '@verdaccio/commons-api'; +import { API_ERROR, HEADER_TYPE, HTTP_STATUS } from '@verdaccio/core'; export default function (server, express) { describe('shoul test for unexpected client hangs', () => { diff --git a/packages/verdaccio/test/functional/sanity/security.ts b/packages/verdaccio/test/functional/sanity/security.ts index abc1325c8..800dc4333 100644 --- a/packages/verdaccio/test/functional/sanity/security.ts +++ b/packages/verdaccio/test/functional/sanity/security.ts @@ -1,5 +1,5 @@ import _ from 'lodash'; -import { HTTP_STATUS } from '@verdaccio/commons-api'; +import { HTTP_STATUS } from '@verdaccio/core'; export default function (server) { describe('should test security on endpoints', () => { diff --git a/packages/verdaccio/test/functional/scenarios/gh29.ts b/packages/verdaccio/test/functional/scenarios/gh29.ts index 40c649ff1..85dee1fc8 100644 --- a/packages/verdaccio/test/functional/scenarios/gh29.ts +++ b/packages/verdaccio/test/functional/scenarios/gh29.ts @@ -1,6 +1,6 @@ import fs from 'fs'; import path from 'path'; -import { HTTP_STATUS } from '@verdaccio/commons-api'; +import { HTTP_STATUS } from '@verdaccio/core'; import { createTarballHash } from '@verdaccio/utils'; import { TARBALL } from '../config.functional'; diff --git a/packages/verdaccio/test/functional/search/simple.search.ts b/packages/verdaccio/test/functional/search/simple.search.ts index 2de5065e4..6fa856bde 100644 --- a/packages/verdaccio/test/functional/search/simple.search.ts +++ b/packages/verdaccio/test/functional/search/simple.search.ts @@ -1,4 +1,4 @@ -import { API_MESSAGE, HTTP_STATUS } from '@verdaccio/commons-api'; +import { API_MESSAGE, HTTP_STATUS } from '@verdaccio/core'; import pkgExample from './search.json'; export default function (server, server2, express) { diff --git a/packages/verdaccio/test/functional/tags/addtag.ts b/packages/verdaccio/test/functional/tags/addtag.ts index 41e4046a5..581f512a4 100644 --- a/packages/verdaccio/test/functional/tags/addtag.ts +++ b/packages/verdaccio/test/functional/tags/addtag.ts @@ -1,4 +1,4 @@ -import { API_ERROR, HTTP_STATUS, CHARACTER_ENCODING } from '@verdaccio/commons-api'; +import { API_ERROR, HTTP_STATUS, CHARACTER_ENCODING } from '@verdaccio/core'; import { readFile } from '../lib/test.utils'; diff --git a/packages/verdaccio/test/functional/tags/dist-tags-merge.ts b/packages/verdaccio/test/functional/tags/dist-tags-merge.ts index d3a93e7d7..977ab7e2f 100644 --- a/packages/verdaccio/test/functional/tags/dist-tags-merge.ts +++ b/packages/verdaccio/test/functional/tags/dist-tags-merge.ts @@ -1,4 +1,4 @@ -import { DIST_TAGS, API_MESSAGE, HTTP_STATUS } from '@verdaccio/commons-api'; +import { DIST_TAGS, API_MESSAGE, HTTP_STATUS } from '@verdaccio/core'; import { DOMAIN_SERVERS, PORT_SERVER_1, PORT_SERVER_2, PORT_SERVER_3 } from '../config.functional'; import { generateSha } from '../lib/test.utils'; diff --git a/packages/verdaccio/test/functional/tags/tags.ts b/packages/verdaccio/test/functional/tags/tags.ts index b1c047108..4e945b7d6 100644 --- a/packages/verdaccio/test/functional/tags/tags.ts +++ b/packages/verdaccio/test/functional/tags/tags.ts @@ -1,5 +1,5 @@ import _ from 'lodash'; -import { HTTP_STATUS } from '@verdaccio/commons-api'; +import { HTTP_STATUS } from '@verdaccio/core'; import SimpleServer from '../lib/simple_server'; const simpleServer = new SimpleServer(); diff --git a/packages/verdaccio/test/functional/uplinks/cache.ts b/packages/verdaccio/test/functional/uplinks/cache.ts index 9f624b5ab..62015fa21 100644 --- a/packages/verdaccio/test/functional/uplinks/cache.ts +++ b/packages/verdaccio/test/functional/uplinks/cache.ts @@ -1,7 +1,7 @@ import fs from 'fs'; import path from 'path'; import crypto from 'crypto'; -import { HTTP_STATUS } from '@verdaccio/commons-api'; +import { HTTP_STATUS } from '@verdaccio/core'; import { createTarballHash } from '@verdaccio/utils'; import { TARBALL } from '../config.functional'; diff --git a/packages/verdaccio/test/functional/uplinks/timeout.ts b/packages/verdaccio/test/functional/uplinks/timeout.ts index 43b938ea8..89200abe5 100644 --- a/packages/verdaccio/test/functional/uplinks/timeout.ts +++ b/packages/verdaccio/test/functional/uplinks/timeout.ts @@ -1,4 +1,4 @@ -import { HTTP_STATUS } from '@verdaccio/commons-api'; +import { HTTP_STATUS } from '@verdaccio/core'; const PKG_SINGLE_UPLINK = 'test-uplink-timeout-single'; const PKG_MULTIPLE_UPLINKS = 'test-uplink-timeout-multiple'; diff --git a/packages/verdaccio/test/unit/__helper/api.ts b/packages/verdaccio/test/unit/__helper/api.ts index 896c0ce5b..3812d497d 100644 --- a/packages/verdaccio/test/unit/__helper/api.ts +++ b/packages/verdaccio/test/unit/__helper/api.ts @@ -1,7 +1,7 @@ import _ from 'lodash'; import request from 'supertest'; -import { HEADER_TYPE, HEADERS, HTTP_STATUS, TOKEN_BEARER } from '@verdaccio/commons-api'; +import { HEADER_TYPE, HEADERS, HTTP_STATUS, TOKEN_BEARER } from '@verdaccio/core'; import { buildToken } from '@verdaccio/utils'; import { generateRandomHexString } from '@verdaccio/utils'; import { Package } from '@verdaccio/types'; diff --git a/packages/verdaccio/test/unit/__helper/expects.ts b/packages/verdaccio/test/unit/__helper/expects.ts index d2d5772b7..6016277f2 100644 --- a/packages/verdaccio/test/unit/__helper/expects.ts +++ b/packages/verdaccio/test/unit/__helper/expects.ts @@ -1,4 +1,4 @@ -import { DIST_TAGS, LATEST } from '@verdaccio/commons-api'; +import { DIST_TAGS, LATEST } from '@verdaccio/core'; /** * Verify whether the package tag match with the desired version. diff --git a/packages/web/package.json b/packages/web/package.json index 3d5361f7f..f3ae542b9 100644 --- a/packages/web/package.json +++ b/packages/web/package.json @@ -26,7 +26,7 @@ "license": "MIT", "dependencies": { "@verdaccio/auth": "workspace:6.0.0-6-next.12", - "@verdaccio/commons-api": "workspace:11.0.0-6-next.4", + "@verdaccio/core": "workspace:6.0.0-6-next.1", "@verdaccio/config": "workspace:6.0.0-6-next.8", "@verdaccio/loaders": "workspace:6.0.0-6-next.5", "@verdaccio/logger": "workspace:6.0.0-6-next.5", diff --git a/packages/web/src/api/readme.ts b/packages/web/src/api/readme.ts index b6bc7f5aa..603af5f3b 100644 --- a/packages/web/src/api/readme.ts +++ b/packages/web/src/api/readme.ts @@ -2,7 +2,7 @@ import buildDebug from 'debug'; import sanitizyReadme from '@verdaccio/readme'; import { allow, $RequestExtend, $ResponseExtend, $NextFunctionVer } from '@verdaccio/middleware'; -import { HEADER_TYPE, HEADERS } from '@verdaccio/commons-api'; +import { HEADER_TYPE, HEADERS } from '@verdaccio/core'; import { Router } from 'express'; import { IAuth } from '@verdaccio/auth'; import { Storage } from '@verdaccio/store'; diff --git a/packages/web/src/api/search.ts b/packages/web/src/api/search.ts index 62dda95a6..158221f7f 100644 --- a/packages/web/src/api/search.ts +++ b/packages/web/src/api/search.ts @@ -1,6 +1,6 @@ import buildDebug from 'debug'; import { SearchInstance } from '@verdaccio/store'; -import { DIST_TAGS } from '@verdaccio/commons-api'; +import { DIST_TAGS } from '@verdaccio/core'; import { Router } from 'express'; import { Package } from '@verdaccio/types'; import { IAuth } from '@verdaccio/auth'; diff --git a/packages/web/src/api/sidebar.ts b/packages/web/src/api/sidebar.ts index 5fbbbd7c2..75da9895f 100644 --- a/packages/web/src/api/sidebar.ts +++ b/packages/web/src/api/sidebar.ts @@ -1,7 +1,7 @@ import buildDebug from 'debug'; import _ from 'lodash'; import { isVersionValid, formatAuthor } from '@verdaccio/utils'; -import { HTTP_STATUS, DIST_TAGS } from '@verdaccio/commons-api'; +import { HTTP_STATUS, DIST_TAGS } from '@verdaccio/core'; import { allow, $RequestExtend, $ResponseExtend, $NextFunctionVer } from '@verdaccio/middleware'; import { Router } from 'express'; diff --git a/packages/web/src/api/user.ts b/packages/web/src/api/user.ts index 5a591c3b6..f9f925053 100644 --- a/packages/web/src/api/user.ts +++ b/packages/web/src/api/user.ts @@ -4,9 +4,9 @@ import { Router, Response, Request } from 'express'; import { Config, RemoteUser, JWTSignOptions } from '@verdaccio/types'; -import { API_ERROR, APP_ERROR, HTTP_STATUS } from '@verdaccio/commons-api'; +import { API_ERROR, APP_ERROR, HTTP_STATUS, errorUtils } from '@verdaccio/core'; import { IAuth } from '@verdaccio/auth'; -import { validatePassword, ErrorCode } from '@verdaccio/utils'; +import { validatePassword } from '@verdaccio/utils'; import { $NextFunctionVer } from './package'; const debug = buildDebug('verdaccio:web:api:user'); @@ -19,7 +19,7 @@ function addUserAuthApi(route: Router, auth: IAuth, config: Config): void { if (err) { const errorCode = err.message ? HTTP_STATUS.UNAUTHORIZED : HTTP_STATUS.INTERNAL_ERROR; debug('error authenticate %o', errorCode); - next(ErrorCode.getCode(errorCode, err.message)); + next(errorUtils.getCode(errorCode, err.message)); } else { req.remote_user = user; const jWTSignOptions: JWTSignOptions = config.security.web.sign; @@ -58,12 +58,12 @@ function addUserAuthApi(route: Router, auth: IAuth, config: Config): void { ok: true, }); } else { - return next(ErrorCode.getInternalError(API_ERROR.INTERNAL_SERVER_ERROR)); + return next(errorUtils.getInternalError(API_ERROR.INTERNAL_SERVER_ERROR)); } } ); } else { - return next(ErrorCode.getCode(HTTP_STATUS.BAD_REQUEST, APP_ERROR.PASSWORD_VALIDATION)); + return next(errorUtils.getCode(HTTP_STATUS.BAD_REQUEST, APP_ERROR.PASSWORD_VALIDATION)); } } ); diff --git a/packages/web/src/middleware/render-web.ts b/packages/web/src/middleware/render-web.ts index bb15251bc..0f07d8be3 100644 --- a/packages/web/src/middleware/render-web.ts +++ b/packages/web/src/middleware/render-web.ts @@ -4,7 +4,7 @@ import buildDebug from 'debug'; import express from 'express'; import { SearchInstance } from '@verdaccio/store'; -import { HTTP_STATUS } from '@verdaccio/commons-api'; +import { HTTP_STATUS } from '@verdaccio/core'; import { loadPlugin } from '@verdaccio/loaders'; import { isURLhasValidProtocol } from '@verdaccio/url'; import renderHTML from '../renderHTML'; diff --git a/packages/web/src/middleware/security.ts b/packages/web/src/middleware/security.ts index 41b1ebe13..339ab0571 100644 --- a/packages/web/src/middleware/security.ts +++ b/packages/web/src/middleware/security.ts @@ -1,4 +1,4 @@ -import { HEADERS } from '@verdaccio/commons-api'; +import { HEADERS } from '@verdaccio/core'; import { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '@verdaccio/middleware'; export function setSecurityWebHeaders( diff --git a/packages/web/src/renderHTML.ts b/packages/web/src/renderHTML.ts index bc093f73a..83afc27fe 100644 --- a/packages/web/src/renderHTML.ts +++ b/packages/web/src/renderHTML.ts @@ -1,7 +1,7 @@ import { URL } from 'url'; import buildDebug from 'debug'; import LRU from 'lru-cache'; -import { HEADERS } from '@verdaccio/commons-api'; +import { HEADERS } from '@verdaccio/core'; import { getPublicUrl } from '@verdaccio/url'; import { WEB_TITLE } from '@verdaccio/config'; diff --git a/packages/web/test/api.packages.test.ts b/packages/web/test/api.packages.test.ts index 01b2e38f2..6c0d75ae3 100644 --- a/packages/web/test/api.packages.test.ts +++ b/packages/web/test/api.packages.test.ts @@ -1,7 +1,7 @@ import path from 'path'; import supertest from 'supertest'; import { setup } from '@verdaccio/logger'; -import { HEADERS, HEADER_TYPE, HTTP_STATUS } from '@verdaccio/commons-api'; +import { HEADERS, HEADER_TYPE, HTTP_STATUS } from '@verdaccio/core'; import { initializeServer } from './helper'; setup([]); diff --git a/packages/web/test/api.readme.test.ts b/packages/web/test/api.readme.test.ts index 419d31c36..d245335dd 100644 --- a/packages/web/test/api.readme.test.ts +++ b/packages/web/test/api.readme.test.ts @@ -2,7 +2,7 @@ import path from 'path'; import supertest from 'supertest'; import { setup } from '@verdaccio/logger'; import { IGetPackageOptions } from '@verdaccio/store'; -import { HEADERS, HEADER_TYPE, HTTP_STATUS } from '@verdaccio/commons-api'; +import { HEADERS, HEADER_TYPE, HTTP_STATUS } from '@verdaccio/core'; import { NOT_README_FOUND } from '../src/api/readme'; import { initializeServer } from './helper'; diff --git a/packages/web/test/api.search.test.ts b/packages/web/test/api.search.test.ts index e4bf7c0f6..d50228419 100644 --- a/packages/web/test/api.search.test.ts +++ b/packages/web/test/api.search.test.ts @@ -3,7 +3,7 @@ import supertest from 'supertest'; import { IGetPackageOptions } from '@verdaccio/store'; import { setup } from '@verdaccio/logger'; -import { HEADERS, HEADER_TYPE, HTTP_STATUS } from '@verdaccio/commons-api'; +import { HEADERS, HEADER_TYPE, HTTP_STATUS } from '@verdaccio/core'; import { initializeServer } from './helper'; setup([]); diff --git a/packages/web/test/api.sidebar.test.ts b/packages/web/test/api.sidebar.test.ts index 03ad5c531..78fb5a740 100644 --- a/packages/web/test/api.sidebar.test.ts +++ b/packages/web/test/api.sidebar.test.ts @@ -2,7 +2,7 @@ import path from 'path'; import supertest from 'supertest'; import { setup } from '@verdaccio/logger'; import { IGetPackageOptions } from '@verdaccio/store'; -import { HEADERS, HEADER_TYPE, HTTP_STATUS } from '@verdaccio/commons-api'; +import { HEADERS, HEADER_TYPE, HTTP_STATUS } from '@verdaccio/core'; import { NOT_README_FOUND } from '../src/api/readme'; import { initializeServer } from './helper'; diff --git a/packages/web/test/api.user.test.ts b/packages/web/test/api.user.test.ts index 6a6514d9b..9306be66b 100644 --- a/packages/web/test/api.user.test.ts +++ b/packages/web/test/api.user.test.ts @@ -1,7 +1,7 @@ import path from 'path'; import supertest from 'supertest'; import { setup } from '@verdaccio/logger'; -import { HEADERS, HEADER_TYPE, HTTP_STATUS, API_ERROR } from '@verdaccio/commons-api'; +import { HEADERS, HEADER_TYPE, HTTP_STATUS, API_ERROR } from '@verdaccio/core'; import { initializeServer } from './helper'; setup([]); diff --git a/packages/web/test/render.test.ts b/packages/web/test/render.test.ts index 9571f8c82..e52472d55 100644 --- a/packages/web/test/render.test.ts +++ b/packages/web/test/render.test.ts @@ -1,7 +1,7 @@ import path from 'path'; import supertest from 'supertest'; import { setup } from '@verdaccio/logger'; -import { HEADER_TYPE, HEADERS, HTTP_STATUS } from '@verdaccio/commons-api'; +import { HEADER_TYPE, HEADERS, HTTP_STATUS } from '@verdaccio/core'; import { initializeServer } from './helper'; setup([]); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 10ee43be6..5daea35ec 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -188,9 +188,9 @@ importers: specifiers: '@types/node': 16.9.1 '@verdaccio/auth': workspace:6.0.0-6-next.12 - '@verdaccio/commons-api': workspace:11.0.0-6-next.4 '@verdaccio/config': workspace:6.0.0-6-next.8 '@verdaccio/core': workspace:6.0.0-6-next.1 + '@verdaccio/helper': 1.0.0 '@verdaccio/hooks': workspace:6.0.0-6-next.7 '@verdaccio/logger': workspace:6.0.0-6-next.5 '@verdaccio/middleware': workspace:6.0.0-6-next.12 @@ -209,7 +209,6 @@ importers: supertest: 6.1.6 dependencies: '@verdaccio/auth': link:../auth - '@verdaccio/commons-api': link:../core/commons-api '@verdaccio/config': link:../config '@verdaccio/core': link:../core/core '@verdaccio/hooks': link:../hooks @@ -226,6 +225,7 @@ importers: semver: 7.3.5 devDependencies: '@types/node': 16.9.1 + '@verdaccio/helper': link:../tools/helpers '@verdaccio/server': link:../server '@verdaccio/types': link:../core/types body-parser: 1.19.0 @@ -233,8 +233,8 @@ importers: packages/auth: specifiers: - '@verdaccio/commons-api': workspace:11.0.0-6-next.4 '@verdaccio/config': workspace:6.0.0-6-next.8 + '@verdaccio/core': workspace:6.0.0-6-next.1 '@verdaccio/loaders': workspace:6.0.0-6-next.5 '@verdaccio/logger': workspace:6.0.0-6-next.5 '@verdaccio/mock': workspace:6.0.0-6-next.9 @@ -246,8 +246,8 @@ importers: lodash: 4.17.21 verdaccio-htpasswd: workspace:11.0.0-6-next.8 dependencies: - '@verdaccio/commons-api': link:../core/commons-api '@verdaccio/config': link:../config + '@verdaccio/core': link:../core/core '@verdaccio/loaders': link:../loaders '@verdaccio/logger': link:../logger '@verdaccio/utils': link:../utils @@ -287,7 +287,7 @@ importers: specifiers: '@types/minimatch': 3.0.5 '@types/yup': 0.29.13 - '@verdaccio/commons-api': workspace:11.0.0-6-next.4 + '@verdaccio/core': workspace:6.0.0-6-next.1 '@verdaccio/utils': workspace:6.0.0-6-next.6 debug: 4.3.2 js-yaml: 3.14.1 @@ -295,7 +295,7 @@ importers: minimatch: 3.0.4 yup: 0.32.9 dependencies: - '@verdaccio/commons-api': link:../core/commons-api + '@verdaccio/core': link:../core/core '@verdaccio/utils': link:../utils debug: 4.3.2 js-yaml: 3.14.1 @@ -306,14 +306,6 @@ importers: '@types/minimatch': 3.0.5 '@types/yup': 0.29.13 - packages/core/commons-api: - specifiers: - http-errors: 1.8.0 - http-status-codes: 2.1.4 - dependencies: - http-errors: 1.8.0 - http-status-codes: 2.1.4 - packages/core/core: specifiers: '@verdaccio/types': workspace:11.0.0-6-next.8 @@ -339,7 +331,7 @@ importers: packages/core/htpasswd: specifiers: '@types/bcryptjs': 2.4.2 - '@verdaccio/commons-api': workspace:11.0.0-6-next.4 + '@verdaccio/core': workspace:6.0.0-6-next.1 '@verdaccio/file-locking': workspace:11.0.0-alpha.3 '@verdaccio/types': workspace:11.0.0-6-next.8 apache-md5: 1.1.7 @@ -349,7 +341,7 @@ importers: mockdate: 3.0.5 unix-crypt-td-js: 1.1.4 dependencies: - '@verdaccio/commons-api': link:../commons-api + '@verdaccio/core': link:../core '@verdaccio/file-locking': link:../file-locking apache-md5: 1.1.7 bcryptjs: 2.4.3 @@ -364,7 +356,6 @@ importers: packages/core/local-storage: specifiers: '@types/minimatch': 3.0.5 - '@verdaccio/commons-api': workspace:11.0.0-6-next.4 '@verdaccio/config': workspace:6.0.0-6-next.8 '@verdaccio/core': workspace:6.0.0-6-next.1 '@verdaccio/file-locking': workspace:11.0.0-alpha.3 @@ -382,7 +373,6 @@ importers: minimatch: 3.0.4 tmp-promise: 3.0.2 dependencies: - '@verdaccio/commons-api': link:../commons-api '@verdaccio/core': link:../core '@verdaccio/file-locking': link:../file-locking '@verdaccio/streams': link:../streams @@ -450,7 +440,7 @@ importers: packages/core/tarball: specifiers: - '@verdaccio/commons-api': workspace:11.0.0-6-next.4 + '@verdaccio/core': workspace:6.0.0-6-next.1 '@verdaccio/types': workspace:11.0.0-6-next.8 '@verdaccio/url': workspace:11.0.0-6-next.5 '@verdaccio/utils': workspace:6.0.0-6-next.6 @@ -458,7 +448,7 @@ importers: lodash: 4.17.21 node-mocks-http: 1.10.1 dependencies: - '@verdaccio/commons-api': link:../commons-api + '@verdaccio/core': link:../core '@verdaccio/url': link:../url '@verdaccio/utils': link:../../utils lodash: 4.17.21 @@ -475,14 +465,14 @@ importers: packages/core/url: specifiers: - '@verdaccio/commons-api': workspace:11.0.0-6-next.4 + '@verdaccio/core': workspace:6.0.0-6-next.1 '@verdaccio/types': workspace:11.0.0-6-next.8 debug: 4.3.2 lodash: 4.17.21 node-mocks-http: 1.10.1 validator: 13.6.0 dependencies: - '@verdaccio/commons-api': link:../commons-api + '@verdaccio/core': link:../core debug: 4.3.2 lodash: 4.17.21 validator: 13.6.0 @@ -494,8 +484,8 @@ importers: specifiers: '@types/node': 16.9.1 '@verdaccio/auth': workspace:6.0.0-6-next.12 - '@verdaccio/commons-api': workspace:11.0.0-6-next.4 '@verdaccio/config': workspace:6.0.0-6-next.8 + '@verdaccio/core': workspace:6.0.0-6-next.1 '@verdaccio/logger': workspace:6.0.0-6-next.5 '@verdaccio/types': workspace:11.0.0-6-next.8 core-js: 3.17.2 @@ -504,7 +494,7 @@ importers: undici: 4.4.7 undici-fetch: 1.0.0-rc.4 dependencies: - '@verdaccio/commons-api': link:../core/commons-api + '@verdaccio/core': link:../core/core '@verdaccio/logger': link:../logger core-js: 3.17.2 debug: 4.3.2 @@ -519,8 +509,8 @@ importers: packages/loaders: specifiers: - '@verdaccio/commons-api': workspace:11.0.0-6-next.4 '@verdaccio/config': workspace:6.0.0-6-next.8 + '@verdaccio/core': workspace:6.0.0-6-next.1 '@verdaccio/logger': workspace:6.0.0-6-next.5 '@verdaccio/mock': workspace:6.0.0-6-next.9 '@verdaccio/types': workspace:11.0.0-6-next.8 @@ -531,8 +521,8 @@ importers: debug: 4.3.2 lodash: 4.17.21 devDependencies: - '@verdaccio/commons-api': link:../core/commons-api '@verdaccio/config': link:../config + '@verdaccio/core': link:../core/core '@verdaccio/mock': link:../mock '@verdaccio/types': link:../core/types @@ -575,14 +565,14 @@ importers: packages/middleware: specifiers: '@verdaccio/auth': workspace:6.0.0-6-next.12 - '@verdaccio/commons-api': workspace:11.0.0-6-next.4 + '@verdaccio/core': workspace:6.0.0-6-next.1 '@verdaccio/logger': workspace:6.0.0-6-next.5 '@verdaccio/utils': workspace:6.0.0-6-next.6 debug: 4.3.2 lodash: 4.17.21 dependencies: '@verdaccio/auth': link:../auth - '@verdaccio/commons-api': link:../core/commons-api + '@verdaccio/core': link:../core/core '@verdaccio/logger': link:../logger '@verdaccio/utils': link:../utils debug: 4.3.2 @@ -590,8 +580,8 @@ importers: packages/mock: specifiers: - '@verdaccio/commons-api': workspace:11.0.0-6-next.4 '@verdaccio/config': workspace:6.0.0-6-next.8 + '@verdaccio/core': workspace:6.0.0-6-next.1 '@verdaccio/types': workspace:11.0.0-6-next.8 '@verdaccio/utils': workspace:6.0.0-6-next.6 core-js: 3.17.2 @@ -601,8 +591,8 @@ importers: request: 2.87.0 supertest: 6.1.6 dependencies: - '@verdaccio/commons-api': link:../core/commons-api '@verdaccio/config': link:../config + '@verdaccio/core': link:../core/core '@verdaccio/utils': link:../utils core-js: 3.17.2 debug: 4.3.2 @@ -616,8 +606,8 @@ importers: packages/node-api: specifiers: '@types/node': 16.9.1 - '@verdaccio/commons-api': workspace:11.0.0-6-next.4 '@verdaccio/config': workspace:6.0.0-6-next.8 + '@verdaccio/core': workspace:6.0.0-6-next.1 '@verdaccio/logger': workspace:6.0.0-6-next.5 '@verdaccio/mock': workspace:6.0.0-6-next.9 '@verdaccio/server': workspace:6.0.0-6-next.20 @@ -629,8 +619,8 @@ importers: selfsigned: 1.10.11 supertest: 6.1.6 dependencies: - '@verdaccio/commons-api': link:../core/commons-api '@verdaccio/config': link:../config + '@verdaccio/core': link:../core/core '@verdaccio/logger': link:../logger '@verdaccio/server': link:../server core-js: 3.17.2 @@ -647,11 +637,11 @@ importers: packages/plugins/active-directory: specifiers: '@types/activedirectory2': 1.2.3 - '@verdaccio/commons-api': workspace:11.0.0-6-next.4 + '@verdaccio/core': workspace:6.0.0-6-next.1 '@verdaccio/types': workspace:11.0.0-6-next.8 activedirectory2: 2.1.0 dependencies: - '@verdaccio/commons-api': link:../../core/commons-api + '@verdaccio/core': link:../../core/core activedirectory2: 2.1.0 devDependencies: '@types/activedirectory2': 1.2.3 @@ -678,24 +668,24 @@ importers: packages/plugins/auth-memory: specifiers: - '@verdaccio/commons-api': workspace:11.0.0-6-next.4 + '@verdaccio/core': workspace:6.0.0-6-next.1 '@verdaccio/types': workspace:11.0.0-6-next.8 debug: 4.3.2 dependencies: - '@verdaccio/commons-api': link:../../core/commons-api + '@verdaccio/core': link:../../core/core debug: 4.3.2 devDependencies: '@verdaccio/types': link:../../core/types packages/plugins/aws-storage: specifiers: - '@verdaccio/commons-api': workspace:11.0.0-6-next.4 + '@verdaccio/core': workspace:6.0.0-6-next.1 '@verdaccio/streams': workspace:11.0.0-6-next.4 '@verdaccio/types': workspace:11.0.0-6-next.8 aws-sdk: 2.981.0 recursive-readdir: 2.2.2 dependencies: - '@verdaccio/commons-api': link:../../core/commons-api + '@verdaccio/core': link:../../core/core '@verdaccio/streams': link:../../core/streams aws-sdk: 2.981.0 devDependencies: @@ -706,7 +696,7 @@ importers: specifiers: '@google-cloud/datastore': 6.5.0 '@google-cloud/storage': 5.14.0 - '@verdaccio/commons-api': 11.0.0-6-next.4 + '@verdaccio/core': workspace:6.0.0-6-next.1 '@verdaccio/streams': workspace:11.0.0-6-next.4 '@verdaccio/types': workspace:11.0.0-6-next.8 fast-crc32c: 1.0.4 @@ -714,7 +704,7 @@ importers: dependencies: '@google-cloud/datastore': 6.5.0 '@google-cloud/storage': 5.14.0 - '@verdaccio/commons-api': link:../../core/commons-api + '@verdaccio/core': link:../../core/core '@verdaccio/streams': link:../../core/streams optionalDependencies: fast-crc32c: 1.0.4 @@ -724,14 +714,14 @@ importers: packages/plugins/memory: specifiers: - '@verdaccio/commons-api': workspace:11.0.0-6-next.4 + '@verdaccio/core': workspace:6.0.0-6-next.1 '@verdaccio/streams': workspace:11.0.0-6-next.4 '@verdaccio/types': workspace:11.0.0-6-next.8 debug: 4.3.2 memfs: 3.2.4 memory-fs: 0.5.0 dependencies: - '@verdaccio/commons-api': link:../../core/commons-api + '@verdaccio/core': link:../../core/core '@verdaccio/streams': link:../../core/streams debug: 4.3.2 memfs: 3.2.4 @@ -908,7 +898,6 @@ importers: packages/proxy: specifiers: '@types/node': 16.9.1 - '@verdaccio/commons-api': workspace:11.0.0-6-next.4 '@verdaccio/config': workspace:6.0.0-6-next.8 '@verdaccio/core': workspace:6.0.0-6-next.1 '@verdaccio/local-storage': workspace:11.0.0-6-next.8 @@ -929,7 +918,6 @@ importers: undici: 4.4.7 undici-fetch: 1.0.0-rc.4 dependencies: - '@verdaccio/commons-api': link:../core/commons-api '@verdaccio/config': link:../config '@verdaccio/core': link:../core/core '@verdaccio/local-storage': link:../core/local-storage @@ -957,8 +945,9 @@ importers: '@types/node': 16.9.1 '@verdaccio/api': workspace:6.0.0-6-next.15 '@verdaccio/auth': workspace:6.0.0-6-next.12 - '@verdaccio/commons-api': workspace:11.0.0-6-next.4 '@verdaccio/config': workspace:6.0.0-6-next.8 + '@verdaccio/core': workspace:6.0.0-6-next.1 + '@verdaccio/helper': 1.0.0 '@verdaccio/loaders': workspace:6.0.0-6-next.5 '@verdaccio/logger': workspace:6.0.0-6-next.5 '@verdaccio/middleware': workspace:6.0.0-6-next.12 @@ -979,8 +968,8 @@ importers: dependencies: '@verdaccio/api': link:../api '@verdaccio/auth': link:../auth - '@verdaccio/commons-api': link:../core/commons-api '@verdaccio/config': link:../config + '@verdaccio/core': link:../core/core '@verdaccio/loaders': link:../loaders '@verdaccio/logger': link:../logger '@verdaccio/middleware': link:../middleware @@ -996,6 +985,7 @@ importers: verdaccio-audit: link:../plugins/audit devDependencies: '@types/node': 16.9.1 + '@verdaccio/helper': link:../tools/helpers '@verdaccio/mock': link:../mock '@verdaccio/proxy': link:../proxy http-errors: 1.8.0 @@ -1022,7 +1012,6 @@ importers: packages/store: specifiers: '@types/node': 16.9.1 - '@verdaccio/commons-api': workspace:11.0.0-6-next.4 '@verdaccio/config': workspace:6.0.0-6-next.8 '@verdaccio/core': workspace:6.0.0-6-next.1 '@verdaccio/loaders': workspace:6.0.0-6-next.5 @@ -1046,7 +1035,6 @@ importers: undici: 4.4.7 undici-fetch: 1.0.0-rc.4 dependencies: - '@verdaccio/commons-api': link:../core/commons-api '@verdaccio/config': link:../config '@verdaccio/core': link:../core/core '@verdaccio/loaders': link:../loaders @@ -1117,6 +1105,12 @@ importers: eslint-plugin-simple-import-sort: 7.0.0_eslint@7.32.0 eslint-plugin-verdaccio: 10.0.0 + packages/tools/helpers: + specifiers: + '@verdaccio/types': workspace:11.0.0-6-next.8 + devDependencies: + '@verdaccio/types': link:../../core/types + packages/types: specifiers: lunr-mutable-indexes: 2.3.2 @@ -1125,12 +1119,12 @@ importers: packages/utils: specifiers: - '@verdaccio/commons-api': workspace:11.0.0-6-next.4 + '@verdaccio/core': workspace:6.0.0-6-next.1 lodash: 4.17.21 minimatch: 3.0.4 semver: 7.3.5 dependencies: - '@verdaccio/commons-api': link:../core/commons-api + '@verdaccio/core': link:../core/core minimatch: 3.0.4 semver: 7.3.5 devDependencies: @@ -1140,8 +1134,8 @@ importers: specifiers: '@verdaccio/auth': workspace:6.0.0-6-next.12 '@verdaccio/cli': workspace:6.0.0-6-next.22 - '@verdaccio/commons-api': workspace:11.0.0-6-next.4 '@verdaccio/config': workspace:6.0.0-6-next.8 + '@verdaccio/core': workspace:6.0.0-6-next.1 '@verdaccio/hooks': workspace:6.0.0-6-next.7 '@verdaccio/logger': workspace:6.0.0-6-next.5 '@verdaccio/mock': workspace:6.0.0-6-next.9 @@ -1164,8 +1158,8 @@ importers: verdaccio-htpasswd: link:../core/htpasswd devDependencies: '@verdaccio/auth': link:../auth - '@verdaccio/commons-api': link:../core/commons-api '@verdaccio/config': link:../config + '@verdaccio/core': link:../core/core '@verdaccio/store': link:../store fastify: 3.20.2 @@ -1173,8 +1167,8 @@ importers: specifiers: '@types/node': 16.9.1 '@verdaccio/auth': workspace:6.0.0-6-next.12 - '@verdaccio/commons-api': workspace:11.0.0-6-next.4 '@verdaccio/config': workspace:6.0.0-6-next.8 + '@verdaccio/core': workspace:6.0.0-6-next.1 '@verdaccio/loaders': workspace:6.0.0-6-next.5 '@verdaccio/logger': workspace:6.0.0-6-next.5 '@verdaccio/middleware': workspace:6.0.0-6-next.12 @@ -1196,8 +1190,8 @@ importers: verdaccio-memory: workspace:11.0.0-6-next.5 dependencies: '@verdaccio/auth': link:../auth - '@verdaccio/commons-api': link:../core/commons-api '@verdaccio/config': link:../config + '@verdaccio/core': link:../core/core '@verdaccio/loaders': link:../loaders '@verdaccio/logger': link:../logger '@verdaccio/middleware': link:../middleware @@ -1245,7 +1239,7 @@ importers: test/e2e-ui: specifiers: - '@verdaccio/commons-api': workspace:11.0.0-6-next.4 + '@verdaccio/core': workspace:6.0.0-6-next.1 '@verdaccio/ui-theme': workspace:6.0.0-6-next.11 debug: 4.3.2 kleur: 3.0.3 @@ -1254,7 +1248,7 @@ importers: request: 2.87.0 rimraf: 3.0.2 devDependencies: - '@verdaccio/commons-api': link:../../packages/core/commons-api + '@verdaccio/core': link:../../packages/core/core '@verdaccio/ui-theme': link:../../packages/plugins/ui-theme debug: 4.3.2 kleur: 3.0.3 diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 650abb33f..1f9b25a58 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -5,3 +5,4 @@ packages: - packages/plugins/* - website - test/e2e-* + - test/helpers diff --git a/test/e2e-ui/package.json b/test/e2e-ui/package.json index 1aae490b7..451e0cfcf 100644 --- a/test/e2e-ui/package.json +++ b/test/e2e-ui/package.json @@ -3,7 +3,7 @@ "name": "@verdaccio/e2e-ui", "version": "1.1.0-6-next.1", "devDependencies": { - "@verdaccio/commons-api": "workspace:11.0.0-6-next.4", + "@verdaccio/core": "workspace:6.0.0-6-next.1", "@verdaccio/ui-theme": "workspace:6.0.0-6-next.11", "debug": "4.3.2", "kleur": "3.0.3", diff --git a/test/e2e-ui/registry-launcher.ts b/test/e2e-ui/registry-launcher.ts index a5665b33c..d26e026ba 100644 --- a/test/e2e-ui/registry-launcher.ts +++ b/test/e2e-ui/registry-launcher.ts @@ -1,7 +1,7 @@ import { fork } from 'child_process'; import path from 'path'; -import { HTTP_STATUS } from '@verdaccio/commons-api'; +import { HTTP_STATUS } from '@verdaccio/core'; const debug = require('debug')('verdaccio:e2e:ui:launcher'); diff --git a/test/e2e-ui/server.ts b/test/e2e-ui/server.ts index 211671fcc..75c501c6e 100644 --- a/test/e2e-ui/server.ts +++ b/test/e2e-ui/server.ts @@ -1,6 +1,6 @@ import assert from 'assert'; -import { HTTP_STATUS, HEADERS, API_MESSAGE } from '@verdaccio/commons-api'; +import { HTTP_STATUS, HEADERS, API_MESSAGE } from '@verdaccio/core'; import _ from 'lodash'; import { CREDENTIALS } from './registry-launcher';