@verdaccio/api 9.0.0-next-9.18 → 9.0.0-next-9.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.js +1 -3
- package/build/index.js.map +1 -1
- package/build/index.mjs +1 -3
- package/build/index.mjs.map +1 -1
- package/build/publish.d.ts +6 -24
- package/build/publish.js +28 -25
- package/build/publish.js.map +1 -1
- package/build/publish.mjs +29 -26
- package/build/publish.mjs.map +1 -1
- package/build/v1/token.js +1 -1
- package/build/v1/token.mjs +1 -1
- package/package.json +12 -9
- package/build/stars.d.ts +0 -3
- package/build/stars.js +0 -21
- package/build/stars.js.map +0 -1
- package/build/stars.mjs +0 -21
- package/build/stars.mjs.map +0 -1
package/build/index.js
CHANGED
|
@@ -8,7 +8,6 @@ const require_package = require("./package.js");
|
|
|
8
8
|
const require_ping = require("./ping.js");
|
|
9
9
|
const require_publish = require("./publish.js");
|
|
10
10
|
const require_search = require("./search.js");
|
|
11
|
-
const require_stars = require("./stars.js");
|
|
12
11
|
const require_user = require("./user.js");
|
|
13
12
|
const require_login = require("./v1/login.js");
|
|
14
13
|
const require_profile = require("./v1/profile.js");
|
|
@@ -44,9 +43,8 @@ function src_default(config, auth, storage, logger) {
|
|
|
44
43
|
require_search.default(app, logger);
|
|
45
44
|
require_user.default(app, auth, config, logger);
|
|
46
45
|
require_dist_tags.default(app, auth, storage, logger);
|
|
47
|
-
require_publish.default(app, auth, storage, logger);
|
|
46
|
+
require_publish.default(app, auth, storage, config, logger);
|
|
48
47
|
require_ping.default(app);
|
|
49
|
-
require_stars.default(app, storage);
|
|
50
48
|
require_search$1.default(app, auth, storage, logger);
|
|
51
49
|
require_token.default(app, auth, storage, config, logger);
|
|
52
50
|
require_package.default(app, auth, storage, logger);
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { Router } from 'express';\nimport express from 'express';\n\nimport type { Auth } from '@verdaccio/auth';\nimport {\n antiLoop,\n encodeScopePackage,\n enforceGeneratedTokenMetadata,\n makeURLrelative,\n match,\n registerBodyParser,\n validateName,\n validatePackage,\n} from '@verdaccio/middleware';\nimport type { Storage } from '@verdaccio/store';\nimport type { Config, Logger } from '@verdaccio/types';\n\nimport distTags from './dist-tags';\nimport pkg from './package';\nimport ping from './ping';\nimport publish from './publish';\nimport search from './search';\nimport
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { Router } from 'express';\nimport express from 'express';\n\nimport type { Auth } from '@verdaccio/auth';\nimport {\n antiLoop,\n encodeScopePackage,\n enforceGeneratedTokenMetadata,\n makeURLrelative,\n match,\n registerBodyParser,\n validateName,\n validatePackage,\n} from '@verdaccio/middleware';\nimport type { Storage } from '@verdaccio/store';\nimport type { Config, Logger } from '@verdaccio/types';\n\nimport distTags from './dist-tags';\nimport pkg from './package';\nimport ping from './ping';\nimport publish from './publish';\nimport search from './search';\nimport user from './user';\nimport login from './v1/login';\nimport profile from './v1/profile';\nimport v1Search from './v1/search';\nimport token from './v1/token';\nimport whoami from './whoami';\n\nexport default function (config: Config, auth: Auth, storage: Storage, logger: Logger): Router {\n /* eslint new-cap:off */\n const app = express.Router();\n\n // validate all of these params as a package name\n // this might be too harsh, so ask if it causes trouble\n app.param('package', validatePackage);\n app.param('filename', validateName);\n app.param('tag', validateName);\n app.param('version', validateName);\n app.param('revision', validateName);\n app.param('token', validateName);\n\n // Express route parameter names must be valid JavaScript identifiers, which means\n // they cannot start with a hyphen (-) or contain special characters like dots (.)\n app.param('_rev', match(/^-rev$/));\n app.param('org_couchdb_user', match(/^org\\.couchdb\\.user:/));\n\n // Body parser must be registered before JWT middleware which pauses/resumes the stream\n registerBodyParser(app, config);\n\n // Avoid executing JWT twice when the parent app already registered the JWT middleware\n const apiJwtMiddleware = auth.apiJWTmiddleware();\n app.use((req, res, next) => {\n const remoteUser = (req as any).remote_user ?? (res.locals as any).remote_user;\n if (remoteUser) {\n return next();\n }\n return apiJwtMiddleware(req, res, next);\n });\n\n app.use(enforceGeneratedTokenMetadata(storage, logger));\n app.use(antiLoop(config));\n app.use(makeURLrelative);\n // encode / in a scoped package name to be matched as a single parameter in routes\n app.use(encodeScopePackage);\n // for \"npm whoami\"\n whoami(app);\n profile(app, auth, config);\n search(app, logger);\n user(app, auth, config, logger);\n distTags(app, auth, storage, logger);\n publish(app, auth, storage, config, logger);\n ping(app);\n v1Search(app, auth, storage, logger);\n token(app, auth, storage, config, logger);\n pkg(app, auth, storage, logger);\n if (config.flags?.webLogin) {\n login(app, auth, storage, config, logger);\n }\n return app;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA6BA,SAAA,YAAyB,QAAgB,MAAY,SAAkB,QAAwB;CAE7F,MAAM,MAAM,QAAA,QAAQ,OAAO;CAI3B,IAAI,MAAM,WAAW,sBAAA,eAAe;CACpC,IAAI,MAAM,YAAY,sBAAA,YAAY;CAClC,IAAI,MAAM,OAAO,sBAAA,YAAY;CAC7B,IAAI,MAAM,WAAW,sBAAA,YAAY;CACjC,IAAI,MAAM,YAAY,sBAAA,YAAY;CAClC,IAAI,MAAM,SAAS,sBAAA,YAAY;CAI/B,IAAI,MAAM,SAAA,GAAA,sBAAA,OAAc,QAAQ,CAAC;CACjC,IAAI,MAAM,qBAAA,GAAA,sBAAA,OAA0B,sBAAsB,CAAC;CAG3D,CAAA,GAAA,sBAAA,oBAAmB,KAAK,MAAM;CAG9B,MAAM,mBAAmB,KAAK,iBAAiB;CAC/C,IAAI,KAAK,KAAK,KAAK,SAAS;EAE1B,IADoB,IAAY,eAAgB,IAAI,OAAe,aAEjE,OAAO,KAAK;EAEd,OAAO,iBAAiB,KAAK,KAAK,IAAI;CACxC,CAAC;CAED,IAAI,KAAA,GAAA,sBAAA,+BAAkC,SAAS,MAAM,CAAC;CACtD,IAAI,KAAA,GAAA,sBAAA,UAAa,MAAM,CAAC;CACxB,IAAI,IAAI,sBAAA,eAAe;CAEvB,IAAI,IAAI,sBAAA,kBAAkB;CAE1B,eAAA,QAAO,GAAG;CACV,gBAAA,QAAQ,KAAK,MAAM,MAAM;CACzB,eAAA,QAAO,KAAK,MAAM;CAClB,aAAA,QAAK,KAAK,MAAM,QAAQ,MAAM;CAC9B,kBAAA,QAAS,KAAK,MAAM,SAAS,MAAM;CACnC,gBAAA,QAAQ,KAAK,MAAM,SAAS,QAAQ,MAAM;CAC1C,aAAA,QAAK,GAAG;CACR,iBAAA,QAAS,KAAK,MAAM,SAAS,MAAM;CACnC,cAAA,QAAM,KAAK,MAAM,SAAS,QAAQ,MAAM;CACxC,gBAAA,QAAI,KAAK,MAAM,SAAS,MAAM;CAC9B,IAAI,OAAO,OAAO,UAChB,cAAA,QAAM,KAAK,MAAM,SAAS,QAAQ,MAAM;CAE1C,OAAO;AACT"}
|
package/build/index.mjs
CHANGED
|
@@ -3,7 +3,6 @@ import package_default from "./package.mjs";
|
|
|
3
3
|
import ping_default from "./ping.mjs";
|
|
4
4
|
import publish from "./publish.mjs";
|
|
5
5
|
import search_default from "./search.mjs";
|
|
6
|
-
import stars_default from "./stars.mjs";
|
|
7
6
|
import user_default from "./user.mjs";
|
|
8
7
|
import login_default from "./v1/login.mjs";
|
|
9
8
|
import profile_default from "./v1/profile.mjs";
|
|
@@ -38,9 +37,8 @@ function src_default(config, auth, storage, logger) {
|
|
|
38
37
|
search_default(app, logger);
|
|
39
38
|
user_default(app, auth, config, logger);
|
|
40
39
|
dist_tags_default(app, auth, storage, logger);
|
|
41
|
-
publish(app, auth, storage, logger);
|
|
40
|
+
publish(app, auth, storage, config, logger);
|
|
42
41
|
ping_default(app);
|
|
43
|
-
stars_default(app, storage);
|
|
44
42
|
search_default$1(app, auth, storage, logger);
|
|
45
43
|
token_default(app, auth, storage, config, logger);
|
|
46
44
|
package_default(app, auth, storage, logger);
|
package/build/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { Router } from 'express';\nimport express from 'express';\n\nimport type { Auth } from '@verdaccio/auth';\nimport {\n antiLoop,\n encodeScopePackage,\n enforceGeneratedTokenMetadata,\n makeURLrelative,\n match,\n registerBodyParser,\n validateName,\n validatePackage,\n} from '@verdaccio/middleware';\nimport type { Storage } from '@verdaccio/store';\nimport type { Config, Logger } from '@verdaccio/types';\n\nimport distTags from './dist-tags';\nimport pkg from './package';\nimport ping from './ping';\nimport publish from './publish';\nimport search from './search';\nimport
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { Router } from 'express';\nimport express from 'express';\n\nimport type { Auth } from '@verdaccio/auth';\nimport {\n antiLoop,\n encodeScopePackage,\n enforceGeneratedTokenMetadata,\n makeURLrelative,\n match,\n registerBodyParser,\n validateName,\n validatePackage,\n} from '@verdaccio/middleware';\nimport type { Storage } from '@verdaccio/store';\nimport type { Config, Logger } from '@verdaccio/types';\n\nimport distTags from './dist-tags';\nimport pkg from './package';\nimport ping from './ping';\nimport publish from './publish';\nimport search from './search';\nimport user from './user';\nimport login from './v1/login';\nimport profile from './v1/profile';\nimport v1Search from './v1/search';\nimport token from './v1/token';\nimport whoami from './whoami';\n\nexport default function (config: Config, auth: Auth, storage: Storage, logger: Logger): Router {\n /* eslint new-cap:off */\n const app = express.Router();\n\n // validate all of these params as a package name\n // this might be too harsh, so ask if it causes trouble\n app.param('package', validatePackage);\n app.param('filename', validateName);\n app.param('tag', validateName);\n app.param('version', validateName);\n app.param('revision', validateName);\n app.param('token', validateName);\n\n // Express route parameter names must be valid JavaScript identifiers, which means\n // they cannot start with a hyphen (-) or contain special characters like dots (.)\n app.param('_rev', match(/^-rev$/));\n app.param('org_couchdb_user', match(/^org\\.couchdb\\.user:/));\n\n // Body parser must be registered before JWT middleware which pauses/resumes the stream\n registerBodyParser(app, config);\n\n // Avoid executing JWT twice when the parent app already registered the JWT middleware\n const apiJwtMiddleware = auth.apiJWTmiddleware();\n app.use((req, res, next) => {\n const remoteUser = (req as any).remote_user ?? (res.locals as any).remote_user;\n if (remoteUser) {\n return next();\n }\n return apiJwtMiddleware(req, res, next);\n });\n\n app.use(enforceGeneratedTokenMetadata(storage, logger));\n app.use(antiLoop(config));\n app.use(makeURLrelative);\n // encode / in a scoped package name to be matched as a single parameter in routes\n app.use(encodeScopePackage);\n // for \"npm whoami\"\n whoami(app);\n profile(app, auth, config);\n search(app, logger);\n user(app, auth, config, logger);\n distTags(app, auth, storage, logger);\n publish(app, auth, storage, config, logger);\n ping(app);\n v1Search(app, auth, storage, logger);\n token(app, auth, storage, config, logger);\n pkg(app, auth, storage, logger);\n if (config.flags?.webLogin) {\n login(app, auth, storage, config, logger);\n }\n return app;\n}\n"],"mappings":";;;;;;;;;;;;;;AA6BA,SAAA,YAAyB,QAAgB,MAAY,SAAkB,QAAwB;CAE7F,MAAM,MAAM,QAAQ,OAAO;CAI3B,IAAI,MAAM,WAAW,eAAe;CACpC,IAAI,MAAM,YAAY,YAAY;CAClC,IAAI,MAAM,OAAO,YAAY;CAC7B,IAAI,MAAM,WAAW,YAAY;CACjC,IAAI,MAAM,YAAY,YAAY;CAClC,IAAI,MAAM,SAAS,YAAY;CAI/B,IAAI,MAAM,QAAQ,MAAM,QAAQ,CAAC;CACjC,IAAI,MAAM,oBAAoB,MAAM,sBAAsB,CAAC;CAG3D,mBAAmB,KAAK,MAAM;CAG9B,MAAM,mBAAmB,KAAK,iBAAiB;CAC/C,IAAI,KAAK,KAAK,KAAK,SAAS;EAE1B,IADoB,IAAY,eAAgB,IAAI,OAAe,aAEjE,OAAO,KAAK;EAEd,OAAO,iBAAiB,KAAK,KAAK,IAAI;CACxC,CAAC;CAED,IAAI,IAAI,8BAA8B,SAAS,MAAM,CAAC;CACtD,IAAI,IAAI,SAAS,MAAM,CAAC;CACxB,IAAI,IAAI,eAAe;CAEvB,IAAI,IAAI,kBAAkB;CAE1B,eAAO,GAAG;CACV,gBAAQ,KAAK,MAAM,MAAM;CACzB,eAAO,KAAK,MAAM;CAClB,aAAK,KAAK,MAAM,QAAQ,MAAM;CAC9B,kBAAS,KAAK,MAAM,SAAS,MAAM;CACnC,QAAQ,KAAK,MAAM,SAAS,QAAQ,MAAM;CAC1C,aAAK,GAAG;CACR,iBAAS,KAAK,MAAM,SAAS,MAAM;CACnC,cAAM,KAAK,MAAM,SAAS,QAAQ,MAAM;CACxC,gBAAI,KAAK,MAAM,SAAS,MAAM;CAC9B,IAAI,OAAO,OAAO,UAChB,cAAM,KAAK,MAAM,SAAS,QAAQ,MAAM;CAE1C,OAAO;AACT"}
|
package/build/publish.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
2
|
import { Auth } from '@verdaccio/auth';
|
|
3
3
|
import { Storage } from '@verdaccio/store';
|
|
4
|
-
import { Logger } from '@verdaccio/types';
|
|
4
|
+
import { Config, Logger } from '@verdaccio/types';
|
|
5
5
|
/**
|
|
6
|
-
* Publish a package / update package
|
|
6
|
+
* Publish a package / update package
|
|
7
7
|
*
|
|
8
8
|
* There are multiples scenarios here to be considered:
|
|
9
9
|
*
|
|
@@ -62,27 +62,9 @@ import { Logger } from '@verdaccio/types';
|
|
|
62
62
|
* Remove the tarball
|
|
63
63
|
* npm http fetch DELETE 201 http://localhost:4873/custom-name/-/test1-1.0.3.tgz/-rev/16-e11c8db282b2d992 19ms
|
|
64
64
|
*
|
|
65
|
-
* 3.
|
|
65
|
+
* 3. Change owners of a package
|
|
66
66
|
*
|
|
67
|
-
*
|
|
68
|
-
* specific flag for star or unstar.
|
|
69
|
-
* The URL for star is similar to the unpublish (change package format)
|
|
70
|
-
*
|
|
71
|
-
* npm has no endpoint for staring a package, rather mutate the metadata and acts as, the difference
|
|
72
|
-
* is the users property which is part of the payload and the body only includes
|
|
73
|
-
*
|
|
74
|
-
* {
|
|
75
|
-
"_id": pkgName,
|
|
76
|
-
"_rev": "3-b0cdaefc9bdb77c8",
|
|
77
|
-
"users": {
|
|
78
|
-
[username]: boolean value (true, false)
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
*
|
|
82
|
-
* 4. Change owners of a package
|
|
83
|
-
*
|
|
84
|
-
* Similar to staring a package, changing owners (maintainers) of a package uses the publish
|
|
85
|
-
* endpoint.
|
|
67
|
+
* Changing owners (maintainers) of a package uses the publish endpoint.
|
|
86
68
|
*
|
|
87
69
|
* The body includes a list of the new owners with the following format
|
|
88
70
|
*
|
|
@@ -97,5 +79,5 @@ import { Logger } from '@verdaccio/types';
|
|
|
97
79
|
}
|
|
98
80
|
*
|
|
99
81
|
*/
|
|
100
|
-
export default function publish(router: Router, auth: Auth, storage: Storage, logger: Logger): void;
|
|
101
|
-
export declare function publishPackage(storage: Storage, logger: Logger, origin: string): any;
|
|
82
|
+
export default function publish(router: Router, auth: Auth, storage: Storage, config: Config, logger: Logger): void;
|
|
83
|
+
export declare function publishPackage(storage: Storage, config: Config, logger: Logger, origin: string): any;
|
package/build/publish.js
CHANGED
|
@@ -3,10 +3,11 @@ let _verdaccio_middleware = require("@verdaccio/middleware");
|
|
|
3
3
|
let _verdaccio_core = require("@verdaccio/core");
|
|
4
4
|
let debug = require("debug");
|
|
5
5
|
debug = require_runtime.__toESM(debug);
|
|
6
|
+
let _verdaccio_hooks = require("@verdaccio/hooks");
|
|
6
7
|
//#region src/publish.ts
|
|
7
8
|
var debug$1 = (0, debug.default)("verdaccio:api:publish");
|
|
8
9
|
/**
|
|
9
|
-
* Publish a package / update package
|
|
10
|
+
* Publish a package / update package
|
|
10
11
|
*
|
|
11
12
|
* There are multiples scenarios here to be considered:
|
|
12
13
|
*
|
|
@@ -65,27 +66,9 @@ npm verb exit [ 0, true ]
|
|
|
65
66
|
* Remove the tarball
|
|
66
67
|
* npm http fetch DELETE 201 http://localhost:4873/custom-name/-/test1-1.0.3.tgz/-rev/16-e11c8db282b2d992 19ms
|
|
67
68
|
*
|
|
68
|
-
* 3.
|
|
69
|
+
* 3. Change owners of a package
|
|
69
70
|
*
|
|
70
|
-
*
|
|
71
|
-
* specific flag for star or unstar.
|
|
72
|
-
* The URL for star is similar to the unpublish (change package format)
|
|
73
|
-
*
|
|
74
|
-
* npm has no endpoint for staring a package, rather mutate the metadata and acts as, the difference
|
|
75
|
-
* is the users property which is part of the payload and the body only includes
|
|
76
|
-
*
|
|
77
|
-
* {
|
|
78
|
-
"_id": pkgName,
|
|
79
|
-
"_rev": "3-b0cdaefc9bdb77c8",
|
|
80
|
-
"users": {
|
|
81
|
-
[username]: boolean value (true, false)
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
*
|
|
85
|
-
* 4. Change owners of a package
|
|
86
|
-
*
|
|
87
|
-
* Similar to staring a package, changing owners (maintainers) of a package uses the publish
|
|
88
|
-
* endpoint.
|
|
71
|
+
* Changing owners (maintainers) of a package uses the publish endpoint.
|
|
89
72
|
*
|
|
90
73
|
* The body includes a list of the new owners with the following format
|
|
91
74
|
*
|
|
@@ -100,13 +83,13 @@ npm verb exit [ 0, true ]
|
|
|
100
83
|
}
|
|
101
84
|
*
|
|
102
85
|
*/
|
|
103
|
-
function publish(router, auth, storage, logger) {
|
|
86
|
+
function publish(router, auth, storage, config, logger) {
|
|
104
87
|
const can = (0, _verdaccio_middleware.allow)(auth, {
|
|
105
88
|
beforeAll: (a, b) => logger.trace(a, b),
|
|
106
89
|
afterAll: (a, b) => logger.trace(a, b)
|
|
107
90
|
});
|
|
108
|
-
router.put(_verdaccio_middleware.PUBLISH_API_ENDPOINTS.add_package, can("publish"), (0, _verdaccio_middleware.media)(_verdaccio_core.HEADERS.JSON), _verdaccio_middleware.expectJson, publishPackage(storage, logger, "publish one version"));
|
|
109
|
-
router.put(_verdaccio_middleware.PUBLISH_API_ENDPOINTS.publish_package, can("unpublish"), (0, _verdaccio_middleware.media)(_verdaccio_core.HEADERS.JSON), _verdaccio_middleware.expectJson, publishPackage(storage, logger, "publish with revision"));
|
|
91
|
+
router.put(_verdaccio_middleware.PUBLISH_API_ENDPOINTS.add_package, can("publish"), (0, _verdaccio_middleware.media)(_verdaccio_core.HEADERS.JSON), _verdaccio_middleware.expectJson, publishPackage(storage, config, logger, "publish one version"));
|
|
92
|
+
router.put(_verdaccio_middleware.PUBLISH_API_ENDPOINTS.publish_package, can("unpublish"), (0, _verdaccio_middleware.media)(_verdaccio_core.HEADERS.JSON), _verdaccio_middleware.expectJson, publishPackage(storage, config, logger, "publish with revision"));
|
|
110
93
|
/**
|
|
111
94
|
* Un-publishing an entire package.
|
|
112
95
|
*
|
|
@@ -133,6 +116,12 @@ function publish(router, auth, storage, logger) {
|
|
|
133
116
|
await storage.removePackage(packageName, rev, username);
|
|
134
117
|
debug$1("package %s unpublished", packageName);
|
|
135
118
|
res.status(_verdaccio_core.HTTP_STATUS.CREATED);
|
|
119
|
+
(0, _verdaccio_hooks.notify)({
|
|
120
|
+
name: packageName,
|
|
121
|
+
_rev: rev
|
|
122
|
+
}, config, req.remote_user, packageName, "unpublish").catch((error) => {
|
|
123
|
+
logger.error({ error: error?.message }, "notify batch service has failed: @{error}");
|
|
124
|
+
});
|
|
136
125
|
return next({ ok: _verdaccio_core.API_MESSAGE.PKG_REMOVED });
|
|
137
126
|
} catch (err) {
|
|
138
127
|
return next(err);
|
|
@@ -155,13 +144,23 @@ function publish(router, auth, storage, logger) {
|
|
|
155
144
|
filename,
|
|
156
145
|
revision
|
|
157
146
|
}, `success remove tarball for @{packageName}-@{tarballName}-@{revision}`);
|
|
147
|
+
const version = _verdaccio_core.tarballUtils.getVersionFromTarball(filename);
|
|
148
|
+
const metadata = {
|
|
149
|
+
name: packageName,
|
|
150
|
+
version,
|
|
151
|
+
_rev: revision
|
|
152
|
+
};
|
|
153
|
+
const publishedPackage = version ? `${packageName}@${version}` : packageName;
|
|
154
|
+
(0, _verdaccio_hooks.notify)(metadata, config, req.remote_user, publishedPackage, "unpublish").catch((error) => {
|
|
155
|
+
logger.error({ error: error?.message }, "notify batch service has failed: @{error}");
|
|
156
|
+
});
|
|
158
157
|
return next({ ok: _verdaccio_core.API_MESSAGE.TARBALL_REMOVED });
|
|
159
158
|
} catch (err) {
|
|
160
159
|
return next(err);
|
|
161
160
|
}
|
|
162
161
|
});
|
|
163
162
|
}
|
|
164
|
-
function publishPackage(storage, logger, origin) {
|
|
163
|
+
function publishPackage(storage, config, logger, origin) {
|
|
165
164
|
return async function(req, res, next) {
|
|
166
165
|
debug$1(origin);
|
|
167
166
|
const ac = new AbortController();
|
|
@@ -183,6 +182,10 @@ function publishPackage(storage, logger, origin) {
|
|
|
183
182
|
});
|
|
184
183
|
debug$1("package %s published", packageName);
|
|
185
184
|
res.status(_verdaccio_core.HTTP_STATUS.CREATED);
|
|
185
|
+
const [version] = Object.keys(metadata.versions ?? {});
|
|
186
|
+
(0, _verdaccio_hooks.notify)(metadata, config, req.remote_user, `${metadata.name}@${version}`, "publish").catch((error) => {
|
|
187
|
+
logger.error({ error: error?.message }, "notify batch service has failed: @{error}");
|
|
188
|
+
});
|
|
186
189
|
return next({
|
|
187
190
|
success: true,
|
|
188
191
|
ok: message
|
package/build/publish.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publish.js","names":[],"sources":["../src/publish.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport type { Router } from 'express';\n\nimport type { Auth } from '@verdaccio/auth';\nimport { API_MESSAGE, HEADERS, HTTP_STATUS } from '@verdaccio/core';\nimport {\n PUBLISH_API_ENDPOINTS,\n allow,\n expectJson,\n getRequestOptions,\n media,\n} from '@verdaccio/middleware';\n// import star from './star';\nimport type { Storage } from '@verdaccio/store';\nimport type { Logger } from '@verdaccio/types';\n\nimport type { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types/custom';\n\nconst debug = buildDebug('verdaccio:api:publish');\n\n/**\n * Publish a package / update package / un/start a package\n *\n * There are multiples scenarios here to be considered:\n *\n * 1. Publish scenario\n *\n * Publish a package consist of at least 1 step (PUT) with a metadata payload.\n * When a package is published, an _attachment property is present that contains the data\n * of the tarball.\n *\n * Example flow of publish.\n *\n * npm http fetch PUT 201 http://localhost:4873/@scope%2ftest1 9627ms\n npm info lifecycle @scope/test1@1.0.1~publish: @scope/test1@1.0.1\n npm info lifecycle @scope/test1@1.0.1~postpublish: @scope/test1@1.0.1\n + @scope/test1@1.0.1\n npm verb exit [ 0, true ]\n *\n *\n * 2. Unpublish scenario\n *\n * Unpublish consist in 3 steps.\n * 1. Try to fetch metadata -> if it fails, return 404\n * 2. Compute metadata locally (client side) and send a mutate payload excluding the version to\n * be unpublished\n * eg: if metadata reflects 1.0.1, 1.0.2 and 1.0.3, the computed metadata won't include 1.0.3.\n * 3. Once the second step has been successfully finished, delete the tarball.\n *\n * All these steps are consecutive and required, there is no transacions here, if step 3 fails,\n * metadata might get corrupted.\n *\n * Note the unpublish call will suffix in the url a /-rev/14-5d500cfce92f90fd revision number,\n * this not\n * used internally.\n *\n *\n * Example flow of unpublish.\n *\n * There are two possible flows:\n *\n * - Remove all packages (entirely)\n * eg: npm unpublish package-name@* --force\n * eg: npm unpublish package-name --force\n *\n * npm http fetch GET 200 http://localhost:4873/custom-name?write=true 1680ms\n * npm http fetch DELETE 201 http://localhost:4873/custom-name/-/test1-1.0.3.tgz/-rev/16-e11c8db282b2d992 19ms\n *\n * - Remove a specific version\n * eg: npm unpublish package-name@1.0.0 --force\n *\n * Get fresh manifest\n * npm http fetch GET 200 http://localhost:4873/custom-name?write=true 1680ms\n * Update manifest without the version to be unpublished\n * npm http fetch PUT 201 http://localhost:4873/custom-name/-rev/14-5d500cfce92f90fd 956606ms\n * Get fresh manifest (revision should be different)\n * npm http fetch GET 200 http://localhost:4873/custom-name?write=true 1601ms\n * Remove the tarball\n * npm http fetch DELETE 201 http://localhost:4873/custom-name/-/test1-1.0.3.tgz/-rev/16-e11c8db282b2d992 19ms\n *\n * 3. Star a package\n *\n * Permissions: staring a package depends of the publish and unpublish permissions, there is no\n * specific flag for star or unstar.\n * The URL for star is similar to the unpublish (change package format)\n *\n * npm has no endpoint for staring a package, rather mutate the metadata and acts as, the difference\n * is the users property which is part of the payload and the body only includes\n *\n * {\n \"_id\": pkgName,\n \"_rev\": \"3-b0cdaefc9bdb77c8\",\n \"users\": {\n [username]: boolean value (true, false)\n }\n }\n *\n * 4. Change owners of a package\n *\n * Similar to staring a package, changing owners (maintainers) of a package uses the publish\n * endpoint.\n *\n * The body includes a list of the new owners with the following format\n *\n * {\n \"_id\": pkgName,\n \"_rev\": \"4-b0cdaefc9bdb77c8\",\n \"maintainers\": [\n { \"name\": \"first owner\", \"email\": \"me@verdaccio.org\" },\n { \"name\": \"second owner\", \"email\": \"you@verdaccio.org\" },\n ...\n ]\n }\n *\n */\nexport default function publish(\n router: Router,\n auth: Auth,\n storage: Storage,\n logger: Logger\n): void {\n const can = allow(auth, {\n beforeAll: (a, b) => logger.trace(a, b),\n afterAll: (a, b) => logger.trace(a, b),\n });\n router.put(\n PUBLISH_API_ENDPOINTS.add_package,\n can('publish'),\n media(HEADERS.JSON),\n expectJson,\n publishPackage(storage, logger, 'publish one version')\n );\n\n router.put(\n PUBLISH_API_ENDPOINTS.publish_package,\n can('unpublish'),\n media(HEADERS.JSON),\n expectJson,\n publishPackage(storage, logger, 'publish with revision')\n );\n\n /**\n * Un-publishing an entire package.\n *\n * This scenario happens when any of these scenarios happens:\n * - the first call detect there is only one version remaining\n * - no version is specified in the unpublish call\n * - all versions are removed npm unpublish package@*\n * - there is no versions on the metadata\n\n * then the client decides to DELETE the resource\n * Example:\n * Get fresh manifest (write=true is a flag to get the latest revision)\n * npm http fetch GET 304 http://localhost:4873/package-name?write=true 1076ms (from cache)\n * Send request to delete the package, this includes the revision number that must match\n * and the package name, it will delete the entire package and all tarballs (or tarball depends the scenario)\n * npm http fetch DELETE 201 http://localhost:4873/package-name/-rev/18-d8ebe3020bd4ac9c 22ms\n */\n router.delete(\n PUBLISH_API_ENDPOINTS.publish_package,\n can('unpublish'),\n async function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer) {\n const packageName = req.params.package;\n const rev = req.params.revision;\n const username = req?.remote_user?.name;\n\n logger.debug({ packageName }, `unpublishing @{packageName}`);\n try {\n await storage.removePackage(packageName, rev, username);\n debug('package %s unpublished', packageName);\n res.status(HTTP_STATUS.CREATED);\n return next({ ok: API_MESSAGE.PKG_REMOVED });\n } catch (err) {\n return next(err);\n }\n }\n );\n\n /*\n Remove a tarball, this happens when npm unpublish a package unique version.\n npm http fetch DELETE 201 http://localhost:4873/package-name/-rev/18-d8ebe3020bd4ac9c 22ms\n */\n router.delete(\n PUBLISH_API_ENDPOINTS.remove_tarball,\n can('unpublish'),\n async function (\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer\n ): Promise<void> {\n const packageName = req.params.package;\n const { filename, revision } = req.params;\n const username = req?.remote_user?.name;\n\n logger.debug(\n { packageName, filename, revision },\n `removing a tarball for @{packageName}-@{tarballName}-@{revision}`\n );\n try {\n await storage.removeTarball(packageName, filename, revision, username);\n res.status(HTTP_STATUS.CREATED);\n\n logger.debug(\n { packageName, filename, revision },\n `success remove tarball for @{packageName}-@{tarballName}-@{revision}`\n );\n return next({ ok: API_MESSAGE.TARBALL_REMOVED });\n } catch (err) {\n return next(err);\n }\n }\n );\n}\n\nexport function publishPackage(storage: Storage, logger: Logger, origin: string): any {\n return async function (\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer\n ): Promise<void> {\n debug(origin);\n const ac = new AbortController();\n const packageName = req.params.package;\n const { revision } = req.params;\n debug('publishing package %s', packageName);\n debug('revision %s', revision);\n if (debug.enabled) {\n debug('body %o', req.body);\n }\n const metadata = req.body;\n\n logger.debug({ packageName }, `publishing package @{packageName}`);\n\n const requestOptions = getRequestOptions(req);\n\n try {\n const message = await storage.updateManifest(metadata, {\n name: packageName,\n revision,\n signal: ac.signal,\n requestOptions,\n uplinksLook: false,\n });\n debug('package %s published', packageName);\n\n res.status(HTTP_STATUS.CREATED);\n\n return next({\n success: true,\n ok: message,\n });\n } catch (err: any) {\n // TODO: review if we need the abort controller here\n next(err);\n }\n };\n}\n"],"mappings":";;;;;;AAkBA,IAAM,WAAA,GAAA,MAAA,SAAmB,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiGhD,SAAwB,QACtB,QACA,MACA,SACA,QACM;CACN,MAAM,OAAA,GAAA,sBAAA,OAAY,MAAM;EACtB,YAAY,GAAG,MAAM,OAAO,MAAM,GAAG,CAAC;EACtC,WAAW,GAAG,MAAM,OAAO,MAAM,GAAG,CAAC;CACvC,CAAC;CACD,OAAO,IACL,sBAAA,sBAAsB,aACtB,IAAI,SAAS,IAAA,GAAA,sBAAA,OACP,gBAAA,QAAQ,IAAI,GAClB,sBAAA,YACA,eAAe,SAAS,QAAQ,qBAAqB,CACvD;CAEA,OAAO,IACL,sBAAA,sBAAsB,iBACtB,IAAI,WAAW,IAAA,GAAA,sBAAA,OACT,gBAAA,QAAQ,IAAI,GAClB,sBAAA,YACA,eAAe,SAAS,QAAQ,uBAAuB,CACzD;;;;;;;;;;;;;;;;;;CAmBA,OAAO,OACL,sBAAA,sBAAsB,iBACtB,IAAI,WAAW,GACf,eAAgB,KAAqB,KAAsB,MAAwB;EACjF,MAAM,cAAc,IAAI,OAAO;EAC/B,MAAM,MAAM,IAAI,OAAO;EACvB,MAAM,WAAW,KAAK,aAAa;EAEnC,OAAO,MAAM,EAAE,YAAY,GAAG,6BAA6B;EAC3D,IAAI;GACF,MAAM,QAAQ,cAAc,aAAa,KAAK,QAAQ;GACtD,QAAM,0BAA0B,WAAW;GAC3C,IAAI,OAAO,gBAAA,YAAY,OAAO;GAC9B,OAAO,KAAK,EAAE,IAAI,gBAAA,YAAY,YAAY,CAAC;EAC7C,SAAS,KAAK;GACZ,OAAO,KAAK,GAAG;EACjB;CACF,CACF;C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ts"],"sourcesContent":["import buildDebug from 'debug';\nimport type { Router } from 'express';\n\nimport type { Auth } from '@verdaccio/auth';\nimport { API_MESSAGE, HEADERS, HTTP_STATUS, tarballUtils } from '@verdaccio/core';\nimport { notify } from '@verdaccio/hooks';\nimport {\n PUBLISH_API_ENDPOINTS,\n allow,\n expectJson,\n getRequestOptions,\n media,\n} from '@verdaccio/middleware';\nimport type { Storage } from '@verdaccio/store';\nimport type { Config, Logger, Manifest } from '@verdaccio/types';\n\nimport type { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types/custom';\n\nconst debug = buildDebug('verdaccio:api:publish');\n\n/**\n * Publish a package / update package\n *\n * There are multiples scenarios here to be considered:\n *\n * 1. Publish scenario\n *\n * Publish a package consist of at least 1 step (PUT) with a metadata payload.\n * When a package is published, an _attachment property is present that contains the data\n * of the tarball.\n *\n * Example flow of publish.\n *\n * npm http fetch PUT 201 http://localhost:4873/@scope%2ftest1 9627ms\n npm info lifecycle @scope/test1@1.0.1~publish: @scope/test1@1.0.1\n npm info lifecycle @scope/test1@1.0.1~postpublish: @scope/test1@1.0.1\n + @scope/test1@1.0.1\n npm verb exit [ 0, true ]\n *\n *\n * 2. Unpublish scenario\n *\n * Unpublish consist in 3 steps.\n * 1. Try to fetch metadata -> if it fails, return 404\n * 2. Compute metadata locally (client side) and send a mutate payload excluding the version to\n * be unpublished\n * eg: if metadata reflects 1.0.1, 1.0.2 and 1.0.3, the computed metadata won't include 1.0.3.\n * 3. Once the second step has been successfully finished, delete the tarball.\n *\n * All these steps are consecutive and required, there is no transacions here, if step 3 fails,\n * metadata might get corrupted.\n *\n * Note the unpublish call will suffix in the url a /-rev/14-5d500cfce92f90fd revision number,\n * this not\n * used internally.\n *\n *\n * Example flow of unpublish.\n *\n * There are two possible flows:\n *\n * - Remove all packages (entirely)\n * eg: npm unpublish package-name@* --force\n * eg: npm unpublish package-name --force\n *\n * npm http fetch GET 200 http://localhost:4873/custom-name?write=true 1680ms\n * npm http fetch DELETE 201 http://localhost:4873/custom-name/-/test1-1.0.3.tgz/-rev/16-e11c8db282b2d992 19ms\n *\n * - Remove a specific version\n * eg: npm unpublish package-name@1.0.0 --force\n *\n * Get fresh manifest\n * npm http fetch GET 200 http://localhost:4873/custom-name?write=true 1680ms\n * Update manifest without the version to be unpublished\n * npm http fetch PUT 201 http://localhost:4873/custom-name/-rev/14-5d500cfce92f90fd 956606ms\n * Get fresh manifest (revision should be different)\n * npm http fetch GET 200 http://localhost:4873/custom-name?write=true 1601ms\n * Remove the tarball\n * npm http fetch DELETE 201 http://localhost:4873/custom-name/-/test1-1.0.3.tgz/-rev/16-e11c8db282b2d992 19ms\n *\n * 3. Change owners of a package\n *\n * Changing owners (maintainers) of a package uses the publish endpoint.\n *\n * The body includes a list of the new owners with the following format\n *\n * {\n \"_id\": pkgName,\n \"_rev\": \"4-b0cdaefc9bdb77c8\",\n \"maintainers\": [\n { \"name\": \"first owner\", \"email\": \"me@verdaccio.org\" },\n { \"name\": \"second owner\", \"email\": \"you@verdaccio.org\" },\n ...\n ]\n }\n *\n */\nexport default function publish(\n router: Router,\n auth: Auth,\n storage: Storage,\n config: Config,\n logger: Logger\n): void {\n const can = allow(auth, {\n beforeAll: (a, b) => logger.trace(a, b),\n afterAll: (a, b) => logger.trace(a, b),\n });\n router.put(\n PUBLISH_API_ENDPOINTS.add_package,\n can('publish'),\n media(HEADERS.JSON),\n expectJson,\n publishPackage(storage, config, logger, 'publish one version')\n );\n\n router.put(\n PUBLISH_API_ENDPOINTS.publish_package,\n can('unpublish'),\n media(HEADERS.JSON),\n expectJson,\n publishPackage(storage, config, logger, 'publish with revision')\n );\n\n /**\n * Un-publishing an entire package.\n *\n * This scenario happens when any of these scenarios happens:\n * - the first call detect there is only one version remaining\n * - no version is specified in the unpublish call\n * - all versions are removed npm unpublish package@*\n * - there is no versions on the metadata\n\n * then the client decides to DELETE the resource\n * Example:\n * Get fresh manifest (write=true is a flag to get the latest revision)\n * npm http fetch GET 304 http://localhost:4873/package-name?write=true 1076ms (from cache)\n * Send request to delete the package, this includes the revision number that must match\n * and the package name, it will delete the entire package and all tarballs (or tarball depends the scenario)\n * npm http fetch DELETE 201 http://localhost:4873/package-name/-rev/18-d8ebe3020bd4ac9c 22ms\n */\n router.delete(\n PUBLISH_API_ENDPOINTS.publish_package,\n can('unpublish'),\n async function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer) {\n const packageName = req.params.package;\n const rev = req.params.revision;\n const username = req?.remote_user?.name;\n\n logger.debug({ packageName }, `unpublishing @{packageName}`);\n try {\n await storage.removePackage(packageName, rev, username);\n debug('package %s unpublished', packageName);\n res.status(HTTP_STATUS.CREATED);\n\n // send notification of package removal\n const metadata: Partial<Manifest> = { name: packageName, _rev: rev };\n\n void notify(metadata, config, req.remote_user, packageName, 'unpublish').catch(\n (error: any) => {\n logger.error({ error: error?.message }, 'notify batch service has failed: @{error}');\n }\n );\n\n return next({ ok: API_MESSAGE.PKG_REMOVED });\n } catch (err) {\n return next(err);\n }\n }\n );\n\n /*\n Remove a tarball, this happens when npm unpublish a package unique version.\n npm http fetch DELETE 201 http://localhost:4873/package-name/-rev/18-d8ebe3020bd4ac9c 22ms\n */\n router.delete(\n PUBLISH_API_ENDPOINTS.remove_tarball,\n can('unpublish'),\n async function (\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer\n ): Promise<void> {\n const packageName = req.params.package;\n const { filename, revision } = req.params;\n const username = req?.remote_user?.name;\n\n logger.debug(\n { packageName, filename, revision },\n `removing a tarball for @{packageName}-@{tarballName}-@{revision}`\n );\n try {\n await storage.removeTarball(packageName, filename, revision, username);\n res.status(HTTP_STATUS.CREATED);\n\n logger.debug(\n { packageName, filename, revision },\n `success remove tarball for @{packageName}-@{tarballName}-@{revision}`\n );\n\n // send notification of version removal\n // getVersionFromTarball returns undefined when the filename is not parseable;\n // fall back to the package name so we never report `name@undefined`\n const version = tarballUtils.getVersionFromTarball(filename);\n const metadata: Partial<Manifest> = { name: packageName, version, _rev: revision };\n const publishedPackage = version ? `${packageName}@${version}` : packageName;\n\n void notify(metadata, config, req.remote_user, publishedPackage, 'unpublish').catch(\n (error: any) => {\n logger.error({ error: error?.message }, 'notify batch service has failed: @{error}');\n }\n );\n\n return next({ ok: API_MESSAGE.TARBALL_REMOVED });\n } catch (err) {\n return next(err);\n }\n }\n );\n}\n\nexport function publishPackage(\n storage: Storage,\n config: Config,\n logger: Logger,\n origin: string\n): any {\n return async function (\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer\n ): Promise<void> {\n debug(origin);\n const ac = new AbortController();\n const packageName = req.params.package;\n const { revision } = req.params;\n debug('publishing package %s', packageName);\n debug('revision %s', revision);\n if (debug.enabled) {\n debug('body %o', req.body);\n }\n const metadata = req.body;\n\n logger.debug({ packageName }, `publishing package @{packageName}`);\n\n const requestOptions = getRequestOptions(req);\n\n try {\n const message = await storage.updateManifest(metadata, {\n name: packageName,\n revision,\n signal: ac.signal,\n requestOptions,\n uplinksLook: false,\n });\n debug('package %s published', packageName);\n res.status(HTTP_STATUS.CREATED);\n\n // send notification of publication (notification step, non transactional)\n // a publish body is a packument; the published version is the single entry\n // under `versions` (see storage.updateManifest), not a top-level field\n const [version] = Object.keys(metadata.versions ?? {});\n void notify(\n metadata,\n config,\n req.remote_user,\n `${metadata.name}@${version}`,\n 'publish'\n ).catch((error: any) => {\n logger.error({ error: error?.message }, 'notify batch service has failed: @{error}');\n });\n\n return next({\n success: true,\n ok: message,\n });\n } catch (err: any) {\n // TODO: review if we need the abort controller here\n next(err);\n }\n };\n}\n"],"mappings":";;;;;;;AAkBA,IAAM,WAAA,GAAA,MAAA,SAAmB,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+EhD,SAAwB,QACtB,QACA,MACA,SACA,QACA,QACM;CACN,MAAM,OAAA,GAAA,sBAAA,OAAY,MAAM;EACtB,YAAY,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K9B,MAAM,CAAC,WAAW,OAAO,KAAK,SAAS,YAAY,CAAC,CAAC;GACrD,CAAA,GAAA,iBAAA,QACE,UACA,QACA,IAAI,aACJ,GAAG,SAAS,KAAK,GAAG,WACpB,SACF,EAAE,OAAO,UAAe;IACtB,OAAO,MAAM,EAAE,OAAO,OAAO,QAAQ,GAAG,2CAA2C;GACrF,CAAC;GAED,OAAO,KAAK;IACV,SAAS;IACT,IAAI;GACN,CAAC;EACH,SAAS,KAAU;GAEjB,KAAK,GAAG;EACV;CACF;AACF"}
|
package/build/publish.mjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { PUBLISH_API_ENDPOINTS, allow, expectJson, getRequestOptions, media } from "@verdaccio/middleware";
|
|
2
|
-
import { API_MESSAGE, HEADERS, HTTP_STATUS } from "@verdaccio/core";
|
|
2
|
+
import { API_MESSAGE, HEADERS, HTTP_STATUS, tarballUtils } from "@verdaccio/core";
|
|
3
3
|
import buildDebug from "debug";
|
|
4
|
+
import { notify } from "@verdaccio/hooks";
|
|
4
5
|
//#region src/publish.ts
|
|
5
6
|
var debug = buildDebug("verdaccio:api:publish");
|
|
6
7
|
/**
|
|
7
|
-
* Publish a package / update package
|
|
8
|
+
* Publish a package / update package
|
|
8
9
|
*
|
|
9
10
|
* There are multiples scenarios here to be considered:
|
|
10
11
|
*
|
|
@@ -63,27 +64,9 @@ npm verb exit [ 0, true ]
|
|
|
63
64
|
* Remove the tarball
|
|
64
65
|
* npm http fetch DELETE 201 http://localhost:4873/custom-name/-/test1-1.0.3.tgz/-rev/16-e11c8db282b2d992 19ms
|
|
65
66
|
*
|
|
66
|
-
* 3.
|
|
67
|
+
* 3. Change owners of a package
|
|
67
68
|
*
|
|
68
|
-
*
|
|
69
|
-
* specific flag for star or unstar.
|
|
70
|
-
* The URL for star is similar to the unpublish (change package format)
|
|
71
|
-
*
|
|
72
|
-
* npm has no endpoint for staring a package, rather mutate the metadata and acts as, the difference
|
|
73
|
-
* is the users property which is part of the payload and the body only includes
|
|
74
|
-
*
|
|
75
|
-
* {
|
|
76
|
-
"_id": pkgName,
|
|
77
|
-
"_rev": "3-b0cdaefc9bdb77c8",
|
|
78
|
-
"users": {
|
|
79
|
-
[username]: boolean value (true, false)
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
*
|
|
83
|
-
* 4. Change owners of a package
|
|
84
|
-
*
|
|
85
|
-
* Similar to staring a package, changing owners (maintainers) of a package uses the publish
|
|
86
|
-
* endpoint.
|
|
69
|
+
* Changing owners (maintainers) of a package uses the publish endpoint.
|
|
87
70
|
*
|
|
88
71
|
* The body includes a list of the new owners with the following format
|
|
89
72
|
*
|
|
@@ -98,13 +81,13 @@ npm verb exit [ 0, true ]
|
|
|
98
81
|
}
|
|
99
82
|
*
|
|
100
83
|
*/
|
|
101
|
-
function publish(router, auth, storage, logger) {
|
|
84
|
+
function publish(router, auth, storage, config, logger) {
|
|
102
85
|
const can = allow(auth, {
|
|
103
86
|
beforeAll: (a, b) => logger.trace(a, b),
|
|
104
87
|
afterAll: (a, b) => logger.trace(a, b)
|
|
105
88
|
});
|
|
106
|
-
router.put(PUBLISH_API_ENDPOINTS.add_package, can("publish"), media(HEADERS.JSON), expectJson, publishPackage(storage, logger, "publish one version"));
|
|
107
|
-
router.put(PUBLISH_API_ENDPOINTS.publish_package, can("unpublish"), media(HEADERS.JSON), expectJson, publishPackage(storage, logger, "publish with revision"));
|
|
89
|
+
router.put(PUBLISH_API_ENDPOINTS.add_package, can("publish"), media(HEADERS.JSON), expectJson, publishPackage(storage, config, logger, "publish one version"));
|
|
90
|
+
router.put(PUBLISH_API_ENDPOINTS.publish_package, can("unpublish"), media(HEADERS.JSON), expectJson, publishPackage(storage, config, logger, "publish with revision"));
|
|
108
91
|
/**
|
|
109
92
|
* Un-publishing an entire package.
|
|
110
93
|
*
|
|
@@ -131,6 +114,12 @@ function publish(router, auth, storage, logger) {
|
|
|
131
114
|
await storage.removePackage(packageName, rev, username);
|
|
132
115
|
debug("package %s unpublished", packageName);
|
|
133
116
|
res.status(HTTP_STATUS.CREATED);
|
|
117
|
+
notify({
|
|
118
|
+
name: packageName,
|
|
119
|
+
_rev: rev
|
|
120
|
+
}, config, req.remote_user, packageName, "unpublish").catch((error) => {
|
|
121
|
+
logger.error({ error: error?.message }, "notify batch service has failed: @{error}");
|
|
122
|
+
});
|
|
134
123
|
return next({ ok: API_MESSAGE.PKG_REMOVED });
|
|
135
124
|
} catch (err) {
|
|
136
125
|
return next(err);
|
|
@@ -153,13 +142,23 @@ function publish(router, auth, storage, logger) {
|
|
|
153
142
|
filename,
|
|
154
143
|
revision
|
|
155
144
|
}, `success remove tarball for @{packageName}-@{tarballName}-@{revision}`);
|
|
145
|
+
const version = tarballUtils.getVersionFromTarball(filename);
|
|
146
|
+
const metadata = {
|
|
147
|
+
name: packageName,
|
|
148
|
+
version,
|
|
149
|
+
_rev: revision
|
|
150
|
+
};
|
|
151
|
+
const publishedPackage = version ? `${packageName}@${version}` : packageName;
|
|
152
|
+
notify(metadata, config, req.remote_user, publishedPackage, "unpublish").catch((error) => {
|
|
153
|
+
logger.error({ error: error?.message }, "notify batch service has failed: @{error}");
|
|
154
|
+
});
|
|
156
155
|
return next({ ok: API_MESSAGE.TARBALL_REMOVED });
|
|
157
156
|
} catch (err) {
|
|
158
157
|
return next(err);
|
|
159
158
|
}
|
|
160
159
|
});
|
|
161
160
|
}
|
|
162
|
-
function publishPackage(storage, logger, origin) {
|
|
161
|
+
function publishPackage(storage, config, logger, origin) {
|
|
163
162
|
return async function(req, res, next) {
|
|
164
163
|
debug(origin);
|
|
165
164
|
const ac = new AbortController();
|
|
@@ -181,6 +180,10 @@ function publishPackage(storage, logger, origin) {
|
|
|
181
180
|
});
|
|
182
181
|
debug("package %s published", packageName);
|
|
183
182
|
res.status(HTTP_STATUS.CREATED);
|
|
183
|
+
const [version] = Object.keys(metadata.versions ?? {});
|
|
184
|
+
notify(metadata, config, req.remote_user, `${metadata.name}@${version}`, "publish").catch((error) => {
|
|
185
|
+
logger.error({ error: error?.message }, "notify batch service has failed: @{error}");
|
|
186
|
+
});
|
|
184
187
|
return next({
|
|
185
188
|
success: true,
|
|
186
189
|
ok: message
|
package/build/publish.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publish.mjs","names":[],"sources":["../src/publish.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport type { Router } from 'express';\n\nimport type { Auth } from '@verdaccio/auth';\nimport { API_MESSAGE, HEADERS, HTTP_STATUS } from '@verdaccio/core';\nimport {\n PUBLISH_API_ENDPOINTS,\n allow,\n expectJson,\n getRequestOptions,\n media,\n} from '@verdaccio/middleware';\n// import star from './star';\nimport type { Storage } from '@verdaccio/store';\nimport type { Logger } from '@verdaccio/types';\n\nimport type { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types/custom';\n\nconst debug = buildDebug('verdaccio:api:publish');\n\n/**\n * Publish a package / update package / un/start a package\n *\n * There are multiples scenarios here to be considered:\n *\n * 1. Publish scenario\n *\n * Publish a package consist of at least 1 step (PUT) with a metadata payload.\n * When a package is published, an _attachment property is present that contains the data\n * of the tarball.\n *\n * Example flow of publish.\n *\n * npm http fetch PUT 201 http://localhost:4873/@scope%2ftest1 9627ms\n npm info lifecycle @scope/test1@1.0.1~publish: @scope/test1@1.0.1\n npm info lifecycle @scope/test1@1.0.1~postpublish: @scope/test1@1.0.1\n + @scope/test1@1.0.1\n npm verb exit [ 0, true ]\n *\n *\n * 2. Unpublish scenario\n *\n * Unpublish consist in 3 steps.\n * 1. Try to fetch metadata -> if it fails, return 404\n * 2. Compute metadata locally (client side) and send a mutate payload excluding the version to\n * be unpublished\n * eg: if metadata reflects 1.0.1, 1.0.2 and 1.0.3, the computed metadata won't include 1.0.3.\n * 3. Once the second step has been successfully finished, delete the tarball.\n *\n * All these steps are consecutive and required, there is no transacions here, if step 3 fails,\n * metadata might get corrupted.\n *\n * Note the unpublish call will suffix in the url a /-rev/14-5d500cfce92f90fd revision number,\n * this not\n * used internally.\n *\n *\n * Example flow of unpublish.\n *\n * There are two possible flows:\n *\n * - Remove all packages (entirely)\n * eg: npm unpublish package-name@* --force\n * eg: npm unpublish package-name --force\n *\n * npm http fetch GET 200 http://localhost:4873/custom-name?write=true 1680ms\n * npm http fetch DELETE 201 http://localhost:4873/custom-name/-/test1-1.0.3.tgz/-rev/16-e11c8db282b2d992 19ms\n *\n * - Remove a specific version\n * eg: npm unpublish package-name@1.0.0 --force\n *\n * Get fresh manifest\n * npm http fetch GET 200 http://localhost:4873/custom-name?write=true 1680ms\n * Update manifest without the version to be unpublished\n * npm http fetch PUT 201 http://localhost:4873/custom-name/-rev/14-5d500cfce92f90fd 956606ms\n * Get fresh manifest (revision should be different)\n * npm http fetch GET 200 http://localhost:4873/custom-name?write=true 1601ms\n * Remove the tarball\n * npm http fetch DELETE 201 http://localhost:4873/custom-name/-/test1-1.0.3.tgz/-rev/16-e11c8db282b2d992 19ms\n *\n * 3. Star a package\n *\n * Permissions: staring a package depends of the publish and unpublish permissions, there is no\n * specific flag for star or unstar.\n * The URL for star is similar to the unpublish (change package format)\n *\n * npm has no endpoint for staring a package, rather mutate the metadata and acts as, the difference\n * is the users property which is part of the payload and the body only includes\n *\n * {\n \"_id\": pkgName,\n \"_rev\": \"3-b0cdaefc9bdb77c8\",\n \"users\": {\n [username]: boolean value (true, false)\n }\n }\n *\n * 4. Change owners of a package\n *\n * Similar to staring a package, changing owners (maintainers) of a package uses the publish\n * endpoint.\n *\n * The body includes a list of the new owners with the following format\n *\n * {\n \"_id\": pkgName,\n \"_rev\": \"4-b0cdaefc9bdb77c8\",\n \"maintainers\": [\n { \"name\": \"first owner\", \"email\": \"me@verdaccio.org\" },\n { \"name\": \"second owner\", \"email\": \"you@verdaccio.org\" },\n ...\n ]\n }\n *\n */\nexport default function publish(\n router: Router,\n auth: Auth,\n storage: Storage,\n logger: Logger\n): void {\n const can = allow(auth, {\n beforeAll: (a, b) => logger.trace(a, b),\n afterAll: (a, b) => logger.trace(a, b),\n });\n router.put(\n PUBLISH_API_ENDPOINTS.add_package,\n can('publish'),\n media(HEADERS.JSON),\n expectJson,\n publishPackage(storage, logger, 'publish one version')\n );\n\n router.put(\n PUBLISH_API_ENDPOINTS.publish_package,\n can('unpublish'),\n media(HEADERS.JSON),\n expectJson,\n publishPackage(storage, logger, 'publish with revision')\n );\n\n /**\n * Un-publishing an entire package.\n *\n * This scenario happens when any of these scenarios happens:\n * - the first call detect there is only one version remaining\n * - no version is specified in the unpublish call\n * - all versions are removed npm unpublish package@*\n * - there is no versions on the metadata\n\n * then the client decides to DELETE the resource\n * Example:\n * Get fresh manifest (write=true is a flag to get the latest revision)\n * npm http fetch GET 304 http://localhost:4873/package-name?write=true 1076ms (from cache)\n * Send request to delete the package, this includes the revision number that must match\n * and the package name, it will delete the entire package and all tarballs (or tarball depends the scenario)\n * npm http fetch DELETE 201 http://localhost:4873/package-name/-rev/18-d8ebe3020bd4ac9c 22ms\n */\n router.delete(\n PUBLISH_API_ENDPOINTS.publish_package,\n can('unpublish'),\n async function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer) {\n const packageName = req.params.package;\n const rev = req.params.revision;\n const username = req?.remote_user?.name;\n\n logger.debug({ packageName }, `unpublishing @{packageName}`);\n try {\n await storage.removePackage(packageName, rev, username);\n debug('package %s unpublished', packageName);\n res.status(HTTP_STATUS.CREATED);\n return next({ ok: API_MESSAGE.PKG_REMOVED });\n } catch (err) {\n return next(err);\n }\n }\n );\n\n /*\n Remove a tarball, this happens when npm unpublish a package unique version.\n npm http fetch DELETE 201 http://localhost:4873/package-name/-rev/18-d8ebe3020bd4ac9c 22ms\n */\n router.delete(\n PUBLISH_API_ENDPOINTS.remove_tarball,\n can('unpublish'),\n async function (\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer\n ): Promise<void> {\n const packageName = req.params.package;\n const { filename, revision } = req.params;\n const username = req?.remote_user?.name;\n\n logger.debug(\n { packageName, filename, revision },\n `removing a tarball for @{packageName}-@{tarballName}-@{revision}`\n );\n try {\n await storage.removeTarball(packageName, filename, revision, username);\n res.status(HTTP_STATUS.CREATED);\n\n logger.debug(\n { packageName, filename, revision },\n `success remove tarball for @{packageName}-@{tarballName}-@{revision}`\n );\n return next({ ok: API_MESSAGE.TARBALL_REMOVED });\n } catch (err) {\n return next(err);\n }\n }\n );\n}\n\nexport function publishPackage(storage: Storage, logger: Logger, origin: string): any {\n return async function (\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer\n ): Promise<void> {\n debug(origin);\n const ac = new AbortController();\n const packageName = req.params.package;\n const { revision } = req.params;\n debug('publishing package %s', packageName);\n debug('revision %s', revision);\n if (debug.enabled) {\n debug('body %o', req.body);\n }\n const metadata = req.body;\n\n logger.debug({ packageName }, `publishing package @{packageName}`);\n\n const requestOptions = getRequestOptions(req);\n\n try {\n const message = await storage.updateManifest(metadata, {\n name: packageName,\n revision,\n signal: ac.signal,\n requestOptions,\n uplinksLook: false,\n });\n debug('package %s published', packageName);\n\n res.status(HTTP_STATUS.CREATED);\n\n return next({\n success: true,\n ok: message,\n });\n } catch (err: any) {\n // TODO: review if we need the abort controller here\n next(err);\n }\n };\n}\n"],"mappings":";;;;AAkBA,IAAM,QAAQ,WAAW,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiGhD,SAAwB,QACtB,QACA,MACA,SACA,QACM;CACN,MAAM,MAAM,MAAM,MAAM;EACtB,YAAY,GAAG,MAAM,OAAO,MAAM,GAAG,CAAC;EACtC,WAAW,GAAG,MAAM,OAAO,MAAM,GAAG,CAAC;CACvC,CAAC;CACD,OAAO,IACL,sBAAsB,aACtB,IAAI,SAAS,GACb,MAAM,QAAQ,IAAI,GAClB,YACA,eAAe,SAAS,QAAQ,qBAAqB,CACvD;CAEA,OAAO,IACL,sBAAsB,iB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AC1C,MAAM,eAAe,QAAQ;EAC7B,IAAI,MAAM,SACR,MAAM,WAAW,IAAI,IAAI;EAE3B,MAAM,WAAW,IAAI;EAErB,OAAO,MAAM,EAAE,YAAY,GAAG,mCAAmC;EAEjE,MAAM,iBAAiB,kBAAkB,GAAG;EAE5C,IAAI;GACF,MAAM,UAAU,MAAM,QAAQ,eAAe,UAAU;IACrD,MAAM;IACN;IACA,QAAQ,GAAG;IACX;IACA,aAAa;GACf,CAAC;GACD,MAAM,wBAAwB,WAAW;GAEzC,IAAI,OAAO,YAAY,OAAO;GAE9B,OAAO,KAAK;IACV,SAAS;IACT,IAAI;GACN,CAAC;EACH,SAAS,KAAU;GAEjB,KAAK,GAAG;EACV;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"publish.mjs","names":[],"sources":["../src/publish.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport type { Router } from 'express';\n\nimport type { Auth } from '@verdaccio/auth';\nimport { API_MESSAGE, HEADERS, HTTP_STATUS, tarballUtils } from '@verdaccio/core';\nimport { notify } from '@verdaccio/hooks';\nimport {\n PUBLISH_API_ENDPOINTS,\n allow,\n expectJson,\n getRequestOptions,\n media,\n} from '@verdaccio/middleware';\nimport type { Storage } from '@verdaccio/store';\nimport type { Config, Logger, Manifest } from '@verdaccio/types';\n\nimport type { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types/custom';\n\nconst debug = buildDebug('verdaccio:api:publish');\n\n/**\n * Publish a package / update package\n *\n * There are multiples scenarios here to be considered:\n *\n * 1. Publish scenario\n *\n * Publish a package consist of at least 1 step (PUT) with a metadata payload.\n * When a package is published, an _attachment property is present that contains the data\n * of the tarball.\n *\n * Example flow of publish.\n *\n * npm http fetch PUT 201 http://localhost:4873/@scope%2ftest1 9627ms\n npm info lifecycle @scope/test1@1.0.1~publish: @scope/test1@1.0.1\n npm info lifecycle @scope/test1@1.0.1~postpublish: @scope/test1@1.0.1\n + @scope/test1@1.0.1\n npm verb exit [ 0, true ]\n *\n *\n * 2. Unpublish scenario\n *\n * Unpublish consist in 3 steps.\n * 1. Try to fetch metadata -> if it fails, return 404\n * 2. Compute metadata locally (client side) and send a mutate payload excluding the version to\n * be unpublished\n * eg: if metadata reflects 1.0.1, 1.0.2 and 1.0.3, the computed metadata won't include 1.0.3.\n * 3. Once the second step has been successfully finished, delete the tarball.\n *\n * All these steps are consecutive and required, there is no transacions here, if step 3 fails,\n * metadata might get corrupted.\n *\n * Note the unpublish call will suffix in the url a /-rev/14-5d500cfce92f90fd revision number,\n * this not\n * used internally.\n *\n *\n * Example flow of unpublish.\n *\n * There are two possible flows:\n *\n * - Remove all packages (entirely)\n * eg: npm unpublish package-name@* --force\n * eg: npm unpublish package-name --force\n *\n * npm http fetch GET 200 http://localhost:4873/custom-name?write=true 1680ms\n * npm http fetch DELETE 201 http://localhost:4873/custom-name/-/test1-1.0.3.tgz/-rev/16-e11c8db282b2d992 19ms\n *\n * - Remove a specific version\n * eg: npm unpublish package-name@1.0.0 --force\n *\n * Get fresh manifest\n * npm http fetch GET 200 http://localhost:4873/custom-name?write=true 1680ms\n * Update manifest without the version to be unpublished\n * npm http fetch PUT 201 http://localhost:4873/custom-name/-rev/14-5d500cfce92f90fd 956606ms\n * Get fresh manifest (revision should be different)\n * npm http fetch GET 200 http://localhost:4873/custom-name?write=true 1601ms\n * Remove the tarball\n * npm http fetch DELETE 201 http://localhost:4873/custom-name/-/test1-1.0.3.tgz/-rev/16-e11c8db282b2d992 19ms\n *\n * 3. Change owners of a package\n *\n * Changing owners (maintainers) of a package uses the publish endpoint.\n *\n * The body includes a list of the new owners with the following format\n *\n * {\n \"_id\": pkgName,\n \"_rev\": \"4-b0cdaefc9bdb77c8\",\n \"maintainers\": [\n { \"name\": \"first owner\", \"email\": \"me@verdaccio.org\" },\n { \"name\": \"second owner\", \"email\": \"you@verdaccio.org\" },\n ...\n ]\n }\n *\n */\nexport default function publish(\n router: Router,\n auth: Auth,\n storage: Storage,\n config: Config,\n logger: Logger\n): void {\n const can = allow(auth, {\n beforeAll: (a, b) => logger.trace(a, b),\n afterAll: (a, b) => logger.trace(a, b),\n });\n router.put(\n PUBLISH_API_ENDPOINTS.add_package,\n can('publish'),\n media(HEADERS.JSON),\n expectJson,\n publishPackage(storage, config, logger, 'publish one version')\n );\n\n router.put(\n PUBLISH_API_ENDPOINTS.publish_package,\n can('unpublish'),\n media(HEADERS.JSON),\n expectJson,\n publishPackage(storage, config, logger, 'publish with revision')\n );\n\n /**\n * Un-publishing an entire package.\n *\n * This scenario happens when any of these scenarios happens:\n * - the first call detect there is only one version remaining\n * - no version is specified in the unpublish call\n * - all versions are removed npm unpublish package@*\n * - there is no versions on the metadata\n\n * then the client decides to DELETE the resource\n * Example:\n * Get fresh manifest (write=true is a flag to get the latest revision)\n * npm http fetch GET 304 http://localhost:4873/package-name?write=true 1076ms (from cache)\n * Send request to delete the package, this includes the revision number that must match\n * and the package name, it will delete the entire package and all tarballs (or tarball depends the scenario)\n * npm http fetch DELETE 201 http://localhost:4873/package-name/-rev/18-d8ebe3020bd4ac9c 22ms\n */\n router.delete(\n PUBLISH_API_ENDPOINTS.publish_package,\n can('unpublish'),\n async function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer) {\n const packageName = req.params.package;\n const rev = req.params.revision;\n const username = req?.remote_user?.name;\n\n logger.debug({ packageName }, `unpublishing @{packageName}`);\n try {\n await storage.removePackage(packageName, rev, username);\n debug('package %s unpublished', packageName);\n res.status(HTTP_STATUS.CREATED);\n\n // send notification of package removal\n const metadata: Partial<Manifest> = { name: packageName, _rev: rev };\n\n void notify(metadata, config, req.remote_user, packageName, 'unpublish').catch(\n (error: any) => {\n logger.error({ error: error?.message }, 'notify batch service has failed: @{error}');\n }\n );\n\n return next({ ok: API_MESSAGE.PKG_REMOVED });\n } catch (err) {\n return next(err);\n }\n }\n );\n\n /*\n Remove a tarball, this happens when npm unpublish a package unique version.\n npm http fetch DELETE 201 http://localhost:4873/package-name/-rev/18-d8ebe3020bd4ac9c 22ms\n */\n router.delete(\n PUBLISH_API_ENDPOINTS.remove_tarball,\n can('unpublish'),\n async function (\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer\n ): Promise<void> {\n const packageName = req.params.package;\n const { filename, revision } = req.params;\n const username = req?.remote_user?.name;\n\n logger.debug(\n { packageName, filename, revision },\n `removing a tarball for @{packageName}-@{tarballName}-@{revision}`\n );\n try {\n await storage.removeTarball(packageName, filename, revision, username);\n res.status(HTTP_STATUS.CREATED);\n\n logger.debug(\n { packageName, filename, revision },\n `success remove tarball for @{packageName}-@{tarballName}-@{revision}`\n );\n\n // send notification of version removal\n // getVersionFromTarball returns undefined when the filename is not parseable;\n // fall back to the package name so we never report `name@undefined`\n const version = tarballUtils.getVersionFromTarball(filename);\n const metadata: Partial<Manifest> = { name: packageName, version, _rev: revision };\n const publishedPackage = version ? `${packageName}@${version}` : packageName;\n\n void notify(metadata, config, req.remote_user, publishedPackage, 'unpublish').catch(\n (error: any) => {\n logger.error({ error: error?.message }, 'notify batch service has failed: @{error}');\n }\n );\n\n return next({ ok: API_MESSAGE.TARBALL_REMOVED });\n } catch (err) {\n return next(err);\n }\n }\n );\n}\n\nexport function publishPackage(\n storage: Storage,\n config: Config,\n logger: Logger,\n origin: string\n): any {\n return async function (\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer\n ): Promise<void> {\n debug(origin);\n const ac = new AbortController();\n const packageName = req.params.package;\n const { revision } = req.params;\n debug('publishing package %s', packageName);\n debug('revision %s', revision);\n if (debug.enabled) {\n debug('body %o', req.body);\n }\n const metadata = req.body;\n\n logger.debug({ packageName }, `publishing package @{packageName}`);\n\n const requestOptions = getRequestOptions(req);\n\n try {\n const message = await storage.updateManifest(metadata, {\n name: packageName,\n revision,\n signal: ac.signal,\n requestOptions,\n uplinksLook: false,\n });\n debug('package %s published', packageName);\n res.status(HTTP_STATUS.CREATED);\n\n // send notification of publication (notification step, non transactional)\n // a publish body is a packument; the published version is the single entry\n // under `versions` (see storage.updateManifest), not a top-level field\n const [version] = Object.keys(metadata.versions ?? {});\n void notify(\n metadata,\n config,\n req.remote_user,\n `${metadata.name}@${version}`,\n 'publish'\n ).catch((error: any) => {\n logger.error({ error: error?.message }, 'notify batch service has failed: @{error}');\n });\n\n return next({\n success: true,\n ok: message,\n });\n } catch (err: any) {\n // TODO: review if we need the abort controller here\n next(err);\n }\n };\n}\n"],"mappings":";;;;;AAkBA,IAAM,QAAQ,WAAW,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+EhD,SAAwB,QACtB,QACA,MACA,SACA,QACA,QACM;CACN,MAAM,MAAM,MAAM,MAAM;EACtB,YAAY,GAAG,MAAM,OAAO,MAAM,GAAG,CAAC;EACtC,WAAW,GAAG,MAAM,OAAO,MAAM,GAAG,CAAC;CACvC,CAAC;CACD,OAAO,IACL,sBAAsB,aACtB,IAAI,SAAS,GACb,MAAM,QAAQ,IAAI,GAClB,YACA,eAAe,SAAS,QAAQ,QAAQ,qBAAqB,CAC/D;CAEA,OAAO,IACL,sBAAsB,iBACtB,IAAI,WAAW,GACf,MAAM,QAAQ,IAAI,GAClB,YACA,eAAe,SAAS,QAAQ,QAAQ,uBAAuB,CACjE;;;;;;;;;;;;;;;;;;CAmBA,OAAO,OACL,sBAAsB,iBACtB,IAAI,WAAW,GACf,eAAgB,KAAqB,KAAsB,MAAwB;EACjF,MAAM,cAAc,IAAI,OAAO;EAC/B,MAAM,MAAM,IAAI,OAAO;EACvB,MAAM,WAAW,KAAK,aAAa;EAEnC,OAAO,MAAM,EAAE,YAAY,GAAG,6BAA6B;EAC3D,IAAI;GACF,MAAM,QAAQ,cAAc,aAAa,KAAK,QAAQ;GACtD,MAAM,0BAA0B,WAAW;GAC3C,IAAI,OAAO,YAAY,OAAO;GAK9B,OAAY;IAF0B,MAAM;IAAa,MAAM;GAEnD,GAAU,QAAQ,IAAI,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AM,WAAW,IAAI,IAAI;EAE3B,MAAM,WAAW,IAAI;EAErB,OAAO,MAAM,EAAE,YAAY,GAAG,mCAAmC;EAEjE,MAAM,iBAAiB,kBAAkB,GAAG;EAE5C,IAAI;GACF,MAAM,UAAU,MAAM,QAAQ,eAAe,UAAU;IACrD,MAAM;IACN;IACA,QAAQ,GAAG;IACX;IACA,aAAa;GACf,CAAC;GACD,MAAM,wBAAwB,WAAW;GACzC,IAAI,OAAO,YAAY,OAAO;GAK9B,MAAM,CAAC,WAAW,OAAO,KAAK,SAAS,YAAY,CAAC,CAAC;GACrD,OACE,UACA,QACA,IAAI,aACJ,GAAG,SAAS,KAAK,GAAG,WACpB,SACF,EAAE,OAAO,UAAe;IACtB,OAAO,MAAM,EAAE,OAAO,OAAO,QAAQ,GAAG,2CAA2C;GACrF,CAAC;GAED,OAAO,KAAK;IACV,SAAS;IACT,IAAI;GACN,CAAC;EACH,SAAS,KAAU;GAEjB,KAAK,GAAG;EACV;CACF;AACF"}
|
package/build/v1/token.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
let _verdaccio_middleware = require("@verdaccio/middleware");
|
|
2
2
|
let _verdaccio_core = require("@verdaccio/core");
|
|
3
|
-
let lodash_es = require("lodash-es");
|
|
4
3
|
let _verdaccio_auth = require("@verdaccio/auth");
|
|
4
|
+
let lodash_es = require("lodash-es");
|
|
5
5
|
//#region src/v1/token.ts
|
|
6
6
|
function normalizeToken(token) {
|
|
7
7
|
return {
|
package/build/v1/token.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TOKEN_API_ENDPOINTS, rateLimit } from "@verdaccio/middleware";
|
|
2
2
|
import { HEADERS, HTTP_STATUS, SUPPORT_ERRORS, cryptoUtils, errorUtils } from "@verdaccio/core";
|
|
3
|
-
import { isBoolean, isNil } from "lodash-es";
|
|
4
3
|
import { getApiToken } from "@verdaccio/auth";
|
|
4
|
+
import { isBoolean, isNil } from "lodash-es";
|
|
5
5
|
//#region src/v1/token.ts
|
|
6
6
|
function normalizeToken(token) {
|
|
7
7
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verdaccio/api",
|
|
3
|
-
"version": "9.0.0-next-9.
|
|
3
|
+
"version": "9.0.0-next-9.19",
|
|
4
4
|
"description": "Verdaccio Registry API",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -33,23 +33,26 @@
|
|
|
33
33
|
},
|
|
34
34
|
"license": "MIT",
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@verdaccio/auth": "9.0.0-next-9.
|
|
37
|
-
"@verdaccio/config": "9.0.0-next-9.
|
|
38
|
-
"@verdaccio/core": "9.0.0-next-9.
|
|
39
|
-
"@verdaccio/
|
|
40
|
-
"@verdaccio/
|
|
41
|
-
"@verdaccio/
|
|
36
|
+
"@verdaccio/auth": "9.0.0-next-9.19",
|
|
37
|
+
"@verdaccio/config": "9.0.0-next-9.19",
|
|
38
|
+
"@verdaccio/core": "9.0.0-next-9.19",
|
|
39
|
+
"@verdaccio/hooks": "9.0.0-next-9.19",
|
|
40
|
+
"@verdaccio/logger": "9.0.0-next-9.19",
|
|
41
|
+
"@verdaccio/middleware": "9.0.0-next-9.19",
|
|
42
|
+
"@verdaccio/store": "9.0.0-next-9.19",
|
|
42
43
|
"debug": "4.4.3",
|
|
43
44
|
"express": "5.2.1",
|
|
44
45
|
"lodash-es": "4.18.1"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
|
47
48
|
"@types/lodash-es": "4.17.12",
|
|
48
|
-
"@verdaccio/test-helper": "5.0.0-next-9.
|
|
49
|
-
"@verdaccio/types": "14.0.0-next-9.
|
|
49
|
+
"@verdaccio/test-helper": "5.0.0-next-9.20",
|
|
50
|
+
"@verdaccio/types": "14.0.0-next-9.10",
|
|
50
51
|
"mockdate": "3.0.5",
|
|
51
52
|
"nock": "13.5.6",
|
|
53
|
+
"rimraf": "6.1.3",
|
|
52
54
|
"supertest": "7.1.4",
|
|
55
|
+
"vite": "8.0.14",
|
|
53
56
|
"vitest": "4.1.7"
|
|
54
57
|
},
|
|
55
58
|
"funding": {
|
package/build/stars.d.ts
DELETED
package/build/stars.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
let _verdaccio_middleware = require("@verdaccio/middleware");
|
|
2
|
-
let _verdaccio_core = require("@verdaccio/core");
|
|
3
|
-
let lodash_es = require("lodash-es");
|
|
4
|
-
//#region src/stars.ts
|
|
5
|
-
function stars_default(route, storage) {
|
|
6
|
-
route.get(_verdaccio_middleware.STARS_API_ENDPOINTS.get_user_starred_packages, async (req, res, next) => {
|
|
7
|
-
const query = req.query;
|
|
8
|
-
if (typeof query?.key !== "string") return next(_verdaccio_core.errorUtils.getBadRequest("missing query key username"));
|
|
9
|
-
try {
|
|
10
|
-
const filteredPackages = (await storage.getLocalDatabase()).filter((localPackage) => (0, lodash_es.keys)(localPackage[_verdaccio_core.USERS]).includes(query?.key.toString().replace(/['"]+/g, "")));
|
|
11
|
-
res.status(_verdaccio_core.HTTP_STATUS.OK);
|
|
12
|
-
next({ rows: filteredPackages.map((filteredPackage) => ({ value: filteredPackage.name })) });
|
|
13
|
-
} catch (err) {
|
|
14
|
-
return next(err);
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
//#endregion
|
|
19
|
-
exports.default = stars_default;
|
|
20
|
-
|
|
21
|
-
//# sourceMappingURL=stars.js.map
|
package/build/stars.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stars.js","names":[],"sources":["../src/stars.ts"],"sourcesContent":["import type { Response, Router } from 'express';\nimport { keys } from 'lodash-es';\n\nimport { HTTP_STATUS, USERS, errorUtils } from '@verdaccio/core';\nimport { STARS_API_ENDPOINTS } from '@verdaccio/middleware';\nimport type { Storage } from '@verdaccio/store';\nimport type { Version } from '@verdaccio/types';\n\nimport type { $NextFunctionVer, $RequestExtend } from '../types/custom';\n\nexport default function (route: Router, storage: Storage): void {\n route.get(\n STARS_API_ENDPOINTS.get_user_starred_packages,\n async (req: $RequestExtend, res: Response, next: $NextFunctionVer): Promise<void> => {\n const query: { key: string } = req.query;\n if (typeof query?.key !== 'string') {\n return next(errorUtils.getBadRequest('missing query key username'));\n }\n\n try {\n const localPackages: Version[] = await storage.getLocalDatabase();\n const filteredPackages: Version[] = localPackages.filter((localPackage: Version) =>\n keys(localPackage[USERS]).includes(query?.key.toString().replace(/['\"]+/g, ''))\n );\n\n res.status(HTTP_STATUS.OK);\n next({\n rows: filteredPackages.map((filteredPackage: Version) => ({\n value: filteredPackage.name,\n })),\n });\n } catch (err: any) {\n return next(err);\n }\n }\n );\n}\n"],"mappings":";;;;AAUA,SAAA,cAAyB,OAAe,SAAwB;CAC9D,MAAM,IACJ,sBAAA,oBAAoB,2BACpB,OAAO,KAAqB,KAAe,SAA0C;EACnF,MAAM,QAAyB,IAAI;EACnC,IAAI,OAAO,OAAO,QAAQ,UACxB,OAAO,KAAK,gBAAA,WAAW,cAAc,4BAA4B,CAAC;EAGpE,IAAI;GAEF,MAAM,oBAA8B,MADG,QAAQ,iBAAiB,GACd,QAAQ,kBAAA,GAAA,UAAA,MACnD,aAAa,gBAAA,MAAM,EAAE,SAAS,OAAO,IAAI,SAAS,EAAE,QAAQ,UAAU,EAAE,CAAC,CAChF;GAEA,IAAI,OAAO,gBAAA,YAAY,EAAE;GACzB,KAAK,EACH,MAAM,iBAAiB,KAAK,qBAA8B,EACxD,OAAO,gBAAgB,KACzB,EAAE,EACJ,CAAC;EACH,SAAS,KAAU;GACjB,OAAO,KAAK,GAAG;EACjB;CACF,CACF;AACF"}
|
package/build/stars.mjs
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { STARS_API_ENDPOINTS } from "@verdaccio/middleware";
|
|
2
|
-
import { HTTP_STATUS, USERS, errorUtils } from "@verdaccio/core";
|
|
3
|
-
import { keys } from "lodash-es";
|
|
4
|
-
//#region src/stars.ts
|
|
5
|
-
function stars_default(route, storage) {
|
|
6
|
-
route.get(STARS_API_ENDPOINTS.get_user_starred_packages, async (req, res, next) => {
|
|
7
|
-
const query = req.query;
|
|
8
|
-
if (typeof query?.key !== "string") return next(errorUtils.getBadRequest("missing query key username"));
|
|
9
|
-
try {
|
|
10
|
-
const filteredPackages = (await storage.getLocalDatabase()).filter((localPackage) => keys(localPackage[USERS]).includes(query?.key.toString().replace(/['"]+/g, "")));
|
|
11
|
-
res.status(HTTP_STATUS.OK);
|
|
12
|
-
next({ rows: filteredPackages.map((filteredPackage) => ({ value: filteredPackage.name })) });
|
|
13
|
-
} catch (err) {
|
|
14
|
-
return next(err);
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
//#endregion
|
|
19
|
-
export { stars_default as default };
|
|
20
|
-
|
|
21
|
-
//# sourceMappingURL=stars.mjs.map
|
package/build/stars.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stars.mjs","names":[],"sources":["../src/stars.ts"],"sourcesContent":["import type { Response, Router } from 'express';\nimport { keys } from 'lodash-es';\n\nimport { HTTP_STATUS, USERS, errorUtils } from '@verdaccio/core';\nimport { STARS_API_ENDPOINTS } from '@verdaccio/middleware';\nimport type { Storage } from '@verdaccio/store';\nimport type { Version } from '@verdaccio/types';\n\nimport type { $NextFunctionVer, $RequestExtend } from '../types/custom';\n\nexport default function (route: Router, storage: Storage): void {\n route.get(\n STARS_API_ENDPOINTS.get_user_starred_packages,\n async (req: $RequestExtend, res: Response, next: $NextFunctionVer): Promise<void> => {\n const query: { key: string } = req.query;\n if (typeof query?.key !== 'string') {\n return next(errorUtils.getBadRequest('missing query key username'));\n }\n\n try {\n const localPackages: Version[] = await storage.getLocalDatabase();\n const filteredPackages: Version[] = localPackages.filter((localPackage: Version) =>\n keys(localPackage[USERS]).includes(query?.key.toString().replace(/['\"]+/g, ''))\n );\n\n res.status(HTTP_STATUS.OK);\n next({\n rows: filteredPackages.map((filteredPackage: Version) => ({\n value: filteredPackage.name,\n })),\n });\n } catch (err: any) {\n return next(err);\n }\n }\n );\n}\n"],"mappings":";;;;AAUA,SAAA,cAAyB,OAAe,SAAwB;CAC9D,MAAM,IACJ,oBAAoB,2BACpB,OAAO,KAAqB,KAAe,SAA0C;EACnF,MAAM,QAAyB,IAAI;EACnC,IAAI,OAAO,OAAO,QAAQ,UACxB,OAAO,KAAK,WAAW,cAAc,4BAA4B,CAAC;EAGpE,IAAI;GAEF,MAAM,oBAA8B,MADG,QAAQ,iBAAiB,GACd,QAAQ,iBACxD,KAAK,aAAa,MAAM,EAAE,SAAS,OAAO,IAAI,SAAS,EAAE,QAAQ,UAAU,EAAE,CAAC,CAChF;GAEA,IAAI,OAAO,YAAY,EAAE;GACzB,KAAK,EACH,MAAM,iBAAiB,KAAK,qBAA8B,EACxD,OAAO,gBAAgB,KACzB,EAAE,EACJ,CAAC;EACH,SAAS,KAAU;GACjB,OAAO,KAAK,GAAG;EACjB;CACF,CACF;AACF"}
|