vona-module-a-user 5.0.14 → 5.0.16
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/.metadata/index.d.ts +48 -54
- package/dist/index.js +139 -155
- package/dist/lib/passport.d.ts +2 -3
- package/dist/types/passport.d.ts +1 -1
- package/package.json +1 -1
- package/dist/bean/guard.admin.d.ts +0 -10
|
@@ -1,54 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import type { BeanAuthInner } from '../bean/bean.authInner.ts';
|
|
6
|
-
import type { BeanPassport } from '../bean/bean.passport.ts';
|
|
7
|
-
import type { BeanRoleInner } from '../bean/bean.roleInner.ts';
|
|
8
|
-
import type { BeanUserInner } from '../bean/bean.userInner.ts';
|
|
9
|
-
/** event: end */
|
|
10
|
-
/** event: begin */
|
|
11
|
-
import type { EventCreateUserAnonymous } from '../bean/event.createUserAnonymous.ts';
|
|
12
|
-
/** event: end */
|
|
13
|
-
/** event: begin */
|
|
14
|
-
import type { TypeEventCreateUserAnonymousData, TypeEventCreateUserAnonymousResult } from '../bean/event.createUserAnonymous.ts';
|
|
15
|
-
import type { EventSignin } from '../bean/event.signin.ts';
|
|
16
|
-
import type { TypeEventSigninData, TypeEventSigninResult } from '../bean/event.signin.ts';
|
|
17
|
-
import type { EventSignout } from '../bean/event.signout.ts';
|
|
18
|
-
import type { TypeEventSignoutData, TypeEventSignoutResult } from '../bean/event.signout.ts';
|
|
19
|
-
/** guard: end */
|
|
20
|
-
/** bean: begin */
|
|
21
|
-
import type { IGuardOptionsAdmin } from '../bean/guard.admin.ts';
|
|
1
|
+
/** guard: begin */
|
|
2
|
+
export * from '../bean/guard.passport.ts';
|
|
3
|
+
export * from '../bean/guard.roleName.ts';
|
|
4
|
+
export * from '../bean/guard.userName.ts';
|
|
22
5
|
import type { IGuardOptionsPassport } from '../bean/guard.passport.ts';
|
|
23
6
|
import type { IGuardOptionsRoleName } from '../bean/guard.roleName.ts';
|
|
24
7
|
import type { IGuardOptionsUserName } from '../bean/guard.userName.ts';
|
|
25
|
-
import type { config } from '../config/config.ts';
|
|
26
|
-
/** config: end */
|
|
27
|
-
/** scope: begin */
|
|
28
|
-
import { BeanScopeBase } from 'vona';
|
|
29
|
-
import 'vona';
|
|
30
|
-
import 'vona';
|
|
31
|
-
import 'vona';
|
|
32
|
-
import 'vona';
|
|
33
|
-
import 'vona';
|
|
34
8
|
import 'vona';
|
|
35
|
-
export * from '../bean/bean.authInner.ts';
|
|
36
|
-
export * from '../bean/bean.passport.ts';
|
|
37
|
-
export * from '../bean/bean.roleInner.ts';
|
|
38
|
-
export * from '../bean/bean.userInner.ts';
|
|
39
9
|
declare module 'vona-module-a-aspect' {
|
|
40
10
|
interface IGuardRecordGlobal {
|
|
41
11
|
'a-user:passport': IGuardOptionsPassport;
|
|
42
12
|
}
|
|
43
13
|
interface IGuardRecordLocal {
|
|
44
|
-
'a-user:admin': IGuardOptionsAdmin;
|
|
45
14
|
'a-user:roleName': IGuardOptionsRoleName;
|
|
46
15
|
'a-user:userName': IGuardOptionsUserName;
|
|
47
16
|
}
|
|
48
17
|
}
|
|
49
18
|
declare module 'vona-module-a-user' {
|
|
50
|
-
interface GuardAdmin {
|
|
51
|
-
}
|
|
52
19
|
interface GuardPassport {
|
|
53
20
|
}
|
|
54
21
|
interface GuardRoleName {
|
|
@@ -56,13 +23,13 @@ declare module 'vona-module-a-user' {
|
|
|
56
23
|
interface GuardUserName {
|
|
57
24
|
}
|
|
58
25
|
}
|
|
59
|
-
/**
|
|
60
|
-
/**
|
|
61
|
-
export * from '../bean/
|
|
62
|
-
export * from '../bean/
|
|
63
|
-
export * from '../bean/
|
|
64
|
-
|
|
65
|
-
|
|
26
|
+
/** guard: end */
|
|
27
|
+
/** bean: begin */
|
|
28
|
+
export * from '../bean/bean.authInner.ts';
|
|
29
|
+
export * from '../bean/bean.passport.ts';
|
|
30
|
+
export * from '../bean/bean.roleInner.ts';
|
|
31
|
+
export * from '../bean/bean.userInner.ts';
|
|
32
|
+
import 'vona';
|
|
66
33
|
declare module 'vona' {
|
|
67
34
|
}
|
|
68
35
|
declare module 'vona-module-a-user' {
|
|
@@ -75,17 +42,27 @@ declare module 'vona-module-a-user' {
|
|
|
75
42
|
interface BeanUserInner {
|
|
76
43
|
}
|
|
77
44
|
}
|
|
45
|
+
/** bean: end */
|
|
46
|
+
/** bean: begin */
|
|
47
|
+
import type { BeanAuthInner } from '../bean/bean.authInner.ts';
|
|
48
|
+
import type { BeanPassport } from '../bean/bean.passport.ts';
|
|
49
|
+
import type { BeanRoleInner } from '../bean/bean.roleInner.ts';
|
|
50
|
+
import type { BeanUserInner } from '../bean/bean.userInner.ts';
|
|
51
|
+
import 'vona';
|
|
78
52
|
declare module 'vona' {
|
|
79
53
|
interface IBeanRecordGlobal {
|
|
80
|
-
authInner: BeanAuthInner;
|
|
81
|
-
passport: BeanPassport;
|
|
82
|
-
roleInner: BeanRoleInner;
|
|
83
|
-
userInner: BeanUserInner;
|
|
54
|
+
'authInner': BeanAuthInner;
|
|
55
|
+
'passport': BeanPassport;
|
|
56
|
+
'roleInner': BeanRoleInner;
|
|
57
|
+
'userInner': BeanUserInner;
|
|
84
58
|
}
|
|
85
59
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
export * from '../bean/
|
|
60
|
+
/** bean: end */
|
|
61
|
+
/** event: begin */
|
|
62
|
+
export * from '../bean/event.createUserAnonymous.ts';
|
|
63
|
+
export * from '../bean/event.signin.ts';
|
|
64
|
+
export * from '../bean/event.signout.ts';
|
|
65
|
+
import 'vona';
|
|
89
66
|
declare module 'vona' {
|
|
90
67
|
}
|
|
91
68
|
declare module 'vona-module-a-user' {
|
|
@@ -96,11 +73,22 @@ declare module 'vona-module-a-user' {
|
|
|
96
73
|
interface EventSignout {
|
|
97
74
|
}
|
|
98
75
|
}
|
|
76
|
+
/** event: end */
|
|
77
|
+
/** event: begin */
|
|
78
|
+
import type { EventCreateUserAnonymous } from '../bean/event.createUserAnonymous.ts';
|
|
79
|
+
import type { EventSignin } from '../bean/event.signin.ts';
|
|
80
|
+
import type { EventSignout } from '../bean/event.signout.ts';
|
|
99
81
|
export interface IModuleEvent {
|
|
100
|
-
createUserAnonymous: EventCreateUserAnonymous;
|
|
101
|
-
signin: EventSignin;
|
|
102
|
-
signout: EventSignout;
|
|
82
|
+
'createUserAnonymous': EventCreateUserAnonymous;
|
|
83
|
+
'signin': EventSignin;
|
|
84
|
+
'signout': EventSignout;
|
|
103
85
|
}
|
|
86
|
+
/** event: end */
|
|
87
|
+
/** event: begin */
|
|
88
|
+
import type { TypeEventCreateUserAnonymousData, TypeEventCreateUserAnonymousResult } from '../bean/event.createUserAnonymous.ts';
|
|
89
|
+
import type { TypeEventSigninData, TypeEventSigninResult } from '../bean/event.signin.ts';
|
|
90
|
+
import type { TypeEventSignoutData, TypeEventSignoutResult } from '../bean/event.signout.ts';
|
|
91
|
+
import type { EventOn } from 'vona-module-a-event';
|
|
104
92
|
declare module 'vona-module-a-event' {
|
|
105
93
|
interface IEventRecord {
|
|
106
94
|
'a-user:createUserAnonymous': EventOn<TypeEventCreateUserAnonymousData, TypeEventCreateUserAnonymousResult>;
|
|
@@ -111,6 +99,7 @@ declare module 'vona-module-a-event' {
|
|
|
111
99
|
/** event: end */
|
|
112
100
|
/** meta: begin */
|
|
113
101
|
export * from '../bean/meta.printTip.ts';
|
|
102
|
+
import 'vona';
|
|
114
103
|
declare module 'vona' {
|
|
115
104
|
interface IMetaRecord {
|
|
116
105
|
'a-user:printTip': never;
|
|
@@ -123,6 +112,10 @@ declare module 'vona-module-a-user' {
|
|
|
123
112
|
/** meta: end */
|
|
124
113
|
/** config: begin */
|
|
125
114
|
export * from '../config/config.ts';
|
|
115
|
+
import type { config } from '../config/config.ts';
|
|
116
|
+
/** config: end */
|
|
117
|
+
/** scope: begin */
|
|
118
|
+
import { BeanScopeBase, type BeanScopeUtil, type TypeModuleConfig } from 'vona';
|
|
126
119
|
export declare class ScopeModuleAUser extends BeanScopeBase {
|
|
127
120
|
}
|
|
128
121
|
export interface ScopeModuleAUser {
|
|
@@ -130,6 +123,7 @@ export interface ScopeModuleAUser {
|
|
|
130
123
|
config: TypeModuleConfig<typeof config>;
|
|
131
124
|
event: IModuleEvent;
|
|
132
125
|
}
|
|
126
|
+
import 'vona';
|
|
133
127
|
declare module 'vona' {
|
|
134
128
|
interface IBeanScopeRecord {
|
|
135
129
|
'a-user': ScopeModuleAUser;
|
package/dist/index.js
CHANGED
|
@@ -1,40 +1,54 @@
|
|
|
1
1
|
import { BeanInfo, BeanBase, beanFullNameFromOnionName, BeanScopeBase } from 'vona';
|
|
2
|
-
import { Bean, Scope } from 'vona-module-a-bean';
|
|
3
2
|
import { catchError } from '@cabloy/utils';
|
|
4
|
-
import { Event, BeanEventBase } from 'vona-module-a-event';
|
|
5
3
|
import { Guard, Aspect } from 'vona-module-a-aspect';
|
|
4
|
+
import { Bean, Scope } from 'vona-module-a-bean';
|
|
5
|
+
import { Event, BeanEventBase } from 'vona-module-a-event';
|
|
6
6
|
import { Meta } from 'vona-module-a-meta';
|
|
7
7
|
|
|
8
|
-
var _dec$
|
|
9
|
-
let
|
|
8
|
+
var _dec$b, _dec2$b, _class$b;
|
|
9
|
+
let GuardPassport = (_dec$b = Guard({
|
|
10
|
+
global: true,
|
|
11
|
+
public: false,
|
|
12
|
+
checkAuthToken: true
|
|
13
|
+
}), _dec2$b = BeanInfo({
|
|
10
14
|
module: "a-user"
|
|
11
|
-
}), _dec$
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
this.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
}), _dec$b(_class$b = _dec2$b(_class$b = class GuardPassport extends BeanBase {
|
|
16
|
+
async execute(options, next) {
|
|
17
|
+
// auth token
|
|
18
|
+
if (!this.bean.passport.getCurrent()) {
|
|
19
|
+
if (options.checkAuthToken) {
|
|
20
|
+
// will return undefined if no accessToken, so not check options.public
|
|
21
|
+
const [_, err] = await catchError(() => {
|
|
22
|
+
return this.bean.passport.checkAuthToken();
|
|
23
|
+
});
|
|
24
|
+
if (err && !options.public) throw err;
|
|
25
|
+
}
|
|
20
26
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
// check current
|
|
28
|
+
if (!this.bean.passport.getCurrent()) {
|
|
29
|
+
await this.bean.passport.signinWithAnonymous();
|
|
30
|
+
}
|
|
31
|
+
if (!options.public && !this.bean.passport.isAuthenticated) {
|
|
32
|
+
// return false;
|
|
33
|
+
// 401 for this guard,403 for the next guards
|
|
34
|
+
return this.app.throw(401);
|
|
35
|
+
}
|
|
36
|
+
// check innerAccess
|
|
37
|
+
if (this.ctx.innerAccess) return true;
|
|
38
|
+
// next
|
|
39
|
+
return next();
|
|
26
40
|
}
|
|
27
|
-
}) || _class$
|
|
41
|
+
}) || _class$b) || _class$b);
|
|
28
42
|
|
|
29
|
-
let
|
|
30
|
-
function
|
|
31
|
-
|
|
43
|
+
let __roleAdapter;
|
|
44
|
+
function setRoleAdapter(roleAdapter) {
|
|
45
|
+
__roleAdapter = roleAdapter;
|
|
32
46
|
}
|
|
33
|
-
function $
|
|
34
|
-
return
|
|
47
|
+
function $getRoleId(role) {
|
|
48
|
+
return __roleAdapter.getRoleId(role);
|
|
35
49
|
}
|
|
36
|
-
function $
|
|
37
|
-
return
|
|
50
|
+
function $getRoleName(role) {
|
|
51
|
+
return __roleAdapter.getRoleName(role);
|
|
38
52
|
}
|
|
39
53
|
|
|
40
54
|
let __userAdapter;
|
|
@@ -60,10 +74,82 @@ function $getUserIdSystem(_userName, userId) {
|
|
|
60
74
|
return userId;
|
|
61
75
|
}
|
|
62
76
|
|
|
63
|
-
var _dec$
|
|
64
|
-
let
|
|
77
|
+
var _dec$a, _dec2$a, _class$a;
|
|
78
|
+
let GuardRoleName = (_dec$a = Guard({
|
|
79
|
+
passWhenMatched: true
|
|
80
|
+
}), _dec2$a = BeanInfo({
|
|
81
|
+
module: "a-user"
|
|
82
|
+
}), _dec$a(_class$a = _dec2$a(_class$a = class GuardRoleName extends BeanBase {
|
|
83
|
+
async execute(options, next) {
|
|
84
|
+
if (!options.name) return this.app.throw(403);
|
|
85
|
+
const user = this.bean.passport.getCurrentUser();
|
|
86
|
+
if (!user || $getUserAnonymous(user)) return this.app.throw(403);
|
|
87
|
+
const roles = this.bean.passport.getCurrentRoles();
|
|
88
|
+
if (!roles) return this.app.throw(403);
|
|
89
|
+
const roleNames = roles?.map(item => $getRoleName(item));
|
|
90
|
+
const optionsName = Array.isArray(options.name) ? options.name : [options.name];
|
|
91
|
+
if (!roleNames.some(roleName => optionsName.includes(roleName))) return this.app.throw(403);
|
|
92
|
+
if (options.passWhenMatched) return true;
|
|
93
|
+
// next
|
|
94
|
+
return next();
|
|
95
|
+
}
|
|
96
|
+
}) || _class$a) || _class$a);
|
|
97
|
+
|
|
98
|
+
var _dec$9, _dec2$9, _class$9;
|
|
99
|
+
let GuardUserName = (_dec$9 = Guard({
|
|
100
|
+
passWhenMatched: true
|
|
101
|
+
}), _dec2$9 = BeanInfo({
|
|
102
|
+
module: "a-user"
|
|
103
|
+
}), _dec$9(_class$9 = _dec2$9(_class$9 = class GuardUserName extends BeanBase {
|
|
104
|
+
async execute(options, next) {
|
|
105
|
+
if (!options.name) return this.app.throw(403);
|
|
106
|
+
const user = this.bean.passport.getCurrentUser();
|
|
107
|
+
if (!user || $getUserAnonymous(user)) return this.app.throw(403);
|
|
108
|
+
const userName = $getUserName(user);
|
|
109
|
+
const optionsName = Array.isArray(options.name) ? options.name : [options.name];
|
|
110
|
+
if (!optionsName.includes(userName)) return this.app.throw(403);
|
|
111
|
+
if (options.passWhenMatched) return true;
|
|
112
|
+
// next
|
|
113
|
+
return next();
|
|
114
|
+
}
|
|
115
|
+
}) || _class$9) || _class$9);
|
|
116
|
+
|
|
117
|
+
var _dec$8, _dec2$8, _class$8;
|
|
118
|
+
let BeanAuthInner = (_dec$8 = Bean(), _dec2$8 = BeanInfo({
|
|
119
|
+
module: "a-user"
|
|
120
|
+
}), _dec$8(_class$8 = _dec2$8(_class$8 = class BeanAuthInner extends BeanBase {
|
|
121
|
+
constructor(...args) {
|
|
122
|
+
super(...args);
|
|
123
|
+
this._authInnerAdapter = void 0;
|
|
124
|
+
}
|
|
125
|
+
get authInnerAdapter() {
|
|
126
|
+
if (!this._authInnerAdapter) {
|
|
127
|
+
const beanFullName = beanFullNameFromOnionName(this.scope.config.adapter.authInner, 'service');
|
|
128
|
+
this._authInnerAdapter = this.bean._getBean(beanFullName);
|
|
129
|
+
}
|
|
130
|
+
return this._authInnerAdapter;
|
|
131
|
+
}
|
|
132
|
+
async findOne(auth) {
|
|
133
|
+
if (String(auth.id).charAt(0) === '-') return auth;
|
|
134
|
+
return await this.authInnerAdapter.findOne(auth);
|
|
135
|
+
}
|
|
136
|
+
}) || _class$8) || _class$8);
|
|
137
|
+
|
|
138
|
+
let __authAdapter;
|
|
139
|
+
function setAuthAdapter(authAdapter) {
|
|
140
|
+
__authAdapter = authAdapter;
|
|
141
|
+
}
|
|
142
|
+
function $getAuthId(user) {
|
|
143
|
+
return __authAdapter.getAuthId(user);
|
|
144
|
+
}
|
|
145
|
+
function $getAuthIdSystem(_authName, authId) {
|
|
146
|
+
return authId;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
var _dec$7, _dec2$7, _class$7;
|
|
150
|
+
let BeanPassport = (_dec$7 = Bean(), _dec2$7 = BeanInfo({
|
|
65
151
|
module: "a-user"
|
|
66
|
-
}), _dec$
|
|
152
|
+
}), _dec$7(_class$7 = _dec2$7(_class$7 = class BeanPassport extends BeanBase {
|
|
67
153
|
constructor(...args) {
|
|
68
154
|
super(...args);
|
|
69
155
|
this._authTokenAdapter = void 0;
|
|
@@ -89,8 +175,8 @@ let BeanPassport = (_dec$b = Bean(), _dec2$b = BeanInfo({
|
|
|
89
175
|
return !!user && !$getUserAnonymous(user);
|
|
90
176
|
}
|
|
91
177
|
async isAdmin() {
|
|
92
|
-
const
|
|
93
|
-
return
|
|
178
|
+
const passport = this.getCurrent();
|
|
179
|
+
return await this.passportAdapter.isAdmin(passport);
|
|
94
180
|
}
|
|
95
181
|
async setCurrent(passport) {
|
|
96
182
|
this.ctx.state.passport = await this.passportAdapter.setCurrent(passport);
|
|
@@ -254,12 +340,12 @@ let BeanPassport = (_dec$b = Bean(), _dec2$b = BeanInfo({
|
|
|
254
340
|
return payloadData2;
|
|
255
341
|
}
|
|
256
342
|
}
|
|
257
|
-
}) || _class$
|
|
343
|
+
}) || _class$7) || _class$7);
|
|
258
344
|
|
|
259
|
-
var _dec$
|
|
260
|
-
let BeanRoleInner = (_dec$
|
|
345
|
+
var _dec$6, _dec2$6, _class$6;
|
|
346
|
+
let BeanRoleInner = (_dec$6 = Bean(), _dec2$6 = BeanInfo({
|
|
261
347
|
module: "a-user"
|
|
262
|
-
}), _dec$
|
|
348
|
+
}), _dec$6(_class$6 = _dec2$6(_class$6 = class BeanRoleInner extends BeanBase {
|
|
263
349
|
constructor(...args) {
|
|
264
350
|
super(...args);
|
|
265
351
|
this._roleInnerAdapter = void 0;
|
|
@@ -280,12 +366,12 @@ let BeanRoleInner = (_dec$a = Bean(), _dec2$a = BeanInfo({
|
|
|
280
366
|
findAllByUserId(userId) {
|
|
281
367
|
return this.roleInnerAdapter.findAllByUserId(userId);
|
|
282
368
|
}
|
|
283
|
-
}) || _class$
|
|
369
|
+
}) || _class$6) || _class$6);
|
|
284
370
|
|
|
285
|
-
var _dec$
|
|
286
|
-
let BeanUserInner = (_dec$
|
|
371
|
+
var _dec$5, _dec2$5, _class$5;
|
|
372
|
+
let BeanUserInner = (_dec$5 = Bean(), _dec2$5 = BeanInfo({
|
|
287
373
|
module: "a-user"
|
|
288
|
-
}), _dec$
|
|
374
|
+
}), _dec$5(_class$5 = _dec2$5(_class$5 = class BeanUserInner extends BeanBase {
|
|
289
375
|
constructor(...args) {
|
|
290
376
|
super(...args);
|
|
291
377
|
this._userInnerAdapter = void 0;
|
|
@@ -315,126 +401,22 @@ let BeanUserInner = (_dec$9 = Bean(), _dec2$9 = BeanInfo({
|
|
|
315
401
|
remove(user) {
|
|
316
402
|
return this.userInnerAdapter.remove(user);
|
|
317
403
|
}
|
|
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);
|
|
324
|
-
|
|
325
|
-
var _dec$7, _dec2$7, _class$7;
|
|
326
|
-
let EventSignin = (_dec$7 = Event(), _dec2$7 = BeanInfo({
|
|
327
|
-
module: "a-user"
|
|
328
|
-
}), _dec$7(_class$7 = _dec2$7(_class$7 = class EventSignin extends BeanEventBase {}) || _class$7) || _class$7);
|
|
329
|
-
|
|
330
|
-
var _dec$6, _dec2$6, _class$6;
|
|
331
|
-
let EventSignout = (_dec$6 = Event(), _dec2$6 = BeanInfo({
|
|
332
|
-
module: "a-user"
|
|
333
|
-
}), _dec$6(_class$6 = _dec2$6(_class$6 = class EventSignout extends BeanEventBase {}) || _class$6) || _class$6);
|
|
334
|
-
|
|
335
|
-
var _dec$5, _dec2$5, _class$5;
|
|
336
|
-
let GuardAdmin = (_dec$5 = Guard({
|
|
337
|
-
admin: true,
|
|
338
|
-
passWhenMatched: true
|
|
339
|
-
}), _dec2$5 = BeanInfo({
|
|
340
|
-
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
404
|
}) || _class$5) || _class$5);
|
|
352
405
|
|
|
353
406
|
var _dec$4, _dec2$4, _class$4;
|
|
354
|
-
let
|
|
355
|
-
global: true,
|
|
356
|
-
public: false,
|
|
357
|
-
checkAuthToken: true
|
|
358
|
-
}), _dec2$4 = BeanInfo({
|
|
407
|
+
let EventCreateUserAnonymous = (_dec$4 = Event(), _dec2$4 = BeanInfo({
|
|
359
408
|
module: "a-user"
|
|
360
|
-
}), _dec$4(_class$4 = _dec2$4(_class$4 = class
|
|
361
|
-
async execute(options, next) {
|
|
362
|
-
// auth token
|
|
363
|
-
if (!this.bean.passport.getCurrent()) {
|
|
364
|
-
if (options.checkAuthToken) {
|
|
365
|
-
// will return undefined if no accessToken, so not check options.public
|
|
366
|
-
const [_, err] = await catchError(() => {
|
|
367
|
-
return this.bean.passport.checkAuthToken();
|
|
368
|
-
});
|
|
369
|
-
if (err && !options.public) throw err;
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
// check current
|
|
373
|
-
if (!this.bean.passport.getCurrent()) {
|
|
374
|
-
await this.bean.passport.signinWithAnonymous();
|
|
375
|
-
}
|
|
376
|
-
if (!options.public && !this.bean.passport.isAuthenticated) {
|
|
377
|
-
// return false;
|
|
378
|
-
// 401 for this guard,403 for the next guards
|
|
379
|
-
return this.app.throw(401);
|
|
380
|
-
}
|
|
381
|
-
// check innerAccess
|
|
382
|
-
if (this.ctx.innerAccess) return true;
|
|
383
|
-
// next
|
|
384
|
-
return next();
|
|
385
|
-
}
|
|
386
|
-
}) || _class$4) || _class$4);
|
|
387
|
-
|
|
388
|
-
let __roleAdapter;
|
|
389
|
-
function setRoleAdapter(roleAdapter) {
|
|
390
|
-
__roleAdapter = roleAdapter;
|
|
391
|
-
}
|
|
392
|
-
function $getRoleId(role) {
|
|
393
|
-
return __roleAdapter.getRoleId(role);
|
|
394
|
-
}
|
|
395
|
-
function $getRoleName(role) {
|
|
396
|
-
return __roleAdapter.getRoleName(role);
|
|
397
|
-
}
|
|
409
|
+
}), _dec$4(_class$4 = _dec2$4(_class$4 = class EventCreateUserAnonymous extends BeanEventBase {}) || _class$4) || _class$4);
|
|
398
410
|
|
|
399
411
|
var _dec$3, _dec2$3, _class$3;
|
|
400
|
-
let
|
|
401
|
-
passWhenMatched: true
|
|
402
|
-
}), _dec2$3 = BeanInfo({
|
|
412
|
+
let EventSignin = (_dec$3 = Event(), _dec2$3 = BeanInfo({
|
|
403
413
|
module: "a-user"
|
|
404
|
-
}), _dec$3(_class$3 = _dec2$3(_class$3 = class
|
|
405
|
-
async execute(options, next) {
|
|
406
|
-
if (!options.name) return this.app.throw(403);
|
|
407
|
-
const user = this.bean.passport.getCurrentUser();
|
|
408
|
-
if (!user || $getUserAnonymous(user)) return this.app.throw(403);
|
|
409
|
-
const roles = this.bean.passport.getCurrentRoles();
|
|
410
|
-
if (!roles) return this.app.throw(403);
|
|
411
|
-
const roleNames = roles?.map(item => $getRoleName(item));
|
|
412
|
-
const optionsName = Array.isArray(options.name) ? options.name : [options.name];
|
|
413
|
-
if (!roleNames.some(roleName => optionsName.includes(roleName))) return this.app.throw(403);
|
|
414
|
-
if (options.passWhenMatched) return true;
|
|
415
|
-
// next
|
|
416
|
-
return next();
|
|
417
|
-
}
|
|
418
|
-
}) || _class$3) || _class$3);
|
|
414
|
+
}), _dec$3(_class$3 = _dec2$3(_class$3 = class EventSignin extends BeanEventBase {}) || _class$3) || _class$3);
|
|
419
415
|
|
|
420
416
|
var _dec$2, _dec2$2, _class$2;
|
|
421
|
-
let
|
|
422
|
-
passWhenMatched: true
|
|
423
|
-
}), _dec2$2 = BeanInfo({
|
|
417
|
+
let EventSignout = (_dec$2 = Event(), _dec2$2 = BeanInfo({
|
|
424
418
|
module: "a-user"
|
|
425
|
-
}), _dec$2(_class$2 = _dec2$2(_class$2 = class
|
|
426
|
-
async execute(options, next) {
|
|
427
|
-
if (!options.name) return this.app.throw(403);
|
|
428
|
-
const user = this.bean.passport.getCurrentUser();
|
|
429
|
-
if (!user || $getUserAnonymous(user)) return this.app.throw(403);
|
|
430
|
-
const userName = $getUserName(user);
|
|
431
|
-
const optionsName = Array.isArray(options.name) ? options.name : [options.name];
|
|
432
|
-
if (!optionsName.includes(userName)) return this.app.throw(403);
|
|
433
|
-
if (options.passWhenMatched) return true;
|
|
434
|
-
// next
|
|
435
|
-
return next();
|
|
436
|
-
}
|
|
437
|
-
}) || _class$2) || _class$2);
|
|
419
|
+
}), _dec$2(_class$2 = _dec2$2(_class$2 = class EventSignout extends BeanEventBase {}) || _class$2) || _class$2);
|
|
438
420
|
|
|
439
421
|
var _dec$1, _dec2$1, _class$1;
|
|
440
422
|
let MetaPrintTip = (_dec$1 = Meta(), _dec2$1 = BeanInfo({
|
|
@@ -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,
|
|
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 };
|
package/dist/lib/passport.d.ts
CHANGED
|
@@ -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 {};
|
package/dist/types/passport.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export interface IPassportBase {
|
|
|
8
8
|
roles?: IRoleBase[];
|
|
9
9
|
}
|
|
10
10
|
export interface IPassportAdapter {
|
|
11
|
-
isAdmin(
|
|
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,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
|
-
}
|