vona-module-a-jwt 5.0.14 → 5.0.15

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.
@@ -18,31 +18,11 @@ declare module 'vona' {
18
18
  }
19
19
  }
20
20
  /** bean: end */
21
- /** dto: begin */
22
- export * from '../dto/jwtToken.ts';
23
- import type { IDtoOptionsJwtToken } from '../dto/jwtToken.ts';
24
- import 'vona';
25
- declare module 'vona-module-a-web' {
26
- interface IDtoRecord {
27
- 'a-jwt:jwtToken': Omit<IDtoOptionsJwtToken, '_fieldsMore_'>;
28
- }
29
- }
30
- declare module 'vona-module-a-jwt' {
31
- }
32
- /** dto: end */
33
- /** dto: begin */
34
- import type { DtoJwtToken } from '../dto/jwtToken.ts';
35
- declare module 'vona-module-a-jwt' {
36
- interface IDtoOptionsJwtToken {
37
- fields?: TypeEntityOptionsFields<DtoJwtToken, IDtoOptionsJwtToken['_fieldsMore_']>;
38
- }
39
- }
40
- /** dto: end */
41
21
  /** service: begin */
42
22
  export * from '../service/jwtClient.ts';
43
23
  export * from '../service/jwtExtract.ts';
44
24
  import 'vona';
