@verdaccio/api 6.0.0-6-next.25 → 6.0.0-6-next.28

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 (64) hide show
  1. package/CHANGELOG.md +106 -0
  2. package/build/dist-tags.js +40 -35
  3. package/build/dist-tags.js.map +1 -1
  4. package/build/index.js +1 -7
  5. package/build/index.js.map +1 -1
  6. package/build/package.js +39 -28
  7. package/build/package.js.map +1 -1
  8. package/build/ping.js.map +1 -1
  9. package/build/publish.d.ts +79 -22
  10. package/build/publish.js +89 -313
  11. package/build/publish.js.map +1 -1
  12. package/build/search.js.map +1 -1
  13. package/build/star.js +53 -54
  14. package/build/star.js.map +1 -1
  15. package/build/stars.js +6 -6
  16. package/build/stars.js.map +1 -1
  17. package/build/user.js +19 -1
  18. package/build/user.js.map +1 -1
  19. package/build/v1/profile.js.map +1 -1
  20. package/build/v1/search.js +2 -4
  21. package/build/v1/search.js.map +1 -1
  22. package/build/v1/token.js.map +1 -1
  23. package/build/whoami.js +11 -25
  24. package/build/whoami.js.map +1 -1
  25. package/jest.config.js +8 -1
  26. package/package.json +71 -69
  27. package/src/dist-tags.ts +63 -50
  28. package/src/index.ts +1 -6
  29. package/src/package.ts +37 -44
  30. package/src/publish.ts +115 -336
  31. package/src/star.ts +53 -52
  32. package/src/stars.ts +9 -11
  33. package/src/user.ts +19 -2
  34. package/src/v1/search.ts +3 -3
  35. package/src/whoami.ts +8 -24
  36. package/test/integration/_helper.ts +97 -54
  37. package/test/integration/config/distTag.yaml +25 -0
  38. package/test/integration/config/package.yaml +3 -8
  39. package/test/integration/config/ping.yaml +2 -6
  40. package/test/integration/config/publish.yaml +4 -10
  41. package/test/integration/config/search.yaml +29 -0
  42. package/test/integration/config/token.jwt.yaml +27 -0
  43. package/test/integration/config/token.yaml +19 -0
  44. package/test/integration/config/user.jwt.yaml +37 -0
  45. package/test/integration/config/user.yaml +8 -14
  46. package/test/integration/config/whoami.yaml +4 -11
  47. package/test/integration/distTag.spec.ts +76 -0
  48. package/test/integration/package.spec.ts +53 -75
  49. package/test/integration/ping.spec.ts +4 -3
  50. package/test/integration/publish.spec.ts +60 -25
  51. package/test/integration/search.spec.ts +126 -0
  52. package/test/integration/token.spec.ts +124 -0
  53. package/test/integration/user.jwt.spec.ts +87 -0
  54. package/test/integration/user.spec.ts +1 -0
  55. package/test/integration/whoami.spec.ts +21 -39
  56. package/test/unit/publish.disabled.ts +252 -0
  57. package/tsconfig.json +1 -1
  58. package/__mocks__/@verdaccio/logger/index.js +0 -21
  59. package/build/utils.d.ts +0 -7
  60. package/build/utils.js +0 -36
  61. package/build/utils.js.map +0 -1
  62. package/src/utils.ts +0 -25
  63. package/test/unit/__snapshots__/publish.spec.ts.snap +0 -49
  64. package/test/unit/publish.spec.ts +0 -300
@@ -1,53 +1,35 @@
1
1
  import supertest from 'supertest';
2
2
 
3
- import { HEADERS, HTTP_STATUS } from '@verdaccio/core';
3
+ import { HEADERS, HTTP_STATUS, TOKEN_BEARER } from '@verdaccio/core';
4
+ import { buildToken } from '@verdaccio/utils';
4
5
 
5
- import { $RequestExtend, $ResponseExtend } from '../../types/custom';
6
- import { initializeServer } from './_helper';
7
-
8
- const mockApiJWTmiddleware = jest.fn(
9
- () =>
10
- (req: $RequestExtend, res: $ResponseExtend, _next): void => {
11
- req.remote_user = { name: 'foo', groups: [], real_groups: [] };
12
- _next();
13
- }
14
- );
15
-
16
- jest.mock('@verdaccio/auth', () => ({
17
- Auth: class {
18
- apiJWTmiddleware() {
19
- return mockApiJWTmiddleware();
20
- }
21
- allow_access(_d, f_, cb) {
22
- cb(null, true);
23
- }
24
- },
25
- }));
6
+ import { createUser, initializeServer } from './_helper';
26
7
 
