@robelest/convex-auth 0.0.4-preview.2 → 0.0.4-preview.21

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 (798) hide show
  1. package/README.md +67 -26
  2. package/dist/authorization/index.d.ts +63 -0
  3. package/dist/authorization/index.d.ts.map +1 -0
  4. package/dist/authorization/index.js +63 -0
  5. package/dist/authorization/index.js.map +1 -0
  6. package/dist/bin.js +6185 -0
  7. package/dist/client/core/types.d.ts +20 -0
  8. package/dist/client/core/types.d.ts.map +1 -0
  9. package/dist/client/index.d.ts +2 -299
  10. package/dist/client/index.d.ts.map +1 -1
  11. package/dist/client/index.js +407 -534
  12. package/dist/client/index.js.map +1 -1
  13. package/dist/component/_generated/api.d.ts +42 -0
  14. package/dist/component/_generated/api.d.ts.map +1 -1
  15. package/dist/component/_generated/api.js.map +1 -1
  16. package/dist/component/_generated/component.d.ts +2546 -90
  17. package/dist/component/_generated/component.d.ts.map +1 -1
  18. package/dist/component/client/core/types.d.ts +2 -0
  19. package/dist/component/client/index.d.ts +2 -0
  20. package/dist/component/convex.config.d.ts +2 -2
  21. package/dist/component/functions.d.ts +11 -9
  22. package/dist/component/functions.d.ts.map +1 -1
  23. package/dist/component/functions.js.map +1 -1
  24. package/dist/component/index.d.ts +7 -11
  25. package/dist/component/index.js +2 -3
  26. package/dist/component/model.d.ts +153 -0
  27. package/dist/component/model.d.ts.map +1 -0
  28. package/dist/component/model.js +349 -0
  29. package/dist/component/model.js.map +1 -0
  30. package/dist/component/providers/anonymous.d.ts +54 -0
  31. package/dist/component/providers/anonymous.d.ts.map +1 -0
  32. package/dist/component/providers/credentials.d.ts +5 -5
  33. package/dist/component/providers/credentials.d.ts.map +1 -1
  34. package/dist/component/providers/device.d.ts +67 -0
  35. package/dist/component/providers/device.d.ts.map +1 -0
  36. package/dist/component/providers/email.d.ts +62 -0
  37. package/dist/component/providers/email.d.ts.map +1 -0
  38. package/dist/component/providers/oauth.d.ts.map +1 -1
  39. package/dist/component/providers/oauth.js.map +1 -1
  40. package/dist/component/providers/passkey.d.ts +57 -0
  41. package/dist/component/providers/passkey.d.ts.map +1 -0
  42. package/dist/component/providers/password.d.ts +88 -0
  43. package/dist/component/providers/password.d.ts.map +1 -0
  44. package/dist/component/providers/phone.d.ts +48 -0
  45. package/dist/component/providers/phone.d.ts.map +1 -0
  46. package/dist/component/providers/sso.d.ts +50 -0
  47. package/dist/component/providers/sso.d.ts.map +1 -0
  48. package/dist/component/providers/totp.d.ts +45 -0
  49. package/dist/component/providers/totp.d.ts.map +1 -0
  50. package/dist/component/public/enterprise/audit.d.ts +73 -0
  51. package/dist/component/public/enterprise/audit.d.ts.map +1 -0
  52. package/dist/component/public/enterprise/audit.js +108 -0
  53. package/dist/component/public/enterprise/audit.js.map +1 -0
  54. package/dist/component/public/enterprise/core.d.ts +176 -0
  55. package/dist/component/public/enterprise/core.d.ts.map +1 -0
  56. package/dist/component/public/enterprise/core.js +292 -0
  57. package/dist/component/public/enterprise/core.js.map +1 -0
  58. package/dist/component/public/enterprise/domains.d.ts +174 -0
  59. package/dist/component/public/enterprise/domains.d.ts.map +1 -0
  60. package/dist/component/public/enterprise/domains.js +271 -0
  61. package/dist/component/public/enterprise/domains.js.map +1 -0
  62. package/dist/component/public/enterprise/scim.d.ts +245 -0
  63. package/dist/component/public/enterprise/scim.d.ts.map +1 -0
  64. package/dist/component/public/enterprise/scim.js +344 -0
  65. package/dist/component/public/enterprise/scim.js.map +1 -0
  66. package/dist/component/public/enterprise/secrets.d.ts +78 -0
  67. package/dist/component/public/enterprise/secrets.d.ts.map +1 -0
  68. package/dist/component/public/enterprise/secrets.js +118 -0
  69. package/dist/component/public/enterprise/secrets.js.map +1 -0
  70. package/dist/component/public/enterprise/webhooks.d.ts +211 -0
  71. package/dist/component/public/enterprise/webhooks.d.ts.map +1 -0
  72. package/dist/component/public/enterprise/webhooks.js +300 -0
  73. package/dist/component/public/enterprise/webhooks.js.map +1 -0
  74. package/dist/component/public/factors/devices.d.ts +157 -0
  75. package/dist/component/public/factors/devices.d.ts.map +1 -0
  76. package/dist/component/public/factors/devices.js +216 -0
  77. package/dist/component/public/factors/devices.js.map +1 -0
  78. package/dist/component/public/factors/passkeys.d.ts +175 -0
  79. package/dist/component/public/factors/passkeys.d.ts.map +1 -0
  80. package/dist/component/public/factors/passkeys.js +238 -0
  81. package/dist/component/public/factors/passkeys.js.map +1 -0
  82. package/dist/component/public/factors/totp.d.ts +189 -0
  83. package/dist/component/public/factors/totp.d.ts.map +1 -0
  84. package/dist/component/public/factors/totp.js +254 -0
  85. package/dist/component/public/factors/totp.js.map +1 -0
  86. package/dist/component/public/groups/core.d.ts +137 -0
  87. package/dist/component/public/groups/core.d.ts.map +1 -0
  88. package/dist/component/public/groups/core.js +321 -0
  89. package/dist/component/public/groups/core.js.map +1 -0
  90. package/dist/component/public/groups/invites.d.ts +217 -0
  91. package/dist/component/public/groups/invites.d.ts.map +1 -0
  92. package/dist/component/public/groups/invites.js +457 -0
  93. package/dist/component/public/groups/invites.js.map +1 -0
  94. package/dist/component/public/groups/members.d.ts +204 -0
  95. package/dist/component/public/groups/members.d.ts.map +1 -0
  96. package/dist/component/public/groups/members.js +355 -0
  97. package/dist/component/public/groups/members.js.map +1 -0
  98. package/dist/component/public/identity/accounts.d.ts +147 -0
  99. package/dist/component/public/identity/accounts.d.ts.map +1 -0
  100. package/dist/component/public/identity/accounts.js +200 -0
  101. package/dist/component/public/identity/accounts.js.map +1 -0
  102. package/dist/component/public/identity/codes.d.ts +104 -0
  103. package/dist/component/public/identity/codes.d.ts.map +1 -0
  104. package/dist/component/public/identity/codes.js +140 -0
  105. package/dist/component/public/identity/codes.js.map +1 -0
  106. package/dist/component/public/identity/sessions.d.ts +128 -0
  107. package/dist/component/public/identity/sessions.d.ts.map +1 -0
  108. package/dist/component/public/identity/sessions.js +192 -0
  109. package/dist/component/public/identity/sessions.js.map +1 -0
  110. package/dist/component/public/identity/tokens.d.ts +169 -0
  111. package/dist/component/public/identity/tokens.d.ts.map +1 -0
  112. package/dist/component/public/identity/tokens.js +227 -0
  113. package/dist/component/public/identity/tokens.js.map +1 -0
  114. package/dist/component/public/identity/users.d.ts +212 -0
  115. package/dist/component/public/identity/users.d.ts.map +1 -0
  116. package/dist/component/public/identity/users.js +311 -0
  117. package/dist/component/public/identity/users.js.map +1 -0
  118. package/dist/component/public/identity/verifiers.d.ts +116 -0
  119. package/dist/component/public/identity/verifiers.d.ts.map +1 -0
  120. package/dist/component/public/identity/verifiers.js +154 -0
  121. package/dist/component/public/identity/verifiers.js.map +1 -0
  122. package/dist/component/public/security/keys.d.ts +209 -0
  123. package/dist/component/public/security/keys.d.ts.map +1 -0
  124. package/dist/component/public/security/keys.js +319 -0
  125. package/dist/component/public/security/keys.js.map +1 -0
  126. package/dist/component/public/security/limits.d.ts +114 -0
  127. package/dist/component/public/security/limits.d.ts.map +1 -0
  128. package/dist/component/public/security/limits.js +169 -0
  129. package/dist/component/public/security/limits.js.map +1 -0
  130. package/dist/component/public.d.ts +24 -271
  131. package/dist/component/public.d.ts.map +1 -1
  132. package/dist/component/public.js +21 -1229
  133. package/dist/component/schema.d.ts +473 -110
  134. package/dist/component/schema.js +162 -73
  135. package/dist/component/schema.js.map +1 -1
  136. package/dist/component/server/auth.d.ts +318 -373
  137. package/dist/component/server/auth.d.ts.map +1 -1
  138. package/dist/component/server/auth.js +204 -123
  139. package/dist/component/server/auth.js.map +1 -1
  140. package/dist/component/server/authError.js +34 -0
  141. package/dist/component/server/authError.js.map +1 -0
  142. package/dist/component/server/{providers.js → config.js} +43 -12
  143. package/dist/component/server/config.js.map +1 -0
  144. package/dist/component/server/cookies.js +3 -0
  145. package/dist/component/server/cookies.js.map +1 -1
  146. package/dist/component/server/core.js +713 -0
  147. package/dist/component/server/core.js.map +1 -0
  148. package/dist/component/server/crypto.js +38 -0
  149. package/dist/component/server/crypto.js.map +1 -0
  150. package/dist/component/server/{implementation/db.js → db.js} +2 -1
  151. package/dist/component/server/db.js.map +1 -0
  152. package/dist/component/server/device.js +109 -0
  153. package/dist/component/server/device.js.map +1 -0
  154. package/dist/component/server/enterprise/config.js +46 -0
  155. package/dist/component/server/enterprise/config.js.map +1 -0
  156. package/dist/component/server/enterprise/domain.js +885 -0
  157. package/dist/component/server/enterprise/domain.js.map +1 -0
  158. package/dist/component/server/enterprise/http.js +766 -0
  159. package/dist/component/server/enterprise/http.js.map +1 -0
  160. package/dist/component/server/enterprise/oidc.js +248 -0
  161. package/dist/component/server/enterprise/oidc.js.map +1 -0
  162. package/dist/component/server/enterprise/policy.js +85 -0
  163. package/dist/component/server/enterprise/policy.js.map +1 -0
  164. package/dist/component/server/enterprise/saml.js +338 -0
  165. package/dist/component/server/enterprise/saml.js.map +1 -0
  166. package/dist/component/server/enterprise/scim.js +97 -0
  167. package/dist/component/server/enterprise/scim.js.map +1 -0
  168. package/dist/component/server/enterprise/shared.js +51 -0
  169. package/dist/component/server/enterprise/shared.js.map +1 -0
  170. package/dist/component/server/errors.d.ts +1 -0
  171. package/dist/component/server/errors.js +24 -16
  172. package/dist/component/server/errors.js.map +1 -1
  173. package/dist/component/server/http.js +288 -0
  174. package/dist/component/server/http.js.map +1 -0
  175. package/dist/component/server/identity.js +13 -0
  176. package/dist/component/server/identity.js.map +1 -0
  177. package/dist/{server/implementation → component/server}/keys.js +9 -31
  178. package/dist/component/server/keys.js.map +1 -0
  179. package/dist/component/server/limits.js +61 -0
  180. package/dist/component/server/limits.js.map +1 -0
  181. package/dist/component/server/mutations/account.js +44 -0
  182. package/dist/component/server/mutations/account.js.map +1 -0
  183. package/dist/component/server/{implementation/mutations → mutations}/code.js +7 -4
  184. package/dist/component/server/mutations/code.js.map +1 -0
  185. package/dist/component/server/mutations/invalidate.js +32 -0
  186. package/dist/component/server/mutations/invalidate.js.map +1 -0
  187. package/dist/component/server/mutations/oauth.js +110 -0
  188. package/dist/component/server/mutations/oauth.js.map +1 -0
  189. package/dist/component/server/mutations/refresh.js +119 -0
  190. package/dist/component/server/mutations/refresh.js.map +1 -0
  191. package/dist/component/server/mutations/register.js +83 -0
  192. package/dist/component/server/mutations/register.js.map +1 -0
  193. package/dist/component/server/mutations/retrieve.js +65 -0
  194. package/dist/component/server/mutations/retrieve.js.map +1 -0
  195. package/dist/component/server/mutations/signature.js +32 -0
  196. package/dist/component/server/mutations/signature.js.map +1 -0
  197. package/dist/component/server/{implementation/mutations → mutations}/signin.js +2 -2
  198. package/dist/component/server/mutations/signin.js.map +1 -0
  199. package/dist/component/server/mutations/signout.js +27 -0
  200. package/dist/component/server/mutations/signout.js.map +1 -0
  201. package/dist/component/server/mutations/store/refs.js +15 -0
  202. package/dist/component/server/mutations/store/refs.js.map +1 -0
  203. package/dist/component/server/mutations/store.js +85 -0
  204. package/dist/component/server/mutations/store.js.map +1 -0
  205. package/dist/component/server/mutations/verifier.js +18 -0
  206. package/dist/component/server/mutations/verifier.js.map +1 -0
  207. package/dist/component/server/mutations/verify.js +98 -0
  208. package/dist/component/server/mutations/verify.js.map +1 -0
  209. package/dist/component/server/oauth.js +106 -60
  210. package/dist/component/server/oauth.js.map +1 -1
  211. package/dist/component/server/passkey.js +328 -0
  212. package/dist/component/server/passkey.js.map +1 -0
  213. package/dist/{server/implementation → component/server}/redirects.js +13 -11
  214. package/dist/component/server/redirects.js.map +1 -0
  215. package/dist/component/server/refresh.js +96 -0
  216. package/dist/component/server/refresh.js.map +1 -0
  217. package/dist/component/server/runtime.d.ts +136 -0
  218. package/dist/component/server/runtime.d.ts.map +1 -0
  219. package/dist/component/server/runtime.js +413 -0
  220. package/dist/component/server/runtime.js.map +1 -0
  221. package/dist/{server/implementation → component/server}/sessions.js +14 -8
  222. package/dist/component/server/sessions.js.map +1 -0
  223. package/dist/component/server/signin.js +201 -0
  224. package/dist/component/server/signin.js.map +1 -0
  225. package/dist/component/server/tokens.js +17 -0
  226. package/dist/component/server/tokens.js.map +1 -0
  227. package/dist/component/server/totp.js +148 -0
  228. package/dist/component/server/totp.js.map +1 -0
  229. package/dist/component/server/types.d.ts +387 -298
  230. package/dist/component/server/types.d.ts.map +1 -1
  231. package/dist/component/server/{implementation/types.js → types.js} +1 -1
  232. package/dist/component/server/types.js.map +1 -0
  233. package/dist/component/server/{implementation/users.js → users.js} +54 -35
  234. package/dist/component/server/users.js.map +1 -0
  235. package/dist/component/server/utils.js +110 -4
  236. package/dist/component/server/utils.js.map +1 -1
  237. package/dist/core/types.d.ts +369 -0
  238. package/dist/core/types.d.ts.map +1 -0
  239. package/dist/factors/device.js +105 -0
  240. package/dist/factors/device.js.map +1 -0
  241. package/dist/factors/passkey.js +181 -0
  242. package/dist/factors/passkey.js.map +1 -0
  243. package/dist/factors/totp.js +122 -0
  244. package/dist/factors/totp.js.map +1 -0
  245. package/dist/providers/anonymous.d.ts +3 -9
  246. package/dist/providers/anonymous.d.ts.map +1 -1
  247. package/dist/providers/anonymous.js +1 -18
  248. package/dist/providers/anonymous.js.map +1 -1
  249. package/dist/providers/credentials.d.ts +8 -10
  250. package/dist/providers/credentials.d.ts.map +1 -1
  251. package/dist/providers/credentials.js +3 -5
  252. package/dist/providers/credentials.js.map +1 -1
  253. package/dist/providers/device.d.ts +18 -10
  254. package/dist/providers/device.d.ts.map +1 -1
  255. package/dist/providers/device.js +4 -8
  256. package/dist/providers/device.js.map +1 -1
  257. package/dist/providers/email.d.ts +50 -23
  258. package/dist/providers/email.d.ts.map +1 -1
  259. package/dist/providers/email.js +58 -34
  260. package/dist/providers/email.js.map +1 -1
  261. package/dist/providers/index.d.ts +7 -3
  262. package/dist/providers/index.js +4 -1
  263. package/dist/providers/oauth.d.ts.map +1 -1
  264. package/dist/providers/oauth.js.map +1 -1
  265. package/dist/providers/passkey.d.ts +12 -9
  266. package/dist/providers/passkey.d.ts.map +1 -1
  267. package/dist/providers/passkey.js +1 -7
  268. package/dist/providers/passkey.js.map +1 -1
  269. package/dist/providers/password.d.ts +6 -12
  270. package/dist/providers/password.d.ts.map +1 -1
  271. package/dist/providers/password.js +189 -89
  272. package/dist/providers/password.js.map +1 -1
  273. package/dist/providers/phone.d.ts +40 -11
  274. package/dist/providers/phone.d.ts.map +1 -1
  275. package/dist/providers/phone.js +52 -21
  276. package/dist/providers/phone.js.map +1 -1
  277. package/dist/providers/sso.d.ts +50 -0
  278. package/dist/providers/sso.d.ts.map +1 -0
  279. package/dist/providers/sso.js +34 -0
  280. package/dist/providers/sso.js.map +1 -0
  281. package/dist/providers/totp.d.ts +12 -9
  282. package/dist/providers/totp.d.ts.map +1 -1
  283. package/dist/providers/totp.js +1 -7
  284. package/dist/providers/totp.js.map +1 -1
  285. package/dist/runtime/browser.js +68 -0
  286. package/dist/runtime/browser.js.map +1 -0
  287. package/dist/runtime/invite.js +51 -0
  288. package/dist/runtime/invite.js.map +1 -0
  289. package/dist/runtime/proxy.js +70 -0
  290. package/dist/runtime/proxy.js.map +1 -0
  291. package/dist/runtime/storage.js +37 -0
  292. package/dist/runtime/storage.js.map +1 -0
  293. package/dist/server/auth.d.ts +335 -370
  294. package/dist/server/auth.d.ts.map +1 -1
  295. package/dist/server/auth.js +204 -123
  296. package/dist/server/auth.js.map +1 -1
  297. package/dist/server/authError.d.ts +46 -0
  298. package/dist/server/authError.d.ts.map +1 -0
  299. package/dist/server/authError.js +34 -0
  300. package/dist/server/authError.js.map +1 -0
  301. package/dist/server/config.d.ts +1 -0
  302. package/dist/server/{providers.js → config.js} +43 -12
  303. package/dist/server/config.js.map +1 -0
  304. package/dist/server/cookies.d.ts +1 -38
  305. package/dist/server/cookies.js +3 -0
  306. package/dist/server/cookies.js.map +1 -1
  307. package/dist/server/core.d.ts +1436 -0
  308. package/dist/server/core.d.ts.map +1 -0
  309. package/dist/server/core.js +713 -0
  310. package/dist/server/core.js.map +1 -0
  311. package/dist/server/crypto.d.ts +8 -0
  312. package/dist/server/crypto.d.ts.map +1 -0
  313. package/dist/server/crypto.js +38 -0
  314. package/dist/server/crypto.js.map +1 -0
  315. package/dist/server/db.d.ts +1 -0
  316. package/dist/server/{implementation/db.js → db.js} +2 -1
  317. package/dist/server/db.js.map +1 -0
  318. package/dist/server/device.d.ts +1 -0
  319. package/dist/server/device.js +109 -0
  320. package/dist/server/device.js.map +1 -0
  321. package/dist/server/enterprise/config.d.ts +1 -0
  322. package/dist/server/enterprise/config.js +46 -0
  323. package/dist/server/enterprise/config.js.map +1 -0
  324. package/dist/server/enterprise/domain.d.ts +409 -0
  325. package/dist/server/enterprise/domain.d.ts.map +1 -0
  326. package/dist/server/enterprise/domain.js +885 -0
  327. package/dist/server/enterprise/domain.js.map +1 -0
  328. package/dist/server/enterprise/http.d.ts +26 -0
  329. package/dist/server/enterprise/http.d.ts.map +1 -0
  330. package/dist/server/enterprise/http.js +766 -0
  331. package/dist/server/enterprise/http.js.map +1 -0
  332. package/dist/server/enterprise/oidc.d.ts +1 -0
  333. package/dist/server/enterprise/oidc.js +248 -0
  334. package/dist/server/enterprise/oidc.js.map +1 -0
  335. package/dist/server/enterprise/policy.d.ts +1 -0
  336. package/dist/server/enterprise/policy.js +85 -0
  337. package/dist/server/enterprise/policy.js.map +1 -0
  338. package/dist/server/enterprise/saml.d.ts +1 -0
  339. package/dist/server/enterprise/saml.js +338 -0
  340. package/dist/server/enterprise/saml.js.map +1 -0
  341. package/dist/server/enterprise/scim.d.ts +1 -0
  342. package/dist/server/enterprise/scim.js +97 -0
  343. package/dist/server/enterprise/scim.js.map +1 -0
  344. package/dist/server/enterprise/shared.d.ts +5 -0
  345. package/dist/server/enterprise/shared.d.ts.map +1 -0
  346. package/dist/server/enterprise/shared.js +51 -0
  347. package/dist/server/enterprise/shared.js.map +1 -0
  348. package/dist/server/enterprise/validators.d.ts +1 -0
  349. package/dist/server/enterprise/validators.js +60 -0
  350. package/dist/server/enterprise/validators.js.map +1 -0
  351. package/dist/server/errors.d.ts +33 -1
  352. package/dist/server/errors.d.ts.map +1 -1
  353. package/dist/server/errors.js +44 -1
  354. package/dist/server/errors.js.map +1 -1
  355. package/dist/server/http.d.ts +59 -0
  356. package/dist/server/http.d.ts.map +1 -0
  357. package/dist/server/http.js +288 -0
  358. package/dist/server/http.js.map +1 -0
  359. package/dist/server/identity.d.ts +1 -0
  360. package/dist/server/identity.js +13 -0
  361. package/dist/server/identity.js.map +1 -0
  362. package/dist/server/index.d.ts +4 -182
  363. package/dist/server/index.js +4 -376
  364. package/dist/server/keys.d.ts +1 -0
  365. package/dist/{component/server/implementation → server}/keys.js +9 -31
  366. package/dist/server/keys.js.map +1 -0
  367. package/dist/server/limits.d.ts +1 -0
  368. package/dist/server/limits.js +61 -0
  369. package/dist/server/limits.js.map +1 -0
  370. package/dist/server/mounts.d.ts +647 -0
  371. package/dist/server/mounts.d.ts.map +1 -0
  372. package/dist/server/mounts.js +643 -0
  373. package/dist/server/mounts.js.map +1 -0
  374. package/dist/server/mutations/account.d.ts +30 -0
  375. package/dist/server/mutations/account.d.ts.map +1 -0
  376. package/dist/server/mutations/account.js +44 -0
  377. package/dist/server/mutations/account.js.map +1 -0
  378. package/dist/server/mutations/code.d.ts +30 -0
  379. package/dist/server/mutations/code.d.ts.map +1 -0
  380. package/dist/server/{implementation/mutations → mutations}/code.js +7 -4
  381. package/dist/server/mutations/code.js.map +1 -0
  382. package/dist/server/mutations/index.d.ts +14 -0
  383. package/dist/server/mutations/index.js +15 -0
  384. package/dist/server/mutations/invalidate.d.ts +20 -0
  385. package/dist/server/mutations/invalidate.d.ts.map +1 -0
  386. package/dist/server/mutations/invalidate.js +32 -0
  387. package/dist/server/mutations/invalidate.js.map +1 -0
  388. package/dist/server/mutations/oauth.d.ts +28 -0
  389. package/dist/server/mutations/oauth.d.ts.map +1 -0
  390. package/dist/server/mutations/oauth.js +110 -0
  391. package/dist/server/mutations/oauth.js.map +1 -0
  392. package/dist/server/mutations/refresh.d.ts +21 -0
  393. package/dist/server/mutations/refresh.d.ts.map +1 -0
  394. package/dist/server/mutations/refresh.js +119 -0
  395. package/dist/server/mutations/refresh.js.map +1 -0
  396. package/dist/server/mutations/register.d.ts +38 -0
  397. package/dist/server/mutations/register.d.ts.map +1 -0
  398. package/dist/server/mutations/register.js +83 -0
  399. package/dist/server/mutations/register.js.map +1 -0
  400. package/dist/server/mutations/retrieve.d.ts +33 -0
  401. package/dist/server/mutations/retrieve.d.ts.map +1 -0
  402. package/dist/server/mutations/retrieve.js +65 -0
  403. package/dist/server/mutations/retrieve.js.map +1 -0
  404. package/dist/server/mutations/signature.d.ts +22 -0
  405. package/dist/server/mutations/signature.d.ts.map +1 -0
  406. package/dist/server/mutations/signature.js +32 -0
  407. package/dist/server/mutations/signature.js.map +1 -0
  408. package/dist/server/mutations/signin.d.ts +22 -0
  409. package/dist/server/mutations/signin.d.ts.map +1 -0
  410. package/dist/server/{implementation/mutations → mutations}/signin.js +2 -2
  411. package/dist/server/mutations/signin.js.map +1 -0
  412. package/dist/server/mutations/signout.d.ts +16 -0
  413. package/dist/server/mutations/signout.d.ts.map +1 -0
  414. package/dist/server/mutations/signout.js +27 -0
  415. package/dist/server/mutations/signout.js.map +1 -0
  416. package/dist/server/mutations/store/refs.d.ts +12 -0
  417. package/dist/server/mutations/store/refs.d.ts.map +1 -0
  418. package/dist/server/mutations/store/refs.js +15 -0
  419. package/dist/server/mutations/store/refs.js.map +1 -0
  420. package/dist/server/mutations/store.d.ts +306 -0
  421. package/dist/server/mutations/store.d.ts.map +1 -0
  422. package/dist/server/mutations/store.js +85 -0
  423. package/dist/server/mutations/store.js.map +1 -0
  424. package/dist/server/mutations/verifier.d.ts +13 -0
  425. package/dist/server/mutations/verifier.d.ts.map +1 -0
  426. package/dist/server/mutations/verifier.js +18 -0
  427. package/dist/server/mutations/verifier.js.map +1 -0
  428. package/dist/server/mutations/verify.d.ts +26 -0
  429. package/dist/server/mutations/verify.d.ts.map +1 -0
  430. package/dist/server/mutations/verify.js +98 -0
  431. package/dist/server/mutations/verify.js.map +1 -0
  432. package/dist/server/oauth.d.ts +1 -48
  433. package/dist/server/oauth.js +107 -64
  434. package/dist/server/oauth.js.map +1 -1
  435. package/dist/server/passkey.d.ts +27 -0
  436. package/dist/server/passkey.d.ts.map +1 -0
  437. package/dist/server/passkey.js +328 -0
  438. package/dist/server/passkey.js.map +1 -0
  439. package/dist/server/redirects.d.ts +1 -0
  440. package/dist/{component/server/implementation → server}/redirects.js +13 -11
  441. package/dist/server/redirects.js.map +1 -0
  442. package/dist/server/refresh.d.ts +1 -0
  443. package/dist/server/refresh.js +96 -0
  444. package/dist/server/refresh.js.map +1 -0
  445. package/dist/server/runtime.d.ts +136 -0
  446. package/dist/server/runtime.d.ts.map +1 -0
  447. package/dist/server/runtime.js +413 -0
  448. package/dist/server/runtime.js.map +1 -0
  449. package/dist/server/sessions.d.ts +1 -0
  450. package/dist/{component/server/implementation → server}/sessions.js +14 -8
  451. package/dist/server/sessions.js.map +1 -0
  452. package/dist/server/signin.d.ts +1 -0
  453. package/dist/server/signin.js +201 -0
  454. package/dist/server/signin.js.map +1 -0
  455. package/dist/server/ssr.d.ts +226 -0
  456. package/dist/server/ssr.d.ts.map +1 -0
  457. package/dist/server/ssr.js +786 -0
  458. package/dist/server/ssr.js.map +1 -0
  459. package/dist/server/templates.d.ts +1 -21
  460. package/dist/server/templates.js +2 -1
  461. package/dist/server/templates.js.map +1 -1
  462. package/dist/server/tokens.d.ts +1 -0
  463. package/dist/server/tokens.js +17 -0
  464. package/dist/server/tokens.js.map +1 -0
  465. package/dist/server/totp.d.ts +1 -0
  466. package/dist/server/totp.js +148 -0
  467. package/dist/server/totp.js.map +1 -0
  468. package/dist/server/types.d.ts +498 -306
  469. package/dist/server/types.d.ts.map +1 -1
  470. package/dist/server/types.js +108 -1
  471. package/dist/server/types.js.map +1 -0
  472. package/dist/server/users.d.ts +1 -0
  473. package/dist/server/{implementation/users.js → users.js} +54 -35
  474. package/dist/server/users.js.map +1 -0
  475. package/dist/server/utils.d.ts +1 -6
  476. package/dist/server/utils.js +110 -4
  477. package/dist/server/utils.js.map +1 -1
  478. package/package.json +49 -46
  479. package/src/authorization/index.ts +83 -0
  480. package/src/cli/bin.ts +5 -0
  481. package/src/cli/command.ts +6 -5
  482. package/src/cli/index.ts +456 -248
  483. package/src/cli/keys.ts +3 -0
  484. package/src/client/core/types.ts +437 -0
  485. package/src/client/factors/device.ts +160 -0
  486. package/src/client/factors/passkey.ts +282 -0
  487. package/src/client/factors/totp.ts +150 -0
  488. package/src/client/index.ts +745 -989
  489. package/src/client/runtime/browser.ts +112 -0
  490. package/src/client/runtime/invite.ts +65 -0
  491. package/src/client/runtime/proxy.ts +111 -0
  492. package/src/client/runtime/storage.ts +79 -0
  493. package/src/component/_generated/api.ts +42 -0
  494. package/src/component/_generated/component.ts +3123 -102
  495. package/src/component/functions.ts +38 -22
  496. package/src/component/index.ts +10 -20
  497. package/src/component/model.ts +449 -0
  498. package/src/component/public/enterprise/audit.ts +120 -0
  499. package/src/component/public/enterprise/core.ts +354 -0
  500. package/src/component/public/enterprise/domains.ts +323 -0
  501. package/src/component/public/enterprise/scim.ts +396 -0
  502. package/src/component/public/enterprise/secrets.ts +132 -0
  503. package/src/component/public/enterprise/webhooks.ts +306 -0
  504. package/src/component/public/factors/devices.ts +223 -0
  505. package/src/component/public/factors/passkeys.ts +242 -0
  506. package/src/component/public/factors/totp.ts +258 -0
  507. package/src/component/public/groups/core.ts +481 -0
  508. package/src/component/public/groups/invites.ts +602 -0
  509. package/src/component/public/groups/members.ts +409 -0
  510. package/src/component/public/identity/accounts.ts +206 -0
  511. package/src/component/public/identity/codes.ts +148 -0
  512. package/src/component/public/identity/sessions.ts +209 -0
  513. package/src/component/public/identity/tokens.ts +250 -0
  514. package/src/component/public/identity/users.ts +354 -0
  515. package/src/component/public/identity/verifiers.ts +157 -0
  516. package/src/component/public/security/keys.ts +365 -0
  517. package/src/component/public/security/limits.ts +173 -0
  518. package/src/component/public.ts +26 -1766
  519. package/src/component/schema.ts +273 -100
  520. package/src/providers/anonymous.ts +10 -20
  521. package/src/providers/credentials.ts +14 -22
  522. package/src/providers/device.ts +3 -14
  523. package/src/providers/email.ts +83 -47
  524. package/src/providers/index.ts +7 -0
  525. package/src/providers/oauth.ts +5 -3
  526. package/src/providers/passkey.ts +0 -13
  527. package/src/providers/password.ts +307 -130
  528. package/src/providers/phone.ts +81 -37
  529. package/src/providers/sso.ts +54 -0
  530. package/src/providers/totp.ts +0 -13
  531. package/src/samlify.d.ts +53 -0
  532. package/src/server/auth.ts +701 -247
  533. package/src/server/authError.ts +44 -0
  534. package/src/server/{providers.ts → config.ts} +84 -15
  535. package/src/server/cookies.ts +8 -1
  536. package/src/server/core.ts +2095 -0
  537. package/src/server/crypto.ts +88 -0
  538. package/src/server/{implementation/db.ts → db.ts} +90 -15
  539. package/src/server/device.ts +221 -0
  540. package/src/server/enterprise/config.ts +51 -0
  541. package/src/server/enterprise/domain.ts +1751 -0
  542. package/src/server/enterprise/http.ts +1324 -0
  543. package/src/server/enterprise/oidc.ts +500 -0
  544. package/src/server/enterprise/policy.ts +128 -0
  545. package/src/server/enterprise/saml.ts +578 -0
  546. package/src/server/enterprise/scim.ts +135 -0
  547. package/src/server/enterprise/shared.ts +134 -0
  548. package/src/server/enterprise/validators.ts +93 -0
  549. package/src/server/errors.ts +130 -119
  550. package/src/server/http.ts +531 -0
  551. package/src/server/identity.ts +18 -0
  552. package/src/server/index.ts +32 -650
  553. package/src/server/{implementation/keys.ts → keys.ts} +16 -44
  554. package/src/server/limits.ts +134 -0
  555. package/src/server/mounts.ts +948 -0
  556. package/src/server/mutations/account.ts +76 -0
  557. package/src/server/{implementation/mutations → mutations}/code.ts +22 -11
  558. package/src/server/mutations/index.ts +13 -0
  559. package/src/server/mutations/invalidate.ts +50 -0
  560. package/src/server/mutations/oauth.ts +237 -0
  561. package/src/server/mutations/refresh.ts +298 -0
  562. package/src/server/mutations/register.ts +200 -0
  563. package/src/server/mutations/retrieve.ts +109 -0
  564. package/src/server/mutations/signature.ts +50 -0
  565. package/src/server/{implementation/mutations → mutations}/signin.ts +9 -7
  566. package/src/server/mutations/signout.ts +43 -0
  567. package/src/server/mutations/store/refs.ts +10 -0
  568. package/src/server/mutations/store.ts +138 -0
  569. package/src/server/mutations/verifier.ts +34 -0
  570. package/src/server/mutations/verify.ts +202 -0
  571. package/src/server/oauth.ts +243 -131
  572. package/src/server/passkey.ts +784 -0
  573. package/src/server/{implementation/redirects.ts → redirects.ts} +21 -16
  574. package/src/server/refresh.ts +222 -0
  575. package/src/server/runtime.ts +880 -0
  576. package/src/server/{implementation/sessions.ts → sessions.ts} +33 -25
  577. package/src/server/signin.ts +438 -0
  578. package/src/server/ssr.ts +1764 -0
  579. package/src/server/templates.ts +8 -3
  580. package/src/server/{implementation/tokens.ts → tokens.ts} +11 -5
  581. package/src/server/totp.ts +349 -0
  582. package/src/server/types.ts +972 -207
  583. package/src/server/{implementation/users.ts → users.ts} +129 -75
  584. package/src/server/utils.ts +192 -5
  585. package/src/test.ts +28 -4
  586. package/dist/bin.cjs +0 -27757
  587. package/dist/component/providers/email.js +0 -47
  588. package/dist/component/providers/email.js.map +0 -1
  589. package/dist/component/public.js.map +0 -1
  590. package/dist/component/server/implementation/db.js.map +0 -1
  591. package/dist/component/server/implementation/device.js +0 -135
  592. package/dist/component/server/implementation/device.js.map +0 -1
  593. package/dist/component/server/implementation/index.d.ts +0 -870
  594. package/dist/component/server/implementation/index.d.ts.map +0 -1
  595. package/dist/component/server/implementation/index.js +0 -610
  596. package/dist/component/server/implementation/index.js.map +0 -1
  597. package/dist/component/server/implementation/keys.js.map +0 -1
  598. package/dist/component/server/implementation/mutations/account.js +0 -39
  599. package/dist/component/server/implementation/mutations/account.js.map +0 -1
  600. package/dist/component/server/implementation/mutations/code.js.map +0 -1
  601. package/dist/component/server/implementation/mutations/index.js +0 -70
  602. package/dist/component/server/implementation/mutations/index.js.map +0 -1
  603. package/dist/component/server/implementation/mutations/invalidate.js +0 -29
  604. package/dist/component/server/implementation/mutations/invalidate.js.map +0 -1
  605. package/dist/component/server/implementation/mutations/oauth.js +0 -51
  606. package/dist/component/server/implementation/mutations/oauth.js.map +0 -1
  607. package/dist/component/server/implementation/mutations/refresh.js +0 -85
  608. package/dist/component/server/implementation/mutations/refresh.js.map +0 -1
  609. package/dist/component/server/implementation/mutations/register.js +0 -65
  610. package/dist/component/server/implementation/mutations/register.js.map +0 -1
  611. package/dist/component/server/implementation/mutations/retrieve.js +0 -50
  612. package/dist/component/server/implementation/mutations/retrieve.js.map +0 -1
  613. package/dist/component/server/implementation/mutations/signature.js +0 -27
  614. package/dist/component/server/implementation/mutations/signature.js.map +0 -1
  615. package/dist/component/server/implementation/mutations/signin.js.map +0 -1
  616. package/dist/component/server/implementation/mutations/signout.js +0 -27
  617. package/dist/component/server/implementation/mutations/signout.js.map +0 -1
  618. package/dist/component/server/implementation/mutations/store.js +0 -12
  619. package/dist/component/server/implementation/mutations/store.js.map +0 -1
  620. package/dist/component/server/implementation/mutations/verifier.js +0 -16
  621. package/dist/component/server/implementation/mutations/verifier.js.map +0 -1
  622. package/dist/component/server/implementation/mutations/verify.js +0 -105
  623. package/dist/component/server/implementation/mutations/verify.js.map +0 -1
  624. package/dist/component/server/implementation/passkey.js +0 -307
  625. package/dist/component/server/implementation/passkey.js.map +0 -1
  626. package/dist/component/server/implementation/provider.js +0 -19
  627. package/dist/component/server/implementation/provider.js.map +0 -1
  628. package/dist/component/server/implementation/ratelimit.js +0 -48
  629. package/dist/component/server/implementation/ratelimit.js.map +0 -1
  630. package/dist/component/server/implementation/redirects.js.map +0 -1
  631. package/dist/component/server/implementation/refresh.js +0 -109
  632. package/dist/component/server/implementation/refresh.js.map +0 -1
  633. package/dist/component/server/implementation/sessions.js.map +0 -1
  634. package/dist/component/server/implementation/signin.js +0 -148
  635. package/dist/component/server/implementation/signin.js.map +0 -1
  636. package/dist/component/server/implementation/tokens.js +0 -15
  637. package/dist/component/server/implementation/tokens.js.map +0 -1
  638. package/dist/component/server/implementation/totp.js +0 -142
  639. package/dist/component/server/implementation/totp.js.map +0 -1
  640. package/dist/component/server/implementation/types.d.ts +0 -42
  641. package/dist/component/server/implementation/types.d.ts.map +0 -1
  642. package/dist/component/server/implementation/types.js.map +0 -1
  643. package/dist/component/server/implementation/users.js.map +0 -1
  644. package/dist/component/server/implementation/utils.js +0 -56
  645. package/dist/component/server/implementation/utils.js.map +0 -1
  646. package/dist/component/server/providers.js.map +0 -1
  647. package/dist/component/server/templates.js +0 -84
  648. package/dist/component/server/templates.js.map +0 -1
  649. package/dist/server/cookies.d.ts.map +0 -1
  650. package/dist/server/implementation/db.d.ts +0 -86
  651. package/dist/server/implementation/db.d.ts.map +0 -1
  652. package/dist/server/implementation/db.js.map +0 -1
  653. package/dist/server/implementation/device.d.ts +0 -30
  654. package/dist/server/implementation/device.d.ts.map +0 -1
  655. package/dist/server/implementation/device.js +0 -135
  656. package/dist/server/implementation/device.js.map +0 -1
  657. package/dist/server/implementation/index.d.ts +0 -870
  658. package/dist/server/implementation/index.d.ts.map +0 -1
  659. package/dist/server/implementation/index.js +0 -610
  660. package/dist/server/implementation/index.js.map +0 -1
  661. package/dist/server/implementation/keys.d.ts +0 -66
  662. package/dist/server/implementation/keys.d.ts.map +0 -1
  663. package/dist/server/implementation/keys.js.map +0 -1
  664. package/dist/server/implementation/mutations/account.d.ts +0 -27
  665. package/dist/server/implementation/mutations/account.d.ts.map +0 -1
  666. package/dist/server/implementation/mutations/account.js +0 -39
  667. package/dist/server/implementation/mutations/account.js.map +0 -1
  668. package/dist/server/implementation/mutations/code.d.ts +0 -29
  669. package/dist/server/implementation/mutations/code.d.ts.map +0 -1
  670. package/dist/server/implementation/mutations/code.js.map +0 -1
  671. package/dist/server/implementation/mutations/index.d.ts +0 -310
  672. package/dist/server/implementation/mutations/index.d.ts.map +0 -1
  673. package/dist/server/implementation/mutations/index.js +0 -70
  674. package/dist/server/implementation/mutations/index.js.map +0 -1
  675. package/dist/server/implementation/mutations/invalidate.d.ts +0 -18
  676. package/dist/server/implementation/mutations/invalidate.d.ts.map +0 -1
  677. package/dist/server/implementation/mutations/invalidate.js +0 -29
  678. package/dist/server/implementation/mutations/invalidate.js.map +0 -1
  679. package/dist/server/implementation/mutations/oauth.d.ts +0 -23
  680. package/dist/server/implementation/mutations/oauth.d.ts.map +0 -1
  681. package/dist/server/implementation/mutations/oauth.js +0 -51
  682. package/dist/server/implementation/mutations/oauth.js.map +0 -1
  683. package/dist/server/implementation/mutations/refresh.d.ts +0 -20
  684. package/dist/server/implementation/mutations/refresh.d.ts.map +0 -1
  685. package/dist/server/implementation/mutations/refresh.js +0 -85
  686. package/dist/server/implementation/mutations/refresh.js.map +0 -1
  687. package/dist/server/implementation/mutations/register.d.ts +0 -37
  688. package/dist/server/implementation/mutations/register.d.ts.map +0 -1
  689. package/dist/server/implementation/mutations/register.js +0 -65
  690. package/dist/server/implementation/mutations/register.js.map +0 -1
  691. package/dist/server/implementation/mutations/retrieve.d.ts +0 -31
  692. package/dist/server/implementation/mutations/retrieve.d.ts.map +0 -1
  693. package/dist/server/implementation/mutations/retrieve.js +0 -50
  694. package/dist/server/implementation/mutations/retrieve.js.map +0 -1
  695. package/dist/server/implementation/mutations/signature.d.ts +0 -19
  696. package/dist/server/implementation/mutations/signature.d.ts.map +0 -1
  697. package/dist/server/implementation/mutations/signature.js +0 -27
  698. package/dist/server/implementation/mutations/signature.js.map +0 -1
  699. package/dist/server/implementation/mutations/signin.d.ts +0 -21
  700. package/dist/server/implementation/mutations/signin.d.ts.map +0 -1
  701. package/dist/server/implementation/mutations/signin.js.map +0 -1
  702. package/dist/server/implementation/mutations/signout.d.ts +0 -14
  703. package/dist/server/implementation/mutations/signout.d.ts.map +0 -1
  704. package/dist/server/implementation/mutations/signout.js +0 -27
  705. package/dist/server/implementation/mutations/signout.js.map +0 -1
  706. package/dist/server/implementation/mutations/store.d.ts +0 -11
  707. package/dist/server/implementation/mutations/store.d.ts.map +0 -1
  708. package/dist/server/implementation/mutations/store.js +0 -12
  709. package/dist/server/implementation/mutations/store.js.map +0 -1
  710. package/dist/server/implementation/mutations/verifier.d.ts +0 -11
  711. package/dist/server/implementation/mutations/verifier.d.ts.map +0 -1
  712. package/dist/server/implementation/mutations/verifier.js +0 -16
  713. package/dist/server/implementation/mutations/verifier.js.map +0 -1
  714. package/dist/server/implementation/mutations/verify.d.ts +0 -25
  715. package/dist/server/implementation/mutations/verify.d.ts.map +0 -1
  716. package/dist/server/implementation/mutations/verify.js +0 -105
  717. package/dist/server/implementation/mutations/verify.js.map +0 -1
  718. package/dist/server/implementation/passkey.d.ts +0 -24
  719. package/dist/server/implementation/passkey.d.ts.map +0 -1
  720. package/dist/server/implementation/passkey.js +0 -307
  721. package/dist/server/implementation/passkey.js.map +0 -1
  722. package/dist/server/implementation/provider.d.ts +0 -10
  723. package/dist/server/implementation/provider.d.ts.map +0 -1
  724. package/dist/server/implementation/provider.js +0 -19
  725. package/dist/server/implementation/provider.js.map +0 -1
  726. package/dist/server/implementation/ratelimit.d.ts +0 -10
  727. package/dist/server/implementation/ratelimit.d.ts.map +0 -1
  728. package/dist/server/implementation/ratelimit.js +0 -48
  729. package/dist/server/implementation/ratelimit.js.map +0 -1
  730. package/dist/server/implementation/redirects.d.ts +0 -10
  731. package/dist/server/implementation/redirects.d.ts.map +0 -1
  732. package/dist/server/implementation/redirects.js.map +0 -1
  733. package/dist/server/implementation/refresh.d.ts +0 -37
  734. package/dist/server/implementation/refresh.d.ts.map +0 -1
  735. package/dist/server/implementation/refresh.js +0 -109
  736. package/dist/server/implementation/refresh.js.map +0 -1
  737. package/dist/server/implementation/sessions.d.ts +0 -29
  738. package/dist/server/implementation/sessions.d.ts.map +0 -1
  739. package/dist/server/implementation/sessions.js.map +0 -1
  740. package/dist/server/implementation/signin.d.ts +0 -55
  741. package/dist/server/implementation/signin.d.ts.map +0 -1
  742. package/dist/server/implementation/signin.js +0 -148
  743. package/dist/server/implementation/signin.js.map +0 -1
  744. package/dist/server/implementation/tokens.d.ts +0 -11
  745. package/dist/server/implementation/tokens.d.ts.map +0 -1
  746. package/dist/server/implementation/tokens.js +0 -15
  747. package/dist/server/implementation/tokens.js.map +0 -1
  748. package/dist/server/implementation/totp.d.ts +0 -31
  749. package/dist/server/implementation/totp.d.ts.map +0 -1
  750. package/dist/server/implementation/totp.js +0 -142
  751. package/dist/server/implementation/totp.js.map +0 -1
  752. package/dist/server/implementation/types.d.ts +0 -189
  753. package/dist/server/implementation/types.d.ts.map +0 -1
  754. package/dist/server/implementation/types.js +0 -97
  755. package/dist/server/implementation/types.js.map +0 -1
  756. package/dist/server/implementation/users.d.ts +0 -30
  757. package/dist/server/implementation/users.d.ts.map +0 -1
  758. package/dist/server/implementation/users.js.map +0 -1
  759. package/dist/server/implementation/utils.d.ts +0 -19
  760. package/dist/server/implementation/utils.d.ts.map +0 -1
  761. package/dist/server/implementation/utils.js +0 -56
  762. package/dist/server/implementation/utils.js.map +0 -1
  763. package/dist/server/index.d.ts.map +0 -1
  764. package/dist/server/index.js.map +0 -1
  765. package/dist/server/oauth.d.ts.map +0 -1
  766. package/dist/server/providers.d.ts +0 -72
  767. package/dist/server/providers.d.ts.map +0 -1
  768. package/dist/server/providers.js.map +0 -1
  769. package/dist/server/templates.d.ts.map +0 -1
  770. package/dist/server/utils.d.ts.map +0 -1
  771. package/dist/server/version.d.ts +0 -5
  772. package/dist/server/version.d.ts.map +0 -1
  773. package/dist/server/version.js +0 -6
  774. package/dist/server/version.js.map +0 -1
  775. package/src/cli/utils.ts +0 -248
  776. package/src/server/implementation/device.ts +0 -307
  777. package/src/server/implementation/index.ts +0 -1583
  778. package/src/server/implementation/mutations/account.ts +0 -50
  779. package/src/server/implementation/mutations/index.ts +0 -157
  780. package/src/server/implementation/mutations/invalidate.ts +0 -42
  781. package/src/server/implementation/mutations/oauth.ts +0 -73
  782. package/src/server/implementation/mutations/refresh.ts +0 -175
  783. package/src/server/implementation/mutations/register.ts +0 -100
  784. package/src/server/implementation/mutations/retrieve.ts +0 -79
  785. package/src/server/implementation/mutations/signature.ts +0 -39
  786. package/src/server/implementation/mutations/signout.ts +0 -35
  787. package/src/server/implementation/mutations/store.ts +0 -7
  788. package/src/server/implementation/mutations/verifier.ts +0 -24
  789. package/src/server/implementation/mutations/verify.ts +0 -194
  790. package/src/server/implementation/passkey.ts +0 -620
  791. package/src/server/implementation/provider.ts +0 -36
  792. package/src/server/implementation/ratelimit.ts +0 -79
  793. package/src/server/implementation/refresh.ts +0 -172
  794. package/src/server/implementation/signin.ts +0 -296
  795. package/src/server/implementation/totp.ts +0 -342
  796. package/src/server/implementation/types.ts +0 -444
  797. package/src/server/implementation/utils.ts +0 -91
  798. package/src/server/version.ts +0 -2
