vona-cli-set-api 1.0.270 → 1.0.271

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.
@@ -1,26 +1,28 @@
1
- import type { IPassportAdapter, IPassportBase } from 'vona-module-a-user';
2
- import type { IPayloadData } from '../types/passport.ts';
1
+ import type { IPassportAdapter } from 'vona-module-a-user';
2
+ import type { IPassport, IPayloadData } from '../types/passport.ts';
3
3
  import { BeanBase } from 'vona';
4
4
  import { Service } from 'vona-module-a-bean';
5
5
 
6
6
  @Service()
7
7
  export class ServicePassportAdapter extends BeanBase implements IPassportAdapter {
8
- async isAdmin(passport: IPassportBase | undefined): Promise<boolean> {
9
- if (!passport || !passport.roles) return false;
10
- return passport.roles.some(item => item.name === 'admin');
8
+ async isAdmin(passport: IPassport | undefined): Promise<boolean> {
9
+ if (!passport) return false;
10
+ if (passport.user?.name === 'admin') return true;
11
+ if (passport.roles?.some(role => role.name === 'admin')) return true;
12
+ return false;
11
13
  }
12
14
 
13
- async setCurrent(passport: IPassportBase | undefined): Promise<IPassportBase | undefined> {
15
+ async setCurrent(passport: IPassport | undefined): Promise<IPassport | undefined> {
14
16
  return passport;
15
17
  }
16
18
 
17
- async serialize(passport: IPassportBase): Promise<IPayloadData> {
19
+ async serialize(passport: IPassport): Promise<IPayloadData> {
18
20
  const userId = passport.user!.id;
19
21
  const authId = passport.auth!.id;
20
22
  return { userId, authId };
21
23
  }
22
24
 
23
- async deserialize(payloadData: IPayloadData): Promise<IPassportBase | undefined> {
25
+ async deserialize(payloadData: IPayloadData): Promise<IPassport | undefined> {
24
26
  const user = await this.bean.user.findOne({ id: payloadData.userId });
25
27
  if (!user) return;
26
28
  const auth = await this.bean.auth.findOne({ id: payloadData.authId });
@@ -1,8 +1,11 @@
1
1
  import type { TableIdentity } from 'table-identity';
2
2
  import type { IPayloadDataBase } from 'vona-module-a-jwt';
3
+ import type { IPassportBase } from 'vona-module-a-user';
3
4
 
4
5
  export interface IPayloadData extends IPayloadDataBase {
5
6
  userId: TableIdentity;
6
7
  authId: TableIdentity;
7
8
  token?: string;
8
9
  }
10
+
11
+ export interface IPassport extends IPassportBase {}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vona-cli-set-api",
3
3
  "type": "module",
4
- "version": "1.0.270",
4
+ "version": "1.0.271",
5
5
  "description": "vona cli-set-api",
6
6
  "publishConfig": {
7
7
  "access": "public"