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,456 @@
1
+ const require_chunk = require('./chunk-oakRccI5.cjs');
2
+ const require_crypto = require('./crypto-CcTxYH82.cjs');
3
+ const require_json = require('./json-CcJ2HjGo.cjs');
4
+ let __faire_auth_core_env = require("@faire-auth/core/env");
5
+ let __faire_auth_core_error = require("@faire-auth/core/error");
6
+ let __faire_auth_core_static = require("@faire-auth/core/static");
7
+ let __faire_auth_core_utils = require("@faire-auth/core/utils");
8
+ let __faire_auth_core_datatypes = require("@faire-auth/core/datatypes");
9
+ let hono_cookie = require("hono/cookie");
10
+ hono_cookie = require_chunk.__toESM(hono_cookie);
11
+ let hono_utils_cookie = require("hono/utils/cookie");
12
+
13
+ //#region src/utils/cookies.ts
14
+ var cookies_exports = /* @__PURE__ */ require_chunk.__export({
15
+ checkAuthCookie: () => checkAuthCookie,
16
+ createCookieCapture: () => createCookieCapture,
17
+ createCookieCreator: () => createCookieCreator,
18
+ createCookieSetter: () => createCookieSetter,
19
+ deleteSessionCookie: () => deleteSessionCookie,
20
+ getCookieCache: () => getCookieCache,
21
+ getCookieKey: () => getCookieKey,
22
+ getCookies: () => getCookies,
23
+ getSessionCookie: () => getSessionCookie,
24
+ parse: () => hono_utils_cookie.parse,
25
+ parseCookies: () => parseCookies,
26
+ parseSetCookieHeader: () => parseSetCookieHeader,
27
+ parseSigned: () => hono_utils_cookie.parseSigned,
28
+ serialize: () => hono_utils_cookie.serialize,
29
+ serializeSigned: () => hono_utils_cookie.serializeSigned,
30
+ serializeSignedCookie: () => serializeSignedCookie,
31
+ setCookieCache: () => setCookieCache,
32
+ setSessionCookie: () => setSessionCookie
33
+ });
34
+ require_chunk.__reExport(cookies_exports, require("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, require_crypto.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 = ((0, __faire_auth_core_static.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 : (0, __faire_auth_core_env.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 __faire_auth_core_error.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 ?? (0, __faire_auth_core_utils.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}` : (0, __faire_auth_core_env.isProduction)() ? `__Secure-${cookiePrefix}.${cookieName}` : `${cookiePrefix}.${cookieName}`;
275
+ const sessionData = parseCookies(cookies).get(name);
276
+ if (sessionData != null) {
277
+ const sessionDataPayload = require_json.safeJSONParse(__faire_auth_core_datatypes.binary.decode(__faire_auth_core_datatypes.base64Url.decode(sessionData)));
278
+ if (!sessionDataPayload) return null;
279
+ const secret = config?.secret ?? __faire_auth_core_env.env["FAIRE_AUTH_SECRET"];
280
+ if (secret == null) throw new __faire_auth_core_error.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 (0, __faire_auth_core_datatypes.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 = (0, __faire_auth_core_utils.getDate)(cookieOptions.maxAge || 60, "sec").getTime();
305
+ const data = __faire_auth_core_datatypes.base64Url.encode(JSON.stringify({
306
+ session: sessionData,
307
+ expiresAt: expiresAtDate,
308
+ signature: await (0, __faire_auth_core_datatypes.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 __faire_auth_core_error.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
+ hono_cookie.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 hono_cookie.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 hono_cookie.setSignedCookie(ctx, context.authCookies.sessionToken.name, session.session.token, context.secret, {
338
+ ...options,
339
+ ...overrides
340
+ });
341
+ }).then(() => {
342
+ if (dontRememberMe === true) return hono_cookie.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 ((0, __faire_auth_core_static.isPromise)(maybePromise)) return maybePromise;
355
+ }
356
+ return Promise.resolve();
357
+ });
358
+ };
359
+ const deleteSessionCookie = (ctx, skipDontRememberMe) => {
360
+ const context = ctx.get("context");
361
+ hono_cookie.deleteCookie(ctx, context.authCookies.sessionToken.name, context.authCookies.sessionToken.options);
362
+ hono_cookie.deleteCookie(ctx, context.authCookies.sessionData.name, context.authCookies.sessionData.options);
363
+ if (!skipDontRememberMe) hono_cookie.deleteCookie(ctx, context.authCookies.dontRememberToken.name, context.authCookies.dontRememberToken.options);
364
+ };
365
+
366
+ //#endregion
367
+ Object.defineProperty(exports, 'checkAuthCookie', {
368
+ enumerable: true,
369
+ get: function () {
370
+ return checkAuthCookie;
371
+ }
372
+ });
373
+ Object.defineProperty(exports, 'cookies_exports', {
374
+ enumerable: true,
375
+ get: function () {
376
+ return cookies_exports;
377
+ }
378
+ });
379
+ Object.defineProperty(exports, 'createCookieCapture', {
380
+ enumerable: true,
381
+ get: function () {
382
+ return createCookieCapture;
383
+ }
384
+ });
385
+ Object.defineProperty(exports, 'createCookieCreator', {
386
+ enumerable: true,
387
+ get: function () {
388
+ return createCookieCreator;
389
+ }
390
+ });
391
+ Object.defineProperty(exports, 'createCookieSetter', {
392
+ enumerable: true,
393
+ get: function () {
394
+ return createCookieSetter;
395
+ }
396
+ });
397
+ Object.defineProperty(exports, 'deleteSessionCookie', {
398
+ enumerable: true,
399
+ get: function () {
400
+ return deleteSessionCookie;
401
+ }
402
+ });
403
+ Object.defineProperty(exports, 'getCookieCache', {
404
+ enumerable: true,
405
+ get: function () {
406
+ return getCookieCache;
407
+ }
408
+ });
409
+ Object.defineProperty(exports, 'getCookieKey', {
410
+ enumerable: true,
411
+ get: function () {
412
+ return getCookieKey;
413
+ }
414
+ });
415
+ Object.defineProperty(exports, 'getCookies', {
416
+ enumerable: true,
417
+ get: function () {
418
+ return getCookies;
419
+ }
420
+ });
421
+ Object.defineProperty(exports, 'getSessionCookie', {
422
+ enumerable: true,
423
+ get: function () {
424
+ return getSessionCookie;
425
+ }
426
+ });
427
+ Object.defineProperty(exports, 'parseCookies', {
428
+ enumerable: true,
429
+ get: function () {
430
+ return parseCookies;
431
+ }
432
+ });
433
+ Object.defineProperty(exports, 'parseSetCookieHeader', {
434
+ enumerable: true,
435
+ get: function () {
436
+ return parseSetCookieHeader;
437
+ }
438
+ });
439
+ Object.defineProperty(exports, 'serializeSignedCookie', {
440
+ enumerable: true,
441
+ get: function () {
442
+ return serializeSignedCookie;
443
+ }
444
+ });
445
+ Object.defineProperty(exports, 'setCookieCache', {
446
+ enumerable: true,
447
+ get: function () {
448
+ return setCookieCache;
449
+ }
450
+ });
451
+ Object.defineProperty(exports, 'setSessionCookie', {
452
+ enumerable: true,
453
+ get: function () {
454
+ return setSessionCookie;
455
+ }
456
+ });