@@ -1,273 +1,697 @@
1
1
  /**
2
- * The `Auth` class the main entry point for Convex Auth.
3
- *
4
- * Main entry point for authentication and authorization helpers:
5
- *
6
- * ```ts
7
- * // convex/auth.ts
8
- * import { Auth } from "@robelest/convex-auth/component";
9
- * import { components } from "./_generated/api";
10
- *
11
- * export const auth = new Auth(components.auth, {
12
- * providers: [{ id: "google", type: "oauth" as const }],
13
- * email: {
14
- * from: "My App <noreply@example.com>",
15
- * send: async (_ctx, { from, to, subject, html }) => {
16
- * await fetch("https://api.resend.com/emails", {
17
- * method: "POST",
18
- * headers: {
19
- * Authorization: `Bearer ${process.env.AUTH_RESEND_KEY}`,
20
- * "Content-Type": "application/json",
21
- * },
22
- * body: JSON.stringify({ from, to, subject, html }),
23
- * });
24
- * },
25
- * },
26
- * });
27
- * export const { signIn, signOut, store } = auth;
28
- * ```
2
+ * Auth configuration helpers for Convex Auth.
29
3
  *
30
4
  * @module
31
5
  */
32
6
 
33
7
  import type { UserIdentity } from "convex/server";
