@things-factory/auth-base 7.0.0-alpha.8 → 7.0.1-alpha.0

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.
@@ -5,13 +5,13 @@ import { User } from './service/user/user';
5
5
  declare global {
6
6
  export type ResolverContext = {
7
7
  state: IContextState;
8
- t: TFunction;
8
+ t?: TFunction;
9
9
  [key: string]: any;
10
10
  };
11
11
  interface IContextState {
12
12
  domain: Domain;
13
13
  user: User;
14
- tx: EntityManager;
14
+ tx?: EntityManager;
15
15
  [key: string]: any;
16
16
  }
17
17
  }
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../server/types.ts"],"names":[],"mappings":"","sourcesContent":["import { TFunction } from 'i18next'\nimport { EntityManager } from 'typeorm'\n\nimport { Domain } from '@things-factory/shell'\n\nimport { User } from './service/user/user'\n\ndeclare global {\n export type ResolverContext = {\n state: IContextState\n t: TFunction\n [key: string]: any\n }\n\n interface IContextState {\n domain: Domain\n user: User\n tx: EntityManager\n [key: string]: any\n }\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../server/types.ts"],"names":[],"mappings":"","sourcesContent":["import { TFunction } from 'i18next'\nimport { EntityManager } from 'typeorm'\n\nimport { Domain } from '@things-factory/shell'\n\nimport { User } from './service/user/user'\n\ndeclare global {\n export type ResolverContext = {\n state: IContextState\n t?: TFunction\n [key: string]: any\n }\n\n interface IContextState {\n domain: Domain\n user: User\n tx?: EntityManager\n [key: string]: any\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/auth-base",
3
- "version": "7.0.0-alpha.8",
3
+ "version": "7.0.1-alpha.0",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "dist-client/index.js",
6
6
  "things-factory": true,
@@ -30,11 +30,11 @@
30
30
  "migration:create": "node ../../node_modules/typeorm/cli.js migration:create -d ./server/migrations"
31
31
  },
32
32
  "dependencies": {
33
- "@things-factory/email-base": "^7.0.0-alpha.8",
34
- "@things-factory/env": "^7.0.0-alpha.0",
35
- "@things-factory/i18n-base": "^7.0.0-alpha.8",
36
- "@things-factory/shell": "^7.0.0-alpha.8",
37
- "@things-factory/utils": "^7.0.0-alpha.0",
33
+ "@things-factory/email-base": "^7.0.1-alpha.0",
34
+ "@things-factory/env": "^7.0.1-alpha.0",
35
+ "@things-factory/i18n-base": "^7.0.1-alpha.0",
36
+ "@things-factory/shell": "^7.0.1-alpha.0",
37
+ "@things-factory/utils": "^7.0.1-alpha.0",
38
38
  "jsonwebtoken": "^9.0.0",
39
39
  "koa-passport": "^6.0.0",
40
40
  "koa-session": "^6.4.0",
@@ -43,5 +43,5 @@
43
43
  "passport-local": "^1.0.0",
44
44
  "popsicle-cookie-jar": "^1.0.0"
45
45
  },
46
- "gitHead": "b4981ea2721e7eaf4dbd618b6c77316ebc000ee5"
46
+ "gitHead": "d18cdb7648bd2003f11278ec7bc8df74edbd31fc"
47
47
  }
@@ -19,10 +19,14 @@ declare global {
19
19
  }
20
20
 
21
21
  process.domainOwnerGranted = async (domain: Domain, user: User): Promise<boolean> => {
22
- return domain && domain.owner === user.id
22
+ return user && domain && domain.owner === user.id
23
23
  }
24
24
 
25
25
  process.superUserGranted = async (domain: Domain, user: User): Promise<boolean> => {
26
+ if (!user) {
27
+ return false
28
+ }
29
+
26
30
  if (!user.domains.length) {
27
31
  user = await getRepository(User).findOne({
28
32
  where: { id: user.id },
@@ -33,6 +33,24 @@ export class ApplianceQuery {
33
33
  return { items, total }
34
34
  }
35
35
 
36
+ @Directive('@privilege(category: "user", privilege: "query", domainOwnerGranted: true, superUserGranted: true)')
37
+ @Query(returns => ApplianceList, { description: 'To fetch multiple appliance' })
38
+ async edges(@Args() params: ListParam, @Ctx() context: ResolverContext): Promise<ApplianceList> {
39
+ const { domain } = context.state
40
+
41
+ const queryBuilder = getQueryBuilderFromListParams({
42
+ domain,
43
+ params,
44
+ repository: getRepository(Appliance),
45
+ alias: 'appliance',
46
+ searchables: ['name', 'description']
47
+ })
48
+
49
+ const [items, total] = await queryBuilder.getManyAndCount()
50
+
51
+ return { items, total }
52
+ }
53
+
36
54
  @FieldResolver(type => String)
37
55
  async accessToken(@Root() appliance: Appliance, @Ctx() context: ResolverContext) {
38
56
  return appliance.accessToken
@@ -83,38 +83,6 @@ export class UserQuery {
83
83
  return Boolean(defaultPassword)
84
84
  }
85
85
 
86
- // @Query(returns => [User], { description: '...' })
87
- // async domainUsers(@Ctx() context: ResolverContext): Promise<User[]> {
88
- // const { domain } = context.state
89
-
90
- // const qb: SelectQueryBuilder<User> = buildDomainUsersQueryBuilder(domain.id, 'USER')
91
- // const domainUsers: User[] = await qb
92
- // .orWhere(qb => {
93
- // const subQuery = qb
94
- // .subQuery()
95
- // .select('CAST(APPLICATION.id as TEXT)')
96
- // .from(Application, 'APPLICATION')
97
- // .where('APPLICATION.domain_id = :domainId', { domainId: domain.id })
98
- // .getQuery()
99
- // return 'USER.reference IN ' + subQuery
100
- // })
101
- // .orWhere(qb => {
102
- // const subQuery = qb
103
- // .subQuery()
104
- // .select('CAST(APPLIANCE.id as TEXT)')
105
- // .from(Appliance, 'APPLIANCE')
106
- // .where('APPLIANCE.domain_id = :domainId', { domainId: domain.id })
107
- // .getQuery()
108
- // return 'USER.reference IN ' + subQuery
109
- // })
110
- // .getMany()
111
-
112
- // return domainUsers.map((user: User & { owner: boolean }) => {
113
- // user.owner = user.id === domain.owner
114
- // return user
115
- // })
116
- // }
117
-
118
86
  @Directive('@privilege(category: "user", privilege: "query")')
119
87
  @Query(returns => Boolean, { description: '...' })
120
88
  async checkUserExistence(@Arg('email', type => GraphQLEmailAddress) email: string): Promise<Boolean> {
package/server/types.ts CHANGED
@@ -8,14 +8,14 @@ import { User } from './service/user/user'
8
8
  declare global {
9
9
  export type ResolverContext = {
10
10
  state: IContextState
11
- t: TFunction
11
+ t?: TFunction
12
12
  [key: string]: any
13
13
  }
14
14
 
15
15
  interface IContextState {
16
16
  domain: Domain
17
17
  user: User
18
- tx: EntityManager
18
+ tx?: EntityManager
19
19
  [key: string]: any
20
20
  }
21
21
  }