@things-factory/shell 6.0.0-zeta.8 → 6.0.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/shell",
3
- "version": "6.0.0-zeta.8",
3
+ "version": "6.0.0",
4
4
  "description": "Core module for framework",
5
5
  "bin": {
6
6
  "things-factory": "bin/things-factory",
@@ -30,13 +30,12 @@
30
30
  "test": "NODE_ENV=test jest"
31
31
  },
32
32
  "dependencies": {
33
- "@anchan828/typeorm-history": "^1.0.16",
34
33
  "@apollo/client": "^3.6.9",
35
34
  "@graphql-tools/merge": "^8.3.0",
36
35
  "@graphql-tools/schema": "^8.5.0",
37
36
  "@graphql-tools/utils": "^8.8.0",
38
37
  "@hatiolab/koa-webpack": "^6.0.0",
39
- "@hatiolab/things-scene": "^3.0.23",
38
+ "@hatiolab/things-scene": "^3.2.0",
40
39
  "@koa/cors": "^3.3.0",
41
40
  "@material/mwc-button": "^0.27.0",
42
41
  "@material/mwc-fab": "^0.27.0",
@@ -50,11 +49,12 @@
50
49
  "@operato/help": "^1.0.1",
51
50
  "@operato/layout": "^1.0.1",
52
51
  "@operato/shell": "^1.0.1",
52
+ "@operato/typeorm-history": "^1.1.65",
53
53
  "@operato/utils": "^1.0.1",
54
54
  "@things-factory/ejs-remote": "^6.0.0-zeta.1",
55
- "@things-factory/env": "^6.0.0-zeta.1",
56
- "@things-factory/styles": "^6.0.0-zeta.1",
57
- "@things-factory/utils": "^6.0.0-zeta.1",
55
+ "@things-factory/env": "^6.0.0-zeta.30",
56
+ "@things-factory/styles": "^6.0.0-zeta.27",
57
+ "@things-factory/utils": "^6.0.0",
58
58
  "@webcomponents/webcomponentsjs": "^2.6.0",
59
59
  "@webpack-contrib/schema-utils": "^1.0.0-beta.0",
60
60
  "apollo-server-core": "^3.10.0",
@@ -96,7 +96,7 @@
96
96
  "koa-send": "^5.0.0",
97
97
  "koa-static": "^5.0.0",
98
98
  "koa2-connect-history-api-fallback": "^0.1.2",
99
- "lit": "^2.4.0",
99
+ "lit": "^2.5.0",
100
100
  "loader-utils": "^2.0.0",
101
101
  "lodash": "^4.17.21",
102
102
  "lodash-es": "^4.17.21",
@@ -131,5 +131,5 @@
131
131
  "pg": "^8.7.3",
132
132
  "sqlite3": "^5.0.8"
133
133
  },
134
- "gitHead": "84c5baee000c881c95673adf97eb30992e09e553"
134
+ "gitHead": "8797165c1e1f734a52cfd2c1ebbb53fe126796e9"
135
135
  }
@@ -26,6 +26,7 @@ export const transactionDirectiveResolver = (schema: GraphQLSchema) =>
26
26
  ...context.state,
27
27
  tx
28
28
  }
29
+ wrap.t = context.t
29
30
 
30
31
  let result = await resolve.call(this, source, args, wrap, info)
31
32
 
@@ -4,14 +4,15 @@ import { In, Repository } from 'typeorm'
4
4
  import { slugger } from '@things-factory/utils'
5
5
 
6
6
  import { getRepository } from '../../initializers/database'
7
- import { buildQuery } from '../../utils/list-query-builder'
7
+ import { getQueryBuilderFromListParams } from '../../utils/get-query-builder-from-list-params'
8
+
8
9
  import { ListParam } from '../common-types/list-param'
9
10
  import { Domain } from './domain'
10
11
  import { DomainList, DomainPatch } from './domain-types'
11
12
 
12
13
  @Resolver(Domain)
