verdaccio 7.0.0-next.6 → 7.0.1
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/LICENSE +1 -1
- package/README.md +259 -4
- package/bin/verdaccio +1 -1
- package/build/cjs/_virtual/_rolldown/runtime.cjs +23 -0
- package/build/cjs/index.cjs +33 -0
- package/build/cjs/lib/auth-utils.cjs +14 -0
- package/build/cjs/lib/auth-utils.cjs.map +1 -0
- package/build/cjs/lib/auth.cjs +10 -0
- package/build/cjs/lib/auth.cjs.map +1 -0
- package/build/cjs/lib/cli.cjs +16 -0
- package/build/cjs/lib/cli.cjs.map +1 -0
- package/build/cjs/lib/config.cjs +20 -0
- package/build/cjs/lib/config.cjs.map +1 -0
- package/build/cjs/lib/constants.cjs +76 -0
- package/build/cjs/lib/constants.cjs.map +1 -0
- package/build/cjs/lib/legacy-storage-adapter.cjs +214 -0
- package/build/cjs/lib/legacy-storage-adapter.cjs.map +1 -0
- package/build/cjs/lib/logger/index.cjs +26 -0
- package/build/cjs/lib/logger/index.cjs.map +1 -0
- package/build/cjs/lib/run-server.cjs +64 -0
- package/build/cjs/lib/run-server.cjs.map +1 -0
- package/build/cjs/lib/storage.cjs +103 -0
- package/build/cjs/lib/storage.cjs.map +1 -0
- package/build/cjs/lib/up-storage.cjs +29 -0
- package/build/cjs/lib/utils.cjs +24 -0
- package/build/cjs/lib/utils.cjs.map +1 -0
- package/build/cjs/types/index.cjs +1 -0
- package/build/esm/index.mjs +3 -0
- package/build/esm/lib/auth-utils.mjs +11 -0
- package/build/esm/lib/auth-utils.mjs.map +1 -0
- package/build/esm/lib/auth.mjs +7 -0
- package/build/esm/lib/auth.mjs.map +1 -0
- package/build/esm/lib/cli.mjs +15 -0
- package/build/esm/lib/cli.mjs.map +1 -0
- package/build/esm/lib/config.mjs +16 -0
- package/build/esm/lib/config.mjs.map +1 -0
- package/build/esm/lib/constants.mjs +11 -0
- package/build/esm/lib/constants.mjs.map +1 -0
- package/build/esm/lib/legacy-storage-adapter.mjs +210 -0
- package/build/esm/lib/legacy-storage-adapter.mjs.map +1 -0
- package/build/esm/lib/logger/index.mjs +17 -0
- package/build/esm/lib/logger/index.mjs.map +1 -0
- package/build/esm/lib/run-server.mjs +58 -0
- package/build/esm/lib/run-server.mjs.map +1 -0
- package/build/esm/lib/storage.mjs +94 -0
- package/build/esm/lib/storage.mjs.map +1 -0
- package/build/esm/lib/up-storage.mjs +1 -0
- package/build/esm/lib/utils.mjs +20 -0
- package/build/esm/lib/utils.mjs.map +1 -0
- package/build/index.d.ts +2 -2
- package/build/lib/auth-utils.d.ts +2 -0
- package/build/lib/auth.d.ts +2 -0
- package/build/lib/cli.d.ts +2 -0
- package/build/lib/config.d.ts +5 -0
- package/build/lib/constants.d.ts +16 -0
- package/build/lib/legacy-storage-adapter.d.ts +14 -0
- package/build/lib/logger/index.d.ts +6 -0
- package/build/lib/run-server.d.ts +35 -0
- package/build/lib/storage.d.ts +16 -0
- package/build/lib/up-storage.d.ts +2 -0
- package/build/lib/utils.d.ts +3 -0
- package/build/types/index.d.ts +58 -0
- package/conf/.gitkeep +0 -0
- package/cypress/e2e/01-home.cy.ts +11 -0
- package/cypress/e2e/02-signin.cy.ts +11 -0
- package/cypress/e2e/03-layout.cy.ts +11 -0
- package/cypress/e2e/04-search.cy.ts +33 -0
- package/cypress/e2e/05-settings.cy.ts +24 -0
- package/cypress/e2e/06-publish.cy.ts +16 -0
- package/cypress/e2e/07-detail.cy.ts +19 -0
- package/cypress/e2e/08-failure-modes.cy.ts +21 -0
- package/cypress/e2e/09-manifest-rendering.cy.ts +20 -0
- package/cypress/e2e/10-session.cy.ts +17 -0
- package/cypress/e2e/11-i18n-keys.cy.ts +17 -0
- package/cypress/e2e/12-signup.cy.ts +19 -0
- package/cypress/e2e/13-change-password.cy.ts +24 -0
- package/cypress/support/e2e.ts +1 -0
- package/cypress/support/node-builtins-stub.cjs +6 -0
- package/cypress.config.ts +86 -0
- package/index.js +1 -0
- package/package.json +120 -62
- package/pnpm-workspace.yaml +32 -0
- package/renovate.json +22 -0
- package/security.txt +5 -0
- package/systemd/verdaccio.service +11 -0
- package/types/custom.d.ts +13 -0
- package/vite.config.ts +101 -0
- package/build/index.js +0 -32
- package/build/index.js.map +0 -1
- package/build/server/index.d.ts +0 -2
- package/build/server/index.js +0 -32
- package/build/server/index.js.map +0 -1
- package/build/server/registry.d.ts +0 -39
- package/build/server/registry.js +0 -154
- package/build/server/registry.js.map +0 -1
- package/build/server/request.d.ts +0 -64
- package/build/server/request.js +0 -264
- package/build/server/request.js.map +0 -1
- package/build/start.js +0 -4
- package/build/start.js.map +0 -1
- /package/build/{start.d.ts → esm/types/index.mjs} +0 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import createDebug from "debug";
|
|
2
|
+
import { Writable } from "node:stream";
|
|
3
|
+
//#region src/lib/legacy-storage-adapter.ts
|
|
4
|
+
var debug = createDebug("verdaccio:storage:legacy-adapter");
|
|
5
|
+
/** Resolve an error-first callback method into a promise. */
|
|
6
|
+
function fromCallback(invoke) {
|
|
7
|
+
return new Promise((resolve, reject) => {
|
|
8
|
+
invoke((err, data) => err ? reject(err) : resolve(data));
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Detect a legacy callback-based storage plugin. The new contract's `get()`
|
|
13
|
+
* takes no arguments (returns a promise); the legacy `get(cb)` declares a
|
|
14
|
+
* trailing callback, and `add(name, cb)` takes two. Arity is a stable signal
|
|
15
|
+
* here because both contracts are frozen.
|
|
16
|
+
*/
|
|
17
|
+
function isLegacyStoragePlugin(plugin) {
|
|
18
|
+
if (!plugin || typeof plugin.get !== "function") return false;
|
|
19
|
+
const getIsCallback = plugin.get.length >= 1;
|
|
20
|
+
const addIsCallback = typeof plugin.add === "function" && plugin.add.length >= 2;
|
|
21
|
+
return getIsCallback || addIsCallback;
|
|
22
|
+
}
|
|
23
|
+
/** Synthesize the new `hasPackage()` from legacy `readPackage(name, cb)`. */
|
|
24
|
+
function hasPackage(handler, pkgName) {
|
|
25
|
+
return new Promise((resolve) => {
|
|
26
|
+
handler.readPackage(pkgName, (err) => resolve(!err));
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Synthesize the new `hasTarball(file)` from a legacy `readTarball` stream:
|
|
31
|
+
* open => exists, 404/ENOENT error => missing. Mirrors the old
|
|
32
|
+
* `Storage.hasLocalTarball` probe.
|
|
33
|
+
*/
|
|
34
|
+
function hasTarball(handler, fileName) {
|
|
35
|
+
return new Promise((resolve, reject) => {
|
|
36
|
+
let stream = handler.readTarball(fileName);
|
|
37
|
+
let isOpen = false;
|
|
38
|
+
stream.on("error", (err) => {
|
|
39
|
+
const notFound = err?.code === "ENOENT" || err?.status === 404;
|
|
40
|
+
if (isOpen || !notFound) {
|
|
41
|
+
if (!isOpen) resolve(false);
|
|
42
|
+
else reject(err);
|
|
43
|
+
} else resolve(false);
|
|
44
|
+
stream?.abort?.();
|
|
45
|
+
stream = null;
|
|
46
|
+
});
|
|
47
|
+
stream.on("open", () => {
|
|
48
|
+
isOpen = true;
|
|
49
|
+
stream.abort?.();
|
|
50
|
+
stream = null;
|
|
51
|
+
resolve(true);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Bridge legacy `readTarball(name) => ReadTarball` to the promise contract.
|
|
57
|
+
* The legacy object is already a Readable that emits `content-length`/`open`/
|
|
58
|
+
* `error`, so it can be handed back as-is; we only wire abort to the signal.
|
|
59
|
+
*/
|
|
60
|
+
function readTarball(handler, fileName, options = {}) {
|
|
61
|
+
const stream = handler.readTarball(fileName);
|
|
62
|
+
const { signal } = options;
|
|
63
|
+
if (signal) {
|
|
64
|
+
if (signal.aborted) stream.abort?.();
|
|
65
|
+
else signal.addEventListener("abort", () => stream.abort?.(), { once: true });
|
|
66
|
+
}
|
|
67
|
+
return Promise.resolve(stream);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Bridge legacy `writeTarball(name) => UploadTarball` to a Node Writable that
|
|
71
|
+
* `@verdaccio/store` can use in `pipeline()`:
|
|
72
|
+
* - the legacy stream finalizes only when `.done()` is called (ends temp file,
|
|
73
|
+
* renames it into place, then emits `success`); store instead ends the
|
|
74
|
+
* stream and waits for `close`.
|
|
75
|
+
* - so we forward writes to the legacy stream, call `.done()` on `_final`, and
|
|
76
|
+
* only complete (emit `close`) once the legacy stream emits `success`.
|
|
77
|
+
*/
|
|
78
|
+
function writeTarball(handler, fileName, options = {}) {
|
|
79
|
+
const upload = handler.writeTarball(fileName);
|
|
80
|
+
const { signal } = options;
|
|
81
|
+
const bridge = new Writable({
|
|
82
|
+
write(chunk, _enc, cb) {
|
|
83
|
+
if (upload.write(chunk)) cb();
|
|
84
|
+
else upload.once("drain", cb);
|
|
85
|
+
},
|
|
86
|
+
final(cb) {
|
|
87
|
+
upload.once("success", () => cb());
|
|
88
|
+
upload.once("error", (err) => cb(err));
|
|
89
|
+
upload.end();
|
|
90
|
+
upload.done();
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
upload.on("open", () => bridge.emit("open"));
|
|
94
|
+
upload.on("error", (err) => bridge.destroy(err));
|
|
95
|
+
if (signal) {
|
|
96
|
+
const onAbort = () => {
|
|
97
|
+
upload.abort?.();
|
|
98
|
+
bridge.destroy(/* @__PURE__ */ new Error("tarball upload aborted"));
|
|
99
|
+
};
|
|
100
|
+
if (signal.aborted) onAbort();
|
|
101
|
+
else signal.addEventListener("abort", onAbort, { once: true });
|
|
102
|
+
}
|
|
103
|
+
return Promise.resolve(bridge);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Bridge legacy 5-arg `updatePackage(name, updateHandler, onWrite,
|
|
107
|
+
* transformPackage, onEnd)` to the new 2-arg `updatePackage(name, handleUpdate)`
|
|
108
|
+
* where `handleUpdate(manifest) => Promise<manifest>`. The store persists the
|
|
109
|
+
* result itself (via `writePackage`/`savePackage`), so `onWrite` is a no-op:
|
|
110
|
+
* we only read-lock, run the handler, and unlock.
|
|
111
|
+
*/
|
|
112
|
+
function updatePackage(handler, name, handleUpdate) {
|
|
113
|
+
return new Promise((resolve, reject) => {
|
|
114
|
+
let updated;
|
|
115
|
+
handler.updatePackage(name, (json, cb) => {
|
|
116
|
+
Promise.resolve(handleUpdate(json)).then((result) => {
|
|
117
|
+
updated = result;
|
|
118
|
+
cb();
|
|
119
|
+
}).catch(cb);
|
|
120
|
+
}, (_name, _data, cb) => cb(), (json) => updated ?? json, (err) => err ? reject(err) : resolve(updated));
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
/** Wrap a legacy per-package storage handler in the promise contract. */
|
|
124
|
+
function wrapLegacyHandler(handler) {
|
|
125
|
+
if (!handler) return handler;
|
|
126
|
+
return {
|
|
127
|
+
readPackage: (name) => fromCallback((cb) => handler.readPackage(name, cb)),
|
|
128
|
+
createPackage: (name, manifest) => fromCallback((cb) => handler.createPackage(name, manifest, cb)),
|
|
129
|
+
savePackage: (name, value) => fromCallback((cb) => handler.savePackage(name, value, cb)),
|
|
130
|
+
deletePackage: (fileName) => fromCallback((cb) => handler.deletePackage(fileName, cb)),
|
|
131
|
+
removePackage: () => fromCallback((cb) => handler.removePackage(cb)),
|
|
132
|
+
hasPackage: (name) => hasPackage(handler, name),
|
|
133
|
+
hasTarball: (fileName) => hasTarball(handler, fileName),
|
|
134
|
+
readTarball: (fileName, options) => readTarball(handler, fileName, options),
|
|
135
|
+
writeTarball: (fileName, options) => writeTarball(handler, fileName, options),
|
|
136
|
+
updatePackage: (name, handleUpdate) => updatePackage(handler, name, handleUpdate)
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* The legacy contract emits the package itself, while `@verdaccio/store` reads
|
|
141
|
+
* `item.package.name` and `item.score`. Wrap whatever is not already in that shape,
|
|
142
|
+
* otherwise a plugin following the documented contract makes `/-/v1/search` fail.
|
|
143
|
+
*/
|
|
144
|
+
function toSearchItem(item) {
|
|
145
|
+
if (item !== null && typeof item === "object" && "package" in item) return item;
|
|
146
|
+
return {
|
|
147
|
+
package: item,
|
|
148
|
+
score: {
|
|
149
|
+
final: 1,
|
|
150
|
+
detail: {
|
|
151
|
+
quality: 1,
|
|
152
|
+
popularity: 1,
|
|
153
|
+
maintenance: 1
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Collect a legacy streaming `search(onPackage, onEnd, validate)` into a list.
|
|
160
|
+
*
|
|
161
|
+
* A legacy plugin has no way to receive the query, so the filtering happens here, on
|
|
162
|
+
* the emitted name. The predicate stays permissive on purpose: a plugin calls it with
|
|
163
|
+
* the basename (`pkg` for `@scope/pkg`), so any rejection there could drop a package
|
|
164
|
+
* whose full name does match.
|
|
165
|
+
*/
|
|
166
|
+
function search(plugin, query) {
|
|
167
|
+
const text = typeof query?.text === "string" ? query.text.toLowerCase() : void 0;
|
|
168
|
+
const matches = (name) => text === void 0 || typeof name === "string" && name.toLowerCase().includes(text);
|
|
169
|
+
return new Promise((resolve, reject) => {
|
|
170
|
+
const items = [];
|
|
171
|
+
try {
|
|
172
|
+
plugin.search((item, done) => {
|
|
173
|
+
const searchItem = toSearchItem(item);
|
|
174
|
+
if (matches(searchItem?.package?.name)) items.push(searchItem);
|
|
175
|
+
done();
|
|
176
|
+
}, (err) => err ? reject(err) : resolve(items), () => true);
|
|
177
|
+
} catch (err) {
|
|
178
|
+
reject(err);
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Wrap a legacy callback storage plugin in the promise contract expected by
|
|
184
|
+
* `@verdaccio/store`. Token methods are exposed only when the legacy plugin
|
|
185
|
+
* implements them (store already guards their absence with SERVICE_UNAVAILABLE).
|
|
186
|
+
*/
|
|
187
|
+
function wrapLegacyStoragePlugin(plugin, logger) {
|
|
188
|
+
debug("wrapping legacy callback storage plugin");
|
|
189
|
+
logger.warn("a legacy callback-based storage plugin was detected and wrapped for compatibility; consider upgrading it to the promise-based storage API");
|
|
190
|
+
const wrapped = {
|
|
191
|
+
init: () => typeof plugin.init === "function" ? Promise.resolve(plugin.init()) : Promise.resolve(void 0),
|
|
192
|
+
getSecret: () => Promise.resolve(plugin.getSecret()),
|
|
193
|
+
setSecret: (secret) => Promise.resolve(plugin.setSecret(secret)),
|
|
194
|
+
get: () => fromCallback((cb) => plugin.get(cb)),
|
|
195
|
+
add: (name) => fromCallback((cb) => plugin.add(name, cb)),
|
|
196
|
+
remove: (name) => fromCallback((cb) => plugin.remove(name, cb)),
|
|
197
|
+
search: (query) => search(plugin, query),
|
|
198
|
+
getPackageStorage: (packageName) => wrapLegacyHandler(plugin.getPackageStorage(packageName))
|
|
199
|
+
};
|
|
200
|
+
for (const tokenMethod of [
|
|
201
|
+
"saveToken",
|
|
202
|
+
"deleteToken",
|
|
203
|
+
"readTokens"
|
|
204
|
+
]) if (typeof plugin[tokenMethod] === "function") wrapped[tokenMethod] = (...args) => Promise.resolve(plugin[tokenMethod](...args));
|
|
205
|
+
return Object.assign(Object.create(plugin), wrapped);
|
|
206
|
+
}
|
|
207
|
+
//#endregion
|
|
208
|
+
export { isLegacyStoragePlugin, wrapLegacyStoragePlugin };
|
|
209
|
+
|
|
210
|
+
//# sourceMappingURL=legacy-storage-adapter.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"legacy-storage-adapter.mjs","names":["buildDebug"],"sources":["../../../src/lib/legacy-storage-adapter.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { Writable } from 'node:stream';\n\nimport { Logger } from '@verdaccio/types';\n\nconst debug = buildDebug('verdaccio:storage:legacy-adapter');\n\n/**\n * Compatibility shim that lets a LEGACY callback/stream based storage plugin\n * (the `@verdaccio/local-storage-legacy` contract used by Verdaccio < 8 and by\n * many third-party plugins) be driven by the promise-based `@verdaccio/store`.\n *\n * `@verdaccio/store` awaits every storage method:\n * await plugin.get() / add(name) / remove(name) / search(query)\n * const h = plugin.getPackageStorage(name)\n * await h.readPackage(name) / savePackage(name, v) / createPackage(...) /\n * deletePackage(file) / removePackage() / hasPackage() /\n * hasTarball(file) / writeTarball(file, {signal}) /\n * readTarball(file, {signal}) / updatePackage(name, handleUpdate)\n *\n * The legacy contract is callback/stream based instead, so we promisify it.\n * New (promise) plugins are detected and returned untouched — zero overhead on\n * the default path.\n */\n\ntype AnyFn = (...args: any[]) => any;\n\n/** Resolve an error-first callback method into a promise. */\nfunction fromCallback<T = any>(invoke: (cb: (err: any, data?: T) => void) => void): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n invoke((err, data) => (err ? reject(err) : resolve(data as T)));\n });\n}\n\n/**\n * Detect a legacy callback-based storage plugin. The new contract's `get()`\n * takes no arguments (returns a promise); the legacy `get(cb)` declares a\n * trailing callback, and `add(name, cb)` takes two. Arity is a stable signal\n * here because both contracts are frozen.\n */\nexport function isLegacyStoragePlugin(plugin: any): boolean {\n if (!plugin || typeof plugin.get !== 'function') {\n return false;\n }\n const getIsCallback = plugin.get.length >= 1;\n const addIsCallback = typeof plugin.add === 'function' && plugin.add.length >= 2;\n return getIsCallback || addIsCallback;\n}\n\n/** Synthesize the new `hasPackage()` from legacy `readPackage(name, cb)`. */\nfunction hasPackage(handler: any, pkgName: string): Promise<boolean> {\n return new Promise((resolve) => {\n handler.readPackage(pkgName, (err: any) => resolve(!err));\n });\n}\n\n/**\n * Synthesize the new `hasTarball(file)` from a legacy `readTarball` stream:\n * open => exists, 404/ENOENT error => missing. Mirrors the old\n * `Storage.hasLocalTarball` probe.\n */\nfunction hasTarball(handler: any, fileName: string): Promise<boolean> {\n return new Promise((resolve, reject) => {\n let stream: any = handler.readTarball(fileName);\n let isOpen = false;\n stream.on('error', (err: any) => {\n const notFound = err?.code === 'ENOENT' || err?.status === 404;\n if (isOpen || !notFound) {\n // a real read error after the file was already opened\n if (!isOpen) {\n resolve(false);\n } else {\n reject(err);\n }\n } else {\n resolve(false);\n }\n stream?.abort?.();\n stream = null;\n });\n stream.on('open', () => {\n isOpen = true;\n stream.abort?.();\n stream = null;\n resolve(true);\n });\n });\n}\n\n/**\n * Bridge legacy `readTarball(name) => ReadTarball` to the promise contract.\n * The legacy object is already a Readable that emits `content-length`/`open`/\n * `error`, so it can be handed back as-is; we only wire abort to the signal.\n */\nfunction readTarball(handler: any, fileName: string, options: { signal?: AbortSignal } = {}) {\n const stream = handler.readTarball(fileName);\n const { signal } = options;\n if (signal) {\n if (signal.aborted) {\n stream.abort?.();\n } else {\n signal.addEventListener('abort', () => stream.abort?.(), { once: true });\n }\n }\n return Promise.resolve(stream);\n}\n\n/**\n * Bridge legacy `writeTarball(name) => UploadTarball` to a Node Writable that\n * `@verdaccio/store` can use in `pipeline()`:\n * - the legacy stream finalizes only when `.done()` is called (ends temp file,\n * renames it into place, then emits `success`); store instead ends the\n * stream and waits for `close`.\n * - so we forward writes to the legacy stream, call `.done()` on `_final`, and\n * only complete (emit `close`) once the legacy stream emits `success`.\n */\nfunction writeTarball(handler: any, fileName: string, options: { signal?: AbortSignal } = {}) {\n const upload = handler.writeTarball(fileName);\n const { signal } = options;\n\n const bridge = new Writable({\n write(chunk, _enc, cb): void {\n if (upload.write(chunk)) {\n cb();\n } else {\n upload.once('drain', cb);\n }\n },\n final(cb): void {\n upload.once('success', () => cb());\n upload.once('error', (err: any) => cb(err));\n // `done()` waits for the legacy stream's `end`, so end it first.\n upload.end();\n upload.done();\n },\n });\n\n upload.on('open', () => bridge.emit('open'));\n upload.on('error', (err: any) => bridge.destroy(err));\n\n if (signal) {\n const onAbort = (): void => {\n upload.abort?.();\n bridge.destroy(new Error('tarball upload aborted'));\n };\n if (signal.aborted) {\n onAbort();\n } else {\n signal.addEventListener('abort', onAbort, { once: true });\n }\n }\n return Promise.resolve(bridge);\n}\n\n/**\n * Bridge legacy 5-arg `updatePackage(name, updateHandler, onWrite,\n * transformPackage, onEnd)` to the new 2-arg `updatePackage(name, handleUpdate)`\n * where `handleUpdate(manifest) => Promise<manifest>`. The store persists the\n * result itself (via `writePackage`/`savePackage`), so `onWrite` is a no-op:\n * we only read-lock, run the handler, and unlock.\n */\nfunction updatePackage(handler: any, name: string, handleUpdate: AnyFn): Promise<any> {\n return new Promise((resolve, reject) => {\n let updated: any;\n handler.updatePackage(\n name,\n // updateHandler(json, cb): run the promise handler, capture the result\n (json: any, cb: (err?: any) => void) => {\n Promise.resolve(handleUpdate(json))\n .then((result) => {\n updated = result;\n cb();\n })\n .catch(cb);\n },\n // onWrite(name, data, cb): store persists separately, so just unlock\n (_name: string, _data: any, cb: (err?: any) => void) => cb(),\n // transformPackage(json): return the updated manifest\n (json: any) => updated ?? json,\n // onEnd(err)\n (err: any) => (err ? reject(err) : resolve(updated))\n );\n });\n}\n\n/** Wrap a legacy per-package storage handler in the promise contract. */\nfunction wrapLegacyHandler(handler: any): any {\n if (!handler) {\n return handler;\n }\n return {\n readPackage: (name: string) => fromCallback((cb) => handler.readPackage(name, cb)),\n createPackage: (name: string, manifest: any) =>\n fromCallback((cb) => handler.createPackage(name, manifest, cb)),\n savePackage: (name: string, value: any) =>\n fromCallback((cb) => handler.savePackage(name, value, cb)),\n deletePackage: (fileName: string) => fromCallback((cb) => handler.deletePackage(fileName, cb)),\n removePackage: () => fromCallback((cb) => handler.removePackage(cb)),\n hasPackage: (name?: string) => hasPackage(handler, name as string),\n hasTarball: (fileName: string) => hasTarball(handler, fileName),\n readTarball: (fileName: string, options?: { signal?: AbortSignal }) =>\n readTarball(handler, fileName, options),\n writeTarball: (fileName: string, options?: { signal?: AbortSignal }) =>\n writeTarball(handler, fileName, options),\n updatePackage: (name: string, handleUpdate: AnyFn) =>\n updatePackage(handler, name, handleUpdate),\n };\n}\n\n/**\n * The legacy contract emits the package itself, while `@verdaccio/store` reads\n * `item.package.name` and `item.score`. Wrap whatever is not already in that shape,\n * otherwise a plugin following the documented contract makes `/-/v1/search` fail.\n */\nfunction toSearchItem(item: any): any {\n if (item !== null && typeof item === 'object' && 'package' in item) {\n return item;\n }\n\n return {\n package: item,\n score: { final: 1, detail: { quality: 1, popularity: 1, maintenance: 1 } },\n };\n}\n\n/**\n * Collect a legacy streaming `search(onPackage, onEnd, validate)` into a list.\n *\n * A legacy plugin has no way to receive the query, so the filtering happens here, on\n * the emitted name. The predicate stays permissive on purpose: a plugin calls it with\n * the basename (`pkg` for `@scope/pkg`), so any rejection there could drop a package\n * whose full name does match.\n */\nfunction search(plugin: any, query: any): Promise<any[]> {\n const text = typeof query?.text === 'string' ? query.text.toLowerCase() : undefined;\n const matches = (name: unknown): boolean =>\n text === undefined || (typeof name === 'string' && name.toLowerCase().includes(text));\n\n return new Promise((resolve, reject) => {\n const items: any[] = [];\n try {\n plugin.search(\n (item: any, done: () => void) => {\n const searchItem = toSearchItem(item);\n if (matches(searchItem?.package?.name)) {\n items.push(searchItem);\n }\n done();\n },\n (err: any) => (err ? reject(err) : resolve(items)),\n () => true\n );\n } catch (err) {\n reject(err);\n }\n });\n}\n\n/**\n * Wrap a legacy callback storage plugin in the promise contract expected by\n * `@verdaccio/store`. Token methods are exposed only when the legacy plugin\n * implements them (store already guards their absence with SERVICE_UNAVAILABLE).\n */\nexport function wrapLegacyStoragePlugin(plugin: any, logger: Logger): any {\n debug('wrapping legacy callback storage plugin');\n logger.warn(\n 'a legacy callback-based storage plugin was detected and wrapped for compatibility; ' +\n 'consider upgrading it to the promise-based storage API'\n );\n\n const wrapped: Record<string, AnyFn> = {\n init: () =>\n typeof plugin.init === 'function'\n ? Promise.resolve(plugin.init())\n : Promise.resolve(undefined),\n getSecret: () => Promise.resolve(plugin.getSecret()),\n setSecret: (secret: string) => Promise.resolve(plugin.setSecret(secret)),\n get: () => fromCallback((cb) => plugin.get(cb)),\n add: (name: string) => fromCallback((cb) => plugin.add(name, cb)),\n remove: (name: string) => fromCallback((cb) => plugin.remove(name, cb)),\n search: (query: any) => search(plugin, query),\n getPackageStorage: (packageName: string) =>\n wrapLegacyHandler(plugin.getPackageStorage(packageName)),\n };\n\n for (const tokenMethod of ['saveToken', 'deleteToken', 'readTokens'] as const) {\n if (typeof plugin[tokenMethod] === 'function') {\n wrapped[tokenMethod] = (...args: any[]) => Promise.resolve(plugin[tokenMethod](...args));\n }\n }\n\n // preserve any extra plugin surface (e.g. logger, config) by prototype-less merge\n return Object.assign(Object.create(plugin), wrapped);\n}\n"],"mappings":";;;AAKA,IAAM,QAAQA,YAAW,kCAAkC;;AAuB3D,SAAS,aAAsB,QAAgE;CAC7F,OAAO,IAAI,SAAY,SAAS,WAAW;EACzC,QAAQ,KAAK,SAAU,MAAM,OAAO,GAAG,IAAI,QAAQ,IAAS,CAAE;CAChE,CAAC;AACH;;;;;;;AAQA,SAAgB,sBAAsB,QAAsB;CAC1D,IAAI,CAAC,UAAU,OAAO,OAAO,QAAQ,YACnC,OAAO;CAET,MAAM,gBAAgB,OAAO,IAAI,UAAU;CAC3C,MAAM,gBAAgB,OAAO,OAAO,QAAQ,cAAc,OAAO,IAAI,UAAU;CAC/E,OAAO,iBAAiB;AAC1B;;AAGA,SAAS,WAAW,SAAc,SAAmC;CACnE,OAAO,IAAI,SAAS,YAAY;EAC9B,QAAQ,YAAY,UAAU,QAAa,QAAQ,CAAC,GAAG,CAAC;CAC1D,CAAC;AACH;;;;;;AAOA,SAAS,WAAW,SAAc,UAAoC;CACpE,OAAO,IAAI,SAAS,SAAS,WAAW;EACtC,IAAI,SAAc,QAAQ,YAAY,QAAQ;EAC9C,IAAI,SAAS;EACb,OAAO,GAAG,UAAU,QAAa;GAC/B,MAAM,WAAW,KAAK,SAAS,YAAY,KAAK,WAAW;GAC3D,IAAI,UAAU,CAAC,UAAU;IAEvB,IAAI,CAAC,QACH,QAAQ,KAAK;SAEb,OAAO,GAAG;GAEd,OACE,QAAQ,KAAK;GAEf,QAAQ,QAAQ;GAChB,SAAS;EACX,CAAC;EACD,OAAO,GAAG,cAAc;GACtB,SAAS;GACT,OAAO,QAAQ;GACf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rD"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import createDebug from "debug";
|
|
2
|
+
import { setup as setup$1 } from "@verdaccio/logger";
|
|
3
|
+
//#region src/lib/logger/index.ts
|
|
4
|
+
var logger;
|
|
5
|
+
var debug = createDebug("verdaccio:logger");
|
|
6
|
+
async function setup(options) {
|
|
7
|
+
debug("setup logger with options %o", options);
|
|
8
|
+
if (!logger) {
|
|
9
|
+
debug("logger not initialized, setting up");
|
|
10
|
+
logger = await setup$1(options);
|
|
11
|
+
debug("logger initialized");
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { logger, setup };
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["setupModule"],"sources":["../../../../src/lib/logger/index.ts"],"sourcesContent":["import createDebug from 'debug';\n\nimport { setup as setupModule } from '@verdaccio/logger';\nimport { Logger } from '@verdaccio/types';\n\nlet logger: Logger;\n\nconst debug = createDebug('verdaccio:logger');\n\ntype SetupModuleOptions = Parameters<typeof setupModule>[0];\n\nexport async function setup(options: SetupModuleOptions): Promise<void> {\n debug('setup logger with options %o', options);\n if (!logger) {\n debug('logger not initialized, setting up');\n logger = await setupModule(options);\n debug('logger initialized');\n }\n}\n\nexport { logger };\n"],"mappings":";;;AAKA,IAAI;AAEJ,IAAM,QAAQ,YAAY,kBAAkB;AAI5C,eAAsB,MAAM,SAA4C;CACtE,MAAM,gCAAgC,OAAO;CAC7C,IAAI,CAAC,QAAQ;EACX,MAAM,oCAAoC;EAC1C,SAAS,MAAMA,QAAY,OAAO;EAClC,MAAM,oBAAoB;CAC5B;AACF"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import Config from "./config.mjs";
|
|
2
|
+
import { logger } from "./logger/index.mjs";
|
|
3
|
+
import { Storage } from "./storage.mjs";
|
|
4
|
+
import { getPackageVersion, initLogger } from "./utils.mjs";
|
|
5
|
+
import * as _ from "lodash-es";
|
|
6
|
+
import { initServer as initServer$1, runServer as runServer$1 } from "@verdaccio/node-api";
|
|
7
|
+
import { defineAPI } from "@verdaccio/server";
|
|
8
|
+
//#region src/lib/run-server.ts
|
|
9
|
+
/**
|
|
10
|
+
* Build the Express app from a raw config by reusing @verdaccio/server's
|
|
11
|
+
* composition (defineAPI), but inject 7.x's Storage so legacy callback storage
|
|
12
|
+
* plugins keep working. Exposed for tests that need the app without a listener.
|
|
13
|
+
*/
|
|
14
|
+
async function endPointAPI(configHash) {
|
|
15
|
+
const appConfig = new Config(_.cloneDeep(configHash));
|
|
16
|
+
const storage = new Storage(appConfig, logger);
|
|
17
|
+
await storage.init(appConfig);
|
|
18
|
+
return defineAPI(appConfig, storage, { version: getPackageVersion() });
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Server factory passed to @verdaccio/node-api / @verdaccio/cli: maps the
|
|
22
|
+
* deprecated `logs` config key then builds the app with 7.x's legacy-aware
|
|
23
|
+
* Storage (via {@link endPointAPI}).
|
|
24
|
+
*/
|
|
25
|
+
async function startServer(config) {
|
|
26
|
+
await initLogger(config);
|
|
27
|
+
return endPointAPI(config);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Exposes a server factory to be instantiated programmatically.
|
|
31
|
+
*
|
|
32
|
+
```ts
|
|
33
|
+
const app = await runServer(); // default configuration
|
|
34
|
+
const app = await runServer('./config/config.yaml');
|
|
35
|
+
const app = await runServer({ configuration });
|
|
36
|
+
app.listen(4000, (event) => {
|
|
37
|
+
// do something
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
* @param config
|
|
41
|
+
*/
|
|
42
|
+
async function runServer(config) {
|
|
43
|
+
return runServer$1(config, startServer);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Start the server on the port defined (or the port defined in the config file)
|
|
47
|
+
* @param config
|
|
48
|
+
* @param port
|
|
49
|
+
* @param version
|
|
50
|
+
* @param pkgName
|
|
51
|
+
*/
|
|
52
|
+
async function initServer(config, port, version, pkgName) {
|
|
53
|
+
return initServer$1(config, port, version, pkgName, startServer);
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
export { endPointAPI, initServer, runServer, startServer };
|
|
57
|
+
|
|
58
|
+
//# sourceMappingURL=run-server.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-server.mjs","names":["AppConfig","runServerNode","initServerNode"],"sources":["../../../src/lib/run-server.ts"],"sourcesContent":["import * as _ from 'lodash-es';\n\nimport { initServer as initServerNode, runServer as runServerNode } from '@verdaccio/node-api';\nimport { defineAPI } from '@verdaccio/server';\nimport { ConfigYaml, Config as IConfig } from '@verdaccio/types';\n\nimport AppConfig from './config';\nimport { logger } from './logger';\nimport Storage from './storage';\nimport { getPackageVersion, initLogger } from './utils';\n\n/**\n * Build the Express app from a raw config by reusing @verdaccio/server's\n * composition (defineAPI), but inject 7.x's Storage so legacy callback storage\n * plugins keep working. Exposed for tests that need the app without a listener.\n */\nexport async function endPointAPI(configHash: ConfigYaml): Promise<any> {\n const appConfig: IConfig = new AppConfig(_.cloneDeep(configHash));\n const storage = new Storage(appConfig, logger);\n await storage.init(appConfig);\n return defineAPI(appConfig, storage as any, { version: getPackageVersion() });\n}\n\n/**\n * Server factory passed to @verdaccio/node-api / @verdaccio/cli: maps the\n * deprecated `logs` config key then builds the app with 7.x's legacy-aware\n * Storage (via {@link endPointAPI}).\n */\nexport async function startServer(config: ConfigYaml): Promise<any> {\n await initLogger(config);\n return endPointAPI(config);\n}\n\n/**\n * Exposes a server factory to be instantiated programmatically.\n *\n ```ts\n const app = await runServer(); // default configuration\n const app = await runServer('./config/config.yaml');\n const app = await runServer({ configuration });\n app.listen(4000, (event) => {\n // do something\n });\n ```\n * @param config\n */\nexport async function runServer(config?: string | ConfigYaml): Promise<any> {\n return runServerNode(config, startServer);\n}\n\n/**\n * Start the server on the port defined (or the port defined in the config file)\n * @param config\n * @param port\n * @param version\n * @param pkgName\n */\nexport async function initServer(\n config: ConfigYaml,\n port: string | void,\n version: string,\n pkgName: string\n): Promise<void> {\n return initServerNode(config, port, version, pkgName, startServer);\n}\n"],"mappings":";;;;;;;;;;;;;AAgBA,eAAsB,YAAY,YAAsC;CACtE,MAAM,YAAqB,IAAIA,OAAU,EAAE,UAAU,UAAU,CAAC;CAChE,MAAM,UAAU,IAAI,QAAQ,WAAW,MAAM;CAC7C,MAAM,QAAQ,KAAK,SAAS;CAC5B,OAAO,UAAU,WAAW,SAAgB,EAAE,SAAS,kBAAkB,EAAE,CAAC;AAC9E;;;;;;AAOA,eAAsB,YAAY,QAAkC;CAClE,MAAM,WAAW,MAAM;CACvB,OAAO,YAAY,MAAM;AAC3B;;;;;;;;;;;;;;AAeA,eAAsB,UAAU,QAA4C;CAC1E,OAAOC,YAAc,QAAQ,WAAW;AAC1C;;;;;;;;AASA,eAAsB,WACpB,QACA,MACA,SACA,SACe;CACf,OAAOC,aAAe,QAAQ,MAAM,SAAS,SAAS,WAAW;AACnE"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { isLegacyStoragePlugin, wrapLegacyStoragePlugin } from "./legacy-storage-adapter.mjs";
|
|
2
|
+
import { head, isNil } from "lodash-es";
|
|
3
|
+
import { PLUGIN_CATEGORY, PLUGIN_PREFIX, errorUtils } from "@verdaccio/core";
|
|
4
|
+
import createDebug from "debug";
|
|
5
|
+
import assert from "node:assert";
|
|
6
|
+
import { asyncLoadPlugin } from "@verdaccio/loaders";
|
|
7
|
+
import LocalDatabaseModule from "@verdaccio/local-storage";
|
|
8
|
+
import { Storage as Storage$1 } from "@verdaccio/store";
|
|
9
|
+
//#region src/lib/storage.ts
|
|
10
|
+
var debug = createDebug("verdaccio:storage");
|
|
11
|
+
var LocalDatabase = LocalDatabaseModule.default || LocalDatabaseModule;
|
|
12
|
+
var storageSanityCheck = (plugin) => typeof plugin?.getPackageStorage !== "undefined";
|
|
13
|
+
/**
|
|
14
|
+
* Drop-in replacement for `@verdaccio/store`'s internal `LocalStorage` that
|
|
15
|
+
* loads the configured storage plugin exactly like upstream, but wraps a
|
|
16
|
+
* legacy callback-based plugin in a promisifying adapter so it satisfies the
|
|
17
|
+
* promise contract the rest of `@verdaccio/store` relies on.
|
|
18
|
+
*
|
|
19
|
+
* `@verdaccio/store` only ever calls `init()`, `getSecret()` and
|
|
20
|
+
* `getStoragePlugin()` on this object, so that is the entire surface we mirror.
|
|
21
|
+
*/
|
|
22
|
+
var CompatLocalStorage = class {
|
|
23
|
+
storagePlugin = null;
|
|
24
|
+
config;
|
|
25
|
+
logger;
|
|
26
|
+
constructor(config, logger) {
|
|
27
|
+
this.config = config;
|
|
28
|
+
this.logger = logger.child({ sub: "fs" });
|
|
29
|
+
}
|
|
30
|
+
async init() {
|
|
31
|
+
if (this.storagePlugin === null) {
|
|
32
|
+
const loaded = await this.loadStorage();
|
|
33
|
+
this.storagePlugin = isLegacyStoragePlugin(loaded) ? wrapLegacyStoragePlugin(loaded, this.logger) : loaded;
|
|
34
|
+
debug("storage plugin init");
|
|
35
|
+
await this.storagePlugin.init();
|
|
36
|
+
debug("storage plugin initialized");
|
|
37
|
+
} else this.logger.warn("storage plugin has been already initialized");
|
|
38
|
+
}
|
|
39
|
+
getStoragePlugin() {
|
|
40
|
+
if (this.storagePlugin === null) throw errorUtils.getInternalError("storage plugin is not initialized");
|
|
41
|
+
return this.storagePlugin;
|
|
42
|
+
}
|
|
43
|
+
async getSecret(config) {
|
|
44
|
+
const secretKey = await this.storagePlugin.getSecret();
|
|
45
|
+
return this.storagePlugin.setSecret(config.checkSecretKey(secretKey));
|
|
46
|
+
}
|
|
47
|
+
async loadStorage() {
|
|
48
|
+
const Storage = await this.loadStorePlugin();
|
|
49
|
+
if (isNil(Storage)) {
|
|
50
|
+
assert(this.config.storage, "CONFIG: storage path not defined");
|
|
51
|
+
debug("no custom storage found, loading default storage @verdaccio/local-storage");
|
|
52
|
+
const localStorage = new LocalDatabase(this.config, this.logger);
|
|
53
|
+
this.logger.info({
|
|
54
|
+
name: "@verdaccio/local-storage",
|
|
55
|
+
pluginCategory: PLUGIN_CATEGORY.STORAGE
|
|
56
|
+
}, "plugin @{name} successfully loaded (@{pluginCategory})");
|
|
57
|
+
return localStorage;
|
|
58
|
+
}
|
|
59
|
+
return Storage;
|
|
60
|
+
}
|
|
61
|
+
async loadStorePlugin() {
|
|
62
|
+
const plugins = await asyncLoadPlugin(this.config.store, {
|
|
63
|
+
config: this.config,
|
|
64
|
+
logger: this.logger
|
|
65
|
+
}, storageSanityCheck, true, this.config.server?.pluginPrefix ?? PLUGIN_PREFIX, PLUGIN_CATEGORY.STORAGE);
|
|
66
|
+
if (plugins.length > 1) this.logger.warn("more than one storage plugins has been detected, multiple storage are not supported, one will be selected automatically");
|
|
67
|
+
return head(plugins);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* `@verdaccio/store` Storage, with one change: it loads the storage plugin
|
|
72
|
+
* through {@link CompatLocalStorage} so legacy callback plugins keep working.
|
|
73
|
+
*
|
|
74
|
+
* The base `init()` only creates its internal `LocalStorage` when
|
|
75
|
+
* `this.localStorage` is still null; by pre-populating it we reuse the entire
|
|
76
|
+
* rest of the upstream Storage implementation (including filter loading via
|
|
77
|
+
* `super.init`) unchanged.
|
|
78
|
+
*/
|
|
79
|
+
var Storage = class extends Storage$1 {
|
|
80
|
+
async init(config) {
|
|
81
|
+
if (this.localStorage === null) {
|
|
82
|
+
const localStorage = new CompatLocalStorage(this.config, this.logger);
|
|
83
|
+
await localStorage.init();
|
|
84
|
+
await localStorage.getSecret(config);
|
|
85
|
+
this.localStorage = localStorage;
|
|
86
|
+
debug("compat local storage initialized");
|
|
87
|
+
}
|
|
88
|
+
await super.init(config);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
//#endregion
|
|
92
|
+
export { Storage, Storage as default };
|
|
93
|
+
|
|
94
|
+
//# sourceMappingURL=storage.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.mjs","names":["buildDebug","BaseStorage"],"sources":["../../../src/lib/storage.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { head, isNil } from 'lodash-es';\nimport assert from 'node:assert';\n\nimport { PLUGIN_CATEGORY, PLUGIN_PREFIX, errorUtils } from '@verdaccio/core';\nimport { asyncLoadPlugin } from '@verdaccio/loaders';\nimport LocalDatabaseModule from '@verdaccio/local-storage';\nimport { Storage as BaseStorage } from '@verdaccio/store';\nimport { Config, Logger } from '@verdaccio/types';\n\nimport { isLegacyStoragePlugin, wrapLegacyStoragePlugin } from './legacy-storage-adapter';\n\nconst debug = buildDebug('verdaccio:storage');\n\n// CJS/ESM interop for the default storage plugin\nconst LocalDatabase = (LocalDatabaseModule as any).default || LocalDatabaseModule;\n\n// `storageSanityCheck` only verifies `getPackageStorage` exists, which both the\n// legacy and promise contracts satisfy.\nconst storageSanityCheck = (plugin: any): boolean =>\n typeof plugin?.getPackageStorage !== 'undefined';\n\n/**\n * Drop-in replacement for `@verdaccio/store`'s internal `LocalStorage` that\n * loads the configured storage plugin exactly like upstream, but wraps a\n * legacy callback-based plugin in a promisifying adapter so it satisfies the\n * promise contract the rest of `@verdaccio/store` relies on.\n *\n * `@verdaccio/store` only ever calls `init()`, `getSecret()` and\n * `getStoragePlugin()` on this object, so that is the entire surface we mirror.\n */\nclass CompatLocalStorage {\n public storagePlugin: any = null;\n private readonly config: Config;\n private readonly logger: Logger;\n\n public constructor(config: Config, logger: Logger) {\n this.config = config;\n this.logger = logger.child({ sub: 'fs' });\n }\n\n public async init(): Promise<void> {\n if (this.storagePlugin === null) {\n const loaded = await this.loadStorage();\n this.storagePlugin = isLegacyStoragePlugin(loaded)\n ? wrapLegacyStoragePlugin(loaded, this.logger)\n : loaded;\n debug('storage plugin init');\n await this.storagePlugin.init();\n debug('storage plugin initialized');\n } else {\n this.logger.warn('storage plugin has been already initialized');\n }\n }\n\n public getStoragePlugin(): any {\n if (this.storagePlugin === null) {\n throw errorUtils.getInternalError('storage plugin is not initialized');\n }\n return this.storagePlugin;\n }\n\n public async getSecret(config: Config): Promise<void> {\n const secretKey = await this.storagePlugin.getSecret();\n return this.storagePlugin.setSecret(config.checkSecretKey(secretKey));\n }\n\n private async loadStorage(): Promise<any> {\n const Storage = await this.loadStorePlugin();\n if (isNil(Storage)) {\n assert(this.config.storage, 'CONFIG: storage path not defined');\n debug('no custom storage found, loading default storage @verdaccio/local-storage');\n const localStorage = new LocalDatabase(this.config, this.logger);\n this.logger.info(\n { name: '@verdaccio/local-storage', pluginCategory: PLUGIN_CATEGORY.STORAGE },\n 'plugin @{name} successfully loaded (@{pluginCategory})'\n );\n return localStorage;\n }\n return Storage;\n }\n\n private async loadStorePlugin(): Promise<any> {\n const plugins = await asyncLoadPlugin(\n this.config.store,\n { config: this.config, logger: this.logger },\n storageSanityCheck,\n // legacyMergeConfigs: pass the full config as the plugin's first constructor\n // arg, which legacy `(config, logger)` storage plugins require (matches the\n // pre-migration 7.x behaviour; @verdaccio/store uses false and so cannot\n // drive legacy plugins).\n true,\n this.config.server?.pluginPrefix ?? PLUGIN_PREFIX,\n PLUGIN_CATEGORY.STORAGE\n );\n if (plugins.length > 1) {\n this.logger.warn(\n 'more than one storage plugins has been detected, multiple storage are not supported, one will be selected automatically'\n );\n }\n return head(plugins);\n }\n}\n\n/**\n * `@verdaccio/store` Storage, with one change: it loads the storage plugin\n * through {@link CompatLocalStorage} so legacy callback plugins keep working.\n *\n * The base `init()` only creates its internal `LocalStorage` when\n * `this.localStorage` is still null; by pre-populating it we reuse the entire\n * rest of the upstream Storage implementation (including filter loading via\n * `super.init`) unchanged.\n */\nclass Storage extends BaseStorage {\n public async init(config: Config): Promise<void> {\n if (this.localStorage === null) {\n const localStorage = new CompatLocalStorage(this.config, this.logger);\n await localStorage.init();\n await localStorage.getSecret(config);\n // structurally compatible with the (non-exported) upstream LocalStorage\n this.localStorage = localStorage as any;\n debug('compat local storage initialized');\n }\n // localStorage is now non-null, so super.init only loads filter plugins\n await super.init(config);\n }\n}\n\nexport default Storage;\nexport { Storage };\n"],"mappings":";;;;;;;;;AAYA,IAAM,QAAQA,YAAW,mBAAmB;AAG5C,IAAM,gBAAiB,oBAA4B,WAAW;AAI9D,IAAM,sBAAsB,WAC1B,OAAO,QAAQ,sBAAsB;;;;;;;;;;AAWvC,IAAM,qBAAN,MAAyB;CACvB,gBAA4B;CAC5B;CACA;CAEA,YAAmB,QAAgB,QAAgB;EACjD,KAAK,SAAS;EACd,KAAK,SAAS,OAAO,MAAM,EAAE,KAAK,KAAK,CAAC;CAC1C;CAEA,MAAa,OAAsB;EACjC,IAAI,KAAK,kBAAkB,MAAM;GAC/B,MAAM,SAAS,MAAM,KAAK,YAAY;GACtC,KAAK,gBAAgB,sBAAsB,MAAM,IAC7C,wBAAwB,QAAQ,KAAK,MAAM,IAC3C;GACJ,MAAM,qBAAqB;GAC3B,MAAM,KAAK,cAAc,KAAK;GAC9B,MAAM,4BAA4B;EACpC,OACE,KAAK,OAAO,KAAK,6CAA6C;CAElE;CAEA,mBAA+B;EAC7B,IAAI,KAAK,kBAAkB,MACzB,MAAM,WAAW,iBAAiB,mCAAmC;EAEvE,OAAO,KAAK;CACd;CAEA,MAAa,UAAU,QAA+B;EACpD,MAAM,YAAY,MAAM,KAAK,cAAc,UAAU;EACrD,OAAO,KAAK,cAAc,UAAU,OAAO,eAAe,SAAS,CAAC;CACtE;CAEA,MAAc,cAA4B;EACxC,MAAM,UAAU,MAAM,KAAK,gBAAgB;EAC3C,IAAI,MAAM,OAAO,GAAG;GAClB,OAAO,KAAK,OAAO,SAAS,kCAAkC;GAC9D,MAAM,2EAA2E;GACjF,MAAM,eAAe,IAAI,cAAc,KAAK,QAAQ,KAAK,MAAM;GAC/D,KAAK,OAAO,KACV;IAAE,MAAM;IAA4B,gBAAgB,gBAAgB;GAAQ,GAC5E,wDACF;GACA,OAAO;EACT;EACA,OAAO;CACT;CAEA,MAAc,kBAAgC;EAC5C,MAAM,UAAU,MAAM,gBACpB,KAAK,OAAO,OACZ;GAAE,QAAQ,KAAK;GAAQ,QAAQ,KAAK;EAAO,GAC3C,oBAKA,MACA,KAAK,OAAO,QAAQ,gBAAgB,eACpC,gBAAgB,OAClB;EACA,IAAI,QAAQ,SAAS,GACnB,KAAK,OAAO,KACV,yHACF;EAEF,OAAO,KAAK,OAAO;CACrB;AACF;;;;;;;;;;AAWA,IAAM,UAAN,cAAsBC,UAAY;CAChC,MAAa,KAAK,QAA+B;EAC/C,IAAI,KAAK,iBAAiB,MAAM;GAC9B,MAAM,eAAe,IAAI,mBAAmB,KAAK,QAAQ,KAAK,MAAM;GACpE,MAAM,aAAa,KAAK;GACxB,MAAM,aAAa,UAAU,MAAM;GAEnC,KAAK,eAAe;GACpB,MAAM,kCAAkC;EAC1C;EAEA,MAAM,MAAM,KAAK,MAAM;CACzB;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ProxyStorage, ProxyStorage as default, setupUpLinks, updateVersionsHiddenUpLinkNext } from "@verdaccio/proxy";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { setup } from "./logger/index.mjs";
|
|
2
|
+
import { warningUtils } from "@verdaccio/core";
|
|
3
|
+
import createDebug from "debug";
|
|
4
|
+
//#region src/lib/utils.ts
|
|
5
|
+
var debug = createDebug("verdaccio:lib:utils");
|
|
6
|
+
async function initLogger(logConfig) {
|
|
7
|
+
if (logConfig.logs) {
|
|
8
|
+
logConfig.log = logConfig.logs;
|
|
9
|
+
warningUtils.emit(warningUtils.Codes.VERWAR002);
|
|
10
|
+
}
|
|
11
|
+
debug("initializing logger with config: %o", logConfig.log);
|
|
12
|
+
await setup(logConfig.log);
|
|
13
|
+
}
|
|
14
|
+
function getPackageVersion() {
|
|
15
|
+
return "7.0.1";
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { getPackageVersion, initLogger };
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=utils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.mjs","names":[],"sources":["../../../src/lib/utils.ts"],"sourcesContent":["import createDebug from 'debug';\n\nimport { warningUtils } from '@verdaccio/core';\nimport { ConfigYaml, LoggerConfigItem } from '@verdaccio/types';\n\nimport { setup } from './logger';\n\nconst debug = createDebug('verdaccio:lib:utils');\n\nexport async function initLogger(logConfig: ConfigYaml) {\n if (logConfig.logs) {\n logConfig.log = logConfig.logs;\n warningUtils.emit(warningUtils.Codes.VERWAR002);\n }\n debug('initializing logger with config: %o', logConfig.log);\n await setup(logConfig.log as LoggerConfigItem);\n}\n\n// `process.env.PACKAGE_VERSION` is inlined by vite at build time; `dev` when running from source\nexport function getPackageVersion(): string {\n return process.env.PACKAGE_VERSION || 'dev';\n}\n"],"mappings":";;;;AAOA,IAAM,QAAQ,YAAY,qBAAqB;AAE/C,eAAsB,WAAW,WAAuB;CACtD,IAAI,UAAU,MAAM;EAClB,UAAU,MAAM,UAAU;EAC1B,aAAa,KAAK,aAAa,MAAM,SAAS;CAChD;CACA,MAAM,uCAAuC,UAAU,GAAG;CAC1D,MAAM,MAAM,UAAU,GAAuB;AAC/C;AAGA,SAAgB,oBAA4B;CAC1C,OAAA;AACF"}
|
package/build/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { runServer } from '
|
|
2
|
-
export {
|
|
1
|
+
export { runServer, runServer as default, initServer } from './lib/run-server';
|
|
2
|
+
export { ConfigBuilder, parseConfigFile, getDefaultConfig, Config } from '@verdaccio/config';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { API_ERROR, API_MESSAGE, HTTP_STATUS, HEADERS, HEADER_TYPE, TOKEN_BASIC, TOKEN_BEARER, SUPPORT_ERRORS, DIST_TAGS, LATEST, } from '@verdaccio/core';
|
|
2
|
+
export declare const ROLES: {
|
|
3
|
+
$ALL: string;
|
|
4
|
+
ALL: string;
|
|
5
|
+
$AUTH: string;
|
|
6
|
+
$ANONYMOUS: string;
|
|
7
|
+
DEPRECATED_ALL: string;
|
|
8
|
+
DEPRECATED_AUTH: string;
|
|
9
|
+
DEPRECATED_ANONYMOUS: string;
|
|
10
|
+
};
|
|
11
|
+
export declare const ERROR_CODE: {
|
|
12
|
+
token_required: string;
|
|
13
|
+
};
|
|
14
|
+
export declare const DEFAULT_REGISTRY = "https://registry.npmjs.org";
|
|
15
|
+
export declare const DEFAULT_UPLINK = "npmjs";
|
|
16
|
+
export declare const WEB_TITLE = "Verdaccio";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Logger } from '@verdaccio/types';
|
|
2
|
+
/**
|
|
3
|
+
* Detect a legacy callback-based storage plugin. The new contract's `get()`
|
|
4
|
+
* takes no arguments (returns a promise); the legacy `get(cb)` declares a
|
|
5
|
+
* trailing callback, and `add(name, cb)` takes two. Arity is a stable signal
|
|
6
|
+
* here because both contracts are frozen.
|
|
7
|
+
*/
|
|
8
|
+
export declare function isLegacyStoragePlugin(plugin: any): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Wrap a legacy callback storage plugin in the promise contract expected by
|
|
11
|
+
* `@verdaccio/store`. Token methods are exposed only when the legacy plugin
|
|
12
|
+
* implements them (store already guards their absence with SERVICE_UNAVAILABLE).
|
|
13
|
+
*/
|
|
14
|
+
export declare function wrapLegacyStoragePlugin(plugin: any, logger: Logger): any;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { setup as setupModule } from '@verdaccio/logger';
|
|
2
|
+
import { Logger } from '@verdaccio/types';
|
|
3
|
+
declare let logger: Logger;
|
|
4
|
+
type SetupModuleOptions = Parameters<typeof setupModule>[0];
|
|
5
|
+
export declare function setup(options: SetupModuleOptions): Promise<void>;
|
|
6
|
+
export { logger };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ConfigYaml } from '@verdaccio/types';
|
|
2
|
+
/**
|
|
3
|
+
* Build the Express app from a raw config by reusing @verdaccio/server's
|
|
4
|
+
* composition (defineAPI), but inject 7.x's Storage so legacy callback storage
|
|
5
|
+
* plugins keep working. Exposed for tests that need the app without a listener.
|
|
6
|
+
*/
|
|
7
|
+
export declare function endPointAPI(configHash: ConfigYaml): Promise<any>;
|
|
8
|
+
/**
|
|
9
|
+
* Server factory passed to @verdaccio/node-api / @verdaccio/cli: maps the
|
|
10
|
+
* deprecated `logs` config key then builds the app with 7.x's legacy-aware
|
|
11
|
+
* Storage (via {@link endPointAPI}).
|
|
12
|
+
*/
|
|
13
|
+
export declare function startServer(config: ConfigYaml): Promise<any>;
|
|
14
|
+
/**
|
|
15
|
+
* Exposes a server factory to be instantiated programmatically.
|
|
16
|
+
*
|
|
17
|
+
```ts
|
|
18
|
+
const app = await runServer(); // default configuration
|
|
19
|
+
const app = await runServer('./config/config.yaml');
|
|
20
|
+
const app = await runServer({ configuration });
|
|
21
|
+
app.listen(4000, (event) => {
|
|
22
|
+
// do something
|
|
23
|
+
});
|
|
24
|
+
```
|
|
25
|
+
* @param config
|
|
26
|
+
*/
|
|
27
|
+
export declare function runServer(config?: string | ConfigYaml): Promise<any>;
|
|
28
|
+
/**
|
|
29
|
+
* Start the server on the port defined (or the port defined in the config file)
|
|
30
|
+
* @param config
|
|
31
|
+
* @param port
|
|
32
|
+
* @param version
|
|
33
|
+
* @param pkgName
|
|
34
|
+
*/
|
|
35
|
+
export declare function initServer(config: ConfigYaml, port: string | void, version: string, pkgName: string): Promise<void>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Storage as BaseStorage } from '@verdaccio/store';
|
|
2
|
+
import { Config } from '@verdaccio/types';
|
|
3
|
+
/**
|
|
4
|
+
* `@verdaccio/store` Storage, with one change: it loads the storage plugin
|
|
5
|
+
* through {@link CompatLocalStorage} so legacy callback plugins keep working.
|
|
6
|
+
*
|
|
7
|
+
* The base `init()` only creates its internal `LocalStorage` when
|
|
8
|
+
* `this.localStorage` is still null; by pre-populating it we reuse the entire
|
|
9
|
+
* rest of the upstream Storage implementation (including filter loading via
|
|
10
|
+
* `super.init`) unchanged.
|
|
11
|
+
*/
|
|
12
|
+
declare class Storage extends BaseStorage {
|
|
13
|
+
init(config: Config): Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
export default Storage;
|
|
16
|
+
export { Storage };
|