vona-module-a-jwt 5.0.13 → 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.
@@ -1,63 +1,28 @@
1
- import type { BeanScopeUtil, TypeModuleConfig } from 'vona';
2
1
  import type { TypeEntityOptionsFields } from 'vona-module-a-openapi';
3
- /** bean: end */
4
- /** bean: begin */
5
- import type { BeanJwt } from '../bean/bean.jwt.ts';
6
- import type { config } from '../config/config.ts';
7
- import type { IDtoOptionsJwtToken } from '../dto/jwtToken.ts';
8
- /** dto: end */
9
- /** dto: begin */
10
- import type { DtoJwtToken } from '../dto/jwtToken.ts';
11
- /** service: end */
12
- /** service: begin */
13
- import type { ServiceJwtClient } from '../service/jwtClient.ts';
14
- import type { ServiceJwtExtract } from '../service/jwtExtract.ts';
15
- /** config: end */
16
- /** scope: begin */
17
- import { BeanScopeBase } from 'vona';
18
- import 'vona';
19
- /** service: end */
20
- /** service: begin */
21
- import 'vona';
22
- import 'vona';
23
- import 'vona';
24
- import 'vona';
25
- import 'vona';
26
2
  /** bean: begin */
27
3
  export * from '../bean/bean.jwt.ts';
4
+ import 'vona';
28
5
  declare module 'vona' {
29
6
  }
30
7
  declare module 'vona-module-a-jwt' {
31
8
  interface BeanJwt {
32
9
  }
33
10
  }
11
+ /** bean: end */
12
+ /** bean: begin */
13
+ import type { BeanJwt } from '../bean/bean.jwt.ts';
14
+ import 'vona';
34
15
  declare module 'vona' {
35
16
  interface IBeanRecordGlobal {
36
- jwt: BeanJwt;
37
- }
38
- }
39
- /** service: end */
40
- /** config: begin */
41
- export * from '../config/config.ts';
42
- declare module 'vona-module-a-web' {
43
- interface IDtoRecord {
44
- 'a-jwt:jwtToken': Omit<IDtoOptionsJwtToken, '_fieldsMore_'>;
45
- }
46
- }
47
- declare module 'vona-module-a-jwt' {
48
- }
49
- declare module 'vona-module-a-jwt' {
50
- interface IDtoOptionsJwtToken {
51
- fields?: TypeEntityOptionsFields<DtoJwtToken, IDtoOptionsJwtToken['_fieldsMore_']>;
17
+ 'jwt': BeanJwt;
52
18
  }
53
19
  }
54
20
  /** bean: end */
55
- /** dto: begin */
56
- export * from '../dto/jwtToken.ts';
57
- /** dto: end */
58
21
  /** service: begin */
59
22
  export * from '../service/jwtClient.ts';