34
8
  import type { GenericId } from "convex/values";
35
- import type { Doc } from "./implementation/types";
36
- import type { ComponentApi as AuthComponentApi } from "../component/_generated/component";
37
- import { Auth as AuthFactory } from "./implementation/index";
38
- import type { ConvexAuthConfig } from "./types";
39
- import { defaultMagicLinkEmail } from "./templates";
40
- import emailProvider from "../providers/email";
41
- import { throwAuthError } from "./errors";
9
+
10
+ import type { AuthApiRefs } from "../client/index";
11
+ import { Auth as AuthFactory } from "./runtime";
12
+ import { Fx } from "@robelest/fx";
13
+ import { AuthError } from "./authError";
14
+ import type { Doc } from "./types";
15
+ import type {
16
+ AuthAuthorizationConfig,
17
+ AuthGrant,
18
+ AuthProviderConfig,
19
+ AuthRoleDefinition,
20
+ AuthRoleId,
21
+ ConvexAuthConfig,
22
+ HasDeviceProvider,
23
+ HasPasskeyProvider,
24
+ HasSSO,
25
+ HasTotpProvider,
26
+ } from "./types";
42
27
 
43
28
  // ============================================================================
44
29
  // Types
45
30
  // ============================================================================
46
31
 
47
32
  /**
48
- * Config for the Auth class. Extends the standard auth config
33
+ * Config for auth setup. Extends the standard auth config
49
34
  * minus `component` (which is passed as the first constructor argument).
35
+ */
36
+ export type AuthConfig = Omit<ConvexAuthConfig, "component">;
37
+
38
+ type MemberApiWithAuthorization<
39
+ TAuthorization extends AuthAuthorizationConfig | undefined,
40
+ > = Omit<
41
+ ReturnType<typeof AuthFactory>["auth"]["member"],
42
+ "create" | "list" | "update" | "resolve"
43
+ > & {
44
+ create: (
45
+ ctx: Parameters<
46
+ ReturnType<typeof AuthFactory>["auth"]["member"]["create"]
47
+ >[0],
48
+ data: {
49
+ groupId: string;
50
+ userId: string;
51
+ roleIds?: AuthRoleId<TAuthorization>[];
52
+ status?: string;
53
+ extend?: Record<string, unknown>;
54
+ },
55
+ ) => Promise<{ ok: true; memberId: string }>;
56
+ list: (
57
+ ctx: Parameters<
58
+ ReturnType<typeof AuthFactory>["auth"]["member"]["list"]
59
+ >[0],
60
+ opts?: {
61
+ where?: {
62
+ groupId?: string;
63
+ userId?: string;
64
+ roleId?: AuthRoleId<TAuthorization>;
65
+ status?: string;
66
+ };
67
+ limit?: number;
68
+ cursor?: string | null;
69
+ orderBy?: "_creationTime" | "status";
70
+ order?: "asc" | "desc";
71
+ },
72
+ ) => ReturnType<ReturnType<typeof AuthFactory>["auth"]["member"]["list"]>;
73
+ update: (
74
+ ctx: Parameters<
75
+ ReturnType<typeof AuthFactory>["auth"]["member"]["update"]
76
+ >[0],
77
+ memberId: string,
78
+ data: Record<string, unknown> & { roleIds?: AuthRoleId<TAuthorization>[] },
79
+ ) => Promise<{ ok: true; memberId: string }>;
80
+ resolve: (
81
+ ctx: Parameters<
82
+ ReturnType<typeof AuthFactory>["auth"]["member"]["resolve"]
83
+ >[0],
84
+ opts: {
85
+ userId: string;
86
+ groupId: string;
87
+ ancestry?: boolean;
88
+ roleIds?: AuthRoleId<TAuthorization>[];
89
+ grants?: AuthGrant<TAuthorization>[];
90
+ maxDepth?: number;
91
+ },
92
+ ) => ReturnType<ReturnType<typeof AuthFactory>["auth"]["member"]["resolve"]>;
93
+ };
94
+
95
+
96
+ /**
97
+ * The base auth API surface returned by {@link createAuth}.
98
+ *
99
+ * Provides core namespaces — `signIn`, `signOut`, `user`, `session`,
100
+ * `member`, `invite`, `group`, `key`, and `http` — that are
101
+ * always available regardless of which providers are configured.
102
+ * Enterprise namespaces (`sso`, `scim`) are added conditionally by
103
+ * {@link AuthApi} when an SSO provider is present.
104
+ *
105
+ * Use this type when you want to describe code that only depends on the
106
+ * standard auth surface and should not assume enterprise features exist.
107
+ *
108
+ * @typeParam TAuthorization - The authorization config, used to narrow
109
+ * role IDs and grant strings on the `member` API.
110
+ */
111
+ export type AuthApiBase<
112
+ TAuthorization extends AuthAuthorizationConfig | undefined = undefined,
113
+ > = {
114
+ signIn: ReturnType<typeof AuthFactory>["signIn"];
115
+ signOut: ReturnType<typeof AuthFactory>["signOut"];
116
+ store: ReturnType<typeof AuthFactory>["store"];
117
+ user: ReturnType<typeof AuthFactory>["auth"]["user"];
118
+ session: ReturnType<typeof AuthFactory>["auth"]["session"];
119
+ provider: ReturnType<typeof AuthFactory>["auth"]["provider"];
120
+ account: ReturnType<typeof AuthFactory>["auth"]["account"];
121
+ group: ReturnType<typeof AuthFactory>["auth"]["group"];
122
+ member: MemberApiWithAuthorization<TAuthorization>;
123
+ invite: ReturnType<typeof AuthFactory>["auth"]["invite"];
124
+ key: ReturnType<typeof AuthFactory>["auth"]["key"];
125
+ http: ReturnType<typeof AuthFactory>["auth"]["http"];
126
+ /**
127
+ * Resolve the current user's auth context. Framework-agnostic — use
128
+ * this in fluent-convex middleware, custom wrappers, or anywhere you
129
+ * need the resolved `{ userId, user, groupId, role, grants }` object.
130
+ *
131
+ * Returns `null` when unauthenticated. Does not throw.
132
+ *
133
+ * @param ctx - Convex query, mutation, or action context.
134
+ * @returns The resolved auth context, or `null`.
135
+ *
136
+ * @example fluent-convex middleware
137
+ * ```ts
138
+ * const withAuth = convex.createMiddleware(async (ctx, next) => {
139
+ * return next({ ...ctx, auth: await auth.resolve(ctx) });
140
+ * });
141
+ * ```
142
+ *
143
+ * @example Direct usage in a handler
144
+ * ```ts
145
+ * const resolved = await auth.resolve(ctx);
146
+ * if (!resolved) return { ok: false, code: "NOT_SIGNED_IN" };
147
+ * const { userId, grants } = resolved;
148
+ * ```
149
+ */
150
+ resolve: (ctx: any) => Promise<AuthResolvedContext | null>;
151
+ /**
152
+ * Context enrichment for convex-helpers `customQuery` / `customMutation` /
153
+ * `customAction`.
154
+ *
155
+ * Resolves the current user's identity, active group, membership role,
156
+ * and grants, then attaches them to `ctx.auth`. Returns a `Customization`
157
+ * object compatible with convex-helpers' custom function builders.
158
+ *
159
+ * `ctx.auth` is `{ userId, user, groupId, role, grants }` when
160
+ * authenticated, `null` when unauthenticated. No throwing — your
161
+ * handler decides how to respond.
162
+ *
163
+ * @returns A convex-helpers `Customization` object.
164
+ *
165
+ * @example One-time setup in `convex/functions.ts`
166
+ * ```ts
167
+ * import { query, mutation, action } from "./_generated/server";
168
+ * import { customQuery, customMutation, customAction } from "convex-helpers/server/customFunctions";
169
+ * import { auth } from "./auth";
170
+ *
171
+ * export const authQuery = customQuery(query, auth.ctx());
172
+ * export const authMutation = customMutation(mutation, auth.ctx());
173
+ * export const authAction = customAction(action, auth.ctx());
174
+ * ```
175
+ *
176
+ * @example Per-function usage
177
+ * ```ts
178
+ * import { authQuery } from "./functions";
179
+ *
180
+ * export const list = authQuery({
181
+ * args: { workspaceId: v.string() },
182
+ * handler: async (ctx, args) => {
183
+ * if (!ctx.auth) return [];
184
+ * const { userId, groupId, grants } = ctx.auth;
185
+ * // business logic
186
+ * },
187
+ * });
188
+ * ```
189
+ */
190
+ ctx: () => {
191
+ args: Record<string, never>;
192
+ input: (ctx: any) => Promise<{
193
+ ctx: { auth: AuthResolvedContext | null };
194
+ args: Record<string, never>;
195
+ }>;
196
+ };
197
+ };
198
+
199
+ /**
200
+ * Resolved auth context injected into `ctx.auth` by `auth.ctx()`.
50
201
  *
51
- * When `email` is configured, the library auto-registers a
52
- * magic link provider (`id: "email"`) for user-facing sign-in.
202
+ * - `null` when unauthenticated.
203
+ * - `groupId` is `null` when the user has no active group set.
204
+ * - `role` / `grants` are `null` / `[]` when no active group or no membership.
53
205
  */
