@things-factory/shell 6.0.0-zeta.30 → 6.0.0-zeta.43
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-server/graphql-local-client.d.ts +3 -3
- package/dist-server/service/domain/domain-resolver.d.ts +0 -1
- package/dist-server/service/domain/domain-resolver.js +39 -33
- package/dist-server/service/domain/domain-resolver.js.map +1 -1
- package/dist-server/service/domain/domain-types.js.map +1 -1
- package/dist-server/service/domain/domain.js +12 -11
- package/dist-server/service/domain/domain.js.map +1 -1
- package/dist-server/service/subscription-data/data-resolver.js +2 -1
- package/dist-server/service/subscription-data/data-resolver.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/server/service/domain/domain-resolver.ts +41 -28
- package/server/service/domain/domain-types.ts +1 -0
- package/server/service/domain/domain.ts +30 -29
- package/server/service/subscription-data/data-resolver.ts +2 -1
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@things-factory/shell",
|
3
|
-
"version": "6.0.0-zeta.
|
3
|
+
"version": "6.0.0-zeta.43",
|
4
4
|
"description": "Core module for framework",
|
5
5
|
"bin": {
|
6
6
|
"things-factory": "bin/things-factory",
|
@@ -131,5 +131,5 @@
|
|
131
131
|
"pg": "^8.7.3",
|
132
132
|
"sqlite3": "^5.0.8"
|
133
133
|
},
|
134
|
-
"gitHead": "
|
134
|
+
"gitHead": "f43b9c1e5447ff2d5739a057c7154e1e1adc31b0"
|
135
135
|
}
|
@@ -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 {
|
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: "
|
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(
|
23
|
-
@Query(returns => DomainList, { description: 'To fetch
|
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 =
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
-
|
39
|
-
|
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
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
43
|
+
// const oldDomain = await domainRepository.findOneBy({ subdomain: targetSubdomain })
|
44
|
+
// if (oldDomain) {
|
45
|
+
// throw new Error('domain is duplicated')
|
46
|
+
// }
|
45
47
|
|
46
|
-
|
47
|
-
}
|
48
|
+
// return true
|
49
|
+
// }
|
48
50
|
|
49
|
-
@Directive('@
|
50
|
-
@
|
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('@
|
65
|
-
@
|
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('@
|
71
|
-
@
|
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('@
|
80
|
-
@
|
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('@
|
92
|
-
@
|
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
|
|
@@ -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 = [
|
6
|
-
const generatedStrategy = ['uuid','rowid',
|
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
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
-
|
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
|
|