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.
- package/dist/{access-Crt-IJ2P.cjs → access-BZ7-AbTM.cjs} +1 -1
- package/dist/{adapter-factory-DT-_2aHJ.cjs → adapter-factory-D1I7joki.cjs} +2 -2
- package/dist/adapters/drizzle-adapter/index.cjs +5 -5
- package/dist/adapters/drizzle-adapter/index.d.cts +1 -1
- package/dist/adapters/drizzle-adapter/index.d.mts +2 -2
- package/dist/adapters/drizzle-adapter/index.mjs +3 -3
- package/dist/adapters/index.cjs +4 -4
- package/dist/adapters/index.d.cts +1 -1
- package/dist/adapters/index.d.mts +2 -2
- package/dist/adapters/index.mjs +3 -3
- package/dist/adapters/kysely-adapter/index.cjs +5 -5
- package/dist/adapters/kysely-adapter/index.d.cts +1 -1
- package/dist/adapters/kysely-adapter/index.d.mts +2 -2
- package/dist/adapters/kysely-adapter/index.mjs +4 -4
- package/dist/adapters/memory-adapter/index.cjs +5 -5
- package/dist/adapters/memory-adapter/index.d.cts +1 -1
- package/dist/adapters/memory-adapter/index.d.mts +2 -2
- package/dist/adapters/memory-adapter/index.mjs +4 -4
- package/dist/adapters/mongodb-adapter/index.cjs +294 -6
- package/dist/adapters/mongodb-adapter/index.d.cts +34 -2
- package/dist/adapters/mongodb-adapter/index.d.mts +35 -3
- package/dist/adapters/mongodb-adapter/index.mjs +291 -4
- package/dist/adapters/prisma-adapter/index.cjs +5 -5
- package/dist/adapters/prisma-adapter/index.d.cts +1 -1
- package/dist/adapters/prisma-adapter/index.d.mts +2 -2
- package/dist/adapters/prisma-adapter/index.mjs +3 -3
- package/dist/adapters/test.cjs +3 -3
- package/dist/adapters/test.d.cts +1 -1
- package/dist/adapters/test.d.mts +2 -2
- package/dist/adapters/test.mjs +2 -2
- package/dist/api/index.cjs +15 -15
- package/dist/api/index.d.cts +1 -1
- package/dist/api/index.d.mts +2 -2
- package/dist/api/index.mjs +8 -8
- package/dist/api/middleware/index.cjs +8 -8
- package/dist/api/middleware/index.d.cts +3 -3
- package/dist/api/middleware/index.d.mts +4 -4
- package/dist/api/middleware/index.mjs +3 -3
- package/dist/{api-_B7qO28y.mjs → api-B4RDwBty.mjs} +7 -7
- package/dist/{api-Bm89BLgN.cjs → api-CaRC1Gio.cjs} +12 -12
- package/dist/{bearer-CHeREcGT.cjs → bearer-DDzrp5M7.cjs} +2 -2
- package/dist/{bearer-0SeEmaS4.mjs → bearer-WZcs7gxL.mjs} +1 -1
- package/dist/{bun-sqlite-dialect-wuaC2-gh.cjs → bun-sqlite-dialect-DPgTzc0w.cjs} +1 -1
- package/dist/{chunk-Ceigfy4P.mjs → chunk-BFnQceUY.mjs} +1 -13
- package/dist/{chunk-oakRccI5.cjs → chunk-fPmz2rbM.cjs} +0 -9
- package/dist/client/index.cjs +26 -7
- package/dist/client/index.d.cts +27 -4
- package/dist/client/index.d.mts +28 -5
- package/dist/client/index.mjs +25 -6
- package/dist/client/lynx/index.cjs +5 -5
- package/dist/client/lynx/index.d.cts +15 -15
- package/dist/client/lynx/index.d.mts +27 -27
- package/dist/client/lynx/index.mjs +3 -3
- package/dist/client/plugins/index.d.cts +1 -1
- package/dist/client/plugins/index.d.mts +2 -2
- package/dist/client/react/index.cjs +5 -5
- package/dist/client/react/index.d.cts +26 -26
- package/dist/client/react/index.d.mts +16 -16
- package/dist/client/react/index.mjs +3 -3
- package/dist/client/solid/index.cjs +5 -5
- package/dist/client/solid/index.d.cts +16 -16
- package/dist/client/solid/index.d.mts +17 -17
- package/dist/client/solid/index.mjs +3 -3
- package/dist/client/svelte/index.cjs +4 -4
- package/dist/client/svelte/index.d.cts +11 -11
- package/dist/client/svelte/index.d.mts +16 -16
- package/dist/client/svelte/index.mjs +3 -3
- package/dist/client/vue/index.cjs +5 -5
- package/dist/client/vue/index.d.cts +27 -27
- package/dist/client/vue/index.d.mts +28 -28
- package/dist/client/vue/index.mjs +3 -3
- package/dist/{cookies-B5xeA6i8.cjs → cookies-BTl72THv.cjs} +3 -3
- package/dist/{cookies-Ch1JfQIz.mjs → cookies-BTs1o992.mjs} +2 -2
- package/dist/crypto/index.cjs +1 -1
- package/dist/crypto/index.d.cts +2 -2
- package/dist/crypto/index.d.mts +3 -3
- package/dist/crypto/index.mjs +1 -1
- package/dist/{crypto-CyQRFtkq.mjs → crypto-DH2Aa7jN.mjs} +1 -1
- package/dist/{crypto-CcTxYH82.cjs → crypto-DpSCnrTp.cjs} +1 -1
- package/dist/db/index.cjs +10 -10
- package/dist/db/index.d.cts +1 -1
- package/dist/db/index.d.mts +2 -2
- package/dist/db/index.mjs +6 -6
- package/dist/{db-xiJtoDgz.mjs → db-4tUsQJXd.mjs} +3 -3
- package/dist/{db-BTKyYu-_.cjs → db-ChMbb_U-.cjs} +8 -8
- package/dist/{email-verification-CWhj2qfb.mjs → email-verification-C_lBu_JY.mjs} +3 -3
- package/dist/{email-verification-C-AsfJsb.cjs → email-verification-DI_0H4JC.cjs} +5 -5
- package/dist/{hono-Cdukwu5K.cjs → hono-C14rpOEa.cjs} +1 -1
- package/dist/{hono-Covz10jU.mjs → hono-CO-zsqI-.mjs} +2 -2
- package/dist/{hono-BEq1NYVX.cjs → hono-DnW5crl1.cjs} +4 -4
- package/dist/{index-BVHscLQl.d.cts → index-4PEF72Mq.d.cts} +20 -20
- package/dist/{index-B-WeOMzg.d.cts → index-BCzB3uDD.d.cts} +833 -833
- package/dist/{index-B09P9p5_.d.cts → index-Bw8dyZTc.d.cts} +6 -6
- package/dist/{index-Qu-iJGNr.d.mts → index-C0b8eC8h.d.mts} +16 -16
- package/dist/{index-jlessPI0.d.mts → index-CrmLTEj8.d.mts} +382 -382
- package/dist/index-Dfgobqa-.d.mts +33 -0
- package/dist/index.cjs +721 -27
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +711 -16
- package/dist/integrations/next-js.cjs +3 -3
- package/dist/integrations/next-js.d.cts +5 -5
- package/dist/integrations/next-js.d.mts +6 -6
- package/dist/integrations/next-js.mjs +2 -2
- package/dist/integrations/node.d.cts +1 -1
- package/dist/integrations/node.d.mts +2 -2
- package/dist/integrations/react-start.cjs +3 -3
- package/dist/integrations/react-start.d.cts +5 -5
- package/dist/integrations/react-start.d.mts +5 -5
- package/dist/integrations/react-start.mjs +2 -2
- package/dist/integrations/svelte-kit.cjs +3 -3
- package/dist/integrations/svelte-kit.d.cts +5 -5
- package/dist/integrations/svelte-kit.d.mts +6 -6
- package/dist/integrations/svelte-kit.mjs +2 -2
- package/dist/{ip-B5SwXaMB.cjs → ip-C17Qdq-G.cjs} +2 -2
- package/dist/{json-CcJ2HjGo.cjs → json--tl7Grvs.cjs} +1 -1
- package/dist/{kysely-adapter-DRuoT_X8.mjs → kysely-adapter-CtIdoHa8.mjs} +3 -3
- package/dist/{kysely-adapter-Bxi7sPdG.cjs → kysely-adapter-QZTx077T.cjs} +4 -4
- package/dist/{logged-DQK3C64b.cjs → logged-Dv3st5qc.cjs} +1 -1
- package/dist/{memory-adapter-BlnDIAAX.cjs → memory-adapter-17RZd5df.cjs} +2 -2
- package/dist/{memory-adapter-Db3tsJTn.mjs → memory-adapter-Dp4XdCZK.mjs} +1 -1
- package/dist/{node-sqlite-dialect-mJWC8LWQ.cjs → node-sqlite-dialect-DP11CB0y.cjs} +1 -1
- package/dist/oauth2/index.cjs +11 -11
- package/dist/oauth2/index.d.cts +1 -1
- package/dist/oauth2/index.d.mts +2 -2
- package/dist/oauth2/index.mjs +6 -6
- package/dist/{oauth2-BLeOEi7Y.cjs → oauth2-5RL4cVNS.cjs} +3 -3
- package/dist/{oauth2-B8M0lW9l.mjs → oauth2-C56wz-n9.mjs} +2 -2
- package/dist/{origin-check-id9lTnqZ.cjs → origin-check-DjLTuZQ8.cjs} +2 -2
- package/dist/{passkey-B6N20LSS.cjs → passkey-BTT-v5c-.cjs} +4 -4
- package/dist/{passkey-DJsR_GX3.mjs → passkey-CzY_W2us.mjs} +2 -2
- package/dist/plugins/access/index.cjs +1 -1
- package/dist/plugins/access/index.d.cts +1 -1
- package/dist/plugins/access/index.d.mts +1 -1
- package/dist/plugins/access/index.mjs +1 -1
- package/dist/plugins/bearer/index.cjs +4 -4
- package/dist/plugins/bearer/index.d.cts +2 -2
- package/dist/plugins/bearer/index.d.mts +3 -3
- package/dist/plugins/bearer/index.mjs +3 -3
- package/dist/plugins/index.cjs +5215 -31
- package/dist/plugins/index.d.cts +351 -351
- package/dist/plugins/index.d.mts +268 -268
- package/dist/plugins/index.mjs +5202 -19
- package/dist/plugins/passkey/index.cjs +10 -10
- package/dist/plugins/passkey/index.d.cts +2 -2
- package/dist/plugins/passkey/index.d.mts +3 -3
- package/dist/plugins/passkey/index.mjs +5 -5
- package/dist/{schema-D-qjygfE.cjs → schema-CirKflVs.cjs} +2 -2
- package/dist/{session-rH8ougDl.mjs → session-CM3rmOYF.mjs} +1 -1
- package/dist/{session-De9POJTW.cjs → session-Cwrj4GfV.cjs} +5 -5
- package/dist/social-providers/index.cjs +1 -1
- package/dist/social-providers/index.d.cts +1 -1
- package/dist/social-providers/index.d.mts +1 -1
- package/dist/social-providers/index.mjs +1 -1
- package/dist/{social-providers-DoYJhBe3.mjs → social-providers-B8RK5yqI.mjs} +1 -1
- package/dist/{social-providers-DcFNUT0S.cjs → social-providers-BmFOIIPk.cjs} +1 -1
- package/dist/{state-CqJfCIl9.mjs → state-CQghgH9I.mjs} +1 -1
- package/dist/{state--f7fwIGh.cjs → state-CvSihlVT.cjs} +2 -2
- package/dist/test-utils/bun-sqlite-dialect-BSWhhKNs.mjs +155 -0
- package/dist/test-utils/bun-sqlite-dialect-BZBvHchL.cjs +156 -0
- package/dist/test-utils/index.cjs +8927 -482
- package/dist/test-utils/index.d.cts +8395 -337
- package/dist/test-utils/index.d.mts +8394 -334
- package/dist/test-utils/index.mjs +8712 -265
- package/dist/test-utils/node-sqlite-dialect-BgJqjBOu.cjs +156 -0
- package/dist/test-utils/node-sqlite-dialect-DAQXiobH.mjs +155 -0
- package/dist/types/index.d.cts +1 -1
- package/dist/types/index.d.mts +2 -2
- package/dist/{url-D2yvKaM7.cjs → url-Ce7CVaQD.cjs} +1 -1
- package/dist/utils/cookies.cjs +4 -4
- package/dist/utils/cookies.d.cts +1 -1
- package/dist/utils/cookies.d.mts +2 -2
- package/dist/utils/cookies.mjs +2 -2
- package/package.json +2 -2
- package/dist/auth-Bo9PDt5j.cjs +0 -739
- package/dist/auth-Ds4AG4h4.mjs +0 -709
- package/dist/index-C2-2QDyS.d.cts +0 -35
- package/dist/index-CWAqWfoZ.d.cts +0 -27
- package/dist/index-CYSShrFx.d.mts +0 -27
- package/dist/index-ppgcFe12.d.mts +0 -33
- package/dist/index-to0RO38U.d.mts +0 -35
- package/dist/mongodb-adapter-C_qGQED5.mjs +0 -291
- package/dist/mongodb-adapter-C_qfK87x.cjs +0 -297
- package/dist/plugins-C1lm2Wj3.cjs +0 -5254
- package/dist/plugins-Dai1QkRU.mjs +0 -5199
- package/dist/vanilla-Bu2PmFzE.cjs +0 -30
- package/dist/vanilla-TfHqeiC7.mjs +0 -25
- /package/dist/{access-B5bBI4uT.mjs → access-D0DRqUKC.mjs} +0 -0
- /package/dist/{adapter-factory-BXei1QRX.mjs → adapter-factory-lKIOf2OR.mjs} +0 -0
- /package/dist/{bun-sqlite-dialect-CfkBo2v5.mjs → bun-sqlite-dialect-6NqeV3px.mjs} +0 -0
- /package/dist/{defu-B0Svx_x4.cjs → defu-BmOYq4PU.cjs} +0 -0
- /package/dist/{defu-SZkpHhbR.mjs → defu-D9ZTXqlo.mjs} +0 -0
- /package/dist/{hono-DuE14mmj.d.mts → hono-D0VqxVy1.d.mts} +0 -0
- /package/dist/{index-B5_0QTLg.d.mts → index-BDhhaE6Y.d.cts} +0 -0
- /package/dist/{index-B7SKyR_a.d.cts → index-CF9iq55a.d.mts} +0 -0
- /package/dist/{index-CTwrVluH.d.mts → index-CRt_fppq.d.mts} +0 -0
- /package/dist/{index-cs4Sh0En.d.cts → index-CdLyn7qP.d.cts} +0 -0
- /package/dist/{node-sqlite-dialect-BfBzyOAg.mjs → node-sqlite-dialect-w4DAg0PH.mjs} +0 -0
- /package/dist/{parser-CeAer-RM.mjs → parser-B25ylT5u.mjs} +0 -0
- /package/dist/{parser-CdncAl9i.cjs → parser-B_wxvaAr.cjs} +0 -0
package/dist/auth-Ds4AG4h4.mjs
DELETED
|
@@ -1,709 +0,0 @@
|
|
|
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 };
|