27
8
  describe('whoami', () => {
28
- test.skip('should test referer /whoami endpoint', async (done) => {
29
- return supertest(await initializeServer('whoami.yaml'))
30
- .get('/whoami')
31
- .set('referer', 'whoami')
32
- .expect(HTTP_STATUS.OK)
33
- .end(done);
34
- });
35
-
36
- test.skip('should test no referer /whoami endpoint', async (done) => {
37
- return supertest(await initializeServer('whoami.yaml'))
38
- .get('/whoami')
39
- .expect(HTTP_STATUS.NOT_FOUND)
40
- .end(done);
41
- });
42
-
43
9
  test('should return the logged username', async () => {
44
- return supertest(await initializeServer('whoami.yaml'))
10
+ const app = await initializeServer('whoami.yaml');
11
+ // @ts-expect-error internal property
12
+ const { _body } = await createUser(app, 'test', 'test');
13
+ return supertest(app)
45
14
  .get('/-/whoami')
46
15
  .set('Accept', HEADERS.JSON)
16
+ .set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, _body.token))
47
17
  .expect('Content-Type', HEADERS.JSON_CHARSET)
48
18
  .expect(HTTP_STATUS.OK)
49
19
  .then((response) => {
50
- expect(response.body.username).toEqual('foo');
20
+ expect(response.body.username).toEqual('test');
51
21
  });
52
22
  });
23
+
24
+ test('should fails with 401 if is not logged in', async () => {
25
+ const app = await initializeServer('whoami.yaml');
26
+ // @ts-expect-error internal property
27
+ const { _body } = await createUser(app, 'test', 'test');
28
+ return supertest(app)
29
+ .get('/-/whoami')
30
+ .set('Accept', HEADERS.JSON)
31
+ .set(HEADERS.AUTHORIZATION, buildToken('invalid-token', _body.token))
32
+ .expect('Content-Type', HEADERS.JSON_CHARSET)
33
+ .expect(HTTP_STATUS.UNAUTHORIZED);
34
+ });
53
35
  });
