@contember/engine-tenant-api 1.2.0 → 1.3.0-alpha.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 (325) hide show
  1. package/dist/src/TenantContainer.d.ts +1 -1
  2. package/dist/src/TenantContainer.d.ts.map +1 -1
  3. package/dist/src/TenantContainer.js +2 -0
  4. package/dist/src/TenantContainer.js.map +1 -1
  5. package/dist/src/bin/runMigrations.d.ts +2 -0
  6. package/dist/src/bin/runMigrations.d.ts.map +1 -0
  7. package/dist/src/bin/runMigrations.js +28 -0
  8. package/dist/src/bin/runMigrations.js.map +1 -0
  9. package/dist/src/migrations/2018-08-02-174310-init.d.ts +3 -0
  10. package/dist/src/migrations/2018-08-02-174310-init.d.ts.map +1 -0
  11. package/dist/src/migrations/2018-08-02-174310-init.js +64 -0
  12. package/dist/src/migrations/2018-08-02-174310-init.js.map +1 -0
  13. package/dist/src/migrations/2018-09-03-140621-identity-project.d.ts +3 -0
  14. package/dist/src/migrations/2018-09-03-140621-identity-project.d.ts.map +1 -0
  15. package/dist/src/migrations/2018-09-03-140621-identity-project.js +33 -0
  16. package/dist/src/migrations/2018-09-03-140621-identity-project.js.map +1 -0
  17. package/dist/src/migrations/2018-10-26-165450-setup-api-key.d.ts +3 -0
  18. package/dist/src/migrations/2018-10-26-165450-setup-api-key.d.ts.map +1 -0
  19. package/dist/src/migrations/2018-10-26-165450-setup-api-key.js +27 -0
  20. package/dist/src/migrations/2018-10-26-165450-setup-api-key.js.map +1 -0
  21. package/dist/src/migrations/2018-10-26-175155-variables.d.ts +3 -0
  22. package/dist/src/migrations/2018-10-26-175155-variables.d.ts.map +1 -0
  23. package/dist/src/migrations/2018-10-26-175155-variables.js +23 -0
  24. package/dist/src/migrations/2018-10-26-175155-variables.js.map +1 -0
  25. package/dist/src/migrations/2019-02-18-110949-project-slug.d.ts +3 -0
  26. package/dist/src/migrations/2019-02-18-110949-project-slug.d.ts.map +1 -0
  27. package/dist/src/migrations/2019-02-18-110949-project-slug.js +18 -0
  28. package/dist/src/migrations/2019-02-18-110949-project-slug.js.map +1 -0
  29. package/dist/src/migrations/2019-02-18-160155-session-expiration.d.ts +3 -0
  30. package/dist/src/migrations/2019-02-18-160155-session-expiration.d.ts.map +1 -0
  31. package/dist/src/migrations/2019-02-18-160155-session-expiration.js +11 -0
  32. package/dist/src/migrations/2019-02-18-160155-session-expiration.js.map +1 -0
  33. package/dist/src/migrations/2019-05-03-163729-api-key-disabled-at.d.ts +3 -0
  34. package/dist/src/migrations/2019-05-03-163729-api-key-disabled-at.d.ts.map +1 -0
  35. package/dist/src/migrations/2019-05-03-163729-api-key-disabled-at.js +18 -0
  36. package/dist/src/migrations/2019-05-03-163729-api-key-disabled-at.js.map +1 -0
  37. package/dist/src/migrations/2019-08-14-153300-project-slug-unique.d.ts +3 -0
  38. package/dist/src/migrations/2019-08-14-153300-project-slug-unique.d.ts.map +1 -0
  39. package/dist/src/migrations/2019-08-14-153300-project-slug-unique.js +11 -0
  40. package/dist/src/migrations/2019-08-14-153300-project-slug-unique.js.map +1 -0
  41. package/dist/src/migrations/2019-09-06-111000-membership.d.ts +3 -0
  42. package/dist/src/migrations/2019-09-06-111000-membership.d.ts.map +1 -0
  43. package/dist/src/migrations/2019-09-06-111000-membership.js +51 -0
  44. package/dist/src/migrations/2019-09-06-111000-membership.js.map +1 -0
  45. package/dist/src/migrations/2019-09-06-111001-drop-old-member.d.ts +3 -0
  46. package/dist/src/migrations/2019-09-06-111001-drop-old-member.d.ts.map +1 -0
  47. package/dist/src/migrations/2019-09-06-111001-drop-old-member.js +11 -0
  48. package/dist/src/migrations/2019-09-06-111001-drop-old-member.js.map +1 -0
  49. package/dist/src/migrations/2020-01-29-idenity-note.d.ts +3 -0
  50. package/dist/src/migrations/2020-01-29-idenity-note.d.ts.map +1 -0
  51. package/dist/src/migrations/2020-01-29-idenity-note.js +18 -0
  52. package/dist/src/migrations/2020-01-29-idenity-note.js.map +1 -0
  53. package/dist/src/migrations/2020-04-17-fix-person-index.d.ts +3 -0
  54. package/dist/src/migrations/2020-04-17-fix-person-index.d.ts.map +1 -0
  55. package/dist/src/migrations/2020-04-17-fix-person-index.js +12 -0
  56. package/dist/src/migrations/2020-04-17-fix-person-index.js.map +1 -0
  57. package/dist/src/migrations/2020-05-01-170000-api-key-index.d.ts +3 -0
  58. package/dist/src/migrations/2020-05-01-170000-api-key-index.d.ts.map +1 -0
  59. package/dist/src/migrations/2020-05-01-170000-api-key-index.js +10 -0
  60. package/dist/src/migrations/2020-05-01-170000-api-key-index.js.map +1 -0
  61. package/dist/src/migrations/2020-06-08-134000-tenant-credentials.d.ts.map +1 -1
  62. package/dist/src/migrations/2020-06-08-134000-tenant-credentials.js +2 -50
  63. package/dist/src/migrations/2020-06-08-134000-tenant-credentials.js.map +1 -1
  64. package/dist/src/migrations/2020-08-07-110000-person-otp.d.ts +3 -0
  65. package/dist/src/migrations/2020-08-07-110000-person-otp.d.ts.map +1 -0
  66. package/dist/src/migrations/2020-08-07-110000-person-otp.js +12 -0
  67. package/dist/src/migrations/2020-08-07-110000-person-otp.js.map +1 -0
  68. package/dist/src/migrations/2020-08-17-162200-mail-templates.d.ts +3 -0
  69. package/dist/src/migrations/2020-08-17-162200-mail-templates.d.ts.map +1 -0
  70. package/dist/src/migrations/2020-08-17-162200-mail-templates.js +23 -0
  71. package/dist/src/migrations/2020-08-17-162200-mail-templates.js.map +1 -0
  72. package/dist/src/migrations/2020-08-21-143400-person-password-reset.d.ts +3 -0
  73. package/dist/src/migrations/2020-08-21-143400-person-password-reset.d.ts.map +1 -0
  74. package/dist/src/migrations/2020-08-21-143400-person-password-reset.js +23 -0
  75. package/dist/src/migrations/2020-08-21-143400-person-password-reset.js.map +1 -0
  76. package/dist/src/migrations/2020-09-07-094200-identity-provider.d.ts +3 -0
  77. package/dist/src/migrations/2020-09-07-094200-identity-provider.d.ts.map +1 -0
  78. package/dist/src/migrations/2020-09-07-094200-identity-provider.js +17 -0
  79. package/dist/src/migrations/2020-09-07-094200-identity-provider.js.map +1 -0
  80. package/dist/src/migrations/2021-03-28-134000-timestamp.d.ts +3 -0
  81. package/dist/src/migrations/2021-03-28-134000-timestamp.d.ts.map +1 -0
  82. package/dist/src/migrations/2021-03-28-134000-timestamp.js +27 -0
  83. package/dist/src/migrations/2021-03-28-134000-timestamp.js.map +1 -0
  84. package/dist/src/migrations/2021-07-26-105000-project-config.d.ts +3 -0
  85. package/dist/src/migrations/2021-07-26-105000-project-config.d.ts.map +1 -0
  86. package/dist/src/migrations/2021-07-26-105000-project-config.js +12 -0
  87. package/dist/src/migrations/2021-07-26-105000-project-config.js.map +1 -0
  88. package/dist/src/migrations/2021-07-26-132000-project-secrets.d.ts +3 -0
  89. package/dist/src/migrations/2021-07-26-132000-project-secrets.d.ts.map +1 -0
  90. package/dist/src/migrations/2021-07-26-132000-project-secrets.js +24 -0
  91. package/dist/src/migrations/2021-07-26-132000-project-secrets.js.map +1 -0
  92. package/dist/src/migrations/2021-07-27-174000-project-alias-index.d.ts +3 -0
  93. package/dist/src/migrations/2021-07-27-174000-project-alias-index.d.ts.map +1 -0
  94. package/dist/src/migrations/2021-07-27-174000-project-alias-index.js +10 -0
  95. package/dist/src/migrations/2021-07-27-174000-project-alias-index.js.map +1 -0
  96. package/dist/src/migrations/2021-11-24-130000-person-password-null.d.ts +3 -0
  97. package/dist/src/migrations/2021-11-24-130000-person-password-null.d.ts.map +1 -0
  98. package/dist/src/migrations/2021-11-24-130000-person-password-null.js +10 -0
  99. package/dist/src/migrations/2021-11-24-130000-person-password-null.js.map +1 -0
  100. package/dist/src/migrations/2021-11-24-161500-mail-template-project-null.d.ts +3 -0
  101. package/dist/src/migrations/2021-11-24-161500-mail-template-project-null.d.ts.map +1 -0
  102. package/dist/src/migrations/2021-11-24-161500-mail-template-project-null.js +18 -0
  103. package/dist/src/migrations/2021-11-24-161500-mail-template-project-null.js.map +1 -0
  104. package/dist/src/migrations/2022-01-04-144000-person-unique-identity.d.ts +3 -0
  105. package/dist/src/migrations/2022-01-04-144000-person-unique-identity.d.ts.map +1 -0
  106. package/dist/src/migrations/2022-01-04-144000-person-unique-identity.js +11 -0
  107. package/dist/src/migrations/2022-01-04-144000-person-unique-identity.js.map +1 -0
  108. package/dist/src/migrations/2022-02-09-111800-fix-crypted.d.ts +3 -0
  109. package/dist/src/migrations/2022-02-09-111800-fix-crypted.d.ts.map +1 -0
  110. package/dist/src/migrations/2022-02-09-111800-fix-crypted.js +22 -0
  111. package/dist/src/migrations/2022-02-09-111800-fix-crypted.js.map +1 -0
  112. package/dist/src/migrations/2022-02-11-153000-idp-auto-sign-up.d.ts +3 -0
  113. package/dist/src/migrations/2022-02-11-153000-idp-auto-sign-up.d.ts.map +1 -0
  114. package/dist/src/migrations/2022-02-11-153000-idp-auto-sign-up.js +11 -0
  115. package/dist/src/migrations/2022-02-11-153000-idp-auto-sign-up.js.map +1 -0
  116. package/dist/src/migrations/2022-06-29-105000-person-idp.d.ts +3 -0
  117. package/dist/src/migrations/2022-06-29-105000-person-idp.d.ts.map +1 -0
  118. package/dist/src/migrations/2022-06-29-105000-person-idp.js +23 -0
  119. package/dist/src/migrations/2022-06-29-105000-person-idp.js.map +1 -0
  120. package/dist/src/migrations/2022-07-07-135000-person-email-opt-uniq.d.ts +3 -0
  121. package/dist/src/migrations/2022-07-07-135000-person-email-opt-uniq.d.ts.map +1 -0
  122. package/dist/src/migrations/2022-07-07-135000-person-email-opt-uniq.js +12 -0
  123. package/dist/src/migrations/2022-07-07-135000-person-email-opt-uniq.js.map +1 -0
  124. package/dist/src/migrations/2022-07-07-141000-person-display-name.d.ts +3 -0
  125. package/dist/src/migrations/2022-07-07-141000-person-display-name.d.ts.map +1 -0
  126. package/dist/src/migrations/2022-07-07-141000-person-display-name.js +13 -0
  127. package/dist/src/migrations/2022-07-07-141000-person-display-name.js.map +1 -0
  128. package/dist/src/migrations/2022-07-14-145000-person-login-options.d.ts +3 -0
  129. package/dist/src/migrations/2022-07-14-145000-person-login-options.d.ts.map +1 -0
  130. package/dist/src/migrations/2022-07-14-145000-person-login-options.js +15 -0
  131. package/dist/src/migrations/2022-07-14-145000-person-login-options.js.map +1 -0
  132. package/dist/src/migrations/2022-11-08-project-update-notification.d.ts +3 -0
  133. package/dist/src/migrations/2022-11-08-project-update-notification.d.ts.map +1 -0
  134. package/dist/src/migrations/2022-11-08-project-update-notification.js +64 -0
  135. package/dist/src/migrations/2022-11-08-project-update-notification.js.map +1 -0
  136. package/dist/src/migrations/runner.d.ts +1 -1
  137. package/dist/src/migrations/runner.d.ts.map +1 -1
  138. package/dist/src/migrations/runner.js +68 -5
  139. package/dist/src/migrations/runner.js.map +1 -1
  140. package/dist/src/migrations/snapshot-factory.d.ts +5 -0
  141. package/dist/src/migrations/snapshot-factory.d.ts.map +1 -0
  142. package/dist/src/migrations/snapshot-factory.js +18 -0
  143. package/dist/src/migrations/snapshot-factory.js.map +1 -0
  144. package/dist/src/migrations/snapshot.d.ts +4 -0
  145. package/dist/src/migrations/snapshot.d.ts.map +1 -0
  146. package/dist/src/migrations/snapshot.js +202 -0
  147. package/dist/src/migrations/snapshot.js.map +1 -0
  148. package/dist/src/migrations/tenantCredentials.d.ts +4 -0
  149. package/dist/src/migrations/tenantCredentials.d.ts.map +1 -0
  150. package/dist/src/migrations/tenantCredentials.js +57 -0
  151. package/dist/src/migrations/tenantCredentials.js.map +1 -0
  152. package/dist/src/migrations/types.d.ts +2 -0
  153. package/dist/src/migrations/types.d.ts.map +1 -1
  154. package/dist/src/model/commands/idp/UpdateIdpCommand.d.ts +1 -0
  155. package/dist/src/model/commands/idp/UpdateIdpCommand.d.ts.map +1 -1
  156. package/dist/src/model/queries/membership/ProjectMembersQuery.d.ts +3 -3
  157. package/dist/src/model/queries/membership/ProjectMembersQuery.d.ts.map +1 -1
  158. package/dist/src/model/queries/membership/ProjectMembersQuery.js +22 -10
  159. package/dist/src/model/queries/membership/ProjectMembersQuery.js.map +1 -1
  160. package/dist/src/model/service/IDPSignInManager.d.ts +3 -3
  161. package/dist/src/model/service/IDPSignInManager.d.ts.map +1 -1
  162. package/dist/src/model/service/IDPSignInManager.js +13 -5
  163. package/dist/src/model/service/IDPSignInManager.js.map +1 -1
  164. package/dist/src/model/service/ProjectMemberManager.d.ts +2 -2
  165. package/dist/src/model/service/ProjectMemberManager.d.ts.map +1 -1
  166. package/dist/src/model/service/ProjectMemberManager.js +2 -2
  167. package/dist/src/model/service/ProjectMemberManager.js.map +1 -1
  168. package/dist/src/model/service/idp/IDPHandlerRegistry.d.ts +2 -2
  169. package/dist/src/model/service/idp/IDPHandlerRegistry.d.ts.map +1 -1
  170. package/dist/src/model/service/idp/IDPHandlerRegistry.js.map +1 -1
  171. package/dist/src/model/service/idp/IDPManager.d.ts.map +1 -1
  172. package/dist/src/model/service/idp/IDPManager.js +7 -2
  173. package/dist/src/model/service/idp/IDPManager.js.map +1 -1
  174. package/dist/src/model/service/idp/IdentityProviderHandler.d.ts +6 -9
  175. package/dist/src/model/service/idp/IdentityProviderHandler.d.ts.map +1 -1
  176. package/dist/src/model/service/idp/index.d.ts +3 -1
  177. package/dist/src/model/service/idp/index.d.ts.map +1 -1
  178. package/dist/src/model/service/idp/index.js +3 -1
  179. package/dist/src/model/service/idp/index.js.map +1 -1
  180. package/dist/src/model/service/idp/providers/AppleProvider.d.ts +29 -0
  181. package/dist/src/model/service/idp/providers/AppleProvider.d.ts.map +1 -0
  182. package/dist/src/model/service/idp/providers/AppleProvider.js +79 -0
  183. package/dist/src/model/service/idp/providers/AppleProvider.js.map +1 -0
  184. package/dist/src/model/service/idp/providers/FacebookProvider.d.ts +27 -0
  185. package/dist/src/model/service/idp/providers/FacebookProvider.d.ts.map +1 -0
  186. package/dist/src/model/service/idp/providers/FacebookProvider.js +137 -0
  187. package/dist/src/model/service/idp/providers/FacebookProvider.js.map +1 -0
  188. package/dist/src/model/service/idp/providers/OIDCHelpers.d.ts +10 -0
  189. package/dist/src/model/service/idp/providers/OIDCHelpers.d.ts.map +1 -0
  190. package/dist/src/model/service/idp/providers/OIDCHelpers.js +56 -0
  191. package/dist/src/model/service/idp/providers/OIDCHelpers.js.map +1 -0
  192. package/dist/src/model/service/idp/providers/OIDCProvider.d.ts +19 -0
  193. package/dist/src/model/service/idp/providers/OIDCProvider.d.ts.map +1 -0
  194. package/dist/src/model/service/idp/providers/OIDCProvider.js +40 -0
  195. package/dist/src/model/service/idp/providers/OIDCProvider.js.map +1 -0
  196. package/dist/src/model/service/idp/providers/OIDCTypes.d.ts +62 -0
  197. package/dist/src/model/service/idp/providers/OIDCTypes.d.ts.map +1 -0
  198. package/dist/src/model/service/idp/providers/OIDCTypes.js +56 -0
  199. package/dist/src/model/service/idp/providers/OIDCTypes.js.map +1 -0
  200. package/dist/src/model/service/idp/providers/helpers.d.ts +3 -0
  201. package/dist/src/model/service/idp/providers/helpers.d.ts.map +1 -0
  202. package/dist/src/model/service/idp/providers/helpers.js +40 -0
  203. package/dist/src/model/service/idp/providers/helpers.js.map +1 -0
  204. package/dist/src/model/utils/DatabaseContext.d.ts +1 -0
  205. package/dist/src/model/utils/DatabaseContext.d.ts.map +1 -1
  206. package/dist/src/model/utils/DatabaseContext.js +5 -0
  207. package/dist/src/model/utils/DatabaseContext.js.map +1 -1
  208. package/dist/src/resolvers/mutation/idp/UpdateIDPMutationResolver.d.ts.map +1 -1
  209. package/dist/src/resolvers/mutation/idp/UpdateIDPMutationResolver.js +4 -3
  210. package/dist/src/resolvers/mutation/idp/UpdateIDPMutationResolver.js.map +1 -1
  211. package/dist/src/resolvers/mutation/person/IDPMutationResolver.d.ts.map +1 -1
  212. package/dist/src/resolvers/mutation/person/IDPMutationResolver.js +10 -3
  213. package/dist/src/resolvers/mutation/person/IDPMutationResolver.js.map +1 -1
  214. package/dist/src/resolvers/types/ProjectTypeResolver.d.ts.map +1 -1
  215. package/dist/src/resolvers/types/ProjectTypeResolver.js +14 -6
  216. package/dist/src/resolvers/types/ProjectTypeResolver.js.map +1 -1
  217. package/dist/src/schema/index.d.ts +26 -8
  218. package/dist/src/schema/index.d.ts.map +1 -1
  219. package/dist/src/schema/index.js +1 -0
  220. package/dist/src/schema/index.js.map +1 -1
  221. package/dist/src/schema/tenant.graphql.d.ts.map +1 -1
  222. package/dist/src/schema/tenant.graphql.js +32 -6
  223. package/dist/src/schema/tenant.graphql.js.map +1 -1
  224. package/dist/src/tsconfig.tsbuildinfo +1 -1
  225. package/dist/tests/cases/integration/db/invite.test.js +2 -2
  226. package/dist/tests/cases/integration/db/unmanagedInvite.test.js +2 -2
  227. package/dist/{src → tests/cases}/migrations/2020-06-08-134000-tenant-credentials.test.d.ts +1 -1
  228. package/dist/tests/cases/migrations/2020-06-08-134000-tenant-credentials.test.d.ts.map +1 -0
  229. package/dist/{src → tests/cases}/migrations/2020-06-08-134000-tenant-credentials.test.js +19 -9
  230. package/dist/tests/cases/migrations/2020-06-08-134000-tenant-credentials.test.js.map +1 -0
  231. package/dist/tests/src/IdPMock.d.ts +4 -4
  232. package/dist/tests/src/IdPMock.d.ts.map +1 -1
  233. package/dist/tests/src/IdPMock.js +2 -2
  234. package/dist/tests/src/IdPMock.js.map +1 -1
  235. package/dist/tests/tsconfig.tsbuildinfo +1 -1
  236. package/package.json +14 -13
  237. package/src/TenantContainer.ts +4 -2
  238. package/src/bin/runMigrations.ts +32 -0
  239. package/src/migrations/{2018-08-02-174310-init.sql → 2018-08-02-174310-init.ts} +8 -1
  240. package/src/migrations/{2018-09-03-140621-identity-project.sql → 2018-09-03-140621-identity-project.ts} +8 -0
  241. package/src/migrations/{2018-10-26-165450-setup-api-key.sql → 2018-10-26-165450-setup-api-key.ts} +8 -0
  242. package/src/migrations/{2018-10-26-175155-variables.sql → 2018-10-26-175155-variables.ts} +7 -0
  243. package/src/migrations/{2019-02-18-110949-project-slug.sql → 2019-02-18-110949-project-slug.ts} +8 -0
  244. package/src/migrations/2019-02-18-160155-session-expiration.ts +10 -0
  245. package/src/migrations/{2019-05-03-163729-api-key-disabled-at.sql → 2019-05-03-163729-api-key-disabled-at.ts} +8 -0
  246. package/src/migrations/2019-08-14-153300-project-slug-unique.ts +10 -0
  247. package/src/migrations/{2019-09-06-111000-membership.sql → 2019-09-06-111000-membership.ts} +8 -0
  248. package/src/migrations/2019-09-06-111001-drop-old-member.ts +10 -0
  249. package/src/migrations/2020-01-29-idenity-note.ts +18 -0
  250. package/src/migrations/2020-04-17-fix-person-index.ts +12 -0
  251. package/src/migrations/2020-05-01-170000-api-key-index.ts +10 -0
  252. package/src/migrations/2020-06-08-134000-tenant-credentials.ts +3 -54
  253. package/src/migrations/2020-08-07-110000-person-otp.ts +12 -0
  254. package/src/migrations/{2020-08-17-162200-mail-templates.sql → 2020-08-17-162200-mail-templates.ts} +8 -0
  255. package/src/migrations/{2020-08-21-143400-person-password-reset.sql → 2020-08-21-143400-person-password-reset.ts} +8 -0
  256. package/src/migrations/{2020-09-07-094200-identity-provider.sql → 2020-09-07-094200-identity-provider.ts} +8 -0
  257. package/src/migrations/{2021-03-28-134000-timestamp.sql → 2021-03-28-134000-timestamp.ts} +9 -0
  258. package/src/migrations/2021-07-26-105000-project-config.ts +12 -0
  259. package/src/migrations/{2021-07-26-132000-project-secrets.sql → 2021-07-26-132000-project-secrets.ts} +8 -0
  260. package/src/migrations/2021-07-27-174000-project-alias-index.ts +10 -0
  261. package/src/migrations/2021-11-24-130000-person-password-null.ts +10 -0
  262. package/src/migrations/{2021-11-24-161500-mail-template-project-null.sql → 2021-11-24-161500-mail-template-project-null.ts} +8 -0
  263. package/src/migrations/2022-01-04-144000-person-unique-identity.ts +10 -0
  264. package/src/migrations/{2022-02-09-111800-fix-crypted.sql → 2022-02-09-111800-fix-crypted.ts} +8 -0
  265. package/src/migrations/2022-02-11-153000-idp-auto-sign-up.ts +10 -0
  266. package/src/migrations/{2022-06-29-105000-person-idp.sql → 2022-06-29-105000-person-idp.ts} +8 -0
  267. package/src/migrations/2022-07-07-135000-person-email-opt-uniq.ts +11 -0
  268. package/src/migrations/2022-07-07-141000-person-display-name.ts +13 -0
  269. package/src/migrations/{2022-07-14-145000-person-login-options.sql → 2022-07-14-145000-person-login-options.ts} +9 -0
  270. package/src/migrations/2022-11-08-project-update-notification.ts +64 -0
  271. package/src/migrations/runner.ts +72 -8
  272. package/src/migrations/snapshot-factory.ts +21 -0
  273. package/src/migrations/snapshot-template-end.txt +10 -0
  274. package/src/migrations/snapshot-template-start.txt +6 -0
  275. package/src/migrations/snapshot.ts +202 -0
  276. package/src/migrations/tenantCredentials.ts +58 -0
  277. package/src/migrations/types.ts +3 -0
  278. package/src/model/commands/idp/UpdateIdpCommand.ts +1 -0
  279. package/src/model/queries/membership/ProjectMembersQuery.ts +23 -14
  280. package/src/model/service/IDPSignInManager.ts +13 -10
  281. package/src/model/service/ProjectMemberManager.ts +3 -3
  282. package/src/model/service/idp/IDPHandlerRegistry.ts +3 -3
  283. package/src/model/service/idp/IDPManager.ts +6 -2
  284. package/src/model/service/idp/IdentityProviderHandler.ts +7 -15
  285. package/src/model/service/idp/index.ts +3 -1
  286. package/src/model/service/idp/providers/AppleProvider.ts +65 -0
  287. package/src/model/service/idp/providers/FacebookProvider.ts +125 -0
  288. package/src/model/service/idp/providers/OIDCHelpers.ts +54 -0
  289. package/src/model/service/idp/providers/OIDCProvider.ts +40 -0
  290. package/src/model/service/idp/providers/OIDCTypes.ts +61 -0
  291. package/src/model/service/idp/providers/helpers.ts +12 -0
  292. package/src/model/utils/DatabaseContext.ts +6 -0
  293. package/src/resolvers/mutation/idp/UpdateIDPMutationResolver.ts +1 -0
  294. package/src/resolvers/mutation/person/IDPMutationResolver.ts +9 -7
  295. package/src/resolvers/types/ProjectTypeResolver.ts +9 -2
  296. package/src/schema/index.ts +28 -8
  297. package/src/schema/tenant.graphql.ts +32 -6
  298. package/src/tsconfig.json +10 -30
  299. package/tests/cases/integration/db/invite.test.ts +2 -2
  300. package/tests/cases/integration/db/unmanagedInvite.test.ts +2 -2
  301. package/{src → tests/cases}/migrations/2020-06-08-134000-tenant-credentials.test.ts +17 -9
  302. package/tests/src/IdPMock.ts +4 -4
  303. package/tests/tsconfig.json +2 -6
  304. package/tsconfig.json +2 -6
  305. package/dist/src/migrations/2020-06-08-134000-tenant-credentials.test.d.ts.map +0 -1
  306. package/dist/src/migrations/2020-06-08-134000-tenant-credentials.test.js.map +0 -1
  307. package/dist/src/model/service/idp/OIDCProvider.d.ts +0 -25
  308. package/dist/src/model/service/idp/OIDCProvider.d.ts.map +0 -1
  309. package/dist/src/model/service/idp/OIDCProvider.js +0 -108
  310. package/dist/src/model/service/idp/OIDCProvider.js.map +0 -1
  311. package/src/migrations/2019-02-18-160155-session-expiration.sql +0 -2
  312. package/src/migrations/2019-08-14-153300-project-slug-unique.sql +0 -2
  313. package/src/migrations/2019-09-06-111001-drop-old-member.sql +0 -2
  314. package/src/migrations/2020-01-29-idenity-note.sql +0 -9
  315. package/src/migrations/2020-04-17-fix-person-index.sql +0 -3
  316. package/src/migrations/2020-05-01-170000-api-key-index.sql +0 -1
  317. package/src/migrations/2020-08-07-110000-person-otp.sql +0 -3
  318. package/src/migrations/2021-07-26-105000-project-config.sql +0 -3
  319. package/src/migrations/2021-07-27-174000-project-alias-index.sql +0 -1
  320. package/src/migrations/2021-11-24-130000-person-password-null.sql +0 -1
  321. package/src/migrations/2022-01-04-144000-person-unique-identity.sql +0 -2
  322. package/src/migrations/2022-02-11-153000-idp-auto-sign-up.sql +0 -2
  323. package/src/migrations/2022-07-07-135000-person-email-opt-uniq.sql +0 -3
  324. package/src/migrations/2022-07-07-141000-person-display-name.sql +0 -4
  325. package/src/model/service/idp/OIDCProvider.ts +0 -100
