vona-module-a-jwt 5.0.22 → 5.0.24

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.js CHANGED
@@ -26,8 +26,8 @@ let ServiceJwtClient = (_dec$4 = Service(), _dec2$4 = BeanInfo({
26
26
  const configJwt = this.scope.config;
27
27
  const configClient = configJwt.clients[clientName];
28
28
  if (!configClient) throw new Error(`jwt client not found: ${clientName}`);
29
- const secret = configJwt.default.secret ?? this.app.config.server.keys[0];
30
- this._clientOptions = deepExtend({}, configJwt.default, {
29
+ const secret = configJwt.base.secret ?? this.app.config.server.keys[0];
30
+ this._clientOptions = deepExtend({}, configJwt.base, {
31
31
  secret
32
32
  }, configClient);
33
33
  this._clientName = clientName;
@@ -57,7 +57,7 @@ let ServiceJwtClient = (_dec$4 = Service(), _dec2$4 = BeanInfo({
57
57
  }
58
58
  if (options?.temp) {
59
59
  signOptions = Object.assign({}, signOptions, {
60
- expiresIn: this.scope.config.tempToken.signOptions.expiresIn
60
+ expiresIn: this.scope.config.tempAuthToken.signOptions.expiresIn
61
61
  });
62
62
  }
63
63
  this._jwtInstance.sign(payload, this._clientOptions.secret, signOptions, (err, encoded) => {
@@ -70,7 +70,7 @@ let ServiceJwtClient = (_dec$4 = Service(), _dec2$4 = BeanInfo({
70
70
  if (!token && this._clientName === 'access') token = this.scope.service.jwtExtract.fromAllWays();
71
71
  if (!token) return undefined;
72
72
  return new Promise((resolve, reject) => {
73
- this._jwtInstance.verify(token, this._clientOptions.secret, this._clientOptions.signOptions, (err, decoded) => {
73
+ this._jwtInstance.verify(token, this._clientOptions.secret, this._clientOptions.verifyOptions, (err, decoded) => {
74
74
  if (err) return reject(err);
75
75
  const payload = cast(decoded);
76
76
  // check field client
@@ -104,7 +104,7 @@ let BeanJwt = (_dec$3 = Bean(), _dec2$3 = BeanInfo({
104
104
  const refreshToken = await this.get('refresh').sign(payloadData, options);
105
105
  // expiresIn
106
106
  let expiresIn = this.scope.config.clients.access.signOptions.expiresIn;
107
- if (typeof expiresIn === 'string') expiresIn = ms(expiresIn);
107
+ if (typeof expiresIn === 'string') expiresIn = Math.floor(ms(expiresIn) / 1000);
108
108
  // ok
109
109
  return {
110
110
  accessToken,
@@ -226,15 +226,18 @@ function config(app) {
226
226
  cookie: 'token'
227
227
  }
228
228
  },
229
- tempToken: {
229
+ tempAuthToken: {
230
230
  signOptions: {
231
231
  expiresIn: 10 * 60
232
232
  }
233
233
  },
234
- default: {
234
+ base: {
235
235
  secret: undefined,
236
236
  signOptions: {
237
237
  issuer: app.meta.env.APP_NAME
238
+ },
239
+ verifyOptions: {
240
+ issuer: app.meta.env.APP_NAME
238
241
  }
239
242
  },
240
243
  clients: {
@@ -1,4 +1,5 @@
1
- import type { SignOptions } from 'jsonwebtoken';
1
+ import type { SignOptions, VerifyOptions } from 'jsonwebtoken';
2
+ import type { StringValue } from 'ms';
2
3
  export declare const ErrorMessageJwtExpired = "jwt expired";
3
4
  export interface IJwtToken {
4
5
  accessToken: string;
@@ -23,6 +24,7 @@ export interface IJwtVerifyOptions {
23
24
  export interface IJwtClientOptions {
24
25
  secret?: string;
25
26
  signOptions: SignOptions;
27
+ verifyOptions?: VerifyOptions;
26
28
  }
27
29
  export interface ConfigJwt {
28
30
  field: {
@@ -39,12 +41,12 @@ export interface ConfigJwt {
39
41
  cookie: string;
40
42
  };
41
43
  };
42
- tempToken: {
44
+ tempAuthToken: {
43
45
  signOptions: {
44
- expiresIn: number;
46
+ expiresIn: StringValue | number;
45
47
  };
46
48
  };
47
- default: IJwtClientOptions;
49
+ base: IJwtClientOptions;
48
50
  clients: Record<keyof IJwtClientRecord, IJwtClientOptions>;
49
51
  }
50
52
  export interface IPayloadData {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vona-module-a-jwt",
3
3
  "type": "module",
4
- "version": "5.0.22",
4
+ "version": "5.0.24",
5
5
  "title": "a-jwt",
6
6
  "vonaModule": {
7
7
  "dependencies": {}
@@ -26,7 +26,8 @@
26
26
  "dist"
27
27
  ],
28
28
  "dependencies": {
29
- "@types/jsonwebtoken": "9.0.8",
29
+ "@types/jsonwebtoken": "^9.0.10",
30
+ "@types/ms": "^2.1.0",
30
31
  "jsonwebtoken": "^9.0.2",
31
32
  "ms": "^2.1.3"
32
33
  },