@xlt-token/nestjs 1.2.1 → 2.1.0
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/index.cjs +46 -74
- package/dist/index.d.cts +12 -22
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +12 -22
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +35 -69
- package/dist/index.mjs.map +1 -1
- package/package.json +30 -34
package/dist/index.cjs
CHANGED
|
@@ -2,8 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
let _nestjs_common = require("@nestjs/common");
|
|
3
3
|
let _xlt_token_core = require("@xlt-token/core");
|
|
4
4
|
let _xlt_token_store_redis = require("@xlt-token/store-redis");
|
|
5
|
-
let
|
|
6
|
-
let node_module = require("node:module");
|
|
5
|
+
let _xlt_token_jwt = require("@xlt-token/jwt");
|
|
7
6
|
let _nestjs_core = require("@nestjs/core");
|
|
8
7
|
|
|
9
8
|
//#region \0@oxc-project+runtime@0.112.0/helpers/decorate.js
|
|
@@ -24,12 +23,12 @@ let XltTokenModule = class XltTokenModule {
|
|
|
24
23
|
static {
|
|
25
24
|
this.stpLogicProvider = {
|
|
26
25
|
provide: _xlt_token_core.StpLogic,
|
|
27
|
-
useFactory: (config, store, strategy,
|
|
26
|
+
useFactory: (config, store, strategy, eventSink) => new _xlt_token_core.StpLogic(config, store, strategy, eventSink),
|
|
28
27
|
inject: [
|
|
29
28
|
_xlt_token_core.XLT_TOKEN_CONFIG,
|
|
30
29
|
_xlt_token_core.XLT_TOKEN_STORE,
|
|
31
30
|
_xlt_token_core.XLT_TOKEN_STRATEGY,
|
|
32
|
-
_xlt_token_core.
|
|
31
|
+
_xlt_token_core.XLT_EVENT_SINK
|
|
33
32
|
]
|
|
34
33
|
};
|
|
35
34
|
}
|
|
@@ -76,7 +75,7 @@ let XltTokenModule = class XltTokenModule {
|
|
|
76
75
|
_XltTokenModule.createStoreProvider(store),
|
|
77
76
|
_XltTokenModule.createStrategyProvider(strategy),
|
|
78
77
|
_XltTokenModule.createStpInterfaceProvider(stpInterface),
|
|
79
|
-
_XltTokenModule.
|
|
78
|
+
_XltTokenModule.createEventSinkProvider(options.eventSink),
|
|
80
79
|
_XltTokenModule.stpLogicProvider,
|
|
81
80
|
_XltTokenModule.stpPermLogicProvider,
|
|
82
81
|
_XltTokenModule.initProvider,
|
|
@@ -103,7 +102,7 @@ let XltTokenModule = class XltTokenModule {
|
|
|
103
102
|
_XltTokenModule.createStoreProvider(store),
|
|
104
103
|
_XltTokenModule.createStrategyProvider(strategy),
|
|
105
104
|
_XltTokenModule.createStpInterfaceProvider(stpInterface),
|
|
106
|
-
_XltTokenModule.
|
|
105
|
+
_XltTokenModule.createEventSinkProvider(options.eventSink),
|
|
107
106
|
_XltTokenModule.stpLogicProvider,
|
|
108
107
|
_XltTokenModule.stpPermLogicProvider,
|
|
109
108
|
_XltTokenModule.initProvider,
|
|
@@ -127,12 +126,16 @@ let XltTokenModule = class XltTokenModule {
|
|
|
127
126
|
};
|
|
128
127
|
}
|
|
129
128
|
static createStrategyProvider(strategy) {
|
|
130
|
-
|
|
129
|
+
if (!strategy) return {
|
|
130
|
+
provide: _xlt_token_core.XLT_TOKEN_STRATEGY,
|
|
131
|
+
useClass: _xlt_token_core.UuidStrategy
|
|
132
|
+
};
|
|
133
|
+
return "useClass" in strategy ? {
|
|
131
134
|
provide: _xlt_token_core.XLT_TOKEN_STRATEGY,
|
|
132
135
|
useClass: strategy.useClass
|
|
133
136
|
} : {
|
|
134
137
|
provide: _xlt_token_core.XLT_TOKEN_STRATEGY,
|
|
135
|
-
|
|
138
|
+
useValue: strategy.useValue
|
|
136
139
|
};
|
|
137
140
|
}
|
|
138
141
|
static createStpInterfaceProvider(stpInterface) {
|
|
@@ -152,10 +155,10 @@ let XltTokenModule = class XltTokenModule {
|
|
|
152
155
|
}
|
|
153
156
|
};
|
|
154
157
|
}
|
|
155
|
-
static
|
|
158
|
+
static createEventSinkProvider(eventSink) {
|
|
156
159
|
return {
|
|
157
|
-
provide: _xlt_token_core.
|
|
158
|
-
useValue:
|
|
160
|
+
provide: _xlt_token_core.XLT_EVENT_SINK,
|
|
161
|
+
useValue: eventSink ?? {}
|
|
159
162
|
};
|
|
160
163
|
}
|
|
161
164
|
};
|
|
@@ -203,59 +206,6 @@ IORedisStore = __decorate([
|
|
|
203
206
|
__decorateMetadata("design:paramtypes", [Object])
|
|
204
207
|
], IORedisStore);
|
|
205
208
|
|
|
206
|
-
//#endregion
|
|
207
|
-
//#region src/token/jwt-strategy.ts
|
|
208
|
-
const require$1 = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
|
|
209
|
-
let jsonwebtoken;
|
|
210
|
-
function getJsonwebtoken() {
|
|
211
|
-
try {
|
|
212
|
-
jsonwebtoken ??= require$1("jsonwebtoken");
|
|
213
|
-
return jsonwebtoken;
|
|
214
|
-
} catch (error) {
|
|
215
|
-
if (error.code === "MODULE_NOT_FOUND") throw new Error("JwtStrategy requires the optional peer dependency \"jsonwebtoken\". Install it in your application with \"pnpm add jsonwebtoken\".");
|
|
216
|
-
throw error;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
let JwtStrategy = class JwtStrategy {
|
|
220
|
-
constructor(config) {
|
|
221
|
-
this.config = config;
|
|
222
|
-
}
|
|
223
|
-
ensureJwtConfig(config) {
|
|
224
|
-
const jwt = (config ?? this.config).jwt;
|
|
225
|
-
if (!jwt || !jwt.secret) throw new Error("JwtStrategy requires jwt config with a secret. Provide { jwt: { secret: \"your-secret\" } } in the module config.");
|
|
226
|
-
return jwt;
|
|
227
|
-
}
|
|
228
|
-
createToken(loginId, config, options) {
|
|
229
|
-
const { sign } = getJsonwebtoken();
|
|
230
|
-
const jwt = this.ensureJwtConfig(config);
|
|
231
|
-
const jti = (0, node_crypto.randomUUID)();
|
|
232
|
-
const resolvedTimeout = options?.timeout ?? config.timeout;
|
|
233
|
-
const hasExpiry = typeof resolvedTimeout === "number" ? resolvedTimeout > 0 : true;
|
|
234
|
-
return sign({
|
|
235
|
-
sub: loginId,
|
|
236
|
-
jti
|
|
237
|
-
}, jwt.secret, {
|
|
238
|
-
algorithm: jwt.algorithm ?? "HS256",
|
|
239
|
-
...jwt.issuer && { issuer: jwt.issuer },
|
|
240
|
-
...jwt.audience && { audience: jwt.audience },
|
|
241
|
-
...hasExpiry && { expiresIn: resolvedTimeout }
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
generateToken(payload) {
|
|
245
|
-
const { sign } = getJsonwebtoken();
|
|
246
|
-
return sign(payload, this.ensureJwtConfig().secret);
|
|
247
|
-
}
|
|
248
|
-
verifyToken(token) {
|
|
249
|
-
const { verify } = getJsonwebtoken();
|
|
250
|
-
return verify(token, this.ensureJwtConfig().secret);
|
|
251
|
-
}
|
|
252
|
-
};
|
|
253
|
-
JwtStrategy = __decorate([
|
|
254
|
-
(0, _nestjs_common.Injectable)(),
|
|
255
|
-
__decorateParam(0, (0, _nestjs_common.Inject)(_xlt_token_core.XLT_TOKEN_CONFIG)),
|
|
256
|
-
__decorateMetadata("design:paramtypes", [Object])
|
|
257
|
-
], JwtStrategy);
|
|
258
|
-
|
|
259
209
|
//#endregion
|
|
260
210
|
//#region src/decorators/xlt-check-login.decorator.ts
|
|
261
211
|
/**
|
|
@@ -333,12 +283,23 @@ var NotLoginException = class NotLoginException extends _nestjs_common.Unauthori
|
|
|
333
283
|
constructor(type, token) {
|
|
334
284
|
super({
|
|
335
285
|
statusCode: 401,
|
|
286
|
+
code: NotLoginException.codeForType(type),
|
|
336
287
|
type,
|
|
337
288
|
message: NotLoginException.describeType(type)
|
|
338
289
|
});
|
|
339
290
|
this.type = type;
|
|
340
291
|
this.token = token;
|
|
341
292
|
}
|
|
293
|
+
static codeForType(type) {
|
|
294
|
+
return {
|
|
295
|
+
[_xlt_token_core.NotLoginType.NOT_TOKEN]: "TOKEN_MISSING",
|
|
296
|
+
[_xlt_token_core.NotLoginType.INVALID_TOKEN]: "TOKEN_INVALID",
|
|
297
|
+
[_xlt_token_core.NotLoginType.TOKEN_TIMEOUT]: "TOKEN_TIMEOUT",
|
|
298
|
+
[_xlt_token_core.NotLoginType.TOKEN_FREEZE]: "TOKEN_FREEZE",
|
|
299
|
+
[_xlt_token_core.NotLoginType.BE_REPLACED]: "TOKEN_REPLACED",
|
|
300
|
+
[_xlt_token_core.NotLoginType.KICK_OUT]: "TOKEN_KICKED_OUT"
|
|
301
|
+
}[type] ?? "TOKEN_INVALID";
|
|
302
|
+
}
|
|
342
303
|
static describeType(type) {
|
|
343
304
|
return {
|
|
344
305
|
[_xlt_token_core.NotLoginType.NOT_TOKEN]: "未提供 Token",
|
|
@@ -357,7 +318,9 @@ var NotPermissionException = class extends _nestjs_common.ForbiddenException {
|
|
|
357
318
|
constructor(permission, mode) {
|
|
358
319
|
super({
|
|
359
320
|
statusCode: 403,
|
|
360
|
-
|
|
321
|
+
code: "PERMISSION_DENIED",
|
|
322
|
+
permission,
|
|
323
|
+
mode,
|
|
361
324
|
message: `缺少权限: ${Array.isArray(permission) ? permission.join(", ") : permission}`
|
|
362
325
|
});
|
|
363
326
|
this.permission = permission;
|
|
@@ -371,7 +334,9 @@ var NotRoleException = class extends _nestjs_common.ForbiddenException {
|
|
|
371
334
|
constructor(role, mode) {
|
|
372
335
|
super({
|
|
373
336
|
statusCode: 403,
|
|
374
|
-
|
|
337
|
+
code: "ROLE_DENIED",
|
|
338
|
+
role,
|
|
339
|
+
mode,
|
|
375
340
|
message: `缺少角色: ${Array.isArray(role) ? role.join(", ") : role}`
|
|
376
341
|
});
|
|
377
342
|
this.role = role;
|
|
@@ -385,7 +350,8 @@ var NotSafeException = class extends _nestjs_common.ForbiddenException {
|
|
|
385
350
|
constructor(business) {
|
|
386
351
|
super({
|
|
387
352
|
statusCode: 403,
|
|
388
|
-
|
|
353
|
+
code: "SAFE_REQUIRED",
|
|
354
|
+
business,
|
|
389
355
|
message: `二级认证未开启:${business}`
|
|
390
356
|
});
|
|
391
357
|
this.business = business;
|
|
@@ -551,7 +517,7 @@ Object.defineProperty(exports, 'IORedisStore', {
|
|
|
551
517
|
Object.defineProperty(exports, 'JwtStrategy', {
|
|
552
518
|
enumerable: true,
|
|
553
519
|
get: function () {
|
|
554
|
-
return JwtStrategy;
|
|
520
|
+
return _xlt_token_jwt.JwtStrategy;
|
|
555
521
|
}
|
|
556
522
|
});
|
|
557
523
|
exports.LoginId = LoginId;
|
|
@@ -603,6 +569,12 @@ Object.defineProperty(exports, 'UuidStrategy', {
|
|
|
603
569
|
}
|
|
604
570
|
});
|
|
605
571
|
exports.XLT_CHECK_SAFE_KEY = XLT_CHECK_SAFE_KEY;
|
|
572
|
+
Object.defineProperty(exports, 'XLT_EVENT_SINK', {
|
|
573
|
+
enumerable: true,
|
|
574
|
+
get: function () {
|
|
575
|
+
return _xlt_token_core.XLT_EVENT_SINK;
|
|
576
|
+
}
|
|
577
|
+
});
|
|
606
578
|
exports.XLT_IOREDIS_CLIENT = XLT_IOREDIS_CLIENT;
|
|
607
579
|
exports.XLT_REDIS_CLIENT = XLT_REDIS_CLIENT;
|
|
608
580
|
Object.defineProperty(exports, 'XLT_STP_INTERFACE', {
|
|
@@ -617,12 +589,6 @@ Object.defineProperty(exports, 'XLT_TOKEN_CONFIG', {
|
|
|
617
589
|
return _xlt_token_core.XLT_TOKEN_CONFIG;
|
|
618
590
|
}
|
|
619
591
|
});
|
|
620
|
-
Object.defineProperty(exports, 'XLT_TOKEN_HOOKS', {
|
|
621
|
-
enumerable: true,
|
|
622
|
-
get: function () {
|
|
623
|
-
return _xlt_token_core.XLT_TOKEN_HOOKS;
|
|
624
|
-
}
|
|
625
|
-
});
|
|
626
592
|
Object.defineProperty(exports, 'XLT_TOKEN_STORE', {
|
|
627
593
|
enumerable: true,
|
|
628
594
|
get: function () {
|
|
@@ -676,6 +642,12 @@ Object.defineProperty(exports, 'createExpressContext', {
|
|
|
676
642
|
return _xlt_token_core.createExpressContext;
|
|
677
643
|
}
|
|
678
644
|
});
|
|
645
|
+
Object.defineProperty(exports, 'createJwtStrategyConfig', {
|
|
646
|
+
enumerable: true,
|
|
647
|
+
get: function () {
|
|
648
|
+
return _xlt_token_jwt.createJwtStrategyConfig;
|
|
649
|
+
}
|
|
650
|
+
});
|
|
679
651
|
Object.defineProperty(exports, 'createMockHttpContext', {
|
|
680
652
|
enumerable: true,
|
|
681
653
|
get: function () {
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as _nestjs_common0 from "@nestjs/common";
|
|
2
2
|
import { CanActivate, ExecutionContext, ForbiddenException, ModuleMetadata, Provider, UnauthorizedException } from "@nestjs/common";
|
|
3
|
-
import { AuthResult, CreateOptions, DEFAULT_XLT_TOKEN_CONFIG, DeviceInfo,
|
|
3
|
+
import { AuthResult, CreateOptions, DEFAULT_XLT_TOKEN_CONFIG, DeviceInfo, HttpContext, MemoryStore, NotLoginType, NotLoginType as NotLoginType$1, StpInterface, StpInterface as StpInterface$1, StpLogic, StpLogic as StpLogic$1, StpPermLogic, StpPermLogic as StpPermLogic$1, StpUtil, TokenStrategy, TokenStrategy as TokenStrategy$1, UuidStrategy, XLT_EVENT_SINK, XLT_STP_INTERFACE, XLT_TOKEN_CONFIG, XLT_TOKEN_STORE, XLT_TOKEN_STRATEGY, XltAuditEvent, XltEventSink, XltEventSink as XltEventSink$1, XltMode, XltMode as XltMode$1, XltSession, XltTokenConfig, XltTokenConfig as XltTokenConfig$1, XltTokenConfigInput, XltTokenContext, XltTokenStore, XltTokenStore as XltTokenStore$1, createExpressContext, createMockHttpContext, createXltToken, matchPermission, setStpLogic, setStpPermLogic } from "@xlt-token/core";
|
|
4
4
|
import { IORedisClient, IORedisStore as IORedisStore$1, RedisClient, RedisStore as RedisStore$1 } from "@xlt-token/store-redis";
|
|
5
|
+
import { JwtAlgorithm, JwtAudience, JwtKey, JwtKeyInput, JwtStrategy, JwtStrategyConfig, JwtStrategyConfigInput, XltJwtPayload, createJwtStrategyConfig } from "@xlt-token/jwt";
|
|
5
6
|
import { Reflector } from "@nestjs/core";
|
|
6
7
|
|
|
7
8
|
//#region src/xlt-token.module.d.ts
|
|
@@ -14,13 +15,15 @@ interface XltTokenModuleOptions {
|
|
|
14
15
|
};
|
|
15
16
|
strategy?: {
|
|
16
17
|
useClass: new (...args: any[]) => TokenStrategy$1;
|
|
18
|
+
} | {
|
|
19
|
+
useValue: TokenStrategy$1;
|
|
17
20
|
};
|
|
18
21
|
isGlobal?: boolean;
|
|
19
22
|
providers?: Provider[];
|
|
20
23
|
stpInterface?: new (...args: any[]) => StpInterface$1;
|
|
21
|
-
|
|
24
|
+
eventSink?: XltEventSink$1;
|
|
22
25
|
}
|
|
23
|
-
interface XltTokenModuleAsyncOptions extends Pick<ModuleMetadata,
|
|
26
|
+
interface XltTokenModuleAsyncOptions extends Pick<ModuleMetadata, "imports"> {
|
|
24
27
|
useFactory: (...args: any[]) => Promise<XltTokenModuleOptions> | XltTokenModuleOptions;
|
|
25
28
|
inject?: any[];
|
|
26
29
|
store?: {
|
|
@@ -30,11 +33,13 @@ interface XltTokenModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
|
|
|
30
33
|
};
|
|
31
34
|
strategy?: {
|
|
32
35
|
useClass: new (...args: any[]) => TokenStrategy$1;
|
|
36
|
+
} | {
|
|
37
|
+
useValue: TokenStrategy$1;
|
|
33
38
|
};
|
|
34
39
|
isGlobal?: boolean;
|
|
35
40
|
providers?: Provider[];
|
|
36
41
|
stpInterface?: new (...args: any[]) => StpInterface$1;
|
|
37
|
-
|
|
42
|
+
eventSink?: XltEventSink$1;
|
|
38
43
|
}
|
|
39
44
|
declare class XltTokenModule {
|
|
40
45
|
private static readonly stpLogicProvider;
|
|
@@ -61,7 +66,7 @@ declare class XltTokenModule {
|
|
|
61
66
|
private static createStoreProvider;
|
|
62
67
|
private static createStrategyProvider;
|
|
63
68
|
private static createStpInterfaceProvider;
|
|
64
|
-
private static
|
|
69
|
+
private static createEventSinkProvider;
|
|
65
70
|
}
|
|
66
71
|
//#endregion
|
|
67
72
|
//#region src/store/redis-store.d.ts
|
|
@@ -84,22 +89,6 @@ declare class IORedisStore extends IORedisStore$1 {
|
|
|
84
89
|
constructor(redisClient: IORedisClient);
|
|
85
90
|
}
|
|
86
91
|
//#endregion
|
|
87
|
-
//#region src/token/jwt-strategy.d.ts
|
|
88
|
-
type XltJwtPayload = Record<string, any> & {
|
|
89
|
-
sub: string;
|
|
90
|
-
jti: string;
|
|
91
|
-
};
|
|
92
|
-
declare class JwtStrategy implements TokenStrategy$1<XltJwtPayload> {
|
|
93
|
-
private readonly config;
|
|
94
|
-
constructor(config: XltTokenConfig$1);
|
|
95
|
-
private ensureJwtConfig;
|
|
96
|
-
createToken(loginId: string, config: XltTokenConfig$1, options?: {
|
|
97
|
-
timeout?: DurationInput;
|
|
98
|
-
}): string;
|
|
99
|
-
generateToken(payload: any): string;
|
|
100
|
-
verifyToken(token: string): XltJwtPayload;
|
|
101
|
-
}
|
|
102
|
-
//#endregion
|
|
103
92
|
//#region src/decorators/xlt-check-login.decorator.d.ts
|
|
104
93
|
/**
|
|
105
94
|
* 登录校验装饰器
|
|
@@ -197,6 +186,7 @@ declare class NotLoginException extends UnauthorizedException {
|
|
|
197
186
|
readonly type: NotLoginType$1;
|
|
198
187
|
readonly token: string | undefined;
|
|
199
188
|
constructor(type: NotLoginType$1, token?: string);
|
|
189
|
+
private static codeForType;
|
|
200
190
|
private static describeType;
|
|
201
191
|
}
|
|
202
192
|
//#endregion
|
|
@@ -220,5 +210,5 @@ declare class NotSafeException extends ForbiddenException {
|
|
|
220
210
|
constructor(business: string);
|
|
221
211
|
}
|
|
222
212
|
//#endregion
|
|
223
|
-
export { type AuthResult, type CreateOptions, DEFAULT_XLT_TOKEN_CONFIG, type DeviceInfo, type HttpContext, IORedisStore, JwtStrategy, LoginId, MemoryStore, NotLoginException, NotLoginType, NotPermissionException, NotRoleException, NotSafeException, RedisStore, type StpInterface, StpLogic, StpPermLogic, StpUtil, type TokenStrategy, TokenValue, UuidStrategy, XLT_CHECK_SAFE_KEY, XLT_IOREDIS_CLIENT, XLT_REDIS_CLIENT, XLT_STP_INTERFACE, XLT_TOKEN_CONFIG,
|
|
213
|
+
export { type AuthResult, type CreateOptions, DEFAULT_XLT_TOKEN_CONFIG, type DeviceInfo, type HttpContext, IORedisStore, type JwtAlgorithm, type JwtAudience, type JwtKey, type JwtKeyInput, JwtStrategy, type JwtStrategyConfig, type JwtStrategyConfigInput, LoginId, MemoryStore, NotLoginException, NotLoginType, NotPermissionException, NotRoleException, NotSafeException, RedisStore, type StpInterface, StpLogic, StpPermLogic, StpUtil, type TokenStrategy, TokenValue, UuidStrategy, XLT_CHECK_SAFE_KEY, XLT_EVENT_SINK, XLT_IOREDIS_CLIENT, XLT_REDIS_CLIENT, XLT_STP_INTERFACE, XLT_TOKEN_CONFIG, XLT_TOKEN_STORE, XLT_TOKEN_STRATEGY, XltAbstractLoginGuard, type XltAuditEvent, XltCheckLogin, XltCheckPermission, XltCheckRole, XltCheckSafe, type XltEventSink, XltIgnore, type XltJwtPayload, XltMode, XltSession, type XltTokenConfig, type XltTokenContext, XltTokenGuard, XltTokenModule, type XltTokenModuleAsyncOptions, type XltTokenModuleOptions, type XltTokenStore, createExpressContext, createJwtStrategyConfig, createMockHttpContext, createXltToken, matchPermission, setStpLogic, setStpPermLogic };
|
|
224
214
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/xlt-token.module.ts","../src/store/redis-store.ts","../src/store/ioredis-store.ts","../src/
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/xlt-token.module.ts","../src/store/redis-store.ts","../src/store/ioredis-store.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/guards/xlt-token.guard.ts","../src/guards/xlt-abstract-login.guard.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"],"mappings":";;;;;;;;UAyBiB,qBAAA;EACf,MAAA,GAAS,OAAA,CAAQ,mBAAA;EACjB,KAAA;IAAU,QAAA,UAAkB,IAAA,YAAgB,eAAA;EAAA;IAAoB,QAAA,EAAU,eAAA;EAAA;EAC1E,QAAA;IAAa,QAAA,UAAkB,IAAA,YAAgB,eAAA;EAAA;IAAoB,QAAA,EAAU,eAAA;EAAA;EAC7E,QAAA;EACA,SAAA,GAAY,QAAA;EACZ,YAAA,WAAuB,IAAA,YAAgB,cAAA;EACvC,SAAA,GAAY,cAAA;AAAA;AAAA,UAGG,0BAAA,SAAmC,IAAA,CAAK,cAAA;EACvD,UAAA,MAAgB,IAAA,YAAgB,OAAA,CAAQ,qBAAA,IAAyB,qBAAA;EACjE,MAAA;EACA,KAAA;IAAU,QAAA,UAAkB,IAAA,YAAgB,eAAA;EAAA;IAAoB,QAAA,EAAU,eAAA;EAAA;EAC1E,QAAA;IAAa,QAAA,UAAkB,IAAA,YAAgB,eAAA;EAAA;IAAoB,QAAA,EAAU,eAAA;EAAA;EAC7E,QAAA;EACA,SAAA,GAAY,QAAA;EACZ,YAAA,WAAuB,IAAA,YAAgB,cAAA;EACvC,SAAA,GAAY,cAAA;AAAA;AAAA,cAID,cAAA;EAAA,wBACa,gBAAA;EAAA,wBAUA,oBAAA;EAAA,wBAMA,YAAA;EAAA,wBASA,aAAA;EAAA,OAQjB,OAAA,CAAQ,OAAA,GAAS,qBAAA;;;;;;SA4BjB,YAAA,CAAa,OAAA,EAAS,0BAAA;;;;;sCAkBY,OAAA,CAAA,gBAAA;;;;;;iBAoB1B,mBAAA;E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EAAK,gBAAA,GAAmB,OAAA;EAAA,UAuBhC,aAAA,CAAc,GAAA,EAAK,gBAAA;EAAA,UAgBnB,aAAA,CAAA,CACR,MAAA;IACE,EAAA;IACA,OAAA;IACA,KAAA;IACA,MAAA,GAAS,cAAA;EAAA,GAEX,OAAA,eACQ,OAAA;EAAA,UAEA,UAAA,CAAA,CACR,MAAA;IACE,EAAA;IACA,OAAA;IACA,KAAA;IACA,MAAA,GAAS,cAAA;EAAA,GAEX,OAAA,eACQ,OAAA;EAAA,UAEA,kBAAA,CAAA,CACR,MAAA;IACE,EAAA;IACA,OAAA;IACA,KAAA;IACA,MAAA,GAAS,cAAA;EAAA,GAEX,OAAA,eACQ,OAAA;AAAA;;;cCtFC,iBAAA,SAA0B,qBAAA;EAAA,SACrB,IAAA,EAAM,cAAA;EAAA,SACN,KAAA;cAEJ,IAAA,EAAM,cAAA,EAAc,KAAA;EAAA,eAWjB,WAAA;EAAA,eAYA,YAAA;AAAA;;;cC3BJ,sBAAA,SAA+B,kBAAA;EAAA,SAC1B,UAAA;EAAA,SACA,IAAA,EAAM,SAAA;cAEV,UAAA,qBAA+B,IAAA,EAAM,SAAA;AAAA;;;cCJtC,gBAAA,SAAyB,kBAAA;EAAA,SACpB,IAAA;EAAA,SACA,IAAA,EAAM,SAAA;cAEV,IAAA,qBAAyB,IAAA,EAAM,SAAA;AAAA;;;cCLhC,gBAAA,SAAyB,kBAAA;EAAA,SAC3B,QAAA;cAEG,QAAA;AAAA"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as _nestjs_common0 from "@nestjs/common";
|
|
2
2
|
import { CanActivate, ExecutionContext, ForbiddenException, ModuleMetadata, Provider, UnauthorizedException } from "@nestjs/common";
|
|
3
|
-
import { AuthResult, CreateOptions, DEFAULT_XLT_TOKEN_CONFIG, DeviceInfo,
|
|
3
|
+
import { AuthResult, CreateOptions, DEFAULT_XLT_TOKEN_CONFIG, DeviceInfo, HttpContext, MemoryStore, NotLoginType, NotLoginType as NotLoginType$1, StpInterface, StpInterface as StpInterface$1, StpLogic, StpLogic as StpLogic$1, StpPermLogic, StpPermLogic as StpPermLogic$1, StpUtil, TokenStrategy, TokenStrategy as TokenStrategy$1, UuidStrategy, XLT_EVENT_SINK, XLT_STP_INTERFACE, XLT_TOKEN_CONFIG, XLT_TOKEN_STORE, XLT_TOKEN_STRATEGY, XltAuditEvent, XltEventSink, XltEventSink as XltEventSink$1, XltMode, XltMode as XltMode$1, XltSession, XltTokenConfig, XltTokenConfig as XltTokenConfig$1, XltTokenConfigInput, XltTokenContext, XltTokenStore, XltTokenStore as XltTokenStore$1, createExpressContext, createMockHttpContext, createXltToken, matchPermission, setStpLogic, setStpPermLogic } from "@xlt-token/core";
|
|
4
4
|
import { IORedisClient, IORedisStore as IORedisStore$1, RedisClient, RedisStore as RedisStore$1 } from "@xlt-token/store-redis";
|
|
5
|
+
import { JwtAlgorithm, JwtAudience, JwtKey, JwtKeyInput, JwtStrategy, JwtStrategyConfig, JwtStrategyConfigInput, XltJwtPayload, createJwtStrategyConfig } from "@xlt-token/jwt";
|
|
5
6
|
import { Reflector } from "@nestjs/core";
|
|
6
7
|
|
|
7
8
|
//#region src/xlt-token.module.d.ts
|
|
@@ -14,13 +15,15 @@ interface XltTokenModuleOptions {
|
|
|
14
15
|
};
|
|
15
16
|
strategy?: {
|
|
16
17
|
useClass: new (...args: any[]) => TokenStrategy$1;
|
|
18
|
+
} | {
|
|
19
|
+
useValue: TokenStrategy$1;
|
|
17
20
|
};
|
|
18
21
|
isGlobal?: boolean;
|
|
19
22
|
providers?: Provider[];
|
|
20
23
|
stpInterface?: new (...args: any[]) => StpInterface$1;
|
|
21
|
-
|
|
24
|
+
eventSink?: XltEventSink$1;
|
|
22
25
|
}
|
|
23
|
-
interface XltTokenModuleAsyncOptions extends Pick<ModuleMetadata,
|
|
26
|
+
interface XltTokenModuleAsyncOptions extends Pick<ModuleMetadata, "imports"> {
|
|
24
27
|
useFactory: (...args: any[]) => Promise<XltTokenModuleOptions> | XltTokenModuleOptions;
|
|
25
28
|
inject?: any[];
|
|
26
29
|
store?: {
|
|
@@ -30,11 +33,13 @@ interface XltTokenModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
|
|
|
30
33
|
};
|
|
31
34
|
strategy?: {
|
|
32
35
|
useClass: new (...args: any[]) => TokenStrategy$1;
|
|
36
|
+
} | {
|
|
37
|
+
useValue: TokenStrategy$1;
|
|
33
38
|
};
|
|
34
39
|
isGlobal?: boolean;
|
|
35
40
|
providers?: Provider[];
|
|
36
41
|
stpInterface?: new (...args: any[]) => StpInterface$1;
|
|
37
|
-
|
|
42
|
+
eventSink?: XltEventSink$1;
|
|
38
43
|
}
|
|
39
44
|
declare class XltTokenModule {
|
|
40
45
|
private static readonly stpLogicProvider;
|
|
@@ -61,7 +66,7 @@ declare class XltTokenModule {
|
|
|
61
66
|
private static createStoreProvider;
|
|
62
67
|
private static createStrategyProvider;
|
|
63
68
|
private static createStpInterfaceProvider;
|
|
64
|
-
private static
|
|
69
|
+
private static createEventSinkProvider;
|
|
65
70
|
}
|
|
66
71
|
//#endregion
|
|
67
72
|
//#region src/store/redis-store.d.ts
|
|
@@ -84,22 +89,6 @@ declare class IORedisStore extends IORedisStore$1 {
|
|
|
84
89
|
constructor(redisClient: IORedisClient);
|
|
85
90
|
}
|
|
86
91
|
//#endregion
|
|
87
|
-
//#region src/token/jwt-strategy.d.ts
|
|
88
|
-
type XltJwtPayload = Record<string, any> & {
|
|
89
|
-
sub: string;
|
|
90
|
-
jti: string;
|
|
91
|
-
};
|
|
92
|
-
declare class JwtStrategy implements TokenStrategy$1<XltJwtPayload> {
|
|
93
|
-
private readonly config;
|
|
94
|
-
constructor(config: XltTokenConfig$1);
|
|
95
|
-
private ensureJwtConfig;
|
|
96
|
-
createToken(loginId: string, config: XltTokenConfig$1, options?: {
|
|
97
|
-
timeout?: DurationInput;
|
|
98
|
-
}): string;
|
|
99
|
-
generateToken(payload: any): string;
|
|
100
|
-
verifyToken(token: string): XltJwtPayload;
|
|
101
|
-
}
|
|
102
|
-
//#endregion
|
|
103
92
|
//#region src/decorators/xlt-check-login.decorator.d.ts
|
|
104
93
|
/**
|
|
105
94
|
* 登录校验装饰器
|
|
@@ -197,6 +186,7 @@ declare class NotLoginException extends UnauthorizedException {
|
|
|
197
186
|
readonly type: NotLoginType$1;
|
|
198
187
|
readonly token: string | undefined;
|
|
199
188
|
constructor(type: NotLoginType$1, token?: string);
|
|
189
|
+
private static codeForType;
|
|
200
190
|
private static describeType;
|
|
201
191
|
}
|
|
202
192
|
//#endregion
|
|
@@ -220,5 +210,5 @@ declare class NotSafeException extends ForbiddenException {
|
|
|
220
210
|
constructor(business: string);
|
|
221
211
|
}
|
|
222
212
|
//#endregion
|
|
223
|
-
export { type AuthResult, type CreateOptions, DEFAULT_XLT_TOKEN_CONFIG, type DeviceInfo, type HttpContext, IORedisStore, JwtStrategy, LoginId, MemoryStore, NotLoginException, NotLoginType, NotPermissionException, NotRoleException, NotSafeException, RedisStore, type StpInterface, StpLogic, StpPermLogic, StpUtil, type TokenStrategy, TokenValue, UuidStrategy, XLT_CHECK_SAFE_KEY, XLT_IOREDIS_CLIENT, XLT_REDIS_CLIENT, XLT_STP_INTERFACE, XLT_TOKEN_CONFIG,
|
|
213
|
+
export { type AuthResult, type CreateOptions, DEFAULT_XLT_TOKEN_CONFIG, type DeviceInfo, type HttpContext, IORedisStore, type JwtAlgorithm, type JwtAudience, type JwtKey, type JwtKeyInput, JwtStrategy, type JwtStrategyConfig, type JwtStrategyConfigInput, LoginId, MemoryStore, NotLoginException, NotLoginType, NotPermissionException, NotRoleException, NotSafeException, RedisStore, type StpInterface, StpLogic, StpPermLogic, StpUtil, type TokenStrategy, TokenValue, UuidStrategy, XLT_CHECK_SAFE_KEY, XLT_EVENT_SINK, XLT_IOREDIS_CLIENT, XLT_REDIS_CLIENT, XLT_STP_INTERFACE, XLT_TOKEN_CONFIG, XLT_TOKEN_STORE, XLT_TOKEN_STRATEGY, XltAbstractLoginGuard, type XltAuditEvent, XltCheckLogin, XltCheckPermission, XltCheckRole, XltCheckSafe, type XltEventSink, XltIgnore, type XltJwtPayload, XltMode, XltSession, type XltTokenConfig, type XltTokenContext, XltTokenGuard, XltTokenModule, type XltTokenModuleAsyncOptions, type XltTokenModuleOptions, type XltTokenStore, createExpressContext, createJwtStrategyConfig, createMockHttpContext, createXltToken, matchPermission, setStpLogic, setStpPermLogic };
|
|
224
214
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/xlt-token.module.ts","../src/store/redis-store.ts","../src/store/ioredis-store.ts","../src/
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/xlt-token.module.ts","../src/store/redis-store.ts","../src/store/ioredis-store.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/guards/xlt-token.guard.ts","../src/guards/xlt-abstract-login.guard.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"],"mappings":";;;;;;;;UAyBiB,qBAAA;EACf,MAAA,GAAS,OAAA,CAAQ,mBAAA;EACjB,KAAA;IAAU,QAAA,UAAkB,IAAA,YAAgB,eAAA;EAAA;IAAoB,QAAA,EAAU,eAAA;EAAA;EAC1E,QAAA;IAAa,QAAA,UAAkB,IAAA,YAAgB,eAAA;EAAA;IAAoB,QAAA,EAAU,eAAA;EAAA;EAC7E,QAAA;EACA,SAAA,GAAY,QAAA;EACZ,YAAA,WAAuB,IAAA,YAAgB,cAAA;EACvC,SAAA,GAAY,cAAA;AAA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eAYA,YAAA;AAAA;;;cC3BJ,sBAAA,SAA+B,kBAAA;EAAA,SAC1B,UAAA;EAAA,SACA,IAAA,EAAM,SAAA;cAEV,UAAA,qBAA+B,IAAA,EAAM,SAAA;AAAA;;;cCJtC,gBAAA,SAAyB,kBAAA;EAAA,SACpB,IAAA;EAAA,SACA,IAAA,EAAM,SAAA;cAEV,IAAA,qBAAyB,IAAA,EAAM,SAAA;AAAA;;;cCLhC,gBAAA,SAAyB,kBAAA;EAAA,SAC3B,QAAA;cAEG,QAAA;AAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
1
|
import { ForbiddenException, Inject, Injectable, Module, Optional, SetMetadata, UnauthorizedException, createParamDecorator } from "@nestjs/common";
|
|
3
|
-
import { DEFAULT_XLT_TOKEN_CONFIG, 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,
|
|
2
|
+
import { DEFAULT_XLT_TOKEN_CONFIG, 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_EVENT_SINK, XLT_EVENT_SINK as XLT_EVENT_SINK$1, 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_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, createExpressContext, createExpressContext as createExpressContext$1, createMockHttpContext, createXltToken, matchPermission, normalizeXltTokenConfig, setStpLogic, setStpLogic as setStpLogic$1, setStpPermLogic, setStpPermLogic as setStpPermLogic$1 } from "@xlt-token/core";
|
|
4
3
|
import { IORedisStore as IORedisStore$1, RedisStore as RedisStore$1 } from "@xlt-token/store-redis";
|
|
5
|
-
import {
|
|
4
|
+
import { JwtStrategy, createJwtStrategyConfig } from "@xlt-token/jwt";
|
|
6
5
|
import { Reflector } from "@nestjs/core";
|
|
7
6
|
|
|
8
7
|
//#region \0@oxc-project+runtime@0.112.0/helpers/decorate.js
|
|
@@ -23,12 +22,12 @@ let XltTokenModule = class XltTokenModule {
|
|
|
23
22
|
static {
|
|
24
23
|
this.stpLogicProvider = {
|
|
25
24
|
provide: StpLogic$1,
|
|
26
|
-
useFactory: (config, store, strategy,
|
|
25
|
+
useFactory: (config, store, strategy, eventSink) => new StpLogic$1(config, store, strategy, eventSink),
|
|
27
26
|
inject: [
|
|
28
27
|
XLT_TOKEN_CONFIG$1,
|
|
29
28
|
XLT_TOKEN_STORE$1,
|
|
30
29
|
XLT_TOKEN_STRATEGY$1,
|
|
31
|
-
|
|
30
|
+
XLT_EVENT_SINK$1
|
|
32
31
|
]
|
|
33
32
|
};
|
|
34
33
|
}
|
|
@@ -75,7 +74,7 @@ let XltTokenModule = class XltTokenModule {
|
|
|
75
74
|
_XltTokenModule.createStoreProvider(store),
|
|
76
75
|
_XltTokenModule.createStrategyProvider(strategy),
|
|
77
76
|
_XltTokenModule.createStpInterfaceProvider(stpInterface),
|
|
78
|
-
_XltTokenModule.
|
|
77
|
+
_XltTokenModule.createEventSinkProvider(options.eventSink),
|
|
79
78
|
_XltTokenModule.stpLogicProvider,
|
|
80
79
|
_XltTokenModule.stpPermLogicProvider,
|
|
81
80
|
_XltTokenModule.initProvider,
|
|
@@ -102,7 +101,7 @@ let XltTokenModule = class XltTokenModule {
|
|
|
102
101
|
_XltTokenModule.createStoreProvider(store),
|
|
103
102
|
_XltTokenModule.createStrategyProvider(strategy),
|
|
104
103
|
_XltTokenModule.createStpInterfaceProvider(stpInterface),
|
|
105
|
-
_XltTokenModule.
|
|
104
|
+
_XltTokenModule.createEventSinkProvider(options.eventSink),
|
|
106
105
|
_XltTokenModule.stpLogicProvider,
|
|
107
106
|
_XltTokenModule.stpPermLogicProvider,
|
|
108
107
|
_XltTokenModule.initProvider,
|
|
@@ -126,12 +125,16 @@ let XltTokenModule = class XltTokenModule {
|
|
|
126
125
|
};
|
|
127
126
|
}
|
|
128
127
|
static createStrategyProvider(strategy) {
|
|
129
|
-
|
|
128
|
+
if (!strategy) return {
|
|
129
|
+
provide: XLT_TOKEN_STRATEGY$1,
|
|
130
|
+
useClass: UuidStrategy$1
|
|
131
|
+
};
|
|
132
|
+
return "useClass" in strategy ? {
|
|
130
133
|
provide: XLT_TOKEN_STRATEGY$1,
|
|
131
134
|
useClass: strategy.useClass
|
|
132
135
|
} : {
|
|
133
136
|
provide: XLT_TOKEN_STRATEGY$1,
|
|
134
|
-
|
|
137
|
+
useValue: strategy.useValue
|
|
135
138
|
};
|
|
136
139
|
}
|
|
137
140
|
static createStpInterfaceProvider(stpInterface) {
|
|
@@ -151,10 +154,10 @@ let XltTokenModule = class XltTokenModule {
|
|
|
151
154
|
}
|
|
152
155
|
};
|
|
153
156
|
}
|
|
154
|
-
static
|
|
157
|
+
static createEventSinkProvider(eventSink) {
|
|
155
158
|
return {
|
|
156
|
-
provide:
|
|
157
|
-
useValue:
|
|
159
|
+
provide: XLT_EVENT_SINK$1,
|
|
160
|
+
useValue: eventSink ?? {}
|
|
158
161
|
};
|
|
159
162
|
}
|
|
160
163
|
};
|
|
@@ -202,59 +205,6 @@ IORedisStore = __decorate([
|
|
|
202
205
|
__decorateMetadata("design:paramtypes", [Object])
|
|
203
206
|
], IORedisStore);
|
|
204
207
|
|
|
205
|
-
//#endregion
|
|
206
|
-
//#region src/token/jwt-strategy.ts
|
|
207
|
-
const require = createRequire(import.meta.url);
|
|
208
|
-
let jsonwebtoken;
|
|
209
|
-
function getJsonwebtoken() {
|
|
210
|
-
try {
|
|
211
|
-
jsonwebtoken ??= require("jsonwebtoken");
|
|
212
|
-
return jsonwebtoken;
|
|
213
|
-
} catch (error) {
|
|
214
|
-
if (error.code === "MODULE_NOT_FOUND") throw new Error("JwtStrategy requires the optional peer dependency \"jsonwebtoken\". Install it in your application with \"pnpm add jsonwebtoken\".");
|
|
215
|
-
throw error;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
let JwtStrategy = class JwtStrategy {
|
|
219
|
-
constructor(config) {
|
|
220
|
-
this.config = config;
|
|
221
|
-
}
|
|
222
|
-
ensureJwtConfig(config) {
|
|
223
|
-
const jwt = (config ?? this.config).jwt;
|
|
224
|
-
if (!jwt || !jwt.secret) throw new Error("JwtStrategy requires jwt config with a secret. Provide { jwt: { secret: \"your-secret\" } } in the module config.");
|
|
225
|
-
return jwt;
|
|
226
|
-
}
|
|
227
|
-
createToken(loginId, config, options) {
|
|
228
|
-
const { sign } = getJsonwebtoken();
|
|
229
|
-
const jwt = this.ensureJwtConfig(config);
|
|
230
|
-
const jti = randomUUID();
|
|
231
|
-
const resolvedTimeout = options?.timeout ?? config.timeout;
|
|
232
|
-
const hasExpiry = typeof resolvedTimeout === "number" ? resolvedTimeout > 0 : true;
|
|
233
|
-
return sign({
|
|
234
|
-
sub: loginId,
|
|
235
|
-
jti
|
|
236
|
-
}, jwt.secret, {
|
|
237
|
-
algorithm: jwt.algorithm ?? "HS256",
|
|
238
|
-
...jwt.issuer && { issuer: jwt.issuer },
|
|
239
|
-
...jwt.audience && { audience: jwt.audience },
|
|
240
|
-
...hasExpiry && { expiresIn: resolvedTimeout }
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
generateToken(payload) {
|
|
244
|
-
const { sign } = getJsonwebtoken();
|
|
245
|
-
return sign(payload, this.ensureJwtConfig().secret);
|
|
246
|
-
}
|
|
247
|
-
verifyToken(token) {
|
|
248
|
-
const { verify } = getJsonwebtoken();
|
|
249
|
-
return verify(token, this.ensureJwtConfig().secret);
|
|
250
|
-
}
|
|
251
|
-
};
|
|
252
|
-
JwtStrategy = __decorate([
|
|
253
|
-
Injectable(),
|
|
254
|
-
__decorateParam(0, Inject(XLT_TOKEN_CONFIG$1)),
|
|
255
|
-
__decorateMetadata("design:paramtypes", [Object])
|
|
256
|
-
], JwtStrategy);
|
|
257
|
-
|
|
258
208
|
//#endregion
|
|
259
209
|
//#region src/decorators/xlt-check-login.decorator.ts
|
|
260
210
|
/**
|
|
@@ -332,12 +282,23 @@ var NotLoginException = class NotLoginException extends UnauthorizedException {
|
|
|
332
282
|
constructor(type, token) {
|
|
333
283
|
super({
|
|
334
284
|
statusCode: 401,
|
|
285
|
+
code: NotLoginException.codeForType(type),
|
|
335
286
|
type,
|
|
336
287
|
message: NotLoginException.describeType(type)
|
|
337
288
|
});
|
|
338
289
|
this.type = type;
|
|
339
290
|
this.token = token;
|
|
340
291
|
}
|
|
292
|
+
static codeForType(type) {
|
|
293
|
+
return {
|
|
294
|
+
[NotLoginType$1.NOT_TOKEN]: "TOKEN_MISSING",
|
|
295
|
+
[NotLoginType$1.INVALID_TOKEN]: "TOKEN_INVALID",
|
|
296
|
+
[NotLoginType$1.TOKEN_TIMEOUT]: "TOKEN_TIMEOUT",
|
|
297
|
+
[NotLoginType$1.TOKEN_FREEZE]: "TOKEN_FREEZE",
|
|
298
|
+
[NotLoginType$1.BE_REPLACED]: "TOKEN_REPLACED",
|
|
299
|
+
[NotLoginType$1.KICK_OUT]: "TOKEN_KICKED_OUT"
|
|
300
|
+
}[type] ?? "TOKEN_INVALID";
|
|
301
|
+
}
|
|
341
302
|
static describeType(type) {
|
|
342
303
|
return {
|
|
343
304
|
[NotLoginType$1.NOT_TOKEN]: "未提供 Token",
|
|
@@ -356,7 +317,9 @@ var NotPermissionException = class extends ForbiddenException {
|
|
|
356
317
|
constructor(permission, mode) {
|
|
357
318
|
super({
|
|
358
319
|
statusCode: 403,
|
|
359
|
-
|
|
320
|
+
code: "PERMISSION_DENIED",
|
|
321
|
+
permission,
|
|
322
|
+
mode,
|
|
360
323
|
message: `缺少权限: ${Array.isArray(permission) ? permission.join(", ") : permission}`
|
|
361
324
|
});
|
|
362
325
|
this.permission = permission;
|
|
@@ -370,7 +333,9 @@ var NotRoleException = class extends ForbiddenException {
|
|
|
370
333
|
constructor(role, mode) {
|
|
371
334
|
super({
|
|
372
335
|
statusCode: 403,
|
|
373
|
-
|
|
336
|
+
code: "ROLE_DENIED",
|
|
337
|
+
role,
|
|
338
|
+
mode,
|
|
374
339
|
message: `缺少角色: ${Array.isArray(role) ? role.join(", ") : role}`
|
|
375
340
|
});
|
|
376
341
|
this.role = role;
|
|
@@ -384,7 +349,8 @@ var NotSafeException = class extends ForbiddenException {
|
|
|
384
349
|
constructor(business) {
|
|
385
350
|
super({
|
|
386
351
|
statusCode: 403,
|
|
387
|
-
|
|
352
|
+
code: "SAFE_REQUIRED",
|
|
353
|
+
business,
|
|
388
354
|
message: `二级认证未开启:${business}`
|
|
389
355
|
});
|
|
390
356
|
this.business = business;
|
|
@@ -535,5 +501,5 @@ XltAbstractLoginGuard = __decorate([
|
|
|
535
501
|
], XltAbstractLoginGuard);
|
|
536
502
|
|
|
537
503
|
//#endregion
|
|
538
|
-
export { DEFAULT_XLT_TOKEN_CONFIG, IORedisStore, JwtStrategy, LoginId, MemoryStore, NotLoginException, NotLoginType, NotPermissionException, NotRoleException, NotSafeException, RedisStore, StpLogic, StpPermLogic, StpUtil, TokenValue, UuidStrategy, XLT_CHECK_SAFE_KEY, XLT_IOREDIS_CLIENT, XLT_REDIS_CLIENT, XLT_STP_INTERFACE, XLT_TOKEN_CONFIG,
|
|
504
|
+
export { DEFAULT_XLT_TOKEN_CONFIG, IORedisStore, JwtStrategy, LoginId, MemoryStore, NotLoginException, NotLoginType, NotPermissionException, NotRoleException, NotSafeException, RedisStore, StpLogic, StpPermLogic, StpUtil, TokenValue, UuidStrategy, XLT_CHECK_SAFE_KEY, XLT_EVENT_SINK, XLT_IOREDIS_CLIENT, XLT_REDIS_CLIENT, XLT_STP_INTERFACE, XLT_TOKEN_CONFIG, XLT_TOKEN_STORE, XLT_TOKEN_STRATEGY, XltAbstractLoginGuard, XltCheckLogin, XltCheckPermission, XltCheckRole, XltCheckSafe, XltIgnore, XltMode, XltSession, XltTokenGuard, XltTokenModule, createExpressContext, createJwtStrategyConfig, createMockHttpContext, createXltToken, matchPermission, setStpLogic, setStpPermLogic };
|
|
539
505
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["StpLogic","XLT_TOKEN_CONFIG","XLT_TOKEN_STORE","XLT_TOKEN_STRATEGY","XLT_TOKEN_HOOKS","StpPermLogic","XLT_STP_INTERFACE","MemoryStore","UuidStrategy","BaseRedisStore","BaseIORedisStore","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/store/ioredis-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 type { ModuleMetadata, Provider } from '@nestjs/common';\nimport { Module } from '@nestjs/common';\nimport type { StpInterface, TokenStrategy, XltHooks, XltTokenConfig, XltTokenConfigInput, XltTokenStore, } from '@xlt-token/core';\nimport {\n DEFAULT_XLT_TOKEN_CONFIG,\n MemoryStore,\n setStpLogic,\n setStpPermLogic,\n StpLogic,\n StpPermLogic,\n UuidStrategy,\n XLT_STP_INTERFACE,\n XLT_TOKEN_CONFIG,\n XLT_TOKEN_HOOKS,\n XLT_TOKEN_STORE,\n XLT_TOKEN_STRATEGY,\n normalizeXltTokenConfig\n} from '@xlt-token/core';\n\nexport interface XltTokenModuleOptions {\n config?: Partial<XltTokenConfigInput>;\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 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 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 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 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: normalizeXltTokenConfig(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 {\n useFactory,\n inject = [],\n imports = [],\n store,\n strategy,\n isGlobal = false,\n providers = [],\n stpInterface\n } = 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 normalizeXltTokenConfig(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 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: () => {\n throw new Error('StpInterface not registered: getPermissionList');\n },\n getRoleList: () => {\n throw new Error('StpInterface not registered: getRoleList');\n },\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","import { Inject, Injectable } from '@nestjs/common';\nimport {\n RedisStore as BaseRedisStore,\n type RedisClient,\n} from '@xlt-token/store-redis';\n\nexport const XLT_REDIS_CLIENT = 'XLT_REDIS_CLIENT';\n\n/**\n * @deprecated Import `RedisStore` from `@xlt-token/store-redis` and provide it\n * through `store.useValue` for new applications.\n */\n@Injectable()\nexport class RedisStore extends BaseRedisStore {\n constructor(\n @Inject(XLT_REDIS_CLIENT)\n redisClient: RedisClient,\n ) {\n super(redisClient);\n }\n}\n","import { Inject, Injectable } from '@nestjs/common';\nimport {\n IORedisStore as BaseIORedisStore,\n type IORedisClient,\n} from '@xlt-token/store-redis';\n\nexport const XLT_IOREDIS_CLIENT = 'XLT_IOREDIS_CLIENT';\n\n/**\n * @deprecated Import `IORedisStore` from `@xlt-token/store-redis` and provide it\n * through `store.useValue` for new applications.\n */\n@Injectable()\nexport class IORedisStore extends BaseIORedisStore {\n constructor(\n @Inject(XLT_IOREDIS_CLIENT)\n redisClient: IORedisClient,\n ) {\n super(redisClient);\n }\n}\n","import { Inject, Injectable } from \"@nestjs/common\";\nimport { randomUUID } from 'node:crypto';\nimport { createRequire } from 'node:module';\nimport { XLT_TOKEN_CONFIG } from '@xlt-token/core';\nimport type { DurationInput, TokenStrategy, XltTokenConfig } from '@xlt-token/core';\n\nconst require = createRequire(import.meta.url);\n\nlet jsonwebtoken: typeof import('jsonwebtoken') | undefined;\n\nexport type XltJwtPayload = Record<string, any> & { sub: string; jti: string };\n\nfunction getJsonwebtoken(): typeof import('jsonwebtoken') {\n try {\n jsonwebtoken ??= require('jsonwebtoken') as typeof import('jsonwebtoken');\n return jsonwebtoken;\n } catch (error) {\n const err = error as NodeJS.ErrnoException;\n if (err.code === 'MODULE_NOT_FOUND') {\n throw new Error(\n 'JwtStrategy requires the optional peer dependency \"jsonwebtoken\". '\n + 'Install it in your application with \"pnpm add jsonwebtoken\".',\n );\n }\n throw error;\n }\n}\n\n@Injectable()\nexport class JwtStrategy implements TokenStrategy<XltJwtPayload> {\n constructor(\n @Inject(XLT_TOKEN_CONFIG) private readonly config: XltTokenConfig\n ) { }\n\n private ensureJwtConfig(config?: XltTokenConfig): NonNullable<XltTokenConfig['jwt']> {\n const jwt = (config ?? this.config).jwt;\n if (!jwt || !jwt.secret) {\n throw new Error(\n 'JwtStrategy requires jwt config with a secret. '\n + 'Provide { jwt: { secret: \"your-secret\" } } in the module config.',\n );\n }\n return jwt;\n }\n\n createToken(loginId: string, config: XltTokenConfig, options?: { timeout?: DurationInput }): string {\n const { sign } = getJsonwebtoken();\n const jwt = this.ensureJwtConfig(config);\n const jti = randomUUID();\n\n const resolvedTimeout = options?.timeout ?? config.timeout;\n const hasExpiry = typeof resolvedTimeout === 'number' ? resolvedTimeout > 0 : true;\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 ...(hasExpiry && { expiresIn: resolvedTimeout }),\n })\n }\n\n generateToken(payload: any): string {\n const { sign } = getJsonwebtoken();\n const jwt = this.ensureJwtConfig();\n return sign(payload, jwt.secret);\n }\n\n verifyToken(token: string): XltJwtPayload {\n const { verify } = getJsonwebtoken();\n const jwt = this.ensureJwtConfig();\n return verify(token, jwt.secret) as XltJwtPayload;\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 type CookieOptions,\n type ExpressLikeResponse,\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\n/**\n * Fastify reply 的写回 API 与 Express response 不同:\n * - 写 header:Express 用 `res.setHeader(n, v)`,Fastify 用 `reply.header(n, v)`\n * - 写 cookie:Express 用 `res.cookie(n, v, o)`,Fastify 用 `reply.setCookie(n, v, o)`\n *\n * 这里把任意一种 response 归一化成 core 期望的 {@link ExpressLikeResponse} 形态,\n * 让核心层无需感知底层 HTTP 平台。读取侧(headers/cookies/query)两个平台形态一致,\n * 直接复用 core 的 createExpressContext。\n */\nfunction normalizeResponse(res: any): ExpressLikeResponse {\n return {\n setHeader(name: string, value: string): void {\n if (typeof res?.setHeader === 'function') {\n // Express response / 原生 Node 响应\n res.setHeader(name, value);\n } else if (typeof res?.header === 'function') {\n // Fastify reply\n res.header(name, value);\n } else {\n throw new Error(\n 'xlt-token: 当前 response 不支持写入 header(既无 setHeader 也无 header 方法)',\n );\n }\n },\n cookie(name: string, value: string, options?: CookieOptions): void {\n if (typeof res?.cookie === 'function') {\n // Express response(或已注册 @fastify/cookie 暴露的 cookie 别名)\n res.cookie(name, value, options);\n } else if (typeof res?.setCookie === 'function') {\n // Fastify reply + @fastify/cookie 插件\n res.setCookie(name, value, options);\n } else {\n throw new Error(\n 'xlt-token: 当前 response 不支持写入 cookie。'\n + '若使用 Fastify,请先注册 @fastify/cookie 插件。',\n );\n }\n },\n };\n}\n\nexport function createNestHttpContext(req: any, res: any) {\n return createExpressContext(req, normalizeResponse(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":";;;;;;;;;;;;;;;;;;AAyCO,2BAAM,eAAe;;;;;0BAC6B;GACjD,SAASA;GACT,aACI,QACA,OACA,UACA,UACC,IAAIA,WAAS,QAAQ,OAAO,UAAU,MAAM;GACjD,QAAQ;IAAEC;IAAkBC;IAAiBC;IAAoBC;IAAiB;GACrF;;;8BACwD;GACrD,SAASC;GACT,aACI,cACA,OACA,WACC,IAAIA,eAAa,cAAc,OAAO,OAAO;GAClD,QAAQ;IAAEC;IAAmBJ;IAAiBD;IAAkB;GACnE;;;sBACgD;GAC7C,SAAS;GACT,aAAa,UAAoB,iBAA+B;AAC5D,kBAAY,SAAS;AACrB,sBAAgB,aAAa;AAC7B,WAAO;;GAEX,QAAQ,CAAED,YAAUK,eAAc;GACrC;;;uBACuC;GAAEJ;GAAkBC;GAAiBC;GAAoBH;GAAUK;GAAc;;CAEzH,OAAO,QAAQ,UAAiC,EAAE,EAAE;EAChD,MAAM,EAAC,QAAQ,YAAY,OAAO,UAAU,WAAW,OAAO,YAAY,EAAE,EAAE,iBAAgB;AAE9F,SAAO;GACH;GACA,WAAW;IACP;KAAC,SAASJ;KAAkB,UAAU,wBAAwB,WAAW;KAAC;oBAC3D,oBAAoB,MAAM;oBAC1B,uBAAuB,SAAS;oBAChC,2BAA2B,aAAa;oBACxC,oBAAoB,QAAQ,MAAM;oBAClC;oBACA;oBACA;IACf,GAAG;IACN;GACD,yBAAwB;GACxB,QAAQ;GACX;;CAGL,OAAO,aAAa,SAAqC;EACrD,MAA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BAIR,OAAOC,mBAAiB"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["StpLogic","XLT_TOKEN_CONFIG","XLT_TOKEN_STORE","XLT_TOKEN_STRATEGY","XLT_EVENT_SINK","StpPermLogic","XLT_STP_INTERFACE","MemoryStore","UuidStrategy","BaseRedisStore","BaseIORedisStore","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/store/ioredis-store.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 type { ModuleMetadata, Provider } from \"@nestjs/common\";\nimport { Module } from \"@nestjs/common\";\nimport type {\n StpInterface,\n TokenStrategy,\n XltEventSink,\n XltTokenConfig,\n XltTokenConfigInput,\n XltTokenStore,\n} from \"@xlt-token/core\";\nimport {\n MemoryStore,\n setStpLogic,\n setStpPermLogic,\n StpLogic,\n StpPermLogic,\n UuidStrategy,\n XLT_STP_INTERFACE,\n XLT_EVENT_SINK,\n XLT_TOKEN_CONFIG,\n XLT_TOKEN_STORE,\n XLT_TOKEN_STRATEGY,\n normalizeXltTokenConfig,\n} from \"@xlt-token/core\";\n\nexport interface XltTokenModuleOptions {\n config?: Partial<XltTokenConfigInput>;\n store?: { useClass: new (...args: any[]) => XltTokenStore } | { useValue: XltTokenStore };\n strategy?: { useClass: new (...args: any[]) => TokenStrategy } | { useValue: TokenStrategy };\n isGlobal?: boolean;\n providers?: Provider[];\n stpInterface?: new (...args: any[]) => StpInterface;\n eventSink?: XltEventSink;\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 } | { useValue: TokenStrategy };\n isGlobal?: boolean;\n providers?: Provider[];\n stpInterface?: new (...args: any[]) => StpInterface;\n eventSink?: XltEventSink;\n}\n\n@Module({})\nexport class XltTokenModule {\n private static readonly stpLogicProvider: Provider = {\n provide: StpLogic,\n useFactory: (\n config: XltTokenConfig,\n store: XltTokenStore,\n strategy: TokenStrategy,\n eventSink: XltEventSink,\n ) => new StpLogic(config, store, strategy, eventSink),\n inject: [XLT_TOKEN_CONFIG, XLT_TOKEN_STORE, XLT_TOKEN_STRATEGY, XLT_EVENT_SINK],\n };\n private static readonly stpPermLogicProvider: Provider = {\n provide: StpPermLogic,\n useFactory: (stpInterface: StpInterface, store: XltTokenStore, config: XltTokenConfig) =>\n new StpPermLogic(stpInterface, store, config),\n inject: [XLT_STP_INTERFACE, XLT_TOKEN_STORE, XLT_TOKEN_CONFIG],\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 private static readonly moduleExports = [\n XLT_TOKEN_CONFIG,\n XLT_TOKEN_STORE,\n XLT_TOKEN_STRATEGY,\n StpLogic,\n StpPermLogic,\n ];\n\n static forRoot(options: XltTokenModuleOptions = {}) {\n const {\n config: userConfig,\n store,\n strategy,\n isGlobal = false,\n providers = [],\n stpInterface,\n } = options;\n\n return {\n module: XltTokenModule,\n providers: [\n { provide: XLT_TOKEN_CONFIG, useValue: normalizeXltTokenConfig(userConfig) },\n XltTokenModule.createStoreProvider(store),\n XltTokenModule.createStrategyProvider(strategy),\n XltTokenModule.createStpInterfaceProvider(stpInterface),\n XltTokenModule.createEventSinkProvider(options.eventSink),\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 {\n useFactory,\n inject = [],\n imports = [],\n store,\n strategy,\n isGlobal = false,\n providers = [],\n stpInterface,\n } = 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 normalizeXltTokenConfig(config);\n },\n inject,\n },\n XltTokenModule.createStoreProvider(store),\n XltTokenModule.createStrategyProvider(strategy),\n XltTokenModule.createStpInterfaceProvider(stpInterface),\n XltTokenModule.createEventSinkProvider(options.eventSink),\n XltTokenModule.stpLogicProvider,\n XltTokenModule.stpPermLogicProvider,\n XltTokenModule.initProvider,\n ...providers,\n ],\n exports: XltTokenModule.moduleExports,\n global: isGlobal,\n };\n }\n\n private static createStoreProvider(store?: XltTokenModuleOptions[\"store\"]): 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(strategy?: XltTokenModuleOptions[\"strategy\"]): Provider {\n if (!strategy) return { provide: XLT_TOKEN_STRATEGY, useClass: UuidStrategy };\n return \"useClass\" in strategy\n ? { provide: XLT_TOKEN_STRATEGY, useClass: strategy.useClass }\n : { provide: XLT_TOKEN_STRATEGY, useValue: strategy.useValue };\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: () => {\n throw new Error(\"StpInterface not registered: getPermissionList\");\n },\n getRoleList: () => {\n throw new Error(\"StpInterface not registered: getRoleList\");\n },\n },\n };\n }\n\n private static createEventSinkProvider(eventSink?: XltTokenModuleOptions[\"eventSink\"]): Provider {\n return { provide: XLT_EVENT_SINK, useValue: eventSink ?? {} };\n }\n}\n","import { Inject, Injectable } from \"@nestjs/common\";\nimport { RedisStore as BaseRedisStore, type RedisClient } from \"@xlt-token/store-redis\";\n\nexport const XLT_REDIS_CLIENT = \"XLT_REDIS_CLIENT\";\n\n/**\n * @deprecated Import `RedisStore` from `@xlt-token/store-redis` and provide it\n * through `store.useValue` for new applications.\n */\n@Injectable()\nexport class RedisStore extends BaseRedisStore {\n constructor(\n @Inject(XLT_REDIS_CLIENT)\n redisClient: RedisClient,\n ) {\n super(redisClient);\n }\n}\n","import { Inject, Injectable } from \"@nestjs/common\";\nimport { IORedisStore as BaseIORedisStore, type IORedisClient } from \"@xlt-token/store-redis\";\n\nexport const XLT_IOREDIS_CLIENT = \"XLT_IOREDIS_CLIENT\";\n\n/**\n * @deprecated Import `IORedisStore` from `@xlt-token/store-redis` and provide it\n * through `store.useValue` for new applications.\n */\n@Injectable()\nexport class IORedisStore extends BaseIORedisStore {\n constructor(\n @Inject(XLT_IOREDIS_CLIENT)\n redisClient: IORedisClient,\n ) {\n super(redisClient);\n }\n}\n","// 登录校验装饰器\n\nimport { SetMetadata } from \"@nestjs/common\";\nimport { XLT_CHECK_LOGIN_KEY } from \"@xlt-token/core\";\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((data: unknown, ctx: ExecutionContext) => {\n const request = ctx.switchToHttp().getRequest();\n return request.stpLoginId;\n});\n","// 注入当前 Token\n\nimport { createParamDecorator, ExecutionContext } from \"@nestjs/common\";\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 * @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 * @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","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, type XltErrorCode } 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 code: NotLoginException.codeForType(type),\n type,\n message: NotLoginException.describeType(type),\n });\n this.type = type;\n this.token = token;\n }\n\n private static codeForType(type: NotLoginType): XltErrorCode {\n const map: Record<NotLoginType, XltErrorCode> = {\n [NotLoginType.NOT_TOKEN]: \"TOKEN_MISSING\",\n [NotLoginType.INVALID_TOKEN]: \"TOKEN_INVALID\",\n [NotLoginType.TOKEN_TIMEOUT]: \"TOKEN_TIMEOUT\",\n [NotLoginType.TOKEN_FREEZE]: \"TOKEN_FREEZE\",\n [NotLoginType.BE_REPLACED]: \"TOKEN_REPLACED\",\n [NotLoginType.KICK_OUT]: \"TOKEN_KICKED_OUT\",\n };\n return map[type] ?? \"TOKEN_INVALID\";\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","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 code: \"PERMISSION_DENIED\",\n permission,\n mode,\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 code: \"ROLE_DENIED\",\n role,\n mode,\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 constructor(business: string) {\n super({\n statusCode: 403,\n code: \"SAFE_REQUIRED\",\n business,\n message: `二级认证未开启:${business}`,\n });\n this.business = business;\n }\n}\n","import {\n createExpressContext,\n type CookieOptions,\n type ExpressLikeResponse,\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\n/**\n * Fastify reply 的写回 API 与 Express response 不同:\n * - 写 header:Express 用 `res.setHeader(n, v)`,Fastify 用 `reply.header(n, v)`\n * - 写 cookie:Express 用 `res.cookie(n, v, o)`,Fastify 用 `reply.setCookie(n, v, o)`\n *\n * 这里把任意一种 response 归一化成 core 期望的 {@link ExpressLikeResponse} 形态,\n * 让核心层无需感知底层 HTTP 平台。读取侧(headers/cookies/query)两个平台形态一致,\n * 直接复用 core 的 createExpressContext。\n */\nfunction normalizeResponse(res: any): ExpressLikeResponse {\n return {\n setHeader(name: string, value: string): void {\n if (typeof res?.setHeader === \"function\") {\n // Express response / 原生 Node 响应\n res.setHeader(name, value);\n } else if (typeof res?.header === \"function\") {\n // Fastify reply\n res.header(name, value);\n } else {\n throw new Error(\n \"xlt-token: 当前 response 不支持写入 header(既无 setHeader 也无 header 方法)\",\n );\n }\n },\n cookie(name: string, value: string, options?: CookieOptions): void {\n if (typeof res?.cookie === \"function\") {\n // Express response(或已注册 @fastify/cookie 暴露的 cookie 别名)\n res.cookie(name, value, options);\n } else if (typeof res?.setCookie === \"function\") {\n // Fastify reply + @fastify/cookie 插件\n res.setCookie(name, value, options);\n } else {\n throw new Error(\n \"xlt-token: 当前 response 不支持写入 cookie。\" +\n \"若使用 Fastify,请先注册 @fastify/cookie 插件。\",\n );\n }\n },\n };\n}\n\nexport function createNestHttpContext(req: any, res: any) {\n return createExpressContext(req, normalizeResponse(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 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(\n result.loginId!,\n permMeta.permissions,\n permMeta.mode,\n );\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, [\n ctx.getHandler(),\n ctx.getClass(),\n ]);\n\n if (this.config.defaultCheck) return !isIgnored;\n\n return (\n this.reflector.getAllAndOverride<boolean>(XLT_CHECK_LOGIN_KEY, [\n ctx.getHandler(),\n ctx.getClass(),\n ]) ?? false\n );\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":";;;;;;;;;;;;;;;;;AA+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,UAAU,kBAA2B,qBAAqB,CAC7D,IAAI,YAAY,EAChB,IAAI,UAAU,CACf,CAAC,IAAI;;;;CA3CX,YAAY;oBAIR,OAAOC,mBAAiB"}
|
package/package.json
CHANGED
|
@@ -1,29 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xlt-token/nestjs",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "NestJS integration for xlt-token",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"nestjs",
|
|
7
|
-
"token",
|
|
8
6
|
"auth",
|
|
9
7
|
"jwt",
|
|
10
|
-
"
|
|
8
|
+
"nestjs",
|
|
9
|
+
"session",
|
|
10
|
+
"token"
|
|
11
11
|
],
|
|
12
|
-
"
|
|
12
|
+
"homepage": "https://xiaolangtou.github.io/xlt-token/",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/xiaoLangtou/xlt-token/issues"
|
|
15
|
+
},
|
|
13
16
|
"license": "MIT",
|
|
17
|
+
"author": "xltorg",
|
|
14
18
|
"repository": {
|
|
15
19
|
"type": "git",
|
|
16
20
|
"url": "git+https://github.com/xiaoLangtou/xlt-token.git",
|
|
17
21
|
"directory": "packages/nestjs"
|
|
18
22
|
},
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"access": "public"
|
|
25
|
-
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist",
|
|
25
|
+
"LICENSE",
|
|
26
|
+
"README.md"
|
|
27
|
+
],
|
|
26
28
|
"type": "module",
|
|
29
|
+
"sideEffects": false,
|
|
30
|
+
"main": "./dist/index.cjs",
|
|
31
|
+
"module": "./dist/index.mjs",
|
|
32
|
+
"types": "./dist/index.d.cts",
|
|
27
33
|
"exports": {
|
|
28
34
|
".": {
|
|
29
35
|
"import": {
|
|
@@ -37,30 +43,13 @@
|
|
|
37
43
|
},
|
|
38
44
|
"./package.json": "./package.json"
|
|
39
45
|
},
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
"types": "./dist/index.d.cts",
|
|
43
|
-
"sideEffects": false,
|
|
44
|
-
"files": [
|
|
45
|
-
"dist",
|
|
46
|
-
"LICENSE",
|
|
47
|
-
"README.md"
|
|
48
|
-
],
|
|
49
|
-
"peerDependencies": {
|
|
50
|
-
"@nestjs/common": "^10.0.0 || ^11.0.0 || ^12.0.0",
|
|
51
|
-
"@nestjs/core": "^10.0.0 || ^11.0.0 || ^12.0.0",
|
|
52
|
-
"jsonwebtoken": "^9.0.0",
|
|
53
|
-
"reflect-metadata": "^0.1.13 || ^0.2.0",
|
|
54
|
-
"rxjs": "^7.0.0"
|
|
55
|
-
},
|
|
56
|
-
"peerDependenciesMeta": {
|
|
57
|
-
"jsonwebtoken": {
|
|
58
|
-
"optional": true
|
|
59
|
-
}
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"access": "public"
|
|
60
48
|
},
|
|
61
49
|
"dependencies": {
|
|
62
|
-
"@xlt-token/core": "^
|
|
63
|
-
"@xlt-token/
|
|
50
|
+
"@xlt-token/core": "^2.1.0",
|
|
51
|
+
"@xlt-token/jwt": "^2.1.0",
|
|
52
|
+
"@xlt-token/store-redis": "^2.1.0",
|
|
64
53
|
"uuid": "^10.0.0"
|
|
65
54
|
},
|
|
66
55
|
"devDependencies": {
|
|
@@ -85,9 +74,16 @@
|
|
|
85
74
|
"unplugin-swc": "^1.5.9",
|
|
86
75
|
"vitest": "^2.0.0"
|
|
87
76
|
},
|
|
77
|
+
"peerDependencies": {
|
|
78
|
+
"@nestjs/common": "^10.0.0 || ^11.0.0 || ^12.0.0",
|
|
79
|
+
"@nestjs/core": "^10.0.0 || ^11.0.0 || ^12.0.0",
|
|
80
|
+
"reflect-metadata": "^0.1.13 || ^0.2.0",
|
|
81
|
+
"rxjs": "^7.0.0"
|
|
82
|
+
},
|
|
88
83
|
"scripts": {
|
|
89
84
|
"build": "tsdown",
|
|
90
85
|
"build:watch": "tsdown --watch",
|
|
86
|
+
"typecheck": "tsc --noEmit",
|
|
91
87
|
"test": "vitest run",
|
|
92
88
|
"test:cov": "vitest run --coverage",
|
|
93
89
|
"test:e2e": "vitest run --config vitest.e2e.config.ts",
|