54
- export type AuthClassConfig = Omit<ConvexAuthConfig, "component">;
206
+ export type AuthResolvedContext = {
207
+ /** The authenticated user's document ID. */
208
+ userId: string;
209
+ /** The authenticated user's full document. */
210
+ user: any;
211
+ /** The user's active group ID, or `null` if none set. */
212
+ groupId: string | null;
213
+ /** The user's primary role in the active group, or `null`. */
214
+ role: string | null;
215
+ /** Resolved grant strings from the user's role definitions. */
216
+ grants: string[];
217
+ };
218
+
219
+ type InternalSsoApi = ReturnType<typeof AuthFactory>["auth"]["sso"];
220
+
221
+ type PublicSsoAdminApi = {
222
+ connection: InternalSsoApi["connection"] & {
223
+ domain: {
224
+ list: InternalSsoApi["domain"]["list"];
225
+ validate: InternalSsoApi["domain"]["validate"];
226
+ set: (
227
+ ctx: Parameters<InternalSsoApi["connection"]["create"]>[0],
228
+ enterpriseId: string,
229
+ domains: Array<{
230
+ domain: string;
231
+ isPrimary?: boolean;
232
+ }>,
233
+ ) => Promise<{
234
+ ok: true;
235
+ enterpriseId: string;
236
+ domains: Array<{
237
+ domainId: string;
238
+ domain: string;
239
+ isPrimary: boolean;
240
+ verified: boolean;
241
+ verifiedAt: number | null;
242
+ }>;
243
+ }>;
244
+ verification: {
245
+ request: (
246
+ ctx: Parameters<InternalSsoApi["connection"]["create"]>[0],
247
+ args: { enterpriseId: string; domain: string },
248
+ ) => Promise<{
249
+ ok: true;
250
+ enterpriseId: string;
251
+ domain: string;
252
+ requestedAt: number;
253
+ expiresAt: number;
254
+ challenge: {
255
+ recordType: "TXT";
256
+ recordName: string;
257
+ recordValue: string;
258
+ };
259
+ }>;
260
+ confirm: (
261
+ ctx: Parameters<InternalSsoApi["connection"]["create"]>[0],
262
+ args: { enterpriseId: string; domain: string },
263
+ ) => Promise<{
264
+ ok: boolean;
265
+ enterpriseId: string;
266
+ domain: string;
267
+ verifiedAt?: number;
268
+ checks: Array<{ name: string; ok: boolean; message?: string }>;
269
+ }>;
270
+ };
271
+ };
272
+ };
273
+ oidc: Omit<InternalSsoApi["oidc"], "signIn">;
274
+ saml: Omit<InternalSsoApi["saml"], "metadata">;
275
+ policy: InternalSsoApi["policy"];
276
+ audit: {
277
+ list: InternalSsoApi["audit"]["list"];
278
+ };
279
+ webhook: {
280
+ endpoint: InternalSsoApi["webhook"]["endpoint"];
281
+ delivery: {
282
+ list: InternalSsoApi["webhook"]["delivery"]["list"];
283
+ };
284
+ };
285
+ };
286
+
287
+ type PublicSsoClientApi = {
288
+ signIn: InternalSsoApi["oidc"]["signIn"];
289
+ metadata: InternalSsoApi["saml"]["metadata"];
290
+ };
291
+
292
+ type PublicSsoApi = {
293
+ admin: PublicSsoAdminApi;
294
+ client: PublicSsoClientApi;
295
+ };
296
+
297
+ type PublicScimApi = {
298
+ admin: Omit<InternalSsoApi["scim"], "getConfigByToken" | "identity">;
299
+ };
300
+
301
+ /**
302
+ * Extended auth API that includes enterprise SSO and SCIM namespaces.
303
+ *
304
+ * This type is the union of {@link AuthApiBase} plus `sso` (SSO connection
305
+ * management, OIDC/SAML, domain verification, policies, audit, webhooks)
306
+ * and `scim` (SCIM provisioning configuration). It is returned by
307
+ * {@link createAuth} only when `new SSO()` is included in the providers
308
+ * array; otherwise the narrower {@link AuthApiBase} is returned instead.
309
+ * Attempting to access `auth.sso` or `auth.scim` without an SSO provider
310
+ * produces a compile-time error because the return type narrows back to
311
+ * {@link AuthApiBase}.
312
+ *
313
+ * @typeParam TAuthorization - The authorization config, forwarded to
314
+ * {@link AuthApiBase} for typed role IDs and grant strings.
315
+ */
316
+ export type AuthApi<
317
+ TAuthorization extends AuthAuthorizationConfig | undefined = undefined,
318
+ > = AuthApiBase<TAuthorization> & {
319
+ sso: PublicSsoApi;
320
+ scim: PublicScimApi;
321
+ };
322
+
323
+ /**
324
+ * The return type of {@link createAuth}.
325
+ *
326
+ * Resolves to {@link AuthApi} (with `sso` and `scim` namespaces) when
327
+ * `new SSO()` is present in the providers array, or to the narrower
328
+ * {@link AuthApiBase} otherwise. This conditional type ensures that
329
+ * enterprise-only APIs are only accessible when the SSO provider is
330
+ * configured, producing a compile-time error if you try to access
331
+ * `auth.sso` without it.
332
+ * This lets application code keep a single `createAuth()` call while still
333
+ * getting provider-aware typing on the resulting API object.
334
+ *
335
+ * @typeParam P - The tuple of provider configs passed to `createAuth`.
336
+ * @typeParam TAuthorization - Optional authorization config for typed roles/grants.
337
+ */
338
+ export type ConvexAuthResult<
339
+ P extends AuthProviderConfig[],
340
+ TAuthorization extends AuthAuthorizationConfig | undefined = undefined,
341
+ > =
342
+ HasSSO<P> extends true
343
+ ? AuthApi<TAuthorization>
344
+ : AuthApiBase<TAuthorization>;
345
+
346
+ /**
347
+ * Infer the typed `AuthApiRefs` for the client SDK from a `createAuth` call.
348
+ *
349
+ * Use this as the generic parameter for `client()` on the frontend:
350
+ *
351
+ * ```ts
352
+ * // convex/auth.ts
353
+ * export const auth = createAuth(components.auth, { providers: [...] });
354
+ *
355
+ * // Frontend
356
+ * import type { auth } from "../convex/auth";
357
+ * import type { InferClientApi } from "@robelest/convex-auth/server";
358
+ * const c = client<InferClientApi<typeof auth>>({ convex, api: api.auth });
359
+ * ```
360
+ *
361
+ * @typeParam T - A ConvexAuthResult to extract the client API from.
362
+ */
363
+ export type InferClientApi<T> =
364
+ T extends ConvexAuthResult<infer P>
365
+ ? AuthApiRefs<
366
+ HasPasskeyProvider<P>,
367
+ HasTotpProvider<P>,
368
+ HasDeviceProvider<P>
369
+ >
370
+ : AuthApiRefs;
371
+
372
+ /** @internal */
373
+ export type AuthLike = Pick<AuthApiBase, "user">;
55
374
 
