faire-auth 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (200) hide show
  1. package/dist/{access-Crt-IJ2P.cjs → access-BZ7-AbTM.cjs} +1 -1
  2. package/dist/{adapter-factory-DT-_2aHJ.cjs → adapter-factory-D1I7joki.cjs} +2 -2
  3. package/dist/adapters/drizzle-adapter/index.cjs +5 -5
  4. package/dist/adapters/drizzle-adapter/index.d.cts +1 -1
  5. package/dist/adapters/drizzle-adapter/index.d.mts +2 -2
  6. package/dist/adapters/drizzle-adapter/index.mjs +3 -3
  7. package/dist/adapters/index.cjs +4 -4
  8. package/dist/adapters/index.d.cts +1 -1
  9. package/dist/adapters/index.d.mts +2 -2
  10. package/dist/adapters/index.mjs +3 -3
  11. package/dist/adapters/kysely-adapter/index.cjs +5 -5
  12. package/dist/adapters/kysely-adapter/index.d.cts +1 -1
  13. package/dist/adapters/kysely-adapter/index.d.mts +2 -2
  14. package/dist/adapters/kysely-adapter/index.mjs +4 -4
  15. package/dist/adapters/memory-adapter/index.cjs +5 -5
  16. package/dist/adapters/memory-adapter/index.d.cts +1 -1
  17. package/dist/adapters/memory-adapter/index.d.mts +2 -2
  18. package/dist/adapters/memory-adapter/index.mjs +4 -4
  19. package/dist/adapters/mongodb-adapter/index.cjs +294 -6
  20. package/dist/adapters/mongodb-adapter/index.d.cts +34 -2
  21. package/dist/adapters/mongodb-adapter/index.d.mts +35 -3
  22. package/dist/adapters/mongodb-adapter/index.mjs +291 -4
  23. package/dist/adapters/prisma-adapter/index.cjs +5 -5
  24. package/dist/adapters/prisma-adapter/index.d.cts +1 -1
  25. package/dist/adapters/prisma-adapter/index.d.mts +2 -2
  26. package/dist/adapters/prisma-adapter/index.mjs +3 -3
  27. package/dist/adapters/test.cjs +3 -3
  28. package/dist/adapters/test.d.cts +1 -1
  29. package/dist/adapters/test.d.mts +2 -2
  30. package/dist/adapters/test.mjs +2 -2
  31. package/dist/api/index.cjs +15 -15
  32. package/dist/api/index.d.cts +1 -1
  33. package/dist/api/index.d.mts +2 -2
  34. package/dist/api/index.mjs +8 -8
  35. package/dist/api/middleware/index.cjs +8 -8
  36. package/dist/api/middleware/index.d.cts +3 -3
  37. package/dist/api/middleware/index.d.mts +4 -4
  38. package/dist/api/middleware/index.mjs +3 -3
  39. package/dist/{api-_B7qO28y.mjs → api-B4RDwBty.mjs} +7 -7
  40. package/dist/{api-Bm89BLgN.cjs → api-CaRC1Gio.cjs} +12 -12
  41. package/dist/{bearer-CHeREcGT.cjs → bearer-DDzrp5M7.cjs} +2 -2
  42. package/dist/{bearer-0SeEmaS4.mjs → bearer-WZcs7gxL.mjs} +1 -1
  43. package/dist/{bun-sqlite-dialect-wuaC2-gh.cjs → bun-sqlite-dialect-DPgTzc0w.cjs} +1 -1
  44. package/dist/{chunk-Ceigfy4P.mjs → chunk-BFnQceUY.mjs} +1 -13
  45. package/dist/{chunk-oakRccI5.cjs → chunk-fPmz2rbM.cjs} +0 -9
  46. package/dist/client/index.cjs +26 -7
  47. package/dist/client/index.d.cts +27 -4
  48. package/dist/client/index.d.mts +28 -5
  49. package/dist/client/index.mjs +25 -6
  50. package/dist/client/lynx/index.cjs +5 -5
  51. package/dist/client/lynx/index.d.cts +15 -15
  52. package/dist/client/lynx/index.d.mts +27 -27
  53. package/dist/client/lynx/index.mjs +3 -3
  54. package/dist/client/plugins/index.d.cts +1 -1
  55. package/dist/client/plugins/index.d.mts +2 -2
  56. package/dist/client/react/index.cjs +5 -5
  57. package/dist/client/react/index.d.cts +26 -26
  58. package/dist/client/react/index.d.mts +16 -16
  59. package/dist/client/react/index.mjs +3 -3
  60. package/dist/client/solid/index.cjs +5 -5
  61. package/dist/client/solid/index.d.cts +16 -16
  62. package/dist/client/solid/index.d.mts +17 -17
  63. package/dist/client/solid/index.mjs +3 -3
  64. package/dist/client/svelte/index.cjs +4 -4
  65. package/dist/client/svelte/index.d.cts +11 -11
  66. package/dist/client/svelte/index.d.mts +16 -16
  67. package/dist/client/svelte/index.mjs +3 -3
  68. package/dist/client/vue/index.cjs +5 -5
  69. package/dist/client/vue/index.d.cts +27 -27
  70. package/dist/client/vue/index.d.mts +28 -28
  71. package/dist/client/vue/index.mjs +3 -3
  72. package/dist/{cookies-B5xeA6i8.cjs → cookies-BTl72THv.cjs} +3 -3
  73. package/dist/{cookies-Ch1JfQIz.mjs → cookies-BTs1o992.mjs} +2 -2
  74. package/dist/crypto/index.cjs +1 -1
  75. package/dist/crypto/index.d.cts +2 -2
  76. package/dist/crypto/index.d.mts +3 -3
  77. package/dist/crypto/index.mjs +1 -1
  78. package/dist/{crypto-CyQRFtkq.mjs → crypto-DH2Aa7jN.mjs} +1 -1
  79. package/dist/{crypto-CcTxYH82.cjs → crypto-DpSCnrTp.cjs} +1 -1
  80. package/dist/db/index.cjs +10 -10
  81. package/dist/db/index.d.cts +1 -1
  82. package/dist/db/index.d.mts +2 -2
  83. package/dist/db/index.mjs +6 -6
  84. package/dist/{db-xiJtoDgz.mjs → db-4tUsQJXd.mjs} +3 -3
  85. package/dist/{db-BTKyYu-_.cjs → db-ChMbb_U-.cjs} +8 -8
  86. package/dist/{email-verification-CWhj2qfb.mjs → email-verification-C_lBu_JY.mjs} +3 -3
  87. package/dist/{email-verification-C-AsfJsb.cjs → email-verification-DI_0H4JC.cjs} +5 -5
  88. package/dist/{hono-Cdukwu5K.cjs → hono-C14rpOEa.cjs} +1 -1
  89. package/dist/{hono-Covz10jU.mjs → hono-CO-zsqI-.mjs} +2 -2
  90. package/dist/{hono-BEq1NYVX.cjs → hono-DnW5crl1.cjs} +4 -4
  91. package/dist/{index-BVHscLQl.d.cts → index-4PEF72Mq.d.cts} +20 -20
  92. package/dist/{index-B-WeOMzg.d.cts → index-BCzB3uDD.d.cts} +833 -833
  93. package/dist/{index-B09P9p5_.d.cts → index-Bw8dyZTc.d.cts} +6 -6
  94. package/dist/{index-Qu-iJGNr.d.mts → index-C0b8eC8h.d.mts} +16 -16
  95. package/dist/{index-jlessPI0.d.mts → index-CrmLTEj8.d.mts} +382 -382
  96. package/dist/index-Dfgobqa-.d.mts +33 -0
  97. package/dist/index.cjs +721 -27
  98. package/dist/index.d.cts +1 -1
  99. package/dist/index.d.mts +2 -2
  100. package/dist/index.mjs +711 -16
  101. package/dist/integrations/next-js.cjs +3 -3
  102. package/dist/integrations/next-js.d.cts +5 -5
  103. package/dist/integrations/next-js.d.mts +6 -6
  104. package/dist/integrations/next-js.mjs +2 -2
  105. package/dist/integrations/node.d.cts +1 -1
  106. package/dist/integrations/node.d.mts +2 -2
  107. package/dist/integrations/react-start.cjs +3 -3
  108. package/dist/integrations/react-start.d.cts +5 -5
  109. package/dist/integrations/react-start.d.mts +5 -5
  110. package/dist/integrations/react-start.mjs +2 -2
  111. package/dist/integrations/svelte-kit.cjs +3 -3
  112. package/dist/integrations/svelte-kit.d.cts +5 -5
  113. package/dist/integrations/svelte-kit.d.mts +6 -6
  114. package/dist/integrations/svelte-kit.mjs +2 -2
  115. package/dist/{ip-B5SwXaMB.cjs → ip-C17Qdq-G.cjs} +2 -2
  116. package/dist/{json-CcJ2HjGo.cjs → json--tl7Grvs.cjs} +1 -1
  117. package/dist/{kysely-adapter-DRuoT_X8.mjs → kysely-adapter-CtIdoHa8.mjs} +3 -3
  118. package/dist/{kysely-adapter-Bxi7sPdG.cjs → kysely-adapter-QZTx077T.cjs} +4 -4
  119. package/dist/{logged-DQK3C64b.cjs → logged-Dv3st5qc.cjs} +1 -1
  120. package/dist/{memory-adapter-BlnDIAAX.cjs → memory-adapter-17RZd5df.cjs} +2 -2
  121. package/dist/{memory-adapter-Db3tsJTn.mjs → memory-adapter-Dp4XdCZK.mjs} +1 -1
  122. package/dist/{node-sqlite-dialect-mJWC8LWQ.cjs → node-sqlite-dialect-DP11CB0y.cjs} +1 -1
  123. package/dist/oauth2/index.cjs +11 -11
  124. package/dist/oauth2/index.d.cts +1 -1
  125. package/dist/oauth2/index.d.mts +2 -2
  126. package/dist/oauth2/index.mjs +6 -6
  127. package/dist/{oauth2-BLeOEi7Y.cjs → oauth2-5RL4cVNS.cjs} +3 -3
  128. package/dist/{oauth2-B8M0lW9l.mjs → oauth2-C56wz-n9.mjs} +2 -2
  129. package/dist/{origin-check-id9lTnqZ.cjs → origin-check-DjLTuZQ8.cjs} +2 -2
  130. package/dist/{passkey-B6N20LSS.cjs → passkey-BTT-v5c-.cjs} +4 -4
  131. package/dist/{passkey-DJsR_GX3.mjs → passkey-CzY_W2us.mjs} +2 -2
  132. package/dist/plugins/access/index.cjs +1 -1
  133. package/dist/plugins/access/index.d.cts +1 -1
  134. package/dist/plugins/access/index.d.mts +1 -1
  135. package/dist/plugins/access/index.mjs +1 -1
  136. package/dist/plugins/bearer/index.cjs +4 -4
  137. package/dist/plugins/bearer/index.d.cts +2 -2
  138. package/dist/plugins/bearer/index.d.mts +3 -3
  139. package/dist/plugins/bearer/index.mjs +3 -3
  140. package/dist/plugins/index.cjs +5215 -31
  141. package/dist/plugins/index.d.cts +351 -351
  142. package/dist/plugins/index.d.mts +268 -268
  143. package/dist/plugins/index.mjs +5202 -19
  144. package/dist/plugins/passkey/index.cjs +10 -10
  145. package/dist/plugins/passkey/index.d.cts +2 -2
  146. package/dist/plugins/passkey/index.d.mts +3 -3
  147. package/dist/plugins/passkey/index.mjs +5 -5
  148. package/dist/{schema-D-qjygfE.cjs → schema-CirKflVs.cjs} +2 -2
  149. package/dist/{session-rH8ougDl.mjs → session-CM3rmOYF.mjs} +1 -1
  150. package/dist/{session-De9POJTW.cjs → session-Cwrj4GfV.cjs} +5 -5
  151. package/dist/social-providers/index.cjs +1 -1
  152. package/dist/social-providers/index.d.cts +1 -1
  153. package/dist/social-providers/index.d.mts +1 -1
  154. package/dist/social-providers/index.mjs +1 -1
  155. package/dist/{social-providers-DoYJhBe3.mjs → social-providers-B8RK5yqI.mjs} +1 -1
  156. package/dist/{social-providers-DcFNUT0S.cjs → social-providers-BmFOIIPk.cjs} +1 -1
  157. package/dist/{state-CqJfCIl9.mjs → state-CQghgH9I.mjs} +1 -1
  158. package/dist/{state--f7fwIGh.cjs → state-CvSihlVT.cjs} +2 -2
  159. package/dist/test-utils/bun-sqlite-dialect-BSWhhKNs.mjs +155 -0
  160. package/dist/test-utils/bun-sqlite-dialect-BZBvHchL.cjs +156 -0
  161. package/dist/test-utils/index.cjs +8927 -482
  162. package/dist/test-utils/index.d.cts +8395 -337
  163. package/dist/test-utils/index.d.mts +8394 -334
  164. package/dist/test-utils/index.mjs +8712 -265
  165. package/dist/test-utils/node-sqlite-dialect-BgJqjBOu.cjs +156 -0
  166. package/dist/test-utils/node-sqlite-dialect-DAQXiobH.mjs +155 -0
  167. package/dist/types/index.d.cts +1 -1
  168. package/dist/types/index.d.mts +2 -2
  169. package/dist/{url-D2yvKaM7.cjs → url-Ce7CVaQD.cjs} +1 -1
  170. package/dist/utils/cookies.cjs +4 -4
  171. package/dist/utils/cookies.d.cts +1 -1
  172. package/dist/utils/cookies.d.mts +2 -2
  173. package/dist/utils/cookies.mjs +2 -2
  174. package/package.json +2 -2
  175. package/dist/auth-Bo9PDt5j.cjs +0 -739
  176. package/dist/auth-Ds4AG4h4.mjs +0 -709
  177. package/dist/index-C2-2QDyS.d.cts +0 -35
  178. package/dist/index-CWAqWfoZ.d.cts +0 -27
  179. package/dist/index-CYSShrFx.d.mts +0 -27
  180. package/dist/index-ppgcFe12.d.mts +0 -33
  181. package/dist/index-to0RO38U.d.mts +0 -35
  182. package/dist/mongodb-adapter-C_qGQED5.mjs +0 -291
  183. package/dist/mongodb-adapter-C_qfK87x.cjs +0 -297
  184. package/dist/plugins-C1lm2Wj3.cjs +0 -5254
  185. package/dist/plugins-Dai1QkRU.mjs +0 -5199
  186. package/dist/vanilla-Bu2PmFzE.cjs +0 -30
  187. package/dist/vanilla-TfHqeiC7.mjs +0 -25
  188. /package/dist/{access-B5bBI4uT.mjs → access-D0DRqUKC.mjs} +0 -0
  189. /package/dist/{adapter-factory-BXei1QRX.mjs → adapter-factory-lKIOf2OR.mjs} +0 -0
  190. /package/dist/{bun-sqlite-dialect-CfkBo2v5.mjs → bun-sqlite-dialect-6NqeV3px.mjs} +0 -0
  191. /package/dist/{defu-B0Svx_x4.cjs → defu-BmOYq4PU.cjs} +0 -0
  192. /package/dist/{defu-SZkpHhbR.mjs → defu-D9ZTXqlo.mjs} +0 -0
  193. /package/dist/{hono-DuE14mmj.d.mts → hono-D0VqxVy1.d.mts} +0 -0
  194. /package/dist/{index-B5_0QTLg.d.mts → index-BDhhaE6Y.d.cts} +0 -0
  195. /package/dist/{index-B7SKyR_a.d.cts → index-CF9iq55a.d.mts} +0 -0
  196. /package/dist/{index-CTwrVluH.d.mts → index-CRt_fppq.d.mts} +0 -0
  197. /package/dist/{index-cs4Sh0En.d.cts → index-CdLyn7qP.d.cts} +0 -0
  198. /package/dist/{node-sqlite-dialect-BfBzyOAg.mjs → node-sqlite-dialect-w4DAg0PH.mjs} +0 -0
  199. /package/dist/{parser-CeAer-RM.mjs → parser-B25ylT5u.mjs} +0 -0
  200. /package/dist/{parser-CdncAl9i.cjs → parser-B_wxvaAr.cjs} +0 -0
