@erikey/react 0.3.0 → 0.3.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,16 +1,1618 @@
1
+ // ../../../node_modules/.pnpm/@better-fetch+fetch@1.1.18/node_modules/@better-fetch/fetch/dist/index.js
2
+ 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
+ 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
+ };
562
+
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
564
+ 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);
568
+ var env = new Proxy(_envShim, {
569
+ get(_, prop) {
570
+ const env2 = _getEnv();
571
+ return env2[prop] ?? _envShim[prop];
572
+ },
573
+ has(_, prop) {
574
+ const env2 = _getEnv();
575
+ return prop in env2 || prop in _envShim;
576
+ },
577
+ set(_, prop, value) {
578
+ const env2 = _getEnv(true);
579
+ env2[prop] = value;
580
+ return true;
581
+ },
582
+ deleteProperty(_, prop) {
583
+ if (!prop) {
584
+ return false;
585
+ }
586
+ const env2 = _getEnv(true);
587
+ delete env2[prop];
588
+ return true;
589
+ },
590
+ ownKeys() {
591
+ const env2 = _getEnv(true);
592
+ return Object.keys(env2);
593
+ }
594
+ });
595
+ var nodeENV = typeof process !== "undefined" && process.env && process.env.NODE_ENV || "";
596
+ 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
+ }
606
+ return fallback;
607
+ }
608
+ var ENV = Object.freeze({
609
+ get BETTER_AUTH_SECRET() {
610
+ return getEnvVar("BETTER_AUTH_SECRET");
611
+ },
612
+ get AUTH_SECRET() {
613
+ return getEnvVar("AUTH_SECRET");
614
+ },
615
+ get BETTER_AUTH_TELEMETRY() {
616
+ return getEnvVar("BETTER_AUTH_TELEMETRY");
617
+ },
618
+ get BETTER_AUTH_TELEMETRY_ID() {
619
+ return getEnvVar("BETTER_AUTH_TELEMETRY_ID");
620
+ },
621
+ get NODE_ENV() {
622
+ return getEnvVar("NODE_ENV", "development");
623
+ },
624
+ get PACKAGE_VERSION() {
625
+ return getEnvVar("PACKAGE_VERSION", "0.0.0");
626
+ },
627
+ get BETTER_AUTH_TELEMETRY_ENDPOINT() {
628
+ return getEnvVar(
629
+ "BETTER_AUTH_TELEMETRY_ENDPOINT",
630
+ "https://telemetry.better-auth.com/v1/track"
631
+ );
632
+ }
633
+ });
634
+ var COLORS_2 = 1;
635
+ var COLORS_16 = 4;
636
+ var COLORS_256 = 8;
637
+ var COLORS_16m = 24;
638
+ var TERM_ENVS = {
639
+ eterm: COLORS_16,
640
+ cons25: COLORS_16,
641
+ console: COLORS_16,
642
+ cygwin: COLORS_16,
643
+ dtterm: COLORS_16,
644
+ gnome: COLORS_16,
645
+ hurd: COLORS_16,
646
+ jfbterm: COLORS_16,
647
+ konsole: COLORS_16,
648
+ kterm: COLORS_16,
649
+ mlterm: COLORS_16,
650
+ mosh: COLORS_16m,
651
+ putty: COLORS_16,
652
+ st: COLORS_16,
653
+ // http://lists.schmorp.de/pipermail/rxvt-unicode/2016q2/002261.html
654
+ "rxvt-unicode-24bit": COLORS_16m,
655
+ // https://bugs.launchpad.net/terminator/+bug/1030562
656
+ terminator: COLORS_16m,
657
+ "xterm-kitty": COLORS_16m
658
+ };
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
+ );
671
+ var TERM_ENVS_REG_EXP = [
672
+ /ansi/,
673
+ /color/,
674
+ /linux/,
675
+ /direct/,
676
+ /^con[0-9]*x[0-9]/,
677
+ /^rxvt/,
678
+ /^screen/,
679
+ /^xterm/,
680
+ /^vt100/,
681
+ /^vt220/
682
+ ];
683
+ 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;
710
+ }
711
+ 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
+ }
720
+ return COLORS_2;
721
+ }
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
+ }
727
+ switch (getEnvVar("TERM_PROGRAM")) {
728
+ case "iTerm.app":
729
+ if (!getEnvVar("TERM_PROGRAM_VERSION") || /^[0-2]\./.exec(getEnvVar("TERM_PROGRAM_VERSION")) !== null) {
730
+ return COLORS_256;
731
+ }
732
+ return COLORS_16m;
733
+ case "HyperTerm":
734
+ case "MacTerm":
735
+ return COLORS_16m;
736
+ case "Apple_Terminal":
737
+ return COLORS_256;
738
+ }
739
+ if (getEnvVar("COLORTERM") === "truecolor" || getEnvVar("COLORTERM") === "24bit") {
740
+ return COLORS_16m;
741
+ }
742
+ 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
+ }
749
+ 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;
759
+ }
760
+ return COLORS_2;
761
+ }
762
+ var TTY_COLORS = {
763
+ reset: "\x1B[0m",
764
+ bright: "\x1B[1m",
765
+ dim: "\x1B[2m",
766
+ undim: "\x1B[22m",
767
+ underscore: "\x1B[4m",
768
+ blink: "\x1B[5m",
769
+ reverse: "\x1B[7m",
770
+ hidden: "\x1B[8m",
771
+ fg: {
772
+ black: "\x1B[30m",
773
+ red: "\x1B[31m",
774
+ green: "\x1B[32m",
775
+ yellow: "\x1B[33m",
776
+ blue: "\x1B[34m",
777
+ magenta: "\x1B[35m",
778
+ cyan: "\x1B[36m",
779
+ white: "\x1B[37m"
780
+ },
781
+ bg: {
782
+ black: "\x1B[40m",
783
+ red: "\x1B[41m",
784
+ green: "\x1B[42m",
785
+ yellow: "\x1B[43m",
786
+ blue: "\x1B[44m",
787
+ magenta: "\x1B[45m",
788
+ cyan: "\x1B[46m",
789
+ white: "\x1B[47m"
790
+ }
791
+ };
792
+ var levels = ["info", "success", "warn", "error", "debug"];
793
+ function shouldPublishLog(currentLogLevel, logLevel) {
794
+ return levels.indexOf(logLevel) <= levels.indexOf(currentLogLevel);
795
+ }
796
+ var levelColors = {
797
+ info: TTY_COLORS.fg.blue,
798
+ success: TTY_COLORS.fg.green,
799
+ warn: TTY_COLORS.fg.yellow,
800
+ error: TTY_COLORS.fg.red,
801
+ debug: TTY_COLORS.fg.magenta
802
+ };
803
+ var formatMessage = (level, message, colorsEnabled) => {
804
+ 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
+ }
808
+ return `${timestamp} ${level.toUpperCase()} [Better Auth]: ${message}`;
809
+ };
810
+ var createLogger = (options) => {
811
+ const enabled = options?.disabled !== true;
812
+ const logLevel = options?.level ?? "error";
813
+ const isDisableColorsSpecified = options?.disableColors !== void 0;
814
+ const colorsEnabled = isDisableColorsSpecified ? !options.disableColors : getColorDepth() !== 1;
815
+ const LogFunc = (level, message, args = []) => {
816
+ if (!enabled || !shouldPublishLog(logLevel, level)) {
817
+ return;
818
+ }
819
+ const formattedMessage = formatMessage(level, message, colorsEnabled);
820
+ 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
+ }
828
+ return;
829
+ }
830
+ options.log(level === "success" ? "info" : level, message, ...args);
831
+ };
832
+ const logger2 = Object.fromEntries(
833
+ levels.map((level) => [
834
+ level,
835
+ (...[message, ...args]) => LogFunc(level, message, args)
836
+ ])
837
+ );
838
+ return {
839
+ ...logger2,
840
+ get level() {
841
+ return logLevel;
842
+ }
843
+ };
844
+ };
845
+ var logger = createLogger();
846
+
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
848
+ function defineErrorCodes(codes) {
849
+ return codes;
850
+ }
851
+
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
853
+ var BASE_ERROR_CODES = defineErrorCodes({
854
+ USER_NOT_FOUND: "User not found",
855
+ FAILED_TO_CREATE_USER: "Failed to create user",
856
+ FAILED_TO_CREATE_SESSION: "Failed to create session",
857
+ FAILED_TO_UPDATE_USER: "Failed to update user",
858
+ FAILED_TO_GET_SESSION: "Failed to get session",
859
+ INVALID_PASSWORD: "Invalid password",
860
+ INVALID_EMAIL: "Invalid email",
861
+ INVALID_EMAIL_OR_PASSWORD: "Invalid email or password",
862
+ SOCIAL_ACCOUNT_ALREADY_LINKED: "Social account already linked",
863
+ PROVIDER_NOT_FOUND: "Provider not found",
864
+ INVALID_TOKEN: "Invalid token",
865
+ ID_TOKEN_NOT_SUPPORTED: "id_token not supported",
866
+ FAILED_TO_GET_USER_INFO: "Failed to get user info",
867
+ USER_EMAIL_NOT_FOUND: "User email not found",
868
+ EMAIL_NOT_VERIFIED: "Email not verified",
869
+ PASSWORD_TOO_SHORT: "Password too short",
870
+ PASSWORD_TOO_LONG: "Password too long",
871
+ USER_ALREADY_EXISTS: "User already exists.",
872
+ USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL: "User already exists. Use another email.",
873
+ EMAIL_CAN_NOT_BE_UPDATED: "Email can not be updated",
874
+ CREDENTIAL_ACCOUNT_NOT_FOUND: "Credential account not found",
875
+ SESSION_EXPIRED: "Session expired. Re-authenticate to perform this action.",
876
+ FAILED_TO_UNLINK_LAST_ACCOUNT: "You can't unlink your last account",
877
+ ACCOUNT_NOT_FOUND: "Account not found",
878
+ USER_ALREADY_HAS_PASSWORD: "User already has a password. Provide that to delete the account."
879
+ });
880
+ var BetterAuthError = class extends Error {
881
+ constructor(message, cause) {
882
+ super(message);
883
+ this.name = "BetterAuthError";
884
+ this.message = message;
885
+ this.cause = cause;
886
+ this.stack = "";
887
+ }
888
+ };
889
+
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
891
+ function checkHasPath(url) {
892
+ try {
893
+ const parsedUrl = new URL(url);
894
+ const pathname = parsedUrl.pathname.replace(/\/+$/, "") || "/";
895
+ return pathname !== "/";
896
+ } catch (error) {
897
+ throw new BetterAuthError(
898
+ `Invalid base URL: ${url}. Please provide a valid base URL.`
899
+ );
900
+ }
901
+ }
902
+ function withPath(url, path = "/api/auth") {
903
+ const hasPath = checkHasPath(url);
904
+ if (hasPath) {
905
+ return url;
906
+ }
907
+ const trimmedUrl = url.replace(/\/+$/, "");
908
+ if (!path || path === "/") {
909
+ return trimmedUrl;
910
+ }
911
+ path = path.startsWith("/") ? path : `/${path}`;
912
+ return `${trimmedUrl}${path}`;
913
+ }
914
+ function getBaseURL(url, path, request, loadEnv) {
915
+ if (url) {
916
+ return withPath(url, path);
917
+ }
918
+ if (loadEnv !== false) {
919
+ 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
+ }
923
+ }
924
+ const fromRequest = request?.headers.get("x-forwarded-host");
925
+ 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
+ );
935
+ }
936
+ return withPath(url2, path);
937
+ }
938
+ if (typeof window !== "undefined" && window.location) {
939
+ return withPath(window.location.origin, path);
940
+ }
941
+ return void 0;
942
+ }
943
+ function getOrigin(url) {
944
+ try {
945
+ const parsedUrl = new URL(url);
946
+ return parsedUrl.origin;
947
+ } catch (error) {
948
+ return null;
949
+ }
950
+ }
951
+
952
+ // ../../../node_modules/.pnpm/nanostores@1.1.0/node_modules/nanostores/clean-stores/index.js
953
+ var clean = Symbol("clean");
954
+
955
+ // ../../../node_modules/.pnpm/nanostores@1.1.0/node_modules/nanostores/atom/index.js
956
+ var listenerQueue = [];
957
+ var lqIndex = 0;
958
+ var QUEUE_ITEMS_PER_LISTENER = 4;
959
+ var epoch = 0;
960
+ var atom = /* @__NO_SIDE_EFFECTS__ */ (initialValue) => {
961
+ let listeners = [];
962
+ let $atom = {
963
+ get() {
964
+ if (!$atom.lc) {
965
+ $atom.listen(() => {
966
+ })();
967
+ }
968
+ return $atom.value;
969
+ },
970
+ lc: 0,
971
+ listen(listener) {
972
+ $atom.lc = listeners.push(listener);
973
+ return () => {
974
+ for (let i = lqIndex + QUEUE_ITEMS_PER_LISTENER; i < listenerQueue.length; ) {
975
+ if (listenerQueue[i] === listener) {
976
+ listenerQueue.splice(i, QUEUE_ITEMS_PER_LISTENER);
977
+ } else {
978
+ i += QUEUE_ITEMS_PER_LISTENER;
979
+ }
980
+ }
981
+ let index = listeners.indexOf(listener);
982
+ if (~index) {
983
+ listeners.splice(index, 1);
984
+ if (!--$atom.lc) $atom.off();
985
+ }
986
+ };
987
+ },
988
+ notify(oldValue, changedKey) {
989
+ epoch++;
990
+ let runListenerQueue = !listenerQueue.length;
991
+ for (let listener of listeners) {
992
+ listenerQueue.push(listener, $atom.value, oldValue, changedKey);
993
+ }
994
+ if (runListenerQueue) {
995
+ for (lqIndex = 0; lqIndex < listenerQueue.length; lqIndex += QUEUE_ITEMS_PER_LISTENER) {
996
+ listenerQueue[lqIndex](
997
+ listenerQueue[lqIndex + 1],
998
+ listenerQueue[lqIndex + 2],
999
+ listenerQueue[lqIndex + 3]
1000
+ );
1001
+ }
1002
+ listenerQueue.length = 0;
1003
+ }
1004
+ },
1005
+ /* It will be called on last listener unsubscribing.
1006
+ We will redefine it in onMount and onStop. */
1007
+ off() {
1008
+ },
1009
+ set(newValue) {
1010
+ let oldValue = $atom.value;
1011
+ if (oldValue !== newValue) {
1012
+ $atom.value = newValue;
1013
+ $atom.notify(oldValue);
1014
+ }
1015
+ },
1016
+ subscribe(listener) {
1017
+ let unbind = $atom.listen(listener);
1018
+ listener($atom.value);
1019
+ return unbind;
1020
+ },
1021
+ value: initialValue
1022
+ };
1023
+ if (process.env.NODE_ENV !== "production") {
1024
+ $atom[clean] = () => {
1025
+ listeners = [];
1026
+ $atom.lc = 0;
1027
+ $atom.off();
1028
+ };
1029
+ }
1030
+ return $atom;
1031
+ };
1032
+
1033
+ // ../../../node_modules/.pnpm/nanostores@1.1.0/node_modules/nanostores/lifecycle/index.js
1034
+ var MOUNT = 5;
1035
+ var UNMOUNT = 6;
1036
+ var REVERT_MUTATION = 10;
1037
+ var on = (object, listener, eventKey, mutateStore) => {
1038
+ object.events = object.events || {};
1039
+ if (!object.events[eventKey + REVERT_MUTATION]) {
1040
+ object.events[eventKey + REVERT_MUTATION] = mutateStore((eventProps) => {
1041
+ object.events[eventKey].reduceRight((event, l) => (l(event), event), {
1042
+ shared: {},
1043
+ ...eventProps
1044
+ });
1045
+ });
1046
+ }
1047
+ object.events[eventKey] = object.events[eventKey] || [];
1048
+ object.events[eventKey].push(listener);
1049
+ return () => {
1050
+ let currentListeners = object.events[eventKey];
1051
+ let index = currentListeners.indexOf(listener);
1052
+ currentListeners.splice(index, 1);
1053
+ if (!currentListeners.length) {
1054
+ delete object.events[eventKey];
1055
+ object.events[eventKey + REVERT_MUTATION]();
1056
+ delete object.events[eventKey + REVERT_MUTATION];
1057
+ }
1058
+ };
1059
+ };
1060
+ var STORE_UNMOUNT_DELAY = 1e3;
1061
+ var onMount = ($store, initialize) => {
1062
+ let listener = (payload) => {
1063
+ let destroy = initialize(payload);
1064
+ if (destroy) $store.events[UNMOUNT].push(destroy);
1065
+ };
1066
+ return on($store, listener, MOUNT, (runListeners) => {
1067
+ let originListen = $store.listen;
1068
+ $store.listen = (...args) => {
1069
+ if (!$store.lc && !$store.active) {
1070
+ $store.active = true;
1071
+ runListeners();
1072
+ }
1073
+ return originListen(...args);
1074
+ };
1075
+ let originOff = $store.off;
1076
+ $store.events[UNMOUNT] = [];
1077
+ $store.off = () => {
1078
+ originOff();
1079
+ setTimeout(() => {
1080
+ if ($store.active && !$store.lc) {
1081
+ $store.active = false;
1082
+ for (let destroy of $store.events[UNMOUNT]) destroy();
1083
+ $store.events[UNMOUNT] = [];
1084
+ }
1085
+ }, STORE_UNMOUNT_DELAY);
1086
+ };
1087
+ if (process.env.NODE_ENV !== "production") {
1088
+ let originClean = $store[clean];
1089
+ $store[clean] = () => {
1090
+ for (let destroy of $store.events[UNMOUNT]) destroy();
1091
+ $store.events[UNMOUNT] = [];
1092
+ $store.active = false;
1093
+ originClean();
1094
+ };
1095
+ }
1096
+ return () => {
1097
+ $store.listen = originListen;
1098
+ $store.off = originOff;
1099
+ };
1100
+ });
1101
+ };
1102
+
1103
+ // ../../../node_modules/.pnpm/nanostores@1.1.0/node_modules/nanostores/listen-keys/index.js
1104
+ function listenKeys($store, keys, listener) {
1105
+ let keysSet = new Set(keys).add(void 0);
1106
+ return $store.listen((value, oldValue, changed) => {
1107
+ if (keysSet.has(changed)) {
1108
+ listener(value, oldValue, changed);
1109
+ }
1110
+ });
1111
+ }
1112
+
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";
1115
+ var useAuthQuery = (initializedAtom, path, $fetch, options) => {
1116
+ const value = atom({
1117
+ data: null,
1118
+ error: null,
1119
+ isPending: true,
1120
+ isRefetching: false,
1121
+ refetch: (queryParams) => {
1122
+ return fn(queryParams);
1123
+ }
1124
+ });
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;
1152
+ value.set({
1153
+ error: context.error,
1154
+ data: null,
1155
+ isPending: false,
1156
+ isRefetching: false,
1157
+ refetch: value.value.refetch
1158
+ });
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
1179
+ });
1180
+ });
1181
+ };
1182
+ initializedAtom = Array.isArray(initializedAtom) ? initializedAtom : [initializedAtom];
1183
+ 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
+ }
1206
+ });
1207
+ }
1208
+ return value;
1209
+ };
1210
+
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);
1262
+ }
1263
+ return isValidDate(date) ? date : null;
1264
+ }
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;
1274
+ }
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);
1278
+ }
1279
+ const lowerValue = trimmed.toLowerCase();
1280
+ if (lowerValue.length <= 9 && lowerValue in SPECIAL_VALUES) {
1281
+ return SPECIAL_VALUES[lowerValue];
1282
+ }
1283
+ if (!JSON_SIGNATURE.test(trimmed)) {
1284
+ if (strict) {
1285
+ throw new SyntaxError("[better-json] Invalid JSON");
1286
+ }
1287
+ return value;
1288
+ }
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
+ );
1304
+ }
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;
1322
+ };
1323
+ return JSON.parse(trimmed, secureReviver);
1324
+ } catch (error) {
1325
+ if (strict) {
1326
+ throw error;
1327
+ }
1328
+ return value;
1329
+ }
1330
+ }
1331
+ function parseJSON(value, options = { strict: true }) {
1332
+ return betterJSONParse(value, options);
1333
+ }
1334
+
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
+ }
1351
+ }
1352
+ }
1353
+ };
1354
+ function getSessionAtom($fetch) {
1355
+ const $signal = atom(false);
1356
+ const session = useAuthQuery($signal, "/get-session", $fetch, {
1357
+ method: "GET"
1358
+ });
1359
+ return {
1360
+ session,
1361
+ $sessionSignal: $signal
1362
+ };
1363
+ }
1364
+ var getClientConfig = (options, loadEnv) => {
1365
+ const isCredentialsSupported = "credentials" in Request.prototype;
1366
+ const baseURL = getBaseURL(options?.baseURL, options?.basePath, void 0, loadEnv) ?? "/api/auth";
1367
+ const pluginsFetchPlugins = options?.plugins?.flatMap((plugin) => plugin.fetchPlugins).filter((pl) => pl !== void 0) || [];
1368
+ const lifeCyclePlugin = {
1369
+ id: "lifecycle-hooks",
1370
+ name: "lifecycle-hooks",
1371
+ hooks: {
1372
+ onSuccess: options?.fetchOptions?.onSuccess,
1373
+ onError: options?.fetchOptions?.onError,
1374
+ onRequest: options?.fetchOptions?.onRequest,
1375
+ onResponse: options?.fetchOptions?.onResponse
1376
+ }
1377
+ };
1378
+ const { onSuccess, onError, onRequest, onResponse, ...restOfFetchOptions } = options?.fetchOptions || {};
1379
+ const $fetch = createFetch({
1380
+ baseURL,
1381
+ ...isCredentialsSupported ? { credentials: "include" } : {},
1382
+ method: "GET",
1383
+ jsonParser(text) {
1384
+ if (!text) {
1385
+ return null;
1386
+ }
1387
+ return parseJSON(text, {
1388
+ strict: false
1389
+ });
1390
+ },
1391
+ customFetchImpl: fetch,
1392
+ ...restOfFetchOptions,
1393
+ plugins: [
1394
+ lifeCyclePlugin,
1395
+ ...restOfFetchOptions.plugins || [],
1396
+ ...options?.disableDefaultFetchPlugins ? [] : [redirectPlugin],
1397
+ ...pluginsFetchPlugins
1398
+ ]
1399
+ });
1400
+ const { $sessionSignal, session } = getSessionAtom($fetch);
1401
+ const plugins = options?.plugins || [];
1402
+ let pluginsActions = {};
1403
+ let pluginsAtoms = {
1404
+ $sessionSignal,
1405
+ session
1406
+ };
1407
+ let pluginPathMethods = {
1408
+ "/sign-out": "POST",
1409
+ "/revoke-sessions": "POST",
1410
+ "/revoke-other-sessions": "POST",
1411
+ "/delete-user": "POST"
1412
+ };
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
+ }
1419
+ }
1420
+ ];
1421
+ 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
+ }
1431
+ }
1432
+ const $store = {
1433
+ notify: (signal) => {
1434
+ pluginsAtoms[signal].set(
1435
+ !pluginsAtoms[signal].get()
1436
+ );
1437
+ },
1438
+ listen: (signal, listener) => {
1439
+ pluginsAtoms[signal].subscribe(listener);
1440
+ },
1441
+ atoms: pluginsAtoms
1442
+ };
1443
+ for (const plugin of plugins) {
1444
+ if (plugin.getActions) {
1445
+ Object.assign(
1446
+ pluginsActions,
1447
+ plugin.getActions?.($fetch, $store, options)
1448
+ );
1449
+ }
1450
+ }
1451
+ return {
1452
+ get baseURL() {
1453
+ return baseURL;
1454
+ },
1455
+ pluginsActions,
1456
+ pluginsAtoms,
1457
+ pluginPathMethods,
1458
+ atomListeners,
1459
+ $fetch,
1460
+ $store
1461
+ };
1462
+ };
1463
+ function isAtom(value) {
1464
+ return typeof value === "object" && value !== null && "get" in value && typeof value.get === "function" && "lc" in value && typeof value.lc === "number";
1465
+ }
1466
+ function getMethod2(path, knownPathMethods, args) {
1467
+ 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
+ }
1478
+ return "GET";
1479
+ }
1480
+ function createDynamicPathProxy(routes, client, knownPathMethods, atoms, atomListeners) {
1481
+ function createProxy(path = []) {
1482
+ return new Proxy(function() {
1483
+ }, {
1484
+ 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
+ }
1491
+ const fullPath = [...path, prop];
1492
+ 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;
1506
+ }
1507
+ return createProxy(fullPath);
1508
+ },
1509
+ apply: async (_, __, args) => {
1510
+ const routePath = "/" + path.map(
1511
+ (segment) => segment.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`)
1512
+ ).join("/");
1513
+ const arg = args[0] || {};
1514
+ const fetchOptions = args[1] || {};
1515
+ const { query, fetchOptions: argFetchOptions, ...body } = arg;
1516
+ const options = {
1517
+ ...fetchOptions,
1518
+ ...argFetchOptions
1519
+ };
1520
+ const method = getMethod2(routePath, knownPathMethods, arg);
1521
+ return await client(routePath, {
1522
+ ...options,
1523
+ body: method === "GET" ? void 0 : {
1524
+ ...body,
1525
+ ...options?.body || {}
1526
+ },
1527
+ query: query || options?.query,
1528
+ method,
1529
+ async onSuccess(context) {
1530
+ await options?.onSuccess?.(context);
1531
+ if (!atomListeners) return;
1532
+ const matches = atomListeners.filter((s) => s.matcher(routePath));
1533
+ if (!matches.length) return;
1534
+ for (const match of matches) {
1535
+ const signal = atoms[match.signal];
1536
+ if (!signal) return;
1537
+ const val = signal.get();
1538
+ setTimeout(() => {
1539
+ signal.set(!val);
1540
+ }, 10);
1541
+ }
1542
+ }
1543
+ });
1544
+ }
1545
+ });
1546
+ }
1547
+ return createProxy();
1548
+ }
1549
+
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";
1552
+ function useStore(store, options = {}) {
1553
+ let snapshotRef = useRef(store.get());
1554
+ const { keys, deps = [store, keys] } = options;
1555
+ let subscribe = useCallback((onChange) => {
1556
+ const emitChange = (value) => {
1557
+ if (snapshotRef.current === value) return;
1558
+ snapshotRef.current = value;
1559
+ onChange();
1560
+ };
1561
+ emitChange(store.value);
1562
+ if (keys?.length) {
1563
+ return listenKeys(store, keys, emitChange);
1564
+ }
1565
+ return store.listen(emitChange);
1566
+ }, deps);
1567
+ let get = () => snapshotRef.current;
1568
+ return useSyncExternalStore(subscribe, get, get);
1569
+ }
1570
+ function getAtomKey(str) {
1571
+ return `use${capitalizeFirstLetter(str)}`;
1572
+ }
1573
+ function capitalizeFirstLetter(str) {
1574
+ return str.charAt(0).toUpperCase() + str.slice(1);
1575
+ }
1576
+ function createAuthClient(options) {
1577
+ const {
1578
+ pluginPathMethods,
1579
+ pluginsActions,
1580
+ pluginsAtoms,
1581
+ $fetch,
1582
+ $store,
1583
+ atomListeners
1584
+ } = getClientConfig(options);
1585
+ let resolvedHooks = {};
1586
+ for (const [key, value] of Object.entries(pluginsAtoms)) {
1587
+ resolvedHooks[getAtomKey(key)] = () => useStore(value);
1588
+ }
1589
+ const routes = {
1590
+ ...pluginsActions,
1591
+ ...resolvedHooks,
1592
+ $fetch,
1593
+ $store
1594
+ };
1595
+ const proxy = createDynamicPathProxy(
1596
+ routes,
1597
+ $fetch,
1598
+ pluginPathMethods,
1599
+ pluginsAtoms,
1600
+ atomListeners
1601
+ );
1602
+ return proxy;
1603
+ }
1604
+
1
1605
  // src/dashboard-client.ts
2
- import { createAuthClient as createBetterAuthClient } from "better-auth/react";
3
1606
  function createDashboardClient(config) {
4
1607
  const baseURL = config?.baseURL || "https://api.erikey.com";
5
- return createBetterAuthClient({
1608
+ return createAuthClient({
6
1609
  baseURL,
7
1610
  credentials: config?.credentials || "include"
8
1611
  });
9
1612
  }
10
1613
 
11
1614
  // src/auth-client.ts
12
- import { useState, useEffect, useCallback } from "react";
13
- import { createAuthClient as createBetterAuthClient2 } from "better-auth/react";
1615
+ import { useState, useEffect, useCallback as useCallback2 } from "react";
14
1616
 
15
1617
  // src/lib/cross-origin-auth.ts
16
1618
  function shouldUseBearerAuth(authApiUrl) {
@@ -57,7 +1659,7 @@ function clearToken(projectId) {
57
1659
  }
58
1660
 
59
1661
  // src/auth-client.ts
60
- function createAuthClient(config) {
1662
+ function createAuthClient2(config) {
61
1663
  const { projectId, baseUrl = "https://auth.erikey.com" } = config;
62
1664
  const useBearerAuth = shouldUseBearerAuth(baseUrl);
63
1665
  const fetchOptions = {
@@ -73,7 +1675,7 @@ function createAuthClient(config) {
73
1675
  }
74
1676
  }
75
1677
  };
76
- const client = createBetterAuthClient2({
1678
+ const client = createAuthClient({
77
1679
  baseURL: baseUrl,
78
1680
  fetchOptions,
79
1681
  // For same-origin, include cookies
@@ -160,7 +1762,7 @@ function createAuthClient(config) {
160
1762
  const [data, setData] = useState(null);
161
1763
  const [isPending, setIsPending] = useState(true);
162
1764
  const [error, setError] = useState(null);
163
- const refetch = useCallback(async () => {
1765
+ const refetch = useCallback2(async () => {
164
1766
  setIsPending(true);
165
1767
  try {
166
1768
  const result = await client.getSession();
@@ -363,7 +1965,7 @@ function createKvClient(config) {
363
1965
  };
364
1966
  }
365
1967
  export {
366
- createAuthClient,
1968
+ createAuthClient2 as createAuthClient,
367
1969
  createDashboardClient,
368
1970
  createKvClient
369
1971
  };