faire-auth 1.0.4 → 1.1.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 (228) hide show
  1. package/dist/{adapter-factory-lKIOf2OR.mjs → adapter-factory-qPVW8x9-.mjs} +34 -36
  2. package/dist/{adapter-factory-D1I7joki.cjs → adapter-factory-u8r3oTez.cjs} +66 -68
  3. package/dist/adapters/drizzle-adapter/index.cjs +34 -40
  4. package/dist/adapters/drizzle-adapter/index.d.cts +4 -9
  5. package/dist/adapters/drizzle-adapter/index.d.mts +4 -9
  6. package/dist/adapters/drizzle-adapter/index.mjs +20 -26
  7. package/dist/adapters/index.cjs +11 -16
  8. package/dist/adapters/index.d.cts +11 -37
  9. package/dist/adapters/index.d.mts +11 -37
  10. package/dist/adapters/index.mjs +4 -13
  11. package/dist/adapters/kysely-adapter/index.cjs +270 -11
  12. package/dist/adapters/kysely-adapter/index.d.cts +9 -19
  13. package/dist/adapters/kysely-adapter/index.d.mts +9 -19
  14. package/dist/adapters/kysely-adapter/index.mjs +267 -9
  15. package/dist/adapters/memory-adapter/index.cjs +146 -9
  16. package/dist/adapters/memory-adapter/index.d.cts +4 -10
  17. package/dist/adapters/memory-adapter/index.d.mts +4 -10
  18. package/dist/adapters/memory-adapter/index.mjs +145 -9
  19. package/dist/adapters/mongodb-adapter/index.cjs +13 -21
  20. package/dist/adapters/mongodb-adapter/index.d.cts +3 -8
  21. package/dist/adapters/mongodb-adapter/index.d.mts +4 -9
  22. package/dist/adapters/mongodb-adapter/index.mjs +12 -20
  23. package/dist/adapters/prisma-adapter/index.cjs +12 -20
  24. package/dist/adapters/prisma-adapter/index.d.cts +4 -8
  25. package/dist/adapters/prisma-adapter/index.d.mts +4 -8
  26. package/dist/adapters/prisma-adapter/index.mjs +5 -13
  27. package/dist/adapters/test.cjs +86 -69
  28. package/dist/adapters/test.d.cts +7 -11
  29. package/dist/adapters/test.d.mts +7 -11
  30. package/dist/adapters/test.mjs +83 -66
  31. package/dist/api/index.cjs +3 -20
  32. package/dist/api/index.d.cts +2 -3
  33. package/dist/api/index.d.mts +2 -3
  34. package/dist/api/index.mjs +1 -20
  35. package/dist/api/middleware/index.cjs +4 -11
  36. package/dist/api/middleware/index.d.cts +3 -9
  37. package/dist/api/middleware/index.d.mts +3 -9
  38. package/dist/api/middleware/index.mjs +3 -11
  39. package/dist/{api-B4RDwBty.mjs → api-0f-F-Fi2.mjs} +292 -189
  40. package/dist/{api-CaRC1Gio.cjs → api-LjfH6hQi.cjs} +557 -452
  41. package/dist/{test-utils/bun-sqlite-dialect-BZBvHchL.cjs → bun-sqlite-dialect-BHkarnxN.cjs} +5 -9
  42. package/dist/{test-utils/bun-sqlite-dialect-BSWhhKNs.mjs → bun-sqlite-dialect-BiZBuEF6.mjs} +6 -9
  43. package/dist/client/index.cjs +8 -15
  44. package/dist/client/index.d.cts +9 -14
  45. package/dist/client/index.d.mts +9 -14
  46. package/dist/client/index.mjs +7 -15
  47. package/dist/client/lynx/index.cjs +10 -18
  48. package/dist/client/lynx/index.d.cts +402 -71
  49. package/dist/client/lynx/index.d.mts +402 -71
  50. package/dist/client/lynx/index.mjs +5 -13
  51. package/dist/client/plugins/index.cjs +3 -5
  52. package/dist/client/plugins/index.d.cts +5 -10
  53. package/dist/client/plugins/index.d.mts +5 -10
  54. package/dist/client/plugins/index.mjs +2 -4
  55. package/dist/client/react/index.cjs +6 -14
  56. package/dist/client/react/index.d.cts +402 -71
  57. package/dist/client/react/index.d.mts +402 -71
  58. package/dist/client/react/index.mjs +5 -13
  59. package/dist/client/solid/index.cjs +6 -14
  60. package/dist/client/solid/index.d.cts +393 -57
  61. package/dist/client/solid/index.d.mts +393 -57
  62. package/dist/client/solid/index.mjs +5 -13
  63. package/dist/client/svelte/index.cjs +5 -10
  64. package/dist/client/svelte/index.d.cts +400 -67
  65. package/dist/client/svelte/index.d.mts +400 -67
  66. package/dist/client/svelte/index.mjs +4 -10
  67. package/dist/client/vue/index.cjs +6 -14
  68. package/dist/client/vue/index.d.cts +401 -68
  69. package/dist/client/vue/index.d.mts +401 -68
  70. package/dist/client/vue/index.mjs +5 -13
  71. package/dist/{cookies-BTs1o992.mjs → cookies-D9aY_gJh.mjs} +25 -21
  72. package/dist/{cookies-BTl72THv.cjs → cookies-DQ52rcOy.cjs} +119 -115
  73. package/dist/crypto/index.cjs +10 -8
  74. package/dist/crypto/index.d.cts +5 -13
  75. package/dist/crypto/index.d.mts +5 -13
  76. package/dist/crypto/index.mjs +2 -5
  77. package/dist/{crypto-DH2Aa7jN.mjs → crypto-BH-hD0lJ.mjs} +7 -10
  78. package/dist/{crypto-DpSCnrTp.cjs → crypto-BITfWVwD.cjs} +24 -27
  79. package/dist/db/index.cjs +1135 -29
  80. package/dist/db/index.d.cts +1 -2
  81. package/dist/db/index.d.mts +1 -2
  82. package/dist/db/index.mjs +1115 -16
  83. package/dist/defu-D2h4S3X-.mjs +87 -0
  84. package/dist/defu-DWS5RPWt.cjs +134 -0
  85. package/dist/{email-verification-DI_0H4JC.cjs → email-verification-DOPnSgbI.cjs} +65 -71
  86. package/dist/{email-verification-C_lBu_JY.mjs → email-verification-YSR5n5lb.mjs} +23 -29
  87. package/dist/{hono-CO-zsqI-.mjs → hono-BAV2wQkK.mjs} +16 -33
  88. package/dist/hono-SVQuc5Ru.mjs +4 -0
  89. package/dist/hono-pgK4H_U1.cjs +9 -0
  90. package/dist/{hono-DnW5crl1.cjs → hono-tyFFJFdS.cjs} +42 -60
  91. package/dist/index-B86Cy0dE.d.cts +2 -0
  92. package/dist/index-B86Cy0dE.d.mts +2 -0
  93. package/dist/index.cjs +115 -150
  94. package/dist/index.d.cts +4 -5
  95. package/dist/index.d.mts +4 -5
  96. package/dist/index.mjs +45 -80
  97. package/dist/integrations/next-js.cjs +5 -9
  98. package/dist/integrations/next-js.d.cts +6 -14
  99. package/dist/integrations/next-js.d.mts +6 -14
  100. package/dist/integrations/next-js.mjs +4 -9
  101. package/dist/integrations/node.cjs +16 -14
  102. package/dist/integrations/node.d.cts +6 -14
  103. package/dist/integrations/node.d.mts +6 -14
  104. package/dist/integrations/node.mjs +15 -13
  105. package/dist/integrations/react-start.cjs +7 -11
  106. package/dist/integrations/react-start.d.cts +5 -13
  107. package/dist/integrations/react-start.d.mts +5 -13
  108. package/dist/integrations/react-start.mjs +6 -11
  109. package/dist/integrations/solid-start.cjs +3 -5
  110. package/dist/integrations/solid-start.d.cts +2 -5
  111. package/dist/integrations/solid-start.d.mts +2 -5
  112. package/dist/integrations/solid-start.mjs +2 -4
  113. package/dist/integrations/svelte-kit.cjs +6 -10
  114. package/dist/integrations/svelte-kit.d.cts +11 -23
  115. package/dist/integrations/svelte-kit.d.mts +11 -23
  116. package/dist/integrations/svelte-kit.mjs +5 -10
  117. package/dist/{ip-BjNYspCH.mjs → ip-6Lv2o42m.mjs} +4 -9
  118. package/dist/{ip-C17Qdq-G.cjs → ip-DPydExzV.cjs} +21 -27
  119. package/dist/{json--tl7Grvs.cjs → json-D3aq-nH2.cjs} +9 -13
  120. package/dist/{json-B1v2qRTQ.mjs → json-DooGMtnJ.mjs} +2 -5
  121. package/dist/{logged-CyGfp8_H.mjs → logged-B83SzMnJ.mjs} +6 -10
  122. package/dist/{logged-Dv3st5qc.cjs → logged-BIpCpnVY.cjs} +13 -18
  123. package/dist/{middleware-CE6OhDkq.mjs → middleware-Cakg4e1D.mjs} +2 -4
  124. package/dist/{middleware-CWvRH4EW.cjs → middleware-Cd-VkNxB.cjs} +17 -20
  125. package/dist/{node-sqlite-dialect-w4DAg0PH.mjs → node-sqlite-dialect-BMVOjEMh.mjs} +6 -9
  126. package/dist/{test-utils/node-sqlite-dialect-BgJqjBOu.cjs → node-sqlite-dialect-D3QPFROH.cjs} +5 -9
  127. package/dist/oauth2/index.cjs +166 -22
  128. package/dist/oauth2/index.d.cts +5 -17
  129. package/dist/oauth2/index.d.mts +5 -17
  130. package/dist/oauth2/index.mjs +156 -16
  131. package/dist/{origin-check-DjLTuZQ8.cjs → origin-check-BflGhEEN.cjs} +34 -38
  132. package/dist/{origin-check-8Gajklvh.mjs → origin-check-CRgs1M7k.mjs} +13 -16
  133. package/dist/{parser-B25ylT5u.mjs → parser-CqwvpF6l.cjs} +12 -10
  134. package/dist/{parser-B_wxvaAr.cjs → parser-DcKDjjHO.mjs} +7 -22
  135. package/dist/plugins/access/index.cjs +38 -4
  136. package/dist/plugins/access/index.d.cts +36 -2
  137. package/dist/plugins/access/index.d.mts +36 -2
  138. package/dist/plugins/access/index.mjs +36 -3
  139. package/dist/plugins/bearer/index.cjs +52 -7
  140. package/dist/plugins/bearer/index.d.cts +27 -4
  141. package/dist/plugins/bearer/index.d.mts +27 -4
  142. package/dist/plugins/bearer/index.mjs +51 -7
  143. package/dist/plugins/index.cjs +1385 -842
  144. package/dist/plugins/index.d.cts +489 -7566
  145. package/dist/plugins/index.d.mts +489 -7566
  146. package/dist/plugins/index.mjs +1118 -576
  147. package/dist/plugins/passkey/index.cjs +551 -15
  148. package/dist/plugins/passkey/index.d.cts +123 -4
  149. package/dist/plugins/passkey/index.d.mts +123 -4
  150. package/dist/plugins/passkey/index.mjs +547 -15
  151. package/dist/{chunk-BFnQceUY.mjs → rolldown-runtime-BKpuH2hG.mjs} +6 -7
  152. package/dist/{chunk-fPmz2rbM.cjs → rolldown-runtime-C_Pgydhf.cjs} +22 -24
  153. package/dist/{schema-DTIwLLmf.mjs → schema-CFCpv0tK.mjs} +3 -6
  154. package/dist/{schema-CirKflVs.cjs → schema-b-lKhMkG.cjs} +51 -55
  155. package/dist/{session-CM3rmOYF.mjs → session-BGjJgihS.mjs} +51 -74
  156. package/dist/{session-Cwrj4GfV.cjs → session-CzZSMmQC.cjs} +197 -219
  157. package/dist/shared.d.cts +1581 -0
  158. package/dist/shared.d.mts +1581 -0
  159. package/dist/social-providers/index.cjs +9 -9
  160. package/dist/social-providers/index.d.cts +1 -1
  161. package/dist/social-providers/index.d.mts +1 -1
  162. package/dist/social-providers/index.mjs +3 -5
  163. package/dist/social-providers-CjPww-qf.mjs +6 -0
  164. package/dist/social-providers-D7w_7Ym8.cjs +10 -0
  165. package/dist/{state-CvSihlVT.cjs → state-2OrNjOO-.cjs} +24 -24
  166. package/dist/{state-CQghgH9I.mjs → state-Dooeisfq.mjs} +17 -17
  167. package/dist/{bun-sqlite-dialect-DPgTzc0w.cjs → test-utils/bun-sqlite-dialect-BHkarnxN.cjs} +5 -9
  168. package/dist/{bun-sqlite-dialect-6NqeV3px.mjs → test-utils/bun-sqlite-dialect-BiZBuEF6.mjs} +6 -9
  169. package/dist/test-utils/index.cjs +8831 -7941
  170. package/dist/test-utils/index.d.cts +310 -12440
  171. package/dist/test-utils/index.d.mts +313 -12440
  172. package/dist/test-utils/index.mjs +8591 -7701
  173. package/dist/test-utils/{node-sqlite-dialect-DAQXiobH.mjs → node-sqlite-dialect-BMVOjEMh.mjs} +6 -9
  174. package/dist/{node-sqlite-dialect-DP11CB0y.cjs → test-utils/node-sqlite-dialect-D3QPFROH.cjs} +5 -9
  175. package/dist/types/index.d.cts +2 -3
  176. package/dist/types/index.d.mts +2 -3
  177. package/dist/types/index.mjs +1 -1
  178. package/dist/{url-BoUuoIwZ.mjs → url-CJtdrrUu.mjs} +12 -13
  179. package/dist/{url-Ce7CVaQD.cjs → url-DjCmCUHS.cjs} +42 -44
  180. package/dist/utils/cookies.cjs +29 -30
  181. package/dist/utils/cookies.d.cts +21 -25
  182. package/dist/utils/cookies.d.mts +20 -24
  183. package/dist/utils/cookies.mjs +2 -7
  184. package/dist/utils-C7OHyfHa.mjs +4 -0
  185. package/dist/utils-iX0Vy_UL.cjs +3 -0
  186. package/package.json +40 -30
  187. package/dist/access-BZ7-AbTM.cjs +0 -51
  188. package/dist/access-D0DRqUKC.mjs +0 -39
  189. package/dist/bearer-DDzrp5M7.cjs +0 -60
  190. package/dist/bearer-WZcs7gxL.mjs +0 -54
  191. package/dist/db-4tUsQJXd.mjs +0 -1119
  192. package/dist/db-ChMbb_U-.cjs +0 -1180
  193. package/dist/defu-BmOYq4PU.cjs +0 -34
  194. package/dist/defu-D9ZTXqlo.mjs +0 -28
  195. package/dist/hono-C14rpOEa.cjs +0 -13
  196. package/dist/hono-CoKYWnXA.mjs +0 -7
  197. package/dist/hono-D0VqxVy1.d.mts +0 -18
  198. package/dist/hono-DOM31WQz.d.cts +0 -18
  199. package/dist/index--DLiUhEn.d.mts +0 -33
  200. package/dist/index-B4bqEDYG.d.mts +0 -992
  201. package/dist/index-BDhhaE6Y.d.cts +0 -3
  202. package/dist/index-Boa0SV4h.d.cts +0 -13350
  203. package/dist/index-Bykgiq3o.d.cts +0 -13350
  204. package/dist/index-CF9iq55a.d.mts +0 -3
  205. package/dist/index-CRt_fppq.d.mts +0 -41
  206. package/dist/index-CdLyn7qP.d.cts +0 -41
  207. package/dist/index-ClFGA8tb.d.mts +0 -33
  208. package/dist/index-ClOM0wFf.d.cts +0 -992
  209. package/dist/index-CsxNfGAV.d.mts +0 -13350
  210. package/dist/index-DKnO_Zfm.d.cts +0 -992
  211. package/dist/index-DRYO4mGd.d.cts +0 -33
  212. package/dist/index-Dsua4U8w.d.cts +0 -33
  213. package/dist/index-DxXFCG2_.d.mts +0 -13350
  214. package/dist/index-gtCVvDvC.d.mts +0 -992
  215. package/dist/kysely-adapter-CtIdoHa8.mjs +0 -270
  216. package/dist/kysely-adapter-QZTx077T.cjs +0 -288
  217. package/dist/memory-adapter-17RZd5df.cjs +0 -154
  218. package/dist/memory-adapter-Dp4XdCZK.mjs +0 -148
  219. package/dist/oauth2-5RL4cVNS.cjs +0 -177
  220. package/dist/oauth2-C56wz-n9.mjs +0 -159
  221. package/dist/passkey-BTT-v5c-.cjs +0 -512
  222. package/dist/passkey-CzY_W2us.mjs +0 -505
  223. package/dist/request-1NL_1lyJ.mjs +0 -58
  224. package/dist/request-CPNlp-DK.cjs +0 -100
  225. package/dist/social-providers-B8RK5yqI.mjs +0 -9
  226. package/dist/social-providers-BmFOIIPk.cjs +0 -13
  227. package/dist/utils-44aDDP8f.cjs +0 -2
  228. package/dist/utils-D4vZd1-9.mjs +0 -4
