@cicctencent/midwayjs-base 1.0.35 → 1.0.37
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/README.md +347 -1
- package/dist/config/config.default.d.ts +2 -2
- package/dist/config/config.default.js +33 -57
- package/dist/config/env.js +6 -9
- package/dist/configuration.js +26 -38
- package/dist/filter/default.filter.js +5 -9
- package/dist/filter/notfound.filter.js +5 -10
- package/dist/guard/api.d.ts +0 -3
- package/dist/guard/api.js +12 -29
- package/dist/guard/auth.d.ts +0 -3
- package/dist/guard/auth.js +34 -57
- package/dist/index.js +19 -39
- package/dist/lib/decorator.d.ts +3 -33
- package/dist/lib/decorator.js +15 -57
- package/dist/lib/jwt.d.ts +3 -104
- package/dist/lib/jwt.js +8 -24
- package/dist/lib/request.d.ts +0 -5
- package/dist/lib/request.js +3 -7
- package/dist/lib/utils.d.ts +1 -7
- package/dist/lib/utils.js +10 -42
- package/dist/middleware/apiResultFormatter.d.ts +4 -5
- package/dist/middleware/apiResultFormatter.js +26 -30
- package/dist/middleware/detect.middleware.d.ts +3 -4
- package/dist/middleware/detect.middleware.js +14 -20
- package/dist/middleware/requestInit.d.ts +4 -5
- package/dist/middleware/requestInit.js +54 -54
- package/dist/service/session.service.d.ts +1 -25
- package/dist/service/session.service.js +16 -44
- package/dist/service/tencent.service.d.ts +5 -13
- package/dist/service/tencent.service.js +35 -44
- package/dist/types/base.controller.js +5 -12
- package/dist/types/base.model.service.d.ts +1 -9
- package/dist/types/base.model.service.js +5 -19
- package/dist/types/base.service.d.ts +1 -10
- package/dist/types/base.service.js +16 -39
- package/dist/types/session.service.interface.d.ts +1 -15
- package/dist/types/session.service.interface.js +8 -16
- package/package.json +13 -1
|
@@ -1,24 +1,20 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
6
|
};
|
|
8
|
-
|
|
9
|
-
exports.DefaultErrorFilter = void 0;
|
|
10
|
-
const core_1 = require("@midwayjs/core");
|
|
7
|
+
import { Catch } from '@midwayjs/core';
|
|
11
8
|
let DefaultErrorFilter = class DefaultErrorFilter {
|
|
12
9
|
async catch(err, ctx) {
|
|
13
|
-
// 所有的未分类错误会到这里
|
|
14
10
|
return {
|
|
15
11
|
success: false,
|
|
16
12
|
message: err.message,
|
|
17
13
|
};
|
|
18
14
|
}
|
|
19
15
|
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
(0, core_1.Catch)()
|
|
16
|
+
DefaultErrorFilter = __decorate([
|
|
17
|
+
Catch()
|
|
23
18
|
], DefaultErrorFilter);
|
|
24
|
-
|
|
19
|
+
export { DefaultErrorFilter };
|
|
20
|
+
//# sourceMappingURL=default.filter.js.map
|
|
@@ -1,22 +1,17 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
6
|
};
|
|
8
|
-
|
|
9
|
-
exports.NotFoundFilter = void 0;
|
|
10
|
-
// @ts-ignore
|
|
11
|
-
const core_1 = require("@midwayjs/core");
|
|
7
|
+
import { Catch, httpError } from '@midwayjs/core';
|
|
12
8
|
let NotFoundFilter = class NotFoundFilter {
|
|
13
9
|
async catch(err, ctx) {
|
|
14
|
-
// 404 错误会到这里
|
|
15
10
|
ctx.redirect('/404.html');
|
|
16
11
|
}
|
|
17
12
|
};
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
(0, core_1.Catch)(core_1.httpError.NotFoundError)
|
|
13
|
+
NotFoundFilter = __decorate([
|
|
14
|
+
Catch(httpError.NotFoundError)
|
|
21
15
|
], NotFoundFilter);
|
|
22
|
-
|
|
16
|
+
export { NotFoundFilter };
|
|
17
|
+
//# sourceMappingURL=notfound.filter.js.map
|
package/dist/guard/api.d.ts
CHANGED
package/dist/guard/api.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -8,34 +7,21 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const core_1 = require("@midwayjs/core");
|
|
15
|
-
const decorator_1 = require("../lib/decorator");
|
|
16
|
-
const api_1 = require("@fefeding/common/dist/utils/api");
|
|
17
|
-
/**
|
|
18
|
-
* 对于需要token的接口,从query或body或cookie中取token,是否跟本服务的一致
|
|
19
|
-
*/
|
|
10
|
+
import { Guard, Config } from '@midwayjs/core';
|
|
11
|
+
import { getApiToken, getCheckIP } from '../lib/decorator';
|
|
12
|
+
import api from '@fefeding/common/dist/utils/api';
|
|
20
13
|
let ApiGuard = class ApiGuard {
|
|
21
|
-
// 登陆态验证配置
|
|
22
|
-
apiOption;
|
|
23
|
-
ipOption;
|
|
24
14
|
async canActivate(context, supplierClz, methodName) {
|
|
25
|
-
|
|
26
|
-
const needIP = (0, decorator_1.getCheckIP)(supplierClz, methodName);
|
|
15
|
+
const needIP = getCheckIP(supplierClz, methodName);
|
|
27
16
|
if (needIP) {
|
|
28
|
-
//console.log('check ip ', needIP);
|
|
29
17
|
this.checkIPInWhiteList(context);
|
|
30
18
|
}
|
|
31
|
-
|
|
32
|
-
const needToken = (0, decorator_1.getApiToken)(supplierClz, methodName);
|
|
19
|
+
const needToken = getApiToken(supplierClz, methodName);
|
|
33
20
|
if (needToken) {
|
|
34
21
|
await this.checkApiToken(context);
|
|
35
22
|
}
|
|
36
23
|
return true;
|
|
37
24
|
}
|
|
38
|
-
// 校验是否有带api token
|
|
39
25
|
async checkApiToken(context) {
|
|
40
26
|
const body = (context.request.body || {});
|
|
41
27
|
const reqToken = context.URL.searchParams.get('api_token') ||
|
|
@@ -50,19 +36,16 @@ let ApiGuard = class ApiGuard {
|
|
|
50
36
|
context.logger.error(`token为空,非法请求, token: ${reqToken}, timestamp: ${timestamp}`);
|
|
51
37
|
throw Error('token为空,非法请求');
|
|
52
38
|
}
|
|
53
|
-
//const time = new Date(timestamp);
|
|
54
39
|
console.log('token time', reqToken, timestamp);
|
|
55
|
-
// 如果超过一定时间,则失效
|
|
56
40
|
if (timestamp < Date.now() - 5 * 60 * 1000) {
|
|
57
41
|
throw Error('timestamp已超过有效时间');
|
|
58
42
|
}
|
|
59
|
-
const thisToken =
|
|
43
|
+
const thisToken = api.createApiToken(this.apiOption.key, timestamp);
|
|
60
44
|
if (reqToken !== thisToken.sign) {
|
|
61
45
|
context.logger.error(`输入token:${reqToken} 本地: ${thisToken.sign} 不一致`);
|
|
62
46
|
throw Error('token输入错误');
|
|
63
47
|
}
|
|
64
48
|
}
|
|
65
|
-
// 检查IP白名单
|
|
66
49
|
checkIPInWhiteList(context) {
|
|
67
50
|
const requestIp = context.detect?.REQUESTIP;
|
|
68
51
|
if (this.ipOption?.whiteList && !this.ipOption.whiteList.includes('*')) {
|
|
@@ -73,16 +56,16 @@ let ApiGuard = class ApiGuard {
|
|
|
73
56
|
}
|
|
74
57
|
}
|
|
75
58
|
};
|
|
76
|
-
exports.ApiGuard = ApiGuard;
|
|
77
59
|
__decorate([
|
|
78
|
-
|
|
60
|
+
Config('apiOption'),
|
|
79
61
|
__metadata("design:type", Object)
|
|
80
62
|
], ApiGuard.prototype, "apiOption", void 0);
|
|
81
63
|
__decorate([
|
|
82
|
-
|
|
64
|
+
Config('ipOption'),
|
|
83
65
|
__metadata("design:type", Object)
|
|
84
66
|
], ApiGuard.prototype, "ipOption", void 0);
|
|
85
|
-
|
|
86
|
-
|
|
67
|
+
ApiGuard = __decorate([
|
|
68
|
+
Guard()
|
|
87
69
|
], ApiGuard);
|
|
88
|
-
|
|
70
|
+
export { ApiGuard };
|
|
71
|
+
//# sourceMappingURL=api.js.map
|
package/dist/guard/auth.d.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { IGuard } from '@midwayjs/core';
|
|
2
2
|
import { Application, Context } from '@midwayjs/koa';
|
|
3
3
|
import { ISessionService } from '../types/session.service.interface';
|
|
4
|
-
/**
|
|
5
|
-
* 校验请求的登陆态
|
|
6
|
-
*/
|
|
7
4
|
export declare class AuthGuard implements IGuard<Context> {
|
|
8
5
|
protected app: Application;
|
|
9
6
|
sessionService: ISessionService;
|
package/dist/guard/auth.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -8,30 +7,18 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const decorator_1 = require("../lib/decorator");
|
|
16
|
-
const utils_1 = require("../lib/utils");
|
|
17
|
-
const session_service_interface_1 = require("../types/session.service.interface");
|
|
18
|
-
/**
|
|
19
|
-
* 校验请求的登陆态
|
|
20
|
-
*/
|
|
10
|
+
import { App, Config, Guard, Init } from '@midwayjs/core';
|
|
11
|
+
import { getCheckLogin } from '../lib/decorator';
|
|
12
|
+
import { getAuthToken, setAuthToken, decodeJWT } from '../lib/utils';
|
|
13
|
+
import { DEFAULT_SESSION_SERVICE_KEY, } from '../types/session.service.interface';
|
|
21
14
|
let AuthGuard = class AuthGuard {
|
|
22
|
-
app;
|
|
23
|
-
sessionService;
|
|
24
|
-
ssoOption;
|
|
25
|
-
authOption;
|
|
26
|
-
apiOption;
|
|
27
|
-
koa;
|
|
28
15
|
async init() {
|
|
29
16
|
const appContext = this.app.getApplicationContext();
|
|
30
17
|
console.log('init auth guard');
|
|
31
|
-
|
|
32
|
-
this.sessionService
|
|
33
|
-
|
|
34
|
-
|
|
18
|
+
this.sessionService = await appContext.getAsync(DEFAULT_SESSION_SERVICE_KEY);
|
|
19
|
+
if (this.sessionService?.sessionOption?.serviceKey &&
|
|
20
|
+
this.sessionService?.sessionOption.serviceKey !==
|
|
21
|
+
DEFAULT_SESSION_SERVICE_KEY) {
|
|
35
22
|
const sessionServiceObj = await appContext.getAsync(this.sessionService.sessionOption.serviceKey);
|
|
36
23
|
if (sessionServiceObj) {
|
|
37
24
|
console.log('use custom session service for auth guard', this.sessionService.sessionOption.serviceKey);
|
|
@@ -39,11 +26,10 @@ let AuthGuard = class AuthGuard {
|
|
|
39
26
|
}
|
|
40
27
|
}
|
|
41
28
|
}
|
|
42
|
-
// 检查是否需要验证登陆态
|
|
43
29
|
checkNeedAuth(context, supplierClz, methodName) {
|
|
44
|
-
// 如果有配置忽略验证,则直接返回false
|
|
45
30
|
if (this.authOption?.ignores) {
|
|
46
|
-
if (this.authOption.ignores === '*' ||
|
|
31
|
+
if (this.authOption.ignores === '*' ||
|
|
32
|
+
this.authOption.ignores === context.path) {
|
|
47
33
|
return false;
|
|
48
34
|
}
|
|
49
35
|
if (Array.isArray(this.authOption.ignores)) {
|
|
@@ -61,52 +47,47 @@ let AuthGuard = class AuthGuard {
|
|
|
61
47
|
}
|
|
62
48
|
}
|
|
63
49
|
}
|
|
64
|
-
|
|
65
|
-
const needAuth = (0, decorator_1.getCheckLogin)(supplierClz, methodName);
|
|
50
|
+
const needAuth = getCheckLogin(supplierClz, methodName);
|
|
66
51
|
return needAuth;
|
|
67
52
|
}
|
|
68
53
|
async canActivate(context, supplierClz, methodName) {
|
|
69
|
-
// 获取是否需要检查登陆态
|
|
70
54
|
const needAuth = this.checkNeedAuth(context, supplierClz, methodName);
|
|
71
|
-
const token =
|
|
55
|
+
const token = getAuthToken(context);
|
|
72
56
|
if (token)
|
|
73
57
|
context.auth_token = token;
|
|
74
58
|
const ret = await this.checkAuth(context, token, needAuth);
|
|
75
59
|
return ret;
|
|
76
60
|
}
|
|
77
|
-
// 校验是否有带api token
|
|
78
61
|
async checkAuth(context, token, needAuth) {
|
|
79
62
|
this.sessionService.ctx = context;
|
|
80
63
|
const authRet = 50001;
|
|
81
|
-
//console.log('check auth', token, needAuth);
|
|
82
64
|
let errRes = null;
|
|
83
65
|
try {
|
|
84
66
|
let session = null;
|
|
85
|
-
// 如果是从登陆回来,则验证监时码
|
|
86
67
|
const authCode = context.URL.searchParams.get('auth_code');
|
|
87
68
|
if (authCode) {
|
|
88
69
|
session = await this.sessionService.loginByCode(authCode);
|
|
89
70
|
if (session) {
|
|
90
|
-
|
|
91
|
-
(0, utils_1.setAuthToken)(context, session.id);
|
|
71
|
+
setAuthToken(context, session.id);
|
|
92
72
|
}
|
|
93
|
-
context.URL.searchParams.delete('auth_code');
|
|
73
|
+
context.URL.searchParams.delete('auth_code');
|
|
94
74
|
context.URL.hostname = context.detect?.HOSTNAME || context.hostname;
|
|
95
75
|
const url = context.URL.toString();
|
|
96
76
|
context.redirect(url);
|
|
97
77
|
return true;
|
|
98
78
|
}
|
|
99
79
|
if (token && !errRes && !session) {
|
|
100
|
-
// jwt签名
|
|
101
80
|
if (token.startsWith('Bearer ')) {
|
|
102
|
-
|
|
81
|
+
const jwtData = decodeJWT(token.replace('Bearer ', ''), this.sessionService?.sessionOption?.secretKey || 'fefeding');
|
|
82
|
+
if (jwtData) {
|
|
83
|
+
session = jwtData;
|
|
84
|
+
}
|
|
103
85
|
}
|
|
104
86
|
else {
|
|
105
87
|
session = await this.sessionService.getLoginSession(token);
|
|
106
88
|
}
|
|
107
89
|
if (!session || !session.id) {
|
|
108
|
-
|
|
109
|
-
//context.status = 403;
|
|
90
|
+
setAuthToken(context, '');
|
|
110
91
|
errRes = {
|
|
111
92
|
ret: authRet,
|
|
112
93
|
msg: 'token不存在或已过期',
|
|
@@ -119,11 +100,8 @@ let AuthGuard = class AuthGuard {
|
|
|
119
100
|
msg: '需要登陆态',
|
|
120
101
|
};
|
|
121
102
|
}
|
|
122
|
-
// 登陆态挂载到当前上下文
|
|
123
103
|
context.currentSession = session;
|
|
124
|
-
// @ts-ignore 登陆态挂载到logger
|
|
125
104
|
if (session && context.logger?.setOptions) {
|
|
126
|
-
// @ts-ignore
|
|
127
105
|
context.logger.setOptions({
|
|
128
106
|
loginId: session?.loginId || '',
|
|
129
107
|
userId: (session?.userId || '').toString(),
|
|
@@ -132,8 +110,8 @@ let AuthGuard = class AuthGuard {
|
|
|
132
110
|
}
|
|
133
111
|
catch (e) {
|
|
134
112
|
errRes = {
|
|
135
|
-
ret: e
|
|
136
|
-
msg: e
|
|
113
|
+
ret: e?.ret || authRet,
|
|
114
|
+
msg: e?.msg || e?.message || 'auth error',
|
|
137
115
|
};
|
|
138
116
|
console.error(e);
|
|
139
117
|
}
|
|
@@ -142,7 +120,6 @@ let AuthGuard = class AuthGuard {
|
|
|
142
120
|
}
|
|
143
121
|
return true;
|
|
144
122
|
}
|
|
145
|
-
// 异常处理
|
|
146
123
|
authError(context, error) {
|
|
147
124
|
const isApi = this.apiOption?.reg?.test(context.path);
|
|
148
125
|
if (isApi) {
|
|
@@ -152,14 +129,14 @@ let AuthGuard = class AuthGuard {
|
|
|
152
129
|
}
|
|
153
130
|
else {
|
|
154
131
|
const loginUrl = `${this.ssoOption?.baseUrl || this.koa?.globalPrefix || ''}/login`;
|
|
155
|
-
// 如果本来就以/login结尾,则直跳
|
|
156
132
|
if (!/\/login\/?(\?|$|#)/.test(context.URL.pathname)) {
|
|
157
133
|
const URL = context.URL;
|
|
158
|
-
if (context.detect?.HOSTNAME &&
|
|
134
|
+
if (context.detect?.HOSTNAME &&
|
|
135
|
+
URL.hostname !== context.detect?.HOSTNAME)
|
|
159
136
|
URL.hostname = context.detect.HOSTNAME;
|
|
160
137
|
URL.searchParams.delete('jv_auth_code');
|
|
161
138
|
URL.searchParams.delete('token');
|
|
162
|
-
URL.searchParams.delete('auth_code');
|
|
139
|
+
URL.searchParams.delete('auth_code');
|
|
163
140
|
const redirectUrl = context.URL.toString();
|
|
164
141
|
context.redirect(`${loginUrl}?url=${encodeURIComponent(redirectUrl)}&appid=${this.ssoOption?.appId || 0}`);
|
|
165
142
|
}
|
|
@@ -169,34 +146,34 @@ let AuthGuard = class AuthGuard {
|
|
|
169
146
|
}
|
|
170
147
|
}
|
|
171
148
|
};
|
|
172
|
-
exports.AuthGuard = AuthGuard;
|
|
173
149
|
__decorate([
|
|
174
|
-
|
|
150
|
+
App(),
|
|
175
151
|
__metadata("design:type", Object)
|
|
176
152
|
], AuthGuard.prototype, "app", void 0);
|
|
177
153
|
__decorate([
|
|
178
|
-
|
|
154
|
+
Config('sso'),
|
|
179
155
|
__metadata("design:type", Object)
|
|
180
156
|
], AuthGuard.prototype, "ssoOption", void 0);
|
|
181
157
|
__decorate([
|
|
182
|
-
|
|
158
|
+
Config('auth'),
|
|
183
159
|
__metadata("design:type", Object)
|
|
184
160
|
], AuthGuard.prototype, "authOption", void 0);
|
|
185
161
|
__decorate([
|
|
186
|
-
|
|
162
|
+
Config('apiOption'),
|
|
187
163
|
__metadata("design:type", Object)
|
|
188
164
|
], AuthGuard.prototype, "apiOption", void 0);
|
|
189
165
|
__decorate([
|
|
190
|
-
|
|
166
|
+
Config('koa'),
|
|
191
167
|
__metadata("design:type", Object)
|
|
192
168
|
], AuthGuard.prototype, "koa", void 0);
|
|
193
169
|
__decorate([
|
|
194
|
-
|
|
170
|
+
Init(),
|
|
195
171
|
__metadata("design:type", Function),
|
|
196
172
|
__metadata("design:paramtypes", []),
|
|
197
173
|
__metadata("design:returntype", Promise)
|
|
198
174
|
], AuthGuard.prototype, "init", null);
|
|
199
|
-
|
|
200
|
-
|
|
175
|
+
AuthGuard = __decorate([
|
|
176
|
+
Guard()
|
|
201
177
|
], AuthGuard);
|
|
202
|
-
|
|
178
|
+
export { AuthGuard };
|
|
179
|
+
//# sourceMappingURL=auth.js.map
|
package/dist/index.js
CHANGED
|
@@ -1,39 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
var configuration_1 = require("./configuration");
|
|
21
|
-
Object.defineProperty(exports, "Configuration", { enumerable: true, get: function () { return configuration_1.BaseConfiguration; } });
|
|
22
|
-
exports.utils = require("./lib/utils");
|
|
23
|
-
exports.jwt = require("./lib/jwt");
|
|
24
|
-
exports.decorators = require("./lib/decorator");
|
|
25
|
-
__exportStar(require("@fefeding/common/dist/models/base/enumType"), exports);
|
|
26
|
-
var baseORM_1 = require("@fefeding/common/dist/models/base/baseORM");
|
|
27
|
-
Object.defineProperty(exports, "BaseEntity", { enumerable: true, get: function () { return baseORM_1.BaseORM; } });
|
|
28
|
-
__exportStar(require("./middleware/apiResultFormatter"), exports);
|
|
29
|
-
__exportStar(require("./middleware/requestInit"), exports);
|
|
30
|
-
__exportStar(require("./middleware/detect.middleware"), exports);
|
|
31
|
-
__exportStar(require("./guard/api"), exports);
|
|
32
|
-
__exportStar(require("./guard/auth"), exports);
|
|
33
|
-
__exportStar(require("./types/base.service"), exports);
|
|
34
|
-
__exportStar(require("./types/base.model.service"), exports);
|
|
35
|
-
__exportStar(require("./types/base.controller"), exports);
|
|
36
|
-
__exportStar(require("./types/session.service.interface"), exports);
|
|
37
|
-
__exportStar(require("./service/session.service"), exports);
|
|
38
|
-
__exportStar(require("./service/tencent.service"), exports);
|
|
39
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7QUFDQSxhQUFhO0FBQ2IsdUNBQXFDO0FBRXJDLGlEQUFxRTtBQUE1RCw4R0FBQSxpQkFBaUIsT0FBaUI7QUFFM0MsdUNBQXFDO0FBQ3JDLG1DQUFpQztBQUNqQyxnREFBOEM7QUFHOUMsNkVBQTJEO0FBQzNELHFFQUFrRjtBQUF6RSxxR0FBQSxPQUFPLE9BQWM7QUFHOUIsa0VBQWdEO0FBQ2hELDJEQUF5QztBQUN6QyxpRUFBK0M7QUFFL0MsOENBQTRCO0FBQzVCLCtDQUE2QjtBQUU3Qix1REFBcUM7QUFDckMsNkRBQTJDO0FBQzNDLDBEQUF3QztBQUN4QyxvRUFBa0Q7QUFFbEQsNERBQTBDO0FBQzFDLDREQUEwQyJ9
|
|
1
|
+
export * as koa from '@midwayjs/koa';
|
|
2
|
+
export { BaseConfiguration as Configuration } from './configuration';
|
|
3
|
+
export * as utils from './lib/utils';
|
|
4
|
+
export * as jwt from './lib/jwt';
|
|
5
|
+
export * as decorators from './lib/decorator';
|
|
6
|
+
export * from '@fefeding/common/dist/models/base/enumType';
|
|
7
|
+
export { BaseORM as BaseEntity } from '@fefeding/common/dist/models/base/baseORM';
|
|
8
|
+
export * from './middleware/apiResultFormatter';
|
|
9
|
+
export * from './middleware/requestInit';
|
|
10
|
+
export * from './middleware/detect.middleware';
|
|
11
|
+
export * from './guard/api';
|
|
12
|
+
export * from './guard/auth';
|
|
13
|
+
export * from './types/base.service';
|
|
14
|
+
export * from './types/base.model.service';
|
|
15
|
+
export * from './types/base.controller';
|
|
16
|
+
export * from './types/session.service.interface';
|
|
17
|
+
export * from './service/session.service';
|
|
18
|
+
export * from './service/tencent.service';
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
package/dist/lib/decorator.d.ts
CHANGED
|
@@ -1,36 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 判断是否校验token的api装饰器
|
|
3
|
-
* @param need 是否要
|
|
4
|
-
* @returns
|
|
5
|
-
*/
|
|
6
1
|
export declare function checkApiToken(need?: boolean): MethodDecorator;
|
|
7
|
-
|
|
8
|
-
* 获取装饰的是否需要toke验证
|
|
9
|
-
* @param target 对象
|
|
10
|
-
* @param propertyKey 属性或方法名
|
|
11
|
-
*/
|
|
12
|
-
export declare function getApiToken(target: any, propertyKey: any): any;
|
|
13
|
-
/**
|
|
14
|
-
* 判断是否校验登陆态
|
|
15
|
-
* @param need 是否要
|
|
16
|
-
* @returns
|
|
17
|
-
*/
|
|
2
|
+
export declare function getApiToken(target: any, propertyKey: string | symbol): any;
|
|
18
3
|
export declare function checkLogin(need?: boolean): MethodDecorator;
|
|
19
|
-
|
|
20
|
-
* 获取装饰的是否需要校验登陆态
|
|
21
|
-
* @param target 对象
|
|
22
|
-
* @param propertyKey 属性或方法名
|
|
23
|
-
*/
|
|
24
|
-
export declare function getCheckLogin(target: any, propertyKey: any): any;
|
|
25
|
-
/**
|
|
26
|
-
* 判断是否校验在IP白名单内
|
|
27
|
-
* @param need 是否要
|
|
28
|
-
* @returns
|
|
29
|
-
*/
|
|
4
|
+
export declare function getCheckLogin(target: any, propertyKey: string | symbol): any;
|
|
30
5
|
export declare function checkIP(need?: boolean): MethodDecorator;
|
|
31
|
-
|
|
32
|
-
* 获取装饰的是否需要校验IP白名单
|
|
33
|
-
* @param target 对象
|
|
34
|
-
* @param propertyKey 属性或方法名
|
|
35
|
-
*/
|
|
36
|
-
export declare function getCheckIP(target: any, propertyKey: any): any;
|
|
6
|
+
export declare function getCheckIP(target: any, propertyKey: string | symbol): any;
|
package/dist/lib/decorator.js
CHANGED
|
@@ -1,34 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.checkApiToken = checkApiToken;
|
|
4
|
-
exports.getApiToken = getApiToken;
|
|
5
|
-
exports.checkLogin = checkLogin;
|
|
6
|
-
exports.getCheckLogin = getCheckLogin;
|
|
7
|
-
exports.checkIP = checkIP;
|
|
8
|
-
exports.getCheckIP = getCheckIP;
|
|
9
|
-
// @ts-ignore
|
|
10
|
-
const core_1 = require("@midwayjs/core");
|
|
11
|
-
const decorator_1 = require("@fefeding/common/dist/utils/decorator");
|
|
1
|
+
import { savePropertyMetadata, getPropertyMetadata } from '@midwayjs/core';
|
|
2
|
+
import decorators from '@fefeding/common/dist/utils/decorator';
|
|
12
3
|
const CheckIPKey = 'decorator:CheckIPKey';
|
|
13
|
-
|
|
14
|
-
* 判断是否校验token的api装饰器
|
|
15
|
-
* @param need 是否要
|
|
16
|
-
* @returns
|
|
17
|
-
*/
|
|
18
|
-
function checkApiToken(need = true) {
|
|
4
|
+
export function checkApiToken(need = true) {
|
|
19
5
|
return (target, propertyKey) => {
|
|
20
|
-
|
|
21
|
-
(0, core_1.savePropertyMetadata)(decorator_1.default.apiTokenMetadataKey, need, target, propertyKey);
|
|
6
|
+
savePropertyMetadata(decorators.apiTokenMetadataKey, need, target, propertyKey);
|
|
22
7
|
};
|
|
23
8
|
}
|
|
24
|
-
|
|
25
|
-
* 获取装饰的是否需要toke验证
|
|
26
|
-
* @param target 对象
|
|
27
|
-
* @param propertyKey 属性或方法名
|
|
28
|
-
*/
|
|
29
|
-
function getApiToken(target, propertyKey) {
|
|
9
|
+
export function getApiToken(target, propertyKey) {
|
|
30
10
|
try {
|
|
31
|
-
const value =
|
|
11
|
+
const value = getPropertyMetadata(decorators.apiTokenMetadataKey, target, propertyKey);
|
|
32
12
|
return value;
|
|
33
13
|
}
|
|
34
14
|
catch (e) {
|
|
@@ -36,44 +16,22 @@ function getApiToken(target, propertyKey) {
|
|
|
36
16
|
return false;
|
|
37
17
|
}
|
|
38
18
|
}
|
|
39
|
-
|
|
40
|
-
* 判断是否校验登陆态
|
|
41
|
-
* @param need 是否要
|
|
42
|
-
* @returns
|
|
43
|
-
*/
|
|
44
|
-
function checkLogin(need = true) {
|
|
19
|
+
export function checkLogin(need = true) {
|
|
45
20
|
return (target, propertyKey) => {
|
|
46
|
-
|
|
47
|
-
(0, core_1.savePropertyMetadata)(decorator_1.default.apiAuthMetadataKey, need, target, propertyKey);
|
|
21
|
+
savePropertyMetadata(decorators.apiAuthMetadataKey, need, target, propertyKey);
|
|
48
22
|
};
|
|
49
23
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
* @param target 对象
|
|
53
|
-
* @param propertyKey 属性或方法名
|
|
54
|
-
*/
|
|
55
|
-
function getCheckLogin(target, propertyKey) {
|
|
56
|
-
const value = (0, core_1.getPropertyMetadata)(decorator_1.default.apiAuthMetadataKey, target, propertyKey);
|
|
24
|
+
export function getCheckLogin(target, propertyKey) {
|
|
25
|
+
const value = getPropertyMetadata(decorators.apiAuthMetadataKey, target, propertyKey);
|
|
57
26
|
return value;
|
|
58
27
|
}
|
|
59
|
-
|
|
60
|
-
* 判断是否校验在IP白名单内
|
|
61
|
-
* @param need 是否要
|
|
62
|
-
* @returns
|
|
63
|
-
*/
|
|
64
|
-
function checkIP(need = true) {
|
|
28
|
+
export function checkIP(need = true) {
|
|
65
29
|
return (target, propertyKey) => {
|
|
66
|
-
|
|
67
|
-
(0, core_1.savePropertyMetadata)(CheckIPKey, need, target, propertyKey);
|
|
30
|
+
savePropertyMetadata(CheckIPKey, need, target, propertyKey);
|
|
68
31
|
};
|
|
69
32
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
* @param target 对象
|
|
73
|
-
* @param propertyKey 属性或方法名
|
|
74
|
-
*/
|
|
75
|
-
function getCheckIP(target, propertyKey) {
|
|
76
|
-
const value = (0, core_1.getPropertyMetadata)(CheckIPKey, target, propertyKey);
|
|
33
|
+
export function getCheckIP(target, propertyKey) {
|
|
34
|
+
const value = getPropertyMetadata(CheckIPKey, target, propertyKey);
|
|
77
35
|
return value;
|
|
78
36
|
}
|
|
79
|
-
//# sourceMappingURL=
|
|
37
|
+
//# sourceMappingURL=decorator.js.map
|