45
- declare module 'vona-module-a-web' {
25
+ declare module 'vona-module-a-bean' {
46
26
  interface IServiceRecord {
47
27
  'a-jwt:jwtClient': never;
48
28
  'a-jwt:jwtExtract': never;
@@ -72,6 +52,26 @@ declare module 'vona' {
72
52
  }
73
53
  }
74
54
  /** service: end */
55
+ /** dto: begin */
56
+ export * from '../dto/jwtToken.ts';
57
+ import type { IDtoOptionsJwtToken } from '../dto/jwtToken.ts';
58
+ import 'vona';
59
+ declare module 'vona-module-a-web' {
60
+ interface IDtoRecord {
61
+ 'a-jwt:jwtToken': Omit<IDtoOptionsJwtToken, '_fieldsMore_'>;
62
+ }
63
+ }
64
+ declare module 'vona-module-a-jwt' {
65
+ }
66
+ /** dto: end */
67
+ /** dto: begin */
68
+ import type { DtoJwtToken } from '../dto/jwtToken.ts';
69
+ declare module 'vona-module-a-jwt' {
70
+ interface IDtoOptionsJwtToken {
71
+ fields?: TypeEntityOptionsFields<DtoJwtToken, IDtoOptionsJwtToken['_fieldsMore_']>;
72
+ }
73
+ }
74
+ /** dto: end */
75
75
  /** config: begin */
76
76
  export * from '../config/config.ts';
77
77
  import type { config } from '../config/config.ts';
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { BeanInfo, BeanBase, deepExtend, cast, BeanScopeBase } from 'vona';
2
2
  import ms from 'ms';
3
- import { Bean, Scope } from 'vona-module-a-bean';
3
+ import { Service, Bean, Scope } from 'vona-module-a-bean';
4
4
  import jwt from 'jsonwebtoken';
5
- import { Service, Dto } from 'vona-module-a-web';
6
5
  import { Api } from 'vona-module-a-openapi';
6
+ import { Dto } from 'vona-module-a-web';
7
7
 
8
8
  var _dec$4, _dec2$4, _class$4;
9
9
  let ServiceJwtClient = (_dec$4 = Service(), _dec2$4 = BeanInfo({
@@ -122,6 +122,45 @@ let BeanJwt = (_dec$3 = Bean(), _dec2$3 = BeanInfo({
122
122
  }
123
123
  }) || _class$3) || _class$3);
124
124
 
125
+ const re = /(\S+)\s+(\S+)/;
126
+ function parseAuthHeader(headerValue) {
127
+ if (typeof headerValue !== 'string') return;
128
+ const matches = headerValue.match(re);
129
+ return matches && {
130
+ scheme: matches[1],
131
+ value: matches[2]
132
+ };
133
+ }
134
+
135
+ var _dec$2, _dec2$2, _class$2;
136
+ let ServiceJwtExtract = (_dec$2 = Service(), _dec2$2 = BeanInfo({
137
+ module: "a-jwt"
138
+ }), _dec$2(_class$2 = _dec2$2(_class$2 = class ServiceJwtExtract extends BeanBase {
139
+ fromHeader() {
140
+ if (!this.scope.config.field.extract.header) return;
141
+ return this.ctx.request.headers[this.scope.config.field.extract.header];
142
+ }
143
+ fromQuery() {
144
+ return this.ctx.request.query[this.scope.config.field.extract.query];
145
+ }
146
+ fromAuthHeaderWithScheme() {
147
+ const headerValue = this.ctx.request.headers[this.scope.config.field.extract.headerAuth];
148
+ const auth = parseAuthHeader(headerValue);
149
+ if (!auth || auth.scheme.toLocaleLowerCase() !== this.scope.config.field.extract.headerAuthScheme.toLocaleLowerCase()) return;
150
+ return auth.value;
151
+ }
152
+ fromCookie() {
153
+ return this.ctx.cookies.get(this.scope.config.field.extract.cookie);
154
+ }
155
+ fromAllWays() {
156
+ let token = this.fromQuery();
157
+ if (!token) token = this.fromAuthHeaderWithScheme();
158
+ if (!token) token = this.fromHeader();
159
+ if (!token) token = this.fromCookie();
160
+ return token;
161
+ }
162
+ }) || _class$2) || _class$2);
163
+
125
164
  function _applyDecoratedDescriptor(i, e, r, n, l) {
126
165
  var a = {};
127
166
  return Object.keys(n).forEach(function (i) {
@@ -139,10 +178,10 @@ function _initializerDefineProperty(e, i, r, l) {
139
178
  });
140
179
  }
141
180
 
142
- var _dec$2, _dec2$2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _class$2, _class2, _descriptor, _descriptor2, _descriptor3;
143
- let DtoJwtToken = (_dec$2 = Dto(), _dec2$2 = BeanInfo({
181
+ var _dec$1, _dec2$1, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _class$1, _class2, _descriptor, _descriptor2, _descriptor3;
182
+ let DtoJwtToken = (_dec$1 = Dto(), _dec2$1 = BeanInfo({
144
183
  module: "a-jwt"
145
- }), _dec3 = Api.field(), _dec4 = Reflect.metadata("design:type", String), _dec5 = Api.field(), _dec6 = Reflect.metadata("design:type", String), _dec7 = Api.field(), _dec8 = Reflect.metadata("design:type", Number), _dec$2(_class$2 = _dec2$2(_class$2 = (_class2 = class DtoJwtToken {
184
+ }), _dec3 = Api.field(), _dec4 = Reflect.metadata("design:type", String), _dec5 = Api.field(), _dec6 = Reflect.metadata("design:type", String), _dec7 = Api.field(), _dec8 = Reflect.metadata("design:type", Number), _dec$1(_class$1 = _dec2$1(_class$1 = (_class2 = class DtoJwtToken {
146
185
  constructor() {
147
186
  _initializerDefineProperty(this, "accessToken", _descriptor, this);
148
187
  _initializerDefineProperty(this, "refreshToken", _descriptor2, this);
@@ -163,46 +202,7 @@ let DtoJwtToken = (_dec$2 = Dto(), _dec2$2 = BeanInfo({
163
202
  enumerable: true,
164
203
  writable: true,
165
204
  initializer: null
166
- }), _class2)) || _class$2) || _class$2);
167
-
168
- const re = /(\S+)\s+(\S+)/;
169
- function parseAuthHeader(headerValue) {
170
- if (typeof headerValue !== 'string') return;
171
- const matches = headerValue.match(re);
172
- return matches && {
173
- scheme: matches[1],
174
- value: matches[2]
175
- };
176
- }
177
-
178
- var _dec$1, _dec2$1, _class$1;
179
- let ServiceJwtExtract = (_dec$1 = Service(), _dec2$1 = BeanInfo({
180
- module: "a-jwt"
181
- }), _dec$1(_class$1 = _dec2$1(_class$1 = class ServiceJwtExtract extends BeanBase {
182
- fromHeader() {
183
- if (!this.scope.config.field.extract.header) return;
184
- return this.ctx.request.headers[this.scope.config.field.extract.header];
185
- }
186
- fromQuery() {
187
- return this.ctx.request.query[this.scope.config.field.extract.query];
188
- }
189
- fromAuthHeaderWithScheme() {
190
- const headerValue = this.ctx.request.headers[this.scope.config.field.extract.headerAuth];
191
- const auth = parseAuthHeader(headerValue);
192
- if (!auth || auth.scheme.toLocaleLowerCase() !== this.scope.config.field.extract.headerAuthScheme.toLocaleLowerCase()) return;
193
- return auth.value;
194
- }
195
- fromCookie() {
196
- return this.ctx.cookies.get(this.scope.config.field.extract.cookie);
197
- }
198
- fromAllWays() {
199
- let token = this.fromQuery();
200
- if (!token) token = this.fromAuthHeaderWithScheme();
201
- if (!token) token = this.fromHeader();
202
- if (!token) token = this.fromCookie();
203
- return token;
204
- }
205
- }) || _class$1) || _class$1);
205
+ }), _class2)) || _class$1) || _class$1);
206
206
 
207
207
  function config(app) {
208
208
  return {
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.14",
4
+ "version": "5.0.15",
5
5
  "title": "a-jwt",
6
6
  "vonaModule": {
7
7
  "dependencies": {}