56
375
  // ============================================================================
57
- // Auth class
376
+ // Auth setup APIs
58
377
  // ============================================================================
59
378
 
60
379
  /**
61
- * Main entry point for Convex Auth. Instantiate with your component
62
- * reference and config to get all the exports you need.
380
+ * Create an auth API object.
381
+ *
382
+ * When `new SSO()` is included in providers, `auth.sso` and `auth.scim`
383
+ * are available on the returned object. Without it, those namespaces are
384
+ * absent and accessing them is a TypeScript compile error.
385
+ *
386
+ * @param component - The installed auth component reference from
387
+ * `components.auth` in your Convex app definition.
388
+ * @param config - Auth configuration including `providers` and optional
389
+ * `authorization`. All fields from {@link AuthConfig} are accepted
390
+ * except `component` (passed as the first argument).
391
+ * @returns A {@link ConvexAuthResult} object — either {@link AuthApi}
392
+ * (with `sso`/`scim`) or {@link AuthApiBase}, depending on whether
393
+ * an SSO provider is present.
63
394
  *
395
+ * @example
64
396
  * ```ts
65
- * export const auth = new Auth(components.auth, {
66
- * providers: [google, password],
67
- * email: {
68
- * from: "My App <noreply@example.com>",
69
- * send: (ctx, params) => resend.sendEmail(ctx, params),
70
- * },
397
+ * export const auth = createAuth(components.auth, {
398
+ * providers: [password(), google()],
399
+ * authorization: { roles },
71
400
  * });
72
- * export const { signIn, signOut, store } = auth;
73
401
  * ```
402
+ *
403
+ * @see {@link AuthCtx}
74
404
  */
