@erikey/react 0.3.5 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,608 +1,38 @@
1
- // ../../../node_modules/.pnpm/@better-fetch+fetch@1.1.18/node_modules/@better-fetch/fetch/dist/index.js
2
1
  var __defProp = Object.defineProperty;
3
- var __defProps = Object.defineProperties;
4
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
8
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
- var __spreadValues = (a, b) => {
10
- for (var prop in b || (b = {}))
11
- if (__hasOwnProp.call(b, prop))
12
- __defNormalProp(a, prop, b[prop]);
13
- if (__getOwnPropSymbols)
14
- for (var prop of __getOwnPropSymbols(b)) {
15
- if (__propIsEnum.call(b, prop))
16
- __defNormalProp(a, prop, b[prop]);
17
- }
18
- return a;
19
- };
20
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
- var BetterFetchError = class extends Error {
22
- constructor(status, statusText, error) {
23
- super(statusText || status.toString(), {
24
- cause: error
25
- });
26
- this.status = status;
27
- this.statusText = statusText;
28
- this.error = error;
29
- }
30
- };
31
- var initializePlugins = async (url, options) => {
32
- var _a, _b, _c, _d, _e, _f;
33
- let opts = options || {};
34
- const hooks = {
35
- onRequest: [options == null ? void 0 : options.onRequest],
36
- onResponse: [options == null ? void 0 : options.onResponse],
37
- onSuccess: [options == null ? void 0 : options.onSuccess],
38
- onError: [options == null ? void 0 : options.onError],
39
- onRetry: [options == null ? void 0 : options.onRetry]
40
- };
41
- if (!options || !(options == null ? void 0 : options.plugins)) {
42
- return {
43
- url,
44
- options: opts,
45
- hooks
46
- };
47
- }
48
- for (const plugin of (options == null ? void 0 : options.plugins) || []) {
49
- if (plugin.init) {
50
- const pluginRes = await ((_a = plugin.init) == null ? void 0 : _a.call(plugin, url.toString(), options));
51
- opts = pluginRes.options || opts;
52
- url = pluginRes.url;
53
- }
54
- hooks.onRequest.push((_b = plugin.hooks) == null ? void 0 : _b.onRequest);
55
- hooks.onResponse.push((_c = plugin.hooks) == null ? void 0 : _c.onResponse);
56
- hooks.onSuccess.push((_d = plugin.hooks) == null ? void 0 : _d.onSuccess);
57
- hooks.onError.push((_e = plugin.hooks) == null ? void 0 : _e.onError);
58
- hooks.onRetry.push((_f = plugin.hooks) == null ? void 0 : _f.onRetry);
59
- }
60
- return {
61
- url,
62
- options: opts,
63
- hooks
64
- };
65
- };
66
- var LinearRetryStrategy = class {
67
- constructor(options) {
68
- this.options = options;
69
- }
70
- shouldAttemptRetry(attempt, response) {
71
- if (this.options.shouldRetry) {
72
- return Promise.resolve(
73
- attempt < this.options.attempts && this.options.shouldRetry(response)
74
- );
75
- }
76
- return Promise.resolve(attempt < this.options.attempts);
77
- }
78
- getDelay() {
79
- return this.options.delay;
80
- }
81
- };
82
- var ExponentialRetryStrategy = class {
83
- constructor(options) {
84
- this.options = options;
85
- }
86
- shouldAttemptRetry(attempt, response) {
87
- if (this.options.shouldRetry) {
88
- return Promise.resolve(
89
- attempt < this.options.attempts && this.options.shouldRetry(response)
90
- );
91
- }
92
- return Promise.resolve(attempt < this.options.attempts);
93
- }
94
- getDelay(attempt) {
95
- const delay = Math.min(
96
- this.options.maxDelay,
97
- this.options.baseDelay * 2 ** attempt
98
- );
99
- return delay;
100
- }
101
- };
102
- function createRetryStrategy(options) {
103
- if (typeof options === "number") {
104
- return new LinearRetryStrategy({
105
- type: "linear",
106
- attempts: options,
107
- delay: 1e3
108
- });
109
- }
110
- switch (options.type) {
111
- case "linear":
112
- return new LinearRetryStrategy(options);
113
- case "exponential":
114
- return new ExponentialRetryStrategy(options);
115
- default:
116
- throw new Error("Invalid retry strategy");
117
- }
118
- }
119
- var getAuthHeader = async (options) => {
120
- const headers = {};
121
- const getValue = async (value) => typeof value === "function" ? await value() : value;
122
- if (options == null ? void 0 : options.auth) {
123
- if (options.auth.type === "Bearer") {
124
- const token = await getValue(options.auth.token);
125
- if (!token) {
126
- return headers;
127
- }
128
- headers["authorization"] = `Bearer ${token}`;
129
- } else if (options.auth.type === "Basic") {
130
- const username = getValue(options.auth.username);
131
- const password = getValue(options.auth.password);
132
- if (!username || !password) {
133
- return headers;
134
- }
135
- headers["authorization"] = `Basic ${btoa(`${username}:${password}`)}`;
136
- } else if (options.auth.type === "Custom") {
137
- const value = getValue(options.auth.value);
138
- if (!value) {
139
- return headers;
140
- }
141
- headers["authorization"] = `${getValue(options.auth.prefix)} ${value}`;
142
- }
143
- }
144
- return headers;
145
- };
146
- var JSON_RE = /^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i;
147
- function detectResponseType(request) {
148
- const _contentType = request.headers.get("content-type");
149
- const textTypes = /* @__PURE__ */ new Set([
150
- "image/svg",
151
- "application/xml",
152
- "application/xhtml",
153
- "application/html"
154
- ]);
155
- if (!_contentType) {
156
- return "json";
157
- }
158
- const contentType = _contentType.split(";").shift() || "";
159
- if (JSON_RE.test(contentType)) {
160
- return "json";
161
- }
162
- if (textTypes.has(contentType) || contentType.startsWith("text/")) {
163
- return "text";
164
- }
165
- return "blob";
166
- }
167
- function isJSONParsable(value) {
168
- try {
169
- JSON.parse(value);
170
- return true;
171
- } catch (error) {
172
- return false;
173
- }
174
- }
175
- function isJSONSerializable(value) {
176
- if (value === void 0) {
177
- return false;
178
- }
179
- const t = typeof value;
180
- if (t === "string" || t === "number" || t === "boolean" || t === null) {
181
- return true;
182
- }
183
- if (t !== "object") {
184
- return false;
185
- }
186
- if (Array.isArray(value)) {
187
- return true;
188
- }
189
- if (value.buffer) {
190
- return false;
191
- }
192
- return value.constructor && value.constructor.name === "Object" || typeof value.toJSON === "function";
193
- }
194
- function jsonParse(text) {
195
- try {
196
- return JSON.parse(text);
197
- } catch (error) {
198
- return text;
199
- }
200
- }
201
- function isFunction(value) {
202
- return typeof value === "function";
203
- }
204
- function getFetch(options) {
205
- if (options == null ? void 0 : options.customFetchImpl) {
206
- return options.customFetchImpl;
207
- }
208
- if (typeof globalThis !== "undefined" && isFunction(globalThis.fetch)) {
209
- return globalThis.fetch;
210
- }
211
- if (typeof window !== "undefined" && isFunction(window.fetch)) {
212
- return window.fetch;
213
- }
214
- throw new Error("No fetch implementation found");
215
- }
216
- async function getHeaders(opts) {
217
- const headers = new Headers(opts == null ? void 0 : opts.headers);
218
- const authHeader = await getAuthHeader(opts);
219
- for (const [key, value] of Object.entries(authHeader || {})) {
220
- headers.set(key, value);
221
- }
222
- if (!headers.has("content-type")) {
223
- const t = detectContentType(opts == null ? void 0 : opts.body);
224
- if (t) {
225
- headers.set("content-type", t);
226
- }
227
- }
228
- return headers;
229
- }
230
- function detectContentType(body) {
231
- if (isJSONSerializable(body)) {
232
- return "application/json";
233
- }
234
- return null;
235
- }
236
- function getBody(options) {
237
- if (!(options == null ? void 0 : options.body)) {
238
- return null;
239
- }
240
- const headers = new Headers(options == null ? void 0 : options.headers);
241
- if (isJSONSerializable(options.body) && !headers.has("content-type")) {
242
- for (const [key, value] of Object.entries(options == null ? void 0 : options.body)) {
243
- if (value instanceof Date) {
244
- options.body[key] = value.toISOString();
245
- }
246
- }
247
- return JSON.stringify(options.body);
248
- }
249
- return options.body;
250
- }
251
- function getMethod(url, options) {
252
- var _a;
253
- if (options == null ? void 0 : options.method) {
254
- return options.method.toUpperCase();
255
- }
256
- if (url.startsWith("@")) {
257
- const pMethod = (_a = url.split("@")[1]) == null ? void 0 : _a.split("/")[0];
258
- if (!methods.includes(pMethod)) {
259
- return (options == null ? void 0 : options.body) ? "POST" : "GET";
260
- }
261
- return pMethod.toUpperCase();
262
- }
263
- return (options == null ? void 0 : options.body) ? "POST" : "GET";
264
- }
265
- function getTimeout(options, controller) {
266
- let abortTimeout;
267
- if (!(options == null ? void 0 : options.signal) && (options == null ? void 0 : options.timeout)) {
268
- abortTimeout = setTimeout(() => controller == null ? void 0 : controller.abort(), options == null ? void 0 : options.timeout);
269
- }
270
- return {
271
- abortTimeout,
272
- clearTimeout: () => {
273
- if (abortTimeout) {
274
- clearTimeout(abortTimeout);
275
- }
276
- }
277
- };
278
- }
279
- var ValidationError = class _ValidationError extends Error {
280
- constructor(issues, message) {
281
- super(message || JSON.stringify(issues, null, 2));
282
- this.issues = issues;
283
- Object.setPrototypeOf(this, _ValidationError.prototype);
284
- }
285
- };
286
- async function parseStandardSchema(schema, input) {
287
- let result = await schema["~standard"].validate(input);
288
- if (result.issues) {
289
- throw new ValidationError(result.issues);
290
- }
291
- return result.value;
292
- }
293
- var methods = ["get", "post", "put", "patch", "delete"];
294
- var applySchemaPlugin = (config) => ({
295
- id: "apply-schema",
296
- name: "Apply Schema",
297
- version: "1.0.0",
298
- async init(url, options) {
299
- var _a, _b, _c, _d;
300
- const schema = ((_b = (_a = config.plugins) == null ? void 0 : _a.find(
301
- (plugin) => {
302
- var _a2;
303
- return ((_a2 = plugin.schema) == null ? void 0 : _a2.config) ? url.startsWith(plugin.schema.config.baseURL || "") || url.startsWith(plugin.schema.config.prefix || "") : false;
304
- }
305
- )) == null ? void 0 : _b.schema) || config.schema;
306
- if (schema) {
307
- let urlKey = url;
308
- if ((_c = schema.config) == null ? void 0 : _c.prefix) {
309
- if (urlKey.startsWith(schema.config.prefix)) {
310
- urlKey = urlKey.replace(schema.config.prefix, "");
311
- if (schema.config.baseURL) {
312
- url = url.replace(schema.config.prefix, schema.config.baseURL);
313
- }
314
- }
315
- }
316
- if ((_d = schema.config) == null ? void 0 : _d.baseURL) {
317
- if (urlKey.startsWith(schema.config.baseURL)) {
318
- urlKey = urlKey.replace(schema.config.baseURL, "");
319
- }
320
- }
321
- const keySchema = schema.schema[urlKey];
322
- if (keySchema) {
323
- let opts = __spreadProps(__spreadValues({}, options), {
324
- method: keySchema.method,
325
- output: keySchema.output
326
- });
327
- if (!(options == null ? void 0 : options.disableValidation)) {
328
- opts = __spreadProps(__spreadValues({}, opts), {
329
- body: keySchema.input ? await parseStandardSchema(keySchema.input, options == null ? void 0 : options.body) : options == null ? void 0 : options.body,
330
- params: keySchema.params ? await parseStandardSchema(keySchema.params, options == null ? void 0 : options.params) : options == null ? void 0 : options.params,
331
- query: keySchema.query ? await parseStandardSchema(keySchema.query, options == null ? void 0 : options.query) : options == null ? void 0 : options.query
332
- });
333
- }
334
- return {
335
- url,
336
- options: opts
337
- };
338
- }
339
- }
340
- return {
341
- url,
342
- options
343
- };
344
- }
345
- });
346
- var createFetch = (config) => {
347
- async function $fetch(url, options) {
348
- const opts = __spreadProps(__spreadValues(__spreadValues({}, config), options), {
349
- plugins: [...(config == null ? void 0 : config.plugins) || [], applySchemaPlugin(config || {})]
350
- });
351
- if (config == null ? void 0 : config.catchAllError) {
352
- try {
353
- return await betterFetch(url, opts);
354
- } catch (error) {
355
- return {
356
- data: null,
357
- error: {
358
- status: 500,
359
- statusText: "Fetch Error",
360
- message: "Fetch related error. Captured by catchAllError option. See error property for more details.",
361
- error
362
- }
363
- };
364
- }
365
- }
366
- return await betterFetch(url, opts);
367
- }
368
- return $fetch;
369
- };
370
- function getURL2(url, option) {
371
- let { baseURL, params, query } = option || {
372
- query: {},
373
- params: {},
374
- baseURL: ""
375
- };
376
- let basePath = url.startsWith("http") ? url.split("/").slice(0, 3).join("/") : baseURL || "";
377
- if (url.startsWith("@")) {
378
- const m = url.toString().split("@")[1].split("/")[0];
379
- if (methods.includes(m)) {
380
- url = url.replace(`@${m}/`, "/");
381
- }
382
- }
383
- if (!basePath.endsWith("/")) basePath += "/";
384
- let [path, urlQuery] = url.replace(basePath, "").split("?");
385
- const queryParams = new URLSearchParams(urlQuery);
386
- for (const [key, value] of Object.entries(query || {})) {
387
- if (value == null) continue;
388
- queryParams.set(key, String(value));
389
- }
390
- if (params) {
391
- if (Array.isArray(params)) {
392
- const paramPaths = path.split("/").filter((p) => p.startsWith(":"));
393
- for (const [index, key] of paramPaths.entries()) {
394
- const value = params[index];
395
- path = path.replace(key, value);
396
- }
397
- } else {
398
- for (const [key, value] of Object.entries(params)) {
399
- path = path.replace(`:${key}`, String(value));
400
- }
401
- }
402
- }
403
- path = path.split("/").map(encodeURIComponent).join("/");
404
- if (path.startsWith("/")) path = path.slice(1);
405
- let queryParamString = queryParams.toString();
406
- queryParamString = queryParamString.length > 0 ? `?${queryParamString}`.replace(/\+/g, "%20") : "";
407
- if (!basePath.startsWith("http")) {
408
- return `${basePath}${path}${queryParamString}`;
409
- }
410
- const _url = new URL(`${path}${queryParamString}`, basePath);
411
- return _url;
412
- }
413
- var betterFetch = async (url, options) => {
414
- var _a, _b, _c, _d, _e, _f, _g, _h;
415
- const {
416
- hooks,
417
- url: __url,
418
- options: opts
419
- } = await initializePlugins(url, options);
420
- const fetch2 = getFetch(opts);
421
- const controller = new AbortController();
422
- const signal = (_a = opts.signal) != null ? _a : controller.signal;
423
- const _url = getURL2(__url, opts);
424
- const body = getBody(opts);
425
- const headers = await getHeaders(opts);
426
- const method = getMethod(__url, opts);
427
- let context = __spreadProps(__spreadValues({}, opts), {
428
- url: _url,
429
- headers,
430
- body,
431
- method,
432
- signal
433
- });
434
- for (const onRequest of hooks.onRequest) {
435
- if (onRequest) {
436
- const res = await onRequest(context);
437
- if (res instanceof Object) {
438
- context = res;
439
- }
440
- }
441
- }
442
- if ("pipeTo" in context && typeof context.pipeTo === "function" || typeof ((_b = options == null ? void 0 : options.body) == null ? void 0 : _b.pipe) === "function") {
443
- if (!("duplex" in context)) {
444
- context.duplex = "half";
445
- }
446
- }
447
- const { clearTimeout: clearTimeout2 } = getTimeout(opts, controller);
448
- let response = await fetch2(context.url, context);
449
- clearTimeout2();
450
- const responseContext = {
451
- response,
452
- request: context
453
- };
454
- for (const onResponse of hooks.onResponse) {
455
- if (onResponse) {
456
- const r = await onResponse(__spreadProps(__spreadValues({}, responseContext), {
457
- response: ((_c = options == null ? void 0 : options.hookOptions) == null ? void 0 : _c.cloneResponse) ? response.clone() : response
458
- }));
459
- if (r instanceof Response) {
460
- response = r;
461
- } else if (r instanceof Object) {
462
- response = r.response;
463
- }
464
- }
465
- }
466
- if (response.ok) {
467
- const hasBody = context.method !== "HEAD";
468
- if (!hasBody) {
469
- return {
470
- data: "",
471
- error: null
472
- };
473
- }
474
- const responseType = detectResponseType(response);
475
- const successContext = {
476
- data: "",
477
- response,
478
- request: context
479
- };
480
- if (responseType === "json" || responseType === "text") {
481
- const text = await response.text();
482
- const parser2 = (_d = context.jsonParser) != null ? _d : jsonParse;
483
- const data = await parser2(text);
484
- successContext.data = data;
485
- } else {
486
- successContext.data = await response[responseType]();
487
- }
488
- if (context == null ? void 0 : context.output) {
489
- if (context.output && !context.disableValidation) {
490
- successContext.data = await parseStandardSchema(
491
- context.output,
492
- successContext.data
493
- );
494
- }
495
- }
496
- for (const onSuccess of hooks.onSuccess) {
497
- if (onSuccess) {
498
- await onSuccess(__spreadProps(__spreadValues({}, successContext), {
499
- response: ((_e = options == null ? void 0 : options.hookOptions) == null ? void 0 : _e.cloneResponse) ? response.clone() : response
500
- }));
501
- }
502
- }
503
- if (options == null ? void 0 : options.throw) {
504
- return successContext.data;
505
- }
506
- return {
507
- data: successContext.data,
508
- error: null
509
- };
510
- }
511
- const parser = (_f = options == null ? void 0 : options.jsonParser) != null ? _f : jsonParse;
512
- const responseText = await response.text();
513
- const isJSONResponse = isJSONParsable(responseText);
514
- const errorObject = isJSONResponse ? await parser(responseText) : null;
515
- const errorContext = {
516
- response,
517
- responseText,
518
- request: context,
519
- error: __spreadProps(__spreadValues({}, errorObject), {
520
- status: response.status,
521
- statusText: response.statusText
522
- })
523
- };
524
- for (const onError of hooks.onError) {
525
- if (onError) {
526
- await onError(__spreadProps(__spreadValues({}, errorContext), {
527
- response: ((_g = options == null ? void 0 : options.hookOptions) == null ? void 0 : _g.cloneResponse) ? response.clone() : response
528
- }));
529
- }
530
- }
531
- if (options == null ? void 0 : options.retry) {
532
- const retryStrategy = createRetryStrategy(options.retry);
533
- const _retryAttempt = (_h = options.retryAttempt) != null ? _h : 0;
534
- if (await retryStrategy.shouldAttemptRetry(_retryAttempt, response)) {
535
- for (const onRetry of hooks.onRetry) {
536
- if (onRetry) {
537
- await onRetry(responseContext);
538
- }
539
- }
540
- const delay = retryStrategy.getDelay(_retryAttempt);
541
- await new Promise((resolve) => setTimeout(resolve, delay));
542
- return await betterFetch(url, __spreadProps(__spreadValues({}, options), {
543
- retryAttempt: _retryAttempt + 1
544
- }));
545
- }
546
- }
547
- if (options == null ? void 0 : options.throw) {
548
- throw new BetterFetchError(
549
- response.status,
550
- response.statusText,
551
- isJSONResponse ? errorObject : responseText
552
- );
553
- }
554
- return {
555
- data: null,
556
- error: __spreadProps(__spreadValues({}, errorObject), {
557
- status: response.status,
558
- statusText: response.statusText
559
- })
560
- };
561
- };
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
562
4
 