package/dist/index.mjs CHANGED
@@ -1,27 +1,722 @@
1
1
  import "./hono-CoKYWnXA.mjs";
2
2
  import { n as getCurrentAdapter } from "./ip-BjNYspCH.mjs";
3
- import "./crypto-CyQRFtkq.mjs";
3
+ import { n as crypto_exports, t as checkPassword } from "./crypto-DH2Aa7jN.mjs";
4
4
  import "./json-B1v2qRTQ.mjs";
5
- import "./cookies-Ch1JfQIz.mjs";
5
+ import { i as createCookieCreator, l as getCookies } from "./cookies-BTs1o992.mjs";
6
6
  import "./logged-CyGfp8_H.mjs";
7
- import "./url-BoUuoIwZ.mjs";
7
+ import { a as getTrustedOrigins, t as getBaseURL } from "./url-BoUuoIwZ.mjs";
8
8
  import "./middleware-CE6OhDkq.mjs";
9
- import "./session-rH8ougDl.mjs";
9
+ import "./session-CM3rmOYF.mjs";
10
10
  import "./origin-check-8Gajklvh.mjs";
11
- import "./email-verification-CWhj2qfb.mjs";
12
- import "./oauth2-B8M0lW9l.mjs";
13
- import { n as parseState, t as generateState } from "./state-CqJfCIl9.mjs";
14
- import "./social-providers-DoYJhBe3.mjs";
15
- import "./api-_B7qO28y.mjs";
11
+ import "./email-verification-C_lBu_JY.mjs";
12
+ import "./oauth2-C56wz-n9.mjs";
13
+ import { n as parseState, t as generateState } from "./state-CQghgH9I.mjs";
14
+ import { t as social_providers_exports } from "./social-providers-B8RK5yqI.mjs";
15
+ import { t as router } from "./api-B4RDwBty.mjs";
16
16
  import { n as mergeHeaders } from "./request-1NL_1lyJ.mjs";
