@xlt-token/nestjs 1.0.0-rc.3
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/LICENSE +21 -0
- package/README.md +29 -0
- package/dist/index.cjs +687 -0
- package/dist/index.d.cts +233 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +233 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +525 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +90 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,525 @@
|
|
|
1
|
+
import { ForbiddenException, Inject, Injectable, Module, Optional, SetMetadata, UnauthorizedException, createParamDecorator } from "@nestjs/common";
|
|
2
|
+
import { DEFAULT_XLT_TOKEN_CONFIG, DEFAULT_XLT_TOKEN_CONFIG as DEFAULT_XLT_TOKEN_CONFIG$1, MemoryStore, MemoryStore as MemoryStore$1, NotLoginException as NotLoginException$1, NotLoginType, NotLoginType as NotLoginType$1, NotPermissionException as NotPermissionException$1, NotRoleException as NotRoleException$1, NotSafeException as NotSafeException$1, StpLogic, StpLogic as StpLogic$1, StpPermLogic, StpPermLogic as StpPermLogic$1, StpUtil, UuidStrategy, UuidStrategy as UuidStrategy$1, XLT_CHECK_LOGIN_KEY, XLT_IGNORE_KEY, XLT_PERMISSION_KEY, XLT_ROLE_KEY, XLT_STP_INTERFACE, XLT_STP_INTERFACE as XLT_STP_INTERFACE$1, XLT_TOKEN_CONFIG, XLT_TOKEN_CONFIG as XLT_TOKEN_CONFIG$1, XLT_TOKEN_HOOKS, XLT_TOKEN_HOOKS as XLT_TOKEN_HOOKS$1, XLT_TOKEN_STORE, XLT_TOKEN_STORE as XLT_TOKEN_STORE$1, XLT_TOKEN_STRATEGY, XLT_TOKEN_STRATEGY as XLT_TOKEN_STRATEGY$1, XltMode, XltMode as XltMode$1, XltSession, XltTokenConfig, createExpressContext, createExpressContext as createExpressContext$1, createMockHttpContext, createXltToken, matchPermission, setStpLogic, setStpLogic as setStpLogic$1, setStpPermLogic, setStpPermLogic as setStpPermLogic$1 } from "@xlt-token/core";
|
|
3
|
+
import { sign, verify } from "jsonwebtoken";
|
|
4
|
+
import { Reflector } from "@nestjs/core";
|
|
5
|
+
|
|
6
|
+
//#region \0@oxc-project+runtime@0.112.0/helpers/decorate.js
|
|
7
|
+
function __decorate(decorators, target, key, desc) {
|
|
8
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
10
|
+
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;
|
|
11
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/xlt-token.module.ts
|
|
16
|
+
var _XltTokenModule;
|
|
17
|
+
let XltTokenModule = class XltTokenModule {
|
|
18
|
+
static {
|
|
19
|
+
_XltTokenModule = this;
|
|
20
|
+
}
|
|
21
|
+
static createStoreProvider(store) {
|
|
22
|
+
if (!store) return {
|
|
23
|
+
provide: XLT_TOKEN_STORE$1,
|
|
24
|
+
useClass: MemoryStore$1
|
|
25
|
+
};
|
|
26
|
+
return "useClass" in store ? {
|
|
27
|
+
provide: XLT_TOKEN_STORE$1,
|
|
28
|
+
useClass: store.useClass
|
|
29
|
+
} : {
|
|
30
|
+
provide: XLT_TOKEN_STORE$1,
|
|
31
|
+
useValue: store.useValue
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
static createStrategyProvider(strategy) {
|
|
35
|
+
return strategy?.useClass ? {
|
|
36
|
+
provide: XLT_TOKEN_STRATEGY$1,
|
|
37
|
+
useClass: strategy.useClass
|
|
38
|
+
} : {
|
|
39
|
+
provide: XLT_TOKEN_STRATEGY$1,
|
|
40
|
+
useClass: UuidStrategy$1
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
static createStpInterfaceProvider(stpInterface) {
|
|
44
|
+
if (stpInterface) return {
|
|
45
|
+
provide: XLT_STP_INTERFACE$1,
|
|
46
|
+
useClass: stpInterface
|
|
47
|
+
};
|
|
48
|
+
return {
|
|
49
|
+
provide: XLT_STP_INTERFACE$1,
|
|
50
|
+
useValue: {
|
|
51
|
+
getPermissionList: () => {
|
|
52
|
+
throw new Error("StpInterface not registered: getPermissionList");
|
|
53
|
+
},
|
|
54
|
+
getRoleList: () => {
|
|
55
|
+
throw new Error("StpInterface not registered: getRoleList");
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
static createHooksProvider(hooks) {
|
|
61
|
+
return {
|
|
62
|
+
provide: XLT_TOKEN_HOOKS$1,
|
|
63
|
+
useValue: hooks ?? {}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
static {
|
|
67
|
+
this.stpLogicProvider = {
|
|
68
|
+
provide: StpLogic$1,
|
|
69
|
+
useFactory: (config, store, strategy, hooks) => new StpLogic$1(config, store, strategy, hooks),
|
|
70
|
+
inject: [
|
|
71
|
+
XLT_TOKEN_CONFIG$1,
|
|
72
|
+
XLT_TOKEN_STORE$1,
|
|
73
|
+
XLT_TOKEN_STRATEGY$1,
|
|
74
|
+
XLT_TOKEN_HOOKS$1
|
|
75
|
+
]
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
static {
|
|
79
|
+
this.stpPermLogicProvider = {
|
|
80
|
+
provide: StpPermLogic$1,
|
|
81
|
+
useFactory: (stpInterface, store, config) => new StpPermLogic$1(stpInterface, store, config),
|
|
82
|
+
inject: [
|
|
83
|
+
XLT_STP_INTERFACE$1,
|
|
84
|
+
XLT_TOKEN_STORE$1,
|
|
85
|
+
XLT_TOKEN_CONFIG$1
|
|
86
|
+
]
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
static {
|
|
90
|
+
this.initProvider = {
|
|
91
|
+
provide: "XLT_TOKEN_INIT",
|
|
92
|
+
useFactory: (stpLogic, stpPermLogic) => {
|
|
93
|
+
setStpLogic$1(stpLogic);
|
|
94
|
+
setStpPermLogic$1(stpPermLogic);
|
|
95
|
+
return true;
|
|
96
|
+
},
|
|
97
|
+
inject: [StpLogic$1, StpPermLogic$1]
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
static {
|
|
101
|
+
this.moduleExports = [
|
|
102
|
+
XLT_TOKEN_CONFIG$1,
|
|
103
|
+
XLT_TOKEN_STORE$1,
|
|
104
|
+
XLT_TOKEN_STRATEGY$1,
|
|
105
|
+
StpLogic$1,
|
|
106
|
+
StpPermLogic$1
|
|
107
|
+
];
|
|
108
|
+
}
|
|
109
|
+
static forRoot(options = {}) {
|
|
110
|
+
const { config: userConfig, store, strategy, isGlobal = false, providers = [], stpInterface } = options;
|
|
111
|
+
return {
|
|
112
|
+
module: _XltTokenModule,
|
|
113
|
+
providers: [
|
|
114
|
+
{
|
|
115
|
+
provide: XLT_TOKEN_CONFIG$1,
|
|
116
|
+
useValue: {
|
|
117
|
+
...DEFAULT_XLT_TOKEN_CONFIG$1,
|
|
118
|
+
...userConfig
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
_XltTokenModule.createStoreProvider(store),
|
|
122
|
+
_XltTokenModule.createStrategyProvider(strategy),
|
|
123
|
+
_XltTokenModule.createStpInterfaceProvider(stpInterface),
|
|
124
|
+
_XltTokenModule.createHooksProvider(options.hooks),
|
|
125
|
+
_XltTokenModule.stpLogicProvider,
|
|
126
|
+
_XltTokenModule.stpPermLogicProvider,
|
|
127
|
+
_XltTokenModule.initProvider,
|
|
128
|
+
...providers
|
|
129
|
+
],
|
|
130
|
+
exports: _XltTokenModule.moduleExports,
|
|
131
|
+
global: isGlobal
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
static forRootAsync(options) {
|
|
135
|
+
const { useFactory, inject = [], imports = [], store, strategy, isGlobal = false, providers = [], stpInterface } = options;
|
|
136
|
+
return {
|
|
137
|
+
module: _XltTokenModule,
|
|
138
|
+
imports,
|
|
139
|
+
providers: [
|
|
140
|
+
{
|
|
141
|
+
provide: XLT_TOKEN_CONFIG$1,
|
|
142
|
+
useFactory: async (...args) => {
|
|
143
|
+
const { config = {} } = await useFactory(...args);
|
|
144
|
+
return {
|
|
145
|
+
...DEFAULT_XLT_TOKEN_CONFIG$1,
|
|
146
|
+
...config
|
|
147
|
+
};
|
|
148
|
+
},
|
|
149
|
+
inject
|
|
150
|
+
},
|
|
151
|
+
_XltTokenModule.createStoreProvider(store),
|
|
152
|
+
_XltTokenModule.createStrategyProvider(strategy),
|
|
153
|
+
_XltTokenModule.createStpInterfaceProvider(stpInterface),
|
|
154
|
+
_XltTokenModule.createHooksProvider(options.hooks),
|
|
155
|
+
_XltTokenModule.stpLogicProvider,
|
|
156
|
+
_XltTokenModule.stpPermLogicProvider,
|
|
157
|
+
_XltTokenModule.initProvider,
|
|
158
|
+
...providers
|
|
159
|
+
],
|
|
160
|
+
exports: _XltTokenModule.moduleExports,
|
|
161
|
+
global: isGlobal
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
XltTokenModule = _XltTokenModule = __decorate([Module({})], XltTokenModule);
|
|
166
|
+
|
|
167
|
+
//#endregion
|
|
168
|
+
//#region \0@oxc-project+runtime@0.112.0/helpers/decorateMetadata.js
|
|
169
|
+
function __decorateMetadata(k, v) {
|
|
170
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
//#endregion
|
|
174
|
+
//#region \0@oxc-project+runtime@0.112.0/helpers/decorateParam.js
|
|
175
|
+
function __decorateParam(paramIndex, decorator) {
|
|
176
|
+
return function(target, key) {
|
|
177
|
+
decorator(target, key, paramIndex);
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
//#endregion
|
|
182
|
+
//#region src/store/redis-store.ts
|
|
183
|
+
const XLT_REDIS_CLIENT = "XLT_REDIS_CLIENT";
|
|
184
|
+
let RedisStore = class RedisStore {
|
|
185
|
+
constructor(redisClient) {
|
|
186
|
+
this.redisClient = redisClient;
|
|
187
|
+
}
|
|
188
|
+
async get(key) {
|
|
189
|
+
return this.redisClient.get(key);
|
|
190
|
+
}
|
|
191
|
+
async set(key, value, timeoutSec) {
|
|
192
|
+
if (timeoutSec === -1) await this.redisClient.set(key, value);
|
|
193
|
+
else await this.redisClient.set(key, value, { EX: timeoutSec });
|
|
194
|
+
}
|
|
195
|
+
async delete(key) {
|
|
196
|
+
await this.redisClient.del(key);
|
|
197
|
+
}
|
|
198
|
+
async update(key, value) {
|
|
199
|
+
if (await this.redisClient.set(key, value, {
|
|
200
|
+
XX: true,
|
|
201
|
+
KEEPTTL: true
|
|
202
|
+
}) === null) throw new Error(`Key not found: ${key}`);
|
|
203
|
+
}
|
|
204
|
+
async has(key) {
|
|
205
|
+
return await this.redisClient.exists(key) === 1;
|
|
206
|
+
}
|
|
207
|
+
async updateTimeout(key, timeoutSec) {
|
|
208
|
+
if (!await this.redisClient.exists(key)) throw new Error(`Key not found: ${key}`);
|
|
209
|
+
if (timeoutSec === -1) await this.redisClient.persist(key);
|
|
210
|
+
else await this.redisClient.expire(key, timeoutSec);
|
|
211
|
+
}
|
|
212
|
+
async getTimeout(key) {
|
|
213
|
+
return await this.redisClient.ttl(key);
|
|
214
|
+
}
|
|
215
|
+
async keys(pattern) {
|
|
216
|
+
const result = [];
|
|
217
|
+
let cursor = 0;
|
|
218
|
+
do {
|
|
219
|
+
const reply = await this.redisClient.scan(cursor, {
|
|
220
|
+
MATCH: pattern,
|
|
221
|
+
COUNT: 100
|
|
222
|
+
});
|
|
223
|
+
cursor = reply.cursor;
|
|
224
|
+
result.push(...reply.keys);
|
|
225
|
+
} while (cursor !== 0);
|
|
226
|
+
return result;
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
RedisStore = __decorate([
|
|
230
|
+
Injectable(),
|
|
231
|
+
__decorateParam(0, Inject(XLT_REDIS_CLIENT)),
|
|
232
|
+
__decorateMetadata("design:paramtypes", [Object])
|
|
233
|
+
], RedisStore);
|
|
234
|
+
|
|
235
|
+
//#endregion
|
|
236
|
+
//#region src/token/jwt-strategy.ts
|
|
237
|
+
var _ref$2;
|
|
238
|
+
let JwtStrategy = class JwtStrategy {
|
|
239
|
+
constructor(config) {
|
|
240
|
+
this.config = config;
|
|
241
|
+
}
|
|
242
|
+
createToken(loginId, config) {
|
|
243
|
+
const jwt = config.jwt;
|
|
244
|
+
return sign({
|
|
245
|
+
sub: loginId,
|
|
246
|
+
jti: crypto.randomUUID()
|
|
247
|
+
}, jwt.secret, {
|
|
248
|
+
algorithm: jwt.algorithm ?? "HS256",
|
|
249
|
+
...jwt.issuer && { issuer: jwt.issuer },
|
|
250
|
+
...jwt.audience && { audience: jwt.audience },
|
|
251
|
+
...config.timeout > 0 && { expiresIn: config.timeout }
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
generateToken(payload) {
|
|
255
|
+
return sign(payload, this.config.jwt.secret);
|
|
256
|
+
}
|
|
257
|
+
verifyToken(token) {
|
|
258
|
+
return verify(token, this.config.jwt.secret);
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
JwtStrategy = __decorate([
|
|
262
|
+
Injectable(),
|
|
263
|
+
__decorateParam(0, Inject(XLT_TOKEN_CONFIG$1)),
|
|
264
|
+
__decorateMetadata("design:paramtypes", [typeof (_ref$2 = typeof XltTokenConfig !== "undefined" && XltTokenConfig) === "function" ? _ref$2 : Object])
|
|
265
|
+
], JwtStrategy);
|
|
266
|
+
|
|
267
|
+
//#endregion
|
|
268
|
+
//#region src/decorators/xlt-check-login.decorator.ts
|
|
269
|
+
/**
|
|
270
|
+
* 登录校验装饰器
|
|
271
|
+
* @constructor
|
|
272
|
+
*/
|
|
273
|
+
const XltCheckLogin = () => SetMetadata(XLT_CHECK_LOGIN_KEY, true);
|
|
274
|
+
|
|
275
|
+
//#endregion
|
|
276
|
+
//#region src/decorators/xlt-ignore.decorator.ts
|
|
277
|
+
const XltIgnore = () => SetMetadata(XLT_IGNORE_KEY, true);
|
|
278
|
+
|
|
279
|
+
//#endregion
|
|
280
|
+
//#region src/decorators/login-id.decorator.ts
|
|
281
|
+
/**
|
|
282
|
+
* 注入当前用户 ID
|
|
283
|
+
* @constructor
|
|
284
|
+
*/
|
|
285
|
+
const LoginId = createParamDecorator((data, ctx) => {
|
|
286
|
+
return ctx.switchToHttp().getRequest().stpLoginId;
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
//#endregion
|
|
290
|
+
//#region src/decorators/token-value.decorator.ts
|
|
291
|
+
/**
|
|
292
|
+
* 注入当前 Token
|
|
293
|
+
* @constructor
|
|
294
|
+
*/
|
|
295
|
+
const TokenValue = createParamDecorator((data, ctx) => {
|
|
296
|
+
return ctx.switchToHttp().getRequest().stpToken;
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
//#endregion
|
|
300
|
+
//#region src/decorators/xlt-check-permission.decorator.ts
|
|
301
|
+
/**
|
|
302
|
+
* 权限检查装饰器
|
|
303
|
+
* @param {string | string[]} permissions 权限列表
|
|
304
|
+
* @param {Object} [options] 模式选项
|
|
305
|
+
* @param {XltMode} [options.mode] 模式选项
|
|
306
|
+
* @constructor
|
|
307
|
+
*/
|
|
308
|
+
const XltCheckPermission = (permissions, options) => {
|
|
309
|
+
return SetMetadata(XLT_PERMISSION_KEY, {
|
|
310
|
+
permissions: Array.isArray(permissions) ? permissions : [permissions],
|
|
311
|
+
mode: options?.mode ?? XltMode$1.AND
|
|
312
|
+
});
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
//#endregion
|
|
316
|
+
//#region src/decorators/xlt-check-role.decorator.ts
|
|
317
|
+
/**
|
|
318
|
+
* 角色检查装饰器
|
|
319
|
+
* @param {string | string[]} roles 角色列表
|
|
320
|
+
* @param {Object} [options] 模式选项
|
|
321
|
+
* @param {XltMode} [options.mode] 模式选项
|
|
322
|
+
* @constructor
|
|
323
|
+
*/
|
|
324
|
+
const XltCheckRole = (roles, options) => {
|
|
325
|
+
return SetMetadata(XLT_ROLE_KEY, {
|
|
326
|
+
roles: Array.isArray(roles) ? roles : [roles],
|
|
327
|
+
mode: options?.mode ?? XltMode$1.AND
|
|
328
|
+
});
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
//#endregion
|
|
332
|
+
//#region src/decorators/xlt-check-safe.decorator.ts
|
|
333
|
+
const XLT_CHECK_SAFE_KEY = "XLT_CHECK_SAFE";
|
|
334
|
+
const XltCheckSafe = (business) => {
|
|
335
|
+
return SetMetadata(XLT_CHECK_SAFE_KEY, business);
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
//#endregion
|
|
339
|
+
//#region src/exceptions/not-login.exception.ts
|
|
340
|
+
var NotLoginException = class NotLoginException extends UnauthorizedException {
|
|
341
|
+
constructor(type, token) {
|
|
342
|
+
super({
|
|
343
|
+
statusCode: 401,
|
|
344
|
+
type,
|
|
345
|
+
message: NotLoginException.describeType(type)
|
|
346
|
+
});
|
|
347
|
+
this.type = type;
|
|
348
|
+
this.token = token;
|
|
349
|
+
}
|
|
350
|
+
static describeType(type) {
|
|
351
|
+
return {
|
|
352
|
+
[NotLoginType$1.NOT_TOKEN]: "未提供 Token",
|
|
353
|
+
[NotLoginType$1.INVALID_TOKEN]: "Token 无效",
|
|
354
|
+
[NotLoginType$1.TOKEN_TIMEOUT]: "Token 已过期",
|
|
355
|
+
[NotLoginType$1.TOKEN_FREEZE]: "Token 已被冻结",
|
|
356
|
+
[NotLoginType$1.BE_REPLACED]: "已被顶下线",
|
|
357
|
+
[NotLoginType$1.KICK_OUT]: "已被踢下线"
|
|
358
|
+
}[type] ?? "未登录";
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
//#endregion
|
|
363
|
+
//#region src/exceptions/not-permission.exception.ts
|
|
364
|
+
var NotPermissionException = class extends ForbiddenException {
|
|
365
|
+
constructor(permission, mode) {
|
|
366
|
+
super({
|
|
367
|
+
statusCode: 403,
|
|
368
|
+
type: "NOT_PERMISSION",
|
|
369
|
+
message: `缺少权限: ${Array.isArray(permission) ? permission.join(", ") : permission}`
|
|
370
|
+
});
|
|
371
|
+
this.permission = permission;
|
|
372
|
+
this.mode = mode;
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
//#endregion
|
|
377
|
+
//#region src/exceptions/not-role.exception.ts
|
|
378
|
+
var NotRoleException = class extends ForbiddenException {
|
|
379
|
+
constructor(role, mode) {
|
|
380
|
+
super({
|
|
381
|
+
statusCode: 403,
|
|
382
|
+
type: "NOT_ROLE",
|
|
383
|
+
message: `缺少角色: ${Array.isArray(role) ? role.join(", ") : role}`
|
|
384
|
+
});
|
|
385
|
+
this.role = role;
|
|
386
|
+
this.mode = mode;
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
//#endregion
|
|
391
|
+
//#region src/exceptions/not-safe.exception.ts
|
|
392
|
+
var NotSafeException = class extends ForbiddenException {
|
|
393
|
+
constructor(business) {
|
|
394
|
+
super({
|
|
395
|
+
statusCode: 403,
|
|
396
|
+
type: "NOT_SAFE",
|
|
397
|
+
message: `二级认证未开启:${business}`
|
|
398
|
+
});
|
|
399
|
+
this.business = business;
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
//#endregion
|
|
404
|
+
//#region src/http/nest-bridge.ts
|
|
405
|
+
function createNestHttpContext(req, res) {
|
|
406
|
+
return createExpressContext$1(req, res);
|
|
407
|
+
}
|
|
408
|
+
function rethrowCoreAuthException(error) {
|
|
409
|
+
if (error instanceof NotLoginException$1) throw new NotLoginException(error.type, error.token);
|
|
410
|
+
if (error instanceof NotPermissionException$1) throw new NotPermissionException(error.permission, error.mode);
|
|
411
|
+
if (error instanceof NotRoleException$1) throw new NotRoleException(error.role, error.mode);
|
|
412
|
+
if (error instanceof NotSafeException$1) throw new NotSafeException(error.business);
|
|
413
|
+
throw error;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
//#endregion
|
|
417
|
+
//#region src/guards/xlt-token.guard.ts
|
|
418
|
+
var _ref$1, _ref2$1, _ref3;
|
|
419
|
+
let XltTokenGuard = class XltTokenGuard {
|
|
420
|
+
constructor(reflector, config, stpLogic, stpPermLogic) {
|
|
421
|
+
this.reflector = reflector;
|
|
422
|
+
this.config = config;
|
|
423
|
+
this.stpLogic = stpLogic;
|
|
424
|
+
this.stpPermLogic = stpPermLogic;
|
|
425
|
+
}
|
|
426
|
+
async canActivate(context) {
|
|
427
|
+
if (!this.requiresLogin(context)) return true;
|
|
428
|
+
const request = context.switchToHttp().getRequest();
|
|
429
|
+
const response = context.switchToHttp().getResponse();
|
|
430
|
+
let result;
|
|
431
|
+
try {
|
|
432
|
+
result = await this.stpLogic.checkLogin(createNestHttpContext(request, response));
|
|
433
|
+
} catch (error) {
|
|
434
|
+
rethrowCoreAuthException(error);
|
|
435
|
+
}
|
|
436
|
+
const business = this.getBusiness(context);
|
|
437
|
+
request.stpLoginId = result.loginId;
|
|
438
|
+
request.stpToken = result.token;
|
|
439
|
+
try {
|
|
440
|
+
if (this.stpPermLogic) {
|
|
441
|
+
const handler = context.getHandler();
|
|
442
|
+
const cls = context.getClass();
|
|
443
|
+
const permMeta = this.reflector.getAllAndOverride(XLT_PERMISSION_KEY, [handler, cls]);
|
|
444
|
+
if (permMeta) await this.stpPermLogic.checkPermission(result.loginId, permMeta.permissions, permMeta.mode);
|
|
445
|
+
const roleMeta = this.reflector.getAllAndOverride(XLT_ROLE_KEY, [handler, cls]);
|
|
446
|
+
if (roleMeta) await this.stpPermLogic.checkRole(result.loginId, roleMeta.roles, roleMeta.mode);
|
|
447
|
+
}
|
|
448
|
+
if (business) await this.stpLogic.checkSafe(result.token, business);
|
|
449
|
+
} catch (error) {
|
|
450
|
+
rethrowCoreAuthException(error);
|
|
451
|
+
}
|
|
452
|
+
return true;
|
|
453
|
+
}
|
|
454
|
+
requiresLogin(context) {
|
|
455
|
+
const isIgnored = this.reflector.getAllAndOverride(XLT_IGNORE_KEY, [context.getHandler(), context.getClass()]);
|
|
456
|
+
if (this.config.defaultCheck) return !isIgnored;
|
|
457
|
+
return this.reflector.getAllAndOverride(XLT_CHECK_LOGIN_KEY, [context.getHandler(), context.getClass()]) ?? false;
|
|
458
|
+
}
|
|
459
|
+
getBusiness(context) {
|
|
460
|
+
return this.reflector.getAllAndOverride(XLT_CHECK_SAFE_KEY, [context.getHandler(), context.getClass()]);
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
XltTokenGuard = __decorate([
|
|
464
|
+
Injectable(),
|
|
465
|
+
__decorateParam(1, Inject(XLT_TOKEN_CONFIG$1)),
|
|
466
|
+
__decorateParam(3, Optional()),
|
|
467
|
+
__decorateMetadata("design:paramtypes", [
|
|
468
|
+
typeof (_ref$1 = typeof Reflector !== "undefined" && Reflector) === "function" ? _ref$1 : Object,
|
|
469
|
+
Object,
|
|
470
|
+
typeof (_ref2$1 = typeof StpLogic$1 !== "undefined" && StpLogic$1) === "function" ? _ref2$1 : Object,
|
|
471
|
+
typeof (_ref3 = typeof StpPermLogic$1 !== "undefined" && StpPermLogic$1) === "function" ? _ref3 : Object
|
|
472
|
+
])
|
|
473
|
+
], XltTokenGuard);
|
|
474
|
+
|
|
475
|
+
//#endregion
|
|
476
|
+
//#region src/guards/xlt-abstract-login.guard.ts
|
|
477
|
+
var _ref, _ref2;
|
|
478
|
+
let XltAbstractLoginGuard = class XltAbstractLoginGuard {
|
|
479
|
+
constructor(reflector, config, stpLogic) {
|
|
480
|
+
this.reflector = reflector;
|
|
481
|
+
this.config = config;
|
|
482
|
+
this.stpLogic = stpLogic;
|
|
483
|
+
}
|
|
484
|
+
async canActivate(ctx) {
|
|
485
|
+
if (!this.requiresLogin(ctx)) return true;
|
|
486
|
+
const request = ctx.switchToHttp().getRequest();
|
|
487
|
+
const response = ctx.switchToHttp().getResponse();
|
|
488
|
+
let result;
|
|
489
|
+
try {
|
|
490
|
+
result = await this.stpLogic.checkLogin(createNestHttpContext(request, response));
|
|
491
|
+
} catch (err) {
|
|
492
|
+
if (err instanceof NotLoginException$1) {
|
|
493
|
+
await this.onAuthFail?.({
|
|
494
|
+
ok: false,
|
|
495
|
+
reason: err.type,
|
|
496
|
+
token: err.token
|
|
497
|
+
}, request);
|
|
498
|
+
throw new NotLoginException(err.type, err.token);
|
|
499
|
+
}
|
|
500
|
+
throw err;
|
|
501
|
+
}
|
|
502
|
+
request.stpLoginId = result.loginId;
|
|
503
|
+
request.stpToken = result.token;
|
|
504
|
+
await this.onAuthSuccess?.(result, request);
|
|
505
|
+
return true;
|
|
506
|
+
}
|
|
507
|
+
requiresLogin(ctx) {
|
|
508
|
+
const isIgnored = this.reflector.getAllAndOverride(XLT_IGNORE_KEY, [ctx.getHandler(), ctx.getClass()]);
|
|
509
|
+
if (this.config.defaultCheck) return !isIgnored;
|
|
510
|
+
return this.reflector.getAllAndOverride(XLT_CHECK_LOGIN_KEY, [ctx.getHandler(), ctx.getClass()]) ?? false;
|
|
511
|
+
}
|
|
512
|
+
};
|
|
513
|
+
XltAbstractLoginGuard = __decorate([
|
|
514
|
+
Injectable(),
|
|
515
|
+
__decorateParam(1, Inject(XLT_TOKEN_CONFIG$1)),
|
|
516
|
+
__decorateMetadata("design:paramtypes", [
|
|
517
|
+
typeof (_ref = typeof Reflector !== "undefined" && Reflector) === "function" ? _ref : Object,
|
|
518
|
+
Object,
|
|
519
|
+
typeof (_ref2 = typeof StpLogic$1 !== "undefined" && StpLogic$1) === "function" ? _ref2 : Object
|
|
520
|
+
])
|
|
521
|
+
], XltAbstractLoginGuard);
|
|
522
|
+
|
|
523
|
+
//#endregion
|
|
524
|
+
export { DEFAULT_XLT_TOKEN_CONFIG, JwtStrategy, LoginId, MemoryStore, NotLoginException, NotLoginType, NotPermissionException, NotRoleException, NotSafeException, RedisStore, StpLogic, StpPermLogic, StpUtil, TokenValue, UuidStrategy, XLT_CHECK_SAFE_KEY, XLT_REDIS_CLIENT, XLT_STP_INTERFACE, XLT_TOKEN_CONFIG, XLT_TOKEN_HOOKS, XLT_TOKEN_STORE, XLT_TOKEN_STRATEGY, XltAbstractLoginGuard, XltCheckLogin, XltCheckPermission, XltCheckRole, XltCheckSafe, XltIgnore, XltMode, XltSession, XltTokenGuard, XltTokenModule, createExpressContext, createMockHttpContext, createXltToken, matchPermission, setStpLogic, setStpPermLogic };
|
|
525
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["XLT_TOKEN_STORE","MemoryStore","XLT_TOKEN_STRATEGY","UuidStrategy","XLT_STP_INTERFACE","XLT_TOKEN_HOOKS","StpLogic","XLT_TOKEN_CONFIG","StpPermLogic","DEFAULT_XLT_TOKEN_CONFIG","XLT_TOKEN_CONFIG","XltMode","XltMode","NotLoginType","createExpressContext","CoreNotLoginException","CoreNotPermissionException","CoreNotRoleException","CoreNotSafeException","XLT_TOKEN_CONFIG","CoreNotLoginException","XLT_TOKEN_CONFIG"],"sources":["../src/xlt-token.module.ts","../src/store/redis-store.ts","../src/token/jwt-strategy.ts","../src/decorators/xlt-check-login.decorator.ts","../src/decorators/xlt-ignore.decorator.ts","../src/decorators/login-id.decorator.ts","../src/decorators/token-value.decorator.ts","../src/decorators/xlt-check-permission.decorator.ts","../src/decorators/xlt-check-role.decorator.ts","../src/decorators/xlt-check-safe.decorator.ts","../src/exceptions/not-login.exception.ts","../src/exceptions/not-permission.exception.ts","../src/exceptions/not-role.exception.ts","../src/exceptions/not-safe.exception.ts","../src/http/nest-bridge.ts","../src/guards/xlt-token.guard.ts","../src/guards/xlt-abstract-login.guard.ts"],"sourcesContent":["import { Module, ModuleMetadata, Provider } from '@nestjs/common';\nimport {\n DEFAULT_XLT_TOKEN_CONFIG,\n MemoryStore,\n StpInterface,\n StpLogic,\n StpPermLogic,\n TokenStrategy,\n UuidStrategy,\n XLT_STP_INTERFACE,\n XLT_TOKEN_CONFIG,\n XLT_TOKEN_HOOKS,\n XLT_TOKEN_STORE,\n XLT_TOKEN_STRATEGY,\n XltHooks,\n XltTokenConfig,\n XltTokenStore,\n setStpLogic,\n setStpPermLogic,\n} from '@xlt-token/core';\n\nexport interface XltTokenModuleOptions {\n config?: Partial<XltTokenConfig>;\n store?: { useClass: new (...args: any[]) => XltTokenStore } | { useValue: XltTokenStore };\n strategy?: { useClass: new (...args: any[]) => TokenStrategy };\n isGlobal?: boolean;\n providers?: Provider[];\n stpInterface?: new (...args: any[]) => StpInterface;\n hooks?: XltHooks;\n}\n\nexport interface XltTokenModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {\n useFactory: (...args: any[]) => Promise<XltTokenModuleOptions> | XltTokenModuleOptions;\n inject?: any[];\n store?: { useClass: new (...args: any[]) => XltTokenStore } | { useValue: XltTokenStore };\n strategy?: { useClass: new (...args: any[]) => TokenStrategy };\n isGlobal?: boolean;\n providers?: Provider[];\n stpInterface?: new (...args: any[]) => StpInterface;\n hooks?: XltHooks;\n}\n\n@Module({})\nexport class XltTokenModule {\n private static createStoreProvider(\n store?: XltTokenModuleOptions['store'],\n ): Provider {\n if (!store) return { provide: XLT_TOKEN_STORE, useClass: MemoryStore };\n return 'useClass' in store\n ? { provide: XLT_TOKEN_STORE, useClass: store.useClass }\n : { provide: XLT_TOKEN_STORE, useValue: store.useValue };\n }\n\n private static createStrategyProvider(\n strategy?: XltTokenModuleOptions['strategy'],\n ): Provider {\n return strategy?.useClass\n ? { provide: XLT_TOKEN_STRATEGY, useClass: strategy.useClass }\n : { provide: XLT_TOKEN_STRATEGY, useClass: UuidStrategy };\n }\n\n private static createStpInterfaceProvider(\n stpInterface?: new (...args: any[]) => StpInterface,\n ): Provider {\n if (stpInterface) return { provide: XLT_STP_INTERFACE, useClass: stpInterface };\n return {\n provide: XLT_STP_INTERFACE,\n useValue: {\n getPermissionList: () => { throw new Error('StpInterface not registered: getPermissionList'); },\n getRoleList: () => { throw new Error('StpInterface not registered: getRoleList'); },\n },\n };\n }\n\n private static createHooksProvider(\n hooks?: XltTokenModuleOptions['hooks'],\n ): Provider {\n return { provide: XLT_TOKEN_HOOKS, useValue: hooks ?? {} };\n }\n\n private static readonly stpLogicProvider: Provider = {\n provide: StpLogic,\n useFactory: (\n config: XltTokenConfig,\n store: XltTokenStore,\n strategy: TokenStrategy,\n hooks: XltHooks,\n ) => new StpLogic(config, store, strategy, hooks),\n inject: [XLT_TOKEN_CONFIG, XLT_TOKEN_STORE, XLT_TOKEN_STRATEGY, XLT_TOKEN_HOOKS],\n };\n\n private static readonly stpPermLogicProvider: Provider = {\n provide: StpPermLogic,\n useFactory: (\n stpInterface: StpInterface,\n store: XltTokenStore,\n config: XltTokenConfig,\n ) => new StpPermLogic(stpInterface, store, config),\n inject: [XLT_STP_INTERFACE, XLT_TOKEN_STORE, XLT_TOKEN_CONFIG],\n };\n\n private static readonly initProvider: Provider = {\n provide: 'XLT_TOKEN_INIT',\n useFactory: (stpLogic: StpLogic, stpPermLogic: StpPermLogic) => {\n setStpLogic(stpLogic);\n setStpPermLogic(stpPermLogic);\n return true;\n },\n inject: [StpLogic, StpPermLogic],\n };\n\n private static readonly moduleExports = [XLT_TOKEN_CONFIG, XLT_TOKEN_STORE, XLT_TOKEN_STRATEGY, StpLogic, StpPermLogic];\n\n static forRoot(options: XltTokenModuleOptions = {}) {\n const { config: userConfig, store, strategy, isGlobal = false, providers = [], stpInterface } = options;\n\n return {\n module: XltTokenModule,\n providers: [\n { provide: XLT_TOKEN_CONFIG, useValue: { ...DEFAULT_XLT_TOKEN_CONFIG, ...userConfig } },\n XltTokenModule.createStoreProvider(store),\n XltTokenModule.createStrategyProvider(strategy),\n XltTokenModule.createStpInterfaceProvider(stpInterface),\n XltTokenModule.createHooksProvider(options.hooks),\n XltTokenModule.stpLogicProvider,\n XltTokenModule.stpPermLogicProvider,\n XltTokenModule.initProvider,\n ...providers,\n ],\n exports: XltTokenModule.moduleExports,\n global: isGlobal,\n };\n }\n\n static forRootAsync(options: XltTokenModuleAsyncOptions) {\n const { useFactory, inject = [], imports = [], store, strategy, isGlobal = false, providers = [], stpInterface } = options;\n\n return {\n module: XltTokenModule,\n imports,\n providers: [\n {\n provide: XLT_TOKEN_CONFIG,\n useFactory: async (...args: any[]) => {\n const { config = {} } = await useFactory(...args);\n return { ...DEFAULT_XLT_TOKEN_CONFIG, ...config };\n },\n inject,\n },\n XltTokenModule.createStoreProvider(store),\n XltTokenModule.createStrategyProvider(strategy),\n XltTokenModule.createStpInterfaceProvider(stpInterface),\n XltTokenModule.createHooksProvider(options.hooks),\n XltTokenModule.stpLogicProvider,\n XltTokenModule.stpPermLogicProvider,\n XltTokenModule.initProvider,\n ...providers,\n ],\n exports: XltTokenModule.moduleExports,\n global: isGlobal,\n };\n }\n}\n","import { XltTokenStore } from '@xlt-token/core';\nimport { Inject, Injectable } from '@nestjs/common';\n\n\nexport const XLT_REDIS_CLIENT = 'XLT_REDIS_CLIENT';\n\n\n@Injectable()\nexport class RedisStore implements XltTokenStore {\n\n constructor(\n @Inject(XLT_REDIS_CLIENT)\n private readonly redisClient: any,\n ) {\n\n }\n\n\n async get(key:string):Promise<string | null> {\n return this.redisClient.get(key);\n }\n\n\n async set(key:string, value:string, timeoutSec:number):Promise<void> {\n if (timeoutSec === -1){\n await this.redisClient.set(key, value);\n }else {\n await this.redisClient.set(key, value, {EX: timeoutSec});\n }\n }\n\n\n async delete(key:string):Promise<void> {\n await this.redisClient.del(key);\n }\n\n\n async update(key:string, value:string):Promise<void> {\n const result = await this.redisClient.set(key, value,{XX:true,KEEPTTL:true})\n if (result ===null){\n throw new Error(`Key not found: ${key}`);\n }\n }\n\n\n async has(key:string):Promise<boolean> {\n const result = await this.redisClient.exists(key);\n return result === 1;\n }\n\n\n async updateTimeout(key:string, timeoutSec:number):Promise<void> {\n const exists = await this.redisClient.exists(key);\n\n if (!exists) {\n throw new Error(`Key not found: ${key}`);\n }\n\n if (timeoutSec === -1) {\n await this.redisClient.persist(key);\n }else {\n await this.redisClient.expire(key, timeoutSec);\n }\n\n }\n\n async getTimeout(key:string):Promise<number> {\n const result = await this.redisClient.ttl(key);\n // Redis TTL 返回值约定:\n // -2 = key 不存在\n // -1 = key 存在但无过期时间(永久)\n // >0 = 剩余秒数\n // 恰好与 XltTokenStore 接口约定一致\n return result;\n }\n\n async keys(pattern: string): Promise<string[]> {\n const result: string[] = [];\n let cursor = 0;\n do {\n const reply = await this.redisClient.scan(cursor, { MATCH: pattern, COUNT: 100 });\n cursor = reply.cursor;\n result.push(...reply.keys);\n } while (cursor !== 0);\n return result;\n }\n}\n","import { Inject, Injectable } from \"@nestjs/common\";\nimport { XLT_TOKEN_CONFIG, XltTokenConfig } from '@xlt-token/core';\nimport type { TokenStrategy } from '@xlt-token/core';\nimport { sign, verify, JwtPayload } from \"jsonwebtoken\";\n\n@Injectable()\nexport class JwtStrategy implements TokenStrategy {\n constructor(\n @Inject(XLT_TOKEN_CONFIG) private readonly config: XltTokenConfig\n ) { }\n\n\n\n createToken(loginId: string, config: XltTokenConfig): string {\n const jwt = config.jwt!;\n const jti = crypto.randomUUID();\n\n\n return sign({\n sub: loginId, jti\n }, jwt.secret, {\n algorithm: jwt.algorithm ?? 'HS256',\n ...(jwt.issuer && { issuer: jwt.issuer }),\n ...(jwt.audience && { audience: jwt.audience }),\n ...(config.timeout > 0 && { expiresIn: config.timeout }),\n })\n\n }\n\n\n generateToken(payload: any): string {\n return sign(payload, this.config.jwt!.secret);\n }\n\n\n\n verifyToken(token: string): JwtPayload & { sub: string; jti: string } {\n return verify(token, this.config.jwt!.secret) as any;\n }\n\n}\n","// 登录校验装饰器\n\nimport { SetMetadata } from '@nestjs/common';\nimport { XLT_CHECK_LOGIN_KEY } from '@xlt-token/core';\n\n\n/**\n * 登录校验装饰器\n * @constructor\n */\nexport const XltCheckLogin = () => SetMetadata(XLT_CHECK_LOGIN_KEY, true);\n","// 忽略校验装饰器\n\nimport { SetMetadata } from '@nestjs/common';\nimport { XLT_IGNORE_KEY } from '@xlt-token/core';\n\nexport const XltIgnore = () => SetMetadata(XLT_IGNORE_KEY, true);\n","// 注入当前用户 ID\n\nimport { createParamDecorator, ExecutionContext } from '@nestjs/common';\n\n/**\n * 注入当前用户 ID\n * @constructor\n */\nexport const LoginId = createParamDecorator(\n (data: unknown, ctx: ExecutionContext) => {\n const request = ctx.switchToHttp().getRequest();\n return request.stpLoginId;\n },\n);\n","// 注入当前 Token\n\nimport { createParamDecorator, ExecutionContext } from '@nestjs/common';\n\n\n/**\n * 注入当前 Token\n * @constructor\n */\nexport const TokenValue = createParamDecorator((data: any, ctx: ExecutionContext) => {\n const request = ctx.switchToHttp().getRequest();\n return request.stpToken;\n});\n","import { XLT_PERMISSION_KEY, XltMode } from '@xlt-token/core';\nimport { SetMetadata } from '@nestjs/common';\n\n\n/**\n * 权限检查装饰器\n * @param {string | string[]} permissions 权限列表\n * @param {Object} [options] 模式选项\n * @param {XltMode} [options.mode] 模式选项\n * @constructor\n */\nexport const XltCheckPermission = (permissions: string | string[], options?: { mode: XltMode; }) => {\n const perms = Array.isArray(permissions) ? permissions : [permissions];\n const mode = options?.mode ?? XltMode.AND;\n return SetMetadata(XLT_PERMISSION_KEY, { permissions: perms, mode });\n};\n","import { XLT_ROLE_KEY, XltMode } from '@xlt-token/core';\nimport { SetMetadata } from '@nestjs/common';\n\n\n/**\n * 角色检查装饰器\n * @param {string | string[]} roles 角色列表\n * @param {Object} [options] 模式选项\n * @param {XltMode} [options.mode] 模式选项\n * @constructor\n */\nexport const XltCheckRole = (roles: string | string[], options?: { mode: XltMode; }) => {\n const _roles = Array.isArray(roles) ? roles : [roles];\n const mode = options?.mode ?? XltMode.AND;\n return SetMetadata(XLT_ROLE_KEY, { roles: _roles, mode });\n\n};\n","import { SetMetadata } from \"@nestjs/common\"\n\nexport const XLT_CHECK_SAFE_KEY = 'XLT_CHECK_SAFE';\n\nexport const XltCheckSafe = (business: string) => {\n return SetMetadata(XLT_CHECK_SAFE_KEY, business);\n}\n","import { UnauthorizedException } from '@nestjs/common';\nimport { NotLoginType } from '@xlt-token/core';\n\nexport class NotLoginException extends UnauthorizedException {\n public readonly type: NotLoginType;\n public readonly token: string | undefined;\n\n constructor(type: NotLoginType, token?: string) {\n super({\n statusCode: 401,\n type,\n message: NotLoginException.describeType(type),\n });\n this.type = type;\n this.token = token;\n }\n\n private static describeType(type: NotLoginType): string {\n const map: Record<NotLoginType, string> = {\n [NotLoginType.NOT_TOKEN]: '未提供 Token',\n [NotLoginType.INVALID_TOKEN]: 'Token 无效',\n [NotLoginType.TOKEN_TIMEOUT]: 'Token 已过期',\n [NotLoginType.TOKEN_FREEZE]: 'Token 已被冻结',\n [NotLoginType.BE_REPLACED]: '已被顶下线',\n [NotLoginType.KICK_OUT]: '已被踢下线',\n };\n return map[type] ?? '未登录';\n }\n}\n\n","import { ForbiddenException } from '@nestjs/common';\nimport { XltMode } from '@xlt-token/core';\n\nexport class NotPermissionException extends ForbiddenException {\n public readonly permission: string | string[];\n public readonly mode: XltMode;\n\n constructor(permission: string | string[], mode: XltMode) {\n super({\n statusCode: 403,\n type: 'NOT_PERMISSION',\n message: `缺少权限: ${Array.isArray(permission) ? permission.join(', ') : permission}`,\n });\n this.permission = permission;\n this.mode = mode;\n }\n}\n","import { ForbiddenException } from '@nestjs/common';\nimport { XltMode } from '@xlt-token/core';\n\nexport class NotRoleException extends ForbiddenException {\n public readonly role: string | string[];\n public readonly mode: XltMode;\n\n constructor(role: string | string[], mode: XltMode) {\n super({\n statusCode: 403,\n type: 'NOT_ROLE',\n message: `缺少角色: ${Array.isArray(role) ? role.join(', ') : role}`,\n });\n this.role = role;\n this.mode = mode;\n }\n}\n","import { ForbiddenException } from \"@nestjs/common\";\n\nexport class NotSafeException extends ForbiddenException {\n readonly business: string;\n\n\n constructor(business: string) {\n super({\n statusCode: 403,\n type: 'NOT_SAFE',\n message: `二级认证未开启:${business}`,\n });\n this.business = business;\n }\n\n}\n","import {\n createExpressContext,\n NotLoginException as CoreNotLoginException,\n NotPermissionException as CoreNotPermissionException,\n NotRoleException as CoreNotRoleException,\n NotSafeException as CoreNotSafeException,\n} from '@xlt-token/core';\nimport { NotLoginException } from '../exceptions/not-login.exception.js';\nimport { NotPermissionException } from '../exceptions/not-permission.exception.js';\nimport { NotRoleException } from '../exceptions/not-role.exception.js';\nimport { NotSafeException } from '../exceptions/not-safe.exception.js';\n\nexport function createNestHttpContext(req: any, res: any) {\n return createExpressContext(req, res);\n}\n\nexport function rethrowCoreAuthException(error: unknown): never {\n if (error instanceof CoreNotLoginException) {\n throw new NotLoginException(error.type, error.token);\n }\n if (error instanceof CoreNotPermissionException) {\n throw new NotPermissionException(error.permission, error.mode);\n }\n if (error instanceof CoreNotRoleException) {\n throw new NotRoleException(error.role, error.mode);\n }\n if (error instanceof CoreNotSafeException) {\n throw new NotSafeException(error.business);\n }\n throw error;\n}\n","// 全局守卫\n\nimport { CanActivate, ExecutionContext, Inject, Injectable, Optional } from '@nestjs/common';\nimport { Reflector } from '@nestjs/core';\nimport {\n type AuthResult,\n StpLogic,\n StpPermLogic,\n XLT_CHECK_LOGIN_KEY,\n XLT_IGNORE_KEY,\n XLT_PERMISSION_KEY,\n XLT_ROLE_KEY,\n XLT_TOKEN_CONFIG,\n type XltTokenConfig,\n} from '@xlt-token/core';\nimport { XLT_CHECK_SAFE_KEY } from '../decorators/xlt-check-safe.decorator.js';\nimport { createNestHttpContext, rethrowCoreAuthException } from '../http/nest-bridge.js';\n\n@Injectable()\nexport class XltTokenGuard implements CanActivate {\n constructor(\n private readonly reflector: Reflector,\n @Inject(XLT_TOKEN_CONFIG) private readonly config: XltTokenConfig,\n private readonly stpLogic: StpLogic,\n @Optional() private readonly stpPermLogic?: StpPermLogic,\n ) {\n }\n\n async canActivate(context: ExecutionContext): Promise<boolean> {\n if (!this.requiresLogin(context)) return true;\n\n const request = context.switchToHttp().getRequest();\n const response = context.switchToHttp().getResponse();\n\n let result: AuthResult;\n try {\n result = await this.stpLogic.checkLogin(createNestHttpContext(request, response));\n } catch (error) {\n rethrowCoreAuthException(error);\n }\n\n const business = this.getBusiness(context);\n request.stpLoginId = result.loginId;\n request.stpToken = result.token;\n\n try {\n if (this.stpPermLogic) {\n const handler = context.getHandler();\n const cls = context.getClass();\n\n const permMeta = this.reflector.getAllAndOverride(XLT_PERMISSION_KEY, [handler, cls]);\n if (permMeta) {\n await this.stpPermLogic.checkPermission(result.loginId!, permMeta.permissions, permMeta.mode);\n }\n\n const roleMeta = this.reflector.getAllAndOverride(XLT_ROLE_KEY, [handler, cls]);\n if (roleMeta) {\n await this.stpPermLogic.checkRole(result.loginId!, roleMeta.roles, roleMeta.mode);\n }\n }\n\n if (business) {\n await this.stpLogic.checkSafe(result.token!, business);\n }\n } catch (error) {\n rethrowCoreAuthException(error);\n }\n\n return true;\n }\n\n private requiresLogin(context: ExecutionContext): boolean {\n const isIgnored = this.reflector.getAllAndOverride<boolean>(XLT_IGNORE_KEY, [\n context.getHandler(),\n context.getClass(),\n ]);\n\n if (this.config.defaultCheck) {\n return !isIgnored;\n }\n\n const shouldCheck = this.reflector.getAllAndOverride<boolean>(XLT_CHECK_LOGIN_KEY, [\n context.getHandler(),\n context.getClass(),\n ]);\n return shouldCheck ?? false;\n }\n\n private getBusiness(context: ExecutionContext): string {\n return this.reflector.getAllAndOverride<string>(XLT_CHECK_SAFE_KEY, [\n context.getHandler(),\n context.getClass(),\n ]);\n }\n}\n","import { CanActivate, ExecutionContext, Inject, Injectable } from '@nestjs/common';\nimport { Reflector } from '@nestjs/core';\nimport {\n NotLoginException as CoreNotLoginException,\n NotLoginType,\n StpLogic,\n XLT_CHECK_LOGIN_KEY,\n XLT_IGNORE_KEY,\n XLT_TOKEN_CONFIG,\n type XltTokenConfig,\n} from '@xlt-token/core';\nimport { NotLoginException } from '../exceptions/not-login.exception.js';\nimport { createNestHttpContext } from '../http/nest-bridge.js';\n\n@Injectable()\nexport abstract class XltAbstractLoginGuard implements CanActivate {\n protected constructor(\n protected readonly reflector: Reflector,\n @Inject(XLT_TOKEN_CONFIG) protected readonly config: XltTokenConfig,\n protected readonly stpLogic: StpLogic,\n ) {}\n\n async canActivate(ctx: ExecutionContext): Promise<boolean> {\n if (!this.requiresLogin(ctx)) return true;\n\n const request = ctx.switchToHttp().getRequest();\n const response = ctx.switchToHttp().getResponse();\n\n let result: { ok: boolean; loginId?: string; token?: string; reason?: NotLoginType };\n try {\n result = await this.stpLogic.checkLogin(createNestHttpContext(request, response));\n } catch (err) {\n if (err instanceof CoreNotLoginException) {\n await this.onAuthFail?.({ ok: false, reason: err.type, token: err.token }, request);\n throw new NotLoginException(err.type, err.token);\n }\n throw err;\n }\n\n request.stpLoginId = result.loginId;\n request.stpToken = result.token;\n await this.onAuthSuccess?.(result, request);\n return true;\n }\n\n protected requiresLogin(ctx: ExecutionContext): boolean {\n const isIgnored = this.reflector.getAllAndOverride<boolean>(XLT_IGNORE_KEY, [ctx.getHandler(), ctx.getClass()]);\n\n if (this.config.defaultCheck) return !isIgnored;\n\n return this.reflector.getAllAndOverride<boolean>(XLT_CHECK_LOGIN_KEY, [ctx.getHandler(), ctx.getClass()]) ?? false;\n }\n\n protected onAuthSuccess?(\n result: {\n ok: boolean;\n loginId?: string | undefined;\n token?: string | undefined;\n reason?: NotLoginType | undefined;\n },\n request: any,\n ): void | Promise<void>;\n\n protected onAuthFail?(\n result: {\n ok: boolean;\n loginId?: string | undefined;\n token?: string | undefined;\n reason?: NotLoginType | undefined;\n },\n request: any,\n ): void | Promise<void>;\n\n protected onPermissionDenied?(\n result: {\n ok: boolean;\n loginId?: string | undefined;\n token?: string | undefined;\n reason?: NotLoginType | undefined;\n },\n request: any,\n ): void | Promise<void>;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA2CO,2BAAM,eAAe;;;;CAC1B,OAAe,oBACb,OACU;AAC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;CAGrB,MAAM,YAAY,KAAyC;AACzD,MAAI,CAAC,KAAK,cAAc,IAAI,CAAE,QAAO;EAErC,MAAM,UAAU,IAAI,cAAc,CAAC,YAAY;EAC/C,MAAM,WAAW,IAAI,cAAc,CAAC,aAAa;EAEjD,IAAI;AACJ,MAAI;AACF,YAAS,MAAM,KAAK,SAAS,WAAW,sBAAsB,SAAS,SAAS,CAAC;WAC1E,KAAK;AACZ,OAAI,eAAeC,qBAAuB;AACxC,UAAM,KAAK,aAAa;KAAE,IAAI;KAAO,QAAQ,IAAI;KAAM,OAAO,IAAI;KAAO,EAAE,QAAQ;AACnF,UAAM,IAAI,kBAAkB,IAAI,MAAM,IAAI,MAAM;;AAElD,SAAM;;AAGR,UAAQ,aAAa,OAAO;AAC5B,UAAQ,WAAW,OAAO;AAC1B,QAAM,KAAK,gBAAgB,QAAQ,QAAQ;AAC3C,SAAO;;CAGT,AAAU,cAAc,KAAgC;EACtD,MAAM,YAAY,KAAK,UAAU,kBAA2B,gBAAgB,CAAC,IAAI,YAAY,EAAE,IAAI,UAAU,CAAC,CAAC;AAE/G,MAAI,KAAK,OAAO,aAAc,QAAO,CAAC;AAEtC,SAAO,KAAK,UAAU,kBAA2B,qBAAqB,CAAC,IAAI,YAAY,EAAE,IAAI,UAAU,CAAC,CAAC,IAAI;;;;CApChH,YAAY;oBAIR,OAAOC,mBAAiB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xlt-token/nestjs",
|
|
3
|
+
"version": "1.0.0-rc.3",
|
|
4
|
+
"description": "NestJS integration for xlt-token",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"nestjs",
|
|
7
|
+
"token",
|
|
8
|
+
"auth",
|
|
9
|
+
"jwt",
|
|
10
|
+
"session"
|
|
11
|
+
],
|
|
12
|
+
"author": "xltorg",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/xiaoLangtou/xlt-token.git",
|
|
17
|
+
"directory": "packages/nestjs"
|
|
18
|
+
},
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/xiaoLangtou/xlt-token/issues"
|
|
21
|
+
},
|
|
22
|
+
"homepage": "https://xiaolangtou.github.io/xlt-token/",
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"type": "module",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"import": "./dist/index.mjs",
|
|
30
|
+
"require": "./dist/index.cjs"
|
|
31
|
+
},
|
|
32
|
+
"./package.json": "./package.json"
|
|
33
|
+
},
|
|
34
|
+
"main": "./dist/index.cjs",
|
|
35
|
+
"module": "./dist/index.mjs",
|
|
36
|
+
"types": "./dist/index.d.cts",
|
|
37
|
+
"sideEffects": false,
|
|
38
|
+
"files": [
|
|
39
|
+
"dist",
|
|
40
|
+
"LICENSE",
|
|
41
|
+
"README.md"
|
|
42
|
+
],
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"@nestjs/common": "^10.0.0 || ^11.0.0",
|
|
45
|
+
"@nestjs/core": "^10.0.0 || ^11.0.0",
|
|
46
|
+
"reflect-metadata": "^0.1.13 || ^0.2.0",
|
|
47
|
+
"rxjs": "^7.0.0"
|
|
48
|
+
},
|
|
49
|
+
"peerDependenciesMeta": {
|
|
50
|
+
"redis": {
|
|
51
|
+
"optional": true
|
|
52
|
+
},
|
|
53
|
+
"jsonwebtoken": {
|
|
54
|
+
"optional": true
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"dependencies": {
|
|
58
|
+
"uuid": "^10.0.0",
|
|
59
|
+
"@xlt-token/core": "1.0.0-rc.3"
|
|
60
|
+
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@nestjs/common": "^10.0.0",
|
|
63
|
+
"@nestjs/core": "^10.0.0",
|
|
64
|
+
"@nestjs/platform-express": "^10.0.0",
|
|
65
|
+
"@nestjs/testing": "^10.0.0",
|
|
66
|
+
"@swc/core": "^1.15.30",
|
|
67
|
+
"@types/jsonwebtoken": "^9.0.10",
|
|
68
|
+
"@types/node": "^20.0.0",
|
|
69
|
+
"@types/supertest": "^7.2.0",
|
|
70
|
+
"@types/uuid": "^10.0.0",
|
|
71
|
+
"@vitest/coverage-v8": "^2.1.9",
|
|
72
|
+
"jsonwebtoken": "^9.0.3",
|
|
73
|
+
"reflect-metadata": "^0.1.13",
|
|
74
|
+
"rxjs": "^7.8.0",
|
|
75
|
+
"supertest": "^7.2.2",
|
|
76
|
+
"tsdown": "^0.20.0",
|
|
77
|
+
"typescript": "^5.1.0",
|
|
78
|
+
"unplugin-swc": "^1.5.9",
|
|
79
|
+
"vitest": "^2.0.0"
|
|
80
|
+
},
|
|
81
|
+
"scripts": {
|
|
82
|
+
"build": "tsdown",
|
|
83
|
+
"build:watch": "tsdown --watch",
|
|
84
|
+
"test": "vitest run",
|
|
85
|
+
"test:cov": "vitest run --coverage",
|
|
86
|
+
"test:e2e": "vitest run --config vitest.e2e.config.ts",
|
|
87
|
+
"test:e2e:cov": "vitest run --config vitest.e2e.config.ts --coverage",
|
|
88
|
+
"test:e2e:junit": "vitest run --config vitest.e2e.config.ts --reporter=junit --outputFile=reports/junit-e2e.xml"
|
|
89
|
+
}
|
|
90
|
+
}
|