@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,156 +0,0 @@
1
- import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
2
- import { EntityManager, In, Not, Repository } from 'typeorm'
3
-
4
- import { Domain, getRepository } from '@things-factory/shell'
5
-
6
- import { Partner } from '../partner/partner'
7
- import { Role } from '../role/role'
8
- import { RolePatch } from '../role/role-types'
9
- import { User } from '../user/user'
10
- import { GrantedRole } from './granted-role'
11
-
12
- @Resolver(GrantedRole)
13
- export class GrantedRoleMutation {
14
- @Directive('@privilege(category: "partner", privilege: "mutation")')
15
- @Directive('@transaction')
16
- @Mutation(returns => Boolean)
17
- async grantRoles(
18
- @Arg('customerId') customerId: string,
19
- @Arg('roles', type => [RolePatch]) roles: RolePatch[],
20
- @Ctx() context: ResolverContext
21
- ): Promise<Boolean> {
22
- const { tx, domain } = context.state
23
- // Check if current domain has partnership with passed `customer`
24
- const customerDomain: Domain = await tx.getRepository(Domain).findOneBy({ id: customerId })
25
- const customer: Partner = await tx.getRepository(Partner).findOne({
26
- where: { domain: { id: domain.id }, partnerDomain: { id: customerDomain.id } }
27
- })
28
-
29
- if (!customer) throw new Error(`Failed to find partnership with customer`)
30
-
31
- // Remove existing granted roles
32
- const grantedRoles: GrantedRole[] = await getGrantedRolesToCustomer(domain, customerDomain, tx)
33
- if (grantedRoles.length) {
34
- await tx.getRepository(GrantedRole).delete(grantedRoles.map((gr: GrantedRole) => gr.id))
35
- }
36
-
37
- // Insert newly granted roles
38
- await tx.getRepository(Role).findBy({
39
- id: In(roles.map((role: Partial<Role>) => role.id))
40
- })
41
- const newlyGrantedRoles: Partial<GrantedRole>[] = roles.map((role: Role) => {
42
- return {
43
- domain: customerDomain,
44
- role
45
- }
46
- })
47
-
48
- await tx.getRepository(GrantedRole).save(newlyGrantedRoles)
49
-
50
- // If there's someone having role which will be removed (refuse roles)
51
- // user roles should be removed as well
52
- const grantedRoleIds: string[] = roles.map((role: Partial<Role>) => role.id)
53
- const nonGrantedRoles: Role[] = await tx.getRepository(Role).find({
54
- where: { domain: { id: domain.id }, id: Not(In(grantedRoleIds)) }
55
- })
56
-
57
- if (nonGrantedRoles?.length) {
58
- // Find customer's user who has non granted roles already
59
- const nonGrantedRoleIds: string[] = nonGrantedRoles.map((role: Role) => role.id)
60
-
61
- let havingRefusedRoleCustomers: User[] = await getCustomerUsersByRoles(customerDomain, nonGrantedRoles, tx)
62
- havingRefusedRoleCustomers = havingRefusedRoleCustomers.map((customerUser: User) => {
63
- const customerDomains: Domain[] = customerUser.domains
64
- const customerDomainIds: string[] = customerDomains.map((domain: Domain) => domain.id)
65
- if (customerDomainIds.indexOf(domain.id) >= 0) {
66
- // Case for customer user is a member of current domain.
67
- // If user is a member of current domain user can have any roles of the domain even if the roles is not granted
68
- return customerUser
69
- } else {
70
- // Case for customer user is an user of partner domain.
71
- // An user of partner domain only can have granted roles
72
- customerUser.roles = customerUser.roles.filter((role: Role) => nonGrantedRoleIds.indexOf(role.id) < 0)
73
- return customerUser
74
- }
75
- })
76
-
77
- await tx.getRepository(User).save(havingRefusedRoleCustomers)
78
- }
79
- return true
80
- }
81
- }
82
-
83
- export async function getGrantedCustomerUsers(
84
- domain: Domain,
85
- customerDomain: Domain,
86
- trx?: EntityManager
87
- ): Promise<User[]> {
88
- const grantedRoles: GrantedRole[] = await getGrantedRolesToCustomer(domain, customerDomain, trx)
89
- const roles: Role[] = grantedRoles.map((grantedRole: GrantedRole) => grantedRole.role)
90
- return await getCustomerUsersByRoles(customerDomain, roles, trx)
91
- }
92
-
93
- export async function getCustomerUsersByRoles(
94
- customerDomain: Domain,
95
- roles: Role[],
96
- trx?: EntityManager
97
- ): Promise<User[]> {
98
- if (!roles.length) return []
99
- const userRepo: Repository<User> = trx?.getRepository(User) || getRepository(User)
100
-
101
- const customerUsers: User[] = await userRepo
102
- .createQueryBuilder('USER')
103
- .select('USER.id')
104
- .distinct(true)
105
- .leftJoin('USER.domains', 'U_DOMAIN')
106
- .leftJoin('USER.roles', 'U_ROLE')
107
- .where('U_DOMAIN.id = :customerDomainId', { customerDomainId: customerDomain.id })
108
- .groupBy('USER.id')
109
- .addGroupBy('U_ROLE.id')
110
- .having('U_ROLE.id IN (:...roleIds)', {
111
- roleIds: roles.map((role: Role) => role.id)
112
- })
113
- .getMany()
114
-
115
- return await userRepo.find({
116
- where: {
117
- id: In(customerUsers.map((user: User) => user.id))
118
- },
119
- relations: ['domains', 'roles', 'roles.domain']
120
- })
121
- }
122
-
123
- async function getGrantedRolesToCustomer(
124
- domain: Domain,
125
- customerDomain: Domain,
126
- trx?: EntityManager
127
- ): Promise<GrantedRole[]> {
128
- const grantedRoleRepo: Repository<GrantedRole> = trx?.getRepository(GrantedRole) || getRepository(GrantedRole)
129
- const grantedRoleQueryBuilder = grantedRoleRepo.createQueryBuilder('GRANTED_ROLE')
130
- return await grantedRoleQueryBuilder
131
- .leftJoinAndSelect('GRANTED_ROLE.domain', 'DOMAIN')
132
- .leftJoinAndSelect('GRANTED_ROLE.role', 'ROLE')
133
- .leftJoin('ROLE.domain', 'R_DOMAIN')
134
- .where('R_DOMAIN.id = :domainId', { domainId: domain.id })
135
- .andWhere('DOMAIN.id = :customerDomainId', { customerDomainId: customerDomain.id })
136
- .getMany()
137
- }
138
-
139
- export async function terminateGrantedRoles(
140
- domain: Domain,
141
- customerDomain: Domain,
142
- trx?: EntityManager
143
- ): Promise<void> {
144
- const userRepo: Repository<User> = trx?.getRepository(User) || getRepository(User)
145
- const grantedRoleRepo: Repository<GrantedRole> = trx?.getRepository(GrantedRole) || getRepository(GrantedRole)
146
-
147
- const grantedRoles: GrantedRole[] = await getGrantedRolesToCustomer(domain, customerDomain, trx)
148
- const customerUsers: User[] = await getGrantedCustomerUsers(domain, customerDomain, trx)
149
-
150
- for (let i: number = 0; i < customerUsers.length; i++) {
151
- customerUsers[i].roles = customerUsers[i].roles.filter((role: Role) => role.domain.id !== domain.id)
152
- }
153
-
154
- if (customerUsers?.length) await userRepo.save(customerUsers)
155
- if (grantedRoles?.length) await grantedRoleRepo.delete(grantedRoles.map((grantedRole: GrantedRole) => grantedRole.id))
156
- }
@@ -1,60 +0,0 @@
1
- import { Arg, Ctx, Directive, FieldResolver, Query, Resolver, Root } from 'type-graphql'
2
- import { SelectQueryBuilder } from 'typeorm'
3
-
4
- import { Domain, getRepository } from '@things-factory/shell'
5
-
6
- import { Partner } from '../partner/partner'
7
- import { Role } from '../role/role'
8
- import { GrantedRole } from './granted-role'
9
-
10
- @Resolver(GrantedRole)
11
- export class GrantedRoleQuery {
12
- @Directive('@privilege(category: "user", privilege: "query", domainOwnerGranted: true, superUserGranted: true)')
13
- @Query(returns => [GrantedRole])
14
- async grantedRoles(@Ctx() context: ResolverContext): Promise<GrantedRole[]> {
15
- const { domain } = context.state
16
- return await getRepository(GrantedRole).find({
17
- where: { domain: { id: domain.id } }
18
- })
19
- }
20
-
21
- /**
22
- * @summary The role list that target customer being granted by domain.
23
- *
24
- * @param customerId
25
- * @param context
26
- * @returns
27
- */
28
- @Directive('@privilege(category: "user", privilege: "query", domainOwnerGranted: true)')
29
- @Query(returns => [GrantedRole])
30
- async grantingRoles(@Arg('customerId') customerId: string, @Ctx() context: ResolverContext): Promise<GrantedRole[]> {
31
- const { domain } = context.state
32
- const customerDomain: Domain = await getRepository(Domain).findOneBy({ id: customerId })
33
-
34
- if (!customerDomain) throw new Error(`Failed to find customer by passed customerId (${customerId})`)
35
-
36
- const hasPartnership: boolean = Boolean(
37
- await getRepository(Partner).countBy({ domain: { id: domain.id }, partnerDomain: { id: customerDomain.id } })
38
- )
39
-
40
- if (!hasPartnership) throw new Error(`Company doesn't have partnership with ${customerDomain.name}`)
41
-
42
- const qb: SelectQueryBuilder<GrantedRole> = getRepository(GrantedRole)
43
- .createQueryBuilder('GRANTED_ROLE')
44
- .leftJoin('GRANTED_ROLE.role', 'ROLE')
45
- .where('GRANTED_ROLE.domain_id = :customerId', { customerId })
46
- .andWhere('ROLE.domain_id = :domainId ', { domainId: domain.id })
47
-
48
- return await qb.getMany()
49
- }
50
-
51
- @FieldResolver(type => Role)
52
- async role(@Root() grantedRole: GrantedRole): Promise<Role> {
53
- return await getRepository(Role).findOneBy({ id: grantedRole.roleId })
54
- }
55
-
56
- @FieldResolver(type => Domain)
57
- async domain(@Root() grantedRole: GrantedRole): Promise<Domain> {
58
- return await getRepository(Domain).findOneBy({ id: grantedRole.domainId })
59
- }
60
- }
@@ -1,27 +0,0 @@
1
- import { Domain } from '@things-factory/shell'
2
- import { Role } from '../role/role'
3
- import { ObjectType, Field, ID } from 'type-graphql'
4
- import { Entity, ManyToOne, PrimaryGeneratedColumn, Index, RelationId } from 'typeorm'
5
-
6
- @Entity()
7
- @Index('ix_granted_role_0', (grantedRole: GrantedRole) => [grantedRole.role, grantedRole.domain], { unique: true })
8
- @ObjectType()
9
- export class GrantedRole {
10
- @PrimaryGeneratedColumn('uuid')
11
- @Field(type => ID)
12
- readonly id: string
13
-
14
- @ManyToOne(type => Role)
15
- @Field()
16
- role: Role
17
-
18
- @RelationId((grantedRole: GrantedRole) => grantedRole.role)
19
- roleId: string
20
-
21
- @ManyToOne(type => Domain)
22
- @Field(type => Domain)
23
- domain?: Domain
24
-
25
- @RelationId((grantedRole: GrantedRole) => grantedRole.domain)
26
- domainId: string
27
- }
@@ -1,6 +0,0 @@
1
- import { GrantedRole } from './granted-role'
2
- import { GrantedRoleQuery } from './granted-role-query'
3
- import { GrantedRoleMutation } from './granted-role-mutation'
4
-
5
- export const entities = [GrantedRole]
6
- export const resolvers = [GrantedRoleQuery, GrantedRoleMutation]
@@ -1,90 +0,0 @@
1
- /* IMPORT ENTITIES AND RESOLVERS */
2
- import { entities as UsersAuthProvidersEntities, resolvers as UsersAuthProvidersResolvers } from './users-auth-providers'
3
- import { entities as AuthProviderEntities, resolvers as AuthProviderResolvers } from './auth-provider'
4
- import { resolvers as AppbindingResolver } from './app-binding'
5
- import { entities as ApplianceEntities, resolvers as ApplianceResolvers } from './appliance'
6
- import { entities as ApplicationEntities, resolvers as ApplicationResolvers } from './application'
7
- import { resolvers as DomainGeneratorResolver } from './domain-generator'
8
- import { entities as GrantedRoleEntities, resolvers as GrantedRoleResolver } from './granted-role'
9
- import { entities as InvitationEntities, resolvers as InvitationResolver } from './invitation'
10
- import { entities as LoginHistoryEntities, resolvers as LoginHistoryResolver } from './login-history'
11
- import { entities as PartnerEntities, resolvers as PartnerResolvers } from './partner'
12
- import { entities as PasswordHistoryEntities } from './password-history'
13
- import { entities as PrivilegeEntities, resolvers as PrivilegeResolvers } from './privilege'
14
- import { privilegeDirectiveResolver, privilegeDirectiveTypeDefs } from './privilege/privilege-directive'
15
- import { entities as RoleEntities, resolvers as RoleResolvers } from './role'
16
- import { entities as UserEntities, resolvers as UserResolvers } from './user'
17
- import { entities as VerificationTokenEntities } from './verification-token'
18
- import { entities as WebAuthCredentialEntities } from './web-auth-credential'
19
-
20
- /* EXPORT ENTITY TYPES */
21
- export * from './users-auth-providers/users-auth-providers'
22
- export * from './auth-provider/auth-provider'
23
- export * from './application/application'
24
- export * from './appliance/appliance'
25
- export * from './privilege/privilege'
26
- export * from './role/role'
27
- export * from './user/user'
28
- export * from './partner/partner'
29
- export * from './granted-role/granted-role'
30
- export * from './invitation/invitation'
31
- export * from './app-binding/app-binding'
32
- export * from './password-history/password-history'
33
- export * from './verification-token/verification-token'
34
- export * from './login-history/login-history'
35
- export * from './web-auth-credential/web-auth-credential'
36
-
37
- /* EXPORT TYPES */
38
- export * from './app-binding/app-binding-types'
39
- export * from './appliance/appliance-types'
40
- export * from './application/application-types'
41
- export * from './domain-generator/domain-generator-types'
42
- export * from './invitation/invitation-types'
43
- export * from './partner/partner-types'
44
- export * from './privilege/privilege-types'
45
- export * from './role/role-types'
46
- export * from './user/user-types'
47
-
48
- export const entities = [
49
- /* ENTITIES */
50
- ...UsersAuthProvidersEntities,
51
- ...AuthProviderEntities,
52
- ...ApplicationEntities,
53
- ...ApplianceEntities,
54
- ...PrivilegeEntities,
55
- ...RoleEntities,
56
- ...UserEntities,
57
- ...PartnerEntities,
58
- ...GrantedRoleEntities,
59
- ...InvitationEntities,
60
- ...PasswordHistoryEntities,
61
- ...VerificationTokenEntities,
62
- ...LoginHistoryEntities,
63
- ...WebAuthCredentialEntities
64
- ]
65
-
66
- export const schema = {
67
- typeDefs: {
68
- privilegeDirectiveTypeDefs
69
- },
70
-
71
- resolverClasses: [
72
- /* RESOLVER CLASSES */
73
- ...UsersAuthProvidersResolvers,
74
- ...AuthProviderResolvers,
75
- ...ApplicationResolvers,
76
- ...ApplianceResolvers,
77
- ...PrivilegeResolvers,
78
- ...RoleResolvers,
79
- ...UserResolvers,
80
- ...PartnerResolvers,
81
- ...GrantedRoleResolver,
82
- ...InvitationResolver,
83
- ...AppbindingResolver,
84
- ...DomainGeneratorResolver,
85
- ...LoginHistoryResolver
86
- ],
87
- directives: {
88
- privilege: privilegeDirectiveResolver
89
- }
90
- }
@@ -1,6 +0,0 @@
1
- import { Invitation } from './invitation'
2
- import { InvitationQuery } from './invitation-query'
3
- import { InvitationMutation } from './invitation-mutation'
4
-
5
- export const entities = [Invitation]
6
- export const resolvers = [InvitationQuery, InvitationMutation]
@@ -1,78 +0,0 @@
1
- import { ILike } from 'typeorm'
2
-
3
- import { Arg, Ctx, Mutation, Resolver } from 'type-graphql'
4
- import { GraphQLEmailAddress } from 'graphql-scalars'
5
-
6
- import { getRepository } from '@things-factory/shell'
7
-
8
- import { User, UserStatus } from '../../service/user/user'
9
- import { sendInvitationEmail } from '../../controllers/invitation'
10
- import { Invitation } from './invitation'
11
-
12
- @Resolver(Invitation)
13
- export class InvitationMutation {
14
- @Mutation(returns => Boolean)
15
- async cancelInvitation(
16
- @Arg('email', type => GraphQLEmailAddress) email: string,
17
- @Arg('reference') reference: string,
18
- @Arg('type') type: string
19
- ) {
20
- const repository = getRepository(Invitation)
21
-
22
- await repository.delete({
23
- email,
24
- reference,
25
- type
26
- })
27
-
28
- return true
29
- }
30
-
31
- @Mutation(returns => Invitation)
32
- async sendInvitation(
33
- @Arg('email', type => GraphQLEmailAddress) email: string,
34
- @Arg('reference') reference: string,
35
- @Arg('type') type: string,
36
- @Ctx() context: ResolverContext
37
- ) {
38
- const { user: updater } = context.state
39
- const invitationRepository = getRepository(Invitation)
40
-
41
- var user = await getRepository(User).findOne({
42
- where: {
43
- email: ILike(email),
44
- status: UserStatus.ACTIVATED
45
- }
46
- })
47
-
48
- if (!user) {
49
- throw new Error(`user not found: ${email}`)
50
- }
51
-
52
- await sendInvitationEmail({
53
- invitation: {
54
- email,
55
- reference,
56
- type
57
- },
58
- user,
59
- context
60
- })
61
-
62
- const oldone = await invitationRepository.findOneBy({
63
- email,
64
- type,
65
- reference
66
- })
67
-
68
- // update or create
69
- return await invitationRepository.save({
70
- creator: updater,
71
- ...oldone, // take only id from oldone for update
72
- email,
73
- reference,
74
- type,
75
- updater: updater
76
- })
77
- }
78
- }
@@ -1,33 +0,0 @@
1
- import { GraphQLEmailAddress } from 'graphql-scalars'
2
- import { Arg, Query, Resolver } from 'type-graphql'
3
-
4
- import { getRepository } from '@things-factory/shell'
5
-
6
- import { Invitation } from './invitation'
7
- import { InvitationList } from './invitation-types'
8
-
9
- @Resolver(Invitation)
10
- export class InvitationQuery {
11
- @Query(returns => Invitation)
12
- async invitation(
13
- @Arg('email', type => GraphQLEmailAddress) email: string,
14
- @Arg('reference') reference: string,
15
- @Arg('type') type: string
16
- ) {
17
- return await getRepository(Invitation).findOneBy({
18
- email,
19
- reference,
20
- type
21
- })
22
- }
23
-
24
- @Query(returns => InvitationList)
25
- async invitations(@Arg('reference') reference: string, @Arg('type') type: string) {
26
- const [items, total] = await getRepository(Invitation).findAndCountBy({
27
- reference,
28
- type
29
- })
30
-
31
- return { items, total }
32
- }
33
- }
@@ -1,11 +0,0 @@
1
- import { Invitation } from './invitation'
2
- import { ObjectType, Field, Int } from 'type-graphql'
3
-
4
- @ObjectType()
5
- export class InvitationList {
6
- @Field(type => [Invitation], { nullable: true })
7
- items: Invitation[]
8
-
9
- @Field(type => Int, { nullable: true })
10
- total: number
11
- }
@@ -1,63 +0,0 @@
1
- import {
2
- CreateDateColumn,
3
- UpdateDateColumn,
4
- Entity,
5
- Index,
6
- Column,
7
- ManyToOne,
8
- RelationId,
9
- PrimaryGeneratedColumn
10
- } from 'typeorm'
11
- import { ObjectType, Field, ID } from 'type-graphql'
12
- import { GraphQLEmailAddress } from 'graphql-scalars'
13
- import { User } from '../user/user'
14
-
15
- @Entity()
16
- @Index('ix_invitation_0', (invitation: Invitation) => [invitation.email, invitation.reference, invitation.type], {
17
- unique: true
18
- })
19
- @Index('ix_invitation_1', (invitation: Invitation) => [invitation.token], { unique: true })
20
- @ObjectType()
21
- export class Invitation {
22
- @PrimaryGeneratedColumn('uuid')
23
- @Field(type => ID)
24
- readonly id: string
25
-
26
- @Column()
27
- @Field(type => GraphQLEmailAddress)
28
- email: string
29
-
30
- @Column()
31
- @Field()
32
- reference: string // company, bizplace
33
-
34
- @Column()
35
- @Field()
36
- type: string // company, bizplace, .. should think whether this column needs.
37
-
38
- @Column()
39
- @Field()
40
- token: string
41
-
42
- @CreateDateColumn({ nullable: true })
43
- @Field({ nullable: true })
44
- createdAt: Date
45
-
46
- @UpdateDateColumn({ nullable: true })
47
- @Field({ nullable: true })
48
- updatedAt: Date
49
-
50
- @ManyToOne(type => User, { nullable: true })
51
- @Field({ nullable: true })
52
- creator: User
53
-
54
- @RelationId((invitation: Invitation) => invitation.creator)
55
- creatorId: string
56
-
57
- @ManyToOne(type => User, { nullable: true })
58
- @Field({ nullable: true })
59
- updater: User
60
-
61
- @RelationId((invitation: Invitation) => invitation.updater)
62
- updaterId: string
63
- }
@@ -1,5 +0,0 @@
1
- import { LoginHistory } from './login-history'
2
- import { LoginHistoryQuery } from './login-history-query'
3
-
4
- export const entities = [LoginHistory]
5
- export const resolvers = [LoginHistoryQuery]
@@ -1,51 +0,0 @@
1
- import { Arg, Args, Ctx, FieldResolver, Query, Resolver, Root } from 'type-graphql'
2
-
3
- import { Domain, getQueryBuilderFromListParams, getRepository, ListParam } from '@things-factory/shell'
4
-
5
- import { User } from '../user/user'
6
- import { LoginHistory } from './login-history'
7
- import { LoginHistoryList } from './login-history-type'
8
-
9
- @Resolver(LoginHistory)
10
- export class LoginHistoryQuery {
11
- @Query(returns => LoginHistoryList, { description: 'To fetch multiple LoginHistories' })
12
- async loginHistories(
13
- @Args(type => ListParam) params: ListParam,
14
- @Ctx() context: ResolverContext
15
- ): Promise<LoginHistoryList> {
16
- const { domain } = context.state
17
-
18
- const queryBuilder = getQueryBuilderFromListParams({
19
- domain,
20
- params,
21
- repository: await getRepository(LoginHistory)
22
- })
23
-
24
- const [items, total] = await queryBuilder.getManyAndCount()
25
- return { items, total }
26
- }
27
-
28
- @Query(returns => [LoginHistory])
29
- async myLoginHistories(@Arg('limit') limit: number, @Ctx() context: ResolverContext): Promise<LoginHistory[]> {
30
- const user: User = context.state.user
31
- if (!user) {
32
- throw new Error('No user specified')
33
- }
34
-
35
- return await getRepository(LoginHistory).find({
36
- where: { accessUser: { id: user.id } },
37
- take: limit || 10,
38
- order: { accessedAt: 'DESC' }
39
- })
40
- }
41
-
42
- @FieldResolver()
43
- async accessDomain(@Root() loginHistory: LoginHistory) {
44
- return await getRepository(Domain).findOneBy({ id: loginHistory.accessDomainId })
45
- }
46
-
47
- @FieldResolver()
48
- async accessUser(@Root() loginHistory: LoginHistory) {
49
- return await getRepository(User).findOneBy({ id: loginHistory.accessUserId })
50
- }
51
- }
@@ -1,12 +0,0 @@
1
- import { Field, ID, InputType, Int, ObjectType } from 'type-graphql'
2
-
3
- import { LoginHistory } from './login-history'
4
-
5
- @ObjectType()
6
- export class LoginHistoryList {
7
- @Field(type => [LoginHistory])
8
- items: LoginHistory[]
9
-
10
- @Field(type => Int)
11
- total: number
12
- }
@@ -1,45 +0,0 @@
1
- import { Field, ID, ObjectType } from 'type-graphql'
2
- import { Column, CreateDateColumn, Entity, Index, ManyToOne, PrimaryGeneratedColumn, RelationId } from 'typeorm'
3
-
4
- import { Domain, getRepository } from '@things-factory/shell'
5
-
6
- import { User } from '../user/user'
7
-
8
- @Entity()
9
- @Index('ix_login_history_0', (loginHistory: LoginHistory) => [loginHistory.accessDomain, loginHistory.accessUser])
10
- @ObjectType()
11
- export class LoginHistory {
12
- @PrimaryGeneratedColumn('uuid')
13
- @Field(type => ID)
14
- readonly id: string
15
-
16
- @ManyToOne(type => Domain)
17
- @Field(type => Domain)
18
- accessDomain?: Domain
19
-
20
- @RelationId((loginHistory: LoginHistory) => loginHistory.accessDomain)
21
- accessDomainId: string
22
-
23
- @ManyToOne(type => User)
24
- @Field(type => User)
25
- accessUser: User
26
-
27
- @RelationId((loginHistory: LoginHistory) => loginHistory.accessUser)
28
- accessUserId: string
29
-
30
- @Column({ nullable: true })
31
- @Field({ nullable: true })
32
- accessorIp: string
33
-
34
- @CreateDateColumn()
35
- @Field({ nullable: true })
36
- accessedAt: Date
37
-
38
- static async stamp(accessDomain: Partial<Domain>, accessUser: User, accessorIp: string): Promise<void> {
39
- await getRepository(LoginHistory).save({
40
- accessDomain,
41
- accessUser,
42
- accessorIp
43
- })
44
- }
45
- }
@@ -1,6 +0,0 @@
1
- import { Partner } from './partner'
2
- import { PartnerQuery } from './partner-query'
3
- import { PartnerMutation } from './partner-mutation'
4
-
5
- export const entities = [Partner]
6
- export const resolvers = [PartnerQuery, PartnerMutation]