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.
Files changed (101) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +259 -4
  3. package/bin/verdaccio +1 -1
  4. package/build/cjs/_virtual/_rolldown/runtime.cjs +23 -0
  5. package/build/cjs/index.cjs +33 -0
  6. package/build/cjs/lib/auth-utils.cjs +14 -0
  7. package/build/cjs/lib/auth-utils.cjs.map +1 -0
  8. package/build/cjs/lib/auth.cjs +10 -0
  9. package/build/cjs/lib/auth.cjs.map +1 -0
  10. package/build/cjs/lib/cli.cjs +16 -0
  11. package/build/cjs/lib/cli.cjs.map +1 -0
  12. package/build/cjs/lib/config.cjs +20 -0
  13. package/build/cjs/lib/config.cjs.map +1 -0
  14. package/build/cjs/lib/constants.cjs +76 -0
  15. package/build/cjs/lib/constants.cjs.map +1 -0
  16. package/build/cjs/lib/legacy-storage-adapter.cjs +214 -0
  17. package/build/cjs/lib/legacy-storage-adapter.cjs.map +1 -0
  18. package/build/cjs/lib/logger/index.cjs +26 -0
  19. package/build/cjs/lib/logger/index.cjs.map +1 -0
  20. package/build/cjs/lib/run-server.cjs +64 -0
  21. package/build/cjs/lib/run-server.cjs.map +1 -0
  22. package/build/cjs/lib/storage.cjs +103 -0
  23. package/build/cjs/lib/storage.cjs.map +1 -0
  24. package/build/cjs/lib/up-storage.cjs +29 -0
  25. package/build/cjs/lib/utils.cjs +24 -0
  26. package/build/cjs/lib/utils.cjs.map +1 -0
  27. package/build/cjs/types/index.cjs +1 -0
  28. package/build/esm/index.mjs +3 -0
  29. package/build/esm/lib/auth-utils.mjs +11 -0
  30. package/build/esm/lib/auth-utils.mjs.map +1 -0
  31. package/build/esm/lib/auth.mjs +7 -0
  32. package/build/esm/lib/auth.mjs.map +1 -0
  33. package/build/esm/lib/cli.mjs +15 -0
  34. package/build/esm/lib/cli.mjs.map +1 -0
  35. package/build/esm/lib/config.mjs +16 -0
  36. package/build/esm/lib/config.mjs.map +1 -0
  37. package/build/esm/lib/constants.mjs +11 -0
  38. package/build/esm/lib/constants.mjs.map +1 -0
  39. package/build/esm/lib/legacy-storage-adapter.mjs +210 -0
  40. package/build/esm/lib/legacy-storage-adapter.mjs.map +1 -0
  41. package/build/esm/lib/logger/index.mjs +17 -0
  42. package/build/esm/lib/logger/index.mjs.map +1 -0
  43. package/build/esm/lib/run-server.mjs +58 -0
  44. package/build/esm/lib/run-server.mjs.map +1 -0
  45. package/build/esm/lib/storage.mjs +94 -0
  46. package/build/esm/lib/storage.mjs.map +1 -0
  47. package/build/esm/lib/up-storage.mjs +1 -0
  48. package/build/esm/lib/utils.mjs +20 -0
  49. package/build/esm/lib/utils.mjs.map +1 -0
  50. package/build/index.d.ts +2 -2
  51. package/build/lib/auth-utils.d.ts +2 -0
  52. package/build/lib/auth.d.ts +2 -0
  53. package/build/lib/cli.d.ts +2 -0
  54. package/build/lib/config.d.ts +5 -0
  55. package/build/lib/constants.d.ts +16 -0
  56. package/build/lib/legacy-storage-adapter.d.ts +14 -0
  57. package/build/lib/logger/index.d.ts +6 -0
  58. package/build/lib/run-server.d.ts +35 -0
  59. package/build/lib/storage.d.ts +16 -0
  60. package/build/lib/up-storage.d.ts +2 -0
  61. package/build/lib/utils.d.ts +3 -0
  62. package/build/types/index.d.ts +58 -0
  63. package/conf/.gitkeep +0 -0
  64. package/cypress/e2e/01-home.cy.ts +11 -0
  65. package/cypress/e2e/02-signin.cy.ts +11 -0
  66. package/cypress/e2e/03-layout.cy.ts +11 -0
  67. package/cypress/e2e/04-search.cy.ts +33 -0
  68. package/cypress/e2e/05-settings.cy.ts +24 -0
  69. package/cypress/e2e/06-publish.cy.ts +16 -0
  70. package/cypress/e2e/07-detail.cy.ts +19 -0
  71. package/cypress/e2e/08-failure-modes.cy.ts +21 -0
  72. package/cypress/e2e/09-manifest-rendering.cy.ts +20 -0
  73. package/cypress/e2e/10-session.cy.ts +17 -0
  74. package/cypress/e2e/11-i18n-keys.cy.ts +17 -0
  75. package/cypress/e2e/12-signup.cy.ts +19 -0
  76. package/cypress/e2e/13-change-password.cy.ts +24 -0
  77. package/cypress/support/e2e.ts +1 -0
  78. package/cypress/support/node-builtins-stub.cjs +6 -0
  79. package/cypress.config.ts +86 -0
  80. package/index.js +1 -0
  81. package/package.json +120 -62
  82. package/pnpm-workspace.yaml +32 -0
  83. package/renovate.json +22 -0
  84. package/security.txt +5 -0
  85. package/systemd/verdaccio.service +11 -0
  86. package/types/custom.d.ts +13 -0
  87. package/vite.config.ts +101 -0
  88. package/build/index.js +0 -32
  89. package/build/index.js.map +0 -1
  90. package/build/server/index.d.ts +0 -2
  91. package/build/server/index.js +0 -32
  92. package/build/server/index.js.map +0 -1
  93. package/build/server/registry.d.ts +0 -39
  94. package/build/server/registry.js +0 -154
  95. package/build/server/registry.js.map +0 -1
  96. package/build/server/request.d.ts +0 -64
  97. package/build/server/request.js +0 -264
  98. package/build/server/request.js.map +0 -1
  99. package/build/start.js +0 -4
  100. package/build/start.js.map +0 -1
  101. /package/build/{start.d.ts → esm/types/index.mjs} +0 -0
