@permi/react 0.0.3 → 0.0.5
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 +0 -2
- package/dist/index.cjs +931 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +927 -15
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -2,12 +2,924 @@
|
|
|
2
2
|
import { useMemo as useMemo3 } from "react";
|
|
3
3
|
import { useQuery } from "@tanstack/react-query";
|
|
4
4
|
import { toAccount } from "viem/accounts";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
|
|
6
|
+
// ../core/src/@tanstack/react-query.gen.ts
|
|
7
|
+
import { queryOptions } from "@tanstack/react-query";
|
|
8
|
+
|
|
9
|
+
// ../core/src/core/bodySerializer.gen.ts
|
|
10
|
+
var jsonBodySerializer = {
|
|
11
|
+
bodySerializer: (body) => JSON.stringify(
|
|
12
|
+
body,
|
|
13
|
+
(_key, value) => typeof value === "bigint" ? value.toString() : value
|
|
14
|
+
)
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// ../core/src/core/params.gen.ts
|
|
18
|
+
var extraPrefixesMap = {
|
|
19
|
+
$body_: "body",
|
|
20
|
+
$headers_: "headers",
|
|
21
|
+
$path_: "path",
|
|
22
|
+
$query_: "query"
|
|
23
|
+
};
|
|
24
|
+
var extraPrefixes = Object.entries(extraPrefixesMap);
|
|
25
|
+
|
|
26
|
+
// ../core/src/core/serverSentEvents.gen.ts
|
|
27
|
+
var createSseClient = ({
|
|
28
|
+
onRequest,
|
|
29
|
+
onSseError,
|
|
30
|
+
onSseEvent,
|
|
31
|
+
responseTransformer,
|
|
32
|
+
responseValidator,
|
|
33
|
+
sseDefaultRetryDelay,
|
|
34
|
+
sseMaxRetryAttempts,
|
|
35
|
+
sseMaxRetryDelay,
|
|
36
|
+
sseSleepFn,
|
|
37
|
+
url,
|
|
38
|
+
...options
|
|
39
|
+
}) => {
|
|
40
|
+
let lastEventId;
|
|
41
|
+
const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
42
|
+
const createStream = async function* () {
|
|
43
|
+
let retryDelay = sseDefaultRetryDelay ?? 3e3;
|
|
44
|
+
let attempt = 0;
|
|
45
|
+
const signal = options.signal ?? new AbortController().signal;
|
|
46
|
+
while (true) {
|
|
47
|
+
if (signal.aborted) break;
|
|
48
|
+
attempt++;
|
|
49
|
+
const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
|
|
50
|
+
if (lastEventId !== void 0) {
|
|
51
|
+
headers.set("Last-Event-ID", lastEventId);
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
const requestInit = {
|
|
55
|
+
redirect: "follow",
|
|
56
|
+
...options,
|
|
57
|
+
body: options.serializedBody,
|
|
58
|
+
headers,
|
|
59
|
+
signal
|
|
60
|
+
};
|
|
61
|
+
let request = new Request(url, requestInit);
|
|
62
|
+
if (onRequest) {
|
|
63
|
+
request = await onRequest(url, requestInit);
|
|
64
|
+
}
|
|
65
|
+
const _fetch = options.fetch ?? globalThis.fetch;
|
|
66
|
+
const response = await _fetch(request);
|
|
67
|
+
if (!response.ok)
|
|
68
|
+
throw new Error(
|
|
69
|
+
`SSE failed: ${response.status} ${response.statusText}`
|
|
70
|
+
);
|
|
71
|
+
if (!response.body) throw new Error("No body in SSE response");
|
|
72
|
+
const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
|
|
73
|
+
let buffer = "";
|
|
74
|
+
const abortHandler = () => {
|
|
75
|
+
try {
|
|
76
|
+
reader.cancel();
|
|
77
|
+
} catch {
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
signal.addEventListener("abort", abortHandler);
|
|
81
|
+
try {
|
|
82
|
+
while (true) {
|
|
83
|
+
const { done, value } = await reader.read();
|
|
84
|
+
if (done) break;
|
|
85
|
+
buffer += value;
|
|
86
|
+
buffer = buffer.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
87
|
+
const chunks = buffer.split("\n\n");
|
|
88
|
+
buffer = chunks.pop() ?? "";
|
|
89
|
+
for (const chunk of chunks) {
|
|
90
|
+
const lines = chunk.split("\n");
|
|
91
|
+
const dataLines = [];
|
|
92
|
+
let eventName;
|
|
93
|
+
for (const line of lines) {
|
|
94
|
+
if (line.startsWith("data:")) {
|
|
95
|
+
dataLines.push(line.replace(/^data:\s*/, ""));
|
|
96
|
+
} else if (line.startsWith("event:")) {
|
|
97
|
+
eventName = line.replace(/^event:\s*/, "");
|
|
98
|
+
} else if (line.startsWith("id:")) {
|
|
99
|
+
lastEventId = line.replace(/^id:\s*/, "");
|
|
100
|
+
} else if (line.startsWith("retry:")) {
|
|
101
|
+
const parsed = Number.parseInt(
|
|
102
|
+
line.replace(/^retry:\s*/, ""),
|
|
103
|
+
10
|
|
104
|
+
);
|
|
105
|
+
if (!Number.isNaN(parsed)) {
|
|
106
|
+
retryDelay = parsed;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
let data;
|
|
111
|
+
let parsedJson = false;
|
|
112
|
+
if (dataLines.length) {
|
|
113
|
+
const rawData = dataLines.join("\n");
|
|
114
|
+
try {
|
|
115
|
+
data = JSON.parse(rawData);
|
|
116
|
+
parsedJson = true;
|
|
117
|
+
} catch {
|
|
118
|
+
data = rawData;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (parsedJson) {
|
|
122
|
+
if (responseValidator) {
|
|
123
|
+
await responseValidator(data);
|
|
124
|
+
}
|
|
125
|
+
if (responseTransformer) {
|
|
126
|
+
data = await responseTransformer(data);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
onSseEvent?.({
|
|
130
|
+
data,
|
|
131
|
+
event: eventName,
|
|
132
|
+
id: lastEventId,
|
|
133
|
+
retry: retryDelay
|
|
134
|
+
});
|
|
135
|
+
if (dataLines.length) {
|
|
136
|
+
yield data;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
} finally {
|
|
141
|
+
signal.removeEventListener("abort", abortHandler);
|
|
142
|
+
reader.releaseLock();
|
|
143
|
+
}
|
|
144
|
+
break;
|
|
145
|
+
} catch (error) {
|
|
146
|
+
onSseError?.(error);
|
|
147
|
+
if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) {
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
const backoff = Math.min(
|
|
151
|
+
retryDelay * 2 ** (attempt - 1),
|
|
152
|
+
sseMaxRetryDelay ?? 3e4
|
|
153
|
+
);
|
|
154
|
+
await sleep(backoff);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
const stream = createStream();
|
|
159
|
+
return { stream };
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
// ../core/src/core/pathSerializer.gen.ts
|
|
163
|
+
var separatorArrayExplode = (style) => {
|
|
164
|
+
switch (style) {
|
|
165
|
+
case "label":
|
|
166
|
+
return ".";
|
|
167
|
+
case "matrix":
|
|
168
|
+
return ";";
|
|
169
|
+
case "simple":
|
|
170
|
+
return ",";
|
|
171
|
+
default:
|
|
172
|
+
return "&";
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
var separatorArrayNoExplode = (style) => {
|
|
176
|
+
switch (style) {
|
|
177
|
+
case "form":
|
|
178
|
+
return ",";
|
|
179
|
+
case "pipeDelimited":
|
|
180
|
+
return "|";
|
|
181
|
+
case "spaceDelimited":
|
|
182
|
+
return "%20";
|
|
183
|
+
default:
|
|
184
|
+
return ",";
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
var separatorObjectExplode = (style) => {
|
|
188
|
+
switch (style) {
|
|
189
|
+
case "label":
|
|
190
|
+
return ".";
|
|
191
|
+
case "matrix":
|
|
192
|
+
return ";";
|
|
193
|
+
case "simple":
|
|
194
|
+
return ",";
|
|
195
|
+
default:
|
|
196
|
+
return "&";
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
var serializeArrayParam = ({
|
|
200
|
+
allowReserved,
|
|
201
|
+
explode,
|
|
202
|
+
name,
|
|
203
|
+
style,
|
|
204
|
+
value
|
|
205
|
+
}) => {
|
|
206
|
+
if (!explode) {
|
|
207
|
+
const joinedValues2 = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
|
|
208
|
+
switch (style) {
|
|
209
|
+
case "label":
|
|
210
|
+
return `.${joinedValues2}`;
|
|
211
|
+
case "matrix":
|
|
212
|
+
return `;${name}=${joinedValues2}`;
|
|
213
|
+
case "simple":
|
|
214
|
+
return joinedValues2;
|
|
215
|
+
default:
|
|
216
|
+
return `${name}=${joinedValues2}`;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
const separator = separatorArrayExplode(style);
|
|
220
|
+
const joinedValues = value.map((v) => {
|
|
221
|
+
if (style === "label" || style === "simple") {
|
|
222
|
+
return allowReserved ? v : encodeURIComponent(v);
|
|
223
|
+
}
|
|
224
|
+
return serializePrimitiveParam({
|
|
225
|
+
allowReserved,
|
|
226
|
+
name,
|
|
227
|
+
value: v
|
|
228
|
+
});
|
|
229
|
+
}).join(separator);
|
|
230
|
+
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
231
|
+
};
|
|
232
|
+
var serializePrimitiveParam = ({
|
|
233
|
+
allowReserved,
|
|
234
|
+
name,
|
|
235
|
+
value
|
|
236
|
+
}) => {
|
|
237
|
+
if (value === void 0 || value === null) {
|
|
238
|
+
return "";
|
|
239
|
+
}
|
|
240
|
+
if (typeof value === "object") {
|
|
241
|
+
throw new Error(
|
|
242
|
+
"Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these."
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
|
|
246
|
+
};
|
|
247
|
+
var serializeObjectParam = ({
|
|
248
|
+
allowReserved,
|
|
249
|
+
explode,
|
|
250
|
+
name,
|
|
251
|
+
style,
|
|
252
|
+
value,
|
|
253
|
+
valueOnly
|
|
254
|
+
}) => {
|
|
255
|
+
if (value instanceof Date) {
|
|
256
|
+
return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
|
|
257
|
+
}
|
|
258
|
+
if (style !== "deepObject" && !explode) {
|
|
259
|
+
let values = [];
|
|
260
|
+
Object.entries(value).forEach(([key, v]) => {
|
|
261
|
+
values = [
|
|
262
|
+
...values,
|
|
263
|
+
key,
|
|
264
|
+
allowReserved ? v : encodeURIComponent(v)
|
|
265
|
+
];
|
|
266
|
+
});
|
|
267
|
+
const joinedValues2 = values.join(",");
|
|
268
|
+
switch (style) {
|
|
269
|
+
case "form":
|
|
270
|
+
return `${name}=${joinedValues2}`;
|
|
271
|
+
case "label":
|
|
272
|
+
return `.${joinedValues2}`;
|
|
273
|
+
case "matrix":
|
|
274
|
+
return `;${name}=${joinedValues2}`;
|
|
275
|
+
default:
|
|
276
|
+
return joinedValues2;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
const separator = separatorObjectExplode(style);
|
|
280
|
+
const joinedValues = Object.entries(value).map(
|
|
281
|
+
([key, v]) => serializePrimitiveParam({
|
|
282
|
+
allowReserved,
|
|
283
|
+
name: style === "deepObject" ? `${name}[${key}]` : key,
|
|
284
|
+
value: v
|
|
285
|
+
})
|
|
286
|
+
).join(separator);
|
|
287
|
+
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
// ../core/src/core/utils.gen.ts
|
|
291
|
+
var PATH_PARAM_RE = /\{[^{}]+\}/g;
|
|
292
|
+
var defaultPathSerializer = ({ path, url: _url }) => {
|
|
293
|
+
let url = _url;
|
|
294
|
+
const matches = _url.match(PATH_PARAM_RE);
|
|
295
|
+
if (matches) {
|
|
296
|
+
for (const match of matches) {
|
|
297
|
+
let explode = false;
|
|
298
|
+
let name = match.substring(1, match.length - 1);
|
|
299
|
+
let style = "simple";
|
|
300
|
+
if (name.endsWith("*")) {
|
|
301
|
+
explode = true;
|
|
302
|
+
name = name.substring(0, name.length - 1);
|
|
303
|
+
}
|
|
304
|
+
if (name.startsWith(".")) {
|
|
305
|
+
name = name.substring(1);
|
|
306
|
+
style = "label";
|
|
307
|
+
} else if (name.startsWith(";")) {
|
|
308
|
+
name = name.substring(1);
|
|
309
|
+
style = "matrix";
|
|
310
|
+
}
|
|
311
|
+
const value = path[name];
|
|
312
|
+
if (value === void 0 || value === null) {
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
if (Array.isArray(value)) {
|
|
316
|
+
url = url.replace(
|
|
317
|
+
match,
|
|
318
|
+
serializeArrayParam({ explode, name, style, value })
|
|
319
|
+
);
|
|
320
|
+
continue;
|
|
321
|
+
}
|
|
322
|
+
if (typeof value === "object") {
|
|
323
|
+
url = url.replace(
|
|
324
|
+
match,
|
|
325
|
+
serializeObjectParam({
|
|
326
|
+
explode,
|
|
327
|
+
name,
|
|
328
|
+
style,
|
|
329
|
+
value,
|
|
330
|
+
valueOnly: true
|
|
331
|
+
})
|
|
332
|
+
);
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
if (style === "matrix") {
|
|
336
|
+
url = url.replace(
|
|
337
|
+
match,
|
|
338
|
+
`;${serializePrimitiveParam({
|
|
339
|
+
name,
|
|
340
|
+
value
|
|
341
|
+
})}`
|
|
342
|
+
);
|
|
343
|
+
continue;
|
|
344
|
+
}
|
|
345
|
+
const replaceValue = encodeURIComponent(
|
|
346
|
+
style === "label" ? `.${value}` : value
|
|
347
|
+
);
|
|
348
|
+
url = url.replace(match, replaceValue);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
return url;
|
|
352
|
+
};
|
|
353
|
+
var getUrl = ({
|
|
354
|
+
baseUrl,
|
|
355
|
+
path,
|
|
356
|
+
query,
|
|
357
|
+
querySerializer,
|
|
358
|
+
url: _url
|
|
359
|
+
}) => {
|
|
360
|
+
const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
|
|
361
|
+
let url = (baseUrl ?? "") + pathUrl;
|
|
362
|
+
if (path) {
|
|
363
|
+
url = defaultPathSerializer({ path, url });
|
|
364
|
+
}
|
|
365
|
+
let search = query ? querySerializer(query) : "";
|
|
366
|
+
if (search.startsWith("?")) {
|
|
367
|
+
search = search.substring(1);
|
|
368
|
+
}
|
|
369
|
+
if (search) {
|
|
370
|
+
url += `?${search}`;
|
|
371
|
+
}
|
|
372
|
+
return url;
|
|
373
|
+
};
|
|
374
|
+
function getValidRequestBody(options) {
|
|
375
|
+
const hasBody = options.body !== void 0;
|
|
376
|
+
const isSerializedBody = hasBody && options.bodySerializer;
|
|
377
|
+
if (isSerializedBody) {
|
|
378
|
+
if ("serializedBody" in options) {
|
|
379
|
+
const hasSerializedBody = options.serializedBody !== void 0 && options.serializedBody !== "";
|
|
380
|
+
return hasSerializedBody ? options.serializedBody : null;
|
|
381
|
+
}
|
|
382
|
+
return options.body !== "" ? options.body : null;
|
|
383
|
+
}
|
|
384
|
+
if (hasBody) {
|
|
385
|
+
return options.body;
|
|
386
|
+
}
|
|
387
|
+
return void 0;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// ../core/src/core/auth.gen.ts
|
|
391
|
+
var getAuthToken = async (auth, callback) => {
|
|
392
|
+
const token = typeof callback === "function" ? await callback(auth) : callback;
|
|
393
|
+
if (!token) {
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
if (auth.scheme === "bearer") {
|
|
397
|
+
return `Bearer ${token}`;
|
|
398
|
+
}
|
|
399
|
+
if (auth.scheme === "basic") {
|
|
400
|
+
return `Basic ${btoa(token)}`;
|
|
401
|
+
}
|
|
402
|
+
return token;
|
|
403
|
+
};
|
|
404
|
+
|
|
405
|
+
// ../core/src/client/utils.gen.ts
|
|
406
|
+
var createQuerySerializer = ({
|
|
407
|
+
parameters = {},
|
|
408
|
+
...args
|
|
409
|
+
} = {}) => {
|
|
410
|
+
const querySerializer = (queryParams) => {
|
|
411
|
+
const search = [];
|
|
412
|
+
if (queryParams && typeof queryParams === "object") {
|
|
413
|
+
for (const name in queryParams) {
|
|
414
|
+
const value = queryParams[name];
|
|
415
|
+
if (value === void 0 || value === null) {
|
|
416
|
+
continue;
|
|
417
|
+
}
|
|
418
|
+
const options = parameters[name] || args;
|
|
419
|
+
if (Array.isArray(value)) {
|
|
420
|
+
const serializedArray = serializeArrayParam({
|
|
421
|
+
allowReserved: options.allowReserved,
|
|
422
|
+
explode: true,
|
|
423
|
+
name,
|
|
424
|
+
style: "form",
|
|
425
|
+
value,
|
|
426
|
+
...options.array
|
|
427
|
+
});
|
|
428
|
+
if (serializedArray) search.push(serializedArray);
|
|
429
|
+
} else if (typeof value === "object") {
|
|
430
|
+
const serializedObject = serializeObjectParam({
|
|
431
|
+
allowReserved: options.allowReserved,
|
|
432
|
+
explode: true,
|
|
433
|
+
name,
|
|
434
|
+
style: "deepObject",
|
|
435
|
+
value,
|
|
436
|
+
...options.object
|
|
437
|
+
});
|
|
438
|
+
if (serializedObject) search.push(serializedObject);
|
|
439
|
+
} else {
|
|
440
|
+
const serializedPrimitive = serializePrimitiveParam({
|
|
441
|
+
allowReserved: options.allowReserved,
|
|
442
|
+
name,
|
|
443
|
+
value
|
|
444
|
+
});
|
|
445
|
+
if (serializedPrimitive) search.push(serializedPrimitive);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
return search.join("&");
|
|
450
|
+
};
|
|
451
|
+
return querySerializer;
|
|
452
|
+
};
|
|
453
|
+
var getParseAs = (contentType) => {
|
|
454
|
+
if (!contentType) {
|
|
455
|
+
return "stream";
|
|
456
|
+
}
|
|
457
|
+
const cleanContent = contentType.split(";")[0]?.trim();
|
|
458
|
+
if (!cleanContent) {
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) {
|
|
462
|
+
return "json";
|
|
463
|
+
}
|
|
464
|
+
if (cleanContent === "multipart/form-data") {
|
|
465
|
+
return "formData";
|
|
466
|
+
}
|
|
467
|
+
if (["application/", "audio/", "image/", "video/"].some(
|
|
468
|
+
(type) => cleanContent.startsWith(type)
|
|
469
|
+
)) {
|
|
470
|
+
return "blob";
|
|
471
|
+
}
|
|
472
|
+
if (cleanContent.startsWith("text/")) {
|
|
473
|
+
return "text";
|
|
474
|
+
}
|
|
475
|
+
return;
|
|
476
|
+
};
|
|
477
|
+
var checkForExistence = (options, name) => {
|
|
478
|
+
if (!name) {
|
|
479
|
+
return false;
|
|
480
|
+
}
|
|
481
|
+
if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) {
|
|
482
|
+
return true;
|
|
483
|
+
}
|
|
484
|
+
return false;
|
|
485
|
+
};
|
|
486
|
+
var setAuthParams = async ({
|
|
487
|
+
security,
|
|
488
|
+
...options
|
|
489
|
+
}) => {
|
|
490
|
+
for (const auth of security) {
|
|
491
|
+
if (checkForExistence(options, auth.name)) {
|
|
492
|
+
continue;
|
|
493
|
+
}
|
|
494
|
+
const token = await getAuthToken(auth, options.auth);
|
|
495
|
+
if (!token) {
|
|
496
|
+
continue;
|
|
497
|
+
}
|
|
498
|
+
const name = auth.name ?? "Authorization";
|
|
499
|
+
switch (auth.in) {
|
|
500
|
+
case "query":
|
|
501
|
+
if (!options.query) {
|
|
502
|
+
options.query = {};
|
|
503
|
+
}
|
|
504
|
+
options.query[name] = token;
|
|
505
|
+
break;
|
|
506
|
+
case "cookie":
|
|
507
|
+
options.headers.append("Cookie", `${name}=${token}`);
|
|
508
|
+
break;
|
|
509
|
+
case "header":
|
|
510
|
+
default:
|
|
511
|
+
options.headers.set(name, token);
|
|
512
|
+
break;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
};
|
|
516
|
+
var buildUrl = (options) => getUrl({
|
|
517
|
+
baseUrl: options.baseUrl,
|
|
518
|
+
path: options.path,
|
|
519
|
+
query: options.query,
|
|
520
|
+
querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
|
|
521
|
+
url: options.url
|
|
522
|
+
});
|
|
523
|
+
var mergeConfigs = (a, b) => {
|
|
524
|
+
const config = { ...a, ...b };
|
|
525
|
+
if (config.baseUrl?.endsWith("/")) {
|
|
526
|
+
config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
|
|
527
|
+
}
|
|
528
|
+
config.headers = mergeHeaders(a.headers, b.headers);
|
|
529
|
+
return config;
|
|
530
|
+
};
|
|
531
|
+
var headersEntries = (headers) => {
|
|
532
|
+
const entries = [];
|
|
533
|
+
headers.forEach((value, key) => {
|
|
534
|
+
entries.push([key, value]);
|
|
535
|
+
});
|
|
536
|
+
return entries;
|
|
537
|
+
};
|
|
538
|
+
var mergeHeaders = (...headers) => {
|
|
539
|
+
const mergedHeaders = new Headers();
|
|
540
|
+
for (const header of headers) {
|
|
541
|
+
if (!header) {
|
|
542
|
+
continue;
|
|
543
|
+
}
|
|
544
|
+
const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
|
|
545
|
+
for (const [key, value] of iterator) {
|
|
546
|
+
if (value === null) {
|
|
547
|
+
mergedHeaders.delete(key);
|
|
548
|
+
} else if (Array.isArray(value)) {
|
|
549
|
+
for (const v of value) {
|
|
550
|
+
mergedHeaders.append(key, v);
|
|
551
|
+
}
|
|
552
|
+
} else if (value !== void 0) {
|
|
553
|
+
mergedHeaders.set(
|
|
554
|
+
key,
|
|
555
|
+
typeof value === "object" ? JSON.stringify(value) : value
|
|
556
|
+
);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
return mergedHeaders;
|
|
561
|
+
};
|
|
562
|
+
var Interceptors = class {
|
|
563
|
+
fns = [];
|
|
564
|
+
clear() {
|
|
565
|
+
this.fns = [];
|
|
566
|
+
}
|
|
567
|
+
eject(id) {
|
|
568
|
+
const index = this.getInterceptorIndex(id);
|
|
569
|
+
if (this.fns[index]) {
|
|
570
|
+
this.fns[index] = null;
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
exists(id) {
|
|
574
|
+
const index = this.getInterceptorIndex(id);
|
|
575
|
+
return Boolean(this.fns[index]);
|
|
576
|
+
}
|
|
577
|
+
getInterceptorIndex(id) {
|
|
578
|
+
if (typeof id === "number") {
|
|
579
|
+
return this.fns[id] ? id : -1;
|
|
580
|
+
}
|
|
581
|
+
return this.fns.indexOf(id);
|
|
582
|
+
}
|
|
583
|
+
update(id, fn) {
|
|
584
|
+
const index = this.getInterceptorIndex(id);
|
|
585
|
+
if (this.fns[index]) {
|
|
586
|
+
this.fns[index] = fn;
|
|
587
|
+
return id;
|
|
588
|
+
}
|
|
589
|
+
return false;
|
|
590
|
+
}
|
|
591
|
+
use(fn) {
|
|
592
|
+
this.fns.push(fn);
|
|
593
|
+
return this.fns.length - 1;
|
|
594
|
+
}
|
|
595
|
+
};
|
|
596
|
+
var createInterceptors = () => ({
|
|
597
|
+
error: new Interceptors(),
|
|
598
|
+
request: new Interceptors(),
|
|
599
|
+
response: new Interceptors()
|
|
600
|
+
});
|
|
601
|
+
var defaultQuerySerializer = createQuerySerializer({
|
|
602
|
+
allowReserved: false,
|
|
603
|
+
array: {
|
|
604
|
+
explode: true,
|
|
605
|
+
style: "form"
|
|
606
|
+
},
|
|
607
|
+
object: {
|
|
608
|
+
explode: true,
|
|
609
|
+
style: "deepObject"
|
|
610
|
+
}
|
|
611
|
+
});
|
|
612
|
+
var defaultHeaders = {
|
|
613
|
+
"Content-Type": "application/json"
|
|
614
|
+
};
|
|
615
|
+
var createConfig = (override = {}) => ({
|
|
616
|
+
...jsonBodySerializer,
|
|
617
|
+
headers: defaultHeaders,
|
|
618
|
+
parseAs: "auto",
|
|
619
|
+
querySerializer: defaultQuerySerializer,
|
|
620
|
+
...override
|
|
621
|
+
});
|
|
622
|
+
|
|
623
|
+
// ../core/src/client/client.gen.ts
|
|
624
|
+
var createClient = (config = {}) => {
|
|
625
|
+
let _config = mergeConfigs(createConfig(), config);
|
|
626
|
+
const getConfig = () => ({ ..._config });
|
|
627
|
+
const setConfig = (config2) => {
|
|
628
|
+
_config = mergeConfigs(_config, config2);
|
|
629
|
+
return getConfig();
|
|
630
|
+
};
|
|
631
|
+
const interceptors = createInterceptors();
|
|
632
|
+
const beforeRequest = async (options) => {
|
|
633
|
+
const opts = {
|
|
634
|
+
..._config,
|
|
635
|
+
...options,
|
|
636
|
+
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
|
|
637
|
+
headers: mergeHeaders(_config.headers, options.headers),
|
|
638
|
+
serializedBody: void 0
|
|
639
|
+
};
|
|
640
|
+
if (opts.security) {
|
|
641
|
+
await setAuthParams({
|
|
642
|
+
...opts,
|
|
643
|
+
security: opts.security
|
|
644
|
+
});
|
|
645
|
+
}
|
|
646
|
+
if (opts.requestValidator) {
|
|
647
|
+
await opts.requestValidator(opts);
|
|
648
|
+
}
|
|
649
|
+
if (opts.body !== void 0 && opts.bodySerializer) {
|
|
650
|
+
opts.serializedBody = opts.bodySerializer(opts.body);
|
|
651
|
+
}
|
|
652
|
+
if (opts.body === void 0 || opts.serializedBody === "") {
|
|
653
|
+
opts.headers.delete("Content-Type");
|
|
654
|
+
}
|
|
655
|
+
const url = buildUrl(opts);
|
|
656
|
+
return { opts, url };
|
|
657
|
+
};
|
|
658
|
+
const request = async (options) => {
|
|
659
|
+
const { opts, url } = await beforeRequest(options);
|
|
660
|
+
const requestInit = {
|
|
661
|
+
redirect: "follow",
|
|
662
|
+
...opts,
|
|
663
|
+
body: getValidRequestBody(opts)
|
|
664
|
+
};
|
|
665
|
+
let request2 = new Request(url, requestInit);
|
|
666
|
+
for (const fn of interceptors.request.fns) {
|
|
667
|
+
if (fn) {
|
|
668
|
+
request2 = await fn(request2, opts);
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
const _fetch = opts.fetch;
|
|
672
|
+
let response;
|
|
673
|
+
try {
|
|
674
|
+
response = await _fetch(request2);
|
|
675
|
+
} catch (error2) {
|
|
676
|
+
let finalError2 = error2;
|
|
677
|
+
for (const fn of interceptors.error.fns) {
|
|
678
|
+
if (fn) {
|
|
679
|
+
finalError2 = await fn(
|
|
680
|
+
error2,
|
|
681
|
+
void 0,
|
|
682
|
+
request2,
|
|
683
|
+
opts
|
|
684
|
+
);
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
finalError2 = finalError2 || {};
|
|
688
|
+
if (opts.throwOnError) {
|
|
689
|
+
throw finalError2;
|
|
690
|
+
}
|
|
691
|
+
return opts.responseStyle === "data" ? void 0 : {
|
|
692
|
+
error: finalError2,
|
|
693
|
+
request: request2,
|
|
694
|
+
response: void 0
|
|
695
|
+
};
|
|
696
|
+
}
|
|
697
|
+
for (const fn of interceptors.response.fns) {
|
|
698
|
+
if (fn) {
|
|
699
|
+
response = await fn(response, request2, opts);
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
const result = {
|
|
703
|
+
request: request2,
|
|
704
|
+
response
|
|
705
|
+
};
|
|
706
|
+
if (response.ok) {
|
|
707
|
+
const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
|
|
708
|
+
if (response.status === 204 || response.headers.get("Content-Length") === "0") {
|
|
709
|
+
let emptyData;
|
|
710
|
+
switch (parseAs) {
|
|
711
|
+
case "arrayBuffer":
|
|
712
|
+
case "blob":
|
|
713
|
+
case "text":
|
|
714
|
+
emptyData = await response[parseAs]();
|
|
715
|
+
break;
|
|
716
|
+
case "formData":
|
|
717
|
+
emptyData = new FormData();
|
|
718
|
+
break;
|
|
719
|
+
case "stream":
|
|
720
|
+
emptyData = response.body;
|
|
721
|
+
break;
|
|
722
|
+
case "json":
|
|
723
|
+
default:
|
|
724
|
+
emptyData = {};
|
|
725
|
+
break;
|
|
726
|
+
}
|
|
727
|
+
return opts.responseStyle === "data" ? emptyData : {
|
|
728
|
+
data: emptyData,
|
|
729
|
+
...result
|
|
730
|
+
};
|
|
731
|
+
}
|
|
732
|
+
let data;
|
|
733
|
+
switch (parseAs) {
|
|
734
|
+
case "arrayBuffer":
|
|
735
|
+
case "blob":
|
|
736
|
+
case "formData":
|
|
737
|
+
case "json":
|
|
738
|
+
case "text":
|
|
739
|
+
data = await response[parseAs]();
|
|
740
|
+
break;
|
|
741
|
+
case "stream":
|
|
742
|
+
return opts.responseStyle === "data" ? response.body : {
|
|
743
|
+
data: response.body,
|
|
744
|
+
...result
|
|
745
|
+
};
|
|
746
|
+
}
|
|
747
|
+
if (parseAs === "json") {
|
|
748
|
+
if (opts.responseValidator) {
|
|
749
|
+
await opts.responseValidator(data);
|
|
750
|
+
}
|
|
751
|
+
if (opts.responseTransformer) {
|
|
752
|
+
data = await opts.responseTransformer(data);
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
return opts.responseStyle === "data" ? data : {
|
|
756
|
+
data,
|
|
757
|
+
...result
|
|
758
|
+
};
|
|
759
|
+
}
|
|
760
|
+
const textError = await response.text();
|
|
761
|
+
let jsonError;
|
|
762
|
+
try {
|
|
763
|
+
jsonError = JSON.parse(textError);
|
|
764
|
+
} catch {
|
|
765
|
+
}
|
|
766
|
+
const error = jsonError ?? textError;
|
|
767
|
+
let finalError = error;
|
|
768
|
+
for (const fn of interceptors.error.fns) {
|
|
769
|
+
if (fn) {
|
|
770
|
+
finalError = await fn(error, response, request2, opts);
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
finalError = finalError || {};
|
|
774
|
+
if (opts.throwOnError) {
|
|
775
|
+
throw finalError;
|
|
776
|
+
}
|
|
777
|
+
return opts.responseStyle === "data" ? void 0 : {
|
|
778
|
+
error: finalError,
|
|
779
|
+
...result
|
|
780
|
+
};
|
|
781
|
+
};
|
|
782
|
+
const makeMethodFn = (method) => (options) => request({ ...options, method });
|
|
783
|
+
const makeSseFn = (method) => async (options) => {
|
|
784
|
+
const { opts, url } = await beforeRequest(options);
|
|
785
|
+
return createSseClient({
|
|
786
|
+
...opts,
|
|
787
|
+
body: opts.body,
|
|
788
|
+
headers: opts.headers,
|
|
789
|
+
method,
|
|
790
|
+
onRequest: async (url2, init) => {
|
|
791
|
+
let request2 = new Request(url2, init);
|
|
792
|
+
for (const fn of interceptors.request.fns) {
|
|
793
|
+
if (fn) {
|
|
794
|
+
request2 = await fn(request2, opts);
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
return request2;
|
|
798
|
+
},
|
|
799
|
+
serializedBody: getValidRequestBody(opts),
|
|
800
|
+
url
|
|
801
|
+
});
|
|
802
|
+
};
|
|
803
|
+
return {
|
|
804
|
+
buildUrl,
|
|
805
|
+
connect: makeMethodFn("CONNECT"),
|
|
806
|
+
delete: makeMethodFn("DELETE"),
|
|
807
|
+
get: makeMethodFn("GET"),
|
|
808
|
+
getConfig,
|
|
809
|
+
head: makeMethodFn("HEAD"),
|
|
810
|
+
interceptors,
|
|
811
|
+
options: makeMethodFn("OPTIONS"),
|
|
812
|
+
patch: makeMethodFn("PATCH"),
|
|
813
|
+
post: makeMethodFn("POST"),
|
|
814
|
+
put: makeMethodFn("PUT"),
|
|
815
|
+
request,
|
|
816
|
+
setConfig,
|
|
817
|
+
sse: {
|
|
818
|
+
connect: makeSseFn("CONNECT"),
|
|
819
|
+
delete: makeSseFn("DELETE"),
|
|
820
|
+
get: makeSseFn("GET"),
|
|
821
|
+
head: makeSseFn("HEAD"),
|
|
822
|
+
options: makeSseFn("OPTIONS"),
|
|
823
|
+
patch: makeSseFn("PATCH"),
|
|
824
|
+
post: makeSseFn("POST"),
|
|
825
|
+
put: makeSseFn("PUT"),
|
|
826
|
+
trace: makeSseFn("TRACE")
|
|
827
|
+
},
|
|
828
|
+
trace: makeMethodFn("TRACE")
|
|
829
|
+
};
|
|
830
|
+
};
|
|
831
|
+
|
|
832
|
+
// ../core/src/client.gen.ts
|
|
833
|
+
var client = createClient(createConfig({ baseUrl: "https://permi.xyz/api/v1" }));
|
|
834
|
+
|
|
835
|
+
// ../core/src/sdk.gen.ts
|
|
836
|
+
var address = (options) => (options?.client ?? client).get({
|
|
837
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
838
|
+
url: "/address",
|
|
839
|
+
...options
|
|
840
|
+
});
|
|
841
|
+
var balance = (options) => (options?.client ?? client).get({
|
|
842
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
843
|
+
url: "/balance",
|
|
844
|
+
...options
|
|
845
|
+
});
|
|
846
|
+
var signMessage = (options) => (options.client ?? client).post({
|
|
847
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
848
|
+
url: "/sign-message",
|
|
849
|
+
...options,
|
|
850
|
+
headers: {
|
|
851
|
+
"Content-Type": "application/json",
|
|
852
|
+
...options.headers
|
|
853
|
+
}
|
|
854
|
+
});
|
|
855
|
+
var signTypedData = (options) => (options.client ?? client).post({
|
|
856
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
857
|
+
url: "/sign-typed-data",
|
|
858
|
+
...options,
|
|
859
|
+
headers: {
|
|
860
|
+
"Content-Type": "application/json",
|
|
861
|
+
...options.headers
|
|
862
|
+
}
|
|
863
|
+
});
|
|
864
|
+
var signTransaction = (options) => (options.client ?? client).post({
|
|
865
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
866
|
+
url: "/sign-transaction",
|
|
867
|
+
...options,
|
|
868
|
+
headers: {
|
|
869
|
+
"Content-Type": "application/json",
|
|
870
|
+
...options.headers
|
|
871
|
+
}
|
|
872
|
+
});
|
|
873
|
+
|
|
874
|
+
// ../core/src/@tanstack/react-query.gen.ts
|
|
875
|
+
var createQueryKey = (id, options, infinite, tags) => {
|
|
876
|
+
const params = { _id: id, baseUrl: options?.baseUrl || (options?.client ?? client).getConfig().baseUrl };
|
|
877
|
+
if (infinite) {
|
|
878
|
+
params._infinite = infinite;
|
|
879
|
+
}
|
|
880
|
+
if (tags) {
|
|
881
|
+
params.tags = tags;
|
|
882
|
+
}
|
|
883
|
+
if (options?.body) {
|
|
884
|
+
params.body = options.body;
|
|
885
|
+
}
|
|
886
|
+
if (options?.headers) {
|
|
887
|
+
params.headers = options.headers;
|
|
888
|
+
}
|
|
889
|
+
if (options?.path) {
|
|
890
|
+
params.path = options.path;
|
|
891
|
+
}
|
|
892
|
+
if (options?.query) {
|
|
893
|
+
params.query = options.query;
|
|
894
|
+
}
|
|
895
|
+
return [params];
|
|
896
|
+
};
|
|
897
|
+
var addressQueryKey = (options) => createQueryKey("address", options);
|
|
898
|
+
var addressOptions = (options) => queryOptions({
|
|
899
|
+
queryFn: async ({ queryKey, signal }) => {
|
|
900
|
+
const { data } = await address({
|
|
901
|
+
...options,
|
|
902
|
+
...queryKey[0],
|
|
903
|
+
signal,
|
|
904
|
+
throwOnError: true
|
|
905
|
+
});
|
|
906
|
+
return data;
|
|
907
|
+
},
|
|
908
|
+
queryKey: addressQueryKey(options)
|
|
909
|
+
});
|
|
910
|
+
var balanceQueryKey = (options) => createQueryKey("balance", options);
|
|
911
|
+
var balanceOptions = (options) => queryOptions({
|
|
912
|
+
queryFn: async ({ queryKey, signal }) => {
|
|
913
|
+
const { data } = await balance({
|
|
914
|
+
...options,
|
|
915
|
+
...queryKey[0],
|
|
916
|
+
signal,
|
|
917
|
+
throwOnError: true
|
|
918
|
+
});
|
|
919
|
+
return data;
|
|
920
|
+
},
|
|
921
|
+
queryKey: balanceQueryKey(options)
|
|
922
|
+
});
|
|
11
923
|
|
|
12
924
|
// src/providers/index.tsx
|
|
13
925
|
import { useMemo as useMemo2, createContext, useContext } from "react";
|
|
@@ -88,7 +1000,7 @@ var PermiProviderRaw = ({
|
|
|
88
1000
|
const { user } = useAuth();
|
|
89
1001
|
const contextValue = useMemo2(
|
|
90
1002
|
() => ({
|
|
91
|
-
baseUrl
|
|
1003
|
+
baseUrl,
|
|
92
1004
|
getAccessToken: () => user?.access_token ?? ""
|
|
93
1005
|
}),
|
|
94
1006
|
[user, baseUrl]
|
|
@@ -147,10 +1059,10 @@ var useOptions = (options) => {
|
|
|
147
1059
|
[options, baseUrl, getAccessToken]
|
|
148
1060
|
);
|
|
149
1061
|
};
|
|
150
|
-
var useBalance = (
|
|
151
|
-
var useAddress = (
|
|
1062
|
+
var useBalance = (queryOptions2) => useQuery({ ...balanceOptions(useOptions()), ...queryOptions2 });
|
|
1063
|
+
var useAddress = (queryOptions2) => useQuery({ ...addressOptions(useOptions()), ...queryOptions2 });
|
|
152
1064
|
var useAccount = () => {
|
|
153
|
-
const { data:
|
|
1065
|
+
const { data: address2, isLoading: isAddressLoading } = useAddress();
|
|
154
1066
|
const { baseUrl, getAccessToken } = usePermiContext();
|
|
155
1067
|
const getAuthOptions = (options) => {
|
|
156
1068
|
return getOptions(
|
|
@@ -161,22 +1073,22 @@ var useAccount = () => {
|
|
|
161
1073
|
getAccessToken
|
|
162
1074
|
);
|
|
163
1075
|
};
|
|
164
|
-
const account = !
|
|
165
|
-
address,
|
|
1076
|
+
const account = !address2 ? void 0 : toAccount({
|
|
1077
|
+
address: address2,
|
|
166
1078
|
signMessage: async (params) => {
|
|
167
|
-
return await
|
|
1079
|
+
return await signMessage(
|
|
168
1080
|
getAuthOptions({
|
|
169
1081
|
body: params
|
|
170
1082
|
})
|
|
171
1083
|
).then((res) => res.data);
|
|
172
1084
|
},
|
|
173
1085
|
signTransaction: async (params) => {
|
|
174
|
-
return await
|
|
1086
|
+
return await signTransaction(
|
|
175
1087
|
getAuthOptions({ body: params })
|
|
176
1088
|
).then((res) => res.data);
|
|
177
1089
|
},
|
|
178
1090
|
signTypedData: async (params) => {
|
|
179
|
-
return await
|
|
1091
|
+
return await signTypedData(getAuthOptions({ body: params })).then(
|
|
180
1092
|
(res) => res.data
|
|
181
1093
|
);
|
|
182
1094
|
}
|