Skip to content

Commit 87c679d

Browse files
committed
refactor: update dependencies and script
1 parent cde1a60 commit 87c679d

File tree

8 files changed

+1354
-1571
lines changed

8 files changed

+1354
-1571
lines changed

.babelrc

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,3 @@
11
{
2-
"env": {
3-
"registry": {
4-
"presets": [
5-
[
6-
"@babel/env",
7-
{
8-
"targets": {
9-
"node": "8.15"
10-
}
11-
}
12-
],
13-
"@babel/typescript"
14-
],
15-
"plugins": [
16-
"@babel/proposal-class-properties",
17-
"@babel/proposal-object-rest-spread"
18-
]
19-
},
20-
"registry-docker": {
21-
"registry": {
22-
"presets": [
23-
[
24-
"@babel/env",
25-
{
26-
"targets": {
27-
"node": "10"
28-
}
29-
}
30-
],
31-
"@babel/typescript"
32-
],
33-
"plugins": [
34-
"@babel/proposal-class-properties",
35-
"@babel/proposal-object-rest-spread"
36-
]
37-
},
38-
},
39-
"development": {}
40-
}
2+
"presets": [["@verdaccio"]]
413
}

.eslintrc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"extends": [
3+
"@verdaccio"
4+
],
5+
"rules": {
6+
"@typescript-eslint/no-var-requires": ["warn"],
7+
"@typescript-eslint/ban-ts-ignore": 0,
8+
"@typescript-eslint/no-inferrable-types": ["warn"],
9+
"@typescript-eslint/no-empty-function": ["warn"],
10+
"@typescript-eslint/no-this-alias": ["warn"],
11+
"@typescript-eslint/no-use-before-define": 0,
12+
"@typescript-eslint/array-type": ["warn"],
13+
"@typescript-eslint/no-explicit-any": 0,
14+
"@typescript-eslint/indent": 0,
15+
"@typescript-eslint/interface-name-prefix": 0
16+
}
17+
}

.eslintrc.yml

Lines changed: 0 additions & 35 deletions
This file was deleted.

