@arkade-os/sdk 0.5.7 → 0.5.8
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 +2 -2
- package/dist/adapters/expo.cjs +6 -6
- package/dist/adapters/expo.d.cts +2 -2
- package/dist/adapters/expo.d.ts +2 -2
- package/dist/adapters/expo.js +3 -3
- package/dist/{asyncStorageTaskQueue-B9byr6ij.d.cts → asyncStorageTaskQueue-B5NPtkXo.d.cts} +2 -2
- package/dist/{asyncStorageTaskQueue-XP4CCdRY.d.ts → asyncStorageTaskQueue-YPwiJyVA.d.ts} +2 -2
- package/dist/{chunk-V2DDN4MV.js → chunk-3F5AJ235.js} +4 -4
- package/dist/{chunk-V2DDN4MV.js.map → chunk-3F5AJ235.js.map} +1 -1
- package/dist/{chunk-3NALVGMJ.cjs → chunk-4IDCSOP2.cjs} +22 -16
- package/dist/chunk-4IDCSOP2.cjs.map +1 -0
- package/dist/{chunk-JFJNB7ZH.cjs → chunk-5PWL7WOT.cjs} +7 -5
- package/dist/chunk-5PWL7WOT.cjs.map +1 -0
- package/dist/{chunk-MWMO2ZQP.js → chunk-E7LKKEVR.js} +10 -4
- package/dist/chunk-E7LKKEVR.js.map +1 -0
- package/dist/{chunk-URGVQ5TQ.cjs → chunk-EQ3JVVUR.cjs} +599 -547
- package/dist/chunk-EQ3JVVUR.cjs.map +1 -0
- package/dist/{chunk-MWEDDWFU.js → chunk-F5O6JI2H.js} +8 -6
- package/dist/chunk-F5O6JI2H.js.map +1 -0
- package/dist/{chunk-4AJRIM44.js → chunk-H7GT3QC4.js} +4 -4
- package/dist/{chunk-4AJRIM44.js.map → chunk-H7GT3QC4.js.map} +1 -1
- package/dist/{chunk-MXCB6EVM.cjs → chunk-JQSHFSME.cjs} +19 -17
- package/dist/chunk-JQSHFSME.cjs.map +1 -0
- package/dist/{chunk-MQUATTIM.cjs → chunk-JYQXB7OH.cjs} +19 -19
- package/dist/{chunk-MQUATTIM.cjs.map → chunk-JYQXB7OH.cjs.map} +1 -1
- package/dist/{chunk-V5WRO3P6.cjs → chunk-KWR37J6L.cjs} +10 -10
- package/dist/{chunk-V5WRO3P6.cjs.map → chunk-KWR37J6L.cjs.map} +1 -1
- package/dist/{chunk-X6ZI53DZ.cjs → chunk-L7OOPAUG.cjs} +14 -26
- package/dist/chunk-L7OOPAUG.cjs.map +1 -0
- package/dist/{chunk-RLD7DRSZ.js → chunk-OLKZUJIN.js} +127 -75
- package/dist/chunk-OLKZUJIN.js.map +1 -0
- package/dist/{chunk-OMPDPBT5.cjs → chunk-SOJDUKY6.cjs} +271 -225
- package/dist/chunk-SOJDUKY6.cjs.map +1 -0
- package/dist/{chunk-V3ZLL5VY.js → chunk-U34GU5RM.js} +9 -21
- package/dist/chunk-U34GU5RM.js.map +1 -0
- package/dist/{chunk-DNFTHG73.js → chunk-XXNPX4MK.js} +7 -5
- package/dist/chunk-XXNPX4MK.js.map +1 -0
- package/dist/{chunk-VMVFRTF4.js → chunk-YTOABP6J.js} +268 -226
- package/dist/chunk-YTOABP6J.js.map +1 -0
- package/dist/compiler.cjs +3 -3
- package/dist/compiler.d.cts +1 -1
- package/dist/compiler.d.ts +1 -1
- package/dist/compiler.js +2 -2
- package/dist/contracts/handlers/index.cjs +10 -10
- package/dist/contracts/handlers/index.d.cts +3 -3
- package/dist/contracts/handlers/index.d.ts +3 -3
- package/dist/contracts/handlers/index.js +3 -3
- package/dist/{index-Ccfhdfvj.d.cts → index-CKzBYoDa.d.cts} +2 -2
- package/dist/{index-B_kcptF8.d.ts → index-COs69e8T.d.ts} +2 -2
- package/dist/{index-18cDMayF.d.ts → index-Pk3i_MMU.d.ts} +12 -2
- package/dist/{index-DDJFHfba.d.cts → index-czozpKPT.d.cts} +12 -2
- package/dist/index.cjs +325 -321
- package/dist/index.d.cts +52 -23
- package/dist/index.d.ts +52 -23
- package/dist/index.js +6 -6
- package/dist/{keyringDescriptorProvider-DL-jAiRO.d.ts → keyringDescriptorProvider-CbNzWwbS.d.ts} +15 -2
- package/dist/{keyringDescriptorProvider-Dtv0JWrT.d.cts → keyringDescriptorProvider-nC8fIjBN.d.cts} +15 -2
- package/dist/{program-BARSNg3X.d.ts → program-38A2Twvj.d.ts} +4 -2
- package/dist/{program-znrWkxE4.d.cts → program-DPzf5qsk.d.cts} +4 -2
- package/dist/repositories/realm/index.cjs +39 -39
- package/dist/repositories/realm/index.d.cts +2 -2
- package/dist/repositories/realm/index.d.ts +2 -2
- package/dist/repositories/realm/index.js +7 -7
- package/dist/repositories/sqlite/index.cjs +37 -37
- package/dist/repositories/sqlite/index.d.cts +2 -2
- package/dist/repositories/sqlite/index.d.ts +2 -2
- package/dist/repositories/sqlite/index.js +7 -7
- package/dist/{taskRunner-DUafWu0o.d.ts → taskRunner-DBOqvP33.d.ts} +2 -2
- package/dist/{taskRunner-JYHaLPne.d.cts → taskRunner-DXivOJHc.d.cts} +2 -2
- package/dist/wallet/expo/background.cjs +16 -16
- package/dist/wallet/expo/background.d.cts +3 -3
- package/dist/wallet/expo/background.d.ts +3 -3
- package/dist/wallet/expo/background.js +8 -8
- package/dist/wallet/expo/index.cjs +17 -17
- package/dist/wallet/expo/index.d.cts +3 -3
- package/dist/wallet/expo/index.d.ts +3 -3
- package/dist/wallet/expo/index.js +7 -7
- package/dist/worker/expo/index.cjs +11 -11
- package/dist/worker/expo/index.d.cts +4 -4
- package/dist/worker/expo/index.d.ts +4 -4
- package/dist/worker/expo/index.js +7 -7
- package/package.json +1 -1
- package/dist/chunk-3NALVGMJ.cjs.map +0 -1
- package/dist/chunk-DNFTHG73.js.map +0 -1
- package/dist/chunk-JFJNB7ZH.cjs.map +0 -1
- package/dist/chunk-MWEDDWFU.js.map +0 -1
- package/dist/chunk-MWMO2ZQP.js.map +0 -1
- package/dist/chunk-MXCB6EVM.cjs.map +0 -1
- package/dist/chunk-OMPDPBT5.cjs.map +0 -1
- package/dist/chunk-RLD7DRSZ.js.map +0 -1
- package/dist/chunk-URGVQ5TQ.cjs.map +0 -1
- package/dist/chunk-V3ZLL5VY.js.map +0 -1
- package/dist/chunk-VMVFRTF4.js.map +0 -1
- package/dist/chunk-X6ZI53DZ.cjs.map +0 -1
|
@@ -302,11 +302,17 @@ function checkKeyMatch(key, arkPsbtFieldKey, prefixOnly = false) {
|
|
|
302
302
|
}
|
|
303
303
|
|
|
304
304
|
// package.json
|
|
305
|
-
var version = "0.5.
|
|
305
|
+
var version = "0.5.8";
|
|
306
|
+
|
|
307
|
+
// src/utils/sdkVersionHeaders.ts
|
|
308
|
+
var sdkVersion = `ts-sdk/${version}`;
|
|
309
|
+
function sdkVersionHeaders() {
|
|
310
|
+
const origin = globalThis.location?.origin;
|
|
311
|
+
return typeof origin === "string" ? {} : { "X-SDK-VERSION": sdkVersion };
|
|
312
|
+
}
|
|
306
313
|
|
|
307
314
|
// src/utils/fetch.ts
|
|
308
315
|
var buildVersion = "0.9.9";
|
|
309
|
-
var sdkVersion = `ts-sdk/${version}`;
|
|
310
316
|
var ARKADE_VERSION_HEADERS = {
|
|
311
317
|
"X-Build-Version": buildVersion,
|
|
312
318
|
"X-SDK-VERSION": sdkVersion
|
|
@@ -368,102 +374,140 @@ function describeRequest(input, init) {
|
|
|
368
374
|
return { url, method };
|
|
369
375
|
}
|
|
370
376
|
|
|
371
|
-
// src/providers/
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
377
|
+
// src/providers/rateGate.ts
|
|
378
|
+
var DEFAULT_MAX_CONCURRENT = 6;
|
|
379
|
+
var DEFAULT_COOLDOWN_MS = 5e3;
|
|
380
|
+
var MAX_COOLDOWN_MS = 6e4;
|
|
381
|
+
var DEFAULT_JITTER_MS = 500;
|
|
382
|
+
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, Math.min(ms, MAX_TIMER_MS)));
|
|
383
|
+
function parseRetryAfterMs(header) {
|
|
384
|
+
if (header === null || header === void 0) return void 0;
|
|
385
|
+
const trimmed = header.trim();
|
|
386
|
+
if (trimmed === "") return void 0;
|
|
387
|
+
const seconds = Number(trimmed);
|
|
388
|
+
if (Number.isFinite(seconds)) return seconds < 0 ? void 0 : seconds * 1e3;
|
|
389
|
+
const at = Date.parse(trimmed);
|
|
390
|
+
if (!Number.isNaN(at)) return Math.max(0, at - Date.now());
|
|
391
|
+
return void 0;
|
|
392
|
+
}
|
|
393
|
+
function requestOrigin(input) {
|
|
394
|
+
let url;
|
|
395
|
+
if (typeof input === "string") {
|
|
396
|
+
url = input;
|
|
397
|
+
} else if (input instanceof URL) {
|
|
398
|
+
url = input.href;
|
|
399
|
+
} else {
|
|
400
|
+
url = input.url;
|
|
401
|
+
}
|
|
379
402
|
try {
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
const text = decoder.decode(chunk, { stream: true });
|
|
384
|
-
if (!text) continue;
|
|
385
|
-
const skipLF = pendingCR && text.startsWith("\n");
|
|
386
|
-
pendingCR = text.endsWith("\r");
|
|
387
|
-
buffer += (skipLF ? text.slice(1) : text).replace(/\r\n?/g, "\n");
|
|
388
|
-
const lines = buffer.split("\n");
|
|
389
|
-
buffer = lines.pop() ?? "";
|
|
390
|
-
for (const line of lines) {
|
|
391
|
-
if (line === "") {
|
|
392
|
-
const joined = data.join("\n");
|
|
393
|
-
if (joined) yield { event: event || "message", data: joined };
|
|
394
|
-
event = "";
|
|
395
|
-
data = [];
|
|
396
|
-
continue;
|
|
397
|
-
}
|
|
398
|
-
const colon = line.indexOf(":");
|
|
399
|
-
const field = colon === -1 ? line : line.slice(0, colon);
|
|
400
|
-
const value = colon === -1 ? "" : line.slice(colon + 1).replace(/^ /, "");
|
|
401
|
-
if (field === "event") event = value;
|
|
402
|
-
else if (field === "data") data.push(value);
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
} finally {
|
|
406
|
-
await reader.cancel().catch(() => {
|
|
407
|
-
});
|
|
403
|
+
return new URL(url).origin;
|
|
404
|
+
} catch {
|
|
405
|
+
return url;
|
|
408
406
|
}
|
|
409
407
|
}
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
408
|
+
var OriginRateGate = class {
|
|
409
|
+
states = /* @__PURE__ */ new Map();
|
|
410
|
+
maxConcurrent;
|
|
411
|
+
defaultCooldownMs;
|
|
412
|
+
maxCooldownMs;
|
|
413
|
+
jitterMs;
|
|
414
|
+
constructor(options) {
|
|
415
|
+
assertNonNegativeMs("defaultCooldownMs", options?.defaultCooldownMs);
|
|
416
|
+
assertNonNegativeMs("maxCooldownMs", options?.maxCooldownMs);
|
|
417
|
+
assertNonNegativeMs("jitterMs", options?.jitterMs);
|
|
418
|
+
this.maxConcurrent = options?.maxConcurrent ?? DEFAULT_MAX_CONCURRENT;
|
|
419
|
+
this.defaultCooldownMs = options?.defaultCooldownMs ?? DEFAULT_COOLDOWN_MS;
|
|
420
|
+
this.maxCooldownMs = options?.maxCooldownMs ?? MAX_COOLDOWN_MS;
|
|
421
|
+
this.jitterMs = options?.jitterMs ?? DEFAULT_JITTER_MS;
|
|
417
422
|
}
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
423
|
+
/**
|
|
424
|
+
* Run `fn` under the origin's concurrency cap and behind any active
|
|
425
|
+
* cooldown. Put only the request in `fn`: the slot is released as soon as
|
|
426
|
+
* it settles, so body parsing doesn't hold one.
|
|
427
|
+
*/
|
|
428
|
+
async run(input, fn) {
|
|
429
|
+
const state = this.stateFor(requestOrigin(input));
|
|
430
|
+
await this.acquire(state);
|
|
431
|
+
try {
|
|
432
|
+
for (; ; ) {
|
|
433
|
+
const remaining = state.blockedUntil - Date.now();
|
|
434
|
+
if (remaining <= 0) break;
|
|
435
|
+
await sleep(remaining + Math.random() * this.jitterMs);
|
|
436
|
+
}
|
|
437
|
+
return await fn();
|
|
438
|
+
} finally {
|
|
439
|
+
this.release(state);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* {@link run} for a request whose response the gate should inspect: a `429`
|
|
444
|
+
* is recorded *before* the slot is released. Reporting after `run()` resolves
|
|
445
|
+
* is too late — `release()` hands the slot to the next queued waiter, which
|
|
446
|
+
* resumes, sees no cooldown, and sends into the limiter that just refused us.
|
|
447
|
+
*
|
|
448
|
+
* Prefer this over `run` for anything returning a `Response`.
|
|
449
|
+
*/
|
|
450
|
+
runHttp(input, fn) {
|
|
451
|
+
return this.run(input, async () => {
|
|
452
|
+
const response = await fn();
|
|
453
|
+
if (response.status === 429) {
|
|
454
|
+
this.reportRateLimited(input, response.headers?.get("retry-after"));
|
|
455
|
+
}
|
|
456
|
+
return response;
|
|
440
457
|
});
|
|
441
458
|
}
|
|
442
|
-
|
|
443
|
-
|
|
459
|
+
/**
|
|
460
|
+
* Record an observed `429`, pausing every gated request to that origin.
|
|
461
|
+
* Monotonic: a shorter cooldown never shortens one already in effect.
|
|
462
|
+
*/
|
|
463
|
+
reportRateLimited(input, retryAfterHeader) {
|
|
464
|
+
const cooldown = Math.min(
|
|
465
|
+
parseRetryAfterMs(retryAfterHeader) ?? this.defaultCooldownMs,
|
|
466
|
+
this.maxCooldownMs
|
|
467
|
+
);
|
|
468
|
+
const state = this.stateFor(requestOrigin(input));
|
|
469
|
+
state.blockedUntil = Math.max(state.blockedUntil, Date.now() + cooldown);
|
|
444
470
|
}
|
|
445
|
-
|
|
446
|
-
|
|
471
|
+
/** Milliseconds left on `input` origin's cooldown; `0` when not cooling down. */
|
|
472
|
+
cooldownRemainingMs(input) {
|
|
473
|
+
const state = this.states.get(requestOrigin(input));
|
|
474
|
+
if (!state) return 0;
|
|
475
|
+
return Math.max(0, state.blockedUntil - Date.now());
|
|
447
476
|
}
|
|
448
|
-
|
|
449
|
-
|
|
477
|
+
/**
|
|
478
|
+
* Drop all per-origin state, so test suites don't inherit each other's
|
|
479
|
+
* cooldowns. Waiters queued on the discarded state still drain normally.
|
|
480
|
+
*/
|
|
481
|
+
reset() {
|
|
482
|
+
this.states.clear();
|
|
450
483
|
}
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
const type = response.headers.get("Content-Type") ?? "";
|
|
457
|
-
if (response.status !== 200 || !response.body || !/^text\/event-stream\s*(;|$)/i.test(type)) {
|
|
458
|
-
await response.body?.cancel();
|
|
459
|
-
throw new Error(`SSE response ${response.status} ${type}`);
|
|
484
|
+
stateFor(origin) {
|
|
485
|
+
let state = this.states.get(origin);
|
|
486
|
+
if (!state) {
|
|
487
|
+
state = { blockedUntil: 0, active: 0, queue: [] };
|
|
488
|
+
this.states.set(origin, state);
|
|
460
489
|
}
|
|
461
|
-
|
|
462
|
-
|
|
490
|
+
return state;
|
|
491
|
+
}
|
|
492
|
+
acquire(state) {
|
|
493
|
+
if (state.active < this.maxConcurrent) {
|
|
494
|
+
state.active += 1;
|
|
495
|
+
return Promise.resolve();
|
|
463
496
|
}
|
|
464
|
-
|
|
497
|
+
return new Promise((resolve) => {
|
|
498
|
+
state.queue.push(() => {
|
|
499
|
+
state.active += 1;
|
|
500
|
+
resolve();
|
|
501
|
+
});
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
release(state) {
|
|
505
|
+
state.active -= 1;
|
|
506
|
+
const next = state.queue.shift();
|
|
507
|
+
if (next) next();
|
|
465
508
|
}
|
|
466
509
|
};
|
|
510
|
+
var rateGate = new OriginRateGate();
|
|
467
511
|
|
|
468
512
|
// src/providers/errors.ts
|
|
469
513
|
var ArkError = class extends Error {
|
|
@@ -505,6 +549,28 @@ var ProviderUnavailableError = class extends Error {
|
|
|
505
549
|
this.name = "ProviderUnavailableError";
|
|
506
550
|
}
|
|
507
551
|
};
|
|
552
|
+
var HttpResponseError = class extends Error {
|
|
553
|
+
status;
|
|
554
|
+
retryAfterMs;
|
|
555
|
+
/** @param detail - Replaces `statusText`, for a route that reads the body instead. */
|
|
556
|
+
constructor(prefix, response, detail) {
|
|
557
|
+
const status = response.status;
|
|
558
|
+
const described = [
|
|
559
|
+
(detail ?? response.statusText)?.trim(),
|
|
560
|
+
typeof status === "number" && `(${status})`
|
|
561
|
+
].filter(Boolean).join(" ");
|
|
562
|
+
super(described ? `${prefix}: ${described}` : prefix);
|
|
563
|
+
this.name = "HttpResponseError";
|
|
564
|
+
this.status = status;
|
|
565
|
+
this.retryAfterMs = parseRetryAfterMs(response.headers?.get("retry-after"));
|
|
566
|
+
}
|
|
567
|
+
};
|
|
568
|
+
function retryAfterMsFromError(error) {
|
|
569
|
+
if (!(error instanceof Error)) return void 0;
|
|
570
|
+
const { status, retryAfterMs } = error;
|
|
571
|
+
if (status !== 429 && status !== 503) return void 0;
|
|
572
|
+
return typeof retryAfterMs === "number" && retryAfterMs > 0 ? retryAfterMs : void 0;
|
|
573
|
+
}
|
|
508
574
|
var ServerResponseMismatchError = class extends Error {
|
|
509
575
|
retryable = false;
|
|
510
576
|
constructor(message, options) {
|
|
@@ -560,6 +626,112 @@ function maybeArkError(error) {
|
|
|
560
626
|
function isMetadata(value) {
|
|
561
627
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
562
628
|
}
|
|
629
|
+
|
|
630
|
+
// src/providers/sseFrames.ts
|
|
631
|
+
async function* readSseFrames(body) {
|
|
632
|
+
const reader = body.getReader();
|
|
633
|
+
const decoder = new TextDecoder();
|
|
634
|
+
let buffer = "";
|
|
635
|
+
let pendingCR = false;
|
|
636
|
+
let event = "";
|
|
637
|
+
let data = [];
|
|
638
|
+
try {
|
|
639
|
+
for (; ; ) {
|
|
640
|
+
const { done, value: chunk } = await reader.read();
|
|
641
|
+
if (done) return;
|
|
642
|
+
const text = decoder.decode(chunk, { stream: true });
|
|
643
|
+
if (!text) continue;
|
|
644
|
+
const skipLF = pendingCR && text.startsWith("\n");
|
|
645
|
+
pendingCR = text.endsWith("\r");
|
|
646
|
+
buffer += (skipLF ? text.slice(1) : text).replace(/\r\n?/g, "\n");
|
|
647
|
+
const lines = buffer.split("\n");
|
|
648
|
+
buffer = lines.pop() ?? "";
|
|
649
|
+
for (const line of lines) {
|
|
650
|
+
if (line === "") {
|
|
651
|
+
const joined = data.join("\n");
|
|
652
|
+
if (joined) yield { event: event || "message", data: joined };
|
|
653
|
+
event = "";
|
|
654
|
+
data = [];
|
|
655
|
+
continue;
|
|
656
|
+
}
|
|
657
|
+
const colon = line.indexOf(":");
|
|
658
|
+
const field = colon === -1 ? line : line.slice(0, colon);
|
|
659
|
+
const value = colon === -1 ? "" : line.slice(colon + 1).replace(/^ /, "");
|
|
660
|
+
if (field === "event") event = value;
|
|
661
|
+
else if (field === "data") data.push(value);
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
} finally {
|
|
665
|
+
await reader.cancel().catch(() => {
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
// src/providers/eventSource.ts
|
|
671
|
+
var GUIDANCE = "Pass one with configureEventSource(url => new EventSource(url)) \u2014 in Node, from the `eventsource` package or by running with --experimental-eventsource. In React Native, use ExpoOperatorProvider / ExpoIndexerProvider instead.";
|
|
672
|
+
var EventSourceUnavailableError = class extends Error {
|
|
673
|
+
constructor() {
|
|
674
|
+
super(`no EventSource is available, so server-sent events cannot be opened. ${GUIDANCE}`);
|
|
675
|
+
this.name = "EventSourceUnavailableError";
|
|
676
|
+
}
|
|
677
|
+
};
|
|
678
|
+
function isEventSourceUnavailableError(error) {
|
|
679
|
+
return error instanceof EventSourceUnavailableError || error instanceof Error && error.name === "EventSourceUnavailableError";
|
|
680
|
+
}
|
|
681
|
+
var configured;
|
|
682
|
+
function configureEventSource(factory) {
|
|
683
|
+
configured = factory;
|
|
684
|
+
}
|
|
685
|
+
function getConfiguredEventSource() {
|
|
686
|
+
return configured;
|
|
687
|
+
}
|
|
688
|
+
function resolveEventSource(override) {
|
|
689
|
+
const factory = override ?? configured ?? (typeof globalThis.fetch === "function" && typeof ReadableStream !== "undefined" ? (url, headers) => new FetchEventSource(url, headers) : void 0) ?? (typeof EventSource === "undefined" ? void 0 : (url) => new EventSource(url));
|
|
690
|
+
if (!factory) throw new EventSourceUnavailableError();
|
|
691
|
+
return factory;
|
|
692
|
+
}
|
|
693
|
+
function errorEvent(error) {
|
|
694
|
+
const event = new Event("error");
|
|
695
|
+
if (error instanceof HttpResponseError) {
|
|
696
|
+
event.status = error.status;
|
|
697
|
+
event.retryAfterMs = error.retryAfterMs;
|
|
698
|
+
}
|
|
699
|
+
return event;
|
|
700
|
+
}
|
|
701
|
+
var FetchEventSource = class {
|
|
702
|
+
events = new EventTarget();
|
|
703
|
+
controller = new AbortController();
|
|
704
|
+
constructor(url, headers = {}) {
|
|
705
|
+
this.read(url, headers).catch((error) => {
|
|
706
|
+
if (!this.controller.signal.aborted) this.events.dispatchEvent(errorEvent(error));
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
addEventListener(type, listener) {
|
|
710
|
+
this.events.addEventListener(type, listener);
|
|
711
|
+
}
|
|
712
|
+
removeEventListener(type, listener) {
|
|
713
|
+
this.events.removeEventListener(type, listener);
|
|
714
|
+
}
|
|
715
|
+
close() {
|
|
716
|
+
this.controller.abort();
|
|
717
|
+
}
|
|
718
|
+
async read(url, headers) {
|
|
719
|
+
const response = await baseFetch(url, {
|
|
720
|
+
headers: { Accept: "text/event-stream", ...headers },
|
|
721
|
+
signal: this.controller.signal
|
|
722
|
+
});
|
|
723
|
+
const type = response.headers.get("Content-Type") ?? "";
|
|
724
|
+
if (response.status !== 200 || !response.body || !/^text\/event-stream\s*(;|$)/i.test(type)) {
|
|
725
|
+
await response.body?.cancel().catch(() => {
|
|
726
|
+
});
|
|
727
|
+
throw new HttpResponseError("SSE response", response, type);
|
|
728
|
+
}
|
|
729
|
+
for await (const { event, data } of readSseFrames(response.body)) {
|
|
730
|
+
this.events.dispatchEvent(new MessageEvent(event, { data }));
|
|
731
|
+
}
|
|
732
|
+
throw new Error("SSE stream ended");
|
|
733
|
+
}
|
|
734
|
+
};
|
|
563
735
|
exports.Proof = void 0;
|
|
564
736
|
((Proof2) => {
|
|
565
737
|
function create(message, ins, outputs = []) {
|
|
@@ -792,7 +964,7 @@ function eventSourceIterator(eventSource) {
|
|
|
792
964
|
errorQueue.push(error);
|
|
793
965
|
}
|
|
794
966
|
};
|
|
795
|
-
const errorHandler = () => rejectWith(eventSourceError("EventSource error"));
|
|
967
|
+
const errorHandler = (event) => rejectWith(eventSourceError("EventSource error", event));
|
|
796
968
|
const failureHandler = (event) => rejectWith(streamFailureError(event.data));
|
|
797
969
|
eventSource.addEventListener("message", messageHandler);
|
|
798
970
|
eventSource.addEventListener("error", errorHandler);
|
|
@@ -834,9 +1006,14 @@ function eventSourceIterator(eventSource) {
|
|
|
834
1006
|
};
|
|
835
1007
|
return managed;
|
|
836
1008
|
}
|
|
837
|
-
function eventSourceError(message) {
|
|
838
|
-
const
|
|
1009
|
+
function eventSourceError(message, refusal) {
|
|
1010
|
+
const { status, retryAfterMs } = refusal ?? {};
|
|
1011
|
+
const error = new Error(status ? `${message} (${status})` : message);
|
|
839
1012
|
error.name = "EventSourceError";
|
|
1013
|
+
if (status !== void 0) {
|
|
1014
|
+
error.status = status;
|
|
1015
|
+
error.retryAfterMs = retryAfterMs;
|
|
1016
|
+
}
|
|
840
1017
|
return error;
|
|
841
1018
|
}
|
|
842
1019
|
function streamFailureError(data) {
|
|
@@ -852,141 +1029,6 @@ function isEventSourceError(error) {
|
|
|
852
1029
|
return error instanceof Error && error.name === "EventSourceError";
|
|
853
1030
|
}
|
|
854
1031
|
|
|
855
|
-
// src/providers/rateGate.ts
|
|
856
|
-
var DEFAULT_MAX_CONCURRENT = 6;
|
|
857
|
-
var DEFAULT_COOLDOWN_MS = 5e3;
|
|
858
|
-
var MAX_COOLDOWN_MS = 6e4;
|
|
859
|
-
var DEFAULT_JITTER_MS = 500;
|
|
860
|
-
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, Math.min(ms, MAX_TIMER_MS)));
|
|
861
|
-
function parseRetryAfterMs(header) {
|
|
862
|
-
if (header === null || header === void 0) return void 0;
|
|
863
|
-
const trimmed = header.trim();
|
|
864
|
-
if (trimmed === "") return void 0;
|
|
865
|
-
const seconds = Number(trimmed);
|
|
866
|
-
if (Number.isFinite(seconds)) return seconds < 0 ? void 0 : seconds * 1e3;
|
|
867
|
-
const at = Date.parse(trimmed);
|
|
868
|
-
if (!Number.isNaN(at)) return Math.max(0, at - Date.now());
|
|
869
|
-
return void 0;
|
|
870
|
-
}
|
|
871
|
-
function requestOrigin(input) {
|
|
872
|
-
let url;
|
|
873
|
-
if (typeof input === "string") {
|
|
874
|
-
url = input;
|
|
875
|
-
} else if (input instanceof URL) {
|
|
876
|
-
url = input.href;
|
|
877
|
-
} else {
|
|
878
|
-
url = input.url;
|
|
879
|
-
}
|
|
880
|
-
try {
|
|
881
|
-
return new URL(url).origin;
|
|
882
|
-
} catch {
|
|
883
|
-
return url;
|
|
884
|
-
}
|
|
885
|
-
}
|
|
886
|
-
var OriginRateGate = class {
|
|
887
|
-
states = /* @__PURE__ */ new Map();
|
|
888
|
-
maxConcurrent;
|
|
889
|
-
defaultCooldownMs;
|
|
890
|
-
maxCooldownMs;
|
|
891
|
-
jitterMs;
|
|
892
|
-
constructor(options) {
|
|
893
|
-
assertNonNegativeMs("defaultCooldownMs", options?.defaultCooldownMs);
|
|
894
|
-
assertNonNegativeMs("maxCooldownMs", options?.maxCooldownMs);
|
|
895
|
-
assertNonNegativeMs("jitterMs", options?.jitterMs);
|
|
896
|
-
this.maxConcurrent = options?.maxConcurrent ?? DEFAULT_MAX_CONCURRENT;
|
|
897
|
-
this.defaultCooldownMs = options?.defaultCooldownMs ?? DEFAULT_COOLDOWN_MS;
|
|
898
|
-
this.maxCooldownMs = options?.maxCooldownMs ?? MAX_COOLDOWN_MS;
|
|
899
|
-
this.jitterMs = options?.jitterMs ?? DEFAULT_JITTER_MS;
|
|
900
|
-
}
|
|
901
|
-
/**
|
|
902
|
-
* Run `fn` under the origin's concurrency cap and behind any active
|
|
903
|
-
* cooldown. Put only the request in `fn`: the slot is released as soon as
|
|
904
|
-
* it settles, so body parsing doesn't hold one.
|
|
905
|
-
*/
|
|
906
|
-
async run(input, fn) {
|
|
907
|
-
const state = this.stateFor(requestOrigin(input));
|
|
908
|
-
await this.acquire(state);
|
|
909
|
-
try {
|
|
910
|
-
for (; ; ) {
|
|
911
|
-
const remaining = state.blockedUntil - Date.now();
|
|
912
|
-
if (remaining <= 0) break;
|
|
913
|
-
await sleep(remaining + Math.random() * this.jitterMs);
|
|
914
|
-
}
|
|
915
|
-
return await fn();
|
|
916
|
-
} finally {
|
|
917
|
-
this.release(state);
|
|
918
|
-
}
|
|
919
|
-
}
|
|
920
|
-
/**
|
|
921
|
-
* {@link run} for a request whose response the gate should inspect: a `429`
|
|
922
|
-
* is recorded *before* the slot is released. Reporting after `run()` resolves
|
|
923
|
-
* is too late — `release()` hands the slot to the next queued waiter, which
|
|
924
|
-
* resumes, sees no cooldown, and sends into the limiter that just refused us.
|
|
925
|
-
*
|
|
926
|
-
* Prefer this over `run` for anything returning a `Response`.
|
|
927
|
-
*/
|
|
928
|
-
runHttp(input, fn) {
|
|
929
|
-
return this.run(input, async () => {
|
|
930
|
-
const response = await fn();
|
|
931
|
-
if (response.status === 429) {
|
|
932
|
-
this.reportRateLimited(input, response.headers?.get("retry-after"));
|
|
933
|
-
}
|
|
934
|
-
return response;
|
|
935
|
-
});
|
|
936
|
-
}
|
|
937
|
-
/**
|
|
938
|
-
* Record an observed `429`, pausing every gated request to that origin.
|
|
939
|
-
* Monotonic: a shorter cooldown never shortens one already in effect.
|
|
940
|
-
*/
|
|
941
|
-
reportRateLimited(input, retryAfterHeader) {
|
|
942
|
-
const cooldown = Math.min(
|
|
943
|
-
parseRetryAfterMs(retryAfterHeader) ?? this.defaultCooldownMs,
|
|
944
|
-
this.maxCooldownMs
|
|
945
|
-
);
|
|
946
|
-
const state = this.stateFor(requestOrigin(input));
|
|
947
|
-
state.blockedUntil = Math.max(state.blockedUntil, Date.now() + cooldown);
|
|
948
|
-
}
|
|
949
|
-
/** Milliseconds left on `input` origin's cooldown; `0` when not cooling down. */
|
|
950
|
-
cooldownRemainingMs(input) {
|
|
951
|
-
const state = this.states.get(requestOrigin(input));
|
|
952
|
-
if (!state) return 0;
|
|
953
|
-
return Math.max(0, state.blockedUntil - Date.now());
|
|
954
|
-
}
|
|
955
|
-
/**
|
|
956
|
-
* Drop all per-origin state, so test suites don't inherit each other's
|
|
957
|
-
* cooldowns. Waiters queued on the discarded state still drain normally.
|
|
958
|
-
*/
|
|
959
|
-
reset() {
|
|
960
|
-
this.states.clear();
|
|
961
|
-
}
|
|
962
|
-
stateFor(origin) {
|
|
963
|
-
let state = this.states.get(origin);
|
|
964
|
-
if (!state) {
|
|
965
|
-
state = { blockedUntil: 0, active: 0, queue: [] };
|
|
966
|
-
this.states.set(origin, state);
|
|
967
|
-
}
|
|
968
|
-
return state;
|
|
969
|
-
}
|
|
970
|
-
acquire(state) {
|
|
971
|
-
if (state.active < this.maxConcurrent) {
|
|
972
|
-
state.active += 1;
|
|
973
|
-
return Promise.resolve();
|
|
974
|
-
}
|
|
975
|
-
return new Promise((resolve) => {
|
|
976
|
-
state.queue.push(() => {
|
|
977
|
-
state.active += 1;
|
|
978
|
-
resolve();
|
|
979
|
-
});
|
|
980
|
-
});
|
|
981
|
-
}
|
|
982
|
-
release(state) {
|
|
983
|
-
state.active -= 1;
|
|
984
|
-
const next = state.queue.shift();
|
|
985
|
-
if (next) next();
|
|
986
|
-
}
|
|
987
|
-
};
|
|
988
|
-
var rateGate = new OriginRateGate();
|
|
989
|
-
|
|
990
1032
|
// src/providers/ark.ts
|
|
991
1033
|
var DigestMismatchError = class extends Error {
|
|
992
1034
|
constructor(message) {
|
|
@@ -1848,8 +1890,10 @@ exports.DigestMismatchError = DigestMismatchError;
|
|
|
1848
1890
|
exports.EXPIRY_MIN_PLAUSIBLE_MS = EXPIRY_MIN_PLAUSIBLE_MS;
|
|
1849
1891
|
exports.EventSourceUnavailableError = EventSourceUnavailableError;
|
|
1850
1892
|
exports.FetchError = FetchError;
|
|
1893
|
+
exports.HttpResponseError = HttpResponseError;
|
|
1851
1894
|
exports.INFO_FETCH_TIMEOUT_MS = INFO_FETCH_TIMEOUT_MS;
|
|
1852
1895
|
exports.Intent = Intent;
|
|
1896
|
+
exports.MAX_COOLDOWN_MS = MAX_COOLDOWN_MS;
|
|
1853
1897
|
exports.ONCHAIN_COSIGN_AMBIGUOUS_PREFIX = ONCHAIN_COSIGN_AMBIGUOUS_PREFIX;
|
|
1854
1898
|
exports.ONCHAIN_COSIGN_REJECTED_PREFIX = ONCHAIN_COSIGN_REJECTED_PREFIX;
|
|
1855
1899
|
exports.ONCHAIN_COSIGN_UNSUPPORTED_PREFIX = ONCHAIN_COSIGN_UNSUPPORTED_PREFIX;
|
|
@@ -1903,11 +1947,13 @@ exports.readSseFrames = readSseFrames;
|
|
|
1903
1947
|
exports.requiresForfeit = requiresForfeit;
|
|
1904
1948
|
exports.resolveEventSource = resolveEventSource;
|
|
1905
1949
|
exports.resolveTimeHeight = resolveTimeHeight;
|
|
1950
|
+
exports.retryAfterMsFromError = retryAfterMsFromError;
|
|
1906
1951
|
exports.sdkVersion = sdkVersion;
|
|
1952
|
+
exports.sdkVersionHeaders = sdkVersionHeaders;
|
|
1907
1953
|
exports.setArkPsbtField = setArkPsbtField;
|
|
1908
1954
|
exports.streamFailureError = streamFailureError;
|
|
1909
1955
|
exports.throwIfHttpUnavailable = throwIfHttpUnavailable;
|
|
1910
1956
|
exports.toOffchainInputFeeParams = toOffchainInputFeeParams;
|
|
1911
1957
|
exports.toProviderUnavailable = toProviderUnavailable;
|
|
1912
|
-
//# sourceMappingURL=chunk-
|
|
1913
|
-
//# sourceMappingURL=chunk-
|
|
1958
|
+
//# sourceMappingURL=chunk-SOJDUKY6.cjs.map
|
|
1959
|
+
//# sourceMappingURL=chunk-SOJDUKY6.cjs.map
|