vona-module-a-user 5.0.38 → 5.0.40
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 +3 -0
- package/dist/bean/bean.passport.d.ts +4 -4
- package/dist/index.js +39 -18
- package/dist/main.d.ts +7 -0
- package/dist/types/passport.d.ts +4 -0
- package/package.json +3 -3
|
@@ -228,6 +228,9 @@ declare module 'vona-module-a-user' {
|
|
|
228
228
|
export * from '../config/config.ts';
|
|
229
229
|
import type { config } from '../config/config.ts';
|
|
230
230
|
/** config: end */
|
|
231
|
+
/** main: begin */
|
|
232
|
+
export * from '../main.ts';
|
|
233
|
+
/** main: end */
|
|
231
234
|
/** scope: begin */
|
|
232
235
|
import { BeanScopeBase, type BeanScopeUtil, type TypeModuleConfig } from 'vona';
|
|
233
236
|
export declare class ScopeModuleAUser extends BeanScopeBase {
|
|
@@ -14,10 +14,10 @@ export declare class BeanPassport extends BeanBase {
|
|
|
14
14
|
get isActivated(): boolean;
|
|
15
15
|
isAdmin(): Promise<boolean>;
|
|
16
16
|
setCurrent(passport: IPassport | undefined): Promise<void>;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
get current(): IPassport | undefined;
|
|
18
|
+
get currentUser(): IUser | undefined;
|
|
19
|
+
get currentAuth(): IAuth | undefined;
|
|
20
|
+
get currentRoles(): IRole[] | undefined;
|
|
21
21
|
signin(passport: IPassport, options?: ISigninOptions): Promise<IJwtToken>;
|
|
22
22
|
signout(): Promise<void>;
|
|
23
23
|
signinSystem<K extends keyof IAuthIdRecord>(authName: IAuthIdRecord[K], authId: K, name?: string, options?: ISigninOptions): Promise<IJwtToken>;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BeanInfo, BeanBase, beanFullNameFromOnionName, createHash, uuidv4, BeanScopeBase } from 'vona';
|
|
1
|
+
import { BeanInfo, BeanBase, beanFullNameFromOnionName, createHash, uuidv4, BeanSimple, BeanScopeBase } from 'vona';
|
|
2
2
|
import { catchError, isNil } from '@cabloy/utils';
|
|
3
3
|
import { Guard, Aspect } from 'vona-module-a-aspect';
|
|
4
4
|
import { Bean, Service, Scope } from 'vona-module-a-bean';
|
|
@@ -17,7 +17,7 @@ let GuardPassport = (_dec$f = Guard({
|
|
|
17
17
|
}), _dec$f(_class$f = _dec2$f(_class$f = class GuardPassport extends BeanBase {
|
|
18
18
|
async execute(options, next) {
|
|
19
19
|
// auth token
|
|
20
|
-
if (!this.bean.passport.
|
|
20
|
+
if (!this.bean.passport.current) {
|
|
21
21
|
if (options.checkAuthToken) {
|
|
22
22
|
// will return undefined if no accessToken, so not check options.public
|
|
23
23
|
const [_, err] = await catchError(() => {
|
|
@@ -27,7 +27,7 @@ let GuardPassport = (_dec$f = Guard({
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
// check current
|
|
30
|
-
if (!this.bean.passport.
|
|
30
|
+
if (!this.bean.passport.current) {
|
|
31
31
|
await this.bean.passport.signinWithAnonymous();
|
|
32
32
|
}
|
|
33
33
|
if (!options.public && !this.bean.passport.isAuthenticated) {
|
|
@@ -69,9 +69,9 @@ let GuardRoleName = (_dec$e = Guard({
|
|
|
69
69
|
}
|
|
70
70
|
async _check(options) {
|
|
71
71
|
if (!options.name) return false;
|
|
72
|
-
const user = this.bean.passport.
|
|
72
|
+
const user = this.bean.passport.currentUser;
|
|
73
73
|
if (!user || user.anonymous) return false;
|
|
74
|
-
const roles = this.bean.passport.
|
|
74
|
+
const roles = this.bean.passport.currentRoles;
|
|
75
75
|
if (!roles) return false;
|
|
76
76
|
const roleNames = roles?.map(item => item.name);
|
|
77
77
|
const optionsName = Array.isArray(options.name) ? options.name : [options.name];
|
|
@@ -99,7 +99,7 @@ let GuardUserName = (_dec$d = Guard({
|
|
|
99
99
|
}
|
|
100
100
|
async _check(options) {
|
|
101
101
|
if (!options.name) return false;
|
|
102
|
-
const user = this.bean.passport.
|
|
102
|
+
const user = this.bean.passport.currentUser;
|
|
103
103
|
if (!user || user.anonymous) return false;
|
|
104
104
|
const userName = user.name;
|
|
105
105
|
const optionsName = Array.isArray(options.name) ? options.name : [options.name];
|
|
@@ -137,30 +137,30 @@ let BeanPassport = (_dec$c = Bean(), _dec2$c = BeanInfo({
|
|
|
137
137
|
return this._passportAdapter;
|
|
138
138
|
}
|
|
139
139
|
get isAuthenticated() {
|
|
140
|
-
const user = this.
|
|
140
|
+
const user = this.currentUser;
|
|
141
141
|
return !!user && !user.anonymous;
|
|
142
142
|
}
|
|
143
143
|
get isActivated() {
|
|
144
|
-
const user = this.
|
|
144
|
+
const user = this.currentUser;
|
|
145
145
|
return !!user && !!user.activated;
|
|
146
146
|
}
|
|
147
147
|
async isAdmin() {
|
|
148
|
-
const passport = this.
|
|
148
|
+
const passport = this.current;
|
|
149
149
|
return await this.passportAdapter.isAdmin(passport);
|
|
150
150
|
}
|
|
151
151
|
async setCurrent(passport) {
|
|
152
152
|
this.ctx.state.passport = await this.passportAdapter.setCurrent(passport);
|
|
153
153
|
}
|
|
154
|
-
|
|
154
|
+
get current() {
|
|
155
155
|
return this.ctx.state.passport;
|
|
156
156
|
}
|
|
157
|
-
|
|
157
|
+
get currentUser() {
|
|
158
158
|
return this.ctx.state.passport?.user;
|
|
159
159
|
}
|
|
160
|
-
|
|
160
|
+
get currentAuth() {
|
|
161
161
|
return this.ctx.state.passport?.auth;
|
|
162
162
|
}
|
|
163
|
-
|
|
163
|
+
get currentRoles() {
|
|
164
164
|
return this.ctx.state.passport?.roles;
|
|
165
165
|
}
|
|
166
166
|
async signin(passport, options) {
|
|
@@ -178,7 +178,7 @@ let BeanPassport = (_dec$c = Bean(), _dec2$c = BeanInfo({
|
|
|
178
178
|
}
|
|
179
179
|
async signout() {
|
|
180
180
|
// current
|
|
181
|
-
const passport = this.
|
|
181
|
+
const passport = this.current;
|
|
182
182
|
if (!passport) return;
|
|
183
183
|
// removeAuthToken
|
|
184
184
|
const payloadData = await this.passportAdapter.serialize(passport);
|
|
@@ -251,7 +251,7 @@ let BeanPassport = (_dec$c = Bean(), _dec2$c = BeanInfo({
|
|
|
251
251
|
// only created by accessToken
|
|
252
252
|
async createTempAuthToken(options) {
|
|
253
253
|
// current
|
|
254
|
-
const passport = this.
|
|
254
|
+
const passport = this.current;
|
|
255
255
|
if (!passport) return this.app.throw(401);
|
|
256
256
|
// payloadData
|
|
257
257
|
const payloadData = await this._passportSerialize(passport, {
|
|
@@ -262,7 +262,7 @@ let BeanPassport = (_dec$c = Bean(), _dec2$c = BeanInfo({
|
|
|
262
262
|
}
|
|
263
263
|
async createOauthAuthToken(options) {
|
|
264
264
|
// current
|
|
265
|
-
const passport = this.
|
|
265
|
+
const passport = this.current;
|
|
266
266
|
if (!passport) return this.app.throw(401);
|
|
267
267
|
// payloadData
|
|
268
268
|
const payloadData = await this._passportSerialize(passport, {
|
|
@@ -273,7 +273,7 @@ let BeanPassport = (_dec$c = Bean(), _dec2$c = BeanInfo({
|
|
|
273
273
|
}
|
|
274
274
|
async createOauthCode(options) {
|
|
275
275
|
// current
|
|
276
|
-
const passport = this.
|
|
276
|
+
const passport = this.current;
|
|
277
277
|
if (!passport) return this.app.throw(401);
|
|
278
278
|
// payloadData
|
|
279
279
|
const payloadData = await this._passportSerialize(passport, {
|
|
@@ -590,6 +590,27 @@ function config(_app) {
|
|
|
590
590
|
};
|
|
591
591
|
}
|
|
592
592
|
|
|
593
|
+
class Main extends BeanSimple {
|
|
594
|
+
async moduleLoading() {}
|
|
595
|
+
async moduleLoaded() {
|
|
596
|
+
// user
|
|
597
|
+
Object.defineProperty(this.app.context, 'user', {
|
|
598
|
+
enumerable: false,
|
|
599
|
+
get() {
|
|
600
|
+
return this.app.bean.passport.currentUser;
|
|
601
|
+
}
|
|
602
|
+
});
|
|
603
|
+
// passport
|
|
604
|
+
Object.defineProperty(this.app.context, 'passport', {
|
|
605
|
+
enumerable: false,
|
|
606
|
+
get() {
|
|
607
|
+
return this.app.bean.passport.current;
|
|
608
|
+
}
|
|
609
|
+
});
|
|
610
|
+
}
|
|
611
|
+
async configLoaded(_config) {}
|
|
612
|
+
}
|
|
613
|
+
|
|
593
614
|
var _dec, _dec2, _class;
|
|
594
615
|
let ScopeModuleAUser = (_dec = Scope(), _dec2 = BeanInfo({
|
|
595
616
|
module: "a-user"
|
|
@@ -632,4 +653,4 @@ function $getUserIdSystem(_userName, userId) {
|
|
|
632
653
|
return userId;
|
|
633
654
|
}
|
|
634
655
|
|
|
635
|
-
export { $getAuthIdSystem, $getUserIdSystem, BeanPassport, BeanRole, BeanUser, CacheRedisAuthToken, EventActivate, EventCreateAnonymous, EventRegister, EventSignin, EventSignout, GuardPassport, GuardRoleName, GuardUserName, MetaPrintTip, Passport, ScopeModuleAUser, ServiceAuthTokenAdapter, ServiceRedisToken, config };
|
|
656
|
+
export { $getAuthIdSystem, $getUserIdSystem, BeanPassport, BeanRole, BeanUser, CacheRedisAuthToken, EventActivate, EventCreateAnonymous, EventRegister, EventSignin, EventSignout, GuardPassport, GuardRoleName, GuardUserName, Main, MetaPrintTip, Passport, ScopeModuleAUser, ServiceAuthTokenAdapter, ServiceRedisToken, config };
|
package/dist/main.d.ts
ADDED
package/dist/types/passport.d.ts
CHANGED
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.
|
|
4
|
+
"version": "5.0.40",
|
|
5
5
|
"title": "a-user",
|
|
6
6
|
"vonaModule": {
|
|
7
7
|
"dependencies": {}
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"./package.json": "./package.json"
|
|
23
23
|
},
|
|
24
24
|
"files": [
|
|
25
|
-
"
|
|
26
|
-
"
|
|
25
|
+
"assets",
|
|
26
|
+
"dist"
|
|
27
27
|
],
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"clean-package": "^2.2.0",
|