better-auth 1.2.6-beta.5 → 1.2.6-beta.7

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 (219) hide show
  1. package/dist/adapters/drizzle-adapter/index.d.cts +2 -2
  2. package/dist/adapters/drizzle-adapter/index.d.mts +2 -2
  3. package/dist/adapters/drizzle-adapter/index.d.ts +2 -2
  4. package/dist/adapters/kysely-adapter/index.d.cts +2 -2
  5. package/dist/adapters/kysely-adapter/index.d.mts +2 -2
  6. package/dist/adapters/kysely-adapter/index.d.ts +2 -2
  7. package/dist/adapters/memory-adapter/index.d.cts +2 -2
  8. package/dist/adapters/memory-adapter/index.d.mts +2 -2
  9. package/dist/adapters/memory-adapter/index.d.ts +2 -2
  10. package/dist/adapters/mongodb-adapter/index.d.cts +2 -2
  11. package/dist/adapters/mongodb-adapter/index.d.mts +2 -2
  12. package/dist/adapters/mongodb-adapter/index.d.ts +2 -2
  13. package/dist/adapters/prisma-adapter/index.d.cts +2 -2
  14. package/dist/adapters/prisma-adapter/index.d.mts +2 -2
  15. package/dist/adapters/prisma-adapter/index.d.ts +2 -2
  16. package/dist/adapters/test.d.cts +2 -2
  17. package/dist/adapters/test.d.mts +2 -2
  18. package/dist/adapters/test.d.ts +2 -2
  19. package/dist/api/index.cjs +3 -3
  20. package/dist/api/index.d.cts +2 -2
  21. package/dist/api/index.d.mts +2 -2
  22. package/dist/api/index.d.ts +2 -2
  23. package/dist/api/index.mjs +4 -4
  24. package/dist/chunks/server.cjs +905 -0
  25. package/dist/chunks/server.mjs +895 -0
  26. package/dist/client/index.d.cts +2 -2
  27. package/dist/client/index.d.mts +2 -2
  28. package/dist/client/index.d.ts +2 -2
  29. package/dist/client/plugins/index.cjs +20 -12
  30. package/dist/client/plugins/index.d.cts +3 -3
  31. package/dist/client/plugins/index.d.mts +3 -3
  32. package/dist/client/plugins/index.d.ts +3 -3
  33. package/dist/client/plugins/index.mjs +20 -12
  34. package/dist/client/react/index.cjs +4 -4
  35. package/dist/client/react/index.d.cts +2 -2
  36. package/dist/client/react/index.d.mts +2 -2
  37. package/dist/client/react/index.d.ts +2 -2
  38. package/dist/client/solid/index.d.cts +2 -2
  39. package/dist/client/solid/index.d.mts +2 -2
  40. package/dist/client/solid/index.d.ts +2 -2
  41. package/dist/client/svelte/index.d.cts +2 -2
  42. package/dist/client/svelte/index.d.mts +2 -2
  43. package/dist/client/svelte/index.d.ts +2 -2
  44. package/dist/client/vue/index.d.cts +2 -2
  45. package/dist/client/vue/index.d.mts +2 -2
  46. package/dist/client/vue/index.d.ts +2 -2
  47. package/dist/cookies/index.d.cts +2 -2
  48. package/dist/cookies/index.d.mts +2 -2
  49. package/dist/cookies/index.d.ts +2 -2
  50. package/dist/db/index.cjs +2 -2
  51. package/dist/db/index.d.cts +3 -3
  52. package/dist/db/index.d.mts +3 -3
  53. package/dist/db/index.d.ts +3 -3
  54. package/dist/db/index.mjs +2 -2
  55. package/dist/index.cjs +4 -4
  56. package/dist/index.d.cts +3 -3
  57. package/dist/index.d.mts +3 -3
  58. package/dist/index.d.ts +3 -3
  59. package/dist/index.mjs +5 -5
  60. package/dist/integrations/next-js.cjs +5 -4
  61. package/dist/integrations/next-js.d.cts +2 -2
  62. package/dist/integrations/next-js.d.mts +2 -2
  63. package/dist/integrations/next-js.d.ts +2 -2
  64. package/dist/integrations/next-js.mjs +5 -4
  65. package/dist/integrations/node.d.cts +2 -2
  66. package/dist/integrations/node.d.mts +2 -2
  67. package/dist/integrations/node.d.ts +2 -2
  68. package/dist/integrations/react-start.cjs +90 -0
  69. package/dist/integrations/react-start.d.cts +20 -0
  70. package/dist/integrations/react-start.d.mts +20 -0
  71. package/dist/integrations/react-start.d.ts +20 -0
  72. package/dist/integrations/react-start.mjs +88 -0
  73. package/dist/integrations/svelte-kit.d.cts +2 -2
  74. package/dist/integrations/svelte-kit.d.mts +2 -2
  75. package/dist/integrations/svelte-kit.d.ts +2 -2
  76. package/dist/oauth2/index.cjs +2 -2
  77. package/dist/oauth2/index.d.cts +4 -4
  78. package/dist/oauth2/index.d.mts +4 -4
  79. package/dist/oauth2/index.d.ts +4 -4
  80. package/dist/oauth2/index.mjs +2 -2
  81. package/dist/plugins/admin/index.cjs +4 -3
  82. package/dist/plugins/admin/index.d.cts +285 -643
  83. package/dist/plugins/admin/index.d.mts +285 -643
  84. package/dist/plugins/admin/index.d.ts +285 -643
  85. package/dist/plugins/admin/index.mjs +4 -3
  86. package/dist/plugins/anonymous/index.cjs +2 -2
  87. package/dist/plugins/anonymous/index.d.cts +22 -35
  88. package/dist/plugins/anonymous/index.d.mts +22 -35
  89. package/dist/plugins/anonymous/index.d.ts +22 -35
  90. package/dist/plugins/anonymous/index.mjs +2 -2
  91. package/dist/plugins/bearer/index.cjs +2 -2
  92. package/dist/plugins/bearer/index.d.cts +2 -2
  93. package/dist/plugins/bearer/index.d.mts +2 -2
  94. package/dist/plugins/bearer/index.d.ts +2 -2
  95. package/dist/plugins/bearer/index.mjs +2 -2
  96. package/dist/plugins/custom-session/index.cjs +3 -3
  97. package/dist/plugins/custom-session/index.d.cts +23 -26
  98. package/dist/plugins/custom-session/index.d.mts +23 -26
  99. package/dist/plugins/custom-session/index.d.ts +23 -26
  100. package/dist/plugins/custom-session/index.mjs +3 -3
  101. package/dist/plugins/email-otp/index.cjs +2 -2
  102. package/dist/plugins/email-otp/index.d.cts +142 -261
  103. package/dist/plugins/email-otp/index.d.mts +142 -261
  104. package/dist/plugins/email-otp/index.d.ts +142 -261
  105. package/dist/plugins/email-otp/index.mjs +2 -2
  106. package/dist/plugins/generic-oauth/index.cjs +11 -9
  107. package/dist/plugins/generic-oauth/index.d.cts +65 -132
  108. package/dist/plugins/generic-oauth/index.d.mts +65 -132
  109. package/dist/plugins/generic-oauth/index.d.ts +65 -132
  110. package/dist/plugins/generic-oauth/index.mjs +11 -9
  111. package/dist/plugins/index.cjs +46 -13
  112. package/dist/plugins/index.d.cts +3 -3
  113. package/dist/plugins/index.d.mts +3 -3
  114. package/dist/plugins/index.d.ts +3 -3
  115. package/dist/plugins/index.mjs +47 -14
  116. package/dist/plugins/jwt/index.cjs +2 -2
  117. package/dist/plugins/jwt/index.d.cts +42 -109
  118. package/dist/plugins/jwt/index.d.mts +42 -109
  119. package/dist/plugins/jwt/index.d.ts +42 -109
  120. package/dist/plugins/jwt/index.mjs +2 -2
  121. package/dist/plugins/magic-link/index.cjs +2 -2
  122. package/dist/plugins/magic-link/index.d.cts +40 -82
  123. package/dist/plugins/magic-link/index.d.mts +40 -82
  124. package/dist/plugins/magic-link/index.d.ts +40 -82
  125. package/dist/plugins/magic-link/index.mjs +2 -2
  126. package/dist/plugins/multi-session/index.cjs +2 -2
  127. package/dist/plugins/multi-session/index.d.cts +62 -129
  128. package/dist/plugins/multi-session/index.d.mts +62 -129
  129. package/dist/plugins/multi-session/index.d.ts +62 -129
  130. package/dist/plugins/multi-session/index.mjs +2 -2
  131. package/dist/plugins/oauth-proxy/index.cjs +2 -2
  132. package/dist/plugins/oauth-proxy/index.d.cts +22 -42
  133. package/dist/plugins/oauth-proxy/index.d.mts +22 -42
  134. package/dist/plugins/oauth-proxy/index.d.ts +22 -42
  135. package/dist/plugins/oauth-proxy/index.mjs +2 -2
  136. package/dist/plugins/oidc-provider/index.cjs +2 -2
  137. package/dist/plugins/oidc-provider/index.d.cts +146 -159
  138. package/dist/plugins/oidc-provider/index.d.mts +146 -159
  139. package/dist/plugins/oidc-provider/index.d.ts +146 -159
  140. package/dist/plugins/oidc-provider/index.mjs +2 -2
  141. package/dist/plugins/one-tap/index.cjs +2 -2
  142. package/dist/plugins/one-tap/index.d.cts +20 -42
  143. package/dist/plugins/one-tap/index.d.mts +20 -42
  144. package/dist/plugins/one-tap/index.d.ts +20 -42
  145. package/dist/plugins/one-tap/index.mjs +2 -2
  146. package/dist/plugins/open-api/index.cjs +5 -3
  147. package/dist/plugins/open-api/index.d.cts +42 -21
  148. package/dist/plugins/open-api/index.d.mts +42 -21
  149. package/dist/plugins/open-api/index.d.ts +42 -21
  150. package/dist/plugins/open-api/index.mjs +5 -3
  151. package/dist/plugins/organization/index.cjs +4 -3
  152. package/dist/plugins/organization/index.d.cts +1375 -2917
  153. package/dist/plugins/organization/index.d.mts +1375 -2917
  154. package/dist/plugins/organization/index.d.ts +1375 -2917
  155. package/dist/plugins/organization/index.mjs +4 -3
  156. package/dist/plugins/passkey/index.cjs +2 -2
  157. package/dist/plugins/passkey/index.d.cts +147 -465
  158. package/dist/plugins/passkey/index.d.mts +147 -465
  159. package/dist/plugins/passkey/index.d.ts +147 -465
  160. package/dist/plugins/passkey/index.mjs +2 -2
  161. package/dist/plugins/phone-number/index.cjs +2 -2
  162. package/dist/plugins/phone-number/index.d.cts +104 -179
  163. package/dist/plugins/phone-number/index.d.mts +104 -179
  164. package/dist/plugins/phone-number/index.d.ts +104 -179
  165. package/dist/plugins/phone-number/index.mjs +2 -2
  166. package/dist/plugins/sso/index.cjs +3 -3
  167. package/dist/plugins/sso/index.d.cts +64 -207
  168. package/dist/plugins/sso/index.d.mts +64 -207
  169. package/dist/plugins/sso/index.d.ts +64 -207
  170. package/dist/plugins/sso/index.mjs +3 -3
  171. package/dist/plugins/two-factor/index.cjs +4 -4
  172. package/dist/plugins/two-factor/index.d.cts +222 -726
  173. package/dist/plugins/two-factor/index.d.mts +222 -726
  174. package/dist/plugins/two-factor/index.d.ts +222 -726
  175. package/dist/plugins/two-factor/index.mjs +4 -4
  176. package/dist/plugins/username/index.cjs +4 -4
  177. package/dist/plugins/username/index.d.cts +22 -45
  178. package/dist/plugins/username/index.d.mts +22 -45
  179. package/dist/plugins/username/index.d.ts +22 -45
  180. package/dist/plugins/username/index.mjs +4 -4
  181. package/dist/shared/{better-auth.Dmtp4RCi.mjs → better-auth.A3TjrU8G.mjs} +1 -1
  182. package/dist/shared/{better-auth.DpnaS1Ry.d.cts → better-auth.B2Fw1vhH.d.cts} +2 -4
  183. package/dist/shared/{better-auth.Cr5ixZZK.d.ts → better-auth.BANAxdkL.d.ts} +2 -4
  184. package/dist/shared/{better-auth.Dy3T8VFf.cjs → better-auth.BDYXUcLv.cjs} +1 -1
  185. package/dist/shared/{better-auth.BGUZBbM4.cjs → better-auth.BIjcZ_vt.cjs} +1 -1
  186. package/dist/shared/{better-auth.-X_5SIE9.d.ts → better-auth.BRf6Iynu.d.ts} +3 -3
  187. package/dist/shared/{better-auth.i9-25Ul9.cjs → better-auth.BSsp73pg.cjs} +1 -1
  188. package/dist/shared/{better-auth.ulRwlmfz.d.ts → better-auth.BWp5dztg.d.ts} +146 -205
  189. package/dist/shared/{better-auth.BsbUy_em.d.cts → better-auth.BiQsvaIP.d.cts} +5356 -7956
  190. package/dist/shared/{better-auth.DZGc_87_.mjs → better-auth.BrOpzmqo.mjs} +1 -1
  191. package/dist/shared/better-auth.CApEjVDP.cjs +21 -0
  192. package/dist/shared/{better-auth.D5DEHFvt.cjs → better-auth.CV1L7TPV.cjs} +26 -44
  193. package/dist/shared/{better-auth.Bu8n0vlp.mjs → better-auth.ClTSOgiD.mjs} +1 -1
  194. package/dist/shared/{better-auth.BzKq70UC.cjs → better-auth.Cm29ZKNJ.cjs} +5 -9
  195. package/dist/shared/{better-auth.CXagCPAv.cjs → better-auth.CsSpq0zL.cjs} +17 -33
  196. package/dist/shared/{better-auth.B5Z63CQV.d.mts → better-auth.D-oLmHIj.d.mts} +5356 -7956
  197. package/dist/shared/{better-auth.CX0ifPU-.mjs → better-auth.D4jH-sJA.mjs} +1 -1
  198. package/dist/shared/{better-auth.BSbTjuSH.mjs → better-auth.D9VnBkRI.mjs} +5 -21
  199. package/dist/shared/{better-auth.DjMtlb7e.mjs → better-auth.DCVeP5-W.mjs} +5 -9
  200. package/dist/shared/better-auth.DLTzKoOS.cjs +18 -0
  201. package/dist/shared/{better-auth.CY_Hrfhe.mjs → better-auth.DPBQN9Fs.mjs} +17 -35
  202. package/dist/shared/{better-auth.i71gRg2g.d.ts → better-auth.DU2QNVc_.d.ts} +5356 -7956
  203. package/dist/shared/{better-auth.BLFZHn6S.d.cts → better-auth.DWRligF8.d.cts} +146 -205
  204. package/dist/shared/better-auth.DiG4KL2x.mjs +16 -0
  205. package/dist/shared/{better-auth.DkJ_Tcxu.d.cts → better-auth.Dmhe30iW.d.mts} +3 -3
  206. package/dist/shared/{better-auth.BGAbPcLi.d.mts → better-auth.DtC8i3pf.d.cts} +3 -3
  207. package/dist/shared/{better-auth.-kZ-JqcP.d.mts → better-auth.bKwabe3I.d.mts} +2 -4
  208. package/dist/shared/better-auth.cOCrlspr.mjs +19 -0
  209. package/dist/shared/{better-auth.USxghgYQ.cjs → better-auth.m575EIBC.cjs} +1 -1
  210. package/dist/shared/{better-auth.CjhKonVM.d.mts → better-auth.wcdMj2cT.d.mts} +146 -205
  211. package/dist/social-providers/index.cjs +14 -5
  212. package/dist/social-providers/index.d.cts +1 -1
  213. package/dist/social-providers/index.d.mts +1 -1
  214. package/dist/social-providers/index.d.ts +1 -1
  215. package/dist/social-providers/index.mjs +14 -5
  216. package/dist/types/index.d.cts +3 -4
  217. package/dist/types/index.d.mts +3 -4
  218. package/dist/types/index.d.ts +3 -4
  219. package/package.json +16 -2