@@ -0,0 +1,252 @@
1
+ // import { API_ERROR, HTTP_STATUS, errorUtils } from '@verdaccio/core';
2
+
3
+ // import { addVersion, publishPackage, removeTarball, unPublishPackage } from '../../src/publish';
4
+
5
+ // const REVISION_MOCK = '15-e53a77096b0ee33e';
6
+
7
+ // require('@verdaccio/logger').setup([{ type: 'stdout', format: 'pretty', level: 'info' }]);
8
+
9
+ // describe('Publish endpoints - add a tag', () => {
10
+ // let req;
11
+ // let res;
12
+ // let next;
13
+
14
+ // beforeEach(() => {
15
+ // req = {
16
+ // params: {
17
+ // version: '1.0.0',
18
+ // tag: 'tag',
19
+ // package: 'verdaccio',
20
+ // },
21
+ // body: '',
22
+ // };
23
+ // res = {
24
+ // status: jest.fn(),
25
+ // };
26
+
27
+ // next = jest.fn();
28
+ // });
29
+
30
+ // test('should add a version', (done) => {
31
+ // const storage = {
32
+ // addVersion: (packageName, version, body, tag, cb) => {
33
+ // expect(packageName).toEqual(req.params.package);
34
+ // expect(version).toEqual(req.params.version);
35
+ // expect(body).toEqual(req.body);
36
+ // expect(tag).toEqual(req.params.tag);
37
+ // cb();
38
+ // done();
39
+ // },
40
+ // };
41
+
42
+ // // @ts-ignore
43
+ // addVersion(storage)(req, res, next);
44
+
45
+ // expect(res.status).toHaveBeenLastCalledWith(HTTP_STATUS.CREATED);
46
+ // expect(next).toHaveBeenLastCalledWith({ ok: 'package published' });
47
+ // });
48
+
49
+ // test('when failed to add a version', (done) => {
50
+ // const storage = {
51
+ // addVersion: (packageName, version, body, tag, cb) => {
52
+ // const error = {
53
+ // message: 'failure',
54
+ // };
55
+ // cb(error);
56
+ // done();
57
+ // },
58
+ // };
59
+
60
+ // // @ts-ignore
61
+ // addVersion(storage)(req, res, next);
62
+
63
+ // expect(next).toHaveBeenLastCalledWith({ message: 'failure' });
64
+ // });
65
+ // });
66
+
67
+ // /**
68
+ // * Delete tarball: '/:package/-/:filename/-rev/:revision'
69
+ // */
70
+ // describe('Publish endpoints - delete tarball', () => {
71
+ // let req;
72
+ // let res;
73
+ // let next;
74
+
75
+ // beforeEach(() => {
76
+ // req = {
77
+ // params: {
78
+ // filename: 'verdaccio.gzip',
79
+ // package: 'verdaccio',
80
+ // revision: REVISION_MOCK,
81
+ // },
82
+ // };
83
+ // res = { status: jest.fn() };
84
+ // next = jest.fn();
85
+ // });
86
+
87
+ // test('should delete tarball successfully', (done) => {
88
+ // const storage = {
89
+ // removeTarball(packageName, filename, revision, cb) {
90
+ // expect(packageName).toEqual(req.params.package);
91
+ // expect(filename).toEqual(req.params.filename);
92
+ // expect(revision).toEqual(req.params.revision);
93
+ // cb();
94
+ // done();
95
+ // },
96
+ // };
97
+
98
+ // // @ts-ignore
99
+ // removeTarball(storage)(req, res, next);
100
+ // expect(res.status).toHaveBeenCalledWith(HTTP_STATUS.CREATED);
101
+ // expect(next).toHaveBeenCalledWith({ ok: 'tarball removed' });
102
+ // });
103
+
104
+ // test('failed while deleting the tarball', (done) => {
105
+ // const error = {
106
+ // message: 'deletion failed',
107
+ // };
108
+ // const storage = {
109
+ // removeTarball(packageName, filename, revision, cb) {
110
+ // cb(error);
111
+ // done();
112
+ // },
113
+ // };
114
+
115
+ // // @ts-ignore
116
+ // removeTarball(storage)(req, res, next);
117
+ // expect(next).toHaveBeenCalledWith(error);
118
+ // });
119
+ // });
120
+
121
+ // /**
122
+ // * Un-publish package: '/:package/-rev/*'
123
+ // */
124
+ // describe('Publish endpoints - un-publish package', () => {
125
+ // let req;
126
+ // let res;
127
+ // let next;
128
+
129
+ // beforeEach(() => {
130
+ // req = {
131
+ // params: {
132
+ // package: 'verdaccio',
133
+ // },
134
+ // };
135
+ // res = { status: jest.fn() };
136
+ // next = jest.fn();
137
+ // });
138
+
139
+ // test('should un-publish package successfully', async () => {
140
+ // const storage = {
141
+ // removePackage(packageName) {
142
+ // expect(packageName).toEqual(req.params.package);
143
+ // return Promise.resolve();
144
+ // },
145
+ // };
146
+
147
+ // // @ts-ignore
148
+ // await unPublishPackage(storage)(req, res, next);
149
+ // expect(res.status).toHaveBeenCalledWith(HTTP_STATUS.CREATED);
150
+ // expect(next).toHaveBeenCalledWith({ ok: 'package removed' });
151
+ // });
152
+
153
+ // test('un-publish failed', async () => {
154
+ // const storage = {
155
+ // removePackage(packageName) {
156
+ // expect(packageName).toEqual(req.params.package);
157
+ // return Promise.reject(errorUtils.getInternalError());
158
+ // },
159
+ // };
160
+
161
+ // // @ts-ignore
162
+ // await unPublishPackage(storage)(req, res, next);
163
+ // expect(next).toHaveBeenCalledWith(errorUtils.getInternalError());
164
+ // });
165
+ // });
166
+
167
+ // /**
168
+ // * Publish package: '/:package/:_rev?/:revision?'
169
+ // */
170
+ // describe('Publish endpoints - publish package', () => {
171
+ // let req;
172
+ // let res;
173
+ // let next;
174
+
175
+ // beforeEach(() => {
176
+ // req = {
177
+ // body: {
178
+ // name: 'verdaccio',
179
+ // },
180
+ // params: {
181
+ // package: 'verdaccio',
182
+ // },
183
+ // };
184
+ // res = { status: jest.fn() };
185
+ // next = jest.fn();
186
+ // });
187
+
188
+ // test('should change the existing package', () => {
189
+ // const storage = {
190
+ // changePackage: jest.fn(),
191
+ // };
192
+
193
+ // req.params._rev = REVISION_MOCK;
194
+
195
+ // // @ts-ignore
196
+ // publishPackage(storage)(req, res, next);
197
+ // expect(storage.changePackage).toMatchSnapshot();
198
+ // });
199
+
200
+ // test('should publish a new a new package', () => {
201
+ // const storage = {
202
+ // addPackage: jest.fn(),
203
+ // };
204
+
205
+ // // @ts-ignore
206
+ // publishPackage(storage)(req, res, next);
207
+ // expect(storage.addPackage).toMatchSnapshot();
208
+ // });
209
+
210
+ // test('should throw an error while publishing package', () => {
211
+ // const storage = {
212
+ // addPackage() {
213
+ // throw new Error();
214
+ // },
215
+ // };
216
+
217
+ // // @ts-ignore
218
+ // publishPackage(storage)(req, res, next);
219
+ // expect(next).toHaveBeenCalledWith(new Error(API_ERROR.BAD_PACKAGE_DATA));
220
+ // });
221
+
222
+ // describe('test start', () => {
223
+ // test('should star a package', () => {
224
+ // const storage = {
225
+ // changePackage: jest.fn(),
226
+ // getPackage({ callback }) {
227
+ // callback(null, {
228
+ // users: {},
229
+ // });
230
+ // },
231
+ // };
232
+ // req = {
233
+ // params: {
234
+ // package: 'verdaccio',
235
+ // },
236
+ // body: {
237
+ // _rev: REVISION_MOCK,
238
+ // users: {
239
+ // verdaccio: true,
240
+ // },
241
+ // },
242
+ // remote_user: {
243
+ // name: 'verdaccio',
244
+ // },
245
+ // };
246
+
247
+ // // @ts-ignore
248
+ // publishPackage(storage)(req, res, next);
249
+ // expect(storage.changePackage).toMatchSnapshot();
250
+ // });
251
+ // });
252
+ // });
package/tsconfig.json CHANGED
@@ -29,7 +29,7 @@
29
29
  "path": "../middleware"
