vona-module-a-jwt 5.0.15 → 5.0.17

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.
@@ -1,3 +1,4 @@
1
+ import type { TypeSymbolKeyFieldsMore } from 'vona-module-a-orm';
1
2
  import type { TypeEntityOptionsFields } from 'vona-module-a-openapi';
2
3
  /** bean: begin */
3
4
  export * from '../bean/bean.jwt.ts';
@@ -31,7 +32,15 @@ declare module 'vona-module-a-bean' {
31
32
  declare module 'vona-module-a-jwt' {
32
33
  interface ServiceJwtClient {
33
34
  }
35
+ interface ServiceJwtClient {
36
+ get $beanFullName(): 'a-jwt.service.jwtClient';
37
+ get $onionName(): 'a-jwt:jwtClient';
38
+ }
39
+ interface ServiceJwtExtract {
40
+ }
34
41
  interface ServiceJwtExtract {
42
+ get $beanFullName(): 'a-jwt.service.jwtExtract';
43
+ get $onionName(): 'a-jwt:jwtExtract';
35
44
  }
36
45
  }
37
46
  /** service: end */
@@ -58,7 +67,7 @@ import type { IDtoOptionsJwtToken } from '../dto/jwtToken.ts';
58
67
  import 'vona';
59
68
  declare module 'vona-module-a-web' {
60
69
  interface IDtoRecord {
61
- 'a-jwt:jwtToken': Omit<IDtoOptionsJwtToken, '_fieldsMore_'>;
70
+ 'a-jwt:jwtToken': IDtoOptionsJwtToken;
62
71
  }
63
72
  }
64
73
  declare module 'vona-module-a-jwt' {
@@ -68,7 +77,7 @@ declare module 'vona-module-a-jwt' {
68
77
  import type { DtoJwtToken } from '../dto/jwtToken.ts';
69
78
  declare module 'vona-module-a-jwt' {
70
79
  interface IDtoOptionsJwtToken {
71
- fields?: TypeEntityOptionsFields<DtoJwtToken, IDtoOptionsJwtToken['_fieldsMore_']>;
80
+ fields?: TypeEntityOptionsFields<DtoJwtToken, IDtoOptionsJwtToken[TypeSymbolKeyFieldsMore]>;
72
81
  }
73
82
  }
74
83
  /** dto: end */
@@ -4,8 +4,8 @@ import { ServiceJwtClient } from '../service/jwtClient.ts';
4
4
  export declare class BeanJwt extends BeanBase {
5
5
  get(clientName?: keyof IJwtClientRecord): ServiceJwtClient;
6
6
  create(payloadData: IPayloadDataBase, options?: IJwtSignOptions): Promise<IJwtToken>;
7
- createTemp(payloadData: IPayloadDataBase, options?: IJwtSignOptions): Promise<string>;
8
- createOauth(payloadData: IPayloadDataBase, options?: IJwtSignOptions): Promise<string>;
7
+ createTempAuthToken(payloadData: IPayloadDataBase, options?: IJwtSignOptions): Promise<string>;
8
+ createOauthAuthToken(payloadData: IPayloadDataBase, options?: IJwtSignOptions): Promise<string>;
9
9
  createOauthState(payloadData: IPayloadDataBase, options?: IJwtSignOptions): Promise<string>;
10
10
  createOauthCode(payloadData: IPayloadDataBase, options?: IJwtSignOptions): Promise<string>;
11
11
  }
package/dist/index.js CHANGED
@@ -66,7 +66,7 @@ let ServiceJwtClient = (_dec$4 = Service(), _dec2$4 = BeanInfo({
66
66
  });
67
67
  });
68
68
  }
69
- async verify(token) {
69
+ async verify(token, options) {
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) => {
@@ -76,12 +76,18 @@ let ServiceJwtClient = (_dec$4 = Service(), _dec2$4 = BeanInfo({
76
76
  // check field client
77
77
  if (payload[this.fieldClient] !== this._clientName) return this.app.throw(401);
78
78
  // check field path
79
- if (payload[this.fieldPath] && payload[this.fieldPath] !== this.ctx.route.routePathRaw) return this.app.throw(401);
79
+ if (!this._checkVerifyPath(payload[this.fieldPath], options?.path)) return this.app.throw(401);
80
80
  // passed
81
81
  resolve(payload[this.fieldData]);
82
82
  });
83
83
  });
84
84
  }
85
+ _checkVerifyPath(pathTarget, pathReal) {
86
+ if (!pathTarget) return true;
87
+ const path = pathReal ?? String(this.ctx.route.routePathRaw);
88
+ if (Array.isArray(pathTarget) && !pathTarget.includes(path)) return false;
89
+ return pathTarget === path;
90
+ }
85
91
  }) || _class$4) || _class$4);
86
92
 
87
93
  var _dec$3, _dec2$3, _class$3;
@@ -106,12 +112,12 @@ let BeanJwt = (_dec$3 = Bean(), _dec2$3 = BeanInfo({
106
112
  expiresIn
107
113
  };
108
114
  }
109
- async createTemp(payloadData, options) {
115
+ async createTempAuthToken(payloadData, options) {
110
116
  return await this.get('access').sign(payloadData, Object.assign({}, options, {
111
117
  temp: true
112
118
  }));
113
119
  }
114
- async createOauth(payloadData, options) {
120
+ async createOauthAuthToken(payloadData, options) {
115
121
  return await this.get('oauth').sign(payloadData, options);
116
122
  }
117
123
  async createOauthState(payloadData, options) {
@@ -1,4 +1,4 @@
1
- import type { IJwtClientRecord, IJwtSignOptions, IPayloadDataBase } from '../types/jwt.ts';
1
+ import type { IJwtClientRecord, IJwtSignOptions, IJwtVerifyOptions, IPayloadDataBase } from '../types/jwt.ts';
2
2
  import jwt from 'jsonwebtoken';
3
3
  import { BeanBase } from 'vona';
4
4
  export declare class ServiceJwtClient extends BeanBase {
@@ -12,5 +12,6 @@ export declare class ServiceJwtClient extends BeanBase {
12
12
  private get fieldPath();
13
13
  private get fieldData();
14
14
  sign(payloadData: IPayloadDataBase, options?: IJwtSignOptions): Promise<string>;
15
- verify(token?: string): Promise<IPayloadDataBase | undefined>;
15
+ verify(token?: string, options?: IJwtVerifyOptions): Promise<IPayloadDataBase | undefined>;
16
+ _checkVerifyPath(pathTarget: string | string[] | undefined, pathReal: string | undefined): boolean;
16
17
  }
@@ -17,6 +17,9 @@ export interface IJwtSignOptions {
17
17
  dev?: boolean;
18
18
  temp?: boolean;
19
19
  }
20
+ export interface IJwtVerifyOptions {
21
+ path?: string;
22
+ }
20
23
  export interface IJwtClientOptions {
21
24
  secret?: string;
22
25
  signOptions: SignOptions;
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.15",
4
+ "version": "5.0.17",
5
5
  "title": "a-jwt",
6
6
  "vonaModule": {
7
7
  "dependencies": {}