vona-module-a-user 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,7 +18,6 @@ import type { EventSignout } from '../bean/event.signout.ts';
18
18
  import type { TypeEventSignoutData, TypeEventSignoutResult } from '../bean/event.signout.ts';
19
19
  /** guard: end */
20
20
  /** bean: begin */
21
- import type { IGuardOptionsAdmin } from '../bean/guard.admin.ts';
22
21
  import type { IGuardOptionsPassport } from '../bean/guard.passport.ts';
23
22
  import type { IGuardOptionsRoleName } from '../bean/guard.roleName.ts';
24
23
  import type { IGuardOptionsUserName } from '../bean/guard.userName.ts';
@@ -35,20 +34,16 @@ import 'vona';
35
34
  export * from '../bean/bean.authInner.ts';
36
35
  export * from '../bean/bean.passport.ts';
37
36
  export * from '../bean/bean.roleInner.ts';
38
- export * from '../bean/bean.userInner.ts';
39
37
  declare module 'vona-module-a-aspect' {
40
38
  interface IGuardRecordGlobal {
41
39
  'a-user:passport': IGuardOptionsPassport;
42
40
  }
43
41
  interface IGuardRecordLocal {
44
- 'a-user:admin': IGuardOptionsAdmin;
45
42
  'a-user:roleName': IGuardOptionsRoleName;
46
43
  'a-user:userName': IGuardOptionsUserName;
47
44
  }
48
45
  }
