@contember/engine-http 1.1.0-alpha.1 → 1.1.0-alpha.4
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/src/ProjectContainer.d.ts +6 -5
- package/dist/src/ProjectContainer.d.ts.map +1 -1
- package/dist/src/ProjectGroupContainer.d.ts +22 -0
- package/dist/src/ProjectGroupContainer.d.ts.map +1 -0
- package/dist/src/ProjectGroupContainer.js +3 -0
- package/dist/src/ProjectGroupContainer.js.map +1 -0
- package/dist/src/common/Authorizator.d.ts +21 -0
- package/dist/src/common/Authorizator.d.ts.map +1 -0
- package/dist/src/common/Authorizator.js +34 -0
- package/dist/src/common/Authorizator.js.map +1 -0
- package/dist/src/common/ErrorMiddleware.d.ts +10 -0
- package/dist/src/common/ErrorMiddleware.d.ts.map +1 -0
- package/dist/src/common/ErrorMiddleware.js +34 -0
- package/dist/src/common/ErrorMiddleware.js.map +1 -0
- package/dist/src/common/HttpError.d.ts +5 -0
- package/dist/src/common/HttpError.d.ts.map +1 -0
- package/dist/src/common/HttpError.js +11 -0
- package/dist/src/common/HttpError.js.map +1 -0
- package/dist/src/common/TimerMiddleware.d.ts +2 -1
- package/dist/src/common/TimerMiddleware.d.ts.map +1 -1
- package/dist/src/common/TimerMiddleware.js.map +1 -1
- package/dist/src/common/index.d.ts +3 -3
- package/dist/src/common/index.d.ts.map +1 -1
- package/dist/src/common/index.js +3 -3
- package/dist/src/common/index.js.map +1 -1
- package/dist/src/{ProjectConfig.d.ts → config.d.ts} +5 -3
- package/dist/src/config.d.ts.map +1 -0
- package/dist/src/{ProjectConfig.js → config.js} +1 -1
- package/dist/src/config.js.map +1 -0
- package/dist/src/content/ContentApiMiddlewareFactory.d.ts +21 -0
- package/dist/src/content/ContentApiMiddlewareFactory.d.ts.map +1 -0
- package/dist/src/content/ContentApiMiddlewareFactory.js +95 -0
- package/dist/src/content/ContentApiMiddlewareFactory.js.map +1 -0
- package/dist/src/content/ContentGraphQLContextFactory.d.ts +26 -0
- package/dist/src/content/ContentGraphQLContextFactory.d.ts.map +1 -0
- package/dist/src/content/ContentGraphQLContextFactory.js +35 -0
- package/dist/src/content/ContentGraphQLContextFactory.js.map +1 -0
- package/dist/src/content/ContentQueryHandlerFactory.d.ts +5 -11
- package/dist/src/content/ContentQueryHandlerFactory.d.ts.map +1 -1
- package/dist/src/content/ContentQueryHandlerFactory.js +5 -36
- package/dist/src/content/ContentQueryHandlerFactory.js.map +1 -1
- package/dist/src/content/GraphQlSchemaFactory.d.ts +2 -2
- package/dist/src/content/GraphQlSchemaFactory.d.ts.map +1 -1
- package/dist/src/content/GraphQlSchemaFactory.js +3 -3
- package/dist/src/content/GraphQlSchemaFactory.js.map +1 -1
- package/dist/src/content/NotModifiedChecker.d.ts +17 -0
- package/dist/src/content/NotModifiedChecker.d.ts.map +1 -0
- package/dist/src/content/NotModifiedChecker.js +32 -0
- package/dist/src/content/NotModifiedChecker.js.map +1 -0
- package/dist/src/content/index.d.ts +3 -4
- package/dist/src/content/index.d.ts.map +1 -1
- package/dist/src/content/index.js +3 -4
- package/dist/src/content/index.js.map +1 -1
- package/dist/src/graphql/execution.d.ts +9 -5
- package/dist/src/graphql/execution.d.ts.map +1 -1
- package/dist/src/graphql/execution.js +10 -11
- package/dist/src/graphql/execution.js.map +1 -1
- package/dist/src/index.d.ts +3 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +3 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/project-common/ProjectGroupResolver.d.ts +16 -0
- package/dist/src/project-common/ProjectGroupResolver.d.ts.map +1 -0
- package/dist/src/project-common/ProjectGroupResolver.js +50 -0
- package/dist/src/project-common/ProjectGroupResolver.js.map +1 -0
- package/dist/src/project-common/ProjectInfoMiddlewareState.d.ts +5 -0
- package/dist/src/project-common/ProjectInfoMiddlewareState.d.ts.map +1 -0
- package/dist/src/project-common/ProjectInfoMiddlewareState.js +3 -0
- package/dist/src/project-common/ProjectInfoMiddlewareState.js.map +1 -0
- package/dist/src/project-common/index.d.ts +2 -3
- package/dist/src/project-common/index.d.ts.map +1 -1
- package/dist/src/project-common/index.js +2 -3
- package/dist/src/project-common/index.js.map +1 -1
- package/dist/src/providers.d.ts +2 -9
- package/dist/src/providers.d.ts.map +1 -1
- package/dist/src/providers.js +1 -17
- package/dist/src/providers.js.map +1 -1
- package/dist/src/system/SystemApiMiddlewareFactory.d.ts +17 -0
- package/dist/src/system/SystemApiMiddlewareFactory.d.ts.map +1 -0
- package/dist/src/system/SystemApiMiddlewareFactory.js +52 -0
- package/dist/src/system/SystemApiMiddlewareFactory.js.map +1 -0
- package/dist/src/system/SystemGraphQLContextFactory.d.ts +17 -0
- package/dist/src/system/SystemGraphQLContextFactory.d.ts.map +1 -0
- package/dist/src/system/SystemGraphQLContextFactory.js +18 -0
- package/dist/src/system/SystemGraphQLContextFactory.js.map +1 -0
- package/dist/src/system/SystemGraphQLHandlerFactory.d.ts +18 -0
- package/dist/src/system/SystemGraphQLHandlerFactory.d.ts.map +1 -0
- package/dist/src/system/{SystemGraphQLMiddlewareFactory.js → SystemGraphQLHandlerFactory.js} +10 -22
- package/dist/src/system/SystemGraphQLHandlerFactory.js.map +1 -0
- package/dist/src/system/index.d.ts +3 -1
- package/dist/src/system/index.d.ts.map +1 -1
- package/dist/src/system/index.js +3 -1
- package/dist/src/system/index.js.map +1 -1
- package/dist/src/tenant/TenantApiMiddlewareFactory.d.ts +17 -0
- package/dist/src/tenant/TenantApiMiddlewareFactory.d.ts.map +1 -0
- package/dist/src/tenant/TenantApiMiddlewareFactory.js +28 -0
- package/dist/src/tenant/TenantApiMiddlewareFactory.js.map +1 -0
- package/dist/src/tenant/TenantGraphQLContextFactory.d.ts +13 -0
- package/dist/src/tenant/TenantGraphQLContextFactory.d.ts.map +1 -0
- package/dist/src/tenant/TenantGraphQLContextFactory.js +17 -0
- package/dist/src/tenant/TenantGraphQLContextFactory.js.map +1 -0
- package/dist/src/tenant/TenantGraphQLHandlerFactory.d.ts +14 -0
- package/dist/src/tenant/TenantGraphQLHandlerFactory.d.ts.map +1 -0
- package/dist/src/tenant/TenantGraphQLHandlerFactory.js +35 -0
- package/dist/src/tenant/TenantGraphQLHandlerFactory.js.map +1 -0
- package/dist/src/tenant/index.d.ts +3 -1
- package/dist/src/tenant/index.d.ts.map +1 -1
- package/dist/src/tenant/index.js +3 -1
- package/dist/src/tenant/index.js.map +1 -1
- package/dist/src/tsconfig.tsbuildinfo +1 -1
- package/dist/src/utils/CryptoWrapper.d.ts +17 -0
- package/dist/src/utils/CryptoWrapper.d.ts.map +1 -0
- package/dist/src/utils/CryptoWrapper.js +64 -0
- package/dist/src/utils/CryptoWrapper.js.map +1 -0
- package/dist/tests/cases/unit/crypto.test.d.ts +2 -0
- package/dist/tests/cases/unit/crypto.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/crypto.test.js +90 -0
- package/dist/tests/cases/unit/crypto.test.js.map +1 -0
- package/dist/tests/tsconfig.tsbuildinfo +1 -0
- package/package.json +12 -12
- package/src/ProjectContainer.ts +7 -5
- package/src/ProjectGroupContainer.ts +32 -0
- package/src/common/Authorizator.ts +47 -0
- package/src/common/ErrorMiddleware.ts +32 -0
- package/src/common/HttpError.ts +8 -0
- package/src/common/TimerMiddleware.ts +3 -1
- package/src/common/index.ts +3 -3
- package/src/{ProjectConfig.ts → config.ts} +3 -6
- package/src/content/ContentApiMiddlewareFactory.ts +128 -0
- package/src/content/ContentGraphQLContextFactory.ts +58 -0
- package/src/content/ContentQueryHandlerFactory.ts +8 -62
- package/src/content/GraphQlSchemaFactory.ts +7 -7
- package/src/content/NotModifiedChecker.ts +43 -0
- package/src/content/index.ts +3 -4
- package/src/graphql/execution.ts +14 -18
- package/src/index.ts +4 -1
- package/src/project-common/ProjectGroupResolver.ts +56 -0
- package/src/project-common/ProjectInfoMiddlewareState.ts +4 -0
- package/src/project-common/index.ts +2 -3
- package/src/providers.ts +2 -19
- package/src/system/SystemApiMiddlewareFactory.ts +73 -0
- package/src/system/SystemGraphQLContextFactory.ts +34 -0
- package/src/system/SystemGraphQLHandlerFactory.ts +72 -0
- package/src/system/index.ts +3 -1
- package/src/tenant/TenantApiMiddlewareFactory.ts +38 -0
- package/src/tenant/TenantGraphQLContextFactory.ts +25 -0
- package/src/tenant/TenantGraphQLHandlerFactory.ts +44 -0
- package/src/tenant/index.ts +3 -1
- package/src/utils/CryptoWrapper.ts +45 -0
- package/tests/cases/unit/crypto.test.ts +78 -0
- package/tests/tsconfig.json +12 -0
- package/tsconfig.json +3 -0
- package/dist/src/ProjectConfig.d.ts.map +0 -1
- package/dist/src/ProjectConfig.js.map +0 -1
- package/dist/src/common/ApiMiddleware.d.ts +0 -12
- package/dist/src/common/ApiMiddleware.d.ts.map +0 -1
- package/dist/src/common/ApiMiddleware.js +0 -25
- package/dist/src/common/ApiMiddleware.js.map +0 -1
- package/dist/src/common/AuthMiddleware.d.ts +0 -20
- package/dist/src/common/AuthMiddleware.d.ts.map +0 -1
- package/dist/src/common/AuthMiddleware.js +0 -38
- package/dist/src/common/AuthMiddleware.js.map +0 -1
- package/dist/src/common/ErrorFactory.d.ts +0 -8
- package/dist/src/common/ErrorFactory.d.ts.map +0 -1
- package/dist/src/common/ErrorFactory.js +0 -21
- package/dist/src/common/ErrorFactory.js.map +0 -1
- package/dist/src/content/ContentQueryHandlerProvider.d.ts +0 -15
- package/dist/src/content/ContentQueryHandlerProvider.d.ts.map +0 -1
- package/dist/src/content/ContentQueryHandlerProvider.js +0 -26
- package/dist/src/content/ContentQueryHandlerProvider.js.map +0 -1
- package/dist/src/content/ContentServerMiddleware.d.ts +0 -15
- package/dist/src/content/ContentServerMiddleware.d.ts.map +0 -1
- package/dist/src/content/ContentServerMiddleware.js +0 -21
- package/dist/src/content/ContentServerMiddleware.js.map +0 -1
- package/dist/src/content/NotModifiedMiddlewareFactory.d.ts +0 -11
- package/dist/src/content/NotModifiedMiddlewareFactory.d.ts.map +0 -1
- package/dist/src/content/NotModifiedMiddlewareFactory.js +0 -37
- package/dist/src/content/NotModifiedMiddlewareFactory.js.map +0 -1
- package/dist/src/content/StageResolveMiddlewareFactory.d.ts +0 -16
- package/dist/src/content/StageResolveMiddlewareFactory.d.ts.map +0 -1
- package/dist/src/content/StageResolveMiddlewareFactory.js +0 -22
- package/dist/src/content/StageResolveMiddlewareFactory.js.map +0 -1
- package/dist/src/project-common/ProjectGroupMiddleware.d.ts +0 -17
- package/dist/src/project-common/ProjectGroupMiddleware.d.ts.map +0 -1
- package/dist/src/project-common/ProjectGroupMiddleware.js +0 -33
- package/dist/src/project-common/ProjectGroupMiddleware.js.map +0 -1
- package/dist/src/project-common/ProjectMemberMiddlewareFactory.d.ts +0 -25
- package/dist/src/project-common/ProjectMemberMiddlewareFactory.d.ts.map +0 -1
- package/dist/src/project-common/ProjectMemberMiddlewareFactory.js +0 -29
- package/dist/src/project-common/ProjectMemberMiddlewareFactory.js.map +0 -1
- package/dist/src/project-common/ProjectResolveMiddlewareFactory.d.ts +0 -19
- package/dist/src/project-common/ProjectResolveMiddlewareFactory.d.ts.map +0 -1
- package/dist/src/project-common/ProjectResolveMiddlewareFactory.js +0 -24
- package/dist/src/project-common/ProjectResolveMiddlewareFactory.js.map +0 -1
- package/dist/src/system/SystemGraphQLMiddlewareFactory.d.ts +0 -20
- package/dist/src/system/SystemGraphQLMiddlewareFactory.d.ts.map +0 -1
- package/dist/src/system/SystemGraphQLMiddlewareFactory.js.map +0 -1
- package/dist/src/tenant/TenantGraphQLMiddlewareFactory.d.ts +0 -20
- package/dist/src/tenant/TenantGraphQLMiddlewareFactory.d.ts.map +0 -1
- package/dist/src/tenant/TenantGraphQLMiddlewareFactory.js +0 -46
- package/dist/src/tenant/TenantGraphQLMiddlewareFactory.js.map +0 -1
- package/src/common/ApiMiddleware.ts +0 -24
- package/src/common/AuthMiddleware.ts +0 -56
- package/src/common/ErrorFactory.ts +0 -21
- package/src/content/ContentQueryHandlerProvider.ts +0 -33
- package/src/content/ContentServerMiddleware.ts +0 -40
- package/src/content/NotModifiedMiddlewareFactory.ts +0 -44
- package/src/content/StageResolveMiddlewareFactory.ts +0 -39
- package/src/project-common/ProjectGroupMiddleware.ts +0 -50
- package/src/project-common/ProjectMemberMiddlewareFactory.ts +0 -53
- package/src/project-common/ProjectResolveMiddlewareFactory.ts +0 -43
- package/src/system/SystemGraphQLMiddlewareFactory.ts +0 -100
- package/src/tenant/TenantGraphQLMiddlewareFactory.ts +0 -56
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { ProjectGroupContainer, ProjectGroupContainerResolver } from '../ProjectGroupContainer'
|
|
2
|
+
import { CryptoWrapper } from '../utils/CryptoWrapper'
|
|
3
|
+
import { HttpError } from '../common'
|
|
4
|
+
import { Request } from 'koa'
|
|
5
|
+
|
|
6
|
+
export class ProjectGroupResolver {
|
|
7
|
+
private groupRegex = (
|
|
8
|
+
this.projectGroupDomainMapping
|
|
9
|
+
? new RegExp(
|
|
10
|
+
this.projectGroupDomainMapping.includes('{group}')
|
|
11
|
+
? regexpQuote(this.projectGroupDomainMapping).replace(regexpQuote('{group}'), '([^.]+)')
|
|
12
|
+
: this.projectGroupDomainMapping,
|
|
13
|
+
)
|
|
14
|
+
: undefined
|
|
15
|
+
)
|
|
16
|
+
private projectGroupConfigHeader
|
|
17
|
+
|
|
18
|
+
constructor(
|
|
19
|
+
private projectGroupDomainMapping: string | undefined,
|
|
20
|
+
projectGroupConfigHeader: string | undefined,
|
|
21
|
+
private projectGroupConfigCrypto: CryptoWrapper | undefined,
|
|
22
|
+
private projectGroupContainerResolver: ProjectGroupContainerResolver,
|
|
23
|
+
) {
|
|
24
|
+
this.projectGroupConfigHeader = projectGroupConfigHeader?.toLowerCase()
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async resolveContainer({ request }: { request: Request }): Promise<ProjectGroupContainer> {
|
|
28
|
+
let group: string | undefined = undefined
|
|
29
|
+
let config = {}
|
|
30
|
+
if (this.groupRegex) {
|
|
31
|
+
const match = request.host.match(this.groupRegex)
|
|
32
|
+
if (!match) {
|
|
33
|
+
throw new HttpError('Project group not found', 404)
|
|
34
|
+
}
|
|
35
|
+
group = match[1]
|
|
36
|
+
if (this.projectGroupConfigHeader) {
|
|
37
|
+
const configHeader = request.get(this.projectGroupConfigHeader.toLowerCase())
|
|
38
|
+
if (configHeader === '') {
|
|
39
|
+
throw new HttpError(`${this.projectGroupConfigHeader} header is missing`, 400)
|
|
40
|
+
}
|
|
41
|
+
const configValue = Buffer.from(configHeader, 'base64')
|
|
42
|
+
const decryptedValue = this.projectGroupConfigCrypto ?
|
|
43
|
+
(await this.projectGroupConfigCrypto?.decrypt(configValue, CryptoWrapper.cryptoVersion)).value
|
|
44
|
+
: configValue
|
|
45
|
+
try {
|
|
46
|
+
config = JSON.parse(decryptedValue.toString())
|
|
47
|
+
} catch (e: any) {
|
|
48
|
+
throw new HttpError(`Cannot parse config: ${e.message}`, 400)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return await this.projectGroupContainerResolver.getProjectGroupContainer(group, config)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const regexpQuote = (regexp: string) => regexp.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './ProjectGroupMiddleware'
|
|
1
|
+
export * from './ProjectGroupResolver'
|
|
2
|
+
export * from './ProjectInfoMiddlewareState'
|
package/src/providers.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { v4 as uuidv4 } from 'uuid'
|
|
2
2
|
import bcrypt from 'bcrypt'
|
|
3
|
-
import crypto, { BinaryLike
|
|
3
|
+
import crypto, { BinaryLike } from 'crypto'
|
|
4
4
|
|
|
5
|
-
const cryptoAlgo = 'aes-256-gcm'
|
|
6
5
|
|
|
7
|
-
export const createProviders = (
|
|
6
|
+
export const createProviders = () => ({
|
|
8
7
|
uuid: () => uuidv4(),
|
|
9
8
|
now: () => new Date(),
|
|
10
9
|
bcrypt: async (value: string) => await bcrypt.hash(value, 10),
|
|
@@ -19,22 +18,6 @@ export const createProviders = (args: { encryptionKey?: KeyObject }) => ({
|
|
|
19
18
|
}
|
|
20
19
|
})
|
|
21
20
|
}),
|
|
22
|
-
encrypt: async (value: Buffer): Promise<{ encrypted: Buffer; iv: Buffer }> => {
|
|
23
|
-
if (!args.encryptionKey) {
|
|
24
|
-
throw new Error('encryption key not provided')
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const iv = crypto.randomBytes(16)
|
|
28
|
-
const cipher = crypto.createCipheriv(cryptoAlgo, args.encryptionKey, iv)
|
|
29
|
-
return { encrypted: cipher.update(value), iv }
|
|
30
|
-
},
|
|
31
|
-
decrypt: async (valueEncrypted: Buffer, iv: Buffer): Promise<Buffer> => {
|
|
32
|
-
if (!args.encryptionKey) {
|
|
33
|
-
throw new Error('encryption key not provided')
|
|
34
|
-
}
|
|
35
|
-
const decipher = crypto.createDecipheriv(cryptoAlgo, args.encryptionKey, iv)
|
|
36
|
-
return decipher.update(valueEncrypted)
|
|
37
|
-
},
|
|
38
21
|
hash: (value: BinaryLike, algo: string): Buffer => (
|
|
39
22
|
crypto.createHash(algo).update(value).digest()
|
|
40
23
|
),
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { KoaMiddleware, KoaRequestState } from '../koa'
|
|
2
|
+
import { ProjectGroupResolver, ProjectInfoMiddlewareState } from '../project-common'
|
|
3
|
+
import { AuthResult, HttpError, TimerMiddlewareState } from '../common'
|
|
4
|
+
import { GraphQLKoaState } from '../graphql'
|
|
5
|
+
import { SystemGraphQLContextFactory } from './SystemGraphQLContextFactory'
|
|
6
|
+
|
|
7
|
+
type SystemApiMiddlewareKoaState =
|
|
8
|
+
& TimerMiddlewareState
|
|
9
|
+
& KoaRequestState
|
|
10
|
+
& GraphQLKoaState
|
|
11
|
+
& ProjectInfoMiddlewareState
|
|
12
|
+
& { authResult: AuthResult }
|
|
13
|
+
|
|
14
|
+
export class SystemApiMiddlewareFactory {
|
|
15
|
+
constructor(
|
|
16
|
+
private readonly debug: boolean,
|
|
17
|
+
private readonly projectGroupResolver: ProjectGroupResolver,
|
|
18
|
+
private readonly systemGraphqlContextFactory: SystemGraphQLContextFactory,
|
|
19
|
+
) {
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
create(): KoaMiddleware<SystemApiMiddlewareKoaState> {
|
|
23
|
+
return async koaContext => {
|
|
24
|
+
const { request, response, state: { timer, params } } = koaContext
|
|
25
|
+
const groupContainer = await this.projectGroupResolver.resolveContainer({ request })
|
|
26
|
+
koaContext.state.projectGroup = groupContainer.slug
|
|
27
|
+
const authResult = await groupContainer.authenticator.authenticate({ request, timer })
|
|
28
|
+
koaContext.state.authResult = authResult
|
|
29
|
+
|
|
30
|
+
const projectSlug = params.projectSlug
|
|
31
|
+
const projectContainer = await groupContainer.projectContainerResolver.getProjectContainer(projectSlug, true)
|
|
32
|
+
if (projectContainer === undefined) {
|
|
33
|
+
throw new HttpError(`Project ${projectSlug} NOT found`, 404)
|
|
34
|
+
}
|
|
35
|
+
const project = projectContainer.project
|
|
36
|
+
koaContext.state.project = project.slug
|
|
37
|
+
|
|
38
|
+
const tenantContainer = groupContainer.tenantContainer
|
|
39
|
+
const memberships = await timer('MembershipFetch', () =>
|
|
40
|
+
tenantContainer.projectMemberManager.getProjectMemberships(
|
|
41
|
+
tenantContainer.databaseContext,
|
|
42
|
+
{ slug: project.slug },
|
|
43
|
+
{
|
|
44
|
+
id: authResult.identityId,
|
|
45
|
+
roles: authResult.roles,
|
|
46
|
+
},
|
|
47
|
+
undefined,
|
|
48
|
+
),
|
|
49
|
+
)
|
|
50
|
+
if (memberships.length === 0) {
|
|
51
|
+
throw this.debug
|
|
52
|
+
? new HttpError(`You are not allowed to access project ${project.slug}`, 403)
|
|
53
|
+
: new HttpError(`Project ${project.slug} NOT found`, 404)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
const graphqlContext = await this.systemGraphqlContextFactory.create({
|
|
58
|
+
authResult,
|
|
59
|
+
memberships,
|
|
60
|
+
koaContext,
|
|
61
|
+
projectContainer,
|
|
62
|
+
systemContainer: groupContainer.systemContainer,
|
|
63
|
+
})
|
|
64
|
+
const handler = groupContainer.systemGraphQLHandler
|
|
65
|
+
|
|
66
|
+
await timer('GraphQL', () => handler({
|
|
67
|
+
request,
|
|
68
|
+
response,
|
|
69
|
+
context: graphqlContext,
|
|
70
|
+
}))
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Identity, SystemContainer } from '@contember/engine-system-api'
|
|
2
|
+
import { SystemGraphQLContext } from './SystemGraphQLHandlerFactory'
|
|
3
|
+
import { AuthMiddlewareState, AuthResult } from '../common'
|
|
4
|
+
import { Membership } from '@contember/engine-tenant-api'
|
|
5
|
+
import { KoaContext } from '../koa'
|
|
6
|
+
import { GraphQLKoaState } from '../graphql'
|
|
7
|
+
import { ProjectContainer } from '../ProjectContainer'
|
|
8
|
+
|
|
9
|
+
export class SystemGraphQLContextFactory {
|
|
10
|
+
public async create({ authResult, memberships, koaContext, projectContainer, systemContainer }: {
|
|
11
|
+
authResult: AuthResult
|
|
12
|
+
memberships: readonly Membership[]
|
|
13
|
+
koaContext: KoaContext<GraphQLKoaState & AuthMiddlewareState>
|
|
14
|
+
projectContainer: ProjectContainer
|
|
15
|
+
systemContainer: SystemContainer
|
|
16
|
+
}): Promise<SystemGraphQLContext> {
|
|
17
|
+
const identity = new Identity(
|
|
18
|
+
authResult.identityId,
|
|
19
|
+
memberships.map(it => it.role),
|
|
20
|
+
)
|
|
21
|
+
const dbContextFactory = projectContainer.systemDatabaseContextFactory
|
|
22
|
+
|
|
23
|
+
const systemContext = await systemContainer.resolverContextFactory.create(
|
|
24
|
+
dbContextFactory.create(),
|
|
25
|
+
projectContainer.project,
|
|
26
|
+
identity,
|
|
27
|
+
)
|
|
28
|
+
return {
|
|
29
|
+
...systemContext,
|
|
30
|
+
contentSchemaResolver: projectContainer.contentSchemaResolver,
|
|
31
|
+
koaContext,
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { devTypeDefs, ResolverFactory, SystemResolverContext, typeDefs } from '@contember/engine-system-api'
|
|
2
|
+
import {
|
|
3
|
+
createDbQueriesListener,
|
|
4
|
+
createErrorListener,
|
|
5
|
+
createGraphQLQueryHandler,
|
|
6
|
+
createGraphqlRequestInfoProviderListener,
|
|
7
|
+
ErrorLogger,
|
|
8
|
+
GraphQLKoaState,
|
|
9
|
+
GraphQLListener,
|
|
10
|
+
GraphQLQueryHandler,
|
|
11
|
+
} from '../graphql'
|
|
12
|
+
import { KoaContext } from '../koa'
|
|
13
|
+
import { DocumentNode } from 'graphql'
|
|
14
|
+
import { mergeTypeDefs } from '@graphql-tools/merge'
|
|
15
|
+
import { makeExecutableSchema } from '@graphql-tools/schema'
|
|
16
|
+
import { ContentSchemaResolver } from '../content'
|
|
17
|
+
|
|
18
|
+
type KoaState =
|
|
19
|
+
& GraphQLKoaState
|
|
20
|
+
|
|
21
|
+
export type SystemGraphQLContext = SystemResolverContext & {
|
|
22
|
+
koaContext: KoaContext<KoaState>
|
|
23
|
+
contentSchemaResolver: ContentSchemaResolver
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type SystemGraphQLHandler = GraphQLQueryHandler<SystemGraphQLContext>
|
|
27
|
+
|
|
28
|
+
export class SystemGraphQLHandlerFactory {
|
|
29
|
+
constructor(
|
|
30
|
+
private readonly errorLogger: ErrorLogger,
|
|
31
|
+
private readonly debugMode: boolean,
|
|
32
|
+
) {
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
create(resolversFactory: ResolverFactory): SystemGraphQLHandler {
|
|
36
|
+
const defs: DocumentNode[] = [typeDefs]
|
|
37
|
+
if (this.debugMode) {
|
|
38
|
+
defs.push(devTypeDefs)
|
|
39
|
+
}
|
|
40
|
+
const mergedDefs = mergeTypeDefs(defs)
|
|
41
|
+
const resolvers = resolversFactory.create(this.debugMode)
|
|
42
|
+
const schema = makeExecutableSchema({
|
|
43
|
+
typeDefs: mergedDefs,
|
|
44
|
+
resolvers,
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
const listeners: GraphQLListener<SystemGraphQLContext>[] = [
|
|
48
|
+
createErrorListener((err, ctx) => {
|
|
49
|
+
this.errorLogger(err, {
|
|
50
|
+
body: ctx.koaContext.request.body as string,
|
|
51
|
+
url: ctx.koaContext.request.originalUrl,
|
|
52
|
+
user: ctx.identity.id,
|
|
53
|
+
module: 'system',
|
|
54
|
+
project: ctx.project.slug,
|
|
55
|
+
})
|
|
56
|
+
}),
|
|
57
|
+
createGraphqlRequestInfoProviderListener(),
|
|
58
|
+
]
|
|
59
|
+
if (this.debugMode) {
|
|
60
|
+
listeners.push({
|
|
61
|
+
onResponse: ({ context }) => {
|
|
62
|
+
context.contentSchemaResolver.clearCache()
|
|
63
|
+
},
|
|
64
|
+
})
|
|
65
|
+
listeners.push(createDbQueriesListener(context => context.db.client))
|
|
66
|
+
}
|
|
67
|
+
return createGraphQLQueryHandler<SystemGraphQLContext>({
|
|
68
|
+
schema,
|
|
69
|
+
listeners,
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
}
|
package/src/system/index.ts
CHANGED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { KoaMiddleware, KoaRequestState } from '../koa'
|
|
2
|
+
import { AuthResult, TimerMiddlewareState } from '../common'
|
|
3
|
+
import { GraphQLKoaState } from '../graphql'
|
|
4
|
+
import { ProjectGroupResolver, ProjectInfoMiddlewareState } from '../project-common'
|
|
5
|
+
import { TenantGraphQLContextFactory } from './TenantGraphQLContextFactory'
|
|
6
|
+
|
|
7
|
+
type TenantApiMiddlewareState =
|
|
8
|
+
& TimerMiddlewareState
|
|
9
|
+
& KoaRequestState
|
|
10
|
+
& GraphQLKoaState
|
|
11
|
+
& ProjectInfoMiddlewareState
|
|
12
|
+
& { authResult: AuthResult }
|
|
13
|
+
|
|
14
|
+
export class TenantApiMiddlewareFactory {
|
|
15
|
+
constructor(
|
|
16
|
+
private readonly debug: boolean,
|
|
17
|
+
private readonly projectGroupResolver: ProjectGroupResolver,
|
|
18
|
+
private readonly tenantGraphQLContextFactory: TenantGraphQLContextFactory,
|
|
19
|
+
) {
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
create(): KoaMiddleware<TenantApiMiddlewareState> {
|
|
23
|
+
return async koaContext => {
|
|
24
|
+
const { request, response, state: { timer } } = koaContext
|
|
25
|
+
const groupContainer = await this.projectGroupResolver.resolveContainer({ request })
|
|
26
|
+
koaContext.state.projectGroup = groupContainer.slug
|
|
27
|
+
const authResult = await groupContainer.authenticator.authenticate({ request, timer })
|
|
28
|
+
koaContext.state.authResult = authResult
|
|
29
|
+
const tenantContainer = groupContainer.tenantContainer
|
|
30
|
+
const context = this.tenantGraphQLContextFactory.create({ authResult, tenantContainer, koaContext })
|
|
31
|
+
return await groupContainer.tenantGraphQLHandler({
|
|
32
|
+
request,
|
|
33
|
+
response,
|
|
34
|
+
context,
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { TenantGraphQLContext } from './TenantGraphQLHandlerFactory'
|
|
2
|
+
import { AuthResult } from '../common'
|
|
3
|
+
import { TenantContainer } from '@contember/engine-tenant-api'
|
|
4
|
+
import { KoaContext } from '../koa'
|
|
5
|
+
import { GraphQLKoaState } from '../graphql'
|
|
6
|
+
|
|
7
|
+
export class TenantGraphQLContextFactory {
|
|
8
|
+
public create({ authResult, tenantContainer, koaContext }: {
|
|
9
|
+
tenantContainer: TenantContainer
|
|
10
|
+
authResult: AuthResult
|
|
11
|
+
koaContext: KoaContext<GraphQLKoaState>
|
|
12
|
+
}): TenantGraphQLContext {
|
|
13
|
+
const resolverContextFactory = tenantContainer.resolverContextFactory
|
|
14
|
+
const db = tenantContainer.databaseContext
|
|
15
|
+
const context = resolverContextFactory.create(
|
|
16
|
+
authResult,
|
|
17
|
+
db,
|
|
18
|
+
)
|
|
19
|
+
return {
|
|
20
|
+
...context,
|
|
21
|
+
identityId: authResult.identityId,
|
|
22
|
+
koaContext,
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { makeExecutableSchema } from '@graphql-tools/schema'
|
|
2
|
+
import { Schema, TenantResolverContext, typeDefs } from '@contember/engine-tenant-api'
|
|
3
|
+
import { KoaContext } from '../koa'
|
|
4
|
+
import {
|
|
5
|
+
createErrorListener,
|
|
6
|
+
createGraphQLQueryHandler,
|
|
7
|
+
createGraphqlRequestInfoProviderListener,
|
|
8
|
+
ErrorLogger,
|
|
9
|
+
GraphQLKoaState,
|
|
10
|
+
GraphQLQueryHandler,
|
|
11
|
+
} from '../graphql'
|
|
12
|
+
|
|
13
|
+
export type TenantGraphQLContext = TenantResolverContext & { identityId: string; koaContext: KoaContext<GraphQLKoaState> }
|
|
14
|
+
|
|
15
|
+
export type TenantGraphQLHandler = GraphQLQueryHandler<TenantGraphQLContext>
|
|
16
|
+
|
|
17
|
+
export class TenantGraphQLHandlerFactory {
|
|
18
|
+
constructor(
|
|
19
|
+
private readonly errorLogger: ErrorLogger,
|
|
20
|
+
) {}
|
|
21
|
+
|
|
22
|
+
create(resolvers: Schema.Resolvers): TenantGraphQLHandler {
|
|
23
|
+
const schema = makeExecutableSchema({
|
|
24
|
+
typeDefs,
|
|
25
|
+
resolvers: resolvers,
|
|
26
|
+
resolverValidationOptions: { requireResolversForResolveType: 'ignore' },
|
|
27
|
+
})
|
|
28
|
+
return createGraphQLQueryHandler<TenantGraphQLContext>({
|
|
29
|
+
schema,
|
|
30
|
+
listeners: [
|
|
31
|
+
createErrorListener((err, ctx) => {
|
|
32
|
+
this.errorLogger(err, {
|
|
33
|
+
body: ctx.koaContext.request.body as string,
|
|
34
|
+
url: ctx.koaContext.request.originalUrl,
|
|
35
|
+
user: ctx.identityId,
|
|
36
|
+
module: 'tenant',
|
|
37
|
+
project: undefined,
|
|
38
|
+
})
|
|
39
|
+
}),
|
|
40
|
+
createGraphqlRequestInfoProviderListener(),
|
|
41
|
+
],
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
}
|
package/src/tenant/index.ts
CHANGED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as crypto from 'crypto'
|
|
2
|
+
|
|
3
|
+
export class CryptoWrapper {
|
|
4
|
+
public static cryptoAlgo = 'aes-256-gcm' as const
|
|
5
|
+
public static cryptoVersion = 2
|
|
6
|
+
|
|
7
|
+
constructor(
|
|
8
|
+
private readonly encryptionKey?: crypto.KeyObject,
|
|
9
|
+
) {
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async encrypt(value: Buffer): Promise<{ value: Buffer; version: number }> {
|
|
13
|
+
if (!this.encryptionKey) {
|
|
14
|
+
throw new Error('encryption key not provided')
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const iv = crypto.randomBytes(16)
|
|
18
|
+
const cipher = crypto.createCipheriv(CryptoWrapper.cryptoAlgo, this.encryptionKey, iv)
|
|
19
|
+
return {
|
|
20
|
+
value: Buffer.concat([cipher.update(value), cipher.final(), iv, cipher.getAuthTag()]),
|
|
21
|
+
version: CryptoWrapper.cryptoVersion,
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async decrypt(value: Buffer, version: number): Promise<{ value: Buffer; needsReEncrypt: boolean }> {
|
|
26
|
+
if (!this.encryptionKey) {
|
|
27
|
+
throw new Error('encryption key not provided')
|
|
28
|
+
}
|
|
29
|
+
if (version === 1) {
|
|
30
|
+
const decipher = crypto.createDecipheriv(CryptoWrapper.cryptoAlgo, this.encryptionKey, value.subarray(-16))
|
|
31
|
+
return {
|
|
32
|
+
value: decipher.update(value.subarray(0, -16)),
|
|
33
|
+
needsReEncrypt: true,
|
|
34
|
+
}
|
|
35
|
+
} else if (version === 2) {
|
|
36
|
+
const decipher = crypto.createDecipheriv(CryptoWrapper.cryptoAlgo, this.encryptionKey, value.subarray(-32, -16))
|
|
37
|
+
decipher.setAuthTag(value.subarray(-16))
|
|
38
|
+
return {
|
|
39
|
+
value: Buffer.concat([decipher.update(value.subarray(0, -32)), decipher.final()]),
|
|
40
|
+
needsReEncrypt: false,
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
throw new Error('unsupported version')
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { test } from 'uvu'
|
|
2
|
+
import * as assert from 'uvu/assert'
|
|
3
|
+
import { CryptoWrapper } from '../../../src'
|
|
4
|
+
import * as crypto from 'crypto'
|
|
5
|
+
|
|
6
|
+
const encryptionKey = crypto.createSecretKey(Buffer.from('0000000000000000000000000000000000000000000000000000000000000000', 'hex'))
|
|
7
|
+
const iv = Buffer.alloc(16).fill('a')
|
|
8
|
+
const algorithm = CryptoWrapper.cryptoAlgo
|
|
9
|
+
|
|
10
|
+
const encryptOld = (data: Buffer) => {
|
|
11
|
+
const cipher = crypto.createCipheriv(algorithm, encryptionKey, iv)
|
|
12
|
+
return Buffer.concat([cipher.update(data), iv])
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
test('encryption v1 16 chars string (block size)', async () => {
|
|
16
|
+
const cryptoWrapper = new CryptoWrapper(encryptionKey)
|
|
17
|
+
const input = 'a'.repeat(16)
|
|
18
|
+
const inputBuffer = Buffer.from(input)
|
|
19
|
+
assert.is(inputBuffer.length, 16)
|
|
20
|
+
const value = encryptOld(inputBuffer)
|
|
21
|
+
const decrypted = await cryptoWrapper.decrypt(value, 1)
|
|
22
|
+
assert.is(decrypted.needsReEncrypt, true)
|
|
23
|
+
assert.is(decrypted.value.toString(), input)
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
test('encryption v1 17 chars string', async () => {
|
|
27
|
+
const cryptoWrapper = new CryptoWrapper(encryptionKey)
|
|
28
|
+
const input = 'a'.repeat(17)
|
|
29
|
+
const inputBuffer = Buffer.from(input)
|
|
30
|
+
assert.is(inputBuffer.length, 17)
|
|
31
|
+
const value = encryptOld(inputBuffer)
|
|
32
|
+
const decrypted = await cryptoWrapper.decrypt(value, 1)
|
|
33
|
+
assert.is(decrypted.needsReEncrypt, true)
|
|
34
|
+
assert.is(decrypted.value.toString(), input)
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
test('encryption v2 16 chars string (block size)', async () => {
|
|
39
|
+
const cryptoWrapper = new CryptoWrapper(encryptionKey)
|
|
40
|
+
const input = 'a'.repeat(16)
|
|
41
|
+
const inputBuffer = Buffer.from(input)
|
|
42
|
+
assert.is(inputBuffer.length, 16)
|
|
43
|
+
const value = await cryptoWrapper.encrypt(inputBuffer)
|
|
44
|
+
assert.is(value.version, 2)
|
|
45
|
+
const decrypted = await cryptoWrapper.decrypt(value.value, value.version)
|
|
46
|
+
assert.is(decrypted.needsReEncrypt, false)
|
|
47
|
+
assert.is(decrypted.value.toString(), input)
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
test('encryption v2 17 chars string', async () => {
|
|
52
|
+
const cryptoWrapper = new CryptoWrapper(encryptionKey)
|
|
53
|
+
const input = 'a'.repeat(17)
|
|
54
|
+
const inputBuffer = Buffer.from(input)
|
|
55
|
+
assert.is(inputBuffer.length, 17)
|
|
56
|
+
const value = await cryptoWrapper.encrypt(inputBuffer)
|
|
57
|
+
assert.is(value.version, 2)
|
|
58
|
+
const decrypted = await cryptoWrapper.decrypt(value.value, value.version)
|
|
59
|
+
assert.is(decrypted.needsReEncrypt, false)
|
|
60
|
+
assert.is(decrypted.value.toString(), input)
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
test('encryption v2: corrupted auth key', async () => {
|
|
64
|
+
const cryptoWrapper = new CryptoWrapper(encryptionKey)
|
|
65
|
+
const inputBuffer = Buffer.from('a')
|
|
66
|
+
const value = await cryptoWrapper.encrypt(inputBuffer)
|
|
67
|
+
let err: any = { message: 'not failed' }
|
|
68
|
+
try {
|
|
69
|
+
const corrupted = Buffer.concat([value.value.subarray(0, -1), Buffer.alloc(1)])
|
|
70
|
+
await cryptoWrapper.decrypt(corrupted, value.version)
|
|
71
|
+
} catch (e) {
|
|
72
|
+
err = e
|
|
73
|
+
}
|
|
74
|
+
assert.is('Unsupported state or unable to authenticate data', err.message)
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
test.run()
|
package/tsconfig.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ProjectConfig.d.ts","sourceRoot":"","sources":["../../src/ProjectConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AAEzD,oBAAY,aAAa,GAAG;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,MAAM,EAAE,WAAW,EAAE,CAAA;IAC9B,QAAQ,CAAC,EAAE,EAAE,mBAAmB,CAAA;CAChC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAE3B,MAAM,WAAW,WAAW;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CACrB;AAED,oBAAY,qBAAqB,GAAG,CACnC,IAAI,EAAE,MAAM,EACZ,gBAAgB,EAAE,GAAG,EACrB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAC3B,aAAa,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ProjectConfig.js","sourceRoot":"","sources":["../../src/ProjectConfig.ts"],"names":[],"mappings":""}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { KoaMiddleware } from '../koa';
|
|
2
|
-
import { AuthMiddlewareFactory } from './AuthMiddleware';
|
|
3
|
-
import { ProjectGroupMiddlewareFactory } from '../project-common';
|
|
4
|
-
declare type KoaState = unknown;
|
|
5
|
-
export declare class ApiMiddlewareFactory {
|
|
6
|
-
private readonly projectGroupMiddlewareFactory;
|
|
7
|
-
private readonly authMiddlewareFactory;
|
|
8
|
-
constructor(projectGroupMiddlewareFactory: ProjectGroupMiddlewareFactory, authMiddlewareFactory: AuthMiddlewareFactory);
|
|
9
|
-
create(module: string): KoaMiddleware<KoaState>;
|
|
10
|
-
}
|
|
11
|
-
export {};
|
|
12
|
-
//# sourceMappingURL=ApiMiddleware.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ApiMiddleware.d.ts","sourceRoot":"","sources":["../../../src/common/ApiMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,aAAa,EAAE,MAAM,QAAQ,CAAA;AAG/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAA;AACxD,OAAO,EAAE,6BAA6B,EAAE,MAAM,mBAAmB,CAAA;AAEjE,aAAK,QAAQ,GAAG,OAAO,CAAA;AAEvB,qBAAa,oBAAoB;IAE/B,OAAO,CAAC,QAAQ,CAAC,6BAA6B;IAC9C,OAAO,CAAC,QAAQ,CAAC,qBAAqB;gBADrB,6BAA6B,EAAE,6BAA6B,EAC5D,qBAAqB,EAAE,qBAAqB;IAIvD,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC,QAAQ,CAAC;CAQtD"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ApiMiddlewareFactory = void 0;
|
|
7
|
-
const koa_1 = require("../koa");
|
|
8
|
-
const ModuleInfoMiddleware_1 = require("./ModuleInfoMiddleware");
|
|
9
|
-
const cors_1 = __importDefault(require("@koa/cors"));
|
|
10
|
-
class ApiMiddlewareFactory {
|
|
11
|
-
constructor(projectGroupMiddlewareFactory, authMiddlewareFactory) {
|
|
12
|
-
this.projectGroupMiddlewareFactory = projectGroupMiddlewareFactory;
|
|
13
|
-
this.authMiddlewareFactory = authMiddlewareFactory;
|
|
14
|
-
}
|
|
15
|
-
create(module) {
|
|
16
|
-
return (0, koa_1.compose)([
|
|
17
|
-
this.projectGroupMiddlewareFactory.create(),
|
|
18
|
-
(0, ModuleInfoMiddleware_1.createModuleInfoMiddleware)(module),
|
|
19
|
-
(0, cors_1.default)(),
|
|
20
|
-
this.authMiddlewareFactory.create(),
|
|
21
|
-
]);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
exports.ApiMiddlewareFactory = ApiMiddlewareFactory;
|
|
25
|
-
//# sourceMappingURL=ApiMiddleware.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ApiMiddleware.js","sourceRoot":"","sources":["../../../src/common/ApiMiddleware.ts"],"names":[],"mappings":";;;;;;AAAA,gCAA+C;AAC/C,iEAAmE;AACnE,qDAAsC;AAMtC,MAAa,oBAAoB;IAChC,YACkB,6BAA4D,EAC5D,qBAA4C;QAD5C,kCAA6B,GAA7B,6BAA6B,CAA+B;QAC5D,0BAAqB,GAArB,qBAAqB,CAAuB;IAE9D,CAAC;IAEM,MAAM,CAAC,MAAc;QAC3B,OAAO,IAAA,aAAO,EAAC;YACd,IAAI,CAAC,6BAA6B,CAAC,MAAM,EAAE;YAC3C,IAAA,iDAA0B,EAAC,MAAM,CAAC;YAClC,IAAA,cAAc,GAAE;YAChB,IAAI,CAAC,qBAAqB,CAAC,MAAM,EAAE;SACnC,CAAC,CAAA;IACH,CAAC;CACD;AAfD,oDAeC"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { ApiKeyManager, VerifyResult } from '@contember/engine-tenant-api';
|
|
2
|
-
import { KoaMiddleware } from '../koa';
|
|
3
|
-
import { TimerMiddlewareState } from './TimerMiddleware';
|
|
4
|
-
import { ErrorFactory } from './ErrorFactory';
|
|
5
|
-
import { ProjectGroupState } from '../project-common';
|
|
6
|
-
declare type InputState = TimerMiddlewareState;
|
|
7
|
-
declare type KoaState = InputState & AuthMiddlewareState & ProjectGroupState;
|
|
8
|
-
export interface AuthMiddlewareState {
|
|
9
|
-
authResult: VerifyResult & {
|
|
10
|
-
assumedIdentityId?: string;
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
export declare class AuthMiddlewareFactory {
|
|
14
|
-
private readonly apiKeyManager;
|
|
15
|
-
private readonly errorFactory;
|
|
16
|
-
constructor(apiKeyManager: ApiKeyManager, errorFactory: ErrorFactory);
|
|
17
|
-
create(): KoaMiddleware<KoaState>;
|
|
18
|
-
}
|
|
19
|
-
export {};
|
|
20
|
-
//# sourceMappingURL=AuthMiddleware.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AuthMiddleware.d.ts","sourceRoot":"","sources":["../../../src/common/AuthMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAC1E,OAAO,EAAc,aAAa,EAAE,MAAM,QAAQ,CAAA;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAA;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAErD,aAAK,UAAU,GACZ,oBAAoB,CAAA;AAEvB,aAAK,QAAQ,GACV,UAAU,GACV,mBAAmB,GACnB,iBAAiB,CAAA;AAEpB,MAAM,WAAW,mBAAmB;IACnC,UAAU,EAAE,YAAY,GAAG;QAAE,iBAAiB,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CACzD;AAID,qBAAa,qBAAqB;IAEhC,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,YAAY;gBADZ,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,YAAY;IAIrC,MAAM,IAAI,aAAa,CAAC,QAAQ,CAAC;CA4BxC"}
|