@things-factory/shell 8.0.2 → 8.0.13
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/config/config.development.js +1 -1
- package/config/config.production.js +1 -14
- package/dist-server/middlewares/domain-middleware.js +3 -3
- package/dist-server/middlewares/domain-middleware.js.map +1 -1
- package/dist-server/service/domain/domain-query.d.ts +4 -3
- package/dist-server/service/domain/domain-query.js +27 -15
- package/dist-server/service/domain/domain-query.js.map +1 -1
- package/dist-server/service/domain/domain-types.d.ts +2 -0
- package/dist-server/service/domain/domain-types.js +8 -0
- package/dist-server/service/domain/domain-types.js.map +1 -1
- package/dist-server/service/domain/domain.js +4 -38
- package/dist-server/service/domain/domain.js.map +1 -1
- package/dist-server/service/index.d.ts +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/dist-server/utils/get-domain.d.ts +9 -10
- package/dist-server/utils/get-domain.js +66 -71
- package/dist-server/utils/get-domain.js.map +1 -1
- package/dist-server/utils/get-query-builder-from-list-params.d.ts +2 -2
- package/dist-server/utils/get-query-builder-from-list-params.js +5 -5
- package/dist-server/utils/get-query-builder-from-list-params.js.map +1 -1
- package/package.json +4 -4
- package/server/middlewares/domain-middleware.ts +3 -3
- package/server/service/domain/domain-query.ts +11 -4
- package/server/service/domain/domain-types.ts +6 -0
- package/server/service/domain/domain.ts +4 -39
- package/server/utils/get-domain.ts +75 -73
- package/server/utils/get-query-builder-from-list-params.ts +3 -3
@@ -7,17 +7,11 @@ import {
|
|
7
7
|
Entity,
|
8
8
|
Index,
|
9
9
|
UpdateDateColumn,
|
10
|
-
DeleteDateColumn
|
10
|
+
DeleteDateColumn,
|
11
|
+
PrimaryGeneratedColumn
|
11
12
|
} from 'typeorm'
|
12
13
|
import { ObjectType, Directive, Field, ID } from 'type-graphql'
|
13
|
-
import {
|
14
|
-
import { ScalarObject } from '../common-types'
|
15
|
-
|
16
|
-
const numericTypes = ['int', 'int2', 'int4', 'int8', 'integer', 'tinyint', 'smallint', 'mediumint', 'bigint']
|
17
|
-
const generatedStrategy = ['uuid', 'rowid', 'increment', 'identity']
|
18
|
-
const domainPrimaryOption = config.get('domainPrimaryOption')
|
19
|
-
const domainPrimaryType = domainPrimaryOption?.type
|
20
|
-
const domainPrimaryStrategy = domainPrimaryOption?.strategy
|
14
|
+
import { ScalarObject } from '../common-types/scalar-object.js'
|
21
15
|
|
22
16
|
export type IPList = {
|
23
17
|
whitelist?: string[]
|
@@ -36,37 +30,8 @@ export type IPList = {
|
|
36
30
|
})
|
37
31
|
@ObjectType()
|
38
32
|
export class Domain {
|
33
|
+
@PrimaryGeneratedColumn('uuid')
|
39
34
|
@Field(type => ID)
|
40
|
-
@Column(
|
41
|
-
domainPrimaryOption
|
42
|
-
? {
|
43
|
-
type: domainPrimaryType,
|
44
|
-
primary: true,
|
45
|
-
transformer: {
|
46
|
-
//from(value: DatabaseType): EntityType
|
47
|
-
from: value => {
|
48
|
-
return value
|
49
|
-
},
|
50
|
-
//to(value: EntityType): DatabaseType
|
51
|
-
to: value => {
|
52
|
-
if (!value) {
|
53
|
-
value = 0
|
54
|
-
}
|
55
|
-
if (numericTypes.indexOf(domainPrimaryType) >= 0) {
|
56
|
-
return parseInt(value)
|
57
|
-
} else {
|
58
|
-
return value
|
59
|
-
}
|
60
|
-
}
|
61
|
-
},
|
62
|
-
generated: generatedStrategy.indexOf(domainPrimaryStrategy) >= 0 ? domainPrimaryStrategy : false
|
63
|
-
}
|
64
|
-
: {
|
65
|
-
type: 'uuid',
|
66
|
-
primary: true,
|
67
|
-
generated: 'uuid'
|
68
|
-
}
|
69
|
-
)
|
70
35
|
readonly id: string
|
71
36
|
|
72
37
|
@Field()
|
@@ -6,10 +6,16 @@ import { getPathInfo } from '@things-factory/utils'
|
|
6
6
|
import { getRepository } from '../initializers/database'
|
7
7
|
import { Domain } from '../service/domain/domain'
|
8
8
|
|
9
|
-
const useVirtualHostBasedDomain = !!config.get('useVirtualHostBasedDomain')
|
10
9
|
const protocol: string = config.get('protocol')
|
11
10
|
const fixed = config.get('subdomain')
|
12
|
-
const
|
11
|
+
const domainTypes = config.get('domainTypes') || ['domain']
|
12
|
+
|
13
|
+
/* 하위 호환성을 위해서, domain prefix가 없는 경우, domain을 추가해준다. */
|
14
|
+
if (domainTypes.indexOf('domain') < 0) {
|
15
|
+
domainTypes.push('domain')
|
16
|
+
}
|
17
|
+
|
18
|
+
const routePrefixForDomainType = `:domainType(${domainTypes.join('|')})`
|
13
19
|
|
14
20
|
/**
|
15
21
|
* Creates a URL based on the given context and path.
|
@@ -51,18 +57,6 @@ export function getUrlFromContext(context, path = '') {
|
|
51
57
|
return url
|
52
58
|
}
|
53
59
|
|
54
|
-
/**
|
55
|
-
* Extracts subdomains from the Host header.
|
56
|
-
*
|
57
|
-
* @param context {Object} An object containing the current request context information.
|
58
|
-
* @returns {string[]} An array of extracted subdomains.
|
59
|
-
*/
|
60
|
-
function getSubdomainsFromHost(context: any) {
|
61
|
-
const { request } = context
|
62
|
-
var subdomains = request.headers.host.split('.').reverse()
|
63
|
-
return subdomains.slice(subdomainOffset)
|
64
|
-
}
|
65
|
-
|
66
60
|
/**
|
67
61
|
* Extracts a subdomain from the path.
|
68
62
|
*
|
@@ -72,9 +66,9 @@ function getSubdomainsFromHost(context: any) {
|
|
72
66
|
function getSubdomainFromPath(context: any) {
|
73
67
|
var { path } = context
|
74
68
|
|
75
|
-
var
|
76
|
-
if (
|
77
|
-
return
|
69
|
+
var subdomain = getPathInfo(path || '', domainTypes)?.subdomain
|
70
|
+
if (subdomain) {
|
71
|
+
return subdomain
|
78
72
|
}
|
79
73
|
|
80
74
|
var {
|
@@ -83,20 +77,32 @@ function getSubdomainFromPath(context: any) {
|
|
83
77
|
|
84
78
|
if (referer) {
|
85
79
|
var { pathname } = new URL(referer)
|
86
|
-
return getPathInfo(pathname || '')?.
|
80
|
+
return getPathInfo(pathname || '', domainTypes)?.subdomain
|
87
81
|
}
|
88
82
|
}
|
89
83
|
|
90
84
|
/**
|
91
|
-
* Extracts
|
85
|
+
* Extracts the subdomain type from the given context's path or referer header.
|
92
86
|
*
|
93
|
-
* @param context
|
94
|
-
* @returns
|
87
|
+
* @param context - The context object containing path and header information.
|
88
|
+
* @returns The subdomain type if found, otherwise undefined.
|
95
89
|
*/
|
96
|
-
function
|
97
|
-
|
90
|
+
function getSubdomainTypeFromPath(context: any) {
|
91
|
+
var { path } = context
|
92
|
+
|
93
|
+
var prefix = getPathInfo(path || '', domainTypes)?.prefix
|
94
|
+
if (prefix) {
|
95
|
+
return prefix
|
96
|
+
}
|
97
|
+
|
98
|
+
var {
|
99
|
+
header: { referer }
|
100
|
+
} = context
|
98
101
|
|
99
|
-
|
102
|
+
if (referer) {
|
103
|
+
var { pathname } = new URL(referer)
|
104
|
+
return getPathInfo(pathname || '', domainTypes)?.prefix
|
105
|
+
}
|
100
106
|
}
|
101
107
|
|
102
108
|
/**
|
@@ -106,7 +112,11 @@ function getSubdomainFromVhost(context: any) {
|
|
106
112
|
* @returns {string} The extracted subdomain.
|
107
113
|
*/
|
108
114
|
function getSubdomainFromURL(context) {
|
109
|
-
return fixed ||
|
115
|
+
return fixed || getSubdomainFromPath(context)
|
116
|
+
}
|
117
|
+
|
118
|
+
function getSubdomainTypeFromURL(context) {
|
119
|
+
return fixed ? '' : getSubdomainTypeFromPath(context)
|
110
120
|
}
|
111
121
|
|
112
122
|
/**
|
@@ -119,21 +129,21 @@ export async function getDomainFromURL(context: any): Promise<Domain> {
|
|
119
129
|
const { header } = context
|
120
130
|
|
121
131
|
const subdomain = header['x-things-factory-domain'] || getSubdomainFromURL(context)
|
132
|
+
const extType = header['x-things-factory-type'] || getSubdomainTypeFromURL(context)
|
122
133
|
|
123
134
|
if (subdomain) {
|
124
|
-
return await getRepository(Domain).findOne({
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
return hostname.split('.').slice(-subdomainOffset).join('.')
|
135
|
+
return await getRepository(Domain).findOne({
|
136
|
+
where:
|
137
|
+
fixed || extType == 'domain' || !extType
|
138
|
+
? {
|
139
|
+
subdomain
|
140
|
+
}
|
141
|
+
: {
|
142
|
+
subdomain,
|
143
|
+
extType
|
144
|
+
},
|
145
|
+
cache: true
|
146
|
+
})
|
137
147
|
}
|
138
148
|
}
|
139
149
|
|
@@ -143,42 +153,37 @@ export function getCookieDomainFromHostname(hostname) {
|
|
143
153
|
* @param subdomain {string} The subdomain.
|
144
154
|
* @returns {string} The generated context path.
|
145
155
|
*/
|
146
|
-
export function getContextPath(
|
147
|
-
|
156
|
+
export function getContextPath(domain: Domain) {
|
157
|
+
const type = domain?.extType || 'domain'
|
158
|
+
return fixed || !domain ? '' : `${type}/${domain?.subdomain}/`
|
148
159
|
}
|
149
160
|
|
150
161
|
/**
|
151
162
|
* Generates a redirection path considering the subdomain.
|
152
163
|
*
|
153
164
|
* @param context {Object} An object containing the current request context information.
|
154
|
-
* @param subdomain {
|
165
|
+
* @param subdomain {Domain} The target domain.
|
155
166
|
* @param redirectTo {string} The path to redirect to (optional).
|
156
167
|
* @returns {string} The generated redirection path.
|
157
168
|
*/
|
158
|
-
export function getRedirectSubdomainPath(context,
|
159
|
-
if (fixed) {
|
169
|
+
export function getRedirectSubdomainPath(context, domain: Partial<Domain>, redirectTo: string = '/') {
|
170
|
+
if (fixed || !domain) {
|
160
171
|
return redirectTo || '/'
|
161
172
|
}
|
162
173
|
|
174
|
+
const type = domain.extType || 'domain'
|
175
|
+
const subdomain = domain.subdomain || fixed
|
176
|
+
|
163
177
|
var parsed = getUrlFromContext(context, redirectTo)
|
164
178
|
var { hostname, pathname } = parsed
|
165
179
|
|
166
|
-
|
167
|
-
|
168
|
-
splitHost[subdomainOffset] = subdomain
|
169
|
-
parsed.hostname = splitHost
|
170
|
-
.reverse()
|
171
|
-
.filter(a => a)
|
172
|
-
.join('.')
|
173
|
-
} else {
|
174
|
-
const contextPath = `/domain/${subdomain}`
|
175
|
-
const match = pathname.match(/^\/domain\/([^\/]+)/)
|
180
|
+
const contextPath = `/${type}/${subdomain}`
|
181
|
+
const match = pathname.match(new RegExp(`^/${type}/([^\/]+)`))
|
176
182
|
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
}
|
183
|
+
if (match) {
|
184
|
+
parsed.pathname = pathname.replace(match[0], contextPath)
|
185
|
+
} else {
|
186
|
+
parsed.pathname = `${contextPath}${pathname}`
|
182
187
|
}
|
183
188
|
|
184
189
|
return parsed.toString()
|
@@ -197,16 +202,21 @@ export function findSubdomainFromPath(context, path) {
|
|
197
202
|
}
|
198
203
|
|
199
204
|
var parsed = getUrlFromContext(context, path)
|
200
|
-
var {
|
201
|
-
|
202
|
-
if (useVirtualHostBasedDomain) {
|
203
|
-
return hostname.split('.').reverse()[subdomainOffset]
|
204
|
-
}
|
205
|
+
var { pathname } = parsed
|
205
206
|
|
206
|
-
const match = pathname.match(
|
207
|
+
const match = pathname.match(new RegExp(`^/${getSubdomainTypeFromURL(context)}/([^\/]+)`))
|
207
208
|
return match && match[1]
|
208
209
|
}
|
209
210
|
|
211
|
+
/**
|
212
|
+
* Retrieves the route prefix for a specific domain type.
|
213
|
+
*
|
214
|
+
* @returns {string} The route prefix associated with the domain type.
|
215
|
+
*/
|
216
|
+
export function getRoutePrefixForDomainType() {
|
217
|
+
return routePrefixForDomainType
|
218
|
+
}
|
219
|
+
|
210
220
|
/**
|
211
221
|
* Generates a site root path based on the current environment.
|
212
222
|
*
|
@@ -214,13 +224,5 @@ export function findSubdomainFromPath(context, path) {
|
|
214
224
|
* @returns {string} The generated site root path.
|
215
225
|
*/
|
216
226
|
export function getSiteRootPath(context) {
|
217
|
-
|
218
|
-
var { protocol, host } = context
|
219
|
-
protocol = protocol.replace(':', '')
|
220
|
-
|
221
|
-
let domainname = host.split('.').slice(-subdomainOffset).join('.')
|
222
|
-
return protocol + '://' + domainname + '/'
|
223
|
-
} else {
|
224
|
-
return '/'
|
225
|
-
}
|
227
|
+
return '/'
|
226
228
|
}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { Brackets, EntityMetadata, Repository, SelectQueryBuilder, WhereExpressionBuilder } from 'typeorm'
|
2
|
-
import { RelationMetadata } from 'typeorm/metadata/RelationMetadata'
|
3
|
-
import { Filter, Sorting, Pagination, ListParam, InheritedValueType } from '../service/common-types/list-param'
|
4
|
-
import { Domain } from '../service/domain/domain'
|
2
|
+
import { RelationMetadata } from 'typeorm/metadata/RelationMetadata.js'
|
3
|
+
import { Filter, Sorting, Pagination, ListParam, InheritedValueType } from '../service/common-types/list-param.js'
|
4
|
+
import { Domain } from '../service/domain/domain.js'
|
5
5
|
|
6
6
|
/**
|
7
7
|
* Creates a TypeORM SelectQueryBuilder based on the provided parameters.
|