@nvwa-app/sdk-core 0.4.2 → 0.4.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/index.d.mts +7 -3
- package/dist/index.d.ts +7 -3
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -708
- package/package.json +16 -5
- package/dist/index.cjs +0 -729
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -218
- package/dist/index.mjs.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,708 +1 @@
|
|
|
1
|
-
import { createAuthClient } from 'better-auth/client';
|
|
2
|
-
import { usernameClient } from 'better-auth/client/plugins';
|
|
3
|
-
import { PostgrestClient, FetchResponse as FetchResponse$1 } from '@nvwa-app/postgrest-js';
|
|
4
|
-
|
|
5
|
-
var __defProp$7 = Object.defineProperty;
|
|
6
|
-
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
-
var __publicField$7 = (obj, key, value) => __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
8
|
-
const AUTH_BASE_PATH = "/auth";
|
|
9
|
-
const LOGIN_TOKEN_KEY = "nvwa_login_token";
|
|
10
|
-
const LOGIN_USER_PROFILE_KEY = "nvwa_user_profile";
|
|
11
|
-
class NvwaAuthClient {
|
|
12
|
-
constructor(baseUrl, fetch, storage) {
|
|
13
|
-
__publicField$7(this, "storage");
|
|
14
|
-
__publicField$7(this, "authClient");
|
|
15
|
-
this.storage = storage;
|
|
16
|
-
this.authClient = createAuthClient({
|
|
17
|
-
baseUrl,
|
|
18
|
-
fetchOptions: {
|
|
19
|
-
// @ts-ignore
|
|
20
|
-
customFetchImpl: fetch,
|
|
21
|
-
auth: {
|
|
22
|
-
type: "Bearer",
|
|
23
|
-
token: () => storage.get(LOGIN_TOKEN_KEY)
|
|
24
|
-
},
|
|
25
|
-
onSuccess: (ctx) => {
|
|
26
|
-
const authToken = ctx.response.headers.get(
|
|
27
|
-
"set-auth-token"
|
|
28
|
-
);
|
|
29
|
-
if (authToken) {
|
|
30
|
-
storage.set(LOGIN_TOKEN_KEY, authToken);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
plugins: [
|
|
35
|
-
usernameClient()
|
|
36
|
-
]
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
async currentUser() {
|
|
40
|
-
return await this.storage.get(LOGIN_USER_PROFILE_KEY);
|
|
41
|
-
}
|
|
42
|
-
async signInWithUsername(username, password) {
|
|
43
|
-
const result = await this.authClient.signIn.username({
|
|
44
|
-
username,
|
|
45
|
-
password
|
|
46
|
-
});
|
|
47
|
-
this.saveSession(result);
|
|
48
|
-
}
|
|
49
|
-
saveSession(result) {
|
|
50
|
-
var _a, _b;
|
|
51
|
-
if (result.error) {
|
|
52
|
-
throw new Error(result.error.message);
|
|
53
|
-
}
|
|
54
|
-
this.storage.set(LOGIN_TOKEN_KEY, (_a = result.data) == null ? void 0 : _a.token);
|
|
55
|
-
this.storage.set(LOGIN_USER_PROFILE_KEY, (_b = result.data) == null ? void 0 : _b.user);
|
|
56
|
-
}
|
|
57
|
-
async signOut() {
|
|
58
|
-
await this.storage.remove(LOGIN_TOKEN_KEY);
|
|
59
|
-
await this.storage.remove(LOGIN_USER_PROFILE_KEY);
|
|
60
|
-
}
|
|
61
|
-
async updateUserPassword(oldPassword, newPassword, revokeOtherSessions = false) {
|
|
62
|
-
const result = await this.authClient.changePassword({
|
|
63
|
-
currentPassword: oldPassword,
|
|
64
|
-
newPassword,
|
|
65
|
-
revokeOtherSessions
|
|
66
|
-
});
|
|
67
|
-
this.saveSession(result);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
var __defProp$6 = Object.defineProperty;
|
|
72
|
-
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
73
|
-
var __publicField$6 = (obj, key, value) => __defNormalProp$6(obj, key + "" , value);
|
|
74
|
-
class NvwaEdgeFunctions {
|
|
75
|
-
constructor(http) {
|
|
76
|
-
__publicField$6(this, "http");
|
|
77
|
-
this.http = http;
|
|
78
|
-
}
|
|
79
|
-
async invoke(name, options) {
|
|
80
|
-
const response = await this.http.request(
|
|
81
|
-
"/functions/" + name,
|
|
82
|
-
{
|
|
83
|
-
method: options.method || "POST",
|
|
84
|
-
data: options.body,
|
|
85
|
-
headers: options.headers
|
|
86
|
-
}
|
|
87
|
-
);
|
|
88
|
-
return response.body;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
var __defProp$5 = Object.defineProperty;
|
|
93
|
-
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
94
|
-
var __publicField$5 = (obj, key, value) => __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
95
|
-
class FetchResponse {
|
|
96
|
-
constructor(ok, status, statusText, headers, body) {
|
|
97
|
-
__publicField$5(this, "ok");
|
|
98
|
-
__publicField$5(this, "status");
|
|
99
|
-
__publicField$5(this, "statusText");
|
|
100
|
-
__publicField$5(this, "headers");
|
|
101
|
-
__publicField$5(this, "body");
|
|
102
|
-
this.ok = ok;
|
|
103
|
-
this.status = status;
|
|
104
|
-
this.statusText = statusText;
|
|
105
|
-
this.headers = headers;
|
|
106
|
-
this.body = body;
|
|
107
|
-
}
|
|
108
|
-
async text() {
|
|
109
|
-
if (typeof this.body === "string") {
|
|
110
|
-
return this.body;
|
|
111
|
-
}
|
|
112
|
-
return JSON.stringify(this.body);
|
|
113
|
-
}
|
|
114
|
-
async json() {
|
|
115
|
-
if (typeof this.body === "string") {
|
|
116
|
-
try {
|
|
117
|
-
return JSON.parse(this.body);
|
|
118
|
-
} catch {
|
|
119
|
-
return this.body;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return this.body;
|
|
123
|
-
}
|
|
124
|
-
async arrayBuffer() {
|
|
125
|
-
if (this.body instanceof ArrayBuffer) {
|
|
126
|
-
return this.body;
|
|
127
|
-
}
|
|
128
|
-
if (typeof this.body === "string") {
|
|
129
|
-
const encoder = new TextEncoder();
|
|
130
|
-
return encoder.encode(this.body).buffer;
|
|
131
|
-
}
|
|
132
|
-
throw new Error("Cannot convert body to ArrayBuffer");
|
|
133
|
-
}
|
|
134
|
-
async blob() {
|
|
135
|
-
if (this.body instanceof Blob) {
|
|
136
|
-
return this.body;
|
|
137
|
-
}
|
|
138
|
-
if (typeof this.body === "string") {
|
|
139
|
-
return new Blob([this.body], { type: this.headers["content-type"] || "text/plain" });
|
|
140
|
-
}
|
|
141
|
-
throw new Error("Cannot convert body to Blob");
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
class NvwaHttpClient {
|
|
145
|
-
// 便捷方法:发送 JSON 请求
|
|
146
|
-
async jsonRequest(url, request) {
|
|
147
|
-
const jsonRequest = {
|
|
148
|
-
...request,
|
|
149
|
-
headers: {
|
|
150
|
-
"Content-Type": "application/json",
|
|
151
|
-
...request.headers
|
|
152
|
-
},
|
|
153
|
-
data: typeof request.data === "object" ? JSON.stringify(request.data) : request.data
|
|
154
|
-
};
|
|
155
|
-
return this.request(url, jsonRequest);
|
|
156
|
-
}
|
|
157
|
-
// 便捷方法:发送带认证的 JSON 请求
|
|
158
|
-
async jsonRequestWithAuth(url, request, handleUnauthorized) {
|
|
159
|
-
const jsonRequest = {
|
|
160
|
-
...request,
|
|
161
|
-
headers: {
|
|
162
|
-
"Content-Type": "application/json",
|
|
163
|
-
...request.headers
|
|
164
|
-
},
|
|
165
|
-
data: typeof request.data === "object" ? JSON.stringify(request.data) : request.data
|
|
166
|
-
};
|
|
167
|
-
return this.requestWithAuth(url, jsonRequest, handleUnauthorized);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
var __defProp$4 = Object.defineProperty;
|
|
172
|
-
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
173
|
-
var __publicField$4 = (obj, key, value) => __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
174
|
-
const FILE_STORAGE_BASE_PATH = "/storage";
|
|
175
|
-
const GENERATE_UPLOAD_URL_PATH = FILE_STORAGE_BASE_PATH + "/generateUploadUrl";
|
|
176
|
-
class NvwaFileStorage {
|
|
177
|
-
constructor(baseUrl, http) {
|
|
178
|
-
__publicField$4(this, "baseUrl");
|
|
179
|
-
__publicField$4(this, "http");
|
|
180
|
-
this.baseUrl = baseUrl;
|
|
181
|
-
this.http = http;
|
|
182
|
-
}
|
|
183
|
-
async uploadFile(file) {
|
|
184
|
-
const uploadUrlResponse = await this.http.request(
|
|
185
|
-
this.baseUrl + GENERATE_UPLOAD_URL_PATH,
|
|
186
|
-
{
|
|
187
|
-
method: "POST",
|
|
188
|
-
data: {
|
|
189
|
-
fileName: file.name || file.fileName,
|
|
190
|
-
fileSize: file.size || file.fileSize,
|
|
191
|
-
fileType: file.type || file.fileType
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
);
|
|
195
|
-
const { url: uploadUrl } = uploadUrlResponse.body;
|
|
196
|
-
if (!uploadUrl) {
|
|
197
|
-
throw new Error("\u83B7\u53D6\u4E0A\u4F20URL\u5931\u8D25");
|
|
198
|
-
}
|
|
199
|
-
const uploadResult = await this.http.request(
|
|
200
|
-
uploadUrl,
|
|
201
|
-
{
|
|
202
|
-
method: "PUT",
|
|
203
|
-
data: file,
|
|
204
|
-
headers: {
|
|
205
|
-
"Content-Type": file.type || file.fileType || "application/octet-stream"
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
);
|
|
209
|
-
const fileUrl = uploadResult.body.url.split("?")[0];
|
|
210
|
-
return { url: fileUrl };
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
const ENTITIES_BASE_PATH = "/entities";
|
|
215
|
-
const buildPostgrestFetch = (httpClient, handleUnauthorized) => {
|
|
216
|
-
const customFetch = async (input, init) => {
|
|
217
|
-
console.log("customFetch", input, init);
|
|
218
|
-
let url;
|
|
219
|
-
if (typeof input === "string") {
|
|
220
|
-
url = input;
|
|
221
|
-
} else if (input && typeof input === "object") {
|
|
222
|
-
if (typeof input.toString === "function" && !input.url) {
|
|
223
|
-
url = input.toString();
|
|
224
|
-
} else if (input.url) {
|
|
225
|
-
url = input.url;
|
|
226
|
-
if (!init) {
|
|
227
|
-
init = {};
|
|
228
|
-
}
|
|
229
|
-
init.method = input.method;
|
|
230
|
-
init.headers = input.headers;
|
|
231
|
-
init.body = input.body;
|
|
232
|
-
} else {
|
|
233
|
-
throw new Error("Unsupported input type for fetch");
|
|
234
|
-
}
|
|
235
|
-
} else {
|
|
236
|
-
throw new Error("Unsupported input type for fetch");
|
|
237
|
-
}
|
|
238
|
-
const method = ((init == null ? void 0 : init.method) || "GET").toUpperCase();
|
|
239
|
-
const headers = {};
|
|
240
|
-
if (init == null ? void 0 : init.headers) {
|
|
241
|
-
if (init.headers && typeof init.headers.forEach === "function") {
|
|
242
|
-
init.headers.forEach((v, k) => {
|
|
243
|
-
headers[k] = v;
|
|
244
|
-
});
|
|
245
|
-
} else if (Array.isArray(init.headers)) {
|
|
246
|
-
for (const [k, v] of init.headers) headers[k] = v;
|
|
247
|
-
} else {
|
|
248
|
-
Object.assign(headers, init.headers);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
let body = init == null ? void 0 : init.body;
|
|
252
|
-
let response;
|
|
253
|
-
try {
|
|
254
|
-
response = await httpClient.requestWithAuth(url, {
|
|
255
|
-
method,
|
|
256
|
-
data: body,
|
|
257
|
-
headers
|
|
258
|
-
}, handleUnauthorized);
|
|
259
|
-
} catch (e) {
|
|
260
|
-
return new FetchResponse$1((e == null ? void 0 : e.message) || "Internal Error", {
|
|
261
|
-
status: 500,
|
|
262
|
-
statusText: "Internal Error"
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
let responseBody = response.body;
|
|
266
|
-
let responseData = null;
|
|
267
|
-
const contentType = response.headers["content-type"] || response.headers["Content-Type"] || "";
|
|
268
|
-
if (contentType.startsWith("application/json") && typeof responseBody !== "string") {
|
|
269
|
-
responseData = JSON.stringify(responseBody);
|
|
270
|
-
} else if (typeof responseBody === "string") {
|
|
271
|
-
responseData = responseBody;
|
|
272
|
-
} else if (responseBody && (responseBody.constructor === Blob || responseBody.constructor === ArrayBuffer || typeof responseBody.getReader === "function")) {
|
|
273
|
-
responseData = responseBody;
|
|
274
|
-
} else {
|
|
275
|
-
responseData = JSON.stringify(responseBody);
|
|
276
|
-
}
|
|
277
|
-
return new FetchResponse$1(responseData, {
|
|
278
|
-
status: response.status,
|
|
279
|
-
headers: response.headers
|
|
280
|
-
});
|
|
281
|
-
};
|
|
282
|
-
return customFetch;
|
|
283
|
-
};
|
|
284
|
-
const createPostgrestClient = (baseUrl, httpClient, handleUnauthorized) => {
|
|
285
|
-
return new PostgrestClient(baseUrl + ENTITIES_BASE_PATH, {
|
|
286
|
-
fetch: buildPostgrestFetch(httpClient, handleUnauthorized)
|
|
287
|
-
});
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
var __defProp$3 = Object.defineProperty;
|
|
291
|
-
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
292
|
-
var __publicField$3 = (obj, key, value) => __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
293
|
-
class Headers {
|
|
294
|
-
constructor(init) {
|
|
295
|
-
__publicField$3(this, "headerMap", /* @__PURE__ */ new Map());
|
|
296
|
-
if (!init) return;
|
|
297
|
-
if (init instanceof Headers) {
|
|
298
|
-
init.forEach((v, k) => this.set(k, v));
|
|
299
|
-
} else if (Array.isArray(init)) {
|
|
300
|
-
for (const [k, v] of init) this.set(k, String(v));
|
|
301
|
-
} else if (typeof init === "object") {
|
|
302
|
-
for (const k of Object.keys(init)) this.set(k, String(init[k]));
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
append(name, value) {
|
|
306
|
-
const key = name.toLowerCase();
|
|
307
|
-
const existing = this.headerMap.get(key);
|
|
308
|
-
this.headerMap.set(key, existing ? `${existing}, ${value}` : value);
|
|
309
|
-
}
|
|
310
|
-
set(name, value) {
|
|
311
|
-
this.headerMap.set(name.toLowerCase(), String(value));
|
|
312
|
-
}
|
|
313
|
-
get(name) {
|
|
314
|
-
const v = this.headerMap.get(name.toLowerCase());
|
|
315
|
-
return v == null ? null : v;
|
|
316
|
-
}
|
|
317
|
-
has(name) {
|
|
318
|
-
return this.headerMap.has(name.toLowerCase());
|
|
319
|
-
}
|
|
320
|
-
delete(name) {
|
|
321
|
-
this.headerMap.delete(name.toLowerCase());
|
|
322
|
-
}
|
|
323
|
-
forEach(callback) {
|
|
324
|
-
for (const [k, v] of this.headerMap.entries()) callback(v, k, this);
|
|
325
|
-
}
|
|
326
|
-
entries() {
|
|
327
|
-
return this.headerMap.entries();
|
|
328
|
-
}
|
|
329
|
-
keys() {
|
|
330
|
-
return this.headerMap.keys();
|
|
331
|
-
}
|
|
332
|
-
values() {
|
|
333
|
-
return this.headerMap.values();
|
|
334
|
-
}
|
|
335
|
-
[Symbol.iterator]() {
|
|
336
|
-
return this.entries();
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
class URLSearchParams {
|
|
340
|
-
constructor(init) {
|
|
341
|
-
__publicField$3(this, "params", /* @__PURE__ */ new Map());
|
|
342
|
-
if (init) {
|
|
343
|
-
if (typeof init === "string") {
|
|
344
|
-
this.parseString(init);
|
|
345
|
-
} else if (init instanceof URLSearchParams) {
|
|
346
|
-
this.params = new Map(init.params);
|
|
347
|
-
} else if (Array.isArray(init)) {
|
|
348
|
-
for (const [key, value] of init) {
|
|
349
|
-
this.append(key, value);
|
|
350
|
-
}
|
|
351
|
-
} else if (init && typeof init === "object") {
|
|
352
|
-
for (const [key, value] of Object.entries(init)) {
|
|
353
|
-
this.set(key, value);
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
parseString(search) {
|
|
359
|
-
if (search.startsWith("?")) {
|
|
360
|
-
search = search.slice(1);
|
|
361
|
-
}
|
|
362
|
-
const pairs = search.split("&");
|
|
363
|
-
for (const pair of pairs) {
|
|
364
|
-
if (pair) {
|
|
365
|
-
const [key, value] = pair.split("=");
|
|
366
|
-
if (key) {
|
|
367
|
-
this.append(
|
|
368
|
-
decodeURIComponent(key),
|
|
369
|
-
value ? decodeURIComponent(value) : ""
|
|
370
|
-
);
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
append(name, value) {
|
|
376
|
-
const existing = this.params.get(name) || [];
|
|
377
|
-
existing.push(value);
|
|
378
|
-
this.params.set(name, existing);
|
|
379
|
-
}
|
|
380
|
-
delete(name) {
|
|
381
|
-
this.params.delete(name);
|
|
382
|
-
}
|
|
383
|
-
get(name) {
|
|
384
|
-
const values = this.params.get(name);
|
|
385
|
-
return values ? values[0] : null;
|
|
386
|
-
}
|
|
387
|
-
getAll(name) {
|
|
388
|
-
return this.params.get(name) || [];
|
|
389
|
-
}
|
|
390
|
-
has(name) {
|
|
391
|
-
return this.params.has(name);
|
|
392
|
-
}
|
|
393
|
-
set(name, value) {
|
|
394
|
-
this.params.set(name, [value]);
|
|
395
|
-
}
|
|
396
|
-
sort() {
|
|
397
|
-
const sortedEntries = Array.from(this.params.entries()).sort(([a], [b]) => a.localeCompare(b));
|
|
398
|
-
this.params = new Map(sortedEntries);
|
|
399
|
-
}
|
|
400
|
-
toString() {
|
|
401
|
-
const pairs = [];
|
|
402
|
-
for (const [name, values] of this.params.entries()) {
|
|
403
|
-
for (const value of values) {
|
|
404
|
-
pairs.push(
|
|
405
|
-
`${encodeURIComponent(name)}=${encodeURIComponent(value)}`
|
|
406
|
-
);
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
return pairs.join("&");
|
|
410
|
-
}
|
|
411
|
-
forEach(callback) {
|
|
412
|
-
for (const [name, values] of this.params.entries()) {
|
|
413
|
-
for (const value of values) {
|
|
414
|
-
callback(value, name, this);
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
keys() {
|
|
419
|
-
return this.params.keys();
|
|
420
|
-
}
|
|
421
|
-
values() {
|
|
422
|
-
const allValues = [];
|
|
423
|
-
for (const values of this.params.values()) {
|
|
424
|
-
allValues.push(...values);
|
|
425
|
-
}
|
|
426
|
-
return allValues[Symbol.iterator]();
|
|
427
|
-
}
|
|
428
|
-
entries() {
|
|
429
|
-
const allEntries = [];
|
|
430
|
-
for (const [name, values] of this.params.entries()) {
|
|
431
|
-
for (const value of values) {
|
|
432
|
-
allEntries.push([name, value]);
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
return allEntries[Symbol.iterator]();
|
|
436
|
-
}
|
|
437
|
-
[Symbol.iterator]() {
|
|
438
|
-
return this.entries();
|
|
439
|
-
}
|
|
440
|
-
get size() {
|
|
441
|
-
return this.params.size;
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
class URL {
|
|
445
|
-
constructor(url, base) {
|
|
446
|
-
__publicField$3(this, "href");
|
|
447
|
-
__publicField$3(this, "origin");
|
|
448
|
-
__publicField$3(this, "protocol");
|
|
449
|
-
__publicField$3(this, "username");
|
|
450
|
-
__publicField$3(this, "password");
|
|
451
|
-
__publicField$3(this, "host");
|
|
452
|
-
__publicField$3(this, "hostname");
|
|
453
|
-
__publicField$3(this, "port");
|
|
454
|
-
__publicField$3(this, "pathname");
|
|
455
|
-
__publicField$3(this, "search");
|
|
456
|
-
__publicField$3(this, "searchParams");
|
|
457
|
-
__publicField$3(this, "hash");
|
|
458
|
-
let urlString;
|
|
459
|
-
if (url instanceof URL) {
|
|
460
|
-
urlString = url.href;
|
|
461
|
-
} else if (base) {
|
|
462
|
-
const baseUrl = base instanceof URL ? base.href : base;
|
|
463
|
-
urlString = this.resolve(baseUrl, url);
|
|
464
|
-
} else {
|
|
465
|
-
urlString = url;
|
|
466
|
-
}
|
|
467
|
-
const parsed = this.parseUrl(urlString);
|
|
468
|
-
this.href = urlString;
|
|
469
|
-
this.origin = `${parsed.protocol}//${parsed.host}`;
|
|
470
|
-
this.protocol = parsed.protocol;
|
|
471
|
-
this.username = parsed.username;
|
|
472
|
-
this.password = parsed.password;
|
|
473
|
-
this.host = parsed.host;
|
|
474
|
-
this.hostname = parsed.hostname;
|
|
475
|
-
this.port = parsed.port;
|
|
476
|
-
this.pathname = parsed.pathname;
|
|
477
|
-
this.search = parsed.search;
|
|
478
|
-
this.searchParams = new URLSearchParams(parsed.search);
|
|
479
|
-
this.hash = parsed.hash;
|
|
480
|
-
}
|
|
481
|
-
resolve(base, relative) {
|
|
482
|
-
if (relative.startsWith("http://") || relative.startsWith("https://")) {
|
|
483
|
-
return relative;
|
|
484
|
-
}
|
|
485
|
-
if (relative.startsWith("//")) {
|
|
486
|
-
const baseParsed2 = this.parseUrl(base);
|
|
487
|
-
return `${baseParsed2.protocol}${relative}`;
|
|
488
|
-
}
|
|
489
|
-
if (relative.startsWith("/")) {
|
|
490
|
-
const baseParsed2 = this.parseUrl(base);
|
|
491
|
-
return `${baseParsed2.protocol}//${baseParsed2.host}${relative}`;
|
|
492
|
-
}
|
|
493
|
-
const baseParsed = this.parseUrl(base);
|
|
494
|
-
const basePath = baseParsed.pathname.endsWith("/") ? baseParsed.pathname : baseParsed.pathname + "/";
|
|
495
|
-
return `${baseParsed.protocol}//${baseParsed.host}${basePath}${relative}`;
|
|
496
|
-
}
|
|
497
|
-
parseUrl(url) {
|
|
498
|
-
const urlMatch = url.match(
|
|
499
|
-
/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/
|
|
500
|
-
);
|
|
501
|
-
if (!urlMatch) {
|
|
502
|
-
throw new TypeError("Invalid URL");
|
|
503
|
-
}
|
|
504
|
-
const protocol = urlMatch[2] || "";
|
|
505
|
-
const authority = urlMatch[4] || "";
|
|
506
|
-
const pathname = urlMatch[5] || "/";
|
|
507
|
-
const search = urlMatch[7] ? `?${urlMatch[7]}` : "";
|
|
508
|
-
const hash = urlMatch[9] ? `#${urlMatch[9]}` : "";
|
|
509
|
-
if (!protocol && !authority && !pathname.startsWith("/")) {
|
|
510
|
-
if (!pathname.includes("/") && !pathname.includes(".")) {
|
|
511
|
-
throw new TypeError("Invalid URL");
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
const authMatch = authority.match(/^([^@]*)@(.+)$/);
|
|
515
|
-
let username = "";
|
|
516
|
-
let password = "";
|
|
517
|
-
let host = authority;
|
|
518
|
-
if (authMatch) {
|
|
519
|
-
const userInfo = authMatch[1];
|
|
520
|
-
host = authMatch[2];
|
|
521
|
-
const userMatch = userInfo.match(/^([^:]*):?(.*)$/);
|
|
522
|
-
if (userMatch) {
|
|
523
|
-
username = userMatch[1] || "";
|
|
524
|
-
password = userMatch[2] || "";
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
const hostMatch = host.match(/^([^:]+):?(\d*)$/);
|
|
528
|
-
const hostname = hostMatch ? hostMatch[1] : host;
|
|
529
|
-
const port = hostMatch && hostMatch[2] ? hostMatch[2] : "";
|
|
530
|
-
return {
|
|
531
|
-
protocol: protocol ? `${protocol}:` : "",
|
|
532
|
-
username,
|
|
533
|
-
password,
|
|
534
|
-
host,
|
|
535
|
-
hostname,
|
|
536
|
-
port,
|
|
537
|
-
pathname,
|
|
538
|
-
search,
|
|
539
|
-
hash
|
|
540
|
-
};
|
|
541
|
-
}
|
|
542
|
-
toString() {
|
|
543
|
-
const searchString = this.searchParams.toString();
|
|
544
|
-
const search = searchString ? `?${searchString}` : "";
|
|
545
|
-
return `${this.protocol}//${this.host}${this.pathname}${search}${this.hash}`;
|
|
546
|
-
}
|
|
547
|
-
toJSON() {
|
|
548
|
-
return this.toString();
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
var __defProp$2 = Object.defineProperty;
|
|
553
|
-
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
554
|
-
var __publicField$2 = (obj, key, value) => __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
555
|
-
class Request {
|
|
556
|
-
constructor(input, init) {
|
|
557
|
-
__publicField$2(this, "url");
|
|
558
|
-
__publicField$2(this, "method");
|
|
559
|
-
__publicField$2(this, "headers");
|
|
560
|
-
__publicField$2(this, "body");
|
|
561
|
-
__publicField$2(this, "timeout");
|
|
562
|
-
__publicField$2(this, "signal");
|
|
563
|
-
if (typeof input === "string") {
|
|
564
|
-
this.url = input;
|
|
565
|
-
} else if (input == null ? void 0 : input.url) {
|
|
566
|
-
this.url = String(input.url);
|
|
567
|
-
} else if (typeof (input == null ? void 0 : input.toString) === "function") {
|
|
568
|
-
this.url = String(input.toString());
|
|
569
|
-
} else {
|
|
570
|
-
throw new Error("Invalid input for Request");
|
|
571
|
-
}
|
|
572
|
-
this.method = ((init == null ? void 0 : init.method) || "GET").toUpperCase();
|
|
573
|
-
this.headers = (init == null ? void 0 : init.headers) instanceof Headers ? init.headers : new Headers(init == null ? void 0 : init.headers);
|
|
574
|
-
this.body = init == null ? void 0 : init.body;
|
|
575
|
-
this.timeout = init == null ? void 0 : init.timeout;
|
|
576
|
-
this.signal = (init == null ? void 0 : init.signal) || void 0;
|
|
577
|
-
}
|
|
578
|
-
clone() {
|
|
579
|
-
return new Request(this.url, {
|
|
580
|
-
method: this.method,
|
|
581
|
-
headers: this.headers,
|
|
582
|
-
body: this.body,
|
|
583
|
-
timeout: this.timeout
|
|
584
|
-
});
|
|
585
|
-
}
|
|
586
|
-
toString() {
|
|
587
|
-
return this.url;
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
var __defProp$1 = Object.defineProperty;
|
|
592
|
-
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
593
|
-
var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
594
|
-
class Response {
|
|
595
|
-
constructor(body, init) {
|
|
596
|
-
__publicField$1(this, "bodyData");
|
|
597
|
-
__publicField$1(this, "status");
|
|
598
|
-
__publicField$1(this, "statusText");
|
|
599
|
-
__publicField$1(this, "headers");
|
|
600
|
-
__publicField$1(this, "ok");
|
|
601
|
-
var _a, _b;
|
|
602
|
-
this.bodyData = body;
|
|
603
|
-
this.status = (_a = init == null ? void 0 : init.status) != null ? _a : 200;
|
|
604
|
-
this.statusText = (_b = init == null ? void 0 : init.statusText) != null ? _b : "";
|
|
605
|
-
this.headers = normalizeHeaders(init == null ? void 0 : init.headers);
|
|
606
|
-
this.ok = this.status >= 200 && this.status < 300;
|
|
607
|
-
}
|
|
608
|
-
async text() {
|
|
609
|
-
if (typeof this.bodyData === "string") return this.bodyData;
|
|
610
|
-
if (this.bodyData == null) return "";
|
|
611
|
-
if (typeof this.bodyData === "object") return JSON.stringify(this.bodyData);
|
|
612
|
-
return String(this.bodyData);
|
|
613
|
-
}
|
|
614
|
-
async json() {
|
|
615
|
-
if (typeof this.bodyData === "string") {
|
|
616
|
-
try {
|
|
617
|
-
return JSON.parse(this.bodyData);
|
|
618
|
-
} catch {
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
return this.bodyData;
|
|
622
|
-
}
|
|
623
|
-
async arrayBuffer() {
|
|
624
|
-
const text = await this.text();
|
|
625
|
-
const encoder = new TextEncoder();
|
|
626
|
-
return encoder.encode(text).buffer;
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
function normalizeHeaders(h) {
|
|
630
|
-
if (!h) return new Headers();
|
|
631
|
-
return new Headers(h);
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
var __defProp = Object.defineProperty;
|
|
635
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
636
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
637
|
-
class AbortSignal {
|
|
638
|
-
constructor() {
|
|
639
|
-
__publicField(this, "_aborted", false);
|
|
640
|
-
__publicField(this, "listeners", /* @__PURE__ */ new Set());
|
|
641
|
-
__publicField(this, "onabort", null);
|
|
642
|
-
}
|
|
643
|
-
get aborted() {
|
|
644
|
-
return this._aborted;
|
|
645
|
-
}
|
|
646
|
-
// 供控制器触发
|
|
647
|
-
_trigger() {
|
|
648
|
-
if (this._aborted) return;
|
|
649
|
-
this._aborted = true;
|
|
650
|
-
if (typeof this.onabort === "function") {
|
|
651
|
-
try {
|
|
652
|
-
this.onabort();
|
|
653
|
-
} catch {
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
for (const l of Array.from(this.listeners)) {
|
|
657
|
-
try {
|
|
658
|
-
l();
|
|
659
|
-
} catch {
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
this.listeners.clear();
|
|
663
|
-
}
|
|
664
|
-
addEventListener(_, listener) {
|
|
665
|
-
if (this._aborted) {
|
|
666
|
-
try {
|
|
667
|
-
listener();
|
|
668
|
-
} catch {
|
|
669
|
-
}
|
|
670
|
-
return;
|
|
671
|
-
}
|
|
672
|
-
this.listeners.add(listener);
|
|
673
|
-
}
|
|
674
|
-
removeEventListener(_, listener) {
|
|
675
|
-
this.listeners.delete(listener);
|
|
676
|
-
}
|
|
677
|
-
toString() {
|
|
678
|
-
return "[object AbortSignal]";
|
|
679
|
-
}
|
|
680
|
-
}
|
|
681
|
-
class AbortController {
|
|
682
|
-
constructor() {
|
|
683
|
-
__publicField(this, "_signal");
|
|
684
|
-
this._signal = new AbortSignal();
|
|
685
|
-
}
|
|
686
|
-
get signal() {
|
|
687
|
-
return this._signal;
|
|
688
|
-
}
|
|
689
|
-
abort() {
|
|
690
|
-
this._signal._trigger();
|
|
691
|
-
}
|
|
692
|
-
toString() {
|
|
693
|
-
return "[object AbortController]";
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
|
|
697
|
-
function polyfill(_global) {
|
|
698
|
-
_global.URL = URL;
|
|
699
|
-
_global.URLSearchParams = URLSearchParams;
|
|
700
|
-
_global.Headers = Headers;
|
|
701
|
-
_global.Request = Request;
|
|
702
|
-
_global.Response = Response;
|
|
703
|
-
_global.AbortController = AbortController;
|
|
704
|
-
_global.AbortSignal = AbortSignal;
|
|
705
|
-
}
|
|
706
|
-
|
|
707
|
-
export { AUTH_BASE_PATH, AbortController, AbortSignal, ENTITIES_BASE_PATH, FILE_STORAGE_BASE_PATH, FetchResponse, GENERATE_UPLOAD_URL_PATH, Headers, LOGIN_TOKEN_KEY, LOGIN_USER_PROFILE_KEY, NvwaAuthClient, NvwaEdgeFunctions, NvwaFileStorage, NvwaHttpClient, Request, Response, URL, URLSearchParams, createPostgrestClient, polyfill };
|
|
708
|
-
//# sourceMappingURL=index.mjs.map
|
|
1
|
+
var Ft=Object.create;var Xe=Object.defineProperty;var Ht=Object.getOwnPropertyDescriptor;var qt=Object.getOwnPropertyNames;var Wt=Object.getPrototypeOf,Gt=Object.prototype.hasOwnProperty;var zt=(r,e)=>()=>(r&&(e=r(r=0)),e);var H=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var Vt=(r,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of qt(e))!Gt.call(r,n)&&n!==t&&Xe(r,n,{get:()=>e[n],enumerable:!(s=Ht(e,n))||s.enumerable});return r};var Kt=(r,e,t)=>(t=r!=null?Ft(Wt(r)):{},Vt(e||!r||!r.__esModule?Xe(t,"default",{value:r,enumerable:!0}):t,r));import gs from"path";import{fileURLToPath as bs}from"url";var a=zt(()=>{"use strict"});var te=H(_=>{"use strict";a();Object.defineProperty(_,"__esModule",{value:!0});_.File=_.FormData=_.Blob=_.FetchResponse=_.URL=_.URLSearchParams=_.FetchHeaders=void 0;var Z=class{constructor(e){if(this.map=new Map,e)for(let[t,s]of Object.entries(e))this.set(t,s)}get(e){var t;return(t=this.map.get(e))!==null&&t!==void 0?t:null}set(e,t){this.map.set(e,t)}has(e){return this.map.has(e)}append(e,t){let s=this.map.get(e);s?this.map.set(e,`${s}${t}`):this.map.set(e,t)}delete(e){this.map.delete(e)}forEach(e){this.map.forEach(e)}size(){return this.map.size}keys(){return this.map.keys()}values(){return this.map.values()}entries(){return this.map.entries()}headers(){return Object.fromEntries(this.map.entries())}[Symbol.iterator](){return this.map[Symbol.iterator]()}};_.FetchHeaders=Z;var Re=class r{constructor(e){if(this.params=new Map,e){if(typeof e=="string")this.parseString(e);else if(e instanceof r)this.params=new Map(e.params);else if(Array.isArray(e))for(let[t,s]of e)this.append(t,s);else if(e&&typeof e=="object")for(let[t,s]of Object.entries(e))this.set(t,s)}}parseString(e){e.startsWith("?")&&(e=e.slice(1));let t=e.split("&");for(let s of t)if(s){let[n,o]=s.split("=");n&&this.append(decodeURIComponent(n),o?decodeURIComponent(o):"")}}append(e,t){let s=this.params.get(e)||[];s.push(t),this.params.set(e,s)}delete(e){this.params.delete(e)}get(e){let t=this.params.get(e);return t?t[0]:null}getAll(e){return this.params.get(e)||[]}has(e){return this.params.has(e)}set(e,t){this.params.set(e,[t])}sort(){let e=Array.from(this.params.entries()).sort(([t],[s])=>t.localeCompare(s));this.params=new Map(e)}toString(){let e=[];for(let[t,s]of this.params.entries())for(let n of s)e.push(`${encodeURIComponent(t)}=${encodeURIComponent(n)}`);return e.join("&")}forEach(e){for(let[t,s]of this.params.entries())for(let n of s)e(n,t,this)}keys(){return this.params.keys()}values(){let e=[];for(let t of this.params.values())e.push(...t);return e[Symbol.iterator]()}entries(){let e=[];for(let[t,s]of this.params.entries())for(let n of s)e.push([t,n]);return e[Symbol.iterator]()}[Symbol.iterator](){return this.entries()}get size(){return this.params.size}};_.URLSearchParams=Re;var we=class r{constructor(e,t){let s;if(e instanceof r)s=e.href;else if(t){let o=t instanceof r?t.href:t;s=this.resolve(o,e)}else s=e;let n=this.parseUrl(s);this.href=s,this.origin=`${n.protocol}//${n.host}`,this.protocol=n.protocol,this.username=n.username,this.password=n.password,this.host=n.host,this.hostname=n.hostname,this.port=n.port,this.pathname=n.pathname,this.search=n.search,this.searchParams=new Re(n.search),this.hash=n.hash}resolve(e,t){if(t.startsWith("http://")||t.startsWith("https://"))return t;if(t.startsWith("//"))return`${this.parseUrl(e).protocol}${t}`;if(t.startsWith("/")){let o=this.parseUrl(e);return`${o.protocol}//${o.host}${t}`}let s=this.parseUrl(e),n=s.pathname.endsWith("/")?s.pathname:s.pathname+"/";return`${s.protocol}//${s.host}${n}${t}`}parseUrl(e){let t=e.match(/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/);if(!t)throw new TypeError("Invalid URL");let s=t[2]||"",n=t[4]||"",o=t[5]||"/",i=t[7]?`?${t[7]}`:"",c=t[9]?`#${t[9]}`:"";if(!s&&!n&&!o.startsWith("/")&&!o.includes("/")&&!o.includes("."))throw new TypeError("Invalid URL");let d=n.match(/^([^@]*)@(.+)$/),u="",l="",h=n;if(d){let x=d[1];h=d[2];let b=x.match(/^([^:]*):?(.*)$/);b&&(u=b[1]||"",l=b[2]||"")}let m=h.match(/^([^:]+):?(\d*)$/),w=m?m[1]:h,v=m&&m[2]?m[2]:"";return{protocol:s?`${s}:`:"",username:u,password:l,host:h,hostname:w,port:v,pathname:o,search:i,hash:c}}toString(){let e=this.searchParams.toString(),t=e?`?${e}`:"";return`${this.protocol}//${this.host}${this.pathname}${t}${this.hash}`}toJSON(){return this.toString()}};_.URL=we;var De=class r{constructor(e,t){var s,n;this.status=(s=t?.status)!==null&&s!==void 0?s:200,this.statusText=(n=t?.statusText)!==null&&n!==void 0?n:"",this.headers=new Z(t?.headers),this.ok=this.status>=200&&this.status<300,this.redirected=!1,this.url="",this.bodyUsed=!1,this.body=e||null}async arrayBuffer(){if(this.bodyUsed)throw new TypeError("Body has already been consumed");return this.bodyUsed=!0,this.body===null?new ArrayBuffer(0):new TextEncoder().encode(this.body).buffer}async blob(){if(this.bodyUsed)throw new TypeError("Body has already been consumed");return this.bodyUsed=!0,new ee([this.body||""])}async formData(){if(this.bodyUsed)throw new TypeError("Body has already been consumed");return this.bodyUsed=!0,new Ee}async json(){if(this.bodyUsed)throw new TypeError("Body has already been consumed");return this.bodyUsed=!0,this.body===null?null:JSON.parse(this.body)}async text(){if(this.bodyUsed)throw new TypeError("Body has already been consumed");return this.bodyUsed=!0,this.body||""}clone(){if(this.bodyUsed)throw new TypeError("Body has already been consumed");return new r(this.body,{status:this.status,statusText:this.statusText,headers:this.headers.headers()})}static error(){let e=new r(null,{status:0,statusText:""});return Object.defineProperty(e,"type",{value:"error",writable:!1}),e}static redirect(e,t=302){let s=e instanceof we?e.href:e,n=new r(null,{status:t,statusText:"Found"});return n.headers.set("Location",s),n}static json(e,t){let s=JSON.stringify(e),n=new Z(t?.headers);return n.set("Content-Type","application/json"),new r(s,Object.assign(Object.assign({},t),{headers:n.headers()}))}};_.FetchResponse=De;var ee=class r{constructor(e,t){this._content=e||[],this.type=t?.type||"";let s=0;for(let n of this._content)typeof n=="string"?s+=new TextEncoder().encode(n).length:n instanceof ArrayBuffer?s+=n.byteLength:n instanceof Uint8Array&&(s+=n.length);this.size=s}async text(){let e="";for(let t of this._content)typeof t=="string"?e+=t:t instanceof ArrayBuffer?e+=new TextDecoder().decode(t):t instanceof Uint8Array&&(e+=new TextDecoder().decode(t));return e}async arrayBuffer(){let e=await this.text();return new TextEncoder().encode(e).buffer}slice(e,t,s){return new r(this._content.slice(e,t),{type:s})}};_.Blob=ee;var Ee=class{constructor(){this._entries=[]}append(e,t,s){this._entries.push([e,t])}delete(e){this._entries=this._entries.filter(([t])=>t!==e)}get(e){let t=this._entries.find(([s])=>s===e);return t?t[1]:null}getAll(e){return this._entries.filter(([t])=>t===e).map(([,t])=>t)}has(e){return this._entries.some(([t])=>t===e)}set(e,t,s){this.delete(e),this.append(e,t,s)}forEach(e){for(let[t,s]of this._entries)e(s,t,this)}keys(){return this._entries.map(([e])=>e)[Symbol.iterator]()}values(){return this._entries.map(([,e])=>e)[Symbol.iterator]()}entries(){return this._entries[Symbol.iterator]()}[Symbol.iterator](){return this.entries()}};_.FormData=Ee;var ke=class extends ee{constructor(e,t,s){super(e,s),this.name=t,this.lastModified=s?.lastModified||Date.now()}};_.File=ke});var je=H(Be=>{"use strict";a();Object.defineProperty(Be,"__esModule",{value:!0});var Me=class extends Error{constructor(e){super(e.message),this.name="PostgrestError",this.details=e.details,this.hint=e.hint,this.code=e.code}};Be.default=Me});var He=H(re=>{"use strict";a();var es=re&&re.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(re,"__esModule",{value:!0});var ts=es(je()),Pt=te(),Fe=class{constructor(e){var t,s;this.shouldThrowOnError=!1,this.method=e.method,this.url=e.url,this.headers=new Pt.FetchHeaders(e.headers),this.schema=e.schema,this.body=e.body,this.shouldThrowOnError=(t=e.shouldThrowOnError)!==null&&t!==void 0?t:!1,this.signal=e.signal,this.isMaybeSingle=(s=e.isMaybeSingle)!==null&&s!==void 0?s:!1,e.fetch?this.fetch=e.fetch:this.fetch=fetch}throwOnError(){return this.shouldThrowOnError=!0,this}setHeader(e,t){return this.headers=new Pt.FetchHeaders(this.headers),this.headers.set(e,t),this}then(e,t){this.schema===void 0||(["GET","HEAD"].includes(this.method)?this.headers.set("Accept-Profile",this.schema):this.headers.set("Content-Profile",this.schema)),this.method!=="GET"&&this.method!=="HEAD"&&this.headers.set("Content-Type","application/json");let s=this.fetch,n=s(this.url.toString(),{method:this.method,headers:this.headers.headers(),body:JSON.stringify(this.body),signal:this.signal}).then(async o=>{var i,c,d,u;let l=null,h=null,m=null,w=o.status,v=o.statusText;if(o.ok){if(this.method!=="HEAD"){let P=await o.text();P===""||(this.headers.get("Accept")==="text/csv"||this.headers.get("Accept")&&(!((i=this.headers.get("Accept"))===null||i===void 0)&&i.includes("application/vnd.pgrst.plan+text"))?h=P:h=JSON.parse(P))}let b=(c=this.headers.get("Prefer"))===null||c===void 0?void 0:c.match(/count=(exact|planned|estimated)/),U=(d=o.headers.get("content-range"))===null||d===void 0?void 0:d.split("/");b&&U&&U.length>1&&(m=parseInt(U[1])),this.isMaybeSingle&&this.method==="GET"&&Array.isArray(h)&&(h.length>1?(l={code:"PGRST116",details:`Results contain ${h.length} rows, application/vnd.pgrst.object+json requires 1 row`,hint:null,message:"JSON object requested, multiple (or no) rows returned"},h=null,m=null,w=406,v="Not Acceptable"):h.length===1?h=h[0]:h=null)}else{let b=await o.text();try{l=JSON.parse(b),Array.isArray(l)&&o.status===404&&(h=[],l=null,w=200,v="OK")}catch{o.status===404&&b===""?(w=204,v="No Content"):l={message:b}}if(l&&this.isMaybeSingle&&(!((u=l?.details)===null||u===void 0)&&u.includes("0 rows"))&&(l=null,w=200,v="OK"),l&&this.shouldThrowOnError)throw new ts.default(l)}return{error:l,data:h,count:m,status:w,statusText:v}});return this.shouldThrowOnError||(n=n.catch(o=>{var i,c,d;return{error:{message:`${(i=o?.name)!==null&&i!==void 0?i:"FetchError"}: ${o?.message}`,details:`${(c=o?.stack)!==null&&c!==void 0?c:""}`,hint:"",code:`${(d=o?.code)!==null&&d!==void 0?d:""}`},data:null,count:null,status:0,statusText:""}})),n.then(e,t)}returns(){return this}overrideTypes(){return this}};re.default=Fe});var We=H(se=>{"use strict";a();var rs=se&&se.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(se,"__esModule",{value:!0});var ss=rs(He()),qe=class extends ss.default{select(e){let t=!1,s=(e??"*").split("").map(n=>/\s/.test(n)&&!t?"":(n==='"'&&(t=!t),n)).join("");return this.url.searchParams.set("select",s),this.headers.append("Prefer","return=representation"),this}order(e,{ascending:t=!0,nullsFirst:s,foreignTable:n,referencedTable:o=n}={}){let i=o?`${o}.order`:"order",c=this.url.searchParams.get(i);return this.url.searchParams.set(i,`${c?`${c},`:""}${e}.${t?"asc":"desc"}${s===void 0?"":s?".nullsfirst":".nullslast"}`),this}limit(e,{foreignTable:t,referencedTable:s=t}={}){let n=typeof s>"u"?"limit":`${s}.limit`;return this.url.searchParams.set(n,`${e}`),this}range(e,t,{foreignTable:s,referencedTable:n=s}={}){let o=typeof n>"u"?"offset":`${n}.offset`,i=typeof n>"u"?"limit":`${n}.limit`;return this.url.searchParams.set(o,`${e}`),this.url.searchParams.set(i,`${t-e+1}`),this}abortSignal(e){return this.signal=e,this}single(){return this.headers.set("Accept","application/vnd.pgrst.object+json"),this}maybeSingle(){return this.method==="GET"?this.headers.set("Accept","application/json"):this.headers.set("Accept","application/vnd.pgrst.object+json"),this.isMaybeSingle=!0,this}csv(){return this.headers.set("Accept","text/csv"),this}geojson(){return this.headers.set("Accept","application/geo+json"),this}explain({analyze:e=!1,verbose:t=!1,settings:s=!1,buffers:n=!1,wal:o=!1,format:i="text"}={}){var c;let d=[e?"analyze":null,t?"verbose":null,s?"settings":null,n?"buffers":null,o?"wal":null].filter(Boolean).join("|"),u=(c=this.headers.get("Accept"))!==null&&c!==void 0?c:"application/json";return this.headers.set("Accept",`application/vnd.pgrst.plan+${i}; for="${u}"; options=${d};`),i==="json"?this:this}rollback(){return this.headers.append("Prefer","tx=rollback"),this}returns(){return this}maxAffected(e){return this.headers.append("Prefer","handling=strict"),this.headers.append("Prefer",`max-affected=${e}`),this}};se.default=qe});var ve=H(ne=>{"use strict";a();var ns=ne&&ne.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(ne,"__esModule",{value:!0});var os=ns(We()),Ge=class extends os.default{eq(e,t){return this.url.searchParams.append(e,`eq.${t}`),this}neq(e,t){return this.url.searchParams.append(e,`neq.${t}`),this}gt(e,t){return this.url.searchParams.append(e,`gt.${t}`),this}gte(e,t){return this.url.searchParams.append(e,`gte.${t}`),this}lt(e,t){return this.url.searchParams.append(e,`lt.${t}`),this}lte(e,t){return this.url.searchParams.append(e,`lte.${t}`),this}like(e,t){return this.url.searchParams.append(e,`like.${t}`),this}likeAllOf(e,t){return this.url.searchParams.append(e,`like(all).{${t.join(",")}}`),this}likeAnyOf(e,t){return this.url.searchParams.append(e,`like(any).{${t.join(",")}}`),this}ilike(e,t){return this.url.searchParams.append(e,`ilike.${t}`),this}ilikeAllOf(e,t){return this.url.searchParams.append(e,`ilike(all).{${t.join(",")}}`),this}ilikeAnyOf(e,t){return this.url.searchParams.append(e,`ilike(any).{${t.join(",")}}`),this}is(e,t){return this.url.searchParams.append(e,`is.${t}`),this}in(e,t){let s=Array.from(new Set(t)).map(n=>typeof n=="string"&&new RegExp("[,()]").test(n)?`"${n}"`:`${n}`).join(",");return this.url.searchParams.append(e,`in.(${s})`),this}contains(e,t){return typeof t=="string"?this.url.searchParams.append(e,`cs.${t}`):Array.isArray(t)?this.url.searchParams.append(e,`cs.{${t.join(",")}}`):this.url.searchParams.append(e,`cs.${JSON.stringify(t)}`),this}containedBy(e,t){return typeof t=="string"?this.url.searchParams.append(e,`cd.${t}`):Array.isArray(t)?this.url.searchParams.append(e,`cd.{${t.join(",")}}`):this.url.searchParams.append(e,`cd.${JSON.stringify(t)}`),this}rangeGt(e,t){return this.url.searchParams.append(e,`sr.${t}`),this}rangeGte(e,t){return this.url.searchParams.append(e,`nxl.${t}`),this}rangeLt(e,t){return this.url.searchParams.append(e,`sl.${t}`),this}rangeLte(e,t){return this.url.searchParams.append(e,`nxr.${t}`),this}rangeAdjacent(e,t){return this.url.searchParams.append(e,`adj.${t}`),this}overlaps(e,t){return typeof t=="string"?this.url.searchParams.append(e,`ov.${t}`):this.url.searchParams.append(e,`ov.{${t.join(",")}}`),this}textSearch(e,t,{config:s,type:n}={}){let o="";n==="plain"?o="pl":n==="phrase"?o="ph":n==="websearch"&&(o="w");let i=s===void 0?"":`(${s})`;return this.url.searchParams.append(e,`${o}fts${i}.${t}`),this}match(e){return Object.entries(e).forEach(([t,s])=>{this.url.searchParams.append(t,`eq.${s}`)}),this}not(e,t,s){return this.url.searchParams.append(e,`not.${t}.${s}`),this}or(e,{foreignTable:t,referencedTable:s=t}={}){let n=s?`${s}.or`:"or";return this.url.searchParams.append(n,`(${e})`),this}filter(e,t,s){return this.url.searchParams.append(e,`${t}.${s}`),this}};ne.default=Ge});var Ve=H(ae=>{"use strict";a();var as=ae&&ae.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(ae,"__esModule",{value:!0});var is=te(),oe=as(ve()),ze=class{constructor(e,{headers:t={},schema:s,fetch:n}){this.url=e,this.headers=new is.FetchHeaders(t),this.schema=s,this.fetch=n}select(e,t){let{head:s=!1,count:n}=t??{},o=s?"HEAD":"GET",i=!1,c=(e??"*").split("").map(d=>/\s/.test(d)&&!i?"":(d==='"'&&(i=!i),d)).join("");return this.url.searchParams.set("select",c),n&&this.headers.append("Prefer",`count=${n}`),new oe.default({method:o,url:this.url,headers:this.headers,schema:this.schema,fetch:this.fetch})}insert(e,{count:t,defaultToNull:s=!0}={}){var n;let o="POST";if(t&&this.headers.append("Prefer",`count=${t}`),s||this.headers.append("Prefer","missing=default"),Array.isArray(e)){let i=e.reduce((c,d)=>c.concat(Object.keys(d)),[]);if(i.length>0){let c=[...new Set(i)].map(d=>`"${d}"`);this.url.searchParams.set("columns",c.join(","))}}return new oe.default({method:o,url:this.url,headers:this.headers,schema:this.schema,body:e,fetch:(n=this.fetch)!==null&&n!==void 0?n:fetch})}upsert(e,{onConflict:t,ignoreDuplicates:s=!1,count:n,defaultToNull:o=!0}={}){var i;let c="POST";if(this.headers.append("Prefer",`resolution=${s?"ignore":"merge"}-duplicates`),t!==void 0&&this.url.searchParams.set("on_conflict",t),n&&this.headers.append("Prefer",`count=${n}`),o||this.headers.append("Prefer","missing=default"),Array.isArray(e)){let d=e.reduce((u,l)=>u.concat(Object.keys(l)),[]);if(d.length>0){let u=[...new Set(d)].map(l=>`"${l}"`);this.url.searchParams.set("columns",u.join(","))}}return new oe.default({method:c,url:this.url,headers:this.headers,schema:this.schema,body:e,fetch:(i=this.fetch)!==null&&i!==void 0?i:fetch})}update(e,{count:t}={}){var s;let n="PATCH";return t&&this.headers.append("Prefer",`count=${t}`),new oe.default({method:n,url:this.url,headers:this.headers,schema:this.schema,body:e,fetch:(s=this.fetch)!==null&&s!==void 0?s:fetch})}delete({count:e}={}){var t;let s="DELETE";return e&&this.headers.append("Prefer",`count=${e}`),new oe.default({method:s,url:this.url,headers:this.headers,schema:this.schema,fetch:(t=this.fetch)!==null&&t!==void 0?t:fetch})}};ae.default=ze});var Ot=H(le=>{"use strict";a();var At=le&&le.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(le,"__esModule",{value:!0});var ls=At(Ve()),cs=At(ve()),ie=te(),Ke=class r{constructor(e,{headers:t={},schema:s,fetch:n}={}){this.url=e,this.headers=new ie.FetchHeaders(t),this.schemaName=s,this.fetch=n}from(e){let t=new ie.URL(`${this.url}/${e}`);return new ls.default(t,{headers:new ie.FetchHeaders(this.headers),schema:this.schemaName,fetch:this.fetch})}schema(e){return new r(this.url,{headers:this.headers,schema:e,fetch:this.fetch})}rpc(e,t={},{head:s=!1,get:n=!1,count:o}={}){var i;let c,d=new ie.URL(`${this.url}/rpc/${e}`),u;s||n?(c=s?"HEAD":"GET",Object.entries(t).filter(([h,m])=>m!==void 0).map(([h,m])=>[h,Array.isArray(m)?`{${m.join(",")}}`:`${m}`]).forEach(([h,m])=>{d.searchParams.append(h,m)})):(c="POST",u=t);let l=new ie.FetchHeaders(this.headers);return o&&l.set("Prefer",`count=${o}`),new cs.default({method:c,url:d,headers:l,schema:this.schemaName,body:u,fetch:(i=this.fetch)!==null&&i!==void 0?i:fetch})}};le.default=Ke});var $t=H(y=>{"use strict";a();var V=y&&y.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(y,"__esModule",{value:!0});y.File=y.FormData=y.Blob=y.FetchResponse=y.FetchHeaders=y.URLSearchParams=y.URL=y.PostgrestError=y.PostgrestBuilder=y.PostgrestTransformBuilder=y.PostgrestFilterBuilder=y.PostgrestQueryBuilder=y.PostgrestClient=void 0;var Ut=V(Ot());y.PostgrestClient=Ut.default;var It=V(Ve());y.PostgrestQueryBuilder=It.default;var xt=V(ve());y.PostgrestFilterBuilder=xt.default;var Ct=V(We());y.PostgrestTransformBuilder=Ct.default;var Nt=V(He());y.PostgrestBuilder=Nt.default;var Lt=V(je());y.PostgrestError=Lt.default;var k=te();Object.defineProperty(y,"FetchHeaders",{enumerable:!0,get:function(){return k.FetchHeaders}});Object.defineProperty(y,"FetchResponse",{enumerable:!0,get:function(){return k.FetchResponse}});Object.defineProperty(y,"URL",{enumerable:!0,get:function(){return k.URL}});Object.defineProperty(y,"URLSearchParams",{enumerable:!0,get:function(){return k.URLSearchParams}});Object.defineProperty(y,"Blob",{enumerable:!0,get:function(){return k.Blob}});Object.defineProperty(y,"FormData",{enumerable:!0,get:function(){return k.FormData}});Object.defineProperty(y,"File",{enumerable:!0,get:function(){return k.File}});y.default={PostgrestClient:Ut.default,PostgrestQueryBuilder:It.default,PostgrestFilterBuilder:xt.default,PostgrestTransformBuilder:Ct.default,PostgrestBuilder:Nt.default,PostgrestError:Lt.default,URLSearchParams:k.URLSearchParams,FetchHeaders:k.FetchHeaders,FetchResponse:k.FetchResponse}});a();a();a();a();a();a();var Jt=Object.defineProperty,Yt=Object.defineProperties,Qt=Object.getOwnPropertyDescriptors,Ze=Object.getOwnPropertySymbols,Xt=Object.prototype.hasOwnProperty,Zt=Object.prototype.propertyIsEnumerable,et=(r,e,t)=>e in r?Jt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,C=(r,e)=>{for(var t in e||(e={}))Xt.call(e,t)&&et(r,t,e[t]);if(Ze)for(var t of Ze(e))Zt.call(e,t)&&et(r,t,e[t]);return r},L=(r,e)=>Yt(r,Qt(e)),er=class extends Error{constructor(r,e,t){super(e||r.toString(),{cause:t}),this.status=r,this.statusText=e,this.error=t}},tr=async(r,e)=>{var t,s,n,o,i,c;let d=e||{},u={onRequest:[e?.onRequest],onResponse:[e?.onResponse],onSuccess:[e?.onSuccess],onError:[e?.onError],onRetry:[e?.onRetry]};if(!e||!e?.plugins)return{url:r,options:d,hooks:u};for(let l of e?.plugins||[]){if(l.init){let h=await((t=l.init)==null?void 0:t.call(l,r.toString(),e));d=h.options||d,r=h.url}u.onRequest.push((s=l.hooks)==null?void 0:s.onRequest),u.onResponse.push((n=l.hooks)==null?void 0:n.onResponse),u.onSuccess.push((o=l.hooks)==null?void 0:o.onSuccess),u.onError.push((i=l.hooks)==null?void 0:i.onError),u.onRetry.push((c=l.hooks)==null?void 0:c.onRetry)}return{url:r,options:d,hooks:u}},tt=class{constructor(r){this.options=r}shouldAttemptRetry(r,e){return this.options.shouldRetry?Promise.resolve(r<this.options.attempts&&this.options.shouldRetry(e)):Promise.resolve(r<this.options.attempts)}getDelay(){return this.options.delay}},rr=class{constructor(r){this.options=r}shouldAttemptRetry(r,e){return this.options.shouldRetry?Promise.resolve(r<this.options.attempts&&this.options.shouldRetry(e)):Promise.resolve(r<this.options.attempts)}getDelay(r){return Math.min(this.options.maxDelay,this.options.baseDelay*2**r)}};function sr(r){if(typeof r=="number")return new tt({type:"linear",attempts:r,delay:1e3});switch(r.type){case"linear":return new tt(r);case"exponential":return new rr(r);default:throw new Error("Invalid retry strategy")}}var nr=async r=>{let e={},t=async s=>typeof s=="function"?await s():s;if(r?.auth){if(r.auth.type==="Bearer"){let s=await t(r.auth.token);if(!s)return e;e.authorization=`Bearer ${s}`}else if(r.auth.type==="Basic"){let s=t(r.auth.username),n=t(r.auth.password);if(!s||!n)return e;e.authorization=`Basic ${btoa(`${s}:${n}`)}`}else if(r.auth.type==="Custom"){let s=t(r.auth.value);if(!s)return e;e.authorization=`${t(r.auth.prefix)} ${s}`}}return e},or=/^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i;function ar(r){let e=r.headers.get("content-type"),t=new Set(["image/svg","application/xml","application/xhtml","application/html"]);if(!e)return"json";let s=e.split(";").shift()||"";return or.test(s)?"json":t.has(s)||s.startsWith("text/")?"text":"blob"}function ir(r){try{return JSON.parse(r),!0}catch{return!1}}function nt(r){if(r===void 0)return!1;let e=typeof r;return e==="string"||e==="number"||e==="boolean"||e===null?!0:e!=="object"?!1:Array.isArray(r)?!0:r.buffer?!1:r.constructor&&r.constructor.name==="Object"||typeof r.toJSON=="function"}function rt(r){try{return JSON.parse(r)}catch{return r}}function st(r){return typeof r=="function"}function lr(r){if(r?.customFetchImpl)return r.customFetchImpl;if(typeof globalThis<"u"&&st(globalThis.fetch))return globalThis.fetch;if(typeof window<"u"&&st(window.fetch))return window.fetch;throw new Error("No fetch implementation found")}async function cr(r){let e=new Headers(r?.headers),t=await nr(r);for(let[s,n]of Object.entries(t||{}))e.set(s,n);if(!e.has("content-type")){let s=ur(r?.body);s&&e.set("content-type",s)}return e}function ur(r){return nt(r)?"application/json":null}function dr(r){if(!r?.body)return null;let e=new Headers(r?.headers);if(nt(r.body)&&!e.has("content-type")){for(let[t,s]of Object.entries(r?.body))s instanceof Date&&(r.body[t]=s.toISOString());return JSON.stringify(r.body)}return r.body}function hr(r,e){var t;if(e?.method)return e.method.toUpperCase();if(r.startsWith("@")){let s=(t=r.split("@")[1])==null?void 0:t.split("/")[0];return at.includes(s)?s.toUpperCase():e?.body?"POST":"GET"}return e?.body?"POST":"GET"}function fr(r,e){let t;return!r?.signal&&r?.timeout&&(t=setTimeout(()=>e?.abort(),r?.timeout)),{abortTimeout:t,clearTimeout:()=>{t&&clearTimeout(t)}}}var pr=class ot extends Error{constructor(e,t){super(t||JSON.stringify(e,null,2)),this.issues=e,Object.setPrototypeOf(this,ot.prototype)}};async function he(r,e){let t=await r["~standard"].validate(e);if(t.issues)throw new pr(t.issues);return t.value}var at=["get","post","put","patch","delete"];var mr=r=>({id:"apply-schema",name:"Apply Schema",version:"1.0.0",async init(e,t){var s,n,o,i;let c=((n=(s=r.plugins)==null?void 0:s.find(d=>{var u;return(u=d.schema)!=null&&u.config?e.startsWith(d.schema.config.baseURL||"")||e.startsWith(d.schema.config.prefix||""):!1}))==null?void 0:n.schema)||r.schema;if(c){let d=e;(o=c.config)!=null&&o.prefix&&d.startsWith(c.config.prefix)&&(d=d.replace(c.config.prefix,""),c.config.baseURL&&(e=e.replace(c.config.prefix,c.config.baseURL))),(i=c.config)!=null&&i.baseURL&&d.startsWith(c.config.baseURL)&&(d=d.replace(c.config.baseURL,""));let u=c.schema[d];if(u){let l=L(C({},t),{method:u.method,output:u.output});return t?.disableValidation||(l=L(C({},l),{body:u.input?await he(u.input,t?.body):t?.body,params:u.params?await he(u.params,t?.params):t?.params,query:u.query?await he(u.query,t?.query):t?.query})),{url:e,options:l}}}return{url:e,options:t}}}),it=r=>{async function e(t,s){let n=L(C(C({},r),s),{plugins:[...r?.plugins||[],mr(r||{})]});if(r?.catchAllError)try{return await Oe(t,n)}catch(o){return{data:null,error:{status:500,statusText:"Fetch Error",message:"Fetch related error. Captured by catchAllError option. See error property for more details.",error:o}}}return await Oe(t,n)}return e};function gr(r,e){let{baseURL:t,params:s,query:n}=e||{query:{},params:{},baseURL:""},o=r.startsWith("http")?r.split("/").slice(0,3).join("/"):t||"";if(r.startsWith("@")){let h=r.toString().split("@")[1].split("/")[0];at.includes(h)&&(r=r.replace(`@${h}/`,"/"))}o.endsWith("/")||(o+="/");let[i,c]=r.replace(o,"").split("?"),d=new URLSearchParams(c);for(let[h,m]of Object.entries(n||{}))m!=null&&d.set(h,String(m));if(s)if(Array.isArray(s)){let h=i.split("/").filter(m=>m.startsWith(":"));for(let[m,w]of h.entries()){let v=s[m];i=i.replace(w,v)}}else for(let[h,m]of Object.entries(s))i=i.replace(`:${h}`,String(m));i=i.split("/").map(encodeURIComponent).join("/"),i.startsWith("/")&&(i=i.slice(1));let u=d.toString();return u=u.length>0?`?${u}`.replace(/\+/g,"%20"):"",o.startsWith("http")?new URL(`${i}${u}`,o):`${o}${i}${u}`}var Oe=async(r,e)=>{var t,s,n,o,i,c,d,u;let{hooks:l,url:h,options:m}=await tr(r,e),w=lr(m),v=new AbortController,x=(t=m.signal)!=null?t:v.signal,b=gr(h,m),U=dr(m),P=await cr(m),B=hr(h,m),g=L(C({},m),{url:b,headers:P,body:U,method:B,signal:x});for(let I of l.onRequest)if(I){let S=await I(g);S instanceof Object&&(g=S)}("pipeTo"in g&&typeof g.pipeTo=="function"||typeof((s=e?.body)==null?void 0:s.pipe)=="function")&&("duplex"in g||(g.duplex="half"));let{clearTimeout:W}=fr(m,v),E=await w(g.url,g);W();let Ye={response:E,request:g};for(let I of l.onResponse)if(I){let S=await I(L(C({},Ye),{response:(n=e?.hookOptions)!=null&&n.cloneResponse?E.clone():E}));S instanceof Response?E=S:S instanceof Object&&(E=S.response)}if(E.ok){if(!(g.method!=="HEAD"))return{data:"",error:null};let S=ar(E),j={data:"",response:E,request:g};if(S==="json"||S==="text"){let F=await E.text(),jt=await((o=g.jsonParser)!=null?o:rt)(F);j.data=jt}else j.data=await E[S]();g?.output&&g.output&&!g.disableValidation&&(j.data=await he(g.output,j.data));for(let F of l.onSuccess)F&&await F(L(C({},j),{response:(i=e?.hookOptions)!=null&&i.cloneResponse?E.clone():E}));return e?.throw?j.data:{data:j.data,error:null}}let Mt=(c=e?.jsonParser)!=null?c:rt,de=await E.text(),Qe=ir(de),Ae=Qe?await Mt(de):null,Bt={response:E,responseText:de,request:g,error:L(C({},Ae),{status:E.status,statusText:E.statusText})};for(let I of l.onError)I&&await I(L(C({},Bt),{response:(d=e?.hookOptions)!=null&&d.cloneResponse?E.clone():E}));if(e?.retry){let I=sr(e.retry),S=(u=e.retryAttempt)!=null?u:0;if(await I.shouldAttemptRetry(S,E)){for(let F of l.onRetry)F&&await F(Ye);let j=I.getDelay(S);return await new Promise(F=>setTimeout(F,j)),await Oe(r,L(C({},e),{retryAttempt:S+1}))}}if(e?.throw)throw new er(E.status,E.statusText,Qe?Ae:de);return{data:null,error:L(C({},Ae),{status:E.status,statusText:E.statusText})}};a();a();var fe=Object.create(null),K=r=>globalThis.process?.env||globalThis.Deno?.env.toObject()||globalThis.__env__||(r?fe:globalThis),O=new Proxy(fe,{get(r,e){return K()[e]??fe[e]},has(r,e){let t=K();return e in t||e in fe},set(r,e,t){let s=K(!0);return s[e]=t,!0},deleteProperty(r,e){if(!e)return!1;let t=K(!0);return delete t[e],!0},ownKeys(){let r=K(!0);return Object.keys(r)}});var Ss=typeof process<"u"&&process.env&&process.env.NODE_ENV||"";function R(r,e){return typeof process<"u"&&process.env?process.env[r]??e:typeof Deno<"u"?Deno.env.get(r)??e:typeof Bun<"u"?Bun.env[r]??e:e}var Ps=Object.freeze({get BETTER_AUTH_SECRET(){return R("BETTER_AUTH_SECRET")},get AUTH_SECRET(){return R("AUTH_SECRET")},get BETTER_AUTH_TELEMETRY(){return R("BETTER_AUTH_TELEMETRY")},get BETTER_AUTH_TELEMETRY_ID(){return R("BETTER_AUTH_TELEMETRY_ID")},get NODE_ENV(){return R("NODE_ENV","development")},get PACKAGE_VERSION(){return R("PACKAGE_VERSION","0.0.0")},get BETTER_AUTH_TELEMETRY_ENDPOINT(){return R("BETTER_AUTH_TELEMETRY_ENDPOINT","https://telemetry.better-auth.com/v1/track")}}),J=1,T=4,$=8,A=24,lt={eterm:T,cons25:T,console:T,cygwin:T,dtterm:T,gnome:T,hurd:T,jfbterm:T,konsole:T,kterm:T,mlterm:T,mosh:A,putty:T,st:T,"rxvt-unicode-24bit":A,terminator:A,"xterm-kitty":A},yr=new Map(Object.entries({APPVEYOR:$,BUILDKITE:$,CIRCLECI:A,DRONE:$,GITEA_ACTIONS:A,GITHUB_ACTIONS:A,GITLAB_CI:$,TRAVIS:$})),br=[/ansi/,/color/,/linux/,/direct/,/^con[0-9]*x[0-9]/,/^rxvt/,/^screen/,/^xterm/,/^vt100/,/^vt220/];function Rr(){if(R("FORCE_COLOR")!==void 0)switch(R("FORCE_COLOR")){case"":case"1":case"true":return T;case"2":return $;case"3":return A;default:return J}if(R("NODE_DISABLE_COLORS")!==void 0&&R("NODE_DISABLE_COLORS")!==""||R("NO_COLOR")!==void 0&&R("NO_COLOR")!==""||R("TERM")==="dumb")return J;if(R("TMUX"))return A;if("TF_BUILD"in O&&"AGENT_NAME"in O)return T;if("CI"in O){for(let{0:r,1:e}of yr)if(r in O)return e;return R("CI_NAME")==="codeship"?$:J}if("TEAMCITY_VERSION"in O)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.exec(R("TEAMCITY_VERSION"))!==null?T:J;switch(R("TERM_PROGRAM")){case"iTerm.app":return!R("TERM_PROGRAM_VERSION")||/^[0-2]\./.exec(R("TERM_PROGRAM_VERSION"))!==null?$:A;case"HyperTerm":case"MacTerm":return A;case"Apple_Terminal":return $}if(R("COLORTERM")==="truecolor"||R("COLORTERM")==="24bit")return A;if(R("TERM")){if(/truecolor/.exec(R("TERM"))!==null)return A;if(/^xterm-256/.exec(R("TERM"))!==null)return $;let r=R("TERM").toLowerCase();if(lt[r])return lt[r];if(br.some(e=>e.exec(r)!==null))return T}return R("COLORTERM")?T:J}var D={reset:"\x1B[0m",bright:"\x1B[1m",dim:"\x1B[2m",undim:"\x1B[22m",underscore:"\x1B[4m",blink:"\x1B[5m",reverse:"\x1B[7m",hidden:"\x1B[8m",fg:{black:"\x1B[30m",red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",magenta:"\x1B[35m",cyan:"\x1B[36m",white:"\x1B[37m"},bg:{black:"\x1B[40m",red:"\x1B[41m",green:"\x1B[42m",yellow:"\x1B[43m",blue:"\x1B[44m",magenta:"\x1B[45m",cyan:"\x1B[46m",white:"\x1B[47m"}},Ue=["info","success","warn","error","debug"];function wr(r,e){return Ue.indexOf(e)<=Ue.indexOf(r)}var Er={info:D.fg.blue,success:D.fg.green,warn:D.fg.yellow,error:D.fg.red,debug:D.fg.magenta},vr=(r,e,t)=>{let s=new Date().toISOString();return t?`${D.dim}${s}${D.reset} ${Er[r]}${r.toUpperCase()}${D.reset} ${D.bright}[Better Auth]:${D.reset} ${e}`:`${s} ${r.toUpperCase()} [Better Auth]: ${e}`},Tr=r=>{let e=r?.disabled!==!0,t=r?.level??"error",n=r?.disableColors!==void 0?!r.disableColors:Rr()!==1,o=(c,d,u=[])=>{if(!e||!wr(t,c))return;let l=vr(c,d,n);if(!r||typeof r.log!="function"){c==="error"?console.error(l,...u):c==="warn"?console.warn(l,...u):console.log(l,...u);return}r.log(c==="success"?"info":c,d,...u)};return{...Object.fromEntries(Ue.map(c=>[c,(...[d,...u])=>o(c,d,u)])),get level(){return t}}},As=Tr();a();a();var Ls={USER_NOT_FOUND:"User not found",FAILED_TO_CREATE_USER:"Failed to create user",FAILED_TO_CREATE_SESSION:"Failed to create session",FAILED_TO_UPDATE_USER:"Failed to update user",FAILED_TO_GET_SESSION:"Failed to get session",INVALID_PASSWORD:"Invalid password",INVALID_EMAIL:"Invalid email",INVALID_EMAIL_OR_PASSWORD:"Invalid email or password",SOCIAL_ACCOUNT_ALREADY_LINKED:"Social account already linked",PROVIDER_NOT_FOUND:"Provider not found",INVALID_TOKEN:"Invalid token",ID_TOKEN_NOT_SUPPORTED:"id_token not supported",FAILED_TO_GET_USER_INFO:"Failed to get user info",USER_EMAIL_NOT_FOUND:"User email not found",EMAIL_NOT_VERIFIED:"Email not verified",PASSWORD_TOO_SHORT:"Password too short",PASSWORD_TOO_LONG:"Password too long",USER_ALREADY_EXISTS:"User already exists.",USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL:"User already exists. Use another email.",EMAIL_CAN_NOT_BE_UPDATED:"Email can not be updated",CREDENTIAL_ACCOUNT_NOT_FOUND:"Credential account not found",SESSION_EXPIRED:"Session expired. Re-authenticate to perform this action.",FAILED_TO_UNLINK_LAST_ACCOUNT:"You can't unlink your last account",ACCOUNT_NOT_FOUND:"Account not found",USER_ALREADY_HAS_PASSWORD:"User already has a password. Provide that to delete the account."},G=class extends Error{constructor(e,t){super(e),this.name="BetterAuthError",this.message=e,this.cause=t,this.stack=""}};function _r(r){try{return(new URL(r).pathname.replace(/\/+$/,"")||"/")!=="/"}catch{throw new G(`Invalid base URL: ${r}. Please provide a valid base URL.`)}}function Y(r,e="/api/auth"){if(_r(r))return r;let s=r.replace(/\/+$/,"");return!e||e==="/"?s:(e=e.startsWith("/")?e:`/${e}`,`${s}${e}`)}function ct(r,e,t,s){if(r)return Y(r,e);if(s!==!1){let i=O.BETTER_AUTH_URL||O.NEXT_PUBLIC_BETTER_AUTH_URL||O.PUBLIC_BETTER_AUTH_URL||O.NUXT_PUBLIC_BETTER_AUTH_URL||O.NUXT_PUBLIC_AUTH_URL||(O.BASE_URL!=="/"?O.BASE_URL:void 0);if(i)return Y(i,e)}let n=t?.headers.get("x-forwarded-host"),o=t?.headers.get("x-forwarded-proto");if(n&&o)return Y(`${o}://${n}`,e);if(t){let i=Sr(t.url);if(!i)throw new G("Could not get origin from request. Please provide a valid base URL.");return Y(i,e)}if(typeof window<"u"&&window.location)return Y(window.location.origin,e)}function Sr(r){try{return new URL(r).origin}catch{return null}}a();a();a();var Q=Symbol("clean");var N=[],q=0,pe=4,Pr=0,X=r=>{let e=[],t={get(){return t.lc||t.listen(()=>{})(),t.value},lc:0,listen(s){return t.lc=e.push(s),()=>{for(let o=q+pe;o<N.length;)N[o]===s?N.splice(o,pe):o+=pe;let n=e.indexOf(s);~n&&(e.splice(n,1),--t.lc||t.off())}},notify(s,n){Pr++;let o=!N.length;for(let i of e)N.push(i,t.value,s,n);if(o){for(q=0;q<N.length;q+=pe)N[q](N[q+1],N[q+2],N[q+3]);N.length=0}},off(){},set(s){let n=t.value;n!==s&&(t.value=s,t.notify(n))},subscribe(s){let n=t.listen(s);return s(t.value),n},value:r};return process.env.NODE_ENV!=="production"&&(t[Q]=()=>{e=[],t.lc=0,t.off()}),t};a();var Ar=5,z=6,me=10,Or=(r,e,t,s)=>(r.events=r.events||{},r.events[t+me]||(r.events[t+me]=s(n=>{r.events[t].reduceRight((o,i)=>(i(o),o),{shared:{},...n})})),r.events[t]=r.events[t]||[],r.events[t].push(e),()=>{let n=r.events[t],o=n.indexOf(e);n.splice(o,1),n.length||(delete r.events[t],r.events[t+me](),delete r.events[t+me])});var ut=1e3,Ie=(r,e)=>Or(r,s=>{let n=e(s);n&&r.events[z].push(n)},Ar,s=>{let n=r.listen;r.listen=(...i)=>(!r.lc&&!r.active&&(r.active=!0,s()),n(...i));let o=r.off;if(r.events[z]=[],r.off=()=>{o(),setTimeout(()=>{if(r.active&&!r.lc){r.active=!1;for(let i of r.events[z])i();r.events[z]=[]}},ut)},process.env.NODE_ENV!=="production"){let i=r[Q];r[Q]=()=>{for(let c of r.events[z])c();r.events[z]=[],r.active=!1,i()}}return()=>{r.listen=n,r.off=o}});a();var Ur=typeof window>"u",ge=(r,e,t,s)=>{let n=X({data:null,error:null,isPending:!0,isRefetching:!1,refetch:c=>o(c)}),o=c=>{let d=typeof s=="function"?s({data:n.get().data,error:n.get().error,isPending:n.get().isPending}):s;t(e,{...d,query:{...d?.query,...c?.query},async onSuccess(u){n.set({data:u.data,error:null,isPending:!1,isRefetching:!1,refetch:n.value.refetch}),await d?.onSuccess?.(u)},async onError(u){let{request:l}=u,h=typeof l.retry=="number"?l.retry:l.retry?.attempts,m=l.retryAttempt||0;h&&m<h||(n.set({error:u.error,data:null,isPending:!1,isRefetching:!1,refetch:n.value.refetch}),await d?.onError?.(u))},async onRequest(u){let l=n.get();n.set({isPending:l.data===null,data:l.data,error:null,isRefetching:!0,refetch:n.value.refetch}),await d?.onRequest?.(u)}}).catch(u=>{n.set({error:u,data:null,isPending:!1,isRefetching:!1,refetch:n.value.refetch})})};r=Array.isArray(r)?r:[r];let i=!1;for(let c of r)c.subscribe(()=>{Ur||(i?o():Ie(n,()=>{let d=setTimeout(()=>{i||(o(),i=!0)},0);return()=>{n.off(),c.off(),clearTimeout(d)}}))});return n};a();var Ir={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*:/,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*:/,protoShort:/"__proto__"\s*:/,constructorShort:/"constructor"\s*:/},xr=/^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/,dt={true:!0,false:!1,null:null,undefined:void 0,nan:Number.NaN,infinity:Number.POSITIVE_INFINITY,"-infinity":Number.NEGATIVE_INFINITY},Cr=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,7}))?(?:Z|([+-])(\d{2}):(\d{2}))$/;function Nr(r){return r instanceof Date&&!isNaN(r.getTime())}function Lr(r){let e=Cr.exec(r);if(!e)return null;let[,t,s,n,o,i,c,d,u,l,h]=e,m=new Date(Date.UTC(parseInt(t,10),parseInt(s,10)-1,parseInt(n,10),parseInt(o,10),parseInt(i,10),parseInt(c,10),d?parseInt(d.padEnd(3,"0"),10):0));if(u){let w=(parseInt(l,10)*60+parseInt(h,10))*(u==="+"?-1:1);m.setUTCMinutes(m.getUTCMinutes()+w)}return Nr(m)?m:null}function $r(r,e={}){let{strict:t=!1,warnings:s=!1,reviver:n,parseDates:o=!0}=e;if(typeof r!="string")return r;let i=r.trim();if(i.length>0&&i[0]==='"'&&i.endsWith('"')&&!i.slice(1,-1).includes('"'))return i.slice(1,-1);let c=i.toLowerCase();if(c.length<=9&&c in dt)return dt[c];if(!xr.test(i)){if(t)throw new SyntaxError("[better-json] Invalid JSON");return r}if(Object.entries(Ir).some(([u,l])=>{let h=l.test(i);return h&&s&&console.warn(`[better-json] Detected potential prototype pollution attempt using ${u} pattern`),h})&&t)throw new Error("[better-json] Potential prototype pollution attempt detected");try{return JSON.parse(i,(l,h)=>{if(l==="__proto__"||l==="constructor"&&h&&typeof h=="object"&&"prototype"in h){s&&console.warn(`[better-json] Dropping "${l}" key to prevent prototype pollution`);return}if(o&&typeof h=="string"){let m=Lr(h);if(m)return m}return n?n(l,h):h})}catch(u){if(t)throw u;return r}}function ht(r,e={strict:!0}){return $r(r,e)}var Dr={id:"redirect",name:"Redirect",hooks:{onSuccess(r){if(r.data?.url&&r.data?.redirect&&typeof window<"u"&&window.location&&window.location)try{window.location.href=r.data.url}catch{}}}};function kr(r){let e=X(!1);return{session:ge(e,"/get-session",r,{method:"GET"}),$sessionSignal:e}}var ft=(r,e)=>{let t="credentials"in Request.prototype,s=ct(r?.baseURL,r?.basePath,void 0,e)??"/api/auth",n=r?.plugins?.flatMap(g=>g.fetchPlugins).filter(g=>g!==void 0)||[],o={id:"lifecycle-hooks",name:"lifecycle-hooks",hooks:{onSuccess:r?.fetchOptions?.onSuccess,onError:r?.fetchOptions?.onError,onRequest:r?.fetchOptions?.onRequest,onResponse:r?.fetchOptions?.onResponse}},{onSuccess:i,onError:c,onRequest:d,onResponse:u,...l}=r?.fetchOptions||{},h=it({baseURL:s,...t?{credentials:"include"}:{},method:"GET",jsonParser(g){return g?ht(g,{strict:!1}):null},customFetchImpl:fetch,...l,plugins:[o,...l.plugins||[],...r?.disableDefaultFetchPlugins?[]:[Dr],...n]}),{$sessionSignal:m,session:w}=kr(h),v=r?.plugins||[],x={},b={$sessionSignal:m,session:w},U={"/sign-out":"POST","/revoke-sessions":"POST","/revoke-other-sessions":"POST","/delete-user":"POST"},P=[{signal:"$sessionSignal",matcher(g){return g==="/sign-out"||g==="/update-user"||g.startsWith("/sign-in")||g.startsWith("/sign-up")||g==="/delete-user"||g==="/verify-email"}}];for(let g of v)g.getAtoms&&Object.assign(b,g.getAtoms?.(h)),g.pathMethods&&Object.assign(U,g.pathMethods),g.atomListeners&&P.push(...g.atomListeners);let B={notify:g=>{b[g].set(!b[g].get())},listen:(g,W)=>{b[g].subscribe(W)},atoms:b};for(let g of v)g.getActions&&Object.assign(x,g.getActions?.(h,B,r));return{get baseURL(){return s},pluginsActions:x,pluginsAtoms:b,pluginPathMethods:U,atomListeners:P,$fetch:h,$store:B}};function Mr(r){return typeof r=="object"&&r!==null&&"get"in r&&typeof r.get=="function"&&"lc"in r&&typeof r.lc=="number"}function Br(r,e,t){let s=e[r],{fetchOptions:n,query:o,...i}=t||{};return s||(n?.method?n.method:i&&Object.keys(i).length>0?"POST":"GET")}function pt(r,e,t,s,n){function o(i=[]){return new Proxy(function(){},{get(c,d){if(typeof d!="string"||d==="then"||d==="catch"||d==="finally")return;let u=[...i,d],l=r;for(let h of u)if(l&&typeof l=="object"&&h in l)l=l[h];else{l=void 0;break}return typeof l=="function"||Mr(l)?l:o(u)},apply:async(c,d,u)=>{let l="/"+i.map(P=>P.replace(/[A-Z]/g,B=>`-${B.toLowerCase()}`)).join("/"),h=u[0]||{},m=u[1]||{},{query:w,fetchOptions:v,...x}=h,b={...m,...v},U=Br(l,t,h);return await e(l,{...b,body:U==="GET"?void 0:{...x,...b?.body||{}},query:w||b?.query,method:U,async onSuccess(P){if(await b?.onSuccess?.(P),!n)return;let B=n.filter(g=>g.matcher(l));if(B.length)for(let g of B){let W=s[g.signal];if(!W)return;let E=W.get();setTimeout(()=>{W.set(!E)},10)}}})}})}return o()}a();function mt(r){return r.charAt(0).toUpperCase()+r.slice(1)}function xe(r){let{pluginPathMethods:e,pluginsActions:t,pluginsAtoms:s,$fetch:n,atomListeners:o,$store:i}=ft(r),c={};for(let[l,h]of Object.entries(s))c[`use${mt(l)}`]=h;let d={...t,...c,$fetch:n,$store:i};return pt(d,n,e,s,o)}a();a();a();function jr(r){return{authorize(e,t="AND"){let s=!1;for(let[n,o]of Object.entries(e)){let i=r[n];if(!i)return{success:!1,error:`You are not allowed to access resource: ${n}`};if(Array.isArray(o))s=o.every(c=>i.includes(c));else if(typeof o=="object"){let c=o;c.connector==="OR"?s=c.actions.some(d=>i.includes(d)):s=c.actions.every(d=>i.includes(d))}else throw new G("Invalid access control request");if(s&&t==="OR")return{success:s};if(!s&&t==="AND")return{success:!1,error:`unauthorized to access resource "${n}"`}}return s?{success:s}:{success:!1,error:"Not authorized"}},statements:r}}function ye(r){return{newRole(e){return jr(e)},statements:r}}var Fr={organization:["update","delete"],member:["create","update","delete"],invitation:["create","cancel"],team:["create","update","delete"],ac:["create","read","update","delete"]},Ce=ye(Fr),Hr=Ce.newRole({organization:["update"],invitation:["create","cancel"],member:["create","update","delete"],team:["create","update","delete"],ac:["create","read","update","delete"]}),qr=Ce.newRole({organization:["update","delete"],member:["create","update","delete"],invitation:["create","cancel"],team:["create","update","delete"],ac:["create","read","update","delete"]}),Wr=Ce.newRole({organization:[],member:[],invitation:[],team:[],ac:["read"]});a();a();a();a();a();a();a();a();a();a();a();var Ne=class{constructor(){Object.defineProperty(this,"controller",{enumerable:!0,configurable:!0,writable:!0,value:void 0})}createNewAbortSignal(){if(this.controller){let t=new Error("Cancelling existing WebAuthn API call for new one");t.name="AbortError",this.controller.abort(t)}let e=new AbortController;return this.controller=e,e.signal}cancelCeremony(){if(this.controller){let e=new Error("Manually cancelling existing WebAuthn API call");e.name="AbortError",this.controller.abort(e),this.controller=void 0}}},bt=new Ne;a();a();a();a();a();a();a();a();var Jr={user:["create","list","set-role","ban","impersonate","delete","set-password","get","update"],session:["list","revoke","delete"]},Rt=ye(Jr),Yr=Rt.newRole({user:["create","list","set-role","ban","impersonate","delete","set-password","get","update"],session:["list","revoke","delete"]}),Qr=Rt.newRole({user:[],session:[]});a();a();var wt=()=>({id:"username",$InferServerPlugin:{}});var $a="/auth",be="nvwa_login_token",$e="nvwa_user_profile",Et=class{constructor(e,t,s){this.storage=s,this.authClient=xe({baseUrl:e,fetchOptions:{customFetchImpl:t,auth:{type:"Bearer",token:()=>s.get(be)},onSuccess:n=>{let o=n.response.headers.get("set-auth-token");o&&s.set(be,o)}},plugins:[wt()]})}async currentUser(){return await this.storage.get($e)}async signUp(e,t){let s=await this.authClient.signUp.email({email:e.email??`${e.username}@nvwa.app`,name:e.name,username:e.username,displayUsername:e.displayUsername,password:t});this.saveSession(s)}async signInWithUsername(e,t){let s=await this.authClient.signIn.username({username:e,password:t});this.saveSession(s)}saveSession(e){if(e.error)throw new Error(e.error.message);this.storage.set(be,e.data?.token),this.storage.set($e,e.data?.user)}async signOut(){await this.storage.remove(be),await this.storage.remove($e)}async updateUserPassword(e,t,s=!1){let n=await this.authClient.changePassword({currentPassword:e,newPassword:t,revokeOtherSessions:s});this.saveSession(n)}};a();var vt=class{constructor(e){this.http=e}async invoke(e,t){return(await this.http.request("/functions/"+e,{method:t.method||"POST",data:t.body,headers:t.headers})).body}};a();var Tt=class{constructor(e,t,s,n,o){this.ok=e,this.status=t,this.statusText=s,this.headers=n,this.body=o}async text(){return typeof this.body=="string"?this.body:JSON.stringify(this.body)}async json(){if(typeof this.body=="string")try{return JSON.parse(this.body)}catch{return this.body}return this.body}async arrayBuffer(){if(this.body instanceof ArrayBuffer)return this.body;if(typeof this.body=="string")return new TextEncoder().encode(this.body).buffer;throw new Error("Cannot convert body to ArrayBuffer")}async blob(){if(this.body instanceof Blob)return this.body;if(typeof this.body=="string")return new Blob([this.body],{type:this.headers["content-type"]||"text/plain"});throw new Error("Cannot convert body to Blob")}},_t=class{async jsonRequest(e,t){let s={...t,headers:{"Content-Type":"application/json",...t.headers},data:typeof t.data=="object"?JSON.stringify(t.data):t.data};return this.request(e,s)}async jsonRequestWithAuth(e,t,s){let n={...t,headers:{"Content-Type":"application/json",...t.headers},data:typeof t.data=="object"?JSON.stringify(t.data):t.data};return this.requestWithAuth(e,n,s)}};a();var Xr="/storage",Zr=Xr+"/generateUploadUrl",St=class{constructor(e,t){this.baseUrl=e,this.http=t}async uploadFile(e){let t=await this.http.request(this.baseUrl+Zr,{method:"POST",data:{fileName:e.name||e.fileName,fileSize:e.size||e.fileSize,fileType:e.type||e.fileType}}),{url:s}=t.body;if(!s)throw new Error("\u83B7\u53D6\u4E0A\u4F20URL\u5931\u8D25");return{url:(await this.http.request(s,{method:"PUT",data:e,headers:{"Content-Type":e.type||e.fileType||"application/octet-stream"}})).body.url.split("?")[0]}}};a();a();a();var Dt=Kt($t(),1),{PostgrestClient:kt,PostgrestQueryBuilder:ii,PostgrestFilterBuilder:li,PostgrestTransformBuilder:ci,PostgrestBuilder:ui,PostgrestError:di,FetchHeaders:hi,FetchResponse:Je,PostgrestFetch:fi,URL:pi,URLSearchParams:mi}=Dt.default;var us="/entities",ds=(r,e)=>async(s,n)=>{console.log("customFetch",s,n);let o;if(typeof s=="string")o=s;else if(s&&typeof s=="object")if(typeof s.toString=="function"&&!s.url)o=s.toString();else if(s.url)o=s.url,n||(n={}),n.method=s.method,n.headers=s.headers,n.body=s.body;else throw new Error("Unsupported input type for fetch");else throw new Error("Unsupported input type for fetch");let i=(n?.method||"GET").toUpperCase(),c={};if(n?.headers)if(n.headers&&typeof n.headers.forEach=="function")n.headers.forEach((w,v)=>{c[v]=w});else if(Array.isArray(n.headers))for(let[w,v]of n.headers)c[w]=v;else Object.assign(c,n.headers);let d=n?.body,u;try{u=await r.requestWithAuth(o,{method:i,data:d,headers:c},e)}catch(w){return new Je(w?.message||"Internal Error",{status:500,statusText:"Internal Error"})}let l=u.body,h=null;return(u.headers["content-type"]||u.headers["Content-Type"]||"").startsWith("application/json")&&typeof l!="string"?h=JSON.stringify(l):typeof l=="string"||l&&(l.constructor===Blob||l.constructor===ArrayBuffer||typeof l.getReader=="function")?h=l:h=JSON.stringify(l),new Je(h,{status:u.status,headers:u.headers})},Ei=(r,e,t)=>new kt(r+us,{fetch:ds(e,t)});a();a();var M=class r{constructor(e){this.headerMap=new Map;if(e){if(e instanceof r)e.forEach((t,s)=>this.set(s,t));else if(Array.isArray(e))for(let[t,s]of e)this.set(t,String(s));else if(typeof e=="object")for(let t of Object.keys(e))this.set(t,String(e[t]))}}append(e,t){let s=e.toLowerCase(),n=this.headerMap.get(s);this.headerMap.set(s,n?`${n}, ${t}`:t)}set(e,t){this.headerMap.set(e.toLowerCase(),String(t))}get(e){let t=this.headerMap.get(e.toLowerCase());return t??null}has(e){return this.headerMap.has(e.toLowerCase())}delete(e){this.headerMap.delete(e.toLowerCase())}forEach(e){for(let[t,s]of this.headerMap.entries())e(s,t,this)}entries(){return this.headerMap.entries()}keys(){return this.headerMap.keys()}values(){return this.headerMap.values()}[Symbol.iterator](){return this.entries()}},ce=class r{constructor(e){this.params=new Map;if(e){if(typeof e=="string")this.parseString(e);else if(e instanceof r)this.params=new Map(e.params);else if(Array.isArray(e))for(let[t,s]of e)this.append(t,s);else if(e&&typeof e=="object")for(let[t,s]of Object.entries(e))this.set(t,s)}}parseString(e){e.startsWith("?")&&(e=e.slice(1));let t=e.split("&");for(let s of t)if(s){let[n,o]=s.split("=");n&&this.append(decodeURIComponent(n),o?decodeURIComponent(o):"")}}append(e,t){let s=this.params.get(e)||[];s.push(t),this.params.set(e,s)}delete(e){this.params.delete(e)}get(e){let t=this.params.get(e);return t?t[0]:null}getAll(e){return this.params.get(e)||[]}has(e){return this.params.has(e)}set(e,t){this.params.set(e,[t])}sort(){let e=Array.from(this.params.entries()).sort(([t],[s])=>t.localeCompare(s));this.params=new Map(e)}toString(){let e=[];for(let[t,s]of this.params.entries())for(let n of s)e.push(`${encodeURIComponent(t)}=${encodeURIComponent(n)}`);return e.join("&")}forEach(e){for(let[t,s]of this.params.entries())for(let n of s)e(n,t,this)}keys(){return this.params.keys()}values(){let e=[];for(let t of this.params.values())e.push(...t);return e[Symbol.iterator]()}entries(){let e=[];for(let[t,s]of this.params.entries())for(let n of s)e.push([t,n]);return e[Symbol.iterator]()}[Symbol.iterator](){return this.entries()}get size(){return this.params.size}},Te=class r{constructor(e,t){let s;if(e instanceof r)s=e.href;else if(t){let o=t instanceof r?t.href:t;s=this.resolve(o,e)}else s=e;let n=this.parseUrl(s);this.href=s,this.origin=`${n.protocol}//${n.host}`,this.protocol=n.protocol,this.username=n.username,this.password=n.password,this.host=n.host,this.hostname=n.hostname,this.port=n.port,this.pathname=n.pathname,this.search=n.search,this.searchParams=new ce(n.search),this.hash=n.hash}resolve(e,t){if(t.startsWith("http://")||t.startsWith("https://"))return t;if(t.startsWith("//"))return`${this.parseUrl(e).protocol}${t}`;if(t.startsWith("/")){let o=this.parseUrl(e);return`${o.protocol}//${o.host}${t}`}let s=this.parseUrl(e),n=s.pathname.endsWith("/")?s.pathname:s.pathname+"/";return`${s.protocol}//${s.host}${n}${t}`}parseUrl(e){let t=e.match(/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/);if(!t)throw new TypeError("Invalid URL");let s=t[2]||"",n=t[4]||"",o=t[5]||"/",i=t[7]?`?${t[7]}`:"",c=t[9]?`#${t[9]}`:"";if(!s&&!n&&!o.startsWith("/")&&!o.includes("/")&&!o.includes("."))throw new TypeError("Invalid URL");let d=n.match(/^([^@]*)@(.+)$/),u="",l="",h=n;if(d){let x=d[1];h=d[2];let b=x.match(/^([^:]*):?(.*)$/);b&&(u=b[1]||"",l=b[2]||"")}let m=h.match(/^([^:]+):?(\d*)$/),w=m?m[1]:h,v=m&&m[2]?m[2]:"";return{protocol:s?`${s}:`:"",username:u,password:l,host:h,hostname:w,port:v,pathname:o,search:i,hash:c}}toString(){let e=this.searchParams.toString(),t=e?`?${e}`:"";return`${this.protocol}//${this.host}${this.pathname}${t}${this.hash}`}toJSON(){return this.toString()}};a();var _e=class r{constructor(e,t){if(typeof e=="string")this.url=e;else if(e?.url)this.url=String(e.url);else if(typeof e?.toString=="function")this.url=String(e.toString());else throw new Error("Invalid input for Request");this.method=(t?.method||"GET").toUpperCase(),this.headers=t?.headers instanceof M?t.headers:new M(t?.headers),this.body=t?.body,this.timeout=t?.timeout,this.signal=t?.signal||void 0}clone(){return new r(this.url,{method:this.method,headers:this.headers,body:this.body,timeout:this.timeout})}toString(){return this.url}};a();var Se=class{constructor(e,t){this.bodyData=e,this.status=t?.status??200,this.statusText=t?.statusText??"",this.headers=hs(t?.headers),this.ok=this.status>=200&&this.status<300}async text(){return typeof this.bodyData=="string"?this.bodyData:this.bodyData==null?"":typeof this.bodyData=="object"?JSON.stringify(this.bodyData):String(this.bodyData)}async json(){if(typeof this.bodyData=="string")try{return JSON.parse(this.bodyData)}catch{}return this.bodyData}async arrayBuffer(){let e=await this.text();return new TextEncoder().encode(e).buffer}};function hs(r){return r?new M(r):new M}a();var ue=class{constructor(){this._aborted=!1;this.listeners=new Set;this.onabort=null}get aborted(){return this._aborted}_trigger(){if(!this._aborted){if(this._aborted=!0,typeof this.onabort=="function")try{this.onabort()}catch{}for(let e of Array.from(this.listeners))try{e()}catch{}this.listeners.clear()}}addEventListener(e,t){if(this._aborted){try{t()}catch{}return}this.listeners.add(t)}removeEventListener(e,t){this.listeners.delete(t)}toString(){return"[object AbortSignal]"}},Pe=class{constructor(){this._signal=new ue}get signal(){return this._signal}abort(){this._signal._trigger()}toString(){return"[object AbortController]"}};a();function Mi(r){r.URL=Te,r.URLSearchParams=ce,r.Headers=M,r.Request=_e,r.Response=Se,r.AbortController=Pe,r.AbortSignal=ue}export{$a as AUTH_BASE_PATH,Pe as AbortController,ue as AbortSignal,us as ENTITIES_BASE_PATH,Xr as FILE_STORAGE_BASE_PATH,Tt as FetchResponse,Zr as GENERATE_UPLOAD_URL_PATH,M as Headers,be as LOGIN_TOKEN_KEY,$e as LOGIN_USER_PROFILE_KEY,Et as NvwaAuthClient,vt as NvwaEdgeFunctions,St as NvwaFileStorage,_t as NvwaHttpClient,_e as Request,Se as Response,Te as URL,ce as URLSearchParams,Ei as createPostgrestClient,Mi as polyfill};
|