@zeroxyz/cli 1.27.1 → 1.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1333 -362
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -9486,12 +9486,12 @@ var init_getCallError = __esm({
|
|
|
9486
9486
|
// ../../node_modules/.pnpm/viem@2.52.2_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@6.0.6_zod@4.3.6/node_modules/viem/_esm/utils/promise/withResolvers.js
|
|
9487
9487
|
function withResolvers() {
|
|
9488
9488
|
let resolve7 = () => void 0;
|
|
9489
|
-
let
|
|
9489
|
+
let reject2 = () => void 0;
|
|
9490
9490
|
const promise3 = new Promise((resolve_, reject_) => {
|
|
9491
9491
|
resolve7 = resolve_;
|
|
9492
|
-
|
|
9492
|
+
reject2 = reject_;
|
|
9493
9493
|
});
|
|
9494
|
-
return { promise: promise3, resolve: resolve7, reject };
|
|
9494
|
+
return { promise: promise3, resolve: resolve7, reject: reject2 };
|
|
9495
9495
|
}
|
|
9496
9496
|
var init_withResolvers = __esm({
|
|
9497
9497
|
"../../node_modules/.pnpm/viem@2.52.2_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@6.0.6_zod@4.3.6/node_modules/viem/_esm/utils/promise/withResolvers.js"() {
|
|
@@ -9516,8 +9516,8 @@ function createBatchScheduler({ fn, id, shouldSplitBatch, wait: wait3 = 0, sort
|
|
|
9516
9516
|
}
|
|
9517
9517
|
}).catch((err) => {
|
|
9518
9518
|
for (let i = 0; i < scheduler.length; i++) {
|
|
9519
|
-
const { reject } = scheduler[i];
|
|
9520
|
-
|
|
9519
|
+
const { reject: reject2 } = scheduler[i];
|
|
9520
|
+
reject2?.(err);
|
|
9521
9521
|
}
|
|
9522
9522
|
});
|
|
9523
9523
|
};
|
|
@@ -9528,16 +9528,16 @@ function createBatchScheduler({ fn, id, shouldSplitBatch, wait: wait3 = 0, sort
|
|
|
9528
9528
|
return {
|
|
9529
9529
|
flush,
|
|
9530
9530
|
async schedule(args) {
|
|
9531
|
-
const { promise: promise3, resolve: resolve7, reject } = withResolvers();
|
|
9531
|
+
const { promise: promise3, resolve: resolve7, reject: reject2 } = withResolvers();
|
|
9532
9532
|
const split3 = shouldSplitBatch?.([...getBatchedArgs(), args]);
|
|
9533
9533
|
if (split3)
|
|
9534
9534
|
exec();
|
|
9535
9535
|
const hasActiveScheduler = getScheduler().length > 0;
|
|
9536
9536
|
if (hasActiveScheduler) {
|
|
9537
|
-
setScheduler({ args, resolve: resolve7, reject });
|
|
9537
|
+
setScheduler({ args, resolve: resolve7, reject: reject2 });
|
|
9538
9538
|
return promise3;
|
|
9539
9539
|
}
|
|
9540
|
-
setScheduler({ args, resolve: resolve7, reject });
|
|
9540
|
+
setScheduler({ args, resolve: resolve7, reject: reject2 });
|
|
9541
9541
|
setTimeout(exec, wait3);
|
|
9542
9542
|
return promise3;
|
|
9543
9543
|
}
|
|
@@ -27585,12 +27585,12 @@ var init_getCallError2 = __esm({
|
|
|
27585
27585
|
// ../../node_modules/.pnpm/viem@2.52.2_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@6.0.6_zod@3.25.76/node_modules/viem/_esm/utils/promise/withResolvers.js
|
|
27586
27586
|
function withResolvers2() {
|
|
27587
27587
|
let resolve7 = () => void 0;
|
|
27588
|
-
let
|
|
27588
|
+
let reject2 = () => void 0;
|
|
27589
27589
|
const promise3 = new Promise((resolve_, reject_) => {
|
|
27590
27590
|
resolve7 = resolve_;
|
|
27591
|
-
|
|
27591
|
+
reject2 = reject_;
|
|
27592
27592
|
});
|
|
27593
|
-
return { promise: promise3, resolve: resolve7, reject };
|
|
27593
|
+
return { promise: promise3, resolve: resolve7, reject: reject2 };
|
|
27594
27594
|
}
|
|
27595
27595
|
var init_withResolvers2 = __esm({
|
|
27596
27596
|
"../../node_modules/.pnpm/viem@2.52.2_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@6.0.6_zod@3.25.76/node_modules/viem/_esm/utils/promise/withResolvers.js"() {
|
|
@@ -27615,8 +27615,8 @@ function createBatchScheduler2({ fn, id, shouldSplitBatch, wait: wait3 = 0, sort
|
|
|
27615
27615
|
}
|
|
27616
27616
|
}).catch((err) => {
|
|
27617
27617
|
for (let i = 0; i < scheduler.length; i++) {
|
|
27618
|
-
const { reject } = scheduler[i];
|
|
27619
|
-
|
|
27618
|
+
const { reject: reject2 } = scheduler[i];
|
|
27619
|
+
reject2?.(err);
|
|
27620
27620
|
}
|
|
27621
27621
|
});
|
|
27622
27622
|
};
|
|
@@ -27627,16 +27627,16 @@ function createBatchScheduler2({ fn, id, shouldSplitBatch, wait: wait3 = 0, sort
|
|
|
27627
27627
|
return {
|
|
27628
27628
|
flush,
|
|
27629
27629
|
async schedule(args) {
|
|
27630
|
-
const { promise: promise3, resolve: resolve7, reject } = withResolvers2();
|
|
27630
|
+
const { promise: promise3, resolve: resolve7, reject: reject2 } = withResolvers2();
|
|
27631
27631
|
const split3 = shouldSplitBatch?.([...getBatchedArgs(), args]);
|
|
27632
27632
|
if (split3)
|
|
27633
27633
|
exec();
|
|
27634
27634
|
const hasActiveScheduler = getScheduler().length > 0;
|
|
27635
27635
|
if (hasActiveScheduler) {
|
|
27636
|
-
setScheduler({ args, resolve: resolve7, reject });
|
|
27636
|
+
setScheduler({ args, resolve: resolve7, reject: reject2 });
|
|
27637
27637
|
return promise3;
|
|
27638
27638
|
}
|
|
27639
|
-
setScheduler({ args, resolve: resolve7, reject });
|
|
27639
|
+
setScheduler({ args, resolve: resolve7, reject: reject2 });
|
|
27640
27640
|
setTimeout(exec, wait3);
|
|
27641
27641
|
return promise3;
|
|
27642
27642
|
}
|
|
@@ -40848,19 +40848,19 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
40848
40848
|
resolve7(value);
|
|
40849
40849
|
});
|
|
40850
40850
|
}
|
|
40851
|
-
return new (P || (P = Promise))(function(resolve7,
|
|
40851
|
+
return new (P || (P = Promise))(function(resolve7, reject2) {
|
|
40852
40852
|
function fulfilled(value) {
|
|
40853
40853
|
try {
|
|
40854
40854
|
step(generator.next(value));
|
|
40855
40855
|
} catch (e) {
|
|
40856
|
-
|
|
40856
|
+
reject2(e);
|
|
40857
40857
|
}
|
|
40858
40858
|
}
|
|
40859
40859
|
function rejected(value) {
|
|
40860
40860
|
try {
|
|
40861
40861
|
step(generator["throw"](value));
|
|
40862
40862
|
} catch (e) {
|
|
40863
|
-
|
|
40863
|
+
reject2(e);
|
|
40864
40864
|
}
|
|
40865
40865
|
}
|
|
40866
40866
|
function step(result) {
|
|
@@ -41001,7 +41001,7 @@ function __asyncGenerator(thisArg, _arguments, generator) {
|
|
|
41001
41001
|
}, i;
|
|
41002
41002
|
function awaitReturn(f) {
|
|
41003
41003
|
return function(v) {
|
|
41004
|
-
return Promise.resolve(v).then(f,
|
|
41004
|
+
return Promise.resolve(v).then(f, reject2);
|
|
41005
41005
|
};
|
|
41006
41006
|
}
|
|
41007
41007
|
function verb(n, f) {
|
|
@@ -41022,12 +41022,12 @@ function __asyncGenerator(thisArg, _arguments, generator) {
|
|
|
41022
41022
|
}
|
|
41023
41023
|
}
|
|
41024
41024
|
function step(r) {
|
|
41025
|
-
r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill,
|
|
41025
|
+
r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject2) : settle3(q[0][2], r);
|
|
41026
41026
|
}
|
|
41027
41027
|
function fulfill(value) {
|
|
41028
41028
|
resume("next", value);
|
|
41029
41029
|
}
|
|
41030
|
-
function
|
|
41030
|
+
function reject2(value) {
|
|
41031
41031
|
resume("throw", value);
|
|
41032
41032
|
}
|
|
41033
41033
|
function settle3(f, v) {
|
|
@@ -41055,15 +41055,15 @@ function __asyncValues(o) {
|
|
|
41055
41055
|
}, i);
|
|
41056
41056
|
function verb(n) {
|
|
41057
41057
|
i[n] = o[n] && function(v) {
|
|
41058
|
-
return new Promise(function(resolve7,
|
|
41059
|
-
v = o[n](v), settle3(resolve7,
|
|
41058
|
+
return new Promise(function(resolve7, reject2) {
|
|
41059
|
+
v = o[n](v), settle3(resolve7, reject2, v.done, v.value);
|
|
41060
41060
|
});
|
|
41061
41061
|
};
|
|
41062
41062
|
}
|
|
41063
|
-
function settle3(resolve7,
|
|
41063
|
+
function settle3(resolve7, reject2, d, v) {
|
|
41064
41064
|
Promise.resolve(v).then(function(v2) {
|
|
41065
41065
|
resolve7({ value: v2, done: d });
|
|
41066
|
-
},
|
|
41066
|
+
}, reject2);
|
|
41067
41067
|
}
|
|
41068
41068
|
}
|
|
41069
41069
|
function __makeTemplateObject(cooked, raw) {
|
|
@@ -42094,17 +42094,17 @@ var require_geturl = __commonJS({
|
|
|
42094
42094
|
request3.write(Buffer.from(body));
|
|
42095
42095
|
}
|
|
42096
42096
|
request3.end();
|
|
42097
|
-
return new Promise((resolve7,
|
|
42097
|
+
return new Promise((resolve7, reject2) => {
|
|
42098
42098
|
if (signal) {
|
|
42099
42099
|
signal.addListener(() => {
|
|
42100
42100
|
if (abort) {
|
|
42101
42101
|
abort.abort();
|
|
42102
42102
|
}
|
|
42103
|
-
|
|
42103
|
+
reject2((0, errors_js_1.makeError)("request cancelled", "CANCELLED"));
|
|
42104
42104
|
});
|
|
42105
42105
|
}
|
|
42106
42106
|
request3.on("timeout", () => {
|
|
42107
|
-
|
|
42107
|
+
reject2((0, errors_js_1.makeError)("request timeout", "TIMEOUT"));
|
|
42108
42108
|
});
|
|
42109
42109
|
request3.once("response", (resp) => {
|
|
42110
42110
|
const statusCode = resp.statusCode || 0;
|
|
@@ -42123,7 +42123,7 @@ var require_geturl = __commonJS({
|
|
|
42123
42123
|
try {
|
|
42124
42124
|
signal.checkSignal();
|
|
42125
42125
|
} catch (error98) {
|
|
42126
|
-
return
|
|
42126
|
+
return reject2(error98);
|
|
42127
42127
|
}
|
|
42128
42128
|
}
|
|
42129
42129
|
if (body2 == null) {
|
|
@@ -42142,7 +42142,7 @@ var require_geturl = __commonJS({
|
|
|
42142
42142
|
}
|
|
42143
42143
|
resolve7({ statusCode, statusMessage, headers: headers2, body: body2 });
|
|
42144
42144
|
} catch (error98) {
|
|
42145
|
-
|
|
42145
|
+
reject2((0, errors_js_1.makeError)("bad response data", "SERVER_ERROR", {
|
|
42146
42146
|
request: req,
|
|
42147
42147
|
info: { response: resp, error: error98 }
|
|
42148
42148
|
}));
|
|
@@ -42150,11 +42150,11 @@ var require_geturl = __commonJS({
|
|
|
42150
42150
|
});
|
|
42151
42151
|
resp.on("error", (error98) => {
|
|
42152
42152
|
error98.response = { statusCode, statusMessage, headers: headers2, body: body2 };
|
|
42153
|
-
|
|
42153
|
+
reject2(error98);
|
|
42154
42154
|
});
|
|
42155
42155
|
});
|
|
42156
42156
|
request3.on("error", (error98) => {
|
|
42157
|
-
|
|
42157
|
+
reject2(error98);
|
|
42158
42158
|
});
|
|
42159
42159
|
});
|
|
42160
42160
|
}
|
|
@@ -56762,7 +56762,7 @@ var require_provider = __commonJS({
|
|
|
56762
56762
|
return null;
|
|
56763
56763
|
}
|
|
56764
56764
|
}
|
|
56765
|
-
const waiter = new Promise((resolve7,
|
|
56765
|
+
const waiter = new Promise((resolve7, reject2) => {
|
|
56766
56766
|
const cancellers = [];
|
|
56767
56767
|
const cancel2 = () => {
|
|
56768
56768
|
cancellers.forEach((c) => c());
|
|
@@ -56773,7 +56773,7 @@ var require_provider = __commonJS({
|
|
|
56773
56773
|
if (timeout > 0) {
|
|
56774
56774
|
const timer = setTimeout(() => {
|
|
56775
56775
|
cancel2();
|
|
56776
|
-
|
|
56776
|
+
reject2((0, index_js_1.makeError)("wait for transaction timeout", "TIMEOUT"));
|
|
56777
56777
|
}, timeout);
|
|
56778
56778
|
cancellers.push(() => {
|
|
56779
56779
|
clearTimeout(timer);
|
|
@@ -56785,7 +56785,7 @@ var require_provider = __commonJS({
|
|
|
56785
56785
|
try {
|
|
56786
56786
|
resolve7(checkReceipt(receipt2));
|
|
56787
56787
|
} catch (error98) {
|
|
56788
|
-
|
|
56788
|
+
reject2(error98);
|
|
56789
56789
|
}
|
|
56790
56790
|
}
|
|
56791
56791
|
};
|
|
@@ -56800,7 +56800,7 @@ var require_provider = __commonJS({
|
|
|
56800
56800
|
} catch (error98) {
|
|
56801
56801
|
if ((0, index_js_1.isError)(error98, "TRANSACTION_REPLACED")) {
|
|
56802
56802
|
cancel2();
|
|
56803
|
-
|
|
56803
|
+
reject2(error98);
|
|
56804
56804
|
return;
|
|
56805
56805
|
}
|
|
56806
56806
|
}
|
|
@@ -57732,7 +57732,7 @@ var require_contract = __commonJS({
|
|
|
57732
57732
|
}
|
|
57733
57733
|
const provider = getProvider(this.runner);
|
|
57734
57734
|
(0, index_js_3.assert)(provider != null, "contract runner does not support .provider", "UNSUPPORTED_OPERATION", { operation: "waitForDeployment" });
|
|
57735
|
-
return new Promise((resolve7,
|
|
57735
|
+
return new Promise((resolve7, reject2) => {
|
|
57736
57736
|
const checkCode = async () => {
|
|
57737
57737
|
try {
|
|
57738
57738
|
const code2 = await this.getDeployedCode();
|
|
@@ -57741,7 +57741,7 @@ var require_contract = __commonJS({
|
|
|
57741
57741
|
}
|
|
57742
57742
|
provider.once("block", checkCode);
|
|
57743
57743
|
} catch (error98) {
|
|
57744
|
-
|
|
57744
|
+
reject2(error98);
|
|
57745
57745
|
}
|
|
57746
57746
|
};
|
|
57747
57747
|
checkCode();
|
|
@@ -60484,7 +60484,7 @@ var require_abstract_provider = __commonJS({
|
|
|
60484
60484
|
if (confirms === 0) {
|
|
60485
60485
|
return this.getTransactionReceipt(hash13);
|
|
60486
60486
|
}
|
|
60487
|
-
return new Promise(async (resolve7,
|
|
60487
|
+
return new Promise(async (resolve7, reject2) => {
|
|
60488
60488
|
let timer = null;
|
|
60489
60489
|
const listener = (async (blockNumber) => {
|
|
60490
60490
|
try {
|
|
@@ -60511,7 +60511,7 @@ var require_abstract_provider = __commonJS({
|
|
|
60511
60511
|
}
|
|
60512
60512
|
timer = null;
|
|
60513
60513
|
this.off("block", listener);
|
|
60514
|
-
|
|
60514
|
+
reject2((0, index_js_6.makeError)("timeout", "TIMEOUT", { reason: "timeout" }));
|
|
60515
60515
|
}, timeout);
|
|
60516
60516
|
}
|
|
60517
60517
|
listener(await this.getBlockNumber());
|
|
@@ -61476,7 +61476,7 @@ var require_provider_jsonrpc = __commonJS({
|
|
|
61476
61476
|
async sendTransaction(tx) {
|
|
61477
61477
|
const blockNumber = await this.provider.getBlockNumber();
|
|
61478
61478
|
const hash13 = await this.sendUncheckedTransaction(tx);
|
|
61479
|
-
return await new Promise((resolve7,
|
|
61479
|
+
return await new Promise((resolve7, reject2) => {
|
|
61480
61480
|
const timeouts = [1e3, 100];
|
|
61481
61481
|
let invalids = 0;
|
|
61482
61482
|
const checkTx = async () => {
|
|
@@ -61492,7 +61492,7 @@ var require_provider_jsonrpc = __commonJS({
|
|
|
61492
61492
|
error98.info = {};
|
|
61493
61493
|
}
|
|
61494
61494
|
error98.info.sendTransactionHash = hash13;
|
|
61495
|
-
|
|
61495
|
+
reject2(error98);
|
|
61496
61496
|
return;
|
|
61497
61497
|
}
|
|
61498
61498
|
if ((0, index_js_5.isError)(error98, "INVALID_ARGUMENT")) {
|
|
@@ -61502,7 +61502,7 @@ var require_provider_jsonrpc = __commonJS({
|
|
|
61502
61502
|
}
|
|
61503
61503
|
error98.info.sendTransactionHash = hash13;
|
|
61504
61504
|
if (invalids > 10) {
|
|
61505
|
-
|
|
61505
|
+
reject2(error98);
|
|
61506
61506
|
return;
|
|
61507
61507
|
}
|
|
61508
61508
|
}
|
|
@@ -61601,9 +61601,9 @@ var require_provider_jsonrpc = __commonJS({
|
|
|
61601
61601
|
try {
|
|
61602
61602
|
const result = await this._send(payload);
|
|
61603
61603
|
this.emit("debug", { action: "receiveRpcResult", result });
|
|
61604
|
-
for (const { resolve: resolve7, reject, payload: payload2 } of batch) {
|
|
61604
|
+
for (const { resolve: resolve7, reject: reject2, payload: payload2 } of batch) {
|
|
61605
61605
|
if (this.destroyed) {
|
|
61606
|
-
|
|
61606
|
+
reject2((0, index_js_5.makeError)("provider destroyed; cancelled request", "UNSUPPORTED_OPERATION", { operation: payload2.method }));
|
|
61607
61607
|
continue;
|
|
61608
61608
|
}
|
|
61609
61609
|
const resp = result.filter((r) => r.id === payload2.id)[0];
|
|
@@ -61613,19 +61613,19 @@ var require_provider_jsonrpc = __commonJS({
|
|
|
61613
61613
|
info: { payload: payload2 }
|
|
61614
61614
|
});
|
|
61615
61615
|
this.emit("error", error98);
|
|
61616
|
-
|
|
61616
|
+
reject2(error98);
|
|
61617
61617
|
continue;
|
|
61618
61618
|
}
|
|
61619
61619
|
if ("error" in resp) {
|
|
61620
|
-
|
|
61620
|
+
reject2(this.getRpcError(payload2, resp));
|
|
61621
61621
|
continue;
|
|
61622
61622
|
}
|
|
61623
61623
|
resolve7(resp.result);
|
|
61624
61624
|
}
|
|
61625
61625
|
} catch (error98) {
|
|
61626
61626
|
this.emit("debug", { action: "receiveRpcError", error: error98 });
|
|
61627
|
-
for (const { reject } of batch) {
|
|
61628
|
-
|
|
61627
|
+
for (const { reject: reject2 } of batch) {
|
|
61628
|
+
reject2(error98);
|
|
61629
61629
|
}
|
|
61630
61630
|
}
|
|
61631
61631
|
})();
|
|
@@ -62058,10 +62058,10 @@ var require_provider_jsonrpc = __commonJS({
|
|
|
62058
62058
|
return Promise.reject((0, index_js_5.makeError)("provider destroyed; cancelled request", "UNSUPPORTED_OPERATION", { operation: method }));
|
|
62059
62059
|
}
|
|
62060
62060
|
const id = this.#nextId++;
|
|
62061
|
-
const promise3 = new Promise((resolve7,
|
|
62061
|
+
const promise3 = new Promise((resolve7, reject2) => {
|
|
62062
62062
|
this.#payloads.push({
|
|
62063
62063
|
resolve: resolve7,
|
|
62064
|
-
reject,
|
|
62064
|
+
reject: reject2,
|
|
62065
62065
|
payload: { method, params, id, jsonrpc: "2.0" }
|
|
62066
62066
|
});
|
|
62067
62067
|
});
|
|
@@ -62113,8 +62113,8 @@ var require_provider_jsonrpc = __commonJS({
|
|
|
62113
62113
|
clearTimeout(this.#drainTimer);
|
|
62114
62114
|
this.#drainTimer = null;
|
|
62115
62115
|
}
|
|
62116
|
-
for (const { payload, reject } of this.#payloads) {
|
|
62117
|
-
|
|
62116
|
+
for (const { payload, reject: reject2 } of this.#payloads) {
|
|
62117
|
+
reject2((0, index_js_5.makeError)("provider destroyed; cancelled request", "UNSUPPORTED_OPERATION", { operation: payload.method }));
|
|
62118
62118
|
}
|
|
62119
62119
|
this.#payloads = [];
|
|
62120
62120
|
super.destroy();
|
|
@@ -67057,8 +67057,8 @@ var require_provider_socket = __commonJS({
|
|
|
67057
67057
|
}
|
|
67058
67058
|
async _send(payload) {
|
|
67059
67059
|
(0, index_js_1.assertArgument)(!Array.isArray(payload), "WebSocket does not support batch send", "payload", payload);
|
|
67060
|
-
const promise3 = new Promise((resolve7,
|
|
67061
|
-
this.#callbacks.set(payload.id, { payload, resolve: resolve7, reject });
|
|
67060
|
+
const promise3 = new Promise((resolve7, reject2) => {
|
|
67061
|
+
this.#callbacks.set(payload.id, { payload, resolve: resolve7, reject: reject2 });
|
|
67062
67062
|
});
|
|
67063
67063
|
await this._waitUntilReady();
|
|
67064
67064
|
await this._write(JSON.stringify(payload));
|
|
@@ -68348,7 +68348,7 @@ var require_provider_browser = __commonJS({
|
|
|
68348
68348
|
if (timeout === 0) {
|
|
68349
68349
|
return null;
|
|
68350
68350
|
}
|
|
68351
|
-
return await new Promise((resolve7,
|
|
68351
|
+
return await new Promise((resolve7, reject2) => {
|
|
68352
68352
|
let found = [];
|
|
68353
68353
|
const addProvider = (event) => {
|
|
68354
68354
|
found.push(event.detail);
|
|
@@ -68377,7 +68377,7 @@ var require_provider_browser = __commonJS({
|
|
|
68377
68377
|
providerInfo: info
|
|
68378
68378
|
}));
|
|
68379
68379
|
} else {
|
|
68380
|
-
|
|
68380
|
+
reject2((0, index_js_1.makeError)("filter returned unknown info", "UNSUPPORTED_OPERATION", {
|
|
68381
68381
|
value: filtered
|
|
68382
68382
|
}));
|
|
68383
68383
|
}
|
|
@@ -72900,19 +72900,19 @@ var require_utils7 = __commonJS({
|
|
|
72900
72900
|
resolve7(value);
|
|
72901
72901
|
});
|
|
72902
72902
|
}
|
|
72903
|
-
return new (P || (P = Promise))(function(resolve7,
|
|
72903
|
+
return new (P || (P = Promise))(function(resolve7, reject2) {
|
|
72904
72904
|
function fulfilled(value) {
|
|
72905
72905
|
try {
|
|
72906
72906
|
step(generator.next(value));
|
|
72907
72907
|
} catch (e) {
|
|
72908
|
-
|
|
72908
|
+
reject2(e);
|
|
72909
72909
|
}
|
|
72910
72910
|
}
|
|
72911
72911
|
function rejected(value) {
|
|
72912
72912
|
try {
|
|
72913
72913
|
step(generator["throw"](value));
|
|
72914
72914
|
} catch (e) {
|
|
72915
|
-
|
|
72915
|
+
reject2(e);
|
|
72916
72916
|
}
|
|
72917
72917
|
}
|
|
72918
72918
|
function step(result) {
|
|
@@ -73009,19 +73009,19 @@ var require_client = __commonJS({
|
|
|
73009
73009
|
resolve7(value);
|
|
73010
73010
|
});
|
|
73011
73011
|
}
|
|
73012
|
-
return new (P || (P = Promise))(function(resolve7,
|
|
73012
|
+
return new (P || (P = Promise))(function(resolve7, reject2) {
|
|
73013
73013
|
function fulfilled(value) {
|
|
73014
73014
|
try {
|
|
73015
73015
|
step(generator.next(value));
|
|
73016
73016
|
} catch (e) {
|
|
73017
|
-
|
|
73017
|
+
reject2(e);
|
|
73018
73018
|
}
|
|
73019
73019
|
}
|
|
73020
73020
|
function rejected(value) {
|
|
73021
73021
|
try {
|
|
73022
73022
|
step(generator["throw"](value));
|
|
73023
73023
|
} catch (e) {
|
|
73024
|
-
|
|
73024
|
+
reject2(e);
|
|
73025
73025
|
}
|
|
73026
73026
|
}
|
|
73027
73027
|
function step(result) {
|
|
@@ -73165,13 +73165,13 @@ var require_client = __commonJS({
|
|
|
73165
73165
|
*/
|
|
73166
73166
|
verify(params, opts = { suppressExceptions: false }) {
|
|
73167
73167
|
return __awaiter2(this, void 0, void 0, function* () {
|
|
73168
|
-
return new Promise((resolve7,
|
|
73168
|
+
return new Promise((resolve7, reject2) => {
|
|
73169
73169
|
var _a4, _b, _c;
|
|
73170
73170
|
const fail = (result) => {
|
|
73171
73171
|
if (opts.suppressExceptions) {
|
|
73172
73172
|
return resolve7(result);
|
|
73173
73173
|
} else {
|
|
73174
|
-
return
|
|
73174
|
+
return reject2(result);
|
|
73175
73175
|
}
|
|
73176
73176
|
};
|
|
73177
73177
|
const invalidParams = (0, utils_1.checkInvalidKeys)(params, types_1.VerifyParamsKeys);
|
|
@@ -78668,7 +78668,7 @@ init_esm_shims();
|
|
|
78668
78668
|
// ../sdk/dist/index.js
|
|
78669
78669
|
init_esm_shims();
|
|
78670
78670
|
|
|
78671
|
-
// ../sdk/dist/chunk-
|
|
78671
|
+
// ../sdk/dist/chunk-PLDXIESP.js
|
|
78672
78672
|
init_esm_shims();
|
|
78673
78673
|
|
|
78674
78674
|
// ../../node_modules/.pnpm/viem@2.52.2_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@6.0.6_zod@4.3.6/node_modules/viem/_esm/index.js
|
|
@@ -80519,9 +80519,9 @@ init_esm_shims();
|
|
|
80519
80519
|
init_esm_shims();
|
|
80520
80520
|
init_utils3();
|
|
80521
80521
|
async function wait(time5, { signal } = {}) {
|
|
80522
|
-
return new Promise((resolve7,
|
|
80522
|
+
return new Promise((resolve7, reject2) => {
|
|
80523
80523
|
if (signal?.aborted) {
|
|
80524
|
-
|
|
80524
|
+
reject2(getAbortError(signal));
|
|
80525
80525
|
return;
|
|
80526
80526
|
}
|
|
80527
80527
|
const cleanup = () => signal?.removeEventListener("abort", onAbort);
|
|
@@ -80532,7 +80532,7 @@ async function wait(time5, { signal } = {}) {
|
|
|
80532
80532
|
const onAbort = () => {
|
|
80533
80533
|
clearTimeout(timeout);
|
|
80534
80534
|
cleanup();
|
|
80535
|
-
|
|
80535
|
+
reject2(getAbortError(signal));
|
|
80536
80536
|
};
|
|
80537
80537
|
signal?.addEventListener("abort", onAbort, { once: true });
|
|
80538
80538
|
});
|
|
@@ -81104,10 +81104,10 @@ init_withResolvers();
|
|
|
81104
81104
|
init_esm_shims();
|
|
81105
81105
|
init_utils3();
|
|
81106
81106
|
function withRetry(fn, { delay: delay_ = 100, retryCount = 2, shouldRetry: shouldRetry3 = () => true, signal } = {}) {
|
|
81107
|
-
return new Promise((resolve7,
|
|
81107
|
+
return new Promise((resolve7, reject2) => {
|
|
81108
81108
|
const attemptRetry = async ({ count = 0 } = {}) => {
|
|
81109
81109
|
if (signal?.aborted) {
|
|
81110
|
-
|
|
81110
|
+
reject2(getAbortError(signal));
|
|
81111
81111
|
return;
|
|
81112
81112
|
}
|
|
81113
81113
|
const retry = async ({ error: error98 }) => {
|
|
@@ -81116,7 +81116,7 @@ function withRetry(fn, { delay: delay_ = 100, retryCount = 2, shouldRetry: shoul
|
|
|
81116
81116
|
try {
|
|
81117
81117
|
await wait(delay, { signal });
|
|
81118
81118
|
} catch (err) {
|
|
81119
|
-
|
|
81119
|
+
reject2(err);
|
|
81120
81120
|
return;
|
|
81121
81121
|
}
|
|
81122
81122
|
}
|
|
@@ -81127,16 +81127,16 @@ function withRetry(fn, { delay: delay_ = 100, retryCount = 2, shouldRetry: shoul
|
|
|
81127
81127
|
resolve7(data);
|
|
81128
81128
|
} catch (err) {
|
|
81129
81129
|
if (signal?.aborted) {
|
|
81130
|
-
|
|
81130
|
+
reject2(getAbortError(signal));
|
|
81131
81131
|
return;
|
|
81132
81132
|
}
|
|
81133
81133
|
if (isAbortError(err)) {
|
|
81134
|
-
|
|
81134
|
+
reject2(err);
|
|
81135
81135
|
return;
|
|
81136
81136
|
}
|
|
81137
81137
|
if (count < retryCount && await shouldRetry3({ count, error: err }))
|
|
81138
81138
|
return retry({ error: err });
|
|
81139
|
-
|
|
81139
|
+
reject2(err);
|
|
81140
81140
|
}
|
|
81141
81141
|
};
|
|
81142
81142
|
attemptRetry();
|
|
@@ -81383,9 +81383,9 @@ async function waitForCallsStatus(client, parameters) {
|
|
|
81383
81383
|
throwOnFailure = false
|
|
81384
81384
|
} = parameters;
|
|
81385
81385
|
const observerId = stringify(["waitForCallsStatus", client.uid, id]);
|
|
81386
|
-
const { promise: promise3, resolve: resolve7, reject } = withResolvers();
|
|
81386
|
+
const { promise: promise3, resolve: resolve7, reject: reject2 } = withResolvers();
|
|
81387
81387
|
let timer;
|
|
81388
|
-
const unobserve = observe(observerId, { resolve: resolve7, reject }, (emit) => {
|
|
81388
|
+
const unobserve = observe(observerId, { resolve: resolve7, reject: reject2 }, (emit) => {
|
|
81389
81389
|
const unpoll = poll(async () => {
|
|
81390
81390
|
const done = (fn) => {
|
|
81391
81391
|
clearTimeout(timer);
|
|
@@ -81418,7 +81418,7 @@ async function waitForCallsStatus(client, parameters) {
|
|
|
81418
81418
|
timer = timeout ? setTimeout(() => {
|
|
81419
81419
|
unobserve();
|
|
81420
81420
|
clearTimeout(timer);
|
|
81421
|
-
|
|
81421
|
+
reject2(new WaitForCallsStatusTimeoutError({ id }));
|
|
81422
81422
|
}, timeout) : void 0;
|
|
81423
81423
|
return await promise3;
|
|
81424
81424
|
}
|
|
@@ -83259,7 +83259,7 @@ init_utils3();
|
|
|
83259
83259
|
init_esm_shims();
|
|
83260
83260
|
init_utils3();
|
|
83261
83261
|
function withTimeout(fn, { errorInstance = new Error("timed out"), timeout, signal }) {
|
|
83262
|
-
return new Promise((resolve7,
|
|
83262
|
+
return new Promise((resolve7, reject2) => {
|
|
83263
83263
|
(async () => {
|
|
83264
83264
|
let timeoutId;
|
|
83265
83265
|
const controller = new AbortController();
|
|
@@ -83274,10 +83274,10 @@ function withTimeout(fn, { errorInstance = new Error("timed out"), timeout, sign
|
|
|
83274
83274
|
resolve7(await fn({ signal: controller?.signal || null }));
|
|
83275
83275
|
} catch (err) {
|
|
83276
83276
|
if (controller?.signal.aborted && isAbortError(err)) {
|
|
83277
|
-
|
|
83277
|
+
reject2(errorInstance);
|
|
83278
83278
|
return;
|
|
83279
83279
|
}
|
|
83280
|
-
|
|
83280
|
+
reject2(err);
|
|
83281
83281
|
} finally {
|
|
83282
83282
|
clearTimeout(timeoutId);
|
|
83283
83283
|
}
|
|
@@ -87200,13 +87200,13 @@ async function waitForTransactionReceipt(client, parameters) {
|
|
|
87200
87200
|
let retrying = false;
|
|
87201
87201
|
let _unobserve;
|
|
87202
87202
|
let _unwatch;
|
|
87203
|
-
const { promise: promise3, resolve: resolve7, reject } = withResolvers();
|
|
87203
|
+
const { promise: promise3, resolve: resolve7, reject: reject2 } = withResolvers();
|
|
87204
87204
|
const timer = timeout ? setTimeout(() => {
|
|
87205
87205
|
_unwatch?.();
|
|
87206
87206
|
_unobserve?.();
|
|
87207
|
-
|
|
87207
|
+
reject2(new WaitForTransactionReceiptTimeoutError({ hash: hash13 }));
|
|
87208
87208
|
}, timeout) : void 0;
|
|
87209
|
-
_unobserve = observe(observerId, { onReplaced, resolve: resolve7, reject }, async (emit) => {
|
|
87209
|
+
_unobserve = observe(observerId, { onReplaced, resolve: resolve7, reject: reject2 }, async (emit) => {
|
|
87210
87210
|
receipt = await getAction(client, getTransactionReceipt, "getTransactionReceipt")({ hash: hash13 }).catch(() => void 0);
|
|
87211
87211
|
if (receipt && confirmations <= 1) {
|
|
87212
87212
|
clearTimeout(timer);
|
|
@@ -100663,12 +100663,12 @@ init_esm_shims();
|
|
|
100663
100663
|
|
|
100664
100664
|
// ../../node_modules/.pnpm/axios@1.15.0/node_modules/axios/lib/core/settle.js
|
|
100665
100665
|
init_esm_shims();
|
|
100666
|
-
function settle(resolve7,
|
|
100666
|
+
function settle(resolve7, reject2, response) {
|
|
100667
100667
|
const validateStatus2 = response.config.validateStatus;
|
|
100668
100668
|
if (!response.status || !validateStatus2 || validateStatus2(response.status)) {
|
|
100669
100669
|
resolve7(response);
|
|
100670
100670
|
} else {
|
|
100671
|
-
|
|
100671
|
+
reject2(
|
|
100672
100672
|
new AxiosError_default(
|
|
100673
100673
|
"Request failed with status code " + response.status,
|
|
100674
100674
|
[AxiosError_default.ERR_BAD_REQUEST, AxiosError_default.ERR_BAD_RESPONSE][Math.floor(response.status / 100) - 4],
|
|
@@ -101469,7 +101469,7 @@ function setProxy(options, configProxy, location2) {
|
|
|
101469
101469
|
}
|
|
101470
101470
|
var isHttpAdapterSupported = typeof process !== "undefined" && utils_default.kindOf(process) === "process";
|
|
101471
101471
|
var wrapAsync = (asyncExecutor) => {
|
|
101472
|
-
return new Promise((resolve7,
|
|
101472
|
+
return new Promise((resolve7, reject2) => {
|
|
101473
101473
|
let onDone;
|
|
101474
101474
|
let isDone;
|
|
101475
101475
|
const done = (value, isRejected) => {
|
|
@@ -101483,7 +101483,7 @@ var wrapAsync = (asyncExecutor) => {
|
|
|
101483
101483
|
};
|
|
101484
101484
|
const _reject = (reason) => {
|
|
101485
101485
|
done(reason, true);
|
|
101486
|
-
|
|
101486
|
+
reject2(reason);
|
|
101487
101487
|
};
|
|
101488
101488
|
asyncExecutor(_resolve, _reject, (onDoneHandler) => onDone = onDoneHandler).catch(_reject);
|
|
101489
101489
|
});
|
|
@@ -101526,7 +101526,7 @@ var http2Transport = {
|
|
|
101526
101526
|
}
|
|
101527
101527
|
};
|
|
101528
101528
|
var http_default = isHttpAdapterSupported && function httpAdapter(config3) {
|
|
101529
|
-
return wrapAsync(async function dispatchHttpRequest(resolve7,
|
|
101529
|
+
return wrapAsync(async function dispatchHttpRequest(resolve7, reject2, onDone) {
|
|
101530
101530
|
let { data, lookup, family, httpVersion = 1, http2Options } = config3;
|
|
101531
101531
|
const { responseType, responseEncoding } = config3;
|
|
101532
101532
|
const method = config3.method.toUpperCase();
|
|
@@ -101564,7 +101564,7 @@ var http_default = isHttpAdapterSupported && function httpAdapter(config3) {
|
|
|
101564
101564
|
console.warn("emit error", err);
|
|
101565
101565
|
}
|
|
101566
101566
|
}
|
|
101567
|
-
abortEmitter.once("abort",
|
|
101567
|
+
abortEmitter.once("abort", reject2);
|
|
101568
101568
|
const onFinished = () => {
|
|
101569
101569
|
if (config3.cancelToken) {
|
|
101570
101570
|
config3.cancelToken.unsubscribe(abort);
|
|
@@ -101605,7 +101605,7 @@ var http_default = isHttpAdapterSupported && function httpAdapter(config3) {
|
|
|
101605
101605
|
const dataUrl = String(config3.url || fullPath || "");
|
|
101606
101606
|
const estimated = estimateDataURLDecodedBytes(dataUrl);
|
|
101607
101607
|
if (estimated > config3.maxContentLength) {
|
|
101608
|
-
return
|
|
101608
|
+
return reject2(
|
|
101609
101609
|
new AxiosError_default(
|
|
101610
101610
|
"maxContentLength size of " + config3.maxContentLength + " exceeded",
|
|
101611
101611
|
AxiosError_default.ERR_BAD_RESPONSE,
|
|
@@ -101616,7 +101616,7 @@ var http_default = isHttpAdapterSupported && function httpAdapter(config3) {
|
|
|
101616
101616
|
}
|
|
101617
101617
|
let convertedData;
|
|
101618
101618
|
if (method !== "GET") {
|
|
101619
|
-
return settle(resolve7,
|
|
101619
|
+
return settle(resolve7, reject2, {
|
|
101620
101620
|
status: 405,
|
|
101621
101621
|
statusText: "method not allowed",
|
|
101622
101622
|
headers: {},
|
|
@@ -101638,7 +101638,7 @@ var http_default = isHttpAdapterSupported && function httpAdapter(config3) {
|
|
|
101638
101638
|
} else if (responseType === "stream") {
|
|
101639
101639
|
convertedData = stream3.Readable.from(convertedData);
|
|
101640
101640
|
}
|
|
101641
|
-
return settle(resolve7,
|
|
101641
|
+
return settle(resolve7, reject2, {
|
|
101642
101642
|
data: convertedData,
|
|
101643
101643
|
status: 200,
|
|
101644
101644
|
statusText: "OK",
|
|
@@ -101647,7 +101647,7 @@ var http_default = isHttpAdapterSupported && function httpAdapter(config3) {
|
|
|
101647
101647
|
});
|
|
101648
101648
|
}
|
|
101649
101649
|
if (supportedProtocols.indexOf(protocol) === -1) {
|
|
101650
|
-
return
|
|
101650
|
+
return reject2(
|
|
101651
101651
|
new AxiosError_default("Unsupported protocol " + protocol, AxiosError_default.ERR_BAD_REQUEST, config3)
|
|
101652
101652
|
);
|
|
101653
101653
|
}
|
|
@@ -101688,7 +101688,7 @@ var http_default = isHttpAdapterSupported && function httpAdapter(config3) {
|
|
|
101688
101688
|
} else if (utils_default.isString(data)) {
|
|
101689
101689
|
data = Buffer.from(data, "utf-8");
|
|
101690
101690
|
} else {
|
|
101691
|
-
return
|
|
101691
|
+
return reject2(
|
|
101692
101692
|
new AxiosError_default(
|
|
101693
101693
|
"Data after transformation must be a string, an ArrayBuffer, a Buffer, or a Stream",
|
|
101694
101694
|
AxiosError_default.ERR_BAD_REQUEST,
|
|
@@ -101698,7 +101698,7 @@ var http_default = isHttpAdapterSupported && function httpAdapter(config3) {
|
|
|
101698
101698
|
}
|
|
101699
101699
|
headers.setContentLength(data.length, false);
|
|
101700
101700
|
if (config3.maxBodyLength > -1 && data.length > config3.maxBodyLength) {
|
|
101701
|
-
return
|
|
101701
|
+
return reject2(
|
|
101702
101702
|
new AxiosError_default(
|
|
101703
101703
|
"Request body larger than maxBodyLength limit",
|
|
101704
101704
|
AxiosError_default.ERR_BAD_REQUEST,
|
|
@@ -101762,7 +101762,7 @@ var http_default = isHttpAdapterSupported && function httpAdapter(config3) {
|
|
|
101762
101762
|
customErr.config = config3;
|
|
101763
101763
|
customErr.url = config3.url;
|
|
101764
101764
|
customErr.exists = true;
|
|
101765
|
-
return
|
|
101765
|
+
return reject2(customErr);
|
|
101766
101766
|
}
|
|
101767
101767
|
headers.set(
|
|
101768
101768
|
"Accept-Encoding",
|
|
@@ -101878,7 +101878,7 @@ var http_default = isHttpAdapterSupported && function httpAdapter(config3) {
|
|
|
101878
101878
|
};
|
|
101879
101879
|
if (responseType === "stream") {
|
|
101880
101880
|
response.data = responseStream;
|
|
101881
|
-
settle(resolve7,
|
|
101881
|
+
settle(resolve7, reject2, response);
|
|
101882
101882
|
} else {
|
|
101883
101883
|
const responseBuffer = [];
|
|
101884
101884
|
let totalResponseBytes = 0;
|
|
@@ -101909,11 +101909,11 @@ var http_default = isHttpAdapterSupported && function httpAdapter(config3) {
|
|
|
101909
101909
|
lastRequest
|
|
101910
101910
|
);
|
|
101911
101911
|
responseStream.destroy(err);
|
|
101912
|
-
|
|
101912
|
+
reject2(err);
|
|
101913
101913
|
});
|
|
101914
101914
|
responseStream.on("error", function handleStreamError(err) {
|
|
101915
101915
|
if (req.destroyed) return;
|
|
101916
|
-
|
|
101916
|
+
reject2(AxiosError_default.from(err, null, config3, lastRequest));
|
|
101917
101917
|
});
|
|
101918
101918
|
responseStream.on("end", function handleStreamEnd() {
|
|
101919
101919
|
try {
|
|
@@ -101926,9 +101926,9 @@ var http_default = isHttpAdapterSupported && function httpAdapter(config3) {
|
|
|
101926
101926
|
}
|
|
101927
101927
|
response.data = responseData;
|
|
101928
101928
|
} catch (err) {
|
|
101929
|
-
return
|
|
101929
|
+
return reject2(AxiosError_default.from(err, null, config3, response.request, response));
|
|
101930
101930
|
}
|
|
101931
|
-
settle(resolve7,
|
|
101931
|
+
settle(resolve7, reject2, response);
|
|
101932
101932
|
});
|
|
101933
101933
|
}
|
|
101934
101934
|
abortEmitter.once("abort", (err) => {
|
|
@@ -101946,7 +101946,7 @@ var http_default = isHttpAdapterSupported && function httpAdapter(config3) {
|
|
|
101946
101946
|
}
|
|
101947
101947
|
});
|
|
101948
101948
|
req.on("error", function handleRequestError(err) {
|
|
101949
|
-
|
|
101949
|
+
reject2(AxiosError_default.from(err, null, config3, req));
|
|
101950
101950
|
});
|
|
101951
101951
|
req.on("socket", function handleRequestSocket(socket) {
|
|
101952
101952
|
socket.setKeepAlive(true, 1e3 * 60);
|
|
@@ -102197,7 +102197,7 @@ var resolveConfig_default = (config3) => {
|
|
|
102197
102197
|
// ../../node_modules/.pnpm/axios@1.15.0/node_modules/axios/lib/adapters/xhr.js
|
|
102198
102198
|
var isXHRAdapterSupported = typeof XMLHttpRequest !== "undefined";
|
|
102199
102199
|
var xhr_default = isXHRAdapterSupported && function(config3) {
|
|
102200
|
-
return new Promise(function dispatchXhrRequest(resolve7,
|
|
102200
|
+
return new Promise(function dispatchXhrRequest(resolve7, reject2) {
|
|
102201
102201
|
const _config = resolveConfig_default(config3);
|
|
102202
102202
|
let requestData = _config.data;
|
|
102203
102203
|
const requestHeaders = AxiosHeaders_default.from(_config.headers).normalize();
|
|
@@ -102236,7 +102236,7 @@ var xhr_default = isXHRAdapterSupported && function(config3) {
|
|
|
102236
102236
|
done();
|
|
102237
102237
|
},
|
|
102238
102238
|
function _reject(err) {
|
|
102239
|
-
|
|
102239
|
+
reject2(err);
|
|
102240
102240
|
done();
|
|
102241
102241
|
},
|
|
102242
102242
|
response
|
|
@@ -102260,14 +102260,14 @@ var xhr_default = isXHRAdapterSupported && function(config3) {
|
|
|
102260
102260
|
if (!request3) {
|
|
102261
102261
|
return;
|
|
102262
102262
|
}
|
|
102263
|
-
|
|
102263
|
+
reject2(new AxiosError_default("Request aborted", AxiosError_default.ECONNABORTED, config3, request3));
|
|
102264
102264
|
request3 = null;
|
|
102265
102265
|
};
|
|
102266
102266
|
request3.onerror = function handleError(event) {
|
|
102267
102267
|
const msg = event && event.message ? event.message : "Network Error";
|
|
102268
102268
|
const err = new AxiosError_default(msg, AxiosError_default.ERR_NETWORK, config3, request3);
|
|
102269
102269
|
err.event = event || null;
|
|
102270
|
-
|
|
102270
|
+
reject2(err);
|
|
102271
102271
|
request3 = null;
|
|
102272
102272
|
};
|
|
102273
102273
|
request3.ontimeout = function handleTimeout() {
|
|
@@ -102276,7 +102276,7 @@ var xhr_default = isXHRAdapterSupported && function(config3) {
|
|
|
102276
102276
|
if (_config.timeoutErrorMessage) {
|
|
102277
102277
|
timeoutErrorMessage = _config.timeoutErrorMessage;
|
|
102278
102278
|
}
|
|
102279
|
-
|
|
102279
|
+
reject2(
|
|
102280
102280
|
new AxiosError_default(
|
|
102281
102281
|
timeoutErrorMessage,
|
|
102282
102282
|
transitional2.clarifyTimeoutError ? AxiosError_default.ETIMEDOUT : AxiosError_default.ECONNABORTED,
|
|
@@ -102312,7 +102312,7 @@ var xhr_default = isXHRAdapterSupported && function(config3) {
|
|
|
102312
102312
|
if (!request3) {
|
|
102313
102313
|
return;
|
|
102314
102314
|
}
|
|
102315
|
-
|
|
102315
|
+
reject2(!cancel2 || cancel2.type ? new CanceledError_default(null, config3, request3) : cancel2);
|
|
102316
102316
|
request3.abort();
|
|
102317
102317
|
request3 = null;
|
|
102318
102318
|
};
|
|
@@ -102323,7 +102323,7 @@ var xhr_default = isXHRAdapterSupported && function(config3) {
|
|
|
102323
102323
|
}
|
|
102324
102324
|
const protocol = parseProtocol(_config.url);
|
|
102325
102325
|
if (protocol && platform_default.protocols.indexOf(protocol) === -1) {
|
|
102326
|
-
|
|
102326
|
+
reject2(
|
|
102327
102327
|
new AxiosError_default(
|
|
102328
102328
|
"Unsupported protocol " + protocol + ":",
|
|
102329
102329
|
AxiosError_default.ERR_BAD_REQUEST,
|
|
@@ -102637,8 +102637,8 @@ var factory = (env) => {
|
|
|
102637
102637
|
config3
|
|
102638
102638
|
);
|
|
102639
102639
|
!isStreamResponse && unsubscribe && unsubscribe();
|
|
102640
|
-
return await new Promise((resolve7,
|
|
102641
|
-
settle(resolve7,
|
|
102640
|
+
return await new Promise((resolve7, reject2) => {
|
|
102641
|
+
settle(resolve7, reject2, {
|
|
102642
102642
|
data: responseData,
|
|
102643
102643
|
headers: AxiosHeaders_default.from(response.headers),
|
|
102644
102644
|
status: response.status,
|
|
@@ -103082,7 +103082,7 @@ var CancelToken = class _CancelToken {
|
|
|
103082
103082
|
token.subscribe(resolve7);
|
|
103083
103083
|
_resolve = resolve7;
|
|
103084
103084
|
}).then(onfulfilled);
|
|
103085
|
-
promise3.cancel = function
|
|
103085
|
+
promise3.cancel = function reject2() {
|
|
103086
103086
|
token.unsubscribe(_resolve);
|
|
103087
103087
|
};
|
|
103088
103088
|
return promise3;
|
|
@@ -104614,8 +104614,8 @@ async function executeSteps(chainId2, request3 = {}, wallet, setState, newJson,
|
|
|
104614
104614
|
websocketFailedPromise = new Promise((resolve7) => {
|
|
104615
104615
|
resolveWebsocketFailed = resolve7;
|
|
104616
104616
|
});
|
|
104617
|
-
terminalStatusPromise = new Promise((_,
|
|
104618
|
-
rejectTerminalStatus =
|
|
104617
|
+
terminalStatusPromise = new Promise((_, reject2) => {
|
|
104618
|
+
rejectTerminalStatus = reject2;
|
|
104619
104619
|
});
|
|
104620
104620
|
statusControl.closeWebSocket = trackRequestStatus({
|
|
104621
104621
|
event: "request.status.updated",
|
|
@@ -104662,7 +104662,7 @@ async function executeSteps(chainId2, request3 = {}, wallet, setState, newJson,
|
|
|
104662
104662
|
let { kind } = step;
|
|
104663
104663
|
client.log([`Execute Steps: Begin processing step items for: ${step.action}`], LogLevel.Verbose);
|
|
104664
104664
|
const promises = stepItems.filter((stepItem) => stepItem.status === "incomplete").map((stepItem) => {
|
|
104665
|
-
return new Promise(async (resolve7,
|
|
104665
|
+
return new Promise(async (resolve7, reject2) => {
|
|
104666
104666
|
try {
|
|
104667
104667
|
const stepExecutionPromise = (async () => {
|
|
104668
104668
|
switch (kind) {
|
|
@@ -104736,7 +104736,7 @@ async function executeSteps(chainId2, request3 = {}, wallet, setState, newJson,
|
|
|
104736
104736
|
details: json3?.details
|
|
104737
104737
|
});
|
|
104738
104738
|
}
|
|
104739
|
-
|
|
104739
|
+
reject2(error98);
|
|
104740
104740
|
}
|
|
104741
104741
|
});
|
|
104742
104742
|
});
|
|
@@ -105604,7 +105604,7 @@ function execute(data) {
|
|
|
105604
105604
|
}
|
|
105605
105605
|
const { request: request3, ...restOfQuote } = quote;
|
|
105606
105606
|
const _quote = safeStructuredClone(restOfQuote);
|
|
105607
|
-
const executionPromise = new Promise((resolve7,
|
|
105607
|
+
const executionPromise = new Promise((resolve7, reject2) => {
|
|
105608
105608
|
executeSteps(chainId2, request3, adaptedWallet, ({ steps, fees, breakdown, details, refunded, error: error98 }) => {
|
|
105609
105609
|
if (abortController.signal.aborted) {
|
|
105610
105610
|
console.log("Relay SDK: Execution aborted, skipping progress callback");
|
|
@@ -105628,7 +105628,7 @@ function execute(data) {
|
|
|
105628
105628
|
}
|
|
105629
105629
|
} : void 0).then((data2) => {
|
|
105630
105630
|
resolve7({ data: data2, abortController });
|
|
105631
|
-
}).catch(
|
|
105631
|
+
}).catch(reject2);
|
|
105632
105632
|
});
|
|
105633
105633
|
executionPromise.abortController = abortController;
|
|
105634
105634
|
return executionPromise;
|
|
@@ -112457,9 +112457,9 @@ init_esm_shims();
|
|
|
112457
112457
|
init_esm_shims();
|
|
112458
112458
|
init_utils6();
|
|
112459
112459
|
async function wait2(time5, { signal } = {}) {
|
|
112460
|
-
return new Promise((resolve7,
|
|
112460
|
+
return new Promise((resolve7, reject2) => {
|
|
112461
112461
|
if (signal?.aborted) {
|
|
112462
|
-
|
|
112462
|
+
reject2(getAbortError2(signal));
|
|
112463
112463
|
return;
|
|
112464
112464
|
}
|
|
112465
112465
|
const cleanup = () => signal?.removeEventListener("abort", onAbort);
|
|
@@ -112470,7 +112470,7 @@ async function wait2(time5, { signal } = {}) {
|
|
|
112470
112470
|
const onAbort = () => {
|
|
112471
112471
|
clearTimeout(timeout);
|
|
112472
112472
|
cleanup();
|
|
112473
|
-
|
|
112473
|
+
reject2(getAbortError2(signal));
|
|
112474
112474
|
};
|
|
112475
112475
|
signal?.addEventListener("abort", onAbort, { once: true });
|
|
112476
112476
|
});
|
|
@@ -112774,10 +112774,10 @@ async function sendRawTransaction2(client, { serializedTransaction }) {
|
|
|
112774
112774
|
init_esm_shims();
|
|
112775
112775
|
init_utils6();
|
|
112776
112776
|
function withRetry2(fn, { delay: delay_ = 100, retryCount = 2, shouldRetry: shouldRetry3 = () => true, signal } = {}) {
|
|
112777
|
-
return new Promise((resolve7,
|
|
112777
|
+
return new Promise((resolve7, reject2) => {
|
|
112778
112778
|
const attemptRetry = async ({ count = 0 } = {}) => {
|
|
112779
112779
|
if (signal?.aborted) {
|
|
112780
|
-
|
|
112780
|
+
reject2(getAbortError2(signal));
|
|
112781
112781
|
return;
|
|
112782
112782
|
}
|
|
112783
112783
|
const retry = async ({ error: error98 }) => {
|
|
@@ -112786,7 +112786,7 @@ function withRetry2(fn, { delay: delay_ = 100, retryCount = 2, shouldRetry: shou
|
|
|
112786
112786
|
try {
|
|
112787
112787
|
await wait2(delay, { signal });
|
|
112788
112788
|
} catch (err) {
|
|
112789
|
-
|
|
112789
|
+
reject2(err);
|
|
112790
112790
|
return;
|
|
112791
112791
|
}
|
|
112792
112792
|
}
|
|
@@ -112797,16 +112797,16 @@ function withRetry2(fn, { delay: delay_ = 100, retryCount = 2, shouldRetry: shou
|
|
|
112797
112797
|
resolve7(data);
|
|
112798
112798
|
} catch (err) {
|
|
112799
112799
|
if (signal?.aborted) {
|
|
112800
|
-
|
|
112800
|
+
reject2(getAbortError2(signal));
|
|
112801
112801
|
return;
|
|
112802
112802
|
}
|
|
112803
112803
|
if (isAbortError2(err)) {
|
|
112804
|
-
|
|
112804
|
+
reject2(err);
|
|
112805
112805
|
return;
|
|
112806
112806
|
}
|
|
112807
112807
|
if (count < retryCount && await shouldRetry3({ count, error: err }))
|
|
112808
112808
|
return retry({ error: err });
|
|
112809
|
-
|
|
112809
|
+
reject2(err);
|
|
112810
112810
|
}
|
|
112811
112811
|
};
|
|
112812
112812
|
attemptRetry();
|
|
@@ -114121,7 +114121,7 @@ init_utils6();
|
|
|
114121
114121
|
init_esm_shims();
|
|
114122
114122
|
init_utils6();
|
|
114123
114123
|
function withTimeout2(fn, { errorInstance = new Error("timed out"), timeout, signal }) {
|
|
114124
|
-
return new Promise((resolve7,
|
|
114124
|
+
return new Promise((resolve7, reject2) => {
|
|
114125
114125
|
(async () => {
|
|
114126
114126
|
let timeoutId;
|
|
114127
114127
|
const controller = new AbortController();
|
|
@@ -114136,10 +114136,10 @@ function withTimeout2(fn, { errorInstance = new Error("timed out"), timeout, sig
|
|
|
114136
114136
|
resolve7(await fn({ signal: controller?.signal || null }));
|
|
114137
114137
|
} catch (err) {
|
|
114138
114138
|
if (controller?.signal.aborted && isAbortError2(err)) {
|
|
114139
|
-
|
|
114139
|
+
reject2(errorInstance);
|
|
114140
114140
|
return;
|
|
114141
114141
|
}
|
|
114142
|
-
|
|
114142
|
+
reject2(err);
|
|
114143
114143
|
} finally {
|
|
114144
114144
|
clearTimeout(timeoutId);
|
|
114145
114145
|
}
|
|
@@ -117455,13 +117455,13 @@ async function waitForTransactionReceipt2(client, parameters) {
|
|
|
117455
117455
|
let retrying = false;
|
|
117456
117456
|
let _unobserve;
|
|
117457
117457
|
let _unwatch;
|
|
117458
|
-
const { promise: promise3, resolve: resolve7, reject } = withResolvers2();
|
|
117458
|
+
const { promise: promise3, resolve: resolve7, reject: reject2 } = withResolvers2();
|
|
117459
117459
|
const timer = timeout ? setTimeout(() => {
|
|
117460
117460
|
_unwatch?.();
|
|
117461
117461
|
_unobserve?.();
|
|
117462
|
-
|
|
117462
|
+
reject2(new WaitForTransactionReceiptTimeoutError2({ hash: hash13 }));
|
|
117463
117463
|
}, timeout) : void 0;
|
|
117464
|
-
_unobserve = observe2(observerId, { onReplaced, resolve: resolve7, reject }, async (emit) => {
|
|
117464
|
+
_unobserve = observe2(observerId, { onReplaced, resolve: resolve7, reject: reject2 }, async (emit) => {
|
|
117465
117465
|
receipt = await getAction2(client, getTransactionReceipt2, "getTransactionReceipt")({ hash: hash13 }).catch(() => void 0);
|
|
117466
117466
|
if (receipt && confirmations <= 1) {
|
|
117467
117467
|
clearTimeout(timer);
|
|
@@ -146840,8 +146840,8 @@ function sessionManager(parameters) {
|
|
|
146840
146840
|
function waitForReceipt(predicate = () => true) {
|
|
146841
146841
|
if (receiptWaiter)
|
|
146842
146842
|
throw new Error("receipt wait already in progress");
|
|
146843
|
-
return new Promise((resolve7,
|
|
146844
|
-
receiptWaiter = { predicate, resolve: resolve7, reject };
|
|
146843
|
+
return new Promise((resolve7, reject2) => {
|
|
146844
|
+
receiptWaiter = { predicate, resolve: resolve7, reject: reject2 };
|
|
146845
146845
|
});
|
|
146846
146846
|
}
|
|
146847
146847
|
function waitForCloseReady() {
|
|
@@ -146849,8 +146849,8 @@ function sessionManager(parameters) {
|
|
|
146849
146849
|
return Promise.resolve(closeReadyReceipt);
|
|
146850
146850
|
if (closeReadyWaiter)
|
|
146851
146851
|
throw new Error("close-ready wait already in progress");
|
|
146852
|
-
return new Promise((resolve7,
|
|
146853
|
-
closeReadyWaiter = { resolve: resolve7, reject };
|
|
146852
|
+
return new Promise((resolve7, reject2) => {
|
|
146853
|
+
closeReadyWaiter = { resolve: resolve7, reject: reject2 };
|
|
146854
146854
|
});
|
|
146855
146855
|
}
|
|
146856
146856
|
function settleReceipt(receipt) {
|
|
@@ -147188,7 +147188,7 @@ function sessionManager(parameters) {
|
|
|
147188
147188
|
}
|
|
147189
147189
|
};
|
|
147190
147190
|
const isExpectedReceipt = (receipt) => receipt.challengeId === challenge2.id && receipt.channelId === activeSocketChannelId;
|
|
147191
|
-
const socketOpened = new Promise((resolve7,
|
|
147191
|
+
const socketOpened = new Promise((resolve7, reject2) => {
|
|
147192
147192
|
const onOpen = () => {
|
|
147193
147193
|
rawSocket.removeEventListener("error", onError);
|
|
147194
147194
|
managedSocket.emit("open", { type: "open" });
|
|
@@ -147196,7 +147196,7 @@ function sessionManager(parameters) {
|
|
|
147196
147196
|
};
|
|
147197
147197
|
const onError = () => {
|
|
147198
147198
|
rawSocket.removeEventListener("open", onOpen);
|
|
147199
|
-
|
|
147199
|
+
reject2(new Error(`WebSocket connection to ${wsUrl} failed to open.`));
|
|
147200
147200
|
};
|
|
147201
147201
|
rawSocket.addEventListener("open", onOpen, { once: true });
|
|
147202
147202
|
rawSocket.addEventListener("error", onError, { once: true });
|
|
@@ -148849,8 +148849,8 @@ function createSingleWaiter(name) {
|
|
|
148849
148849
|
wait(predicate = () => true) {
|
|
148850
148850
|
if (waiter)
|
|
148851
148851
|
throw new Error(`${name} wait already in progress`);
|
|
148852
|
-
return new Promise((resolve7,
|
|
148853
|
-
waiter = { predicate, resolve: resolve7, reject };
|
|
148852
|
+
return new Promise((resolve7, reject2) => {
|
|
148853
|
+
waiter = { predicate, resolve: resolve7, reject: reject2 };
|
|
148854
148854
|
});
|
|
148855
148855
|
},
|
|
148856
148856
|
settle(value) {
|
|
@@ -149454,7 +149454,7 @@ async function openWebSocketSession(parameters) {
|
|
|
149454
149454
|
return managedSocket.socket;
|
|
149455
149455
|
}
|
|
149456
149456
|
function waitForSocketOpen(rawSocket, managedEmit, wsUrl) {
|
|
149457
|
-
return new Promise((resolve7,
|
|
149457
|
+
return new Promise((resolve7, reject2) => {
|
|
149458
149458
|
const onOpen = () => {
|
|
149459
149459
|
rawSocket.removeEventListener("error", onError);
|
|
149460
149460
|
managedEmit("open", { type: "open" });
|
|
@@ -149462,7 +149462,7 @@ function waitForSocketOpen(rawSocket, managedEmit, wsUrl) {
|
|
|
149462
149462
|
};
|
|
149463
149463
|
const onError = () => {
|
|
149464
149464
|
rawSocket.removeEventListener("open", onOpen);
|
|
149465
|
-
|
|
149465
|
+
reject2(new Error(`WebSocket connection to ${wsUrl} failed to open.`));
|
|
149466
149466
|
};
|
|
149467
149467
|
rawSocket.addEventListener("open", onOpen, { once: true });
|
|
149468
149468
|
rawSocket.addEventListener("error", onError, { once: true });
|
|
@@ -164225,6 +164225,135 @@ var ERC20_BALANCE_ABI = [
|
|
|
164225
164225
|
}
|
|
164226
164226
|
];
|
|
164227
164227
|
var USDC_DECIMALS = 6;
|
|
164228
|
+
var FETCH_DIAGNOSTIC_CODES = Object.freeze({
|
|
164229
|
+
capabilityResolutionFailed: "capability_resolution_failed",
|
|
164230
|
+
probeTimeout: "probe_timeout",
|
|
164231
|
+
probeNetworkError: "probe_network_error",
|
|
164232
|
+
challengeDecodeFailed: "challenge_decode_failed",
|
|
164233
|
+
unsupportedPaymentRail: "unsupported_payment_rail",
|
|
164234
|
+
invalidMaxPay: "invalid_max_pay",
|
|
164235
|
+
maxPayExceeded: "max_pay_exceeded",
|
|
164236
|
+
walletResolutionFailed: "wallet_resolution_failed",
|
|
164237
|
+
balanceCheckFailed: "balance_check_failed",
|
|
164238
|
+
insufficientFunds: "insufficient_funds",
|
|
164239
|
+
bridgeFailed: "bridge_failed",
|
|
164240
|
+
credentialSignFailed: "credential_sign_failed",
|
|
164241
|
+
paymentFailed: "payment_failed",
|
|
164242
|
+
paidReplayTimeout: "paid_replay_timeout",
|
|
164243
|
+
paidReplayFailed: "paid_replay_failed",
|
|
164244
|
+
paymentRejected: "payment_rejected",
|
|
164245
|
+
settlementUnconfirmed: "settlement_unconfirmed",
|
|
164246
|
+
settlementReceiptInvalid: "settlement_receipt_invalid",
|
|
164247
|
+
sessionCloseFailed: "session_close_failed",
|
|
164248
|
+
upstream4xx: "upstream_4xx",
|
|
164249
|
+
upstream5xx: "upstream_5xx",
|
|
164250
|
+
upstreamErrorPayload: "upstream_error_payload",
|
|
164251
|
+
bodyReadFailed: "body_read_failed",
|
|
164252
|
+
bodyTruncated: "body_truncated",
|
|
164253
|
+
callerAborted: "caller_aborted",
|
|
164254
|
+
runCreateFailed: "run_create_failed"
|
|
164255
|
+
});
|
|
164256
|
+
var UNCONFIRMED_PAYMENT_CODES = /* @__PURE__ */ new Set([
|
|
164257
|
+
FETCH_DIAGNOSTIC_CODES.paidReplayTimeout,
|
|
164258
|
+
FETCH_DIAGNOSTIC_CODES.paidReplayFailed,
|
|
164259
|
+
FETCH_DIAGNOSTIC_CODES.paymentFailed,
|
|
164260
|
+
FETCH_DIAGNOSTIC_CODES.paymentRejected,
|
|
164261
|
+
FETCH_DIAGNOSTIC_CODES.settlementUnconfirmed,
|
|
164262
|
+
FETCH_DIAGNOSTIC_CODES.callerAborted
|
|
164263
|
+
]);
|
|
164264
|
+
var FetchDiagnosticContext = class {
|
|
164265
|
+
fetchId;
|
|
164266
|
+
failureStage = null;
|
|
164267
|
+
failureCode = null;
|
|
164268
|
+
issues = [];
|
|
164269
|
+
stageDurationsMs = {};
|
|
164270
|
+
paymentProtocol = null;
|
|
164271
|
+
paymentMode = null;
|
|
164272
|
+
fundingSource = null;
|
|
164273
|
+
constructor(fetchId) {
|
|
164274
|
+
this.fetchId = fetchId;
|
|
164275
|
+
}
|
|
164276
|
+
recordDuration = (stage, startedAt) => {
|
|
164277
|
+
const duration5 = Math.max(0, Date.now() - startedAt);
|
|
164278
|
+
this.stageDurationsMs[stage] = (this.stageDurationsMs[stage] ?? 0) + duration5;
|
|
164279
|
+
};
|
|
164280
|
+
measure = async (stage, work) => {
|
|
164281
|
+
const startedAt = Date.now();
|
|
164282
|
+
try {
|
|
164283
|
+
return await work();
|
|
164284
|
+
} finally {
|
|
164285
|
+
this.recordDuration(stage, startedAt);
|
|
164286
|
+
}
|
|
164287
|
+
};
|
|
164288
|
+
issue = (stage, code) => {
|
|
164289
|
+
if (!this.issues.some((item) => item.stage === stage && item.code === code)) {
|
|
164290
|
+
this.issues.push({ stage, code });
|
|
164291
|
+
}
|
|
164292
|
+
};
|
|
164293
|
+
fail = (stage, code) => {
|
|
164294
|
+
this.issue(stage, code);
|
|
164295
|
+
if (this.failureStage === null) {
|
|
164296
|
+
this.failureStage = stage;
|
|
164297
|
+
this.failureCode = code;
|
|
164298
|
+
}
|
|
164299
|
+
};
|
|
164300
|
+
selectPaymentProtocol = (protocol) => {
|
|
164301
|
+
this.paymentProtocol = protocol;
|
|
164302
|
+
};
|
|
164303
|
+
setPaymentMode = (mode) => {
|
|
164304
|
+
this.paymentMode = mode;
|
|
164305
|
+
};
|
|
164306
|
+
setFundingSource = (source) => {
|
|
164307
|
+
this.fundingSource = source;
|
|
164308
|
+
};
|
|
164309
|
+
snapshot = () => ({
|
|
164310
|
+
failureStage: this.failureStage,
|
|
164311
|
+
failureCode: this.failureCode,
|
|
164312
|
+
issues: this.issues.map((issue3) => ({ ...issue3 })),
|
|
164313
|
+
paymentProtocol: this.paymentProtocol,
|
|
164314
|
+
paymentMode: this.paymentMode,
|
|
164315
|
+
fundingSource: this.fundingSource,
|
|
164316
|
+
stageDurationsMs: { ...this.stageDurationsMs }
|
|
164317
|
+
});
|
|
164318
|
+
};
|
|
164319
|
+
var settlementStateFor = (payment, warnings, diagnostics) => {
|
|
164320
|
+
if (warnings?.includes("mpp_session_close_failed")) return "session_open";
|
|
164321
|
+
if (diagnostics?.paymentMode === "proof") return "not_attempted";
|
|
164322
|
+
if (payment !== null && (payment.txHash !== null || payment.session !== void 0))
|
|
164323
|
+
return "confirmed";
|
|
164324
|
+
if (payment !== null) return "unconfirmed";
|
|
164325
|
+
const paymentMayHaveBeenSent = diagnostics?.issues.some(
|
|
164326
|
+
(issue3) => UNCONFIRMED_PAYMENT_CODES.has(issue3.code)
|
|
164327
|
+
);
|
|
164328
|
+
return paymentMayHaveBeenSent ? "unconfirmed" : "not_attempted";
|
|
164329
|
+
};
|
|
164330
|
+
var isCallerAbortError = (error98) => {
|
|
164331
|
+
const record3 = typeof error98 === "object" && error98 !== null ? error98 : null;
|
|
164332
|
+
if (record3?.name === "AbortError") return true;
|
|
164333
|
+
if (record3?.code !== "api_error" || record3.status !== 0) return false;
|
|
164334
|
+
const cause = typeof record3.cause === "object" && record3.cause !== null ? record3.cause : null;
|
|
164335
|
+
return cause?.name === "AbortError";
|
|
164336
|
+
};
|
|
164337
|
+
var attachFetchErrorContext = (error98, fetchId, diagnostics) => {
|
|
164338
|
+
if (typeof error98 !== "object" && typeof error98 !== "function" || error98 === null) {
|
|
164339
|
+
return;
|
|
164340
|
+
}
|
|
164341
|
+
try {
|
|
164342
|
+
Object.defineProperties(error98, {
|
|
164343
|
+
fetchId: { configurable: true, value: fetchId },
|
|
164344
|
+
diagnostics: { configurable: true, value: diagnostics }
|
|
164345
|
+
});
|
|
164346
|
+
} catch {
|
|
164347
|
+
}
|
|
164348
|
+
};
|
|
164349
|
+
var fetchErrorContext = (error98) => {
|
|
164350
|
+
if (typeof error98 !== "object" || error98 === null) return {};
|
|
164351
|
+
const value = error98;
|
|
164352
|
+
return {
|
|
164353
|
+
...typeof value.fetchId === "string" && { fetchId: value.fetchId },
|
|
164354
|
+
...value.diagnostics && typeof value.diagnostics === "object" ? { diagnostics: value.diagnostics } : {}
|
|
164355
|
+
};
|
|
164356
|
+
};
|
|
164228
164357
|
var ERROR_MAX = 500;
|
|
164229
164358
|
var redactUrl = (raw) => {
|
|
164230
164359
|
try {
|
|
@@ -164236,7 +164365,7 @@ var redactUrl = (raw) => {
|
|
|
164236
164365
|
};
|
|
164237
164366
|
var truncateError = (raw) => raw.length > ERROR_MAX ? `${raw.slice(0, ERROR_MAX)}\u2026` : raw;
|
|
164238
164367
|
var package_default = {
|
|
164239
|
-
version: "0.
|
|
164368
|
+
version: "0.21.0"
|
|
164240
164369
|
};
|
|
164241
164370
|
var SDK_VERSION2 = package_default.version;
|
|
164242
164371
|
var ZeroError = class extends Error {
|
|
@@ -164587,9 +164716,9 @@ var buildAccountAuthHeaders = async (account, method, pathWithQuery, body) => {
|
|
|
164587
164716
|
};
|
|
164588
164717
|
};
|
|
164589
164718
|
var RETRYABLE_STATUS = /* @__PURE__ */ new Set([408, 502, 503, 504]);
|
|
164590
|
-
var sleep = (ms, signal) => new Promise((resolve7,
|
|
164719
|
+
var sleep = (ms, signal) => new Promise((resolve7, reject2) => {
|
|
164591
164720
|
if (signal?.aborted) {
|
|
164592
|
-
|
|
164721
|
+
reject2(new DOMException("Aborted", "AbortError"));
|
|
164593
164722
|
return;
|
|
164594
164723
|
}
|
|
164595
164724
|
const timer = setTimeout(() => {
|
|
@@ -164598,7 +164727,7 @@ var sleep = (ms, signal) => new Promise((resolve7, reject) => {
|
|
|
164598
164727
|
}, ms);
|
|
164599
164728
|
const onAbort = () => {
|
|
164600
164729
|
clearTimeout(timer);
|
|
164601
|
-
|
|
164730
|
+
reject2(new DOMException("Aborted", "AbortError"));
|
|
164602
164731
|
};
|
|
164603
164732
|
signal?.addEventListener("abort", onAbort, { once: true });
|
|
164604
164733
|
});
|
|
@@ -164954,15 +165083,44 @@ var isV1ShapedAccept = (accept) => {
|
|
|
164954
165083
|
const v1AmountField = a.maxAmountRequired != null && a.amount == null;
|
|
164955
165084
|
return bareNetwork || v1AmountField;
|
|
164956
165085
|
};
|
|
164957
|
-
var
|
|
165086
|
+
var normalizeX402ChallengeVersion = (challenge2) => {
|
|
164958
165087
|
const accepts = Array.isArray(challenge2.accepts) ? challenge2.accepts : [];
|
|
164959
|
-
|
|
165088
|
+
if (challenge2.x402Version !== 2 || !accepts.some(isV1ShapedAccept)) {
|
|
165089
|
+
return challenge2;
|
|
165090
|
+
}
|
|
165091
|
+
return { ...challenge2, x402Version: 1 };
|
|
164960
165092
|
};
|
|
165093
|
+
var responseWithHeaders = (response, headers) => new Response(response.body, {
|
|
165094
|
+
status: response.status,
|
|
165095
|
+
statusText: response.statusText,
|
|
165096
|
+
headers
|
|
165097
|
+
});
|
|
164961
165098
|
var withSynthesizedX402Header = (baseFetch) => async (input, init) => {
|
|
164962
165099
|
const response = await baseFetch(input, init);
|
|
164963
165100
|
if (response.status !== 402) return response;
|
|
164964
|
-
|
|
164965
|
-
|
|
165101
|
+
const standardHeader = response.headers.get("payment-required");
|
|
165102
|
+
const legacyHeader = response.headers.get("x-payment-required");
|
|
165103
|
+
const encodedHeader = standardHeader ?? legacyHeader;
|
|
165104
|
+
if (encodedHeader) {
|
|
165105
|
+
let normalizedHeader = encodedHeader;
|
|
165106
|
+
try {
|
|
165107
|
+
const decoded = JSON.parse(
|
|
165108
|
+
Buffer.from(encodedHeader, "base64").toString("utf8")
|
|
165109
|
+
);
|
|
165110
|
+
if (looksLikeX402Body(decoded)) {
|
|
165111
|
+
normalizedHeader = encodePaymentRequiredHeader(
|
|
165112
|
+
normalizeX402ChallengeVersion(
|
|
165113
|
+
decoded
|
|
165114
|
+
)
|
|
165115
|
+
);
|
|
165116
|
+
}
|
|
165117
|
+
} catch {
|
|
165118
|
+
}
|
|
165119
|
+
if (standardHeader && normalizedHeader === standardHeader)
|
|
165120
|
+
return response;
|
|
165121
|
+
const headers2 = new Headers(response.headers);
|
|
165122
|
+
headers2.set("PAYMENT-REQUIRED", normalizedHeader);
|
|
165123
|
+
return responseWithHeaders(response, headers2);
|
|
164966
165124
|
}
|
|
164967
165125
|
const text = await response.clone().text();
|
|
164968
165126
|
let parsed;
|
|
@@ -164974,7 +165132,9 @@ var withSynthesizedX402Header = (baseFetch) => async (input, init) => {
|
|
|
164974
165132
|
if (!looksLikeX402Body(parsed) || parsed.x402Version === 1) {
|
|
164975
165133
|
return response;
|
|
164976
165134
|
}
|
|
164977
|
-
const challenge2 =
|
|
165135
|
+
const challenge2 = normalizeX402ChallengeVersion(
|
|
165136
|
+
parsed
|
|
165137
|
+
);
|
|
164978
165138
|
const headers = new Headers(response.headers);
|
|
164979
165139
|
headers.set(
|
|
164980
165140
|
"PAYMENT-REQUIRED",
|
|
@@ -164991,6 +165151,154 @@ var withSynthesizedX402Header = (baseFetch) => async (input, init) => {
|
|
|
164991
165151
|
headers
|
|
164992
165152
|
});
|
|
164993
165153
|
};
|
|
165154
|
+
var USDC_BASE2 = "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913";
|
|
165155
|
+
var USDC_BASE_SEPOLIA = "0x036cbd53842c5426634e7929541ec2318f3dcf7e";
|
|
165156
|
+
var UINT_RE = /^[0-9]+$/;
|
|
165157
|
+
var EVM_ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;
|
|
165158
|
+
var MAX_AMOUNT_DIGITS = 30;
|
|
165159
|
+
var X402_ACCEPT_SCHEMA = external_exports3.object({
|
|
165160
|
+
scheme: external_exports3.string().optional(),
|
|
165161
|
+
network: external_exports3.string().optional(),
|
|
165162
|
+
asset: external_exports3.string().optional(),
|
|
165163
|
+
amount: external_exports3.unknown().optional(),
|
|
165164
|
+
maxAmountRequired: external_exports3.unknown().optional(),
|
|
165165
|
+
payTo: external_exports3.unknown().optional(),
|
|
165166
|
+
maxTimeoutSeconds: external_exports3.unknown().optional(),
|
|
165167
|
+
extra: external_exports3.unknown().optional()
|
|
165168
|
+
}).passthrough();
|
|
165169
|
+
var X402_EXTRA_SCHEMA = external_exports3.object({ assetTransferMethod: external_exports3.unknown().optional() }).passthrough();
|
|
165170
|
+
var SUPPORTED_NETWORKS = {
|
|
165171
|
+
base: { chain: "base", asset: USDC_BASE2, version: 1 },
|
|
165172
|
+
"base-sepolia": {
|
|
165173
|
+
chain: "base-sepolia",
|
|
165174
|
+
asset: USDC_BASE_SEPOLIA,
|
|
165175
|
+
version: 1
|
|
165176
|
+
},
|
|
165177
|
+
"eip155:8453": { chain: "base", asset: USDC_BASE2, version: 2 },
|
|
165178
|
+
"eip155:84532": {
|
|
165179
|
+
chain: "base-sepolia",
|
|
165180
|
+
asset: USDC_BASE_SEPOLIA,
|
|
165181
|
+
version: 2
|
|
165182
|
+
}
|
|
165183
|
+
};
|
|
165184
|
+
var reject = (reason, detail) => ({ settleable: false, reason, detail });
|
|
165185
|
+
var classifyX402Requirement = (candidate, x402Version2) => {
|
|
165186
|
+
if (x402Version2 !== void 0 && x402Version2 !== 1 && x402Version2 !== 2) {
|
|
165187
|
+
return reject(
|
|
165188
|
+
"unsupported_version",
|
|
165189
|
+
`x402 version ${String(x402Version2)} is not supported`
|
|
165190
|
+
);
|
|
165191
|
+
}
|
|
165192
|
+
const parsed = X402_ACCEPT_SCHEMA.safeParse(candidate);
|
|
165193
|
+
if (!parsed.success) {
|
|
165194
|
+
return reject("malformed_accept", "accept is not a valid object");
|
|
165195
|
+
}
|
|
165196
|
+
const accept = parsed.data;
|
|
165197
|
+
if (accept.scheme === void 0) {
|
|
165198
|
+
return reject("malformed_accept", "accept.scheme is required");
|
|
165199
|
+
}
|
|
165200
|
+
const scheme = accept.scheme;
|
|
165201
|
+
if (scheme !== "exact") {
|
|
165202
|
+
return reject(
|
|
165203
|
+
"unsupported_scheme",
|
|
165204
|
+
`scheme ${JSON.stringify(scheme)} is not supported`
|
|
165205
|
+
);
|
|
165206
|
+
}
|
|
165207
|
+
const network = accept.network?.toLowerCase();
|
|
165208
|
+
const supportedNetwork = network ? SUPPORTED_NETWORKS[network] : void 0;
|
|
165209
|
+
if (!supportedNetwork) {
|
|
165210
|
+
return reject(
|
|
165211
|
+
"unsupported_network",
|
|
165212
|
+
`network ${JSON.stringify(accept.network)} is not supported`
|
|
165213
|
+
);
|
|
165214
|
+
}
|
|
165215
|
+
const effectiveVersion = x402Version2 ?? supportedNetwork.version;
|
|
165216
|
+
if (supportedNetwork.version !== effectiveVersion) {
|
|
165217
|
+
return reject(
|
|
165218
|
+
"network_version_mismatch",
|
|
165219
|
+
`network ${accept.network} uses the x402 v${supportedNetwork.version} shape, not v${effectiveVersion}`
|
|
165220
|
+
);
|
|
165221
|
+
}
|
|
165222
|
+
if (accept.asset?.toLowerCase() !== supportedNetwork.asset.toLowerCase()) {
|
|
165223
|
+
return reject(
|
|
165224
|
+
"unsupported_asset",
|
|
165225
|
+
`asset ${JSON.stringify(accept.asset)} is not USDC on ${supportedNetwork.chain}`
|
|
165226
|
+
);
|
|
165227
|
+
}
|
|
165228
|
+
let transferMethod = "eip3009";
|
|
165229
|
+
if (accept.extra !== void 0) {
|
|
165230
|
+
const parsedExtra = X402_EXTRA_SCHEMA.safeParse(accept.extra);
|
|
165231
|
+
if (!parsedExtra.success) {
|
|
165232
|
+
return reject("malformed_accept", "accept.extra is not an object");
|
|
165233
|
+
}
|
|
165234
|
+
transferMethod = parsedExtra.data.assetTransferMethod ?? transferMethod;
|
|
165235
|
+
}
|
|
165236
|
+
if (transferMethod !== "eip3009" && transferMethod !== "permit2") {
|
|
165237
|
+
return reject(
|
|
165238
|
+
"unsupported_transfer_method",
|
|
165239
|
+
`transfer method ${JSON.stringify(transferMethod)} is not supported`
|
|
165240
|
+
);
|
|
165241
|
+
}
|
|
165242
|
+
if (effectiveVersion === 1 && transferMethod === "permit2") {
|
|
165243
|
+
return reject(
|
|
165244
|
+
"unsupported_transfer_method",
|
|
165245
|
+
"Permit2 is only supported by the x402 v2 EVM client"
|
|
165246
|
+
);
|
|
165247
|
+
}
|
|
165248
|
+
const amount2 = effectiveVersion === 1 ? accept.maxAmountRequired : accept.amount;
|
|
165249
|
+
if (amount2 === void 0) {
|
|
165250
|
+
return reject(
|
|
165251
|
+
"missing_amount",
|
|
165252
|
+
`x402 v${effectiveVersion} accept has no ${effectiveVersion === 1 ? "maxAmountRequired" : "amount"}`
|
|
165253
|
+
);
|
|
165254
|
+
}
|
|
165255
|
+
if (typeof amount2 !== "string" || amount2.length > MAX_AMOUNT_DIGITS || !UINT_RE.test(amount2)) {
|
|
165256
|
+
return reject(
|
|
165257
|
+
"invalid_amount",
|
|
165258
|
+
"payment amount must be a bounded unsigned integer string"
|
|
165259
|
+
);
|
|
165260
|
+
}
|
|
165261
|
+
if (typeof accept.payTo !== "string" || !EVM_ADDRESS_RE.test(accept.payTo)) {
|
|
165262
|
+
return reject("invalid_recipient", "accept.payTo must be an EVM address");
|
|
165263
|
+
}
|
|
165264
|
+
if (typeof accept.maxTimeoutSeconds !== "number" || !Number.isInteger(accept.maxTimeoutSeconds) || accept.maxTimeoutSeconds <= 0) {
|
|
165265
|
+
return reject(
|
|
165266
|
+
"invalid_timeout",
|
|
165267
|
+
"accept.maxTimeoutSeconds must be a positive integer"
|
|
165268
|
+
);
|
|
165269
|
+
}
|
|
165270
|
+
return {
|
|
165271
|
+
settleable: true,
|
|
165272
|
+
chain: supportedNetwork.chain,
|
|
165273
|
+
transferMethod,
|
|
165274
|
+
x402Version: effectiveVersion,
|
|
165275
|
+
amount: amount2
|
|
165276
|
+
};
|
|
165277
|
+
};
|
|
165278
|
+
var selectSettleableX402Requirement = (accepts, preselected, x402Version2) => {
|
|
165279
|
+
const settleable = (accepts ?? []).filter(
|
|
165280
|
+
(accept) => classifyX402Requirement(accept, x402Version2).settleable
|
|
165281
|
+
);
|
|
165282
|
+
if (settleable.length === 0) return null;
|
|
165283
|
+
return settleable.find((accept) => {
|
|
165284
|
+
const classification = classifyX402Requirement(accept, x402Version2);
|
|
165285
|
+
return classification.settleable && classification.chain === "base";
|
|
165286
|
+
}) ?? settleable[0] ?? null;
|
|
165287
|
+
};
|
|
165288
|
+
var describeX402Accepts = (accepts, x402Version2) => (accepts ?? []).map((candidate) => {
|
|
165289
|
+
const parsed = X402_ACCEPT_SCHEMA.safeParse(candidate);
|
|
165290
|
+
const classification = classifyX402Requirement(candidate, x402Version2);
|
|
165291
|
+
if (!parsed.success) {
|
|
165292
|
+
return `malformed (${classification.settleable ? "unexpectedly settleable" : classification.detail})`;
|
|
165293
|
+
}
|
|
165294
|
+
const accept = parsed.data;
|
|
165295
|
+
const extra = X402_EXTRA_SCHEMA.safeParse(accept.extra);
|
|
165296
|
+
const transferMethod = extra.success ? extra.data.assetTransferMethod : void 0;
|
|
165297
|
+
const shape2 = `${accept.scheme ?? "?"}/${accept.network ?? "?"}/${accept.asset ?? "?"}/${typeof transferMethod === "string" ? transferMethod : "eip3009"}`;
|
|
165298
|
+
return classification.settleable ? shape2 : `${shape2} (${classification.reason})`;
|
|
165299
|
+
}).join(", ") || "(none)";
|
|
165300
|
+
var USDC_BASE3 = "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913";
|
|
165301
|
+
var USDC_BASE_SEPOLIA2 = "0x036cbd53842c5426634e7929541ec2318f3dcf7e";
|
|
164994
165302
|
var NETWORK_TO_CHAIN = {
|
|
164995
165303
|
base: "base",
|
|
164996
165304
|
"base-sepolia": "base-sepolia",
|
|
@@ -165003,12 +165311,11 @@ var networkToChain = (network) => {
|
|
|
165003
165311
|
return NETWORK_TO_CHAIN[normalized] ?? "unknown";
|
|
165004
165312
|
};
|
|
165005
165313
|
var MAX_PAY_RE = /^[0-9]+(\.[0-9]{1,6})?$/;
|
|
165006
|
-
var
|
|
165007
|
-
var
|
|
165314
|
+
var UINT_RE2 = /^[0-9]+$/;
|
|
165315
|
+
var MAX_AMOUNT_DIGITS2 = 30;
|
|
165008
165316
|
var JIT_REVERSE_FEE_MARGIN = 50000n;
|
|
165009
165317
|
var BRIDGE_FILL_POLL_INTERVAL_MS = 2e3;
|
|
165010
165318
|
var BRIDGE_FILL_TIMEOUT_MS = 9e4;
|
|
165011
|
-
var USDC_BASE2 = "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913";
|
|
165012
165319
|
var USDC_TEMPO2 = "0x20c000000000000000000000b9537d11c60e8b50";
|
|
165013
165320
|
var PATHUSD_TEMPO = "0x20c0000000000000000000000000000000000000";
|
|
165014
165321
|
var BASE_CHAIN_ID = 8453;
|
|
@@ -165053,7 +165360,7 @@ var resolveDefaultPrefund = (displayCostAmount) => {
|
|
|
165053
165360
|
const bounded = scaled < floor ? floor : scaled > ceiling ? ceiling : scaled;
|
|
165054
165361
|
return bounded.toFixed(6).replace(/\.?0+$/, "");
|
|
165055
165362
|
};
|
|
165056
|
-
var isUintString = (v) => typeof v === "string" && v.length > 0 && v.length <=
|
|
165363
|
+
var isUintString = (v) => typeof v === "string" && v.length > 0 && v.length <= MAX_AMOUNT_DIGITS2 && UINT_RE2.test(v);
|
|
165057
165364
|
var buildTempoPaymentMethods = (parameters) => [
|
|
165058
165365
|
tempo2(parameters),
|
|
165059
165366
|
tempo2.sessionLegacy.method(parameters)
|
|
@@ -165152,11 +165459,11 @@ var raceWithSignal = (p, signal, client) => {
|
|
|
165152
165459
|
});
|
|
165153
165460
|
return Promise.reject(new DOMException("Aborted", "AbortError"));
|
|
165154
165461
|
}
|
|
165155
|
-
return new Promise((resolve7,
|
|
165462
|
+
return new Promise((resolve7, reject2) => {
|
|
165156
165463
|
let settled = false;
|
|
165157
165464
|
const onAbort = () => {
|
|
165158
165465
|
settled = true;
|
|
165159
|
-
|
|
165466
|
+
reject2(new DOMException("Aborted", "AbortError"));
|
|
165160
165467
|
};
|
|
165161
165468
|
signal.addEventListener("abort", onAbort, { once: true });
|
|
165162
165469
|
p.then(
|
|
@@ -165177,7 +165484,7 @@ var raceWithSignal = (p, signal, client) => {
|
|
|
165177
165484
|
return;
|
|
165178
165485
|
}
|
|
165179
165486
|
settled = true;
|
|
165180
|
-
|
|
165487
|
+
reject2(e);
|
|
165181
165488
|
}
|
|
165182
165489
|
);
|
|
165183
165490
|
});
|
|
@@ -165201,6 +165508,8 @@ var resolveAccount = async (client, overrideAccount, signal, walletAddress) => {
|
|
|
165201
165508
|
"payments.pay() requires either a client constructed with `account` or a per-call `account` override."
|
|
165202
165509
|
);
|
|
165203
165510
|
};
|
|
165511
|
+
var measureDiagnostic = (diagnostics, stage, work) => diagnostics ? diagnostics.measure(stage, work) : work();
|
|
165512
|
+
var isMppProofChallenge = (challenge2) => challenge2.intent === "proof" || challenge2.intent === "charge" && challenge2.request.amount === "0";
|
|
165204
165513
|
var validateMaxPay = (maxPay) => {
|
|
165205
165514
|
const normalized = maxPay?.trim();
|
|
165206
165515
|
if (normalized === void 0) return null;
|
|
@@ -165233,44 +165542,83 @@ var Payments = class {
|
|
|
165233
165542
|
* on the detected 402 protocol.
|
|
165234
165543
|
*/
|
|
165235
165544
|
pay = async (input) => {
|
|
165236
|
-
|
|
165237
|
-
|
|
165238
|
-
|
|
165239
|
-
input.
|
|
165240
|
-
|
|
165241
|
-
input.
|
|
165242
|
-
|
|
165545
|
+
input.diagnostics?.setPaymentMode("charge");
|
|
165546
|
+
let maxPayUnits;
|
|
165547
|
+
try {
|
|
165548
|
+
maxPayUnits = validateMaxPay(input.maxPay);
|
|
165549
|
+
} catch (error98) {
|
|
165550
|
+
input.diagnostics?.fail(
|
|
165551
|
+
"rail_select",
|
|
165552
|
+
FETCH_DIAGNOSTIC_CODES.invalidMaxPay
|
|
165553
|
+
);
|
|
165554
|
+
throw error98;
|
|
165555
|
+
}
|
|
165556
|
+
let account;
|
|
165557
|
+
try {
|
|
165558
|
+
account = await measureDiagnostic(
|
|
165559
|
+
input.diagnostics,
|
|
165560
|
+
"wallet_resolve",
|
|
165561
|
+
() => resolveAccount(
|
|
165562
|
+
this.client,
|
|
165563
|
+
input.account,
|
|
165564
|
+
input.signal,
|
|
165565
|
+
input.walletAddress
|
|
165566
|
+
)
|
|
165567
|
+
);
|
|
165568
|
+
} catch (error98) {
|
|
165569
|
+
input.diagnostics?.fail(
|
|
165570
|
+
"wallet_resolve",
|
|
165571
|
+
FETCH_DIAGNOSTIC_CODES.walletResolutionFailed
|
|
165572
|
+
);
|
|
165573
|
+
throw error98;
|
|
165574
|
+
}
|
|
165243
165575
|
let capturedAmount = null;
|
|
165244
165576
|
let pendingAmountUnits = 0n;
|
|
165245
165577
|
let identityChallengeHandled = false;
|
|
165246
165578
|
let paidChallengeHandled = false;
|
|
165247
165579
|
let capturedNetwork;
|
|
165248
165580
|
let preflightError = null;
|
|
165249
|
-
const x4022 = registerExactEvmScheme(
|
|
165581
|
+
const x4022 = registerExactEvmScheme(
|
|
165582
|
+
new x402Client((x402Version2, requirements) => {
|
|
165583
|
+
const selected = selectSettleableX402Requirement(
|
|
165584
|
+
requirements,
|
|
165585
|
+
void 0,
|
|
165586
|
+
x402Version2
|
|
165587
|
+
);
|
|
165588
|
+
if (selected) return selected;
|
|
165589
|
+
const fallback2 = requirements[0];
|
|
165590
|
+
if (!fallback2) {
|
|
165591
|
+
throw new Error(
|
|
165592
|
+
"x402 challenge has no registered payment requirements"
|
|
165593
|
+
);
|
|
165594
|
+
}
|
|
165595
|
+
return fallback2;
|
|
165596
|
+
}),
|
|
165597
|
+
{ signer: account }
|
|
165598
|
+
);
|
|
165250
165599
|
x4022.onBeforePaymentCreation(async (context) => {
|
|
165251
|
-
const
|
|
165252
|
-
|
|
165253
|
-
|
|
165254
|
-
|
|
165255
|
-
|
|
165256
|
-
|
|
165257
|
-
|
|
165600
|
+
const requirement = context.selectedRequirements;
|
|
165601
|
+
const classification = classifyX402Requirement(
|
|
165602
|
+
requirement,
|
|
165603
|
+
context.paymentRequired.x402Version
|
|
165604
|
+
);
|
|
165605
|
+
if (!classification.settleable) {
|
|
165606
|
+
input.diagnostics?.fail(
|
|
165607
|
+
"rail_select",
|
|
165608
|
+
FETCH_DIAGNOSTIC_CODES.unsupportedPaymentRail
|
|
165609
|
+
);
|
|
165258
165610
|
return {
|
|
165259
165611
|
abort: true,
|
|
165260
|
-
reason:
|
|
165612
|
+
reason: `x402 challenge has no rail this wallet can settle \u2014 offered [${describeX402Accepts(context.paymentRequired.accepts, context.paymentRequired.x402Version)}], supported: USDC exact (EIP-3009 or Permit2) on base / base-sepolia`
|
|
165261
165613
|
};
|
|
165262
165614
|
}
|
|
165615
|
+
const filled = withKnownEip712Domain(
|
|
165616
|
+
requirement.asset,
|
|
165617
|
+
requirement.extra
|
|
165618
|
+
);
|
|
165619
|
+
if (filled) requirement.extra = filled;
|
|
165263
165620
|
capturedNetwork = requirement.network;
|
|
165264
|
-
const rawAmount =
|
|
165265
|
-
if (!rawAmount) {
|
|
165266
|
-
return { abort: true, reason: "x402 requirement had no amount field" };
|
|
165267
|
-
}
|
|
165268
|
-
if (rawAmount.length > MAX_AMOUNT_DIGITS || !UINT_RE.test(rawAmount)) {
|
|
165269
|
-
return {
|
|
165270
|
-
abort: true,
|
|
165271
|
-
reason: `x402 requirement amount is not an unsigned integer string: ${JSON.stringify(rawAmount)}`
|
|
165272
|
-
};
|
|
165273
|
-
}
|
|
165621
|
+
const rawAmount = classification.amount;
|
|
165274
165622
|
const rawAmountUnits = BigInt(rawAmount);
|
|
165275
165623
|
pendingAmountUnits = rawAmountUnits;
|
|
165276
165624
|
const challengeAmount = formatUnits(rawAmountUnits, 6);
|
|
@@ -165288,6 +165636,10 @@ var Payments = class {
|
|
|
165288
165636
|
};
|
|
165289
165637
|
}
|
|
165290
165638
|
if (maxPayUnits !== null && rawAmountUnits > maxPayUnits) {
|
|
165639
|
+
input.diagnostics?.fail(
|
|
165640
|
+
"rail_select",
|
|
165641
|
+
FETCH_DIAGNOSTIC_CODES.maxPayExceeded
|
|
165642
|
+
);
|
|
165291
165643
|
return {
|
|
165292
165644
|
abort: true,
|
|
165293
165645
|
reason: `Payment of ${challengeAmount} USDC exceeds maxPay ${input.maxPay}`
|
|
@@ -165297,8 +165649,16 @@ var Payments = class {
|
|
|
165297
165649
|
const balanceChain = detected === "base-sepolia" ? "base-sepolia" : "base";
|
|
165298
165650
|
let balance = null;
|
|
165299
165651
|
try {
|
|
165300
|
-
balance = await
|
|
165652
|
+
balance = await measureDiagnostic(
|
|
165653
|
+
input.diagnostics,
|
|
165654
|
+
"balance_check",
|
|
165655
|
+
() => this.readUsdcBalance(account.address, balanceChain)
|
|
165656
|
+
);
|
|
165301
165657
|
} catch (readErr) {
|
|
165658
|
+
input.diagnostics?.issue(
|
|
165659
|
+
"balance_check",
|
|
165660
|
+
FETCH_DIAGNOSTIC_CODES.balanceCheckFailed
|
|
165661
|
+
);
|
|
165302
165662
|
this.client.logger?.({
|
|
165303
165663
|
level: "warn",
|
|
165304
165664
|
message: "Pre-flight balance read failed; proceeding to attempt payment",
|
|
@@ -165309,7 +165669,12 @@ var Payments = class {
|
|
|
165309
165669
|
});
|
|
165310
165670
|
}
|
|
165311
165671
|
if (balance !== null && balance < rawAmountUnits) {
|
|
165312
|
-
if (balanceChain === "base" && await
|
|
165672
|
+
if (!input.preferMppOnX402Shortfall && balanceChain === "base" && await measureDiagnostic(
|
|
165673
|
+
input.diagnostics,
|
|
165674
|
+
"bridge",
|
|
165675
|
+
() => this.tryJitReverseBridge(account, rawAmountUnits, balance)
|
|
165676
|
+
)) {
|
|
165677
|
+
input.diagnostics?.setFundingSource("jit_bridge");
|
|
165313
165678
|
return;
|
|
165314
165679
|
}
|
|
165315
165680
|
const have = formatUnits(balance, 6);
|
|
@@ -165320,6 +165685,9 @@ var Payments = class {
|
|
|
165320
165685
|
);
|
|
165321
165686
|
return { abort: true, reason: preflightError.message };
|
|
165322
165687
|
}
|
|
165688
|
+
input.diagnostics?.setFundingSource(
|
|
165689
|
+
balance === null ? "unknown" : rawAmountUnits === 0n ? "not_required" : "wallet_balance"
|
|
165690
|
+
);
|
|
165323
165691
|
});
|
|
165324
165692
|
const configuredFetch = buildConfiguredFetch(this.client, {
|
|
165325
165693
|
timeoutMs: input.timeoutMs
|
|
@@ -165366,7 +165734,19 @@ var Payments = class {
|
|
|
165366
165734
|
}
|
|
165367
165735
|
}
|
|
165368
165736
|
pendingAmountUnits = 0n;
|
|
165369
|
-
const paymentPayload = await
|
|
165737
|
+
const paymentPayload = await measureDiagnostic(
|
|
165738
|
+
input.diagnostics,
|
|
165739
|
+
"credential_sign",
|
|
165740
|
+
() => x4022.createPaymentPayload(paymentRequired2)
|
|
165741
|
+
).catch((error98) => {
|
|
165742
|
+
if (!preflightError) {
|
|
165743
|
+
input.diagnostics?.fail(
|
|
165744
|
+
"credential_sign",
|
|
165745
|
+
FETCH_DIAGNOSTIC_CODES.credentialSignFailed
|
|
165746
|
+
);
|
|
165747
|
+
}
|
|
165748
|
+
throw error98;
|
|
165749
|
+
});
|
|
165370
165750
|
if (pendingAmountUnits === 0n) {
|
|
165371
165751
|
identityChallengeHandled = true;
|
|
165372
165752
|
capturedAmount = "0";
|
|
@@ -165383,10 +165763,34 @@ var Payments = class {
|
|
|
165383
165763
|
"Access-Control-Expose-Headers",
|
|
165384
165764
|
"PAYMENT-RESPONSE,X-PAYMENT-RESPONSE"
|
|
165385
165765
|
);
|
|
165386
|
-
response = await
|
|
165766
|
+
response = await measureDiagnostic(
|
|
165767
|
+
input.diagnostics,
|
|
165768
|
+
"paid_replay",
|
|
165769
|
+
() => paymentFetch(paidRequest)
|
|
165770
|
+
).catch((error98) => {
|
|
165771
|
+
input.diagnostics?.fail(
|
|
165772
|
+
"paid_replay",
|
|
165773
|
+
isCallerAbortError(error98) ? FETCH_DIAGNOSTIC_CODES.callerAborted : FETCH_DIAGNOSTIC_CODES.paidReplayFailed
|
|
165774
|
+
);
|
|
165775
|
+
throw error98;
|
|
165776
|
+
});
|
|
165387
165777
|
}
|
|
165388
165778
|
} catch (err) {
|
|
165389
|
-
if (preflightError)
|
|
165779
|
+
if (preflightError) {
|
|
165780
|
+
if (!input.preferMppOnX402Shortfall) {
|
|
165781
|
+
input.diagnostics?.fail(
|
|
165782
|
+
"balance_check",
|
|
165783
|
+
FETCH_DIAGNOSTIC_CODES.insufficientFunds
|
|
165784
|
+
);
|
|
165785
|
+
}
|
|
165786
|
+
throw preflightError;
|
|
165787
|
+
}
|
|
165788
|
+
if (input.diagnostics?.snapshot().failureStage === null) {
|
|
165789
|
+
input.diagnostics.fail(
|
|
165790
|
+
"paid_replay",
|
|
165791
|
+
FETCH_DIAGNOSTIC_CODES.paymentFailed
|
|
165792
|
+
);
|
|
165793
|
+
}
|
|
165390
165794
|
if (err instanceof ZeroError) throw err;
|
|
165391
165795
|
throw new ZeroPaymentError(
|
|
165392
165796
|
`x402 payment failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
@@ -165405,6 +165809,10 @@ var Payments = class {
|
|
|
165405
165809
|
capturedNetwork = settlement.network;
|
|
165406
165810
|
}
|
|
165407
165811
|
} catch {
|
|
165812
|
+
input.diagnostics?.issue(
|
|
165813
|
+
"settlement_receipt",
|
|
165814
|
+
FETCH_DIAGNOSTIC_CODES.settlementReceiptInvalid
|
|
165815
|
+
);
|
|
165408
165816
|
}
|
|
165409
165817
|
}
|
|
165410
165818
|
const amount2 = capturedAmount ?? "unknown";
|
|
@@ -165433,16 +165841,52 @@ var Payments = class {
|
|
|
165433
165841
|
* carrying the orphaned channel for out-of-band reconciliation.
|
|
165434
165842
|
*/
|
|
165435
165843
|
payMpp = async (input) => {
|
|
165436
|
-
|
|
165437
|
-
|
|
165438
|
-
|
|
165439
|
-
|
|
165440
|
-
input.
|
|
165441
|
-
|
|
165442
|
-
|
|
165844
|
+
let maxPayUnits;
|
|
165845
|
+
try {
|
|
165846
|
+
maxPayUnits = validateMaxPay(input.maxPay);
|
|
165847
|
+
} catch (error98) {
|
|
165848
|
+
input.diagnostics?.fail(
|
|
165849
|
+
"rail_select",
|
|
165850
|
+
FETCH_DIAGNOSTIC_CODES.invalidMaxPay
|
|
165851
|
+
);
|
|
165852
|
+
throw error98;
|
|
165853
|
+
}
|
|
165854
|
+
let account;
|
|
165855
|
+
try {
|
|
165856
|
+
account = await measureDiagnostic(
|
|
165857
|
+
input.diagnostics,
|
|
165858
|
+
"wallet_resolve",
|
|
165859
|
+
() => resolveAccount(
|
|
165860
|
+
this.client,
|
|
165861
|
+
input.account,
|
|
165862
|
+
input.signal,
|
|
165863
|
+
input.walletAddress
|
|
165864
|
+
)
|
|
165865
|
+
);
|
|
165866
|
+
} catch (error98) {
|
|
165867
|
+
input.diagnostics?.fail(
|
|
165868
|
+
"wallet_resolve",
|
|
165869
|
+
FETCH_DIAGNOSTIC_CODES.walletResolutionFailed
|
|
165870
|
+
);
|
|
165871
|
+
throw error98;
|
|
165872
|
+
}
|
|
165443
165873
|
const configuredFetch = buildConfiguredFetch(this.client, {
|
|
165444
165874
|
timeoutMs: input.timeoutMs
|
|
165445
165875
|
});
|
|
165876
|
+
const mppFetch = async (request22, init) => {
|
|
165877
|
+
const response2 = await configuredFetch(request22, init);
|
|
165878
|
+
if (response2.status !== 402 || !response2.headers.has("payment-required") && !response2.headers.has("x-payment-required")) {
|
|
165879
|
+
return response2;
|
|
165880
|
+
}
|
|
165881
|
+
const headers = new Headers(response2.headers);
|
|
165882
|
+
headers.delete("payment-required");
|
|
165883
|
+
headers.delete("x-payment-required");
|
|
165884
|
+
return new Response(response2.body, {
|
|
165885
|
+
status: response2.status,
|
|
165886
|
+
statusText: response2.statusText,
|
|
165887
|
+
headers
|
|
165888
|
+
});
|
|
165889
|
+
};
|
|
165446
165890
|
let capturedAmount = "unknown";
|
|
165447
165891
|
let capturedChallenge;
|
|
165448
165892
|
let channelEntry;
|
|
@@ -165473,7 +165917,8 @@ var Payments = class {
|
|
|
165473
165917
|
// escrow-less emit can't blank an open channel's escrow.
|
|
165474
165918
|
escrowContract: entry.escrow ?? entry.escrowContract ?? channelEntry?.escrowContract ?? "0x0000000000000000000000000000000000000000",
|
|
165475
165919
|
cumulativeAmount: cumulative,
|
|
165476
|
-
opened: wasOpened || entry.opened
|
|
165920
|
+
opened: wasOpened || entry.opened,
|
|
165921
|
+
descriptor: entry.descriptor ?? channelEntry?.descriptor
|
|
165477
165922
|
};
|
|
165478
165923
|
};
|
|
165479
165924
|
const tempoMethodParams = {
|
|
@@ -165483,29 +165928,68 @@ var Payments = class {
|
|
|
165483
165928
|
};
|
|
165484
165929
|
const mppx = Mppx_exports.create({
|
|
165485
165930
|
polyfill: false,
|
|
165486
|
-
fetch:
|
|
165931
|
+
fetch: mppFetch,
|
|
165487
165932
|
methods: buildTempoPaymentMethods(tempoMethodParams),
|
|
165488
|
-
onChallenge: async (challenge2) => {
|
|
165933
|
+
onChallenge: async (challenge2, { createCredential }) => {
|
|
165489
165934
|
capturedChallenge = challenge2;
|
|
165490
|
-
|
|
165491
|
-
|
|
165492
|
-
challenge2,
|
|
165493
|
-
maxPayUnits,
|
|
165494
|
-
input.displayCostAmount
|
|
165935
|
+
input.diagnostics?.setPaymentMode(
|
|
165936
|
+
challenge2.intent === "session" ? "session" : isMppProofChallenge(challenge2) ? "proof" : challenge2.intent === "charge" ? "charge" : "unknown"
|
|
165495
165937
|
);
|
|
165938
|
+
capturedAmount = await measureDiagnostic(
|
|
165939
|
+
input.diagnostics,
|
|
165940
|
+
"balance_check",
|
|
165941
|
+
() => this.prepareTempoFunds(
|
|
165942
|
+
account,
|
|
165943
|
+
challenge2,
|
|
165944
|
+
maxPayUnits,
|
|
165945
|
+
input.displayCostAmount,
|
|
165946
|
+
input.diagnostics
|
|
165947
|
+
)
|
|
165948
|
+
).catch((error98) => {
|
|
165949
|
+
if (input.diagnostics?.snapshot().failureStage === null) {
|
|
165950
|
+
input.diagnostics.fail(
|
|
165951
|
+
"balance_check",
|
|
165952
|
+
FETCH_DIAGNOSTIC_CODES.balanceCheckFailed
|
|
165953
|
+
);
|
|
165954
|
+
}
|
|
165955
|
+
throw error98;
|
|
165956
|
+
});
|
|
165957
|
+
if (challenge2.intent === "session") {
|
|
165958
|
+
return measureDiagnostic(
|
|
165959
|
+
input.diagnostics,
|
|
165960
|
+
"credential_sign",
|
|
165961
|
+
() => createCredential({
|
|
165962
|
+
depositRaw: parseUnits(capturedAmount, 6).toString()
|
|
165963
|
+
})
|
|
165964
|
+
).catch((error98) => {
|
|
165965
|
+
input.diagnostics?.fail(
|
|
165966
|
+
"credential_sign",
|
|
165967
|
+
FETCH_DIAGNOSTIC_CODES.credentialSignFailed
|
|
165968
|
+
);
|
|
165969
|
+
throw error98;
|
|
165970
|
+
});
|
|
165971
|
+
}
|
|
165496
165972
|
return void 0;
|
|
165497
165973
|
}
|
|
165498
165974
|
});
|
|
165499
165975
|
let response;
|
|
165500
165976
|
try {
|
|
165501
|
-
response = await
|
|
165502
|
-
|
|
165503
|
-
|
|
165504
|
-
|
|
165505
|
-
|
|
165506
|
-
|
|
165977
|
+
response = await measureDiagnostic(
|
|
165978
|
+
input.diagnostics,
|
|
165979
|
+
"paid_replay",
|
|
165980
|
+
() => mppx.fetch(input.url, {
|
|
165981
|
+
method: input.method ?? "GET",
|
|
165982
|
+
headers: input.headers,
|
|
165983
|
+
body: input.body,
|
|
165984
|
+
signal: input.signal
|
|
165985
|
+
})
|
|
165986
|
+
);
|
|
165507
165987
|
} catch (err) {
|
|
165508
165988
|
if (channelEntry?.opened) {
|
|
165989
|
+
input.diagnostics?.fail(
|
|
165990
|
+
"session_close",
|
|
165991
|
+
FETCH_DIAGNOSTIC_CODES.sessionCloseFailed
|
|
165992
|
+
);
|
|
165509
165993
|
throw this.buildOrphanError(
|
|
165510
165994
|
channelEntry,
|
|
165511
165995
|
capturedChallenge,
|
|
@@ -165515,6 +165999,12 @@ var Payments = class {
|
|
|
165515
165999
|
err
|
|
165516
166000
|
);
|
|
165517
166001
|
}
|
|
166002
|
+
if (input.diagnostics?.snapshot().failureStage === null) {
|
|
166003
|
+
input.diagnostics.fail(
|
|
166004
|
+
"paid_replay",
|
|
166005
|
+
isCallerAbortError(err) ? FETCH_DIAGNOSTIC_CODES.callerAborted : FETCH_DIAGNOSTIC_CODES.paidReplayFailed
|
|
166006
|
+
);
|
|
166007
|
+
}
|
|
165518
166008
|
if (err instanceof ZeroError) throw err;
|
|
165519
166009
|
throw new ZeroPaymentError(
|
|
165520
166010
|
`MPP payment failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
@@ -165532,7 +166022,8 @@ var Payments = class {
|
|
|
165532
166022
|
capturedAmount,
|
|
165533
166023
|
mppx,
|
|
165534
166024
|
signal: input.signal,
|
|
165535
|
-
configuredFetch
|
|
166025
|
+
configuredFetch,
|
|
166026
|
+
diagnostics: input.diagnostics
|
|
165536
166027
|
});
|
|
165537
166028
|
}
|
|
165538
166029
|
const sdkWarnings = [];
|
|
@@ -165544,15 +166035,21 @@ var Payments = class {
|
|
|
165544
166035
|
sdkWarnings.push(FETCH_WARNINGS.sessionOpenUnobserved);
|
|
165545
166036
|
}
|
|
165546
166037
|
let txHash = null;
|
|
165547
|
-
|
|
165548
|
-
|
|
165549
|
-
|
|
165550
|
-
|
|
165551
|
-
|
|
165552
|
-
|
|
165553
|
-
|
|
165554
|
-
|
|
165555
|
-
|
|
166038
|
+
if (capturedChallenge && !isMppProofChallenge(capturedChallenge)) {
|
|
166039
|
+
try {
|
|
166040
|
+
const receipt = Receipt_exports.fromResponse(response);
|
|
166041
|
+
txHash = receipt.reference ?? null;
|
|
166042
|
+
} catch (err) {
|
|
166043
|
+
input.diagnostics?.issue(
|
|
166044
|
+
"settlement_receipt",
|
|
166045
|
+
FETCH_DIAGNOSTIC_CODES.settlementReceiptInvalid
|
|
166046
|
+
);
|
|
166047
|
+
this.client.logger?.({
|
|
166048
|
+
level: "warn",
|
|
166049
|
+
message: "Failed to parse MPP charge receipt; txHash unknown",
|
|
166050
|
+
meta: { error: err instanceof Error ? err.message : String(err) }
|
|
166051
|
+
});
|
|
166052
|
+
}
|
|
165556
166053
|
}
|
|
165557
166054
|
return {
|
|
165558
166055
|
response,
|
|
@@ -165593,7 +166090,7 @@ var Payments = class {
|
|
|
165593
166090
|
cause
|
|
165594
166091
|
});
|
|
165595
166092
|
};
|
|
165596
|
-
prepareTempoFunds = async (account, challenge2, maxPayUnits, displayCostAmount) => {
|
|
166093
|
+
prepareTempoFunds = async (account, challenge2, maxPayUnits, displayCostAmount, diagnostics) => {
|
|
165597
166094
|
const challengeRequest = challenge2.request;
|
|
165598
166095
|
let requiredRaw;
|
|
165599
166096
|
if (challenge2.intent === "session") {
|
|
@@ -165607,7 +166104,11 @@ var Payments = class {
|
|
|
165607
166104
|
}
|
|
165608
166105
|
} else {
|
|
165609
166106
|
const rawAmount = challengeRequest.amount;
|
|
165610
|
-
if (typeof rawAmount !== "string" || rawAmount.length >
|
|
166107
|
+
if (typeof rawAmount !== "string" || rawAmount.length > MAX_AMOUNT_DIGITS2 || !UINT_RE2.test(rawAmount)) {
|
|
166108
|
+
diagnostics?.fail(
|
|
166109
|
+
"challenge_decode",
|
|
166110
|
+
FETCH_DIAGNOSTIC_CODES.challengeDecodeFailed
|
|
166111
|
+
);
|
|
165611
166112
|
throw new ZeroPaymentError(
|
|
165612
166113
|
`MPP charge challenge amount is not an unsigned integer string: ${JSON.stringify(rawAmount)}`
|
|
165613
166114
|
);
|
|
@@ -165615,11 +166116,13 @@ var Payments = class {
|
|
|
165615
166116
|
requiredRaw = BigInt(rawAmount);
|
|
165616
166117
|
}
|
|
165617
166118
|
if (challenge2.intent === "session" && requiredRaw === 0n) {
|
|
166119
|
+
diagnostics?.fail("rail_select", FETCH_DIAGNOSTIC_CODES.maxPayExceeded);
|
|
165618
166120
|
throw new ZeroPaymentError(
|
|
165619
166121
|
"This capability opens an MPP payment channel that needs a positive deposit; maxPay='0' cannot fund it. Pass a small cap (e.g. '0.05') to size the channel."
|
|
165620
166122
|
);
|
|
165621
166123
|
}
|
|
165622
166124
|
if (maxPayUnits !== null && requiredRaw > maxPayUnits) {
|
|
166125
|
+
diagnostics?.fail("rail_select", FETCH_DIAGNOSTIC_CODES.maxPayExceeded);
|
|
165623
166126
|
throw new ZeroPaymentError(
|
|
165624
166127
|
`Payment of ${formatUnits(requiredRaw, 6)} USDC exceeds maxPay ${formatUnits(maxPayUnits, 6)}`
|
|
165625
166128
|
);
|
|
@@ -165630,6 +166133,10 @@ var Payments = class {
|
|
|
165630
166133
|
challengeRequest.chainId ?? methodDetails?.chainId
|
|
165631
166134
|
);
|
|
165632
166135
|
if (!coerced) {
|
|
166136
|
+
diagnostics?.fail(
|
|
166137
|
+
"rail_select",
|
|
166138
|
+
FETCH_DIAGNOSTIC_CODES.unsupportedPaymentRail
|
|
166139
|
+
);
|
|
165633
166140
|
throw new ZeroPaymentError(
|
|
165634
166141
|
`MPP challenge has missing or unsupported chainId (expected ${TEMPO_CHAIN_ID2} or ${TEMPO_TESTNET_CHAIN_ID})`
|
|
165635
166142
|
);
|
|
@@ -165641,15 +166148,38 @@ var Payments = class {
|
|
|
165641
166148
|
if (tempoBalance < requiredRaw) {
|
|
165642
166149
|
if (coerced.chain === "tempo-testnet") {
|
|
165643
166150
|
const have = formatUnits(tempoBalance, 6);
|
|
166151
|
+
diagnostics?.fail(
|
|
166152
|
+
"balance_check",
|
|
166153
|
+
FETCH_DIAGNOSTIC_CODES.insufficientFunds
|
|
166154
|
+
);
|
|
165644
166155
|
throw new ZeroInsufficientFundsError(
|
|
165645
166156
|
`Insufficient pathUSD on Tempo testnet: have ${have}, need ${capturedAmount}. Fund via the Tempo testnet faucet: https://docs.tempo.xyz/quickstart/faucet`,
|
|
165646
166157
|
{ have, need: capturedAmount }
|
|
165647
166158
|
);
|
|
165648
166159
|
}
|
|
165649
|
-
await
|
|
165650
|
-
|
|
165651
|
-
|
|
166160
|
+
await measureDiagnostic(
|
|
166161
|
+
diagnostics,
|
|
166162
|
+
"bridge",
|
|
166163
|
+
() => this.bridgeBaseToTempo(account, requiredRaw - tempoBalance, {
|
|
166164
|
+
isSessionDeposit: challenge2.intent === "session",
|
|
166165
|
+
depositTotal: capturedAmount
|
|
166166
|
+
})
|
|
166167
|
+
).catch((error98) => {
|
|
166168
|
+
if (error98 instanceof ZeroInsufficientFundsError) {
|
|
166169
|
+
diagnostics?.fail(
|
|
166170
|
+
"balance_check",
|
|
166171
|
+
FETCH_DIAGNOSTIC_CODES.insufficientFunds
|
|
166172
|
+
);
|
|
166173
|
+
} else {
|
|
166174
|
+
diagnostics?.fail("bridge", FETCH_DIAGNOSTIC_CODES.bridgeFailed);
|
|
166175
|
+
}
|
|
166176
|
+
throw error98;
|
|
165652
166177
|
});
|
|
166178
|
+
diagnostics?.setFundingSource("jit_bridge");
|
|
166179
|
+
} else {
|
|
166180
|
+
diagnostics?.setFundingSource(
|
|
166181
|
+
requiredRaw === 0n ? "not_required" : "wallet_balance"
|
|
166182
|
+
);
|
|
165653
166183
|
}
|
|
165654
166184
|
return capturedAmount;
|
|
165655
166185
|
};
|
|
@@ -165698,7 +166228,7 @@ var Payments = class {
|
|
|
165698
166228
|
const quote = await getClient().actions.getQuote({
|
|
165699
166229
|
chainId: BASE_CHAIN_ID,
|
|
165700
166230
|
toChainId: TEMPO_CHAIN_ID2,
|
|
165701
|
-
currency:
|
|
166231
|
+
currency: USDC_BASE3,
|
|
165702
166232
|
toCurrency: USDC_TEMPO2,
|
|
165703
166233
|
amount: bridgeAmount.toString(),
|
|
165704
166234
|
tradeType: "EXACT_INPUT",
|
|
@@ -165792,11 +166322,11 @@ var Payments = class {
|
|
|
165792
166322
|
const { viemChain, token } = (() => {
|
|
165793
166323
|
switch (chain2) {
|
|
165794
166324
|
case "base":
|
|
165795
|
-
return { viemChain: base, token:
|
|
166325
|
+
return { viemChain: base, token: USDC_BASE3 };
|
|
165796
166326
|
case "base-sepolia":
|
|
165797
166327
|
return {
|
|
165798
166328
|
viemChain: baseSepolia,
|
|
165799
|
-
token:
|
|
166329
|
+
token: USDC_BASE_SEPOLIA2
|
|
165800
166330
|
};
|
|
165801
166331
|
case "tempo":
|
|
165802
166332
|
return { viemChain: tempoChain2, token: USDC_TEMPO2 };
|
|
@@ -165830,7 +166360,8 @@ var Payments = class {
|
|
|
165830
166360
|
capturedAmount,
|
|
165831
166361
|
mppx,
|
|
165832
166362
|
signal,
|
|
165833
|
-
configuredFetch
|
|
166363
|
+
configuredFetch,
|
|
166364
|
+
diagnostics
|
|
165834
166365
|
} = params;
|
|
165835
166366
|
const challengeRequest = challenge2.request;
|
|
165836
166367
|
const recipientRaw = challengeRequest.recipient;
|
|
@@ -165851,11 +166382,19 @@ var Payments = class {
|
|
|
165851
166382
|
void 0
|
|
165852
166383
|
);
|
|
165853
166384
|
if (!recipient || !challengeEscrow) {
|
|
166385
|
+
diagnostics?.fail(
|
|
166386
|
+
"session_close",
|
|
166387
|
+
FETCH_DIAGNOSTIC_CODES.sessionCloseFailed
|
|
166388
|
+
);
|
|
165854
166389
|
throw buildOrphanFromChannelEntry(
|
|
165855
166390
|
`MPP session challenge has missing or malformed recipient/escrowContract; channel ${channelId} is open and requires reconciliation.`
|
|
165856
166391
|
);
|
|
165857
166392
|
}
|
|
165858
166393
|
if (!coercedChainId) {
|
|
166394
|
+
diagnostics?.fail(
|
|
166395
|
+
"session_close",
|
|
166396
|
+
FETCH_DIAGNOSTIC_CODES.sessionCloseFailed
|
|
166397
|
+
);
|
|
165859
166398
|
throw buildOrphanFromChannelEntry(
|
|
165860
166399
|
`MPP session challenge has unsupported chainId (expected ${TEMPO_CHAIN_ID2} or ${TEMPO_TESTNET_CHAIN_ID}); channel ${channelId} is open and requires reconciliation.`
|
|
165861
166400
|
);
|
|
@@ -165880,6 +166419,10 @@ var Payments = class {
|
|
|
165880
166419
|
cause
|
|
165881
166420
|
});
|
|
165882
166421
|
if (closeAmount === 0n && !isMeteredZeroReceipt(receipt)) {
|
|
166422
|
+
diagnostics?.fail(
|
|
166423
|
+
"session_close",
|
|
166424
|
+
FETCH_DIAGNOSTIC_CODES.sessionCloseFailed
|
|
166425
|
+
);
|
|
165883
166426
|
throw closeFailed(
|
|
165884
166427
|
`Refusing to sign zero close credential for channel ${channelId} \u2014 neither receipt nor channelEntry produced a nonzero cumulativeAmount. Query escrow directly to recover; check logger for an earlier 'non-bigint cumulativeAmount' warning.`
|
|
165885
166428
|
);
|
|
@@ -165890,16 +166433,31 @@ var Payments = class {
|
|
|
165890
166433
|
});
|
|
165891
166434
|
let closeCredential;
|
|
165892
166435
|
try {
|
|
165893
|
-
closeCredential = await
|
|
165894
|
-
|
|
165895
|
-
|
|
165896
|
-
|
|
165897
|
-
|
|
165898
|
-
|
|
165899
|
-
|
|
165900
|
-
|
|
166436
|
+
closeCredential = await measureDiagnostic(
|
|
166437
|
+
diagnostics,
|
|
166438
|
+
"credential_sign",
|
|
166439
|
+
() => raceWithSignal(
|
|
166440
|
+
mppx.createCredential(closeChallengeResponse, {
|
|
166441
|
+
action: "close",
|
|
166442
|
+
channelId,
|
|
166443
|
+
cumulativeAmountRaw: closeAmount.toString(),
|
|
166444
|
+
...channelEntry.descriptor && {
|
|
166445
|
+
descriptor: channelEntry.descriptor
|
|
166446
|
+
}
|
|
166447
|
+
}),
|
|
166448
|
+
signal,
|
|
166449
|
+
this.client
|
|
166450
|
+
)
|
|
165901
166451
|
);
|
|
165902
166452
|
} catch (err) {
|
|
166453
|
+
diagnostics?.issue(
|
|
166454
|
+
"credential_sign",
|
|
166455
|
+
FETCH_DIAGNOSTIC_CODES.credentialSignFailed
|
|
166456
|
+
);
|
|
166457
|
+
diagnostics?.fail(
|
|
166458
|
+
"session_close",
|
|
166459
|
+
FETCH_DIAGNOSTIC_CODES.sessionCloseFailed
|
|
166460
|
+
);
|
|
165903
166461
|
throw closeFailed(
|
|
165904
166462
|
`Session close credential build failed for channel ${channelId}: ${err instanceof Error ? err.message : String(err)}`,
|
|
165905
166463
|
err
|
|
@@ -165907,18 +166465,30 @@ var Payments = class {
|
|
|
165907
166465
|
}
|
|
165908
166466
|
let closeResponse;
|
|
165909
166467
|
try {
|
|
165910
|
-
closeResponse = await
|
|
165911
|
-
|
|
165912
|
-
|
|
165913
|
-
|
|
165914
|
-
|
|
166468
|
+
closeResponse = await measureDiagnostic(
|
|
166469
|
+
diagnostics,
|
|
166470
|
+
"session_close",
|
|
166471
|
+
() => configuredFetch(url4, {
|
|
166472
|
+
method: method.toUpperCase(),
|
|
166473
|
+
headers: { authorization: closeCredential },
|
|
166474
|
+
signal
|
|
166475
|
+
})
|
|
166476
|
+
);
|
|
165915
166477
|
} catch (err) {
|
|
166478
|
+
diagnostics?.fail(
|
|
166479
|
+
"session_close",
|
|
166480
|
+
FETCH_DIAGNOSTIC_CODES.sessionCloseFailed
|
|
166481
|
+
);
|
|
165916
166482
|
throw closeFailed(
|
|
165917
166483
|
`Session close request failed for channel ${channelId}: ${err instanceof Error ? err.message : String(err)}`,
|
|
165918
166484
|
err
|
|
165919
166485
|
);
|
|
165920
166486
|
}
|
|
165921
166487
|
if (!closeResponse.ok) {
|
|
166488
|
+
diagnostics?.fail(
|
|
166489
|
+
"session_close",
|
|
166490
|
+
FETCH_DIAGNOSTIC_CODES.sessionCloseFailed
|
|
166491
|
+
);
|
|
165922
166492
|
const errBody = await Promise.race([
|
|
165923
166493
|
closeResponse.text().catch(() => ""),
|
|
165924
166494
|
new Promise((resolve7) => {
|
|
@@ -165932,6 +166502,12 @@ var Payments = class {
|
|
|
165932
166502
|
);
|
|
165933
166503
|
}
|
|
165934
166504
|
const closeReceipt = readSessionReceipt(closeResponse);
|
|
166505
|
+
if (!closeReceipt) {
|
|
166506
|
+
diagnostics?.issue(
|
|
166507
|
+
"settlement_receipt",
|
|
166508
|
+
FETCH_DIAGNOSTIC_CODES.settlementReceiptInvalid
|
|
166509
|
+
);
|
|
166510
|
+
}
|
|
165935
166511
|
cancelBody(closeResponse);
|
|
165936
166512
|
const rawCloseTx = closeReceipt?.txHash;
|
|
165937
166513
|
const closeTxHash = typeof rawCloseTx === "string" && /^0x[0-9a-fA-F]+$/.test(rawCloseTx) ? rawCloseTx : null;
|
|
@@ -165941,7 +166517,11 @@ var Payments = class {
|
|
|
165941
166517
|
protocol: "mpp",
|
|
165942
166518
|
chain: this.tempoChainLabel(challenge2),
|
|
165943
166519
|
txHash: closeTxHash,
|
|
165944
|
-
|
|
166520
|
+
// `capturedAmount` is the channel prefund, not the amount the
|
|
166521
|
+
// seller ultimately claimed. Once close succeeds, report the
|
|
166522
|
+
// cumulative amount authorized by the close voucher so callers and
|
|
166523
|
+
// run accounting do not mistake refundable liquidity for spend.
|
|
166524
|
+
amount: formatUnits(closeAmount, 6),
|
|
165945
166525
|
asset: "USDC",
|
|
165946
166526
|
session: {
|
|
165947
166527
|
channelId,
|
|
@@ -166000,10 +166580,28 @@ var splitWwwAuthenticateChallenges = (header) => {
|
|
|
166000
166580
|
return chunks;
|
|
166001
166581
|
};
|
|
166002
166582
|
var isTextContentType = (contentType) => {
|
|
166003
|
-
if (!contentType) return
|
|
166583
|
+
if (!contentType) return false;
|
|
166004
166584
|
const lower = contentType.toLowerCase();
|
|
166005
166585
|
return TEXT_CONTENT_TYPES.some((marker) => lower.includes(marker));
|
|
166006
166586
|
};
|
|
166587
|
+
var isProbablyText = (bytes) => {
|
|
166588
|
+
if (bytes.byteLength === 0) return true;
|
|
166589
|
+
const sample = bytes.subarray(0, Math.min(bytes.byteLength, 64 * 1024));
|
|
166590
|
+
let controls = 0;
|
|
166591
|
+
for (const byte of sample) {
|
|
166592
|
+
if (byte === 0) return false;
|
|
166593
|
+
if (byte < 32 && byte !== 9 && byte !== 10 && byte !== 13) {
|
|
166594
|
+
controls++;
|
|
166595
|
+
}
|
|
166596
|
+
}
|
|
166597
|
+
if (controls > Math.max(1, Math.floor(sample.byteLength / 100))) return false;
|
|
166598
|
+
try {
|
|
166599
|
+
new TextDecoder("utf-8", { fatal: true }).decode(sample);
|
|
166600
|
+
return true;
|
|
166601
|
+
} catch {
|
|
166602
|
+
return false;
|
|
166603
|
+
}
|
|
166604
|
+
};
|
|
166007
166605
|
var redactUrl2 = (url4) => {
|
|
166008
166606
|
try {
|
|
166009
166607
|
const u = new URL(url4);
|
|
@@ -166046,6 +166644,22 @@ var detectPaymentRequirement = async (response, preferredProtocol) => {
|
|
|
166046
166644
|
cancelBody2(response);
|
|
166047
166645
|
return advertisesMpp ? { protocol: "mpp", raw: { "www-authenticate": wwwAuth } } : { protocol: "unknown", raw: { requestedProtocol: "mpp" } };
|
|
166048
166646
|
}
|
|
166647
|
+
const canSettleX402 = (raw) => {
|
|
166648
|
+
if (!raw || typeof raw !== "object") return false;
|
|
166649
|
+
const normalized = normalizeX402ChallengeVersion(
|
|
166650
|
+
raw
|
|
166651
|
+
);
|
|
166652
|
+
const accepts = normalized.accepts;
|
|
166653
|
+
if (!Array.isArray(accepts)) return false;
|
|
166654
|
+
const x402Version2 = typeof normalized.x402Version === "number" ? normalized.x402Version : void 0;
|
|
166655
|
+
return selectSettleableX402Requirement(accepts, void 0, x402Version2) !== null;
|
|
166656
|
+
};
|
|
166657
|
+
const preferMppFallback = (raw) => preferredProtocol === void 0 && advertisesMpp && !canSettleX402(raw);
|
|
166658
|
+
const selectedX402 = (raw) => ({
|
|
166659
|
+
protocol: "x402",
|
|
166660
|
+
raw,
|
|
166661
|
+
...preferredProtocol === void 0 && advertisesMpp ? { fallbackProtocol: "mpp" } : {}
|
|
166662
|
+
});
|
|
166049
166663
|
const x402Header = response.headers.get("payment-required") ?? response.headers.get("x-payment-required");
|
|
166050
166664
|
if (x402Header) {
|
|
166051
166665
|
cancelBody2(response);
|
|
@@ -166053,9 +166667,15 @@ var detectPaymentRequirement = async (response, preferredProtocol) => {
|
|
|
166053
166667
|
const decoded = JSON.parse(
|
|
166054
166668
|
Buffer.from(x402Header, "base64").toString("utf8")
|
|
166055
166669
|
);
|
|
166056
|
-
|
|
166670
|
+
if (preferMppFallback(decoded)) {
|
|
166671
|
+
return { protocol: "mpp", raw: { "www-authenticate": wwwAuth } };
|
|
166672
|
+
}
|
|
166673
|
+
return selectedX402(decoded);
|
|
166057
166674
|
} catch {
|
|
166058
|
-
|
|
166675
|
+
if (preferredProtocol === void 0 && advertisesMpp) {
|
|
166676
|
+
return { protocol: "mpp", raw: { "www-authenticate": wwwAuth } };
|
|
166677
|
+
}
|
|
166678
|
+
return selectedX402({ encoded: x402Header });
|
|
166059
166679
|
}
|
|
166060
166680
|
}
|
|
166061
166681
|
const declaredLen = Number.parseInt(
|
|
@@ -166069,7 +166689,13 @@ var detectPaymentRequirement = async (response, preferredProtocol) => {
|
|
|
166069
166689
|
if (text) {
|
|
166070
166690
|
const parsed = JSON.parse(text);
|
|
166071
166691
|
if (looksLikeX402Body(parsed)) {
|
|
166072
|
-
|
|
166692
|
+
if (preferMppFallback(parsed)) {
|
|
166693
|
+
return {
|
|
166694
|
+
protocol: "mpp",
|
|
166695
|
+
raw: { "www-authenticate": wwwAuth }
|
|
166696
|
+
};
|
|
166697
|
+
}
|
|
166698
|
+
return selectedX402(parsed);
|
|
166073
166699
|
}
|
|
166074
166700
|
}
|
|
166075
166701
|
} catch {
|
|
@@ -166125,7 +166751,8 @@ var parseResponseBody = async (response, max) => {
|
|
|
166125
166751
|
const truncated = bytes.byteLength > max;
|
|
166126
166752
|
const view = truncated ? bytes.subarray(0, max) : bytes;
|
|
166127
166753
|
const buf = Buffer.from(view.buffer, view.byteOffset, view.byteLength);
|
|
166128
|
-
|
|
166754
|
+
const textResponse = contentType ? isTextContentType(contentType) : isProbablyText(view);
|
|
166755
|
+
if (!textResponse) {
|
|
166129
166756
|
const base645 = buf.toString("base64");
|
|
166130
166757
|
return {
|
|
166131
166758
|
body: base645,
|
|
@@ -166184,6 +166811,27 @@ var extractUpstreamErrorMessage = (body) => {
|
|
|
166184
166811
|
}
|
|
166185
166812
|
return void 0;
|
|
166186
166813
|
};
|
|
166814
|
+
var SUCCESS_PAYLOAD_FIELDS = [
|
|
166815
|
+
"data",
|
|
166816
|
+
"result",
|
|
166817
|
+
"results",
|
|
166818
|
+
"output",
|
|
166819
|
+
"content",
|
|
166820
|
+
"items",
|
|
166821
|
+
"url",
|
|
166822
|
+
"audio_url",
|
|
166823
|
+
"image_url",
|
|
166824
|
+
"video_url"
|
|
166825
|
+
];
|
|
166826
|
+
var hasErrorShapedBody = (body) => {
|
|
166827
|
+
if (!body || typeof body !== "object" || Array.isArray(body)) return false;
|
|
166828
|
+
const record3 = body;
|
|
166829
|
+
if (record3.ok === false || record3.success === false) return true;
|
|
166830
|
+
const error98 = record3.error;
|
|
166831
|
+
const hasError = typeof error98 === "string" && error98.trim().length > 0 || error98 === true || typeof error98 === "object" && error98 !== null;
|
|
166832
|
+
if (!hasError) return false;
|
|
166833
|
+
return !SUCCESS_PAYLOAD_FIELDS.some((field) => record3[field] != null);
|
|
166834
|
+
};
|
|
166187
166835
|
var extractFieldName = (message2) => {
|
|
166188
166836
|
const patterns = [
|
|
166189
166837
|
/(?:field|param(?:eter)?|property|key)[:\s]+["'`]?([a-z0-9_.[\]-]+)["'`]?/i,
|
|
@@ -166254,8 +166902,8 @@ var computeFixHint = (status, message2, bodyRaw) => {
|
|
|
166254
166902
|
}
|
|
166255
166903
|
return void 0;
|
|
166256
166904
|
};
|
|
166257
|
-
var buildUpstreamError = (status, bodyRaw, bodyEncoding) => {
|
|
166258
|
-
if (status >= 200 && status < 300) return void 0;
|
|
166905
|
+
var buildUpstreamError = (status, bodyRaw, bodyEncoding, errorShapedSuccess = false) => {
|
|
166906
|
+
if (status >= 200 && status < 300 && !errorShapedSuccess) return void 0;
|
|
166259
166907
|
if (bodyRaw === null || bodyRaw.length === 0) return void 0;
|
|
166260
166908
|
if (bodyEncoding === "base64") return void 0;
|
|
166261
166909
|
const snippet = bodyRaw.slice(0, ERROR_SNIPPET_BYTES);
|
|
@@ -166269,11 +166917,12 @@ var buildUpstreamError = (status, bodyRaw, bodyEncoding) => {
|
|
|
166269
166917
|
...fixHint && { fixHint }
|
|
166270
166918
|
};
|
|
166271
166919
|
};
|
|
166272
|
-
var computeOutcome = (status, payment, warnings) => {
|
|
166920
|
+
var computeOutcome = (status, payment, warnings, errorShapedSuccess = false) => {
|
|
166273
166921
|
if (warnings.includes(FETCH_WARNINGS.mppSessionCloseFailed))
|
|
166274
166922
|
return "payment_close_failed";
|
|
166275
166923
|
if (status === 402 && payment !== null) return "payment_rejected";
|
|
166276
166924
|
if (status === 402) return "payment_failed";
|
|
166925
|
+
if (errorShapedSuccess) return "server_error";
|
|
166277
166926
|
if (status >= 400) return "server_error";
|
|
166278
166927
|
return "success";
|
|
166279
166928
|
};
|
|
@@ -166293,9 +166942,10 @@ var errorFetchResult = (fetchId, startedAt, error98, skipReason, capabilityIdReq
|
|
|
166293
166942
|
if (capabilityIdRequested) result.runTrackingSkipped = [skipReason];
|
|
166294
166943
|
return result;
|
|
166295
166944
|
};
|
|
166296
|
-
var settlementFields = (payment) => {
|
|
166945
|
+
var settlementFields = (payment, paymentMode) => {
|
|
166297
166946
|
if (payment === null) return {};
|
|
166298
166947
|
const knownAmount = payment.amount !== "unknown";
|
|
166948
|
+
const mode = paymentMode && paymentMode !== "unknown" ? paymentMode : payment.session ? "session" : "charge";
|
|
166299
166949
|
return {
|
|
166300
166950
|
...knownAmount && {
|
|
166301
166951
|
costAmount: payment.amount,
|
|
@@ -166304,7 +166954,8 @@ var settlementFields = (payment) => {
|
|
|
166304
166954
|
paymentProtocol: payment.protocol,
|
|
166305
166955
|
paymentChain: payment.chain,
|
|
166306
166956
|
paymentTxHash: payment.txHash ?? void 0,
|
|
166307
|
-
paymentMode:
|
|
166957
|
+
paymentMode: mode,
|
|
166958
|
+
...payment.session && { paymentSession: payment.session }
|
|
166308
166959
|
};
|
|
166309
166960
|
};
|
|
166310
166961
|
var resolveRecordingClient = (client, opts) => {
|
|
@@ -166313,7 +166964,7 @@ var resolveRecordingClient = (client, opts) => {
|
|
|
166313
166964
|
const canRecord = opts.account !== void 0 || credentials.kind === "account" || credentials.kind === "session";
|
|
166314
166965
|
return { recordingClient, canRecord };
|
|
166315
166966
|
};
|
|
166316
|
-
var recordErrorFetchRun = async (client, opts, result, capabilityIdOverride, requestUrl, requestMethod) => {
|
|
166967
|
+
var recordErrorFetchRun = async (client, opts, result, diagnostics, capabilityIdOverride, requestUrl, requestMethod) => {
|
|
166317
166968
|
const effectiveCapId = capabilityIdOverride ?? opts.capabilityId;
|
|
166318
166969
|
const urlTarget = requestUrl ? {
|
|
166319
166970
|
requestUrl: redactUrl2(requestUrl),
|
|
@@ -166325,27 +166976,60 @@ var recordErrorFetchRun = async (client, opts, result, capabilityIdOverride, req
|
|
|
166325
166976
|
if (!canRecord) return;
|
|
166326
166977
|
const fetchOriginForRecord = opts.capabilityId === void 0 ? "direct_url" : effectiveCapId !== void 0 && isShortToken(effectiveCapId) ? "from_search" : opts.fetchOrigin;
|
|
166327
166978
|
try {
|
|
166328
|
-
const created = await
|
|
166329
|
-
|
|
166330
|
-
|
|
166331
|
-
|
|
166332
|
-
|
|
166333
|
-
|
|
166334
|
-
|
|
166335
|
-
|
|
166336
|
-
|
|
166337
|
-
|
|
166338
|
-
|
|
166339
|
-
|
|
166340
|
-
|
|
166341
|
-
|
|
166342
|
-
|
|
166979
|
+
const created = await diagnostics.measure(
|
|
166980
|
+
"run_record",
|
|
166981
|
+
() => recordingClient.runs.create({
|
|
166982
|
+
...runTarget,
|
|
166983
|
+
fetchId: result.fetchId,
|
|
166984
|
+
...opts.searchId && { searchId: opts.searchId },
|
|
166985
|
+
...fetchOriginForRecord && { fetchOrigin: fetchOriginForRecord },
|
|
166986
|
+
...result.status !== null && { status: result.status },
|
|
166987
|
+
// The SDK's verdict. HTTP status alone can't say "the capability
|
|
166988
|
+
// answered 200 but the caller got nothing" — outcome can.
|
|
166989
|
+
outcome: result.outcome,
|
|
166990
|
+
latencyMs: result.latencyMs,
|
|
166991
|
+
settlementState: settlementStateFor(
|
|
166992
|
+
result.payment,
|
|
166993
|
+
result.warnings,
|
|
166994
|
+
diagnostics.snapshot()
|
|
166995
|
+
),
|
|
166996
|
+
failureStage: diagnostics.snapshot().failureStage ?? void 0,
|
|
166997
|
+
failureCode: diagnostics.snapshot().failureCode ?? void 0,
|
|
166998
|
+
paymentProtocol: diagnostics.snapshot().paymentProtocol ?? void 0,
|
|
166999
|
+
paymentMode: diagnostics.snapshot().paymentMode ?? void 0,
|
|
167000
|
+
fundingSource: diagnostics.snapshot().fundingSource ?? void 0,
|
|
167001
|
+
stageDurationsMs: diagnostics.snapshot().stageDurationsMs,
|
|
167002
|
+
warningCodes: result.warnings,
|
|
167003
|
+
// Carry the settlement when the failure happened AFTER we paid.
|
|
167004
|
+
...settlementFields(result.payment, diagnostics.snapshot().paymentMode),
|
|
167005
|
+
...opts.requestSchema && { requestSchema: opts.requestSchema },
|
|
167006
|
+
...opts.walletAddress && !opts.account && { walletAddress: opts.walletAddress }
|
|
167007
|
+
})
|
|
167008
|
+
);
|
|
166343
167009
|
result.runId = created.runId;
|
|
166344
167010
|
delete result.runTrackingSkipped;
|
|
166345
|
-
} catch {
|
|
167011
|
+
} catch (err) {
|
|
167012
|
+
diagnostics.issue("run_record", FETCH_DIAGNOSTIC_CODES.runCreateFailed);
|
|
167013
|
+
const errorMessage2 = err instanceof Error ? err.message : String(err);
|
|
167014
|
+
const code = err instanceof ZeroError ? err.code : void 0;
|
|
167015
|
+
const skipReason = code ? `run_create_failed:${code}: ${errorMessage2}` : `run_create_failed: ${errorMessage2}`;
|
|
167016
|
+
result.runTrackingSkipped = [
|
|
167017
|
+
...result.runTrackingSkipped ?? [],
|
|
167018
|
+
skipReason
|
|
167019
|
+
];
|
|
167020
|
+
client.logger?.({
|
|
167021
|
+
level: "warn",
|
|
167022
|
+
message: "Failed to record error-path run for fetch",
|
|
167023
|
+
meta: {
|
|
167024
|
+
fetchId: result.fetchId,
|
|
167025
|
+
stage: "run_record",
|
|
167026
|
+
errorCode: code,
|
|
167027
|
+
error: errorMessage2
|
|
167028
|
+
}
|
|
167029
|
+
});
|
|
166346
167030
|
}
|
|
166347
167031
|
};
|
|
166348
|
-
var recordTimeoutRun = async (client, opts, fetchId, err, startedAt, capabilityIdRequested, capabilityIdOverride, requestUrl, requestMethod) => {
|
|
167032
|
+
var recordTimeoutRun = async (client, opts, fetchId, err, startedAt, capabilityIdRequested, diagnostics, capabilityIdOverride, requestUrl, requestMethod) => {
|
|
166349
167033
|
const result = errorFetchResult(
|
|
166350
167034
|
fetchId,
|
|
166351
167035
|
startedAt,
|
|
@@ -166358,6 +167042,7 @@ var recordTimeoutRun = async (client, opts, fetchId, err, startedAt, capabilityI
|
|
|
166358
167042
|
client,
|
|
166359
167043
|
opts,
|
|
166360
167044
|
result,
|
|
167045
|
+
diagnostics,
|
|
166361
167046
|
capabilityIdOverride,
|
|
166362
167047
|
requestUrl,
|
|
166363
167048
|
requestMethod
|
|
@@ -166386,9 +167071,9 @@ var withDefaultContentType = (headers, body) => {
|
|
|
166386
167071
|
}
|
|
166387
167072
|
return next;
|
|
166388
167073
|
};
|
|
166389
|
-
var clientFetch = async (client, url4, opts = {}) => {
|
|
167074
|
+
var clientFetch = async (client, url4, opts = {}, diagnostics) => {
|
|
166390
167075
|
const startedAt = Date.now();
|
|
166391
|
-
const fetchId =
|
|
167076
|
+
const fetchId = diagnostics.fetchId;
|
|
166392
167077
|
const capabilityIdRequested = opts.capabilityId !== void 0;
|
|
166393
167078
|
const normalized = normalizeTransportEnvelopeRequest(url4, {
|
|
166394
167079
|
method: opts.method,
|
|
@@ -166401,7 +167086,16 @@ var clientFetch = async (client, url4, opts = {}) => {
|
|
|
166401
167086
|
client,
|
|
166402
167087
|
opts
|
|
166403
167088
|
);
|
|
166404
|
-
const resolvePromise = !capabilityIdRequested && canRecordForResolve ?
|
|
167089
|
+
const resolvePromise = !capabilityIdRequested && canRecordForResolve ? diagnostics.measure(
|
|
167090
|
+
"resolve_target",
|
|
167091
|
+
() => client.capabilities.resolveByUrl(redactUrl2(requestUrl), method)
|
|
167092
|
+
).catch(() => {
|
|
167093
|
+
diagnostics.issue(
|
|
167094
|
+
"resolve_target",
|
|
167095
|
+
FETCH_DIAGNOSTIC_CODES.capabilityResolutionFailed
|
|
167096
|
+
);
|
|
167097
|
+
return null;
|
|
167098
|
+
}) : Promise.resolve(null);
|
|
166405
167099
|
const probeHeaders = withDefaultContentType(opts.headers, requestBody);
|
|
166406
167100
|
const requestInit = {
|
|
166407
167101
|
method,
|
|
@@ -166414,12 +167108,17 @@ var clientFetch = async (client, url4, opts = {}) => {
|
|
|
166414
167108
|
});
|
|
166415
167109
|
let response;
|
|
166416
167110
|
let payment = null;
|
|
167111
|
+
let paymentCloseError;
|
|
166417
167112
|
const skipReasons = [];
|
|
166418
167113
|
const warnings = [];
|
|
166419
167114
|
try {
|
|
166420
|
-
response = await
|
|
167115
|
+
response = await diagnostics.measure(
|
|
167116
|
+
"probe",
|
|
167117
|
+
() => configuredFetch(requestUrl, requestInit)
|
|
167118
|
+
);
|
|
166421
167119
|
} catch (err) {
|
|
166422
167120
|
if (err instanceof ZeroTimeoutError) {
|
|
167121
|
+
diagnostics.fail("probe", FETCH_DIAGNOSTIC_CODES.probeTimeout);
|
|
166423
167122
|
await recordTimeoutRun(
|
|
166424
167123
|
client,
|
|
166425
167124
|
opts,
|
|
@@ -166427,12 +167126,14 @@ var clientFetch = async (client, url4, opts = {}) => {
|
|
|
166427
167126
|
err,
|
|
166428
167127
|
startedAt,
|
|
166429
167128
|
capabilityIdRequested,
|
|
167129
|
+
diagnostics,
|
|
166430
167130
|
void 0,
|
|
166431
167131
|
requestUrl,
|
|
166432
167132
|
method
|
|
166433
167133
|
);
|
|
166434
167134
|
throw err;
|
|
166435
167135
|
}
|
|
167136
|
+
diagnostics.fail("probe", FETCH_DIAGNOSTIC_CODES.probeNetworkError);
|
|
166436
167137
|
if (err instanceof ZeroError) throw err;
|
|
166437
167138
|
const errMessage = err instanceof Error ? err.message : String(err);
|
|
166438
167139
|
const result2 = errorFetchResult(
|
|
@@ -166447,6 +167148,7 @@ var clientFetch = async (client, url4, opts = {}) => {
|
|
|
166447
167148
|
client,
|
|
166448
167149
|
opts,
|
|
166449
167150
|
result2,
|
|
167151
|
+
diagnostics,
|
|
166450
167152
|
void 0,
|
|
166451
167153
|
requestUrl,
|
|
166452
167154
|
method
|
|
@@ -166454,14 +167156,21 @@ var clientFetch = async (client, url4, opts = {}) => {
|
|
|
166454
167156
|
return result2;
|
|
166455
167157
|
}
|
|
166456
167158
|
if (response.status === 402) {
|
|
166457
|
-
const requirement = await
|
|
166458
|
-
|
|
166459
|
-
opts.paymentProtocol
|
|
166460
|
-
)
|
|
167159
|
+
const requirement = await diagnostics.measure(
|
|
167160
|
+
"challenge_decode",
|
|
167161
|
+
() => detectPaymentRequirement(response, opts.paymentProtocol)
|
|
167162
|
+
).catch((error98) => {
|
|
167163
|
+
diagnostics.fail(
|
|
167164
|
+
"challenge_decode",
|
|
167165
|
+
FETCH_DIAGNOSTIC_CODES.challengeDecodeFailed
|
|
167166
|
+
);
|
|
167167
|
+
throw error98;
|
|
167168
|
+
});
|
|
166461
167169
|
if (requirement?.protocol === "x402" || requirement?.protocol === "mpp") {
|
|
167170
|
+
diagnostics.selectPaymentProtocol(requirement.protocol);
|
|
166462
167171
|
const payCall = requirement.protocol === "x402" ? client.payments.pay : client.payments.payMpp;
|
|
166463
167172
|
try {
|
|
166464
|
-
const
|
|
167173
|
+
const paymentInput = {
|
|
166465
167174
|
url: requestUrl,
|
|
166466
167175
|
method,
|
|
166467
167176
|
// Fresh clone for the paid retry — same rationale as
|
|
@@ -166476,13 +167185,39 @@ var clientFetch = async (client, url4, opts = {}) => {
|
|
|
166476
167185
|
timeoutMs: opts.timeoutMs,
|
|
166477
167186
|
...opts.displayCostAmount && {
|
|
166478
167187
|
displayCostAmount: opts.displayCostAmount
|
|
167188
|
+
},
|
|
167189
|
+
// Internal correlation/stage recorder shared with the payment
|
|
167190
|
+
// namespace. Never serialized onto the wire.
|
|
167191
|
+
diagnostics,
|
|
167192
|
+
// A default-selected dual offer should use its already-funded MPP
|
|
167193
|
+
// rail before moving Tempo funds back to Base for x402. Explicit
|
|
167194
|
+
// paymentProtocol="x402" calls retain the JIT-bridge behavior.
|
|
167195
|
+
preferMppOnX402Shortfall: requirement.protocol === "x402" && requirement.fallbackProtocol === "mpp"
|
|
167196
|
+
};
|
|
167197
|
+
let paid;
|
|
167198
|
+
try {
|
|
167199
|
+
paid = await payCall(paymentInput);
|
|
167200
|
+
} catch (error98) {
|
|
167201
|
+
if (error98 instanceof ZeroInsufficientFundsError && requirement.protocol === "x402" && requirement.fallbackProtocol === "mpp") {
|
|
167202
|
+
diagnostics.issue(
|
|
167203
|
+
"balance_check",
|
|
167204
|
+
FETCH_DIAGNOSTIC_CODES.insufficientFunds
|
|
167205
|
+
);
|
|
167206
|
+
diagnostics.selectPaymentProtocol("mpp");
|
|
167207
|
+
paid = await client.payments.payMpp(paymentInput);
|
|
167208
|
+
} else {
|
|
167209
|
+
throw error98;
|
|
166479
167210
|
}
|
|
166480
|
-
}
|
|
167211
|
+
}
|
|
166481
167212
|
response = paid.response;
|
|
166482
167213
|
payment = paid.payment;
|
|
166483
167214
|
if (paid.warnings) warnings.push(...paid.warnings);
|
|
166484
167215
|
} catch (err) {
|
|
166485
167216
|
if (err instanceof ZeroSessionCloseFailedError) {
|
|
167217
|
+
diagnostics.fail(
|
|
167218
|
+
"session_close",
|
|
167219
|
+
FETCH_DIAGNOSTIC_CODES.sessionCloseFailed
|
|
167220
|
+
);
|
|
166486
167221
|
response = err.response;
|
|
166487
167222
|
payment = {
|
|
166488
167223
|
protocol: "mpp",
|
|
@@ -166492,8 +167227,13 @@ var clientFetch = async (client, url4, opts = {}) => {
|
|
|
166492
167227
|
asset: "USDC",
|
|
166493
167228
|
session: err.session
|
|
166494
167229
|
};
|
|
167230
|
+
paymentCloseError = err.message;
|
|
166495
167231
|
warnings.push(FETCH_WARNINGS.mppSessionCloseFailed);
|
|
166496
167232
|
} else if (err instanceof ZeroInsufficientFundsError) {
|
|
167233
|
+
diagnostics.fail(
|
|
167234
|
+
"balance_check",
|
|
167235
|
+
FETCH_DIAGNOSTIC_CODES.insufficientFunds
|
|
167236
|
+
);
|
|
166497
167237
|
return errorFetchResult(
|
|
166498
167238
|
fetchId,
|
|
166499
167239
|
startedAt,
|
|
@@ -166504,6 +167244,12 @@ var clientFetch = async (client, url4, opts = {}) => {
|
|
|
166504
167244
|
null
|
|
166505
167245
|
);
|
|
166506
167246
|
} else if (err instanceof ZeroPaymentError || err instanceof ZeroAuthError) {
|
|
167247
|
+
if (diagnostics.snapshot().failureStage === null) {
|
|
167248
|
+
diagnostics.fail(
|
|
167249
|
+
"paid_replay",
|
|
167250
|
+
FETCH_DIAGNOSTIC_CODES.paymentFailed
|
|
167251
|
+
);
|
|
167252
|
+
}
|
|
166507
167253
|
const result2 = errorFetchResult(
|
|
166508
167254
|
fetchId,
|
|
166509
167255
|
startedAt,
|
|
@@ -166517,12 +167263,17 @@ var clientFetch = async (client, url4, opts = {}) => {
|
|
|
166517
167263
|
client,
|
|
166518
167264
|
opts,
|
|
166519
167265
|
result2,
|
|
167266
|
+
diagnostics,
|
|
166520
167267
|
void 0,
|
|
166521
167268
|
requestUrl,
|
|
166522
167269
|
method
|
|
166523
167270
|
);
|
|
166524
167271
|
return result2;
|
|
166525
167272
|
} else if (err instanceof ZeroTimeoutError) {
|
|
167273
|
+
diagnostics.fail(
|
|
167274
|
+
"paid_replay",
|
|
167275
|
+
FETCH_DIAGNOSTIC_CODES.paidReplayTimeout
|
|
167276
|
+
);
|
|
166526
167277
|
await recordTimeoutRun(
|
|
166527
167278
|
client,
|
|
166528
167279
|
opts,
|
|
@@ -166530,12 +167281,17 @@ var clientFetch = async (client, url4, opts = {}) => {
|
|
|
166530
167281
|
err,
|
|
166531
167282
|
startedAt,
|
|
166532
167283
|
capabilityIdRequested,
|
|
167284
|
+
diagnostics,
|
|
166533
167285
|
void 0,
|
|
166534
167286
|
requestUrl,
|
|
166535
167287
|
method
|
|
166536
167288
|
);
|
|
166537
167289
|
throw err;
|
|
166538
167290
|
} else {
|
|
167291
|
+
diagnostics.fail(
|
|
167292
|
+
"paid_replay",
|
|
167293
|
+
isCallerAbortError(err) ? FETCH_DIAGNOSTIC_CODES.callerAborted : FETCH_DIAGNOSTIC_CODES.paidReplayFailed
|
|
167294
|
+
);
|
|
166539
167295
|
const failed = errorFetchResult(
|
|
166540
167296
|
fetchId,
|
|
166541
167297
|
startedAt,
|
|
@@ -166548,6 +167304,7 @@ var clientFetch = async (client, url4, opts = {}) => {
|
|
|
166548
167304
|
client,
|
|
166549
167305
|
opts,
|
|
166550
167306
|
failed,
|
|
167307
|
+
diagnostics,
|
|
166551
167308
|
void 0,
|
|
166552
167309
|
requestUrl,
|
|
166553
167310
|
method
|
|
@@ -166556,6 +167313,10 @@ var clientFetch = async (client, url4, opts = {}) => {
|
|
|
166556
167313
|
}
|
|
166557
167314
|
}
|
|
166558
167315
|
} else if (requirement?.protocol === "unknown") {
|
|
167316
|
+
diagnostics.fail(
|
|
167317
|
+
"rail_select",
|
|
167318
|
+
FETCH_DIAGNOSTIC_CODES.unsupportedPaymentRail
|
|
167319
|
+
);
|
|
166559
167320
|
const result2 = errorFetchResult(
|
|
166560
167321
|
fetchId,
|
|
166561
167322
|
startedAt,
|
|
@@ -166569,6 +167330,7 @@ var clientFetch = async (client, url4, opts = {}) => {
|
|
|
166569
167330
|
client,
|
|
166570
167331
|
opts,
|
|
166571
167332
|
result2,
|
|
167333
|
+
diagnostics,
|
|
166572
167334
|
void 0,
|
|
166573
167335
|
requestUrl,
|
|
166574
167336
|
method
|
|
@@ -166582,13 +167344,20 @@ var clientFetch = async (client, url4, opts = {}) => {
|
|
|
166582
167344
|
let bodyRaw;
|
|
166583
167345
|
let bodyEncoding;
|
|
166584
167346
|
try {
|
|
166585
|
-
const parsed = await
|
|
167347
|
+
const parsed = await diagnostics.measure(
|
|
167348
|
+
"body_read",
|
|
167349
|
+
() => parseResponseBody(response, maxResponseBytes)
|
|
167350
|
+
);
|
|
166586
167351
|
body = parsed.body;
|
|
166587
167352
|
bodyRaw = parsed.bodyRaw;
|
|
166588
167353
|
bodyEncoding = parsed.bodyEncoding;
|
|
166589
|
-
if (parsed.truncated)
|
|
167354
|
+
if (parsed.truncated) {
|
|
167355
|
+
warnings.push(FETCH_WARNINGS.bodyTruncated);
|
|
167356
|
+
diagnostics.issue("body_read", FETCH_DIAGNOSTIC_CODES.bodyTruncated);
|
|
167357
|
+
}
|
|
166590
167358
|
} catch (err) {
|
|
166591
167359
|
if (err instanceof Error && err.name === "AbortError") {
|
|
167360
|
+
diagnostics.fail("body_read", FETCH_DIAGNOSTIC_CODES.callerAborted);
|
|
166592
167361
|
const aborted3 = {
|
|
166593
167362
|
fetchId,
|
|
166594
167363
|
runId: null,
|
|
@@ -166605,6 +167374,7 @@ var clientFetch = async (client, url4, opts = {}) => {
|
|
|
166605
167374
|
client,
|
|
166606
167375
|
opts,
|
|
166607
167376
|
aborted3,
|
|
167377
|
+
diagnostics,
|
|
166608
167378
|
(await resolvePromise.catch(() => null))?.capabilityId,
|
|
166609
167379
|
requestUrl,
|
|
166610
167380
|
method
|
|
@@ -166615,6 +167385,7 @@ var clientFetch = async (client, url4, opts = {}) => {
|
|
|
166615
167385
|
});
|
|
166616
167386
|
}
|
|
166617
167387
|
const message2 = err instanceof Error ? err.message : String(err);
|
|
167388
|
+
diagnostics.fail("body_read", FETCH_DIAGNOSTIC_CODES.bodyReadFailed);
|
|
166618
167389
|
const skips = [];
|
|
166619
167390
|
const settledLocally = paymentHasAnchor(payment);
|
|
166620
167391
|
if (settledLocally && response.status === 402) {
|
|
@@ -166655,6 +167426,7 @@ var clientFetch = async (client, url4, opts = {}) => {
|
|
|
166655
167426
|
client,
|
|
166656
167427
|
opts,
|
|
166657
167428
|
result2,
|
|
167429
|
+
diagnostics,
|
|
166658
167430
|
(await resolvePromise.catch(() => null))?.capabilityId,
|
|
166659
167431
|
requestUrl,
|
|
166660
167432
|
method
|
|
@@ -166667,14 +167439,22 @@ var clientFetch = async (client, url4, opts = {}) => {
|
|
|
166667
167439
|
if (paidButStill402) warnings.push(FETCH_WARNINGS.paidButStill402);
|
|
166668
167440
|
if (settlementUnconfirmed)
|
|
166669
167441
|
warnings.push(FETCH_WARNINGS.paymentSettlementUnconfirmed);
|
|
167442
|
+
if (settlementUnconfirmed) {
|
|
167443
|
+
diagnostics.issue(
|
|
167444
|
+
"settlement_receipt",
|
|
167445
|
+
FETCH_DIAGNOSTIC_CODES.settlementUnconfirmed
|
|
167446
|
+
);
|
|
167447
|
+
}
|
|
166670
167448
|
if (payment !== null && payment.amount === "unknown") {
|
|
166671
167449
|
warnings.push(FETCH_WARNINGS.paymentAmountUnknown);
|
|
166672
167450
|
}
|
|
167451
|
+
const errorShapedSuccess = response.ok && hasErrorShapedBody(body);
|
|
166673
167452
|
let runId = null;
|
|
166674
167453
|
const upstreamErrorForRecord = buildUpstreamError(
|
|
166675
167454
|
response.status,
|
|
166676
167455
|
bodyRaw,
|
|
166677
|
-
bodyEncoding
|
|
167456
|
+
bodyEncoding,
|
|
167457
|
+
errorShapedSuccess
|
|
166678
167458
|
);
|
|
166679
167459
|
const resolvedCap = await resolvePromise;
|
|
166680
167460
|
const effectiveCapabilityId = opts.capabilityId ?? resolvedCap?.capabilityId;
|
|
@@ -166689,7 +167469,26 @@ var clientFetch = async (client, url4, opts = {}) => {
|
|
|
166689
167469
|
requestUrl: redactUrl2(requestUrl),
|
|
166690
167470
|
requestMethod: method
|
|
166691
167471
|
} : { requestUrl: redactUrl2(requestUrl), requestMethod: method };
|
|
166692
|
-
const fetchOutcome = computeOutcome(
|
|
167472
|
+
const fetchOutcome = computeOutcome(
|
|
167473
|
+
response.status,
|
|
167474
|
+
payment,
|
|
167475
|
+
warnings,
|
|
167476
|
+
errorShapedSuccess
|
|
167477
|
+
);
|
|
167478
|
+
if (fetchOutcome !== "success" && diagnostics.snapshot().failureStage === null) {
|
|
167479
|
+
if (fetchOutcome === "payment_rejected") {
|
|
167480
|
+
diagnostics.fail("paid_replay", FETCH_DIAGNOSTIC_CODES.paymentRejected);
|
|
167481
|
+
} else if (errorShapedSuccess) {
|
|
167482
|
+
diagnostics.fail(
|
|
167483
|
+
"upstream_response",
|
|
167484
|
+
FETCH_DIAGNOSTIC_CODES.upstreamErrorPayload
|
|
167485
|
+
);
|
|
167486
|
+
} else if (response.status >= 500) {
|
|
167487
|
+
diagnostics.fail("upstream_response", FETCH_DIAGNOSTIC_CODES.upstream5xx);
|
|
167488
|
+
} else if (response.status >= 400) {
|
|
167489
|
+
diagnostics.fail("upstream_response", FETCH_DIAGNOSTIC_CODES.upstream4xx);
|
|
167490
|
+
}
|
|
167491
|
+
}
|
|
166693
167492
|
{
|
|
166694
167493
|
const { recordingClient, canRecord } = resolveRecordingClient(client, opts);
|
|
166695
167494
|
if (!canRecord) {
|
|
@@ -166702,51 +167501,66 @@ var clientFetch = async (client, url4, opts = {}) => {
|
|
|
166702
167501
|
try {
|
|
166703
167502
|
derived = opts.deriveRunMetadata({
|
|
166704
167503
|
status: response.status,
|
|
166705
|
-
ok: response.ok,
|
|
167504
|
+
ok: response.ok && !errorShapedSuccess,
|
|
166706
167505
|
bodyRaw,
|
|
166707
167506
|
...bodyEncoding && { bodyEncoding }
|
|
166708
167507
|
});
|
|
166709
167508
|
} catch {
|
|
166710
167509
|
}
|
|
166711
167510
|
}
|
|
166712
|
-
const result2 = await
|
|
166713
|
-
|
|
166714
|
-
|
|
166715
|
-
|
|
166716
|
-
|
|
166717
|
-
|
|
166718
|
-
|
|
166719
|
-
|
|
166720
|
-
|
|
166721
|
-
|
|
166722
|
-
|
|
166723
|
-
|
|
166724
|
-
|
|
166725
|
-
|
|
166726
|
-
|
|
166727
|
-
|
|
166728
|
-
|
|
166729
|
-
|
|
166730
|
-
|
|
166731
|
-
|
|
166732
|
-
|
|
166733
|
-
|
|
166734
|
-
|
|
166735
|
-
|
|
166736
|
-
|
|
166737
|
-
|
|
166738
|
-
|
|
166739
|
-
|
|
166740
|
-
|
|
167511
|
+
const result2 = await diagnostics.measure(
|
|
167512
|
+
"run_record",
|
|
167513
|
+
() => recordingClient.runs.create({
|
|
167514
|
+
...runTarget,
|
|
167515
|
+
fetchId,
|
|
167516
|
+
searchId: opts.searchId,
|
|
167517
|
+
// Auto-resolved runs are always direct_url — they only fire when
|
|
167518
|
+
// no capabilityId was supplied (the direct_url path by definition).
|
|
167519
|
+
...opts.capabilityId === void 0 ? { fetchOrigin: "direct_url" } : opts.fetchOrigin && { fetchOrigin: opts.fetchOrigin },
|
|
167520
|
+
status: response.status,
|
|
167521
|
+
// The SDK's verdict alongside the raw status. A close-fail or a
|
|
167522
|
+
// dropped body answers 200 while the caller got nothing — the
|
|
167523
|
+
// server must not read that as a clean success.
|
|
167524
|
+
outcome: fetchOutcome,
|
|
167525
|
+
latencyMs,
|
|
167526
|
+
settlementState: settlementStateFor(
|
|
167527
|
+
payment,
|
|
167528
|
+
warnings,
|
|
167529
|
+
diagnostics.snapshot()
|
|
167530
|
+
),
|
|
167531
|
+
failureStage: diagnostics.snapshot().failureStage ?? void 0,
|
|
167532
|
+
failureCode: diagnostics.snapshot().failureCode ?? void 0,
|
|
167533
|
+
fundingSource: diagnostics.snapshot().fundingSource ?? void 0,
|
|
167534
|
+
stageDurationsMs: diagnostics.snapshot().stageDurationsMs,
|
|
167535
|
+
warningCodes: warnings.length > 0 ? warnings : void 0,
|
|
167536
|
+
// Attribute to the selected wallet in session mode. Skipped when a
|
|
167537
|
+
// per-call `account` override records the run — that account's own
|
|
167538
|
+
// EIP-191 identity is the attribution.
|
|
167539
|
+
...opts.walletAddress && !opts.account && { walletAddress: opts.walletAddress },
|
|
167540
|
+
...opts.requestSchema && { requestSchema: opts.requestSchema },
|
|
167541
|
+
...derived?.responseSchema && {
|
|
167542
|
+
responseSchema: derived.responseSchema
|
|
166741
167543
|
},
|
|
166742
|
-
|
|
166743
|
-
|
|
166744
|
-
|
|
166745
|
-
|
|
166746
|
-
|
|
166747
|
-
|
|
167544
|
+
...upstreamErrorForRecord && {
|
|
167545
|
+
errorSnippetHash: upstreamErrorForRecord.snippetHash,
|
|
167546
|
+
errorSnippetLength: upstreamErrorForRecord.snippetLength
|
|
167547
|
+
},
|
|
167548
|
+
...payment && {
|
|
167549
|
+
...knownAmount && {
|
|
167550
|
+
costAmount: payment.amount,
|
|
167551
|
+
costAsset: payment.asset
|
|
167552
|
+
},
|
|
167553
|
+
paymentProtocol: payment.protocol,
|
|
167554
|
+
paymentChain: payment.chain,
|
|
167555
|
+
paymentTxHash: payment.txHash ?? void 0,
|
|
167556
|
+
paymentMode: diagnostics.snapshot().paymentMode ?? (payment.session ? "session" : "charge"),
|
|
167557
|
+
...payment.session && { paymentSession: payment.session }
|
|
167558
|
+
}
|
|
167559
|
+
})
|
|
167560
|
+
);
|
|
166748
167561
|
runId = result2.runId;
|
|
166749
167562
|
} catch (err) {
|
|
167563
|
+
diagnostics.issue("run_record", FETCH_DIAGNOSTIC_CODES.runCreateFailed);
|
|
166750
167564
|
const errorMessage2 = err instanceof Error ? err.message : String(err);
|
|
166751
167565
|
const code = err instanceof ZeroError ? err.code : void 0;
|
|
166752
167566
|
const skipMsg = code ? `run_create_failed:${code}: ${errorMessage2}` : `run_create_failed: ${errorMessage2}`;
|
|
@@ -166755,6 +167569,8 @@ var clientFetch = async (client, url4, opts = {}) => {
|
|
|
166755
167569
|
level: "warn",
|
|
166756
167570
|
message: "Failed to record run for fetch",
|
|
166757
167571
|
meta: {
|
|
167572
|
+
fetchId,
|
|
167573
|
+
stage: "run_record",
|
|
166758
167574
|
url: redactUrl2(url4),
|
|
166759
167575
|
capabilityId: effectiveCapabilityId,
|
|
166760
167576
|
error: errorMessage2,
|
|
@@ -166767,7 +167583,7 @@ var clientFetch = async (client, url4, opts = {}) => {
|
|
|
166767
167583
|
const result = {
|
|
166768
167584
|
fetchId,
|
|
166769
167585
|
runId,
|
|
166770
|
-
ok: response.ok,
|
|
167586
|
+
ok: response.ok && !errorShapedSuccess,
|
|
166771
167587
|
status: response.status,
|
|
166772
167588
|
latencyMs,
|
|
166773
167589
|
payment,
|
|
@@ -166776,11 +167592,12 @@ var clientFetch = async (client, url4, opts = {}) => {
|
|
|
166776
167592
|
bodyRaw
|
|
166777
167593
|
};
|
|
166778
167594
|
if (bodyEncoding) result.bodyEncoding = bodyEncoding;
|
|
166779
|
-
if (!response.ok) {
|
|
167595
|
+
if (!response.ok || errorShapedSuccess) {
|
|
166780
167596
|
const candidate = bodyRaw !== null && bodyRaw.length > 0 && bodyEncoding !== "base64" ? bodyRaw.slice(0, 240) : null;
|
|
166781
167597
|
result.error = candidate !== null && !requestBodyEchoed(candidate, opts.body) ? candidate : `HTTP ${response.status}`;
|
|
166782
167598
|
if (upstreamErrorForRecord) result.upstreamError = upstreamErrorForRecord;
|
|
166783
167599
|
}
|
|
167600
|
+
if (paymentCloseError) result.error = paymentCloseError;
|
|
166784
167601
|
if (skipReasons.length > 0) {
|
|
166785
167602
|
result.runTrackingSkipped = skipReasons;
|
|
166786
167603
|
}
|
|
@@ -167151,13 +167968,22 @@ var normalizeMessage = (message2) => {
|
|
|
167151
167968
|
return bytesToHex(message2.raw);
|
|
167152
167969
|
};
|
|
167153
167970
|
var repackageSignFailure = (err, op) => {
|
|
167154
|
-
if (err instanceof ZeroApiError
|
|
167971
|
+
if (err instanceof ZeroApiError) {
|
|
167155
167972
|
const body = err.body;
|
|
167156
167973
|
const detail = body && typeof body.error === "string" ? `: ${body.error}` : "";
|
|
167157
|
-
|
|
167158
|
-
|
|
167159
|
-
|
|
167160
|
-
|
|
167974
|
+
if (err.status === 400 || err.status === 402) {
|
|
167975
|
+
throw new ZeroPaymentError(
|
|
167976
|
+
`Sign endpoint refused ${op} (HTTP ${err.status})${detail}`,
|
|
167977
|
+
{ cause: err }
|
|
167978
|
+
);
|
|
167979
|
+
}
|
|
167980
|
+
if (err.status === 403 || err.status === 404) {
|
|
167981
|
+
throw new ZeroAuthError(
|
|
167982
|
+
"auth_error",
|
|
167983
|
+
`Managed signer refused ${op} (HTTP ${err.status})${detail}`,
|
|
167984
|
+
{ cause: err }
|
|
167985
|
+
);
|
|
167986
|
+
}
|
|
167161
167987
|
}
|
|
167162
167988
|
throw err;
|
|
167163
167989
|
};
|
|
@@ -167583,6 +168409,13 @@ var Capabilities = class {
|
|
|
167583
168409
|
}
|
|
167584
168410
|
};
|
|
167585
168411
|
};
|
|
168412
|
+
var paymentSessionSchema = external_exports3.object({
|
|
168413
|
+
channelId: external_exports3.string().regex(/^0x[0-9a-fA-F]{64}$/),
|
|
168414
|
+
escrowContract: external_exports3.string().regex(/^0x[0-9a-fA-F]{40}$/),
|
|
168415
|
+
chainId: external_exports3.number().int().positive(),
|
|
168416
|
+
recipient: external_exports3.string().regex(/^0x[0-9a-fA-F]{40}$/).nullable(),
|
|
168417
|
+
cumulativeAmount: external_exports3.string().regex(/^(?:0|[1-9]\d*)$/)
|
|
168418
|
+
}).strict();
|
|
167586
168419
|
var createRunResponseSchema = external_exports3.object({
|
|
167587
168420
|
runId: external_exports3.string()
|
|
167588
168421
|
});
|
|
@@ -167598,7 +168431,8 @@ var runListItemSchema = external_exports3.object({
|
|
|
167598
168431
|
protocol: external_exports3.string(),
|
|
167599
168432
|
chain: external_exports3.string().nullable(),
|
|
167600
168433
|
txHash: external_exports3.string().nullable(),
|
|
167601
|
-
mode: external_exports3.string().nullable()
|
|
168434
|
+
mode: external_exports3.string().nullable(),
|
|
168435
|
+
session: paymentSessionSchema.nullable().optional().default(null)
|
|
167602
168436
|
}).nullable(),
|
|
167603
168437
|
createdAt: external_exports3.coerce.date(),
|
|
167604
168438
|
reviewed: external_exports3.boolean()
|
|
@@ -167618,7 +168452,8 @@ var runDetailSchema = external_exports3.object({
|
|
|
167618
168452
|
protocol: external_exports3.string(),
|
|
167619
168453
|
chain: external_exports3.string().nullable(),
|
|
167620
168454
|
txHash: external_exports3.string().nullable(),
|
|
167621
|
-
mode: external_exports3.string().nullable()
|
|
168455
|
+
mode: external_exports3.string().nullable(),
|
|
168456
|
+
session: paymentSessionSchema.nullable().optional().default(null)
|
|
167622
168457
|
}).nullable(),
|
|
167623
168458
|
capability: external_exports3.object({
|
|
167624
168459
|
uid: external_exports3.string(),
|
|
@@ -167674,6 +168509,18 @@ var Runs = class _Runs {
|
|
|
167674
168509
|
* unattributed runs, which it can't do if we strip the target as well.
|
|
167675
168510
|
*/
|
|
167676
168511
|
static FIELD_GENERATIONS = [
|
|
168512
|
+
// MPP channel anchor for close-failure reconciliation. Peels first so a
|
|
168513
|
+
// newer SDK still records all prior diagnostics against an older API.
|
|
168514
|
+
["paymentSession"],
|
|
168515
|
+
// Phase-localized observability + settlement confirmation.
|
|
168516
|
+
[
|
|
168517
|
+
"settlementState",
|
|
168518
|
+
"failureStage",
|
|
168519
|
+
"failureCode",
|
|
168520
|
+
"fundingSource",
|
|
168521
|
+
"stageDurationsMs",
|
|
168522
|
+
"warningCodes"
|
|
168523
|
+
],
|
|
167677
168524
|
// Newest: correlation + honest classification.
|
|
167678
168525
|
["fetchId", "outcome"],
|
|
167679
168526
|
// ZERO-536: the direct-URL target. Dropping this loses attribution for an
|
|
@@ -168172,11 +169019,7 @@ var classifyFetchError = (error98) => {
|
|
|
168172
169019
|
}
|
|
168173
169020
|
};
|
|
168174
169021
|
var isCallerAbort = (error98) => {
|
|
168175
|
-
|
|
168176
|
-
if (record3?.name === "AbortError") return true;
|
|
168177
|
-
if (record3?.code !== "api_error" || record3.status !== 0) return false;
|
|
168178
|
-
const cause = typeof record3.cause === "object" && record3.cause !== null ? record3.cause : null;
|
|
168179
|
-
return cause?.name === "AbortError";
|
|
169022
|
+
return isCallerAbortError(error98);
|
|
168180
169023
|
};
|
|
168181
169024
|
var AnalyticsEmitter = class {
|
|
168182
169025
|
isEnabled;
|
|
@@ -168257,8 +169100,19 @@ var AnalyticsEmitter = class {
|
|
|
168257
169100
|
error_class: res.outcome === "success" ? null : outcomeToErrorClass(res.outcome, res.status),
|
|
168258
169101
|
latency_ms: res.latencyMs,
|
|
168259
169102
|
has_payment: res.payment !== null,
|
|
168260
|
-
payment_protocol: res.payment?.protocol ?? null,
|
|
169103
|
+
payment_protocol: res.payment?.protocol ?? res.diagnostics?.paymentProtocol ?? null,
|
|
169104
|
+
funding_source: res.diagnostics?.fundingSource ?? null,
|
|
168261
169105
|
payment_amount: res.payment?.amount ?? null,
|
|
169106
|
+
payment_chain: res.payment?.chain ?? null,
|
|
169107
|
+
payment_mode: res.diagnostics?.paymentMode ?? (res.payment?.session ? "session" : res.payment ? "charge" : null),
|
|
169108
|
+
has_settlement_anchor: res.diagnostics?.paymentMode !== "proof" && res.payment !== null && (res.payment.txHash !== null || res.payment.session !== void 0),
|
|
169109
|
+
payment_session_channel_id: res.payment?.session?.channelId ?? null,
|
|
169110
|
+
settlement_state: res.settlementState ?? null,
|
|
169111
|
+
warning_codes: res.warnings ?? [],
|
|
169112
|
+
failure_stage: res.diagnostics?.failureStage ?? null,
|
|
169113
|
+
failure_code: res.diagnostics?.failureCode ?? null,
|
|
169114
|
+
diagnostic_codes: res.diagnostics?.issues.map((issue3) => issue3.code) ?? [],
|
|
169115
|
+
stage_durations_ms: res.diagnostics?.stageDurationsMs ?? {},
|
|
168262
169116
|
// Opaque cap uid / slug / attribution token — not PII, useful for
|
|
168263
169117
|
// joining back to the capabilities table in BI.
|
|
168264
169118
|
capability_id: opts.capabilityId ?? null,
|
|
@@ -168277,12 +169131,20 @@ var AnalyticsEmitter = class {
|
|
|
168277
169131
|
error_snippet_length: res.upstreamError?.snippetLength ?? null
|
|
168278
169132
|
});
|
|
168279
169133
|
}
|
|
168280
|
-
fetchError(url4, opts, error98, errorClass, status) {
|
|
169134
|
+
fetchError(url4, opts, error98, errorClass, status, fetchId = null, diagnostics) {
|
|
168281
169135
|
if (!this.sink) return;
|
|
168282
169136
|
this.emit("fetch_error", {
|
|
168283
169137
|
url: redactUrl(url4),
|
|
168284
169138
|
error_class: errorClass,
|
|
168285
169139
|
status,
|
|
169140
|
+
fetch_id: fetchId,
|
|
169141
|
+
failure_stage: diagnostics?.failureStage ?? null,
|
|
169142
|
+
failure_code: diagnostics?.failureCode ?? null,
|
|
169143
|
+
payment_protocol: diagnostics?.paymentProtocol ?? null,
|
|
169144
|
+
payment_mode: diagnostics?.paymentMode ?? null,
|
|
169145
|
+
funding_source: diagnostics?.fundingSource ?? null,
|
|
169146
|
+
diagnostic_codes: diagnostics?.issues.map((issue3) => issue3.code) ?? [],
|
|
169147
|
+
stage_durations_ms: diagnostics?.stageDurationsMs ?? {},
|
|
168286
169148
|
capability_id: opts.capabilityId ?? null,
|
|
168287
169149
|
search_id: opts.searchId ?? null,
|
|
168288
169150
|
error: safeErrorLabel(error98, errorClass)
|
|
@@ -168386,6 +169248,10 @@ var ZeroClient = class _ZeroClient {
|
|
|
168386
169248
|
// public surface is the constructor option + emitted event types, not the
|
|
168387
169249
|
// mutable emitter implementation.
|
|
168388
169250
|
analytics;
|
|
169251
|
+
// Every session token this client has held. Keep rotated values for the
|
|
169252
|
+
// client's lifetime so a delayed rejection from an old request cannot leak
|
|
169253
|
+
// the previous access/refresh token through a consumer logger.
|
|
169254
|
+
sensitiveLogValues = /* @__PURE__ */ new Set();
|
|
168389
169255
|
// Private — read via getCredentials(), mutate only via applyRefreshedTokens().
|
|
168390
169256
|
// Keeping a single mutator funnel is what lets the transport replay
|
|
168391
169257
|
// requests with a fresh access token after a 401 → refresh.
|
|
@@ -168436,6 +169302,9 @@ var ZeroClient = class _ZeroClient {
|
|
|
168436
169302
|
refreshOverride;
|
|
168437
169303
|
constructor(options = {}) {
|
|
168438
169304
|
this.credentials = normalizeCredentials(options.session, options.account);
|
|
169305
|
+
if (this.credentials.kind === "session") {
|
|
169306
|
+
this.rememberSessionTokens(this.credentials);
|
|
169307
|
+
}
|
|
168439
169308
|
this.baseUrl = options.baseUrl ?? DEFAULT_BASE_URL;
|
|
168440
169309
|
this.timeout = options.timeout ?? DEFAULT_TIMEOUT_MS;
|
|
168441
169310
|
this.maxRetries = options.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
@@ -168443,7 +169312,7 @@ var ZeroClient = class _ZeroClient {
|
|
|
168443
169312
|
this.defaultHeaders = options.defaultHeaders ?? {};
|
|
168444
169313
|
this.fetchImpl = options.fetch ?? ((...args) => globalThis.fetch(...args));
|
|
168445
169314
|
this.fetchOptions = options.fetchOptions;
|
|
168446
|
-
this.logger = options.logger;
|
|
169315
|
+
this.logger = options.logger ? (event) => options.logger?.(this.redactLogEvent(event)) : void 0;
|
|
168447
169316
|
this.analyticsOptions = options.analytics;
|
|
168448
169317
|
this.refreshOverride = options.refresh;
|
|
168449
169318
|
this.withAccountCache = options._sharedAccountCache ?? /* @__PURE__ */ new Map();
|
|
@@ -168517,6 +169386,7 @@ var ZeroClient = class _ZeroClient {
|
|
|
168517
169386
|
// still considered the source of truth for the current process.
|
|
168518
169387
|
applyRefreshedTokens = async (next) => {
|
|
168519
169388
|
if (this.credentials.kind !== "session") return;
|
|
169389
|
+
this.rememberSessionTokens(next);
|
|
168520
169390
|
this.credentials = {
|
|
168521
169391
|
...this.credentials,
|
|
168522
169392
|
accessToken: next.accessToken,
|
|
@@ -168539,12 +169409,55 @@ var ZeroClient = class _ZeroClient {
|
|
|
168539
169409
|
// callback). No-op outside session mode.
|
|
168540
169410
|
setSessionTokens = (tokens2) => {
|
|
168541
169411
|
if (this.credentials.kind !== "session") return;
|
|
169412
|
+
this.rememberSessionTokens(tokens2);
|
|
168542
169413
|
this.credentials = {
|
|
168543
169414
|
...this.credentials,
|
|
168544
169415
|
accessToken: tokens2.accessToken,
|
|
168545
169416
|
refreshToken: tokens2.refreshToken
|
|
168546
169417
|
};
|
|
168547
169418
|
};
|
|
169419
|
+
rememberSessionTokens = (tokens2) => {
|
|
169420
|
+
if (tokens2.accessToken) this.sensitiveLogValues.add(tokens2.accessToken);
|
|
169421
|
+
if (tokens2.refreshToken) this.sensitiveLogValues.add(tokens2.refreshToken);
|
|
169422
|
+
};
|
|
169423
|
+
redactLogString = (value) => {
|
|
169424
|
+
let redacted = value;
|
|
169425
|
+
for (const secret of this.sensitiveLogValues) {
|
|
169426
|
+
redacted = redacted.split(secret).join("[REDACTED]");
|
|
169427
|
+
}
|
|
169428
|
+
return redacted;
|
|
169429
|
+
};
|
|
169430
|
+
redactLogValue = (value, key, seen) => {
|
|
169431
|
+
if (key && /(?:authorization|access[_-]?token|refresh[_-]?token|session[_-]?token)/i.test(
|
|
169432
|
+
key
|
|
169433
|
+
)) {
|
|
169434
|
+
return "[REDACTED]";
|
|
169435
|
+
}
|
|
169436
|
+
if (typeof value === "string") return this.redactLogString(value);
|
|
169437
|
+
if (!value || typeof value !== "object") return value;
|
|
169438
|
+
if (seen.has(value)) return "[Circular]";
|
|
169439
|
+
seen.add(value);
|
|
169440
|
+
if (Array.isArray(value)) {
|
|
169441
|
+
return value.map((item) => this.redactLogValue(item, void 0, seen));
|
|
169442
|
+
}
|
|
169443
|
+
return Object.fromEntries(
|
|
169444
|
+
Object.entries(value).map(([childKey, childValue]) => [
|
|
169445
|
+
childKey,
|
|
169446
|
+
this.redactLogValue(childValue, childKey, seen)
|
|
169447
|
+
])
|
|
169448
|
+
);
|
|
169449
|
+
};
|
|
169450
|
+
redactLogEvent = (event) => ({
|
|
169451
|
+
...event,
|
|
169452
|
+
message: this.redactLogString(event.message),
|
|
169453
|
+
...event.meta && {
|
|
169454
|
+
meta: this.redactLogValue(
|
|
169455
|
+
event.meta,
|
|
169456
|
+
void 0,
|
|
169457
|
+
/* @__PURE__ */ new WeakSet()
|
|
169458
|
+
)
|
|
169459
|
+
}
|
|
169460
|
+
});
|
|
168548
169461
|
// Returns a new client bound to a different session, inheriting
|
|
168549
169462
|
// transport config but with its own credential slot. Refreshes on the
|
|
168550
169463
|
// sub-client never mutate the base — critical for multi-tenant servers
|
|
@@ -168735,8 +169648,8 @@ var ZeroClient = class _ZeroClient {
|
|
|
168735
169648
|
return Promise.reject(
|
|
168736
169649
|
abortErr(new DOMException("Aborted", "AbortError"))
|
|
168737
169650
|
);
|
|
168738
|
-
return new Promise((resolve7,
|
|
168739
|
-
const onAbort = () =>
|
|
169651
|
+
return new Promise((resolve7, reject2) => {
|
|
169652
|
+
const onAbort = () => reject2(abortErr(new DOMException("Aborted", "AbortError")));
|
|
168740
169653
|
signal.addEventListener("abort", onAbort, { once: true });
|
|
168741
169654
|
p.then(
|
|
168742
169655
|
(v) => {
|
|
@@ -168745,7 +169658,7 @@ var ZeroClient = class _ZeroClient {
|
|
|
168745
169658
|
},
|
|
168746
169659
|
(e) => {
|
|
168747
169660
|
signal.removeEventListener("abort", onAbort);
|
|
168748
|
-
|
|
169661
|
+
reject2(e);
|
|
168749
169662
|
}
|
|
168750
169663
|
);
|
|
168751
169664
|
});
|
|
@@ -168783,15 +169696,32 @@ var ZeroClient = class _ZeroClient {
|
|
|
168783
169696
|
// path is flat on the client, same rationale as `search` above.
|
|
168784
169697
|
// Orchestration lives in fetch.ts so this class stays readable.
|
|
168785
169698
|
fetch = async (url4, opts = {}) => {
|
|
169699
|
+
const fetchId = randomUUID();
|
|
169700
|
+
const diagnostics = new FetchDiagnosticContext(fetchId);
|
|
168786
169701
|
try {
|
|
168787
|
-
const result = await clientFetch(this, url4, opts);
|
|
169702
|
+
const result = await clientFetch(this, url4, opts, diagnostics);
|
|
169703
|
+
result.diagnostics = diagnostics.snapshot();
|
|
169704
|
+
result.settlementState = settlementStateFor(
|
|
169705
|
+
result.payment,
|
|
169706
|
+
result.warnings,
|
|
169707
|
+
diagnostics.snapshot()
|
|
169708
|
+
);
|
|
168788
169709
|
this.analytics.fetchExecuted(url4, opts, result);
|
|
168789
169710
|
return result;
|
|
168790
169711
|
} catch (error98) {
|
|
168791
169712
|
if (this.analytics.isEnabled && !isCallerAbort(error98)) {
|
|
168792
169713
|
const { errorClass, status } = classifyFetchError(error98);
|
|
168793
|
-
this.analytics.fetchError(
|
|
169714
|
+
this.analytics.fetchError(
|
|
169715
|
+
url4,
|
|
169716
|
+
opts,
|
|
169717
|
+
error98,
|
|
169718
|
+
errorClass,
|
|
169719
|
+
status,
|
|
169720
|
+
fetchId,
|
|
169721
|
+
diagnostics.snapshot()
|
|
169722
|
+
);
|
|
168794
169723
|
}
|
|
169724
|
+
attachFetchErrorContext(error98, fetchId, diagnostics.snapshot());
|
|
168795
169725
|
throw error98;
|
|
168796
169726
|
}
|
|
168797
169727
|
};
|
|
@@ -169026,7 +169956,7 @@ var placeholderFor = (fieldName, propSchema) => String(sampleValueFor(fieldName,
|
|
|
169026
169956
|
|
|
169027
169957
|
// package.json
|
|
169028
169958
|
var package_default2 = {
|
|
169029
|
-
version: "1.
|
|
169959
|
+
version: "1.28.0"};
|
|
169030
169960
|
|
|
169031
169961
|
// src/app.ts
|
|
169032
169962
|
init_esm_shims();
|
|
@@ -169549,11 +170479,11 @@ var baseOpen = async (options) => {
|
|
|
169549
170479
|
}
|
|
169550
170480
|
const subprocess = childProcess.spawn(command, cliArguments, childProcessOptions);
|
|
169551
170481
|
if (options.wait) {
|
|
169552
|
-
return new Promise((resolve7,
|
|
169553
|
-
subprocess.once("error",
|
|
170482
|
+
return new Promise((resolve7, reject2) => {
|
|
170483
|
+
subprocess.once("error", reject2);
|
|
169554
170484
|
subprocess.once("close", (exitCode) => {
|
|
169555
170485
|
if (!options.allowNonzeroExitCode && exitCode !== 0) {
|
|
169556
|
-
|
|
170486
|
+
reject2(new Error(`Exited with code ${exitCode}`));
|
|
169557
170487
|
return;
|
|
169558
170488
|
}
|
|
169559
170489
|
resolve7(subprocess);
|
|
@@ -169561,13 +170491,13 @@ var baseOpen = async (options) => {
|
|
|
169561
170491
|
});
|
|
169562
170492
|
}
|
|
169563
170493
|
if (isFallbackAttempt) {
|
|
169564
|
-
return new Promise((resolve7,
|
|
169565
|
-
subprocess.once("error",
|
|
170494
|
+
return new Promise((resolve7, reject2) => {
|
|
170495
|
+
subprocess.once("error", reject2);
|
|
169566
170496
|
subprocess.once("spawn", () => {
|
|
169567
170497
|
subprocess.once("close", (exitCode) => {
|
|
169568
|
-
subprocess.off("error",
|
|
170498
|
+
subprocess.off("error", reject2);
|
|
169569
170499
|
if (exitCode !== 0) {
|
|
169570
|
-
|
|
170500
|
+
reject2(new Error(`Exited with code ${exitCode}`));
|
|
169571
170501
|
return;
|
|
169572
170502
|
}
|
|
169573
170503
|
subprocess.unref();
|
|
@@ -169577,10 +170507,10 @@ var baseOpen = async (options) => {
|
|
|
169577
170507
|
});
|
|
169578
170508
|
}
|
|
169579
170509
|
subprocess.unref();
|
|
169580
|
-
return new Promise((resolve7,
|
|
169581
|
-
subprocess.once("error",
|
|
170510
|
+
return new Promise((resolve7, reject2) => {
|
|
170511
|
+
subprocess.once("error", reject2);
|
|
169582
170512
|
subprocess.once("spawn", () => {
|
|
169583
|
-
subprocess.off("error",
|
|
170513
|
+
subprocess.off("error", reject2);
|
|
169584
170514
|
resolve7(subprocess);
|
|
169585
170515
|
});
|
|
169586
170516
|
});
|
|
@@ -170666,7 +171596,7 @@ var fetchCommand = (appContext) => new Command("fetch").description(
|
|
|
170666
171596
|
"Bind this fetch to a capability (uid or slug) so a reviewable run is recorded even without a prior `zero search`"
|
|
170667
171597
|
).option(
|
|
170668
171598
|
"--json",
|
|
170669
|
-
"Emit
|
|
171599
|
+
"Emit the full result envelope as JSON on stdout \u2014 fetchId, runId, ok, outcome, status, latencyMs, payment, settlementState, diagnostics, body, bodyRaw (plus upstreamError/warnings when present) \u2014 for batch/non-TTY use"
|
|
170670
171600
|
).option(
|
|
170671
171601
|
"--raw-body",
|
|
170672
171602
|
"With --json: keep `body` as the raw response string instead of parsing JSON. `bodyRaw` still reflects the raw text."
|
|
@@ -170864,8 +171794,19 @@ var fetchCommand = (appContext) => new Command("fetch").description(
|
|
|
170864
171794
|
});
|
|
170865
171795
|
} catch (err) {
|
|
170866
171796
|
const message2 = err instanceof Error ? err.message : "Fetch failed";
|
|
171797
|
+
const fetchContext = fetchErrorContext(err);
|
|
170867
171798
|
analyticsService.capture("fetch_error", {
|
|
170868
171799
|
cliErrorClass: "network",
|
|
171800
|
+
fetchId: fetchContext.fetchId,
|
|
171801
|
+
failureStage: fetchContext.diagnostics?.failureStage,
|
|
171802
|
+
failureCode: fetchContext.diagnostics?.failureCode,
|
|
171803
|
+
paymentProtocol: fetchContext.diagnostics?.paymentProtocol,
|
|
171804
|
+
paymentMode: fetchContext.diagnostics?.paymentMode,
|
|
171805
|
+
fundingSource: fetchContext.diagnostics?.fundingSource,
|
|
171806
|
+
diagnosticCodes: fetchContext.diagnostics?.issues?.map(
|
|
171807
|
+
(issue3) => issue3.code
|
|
171808
|
+
),
|
|
171809
|
+
stageDurationsMs: fetchContext.diagnostics?.stageDurationsMs,
|
|
170869
171810
|
url: redactUrl(resolvedUrl),
|
|
170870
171811
|
error: truncateError(message2)
|
|
170871
171812
|
});
|
|
@@ -170874,6 +171815,7 @@ var fetchCommand = (appContext) => new Command("fetch").description(
|
|
|
170874
171815
|
return;
|
|
170875
171816
|
}
|
|
170876
171817
|
const {
|
|
171818
|
+
fetchId,
|
|
170877
171819
|
runId,
|
|
170878
171820
|
status,
|
|
170879
171821
|
latencyMs,
|
|
@@ -170886,7 +171828,9 @@ var fetchCommand = (appContext) => new Command("fetch").description(
|
|
|
170886
171828
|
warnings: sdkWarnings,
|
|
170887
171829
|
runTrackingSkipped: sdkSkipReasons,
|
|
170888
171830
|
error: resultError,
|
|
170889
|
-
capabilityResolution
|
|
171831
|
+
capabilityResolution,
|
|
171832
|
+
settlementState,
|
|
171833
|
+
diagnostics
|
|
170890
171834
|
} = result;
|
|
170891
171835
|
const isBinary = bodyEncoding === "base64";
|
|
170892
171836
|
const bodyBytes = isBinary && bodyRaw ? Buffer.from(bodyRaw, "base64") : void 0;
|
|
@@ -170992,6 +171936,15 @@ var fetchCommand = (appContext) => new Command("fetch").description(
|
|
|
170992
171936
|
);
|
|
170993
171937
|
analyticsService.capture("fetch_error", {
|
|
170994
171938
|
cliErrorClass,
|
|
171939
|
+
fetchId,
|
|
171940
|
+
settlementState,
|
|
171941
|
+
failureStage: diagnostics?.failureStage,
|
|
171942
|
+
failureCode: diagnostics?.failureCode,
|
|
171943
|
+
paymentProtocol: diagnostics?.paymentProtocol,
|
|
171944
|
+
paymentMode: diagnostics?.paymentMode,
|
|
171945
|
+
fundingSource: diagnostics?.fundingSource,
|
|
171946
|
+
diagnosticCodes: diagnostics?.issues.map((issue3) => issue3.code),
|
|
171947
|
+
stageDurationsMs: diagnostics?.stageDurationsMs,
|
|
170995
171948
|
capabilityUid: capabilityUid ?? void 0,
|
|
170996
171949
|
capabilitySlug: capabilitySlug ?? void 0,
|
|
170997
171950
|
capabilityId: capabilityId ?? void 0,
|
|
@@ -171058,11 +172011,18 @@ var fetchCommand = (appContext) => new Command("fetch").description(
|
|
|
171058
172011
|
];
|
|
171059
172012
|
console.log(
|
|
171060
172013
|
JSON.stringify({
|
|
172014
|
+
fetchId,
|
|
171061
172015
|
runId,
|
|
171062
172016
|
ok,
|
|
172017
|
+
// The canonical FetchOutcome discriminator — the field an
|
|
172018
|
+
// agent branches on (payment_failed vs insufficient_funds
|
|
172019
|
+
// vs server_error vs …). `ok` alone can't distinguish them.
|
|
172020
|
+
outcome,
|
|
171063
172021
|
status,
|
|
171064
172022
|
latencyMs,
|
|
171065
172023
|
payment: payment ?? null,
|
|
172024
|
+
settlementState,
|
|
172025
|
+
diagnostics,
|
|
171066
172026
|
body: envBody,
|
|
171067
172027
|
bodyRaw: status === null ? null : bodyRaw,
|
|
171068
172028
|
...isBinary && { bodyEncoding: "base64" },
|
|
@@ -175130,11 +176090,11 @@ var PostHogCoreStateless = class {
|
|
|
175130
176090
|
let timeoutHandle;
|
|
175131
176091
|
try {
|
|
175132
176092
|
return await Promise.race([
|
|
175133
|
-
new Promise((_,
|
|
176093
|
+
new Promise((_, reject2) => {
|
|
175134
176094
|
timeoutHandle = safeSetTimeout(() => {
|
|
175135
176095
|
this._logger.error("Timed out while shutting down PostHog");
|
|
175136
176096
|
hasTimedOut = true;
|
|
175137
|
-
|
|
176097
|
+
reject2("Timeout while shutting down PostHog. Some events may not have been sent.");
|
|
175138
176098
|
}, shutdownTimeoutMs);
|
|
175139
176099
|
}),
|
|
175140
176100
|
doShutdown()
|
|
@@ -176583,7 +177543,7 @@ var FeatureFlagsPoller = class {
|
|
|
176583
177543
|
const shutdownResult = this.cacheProvider.shutdown();
|
|
176584
177544
|
if (shutdownResult instanceof Promise) await Promise.race([
|
|
176585
177545
|
shutdownResult,
|
|
176586
|
-
new Promise((_,
|
|
177546
|
+
new Promise((_, reject2) => setTimeout(() => reject2(new Error(`Cache shutdown timeout after ${timeoutMs}ms`)), timeoutMs))
|
|
176587
177547
|
]);
|
|
176588
177548
|
} catch (err) {
|
|
176589
177549
|
this.onError?.(new Error(`Error during cache shutdown: ${err}`));
|
|
@@ -177738,7 +178698,18 @@ var mapSdkEventToCliEvent = (event) => {
|
|
|
177738
178698
|
latencyMs: p.latency_ms,
|
|
177739
178699
|
hasPayment: p.has_payment,
|
|
177740
178700
|
paymentProtocol: orUndef(p.payment_protocol),
|
|
178701
|
+
fundingSource: orUndef(p.funding_source),
|
|
177741
178702
|
paymentAmount: dropUnknownAmount(p.payment_amount),
|
|
178703
|
+
paymentChain: orUndef(p.payment_chain),
|
|
178704
|
+
paymentMode: orUndef(p.payment_mode),
|
|
178705
|
+
paymentSessionChannelId: orUndef(p.payment_session_channel_id),
|
|
178706
|
+
hasSettlementAnchor: p.has_settlement_anchor,
|
|
178707
|
+
settlementState: orUndef(p.settlement_state),
|
|
178708
|
+
warningCodes: p.warning_codes,
|
|
178709
|
+
failureStage: orUndef(p.failure_stage),
|
|
178710
|
+
failureCode: orUndef(p.failure_code),
|
|
178711
|
+
diagnosticCodes: p.diagnostic_codes,
|
|
178712
|
+
stageDurationsMs: p.stage_durations_ms,
|
|
177742
178713
|
runId: orUndef(p.run_id),
|
|
177743
178714
|
runTracked: p.run_tracked,
|
|
177744
178715
|
error: orUndef(p.error),
|