@gatwech/auth 1.0.0-beta.18

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 (422) hide show
  1. package/README.md +31 -0
  2. package/dist/access-BO2g7QVe.mjs +45 -0
  3. package/dist/access-C6O_osEz.mjs +79 -0
  4. package/dist/access-DT1f6l5k.mjs +51 -0
  5. package/dist/adapter-factory-BZ2Qiqpn.mjs +640 -0
  6. package/dist/adapters/drizzle-adapter/index.d.mts +47 -0
  7. package/dist/adapters/drizzle-adapter/index.mjs +208 -0
  8. package/dist/adapters/index.d.mts +132 -0
  9. package/dist/adapters/index.mjs +18 -0
  10. package/dist/adapters/kysely-adapter/index.d.mts +47 -0
  11. package/dist/adapters/kysely-adapter/index.mjs +11 -0
  12. package/dist/adapters/memory-adapter/index.d.mts +14 -0
  13. package/dist/adapters/memory-adapter/index.mjs +154 -0
  14. package/dist/adapters/mongodb-adapter/index.d.mts +35 -0
  15. package/dist/adapters/mongodb-adapter/index.mjs +315 -0
  16. package/dist/adapters/prisma-adapter/index.d.mts +34 -0
  17. package/dist/adapters/prisma-adapter/index.mjs +159 -0
  18. package/dist/adapters/test.d.mts +81 -0
  19. package/dist/adapters/test.mjs +793 -0
  20. package/dist/admin-Bcq53Nwj.mjs +743 -0
  21. package/dist/admin-DtfO1PLg.d.mts +1689 -0
  22. package/dist/anonymous-CRt1imBW.mjs +107 -0
  23. package/dist/api/index.d.mts +6 -0
  24. package/dist/api/index.mjs +17 -0
  25. package/dist/api-0pR_I-Nx.mjs +3139 -0
  26. package/dist/auth-CBUoBX6o.mjs +233 -0
  27. package/dist/bearer-Djf_awfo.mjs +63 -0
  28. package/dist/bun-sqlite-dialect-CeNvMaZz.mjs +155 -0
  29. package/dist/captcha-BqaMxlKC.mjs +178 -0
  30. package/dist/chunk-BK_LfMhE.mjs +40 -0
  31. package/dist/client/index.d.mts +186 -0
  32. package/dist/client/index.mjs +7 -0
  33. package/dist/client/plugins/index.d.mts +949 -0
  34. package/dist/client/plugins/index.mjs +539 -0
  35. package/dist/client/react/index.d.mts +179 -0
  36. package/dist/client/react/index.mjs +69 -0
  37. package/dist/client-BOX93C3d.d.mts +1250 -0
  38. package/dist/client-CNY0tn9g.d.mts +628 -0
  39. package/dist/client-CygJhqeB.mjs +29 -0
  40. package/dist/client-WiN43tAS.mjs +17 -0
  41. package/dist/client-aExCkfwm.mjs +30 -0
  42. package/dist/cookies/index.d.mts +7 -0
  43. package/dist/cookies/index.mjs +7 -0
  44. package/dist/cookies-cJObLwn1.mjs +597 -0
  45. package/dist/crypto/index.d.mts +44 -0
  46. package/dist/crypto/index.mjs +4 -0
  47. package/dist/crypto-Bb42eMrH.mjs +70 -0
  48. package/dist/custom-session-L3t7ecsd.mjs +67 -0
  49. package/dist/date-Cx2yCiC4.mjs +115 -0
  50. package/dist/db/index.d.mts +7 -0
  51. package/dist/db/index.mjs +15 -0
  52. package/dist/db-BrstmDhc.mjs +1124 -0
  53. package/dist/device-authorization-V4s3h4Mj.mjs +557 -0
  54. package/dist/dialect-CeddeGHf.mjs +72 -0
  55. package/dist/email-otp-BtDHSw14.mjs +592 -0
  56. package/dist/esm-C-QicDNz.mjs +4090 -0
  57. package/dist/generic-oauth-CL5X27ZI.mjs +445 -0
  58. package/dist/get-request-ip-DSjrEpGo.mjs +27 -0
  59. package/dist/get-tables-BQP7YW9c.mjs +249 -0
  60. package/dist/has-permission-BpAr7uCn.mjs +14 -0
  61. package/dist/haveibeenpwned-cMpJvmzI.mjs +43 -0
  62. package/dist/helper-tmxW3BHj.d.mts +21 -0
  63. package/dist/index-34ONrP8l.d.mts +503 -0
  64. package/dist/index-65G5U5DB-DSdjzreF.d.mts +2543 -0
  65. package/dist/index-B-XKqFvY.d.mts +30 -0
  66. package/dist/index-B3n8e37d.d.mts +165 -0
  67. package/dist/index-BBm8nQ9Q.d.mts +42 -0
  68. package/dist/index-BHoQlf7a.d.mts +7699 -0
  69. package/dist/index-BYMI9r_d.d.mts +257 -0
  70. package/dist/index-BqhKCbPH.d.mts +36 -0
  71. package/dist/index-Buhn3hkR.d.mts +433 -0
  72. package/dist/index-C-u1h_WX.d.mts +174 -0
  73. package/dist/index-C7fQuk-V.d.mts +41 -0
  74. package/dist/index-CM-CFWwr.d.mts +1919 -0
  75. package/dist/index-CuFzhoS6.d.mts +359 -0
  76. package/dist/index-Cxi7TbLE.d.mts +11347 -0
  77. package/dist/index-DB7t8whN.d.mts +1 -0
  78. package/dist/index-DKNNV1kb.d.mts +626 -0
  79. package/dist/index-DR0xXno9.d.mts +113 -0
  80. package/dist/index-D_k662QG.d.mts +833 -0
  81. package/dist/index-DaBcikv9.d.mts +118 -0
  82. package/dist/index-DlaMq1nb.d.mts +955 -0
  83. package/dist/index-DoXZYQpq.d.mts +290 -0
  84. package/dist/index-G6V0Z_Mn.d.mts +125 -0
  85. package/dist/index-z0KSvE5i.d.mts +246 -0
  86. package/dist/index-zjjNBRY2.d.mts +95 -0
  87. package/dist/index.d.mts +12 -0
  88. package/dist/index.mjs +33 -0
  89. package/dist/integrations/next-js.d.mts +21 -0
  90. package/dist/integrations/next-js.mjs +62 -0
  91. package/dist/integrations/node.d.mts +15 -0
  92. package/dist/integrations/node.mjs +15 -0
  93. package/dist/integrations/react-start.d.mts +15 -0
  94. package/dist/integrations/react-start.mjs +46 -0
  95. package/dist/json-D0TBLy4q.mjs +24 -0
  96. package/dist/jwt-CmxZAGe2.mjs +94 -0
  97. package/dist/jwt-lHV4QHpD.mjs +387 -0
  98. package/dist/kysely-adapter-DpzYO8Yf.mjs +181 -0
  99. package/dist/magic-link-Bk-ueorR.mjs +176 -0
  100. package/dist/misc-beA1w3XV.mjs +7 -0
  101. package/dist/multi-session-DRrLKrg9.mjs +144 -0
  102. package/dist/node-sqlite-dialect-BcKxBQnm.mjs +155 -0
  103. package/dist/oauth-proxy-D1sWh9B_.mjs +133 -0
  104. package/dist/oauth2/index.d.mts +60 -0
  105. package/dist/oauth2/index.mjs +19 -0
  106. package/dist/one-tap-DMswkTEc.mjs +113 -0
  107. package/dist/organization-BArHO_5v.mjs +3857 -0
  108. package/dist/parser-DcrIEuXE.mjs +73 -0
  109. package/dist/passkey-CcD4CnhM.mjs +558 -0
  110. package/dist/password-sVC4nePO.mjs +25 -0
  111. package/dist/permission-DLYUF3cW.mjs +15 -0
  112. package/dist/phone-number-rHDIlh-2.mjs +485 -0
  113. package/dist/plugin-helper-4L-lzsjZ.mjs +16 -0
  114. package/dist/plugins/access/index.d.mts +3 -0
  115. package/dist/plugins/access/index.mjs +3 -0
  116. package/dist/plugins/admin/access/index.d.mts +116 -0
  117. package/dist/plugins/admin/access/index.mjs +4 -0
  118. package/dist/plugins/admin/index.d.mts +9 -0
  119. package/dist/plugins/admin/index.mjs +22 -0
  120. package/dist/plugins/anonymous/index.d.mts +7 -0
  121. package/dist/plugins/anonymous/index.mjs +18 -0
  122. package/dist/plugins/bearer/index.d.mts +2 -0
  123. package/dist/plugins/bearer/index.mjs +8 -0
  124. package/dist/plugins/captcha/index.d.mts +2 -0
  125. package/dist/plugins/captcha/index.mjs +4 -0
  126. package/dist/plugins/custom-session/index.d.mts +7 -0
  127. package/dist/plugins/custom-session/index.mjs +19 -0
  128. package/dist/plugins/device-authorization/index.d.mts +4 -0
  129. package/dist/plugins/device-authorization/index.mjs +18 -0
  130. package/dist/plugins/email-otp/index.d.mts +3 -0
  131. package/dist/plugins/email-otp/index.mjs +19 -0
  132. package/dist/plugins/generic-oauth/index.d.mts +7 -0
  133. package/dist/plugins/generic-oauth/index.mjs +18 -0
  134. package/dist/plugins/haveibeenpwned/index.d.mts +2 -0
  135. package/dist/plugins/haveibeenpwned/index.mjs +18 -0
  136. package/dist/plugins/index.d.mts +139 -0
  137. package/dist/plugins/index.mjs +47 -0
  138. package/dist/plugins/jwt/index.d.mts +7 -0
  139. package/dist/plugins/jwt/index.mjs +18 -0
  140. package/dist/plugins/magic-link/index.d.mts +2 -0
  141. package/dist/plugins/magic-link/index.mjs +18 -0
  142. package/dist/plugins/multi-session/index.d.mts +3 -0
  143. package/dist/plugins/multi-session/index.mjs +18 -0
  144. package/dist/plugins/oauth-proxy/index.d.mts +2 -0
  145. package/dist/plugins/oauth-proxy/index.mjs +18 -0
  146. package/dist/plugins/one-tap/index.d.mts +2 -0
  147. package/dist/plugins/one-tap/index.mjs +18 -0
  148. package/dist/plugins/one-time-token/index.d.mts +7 -0
  149. package/dist/plugins/one-time-token/index.mjs +47 -0
  150. package/dist/plugins/organization/access/index.d.mts +4 -0
  151. package/dist/plugins/organization/access/index.mjs +4 -0
  152. package/dist/plugins/organization/index.d.mts +9 -0
  153. package/dist/plugins/organization/index.mjs +22 -0
  154. package/dist/plugins/passkey/index.d.mts +7 -0
  155. package/dist/plugins/passkey/index.mjs +18 -0
  156. package/dist/plugins/phone-number/index.d.mts +7 -0
  157. package/dist/plugins/phone-number/index.mjs +18 -0
  158. package/dist/plugins/two-factor/index.d.mts +7 -0
  159. package/dist/plugins/two-factor/index.mjs +20 -0
  160. package/dist/plugins/username/index.d.mts +4 -0
  161. package/dist/plugins/username/index.mjs +18 -0
  162. package/dist/plugins-3jfNste3.mjs +1544 -0
  163. package/dist/plugins-hFZT3hmK.d.mts +14 -0
  164. package/dist/promise-8rrEHRXd.mjs +23154 -0
  165. package/dist/proxy-CL9PZXJA.mjs +441 -0
  166. package/dist/session-Dgp133Yt.mjs +413 -0
  167. package/dist/social-providers/index.d.mts +1 -0
  168. package/dist/social-providers/index.mjs +3 -0
  169. package/dist/src/adapters/adapter-factory/index.d.ts +10 -0
  170. package/dist/src/adapters/adapter-factory/types.d.ts +124 -0
  171. package/dist/src/adapters/create-test-suite.d.ts +97 -0
  172. package/dist/src/adapters/drizzle-adapter/drizzle-adapter.d.ts +43 -0
  173. package/dist/src/adapters/drizzle-adapter/index.d.ts +1 -0
  174. package/dist/src/adapters/drizzle-adapter/test/generate-schema.d.ts +12 -0
  175. package/dist/src/adapters/index.d.ts +21 -0
  176. package/dist/src/adapters/kysely-adapter/bun-sqlite-dialect.d.ts +58 -0
  177. package/dist/src/adapters/kysely-adapter/dialect.d.ts +13 -0
  178. package/dist/src/adapters/kysely-adapter/index.d.ts +3 -0
  179. package/dist/src/adapters/kysely-adapter/kysely-adapter.d.ts +32 -0
  180. package/dist/src/adapters/kysely-adapter/node-sqlite-dialect.d.ts +58 -0
  181. package/dist/src/adapters/kysely-adapter/types.d.ts +1 -0
  182. package/dist/src/adapters/memory-adapter/index.d.ts +1 -0
  183. package/dist/src/adapters/memory-adapter/memory-adapter.d.ts +9 -0
  184. package/dist/src/adapters/mongodb-adapter/index.d.ts +1 -0
  185. package/dist/src/adapters/mongodb-adapter/mongodb-adapter.d.ts +31 -0
  186. package/dist/src/adapters/prisma-adapter/index.d.ts +1 -0
  187. package/dist/src/adapters/prisma-adapter/prisma-adapter.d.ts +32 -0
  188. package/dist/src/adapters/prisma-adapter/test/auth.d.ts +3 -0
  189. package/dist/src/adapters/prisma-adapter/test/generate-auth-config.d.ts +2 -0
  190. package/dist/src/adapters/prisma-adapter/test/generate-prisma-schema.d.ts +3 -0
  191. package/dist/src/adapters/prisma-adapter/test/get-prisma-client.d.ts +7 -0
  192. package/dist/src/adapters/prisma-adapter/test/push-prisma-schema.d.ts +1 -0
  193. package/dist/src/adapters/test-adapter.d.ts +61 -0
  194. package/dist/src/adapters/test.d.ts +78 -0
  195. package/dist/src/adapters/tests/auth-flow.d.ts +22 -0
  196. package/dist/src/adapters/tests/index.d.ts +5 -0
  197. package/dist/src/adapters/tests/normal.d.ts +87 -0
  198. package/dist/src/adapters/tests/number-id.d.ts +17 -0
  199. package/dist/src/adapters/tests/performance.d.ts +24 -0
  200. package/dist/src/adapters/tests/transactions.d.ts +20 -0
  201. package/dist/src/adapters/utils.d.ts +3 -0
  202. package/dist/src/api/index.d.ts +7150 -0
  203. package/dist/src/api/middlewares/index.d.ts +2 -0
  204. package/dist/src/api/middlewares/oauth.d.ts +15 -0
  205. package/dist/src/api/middlewares/origin-check.d.ts +8 -0
  206. package/dist/src/api/rate-limiter/index.d.ts +13 -0
  207. package/dist/src/api/routes/account.d.ts +623 -0
  208. package/dist/src/api/routes/callback.d.ts +68 -0
  209. package/dist/src/api/routes/email-verification.d.ts +266 -0
  210. package/dist/src/api/routes/error.d.ts +51 -0
  211. package/dist/src/api/routes/index.d.ts +11 -0
  212. package/dist/src/api/routes/ok.d.ts +61 -0
  213. package/dist/src/api/routes/reset-password.d.ts +203 -0
  214. package/dist/src/api/routes/session.d.ts +586 -0
  215. package/dist/src/api/routes/sign-in.d.ts +298 -0
  216. package/dist/src/api/routes/sign-out.d.ts +59 -0
  217. package/dist/src/api/routes/sign-up.d.ts +625 -0
  218. package/dist/src/api/routes/update-user.d.ts +862 -0
  219. package/dist/src/api/to-auth-endpoints.d.ts +3 -0
  220. package/dist/src/auth.d.ts +25 -0
  221. package/dist/src/client/broadcast-channel.d.ts +12 -0
  222. package/dist/src/client/config.d.ts +85 -0
  223. package/dist/src/client/fetch-plugins.d.ts +14 -0
  224. package/dist/src/client/index.d.ts +15 -0
  225. package/dist/src/client/parser.d.ts +12 -0
  226. package/dist/src/client/path-to-object.d.ts +63 -0
  227. package/dist/src/client/plugins/index.d.ts +21 -0
  228. package/dist/src/client/plugins/infer-plugin.d.ts +11 -0
  229. package/dist/src/client/proxy.d.ts +8 -0
  230. package/dist/src/client/query.d.ts +16 -0
  231. package/dist/src/client/react/index.d.ts +130 -0
  232. package/dist/src/client/react/react-store.d.ts +43 -0
  233. package/dist/src/client/session-atom.d.ts +18 -0
  234. package/dist/src/client/session-refresh.d.ts +17 -0
  235. package/dist/src/client/test-plugin.d.ts +147 -0
  236. package/dist/src/client/types.d.ts +49 -0
  237. package/dist/src/client/vanilla.d.ts +124 -0
  238. package/dist/src/cookies/check-cookies.d.ts +4 -0
  239. package/dist/src/cookies/cookie-utils.d.ts +16 -0
  240. package/dist/src/cookies/index.d.ts +56 -0
  241. package/dist/src/cookies/session-store.d.ts +43 -0
  242. package/dist/src/crypto/buffer.d.ts +4 -0
  243. package/dist/src/crypto/index.d.ts +14 -0
  244. package/dist/src/crypto/jwt.d.ts +4 -0
  245. package/dist/src/crypto/password.d.ts +5 -0
  246. package/dist/src/crypto/random.d.ts +1 -0
  247. package/dist/src/db/field.d.ts +97 -0
  248. package/dist/src/db/get-migration.d.ts +18 -0
  249. package/dist/src/db/get-schema.d.ts +6 -0
  250. package/dist/src/db/get-tables.d.ts +3 -0
  251. package/dist/src/db/index.d.ts +10 -0
  252. package/dist/src/db/internal-adapter.d.ts +9 -0
  253. package/dist/src/db/schema.d.ts +76 -0
  254. package/dist/src/db/to-zod.d.ts +31 -0
  255. package/dist/src/db/utils.d.ts +6 -0
  256. package/dist/src/db/with-hooks.d.ts +27 -0
  257. package/dist/src/index.d.ts +14 -0
  258. package/dist/src/init.d.ts +2 -0
  259. package/dist/src/integrations/next-js.d.ts +15 -0
  260. package/dist/src/integrations/node.d.ts +6 -0
  261. package/dist/src/integrations/react-start.d.ts +9 -0
  262. package/dist/src/oauth2/index.d.ts +4 -0
  263. package/dist/src/oauth2/link-account.d.ts +41 -0
  264. package/dist/src/oauth2/state.d.ts +21 -0
  265. package/dist/src/oauth2/utils.d.ts +3 -0
  266. package/dist/src/plugins/access/access.d.ts +25 -0
  267. package/dist/src/plugins/access/index.d.ts +2 -0
  268. package/dist/src/plugins/access/types.d.ts +14 -0
  269. package/dist/src/plugins/additional-fields/client.d.ts +91 -0
  270. package/dist/src/plugins/admin/access/index.d.ts +1 -0
  271. package/dist/src/plugins/admin/access/statement.d.ts +110 -0
  272. package/dist/src/plugins/admin/admin.d.ts +1570 -0
  273. package/dist/src/plugins/admin/client.d.ts +62 -0
  274. package/dist/src/plugins/admin/error-codes.d.ts +21 -0
  275. package/dist/src/plugins/admin/has-permission.d.ts +21 -0
  276. package/dist/src/plugins/admin/index.d.ts +2 -0
  277. package/dist/src/plugins/admin/schema.d.ts +36 -0
  278. package/dist/src/plugins/admin/types.d.ts +77 -0
  279. package/dist/src/plugins/anonymous/client.d.ts +8 -0
  280. package/dist/src/plugins/anonymous/index.d.ts +159 -0
  281. package/dist/src/plugins/api-key/client.d.ts +11 -0
  282. package/dist/src/plugins/api-key/index.d.ts +1431 -0
  283. package/dist/src/plugins/api-key/rate-limit.d.ts +20 -0
  284. package/dist/src/plugins/api-key/routes/create-api-key.d.ts +244 -0
  285. package/dist/src/plugins/api-key/routes/delete-all-expired-api-keys.d.ts +45 -0
  286. package/dist/src/plugins/api-key/routes/delete-api-key.d.ts +112 -0
  287. package/dist/src/plugins/api-key/routes/get-api-key.d.ts +234 -0
  288. package/dist/src/plugins/api-key/routes/index.d.ts +1136 -0
  289. package/dist/src/plugins/api-key/routes/list-api-keys.d.ts +231 -0
  290. package/dist/src/plugins/api-key/routes/update-api-key.d.ts +235 -0
  291. package/dist/src/plugins/api-key/routes/verify-api-key.d.ts +80 -0
  292. package/dist/src/plugins/api-key/schema.d.ts +188 -0
  293. package/dist/src/plugins/api-key/types.d.ts +285 -0
  294. package/dist/src/plugins/bearer/index.d.ts +31 -0
  295. package/dist/src/plugins/captcha/constants.d.ts +9 -0
  296. package/dist/src/plugins/captcha/error-codes.d.ts +9 -0
  297. package/dist/src/plugins/captcha/index.d.ts +7 -0
  298. package/dist/src/plugins/captcha/types.d.ts +23 -0
  299. package/dist/src/plugins/captcha/utils.d.ts +1 -0
  300. package/dist/src/plugins/captcha/verify-handlers/captchafox.d.ts +11 -0
  301. package/dist/src/plugins/captcha/verify-handlers/cloudflare-turnstile.d.ts +10 -0
  302. package/dist/src/plugins/captcha/verify-handlers/google-recaptcha.d.ts +11 -0
  303. package/dist/src/plugins/captcha/verify-handlers/h-captcha.d.ts +11 -0
  304. package/dist/src/plugins/captcha/verify-handlers/index.d.ts +4 -0
  305. package/dist/src/plugins/custom-session/client.d.ts +12 -0
  306. package/dist/src/plugins/custom-session/index.d.ts +89 -0
  307. package/dist/src/plugins/device-authorization/client.d.ts +12 -0
  308. package/dist/src/plugins/device-authorization/index.d.ts +568 -0
  309. package/dist/src/plugins/device-authorization/schema.d.ts +56 -0
  310. package/dist/src/plugins/email-otp/client.d.ts +9 -0
  311. package/dist/src/plugins/email-otp/index.d.ts +826 -0
  312. package/dist/src/plugins/email-otp/utils.d.ts +2 -0
  313. package/dist/src/plugins/generic-oauth/client.d.ts +5 -0
  314. package/dist/src/plugins/generic-oauth/index.d.ts +428 -0
  315. package/dist/src/plugins/haveibeenpwned/index.d.ts +25 -0
  316. package/dist/src/plugins/index.d.ts +28 -0
  317. package/dist/src/plugins/jwt/adapter.d.ts +8 -0
  318. package/dist/src/plugins/jwt/client.d.ts +5 -0
  319. package/dist/src/plugins/jwt/index.d.ts +276 -0
  320. package/dist/src/plugins/jwt/schema.d.ts +18 -0
  321. package/dist/src/plugins/jwt/sign.d.ts +8 -0
  322. package/dist/src/plugins/jwt/types.d.ts +175 -0
  323. package/dist/src/plugins/jwt/utils.d.ts +46 -0
  324. package/dist/src/plugins/last-login-method/client.d.ts +34 -0
  325. package/dist/src/plugins/last-login-method/index.d.ts +103 -0
  326. package/dist/src/plugins/magic-link/client.d.ts +5 -0
  327. package/dist/src/plugins/magic-link/index.d.ts +253 -0
  328. package/dist/src/plugins/magic-link/utils.d.ts +1 -0
  329. package/dist/src/plugins/multi-session/client.d.ts +9 -0
  330. package/dist/src/plugins/multi-session/index.d.ts +284 -0
  331. package/dist/src/plugins/oauth-proxy/index.d.ts +119 -0
  332. package/dist/src/plugins/one-tap/client.d.ts +81 -0
  333. package/dist/src/plugins/one-tap/index.d.ts +114 -0
  334. package/dist/src/plugins/one-time-token/client.d.ts +5 -0
  335. package/dist/src/plugins/one-time-token/index.d.ts +170 -0
  336. package/dist/src/plugins/one-time-token/utils.d.ts +1 -0
  337. package/dist/src/plugins/organization/access/index.d.ts +1 -0
  338. package/dist/src/plugins/organization/access/statement.d.ts +241 -0
  339. package/dist/src/plugins/organization/adapter.d.ts +685 -0
  340. package/dist/src/plugins/organization/call.d.ts +55 -0
  341. package/dist/src/plugins/organization/client.d.ts +344 -0
  342. package/dist/src/plugins/organization/error-codes.d.ts +58 -0
  343. package/dist/src/plugins/organization/has-permission.d.ts +13 -0
  344. package/dist/src/plugins/organization/index.d.ts +4 -0
  345. package/dist/src/plugins/organization/organization.d.ts +412 -0
  346. package/dist/src/plugins/organization/permission.d.ts +27 -0
  347. package/dist/src/plugins/organization/routes/crud-access-control.d.ts +701 -0
  348. package/dist/src/plugins/organization/routes/crud-invites.d.ts +1522 -0
  349. package/dist/src/plugins/organization/routes/crud-members.d.ts +1220 -0
  350. package/dist/src/plugins/organization/routes/crud-org.d.ts +1399 -0
  351. package/dist/src/plugins/organization/routes/crud-team.d.ts +1323 -0
  352. package/dist/src/plugins/organization/schema.d.ts +366 -0
  353. package/dist/src/plugins/organization/types.d.ts +737 -0
  354. package/dist/src/plugins/passkey/client.d.ts +190 -0
  355. package/dist/src/plugins/passkey/error-codes.d.ts +9 -0
  356. package/dist/src/plugins/passkey/index.d.ts +838 -0
  357. package/dist/src/plugins/passkey/schema.d.ts +50 -0
  358. package/dist/src/plugins/passkey/types.d.ts +69 -0
  359. package/dist/src/plugins/passkey/utils.d.ts +2 -0
  360. package/dist/src/plugins/phone-number/client.d.ts +9 -0
  361. package/dist/src/plugins/phone-number/index.d.ts +622 -0
  362. package/dist/src/plugins/phone-number/phone-number-error.d.ts +10 -0
  363. package/dist/src/plugins/two-factor/backup-codes/index.d.ts +387 -0
  364. package/dist/src/plugins/two-factor/client.d.ts +28 -0
  365. package/dist/src/plugins/two-factor/constant.d.ts +2 -0
  366. package/dist/src/plugins/two-factor/error-code.d.ts +11 -0
  367. package/dist/src/plugins/two-factor/index.d.ts +1014 -0
  368. package/dist/src/plugins/two-factor/otp/index.d.ts +282 -0
  369. package/dist/src/plugins/two-factor/schema.d.ts +35 -0
  370. package/dist/src/plugins/two-factor/totp/index.d.ts +298 -0
  371. package/dist/src/plugins/two-factor/types.d.ts +50 -0
  372. package/dist/src/plugins/two-factor/utils.d.ts +1 -0
  373. package/dist/src/plugins/two-factor/verify-two-factor.d.ts +59 -0
  374. package/dist/src/plugins/username/client.d.ts +5 -0
  375. package/dist/src/plugins/username/error-codes.d.ts +10 -0
  376. package/dist/src/plugins/username/index.d.ts +313 -0
  377. package/dist/src/plugins/username/schema.d.ts +27 -0
  378. package/dist/src/social-providers/index.d.ts +1 -0
  379. package/dist/src/test-utils/headers.d.ts +5 -0
  380. package/dist/src/test-utils/index.d.ts +2 -0
  381. package/dist/src/test-utils/test-instance.d.ts +17849 -0
  382. package/dist/src/types/adapter.d.ts +21 -0
  383. package/dist/src/types/api.d.ts +29 -0
  384. package/dist/src/types/helper.d.ts +32 -0
  385. package/dist/src/types/index.d.ts +7 -0
  386. package/dist/src/types/models.d.ts +13 -0
  387. package/dist/src/types/plugins.d.ts +14 -0
  388. package/dist/src/utils/await-object.d.ts +3 -0
  389. package/dist/src/utils/boolean.d.ts +1 -0
  390. package/dist/src/utils/clone.d.ts +1 -0
  391. package/dist/src/utils/constants.d.ts +1 -0
  392. package/dist/src/utils/date.d.ts +1 -0
  393. package/dist/src/utils/ensure-utc.d.ts +1 -0
  394. package/dist/src/utils/get-request-ip.d.ts +2 -0
  395. package/dist/src/utils/hashing.d.ts +6 -0
  396. package/dist/src/utils/hide-metadata.d.ts +3 -0
  397. package/dist/src/utils/id.d.ts +1 -0
  398. package/dist/src/utils/import-util.d.ts +1 -0
  399. package/dist/src/utils/index.d.ts +5 -0
  400. package/dist/src/utils/is-atom.d.ts +2 -0
  401. package/dist/src/utils/is-promise.d.ts +1 -0
  402. package/dist/src/utils/json.d.ts +1 -0
  403. package/dist/src/utils/merger.d.ts +1 -0
  404. package/dist/src/utils/middleware-response.d.ts +8 -0
  405. package/dist/src/utils/misc.d.ts +1 -0
  406. package/dist/src/utils/password.d.ts +6 -0
  407. package/dist/src/utils/plugin-helper.d.ts +5 -0
  408. package/dist/src/utils/shim.d.ts +3 -0
  409. package/dist/src/utils/time.d.ts +4 -0
  410. package/dist/src/utils/url.d.ts +4 -0
  411. package/dist/src/utils/wildcard.d.ts +45 -0
  412. package/dist/test-utils/index.d.mts +17870 -0
  413. package/dist/test-utils/index.mjs +272 -0
  414. package/dist/two-factor-ClUXxom2.mjs +914 -0
  415. package/dist/types/index.d.mts +6 -0
  416. package/dist/types/index.mjs +3 -0
  417. package/dist/types-B1OL7hyf.d.mts +4 -0
  418. package/dist/types-Bjn15Uy6.mjs +1 -0
  419. package/dist/url-VB2gAbTI.mjs +59 -0
  420. package/dist/username-DiGklOGl.mjs +278 -0
  421. package/dist/utils-SOMB4Px5.mjs +132 -0
  422. package/package.json +447 -0
