vona-module-a-user 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.
- package/dist/.metadata/index.d.ts +11 -6
- package/dist/bean/bean.authInner.d.ts +1 -1
- package/dist/bean/bean.passport.d.ts +2 -0
- package/dist/bean/bean.roleInner.d.ts +10 -0
- package/dist/bean/bean.userInner.d.ts +3 -3
- package/dist/bean/guard.roleName.d.ts +11 -0
- package/dist/config/config.d.ts +1 -0
- package/dist/index.js +96 -46
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/passport.d.ts +5 -3
- package/dist/lib/role.d.ts +5 -0
- package/dist/types/auth.d.ts +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/passport.d.ts +3 -1
- package/dist/types/role.d.ts +18 -0
- package/dist/types/user.d.ts +3 -3
- package/package.json +1 -1
- package/dist/bean/guard.admin.d.ts +0 -10
|
@@ -4,6 +4,7 @@ import type { EventOn } from 'vona-module-a-event';
|
|
|
4
4
|
/** bean: begin */
|
|
5
5
|
import type { BeanAuthInner } from '../bean/bean.authInner.ts';
|
|
6
6
|
import type { BeanPassport } from '../bean/bean.passport.ts';
|
|
7
|
+
import type { BeanRoleInner } from '../bean/bean.roleInner.ts';
|
|
7
8
|
import type { BeanUserInner } from '../bean/bean.userInner.ts';
|
|
8
9
|
/** event: end */
|
|
9
10
|
/** event: begin */
|
|
@@ -17,8 +18,8 @@ import type { EventSignout } from '../bean/event.signout.ts';
|
|
|
17
18
|
import type { TypeEventSignoutData, TypeEventSignoutResult } from '../bean/event.signout.ts';
|
|
18
19
|
/** guard: end */
|
|
19
20
|
/** bean: begin */
|
|
20
|
-
import type { IGuardOptionsAdmin } from '../bean/guard.admin.ts';
|
|
21
21
|
import type { IGuardOptionsPassport } from '../bean/guard.passport.ts';
|
|
22
|
+
import type { IGuardOptionsRoleName } from '../bean/guard.roleName.ts';
|
|
22
23
|
import type { IGuardOptionsUserName } from '../bean/guard.userName.ts';
|
|
23
24
|
import type { config } from '../config/config.ts';
|
|
24
25
|
/** config: end */
|
|
@@ -32,24 +33,25 @@ import 'vona';
|
|
|
32
33
|
import 'vona';
|
|
33
34
|
export * from '../bean/bean.authInner.ts';
|
|
34
35
|
export * from '../bean/bean.passport.ts';
|
|
35
|
-
export * from '../bean/bean.
|
|
36
|
+
export * from '../bean/bean.roleInner.ts';
|
|
36
37
|
declare module 'vona-module-a-aspect' {
|
|
37
38
|
interface IGuardRecordGlobal {
|
|
38
39
|
'a-user:passport': IGuardOptionsPassport;
|
|
39
40
|
}
|
|
40
41
|
interface IGuardRecordLocal {
|
|
41
|
-
'a-user:
|
|
42
|
+
'a-user:roleName': IGuardOptionsRoleName;
|
|
42
43
|
'a-user:userName': IGuardOptionsUserName;
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
46
|
declare module 'vona-module-a-user' {
|
|
46
|
-
interface GuardAdmin {
|
|
47
|
-
}
|
|
48
47
|
interface GuardPassport {
|
|
49
48
|
}
|
|
49
|
+
interface GuardRoleName {
|
|
50
|
+
}
|
|
50
51
|
interface GuardUserName {
|
|
51
52
|
}
|
|
52
53
|
}
|
|
54
|
+
export * from '../bean/bean.userInner.ts';
|
|
53
55
|
/** bean: end */
|
|
54
56
|
/** event: begin */
|
|
55
57
|
export * from '../bean/event.createUserAnonymous.ts';
|
|
@@ -62,6 +64,8 @@ declare module 'vona-module-a-user' {
|
|
|
62
64
|
}
|
|
63
65
|
interface BeanPassport {
|
|
64
66
|
}
|
|
67
|
+
interface BeanRoleInner {
|
|
68
|
+
}
|
|
65
69
|
interface BeanUserInner {
|
|
66
70
|
}
|
|
67
71
|
}
|
|
@@ -69,12 +73,13 @@ declare module 'vona' {
|
|
|
69
73
|
interface IBeanRecordGlobal {
|
|
70
74
|
authInner: BeanAuthInner;
|
|
71
75
|
passport: BeanPassport;
|
|
76
|
+
roleInner: BeanRoleInner;
|
|
72
77
|
userInner: BeanUserInner;
|
|
73
78
|
}
|
|
74
79
|
}
|
|
75
80
|
/** guard: begin */
|
|
76
|
-
export * from '../bean/guard.admin.ts';
|
|
77
81
|
export * from '../bean/guard.passport.ts';
|
|
82
|
+
export * from '../bean/guard.roleName.ts';
|
|
78
83
|
export * from '../bean/guard.userName.ts';
|
|
79
84
|
declare module 'vona' {
|
|
80
85
|
}
|
|
@@ -3,5 +3,5 @@ import { BeanBase } from 'vona';
|
|
|
3
3
|
export declare class BeanAuthInner extends BeanBase {
|
|
4
4
|
private _authInnerAdapter;
|
|
5
5
|
private get authInnerAdapter();
|
|
6
|
-
|
|
6
|
+
findOne(auth: Partial<IAuthBase>): Promise<IAuthBase | undefined>;
|
|
7
7
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { IJwtClientRecord, IJwtSignOptions, IJwtToken, IPayloadDataBase } from 'vona-module-a-jwt';
|
|
2
2
|
import type { IAuthBase, IAuthIdRecord, ISigninOptions } from '../types/auth.ts';
|
|
3
3
|
import type { IPassportBase } from '../types/passport.ts';
|
|
4
|
+
import type { IRoleBase } from '../types/role.ts';
|
|
4
5
|
import type { IUserBase, IUserNameRecord } from '../types/user.ts';
|
|
5
6
|
import { BeanBase } from 'vona';
|
|
6
7
|
export declare class BeanPassport extends BeanBase {
|
|
@@ -15,6 +16,7 @@ export declare class BeanPassport extends BeanBase {
|
|
|
15
16
|
getCurrent(): IPassportBase | undefined;
|
|
16
17
|
getCurrentUser(): IUserBase | undefined;
|
|
17
18
|
getCurrentAuth(): IAuthBase | undefined;
|
|
19
|
+
getCurrentRoles(): IRoleBase[] | undefined;
|
|
18
20
|
signin(passport: IPassportBase, options?: ISigninOptions): Promise<IJwtToken>;
|
|
19
21
|
signout(): Promise<void>;
|
|
20
22
|
signinSystem<K extends keyof IAuthIdRecord>(authName: IAuthIdRecord[K], authId: K, name?: string, options?: ISigninOptions): Promise<IJwtToken>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { TableIdentity } from 'vona-module-a-database';
|
|
2
|
+
import type { IRoleBase } from '../types/role.ts';
|
|
3
|
+
import { BeanBase } from 'vona';
|
|
4
|
+
export declare class BeanRoleInner extends BeanBase {
|
|
5
|
+
private _roleInnerAdapter;
|
|
6
|
+
private get roleInnerAdapter();
|
|
7
|
+
findOneByName(name: string): Promise<IRoleBase | undefined>;
|
|
8
|
+
findOne(role: Partial<IRoleBase>): Promise<IRoleBase | undefined>;
|
|
9
|
+
findAllByUserId(userId: TableIdentity): Promise<IRoleBase[]>;
|
|
10
|
+
}
|
|
@@ -6,8 +6,8 @@ export declare class BeanUserInner extends BeanBase {
|
|
|
6
6
|
private get userInnerAdapter();
|
|
7
7
|
createByProfile(profile: IAuthUserProfile): Promise<IUserBase>;
|
|
8
8
|
createAnonymous(): Promise<IUserBase>;
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
findOneByName(name: string): Promise<IUserBase | undefined>;
|
|
10
|
+
findOne(user: Partial<IUserBase>): Promise<IUserBase | undefined>;
|
|
11
11
|
update(user: Partial<IUserBase>): Promise<void>;
|
|
12
|
-
|
|
12
|
+
remove(user: Partial<IUserBase>): Promise<void>;
|
|
13
13
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Next } from 'vona';
|
|
2
|
+
import type { IDecoratorGuardOptions, IGuardExecute } from 'vona-module-a-aspect';
|
|
3
|
+
import type { IRoleNameRecord } from '../types/role.ts';
|
|
4
|
+
import { BeanBase } from 'vona';
|
|
5
|
+
export interface IGuardOptionsRoleName extends IDecoratorGuardOptions {
|
|
6
|
+
name?: keyof IRoleNameRecord | (keyof IRoleNameRecord)[];
|
|
7
|
+
passWhenMatched: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare class GuardRoleName extends BeanBase implements IGuardExecute {
|
|
10
|
+
execute(options: IGuardOptionsRoleName, next: Next): Promise<boolean>;
|
|
11
|
+
}
|
package/dist/config/config.d.ts
CHANGED
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$
|
|
9
|
-
let BeanAuthInner = (_dec$
|
|
8
|
+
var _dec$b, _dec2$b, _class$b;
|
|
9
|
+
let BeanAuthInner = (_dec$b = Bean(), _dec2$b = BeanInfo({
|
|
10
10
|
module: "a-user"
|
|
11
|
-
}), _dec$
|
|
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;
|
|
@@ -20,11 +20,11 @@ let BeanAuthInner = (_dec$a = Bean(), _dec2$a = BeanInfo({
|
|
|
20
20
|
}
|
|
21
21
|
return this._authInnerAdapter;
|
|
22
22
|
}
|
|
23
|
-
async
|
|
23
|
+
async findOne(auth) {
|
|
24
24
|
if (String(auth.id).charAt(0) === '-') return auth;
|
|
25
|
-
return await this.authInnerAdapter.
|
|
25
|
+
return await this.authInnerAdapter.findOne(auth);
|
|
26
26
|
}
|
|
27
|
-
}) || _class$
|
|
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$
|
|
64
|
-
let BeanPassport = (_dec$
|
|
63
|
+
var _dec$a, _dec2$a, _class$a;
|
|
64
|
+
let BeanPassport = (_dec$a = Bean(), _dec2$a = BeanInfo({
|
|
65
65
|
module: "a-user"
|
|
66
|
-
}), _dec$
|
|
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$9 = Bean(), _dec2$9 = BeanInfo({
|
|
|
89
89
|
return !!user && !$getUserAnonymous(user);
|
|
90
90
|
}
|
|
91
91
|
async isAdmin() {
|
|
92
|
-
const
|
|
93
|
-
return
|
|
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);
|
|
@@ -104,6 +104,9 @@ let BeanPassport = (_dec$9 = Bean(), _dec2$9 = BeanInfo({
|
|
|
104
104
|
getCurrentAuth() {
|
|
105
105
|
return this.ctx.state.passport?.auth;
|
|
106
106
|
}
|
|
107
|
+
getCurrentRoles() {
|
|
108
|
+
return this.ctx.state.passport?.roles;
|
|
109
|
+
}
|
|
107
110
|
async signin(passport, options) {
|
|
108
111
|
// current
|
|
109
112
|
await this.setCurrent(passport);
|
|
@@ -129,7 +132,7 @@ let BeanPassport = (_dec$9 = Bean(), _dec2$9 = BeanInfo({
|
|
|
129
132
|
await this.setCurrent(undefined);
|
|
130
133
|
}
|
|
131
134
|
async signinSystem(authName, authId, name, options) {
|
|
132
|
-
const user = await this.bean.userInner.
|
|
135
|
+
const user = await this.bean.userInner.findOneByName(name ?? 'admin');
|
|
133
136
|
if (!user) return this.app.throw(401);
|
|
134
137
|
const auth = {
|
|
135
138
|
id: $getAuthIdSystem(authName, authId)
|
|
@@ -251,6 +254,32 @@ let BeanPassport = (_dec$9 = Bean(), _dec2$9 = BeanInfo({
|
|
|
251
254
|
return payloadData2;
|
|
252
255
|
}
|
|
253
256
|
}
|
|
257
|
+
}) || _class$a) || _class$a);
|
|
258
|
+
|
|
259
|
+
var _dec$9, _dec2$9, _class$9;
|
|
260
|
+
let BeanRoleInner = (_dec$9 = Bean(), _dec2$9 = BeanInfo({
|
|
261
|
+
module: "a-user"
|
|
262
|
+
}), _dec$9(_class$9 = _dec2$9(_class$9 = class BeanRoleInner extends BeanBase {
|
|
263
|
+
constructor(...args) {
|
|
264
|
+
super(...args);
|
|
265
|
+
this._roleInnerAdapter = void 0;
|
|
266
|
+
}
|
|
267
|
+
get roleInnerAdapter() {
|
|
268
|
+
if (!this._roleInnerAdapter) {
|
|
269
|
+
const beanFullName = beanFullNameFromOnionName(this.scope.config.adapter.roleInner, 'service');
|
|
270
|
+
this._roleInnerAdapter = this.bean._getBean(beanFullName);
|
|
271
|
+
}
|
|
272
|
+
return this._roleInnerAdapter;
|
|
273
|
+
}
|
|
274
|
+
findOneByName(name) {
|
|
275
|
+
return this.roleInnerAdapter.findOneByName(name);
|
|
276
|
+
}
|
|
277
|
+
findOne(role) {
|
|
278
|
+
return this.roleInnerAdapter.findOne(role);
|
|
279
|
+
}
|
|
280
|
+
findAllByUserId(userId) {
|
|
281
|
+
return this.roleInnerAdapter.findAllByUserId(userId);
|
|
282
|
+
}
|
|
254
283
|
}) || _class$9) || _class$9);
|
|
255
284
|
|
|
256
285
|
var _dec$8, _dec2$8, _class$8;
|
|
@@ -274,17 +303,17 @@ let BeanUserInner = (_dec$8 = Bean(), _dec2$8 = BeanInfo({
|
|
|
274
303
|
createAnonymous() {
|
|
275
304
|
return this.userInnerAdapter.createAnonymous();
|
|
276
305
|
}
|
|
277
|
-
|
|
278
|
-
return this.userInnerAdapter.
|
|
306
|
+
findOneByName(name) {
|
|
307
|
+
return this.userInnerAdapter.findOneByName(name);
|
|
279
308
|
}
|
|
280
|
-
|
|
281
|
-
return this.userInnerAdapter.
|
|
309
|
+
findOne(user) {
|
|
310
|
+
return this.userInnerAdapter.findOne(user);
|
|
282
311
|
}
|
|
283
312
|
update(user) {
|
|
284
313
|
return this.userInnerAdapter.update(user);
|
|
285
314
|
}
|
|
286
|
-
|
|
287
|
-
return this.userInnerAdapter.
|
|
315
|
+
remove(user) {
|
|
316
|
+
return this.userInnerAdapter.remove(user);
|
|
288
317
|
}
|
|
289
318
|
}) || _class$8) || _class$8);
|
|
290
319
|
|
|
@@ -304,31 +333,13 @@ let EventSignout = (_dec$5 = Event(), _dec2$5 = BeanInfo({
|
|
|
304
333
|
}), _dec$5(_class$5 = _dec2$5(_class$5 = class EventSignout extends BeanEventBase {}) || _class$5) || _class$5);
|
|
305
334
|
|
|
306
335
|
var _dec$4, _dec2$4, _class$4;
|
|
307
|
-
let
|
|
308
|
-
admin: true,
|
|
309
|
-
passWhenMatched: true
|
|
310
|
-
}), _dec2$4 = BeanInfo({
|
|
311
|
-
module: "a-user"
|
|
312
|
-
}), _dec$4(_class$4 = _dec2$4(_class$4 = class GuardAdmin extends BeanBase {
|
|
313
|
-
async execute(options, next) {
|
|
314
|
-
if (options.admin) {
|
|
315
|
-
const isAdmin = await this.bean.passport.isAdmin();
|
|
316
|
-
if (!isAdmin) return this.app.throw(403);
|
|
317
|
-
if (options.passWhenMatched) return true;
|
|
318
|
-
}
|
|
319
|
-
// next
|
|
320
|
-
return next();
|
|
321
|
-
}
|
|
322
|
-
}) || _class$4) || _class$4);
|
|
323
|
-
|
|
324
|
-
var _dec$3, _dec2$3, _class$3;
|
|
325
|
-
let GuardPassport = (_dec$3 = Guard({
|
|
336
|
+
let GuardPassport = (_dec$4 = Guard({
|
|
326
337
|
global: true,
|
|
327
338
|
public: false,
|
|
328
339
|
checkAuthToken: true
|
|
329
|
-
}), _dec2$
|
|
340
|
+
}), _dec2$4 = BeanInfo({
|
|
330
341
|
module: "a-user"
|
|
331
|
-
}), _dec$
|
|
342
|
+
}), _dec$4(_class$4 = _dec2$4(_class$4 = class GuardPassport extends BeanBase {
|
|
332
343
|
async execute(options, next) {
|
|
333
344
|
// auth token
|
|
334
345
|
if (!this.bean.passport.getCurrent()) {
|
|
@@ -354,6 +365,38 @@ let GuardPassport = (_dec$3 = Guard({
|
|
|
354
365
|
// next
|
|
355
366
|
return next();
|
|
356
367
|
}
|
|
368
|
+
}) || _class$4) || _class$4);
|
|
369
|
+
|
|
370
|
+
let __roleAdapter;
|
|
371
|
+
function setRoleAdapter(roleAdapter) {
|
|
372
|
+
__roleAdapter = roleAdapter;
|
|
373
|
+
}
|
|
374
|
+
function $getRoleId(role) {
|
|
375
|
+
return __roleAdapter.getRoleId(role);
|
|
376
|
+
}
|
|
377
|
+
function $getRoleName(role) {
|
|
378
|
+
return __roleAdapter.getRoleName(role);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
var _dec$3, _dec2$3, _class$3;
|
|
382
|
+
let GuardRoleName = (_dec$3 = Guard({
|
|
383
|
+
passWhenMatched: true
|
|
384
|
+
}), _dec2$3 = BeanInfo({
|
|
385
|
+
module: "a-user"
|
|
386
|
+
}), _dec$3(_class$3 = _dec2$3(_class$3 = class GuardRoleName extends BeanBase {
|
|
387
|
+
async execute(options, next) {
|
|
388
|
+
if (!options.name) return this.app.throw(403);
|
|
389
|
+
const user = this.bean.passport.getCurrentUser();
|
|
390
|
+
if (!user || $getUserAnonymous(user)) return this.app.throw(403);
|
|
391
|
+
const roles = this.bean.passport.getCurrentRoles();
|
|
392
|
+
if (!roles) return this.app.throw(403);
|
|
393
|
+
const roleNames = roles?.map(item => $getRoleName(item));
|
|
394
|
+
const optionsName = Array.isArray(options.name) ? options.name : [options.name];
|
|
395
|
+
if (!roleNames.some(roleName => optionsName.includes(roleName))) return this.app.throw(403);
|
|
396
|
+
if (options.passWhenMatched) return true;
|
|
397
|
+
// next
|
|
398
|
+
return next();
|
|
399
|
+
}
|
|
357
400
|
}) || _class$3) || _class$3);
|
|
358
401
|
|
|
359
402
|
var _dec$2, _dec2$2, _class$2;
|
|
@@ -404,7 +447,8 @@ function config(_app) {
|
|
|
404
447
|
authToken: 'home-user:authTokenAdapter',
|
|
405
448
|
passport: 'home-user:passportAdapter',
|
|
406
449
|
userInner: 'home-user:userInnerAdapter',
|
|
407
|
-
authInner: 'home-user:authInnerAdapter'
|
|
450
|
+
authInner: 'home-user:authInnerAdapter',
|
|
451
|
+
roleInner: 'home-user:roleInnerAdapter'
|
|
408
452
|
}
|
|
409
453
|
};
|
|
410
454
|
}
|
|
@@ -422,16 +466,22 @@ function Public(options) {
|
|
|
422
466
|
public: _public
|
|
423
467
|
});
|
|
424
468
|
}
|
|
425
|
-
function Admin(options) {
|
|
426
|
-
return Aspect.guard('a-user:admin', options);
|
|
427
|
-
}
|
|
428
469
|
function UserName(options) {
|
|
429
470
|
return Aspect.guard('a-user:userName', options);
|
|
430
471
|
}
|
|
472
|
+
function RoleName(options) {
|
|
473
|
+
return Aspect.guard('a-user:roleName', options);
|
|
474
|
+
}
|
|
475
|
+
function Admin(options) {
|
|
476
|
+
return Aspect.guard('a-user:roleName', Object.assign({}, options, {
|
|
477
|
+
name: 'admin'
|
|
478
|
+
}));
|
|
479
|
+
}
|
|
431
480
|
const Passport = {
|
|
432
|
-
admin: Admin,
|
|
433
481
|
public: Public,
|
|
434
|
-
userName: UserName
|
|
482
|
+
userName: UserName,
|
|
483
|
+
roleName: RoleName,
|
|
484
|
+
admin: Admin
|
|
435
485
|
};
|
|
436
486
|
|
|
437
|
-
export { $getAuthId, $getAuthIdSystem, $getUserAnonymous, $getUserAvatar, $getUserId, $getUserIdSystem, $getUserLocale, $getUserName, BeanAuthInner, BeanPassport, 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/index.d.ts
CHANGED
package/dist/lib/passport.d.ts
CHANGED
|
@@ -1,14 +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';
|
|
3
|
+
import type { IGuardOptionsRoleName } from '../bean/guard.roleName.ts';
|
|
4
4
|
import type { IGuardOptionsUserName } from '../bean/guard.userName.ts';
|
|
5
5
|
declare function Public(options?: Partial<TypeUseOnionOmitOptionsGlobal<IGuardOptionsPassport>>): ClassDecorator & MethodDecorator;
|
|
6
|
-
declare function Admin(options?: Partial<IGuardOptionsAdmin>): ClassDecorator & MethodDecorator;
|
|
7
6
|
declare function UserName(options?: Partial<IGuardOptionsUserName>): ClassDecorator & MethodDecorator;
|
|
7
|
+
declare function RoleName(options?: Partial<IGuardOptionsRoleName>): ClassDecorator & MethodDecorator;
|
|
8
|
+
declare function Admin(options?: Partial<Omit<IGuardOptionsRoleName, 'name'>>): ClassDecorator & MethodDecorator;
|
|
8
9
|
export interface IDecoratorGroupPassport {
|
|
9
|
-
admin: typeof Admin;
|
|
10
10
|
public: typeof Public;
|
|
11
11
|
userName: typeof UserName;
|
|
12
|
+
roleName: typeof RoleName;
|
|
13
|
+
admin: typeof Admin;
|
|
12
14
|
}
|
|
13
15
|
export declare const Passport: IDecoratorGroupPassport;
|
|
14
16
|
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { TableIdentity } from 'vona-module-a-database';
|
|
2
|
+
import type { IRoleAdapter, IRoleBase } from '../types/role.ts';
|
|
3
|
+
export declare function setRoleAdapter(roleAdapter: IRoleAdapter): void;
|
|
4
|
+
export declare function $getRoleId(role: IRoleBase): TableIdentity;
|
|
5
|
+
export declare function $getRoleName(role: IRoleBase): string;
|
package/dist/types/auth.d.ts
CHANGED
package/dist/types/index.d.ts
CHANGED
package/dist/types/passport.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import type { IPayloadDataBase } from 'vona-module-a-jwt';
|
|
2
2
|
import type { IAuthBase } from './auth.ts';
|
|
3
|
+
import type { IRoleBase } from './role.ts';
|
|
3
4
|
import type { IUserBase } from './user.ts';
|
|
4
5
|
export interface IPassportBase {
|
|
5
6
|
user?: IUserBase;
|
|
6
7
|
auth?: IAuthBase;
|
|
8
|
+
roles?: IRoleBase[];
|
|
7
9
|
}
|
|
8
10
|
export interface IPassportAdapter {
|
|
9
|
-
isAdmin(
|
|
11
|
+
isAdmin(passport: IPassportBase | undefined): Promise<boolean>;
|
|
10
12
|
setCurrent(passport: IPassportBase | undefined): Promise<IPassportBase | undefined>;
|
|
11
13
|
serialize(passport: IPassportBase): Promise<IPayloadDataBase>;
|
|
12
14
|
deserialize(payloadData: IPayloadDataBase): Promise<IPassportBase | undefined>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { TableIdentity } from 'vona-module-a-database';
|
|
2
|
+
export interface IRoleNameRecord {
|
|
3
|
+
admin: never;
|
|
4
|
+
}
|
|
5
|
+
export interface IRoleIdRecord {
|
|
6
|
+
}
|
|
7
|
+
export interface IRoleBase {
|
|
8
|
+
id: TableIdentity;
|
|
9
|
+
}
|
|
10
|
+
export interface IRoleAdapter {
|
|
11
|
+
getRoleId(role: IRoleBase): TableIdentity;
|
|
12
|
+
getRoleName(role: IRoleBase): string;
|
|
13
|
+
}
|
|
14
|
+
export interface IRoleInnerAdapter {
|
|
15
|
+
findOneByName(name: string): Promise<IRoleBase | undefined>;
|
|
16
|
+
findOne(role: Partial<IRoleBase>): Promise<IRoleBase | undefined>;
|
|
17
|
+
findAllByUserId(userId: TableIdentity): Promise<IRoleBase[]>;
|
|
18
|
+
}
|
package/dist/types/user.d.ts
CHANGED
|
@@ -20,8 +20,8 @@ export interface IUserAdapter {
|
|
|
20
20
|
export interface IUserInnerAdapter {
|
|
21
21
|
createByProfile(profile: IAuthUserProfile): Promise<IUserBase>;
|
|
22
22
|
createAnonymous(): Promise<IUserBase>;
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
findOneByName(name: string): Promise<IUserBase | undefined>;
|
|
24
|
+
findOne(user: Partial<IUserBase>): Promise<IUserBase | undefined>;
|
|
25
25
|
update(user: Partial<IUserBase>): Promise<void>;
|
|
26
|
-
|
|
26
|
+
remove(user: Partial<IUserBase>): Promise<void>;
|
|
27
27
|
}
|
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
|
-
}
|