@things-factory/auth-base 10.1.31 → 10.1.33

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 (108) hide show
  1. package/dist-server/controllers/invitation.d.ts +47 -10
  2. package/dist-server/controllers/invitation.js +159 -113
  3. package/dist-server/controllers/invitation.js.map +1 -1
  4. package/dist-server/controllers/profile.d.ts +1 -0
  5. package/dist-server/router/auth-public-process-router.js +36 -13
  6. package/dist-server/router/auth-public-process-router.js.map +1 -1
  7. package/dist-server/router/oauth2/oauth2-router.js +7 -2
  8. package/dist-server/router/oauth2/oauth2-router.js.map +1 -1
  9. package/dist-server/router/oauth2/oauth2-server.js +4 -4
  10. package/dist-server/router/oauth2/oauth2-server.js.map +1 -1
  11. package/dist-server/service/app-binding/app-binding-mutation.d.ts +27 -0
  12. package/dist-server/service/app-binding/app-binding-mutation.js +39 -6
  13. package/dist-server/service/app-binding/app-binding-mutation.js.map +1 -1
  14. package/dist-server/service/app-binding/app-binding-query.js +14 -7
  15. package/dist-server/service/app-binding/app-binding-query.js.map +1 -1
  16. package/dist-server/service/app-binding/app-binding.d.ts +9 -0
  17. package/dist-server/service/app-binding/app-binding.js +10 -1
  18. package/dist-server/service/app-binding/app-binding.js.map +1 -1
  19. package/dist-server/service/appliance/appliance-mutation.js +34 -1
  20. package/dist-server/service/appliance/appliance-mutation.js.map +1 -1
  21. package/dist-server/service/appliance/appliance-query.d.ts +2 -0
  22. package/dist-server/service/appliance/appliance-query.js +48 -0
  23. package/dist-server/service/appliance/appliance-query.js.map +1 -1
  24. package/dist-server/service/appliance/appliance.d.ts +1 -0
  25. package/dist-server/service/appliance/appliance.js +33 -3
  26. package/dist-server/service/appliance/appliance.js.map +1 -1
  27. package/dist-server/service/application/application-mutation.js +51 -6
  28. package/dist-server/service/application/application-mutation.js.map +1 -1
  29. package/dist-server/service/application/application.d.ts +9 -3
  30. package/dist-server/service/application/application.js +24 -8
  31. package/dist-server/service/application/application.js.map +1 -1
  32. package/dist-server/service/auth-provider/auth-provider-mutation.js +5 -0
  33. package/dist-server/service/auth-provider/auth-provider-mutation.js.map +1 -1
  34. package/dist-server/service/domain-generator/domain-generator-mutation.js +3 -0
  35. package/dist-server/service/domain-generator/domain-generator-mutation.js.map +1 -1
  36. package/dist-server/service/invitation/invitation-mutation.d.ts +17 -15
  37. package/dist-server/service/invitation/invitation-mutation.js +83 -56
  38. package/dist-server/service/invitation/invitation-mutation.js.map +1 -1
  39. package/dist-server/service/invitation/invitation-query.d.ts +20 -5
  40. package/dist-server/service/invitation/invitation-query.js +60 -19
  41. package/dist-server/service/invitation/invitation-query.js.map +1 -1
  42. package/dist-server/service/invitation/invitation.d.ts +14 -2
  43. package/dist-server/service/invitation/invitation.js +77 -8
  44. package/dist-server/service/invitation/invitation.js.map +1 -1
  45. package/dist-server/service/login-history/login-history-query.js +3 -0
  46. package/dist-server/service/login-history/login-history-query.js.map +1 -1
  47. package/dist-server/service/role/role-mutation.js +14 -15
  48. package/dist-server/service/role/role-mutation.js.map +1 -1
  49. package/dist-server/service/role/role-query.js +26 -4
  50. package/dist-server/service/role/role-query.js.map +1 -1
  51. package/dist-server/service/role/role-types.d.ts +2 -0
  52. package/dist-server/service/role/role-types.js +8 -0
  53. package/dist-server/service/role/role-types.js.map +1 -1
  54. package/dist-server/service/role-template/role-template-mutation.d.ts +17 -1
  55. package/dist-server/service/role-template/role-template-mutation.js +14 -3
  56. package/dist-server/service/role-template/role-template-mutation.js.map +1 -1
  57. package/dist-server/service/user/user-mutation.js +1 -0
  58. package/dist-server/service/user/user-mutation.js.map +1 -1
  59. package/dist-server/service/user/user.d.ts +1 -0
  60. package/dist-server/service/user/user.js +19 -4
  61. package/dist-server/service/user/user.js.map +1 -1
  62. package/dist-server/templates/invitation-email.d.ts +2 -1
  63. package/dist-server/templates/invitation-email.js +16 -4
  64. package/dist-server/templates/invitation-email.js.map +1 -1
  65. package/dist-server/tsconfig.tsbuildinfo +1 -1
  66. package/dist-server/utils/credential-at-rest.d.ts +28 -0
  67. package/dist-server/utils/credential-at-rest.js +36 -0
  68. package/dist-server/utils/credential-at-rest.js.map +1 -0
  69. package/dist-server/utils/credential-features.d.ts +35 -0
  70. package/dist-server/utils/credential-features.js +45 -0
  71. package/dist-server/utils/credential-features.js.map +1 -0
  72. package/dist-server/utils/credential-serial-rule.d.ts +41 -0
  73. package/dist-server/utils/credential-serial-rule.js +43 -0
  74. package/dist-server/utils/credential-serial-rule.js.map +1 -0
  75. package/dist-server/utils/invitation-state.d.ts +52 -0
  76. package/dist-server/utils/invitation-state.js +76 -0
  77. package/dist-server/utils/invitation-state.js.map +1 -0
  78. package/dist-server/utils/refuse-role-name.d.ts +42 -0
  79. package/dist-server/utils/refuse-role-name.js +76 -0
  80. package/dist-server/utils/refuse-role-name.js.map +1 -0
  81. package/dist-server/utils/role-name-standing.d.ts +58 -0
  82. package/dist-server/utils/role-name-standing.js +72 -0
  83. package/dist-server/utils/role-name-standing.js.map +1 -0
  84. package/package.json +4 -4
  85. package/tests/app-binding-delete-db.test.ts +188 -0
  86. package/tests/appliance-credential-state-db.test.ts +207 -0
  87. package/tests/appliance-delete-db.test.ts +119 -0
  88. package/tests/appliance-revoke-db.test.ts +73 -28
  89. package/tests/appliance-schema.test.ts +129 -0
  90. package/tests/application-delete-db.test.ts +190 -0
  91. package/tests/application-token-payload-db.test.ts +185 -0
  92. package/tests/checkin-privilege-seam-db.test.ts +158 -0
  93. package/tests/credential-at-rest-db.test.ts +246 -0
  94. package/tests/credential-features-off-db.test.ts +189 -0
  95. package/tests/credential-serial-rule.test.ts +84 -0
  96. package/tests/invitation-db.test.ts +416 -0
  97. package/tests/invitation-state.test.ts +92 -0
  98. package/tests/open-doors.test.ts +132 -0
  99. package/tests/role-inheritance-db.test.ts +286 -0
  100. package/tests/role-mutation-db.test.ts +21 -7
  101. package/tests/role-name-lookup-sentinel.test.ts +79 -0
  102. package/tests/role-name-standing.test.ts +83 -0
  103. package/tests/token-issuance.test.ts +7 -3
  104. package/translations/en.json +2 -0
  105. package/translations/ja.json +2 -0
  106. package/translations/ko.json +2 -0
  107. package/translations/ms.json +2 -0
  108. package/translations/zh.json +2 -0
