mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-20 17:05:52 +01:00
feat: add @verdaccio/commons-api package
Update local references
This commit is contained in:
parent
3838d3d212
commit
4fcd6457be
@ -24,7 +24,7 @@
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@verdaccio/auth": "5.0.0-alpha.0",
|
||||
"@verdaccio/commons-api": "9.6.1",
|
||||
"@verdaccio/commons-api": "workspace:*",
|
||||
"@verdaccio/dev-commons": "5.0.0-alpha.0",
|
||||
"@verdaccio/hooks": "5.0.0-alpha.0",
|
||||
"@verdaccio/logger": "5.0.0-alpha.0",
|
||||
|
@ -23,7 +23,7 @@
|
||||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@verdaccio/commons-api": "9.6.1",
|
||||
"@verdaccio/commons-api": "workspace:*",
|
||||
"@verdaccio/dev-commons": "5.0.0-alpha.0",
|
||||
"@verdaccio/loaders": "5.0.0-alpha.0",
|
||||
"@verdaccio/logger": "5.0.0-alpha.0",
|
||||
|
3
packages/core/commons-api/.babelrc
Normal file
3
packages/core/commons-api/.babelrc
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "../../../.babelrc"
|
||||
}
|
5
packages/core/commons-api/.eslintignore
Normal file
5
packages/core/commons-api/.eslintignore
Normal file
@ -0,0 +1,5 @@
|
||||
node_modules
|
||||
coverage/
|
||||
lib/
|
||||
.nyc_output
|
||||
tests-report/
|
1
packages/core/commons-api/.gitignore
vendored
Normal file
1
packages/core/commons-api/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
lib/
|
231
packages/core/commons-api/CHANGELOG.md
Normal file
231
packages/core/commons-api/CHANGELOG.md
Normal file
@ -0,0 +1,231 @@
|
||||
# Change Log
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [9.7.1](https://github.com/verdaccio/monorepo/compare/v9.7.0...v9.7.1) (2020-07-10)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* update dependencies ([#375](https://github.com/verdaccio/monorepo/issues/375)) ([1e7aeec](https://github.com/verdaccio/monorepo/commit/1e7aeec31b056979285e272793a95b8c75d57c77))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [9.6.1](https://github.com/verdaccio/monorepo/compare/v9.6.0...v9.6.1) (2020-06-07)
|
||||
|
||||
**Note:** Version bump only for package @verdaccio/commons-api
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [9.4.0](https://github.com/verdaccio/monorepo/compare/v9.3.4...v9.4.0) (2020-03-21)
|
||||
|
||||
**Note:** Version bump only for package @verdaccio/commons-api
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [9.3.2](https://github.com/verdaccio/monorepo/compare/v9.3.1...v9.3.2) (2020-03-08)
|
||||
|
||||
**Note:** Version bump only for package @verdaccio/commons-api
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [9.3.1](https://github.com/verdaccio/monorepo/compare/v9.3.0...v9.3.1) (2020-02-23)
|
||||
|
||||
**Note:** Version bump only for package @verdaccio/commons-api
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [9.0.0](https://github.com/verdaccio/monorepo/compare/v8.5.3...v9.0.0) (2020-01-07)
|
||||
|
||||
**Note:** Version bump only for package @verdaccio/commons-api
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [8.5.0](https://github.com/verdaccio/monorepo/compare/v8.4.2...v8.5.0) (2019-12-22)
|
||||
|
||||
**Note:** Version bump only for package @verdaccio/commons-api
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [8.4.2](https://github.com/verdaccio/monorepo/compare/v8.4.1...v8.4.2) (2019-11-23)
|
||||
|
||||
**Note:** Version bump only for package @verdaccio/commons-api
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [8.4.1](https://github.com/verdaccio/monorepo/compare/v8.4.0...v8.4.1) (2019-11-22)
|
||||
|
||||
**Note:** Version bump only for package @verdaccio/commons-api
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [8.4.0](https://github.com/verdaccio/monorepo/compare/v8.3.0...v8.4.0) (2019-11-22)
|
||||
|
||||
**Note:** Version bump only for package @verdaccio/commons-api
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [8.3.0](https://github.com/verdaccio/monorepo/compare/v8.2.0...v8.3.0) (2019-10-27)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add http-status-codes dep ([#212](https://github.com/verdaccio/monorepo/issues/212)) ([00b66af](https://github.com/verdaccio/monorepo/commit/00b66af))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [8.2.0](https://github.com/verdaccio/monorepo/compare/v8.2.0-next.0...v8.2.0) (2019-10-23)
|
||||
|
||||
**Note:** Version bump only for package @verdaccio/commons-api
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [8.2.0-next.0](https://github.com/verdaccio/monorepo/compare/v8.1.4...v8.2.0-next.0) (2019-10-08)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* fixed lint errors ([5e677f7](https://github.com/verdaccio/monorepo/commit/5e677f7))
|
||||
* fixed lint errors ([c80e915](https://github.com/verdaccio/monorepo/commit/c80e915))
|
||||
* quotes should be single ([ae9aa44](https://github.com/verdaccio/monorepo/commit/ae9aa44))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [8.1.2](https://github.com/verdaccio/monorepo/compare/v8.1.1...v8.1.2) (2019-09-29)
|
||||
|
||||
**Note:** Version bump only for package @verdaccio/commons-api
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [8.1.1](https://github.com/verdaccio/monorepo/compare/v8.1.0...v8.1.1) (2019-09-26)
|
||||
|
||||
**Note:** Version bump only for package @verdaccio/commons-api
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [8.1.0](https://github.com/verdaccio/monorepo/compare/v8.0.1-next.1...v8.1.0) (2019-09-07)
|
||||
|
||||
**Note:** Version bump only for package @verdaccio/commons-api
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [8.0.1-next.1](https://github.com/verdaccio/monorepo/compare/v8.0.1-next.0...v8.0.1-next.1) (2019-08-29)
|
||||
|
||||
**Note:** Version bump only for package @verdaccio/commons-api
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [8.0.1-next.0](https://github.com/verdaccio/monorepo/compare/v8.0.0...v8.0.1-next.0) (2019-08-29)
|
||||
|
||||
**Note:** Version bump only for package @verdaccio/commons-api
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [8.0.0](https://github.com/verdaccio/monorepo/compare/v8.0.0-next.4...v8.0.0) (2019-08-22)
|
||||
|
||||
**Note:** Version bump only for package @verdaccio/commons-api
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [8.0.0-next.4](https://github.com/verdaccio/monorepo/compare/v8.0.0-next.3...v8.0.0-next.4) (2019-08-18)
|
||||
|
||||
**Note:** Version bump only for package @verdaccio/commons-api
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [8.0.0-next.2](https://github.com/verdaccio/monorepo/compare/v8.0.0-next.1...v8.0.0-next.2) (2019-08-03)
|
||||
|
||||
**Note:** Version bump only for package @verdaccio/commons-api
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [8.0.0-next.1](https://github.com/verdaccio/monorepo/compare/v8.0.0-next.0...v8.0.0-next.1) (2019-08-01)
|
||||
|
||||
**Note:** Version bump only for package @verdaccio/commons-api
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [8.0.0-next.0](https://github.com/verdaccio/monorepo/compare/v2.0.0...v8.0.0-next.0) (2019-08-01)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **commons-api:** add commons-api package ([13dfa76](https://github.com/verdaccio/monorepo/commit/13dfa76))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
||||
|
||||
### [0.1.2](https://github.com/verdaccio/commons-api/compare/v0.1.1...v0.1.2) (2019-07-15)
|
||||
|
||||
|
||||
### Build System
|
||||
|
||||
* build before publish ([f3d952d](https://github.com/verdaccio/commons-api/commit/f3d952d))
|
||||
|
||||
|
||||
|
||||
### [0.1.1](https://github.com/verdaccio/commons-api/compare/v0.1.0...v0.1.1) (2019-07-12)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* remove unecessary shallow copy ([af7bc7c](https://github.com/verdaccio/commons-api/commit/af7bc7c))
|
||||
|
||||
|
||||
|
||||
## 0.1.0 (2019-06-25)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add error handler modules ([936212b](https://github.com/verdaccio/commons-api/commit/936212b))
|
21
packages/core/commons-api/LICENSE
Normal file
21
packages/core/commons-api/LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 Verdaccio
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
16
packages/core/commons-api/README.md
Normal file
16
packages/core/commons-api/README.md
Normal file
@ -0,0 +1,16 @@
|
||||
# @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)
|
3
packages/core/commons-api/jest.config.js
Normal file
3
packages/core/commons-api/jest.config.js
Normal file
@ -0,0 +1,3 @@
|
||||
const config = require('../../../jest/config');
|
||||
|
||||
module.exports = Object.assign({}, config, {});
|
48
packages/core/commons-api/package.json
Normal file
48
packages/core/commons-api/package.json
Normal file
@ -0,0 +1,48 @@
|
||||
{
|
||||
"name": "@verdaccio/commons-api",
|
||||
"version": "10.0.0-beta",
|
||||
"description": "Commons API utilities for Verdaccio",
|
||||
"keywords": [
|
||||
"http",
|
||||
"verdaccio",
|
||||
"api"
|
||||
],
|
||||
"author": "Juan Picado <juanpicado19@gmail.com>",
|
||||
"license": "MIT",
|
||||
"homepage": "https://verdaccio.org",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/verdaccio/monorepo",
|
||||
"directory": "core/commons-api"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/verdaccio/monorepo/issues"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"main": "build/index.js",
|
||||
"types": "build/index.d.ts",
|
||||
"files": [
|
||||
"build"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
},
|
||||
"dependencies": {
|
||||
"http-errors": "^1.8.0",
|
||||
"http-status-codes": "^1.4.0"
|
||||
},
|
||||
"scripts": {
|
||||
"clean": "rimraf ./build",
|
||||
"test": "cross-env NODE_ENV=test BABEL_ENV=test jest",
|
||||
"type-check": "tsc --noEmit",
|
||||
"build:types": "tsc --emitDeclarationOnly --declaration true",
|
||||
"build:js": "cross-env babel src/ --out-dir build/ --copy-files --extensions \".ts,.tsx\" --source-maps",
|
||||
"build": "pnpm run build:js && pnpm run build:types"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/verdaccio"
|
||||
}
|
||||
}
|
137
packages/core/commons-api/src/index.ts
Normal file
137
packages/core/commons-api/src/index.ts
Normal file
@ -0,0 +1,137 @@
|
||||
import createError, { HttpError } from 'http-errors';
|
||||
import httpCodes from 'http-status-codes';
|
||||
|
||||
export const DEFAULT_MIN_LIMIT_PASSWORD = 3;
|
||||
|
||||
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,
|
||||
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 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_HTML: 'text/html',
|
||||
AUTHORIZATION: 'authorization',
|
||||
FORWARDED_PROTO: 'X-Forwarded-Proto',
|
||||
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',
|
||||
};
|
||||
|
||||
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",
|
||||
FILE_NOT_FOUND: 'File not found',
|
||||
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',
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
108
packages/core/commons-api/test/errors.spec.ts
Normal file
108
packages/core/commons-api/test/errors.spec.ts
Normal file
@ -0,0 +1,108 @@
|
||||
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);
|
||||
});
|
||||
});
|
9
packages/core/commons-api/tsconfig.json
Normal file
9
packages/core/commons-api/tsconfig.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"extends": "../../../tsconfig",
|
||||
"compilerOptions": {
|
||||
"rootDir": "./src",
|
||||
"outDir": "./build"
|
||||
},
|
||||
"include": ["src/**/*"],
|
||||
"exclude": ["src/**/*.test.ts"]
|
||||
}
|
20
packages/core/commons-api/types/lockfile.d.ts
vendored
Normal file
20
packages/core/commons-api/types/lockfile.d.ts
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
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;
|
||||
}
|
@ -31,7 +31,7 @@
|
||||
"node": ">=8"
|
||||
},
|
||||
"dependencies": {
|
||||
"@verdaccio/commons-api": "^9.7.1",
|
||||
"@verdaccio/commons-api": "workspace:*",
|
||||
"@verdaccio/file-locking": "workspace:*",
|
||||
"@verdaccio/streams": "workspace:*",
|
||||
"async": "^3.2.0",
|
||||
|
@ -15,7 +15,7 @@
|
||||
"license": "MIT",
|
||||
"homepage": "https://verdaccio.org",
|
||||
"dependencies": {
|
||||
"@verdaccio/commons-api": "9.6.1",
|
||||
"@verdaccio/commons-api": "workspace:*",
|
||||
"@verdaccio/logger": "5.0.0-alpha.0",
|
||||
"handlebars": "4.5.3",
|
||||
"request": "2.87.0"
|
||||
|
@ -21,7 +21,7 @@
|
||||
"@verdaccio/mock": "workspace:5.0.0-alpha.0",
|
||||
"@verdaccio/dev-types": "workspace:5.0.0-alpha.0",
|
||||
"@verdaccio/config": "workspace:5.0.0-alpha.0",
|
||||
"@verdaccio/commons-api": "^9.7.1",
|
||||
"@verdaccio/commons-api": "workspace:*",
|
||||
"@verdaccio/types": "9.5.0"
|
||||
},
|
||||
"homepage": "https://verdaccio.org",
|
||||
|
@ -22,7 +22,7 @@
|
||||
"build": "pnpm run build:js && pnpm run build:types"
|
||||
},
|
||||
"dependencies": {
|
||||
"@verdaccio/commons-api": "9.6.1",
|
||||
"@verdaccio/commons-api": "workspace:*",
|
||||
"@verdaccio/dev-commons": "5.0.0-alpha.0",
|
||||
"dayjs": "1.8.19",
|
||||
"fast-safe-stringify": "2.0.7",
|
||||
|
@ -22,7 +22,7 @@
|
||||
"build": "pnpm run build:js && pnpm run build:types"
|
||||
},
|
||||
"dependencies": {
|
||||
"@verdaccio/commons-api": "9.6.1",
|
||||
"@verdaccio/commons-api": "workspace:*",
|
||||
"@verdaccio/dev-commons": "5.0.0-alpha.0",
|
||||
"@verdaccio/logger": "5.0.0-alpha.0",
|
||||
"@verdaccio/utils": "5.0.0-alpha.0",
|
||||
|
@ -32,7 +32,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@verdaccio/proxy": "5.0.0-alpha.0",
|
||||
"@verdaccio/commons-api": "9.7.1",
|
||||
"@verdaccio/commons-api": "workspace:*",
|
||||
"@verdaccio/dev-types": "5.0.0-alpha.0",
|
||||
"@verdaccio/mock": "5.0.0-alpha.0",
|
||||
"http-errors": "1.7.3",
|
||||
|
@ -23,7 +23,7 @@
|
||||
"build": "pnpm run build:js && pnpm run build:types"
|
||||
},
|
||||
"dependencies": {
|
||||
"@verdaccio/commons-api": "9.6.1",
|
||||
"@verdaccio/commons-api": "workspace:*",
|
||||
"@verdaccio/dev-commons": "5.0.0-alpha.0",
|
||||
"@verdaccio/loaders": "5.0.0-alpha.0",
|
||||
"@verdaccio/local-storage": "9.6.1",
|
||||
|
@ -15,7 +15,7 @@
|
||||
"license": "MIT",
|
||||
"homepage": "https://verdaccio.org",
|
||||
"dependencies": {
|
||||
"@verdaccio/commons-api": "^9.7.1",
|
||||
"@verdaccio/commons-api": "workspace:*",
|
||||
"@verdaccio/dev-commons": "workspace:5.0.0-alpha.0",
|
||||
"@verdaccio/readme": "workspace:*",
|
||||
"js-yaml": "3.13.1",
|
||||
|
47
pnpm-lock.yaml
generated
47
pnpm-lock.yaml
generated
@ -165,7 +165,7 @@ importers:
|
||||
packages/api:
|
||||
dependencies:
|
||||
'@verdaccio/auth': 'link:../auth'
|
||||
'@verdaccio/commons-api': 9.6.1
|
||||
'@verdaccio/commons-api': 'link:../core/commons-api'
|
||||
'@verdaccio/dev-commons': 'link:../commons'
|
||||
'@verdaccio/hooks': 'link:../hooks'
|
||||
'@verdaccio/logger': 'link:../logger'
|
||||
@ -186,7 +186,7 @@ importers:
|
||||
supertest: 5.0.0-0
|
||||
specifiers:
|
||||
'@verdaccio/auth': 5.0.0-alpha.0
|
||||
'@verdaccio/commons-api': 9.6.1
|
||||
'@verdaccio/commons-api': 'workspace:*'
|
||||
'@verdaccio/config': 5.0.0-alpha.0
|
||||
'@verdaccio/dev-commons': 5.0.0-alpha.0
|
||||
'@verdaccio/dev-types': 5.0.0-alpha.0
|
||||
@ -206,7 +206,7 @@ importers:
|
||||
supertest: next
|
||||
packages/auth:
|
||||
dependencies:
|
||||
'@verdaccio/commons-api': 9.6.1
|
||||
'@verdaccio/commons-api': 'link:../core/commons-api'
|
||||
'@verdaccio/dev-commons': 'link:../commons'
|
||||
'@verdaccio/loaders': 'link:../loaders'
|
||||
'@verdaccio/logger': 'link:../logger'
|
||||
@ -219,7 +219,7 @@ importers:
|
||||
'@verdaccio/mock': 'link:../mock'
|
||||
'@verdaccio/types': 9.5.0
|
||||
specifiers:
|
||||
'@verdaccio/commons-api': 9.6.1
|
||||
'@verdaccio/commons-api': 'workspace:*'
|
||||
'@verdaccio/config': 'workspace:5.0.0-alpha.0'
|
||||
'@verdaccio/dev-commons': 5.0.0-alpha.0
|
||||
'@verdaccio/dev-types': 'workspace:5.0.0-alpha.0'
|
||||
@ -265,6 +265,13 @@ importers:
|
||||
'@verdaccio/logger': 'workspace:5.0.0-alpha.0'
|
||||
'@verdaccio/utils': 'workspace:5.0.0-alpha.0'
|
||||
mkdirp: 0.5.5
|
||||
packages/core/commons-api:
|
||||
dependencies:
|
||||
http-errors: 1.8.0
|
||||
http-status-codes: 1.4.0
|
||||
specifiers:
|
||||
http-errors: ^1.8.0
|
||||
http-status-codes: ^1.4.0
|
||||
packages/core/file-locking:
|
||||
dependencies:
|
||||
lockfile: 1.0.4
|
||||
@ -293,7 +300,7 @@ importers:
|
||||
unix-crypt-td-js: 1.1.4
|
||||
packages/core/local-storage:
|
||||
dependencies:
|
||||
'@verdaccio/commons-api': 9.7.1
|
||||
'@verdaccio/commons-api': 'link:../commons-api'
|
||||
'@verdaccio/file-locking': 'link:../file-locking'
|
||||
'@verdaccio/streams': 'link:../streams'
|
||||
async: 3.2.0
|
||||
@ -307,7 +314,7 @@ importers:
|
||||
rmdir-sync: 1.0.1
|
||||
specifiers:
|
||||
'@types/minimatch': ^3.0.3
|
||||
'@verdaccio/commons-api': ^9.7.1
|
||||
'@verdaccio/commons-api': 'workspace:*'
|
||||
'@verdaccio/file-locking': 'workspace:*'
|
||||
'@verdaccio/streams': 'workspace:*'
|
||||
'@verdaccio/types': 'workspace:*'
|
||||
@ -338,7 +345,7 @@ importers:
|
||||
specifiers: {}
|
||||
packages/hooks:
|
||||
dependencies:
|
||||
'@verdaccio/commons-api': 9.6.1
|
||||
'@verdaccio/commons-api': 'link:../core/commons-api'
|
||||
'@verdaccio/logger': 'link:../logger'
|
||||
handlebars: 4.5.3
|
||||
request: 2.87.0
|
||||
@ -351,7 +358,7 @@ importers:
|
||||
'@verdaccio/utils': 'link:../utils'
|
||||
specifiers:
|
||||
'@verdaccio/auth': 5.0.0-alpha.0
|
||||
'@verdaccio/commons-api': 9.6.1
|
||||
'@verdaccio/commons-api': 'workspace:*'
|
||||
'@verdaccio/config': 5.0.0-alpha.0
|
||||
'@verdaccio/dev-commons': 5.0.0-alpha.0
|
||||
'@verdaccio/dev-types': 5.0.0-alpha.0
|
||||
@ -366,13 +373,13 @@ importers:
|
||||
'@verdaccio/logger': 'link:../logger'
|
||||
lodash: 4.17.15
|
||||
devDependencies:
|
||||
'@verdaccio/commons-api': 9.7.1
|
||||
'@verdaccio/commons-api': 'link:../core/commons-api'
|
||||
'@verdaccio/config': 'link:../config'
|
||||
'@verdaccio/dev-types': 'link:../types'
|
||||
'@verdaccio/mock': 'link:../mock'
|
||||
'@verdaccio/types': 9.5.0
|
||||
specifiers:
|
||||
'@verdaccio/commons-api': ^9.7.1
|
||||
'@verdaccio/commons-api': 'workspace:*'
|
||||
'@verdaccio/config': 'workspace:5.0.0-alpha.0'
|
||||
'@verdaccio/dev-commons': 'workspace:5.0.0-alpha.0'
|
||||
'@verdaccio/dev-types': 'workspace:5.0.0-alpha.0'
|
||||
@ -396,7 +403,7 @@ importers:
|
||||
pino: 5.17.0
|
||||
packages/logger-prettify:
|
||||
dependencies:
|
||||
'@verdaccio/commons-api': 9.6.1
|
||||
'@verdaccio/commons-api': 'link:../core/commons-api'
|
||||
'@verdaccio/dev-commons': 'link:../commons'
|
||||
dayjs: 1.8.19
|
||||
fast-safe-stringify: 2.0.7
|
||||
@ -411,7 +418,7 @@ importers:
|
||||
pino: 6.2.1
|
||||
specifiers:
|
||||
'@types/pino': 6.0.1
|
||||
'@verdaccio/commons-api': 9.6.1
|
||||
'@verdaccio/commons-api': 'workspace:*'
|
||||
'@verdaccio/dev-commons': 5.0.0-alpha.0
|
||||
dayjs: 1.8.19
|
||||
fast-safe-stringify: 2.0.7
|
||||
@ -424,7 +431,7 @@ importers:
|
||||
pretty-ms: 5.0.0
|
||||
packages/middleware:
|
||||
dependencies:
|
||||
'@verdaccio/commons-api': 9.6.1
|
||||
'@verdaccio/commons-api': 'link:../core/commons-api'
|
||||
'@verdaccio/dev-commons': 'link:../commons'
|
||||
'@verdaccio/logger': 'link:../logger'
|
||||
'@verdaccio/utils': 'link:../utils'
|
||||
@ -432,7 +439,7 @@ importers:
|
||||
devDependencies:
|
||||
'@verdaccio/dev-types': 'link:../types'
|
||||
specifiers:
|
||||
'@verdaccio/commons-api': 9.6.1
|
||||
'@verdaccio/commons-api': 'workspace:*'
|
||||
'@verdaccio/dev-commons': 5.0.0-alpha.0
|
||||
'@verdaccio/dev-types': 5.0.0-alpha.0
|
||||
'@verdaccio/logger': 5.0.0-alpha.0
|
||||
@ -517,7 +524,7 @@ importers:
|
||||
express: 4.17.1
|
||||
lodash: 4.17.15
|
||||
devDependencies:
|
||||
'@verdaccio/commons-api': 9.7.1
|
||||
'@verdaccio/commons-api': 'link:../core/commons-api'
|
||||
'@verdaccio/dev-types': 'link:../types'
|
||||
'@verdaccio/mock': 'link:../mock'
|
||||
'@verdaccio/proxy': 'link:../proxy'
|
||||
@ -527,7 +534,7 @@ importers:
|
||||
specifiers:
|
||||
'@verdaccio/api': 5.0.0-alpha.0
|
||||
'@verdaccio/auth': 5.0.0-alpha.0
|
||||
'@verdaccio/commons-api': 9.7.1
|
||||
'@verdaccio/commons-api': 'workspace:*'
|
||||
'@verdaccio/config': 5.0.0-alpha.0
|
||||
'@verdaccio/dev-commons': 5.0.0-alpha.0
|
||||
'@verdaccio/dev-types': 5.0.0-alpha.0
|
||||
@ -548,7 +555,7 @@ importers:
|
||||
verdaccio: ~4.4.0
|
||||
packages/store:
|
||||
dependencies:
|
||||
'@verdaccio/commons-api': 9.6.1
|
||||
'@verdaccio/commons-api': 'link:../core/commons-api'
|
||||
'@verdaccio/dev-commons': 'link:../commons'
|
||||
'@verdaccio/loaders': 'link:../loaders'
|
||||
'@verdaccio/local-storage': 9.6.1
|
||||
@ -567,7 +574,7 @@ importers:
|
||||
'@verdaccio/mock': 'link:../mock'
|
||||
'@verdaccio/types': 9.5.0
|
||||
specifiers:
|
||||
'@verdaccio/commons-api': 9.6.1
|
||||
'@verdaccio/commons-api': 'workspace:*'
|
||||
'@verdaccio/config': 5.0.0-alpha.0
|
||||
'@verdaccio/dev-commons': 5.0.0-alpha.0
|
||||
'@verdaccio/dev-types': 5.0.0-alpha.0
|
||||
@ -591,7 +598,7 @@ importers:
|
||||
lunr-mutable-indexes: ^2.3.2
|
||||
packages/utils:
|
||||
dependencies:
|
||||
'@verdaccio/commons-api': 9.7.1
|
||||
'@verdaccio/commons-api': 'link:../core/commons-api'
|
||||
'@verdaccio/dev-commons': 'link:../commons'
|
||||
'@verdaccio/readme': 'link:../core/readme'
|
||||
js-yaml: 3.13.1
|
||||
@ -605,7 +612,7 @@ importers:
|
||||
lodash: 4.17.19
|
||||
specifiers:
|
||||
'@types/minimatch': 3.0.3
|
||||
'@verdaccio/commons-api': ^9.7.1
|
||||
'@verdaccio/commons-api': 'workspace:*'
|
||||
'@verdaccio/dev-commons': 'workspace:5.0.0-alpha.0'
|
||||
'@verdaccio/dev-types': 'workspace:5.0.0-alpha.0'
|
||||
'@verdaccio/logger': 'workspace:5.0.0-alpha.0'
|
||||
|
Loading…
Reference in New Issue
Block a user