faire-auth 1.0.0

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