@@ -0,0 +1,64 @@
1
+ import { MigrationBuilder } from '@contember/database-migrations'
2
+
3
+ const sql = `
4
+ CREATE FUNCTION project_updated()
5
+ RETURNS TRIGGER AS
6
+ $$
7
+ BEGIN
8
+ NEW.updated_at = 'now';
9
+ PERFORM pg_notify('project_updated', new.id::text);
10
+ RETURN new;
11
+ END;
12
+ $$ LANGUAGE plpgsql;
13
+
14
+ CREATE FUNCTION project_deleted()
15
+ RETURNS TRIGGER AS
16
+ $$
17
+ BEGIN
18
+ PERFORM pg_notify('project_updated', old.id::text);
19
+ RETURN NULL;
20
+ END;
21
+ $$ LANGUAGE plpgsql;
22
+
23
+
24
+ CREATE FUNCTION project_secret_updated()
25
+ RETURNS TRIGGER AS
26
+ $$
27
+ BEGIN
28
+ UPDATE project SET updated_at = 'now' WHERE id = COALESCE(new.project_id, old.project_id);
29
+ PERFORM pg_notify('project_updated', COALESCE(new.project_id, old.project_id)::TEXT);
30
+ RETURN NULL;
31
+ END;
32
+ $$ LANGUAGE plpgsql;
33
+
34
+ CREATE TRIGGER project_updated
35
+ BEFORE INSERT OR UPDATE OF name, slug, config
36
+ ON project
37
+ FOR EACH ROW
38
+ EXECUTE PROCEDURE project_updated();
39
+
40
+ CREATE TRIGGER project_deleted
41
+ AFTER DELETE
42
+ ON project
43
+ FOR EACH ROW
44
+ EXECUTE PROCEDURE project_deleted();
45
+
46
+ CREATE TRIGGER project_secret_updated
47
+ AFTER DELETE OR INSERT OR UPDATE
48
+ ON project_secret
49
+ FOR EACH ROW
50
+ EXECUTE PROCEDURE project_secret_updated();
51
+
52
+
53
+ DO LANGUAGE plpgsql
54
+ $$
55
+ BEGIN
56
+ EXECUTE FORMAT('ALTER FUNCTION project_secret_updated() SET SEARCH_PATH = %s', QUOTE_IDENT(CURRENT_SCHEMA()));
57
+ END
58
+ $$;
59
+ `
60
+
61
+ export default async function (builder: MigrationBuilder) {
62
+ builder.sql(sql)
63
+ }
64
+
@@ -1,7 +1,39 @@
1
1
  import { Connection, createDatabaseIfNotExists, DatabaseConfig, EventManager } from '@contember/database'
