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