@@ -1,7 +1,5 @@
1
- const require_index = require('./index.cjs');
2
1
  let kysely = require("kysely");
3
-
4
- //#region src/adapters/kysely-adapter/node-sqlite-dialect.ts
2
+ // src/adapters/kysely-adapter/node-sqlite-dialect.ts
5
3
  var NodeSqliteAdapter = class {
6
4
  get supportsCreateIfNotExists() {
7
5
  return true;
@@ -57,8 +55,8 @@ var NodeSqliteConnection = class {
57
55
  this.#db = db;
58
56
  }
59
57
  executeQuery(compiledQuery) {
60
- const { sql: sql$1, parameters } = compiledQuery;
61
- const rows = this.#db.prepare(sql$1).all(...parameters);
58
+ const { sql, parameters } = compiledQuery;
59
+ const rows = this.#db.prepare(sql).all(...parameters);
62
60
  return Promise.resolve({ rows });
63
61
  }
64
62
  async *streamQuery() {
@@ -69,7 +67,7 @@ var ConnectionMutex = class {
69
67
  #promise;
70
68
  #resolve;
71
69
  async lock() {
72
- while (this.#promise) await this.#promise;
70
+ while (this.#promise !== void 0) await this.#promise;
73
71
  this.#promise = new Promise((resolve) => {
74
72
  this.#resolve = resolve;
75
73
  });
@@ -151,6 +149,4 @@ var NodeSqliteDialect = class {
151
149
  return new NodeSqliteIntrospector(db);
152
150
  }
153
151
  };
154
-
155
- //#endregion
156
- exports.NodeSqliteDialect = NodeSqliteDialect;
152
+ exports.NodeSqliteDialect = NodeSqliteDialect;
@@ -1,25 +1,169 @@
1
- require('../hono-C14rpOEa.cjs');
2
- require('../crypto-DpSCnrTp.cjs');
3
- require('../json--tl7Grvs.cjs');
4
- require('../cookies-BTl72THv.cjs');
5
- require('../logged-Dv3st5qc.cjs');
6
- require('../url-Ce7CVaQD.cjs');
7
- require('../middleware-CWvRH4EW.cjs');
8
- require('../session-Cwrj4GfV.cjs');
9
- require('../origin-check-DjLTuZQ8.cjs');
10
- require('../email-verification-DI_0H4JC.cjs');
11
- const require_oauth2 = require('../oauth2-5RL4cVNS.cjs');
12
- const require_state = require('../state-CvSihlVT.cjs');
13
-
14
- exports.decryptOAuthToken = require_oauth2.decryptOAuthToken;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_crypto = require("../crypto-BITfWVwD.cjs");
3
+ const require_state = require("../state-2OrNjOO-.cjs");
4
+ const require_email_verification = require("../email-verification-DOPnSgbI.cjs");
5
+ let _faire_auth_core_env = require("@faire-auth/core/env");
6
+ let _faire_auth_core_error = require("@faire-auth/core/error");
7
+ // src/oauth2/utils.ts
8
+ const decryptOAuthToken = (token, ctx, options) => {
9
+ if (!token) return token;
10
+ if (options.account?.encryptOAuthTokens) return (0, require_crypto.crypto_exports.symmetricDecrypt)({
11
+ key: ctx.get("context").secret,
12
+ data: token
13
+ });
14
+ return token;
15
+ };
16
+ const setTokenUtil = (token, ctx, options) => {
17
+ if (options.account?.encryptOAuthTokens && token) return (0, require_crypto.crypto_exports.symmetricEncrypt)({
18
+ key: ctx.get("context").secret,
19
+ data: token
20
+ });
21
+ return token;
22
+ };
23
+ // src/oauth2/link-account.ts
24
+ const handleOAuthUserInfo = async (ctx, { userInfo, account, callbackURL, disableSignUp, overrideUserInfo }, options) => {
25
+ const context = ctx.get("context");
26
+ const redirectOnError = (reason) => {
27
+ const errorURL = options.onAPIError?.errorURL ?? `${context.baseURL}/error`;
28
+ return {
29
+ type: "redirect",
30
+ response: ctx.redirect(`${errorURL}?error=${reason}`, 302)
31
+ };
32
+ };
33
+ const dbUser = await context.internalAdapter.findOAuthUser(userInfo.email.toLowerCase(), account.accountId, account.providerId).catch((e) => {
34
+ _faire_auth_core_env.logger.error("Better auth was unable to query your database.\nError: ", e);
35
+ return "error";
36
+ });
37
+ if (dbUser === "error") return redirectOnError("internal_server_error");
38
+ let user = dbUser?.user ?? null;
39
+ const isRegister = user == null;
40
+ if (dbUser) {
41
+ const hasBeenLinked = dbUser.accounts.find((a) => a.providerId === account.providerId && a.accountId === account.accountId);
42
+ if (!hasBeenLinked) {
43
+ if (!(options.account?.accountLinking?.trustedProviders)?.includes(account.providerId) && !userInfo.emailVerified || options.account?.accountLinking?.enabled === false) {
44
+ if ((0, _faire_auth_core_env.isDevelopment)()) _faire_auth_core_env.logger.warn(`User already exist but account isn't linked to ${account.providerId}. To read more about how account linking works in Faire Auth see https://www.faire-auth.com/docs/concepts/users-accounts#account-linking.`);
45
+ return {
46
+ type: "error",
47
+ reason: "account_not_linked"
48
+ };
49
+ }
50
+ try {
51
+ await context.internalAdapter.linkAccount({
52
+ providerId: account.providerId,
53
+ accountId: userInfo.id.toString(),
54
+ userId: dbUser.user.id,
55
+ accessToken: await setTokenUtil(account.accessToken, ctx, options),
56
+ refreshToken: await setTokenUtil(account.refreshToken, ctx, options),
57
+ idToken: account.idToken,
58
+ accessTokenExpiresAt: account.accessTokenExpiresAt,
59
+ refreshTokenExpiresAt: account.refreshTokenExpiresAt,
60
+ scope: account.scope
61
+ });
62
+ } catch (e) {
63
+ _faire_auth_core_env.logger.error("Unable to link account", e);
64
+ return {
65
+ type: "error",
66
+ reason: "unable_to_link_account"
67
+ };
68
+ }
69
+ if (userInfo.emailVerified && !dbUser.user.emailVerified && userInfo.email.toLowerCase() === dbUser.user.email) await context.internalAdapter.updateUser(dbUser.user.id, { emailVerified: true });
70
+ } else {
71
+ if (options.account?.updateAccountOnSignIn !== false) {
72
+ const updateData = Object.fromEntries(Object.entries({
73
+ idToken: account.idToken,
74
+ accessToken: await setTokenUtil(account.accessToken, ctx, options),
75
+ refreshToken: await setTokenUtil(account.refreshToken, ctx, options),
76
+ accessTokenExpiresAt: account.accessTokenExpiresAt,
77
+ refreshTokenExpiresAt: account.refreshTokenExpiresAt,
78
+ scope: account.scope
79
+ }).filter(([, value]) => value !== void 0 && value !== ""));
80
+ if (Object.keys(updateData).length > 0) await context.internalAdapter.updateAccount(hasBeenLinked.id, updateData);
81
+ }
82
+ if (userInfo.emailVerified && !dbUser.user.emailVerified && userInfo.email.toLowerCase() === dbUser.user.email) await context.internalAdapter.updateUser(dbUser.user.id, { emailVerified: true });
83
+ }
84
+ if (overrideUserInfo === true) {
85
+ const { id: _, ...restUserInfo } = userInfo;
86
+ await context.internalAdapter.updateUser(dbUser.user.id, {
87
+ ...restUserInfo,
88
+ email: userInfo.email.toLowerCase(),
89
+ emailVerified: userInfo.email.toLowerCase() === dbUser.user.email ? dbUser.user.emailVerified || userInfo.emailVerified : userInfo.emailVerified
90
+ });
91
+ }
92
+ } else {
93
+ if (disableSignUp === true) return {
94
+ type: "error",
95
+ reason: "signup_disabled",
96
+ isRegister: false
97
+ };
98
+ try {
99
+ const { id: _, ...restUserInfo } = userInfo;
100
+ user = await context.internalAdapter.createOAuthUser({
101
+ ...restUserInfo,
102
+ email: userInfo.email.toLowerCase()
103
+ }, {
104
+ accessToken: await setTokenUtil(account.accessToken, ctx, options),
105
+ refreshToken: await setTokenUtil(account.refreshToken, ctx, options),
106
+ idToken: account.idToken,
107
+ accessTokenExpiresAt: account.accessTokenExpiresAt,
108
+ refreshTokenExpiresAt: account.refreshTokenExpiresAt,
109
+ scope: account.scope,
110
+ providerId: account.providerId,
111
+ accountId: userInfo.id.toString()
112
+ }).then((res) => res.user);
113
+ if (!userInfo.emailVerified && user && options.emailVerification?.sendOnSignUp === true) {
114
+ const token = await require_email_verification.createEmailVerificationToken(context.secret, user.email, void 0, options.emailVerification.expiresIn);
115
+ const url = `${context.baseURL}/verify-email?token=${token}${callbackURL ? `&callbackURL=${callbackURL}` : ""}`;
116
+ await options.emailVerification.sendVerificationEmail?.({
117
+ user,
118
+ url,
119
+ token
120
+ }, ctx);
121
+ }
122
+ } catch (e) {
123
+ _faire_auth_core_env.logger.error(e instanceof Error ? e.message : String(e), e);
124
+ if (e instanceof _faire_auth_core_error.APIError) return {
125
+ type: "error",
126
+ reason: e.message,
127
+ isRegister: false
128
+ };
129
+ return {
130
+ type: "error",
131
+ reason: "unable_to_create_user",
132
+ isRegister: false
133
+ };
134
+ }
135
+ }
136
+ if (!user) return {
137
+ type: "error",
138
+ reason: "unable_to_create_user",
139
+ isRegister: false
140
+ };
141
+ const session = await context.internalAdapter.createSession(user.id);
142
+ if (!session) return {
143
+ type: "error",
144
+ reason: "unable_to_create_session",
145
+ isRegister: false
146
+ };
147
+ return {
148
+ type: "success",
149
+ data: {
150
+ session,
151
+ user
152
+ },
153
+ isRegister
154
+ };
155
+ };
156
+ exports.decryptOAuthToken = decryptOAuthToken;
15
157
  exports.generateState = require_state.generateState;
16
- exports.handleOAuthUserInfo = require_oauth2.handleOAuthUserInfo;
158
+ exports.handleOAuthUserInfo = handleOAuthUserInfo;
17
159
  exports.parseState = require_state.parseState;
18
- exports.setTokenUtil = require_oauth2.setTokenUtil;
19
- var __faire_auth_core_oauth2 = require("@faire-auth/core/oauth2");
20
- Object.keys(__faire_auth_core_oauth2).forEach(function (k) {
21
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
22
- enumerable: true,
23
- get: function () { return __faire_auth_core_oauth2[k]; }
24
- });
160
+ exports.setTokenUtil = setTokenUtil;
161
+ var _faire_auth_core_oauth2 = require("@faire-auth/core/oauth2");
162
+ Object.keys(_faire_auth_core_oauth2).forEach(function(k) {
163
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
164
+ enumerable: true,
165
+ get: function() {
166
+ return _faire_auth_core_oauth2[k];
167
+ }
168
+ });
25
169
  });
@@ -1,23 +1,12 @@
1
- import { I as FaireAuthOptions$1, M as generateState, N as parseState } from "../index-Boa0SV4h.cjs";
2
- import { t as ContextVars } from "../hono-DOM31WQz.cjs";
1
+ import { P as ContextVars, ht as FaireAuthOptions$1, v as generateState, y as parseState } from "../shared.cjs";
3
2
  import { ExK } from "@faire-auth/core/types";
4
3
  import { Context, TypedResponse } from "hono";
5
4
  import { Account, Session, User } from "@faire-auth/core/db";
6
5
  export * from "@faire-auth/core/oauth2";
7
-
8
- //#region src/oauth2/utils.d.ts
9
- declare const decryptOAuthToken: <V extends object>(token: string, ctx: Context<ContextVars<V>>, options: Pick<FaireAuthOptions$1, "account">) => string | Promise<string>;
10
- declare const setTokenUtil: <V extends object>(token: string | null | undefined, ctx: Context<ContextVars<V>>, options: Pick<FaireAuthOptions$1, "account">) => string | Promise<string> | null | undefined;
11
- //#endregion
12
- //#region src/oauth2/link-account.d.ts
6
+ export declare const decryptOAuthToken: <V extends object>(token: string, ctx: Context<ContextVars<V>>, options: Pick<FaireAuthOptions$1, "account">) => any;
7
+ export declare const setTokenUtil: <V extends object>(token: string | null | undefined, ctx: Context<ContextVars<V>>, options: Pick<FaireAuthOptions$1, "account">) => any;
13
8
  type OAuthError = "account_not_linked" | "unable_to_link_account" | "unable_to_create_user" | "unable_to_create_session" | "internal_server_error" | "signup_disabled" | (string & {});
14
- declare const handleOAuthUserInfo: (ctx: Context<ContextVars>, {
15
- userInfo,
16
- account,
17
- callbackURL,
18
- disableSignUp,
19
- overrideUserInfo
20
- }: {
9
+ export declare const handleOAuthUserInfo: (ctx: Context<ContextVars>, { userInfo, account, callbackURL, disableSignUp, overrideUserInfo }: {
21
10
  userInfo: ExK<User, "createdAt" | "updatedAt">;
22
11
  account: ExK<Account, "createdAt" | "id" | "updatedAt" | "userId">;
23
12
  callbackURL?: string;
@@ -38,5 +27,4 @@ declare const handleOAuthUserInfo: (ctx: Context<ContextVars>, {
38
27
  reason: OAuthError;
39
28
  isRegister?: false;
40
29
  }>;
41
- //#endregion
42
- export { decryptOAuthToken, generateState, handleOAuthUserInfo, parseState, setTokenUtil };
30
+ export { generateState, parseState };
@@ -1,23 +1,12 @@
1
- import { I as FaireAuthOptions$1, M as generateState, N as parseState } from "../index-DxXFCG2_.mjs";
2
- import { t as ContextVars } from "../hono-D0VqxVy1.mjs";
1
+ import { A as generateState, gt as FaireAuthOptions$1, j as parseState, t as ContextVars } from "../shared.mjs";
3
2
  import { Context, TypedResponse } from "hono";
4
3
  import { Account, Session, User } from "@faire-auth/core/db";
5
4
  import { ExK } from "@faire-auth/core/types";
6
5
  export * from "@faire-auth/core/oauth2";
7
-
8
- //#region src/oauth2/utils.d.ts
9
- declare const decryptOAuthToken: <V extends object>(token: string, ctx: Context<ContextVars<V>>, options: Pick<FaireAuthOptions$1, "account">) => string | Promise<string>;
10
- declare const setTokenUtil: <V extends object>(token: string | null | undefined, ctx: Context<ContextVars<V>>, options: Pick<FaireAuthOptions$1, "account">) => string | Promise<string> | null | undefined;
11
- //#endregion
12
- //#region src/oauth2/link-account.d.ts
6
+ export declare const decryptOAuthToken: <V extends object>(token: string, ctx: Context<ContextVars<V>>, options: Pick<FaireAuthOptions$1, "account">) => any;
7
+ export declare const setTokenUtil: <V extends object>(token: string | null | undefined, ctx: Context<ContextVars<V>>, options: Pick<FaireAuthOptions$1, "account">) => any;
13
8
  type OAuthError = "account_not_linked" | "unable_to_link_account" | "unable_to_create_user" | "unable_to_create_session" | "internal_server_error" | "signup_disabled" | (string & {});
14
- declare const handleOAuthUserInfo: (ctx: Context<ContextVars>, {
15
- userInfo,
16
- account,
17
- callbackURL,
18
- disableSignUp,
19
- overrideUserInfo
20
- }: {
9
+ export declare const handleOAuthUserInfo: (ctx: Context<ContextVars>, { userInfo, account, callbackURL, disableSignUp, overrideUserInfo }: {
21
10
  userInfo: ExK<User, "createdAt" | "updatedAt">;
22
11
  account: ExK<Account, "createdAt" | "id" | "updatedAt" | "userId">;
23
12
  callbackURL?: string;
@@ -38,5 +27,4 @@ declare const handleOAuthUserInfo: (ctx: Context<ContextVars>, {
38
27
  reason: OAuthError;
39
28
  isRegister?: false;
40
29
  }>;
41
- //#endregion
42
- export { decryptOAuthToken, generateState, handleOAuthUserInfo, parseState, setTokenUtil };
30
+ export { generateState, parseState };
@@ -1,16 +1,156 @@
1
- import "../hono-CoKYWnXA.mjs";
2
- import "../crypto-DH2Aa7jN.mjs";
3
- import "../json-B1v2qRTQ.mjs";
4
- import "../cookies-BTs1o992.mjs";
5
- import "../logged-CyGfp8_H.mjs";
6
- import "../url-BoUuoIwZ.mjs";
7
- import "../middleware-CE6OhDkq.mjs";
8
- import "../session-CM3rmOYF.mjs";
9
- import "../origin-check-8Gajklvh.mjs";
10
- import "../email-verification-C_lBu_JY.mjs";
11
- import { n as decryptOAuthToken, r as setTokenUtil, t as handleOAuthUserInfo } from "../oauth2-C56wz-n9.mjs";
12
- import { n as parseState, t as generateState } from "../state-CQghgH9I.mjs";
13
-
14
- export * from "@faire-auth/core/oauth2"
15
-
16
- export { decryptOAuthToken, generateState, handleOAuthUserInfo, parseState, setTokenUtil };
1
+ import { n as crypto_exports } from "../crypto-BH-hD0lJ.mjs";
2
+ import { n as parseState, t as generateState } from "../state-Dooeisfq.mjs";
3
+ import { t as createEmailVerificationToken } from "../email-verification-YSR5n5lb.mjs";
4
+ import { isDevelopment, logger } from "@faire-auth/core/env";
5
+ import { APIError } from "@faire-auth/core/error";
6
+ export * from "@faire-auth/core/oauth2";
7
+ // src/oauth2/utils.ts
8
+ const decryptOAuthToken = (token, ctx, options) => {
9
+ if (!token) return token;
10
+ if (options.account?.encryptOAuthTokens) return (0, crypto_exports.symmetricDecrypt)({
11
+ key: ctx.get("context").secret,
12
+ data: token
13
+ });
14
+ return token;
15
+ };
16
+ const setTokenUtil = (token, ctx, options) => {
17
+ if (options.account?.encryptOAuthTokens && token) return (0, crypto_exports.symmetricEncrypt)({
18
+ key: ctx.get("context").secret,
19
+ data: token
20
+ });
21
+ return token;
22
+ };
23
+ // src/oauth2/link-account.ts
24
+ const handleOAuthUserInfo = async (ctx, { userInfo, account, callbackURL, disableSignUp, overrideUserInfo }, options) => {
25
+ const context = ctx.get("context");
26
+ const redirectOnError = (reason) => {
27
+ const errorURL = options.onAPIError?.errorURL ?? `${context.baseURL}/error`;
28
+ return {
29
+ type: "redirect",
30
+ response: ctx.redirect(`${errorURL}?error=${reason}`, 302)
31
+ };
32
+ };
33
+ const dbUser = await context.internalAdapter.findOAuthUser(userInfo.email.toLowerCase(), account.accountId, account.providerId).catch((e) => {
34
+ logger.error("Better auth was unable to query your database.\nError: ", e);
35
+ return "error";
36
+ });
37
+ if (dbUser === "error") return redirectOnError("internal_server_error");
38
+ let user = dbUser?.user ?? null;
39
+ const isRegister = user == null;
40
+ if (dbUser) {
41
+ const hasBeenLinked = dbUser.accounts.find((a) => a.providerId === account.providerId && a.accountId === account.accountId);
42
+ if (!hasBeenLinked) {
43
+ if (!(options.account?.accountLinking?.trustedProviders)?.includes(account.providerId) && !userInfo.emailVerified || options.account?.accountLinking?.enabled === false) {
44
+ if (isDevelopment()) logger.warn(`User already exist but account isn't linked to ${account.providerId}. To read more about how account linking works in Faire Auth see https://www.faire-auth.com/docs/concepts/users-accounts#account-linking.`);
45
+ return {
46
+ type: "error",
47
+ reason: "account_not_linked"
48
+ };
49
+ }
50
+ try {
51
+ await context.internalAdapter.linkAccount({
52
+ providerId: account.providerId,
53
+ accountId: userInfo.id.toString(),
54
+ userId: dbUser.user.id,
55
+ accessToken: await setTokenUtil(account.accessToken, ctx, options),
56
+ refreshToken: await setTokenUtil(account.refreshToken, ctx, options),
57
+ idToken: account.idToken,
58
+ accessTokenExpiresAt: account.accessTokenExpiresAt,
59
+ refreshTokenExpiresAt: account.refreshTokenExpiresAt,
60
+ scope: account.scope
61
+ });
62
+ } catch (e) {
63
+ logger.error("Unable to link account", e);
64
+ return {
65
+ type: "error",
66
+ reason: "unable_to_link_account"
67
+ };
68
+ }
69
+ if (userInfo.emailVerified && !dbUser.user.emailVerified && userInfo.email.toLowerCase() === dbUser.user.email) await context.internalAdapter.updateUser(dbUser.user.id, { emailVerified: true });
70
+ } else {
71
+ if (options.account?.updateAccountOnSignIn !== false) {
72
+ const updateData = Object.fromEntries(Object.entries({
73
+ idToken: account.idToken,
74
+ accessToken: await setTokenUtil(account.accessToken, ctx, options),
75
+ refreshToken: await setTokenUtil(account.refreshToken, ctx, options),
76
+ accessTokenExpiresAt: account.accessTokenExpiresAt,
77
+ refreshTokenExpiresAt: account.refreshTokenExpiresAt,
78
+ scope: account.scope
79
+ }).filter(([, value]) => value !== void 0 && value !== ""));
80
+ if (Object.keys(updateData).length > 0) await context.internalAdapter.updateAccount(hasBeenLinked.id, updateData);
81
+ }
82
+ if (userInfo.emailVerified && !dbUser.user.emailVerified && userInfo.email.toLowerCase() === dbUser.user.email) await context.internalAdapter.updateUser(dbUser.user.id, { emailVerified: true });
83
+ }
84
+ if (overrideUserInfo === true) {
85
+ const { id: _, ...restUserInfo } = userInfo;
86
+ await context.internalAdapter.updateUser(dbUser.user.id, {
87
+ ...restUserInfo,
88
+ email: userInfo.email.toLowerCase(),
89
+ emailVerified: userInfo.email.toLowerCase() === dbUser.user.email ? dbUser.user.emailVerified || userInfo.emailVerified : userInfo.emailVerified
90
+ });
91
+ }
92
+ } else {
93
+ if (disableSignUp === true) return {
94
+ type: "error",
95
+ reason: "signup_disabled",
96
+ isRegister: false
97
+ };
98
+ try {
99
+ const { id: _, ...restUserInfo } = userInfo;
100
+ user = await context.internalAdapter.createOAuthUser({
101
+ ...restUserInfo,
102
+ email: userInfo.email.toLowerCase()
103
+ }, {
104
+ accessToken: await setTokenUtil(account.accessToken, ctx, options),
105
+ refreshToken: await setTokenUtil(account.refreshToken, ctx, options),
106
+ idToken: account.idToken,
107
+ accessTokenExpiresAt: account.accessTokenExpiresAt,
108
+ refreshTokenExpiresAt: account.refreshTokenExpiresAt,
109
+ scope: account.scope,
110
+ providerId: account.providerId,
111
+ accountId: userInfo.id.toString()
112
+ }).then((res) => res.user);
113
+ if (!userInfo.emailVerified && user && options.emailVerification?.sendOnSignUp === true) {
114
+ const token = await createEmailVerificationToken(context.secret, user.email, void 0, options.emailVerification.expiresIn);
115
+ const url = `${context.baseURL}/verify-email?token=${token}${callbackURL ? `&callbackURL=${callbackURL}` : ""}`;
116
+ await options.emailVerification.sendVerificationEmail?.({
117
+ user,
118
+ url,
119
+ token
120
+ }, ctx);
121
+ }
122
+ } catch (e) {
123
+ logger.error(e instanceof Error ? e.message : String(e), e);
124
+ if (e instanceof APIError) return {
125
+ type: "error",
126
+ reason: e.message,
127
+ isRegister: false
128
+ };
129
+ return {
130
+ type: "error",
131
+ reason: "unable_to_create_user",
132
+ isRegister: false
133
+ };
134
+ }
135
+ }
136
+ if (!user) return {
137
+ type: "error",
138
+ reason: "unable_to_create_user",
139
+ isRegister: false
140
+ };
141
+ const session = await context.internalAdapter.createSession(user.id);
142
+ if (!session) return {
143
+ type: "error",
144
+ reason: "unable_to_create_session",
145
+ isRegister: false
146
+ };
147
+ return {
148
+ type: "success",
149
+ data: {
150
+ session,
151
+ user
152
+ },
153
+ isRegister
154
+ };
155
+ };
156
+ export { decryptOAuthToken, generateState, handleOAuthUserInfo, parseState, setTokenUtil };
@@ -1,10 +1,8 @@
1
- const require_chunk = require('./chunk-fPmz2rbM.cjs');
2
- const require_url = require('./url-Ce7CVaQD.cjs');
3
- const require_middleware = require('./middleware-CWvRH4EW.cjs');
4
- let __faire_auth_core_env = require("@faire-auth/core/env");
5
- let __faire_auth_core_static = require("@faire-auth/core/static");
6
-
7
- //#region src/utils/wildcard.ts
1
+ const require_url = require("./url-DjCmCUHS.cjs");
2
+ const require_middleware = require("./middleware-Cd-VkNxB.cjs");
3
+ let _faire_auth_core_env = require("@faire-auth/core/env");
4
+ let _faire_auth_core_static = require("@faire-auth/core/static");
5
+ // src/utils/wildcard.ts
8
6
  /**
9
7
  * Escapes a character if it has a special meaning in regular expressions
10
8
  * and returns the character as is if it doesn't
@@ -51,9 +49,11 @@ const transform = (pattern, separator = true) => {
51
49
  const nextSegment = segments[s + 1];
52
50
  let currentSeparator = "";
53
51
  if (segment == null && s > 0) continue;
54
- if (truthySeparator) if (s === segments.length - 1) currentSeparator = optionalSeparator;
55
- else if (nextSegment !== "**") currentSeparator = requiredSeparator;
56
- else currentSeparator = "";
52
+ if (truthySeparator) {
53
+ if (s === segments.length - 1) currentSeparator = optionalSeparator;
54
+ else if (nextSegment !== "**") currentSeparator = requiredSeparator;
55
+ else currentSeparator = "";
56
+ }
57
57
  if (truthySeparator && segment === "**") {
58
58
  if (currentSeparator) {
59
59
  result += s === 0 ? "" : currentSeparator;
@@ -116,9 +116,7 @@ function wildcardMatch(pattern, options) {
116
116
  fn.regexp = regexp;
117
117
  return fn;
118
118
  }
119
-
120
- //#endregion
121
- //#region src/api/middleware/origin-check.ts
119
+ // src/api/middleware/origin-check.ts
122
120
  const RELATIVE_PATH_RE = /^\/(?!\/|\\|%2f|%5c)[\w\-.\+/@]*(?:\?[\w\-.\+/=&%@]*)?$/;
123
121
  const matchesPattern = (url, pattern) => {
124
122
  if (url.startsWith("/")) return false;
@@ -129,17 +127,17 @@ const matchesPattern = (url, pattern) => {
129
127
  const protocol = require_url.getProtocol(url);
130
128
  return protocol === "http:" || protocol === "https:" || !protocol ? pattern === require_url.getOrigin(url) : url.startsWith(pattern);
131
129
  };
132
- const validateURL = (url, label, trustedOrigins, logger$1, ctx) => {
130
+ const validateURL = (url, label, trustedOrigins, logger, ctx) => {
133
131
  if (url == null) return null;
134
132
  let isTrustedOrigin = false;
135
133
  trustedOrigins.forEach((origin) => {
136
134
  if (isTrustedOrigin === false && (matchesPattern(url, origin) || url.startsWith("/") && label !== "origin" && RELATIVE_PATH_RE.test(url))) isTrustedOrigin = true;
137
135
  });
138
136
  if (!isTrustedOrigin) {
139
- logger$1.error(`Invalid ${label}: ${url}`);
140
- logger$1.info(`If it's a valid URL, please add ${url} to trustedOrigins in your auth config\n`, `Current list of trustedOrigins: ${[...trustedOrigins].join(", ")}`);
137
+ logger.error(`Invalid ${label}: ${url}`);
138
+ logger.info(`If it's a valid URL, please add ${url} to trustedOrigins in your auth config\n`, `Current list of trustedOrigins: ${[...trustedOrigins].join(", ")}`);
141
139
  return ctx.json({
142
- success: __faire_auth_core_static.False,
140
+ success: _faire_auth_core_static.False,
143
141
  message: `Invalid ${label}`
144
142
  }, 403);
145
143
  }
@@ -151,8 +149,8 @@ const validateURL = (url, label, trustedOrigins, logger$1, ctx) => {
151
149
  */
152
150
  const initOriginCheckMiddleware = (options, context) => {
153
151
  const log = {
154
- info: (message, ...args) => options.logger?.log?.("info", message, ...args) ?? __faire_auth_core_env.logger.info,
155
- error: (message, ...args) => options.logger?.log?.("error", message, ...args) ?? __faire_auth_core_env.logger.error
152
+ info: (message, ...args) => options.logger?.log?.("info", message, ...args) ?? _faire_auth_core_env.logger.info,
153
+ error: (message, ...args) => options.logger?.log?.("error", message, ...args) ?? _faire_auth_core_env.logger.error
156
154
  };
157
155
  return require_middleware.createMiddleware()(async (ctx, next) => {
158
156
  if (ctx.get("isServer") === true || ctx.req.method !== "POST") return await next();
@@ -213,7 +211,7 @@ const originCheck = (getValue) => {
213
211
  if (ctx.get("isServer") === true) return await next();
214
212
  const context = ctx.get("context");
215
213
  let callbackURL = getValue(ctx);
216
- if ((0, __faire_auth_core_static.isPromise)(callbackURL)) callbackURL = await callbackURL;
214
+ if ((0, _faire_auth_core_static.isPromise)(callbackURL)) callbackURL = await callbackURL;
217
215
  if (!callbackURL) return await next();
218
216
  const callbacks = Array.isArray(callbackURL) ? callbackURL : [callbackURL];
219
217
  let ret;
@@ -224,23 +222,21 @@ const originCheck = (getValue) => {
224
222
  return await next();
225
223
  });
226
224
  };
227
-
228
- //#endregion
229
- Object.defineProperty(exports, 'initOriginCheckMiddleware', {
230
- enumerable: true,
231
- get: function () {
232
- return initOriginCheckMiddleware;
233
- }
225
+ Object.defineProperty(exports, "initOriginCheckMiddleware", {
226
+ enumerable: true,
227
+ get: function() {
228
+ return initOriginCheckMiddleware;
229
+ }
234
230
  });
235
- Object.defineProperty(exports, 'originCheck', {
236
- enumerable: true,
237
- get: function () {
238
- return originCheck;
239
- }
231
+ Object.defineProperty(exports, "originCheck", {
232
+ enumerable: true,
233
+ get: function() {
234
+ return originCheck;
235
+ }
236
+ });
237
+ Object.defineProperty(exports, "wildcardMatch", {
238
+ enumerable: true,
239
+ get: function() {
240
+ return wildcardMatch;
241
+ }
240
242
  });
241
- Object.defineProperty(exports, 'wildcardMatch', {
242
- enumerable: true,
243
- get: function () {
244
- return wildcardMatch;
245
- }
246
- });
@@ -1,9 +1,8 @@
1
- import { a as getTrustedOrigins, i as getProtocol, n as getHost, r as getOrigin } from "./url-BoUuoIwZ.mjs";
2
- import { r as createMiddleware } from "./middleware-CE6OhDkq.mjs";
1
+ import { a as getTrustedOrigins, i as getProtocol, n as getHost, r as getOrigin } from "./url-CJtdrrUu.mjs";
2
+ import { r as createMiddleware } from "./middleware-Cakg4e1D.mjs";
3
3
  import { logger } from "@faire-auth/core/env";
4
4
  import { False, isPromise } from "@faire-auth/core/static";
5
-
6
- //#region src/utils/wildcard.ts
5
+ // src/utils/wildcard.ts
7
6
  /**
8
7
  * Escapes a character if it has a special meaning in regular expressions
9
8
  * and returns the character as is if it doesn't
@@ -50,9 +49,11 @@ const transform = (pattern, separator = true) => {
50
49
  const nextSegment = segments[s + 1];
51
50
  let currentSeparator = "";
52
51
  if (segment == null && s > 0) continue;
53
- if (truthySeparator) if (s === segments.length - 1) currentSeparator = optionalSeparator;
54
- else if (nextSegment !== "**") currentSeparator = requiredSeparator;
55
- else currentSeparator = "";
52
+ if (truthySeparator) {
53
+ if (s === segments.length - 1) currentSeparator = optionalSeparator;
54
+ else if (nextSegment !== "**") currentSeparator = requiredSeparator;
55
+ else currentSeparator = "";
56
+ }
56
57
  if (truthySeparator && segment === "**") {
57
58
  if (currentSeparator) {
58
59
  result += s === 0 ? "" : currentSeparator;
@@ -115,9 +116,7 @@ function wildcardMatch(pattern, options) {
115
116
  fn.regexp = regexp;
116
117
  return fn;
117
118
  }
118
-
119
- //#endregion
120
- //#region src/api/middleware/origin-check.ts
119
+ // src/api/middleware/origin-check.ts
121
120
  const RELATIVE_PATH_RE = /^\/(?!\/|\\|%2f|%5c)[\w\-.\+/@]*(?:\?[\w\-.\+/=&%@]*)?$/;
122
121
  const matchesPattern = (url, pattern) => {
123
122
  if (url.startsWith("/")) return false;
@@ -128,15 +127,15 @@ const matchesPattern = (url, pattern) => {
128
127
  const protocol = getProtocol(url);
129
128
  return protocol === "http:" || protocol === "https:" || !protocol ? pattern === getOrigin(url) : url.startsWith(pattern);
130
129
  };
131
- const validateURL = (url, label, trustedOrigins, logger$1, ctx) => {
130
+ const validateURL = (url, label, trustedOrigins, logger, ctx) => {
132
131
  if (url == null) return null;
133
132
  let isTrustedOrigin = false;
134
133
  trustedOrigins.forEach((origin) => {
135
134
  if (isTrustedOrigin === false && (matchesPattern(url, origin) || url.startsWith("/") && label !== "origin" && RELATIVE_PATH_RE.test(url))) isTrustedOrigin = true;
136
135
  });
137
136
  if (!isTrustedOrigin) {
138
- logger$1.error(`Invalid ${label}: ${url}`);
139
- logger$1.info(`If it's a valid URL, please add ${url} to trustedOrigins in your auth config\n`, `Current list of trustedOrigins: ${[...trustedOrigins].join(", ")}`);
137
+ logger.error(`Invalid ${label}: ${url}`);
138
+ logger.info(`If it's a valid URL, please add ${url} to trustedOrigins in your auth config\n`, `Current list of trustedOrigins: ${[...trustedOrigins].join(", ")}`);
140
139
  return ctx.json({
141
140
  success: False,
142
141
  message: `Invalid ${label}`
@@ -223,6 +222,4 @@ const originCheck = (getValue) => {
223
222
  return await next();
224
223
  });
225
224
  };
226
-
227
- //#endregion
228
- export { originCheck as n, wildcardMatch as r, initOriginCheckMiddleware as t };
225
+ export { originCheck as n, wildcardMatch as r, initOriginCheckMiddleware as t };