2
2
  import { TenantMigrationArgs } from './types'
3
- import { loadMigrations, Migration, MigrationsRunner as DbMigrationsRunner } from '@contember/database-migrations'
4
- import tenantCredentials from './2020-06-08-134000-tenant-credentials'
3
+ import { MigrationsRunner as DbMigrationsRunner, SnapshotMigrationResolver } from '@contember/database-migrations'
4
+ import _20180802174310init from './2018-08-02-174310-init'
5
+ import _20180903140621identityproject from './2018-09-03-140621-identity-project'
6
+ import _20181026165450setupapikey from './2018-10-26-165450-setup-api-key'
7
+ import _20181026175155variables from './2018-10-26-175155-variables'
8
+ import _20190218110949projectslug from './2019-02-18-110949-project-slug'
9
+ import _20190218160155sessionexpiration from './2019-02-18-160155-session-expiration'
10
+ import _20190503163729apikeydisabledat from './2019-05-03-163729-api-key-disabled-at'
11
+ import _20190814153300projectslugunique from './2019-08-14-153300-project-slug-unique'
12
+ import _20190906111000membership from './2019-09-06-111000-membership'
13
+ import _20190906111001dropoldmember from './2019-09-06-111001-drop-old-member'
14
+ import _20200129idenitynote from './2020-01-29-idenity-note'
15
+ import _20200417fixpersonindex from './2020-04-17-fix-person-index'
16
+ import _20200501170000apikeyindex from './2020-05-01-170000-api-key-index'
17
+ import _20200608134000tenantcredentials from './2020-06-08-134000-tenant-credentials'
18
+ import _20200807110000personotp from './2020-08-07-110000-person-otp'
19
+ import _20200817162200mailtemplates from './2020-08-17-162200-mail-templates'
20
+ import _20200821143400personpasswordreset from './2020-08-21-143400-person-password-reset'
21
+ import _20200907094200identityprovider from './2020-09-07-094200-identity-provider'
22
+ import _20210328134000timestamp from './2021-03-28-134000-timestamp'
23
+ import _20210726105000projectconfig from './2021-07-26-105000-project-config'
24
+ import _20210726132000projectsecrets from './2021-07-26-132000-project-secrets'
25
+ import _20210727174000projectaliasindex from './2021-07-27-174000-project-alias-index'
26
+ import _20211124130000personpasswordnull from './2021-11-24-130000-person-password-null'
27
+ import _20211124161500mailtemplateprojectnull from './2021-11-24-161500-mail-template-project-null'
28
+ import _20220104144000personuniqueidentity from './2022-01-04-144000-person-unique-identity'
29
+ import _20220209111800fixcrypted from './2022-02-09-111800-fix-crypted'
30
+ import _20220211153000idpautosignup from './2022-02-11-153000-idp-auto-sign-up'
31
+ import _20220629105000personidp from './2022-06-29-105000-person-idp'
32
+ import _20220707135000personemailoptuniq from './2022-07-07-135000-person-email-opt-uniq'
33
+ import _20220707141000persondisplayname from './2022-07-07-141000-person-display-name'
34
+ import _20220714145000personloginoptions from './2022-07-14-145000-person-login-options'
35
+ import _20221108projectupdatenotification from './2022-11-08-project-update-notification'
36
+ import snapshot from './snapshot'
5
37
  import { computeTokenHash, Providers } from '../model'
