@jayfong/x-server 2.108.0 → 2.108.2
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/lib/_cjs/cli/cli.js +0 -0
- package/lib/_cjs/services/jwt.js +1 -0
- package/lib/services/jwt.d.ts +12 -6
- package/lib/services/jwt.js +1 -0
- package/package.json +1 -1
package/lib/_cjs/cli/cli.js
CHANGED
|
File without changes
|
package/lib/_cjs/services/jwt.js
CHANGED
|
@@ -39,6 +39,7 @@ class JwtService {
|
|
|
39
39
|
if (err || !data || typeof data === 'string' || !data.iat || !data.exp) {
|
|
40
40
|
reject(new _http_error.HttpError.Unauthorized('data'));
|
|
41
41
|
} else {
|
|
42
|
+
data.token = token;
|
|
42
43
|
if (this.cache) {
|
|
43
44
|
this.cache.set(token, data, {
|
|
44
45
|
ttl: (0, _date.differenceInMilliseconds)((0, _date.fromUnixTime)(data.exp), new Date())
|
package/lib/services/jwt.d.ts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import type { IncomingHttpHeaders } from 'http';
|
|
1
|
+
import type { IncomingHttpHeaders } from 'node:http';
|
|
2
2
|
import jwt from 'jsonwebtoken';
|
|
3
3
|
import { LRUCache } from 'lru-cache';
|
|
4
|
-
import { MsValue } from 'vtils';
|
|
4
|
+
import { type MsValue } from 'vtils';
|
|
5
5
|
import type { RequiredBy } from 'vtils/types';
|
|
6
|
-
import { BaseService } from './base';
|
|
6
|
+
import type { BaseService } from './base';
|
|
7
7
|
export interface JwtServiceJwtPayload extends Record<string, any> {
|
|
8
8
|
}
|
|
9
9
|
export interface JwtServiceOptions {
|
|
10
10
|
secret: string;
|
|
11
11
|
ttl: MsValue;
|
|
12
12
|
cache?: LRUCache.Options<string, JwtServiceJwtPayload, any>;
|
|
13
|
-
onVerify?: (payload: JwtServiceJwtPayload & RequiredBy<jwt.JwtPayload, 'iat' | 'exp'>
|
|
13
|
+
onVerify?: (payload: JwtServiceJwtPayload & RequiredBy<jwt.JwtPayload, 'iat' | 'exp'> & {
|
|
14
|
+
token: string;
|
|
15
|
+
}) => any;
|
|
14
16
|
}
|
|
15
17
|
export declare class JwtService implements BaseService {
|
|
16
18
|
private options;
|
|
@@ -18,8 +20,12 @@ export declare class JwtService implements BaseService {
|
|
|
18
20
|
private cache;
|
|
19
21
|
constructor(options: JwtServiceOptions);
|
|
20
22
|
sign<T extends JwtServiceJwtPayload>(payload: T, ttl?: MsValue): string;
|
|
21
|
-
verify<T extends JwtServiceJwtPayload>(token: string): Promise<T
|
|
22
|
-
|
|
23
|
+
verify<T extends JwtServiceJwtPayload>(token: string): Promise<T & {
|
|
24
|
+
token: string;
|
|
25
|
+
}>;
|
|
26
|
+
verifyFromHttpHeaders<T extends JwtServiceJwtPayload>(headers: IncomingHttpHeaders): Promise<T & {
|
|
27
|
+
token: string;
|
|
28
|
+
}>;
|
|
23
29
|
}
|
|
24
30
|
declare module '../x' {
|
|
25
31
|
interface X {
|
package/lib/services/jwt.js
CHANGED
|
@@ -34,6 +34,7 @@ export class JwtService {
|
|
|
34
34
|
if (err || !data || typeof data === 'string' || !data.iat || !data.exp) {
|
|
35
35
|
reject(new HttpError.Unauthorized('data'));
|
|
36
36
|
} else {
|
|
37
|
+
data.token = token;
|
|
37
38
|
if (this.cache) {
|
|
38
39
|
this.cache.set(token, data, {
|
|
39
40
|
ttl: differenceInMilliseconds(fromUnixTime(data.exp), new Date())
|