vona-module-a-user 5.0.11 → 5.0.13
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.
|
@@ -19,6 +19,7 @@ import type { TypeEventSignoutData, TypeEventSignoutResult } from '../bean/event
|
|
|
19
19
|
/** bean: begin */
|
|
20
20
|
import type { IGuardOptionsAdmin } from '../bean/guard.admin.ts';
|
|
21
21
|
import type { IGuardOptionsPassport } from '../bean/guard.passport.ts';
|
|
22
|
+
import type { IGuardOptionsUserName } from '../bean/guard.userName.ts';
|
|
22
23
|
import type { config } from '../config/config.ts';
|
|
23
24
|
/** config: end */
|
|
24
25
|
/** scope: begin */
|
|
@@ -31,12 +32,14 @@ import 'vona';
|
|
|
31
32
|
import 'vona';
|
|
32
33
|
export * from '../bean/bean.authInner.ts';
|
|
33
34
|
export * from '../bean/bean.passport.ts';
|
|
35
|
+
export * from '../bean/bean.userInner.ts';
|
|
34
36
|
declare module 'vona-module-a-aspect' {
|
|
35
37
|
interface IGuardRecordGlobal {
|
|
36
38
|
'a-user:passport': IGuardOptionsPassport;
|
|
37
39
|
}
|
|
38
40
|
interface IGuardRecordLocal {
|
|
39
41
|
'a-user:admin': IGuardOptionsAdmin;
|
|
42
|
+
'a-user:userName': IGuardOptionsUserName;
|
|
40
43
|
}
|
|
41
44
|
}
|
|
42
45
|
declare module 'vona-module-a-user' {
|
|
@@ -44,12 +47,14 @@ declare module 'vona-module-a-user' {
|
|
|
44
47
|
}
|
|
45
48
|
interface GuardPassport {
|
|
46
49
|
}
|
|
50
|
+
interface GuardUserName {
|
|
51
|
+
}
|
|
47
52
|
}
|
|
48
|
-
export * from '../bean/bean.userInner.ts';
|
|
49
53
|
/** bean: end */
|
|
50
54
|
/** event: begin */
|
|
51
55
|
export * from '../bean/event.createUserAnonymous.ts';
|
|
52
56
|
export * from '../bean/event.signin.ts';
|
|
57
|
+
export * from '../bean/event.signout.ts';
|
|
53
58
|
declare module 'vona' {
|
|
54
59
|
}
|
|
55
60
|
declare module 'vona-module-a-user' {
|
|
@@ -67,10 +72,10 @@ declare module 'vona' {
|
|
|
67
72
|
userInner: BeanUserInner;
|
|
68
73
|
}
|
|
69
74
|
}
|
|
70
|
-
export * from '../bean/event.signout.ts';
|
|
71
75
|
/** guard: begin */
|
|
72
76
|
export * from '../bean/guard.admin.ts';
|
|
73
77
|
export * from '../bean/guard.passport.ts';
|
|
78
|
+
export * from '../bean/guard.userName.ts';
|
|
74
79
|
declare module 'vona' {
|
|
75
80
|
}
|
|
76
81
|
declare module 'vona-module-a-user' {
|
|
@@ -1,7 +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 { IUserBase } from '../types/user.ts';
|
|
4
|
+
import type { IUserBase, IUserNameRecord } from '../types/user.ts';
|
|
5
5
|
import { BeanBase } from 'vona';
|
|
6
6
|
export declare class BeanPassport extends BeanBase {
|
|
7
7
|
private _authTokenAdapter;
|
|
@@ -18,7 +18,7 @@ export declare class BeanPassport extends BeanBase {
|
|
|
18
18
|
signin(passport: IPassportBase, options?: ISigninOptions): Promise<IJwtToken>;
|
|
19
19
|
signout(): Promise<void>;
|
|
20
20
|
signinSystem<K extends keyof IAuthIdRecord>(authName: IAuthIdRecord[K], authId: K, name?: string, options?: ISigninOptions): Promise<IJwtToken>;
|
|
21
|
-
signinMock(name?:
|
|
21
|
+
signinMock(name?: keyof IUserNameRecord, options?: ISigninOptions): Promise<IJwtToken>;
|
|
22
22
|
signinWithAnonymous(): Promise<void>;
|
|
23
23
|
createUserAnonymous(): Promise<IUserBase>;
|
|
24
24
|
kickOut(user: IUserBase): Promise<void>;
|
|
@@ -3,7 +3,7 @@ import type { IDecoratorGuardOptions, IGuardExecute } from 'vona-module-a-aspect
|
|
|
3
3
|
import { BeanBase } from 'vona';
|
|
4
4
|
export interface IGuardOptionsAdmin extends IDecoratorGuardOptions {
|
|
5
5
|
admin: boolean;
|
|
6
|
-
|
|
6
|
+
passWhenMatched: boolean;
|
|
7
7
|
}
|
|
8
8
|
export declare class GuardAdmin extends BeanBase implements IGuardExecute {
|
|
9
9
|
execute(options: IGuardOptionsAdmin, next: Next): Promise<boolean>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Next } from 'vona';
|
|
2
|
+
import type { IDecoratorGuardOptions, IGuardExecute } from 'vona-module-a-aspect';
|
|
3
|
+
import type { IUserNameRecord } from '../types/user.ts';
|
|
4
|
+
import { BeanBase } from 'vona';
|
|
5
|
+
export interface IGuardOptionsUserName extends IDecoratorGuardOptions {
|
|
6
|
+
name?: keyof IUserNameRecord | (keyof IUserNameRecord)[];
|
|
7
|
+
passWhenMatched: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare class GuardUserName extends BeanBase implements IGuardExecute {
|
|
10
|
+
execute(options: IGuardOptionsUserName, next: Next): Promise<boolean>;
|
|
11
|
+
}
|
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$a, _dec2$a, _class$a;
|
|
9
|
+
let BeanAuthInner = (_dec$a = Bean(), _dec2$a = BeanInfo({
|
|
10
10
|
module: "a-user"
|
|
11
|
-
}), _dec$
|
|
11
|
+
}), _dec$a(_class$a = _dec2$a(_class$a = 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$9 = Bean(), _dec2$9 = BeanInfo({
|
|
|
24
24
|
if (String(auth.id).charAt(0) === '-') return auth;
|
|
25
25
|
return await this.authInnerAdapter.get(auth);
|
|
26
26
|
}
|
|
27
|
-
}) || _class$
|
|
27
|
+
}) || _class$a) || _class$a);
|
|
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$9, _dec2$9, _class$9;
|
|
64
|
+
let BeanPassport = (_dec$9 = Bean(), _dec2$9 = BeanInfo({
|
|
65
65
|
module: "a-user"
|
|
66
|
-
}), _dec$
|
|
66
|
+
}), _dec$9(_class$9 = _dec2$9(_class$9 = class BeanPassport extends BeanBase {
|
|
67
67
|
constructor(...args) {
|
|
68
68
|
super(...args);
|
|
69
69
|
this._authTokenAdapter = void 0;
|
|
@@ -251,12 +251,12 @@ let BeanPassport = (_dec$8 = Bean(), _dec2$8 = BeanInfo({
|
|
|
251
251
|
return payloadData2;
|
|
252
252
|
}
|
|
253
253
|
}
|
|
254
|
-
}) || _class$
|
|
254
|
+
}) || _class$9) || _class$9);
|
|
255
255
|
|
|
256
|
-
var _dec$
|
|
257
|
-
let BeanUserInner = (_dec$
|
|
256
|
+
var _dec$8, _dec2$8, _class$8;
|
|
257
|
+
let BeanUserInner = (_dec$8 = Bean(), _dec2$8 = BeanInfo({
|
|
258
258
|
module: "a-user"
|
|
259
|
-
}), _dec$
|
|
259
|
+
}), _dec$8(_class$8 = _dec2$8(_class$8 = class BeanUserInner extends BeanBase {
|
|
260
260
|
constructor(...args) {
|
|
261
261
|
super(...args);
|
|
262
262
|
this._userInnerAdapter = void 0;
|
|
@@ -286,49 +286,49 @@ let BeanUserInner = (_dec$7 = Bean(), _dec2$7 = BeanInfo({
|
|
|
286
286
|
delete(user) {
|
|
287
287
|
return this.userInnerAdapter.delete(user);
|
|
288
288
|
}
|
|
289
|
-
}) || _class$
|
|
289
|
+
}) || _class$8) || _class$8);
|
|
290
|
+
|
|
291
|
+
var _dec$7, _dec2$7, _class$7;
|
|
292
|
+
let EventCreateUserAnonymous = (_dec$7 = Event(), _dec2$7 = BeanInfo({
|
|
293
|
+
module: "a-user"
|
|
294
|
+
}), _dec$7(_class$7 = _dec2$7(_class$7 = class EventCreateUserAnonymous extends BeanEventBase {}) || _class$7) || _class$7);
|
|
290
295
|
|
|
291
296
|
var _dec$6, _dec2$6, _class$6;
|
|
292
|
-
let
|
|
297
|
+
let EventSignin = (_dec$6 = Event(), _dec2$6 = BeanInfo({
|
|
293
298
|
module: "a-user"
|
|
294
|
-
}), _dec$6(_class$6 = _dec2$6(_class$6 = class
|
|
299
|
+
}), _dec$6(_class$6 = _dec2$6(_class$6 = class EventSignin extends BeanEventBase {}) || _class$6) || _class$6);
|
|
295
300
|
|
|
296
301
|
var _dec$5, _dec2$5, _class$5;
|
|
297
|
-
let
|
|
302
|
+
let EventSignout = (_dec$5 = Event(), _dec2$5 = BeanInfo({
|
|
298
303
|
module: "a-user"
|
|
299
|
-
}), _dec$5(_class$5 = _dec2$5(_class$5 = class
|
|
304
|
+
}), _dec$5(_class$5 = _dec2$5(_class$5 = class EventSignout extends BeanEventBase {}) || _class$5) || _class$5);
|
|
300
305
|
|
|
301
306
|
var _dec$4, _dec2$4, _class$4;
|
|
302
|
-
let
|
|
303
|
-
module: "a-user"
|
|
304
|
-
}), _dec$4(_class$4 = _dec2$4(_class$4 = class EventSignout extends BeanEventBase {}) || _class$4) || _class$4);
|
|
305
|
-
|
|
306
|
-
var _dec$3, _dec2$3, _class$3;
|
|
307
|
-
let GuardAdmin = (_dec$3 = Guard({
|
|
307
|
+
let GuardAdmin = (_dec$4 = Guard({
|
|
308
308
|
admin: true,
|
|
309
|
-
|
|
310
|
-
}), _dec2$
|
|
309
|
+
passWhenMatched: true
|
|
310
|
+
}), _dec2$4 = BeanInfo({
|
|
311
311
|
module: "a-user"
|
|
312
|
-
}), _dec$
|
|
312
|
+
}), _dec$4(_class$4 = _dec2$4(_class$4 = class GuardAdmin extends BeanBase {
|
|
313
313
|
async execute(options, next) {
|
|
314
314
|
if (options.admin) {
|
|
315
315
|
const isAdmin = await this.bean.passport.isAdmin();
|
|
316
316
|
if (!isAdmin) return this.app.throw(403);
|
|
317
|
-
if (options.
|
|
317
|
+
if (options.passWhenMatched) return true;
|
|
318
318
|
}
|
|
319
319
|
// next
|
|
320
320
|
return next();
|
|
321
321
|
}
|
|
322
|
-
}) || _class$
|
|
322
|
+
}) || _class$4) || _class$4);
|
|
323
323
|
|
|
324
|
-
var _dec$
|
|
325
|
-
let GuardPassport = (_dec$
|
|
324
|
+
var _dec$3, _dec2$3, _class$3;
|
|
325
|
+
let GuardPassport = (_dec$3 = Guard({
|
|
326
326
|
global: true,
|
|
327
327
|
public: false,
|
|
328
328
|
checkAuthToken: true
|
|
329
|
-
}), _dec2$
|
|
329
|
+
}), _dec2$3 = BeanInfo({
|
|
330
330
|
module: "a-user"
|
|
331
|
-
}), _dec$
|
|
331
|
+
}), _dec$3(_class$3 = _dec2$3(_class$3 = class GuardPassport extends BeanBase {
|
|
332
332
|
async execute(options, next) {
|
|
333
333
|
// auth token
|
|
334
334
|
if (!this.bean.passport.getCurrent()) {
|
|
@@ -354,6 +354,25 @@ let GuardPassport = (_dec$2 = Guard({
|
|
|
354
354
|
// next
|
|
355
355
|
return next();
|
|
356
356
|
}
|
|
357
|
+
}) || _class$3) || _class$3);
|
|
358
|
+
|
|
359
|
+
var _dec$2, _dec2$2, _class$2;
|
|
360
|
+
let GuardUserName = (_dec$2 = Guard({
|
|
361
|
+
passWhenMatched: true
|
|
362
|
+
}), _dec2$2 = BeanInfo({
|
|
363
|
+
module: "a-user"
|
|
364
|
+
}), _dec$2(_class$2 = _dec2$2(_class$2 = class GuardUserName extends BeanBase {
|
|
365
|
+
async execute(options, next) {
|
|
366
|
+
if (!options.name) return this.app.throw(403);
|
|
367
|
+
const user = this.bean.passport.getCurrentUser();
|
|
368
|
+
if (!user || $getUserAnonymous(user)) return this.app.throw(403);
|
|
369
|
+
const userName = $getUserName(user);
|
|
370
|
+
const optionsName = Array.isArray(options.name) ? options.name : [options.name];
|
|
371
|
+
if (!optionsName.includes(userName)) return this.app.throw(403);
|
|
372
|
+
if (options.passWhenMatched) return true;
|
|
373
|
+
// next
|
|
374
|
+
return next();
|
|
375
|
+
}
|
|
357
376
|
}) || _class$2) || _class$2);
|
|
358
377
|
|
|
359
378
|
var _dec$1, _dec2$1, _class$1;
|
|
@@ -406,9 +425,13 @@ function Public(options) {
|
|
|
406
425
|
function Admin(options) {
|
|
407
426
|
return Aspect.guard('a-user:admin', options);
|
|
408
427
|
}
|
|
428
|
+
function UserName(options) {
|
|
429
|
+
return Aspect.guard('a-user:userName', options);
|
|
430
|
+
}
|
|
409
431
|
const Passport = {
|
|
410
432
|
admin: Admin,
|
|
411
|
-
public: Public
|
|
433
|
+
public: Public,
|
|
434
|
+
userName: UserName
|
|
412
435
|
};
|
|
413
436
|
|
|
414
|
-
export { $getAuthId, $getAuthIdSystem, $getUserAnonymous, $getUserAvatar, $getUserId, $getUserIdSystem, $getUserLocale, $getUserName, BeanAuthInner, BeanPassport, BeanUserInner, EventCreateUserAnonymous, EventSignin, EventSignout, GuardAdmin, GuardPassport, MetaPrintTip, Passport, ScopeModuleAUser, config, setAuthAdapter, setUserAdapter };
|
|
437
|
+
export { $getAuthId, $getAuthIdSystem, $getUserAnonymous, $getUserAvatar, $getUserId, $getUserIdSystem, $getUserLocale, $getUserName, BeanAuthInner, BeanPassport, BeanUserInner, EventCreateUserAnonymous, EventSignin, EventSignout, GuardAdmin, GuardPassport, GuardUserName, MetaPrintTip, Passport, ScopeModuleAUser, config, setAuthAdapter, setUserAdapter };
|
package/dist/lib/passport.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import type { TypeUseOnionOmitOptionsGlobal } from 'vona-module-a-onion';
|
|
2
2
|
import type { IGuardOptionsAdmin } from '../bean/guard.admin.ts';
|
|
3
3
|
import type { IGuardOptionsPassport } from '../bean/guard.passport.ts';
|
|
4
|
+
import type { IGuardOptionsUserName } from '../bean/guard.userName.ts';
|
|
4
5
|
declare function Public(options?: Partial<TypeUseOnionOmitOptionsGlobal<IGuardOptionsPassport>>): ClassDecorator & MethodDecorator;
|
|
5
6
|
declare function Admin(options?: Partial<IGuardOptionsAdmin>): ClassDecorator & MethodDecorator;
|
|
6
|
-
|
|
7
|
+
declare function UserName(options?: Partial<IGuardOptionsUserName>): ClassDecorator & MethodDecorator;
|
|
8
|
+
export interface IDecoratorGroupPassport {
|
|
7
9
|
admin: typeof Admin;
|
|
8
10
|
public: typeof Public;
|
|
9
|
-
|
|
11
|
+
userName: typeof UserName;
|
|
12
|
+
}
|
|
13
|
+
export declare const Passport: IDecoratorGroupPassport;
|
|
10
14
|
export {};
|
package/dist/types/user.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { ILocaleInfos } from 'vona';
|
|
2
2
|
import type { TableIdentity } from 'vona-module-a-database';
|
|
3
3
|
import type { IAuthUserProfile } from './authProfile.ts';
|
|
4
|
+
export interface IUserNameRecord {
|
|
5
|
+
admin: never;
|
|
6
|
+
}
|
|
4
7
|
export interface IUserIdRecord {
|
|
5
8
|
'-1': 'anonymous';
|
|
6
9
|
}
|