@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,246 @@
1
+ import { EntityManager } from 'typeorm';
2
+ import { AuthOptions } from '../../auth-options.js';
3
+ import { RequestContext } from '../../common/request-context.js';
4
+ import { UserEntity } from '../../database/entities/index.js';
5
+ import { AuthEventsService } from '../events/auth-events.service.js';
6
+ import { SessionService } from '../sessions/session.service.js';
7
+ import { AuthSettings } from '../settings/settings.types.js';
8
+ import { PendingVerification, PublicUserProfile } from './users.types';
9
+ import type { JsonObject } from '../../database/entities/json-object.js';
10
+ export interface NewUserDetails {
11
+ email?: string | null;
12
+ phoneNumber?: string | null;
13
+ firstName?: string | null;
14
+ lastName?: string | null;
15
+ /** True when the sign-up itself proved the email (email code, magic link, Google...). */
16
+ isEmailVerified?: boolean;
17
+ isPhoneVerified?: boolean;
18
+ acceptedTerms?: boolean;
19
+ acceptedPrivacyPolicy?: boolean;
20
+ }
21
+ export interface ProfileChanges {
22
+ firstName?: string;
23
+ lastName?: string;
24
+ /** Your app's own extra fields. Replaces the whole object. */
25
+ metadata?: JsonObject;
26
+ }
27
+ /**
28
+ * Accounts and their life cycle:
29
+ *
30
+ * PENDING_VERIFICATION --(required verifications done)--> ACTIVE
31
+ * ACTIVE --(admin)--> SUSPENDED --(admin lifts it)--> ACTIVE
32
+ * ACTIVE --(user)--> DEACTIVATED --(user reactivates)--> ACTIVE
33
+ * any --(user or admin)--> DELETED (personal data wiped; cannot be undone)
34
+ *
35
+ * Suspending, deactivating and deleting all sign the user out everywhere.
36
+ */
37
+ export declare class UsersService {
38
+ private readonly sessions;
39
+ private readonly events;
40
+ private readonly database;
41
+ constructor(options: AuthOptions, sessions: SessionService, events: AuthEventsService);
42
+ /**
43
+ * @param userId - The user's id.
44
+ * @returns The user (in any status, including DELETED), or null.
45
+ */
46
+ findUserById(userId: string): Promise<UserEntity | null>;
47
+ /**
48
+ * @param email - Must already be normalized (see `normalizeEmail`).
49
+ * @returns The user with this email, or null.
50
+ */
51
+ findUserByEmail(email: string): Promise<UserEntity | null>;
52
+ /**
53
+ * @param phoneNumber - Must already be normalized (see `normalizePhoneNumber`).
54
+ * @returns The user with this phone number, or null.
55
+ */
56
+ findUserByPhoneNumber(phoneNumber: string): Promise<UserEntity | null>;
57
+ /**
58
+ * Loads a user that must exist. Deleted accounts count as missing.
59
+ *
60
+ * @param userId - The user's id.
61
+ * @returns The user.
62
+ * @throws AuthError NOT_FOUND when there is no such user, or it was deleted.
63
+ */
64
+ getUserOrThrow(userId: string): Promise<UserEntity>;
65
+ /**
66
+ * Creates an account with the app's default roles (users can never pick their own role).
67
+ * The account starts ACTIVE if the sign-up already proved everything the settings require,
68
+ * otherwise PENDING_VERIFICATION.
69
+ *
70
+ * @param details - Contact details, names, and what the sign-up already verified.
71
+ * @param settings - The current settings (registration and activation rules).
72
+ * @param request - Who is asking (for the audit log).
73
+ * @param transaction - Pass one to create the user together with other rows (e.g. the password).
74
+ * @returns The saved user.
75
+ * @throws AuthError SIGN_UP_CLOSED when registration is turned off.
76
+ * @throws AuthError ACCOUNT_ALREADY_EXISTS when the email or phone number is already taken.
77
+ */
78
+ createUser(details: NewUserDetails, settings: AuthSettings, request: RequestContext, transaction?: EntityManager): Promise<UserEntity>;
79
+ /**
80
+ * Lists what the user still has to verify before the account becomes ACTIVE.
81
+ *
82
+ * @param user - The user.
83
+ * @param settings - The current settings (activation rules).
84
+ * @returns e.g. ["email"]; empty when nothing is left.
85
+ */
86
+ getPendingVerifications(user: UserEntity, settings: AuthSettings): PendingVerification[];
87
+ /**
88
+ * Marks the email verified, and activates the account if nothing else is pending.
89
+ *
90
+ * @param user - The user; updated in place.
91
+ * @param settings - The current settings.
92
+ * @param request - Who is asking (for the audit log).
93
+ * @returns The same user, with its new status.
94
+ */
95
+ markEmailVerified(user: UserEntity, settings: AuthSettings, request: RequestContext): Promise<UserEntity>;
96
+ /**
97
+ * Marks the phone number verified, and activates the account if nothing else is pending.
98
+ *
99
+ * @param user - The user; updated in place.
100
+ * @param settings - The current settings.
101
+ * @param request - Who is asking (for the audit log).
102
+ * @returns The same user, with its new status.
103
+ */
104
+ markPhoneVerified(user: UserEntity, settings: AuthSettings, request: RequestContext): Promise<UserEntity>;
105
+ /**
106
+ * Protects against "account pre-hijacking": someone registers YOUR email with THEIR password,
107
+ * never verifies it, and waits for you to sign in with a code, link or Google. When the real
108
+ * owner proves the email for the first time this way, any password set before that proof is
109
+ * removed and all earlier sessions end. Call it BEFORE markEmailVerified.
110
+ *
111
+ * A brand-new account (younger than UNVERIFIED_ACCOUNT_GRACE_SECONDS) is left alone: that is the
112
+ * normal "register with a password, then verify with the emailed code" flow.
113
+ *
114
+ * @param user - The user who just proved the email.
115
+ * @param request - Who is asking (for the audit log).
116
+ */
117
+ removeUnprovenPassword(user: UserEntity, request: RequestContext): Promise<void>;
118
+ /**
119
+ * Moves a PENDING_VERIFICATION account to ACTIVE once nothing is left to verify.
120
+ * Does nothing for accounts in any other status.
121
+ *
122
+ * @param user - The user; updated in place.
123
+ * @param settings - The current settings.
124
+ * @param request - Who is asking (for the audit log).
125
+ * @returns The same user.
126
+ */
127
+ activateIfReady(user: UserEntity, settings: AuthSettings, request: RequestContext): Promise<UserEntity>;
128
+ /**
129
+ * Changes the user's names and/or app metadata. Fields left undefined are not touched.
130
+ *
131
+ * @param userId - The user to change.
132
+ * @param changes - The new values.
133
+ * @param performedBy - Who made the change, for the audit log (null when it was the user).
134
+ * @param request - Who is asking.
135
+ * @returns The updated user.
136
+ * @throws AuthError NOT_FOUND when the user doesn't exist.
137
+ */
138
+ updateProfile(userId: string, changes: ProfileChanges, performedBy: string | null, request: RequestContext): Promise<UserEntity>;
139
+ /**
140
+ * Called by your app's profile module once the user has finished onboarding.
141
+ * Calling it again changes nothing.
142
+ *
143
+ * @param userId - The user.
144
+ * @param request - Who is asking (for the audit log).
145
+ * @returns The updated user.
146
+ */
147
+ completeOnboarding(userId: string, request: RequestContext): Promise<UserEntity>;
148
+ /**
149
+ * Replaces a user's app-wide roles. Admin only. New roles show up in the user's next access token.
150
+ *
151
+ * @param userId - The user to change.
152
+ * @param roles - The full new list; duplicates are removed.
153
+ * @param adminUserId - The admin doing it (for the audit log).
154
+ * @param request - Who is asking.
155
+ * @returns The updated user.
156
+ * @throws AuthError VALIDATION_ERROR when a role name is invalid or there are too many roles.
157
+ */
158
+ setRoles(userId: string, roles: string[], adminUserId: string, request: RequestContext): Promise<UserEntity>;
159
+ /**
160
+ * Remembers when the user last signed in (shown to admins and in the profile).
161
+ *
162
+ * @param user - The user; updated in place.
163
+ */
164
+ recordSignIn(user: UserEntity): Promise<void>;
165
+ /**
166
+ * Admin blocks an account. The reason is kept for support staff. Signs the user out everywhere.
167
+ *
168
+ * @param userId - The user to suspend.
169
+ * @param reason - Why (kept for support staff, not shown to the user).
170
+ * @param adminUserId - The admin doing it (for the audit log).
171
+ * @param request - Who is asking.
172
+ * @returns The updated user.
173
+ */
174
+ suspendUser(userId: string, reason: string, adminUserId: string, request: RequestContext): Promise<UserEntity>;
175
+ /**
176
+ * Admin lifts a suspension. The account goes back to ACTIVE (or PENDING_VERIFICATION if still unverified).
177
+ *
178
+ * @param userId - The suspended user.
179
+ * @param adminUserId - The admin doing it (for the audit log).
180
+ * @param settings - The current settings.
181
+ * @param request - Who is asking.
182
+ * @returns The updated user (unchanged if it wasn't suspended).
183
+ */
184
+ liftSuspension(userId: string, adminUserId: string, settings: AuthSettings, request: RequestContext): Promise<UserEntity>;
185
+ /**
186
+ * The user switches their own account off for a while. Signs them out everywhere.
187
+ * They can switch it back on by signing in again.
188
+ *
189
+ * @param userId - The signed-in user.
190
+ * @param request - Who is asking (for the audit log).
191
+ * @throws AuthError ACCOUNT_SUSPENDED when an admin has suspended the account.
192
+ */
193
+ deactivateAccount(userId: string, request: RequestContext): Promise<void>;
194
+ /**
195
+ * The user switches their account back on (after proving who they are, see SignInService).
196
+ *
197
+ * @param userId - The deactivated user.
198
+ * @param settings - The current settings.
199
+ * @param request - Who is asking (for the audit log).
200
+ * @returns The updated user.
201
+ * @throws AuthError ACCOUNT_NOT_DEACTIVATED when the account isn't deactivated.
202
+ */
203
+ reactivateAccount(userId: string, settings: AuthSettings, request: RequestContext): Promise<UserEntity>;
204
+ /**
205
+ * Deletes the account. The row stays (so ids in your other tables don't dangle and the audit log
206
+ * still makes sense), but every piece of personal data and every way to sign in is wiped.
207
+ * This cannot be undone.
208
+ *
209
+ * @param userId - The user to delete.
210
+ * @param performedBy - Who did it, for the audit log (null when it was the user).
211
+ * @param request - Who is asking.
212
+ */
213
+ deleteUser(userId: string, performedBy: string | null, request: RequestContext): Promise<void>;
214
+ /**
215
+ * The user as your app may show it. Never includes secrets.
216
+ *
217
+ * @param user - The user.
218
+ * @param settings - The current settings (to work out pending verifications).
219
+ * @returns The profile to send to the client.
220
+ */
221
+ toPublicProfile(user: UserEntity, settings: AuthSettings): PublicUserProfile;
222
+ /**
223
+ * Where a returning (unsuspended / reactivated) account lands: ACTIVE, unless verification is still owed.
224
+ *
225
+ * @param user - The returning user.
226
+ * @param settings - The current settings.
227
+ * @returns ACTIVE or PENDING_VERIFICATION.
228
+ */
229
+ private statusAfterReturning;
230
+ /**
231
+ * Changes the status only if it is still `expectedStatus` (so two admins clicking at once can't
232
+ * clash). Updates `user` in place.
233
+ *
234
+ * @param user - The user to change.
235
+ * @param expectedStatus - The status the user must still have.
236
+ * @param newStatus - The status to set.
237
+ * @param extraColumns - Other columns to change in the same UPDATE.
238
+ * @returns False if someone else changed it first.
239
+ */
240
+ private changeStatus;
241
+ /**
242
+ * @param error - An error thrown by the database.
243
+ * @returns True when Postgres refused a duplicate value (e.g. an email that is already taken).
244
+ */
245
+ private isUniqueViolation;
246
+ }