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