@cicctencent/midwayjs-base 1.0.36 → 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/dist/{types/config → config}/config.default.js +3 -38
- package/dist/config/env.js +16 -0
- package/dist/configuration.js +67 -0
- package/dist/{types/filter → filter}/default.filter.js +4 -7
- package/dist/{types/filter → filter}/notfound.filter.js +4 -7
- package/dist/{types/guard → guard}/api.js +11 -17
- package/dist/{types/guard → guard}/auth.js +20 -23
- package/dist/index.js +19 -0
- package/dist/lib/decorator.js +37 -0
- package/dist/lib/jwt.js +22 -0
- package/dist/lib/request.js +3 -0
- package/dist/{types/lib → lib}/utils.js +7 -28
- package/dist/{types/middleware → middleware}/apiResultFormatter.js +7 -10
- package/dist/{types/middleware → middleware}/detect.middleware.js +4 -7
- package/dist/{types/middleware → middleware}/requestInit.js +10 -49
- package/dist/{types/service → service}/session.service.js +12 -15
- package/dist/{types/service → service}/tencent.service.js +14 -50
- package/dist/types/{types/base.controller.js → base.controller.js} +4 -8
- package/dist/types/{types/base.model.service.js → base.model.service.js} +4 -8
- package/dist/types/{types/base.service.js → base.service.js} +10 -17
- package/dist/types/{types/session.service.interface.js → session.service.interface.js} +7 -11
- package/package.json +10 -1
- package/dist/types/config/env.js +0 -52
- package/dist/types/configuration.js +0 -103
- package/dist/types/index.js +0 -60
- package/dist/types/lib/decorator.js +0 -48
- package/dist/types/lib/jwt.js +0 -59
- package/dist/types/lib/request.js +0 -7
- /package/dist/{types/config → config}/config.default.d.ts +0 -0
- /package/dist/{types/config → config}/env.d.ts +0 -0
- /package/dist/{types/configuration.d.ts → configuration.d.ts} +0 -0
- /package/dist/{types/filter → filter}/default.filter.d.ts +0 -0
- /package/dist/{types/filter → filter}/notfound.filter.d.ts +0 -0
- /package/dist/{types/guard → guard}/api.d.ts +0 -0
- /package/dist/{types/guard → guard}/auth.d.ts +0 -0
- /package/dist/{types/index.d.ts → index.d.ts} +0 -0
- /package/dist/{types/lib → lib}/decorator.d.ts +0 -0
- /package/dist/{types/lib → lib}/jwt.d.ts +0 -0
- /package/dist/{types/lib → lib}/request.d.ts +0 -0
- /package/dist/{types/lib → lib}/utils.d.ts +0 -0
- /package/dist/{types/middleware → middleware}/apiResultFormatter.d.ts +0 -0
- /package/dist/{types/middleware → middleware}/detect.middleware.d.ts +0 -0
- /package/dist/{types/middleware → middleware}/requestInit.d.ts +0 -0
- /package/dist/{types/service → service}/session.service.d.ts +0 -0
- /package/dist/{types/service → service}/tencent.service.d.ts +0 -0
- /package/dist/types/{types/base.controller.d.ts → base.controller.d.ts} +0 -0
- /package/dist/types/{types/base.model.service.d.ts → base.model.service.d.ts} +0 -0
- /package/dist/types/{types/base.service.d.ts → base.service.d.ts} +0 -0
- /package/dist/types/{types/session.service.interface.d.ts → session.service.interface.d.ts} +0 -0
|
@@ -1,41 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
const path = __importStar(require("path"));
|
|
37
|
-
const fs = __importStar(require("fs"));
|
|
38
|
-
exports.default = (appInfo) => {
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
export default (appInfo) => {
|
|
39
4
|
appInfo.appId = Number(process.env.APP_ID) || 0;
|
|
40
5
|
const appRoot = appInfo.appDir || appInfo.root;
|
|
41
6
|
appInfo.dist = path.join(appRoot, 'dist');
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as dotenv from 'dotenv';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import * as fs from 'fs';
|
|
4
|
+
export function loadEnv(envPath) {
|
|
5
|
+
envPath = envPath || path.join(process.cwd(), '.env');
|
|
6
|
+
console.log('env path', envPath);
|
|
7
|
+
if (fs.existsSync(envPath)) {
|
|
8
|
+
const env = dotenv.config({
|
|
9
|
+
path: envPath,
|
|
10
|
+
encoding: 'utf-8',
|
|
11
|
+
});
|
|
12
|
+
console.log(env);
|
|
13
|
+
}
|
|
14
|
+
return process.env;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=env.js.map
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
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;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { Configuration, App } from '@midwayjs/core';
|
|
11
|
+
import * as koa from '@midwayjs/koa';
|
|
12
|
+
import * as info from '@midwayjs/info';
|
|
13
|
+
import * as axios from '@midwayjs/axios';
|
|
14
|
+
import { ApiResultFormatterMiddleware } from './middleware/apiResultFormatter';
|
|
15
|
+
import { RequestInitMiddleware } from './middleware/requestInit';
|
|
16
|
+
import { DetectMiddleware } from './middleware/detect.middleware';
|
|
17
|
+
import * as view from '@midwayjs/view-nunjucks';
|
|
18
|
+
import * as staticFile from '@midwayjs/static-file';
|
|
19
|
+
import * as cacheManager from '@midwayjs/cache-manager';
|
|
20
|
+
import * as DefaultConfig from './config/config.default';
|
|
21
|
+
import { ApiGuard } from './guard/api';
|
|
22
|
+
import { AuthGuard } from './guard/auth';
|
|
23
|
+
import { loadEnv } from './config/env';
|
|
24
|
+
loadEnv();
|
|
25
|
+
let BaseConfiguration = class BaseConfiguration {
|
|
26
|
+
async onReady() {
|
|
27
|
+
if (process.env.FEFE_MIDWAYJS_BASE_READY === 'true') {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
process.env.SERVICE_NAME =
|
|
31
|
+
process.env.SERVICE_NAME || this.app.getProjectName();
|
|
32
|
+
this.app.useGuard([ApiGuard, AuthGuard]);
|
|
33
|
+
this.app.useMiddleware([
|
|
34
|
+
RequestInitMiddleware,
|
|
35
|
+
DetectMiddleware,
|
|
36
|
+
ApiResultFormatterMiddleware,
|
|
37
|
+
]);
|
|
38
|
+
process.env.FEFE_MIDWAYJS_BASE_READY = 'true';
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
__decorate([
|
|
42
|
+
App(),
|
|
43
|
+
__metadata("design:type", Object)
|
|
44
|
+
], BaseConfiguration.prototype, "app", void 0);
|
|
45
|
+
BaseConfiguration = __decorate([
|
|
46
|
+
Configuration({
|
|
47
|
+
namespace: 'MidwayjsBase',
|
|
48
|
+
imports: [
|
|
49
|
+
koa,
|
|
50
|
+
{
|
|
51
|
+
component: info,
|
|
52
|
+
enabledEnvironment: ['local'],
|
|
53
|
+
},
|
|
54
|
+
view,
|
|
55
|
+
staticFile,
|
|
56
|
+
axios,
|
|
57
|
+
cacheManager,
|
|
58
|
+
],
|
|
59
|
+
importConfigs: [
|
|
60
|
+
{
|
|
61
|
+
default: DefaultConfig,
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
})
|
|
65
|
+
], BaseConfiguration);
|
|
66
|
+
export { BaseConfiguration };
|
|
67
|
+
//# sourceMappingURL=configuration.js.map
|
|
@@ -1,13 +1,10 @@
|
|
|
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
10
|
return {
|
|
@@ -16,8 +13,8 @@ let DefaultErrorFilter = class DefaultErrorFilter {
|
|
|
16
13
|
};
|
|
17
14
|
}
|
|
18
15
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
(0, core_1.Catch)()
|
|
16
|
+
DefaultErrorFilter = __decorate([
|
|
17
|
+
Catch()
|
|
22
18
|
], DefaultErrorFilter);
|
|
19
|
+
export { DefaultErrorFilter };
|
|
23
20
|
//# sourceMappingURL=default.filter.js.map
|
|
@@ -1,20 +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
|
-
const core_1 = require("@midwayjs/core");
|
|
7
|
+
import { Catch, httpError } from '@midwayjs/core';
|
|
11
8
|
let NotFoundFilter = class NotFoundFilter {
|
|
12
9
|
async catch(err, ctx) {
|
|
13
10
|
ctx.redirect('/404.html');
|
|
14
11
|
}
|
|
15
12
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
(0, core_1.Catch)(core_1.httpError.NotFoundError)
|
|
13
|
+
NotFoundFilter = __decorate([
|
|
14
|
+
Catch(httpError.NotFoundError)
|
|
19
15
|
], NotFoundFilter);
|
|
16
|
+
export { NotFoundFilter };
|
|
20
17
|
//# sourceMappingURL=notfound.filter.js.map
|
|
@@ -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,21 +7,16 @@ 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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.ApiGuard = void 0;
|
|
16
|
-
const core_1 = require("@midwayjs/core");
|
|
17
|
-
const decorator_1 = require("../lib/decorator");
|
|
18
|
-
const api_1 = __importDefault(require("@fefeding/common/dist/utils/api"));
|
|
10
|
+
import { Guard, Config } from '@midwayjs/core';
|
|
11
|
+
import { getApiToken, getCheckIP } from '../lib/decorator';
|
|
12
|
+
import api from '@fefeding/common/dist/utils/api';
|
|
19
13
|
let ApiGuard = class ApiGuard {
|
|
20
14
|
async canActivate(context, supplierClz, methodName) {
|
|
21
|
-
const needIP =
|
|
15
|
+
const needIP = getCheckIP(supplierClz, methodName);
|
|
22
16
|
if (needIP) {
|
|
23
17
|
this.checkIPInWhiteList(context);
|
|
24
18
|
}
|
|
25
|
-
const needToken =
|
|
19
|
+
const needToken = getApiToken(supplierClz, methodName);
|
|
26
20
|
if (needToken) {
|
|
27
21
|
await this.checkApiToken(context);
|
|
28
22
|
}
|
|
@@ -46,7 +40,7 @@ let ApiGuard = class ApiGuard {
|
|
|
46
40
|
if (timestamp < Date.now() - 5 * 60 * 1000) {
|
|
47
41
|
throw Error('timestamp已超过有效时间');
|
|
48
42
|
}
|
|
49
|
-
const thisToken =
|
|
43
|
+
const thisToken = api.createApiToken(this.apiOption.key, timestamp);
|
|
50
44
|
if (reqToken !== thisToken.sign) {
|
|
51
45
|
context.logger.error(`输入token:${reqToken} 本地: ${thisToken.sign} 不一致`);
|
|
52
46
|
throw Error('token输入错误');
|
|
@@ -62,16 +56,16 @@ let ApiGuard = class ApiGuard {
|
|
|
62
56
|
}
|
|
63
57
|
}
|
|
64
58
|
};
|
|
65
|
-
exports.ApiGuard = ApiGuard;
|
|
66
59
|
__decorate([
|
|
67
|
-
|
|
60
|
+
Config('apiOption'),
|
|
68
61
|
__metadata("design:type", Object)
|
|
69
62
|
], ApiGuard.prototype, "apiOption", void 0);
|
|
70
63
|
__decorate([
|
|
71
|
-
|
|
64
|
+
Config('ipOption'),
|
|
72
65
|
__metadata("design:type", Object)
|
|
73
66
|
], ApiGuard.prototype, "ipOption", void 0);
|
|
74
|
-
|
|
75
|
-
|
|
67
|
+
ApiGuard = __decorate([
|
|
68
|
+
Guard()
|
|
76
69
|
], ApiGuard);
|
|
70
|
+
export { ApiGuard };
|
|
77
71
|
//# sourceMappingURL=api.js.map
|
|
@@ -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,20 +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 utils_1 = require("../lib/utils");
|
|
16
|
-
const session_service_interface_1 = require("../types/session.service.interface");
|
|
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';
|
|
17
14
|
let AuthGuard = class AuthGuard {
|
|
18
15
|
async init() {
|
|
19
16
|
const appContext = this.app.getApplicationContext();
|
|
20
17
|
console.log('init auth guard');
|
|
21
|
-
this.sessionService = await appContext.getAsync(
|
|
18
|
+
this.sessionService = await appContext.getAsync(DEFAULT_SESSION_SERVICE_KEY);
|
|
22
19
|
if (this.sessionService?.sessionOption?.serviceKey &&
|
|
23
20
|
this.sessionService?.sessionOption.serviceKey !==
|
|
24
|
-
|
|
21
|
+
DEFAULT_SESSION_SERVICE_KEY) {
|
|
25
22
|
const sessionServiceObj = await appContext.getAsync(this.sessionService.sessionOption.serviceKey);
|
|
26
23
|
if (sessionServiceObj) {
|
|
27
24
|
console.log('use custom session service for auth guard', this.sessionService.sessionOption.serviceKey);
|
|
@@ -50,12 +47,12 @@ let AuthGuard = class AuthGuard {
|
|
|
50
47
|
}
|
|
51
48
|
}
|
|
52
49
|
}
|
|
53
|
-
const needAuth =
|
|
50
|
+
const needAuth = getCheckLogin(supplierClz, methodName);
|
|
54
51
|
return needAuth;
|
|
55
52
|
}
|
|
56
53
|
async canActivate(context, supplierClz, methodName) {
|
|
57
54
|
const needAuth = this.checkNeedAuth(context, supplierClz, methodName);
|
|
58
|
-
const token =
|
|
55
|
+
const token = getAuthToken(context);
|
|
59
56
|
if (token)
|
|
60
57
|
context.auth_token = token;
|
|
61
58
|
const ret = await this.checkAuth(context, token, needAuth);
|
|
@@ -71,7 +68,7 @@ let AuthGuard = class AuthGuard {
|
|
|
71
68
|
if (authCode) {
|
|
72
69
|
session = await this.sessionService.loginByCode(authCode);
|
|
73
70
|
if (session) {
|
|
74
|
-
|
|
71
|
+
setAuthToken(context, session.id);
|
|
75
72
|
}
|
|
76
73
|
context.URL.searchParams.delete('auth_code');
|
|
77
74
|
context.URL.hostname = context.detect?.HOSTNAME || context.hostname;
|
|
@@ -81,7 +78,7 @@ let AuthGuard = class AuthGuard {
|
|
|
81
78
|
}
|
|
82
79
|
if (token && !errRes && !session) {
|
|
83
80
|
if (token.startsWith('Bearer ')) {
|
|
84
|
-
const jwtData =
|
|
81
|
+
const jwtData = decodeJWT(token.replace('Bearer ', ''), this.sessionService?.sessionOption?.secretKey || 'fefeding');
|
|
85
82
|
if (jwtData) {
|
|
86
83
|
session = jwtData;
|
|
87
84
|
}
|
|
@@ -90,7 +87,7 @@ let AuthGuard = class AuthGuard {
|
|
|
90
87
|
session = await this.sessionService.getLoginSession(token);
|
|
91
88
|
}
|
|
92
89
|
if (!session || !session.id) {
|
|
93
|
-
|
|
90
|
+
setAuthToken(context, '');
|
|
94
91
|
errRes = {
|
|
95
92
|
ret: authRet,
|
|
96
93
|
msg: 'token不存在或已过期',
|
|
@@ -149,34 +146,34 @@ let AuthGuard = class AuthGuard {
|
|
|
149
146
|
}
|
|
150
147
|
}
|
|
151
148
|
};
|
|
152
|
-
exports.AuthGuard = AuthGuard;
|
|
153
149
|
__decorate([
|
|
154
|
-
|
|
150
|
+
App(),
|
|
155
151
|
__metadata("design:type", Object)
|
|
156
152
|
], AuthGuard.prototype, "app", void 0);
|
|
157
153
|
__decorate([
|
|
158
|
-
|
|
154
|
+
Config('sso'),
|
|
159
155
|
__metadata("design:type", Object)
|
|
160
156
|
], AuthGuard.prototype, "ssoOption", void 0);
|
|
161
157
|
__decorate([
|
|
162
|
-
|
|
158
|
+
Config('auth'),
|
|
163
159
|
__metadata("design:type", Object)
|
|
164
160
|
], AuthGuard.prototype, "authOption", void 0);
|
|
165
161
|
__decorate([
|
|
166
|
-
|
|
162
|
+
Config('apiOption'),
|
|
167
163
|
__metadata("design:type", Object)
|
|
168
164
|
], AuthGuard.prototype, "apiOption", void 0);
|
|
169
165
|
__decorate([
|
|
170
|
-
|
|
166
|
+
Config('koa'),
|
|
171
167
|
__metadata("design:type", Object)
|
|
172
168
|
], AuthGuard.prototype, "koa", void 0);
|
|
173
169
|
__decorate([
|
|
174
|
-
|
|
170
|
+
Init(),
|
|
175
171
|
__metadata("design:type", Function),
|
|
176
172
|
__metadata("design:paramtypes", []),
|
|
177
173
|
__metadata("design:returntype", Promise)
|
|
178
174
|
], AuthGuard.prototype, "init", null);
|
|
179
|
-
|
|
180
|
-
|
|
175
|
+
AuthGuard = __decorate([
|
|
176
|
+
Guard()
|
|
181
177
|
], AuthGuard);
|
|
178
|
+
export { AuthGuard };
|
|
182
179
|
//# sourceMappingURL=auth.js.map
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
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
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { savePropertyMetadata, getPropertyMetadata } from '@midwayjs/core';
|
|
2
|
+
import decorators from '@fefeding/common/dist/utils/decorator';
|
|
3
|
+
const CheckIPKey = 'decorator:CheckIPKey';
|
|
4
|
+
export function checkApiToken(need = true) {
|
|
5
|
+
return (target, propertyKey) => {
|
|
6
|
+
savePropertyMetadata(decorators.apiTokenMetadataKey, need, target, propertyKey);
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export function getApiToken(target, propertyKey) {
|
|
10
|
+
try {
|
|
11
|
+
const value = getPropertyMetadata(decorators.apiTokenMetadataKey, target, propertyKey);
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
catch (e) {
|
|
15
|
+
console.log(e);
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export function checkLogin(need = true) {
|
|
20
|
+
return (target, propertyKey) => {
|
|
21
|
+
savePropertyMetadata(decorators.apiAuthMetadataKey, need, target, propertyKey);
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export function getCheckLogin(target, propertyKey) {
|
|
25
|
+
const value = getPropertyMetadata(decorators.apiAuthMetadataKey, target, propertyKey);
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
28
|
+
export function checkIP(need = true) {
|
|
29
|
+
return (target, propertyKey) => {
|
|
30
|
+
savePropertyMetadata(CheckIPKey, need, target, propertyKey);
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export function getCheckIP(target, propertyKey) {
|
|
34
|
+
const value = getPropertyMetadata(CheckIPKey, target, propertyKey);
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=decorator.js.map
|
package/dist/lib/jwt.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as jwt from 'jsonwebtoken';
|
|
2
|
+
export function decodeJWT(token, secretKey, options) {
|
|
3
|
+
try {
|
|
4
|
+
const decoded = jwt.verify(token, secretKey, {
|
|
5
|
+
algorithms: ['HS256'],
|
|
6
|
+
...(options || {}),
|
|
7
|
+
});
|
|
8
|
+
return decoded;
|
|
9
|
+
}
|
|
10
|
+
catch (err) {
|
|
11
|
+
console.error('Token 验证失败:', err?.message);
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export function encodeJWT(data, secretKey, options) {
|
|
16
|
+
const token = jwt.sign(data, secretKey, {
|
|
17
|
+
algorithm: 'HS256',
|
|
18
|
+
...(options || {}),
|
|
19
|
+
});
|
|
20
|
+
return token;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=jwt.js.map
|
|
@@ -1,28 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.loadEnv = void 0;
|
|
18
|
-
exports.checkUrlHost = checkUrlHost;
|
|
19
|
-
exports.getDefaultTemplate = getDefaultTemplate;
|
|
20
|
-
exports.getAuthToken = getAuthToken;
|
|
21
|
-
exports.setAuthToken = setAuthToken;
|
|
22
|
-
__exportStar(require("./jwt"), exports);
|
|
23
|
-
const env_1 = require("../config/env");
|
|
24
|
-
Object.defineProperty(exports, "loadEnv", { enumerable: true, get: function () { return env_1.loadEnv; } });
|
|
25
|
-
function checkUrlHost(url, host) {
|
|
1
|
+
export * from './jwt';
|
|
2
|
+
import { loadEnv } from '../config/env';
|
|
3
|
+
export function checkUrlHost(url, host) {
|
|
26
4
|
if (/^\/[^\/]{1,}/.test(url))
|
|
27
5
|
return true;
|
|
28
6
|
if (Array.isArray(host)) {
|
|
@@ -35,7 +13,7 @@ function checkUrlHost(url, host) {
|
|
|
35
13
|
const reg = new RegExp('^(http(s)?:)?//' + host);
|
|
36
14
|
return reg.test(url);
|
|
37
15
|
}
|
|
38
|
-
function getDefaultTemplate(ctx, file = 'index.html', data = {}) {
|
|
16
|
+
export function getDefaultTemplate(ctx, file = 'index.html', data = {}) {
|
|
39
17
|
const viteTarget = process.env.VITE_PORT;
|
|
40
18
|
const config = ctx.app.getConfig();
|
|
41
19
|
const prefix = config.koa.globalPrefix;
|
|
@@ -56,7 +34,7 @@ function getDefaultTemplate(ctx, file = 'index.html', data = {}) {
|
|
|
56
34
|
};
|
|
57
35
|
return ctx.render(file, option);
|
|
58
36
|
}
|
|
59
|
-
function getAuthToken(ctx, option) {
|
|
37
|
+
export function getAuthToken(ctx, option) {
|
|
60
38
|
const body = (ctx.request.body || {});
|
|
61
39
|
const token = ctx.URL.searchParams.get('token') ||
|
|
62
40
|
ctx.request.header['x-auth-token'] ||
|
|
@@ -68,11 +46,12 @@ function getAuthToken(ctx, option) {
|
|
|
68
46
|
body.token;
|
|
69
47
|
return token;
|
|
70
48
|
}
|
|
71
|
-
function setAuthToken(ctx, token, option) {
|
|
49
|
+
export function setAuthToken(ctx, token, option) {
|
|
72
50
|
ctx.cookies.set('token', token, {
|
|
73
51
|
httpOnly: true,
|
|
74
52
|
maxAge: 1000 * 60 * 60 * 24 * 30,
|
|
75
53
|
...(option || {}),
|
|
76
54
|
});
|
|
77
55
|
}
|
|
56
|
+
export { loadEnv };
|
|
78
57
|
//# sourceMappingURL=utils.js.map
|
|
@@ -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,10 +7,8 @@ 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
|
-
const core_1 = require("@midwayjs/core");
|
|
14
|
-
const stream_1 = require("stream");
|
|
10
|
+
import { Middleware, Config, } from '@midwayjs/core';
|
|
11
|
+
import { Stream } from 'stream';
|
|
15
12
|
let ApiResultFormatterMiddleware = class ApiResultFormatterMiddleware {
|
|
16
13
|
ignore(ctx) {
|
|
17
14
|
const koaCtx = ctx;
|
|
@@ -67,17 +64,17 @@ let ApiResultFormatterMiddleware = class ApiResultFormatterMiddleware {
|
|
|
67
64
|
canFormat(data) {
|
|
68
65
|
return (data !== '' &&
|
|
69
66
|
!Buffer.isBuffer(data) &&
|
|
70
|
-
!(data instanceof
|
|
67
|
+
!(data instanceof Stream ||
|
|
71
68
|
data instanceof Uint8Array ||
|
|
72
69
|
data instanceof Blob));
|
|
73
70
|
}
|
|
74
71
|
};
|
|
75
|
-
exports.ApiResultFormatterMiddleware = ApiResultFormatterMiddleware;
|
|
76
72
|
__decorate([
|
|
77
|
-
|
|
73
|
+
Config('apiOption'),
|
|
78
74
|
__metadata("design:type", Object)
|
|
79
75
|
], ApiResultFormatterMiddleware.prototype, "apiOption", void 0);
|
|
80
|
-
|
|
81
|
-
|
|
76
|
+
ApiResultFormatterMiddleware = __decorate([
|
|
77
|
+
Middleware()
|
|
82
78
|
], ApiResultFormatterMiddleware);
|
|
79
|
+
export { ApiResultFormatterMiddleware };
|
|
83
80
|
//# sourceMappingURL=apiResultFormatter.js.map
|
|
@@ -1,13 +1,10 @@
|
|
|
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.DetectMiddleware = void 0;
|
|
10
|
-
const core_1 = require("@midwayjs/core");
|
|
7
|
+
import { Middleware } from '@midwayjs/core';
|
|
11
8
|
let DetectMiddleware = class DetectMiddleware {
|
|
12
9
|
resolve() {
|
|
13
10
|
return async (ctx, next) => {
|
|
@@ -51,8 +48,8 @@ let DetectMiddleware = class DetectMiddleware {
|
|
|
51
48
|
};
|
|
52
49
|
}
|
|
53
50
|
};
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
(0, core_1.Middleware)()
|
|
51
|
+
DetectMiddleware = __decorate([
|
|
52
|
+
Middleware()
|
|
57
53
|
], DetectMiddleware);
|
|
54
|
+
export { DetectMiddleware };
|
|
58
55
|
//# sourceMappingURL=detect.middleware.js.map
|