@verdaccio/core 6.0.0-6-next.48 → 6.0.0-6-next.50

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 CHANGED
@@ -1,5 +1,9 @@
1
1
  # @verdaccio/core
2
2
 
3
+ ## 6.0.0-6-next.50
4
+
5
+ ## 6.0.0-6-next.49
6
+
3
7
  ## 6.0.0-6-next.48
4
8
 
5
9
  ### Minor Changes
@@ -1,21 +1,137 @@
1
- import { Config, IPackageStorage, Token, TokenFilter } from '@verdaccio/types';
2
- import { searchUtils } from '.';
3
- interface IPlugin {
4
- version?: string;
5
- close?(): void;
6
- }
7
- export interface IPluginStorage<T> extends IPlugin {
8
- config: T & Config;
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): IPackageStorage;
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
- export {};
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
+ }
@@ -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 { Config, IPackageStorage, Token, TokenFilter } from '@verdaccio/types';\n\nimport { searchUtils } from '.';\n\ninterface IPlugin {\n version?: string;\n // In case a plugin needs to be cleaned up/removed\n close?(): void;\n}\n\nexport interface IPluginStorage<T> extends IPlugin {\n config: T & Config;\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): IPackageStorage;\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"],"mappings":""}
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"}
@@ -1,45 +1,11 @@
1
1
  /// <reference types="node" />
2
- import { PassThrough, Transform, TransformOptions } from 'stream';
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: any) => Promise<string>;
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 { ReadTarball, UploadTarball, readableToString, transformObjectToString };
11
+ export { readableToString, transformObjectToString };
@@ -3,91 +3,13 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.transformObjectToString = exports.readableToString = exports.UploadTarball = exports.ReadTarball = void 0;
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":["ReadTarball","PassThrough","constructor","options","addAbstractMethods","abort","UploadTarball","done","self","name","_called_methods","__defineGetter__","__defineSetter__","fn","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 { PassThrough, Transform, TransformOptions } from 'stream';\n\nexport interface IReadTarball {\n abort?: () => void;\n}\n\nexport interface IUploadTarball {\n done?: () => void;\n abort?: () => void;\n}\n\n/**\n * This stream is used to read tarballs from repository.\n * @param {*} options\n * @return {Stream}\n */\nclass ReadTarball extends PassThrough implements IReadTarball {\n /**\n *\n * @param {Object} options\n */\n public constructor(options: TransformOptions) {\n super(options);\n // called when data is not needed anymore\n addAbstractMethods(this, 'abort');\n }\n\n public abort(): void {}\n}\n\n/**\n * This stream is used to upload tarballs to a repository.\n * @param {*} options\n * @return {Stream}\n */\nclass UploadTarball extends PassThrough implements IUploadTarball {\n /**\n *\n * @param {Object} options\n */\n public constructor(options: any) {\n super(options);\n // called when user closes connection before upload finishes\n addAbstractMethods(this, 'abort');\n\n // called when upload finishes successfully\n addAbstractMethods(this, 'done');\n }\n\n public abort(): void {}\n public done(): void {}\n}\n\n/**\n * This function intercepts abstract calls and replays them allowing.\n * us to attach those functions after we are ready to do so\n * @param {*} self\n * @param {*} name\n */\n// Perhaps someone knows a better way to write this\nfunction addAbstractMethods(self: any, name: any): void {\n self._called_methods = self._called_methods || {};\n\n self.__defineGetter__(name, function () {\n return function (): void {\n self._called_methods[name] = true;\n };\n });\n\n self.__defineSetter__(name, function (fn: any) {\n delete self[name];\n\n self[name] = fn;\n\n // eslint-disable-next-line @typescript-eslint/prefer-optional-chain\n if (self._called_methods && self._called_methods[name]) {\n delete self._called_methods[name];\n\n self[name]();\n }\n });\n}\n\n/**\n * Converts a buffer stream to a string.\n */\nconst readableToString = async (stream) => {\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 { ReadTarball, UploadTarball, readableToString, transformObjectToString };\n"],"mappings":";;;;;;;AAAA;;AAWA;AACA;AACA;AACA;AACA;AACA,MAAMA,WAAN,SAA0BC,mBAA1B,CAA8D;EAC5D;AACF;AACA;AACA;EACSC,WAAW,CAACC,OAAD,EAA4B;IAC5C,MAAMA,OAAN,EAD4C,CAE5C;;IACAC,kBAAkB,CAAC,IAAD,EAAO,OAAP,CAAlB;EACD;;EAEMC,KAAK,GAAS,CAAE;;AAXqC;AAc9D;AACA;AACA;AACA;AACA;;;;;AACA,MAAMC,aAAN,SAA4BL,mBAA5B,CAAkE;EAChE;AACF;AACA;AACA;EACSC,WAAW,CAACC,OAAD,EAAe;IAC/B,MAAMA,OAAN,EAD+B,CAE/B;;IACAC,kBAAkB,CAAC,IAAD,EAAO,OAAP,CAAlB,CAH+B,CAK/B;;IACAA,kBAAkB,CAAC,IAAD,EAAO,MAAP,CAAlB;EACD;;EAEMC,KAAK,GAAS,CAAE;;EAChBE,IAAI,GAAS,CAAE;;AAf0C;AAkBlE;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACA,SAASH,kBAAT,CAA4BI,IAA5B,EAAuCC,IAAvC,EAAwD;EACtDD,IAAI,CAACE,eAAL,GAAuBF,IAAI,CAACE,eAAL,IAAwB,EAA/C;;EAEAF,IAAI,CAACG,gBAAL,CAAsBF,IAAtB,EAA4B,YAAY;IACtC,OAAO,YAAkB;MACvBD,IAAI,CAACE,eAAL,CAAqBD,IAArB,IAA6B,IAA7B;IACD,CAFD;EAGD,CAJD;;EAMAD,IAAI,CAACI,gBAAL,CAAsBH,IAAtB,EAA4B,UAAUI,EAAV,EAAmB;IAC7C,OAAOL,IAAI,CAACC,IAAD,CAAX;IAEAD,IAAI,CAACC,IAAD,CAAJ,GAAaI,EAAb,CAH6C,CAK7C;;IACA,IAAIL,IAAI,CAACE,eAAL,IAAwBF,IAAI,CAACE,eAAL,CAAqBD,IAArB,CAA5B,EAAwD;MACtD,OAAOD,IAAI,CAACE,eAAL,CAAqBD,IAArB,CAAP;MAEAD,IAAI,CAACC,IAAD,CAAJ;IACD;EACF,CAXD;AAYD;AAED;AACA;AACA;;;AACA,MAAMK,gBAAgB,GAAG,MAAOC,MAAP,IAAkB;EACzC,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"}
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"}
@@ -1 +1 @@
1
- {"version":3,"file":"string-utils.js","names":["getByQualityPriorityValue","headerValue","split","length","qList","header","reduce","acc","item","accept","q","query","push","trim","sort","a","b"],"sources":["../src/string-utils.ts"],"sourcesContent":["/**\n * Quality values, or q-values and q-factors, are used to describe the order\n * of priority of values in a comma-separated list.\n * It is a special syntax allowed in some HTTP headers and in HTML.\n * https://developer.mozilla.org/en-US/docs/Glossary/Quality_values\n * @param headerValue\n */\nexport function getByQualityPriorityValue(headerValue: string | undefined | null): string {\n if (typeof headerValue !== 'string') {\n return '';\n }\n\n const split = headerValue.split(',');\n\n if (split.length <= 1) {\n const qList = split[0].split(';');\n return qList[0];\n }\n\n let [header] = split\n .reduce((acc, item: string) => {\n const qList = item.split(';');\n if (qList.length > 1) {\n const [accept, q] = qList;\n const [, query] = q.split('=');\n acc.push([accept.trim(), query ? query : 0]);\n } else {\n acc.push([qList[0], 0]);\n }\n return acc;\n }, [] as any)\n .sort(function (a, b) {\n return b[1] - a[1];\n });\n return header[0];\n}\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,yBAAT,CAAmCC,WAAnC,EAAmF;EACxF,IAAI,OAAOA,WAAP,KAAuB,QAA3B,EAAqC;IACnC,OAAO,EAAP;EACD;;EAED,MAAMC,KAAK,GAAGD,WAAW,CAACC,KAAZ,CAAkB,GAAlB,CAAd;;EAEA,IAAIA,KAAK,CAACC,MAAN,IAAgB,CAApB,EAAuB;IACrB,MAAMC,KAAK,GAAGF,KAAK,CAAC,CAAD,CAAL,CAASA,KAAT,CAAe,GAAf,CAAd;IACA,OAAOE,KAAK,CAAC,CAAD,CAAZ;EACD;;EAED,IAAI,CAACC,MAAD,IAAWH,KAAK,CACjBI,MADY,CACL,CAACC,GAAD,EAAMC,IAAN,KAAuB;IAC7B,MAAMJ,KAAK,GAAGI,IAAI,CAACN,KAAL,CAAW,GAAX,CAAd;;IACA,IAAIE,KAAK,CAACD,MAAN,GAAe,CAAnB,EAAsB;MACpB,MAAM,CAACM,MAAD,EAASC,CAAT,IAAcN,KAApB;MACA,MAAM,GAAGO,KAAH,IAAYD,CAAC,CAACR,KAAF,CAAQ,GAAR,CAAlB;MACAK,GAAG,CAACK,IAAJ,CAAS,CAACH,MAAM,CAACI,IAAP,EAAD,EAAgBF,KAAK,GAAGA,KAAH,GAAW,CAAhC,CAAT;IACD,CAJD,MAIO;MACLJ,GAAG,CAACK,IAAJ,CAAS,CAACR,KAAK,CAAC,CAAD,CAAN,EAAW,CAAX,CAAT;IACD;;IACD,OAAOG,GAAP;EACD,CAXY,EAWV,EAXU,EAYZO,IAZY,CAYP,UAAUC,CAAV,EAAaC,CAAb,EAAgB;IACpB,OAAOA,CAAC,CAAC,CAAD,CAAD,GAAOD,CAAC,CAAC,CAAD,CAAf;EACD,CAdY,CAAf;EAeA,OAAOV,MAAM,CAAC,CAAD,CAAb;AACD"}
1
+ {"version":3,"file":"string-utils.js","names":["getByQualityPriorityValue","headerValue","split","length","qList","header","reduce","acc","item","accept","q","query","push","trim","sort","a","b"],"sources":["../src/string-utils.ts"],"sourcesContent":["/**\n * Quality values, or q-values and q-factors, are used to describe the order\n * of priority of values in a comma-separated list.\n * It is a special syntax allowed in some HTTP headers and in HTML.\n * https://developer.mozilla.org/en-US/docs/Glossary/Quality_values\n * @param headerValue\n */\nexport function getByQualityPriorityValue(headerValue: string | undefined | null): string {\n if (typeof headerValue !== 'string') {\n return '';\n }\n\n const split = headerValue.split(',');\n\n if (split.length <= 1) {\n const qList = split[0].split(';');\n return qList[0];\n }\n\n let [header] = split\n .reduce((acc, item: string) => {\n const qList = item.split(';');\n if (qList.length > 1) {\n const [accept, q] = qList;\n const [, query] = q.split('=');\n acc.push([accept.trim(), query ? query : 0]);\n } else {\n acc.push([qList[0], 0]);\n }\n return acc;\n }, [] as any)\n .sort(function (a: number[], b: number[]) {\n return b[1] - a[1];\n });\n return header[0];\n}\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,yBAAT,CAAmCC,WAAnC,EAAmF;EACxF,IAAI,OAAOA,WAAP,KAAuB,QAA3B,EAAqC;IACnC,OAAO,EAAP;EACD;;EAED,MAAMC,KAAK,GAAGD,WAAW,CAACC,KAAZ,CAAkB,GAAlB,CAAd;;EAEA,IAAIA,KAAK,CAACC,MAAN,IAAgB,CAApB,EAAuB;IACrB,MAAMC,KAAK,GAAGF,KAAK,CAAC,CAAD,CAAL,CAASA,KAAT,CAAe,GAAf,CAAd;IACA,OAAOE,KAAK,CAAC,CAAD,CAAZ;EACD;;EAED,IAAI,CAACC,MAAD,IAAWH,KAAK,CACjBI,MADY,CACL,CAACC,GAAD,EAAMC,IAAN,KAAuB;IAC7B,MAAMJ,KAAK,GAAGI,IAAI,CAACN,KAAL,CAAW,GAAX,CAAd;;IACA,IAAIE,KAAK,CAACD,MAAN,GAAe,CAAnB,EAAsB;MACpB,MAAM,CAACM,MAAD,EAASC,CAAT,IAAcN,KAApB;MACA,MAAM,GAAGO,KAAH,IAAYD,CAAC,CAACR,KAAF,CAAQ,GAAR,CAAlB;MACAK,GAAG,CAACK,IAAJ,CAAS,CAACH,MAAM,CAACI,IAAP,EAAD,EAAgBF,KAAK,GAAGA,KAAH,GAAW,CAAhC,CAAT;IACD,CAJD,MAIO;MACLJ,GAAG,CAACK,IAAJ,CAAS,CAACR,KAAK,CAAC,CAAD,CAAN,EAAW,CAAX,CAAT;IACD;;IACD,OAAOG,GAAP;EACD,CAXY,EAWV,EAXU,EAYZO,IAZY,CAYP,UAAUC,CAAV,EAAuBC,CAAvB,EAAoC;IACxC,OAAOA,CAAC,CAAC,CAAD,CAAD,GAAOD,CAAC,CAAC,CAAD,CAAf;EACD,CAdY,CAAf;EAeA,OAAOV,MAAM,CAAC,CAAD,CAAb;AACD"}
@@ -5,4 +5,4 @@ export declare enum Codes {
5
5
  VERWAR004 = "VERWAR004",
6
6
  VERDEP003 = "VERDEP003"
7
7
  }
8
- export declare function emit(code: any, a?: string, b?: string, c?: string): void;
8
+ export declare function emit(code: string, a?: string, b?: string, c?: string): void;
@@ -1 +1 @@
1
- {"version":3,"file":"warning-utils.js","names":["warningInstance","warning","verdaccioWarning","verdaccioDeprecation","Codes","create","VERWAR002","VERWAR001","VERWAR003","VERWAR004","VERDEP003","emit","code","a","b","c"],"sources":["../src/warning-utils.ts"],"sourcesContent":["import warning from 'process-warning';\n\nconst warningInstance = warning();\nconst verdaccioWarning = 'VerdaccioWarning';\nconst verdaccioDeprecation = 'VerdaccioDeprecation';\n\nexport enum Codes {\n VERWAR001 = 'VERWAR001',\n VERWAR002 = 'VERWAR002',\n VERWAR003 = 'VERWAR003',\n VERWAR004 = 'VERWAR004',\n // deprecation warnings\n VERDEP003 = 'VERDEP003',\n}\n\nwarningInstance.create(\n verdaccioWarning,\n Codes.VERWAR002,\n `The property config \"logs\" property is longer supported, rename to \"log\" and use object instead`\n);\n\nwarningInstance.create(\n verdaccioWarning,\n Codes.VERWAR001,\n `Verdaccio doesn't need superuser privileges. don't run it under root`\n);\n\nwarningInstance.create(\n verdaccioWarning,\n Codes.VERWAR003,\n 'rotating-file type is not longer supported, consider use [logrotate] instead'\n);\n\nwarningInstance.create(\n verdaccioWarning,\n Codes.VERWAR004,\n `invalid address - %s, we expect a port (e.g. \"4873\"), \nhost:port (e.g. \"localhost:4873\") or full url '(e.g. \"http://localhost:4873/\")\nhttps://verdaccio.org/docs/en/configuration#listen-port`\n);\n\nwarningInstance.create(\n verdaccioDeprecation,\n Codes.VERDEP003,\n 'multiple addresses will be deprecated in the next major, only use one'\n);\n\nexport function emit(code, a?: string, b?: string, c?: string) {\n warningInstance.emit(code, a, b, c);\n}\n"],"mappings":";;;;;;;;AAAA;;;;AAEA,MAAMA,eAAe,GAAG,IAAAC,uBAAA,GAAxB;AACA,MAAMC,gBAAgB,GAAG,kBAAzB;AACA,MAAMC,oBAAoB,GAAG,sBAA7B;IAEYC,K;;;WAAAA,K;EAAAA,K;EAAAA,K;EAAAA,K;EAAAA,K;EAAAA,K;GAAAA,K,qBAAAA,K;;AASZJ,eAAe,CAACK,MAAhB,CACEH,gBADF,EAEEE,KAAK,CAACE,SAFR,EAGG,iGAHH;AAMAN,eAAe,CAACK,MAAhB,CACEH,gBADF,EAEEE,KAAK,CAACG,SAFR,EAGG,sEAHH;AAMAP,eAAe,CAACK,MAAhB,CACEH,gBADF,EAEEE,KAAK,CAACI,SAFR,EAGE,8EAHF;AAMAR,eAAe,CAACK,MAAhB,CACEH,gBADF,EAEEE,KAAK,CAACK,SAFR,EAGG;AACH;AACA,wDALA;AAQAT,eAAe,CAACK,MAAhB,CACEF,oBADF,EAEEC,KAAK,CAACM,SAFR,EAGE,uEAHF;;AAMO,SAASC,IAAT,CAAcC,IAAd,EAAoBC,CAApB,EAAgCC,CAAhC,EAA4CC,CAA5C,EAAwD;EAC7Df,eAAe,CAACW,IAAhB,CAAqBC,IAArB,EAA2BC,CAA3B,EAA8BC,CAA9B,EAAiCC,CAAjC;AACD"}
1
+ {"version":3,"file":"warning-utils.js","names":["warningInstance","warning","verdaccioWarning","verdaccioDeprecation","Codes","create","VERWAR002","VERWAR001","VERWAR003","VERWAR004","VERDEP003","emit","code","a","b","c"],"sources":["../src/warning-utils.ts"],"sourcesContent":["import warning from 'process-warning';\n\nconst warningInstance = warning();\nconst verdaccioWarning = 'VerdaccioWarning';\nconst verdaccioDeprecation = 'VerdaccioDeprecation';\n\nexport enum Codes {\n VERWAR001 = 'VERWAR001',\n VERWAR002 = 'VERWAR002',\n VERWAR003 = 'VERWAR003',\n VERWAR004 = 'VERWAR004',\n // deprecation warnings\n VERDEP003 = 'VERDEP003',\n}\n\nwarningInstance.create(\n verdaccioWarning,\n Codes.VERWAR002,\n `The property config \"logs\" property is longer supported, rename to \"log\" and use object instead`\n);\n\nwarningInstance.create(\n verdaccioWarning,\n Codes.VERWAR001,\n `Verdaccio doesn't need superuser privileges. don't run it under root`\n);\n\nwarningInstance.create(\n verdaccioWarning,\n Codes.VERWAR003,\n 'rotating-file type is not longer supported, consider use [logrotate] instead'\n);\n\nwarningInstance.create(\n verdaccioWarning,\n Codes.VERWAR004,\n `invalid address - %s, we expect a port (e.g. \"4873\"), \nhost:port (e.g. \"localhost:4873\") or full url '(e.g. \"http://localhost:4873/\")\nhttps://verdaccio.org/docs/en/configuration#listen-port`\n);\n\nwarningInstance.create(\n verdaccioDeprecation,\n Codes.VERDEP003,\n 'multiple addresses will be deprecated in the next major, only use one'\n);\n\nexport function emit(code: string, a?: string, b?: string, c?: string) {\n warningInstance.emit(code, a, b, c);\n}\n"],"mappings":";;;;;;;;AAAA;;;;AAEA,MAAMA,eAAe,GAAG,IAAAC,uBAAA,GAAxB;AACA,MAAMC,gBAAgB,GAAG,kBAAzB;AACA,MAAMC,oBAAoB,GAAG,sBAA7B;IAEYC,K;;;WAAAA,K;EAAAA,K;EAAAA,K;EAAAA,K;EAAAA,K;EAAAA,K;GAAAA,K,qBAAAA,K;;AASZJ,eAAe,CAACK,MAAhB,CACEH,gBADF,EAEEE,KAAK,CAACE,SAFR,EAGG,iGAHH;AAMAN,eAAe,CAACK,MAAhB,CACEH,gBADF,EAEEE,KAAK,CAACG,SAFR,EAGG,sEAHH;AAMAP,eAAe,CAACK,MAAhB,CACEH,gBADF,EAEEE,KAAK,CAACI,SAFR,EAGE,8EAHF;AAMAR,eAAe,CAACK,MAAhB,CACEH,gBADF,EAEEE,KAAK,CAACK,SAFR,EAGG;AACH;AACA,wDALA;AAQAT,eAAe,CAACK,MAAhB,CACEF,oBADF,EAEEC,KAAK,CAACM,SAFR,EAGE,uEAHF;;AAMO,SAASC,IAAT,CAAcC,IAAd,EAA4BC,CAA5B,EAAwCC,CAAxC,EAAoDC,CAApD,EAAgE;EACrEf,eAAe,CAACW,IAAhB,CAAqBC,IAArB,EAA2BC,CAA3B,EAA8BC,CAA9B,EAAiCC,CAAjC;AACD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verdaccio/core",
3
- "version": "6.0.0-6-next.48",
3
+ "version": "6.0.0-6-next.50",
4
4
  "description": "core utilities",
5
5
  "keywords": [
6
6
  "private",
@@ -36,13 +36,15 @@
36
36
  "dependencies": {
37
37
  "http-errors": "1.8.1",
38
38
  "http-status-codes": "2.2.0",
39
- "semver": "7.3.7",
39
+ "semver": "7.3.8",
40
40
  "ajv": "8.11.0",
41
41
  "process-warning": "1.0.0",
42
- "core-js": "3.25.2"
42
+ "core-js": "3.25.5"
43
43
  },
44
44
  "devDependencies": {
45
45
  "lodash": "4.17.21",
46
+ "typedoc": "0.23.16",
47
+ "typedoc-plugin-missing-exports": "latest",
46
48
  "@verdaccio/types": "11.0.0-6-next.17"
47
49
  },
48
50
  "funding": {
@@ -53,6 +55,7 @@
53
55
  "clean": "rimraf ./build",
54
56
  "test": "jest",
55
57
  "type-check": "tsc --noEmit -p tsconfig.build.json",
58
+ "build:docs": "typedoc --options ./typedoc.json --tsconfig tsconfig.build.json",
56
59
  "build:types": "tsc --emitDeclarationOnly -p tsconfig.build.json",
57
60
  "build:js": "babel src/ --out-dir build/ --copy-files --extensions \".ts,.tsx\" --source-maps",
58
61
  "watch": "pnpm build:js -- --watch",
@@ -1,24 +1,174 @@
1
- import { Config, IPackageStorage, Token, TokenFilter } from '@verdaccio/types';
1
+ import { Express, RequestHandler } from 'express';
2
+ import { Readable, Writable } from 'stream';
2
3
 
3
- import { searchUtils } from '.';
4
+ import {
5
+ AllowAccess,
6
+ Callback,
7
+ Config,
8
+ Logger,
9
+ Manifest,
10
+ PackageAccess,
11
+ RemoteUser,
12
+ Token,
13
+ TokenFilter,
14
+ } from '@verdaccio/types';
4
15
 
5
- interface IPlugin {
6
- version?: string;
7
- // In case a plugin needs to be cleaned up/removed
8
- close?(): void;
16
+ import { VerdaccioError, searchUtils } from '.';
17
+
18
+ export interface AuthPluginPackage {
19
+ packageName: string;
20
+ packageVersion?: string;
21
+ tag?: string;
22
+ }
23
+ export interface PluginOptions {
24
+ config: Config;
25
+ logger: Logger;
26
+ }
27
+
28
+ /**
29
+ * The base plugin class, set of utilities for developing
30
+ * plugins.
31
+ * @alpha
32
+ * */
33
+ export class Plugin<PluginConfig> {
34
+ static version = 1;
35
+ public readonly version: number;
36
+ public readonly config: PluginConfig | unknown;
37
+ public readonly options: PluginOptions;
38
+ public constructor(config: PluginConfig, options: PluginOptions) {
39
+ this.version = Plugin.version;
40
+ this.config = config;
41
+ this.options = options;
42
+ }
43
+
44
+ public getVersion() {
45
+ return this.version;
46
+ }
47
+ }
48
+ export interface StorageHandler {
49
+ logger: Logger;
50
+ deletePackage(fileName: string): Promise<void>;
51
+ removePackage(): Promise<void>;
52
+ // next packages migration (this list is meant to replace the callback parent functions)
53
+ updatePackage(
54
+ packageName: string,
55
+ handleUpdate: (manifest: Manifest) => Promise<Manifest>
56
+ ): Promise<Manifest>;
57
+ readPackage(name: string): Promise<Manifest>;
58
+ savePackage(pkgName: string, value: Manifest): Promise<void>;
59
+ readTarball(pkgName: string, { signal }: { signal: AbortSignal }): Promise<Readable>;
60
+ createPackage(name: string, manifest: Manifest): Promise<void>;
61
+ writeTarball(tarballName: string, { signal }: { signal: AbortSignal }): Promise<Writable>;
62
+ // verify if tarball exist in the storage
63
+ hasTarball(fileName: string): Promise<boolean>;
64
+ // verify if package exist in the storage
65
+ hasPackage(): Promise<boolean>;
9
66
  }
10
67
 
11
- export interface IPluginStorage<T> extends IPlugin {
12
- config: T & Config;
68
+ export interface Storage<PluginConfig> extends Plugin<PluginConfig> {
13
69
  add(name: string): Promise<void>;
14
70
  remove(name: string): Promise<void>;
15
71
  get(): Promise<any>;
16
72
  init(): Promise<void>;
17
73
  getSecret(): Promise<string>;
18
74
  setSecret(secret: string): Promise<any>;
19
- getPackageStorage(packageInfo: string): IPackageStorage;
75
+ getPackageStorage(packageInfo: string): StorageHandler;
20
76
  search(query: searchUtils.SearchQuery): Promise<searchUtils.SearchItem[]>;
21
77
  saveToken(token: Token): Promise<any>;
22
78
  deleteToken(user: string, tokenKey: string): Promise<any>;
23
79
  readTokens(filter: TokenFilter): Promise<Token[]>;
24
80
  }
81
+
82
+ /**
83
+ * This function allow add additional middleware to the application.
84
+ *
85
+ * ```ts
86
+ * import express, { Request, Response } from 'express';
87
+ *
88
+ * class Middleware extends Plugin {
89
+ * // instances of auth and storage are injected
90
+ * register_middlewares(app, auth, storage) {
91
+ * const router = express.Router();
92
+ * router.post('/my-endpoint', (req: Request, res: Response): void => {
93
+ res.status(200).end();
94
+ });
95
+ * }
96
+ * }
97
+ *
98
+ *
99
+ * const [plugin] = await asyncLoadPlugin(...);
100
+ * plugin.register_middlewares(app, auth, storage);
101
+ * ```
102
+ */
103
+ export interface ExpressMiddleware<PluginConfig, Storage, Auth> extends Plugin<PluginConfig> {
104
+ register_middlewares(app: Express, auth: Auth, storage: Storage): void;
105
+ }
106
+
107
+ /**
108
+ * dasdsa
109
+ */
110
+ export type AuthCallback = (error: VerdaccioError | null, groups?: string[] | false) => void;
111
+
112
+ export type AuthAccessCallback = (error: VerdaccioError | null, access?: boolean) => void;
113
+ export type AuthUserCallback = (error: VerdaccioError | null, access?: boolean | string) => void;
114
+ export type AuthChangePasswordCallback = (error: VerdaccioError | null, access?: boolean) => void;
115
+ export type AccessCallback = (error: VerdaccioError | null, ok?: boolean) => void;
116
+ export interface Auth<T> extends Plugin<T> {
117
+ /**
118
+ * Handles the authenticated method.
119
+ * ```ts
120
+ * class Auth {
121
+ public authenticate(user: string, password: string, done: AuthCallback): void {
122
+ if (!password) {
123
+ return done(errorUtils.getUnauthorized(API_ERROR.BAD_USERNAME_PASSWORD));
124
+ }
125
+ // always return an array of users
126
+ return done(null, [user]);
127
+ * }
128
+ * ```
129
+ */
130
+ authenticate(user: string, password: string, cb: AuthCallback): void;
131
+ /**
132
+ * Handles the authenticated method.
133
+ * ```ts
134
+ * class Auth {
135
+ public adduser(user: string, password: string, done: AuthCallback): void {
136
+ if (!password) {
137
+ return done(errorUtils.getUnauthorized(API_ERROR.BAD_USERNAME_PASSWORD));
138
+ }
139
+ // return boolean
140
+ return done(null, true);
141
+ * }
142
+ * ```
143
+ */
144
+ adduser?(user: string, password: string, cb: AuthUserCallback): void;
145
+ changePassword?(
146
+ user: string,
147
+ password: string,
148
+ newPassword: string,
149
+ cb: AuthChangePasswordCallback
150
+ ): void;
151
+ allow_publish?(user: RemoteUser, pkg: T & PackageAccess, cb: AuthAccessCallback): void;
152
+ allow_publish?(user: RemoteUser, pkg: AllowAccess & PackageAccess, cb: AuthAccessCallback): void;
153
+ allow_access?(user: RemoteUser, pkg: T & PackageAccess, cb: AccessCallback): void;
154
+ allow_access?(user: RemoteUser, pkg: AllowAccess & PackageAccess, cb: AccessCallback): void;
155
+ allow_unpublish?(user: RemoteUser, pkg: T & PackageAccess, cb: AuthAccessCallback): void;
156
+ allow_unpublish?(
157
+ user: RemoteUser,
158
+ pkg: AllowAccess & PackageAccess,
159
+ cb: AuthAccessCallback
160
+ ): void;
161
+ apiJWTmiddleware?(helpers: any): RequestHandler;
162
+ }
163
+
164
+ export interface IBasicAuth {
165
+ authenticate(user: string, password: string, cb: Callback): void;
166
+ invalidateToken?(token: string): Promise<void>;
167
+ changePassword(user: string, password: string, newPassword: string, cb: Callback): void;
168
+ allow_access(pkg: AuthPluginPackage, user: RemoteUser, callback: Callback): void;
169
+ add_user(user: string, password: string, cb: Callback): any;
170
+ }
171
+
172
+ export interface ManifestFilter<T> extends Plugin<T> {
173
+ filterMetadata(packageInfo: Manifest): Promise<Manifest>;
174
+ }
@@ -1,90 +1,9 @@
1
- import { PassThrough, Transform, TransformOptions } from 'stream';
2
-
3
- export interface IReadTarball {
4
- abort?: () => void;
5
- }
6
-
7
- export interface IUploadTarball {
8
- done?: () => void;
9
- abort?: () => void;
10
- }
11
-
12
- /**
13
- * This stream is used to read tarballs from repository.
14
- * @param {*} options
15
- * @return {Stream}
16
- */
17
- class ReadTarball extends PassThrough implements IReadTarball {
18
- /**
19
- *
20
- * @param {Object} options
21
- */
22
- public constructor(options: TransformOptions) {
23
- super(options);
24
- // called when data is not needed anymore
25
- addAbstractMethods(this, 'abort');
26
- }
27
-
28
- public abort(): void {}
29
- }
30
-
31
- /**
32
- * This stream is used to upload tarballs to a repository.
33
- * @param {*} options
34
- * @return {Stream}
35
- */
36
- class UploadTarball extends PassThrough implements IUploadTarball {
37
- /**
38
- *
39
- * @param {Object} options
40
- */
41
- public constructor(options: any) {
42
- super(options);
43
- // called when user closes connection before upload finishes
44
- addAbstractMethods(this, 'abort');
45
-
46
- // called when upload finishes successfully
47
- addAbstractMethods(this, 'done');
48
- }
49
-
50
- public abort(): void {}
51
- public done(): void {}
52
- }
53
-
54
- /**
55
- * This function intercepts abstract calls and replays them allowing.
56
- * us to attach those functions after we are ready to do so
57
- * @param {*} self
58
- * @param {*} name
59
- */
60
- // Perhaps someone knows a better way to write this
61
- function addAbstractMethods(self: any, name: any): void {
62
- self._called_methods = self._called_methods || {};
63
-
64
- self.__defineGetter__(name, function () {
65
- return function (): void {
66
- self._called_methods[name] = true;
67
- };
68
- });
69
-
70
- self.__defineSetter__(name, function (fn: any) {
71
- delete self[name];
72
-
73
- self[name] = fn;
74
-
75
- // eslint-disable-next-line @typescript-eslint/prefer-optional-chain
76
- if (self._called_methods && self._called_methods[name]) {
77
- delete self._called_methods[name];
78
-
79
- self[name]();
80
- }
81
- });
82
- }
1
+ import { Readable, Transform } from 'stream';
83
2
 
84
3
  /**
85
4
  * Converts a buffer stream to a string.
86
5
  */
87
- const readableToString = async (stream) => {
6
+ const readableToString = async (stream: Readable) => {
88
7
  const chunks: Buffer[] = [];
89
8
  for await (let chunk of stream) {
90
9
  chunks.push(Buffer.from(chunk));
@@ -106,4 +25,4 @@ const transformObjectToString = () => {
106
25
  });
107
26
  };
108
27
 
109
- export { ReadTarball, UploadTarball, readableToString, transformObjectToString };
28
+ export { readableToString, transformObjectToString };
@@ -29,7 +29,7 @@ export function getByQualityPriorityValue(headerValue: string | undefined | null
29
29
  }
30
30
  return acc;
31
31
  }, [] as any)
32
- .sort(function (a, b) {
32
+ .sort(function (a: number[], b: number[]) {
33
33
  return b[1] - a[1];
34
34
  });
35
35
  return header[0];
@@ -45,6 +45,6 @@ warningInstance.create(
45
45
  'multiple addresses will be deprecated in the next major, only use one'
46
46
  );
47
47
 
48
- export function emit(code, a?: string, b?: string, c?: string) {
48
+ export function emit(code: string, a?: string, b?: string, c?: string) {
49
49
  warningInstance.emit(code, a, b, c);
50
50
  }
@@ -1,34 +1,8 @@
1
1
  import { Stream } from 'stream';
2
2
 
3
- import { ReadTarball, UploadTarball, readableToString } from '../src/stream-utils';
3
+ import { readableToString } from '../src/stream-utils';
4
4
 
5
5
  describe('mystreams', () => {
6
- test('should delay events on ReadTarball abort', (cb) => {
7
- const readTballStream = new ReadTarball({});
8
- readTballStream.abort();
9
- setTimeout(function () {
10
- readTballStream.abort = function (): void {
11
- cb();
12
- };
13
- readTballStream.abort = function (): never {
14
- throw Error('fail');
15
- };
16
- }, 10);
17
- });
18
-
19
- test('should delay events on UploadTarball abort', (cb) => {
20
- const uploadTballStream = new UploadTarball({});
21
- uploadTballStream.abort();
22
- setTimeout(function () {
23
- uploadTballStream.abort = function (): void {
24
- cb();
25
- };
26
- uploadTballStream.abort = function (): never {
27
- throw Error('fail');
28
- };
29
- }, 10);
30
- });
31
-
32
6
  test('readableToString single string', async () => {
33
7
  expect(await readableToString(Stream.Readable.from('foo'))).toEqual('foo');
34
8
  });
@@ -2,7 +2,8 @@
2
2
  "extends": "../../../tsconfig.base.json",
3
3
  "compilerOptions": {
4
4
  "rootDir": "./src",
5
- "outDir": "./build"
5
+ "outDir": "./build",
6
+ "noImplicitAny": true
6
7
  },
7
8
  "include": ["src/**/*"],
8
9
  "exclude": ["src/**/*.test.ts"]
package/tsconfig.json CHANGED
@@ -4,7 +4,8 @@
4
4
  "rootDir": "./src",
5
5
  "outDir": "./build",
6
6
  "composite": true,
7
- "declaration": true
7
+ "declaration": true,
8
+ "noImplicitAny": true
8
9
  },
9
10
  "include": ["src/**/*.ts"],
10
11
  "exclude": ["src/**/*.test.ts"]
package/typedoc.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "$schema": "https://typedoc.org/schema.json",
3
+ "entryPoints": ["src/index.ts"],
4
+ "sort": ["source-order"]
5
+ }