30
30
  },
31
31
  {
32
- "path": "../server"
32
+ "path": "../server/express"
33
33
  },
34
34
  {
35
35
  "path": "../store"
@@ -1,21 +0,0 @@
1
- const debug = require('debug')('verdaccio:test');
2
-
3
- const setup = debug;
4
- const logger = {
5
- child: jest.fn(() => ({
6
- debug,
7
- trace: debug,
8
- warn: debug,
9
- info: debug,
10
- error: debug,
11
- fatal: debug,
12
- })),
13
- debug: debug,
14
- trace: debug,
15
- warn: debug,
16
- info: debug,
17
- error: debug,
18
- fatal: debug,
19
- };
20
-
21
- export { setup, logger };
package/build/utils.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import { Package } from '@verdaccio/types';
2
- /**
3
- * Check whether the package metadta has enough data to be published
4
- * @param pkg metadata
5
- */
6
- export declare function isPublishablePackage(pkg: Package): boolean;
7
- export declare function isRelatedToDeprecation(pkgInfo: Package): boolean;
package/build/utils.js DELETED
@@ -1,36 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.isPublishablePackage = isPublishablePackage;
7
- exports.isRelatedToDeprecation = isRelatedToDeprecation;
8
-
9
- var _lodash = _interopRequireDefault(require("lodash"));
10
-
11
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
-
13
- /**
14
- * Check whether the package metadta has enough data to be published
15
- * @param pkg metadata
16
- */
17
- function isPublishablePackage(pkg) {
18
- // TODO: we can do better, no need get keys
19
- const keys = Object.keys(pkg);
20
- return _lodash.default.includes(keys, 'versions');
21
- }
22
-
23
- function isRelatedToDeprecation(pkgInfo) {
24
- const {
25
- versions
26
- } = pkgInfo;
27
-
28
- for (const version in versions) {
29
- if (Object.prototype.hasOwnProperty.call(versions[version], 'deprecated')) {
30
- return true;
31
- }
32
- }
33
-
34
- return false;
35
- }
36
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/utils.ts"],"names":["isPublishablePackage","pkg","keys","Object","_","includes","isRelatedToDeprecation","pkgInfo","versions","version","prototype","hasOwnProperty","call"],"mappings":";;;;;;;;AAAA;;;;AAIA;AACA;AACA;AACA;AAEO,SAASA,oBAAT,CAA8BC,GAA9B,EAAqD;AAC1D;AACA,QAAMC,IAAc,GAAGC,MAAM,CAACD,IAAP,CAAYD,GAAZ,CAAvB;AAEA,SAAOG,gBAAEC,QAAF,CAAWH,IAAX,EAAiB,UAAjB,CAAP;AACD;;AAEM,SAASI,sBAAT,CAAgCC,OAAhC,EAA2D;AAChE,QAAM;AAAEC,IAAAA;AAAF,MAAeD,OAArB;;AACA,OAAK,MAAME,OAAX,IAAsBD,QAAtB,EAAgC;AAC9B,QAAIL,MAAM,CAACO,SAAP,CAAiBC,cAAjB,CAAgCC,IAAhC,CAAqCJ,QAAQ,CAACC,OAAD,CAA7C,EAAwD,YAAxD,CAAJ,EAA2E;AACzE,aAAO,IAAP;AACD;AACF;;AACD,SAAO,KAAP;AACD","sourcesContent":["import _ from 'lodash';\n\nimport { Package } from '@verdaccio/types';\n\n/**\n * Check whether the package metadta has enough data to be published\n * @param pkg metadata\n */\n\nexport function isPublishablePackage(pkg: Package): boolean {\n // TODO: we can do better, no need get keys\n const keys: string[] = Object.keys(pkg);\n\n return _.includes(keys, 'versions');\n}\n\nexport function isRelatedToDeprecation(pkgInfo: Package): boolean {\n const { versions } = pkgInfo;\n for (const version in versions) {\n if (Object.prototype.hasOwnProperty.call(versions[version], 'deprecated')) {\n return true;\n }\n }\n return false;\n}\n"],"file":"utils.js"}
package/src/utils.ts DELETED
@@ -1,25 +0,0 @@
1
- import _ from 'lodash';
2
-
3
- import { Package } from '@verdaccio/types';
4
-
5
- /**
6
- * Check whether the package metadta has enough data to be published
7
- * @param pkg metadata
8
- */
9
-
10
- export function isPublishablePackage(pkg: Package): boolean {
11
- // TODO: we can do better, no need get keys
12
- const keys: string[] = Object.keys(pkg);
13
-
14
- return _.includes(keys, 'versions');
15
- }
16
-
17
- export function isRelatedToDeprecation(pkgInfo: Package): boolean {
18
- const { versions } = pkgInfo;
19
- for (const version in versions) {
20
- if (Object.prototype.hasOwnProperty.call(versions[version], 'deprecated')) {
21
- return true;
22
- }
23
- }
24
- return false;
25
- }
@@ -1,49 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`Publish endpoints - publish package should change the existing package 1`] = `[MockFunction]`;
4
-
5
- exports[`Publish endpoints - publish package should publish a new a new package 1`] = `
6
- [MockFunction] {
7
- "calls": Array [
8
- Array [
9
- "verdaccio",
10
- Object {
11
- "dist-tags": Object {},
12
- "name": "verdaccio",
13
- "time": Object {},
14
- "versions": Object {},
15
- },
16
- [Function],
17
- ],
18
- ],
19
- "results": Array [
20
- Object {
21
- "type": "return",
22
- "value": undefined,
23
- },
24
- ],
25
- }
26
- `;
27
-
28
- exports[`Publish endpoints - publish package test start should star a package 1`] = `
29
- [MockFunction] {
30
- "calls": Array [
31
- Array [
32
- "verdaccio",
33
- Object {
34
- "users": Object {
35
- "verdaccio": true,
36
- },
37
- },
38
- "15-e53a77096b0ee33e",
39
- [Function],
40
- ],
41
- ],
42
- "results": Array [
43
- Object {
44
- "type": "return",
45
- "value": undefined,
46
- },
47
- ],
48
- }
49
- `;