@xlt-token/nestjs 1.2.0 → 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 +64 -110
- package/dist/index.d.cts +27 -31
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +27 -31
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +46 -105
- package/dist/index.mjs.map +1 -1
- package/package.json +30 -37
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
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
|
-
let
|
|
5
|
-
let
|
|
4
|
+
let _xlt_token_store_redis = require("@xlt-token/store-redis");
|
|
5
|
+
let _xlt_token_jwt = require("@xlt-token/jwt");
|
|
6
6
|
let _nestjs_core = require("@nestjs/core");
|
|
7
7
|
|
|
8
8
|
//#region \0@oxc-project+runtime@0.112.0/helpers/decorate.js
|
|
@@ -23,12 +23,12 @@ let XltTokenModule = class XltTokenModule {
|
|
|
23
23
|
static {
|
|
24
24
|
this.stpLogicProvider = {
|
|
25
25
|
provide: _xlt_token_core.StpLogic,
|
|
26
|
-
useFactory: (config, store, strategy,
|
|
26
|
+
useFactory: (config, store, strategy, eventSink) => new _xlt_token_core.StpLogic(config, store, strategy, eventSink),
|
|
27
27
|
inject: [
|
|
28
28
|
_xlt_token_core.XLT_TOKEN_CONFIG,
|
|
29
29
|
_xlt_token_core.XLT_TOKEN_STORE,
|
|
30
30
|
_xlt_token_core.XLT_TOKEN_STRATEGY,
|
|
31
|
-
_xlt_token_core.
|
|
31
|
+
_xlt_token_core.XLT_EVENT_SINK
|
|
32
32
|
]
|
|
33
33
|
};
|
|
34
34
|
}
|
|
@@ -75,7 +75,7 @@ let XltTokenModule = class XltTokenModule {
|
|
|
75
75
|
_XltTokenModule.createStoreProvider(store),
|
|
76
76
|
_XltTokenModule.createStrategyProvider(strategy),
|
|
77
77
|
_XltTokenModule.createStpInterfaceProvider(stpInterface),
|
|
78
|
-
_XltTokenModule.
|
|
78
|
+
_XltTokenModule.createEventSinkProvider(options.eventSink),
|
|
79
79
|
_XltTokenModule.stpLogicProvider,
|
|
80
80
|
_XltTokenModule.stpPermLogicProvider,
|
|
81
81
|
_XltTokenModule.initProvider,
|
|
@@ -102,7 +102,7 @@ let XltTokenModule = class XltTokenModule {
|
|
|
102
102
|
_XltTokenModule.createStoreProvider(store),
|
|
103
103
|
_XltTokenModule.createStrategyProvider(strategy),
|
|
104
104
|
_XltTokenModule.createStpInterfaceProvider(stpInterface),
|
|
105
|
-
_XltTokenModule.
|
|
105
|
+
_XltTokenModule.createEventSinkProvider(options.eventSink),
|
|
106
106
|
_XltTokenModule.stpLogicProvider,
|
|
107
107
|
_XltTokenModule.stpPermLogicProvider,
|
|
108
108
|
_XltTokenModule.initProvider,
|
|
@@ -126,12 +126,16 @@ let XltTokenModule = class XltTokenModule {
|
|
|
126
126
|
};
|
|
127
127
|
}
|
|
128
128
|
static createStrategyProvider(strategy) {
|
|
129
|
-
|
|
129
|
+
if (!strategy) return {
|
|
130
|
+
provide: _xlt_token_core.XLT_TOKEN_STRATEGY,
|
|
131
|
+
useClass: _xlt_token_core.UuidStrategy
|
|
132
|
+
};
|
|
133
|
+
return "useClass" in strategy ? {
|
|
130
134
|
provide: _xlt_token_core.XLT_TOKEN_STRATEGY,
|
|
131
135
|
useClass: strategy.useClass
|
|
132
136
|
} : {
|
|
133
137
|
provide: _xlt_token_core.XLT_TOKEN_STRATEGY,
|
|
134
|
-
|
|
138
|
+
useValue: strategy.useValue
|
|
135
139
|
};
|
|
136
140
|
}
|
|
137
141
|
static createStpInterfaceProvider(stpInterface) {
|
|
@@ -151,10 +155,10 @@ let XltTokenModule = class XltTokenModule {
|
|
|
151
155
|
}
|
|
152
156
|
};
|
|
153
157
|
}
|
|
154
|
-
static
|
|
158
|
+
static createEventSinkProvider(eventSink) {
|
|
155
159
|
return {
|
|
156
|
-
provide: _xlt_token_core.
|
|
157
|
-
useValue:
|
|
160
|
+
provide: _xlt_token_core.XLT_EVENT_SINK,
|
|
161
|
+
useValue: eventSink ?? {}
|
|
158
162
|
};
|
|
159
163
|
}
|
|
160
164
|
};
|
|
@@ -177,49 +181,9 @@ function __decorateParam(paramIndex, decorator) {
|
|
|
177
181
|
//#endregion
|
|
178
182
|
//#region src/store/redis-store.ts
|
|
179
183
|
const XLT_REDIS_CLIENT = "XLT_REDIS_CLIENT";
|
|
180
|
-
let RedisStore = class RedisStore {
|
|
184
|
+
let RedisStore = class RedisStore extends _xlt_token_store_redis.RedisStore {
|
|
181
185
|
constructor(redisClient) {
|
|
182
|
-
|
|
183
|
-
}
|
|
184
|
-
async get(key) {
|
|
185
|
-
return this.redisClient.get(key);
|
|
186
|
-
}
|
|
187
|
-
async set(key, value, timeoutSec) {
|
|
188
|
-
if (timeoutSec === -1) await this.redisClient.set(key, value);
|
|
189
|
-
else await this.redisClient.set(key, value, { EX: timeoutSec });
|
|
190
|
-
}
|
|
191
|
-
async delete(key) {
|
|
192
|
-
await this.redisClient.del(key);
|
|
193
|
-
}
|
|
194
|
-
async update(key, value) {
|
|
195
|
-
if (await this.redisClient.set(key, value, {
|
|
196
|
-
XX: true,
|
|
197
|
-
KEEPTTL: true
|
|
198
|
-
}) === null) throw new Error(`Key not found: ${key}`);
|
|
199
|
-
}
|
|
200
|
-
async has(key) {
|
|
201
|
-
return await this.redisClient.exists(key) === 1;
|
|
202
|
-
}
|
|
203
|
-
async updateTimeout(key, timeoutSec) {
|
|
204
|
-
if (!await this.redisClient.exists(key)) throw new Error(`Key not found: ${key}`);
|
|
205
|
-
if (timeoutSec === -1) await this.redisClient.persist(key);
|
|
206
|
-
else await this.redisClient.expire(key, timeoutSec);
|
|
207
|
-
}
|
|
208
|
-
async getTimeout(key) {
|
|
209
|
-
return await this.redisClient.ttl(key);
|
|
210
|
-
}
|
|
211
|
-
async keys(pattern) {
|
|
212
|
-
const result = [];
|
|
213
|
-
let cursor = "0";
|
|
214
|
-
do {
|
|
215
|
-
const reply = await this.redisClient.scan(cursor, {
|
|
216
|
-
MATCH: pattern,
|
|
217
|
-
COUNT: 100
|
|
218
|
-
});
|
|
219
|
-
cursor = String(reply.cursor);
|
|
220
|
-
result.push(...reply.keys);
|
|
221
|
-
} while (cursor !== "0");
|
|
222
|
-
return result;
|
|
186
|
+
super(redisClient);
|
|
223
187
|
}
|
|
224
188
|
};
|
|
225
189
|
RedisStore = __decorate([
|
|
@@ -229,57 +193,18 @@ RedisStore = __decorate([
|
|
|
229
193
|
], RedisStore);
|
|
230
194
|
|
|
231
195
|
//#endregion
|
|
232
|
-
//#region src/
|
|
233
|
-
const
|
|
234
|
-
let
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
jsonwebtoken ??= require$1("jsonwebtoken");
|
|
238
|
-
return jsonwebtoken;
|
|
239
|
-
} catch (error) {
|
|
240
|
-
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\".");
|
|
241
|
-
throw error;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
let JwtStrategy = class JwtStrategy {
|
|
245
|
-
constructor(config) {
|
|
246
|
-
this.config = config;
|
|
247
|
-
}
|
|
248
|
-
ensureJwtConfig(config) {
|
|
249
|
-
const jwt = (config ?? this.config).jwt;
|
|
250
|
-
if (!jwt || !jwt.secret) throw new Error("JwtStrategy requires jwt config with a secret. Provide { jwt: { secret: \"your-secret\" } } in the module config.");
|
|
251
|
-
return jwt;
|
|
252
|
-
}
|
|
253
|
-
createToken(loginId, config, options) {
|
|
254
|
-
const { sign } = getJsonwebtoken();
|
|
255
|
-
const jwt = this.ensureJwtConfig(config);
|
|
256
|
-
const jti = (0, node_crypto.randomUUID)();
|
|
257
|
-
const resolvedTimeout = options?.timeout ?? config.timeout;
|
|
258
|
-
const hasExpiry = typeof resolvedTimeout === "number" ? resolvedTimeout > 0 : true;
|
|
259
|
-
return sign({
|
|
260
|
-
sub: loginId,
|
|
261
|
-
jti
|
|
262
|
-
}, jwt.secret, {
|
|
263
|
-
algorithm: jwt.algorithm ?? "HS256",
|
|
264
|
-
...jwt.issuer && { issuer: jwt.issuer },
|
|
265
|
-
...jwt.audience && { audience: jwt.audience },
|
|
266
|
-
...hasExpiry && { expiresIn: resolvedTimeout }
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
generateToken(payload) {
|
|
270
|
-
const { sign } = getJsonwebtoken();
|
|
271
|
-
return sign(payload, this.ensureJwtConfig().secret);
|
|
272
|
-
}
|
|
273
|
-
verifyToken(token) {
|
|
274
|
-
const { verify } = getJsonwebtoken();
|
|
275
|
-
return verify(token, this.ensureJwtConfig().secret);
|
|
196
|
+
//#region src/store/ioredis-store.ts
|
|
197
|
+
const XLT_IOREDIS_CLIENT = "XLT_IOREDIS_CLIENT";
|
|
198
|
+
let IORedisStore = class IORedisStore extends _xlt_token_store_redis.IORedisStore {
|
|
199
|
+
constructor(redisClient) {
|
|
200
|
+
super(redisClient);
|
|
276
201
|
}
|
|
277
202
|
};
|
|
278
|
-
|
|
203
|
+
IORedisStore = __decorate([
|
|
279
204
|
(0, _nestjs_common.Injectable)(),
|
|
280
|
-
__decorateParam(0, (0, _nestjs_common.Inject)(
|
|
205
|
+
__decorateParam(0, (0, _nestjs_common.Inject)(XLT_IOREDIS_CLIENT)),
|
|
281
206
|
__decorateMetadata("design:paramtypes", [Object])
|
|
282
|
-
],
|
|
207
|
+
], IORedisStore);
|
|
283
208
|
|
|
284
209
|
//#endregion
|
|
285
210
|
//#region src/decorators/xlt-check-login.decorator.ts
|
|
@@ -358,12 +283,23 @@ var NotLoginException = class NotLoginException extends _nestjs_common.Unauthori
|
|
|
358
283
|
constructor(type, token) {
|
|
359
284
|
super({
|
|
360
285
|
statusCode: 401,
|
|
286
|
+
code: NotLoginException.codeForType(type),
|
|
361
287
|
type,
|
|
362
288
|
message: NotLoginException.describeType(type)
|
|
363
289
|
});
|
|
364
290
|
this.type = type;
|
|
365
291
|
this.token = token;
|
|
366
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
|
+
}
|
|
367
303
|
static describeType(type) {
|
|
368
304
|
return {
|
|
369
305
|
[_xlt_token_core.NotLoginType.NOT_TOKEN]: "未提供 Token",
|
|
@@ -382,7 +318,9 @@ var NotPermissionException = class extends _nestjs_common.ForbiddenException {
|
|
|
382
318
|
constructor(permission, mode) {
|
|
383
319
|
super({
|
|
384
320
|
statusCode: 403,
|
|
385
|
-
|
|
321
|
+
code: "PERMISSION_DENIED",
|
|
322
|
+
permission,
|
|
323
|
+
mode,
|
|
386
324
|
message: `缺少权限: ${Array.isArray(permission) ? permission.join(", ") : permission}`
|
|
387
325
|
});
|
|
388
326
|
this.permission = permission;
|
|
@@ -396,7 +334,9 @@ var NotRoleException = class extends _nestjs_common.ForbiddenException {
|
|
|
396
334
|
constructor(role, mode) {
|
|
397
335
|
super({
|
|
398
336
|
statusCode: 403,
|
|
399
|
-
|
|
337
|
+
code: "ROLE_DENIED",
|
|
338
|
+
role,
|
|
339
|
+
mode,
|
|
400
340
|
message: `缺少角色: ${Array.isArray(role) ? role.join(", ") : role}`
|
|
401
341
|
});
|
|
402
342
|
this.role = role;
|
|
@@ -410,7 +350,8 @@ var NotSafeException = class extends _nestjs_common.ForbiddenException {
|
|
|
410
350
|
constructor(business) {
|
|
411
351
|
super({
|
|
412
352
|
statusCode: 403,
|
|
413
|
-
|
|
353
|
+
code: "SAFE_REQUIRED",
|
|
354
|
+
business,
|
|
414
355
|
message: `二级认证未开启:${business}`
|
|
415
356
|
});
|
|
416
357
|
this.business = business;
|
|
@@ -567,10 +508,16 @@ Object.defineProperty(exports, 'DEFAULT_XLT_TOKEN_CONFIG', {
|
|
|
567
508
|
return _xlt_token_core.DEFAULT_XLT_TOKEN_CONFIG;
|
|
568
509
|
}
|
|
569
510
|
});
|
|
511
|
+
Object.defineProperty(exports, 'IORedisStore', {
|
|
512
|
+
enumerable: true,
|
|
513
|
+
get: function () {
|
|
514
|
+
return IORedisStore;
|
|
515
|
+
}
|
|
516
|
+
});
|
|
570
517
|
Object.defineProperty(exports, 'JwtStrategy', {
|
|
571
518
|
enumerable: true,
|
|
572
519
|
get: function () {
|
|
573
|
-
return JwtStrategy;
|
|
520
|
+
return _xlt_token_jwt.JwtStrategy;
|
|
574
521
|
}
|
|
575
522
|
});
|
|
576
523
|
exports.LoginId = LoginId;
|
|
@@ -622,6 +569,13 @@ Object.defineProperty(exports, 'UuidStrategy', {
|
|
|
622
569
|
}
|
|
623
570
|
});
|
|
624
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
|
+
});
|
|
578
|
+
exports.XLT_IOREDIS_CLIENT = XLT_IOREDIS_CLIENT;
|
|
625
579
|
exports.XLT_REDIS_CLIENT = XLT_REDIS_CLIENT;
|
|
626
580
|
Object.defineProperty(exports, 'XLT_STP_INTERFACE', {
|
|
627
581
|
enumerable: true,
|
|
@@ -635,12 +589,6 @@ Object.defineProperty(exports, 'XLT_TOKEN_CONFIG', {
|
|
|
635
589
|
return _xlt_token_core.XLT_TOKEN_CONFIG;
|
|
636
590
|
}
|
|
637
591
|
});
|
|
638
|
-
Object.defineProperty(exports, 'XLT_TOKEN_HOOKS', {
|
|
639
|
-
enumerable: true,
|
|
640
|
-
get: function () {
|
|
641
|
-
return _xlt_token_core.XLT_TOKEN_HOOKS;
|
|
642
|
-
}
|
|
643
|
-
});
|
|
644
592
|
Object.defineProperty(exports, 'XLT_TOKEN_STORE', {
|
|
645
593
|
enumerable: true,
|
|
646
594
|
get: function () {
|
|
@@ -694,6 +642,12 @@ Object.defineProperty(exports, 'createExpressContext', {
|
|
|
694
642
|
return _xlt_token_core.createExpressContext;
|
|
695
643
|
}
|
|
696
644
|
});
|
|
645
|
+
Object.defineProperty(exports, 'createJwtStrategyConfig', {
|
|
646
|
+
enumerable: true,
|
|
647
|
+
get: function () {
|
|
648
|
+
return _xlt_token_jwt.createJwtStrategyConfig;
|
|
649
|
+
}
|
|
650
|
+
});
|
|
697
651
|
Object.defineProperty(exports, 'createMockHttpContext', {
|
|
698
652
|
enumerable: true,
|
|
699
653
|
get: function () {
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +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
|
+
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";
|
|
4
6
|
import { Reflector } from "@nestjs/core";
|
|
5
7
|
|
|
6
8
|
//#region src/xlt-token.module.d.ts
|
|
@@ -13,13 +15,15 @@ interface XltTokenModuleOptions {
|
|
|
13
15
|
};
|
|
14
16
|
strategy?: {
|
|
15
17
|
useClass: new (...args: any[]) => TokenStrategy$1;
|
|
18
|
+
} | {
|
|
19
|
+
useValue: TokenStrategy$1;
|
|
16
20
|
};
|
|
17
21
|
isGlobal?: boolean;
|
|
18
22
|
providers?: Provider[];
|
|
19
23
|
stpInterface?: new (...args: any[]) => StpInterface$1;
|
|
20
|
-
|
|
24
|
+
eventSink?: XltEventSink$1;
|
|
21
25
|
}
|
|
22
|
-
interface XltTokenModuleAsyncOptions extends Pick<ModuleMetadata,
|
|
26
|
+
interface XltTokenModuleAsyncOptions extends Pick<ModuleMetadata, "imports"> {
|
|
23
27
|
useFactory: (...args: any[]) => Promise<XltTokenModuleOptions> | XltTokenModuleOptions;
|
|
24
28
|
inject?: any[];
|
|
25
29
|
store?: {
|
|
@@ -29,11 +33,13 @@ interface XltTokenModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
|
|
|
29
33
|
};
|
|
30
34
|
strategy?: {
|
|
31
35
|
useClass: new (...args: any[]) => TokenStrategy$1;
|
|
36
|
+
} | {
|
|
37
|
+
useValue: TokenStrategy$1;
|
|
32
38
|
};
|
|
33
39
|
isGlobal?: boolean;
|
|
34
40
|
providers?: Provider[];
|
|
35
41
|
stpInterface?: new (...args: any[]) => StpInterface$1;
|
|
36
|
-
|
|
42
|
+
eventSink?: XltEventSink$1;
|
|
37
43
|
}
|
|
38
44
|
declare class XltTokenModule {
|
|
39
45
|
private static readonly stpLogicProvider;
|
|
@@ -60,38 +66,27 @@ declare class XltTokenModule {
|
|
|
60
66
|
private static createStoreProvider;
|
|
61
67
|
private static createStrategyProvider;
|
|
62
68
|
private static createStpInterfaceProvider;
|
|
63
|
-
private static
|
|
69
|
+
private static createEventSinkProvider;
|
|
64
70
|
}
|
|
65
71
|
//#endregion
|
|
66
72
|
//#region src/store/redis-store.d.ts
|
|
67
73
|
declare const XLT_REDIS_CLIENT = "XLT_REDIS_CLIENT";
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
update(key: string, value: string): Promise<void>;
|
|
75
|
-
has(key: string): Promise<boolean>;
|
|
76
|
-
updateTimeout(key: string, timeoutSec: number): Promise<void>;
|
|
77
|
-
getTimeout(key: string): Promise<number>;
|
|
78
|
-
keys(pattern: string): Promise<string[]>;
|
|
74
|
+
/**
|
|
75
|
+
* @deprecated Import `RedisStore` from `@xlt-token/store-redis` and provide it
|
|
76
|
+
* through `store.useValue` for new applications.
|
|
77
|
+
*/
|
|
78
|
+
declare class RedisStore extends RedisStore$1 {
|
|
79
|
+
constructor(redisClient: RedisClient);
|
|
79
80
|
}
|
|
80
81
|
//#endregion
|
|
81
|
-
//#region src/
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
constructor(
|
|
89
|
-
private ensureJwtConfig;
|
|
90
|
-
createToken(loginId: string, config: XltTokenConfig$1, options?: {
|
|
91
|
-
timeout?: DurationInput;
|
|
92
|
-
}): string;
|
|
93
|
-
generateToken(payload: any): string;
|
|
94
|
-
verifyToken(token: string): XltJwtPayload;
|
|
82
|
+
//#region src/store/ioredis-store.d.ts
|
|
83
|
+
declare const XLT_IOREDIS_CLIENT = "XLT_IOREDIS_CLIENT";
|
|
84
|
+
/**
|
|
85
|
+
* @deprecated Import `IORedisStore` from `@xlt-token/store-redis` and provide it
|
|
86
|
+
* through `store.useValue` for new applications.
|
|
87
|
+
*/
|
|
88
|
+
declare class IORedisStore extends IORedisStore$1 {
|
|
89
|
+
constructor(redisClient: IORedisClient);
|
|
95
90
|
}
|
|
96
91
|
//#endregion
|
|
97
92
|
//#region src/decorators/xlt-check-login.decorator.d.ts
|
|
@@ -191,6 +186,7 @@ declare class NotLoginException extends UnauthorizedException {
|
|
|
191
186
|
readonly type: NotLoginType$1;
|
|
192
187
|
readonly token: string | undefined;
|
|
193
188
|
constructor(type: NotLoginType$1, token?: string);
|
|
189
|
+
private static codeForType;
|
|
194
190
|
private static describeType;
|
|
195
191
|
}
|
|
196
192
|
//#endregion
|
|
@@ -214,5 +210,5 @@ declare class NotSafeException extends ForbiddenException {
|
|
|
214
210
|
constructor(business: string);
|
|
215
211
|
}
|
|
216
212
|
//#endregion
|
|
217
|
-
export { type AuthResult, type CreateOptions, DEFAULT_XLT_TOKEN_CONFIG, type DeviceInfo, type HttpContext, JwtStrategy, LoginId, MemoryStore, NotLoginException, NotLoginType, NotPermissionException, NotRoleException, NotSafeException, RedisStore, type StpInterface, StpLogic, StpPermLogic, StpUtil, type TokenStrategy, TokenValue, UuidStrategy, XLT_CHECK_SAFE_KEY, 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 };
|
|
218
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/
|
|
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":";;;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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,6 +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
|
+
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";
|
|
4
6
|
import { Reflector } from "@nestjs/core";
|
|
5
7
|
|
|
6
8
|
//#region src/xlt-token.module.d.ts
|
|
@@ -13,13 +15,15 @@ interface XltTokenModuleOptions {
|
|
|
13
15
|
};
|
|
14
16
|
strategy?: {
|
|
15
17
|
useClass: new (...args: any[]) => TokenStrategy$1;
|
|
18
|
+
} | {
|
|
19
|
+
useValue: TokenStrategy$1;
|
|
16
20
|
};
|
|
17
21
|
isGlobal?: boolean;
|
|
18
22
|
providers?: Provider[];
|
|
19
23
|
stpInterface?: new (...args: any[]) => StpInterface$1;
|
|
20
|
-
|
|
24
|
+
eventSink?: XltEventSink$1;
|
|
21
25
|
}
|
|
22
|
-
interface XltTokenModuleAsyncOptions extends Pick<ModuleMetadata,
|
|
26
|
+
interface XltTokenModuleAsyncOptions extends Pick<ModuleMetadata, "imports"> {
|
|
23
27
|
useFactory: (...args: any[]) => Promise<XltTokenModuleOptions> | XltTokenModuleOptions;
|
|
24
28
|
inject?: any[];
|
|
25
29
|
store?: {
|
|
@@ -29,11 +33,13 @@ interface XltTokenModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
|
|
|
29
33
|
};
|
|
30
34
|
strategy?: {
|
|
31
35
|
useClass: new (...args: any[]) => TokenStrategy$1;
|
|
36
|
+
} | {
|
|
37
|
+
useValue: TokenStrategy$1;
|
|
32
38
|
};
|
|
33
39
|
isGlobal?: boolean;
|
|
34
40
|
providers?: Provider[];
|
|
35
41
|
stpInterface?: new (...args: any[]) => StpInterface$1;
|
|
36
|
-
|
|
42
|
+
eventSink?: XltEventSink$1;
|
|
37
43
|
}
|
|
38
44
|
declare class XltTokenModule {
|
|
39
45
|
private static readonly stpLogicProvider;
|
|
@@ -60,38 +66,27 @@ declare class XltTokenModule {
|
|
|
60
66
|
private static createStoreProvider;
|
|
61
67
|
private static createStrategyProvider;
|
|
62
68
|
private static createStpInterfaceProvider;
|
|
63
|
-
private static
|
|
69
|
+
private static createEventSinkProvider;
|
|
64
70
|
}
|
|
65
71
|
//#endregion
|
|
66
72
|
//#region src/store/redis-store.d.ts
|
|
67
73
|
declare const XLT_REDIS_CLIENT = "XLT_REDIS_CLIENT";
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
update(key: string, value: string): Promise<void>;
|
|
75
|
-
has(key: string): Promise<boolean>;
|
|
76
|
-
updateTimeout(key: string, timeoutSec: number): Promise<void>;
|
|
77
|
-
getTimeout(key: string): Promise<number>;
|
|
78
|
-
keys(pattern: string): Promise<string[]>;
|
|
74
|
+
/**
|
|
75
|
+
* @deprecated Import `RedisStore` from `@xlt-token/store-redis` and provide it
|
|
76
|
+
* through `store.useValue` for new applications.
|
|
77
|
+
*/
|
|
78
|
+
declare class RedisStore extends RedisStore$1 {
|
|
79
|
+
constructor(redisClient: RedisClient);
|
|
79
80
|
}
|
|
80
81
|
//#endregion
|
|
81
|
-
//#region src/
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
constructor(
|
|
89
|
-
private ensureJwtConfig;
|
|
90
|
-
createToken(loginId: string, config: XltTokenConfig$1, options?: {
|
|
91
|
-
timeout?: DurationInput;
|
|
92
|
-
}): string;
|
|
93
|
-
generateToken(payload: any): string;
|
|
94
|
-
verifyToken(token: string): XltJwtPayload;
|
|
82
|
+
//#region src/store/ioredis-store.d.ts
|
|
83
|
+
declare const XLT_IOREDIS_CLIENT = "XLT_IOREDIS_CLIENT";
|
|
84
|
+
/**
|
|
85
|
+
* @deprecated Import `IORedisStore` from `@xlt-token/store-redis` and provide it
|
|
86
|
+
* through `store.useValue` for new applications.
|
|
87
|
+
*/
|
|
88
|
+
declare class IORedisStore extends IORedisStore$1 {
|
|
89
|
+
constructor(redisClient: IORedisClient);
|
|
95
90
|
}
|
|
96
91
|
//#endregion
|
|
97
92
|
//#region src/decorators/xlt-check-login.decorator.d.ts
|
|
@@ -191,6 +186,7 @@ declare class NotLoginException extends UnauthorizedException {
|
|
|
191
186
|
readonly type: NotLoginType$1;
|
|
192
187
|
readonly token: string | undefined;
|
|
193
188
|
constructor(type: NotLoginType$1, token?: string);
|
|
189
|
+
private static codeForType;
|
|
194
190
|
private static describeType;
|
|
195
191
|
}
|
|
196
192
|
//#endregion
|
|
@@ -214,5 +210,5 @@ declare class NotSafeException extends ForbiddenException {
|
|
|
214
210
|
constructor(business: string);
|
|
215
211
|
}
|
|
216
212
|
//#endregion
|
|
217
|
-
export { type AuthResult, type CreateOptions, DEFAULT_XLT_TOKEN_CONFIG, type DeviceInfo, type HttpContext, JwtStrategy, LoginId, MemoryStore, NotLoginException, NotLoginType, NotPermissionException, NotRoleException, NotSafeException, RedisStore, type StpInterface, StpLogic, StpPermLogic, StpUtil, type TokenStrategy, TokenValue, UuidStrategy, XLT_CHECK_SAFE_KEY, 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 };
|
|
218
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/
|
|
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;E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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.mjs
CHANGED
|
@@ -1,7 +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,
|
|
4
|
-
import {
|
|
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";
|
|
3
|
+
import { IORedisStore as IORedisStore$1, RedisStore as RedisStore$1 } from "@xlt-token/store-redis";
|
|
4
|
+
import { JwtStrategy, createJwtStrategyConfig } from "@xlt-token/jwt";
|
|
5
5
|
import { Reflector } from "@nestjs/core";
|
|
6
6
|
|
|
7
7
|
//#region \0@oxc-project+runtime@0.112.0/helpers/decorate.js
|
|
@@ -22,12 +22,12 @@ let XltTokenModule = class XltTokenModule {
|
|
|
22
22
|
static {
|
|
23
23
|
this.stpLogicProvider = {
|
|
24
24
|
provide: StpLogic$1,
|
|
25
|
-
useFactory: (config, store, strategy,
|
|
25
|
+
useFactory: (config, store, strategy, eventSink) => new StpLogic$1(config, store, strategy, eventSink),
|
|
26
26
|
inject: [
|
|
27
27
|
XLT_TOKEN_CONFIG$1,
|
|
28
28
|
XLT_TOKEN_STORE$1,
|
|
29
29
|
XLT_TOKEN_STRATEGY$1,
|
|
30
|
-
|
|
30
|
+
XLT_EVENT_SINK$1
|
|
31
31
|
]
|
|
32
32
|
};
|
|
33
33
|
}
|
|
@@ -74,7 +74,7 @@ let XltTokenModule = class XltTokenModule {
|
|
|
74
74
|
_XltTokenModule.createStoreProvider(store),
|
|
75
75
|
_XltTokenModule.createStrategyProvider(strategy),
|
|
76
76
|
_XltTokenModule.createStpInterfaceProvider(stpInterface),
|
|
77
|
-
_XltTokenModule.
|
|
77
|
+
_XltTokenModule.createEventSinkProvider(options.eventSink),
|
|
78
78
|
_XltTokenModule.stpLogicProvider,
|
|
79
79
|
_XltTokenModule.stpPermLogicProvider,
|
|
80
80
|
_XltTokenModule.initProvider,
|
|
@@ -101,7 +101,7 @@ let XltTokenModule = class XltTokenModule {
|
|
|
101
101
|
_XltTokenModule.createStoreProvider(store),
|
|
102
102
|
_XltTokenModule.createStrategyProvider(strategy),
|
|
103
103
|
_XltTokenModule.createStpInterfaceProvider(stpInterface),
|
|
104
|
-
_XltTokenModule.
|
|
104
|
+
_XltTokenModule.createEventSinkProvider(options.eventSink),
|
|
105
105
|
_XltTokenModule.stpLogicProvider,
|
|
106
106
|
_XltTokenModule.stpPermLogicProvider,
|
|
107
107
|
_XltTokenModule.initProvider,
|
|
@@ -125,12 +125,16 @@ let XltTokenModule = class XltTokenModule {
|
|
|
125
125
|
};
|
|
126
126
|
}
|
|
127
127
|
static createStrategyProvider(strategy) {
|
|
128
|
-
|
|
128
|
+
if (!strategy) return {
|
|
129
|
+
provide: XLT_TOKEN_STRATEGY$1,
|
|
130
|
+
useClass: UuidStrategy$1
|
|
131
|
+
};
|
|
132
|
+
return "useClass" in strategy ? {
|
|
129
133
|
provide: XLT_TOKEN_STRATEGY$1,
|
|
130
134
|
useClass: strategy.useClass
|
|
131
135
|
} : {
|
|
132
136
|
provide: XLT_TOKEN_STRATEGY$1,
|
|
133
|
-
|
|
137
|
+
useValue: strategy.useValue
|
|
134
138
|
};
|
|
135
139
|
}
|
|
136
140
|
static createStpInterfaceProvider(stpInterface) {
|
|
@@ -150,10 +154,10 @@ let XltTokenModule = class XltTokenModule {
|
|
|
150
154
|
}
|
|
151
155
|
};
|
|
152
156
|
}
|
|
153
|
-
static
|
|
157
|
+
static createEventSinkProvider(eventSink) {
|
|
154
158
|
return {
|
|
155
|
-
provide:
|
|
156
|
-
useValue:
|
|
159
|
+
provide: XLT_EVENT_SINK$1,
|
|
160
|
+
useValue: eventSink ?? {}
|
|
157
161
|
};
|
|
158
162
|
}
|
|
159
163
|
};
|
|
@@ -176,49 +180,9 @@ function __decorateParam(paramIndex, decorator) {
|
|
|
176
180
|
//#endregion
|
|
177
181
|
//#region src/store/redis-store.ts
|
|
178
182
|
const XLT_REDIS_CLIENT = "XLT_REDIS_CLIENT";
|
|
179
|
-
let RedisStore = class RedisStore {
|
|
183
|
+
let RedisStore = class RedisStore extends RedisStore$1 {
|
|
180
184
|
constructor(redisClient) {
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
-
async get(key) {
|
|
184
|
-
return this.redisClient.get(key);
|
|
185
|
-
}
|
|
186
|
-
async set(key, value, timeoutSec) {
|
|
187
|
-
if (timeoutSec === -1) await this.redisClient.set(key, value);
|
|
188
|
-
else await this.redisClient.set(key, value, { EX: timeoutSec });
|
|
189
|
-
}
|
|
190
|
-
async delete(key) {
|
|
191
|
-
await this.redisClient.del(key);
|
|
192
|
-
}
|
|
193
|
-
async update(key, value) {
|
|
194
|
-
if (await this.redisClient.set(key, value, {
|
|
195
|
-
XX: true,
|
|
196
|
-
KEEPTTL: true
|
|
197
|
-
}) === null) throw new Error(`Key not found: ${key}`);
|
|
198
|
-
}
|
|
199
|
-
async has(key) {
|
|
200
|
-
return await this.redisClient.exists(key) === 1;
|
|
201
|
-
}
|
|
202
|
-
async updateTimeout(key, timeoutSec) {
|
|
203
|
-
if (!await this.redisClient.exists(key)) throw new Error(`Key not found: ${key}`);
|
|
204
|
-
if (timeoutSec === -1) await this.redisClient.persist(key);
|
|
205
|
-
else await this.redisClient.expire(key, timeoutSec);
|
|
206
|
-
}
|
|
207
|
-
async getTimeout(key) {
|
|
208
|
-
return await this.redisClient.ttl(key);
|
|
209
|
-
}
|
|
210
|
-
async keys(pattern) {
|
|
211
|
-
const result = [];
|
|
212
|
-
let cursor = "0";
|
|
213
|
-
do {
|
|
214
|
-
const reply = await this.redisClient.scan(cursor, {
|
|
215
|
-
MATCH: pattern,
|
|
216
|
-
COUNT: 100
|
|
217
|
-
});
|
|
218
|
-
cursor = String(reply.cursor);
|
|
219
|
-
result.push(...reply.keys);
|
|
220
|
-
} while (cursor !== "0");
|
|
221
|
-
return result;
|
|
185
|
+
super(redisClient);
|
|
222
186
|
}
|
|
223
187
|
};
|
|
224
188
|
RedisStore = __decorate([
|
|
@@ -228,57 +192,18 @@ RedisStore = __decorate([
|
|
|
228
192
|
], RedisStore);
|
|
229
193
|
|
|
230
194
|
//#endregion
|
|
231
|
-
//#region src/
|
|
232
|
-
const
|
|
233
|
-
let
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
jsonwebtoken ??= require("jsonwebtoken");
|
|
237
|
-
return jsonwebtoken;
|
|
238
|
-
} catch (error) {
|
|
239
|
-
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\".");
|
|
240
|
-
throw error;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
let JwtStrategy = class JwtStrategy {
|
|
244
|
-
constructor(config) {
|
|
245
|
-
this.config = config;
|
|
246
|
-
}
|
|
247
|
-
ensureJwtConfig(config) {
|
|
248
|
-
const jwt = (config ?? this.config).jwt;
|
|
249
|
-
if (!jwt || !jwt.secret) throw new Error("JwtStrategy requires jwt config with a secret. Provide { jwt: { secret: \"your-secret\" } } in the module config.");
|
|
250
|
-
return jwt;
|
|
251
|
-
}
|
|
252
|
-
createToken(loginId, config, options) {
|
|
253
|
-
const { sign } = getJsonwebtoken();
|
|
254
|
-
const jwt = this.ensureJwtConfig(config);
|
|
255
|
-
const jti = randomUUID();
|
|
256
|
-
const resolvedTimeout = options?.timeout ?? config.timeout;
|
|
257
|
-
const hasExpiry = typeof resolvedTimeout === "number" ? resolvedTimeout > 0 : true;
|
|
258
|
-
return sign({
|
|
259
|
-
sub: loginId,
|
|
260
|
-
jti
|
|
261
|
-
}, jwt.secret, {
|
|
262
|
-
algorithm: jwt.algorithm ?? "HS256",
|
|
263
|
-
...jwt.issuer && { issuer: jwt.issuer },
|
|
264
|
-
...jwt.audience && { audience: jwt.audience },
|
|
265
|
-
...hasExpiry && { expiresIn: resolvedTimeout }
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
generateToken(payload) {
|
|
269
|
-
const { sign } = getJsonwebtoken();
|
|
270
|
-
return sign(payload, this.ensureJwtConfig().secret);
|
|
271
|
-
}
|
|
272
|
-
verifyToken(token) {
|
|
273
|
-
const { verify } = getJsonwebtoken();
|
|
274
|
-
return verify(token, this.ensureJwtConfig().secret);
|
|
195
|
+
//#region src/store/ioredis-store.ts
|
|
196
|
+
const XLT_IOREDIS_CLIENT = "XLT_IOREDIS_CLIENT";
|
|
197
|
+
let IORedisStore = class IORedisStore extends IORedisStore$1 {
|
|
198
|
+
constructor(redisClient) {
|
|
199
|
+
super(redisClient);
|
|
275
200
|
}
|
|
276
201
|
};
|
|
277
|
-
|
|
202
|
+
IORedisStore = __decorate([
|
|
278
203
|
Injectable(),
|
|
279
|
-
__decorateParam(0, Inject(
|
|
204
|
+
__decorateParam(0, Inject(XLT_IOREDIS_CLIENT)),
|
|
280
205
|
__decorateMetadata("design:paramtypes", [Object])
|
|
281
|
-
],
|
|
206
|
+
], IORedisStore);
|
|
282
207
|
|
|
283
208
|
//#endregion
|
|
284
209
|
//#region src/decorators/xlt-check-login.decorator.ts
|
|
@@ -357,12 +282,23 @@ var NotLoginException = class NotLoginException extends UnauthorizedException {
|
|
|
357
282
|
constructor(type, token) {
|
|
358
283
|
super({
|
|
359
284
|
statusCode: 401,
|
|
285
|
+
code: NotLoginException.codeForType(type),
|
|
360
286
|
type,
|
|
361
287
|
message: NotLoginException.describeType(type)
|
|
362
288
|
});
|
|
363
289
|
this.type = type;
|
|
364
290
|
this.token = token;
|
|
365
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
|
+
}
|
|
366
302
|
static describeType(type) {
|
|
367
303
|
return {
|
|
368
304
|
[NotLoginType$1.NOT_TOKEN]: "未提供 Token",
|
|
@@ -381,7 +317,9 @@ var NotPermissionException = class extends ForbiddenException {
|
|
|
381
317
|
constructor(permission, mode) {
|
|
382
318
|
super({
|
|
383
319
|
statusCode: 403,
|
|
384
|
-
|
|
320
|
+
code: "PERMISSION_DENIED",
|
|
321
|
+
permission,
|
|
322
|
+
mode,
|
|
385
323
|
message: `缺少权限: ${Array.isArray(permission) ? permission.join(", ") : permission}`
|
|
386
324
|
});
|
|
387
325
|
this.permission = permission;
|
|
@@ -395,7 +333,9 @@ var NotRoleException = class extends ForbiddenException {
|
|
|
395
333
|
constructor(role, mode) {
|
|
396
334
|
super({
|
|
397
335
|
statusCode: 403,
|
|
398
|
-
|
|
336
|
+
code: "ROLE_DENIED",
|
|
337
|
+
role,
|
|
338
|
+
mode,
|
|
399
339
|
message: `缺少角色: ${Array.isArray(role) ? role.join(", ") : role}`
|
|
400
340
|
});
|
|
401
341
|
this.role = role;
|
|
@@ -409,7 +349,8 @@ var NotSafeException = class extends ForbiddenException {
|
|
|
409
349
|
constructor(business) {
|
|
410
350
|
super({
|
|
411
351
|
statusCode: 403,
|
|
412
|
-
|
|
352
|
+
code: "SAFE_REQUIRED",
|
|
353
|
+
business,
|
|
413
354
|
message: `二级认证未开启:${business}`
|
|
414
355
|
});
|
|
415
356
|
this.business = business;
|
|
@@ -560,5 +501,5 @@ XltAbstractLoginGuard = __decorate([
|
|
|
560
501
|
], XltAbstractLoginGuard);
|
|
561
502
|
|
|
562
503
|
//#endregion
|
|
563
|
-
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,
|
|
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 };
|
|
564
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","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 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 type { 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 = String(reply.cursor);\n result.push(...reply.keys);\n } while (cursor !== \"0\");\n return result;\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,2BAA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AS,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"}
|
|
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+CO,2BAAM,eAAe;;;;;0BAC2B;GACnD,SAASA;GACT,aACE,QACA,OACA,UACA,cACG,IAAIA,WAAS,QAAQ,OAAO,UAAU,UAAU;GACrD,QAAQ;IAACC;IAAkBC;IAAiBC;IAAoBC;IAAe;GAChF;;;8BACwD;GACvD,SAASC;GACT,aAAa,cAA4B,OAAsB,WAC7D,IAAIA,eAAa,cAAc,OAAO,OAAO;GAC/C,QAAQ;IAACC;IAAmBJ;IAAiBD;IAAiB;GAC/D;;;sBACgD;GAC/C,SAAS;GACT,aAAa,UAAoB,iBAA+B;AAC9D,kBAAY,SAAS;AACrB,sBAAgB,aAAa;AAC7B,WAAO;;GAET,QAAQ,CAACD,YAAUK,eAAa;GACjC;;;uBACuC;GACtCJ;GACAC;GACAC;GACAH;GACAK;GACD;;CAED,OAAO,QAAQ,UAAiC,EAAE,EAAE;EAClD,MAAM,EACJ,QAAQ,YACR,OACA,UACA,WAAW,OACX,YAAY,EAAE,EACd,iBACE;AAEJ,SAAO;GACL;GACA,WAAW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W,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,CAC1E,IAAI,YAAY,EAChB,IAAI,UAAU,CACf,CAAC;AAEF,MAAI,KAAK,OAAO,aAAc,QAAO,CAAC;AAEtC,SACE,KAAK,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": "1.
|
|
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,33 +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
|
-
"redis": "^4.0.0 || ^5.0.0",
|
|
54
|
-
"reflect-metadata": "^0.1.13 || ^0.2.0",
|
|
55
|
-
"rxjs": "^7.0.0"
|
|
56
|
-
},
|
|
57
|
-
"peerDependenciesMeta": {
|
|
58
|
-
"redis": {
|
|
59
|
-
"optional": true
|
|
60
|
-
},
|
|
61
|
-
"jsonwebtoken": {
|
|
62
|
-
"optional": true
|
|
63
|
-
}
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"access": "public"
|
|
64
48
|
},
|
|
65
49
|
"dependencies": {
|
|
66
|
-
"@xlt-token/core": "^1.
|
|
50
|
+
"@xlt-token/core": "^2.1.0",
|
|
51
|
+
"@xlt-token/jwt": "^2.1.0",
|
|
52
|
+
"@xlt-token/store-redis": "^2.1.0",
|
|
67
53
|
"uuid": "^10.0.0"
|
|
68
54
|
},
|
|
69
55
|
"devDependencies": {
|
|
@@ -88,9 +74,16 @@
|
|
|
88
74
|
"unplugin-swc": "^1.5.9",
|
|
89
75
|
"vitest": "^2.0.0"
|
|
90
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
|
+
},
|
|
91
83
|
"scripts": {
|
|
92
84
|
"build": "tsdown",
|
|
93
85
|
"build:watch": "tsdown --watch",
|
|
86
|
+
"typecheck": "tsc --noEmit",
|
|
94
87
|
"test": "vitest run",
|
|
95
88
|
"test:cov": "vitest run --coverage",
|
|
96
89
|
"test:e2e": "vitest run --config vitest.e2e.config.ts",
|