vona-module-a-user 5.0.23 → 5.0.25
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 +32 -13
- package/dist/bean/bean.passport.d.ts +1 -1
- package/dist/bean/{bean.roleInner.d.ts → bean.role.d.ts} +3 -3
- package/dist/bean/{bean.userInner.d.ts → bean.user.d.ts} +3 -3
- package/dist/bean/cacheRedis.authToken.d.ts +5 -0
- package/dist/config/config.d.ts +2 -6
- package/dist/index.js +78 -146
- package/dist/lib/auth.d.ts +1 -3
- package/dist/lib/index.d.ts +0 -1
- package/dist/lib/user.d.ts +1 -11
- package/dist/service/redisToken.d.ts +1 -2
- package/dist/types/auth.d.ts +8 -6
- package/dist/types/role.d.ts +1 -4
- package/dist/types/user.d.ts +7 -10
- package/package.json +1 -1
- package/dist/bean/bean.authInner.d.ts +0 -7
- package/dist/lib/role.d.ts +0 -5
|
@@ -37,36 +37,31 @@ declare module 'vona-module-a-user' {
|
|
|
37
37
|
}
|
|
38
38
|
/** guard: end */
|
|
39
39
|
/** bean: begin */
|
|
40
|
-
export * from '../bean/bean.authInner.ts';
|
|
41
40
|
export * from '../bean/bean.passport.ts';
|
|
42
|
-
export * from '../bean/bean.
|
|
43
|
-
export * from '../bean/bean.
|
|
41
|
+
export * from '../bean/bean.role.ts';
|
|
42
|
+
export * from '../bean/bean.user.ts';
|
|
44
43
|
import 'vona';
|
|
45
44
|
declare module 'vona' {
|
|
46
45
|
}
|
|
47
46
|
declare module 'vona-module-a-user' {
|
|
48
|
-
interface BeanAuthInner {
|
|
49
|
-
}
|
|
50
47
|
interface BeanPassport {
|
|
51
48
|
}
|
|
52
|
-
interface
|
|
49
|
+
interface BeanRole {
|
|
53
50
|
}
|
|
54
|
-
interface
|
|
51
|
+
interface BeanUser {
|
|
55
52
|
}
|
|
56
53
|
}
|
|
57
54
|
/** bean: end */
|
|
58
55
|
/** bean: begin */
|
|
59
|
-
import type { BeanAuthInner } from '../bean/bean.authInner.ts';
|
|
60
56
|
import type { BeanPassport } from '../bean/bean.passport.ts';
|
|
61
|
-
import type {
|
|
62
|
-
import type {
|
|
57
|
+
import type { BeanRole } from '../bean/bean.role.ts';
|
|
58
|
+
import type { BeanUser } from '../bean/bean.user.ts';
|
|
63
59
|
import 'vona';
|
|
64
60
|
declare module 'vona' {
|
|
65
61
|
interface IBeanRecordGlobal {
|
|
66
|
-
'authInner': BeanAuthInner;
|
|
67
62
|
'passport': BeanPassport;
|
|
68
|
-
'
|
|
69
|
-
'
|
|
63
|
+
'role': BeanRole;
|
|
64
|
+
'user': BeanUser;
|
|
70
65
|
}
|
|
71
66
|
}
|
|
72
67
|
/** bean: end */
|
|
@@ -112,6 +107,29 @@ declare module 'vona' {
|
|
|
112
107
|
}
|
|
113
108
|
}
|
|
114
109
|
/** service: end */
|
|
110
|
+
/** cacheRedis: begin */
|
|
111
|
+
export * from '../bean/cacheRedis.authToken.ts';
|
|
112
|
+
import { type IDecoratorCacheRedisOptions } from 'vona-module-a-cache';
|
|
113
|
+
declare module 'vona-module-a-cache' {
|
|
114
|
+
interface ICacheRedisRecord {
|
|
115
|
+
'a-user:authToken': IDecoratorCacheRedisOptions;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
declare module 'vona-module-a-user' {
|
|
119
|
+
interface CacheRedisAuthToken {
|
|
120
|
+
}
|
|
121
|
+
interface CacheRedisAuthToken {
|
|
122
|
+
get $beanFullName(): 'a-user.cacheRedis.authToken';
|
|
123
|
+
get $onionName(): 'a-user:authToken';
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/** cacheRedis: end */
|
|
127
|
+
/** cacheRedis: begin */
|
|
128
|
+
import type { CacheRedisAuthToken } from '../bean/cacheRedis.authToken.ts';
|
|
129
|
+
export interface IModuleCacheRedis {
|
|
130
|
+
'authToken': CacheRedisAuthToken;
|
|
131
|
+
}
|
|
132
|
+
/** cacheRedis: end */
|
|
115
133
|
/** event: begin */
|
|
116
134
|
export * from '../bean/event.activate.ts';
|
|
117
135
|
export * from '../bean/event.createUserAnonymous.ts';
|
|
@@ -214,6 +232,7 @@ export interface ScopeModuleAUser {
|
|
|
214
232
|
util: BeanScopeUtil;
|
|
215
233
|
config: TypeModuleConfig<typeof config>;
|
|
216
234
|
service: IModuleService;
|
|
235
|
+
cacheRedis: IModuleCacheRedis;
|
|
217
236
|
event: IModuleEvent;
|
|
218
237
|
}
|
|
219
238
|
import 'vona';
|
|
@@ -24,7 +24,7 @@ export declare class BeanPassport extends BeanBase {
|
|
|
24
24
|
signinMock(name?: keyof IUserNameRecord, options?: ISigninOptions): Promise<IJwtToken>;
|
|
25
25
|
signinWithAnonymous(): Promise<void>;
|
|
26
26
|
createUserAnonymous(): Promise<IUserBase>;
|
|
27
|
-
kickOut(user
|
|
27
|
+
kickOut(user?: IUserBase): Promise<void>;
|
|
28
28
|
checkAuthToken(accessToken?: string, clientName?: keyof IJwtClientRecord, options?: IJwtVerifyOptions): Promise<IPayloadDataBase | undefined>;
|
|
29
29
|
refreshAuthToken(refreshToken: string): Promise<IJwtToken>;
|
|
30
30
|
createTempAuthToken(options?: IJwtSignOptions): Promise<string>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { TableIdentity } from 'table-identity';
|
|
2
2
|
import type { IRoleBase } from '../types/role.ts';
|
|
3
3
|
import { BeanBase } from 'vona';
|
|
4
|
-
export declare class
|
|
5
|
-
private
|
|
6
|
-
private get
|
|
4
|
+
export declare class BeanRole extends BeanBase {
|
|
5
|
+
private _roleAdapter;
|
|
6
|
+
private get roleAdapter();
|
|
7
7
|
findOneByName(name: string): Promise<IRoleBase | undefined>;
|
|
8
8
|
findOne(role: Partial<IRoleBase>): Promise<IRoleBase | undefined>;
|
|
9
9
|
findAllByUserId(userId: TableIdentity): Promise<IRoleBase[] | undefined>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { IAuthUserProfile } from '../types/authProfile.ts';
|
|
2
2
|
import type { IUserBase } from '../types/user.ts';
|
|
3
3
|
import { BeanBase } from 'vona';
|
|
4
|
-
export declare class
|
|
5
|
-
private
|
|
6
|
-
private get
|
|
4
|
+
export declare class BeanUser extends BeanBase {
|
|
5
|
+
private _userAdapter;
|
|
6
|
+
private get userAdapter();
|
|
7
7
|
activate(user: IUserBase): Promise<void>;
|
|
8
8
|
register(user: Partial<IUserBase>, confirmed?: boolean): Promise<IUserBase>;
|
|
9
9
|
registerByProfile(profile: IAuthUserProfile): Promise<IUserBase>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { BeanCacheRedisBase } from 'vona-module-a-cache';
|
|
2
|
+
export type TCacheRedisAuthTokenKey = string;
|
|
3
|
+
export type TCacheRedisAuthTokenData = string;
|
|
4
|
+
export declare class CacheRedisAuthToken extends BeanCacheRedisBase<TCacheRedisAuthTokenKey, TCacheRedisAuthTokenData> {
|
|
5
|
+
}
|
package/dist/config/config.d.ts
CHANGED
|
@@ -11,9 +11,8 @@ export declare function config(_app: VonaApplication): {
|
|
|
11
11
|
adapter: {
|
|
12
12
|
authToken: keyof IServiceRecord;
|
|
13
13
|
passport: keyof IServiceRecord;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
roleInner: keyof IServiceRecord;
|
|
14
|
+
user: keyof IServiceRecord;
|
|
15
|
+
role: keyof IServiceRecord;
|
|
17
16
|
};
|
|
18
17
|
payloadData: {
|
|
19
18
|
fields: {
|
|
@@ -22,7 +21,4 @@ export declare function config(_app: VonaApplication): {
|
|
|
22
21
|
token: string;
|
|
23
22
|
};
|
|
24
23
|
};
|
|
25
|
-
redisToken: {
|
|
26
|
-
maxAge: number;
|
|
27
|
-
};
|
|
28
24
|
};
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import { BeanInfo, BeanBase, beanFullNameFromOnionName, createHash, uuidv4, Bean
|
|
|
2
2
|
import { catchError } from '@cabloy/utils';
|
|
3
3
|
import { Guard, Aspect } from 'vona-module-a-aspect';
|
|
4
4
|
import { Bean, Service, Scope } from 'vona-module-a-bean';
|
|
5
|
+
import { CacheRedis, BeanCacheRedisBase } from 'vona-module-a-cache';
|
|
5
6
|
import { Event, BeanEventBase } from 'vona-module-a-event';
|
|
6
7
|
import { Meta } from 'vona-module-a-meta';
|
|
7
8
|
|
|
@@ -49,49 +50,6 @@ let GuardPassport = (_dec$f = Guard({
|
|
|
49
50
|
}
|
|
50
51
|
}) || _class$f) || _class$f);
|
|
51
52
|
|
|
52
|
-
let __roleAdapter;
|
|
53
|
-
function setRoleAdapter(roleAdapter) {
|
|
54
|
-
__roleAdapter = roleAdapter;
|
|
55
|
-
}
|
|
56
|
-
function $getRoleId(role) {
|
|
57
|
-
return __roleAdapter.getRoleId(role);
|
|
58
|
-
}
|
|
59
|
-
function $getRoleName(role) {
|
|
60
|
-
return __roleAdapter.getRoleName(role);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
let __userAdapter;
|
|
64
|
-
function setUserAdapter(userAdapter) {
|
|
65
|
-
__userAdapter = userAdapter;
|
|
66
|
-
}
|
|
67
|
-
function $getUserId(user) {
|
|
68
|
-
return __userAdapter.getUserId(user);
|
|
69
|
-
}
|
|
70
|
-
function $getUserName(user) {
|
|
71
|
-
return __userAdapter.getUserName(user);
|
|
72
|
-
}
|
|
73
|
-
function $getUserAvatar(user) {
|
|
74
|
-
return __userAdapter.getUserAvatar(user);
|
|
75
|
-
}
|
|
76
|
-
function $getUserEmail(user) {
|
|
77
|
-
return __userAdapter.getUserEmail(user);
|
|
78
|
-
}
|
|
79
|
-
function $getUserMobile(user) {
|
|
80
|
-
return __userAdapter.getUserMobile(user);
|
|
81
|
-
}
|
|
82
|
-
function $getUserActivated(user) {
|
|
83
|
-
return __userAdapter.getUserActivated(user);
|
|
84
|
-
}
|
|
85
|
-
function $getUserLocale(user) {
|
|
86
|
-
return __userAdapter.getUserLocale(user);
|
|
87
|
-
}
|
|
88
|
-
function $getUserAnonymous(user) {
|
|
89
|
-
return __userAdapter.getUserAnonymous(user);
|
|
90
|
-
}
|
|
91
|
-
function $getUserIdSystem(_userName, userId) {
|
|
92
|
-
return userId;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
53
|
var _dec$e, _dec2$e, _class$e;
|
|
96
54
|
let GuardRoleName = (_dec$e = Guard({
|
|
97
55
|
passWhenMatched: true
|
|
@@ -101,10 +59,10 @@ let GuardRoleName = (_dec$e = Guard({
|
|
|
101
59
|
async execute(options, next) {
|
|
102
60
|
if (!options.name) return this.app.throw(403);
|
|
103
61
|
const user = this.bean.passport.getCurrentUser();
|
|
104
|
-
if (!user ||
|
|
62
|
+
if (!user || user.anonymous) return this.app.throw(403);
|
|
105
63
|
const roles = this.bean.passport.getCurrentRoles();
|
|
106
64
|
if (!roles) return this.app.throw(403);
|
|
107
|
-
const roleNames = roles?.map(item =>
|
|
65
|
+
const roleNames = roles?.map(item => item.name);
|
|
108
66
|
const optionsName = Array.isArray(options.name) ? options.name : [options.name];
|
|
109
67
|
if (!roleNames.some(roleName => optionsName.includes(roleName))) return this.app.throw(403);
|
|
110
68
|
if (options.passWhenMatched) return true;
|
|
@@ -122,8 +80,8 @@ let GuardUserName = (_dec$d = Guard({
|
|
|
122
80
|
async execute(options, next) {
|
|
123
81
|
if (!options.name) return this.app.throw(403);
|
|
124
82
|
const user = this.bean.passport.getCurrentUser();
|
|
125
|
-
if (!user ||
|
|
126
|
-
const userName =
|
|
83
|
+
if (!user || user.anonymous) return this.app.throw(403);
|
|
84
|
+
const userName = user.name;
|
|
127
85
|
const optionsName = Array.isArray(options.name) ? options.name : [options.name];
|
|
128
86
|
if (!optionsName.includes(userName)) return this.app.throw(403);
|
|
129
87
|
if (options.passWhenMatched) return true;
|
|
@@ -132,42 +90,14 @@ let GuardUserName = (_dec$d = Guard({
|
|
|
132
90
|
}
|
|
133
91
|
}) || _class$d) || _class$d);
|
|
134
92
|
|
|
135
|
-
var _dec$c, _dec2$c, _class$c;
|
|
136
|
-
let BeanAuthInner = (_dec$c = Bean(), _dec2$c = BeanInfo({
|
|
137
|
-
module: "a-user"
|
|
138
|
-
}), _dec$c(_class$c = _dec2$c(_class$c = class BeanAuthInner extends BeanBase {
|
|
139
|
-
constructor(...args) {
|
|
140
|
-
super(...args);
|
|
141
|
-
this._authInnerAdapter = void 0;
|
|
142
|
-
}
|
|
143
|
-
get authInnerAdapter() {
|
|
144
|
-
if (!this._authInnerAdapter) {
|
|
145
|
-
const beanFullName = beanFullNameFromOnionName(this.scope.config.adapter.authInner, 'service');
|
|
146
|
-
this._authInnerAdapter = this.bean._getBean(beanFullName);
|
|
147
|
-
}
|
|
148
|
-
return this._authInnerAdapter;
|
|
149
|
-
}
|
|
150
|
-
async findOne(auth) {
|
|
151
|
-
if (String(auth.id).charAt(0) === '-') return auth;
|
|
152
|
-
return await this.authInnerAdapter.findOne(auth);
|
|
153
|
-
}
|
|
154
|
-
}) || _class$c) || _class$c);
|
|
155
|
-
|
|
156
|
-
let __authAdapter;
|
|
157
|
-
function setAuthAdapter(authAdapter) {
|
|
158
|
-
__authAdapter = authAdapter;
|
|
159
|
-
}
|
|
160
|
-
function $getAuthId(user) {
|
|
161
|
-
return __authAdapter.getAuthId(user);
|
|
162
|
-
}
|
|
163
93
|
function $getAuthIdSystem(_authName, authId) {
|
|
164
94
|
return authId;
|
|
165
95
|
}
|
|
166
96
|
|
|
167
|
-
var _dec$
|
|
168
|
-
let BeanPassport = (_dec$
|
|
97
|
+
var _dec$c, _dec2$c, _class$c;
|
|
98
|
+
let BeanPassport = (_dec$c = Bean(), _dec2$c = BeanInfo({
|
|
169
99
|
module: "a-user"
|
|
170
|
-
}), _dec$
|
|
100
|
+
}), _dec$c(_class$c = _dec2$c(_class$c = class BeanPassport extends BeanBase {
|
|
171
101
|
constructor(...args) {
|
|
172
102
|
super(...args);
|
|
173
103
|
this._authTokenAdapter = void 0;
|
|
@@ -190,11 +120,11 @@ let BeanPassport = (_dec$b = Bean(), _dec2$b = BeanInfo({
|
|
|
190
120
|
}
|
|
191
121
|
get isAuthenticated() {
|
|
192
122
|
const user = this.getCurrentUser();
|
|
193
|
-
return !!user &&
|
|
123
|
+
return !!user && !user.anonymous;
|
|
194
124
|
}
|
|
195
125
|
get isActivated() {
|
|
196
126
|
const user = this.getCurrentUser();
|
|
197
|
-
return !!user &&
|
|
127
|
+
return !!user && !!user.activated;
|
|
198
128
|
}
|
|
199
129
|
async isAdmin() {
|
|
200
130
|
const passport = this.getCurrent();
|
|
@@ -240,7 +170,7 @@ let BeanPassport = (_dec$b = Bean(), _dec2$b = BeanInfo({
|
|
|
240
170
|
await this.setCurrent(undefined);
|
|
241
171
|
}
|
|
242
172
|
async signinSystem(authName, authId, name, options) {
|
|
243
|
-
const user = await this.bean.
|
|
173
|
+
const user = await this.bean.user.findOneByName(name ?? 'admin');
|
|
244
174
|
if (!user) return this.app.throw(401);
|
|
245
175
|
const auth = {
|
|
246
176
|
id: $getAuthIdSystem(authName, authId)
|
|
@@ -263,13 +193,14 @@ let BeanPassport = (_dec$b = Bean(), _dec2$b = BeanInfo({
|
|
|
263
193
|
await this.setCurrent(passport);
|
|
264
194
|
}
|
|
265
195
|
async createUserAnonymous() {
|
|
266
|
-
const userAnonymous = await this.bean.
|
|
196
|
+
const userAnonymous = await this.bean.user.createAnonymous();
|
|
267
197
|
// event
|
|
268
198
|
await this.scope.event.createUserAnonymous.emit(userAnonymous);
|
|
269
199
|
// ok
|
|
270
200
|
return userAnonymous;
|
|
271
201
|
}
|
|
272
202
|
async kickOut(user) {
|
|
203
|
+
if (!user) return;
|
|
273
204
|
await this.authTokenAdapter.removeAll(user);
|
|
274
205
|
}
|
|
275
206
|
async checkAuthToken(accessToken, clientName, options) {
|
|
@@ -373,52 +304,52 @@ let BeanPassport = (_dec$b = Bean(), _dec2$b = BeanInfo({
|
|
|
373
304
|
return payloadData2;
|
|
374
305
|
}
|
|
375
306
|
}
|
|
376
|
-
}) || _class$
|
|
307
|
+
}) || _class$c) || _class$c);
|
|
377
308
|
|
|
378
|
-
var _dec$
|
|
379
|
-
let
|
|
309
|
+
var _dec$b, _dec2$b, _class$b;
|
|
310
|
+
let BeanRole = (_dec$b = Bean(), _dec2$b = BeanInfo({
|
|
380
311
|
module: "a-user"
|
|
381
|
-
}), _dec$
|
|
312
|
+
}), _dec$b(_class$b = _dec2$b(_class$b = class BeanRole extends BeanBase {
|
|
382
313
|
constructor(...args) {
|
|
383
314
|
super(...args);
|
|
384
|
-
this.
|
|
315
|
+
this._roleAdapter = void 0;
|
|
385
316
|
}
|
|
386
|
-
get
|
|
387
|
-
if (!this.
|
|
388
|
-
const beanFullName = beanFullNameFromOnionName(this.scope.config.adapter.
|
|
389
|
-
this.
|
|
317
|
+
get roleAdapter() {
|
|
318
|
+
if (!this._roleAdapter) {
|
|
319
|
+
const beanFullName = beanFullNameFromOnionName(this.scope.config.adapter.role, 'service');
|
|
320
|
+
this._roleAdapter = this.bean._getBean(beanFullName);
|
|
390
321
|
}
|
|
391
|
-
return this.
|
|
322
|
+
return this._roleAdapter;
|
|
392
323
|
}
|
|
393
324
|
findOneByName(name) {
|
|
394
|
-
return this.
|
|
325
|
+
return this.roleAdapter.findOneByName(name);
|
|
395
326
|
}
|
|
396
327
|
findOne(role) {
|
|
397
|
-
return this.
|
|
328
|
+
return this.roleAdapter.findOne(role);
|
|
398
329
|
}
|
|
399
330
|
findAllByUserId(userId) {
|
|
400
|
-
return this.
|
|
331
|
+
return this.roleAdapter.findAllByUserId(userId);
|
|
401
332
|
}
|
|
402
|
-
}) || _class$
|
|
333
|
+
}) || _class$b) || _class$b);
|
|
403
334
|
|
|
404
|
-
var _dec$
|
|
405
|
-
let
|
|
335
|
+
var _dec$a, _dec2$a, _class$a;
|
|
336
|
+
let BeanUser = (_dec$a = Bean(), _dec2$a = BeanInfo({
|
|
406
337
|
module: "a-user"
|
|
407
|
-
}), _dec$
|
|
338
|
+
}), _dec$a(_class$a = _dec2$a(_class$a = class BeanUser extends BeanBase {
|
|
408
339
|
constructor(...args) {
|
|
409
340
|
super(...args);
|
|
410
|
-
this.
|
|
341
|
+
this._userAdapter = void 0;
|
|
411
342
|
}
|
|
412
|
-
get
|
|
413
|
-
if (!this.
|
|
414
|
-
const beanFullName = beanFullNameFromOnionName(this.scope.config.adapter.
|
|
415
|
-
this.
|
|
343
|
+
get userAdapter() {
|
|
344
|
+
if (!this._userAdapter) {
|
|
345
|
+
const beanFullName = beanFullNameFromOnionName(this.scope.config.adapter.user, 'service');
|
|
346
|
+
this._userAdapter = this.bean._getBean(beanFullName);
|
|
416
347
|
}
|
|
417
|
-
return this.
|
|
348
|
+
return this._userAdapter;
|
|
418
349
|
}
|
|
419
350
|
async activate(user) {
|
|
420
351
|
await this.scope.event.activate.emit(user, async user => {
|
|
421
|
-
await this.
|
|
352
|
+
await this.userAdapter.setActivated(user.id, true);
|
|
422
353
|
});
|
|
423
354
|
}
|
|
424
355
|
async register(user, confirmed) {
|
|
@@ -431,7 +362,7 @@ let BeanUserInner = (_dec$9 = Bean(), _dec2$9 = BeanInfo({
|
|
|
431
362
|
};
|
|
432
363
|
return await this.scope.event.register.emit(data, async data => {
|
|
433
364
|
// user
|
|
434
|
-
const userNew = await this.
|
|
365
|
+
const userNew = await this.userAdapter.create(data.user);
|
|
435
366
|
if (data.autoActivate) {
|
|
436
367
|
await this.activate(userNew);
|
|
437
368
|
}
|
|
@@ -439,30 +370,30 @@ let BeanUserInner = (_dec$9 = Bean(), _dec2$9 = BeanInfo({
|
|
|
439
370
|
});
|
|
440
371
|
}
|
|
441
372
|
async registerByProfile(profile) {
|
|
442
|
-
const user = await this.
|
|
373
|
+
const user = await this.userAdapter.userOfProfile(profile);
|
|
443
374
|
return await this.register(user, profile.confirmed);
|
|
444
375
|
}
|
|
445
376
|
createAnonymous() {
|
|
446
|
-
return this.
|
|
377
|
+
return this.userAdapter.createAnonymous();
|
|
447
378
|
}
|
|
448
379
|
findOneByName(name) {
|
|
449
|
-
return this.
|
|
380
|
+
return this.userAdapter.findOneByName(name);
|
|
450
381
|
}
|
|
451
382
|
findOne(user) {
|
|
452
|
-
return this.
|
|
383
|
+
return this.userAdapter.findOne(user);
|
|
453
384
|
}
|
|
454
385
|
update(user) {
|
|
455
|
-
return this.
|
|
386
|
+
return this.userAdapter.update(user);
|
|
456
387
|
}
|
|
457
388
|
remove(user) {
|
|
458
|
-
return this.
|
|
389
|
+
return this.userAdapter.remove(user);
|
|
459
390
|
}
|
|
460
|
-
}) || _class$
|
|
391
|
+
}) || _class$a) || _class$a);
|
|
461
392
|
|
|
462
|
-
var _dec$
|
|
463
|
-
let ServiceAuthTokenAdapter = (_dec$
|
|
393
|
+
var _dec$9, _dec2$9, _class$9;
|
|
394
|
+
let ServiceAuthTokenAdapter = (_dec$9 = Service(), _dec2$9 = BeanInfo({
|
|
464
395
|
module: "a-user"
|
|
465
|
-
}), _dec$
|
|
396
|
+
}), _dec$9(_class$9 = _dec2$9(_class$9 = class ServiceAuthTokenAdapter extends BeanBase {
|
|
466
397
|
async create(payloadData) {
|
|
467
398
|
const authIdStr = this._getAuthId(payloadData)?.toString();
|
|
468
399
|
const token = authIdStr === '-1' ? createHash(authIdStr) : uuidv4();
|
|
@@ -490,15 +421,12 @@ let ServiceAuthTokenAdapter = (_dec$8 = Service(), _dec2$8 = BeanInfo({
|
|
|
490
421
|
_getAuthId(payloadData) {
|
|
491
422
|
return payloadData[this.scope.config.payloadData.fields.authId];
|
|
492
423
|
}
|
|
493
|
-
}) || _class$
|
|
424
|
+
}) || _class$9) || _class$9);
|
|
494
425
|
|
|
495
|
-
var _dec$
|
|
496
|
-
let ServiceRedisToken = (_dec$
|
|
426
|
+
var _dec$8, _dec2$8, _class$8;
|
|
427
|
+
let ServiceRedisToken = (_dec$8 = Service(), _dec2$8 = BeanInfo({
|
|
497
428
|
module: "a-user"
|
|
498
|
-
}), _dec$
|
|
499
|
-
get redisAuth() {
|
|
500
|
-
return this.bean.redis.get('auth');
|
|
501
|
-
}
|
|
429
|
+
}), _dec$8(_class$8 = _dec2$8(_class$8 = class ServiceRedisToken extends BeanBase {
|
|
502
430
|
async verify(payloadData) {
|
|
503
431
|
const payloadData2 = await this.retrieve(payloadData);
|
|
504
432
|
if (!payloadData2) return false;
|
|
@@ -508,7 +436,7 @@ let ServiceRedisToken = (_dec$7 = Service(), _dec2$7 = BeanInfo({
|
|
|
508
436
|
async retrieve(payloadData) {
|
|
509
437
|
const key = this._getAuthRedisKey(payloadData);
|
|
510
438
|
if (!key) return;
|
|
511
|
-
const token = await this.
|
|
439
|
+
const token = await this.scope.cacheRedis.authToken.get(key);
|
|
512
440
|
if (!token) return;
|
|
513
441
|
return {
|
|
514
442
|
...payloadData,
|
|
@@ -518,33 +446,29 @@ let ServiceRedisToken = (_dec$7 = Service(), _dec2$7 = BeanInfo({
|
|
|
518
446
|
async create(payloadData) {
|
|
519
447
|
const key = this._getAuthRedisKey(payloadData);
|
|
520
448
|
if (!key || !this._getToken(payloadData)) return this.app.throw(401);
|
|
521
|
-
await this.
|
|
449
|
+
await this.scope.cacheRedis.authToken.set(this._getToken(payloadData), key);
|
|
522
450
|
}
|
|
523
451
|
async refresh(payloadData) {
|
|
524
452
|
const key = this._getAuthRedisKey(payloadData);
|
|
525
453
|
if (!key) return this.app.throw(401);
|
|
526
|
-
await this.
|
|
454
|
+
await this.scope.cacheRedis.authToken.expire(key);
|
|
527
455
|
}
|
|
528
456
|
async remove(payloadData) {
|
|
529
457
|
const key = this._getAuthRedisKey(payloadData);
|
|
530
458
|
if (!key) return;
|
|
531
|
-
await this.
|
|
459
|
+
await this.scope.cacheRedis.authToken.del(key);
|
|
532
460
|
}
|
|
533
461
|
async removeAll(user) {
|
|
534
|
-
const keyPrefix = this.
|
|
535
|
-
const
|
|
536
|
-
|
|
537
|
-
for (const fullKey of keys) {
|
|
538
|
-
const key = keyPrefix ? fullKey.substring(keyPrefix.length) : fullKey;
|
|
539
|
-
await this.redisAuth.del(key);
|
|
540
|
-
}
|
|
462
|
+
const keyPrefix = this._getAuthRedisKeyPrefix(user);
|
|
463
|
+
const keys = await this.scope.cacheRedis.authToken.lookupKeys(keyPrefix, true);
|
|
464
|
+
await this.scope.cacheRedis.authToken.mdel(keys);
|
|
541
465
|
}
|
|
542
466
|
_getAuthRedisKey(payloadData) {
|
|
543
467
|
if (!this.ctx.instance) return;
|
|
544
|
-
return
|
|
468
|
+
return `${this._getUserId(payloadData)}:${this._getAuthId(payloadData)}`;
|
|
545
469
|
}
|
|
546
|
-
|
|
547
|
-
return `${
|
|
470
|
+
_getAuthRedisKeyPrefix(user) {
|
|
471
|
+
return `${user.id}`;
|
|
548
472
|
}
|
|
549
473
|
_getToken(payloadData) {
|
|
550
474
|
return payloadData[this.scope.config.payloadData.fields.token];
|
|
@@ -555,7 +479,15 @@ let ServiceRedisToken = (_dec$7 = Service(), _dec2$7 = BeanInfo({
|
|
|
555
479
|
_getUserId(payloadData) {
|
|
556
480
|
return payloadData[this.scope.config.payloadData.fields.userId];
|
|
557
481
|
}
|
|
558
|
-
}) || _class$
|
|
482
|
+
}) || _class$8) || _class$8);
|
|
483
|
+
|
|
484
|
+
var _dec$7, _dec2$7, _class$7;
|
|
485
|
+
let CacheRedisAuthToken = (_dec$7 = CacheRedis({
|
|
486
|
+
ttl: 30 * 24 * 60 * 60 * 1000,
|
|
487
|
+
disableTransactionCompensate: true
|
|
488
|
+
}), _dec2$7 = BeanInfo({
|
|
489
|
+
module: "a-user"
|
|
490
|
+
}), _dec$7(_class$7 = _dec2$7(_class$7 = class CacheRedisAuthToken extends BeanCacheRedisBase {}) || _class$7) || _class$7);
|
|
559
491
|
|
|
560
492
|
var _dec$6, _dec2$6, _class$6;
|
|
561
493
|
let EventActivate = (_dec$6 = Event(), _dec2$6 = BeanInfo({
|
|
@@ -613,9 +545,8 @@ function config(_app) {
|
|
|
613
545
|
adapter: {
|
|
614
546
|
authToken: 'a-user:authTokenAdapter',
|
|
615
547
|
passport: 'home-user:passportAdapter',
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
roleInner: 'home-user:roleInnerAdapter'
|
|
548
|
+
user: 'home-user:userAdapter',
|
|
549
|
+
role: 'home-user:roleAdapter'
|
|
619
550
|
},
|
|
620
551
|
payloadData: {
|
|
621
552
|
fields: {
|
|
@@ -623,9 +554,6 @@ function config(_app) {
|
|
|
623
554
|
userId: 'userId',
|
|
624
555
|
token: 'token'
|
|
625
556
|
}
|
|
626
|
-
},
|
|
627
|
-
redisToken: {
|
|
628
|
-
maxAge: 30 * 24 * 60 * 60
|
|
629
557
|
}
|
|
630
558
|
};
|
|
631
559
|
}
|
|
@@ -668,4 +596,8 @@ const Passport = {
|
|
|
668
596
|
admin: Admin
|
|
669
597
|
};
|
|
670
598
|
|
|
671
|
-
|
|
599
|
+
function $getUserIdSystem(_userName, userId) {
|
|
600
|
+
return userId;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
export { $getAuthIdSystem, $getUserIdSystem, BeanPassport, BeanRole, BeanUser, CacheRedisAuthToken, EventActivate, EventCreateUserAnonymous, EventRegister, EventSignin, EventSignout, GuardPassport, GuardRoleName, GuardUserName, MetaPrintTip, Passport, ScopeModuleAUser, ServiceAuthTokenAdapter, ServiceRedisToken, config };
|
package/dist/lib/auth.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
import type { TableIdentity } from 'table-identity';
|
|
2
|
-
import type {
|
|
3
|
-
export declare function setAuthAdapter(authAdapter: IAuthAdapter): void;
|
|
4
|
-
export declare function $getAuthId(user: IAuthBase): TableIdentity;
|
|
2
|
+
import type { IAuthIdRecord } from '../types/auth.ts';
|
|
5
3
|
export declare function $getAuthIdSystem<K extends keyof IAuthIdRecord>(_authName: IAuthIdRecord[K], authId: K): TableIdentity;
|
package/dist/lib/index.d.ts
CHANGED
package/dist/lib/user.d.ts
CHANGED
|
@@ -1,13 +1,3 @@
|
|
|
1
1
|
import type { TableIdentity } from 'table-identity';
|
|
2
|
-
import type {
|
|
3
|
-
import type { IUserAdapter, IUserBase, IUserIdRecord } from '../types/user.ts';
|
|
4
|
-
export declare function setUserAdapter(userAdapter: IUserAdapter): void;
|
|
5
|
-
export declare function $getUserId(user: IUserBase): TableIdentity;
|
|
6
|
-
export declare function $getUserName(user: IUserBase): string;
|
|
7
|
-
export declare function $getUserAvatar(user: IUserBase): string | undefined;
|
|
8
|
-
export declare function $getUserEmail(user: IUserBase): string | undefined;
|
|
9
|
-
export declare function $getUserMobile(user: IUserBase): string | undefined;
|
|
10
|
-
export declare function $getUserActivated(user: IUserBase): boolean;
|
|
11
|
-
export declare function $getUserLocale(user: IUserBase): keyof ILocaleInfos | undefined;
|
|
12
|
-
export declare function $getUserAnonymous(user: IUserBase): boolean;
|
|
2
|
+
import type { IUserIdRecord } from '../types/user.ts';
|
|
13
3
|
export declare function $getUserIdSystem<K extends keyof IUserIdRecord>(_userName: IUserIdRecord[K], userId: K): TableIdentity;
|
|
@@ -2,7 +2,6 @@ import type { IPayloadDataBase } from 'vona-module-a-jwt';
|
|
|
2
2
|
import type { IUserBase } from 'vona-module-a-user';
|
|
3
3
|
import { BeanBase } from 'vona';
|
|
4
4
|
export declare class ServiceRedisToken extends BeanBase {
|
|
5
|
-
private get redisAuth();
|
|
6
5
|
verify(payloadData: IPayloadDataBase): Promise<boolean>;
|
|
7
6
|
retrieve(payloadData: IPayloadDataBase): Promise<IPayloadDataBase | undefined>;
|
|
8
7
|
create(payloadData: IPayloadDataBase): Promise<undefined>;
|
|
@@ -10,7 +9,7 @@ export declare class ServiceRedisToken extends BeanBase {
|
|
|
10
9
|
remove(payloadData: IPayloadDataBase): Promise<void>;
|
|
11
10
|
removeAll(user: IUserBase): Promise<void>;
|
|
12
11
|
private _getAuthRedisKey;
|
|
13
|
-
private
|
|
12
|
+
private _getAuthRedisKeyPrefix;
|
|
14
13
|
private _getToken;
|
|
15
14
|
private _getAuthId;
|
|
16
15
|
private _getUserId;
|
package/dist/types/auth.d.ts
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import type { TableIdentity } from 'table-identity';
|
|
2
|
+
import type { IAuthProviderRecord } from 'vona-module-a-auth';
|
|
2
3
|
export interface IAuthIdRecord {
|
|
3
4
|
'-1': 'dev';
|
|
4
5
|
'-10000': 'mock';
|
|
5
6
|
}
|
|
6
|
-
export interface
|
|
7
|
+
export interface IAuthProviderBase {
|
|
7
8
|
id: TableIdentity;
|
|
9
|
+
providerName: keyof IAuthProviderRecord;
|
|
10
|
+
clientName: string;
|
|
8
11
|
}
|
|
9
|
-
export interface
|
|
10
|
-
|
|
12
|
+
export interface IAuthBase {
|
|
13
|
+
id: TableIdentity;
|
|
14
|
+
profileId?: string;
|
|
15
|
+
authProvider?: IAuthProviderBase;
|
|
11
16
|
}
|
|
12
17
|
export type TypeAuthToken = 'recreate' | 'refresh' | 'nochange';
|
|
13
18
|
export interface ISigninOptions {
|
|
14
19
|
/** default: refresh */
|
|
15
20
|
authToken?: TypeAuthToken;
|
|
16
21
|
}
|
|
17
|
-
export interface IAuthInnerAdapter {
|
|
18
|
-
findOne(auth: Partial<IAuthBase>): Promise<IAuthBase | undefined>;
|
|
19
|
-
}
|
package/dist/types/role.d.ts
CHANGED
|
@@ -6,12 +6,9 @@ export interface IRoleIdRecord {
|
|
|
6
6
|
}
|
|
7
7
|
export interface IRoleBase {
|
|
8
8
|
id: TableIdentity;
|
|
9
|
+
name: string;
|
|
9
10
|
}
|
|
10
11
|
export interface IRoleAdapter {
|
|
11
|
-
getRoleId(role: IRoleBase): TableIdentity;
|
|
12
|
-
getRoleName(role: IRoleBase): string;
|
|
13
|
-
}
|
|
14
|
-
export interface IRoleInnerAdapter {
|
|
15
12
|
findOneByName(name: string): Promise<IRoleBase | undefined>;
|
|
16
13
|
findOne(role: Partial<IRoleBase>): Promise<IRoleBase | undefined>;
|
|
17
14
|
findAllByUserId(userId: TableIdentity): Promise<IRoleBase[] | undefined>;
|
package/dist/types/user.d.ts
CHANGED
|
@@ -9,18 +9,15 @@ export interface IUserIdRecord {
|
|
|
9
9
|
}
|
|
10
10
|
export interface IUserBase {
|
|
11
11
|
id: TableIdentity;
|
|
12
|
+
name: string;
|
|
13
|
+
avatar?: string;
|
|
14
|
+
email?: string;
|
|
15
|
+
mobile?: string;
|
|
16
|
+
activated?: boolean;
|
|
17
|
+
locale?: keyof ILocaleInfos | undefined;
|
|
18
|
+
anonymous?: boolean;
|
|
12
19
|
}
|
|
13
20
|
export interface IUserAdapter {
|
|
14
|
-
getUserId(user: IUserBase): TableIdentity;
|
|
15
|
-
getUserName(user: IUserBase): string;
|
|
16
|
-
getUserAvatar(user: IUserBase): string | undefined;
|
|
17
|
-
getUserEmail(user: IUserBase): string | undefined;
|
|
18
|
-
getUserMobile(user: IUserBase): string | undefined;
|
|
19
|
-
getUserActivated(user: IUserBase): boolean;
|
|
20
|
-
getUserLocale(user: IUserBase): keyof ILocaleInfos | undefined;
|
|
21
|
-
getUserAnonymous(user: IUserBase): boolean;
|
|
22
|
-
}
|
|
23
|
-
export interface IUserInnerAdapter {
|
|
24
21
|
create(user: Partial<IUserBase>): Promise<IUserBase>;
|
|
25
22
|
userOfProfile(profile: IAuthUserProfile): Promise<IUserBase>;
|
|
26
23
|
createAnonymous(): Promise<IUserBase>;
|
package/package.json
CHANGED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { IAuthBase } from '../types/auth.ts';
|
|
2
|
-
import { BeanBase } from 'vona';
|
|
3
|
-
export declare class BeanAuthInner extends BeanBase {
|
|
4
|
-
private _authInnerAdapter;
|
|
5
|
-
private get authInnerAdapter();
|
|
6
|
-
findOne(auth: Partial<IAuthBase>): Promise<IAuthBase | undefined>;
|
|
7
|
-
}
|
package/dist/lib/role.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { TableIdentity } from 'table-identity';
|
|
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;
|