@rio.js/enterprise 1.4.0
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 +89 -0
- package/dist/adapter-factory-BTRALCLD-kJBwe70v.mjs +836 -0
- package/dist/better-auth-CStoaWiq.d.mts +10 -0
- package/dist/better-auth-CqfhQJYE.mjs +558 -0
- package/dist/better-auth.d.mts +2 -0
- package/dist/better-auth.mjs +17 -0
- package/dist/bun-sqlite-dialect-2R9nCsVF-DFs6tpGr.mjs +155 -0
- package/dist/client--1_AEBPu-8Ae9icC9.mjs +125 -0
- package/dist/client.d.mts +17 -0
- package/dist/client.mjs +381 -0
- package/dist/db-BVXTgOd3.mjs +681 -0
- package/dist/db-BadqSwVl.d.mts +9542 -0
- package/dist/db-schema.final-DWleoQm0.mjs +785 -0
- package/dist/db.d.mts +2 -0
- package/dist/db.mjs +3 -0
- package/dist/dialect-C6_pK3V9-CPJHWkYR.mjs +72 -0
- package/dist/dist-CygcgJYk.mjs +422 -0
- package/dist/env-DwlNAN_D-C1zHd0cf-Cdlw8sNp.mjs +289 -0
- package/dist/esm-C5TuvtGn.mjs +15816 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.mjs +17 -0
- package/dist/init-D8lwWc90.mjs +27 -0
- package/dist/json-oFuWgANh-O1U6k3bL.mjs +3811 -0
- package/dist/kysely-adapter-D_seG51p.mjs +297 -0
- package/dist/memory-adapter-CY-oDozb.mjs +215 -0
- package/dist/misc-CbURQDlR-sLtUwwQY.mjs +7 -0
- package/dist/node-sqlite-dialect-CdC7L-ji-QLbJGmDc.mjs +155 -0
- package/dist/parser-bL7W2mQ0-YdTgjtji.mjs +140 -0
- package/dist/plugins-BNFht2HW.mjs +23358 -0
- package/dist/plugins.d.mts +1 -0
- package/dist/plugins.mjs +13 -0
- package/dist/react--VZQu7s1.mjs +560 -0
- package/dist/react.d.mts +1 -0
- package/dist/react.mjs +6 -0
- package/dist/server.d.mts +10 -0
- package/dist/server.mjs +45 -0
- package/dist/social-providers-DNfE9Ak7-Be5zMAEe.mjs +2920 -0
- package/dist/social-providers.d.mts +1 -0
- package/dist/social-providers.mjs +6 -0
- package/dist/verify-CN5Qc0e-.mjs +1183 -0
- package/package.json +98 -0
package/dist/db.d.mts
ADDED
package/dist/db.mjs
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { i as SqliteDialect, n as PostgresDialect, r as MysqlDialect, t as MssqlDialect, u as Kysely } from "./esm-C5TuvtGn.mjs";
|
|
2
|
+
|
|
3
|
+
//#region ../better-auth/dist/dialect-C6_pK3V9.mjs
|
|
4
|
+
function getKyselyDatabaseType(db) {
|
|
5
|
+
if (!db) return null;
|
|
6
|
+
if ("dialect" in db) return getKyselyDatabaseType(db.dialect);
|
|
7
|
+
if ("createDriver" in db) {
|
|
8
|
+
if (db instanceof SqliteDialect) return "sqlite";
|
|
9
|
+
if (db instanceof MysqlDialect) return "mysql";
|
|
10
|
+
if (db instanceof PostgresDialect) return "postgres";
|
|
11
|
+
if (db instanceof MssqlDialect) return "mssql";
|
|
12
|
+
}
|
|
13
|
+
if ("aggregate" in db) return "sqlite";
|
|
14
|
+
if ("getConnection" in db) return "mysql";
|
|
15
|
+
if ("connect" in db) return "postgres";
|
|
16
|
+
if ("fileControl" in db) return "sqlite";
|
|
17
|
+
if ("open" in db && "close" in db && "prepare" in db) return "sqlite";
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
const createKyselyAdapter = async (config) => {
|
|
21
|
+
const db = config.database;
|
|
22
|
+
if (!db) return {
|
|
23
|
+
kysely: null,
|
|
24
|
+
databaseType: null,
|
|
25
|
+
transaction: void 0
|
|
26
|
+
};
|
|
27
|
+
if ("db" in db) return {
|
|
28
|
+
kysely: db.db,
|
|
29
|
+
databaseType: db.type,
|
|
30
|
+
transaction: db.transaction
|
|
31
|
+
};
|
|
32
|
+
if ("dialect" in db) return {
|
|
33
|
+
kysely: new Kysely({ dialect: db.dialect }),
|
|
34
|
+
databaseType: db.type,
|
|
35
|
+
transaction: db.transaction
|
|
36
|
+
};
|
|
37
|
+
let dialect = void 0;
|
|
38
|
+
const databaseType = getKyselyDatabaseType(db);
|
|
39
|
+
if ("createDriver" in db) dialect = db;
|
|
40
|
+
if ("aggregate" in db && !("createSession" in db)) dialect = new SqliteDialect({ database: db });
|
|
41
|
+
if ("getConnection" in db) dialect = new MysqlDialect(db);
|
|
42
|
+
if ("connect" in db) dialect = new PostgresDialect({ pool: db });
|
|
43
|
+
if ("fileControl" in db) {
|
|
44
|
+
const { BunSqliteDialect } = await import("./bun-sqlite-dialect-2R9nCsVF-DFs6tpGr.mjs");
|
|
45
|
+
dialect = new BunSqliteDialect({ database: db });
|
|
46
|
+
}
|
|
47
|
+
if ("createSession" in db && typeof window === "undefined") {
|
|
48
|
+
let DatabaseSync = void 0;
|
|
49
|
+
try {
|
|
50
|
+
let nodeSqlite = "node:sqlite";
|
|
51
|
+
({DatabaseSync} = await import(
|
|
52
|
+
/* @vite-ignore */
|
|
53
|
+
/* webpackIgnore: true */
|
|
54
|
+
nodeSqlite
|
|
55
|
+
));
|
|
56
|
+
} catch (error) {
|
|
57
|
+
if (error !== null && typeof error === "object" && "code" in error && error.code !== "ERR_UNKNOWN_BUILTIN_MODULE") throw error;
|
|
58
|
+
}
|
|
59
|
+
if (DatabaseSync && db instanceof DatabaseSync) {
|
|
60
|
+
const { NodeSqliteDialect } = await import("./node-sqlite-dialect-CdC7L-ji-QLbJGmDc.mjs");
|
|
61
|
+
dialect = new NodeSqliteDialect({ database: db });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
kysely: dialect ? new Kysely({ dialect }) : null,
|
|
66
|
+
databaseType,
|
|
67
|
+
transaction: void 0
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
//#endregion
|
|
72
|
+
export { getKyselyDatabaseType as n, createKyselyAdapter as t };
|
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
//#region ../../node_modules/.pnpm/@better-fetch+fetch@1.1.18/node_modules/@better-fetch/fetch/dist/index.js
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
configurable: true,
|
|
11
|
+
writable: true,
|
|
12
|
+
value
|
|
13
|
+
}) : obj[key] = value;
|
|
14
|
+
var __spreadValues = (a, b) => {
|
|
15
|
+
for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols) {
|
|
17
|
+
for (var prop of __getOwnPropSymbols(b)) if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
|
|
18
|
+
}
|
|
19
|
+
return a;
|
|
20
|
+
};
|
|
21
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
22
|
+
var BetterFetchError = class extends Error {
|
|
23
|
+
constructor(status, statusText, error) {
|
|
24
|
+
super(statusText || status.toString(), { cause: error });
|
|
25
|
+
this.status = status;
|
|
26
|
+
this.statusText = statusText;
|
|
27
|
+
this.error = error;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
var initializePlugins = async (url, options) => {
|
|
31
|
+
var _a, _b, _c, _d, _e, _f;
|
|
32
|
+
let opts = options || {};
|
|
33
|
+
const hooks = {
|
|
34
|
+
onRequest: [options == null ? void 0 : options.onRequest],
|
|
35
|
+
onResponse: [options == null ? void 0 : options.onResponse],
|
|
36
|
+
onSuccess: [options == null ? void 0 : options.onSuccess],
|
|
37
|
+
onError: [options == null ? void 0 : options.onError],
|
|
38
|
+
onRetry: [options == null ? void 0 : options.onRetry]
|
|
39
|
+
};
|
|
40
|
+
if (!options || !(options == null ? void 0 : options.plugins)) return {
|
|
41
|
+
url,
|
|
42
|
+
options: opts,
|
|
43
|
+
hooks
|
|
44
|
+
};
|
|
45
|
+
for (const plugin of (options == null ? void 0 : options.plugins) || []) {
|
|
46
|
+
if (plugin.init) {
|
|
47
|
+
const pluginRes = await ((_a = plugin.init) == null ? void 0 : _a.call(plugin, url.toString(), options));
|
|
48
|
+
opts = pluginRes.options || opts;
|
|
49
|
+
url = pluginRes.url;
|
|
50
|
+
}
|
|
51
|
+
hooks.onRequest.push((_b = plugin.hooks) == null ? void 0 : _b.onRequest);
|
|
52
|
+
hooks.onResponse.push((_c = plugin.hooks) == null ? void 0 : _c.onResponse);
|
|
53
|
+
hooks.onSuccess.push((_d = plugin.hooks) == null ? void 0 : _d.onSuccess);
|
|
54
|
+
hooks.onError.push((_e = plugin.hooks) == null ? void 0 : _e.onError);
|
|
55
|
+
hooks.onRetry.push((_f = plugin.hooks) == null ? void 0 : _f.onRetry);
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
url,
|
|
59
|
+
options: opts,
|
|
60
|
+
hooks
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
var LinearRetryStrategy = class {
|
|
64
|
+
constructor(options) {
|
|
65
|
+
this.options = options;
|
|
66
|
+
}
|
|
67
|
+
shouldAttemptRetry(attempt, response) {
|
|
68
|
+
if (this.options.shouldRetry) return Promise.resolve(attempt < this.options.attempts && this.options.shouldRetry(response));
|
|
69
|
+
return Promise.resolve(attempt < this.options.attempts);
|
|
70
|
+
}
|
|
71
|
+
getDelay() {
|
|
72
|
+
return this.options.delay;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
var ExponentialRetryStrategy = class {
|
|
76
|
+
constructor(options) {
|
|
77
|
+
this.options = options;
|
|
78
|
+
}
|
|
79
|
+
shouldAttemptRetry(attempt, response) {
|
|
80
|
+
if (this.options.shouldRetry) return Promise.resolve(attempt < this.options.attempts && this.options.shouldRetry(response));
|
|
81
|
+
return Promise.resolve(attempt < this.options.attempts);
|
|
82
|
+
}
|
|
83
|
+
getDelay(attempt) {
|
|
84
|
+
return Math.min(this.options.maxDelay, this.options.baseDelay * 2 ** attempt);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
function createRetryStrategy(options) {
|
|
88
|
+
if (typeof options === "number") return new LinearRetryStrategy({
|
|
89
|
+
type: "linear",
|
|
90
|
+
attempts: options,
|
|
91
|
+
delay: 1e3
|
|
92
|
+
});
|
|
93
|
+
switch (options.type) {
|
|
94
|
+
case "linear": return new LinearRetryStrategy(options);
|
|
95
|
+
case "exponential": return new ExponentialRetryStrategy(options);
|
|
96
|
+
default: throw new Error("Invalid retry strategy");
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
var getAuthHeader = async (options) => {
|
|
100
|
+
const headers = {};
|
|
101
|
+
const getValue = async (value) => typeof value === "function" ? await value() : value;
|
|
102
|
+
if (options == null ? void 0 : options.auth) {
|
|
103
|
+
if (options.auth.type === "Bearer") {
|
|
104
|
+
const token = await getValue(options.auth.token);
|
|
105
|
+
if (!token) return headers;
|
|
106
|
+
headers["authorization"] = `Bearer ${token}`;
|
|
107
|
+
} else if (options.auth.type === "Basic") {
|
|
108
|
+
const username = getValue(options.auth.username);
|
|
109
|
+
const password = getValue(options.auth.password);
|
|
110
|
+
if (!username || !password) return headers;
|
|
111
|
+
headers["authorization"] = `Basic ${btoa(`${username}:${password}`)}`;
|
|
112
|
+
} else if (options.auth.type === "Custom") {
|
|
113
|
+
const value = getValue(options.auth.value);
|
|
114
|
+
if (!value) return headers;
|
|
115
|
+
headers["authorization"] = `${getValue(options.auth.prefix)} ${value}`;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return headers;
|
|
119
|
+
};
|
|
120
|
+
var JSON_RE = /^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i;
|
|
121
|
+
function detectResponseType(request) {
|
|
122
|
+
const _contentType = request.headers.get("content-type");
|
|
123
|
+
const textTypes = /* @__PURE__ */ new Set([
|
|
124
|
+
"image/svg",
|
|
125
|
+
"application/xml",
|
|
126
|
+
"application/xhtml",
|
|
127
|
+
"application/html"
|
|
128
|
+
]);
|
|
129
|
+
if (!_contentType) return "json";
|
|
130
|
+
const contentType = _contentType.split(";").shift() || "";
|
|
131
|
+
if (JSON_RE.test(contentType)) return "json";
|
|
132
|
+
if (textTypes.has(contentType) || contentType.startsWith("text/")) return "text";
|
|
133
|
+
return "blob";
|
|
134
|
+
}
|
|
135
|
+
function isJSONParsable(value) {
|
|
136
|
+
try {
|
|
137
|
+
JSON.parse(value);
|
|
138
|
+
return true;
|
|
139
|
+
} catch (error) {
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
function isJSONSerializable(value) {
|
|
144
|
+
if (value === void 0) return false;
|
|
145
|
+
const t = typeof value;
|
|
146
|
+
if (t === "string" || t === "number" || t === "boolean" || t === null) return true;
|
|
147
|
+
if (t !== "object") return false;
|
|
148
|
+
if (Array.isArray(value)) return true;
|
|
149
|
+
if (value.buffer) return false;
|
|
150
|
+
return value.constructor && value.constructor.name === "Object" || typeof value.toJSON === "function";
|
|
151
|
+
}
|
|
152
|
+
function jsonParse(text) {
|
|
153
|
+
try {
|
|
154
|
+
return JSON.parse(text);
|
|
155
|
+
} catch (error) {
|
|
156
|
+
return text;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
function isFunction(value) {
|
|
160
|
+
return typeof value === "function";
|
|
161
|
+
}
|
|
162
|
+
function getFetch(options) {
|
|
163
|
+
if (options == null ? void 0 : options.customFetchImpl) return options.customFetchImpl;
|
|
164
|
+
if (typeof globalThis !== "undefined" && isFunction(globalThis.fetch)) return globalThis.fetch;
|
|
165
|
+
if (typeof window !== "undefined" && isFunction(window.fetch)) return window.fetch;
|
|
166
|
+
throw new Error("No fetch implementation found");
|
|
167
|
+
}
|
|
168
|
+
async function getHeaders(opts) {
|
|
169
|
+
const headers = new Headers(opts == null ? void 0 : opts.headers);
|
|
170
|
+
const authHeader = await getAuthHeader(opts);
|
|
171
|
+
for (const [key, value] of Object.entries(authHeader || {})) headers.set(key, value);
|
|
172
|
+
if (!headers.has("content-type")) {
|
|
173
|
+
const t = detectContentType(opts == null ? void 0 : opts.body);
|
|
174
|
+
if (t) headers.set("content-type", t);
|
|
175
|
+
}
|
|
176
|
+
return headers;
|
|
177
|
+
}
|
|
178
|
+
function detectContentType(body) {
|
|
179
|
+
if (isJSONSerializable(body)) return "application/json";
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
function getBody(options) {
|
|
183
|
+
if (!(options == null ? void 0 : options.body)) return null;
|
|
184
|
+
const headers = new Headers(options == null ? void 0 : options.headers);
|
|
185
|
+
if (isJSONSerializable(options.body) && !headers.has("content-type")) {
|
|
186
|
+
for (const [key, value] of Object.entries(options == null ? void 0 : options.body)) if (value instanceof Date) options.body[key] = value.toISOString();
|
|
187
|
+
return JSON.stringify(options.body);
|
|
188
|
+
}
|
|
189
|
+
return options.body;
|
|
190
|
+
}
|
|
191
|
+
function getMethod(url, options) {
|
|
192
|
+
var _a;
|
|
193
|
+
if (options == null ? void 0 : options.method) return options.method.toUpperCase();
|
|
194
|
+
if (url.startsWith("@")) {
|
|
195
|
+
const pMethod = (_a = url.split("@")[1]) == null ? void 0 : _a.split("/")[0];
|
|
196
|
+
if (!methods.includes(pMethod)) return (options == null ? void 0 : options.body) ? "POST" : "GET";
|
|
197
|
+
return pMethod.toUpperCase();
|
|
198
|
+
}
|
|
199
|
+
return (options == null ? void 0 : options.body) ? "POST" : "GET";
|
|
200
|
+
}
|
|
201
|
+
function getTimeout(options, controller) {
|
|
202
|
+
let abortTimeout;
|
|
203
|
+
if (!(options == null ? void 0 : options.signal) && (options == null ? void 0 : options.timeout)) abortTimeout = setTimeout(() => controller == null ? void 0 : controller.abort(), options == null ? void 0 : options.timeout);
|
|
204
|
+
return {
|
|
205
|
+
abortTimeout,
|
|
206
|
+
clearTimeout: () => {
|
|
207
|
+
if (abortTimeout) clearTimeout(abortTimeout);
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
var ValidationError = class _ValidationError extends Error {
|
|
212
|
+
constructor(issues, message) {
|
|
213
|
+
super(message || JSON.stringify(issues, null, 2));
|
|
214
|
+
this.issues = issues;
|
|
215
|
+
Object.setPrototypeOf(this, _ValidationError.prototype);
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
async function parseStandardSchema(schema, input) {
|
|
219
|
+
let result = await schema["~standard"].validate(input);
|
|
220
|
+
if (result.issues) throw new ValidationError(result.issues);
|
|
221
|
+
return result.value;
|
|
222
|
+
}
|
|
223
|
+
var methods = [
|
|
224
|
+
"get",
|
|
225
|
+
"post",
|
|
226
|
+
"put",
|
|
227
|
+
"patch",
|
|
228
|
+
"delete"
|
|
229
|
+
];
|
|
230
|
+
var applySchemaPlugin = (config) => ({
|
|
231
|
+
id: "apply-schema",
|
|
232
|
+
name: "Apply Schema",
|
|
233
|
+
version: "1.0.0",
|
|
234
|
+
async init(url, options) {
|
|
235
|
+
var _a, _b, _c, _d;
|
|
236
|
+
const schema = ((_b = (_a = config.plugins) == null ? void 0 : _a.find((plugin) => {
|
|
237
|
+
var _a2;
|
|
238
|
+
return ((_a2 = plugin.schema) == null ? void 0 : _a2.config) ? url.startsWith(plugin.schema.config.baseURL || "") || url.startsWith(plugin.schema.config.prefix || "") : false;
|
|
239
|
+
})) == null ? void 0 : _b.schema) || config.schema;
|
|
240
|
+
if (schema) {
|
|
241
|
+
let urlKey = url;
|
|
242
|
+
if ((_c = schema.config) == null ? void 0 : _c.prefix) {
|
|
243
|
+
if (urlKey.startsWith(schema.config.prefix)) {
|
|
244
|
+
urlKey = urlKey.replace(schema.config.prefix, "");
|
|
245
|
+
if (schema.config.baseURL) url = url.replace(schema.config.prefix, schema.config.baseURL);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
if ((_d = schema.config) == null ? void 0 : _d.baseURL) {
|
|
249
|
+
if (urlKey.startsWith(schema.config.baseURL)) urlKey = urlKey.replace(schema.config.baseURL, "");
|
|
250
|
+
}
|
|
251
|
+
const keySchema = schema.schema[urlKey];
|
|
252
|
+
if (keySchema) {
|
|
253
|
+
let opts = __spreadProps(__spreadValues({}, options), {
|
|
254
|
+
method: keySchema.method,
|
|
255
|
+
output: keySchema.output
|
|
256
|
+
});
|
|
257
|
+
if (!(options == null ? void 0 : options.disableValidation)) opts = __spreadProps(__spreadValues({}, opts), {
|
|
258
|
+
body: keySchema.input ? await parseStandardSchema(keySchema.input, options == null ? void 0 : options.body) : options == null ? void 0 : options.body,
|
|
259
|
+
params: keySchema.params ? await parseStandardSchema(keySchema.params, options == null ? void 0 : options.params) : options == null ? void 0 : options.params,
|
|
260
|
+
query: keySchema.query ? await parseStandardSchema(keySchema.query, options == null ? void 0 : options.query) : options == null ? void 0 : options.query
|
|
261
|
+
});
|
|
262
|
+
return {
|
|
263
|
+
url,
|
|
264
|
+
options: opts
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return {
|
|
269
|
+
url,
|
|
270
|
+
options
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
var createFetch = (config) => {
|
|
275
|
+
async function $fetch(url, options) {
|
|
276
|
+
const opts = __spreadProps(__spreadValues(__spreadValues({}, config), options), { plugins: [...(config == null ? void 0 : config.plugins) || [], applySchemaPlugin(config || {})] });
|
|
277
|
+
if (config == null ? void 0 : config.catchAllError) try {
|
|
278
|
+
return await betterFetch(url, opts);
|
|
279
|
+
} catch (error) {
|
|
280
|
+
return {
|
|
281
|
+
data: null,
|
|
282
|
+
error: {
|
|
283
|
+
status: 500,
|
|
284
|
+
statusText: "Fetch Error",
|
|
285
|
+
message: "Fetch related error. Captured by catchAllError option. See error property for more details.",
|
|
286
|
+
error
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
return await betterFetch(url, opts);
|
|
291
|
+
}
|
|
292
|
+
return $fetch;
|
|
293
|
+
};
|
|
294
|
+
function getURL2(url, option) {
|
|
295
|
+
let { baseURL, params, query } = option || {
|
|
296
|
+
query: {},
|
|
297
|
+
params: {},
|
|
298
|
+
baseURL: ""
|
|
299
|
+
};
|
|
300
|
+
let basePath = url.startsWith("http") ? url.split("/").slice(0, 3).join("/") : baseURL || "";
|
|
301
|
+
if (url.startsWith("@")) {
|
|
302
|
+
const m = url.toString().split("@")[1].split("/")[0];
|
|
303
|
+
if (methods.includes(m)) url = url.replace(`@${m}/`, "/");
|
|
304
|
+
}
|
|
305
|
+
if (!basePath.endsWith("/")) basePath += "/";
|
|
306
|
+
let [path, urlQuery] = url.replace(basePath, "").split("?");
|
|
307
|
+
const queryParams = new URLSearchParams(urlQuery);
|
|
308
|
+
for (const [key, value] of Object.entries(query || {})) {
|
|
309
|
+
if (value == null) continue;
|
|
310
|
+
queryParams.set(key, String(value));
|
|
311
|
+
}
|
|
312
|
+
if (params) if (Array.isArray(params)) {
|
|
313
|
+
const paramPaths = path.split("/").filter((p) => p.startsWith(":"));
|
|
314
|
+
for (const [index, key] of paramPaths.entries()) {
|
|
315
|
+
const value = params[index];
|
|
316
|
+
path = path.replace(key, value);
|
|
317
|
+
}
|
|
318
|
+
} else for (const [key, value] of Object.entries(params)) path = path.replace(`:${key}`, String(value));
|
|
319
|
+
path = path.split("/").map(encodeURIComponent).join("/");
|
|
320
|
+
if (path.startsWith("/")) path = path.slice(1);
|
|
321
|
+
let queryParamString = queryParams.toString();
|
|
322
|
+
queryParamString = queryParamString.length > 0 ? `?${queryParamString}`.replace(/\+/g, "%20") : "";
|
|
323
|
+
if (!basePath.startsWith("http")) return `${basePath}${path}${queryParamString}`;
|
|
324
|
+
return new URL(`${path}${queryParamString}`, basePath);
|
|
325
|
+
}
|
|
326
|
+
var betterFetch = async (url, options) => {
|
|
327
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
328
|
+
const { hooks, url: __url, options: opts } = await initializePlugins(url, options);
|
|
329
|
+
const fetch = getFetch(opts);
|
|
330
|
+
const controller = new AbortController();
|
|
331
|
+
const signal = (_a = opts.signal) != null ? _a : controller.signal;
|
|
332
|
+
const _url = getURL2(__url, opts);
|
|
333
|
+
const body = getBody(opts);
|
|
334
|
+
const headers = await getHeaders(opts);
|
|
335
|
+
const method = getMethod(__url, opts);
|
|
336
|
+
let context = __spreadProps(__spreadValues({}, opts), {
|
|
337
|
+
url: _url,
|
|
338
|
+
headers,
|
|
339
|
+
body,
|
|
340
|
+
method,
|
|
341
|
+
signal
|
|
342
|
+
});
|
|
343
|
+
for (const onRequest of hooks.onRequest) if (onRequest) {
|
|
344
|
+
const res = await onRequest(context);
|
|
345
|
+
if (res instanceof Object) context = res;
|
|
346
|
+
}
|
|
347
|
+
if ("pipeTo" in context && typeof context.pipeTo === "function" || typeof ((_b = options == null ? void 0 : options.body) == null ? void 0 : _b.pipe) === "function") {
|
|
348
|
+
if (!("duplex" in context)) context.duplex = "half";
|
|
349
|
+
}
|
|
350
|
+
const { clearTimeout: clearTimeout2 } = getTimeout(opts, controller);
|
|
351
|
+
let response = await fetch(context.url, context);
|
|
352
|
+
clearTimeout2();
|
|
353
|
+
const responseContext = {
|
|
354
|
+
response,
|
|
355
|
+
request: context
|
|
356
|
+
};
|
|
357
|
+
for (const onResponse of hooks.onResponse) if (onResponse) {
|
|
358
|
+
const r = await onResponse(__spreadProps(__spreadValues({}, responseContext), { response: ((_c = options == null ? void 0 : options.hookOptions) == null ? void 0 : _c.cloneResponse) ? response.clone() : response }));
|
|
359
|
+
if (r instanceof Response) response = r;
|
|
360
|
+
else if (r instanceof Object) response = r.response;
|
|
361
|
+
}
|
|
362
|
+
if (response.ok) {
|
|
363
|
+
if (!(context.method !== "HEAD")) return {
|
|
364
|
+
data: "",
|
|
365
|
+
error: null
|
|
366
|
+
};
|
|
367
|
+
const responseType = detectResponseType(response);
|
|
368
|
+
const successContext = {
|
|
369
|
+
data: "",
|
|
370
|
+
response,
|
|
371
|
+
request: context
|
|
372
|
+
};
|
|
373
|
+
if (responseType === "json" || responseType === "text") {
|
|
374
|
+
const text = await response.text();
|
|
375
|
+
successContext.data = await ((_d = context.jsonParser) != null ? _d : jsonParse)(text);
|
|
376
|
+
} else successContext.data = await response[responseType]();
|
|
377
|
+
if (context == null ? void 0 : context.output) {
|
|
378
|
+
if (context.output && !context.disableValidation) successContext.data = await parseStandardSchema(context.output, successContext.data);
|
|
379
|
+
}
|
|
380
|
+
for (const onSuccess of hooks.onSuccess) if (onSuccess) await onSuccess(__spreadProps(__spreadValues({}, successContext), { response: ((_e = options == null ? void 0 : options.hookOptions) == null ? void 0 : _e.cloneResponse) ? response.clone() : response }));
|
|
381
|
+
if (options == null ? void 0 : options.throw) return successContext.data;
|
|
382
|
+
return {
|
|
383
|
+
data: successContext.data,
|
|
384
|
+
error: null
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
const parser = (_f = options == null ? void 0 : options.jsonParser) != null ? _f : jsonParse;
|
|
388
|
+
const responseText = await response.text();
|
|
389
|
+
const isJSONResponse = isJSONParsable(responseText);
|
|
390
|
+
const errorObject = isJSONResponse ? await parser(responseText) : null;
|
|
391
|
+
const errorContext = {
|
|
392
|
+
response,
|
|
393
|
+
responseText,
|
|
394
|
+
request: context,
|
|
395
|
+
error: __spreadProps(__spreadValues({}, errorObject), {
|
|
396
|
+
status: response.status,
|
|
397
|
+
statusText: response.statusText
|
|
398
|
+
})
|
|
399
|
+
};
|
|
400
|
+
for (const onError of hooks.onError) if (onError) await onError(__spreadProps(__spreadValues({}, errorContext), { response: ((_g = options == null ? void 0 : options.hookOptions) == null ? void 0 : _g.cloneResponse) ? response.clone() : response }));
|
|
401
|
+
if (options == null ? void 0 : options.retry) {
|
|
402
|
+
const retryStrategy = createRetryStrategy(options.retry);
|
|
403
|
+
const _retryAttempt = (_h = options.retryAttempt) != null ? _h : 0;
|
|
404
|
+
if (await retryStrategy.shouldAttemptRetry(_retryAttempt, response)) {
|
|
405
|
+
for (const onRetry of hooks.onRetry) if (onRetry) await onRetry(responseContext);
|
|
406
|
+
const delay = retryStrategy.getDelay(_retryAttempt);
|
|
407
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
408
|
+
return await betterFetch(url, __spreadProps(__spreadValues({}, options), { retryAttempt: _retryAttempt + 1 }));
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
if (options == null ? void 0 : options.throw) throw new BetterFetchError(response.status, response.statusText, isJSONResponse ? errorObject : responseText);
|
|
412
|
+
return {
|
|
413
|
+
data: null,
|
|
414
|
+
error: __spreadProps(__spreadValues({}, errorObject), {
|
|
415
|
+
status: response.status,
|
|
416
|
+
statusText: response.statusText
|
|
417
|
+
})
|
|
418
|
+
};
|
|
419
|
+
};
|
|
420
|
+
|
|
421
|
+
//#endregion
|
|
422
|
+
export { createFetch as n, betterFetch as t };
|