75
- export class Auth {
76
- /** The inner `auth` helper object from AuthFactory() */
77
- private readonly _auth: ReturnType<typeof AuthFactory>["auth"];
78
- /** The signIn action — export this from your convex/auth.ts */
79
- public readonly signIn: ReturnType<typeof AuthFactory>["signIn"];
80
- /** The signOut action — export this from your convex/auth.ts */
81
- public readonly signOut: ReturnType<typeof AuthFactory>["signOut"];
82
- /** The store internal mutation — export this from your convex/auth.ts */
83
- public readonly store: ReturnType<typeof AuthFactory>["store"];
84
-
85
- // ---- Proxied auth helper sub-objects ----
86
- /** User helpers: `.current(ctx)`, `.require(ctx)`, `.get(ctx, userId)`, `.patch(ctx, userId, data)`, `.viewer(ctx)`, `.group.list(ctx, ...)`, `.group.get(ctx, ...)` */
87
- get user() { return this._auth.user; }
88
- /** Session helpers: `.current(ctx)`, `.invalidate(ctx, { userId, except? })` */
89
- get session() { return this._auth.session; }
90
- /** Provider helpers: `.signIn(ctx, provider, args)` */
91
- get provider() { return this._auth.provider; }
92
- /** Account helpers: `.create(ctx, args)`, `.get(ctx, args)`, `.update(ctx, args)` */
93
- get account() { return this._auth.account; }
94
- /** Group helpers: `.create(ctx, ...)`, `.get(ctx, id)`, `.list(ctx, ...)`, `.update(ctx, ...)`, `.delete(ctx, id)`, `.member.*` */
95
- get group() { return this._auth.group; }
96
- /** Invite helpers: `.create(ctx, ...)`, `.get(ctx, id)`, `.list(ctx, ...)`, `.accept(ctx, ...)`, `.revoke(ctx, id)` */
97
- get invite() { return this._auth.invite; }
98
- /** Passkey helpers: `.list(ctx, { userId })`, `.rename(ctx, id, name)`, `.remove(ctx, id)` */
99
- get passkey() { return this._auth.passkey; }
100
- /** TOTP helpers: `.list(ctx, { userId })`, `.remove(ctx, id)` */
101
- get totp() { return this._auth.totp; }
102
- /** API key helpers: `.create(ctx, ...)`, `.verify(ctx, rawKey)`, `.list(ctx, ...)`, `.get(ctx, id)`, `.update(ctx, ...)`, `.revoke(ctx, id)`, `.remove(ctx, id)` */
103
- get key() { return this._auth.key; }
104
405
 
105
- /**
106
- * @param component - The auth component reference from `components.auth`.
107
- * @param config - Auth configuration (providers, email transport, session, JWT, callbacks).
108
- */
109
- constructor(component: AuthComponentApi, config: AuthClassConfig) {
110
- const emailTransport = config.email;
111
- const providers = [...config.providers];
112
-
113
- // Auto-register user-facing magic link provider when email is configured.
114
- // Skipped if the user already registered their own provider with id "email".
115
- const hasUserEmailProvider = providers.some(
116
- (p) => typeof p === "object" && "id" in p && p.id === "email",
117
- );
118
- if (emailTransport && !hasUserEmailProvider) {
119
- providers.push(
120
- emailProvider({
121
- id: "email",
122
- maxAge: 60 * 60 * 24, // 24 hours
123
- authorize: undefined, // Magic link no OTP email check needed
124
- async sendVerificationRequest({ identifier, url }, ctx) {
125
- if (!ctx) {
126
- throwAuthError("MISSING_ACTION_CONTEXT");
127
- }
128
- const { host } = new URL(url);
129
- await emailTransport.send(ctx, {
130
- from: emailTransport.from,
131
- to: identifier,
132
- subject: `Sign in to ${host}`,
133
- html: defaultMagicLinkEmail(url, host),
134
- });
135
- },
136
- }),
137
- );
406
+ // ---------------------------------------------------------------------------
407
+ // Function builders shared auth resolution logic
408
+ // ---------------------------------------------------------------------------
409
+
410
+ /**
411
+ * Resolve auth context for the current user. Returns the enriched
412
+ * `ctx.auth` object or `null` when unauthenticated.
413
+ *
414
+ * Resolution flow:
415
+ * 1. `user.id(ctx)` userId or null (exit early)
416
+ * 2. `user.get(ctx, userId)` → user doc (cached per-execution)
417
+ * 3. `user.getActiveGroup(ctx, { userId })` groupId or null
418
+ * 4. If groupId → `member.resolve(ctx, { userId, groupId })` → role + grants
419
+ */
420
+ async function resolveAuthContext(auth: any, ctx: any) {
421
+ const userId = await auth.user.id(ctx);
422
+ if (!userId) return null;
423
+ const user = await auth.user.get(ctx, userId);
424
+ const groupId = await auth.user.getActiveGroup(ctx, { userId });
425
+ let role: string | null = null;
426
+ let grants: string[] = [];
427
+ if (groupId) {
428
+ const resolved = await auth.member.resolve(ctx, { userId, groupId });
429
+ if (resolved.membership) {
430
+ role = resolved.roleIds[0] ?? null;
431
+ grants = resolved.grants;
138
432
  }
433
+ }
434
+ return { userId, user, groupId, role, grants };
435
+ }
139
436
 
140
- // Initialize the core AuthFactory()
141
- const authResult = AuthFactory({
142
- ...config,
143
- component,
144
- providers,
145
- });
437
+ export function createAuth<
438
+ P extends AuthProviderConfig[],
439
+ TAuthorization extends AuthAuthorizationConfig | undefined = undefined,
440
+ >(
441
+ component: ConvexAuthConfig["component"],
442
+ config: Omit<AuthConfig, "providers" | "authorization"> & {
443
+ providers: P;
444
+ authorization?: TAuthorization;
445
+ },
446
+ ): ConvexAuthResult<P, TAuthorization> {
447
+ const authResult = AuthFactory({
448
+ ...config,
449
+ component,
450
+ providers: [...config.providers],
451
+ });
452
+ const {
453
+ domain: domainApi,
454
+ scim: scimApi,
455
+ connection: connectionApi,
456
+ audit: auditApi,
457
+ webhook: webhookApi,
458
+ oidc: oidcApi,
459
+ saml: samlApi,
460
+ ...restSso
461
+ } = authResult.auth.sso as InternalSsoApi;
146
462
 
147
- this._auth = authResult.auth;
148
- this.signIn = authResult.signIn;
149
- this.signOut = authResult.signOut;
150
- this.store = authResult.store;
463
+ type SetEnterpriseDomains = PublicSsoAdminApi["connection"]["domain"]["set"];
464
+ type EnterpriseDomainInput = Array<{
465
+ domain: string;
466
+ isPrimary?: boolean;
467
+ }>;
468
+ const setEnterpriseDomains: PublicSsoAdminApi["connection"]["domain"]["set"] =
469
+ async (
470
+ ctx: Parameters<SetEnterpriseDomains>[0],
471
+ enterpriseId: Parameters<SetEnterpriseDomains>[1],
472
+ domains: EnterpriseDomainInput,
473
+ ) => {
474
+ const enterprise = await connectionApi.get(ctx, enterpriseId);
475
+ if (enterprise === null) {
476
+ throw new AuthError(
477
+ "INVALID_PARAMETERS",
478
+ "Enterprise not found.",
479
+ ).toConvexError();
480
+ }
151
481
 
152
- }
482
+ const normalized = domains.map((entry: (typeof domains)[number]) => ({
483
+ ...entry,
484
+ domain: entry.domain.trim().toLowerCase(),
485
+ }));
486
+ const deduped = new Map<string, (typeof normalized)[number]>();
487
+ for (const entry of normalized) {
488
+ if (entry.domain.length === 0) {
489
+ throw new AuthError(
490
+ "INVALID_PARAMETERS",
491
+ "Domain must not be empty.",
492
+ ).toConvexError();
493
+ }
494
+ if (deduped.has(entry.domain)) {
495
+ throw new AuthError(
496
+ "INVALID_PARAMETERS",
497
+ `Duplicate domain: ${entry.domain}`,
498
+ ).toConvexError();
499
+ }
500
+ deduped.set(entry.domain, entry);
501
+ }
153
502
 
154
- /** HTTP namespace — route registration and Bearer-authenticated endpoints. */
155
- get http() {
156
- return this._auth.http;
157
- }
503
+ const nextDomains = [...deduped.values()];
504
+ const primaryCount = nextDomains.filter(
505
+ (entry) => entry.isPrimary,
506
+ ).length;
507
+ if (primaryCount > 1) {
508
+ throw new AuthError(
509
+ "INVALID_PARAMETERS",
510
+ "Only one primary domain may be set.",
511
+ ).toConvexError();
512
+ }
513
+ if (nextDomains.length > 0 && primaryCount === 0) {
514
+ nextDomains[0] = { ...nextDomains[0], isPrimary: true };
515
+ }
516
+
517
+ const currentDomains = await domainApi.list(ctx, enterpriseId);
518
+ const currentByDomain = new Map<string, (typeof currentDomains)[number]>(
519
+ currentDomains.map((entry: (typeof currentDomains)[number]) => [
520
+ entry.domain.toLowerCase(),
521
+ entry,
522
+ ]),
523
+ );
524
+
525
+ for (const existing of currentDomains) {
526
+ if (!deduped.has(existing.domain.toLowerCase())) {
527
+ await domainApi.remove(ctx, existing._id);
528
+ }
529
+ }
530
+
531
+ for (const nextDomain of nextDomains) {
532
+ const current = currentByDomain.get(nextDomain.domain);
533
+ if (current && current.isPrimary === Boolean(nextDomain.isPrimary)) {
534
+ continue;
535
+ }
536
+ if (current) {
537
+ await domainApi.remove(ctx, current._id);
538
+ }
539
+ const domainId = await domainApi.add(ctx, {
540
+ enterpriseId: enterprise._id,
541
+ groupId: enterprise.groupId,
542
+ domain: nextDomain.domain,
543
+ isPrimary: nextDomain.isPrimary,
544
+ });
545
+ if (current?.verifiedAt !== undefined) {
546
+ await (ctx as any).runMutation(
547
+ component.public.enterpriseDomainVerify,
548
+ {
549
+ domainId,
550
+ verifiedAt: current.verifiedAt,
551
+ },
552
+ );
553
+ }
554
+ }
555
+
556
+ const updatedDomains = await domainApi.list(ctx, enterpriseId);
557
+ return {
558
+ ok: true as const,
559
+ enterpriseId,
560
+ domains: updatedDomains.map(
561
+ (domain: (typeof updatedDomains)[number]) => ({
562
+ domainId: domain._id,
563
+ domain: domain.domain,
564
+ isPrimary: domain.isPrimary,
565
+ verified: domain.verifiedAt !== undefined,
566
+ verifiedAt: domain.verifiedAt ?? null,
567
+ }),
568
+ ),
569
+ };
570
+ };
571
+
572
+ const publicSso: PublicSsoApi = {
573
+ admin: {
574
+ ...restSso,
575
+ oidc: {
576
+ ...oidcApi,
577
+ },
578
+ saml: {
579
+ ...samlApi,
580
+ },
581
+ connection: {
582
+ ...connectionApi,
583
+ domain: {
584
+ list: domainApi.list,
585
+ validate: domainApi.validate,
586
+ set: setEnterpriseDomains,
587
+ verification: {
588
+ request: domainApi.verification.request,
589
+ confirm: domainApi.verification.confirm,
590
+ },
591
+ },
592
+ },
593
+ policy: restSso.policy,
594
+ audit: {
595
+ list: auditApi.list,
596
+ },
597
+ webhook: {
598
+ endpoint: webhookApi.endpoint,
599
+ delivery: {
600
+ list: webhookApi.delivery.list,
601
+ },
602
+ },
603
+ },
604
+ client: {
605
+ signIn: oidcApi.signIn,
606
+ metadata: samlApi.metadata,
607
+ },
608
+ };
609
+
610
+ return {
611
+ signIn: authResult.signIn,
612
+ signOut: authResult.signOut,
613
+ store: authResult.store,
614
+ user: authResult.auth.user,
615
+ session: authResult.auth.session,
616
+ provider: authResult.auth.provider,
617
+ account: authResult.auth.account,
618
+ group: authResult.auth.group,
619
+ member: authResult.auth.member,
620
+ invite: authResult.auth.invite,
621
+ key: authResult.auth.key,
622
+ sso: publicSso,
623
+ scim: {
624
+ admin: {
625
+ configure: scimApi.configure,
626
+ get: scimApi.get,
627
+ validate: scimApi.validate,
628
+ },
629
+ },
630
+ http: authResult.auth.http,
631
+
632
+ resolve: (ctx: any) => resolveAuthContext(authResult.auth, ctx),
633
+
634
+ ctx: () => ({
635
+ args: {},
636
+ input: async (ctx: any) => {
637
+ const authCtx = await resolveAuthContext(authResult.auth, ctx);
638
+ return { ctx: { auth: authCtx }, args: {} };
639
+ },
640
+ }),
641
+ } as unknown as ConvexAuthResult<P, TAuthorization>;
158
642
  }
159
643
 
160
644
  // ============================================================================
161
645
  // AuthCtx — ctx enrichment for customQuery / customMutation
162
646
  // ============================================================================
163
647
 
164
- /**
165
- * The shape of a user document from the auth component's `user` table.
166
- *
167
- * Includes system fields (`_id`, `_creationTime`) plus the schema fields
168
- * (`name`, `email`, `image`, `extend`, etc.).
169
- */
170
- export type UserDoc = Doc<"user">;
648
+ /** Canonical user document type exposed by Convex Auth. */
649
+ export type UserDoc = Doc<"User">;
171
650
 
172
651
  /**
173
- * Configuration for auth context enrichment.
652
+ * Configuration for {@link AuthCtx} context enrichment.
174
653
  *
175
- * @typeParam TResolve - The shape returned by the `resolve` callback.
176
- * Inferred automatically you usually don't need to supply this manually.
654
+ * @typeParam TResolve - Extra fields returned from `resolve()` and merged into
655
+ * the resulting `ctx.auth` object.
177
656
  */
178
657
  export type AuthCtxConfig<
179
658
  TResolve extends Record<string, unknown> = Record<string, never>,
180
659
  > = {
181
- /**
182
- * When `true`, unauthenticated requests set `ctx.auth.userId` and
183
- * `ctx.auth.user` to `null` instead of throwing.
184
- *
185
- * @default false
186
- */
660
+ /** Allow unauthenticated callers and return `userId: null` / `user: null`. */
187
661
  optional?: boolean;
188
662
  /**
189
- * Resolve additional context after authentication succeeds (e.g.
190
- * group/role for multi-tenant apps). The returned object is spread
191
- * into `ctx.auth`.
663
+ * Attach additional derived fields to the auth context after the user is resolved.
192
664
  */
193
- resolve?: (
194
- ctx: any,
195
- user: UserDoc,
196
- ) => Promise<TResolve> | TResolve;
665
+ resolve?: (ctx: any, user: UserDoc) => Promise<TResolve> | TResolve;
197
666
  };
198
667
 
199
668
  /**
200
- * Create a `convex-helpers`–compatible customization object that
201
- * enriches `ctx.auth` with the authenticated user's data.
202
- *
203
- * Standalone function (not a class method) because Convex's bundler
204
- * can trace `export const x = fn(instance)` but not `instance.method()`.
205
- *
206
- * ### Basic usage (with `convex-helpers`)
669
+ * Create a context enrichment for `customQuery` / `customMutation` — optional auth.
207
670
  *
208
- * ```ts
209
- * // convex/functions.ts
210
- * import { customQuery, customMutation } from "convex-helpers/server/customFunctions";
211
- * import { query as rawQuery, mutation as rawMutation } from "./_generated/server";
212
- * import { AuthCtx } from "\@robelest/convex-auth/component";
213
- * import { auth } from "./auth";
214
- *
215
- * const authCtx = AuthCtx(auth);
216
- *
217
- * export const query = customQuery(rawQuery, authCtx);
218
- * export const mutation = customMutation(rawMutation, authCtx);
219
- * ```
220
- *
221
- * Then in any function file:
671
+ * When `optional: true` is set, unauthenticated requests are allowed.
672
+ * The enriched `ctx.auth` will have `userId: null` and `user: null`
673
+ * for unauthenticated callers.
222
674
  *
223
- * ```ts
224
- * // convex/messages.ts
225
- * import { query, mutation } from "./functions";
226
- *
227
- * export const list = query({
228
- * args: {},
229
- * handler: async (ctx) => {
230
- * // ctx.auth.userId and ctx.auth.user are already resolved
231
- * return ctx.db.query("messages").collect();
232
- * },
233
- * });
234
- * ```
235
- *
236
- * ### Optional auth (public routes)
237
- *
238
- * ```ts
239
- * export const publicQuery = customQuery(rawQuery, AuthCtx(auth, { optional: true }));
240
- * // ctx.auth.userId is null when unauthenticated
241
- * ```
242
- *
243
- * ### Multi-tenant with group resolution
675
+ * @param auth - The auth API object returned by {@link createAuth}.
676
+ * @param config - Configuration with `optional: true` and an optional
677
+ * `resolve` callback for attaching extra fields to the auth context.
678
+ * @returns An object with `args` and `input` compatible with Convex
679
+ * custom function builders.
244
680
  *
681
+ * @example
245
682
  * ```ts
246
683
  * const authCtx = AuthCtx(auth, {
247
- * resolve: async (ctx, user) => {
248
- * const groupId = user?.extend?.lastActiveGroup;
249
- * const membership = await auth.user.group.get(ctx, {
250
- * userId: user._id,
251
- * groupId,
252
- * });
253
- * return { groupId, role: membership?.role ?? "member" };
254
- * },
684
+ * optional: true,
685
+ * resolve: async (_ctx, user) => ({ plan: user?.extend?.plan ?? null }),
255
686
  * });
256
- * // ctx.auth.groupId and ctx.auth.role available in handlers
257
687
  * ```
258
688
  *
259
- * @param auth - The `Auth` class instance from your `convex/auth.ts`.
260
- * @param config - Optional configuration for optional auth and group resolution.
261
- * @returns A `{ args, input }` customization object compatible with
262
- * `customQuery` / `customMutation` from `convex-helpers`.
263
- */
264
- /**
265
- * Overload: optional auth — `userId` and `user` may be `null`.
689
+ * @see {@link createAuth}
266
690
  */
267
691
  export function AuthCtx<
268
692
  TResolve extends Record<string, unknown> = Record<string, never>,
269
693
  >(
270
- auth: Auth,
694
+ auth: AuthLike,
271
695
  config: AuthCtxConfig<TResolve> & { optional: true },
272
696
  ): {
273
697
  args: {};
@@ -279,7 +703,7 @@ export function AuthCtx<
279
703
  ctx: {
280
704
  auth: {
281
705
  getUserIdentity: () => Promise<UserIdentity | null>;
282
- userId: GenericId<"user"> | null;
706
+ userId: GenericId<"User"> | null;
283
707
  user: UserDoc | null;
284
708
  } & TResolve;
285
709
  };
@@ -287,12 +711,32 @@ export function AuthCtx<
287
711
  }>;
288
712
  };
289
713
  /**
290
- * Overload: required auth (default) `userId` and `user` are never `null`.
714
+ * Create a context enrichment for `customQuery` / `customMutation` required auth (default).
715
+ *
716
+ * When `optional` is omitted or `false`, the inferred type is the authenticated
717
+ * auth shape. At runtime this helper still resolves instead of throwing, so if
718
+ * no user is signed in the returned `ctx.auth.userId` and `ctx.auth.user` are
719
+ * `null`.
720
+ *
721
+ * @param auth - The auth API object returned by {@link createAuth}.
722
+ * @param config - Optional configuration with a `resolve` callback
723
+ * for attaching extra fields to the auth context.
724
+ * @returns An object with `args` and `input` compatible with Convex
725
+ * custom function builders.
726
+ *
727
+ * @example
728
+ * ```ts
729
+ * const authCtx = AuthCtx(auth, {
730
+ * resolve: async (_ctx, user) => ({ email: user.email }),
731
+ * });
732
+ * ```
733
+ *
734
+ * @see {@link createAuth}
291
735
  */
292
736
  export function AuthCtx<
293
737
  TResolve extends Record<string, unknown> = Record<string, never>,
294
738
  >(
295
- auth: Auth,
739
+ auth: AuthLike,
296
740
  config?: AuthCtxConfig<TResolve>,
297
741
  ): {
298
742
  args: {};
@@ -304,7 +748,7 @@ export function AuthCtx<
304
748
  ctx: {
305
749
  auth: {
306
750
  getUserIdentity: () => Promise<UserIdentity | null>;
307
- userId: GenericId<"user">;
751
+ userId: GenericId<"User">;
308
752
  user: UserDoc;
309
753
  } & TResolve;
310
754
  };
@@ -312,58 +756,60 @@ export function AuthCtx<
312
756
  }>;
313
757
  };
