@verdaccio/core 6.0.0-6-next.47 → 6.0.0-6-next.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/build/constants.d.ts +2 -1
- package/build/constants.js +4 -3
- package/build/constants.js.map +1 -1
- package/build/error-utils.d.ts +1 -1
- package/build/error-utils.js +1 -1
- package/build/error-utils.js.map +1 -1
- package/build/index.d.ts +3 -2
- package/build/index.js +7 -3
- package/build/index.js.map +1 -1
- package/build/plugin-utils.d.ts +126 -10
- package/build/plugin-utils.js +23 -0
- package/build/plugin-utils.js.map +1 -1
- package/build/stream-utils.d.ts +3 -37
- package/build/stream-utils.js +1 -79
- package/build/stream-utils.js.map +1 -1
- package/build/string-utils.d.ts +8 -0
- package/build/string-utils.js +44 -0
- package/build/string-utils.js.map +1 -0
- package/build/validation-utils.d.ts +1 -0
- package/build/validation-utils.js +5 -0
- package/build/validation-utils.js.map +1 -1
- package/build/warning-utils.d.ts +1 -1
- package/build/warning-utils.js.map +1 -1
- package/package.json +6 -3
- package/src/constants.ts +2 -1
- package/src/error-utils.ts +2 -4
- package/src/index.ts +3 -1
- package/src/plugin-utils.ts +159 -9
- package/src/stream-utils.ts +3 -84
- package/src/string-utils.ts +36 -0
- package/src/validation-utils.ts +10 -1
- package/src/warning-utils.ts +1 -1
- package/test/mystreams.spec.ts +1 -27
- package/test/string-utils.spec.ts +40 -0
- package/test/validation-utilts.spec.ts +52 -1
- package/tsconfig.build.json +2 -1
- package/tsconfig.json +2 -1
- package/typedoc.json +5 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @verdaccio/core
|
|
2
2
|
|
|
3
|
+
## 6.0.0-6-next.49
|
|
4
|
+
|
|
5
|
+
## 6.0.0-6-next.48
|
|
6
|
+
|
|
7
|
+
### Minor Changes
|
|
8
|
+
|
|
9
|
+
- 62c24b63: feat: add passwordValidationRegex property
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 43f32687: fix: abbreviated headers handle quality values
|
|
14
|
+
|
|
3
15
|
## 6.0.0-6-next.47
|
|
4
16
|
|
|
5
17
|
## 6.0.0-6-next.8
|
package/build/constants.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const DEFAULT_PASSWORD_VALIDATION: RegExp;
|
|
2
2
|
export declare const TIME_EXPIRATION_24H = "24h";
|
|
3
3
|
export declare const TIME_EXPIRATION_7D = "7d";
|
|
4
4
|
export declare const DIST_TAGS = "dist-tags";
|
|
@@ -37,6 +37,7 @@ export declare const HEADERS: {
|
|
|
37
37
|
NONE_MATCH: string;
|
|
38
38
|
ETAG: string;
|
|
39
39
|
JSON_CHARSET: string;
|
|
40
|
+
JSON_INSTALL_CHARSET: string;
|
|
40
41
|
OCTET_STREAM: string;
|
|
41
42
|
TEXT_CHARSET: string;
|
|
42
43
|
WWW_AUTH: string;
|
package/build/constants.js
CHANGED
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.USERS = exports.TOKEN_BEARER = exports.TOKEN_BASIC = exports.TIME_EXPIRATION_7D = exports.TIME_EXPIRATION_24H = exports.ROLES = exports.PACKAGE_ACCESS = exports.LOG_VERDACCIO_ERROR = exports.LOG_VERDACCIO_BYTES = exports.LOG_STATUS_MESSAGE = exports.LATEST = exports.HTTP_STATUS = exports.HEADER_TYPE = exports.HEADERS = exports.ERROR_CODE = exports.DIST_TAGS = exports.DEFAULT_USER = exports.
|
|
6
|
+
exports.USERS = exports.TOKEN_BEARER = exports.TOKEN_BASIC = exports.TIME_EXPIRATION_7D = exports.TIME_EXPIRATION_24H = exports.ROLES = exports.PACKAGE_ACCESS = exports.LOG_VERDACCIO_ERROR = exports.LOG_VERDACCIO_BYTES = exports.LOG_STATUS_MESSAGE = exports.LATEST = exports.HTTP_STATUS = exports.HEADER_TYPE = exports.HEADERS = exports.ERROR_CODE = exports.DIST_TAGS = exports.DEFAULT_USER = exports.DEFAULT_PASSWORD_VALIDATION = exports.CHARACTER_ENCODING = exports.API_MESSAGE = void 0;
|
|
7
7
|
|
|
8
8
|
var _httpStatusCodes = _interopRequireDefault(require("http-status-codes"));
|
|
9
9
|
|
|
10
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
11
|
|
|
12
|
-
const
|
|
13
|
-
exports.
|
|
12
|
+
const DEFAULT_PASSWORD_VALIDATION = /.{3}$/;
|
|
13
|
+
exports.DEFAULT_PASSWORD_VALIDATION = DEFAULT_PASSWORD_VALIDATION;
|
|
14
14
|
const TIME_EXPIRATION_24H = '24h';
|
|
15
15
|
exports.TIME_EXPIRATION_24H = TIME_EXPIRATION_24H;
|
|
16
16
|
const TIME_EXPIRATION_7D = '7d';
|
|
@@ -62,6 +62,7 @@ const HEADERS = {
|
|
|
62
62
|
NONE_MATCH: 'If-None-Match',
|
|
63
63
|
ETAG: 'ETag',
|
|
64
64
|
JSON_CHARSET: 'application/json; charset=utf-8',
|
|
65
|
+
JSON_INSTALL_CHARSET: 'application/vnd.npm.install-v1+json; charset=utf-8',
|
|
65
66
|
OCTET_STREAM: 'application/octet-stream; charset=utf-8',
|
|
66
67
|
TEXT_CHARSET: 'text/plain; charset=utf-8',
|
|
67
68
|
WWW_AUTH: 'WWW-Authenticate',
|
package/build/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","names":["
|
|
1
|
+
{"version":3,"file":"constants.js","names":["DEFAULT_PASSWORD_VALIDATION","TIME_EXPIRATION_24H","TIME_EXPIRATION_7D","DIST_TAGS","LATEST","USERS","DEFAULT_USER","HEADER_TYPE","CONTENT_ENCODING","CONTENT_TYPE","CONTENT_LENGTH","ACCEPT_ENCODING","CHARACTER_ENCODING","UTF8","TOKEN_BASIC","TOKEN_BEARER","HEADERS","ACCEPT","USER_AGENT","JSON","TEXT_PLAIN","TEXT_PLAIN_UTF8","TEXT_HTML_UTF8","TEXT_HTML","AUTHORIZATION","FORWARDED_PROTO","FORWARDED_FOR","FRAMES_OPTIONS","CSP","CTO","XSS","NONE_MATCH","ETAG","JSON_CHARSET","JSON_INSTALL_CHARSET","OCTET_STREAM","TEXT_CHARSET","WWW_AUTH","GZIP","HTTP_STATUS","OK","httpCodes","CREATED","MULTIPLE_CHOICES","NOT_MODIFIED","BAD_REQUEST","UNAUTHORIZED","FORBIDDEN","NOT_FOUND","CONFLICT","NOT_IMPLEMENTED","UNSUPPORTED_MEDIA","UNSUPPORTED_MEDIA_TYPE","BAD_DATA","UNPROCESSABLE_ENTITY","INTERNAL_ERROR","INTERNAL_SERVER_ERROR","SERVICE_UNAVAILABLE","LOOP_DETECTED","ERROR_CODE","token_required","API_MESSAGE","PKG_CREATED","PKG_CHANGED","PKG_REMOVED","PKG_PUBLISHED","TARBALL_UPLOADED","TARBALL_REMOVED","TAG_UPDATED","TAG_REMOVED","TAG_ADDED","LOGGED_OUT","LOG_STATUS_MESSAGE","LOG_VERDACCIO_ERROR","LOG_VERDACCIO_BYTES","ROLES","$ALL","ALL","$AUTH","$ANONYMOUS","DEPRECATED_ALL","DEPRECATED_AUTH","DEPRECATED_ANONYMOUS","PACKAGE_ACCESS","SCOPE"],"sources":["../src/constants.ts"],"sourcesContent":["import httpCodes from 'http-status-codes';\n\nexport const DEFAULT_PASSWORD_VALIDATION = /.{3}$/;\nexport const TIME_EXPIRATION_24H = '24h';\nexport const TIME_EXPIRATION_7D = '7d';\nexport const DIST_TAGS = 'dist-tags';\nexport const LATEST = 'latest';\nexport const USERS = 'users';\nexport const DEFAULT_USER = 'Anonymous';\n\nexport const HEADER_TYPE = {\n CONTENT_ENCODING: 'content-encoding',\n CONTENT_TYPE: 'content-type',\n CONTENT_LENGTH: 'content-length',\n ACCEPT_ENCODING: 'accept-encoding',\n};\n\nexport const CHARACTER_ENCODING = {\n UTF8: 'utf8',\n};\n\n// @deprecated use Bearer instead\nexport const TOKEN_BASIC = 'Basic';\nexport const TOKEN_BEARER = 'Bearer';\n\nexport const HEADERS = {\n ACCEPT: 'Accept',\n ACCEPT_ENCODING: 'Accept-Encoding',\n USER_AGENT: 'User-Agent',\n JSON: 'application/json',\n CONTENT_TYPE: 'Content-type',\n CONTENT_LENGTH: 'content-length',\n TEXT_PLAIN: 'text/plain',\n TEXT_PLAIN_UTF8: 'text/plain; charset=utf-8',\n TEXT_HTML_UTF8: 'text/html; charset=utf-8',\n TEXT_HTML: 'text/html',\n AUTHORIZATION: 'authorization',\n // only set with proxy that setup HTTPS\n // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Proto\n FORWARDED_PROTO: 'X-Forwarded-Proto',\n FORWARDED_FOR: 'X-Forwarded-For',\n FRAMES_OPTIONS: 'X-Frame-Options',\n CSP: 'Content-Security-Policy',\n CTO: 'X-Content-Type-Options',\n XSS: 'X-XSS-Protection',\n NONE_MATCH: 'If-None-Match',\n ETAG: 'ETag',\n JSON_CHARSET: 'application/json; charset=utf-8',\n JSON_INSTALL_CHARSET: 'application/vnd.npm.install-v1+json; charset=utf-8',\n OCTET_STREAM: 'application/octet-stream; charset=utf-8',\n TEXT_CHARSET: 'text/plain; charset=utf-8',\n WWW_AUTH: 'WWW-Authenticate',\n GZIP: 'gzip',\n};\n\nexport const HTTP_STATUS = {\n OK: httpCodes.OK,\n CREATED: httpCodes.CREATED,\n MULTIPLE_CHOICES: httpCodes.MULTIPLE_CHOICES,\n NOT_MODIFIED: httpCodes.NOT_MODIFIED,\n BAD_REQUEST: httpCodes.BAD_REQUEST,\n UNAUTHORIZED: httpCodes.UNAUTHORIZED,\n FORBIDDEN: httpCodes.FORBIDDEN,\n NOT_FOUND: httpCodes.NOT_FOUND,\n CONFLICT: httpCodes.CONFLICT,\n NOT_IMPLEMENTED: httpCodes.NOT_IMPLEMENTED,\n UNSUPPORTED_MEDIA: httpCodes.UNSUPPORTED_MEDIA_TYPE,\n BAD_DATA: httpCodes.UNPROCESSABLE_ENTITY,\n INTERNAL_ERROR: httpCodes.INTERNAL_SERVER_ERROR,\n SERVICE_UNAVAILABLE: httpCodes.SERVICE_UNAVAILABLE,\n LOOP_DETECTED: 508,\n};\n\nexport const ERROR_CODE = {\n token_required: 'token is required',\n};\n\nexport const API_MESSAGE = {\n PKG_CREATED: 'created new package',\n PKG_CHANGED: 'package changed',\n PKG_REMOVED: 'package removed',\n PKG_PUBLISHED: 'package published',\n TARBALL_UPLOADED: 'tarball uploaded successfully',\n TARBALL_REMOVED: 'tarball removed',\n TAG_UPDATED: 'tags updated',\n TAG_REMOVED: 'tag removed',\n TAG_ADDED: 'package tagged',\n OK: 'ok',\n LOGGED_OUT: 'Logged out',\n};\n\nexport const LOG_STATUS_MESSAGE =\n \"@{status}, user: @{user}(@{remoteIP}), req: '@{request.method} @{request.url}'\";\nexport const LOG_VERDACCIO_ERROR = `${LOG_STATUS_MESSAGE}, error: @{!error}`;\nexport const LOG_VERDACCIO_BYTES = `${LOG_STATUS_MESSAGE}, bytes: @{bytes.in}/@{bytes.out}`;\n\nexport const ROLES = {\n $ALL: '$all',\n ALL: 'all',\n $AUTH: '$authenticated',\n $ANONYMOUS: '$anonymous',\n DEPRECATED_ALL: '@all',\n DEPRECATED_AUTH: '@authenticated',\n DEPRECATED_ANONYMOUS: '@anonymous',\n};\n\nexport const PACKAGE_ACCESS = {\n SCOPE: '@*/*',\n ALL: '**',\n};\n"],"mappings":";;;;;;;AAAA;;;;AAEO,MAAMA,2BAA2B,GAAG,OAApC;;AACA,MAAMC,mBAAmB,GAAG,KAA5B;;AACA,MAAMC,kBAAkB,GAAG,IAA3B;;AACA,MAAMC,SAAS,GAAG,WAAlB;;AACA,MAAMC,MAAM,GAAG,QAAf;;AACA,MAAMC,KAAK,GAAG,OAAd;;AACA,MAAMC,YAAY,GAAG,WAArB;;AAEA,MAAMC,WAA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E5BP,GAAG,EAAE;AAFuB,CAAvB"}
|
package/build/error-utils.d.ts
CHANGED
package/build/error-utils.js
CHANGED
|
@@ -21,7 +21,7 @@ var _constants = require("./constants");
|
|
|
21
21
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
22
22
|
|
|
23
23
|
const API_ERROR = {
|
|
24
|
-
PASSWORD_SHORT:
|
|
24
|
+
PASSWORD_SHORT: `The provided password does not pass the validation`,
|
|
25
25
|
MUST_BE_LOGGED: 'You must be logged in to publish packages.',
|
|
26
26
|
PLUGIN_ERROR: 'bug in the auth plugin system',
|
|
27
27
|
CONFIG_BAD_FORMAT: 'config file must be an object',
|
package/build/error-utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-utils.js","names":["API_ERROR","PASSWORD_SHORT","
|
|
1
|
+
{"version":3,"file":"error-utils.js","names":["API_ERROR","PASSWORD_SHORT","MUST_BE_LOGGED","PLUGIN_ERROR","CONFIG_BAD_FORMAT","BAD_USERNAME_PASSWORD","NO_PACKAGE","PACKAGE_CANNOT_BE_ADDED","BAD_DATA","NOT_ALLOWED","NOT_ALLOWED_PUBLISH","INTERNAL_SERVER_ERROR","UNKNOWN_ERROR","NOT_PACKAGE_UPLINK","UPLINK_OFFLINE_PUBLISH","UPLINK_OFFLINE","NOT_MODIFIED_NO_DATA","CONTENT_MISMATCH","NOT_FILE_UPLINK","MAX_USERS_REACHED","VERSION_NOT_EXIST","NO_SUCH_FILE","UNSUPORTED_REGISTRY_CALL","FILE_NOT_FOUND","REGISTRATION_DISABLED","UNAUTHORIZED_ACCESS","BAD_STATUS_CODE","PACKAGE_EXIST","BAD_AUTH_HEADER","WEB_DISABLED","DEPRECATED_BASIC_HEADER","BAD_FORMAT_USER_GROUP","RESOURCE_UNAVAILABLE","BAD_PACKAGE_DATA","USERNAME_PASSWORD_REQUIRED","USERNAME_ALREADY_REGISTERED","SUPPORT_ERRORS","PLUGIN_MISSING_INTERFACE","TFA_DISABLED","STORAGE_NOT_IMPLEMENT","PARAMETERS_NOT_VALID","APP_ERROR","CONFIG_NOT_VALID","PROFILE_ERROR","PASSWORD_VALIDATION","getError","code","message","httpError","createError","getConflict","HTTP_STATUS","CONFLICT","getBadData","customMessage","getBadRequest","BAD_REQUEST","getInternalError","INTERNAL_ERROR","getUnauthorized","UNAUTHORIZED","getForbidden","FORBIDDEN","getServiceUnavailable","SERVICE_UNAVAILABLE","getNotFound","NOT_FOUND","getCode","statusCode"],"sources":["../src/error-utils.ts"],"sourcesContent":["import createError, { HttpError } from 'http-errors';\n\nimport { HTTP_STATUS } from './constants';\n\nexport const API_ERROR = {\n PASSWORD_SHORT: `The provided password does not pass the validation`,\n MUST_BE_LOGGED: 'You must be logged in to publish packages.',\n PLUGIN_ERROR: 'bug in the auth plugin system',\n CONFIG_BAD_FORMAT: 'config file must be an object',\n BAD_USERNAME_PASSWORD: 'bad username/password, access denied',\n NO_PACKAGE: 'no such package available',\n PACKAGE_CANNOT_BE_ADDED: 'this package cannot be added',\n BAD_DATA: 'bad data',\n NOT_ALLOWED: 'not allowed to access package',\n NOT_ALLOWED_PUBLISH: 'not allowed to publish package',\n INTERNAL_SERVER_ERROR: 'internal server error',\n UNKNOWN_ERROR: 'unknown error',\n NOT_PACKAGE_UPLINK: 'package does not exist on uplink',\n UPLINK_OFFLINE_PUBLISH: 'one of the uplinks is down, refuse to publish',\n UPLINK_OFFLINE: 'uplink is offline',\n NOT_MODIFIED_NO_DATA: 'no data',\n CONTENT_MISMATCH: 'content length mismatch',\n NOT_FILE_UPLINK: \"file doesn't exist on uplink\",\n MAX_USERS_REACHED: 'maximum amount of users reached',\n VERSION_NOT_EXIST: \"this version doesn't exist\",\n NO_SUCH_FILE: 'no such file available',\n UNSUPORTED_REGISTRY_CALL: 'unsupported registry call',\n FILE_NOT_FOUND: 'File not found',\n REGISTRATION_DISABLED: 'user registration disabled',\n UNAUTHORIZED_ACCESS: 'unauthorized access',\n BAD_STATUS_CODE: 'bad status code',\n PACKAGE_EXIST: 'this package is already present',\n BAD_AUTH_HEADER: 'bad authorization header',\n WEB_DISABLED: 'Web interface is disabled in the config file',\n DEPRECATED_BASIC_HEADER: 'basic authentication is deprecated, please use JWT instead',\n BAD_FORMAT_USER_GROUP: 'user groups is different than an array',\n RESOURCE_UNAVAILABLE: 'resource unavailable',\n BAD_PACKAGE_DATA: 'bad incoming package data',\n USERNAME_PASSWORD_REQUIRED: 'username and password is required',\n USERNAME_ALREADY_REGISTERED: 'username is already registered',\n};\n\nexport const SUPPORT_ERRORS = {\n PLUGIN_MISSING_INTERFACE: 'the plugin does not provide implementation of the requested feature',\n TFA_DISABLED: 'the two-factor authentication is not yet supported',\n STORAGE_NOT_IMPLEMENT: 'the storage does not support token saving',\n PARAMETERS_NOT_VALID: 'the parameters are not valid',\n};\n\nexport const APP_ERROR = {\n CONFIG_NOT_VALID: 'CONFIG: it does not look like a valid config file',\n PROFILE_ERROR: 'profile unexpected error',\n PASSWORD_VALIDATION: 'not valid password',\n};\n\nexport type VerdaccioError = HttpError & { code: number };\n\nfunction getError(code: number, message: string): VerdaccioError {\n const httpError = createError(code, message);\n\n httpError.code = code;\n\n return httpError as VerdaccioError;\n}\n\nexport function getConflict(message: string = API_ERROR.PACKAGE_EXIST): VerdaccioError {\n return getError(HTTP_STATUS.CONFLICT, message);\n}\n\nexport function getBadData(customMessage?: string): VerdaccioError {\n return getError(HTTP_STATUS.BAD_DATA, customMessage || API_ERROR.BAD_DATA);\n}\n\nexport function getBadRequest(customMessage: string): VerdaccioError {\n return getError(HTTP_STATUS.BAD_REQUEST, customMessage);\n}\n\nexport function getInternalError(customMessage?: string): VerdaccioError {\n return customMessage\n ? getError(HTTP_STATUS.INTERNAL_ERROR, customMessage)\n : getError(HTTP_STATUS.INTERNAL_ERROR, API_ERROR.UNKNOWN_ERROR);\n}\n\nexport function getUnauthorized(message = 'no credentials provided'): VerdaccioError {\n return getError(HTTP_STATUS.UNAUTHORIZED, message);\n}\n\nexport function getForbidden(message = \"can't use this filename\"): VerdaccioError {\n return getError(HTTP_STATUS.FORBIDDEN, message);\n}\n\nexport function getServiceUnavailable(\n message: string = API_ERROR.RESOURCE_UNAVAILABLE\n): VerdaccioError {\n return getError(HTTP_STATUS.SERVICE_UNAVAILABLE, message);\n}\n\nexport function getNotFound(customMessage?: string): VerdaccioError {\n return getError(HTTP_STATUS.NOT_FOUND, customMessage || API_ERROR.NO_PACKAGE);\n}\n\nexport function getCode(statusCode: number, customMessage: string): VerdaccioError {\n return getError(statusCode, customMessage);\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;;AAEA;;;;AAEO,MAAMA,SAAS,GAAG;EACvBC,cAAc,EAAG,oDADM;EAEvBC,cAAc,EAAE,4CAFO;EAGvBC,YAAY,EAAE,+BAHS;EAIvBC,iBAAiB,EAAE,+BAJI;EAKvBC,qBAAqB,EAAE,sCALA;EAMvBC,UAAU,EAAE,2BANW;EAOvBC,uBAAuB,EAAE,8BAPF;EAQvBC,QAAQ,EAAE,UARa;EASvBC,WAAW,EAAE,+BATU;EAUvBC,mBAAmB,EAAE,gCAVE;EAWvBC,qBAAqB,EAAE,uBAXA;EAYvBC,aAAa,EAAE,eAZQ;EAavBC,kBAAkB,EAAE,kCAbG;EAcvBC,sBAAsB,EAAE,+CAdD;EAevBC,cAAc,EAAE,mBAfO;EAgBvBC,oBAAoB,EAAE,SAhBC;EAiBvBC,gBAAgB,EAAE,yBAjBK;EAkBvBC,eAAe,EAAE,8BAlBM;EAmBvBC,iBAAiB,EAAE,iCAnBI;EAoBvBC,iBAAiB,EAAE,4BApBI;EAqBvBC,YAAY,EAAE,wBArBS;EAsBvBC,wBAAwB,EAAE,2BAtBH;EAuBvBC,cAAc,EAAE,gBAvBO;EAwBvBC,qBAAqB,EAAE,4BAxBA;EAyBvBC,mBAAmB,EAAE,qBAzBE;EA0BvBC,eAAe,EAAE,iBA1BM;EA2BvBC,aAAa,EAAE,iCA3BQ;EA4BvBC,eAA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A6BJ,aAA7B,CADQ,GAEhBT,QAAQ,CAACM,sBAAA,CAAYO,cAAb,EAA6B1D,SAAS,CAACY,aAAvC,CAFZ;AAGD;;AAEM,SAAS+C,eAAT,CAAyBZ,OAAO,GAAG,yBAAnC,EAA8E;EACnF,OAAOF,QAAQ,CAACM,sBAAA,CAAYS,YAAb,EAA2Bb,OAA3B,CAAf;AACD;;AAEM,SAASc,YAAT,CAAsBd,OAAO,GAAG,yBAAhC,EAA2E;EAChF,OAAOF,QAAQ,CAACM,sBAAA,CAAYW,SAAb,EAAwBf,OAAxB,CAAf;AACD;;AAEM,SAASgB,qBAAT,CACLhB,OAAe,GAAG/C,SAAS,CAACgC,oBADvB,EAEW;EAChB,OAAOa,QAAQ,CAACM,sBAAA,CAAYa,mBAAb,EAAkCjB,OAAlC,CAAf;AACD;;AAEM,SAASkB,WAAT,CAAqBX,aAArB,EAA6D;EAClE,OAAOT,QAAQ,CAACM,sBAAA,CAAYe,SAAb,EAAwBZ,aAAa,IAAItD,SAAS,CAACM,UAAnD,CAAf;AACD;;AAEM,SAAS6D,OAAT,CAAiBC,UAAjB,EAAqCd,aAArC,EAA4E;EACjF,OAAOT,QAAQ,CAACuB,UAAD,EAAad,aAAb,CAAf;AACD"}
|
package/build/index.d.ts
CHANGED
|
@@ -5,9 +5,10 @@ import * as pkgUtils from './pkg-utils';
|
|
|
5
5
|
import * as pluginUtils from './plugin-utils';
|
|
6
6
|
import * as searchUtils from './search-utils';
|
|
7
7
|
import * as streamUtils from './stream-utils';
|
|
8
|
+
import * as stringUtils from './string-utils';
|
|
8
9
|
import * as validatioUtils from './validation-utils';
|
|
9
10
|
import * as warningUtils from './warning-utils';
|
|
10
11
|
export { VerdaccioError, API_ERROR, SUPPORT_ERRORS, APP_ERROR } from './error-utils';
|
|
11
|
-
export { TOKEN_BASIC, TOKEN_BEARER, HTTP_STATUS, API_MESSAGE, HEADERS, DIST_TAGS, CHARACTER_ENCODING, HEADER_TYPE, LATEST,
|
|
12
|
+
export { TOKEN_BASIC, TOKEN_BEARER, HTTP_STATUS, API_MESSAGE, HEADERS, DIST_TAGS, CHARACTER_ENCODING, HEADER_TYPE, LATEST, DEFAULT_PASSWORD_VALIDATION, DEFAULT_USER, USERS, } from './constants';
|
|
12
13
|
declare const validationUtils: typeof validatioUtils;
|
|
13
|
-
export { fileUtils, pkgUtils, searchUtils, streamUtils, errorUtils, validatioUtils, validationUtils, constants, pluginUtils, warningUtils, };
|
|
14
|
+
export { fileUtils, pkgUtils, searchUtils, streamUtils, errorUtils, validatioUtils, validationUtils, stringUtils, constants, pluginUtils, warningUtils, };
|
package/build/index.js
CHANGED
|
@@ -27,10 +27,10 @@ Object.defineProperty(exports, "CHARACTER_ENCODING", {
|
|
|
27
27
|
return constants.CHARACTER_ENCODING;
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
|
-
Object.defineProperty(exports, "
|
|
30
|
+
Object.defineProperty(exports, "DEFAULT_PASSWORD_VALIDATION", {
|
|
31
31
|
enumerable: true,
|
|
32
32
|
get: function () {
|
|
33
|
-
return constants.
|
|
33
|
+
return constants.DEFAULT_PASSWORD_VALIDATION;
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
36
|
Object.defineProperty(exports, "DEFAULT_USER", {
|
|
@@ -99,7 +99,7 @@ Object.defineProperty(exports, "VerdaccioError", {
|
|
|
99
99
|
return errorUtils.VerdaccioError;
|
|
100
100
|
}
|
|
101
101
|
});
|
|
102
|
-
exports.warningUtils = exports.validationUtils = exports.validatioUtils = exports.streamUtils = exports.searchUtils = exports.pluginUtils = exports.pkgUtils = exports.fileUtils = exports.errorUtils = exports.constants = void 0;
|
|
102
|
+
exports.warningUtils = exports.validationUtils = exports.validatioUtils = exports.stringUtils = exports.streamUtils = exports.searchUtils = exports.pluginUtils = exports.pkgUtils = exports.fileUtils = exports.errorUtils = exports.constants = void 0;
|
|
103
103
|
|
|
104
104
|
var constants = _interopRequireWildcard(require("./constants"));
|
|
105
105
|
|
|
@@ -129,6 +129,10 @@ var streamUtils = _interopRequireWildcard(require("./stream-utils"));
|
|
|
129
129
|
|
|
130
130
|
exports.streamUtils = streamUtils;
|
|
131
131
|
|
|
132
|
+
var stringUtils = _interopRequireWildcard(require("./string-utils"));
|
|
133
|
+
|
|
134
|
+
exports.stringUtils = stringUtils;
|
|
135
|
+
|
|
132
136
|
var validatioUtils = _interopRequireWildcard(require("./validation-utils"));
|
|
133
137
|
|
|
134
138
|
exports.validatioUtils = validatioUtils;
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["validationUtils","validatioUtils"],"sources":["../src/index.ts"],"sourcesContent":["import * as constants from './constants';\nimport * as errorUtils from './error-utils';\nimport * as fileUtils from './file-utils';\nimport * as pkgUtils from './pkg-utils';\nimport * as pluginUtils from './plugin-utils';\nimport * as searchUtils from './search-utils';\nimport * as streamUtils from './stream-utils';\nimport * as validatioUtils from './validation-utils';\nimport * as warningUtils from './warning-utils';\n\nexport { VerdaccioError, API_ERROR, SUPPORT_ERRORS, APP_ERROR } from './error-utils';\nexport {\n TOKEN_BASIC,\n TOKEN_BEARER,\n HTTP_STATUS,\n API_MESSAGE,\n HEADERS,\n DIST_TAGS,\n CHARACTER_ENCODING,\n HEADER_TYPE,\n LATEST,\n
|
|
1
|
+
{"version":3,"file":"index.js","names":["validationUtils","validatioUtils"],"sources":["../src/index.ts"],"sourcesContent":["import * as constants from './constants';\nimport * as errorUtils from './error-utils';\nimport * as fileUtils from './file-utils';\nimport * as pkgUtils from './pkg-utils';\nimport * as pluginUtils from './plugin-utils';\nimport * as searchUtils from './search-utils';\nimport * as streamUtils from './stream-utils';\nimport * as stringUtils from './string-utils';\nimport * as validatioUtils from './validation-utils';\nimport * as warningUtils from './warning-utils';\n\nexport { VerdaccioError, API_ERROR, SUPPORT_ERRORS, APP_ERROR } from './error-utils';\nexport {\n TOKEN_BASIC,\n TOKEN_BEARER,\n HTTP_STATUS,\n API_MESSAGE,\n HEADERS,\n DIST_TAGS,\n CHARACTER_ENCODING,\n HEADER_TYPE,\n LATEST,\n DEFAULT_PASSWORD_VALIDATION,\n DEFAULT_USER,\n USERS,\n} from './constants';\nconst validationUtils = validatioUtils;\nexport {\n fileUtils,\n pkgUtils,\n searchUtils,\n streamUtils,\n errorUtils,\n // TODO: remove this typo\n validatioUtils,\n validationUtils,\n stringUtils,\n constants,\n pluginUtils,\n warningUtils,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;;;;;;;AAiBA,MAAMA,eAAe,GAAGC,cAAxB"}
|
package/build/plugin-utils.d.ts
CHANGED
|
@@ -1,21 +1,137 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Express, RequestHandler } from 'express';
|
|
3
|
+
import { Readable, Writable } from 'stream';
|
|
4
|
+
import { AllowAccess, Callback, Config, Logger, Manifest, PackageAccess, RemoteUser, Token, TokenFilter } from '@verdaccio/types';
|
|
5
|
+
import { VerdaccioError, searchUtils } from '.';
|
|
6
|
+
export interface AuthPluginPackage {
|
|
7
|
+
packageName: string;
|
|
8
|
+
packageVersion?: string;
|
|
9
|
+
tag?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface PluginOptions {
|
|
12
|
+
config: Config;
|
|
13
|
+
logger: Logger;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The base plugin class, set of utilities for developing
|
|
17
|
+
* plugins.
|
|
18
|
+
* @alpha
|
|
19
|
+
* */
|
|
20
|
+
export declare class Plugin<PluginConfig> {
|
|
21
|
+
static version: number;
|
|
22
|
+
readonly version: number;
|
|
23
|
+
readonly config: PluginConfig | unknown;
|
|
24
|
+
readonly options: PluginOptions;
|
|
25
|
+
constructor(config: PluginConfig, options: PluginOptions);
|
|
26
|
+
getVersion(): number;
|
|
27
|
+
}
|
|
28
|
+
export interface StorageHandler {
|
|
29
|
+
logger: Logger;
|
|
30
|
+
deletePackage(fileName: string): Promise<void>;
|
|
31
|
+
removePackage(): Promise<void>;
|
|
32
|
+
updatePackage(packageName: string, handleUpdate: (manifest: Manifest) => Promise<Manifest>): Promise<Manifest>;
|
|
33
|
+
readPackage(name: string): Promise<Manifest>;
|
|
34
|
+
savePackage(pkgName: string, value: Manifest): Promise<void>;
|
|
35
|
+
readTarball(pkgName: string, { signal }: {
|
|
36
|
+
signal: AbortSignal;
|
|
37
|
+
}): Promise<Readable>;
|
|
38
|
+
createPackage(name: string, manifest: Manifest): Promise<void>;
|
|
39
|
+
writeTarball(tarballName: string, { signal }: {
|
|
40
|
+
signal: AbortSignal;
|
|
41
|
+
}): Promise<Writable>;
|
|
42
|
+
hasTarball(fileName: string): Promise<boolean>;
|
|
43
|
+
hasPackage(): Promise<boolean>;
|
|
44
|
+
}
|
|
45
|
+
export interface Storage<PluginConfig> extends Plugin<PluginConfig> {
|
|
9
46
|
add(name: string): Promise<void>;
|
|
10
47
|
remove(name: string): Promise<void>;
|
|
11
48
|
get(): Promise<any>;
|
|
12
49
|
init(): Promise<void>;
|
|
13
50
|
getSecret(): Promise<string>;
|
|
14
51
|
setSecret(secret: string): Promise<any>;
|
|
15
|
-
getPackageStorage(packageInfo: string):
|
|
52
|
+
getPackageStorage(packageInfo: string): StorageHandler;
|
|
16
53
|
search(query: searchUtils.SearchQuery): Promise<searchUtils.SearchItem[]>;
|
|
17
54
|
saveToken(token: Token): Promise<any>;
|
|
18
55
|
deleteToken(user: string, tokenKey: string): Promise<any>;
|
|
19
56
|
readTokens(filter: TokenFilter): Promise<Token[]>;
|
|
20
57
|
}
|
|
21
|
-
|
|
58
|
+
/**
|
|
59
|
+
* This function allow add additional middleware to the application.
|
|
60
|
+
*
|
|
61
|
+
* ```ts
|
|
62
|
+
* import express, { Request, Response } from 'express';
|
|
63
|
+
*
|
|
64
|
+
* class Middleware extends Plugin {
|
|
65
|
+
* // instances of auth and storage are injected
|
|
66
|
+
* register_middlewares(app, auth, storage) {
|
|
67
|
+
* const router = express.Router();
|
|
68
|
+
* router.post('/my-endpoint', (req: Request, res: Response): void => {
|
|
69
|
+
res.status(200).end();
|
|
70
|
+
});
|
|
71
|
+
* }
|
|
72
|
+
* }
|
|
73
|
+
*
|
|
74
|
+
*
|
|
75
|
+
* const [plugin] = await asyncLoadPlugin(...);
|
|
76
|
+
* plugin.register_middlewares(app, auth, storage);
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export interface ExpressMiddleware<PluginConfig, Storage, Auth> extends Plugin<PluginConfig> {
|
|
80
|
+
register_middlewares(app: Express, auth: Auth, storage: Storage): void;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* dasdsa
|
|
84
|
+
*/
|
|
85
|
+
export declare type AuthCallback = (error: VerdaccioError | null, groups?: string[] | false) => void;
|
|
86
|
+
export declare type AuthAccessCallback = (error: VerdaccioError | null, access?: boolean) => void;
|
|
87
|
+
export declare type AuthUserCallback = (error: VerdaccioError | null, access?: boolean | string) => void;
|
|
88
|
+
export declare type AuthChangePasswordCallback = (error: VerdaccioError | null, access?: boolean) => void;
|
|
89
|
+
export declare type AccessCallback = (error: VerdaccioError | null, ok?: boolean) => void;
|
|
90
|
+
export interface Auth<T> extends Plugin<T> {
|
|
91
|
+
/**
|
|
92
|
+
* Handles the authenticated method.
|
|
93
|
+
* ```ts
|
|
94
|
+
* class Auth {
|
|
95
|
+
public authenticate(user: string, password: string, done: AuthCallback): void {
|
|
96
|
+
if (!password) {
|
|
97
|
+
return done(errorUtils.getUnauthorized(API_ERROR.BAD_USERNAME_PASSWORD));
|
|
98
|
+
}
|
|
99
|
+
// always return an array of users
|
|
100
|
+
return done(null, [user]);
|
|
101
|
+
* }
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
authenticate(user: string, password: string, cb: AuthCallback): void;
|
|
105
|
+
/**
|
|
106
|
+
* Handles the authenticated method.
|
|
107
|
+
* ```ts
|
|
108
|
+
* class Auth {
|
|
109
|
+
public adduser(user: string, password: string, done: AuthCallback): void {
|
|
110
|
+
if (!password) {
|
|
111
|
+
return done(errorUtils.getUnauthorized(API_ERROR.BAD_USERNAME_PASSWORD));
|
|
112
|
+
}
|
|
113
|
+
// return boolean
|
|
114
|
+
return done(null, true);
|
|
115
|
+
* }
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
adduser?(user: string, password: string, cb: AuthUserCallback): void;
|
|
119
|
+
changePassword?(user: string, password: string, newPassword: string, cb: AuthChangePasswordCallback): void;
|
|
120
|
+
allow_publish?(user: RemoteUser, pkg: T & PackageAccess, cb: AuthAccessCallback): void;
|
|
121
|
+
allow_publish?(user: RemoteUser, pkg: AllowAccess & PackageAccess, cb: AuthAccessCallback): void;
|
|
122
|
+
allow_access?(user: RemoteUser, pkg: T & PackageAccess, cb: AccessCallback): void;
|
|
123
|
+
allow_access?(user: RemoteUser, pkg: AllowAccess & PackageAccess, cb: AccessCallback): void;
|
|
124
|
+
allow_unpublish?(user: RemoteUser, pkg: T & PackageAccess, cb: AuthAccessCallback): void;
|
|
125
|
+
allow_unpublish?(user: RemoteUser, pkg: AllowAccess & PackageAccess, cb: AuthAccessCallback): void;
|
|
126
|
+
apiJWTmiddleware?(helpers: any): RequestHandler;
|
|
127
|
+
}
|
|
128
|
+
export interface IBasicAuth {
|
|
129
|
+
authenticate(user: string, password: string, cb: Callback): void;
|
|
130
|
+
invalidateToken?(token: string): Promise<void>;
|
|
131
|
+
changePassword(user: string, password: string, newPassword: string, cb: Callback): void;
|
|
132
|
+
allow_access(pkg: AuthPluginPackage, user: RemoteUser, callback: Callback): void;
|
|
133
|
+
add_user(user: string, password: string, cb: Callback): any;
|
|
134
|
+
}
|
|
135
|
+
export interface ManifestFilter<T> extends Plugin<T> {
|
|
136
|
+
filterMetadata(packageInfo: Manifest): Promise<Manifest>;
|
|
137
|
+
}
|
package/build/plugin-utils.js
CHANGED
|
@@ -3,4 +3,27 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.Plugin = void 0;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The base plugin class, set of utilities for developing
|
|
10
|
+
* plugins.
|
|
11
|
+
* @alpha
|
|
12
|
+
* */
|
|
13
|
+
class Plugin {
|
|
14
|
+
static version = 1;
|
|
15
|
+
|
|
16
|
+
constructor(config, options) {
|
|
17
|
+
this.version = Plugin.version;
|
|
18
|
+
this.config = config;
|
|
19
|
+
this.options = options;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
getVersion() {
|
|
23
|
+
return this.version;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
exports.Plugin = Plugin;
|
|
6
29
|
//# sourceMappingURL=plugin-utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-utils.js","names":[],"sources":["../src/plugin-utils.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"plugin-utils.js","names":["Plugin","version","constructor","config","options","getVersion"],"sources":["../src/plugin-utils.ts"],"sourcesContent":["import { Express, RequestHandler } from 'express';\nimport { Readable, Writable } from 'stream';\n\nimport {\n AllowAccess,\n Callback,\n Config,\n Logger,\n Manifest,\n PackageAccess,\n RemoteUser,\n Token,\n TokenFilter,\n} from '@verdaccio/types';\n\nimport { VerdaccioError, searchUtils } from '.';\n\nexport interface AuthPluginPackage {\n packageName: string;\n packageVersion?: string;\n tag?: string;\n}\nexport interface PluginOptions {\n config: Config;\n logger: Logger;\n}\n\n/**\n * The base plugin class, set of utilities for developing\n * plugins.\n * @alpha\n * */\nexport class Plugin<PluginConfig> {\n static version = 1;\n public readonly version: number;\n public readonly config: PluginConfig | unknown;\n public readonly options: PluginOptions;\n public constructor(config: PluginConfig, options: PluginOptions) {\n this.version = Plugin.version;\n this.config = config;\n this.options = options;\n }\n\n public getVersion() {\n return this.version;\n }\n}\nexport interface StorageHandler {\n logger: Logger;\n deletePackage(fileName: string): Promise<void>;\n removePackage(): Promise<void>;\n // next packages migration (this list is meant to replace the callback parent functions)\n updatePackage(\n packageName: string,\n handleUpdate: (manifest: Manifest) => Promise<Manifest>\n ): Promise<Manifest>;\n readPackage(name: string): Promise<Manifest>;\n savePackage(pkgName: string, value: Manifest): Promise<void>;\n readTarball(pkgName: string, { signal }: { signal: AbortSignal }): Promise<Readable>;\n createPackage(name: string, manifest: Manifest): Promise<void>;\n writeTarball(tarballName: string, { signal }: { signal: AbortSignal }): Promise<Writable>;\n // verify if tarball exist in the storage\n hasTarball(fileName: string): Promise<boolean>;\n // verify if package exist in the storage\n hasPackage(): Promise<boolean>;\n}\n\nexport interface Storage<PluginConfig> extends Plugin<PluginConfig> {\n add(name: string): Promise<void>;\n remove(name: string): Promise<void>;\n get(): Promise<any>;\n init(): Promise<void>;\n getSecret(): Promise<string>;\n setSecret(secret: string): Promise<any>;\n getPackageStorage(packageInfo: string): StorageHandler;\n search(query: searchUtils.SearchQuery): Promise<searchUtils.SearchItem[]>;\n saveToken(token: Token): Promise<any>;\n deleteToken(user: string, tokenKey: string): Promise<any>;\n readTokens(filter: TokenFilter): Promise<Token[]>;\n}\n\n/**\n * This function allow add additional middleware to the application.\n *\n * ```ts\n * import express, { Request, Response } from 'express';\n * \n * class Middleware extends Plugin {\n * // instances of auth and storage are injected\n * register_middlewares(app, auth, storage) {\n * const router = express.Router();\n * router.post('/my-endpoint', (req: Request, res: Response): void => {\n res.status(200).end();\n });\n * }\n * }\n * \n * \n * const [plugin] = await asyncLoadPlugin(...);\n * plugin.register_middlewares(app, auth, storage);\n * ```\n */\nexport interface ExpressMiddleware<PluginConfig, Storage, Auth> extends Plugin<PluginConfig> {\n register_middlewares(app: Express, auth: Auth, storage: Storage): void;\n}\n\n/**\n * dasdsa\n */\nexport type AuthCallback = (error: VerdaccioError | null, groups?: string[] | false) => void;\n\nexport type AuthAccessCallback = (error: VerdaccioError | null, access?: boolean) => void;\nexport type AuthUserCallback = (error: VerdaccioError | null, access?: boolean | string) => void;\nexport type AuthChangePasswordCallback = (error: VerdaccioError | null, access?: boolean) => void;\nexport type AccessCallback = (error: VerdaccioError | null, ok?: boolean) => void;\nexport interface Auth<T> extends Plugin<T> {\n /**\n * Handles the authenticated method.\n * ```ts\n * class Auth {\n public authenticate(user: string, password: string, done: AuthCallback): void {\n if (!password) {\n return done(errorUtils.getUnauthorized(API_ERROR.BAD_USERNAME_PASSWORD));\n }\n // always return an array of users\n return done(null, [user]); \n * }\n * ```\n */\n authenticate(user: string, password: string, cb: AuthCallback): void;\n /**\n * Handles the authenticated method.\n * ```ts\n * class Auth {\n public adduser(user: string, password: string, done: AuthCallback): void {\n if (!password) {\n return done(errorUtils.getUnauthorized(API_ERROR.BAD_USERNAME_PASSWORD));\n }\n // return boolean\n return done(null, true); \n * }\n * ```\n */\n adduser?(user: string, password: string, cb: AuthUserCallback): void;\n changePassword?(\n user: string,\n password: string,\n newPassword: string,\n cb: AuthChangePasswordCallback\n ): void;\n allow_publish?(user: RemoteUser, pkg: T & PackageAccess, cb: AuthAccessCallback): void;\n allow_publish?(user: RemoteUser, pkg: AllowAccess & PackageAccess, cb: AuthAccessCallback): void;\n allow_access?(user: RemoteUser, pkg: T & PackageAccess, cb: AccessCallback): void;\n allow_access?(user: RemoteUser, pkg: AllowAccess & PackageAccess, cb: AccessCallback): void;\n allow_unpublish?(user: RemoteUser, pkg: T & PackageAccess, cb: AuthAccessCallback): void;\n allow_unpublish?(\n user: RemoteUser,\n pkg: AllowAccess & PackageAccess,\n cb: AuthAccessCallback\n ): void;\n apiJWTmiddleware?(helpers: any): RequestHandler;\n}\n\nexport interface IBasicAuth {\n authenticate(user: string, password: string, cb: Callback): void;\n invalidateToken?(token: string): Promise<void>;\n changePassword(user: string, password: string, newPassword: string, cb: Callback): void;\n allow_access(pkg: AuthPluginPackage, user: RemoteUser, callback: Callback): void;\n add_user(user: string, password: string, cb: Callback): any;\n}\n\nexport interface ManifestFilter<T> extends Plugin<T> {\n filterMetadata(packageInfo: Manifest): Promise<Manifest>;\n}\n"],"mappings":";;;;;;;AA2BA;AACA;AACA;AACA;AACA;AACO,MAAMA,MAAN,CAA2B;EAClB,OAAPC,OAAO,GAAG,CAAH;;EAIPC,WAAW,CAACC,MAAD,EAAuBC,OAAvB,EAA+C;IAC/D,KAAKH,OAAL,GAAeD,MAAM,CAACC,OAAtB;IACA,KAAKE,MAAL,GAAcA,MAAd;IACA,KAAKC,OAAL,GAAeA,OAAf;EACD;;EAEMC,UAAU,GAAG;IAClB,OAAO,KAAKJ,OAAZ;EACD;;AAb+B"}
|
package/build/stream-utils.d.ts
CHANGED
|
@@ -1,45 +1,11 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import {
|
|
3
|
-
export interface IReadTarball {
|
|
4
|
-
abort?: () => void;
|
|
5
|
-
}
|
|
6
|
-
export interface IUploadTarball {
|
|
7
|
-
done?: () => void;
|
|
8
|
-
abort?: () => void;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* This stream is used to read tarballs from repository.
|
|
12
|
-
* @param {*} options
|
|
13
|
-
* @return {Stream}
|
|
14
|
-
*/
|
|
15
|
-
declare class ReadTarball extends PassThrough implements IReadTarball {
|
|
16
|
-
/**
|
|
17
|
-
*
|
|
18
|
-
* @param {Object} options
|
|
19
|
-
*/
|
|
20
|
-
constructor(options: TransformOptions);
|
|
21
|
-
abort(): void;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* This stream is used to upload tarballs to a repository.
|
|
25
|
-
* @param {*} options
|
|
26
|
-
* @return {Stream}
|
|
27
|
-
*/
|
|
28
|
-
declare class UploadTarball extends PassThrough implements IUploadTarball {
|
|
29
|
-
/**
|
|
30
|
-
*
|
|
31
|
-
* @param {Object} options
|
|
32
|
-
*/
|
|
33
|
-
constructor(options: any);
|
|
34
|
-
abort(): void;
|
|
35
|
-
done(): void;
|
|
36
|
-
}
|
|
2
|
+
import { Readable, Transform } from 'stream';
|
|
37
3
|
/**
|
|
38
4
|
* Converts a buffer stream to a string.
|
|
39
5
|
*/
|
|
40
|
-
declare const readableToString: (stream:
|
|
6
|
+
declare const readableToString: (stream: Readable) => Promise<string>;
|
|
41
7
|
/**
|
|
42
8
|
* Transform stream object mode to string
|
|
43
9
|
**/
|
|
44
10
|
declare const transformObjectToString: () => Transform;
|
|
45
|
-
export {
|
|
11
|
+
export { readableToString, transformObjectToString };
|
package/build/stream-utils.js
CHANGED
|
@@ -3,91 +3,13 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.transformObjectToString = exports.readableToString =
|
|
6
|
+
exports.transformObjectToString = exports.readableToString = void 0;
|
|
7
7
|
|
|
8
8
|
var _stream = require("stream");
|
|
9
9
|
|
|
10
|
-
/**
|
|
11
|
-
* This stream is used to read tarballs from repository.
|
|
12
|
-
* @param {*} options
|
|
13
|
-
* @return {Stream}
|
|
14
|
-
*/
|
|
15
|
-
class ReadTarball extends _stream.PassThrough {
|
|
16
|
-
/**
|
|
17
|
-
*
|
|
18
|
-
* @param {Object} options
|
|
19
|
-
*/
|
|
20
|
-
constructor(options) {
|
|
21
|
-
super(options); // called when data is not needed anymore
|
|
22
|
-
|
|
23
|
-
addAbstractMethods(this, 'abort');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
abort() {}
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* This stream is used to upload tarballs to a repository.
|
|
31
|
-
* @param {*} options
|
|
32
|
-
* @return {Stream}
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
exports.ReadTarball = ReadTarball;
|
|
37
|
-
|
|
38
|
-
class UploadTarball extends _stream.PassThrough {
|
|
39
|
-
/**
|
|
40
|
-
*
|
|
41
|
-
* @param {Object} options
|
|
42
|
-
*/
|
|
43
|
-
constructor(options) {
|
|
44
|
-
super(options); // called when user closes connection before upload finishes
|
|
45
|
-
|
|
46
|
-
addAbstractMethods(this, 'abort'); // called when upload finishes successfully
|
|
47
|
-
|
|
48
|
-
addAbstractMethods(this, 'done');
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
abort() {}
|
|
52
|
-
|
|
53
|
-
done() {}
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* This function intercepts abstract calls and replays them allowing.
|
|
58
|
-
* us to attach those functions after we are ready to do so
|
|
59
|
-
* @param {*} self
|
|
60
|
-
* @param {*} name
|
|
61
|
-
*/
|
|
62
|
-
// Perhaps someone knows a better way to write this
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
exports.UploadTarball = UploadTarball;
|
|
66
|
-
|
|
67
|
-
function addAbstractMethods(self, name) {
|
|
68
|
-
self._called_methods = self._called_methods || {};
|
|
69
|
-
|
|
70
|
-
self.__defineGetter__(name, function () {
|
|
71
|
-
return function () {
|
|
72
|
-
self._called_methods[name] = true;
|
|
73
|
-
};
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
self.__defineSetter__(name, function (fn) {
|
|
77
|
-
delete self[name];
|
|
78
|
-
self[name] = fn; // eslint-disable-next-line @typescript-eslint/prefer-optional-chain
|
|
79
|
-
|
|
80
|
-
if (self._called_methods && self._called_methods[name]) {
|
|
81
|
-
delete self._called_methods[name];
|
|
82
|
-
self[name]();
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
10
|
/**
|
|
87
11
|
* Converts a buffer stream to a string.
|
|
88
12
|
*/
|
|
89
|
-
|
|
90
|
-
|
|
91
13
|
const readableToString = async stream => {
|
|
92
14
|
const chunks = [];
|
|
93
15
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-utils.js","names":["
|
|
1
|
+
{"version":3,"file":"stream-utils.js","names":["readableToString","stream","chunks","chunk","push","Buffer","from","buffer","concat","str","toString","transformObjectToString","Transform","objectMode","transform","encoding","callback","JSON","stringify"],"sources":["../src/stream-utils.ts"],"sourcesContent":["import { Readable, Transform } from 'stream';\n\n/**\n * Converts a buffer stream to a string.\n */\nconst readableToString = async (stream: Readable) => {\n const chunks: Buffer[] = [];\n for await (let chunk of stream) {\n chunks.push(Buffer.from(chunk));\n }\n const buffer = Buffer.concat(chunks);\n const str = buffer.toString('utf-8');\n return str;\n};\n\n/**\n * Transform stream object mode to string\n **/\nconst transformObjectToString = () => {\n return new Transform({\n objectMode: true,\n transform: (chunk, encoding, callback) => {\n callback(null, JSON.stringify(chunk));\n },\n });\n};\n\nexport { readableToString, transformObjectToString };\n"],"mappings":";;;;;;;AAAA;;AAEA;AACA;AACA;AACA,MAAMA,gBAAgB,GAAG,MAAOC,MAAP,IAA4B;EACnD,MAAMC,MAAgB,GAAG,EAAzB;;EACA,WAAW,IAAIC,KAAf,IAAwBF,MAAxB,EAAgC;IAC9BC,MAAM,CAACE,IAAP,CAAYC,MAAM,CAACC,IAAP,CAAYH,KAAZ,CAAZ;EACD;;EACD,MAAMI,MAAM,GAAGF,MAAM,CAACG,MAAP,CAAcN,MAAd,CAAf;EACA,MAAMO,GAAG,GAAGF,MAAM,CAACG,QAAP,CAAgB,OAAhB,CAAZ;EACA,OAAOD,GAAP;AACD,CARD;AAUA;AACA;AACA;;;;;AACA,MAAME,uBAAuB,GAAG,MAAM;EACpC,OAAO,IAAIC,iBAAJ,CAAc;IACnBC,UAAU,EAAE,IADO;IAEnBC,SAAS,EAAE,CAACX,KAAD,EAAQY,QAAR,EAAkBC,QAAlB,KAA+B;MACxCA,QAAQ,CAAC,IAAD,EAAOC,IAAI,CAACC,SAAL,CAAef,KAAf,CAAP,CAAR;IACD;EAJkB,CAAd,CAAP;AAMD,CAPD"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Quality values, or q-values and q-factors, are used to describe the order
|
|
3
|
+
* of priority of values in a comma-separated list.
|
|
4
|
+
* It is a special syntax allowed in some HTTP headers and in HTML.
|
|
5
|
+
* https://developer.mozilla.org/en-US/docs/Glossary/Quality_values
|
|
6
|
+
* @param headerValue
|
|
7
|
+
*/
|
|
8
|
+
export declare function getByQualityPriorityValue(headerValue: string | undefined | null): string;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getByQualityPriorityValue = getByQualityPriorityValue;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Quality values, or q-values and q-factors, are used to describe the order
|
|
10
|
+
* of priority of values in a comma-separated list.
|
|
11
|
+
* It is a special syntax allowed in some HTTP headers and in HTML.
|
|
12
|
+
* https://developer.mozilla.org/en-US/docs/Glossary/Quality_values
|
|
13
|
+
* @param headerValue
|
|
14
|
+
*/
|
|
15
|
+
function getByQualityPriorityValue(headerValue) {
|
|
16
|
+
if (typeof headerValue !== 'string') {
|
|
17
|
+
return '';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const split = headerValue.split(',');
|
|
21
|
+
|
|
22
|
+
if (split.length <= 1) {
|
|
23
|
+
const qList = split[0].split(';');
|
|
24
|
+
return qList[0];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let [header] = split.reduce((acc, item) => {
|
|
28
|
+
const qList = item.split(';');
|
|
29
|
+
|
|
30
|
+
if (qList.length > 1) {
|
|
31
|
+
const [accept, q] = qList;
|
|
32
|
+
const [, query] = q.split('=');
|
|
33
|
+
acc.push([accept.trim(), query ? query : 0]);
|
|
34
|
+
} else {
|
|
35
|
+
acc.push([qList[0], 0]);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return acc;
|
|
39
|
+
}, []).sort(function (a, b) {
|
|
40
|
+
return b[1] - a[1];
|
|
41
|
+
});
|
|
42
|
+
return header[0];
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=string-utils.js.map
|