49
46
  declare module 'vona-module-a-user' {
50
- interface GuardAdmin {
51
- }
52
47
  interface GuardPassport {
53
48
  }
54
49
  interface GuardRoleName {
@@ -56,13 +51,12 @@ declare module 'vona-module-a-user' {
56
51
  interface GuardUserName {
57
52
  }
58
53
  }
54
+ export * from '../bean/bean.userInner.ts';
59
55
  /** bean: end */
60
56
  /** event: begin */
61
57
  export * from '../bean/event.createUserAnonymous.ts';
62
58
  export * from '../bean/event.signin.ts';
63
59
  export * from '../bean/event.signout.ts';
64
- /** guard: begin */
65
- export * from '../bean/guard.admin.ts';
66
60
  declare module 'vona' {
67
61
  }
68
62
  declare module 'vona-module-a-user' {
@@ -83,6 +77,7 @@ declare module 'vona' {
83
77
  userInner: BeanUserInner;
84
78
  }
85
79
  }
80
+ /** guard: begin */
86
81
  export * from '../bean/guard.passport.ts';
87
82
  export * from '../bean/guard.roleName.ts';
88
83
  export * from '../bean/guard.userName.ts';
package/dist/index.js CHANGED
@@ -5,10 +5,10 @@ import { Event, BeanEventBase } from 'vona-module-a-event';
5
5
  import { Guard, Aspect } from 'vona-module-a-aspect';
6
6
  import { Meta } from 'vona-module-a-meta';
7
7
 
8
- var _dec$c, _dec2$c, _class$c;
9
- let BeanAuthInner = (_dec$c = Bean(), _dec2$c = BeanInfo({
8
+ var _dec$b, _dec2$b, _class$b;
9
+ let BeanAuthInner = (_dec$b = Bean(), _dec2$b = BeanInfo({
10
10
  module: "a-user"
11
- }), _dec$c(_class$c = _dec2$c(_class$c = class BeanAuthInner extends BeanBase {
11
+ }), _dec$b(_class$b = _dec2$b(_class$b = class BeanAuthInner extends BeanBase {
12
12
  constructor(...args) {
13
13
  super(...args);
14
14
  this._authInnerAdapter = void 0;
@@ -24,7 +24,7 @@ let BeanAuthInner = (_dec$c = Bean(), _dec2$c = BeanInfo({
24
24
  if (String(auth.id).charAt(0) === '-') return auth;
25
25
  return await this.authInnerAdapter.findOne(auth);
26
26
  }
27
- }) || _class$c) || _class$c);
27
+ }) || _class$b) || _class$b);
28
28
 
29
29
  let __authAdapter;
30
30
  function setAuthAdapter(authAdapter) {
@@ -60,10 +60,10 @@ function $getUserIdSystem(_userName, userId) {
60
60
  return userId;
61
61
  }
62
62
 
63
- var _dec$b, _dec2$b, _class$b;
64
- let BeanPassport = (_dec$b = Bean(), _dec2$b = BeanInfo({
63
+ var _dec$a, _dec2$a, _class$a;
64
+ let BeanPassport = (_dec$a = Bean(), _dec2$a = BeanInfo({
65
65
  module: "a-user"
66
- }), _dec$b(_class$b = _dec2$b(_class$b = class BeanPassport extends BeanBase {
66
+ }), _dec$a(_class$a = _dec2$a(_class$a = class BeanPassport extends BeanBase {
67
67
  constructor(...args) {
68
68
  super(...args);
69
69
  this._authTokenAdapter = void 0;
@@ -89,8 +89,8 @@ let BeanPassport = (_dec$b = Bean(), _dec2$b = BeanInfo({
89
89
  return !!user && !$getUserAnonymous(user);
90
90
  }
91
91
  async isAdmin() {
92
- const user = this.getCurrentUser();
93
- return !!user && this.isAuthenticated && (await this.passportAdapter.isAdmin(user));
92
+ const passport = this.getCurrent();
93
+ return await this.passportAdapter.isAdmin(passport);
94
94
  }
95
95
  async setCurrent(passport) {
96
96
  this.ctx.state.passport = await this.passportAdapter.setCurrent(passport);
@@ -254,12 +254,12 @@ let BeanPassport = (_dec$b = Bean(), _dec2$b = BeanInfo({
254
254
  return payloadData2;
255
255
  }
256
256
  }
257
- }) || _class$b) || _class$b);
257
+ }) || _class$a) || _class$a);
258
258
 
259
- var _dec$a, _dec2$a, _class$a;
260
- let BeanRoleInner = (_dec$a = Bean(), _dec2$a = BeanInfo({
259
+ var _dec$9, _dec2$9, _class$9;
260
+ let BeanRoleInner = (_dec$9 = Bean(), _dec2$9 = BeanInfo({
261
261
  module: "a-user"
262
- }), _dec$a(_class$a = _dec2$a(_class$a = class BeanRoleInner extends BeanBase {
262
+ }), _dec$9(_class$9 = _dec2$9(_class$9 = class BeanRoleInner extends BeanBase {
263
263
  constructor(...args) {
264
264
  super(...args);
265
265
  this._roleInnerAdapter = void 0;
@@ -280,12 +280,12 @@ let BeanRoleInner = (_dec$a = Bean(), _dec2$a = BeanInfo({
280
280
  findAllByUserId(userId) {
281
281
  return this.roleInnerAdapter.findAllByUserId(userId);
282
282
  }
283
- }) || _class$a) || _class$a);
283
+ }) || _class$9) || _class$9);
284
284
 
285
- var _dec$9, _dec2$9, _class$9;
286
- let BeanUserInner = (_dec$9 = Bean(), _dec2$9 = BeanInfo({
285
+ var _dec$8, _dec2$8, _class$8;
286
+ let BeanUserInner = (_dec$8 = Bean(), _dec2$8 = BeanInfo({
287
287
  module: "a-user"
288
- }), _dec$9(_class$9 = _dec2$9(_class$9 = class BeanUserInner extends BeanBase {
288
+ }), _dec$8(_class$8 = _dec2$8(_class$8 = class BeanUserInner extends BeanBase {
289
289
  constructor(...args) {
290
290
  super(...args);
291
291
  this._userInnerAdapter = void 0;
@@ -315,40 +315,22 @@ let BeanUserInner = (_dec$9 = Bean(), _dec2$9 = BeanInfo({
315
315
  remove(user) {
316
316
  return this.userInnerAdapter.remove(user);
317
317
  }
318
- }) || _class$9) || _class$9);
319
-
320
- var _dec$8, _dec2$8, _class$8;
321
- let EventCreateUserAnonymous = (_dec$8 = Event(), _dec2$8 = BeanInfo({
322
- module: "a-user"
323
- }), _dec$8(_class$8 = _dec2$8(_class$8 = class EventCreateUserAnonymous extends BeanEventBase {}) || _class$8) || _class$8);
318
+ }) || _class$8) || _class$8);
324
319
 
325
320
  var _dec$7, _dec2$7, _class$7;
326
- let EventSignin = (_dec$7 = Event(), _dec2$7 = BeanInfo({
321
+ let EventCreateUserAnonymous = (_dec$7 = Event(), _dec2$7 = BeanInfo({
327
322
  module: "a-user"
328
- }), _dec$7(_class$7 = _dec2$7(_class$7 = class EventSignin extends BeanEventBase {}) || _class$7) || _class$7);
323
+ }), _dec$7(_class$7 = _dec2$7(_class$7 = class EventCreateUserAnonymous extends BeanEventBase {}) || _class$7) || _class$7);
329
324
 
330
325
  var _dec$6, _dec2$6, _class$6;
331
- let EventSignout = (_dec$6 = Event(), _dec2$6 = BeanInfo({
326
+ let EventSignin = (_dec$6 = Event(), _dec2$6 = BeanInfo({
332
327
  module: "a-user"
333
- }), _dec$6(_class$6 = _dec2$6(_class$6 = class EventSignout extends BeanEventBase {}) || _class$6) || _class$6);
328
+ }), _dec$6(_class$6 = _dec2$6(_class$6 = class EventSignin extends BeanEventBase {}) || _class$6) || _class$6);
334
329
 
335
330
  var _dec$5, _dec2$5, _class$5;
336
- let GuardAdmin = (_dec$5 = Guard({
337
- admin: true,
338
- passWhenMatched: true
339
- }), _dec2$5 = BeanInfo({
331
+ let EventSignout = (_dec$5 = Event(), _dec2$5 = BeanInfo({
340
332
  module: "a-user"
341
- }), _dec$5(_class$5 = _dec2$5(_class$5 = class GuardAdmin extends BeanBase {
342
- async execute(options, next) {
343
- if (options.admin) {
344
- const isAdmin = await this.bean.passport.isAdmin();
345
- if (!isAdmin) return this.app.throw(403);
346
- if (options.passWhenMatched) return true;
347
- }
348
- // next
349
- return next();
350
- }
351
- }) || _class$5) || _class$5);
333
+ }), _dec$5(_class$5 = _dec2$5(_class$5 = class EventSignout extends BeanEventBase {}) || _class$5) || _class$5);
352
334
 
353
335
  var _dec$4, _dec2$4, _class$4;
354
336
  let GuardPassport = (_dec$4 = Guard({
@@ -484,20 +466,22 @@ function Public(options) {
484
466
  public: _public
485
467
  });
486
468
  }
487
- function Admin(options) {
488
- return Aspect.guard('a-user:admin', options);
489
- }
490
469
  function UserName(options) {
491
470
  return Aspect.guard('a-user:userName', options);
492
471
  }
493
472
  function RoleName(options) {
494
473
  return Aspect.guard('a-user:roleName', options);
495
474
  }
475
+ function Admin(options) {
476
+ return Aspect.guard('a-user:roleName', Object.assign({}, options, {
477
+ name: 'admin'
478
+ }));
479
+ }
496
480
  const Passport = {
497
- admin: Admin,
498
481
  public: Public,
499
482
  userName: UserName,
500
- roleName: RoleName
483
+ roleName: RoleName,
484
+ admin: Admin
501
485
  };
502
486
 
503
- export { $getAuthId, $getAuthIdSystem, $getRoleId, $getRoleName, $getUserAnonymous, $getUserAvatar, $getUserId, $getUserIdSystem, $getUserLocale, $getUserName, BeanAuthInner, BeanPassport, BeanRoleInner, BeanUserInner, EventCreateUserAnonymous, EventSignin, EventSignout, GuardAdmin, GuardPassport, GuardRoleName, GuardUserName, MetaPrintTip, Passport, ScopeModuleAUser, config, setAuthAdapter, setRoleAdapter, setUserAdapter };
487
+ export { $getAuthId, $getAuthIdSystem, $getRoleId, $getRoleName, $getUserAnonymous, $getUserAvatar, $getUserId, $getUserIdSystem, $getUserLocale, $getUserName, BeanAuthInner, BeanPassport, BeanRoleInner, BeanUserInner, EventCreateUserAnonymous, EventSignin, EventSignout, GuardPassport, GuardRoleName, GuardUserName, MetaPrintTip, Passport, ScopeModuleAUser, config, setAuthAdapter, setRoleAdapter, setUserAdapter };
@@ -1,17 +1,16 @@
1
1
  import type { TypeUseOnionOmitOptionsGlobal } from 'vona-module-a-onion';
2
- import type { IGuardOptionsAdmin } from '../bean/guard.admin.ts';
3
2
  import type { IGuardOptionsPassport } from '../bean/guard.passport.ts';
4
3
  import type { IGuardOptionsRoleName } from '../bean/guard.roleName.ts';
5
4
  import type { IGuardOptionsUserName } from '../bean/guard.userName.ts';
6
5
  declare function Public(options?: Partial<TypeUseOnionOmitOptionsGlobal<IGuardOptionsPassport>>): ClassDecorator & MethodDecorator;
7
- declare function Admin(options?: Partial<IGuardOptionsAdmin>): ClassDecorator & MethodDecorator;
8
6
  declare function UserName(options?: Partial<IGuardOptionsUserName>): ClassDecorator & MethodDecorator;
9
7
  declare function RoleName(options?: Partial<IGuardOptionsRoleName>): ClassDecorator & MethodDecorator;
8
+ declare function Admin(options?: Partial<Omit<IGuardOptionsRoleName, 'name'>>): ClassDecorator & MethodDecorator;
10
9
  export interface IDecoratorGroupPassport {
11
- admin: typeof Admin;
12
10
  public: typeof Public;
13
11
  userName: typeof UserName;
14
12
  roleName: typeof RoleName;
13
+ admin: typeof Admin;
15
14
  }
16
15
  export declare const Passport: IDecoratorGroupPassport;
17
16
  export {};
@@ -8,7 +8,7 @@ export interface IPassportBase {
8
8
  roles?: IRoleBase[];
9
9
  }
10
10
  export interface IPassportAdapter {
11
- isAdmin(user: IUserBase): Promise<boolean>;
11
+ isAdmin(passport: IPassportBase | undefined): Promise<boolean>;
12
12
  setCurrent(passport: IPassportBase | undefined): Promise<IPassportBase | undefined>;
13
13
  serialize(passport: IPassportBase): Promise<IPayloadDataBase>;
14
14
  deserialize(payloadData: IPayloadDataBase): Promise<IPassportBase | undefined>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vona-module-a-user",
3
3
  "type": "module",
4
- "version": "5.0.14",
4
+ "version": "5.0.15",
5
5
  "title": "a-user",
6
6
  "vonaModule": {
7
7
  "dependencies": {}
@@ -1,10 +0,0 @@
1
- import type { Next } from 'vona';
2
- import type { IDecoratorGuardOptions, IGuardExecute } from 'vona-module-a-aspect';
3
- import { BeanBase } from 'vona';
4
- export interface IGuardOptionsAdmin extends IDecoratorGuardOptions {
5
- admin: boolean;
6
- passWhenMatched: boolean;
7
- }
8
- export declare class GuardAdmin extends BeanBase implements IGuardExecute {
9
- execute(options: IGuardOptionsAdmin, next: Next): Promise<boolean>;
10
- }