@@ -0,0 +1,32 @@
1
+ allowBuilds:
2
+ esbuild: true
3
+ unrs-resolver: true
4
+ minimumReleaseAge: 10080
5
+ # pnpm 12 auto-adds new direct dependencies to minimumReleaseAgeExclude instead
6
+ # of blocking them; strict keeps the pnpm 11 behavior (fail on immature versions)
7
+ minimumReleaseAgeStrict: true
8
+ minimumReleaseAgeExclude:
9
+ - '@verdaccio/*'
10
+ - '@verdaccio-scope/*'
11
+ - 'verdaccio-*'
12
+ # security update: body-parser@2.4.0 (GHSA-27r3-jxmh-p828)
13
+ - body-parser@2.4.0
14
+ # security update: fast-uri@3.1.9 (GHSA-w74x-v6f9-j3xg)
15
+ - fast-uri@3.1.9
16
+ ignoreScripts: true
17
+ saveExact: true
18
+ preferFrozenLockfile: true
19
+
20
+ auditConfig:
21
+ ignoreGhsas:
22
+ # braces: no patched release yet; only reached through globby with fixed '*' patterns
23
+ - GHSA-vfj7-8cjw-p6xm
24
+ # http-cache-semantics: no patched release yet; got only uses it with the `cache` option, which is never set
25
+ - GHSA-ch52-4w7c-c8xp
26
+ # Express.js unreleased
27
+ - GHSA-j3q9-mxjg-w52f
28
+ # Express.js unreleased
29
+ - GHSA-w7fw-mjwx-w883
30
+ # fast-uri (via Ajv)
31
+ - GHSA-qw65-cvwx-89v3
32
+ - GHSA-58mr-gqgx-xq4g
package/renovate.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "$schema": "https://docs.renovatebot.com/renovate-schema.json",
3
+ "extends": ["config:recommended", "helpers:pinGitHubActionDigests"],
4
+ "baseBranches": ["7.x"],
5
+ "prConcurrentLimit": 1,
6
+ "labels": ["bot: dependencies"],
7
+ "minimumReleaseAge": "15 days",
8
+ "semanticCommitType": "fix",
9
+ "packageRules": [
10
+ {
11
+ "description": "Verdaccio packages — update immediately, no age gate",
12
+ "matchPackagePatterns": ["^@verdaccio/", "^verdaccio-"],
13
+ "minimumReleaseAge": "0 days",
14
+ "groupName": "verdaccio"
15
+ },
16
+ {
17
+ "matchPackageNames": ["actions/*", "github/codeql-action/*"],
18
+ "groupName": "all actions",
19
+ "groupSlug": "github-actions"
20
+ }
21
+ ]
22
+ }
package/security.txt ADDED
@@ -0,0 +1,5 @@
1
+ Contact: verdaccio@pm.me
2
+ Encryption: https://verdaccio.nyc3.digitaloceanspaces.com/gpg/publickey.verdaccio@pm.me.asc
3
+ Acknowledgments: https://verdaccio.org/thanks.html
4
+ Preferred-Languages: en
5
+ Policy: https://github.com/verdaccio/verdaccio/security/policy
@@ -0,0 +1,11 @@
1
+ [Unit]
2
+ Description=Verdaccio lightweight npm proxy registry
3
+
4
+ [Service]
5
+ Type=simple
6
+ Restart=on-failure
7
+ User=verdaccio
8
+ ExecStart=/usr/bin/verdaccio --config /etc/verdaccio/config.yaml
9
+
10
+ [Install]
11
+ WantedBy=multi-user.target
@@ -0,0 +1,13 @@
1
+ import type { pluginUtils } from '@verdaccio/core';
2
+ import type { Logger, RemoteUser } from '@verdaccio/types';
3
+
4
+ declare global {
5
+ namespace Express {
6
+ export interface Request {
7
+ remote_user: RemoteUser;
8
+ log: Logger;
9
+ }
10
+ }
11
+ }
12
+
13
+ export type StoragePluginLegacy<T> = pluginUtils.Storage<T>;
package/vite.config.ts ADDED
@@ -0,0 +1,101 @@
1
+ import { spawn } from 'child_process';
2
+ import { readFileSync, readdirSync, statSync } from 'fs';
3
+ import { join, resolve } from 'path';
4
+ import { defineConfig } from 'vite';
5
+
6
+ const pkg = JSON.parse(readFileSync('./package.json', 'utf-8'));
7
+
8
+ function collectEntries(dir: string, base: string = ''): Record<string, string> {
9
+ const entries: Record<string, string> = {};
10
+ for (const file of readdirSync(dir)) {
11
+ const fullPath = join(dir, file);
12
+ const relPath = base ? `${base}/${file}` : file;
13
+ if (statSync(fullPath).isDirectory()) {
14
+ Object.assign(entries, collectEntries(fullPath, relPath));
15
+ } else if (file.endsWith('.ts') && !file.endsWith('.d.ts') && !file.endsWith('.spec.ts')) {
16
+ const name = relPath.replace(/\.ts$/, '');
17
+ entries[name] = fullPath;
18
+ }
19
+ }
20
+ return entries;
21
+ }
22
+
23
+ const entries = collectEntries(resolve(__dirname, 'src'));
24
+
25
+ const external = [
26
+ /^node:/,
27
+ /^(fs|path|http|https|url|crypto|stream|zlib|os|util|events|net|tls|child_process|constants|console|assert|module|dns|tty|readline|querystring|string_decoder|buffer|dgram|cluster|worker_threads|perf_hooks|inspector|v8|vm|async_hooks|diagnostics_channel|punycode|process)$/,
28
+ ...Object.keys(pkg.dependencies || {}),
29
+ ];
30
+
31
+ const preserveModules = {
32
+ preserveModules: true,
33
+ preserveModulesRoot: 'src',
34
+ };
35
+
36
+ function nativeDts() {
37
+ let emitted = false;
38
+
39
+ return {
40
+ name: 'verdaccio:native-dts',
41
+ apply: 'build' as const,
42
+ async closeBundle() {
43
+ if (emitted) {
44
+ return;
45
+ }
46
+ emitted = true;
47
+
48
+ const tsc = join(__dirname, 'node_modules', '.bin', 'tsc');
49
+ await new Promise<void>((resolvePromise, reject) => {
50
+ const child = spawn(
51
+ tsc,
52
+ ['-p', resolve(__dirname, 'tsconfig.json'), '--emitDeclarationOnly'],
53
+ {
54
+ cwd: __dirname,
55
+ stdio: 'inherit',
56
+ }
57
+ );
58
+ child.on('error', reject);
59
+ child.on('close', (code) =>
60
+ code === 0
61
+ ? resolvePromise()
62
+ : reject(new Error(`tsc --emitDeclarationOnly exited with code ${code}`))
63
+ );
64
+ });
65
+ },
66
+ };
67
+ }
68
+
69
+ export default defineConfig({
70
+ plugins: [nativeDts()],
71
+ build: {
72
+ target: 'node24',
73
+ outDir: 'build',
74
+ sourcemap: true,
75
+ minify: false,
76
+ lib: {
77
+ entry: entries,
78
+ },
79
+ rollupOptions: {
80
+ external,
81
+ output: [
82
+ {
83
+ format: 'es',
84
+ dir: 'build/esm',
85
+ entryFileNames: '[name].mjs',
86
+ ...preserveModules,
87
+ },
88
+ {
89
+ format: 'cjs',
90
+ dir: 'build/cjs',
91
+ entryFileNames: '[name].cjs',
92
+ exports: 'named',
93
+ ...preserveModules,
94
+ },
95
+ ],
96
+ },
97
+ },
98
+ define: {
99
+ 'process.env.PACKAGE_VERSION': JSON.stringify(pkg.version),
100
+ },
101
+ });
package/build/index.js DELETED
@@ -1,32 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "Registry", {
7
- enumerable: true,
8
- get: function () {
9
- return _server.Registry;
10
- }
11
- });
12
- Object.defineProperty(exports, "ResponseAssert", {
13
- enumerable: true,
14
- get: function () {
15
- return _server.ResponseAssert;
16
- }
17
- });
18
- Object.defineProperty(exports, "ServerQuery", {
19
- enumerable: true,
20
- get: function () {
21
- return _server.ServerQuery;
22
- }
23
- });
24
- Object.defineProperty(exports, "runServer", {
25
- enumerable: true,
26
- get: function () {
27
- return _nodeApi.runServer;
28
- }
29
- });
30
- var _nodeApi = require("@verdaccio/node-api");
31
- var _server = require("./server");
32
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":["_nodeApi","require","_server"],"sources":["../src/index.ts"],"sourcesContent":["export { runServer } from '@verdaccio/node-api';\nexport { Registry, ResponseAssert, ServerQuery } from './server';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA"}
@@ -1,2 +0,0 @@
1
- export { Registry } from './registry';
2
- export { ServerQuery, createRequest, ResponseAssert } from './request';
@@ -1,32 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "Registry", {
7
- enumerable: true,
8
- get: function () {
9
- return _registry.Registry;
10
- }
11
- });
12
- Object.defineProperty(exports, "ResponseAssert", {
13
- enumerable: true,
14
- get: function () {
15
- return _request.ResponseAssert;
16
- }
17
- });
18
- Object.defineProperty(exports, "ServerQuery", {
19
- enumerable: true,
20
- get: function () {
21
- return _request.ServerQuery;
22
- }
23
- });
24
- Object.defineProperty(exports, "createRequest", {
25
- enumerable: true,
26
- get: function () {
27
- return _request.createRequest;
28
- }
29
- });
30
- var _registry = require("./registry");
31
- var _request = require("./request");
32
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":["_registry","require","_request"],"sources":["../../src/server/index.ts"],"sourcesContent":["export { Registry } from './registry';\nexport { ServerQuery, createRequest, ResponseAssert } from './request';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA"}
@@ -1,39 +0,0 @@
1
- /// <reference types="node" />
2
- import { ChildProcess } from 'child_process';
3
- import { ConfigYaml } from '@verdaccio/types';
4
- type Options = {
5
- domain: string;
6
- port: number;
7
- createUser: boolean;
8
- credentials: {
9
- user: string;
10
- password: string;
11
- };
12
- debug: boolean;
13
- };
14
- export declare class Registry {
15
- private childFork;
16
- private configPath;
17
- private domain;
18
- private createUser;
19
- private authstr;
20
- private port;
21
- private credentials;
22
- private token;
23
- private debug;
24
- constructor(configPath: string, options?: Partial<Options>);
25
- static fromConfigToPath(config: Partial<ConfigYaml>): Promise<{
26
- tempFolder: string;
27
- configPath: string;
28
- yamlContent: string;
29
- }>;
30
- init(verdaccioPath: string): Promise<ChildProcess>;
31
- getToken(): string | null;
32
- getAuthStr(): string | null;
33
- getPort(): number;
34
- getDomain(): string;
35
- getRegistryUrl(): string;
36
- private _start;
37
- stop(): void;
38
- }
39
- export {};
@@ -1,154 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Registry = void 0;
7
- var _child_process = require("child_process");
8
- var _debug = _interopRequireDefault(require("debug"));
9
- var _fs = _interopRequireDefault(require("fs"));
10
- var _path = _interopRequireDefault(require("path"));
11
- var _config = require("@verdaccio/config");
12
- var _core = require("@verdaccio/core");
13
- var _utils = require("@verdaccio/utils");
14
- var _request = require("./request");
15
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
- const {
17
- writeFile
18
- } = _fs.default.promises ? _fs.default.promises : require('fs/promises');
19
- const buildAuthHeader = token => {
20
- return (0, _utils.buildToken)(_core.TOKEN_BEARER, token);
21
- };
22
- const debug = (0, _debug.default)('verdaccio:registry');
23
- const defaultOptions = {
24
- domain: 'localhost',
25
- port: 4873,
26
- createUser: false,
27
- credentials: {
28
- user: 'foo',
29
- password: '12345'
30
- },
31
- debug: false
32
- };
33
- class Registry {
34
- authstr = null;
35
- token = null;
36
- constructor(configPath, options = {}) {
37
- const _options = {
38
- ...defaultOptions,
39
- ...options
40
- };
41
- this.configPath = configPath;
42
- this.createUser = _options.createUser;
43
- this.port = _options.port;
44
- this.domain = _options.domain;
45
- this.debug = _options.debug;
46
- this.credentials = _options.credentials;
47
- }
48
- static async fromConfigToPath(config) {
49
- debug(`fromConfigToPath`);
50
- const tempFolder = await _core.fileUtils.createTempFolder('registry-');
51
- debug(`tempFolder %o`, tempFolder);
52
- const yamlContent = (0, _config.fromJStoYAML)(config);
53
- const configPath = _path.default.join(tempFolder, 'registry.yaml');
54
- await writeFile(configPath, yamlContent);
55
- debug(`configPath %o`, configPath);
56
- return {
57
- tempFolder,
58
- configPath,
59
- yamlContent
60
- };
61
- }
62
- init(verdaccioPath) {
63
- return this._start(verdaccioPath);
64
- }
65
- getToken() {
66
- return this.token;
67
- }
68
- getAuthStr() {
69
- return this.authstr;
70
- }
71
- getPort() {
72
- return this.port;
73
- }
74
- getDomain() {
75
- return this.domain;
76
- }
77
- getRegistryUrl() {
78
- return `http://${this.getDomain()}:${this.getPort()}`;
79
- }
80
- _start(verdaccioPath = _path.default.join(__dirname, '../../bin/verdaccio')) {
81
- debug('_start %o', verdaccioPath);
82
- debug('port %o', this.port);
83
- return new Promise((resolve, reject) => {
84
- let childOptions = {
85
- silent: false
86
- };
87
- if (this.debug) {
88
- const debugPort = this.port + 5;
89
- debug('debug port %o', debugPort);
90
- childOptions = Object.assign({}, childOptions, {
91
- execArgv: [`--inspect=${debugPort}`],
92
- env: {
93
- DEBUG: process.env.DEBUG,
94
- VERDACCIO_SERVER: process.env.VERDACCIO_SERVER
95
- }
96
- });
97
- } else {
98
- childOptions = Object.assign({}, childOptions, {
99
- env: {
100
- DEBUG: process.env.DEBUG,
101
- VERDACCIO_SERVER: process.env.VERDACCIO_SERVER
102
- }
103
- });
104
- }
105
- const {
106
- configPath
107
- } = this;
108
- debug('configPath %s', configPath);
109
- debug('port %s', this.port);
110
- this.childFork = (0, _child_process.fork)(verdaccioPath, ['-c', configPath, '-l', String(this.port)], childOptions);
111
- this.childFork.on('message', async msg => {
112
- // verdaccio_started is a message that comes from verdaccio in debug mode that
113
- // notify has been started
114
- try {
115
- if ('verdaccio_started' in msg) {
116
- const server = new _request.ServerQuery(`http://${this.domain}:` + this.port);
117
- if (this.createUser) {
118
- var _user$response;
119
- const user = await server.createUser(this.credentials.user, this.credentials.password);
120
- user.status(_core.HTTP_STATUS.CREATED).body_ok(new RegExp(this.credentials.user));
121
- // @ts-ignore
122
- this.token = user === null || user === void 0 ? void 0 : (_user$response = user.response) === null || _user$response === void 0 ? void 0 : _user$response.body.token;
123
- this.authstr = buildAuthHeader(this.token);
124
- }
125
- return resolve(this.childFork);
126
- }
127
- } catch (e) {
128
- // eslint-disable-next-line no-console
129
- console.error(e);
130
- // eslint-disable-next-line prefer-promise-reject-errors
131
- return reject([e, this]);
132
- }
133
- });
134
- this.childFork.on('error', err => {
135
- debug('error %s', err);
136
- // eslint-disable-next-line prefer-promise-reject-errors
137
- reject([err, this]);
138
- });
139
- this.childFork.on('disconnect', err => {
140
- // eslint-disable-next-line prefer-promise-reject-errors
141
- reject([err, this]);
142
- });
143
- this.childFork.on('exit', err => {
144
- // eslint-disable-next-line prefer-promise-reject-errors
145
- reject([err, this]);
146
- });
147
- });
148
- }
149
- stop() {
150
- return this.childFork.kill('SIGINT');
151
- }
152
- }
153
- exports.Registry = Registry;
154
- //# sourceMappingURL=registry.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"registry.js","names":["_child_process","require","_debug","_interopRequireDefault","_fs","_path","_config","_core","_utils","_request","obj","__esModule","default","writeFile","fs","promises","buildAuthHeader","token","buildToken","TOKEN_BEARER","debug","buildDebug","defaultOptions","domain","port","createUser","credentials","user","password","Registry","authstr","constructor","configPath","options","_options","fromConfigToPath","config","tempFolder","fileUtils","createTempFolder","yamlContent","fromJStoYAML","path","join","init","verdaccioPath","_start","getToken","getAuthStr","getPort","getDomain","getRegistryUrl","__dirname","Promise","resolve","reject","childOptions","silent","debugPort","Object","assign","execArgv","env","DEBUG","process","VERDACCIO_SERVER","childFork","fork","String","on","msg","server","ServerQuery","_user$response","status","HTTP_STATUS","CREATED","body_ok","RegExp","response","body","e","console","error","err","stop","kill","exports"],"sources":["../../src/server/registry.ts"],"sourcesContent":["import { ChildProcess, fork } from 'child_process';\nimport buildDebug from 'debug';\nimport fs from 'fs';\nimport path from 'path';\n\nimport { fromJStoYAML } from '@verdaccio/config';\nimport { HTTP_STATUS, TOKEN_BEARER, fileUtils } from '@verdaccio/core';\nimport { ConfigYaml } from '@verdaccio/types';\nimport { buildToken } from '@verdaccio/utils';\n\nimport { ServerQuery } from './request';\n\nconst { writeFile } = fs.promises ? fs.promises : require('fs/promises');\n\nconst buildAuthHeader = (token: string): string => {\n return buildToken(TOKEN_BEARER, token);\n};\n\nconst debug = buildDebug('verdaccio:registry');\n\nconst defaultOptions: Options = {\n domain: 'localhost',\n port: 4873,\n createUser: false,\n credentials: {\n user: 'foo',\n password: '12345',\n },\n debug: false,\n};\n\ntype Options = {\n domain: string;\n port: number;\n createUser: boolean;\n credentials: { user: string; password: string };\n debug: boolean;\n};\n\nexport class Registry {\n private childFork: any;\n private configPath: string;\n private domain: string;\n private createUser: boolean;\n private authstr: string | null = null;\n private port: number;\n private credentials;\n private token: string | null = null;\n private debug: boolean;\n public constructor(configPath: string, options: Partial<Options> = {}) {\n const _options = { ...defaultOptions, ...options };\n this.configPath = configPath;\n this.createUser = _options.createUser;\n this.port = _options.port;\n this.domain = _options.domain;\n this.debug = _options.debug;\n this.credentials = _options.credentials;\n }\n\n public static async fromConfigToPath(\n config: Partial<ConfigYaml>\n ): Promise<{ tempFolder: string; configPath: string; yamlContent: string }> {\n debug(`fromConfigToPath`);\n const tempFolder = await fileUtils.createTempFolder('registry-');\n debug(`tempFolder %o`, tempFolder);\n const yamlContent = fromJStoYAML(config) as string;\n const configPath = path.join(tempFolder, 'registry.yaml');\n await writeFile(configPath, yamlContent);\n debug(`configPath %o`, configPath);\n return {\n tempFolder,\n configPath,\n yamlContent,\n };\n }\n\n public init(verdaccioPath: string): Promise<ChildProcess> {\n return this._start(verdaccioPath);\n }\n\n public getToken() {\n return this.token;\n }\n\n public getAuthStr() {\n return this.authstr;\n }\n\n public getPort() {\n return this.port;\n }\n\n public getDomain() {\n return this.domain;\n }\n\n public getRegistryUrl() {\n return `http://${this.getDomain()}:${this.getPort()}`;\n }\n\n private _start(\n verdaccioPath: string = path.join(__dirname, '../../bin/verdaccio')\n ): Promise<ChildProcess> {\n debug('_start %o', verdaccioPath);\n debug('port %o', this.port);\n return new Promise((resolve, reject) => {\n let childOptions = {\n silent: false,\n };\n\n if (this.debug) {\n const debugPort = this.port + 5;\n debug('debug port %o', debugPort);\n childOptions = Object.assign({}, childOptions, {\n execArgv: [`--inspect=${debugPort}`],\n env: {\n DEBUG: process.env.DEBUG,\n VERDACCIO_SERVER: process.env.VERDACCIO_SERVER,\n },\n });\n } else {\n childOptions = Object.assign({}, childOptions, {\n env: {\n DEBUG: process.env.DEBUG,\n VERDACCIO_SERVER: process.env.VERDACCIO_SERVER,\n },\n });\n }\n\n const { configPath } = this;\n debug('configPath %s', configPath);\n debug('port %s', this.port);\n this.childFork = fork(\n verdaccioPath,\n ['-c', configPath, '-l', String(this.port)],\n childOptions\n );\n\n this.childFork.on('message', async (msg: any) => {\n // verdaccio_started is a message that comes from verdaccio in debug mode that\n // notify has been started\n try {\n if ('verdaccio_started' in msg) {\n const server = new ServerQuery(`http://${this.domain}:` + this.port);\n if (this.createUser) {\n const user = await server.createUser(\n this.credentials.user,\n this.credentials.password\n );\n user.status(HTTP_STATUS.CREATED).body_ok(new RegExp(this.credentials.user));\n // @ts-ignore\n this.token = user?.response?.body.token;\n this.authstr = buildAuthHeader(this.token as string);\n }\n\n return resolve(this.childFork);\n }\n } catch (e: any) {\n // eslint-disable-next-line no-console\n console.error(e);\n // eslint-disable-next-line prefer-promise-reject-errors\n return reject([e, this]);\n }\n });\n\n this.childFork.on('error', (err) => {\n debug('error %s', err);\n // eslint-disable-next-line prefer-promise-reject-errors\n reject([err, this]);\n });\n this.childFork.on('disconnect', (err) => {\n // eslint-disable-next-line prefer-promise-reject-errors\n reject([err, this]);\n });\n this.childFork.on('exit', (err) => {\n // eslint-disable-next-line prefer-promise-reject-errors\n reject([err, this]);\n });\n });\n }\n\n public stop(): void {\n return this.childFork.kill('SIGINT');\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,cAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,GAAA,GAAAD,sBAAA,CAAAF,OAAA;AACA,IAAAI,KAAA,GAAAF,sBAAA,CAAAF,OAAA;AAEA,IAAAK,OAAA,GAAAL,OAAA;AACA,IAAAM,KAAA,GAAAN,OAAA;AAEA,IAAAO,MAAA,GAAAP,OAAA;AAEA,IAAAQ,QAAA,GAAAR,OAAA;AAAwC,SAAAE,uBAAAO,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAExC,MAAM;EAAEG;AAAU,CAAC,GAAGC,WAAE,CAACC,QAAQ,GAAGD,WAAE,CAACC,QAAQ,GAAGd,OAAO,CAAC,aAAa,CAAC;AAExE,MAAMe,eAAe,GAAIC,KAAa,IAAa;EACjD,OAAO,IAAAC,iBAAU,EAACC,kBAAY,EAAEF,KAAK,CAAC;AACxC,CAAC;AAED,MAAMG,KAAK,GAAG,IAAAC,cAAU,EAAC,oBAAoB,CAAC;AAE9C,MAAMC,cAAuB,GAAG;EAC9BC,MAAM,EAAE,WAAW;EACnBC,IAAI,EAAE,IAAI;EACVC,UAAU,EAAE,KAAK;EACjBC,WAAW,EAAE;IACXC,IAAI,EAAE,KAAK;IACXC,QAAQ,EAAE;EACZ,CAAC;EACDR,KAAK,EAAE;AACT,CAAC;AAUM,MAAMS,QAAQ,CAAC;EAKZC,OAAO,GAAkB,IAAI;EAG7Bb,KAAK,GAAkB,IAAI;EAE5Bc,WAAWA,CAACC,UAAkB,EAAEC,OAAyB,GAAG,CAAC,CAAC,EAAE;IACrE,MAAMC,QAAQ,GAAG;MAAE,GAAGZ,cAAc;MAAE,GAAGW;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AW,EAAEgE,GAAG,CAAC;QACvB;QACA7B,MAAM,CAAC,CAAC6B,GAAG,EAAE,IAAI,CAAC,CAAC;MACrB,CAAC,CAAC;MACF,IAAI,CAAClB,SAAS,CAACG,EAAE,CAAC,YAAY,EAAGe,GAAG,IAAK;QACvC;QACA7B,MAAM,CAAC,CAAC6B,GAAG,EAAE,IAAI,CAAC,CAAC;MACrB,CAAC,CAAC;MACF,IAAI,CAAClB,SAAS,CAACG,EAAE,CAAC,MAAM,EAAGe,GAAG,IAAK;QACjC;QACA7B,MAAM,CAAC,CAAC6B,GAAG,EAAE,IAAI,CAAC,CAAC;MACrB,CAAC,CAAC;IACJ,CAAC,CAAC;EACJ;EAEOC,IAAIA,CAAA,EAAS;IAClB,OAAO,IAAI,CAACnB,SAAS,CAACoB,IAAI,CAAC,QAAQ,CAAC;EACtC;AACF;AAACC,OAAA,CAAA1D,QAAA,GAAAA,QAAA"}
@@ -1,64 +0,0 @@
1
- import { HTTPAlias, Headers as gotHeaders } from 'got';
2
- export interface ResponseAssert {
3
- status(reason: any): any;
4
- body_ok(reason: any): any;
5
- body_error(reason: any): any;
6
- request(reason: any): any;
7
- response(reason: any): any;
8
- send(reason: any): any;
9
- }
10
- type Options = {
11
- url: string;
12
- method: HTTPAlias;
13
- headers: gotHeaders;
14
- encoding?: string;
15
- json: boolean;
16
- body?: any;
17
- };
18
- export declare function createRequest(options: Options): Promise<any>;
19
- export declare class ServerQuery {
20
- private userAgent;
21
- private url;
22
- constructor(url: any);
23
- private request;
24
- debug(): Promise<ResponseAssert>;
25
- /**
26
- *
27
- *
28
- * @param {{ name: string; password: string }} { name, password }
29
- * @return {*} {Promise<ResponseAssert>}
30
- * @memberof ServerQuery
31
- * @deprecated use createUser instead
32
- */
33
- auth({ name, password }: {
34
- name: string;
35
- password: string;
36
- }): Promise<ResponseAssert>;
37
- createUser(name: any, password: any): Promise<ResponseAssert>;
38
- logout(token: string): Promise<ResponseAssert>;
39
- getPackage(name: string): Promise<ResponseAssert>;
40
- getTarball(name: string, filename: string): Promise<ResponseAssert>;
41
- /**
42
- * Remove entire package.
43
- * @param name package name
44
- * @param rev revision id
45
- * @returns
46
- */
47
- removePackage(name: string, rev: any): Promise<ResponseAssert>;
48
- removeSingleTarball(name: string, filename: string): Promise<ResponseAssert>;
49
- /**
50
- *
51
- * @param name
52
- * @param tag
53
- * @param version
54
- * @returns
55
- */
56
- addTag(name: string, tag: string, version: string): Promise<ResponseAssert>;
57
- putVersion(name: string, version: string, data: any, headers: any): Promise<ResponseAssert>;
58
- putPackage(name: string, data: any, headers?: {}): Promise<ResponseAssert>;
59
- addPackage(name: string, version?: string, message?: string): Promise<ResponseAssert>;
60
- addPackageAssert(name: string, version?: string): Promise<ResponseAssert>;
61
- whoami(): Promise<ResponseAssert>;
62
- ping(): Promise<any>;
63
- }
64
- export {};