@@ -0,0 +1,905 @@
1
+ 'use strict';
2
+
3
+ require('defu');
4
+ const node_async_hooks = require('node:async_hooks');
5
+
6
+ function parse(str, options) {
7
+ if (typeof str !== "string") {
8
+ throw new TypeError("argument str must be a string");
9
+ }
10
+ const obj = {};
11
+ const opt = {};
12
+ const dec = opt.decode || decode;
13
+ let index = 0;
14
+ while (index < str.length) {
15
+ const eqIdx = str.indexOf("=", index);
16
+ if (eqIdx === -1) {
17
+ break;
18
+ }
19
+ let endIdx = str.indexOf(";", index);
20
+ if (endIdx === -1) {
21
+ endIdx = str.length;
22
+ } else if (endIdx < eqIdx) {
23
+ index = str.lastIndexOf(";", eqIdx - 1) + 1;
24
+ continue;
25
+ }
26
+ const key = str.slice(index, eqIdx).trim();
27
+ if (opt?.filter && !opt?.filter(key)) {
28
+ index = endIdx + 1;
29
+ continue;
30
+ }
31
+ if (void 0 === obj[key]) {
32
+ let val = str.slice(eqIdx + 1, endIdx).trim();
33
+ if (val.codePointAt(0) === 34) {
34
+ val = val.slice(1, -1);
35
+ }
36
+ obj[key] = tryDecode(val, dec);
37
+ }
38
+ index = endIdx + 1;
39
+ }
40
+ return obj;
41
+ }
42
+ function decode(str) {
43
+ return str.includes("%") ? decodeURIComponent(str) : str;
44
+ }
45
+ function tryDecode(str, decode2) {
46
+ try {
47
+ return decode2(str);
48
+ } catch {
49
+ return str;
50
+ }
51
+ }
52
+
53
+ const fieldContentRegExp = /^[\u0009\u0020-\u007E\u0080-\u00FF]+$/;
54
+ function serialize(name, value, options) {
55
+ const opt = options || {};
56
+ const enc = opt.encode || encodeURIComponent;
57
+ if (typeof enc !== "function") {
58
+ throw new TypeError("option encode is invalid");
59
+ }
60
+ if (!fieldContentRegExp.test(name)) {
61
+ throw new TypeError("argument name is invalid");
62
+ }
63
+ const encodedValue = enc(value);
64
+ if (encodedValue && !fieldContentRegExp.test(encodedValue)) {
65
+ throw new TypeError("argument val is invalid");
66
+ }
67
+ let str = name + "=" + encodedValue;
68
+ if (void 0 !== opt.maxAge && opt.maxAge !== null) {
69
+ const maxAge = opt.maxAge - 0;
70
+ if (Number.isNaN(maxAge) || !Number.isFinite(maxAge)) {
71
+ throw new TypeError("option maxAge is invalid");
72
+ }
73
+ str += "; Max-Age=" + Math.floor(maxAge);
74
+ }
75
+ if (opt.domain) {
76
+ if (!fieldContentRegExp.test(opt.domain)) {
77
+ throw new TypeError("option domain is invalid");
78
+ }
79
+ str += "; Domain=" + opt.domain;
80
+ }
81
+ if (opt.path) {
82
+ if (!fieldContentRegExp.test(opt.path)) {
83
+ throw new TypeError("option path is invalid");
84
+ }
85
+ str += "; Path=" + opt.path;
86
+ }
87
+ if (opt.expires) {
88
+ if (!isDate(opt.expires) || Number.isNaN(opt.expires.valueOf())) {
89
+ throw new TypeError("option expires is invalid");
90
+ }
91
+ str += "; Expires=" + opt.expires.toUTCString();
92
+ }
93
+ if (opt.httpOnly) {
94
+ str += "; HttpOnly";
95
+ }
96
+ if (opt.secure) {
97
+ str += "; Secure";
98
+ }
99
+ if (opt.priority) {
100
+ const priority = typeof opt.priority === "string" ? opt.priority.toLowerCase() : opt.priority;
101
+ switch (priority) {
102
+ case "low": {
103
+ str += "; Priority=Low";
104
+ break;
105
+ }
106
+ case "medium": {
107
+ str += "; Priority=Medium";
108
+ break;
109
+ }
110
+ case "high": {
111
+ str += "; Priority=High";
112
+ break;
113
+ }
114
+ default: {
115
+ throw new TypeError("option priority is invalid");
116
+ }
117
+ }
118
+ }
119
+ if (opt.sameSite) {
120
+ const sameSite = typeof opt.sameSite === "string" ? opt.sameSite.toLowerCase() : opt.sameSite;
121
+ switch (sameSite) {
122
+ case true: {
123
+ str += "; SameSite=Strict";
124
+ break;
125
+ }
126
+ case "lax": {
127
+ str += "; SameSite=Lax";
128
+ break;
129
+ }
130
+ case "strict": {
131
+ str += "; SameSite=Strict";
132
+ break;
133
+ }
134
+ case "none": {
135
+ str += "; SameSite=None";
136
+ break;
137
+ }
138
+ default: {
139
+ throw new TypeError("option sameSite is invalid");
140
+ }
141
+ }
142
+ }
143
+ if (opt.partitioned) {
144
+ str += "; Partitioned";
145
+ }
146
+ return str;
147
+ }
148
+ function isDate(val) {
149
+ return Object.prototype.toString.call(val) === "[object Date]" || val instanceof Date;
150
+ }
151
+
152
+ const defaults = Object.freeze({
153
+ ignoreUnknown: false,
154
+ respectType: false,
155
+ respectFunctionNames: false,
156
+ respectFunctionProperties: false,
157
+ unorderedObjects: true,
158
+ unorderedArrays: false,
159
+ unorderedSets: false,
160
+ excludeKeys: void 0,
161
+ excludeValues: void 0,
162
+ replacer: void 0
163
+ });
164
+ function objectHash(object, options) {
165
+ if (options) {
166
+ options = { ...defaults, ...options };
167
+ } else {
168
+ options = defaults;
169
+ }
170
+ const hasher = createHasher(options);
171
+ hasher.dispatch(object);
172
+ return hasher.toString();
173
+ }
174
+ const defaultPrototypesKeys = Object.freeze([
175
+ "prototype",
176
+ "__proto__",
177
+ "constructor"
178
+ ]);
179
+ function createHasher(options) {
180
+ let buff = "";
181
+ let context = /* @__PURE__ */ new Map();
182
+ const write = (str) => {
183
+ buff += str;
184
+ };
185
+ return {
186
+ toString() {
187
+ return buff;
188
+ },
189
+ getContext() {
190
+ return context;
191
+ },
192
+ dispatch(value) {
193
+ if (options.replacer) {
194
+ value = options.replacer(value);
195
+ }
196
+ const type = value === null ? "null" : typeof value;
197
+ return this[type](value);
198
+ },
199
+ object(object) {
200
+ if (object && typeof object.toJSON === "function") {
201
+ return this.object(object.toJSON());
202
+ }
203
+ const objString = Object.prototype.toString.call(object);
204
+ let objType = "";
205
+ const objectLength = objString.length;
206
+ if (objectLength < 10) {
207
+ objType = "unknown:[" + objString + "]";
208
+ } else {
209
+ objType = objString.slice(8, objectLength - 1);
210
+ }
211
+ objType = objType.toLowerCase();
212
+ let objectNumber = null;
213
+ if ((objectNumber = context.get(object)) === void 0) {
214
+ context.set(object, context.size);
215
+ } else {
216
+ return this.dispatch("[CIRCULAR:" + objectNumber + "]");
217
+ }
218
+ if (typeof Buffer !== "undefined" && Buffer.isBuffer && Buffer.isBuffer(object)) {
219
+ write("buffer:");
220
+ return write(object.toString("utf8"));
221
+ }
222
+ if (objType !== "object" && objType !== "function" && objType !== "asyncfunction") {
223
+ if (this[objType]) {
224
+ this[objType](object);
225
+ } else if (!options.ignoreUnknown) {
226
+ this.unkown(object, objType);
227
+ }
228
+ } else {
229
+ let keys = Object.keys(object);
230
+ if (options.unorderedObjects) {
231
+ keys = keys.sort();
232
+ }
233
+ let extraKeys = [];
234
+ if (options.respectType !== false && !isNativeFunction(object)) {
235
+ extraKeys = defaultPrototypesKeys;
236
+ }
237
+ if (options.excludeKeys) {
238
+ keys = keys.filter((key) => {
239
+ return !options.excludeKeys(key);
240
+ });
241
+ extraKeys = extraKeys.filter((key) => {
242
+ return !options.excludeKeys(key);
243
+ });
244
+ }
245
+ write("object:" + (keys.length + extraKeys.length) + ":");
246
+ const dispatchForKey = (key) => {
247
+ this.dispatch(key);
248
+ write(":");
249
+ if (!options.excludeValues) {
250
+ this.dispatch(object[key]);
251
+ }
252
+ write(",");
253
+ };
254
+ for (const key of keys) {
255
+ dispatchForKey(key);
256
+ }
257
+ for (const key of extraKeys) {
258
+ dispatchForKey(key);
259
+ }
260
+ }
261
+ },
262
+ array(arr, unordered) {
263
+ unordered = unordered === void 0 ? options.unorderedArrays !== false : unordered;
264
+ write("array:" + arr.length + ":");
265
+ if (!unordered || arr.length <= 1) {
266
+ for (const entry of arr) {
267
+ this.dispatch(entry);
268
+ }
269
+ return;
270
+ }
271
+ const contextAdditions = /* @__PURE__ */ new Map();
272
+ const entries = arr.map((entry) => {
273
+ const hasher = createHasher(options);
274
+ hasher.dispatch(entry);
275
+ for (const [key, value] of hasher.getContext()) {
276
+ contextAdditions.set(key, value);
277
+ }
278
+ return hasher.toString();
279
+ });
280
+ context = contextAdditions;
281
+ entries.sort();
282
+ return this.array(entries, false);
283
+ },
284
+ date(date) {
285
+ return write("date:" + date.toJSON());
286
+ },
287
+ symbol(sym) {
288
+ return write("symbol:" + sym.toString());
289
+ },
290
+ unkown(value, type) {
291
+ write(type);
292
+ if (!value) {
293
+ return;
294
+ }
295
+ write(":");
296
+ if (value && typeof value.entries === "function") {
297
+ return this.array(
298
+ Array.from(value.entries()),
299
+ true
300
+ /* ordered */
301
+ );
302
+ }
303
+ },
304
+ error(err) {
305
+ return write("error:" + err.toString());
306
+ },
307
+ boolean(bool) {
308
+ return write("bool:" + bool);
309
+ },
310
+ string(string) {
311
+ write("string:" + string.length + ":");
312
+ write(string);
313
+ },
314
+ function(fn) {
315
+ write("fn:");
316
+ if (isNativeFunction(fn)) {
317
+ this.dispatch("[native]");
318
+ } else {
319
+ this.dispatch(fn.toString());
320
+ }
321
+ if (options.respectFunctionNames !== false) {
322
+ this.dispatch("function-name:" + String(fn.name));
323
+ }
324
+ if (options.respectFunctionProperties) {
325
+ this.object(fn);
326
+ }
327
+ },
328
+ number(number) {
329
+ return write("number:" + number);
330
+ },
331
+ xml(xml) {
332
+ return write("xml:" + xml.toString());
333
+ },
334
+ null() {
335
+ return write("Null");
336
+ },
337
+ undefined() {
338
+ return write("Undefined");
339
+ },
340
+ regexp(regex) {
341
+ return write("regex:" + regex.toString());
342
+ },
343
+ uint8array(arr) {
344
+ write("uint8array:");
345
+ return this.dispatch(Array.prototype.slice.call(arr));
346
+ },
347
+ uint8clampedarray(arr) {
348
+ write("uint8clampedarray:");
349
+ return this.dispatch(Array.prototype.slice.call(arr));
350
+ },
351
+ int8array(arr) {
352
+ write("int8array:");
353
+ return this.dispatch(Array.prototype.slice.call(arr));
354
+ },
355
+ uint16array(arr) {
356
+ write("uint16array:");
357
+ return this.dispatch(Array.prototype.slice.call(arr));
358
+ },
359
+ int16array(arr) {
360
+ write("int16array:");
361
+ return this.dispatch(Array.prototype.slice.call(arr));
362
+ },
363
+ uint32array(arr) {
364
+ write("uint32array:");
365
+ return this.dispatch(Array.prototype.slice.call(arr));
366
+ },
367
+ int32array(arr) {
368
+ write("int32array:");
369
+ return this.dispatch(Array.prototype.slice.call(arr));
370
+ },
371
+ float32array(arr) {
372
+ write("float32array:");
373
+ return this.dispatch(Array.prototype.slice.call(arr));
374
+ },
375
+ float64array(arr) {
376
+ write("float64array:");
377
+ return this.dispatch(Array.prototype.slice.call(arr));
378
+ },
379
+ arraybuffer(arr) {
380
+ write("arraybuffer:");
381
+ return this.dispatch(new Uint8Array(arr));
382
+ },
383
+ url(url) {
384
+ return write("url:" + url.toString());
385
+ },
386
+ map(map) {
387
+ write("map:");
388
+ const arr = [...map];
389
+ return this.array(arr, options.unorderedSets !== false);
390
+ },
391
+ set(set) {
392
+ write("set:");
393
+ const arr = [...set];
394
+ return this.array(arr, options.unorderedSets !== false);
395
+ },
396
+ file(file) {
397
+ write("file:");
398
+ return this.dispatch([file.name, file.size, file.type, file.lastModfied]);
399
+ },
400
+ blob() {
401
+ if (options.ignoreUnknown) {
402
+ return write("[blob]");
403
+ }
404
+ throw new Error(
405
+ 'Hashing Blob objects is currently not supported\nUse "options.replacer" or "options.ignoreUnknown"\n'
406
+ );
407
+ },
408
+ domwindow() {
409
+ return write("domwindow");
410
+ },
411
+ bigint(number) {
412
+ return write("bigint:" + number.toString());
413
+ },
414
+ /* Node.js standard native objects */
415
+ process() {
416
+ return write("process");
417
+ },
418
+ timer() {
419
+ return write("timer");
420
+ },
421
+ pipe() {
422
+ return write("pipe");
423
+ },
424
+ tcp() {
425
+ return write("tcp");
426
+ },
427
+ udp() {
428
+ return write("udp");
429
+ },
430
+ tty() {
431
+ return write("tty");
432
+ },
433
+ statwatcher() {
434
+ return write("statwatcher");
435
+ },
436
+ securecontext() {
437
+ return write("securecontext");
438
+ },
439
+ connection() {
440
+ return write("connection");
441
+ },
442
+ zlib() {
443
+ return write("zlib");
444
+ },
445
+ context() {
446
+ return write("context");
447
+ },
448
+ nodescript() {
449
+ return write("nodescript");
450
+ },
451
+ httpparser() {
452
+ return write("httpparser");
453
+ },
454
+ dataview() {
455
+ return write("dataview");
456
+ },
457
+ signal() {
458
+ return write("signal");
459
+ },
460
+ fsevent() {
461
+ return write("fsevent");
462
+ },
463
+ tlswrap() {
464
+ return write("tlswrap");
465
+ }
466
+ };
467
+ }
468
+ const nativeFunc = "[native code] }";
469
+ const nativeFuncLength = nativeFunc.length;
470
+ function isNativeFunction(f) {
471
+ if (typeof f !== "function") {
472
+ return false;
473
+ }
474
+ return Function.prototype.toString.call(f).slice(-nativeFuncLength) === nativeFunc;
475
+ }
476
+
477
+ function hasProp(obj, prop) {
478
+ try {
479
+ return prop in obj;
480
+ } catch {
481
+ return false;
482
+ }
483
+ }
484
+
485
+ var __defProp$2 = Object.defineProperty;
486
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
487
+ var __publicField$2 = (obj, key, value) => {
488
+ __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
489
+ return value;
490
+ };
491
+ class H3Error extends Error {
492
+ constructor(message, opts = {}) {
493
+ super(message, opts);
494
+ __publicField$2(this, "statusCode", 500);
495
+ __publicField$2(this, "fatal", false);
496
+ __publicField$2(this, "unhandled", false);
497
+ __publicField$2(this, "statusMessage");
498
+ __publicField$2(this, "data");
499
+ __publicField$2(this, "cause");
500
+ if (opts.cause && !this.cause) {
501
+ this.cause = opts.cause;
502
+ }
503
+ }
504
+ toJSON() {
505
+ const obj = {
506
+ message: this.message,
507
+ statusCode: sanitizeStatusCode(this.statusCode, 500)
508
+ };
509
+ if (this.statusMessage) {
510
+ obj.statusMessage = sanitizeStatusMessage(this.statusMessage);
511
+ }
512
+ if (this.data !== void 0) {
513
+ obj.data = this.data;
514
+ }
515
+ return obj;
516
+ }
517
+ }
518
+ __publicField$2(H3Error, "__h3_error__", true);
519
+
520
+ const DISALLOWED_STATUS_CHARS = /[^\u0009\u0020-\u007E]/g;
521
+ function sanitizeStatusMessage(statusMessage = "") {
522
+ return statusMessage.replace(DISALLOWED_STATUS_CHARS, "");
523
+ }
524
+ function sanitizeStatusCode(statusCode, defaultStatusCode = 200) {
525
+ if (!statusCode) {
526
+ return defaultStatusCode;
527
+ }
528
+ if (typeof statusCode === "string") {
529
+ statusCode = Number.parseInt(statusCode, 10);
530
+ }
531
+ if (statusCode < 100 || statusCode > 999) {
532
+ return defaultStatusCode;
533
+ }
534
+ return statusCode;
535
+ }
536
+ function setCookie$1(event, name, value, serializeOptions) {
537
+ serializeOptions = { path: "/", ...serializeOptions };
538
+ const cookieStr = serialize(name, value, serializeOptions);
539
+ let setCookies = event.node.res.getHeader("set-cookie");
540
+ if (!Array.isArray(setCookies)) {
541
+ setCookies = [setCookies];
542
+ }
543
+ const _optionsHash = objectHash(serializeOptions);
544
+ setCookies = setCookies.filter((cookieValue) => {
545
+ return cookieValue && _optionsHash !== objectHash(parse(cookieValue));
546
+ });
547
+ event.node.res.setHeader("set-cookie", [...setCookies, cookieStr]);
548
+ }
549
+ function splitCookiesString(cookiesString) {
550
+ if (Array.isArray(cookiesString)) {
551
+ return cookiesString.flatMap((c) => splitCookiesString(c));
552
+ }
553
+ if (typeof cookiesString !== "string") {
554
+ return [];
555
+ }
556
+ const cookiesStrings = [];
557
+ let pos = 0;
558
+ let start;
559
+ let ch;
560
+ let lastComma;
561
+ let nextStart;
562
+ let cookiesSeparatorFound;
563
+ const skipWhitespace = () => {
564
+ while (pos < cookiesString.length && /\s/.test(cookiesString.charAt(pos))) {
565
+ pos += 1;
566
+ }
567
+ return pos < cookiesString.length;
568
+ };
569
+ const notSpecialChar = () => {
570
+ ch = cookiesString.charAt(pos);
571
+ return ch !== "=" && ch !== ";" && ch !== ",";
572
+ };
573
+ while (pos < cookiesString.length) {
574
+ start = pos;
575
+ cookiesSeparatorFound = false;
576
+ while (skipWhitespace()) {
577
+ ch = cookiesString.charAt(pos);
578
+ if (ch === ",") {
579
+ lastComma = pos;
580
+ pos += 1;
581
+ skipWhitespace();
582
+ nextStart = pos;
583
+ while (pos < cookiesString.length && notSpecialChar()) {
584
+ pos += 1;
585
+ }
586
+ if (pos < cookiesString.length && cookiesString.charAt(pos) === "=") {
587
+ cookiesSeparatorFound = true;
588
+ pos = nextStart;
589
+ cookiesStrings.push(cookiesString.slice(start, lastComma));
590
+ start = pos;
591
+ } else {
592
+ pos = lastComma + 1;
593
+ }
594
+ } else {
595
+ pos += 1;
596
+ }
597
+ }
598
+ if (!cookiesSeparatorFound || pos >= cookiesString.length) {
599
+ cookiesStrings.push(cookiesString.slice(start));
600
+ }
601
+ }
602
+ return cookiesStrings;
603
+ }
604
+
605
+ typeof setImmediate === "undefined" ? (fn) => fn() : setImmediate;
606
+ function sendStream(event, stream) {
607
+ if (!stream || typeof stream !== "object") {
608
+ throw new Error("[h3] Invalid stream provided.");
609
+ }
610
+ event.node.res._data = stream;
611
+ if (!event.node.res.socket) {
612
+ event._handled = true;
613
+ return Promise.resolve();
614
+ }
615
+ if (hasProp(stream, "pipeTo") && typeof stream.pipeTo === "function") {
616
+ return stream.pipeTo(
617
+ new WritableStream({
618
+ write(chunk) {
619
+ event.node.res.write(chunk);
620
+ }
621
+ })
622
+ ).then(() => {
623
+ event.node.res.end();
624
+ });
625
+ }
626
+ if (hasProp(stream, "pipe") && typeof stream.pipe === "function") {
627
+ return new Promise((resolve, reject) => {
628
+ stream.pipe(event.node.res);
629
+ if (stream.on) {
630
+ stream.on("end", () => {
631
+ event.node.res.end();
632
+ resolve();
633
+ });
634
+ stream.on("error", (error) => {
635
+ reject(error);
636
+ });
637
+ }
638
+ event.node.res.on("close", () => {
639
+ if (stream.abort) {
640
+ stream.abort();
641
+ }
642
+ });
643
+ });
644
+ }
645
+ throw new Error("[h3] Invalid or incompatible stream provided.");
646
+ }
647
+ function sendWebResponse(event, response) {
648
+ for (const [key, value] of response.headers) {
649
+ if (key === "set-cookie") {
650
+ event.node.res.appendHeader(key, splitCookiesString(value));
651
+ } else {
652
+ event.node.res.setHeader(key, value);
653
+ }
654
+ }
655
+ if (response.status) {
656
+ event.node.res.statusCode = sanitizeStatusCode(
657
+ response.status,
658
+ event.node.res.statusCode
659
+ );
660
+ }
661
+ if (response.statusText) {
662
+ event.node.res.statusMessage = sanitizeStatusMessage(response.statusText);
663
+ }
664
+ if (response.redirected) {
665
+ event.node.res.setHeader("location", response.url);
666
+ }
667
+ if (!response.body) {
668
+ event.node.res.end();
669
+ return;
670
+ }
671
+ return sendStream(event, response.body);
672
+ }
673
+
674
+ var __defProp = Object.defineProperty;
675
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
676
+ var __publicField = (obj, key, value) => {
677
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
678
+ return value;
679
+ };
680
+ class H3Event {
681
+ constructor(req, res) {
682
+ __publicField(this, "__is_event__", true);
683
+ // Context
684
+ __publicField(this, "node");
685
+ // Node
686
+ __publicField(this, "web");
687
+ // Web
688
+ __publicField(this, "context", {});
689
+ // Shared
690
+ // Request
691
+ __publicField(this, "_method");
692
+ __publicField(this, "_path");
693
+ __publicField(this, "_headers");
694
+ __publicField(this, "_requestBody");
695
+ // Response
696
+ __publicField(this, "_handled", false);
697
+ // Hooks
698
+ __publicField(this, "_onBeforeResponseCalled");
699
+ __publicField(this, "_onAfterResponseCalled");
700
+ this.node = { req, res };
701
+ }
702
+ // --- Request ---
703
+ get method() {
704
+ if (!this._method) {
705
+ this._method = (this.node.req.method || "GET").toUpperCase();
706
+ }
707
+ return this._method;
708
+ }
709
+ get path() {
710
+ return this._path || this.node.req.url || "/";
711
+ }
712
+ get headers() {
713
+ if (!this._headers) {
714
+ this._headers = _normalizeNodeHeaders(this.node.req.headers);
715
+ }
716
+ return this._headers;
717
+ }
718
+ // --- Respoonse ---
719
+ get handled() {
720
+ return this._handled || this.node.res.writableEnded || this.node.res.headersSent;
721
+ }
722
+ respondWith(response) {
723
+ return Promise.resolve(response).then(
724
+ (_response) => sendWebResponse(this, _response)
725
+ );
726
+ }
727
+ // --- Utils ---
728
+ toString() {
729
+ return `[${this.method}] ${this.path}`;
730
+ }
731
+ toJSON() {
732
+ return this.toString();
733
+ }
734
+ // --- Deprecated ---
735
+ /** @deprecated Please use `event.node.req` instead. */
736
+ get req() {
737
+ return this.node.req;
738
+ }
739
+ /** @deprecated Please use `event.node.res` instead. */
740
+ get res() {
741
+ return this.node.res;
742
+ }
743
+ }
744
+ function _normalizeNodeHeaders(nodeHeaders) {
745
+ const headers = new Headers();
746
+ for (const [name, value] of Object.entries(nodeHeaders)) {
747
+ if (Array.isArray(value)) {
748
+ for (const item of value) {
749
+ headers.append(name, item);
750
+ }
751
+ } else if (value) {
752
+ headers.set(name, value);
753
+ }
754
+ }
755
+ return headers;
756
+ }
757
+
758
+ function createContext(opts = {}) {
759
+ let currentInstance;
760
+ let isSingleton = false;
761
+ const checkConflict = (instance) => {
762
+ if (currentInstance && currentInstance !== instance) {
763
+ throw new Error("Context conflict");
764
+ }
765
+ };
766
+ let als;
767
+ if (opts.asyncContext) {
768
+ const _AsyncLocalStorage = opts.AsyncLocalStorage || globalThis.AsyncLocalStorage;
769
+ if (_AsyncLocalStorage) {
770
+ als = new _AsyncLocalStorage();
771
+ } else {
772
+ console.warn("[unctx] `AsyncLocalStorage` is not provided.");
773
+ }
774
+ }
775
+ const _getCurrentInstance = () => {
776
+ if (als) {
777
+ const instance = als.getStore();
778
+ if (instance !== void 0) {
779
+ return instance;
780
+ }
781
+ }
782
+ return currentInstance;
783
+ };
784
+ return {
785
+ use: () => {
786
+ const _instance = _getCurrentInstance();
787
+ if (_instance === void 0) {
788
+ throw new Error("Context is not available");
789
+ }
790
+ return _instance;
791
+ },
792
+ tryUse: () => {
793
+ return _getCurrentInstance();
794
+ },
795
+ set: (instance, replace) => {
796
+ if (!replace) {
797
+ checkConflict(instance);
798
+ }
799
+ currentInstance = instance;
800
+ isSingleton = true;
801
+ },
802
+ unset: () => {
803
+ currentInstance = void 0;
804
+ isSingleton = false;
805
+ },
806
+ call: (instance, callback) => {
807
+ checkConflict(instance);
808
+ currentInstance = instance;
809
+ try {
810
+ return als ? als.run(instance, callback) : callback();
811
+ } finally {
812
+ if (!isSingleton) {
813
+ currentInstance = void 0;
814
+ }
815
+ }
816
+ },
817
+ async callAsync(instance, callback) {
818
+ currentInstance = instance;
819
+ const onRestore = () => {
820
+ currentInstance = instance;
821
+ };
822
+ const onLeave = () => currentInstance === instance ? onRestore : void 0;
823
+ asyncHandlers.add(onLeave);
824
+ try {
825
+ const r = als ? als.run(instance, callback) : callback();
826
+ if (!isSingleton) {
827
+ currentInstance = void 0;
828
+ }
829
+ return await r;
830
+ } finally {
831
+ asyncHandlers.delete(onLeave);
832
+ }
833
+ }
834
+ };
835
+ }
836
+ function createNamespace(defaultOpts = {}) {
837
+ const contexts = {};
838
+ return {
839
+ get(key, opts = {}) {
840
+ if (!contexts[key]) {
841
+ contexts[key] = createContext({ ...defaultOpts, ...opts });
842
+ }
843
+ return contexts[key];
844
+ }
845
+ };
846
+ }
847
+ const _globalThis = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : typeof global !== "undefined" ? global : typeof window !== "undefined" ? window : {};
848
+ const globalKey = "__unctx__";
849
+ const defaultNamespace = _globalThis[globalKey] || (_globalThis[globalKey] = createNamespace());
850
+ const getContext = (key, opts = {}) => defaultNamespace.get(key, opts);
851
+ const asyncHandlersKey = "__unctx_async_handlers__";
852
+ const asyncHandlers = _globalThis[asyncHandlersKey] || (_globalThis[asyncHandlersKey] = /* @__PURE__ */ new Set());
853
+
854
+ function getHTTPEvent() {
855
+ return getEvent();
856
+ }
857
+ const HTTPEventSymbol = Symbol("$HTTPEvent");
858
+ function isEvent(obj) {
859
+ return typeof obj === "object" && (obj instanceof H3Event || (obj == null ? void 0 : obj[HTTPEventSymbol]) instanceof H3Event || (obj == null ? void 0 : obj.__is_event__) === true);
860
+ }
861
+ function createWrapperFunction(h3Function) {
862
+ return function(...args) {
863
+ var _a;
864
+ const event = args[0];
865
+ if (!isEvent(event)) {
866
+ if (!((_a = globalThis.app.config.server.experimental) == null ? void 0 : _a.asyncContext)) {
867
+ throw new Error(
868
+ "AsyncLocalStorage was not enabled. Use the `server.experimental.asyncContext: true` option in your app configuration to enable it. Or, pass the instance of HTTPEvent that you have as the first argument to the function."
869
+ );
870
+ }
871
+ args.unshift(getHTTPEvent());
872
+ } else {
873
+ args[0] = event instanceof H3Event || event.__is_event__ ? event : event[HTTPEventSymbol];
874
+ }
875
+ return h3Function(...args);
876
+ };
877
+ }
878
+ const setCookie = createWrapperFunction(setCookie$1);
879
+ function getNitroAsyncContext() {
880
+ var _a;
881
+ const nitroAsyncContext = getContext("nitro-app", {
882
+ asyncContext: ((_a = globalThis.app.config.server.experimental) == null ? void 0 : _a.asyncContext) ? true : false,
883
+ AsyncLocalStorage: node_async_hooks.AsyncLocalStorage
884
+ });
885
+ return nitroAsyncContext;
886
+ }
887
+ function getEvent() {
888
+ const event = getNitroAsyncContext().use().event;
889
+ if (!event) {
890
+ throw new Error(
891
+ `No HTTPEvent found in AsyncLocalStorage. Make sure you are using the function within the server runtime.`
892
+ );
893
+ }
894
+ return event;
895
+ }
896
+
897
+ exports.H3Error = H3Error;
898
+ exports.H3Event = H3Event;
899
+ exports.HTTPEventSymbol = HTTPEventSymbol;
900
+ exports.getEvent = getEvent;
901
+ exports.isEvent = isEvent;
902
+ exports.sanitizeStatusCode = sanitizeStatusCode;
903
+ exports.sanitizeStatusMessage = sanitizeStatusMessage;
904
+ exports.setCookie = setCookie;
905
+ exports.splitCookiesString = splitCookiesString;