package.json

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@
88
"type-check": "tsc --noEmit",
99
"commitmsg": "commitlint -e $GIT_PARAMS",
1010
"license": "license-checker --onlyAllow 'Apache-2.0; Apache License, Version 2.0; BSD; BSD-2-Clause; BSD-3-Clause; ISC; MIT; Unlicense; WTFPL; CC-BY-3.0; CC0-1.0' --production",
11-
"lint": "yarn flow && eslint . && eclint check $(git ls-files) && markdownlint README.md",
11+
"type-check:watch": "npm run type-check -- --watch",
12+
"lint:ts": "eslint . --ext .js,.ts",
13+
"lint": "yarn type-check && yarn lint:ts && eclint check $(git ls-files) && markdownlint README.md",
1214
"prepublish": "in-publish && yarn lint && yarn code:build || not-in-publish",
1315
"release:major": "changelog -M && git commit -a -m 'docs: updated CHANGELOG.md' && yarn version --major && git push origin && git push origin --tags",
1416
"release:minor": "changelog -m && git commit -a -m 'docs: updated CHANGELOG.md' && yarn version --minor && git push origin && git push origin --tags",
1517
"release:patch": "changelog -p && git commit -a -m 'docs: updated CHANGELOG.md' && yarn version --patch && git push origin && git push origin --tags",
1618
"start": "yarn code:build && cross-env NODE_PATH=$NODE_PATH:.. BABEL_ENV=registry babel-node build/verdaccio.js",
1719
"code:build:types": "tsc --emitDeclarationOnly",
1820
"code:build": "cross-env BABEL_ENV=registry babel src/ --out-dir build/ --extensions \".ts,.tsx\"",
19-
"code:docker-build": "cross-env BABEL_ENV=registry-docker babel src/ --out-dir build/ --extensions \".ts,.tsx\"",
21+
"code:docker-build": "cross-env BABEL_ENV=docker babel src/ --out-dir build/ --extensions \".ts,.tsx\"",
2022
"build:docker": "docker build -t verdaccio-gitlab . --no-cache",
2123
"test": "yarn test:unit",
2224
"test:unit": "cross-env BABEL_ENV=test TZ=UTC jest --config ./test/jest.config.unit.js --maxWorkers 2",
@@ -55,43 +57,22 @@
5557
"verdaccio": "^4.3.4"
5658
},
5759
"devDependencies": {
58-
"@babel/cli": "7.4.4",
59-
"@babel/core": "7.4.5",
60-
"@babel/node": "7.4.5",
61-
"@babel/plugin-proposal-class-properties": "7.4.4",
62-
"@babel/plugin-proposal-decorators": "7.4.4",
63-
"@babel/plugin-proposal-export-namespace-from": "7.2.0",
64-
"@babel/plugin-proposal-function-sent": "7.2.0",
65-
"@babel/plugin-proposal-json-strings": "7.2.0",
66-
"@babel/plugin-proposal-numeric-separator": "7.2.0",
67-
"@babel/plugin-proposal-object-rest-spread": "7.4.4",
68-
"@babel/plugin-proposal-throw-expressions": "7.2.0",
69-
"@babel/plugin-syntax-dynamic-import": "7.2.0",
70-
"@babel/plugin-syntax-import-meta": "7.2.0",
71-
"@babel/plugin-transform-async-to-generator": "7.4.4",
72-
"@babel/plugin-transform-classes": "7.4.4",
73-
"@babel/plugin-transform-runtime": "7.4.4",
74-
"@babel/polyfill": "7.4.4",
75-
"@babel/preset-env": "7.4.5",
76-
"@babel/preset-flow": "7.0.0",
77-
"@babel/preset-react": "7.0.0",
78-
"@babel/preset-typescript": "7.3.3",
79-
"@babel/register": "7.4.4",
80-
"@babel/runtime": "7.4.5",
60+
"@verdaccio/babel-preset": "^8.2.0",
61+
"@verdaccio/eslint-config": "^8.2.0",
62+
"@verdaccio/commons-api": "^8.2.0",
63+
"@verdaccio/types": "^8.3.0",
8164
"@commitlint/cli": "7.0.0",
8265
"@commitlint/config-conventional": "7.0.1",
8366
"@commitlint/travis-cli": "7.0.0",
8467
"@types/http-errors": "1.6.1",
8568
"@types/jest": "24.0.15",
8669
"@types/node": "^12.0.10",
87-
"@verdaccio/types": "5.1.0",
70+
"@typescript-eslint/eslint-plugin": "2.1.0",
8871
"body-parser": "^1.18.3",
8972
"chalk": "^2.4.1",
9073
"cross-env": "^5.2.0",
91-
"eclint": "2.8.0",
92-
"eslint": "5.2.0",
93-
"eslint-plugin-import": "2.13.0",
94-
"eslint-plugin-jest": "^21.21.0",
74+
"eslint": "^6.3.0",
75+
9576
"express": "^4.16.3",
9677
"generate-changelog": "1.7.1",
9778
"http-status": "^1.2.0",
@@ -105,7 +86,7 @@
10586
"repolinter": "0.7.0",
10687
"request": "^2.88.0",
10788
"rimraf": "^2.6.2",
108-
"typescript": "3.5.2"
89+
"typescript": "3.7.1-rc"
10990
},
11091
"commitlint": {
11192
"extends": [

src/authcache.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ export class AuthCache {
2828
useClones: false
2929
});
3030
this.storage.on('expired', (key, value) => {
31-
if (this.logger.trace()) {
32-
this.logger.trace(`[gitlab] expired key: ${key} with value:`, value);
33-
}
31+
this.logger.trace(`[gitlab] expired key: ${key} with value:`, value);
3432
});
3533
}
3634

src/gitlab.ts

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
// Copyright 2018 Roger Meier <[email protected]>
22
// SPDX-License-Identifier: MIT
3-
// @flow
43