563
- // ../../../node_modules/.pnpm/@better-auth+core@1.3.34_@better-auth+utils@0.3.0_@better-fetch+fetch@1.1.18_better-call@1.0._cenebiivepn42iaejxu4tccdyq/node_modules/@better-auth/core/dist/env/index.mjs
5
+ // ../../../node_modules/.pnpm/@better-auth+core@1.4.10_@better-auth+utils@0.3.0_@better-fetch+fetch@1.1.21_better-call@1.1._s4ptmt7cznbdkhj2rfry3i4hxy/node_modules/@better-auth/core/dist/env-DbssmzoK.mjs
564
6
  var _envShim = /* @__PURE__ */ Object.create(null);
565
- var _getEnv = (useShim) => globalThis.process?.env || //@ts-expect-error
566
- globalThis.Deno?.env.toObject() || //@ts-expect-error
567
- globalThis.__env__ || (useShim ? _envShim : globalThis);
7
+ var _getEnv = (useShim) => globalThis.process?.env || globalThis.Deno?.env.toObject() || globalThis.__env__ || (useShim ? _envShim : globalThis);
568
8
  var env = new Proxy(_envShim, {
569
9
  get(_, prop) {
570
- const env2 = _getEnv();
571
- return env2[prop] ?? _envShim[prop];
10
+ return _getEnv()[prop] ?? _envShim[prop];
572
11
  },
573
12
  has(_, prop) {
574
- const env2 = _getEnv();
575
- return prop in env2 || prop in _envShim;
13
+ return prop in _getEnv() || prop in _envShim;
576
14
  },
577
15
  set(_, prop, value) {
578
- const env2 = _getEnv(true);
579
- env2[prop] = value;
16
+ const env$1 = _getEnv(true);
17
+ env$1[prop] = value;
580
18
  return true;
581
19
  },
582
20
  deleteProperty(_, prop) {
583
- if (!prop) {
584
- return false;
585
- }
586
- const env2 = _getEnv(true);
587
- delete env2[prop];
21
+ if (!prop) return false;
22
+ const env$1 = _getEnv(true);
23
+ delete env$1[prop];
588
24
  return true;
589
25
  },
590
26
  ownKeys() {
591
- const env2 = _getEnv(true);
592
- return Object.keys(env2);
27
+ const env$1 = _getEnv(true);
28
+ return Object.keys(env$1);
593
29
  }
594
30
  });
