@techelusive/nest-auth 0.0.0-stage → 0.2.0

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 (340) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/LICENSE +21 -0
  3. package/README.md +204 -2
  4. package/api/openapi.json +4399 -0
  5. package/api/techelusive-authentication.postman_collection.json +3178 -0
  6. package/dist/auth-options.d.ts +156 -0
  7. package/dist/auth-options.js +3 -0
  8. package/dist/auth-options.js.map +1 -0
  9. package/dist/auth-options.validation.d.ts +9 -0
  10. package/dist/auth-options.validation.js +74 -0
  11. package/dist/auth-options.validation.js.map +1 -0
  12. package/dist/auth.module.d.ts +38 -0
  13. package/dist/auth.module.js +173 -0
  14. package/dist/auth.module.js.map +1 -0
  15. package/dist/common/auth-error.d.ts +16 -0
  16. package/dist/common/auth-error.js +23 -0
  17. package/dist/common/auth-error.js.map +1 -0
  18. package/dist/common/auth-exception.filter.d.ts +24 -0
  19. package/dist/common/auth-exception.filter.js +66 -0
  20. package/dist/common/auth-exception.filter.js.map +1 -0
  21. package/dist/common/crypto/jwt.d.ts +89 -0
  22. package/dist/common/crypto/jwt.js +144 -0
  23. package/dist/common/crypto/jwt.js.map +1 -0
  24. package/dist/common/crypto/random-secrets.d.ts +78 -0
  25. package/dist/common/crypto/random-secrets.js +113 -0
  26. package/dist/common/crypto/random-secrets.js.map +1 -0
  27. package/dist/common/crypto/remote-public-keys.d.ts +49 -0
  28. package/dist/common/crypto/remote-public-keys.js +105 -0
  29. package/dist/common/crypto/remote-public-keys.js.map +1 -0
  30. package/dist/common/crypto/totp.d.ts +68 -0
  31. package/dist/common/crypto/totp.js +148 -0
  32. package/dist/common/crypto/totp.js.map +1 -0
  33. package/dist/common/encryption.service.d.ts +36 -0
  34. package/dist/common/encryption.service.js +111 -0
  35. package/dist/common/encryption.service.js.map +1 -0
  36. package/dist/common/identifiers.d.ts +48 -0
  37. package/dist/common/identifiers.js +89 -0
  38. package/dist/common/identifiers.js.map +1 -0
  39. package/dist/common/network-safety.d.ts +19 -0
  40. package/dist/common/network-safety.js +72 -0
  41. package/dist/common/network-safety.js.map +1 -0
  42. package/dist/common/rate-limiter.service.d.ts +63 -0
  43. package/dist/common/rate-limiter.service.js +158 -0
  44. package/dist/common/rate-limiter.service.js.map +1 -0
  45. package/dist/common/refresh-token-cookie.d.ts +78 -0
  46. package/dist/common/refresh-token-cookie.js +185 -0
  47. package/dist/common/refresh-token-cookie.js.map +1 -0
  48. package/dist/common/request-context.d.ts +14 -0
  49. package/dist/common/request-context.js +22 -0
  50. package/dist/common/request-context.js.map +1 -0
  51. package/dist/common/strict-validation.pipe.d.ts +8 -0
  52. package/dist/common/strict-validation.pipe.js +16 -0
  53. package/dist/common/strict-validation.pipe.js.map +1 -0
  54. package/dist/common/time.d.ts +15 -0
  55. package/dist/common/time.js +34 -0
  56. package/dist/common/time.js.map +1 -0
  57. package/dist/constants.d.ts +1326 -0
  58. package/dist/constants.js +1142 -0
  59. package/dist/constants.js.map +1 -0
  60. package/dist/database/create-auth-tables.migration.d.ts +26 -0
  61. package/dist/database/create-auth-tables.migration.js +291 -0
  62. package/dist/database/create-auth-tables.migration.js.map +1 -0
  63. package/dist/database/email-change-and-retention.migration.d.ts +25 -0
  64. package/dist/database/email-change-and-retention.migration.js +54 -0
  65. package/dist/database/email-change-and-retention.migration.js.map +1 -0
  66. package/dist/database/entities/api-key.entity.d.ts +17 -0
  67. package/dist/database/entities/api-key.entity.js +80 -0
  68. package/dist/database/entities/api-key.entity.js.map +1 -0
  69. package/dist/database/entities/audit-log.entity.d.ts +13 -0
  70. package/dist/database/entities/audit-log.entity.js +64 -0
  71. package/dist/database/entities/audit-log.entity.js.map +1 -0
  72. package/dist/database/entities/backup-code.entity.d.ts +9 -0
  73. package/dist/database/entities/backup-code.entity.js +52 -0
  74. package/dist/database/entities/backup-code.entity.js.map +1 -0
  75. package/dist/database/entities/index.d.ts +43 -0
  76. package/dist/database/entities/index.js +82 -0
  77. package/dist/database/entities/index.js.map +1 -0
  78. package/dist/database/entities/json-object.d.ts +12 -0
  79. package/dist/database/entities/json-object.js +3 -0
  80. package/dist/database/entities/json-object.js.map +1 -0
  81. package/dist/database/entities/link-token.entity.d.ts +15 -0
  82. package/dist/database/entities/link-token.entity.js +64 -0
  83. package/dist/database/entities/link-token.entity.js.map +1 -0
  84. package/dist/database/entities/one-time-code.entity.d.ts +16 -0
  85. package/dist/database/entities/one-time-code.entity.js +69 -0
  86. package/dist/database/entities/one-time-code.entity.js.map +1 -0
  87. package/dist/database/entities/organization-invitation.entity.d.ts +14 -0
  88. package/dist/database/entities/organization-invitation.entity.js +73 -0
  89. package/dist/database/entities/organization-invitation.entity.js.map +1 -0
  90. package/dist/database/entities/organization-member.entity.d.ts +9 -0
  91. package/dist/database/entities/organization-member.entity.js +48 -0
  92. package/dist/database/entities/organization-member.entity.js.map +1 -0
  93. package/dist/database/entities/organization.entity.d.ts +12 -0
  94. package/dist/database/entities/organization.entity.js +58 -0
  95. package/dist/database/entities/organization.entity.js.map +1 -0
  96. package/dist/database/entities/passkey.entity.d.ts +19 -0
  97. package/dist/database/entities/passkey.entity.js +78 -0
  98. package/dist/database/entities/passkey.entity.js.map +1 -0
  99. package/dist/database/entities/password.entity.d.ts +6 -0
  100. package/dist/database/entities/password.entity.js +36 -0
  101. package/dist/database/entities/password.entity.js.map +1 -0
  102. package/dist/database/entities/refresh-token.entity.d.ts +9 -0
  103. package/dist/database/entities/refresh-token.entity.js +53 -0
  104. package/dist/database/entities/refresh-token.entity.js.map +1 -0
  105. package/dist/database/entities/session.entity.d.ts +20 -0
  106. package/dist/database/entities/session.entity.js +87 -0
  107. package/dist/database/entities/session.entity.js.map +1 -0
  108. package/dist/database/entities/settings.entity.d.ts +7 -0
  109. package/dist/database/entities/settings.entity.js +41 -0
  110. package/dist/database/entities/settings.entity.js.map +1 -0
  111. package/dist/database/entities/sign-in-challenge.entity.d.ts +23 -0
  112. package/dist/database/entities/sign-in-challenge.entity.js +80 -0
  113. package/dist/database/entities/sign-in-challenge.entity.js.map +1 -0
  114. package/dist/database/entities/signing-key.entity.d.ts +11 -0
  115. package/dist/database/entities/signing-key.entity.js +54 -0
  116. package/dist/database/entities/signing-key.entity.js.map +1 -0
  117. package/dist/database/entities/social-account.entity.d.ts +13 -0
  118. package/dist/database/entities/social-account.entity.js +54 -0
  119. package/dist/database/entities/social-account.entity.js.map +1 -0
  120. package/dist/database/entities/two-factor-secret.entity.d.ts +10 -0
  121. package/dist/database/entities/two-factor-secret.entity.js +48 -0
  122. package/dist/database/entities/two-factor-secret.entity.js.map +1 -0
  123. package/dist/database/entities/user.entity.d.ts +34 -0
  124. package/dist/database/entities/user.entity.js +129 -0
  125. package/dist/database/entities/user.entity.js.map +1 -0
  126. package/dist/database/entities/webhook-delivery.entity.d.ts +17 -0
  127. package/dist/database/entities/webhook-delivery.entity.js +79 -0
  128. package/dist/database/entities/webhook-delivery.entity.js.map +1 -0
  129. package/dist/database/entities/webhook.entity.d.ts +12 -0
  130. package/dist/database/entities/webhook.entity.js +58 -0
  131. package/dist/database/entities/webhook.entity.js.map +1 -0
  132. package/dist/database/typeorm-row.d.ts +21 -0
  133. package/dist/database/typeorm-row.js +29 -0
  134. package/dist/database/typeorm-row.js.map +1 -0
  135. package/dist/features/account/account.controller.d.ts +259 -0
  136. package/dist/features/account/account.controller.js +372 -0
  137. package/dist/features/account/account.controller.js.map +1 -0
  138. package/dist/features/account/account.dto.d.ts +16 -0
  139. package/dist/features/account/account.dto.js +61 -0
  140. package/dist/features/account/account.dto.js.map +1 -0
  141. package/dist/features/account/data-export.service.d.ts +85 -0
  142. package/dist/features/account/data-export.service.js +125 -0
  143. package/dist/features/account/data-export.service.js.map +1 -0
  144. package/dist/features/account/health.service.d.ts +30 -0
  145. package/dist/features/account/health.service.js +59 -0
  146. package/dist/features/account/health.service.js.map +1 -0
  147. package/dist/features/admin/admin.controller.d.ts +382 -0
  148. package/dist/features/admin/admin.controller.js +623 -0
  149. package/dist/features/admin/admin.controller.js.map +1 -0
  150. package/dist/features/admin/admin.dto.d.ts +61 -0
  151. package/dist/features/admin/admin.dto.js +253 -0
  152. package/dist/features/admin/admin.dto.js.map +1 -0
  153. package/dist/features/admin/admin.service.d.ts +142 -0
  154. package/dist/features/admin/admin.service.js +227 -0
  155. package/dist/features/admin/admin.service.js.map +1 -0
  156. package/dist/features/api-keys/api-keys.service.d.ts +67 -0
  157. package/dist/features/api-keys/api-keys.service.js +144 -0
  158. package/dist/features/api-keys/api-keys.service.js.map +1 -0
  159. package/dist/features/email-change/email-change.controller.d.ts +38 -0
  160. package/dist/features/email-change/email-change.controller.js +85 -0
  161. package/dist/features/email-change/email-change.controller.js.map +1 -0
  162. package/dist/features/email-change/email-change.dto.d.ts +10 -0
  163. package/dist/features/email-change/email-change.dto.js +43 -0
  164. package/dist/features/email-change/email-change.dto.js.map +1 -0
  165. package/dist/features/email-change/email-change.service.d.ts +74 -0
  166. package/dist/features/email-change/email-change.service.js +179 -0
  167. package/dist/features/email-change/email-change.service.js.map +1 -0
  168. package/dist/features/email-links/email-verification.service.d.ts +46 -0
  169. package/dist/features/email-links/email-verification.service.js +94 -0
  170. package/dist/features/email-links/email-verification.service.js.map +1 -0
  171. package/dist/features/email-links/link-tokens.service.d.ts +44 -0
  172. package/dist/features/email-links/link-tokens.service.js +122 -0
  173. package/dist/features/email-links/link-tokens.service.js.map +1 -0
  174. package/dist/features/events/auth-events.service.d.ts +52 -0
  175. package/dist/features/events/auth-events.service.js +117 -0
  176. package/dist/features/events/auth-events.service.js.map +1 -0
  177. package/dist/features/maintenance/data-retention.service.d.ts +60 -0
  178. package/dist/features/maintenance/data-retention.service.js +182 -0
  179. package/dist/features/maintenance/data-retention.service.js.map +1 -0
  180. package/dist/features/notifications/notifications.service.d.ts +40 -0
  181. package/dist/features/notifications/notifications.service.js +94 -0
  182. package/dist/features/notifications/notifications.service.js.map +1 -0
  183. package/dist/features/one-time-codes/one-time-codes.service.d.ts +40 -0
  184. package/dist/features/one-time-codes/one-time-codes.service.js +102 -0
  185. package/dist/features/one-time-codes/one-time-codes.service.js.map +1 -0
  186. package/dist/features/organizations/organizations.controller.d.ts +220 -0
  187. package/dist/features/organizations/organizations.controller.js +337 -0
  188. package/dist/features/organizations/organizations.controller.js.map +1 -0
  189. package/dist/features/organizations/organizations.dto.d.ts +31 -0
  190. package/dist/features/organizations/organizations.dto.js +100 -0
  191. package/dist/features/organizations/organizations.dto.js.map +1 -0
  192. package/dist/features/organizations/organizations.service.d.ts +274 -0
  193. package/dist/features/organizations/organizations.service.js +481 -0
  194. package/dist/features/organizations/organizations.service.js.map +1 -0
  195. package/dist/features/passkeys/passkeys.controller.d.ts +92 -0
  196. package/dist/features/passkeys/passkeys.controller.js +183 -0
  197. package/dist/features/passkeys/passkeys.controller.js.map +1 -0
  198. package/dist/features/passkeys/passkeys.dto.d.ts +13 -0
  199. package/dist/features/passkeys/passkeys.dto.js +50 -0
  200. package/dist/features/passkeys/passkeys.dto.js.map +1 -0
  201. package/dist/features/passkeys/passkeys.service.d.ts +159 -0
  202. package/dist/features/passkeys/passkeys.service.js +350 -0
  203. package/dist/features/passkeys/passkeys.service.js.map +1 -0
  204. package/dist/features/passwordless/passwordless-auth.service.d.ts +152 -0
  205. package/dist/features/passwordless/passwordless-auth.service.js +304 -0
  206. package/dist/features/passwordless/passwordless-auth.service.js.map +1 -0
  207. package/dist/features/passwordless/passwordless.controller.d.ts +75 -0
  208. package/dist/features/passwordless/passwordless.controller.js +163 -0
  209. package/dist/features/passwordless/passwordless.controller.js.map +1 -0
  210. package/dist/features/passwordless/passwordless.dto.d.ts +29 -0
  211. package/dist/features/passwordless/passwordless.dto.js +101 -0
  212. package/dist/features/passwordless/passwordless.dto.js.map +1 -0
  213. package/dist/features/passwords/password-auth.service.d.ts +154 -0
  214. package/dist/features/passwords/password-auth.service.js +317 -0
  215. package/dist/features/passwords/password-auth.service.js.map +1 -0
  216. package/dist/features/passwords/password-policy.service.d.ts +63 -0
  217. package/dist/features/passwords/password-policy.service.js +175 -0
  218. package/dist/features/passwords/password-policy.service.js.map +1 -0
  219. package/dist/features/passwords/password.controller.d.ts +95 -0
  220. package/dist/features/passwords/password.controller.js +193 -0
  221. package/dist/features/passwords/password.controller.js.map +1 -0
  222. package/dist/features/passwords/password.dto.d.ts +36 -0
  223. package/dist/features/passwords/password.dto.js +140 -0
  224. package/dist/features/passwords/password.dto.js.map +1 -0
  225. package/dist/features/sessions/session.service.d.ts +132 -0
  226. package/dist/features/sessions/session.service.js +308 -0
  227. package/dist/features/sessions/session.service.js.map +1 -0
  228. package/dist/features/sessions/session.types.d.ts +34 -0
  229. package/dist/features/sessions/session.types.js +3 -0
  230. package/dist/features/sessions/session.types.js.map +1 -0
  231. package/dist/features/settings/settings.defaults.d.ts +2 -0
  232. package/dist/features/settings/settings.defaults.js +7 -0
  233. package/dist/features/settings/settings.defaults.js.map +1 -0
  234. package/dist/features/settings/settings.service.d.ts +44 -0
  235. package/dist/features/settings/settings.service.js +112 -0
  236. package/dist/features/settings/settings.service.js.map +1 -0
  237. package/dist/features/settings/settings.types.d.ts +133 -0
  238. package/dist/features/settings/settings.types.js +3 -0
  239. package/dist/features/settings/settings.types.js.map +1 -0
  240. package/dist/features/settings/settings.validation.d.ts +33 -0
  241. package/dist/features/settings/settings.validation.js +614 -0
  242. package/dist/features/settings/settings.validation.js.map +1 -0
  243. package/dist/features/sign-in/sign-in-challenges.service.d.ts +54 -0
  244. package/dist/features/sign-in/sign-in-challenges.service.js +104 -0
  245. package/dist/features/sign-in/sign-in-challenges.service.js.map +1 -0
  246. package/dist/features/sign-in/sign-in.service.d.ts +127 -0
  247. package/dist/features/sign-in/sign-in.service.js +248 -0
  248. package/dist/features/sign-in/sign-in.service.js.map +1 -0
  249. package/dist/features/sign-in/sign-in.types.d.ts +22 -0
  250. package/dist/features/sign-in/sign-in.types.js +3 -0
  251. package/dist/features/sign-in/sign-in.types.js.map +1 -0
  252. package/dist/features/signing-keys/jwks.controller.d.ts +17 -0
  253. package/dist/features/signing-keys/jwks.controller.js +51 -0
  254. package/dist/features/signing-keys/jwks.controller.js.map +1 -0
  255. package/dist/features/signing-keys/signing-keys.service.d.ts +67 -0
  256. package/dist/features/signing-keys/signing-keys.service.js +142 -0
  257. package/dist/features/signing-keys/signing-keys.service.js.map +1 -0
  258. package/dist/features/social/social-auth.service.d.ts +100 -0
  259. package/dist/features/social/social-auth.service.js +232 -0
  260. package/dist/features/social/social-auth.service.js.map +1 -0
  261. package/dist/features/social/social-providers.service.d.ts +97 -0
  262. package/dist/features/social/social-providers.service.js +214 -0
  263. package/dist/features/social/social-providers.service.js.map +1 -0
  264. package/dist/features/social/social.controller.d.ts +54 -0
  265. package/dist/features/social/social.controller.js +124 -0
  266. package/dist/features/social/social.controller.js.map +1 -0
  267. package/dist/features/social/social.dto.d.ts +11 -0
  268. package/dist/features/social/social.dto.js +38 -0
  269. package/dist/features/social/social.dto.js.map +1 -0
  270. package/dist/features/two-factor/two-factor.controller.d.ts +84 -0
  271. package/dist/features/two-factor/two-factor.controller.js +174 -0
  272. package/dist/features/two-factor/two-factor.controller.js.map +1 -0
  273. package/dist/features/two-factor/two-factor.dto.d.ts +10 -0
  274. package/dist/features/two-factor/two-factor.dto.js +37 -0
  275. package/dist/features/two-factor/two-factor.dto.js.map +1 -0
  276. package/dist/features/two-factor/two-factor.service.d.ts +171 -0
  277. package/dist/features/two-factor/two-factor.service.js +348 -0
  278. package/dist/features/two-factor/two-factor.service.js.map +1 -0
  279. package/dist/features/users/sign-in-methods.service.d.ts +40 -0
  280. package/dist/features/users/sign-in-methods.service.js +81 -0
  281. package/dist/features/users/sign-in-methods.service.js.map +1 -0
  282. package/dist/features/users/sign-up-rules.d.ts +12 -0
  283. package/dist/features/users/sign-up-rules.js +29 -0
  284. package/dist/features/users/sign-up-rules.js.map +1 -0
  285. package/dist/features/users/users.service.d.ts +246 -0
  286. package/dist/features/users/users.service.js +509 -0
  287. package/dist/features/users/users.service.js.map +1 -0
  288. package/dist/features/users/users.types.d.ts +24 -0
  289. package/dist/features/users/users.types.js +3 -0
  290. package/dist/features/users/users.types.js.map +1 -0
  291. package/dist/features/webhooks/webhook-delivery.worker.d.ts +55 -0
  292. package/dist/features/webhooks/webhook-delivery.worker.js +175 -0
  293. package/dist/features/webhooks/webhook-delivery.worker.js.map +1 -0
  294. package/dist/features/webhooks/webhook-signature.d.ts +28 -0
  295. package/dist/features/webhooks/webhook-signature.js +85 -0
  296. package/dist/features/webhooks/webhook-signature.js.map +1 -0
  297. package/dist/features/webhooks/webhooks.service.d.ts +144 -0
  298. package/dist/features/webhooks/webhooks.service.js +238 -0
  299. package/dist/features/webhooks/webhooks.service.js.map +1 -0
  300. package/dist/guards/auth.decorators.d.ts +65 -0
  301. package/dist/guards/auth.decorators.js +68 -0
  302. package/dist/guards/auth.decorators.js.map +1 -0
  303. package/dist/guards/auth.guard.d.ts +47 -0
  304. package/dist/guards/auth.guard.js +132 -0
  305. package/dist/guards/auth.guard.js.map +1 -0
  306. package/dist/index.d.ts +38 -0
  307. package/dist/index.js +95 -0
  308. package/dist/index.js.map +1 -0
  309. package/dist/integrations/console-email-sender.d.ts +15 -0
  310. package/dist/integrations/console-email-sender.js +26 -0
  311. package/dist/integrations/console-email-sender.js.map +1 -0
  312. package/dist/integrations/msg91-sms-sender.d.ts +28 -0
  313. package/dist/integrations/msg91-sms-sender.js +46 -0
  314. package/dist/integrations/msg91-sms-sender.js.map +1 -0
  315. package/docs/README.md +39 -0
  316. package/docs/admin-api-keys-webhooks.md +147 -0
  317. package/docs/api-reference.md +175 -0
  318. package/docs/architecture.md +119 -0
  319. package/docs/client-integration.md +192 -0
  320. package/docs/code-walkthrough.md +273 -0
  321. package/docs/configuration.md +229 -0
  322. package/docs/endpoints/README.md +151 -0
  323. package/docs/endpoints/account.md +363 -0
  324. package/docs/endpoints/admin.md +422 -0
  325. package/docs/endpoints/email-password.md +261 -0
  326. package/docs/endpoints/organizations.md +192 -0
  327. package/docs/endpoints/passkeys.md +195 -0
  328. package/docs/endpoints/passwordless.md +214 -0
  329. package/docs/endpoints/social.md +116 -0
  330. package/docs/endpoints/two-factor.md +146 -0
  331. package/docs/error-codes.md +100 -0
  332. package/docs/events.md +83 -0
  333. package/docs/getting-started.md +139 -0
  334. package/docs/manual-testing.md +215 -0
  335. package/docs/organizations.md +86 -0
  336. package/docs/production-checklist.md +60 -0
  337. package/docs/protecting-routes.md +147 -0
  338. package/docs/security.md +61 -0
  339. package/docs/sign-in-flows.md +294 -0
  340. package/package.json +92 -4