5-
import type { Callback, IPluginAuth, Logger, PluginOptions, RemoteUser, PackageAccess } from '@verdaccio/types';
6-
import type { UserDataGroups } from './authcache';
4+
import { Callback, IPluginAuth, Logger, PluginOptions, RemoteUser, PackageAccess } from '@verdaccio/types';
5+
import { getInternalError, getUnauthorized, getForbidden } from '@verdaccio/commons-api';
6+
import { UserDataGroups } from './authcache';
77

88
import Gitlab from 'gitlab';
99
import { AuthCache, UserData } from './authcache';
10-
import httperror from 'http-errors';
1110

1211
export type VerdaccioGitlabAccessLevel =
1312
'$guest' |
@@ -26,10 +25,10 @@ export type VerdaccioGitlabConfig = {
2625
publish?: VerdaccioGitlabAccessLevel
2726
};
2827

29-
export type VerdaccioGitlabPackageAccess = PackageAccess & {
30-
name: string,
28+
export interface VerdaccioGitlabPackageAccess extends PackageAccess {
29+
name?: string,
3130
gitlab?: boolean
32-
}
31+
};
3332

3433
const ACCESS_LEVEL_MAPPING = {
3534
$guest: 10,
@@ -46,14 +45,19 @@ const BUILTIN_ACCESS_LEVEL_ANONYMOUS = [ '$anonymous', '$all' ];
4645
const DEFAULT_ALLOW_ACCESS_LEVEL = [ '$all' ];
4746

4847

49-
export default class VerdaccioGitLab implements IPluginAuth {
50-
options: PluginOptions;
48+
export interface VerdaccioGitLabPlugin extends IPluginAuth<VerdaccioGitlabConfig> {
49+
authCache: AuthCache;
50+
}
51+
52+
53+
export default class VerdaccioGitLab implements VerdaccioGitLabPlugin {
54+
options: PluginOptions<VerdaccioGitlabConfig>;
5155
config: VerdaccioGitlabConfig;
5256
authCache: AuthCache;
5357
logger: Logger;
5458
publishLevel: VerdaccioGitlabAccessLevel;
5559

56-
constructor(config: VerdaccioGitlabConfig, options: PluginOptions) {
60+
constructor(config: VerdaccioGitlabConfig, options: PluginOptions<VerdaccioGitlabConfig>) {
5761
this.logger = options.logger;
5862
this.config = config;
5963
this.options = options;
@@ -103,7 +107,7 @@ export default class VerdaccioGitLab implements IPluginAuth {
103107

104108
GitlabAPI.Users.current().then(response => {
105109
if (user !== response.username) {
106-
return cb(httperror[401]('wrong gitlab username'));
110+
return cb(getForbidden('wrong gitlab username'));
107111
}
108112

109113
const publishLevelId = ACCESS_LEVEL_MAPPING[this.publishLevel];
@@ -136,12 +140,12 @@ export default class VerdaccioGitLab implements IPluginAuth {
136140
return cb(null, realGroups);
137141
}).catch(error => {
138142
this.logger.error(`[gitlab] user: ${user} error querying gitlab: ${error}`);
139-
return cb(httperror[401]('error authenticating user'));
143+
return cb(getUnauthorized('error authenticating user'));
140144
});
141145

142146
}).catch(error => {
143147
this.logger.error(`[gitlab] user: ${user} error querying gitlab user data: ${error.message || {}}`);
144-
return cb(httperror[401]('error authenticating user'));
148+
return cb(getUnauthorized('error authenticating user'));
145149
});
146150
}
147151

@@ -150,12 +154,12 @@ export default class VerdaccioGitLab implements IPluginAuth {
150154
return cb(null, true);
151155
}
152156

153-
changePassword(user: string, password: string, newPassword: string, cb: verdaccio$Callback) {
157+
changePassword(user: string, password: string, newPassword: string, cb: Callback) {
154158
this.logger.trace(`[gitlab] changePassword called for user: ${user}`);
155-
return cb(httperror[501]('You are using verdaccio-gitlab integration. Please change your password in gitlab'));
159+
return cb(getInternalError('You are using verdaccio-gitlab integration. Please change your password in gitlab'));
156160
}
157161

158-
allow_access(user: RemoteUser, _package: VerdaccioGitlabPackageAccess, cb: Callback) {
162+
allow_access(user: RemoteUser, _package: VerdaccioGitlabPackageAccess & PackageAccess, cb: Callback) {
159163
if (!_package.gitlab) return cb(null, false);
160164

161165
const packageAccess = (_package.access && _package.access.length > 0) ? _package.access : DEFAULT_ALLOW_ACCESS_LEVEL;
@@ -169,12 +173,12 @@ export default class VerdaccioGitLab implements IPluginAuth {
169173
return cb(null, true);
170174
} else {
171175
this.logger.debug(`[gitlab] deny access to package: ${_package.name}`);
172-
return cb(httperror[401]('access denied, user not authenticated and anonymous access disabled'));
176+
return cb(getForbidden('access denied, user not authenticated and anonymous access disabled'));
173177
}
174178
}
175179
}
176180

177-
allow_publish(user: RemoteUser, _package: VerdaccioGitlabPackageAccess, cb: Callback) {
181+
allow_publish(user: RemoteUser, _package: VerdaccioGitlabPackageAccess & PackageAccess, cb: Callback) {
178182
if (!_package.gitlab) return cb(null, false);
179183

180184
let packageScopePermit = false;
@@ -185,7 +189,7 @@ export default class VerdaccioGitLab implements IPluginAuth {
185189
for (let real_group of user.real_groups) { // jscs:ignore requireCamelCaseOrUpperCaseIdentifiers
186190
this.logger.trace(`[gitlab] publish: checking group: ${real_group} for user: ${user.name || ''} and package: ${_package.name}`);
187191

188-
if (this._matchGroupWithPackage(real_group, _package.name)) {
192+
if (this._matchGroupWithPackage(real_group, _package.name as string)) {
189193
packagePermit = true;
190194
break;
191195
}
@@ -197,8 +201,8 @@ export default class VerdaccioGitLab implements IPluginAuth {
197201
return cb(null, true);
198202
} else {
199203
this.logger.debug(`[gitlab] user: ${user.name || ''} denied from publishing package: ${_package.name}`);
200-
const missingPerm = _package.name.indexOf('@') === 0 ? 'package-scope' : 'package-name';
201-
return cb(httperror[403](`must have required permissions: ${this.publishLevel || ''} at ${missingPerm}`));
204+
const missingPerm = _package.name ?? _package.name.indexOf('@') === 0 ? 'package-scope' : 'package-name';
205+
return cb(getForbidden(`must have required permissions: ${this.publishLevel || ''} at ${missingPerm}`));
202206
}
203207
}
204208

@@ -227,7 +231,7 @@ export default class VerdaccioGitLab implements IPluginAuth {
227231
return false;
228232
}
229233

230-
_getCachedUserGroups(username: string, password: string): ?UserDataGroups {
234+
_getCachedUserGroups(username: string, password: string): UserDataGroups | null {
231235
if (!this.authCache) {
232236
return null;
233237
}

src/index.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
// Copyright 2018 Roger Meier <[email protected]>
22
// SPDX-License-Identifier: MIT
3-
// @flow
43

54
import VerdaccioGitLab from './gitlab';
6-
import type { PluginOptions } from '@verdaccio/types';
7-
import type { VerdaccioGitlabConfig } from './gitlab';
5+
import { PluginOptions } from '@verdaccio/types';
6+
import { VerdaccioGitlabConfig } from './gitlab';
87

9-
export default function(config: VerdaccioGitlabConfig, options: PluginOptions) {
8+
export default function(config: VerdaccioGitlabConfig, options: PluginOptions<VerdaccioGitlabConfig>) {
109
return new VerdaccioGitLab(config, options);
1110
}

0 commit comments

Comments
 (0)