6
38
  import { Logger } from '@contember/logger'
7
39
 
@@ -13,10 +45,39 @@ export interface TenantCredentials {
13
45
  rootPassword?: string
14
46
  }
15
47
 
16
- const getMigrations = (): Promise<Migration<TenantMigrationArgs>[]> => {
17
- return loadMigrations(process.env.CONTEMBER_TENANT_MIGRATIONS_DIR || __dirname, [
18
- new Migration('2020-06-08-134000-tenant-credentials', tenantCredentials),
19
- ])
48
+ const migrations = {
49
+ '2018-08-02-174310-init': _20180802174310init,
50
+ '2018-09-03-140621-identity-project': _20180903140621identityproject,
51
+ '2018-10-26-165450-setup-api-key': _20181026165450setupapikey,
52
+ '2018-10-26-175155-variables': _20181026175155variables,
53
+ '2019-02-18-110949-project-slug': _20190218110949projectslug,
54
+ '2019-02-18-160155-session-expiration': _20190218160155sessionexpiration,
55
+ '2019-05-03-163729-api-key-disabled-at': _20190503163729apikeydisabledat,
56
+ '2019-08-14-153300-project-slug-unique': _20190814153300projectslugunique,
57
+ '2019-09-06-111000-membership': _20190906111000membership,
58
+ '2019-09-06-111001-drop-old-member': _20190906111001dropoldmember,
59
+ '2020-01-29-idenity-note': _20200129idenitynote,
60
+ '2020-04-17-fix-person-index': _20200417fixpersonindex,
61
+ '2020-05-01-170000-api-key-index': _20200501170000apikeyindex,
62
+ '2020-06-08-134000-tenant-credentials': _20200608134000tenantcredentials,
63
+ '2020-08-07-110000-person-otp': _20200807110000personotp,
64
+ '2020-08-17-162200-mail-templates': _20200817162200mailtemplates,
65
+ '2020-08-21-143400-person-password-reset': _20200821143400personpasswordreset,
66
+ '2020-09-07-094200-identity-provider': _20200907094200identityprovider,
67
+ '2021-03-28-134000-timestamp': _20210328134000timestamp,
68
+ '2021-07-26-105000-project-config': _20210726105000projectconfig,
69
+ '2021-07-26-132000-project-secrets': _20210726132000projectsecrets,
70
+ '2021-07-27-174000-project-alias-index': _20210727174000projectaliasindex,
71
+ '2021-11-24-130000-person-password-null': _20211124130000personpasswordnull,
72
+ '2021-11-24-161500-mail-template-project-null': _20211124161500mailtemplateprojectnull,
73
+ '2022-01-04-144000-person-unique-identity': _20220104144000personuniqueidentity,
74
+ '2022-02-09-111800-fix-crypted': _20220209111800fixcrypted,
75
+ '2022-02-11-153000-idp-auto-sign-up': _20220211153000idpautosignup,
76
+ '2022-06-29-105000-person-idp': _20220629105000personidp,
77
+ '2022-07-07-135000-person-email-opt-uniq': _20220707135000personemailoptuniq,
78
+ '2022-07-07-141000-person-display-name': _20220707141000persondisplayname,
79
+ '2022-07-14-145000-person-login-options': _20220714145000personloginoptions,
80
+ '2022-11-08-project-update-notification': _20221108projectupdatenotification,
20
81
  }
21
82
 
22
83
  export class TenantMigrationsRunner {
@@ -24,7 +85,7 @@ export class TenantMigrationsRunner {
24
85
  private readonly db: DatabaseConfig,
25
86
  private readonly schema: string,
26
87
  private readonly tenantCredentials: TenantCredentials,
27
- private readonly providers: Providers,
88
+ private readonly providers: Pick<Providers, 'bcrypt' | 'uuid'>,
28
89
  ) {
29
90
  }
30
91
 
@@ -32,7 +93,9 @@ export class TenantMigrationsRunner {
32
93
  await createDatabaseIfNotExists(this.db, message => typeof message === 'string' ? logger.warn(message) : logger.error(message))
33
94
  const connection = Connection.createSingle(this.db, err => logger.error(err))
34
95
  const result = await connection.scope(async connection => {
35
- const innerRunner = new DbMigrationsRunner<TenantMigrationArgs>(connection, this.schema, getMigrations)
96
+ const migrationsResolver = new SnapshotMigrationResolver(snapshot, migrations)
97
+
98
+ const innerRunner = new DbMigrationsRunner<TenantMigrationArgs>(connection, this.schema, migrationsResolver)
36
99
  return await innerRunner.migrate(message => logger.warn(message), {
37
100
  getCredentials: async () => ({
38
101
  loginTokenHash: this.tenantCredentials.loginToken ? computeTokenHash(this.tenantCredentials.loginToken) : undefined,
@@ -41,6 +104,7 @@ export class TenantMigrationsRunner {
41
104
  rootEmail: this.tenantCredentials.rootEmail,
42
105
  rootPasswordBcrypted: this.tenantCredentials.rootPassword ? await this.providers.bcrypt(this.tenantCredentials.rootPassword) : undefined,
43
106
  }),
107
+ providers: this.providers,
44
108
  })
45
109
  })
46
110
  await connection.end()
@@ -0,0 +1,21 @@
1
+ import { MigrationArgs, MigrationBuilder } from '@contember/database-migrations'
2
+ import { TenantMigrationArgs } from './types'
3
+ import { createCredentials } from './tenantCredentials'
4
+
5
+ export default async (sqlFactory: () => string) => {
6
+ return async (builder: MigrationBuilder, args: MigrationArgs<TenantMigrationArgs>) => {
7
+
8
+ const sql = sqlFactory()
9
+ builder.sql(sql)
10
+
11
+ builder.sql(`DO LANGUAGE plpgsql
12
+ $$
13
+ BEGIN
14
+ EXECUTE FORMAT('ALTER FUNCTION project_secret_updated() SET SEARCH_PATH = %s', QUOTE_IDENT(CURRENT_SCHEMA()));
15
+ END
16
+ $$;
17
+ `)
18
+
19
+ await createCredentials(builder, args)
20
+ }
21
+ }
@@ -0,0 +1,10 @@
1
+ DO LANGUAGE plpgsql
2
+ $$
3
+ BEGIN
4
+ EXECUTE FORMAT('ALTER FUNCTION project_secret_updated() SET SEARCH_PATH = %s', QUOTE_IDENT(CURRENT_SCHEMA()));
5
+ END
6
+ $$;
7
+ `)
8
+
9
+ await createCredentials(builder, args)
10
+ }
@@ -0,0 +1,6 @@
1
+ import { MigrationBuilder } from '@contember/database-migrations'
2
+ import { TenantMigrationArgs } from './types'
3
+ import { createCredentials } from './tenantCredentials'
4
+
5
+ export default async function (builder: MigrationBuilder, args: TenantMigrationArgs) {
6
+ builder.sql(`
@@ -0,0 +1,202 @@
1
+ import { MigrationBuilder } from '@contember/database-migrations'
2
+ import { TenantMigrationArgs } from './types'
3
+ import { createCredentials } from './tenantCredentials'
4
+
5
+ export default async function (builder: MigrationBuilder, args: TenantMigrationArgs) {
6
+ builder.sql(`
7
+ CREATE FUNCTION "project_deleted"() RETURNS "trigger"
8
+ LANGUAGE "plpgsql"
9
+ AS $$
10
+ BEGIN
11
+ PERFORM pg_notify('project_updated', old.id::text);
12
+ RETURN NULL;
13
+ END;
14
+ $$;
15
+ CREATE FUNCTION "project_secret_updated"() RETURNS "trigger"
16
+ LANGUAGE "plpgsql"
17
+ AS $$
18
+ BEGIN
19
+ UPDATE project SET updated_at = 'now' WHERE id = COALESCE(new.project_id, old.project_id);
20
+ PERFORM pg_notify('project_updated', COALESCE(new.project_id, old.project_id)::TEXT);
21
+ RETURN NULL;
22
+ END;
23
+ $$;
24
+ CREATE FUNCTION "project_updated"() RETURNS "trigger"
25
+ LANGUAGE "plpgsql"
26
+ AS $$
27
+ BEGIN
28
+ NEW.updated_at = 'now';
29
+ PERFORM pg_notify('project_updated', new.id::text);
30
+ RETURN new;
31
+ END;
32
+ $$;
33
+ CREATE TABLE "api_key" (
34
+ "id" "uuid" NOT NULL,
35
+ "token_hash" "text" NOT NULL,
36
+ "type" "text" NOT NULL,
37
+ "identity_id" "uuid" NOT NULL,
38
+ "expires_at" timestamp with time zone,
39
+ "created_at" timestamp with time zone NOT NULL,
40
+ "expiration" integer,
41
+ "disabled_at" timestamp with time zone
42
+ );
43
+ CREATE TABLE "identity" (
44
+ "id" "uuid" NOT NULL,
45
+ "parent_id" "uuid",
46
+ "roles" "jsonb" NOT NULL,
47
+ "description" "text",
48
+ "created_at" timestamp with time zone NOT NULL
49
+ );
50
+ CREATE TABLE "identity_provider" (
51
+ "id" "uuid" NOT NULL,
52
+ "slug" "text" NOT NULL,
53
+ "type" "text" NOT NULL,
54
+ "configuration" "jsonb" NOT NULL,
55
+ "disabled_at" timestamp with time zone,
56
+ "auto_sign_up" boolean DEFAULT false NOT NULL,
57
+ "exclusive" boolean DEFAULT false
58
+ );
59
+ CREATE TABLE "mail_template" (
60
+ "id" "uuid" NOT NULL,
61
+ "project_id" "uuid",
62
+ "mail_type" "text" NOT NULL,
63
+ "variant" "text" NOT NULL,
64
+ "subject" "text" NOT NULL,
65
+ "content" "text" NOT NULL,
66
+ "use_layout" boolean NOT NULL
67
+ );
68
+ CREATE TABLE "person" (
69
+ "id" "uuid" NOT NULL,
70
+ "email" "text",
71
+ "password_hash" "text",
72
+ "identity_id" "uuid" NOT NULL,
73
+ "otp_uri" "text",
74
+ "otp_activated_at" timestamp with time zone,
75
+ "name" "text",
76
+ "idp_only" boolean DEFAULT false NOT NULL,
77
+ CONSTRAINT "idp_only_no_email" CHECK ((("idp_only" = false) OR (("idp_only" = true) AND ("email" IS NULL))))
78
+ );
79
+ CREATE TABLE "person_identity_provider" (
80
+ "id" "uuid" NOT NULL,
81
+ "person_id" "uuid" NOT NULL,
82
+ "identity_provider_id" "uuid" NOT NULL,
83
+ "created_at" timestamp with time zone DEFAULT "now"() NOT NULL,
84
+ "external_identifier" "text" NOT NULL
85
+ );
86
+ CREATE TABLE "person_password_reset" (
87
+ "id" "uuid" NOT NULL,
88
+ "token_hash" "text" NOT NULL,
89
+ "person_id" "uuid" NOT NULL,
90
+ "expires_at" timestamp with time zone NOT NULL,
91
+ "created_at" timestamp with time zone NOT NULL,
92
+ "used_at" timestamp with time zone
93
+ );
94
+ CREATE TABLE "project" (
95
+ "id" "uuid" NOT NULL,
96
+ "name" "text" NOT NULL,
97
+ "slug" "text" NOT NULL,
98
+ "config" "jsonb" DEFAULT '{}'::"jsonb" NOT NULL,
99
+ "updated_at" timestamp with time zone DEFAULT "now"() NOT NULL
100
+ );
101
+ CREATE TABLE "project_membership" (
102
+ "id" "uuid" NOT NULL,
103
+ "project_id" "uuid" NOT NULL,
104
+ "identity_id" "uuid" NOT NULL,
105
+ "role" "text" NOT NULL
106
+ );
107
+ CREATE TABLE "project_membership_variable" (
108
+ "id" "uuid" NOT NULL,
109
+ "membership_id" "uuid" NOT NULL,
110
+ "variable" "text" NOT NULL,
111
+ "value" "jsonb" NOT NULL
112
+ );
113
+ CREATE TABLE "project_secret" (
114
+ "id" "uuid" NOT NULL,
115
+ "project_id" "uuid" NOT NULL,
116
+ "key" "text" NOT NULL,
117
+ "created_at" timestamp with time zone NOT NULL,
118
+ "updated_at" timestamp with time zone NOT NULL,
119
+ "value" "bytea" NOT NULL,
120
+ "version" smallint NOT NULL
121
+ );
122
+ ALTER TABLE ONLY "api_key"
123
+ ADD CONSTRAINT "api_key_id" PRIMARY KEY ("id");
124
+ ALTER TABLE ONLY "person"
125
+ ADD CONSTRAINT "email_unique" UNIQUE ("email");
126
+ ALTER TABLE ONLY "identity"
127
+ ADD CONSTRAINT "identity_id" PRIMARY KEY ("id");
128
+ ALTER TABLE ONLY "identity_provider"
129
+ ADD CONSTRAINT "identity_provider_id" PRIMARY KEY ("id");
130
+ ALTER TABLE ONLY "identity_provider"
131
+ ADD CONSTRAINT "identity_provider_slug_key" UNIQUE ("slug");
132
+ ALTER TABLE ONLY "mail_template"
133
+ ADD CONSTRAINT "mail_template_pkey" PRIMARY KEY ("id");
134
+ ALTER TABLE ONLY "person"
135
+ ADD CONSTRAINT "person_id" PRIMARY KEY ("id");
136
+ ALTER TABLE ONLY "person"
137
+ ADD CONSTRAINT "person_identity_id_key" UNIQUE ("identity_id");
138
+ ALTER TABLE ONLY "person_identity_provider"
139
+ ADD CONSTRAINT "person_identity_provider_pkey" PRIMARY KEY ("id");
140
+ ALTER TABLE ONLY "person_password_reset"
141
+ ADD CONSTRAINT "person_password_reset_id" PRIMARY KEY ("id");
142
+ ALTER TABLE ONLY "project"
143
+ ADD CONSTRAINT "project_id" PRIMARY KEY ("id");
144
+ ALTER TABLE ONLY "project_membership"
145
+ ADD CONSTRAINT "project_membership_pkey" PRIMARY KEY ("id");
146
+ ALTER TABLE ONLY "project_membership_variable"
147
+ ADD CONSTRAINT "project_membership_variable_pkey" PRIMARY KEY ("id");
148
+ ALTER TABLE ONLY "project_membership_variable"
149
+ ADD CONSTRAINT "project_membership_variable_unique" UNIQUE ("membership_id", "variable");
150
+ ALTER TABLE ONLY "project_secret"
151
+ ADD CONSTRAINT "project_secret_pkey" PRIMARY KEY ("id");
152
+ CREATE INDEX "api_key_identity_id" ON "api_key" USING "btree" ("identity_id");
153
+ CREATE UNIQUE INDEX "api_key_token_hash" ON "api_key" USING "btree" ("token_hash");
154
+ CREATE INDEX "identity_parent_id" ON "identity" USING "btree" ("parent_id");
155
+ CREATE UNIQUE INDEX "mail_template_identifier" ON "mail_template" USING "btree" ("project_id", "mail_type", "variant") WHERE ("project_id" IS NOT NULL);
156
+ CREATE UNIQUE INDEX "mail_template_identifier_global" ON "mail_template" USING "btree" ("mail_type", "variant") WHERE ("project_id" IS NULL);
157
+ CREATE INDEX "mail_template_project_index" ON "mail_template" USING "btree" ("project_id");
158
+ CREATE INDEX "person_identity_id" ON "person" USING "btree" ("identity_id");
159
+ CREATE UNIQUE INDEX "person_identity_provider_identifier" ON "person_identity_provider" USING "btree" ("identity_provider_id", "external_identifier");
160
+ CREATE INDEX "person_identity_provider_person_id" ON "person_identity_provider" USING "btree" ("person_id");
161
+ CREATE UNIQUE INDEX "person_password_reset_token" ON "person_password_reset" USING "btree" ("token_hash");
162
+ CREATE INDEX "project_alias" ON "project" USING "gin" ((("config" -> 'alias'::"text")));
163
+ CREATE INDEX "project_membership_identity_index" ON "project_membership" USING "btree" ("identity_id");
164
+ CREATE UNIQUE INDEX "project_membership_unique" ON "project_membership" USING "btree" ("project_id", "identity_id", "role");
165
+ CREATE INDEX "project_secret_project_index" ON "project_secret" USING "btree" ("project_id");
166
+ CREATE UNIQUE INDEX "project_secret_unique" ON "project_secret" USING "btree" ("project_id", "key");
167
+ CREATE UNIQUE INDEX "project_slug" ON "project" USING "btree" ("slug");
168
+ CREATE TRIGGER "project_deleted" AFTER DELETE ON "project" FOR EACH ROW EXECUTE FUNCTION "project_deleted"();
169
+ CREATE TRIGGER "project_secret_updated" AFTER INSERT OR DELETE OR UPDATE ON "project_secret" FOR EACH ROW EXECUTE FUNCTION "project_secret_updated"();
170
+ CREATE TRIGGER "project_updated" BEFORE INSERT OR UPDATE OF "name", "slug", "config" ON "project" FOR EACH ROW EXECUTE FUNCTION "project_updated"();
171
+ ALTER TABLE ONLY "api_key"
172
+ ADD CONSTRAINT "api_key_identity_id_fkey" FOREIGN KEY ("identity_id") REFERENCES "identity"("id");
173
+ ALTER TABLE ONLY "identity"
174
+ ADD CONSTRAINT "identity_parent_id_fkey" FOREIGN KEY ("parent_id") REFERENCES "identity"("id");
175
+ ALTER TABLE ONLY "mail_template"
176
+ ADD CONSTRAINT "mail_template_project" FOREIGN KEY ("project_id") REFERENCES "project"("id") ON DELETE CASCADE;
177
+ ALTER TABLE ONLY "person"
178
+ ADD CONSTRAINT "person_identity_id_fkey" FOREIGN KEY ("identity_id") REFERENCES "identity"("id");
179
+ ALTER TABLE ONLY "person_identity_provider"
180
+ ADD CONSTRAINT "person_identity_provider_idp" FOREIGN KEY ("identity_provider_id") REFERENCES "identity_provider"("id") ON DELETE CASCADE;
181
+ ALTER TABLE ONLY "person_identity_provider"
182
+ ADD CONSTRAINT "person_identity_provider_person" FOREIGN KEY ("person_id") REFERENCES "person"("id") ON DELETE CASCADE;
183
+ ALTER TABLE ONLY "person_password_reset"
184
+ ADD CONSTRAINT "person_password_reset_person" FOREIGN KEY ("person_id") REFERENCES "person"("id") ON DELETE CASCADE;
185
+ ALTER TABLE ONLY "project_membership"
186
+ ADD CONSTRAINT "project_membership_identity" FOREIGN KEY ("identity_id") REFERENCES "identity"("id") ON DELETE CASCADE;
187
+ ALTER TABLE ONLY "project_membership"
188
+ ADD CONSTRAINT "project_membership_project" FOREIGN KEY ("project_id") REFERENCES "project"("id") ON DELETE CASCADE;
189
+ ALTER TABLE ONLY "project_membership_variable"
190
+ ADD CONSTRAINT "project_membership_variable_membership" FOREIGN KEY ("membership_id") REFERENCES "project_membership"("id") ON DELETE CASCADE;
191
+ ALTER TABLE ONLY "project_secret"
192
+ ADD CONSTRAINT "project_secret_project" FOREIGN KEY ("project_id") REFERENCES "project"("id") ON DELETE CASCADE;
193
+ DO LANGUAGE plpgsql
194
+ $$
195
+ BEGIN
196
+ EXECUTE FORMAT('ALTER FUNCTION project_secret_updated() SET SEARCH_PATH = %s', QUOTE_IDENT(CURRENT_SCHEMA()));
197
+ END
198
+ $$;
199
+ `)
200
+
201
+ await createCredentials(builder, args)
202
+ }
@@ -0,0 +1,58 @@
1
+ import { escapeValue, MigrationBuilder } from '@contember/database-migrations'
2
+ import { TenantMigrationArgs } from './types'
3
+
4
+ export const createCredentials = async (builder: MigrationBuilder, args: TenantMigrationArgs) => {
5
+ const credentials = await args.getCredentials()
6
+ if (credentials.loginTokenHash) {
7
+ const tokenHash = credentials.loginTokenHash
8
+ builder.sql(`
9
+ WITH identity AS (
10
+ INSERT INTO identity(id, parent_id, roles, description, created_at)
11
+ VALUES (${escapeValue(args.providers.uuid())}, NULL, '["login"]'::JSONB, 'Login key', now()) RETURNING id
12
+ )
13
+ INSERT INTO api_key (id, token_hash, type, identity_id, disabled_at, expires_at, expiration, created_at)
14
+ SELECT ${escapeValue(args.providers.uuid())}, ${escapeValue(tokenHash)}, 'permanent', identity.id, NULL, NULL, NULL, now()
15
+ FROM identity
16
+ `)
17
+ }
18
+
19
+ if (!credentials.rootTokenHash) {
20
+ throw 'Please specify a root token using CONTEMBER_ROOT_TOKEN env variable.'
21
+ }
22
+
23
+ if (credentials.rootEmail && !credentials.rootPasswordBcrypted) {
24
+ throw 'Please specify a root password using CONTEMBER_ROOT_PASSWORD env variable.'
25
+ }
26
+ const rootEmail = credentials.rootPasswordBcrypted ? credentials.rootEmail || 'root@localhost' : null
27
+ const rootPasswordHash = credentials.rootPasswordBcrypted || null
28
+
29
+ const rootTokenHash = credentials.rootTokenHash
30
+
31
+ builder.sql(`
32
+ WITH identity AS (
33
+ INSERT INTO identity(id, parent_id, roles, description, created_at)
34
+ VALUES (
35
+ ${escapeValue(args.providers.uuid())},
36
+ NULL,
37
+ '["super_admin"]'::JSONB
38
+ || (CASE WHEN ${escapeValue(rootEmail)} IS NOT NULL THEN '["person"]'::JSONB ELSE '[]'::JSONB END),
39
+ 'Superadmin',
40
+ now()
41
+ ) RETURNING id
42
+ ),
43
+ person AS (
44
+ INSERT INTO person(id, email, password_hash, identity_id)
45
+ SELECT ${escapeValue(args.providers.uuid())}, ${escapeValue(rootEmail)}, ${escapeValue(rootPasswordHash)}, identity.id
46
+ FROM identity
47
+ WHERE ${escapeValue(rootEmail)} IS NOT NULL
48
+ RETURNING id
49
+ ),
50
+ api_key AS (
51
+ INSERT INTO api_key (id, token_hash, type, identity_id, disabled_at, expires_at, expiration, created_at)
52
+ SELECT ${escapeValue(args.providers.uuid())}, ${escapeValue(rootTokenHash)}, 'permanent', identity.id, NULL, NULL, NULL, now()
53
+ FROM identity WHERE ${escapeValue(rootTokenHash)} IS NOT NULL
54
+ RETURNING id
55
+ )
56
+ SELECT * FROM person, api_key
57
+ `)
58
+ }
@@ -1,3 +1,5 @@
1
+ import { Providers } from '../model'
2
+
1
3
  export interface TenantMigrationArgs {
2
4
  getCredentials: () => Promise<{
3
5
  loginTokenHash?: string
@@ -5,4 +7,5 @@ export interface TenantMigrationArgs {
5
7
  rootTokenHash?: string
6
8
  rootPasswordBcrypted?: string
7
9
  }>
10
+ providers: Pick<Providers, 'uuid'>
8
11
  }
@@ -28,4 +28,5 @@ export class UpdateIdpCommand implements Command<void> {
28
28
  export type UpdateIdpData = {
29
29
  options?: Partial<IdentityProviderData['options']>
30
30
  configuration?: IdentityProviderData['configuration']
31
+ type?: string
31
32
  }
@@ -1,10 +1,12 @@
1
- import { ConditionBuilder, DatabaseQuery, DatabaseQueryable, SelectBuilder } from '@contember/database'
2
- import { MemberType } from '../../../schema'
1
+ import { DatabaseQuery, DatabaseQueryable, SelectBuilder } from '@contember/database'
2
+ import { MemberType, ProjectMembersInput } from '../../../schema'
3
+ import { ImplementationException } from '../../../exceptions'
3
4
 
4
5
  export class ProjectMembersQuery extends DatabaseQuery<ProjectMembersQueryResult> {
6
+
5
7
  constructor(
6
8
  private readonly projectId: string,
7
- private readonly memberType?: MemberType,
9
+ private readonly projectMemberInput: ProjectMembersInput,
8
10
  ) {
9
11
  super()
10
12
  }
@@ -17,22 +19,29 @@ export class ProjectMembersQuery extends DatabaseQuery<ProjectMembersQueryResult
17
19
  .where(it => it.exists(
18
20
  builder => builder
19
21
  .from('project_membership')
20
- .where(expr => expr.columnsEq(['project_membership', 'identity_id'], ['identity', 'id'])),
22
+ .where(expr => expr.columnsEq(['project_membership', 'identity_id'], ['identity', 'id']))
23
+ .where({ project_id: this.projectId }),
21
24
  ))
22
25
  .match(qb => {
23
- if (!this.memberType) {
24
- return qb
26
+ const { email, memberType } = this.projectMemberInput.filter ?? {}
27
+ if (email && memberType === MemberType.ApiKey) {
28
+ throw new ImplementationException()
29
+ }
30
+ const personQuery = SelectBuilder.create()
31
+ .from('person')
32
+ .where(expr => expr.columnsEq(['person', 'identity_id'], ['identity', 'id']))
33
+ if (email) {
34
+ return qb.where(it => it.exists(personQuery.where({ email })))
25
35
  }
26
- const expr = ConditionBuilder.create().exists(
27
- builder => builder
28
- .from('person')
29
- .where(expr => expr.columnsEq(['person', 'identity_id'], ['identity', 'id'])),
30
- )
31
- if (this.memberType === MemberType.Person) {
32
- return qb.where(expr)
36
+ switch (memberType) {
37
+ case MemberType.ApiKey:
38
+ return qb.where(it => it.not(it => it.exists(personQuery)))
39
+ case MemberType.Person:
40
+ return qb.where(it => it.exists(personQuery))
33
41
  }
34
- return qb.where(ConditionBuilder.not(expr))
42
+ return qb
35
43
  })
44
+ .limit(this.projectMemberInput.limit ?? undefined, this.projectMemberInput.offset ?? undefined)
36
45
  .getResult(db)
37
46
  }
38
47
  }
@@ -1,6 +1,6 @@
1
1
  import { ApiKeyManager } from './apiKey'
2
2
  import { IdentityProviderBySlugQuery, PersonByIdPQuery, PersonQuery, PersonRow } from '../queries'
3
- import { IDPClaim, IDPHandlerRegistry, IDPResponse, IDPResponseError, IDPValidationError } from './idp'
3
+ import { IDPClaim, IDPHandlerRegistry, IDPResponseError, IDPValidationError } from './idp'
4
4
  import { Response, ResponseError, ResponseOk } from '../utils/Response'
5
5
  import { InitSignInIdpErrorCode, SignInIdpErrorCode } from '../../schema'
6
6
  import { DatabaseContext } from '../utils'
@@ -18,9 +18,7 @@ class IDPSignInManager {
18
18
  async signInIDP(
19
19
  dbContext: DatabaseContext,
20
20
  idpSlug: string,
21
- redirectUrl: string,
22
- idpResponse: IDPResponse,
23
- sessionData: any,
21
+ responseData: unknown,
24
22
  expiration?: number,
25
23
  ): Promise<IDPSignInManager.SignInIDPResponse> {
26
24
  return dbContext.transaction(async db => {
@@ -34,9 +32,7 @@ class IDPSignInManager {
34
32
  try {
35
33
  claim = await providerService.processResponse(
36
34
  validatedConfig,
37
- redirectUrl,
38
- idpResponse,
39
- sessionData,
35
+ responseData,
40
36
  )
41
37
  } catch (e) {
42
38
  if (e instanceof IDPResponseError) {
@@ -57,15 +53,22 @@ class IDPSignInManager {
57
53
  })
58
54
  }
59
55
 
60
- async initSignInIDP(dbContext: DatabaseContext, idpSlug: string, redirectUrl: string): Promise<IDPSignInManager.InitSignInIDPResponse> {
56
+ async initSignInIDP(dbContext: DatabaseContext, idpSlug: string, data: unknown): Promise<IDPSignInManager.InitSignInIDPResponse> {
61
57
  const provider = await dbContext.queryHandler.fetch(new IdentityProviderBySlugQuery(idpSlug))
62
58
  if (!provider || provider.disabledAt) {
63
59
  return new ResponseError(InitSignInIdpErrorCode.ProviderNotFound, `Identity provider ${idpSlug} not found`)
64
60
  }
65
61
  const providerService = this.idpRegistry.getHandler(provider.type)
66
62
  const validatedConfig = providerService.validateConfiguration(provider.configuration)
67
- const initResponse = await providerService.initAuth(validatedConfig, redirectUrl)
68
- return new ResponseOk(initResponse)
63
+ try {
64
+ const initResponse = await providerService.initAuth(validatedConfig, data)
65
+ return new ResponseOk(initResponse)
66
+ } catch (e) {
67
+ if (e instanceof IDPValidationError) {
68
+ return new ResponseError(InitSignInIdpErrorCode.IdpValidationFailed, e.message)
69
+ }
70
+ throw e
71
+ }
69
72
  }
70
73
 
71
74
  private async resolvePerson(db: DatabaseContext, claim: IDPClaim, provider: IdentityProviderRow): Promise<PersonRow | null> {
@@ -8,7 +8,7 @@ import {
8
8
  UpdateProjectMemberResponse,
9
9
  } from '../commands'
10
10
  import { ProjectMembershipByIdentityQuery, ProjectMembersQuery } from '../queries'
11
- import { AddProjectMemberErrorCode, MemberType } from '../../schema'
11
+ import { AddProjectMemberErrorCode, MemberType, ProjectMembersInput } from '../../schema'
12
12
  import { AccessVerifier, PermissionActions, TenantRole } from '../authorization'
13
13
  import { indexListBy, notEmpty } from '../../utils/array'
14
14
  import { createSetMembershipVariables } from './membershipUtils'
@@ -105,9 +105,9 @@ export class ProjectMemberManager {
105
105
  }
106
106
 
107
107
 
108
- async getProjectMembers(dbContext: DatabaseContext, projectId: string, accessVerifier: AccessVerifier, memberType?: MemberType): Promise<GetProjectMembersResponse> {
108
+ async getProjectMembers(dbContext: DatabaseContext, projectId: string, accessVerifier: AccessVerifier, input: ProjectMembersInput): Promise<GetProjectMembersResponse> {
109
109
  return dbContext.transaction(async db => {
110
- const members = await db.queryHandler.fetch(new ProjectMembersQuery(projectId, memberType))
110
+ const members = await db.queryHandler.fetch(new ProjectMembersQuery(projectId, input))
111
111
  const memberships = await db.queryHandler.fetch(
112
112
  new ProjectMembershipByIdentityQuery(
113
113
  { id: projectId },
@@ -2,13 +2,13 @@ import { IdentityProviderHandler } from './IdentityProviderHandler'
2
2
  import { IdentityProviderNotFoundError } from './IdentityProviderNotFoundError'
3
3
 
4
4
  export class IDPHandlerRegistry {
5
- private providers: Record<string, IdentityProviderHandler<any, any>> = {}
5
+ private providers: Record<string, IdentityProviderHandler<any>> = {}
6
6
 
7
- public registerHandler(type: string, provider: IdentityProviderHandler<any, any>): void {
7
+ public registerHandler(type: string, provider: IdentityProviderHandler<any>): void {
8
8
  this.providers[type] = provider
9
9
  }
10
10
 
11
- public getHandler(type: string): IdentityProviderHandler<any, any> {
11
+ public getHandler(type: string): IdentityProviderHandler<{}> {
12
12
  const provider = this.providers[type]
13
13
  if (!provider) {
14
14
  throw new IdentityProviderNotFoundError(`Identity provider handler ${type} not found`)