17
17
  import { a as logger, i as generateRandomString, n as createLogger, r as generateId, t as ENV } from "./utils-D4vZd1-9.mjs";
18
18
  import "./schema-DTIwLLmf.mjs";
19
- import { a as getTelemetryAuthConfig, i as createTelemetry, n as faireAuth, t as defineOptions } from "./auth-Ds4AG4h4.mjs";
20
- import "./kysely-adapter-DRuoT_X8.mjs";
21
- import "./adapter-factory-BXei1QRX.mjs";
22
- import "./db-xiJtoDgz.mjs";
23
- import "./memory-adapter-Db3tsJTn.mjs";
24
- import "./defu-SZkpHhbR.mjs";
25
- import { APIError, FaireAuthError, MissingDependencyError } from "@faire-auth/core/error";
19
+ import { r as getKyselyDatabaseType } from "./kysely-adapter-CtIdoHa8.mjs";
20
+ import { n as getAuthTables } from "./adapter-factory-lKIOf2OR.mjs";
21
+ import { a as createInternalAdapter, r as getAdapter, s as getMigrations } from "./db-4tUsQJXd.mjs";
22
+ import "./memory-adapter-Dp4XdCZK.mjs";
23
+ import { t as defu } from "./defu-D9ZTXqlo.mjs";
24
+ import { ENV as ENV$1, createLogger as createLogger$1, env, getBooleanEnvVar, getEnvVar, isDevelopment, isProduction, isTest, logger as logger$1 } from "@faire-auth/core/env";
25
+ import { APIError, BASE_ERROR_CODES, FaireAuthError, FaireAuthError as FaireAuthError$1, MissingDependencyError } from "@faire-auth/core/error";
26
+ import { DEFAULT_SECRET } from "@faire-auth/core/static";
27
+ import { hashToBase64 } from "@faire-auth/core/datatypes";
28
+ import { betterFetch } from "@better-fetch/fetch";
26
29
 