@@ -1 +1 @@
1
- {"version":3,"file":"auth-provider-mutation.js","sourceRoot":"","sources":["../../../server/service/auth-provider/auth-provider-mutation.ts"],"names":[],"mappings":";;;;AAAA,+CAAsE;AACtE,qCAA4B;AAE5B,yDAAiD;AACjD,mEAA4E;AAGrE,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAGzB,AAAN,KAAK,CAAC,kBAAkB,CACD,YAA6B,EAC3C,OAAwB;QAE/B,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAE1C,OAAO,MAAM,EAAE,CAAC,aAAa,CAAC,+BAAY,CAAC,CAAC,IAAI,CAAC;YAC/C,GAAG,YAAY;YACf,MAAM;YACN,OAAO,EAAE,IAAI;YACb,OAAO,EAAE,IAAI;SACd,CAAC,CAAA;IACJ,CAAC;IAIK,AAAN,KAAK,CAAC,kBAAkB,CACX,EAAU,EACP,KAAwB,EAC/B,OAAwB;QAE/B,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAE1C,MAAM,UAAU,GAAG,EAAE,CAAC,aAAa,CAAC,+BAAY,CAAC,CAAA;QACjD,MAAM,YAAY,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC;YAC5C,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE;SACzC,CAAC,CAAA;QAEF,OAAO,MAAM,UAAU,CAAC,IAAI,CAAC;YAC3B,GAAG,YAAY;YACf,GAAG,KAAK;YACR,OAAO,EAAE,IAAI;SACd,CAAC,CAAA;IACJ,CAAC;IAIK,AAAN,KAAK,CAAC,0BAA0B,CACe,OAA4B,EAClE,OAAwB;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,wBAAS,EAAC,cAAc,CAAC;IACzB,IAAA,uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC;IAE1B,mBAAA,IAAA,kBAAG,EAAC,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;IAC5B,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;+DAqBP;AAKK;IAHL,IAAA,wBAAS,EAAC,cAAc,CAAC;IACzB,IAAA,wBAAS,EAAC,mCAAmC,CAAC;IAC9C,IAAA,uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,qCAAqC,EAAE,CAAC;IACjD,mBAAA,IAAA,kBAAG,EAAC,IAAI,CAAC,CAAA;IAAc,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;wEAiB/D;+BAtJU,oBAAoB;IADhC,IAAA,uBAAQ,EAAC,+BAAY,CAAC;GACV,oBAAoB,CAuJhC","sourcesContent":["import { Resolver, Mutation, Arg, Ctx, Directive } from 'type-graphql'\nimport { In } from 'typeorm'\n\nimport { AuthProvider } from './auth-provider.js'\nimport { NewAuthProvider, AuthProviderPatch } from './auth-provider-type.js'\n\n@Resolver(AuthProvider)\nexport class AuthProviderMutation {\n @Directive('@transaction')\n @Mutation(returns => AuthProvider, { description: 'To create new AuthProvider' })\n async createAuthProvider(\n @Arg('authProvider') authProvider: NewAuthProvider,\n @Ctx() context: ResolverContext\n ): Promise<AuthProvider> {\n const { domain, user, tx } = context.state\n\n return await tx.getRepository(AuthProvider).save({\n ...authProvider,\n domain,\n creator: user,\n updater: user\n })\n }\n\n @Directive('@transaction')\n @Mutation(returns => AuthProvider, { description: 'To modify AuthProvider information' })\n async updateAuthProvider(\n @Arg('id') id: string,\n @Arg('patch') patch: AuthProviderPatch,\n @Ctx() context: ResolverContext\n ): Promise<AuthProvider> {\n const { domain, user, tx } = context.state\n\n const repository = tx.getRepository(AuthProvider)\n const authProvider = await repository.findOne({\n where: { domain: { id: domain.id }, id }\n })\n\n return await repository.save({\n ...authProvider,\n ...patch,\n updater: user\n })\n }\n\n @Directive('@transaction')\n @Mutation(returns => [AuthProvider])\n async updateMultipleAuthProvider(\n @Arg('patches', type => [AuthProviderPatch]) patches: AuthProviderPatch[],\n @Ctx() context: ResolverContext\n ): Promise<AuthProvider[]> {\n const { domain, user, tx } = context.state\n\n let results = []\n const _createRecords = patches.filter((patch: any) => patch.cuFlag === '+')\n const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')\n\n if (_createRecords.length > 0) {\n for (let i = 0; i < _createRecords.length; i++) {\n const newRecord = _createRecords[i]\n\n let foundAuthProvider = await tx.getRepository(AuthProvider).findOne({\n where: { domain: { id: domain.id }, type: newRecord.type }\n })\n\n if (foundAuthProvider) {\n throw new Error('Duplicated authProvider found')\n }\n\n const result: AuthProvider = await tx.getRepository(AuthProvider).save({\n domain: domain,\n creator: user,\n updater: user,\n ...newRecord\n })\n\n results.push({ ...result, cuFlag: '+' })\n }\n }\n\n if (_updateRecords.length > 0) {\n for (let i = 0; i < _updateRecords.length; i++) {\n const updatedRecord = _updateRecords[i]\n const authProvider = await tx.getRepository(AuthProvider).findOne({\n where: { domain: { id: domain.id }, id: updatedRecord.id }\n })\n\n const result = await tx.getRepository(AuthProvider).save({\n ...authProvider,\n ...updatedRecord,\n updater: user\n })\n\n results.push({ ...result, cuFlag: 'M' })\n }\n }\n\n return results\n }\n\n @Directive('@transaction')\n @Mutation(returns => Boolean, { description: 'To delete AuthProvider' })\n async deleteAuthProvider(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {\n const { domain, tx } = context.state\n\n await tx.getRepository(AuthProvider).delete({ domain: { id: domain.id }, id })\n\n return true\n }\n\n @Directive('@transaction')\n @Mutation(returns => Boolean)\n async deleteAuthProviders(\n @Arg('ids', type => [String]) ids: string[],\n @Ctx() context: ResolverContext\n ): Promise<Boolean> {\n const { domain, user, tx } = context.state\n\n const authProviders = await tx.getRepository(AuthProvider).find({\n where: {\n domain: { id: domain.id },\n id: In(ids)\n }\n })\n\n await Promise.all(\n authProviders.map(async (authProvider: AuthProvider) => {\n await tx.getRepository(AuthProvider).save({\n ...authProvider,\n deletedAt: new Date(),\n updater: user\n })\n })\n )\n return true\n }\n\n @Directive('@transaction')\n @Directive('@privilege(superUserGranted:true)')\n @Mutation(returns => Boolean, { description: 'To synchronize auth-providers users' })\n async synchronizeAuthProviderUsers(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {\n const { domain, user, tx } = context.state\n\n const repository = tx.getRepository(AuthProvider)\n const authProvider = await repository.findOne({\n where: { domain: { id: domain.id }, id },\n relations: ['domain']\n })\n\n const { type } = authProvider\n const { synchronizeUsers } = AuthProvider.getAuthProviderImpl(type) || {}\n\n if (synchronizeUsers) {\n return await synchronizeUsers(authProvider, context)\n } else {\n throw new Error(`No AuthProviderImpl for the type '${type}'`)\n }\n }\n}\n"]}
1
+ {"version":3,"file":"auth-provider-mutation.js","sourceRoot":"","sources":["../../../server/service/auth-provider/auth-provider-mutation.ts"],"names":[],"mappings":";;;;AAAA,+CAAsE;AACtE,qCAA4B;AAE5B,yDAAiD;AACjD,mEAA4E;AAGrE,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAIzB,AAAN,KAAK,CAAC,kBAAkB,CACD,YAA6B,EAC3C,OAAwB;QAE/B,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAE1C,OAAO,MAAM,EAAE,CAAC,aAAa,CAAC,+BAAY,CAAC,CAAC,IAAI,CAAC;YAC/C,GAAG,YAAY;YACf,MAAM;YACN,OAAO,EAAE,IAAI;YACb,OAAO,EAAE,IAAI;SACd,CAAC,CAAA;IACJ,CAAC;IAKK,AAAN,KAAK,CAAC,kBAAkB,CACX,EAAU,EACP,KAAwB,EAC/B,OAAwB;QAE/B,MAAM,EAAE,MAAM,EAAE,IAAI,EA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,uBAAQ,EAAC,+BAAY,CAAC;GACV,oBAAoB,CA4JhC","sourcesContent":["import { Resolver, Mutation, Arg, Ctx, Directive } from 'type-graphql'\nimport { In } from 'typeorm'\n\nimport { AuthProvider } from './auth-provider.js'\nimport { NewAuthProvider, AuthProviderPatch } from './auth-provider-type.js'\n\n@Resolver(AuthProvider)\nexport class AuthProviderMutation {\n @Directive('@privilege(category: \"user\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Directive('@transaction')\n @Mutation(returns => AuthProvider, { description: 'To create new AuthProvider' })\n async createAuthProvider(\n @Arg('authProvider') authProvider: NewAuthProvider,\n @Ctx() context: ResolverContext\n ): Promise<AuthProvider> {\n const { domain, user, tx } = context.state\n\n return await tx.getRepository(AuthProvider).save({\n ...authProvider,\n domain,\n creator: user,\n updater: user\n })\n }\n\n @Directive('@privilege(category: \"user\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Directive('@transaction')\n @Mutation(returns => AuthProvider, { description: 'To modify AuthProvider information' })\n async updateAuthProvider(\n @Arg('id') id: string,\n @Arg('patch') patch: AuthProviderPatch,\n @Ctx() context: ResolverContext\n ): Promise<AuthProvider> {\n const { domain, user, tx } = context.state\n\n const repository = tx.getRepository(AuthProvider)\n const authProvider = await repository.findOne({\n where: { domain: { id: domain.id }, id }\n })\n\n return await repository.save({\n ...authProvider,\n ...patch,\n updater: user\n })\n }\n\n @Directive('@privilege(category: \"user\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Directive('@transaction')\n @Mutation(returns => [AuthProvider])\n async updateMultipleAuthProvider(\n @Arg('patches', type => [AuthProviderPatch]) patches: AuthProviderPatch[],\n @Ctx() context: ResolverContext\n ): Promise<AuthProvider[]> {\n const { domain, user, tx } = context.state\n\n let results = []\n const _createRecords = patches.filter((patch: any) => patch.cuFlag === '+')\n const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')\n\n if (_createRecords.length > 0) {\n for (let i = 0; i < _createRecords.length; i++) {\n const newRecord = _createRecords[i]\n\n let foundAuthProvider = await tx.getRepository(AuthProvider).findOne({\n where: { domain: { id: domain.id }, type: newRecord.type }\n })\n\n if (foundAuthProvider) {\n throw new Error('Duplicated authProvider found')\n }\n\n const result: AuthProvider = await tx.getRepository(AuthProvider).save({\n domain: domain,\n creator: user,\n updater: user,\n ...newRecord\n })\n\n results.push({ ...result, cuFlag: '+' })\n }\n }\n\n if (_updateRecords.length > 0) {\n for (let i = 0; i < _updateRecords.length; i++) {\n const updatedRecord = _updateRecords[i]\n const authProvider = await tx.getRepository(AuthProvider).findOne({\n where: { domain: { id: domain.id }, id: updatedRecord.id }\n })\n\n const result = await tx.getRepository(AuthProvider).save({\n ...authProvider,\n ...updatedRecord,\n updater: user\n })\n\n results.push({ ...result, cuFlag: 'M' })\n }\n }\n\n return results\n }\n\n @Directive('@privilege(category: \"user\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Directive('@transaction')\n @Mutation(returns => Boolean, { description: 'To delete AuthProvider' })\n async deleteAuthProvider(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {\n const { domain, tx } = context.state\n\n await tx.getRepository(AuthProvider).delete({ domain: { id: domain.id }, id })\n\n return true\n }\n\n @Directive('@privilege(category: \"user\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Directive('@transaction')\n @Mutation(returns => Boolean)\n async deleteAuthProviders(\n @Arg('ids', type => [String]) ids: string[],\n @Ctx() context: ResolverContext\n ): Promise<Boolean> {\n const { domain, user, tx } = context.state\n\n const authProviders = await tx.getRepository(AuthProvider).find({\n where: {\n domain: { id: domain.id },\n id: In(ids)\n }\n })\n\n await Promise.all(\n authProviders.map(async (authProvider: AuthProvider) => {\n await tx.getRepository(AuthProvider).save({\n ...authProvider,\n deletedAt: new Date(),\n updater: user\n })\n })\n )\n return true\n }\n\n @Directive('@transaction')\n @Directive('@privilege(superUserGranted:true)')\n @Mutation(returns => Boolean, { description: 'To synchronize auth-providers users' })\n async synchronizeAuthProviderUsers(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {\n const { domain, user, tx } = context.state\n\n const repository = tx.getRepository(AuthProvider)\n const authProvider = await repository.findOne({\n where: { domain: { id: domain.id }, id },\n relations: ['domain']\n })\n\n const { type } = authProvider\n const { synchronizeUsers } = AuthProvider.getAuthProviderImpl(type) || {}\n\n if (synchronizeUsers) {\n return await synchronizeUsers(authProvider, context)\n } else {\n throw new Error(`No AuthProviderImpl for the type '${type}'`)\n }\n }\n}\n"]}
@@ -26,6 +26,8 @@ let DomainGeneratorMutation = class DomainGeneratorMutation {
26
26
  await (0, domain_ownership_js_1.setPrimaryDomainOwner)(newDomain, user.id, user);
27
27
  return await domainRepo.findOneBy({ id: newDomain.id });
28
28
  }