@@ -0,0 +1,73 @@
1
+ //#region src/client/parser.ts
2
+ const PROTO_POLLUTION_PATTERNS = {
3
+ proto: /"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/,
4
+ constructor: /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/,
5
+ protoShort: /"__proto__"\s*:/,
6
+ constructorShort: /"constructor"\s*:/
7
+ };
8
+ const JSON_SIGNATURE = /^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/;
9
+ const SPECIAL_VALUES = {
10
+ true: true,
11
+ false: false,
12
+ null: null,
13
+ undefined: void 0,
14
+ nan: NaN,
15
+ infinity: Number.POSITIVE_INFINITY,
16
+ "-infinity": Number.NEGATIVE_INFINITY
17
+ };
18
+ const ISO_DATE_REGEX = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,7}))?(?:Z|([+-])(\d{2}):(\d{2}))$/;
19
+ function isValidDate(date) {
20
+ return date instanceof Date && !isNaN(date.getTime());
21
+ }
22
+ function parseISODate(value) {
23
+ const match = ISO_DATE_REGEX.exec(value);
24
+ if (!match) return null;
25
+ const [, year, month, day, hour, minute, second, ms, offsetSign, offsetHour, offsetMinute] = match;
26
+ let date = new Date(Date.UTC(parseInt(year, 10), parseInt(month, 10) - 1, parseInt(day, 10), parseInt(hour, 10), parseInt(minute, 10), parseInt(second, 10), ms ? parseInt(ms.padEnd(3, "0"), 10) : 0));
27
+ if (offsetSign) {
28
+ const offset = (parseInt(offsetHour, 10) * 60 + parseInt(offsetMinute, 10)) * (offsetSign === "+" ? -1 : 1);
29
+ date.setUTCMinutes(date.getUTCMinutes() + offset);
30
+ }
31
+ return isValidDate(date) ? date : null;
32
+ }
33
+ function betterJSONParse(value, options = {}) {
34
+ const { strict = false, warnings = false, reviver, parseDates = true } = options;
35
+ if (typeof value !== "string") return value;
36
+ const trimmed = value.trim();
37
+ if (trimmed.length > 0 && trimmed[0] === "\"" && trimmed.endsWith("\"") && !trimmed.slice(1, -1).includes("\"")) return trimmed.slice(1, -1);
38
+ const lowerValue = trimmed.toLowerCase();
39
+ if (lowerValue.length <= 9 && lowerValue in SPECIAL_VALUES) return SPECIAL_VALUES[lowerValue];
40
+ if (!JSON_SIGNATURE.test(trimmed)) {
41
+ if (strict) throw new SyntaxError("[better-json] Invalid JSON");
42
+ return value;
43
+ }
44
+ if (Object.entries(PROTO_POLLUTION_PATTERNS).some(([key, pattern]) => {
45
+ const matches = pattern.test(trimmed);
46
+ if (matches && warnings) console.warn(`[better-json] Detected potential prototype pollution attempt using ${key} pattern`);
47
+ return matches;
48
+ }) && strict) throw new Error("[better-json] Potential prototype pollution attempt detected");
49
+ try {
50
+ const secureReviver = (key, value$1) => {
51
+ if (key === "__proto__" || key === "constructor" && value$1 && typeof value$1 === "object" && "prototype" in value$1) {
52
+ if (warnings) console.warn(`[better-json] Dropping "${key}" key to prevent prototype pollution`);
53
+ return;
54
+ }
55
+ if (parseDates && typeof value$1 === "string") {
56
+ const date = parseISODate(value$1);
57
+ if (date) return date;
58
+ }
59
+ return reviver ? reviver(key, value$1) : value$1;
60
+ };
61
+ return JSON.parse(trimmed, secureReviver);
62
+ } catch (error) {
63
+ if (strict) throw error;
64
+ return value;
65
+ }
66
+ }
67
+ function parseJSON(value, options = { strict: true }) {
68
+ return betterJSONParse(value, options);
69
+ }
70
+ var parser_default = parseJSON;
71
+
72
+ //#endregion
73
+ export { parser_default as n, parseJSON as t };
@@ -0,0 +1,558 @@
1
+ import { t as generateId } from "./utils-SOMB4Px5.mjs";
2
+ import { r as generateRandomString } from "./crypto-Bb42eMrH.mjs";
3
+ import { c as setSessionCookie } from "./cookies-cJObLwn1.mjs";
4
+ import { n as mergeSchema } from "./date-Cx2yCiC4.mjs";
5
+ import { r as getSessionFromCtx, t as freshSessionMiddleware, u as sessionMiddleware } from "./session-Dgp133Yt.mjs";
6
+ import { defineErrorCodes } from "@gatwech/core/utils";
7
+ import { APIError } from "better-call";
8
+ import { createAuthEndpoint } from "@gatwech/core/api";
9
+ import * as z$1 from "zod";
10
+ import { base64 } from "@gatwech/utils/base64";
11
+ import { generateAuthenticationOptions, generateRegistrationOptions, verifyAuthenticationResponse, verifyRegistrationResponse } from "@simplewebauthn/server";
12
+
13
+ //#region src/plugins/passkey/error-codes.ts
14
+ const PASSKEY_ERROR_CODES = defineErrorCodes({
15
+ CHALLENGE_NOT_FOUND: "Challenge not found",
16
+ YOU_ARE_NOT_ALLOWED_TO_REGISTER_THIS_PASSKEY: "You are not allowed to register this passkey",
17
+ FAILED_TO_VERIFY_REGISTRATION: "Failed to verify registration",
18
+ PASSKEY_NOT_FOUND: "Passkey not found",
19
+ AUTHENTICATION_FAILED: "Authentication failed",
20
+ UNABLE_TO_CREATE_SESSION: "Unable to create session",
21
+ FAILED_TO_UPDATE_PASSKEY: "Failed to update passkey"
22
+ });
23
+
24
+ //#endregion
25
+ //#region src/plugins/passkey/schema.ts
26
+ const schema = { passkey: { fields: {
27
+ name: {
28
+ type: "string",
29
+ required: false
30
+ },
31
+ publicKey: {
32
+ type: "string",
33
+ required: true
34
+ },
35
+ userId: {
36
+ type: "string",
37
+ references: {
38
+ model: "user",
39
+ field: "id"
40
+ },
41
+ required: true
42
+ },
43
+ credentialID: {
44
+ type: "string",
45
+ required: true
46
+ },
47
+ counter: {
48
+ type: "number",
49
+ required: true
50
+ },
51
+ deviceType: {
52
+ type: "string",
53
+ required: true
54
+ },
55
+ backedUp: {
56
+ type: "boolean",
57
+ required: true
58
+ },
59
+ transports: {
60
+ type: "string",
61
+ required: false
62
+ },
63
+ createdAt: {
64
+ type: "date",
65
+ required: false
66
+ },
67
+ aaguid: {
68
+ type: "string",
69
+ required: false
70
+ }
71
+ } } };
72
+
73
+ //#endregion
74
+ //#region src/plugins/passkey/utils.ts
75
+ function getRpID(options, baseURL) {
76
+ return options.rpID || (baseURL ? new URL(baseURL).hostname : "localhost");
77
+ }
78
+
79
+ //#endregion
80
+ //#region src/plugins/passkey/index.ts
81
+ const passkey = (options) => {
82
+ const opts = {
83
+ origin: null,
84
+ ...options,
85
+ advanced: {
86
+ webAuthnChallengeCookie: "payvo-auth-passkey",
87
+ ...options?.advanced
88
+ }
89
+ };
90
+ const expirationTime = new Date(Date.now() + 1e3 * 60 * 5);
91
+ const currentTime = /* @__PURE__ */ new Date();
92
+ const maxAgeInSeconds = Math.floor((expirationTime.getTime() - currentTime.getTime()) / 1e3);
93
+ return {
94
+ id: "passkey",
95
+ endpoints: {
96
+ generatePasskeyRegistrationOptions: createAuthEndpoint("/passkey/generate-register-options", {
97
+ method: "GET",
98
+ use: [freshSessionMiddleware],
99
+ query: z$1.object({
100
+ authenticatorAttachment: z$1.enum(["platform", "cross-platform"]).optional(),
101
+ name: z$1.string().optional()
102
+ }).optional(),
103
+ metadata: {
104
+ client: false,
105
+ openapi: {
106
+ description: "Generate registration options for a new passkey",
107
+ responses: { 200: {
108
+ description: "Success",
109
+ parameters: { query: {
110
+ authenticatorAttachment: {
111
+ description: `Type of authenticator to use for registration.
112
+ "platform" for device-specific authenticators,
113
+ "cross-platform" for authenticators that can be used across devices.`,
114
+ required: false
115
+ },
116
+ name: {
117
+ description: `Optional custom name for the passkey.
118
+ This can help identify the passkey when managing multiple credentials.`,
119
+ required: false
120
+ }
121
+ } },
122
+ content: { "application/json": { schema: {
123
+ type: "object",
124
+ properties: {
125
+ challenge: { type: "string" },
126
+ rp: {
127
+ type: "object",
128
+ properties: {
129
+ name: { type: "string" },
130
+ id: { type: "string" }
131
+ }
132
+ },
133
+ user: {
134
+ type: "object",
135
+ properties: {
136
+ id: { type: "string" },
137
+ name: { type: "string" },
138
+ displayName: { type: "string" }
139
+ }
140
+ },
141
+ pubKeyCredParams: {
142
+ type: "array",
143
+ items: {
144
+ type: "object",
145
+ properties: {
146
+ type: { type: "string" },
147
+ alg: { type: "number" }
148
+ }
149
+ }
150
+ },
151
+ timeout: { type: "number" },
152
+ excludeCredentials: {
153
+ type: "array",
154
+ items: {
155
+ type: "object",
156
+ properties: {
157
+ id: { type: "string" },
158
+ type: { type: "string" },
159
+ transports: {
160
+ type: "array",
161
+ items: { type: "string" }
162
+ }
163
+ }
164
+ }
165
+ },
166
+ authenticatorSelection: {
167
+ type: "object",
168
+ properties: {
169
+ authenticatorAttachment: { type: "string" },
170
+ requireResidentKey: { type: "boolean" },
171
+ userVerification: { type: "string" }
172
+ }
173
+ },
174
+ attestation: { type: "string" },
175
+ extensions: { type: "object" }
176
+ }
177
+ } } }
178
+ } }
179
+ }
180
+ }
181
+ }, async (ctx) => {
182
+ const { session } = ctx.context;
183
+ const userPasskeys = await ctx.context.adapter.findMany({
184
+ model: "passkey",
185
+ where: [{
186
+ field: "userId",
187
+ value: session.user.id
188
+ }]
189
+ });
190
+ const userID = new TextEncoder().encode(generateRandomString(32, "a-z", "0-9"));
191
+ let options$1;
192
+ options$1 = await generateRegistrationOptions({
193
+ rpName: opts.rpName || ctx.context.appName,
194
+ rpID: getRpID(opts, ctx.context.options.baseURL),
195
+ userID,
196
+ userName: ctx.query?.name || session.user.email || session.user.id,
197
+ userDisplayName: session.user.email || session.user.id,
198
+ attestationType: "none",
199
+ excludeCredentials: userPasskeys.map((passkey$1) => ({
200
+ id: passkey$1.credentialID,
201
+ transports: passkey$1.transports?.split(",")
202
+ })),
203
+ authenticatorSelection: {
204
+ residentKey: "preferred",
205
+ userVerification: "preferred",
206
+ ...opts.authenticatorSelection || {},
207
+ ...ctx.query?.authenticatorAttachment ? { authenticatorAttachment: ctx.query.authenticatorAttachment } : {}
208
+ }
209
+ });
210
+ const id = generateId(32);
211
+ const webAuthnCookie = ctx.context.createAuthCookie(opts.advanced.webAuthnChallengeCookie);
212
+ await ctx.setSignedCookie(webAuthnCookie.name, id, ctx.context.secret, {
213
+ ...webAuthnCookie.attributes,
214
+ maxAge: maxAgeInSeconds
215
+ });
216
+ await ctx.context.internalAdapter.createVerificationValue({
217
+ identifier: id,
218
+ value: JSON.stringify({
219
+ expectedChallenge: options$1.challenge,
220
+ userData: { id: session.user.id }
221
+ }),
222
+ expiresAt: expirationTime
223
+ });
224
+ return ctx.json(options$1, { status: 200 });
225
+ }),
226
+ generatePasskeyAuthenticationOptions: createAuthEndpoint("/passkey/generate-authenticate-options", {
227
+ method: "POST",
228
+ metadata: { openapi: {
229
+ description: "Generate authentication options for a passkey",
230
+ responses: { 200: {
231
+ description: "Success",
232
+ content: { "application/json": { schema: {
233
+ type: "object",
234
+ properties: {
235
+ challenge: { type: "string" },
236
+ rp: {
237
+ type: "object",
238
+ properties: {
239
+ name: { type: "string" },
240
+ id: { type: "string" }
241
+ }
242
+ },
243
+ user: {
244
+ type: "object",
245
+ properties: {
246
+ id: { type: "string" },
247
+ name: { type: "string" },
248
+ displayName: { type: "string" }
249
+ }
250
+ },
251
+ timeout: { type: "number" },
252
+ allowCredentials: {
253
+ type: "array",
254
+ items: {
255
+ type: "object",
256
+ properties: {
257
+ id: { type: "string" },
258
+ type: { type: "string" },
259
+ transports: {
260
+ type: "array",
261
+ items: { type: "string" }
262
+ }
263
+ }
264
+ }
265
+ },
266
+ userVerification: { type: "string" },
267
+ authenticatorSelection: {
268
+ type: "object",
269
+ properties: {
270
+ authenticatorAttachment: { type: "string" },
271
+ requireResidentKey: { type: "boolean" },
272
+ userVerification: { type: "string" }
273
+ }
274
+ },
275
+ extensions: { type: "object" }
276
+ }
277
+ } } }
278
+ } }
279
+ } }
280
+ }, async (ctx) => {
281
+ const session = await getSessionFromCtx(ctx);
282
+ let userPasskeys = [];
283
+ if (session) userPasskeys = await ctx.context.adapter.findMany({
284
+ model: "passkey",
285
+ where: [{
286
+ field: "userId",
287
+ value: session.user.id
288
+ }]
289
+ });
290
+ const options$1 = await generateAuthenticationOptions({
291
+ rpID: getRpID(opts, ctx.context.options.baseURL),
292
+ userVerification: "preferred",
293
+ ...userPasskeys.length ? { allowCredentials: userPasskeys.map((passkey$1) => ({
294
+ id: passkey$1.credentialID,
295
+ transports: passkey$1.transports?.split(",")
296
+ })) } : {}
297
+ });
298
+ const data = {
299
+ expectedChallenge: options$1.challenge,
300
+ userData: { id: session?.user.id || "" }
301
+ };
302
+ const id = generateId(32);
303
+ const webAuthnCookie = ctx.context.createAuthCookie(opts.advanced.webAuthnChallengeCookie);
304
+ await ctx.setSignedCookie(webAuthnCookie.name, id, ctx.context.secret, {
305
+ ...webAuthnCookie.attributes,
306
+ maxAge: maxAgeInSeconds
307
+ });
308
+ await ctx.context.internalAdapter.createVerificationValue({
309
+ identifier: id,
310
+ value: JSON.stringify(data),
311
+ expiresAt: expirationTime
312
+ });
313
+ return ctx.json(options$1, { status: 200 });
314
+ }),
315
+ verifyPasskeyRegistration: createAuthEndpoint("/passkey/verify-registration", {
316
+ method: "POST",
317
+ body: z$1.object({
318
+ response: z$1.any(),
319
+ name: z$1.string().meta({ description: "Name of the passkey" }).optional()
320
+ }),
321
+ use: [freshSessionMiddleware],
322
+ metadata: { openapi: {
323
+ description: "Verify registration of a new passkey",
324
+ responses: {
325
+ 200: {
326
+ description: "Success",
327
+ content: { "application/json": { schema: { $ref: "#/components/schemas/Passkey" } } }
328
+ },
329
+ 400: { description: "Bad request" }
330
+ }
331
+ } }
332
+ }, async (ctx) => {
333
+ const origin = options?.origin || ctx.headers?.get("origin") || "";
334
+ if (!origin) return ctx.json(null, { status: 400 });
335
+ const resp = ctx.body.response;
336
+ const webAuthnCookie = ctx.context.createAuthCookie(opts.advanced.webAuthnChallengeCookie);
337
+ const challengeId = await ctx.getSignedCookie(webAuthnCookie.name, ctx.context.secret);
338
+ if (!challengeId) throw new APIError("BAD_REQUEST", { message: PASSKEY_ERROR_CODES.CHALLENGE_NOT_FOUND });
339
+ const data = await ctx.context.internalAdapter.findVerificationValue(challengeId);
340
+ if (!data) return ctx.json(null, { status: 400 });
341
+ const { expectedChallenge, userData } = JSON.parse(data.value);
342
+ if (userData.id !== ctx.context.session.user.id) throw new APIError("UNAUTHORIZED", { message: PASSKEY_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_REGISTER_THIS_PASSKEY });
343
+ try {
344
+ const { verified, registrationInfo } = await verifyRegistrationResponse({
345
+ response: resp,
346
+ expectedChallenge,
347
+ expectedOrigin: origin,
348
+ expectedRPID: getRpID(opts, ctx.context.options.baseURL),
349
+ requireUserVerification: false
350
+ });
351
+ if (!verified || !registrationInfo) return ctx.json(null, { status: 400 });
352
+ const { aaguid, credentialDeviceType, credentialBackedUp, credential, credentialType } = registrationInfo;
353
+ const pubKey = base64.encode(credential.publicKey);
354
+ const newPasskey = {
355
+ name: ctx.body.name,
356
+ userId: userData.id,
357
+ credentialID: credential.id,
358
+ publicKey: pubKey,
359
+ counter: credential.counter,
360
+ deviceType: credentialDeviceType,
361
+ transports: resp.response.transports.join(","),
362
+ backedUp: credentialBackedUp,
363
+ createdAt: /* @__PURE__ */ new Date(),
364
+ aaguid
365
+ };
366
+ const newPasskeyRes = await ctx.context.adapter.create({
367
+ model: "passkey",
368
+ data: newPasskey
369
+ });
370
+ return ctx.json(newPasskeyRes, { status: 200 });
371
+ } catch (e) {
372
+ console.log(e);
373
+ throw new APIError("INTERNAL_SERVER_ERROR", { message: PASSKEY_ERROR_CODES.FAILED_TO_VERIFY_REGISTRATION });
374
+ }
375
+ }),
376
+ verifyPasskeyAuthentication: createAuthEndpoint("/passkey/verify-authentication", {
377
+ method: "POST",
378
+ body: z$1.object({ response: z$1.record(z$1.any(), z$1.any()) }),
379
+ metadata: {
380
+ openapi: {
381
+ description: "Verify authentication of a passkey",
382
+ responses: { 200: {
383
+ description: "Success",
384
+ content: { "application/json": { schema: {
385
+ type: "object",
386
+ properties: {
387
+ session: { $ref: "#/components/schemas/Session" },
388
+ user: { $ref: "#/components/schemas/User" }
389
+ }
390
+ } } }
391
+ } }
392
+ },
393
+ $Infer: { body: {} }
394
+ }
395
+ }, async (ctx) => {
396
+ const origin = options?.origin || ctx.headers?.get("origin") || "";
397
+ if (!origin) throw new APIError("BAD_REQUEST", { message: "origin missing" });
398
+ const resp = ctx.body.response;
399
+ const webAuthnCookie = ctx.context.createAuthCookie(opts.advanced.webAuthnChallengeCookie);
400
+ const challengeId = await ctx.getSignedCookie(webAuthnCookie.name, ctx.context.secret);
401
+ if (!challengeId) throw new APIError("BAD_REQUEST", { message: PASSKEY_ERROR_CODES.CHALLENGE_NOT_FOUND });
402
+ const data = await ctx.context.internalAdapter.findVerificationValue(challengeId);
403
+ if (!data) throw new APIError("BAD_REQUEST", { message: PASSKEY_ERROR_CODES.CHALLENGE_NOT_FOUND });
404
+ const { expectedChallenge } = JSON.parse(data.value);
405
+ const passkey$1 = await ctx.context.adapter.findOne({
406
+ model: "passkey",
407
+ where: [{
408
+ field: "credentialID",
409
+ value: resp.id
410
+ }]
411
+ });
412
+ if (!passkey$1) throw new APIError("UNAUTHORIZED", { message: PASSKEY_ERROR_CODES.PASSKEY_NOT_FOUND });
413
+ try {
414
+ const verification = await verifyAuthenticationResponse({
415
+ response: resp,
416
+ expectedChallenge,
417
+ expectedOrigin: origin,
418
+ expectedRPID: getRpID(opts, ctx.context.options.baseURL),
419
+ credential: {
420
+ id: passkey$1.credentialID,
421
+ publicKey: base64.decode(passkey$1.publicKey).slice(),
422
+ counter: passkey$1.counter,
423
+ transports: passkey$1.transports?.split(",")
424
+ },
425
+ requireUserVerification: false
426
+ });
427
+ const { verified } = verification;
428
+ if (!verified) throw new APIError("UNAUTHORIZED", { message: PASSKEY_ERROR_CODES.AUTHENTICATION_FAILED });
429
+ await ctx.context.adapter.update({
430
+ model: "passkey",
431
+ where: [{
432
+ field: "id",
433
+ value: passkey$1.id
434
+ }],
435
+ update: { counter: verification.authenticationInfo.newCounter }
436
+ });
437
+ const s = await ctx.context.internalAdapter.createSession(passkey$1.userId);
438
+ if (!s) throw new APIError("INTERNAL_SERVER_ERROR", { message: PASSKEY_ERROR_CODES.UNABLE_TO_CREATE_SESSION });
439
+ const user = await ctx.context.internalAdapter.findUserById(passkey$1.userId);
440
+ if (!user) throw new APIError("INTERNAL_SERVER_ERROR", { message: "User not found" });
441
+ await setSessionCookie(ctx, {
442
+ session: s,
443
+ user
444
+ });
445
+ return ctx.json({ session: s }, { status: 200 });
446
+ } catch (e) {
447
+ ctx.context.logger.error("Failed to verify authentication", e);
448
+ throw new APIError("BAD_REQUEST", { message: PASSKEY_ERROR_CODES.AUTHENTICATION_FAILED });
449
+ }
450
+ }),
451
+ listPasskeys: createAuthEndpoint("/passkey/list-user-passkeys", {
452
+ method: "GET",
453
+ use: [sessionMiddleware],
454
+ metadata: { openapi: {
455
+ description: "List all passkeys for the authenticated user",
456
+ responses: { "200": {
457
+ description: "Passkeys retrieved successfully",
458
+ content: { "application/json": { schema: {
459
+ type: "array",
460
+ items: {
461
+ $ref: "#/components/schemas/Passkey",
462
+ required: [
463
+ "id",
464
+ "userId",
465
+ "publicKey",
466
+ "createdAt",
467
+ "updatedAt"
468
+ ]
469
+ },
470
+ description: "Array of passkey objects associated with the user"
471
+ } } }
472
+ } }
473
+ } }
474
+ }, async (ctx) => {
475
+ const passkeys = await ctx.context.adapter.findMany({
476
+ model: "passkey",
477
+ where: [{
478
+ field: "userId",
479
+ value: ctx.context.session.user.id
480
+ }]
481
+ });
482
+ return ctx.json(passkeys, { status: 200 });
483
+ }),
484
+ deletePasskey: createAuthEndpoint("/passkey/delete-passkey", {
485
+ method: "POST",
486
+ body: z$1.object({ id: z$1.string().meta({ description: "The ID of the passkey to delete. Eg: \"some-passkey-id\"" }) }),
487
+ use: [sessionMiddleware],
488
+ metadata: { openapi: {
489
+ description: "Delete a specific passkey",
490
+ responses: { "200": {
491
+ description: "Passkey deleted successfully",
492
+ content: { "application/json": { schema: {
493
+ type: "object",
494
+ properties: { status: {
495
+ type: "boolean",
496
+ description: "Indicates whether the deletion was successful"
497
+ } },
498
+ required: ["status"]
499
+ } } }
500
+ } }
501
+ } }
502
+ }, async (ctx) => {
503
+ await ctx.context.adapter.delete({
504
+ model: "passkey",
505
+ where: [{
506
+ field: "id",
507
+ value: ctx.body.id
508
+ }]
509
+ });
510
+ return ctx.json(null, { status: 200 });
511
+ }),
512
+ updatePasskey: createAuthEndpoint("/passkey/update-passkey", {
513
+ method: "POST",
514
+ body: z$1.object({
515
+ id: z$1.string().meta({ description: `The ID of the passkey which will be updated. Eg: \"passkey-id\"` }),
516
+ name: z$1.string().meta({ description: `The new name which the passkey will be updated to. Eg: \"my-new-passkey-name\"` })
517
+ }),
518
+ use: [sessionMiddleware],
519
+ metadata: { openapi: {
520
+ description: "Update a specific passkey's name",
521
+ responses: { "200": {
522
+ description: "Passkey updated successfully",
523
+ content: { "application/json": { schema: {
524
+ type: "object",
525
+ properties: { passkey: { $ref: "#/components/schemas/Passkey" } },
526
+ required: ["passkey"]
527
+ } } }
528
+ } }
529
+ } }
530
+ }, async (ctx) => {
531
+ const passkey$1 = await ctx.context.adapter.findOne({
532
+ model: "passkey",
533
+ where: [{
534
+ field: "id",
535
+ value: ctx.body.id
536
+ }]
537
+ });
538
+ if (!passkey$1) throw new APIError("NOT_FOUND", { message: PASSKEY_ERROR_CODES.PASSKEY_NOT_FOUND });
539
+ if (passkey$1.userId !== ctx.context.session.user.id) throw new APIError("UNAUTHORIZED", { message: PASSKEY_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_REGISTER_THIS_PASSKEY });
540
+ const updatedPasskey = await ctx.context.adapter.update({
541
+ model: "passkey",
542
+ where: [{
543
+ field: "id",
544
+ value: ctx.body.id
545
+ }],
546
+ update: { name: ctx.body.name }
547
+ });
548
+ if (!updatedPasskey) throw new APIError("INTERNAL_SERVER_ERROR", { message: PASSKEY_ERROR_CODES.FAILED_TO_UPDATE_PASSKEY });
549
+ return ctx.json({ passkey: updatedPasskey }, { status: 200 });
550
+ })
551
+ },
552
+ schema: mergeSchema(schema, options?.schema),
553
+ $ERROR_CODES: PASSKEY_ERROR_CODES
554
+ };
555
+ };
556
+
557
+ //#endregion
558
+ export { passkey as t };
@@ -0,0 +1,25 @@
1
+ import { APIError } from "better-call";
2
+
3
+ //#region src/utils/password.ts
4
+ async function validatePassword(ctx, data) {
5
+ const credentialAccount = (await ctx.context.internalAdapter.findAccounts(data.userId))?.find((account) => account.providerId === "credential");
6
+ const currentPassword = credentialAccount?.password;
7
+ if (!credentialAccount || !currentPassword) return false;
8
+ return await ctx.context.password.verify({
9
+ hash: currentPassword,
10
+ password: data.password
11
+ });
12
+ }
13
+ async function checkPassword(userId, c) {
14
+ const credentialAccount = (await c.context.internalAdapter.findAccounts(userId))?.find((account) => account.providerId === "credential");
15
+ const currentPassword = credentialAccount?.password;
16
+ if (!credentialAccount || !currentPassword || !c.body.password) throw new APIError("BAD_REQUEST", { message: "No password credential found" });
17
+ if (!await c.context.password.verify({
18
+ hash: currentPassword,
19
+ password: c.body.password
20
+ })) throw new APIError("BAD_REQUEST", { message: "Invalid password" });
21
+ return true;
22
+ }
23
+
24
+ //#endregion
25
+ export { validatePassword as n, checkPassword as t };
@@ -0,0 +1,15 @@
1
+ //#region src/plugins/organization/permission.ts
2
+ const hasPermissionFn = (input, acRoles) => {
3
+ if (!input.permissions && !input.permission) return false;
4
+ const roles = input.role.split(",");
5
+ const creatorRole = input.options.creatorRole || "owner";
6
+ const isCreator = roles.includes(creatorRole);
7
+ const allowCreatorsAllPermissions = input.allowCreatorAllPermissions || false;
8
+ if (isCreator && allowCreatorsAllPermissions) return true;
9
+ for (const role of roles) if ((acRoles[role]?.authorize(input.permissions ?? input.permission))?.success) return true;
10
+ return false;
11
+ };
12
+ let cacheAllRoles = /* @__PURE__ */ new Map();
13
+
14
+ //#endregion
15
+ export { hasPermissionFn as n, cacheAllRoles as t };