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,367 @@
1
+ import { n as __export, r as __reExport } from "./chunk-Ceigfy4P.mjs";
2
+ import { n as crypto_exports } from "./crypto-CyQRFtkq.mjs";
3
+ import { t as safeJSONParse } from "./json-B1v2qRTQ.mjs";
4
+ import { env, isProduction } from "@faire-auth/core/env";
5
+ import { FaireAuthError } from "@faire-auth/core/error";
6
+ import { isPromise } from "@faire-auth/core/static";
7
+ import { createTime, getDate } from "@faire-auth/core/utils";
8
+ import { base64Url, binary, createHMAC } from "@faire-auth/core/datatypes";
9
+ import * as hc from "hono/cookie";
10
+ import { parse, parseSigned, serialize as serialize$1, serializeSigned } from "hono/utils/cookie";
11
+
12
+ //#region src/utils/cookies.ts
13
+ var cookies_exports = /* @__PURE__ */ __export({
14
+ checkAuthCookie: () => checkAuthCookie,
15
+ createCookieCapture: () => createCookieCapture,
16
+ createCookieCreator: () => createCookieCreator,
17
+ createCookieSetter: () => createCookieSetter,
18
+ deleteSessionCookie: () => deleteSessionCookie,
19
+ getCookieCache: () => getCookieCache,
20
+ getCookieKey: () => getCookieKey,
21
+ getCookies: () => getCookies,
22
+ getSessionCookie: () => getSessionCookie,
23
+ parse: () => parse,
24
+ parseCookies: () => parseCookies,
25
+ parseSetCookieHeader: () => parseSetCookieHeader,
26
+ parseSigned: () => parseSigned,
27
+ serialize: () => serialize$1,
28
+ serializeSigned: () => serializeSigned,
29
+ serializeSignedCookie: () => serializeSignedCookie,
30
+ setCookieCache: () => setCookieCache,
31
+ setSessionCookie: () => setSessionCookie
32
+ });
33
+ import * as import_hono_cookie from "hono/cookie";
34
+ __reExport(cookies_exports, import_hono_cookie);
35
+ const tryDecode = (str) => {
36
+ try {
37
+ return str.includes("%") ? decodeURIComponent(str) : str;
38
+ } catch {
39
+ return str;
40
+ }
41
+ };
42
+ const getCookieKey = (key, prefix) => {
43
+ let finalKey = key;
44
+ if (prefix) if (prefix === "secure") finalKey = `__Secure-${key}`;
45
+ else if (prefix === "host") finalKey = `__Host-${key}`;
46
+ else return;
47
+ return finalKey;
48
+ };
49
+ /**
50
+ * Parse an HTTP Cookie header string and returning an object of all cookie
51
+ * name-value pairs.
52
+ *
53
+ * Inspired by https://github.com/unjs/cookie-es/blob/main/src/cookie/parse.ts
54
+ *
55
+ * @param str the string representing a `Cookie` header value
56
+ */
57
+ const parseCookies = (str) => {
58
+ if (typeof str !== "string") throw new TypeError("argument str must be a string");
59
+ const cookies = /* @__PURE__ */ new Map();
60
+ let index = 0;
61
+ while (index < str.length) {
62
+ const eqIdx = str.indexOf("=", index);
63
+ if (eqIdx === -1) break;
64
+ let endIdx = str.indexOf(";", index);
65
+ if (endIdx === -1) endIdx = str.length;
66
+ else if (endIdx < eqIdx) {
67
+ index = str.lastIndexOf(";", eqIdx - 1) + 1;
68
+ continue;
69
+ }
70
+ const key = str.slice(index, eqIdx).trim();
71
+ if (!cookies.has(key)) {
72
+ let val = str.slice(eqIdx + 1, endIdx).trim();
73
+ if (val.codePointAt(0) === 34) val = val.slice(1, -1);
74
+ cookies.set(key, tryDecode(val));
75
+ }
76
+ index = endIdx + 1;
77
+ }
78
+ return cookies;
79
+ };
80
+ const _serialize = (key, value, opt = {}) => {
81
+ let cookie;
82
+ if (opt.prefix === "secure") cookie = `__Secure-${key}=${value}`;
83
+ else if (opt.prefix === "host") cookie = `__Host-${key}=${value}`;
84
+ else cookie = `${key}=${value}`;
85
+ if (key.startsWith("__Secure-") && !(opt.secure ?? false)) opt.secure = true;
86
+ if (key.startsWith("__Host-")) {
87
+ if (!(opt.secure ?? false)) opt.secure = true;
88
+ if (opt.path !== "/") opt.path = "/";
89
+ if (opt.domain != null) delete opt.domain;
90
+ }
91
+ if (opt != null && typeof opt.maxAge === "number" && opt.maxAge >= 0) {
92
+ if (opt.maxAge > 3456e4) throw new Error("Cookies Max-Age SHOULD NOT be greater than 400 days (34560000 seconds) in duration.");
93
+ cookie += `; Max-Age=${Math.floor(opt.maxAge)}`;
94
+ }
95
+ if (opt.domain != null && opt.prefix !== "host") cookie += `; Domain=${opt.domain}`;
96
+ if (opt.path != null) cookie += `; Path=${opt.path}`;
97
+ if (opt.expires) {
98
+ if (opt.expires.getTime() - Date.now() > 3456e7) throw new Error("Cookies Expires SHOULD NOT be greater than 400 days (34560000 seconds) in the future.");
99
+ cookie += `; Expires=${opt.expires.toUTCString()}`;
100
+ }
101
+ if (opt.httpOnly === true) cookie += "; HttpOnly";
102
+ if (opt.secure === true) cookie += "; Secure";
103
+ if (opt.sameSite) cookie += `; SameSite=${opt.sameSite.charAt(0).toUpperCase() + opt.sameSite.slice(1)}`;
104
+ if (opt.partitioned === true) {
105
+ if (!(opt.secure ?? false)) opt.secure = true;
106
+ cookie += "; Partitioned";
107
+ }
108
+ return cookie;
109
+ };
110
+ const serializeSignedCookie = async (key, value, secret, opt) => {
111
+ value = await (0, crypto_exports.signCookieValue)(value, secret);
112
+ return _serialize(key, value, opt);
113
+ };
114
+ const checkAuthCookie = async (request, auth) => {
115
+ const cookies = (request instanceof Headers ? request : request.headers).get("cookie");
116
+ if (cookies == null) return null;
117
+ const cookieName = (isPromise(auth.$context) ? await auth.$context : auth.$context).authCookies.sessionToken.name;
118
+ const sessionToken = parseCookies(cookies).get(cookieName);
119
+ if (sessionToken != null) return sessionToken;
120
+ return null;
121
+ };
122
+ /**
123
+ * Split attributes by semicolon, but respect that semicolons
124
+ * might appear in attribute values (though this is rare in practice)
125
+ */
126
+ const splitAttributes = (str) => {
127
+ const attributes = [];
128
+ let current = "";
129
+ let inQuotes = false;
130
+ for (let i = 0; i < str.length; i++) {
131
+ const char = str[i];
132
+ if (char === "\"" && (i === 0 || str[i - 1] !== "\\")) {
133
+ inQuotes = !inQuotes;
134
+ current += char;
135
+ } else if (char === ";" && !inQuotes) {
136
+ if (current.trim()) attributes.push(current.trim());
137
+ current = "";
138
+ } else current += char;
139
+ }
140
+ if (current.trim()) attributes.push(current.trim());
141
+ return attributes;
142
+ };
143
+ /**
144
+ * IMPORTANT - each Set-Cookie header should be a single cookie
145
+ */
146
+ const parseSetCookieHeader = (setCookie) => {
147
+ if (Array.isArray(setCookie)) return new Map(setCookie.flatMap((c) => [...parseSetCookieHeader(c)]));
148
+ const cookies = /* @__PURE__ */ new Map();
149
+ const nameValueMatch = setCookie.match(/^([^=]+)=([^;]*)/);
150
+ if (!nameValueMatch) return cookies;
151
+ const name = nameValueMatch[1]?.trim();
152
+ let value = nameValueMatch[2]?.trim() || "";
153
+ if (!name) return cookies;
154
+ if (value.startsWith("\"") && value.endsWith("\"") && value.length >= 2) {
155
+ value = value.slice(1, -1);
156
+ value = value.replace(/\\"/g, "\"");
157
+ }
158
+ const attrObj = { value };
159
+ const firstSemicolon = setCookie.indexOf(";", nameValueMatch[0].length);
160
+ if (firstSemicolon === -1) {
161
+ cookies.set(name, attrObj);
162
+ return cookies;
163
+ }
164
+ splitAttributes(setCookie.slice(firstSemicolon + 1)).forEach((attribute) => {
165
+ const eqIndex = attribute.indexOf("=");
166
+ const attrName = eqIndex === -1 ? attribute.trim() : attribute.slice(0, eqIndex).trim();
167
+ const attrValue = eqIndex === -1 ? "" : attribute.slice(eqIndex + 1).trim();
168
+ const normalizedAttrName = attrName.toLowerCase();
169
+ switch (normalizedAttrName) {
170
+ case "max-age": {
171
+ const maxAge = attrValue ? Number.parseInt(attrValue, 10) : void 0;
172
+ if (!Number.isNaN(maxAge) && maxAge != null) attrObj["max-age"] = maxAge;
173
+ break;
174
+ }
175
+ case "expires": {
176
+ const expires = attrValue ? new Date(attrValue) : void 0;
177
+ if (expires && !Number.isNaN(expires.getTime())) attrObj.expires = expires;
178
+ break;
179
+ }
180
+ case "domain":
181
+ if (attrValue) attrObj.domain = attrValue;
182
+ break;
183
+ case "path":
184
+ if (attrValue) attrObj.path = attrValue;
185
+ break;
186
+ case "secure":
187
+ attrObj.secure = true;
188
+ break;
189
+ case "httponly":
190
+ attrObj.httponly = true;
191
+ break;
192
+ case "samesite": {
193
+ const samesite = attrValue.toLowerCase();
194
+ if ([
195
+ "lax",
196
+ "none",
197
+ "strict"
198
+ ].includes(samesite)) attrObj.samesite = samesite;
199
+ break;
200
+ }
201
+ case "partitioned":
202
+ attrObj.partitioned = true;
203
+ break;
204
+ default:
205
+ if (normalizedAttrName) attrObj[normalizedAttrName] = attrValue || true;
206
+ break;
207
+ }
208
+ });
209
+ cookies.set(name, attrObj);
210
+ return cookies;
211
+ };
212
+ const createCookieCreator = (options) => {
213
+ const secureCookiePrefix = (options.advanced?.useSecureCookies !== void 0 ? options.advanced.useSecureCookies : options.baseURL !== void 0 ? options.baseURL.startsWith("https://") ? true : false : isProduction()) ? "__Secure-" : "";
214
+ const crossSubdomainEnabled = options.advanced?.crossSubDomainCookies?.enabled === true;
215
+ const domain = crossSubdomainEnabled ? options.advanced?.crossSubDomainCookies?.domain ?? (options.baseURL != null ? new URL(options.baseURL).hostname : void 0) : void 0;
216
+ if (crossSubdomainEnabled && domain == null) throw new FaireAuthError("baseURL is required when crossSubdomainCookies are enabled");
217
+ const createCookie = (cookieName, overrideAttributes = {}) => {
218
+ const prefix = options.advanced?.cookiePrefix ?? "faire-auth";
219
+ const name = options.advanced?.cookies?.[cookieName]?.name ?? `${prefix}.${cookieName}`;
220
+ const attributes = options.advanced?.cookies?.[cookieName]?.attributes;
221
+ return {
222
+ name: `${secureCookiePrefix}${name}`,
223
+ attributes: {
224
+ secure: !!secureCookiePrefix,
225
+ sameSite: "lax",
226
+ path: "/",
227
+ httpOnly: true,
228
+ ...crossSubdomainEnabled ? { domain } : {},
229
+ ...options.advanced?.defaultCookieAttributes,
230
+ ...overrideAttributes,
231
+ ...attributes
232
+ }
233
+ };
234
+ };
235
+ return createCookie;
236
+ };
237
+ const getCookies = (options) => {
238
+ const createCookie = createCookieCreator(options);
239
+ const sessionToken = createCookie("session_token", { maxAge: options.session?.expiresIn ?? createTime(7, "d").toSeconds() });
240
+ const sessionData = createCookie("session_data", { maxAge: options.session?.cookieCache?.maxAge ?? 300 });
241
+ const dontRememberToken = createCookie("dont_remember");
242
+ return {
243
+ sessionToken: {
244
+ name: sessionToken.name,
245
+ options: sessionToken.attributes
246
+ },
247
+ sessionData: {
248
+ name: sessionData.name,
249
+ options: sessionData.attributes
250
+ },
251
+ dontRememberToken: {
252
+ name: dontRememberToken.name,
253
+ options: dontRememberToken.attributes
254
+ }
255
+ };
256
+ };
257
+ const serializeCookies = (cookies) => Array.from(cookies, ([key, value]) => value ? `${key}=${value}` : "").filter(Boolean).join("; ");
258
+ const createCookieSetter = (headers) => (name, value) => {
259
+ const cookieMap = parseCookies(headers.get("cookie") ?? "");
260
+ cookieMap.set(name, value);
261
+ headers.set("cookie", serializeCookies(cookieMap));
262
+ };
263
+ const createCookieCapture = (headers) => (callback) => (context) => {
264
+ const setCookieHeader = context.response.headers.getSetCookie();
265
+ if (setCookieHeader.length === 0) return;
266
+ const cookieMap = new Map([...parseCookies(headers.get("cookie") ?? ""), ...Array.from(parseSetCookieHeader(setCookieHeader), ([key, value]) => [key, value.value])]);
267
+ headers.set("cookie", serializeCookies(cookieMap));
268
+ if (callback) callback(cookieMap);
269
+ };
270
+ const getCookieCache = async (request, config) => {
271
+ const cookies = (request instanceof Headers ? request : request.headers).get("cookie");
272
+ if (cookies == null) return null;
273
+ const { cookieName = "session_data", cookiePrefix = "faire-auth" } = config ?? {};
274
+ const name = config?.isSecure !== void 0 ? config.isSecure ? `__Secure-${cookiePrefix}.${cookieName}` : `${cookiePrefix}.${cookieName}` : isProduction() ? `__Secure-${cookiePrefix}.${cookieName}` : `${cookiePrefix}.${cookieName}`;
275
+ const sessionData = parseCookies(cookies).get(name);
276
+ if (sessionData != null) {
277
+ const sessionDataPayload = safeJSONParse(binary.decode(base64Url.decode(sessionData)));
278
+ if (!sessionDataPayload) return null;
279
+ const secret = config?.secret ?? env["FAIRE_AUTH_SECRET"];
280
+ if (secret == null) throw new FaireAuthError("getCookieCache requires a secret to be provided. Either pass it as an option or set the FAIRE_AUTH_SECRET environment variable");
281
+ if (!await createHMAC("SHA-256", "base64urlnopad").verify(secret, JSON.stringify({
282
+ ...sessionDataPayload.session,
283
+ expiresAt: sessionDataPayload.expiresAt
284
+ }), sessionDataPayload.signature)) return null;
285
+ return sessionDataPayload.session;
286
+ }
287
+ return null;
288
+ };
289
+ const setCookieCache = async (ctx, options, session, dontRememberMe = false) => {
290
+ const context = ctx.get("context");
291
+ if (options.session?.cookieCache?.enabled === true) {
292
+ const sessionData = {
293
+ session: Object.entries(session.session).reduce((acc, [key, value]) => {
294
+ const fieldConfig = options.session?.additionalFields?.[key];
295
+ if (!fieldConfig || fieldConfig.returned !== false) acc[key] = value;
296
+ return acc;
297
+ }, {}),
298
+ user: session.user
299
+ };
300
+ const cookieOptions = {
301
+ ...context.authCookies.sessionData.options,
302
+ ...dontRememberMe && { maxAge: context.authCookies.sessionData.options.maxAge }
303
+ };
304
+ const expiresAtDate = getDate(cookieOptions.maxAge || 60, "sec").getTime();
305
+ const data = base64Url.encode(JSON.stringify({
306
+ session: sessionData,
307
+ expiresAt: expiresAtDate,
308
+ signature: await createHMAC("SHA-256", "base64urlnopad").sign(context.secret, JSON.stringify({
309
+ ...sessionData,
310
+ expiresAt: expiresAtDate
311
+ }))
312
+ }), { padding: false });
313
+ if (data.length > 4093) throw new FaireAuthError("Session data is too large to store in the cookie. Please disable session cookie caching or reduce the size of the session data");
314
+ hc.setCookie(ctx, context.authCookies.sessionData.name, data, cookieOptions);
315
+ }
316
+ };
317
+ const getSessionCookie = (request, config) => {
318
+ if (config?.cookiePrefix != null) if (config.cookieName != null) config.cookiePrefix = `${config.cookiePrefix}-`;
319
+ else config.cookiePrefix = `${config.cookiePrefix}.`;
320
+ const cookies = ("headers" in request ? request.headers : request).get("cookie");
321
+ if (cookies == null) return null;
322
+ const { cookieName = "session_token", cookiePrefix = "faire-auth." } = config ?? {};
323
+ const name = `${cookiePrefix}${cookieName}`;
324
+ const secureCookieName = `__Secure-${name}`;
325
+ const parsedCookie = parseCookies(cookies);
326
+ const sessionToken = parsedCookie.get(name) ?? parsedCookie.get(secureCookieName);
327
+ if (sessionToken != null) return sessionToken;
328
+ return null;
329
+ };
330
+ const setSessionCookie = (ctx, authOptions, session, dontRememberMe, overrides) => {
331
+ const context = ctx.get("context");
332
+ return hc.getSignedCookie(ctx, context.secret, context.authCookies.dontRememberToken.name).then((dontRememberMeCookie) => {
333
+ dontRememberMe ??= !!dontRememberMeCookie;
334
+ const options = { ...context.authCookies.sessionToken.options };
335
+ if (dontRememberMe === true) delete options.maxAge;
336
+ else options.maxAge = context.sessionConfig.expiresIn;
337
+ return hc.setSignedCookie(ctx, context.authCookies.sessionToken.name, session.session.token, context.secret, {
338
+ ...options,
339
+ ...overrides
340
+ });
341
+ }).then(() => {
342
+ if (dontRememberMe === true) return hc.setSignedCookie(ctx, context.authCookies.dontRememberToken.name, "true", context.secret, context.authCookies.dontRememberToken.options);
343
+ return Promise.resolve();
344
+ }).then(() => {
345
+ if (authOptions.session?.cookieCache?.enabled === true) return setCookieCache(ctx, authOptions, session, dontRememberMe);
346
+ return Promise.resolve();
347
+ }).then(() => {
348
+ context.newSession = session;
349
+ if (authOptions.secondaryStorage) {
350
+ const maybePromise = context.secondaryStorage?.set(session.session.token, JSON.stringify({
351
+ user: session.user,
352
+ session: session.session
353
+ }), Math.floor((new Date(session.session.expiresAt).getTime() - Date.now()) / 1e3));
354
+ if (isPromise(maybePromise)) return maybePromise;
355
+ }
356
+ return Promise.resolve();
357
+ });
358
+ };
359
+ const deleteSessionCookie = (ctx, skipDontRememberMe) => {
360
+ const context = ctx.get("context");
361
+ hc.deleteCookie(ctx, context.authCookies.sessionToken.name, context.authCookies.sessionToken.options);
362
+ hc.deleteCookie(ctx, context.authCookies.sessionData.name, context.authCookies.sessionData.options);
363
+ if (!skipDontRememberMe) hc.deleteCookie(ctx, context.authCookies.dontRememberToken.name, context.authCookies.dontRememberToken.options);
364
+ };
365
+
366
+ //#endregion
367
+ export { serializeSignedCookie as _, createCookieSetter as a, getCookieKey as c, parse as d, parseCookies as f, serializeSigned as g, serialize$1 as h, createCookieCreator as i, getCookies as l, parseSigned as m, cookies_exports as n, deleteSessionCookie as o, parseSetCookieHeader as p, createCookieCapture as r, getCookieCache as s, checkAuthCookie as t, getSessionCookie as u, setCookieCache as v, setSessionCookie as y };
@@ -0,0 +1,11 @@
1
+ const require_crypto = require('../crypto-CcTxYH82.cjs');
2
+
3
+ exports.checkPassword = require_crypto.checkPassword;
4
+ exports.validatePassword = require_crypto.validatePassword;
5
+ var __faire_auth_core_crypto = require("@faire-auth/core/crypto");
6
+ Object.keys(__faire_auth_core_crypto).forEach(function (k) {
7
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
8
+ enumerable: true,
9
+ get: function () { return __faire_auth_core_crypto[k]; }
10
+ });
11
+ });
@@ -0,0 +1,22 @@
1
+ import { t as ContextVars } from "../hono-DOM31WQz.cjs";
2
+ import * as _faire_auth_core_types30 from "@faire-auth/core/types";
3
+ import { Context } from "hono";
4
+ export * from "@faire-auth/core/crypto";
5
+
6
+ //#region src/crypto/index.d.ts
7
+ declare const validatePassword: <T extends object>(ctx: Context<ContextVars<T>>, data: {
8
+ password: string;
9
+ userId: string;
10
+ }) => Promise<boolean>;
11
+ declare const checkPassword: <T extends object>(userId: string, ctx: Context<ContextVars<T>, any, {
12
+ out: {
13
+ json: {
14
+ password?: string;
15
+ };
16
+ };
17
+ }>) => Promise<true | _faire_auth_core_types30.JSONRespondReturn<{
18
+ success: false;
19
+ message: string;
20
+ }, 400>>;
21
+ //#endregion
22
+ export { checkPassword, validatePassword };
@@ -0,0 +1,22 @@
1
+ import { t as ContextVars } from "../hono-DuE14mmj.mjs";
2
+ import { Context } from "hono";
3
+ import * as _faire_auth_core_types32 from "@faire-auth/core/types";
4
+ export * from "@faire-auth/core/crypto";
5
+
6
+ //#region src/crypto/index.d.ts
7
+ declare const validatePassword: <T extends object>(ctx: Context<ContextVars<T>>, data: {
8
+ password: string;
9
+ userId: string;
10
+ }) => Promise<boolean>;
11
+ declare const checkPassword: <T extends object>(userId: string, ctx: Context<ContextVars<T>, any, {
12
+ out: {
13
+ json: {
14
+ password?: string;
15
+ };
16
+ };
17
+ }>) => Promise<true | _faire_auth_core_types32.JSONRespondReturn<{
18
+ success: false;
19
+ message: string;
20
+ }, 400>>;
21
+ //#endregion
22
+ export { checkPassword, validatePassword };
@@ -0,0 +1,5 @@
1
+ import { r as validatePassword, t as checkPassword } from "../crypto-CyQRFtkq.mjs";
2
+
3
+ export * from "@faire-auth/core/crypto"
4
+
5
+ export { checkPassword, validatePassword };
@@ -0,0 +1,57 @@
1
+ const require_chunk = require('./chunk-oakRccI5.cjs');
2
+ let __faire_auth_core_static = require("@faire-auth/core/static");
3
+
4
+ //#region src/crypto/index.ts
5
+ var crypto_exports = /* @__PURE__ */ require_chunk.__export({
6
+ checkPassword: () => checkPassword,
7
+ validatePassword: () => validatePassword
8
+ });
9
+ require_chunk.__reExport(crypto_exports, require("@faire-auth/core/crypto"));
10
+ const validatePassword = async (ctx, data) => {
11
+ const context = ctx.get("context");
12
+ const credentialAccount = (await context.internalAdapter.findAccounts(data.userId)).find((account) => account.providerId === "credential");
13
+ const currentPassword = credentialAccount?.password;
14
+ if (!credentialAccount || !currentPassword) return false;
15
+ return await context.password.verify({
16
+ hash: currentPassword,
17
+ password: data.password
18
+ });
19
+ };
20
+ const checkPassword = async (userId, ctx) => {
21
+ const context = ctx.get("context");
22
+ const { password } = ctx.req.valid("json");
23
+ const credentialAccount = (await context.internalAdapter.findAccounts(userId)).find((account) => account.providerId === "credential");
24
+ const currentPassword = credentialAccount?.password;
25
+ if (!credentialAccount || !currentPassword || !password) return ctx.render({
26
+ success: __faire_auth_core_static.False,
27
+ message: "No password credential found"
28
+ }, 400);
29
+ if (!await context.password.verify({
30
+ hash: currentPassword,
31
+ password
32
+ })) return ctx.render({
33
+ success: __faire_auth_core_static.False,
34
+ message: "Invalid password"
35
+ }, 400);
36
+ return true;
37
+ };
38
+
39
+ //#endregion
40
+ Object.defineProperty(exports, 'checkPassword', {
41
+ enumerable: true,
42
+ get: function () {
43
+ return checkPassword;
44
+ }
45
+ });
46
+ Object.defineProperty(exports, 'crypto_exports', {
47
+ enumerable: true,
48
+ get: function () {
49
+ return crypto_exports;
50
+ }
51
+ });
52
+ Object.defineProperty(exports, 'validatePassword', {
53
+ enumerable: true,
54
+ get: function () {
55
+ return validatePassword;
56
+ }
57
+ });
@@ -0,0 +1,41 @@
1
+ import { n as __export, r as __reExport } from "./chunk-Ceigfy4P.mjs";
2
+ import { False } from "@faire-auth/core/static";
3
+
4
+ //#region src/crypto/index.ts
5
+ var crypto_exports = /* @__PURE__ */ __export({
6
+ checkPassword: () => checkPassword,
7
+ validatePassword: () => validatePassword
8
+ });
9
+ import * as import___faire_auth_core_crypto from "@faire-auth/core/crypto";
10
+ __reExport(crypto_exports, import___faire_auth_core_crypto);
11
+ const validatePassword = async (ctx, data) => {
12
+ const context = ctx.get("context");
13
+ const credentialAccount = (await context.internalAdapter.findAccounts(data.userId)).find((account) => account.providerId === "credential");
14
+ const currentPassword = credentialAccount?.password;
15
+ if (!credentialAccount || !currentPassword) return false;
16
+ return await context.password.verify({
17
+ hash: currentPassword,
18
+ password: data.password
19
+ });
20
+ };
21
+ const checkPassword = async (userId, ctx) => {
22
+ const context = ctx.get("context");
23
+ const { password } = ctx.req.valid("json");
24
+ const credentialAccount = (await context.internalAdapter.findAccounts(userId)).find((account) => account.providerId === "credential");
25
+ const currentPassword = credentialAccount?.password;
26
+ if (!credentialAccount || !currentPassword || !password) return ctx.render({
27
+ success: False,
28
+ message: "No password credential found"
29
+ }, 400);
30
+ if (!await context.password.verify({
31
+ hash: currentPassword,
32
+ password
33
+ })) return ctx.render({
34
+ success: False,
35
+ message: "Invalid password"
36
+ }, 400);
37
+ return true;
38
+ };
39
+
40
+ //#endregion
41
+ export { crypto_exports as n, validatePassword as r, checkPassword as t };
@@ -0,0 +1,40 @@
1
+ require('../hono-Cdukwu5K.cjs');
2
+ require('../ip-B5SwXaMB.cjs');
3
+ require('../crypto-CcTxYH82.cjs');
4
+ require('../json-CcJ2HjGo.cjs');
5
+ require('../state--f7fwIGh.cjs');
6
+ require('../request-CPNlp-DK.cjs');
7
+ require('../utils-44aDDP8f.cjs');
8
+ const require_schema = require('../schema-D-qjygfE.cjs');
9
+ require('../kysely-adapter-Bxi7sPdG.cjs');
10
+ const require_adapter_factory = require('../adapter-factory-DT-_2aHJ.cjs');
11
+ const require_db = require('../db-BTKyYu-_.cjs');
12
+ require('../memory-adapter-BlnDIAAX.cjs');
13
+
14
+ exports.convertFromDB = require_db.convertFromDB;
15
+ exports.convertToDB = require_db.convertToDB;
16
+ exports.createFieldAttribute = require_db.createFieldAttribute;
17
+ exports.createInternalAdapter = require_db.createInternalAdapter;
18
+ exports.getAdapter = require_db.getAdapter;
19
+ exports.getAuthTables = require_adapter_factory.getAuthTables;
20
+ exports.getMigrations = require_db.getMigrations;
21
+ exports.getSchema = require_db.getSchema;
22
+ exports.getWithHooks = require_db.getWithHooks;
23
+ exports.matchType = require_db.matchType;
24
+ exports.mergeSchema = require_schema.mergeSchema;
25
+ exports.parseAccountInput = require_schema.parseAccountInput;
26
+ exports.parseAccountOutput = require_schema.parseAccountOutput;
27
+ exports.parseAdditionalUserInput = require_schema.parseAdditionalUserInput;
28
+ exports.parseInputData = require_schema.parseInputData;
29
+ exports.parseSessionInput = require_schema.parseSessionInput;
30
+ exports.parseSessionOutput = require_schema.parseSessionOutput;
31
+ exports.parseUserInput = require_schema.parseUserInput;
32
+ exports.parseUserOutput = require_schema.parseUserOutput;
33
+ exports.toZodSchema = require_db.toZodSchema;
34
+ var __faire_auth_core_db = require("@faire-auth/core/db");
35
+ Object.keys(__faire_auth_core_db).forEach(function (k) {
36
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
37
+ enumerable: true,
38
+ get: function () { return __faire_auth_core_db[k]; }
39
+ });
40
+ });
@@ -0,0 +1,4 @@
1
+ import { $t as PluginFieldAttribute, At as mergeSchema, Bt as getAuthTables, Dt as getAdapter, Et as convertToDB, Ft as parseSessionInput, Gt as FieldAttributeToObject, Ht as getMigrations, It as parseSessionOutput, Jt as InferFieldsFromPlugins, Kt as InferAdditionalFieldsFromPluginOptions, Lt as parseUserInput, Mt as parseAccountOutput, Nt as parseAdditionalUserInput, Ot as FieldAttributeToSchema, Pt as parseInputData, Qt as InferValueType, Rt as parseUserOutput, Tt as convertFromDB, Ut as matchType, Vt as getSchema, Xt as InferFieldsInputClient, Yt as InferFieldsInput, Zt as InferFieldsOutput, en as createFieldAttribute, jt as parseAccountInput, kt as toZodSchema, qt as InferFieldsFromOptions, wt as getWithHooks, zt as createInternalAdapter } from "../index-B-WeOMzg.cjs";
2
+ import "../hono-DOM31WQz.cjs";
3
+ export * from "@faire-auth/core/db";
4
+ export { FieldAttributeToObject, FieldAttributeToSchema, InferAdditionalFieldsFromPluginOptions, InferFieldsFromOptions, InferFieldsFromPlugins, InferFieldsInput, InferFieldsInputClient, InferFieldsOutput, InferValueType, PluginFieldAttribute, convertFromDB, convertToDB, createFieldAttribute, createInternalAdapter, getAdapter, getAuthTables, getMigrations, getSchema, getWithHooks, matchType, mergeSchema, parseAccountInput, parseAccountOutput, parseAdditionalUserInput, parseInputData, parseSessionInput, parseSessionOutput, parseUserInput, parseUserOutput, toZodSchema };
@@ -0,0 +1,4 @@
1
+ import { $t as PluginFieldAttribute, At as mergeSchema, Bt as getAuthTables, Dt as getAdapter, Et as convertToDB, Ft as parseSessionInput, Gt as FieldAttributeToObject, Ht as getMigrations, It as parseSessionOutput, Jt as InferFieldsFromPlugins, Kt as InferAdditionalFieldsFromPluginOptions, Lt as parseUserInput, Mt as parseAccountOutput, Nt as parseAdditionalUserInput, Ot as FieldAttributeToSchema, Pt as parseInputData, Qt as InferValueType, Rt as parseUserOutput, Tt as convertFromDB, Ut as matchType, Vt as getSchema, Xt as InferFieldsInputClient, Yt as InferFieldsInput, Zt as InferFieldsOutput, en as createFieldAttribute, jt as parseAccountInput, kt as toZodSchema, qt as InferFieldsFromOptions, wt as getWithHooks, zt as createInternalAdapter } from "../index-jlessPI0.mjs";
2
+ import "../hono-DuE14mmj.mjs";
3
+ export * from "@faire-auth/core/db";
4
+ export { FieldAttributeToObject, FieldAttributeToSchema, InferAdditionalFieldsFromPluginOptions, InferFieldsFromOptions, InferFieldsFromPlugins, InferFieldsInput, InferFieldsInputClient, InferFieldsOutput, InferValueType, PluginFieldAttribute, convertFromDB, convertToDB, createFieldAttribute, createInternalAdapter, getAdapter, getAuthTables, getMigrations, getSchema, getWithHooks, matchType, mergeSchema, parseAccountInput, parseAccountOutput, parseAdditionalUserInput, parseInputData, parseSessionInput, parseSessionOutput, parseUserInput, parseUserOutput, toZodSchema };
@@ -0,0 +1,16 @@
1
+ import "../hono-CoKYWnXA.mjs";
2
+ import "../ip-BjNYspCH.mjs";
3
+ import "../crypto-CyQRFtkq.mjs";
4
+ import "../json-B1v2qRTQ.mjs";
5
+ import "../state-CqJfCIl9.mjs";
6
+ import "../request-1NL_1lyJ.mjs";
7
+ import "../utils-D4vZd1-9.mjs";
8
+ import { a as parseInputData, c as parseUserInput, i as parseAdditionalUserInput, l as parseUserOutput, n as parseAccountInput, o as parseSessionInput, r as parseAccountOutput, s as parseSessionOutput, t as mergeSchema } from "../schema-DTIwLLmf.mjs";
9
+ import "../kysely-adapter-DRuoT_X8.mjs";
10
+ import { n as getAuthTables } from "../adapter-factory-BXei1QRX.mjs";
11
+ import { a as createInternalAdapter, c as matchType, i as toZodSchema, l as getSchema, n as convertToDB, o as getWithHooks, r as getAdapter, s as getMigrations, t as convertFromDB, u as createFieldAttribute } from "../db-xiJtoDgz.mjs";
12
+ import "../memory-adapter-Db3tsJTn.mjs";
13
+
14
+ export * from "@faire-auth/core/db"
15
+
16
+ export { convertFromDB, convertToDB, createFieldAttribute, createInternalAdapter, getAdapter, getAuthTables, getMigrations, getSchema, getWithHooks, matchType, mergeSchema, parseAccountInput, parseAccountOutput, parseAdditionalUserInput, parseInputData, parseSessionInput, parseSessionOutput, parseUserInput, parseUserOutput, toZodSchema };