29
+ /* `domainRegister` beside it makes a domain and is super-user only. This makes a domain,
30
+ its roles and its users, and carried nothing at all. */
29
31
  async domainUserRoleRegister(newDomainInfo, context) {
30
32
  const { tx } = context.state;
31
33
  // 도메인 생성
@@ -94,6 +96,7 @@ tslib_1.__decorate([
94
96
  tslib_1.__metadata("design:returntype", Promise)
95
97
  ], DomainGeneratorMutation.prototype, "domainRegister", null);
96
98
  tslib_1.__decorate([
99
+ (0, type_graphql_1.Directive)('@privilege(superUserGranted: true)'),
97
100
  (0, type_graphql_1.Directive)('@transaction'),
98
101
  (0, type_graphql_1.Mutation)(returns => shell_1.Domain),
99
102
  tslib_1.__param(0, (0, type_graphql_1.Arg)('newDomainInfo')),
@@ -1 +1 @@
1
- {"version":3,"file":"domain-generator-mutation.js","sourceRoot":"","sources":["../../../server/service/domain-generator/domain-generator-mutation.ts"],"names":[],"mappings":";;;;AAAA,+CAAsE;AACtE,qCAA+C;AAE/C,iDAA6D;AAC7D,iDAA+C;AAE/C,yEAAuE;AACvE,4DAAqD;AACrD,6CAAsC;AACtC,6CAAsC;AACtC,2EAAuF;AAGhF,IAAM,uBAAuB,GAA7B,MAAM,uBAAuB;IAI5B,AAAN,KAAK,CAAC,cAAc,CACE,WAAiC,EAC9C,OAA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","sourcesContent":["import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'\nimport { ILike, In, Repository } from 'typeorm'\n\nimport { Domain, getRepository } from '@things-factory/shell'\nimport { slugger } from '@things-factory/utils'\n\nimport { setPrimaryDomainOwner } from '../../utils/domain-ownership.js'\nimport { Privilege } from '../privilege/privilege.js'\nimport { Role } from '../role/role.js'\nimport { User } from '../user/user.js'\nimport { DomainGeneratorInput, DomainUserRoleInput } from './domain-generator-types.js'\n\n@Resolver()\nexport class DomainGeneratorMutation {\n @Directive('@privilege(superUserGranted: true)')\n @Directive('@transaction')\n @Mutation(returns => Domain)\n async domainRegister(\n @Arg('domainInput') domainInput: DomainGeneratorInput,\n @Ctx() context: ResolverContext\n ): Promise<Domain> {\n const { user } = context.state\n const { name, description } = domainInput\n const domainRepo: Repository<Domain> = getRepository(Domain)\n const subdomain: string = slugger(name)\n\n const domain: Domain = await domainRepo.findOneBy({ subdomain })\n if (domain) {\n throw new Error('domain is duplicated')\n }\n\n const newDomain: Domain = await domainRepo.save({ name, description, subdomain })\n\n /* 대표 오너 컬럼과 `DomainOwner` 테이블을 함께 세팅한다 (컬럼만 쓰면 오너 목록에 나오지 않는다). */\n await setPrimaryDomainOwner(newDomain, user.id, user)\n\n return await domainRepo.findOneBy({ id: newDomain.id })\n }\n\n @Directive('@transaction')\n @Mutation(returns => Domain)\n async domainUserRoleRegister(\n @Arg('newDomainInfo') newDomainInfo: DomainUserRoleInput,\n @Ctx() context: ResolverContext\n ): Promise<Domain> {\n const { tx } = context.state\n // 도메인 생성\n const { domain, users, roles } = newDomainInfo\n const domainOwner = users.find(user => user.owner === true)\n\n const domainRepository: Repository<Domain> = tx.getRepository(Domain)\n const roleRepository: Repository<Role> = tx.getRepository(Role)\n const userRepository: Repository<User> = tx.getRepository(User)\n const privilegeRepository: Repository<Privilege> = tx.getRepository(Privilege)\n\n const subdomain: string = slugger(domain.name)\n\n const newDomain = await domainRepository.save({\n name: domain.name,\n description: domain.description,\n subdomain\n })\n\n // 역할 생성\n const newRoles: Role[] = await Promise.all(\n roles.map(async (role: Role) => {\n if (role.privileges?.length) {\n const privilegeIds: string[] = role.privileges.map((p: Privilege) => p.id)\n role.privileges = await privilegeRepository.findBy({\n id: In(privilegeIds)\n })\n }\n\n role.domain = newDomain\n return await roleRepository.save(role)\n })\n )\n\n // 사용자 생성\n let inviteUsers = []\n let createUsers = []\n users.forEach(user => (user.isInvitee ? inviteUsers.push(user) : createUsers.push(user)))\n\n // create user\n await Promise.all(\n createUsers.map(async user => {\n user.domains = [newDomain]\n user.password = User.encode(user.password, user.salt)\n user.salt = User.generateSalt()\n user.passwordUpdatedAt = new Date()\n user.userType = 'user'\n user.roles = filterUserRoles(user.roles, newRoles)\n\n return await userRepository.save(user)\n })\n )\n\n // invite user\n await Promise.all(\n inviteUsers.map(async inviteUser => {\n const user: User = await userRepository.findOne({\n where: { email: inviteUser.email },\n relations: ['domains', 'roles']\n })\n\n user.domains = [...user.domains, newDomain]\n user.roles = [...user.roles, ...filterUserRoles(inviteUser.roles, newRoles)]\n\n return await userRepository.save(user)\n })\n )\n\n // domain owner — 대표 오너 컬럼과 `DomainOwner` 테이블을 함께 세팅한다.\n const { id } = await userRepository.findOne({ where: { email: ILike(domainOwner.email) } })\n await setPrimaryDomainOwner(newDomain, id, context.state.user, tx)\n\n return await domainRepository.findOneBy({ id: newDomain.id })\n }\n}\n\nfunction filterUserRoles(userRoles: Role[], newRoles: Role[]): Role[] {\n const userRoleNames: string[] = userRoles.map((r: Role) => r.name)\n return newRoles.filter((r: Role) => userRoleNames.indexOf(r.name) >= 0)\n}\n"]}
1
+ {"version":3,"file":"domain-generator-mutation.js","sourceRoot":"","sources":["../../../server/service/domain-generator/domain-generator-mutation.ts"],"names":[],"mappings":";;;;AAAA,+CAAsE;AACtE,qCAA+C;AAE/C,iDAA6D;AAC7D,iDAA+C;AAE/C,yEAAuE;AACvE,4DAAqD;AACrD,6CAAsC;AACtC,6CAAsC;AACtC,2EAAuF;AAG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AClE,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAO,EAAE,EAAE,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;AACzE,CAAC","sourcesContent":["import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'\nimport { ILike, In, Repository } from 'typeorm'\n\nimport { Domain, getRepository } from '@things-factory/shell'\nimport { slugger } from '@things-factory/utils'\n\nimport { setPrimaryDomainOwner } from '../../utils/domain-ownership.js'\nimport { Privilege } from '../privilege/privilege.js'\nimport { Role } from '../role/role.js'\nimport { User } from '../user/user.js'\nimport { DomainGeneratorInput, DomainUserRoleInput } from './domain-generator-types.js'\n\n@Resolver()\nexport class DomainGeneratorMutation {\n @Directive('@privilege(superUserGranted: true)')\n @Directive('@transaction')\n @Mutation(returns => Domain)\n async domainRegister(\n @Arg('domainInput') domainInput: DomainGeneratorInput,\n @Ctx() context: ResolverContext\n ): Promise<Domain> {\n const { user } = context.state\n const { name, description } = domainInput\n const domainRepo: Repository<Domain> = getRepository(Domain)\n const subdomain: string = slugger(name)\n\n const domain: Domain = await domainRepo.findOneBy({ subdomain })\n if (domain) {\n throw new Error('domain is duplicated')\n }\n\n const newDomain: Domain = await domainRepo.save({ name, description, subdomain })\n\n /* 대표 오너 컬럼과 `DomainOwner` 테이블을 함께 세팅한다 (컬럼만 쓰면 오너 목록에 나오지 않는다). */\n await setPrimaryDomainOwner(newDomain, user.id, user)\n\n return await domainRepo.findOneBy({ id: newDomain.id })\n }\n\n /* `domainRegister` beside it makes a domain and is super-user only. This makes a domain,\n its roles and its users, and carried nothing at all. */\n @Directive('@privilege(superUserGranted: true)')\n @Directive('@transaction')\n @Mutation(returns => Domain)\n async domainUserRoleRegister(\n @Arg('newDomainInfo') newDomainInfo: DomainUserRoleInput,\n @Ctx() context: ResolverContext\n ): Promise<Domain> {\n const { tx } = context.state\n // 도메인 생성\n const { domain, users, roles } = newDomainInfo\n const domainOwner = users.find(user => user.owner === true)\n\n const domainRepository: Repository<Domain> = tx.getRepository(Domain)\n const roleRepository: Repository<Role> = tx.getRepository(Role)\n const userRepository: Repository<User> = tx.getRepository(User)\n const privilegeRepository: Repository<Privilege> = tx.getRepository(Privilege)\n\n const subdomain: string = slugger(domain.name)\n\n const newDomain = await domainRepository.save({\n name: domain.name,\n description: domain.description,\n subdomain\n })\n\n // 역할 생성\n const newRoles: Role[] = await Promise.all(\n roles.map(async (role: Role) => {\n if (role.privileges?.length) {\n const privilegeIds: string[] = role.privileges.map((p: Privilege) => p.id)\n role.privileges = await privilegeRepository.findBy({\n id: In(privilegeIds)\n })\n }\n\n role.domain = newDomain\n return await roleRepository.save(role)\n })\n )\n\n // 사용자 생성\n let inviteUsers = []\n let createUsers = []\n users.forEach(user => (user.isInvitee ? inviteUsers.push(user) : createUsers.push(user)))\n\n // create user\n await Promise.all(\n createUsers.map(async user => {\n user.domains = [newDomain]\n user.password = User.encode(user.password, user.salt)\n user.salt = User.generateSalt()\n user.passwordUpdatedAt = new Date()\n user.userType = 'user'\n user.roles = filterUserRoles(user.roles, newRoles)\n\n return await userRepository.save(user)\n })\n )\n\n // invite user\n await Promise.all(\n inviteUsers.map(async inviteUser => {\n const user: User = await userRepository.findOne({\n where: { email: inviteUser.email },\n relations: ['domains', 'roles']\n })\n\n user.domains = [...user.domains, newDomain]\n user.roles = [...user.roles, ...filterUserRoles(inviteUser.roles, newRoles)]\n\n return await userRepository.save(user)\n })\n )\n\n // domain owner — 대표 오너 컬럼과 `DomainOwner` 테이블을 함께 세팅한다.\n const { id } = await userRepository.findOne({ where: { email: ILike(domainOwner.email) } })\n await setPrimaryDomainOwner(newDomain, id, context.state.user, tx)\n\n return await domainRepository.findOneBy({ id: newDomain.id })\n }\n}\n\nfunction filterUserRoles(userRoles: Role[], newRoles: Role[]): Role[] {\n const userRoleNames: string[] = userRoles.map((r: Role) => r.name)\n return newRoles.filter((r: Role) => userRoleNames.indexOf(r.name) >= 0)\n}\n"]}
@@ -1,18 +1,20 @@
1
- import { User } from '../../service/user/user.js';
2
1
  import { Invitation } from './invitation.js';
3
2
  export declare class InvitationMutation {
4
- cancelInvitation(email: string, reference: string, type: string): Promise<boolean>;
5
- sendInvitation(email: string, reference: string, type: string, context: ResolverContext): Promise<{
6
- email: string;
7
- reference: string;
8
- type: string;
9
- updater: User;
10
- id: string;
11
- token: string;
12
- createdAt: Date;
13
- updatedAt: Date;
14
- creator: User;
15
- creatorId: string;
16
- updaterId: string;
17
- } & Invitation>;
3
+ /**
4
+ * Invite somebody into this domain by email.
5
+ *
6
+ * ⚠ The domain is the caller's own, never an argument. It used to be `reference`, a string the
7
+ * caller passed, which is how a door that reads by `{ email, reference, type }` ends up
8
+ * answering about other tenants. The domain comes from the request now.
9
+ */
10
+ sendInvitation(email: string, context: ResolverContext, roleIds?: string[]): Promise<Invitation>;
11
+ /** Send the mail again for an invitation that is still open. A new token, a new expiry. */
12
+ resendInvitation(id: string, context: ResolverContext): Promise<boolean>;
13
+ /**
14
+ * Withdraw a pending invitation.
15
+ *
16
+ * The row stays and says it was cancelled. It used to be deleted by `{ email, reference, type }`
17
+ * — which erased the fact that anybody had been invited, and took an id from any tenant.
18
+ */
19
+ cancelInvitation(id: string, context: ResolverContext): Promise<boolean>;
18
20
  }
@@ -2,81 +2,108 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InvitationMutation = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const typeorm_1 = require("typeorm");
6
5
  const type_graphql_1 = require("type-graphql");
7
- const graphql_scalars_1 = require("graphql-scalars");
6
+ const typeorm_1 = require("typeorm");
8
7
  const shell_1 = require("@things-factory/shell");
9
- const user_js_1 = require("../../service/user/user.js");
10
8
  const invitation_js_1 = require("../../controllers/invitation.js");
9
+ const invitation_state_js_1 = require("../../utils/invitation-state.js");
10
+ const role_js_1 = require("../role/role.js");
11
11
  const invitation_js_2 = require("./invitation.js");
12
+ /* Both doors carry what the user screens ask for — inviting somebody is changing who is here. */
13
+ const ADMIN = '@privilege(category: "user", privilege: "mutation", domainOwnerGranted: true)';
12
14
  let InvitationMutation = class InvitationMutation {
13
- async cancelInvitation(email, reference, type) {
14
- const repository = (0, shell_1.getRepository)(invitation_js_2.Invitation);
15
- await repository.delete({
16
- email,
17
- reference,
18
- type
19
- });
20
- return true;
15
+ /**
16
+ * Invite somebody into this domain by email.
17
+ *
18
+ * ⚠ The domain is the caller's own, never an argument. It used to be `reference`, a string the
19
+ * caller passed, which is how a door that reads by `{ email, reference, type }` ends up
20
+ * answering about other tenants. The domain comes from the request now.
21
+ */
22
+ async sendInvitation(email, context, roleIds) {
23
+ const { domain, user, tx } = context.state;
24
+ /*
25
+ * Roles are looked up inside this domain and its parent — the same reach a role picker
26
+ * offers. An id from anywhere else simply does not match, so a role cannot be smuggled in.
27
+ */
28
+ const roles = roleIds?.length
29
+ ? await (0, shell_1.getRepository)(role_js_1.Role, tx).find({
30
+ where: {
31
+ id: (0, typeorm_1.In)(roleIds),
32
+ domain: { id: (0, typeorm_1.In)([domain.id, domain.parentId].filter(Boolean)) }
33
+ }
34
+ })
35
+ : [];
36
+ return await (0, invitation_js_1.inviteByEmail)({ email, domain, roles, user, context, tx });
21
37
  }
22
- async sendInvitation(email, reference, type, context) {
23
- const { user: updater } = context.state;
24
- const invitationRepository = (0, shell_1.getRepository)(invitation_js_2.Invitation);
25
- var user = await (0, shell_1.getRepository)(user_js_1.User).findOne({
26
- where: {
27
- email: (0, typeorm_1.ILike)(email),
28
- status: user_js_1.UserStatus.ACTIVATED
29
- }
38
+ /** Send the mail again for an invitation that is still open. A new token, a new expiry. */
39
+ async resendInvitation(id, context) {
40
+ const { domain, user, tx } = context.state;
41
+ const invitation = await (0, shell_1.getRepository)(invitation_js_2.Invitation, tx).findOne({
42
+ where: { id, domain: { id: domain.id } },
43
+ relations: ['domain']
30
44
  });
31
- if (!user) {
32
- throw new Error(`user not found: ${email}`);
45
+ if (!invitation || !(0, invitation_state_js_1.mayAccept)(invitation)) {
46
+ return false;
33
47
  }
34
- await (0, invitation_js_1.sendInvitationEmail)({
35
- invitation: {
36
- email,
37
- reference,
38
- type
39
- },
48
+ /*
49
+ * A fresh token. Re-mailing the old one would leave two live links for one invitation, and
50
+ * the older mail is the one more likely to have been forwarded.
51
+ */
52
+ const reissued = await (0, invitation_js_1.inviteByEmail)({
53
+ email: invitation.email,
54
+ domain: invitation.domain,
55
+ roles: invitation.roles,
40
56
  user,
41
- context
42
- });
43
- const oldone = await invitationRepository.findOneBy({
44
- email,
45
- type,
46
- reference
47
- });
48
- // update or create
49
- return await invitationRepository.save({
50
- creator: updater,
51
- ...oldone, // take only id from oldone for update
52
- email,
53
- reference,
54
- type,
55
- updater: updater
57
+ context,
58
+ tx
56
59
  });
60
+ return !!reissued;
61
+ }
62
+ /**
63
+ * Withdraw a pending invitation.
64
+ *
65
+ * The row stays and says it was cancelled. It used to be deleted by `{ email, reference, type }`
66
+ * — which erased the fact that anybody had been invited, and took an id from any tenant.
67
+ */
68
+ async cancelInvitation(id, context) {
69
+ const { domain, user, tx } = context.state;
70
+ return await (0, invitation_js_1.cancelInvitation)(id, domain, user, tx);
57
71
  }
58
72
  };
59
73
  exports.InvitationMutation = InvitationMutation;
60
74
  tslib_1.__decorate([
61
- (0, type_graphql_1.Mutation)(returns => Boolean),
62
- tslib_1.__param(0, (0, type_graphql_1.Arg)('email', type => graphql_scalars_1.GraphQLEmailAddress)),
63
- tslib_1.__param(1, (0, type_graphql_1.Arg)('reference')),
64
- tslib_1.__param(2, (0, type_graphql_1.Arg)('type')),
75
+ (0, type_graphql_1.Directive)(ADMIN),
76
+ (0, type_graphql_1.Directive)('@transaction'),
77
+ (0, type_graphql_1.Mutation)(returns => invitation_js_2.Invitation, { description: "To invite someone into this domain by email" }),
78
+ tslib_1.__param(0, (0, type_graphql_1.Arg)('email')),
79
+ tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
80
+ tslib_1.__param(2, (0, type_graphql_1.Arg)('roleIds', type => [String], { nullable: true })),
65
81
  tslib_1.__metadata("design:type", Function),
66
- tslib_1.__metadata("design:paramtypes", [String, String, String]),
82
+ tslib_1.__metadata("design:paramtypes", [String, Object, Array]),
67
83
  tslib_1.__metadata("design:returntype", Promise)
68
- ], InvitationMutation.prototype, "cancelInvitation", null);
84
+ ], InvitationMutation.prototype, "sendInvitation", null);
69
85
  tslib_1.__decorate([
70
- (0, type_graphql_1.Mutation)(returns => invitation_js_2.Invitation),
71
- tslib_1.__param(0, (0, type_graphql_1.Arg)('email', type => graphql_scalars_1.GraphQLEmailAddress)),
72
- tslib_1.__param(1, (0, type_graphql_1.Arg)('reference')),
73
- tslib_1.__param(2, (0, type_graphql_1.Arg)('type')),
74
- tslib_1.__param(3, (0, type_graphql_1.Ctx)()),
86
+ (0, type_graphql_1.Directive)(ADMIN),
87
+ (0, type_graphql_1.Directive)('@transaction'),
88
+ (0, type_graphql_1.Mutation)(returns => Boolean, { description: 'To send a pending invitation again' }),
89
+ tslib_1.__param(0, (0, type_graphql_1.Arg)('id')),
90
+ tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
75
91
  tslib_1.__metadata("design:type", Function),
76
- tslib_1.__metadata("design:paramtypes", [String, String, String, Object]),
92
+ tslib_1.__metadata("design:paramtypes", [String, Object]),
77
93
  tslib_1.__metadata("design:returntype", Promise)
78
- ], InvitationMutation.prototype, "sendInvitation", null);
94
+ ], InvitationMutation.prototype, "resendInvitation", null);
95
+ tslib_1.__decorate([
96
+ (0, type_graphql_1.Directive)(ADMIN),
97
+ (0, type_graphql_1.Directive)('@transaction'),
98
+ (0, type_graphql_1.Mutation)(returns => Boolean, { description: 'To withdraw a pending invitation' }),
99
+ tslib_1.__param(0, (0, type_graphql_1.Arg)('id')),
100
+ tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
101
+ tslib_1.__metadata("design:type", Function),
102
+ tslib_1.__metadata("design:paramtypes", [String, Object]),
103
+ tslib_1.__metadata("design:returntype", Promise)
104
+ ], InvitationMutation.prototype, "cancelInvitation", null);
79
105
  exports.InvitationMutation = InvitationMutation = tslib_1.__decorate([
80
- (0, type_graphql_1.Resolver)(invitation_js_2.Invitation)
106
+ (0, type_graphql_1.Resolver)(invitation_js_2.Invitation),
107
+ (0, type_graphql_1.UseMiddleware)(shell_1.SpeakRefusals)
81
108
  ], InvitationMutation);
82
109
  //# sourceMappingURL=invitation-mutation.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"invitation-mutation.js","sourceRoot":"","sources":["../../../server/service/invitation/invitation-mutation.ts"],"names":[],"mappings":";;;;AAAA,qCAA+B;AAE/B,+CAA2D;AAC3D,qDAAqD;AAErD,iDAAqD;AAErD,wDAA6D;AAC7D,mEAAqE;AACrE,mDAA4C;AAGrC,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAEvB,AAAN,KAAK,CAAC,gBAAgB,CACuB,KAAa,EACtC,SAAiB,EACtB,IAAY;QAEzB,MAAM,UAAU,GAAG,IAAA,qBAAa,EAAC,0BAAU,CAAC,CAAA;QAE5C,MAAM,UAAU,CAAC,MAAM,CAAC;YACtB,KAAK;YACL,SAAS;YACT,IAAI;SACL,CAAC,CAAA;QAEF,OAAO,IAAI,CAAA;IACb,CAAC;IAGK,AAAN,KAAK,CAAC,cAAc,CACyB,KAAa,EACtC,SAAiB,EACtB,IAAY,EAClB,OAAwB;QAE/B,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QACvC,MAAM,oBAAoB,GAAG,IAAA,qBAAa,EAAC,0BAAU,CAAC,CAAA;QAEtD,IAAI,IAAI,GAAG,MAAM,IAAA,qBAAa,EAAC,cAAI,CAAC,CAAC,OAAO,CAAC;YAC3C,KAAK,EAAE;gBACL,KAAK,EAAE,IAAA,eAAK,EAAC,KAAK,CAAC;gBACnB,MAAM,EAAE,oBAAU,CAAC,SAAS;aAC7B;SACF,CAAC,CAAA;QAEF,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM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Ctx, Mutation, Resolver } from 'type-graphql'\nimport { GraphQLEmailAddress } from 'graphql-scalars'\n\nimport { getRepository } from '@things-factory/shell'\n\nimport { User, UserStatus } from '../../service/user/user.js'\nimport { sendInvitationEmail } from '../../controllers/invitation.js'\nimport { Invitation } from './invitation.js'\n\n@Resolver(Invitation)\nexport class InvitationMutation {\n @Mutation(returns => Boolean)\n async cancelInvitation(\n @Arg('email', type => GraphQLEmailAddress) email: string,\n @Arg('reference') reference: string,\n @Arg('type') type: string\n ) {\n const repository = getRepository(Invitation)\n\n await repository.delete({\n email,\n reference,\n type\n })\n\n return true\n }\n\n @Mutation(returns => Invitation)\n async sendInvitation(\n @Arg('email', type => GraphQLEmailAddress) email: string,\n @Arg('reference') reference: string,\n @Arg('type') type: string,\n @Ctx() context: ResolverContext\n ) {\n const { user: updater } = context.state\n const invitationRepository = getRepository(Invitation)\n\n var user = await getRepository(User).findOne({\n where: {\n email: ILike(email),\n status: UserStatus.ACTIVATED\n }\n })\n\n if (!user) {\n throw new Error(`user not found: ${email}`)\n }\n\n await sendInvitationEmail({\n invitation: {\n email,\n reference,\n type\n },\n user,\n context\n })\n\n const oldone = await invitationRepository.findOneBy({\n email,\n type,\n reference\n })\n\n // update or create\n return await invitationRepository.save({\n creator: updater,\n ...oldone, // take only id from oldone for update\n email,\n reference,\n type,\n updater: updater\n })\n }\n}\n"]}
1
+ {"version":3,"file":"invitation-mutation.js","sourceRoot":"","sources":["../../../server/service/invitation/invitation-mutation.ts"],"names":[],"mappings":";;;;AAAA,+CAAqF;AACrF,qCAA4B;AAE5B,iDAAoE;AAEpE,mEAAiG;AACjG,yEAA6E;AAC7E,6CAAsC;AACtC,mDAA4C;AAE5C,iGAAiG;AACjG,MAAM,KAAK,GAAG,+EAA+E,CAAA;AAItF,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAC7B;;;;;;OAMG;IAIG,AAAN,KAAK,CAAC,cAAc,CACJ,KAAa,EACpB,OAAwB,EACuB,OAAkB;QAEx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IAChB,IAAA,wBAAS,EAAC,cAAc,CAAC;IACzB,IAAA,uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,kCAAkC,EAAE,CAAC;IAC1D,mBAAA,IAAA,kBAAG,EAAC,IAAI,CAAC,CAAA;IAAc,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;0DAInD;6BA/EU,kBAAkB;IAF9B,IAAA,uBAAQ,EAAC,0BAAU,CAAC;IACpB,IAAA,4BAAa,EAAC,qBAAa,CAAC;GAChB,kBAAkB,CAgF9B","sourcesContent":["import { Arg, Ctx, Directive, Mutation, Resolver, UseMiddleware } from 'type-graphql'\nimport { In } from 'typeorm'\n\nimport { getRepository, SpeakRefusals } from '@things-factory/shell'\n\nimport { cancelInvitation, inviteByEmail, mailInvitation } from '../../controllers/invitation.js'\nimport { InvitationStatus, mayAccept } from '../../utils/invitation-state.js'\nimport { Role } from '../role/role.js'\nimport { Invitation } from './invitation.js'\n\n/* Both doors carry what the user screens ask for — inviting somebody is changing who is here. */\nconst ADMIN = '@privilege(category: \"user\", privilege: \"mutation\", domainOwnerGranted: true)'\n\n@Resolver(Invitation)\n@UseMiddleware(SpeakRefusals)\nexport class InvitationMutation {\n /**\n * Invite somebody into this domain by email.\n *\n * ⚠ The domain is the caller's own, never an argument. It used to be `reference`, a string the\n * caller passed, which is how a door that reads by `{ email, reference, type }` ends up\n * answering about other tenants. The domain comes from the request now.\n */\n @Directive(ADMIN)\n @Directive('@transaction')\n @Mutation(returns => Invitation, { description: \"To invite someone into this domain by email\" })\n async sendInvitation(\n @Arg('email') email: string,\n @Ctx() context: ResolverContext,\n @Arg('roleIds', type => [String], { nullable: true }) roleIds?: string[]\n ): Promise<Invitation> {\n const { domain, user, tx } = context.state\n\n /*\n * Roles are looked up inside this domain and its parent — the same reach a role picker\n * offers. An id from anywhere else simply does not match, so a role cannot be smuggled in.\n */\n const roles = roleIds?.length\n ? await getRepository(Role, tx).find({\n where: {\n id: In(roleIds),\n domain: { id: In([domain.id, domain.parentId].filter(Boolean)) }\n }\n })\n : []\n\n return await inviteByEmail({ email, domain, roles, user, context, tx })\n }\n\n /** Send the mail again for an invitation that is still open. A new token, a new expiry. */\n @Directive(ADMIN)\n @Directive('@transaction')\n @Mutation(returns => Boolean, { description: 'To send a pending invitation again' })\n async resendInvitation(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {\n const { domain, user, tx } = context.state\n\n const invitation = await getRepository(Invitation, tx).findOne({\n where: { id, domain: { id: domain.id } },\n relations: ['domain']\n })\n\n if (!invitation || !mayAccept(invitation)) {\n return false\n }\n\n /*\n * A fresh token. Re-mailing the old one would leave two live links for one invitation, and\n * the older mail is the one more likely to have been forwarded.\n */\n const reissued = await inviteByEmail({\n email: invitation.email,\n domain: invitation.domain,\n roles: invitation.roles,\n user,\n context,\n tx\n })\n\n return !!reissued\n }\n\n /**\n * Withdraw a pending invitation.\n *\n * The row stays and says it was cancelled. It used to be deleted by `{ email, reference, type }`\n * — which erased the fact that anybody had been invited, and took an id from any tenant.\n */\n @Directive(ADMIN)\n @Directive('@transaction')\n @Mutation(returns => Boolean, { description: 'To withdraw a pending invitation' })\n async cancelInvitation(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {\n const { domain, user, tx } = context.state\n\n return await cancelInvitation(id, domain, user, tx)\n }\n}\n"]}
@@ -1,8 +1,23 @@
1
+ import { ListParam } from '@things-factory/shell';
1
2
  import { Invitation } from './invitation.js';
3
+ import { InvitationList } from './invitation-types.js';
2
4
  export declare class InvitationQuery {
3
- invitation(email: string, reference: string, type: string): Promise<Invitation>;
4
- invitations(reference: string, type: string): Promise<{
5
- items: Invitation[];
6
- total: number;
7
- }>;
5
+ invitation(id: string, context: ResolverContext): Promise<Invitation>;
6
+ /**
7
+ * Who was invited to this domain, by whom, when, and whether they came in.
8
+ *
9
+ * ⚠ This is why the rows are kept. Accepting used to delete the row, so the moment somebody
10
+ * joined, the fact that they had been invited stopped existing — there was nothing to put on a
11
+ * screen, so no screen was built, so nothing called any of this.
12
+ */
13
+ invitations(params: ListParam, context: ResolverContext): Promise<InvitationList>;
14
+ /**
15
+ * What state this invitation is in, read against the clock.
16
+ *
17
+ * ⚠ Not the stored column on its own. A pending row whose expiry has passed **is** expired
18
+ * whether or not anything has been round to write that down — otherwise the list would show a
19
+ * live invitation for a token that no longer opens anything, which is the more dangerous of
20
+ * the two ways to be wrong here.
21
+ */
22
+ state(invitation: Invitation): Promise<string>;
8
23
  }
@@ -2,45 +2,86 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InvitationQuery = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const graphql_scalars_1 = require("graphql-scalars");
6
5
  const type_graphql_1 = require("type-graphql");
7
6
  const shell_1 = require("@things-factory/shell");
7
+ const invitation_state_js_1 = require("../../utils/invitation-state.js");
8
8
  const invitation_js_1 = require("./invitation.js");
9
9
  const invitation_types_js_1 = require("./invitation-types.js");
10
+ /*
11
+ * ── What changed here, and why ──────────────────────────────────────────────
12
+ * These read by `{ email, reference, type }` and took no domain at all — `invitations` did not
13
+ * even take a context, so there was nothing to compare a caller against. An id from one tenant
14
+ * and an id from another were the same kind of argument.
15
+ *
16
+ * They are the invitation **list** now: this domain's invitations, scoped the way every other
17
+ * list in this package is scoped. `reference` is not read; the domain is a column.
18
+ */
19
+ const GATE = '@privilege(category: "user", privilege: "query", domainOwnerGranted: true, superUserGranted: true)';
10
20
  let InvitationQuery = class InvitationQuery {
11
- async invitation(email, reference, type) {
12
- return await (0, shell_1.getRepository)(invitation_js_1.Invitation).findOneBy({
13
- email,
14
- reference,
15
- type
21
+ async invitation(id, context) {
22
+ const { domain } = context.state;
23
+ return await (0, shell_1.getRepository)(invitation_js_1.Invitation).findOne({
24
+ where: { id, domain: { id: domain.id } },
25
+ relations: ['domain', 'roles']
16
26
  });
17
27
  }
18
- async invitations(reference, type) {
19
- const [items, total] = await (0, shell_1.getRepository)(invitation_js_1.Invitation).findAndCountBy({
20
- reference,
21
- type
28
+ /**
29
+ * Who was invited to this domain, by whom, when, and whether they came in.
30
+ *
31
+ * ⚠ This is why the rows are kept. Accepting used to delete the row, so the moment somebody
32
+ * joined, the fact that they had been invited stopped existing — there was nothing to put on a
33
+ * screen, so no screen was built, so nothing called any of this.
34
+ */
35
+ async invitations(params, context) {
36
+ const { domain } = context.state;
37
+ const queryBuilder = (0, shell_1.getQueryBuilderFromListParams)({
38
+ domain,
39
+ params,
40
+ repository: (0, shell_1.getRepository)(invitation_js_1.Invitation),
41
+ alias: 'invitation',
42
+ searchables: ['email']
22
43
  });
44
+ const [items, total] = await queryBuilder.getManyAndCount();
23
45
  return { items, total };
24
46
  }
47
+ /**
48
+ * What state this invitation is in, read against the clock.
49
+ *
50
+ * ⚠ Not the stored column on its own. A pending row whose expiry has passed **is** expired
51
+ * whether or not anything has been round to write that down — otherwise the list would show a
52
+ * live invitation for a token that no longer opens anything, which is the more dangerous of
53
+ * the two ways to be wrong here.
54
+ */
55
+ async state(invitation) {
56
+ return (0, invitation_state_js_1.invitationState)(invitation);
57
+ }
25
58
  };
26
59
  exports.InvitationQuery = InvitationQuery;
27
60
  tslib_1.__decorate([
28
- (0, type_graphql_1.Query)(returns => invitation_js_1.Invitation),
29
- tslib_1.__param(0, (0, type_graphql_1.Arg)('email', type => graphql_scalars_1.GraphQLEmailAddress)),
30
- tslib_1.__param(1, (0, type_graphql_1.Arg)('reference')),
31
- tslib_1.__param(2, (0, type_graphql_1.Arg)('type')),
61
+ (0, type_graphql_1.Directive)(GATE),
62
+ (0, type_graphql_1.Query)(returns => invitation_js_1.Invitation, { nullable: true, description: 'To fetch an invitation of this domain' }),
63
+ tslib_1.__param(0, (0, type_graphql_1.Arg)('id')),
64
+ tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
32
65
  tslib_1.__metadata("design:type", Function),
33
- tslib_1.__metadata("design:paramtypes", [String, String, String]),
66
+ tslib_1.__metadata("design:paramtypes", [String, Object]),
34
67
  tslib_1.__metadata("design:returntype", Promise)
35
68
  ], InvitationQuery.prototype, "invitation", null);
36
69
  tslib_1.__decorate([
37
- (0, type_graphql_1.Query)(returns => invitation_types_js_1.InvitationList),
38
- tslib_1.__param(0, (0, type_graphql_1.Arg)('reference')),
39
- tslib_1.__param(1, (0, type_graphql_1.Arg)('type')),
70
+ (0, type_graphql_1.Directive)(GATE),
71
+ (0, type_graphql_1.Query)(returns => invitation_types_js_1.InvitationList, { description: "To fetch this domain's invitations" }),
72
+ tslib_1.__param(0, (0, type_graphql_1.Args)(type => shell_1.ListParam)),
73
+ tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
40
74
  tslib_1.__metadata("design:type", Function),
41
- tslib_1.__metadata("design:paramtypes", [String, String]),
75
+ tslib_1.__metadata("design:paramtypes", [shell_1.ListParam, Object]),
42
76
  tslib_1.__metadata("design:returntype", Promise)
43
77
  ], InvitationQuery.prototype, "invitations", null);
78
+ tslib_1.__decorate([
79
+ (0, type_graphql_1.FieldResolver)(type => String),
80
+ tslib_1.__param(0, (0, type_graphql_1.Root)()),
81
+ tslib_1.__metadata("design:type", Function),
82
+ tslib_1.__metadata("design:paramtypes", [invitation_js_1.Invitation]),
83
+ tslib_1.__metadata("design:returntype", Promise)
84
+ ], InvitationQuery.prototype, "state", null);
44
85
  exports.InvitationQuery = InvitationQuery = tslib_1.__decorate([
45
86
  (0, type_graphql_1.Resolver)(invitation_js_1.Invitation)
46
87
  ], InvitationQuery);
@@ -1 +1 @@
1
- {"version":3,"file":"invitation-query.js","sourceRoot":"","sources":["../../../server/service/invitation/invitation-query.ts"],"names":[],"mappings":";;;;AAAA,qDAAqD;AACrD,+CAAmD;AAEnD,iDAAqD;AAErD,mDAA4C;AAC5C,+DAAsD;AAG/C,IAAM,eAAe,GAArB,MAAM,eAAe;IAEpB,AAAN,KAAK,CAAC,UAAU,CAC6B,KAAa,EACtC,SAAiB,EACtB,IAAY;QAEzB,OAAO,MAAM,IAAA,qBAAa,EAAC,0BAAU,CAAC,CAAC,SAAS,CAAC;YAC/C,KAAK;YACL,SAAS;YACT,IAAI;SACL,CAAC,CAAA;IACJ,CAAC;IAGK,AAAN,KAAK,CAAC,WAAW,CAAmB,SAAiB,EAAe,IAAY;QAC9E,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,MAAM,IAAA,qBAAa,EAAC,0BAAU,CAAC,CAAC,cAAc,CAAC;YACpE,SAAS;YACT,IAAI;SACL,CAAC,CAAA;QAEF,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAA;IACzB,CAAC;CACF,CAAA;AAvBY,0CAAe;AAEpB;IADL,IAAA,oBAAK,EAAC,OAAO,CAAC,EAAE,CAAC,0BAAU,CAAC;IAE1B,mBAAA,IAAA,kBAAG,EAAC,OAAO,EAAE,IAAI,CAAC,EAAE,CAAC,qCAAmB,CAAC,CAAA;IACzC,mBAAA,IAAA,kBAAG,EAAC,WAAW,CAAC,CAAA;IAChB,mBAAA,IAAA,kBAAG,EAAC,MAAM,CAAC,CAAA;;;;iDAOb;AAGK;IADL,IAAA,oBAAK,EAAC,OAAO,CAAC,EAAE,CAAC,oCAAc,CAAC;IACd,mBAAA,IAAA,kBAAG,EAAC,WAAW,CAAC,CAAA;IAAqB,mBAAA,IAAA,kBAAG,EAAC,MAAM,CAAC,CAAA;;;;kDAOlE;0BAtBU,eAAe;IAD3B,IAAA,uBAAQ,EAAC,0BAAU,CAAC;GACR,eAAe,CAuB3B","sourcesContent":["import { GraphQLEmailAddress } from 'graphql-scalars'\nimport { Arg, Query, Resolver } from 'type-graphql'\n\nimport { getRepository } from '@things-factory/shell'\n\nimport { Invitation } from './invitation.js'\nimport { InvitationList } from './invitation-types.js'\n\n@Resolver(Invitation)\nexport class InvitationQuery {\n @Query(returns => Invitation)\n async invitation(\n @Arg('email', type => GraphQLEmailAddress) email: string,\n @Arg('reference') reference: string,\n @Arg('type') type: string\n ) {\n return await getRepository(Invitation).findOneBy({\n email,\n reference,\n type\n })\n }\n\n @Query(returns => InvitationList)\n async invitations(@Arg('reference') reference: string, @Arg('type') type: string) {\n const [items, total] = await getRepository(Invitation).findAndCountBy({\n reference,\n type\n })\n\n return { items, total }\n }\n}\n"]}
1
+ {"version":3,"file":"invitation-query.js","sourceRoot":"","sources":["../../../server/service/invitation/invitation-query.ts"],"names":[],"mappings":";;;;AAAA,+CAA8F;AAE9F,iDAA+F;AAE/F,yEAAiE;AACjE,mDAA4C;AAC5C,+DAAsD;AAEtD;;;;;;;;GAQG;AACH,MAAM,IAAI,GAAG,oGAAoG,CAAA;AAG1G,IAAM,eAAe,GAArB,MAAM,eAAe;IAGpB,AAAN,KAAK,CAAC,UAAU,CAAY,EAAU,EAAS,OAAwB;QACrE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAEhC,OAAO,MAAM,IAAA,qBAAa,EAAC,0BAAU,CAAC,CAAC,OAAO,CAAC;YAC7C,KAAK,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,EAAE;YACxC,SAAS,EAAE,CAAC,QAAQ,EAAE,OAAO,CAAC;SAC/B,CAAC,CAAA;IACJ,CAAC;IAED;;;;;;OAMG;IAGG,AAAN,KAAK,CAAC,WAAW,CACU,MAAiB,EACnC,OAAwB;QAE/B,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAEhC,MAAM,YAAY,GAAG,IAAA,qCAA6B,EAAC;YACjD,MAAM;YACN,MAAM;YACN,UAAU,EAAE,IAAA,qBAAa,EAAC,0BAAU,CAAC;YACrC,KAAK,EAAE,YAAY;YACnB,WAAW,EAAE,CAAC,OAAO,CAAC;SACvB,CAAC,CAAA;QAEF,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,MAAM,YAAY,CAAC,eAAe,EAAE,CAAA;QAE3D,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAA;IACzB,CAAC;IAED;;;;;;;OAOG;IAEG,AAAN,KAAK,CAAC,KAAK,CAAS,UAAsB;QACxC,OAAO,IAAA,qCAAe,EAAC,UAAU,CAAC,CAAA;IACpC,CAAC;CACF,CAAA;AApDY,0CAAe;AAGpB;IAFL,IAAA,wBAAS,EAAC,IAAI,CAAC;IACf,IAAA,oBAAK,EAAC,OAAO,CAAC,EAAE,CAAC,0BAAU,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,uCAAuC,EAAE,CAAC;IACrF,mBAAA,IAAA,kBAAG,EAAC,IAAI,CAAC,CAAA;IAAc,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;iDAO7C;AAWK;IAFL,IAAA,wBAAS,EAAC,IAAI,CAAC;IACf,IAAA,oBAAK,EAAC,OAAO,CAAC,EAAE,CAAC,oCAAc,EAAE,EAAE,WAAW,EAAE,oCAAoC,EAAE,CAAC;IAErF,mBAAA,IAAA,mBAAI,EAAC,IAAI,CAAC,EAAE,CAAC,iBAAS,CAAC,CAAA;IACvB,mBAAA,IAAA,kBAAG,GAAE,CAAA;;6CAD2B,iBAAS;;kDAgB3C;AAWK;IADL,IAAA,4BAAa,EAAC,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC;IACjB,mBAAA,IAAA,mBAAI,GAAE,CAAA;;6CAAa,0BAAU;;4CAEzC;0BAnDU,eAAe;IAD3B,IAAA,uBAAQ,EAAC,0BAAU,CAAC;GACR,eAAe,CAoD3B","sourcesContent":["import { Arg, Args, Ctx, Directive, FieldResolver, Query, Resolver, Root } from 'type-graphql'\n\nimport { getQueryBuilderFromListParams, getRepository, ListParam } from '@things-factory/shell'\n\nimport { invitationState } from '../../utils/invitation-state.js'\nimport { Invitation } from './invitation.js'\nimport { InvitationList } from './invitation-types.js'\n\n/*\n * ── What changed here, and why ──────────────────────────────────────────────\n * These read by `{ email, reference, type }` and took no domain at all — `invitations` did not\n * even take a context, so there was nothing to compare a caller against. An id from one tenant\n * and an id from another were the same kind of argument.\n *\n * They are the invitation **list** now: this domain's invitations, scoped the way every other\n * list in this package is scoped. `reference` is not read; the domain is a column.\n */\nconst GATE = '@privilege(category: \"user\", privilege: \"query\", domainOwnerGranted: true, superUserGranted: true)'\n\n@Resolver(Invitation)\nexport class InvitationQuery {\n @Directive(GATE)\n @Query(returns => Invitation, { nullable: true, description: 'To fetch an invitation of this domain' })\n async invitation(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Invitation> {\n const { domain } = context.state\n\n return await getRepository(Invitation).findOne({\n where: { id, domain: { id: domain.id } },\n relations: ['domain', 'roles']\n })\n }\n\n /**\n * Who was invited to this domain, by whom, when, and whether they came in.\n *\n * ⚠ This is why the rows are kept. Accepting used to delete the row, so the moment somebody\n * joined, the fact that they had been invited stopped existing — there was nothing to put on a\n * screen, so no screen was built, so nothing called any of this.\n */\n @Directive(GATE)\n @Query(returns => InvitationList, { description: \"To fetch this domain's invitations\" })\n async invitations(\n @Args(type => ListParam) params: ListParam,\n @Ctx() context: ResolverContext\n ): Promise<InvitationList> {\n const { domain } = context.state\n\n const queryBuilder = getQueryBuilderFromListParams({\n domain,\n params,\n repository: getRepository(Invitation),\n alias: 'invitation',\n searchables: ['email']\n })\n\n const [items, total] = await queryBuilder.getManyAndCount()\n\n return { items, total }\n }\n\n /**\n * What state this invitation is in, read against the clock.\n *\n * ⚠ Not the stored column on its own. A pending row whose expiry has passed **is** expired\n * whether or not anything has been round to write that down — otherwise the list would show a\n * live invitation for a token that no longer opens anything, which is the more dangerous of\n * the two ways to be wrong here.\n */\n @FieldResolver(type => String)\n async state(@Root() invitation: Invitation): Promise<string> {\n return invitationState(invitation)\n }\n}\n"]}
@@ -1,10 +1,22 @@
1
+ import { Domain } from '@things-factory/shell';
2
+ import { Role } from '../role/role.js';
1
3
  import { User } from '../user/user.js';
4
+ import { InvitationStatus } from '../../utils/invitation-state.js';
2
5
  export declare class Invitation {
3
6
  readonly id: string;
4
7
  email: string;
5
- reference: string;
6
- type: string;
8
+ domain: Domain;
9
+ domainId: string;
10
+ /** ⚠ Superseded by `domain`. Kept nullable for rows written before that column existed. */
11
+ reference?: string;
12
+ /** ⚠ Superseded by `domain`. Kept nullable for rows written before that column existed. */
13
+ type?: string;
14
+ roles?: Role[];
15
+ status: InvitationStatus;
16
+ expiresAt?: Date;
17
+ acceptedAt?: Date;
7
18
  token: string;
19
+ state?: string;
8
20
  createdAt: Date;
9
21
  updatedAt: Date;
10
22
  creator: User;