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