13
14
  export class DomainResolver {
14
- @Directive('@privilege(category: "system", privilege: "mutation", domainOwnerGranted: true, superUserGranted: true)')
15
+ @Directive('@privilege(category: "system", privilege: "query", domainOwnerGranted: true, superUserGranted: true)')
15
16
  @Query(returns => Domain, { description: 'To fetch domain' })
16
17
  async domain(@Arg('id') id: string): Promise<Domain> {
17
18
  const repository = getRepository(Domain)
@@ -19,35 +20,37 @@ export class DomainResolver {
19
20
  return await repository.findOneBy({ id })
20
21
  }
21
22
 
22
- @Directive('@privilege(category: "system", privilege: "query", superUserGranted: true)')
23
- @Query(returns => DomainList, { description: 'To fetch multiple domain' })
23
+ @Directive('@privilege(superUserGranted: true)')
24
+ @Query(returns => DomainList, { description: 'To fetch all domains (Only superuser is granted this privilege.)' })
24
25
  async domains(@Args() params: ListParam, @Ctx() context: any): Promise<DomainList> {
25
- const queryBuilder = getRepository(Domain).createQueryBuilder()
26
-
27
- buildQuery(queryBuilder, params || {}, context, {
28
- domainRef: false,
26
+ const queryBuilder = await getQueryBuilderFromListParams({
27
+ repository: getRepository(Domain),
28
+ alias: 'ContactPoint',
29
+ params,
29
30
  searchables: ['name', 'description', 'subdomain']
30
31
  })
32
+
31
33
  const [items, total] = await queryBuilder.getManyAndCount()
32
34
 
33
35
  return { items, total }
34
36
  }
35
37
 
36
- @Query(returns => Boolean, { description: 'To check if given domain is exist' })
37
- async checkExistsDomain(@Arg('name') name: string) {
38
- const domainRepository: Repository<Domain> = getRepository(Domain)
39
- const targetSubdomain: string = slugger(name)
38
+ // @Query(returns => Boolean, { description: 'To check if given domain is exist' })
39
+ // async checkExistsDomain(@Arg('name') name: string) {
40
+ // const domainRepository: Repository<Domain> = getRepository(Domain)
41
+ // const targetSubdomain: string = slugger(name)
40
42
 
41
- const oldDomain = await domainRepository.findOneBy({ subdomain: targetSubdomain })
42
- if (oldDomain) {
43
- throw new Error('domain is duplicated')
44
- }
43
+ // const oldDomain = await domainRepository.findOneBy({ subdomain: targetSubdomain })
44
+ // if (oldDomain) {
45
+ // throw new Error('domain is duplicated')
46
+ // }
45
47
 
46
- return true
47
- }
48
+ // return true
49
+ // }
48
50
 
49
- @Directive('@privilege(category: "system", privilege: "mutation", superUserGranted: true)')
50
- @Mutation(returns => Domain, { description: 'To create domain' })
51
+ @Directive('@transaction')
52
+ @Directive('@privilege(superUserGranted: true)')
53
+ @Mutation(returns => Domain, { description: 'To create domain (Only superuser is granted this privilege.)' })
51
54
  async createDomain(@Arg('domainInput') domainInput: DomainPatch) {
52
55
  const { name, description } = domainInput
53
56
  const domainRepo: Repository<Domain> = getRepository(Domain)
@@ -61,14 +64,18 @@ export class DomainResolver {
61
64
  return await domainRepo.save({ name, description, subdomain })
62
65
  }
63
66
 
64
- @Directive('@privilege(category: "system", privilege: "mutation", superUserGranted: true)')
65
- @Mutation(returns => Domain, { description: 'To delete domain' })
67
+ @Directive('@transaction')
68
+ @Directive('@privilege(superUserGranted: true)')
69
+ @Mutation(returns => Domain, { description: 'To delete domain (Only superuser is granted this privilege.)' })
66
70
  async deleteDomain(@Arg('name') name: string) {
67
71
  return await getRepository(Domain).delete({ name })
68
72
  }
69
73
 
70
- @Directive('@privilege(category: "system", privilege: "mutation", superUserGranted: true)')
71
- @Mutation(returns => Boolean, { description: 'To delete multiple domains' })
74
+ @Directive('@transaction')
75
+ @Directive('@privilege(superUserGranted: true)')
76
+ @Mutation(returns => Boolean, {
77
+ description: 'To delete multiple domains (Only superuser is granted this privilege.)'
78
+ })
72
79
  async deleteDomains(@Arg('names', () => [String]) names: string[]) {
73
80
  const domains: Domain[] = await getRepository(Domain).find({ where: { name: In(names) } })
74
81
  const domainIds: string[] = domains.map(domain => domain.id)
@@ -76,8 +83,11 @@ export class DomainResolver {
76
83
  await getRepository(Domain).delete({ id: In(domainIds) })
77
84
  }
78
85
 
79
- @Directive('@privilege(category: "system", privilege: "mutation", domainOwnerGranted: true, superUserGranted: true)')
80
- @Mutation(returns => Domain, { description: 'To update domain' })
86
+ @Directive('@transaction')
87
+ @Directive('@privilege(superUserGranted: true)')
88
+ @Mutation(returns => Domain, {
89
+ description: 'To update domain (Only superuser is granted this privilege.)'
90
+ })
81
91
  async updateDomain(@Arg('name') name: string, @Arg('patch', () => DomainPatch) patch: DomainPatch) {
82
92
  const repository = getRepository(Domain)
83
93
  const domain: Domain = await repository.findOneBy({ name })
@@ -88,8 +98,11 @@ export class DomainResolver {
88
98
  } as any)
89
99
  }
90
100
 
91
- @Directive('@privilege(category: "system", privilege: "mutation", superUserGranted: true)')
92
- @Mutation(returns => Boolean, { description: 'To update multiple domains' })
101
+ @Directive('@transaction')
102
+ @Directive('@privilege(superUserGranted: true)')
103
+ @Mutation(returns => Boolean, {
104
+ description: 'To update multiple domains (Only superuser is granted this privilege.)'
105
+ })
93
106
  async updateDomains(@Arg('patches', () => [DomainPatch]) patches: DomainPatch[]): Promise<boolean> {
94
107
  const domainRepo: Repository<Domain> = getRepository(Domain)
95
108
 
@@ -1,5 +1,6 @@
1
1
  import { ObjectType, InputType, Field, Int } from 'type-graphql'
2
2
  import { Domain } from './domain'
3
+ import { ObjectRef } from '../common-types/object-ref'
3
4
 
4
5
  @InputType()
5
6
  export class DomainInput {
@@ -2,9 +2,9 @@ import { Column, CreateDateColumn, Entity, Index, UpdateDateColumn } from 'typeo
2
2
  import { ObjectType, Field, ID } from 'type-graphql'
3
3
  import { config } from '@things-factory/env'
4
4
 
5
- const numericTypes = ["int","int2","int4","int8","integer","tinyint","smallint","mediumint","bigint"]
6
- const generatedStrategy = ['uuid','rowid',"increment","identity"]
7
- const domainPrimaryOption =config.get('domainPrimaryOption')
5
+ const numericTypes = ['int', 'int2', 'int4', 'int8', 'integer', 'tinyint', 'smallint', 'mediumint', 'bigint']
6
+ const generatedStrategy = ['uuid', 'rowid', 'increment', 'identity']
7
+ const domainPrimaryOption = config.get('domainPrimaryOption')
8
8
  const domainPrimaryType = domainPrimaryOption?.type
9
9
  const domainPrimaryStrategy = domainPrimaryOption?.strategy
10
10
 
@@ -14,33 +14,34 @@ const domainPrimaryStrategy = domainPrimaryOption?.strategy
14
14
  export class Domain {
15
15
  @Field(type => ID)
16
16
  @Column(
17
- domainPrimaryOption?
18
- {
19
- type: domainPrimaryType,
20
- primary:true,
21
- transformer: {
22
- //from(value: DatabaseType): EntityType
23
- from: (value) => {
24
- return value
25
- },
26
- //to(value: EntityType): DatabaseType
27
- to: (value) => {
28
- if(!value){
29
- value = 0
30
- }
31
- if(numericTypes.indexOf(domainPrimaryType)>=0){
32
- return parseInt(value)
33
- }else{
34
- return value
35
- }
17
+ domainPrimaryOption
18
+ ? {
19
+ type: domainPrimaryType,
20
+ primary: true,
21
+ transformer: {
22
+ //from(value: DatabaseType): EntityType
23
+ from: value => {
24
+ return value
25
+ },
26
+ //to(value: EntityType): DatabaseType
27
+ to: value => {
28
+ if (!value) {
29
+ value = 0
30
+ }
31
+ if (numericTypes.indexOf(domainPrimaryType) >= 0) {
32
+ return parseInt(value)
33
+ } else {
34
+ return value
35
+ }
36
+ }
37
+ },
38
+ generated: generatedStrategy.indexOf(domainPrimaryStrategy) >= 0 ? domainPrimaryStrategy : false
39
+ }
40
+ : {
41
+ type: 'uuid',
42
+ primary: true,
43
+ generated: 'uuid'
36
44
  }
37
- },
38
- generated:generatedStrategy.indexOf(domainPrimaryStrategy)>=0?domainPrimaryStrategy:false
39
- }:{
40
- type: 'uuid',
41
- primary:true,
42
- generated:'uuid'
43
- }
44
45
  )
45
46
  readonly id: string
46
47
 
@@ -16,7 +16,8 @@ export class DataResolver {
16
16
  throw new Error('domain and tag required')
17
17
  }
18
18
 
19
- if (!user.domains?.find(d => d.subdomain === subdomain)) {
19
+ //@ts-ignore
20
+ if (!user.domains?.find(d => d.subdomain === subdomain) && !process.superUserGranted(domain, user)) {
20
21
  throw new Error(`domain(${subdomain}) is not working for user(${user.email}).`)
21
22
  }
22
23