@verdaccio/api 6.0.0-6-next.12 → 6.0.0-6-next.16
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/CHANGELOG.md +100 -0
- package/build/dist-tags.d.ts +2 -2
- package/build/dist-tags.js +8 -8
- package/build/dist-tags.js.map +1 -1
- package/build/index.d.ts +2 -2
- package/build/index.js +12 -13
- package/build/index.js.map +1 -1
- package/build/package.d.ts +2 -2
- package/build/package.js +6 -6
- package/build/package.js.map +1 -1
- package/build/publish.d.ts +7 -7
- package/build/publish.js +24 -22
- package/build/publish.js.map +1 -1
- package/build/search.d.ts +1 -1
- package/build/search.js +9 -102
- package/build/search.js.map +1 -1
- package/build/star.d.ts +2 -2
- package/build/star.js +6 -5
- package/build/star.js.map +1 -1
- package/build/stars.d.ts +2 -2
- package/build/stars.js +3 -3
- package/build/stars.js.map +1 -1
- package/build/user.js +12 -12
- package/build/user.js.map +1 -1
- package/build/v1/profile.js +10 -10
- package/build/v1/profile.js.map +1 -1
- package/build/v1/search.d.ts +9 -1
- package/build/v1/search.js +71 -88
- package/build/v1/search.js.map +1 -1
- package/build/v1/token.d.ts +2 -2
- package/build/v1/token.js +12 -12
- package/build/v1/token.js.map +1 -1
- package/build/whoami.js +0 -1
- package/build/whoami.js.map +1 -1
- package/package.json +16 -13
- package/src/dist-tags.ts +10 -10
- package/src/index.ts +12 -11
- package/src/package.ts +5 -10
- package/src/publish.ts +28 -19
- package/src/search.ts +9 -100
- package/src/star.ts +4 -3
- package/src/stars.ts +3 -3
- package/src/user.ts +7 -7
- package/src/v1/profile.ts +7 -7
- package/src/v1/search.ts +64 -89
- package/src/v1/token.ts +13 -18
- package/src/whoami.ts +0 -1
- package/test/integration/_helper.ts +3 -2
- package/test/integration/package.spec.ts +3 -3
- package/test/integration/ping.spec.ts +1 -1
- package/test/integration/publish.spec.ts +3 -8
- package/test/integration/user.spec.ts +6 -8
- package/test/integration/whoami.spec.ts +1 -1
- package/test/unit/publish.spec.ts +11 -15
- package/tsconfig.json +1 -1
package/src/v1/token.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import _ from 'lodash';
|
|
2
|
-
import { HTTP_STATUS, SUPPORT_ERRORS
|
|
3
|
-
import {
|
|
2
|
+
import { errorUtils, HTTP_STATUS, SUPPORT_ERRORS } from '@verdaccio/core';
|
|
3
|
+
import { stringToMD5, mask } from '@verdaccio/utils';
|
|
4
4
|
import { getApiToken } from '@verdaccio/auth';
|
|
5
5
|
import { logger } from '@verdaccio/logger';
|
|
6
6
|
import { Response, Router } from 'express';
|
|
7
7
|
|
|
8
8
|
import { Config, RemoteUser, Token } from '@verdaccio/types';
|
|
9
9
|
import { IAuth } from '@verdaccio/auth';
|
|
10
|
-
import {
|
|
10
|
+
import { Storage } from '@verdaccio/store';
|
|
11
11
|
import { $RequestExtend, $NextFunctionVer } from '../../types/custom';
|
|
12
12
|
|
|
13
13
|
export type NormalizeToken = Token & {
|
|
@@ -22,12 +22,7 @@ function normalizeToken(token: Token): NormalizeToken {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
// https://github.com/npm/npm-profile/blob/latest/lib/index.js
|
|
25
|
-
export default function (
|
|
26
|
-
route: Router,
|
|
27
|
-
auth: IAuth,
|
|
28
|
-
storage: IStorageHandler,
|
|
29
|
-
config: Config
|
|
30
|
-
): void {
|
|
25
|
+
export default function (route: Router, auth: IAuth, storage: Storage, config: Config): void {
|
|
31
26
|
route.get(
|
|
32
27
|
'/-/npm/v1/tokens',
|
|
33
28
|
async function (req: $RequestExtend, res: Response, next: $NextFunctionVer) {
|
|
@@ -48,10 +43,10 @@ export default function (
|
|
|
48
43
|
});
|
|
49
44
|
} catch (error: any) {
|
|
50
45
|
logger.error({ error: error.msg }, 'token list has failed: @{error}');
|
|
51
|
-
return next(
|
|
46
|
+
return next(errorUtils.getCode(HTTP_STATUS.INTERNAL_ERROR, error.message));
|
|
52
47
|
}
|
|
53
48
|
}
|
|
54
|
-
return next(
|
|
49
|
+
return next(errorUtils.getUnauthorized());
|
|
55
50
|
}
|
|
56
51
|
);
|
|
57
52
|
|
|
@@ -62,27 +57,27 @@ export default function (
|
|
|
62
57
|
const { name } = req.remote_user;
|
|
63
58
|
|
|
64
59
|
if (!_.isBoolean(readonly) || !_.isArray(cidr_whitelist)) {
|
|
65
|
-
return next(
|
|
60
|
+
return next(errorUtils.getCode(HTTP_STATUS.BAD_DATA, SUPPORT_ERRORS.PARAMETERS_NOT_VALID));
|
|
66
61
|
}
|
|
67
62
|
|
|
68
63
|
auth.authenticate(name, password, async (err, user: RemoteUser) => {
|
|
69
64
|
if (err) {
|
|
70
65
|
const errorCode = err.message ? HTTP_STATUS.UNAUTHORIZED : HTTP_STATUS.INTERNAL_ERROR;
|
|
71
|
-
return next(
|
|
66
|
+
return next(errorUtils.getCode(errorCode, err.message));
|
|
72
67
|
}
|
|
73
68
|
|
|
74
69
|
req.remote_user = user;
|
|
75
70
|
|
|
76
71
|
if (!_.isFunction(storage.saveToken)) {
|
|
77
72
|
return next(
|
|
78
|
-
|
|
73
|
+
errorUtils.getCode(HTTP_STATUS.NOT_IMPLEMENTED, SUPPORT_ERRORS.STORAGE_NOT_IMPLEMENT)
|
|
79
74
|
);
|
|
80
75
|
}
|
|
81
76
|
|
|
82
77
|
try {
|
|
83
78
|
const token = await getApiToken(auth, config, user, password);
|
|
84
79
|
if (!token) {
|
|
85
|
-
throw getInternalError();
|
|
80
|
+
throw errorUtils.getInternalError();
|
|
86
81
|
}
|
|
87
82
|
|
|
88
83
|
const key = stringToMD5(token);
|
|
@@ -118,7 +113,7 @@ export default function (
|
|
|
118
113
|
);
|
|
119
114
|
} catch (error: any) {
|
|
120
115
|
logger.error({ error: error.msg }, 'token creation has failed: @{error}');
|
|
121
|
-
return next(
|
|
116
|
+
return next(errorUtils.getInternalError(error.message));
|
|
122
117
|
}
|
|
123
118
|
});
|
|
124
119
|
}
|
|
@@ -140,10 +135,10 @@ export default function (
|
|
|
140
135
|
return next({});
|
|
141
136
|
} catch (error: any) {
|
|
142
137
|
logger.error({ error: error.msg }, 'token creation has failed: @{error}');
|
|
143
|
-
return next(
|
|
138
|
+
return next(errorUtils.getCode(HTTP_STATUS.INTERNAL_ERROR, error.message));
|
|
144
139
|
}
|
|
145
140
|
}
|
|
146
|
-
return next(
|
|
141
|
+
return next(errorUtils.getUnauthorized());
|
|
147
142
|
}
|
|
148
143
|
);
|
|
149
144
|
}
|
package/src/whoami.ts
CHANGED
|
@@ -5,9 +5,10 @@ import bodyParser from 'body-parser';
|
|
|
5
5
|
|
|
6
6
|
import { Config, parseConfigFile } from '@verdaccio/config';
|
|
7
7
|
import { Storage } from '@verdaccio/store';
|
|
8
|
+
import { generatePackageMetadata } from '@verdaccio/helper';
|
|
8
9
|
import { final, handleError, errorReportingMiddleware } from '@verdaccio/middleware';
|
|
9
10
|
import { Auth, IAuth } from '@verdaccio/auth';
|
|
10
|
-
import { HEADERS, HEADER_TYPE, HTTP_STATUS
|
|
11
|
+
import { HEADERS, HEADER_TYPE, HTTP_STATUS } from '@verdaccio/core';
|
|
11
12
|
import apiEndpoints from '../../src';
|
|
12
13
|
|
|
13
14
|
const getConf = (conf) => {
|
|
@@ -42,7 +43,7 @@ export async function initializeServer(configName): Promise<Application> {
|
|
|
42
43
|
return app;
|
|
43
44
|
}
|
|
44
45
|
|
|
45
|
-
export function publishVersion(app,
|
|
46
|
+
export function publishVersion(app, _configFile, pkgName, version): supertest.Test {
|
|
46
47
|
const pkgMetadata = generatePackageMetadata(pkgName, version);
|
|
47
48
|
|
|
48
49
|
return supertest(app)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import supertest from 'supertest';
|
|
2
2
|
|
|
3
|
-
import { HEADER_TYPE, HEADERS, HTTP_STATUS } from '@verdaccio/
|
|
3
|
+
import { HEADER_TYPE, HEADERS, HTTP_STATUS } from '@verdaccio/core';
|
|
4
4
|
import { $ResponseExtend, $RequestExtend } from '../../types/custom';
|
|
5
5
|
import { initializeServer, publishTaggedVersion, publishVersion } from './_helper';
|
|
6
6
|
|
|
@@ -64,7 +64,7 @@ describe('package', () => {
|
|
|
64
64
|
});
|
|
65
65
|
});
|
|
66
66
|
|
|
67
|
-
//
|
|
67
|
+
// FIXME: investigate the 404
|
|
68
68
|
test.skip('should return a package by dist-tag', async (done) => {
|
|
69
69
|
// await publishVersion(app, 'package.yaml', 'foo3', '1.0.0');
|
|
70
70
|
await publishVersion(app, 'package.yaml', 'foo-tagged', '1.0.0');
|
|
@@ -80,7 +80,7 @@ describe('package', () => {
|
|
|
80
80
|
});
|
|
81
81
|
});
|
|
82
82
|
|
|
83
|
-
test
|
|
83
|
+
test('should return 404', async () => {
|
|
84
84
|
return supertest(app)
|
|
85
85
|
.get('/404-not-found')
|
|
86
86
|
.set('Accept', HEADERS.JSON)
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
import { HTTP_STATUS } from '@verdaccio/
|
|
1
|
+
import { HTTP_STATUS } from '@verdaccio/core';
|
|
2
2
|
import supertest from 'supertest';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
API_MESSAGE,
|
|
6
|
-
generatePackageMetadata,
|
|
7
|
-
HEADER_TYPE,
|
|
8
|
-
HEADERS,
|
|
9
|
-
} from '@verdaccio/commons-api';
|
|
3
|
+
import { API_ERROR, API_MESSAGE, HEADER_TYPE, HEADERS } from '@verdaccio/core';
|
|
4
|
+
import { generatePackageMetadata } from '@verdaccio/helper';
|
|
10
5
|
import { $ResponseExtend, $RequestExtend } from '../../types/custom';
|
|
11
6
|
import { initializeServer, publishVersion } from './_helper';
|
|
12
7
|
|
|
@@ -2,15 +2,13 @@ import supertest from 'supertest';
|
|
|
2
2
|
import _ from 'lodash';
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
getConflict,
|
|
7
|
-
getUnauthorized,
|
|
5
|
+
errorUtils,
|
|
8
6
|
HEADERS,
|
|
9
7
|
HEADER_TYPE,
|
|
10
8
|
API_MESSAGE,
|
|
11
9
|
HTTP_STATUS,
|
|
12
10
|
API_ERROR,
|
|
13
|
-
} from '@verdaccio/
|
|
11
|
+
} from '@verdaccio/core';
|
|
14
12
|
|
|
15
13
|
import { $RequestExtend, $ResponseExtend } from '../../types/custom';
|
|
16
14
|
import { initializeServer } from './_helper';
|
|
@@ -28,7 +26,7 @@ const mockAuthenticate = jest.fn(() => (_name, _password, callback): void => {
|
|
|
28
26
|
});
|
|
29
27
|
|
|
30
28
|
const mockAddUser = jest.fn(() => (_name, _password, callback): void => {
|
|
31
|
-
return callback(getConflict(API_ERROR.USERNAME_ALREADY_REGISTERED));
|
|
29
|
+
return callback(errorUtils.getConflict(API_ERROR.USERNAME_ALREADY_REGISTERED));
|
|
32
30
|
});
|
|
33
31
|
|
|
34
32
|
jest.mock('@verdaccio/auth', () => ({
|
|
@@ -143,7 +141,7 @@ describe('user', () => {
|
|
|
143
141
|
}
|
|
144
142
|
);
|
|
145
143
|
mockAddUser.mockImplementationOnce(() => (_name, _password, callback): void => {
|
|
146
|
-
return callback(getBadRequest(API_ERROR.USERNAME_PASSWORD_REQUIRED));
|
|
144
|
+
return callback(errorUtils.getBadRequest(API_ERROR.USERNAME_PASSWORD_REQUIRED));
|
|
147
145
|
});
|
|
148
146
|
const credentialsShort = _.cloneDeep(credentials);
|
|
149
147
|
delete credentialsShort.name;
|
|
@@ -208,7 +206,7 @@ describe('user', () => {
|
|
|
208
206
|
}
|
|
209
207
|
);
|
|
210
208
|
mockAuthenticate.mockImplementationOnce(() => (_name, _password, callback): void => {
|
|
211
|
-
return callback(getUnauthorized(API_ERROR.BAD_USERNAME_PASSWORD));
|
|
209
|
+
return callback(errorUtils.getUnauthorized(API_ERROR.BAD_USERNAME_PASSWORD));
|
|
212
210
|
});
|
|
213
211
|
const credentialsShort = _.cloneDeep(credentials);
|
|
214
212
|
credentialsShort.password = 'failPassword';
|
|
@@ -240,7 +238,7 @@ describe('user', () => {
|
|
|
240
238
|
}
|
|
241
239
|
);
|
|
242
240
|
mockAuthenticate.mockImplementationOnce(() => (_name, _password, callback): void => {
|
|
243
|
-
return callback(getUnauthorized(API_ERROR.BAD_USERNAME_PASSWORD));
|
|
241
|
+
return callback(errorUtils.getUnauthorized(API_ERROR.BAD_USERNAME_PASSWORD));
|
|
244
242
|
});
|
|
245
243
|
const credentialsShort = _.cloneDeep(credentials);
|
|
246
244
|
credentialsShort.password = 'failPassword';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import supertest from 'supertest';
|
|
2
2
|
|
|
3
|
-
import { HEADERS, HTTP_STATUS } from '@verdaccio/
|
|
3
|
+
import { HEADERS, HTTP_STATUS } from '@verdaccio/core';
|
|
4
4
|
|
|
5
5
|
import { $RequestExtend, $ResponseExtend } from '../../types/custom';
|
|
6
6
|
import { initializeServer } from './_helper';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HTTP_STATUS, API_ERROR } from '@verdaccio/
|
|
1
|
+
import { errorUtils, HTTP_STATUS, API_ERROR } from '@verdaccio/core';
|
|
2
2
|
import {
|
|
3
3
|
addVersion,
|
|
4
4
|
uploadPackageTarball,
|
|
@@ -183,35 +183,31 @@ describe('Publish endpoints - un-publish package', () => {
|
|
|
183
183
|
next = jest.fn();
|
|
184
184
|
});
|
|
185
185
|
|
|
186
|
-
test('should un-publish package successfully', (
|
|
186
|
+
test('should un-publish package successfully', async () => {
|
|
187
187
|
const storage = {
|
|
188
|
-
removePackage(packageName
|
|
188
|
+
removePackage(packageName) {
|
|
189
189
|
expect(packageName).toEqual(req.params.package);
|
|
190
|
-
|
|
191
|
-
done();
|
|
190
|
+
return Promise.resolve();
|
|
192
191
|
},
|
|
193
192
|
};
|
|
194
193
|
|
|
195
194
|
// @ts-ignore
|
|
196
|
-
unPublishPackage(storage)(req, res, next);
|
|
195
|
+
await unPublishPackage(storage)(req, res, next);
|
|
197
196
|
expect(res.status).toHaveBeenCalledWith(HTTP_STATUS.CREATED);
|
|
198
197
|
expect(next).toHaveBeenCalledWith({ ok: 'package removed' });
|
|
199
198
|
});
|
|
200
199
|
|
|
201
|
-
test('un-publish failed', (
|
|
202
|
-
const error = {
|
|
203
|
-
message: 'un-publish failed',
|
|
204
|
-
};
|
|
200
|
+
test('un-publish failed', async () => {
|
|
205
201
|
const storage = {
|
|
206
|
-
removePackage(packageName
|
|
207
|
-
|
|
208
|
-
|
|
202
|
+
removePackage(packageName) {
|
|
203
|
+
expect(packageName).toEqual(req.params.package);
|
|
204
|
+
return Promise.reject(errorUtils.getInternalError());
|
|
209
205
|
},
|
|
210
206
|
};
|
|
211
207
|
|
|
212
208
|
// @ts-ignore
|
|
213
|
-
unPublishPackage(storage)(req, res, next);
|
|
214
|
-
expect(next).toHaveBeenCalledWith(
|
|
209
|
+
await unPublishPackage(storage)(req, res, next);
|
|
210
|
+
expect(next).toHaveBeenCalledWith(errorUtils.getInternalError());
|
|
215
211
|
});
|
|
216
212
|
});
|
|
217
213
|
|