@things-factory/auth-base 8.0.0-beta.1 → 8.0.0-beta.2

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.
Files changed (142) hide show
  1. package/package.json +6 -6
  2. package/client/actions/auth.ts +0 -24
  3. package/client/auth.ts +0 -272
  4. package/client/bootstrap.ts +0 -47
  5. package/client/directive/privileged.ts +0 -28
  6. package/client/index.ts +0 -4
  7. package/client/profiled.ts +0 -83
  8. package/client/reducers/auth.ts +0 -31
  9. package/client/verify-webauthn.ts +0 -86
  10. package/server/constants/error-code.ts +0 -22
  11. package/server/constants/error-message.ts +0 -0
  12. package/server/constants/max-age.ts +0 -1
  13. package/server/controllers/auth.ts +0 -5
  14. package/server/controllers/change-pwd.ts +0 -100
  15. package/server/controllers/checkin.ts +0 -21
  16. package/server/controllers/delete-user.ts +0 -71
  17. package/server/controllers/invitation.ts +0 -163
  18. package/server/controllers/profile.ts +0 -55
  19. package/server/controllers/reset-password.ts +0 -126
  20. package/server/controllers/signin.ts +0 -98
  21. package/server/controllers/signup.ts +0 -72
  22. package/server/controllers/unlock-user.ts +0 -62
  23. package/server/controllers/utils/make-invitation-token.ts +0 -5
  24. package/server/controllers/utils/make-verification-token.ts +0 -4
  25. package/server/controllers/utils/password-rule.ts +0 -120
  26. package/server/controllers/utils/save-invitation-token.ts +0 -10
  27. package/server/controllers/utils/save-verification-token.ts +0 -12
  28. package/server/controllers/verification.ts +0 -84
  29. package/server/errors/auth-error.ts +0 -24
  30. package/server/errors/index.ts +0 -2
  31. package/server/errors/user-domain-not-match-error.ts +0 -29
  32. package/server/index.ts +0 -37
  33. package/server/middlewares/authenticate-401-middleware.ts +0 -114
  34. package/server/middlewares/domain-authenticate-middleware.ts +0 -78
  35. package/server/middlewares/graphql-authenticate-middleware.ts +0 -13
  36. package/server/middlewares/index.ts +0 -67
  37. package/server/middlewares/jwt-authenticate-middleware.ts +0 -84
  38. package/server/middlewares/signin-middleware.ts +0 -55
  39. package/server/middlewares/webauthn-middleware.ts +0 -126
  40. package/server/migrations/1548206416130-SeedUser.ts +0 -60
  41. package/server/migrations/1566805283882-SeedPrivilege.ts +0 -28
  42. package/server/migrations/index.ts +0 -9
  43. package/server/router/auth-checkin-router.ts +0 -113
  44. package/server/router/auth-private-process-router.ts +0 -114
  45. package/server/router/auth-public-process-router.ts +0 -314
  46. package/server/router/auth-signin-router.ts +0 -55
  47. package/server/router/auth-signup-router.ts +0 -95
  48. package/server/router/index.ts +0 -9
  49. package/server/router/oauth2/index.ts +0 -2
  50. package/server/router/oauth2/oauth2-authorize-router.ts +0 -81
  51. package/server/router/oauth2/oauth2-router.ts +0 -165
  52. package/server/router/oauth2/oauth2-server.ts +0 -262
  53. package/server/router/oauth2/passport-oauth2-client-password.ts +0 -87
  54. package/server/router/oauth2/passport-refresh-token.ts +0 -87
  55. package/server/router/path-base-domain-router.ts +0 -8
  56. package/server/router/site-root-router.ts +0 -48
  57. package/server/router/webauthn-router.ts +0 -149
  58. package/server/routes.ts +0 -80
  59. package/server/service/app-binding/app-binding-mutation.ts +0 -22
  60. package/server/service/app-binding/app-binding-query.ts +0 -92
  61. package/server/service/app-binding/app-binding-types.ts +0 -11
  62. package/server/service/app-binding/app-binding.ts +0 -17
  63. package/server/service/app-binding/index.ts +0 -4
  64. package/server/service/appliance/appliance-mutation.ts +0 -113
  65. package/server/service/appliance/appliance-query.ts +0 -76
  66. package/server/service/appliance/appliance-types.ts +0 -56
  67. package/server/service/appliance/appliance.ts +0 -133
  68. package/server/service/appliance/index.ts +0 -6
  69. package/server/service/application/application-mutation.ts +0 -104
  70. package/server/service/application/application-query.ts +0 -98
  71. package/server/service/application/application-types.ts +0 -76
  72. package/server/service/application/application.ts +0 -216
  73. package/server/service/application/index.ts +0 -6
  74. package/server/service/auth-provider/auth-provider-mutation.ts +0 -159
  75. package/server/service/auth-provider/auth-provider-parameter-spec.ts +0 -24
  76. package/server/service/auth-provider/auth-provider-query.ts +0 -88
  77. package/server/service/auth-provider/auth-provider-type.ts +0 -67
  78. package/server/service/auth-provider/auth-provider.ts +0 -155
  79. package/server/service/auth-provider/index.ts +0 -7
  80. package/server/service/domain-generator/domain-generator-mutation.ts +0 -117
  81. package/server/service/domain-generator/domain-generator-types.ts +0 -46
  82. package/server/service/domain-generator/index.ts +0 -3
  83. package/server/service/granted-role/granted-role-mutation.ts +0 -156
  84. package/server/service/granted-role/granted-role-query.ts +0 -60
  85. package/server/service/granted-role/granted-role.ts +0 -27
  86. package/server/service/granted-role/index.ts +0 -6
  87. package/server/service/index.ts +0 -90
  88. package/server/service/invitation/index.ts +0 -6
  89. package/server/service/invitation/invitation-mutation.ts +0 -78
  90. package/server/service/invitation/invitation-query.ts +0 -33
  91. package/server/service/invitation/invitation-types.ts +0 -11
  92. package/server/service/invitation/invitation.ts +0 -63
  93. package/server/service/login-history/index.ts +0 -5
  94. package/server/service/login-history/login-history-query.ts +0 -51
  95. package/server/service/login-history/login-history-type.ts +0 -12
  96. package/server/service/login-history/login-history.ts +0 -45
  97. package/server/service/partner/index.ts +0 -6
  98. package/server/service/partner/partner-mutation.ts +0 -61
  99. package/server/service/partner/partner-query.ts +0 -102
  100. package/server/service/partner/partner-types.ts +0 -11
  101. package/server/service/partner/partner.ts +0 -57
  102. package/server/service/password-history/index.ts +0 -3
  103. package/server/service/password-history/password-history.ts +0 -16
  104. package/server/service/privilege/index.ts +0 -6
  105. package/server/service/privilege/privilege-directive.ts +0 -77
  106. package/server/service/privilege/privilege-mutation.ts +0 -92
  107. package/server/service/privilege/privilege-query.ts +0 -94
  108. package/server/service/privilege/privilege-types.ts +0 -60
  109. package/server/service/privilege/privilege.ts +0 -102
  110. package/server/service/role/index.ts +0 -6
  111. package/server/service/role/role-mutation.ts +0 -109
  112. package/server/service/role/role-query.ts +0 -155
  113. package/server/service/role/role-types.ts +0 -81
  114. package/server/service/role/role.ts +0 -72
  115. package/server/service/user/domain-query.ts +0 -24
  116. package/server/service/user/index.ts +0 -7
  117. package/server/service/user/user-mutation.ts +0 -482
  118. package/server/service/user/user-query.ts +0 -145
  119. package/server/service/user/user-types.ts +0 -100
  120. package/server/service/user/user.ts +0 -381
  121. package/server/service/users-auth-providers/index.ts +0 -5
  122. package/server/service/users-auth-providers/users-auth-providers.ts +0 -71
  123. package/server/service/verification-token/index.ts +0 -3
  124. package/server/service/verification-token/verification-token.ts +0 -60
  125. package/server/service/web-auth-credential/index.ts +0 -3
  126. package/server/service/web-auth-credential/web-auth-credential.ts +0 -67
  127. package/server/templates/account-unlock-email.ts +0 -65
  128. package/server/templates/invitation-email.ts +0 -66
  129. package/server/templates/reset-password-email.ts +0 -65
  130. package/server/templates/verification-email.ts +0 -66
  131. package/server/types.ts +0 -21
  132. package/server/utils/accepts.ts +0 -11
  133. package/server/utils/access-token-cookie.ts +0 -61
  134. package/server/utils/check-permission.ts +0 -52
  135. package/server/utils/check-user-belongs-domain.ts +0 -19
  136. package/server/utils/check-user-has-role.ts +0 -29
  137. package/server/utils/encrypt-state.ts +0 -22
  138. package/server/utils/get-aes-256-key.ts +0 -13
  139. package/server/utils/get-domain-from-hostname.ts +0 -7
  140. package/server/utils/get-domain-users.ts +0 -38
  141. package/server/utils/get-secret.ts +0 -13
  142. package/server/utils/get-user-domains.ts +0 -112