314
758
  // Implementation
315
- export function AuthCtx(auth: Auth, config?: AuthCtxConfig<any>) {
316
- const authHelper = (auth as any)._auth;
317
-
759
+ export function AuthCtx(auth: AuthLike, config?: AuthCtxConfig<any>) {
318
760
  return {
319
761
  args: {},
320
762
  input: async (ctx: any, _args: any, _extra?: any) => {
321
763
  const nativeAuth = ctx.auth;
764
+ const modeDispatch =
765
+ config?.optional === true
766
+ ? { mode: "optional" as const }
767
+ : { mode: "required" as const };
322
768
 
323
- if (config?.optional) {
324
- const userId = await authHelper.user.current(ctx);
325
- if (!userId) {
326
- return {
327
- ctx: {
328
- auth: {
329
- getUserIdentity: nativeAuth.getUserIdentity.bind(nativeAuth),
330
- userId: null,
331
- user: null,
332
- },
333
- },
334
- args: {},
335
- };
336
- }
337
- const user = await authHelper.user.get(ctx, userId);
338
- const extra = config.resolve
339
- ? await config.resolve(ctx, user)
340
- : {};
769
+ const userContext = await Fx.run(
770
+ Fx.match(modeDispatch, modeDispatch.mode, {
771
+ optional: async () => {
772
+ const userId = await auth.user.id(ctx);
773
+ if (!userId) {
774
+ return null;
775
+ }
776
+ const user = await auth.user.get(ctx, userId);
777
+ return { userId, user };
778
+ },
779
+ required: async () => {
780
+ const userId = await auth.user.id(ctx);
781
+ if (!userId) {
782
+ return null;
783
+ }
784
+ const user = await auth.user.get(ctx, userId);
785
+ return { userId, user };
786
+ },
787
+ }),
788
+ );
789
+
790
+ if (userContext === null) {
341
791
  return {
342
792
  ctx: {
343
793
  auth: {
344
794
  getUserIdentity: nativeAuth.getUserIdentity.bind(nativeAuth),
345
- userId,
346
- user,
347
- ...extra,
795
+ userId: null,
796
+ user: null,
348
797
  },
349
798
  },
350
799
  args: {},
351
800
  };
352
801
  }
353
802
 
354
- // Required mode (default): throws NOT_SIGNED_IN
355
- const userId = await authHelper.user.require(ctx);
356
- const user = await authHelper.user.get(ctx, userId);
357
803
  const extra = config?.resolve
358
- ? await config.resolve(ctx, user)
804
+ ? await config.resolve(ctx, userContext.user)
359
805
  : {};
360
806
 
361
807
  return {
362
808
  ctx: {
363
809
  auth: {
364
810
  getUserIdentity: nativeAuth.getUserIdentity.bind(nativeAuth),
365
- userId,
366
- user,
811
+ userId: userContext.userId,
812
+ user: userContext.user,
367
813
  ...extra,
368
814
  },
369
815
  },
@@ -374,19 +820,27 @@ export function AuthCtx(auth: Auth, config?: AuthCtxConfig<any>) {
374
820
  }
375
821
 
376
822
  /**
377
- * Extract the `ctx.auth` shape from an {@link AuthCtx} result.
823
+ * Extract the resolved `auth` context type from an {@link AuthCtx} instance.
378
824
  *
379
- * Follows the same pattern as `Infer<typeof validator>` in Convex
380
- * and `z.infer<typeof schema>` in Zod.
825
+ * Use this to type function parameters or variables that receive the
826
+ * enriched auth context produced by `AuthCtx`. The inferred type includes
827
+ * `userId`, `user`, `getUserIdentity`, and any additional fields added
828
+ * by the `resolve` callback. This is the generic utility for reusing the
829
+ * enriched auth shape without manually duplicating conditional auth types.
830
+ *
831
+ * @typeParam T - An `AuthCtx` return value (must have an `input` method
832
+ * that returns `{ ctx: { auth: ... } }`).
381
833
  *
382
834
  * @example
383
835
  * ```ts
384
836
  * const authCtx = AuthCtx(auth, {
385
- * resolve: async (ctx, user) => ({ groupId: "abc", role: "admin" }),
837
+ * resolve: async (ctx, user) => ({ orgId: user.orgId }),
386
838
  * });
387
- * type MyAuth = InferAuth<typeof authCtx>;
388
- * // { getUserIdentity, userId, user, groupId: string, role: string }
839
+ * type Auth = InferAuth<typeof authCtx>;
840
+ * // Auth = { userId: Id<"User">; user: UserDoc; getUserIdentity: ...; orgId: string }
389
841
  * ```
842
+ *
843
+ * @see {@link createAuth}
390
844
  */
391
845
  export type InferAuth<
392
846
  T extends { input: (...args: any[]) => Promise<{ ctx: { auth: any } }> },