30
+ //#region src/context/cloudflare.ts
31
+ /**
32
+ * Symbol used as an index in the global scope to set and retrieve the Cloudflare context
33
+ *
34
+ * This is used both in production (in the actual built worker) and in development (`next dev`)
35
+ *
36
+ * Note: this symbol needs to be kept in sync with the one used in `src/cli/templates/worker.ts`
37
+ */
38
+ const cloudflareContextSymbol = Symbol.for("__cloudflare-context__");
39
+ /**
40
+ * Get the cloudflare context from the current global scope
41
+ */
42
+ function getCloudflareContext() {
43
+ return globalThis[cloudflareContextSymbol];
44
+ }
45
+
46
+ //#endregion
47
+ //#region src/telemetry/detectors/detect-auth-config.ts
48
+ function getTelemetryAuthConfig(options, context) {
49
+ return {
50
+ database: context?.database,
51
+ adapter: context?.adapter,
52
+ emailVerification: {
53
+ sendVerificationEmail: !!options.emailVerification?.sendVerificationEmail,
54
+ sendOnSignUp: !!options.emailVerification?.sendOnSignUp,
55
+ sendOnSignIn: !!options.emailVerification?.sendOnSignIn,
56
+ autoSignInAfterVerification: !!options.emailVerification?.autoSignInAfterVerification,
57
+ expiresIn: options.emailVerification?.expiresIn,
58
+ onEmailVerification: !!options.emailVerification?.onEmailVerification,
59
+ afterEmailVerification: !!options.emailVerification?.afterEmailVerification
60
+ },
61
+ emailAndPassword: {
62
+ enabled: !!options.emailAndPassword?.enabled,
63
+ disableSignUp: !!options.emailAndPassword?.disableSignUp,
64
+ requireEmailVerification: !!options.emailAndPassword?.requireEmailVerification,
65
+ maxPasswordLength: options.emailAndPassword?.maxPasswordLength,
66
+ minPasswordLength: options.emailAndPassword?.minPasswordLength,
67
+ sendResetPassword: !!options.emailAndPassword?.sendResetPassword,
68
+ resetPasswordTokenExpiresIn: options.emailAndPassword?.resetPasswordTokenExpiresIn,
69
+ onPasswordReset: !!options.emailAndPassword?.onPasswordReset,
70
+ password: {
71
+ hash: !!options.emailAndPassword?.password?.hash,
72
+ verify: !!options.emailAndPassword?.password?.verify
73
+ },
74
+ autoSignIn: !!options.emailAndPassword?.autoSignIn,
75
+ revokeSessionsOnPasswordReset: !!options.emailAndPassword?.revokeSessionsOnPasswordReset
76
+ },
77
+ socialProviders: Object.keys(options.socialProviders || {}).map((p) => {
78
+ const provider = options.socialProviders?.[p];
79
+ if (!provider) return {};
80
+ return {
81
+ id: p,
82
+ mapProfileToUser: !!provider.mapProfileToUser,
83
+ disableDefaultScope: !!provider.disableDefaultScope,
84
+ disableIdTokenSignIn: !!provider.disableIdTokenSignIn,
85
+ disableImplicitSignUp: provider.disableImplicitSignUp,
86
+ disableSignUp: provider.disableSignUp,
87
+ getUserInfo: !!provider.getUserInfo,
88
+ overrideUserInfoOnSignIn: !!provider.overrideUserInfoOnSignIn,
89
+ prompt: provider.prompt,
90
+ verifyIdToken: !!provider.verifyIdToken,
91
+ scope: provider.scope,
92
+ refreshAccessToken: !!provider.refreshAccessToken
93
+ };
94
+ }),
95
+ plugins: options.plugins?.map((p) => p.id.toString()),
96
+ user: {
97
+ modelName: options.user?.modelName,
98
+ fields: options.user?.fields,
99
+ additionalFields: options.user?.additionalFields,
100
+ changeEmail: {
101
+ enabled: options.user?.changeEmail?.enabled,
102
+ sendChangeEmailVerification: !!options.user?.changeEmail?.sendChangeEmailVerification
103
+ }
104
+ },
105
+ verification: {
106
+ modelName: options.verification?.modelName,
107
+ disableCleanup: options.verification?.disableCleanup,
108
+ fields: options.verification?.fields
109
+ },
110
+ session: {
111
+ modelName: options.session?.modelName,
112
+ additionalFields: options.session?.additionalFields,
113
+ cookieCache: {
114
+ enabled: options.session?.cookieCache?.enabled,
115
+ maxAge: options.session?.cookieCache?.maxAge
116
+ },
117
+ disableSessionRefresh: options.session?.disableSessionRefresh,
118
+ expiresIn: options.session?.expiresIn,
119
+ fields: options.session?.fields,
120
+ freshAge: options.session?.freshAge,
121
+ preserveSessionInDatabase: options.session?.preserveSessionInDatabase,
122
+ storeSessionInDatabase: options.session?.storeSessionInDatabase,
123
+ updateAge: options.session?.updateAge
124
+ },
125
+ account: {
126
+ modelName: options.account?.modelName,
127
+ fields: options.account?.fields,
128
+ encryptOAuthTokens: options.account?.encryptOAuthTokens,
129
+ updateAccountOnSignIn: options.account?.updateAccountOnSignIn,
130
+ accountLinking: {
131
+ enabled: options.account?.accountLinking?.enabled,
132
+ trustedProviders: options.account?.accountLinking?.trustedProviders,
133
+ updateUserInfoOnLink: options.account?.accountLinking?.updateUserInfoOnLink,
134
+ allowUnlinkingAll: options.account?.accountLinking?.allowUnlinkingAll
135
+ }
136
+ },
137
+ hooks: {
138
+ after: !!options.hooks?.after,
139
+ before: !!options.hooks?.before
140
+ },
141
+ secondaryStorage: !!options.secondaryStorage,
142
+ advanced: {
143
+ cookiePrefix: !!options.advanced?.cookiePrefix,
144
+ cookies: !!options.advanced?.cookies,
145
+ crossSubDomainCookies: {
146
+ domain: !!options.advanced?.crossSubDomainCookies?.domain,
147
+ enabled: options.advanced?.crossSubDomainCookies?.enabled,
148
+ additionalCookies: options.advanced?.crossSubDomainCookies?.additionalCookies
149
+ },
150
+ database: {
151
+ useNumberId: !!options.advanced?.database?.useNumberId,
152
+ generateId: options.advanced?.database?.generateId,
153
+ defaultFindManyLimit: options.advanced?.database?.defaultFindManyLimit
154
+ },
155
+ useSecureCookies: options.advanced?.useSecureCookies,
156
+ ipAddress: {
157
+ disableIpTracking: options.advanced?.ipAddress?.disableIpTracking,
158
+ ipAddressHeaders: options.advanced?.ipAddress?.ipAddressHeaders
159
+ },
160
+ disableCSRFCheck: options.advanced?.disableCSRFCheck,
161
+ cookieAttributes: {
162
+ expires: options.advanced?.defaultCookieAttributes?.expires,
163
+ secure: options.advanced?.defaultCookieAttributes?.secure,
164
+ sameSite: options.advanced?.defaultCookieAttributes?.sameSite,
165
+ domain: !!options.advanced?.defaultCookieAttributes?.domain,
166
+ path: options.advanced?.defaultCookieAttributes?.path,
167
+ httpOnly: options.advanced?.defaultCookieAttributes?.httpOnly
168
+ }
169
+ },
170
+ trustedOrigins: options.trustedOrigins?.length,
171
+ rateLimit: {
172
+ storage: options.rateLimit?.storage,
173
+ modelName: options.rateLimit?.modelName,
174
+ window: options.rateLimit?.window,
175
+ customStorage: !!options.rateLimit?.customStorage,
176
+ enabled: options.rateLimit?.enabled,
177
+ max: options.rateLimit?.max
178
+ },
179
+ onAPIError: {
180
+ errorURL: options.onAPIError?.errorURL,
181
+ onError: !!options.onAPIError?.onError,
182
+ throw: options.onAPIError?.throw
183
+ },
184
+ logger: {
185
+ disabled: options.logger?.disabled,
186
+ level: options.logger?.level,
187
+ log: !!options.logger?.log
188
+ },
189
+ databaseHooks: {
190
+ user: {
191
+ create: {
192
+ after: !!options.databaseHooks?.user?.create?.after,
193
+ before: !!options.databaseHooks?.user?.create?.before
194
+ },
195
+ update: {
196
+ after: !!options.databaseHooks?.user?.update?.after,
197
+ before: !!options.databaseHooks?.user?.update?.before
198
+ }
199
+ },
200
+ session: {
201
+ create: {
202
+ after: !!options.databaseHooks?.session?.create?.after,
203
+ before: !!options.databaseHooks?.session?.create?.before
204
+ },
205
+ update: {
206
+ after: !!options.databaseHooks?.session?.update?.after,
207
+ before: !!options.databaseHooks?.session?.update?.before
208
+ }
209
+ },
210
+ account: {
211
+ create: {
212
+ after: !!options.databaseHooks?.account?.create?.after,
213
+ before: !!options.databaseHooks?.account?.create?.before
214
+ },
215
+ update: {
216
+ after: !!options.databaseHooks?.account?.update?.after,
217
+ before: !!options.databaseHooks?.account?.update?.before
218
+ }
219
+ },
220
+ verification: {
221
+ create: {
222
+ after: !!options.databaseHooks?.verification?.create?.after,
223
+ before: !!options.databaseHooks?.verification?.create?.before
224
+ },
225
+ update: {
226
+ after: !!options.databaseHooks?.verification?.update?.after,
227
+ before: !!options.databaseHooks?.verification?.update?.before
228
+ }
229
+ }
230
+ }
231
+ };
232
+ }
233
+
234
+ //#endregion
235
+ //#region src/utils/package-json.ts
236
+ let packageJSONCache;
237
+ async function readRootPackageJson() {
238
+ if (packageJSONCache) return packageJSONCache;
239
+ try {
240
+ const cwd = typeof process !== "undefined" && typeof process.cwd === "function" ? process.cwd() : "";
241
+ if (!cwd) return void 0;
242
+ const importRuntime = (m) => Function("mm", "return import(mm)")(m);
243
+ const [{ default: fs }, { default: path }] = await Promise.all([importRuntime("fs/promises"), importRuntime("path")]);
244
+ const raw = await fs.readFile(path.join(cwd, "package.json"), "utf-8");
245
+ packageJSONCache = JSON.parse(raw);
246
+ return packageJSONCache;
247
+ } catch {}
248
+ }
249
+ async function getPackageVersion(pkg) {
250
+ if (packageJSONCache) return packageJSONCache.dependencies?.[pkg] || packageJSONCache.devDependencies?.[pkg] || packageJSONCache.peerDependencies?.[pkg];
251
+ try {
252
+ const cwd = typeof process !== "undefined" && typeof process.cwd === "function" ? process.cwd() : "";
253
+ if (!cwd) throw new Error("no-cwd");
254
+ const importRuntime = (m) => Function("mm", "return import(mm)")(m);
255
+ const [{ default: fs }, { default: path }] = await Promise.all([importRuntime("fs/promises"), importRuntime("path")]);
256
+ const pkgJsonPath = path.join(cwd, "node_modules", pkg, "package.json");
257
+ const raw = await fs.readFile(pkgJsonPath, "utf-8");
258
+ return JSON.parse(raw).version || await getVersionFromLocalPackageJson(pkg) || void 0;
259
+ } catch {}
260
+ return await getVersionFromLocalPackageJson(pkg);
261
+ }
262
+ async function getVersionFromLocalPackageJson(pkg) {
263
+ const json = await readRootPackageJson();
264
+ if (!json) return void 0;
265
+ return {
266
+ ...json.dependencies,
267
+ ...json.devDependencies,
268
+ ...json.peerDependencies
269
+ }[pkg];
270
+ }
271
+ async function getNameFromLocalPackageJson() {
272
+ return (await readRootPackageJson())?.name;
273
+ }
274
+
275
+ //#endregion
276
+ //#region src/telemetry/detectors/detect-database.ts
277
+ const DATABASES = {
278
+ pg: "postgresql",
279
+ mysql: "mysql",
280
+ mariadb: "mariadb",
281
+ sqlite3: "sqlite",
282
+ "better-sqlite3": "sqlite",
283
+ "@prisma/client": "prisma",
284
+ mongoose: "mongodb",
285
+ mongodb: "mongodb",
286
+ "drizzle-orm": "drizzle"
287
+ };
288
+ async function detectDatabase() {
289
+ for (const [pkg, name] of Object.entries(DATABASES)) {
290
+ const version = await getPackageVersion(pkg);
291
+ if (version) return {
292
+ name,
293
+ version
294
+ };
295
+ }
296
+ }
297
+
298
+ //#endregion
299
+ //#region src/telemetry/detectors/detect-framework.ts
300
+ const FRAMEWORKS = {
301
+ next: "next",
302
+ nuxt: "nuxt",
303
+ "@remix-run/server-runtime": "remix",
304
+ astro: "astro",
305
+ "@sveltejs/kit": "sveltekit",
306
+ "solid-start": "solid-start",
307
+ "tanstack-start": "tanstack-start",
308
+ hono: "hono",
309
+ express: "express",
310
+ elysia: "elysia",
311
+ expo: "expo"
312
+ };
313
+ async function detectFramework() {
314
+ for (const [pkg, name] of Object.entries(FRAMEWORKS)) {
315
+ const version = await getPackageVersion(pkg);
316
+ if (version) return {
317
+ name,
318
+ version
319
+ };
320
+ }
321
+ }
322
+
323
+ //#endregion
324
+ //#region src/telemetry/detectors/detect-project-info.ts
325
+ function detectPackageManager() {
326
+ const userAgent = process.env.npm_config_user_agent;
327
+ if (!userAgent) return;
328
+ const pmSpec = userAgent.split(" ")[0];
329
+ const separatorPos = pmSpec.lastIndexOf("/");
330
+ const name = pmSpec.substring(0, separatorPos);
331
+ return {
332
+ name: name === "npminstall" ? "cnpm" : name,
333
+ version: pmSpec.substring(separatorPos + 1)
334
+ };
335
+ }
336
+
337
+ //#endregion
338
+ //#region src/telemetry/detectors/detect-system-info.ts
339
+ function getVendor() {
340
+ const hasAny = (...keys) => keys.some((k) => Boolean(env[k]));
341
+ if (hasAny("CF_PAGES", "CF_PAGES_URL", "CF_ACCOUNT_ID") || typeof navigator !== "undefined" && navigator.userAgent === "Cloudflare-Workers") return "cloudflare";
342
+ if (hasAny("VERCEL", "VERCEL_URL", "VERCEL_ENV")) return "vercel";
343
+ if (hasAny("NETLIFY", "NETLIFY_URL")) return "netlify";
344
+ if (hasAny("RENDER", "RENDER_URL", "RENDER_INTERNAL_HOSTNAME", "RENDER_SERVICE_ID")) return "render";
345
+ if (hasAny("AWS_LAMBDA_FUNCTION_NAME", "AWS_EXECUTION_ENV", "LAMBDA_TASK_ROOT")) return "aws";
346
+ if (hasAny("GOOGLE_CLOUD_FUNCTION_NAME", "GOOGLE_CLOUD_PROJECT", "GCP_PROJECT", "K_SERVICE")) return "gcp";
347
+ if (hasAny("AZURE_FUNCTION_NAME", "FUNCTIONS_WORKER_RUNTIME", "WEBSITE_INSTANCE_ID", "WEBSITE_SITE_NAME")) return "azure";
348
+ if (hasAny("DENO_DEPLOYMENT_ID", "DENO_REGION")) return "deno-deploy";
349
+ if (hasAny("FLY_APP_NAME", "FLY_REGION", "FLY_ALLOC_ID")) return "fly-io";
350
+ if (hasAny("RAILWAY_STATIC_URL", "RAILWAY_ENVIRONMENT_NAME")) return "railway";
351
+ if (hasAny("DYNO", "HEROKU_APP_NAME")) return "heroku";
352
+ if (hasAny("DO_DEPLOYMENT_ID", "DO_APP_NAME", "DIGITALOCEAN")) return "digitalocean";
353
+ if (hasAny("KOYEB", "KOYEB_DEPLOYMENT_ID", "KOYEB_APP_NAME")) return "koyeb";
354
+ return null;
355
+ }
356
+ async function detectSystemInfo() {
357
+ try {
358
+ if (getVendor() === "cloudflare") return "cloudflare";
359
+ const importRuntime = (m) => Function("mm", "return import(mm)")(m);
360
+ const { default: os } = await importRuntime("os");
361
+ const cpus = os.cpus();
362
+ return {
363
+ deploymentVendor: getVendor(),
364
+ systemPlatform: os.platform(),
365
+ systemRelease: os.release(),
366
+ systemArchitecture: os.arch(),
367
+ cpuCount: cpus.length,
368
+ cpuModel: cpus.length ? cpus[0].model : null,
369
+ cpuSpeed: cpus.length ? cpus[0].speed : null,
370
+ memory: os.totalmem(),
371
+ isWSL: await isWsl(),
372
+ isDocker: await isDocker(),
373
+ isTTY: process.stdout.isTTY
374
+ };
375
+ } catch (e) {
376
+ return {
377
+ systemPlatform: null,
378
+ systemRelease: null,
379
+ systemArchitecture: null,
380
+ cpuCount: null,
381
+ cpuModel: null,
382
+ cpuSpeed: null,
383
+ memory: null,
384
+ isWSL: null,
385
+ isDocker: null,
386
+ isTTY: null
387
+ };
388
+ }
389
+ }
390
+ let isDockerCached;
391
+ async function hasDockerEnv() {
392
+ if (getVendor() === "cloudflare") return false;
393
+ try {
394
+ const importRuntime = (m) => Function("mm", "return import(mm)")(m);
395
+ const { default: fs } = await importRuntime("fs");
396
+ fs.statSync("/.dockerenv");
397
+ return true;
398
+ } catch {
399
+ return false;
400
+ }
401
+ }
402
+ async function hasDockerCGroup() {
403
+ if (getVendor() === "cloudflare") return false;
404
+ try {
405
+ const importRuntime = (m) => Function("mm", "return import(mm)")(m);
406
+ const { default: fs } = await importRuntime("fs");
407
+ return fs.readFileSync("/proc/self/cgroup", "utf8").includes("docker");
408
+ } catch {
409
+ return false;
410
+ }
411
+ }
412
+ async function isDocker() {
413
+ if (getVendor() === "cloudflare") return false;
414
+ if (isDockerCached === void 0) isDockerCached = await hasDockerEnv() || await hasDockerCGroup();
415
+ return isDockerCached;
416
+ }
417
+ async function isWsl() {
418
+ try {
419
+ if (getVendor() === "cloudflare") return false;
420
+ if (process.platform !== "linux") return false;
421
+ const importRuntime = (m) => Function("mm", "return import(mm)")(m);
422
+ const { default: fs } = await importRuntime("fs");
423
+ const { default: os } = await importRuntime("os");
424
+ if (os.release().toLowerCase().includes("microsoft")) {
425
+ if (await isInsideContainer()) return false;
426
+ return true;
427
+ }
428
+ return fs.readFileSync("/proc/version", "utf8").toLowerCase().includes("microsoft") ? !await isInsideContainer() : false;
429
+ } catch {
430
+ return false;
431
+ }
432
+ }
433
+ let isInsideContainerCached;
434
+ const hasContainerEnv = async () => {
435
+ if (getVendor() === "cloudflare") return false;
436
+ try {
437
+ const importRuntime = (m) => Function("mm", "return import(mm)")(m);
438
+ const { default: fs } = await importRuntime("fs");
439
+ fs.statSync("/run/.containerenv");
440
+ return true;
441
+ } catch {
442
+ return false;
443
+ }
444
+ };
445
+ async function isInsideContainer() {
446
+ if (isInsideContainerCached === void 0) isInsideContainerCached = await hasContainerEnv() || await isDocker();
447
+ return isInsideContainerCached;
448
+ }
449
+ function isCI$1() {
450
+ return env.CI !== "false" && ("BUILD_ID" in env || "BUILD_NUMBER" in env || "CI" in env || "CI_APP_ID" in env || "CI_BUILD_ID" in env || "CI_BUILD_NUMBER" in env || "CI_NAME" in env || "CONTINUOUS_INTEGRATION" in env || "RUN_ID" in env);
451
+ }
452
+
453
+ //#endregion
454
+ //#region src/telemetry/detectors/detect-runtime.ts
455
+ function detectRuntime() {
456
+ if (typeof Deno !== "undefined") return {
457
+ name: "deno",
458
+ version: Deno?.version?.deno ?? null
459
+ };
460
+ if (typeof Bun !== "undefined") return {
461
+ name: "bun",
462
+ version: Bun?.version ?? null
463
+ };
464
+ if (typeof process !== "undefined" && process?.versions?.node) return {
465
+ name: "node",
466
+ version: process.versions.node ?? null
467
+ };
468
+ return {
469
+ name: "edge",
470
+ version: null
471
+ };
472
+ }
473
+ function detectEnvironment() {
474
+ return getEnvVar("NODE_ENV") === "production" ? "production" : isCI$1() ? "ci" : isTest() ? "test" : "development";
475
+ }
476
+
477
+ //#endregion
478
+ //#region src/telemetry/project-id.ts
479
+ let projectIdCached = null;
480
+ async function getProjectId(baseUrl) {
481
+ if (projectIdCached) return projectIdCached;
482
+ const projectName = await getNameFromLocalPackageJson();
483
+ if (projectName) {
484
+ projectIdCached = await hashToBase64(baseUrl ? baseUrl + projectName : projectName);
485
+ return projectIdCached;
486
+ }
487
+ if (baseUrl) {
488
+ projectIdCached = await hashToBase64(baseUrl);
489
+ return projectIdCached;
490
+ }
491
+ projectIdCached = generateId(32);
492
+ return projectIdCached;
493
+ }
494
+
495
+ //#endregion
496
+ //#region src/telemetry/index.ts
497
+ function createTelemetry(options, context) {
498
+ const debugEnabled = options.telemetry?.debug || getBooleanEnvVar("FAIRE_AUTH_TELEMETRY_DEBUG", false);
499
+ const TELEMETRY_ENDPOINT = ENV$1.FAIRE_AUTH_TELEMETRY_ENDPOINT;
500
+ const track = async (event) => {
501
+ try {
502
+ if (context?.customTrack) await context.customTrack(event);
503
+ else if (debugEnabled) await Promise.resolve(logger$1.info("telemetry event", JSON.stringify(event, null, 2)));
504
+ else await betterFetch(TELEMETRY_ENDPOINT, {
505
+ method: "POST",
506
+ body: event
507
+ });
508
+ } catch {}
509
+ };
510
+ const isEnabled = () => {
511
+ const telemetryEnabled = options.telemetry?.enabled !== void 0 ? options.telemetry.enabled : false;
512
+ return (getBooleanEnvVar("FAIRE_AUTH_TELEMETRY", false) || telemetryEnabled) && (context?.skipTestCheck || !isTest());
513
+ };
514
+ let initDone;
515
+ let anonymousId;
516
+ let payload;
517
+ const enabled = isEnabled();
518
+ async function ensureInitialized() {
519
+ if (initDone) return initDone;
520
+ initDone = (async () => {
521
+ anonymousId = await getProjectId(options.baseURL);
522
+ payload = {
523
+ config: getTelemetryAuthConfig(options),
524
+ runtime: detectRuntime(),
525
+ database: await detectDatabase(),
526
+ framework: await detectFramework(),
527
+ environment: detectEnvironment(),
528
+ systemInfo: await detectSystemInfo(),
529
+ packageManager: detectPackageManager()
530
+ };
531
+ if (enabled) await track({
532
+ type: "init",
533
+ payload,
534
+ anonymousId
535
+ });
536
+ })();
537
+ return initDone;
538
+ }
539
+ return {
540
+ initPromise: ensureInitialized(),
541
+ async publish(event) {
542
+ if (!enabled) return;
543
+ await track({
544
+ type: event.type,
545
+ payload: event.payload,
546
+ anonymousId
547
+ });
548
+ }
549
+ };
550
+ }
551
+
552
+ //#endregion
553
+ //#region src/init.ts
554
+ const getInternalPlugins = (options) => {
555
+ const plugins = [];
556
+ if (options.advanced?.crossSubDomainCookies?.enabled === true) {}
557
+ return plugins;
558
+ };
559
+ const loadSecret = (options, logger$2) => {
560
+ const secret = options.secret ?? env["FAIRE_AUTH_SECRET"] ?? env["AUTH_SECRET"] ?? DEFAULT_SECRET;
561
+ if (secret === DEFAULT_SECRET) {
562
+ if (isProduction()) logger$2.error("You are using the default secret. Please set `FAIRE_AUTH_SECRET` in your environment variables or pass `secret` in your auth config.");
563
+ }
564
+ return secret;
565
+ };
566
+ const runPluginInit = (ctx, options) => {
567
+ let context = ctx;
568
+ const dbHooks = [];
569
+ for (const plugin of options.plugins ?? []) if (plugin.init) {
570
+ const result = plugin.init(context);
571
+ if (typeof result === "object") {
572
+ if (result.options) {
573
+ const { databaseHooks,...restOpts } = result.options;
574
+ if (result.options.databaseHooks) dbHooks.push(result.options.databaseHooks);
575
+ options = defu(options, restOpts);
576
+ }
577
+ if (result.context) context = {
578
+ ...context,
579
+ ...result.context
580
+ };
581
+ }
582
+ }
583
+ if (options.databaseHooks) dbHooks.push(options.databaseHooks);
584
+ context.internalAdapter = createInternalAdapter(ctx.adapter, options, context, dbHooks);
585
+ return [context, options];
586
+ };
587
+ const initGenerateId = (options) => {
588
+ const advDbGenId = options.advanced?.database?.generateId;
589
+ return ({ model, size }) => {
590
+ if (typeof advDbGenId === "function") return advDbGenId({
591
+ model,
592
+ ...size != null ? { size } : {}
593
+ });
594
+ return generateId(size);
595
+ };
596
+ };
597
+ const init = (options) => {
598
+ const baseURL = getBaseURL(options.baseURL, options.basePath);
599
+ if (baseURL == null && !isDevelopment() && !isTest()) throw new Error("baseURL is required for auth context");
600
+ const adapter = getAdapter(options);
601
+ const internalPlugins = getInternalPlugins(options);
602
+ const logger$2 = createLogger$1(options.logger);
603
+ const secret = loadSecret(options, logger$2);
604
+ const generateId$1 = initGenerateId(options);
605
+ const secondaryStorage = options.secondaryStorage;
606
+ const sessionConfig = {
607
+ updateAge: options.session?.updateAge ?? 1440 * 60,
608
+ expiresIn: options.session?.expiresIn ?? 3600 * 24 * 7,
609
+ freshAge: options.session?.freshAge ?? 3600 * 24,
610
+ cookieRefreshCache: (() => {
611
+ const refreshCache = options.session?.cookieCache?.refreshCache;
612
+ const maxAge = options.session?.cookieCache?.maxAge ?? 300;
613
+ if (refreshCache === false || refreshCache === void 0) return false;
614
+ if (refreshCache === true) return {
615
+ enabled: true,
616
+ updateAge: Math.floor(maxAge * .2)
617
+ };
618
+ return {
619
+ enabled: true,
620
+ updateAge: refreshCache.updateAge !== void 0 ? refreshCache.updateAge : Math.floor(maxAge * .2)
621
+ };
622
+ })()
623
+ };
624
+ const rateLimit = {
625
+ ...options.rateLimit,
626
+ enabled: options.rateLimit?.enabled ?? isProduction(),
627
+ window: options.rateLimit?.window ?? 10,
628
+ max: options.rateLimit?.max ?? 100,
629
+ storage: options.rateLimit?.storage ?? (options.secondaryStorage ? "secondary-storage" : "memory")
630
+ };
631
+ options.secret = secret;
632
+ options.baseURL = baseURL ? new URL(baseURL).origin : "";
633
+ options.basePath ??= "/api/auth";
634
+ options.plugins ??= [];
635
+ options.plugins.push(...internalPlugins);
636
+ return runPluginInit({
637
+ appName: options.appName ?? "Faire Auth",
638
+ socialProviders: Object.entries(options.socialProviders ?? {}).map(([key, value]) => {
639
+ if (value == null) return null;
640
+ if (value.enabled === false) return null;
641
+ if (!value.clientId) logger$2.warn(`Social provider ${key} is missing clientId or clientSecret`);
642
+ if (!(key in social_providers_exports.socialProviders)) throw new Error(`${key} does not exist in known social providers`);
643
+ const provider = social_providers_exports.socialProviders[key](value);
644
+ if (value.disableImplicitSignUp) provider.disableImplicitSignUp = value.disableImplicitSignUp;
645
+ return provider;
646
+ }).filter((x) => x !== null),
647
+ tables: getAuthTables(options),
648
+ trustedOrigins: getTrustedOrigins(options, { baseURL }).trustedOrigins,
649
+ baseURL,
650
+ sessionConfig,
651
+ secret,
652
+ authCookies: getCookies(options),
653
+ logger: logger$2,
654
+ rateLimit,
655
+ generateId: generateId$1,
656
+ password: {
657
+ hash: options.emailAndPassword?.password?.hash ?? crypto_exports.hashPassword,
658
+ verify: options.emailAndPassword?.password?.verify ?? crypto_exports.verifyPassword,
659
+ config: {
660
+ minPasswordLength: options.emailAndPassword?.minPasswordLength ?? 8,
661
+ maxPasswordLength: options.emailAndPassword?.maxPasswordLength ?? 128
662
+ },
663
+ checkPassword
664
+ },
665
+ newSession: null,
666
+ adapter,
667
+ internalAdapter: createInternalAdapter(adapter, options, {
668
+ logger: logger$2,
669
+ generateId: generateId$1,
670
+ sessionConfig,
671
+ ...secondaryStorage && { secondaryStorage }
672
+ }, options.databaseHooks ? [options.databaseHooks] : []),
673
+ createAuthCookie: createCookieCreator(options),
674
+ runMigrations: async () => {
675
+ if (!options.database || "updateMany" in options.database) throw new FaireAuthError$1("Database is not provided or it's an adapter. Migrations are only supported with a database instance.");
676
+ const { runMigrations } = await getMigrations(options);
677
+ await runMigrations();
678
+ },
679
+ publishTelemetry: createTelemetry(options, {
680
+ adapter: adapter.id,
681
+ database: typeof options.database === "function" ? "adapter" : getKyselyDatabaseType(options.database) || "unknown"
682
+ }).publish,
683
+ ...secondaryStorage && { secondaryStorage }
684
+ }, options);
685
+ };
686
+
687
+ //#endregion
688
+ //#region src/auth.ts
689
+ function defineOptions(config) {
690
+ return config;
691
+ }
692
+ const faireAuth = (options) => {
693
+ const [authContext, authOptions] = init(options);
694
+ const { api, app } = router(authContext, authOptions);
695
+ return {
696
+ handler: (request, Env, executionCtx) => {
697
+ const cfCtx = getCloudflareContext();
698
+ return app.fetch(request, Object.assign(ENV$1, cfCtx?.env, Env), executionCtx ?? cfCtx?.ctx);
699
+ },
700
+ app,
701
+ api,
702
+ options: authOptions,
703
+ $context: authContext,
704
+ $Infer: {
705
+ App: (_o) => app,
706
+ Api: (_a) => api
707
+ },
708
+ $ERROR_CODES: {
709
+ ...authOptions.plugins?.reduce((acc, plugin) => {
710
+ if (plugin.$ERROR_CODES) return {
711
+ ...acc,
712
+ ...plugin.$ERROR_CODES
713
+ };
714
+ return acc;
715
+ }, {}),
716
+ ...BASE_ERROR_CODES
717
+ }
718
+ };
719
+ };
720
+
721
+ //#endregion
27
722
  export { APIError, ENV, FaireAuthError, MissingDependencyError, createLogger, createTelemetry, defineOptions, faireAuth, generateId, generateRandomString, generateState, getCurrentAdapter, getTelemetryAuthConfig, logger, mergeHeaders, parseState };