60
- declare module 'vona-module-a-web' {
23
+ export * from '../service/jwtExtract.ts';
24
+ import 'vona';
25
+ declare module 'vona-module-a-bean' {
61
26
  interface IServiceRecord {
62
27
  'a-jwt:jwtClient': never;
63
28
  'a-jwt:jwtExtract': never;
@@ -69,17 +34,50 @@ declare module 'vona-module-a-jwt' {
69
34
  interface ServiceJwtExtract {
70
35
  }
71
36
  }
37
+ /** service: end */
38
+ /** service: begin */
39
+ import type { ServiceJwtClient } from '../service/jwtClient.ts';
40
+ import type { ServiceJwtExtract } from '../service/jwtExtract.ts';
72
41
  export interface IModuleService {
73
- jwtClient: ServiceJwtClient;
74
- jwtExtract: ServiceJwtExtract;
42
+ 'jwtClient': ServiceJwtClient;
43
+ 'jwtExtract': ServiceJwtExtract;
75
44
  }
45
+ /** service: end */
46
+ /** service: begin */
47
+ import 'vona';
76
48
  declare module 'vona' {
77
49
  interface IBeanRecordGeneral {
78
50
  'a-jwt.service.jwtClient': ServiceJwtClient;
79
51
  'a-jwt.service.jwtExtract': ServiceJwtExtract;
80
52
  }
81
53
  }
82
- export * from '../service/jwtExtract.ts';
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
+ /** config: begin */
76
+ export * from '../config/config.ts';
77
+ import type { config } from '../config/config.ts';
78
+ /** config: end */
79
+ /** scope: begin */
80
+ import { BeanScopeBase, type BeanScopeUtil, type TypeModuleConfig } from 'vona';
83
81
  export declare class ScopeModuleAJwt extends BeanScopeBase {
84
82
  }
85
83
  export interface ScopeModuleAJwt {
@@ -87,6 +85,7 @@ export interface ScopeModuleAJwt {
87
85
  config: TypeModuleConfig<typeof config>;
88
86
  service: IModuleService;
89
87
  }
88
+ import 'vona';
90
89
  declare module 'vona' {
91
90
  interface IBeanScopeRecord {
92
91
  'a-jwt': ScopeModuleAJwt;
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { BeanInfo, BeanBase, deepExtend, cast, BeanScopeBase } from 'vona';
2
- import { Bean, Scope } from 'vona-module-a-bean';
3
2
  import ms from 'ms';
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,88 @@ 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
+
164
+ function _applyDecoratedDescriptor(i, e, r, n, l) {
165
+ var a = {};
166
+ return Object.keys(n).forEach(function (i) {
167
+ a[i] = n[i];
168
+ }), a.enumerable = !!a.enumerable, a.configurable = !!a.configurable, ("value" in a || a.initializer) && (a.writable = true), a = r.slice().reverse().reduce(function (r, n) {
169
+ return n(i, e, r) || r;
170
+ }, a), void 0 === a.initializer ? (Object.defineProperty(i, e, a), null) : a;
171
+ }
172
+ function _initializerDefineProperty(e, i, r, l) {
173
+ r && Object.defineProperty(e, i, {
174
+ enumerable: r.enumerable,
175
+ configurable: r.configurable,
176
+ writable: r.writable,
177
+ value: r.initializer ? r.initializer.call(l) : void 0
178
+ });
179
+ }
180
+
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({
183
+ module: "a-jwt"
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 {
185
+ constructor() {
186
+ _initializerDefineProperty(this, "accessToken", _descriptor, this);
187
+ _initializerDefineProperty(this, "refreshToken", _descriptor2, this);
188
+ _initializerDefineProperty(this, "expiresIn", _descriptor3, this);
189
+ }
190
+ }, _descriptor = _applyDecoratedDescriptor(_class2.prototype, "accessToken", [_dec3, _dec4], {
191
+ configurable: true,
192
+ enumerable: true,
193
+ writable: true,
194
+ initializer: null
195
+ }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "refreshToken", [_dec5, _dec6], {
196
+ configurable: true,
197
+ enumerable: true,
198
+ writable: true,
199
+ initializer: null
200
+ }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "expiresIn", [_dec7, _dec8], {
201
+ configurable: true,
202
+ enumerable: true,
203
+ writable: true,
204
+ initializer: null
205
+ }), _class2)) || _class$1) || _class$1);
206
+
125
207
  function config(app) {
126
208
  return {
127
209
  field: {
@@ -179,88 +261,6 @@ function config(app) {
179
261
  };
180
262
  }
181
263
 
182
- function _applyDecoratedDescriptor(i, e, r, n, l) {
183
- var a = {};
184
- return Object.keys(n).forEach(function (i) {
185
- a[i] = n[i];
186
- }), a.enumerable = !!a.enumerable, a.configurable = !!a.configurable, ("value" in a || a.initializer) && (a.writable = true), a = r.slice().reverse().reduce(function (r, n) {
187
- return n(i, e, r) || r;
188
- }, a), void 0 === a.initializer ? (Object.defineProperty(i, e, a), null) : a;
189
- }
190
- function _initializerDefineProperty(e, i, r, l) {
191
- r && Object.defineProperty(e, i, {
192
- enumerable: r.enumerable,
193
- configurable: r.configurable,
194
- writable: r.writable,
195
- value: r.initializer ? r.initializer.call(l) : void 0
196
- });
197
- }
198
-
199
- var _dec$2, _dec2$2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _class$2, _class2, _descriptor, _descriptor2, _descriptor3;
200
- let DtoJwtToken = (_dec$2 = Dto(), _dec2$2 = BeanInfo({
201
- module: "a-jwt"
202
- }), _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 {
203
- constructor() {
204
- _initializerDefineProperty(this, "accessToken", _descriptor, this);
205
- _initializerDefineProperty(this, "refreshToken", _descriptor2, this);
206
- _initializerDefineProperty(this, "expiresIn", _descriptor3, this);
207
- }
208
- }, _descriptor = _applyDecoratedDescriptor(_class2.prototype, "accessToken", [_dec3, _dec4], {
209
- configurable: true,
210
- enumerable: true,
211
- writable: true,
212
- initializer: null
213
- }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "refreshToken", [_dec5, _dec6], {
214
- configurable: true,
215
- enumerable: true,
216
- writable: true,
217
- initializer: null
218
- }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "expiresIn", [_dec7, _dec8], {
219
- configurable: true,
220
- enumerable: true,
221
- writable: true,
222
- initializer: null
223
- }), _class2)) || _class$2) || _class$2);
224
-
225
- const re = /(\S+)\s+(\S+)/;
226
- function parseAuthHeader(headerValue) {
227
- if (typeof headerValue !== 'string') return;
228
- const matches = headerValue.match(re);
229
- return matches && {
230
- scheme: matches[1],
231
- value: matches[2]
232
- };
233
- }
234
-
235
- var _dec$1, _dec2$1, _class$1;
236
- let ServiceJwtExtract = (_dec$1 = Service(), _dec2$1 = BeanInfo({
237
- module: "a-jwt"
238
- }), _dec$1(_class$1 = _dec2$1(_class$1 = class ServiceJwtExtract extends BeanBase {
239
- fromHeader() {
240
- if (!this.scope.config.field.extract.header) return;
241
- return this.ctx.request.headers[this.scope.config.field.extract.header];
242
- }
243
- fromQuery() {
244
- return this.ctx.request.query[this.scope.config.field.extract.query];
245
- }
246
- fromAuthHeaderWithScheme() {
247
- const headerValue = this.ctx.request.headers[this.scope.config.field.extract.headerAuth];
248
- const auth = parseAuthHeader(headerValue);
249
- if (!auth || auth.scheme.toLocaleLowerCase() !== this.scope.config.field.extract.headerAuthScheme.toLocaleLowerCase()) return;
250
- return auth.value;
251
- }
252
- fromCookie() {
253
- return this.ctx.cookies.get(this.scope.config.field.extract.cookie);
254
- }
255
- fromAllWays() {
256
- let token = this.fromQuery();
257
- if (!token) token = this.fromAuthHeaderWithScheme();
258
- if (!token) token = this.fromHeader();
259
- if (!token) token = this.fromCookie();
260
- return token;
261
- }
262
- }) || _class$1) || _class$1);
263
-
264
264
  var _dec, _dec2, _class;
265
265
  let ScopeModuleAJwt = (_dec = Scope(), _dec2 = BeanInfo({
266
266
  module: "a-jwt"
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.13",
4
+ "version": "5.0.15",
5
5
  "title": "a-jwt",
6
6
  "vonaModule": {
7
7
  "dependencies": {}