@@ -0,0 +1,509 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.UsersService = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const typeorm_1 = require("typeorm");
18
+ const auth_error_1 = require("../../common/auth-error.js");
19
+ const constants_1 = require("../../constants.js");
20
+ const entities_1 = require("../../database/entities/index.js");
21
+ const auth_events_service_1 = require("../events/auth-events.service.js");
22
+ const session_service_1 = require("../sessions/session.service.js");
23
+ const typeorm_row_1 = require("../../database/typeorm-row.js");
24
+ /**
25
+ * Accounts and their life cycle:
26
+ *
27
+ * PENDING_VERIFICATION --(required verifications done)--> ACTIVE
28
+ * ACTIVE --(admin)--> SUSPENDED --(admin lifts it)--> ACTIVE
29
+ * ACTIVE --(user)--> DEACTIVATED --(user reactivates)--> ACTIVE
30
+ * any --(user or admin)--> DELETED (personal data wiped; cannot be undone)
31
+ *
32
+ * Suspending, deactivating and deleting all sign the user out everywhere.
33
+ */
34
+ let UsersService = class UsersService {
35
+ sessions;
36
+ events;
37
+ database;
38
+ constructor(options, sessions, events) {
39
+ this.sessions = sessions;
40
+ this.events = events;
41
+ this.database = options.dataSource;
42
+ }
43
+ // -------------------------------------------------------------------------------------------
44
+ // Finding users
45
+ // -------------------------------------------------------------------------------------------
46
+ /**
47
+ * @param userId - The user's id.
48
+ * @returns The user (in any status, including DELETED), or null.
49
+ */
50
+ findUserById(userId) {
51
+ return this.database.getRepository(entities_1.UserEntity).findOne({ where: { id: userId } });
52
+ }
53
+ /**
54
+ * @param email - Must already be normalized (see `normalizeEmail`).
55
+ * @returns The user with this email, or null.
56
+ */
57
+ findUserByEmail(email) {
58
+ return this.database.getRepository(entities_1.UserEntity).findOne({ where: { email } });
59
+ }
60
+ /**
61
+ * @param phoneNumber - Must already be normalized (see `normalizePhoneNumber`).
62
+ * @returns The user with this phone number, or null.
63
+ */
64
+ findUserByPhoneNumber(phoneNumber) {
65
+ return this.database.getRepository(entities_1.UserEntity).findOne({ where: { phoneNumber } });
66
+ }
67
+ /**
68
+ * Loads a user that must exist. Deleted accounts count as missing.
69
+ *
70
+ * @param userId - The user's id.
71
+ * @returns The user.
72
+ * @throws AuthError NOT_FOUND when there is no such user, or it was deleted.
73
+ */
74
+ async getUserOrThrow(userId) {
75
+ const user = await this.findUserById(userId);
76
+ if (!user || user.status === constants_1.ACCOUNT_STATUS.deleted)
77
+ throw new auth_error_1.AuthError(constants_1.AUTH_ERRORS.notFound);
78
+ return user;
79
+ }
80
+ // -------------------------------------------------------------------------------------------
81
+ // Creating users
82
+ // -------------------------------------------------------------------------------------------
83
+ /**
84
+ * Creates an account with the app's default roles (users can never pick their own role).
85
+ * The account starts ACTIVE if the sign-up already proved everything the settings require,
86
+ * otherwise PENDING_VERIFICATION.
87
+ *
88
+ * @param details - Contact details, names, and what the sign-up already verified.
89
+ * @param settings - The current settings (registration and activation rules).
90
+ * @param request - Who is asking (for the audit log).
91
+ * @param transaction - Pass one to create the user together with other rows (e.g. the password).
92
+ * @returns The saved user.
93
+ * @throws AuthError SIGN_UP_CLOSED when registration is turned off.
94
+ * @throws AuthError ACCOUNT_ALREADY_EXISTS when the email or phone number is already taken.
95
+ */
96
+ async createUser(details, settings, request, transaction) {
97
+ if (!settings.registration.enabled)
98
+ throw new auth_error_1.AuthError(constants_1.AUTH_ERRORS.signUpClosed);
99
+ const now = new Date();
100
+ const newUser = this.database.getRepository(entities_1.UserEntity).create({
101
+ email: details.email ?? null,
102
+ isEmailVerified: details.isEmailVerified ?? false,
103
+ phoneNumber: details.phoneNumber ?? null,
104
+ isPhoneVerified: details.isPhoneVerified ?? false,
105
+ firstName: details.firstName ?? null,
106
+ lastName: details.lastName ?? null,
107
+ roles: [...settings.registration.defaultRoles],
108
+ termsAcceptedAt: details.acceptedTerms ? now : null,
109
+ privacyPolicyAcceptedAt: details.acceptedPrivacyPolicy ? now : null,
110
+ metadata: {},
111
+ });
112
+ newUser.status = this.getPendingVerifications(newUser, settings).length === 0 ? constants_1.ACCOUNT_STATUS.active : constants_1.ACCOUNT_STATUS.pendingVerification;
113
+ newUser.statusChangedAt = now;
114
+ let savedUser;
115
+ try {
116
+ savedUser = await (transaction ?? this.database.manager).save(entities_1.UserEntity, newUser);
117
+ }
118
+ catch (error) {
119
+ if (this.isUniqueViolation(error))
120
+ throw new auth_error_1.AuthError(constants_1.AUTH_ERRORS.accountAlreadyExists);
121
+ throw error;
122
+ }
123
+ await this.events.record({
124
+ name: constants_1.AUTH_EVENTS.userCreated,
125
+ userId: savedUser.id,
126
+ request,
127
+ details: { status: savedUser.status },
128
+ });
129
+ return savedUser;
130
+ }
131
+ // -------------------------------------------------------------------------------------------
132
+ // Verification and activation
133
+ // -------------------------------------------------------------------------------------------
134
+ /**
135
+ * Lists what the user still has to verify before the account becomes ACTIVE.
136
+ *
137
+ * @param user - The user.
138
+ * @param settings - The current settings (activation rules).
139
+ * @returns e.g. ["email"]; empty when nothing is left.
140
+ */
141
+ getPendingVerifications(user, settings) {
142
+ const pending = [];
143
+ if (settings.activation.requireVerifiedEmail && user.email && !user.isEmailVerified)
144
+ pending.push(constants_1.PENDING_VERIFICATION.email);
145
+ if (settings.activation.requireVerifiedPhone && !(user.phoneNumber && user.isPhoneVerified))
146
+ pending.push(constants_1.PENDING_VERIFICATION.phone);
147
+ return pending;
148
+ }
149
+ /**
150
+ * Marks the email verified, and activates the account if nothing else is pending.
151
+ *
152
+ * @param user - The user; updated in place.
153
+ * @param settings - The current settings.
154
+ * @param request - Who is asking (for the audit log).
155
+ * @returns The same user, with its new status.
156
+ */
157
+ async markEmailVerified(user, settings, request) {
158
+ if (!user.isEmailVerified) {
159
+ await this.database.getRepository(entities_1.UserEntity).update({ id: user.id }, { isEmailVerified: true });
160
+ user.isEmailVerified = true;
161
+ await this.events.record({ name: constants_1.AUTH_EVENTS.emailVerified, userId: user.id, request });
162
+ }
163
+ return this.activateIfReady(user, settings, request);
164
+ }
165
+ /**
166
+ * Marks the phone number verified, and activates the account if nothing else is pending.
167
+ *
168
+ * @param user - The user; updated in place.
169
+ * @param settings - The current settings.
170
+ * @param request - Who is asking (for the audit log).
171
+ * @returns The same user, with its new status.
172
+ */
173
+ async markPhoneVerified(user, settings, request) {
174
+ if (!user.isPhoneVerified) {
175
+ await this.database.getRepository(entities_1.UserEntity).update({ id: user.id }, { isPhoneVerified: true });
176
+ user.isPhoneVerified = true;
177
+ await this.events.record({ name: constants_1.AUTH_EVENTS.phoneVerified, userId: user.id, request });
178
+ }
179
+ return this.activateIfReady(user, settings, request);
180
+ }
181
+ /**
182
+ * Protects against "account pre-hijacking": someone registers YOUR email with THEIR password,
183
+ * never verifies it, and waits for you to sign in with a code, link or Google. When the real
184
+ * owner proves the email for the first time this way, any password set before that proof is
185
+ * removed and all earlier sessions end. Call it BEFORE markEmailVerified.
186
+ *
187
+ * A brand-new account (younger than UNVERIFIED_ACCOUNT_GRACE_SECONDS) is left alone: that is the
188
+ * normal "register with a password, then verify with the emailed code" flow.
189
+ *
190
+ * @param user - The user who just proved the email.
191
+ * @param request - Who is asking (for the audit log).
192
+ */
193
+ async removeUnprovenPassword(user, request) {
194
+ if (user.isEmailVerified)
195
+ return;
196
+ const accountAgeSeconds = (Date.now() - user.createdAt.getTime()) / constants_1.SECOND_IN_MILLISECONDS;
197
+ if (accountAgeSeconds < constants_1.UNVERIFIED_ACCOUNT_GRACE_SECONDS)
198
+ return;
199
+ const removed = await this.database.getRepository(entities_1.PasswordEntity).delete({ userId: user.id });
200
+ await this.sessions.revokeAllSessions(user.id, constants_1.SESSION_END_REASON.emailProvenByOwner);
201
+ if (removed.affected) {
202
+ await this.events.record({
203
+ name: constants_1.AUTH_EVENTS.passwordChanged,
204
+ userId: user.id,
205
+ request,
206
+ details: { how: constants_1.PASSWORD_CHANGE_KIND.removedUnverified },
207
+ });
208
+ }
209
+ }
210
+ /**
211
+ * Moves a PENDING_VERIFICATION account to ACTIVE once nothing is left to verify.
212
+ * Does nothing for accounts in any other status.
213
+ *
214
+ * @param user - The user; updated in place.
215
+ * @param settings - The current settings.
216
+ * @param request - Who is asking (for the audit log).
217
+ * @returns The same user.
218
+ */
219
+ async activateIfReady(user, settings, request) {
220
+ if (user.status !== constants_1.ACCOUNT_STATUS.pendingVerification || this.getPendingVerifications(user, settings).length > 0)
221
+ return user;
222
+ const wasActivated = await this.changeStatus(user, constants_1.ACCOUNT_STATUS.pendingVerification, constants_1.ACCOUNT_STATUS.active);
223
+ if (wasActivated)
224
+ await this.events.record({ name: constants_1.AUTH_EVENTS.userActivated, userId: user.id, request });
225
+ return user;
226
+ }
227
+ // -------------------------------------------------------------------------------------------
228
+ // Profile
229
+ // -------------------------------------------------------------------------------------------
230
+ /**
231
+ * Changes the user's names and/or app metadata. Fields left undefined are not touched.
232
+ *
233
+ * @param userId - The user to change.
234
+ * @param changes - The new values.
235
+ * @param performedBy - Who made the change, for the audit log (null when it was the user).
236
+ * @param request - Who is asking.
237
+ * @returns The updated user.
238
+ * @throws AuthError NOT_FOUND when the user doesn't exist.
239
+ */
240
+ async updateProfile(userId, changes, performedBy, request) {
241
+ const user = await this.getUserOrThrow(userId);
242
+ const changedFields = Object.keys(changes).filter((field) => changes[field] !== undefined);
243
+ if (changedFields.length === 0)
244
+ return user;
245
+ Object.assign(user, Object.fromEntries(changedFields.map((field) => [field, changes[field]])));
246
+ await this.database.getRepository(entities_1.UserEntity).save(user);
247
+ await this.events.record({ name: constants_1.AUTH_EVENTS.userUpdated, userId, performedBy, request, details: { changedFields } });
248
+ return user;
249
+ }
250
+ /**
251
+ * Called by your app's profile module once the user has finished onboarding.
252
+ * Calling it again changes nothing.
253
+ *
254
+ * @param userId - The user.
255
+ * @param request - Who is asking (for the audit log).
256
+ * @returns The updated user.
257
+ */
258
+ async completeOnboarding(userId, request) {
259
+ const user = await this.getUserOrThrow(userId);
260
+ if (user.onboardingCompletedAt)
261
+ return user;
262
+ user.onboardingCompletedAt = new Date();
263
+ await this.database.getRepository(entities_1.UserEntity).update({ id: userId }, { onboardingCompletedAt: user.onboardingCompletedAt });
264
+ await this.events.record({ name: constants_1.AUTH_EVENTS.onboardingCompleted, userId, request });
265
+ return user;
266
+ }
267
+ /**
268
+ * Replaces a user's app-wide roles. Admin only. New roles show up in the user's next access token.
269
+ *
270
+ * @param userId - The user to change.
271
+ * @param roles - The full new list; duplicates are removed.
272
+ * @param adminUserId - The admin doing it (for the audit log).
273
+ * @param request - Who is asking.
274
+ * @returns The updated user.
275
+ * @throws AuthError VALIDATION_ERROR when a role name is invalid or there are too many roles.
276
+ */
277
+ async setRoles(userId, roles, adminUserId, request) {
278
+ const uniqueRoles = [...new Set(roles)];
279
+ const hasInvalidRole = uniqueRoles.some((role) => !constants_1.ROLE_NAME_PATTERN.test(role));
280
+ if (hasInvalidRole || uniqueRoles.length > constants_1.MAXIMUM_ROLES_PER_USER)
281
+ throw new auth_error_1.AuthError(constants_1.AUTH_ERRORS.validationFailed);
282
+ const user = await this.getUserOrThrow(userId);
283
+ const previousRoles = user.roles;
284
+ user.roles = uniqueRoles;
285
+ await this.database.getRepository(entities_1.UserEntity).update({ id: userId }, { roles: uniqueRoles });
286
+ await this.events.record({
287
+ name: constants_1.AUTH_EVENTS.userRolesChanged,
288
+ userId,
289
+ performedBy: constants_1.PERFORMED_BY.admin(adminUserId),
290
+ request,
291
+ details: { previousRoles, roles: uniqueRoles },
292
+ });
293
+ return user;
294
+ }
295
+ /**
296
+ * Remembers when the user last signed in (shown to admins and in the profile).
297
+ *
298
+ * @param user - The user; updated in place.
299
+ */
300
+ async recordSignIn(user) {
301
+ user.lastSignedInAt = new Date();
302
+ await this.database.getRepository(entities_1.UserEntity).update({ id: user.id }, { lastSignedInAt: user.lastSignedInAt });
303
+ }
304
+ // -------------------------------------------------------------------------------------------
305
+ // Status changes
306
+ // -------------------------------------------------------------------------------------------
307
+ /**
308
+ * Admin blocks an account. The reason is kept for support staff. Signs the user out everywhere.
309
+ *
310
+ * @param userId - The user to suspend.
311
+ * @param reason - Why (kept for support staff, not shown to the user).
312
+ * @param adminUserId - The admin doing it (for the audit log).
313
+ * @param request - Who is asking.
314
+ * @returns The updated user.
315
+ */
316
+ async suspendUser(userId, reason, adminUserId, request) {
317
+ const user = await this.getUserOrThrow(userId);
318
+ if (user.status !== constants_1.ACCOUNT_STATUS.suspended) {
319
+ user.suspensionReason = reason;
320
+ await this.changeStatus(user, user.status, constants_1.ACCOUNT_STATUS.suspended, { suspensionReason: reason });
321
+ }
322
+ await this.sessions.revokeAllSessions(userId, constants_1.SESSION_END_REASON.accountSuspended);
323
+ await this.events.record({
324
+ name: constants_1.AUTH_EVENTS.userSuspended,
325
+ userId,
326
+ performedBy: constants_1.PERFORMED_BY.admin(adminUserId),
327
+ request,
328
+ details: { reason },
329
+ });
330
+ return user;
331
+ }
332
+ /**
333
+ * Admin lifts a suspension. The account goes back to ACTIVE (or PENDING_VERIFICATION if still unverified).
334
+ *
335
+ * @param userId - The suspended user.
336
+ * @param adminUserId - The admin doing it (for the audit log).
337
+ * @param settings - The current settings.
338
+ * @param request - Who is asking.
339
+ * @returns The updated user (unchanged if it wasn't suspended).
340
+ */
341
+ async liftSuspension(userId, adminUserId, settings, request) {
342
+ const user = await this.getUserOrThrow(userId);
343
+ if (user.status !== constants_1.ACCOUNT_STATUS.suspended)
344
+ return user;
345
+ await this.changeStatus(user, constants_1.ACCOUNT_STATUS.suspended, this.statusAfterReturning(user, settings), { suspensionReason: null });
346
+ user.suspensionReason = null;
347
+ await this.events.record({ name: constants_1.AUTH_EVENTS.userReactivated, userId, performedBy: constants_1.PERFORMED_BY.admin(adminUserId), request });
348
+ return user;
349
+ }
350
+ /**
351
+ * The user switches their own account off for a while. Signs them out everywhere.
352
+ * They can switch it back on by signing in again.
353
+ *
354
+ * @param userId - The signed-in user.
355
+ * @param request - Who is asking (for the audit log).
356
+ * @throws AuthError ACCOUNT_SUSPENDED when an admin has suspended the account.
357
+ */
358
+ async deactivateAccount(userId, request) {
359
+ const user = await this.getUserOrThrow(userId);
360
+ if (user.status === constants_1.ACCOUNT_STATUS.suspended)
361
+ throw new auth_error_1.AuthError(constants_1.AUTH_ERRORS.accountSuspended);
362
+ if (user.status !== constants_1.ACCOUNT_STATUS.deactivated)
363
+ await this.changeStatus(user, user.status, constants_1.ACCOUNT_STATUS.deactivated);
364
+ await this.sessions.revokeAllSessions(userId, constants_1.SESSION_END_REASON.accountDeactivated);
365
+ await this.events.record({ name: constants_1.AUTH_EVENTS.userDeactivated, userId, request });
366
+ }
367
+ /**
368
+ * The user switches their account back on (after proving who they are, see SignInService).
369
+ *
370
+ * @param userId - The deactivated user.
371
+ * @param settings - The current settings.
372
+ * @param request - Who is asking (for the audit log).
373
+ * @returns The updated user.
374
+ * @throws AuthError ACCOUNT_NOT_DEACTIVATED when the account isn't deactivated.
375
+ */
376
+ async reactivateAccount(userId, settings, request) {
377
+ const user = await this.getUserOrThrow(userId);
378
+ if (user.status !== constants_1.ACCOUNT_STATUS.deactivated)
379
+ throw new auth_error_1.AuthError(constants_1.AUTH_ERRORS.accountNotDeactivated);
380
+ await this.changeStatus(user, constants_1.ACCOUNT_STATUS.deactivated, this.statusAfterReturning(user, settings));
381
+ await this.events.record({ name: constants_1.AUTH_EVENTS.userReactivated, userId, request });
382
+ return user;
383
+ }
384
+ /**
385
+ * Deletes the account. The row stays (so ids in your other tables don't dangle and the audit log
386
+ * still makes sense), but every piece of personal data and every way to sign in is wiped.
387
+ * This cannot be undone.
388
+ *
389
+ * @param userId - The user to delete.
390
+ * @param performedBy - Who did it, for the audit log (null when it was the user).
391
+ * @param request - Who is asking.
392
+ */
393
+ async deleteUser(userId, performedBy, request) {
394
+ const user = await this.getUserOrThrow(userId);
395
+ const deletedUserFilter = { userId };
396
+ await this.database.transaction(async (transaction) => {
397
+ await transaction.update(entities_1.UserEntity, { id: userId }, (0, typeorm_row_1.typeormRow)({
398
+ email: null,
399
+ isEmailVerified: false,
400
+ phoneNumber: null,
401
+ isPhoneVerified: false,
402
+ firstName: null,
403
+ lastName: null,
404
+ roles: [],
405
+ metadata: {},
406
+ isTwoFactorEnabled: false,
407
+ suspensionReason: null,
408
+ status: constants_1.ACCOUNT_STATUS.deleted,
409
+ statusChangedAt: new Date(),
410
+ }));
411
+ const tablesWithUserRows = [
412
+ entities_1.PasswordEntity,
413
+ entities_1.SocialAccountEntity,
414
+ entities_1.PasskeyEntity,
415
+ entities_1.TwoFactorSecretEntity,
416
+ entities_1.BackupCodeEntity,
417
+ entities_1.SignInChallengeEntity,
418
+ entities_1.LinkTokenEntity,
419
+ entities_1.OrganizationMemberEntity,
420
+ ];
421
+ for (const table of tablesWithUserRows)
422
+ await transaction.delete(table, deletedUserFilter);
423
+ // Pending codes are keyed by where they were sent, not by user.
424
+ const destinations = [user.email, user.phoneNumber].filter((value) => !!value);
425
+ for (const destination of destinations)
426
+ await transaction.delete(entities_1.OneTimeCodeEntity, { destination });
427
+ });
428
+ await this.sessions.revokeAllSessions(userId, constants_1.SESSION_END_REASON.accountDeleted);
429
+ await this.events.record({ name: constants_1.AUTH_EVENTS.userDeleted, userId, performedBy, request });
430
+ }
431
+ // -------------------------------------------------------------------------------------------
432
+ // Responses
433
+ // -------------------------------------------------------------------------------------------
434
+ /**
435
+ * The user as your app may show it. Never includes secrets.
436
+ *
437
+ * @param user - The user.
438
+ * @param settings - The current settings (to work out pending verifications).
439
+ * @returns The profile to send to the client.
440
+ */
441
+ toPublicProfile(user, settings) {
442
+ return {
443
+ id: user.id,
444
+ email: user.email,
445
+ isEmailVerified: user.isEmailVerified,
446
+ phoneNumber: user.phoneNumber,
447
+ isPhoneVerified: user.isPhoneVerified,
448
+ firstName: user.firstName,
449
+ lastName: user.lastName,
450
+ roles: user.roles,
451
+ status: user.status,
452
+ pendingVerifications: this.getPendingVerifications(user, settings),
453
+ onboardingCompleted: user.onboardingCompletedAt !== null,
454
+ isTwoFactorEnabled: user.isTwoFactorEnabled,
455
+ metadata: user.metadata,
456
+ lastSignedInAt: user.lastSignedInAt?.toISOString() ?? null,
457
+ createdAt: user.createdAt.toISOString(),
458
+ };
459
+ }
460
+ // -------------------------------------------------------------------------------------------
461
+ // Helpers
462
+ // -------------------------------------------------------------------------------------------
463
+ /**
464
+ * Where a returning (unsuspended / reactivated) account lands: ACTIVE, unless verification is still owed.
465
+ *
466
+ * @param user - The returning user.
467
+ * @param settings - The current settings.
468
+ * @returns ACTIVE or PENDING_VERIFICATION.
469
+ */
470
+ statusAfterReturning(user, settings) {
471
+ return this.getPendingVerifications(user, settings).length === 0 ? constants_1.ACCOUNT_STATUS.active : constants_1.ACCOUNT_STATUS.pendingVerification;
472
+ }
473
+ /**
474
+ * Changes the status only if it is still `expectedStatus` (so two admins clicking at once can't
475
+ * clash). Updates `user` in place.
476
+ *
477
+ * @param user - The user to change.
478
+ * @param expectedStatus - The status the user must still have.
479
+ * @param newStatus - The status to set.
480
+ * @param extraColumns - Other columns to change in the same UPDATE.
481
+ * @returns False if someone else changed it first.
482
+ */
483
+ async changeStatus(user, expectedStatus, newStatus, extraColumns = {}) {
484
+ const changedAt = new Date();
485
+ const result = await this.database
486
+ .getRepository(entities_1.UserEntity)
487
+ .update({ id: user.id, status: expectedStatus }, (0, typeorm_row_1.typeormRow)({ status: newStatus, statusChangedAt: changedAt, ...extraColumns }));
488
+ if (!result.affected)
489
+ return false;
490
+ user.status = newStatus;
491
+ user.statusChangedAt = changedAt;
492
+ return true;
493
+ }
494
+ /**
495
+ * @param error - An error thrown by the database.
496
+ * @returns True when Postgres refused a duplicate value (e.g. an email that is already taken).
497
+ */
498
+ isUniqueViolation(error) {
499
+ return error instanceof typeorm_1.QueryFailedError && error.code === constants_1.POSTGRES_UNIQUE_VIOLATION_CODE;
500
+ }
501
+ };
502
+ exports.UsersService = UsersService;
503
+ exports.UsersService = UsersService = __decorate([
504
+ (0, common_1.Injectable)(),
505
+ __param(0, (0, common_1.Inject)(constants_1.AUTH_OPTIONS_TOKEN)),
506
+ __metadata("design:paramtypes", [Object, session_service_1.SessionService,
507
+ auth_events_service_1.AuthEventsService])
508
+ ], UsersService);
509
+ //# sourceMappingURL=users.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"users.service.js","sourceRoot":"","sources":["../../../src/features/users/users.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAoD;AACpD,qCAAsE;AAEtE,oDAAgD;AAEhD,2CAeqB;AACrB,kDAW6B;AAC7B,+EAA0E;AAC1E,yEAAqE;AAIrE,wDAAoD;AAqBpD;;;;;;;;;GASG;AAEI,IAAM,YAAY,GAAlB,MAAM,YAAY;IAKJ;IACA;IALF,QAAQ,CAAa;IAEtC,YAC8B,OAAoB,EAC/B,QAAwB,EACxB,MAAyB;QADzB,a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,SAAS,CAAC;QACxB,IAAI,CAAC,eAAe,GAAG,SAAS,CAAC;QACjC,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;OAGG;IACK,iBAAiB,CAAC,KAAc;QACtC,OAAO,KAAK,YAAY,0BAAgB,IAAK,KAA8C,CAAC,IAAI,KAAK,0CAA8B,CAAC;IACtI,CAAC;CACF,CAAA;AAlfY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,mBAAU,GAAE;IAKR,WAAA,IAAA,eAAM,EAAC,8BAAkB,CAAC,CAAA;6CACA,gCAAc;QAChB,uCAAiB;GANjC,YAAY,CAkfxB"}
@@ -0,0 +1,24 @@
1
+ import type { AccountStatus, PendingVerification } from '../../constants.js';
2
+ import type { JsonObject } from '../../database/entities/json-object.js';
3
+ /** A verification still owed before the account becomes ACTIVE (see PENDING_VERIFICATION). */
4
+ export type { PendingVerification };
5
+ /** The user as returned by GET /auth/me and the admin API. Never contains secrets. */
6
+ export interface PublicUserProfile {
7
+ id: string;
8
+ email: string | null;
9
+ isEmailVerified: boolean;
10
+ phoneNumber: string | null;
11
+ isPhoneVerified: boolean;
12
+ firstName: string | null;
13
+ lastName: string | null;
14
+ roles: string[];
15
+ status: AccountStatus;
16
+ /** What the user still has to verify. The app can send them straight to that screen. */
17
+ pendingVerifications: PendingVerification[];
18
+ /** Set by your app's profile module through UsersService.completeOnboarding(). */
19
+ onboardingCompleted: boolean;
20
+ isTwoFactorEnabled: boolean;
21
+ metadata: JsonObject;
22
+ lastSignedInAt: string | null;
23
+ createdAt: string;
24
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=users.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"users.types.js","sourceRoot":"","sources":["../../../src/features/users/users.types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,55 @@
1
+ import { OnApplicationBootstrap, OnModuleDestroy } from '@nestjs/common';
2
+ import { AuthOptions } from '../../auth-options.js';
3
+ import { WebhooksService } from './webhooks.service';
4
+ /**
5
+ * Sends queued webhook deliveries in the background.
6
+ *
7
+ * - Runs every few seconds on every server. Each server claims different rows
8
+ * (FOR UPDATE SKIP LOCKED), so nothing is sent twice.
9
+ * - A 2xx response = delivered. Anything else is retried with growing delays
10
+ * (1 min, 5 min, 30 min, 2 h, 6 h, 12 h, 24 h), then marked failed.
11
+ * - Redirects are not followed, and the URL is re-checked before every send, so a receiver
12
+ * can't later point us at a private address.
13
+ */
14
+ export declare class WebhookDeliveryWorker implements OnApplicationBootstrap, OnModuleDestroy {
15
+ private readonly webhooks;
16
+ private readonly logger;
17
+ private readonly database;
18
+ private timer?;
19
+ private isRunning;
20
+ constructor(options: AuthOptions, webhooks: WebhooksService);
21
+ /**
22
+ * Starts the timer that sends due deliveries every few seconds.
23
+ */
24
+ onApplicationBootstrap(): void;
25
+ /**
26
+ * Stops the timer when the app shuts down.
27
+ */
28
+ onModuleDestroy(): void;
29
+ /**
30
+ * One round: claim due deliveries and send them. Public so tests and scripts can call it.
31
+ * A round is skipped if the previous one is still running. Errors are logged, never thrown.
32
+ */
33
+ sendDueDeliveries(): Promise<void>;
34
+ /**
35
+ * Takes due rows and pushes their next attempt a little into the future, in one statement.
36
+ * If this server crashes mid-send, another server picks them up after the claim times out.
37
+ *
38
+ * @returns The deliveries this server should send now.
39
+ */
40
+ private claimDueDeliveries;
41
+ /**
42
+ * Sends one delivery and records what happened. The webhook's URL is checked again first.
43
+ *
44
+ * @param delivery - A claimed delivery.
45
+ */
46
+ private sendOne;
47
+ /**
48
+ * Saves the result of an attempt and schedules the next retry, or marks the delivery
49
+ * delivered or failed.
50
+ *
51
+ * @param delivery - The delivery that was attempted.
52
+ * @param outcome - Whether it was delivered, whether to stop retrying, the HTTP status and the error.
53
+ */
54
+ private recordOutcome;
55
+ }