595
31
  var nodeENV = typeof process !== "undefined" && process.env && process.env.NODE_ENV || "";
596
32
  function getEnvVar(key, fallback) {
597
- if (typeof process !== "undefined" && process.env) {
598
- return process.env[key] ?? fallback;
599
- }
600
- if (typeof Deno !== "undefined") {
601
- return Deno.env.get(key) ?? fallback;
602
- }
603
- if (typeof Bun !== "undefined") {
604
- return Bun.env[key] ?? fallback;
605
- }
33
+ if (typeof process !== "undefined" && process.env) return process.env[key] ?? fallback;
34
+ if (typeof Deno !== "undefined") return Deno.env.get(key) ?? fallback;
35
+ if (typeof Bun !== "undefined") return Bun.env[key] ?? fallback;
606
36
  return fallback;
607
37
  }
608
38
  var ENV = Object.freeze({
@@ -625,10 +55,7 @@ var ENV = Object.freeze({
625
55
  return getEnvVar("PACKAGE_VERSION", "0.0.0");
626
56
  },
627
57
  get BETTER_AUTH_TELEMETRY_ENDPOINT() {
628
- return getEnvVar(
629
- "BETTER_AUTH_TELEMETRY_ENDPOINT",
630
- "https://telemetry.better-auth.com/v1/track"
631
- );
58
+ return getEnvVar("BETTER_AUTH_TELEMETRY_ENDPOINT", "https://telemetry.better-auth.com/v1/track");
632
59
  }
633
60
  });
634
61
  var COLORS_2 = 1;
@@ -650,24 +77,20 @@ var TERM_ENVS = {
650
77
  mosh: COLORS_16m,
651
78
  putty: COLORS_16,
652
79
  st: COLORS_16,
653
- // http://lists.schmorp.de/pipermail/rxvt-unicode/2016q2/002261.html
654
80
  "rxvt-unicode-24bit": COLORS_16m,
655
- // https://bugs.launchpad.net/terminator/+bug/1030562
656
81
  terminator: COLORS_16m,
657
82
  "xterm-kitty": COLORS_16m
658
83
  };
659
- var CI_ENVS_MAP = new Map(
660
- Object.entries({
661
- APPVEYOR: COLORS_256,
662
- BUILDKITE: COLORS_256,
663
- CIRCLECI: COLORS_16m,
664
- DRONE: COLORS_256,
665
- GITEA_ACTIONS: COLORS_16m,
666
- GITHUB_ACTIONS: COLORS_16m,
667
- GITLAB_CI: COLORS_256,
668
- TRAVIS: COLORS_256
669
- })
670
- );
84
+ var CI_ENVS_MAP = new Map(Object.entries({
85
+ APPVEYOR: COLORS_256,
86
+ BUILDKITE: COLORS_256,
87
+ CIRCLECI: COLORS_16m,
88
+ DRONE: COLORS_256,
89
+ GITEA_ACTIONS: COLORS_16m,
90
+ GITHUB_ACTIONS: COLORS_16m,
91
+ GITLAB_CI: COLORS_256,
92
+ TRAVIS: COLORS_256
93
+ }));
671
94
  var TERM_ENVS_REG_EXP = [
672
95
  /ansi/,
673
96
  /color/,
@@ -681,54 +104,30 @@ var TERM_ENVS_REG_EXP = [
681
104
  /^vt220/
682
105
  ];
683
106
  function getColorDepth() {
684
- if (getEnvVar("FORCE_COLOR") !== void 0) {
685
- switch (getEnvVar("FORCE_COLOR")) {
686
- case "":
687
- case "1":
688
- case "true":
689
- return COLORS_16;
690
- case "2":
691
- return COLORS_256;
692
- case "3":
693
- return COLORS_16m;
694
- default:
695
- return COLORS_2;
696
- }
697
- }
698
- if (getEnvVar("NODE_DISABLE_COLORS") !== void 0 && getEnvVar("NODE_DISABLE_COLORS") !== "" || // See https://no-color.org/
699
- getEnvVar("NO_COLOR") !== void 0 && getEnvVar("NO_COLOR") !== "" || // The "dumb" special terminal, as defined by terminfo, doesn't support
700
- // ANSI color control codes.
701
- // See https://invisible-island.net/ncurses/terminfo.ti.html#toc-_Specials
702
- getEnvVar("TERM") === "dumb") {
703
- return COLORS_2;
704
- }
705
- if (getEnvVar("TMUX")) {
706
- return COLORS_16m;
707
- }
708
- if ("TF_BUILD" in env && "AGENT_NAME" in env) {
709
- return COLORS_16;
107
+ if (getEnvVar("FORCE_COLOR") !== void 0) switch (getEnvVar("FORCE_COLOR")) {
108
+ case "":
109
+ case "1":
110
+ case "true":
111
+ return COLORS_16;
112
+ case "2":
113
+ return COLORS_256;
114
+ case "3":
115
+ return COLORS_16m;
116
+ default:
117
+ return COLORS_2;
710
118
  }
119
+ if (getEnvVar("NODE_DISABLE_COLORS") !== void 0 && getEnvVar("NODE_DISABLE_COLORS") !== "" || getEnvVar("NO_COLOR") !== void 0 && getEnvVar("NO_COLOR") !== "" || getEnvVar("TERM") === "dumb") return COLORS_2;
120
+ if (getEnvVar("TMUX")) return COLORS_16m;
121
+ if ("TF_BUILD" in env && "AGENT_NAME" in env) return COLORS_16;
711
122
  if ("CI" in env) {
712
- for (const { 0: envName, 1: colors } of CI_ENVS_MAP) {
713
- if (envName in env) {
714
- return colors;
715
- }
716
- }
717
- if (getEnvVar("CI_NAME") === "codeship") {
718
- return COLORS_256;
719
- }
123
+ for (const { 0: envName, 1: colors } of CI_ENVS_MAP) if (envName in env) return colors;
124
+ if (getEnvVar("CI_NAME") === "codeship") return COLORS_256;
720
125
  return COLORS_2;
721
126
  }
722
- if ("TEAMCITY_VERSION" in env) {
723
- return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.exec(
724
- getEnvVar("TEAMCITY_VERSION")
725
- ) !== null ? COLORS_16 : COLORS_2;
726
- }
127
+ if ("TEAMCITY_VERSION" in env) return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.exec(getEnvVar("TEAMCITY_VERSION")) !== null ? COLORS_16 : COLORS_2;
727
128
  switch (getEnvVar("TERM_PROGRAM")) {
728
129
  case "iTerm.app":
729
- if (!getEnvVar("TERM_PROGRAM_VERSION") || /^[0-2]\./.exec(getEnvVar("TERM_PROGRAM_VERSION")) !== null) {
730
- return COLORS_256;
731
- }
130
+ if (!getEnvVar("TERM_PROGRAM_VERSION") || /^[0-2]\./.exec(getEnvVar("TERM_PROGRAM_VERSION")) !== null) return COLORS_256;
732
131
  return COLORS_16m;
733
132
  case "HyperTerm":
734
133
  case "MacTerm":
@@ -736,27 +135,15 @@ function getColorDepth() {
736
135
  case "Apple_Terminal":
737
136
  return COLORS_256;
738
137
  }
739
- if (getEnvVar("COLORTERM") === "truecolor" || getEnvVar("COLORTERM") === "24bit") {
740
- return COLORS_16m;
741
- }
138
+ if (getEnvVar("COLORTERM") === "truecolor" || getEnvVar("COLORTERM") === "24bit") return COLORS_16m;
742
139
  if (getEnvVar("TERM")) {
743
- if (/truecolor/.exec(getEnvVar("TERM")) !== null) {
744
- return COLORS_16m;
745
- }
746
- if (/^xterm-256/.exec(getEnvVar("TERM")) !== null) {
747
- return COLORS_256;
748
- }
140
+ if (/truecolor/.exec(getEnvVar("TERM")) !== null) return COLORS_16m;
141
+ if (/^xterm-256/.exec(getEnvVar("TERM")) !== null) return COLORS_256;
749
142
  const termEnv = getEnvVar("TERM").toLowerCase();
750
- if (TERM_ENVS[termEnv]) {
751
- return TERM_ENVS[termEnv];
752
- }
753
- if (TERM_ENVS_REG_EXP.some((term) => term.exec(termEnv) !== null)) {
754
- return COLORS_16;
755
- }
756
- }
757
- if (getEnvVar("COLORTERM")) {
758
- return COLORS_16;
143
+ if (TERM_ENVS[termEnv]) return TERM_ENVS[termEnv];
144
+ if (TERM_ENVS_REG_EXP.some((term) => term.exec(termEnv) !== null)) return COLORS_16;
759
145
  }
146
+ if (getEnvVar("COLORTERM")) return COLORS_16;
760
147
  return COLORS_2;
761
148
  }
762
149
  var TTY_COLORS = {
@@ -789,9 +176,15 @@ var TTY_COLORS = {
789
176
  white: "\x1B[47m"
790
177
  }
791
178
  };
792
- var levels = ["info", "success", "warn", "error", "debug"];
179
+ var levels = [
180
+ "debug",
181
+ "info",
182
+ "success",
183
+ "warn",
184
+ "error"
185
+ ];
793
186
  function shouldPublishLog(currentLogLevel, logLevel) {
794
- return levels.indexOf(logLevel) <= levels.indexOf(currentLogLevel);
187
+ return levels.indexOf(logLevel) >= levels.indexOf(currentLogLevel);
795
188
  }
796
189
  var levelColors = {
797
190
  info: TTY_COLORS.fg.blue,
@@ -802,41 +195,26 @@ var levelColors = {
802
195
  };
803
196
  var formatMessage = (level, message, colorsEnabled) => {
804
197
  const timestamp = (/* @__PURE__ */ new Date()).toISOString();
805
- if (colorsEnabled) {
806
- return `${TTY_COLORS.dim}${timestamp}${TTY_COLORS.reset} ${levelColors[level]}${level.toUpperCase()}${TTY_COLORS.reset} ${TTY_COLORS.bright}[Better Auth]:${TTY_COLORS.reset} ${message}`;
807
- }
198
+ if (colorsEnabled) return `${TTY_COLORS.dim}${timestamp}${TTY_COLORS.reset} ${levelColors[level]}${level.toUpperCase()}${TTY_COLORS.reset} ${TTY_COLORS.bright}[Better Auth]:${TTY_COLORS.reset} ${message}`;
808
199
  return `${timestamp} ${level.toUpperCase()} [Better Auth]: ${message}`;
809
200
  };
810
201
  var createLogger = (options) => {
811
202
  const enabled = options?.disabled !== true;
812
203
  const logLevel = options?.level ?? "error";
813
- const isDisableColorsSpecified = options?.disableColors !== void 0;
814
- const colorsEnabled = isDisableColorsSpecified ? !options.disableColors : getColorDepth() !== 1;
204
+ const colorsEnabled = options?.disableColors !== void 0 ? !options.disableColors : getColorDepth() !== 1;
815
205
  const LogFunc = (level, message, args = []) => {
816
- if (!enabled || !shouldPublishLog(logLevel, level)) {
817
- return;
818
- }
206
+ if (!enabled || !shouldPublishLog(logLevel, level)) return;
819
207
  const formattedMessage = formatMessage(level, message, colorsEnabled);
820
208
  if (!options || typeof options.log !== "function") {
821
- if (level === "error") {
822
- console.error(formattedMessage, ...args);
823
- } else if (level === "warn") {
824
- console.warn(formattedMessage, ...args);
825
- } else {
826
- console.log(formattedMessage, ...args);
827
- }
209
+ if (level === "error") console.error(formattedMessage, ...args);
210
+ else if (level === "warn") console.warn(formattedMessage, ...args);
211
+ else console.log(formattedMessage, ...args);
828
212
  return;
829
213
  }
830
214
  options.log(level === "success" ? "info" : level, message, ...args);
831
215
  };
832
- const logger2 = Object.fromEntries(
833
- levels.map((level) => [
834
- level,
835
- (...[message, ...args]) => LogFunc(level, message, args)
836
- ])
837
- );
838
216
  return {
839
- ...logger2,
217
+ ...Object.fromEntries(levels.map((level) => [level, (...[message, ...args]) => LogFunc(level, message, args)])),
840
218
  get level() {
841
219
  return logLevel;
842
220
  }
@@ -844,12 +222,15 @@ var createLogger = (options) => {
844
222
  };
845
223
  var logger = createLogger();
846
224
 
847
- // ../../../node_modules/.pnpm/@better-auth+core@1.3.34_@better-auth+utils@0.3.0_@better-fetch+fetch@1.1.18_better-call@1.0._cenebiivepn42iaejxu4tccdyq/node_modules/@better-auth/core/dist/utils/index.mjs
225
+ // ../../../node_modules/.pnpm/@better-auth+core@1.4.10_@better-auth+utils@0.3.0_@better-fetch+fetch@1.1.21_better-call@1.1._s4ptmt7cznbdkhj2rfry3i4hxy/node_modules/@better-auth/core/dist/utils-NloIXYE0.mjs
848
226
  function defineErrorCodes(codes) {
849
227
  return codes;
850
228
  }
229
+ function capitalizeFirstLetter(str) {
230
+ return str.charAt(0).toUpperCase() + str.slice(1);
231
+ }
851
232
 
852
- // ../../../node_modules/.pnpm/@better-auth+core@1.3.34_@better-auth+utils@0.3.0_@better-fetch+fetch@1.1.18_better-call@1.0._cenebiivepn42iaejxu4tccdyq/node_modules/@better-auth/core/dist/error/index.mjs
233
+ // ../../../node_modules/.pnpm/@better-auth+core@1.4.10_@better-auth+utils@0.3.0_@better-fetch+fetch@1.1.21_better-call@1.1._s4ptmt7cznbdkhj2rfry3i4hxy/node_modules/@better-auth/core/dist/error-RtKwr3Pu.mjs
853
234
  var BASE_ERROR_CODES = defineErrorCodes({
854
235
  USER_NOT_FOUND: "User not found",
855
236
  FAILED_TO_CREATE_USER: "Failed to create user",
@@ -875,7 +256,25 @@ var BASE_ERROR_CODES = defineErrorCodes({
875
256
  SESSION_EXPIRED: "Session expired. Re-authenticate to perform this action.",
876
257
  FAILED_TO_UNLINK_LAST_ACCOUNT: "You can't unlink your last account",
877
258
  ACCOUNT_NOT_FOUND: "Account not found",
878
- USER_ALREADY_HAS_PASSWORD: "User already has a password. Provide that to delete the account."
259
+ USER_ALREADY_HAS_PASSWORD: "User already has a password. Provide that to delete the account.",
260
+ CROSS_SITE_NAVIGATION_LOGIN_BLOCKED: "Cross-site navigation login blocked. This request appears to be a CSRF attack.",
261
+ VERIFICATION_EMAIL_NOT_ENABLED: "Verification email isn't enabled",
262
+ EMAIL_ALREADY_VERIFIED: "Email is already verified",
263
+ EMAIL_MISMATCH: "Email mismatch",
264
+ SESSION_NOT_FRESH: "Session is not fresh",
265
+ LINKED_ACCOUNT_ALREADY_EXISTS: "Linked account already exists",
266
+ INVALID_ORIGIN: "Invalid origin",
267
+ INVALID_CALLBACK_URL: "Invalid callbackURL",
268
+ INVALID_REDIRECT_URL: "Invalid redirectURL",
269
+ INVALID_ERROR_CALLBACK_URL: "Invalid errorCallbackURL",
270
+ INVALID_NEW_USER_CALLBACK_URL: "Invalid newUserCallbackURL",
271
+ MISSING_OR_NULL_ORIGIN: "Missing or null Origin",
272
+ CALLBACK_URL_REQUIRED: "callbackURL is required",
273
+ FAILED_TO_CREATE_VERIFICATION: "Unable to create verification",
274
+ FIELD_NOT_ALLOWED: "Field not allowed to be set",
275
+ ASYNC_VALIDATION_NOT_SUPPORTED: "Async validation is not supported",
276
+ VALIDATION_ERROR: "Validation Error",
277
+ MISSING_FIELD: "Field is required"
879
278
  });
880
279
  var BetterAuthError = class extends Error {
881
280
  constructor(message, cause) {
@@ -887,68 +286,165 @@ var BetterAuthError = class extends Error {
887
286
  }
888
287
  };
889
288
 
890
- // ../../../node_modules/.pnpm/better-auth@1.3.34_next@15.1.9_react-dom@19.0.0_react@19.0.0__react@19.0.0__react-dom@19.0.0_react@19.0.0__react@19.0.0/node_modules/better-auth/dist/shared/better-auth.DR3R5wdU.mjs
289
+ // ../../../node_modules/.pnpm/better-auth@1.4.10_drizzle-kit@0.31.8_drizzle-orm@0.45.1_@cloudflare+workers-types@4.20251119_hirg525kbrpwuqvxcih3czaike/node_modules/better-auth/dist/utils/url.mjs
891
290
  function checkHasPath(url) {
291
+ try {
292
+ return (new URL(url).pathname.replace(/\/+$/, "") || "/") !== "/";
293
+ } catch {
294
+ throw new BetterAuthError(`Invalid base URL: ${url}. Please provide a valid base URL.`);
295
+ }
296
+ }
297
+ function assertHasProtocol(url) {
892
298
  try {
893
299
  const parsedUrl = new URL(url);
894
- const pathname = parsedUrl.pathname.replace(/\/+$/, "") || "/";
895
- return pathname !== "/";
300
+ if (parsedUrl.protocol !== "http:" && parsedUrl.protocol !== "https:") throw new BetterAuthError(`Invalid base URL: ${url}. URL must include 'http://' or 'https://'`);
896
301
  } catch (error) {
897
- throw new BetterAuthError(
898
- `Invalid base URL: ${url}. Please provide a valid base URL.`
899
- );
302
+ if (error instanceof BetterAuthError) throw error;
303
+ throw new BetterAuthError(`Invalid base URL: ${url}. Please provide a valid base URL.`, String(error));
900
304
  }
901
305
  }
902
306
  function withPath(url, path = "/api/auth") {
903
- const hasPath = checkHasPath(url);
904
- if (hasPath) {
905
- return url;
906
- }
307
+ assertHasProtocol(url);
308
+ if (checkHasPath(url)) return url;
907
309
  const trimmedUrl = url.replace(/\/+$/, "");
908
- if (!path || path === "/") {
909
- return trimmedUrl;
910
- }
310
+ if (!path || path === "/") return trimmedUrl;
911
311
  path = path.startsWith("/") ? path : `/${path}`;
912
312
  return `${trimmedUrl}${path}`;
913
313
  }
914
- function getBaseURL(url, path, request, loadEnv) {
915
- if (url) {
916
- return withPath(url, path);
917
- }
314
+ function validateProxyHeader(header, type) {
315
+ if (!header || header.trim() === "") return false;
316
+ if (type === "proto") return header === "http" || header === "https";
317
+ if (type === "host") {
318
+ if ([
319
+ /\.\./,
320
+ /\0/,
321
+ /[\s]/,
322
+ /^[.]/,
323
+ /[<>'"]/,
324
+ /javascript:/i,
325
+ /file:/i,
326
+ /data:/i
327
+ ].some((pattern) => pattern.test(header))) return false;
328
+ return /^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*(:[0-9]{1,5})?$/.test(header) || /^(\d{1,3}\.){3}\d{1,3}(:[0-9]{1,5})?$/.test(header) || /^\[[0-9a-fA-F:]+\](:[0-9]{1,5})?$/.test(header) || /^localhost(:[0-9]{1,5})?$/i.test(header);
329
+ }
330
+ return false;
331
+ }
332
+ function getBaseURL(url, path, request, loadEnv, trustedProxyHeaders) {
333
+ if (url) return withPath(url, path);
918
334
  if (loadEnv !== false) {
919
335
  const fromEnv = env.BETTER_AUTH_URL || env.NEXT_PUBLIC_BETTER_AUTH_URL || env.PUBLIC_BETTER_AUTH_URL || env.NUXT_PUBLIC_BETTER_AUTH_URL || env.NUXT_PUBLIC_AUTH_URL || (env.BASE_URL !== "/" ? env.BASE_URL : void 0);
920
- if (fromEnv) {
921
- return withPath(fromEnv, path);
922
- }
336
+ if (fromEnv) return withPath(fromEnv, path);
923
337
  }
924
338
  const fromRequest = request?.headers.get("x-forwarded-host");
925
339
  const fromRequestProto = request?.headers.get("x-forwarded-proto");
926
- if (fromRequest && fromRequestProto) {
927
- return withPath(`${fromRequestProto}://${fromRequest}`, path);
928
- }
929
- if (request) {
930
- const url2 = getOrigin(request.url);
931
- if (!url2) {
932
- throw new BetterAuthError(
933
- "Could not get origin from request. Please provide a valid base URL."
934
- );
340
+ if (fromRequest && fromRequestProto && trustedProxyHeaders) {
341
+ if (validateProxyHeader(fromRequestProto, "proto") && validateProxyHeader(fromRequest, "host")) try {
342
+ return withPath(`${fromRequestProto}://${fromRequest}`, path);
343
+ } catch (_error) {
935
344
  }
936
- return withPath(url2, path);
937
345
  }
938
- if (typeof window !== "undefined" && window.location) {
939
- return withPath(window.location.origin, path);
346
+ if (request) {
347
+ const url$1 = getOrigin(request.url);
348
+ if (!url$1) throw new BetterAuthError("Could not get origin from request. Please provide a valid base URL.");
349
+ return withPath(url$1, path);
940
350
  }
941
- return void 0;
351
+ if (typeof window !== "undefined" && window.location) return withPath(window.location.origin, path);
942
352
  }
943
353
  function getOrigin(url) {
944
354
  try {
945
355
  const parsedUrl = new URL(url);
946
- return parsedUrl.origin;
947
- } catch (error) {
356
+ return parsedUrl.origin === "null" ? null : parsedUrl.origin;
357
+ } catch {
948
358
  return null;
949
359
  }
950
360
  }
951
361
 
362
+ // ../../../node_modules/.pnpm/better-auth@1.4.10_drizzle-kit@0.31.8_drizzle-orm@0.45.1_@cloudflare+workers-types@4.20251119_hirg525kbrpwuqvxcih3czaike/node_modules/better-auth/dist/client/fetch-plugins.mjs
363
+ var redirectPlugin = {
364
+ id: "redirect",
365
+ name: "Redirect",
366
+ hooks: { onSuccess(context) {
367
+ if (context.data?.url && context.data?.redirect) {
368
+ if (typeof window !== "undefined" && window.location) {
369
+ if (window.location) try {
370
+ window.location.href = context.data.url;
371
+ } catch {
372
+ }
373
+ }
374
+ }
375
+ } }
376
+ };
377
+
378
+ // ../../../node_modules/.pnpm/better-auth@1.4.10_drizzle-kit@0.31.8_drizzle-orm@0.45.1_@cloudflare+workers-types@4.20251119_hirg525kbrpwuqvxcih3czaike/node_modules/better-auth/dist/client/parser.mjs
379
+ var PROTO_POLLUTION_PATTERNS = {
380
+ proto: /"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/,
381
+ constructor: /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/,
382
+ protoShort: /"__proto__"\s*:/,
383
+ constructorShort: /"constructor"\s*:/
384
+ };
385
+ var JSON_SIGNATURE = /^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/;
386
+ var SPECIAL_VALUES = {
387
+ true: true,
388
+ false: false,
389
+ null: null,
390
+ undefined: void 0,
391
+ nan: NaN,
392
+ infinity: Number.POSITIVE_INFINITY,
393
+ "-infinity": Number.NEGATIVE_INFINITY
394
+ };
395
+ var ISO_DATE_REGEX = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,7}))?(?:Z|([+-])(\d{2}):(\d{2}))$/;
396
+ function isValidDate(date) {
397
+ return date instanceof Date && !isNaN(date.getTime());
398
+ }
399
+ function parseISODate(value) {
400
+ const match = ISO_DATE_REGEX.exec(value);
401
+ if (!match) return null;
402
+ const [, year, month, day, hour, minute, second, ms, offsetSign, offsetHour, offsetMinute] = match;
403
+ let date = new Date(Date.UTC(parseInt(year, 10), parseInt(month, 10) - 1, parseInt(day, 10), parseInt(hour, 10), parseInt(minute, 10), parseInt(second, 10), ms ? parseInt(ms.padEnd(3, "0"), 10) : 0));
404
+ if (offsetSign) {
405
+ const offset = (parseInt(offsetHour, 10) * 60 + parseInt(offsetMinute, 10)) * (offsetSign === "+" ? -1 : 1);
406
+ date.setUTCMinutes(date.getUTCMinutes() + offset);
407
+ }
408
+ return isValidDate(date) ? date : null;
409
+ }
410
+ function betterJSONParse(value, options = {}) {
411
+ const { strict = false, warnings = false, reviver, parseDates = true } = options;
412
+ if (typeof value !== "string") return value;
413
+ const trimmed = value.trim();
414
+ if (trimmed.length > 0 && trimmed[0] === '"' && trimmed.endsWith('"') && !trimmed.slice(1, -1).includes('"')) return trimmed.slice(1, -1);
415
+ const lowerValue = trimmed.toLowerCase();
416
+ if (lowerValue.length <= 9 && lowerValue in SPECIAL_VALUES) return SPECIAL_VALUES[lowerValue];
417
+ if (!JSON_SIGNATURE.test(trimmed)) {
418
+ if (strict) throw new SyntaxError("[better-json] Invalid JSON");
419
+ return value;
420
+ }
421
+ if (Object.entries(PROTO_POLLUTION_PATTERNS).some(([key, pattern]) => {
422
+ const matches = pattern.test(trimmed);
423
+ if (matches && warnings) console.warn(`[better-json] Detected potential prototype pollution attempt using ${key} pattern`);
424
+ return matches;
425
+ }) && strict) throw new Error("[better-json] Potential prototype pollution attempt detected");
426
+ try {
427
+ const secureReviver = (key, value$1) => {
428
+ if (key === "__proto__" || key === "constructor" && value$1 && typeof value$1 === "object" && "prototype" in value$1) {
429
+ if (warnings) console.warn(`[better-json] Dropping "${key}" key to prevent prototype pollution`);
430
+ return;
431
+ }
432
+ if (parseDates && typeof value$1 === "string") {
433
+ const date = parseISODate(value$1);
434
+ if (date) return date;
435
+ }
436
+ return reviver ? reviver(key, value$1) : value$1;
437
+ };
438
+ return JSON.parse(trimmed, secureReviver);
439
+ } catch (error) {
440
+ if (strict) throw error;
441
+ return value;
442
+ }
443
+ }
444
+ function parseJSON(value, options = { strict: true }) {
445
+ return betterJSONParse(value, options);
446
+ }
447
+
952
448
  // ../../../node_modules/.pnpm/nanostores@1.1.0/node_modules/nanostores/clean-stores/index.js
953
449
  var clean = Symbol("clean");
954
450
 
@@ -1110,257 +606,353 @@ function listenKeys($store, keys, listener) {
1110
606
  });
1111
607
  }
1112
608
 
1113
- // ../../../node_modules/.pnpm/better-auth@1.3.34_next@15.1.9_react-dom@19.0.0_react@19.0.0__react@19.0.0__react-dom@19.0.0_react@19.0.0__react@19.0.0/node_modules/better-auth/dist/shared/better-auth.BYWGbmZ5.mjs
1114
- var isServer = typeof window === "undefined";
609
+ // ../../../node_modules/.pnpm/better-auth@1.4.10_drizzle-kit@0.31.8_drizzle-orm@0.45.1_@cloudflare+workers-types@4.20251119_hirg525kbrpwuqvxcih3czaike/node_modules/better-auth/dist/client/query.mjs
610
+ var isServer = () => typeof window === "undefined";
1115
611
  var useAuthQuery = (initializedAtom, path, $fetch, options) => {
1116
612
  const value = atom({
1117
613
  data: null,
1118
614
  error: null,
1119
615
  isPending: true,
1120
616
  isRefetching: false,
1121
- refetch: (queryParams) => {
1122
- return fn(queryParams);
1123
- }
617
+ refetch: (queryParams) => fn(queryParams)
1124
618
  });
1125
- const fn = (queryParams) => {
1126
- const opts = typeof options === "function" ? options({
1127
- data: value.get().data,
1128
- error: value.get().error,
1129
- isPending: value.get().isPending
1130
- }) : options;
1131
- $fetch(path, {
1132
- ...opts,
1133
- query: {
1134
- ...opts?.query,
1135
- ...queryParams?.query
1136
- },
1137
- async onSuccess(context) {
1138
- value.set({
1139
- data: context.data,
1140
- error: null,
1141
- isPending: false,
1142
- isRefetching: false,
1143
- refetch: value.value.refetch
1144
- });
1145
- await opts?.onSuccess?.(context);
1146
- },
1147
- async onError(context) {
1148
- const { request } = context;
1149
- const retryAttempts = typeof request.retry === "number" ? request.retry : request.retry?.attempts;
1150
- const retryAttempt = request.retryAttempt || 0;
1151
- if (retryAttempts && retryAttempt < retryAttempts) return;
619
+ const fn = async (queryParams) => {
620
+ return new Promise((resolve) => {
621
+ const opts = typeof options === "function" ? options({
622
+ data: value.get().data,
623
+ error: value.get().error,
624
+ isPending: value.get().isPending
625
+ }) : options;
626
+ $fetch(path, {
627
+ ...opts,
628
+ query: {
629
+ ...opts?.query,
630
+ ...queryParams?.query
631
+ },
632
+ async onSuccess(context) {
633
+ value.set({
634
+ data: context.data,
635
+ error: null,
636
+ isPending: false,
637
+ isRefetching: false,
638
+ refetch: value.value.refetch
639
+ });
640
+ await opts?.onSuccess?.(context);
641
+ },
642
+ async onError(context) {
643
+ const { request } = context;
644
+ const retryAttempts = typeof request.retry === "number" ? request.retry : request.retry?.attempts;
645
+ const retryAttempt = request.retryAttempt || 0;
646
+ if (retryAttempts && retryAttempt < retryAttempts) return;
647
+ value.set({
648
+ error: context.error,
649
+ data: null,
650
+ isPending: false,
651
+ isRefetching: false,
652
+ refetch: value.value.refetch
653
+ });
654
+ await opts?.onError?.(context);
655
+ },
656
+ async onRequest(context) {
657
+ const currentValue = value.get();
658
+ value.set({
659
+ isPending: currentValue.data === null,
660
+ data: currentValue.data,
661
+ error: null,
662
+ isRefetching: true,
663
+ refetch: value.value.refetch
664
+ });
665
+ await opts?.onRequest?.(context);
666
+ }
667
+ }).catch((error) => {
1152
668
  value.set({
1153
- error: context.error,
669
+ error,
1154
670
  data: null,
1155
671
  isPending: false,
1156
672
  isRefetching: false,
1157
673
  refetch: value.value.refetch
1158
674
  });
1159
- await opts?.onError?.(context);
1160
- },
1161
- async onRequest(context) {
1162
- const currentValue = value.get();
1163
- value.set({
1164
- isPending: currentValue.data === null,
1165
- data: currentValue.data,
1166
- error: null,
1167
- isRefetching: true,
1168
- refetch: value.value.refetch
1169
- });
1170
- await opts?.onRequest?.(context);
1171
- }
1172
- }).catch((error) => {
1173
- value.set({
1174
- error,
1175
- data: null,
1176
- isPending: false,
1177
- isRefetching: false,
1178
- refetch: value.value.refetch
675
+ }).finally(() => {
676
+ resolve(void 0);
1179
677
  });
1180
678
  });
1181
679
  };
1182
680
  initializedAtom = Array.isArray(initializedAtom) ? initializedAtom : [initializedAtom];
1183
681
  let isMounted = false;
1184
- for (const initAtom of initializedAtom) {
1185
- initAtom.subscribe(() => {
1186
- if (isServer) {
1187
- return;
1188
- }
1189
- if (isMounted) {
1190
- fn();
1191
- } else {
1192
- onMount(value, () => {
1193
- const timeoutId = setTimeout(() => {
1194
- if (!isMounted) {
1195
- fn();
1196
- isMounted = true;
1197
- }
1198
- }, 0);
1199
- return () => {
1200
- value.off();
1201
- initAtom.off();
1202
- clearTimeout(timeoutId);
1203
- };
1204
- });
1205
- }
682
+ for (const initAtom of initializedAtom) initAtom.subscribe(async () => {
683
+ if (isServer()) return;
684
+ if (isMounted) await fn();
685
+ else onMount(value, () => {
686
+ const timeoutId = setTimeout(async () => {
687
+ if (!isMounted) {
688
+ await fn();
689
+ isMounted = true;
690
+ }
691
+ }, 0);
692
+ return () => {
693
+ value.off();
694
+ initAtom.off();
695
+ clearTimeout(timeoutId);
696
+ };
1206
697
  });
1207
- }
698
+ });
1208
699
  return value;
1209
700
  };
1210
701
 
1211
- // ../../../node_modules/.pnpm/better-auth@1.3.34_next@15.1.9_react-dom@19.0.0_react@19.0.0__react@19.0.0__react-dom@19.0.0_react@19.0.0__react@19.0.0/node_modules/better-auth/dist/shared/better-auth.msGOU0m9.mjs
1212
- var PROTO_POLLUTION_PATTERNS = {
1213
- proto: /"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/,
1214
- constructor: /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/,
1215
- protoShort: /"__proto__"\s*:/,
1216
- constructorShort: /"constructor"\s*:/
1217
- };
1218
- var JSON_SIGNATURE = /^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/;
1219
- var SPECIAL_VALUES = {
1220
- true: true,
1221
- false: false,
1222
- null: null,
1223
- undefined: void 0,
1224
- nan: Number.NaN,
1225
- infinity: Number.POSITIVE_INFINITY,
1226
- "-infinity": Number.NEGATIVE_INFINITY
1227
- };
1228
- var ISO_DATE_REGEX = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,7}))?(?:Z|([+-])(\d{2}):(\d{2}))$/;
1229
- function isValidDate(date) {
1230
- return date instanceof Date && !isNaN(date.getTime());
1231
- }
1232
- function parseISODate(value) {
1233
- const match = ISO_DATE_REGEX.exec(value);
1234
- if (!match) return null;
1235
- const [
1236
- ,
1237
- year,
1238
- month,
1239
- day,
1240
- hour,
1241
- minute,
1242
- second,
1243
- ms,
1244
- offsetSign,
1245
- offsetHour,
1246
- offsetMinute
1247
- ] = match;
1248
- let date = new Date(
1249
- Date.UTC(
1250
- parseInt(year, 10),
1251
- parseInt(month, 10) - 1,
1252
- parseInt(day, 10),
1253
- parseInt(hour, 10),
1254
- parseInt(minute, 10),
1255
- parseInt(second, 10),
1256
- ms ? parseInt(ms.padEnd(3, "0"), 10) : 0
1257
- )
1258
- );
1259
- if (offsetSign) {
1260
- const offset = (parseInt(offsetHour, 10) * 60 + parseInt(offsetMinute, 10)) * (offsetSign === "+" ? -1 : 1);
1261
- date.setUTCMinutes(date.getUTCMinutes() + offset);
702
+ // ../../../node_modules/.pnpm/better-auth@1.4.10_drizzle-kit@0.31.8_drizzle-orm@0.45.1_@cloudflare+workers-types@4.20251119_hirg525kbrpwuqvxcih3czaike/node_modules/better-auth/dist/client/broadcast-channel.mjs
703
+ var kBroadcastChannel = Symbol.for("better-auth:broadcast-channel");
704
+ var now = () => Math.floor(Date.now() / 1e3);
705
+ var WindowBroadcastChannel = class {
706
+ constructor(name = "better-auth.message") {
707
+ __publicField(this, "listeners", /* @__PURE__ */ new Set());
708
+ __publicField(this, "name");
709
+ this.name = name;
710
+ }
711
+ subscribe(listener) {
712
+ this.listeners.add(listener);
713
+ return () => {
714
+ this.listeners.delete(listener);
715
+ };
1262
716
  }
1263
- return isValidDate(date) ? date : null;
717
+ post(message) {
718
+ if (typeof window === "undefined") return;
719
+ try {
720
+ localStorage.setItem(this.name, JSON.stringify({
721
+ ...message,
722
+ timestamp: now()
723
+ }));
724
+ } catch {
725
+ }
726
+ }
727
+ setup() {
728
+ if (typeof window === "undefined" || typeof window.addEventListener === "undefined") return () => {
729
+ };
730
+ const handler = (event) => {
731
+ if (event.key !== this.name) return;
732
+ const message = JSON.parse(event.newValue ?? "{}");
733
+ if (message?.event !== "session" || !message?.data) return;
734
+ this.listeners.forEach((listener) => listener(message));
735
+ };
736
+ window.addEventListener("storage", handler);
737
+ return () => {
738
+ window.removeEventListener("storage", handler);
739
+ };
740
+ }
741
+ };
742
+ function getGlobalBroadcastChannel(name = "better-auth.message") {
743
+ if (!globalThis[kBroadcastChannel]) globalThis[kBroadcastChannel] = new WindowBroadcastChannel(name);
744
+ return globalThis[kBroadcastChannel];
1264
745
  }
1265
- function betterJSONParse(value, options = {}) {
1266
- const {
1267
- strict = false,
1268
- warnings = false,
1269
- reviver,
1270
- parseDates = true
1271
- } = options;
1272
- if (typeof value !== "string") {
1273
- return value;
746
+
747
+ // ../../../node_modules/.pnpm/better-auth@1.4.10_drizzle-kit@0.31.8_drizzle-orm@0.45.1_@cloudflare+workers-types@4.20251119_hirg525kbrpwuqvxcih3czaike/node_modules/better-auth/dist/client/focus-manager.mjs
748
+ var kFocusManager = Symbol.for("better-auth:focus-manager");
749
+ var WindowFocusManager = class {
750
+ constructor() {
751
+ __publicField(this, "listeners", /* @__PURE__ */ new Set());
752
+ }
753
+ subscribe(listener) {
754
+ this.listeners.add(listener);
755
+ return () => {
756
+ this.listeners.delete(listener);
757
+ };
1274
758
  }
1275
- const trimmed = value.trim();
1276
- if (trimmed.length > 0 && trimmed[0] === '"' && trimmed.endsWith('"') && !trimmed.slice(1, -1).includes('"')) {
1277
- return trimmed.slice(1, -1);
759
+ setFocused(focused) {
760
+ this.listeners.forEach((listener) => listener(focused));
1278
761
  }
1279
- const lowerValue = trimmed.toLowerCase();
1280
- if (lowerValue.length <= 9 && lowerValue in SPECIAL_VALUES) {
1281
- return SPECIAL_VALUES[lowerValue];
762
+ setup() {
763
+ if (typeof window === "undefined" || typeof document === "undefined" || typeof window.addEventListener === "undefined") return () => {
764
+ };
765
+ const visibilityHandler = () => {
766
+ if (document.visibilityState === "visible") this.setFocused(true);
767
+ };
768
+ document.addEventListener("visibilitychange", visibilityHandler, false);
769
+ return () => {
770
+ document.removeEventListener("visibilitychange", visibilityHandler, false);
771
+ };
1282
772
  }
1283
- if (!JSON_SIGNATURE.test(trimmed)) {
1284
- if (strict) {
1285
- throw new SyntaxError("[better-json] Invalid JSON");
1286
- }
1287
- return value;
773
+ };
774
+ function getGlobalFocusManager() {
775
+ if (!globalThis[kFocusManager]) globalThis[kFocusManager] = new WindowFocusManager();
776
+ return globalThis[kFocusManager];
777
+ }
778
+
779
+ // ../../../node_modules/.pnpm/better-auth@1.4.10_drizzle-kit@0.31.8_drizzle-orm@0.45.1_@cloudflare+workers-types@4.20251119_hirg525kbrpwuqvxcih3czaike/node_modules/better-auth/dist/client/online-manager.mjs
780
+ var kOnlineManager = Symbol.for("better-auth:online-manager");
781
+ var WindowOnlineManager = class {
782
+ constructor() {
783
+ __publicField(this, "listeners", /* @__PURE__ */ new Set());
784
+ __publicField(this, "isOnline", typeof navigator !== "undefined" ? navigator.onLine : true);
785
+ }
786
+ subscribe(listener) {
787
+ this.listeners.add(listener);
788
+ return () => {
789
+ this.listeners.delete(listener);
790
+ };
1288
791
  }
1289
- const hasProtoPattern = Object.entries(PROTO_POLLUTION_PATTERNS).some(
1290
- ([key, pattern]) => {
1291
- const matches = pattern.test(trimmed);
1292
- if (matches && warnings) {
1293
- console.warn(
1294
- `[better-json] Detected potential prototype pollution attempt using ${key} pattern`
1295
- );
1296
- }
1297
- return matches;
1298
- }
1299
- );
1300
- if (hasProtoPattern && strict) {
1301
- throw new Error(
1302
- "[better-json] Potential prototype pollution attempt detected"
1303
- );
792
+ setOnline(online) {
793
+ this.isOnline = online;
794
+ this.listeners.forEach((listener) => listener(online));
1304
795
  }
1305
- try {
1306
- const secureReviver = (key, value2) => {
1307
- if (key === "__proto__" || key === "constructor" && value2 && typeof value2 === "object" && "prototype" in value2) {
1308
- if (warnings) {
1309
- console.warn(
1310
- `[better-json] Dropping "${key}" key to prevent prototype pollution`
1311
- );
1312
- }
1313
- return void 0;
1314
- }
1315
- if (parseDates && typeof value2 === "string") {
1316
- const date = parseISODate(value2);
1317
- if (date) {
1318
- return date;
1319
- }
1320
- }
1321
- return reviver ? reviver(key, value2) : value2;
796
+ setup() {
797
+ if (typeof window === "undefined" || typeof window.addEventListener === "undefined") return () => {
798
+ };
799
+ const onOnline = () => this.setOnline(true);
800
+ const onOffline = () => this.setOnline(false);
801
+ window.addEventListener("online", onOnline, false);
802
+ window.addEventListener("offline", onOffline, false);
803
+ return () => {
804
+ window.removeEventListener("online", onOnline, false);
805
+ window.removeEventListener("offline", onOffline, false);
1322
806
  };
1323
- return JSON.parse(trimmed, secureReviver);
1324
- } catch (error) {
1325
- if (strict) {
1326
- throw error;
1327
- }
1328
- return value;
1329
807
  }
1330
- }
1331
- function parseJSON(value, options = { strict: true }) {
1332
- return betterJSONParse(value, options);
808
+ };
809
+ function getGlobalOnlineManager() {
810
+ if (!globalThis[kOnlineManager]) globalThis[kOnlineManager] = new WindowOnlineManager();
811
+ return globalThis[kOnlineManager];
1333
812
  }
1334
813
 
1335
- // ../../../node_modules/.pnpm/better-auth@1.3.34_next@15.1.9_react-dom@19.0.0_react@19.0.0__react@19.0.0__react-dom@19.0.0_react@19.0.0__react@19.0.0/node_modules/better-auth/dist/shared/better-auth.RKafzlkP.mjs
1336
- var redirectPlugin = {
1337
- id: "redirect",
1338
- name: "Redirect",
1339
- hooks: {
1340
- onSuccess(context) {
1341
- if (context.data?.url && context.data?.redirect) {
1342
- if (typeof window !== "undefined" && window.location) {
1343
- if (window.location) {
1344
- try {
1345
- window.location.href = context.data.url;
1346
- } catch {
1347
- }
1348
- }
1349
- }
1350
- }
814
+ // ../../../node_modules/.pnpm/better-auth@1.4.10_drizzle-kit@0.31.8_drizzle-orm@0.45.1_@cloudflare+workers-types@4.20251119_hirg525kbrpwuqvxcih3czaike/node_modules/better-auth/dist/client/session-refresh.mjs
815
+ var now2 = () => Math.floor(Date.now() / 1e3);
816
+ var FOCUS_REFETCH_RATE_LIMIT_SECONDS = 5;
817
+ function createSessionRefreshManager(opts) {
818
+ const { sessionAtom, sessionSignal, $fetch, options = {} } = opts;
819
+ const refetchInterval = options.sessionOptions?.refetchInterval ?? 0;
820
+ const refetchOnWindowFocus = options.sessionOptions?.refetchOnWindowFocus ?? true;
821
+ const refetchWhenOffline = options.sessionOptions?.refetchWhenOffline ?? false;
822
+ const state = {
823
+ lastSync: 0,
824
+ lastSessionRequest: 0,
825
+ cachedSession: void 0
826
+ };
827
+ const shouldRefetch = () => {
828
+ return refetchWhenOffline || getGlobalOnlineManager().isOnline;
829
+ };
830
+ const triggerRefetch = (event) => {
831
+ if (!shouldRefetch()) return;
832
+ if (event?.event === "storage") {
833
+ state.lastSync = now2();
834
+ sessionSignal.set(!sessionSignal.get());
835
+ return;
1351
836
  }
1352
- }
1353
- };
1354
- function getSessionAtom($fetch) {
837
+ const currentSession = sessionAtom.get();
838
+ if (event?.event === "poll") {
839
+ state.lastSessionRequest = now2();
840
+ $fetch("/get-session").then((res) => {
841
+ if (res.error) sessionAtom.set({
842
+ ...currentSession,
843
+ data: null,
844
+ error: res.error
845
+ });
846
+ else sessionAtom.set({
847
+ ...currentSession,
848
+ data: res.data,
849
+ error: null
850
+ });
851
+ state.lastSync = now2();
852
+ sessionSignal.set(!sessionSignal.get());
853
+ }).catch(() => {
854
+ });
855
+ return;
856
+ }
857
+ if (event?.event === "visibilitychange") {
858
+ if (now2() - state.lastSessionRequest < FOCUS_REFETCH_RATE_LIMIT_SECONDS) return;
859
+ state.lastSessionRequest = now2();
860
+ }
861
+ if (currentSession?.data === null || currentSession?.data === void 0 || event?.event === "visibilitychange") {
862
+ state.lastSync = now2();
863
+ sessionSignal.set(!sessionSignal.get());
864
+ }
865
+ };
866
+ const broadcastSessionUpdate = (trigger) => {
867
+ getGlobalBroadcastChannel().post({
868
+ event: "session",
869
+ data: { trigger },
870
+ clientId: Math.random().toString(36).substring(7)
871
+ });
872
+ };
873
+ const setupPolling = () => {
874
+ if (refetchInterval && refetchInterval > 0) state.pollInterval = setInterval(() => {
875
+ if (sessionAtom.get()?.data) triggerRefetch({ event: "poll" });
876
+ }, refetchInterval * 1e3);
877
+ };
878
+ const setupBroadcast = () => {
879
+ state.unsubscribeBroadcast = getGlobalBroadcastChannel().subscribe(() => {
880
+ triggerRefetch({ event: "storage" });
881
+ });
882
+ };
883
+ const setupFocusRefetch = () => {
884
+ if (!refetchOnWindowFocus) return;
885
+ state.unsubscribeFocus = getGlobalFocusManager().subscribe(() => {
886
+ triggerRefetch({ event: "visibilitychange" });
887
+ });
888
+ };
889
+ const setupOnlineRefetch = () => {
890
+ state.unsubscribeOnline = getGlobalOnlineManager().subscribe((online) => {
891
+ if (online) triggerRefetch({ event: "visibilitychange" });
892
+ });
893
+ };
894
+ const init = () => {
895
+ setupPolling();
896
+ setupBroadcast();
897
+ setupFocusRefetch();
898
+ setupOnlineRefetch();
899
+ getGlobalBroadcastChannel().setup();
900
+ getGlobalFocusManager().setup();
901
+ getGlobalOnlineManager().setup();
902
+ };
903
+ const cleanup = () => {
904
+ if (state.pollInterval) {
905
+ clearInterval(state.pollInterval);
906
+ state.pollInterval = void 0;
907
+ }
908
+ if (state.unsubscribeBroadcast) {
909
+ state.unsubscribeBroadcast();
910
+ state.unsubscribeBroadcast = void 0;
911
+ }
912
+ if (state.unsubscribeFocus) {
913
+ state.unsubscribeFocus();
914
+ state.unsubscribeFocus = void 0;
915
+ }
916
+ if (state.unsubscribeOnline) {
917
+ state.unsubscribeOnline();
918
+ state.unsubscribeOnline = void 0;
919
+ }
920
+ state.lastSync = 0;
921
+ state.lastSessionRequest = 0;
922
+ state.cachedSession = void 0;
923
+ };
924
+ return {
925
+ init,
926
+ cleanup,
927
+ triggerRefetch,
928
+ broadcastSessionUpdate
929
+ };
930
+ }
931
+
932
+ // ../../../node_modules/.pnpm/better-auth@1.4.10_drizzle-kit@0.31.8_drizzle-orm@0.45.1_@cloudflare+workers-types@4.20251119_hirg525kbrpwuqvxcih3czaike/node_modules/better-auth/dist/client/session-atom.mjs
933
+ function getSessionAtom($fetch, options) {
1355
934
  const $signal = atom(false);
1356
- const session = useAuthQuery($signal, "/get-session", $fetch, {
1357
- method: "GET"
935
+ const session = useAuthQuery($signal, "/get-session", $fetch, { method: "GET" });
936
+ onMount(session, () => {
937
+ const refreshManager = createSessionRefreshManager({
938
+ sessionAtom: session,
939
+ sessionSignal: $signal,
940
+ $fetch,
941
+ options
942
+ });
943
+ refreshManager.init();
944
+ return () => {
945
+ refreshManager.cleanup();
946
+ };
1358
947
  });
1359
948
  return {
1360
949
  session,
1361
950
  $sessionSignal: $signal
1362
951
  };
1363
952
  }
953
+
954
+ // ../../../node_modules/.pnpm/better-auth@1.4.10_drizzle-kit@0.31.8_drizzle-orm@0.45.1_@cloudflare+workers-types@4.20251119_hirg525kbrpwuqvxcih3czaike/node_modules/better-auth/dist/client/config.mjs
955
+ import { createFetch } from "@better-fetch/fetch";
1364
956
  var getClientConfig = (options, loadEnv) => {
1365
957
  const isCredentialsSupported = "credentials" in Request.prototype;
1366
958
  const baseURL = getBaseURL(options?.baseURL, options?.basePath, void 0, loadEnv) ?? "/api/auth";
@@ -1375,18 +967,14 @@ var getClientConfig = (options, loadEnv) => {
1375
967
  onResponse: options?.fetchOptions?.onResponse
1376
968
  }
1377
969
  };
1378
- const { onSuccess, onError, onRequest, onResponse, ...restOfFetchOptions } = options?.fetchOptions || {};
970
+ const { onSuccess: _onSuccess, onError: _onError, onRequest: _onRequest, onResponse: _onResponse, ...restOfFetchOptions } = options?.fetchOptions || {};
1379
971
  const $fetch = createFetch({
1380
972
  baseURL,
1381
973
  ...isCredentialsSupported ? { credentials: "include" } : {},
1382
974
  method: "GET",
1383
975
  jsonParser(text) {
1384
- if (!text) {
1385
- return null;
1386
- }
1387
- return parseJSON(text, {
1388
- strict: false
1389
- });
976
+ if (!text) return null;
977
+ return parseJSON(text, { strict: false });
1390
978
  },
1391
979
  customFetchImpl: fetch,
1392
980
  ...restOfFetchOptions,
@@ -1397,7 +985,7 @@ var getClientConfig = (options, loadEnv) => {
1397
985
  ...pluginsFetchPlugins
1398
986
  ]
1399
987
  });
1400
- const { $sessionSignal, session } = getSessionAtom($fetch);
988
+ const { $sessionSignal, session } = getSessionAtom($fetch, options);
1401
989
  const plugins = options?.plugins || [];
1402
990
  let pluginsActions = {};
1403
991
  let pluginsAtoms = {
@@ -1410,44 +998,27 @@ var getClientConfig = (options, loadEnv) => {
1410
998
  "/revoke-other-sessions": "POST",
1411
999
  "/delete-user": "POST"
1412
1000
  };
1413
- const atomListeners = [
1414
- {
1415
- signal: "$sessionSignal",
1416
- matcher(path) {
1417
- return path === "/sign-out" || path === "/update-user" || path.startsWith("/sign-in") || path.startsWith("/sign-up") || path === "/delete-user" || path === "/verify-email";
1418
- }
1001
+ const atomListeners = [{
1002
+ signal: "$sessionSignal",
1003
+ matcher(path) {
1004
+ return path === "/sign-out" || path === "/update-user" || path === "/sign-up/email" || path === "/sign-in/email" || path === "/delete-user" || path === "/verify-email" || path === "/revoke-sessions" || path === "/revoke-session" || path === "/change-email";
1419
1005
  }
1420
- ];
1006
+ }];
1421
1007
  for (const plugin of plugins) {
1422
- if (plugin.getAtoms) {
1423
- Object.assign(pluginsAtoms, plugin.getAtoms?.($fetch));
1424
- }
1425
- if (plugin.pathMethods) {
1426
- Object.assign(pluginPathMethods, plugin.pathMethods);
1427
- }
1428
- if (plugin.atomListeners) {
1429
- atomListeners.push(...plugin.atomListeners);
1430
- }
1008
+ if (plugin.getAtoms) Object.assign(pluginsAtoms, plugin.getAtoms?.($fetch));
1009
+ if (plugin.pathMethods) Object.assign(pluginPathMethods, plugin.pathMethods);
1010
+ if (plugin.atomListeners) atomListeners.push(...plugin.atomListeners);
1431
1011
  }
1432
1012
  const $store = {
1433
1013
  notify: (signal) => {
1434
- pluginsAtoms[signal].set(
1435
- !pluginsAtoms[signal].get()
1436
- );
1014
+ pluginsAtoms[signal].set(!pluginsAtoms[signal].get());
1437
1015
  },
1438
1016
  listen: (signal, listener) => {
1439
1017
  pluginsAtoms[signal].subscribe(listener);
1440
1018
  },
1441
1019
  atoms: pluginsAtoms
1442
1020
  };
1443
- for (const plugin of plugins) {
1444
- if (plugin.getActions) {
1445
- Object.assign(
1446
- pluginsActions,
1447
- plugin.getActions?.($fetch, $store, options)
1448
- );
1449
- }
1450
- }
1021
+ for (const plugin of plugins) if (plugin.getActions) Object.assign(pluginsActions, plugin.getActions?.($fetch, $store, options));
1451
1022
  return {
1452
1023
  get baseURL() {
1453
1024
  return baseURL;
@@ -1460,21 +1031,19 @@ var getClientConfig = (options, loadEnv) => {
1460
1031
  $store
1461
1032
  };
1462
1033
  };
1034
+
1035
+ // ../../../node_modules/.pnpm/better-auth@1.4.10_drizzle-kit@0.31.8_drizzle-orm@0.45.1_@cloudflare+workers-types@4.20251119_hirg525kbrpwuqvxcih3czaike/node_modules/better-auth/dist/utils/is-atom.mjs
1463
1036
  function isAtom(value) {
1464
1037
  return typeof value === "object" && value !== null && "get" in value && typeof value.get === "function" && "lc" in value && typeof value.lc === "number";
1465
1038
  }
1466
- function getMethod2(path, knownPathMethods, args) {
1039
+
1040
+ // ../../../node_modules/.pnpm/better-auth@1.4.10_drizzle-kit@0.31.8_drizzle-orm@0.45.1_@cloudflare+workers-types@4.20251119_hirg525kbrpwuqvxcih3czaike/node_modules/better-auth/dist/client/proxy.mjs
1041
+ function getMethod(path, knownPathMethods, args) {
1467
1042
  const method = knownPathMethods[path];
1468
- const { fetchOptions, query, ...body } = args || {};
1469
- if (method) {
1470
- return method;
1471
- }
1472
- if (fetchOptions?.method) {
1473
- return fetchOptions.method;
1474
- }
1475
- if (body && Object.keys(body).length > 0) {
1476
- return "POST";
1477
- }
1043
+ const { fetchOptions, query: _query, ...body } = args || {};
1044
+ if (method) return method;
1045
+ if (fetchOptions?.method) return fetchOptions.method;
1046
+ if (body && Object.keys(body).length > 0) return "POST";
1478
1047
  return "GET";
1479
1048
  }
1480
1049
  function createDynamicPathProxy(routes, client, knownPathMethods, atoms, atomListeners) {
@@ -1482,34 +1051,21 @@ function createDynamicPathProxy(routes, client, knownPathMethods, atoms, atomLis
1482
1051
  return new Proxy(function() {
1483
1052
  }, {
1484
1053
  get(_, prop) {
1485
- if (typeof prop !== "string") {
1486
- return void 0;
1487
- }
1488
- if (prop === "then" || prop === "catch" || prop === "finally") {
1489
- return void 0;
1490
- }
1054
+ if (typeof prop !== "string") return;
1055
+ if (prop === "then" || prop === "catch" || prop === "finally") return;
1491
1056
  const fullPath = [...path, prop];
1492
1057
  let current = routes;
1493
- for (const segment of fullPath) {
1494
- if (current && typeof current === "object" && segment in current) {
1495
- current = current[segment];
1496
- } else {
1497
- current = void 0;
1498
- break;
1499
- }
1500
- }
1501
- if (typeof current === "function") {
1502
- return current;
1503
- }
1504
- if (isAtom(current)) {
1505
- return current;
1058
+ for (const segment of fullPath) if (current && typeof current === "object" && segment in current) current = current[segment];
1059
+ else {
1060
+ current = void 0;
1061
+ break;
1506
1062
  }
1063
+ if (typeof current === "function") return current;
1064
+ if (isAtom(current)) return current;
1507
1065
  return createProxy(fullPath);
1508
1066
  },
1509
1067
  apply: async (_, __, args) => {
1510
- const routePath = "/" + path.map(
1511
- (segment) => segment.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`)
1512
- ).join("/");
1068
+ const routePath = "/" + path.map((segment) => segment.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`)).join("/");
1513
1069
  const arg = args[0] || {};
1514
1070
  const fetchOptions = args[1] || {};
1515
1071
  const { query, fetchOptions: argFetchOptions, ...body } = arg;
@@ -1517,7 +1073,7 @@ function createDynamicPathProxy(routes, client, knownPathMethods, atoms, atomLis
1517
1073
  ...fetchOptions,
1518
1074
  ...argFetchOptions
1519
1075
  };
1520
- const method = getMethod2(routePath, knownPathMethods, arg);
1076
+ const method = getMethod(routePath, knownPathMethods, arg);
1521
1077
  return await client(routePath, {
1522
1078
  ...options,
1523
1079
  body: method === "GET" ? void 0 : {
@@ -1528,12 +1084,15 @@ function createDynamicPathProxy(routes, client, knownPathMethods, atoms, atomLis
1528
1084
  method,
1529
1085
  async onSuccess(context) {
1530
1086
  await options?.onSuccess?.(context);
1531
- if (!atomListeners) return;
1087
+ if (!atomListeners || options.disableSignal) return;
1532
1088
  const matches = atomListeners.filter((s) => s.matcher(routePath));
1533
1089
  if (!matches.length) return;
1090
+ const visited = /* @__PURE__ */ new Set();
1534
1091
  for (const match of matches) {
1535
1092
  const signal = atoms[match.signal];
1536
1093
  if (!signal) return;
1094
+ if (visited.has(match.signal)) continue;
1095
+ visited.add(match.signal);
1537
1096
  const val = signal.get();
1538
1097
  setTimeout(() => {
1539
1098
  signal.set(!val);
@@ -1547,8 +1106,8 @@ function createDynamicPathProxy(routes, client, knownPathMethods, atoms, atomLis
1547
1106
  return createProxy();
1548
1107
  }
1549
1108
 
1550
- // ../../../node_modules/.pnpm/better-auth@1.3.34_next@15.1.9_react-dom@19.0.0_react@19.0.0__react@19.0.0__react-dom@19.0.0_react@19.0.0__react@19.0.0/node_modules/better-auth/dist/client/react/index.mjs
1551
- import { useRef, useCallback, useSyncExternalStore } from "react";
1109
+ // ../../../node_modules/.pnpm/better-auth@1.4.10_drizzle-kit@0.31.8_drizzle-orm@0.45.1_@cloudflare+workers-types@4.20251119_hirg525kbrpwuqvxcih3czaike/node_modules/better-auth/dist/client/react/react-store.mjs
1110
+ import { useCallback, useRef, useSyncExternalStore } from "react";
1552
1111
  function useStore(store, options = {}) {
1553
1112
  let snapshotRef = useRef(store.get());
1554
1113
  const { keys, deps = [store, keys] } = options;
@@ -1559,47 +1118,27 @@ function useStore(store, options = {}) {
1559
1118
  onChange();
1560
1119
  };
1561
1120
  emitChange(store.value);
1562
- if (keys?.length) {
1563
- return listenKeys(store, keys, emitChange);
1564
- }
1121
+ if (keys?.length) return listenKeys(store, keys, emitChange);
1565
1122
  return store.listen(emitChange);
1566
1123
  }, deps);
1567
1124
  let get = () => snapshotRef.current;
1568
1125
  return useSyncExternalStore(subscribe, get, get);
1569
1126
  }
1127
+
1128
+ // ../../../node_modules/.pnpm/better-auth@1.4.10_drizzle-kit@0.31.8_drizzle-orm@0.45.1_@cloudflare+workers-types@4.20251119_hirg525kbrpwuqvxcih3czaike/node_modules/better-auth/dist/client/react/index.mjs
1570
1129
  function getAtomKey(str) {
1571
1130
  return `use${capitalizeFirstLetter(str)}`;
1572
1131
  }
1573
- function capitalizeFirstLetter(str) {
1574
- return str.charAt(0).toUpperCase() + str.slice(1);
1575
- }
1576
1132
  function createAuthClient(options) {
1577
- const {
1578
- pluginPathMethods,
1579
- pluginsActions,
1580
- pluginsAtoms,
1581
- $fetch,
1582
- $store,
1583
- atomListeners
1584
- } = getClientConfig(options);
1133
+ const { pluginPathMethods, pluginsActions, pluginsAtoms, $fetch, $store, atomListeners } = getClientConfig(options);
1585
1134
  let resolvedHooks = {};
1586
- for (const [key, value] of Object.entries(pluginsAtoms)) {
1587
- resolvedHooks[getAtomKey(key)] = () => useStore(value);
1588
- }
1589
- const routes = {
1135
+ for (const [key, value] of Object.entries(pluginsAtoms)) resolvedHooks[getAtomKey(key)] = () => useStore(value);
1136
+ return createDynamicPathProxy({
1590
1137
  ...pluginsActions,
1591
1138
  ...resolvedHooks,
1592
1139
  $fetch,
1593
1140
  $store
1594
- };
1595
- const proxy = createDynamicPathProxy(
1596
- routes,
1597
- $fetch,
1598
- pluginPathMethods,
1599
- pluginsAtoms,
1600
- atomListeners
1601
- );
1602
- return proxy;
1141
+ }, $fetch, pluginPathMethods, pluginsAtoms, atomListeners);
1603
1142
  }
1604
1143
 
1605
1144
  // src/dashboard-client.ts