@@ -1,133 +0,0 @@
1
- import {
2
- Column,
3
- CreateDateColumn,
4
- Entity,
5
- Index,
6
- ManyToOne,
7
- PrimaryGeneratedColumn,
8
- RelationId,
9
- UpdateDateColumn
10
- } from 'typeorm'
11
- import { Directive, Field, ID, ObjectType } from 'type-graphql'
12
- import { User, UserStatus } from '../user/user'
13
-
14
- import { Domain } from '@things-factory/shell'
15
- import { SECRET } from '../../utils/get-secret'
16
- import { config } from '@things-factory/env'
17
- import jwt from 'jsonwebtoken'
18
-
19
- const ORMCONFIG = config.get('ormconfig', {})
20
- const DATABASE_TYPE = ORMCONFIG.type
21
-
22
- @Entity()
23
- @Index('ix_appliance_0', (appliance: Appliance) => [appliance.domain, appliance.name], {
24
- unique: true
25
- })
26
- @ObjectType()
27
- export class Appliance {
28
- @PrimaryGeneratedColumn('uuid')
29
- @Field(type => ID)
30
- readonly id: string
31
-
32
- @ManyToOne(type => Domain)
33
- @Field(type => Domain)
34
- domain?: Domain
35
-
36
- @RelationId((appliance: Appliance) => appliance.domain)
37
- domainId: string
38
-
39
- @Column({
40
- nullable: true
41
- })
42
- @Field({ nullable: true })
43
- serialNo: string
44
-
45
- @Column()
46
- @Field()
47
- name: string
48
-
49
- @Column()
50
- @Field({ nullable: true })
51
- brand: string
52
-
53
- @Column()
54
- @Field({ nullable: true })
55
- model: string
56
-
57
- @Column({
58
- nullable: true
59
- })
60
- @Field({ nullable: true })
61
- netmask: string
62
-
63
- @Column({
64
- nullable: true
65
- })
66
- @Field({ nullable: true })
67
- description: string
68
-
69
- @Column({
70
- nullable: true,
71
- type:
72
- DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'
73
- ? 'longtext'
74
- : DATABASE_TYPE == 'oracle'
75
- ? 'clob'
76
- : DATABASE_TYPE == 'mssql'
77
- ? 'nvarchar'
78
- : 'varchar',
79
- length: DATABASE_TYPE == 'mssql' ? 'MAX' : undefined
80
- })
81
- @Field({ nullable: true })
82
- @Directive('@privilege(category: "security", privilege: "query", domainOwnerGranted: true)')
83
- accessToken: string
84
-
85
- @ManyToOne(type => User, { nullable: true })
86
- @Field({ nullable: true })
87
- creator: User
88
-
89
- @RelationId((appliance: Appliance) => appliance.creator)
90
- creatorId: string
91
-
92
- @ManyToOne(type => User, { nullable: true })
93
- @Field({ nullable: true })
94
- updater: User
95
-
96
- @RelationId((appliance: Appliance) => appliance.updater)
97
- updaterId: string
98
-
99
- @CreateDateColumn()
100
- @Field({ nullable: true })
101
- createdAt: Date
102
-
103
- @UpdateDateColumn()
104
- @Field({ nullable: true })
105
- updatedAt: Date
106
-
107
- /* signing for jsonwebtoken */
108
- static sign(subject, expiresIn, domain, user, appliance) {
109
- var credential = {
110
- id: user.id,
111
- userType: 'appliance',
112
- appliance: {
113
- id: appliance.id
114
- },
115
- status: UserStatus.ACTIVATED,
116
- domain: {
117
- subdomain: domain.subdomain
118
- }
119
- }
120
-
121
- return jwt.sign(credential, SECRET, {
122
- expiresIn,
123
- issuer: 'hatiolab.com',
124
- subject
125
- })
126
- }
127
-
128
- static generateAccessToken(domain, user, appliance) {
129
- /* how to set expiresIn https://github.com/vercel/ms */
130
- let expiresIn = config.get('applianceJwtExpiresIn', '1y')
131
- return this.sign('access-token', expiresIn, domain, user, appliance)
132
- }
133
- }
@@ -1,6 +0,0 @@
1
- import { Appliance } from './appliance'
2
- import { ApplianceQuery } from './appliance-query'
3
- import { ApplianceMutation } from './appliance-mutation'
4
-
5
- export const entities = [Appliance]
6
- export const resolvers = [ApplianceQuery, ApplianceMutation]
@@ -1,104 +0,0 @@
1
- import { Directive, Arg, Ctx, Mutation, Resolver } from 'type-graphql'
2
-
3
- import { getRepository } from '@things-factory/shell'
4
-
5
- import { User } from '../user/user'
6
- import { Application } from './application'
7
- import { AccessToken, ApplicationPatch, NewApplication } from './application-types'
8
-
9
- @Resolver(Application)
10
- export class ApplicationMutation {
11
- @Directive('@privilege(category: "user", privilege: "mutation", domainOwnerGranted: true)')
12
- @Mutation(returns => Application, { description: 'To create new application' })
13
- async createApplication(@Arg('application') application: NewApplication, @Ctx() context: ResolverContext) {
14
- const { domain } = context.state
15
- return await getRepository(Application).save({
16
- ...application,
17
- domain,
18
- appKey: Application.generateAppKey(),
19
- appSecret: Application.generateAppSecret(),
20
- creator: context.state.user,
21
- updater: context.state.user
22
- })
23
- }
24
-
25
- @Directive('@privilege(category: "user", privilege: "mutation", domainOwnerGranted: true)')
26
- @Mutation(returns => Boolean, { description: 'To delete application' })
27
- async deleteApplication(@Arg('id') id: string, @Ctx() context: ResolverContext) {
28
- const { domain } = context.state
29
- await getRepository(Application).delete({
30
- domain: { id: domain.id },
31
- id
32
- })
33
- return true
34
- }
35
-
36
- @Directive('@privilege(category: "security", privilege: "mutation", domainOwnerGranted: true)')
37
- @Mutation(returns => Application)
38
- async generateApplicationSecret(@Arg('id') id: string, @Ctx() context: ResolverContext) {
39
- const { domain } = context.state
40
- const repository = getRepository(Application)
41
- const application = await repository.findOneBy({ domain: { id: domain.id }, id })
42
-
43
- return await repository.save({
44
- ...application,
45
- appSecret: Application.generateAppSecret(),
46
- updater: context.state.user
47
- })
48
- }
49
-
50
- @Directive('@privilege(category: "security", privilege: "mutation", domainOwnerGranted: true)')
51
- @Mutation(returns => AccessToken)
52
- async renewApplicationAccessToken(
53
- @Arg('id') id: string,
54
- @Ctx() context: ResolverContext,
55
- @Arg('scope') scope?: string
56
- ) {
57
- const { domain } = context.state
58
-
59
- var appuser: User = await getRepository(User).findOneBy({
60
- id,
61
- userType: 'application'
62
- })
63
-
64
- if (!appuser) {
65
- throw new Error('application is not bound')
66
- }
67
-
68
- const repository = getRepository(Application)
69
- const application = await repository.findOneBy({ id: appuser.reference })
70
- if (!application) {
71
- throw new Error('application not found')
72
- }
73
-
74
- var accessToken = Application.generateAccessToken(domain, appuser, application.appSecret, scope || '')
75
- var refreshToken = Application.generateRefreshToken(domain, appuser, application.appSecret, scope || '')
76
-
77
- await getRepository(User).save({
78
- ...(appuser as any),
79
- password: refreshToken
80
- })
81
-
82
- return {
83
- accessToken,
84
- refreshToken
85
- }
86
- }
87
-
88
- @Directive('@privilege(category: "user", privilege: "mutation", domainOwnerGranted: true)')
89
- @Mutation(returns => Application)
90
- async updateApplication(
91
- @Arg('id') id: string,
92
- @Arg('patch') patch: ApplicationPatch,
93
- @Ctx() context: ResolverContext
94
- ) {
95
- const repository = getRepository(Application)
96
- const application = await repository.findOneBy({ id })
97
-
98
- return await repository.save({
99
- ...application,
100
- ...patch,
101
- updater: context.state.user
102
- })
103
- }
104
- }
@@ -1,98 +0,0 @@
1
- import { Directive, Arg, Args, Ctx, FieldResolver, Query, Resolver, Root } from 'type-graphql'
2
- import { SelectQueryBuilder } from 'typeorm'
3
- import { URL } from 'url'
4
-
5
- import { config } from '@things-factory/env'
6
- import { getQueryBuilderFromListParams, Domain, getRepository, ListParam } from '@things-factory/shell'
7
-
8
- import { Role } from '../role/role'
9
- import { User } from '../user/user'
10
- import { Application } from './application'
11
- import { ApplicationList } from './application-types'
12
-
13
- const protocol: string = config.get('protocol')
14
-
15
- @Resolver(Application)
16
- export class ApplicationQuery {
17
- @Directive('@privilege(category: "user", privilege: "query", domainOwnerGranted: true, superUserGranted: true)')
18
- @Query(returns => Application, { description: 'To fetch application' })
19
- async application(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Application> {
20
- const repository = getRepository(Application)
21
-
22
- return await repository.findOneBy({ id })
23
- }
24
-
25
- @Directive('@privilege(category: "user", privilege: "query", domainOwnerGranted: true, superUserGranted: true)')
26
- @Query(returns => ApplicationList, { description: 'To fetch multiple application' })
27
- async applications(@Args(type => ListParam) params: ListParam, @Ctx() context: ResolverContext) {
28
- const { domain } = context.state
29
-
30
- const queryBuilder = getQueryBuilderFromListParams({
31
- domain,
32
- params,
33
- repository: getRepository(Application),
34
- alias: 'application',
35
- searchables: ['name', 'description']
36
- })
37
-
38
- const [items, total] = await queryBuilder.getManyAndCount()
39
-
40
- return { items, total }
41
- }
42
-
43
- @FieldResolver(type => String)
44
- async availableScopes(@Ctx() context: ResolverContext): Promise<string> {
45
- const { domain } = context.state
46
- const roles = await getRepository(Role).findBy({ domain: { id: domain.id } })
47
-
48
- return roles.map((role: Role) => role.name).join(' ')
49
- }
50
-
51
- @FieldResolver(type => String)
52
- async accessTokenUrl(@Ctx() context: ResolverContext): Promise<string> {
53
- return buildAuthURL('/oauth/access-token', context)
54
- }
55
-
56
- @FieldResolver(type => String)
57
- async authUrl(@Ctx() context: ResolverContext): Promise<string> {
58
- return buildAuthURL('/oauth/authorize', context)
59
- }
60
-
61
- @FieldResolver(type => Domain)
62
- async domain(@Ctx() context: ResolverContext) {
63
- return context.state.domain
64
- }
65
-
66
- @FieldResolver(type => User)
67
- async updater(@Root() application: Application): Promise<User> {
68
- return await getRepository(User).findOneBy({ id: application.updaterId })
69
- }
70
-
71
- @FieldResolver(type => User)
72
- async creator(@Root() application: Application): Promise<User> {
73
- return await getRepository(User).findOneBy({ id: application.creatorId })
74
- }
75
- }
76
-
77
- function buildAuthURL(pathname: string, context: ResolverContext): string {
78
- const originalProtocol = context.headers['x-forwarded-proto']
79
- const originalHost = context.headers['x-forwarded-host']
80
- const originalPort = context.headers['x-forwarded-port']
81
-
82
- if (originalProtocol && originalHost) {
83
- var url: URL = new URL(`${originalProtocol}://${originalHost}`)
84
- if (originalPort) {
85
- url.port = originalPort
86
- }
87
- } else {
88
- var url: URL = new URL(context.request.origin)
89
- }
90
-
91
- if (protocol) {
92
- url.protocol = protocol
93
- }
94
-
95
- url.pathname = pathname
96
-
97
- return url.href
98
- }
@@ -1,76 +0,0 @@
1
- import { Field, InputType, Int, ObjectType } from 'type-graphql'
2
- import { GraphQLEmailAddress } from 'graphql-scalars'
3
-
4
- import { Application, ApplicationType } from './application'
5
-
6
- @ObjectType()
7
- export class AccessToken {
8
- @Field()
9
- accesToken: string
10
-
11
- @Field()
12
- refreshToken: string
13
- }
14
-
15
- @ObjectType()
16
- export class ApplicationList {
17
- @Field(type => [Application], { nullable: true })
18
- items?: Application[]
19
-
20
- @Field(type => Int, { nullable: true })
21
- total?: number
22
- }
23
-
24
- @InputType()
25
- export class ApplicationPatch {
26
- @Field({ nullable: true })
27
- name?: string
28
-
29
- @Field({ nullable: true })
30
- description?: string
31
-
32
- @Field(type => GraphQLEmailAddress, { nullable: true })
33
- email?: string
34
-
35
- @Field({ nullable: true })
36
- url?: string
37
-
38
- @Field({ nullable: true })
39
- icon?: string
40
-
41
- @Field({ nullable: true })
42
- redirectUrl?: string
43
-
44
- @Field({ nullable: true })
45
- webhook?: string
46
-
47
- @Field(type => ApplicationType, { nullable: true })
48
- type?: ApplicationType
49
- }
50
-
51
- @InputType()
52
- export class NewApplication {
53
- @Field()
54
- name: string
55
-
56
- @Field({ nullable: true })
57
- description?: string
58
-
59
- @Field(type => GraphQLEmailAddress, { nullable: true })
60
- email?: string
61
-
62
- @Field({ nullable: true })
63
- url?: string
64
-
65
- @Field({ nullable: true })
66
- icon?: string
67
-
68
- @Field({ nullable: true })
69
- redirectUrl?: string
70
-
71
- @Field({ nullable: true })
72
- webhook?: string
73
-
74
- @Field(type => ApplicationType, { nullable: true })
75
- type?: ApplicationType
76
- }
@@ -1,216 +0,0 @@
1
- import crypto from 'crypto'
2
- import jwt from 'jsonwebtoken'
3
- import { Directive, Field, ID, ObjectType, registerEnumType } from 'type-graphql'
4
- import { GraphQLEmailAddress } from 'graphql-scalars'
5
- import {
6
- Column,
7
- CreateDateColumn,
8
- Entity,
9
- Index,
10
- ManyToOne,
11
- PrimaryGeneratedColumn,
12
- RelationId,
13
- UpdateDateColumn
14
- } from 'typeorm'
15
-
16
- import { config } from '@things-factory/env'
17
- import { Domain } from '@things-factory/shell'
18
-
19
- import { SECRET } from '../../utils/get-secret'
20
- import { User, UserStatus } from '../user/user'
21
-
22
- const ORMCONFIG = config.get('ormconfig', {})
23
- const DATABASE_TYPE = ORMCONFIG.type
24
-
25
- export enum ApplicationStatus {
26
- DRAFT = 'DRAFT',
27
- ACTIVATED = 'ACTIVATED'
28
- }
29
-
30
- registerEnumType(ApplicationStatus, {
31
- name: 'ApplicationStatus',
32
- description: 'state enumeration of a application'
33
- })
34
-
35
- export enum ApplicationType {
36
- SELLERCRAFT = 'SELLERCRAFT',
37
- XILNEX = 'XILNEX',
38
- MMS = 'MMS',
39
- XERO = 'XERO',
40
- OTHERS = 'OTHERS',
41
- SFTP = 'SFTP'
42
- }
43
-
44
- registerEnumType(ApplicationType, {
45
- name: 'ApplicationType',
46
- description: 'state enumeration of a application'
47
- })
48
- @Entity()
49
- @Index('ix_application_0', (application: Application) => [application.appKey], { unique: true })
50
- @ObjectType()
51
- export class Application {
52
- @PrimaryGeneratedColumn('uuid')
53
- @Field(type => ID)
54
- readonly id?: string
55
-
56
- @ManyToOne(type => Domain)
57
- @Field(type => Domain)
58
- domain?: Domain
59
-
60
- @RelationId((application: Application) => application.domain)
61
- domainId?: string
62
-
63
- @Column()
64
- @Field()
65
- name?: string
66
-
67
- @Column({ nullable: true })
68
- @Field({ nullable: true })
69
- description?: string
70
-
71
- @Column()
72
- @Field(type => GraphQLEmailAddress)
73
- email?: string
74
-
75
- @Column()
76
- @Field()
77
- url?: string
78
-
79
- @Column({ nullable: true })
80
- @Field({ nullable: true })
81
- icon?: string
82
-
83
- @Column()
84
- @Field()
85
- redirectUrl?: string
86
-
87
- @Column({ nullable: true })
88
- @Field({ nullable: true })
89
- webhook?: string
90
-
91
- @Column({ nullable: true })
92
- @Field({ nullable: true })
93
- appKey?: string
94
-
95
- @Column({
96
- nullable: true,
97
- type:
98
- DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'
99
- ? 'longtext'
100
- : DATABASE_TYPE == 'oracle'
101
- ? 'clob'
102
- : DATABASE_TYPE == 'mssql'
103
- ? 'nvarchar'
104
- : 'varchar',
105
- length: DATABASE_TYPE == 'mssql' ? 'MAX' : undefined
106
- })
107
- @Field({ nullable: true })
108
- @Directive('@privilege(category: "security", privilege: "query", domainOwnerGranted: true)')
109
- appSecret?: string
110
-
111
- @Column({ default: ApplicationStatus.DRAFT })
112
- @Field()
113
- status?: ApplicationStatus
114
-
115
- @Column({
116
- type:
117
- DATABASE_TYPE == 'postgres' || DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'
118
- ? 'enum'
119
- : DATABASE_TYPE == 'oracle'
120
- ? 'varchar2'
121
- : DATABASE_TYPE == 'mssql'
122
- ? 'nvarchar'
123
- : 'varchar',
124
- enum:
125
- DATABASE_TYPE == 'postgres' || DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'
126
- ? ApplicationType
127
- : undefined,
128
- length: DATABASE_TYPE == 'postgres' || DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb' ? undefined : 32,
129
- default: ApplicationType.OTHERS
130
- })
131
- @Field()
132
- type?: ApplicationType
133
-
134
- @CreateDateColumn()
135
- @Field({ nullable: true })
136
- createdAt?: Date
137
-
138
- @UpdateDateColumn()
139
- @Field({ nullable: true })
140
- updatedAt?: Date
141
-
142
- @ManyToOne(type => User, { nullable: true })
143
- @Field(type => User, { nullable: true })
144
- creator?: User
145
-
146
- @RelationId((application: Application) => application.creator)
147
- creatorId?: string
148
-
149
- @ManyToOne(type => User, { nullable: true })
150
- @Field(type => User, { nullable: true })
151
- updater?: User
152
-
153
- @RelationId((application: Application) => application.updater)
154
- updaterId?: string
155
-
156
- /* generateAppSecret */
157
- static generateAppSecret() {
158
- return crypto.randomBytes(16).toString('hex')
159
- }
160
-
161
- static generateAppKey() {
162
- return crypto.randomBytes(16).toString('hex')
163
- }
164
-
165
- /* signing for jsonwebtoken */
166
- static sign(subject, expiresIn, domain, user, appKey, scope) {
167
- var application = {
168
- id: user.id,
169
- userType: 'application',
170
- application: {
171
- appKey
172
- },
173
- status: UserStatus.ACTIVATED,
174
- domain: {
175
- subdomain: domain.subdomain
176
- },
177
- scope
178
- }
179
-
180
- return jwt.sign(application, SECRET, {
181
- expiresIn,
182
- issuer: 'hatiolab.com',
183
- subject
184
- })
185
- }
186
-
187
- static generateAccessToken(domain, user, appKey, scope) {
188
- /* how to set expiresIn https://github.com/vercel/ms */
189
- return this.sign('access-token', '30d', domain, user, appKey, scope)
190
- }
191
-
192
- static generateRefreshToken(domain, user, appKey, scope) {
193
- /* how to set expiresIn https://github.com/vercel/ms */
194
- return this.sign('refresh-token', '1y', domain, user, appKey, scope)
195
- }
196
-
197
- /* auth-code signing for jsonwebtoken */
198
- static generateAuthCode(email, appKey, subdomain, scopes, state) {
199
- var credential = {
200
- email,
201
- appKey,
202
- subdomain,
203
- scopes,
204
- state
205
- }
206
-
207
- return jwt.sign(credential, SECRET, {
208
- expiresIn: '1m'
209
- })
210
- }
211
-
212
- /* auth-code signing for jsonwebtoken */
213
- static verifyAuthCode(authcode) {
214
- return jwt.verify(authcode, SECRET)
215
- }
216
- }
@@ -1,6 +0,0 @@
1
- import { Application } from './application'
2
- import { ApplicationQuery } from './application-query'
3
- import { ApplicationMutation } from './application-mutation'
4
-
5
- export const entities = [Application]
6
- export const resolvers = [ApplicationQuery, ApplicationMutation]