@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,300 +0,0 @@
1
- import { API_ERROR, HTTP_STATUS, errorUtils } from '@verdaccio/core';
2
-
3
- import {
4
- addVersion,
5
- publishPackage,
6
- removeTarball,
7
- unPublishPackage,
8
- uploadPackageTarball,
9
- } from '../../src/publish';
10
-
11
- const REVISION_MOCK = '15-e53a77096b0ee33e';
12
-
13
- require('@verdaccio/logger').setup([{ type: 'stdout', format: 'pretty', level: 'info' }]);
14
-
15
- describe('Publish endpoints - add a tag', () => {
16
- let req;
17
- let res;
18
- let next;
19
-
20
- beforeEach(() => {
21
- req = {
22
- params: {
23
- version: '1.0.0',
24
- tag: 'tag',
25
- package: 'verdaccio',
26
- },
27
- body: '',
28
- };
29
- res = {
30
- status: jest.fn(),
31
- };
32
-
33
- next = jest.fn();
34
- });
35
-
36
- test('should add a version', (done) => {
37
- const storage = {
38
- addVersion: (packageName, version, body, tag, cb) => {
39
- expect(packageName).toEqual(req.params.package);
40
- expect(version).toEqual(req.params.version);
41
- expect(body).toEqual(req.body);
42
- expect(tag).toEqual(req.params.tag);
43
- cb();
44
- done();
45
- },
46
- };
47
-
48
- // @ts-ignore
49
- addVersion(storage)(req, res, next);
50
-
51
- expect(res.status).toHaveBeenLastCalledWith(HTTP_STATUS.CREATED);
52
- expect(next).toHaveBeenLastCalledWith({ ok: 'package published' });
53
- });
54
-
55
- test('when failed to add a version', (done) => {
56
- const storage = {
57
- addVersion: (packageName, version, body, tag, cb) => {
58
- const error = {
59
- message: 'failure',
60
- };
61
- cb(error);
62
- done();
63
- },
64
- };
65
-
66
- // @ts-ignore
67
- addVersion(storage)(req, res, next);
68
-
69
- expect(next).toHaveBeenLastCalledWith({ message: 'failure' });
70
- });
71
- });
72
-
73
- /**
74
- * upload package: '/:package/-/:filename/*'
75
- */
76
- describe('Publish endpoints - upload package tarball', () => {
77
- let req;
78
- let res;
79
- let next;
80
-
81
- beforeEach(() => {
82
- req = {
83
- params: {
84
- filename: 'verdaccio.gzip',
85
- package: 'verdaccio',
86
- },
87
- pipe: jest.fn(),
88
- on: jest.fn(),
89
- };
90
- res = { status: jest.fn(), locals: { report_error: jest.fn() } };
91
- next = jest.fn();
92
- });
93
-
94
- test('should upload package tarball successfully', () => {
95
- const stream = {
96
- done: jest.fn(),
97
- abort: jest.fn(),
98
- on: jest.fn(() => (status, cb) => cb()),
99
- };
100
- const storage = {
101
- addTarball(packageName, filename) {
102
- expect(packageName).toEqual(req.params.package);
103
- expect(filename).toEqual(req.params.filename);
104
- return stream;
105
- },
106
- };
107
-
108
- // @ts-ignore
109
- uploadPackageTarball(storage)(req, res, next);
110
- expect(req.pipe).toHaveBeenCalled();
111
- expect(req.on).toHaveBeenCalled();
112
- });
113
- });
114
-
115
- /**
116
- * Delete tarball: '/:package/-/:filename/-rev/:revision'
117
- */
118
- describe('Publish endpoints - delete tarball', () => {
119
- let req;
120
- let res;
121
- let next;
122
-
123
- beforeEach(() => {
124
- req = {
125
- params: {
126
- filename: 'verdaccio.gzip',
127
- package: 'verdaccio',
128
- revision: REVISION_MOCK,
129
- },
130
- };
131
- res = { status: jest.fn() };
132
- next = jest.fn();
133
- });
134
-
135
- test('should delete tarball successfully', (done) => {
136
- const storage = {
137
- removeTarball(packageName, filename, revision, cb) {
138
- expect(packageName).toEqual(req.params.package);
139
- expect(filename).toEqual(req.params.filename);
140
- expect(revision).toEqual(req.params.revision);
141
- cb();
142
- done();
143
- },
144
- };
145
-
146
- // @ts-ignore
147
- removeTarball(storage)(req, res, next);
148
- expect(res.status).toHaveBeenCalledWith(HTTP_STATUS.CREATED);
149
- expect(next).toHaveBeenCalledWith({ ok: 'tarball removed' });
150
- });
151
-
152
- test('failed while deleting the tarball', (done) => {
153
- const error = {
154
- message: 'deletion failed',
155
- };
156
- const storage = {
157
- removeTarball(packageName, filename, revision, cb) {
158
- cb(error);
159
- done();
160
- },
161
- };
162
-
163
- // @ts-ignore
164
- removeTarball(storage)(req, res, next);
165
- expect(next).toHaveBeenCalledWith(error);
166
- });
167
- });
168
-
169
- /**
170
- * Un-publish package: '/:package/-rev/*'
171
- */
172
- describe('Publish endpoints - un-publish package', () => {
173
- let req;
174
- let res;
175
- let next;
176
-
177
- beforeEach(() => {
178
- req = {
179
- params: {
180
- package: 'verdaccio',
181
- },
182
- };
183
- res = { status: jest.fn() };
184
- next = jest.fn();
185
- });
186
-
187
- test('should un-publish package successfully', async () => {
188
- const storage = {
189
- removePackage(packageName) {
190
- expect(packageName).toEqual(req.params.package);
191
- return Promise.resolve();
192
- },
193
- };
194
-
195
- // @ts-ignore
196
- await unPublishPackage(storage)(req, res, next);
197
- expect(res.status).toHaveBeenCalledWith(HTTP_STATUS.CREATED);
198
- expect(next).toHaveBeenCalledWith({ ok: 'package removed' });
199
- });
200
-
201
- test('un-publish failed', async () => {
202
- const storage = {
203
- removePackage(packageName) {
204
- expect(packageName).toEqual(req.params.package);
205
- return Promise.reject(errorUtils.getInternalError());
206
- },
207
- };
208
-
209
- // @ts-ignore
210
- await unPublishPackage(storage)(req, res, next);
211
- expect(next).toHaveBeenCalledWith(errorUtils.getInternalError());
212
- });
213
- });
214
-
215
- /**
216
- * Publish package: '/:package/:_rev?/:revision?'
217
- */
218
- describe('Publish endpoints - publish package', () => {
219
- let req;
220
- let res;
221
- let next;
222
-
223
- beforeEach(() => {
224
- req = {
225
- body: {
226
- name: 'verdaccio',
227
- },
228
- params: {
229
- package: 'verdaccio',
230
- },
231
- };
232
- res = { status: jest.fn() };
233
- next = jest.fn();
234
- });
235
-
236
- test('should change the existing package', () => {
237
- const storage = {
238
- changePackage: jest.fn(),
239
- };
240
-
241
- req.params._rev = REVISION_MOCK;
242
-
243
- // @ts-ignore
244
- publishPackage(storage)(req, res, next);
245
- expect(storage.changePackage).toMatchSnapshot();
246
- });
247
-
248
- test('should publish a new a new package', () => {
249
- const storage = {
250
- addPackage: jest.fn(),
251
- };
252
-
253
- // @ts-ignore
254
- publishPackage(storage)(req, res, next);
255
- expect(storage.addPackage).toMatchSnapshot();
256
- });
257
-
258
- test('should throw an error while publishing package', () => {
259
- const storage = {
260
- addPackage() {
261
- throw new Error();
262
- },
263
- };
264
-
265
- // @ts-ignore
266
- publishPackage(storage)(req, res, next);
267
- expect(next).toHaveBeenCalledWith(new Error(API_ERROR.BAD_PACKAGE_DATA));
268
- });
269
-
270
- describe('test start', () => {
271
- test('should star a package', () => {
272
- const storage = {
273
- changePackage: jest.fn(),
274
- getPackage({ callback }) {
275
- callback(null, {
276
- users: {},
277
- });
278
- },
279
- };
280
- req = {
281
- params: {
282
- package: 'verdaccio',
283
- },
284
- body: {
285
- _rev: REVISION_MOCK,
286
- users: {
287
- verdaccio: true,
288
- },
289
- },
290
- remote_user: {
291
- name: 'verdaccio',
292
- },
293
- };
294
-
295
- // @ts-ignore
296
- publishPackage(storage)(req, res, next);
297
- expect(storage.changePackage).toMatchSnapshot();
298
- });
299
- });
300
- });