@zeroxyz/cli 1.27.1 → 1.29.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 +2179 -461
- 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();
|
|
@@ -62738,10 +62738,10 @@ var require_provider_etherscan = __commonJS({
|
|
|
62738
62738
|
*
|
|
62739
62739
|
* If %%post%%, the request is made as a POST request.
|
|
62740
62740
|
*/
|
|
62741
|
-
async fetch(module2, params,
|
|
62741
|
+
async fetch(module2, params, post2) {
|
|
62742
62742
|
const id = nextId++;
|
|
62743
|
-
const url4 =
|
|
62744
|
-
const payload =
|
|
62743
|
+
const url4 = post2 ? this.getPostUrl() : this.getUrl(module2, params);
|
|
62744
|
+
const payload = post2 ? this.getPostData(module2, params) : null;
|
|
62745
62745
|
this.emit("debug", { action: "sendRequest", id, url: url4, payload });
|
|
62746
62746
|
const request3 = new index_js_4.FetchRequest(url4);
|
|
62747
62747
|
request3.setThrottleParams({ slotInterval: 1e3 });
|
|
@@ -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-5334O6ZN.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.22.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
|
}
|
|
@@ -166843,7 +167660,6 @@ var agentZeroSessionSchema = external_exports3.object({
|
|
|
166843
167660
|
user: external_exports3.object({ id: external_exports3.string() }).loose(),
|
|
166844
167661
|
walletAddress: external_exports3.string().optional()
|
|
166845
167662
|
}).loose();
|
|
166846
|
-
var JWT_BEARER_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:jwt-bearer";
|
|
166847
167663
|
var trimSlash = (value) => value.replace(/\/$/, "");
|
|
166848
167664
|
var wrapNetworkError = (url4, err) => {
|
|
166849
167665
|
const cause = err?.cause;
|
|
@@ -166853,6 +167669,80 @@ var wrapNetworkError = (url4, err) => {
|
|
|
166853
167669
|
cause: err
|
|
166854
167670
|
});
|
|
166855
167671
|
};
|
|
167672
|
+
var getJson = async (fetchImpl, url4) => {
|
|
167673
|
+
const response = await fetchImpl(url4).catch((err) => {
|
|
167674
|
+
throw wrapNetworkError(url4, err);
|
|
167675
|
+
});
|
|
167676
|
+
if (!response.ok) {
|
|
167677
|
+
throw new ZeroAgentAuthError(`GET ${url4} failed (${response.status})`, {
|
|
167678
|
+
status: response.status
|
|
167679
|
+
});
|
|
167680
|
+
}
|
|
167681
|
+
return await response.json();
|
|
167682
|
+
};
|
|
167683
|
+
var postJson = (fetchImpl, url4, body, schema) => post(fetchImpl, url4, "application/json", JSON.stringify(body), schema);
|
|
167684
|
+
var postForm = (fetchImpl, url4, fields, schema) => post(
|
|
167685
|
+
fetchImpl,
|
|
167686
|
+
url4,
|
|
167687
|
+
"application/x-www-form-urlencoded",
|
|
167688
|
+
new URLSearchParams(fields).toString(),
|
|
167689
|
+
schema
|
|
167690
|
+
);
|
|
167691
|
+
var post = async (fetchImpl, url4, contentType, body, schema) => {
|
|
167692
|
+
const response = await fetchImpl(url4, {
|
|
167693
|
+
method: "POST",
|
|
167694
|
+
headers: { "content-type": contentType },
|
|
167695
|
+
body
|
|
167696
|
+
}).catch((err) => {
|
|
167697
|
+
throw wrapNetworkError(url4, err);
|
|
167698
|
+
});
|
|
167699
|
+
const text = await response.text();
|
|
167700
|
+
let parsed = null;
|
|
167701
|
+
try {
|
|
167702
|
+
parsed = text ? JSON.parse(text) : null;
|
|
167703
|
+
} catch {
|
|
167704
|
+
}
|
|
167705
|
+
if (!response.ok) {
|
|
167706
|
+
const errBody = parsed;
|
|
167707
|
+
const code = errBody?.code ?? errBody?.error;
|
|
167708
|
+
throw new ZeroAgentAuthError(
|
|
167709
|
+
`Agent auth request to ${url4} failed (${response.status}${typeof code === "string" ? `: ${code}` : ""})`,
|
|
167710
|
+
{ status: response.status, body: parsed ?? text }
|
|
167711
|
+
);
|
|
167712
|
+
}
|
|
167713
|
+
return schema.parse(parsed);
|
|
167714
|
+
};
|
|
167715
|
+
var completeClaimAt = async (fetchImpl, claimEndpoint, input) => {
|
|
167716
|
+
try {
|
|
167717
|
+
const identity = await postJson(
|
|
167718
|
+
fetchImpl,
|
|
167719
|
+
`${claimEndpoint}/complete`,
|
|
167720
|
+
{ claim_token: input.claimToken, user_code: input.userCode },
|
|
167721
|
+
completeClaimResponseSchema
|
|
167722
|
+
);
|
|
167723
|
+
return { status: "ok", ...identity };
|
|
167724
|
+
} catch (err) {
|
|
167725
|
+
if (err instanceof ZeroAgentAuthError && err.serverCode) {
|
|
167726
|
+
if (err.serverCode === "claim_not_confirmed") {
|
|
167727
|
+
return { status: "not_confirmed" };
|
|
167728
|
+
}
|
|
167729
|
+
if (err.serverCode === "invalid_user_code") {
|
|
167730
|
+
return { status: "invalid_code" };
|
|
167731
|
+
}
|
|
167732
|
+
if ([
|
|
167733
|
+
"user_code_expired",
|
|
167734
|
+
"claim_expired",
|
|
167735
|
+
"claim_revoked",
|
|
167736
|
+
"already_claimed",
|
|
167737
|
+
"claim_denied"
|
|
167738
|
+
].includes(err.serverCode)) {
|
|
167739
|
+
return { status: "expired", code: err.serverCode };
|
|
167740
|
+
}
|
|
167741
|
+
}
|
|
167742
|
+
throw err;
|
|
167743
|
+
}
|
|
167744
|
+
};
|
|
167745
|
+
var JWT_BEARER_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:jwt-bearer";
|
|
166856
167746
|
var AuthAgent = class {
|
|
166857
167747
|
constructor(client) {
|
|
166858
167748
|
this.client = client;
|
|
@@ -166870,7 +167760,8 @@ var AuthAgent = class {
|
|
|
166870
167760
|
};
|
|
166871
167761
|
register = async () => {
|
|
166872
167762
|
const endpoints = await this.endpoints();
|
|
166873
|
-
return
|
|
167763
|
+
return postJson(
|
|
167764
|
+
this.client.fetchImpl,
|
|
166874
167765
|
endpoints.identityEndpoint,
|
|
166875
167766
|
{ type: "anonymous" },
|
|
166876
167767
|
identityEnvelopeSchema
|
|
@@ -166878,7 +167769,8 @@ var AuthAgent = class {
|
|
|
166878
167769
|
};
|
|
166879
167770
|
exchangeAssertion = async (identityAssertion) => {
|
|
166880
167771
|
const endpoints = await this.endpoints();
|
|
166881
|
-
return
|
|
167772
|
+
return postForm(
|
|
167773
|
+
this.client.fetchImpl,
|
|
166882
167774
|
endpoints.tokenEndpoint,
|
|
166883
167775
|
{ grant_type: JWT_BEARER_GRANT_TYPE, assertion: identityAssertion },
|
|
166884
167776
|
agentTokenResponseSchema
|
|
@@ -166908,7 +167800,8 @@ var AuthAgent = class {
|
|
|
166908
167800
|
{ status: 0 }
|
|
166909
167801
|
);
|
|
166910
167802
|
}
|
|
166911
|
-
return
|
|
167803
|
+
return postJson(
|
|
167804
|
+
this.client.fetchImpl,
|
|
166912
167805
|
endpoints.claimEndpoint,
|
|
166913
167806
|
{
|
|
166914
167807
|
type: "service_auth",
|
|
@@ -166918,8 +167811,6 @@ var AuthAgent = class {
|
|
|
166918
167811
|
startClaimResponseSchema
|
|
166919
167812
|
);
|
|
166920
167813
|
};
|
|
166921
|
-
// Submit the pairing code the human read off the hosted page. Terminal
|
|
166922
|
-
// states map to a typed result; anything unexpected throws.
|
|
166923
167814
|
completeClaim = async (input) => {
|
|
166924
167815
|
const endpoints = await this.endpoints();
|
|
166925
167816
|
if (!endpoints.claimEndpoint) {
|
|
@@ -166928,33 +167819,10 @@ var AuthAgent = class {
|
|
|
166928
167819
|
{ status: 0 }
|
|
166929
167820
|
);
|
|
166930
167821
|
}
|
|
166931
|
-
|
|
166932
|
-
|
|
166933
|
-
|
|
166934
|
-
|
|
166935
|
-
completeClaimResponseSchema
|
|
166936
|
-
);
|
|
166937
|
-
return { status: "ok", ...identity };
|
|
166938
|
-
} catch (err) {
|
|
166939
|
-
if (err instanceof ZeroAgentAuthError && err.serverCode) {
|
|
166940
|
-
if (err.serverCode === "claim_not_confirmed") {
|
|
166941
|
-
return { status: "not_confirmed" };
|
|
166942
|
-
}
|
|
166943
|
-
if (err.serverCode === "invalid_user_code") {
|
|
166944
|
-
return { status: "invalid_code" };
|
|
166945
|
-
}
|
|
166946
|
-
if ([
|
|
166947
|
-
"user_code_expired",
|
|
166948
|
-
"claim_expired",
|
|
166949
|
-
"claim_revoked",
|
|
166950
|
-
"already_claimed",
|
|
166951
|
-
"claim_denied"
|
|
166952
|
-
].includes(err.serverCode)) {
|
|
166953
|
-
return { status: "expired", code: err.serverCode };
|
|
166954
|
-
}
|
|
166955
|
-
}
|
|
166956
|
-
throw err;
|
|
166957
|
-
}
|
|
167822
|
+
return completeClaimAt(this.client.fetchImpl, endpoints.claimEndpoint, {
|
|
167823
|
+
claimToken: input.claimToken,
|
|
167824
|
+
userCode: input.userCode
|
|
167825
|
+
});
|
|
166958
167826
|
};
|
|
166959
167827
|
// Resolve (and cache) the agent-auth endpoints via discovery.
|
|
166960
167828
|
endpoints = () => {
|
|
@@ -166967,13 +167835,15 @@ var AuthAgent = class {
|
|
|
166967
167835
|
return this.endpointsPromise;
|
|
166968
167836
|
};
|
|
166969
167837
|
discover = async () => {
|
|
166970
|
-
const resource = await
|
|
167838
|
+
const resource = await getJson(
|
|
167839
|
+
this.client.fetchImpl,
|
|
166971
167840
|
`${trimSlash(this.client.baseUrl)}/.well-known/oauth-protected-resource`
|
|
166972
167841
|
);
|
|
166973
167842
|
let lastError = null;
|
|
166974
167843
|
for (const server of resource.authorization_servers ?? []) {
|
|
166975
167844
|
try {
|
|
166976
|
-
const raw = await
|
|
167845
|
+
const raw = await getJson(
|
|
167846
|
+
this.client.fetchImpl,
|
|
166977
167847
|
`${trimSlash(server)}/.well-known/oauth-authorization-server`
|
|
166978
167848
|
);
|
|
166979
167849
|
const metadata = agentAuthMetadataSchema.parse(raw);
|
|
@@ -166992,48 +167862,6 @@ var AuthAgent = class {
|
|
|
166992
167862
|
{ status: 0, cause: lastError }
|
|
166993
167863
|
);
|
|
166994
167864
|
};
|
|
166995
|
-
getJson = async (url4) => {
|
|
166996
|
-
const response = await this.client.fetchImpl(url4).catch((err) => {
|
|
166997
|
-
throw wrapNetworkError(url4, err);
|
|
166998
|
-
});
|
|
166999
|
-
if (!response.ok) {
|
|
167000
|
-
throw new ZeroAgentAuthError(`GET ${url4} failed (${response.status})`, {
|
|
167001
|
-
status: response.status
|
|
167002
|
-
});
|
|
167003
|
-
}
|
|
167004
|
-
return await response.json();
|
|
167005
|
-
};
|
|
167006
|
-
postJson = (url4, body, schema) => this.post(url4, "application/json", JSON.stringify(body), schema);
|
|
167007
|
-
postForm = (url4, fields, schema) => this.post(
|
|
167008
|
-
url4,
|
|
167009
|
-
"application/x-www-form-urlencoded",
|
|
167010
|
-
new URLSearchParams(fields).toString(),
|
|
167011
|
-
schema
|
|
167012
|
-
);
|
|
167013
|
-
post = async (url4, contentType, body, schema) => {
|
|
167014
|
-
const response = await this.client.fetchImpl(url4, {
|
|
167015
|
-
method: "POST",
|
|
167016
|
-
headers: { "content-type": contentType },
|
|
167017
|
-
body
|
|
167018
|
-
}).catch((err) => {
|
|
167019
|
-
throw wrapNetworkError(url4, err);
|
|
167020
|
-
});
|
|
167021
|
-
const text = await response.text();
|
|
167022
|
-
let parsed = null;
|
|
167023
|
-
try {
|
|
167024
|
-
parsed = text ? JSON.parse(text) : null;
|
|
167025
|
-
} catch {
|
|
167026
|
-
}
|
|
167027
|
-
if (!response.ok) {
|
|
167028
|
-
const errBody = parsed;
|
|
167029
|
-
const code = errBody?.code ?? errBody?.error;
|
|
167030
|
-
throw new ZeroAgentAuthError(
|
|
167031
|
-
`Agent auth request to ${url4} failed (${response.status}${typeof code === "string" ? `: ${code}` : ""})`,
|
|
167032
|
-
{ status: response.status, body: parsed ?? text }
|
|
167033
|
-
);
|
|
167034
|
-
}
|
|
167035
|
-
return schema.parse(parsed);
|
|
167036
|
-
};
|
|
167037
167865
|
};
|
|
167038
167866
|
var userWalletDtoSchema = external_exports3.object({
|
|
167039
167867
|
walletAddress: external_exports3.string(),
|
|
@@ -167144,6 +167972,294 @@ var AuthDevice = class {
|
|
|
167144
167972
|
};
|
|
167145
167973
|
};
|
|
167146
167974
|
};
|
|
167975
|
+
var ID_JAG_TOKEN_TYPE = "urn:ietf:params:oauth:token-type:id-jag";
|
|
167976
|
+
var idJagMintResponseSchema = external_exports3.object({
|
|
167977
|
+
access_token: external_exports3.string(),
|
|
167978
|
+
issued_token_type: external_exports3.string().optional(),
|
|
167979
|
+
expires_in: external_exports3.number().optional()
|
|
167980
|
+
}).loose().transform((raw) => ({
|
|
167981
|
+
idJag: raw.access_token,
|
|
167982
|
+
issuedTokenType: raw.issued_token_type ?? ID_JAG_TOKEN_TYPE,
|
|
167983
|
+
expiresIn: raw.expires_in ?? null
|
|
167984
|
+
}));
|
|
167985
|
+
var protectedResourceMetadataSchema = external_exports3.object({
|
|
167986
|
+
resource: external_exports3.string().optional(),
|
|
167987
|
+
resource_name: external_exports3.string().optional(),
|
|
167988
|
+
authorization_servers: external_exports3.array(external_exports3.string()).optional()
|
|
167989
|
+
}).loose();
|
|
167990
|
+
var serviceAuthMetadataSchema = external_exports3.object({
|
|
167991
|
+
resource: external_exports3.string().optional(),
|
|
167992
|
+
resource_name: external_exports3.string().optional(),
|
|
167993
|
+
token_endpoint: external_exports3.string().optional(),
|
|
167994
|
+
agent_auth: external_exports3.object({
|
|
167995
|
+
identity_endpoint: external_exports3.string(),
|
|
167996
|
+
claim_endpoint: external_exports3.string().optional(),
|
|
167997
|
+
identity_types_supported: external_exports3.array(external_exports3.string()).optional(),
|
|
167998
|
+
identity_assertion: external_exports3.object({
|
|
167999
|
+
assertion_types_supported: external_exports3.array(external_exports3.string()).optional(),
|
|
168000
|
+
// Optional shared-audience hint: a platform fronting many
|
|
168001
|
+
// storefronts advertises one audience (its AS) so a single
|
|
168002
|
+
// consent covers the network.
|
|
168003
|
+
audience: external_exports3.string().optional()
|
|
168004
|
+
}).loose().optional()
|
|
168005
|
+
}).loose()
|
|
168006
|
+
}).loose();
|
|
168007
|
+
var identityAssertionEnvelopeSchema = external_exports3.object({
|
|
168008
|
+
id: external_exports3.string(),
|
|
168009
|
+
identity: external_exports3.object({
|
|
168010
|
+
assertion: external_exports3.string(),
|
|
168011
|
+
expires_at: external_exports3.string().optional(),
|
|
168012
|
+
refresh_token: external_exports3.object({ value: external_exports3.string() }).loose().optional()
|
|
168013
|
+
}).loose(),
|
|
168014
|
+
assertion_expires: external_exports3.string().nullable().optional()
|
|
168015
|
+
}).loose().transform((raw) => ({
|
|
168016
|
+
registrationId: raw.id,
|
|
168017
|
+
identityAssertion: raw.identity.assertion,
|
|
168018
|
+
assertionExpires: raw.assertion_expires ?? raw.identity.expires_at ?? null,
|
|
168019
|
+
refreshToken: raw.identity.refresh_token?.value ?? null
|
|
168020
|
+
}));
|
|
168021
|
+
var interactionRequiredBodySchema = external_exports3.object({
|
|
168022
|
+
error_description: external_exports3.string().optional(),
|
|
168023
|
+
claim: external_exports3.object({
|
|
168024
|
+
token: external_exports3.string().optional(),
|
|
168025
|
+
expires_at: external_exports3.string().optional(),
|
|
168026
|
+
attempt: external_exports3.object({
|
|
168027
|
+
verification_uri: external_exports3.string().optional(),
|
|
168028
|
+
expires_at: external_exports3.string().optional()
|
|
168029
|
+
}).loose().optional()
|
|
168030
|
+
}).loose().optional()
|
|
168031
|
+
}).loose();
|
|
168032
|
+
var identityGrantSchema = external_exports3.object({ audience: external_exports3.string(), createdAt: external_exports3.string() }).loose();
|
|
168033
|
+
var identityGrantListSchema = external_exports3.object({ grants: external_exports3.array(identityGrantSchema) }).loose();
|
|
168034
|
+
var identityGrantRevokeSchema = external_exports3.object({ revoked: external_exports3.boolean() }).loose();
|
|
168035
|
+
var identityGrantRequestSchema = external_exports3.object({
|
|
168036
|
+
requestId: external_exports3.string(),
|
|
168037
|
+
approveUrl: external_exports3.string(),
|
|
168038
|
+
expiresAt: external_exports3.string()
|
|
168039
|
+
}).loose();
|
|
168040
|
+
var identityGrantRequestStatusSchema = external_exports3.object({
|
|
168041
|
+
requestId: external_exports3.string(),
|
|
168042
|
+
status: external_exports3.enum(["pending", "approved", "denied", "expired"]),
|
|
168043
|
+
audience: external_exports3.string(),
|
|
168044
|
+
resourceName: external_exports3.string().nullable().optional()
|
|
168045
|
+
}).loose();
|
|
168046
|
+
var TOKEN_EXCHANGE_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:token-exchange";
|
|
168047
|
+
var SUBJECT_TOKEN_TYPE_ACCESS_TOKEN = "urn:ietf:params:oauth:token-type:access_token";
|
|
168048
|
+
var JWT_BEARER_GRANT_TYPE2 = "urn:ietf:params:oauth:grant-type:jwt-bearer";
|
|
168049
|
+
var IDENTITY_ASSERTION_TYPE = "identity_assertion";
|
|
168050
|
+
var AuthIdentity = class {
|
|
168051
|
+
constructor(client) {
|
|
168052
|
+
this.client = client;
|
|
168053
|
+
}
|
|
168054
|
+
discover = async (url4) => {
|
|
168055
|
+
const origin2 = new URL(url4).origin;
|
|
168056
|
+
const prm = protectedResourceMetadataSchema.parse(
|
|
168057
|
+
await getJson(
|
|
168058
|
+
this.client.fetchImpl,
|
|
168059
|
+
`${origin2}/.well-known/oauth-protected-resource`
|
|
168060
|
+
)
|
|
168061
|
+
);
|
|
168062
|
+
let lastError = null;
|
|
168063
|
+
for (const server of prm.authorization_servers ?? [origin2]) {
|
|
168064
|
+
try {
|
|
168065
|
+
const metadata = serviceAuthMetadataSchema.parse(
|
|
168066
|
+
await getJson(
|
|
168067
|
+
this.client.fetchImpl,
|
|
168068
|
+
`${trimSlash(server)}/.well-known/oauth-authorization-server`
|
|
168069
|
+
)
|
|
168070
|
+
);
|
|
168071
|
+
const agentAuth = metadata.agent_auth;
|
|
168072
|
+
const assertionTypes = agentAuth.identity_assertion?.assertion_types_supported;
|
|
168073
|
+
const resource = prm.resource ?? `${origin2}/`;
|
|
168074
|
+
return {
|
|
168075
|
+
resource,
|
|
168076
|
+
mintAudience: agentAuth.identity_assertion?.audience ?? resource,
|
|
168077
|
+
resourceName: prm.resource_name ?? metadata.resource_name ?? null,
|
|
168078
|
+
authorizationServer: trimSlash(server),
|
|
168079
|
+
identityEndpoint: agentAuth.identity_endpoint,
|
|
168080
|
+
claimEndpoint: agentAuth.claim_endpoint ?? null,
|
|
168081
|
+
tokenEndpoint: metadata.token_endpoint ?? `${trimSlash(server)}/oauth2/token`,
|
|
168082
|
+
identityAssertionSupported: (agentAuth.identity_types_supported ?? []).includes(
|
|
168083
|
+
IDENTITY_ASSERTION_TYPE
|
|
168084
|
+
) && (assertionTypes ? assertionTypes.includes(ID_JAG_TOKEN_TYPE) : true)
|
|
168085
|
+
};
|
|
168086
|
+
} catch (err) {
|
|
168087
|
+
lastError = err;
|
|
168088
|
+
}
|
|
168089
|
+
}
|
|
168090
|
+
throw new ZeroAgentAuthError(
|
|
168091
|
+
`No authorization server with an agent_auth block found at ${origin2} \u2014 agent auth is not enabled for this service.`,
|
|
168092
|
+
{ status: 0, cause: lastError }
|
|
168093
|
+
);
|
|
168094
|
+
};
|
|
168095
|
+
// The minted grant is single-use (fresh jti) and minutes-lived — mint per
|
|
168096
|
+
// registration, never cache.
|
|
168097
|
+
mint = async (input) => {
|
|
168098
|
+
const attempt = () => {
|
|
168099
|
+
const credentials = this.client.getCredentials();
|
|
168100
|
+
if (credentials.kind !== "session") {
|
|
168101
|
+
throw new ZeroAuthError(
|
|
168102
|
+
"auth_no_credentials",
|
|
168103
|
+
"mint() requires session credentials \u2014 the ID-JAG asserts the signed-in user's identity."
|
|
168104
|
+
);
|
|
168105
|
+
}
|
|
168106
|
+
return request2(
|
|
168107
|
+
this.client,
|
|
168108
|
+
{
|
|
168109
|
+
method: "POST",
|
|
168110
|
+
path: "/v1/oauth/token",
|
|
168111
|
+
body: {
|
|
168112
|
+
grant_type: TOKEN_EXCHANGE_GRANT_TYPE,
|
|
168113
|
+
subject_token: credentials.accessToken,
|
|
168114
|
+
subject_token_type: SUBJECT_TOKEN_TYPE_ACCESS_TOKEN,
|
|
168115
|
+
audience: input.audience,
|
|
168116
|
+
requested_token_type: ID_JAG_TOKEN_TYPE
|
|
168117
|
+
}
|
|
168118
|
+
},
|
|
168119
|
+
idJagMintResponseSchema
|
|
168120
|
+
);
|
|
168121
|
+
};
|
|
168122
|
+
try {
|
|
168123
|
+
return await attempt();
|
|
168124
|
+
} catch (err) {
|
|
168125
|
+
if (err instanceof ZeroApiError && err.status === 400 && err.body?.error === "invalid_grant" && await this.client.refreshSessionOnce()) {
|
|
168126
|
+
return await attempt();
|
|
168127
|
+
}
|
|
168128
|
+
throw err;
|
|
168129
|
+
}
|
|
168130
|
+
};
|
|
168131
|
+
// Recoverable protocol states come back as typed outcomes; mint-bug
|
|
168132
|
+
// rejections (invalid_audience, expired, …) throw. replay_detected is
|
|
168133
|
+
// retried once with a freshly minted grant (single-use jti).
|
|
168134
|
+
assert = async (input) => {
|
|
168135
|
+
let discovery;
|
|
168136
|
+
try {
|
|
168137
|
+
discovery = input.discovery ?? await this.discover(input.url);
|
|
168138
|
+
} catch (err) {
|
|
168139
|
+
if (err instanceof ZeroAgentAuthError) {
|
|
168140
|
+
return { status: "unsupported", discovery: null };
|
|
168141
|
+
}
|
|
168142
|
+
throw err;
|
|
168143
|
+
}
|
|
168144
|
+
if (!discovery.identityAssertionSupported) {
|
|
168145
|
+
return { status: "unsupported", discovery };
|
|
168146
|
+
}
|
|
168147
|
+
try {
|
|
168148
|
+
return await this.register(discovery);
|
|
168149
|
+
} catch (err) {
|
|
168150
|
+
if (err instanceof ZeroAgentAuthError && err.serverCode === "replay_detected") {
|
|
168151
|
+
return await this.register(discovery);
|
|
168152
|
+
}
|
|
168153
|
+
throw err;
|
|
168154
|
+
}
|
|
168155
|
+
};
|
|
168156
|
+
// RFC 7523 jwt-bearer. Bearer tokens are minutes-lived: exchange per work
|
|
168157
|
+
// session, persist only the assertion + refresh token.
|
|
168158
|
+
exchange = (input) => postForm(
|
|
168159
|
+
this.client.fetchImpl,
|
|
168160
|
+
input.tokenEndpoint,
|
|
168161
|
+
{ grant_type: JWT_BEARER_GRANT_TYPE2, assertion: input.assertion },
|
|
168162
|
+
agentTokenResponseSchema
|
|
168163
|
+
);
|
|
168164
|
+
completeClaim = (input) => completeClaimAt(this.client.fetchImpl, input.claimEndpoint, {
|
|
168165
|
+
claimToken: input.claimToken,
|
|
168166
|
+
userCode: input.userCode
|
|
168167
|
+
});
|
|
168168
|
+
grants = (opts = {}) => request2(
|
|
168169
|
+
this.client,
|
|
168170
|
+
{
|
|
168171
|
+
method: "GET",
|
|
168172
|
+
path: "/v1/users/me/identity-grants",
|
|
168173
|
+
signal: opts.signal
|
|
168174
|
+
},
|
|
168175
|
+
identityGrantListSchema
|
|
168176
|
+
).then((body) => body.grants);
|
|
168177
|
+
// `resourceUrl` lets the server verify and display the service's
|
|
168178
|
+
// name/logo on the approve page. Poll grantRequest() until decided.
|
|
168179
|
+
requestGrant = (input) => request2(
|
|
168180
|
+
this.client,
|
|
168181
|
+
{
|
|
168182
|
+
method: "POST",
|
|
168183
|
+
path: "/v1/users/me/identity-grants/requests",
|
|
168184
|
+
body: {
|
|
168185
|
+
audience: input.audience,
|
|
168186
|
+
...input.resourceUrl ? { resourceUrl: input.resourceUrl } : {}
|
|
168187
|
+
}
|
|
168188
|
+
},
|
|
168189
|
+
identityGrantRequestSchema
|
|
168190
|
+
);
|
|
168191
|
+
grantRequest = (requestId, opts = {}) => request2(
|
|
168192
|
+
this.client,
|
|
168193
|
+
{
|
|
168194
|
+
method: "GET",
|
|
168195
|
+
path: `/v1/users/me/identity-grants/requests/${requestId}`,
|
|
168196
|
+
signal: opts.signal
|
|
168197
|
+
},
|
|
168198
|
+
identityGrantRequestStatusSchema
|
|
168199
|
+
);
|
|
168200
|
+
revokeGrant = (input) => request2(
|
|
168201
|
+
this.client,
|
|
168202
|
+
{
|
|
168203
|
+
method: "DELETE",
|
|
168204
|
+
path: "/v1/users/me/identity-grants",
|
|
168205
|
+
query: { audience: input.audience }
|
|
168206
|
+
},
|
|
168207
|
+
identityGrantRevokeSchema
|
|
168208
|
+
).then((body) => body.revoked);
|
|
168209
|
+
register = async (discovery) => {
|
|
168210
|
+
let minted;
|
|
168211
|
+
try {
|
|
168212
|
+
minted = await this.mint({ audience: discovery.mintAudience });
|
|
168213
|
+
} catch (err) {
|
|
168214
|
+
if (err instanceof ZeroApiError && err.body?.error === "consent_required") {
|
|
168215
|
+
return { status: "consent_required", discovery };
|
|
168216
|
+
}
|
|
168217
|
+
throw err;
|
|
168218
|
+
}
|
|
168219
|
+
try {
|
|
168220
|
+
const registration = await postJson(
|
|
168221
|
+
this.client.fetchImpl,
|
|
168222
|
+
discovery.identityEndpoint,
|
|
168223
|
+
{
|
|
168224
|
+
type: IDENTITY_ASSERTION_TYPE,
|
|
168225
|
+
assertion_type: ID_JAG_TOKEN_TYPE,
|
|
168226
|
+
assertion: minted.idJag
|
|
168227
|
+
},
|
|
168228
|
+
identityAssertionEnvelopeSchema
|
|
168229
|
+
);
|
|
168230
|
+
return { status: "ok", discovery, registration };
|
|
168231
|
+
} catch (err) {
|
|
168232
|
+
if (err instanceof ZeroAgentAuthError) {
|
|
168233
|
+
if (err.serverCode === "issuer_not_enabled") {
|
|
168234
|
+
return { status: "issuer_not_enabled", discovery };
|
|
168235
|
+
}
|
|
168236
|
+
const description = err.body?.error_description;
|
|
168237
|
+
if (err.serverCode === "login_required") {
|
|
168238
|
+
return {
|
|
168239
|
+
status: "login_required",
|
|
168240
|
+
discovery,
|
|
168241
|
+
description: typeof description === "string" ? description : null
|
|
168242
|
+
};
|
|
168243
|
+
}
|
|
168244
|
+
if (err.serverCode === "interaction_required") {
|
|
168245
|
+
const body = interactionRequiredBodySchema.safeParse(err.body);
|
|
168246
|
+
const claim3 = body.success ? body.data.claim : void 0;
|
|
168247
|
+
return {
|
|
168248
|
+
status: "interaction_required",
|
|
168249
|
+
discovery,
|
|
168250
|
+
claim: {
|
|
168251
|
+
claimToken: claim3?.token ?? null,
|
|
168252
|
+
claimTokenExpires: claim3?.expires_at ?? null,
|
|
168253
|
+
verificationUri: claim3?.attempt?.verification_uri ?? null,
|
|
168254
|
+
description: body.success ? body.data.error_description ?? null : null
|
|
168255
|
+
}
|
|
168256
|
+
};
|
|
168257
|
+
}
|
|
168258
|
+
}
|
|
168259
|
+
throw err;
|
|
168260
|
+
}
|
|
168261
|
+
};
|
|
168262
|
+
};
|
|
167147
168263
|
var userWalletsSchema = external_exports3.array(userWalletDtoSchema);
|
|
167148
168264
|
var normalizeMessage = (message2) => {
|
|
167149
168265
|
if (typeof message2 === "string") return message2;
|
|
@@ -167151,13 +168267,22 @@ var normalizeMessage = (message2) => {
|
|
|
167151
168267
|
return bytesToHex(message2.raw);
|
|
167152
168268
|
};
|
|
167153
168269
|
var repackageSignFailure = (err, op) => {
|
|
167154
|
-
if (err instanceof ZeroApiError
|
|
168270
|
+
if (err instanceof ZeroApiError) {
|
|
167155
168271
|
const body = err.body;
|
|
167156
168272
|
const detail = body && typeof body.error === "string" ? `: ${body.error}` : "";
|
|
167157
|
-
|
|
167158
|
-
|
|
167159
|
-
|
|
167160
|
-
|
|
168273
|
+
if (err.status === 400 || err.status === 402) {
|
|
168274
|
+
throw new ZeroPaymentError(
|
|
168275
|
+
`Sign endpoint refused ${op} (HTTP ${err.status})${detail}`,
|
|
168276
|
+
{ cause: err }
|
|
168277
|
+
);
|
|
168278
|
+
}
|
|
168279
|
+
if (err.status === 403 || err.status === 404) {
|
|
168280
|
+
throw new ZeroAuthError(
|
|
168281
|
+
"auth_error",
|
|
168282
|
+
`Managed signer refused ${op} (HTTP ${err.status})${detail}`,
|
|
168283
|
+
{ cause: err }
|
|
168284
|
+
);
|
|
168285
|
+
}
|
|
167161
168286
|
}
|
|
167162
168287
|
throw err;
|
|
167163
168288
|
};
|
|
@@ -167166,9 +168291,11 @@ var Auth = class {
|
|
|
167166
168291
|
this.client = client;
|
|
167167
168292
|
this.agent = new AuthAgent(client);
|
|
167168
168293
|
this.device = new AuthDevice(client);
|
|
168294
|
+
this.identity = new AuthIdentity(client);
|
|
167169
168295
|
}
|
|
167170
168296
|
agent;
|
|
167171
168297
|
device;
|
|
168298
|
+
identity;
|
|
167172
168299
|
// The internal (web-app facing) user profile. Richer than profile(): full
|
|
167173
168300
|
// wallet list with per-wallet delegation/signer/limit metadata.
|
|
167174
168301
|
me = (opts = {}) => request2(
|
|
@@ -167583,6 +168710,13 @@ var Capabilities = class {
|
|
|
167583
168710
|
}
|
|
167584
168711
|
};
|
|
167585
168712
|
};
|
|
168713
|
+
var paymentSessionSchema = external_exports3.object({
|
|
168714
|
+
channelId: external_exports3.string().regex(/^0x[0-9a-fA-F]{64}$/),
|
|
168715
|
+
escrowContract: external_exports3.string().regex(/^0x[0-9a-fA-F]{40}$/),
|
|
168716
|
+
chainId: external_exports3.number().int().positive(),
|
|
168717
|
+
recipient: external_exports3.string().regex(/^0x[0-9a-fA-F]{40}$/).nullable(),
|
|
168718
|
+
cumulativeAmount: external_exports3.string().regex(/^(?:0|[1-9]\d*)$/)
|
|
168719
|
+
}).strict();
|
|
167586
168720
|
var createRunResponseSchema = external_exports3.object({
|
|
167587
168721
|
runId: external_exports3.string()
|
|
167588
168722
|
});
|
|
@@ -167598,7 +168732,8 @@ var runListItemSchema = external_exports3.object({
|
|
|
167598
168732
|
protocol: external_exports3.string(),
|
|
167599
168733
|
chain: external_exports3.string().nullable(),
|
|
167600
168734
|
txHash: external_exports3.string().nullable(),
|
|
167601
|
-
mode: external_exports3.string().nullable()
|
|
168735
|
+
mode: external_exports3.string().nullable(),
|
|
168736
|
+
session: paymentSessionSchema.nullable().optional().default(null)
|
|
167602
168737
|
}).nullable(),
|
|
167603
168738
|
createdAt: external_exports3.coerce.date(),
|
|
167604
168739
|
reviewed: external_exports3.boolean()
|
|
@@ -167618,7 +168753,8 @@ var runDetailSchema = external_exports3.object({
|
|
|
167618
168753
|
protocol: external_exports3.string(),
|
|
167619
168754
|
chain: external_exports3.string().nullable(),
|
|
167620
168755
|
txHash: external_exports3.string().nullable(),
|
|
167621
|
-
mode: external_exports3.string().nullable()
|
|
168756
|
+
mode: external_exports3.string().nullable(),
|
|
168757
|
+
session: paymentSessionSchema.nullable().optional().default(null)
|
|
167622
168758
|
}).nullable(),
|
|
167623
168759
|
capability: external_exports3.object({
|
|
167624
168760
|
uid: external_exports3.string(),
|
|
@@ -167674,6 +168810,18 @@ var Runs = class _Runs {
|
|
|
167674
168810
|
* unattributed runs, which it can't do if we strip the target as well.
|
|
167675
168811
|
*/
|
|
167676
168812
|
static FIELD_GENERATIONS = [
|
|
168813
|
+
// MPP channel anchor for close-failure reconciliation. Peels first so a
|
|
168814
|
+
// newer SDK still records all prior diagnostics against an older API.
|
|
168815
|
+
["paymentSession"],
|
|
168816
|
+
// Phase-localized observability + settlement confirmation.
|
|
168817
|
+
[
|
|
168818
|
+
"settlementState",
|
|
168819
|
+
"failureStage",
|
|
168820
|
+
"failureCode",
|
|
168821
|
+
"fundingSource",
|
|
168822
|
+
"stageDurationsMs",
|
|
168823
|
+
"warningCodes"
|
|
168824
|
+
],
|
|
167677
168825
|
// Newest: correlation + honest classification.
|
|
167678
168826
|
["fetchId", "outcome"],
|
|
167679
168827
|
// ZERO-536: the direct-URL target. Dropping this loses attribution for an
|
|
@@ -167690,7 +168838,7 @@ var Runs = class _Runs {
|
|
|
167690
168838
|
* target left to name, so that server could never have recorded it.
|
|
167691
168839
|
*/
|
|
167692
168840
|
create = async (input, opts = {}) => {
|
|
167693
|
-
const
|
|
168841
|
+
const post2 = (body) => request2(
|
|
167694
168842
|
this.client,
|
|
167695
168843
|
{
|
|
167696
168844
|
method: "POST",
|
|
@@ -167704,7 +168852,7 @@ var Runs = class _Runs {
|
|
|
167704
168852
|
let generation = 0;
|
|
167705
168853
|
for (; ; ) {
|
|
167706
168854
|
try {
|
|
167707
|
-
return await
|
|
168855
|
+
return await post2(payload);
|
|
167708
168856
|
} catch (err) {
|
|
167709
168857
|
const rejected = err instanceof ZeroApiError && (err.status === 400 || err.status === 422);
|
|
167710
168858
|
if (!rejected) throw err;
|
|
@@ -168172,11 +169320,7 @@ var classifyFetchError = (error98) => {
|
|
|
168172
169320
|
}
|
|
168173
169321
|
};
|
|
168174
169322
|
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";
|
|
169323
|
+
return isCallerAbortError(error98);
|
|
168180
169324
|
};
|
|
168181
169325
|
var AnalyticsEmitter = class {
|
|
168182
169326
|
isEnabled;
|
|
@@ -168257,8 +169401,19 @@ var AnalyticsEmitter = class {
|
|
|
168257
169401
|
error_class: res.outcome === "success" ? null : outcomeToErrorClass(res.outcome, res.status),
|
|
168258
169402
|
latency_ms: res.latencyMs,
|
|
168259
169403
|
has_payment: res.payment !== null,
|
|
168260
|
-
payment_protocol: res.payment?.protocol ?? null,
|
|
169404
|
+
payment_protocol: res.payment?.protocol ?? res.diagnostics?.paymentProtocol ?? null,
|
|
169405
|
+
funding_source: res.diagnostics?.fundingSource ?? null,
|
|
168261
169406
|
payment_amount: res.payment?.amount ?? null,
|
|
169407
|
+
payment_chain: res.payment?.chain ?? null,
|
|
169408
|
+
payment_mode: res.diagnostics?.paymentMode ?? (res.payment?.session ? "session" : res.payment ? "charge" : null),
|
|
169409
|
+
has_settlement_anchor: res.diagnostics?.paymentMode !== "proof" && res.payment !== null && (res.payment.txHash !== null || res.payment.session !== void 0),
|
|
169410
|
+
payment_session_channel_id: res.payment?.session?.channelId ?? null,
|
|
169411
|
+
settlement_state: res.settlementState ?? null,
|
|
169412
|
+
warning_codes: res.warnings ?? [],
|
|
169413
|
+
failure_stage: res.diagnostics?.failureStage ?? null,
|
|
169414
|
+
failure_code: res.diagnostics?.failureCode ?? null,
|
|
169415
|
+
diagnostic_codes: res.diagnostics?.issues.map((issue3) => issue3.code) ?? [],
|
|
169416
|
+
stage_durations_ms: res.diagnostics?.stageDurationsMs ?? {},
|
|
168262
169417
|
// Opaque cap uid / slug / attribution token — not PII, useful for
|
|
168263
169418
|
// joining back to the capabilities table in BI.
|
|
168264
169419
|
capability_id: opts.capabilityId ?? null,
|
|
@@ -168277,12 +169432,20 @@ var AnalyticsEmitter = class {
|
|
|
168277
169432
|
error_snippet_length: res.upstreamError?.snippetLength ?? null
|
|
168278
169433
|
});
|
|
168279
169434
|
}
|
|
168280
|
-
fetchError(url4, opts, error98, errorClass, status) {
|
|
169435
|
+
fetchError(url4, opts, error98, errorClass, status, fetchId = null, diagnostics) {
|
|
168281
169436
|
if (!this.sink) return;
|
|
168282
169437
|
this.emit("fetch_error", {
|
|
168283
169438
|
url: redactUrl(url4),
|
|
168284
169439
|
error_class: errorClass,
|
|
168285
169440
|
status,
|
|
169441
|
+
fetch_id: fetchId,
|
|
169442
|
+
failure_stage: diagnostics?.failureStage ?? null,
|
|
169443
|
+
failure_code: diagnostics?.failureCode ?? null,
|
|
169444
|
+
payment_protocol: diagnostics?.paymentProtocol ?? null,
|
|
169445
|
+
payment_mode: diagnostics?.paymentMode ?? null,
|
|
169446
|
+
funding_source: diagnostics?.fundingSource ?? null,
|
|
169447
|
+
diagnostic_codes: diagnostics?.issues.map((issue3) => issue3.code) ?? [],
|
|
169448
|
+
stage_durations_ms: diagnostics?.stageDurationsMs ?? {},
|
|
168286
169449
|
capability_id: opts.capabilityId ?? null,
|
|
168287
169450
|
search_id: opts.searchId ?? null,
|
|
168288
169451
|
error: safeErrorLabel(error98, errorClass)
|
|
@@ -168386,6 +169549,10 @@ var ZeroClient = class _ZeroClient {
|
|
|
168386
169549
|
// public surface is the constructor option + emitted event types, not the
|
|
168387
169550
|
// mutable emitter implementation.
|
|
168388
169551
|
analytics;
|
|
169552
|
+
// Every session token this client has held. Keep rotated values for the
|
|
169553
|
+
// client's lifetime so a delayed rejection from an old request cannot leak
|
|
169554
|
+
// the previous access/refresh token through a consumer logger.
|
|
169555
|
+
sensitiveLogValues = /* @__PURE__ */ new Set();
|
|
168389
169556
|
// Private — read via getCredentials(), mutate only via applyRefreshedTokens().
|
|
168390
169557
|
// Keeping a single mutator funnel is what lets the transport replay
|
|
168391
169558
|
// requests with a fresh access token after a 401 → refresh.
|
|
@@ -168436,6 +169603,9 @@ var ZeroClient = class _ZeroClient {
|
|
|
168436
169603
|
refreshOverride;
|
|
168437
169604
|
constructor(options = {}) {
|
|
168438
169605
|
this.credentials = normalizeCredentials(options.session, options.account);
|
|
169606
|
+
if (this.credentials.kind === "session") {
|
|
169607
|
+
this.rememberSessionTokens(this.credentials);
|
|
169608
|
+
}
|
|
168439
169609
|
this.baseUrl = options.baseUrl ?? DEFAULT_BASE_URL;
|
|
168440
169610
|
this.timeout = options.timeout ?? DEFAULT_TIMEOUT_MS;
|
|
168441
169611
|
this.maxRetries = options.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
@@ -168443,7 +169613,7 @@ var ZeroClient = class _ZeroClient {
|
|
|
168443
169613
|
this.defaultHeaders = options.defaultHeaders ?? {};
|
|
168444
169614
|
this.fetchImpl = options.fetch ?? ((...args) => globalThis.fetch(...args));
|
|
168445
169615
|
this.fetchOptions = options.fetchOptions;
|
|
168446
|
-
this.logger = options.logger;
|
|
169616
|
+
this.logger = options.logger ? (event) => options.logger?.(this.redactLogEvent(event)) : void 0;
|
|
168447
169617
|
this.analyticsOptions = options.analytics;
|
|
168448
169618
|
this.refreshOverride = options.refresh;
|
|
168449
169619
|
this.withAccountCache = options._sharedAccountCache ?? /* @__PURE__ */ new Map();
|
|
@@ -168517,6 +169687,7 @@ var ZeroClient = class _ZeroClient {
|
|
|
168517
169687
|
// still considered the source of truth for the current process.
|
|
168518
169688
|
applyRefreshedTokens = async (next) => {
|
|
168519
169689
|
if (this.credentials.kind !== "session") return;
|
|
169690
|
+
this.rememberSessionTokens(next);
|
|
168520
169691
|
this.credentials = {
|
|
168521
169692
|
...this.credentials,
|
|
168522
169693
|
accessToken: next.accessToken,
|
|
@@ -168539,12 +169710,55 @@ var ZeroClient = class _ZeroClient {
|
|
|
168539
169710
|
// callback). No-op outside session mode.
|
|
168540
169711
|
setSessionTokens = (tokens2) => {
|
|
168541
169712
|
if (this.credentials.kind !== "session") return;
|
|
169713
|
+
this.rememberSessionTokens(tokens2);
|
|
168542
169714
|
this.credentials = {
|
|
168543
169715
|
...this.credentials,
|
|
168544
169716
|
accessToken: tokens2.accessToken,
|
|
168545
169717
|
refreshToken: tokens2.refreshToken
|
|
168546
169718
|
};
|
|
168547
169719
|
};
|
|
169720
|
+
rememberSessionTokens = (tokens2) => {
|
|
169721
|
+
if (tokens2.accessToken) this.sensitiveLogValues.add(tokens2.accessToken);
|
|
169722
|
+
if (tokens2.refreshToken) this.sensitiveLogValues.add(tokens2.refreshToken);
|
|
169723
|
+
};
|
|
169724
|
+
redactLogString = (value) => {
|
|
169725
|
+
let redacted = value;
|
|
169726
|
+
for (const secret of this.sensitiveLogValues) {
|
|
169727
|
+
redacted = redacted.split(secret).join("[REDACTED]");
|
|
169728
|
+
}
|
|
169729
|
+
return redacted;
|
|
169730
|
+
};
|
|
169731
|
+
redactLogValue = (value, key, seen) => {
|
|
169732
|
+
if (key && /(?:authorization|access[_-]?token|refresh[_-]?token|session[_-]?token)/i.test(
|
|
169733
|
+
key
|
|
169734
|
+
)) {
|
|
169735
|
+
return "[REDACTED]";
|
|
169736
|
+
}
|
|
169737
|
+
if (typeof value === "string") return this.redactLogString(value);
|
|
169738
|
+
if (!value || typeof value !== "object") return value;
|
|
169739
|
+
if (seen.has(value)) return "[Circular]";
|
|
169740
|
+
seen.add(value);
|
|
169741
|
+
if (Array.isArray(value)) {
|
|
169742
|
+
return value.map((item) => this.redactLogValue(item, void 0, seen));
|
|
169743
|
+
}
|
|
169744
|
+
return Object.fromEntries(
|
|
169745
|
+
Object.entries(value).map(([childKey, childValue]) => [
|
|
169746
|
+
childKey,
|
|
169747
|
+
this.redactLogValue(childValue, childKey, seen)
|
|
169748
|
+
])
|
|
169749
|
+
);
|
|
169750
|
+
};
|
|
169751
|
+
redactLogEvent = (event) => ({
|
|
169752
|
+
...event,
|
|
169753
|
+
message: this.redactLogString(event.message),
|
|
169754
|
+
...event.meta && {
|
|
169755
|
+
meta: this.redactLogValue(
|
|
169756
|
+
event.meta,
|
|
169757
|
+
void 0,
|
|
169758
|
+
/* @__PURE__ */ new WeakSet()
|
|
169759
|
+
)
|
|
169760
|
+
}
|
|
169761
|
+
});
|
|
168548
169762
|
// Returns a new client bound to a different session, inheriting
|
|
168549
169763
|
// transport config but with its own credential slot. Refreshes on the
|
|
168550
169764
|
// sub-client never mutate the base — critical for multi-tenant servers
|
|
@@ -168735,8 +169949,8 @@ var ZeroClient = class _ZeroClient {
|
|
|
168735
169949
|
return Promise.reject(
|
|
168736
169950
|
abortErr(new DOMException("Aborted", "AbortError"))
|
|
168737
169951
|
);
|
|
168738
|
-
return new Promise((resolve7,
|
|
168739
|
-
const onAbort = () =>
|
|
169952
|
+
return new Promise((resolve7, reject2) => {
|
|
169953
|
+
const onAbort = () => reject2(abortErr(new DOMException("Aborted", "AbortError")));
|
|
168740
169954
|
signal.addEventListener("abort", onAbort, { once: true });
|
|
168741
169955
|
p.then(
|
|
168742
169956
|
(v) => {
|
|
@@ -168745,7 +169959,7 @@ var ZeroClient = class _ZeroClient {
|
|
|
168745
169959
|
},
|
|
168746
169960
|
(e) => {
|
|
168747
169961
|
signal.removeEventListener("abort", onAbort);
|
|
168748
|
-
|
|
169962
|
+
reject2(e);
|
|
168749
169963
|
}
|
|
168750
169964
|
);
|
|
168751
169965
|
});
|
|
@@ -168783,15 +169997,32 @@ var ZeroClient = class _ZeroClient {
|
|
|
168783
169997
|
// path is flat on the client, same rationale as `search` above.
|
|
168784
169998
|
// Orchestration lives in fetch.ts so this class stays readable.
|
|
168785
169999
|
fetch = async (url4, opts = {}) => {
|
|
170000
|
+
const fetchId = randomUUID();
|
|
170001
|
+
const diagnostics = new FetchDiagnosticContext(fetchId);
|
|
168786
170002
|
try {
|
|
168787
|
-
const result = await clientFetch(this, url4, opts);
|
|
170003
|
+
const result = await clientFetch(this, url4, opts, diagnostics);
|
|
170004
|
+
result.diagnostics = diagnostics.snapshot();
|
|
170005
|
+
result.settlementState = settlementStateFor(
|
|
170006
|
+
result.payment,
|
|
170007
|
+
result.warnings,
|
|
170008
|
+
diagnostics.snapshot()
|
|
170009
|
+
);
|
|
168788
170010
|
this.analytics.fetchExecuted(url4, opts, result);
|
|
168789
170011
|
return result;
|
|
168790
170012
|
} catch (error98) {
|
|
168791
170013
|
if (this.analytics.isEnabled && !isCallerAbort(error98)) {
|
|
168792
170014
|
const { errorClass, status } = classifyFetchError(error98);
|
|
168793
|
-
this.analytics.fetchError(
|
|
170015
|
+
this.analytics.fetchError(
|
|
170016
|
+
url4,
|
|
170017
|
+
opts,
|
|
170018
|
+
error98,
|
|
170019
|
+
errorClass,
|
|
170020
|
+
status,
|
|
170021
|
+
fetchId,
|
|
170022
|
+
diagnostics.snapshot()
|
|
170023
|
+
);
|
|
168794
170024
|
}
|
|
170025
|
+
attachFetchErrorContext(error98, fetchId, diagnostics.snapshot());
|
|
168795
170026
|
throw error98;
|
|
168796
170027
|
}
|
|
168797
170028
|
};
|
|
@@ -169026,7 +170257,7 @@ var placeholderFor = (fieldName, propSchema) => String(sampleValueFor(fieldName,
|
|
|
169026
170257
|
|
|
169027
170258
|
// package.json
|
|
169028
170259
|
var package_default2 = {
|
|
169029
|
-
version: "1.
|
|
170260
|
+
version: "1.29.0"};
|
|
169030
170261
|
|
|
169031
170262
|
// src/app.ts
|
|
169032
170263
|
init_esm_shims();
|
|
@@ -169549,11 +170780,11 @@ var baseOpen = async (options) => {
|
|
|
169549
170780
|
}
|
|
169550
170781
|
const subprocess = childProcess.spawn(command, cliArguments, childProcessOptions);
|
|
169551
170782
|
if (options.wait) {
|
|
169552
|
-
return new Promise((resolve7,
|
|
169553
|
-
subprocess.once("error",
|
|
170783
|
+
return new Promise((resolve7, reject2) => {
|
|
170784
|
+
subprocess.once("error", reject2);
|
|
169554
170785
|
subprocess.once("close", (exitCode) => {
|
|
169555
170786
|
if (!options.allowNonzeroExitCode && exitCode !== 0) {
|
|
169556
|
-
|
|
170787
|
+
reject2(new Error(`Exited with code ${exitCode}`));
|
|
169557
170788
|
return;
|
|
169558
170789
|
}
|
|
169559
170790
|
resolve7(subprocess);
|
|
@@ -169561,13 +170792,13 @@ var baseOpen = async (options) => {
|
|
|
169561
170792
|
});
|
|
169562
170793
|
}
|
|
169563
170794
|
if (isFallbackAttempt) {
|
|
169564
|
-
return new Promise((resolve7,
|
|
169565
|
-
subprocess.once("error",
|
|
170795
|
+
return new Promise((resolve7, reject2) => {
|
|
170796
|
+
subprocess.once("error", reject2);
|
|
169566
170797
|
subprocess.once("spawn", () => {
|
|
169567
170798
|
subprocess.once("close", (exitCode) => {
|
|
169568
|
-
subprocess.off("error",
|
|
170799
|
+
subprocess.off("error", reject2);
|
|
169569
170800
|
if (exitCode !== 0) {
|
|
169570
|
-
|
|
170801
|
+
reject2(new Error(`Exited with code ${exitCode}`));
|
|
169571
170802
|
return;
|
|
169572
170803
|
}
|
|
169573
170804
|
subprocess.unref();
|
|
@@ -169577,10 +170808,10 @@ var baseOpen = async (options) => {
|
|
|
169577
170808
|
});
|
|
169578
170809
|
}
|
|
169579
170810
|
subprocess.unref();
|
|
169580
|
-
return new Promise((resolve7,
|
|
169581
|
-
subprocess.once("error",
|
|
170811
|
+
return new Promise((resolve7, reject2) => {
|
|
170812
|
+
subprocess.once("error", reject2);
|
|
169582
170813
|
subprocess.once("spawn", () => {
|
|
169583
|
-
subprocess.off("error",
|
|
170814
|
+
subprocess.off("error", reject2);
|
|
169584
170815
|
resolve7(subprocess);
|
|
169585
170816
|
});
|
|
169586
170817
|
});
|
|
@@ -169678,13 +170909,458 @@ var readConfig = (path3) => {
|
|
|
169678
170909
|
}
|
|
169679
170910
|
};
|
|
169680
170911
|
|
|
169681
|
-
// src/commands/auth-command.ts
|
|
170912
|
+
// src/commands/auth-identity-command.ts
|
|
170913
|
+
init_esm_shims();
|
|
169682
170914
|
var getConfigPath = () => join$1(homedir(), ".zero", "config.json");
|
|
170915
|
+
var CLAIM_NOT_CONFIRMED_RETRIES = 12;
|
|
170916
|
+
var CLAIM_NOT_CONFIRMED_INTERVAL_S = 5;
|
|
170917
|
+
var CONSENT_POLL_INTERVAL_S = 3;
|
|
170918
|
+
var ASSERTION_EXPIRY_MARGIN_MS = 6e4;
|
|
170919
|
+
var sleep2 = (ms) => new Promise((resolve7) => setTimeout(resolve7, ms));
|
|
170920
|
+
var normalizeUrl = (raw) => {
|
|
170921
|
+
try {
|
|
170922
|
+
return new URL(/^https?:\/\//.test(raw) ? raw : `https://${raw}`);
|
|
170923
|
+
} catch {
|
|
170924
|
+
return null;
|
|
170925
|
+
}
|
|
170926
|
+
};
|
|
170927
|
+
var updateServiceIdentity = (host, update2) => {
|
|
170928
|
+
const path3 = getConfigPath();
|
|
170929
|
+
ensureSecureDir(dirname(path3));
|
|
170930
|
+
const config3 = readConfig(path3);
|
|
170931
|
+
const identities = { ...config3.serviceIdentities };
|
|
170932
|
+
const next = update2(identities[host] ?? {});
|
|
170933
|
+
if (next === void 0) {
|
|
170934
|
+
delete identities[host];
|
|
170935
|
+
} else {
|
|
170936
|
+
identities[host] = next;
|
|
170937
|
+
}
|
|
170938
|
+
writeSecureFile(
|
|
170939
|
+
path3,
|
|
170940
|
+
JSON.stringify({ ...config3, serviceIdentities: identities }, null, 2)
|
|
170941
|
+
);
|
|
170942
|
+
};
|
|
170943
|
+
var isUsable = (expiresAt) => {
|
|
170944
|
+
if (!expiresAt) return true;
|
|
170945
|
+
const parsed = Date.parse(expiresAt);
|
|
170946
|
+
return Number.isNaN(parsed) ? true : parsed - ASSERTION_EXPIRY_MARGIN_MS > Date.now();
|
|
170947
|
+
};
|
|
170948
|
+
var emitAccessToken = (accessToken, discovery, host, json3, reused) => {
|
|
170949
|
+
if (json3) {
|
|
170950
|
+
process.stdout.write(
|
|
170951
|
+
`${JSON.stringify({
|
|
170952
|
+
status: "ok",
|
|
170953
|
+
accessToken,
|
|
170954
|
+
resource: discovery.resource,
|
|
170955
|
+
resourceName: discovery.resourceName,
|
|
170956
|
+
tokenEndpoint: discovery.tokenEndpoint,
|
|
170957
|
+
reused
|
|
170958
|
+
})}
|
|
170959
|
+
`
|
|
170960
|
+
);
|
|
170961
|
+
return;
|
|
170962
|
+
}
|
|
170963
|
+
process.stderr.write(
|
|
170964
|
+
[
|
|
170965
|
+
`Signed in to ${discovery.resourceName ?? host} with your Zero identity.`,
|
|
170966
|
+
"The bearer token below is short-lived \u2014 use it right away:",
|
|
170967
|
+
` zero fetch <url> -H "Authorization: Bearer <token>"`,
|
|
170968
|
+
`Re-run this command for a fresh token; it reuses the stored registration.`,
|
|
170969
|
+
""
|
|
170970
|
+
].join("\n")
|
|
170971
|
+
);
|
|
170972
|
+
process.stdout.write(`${accessToken}
|
|
170973
|
+
`);
|
|
170974
|
+
};
|
|
170975
|
+
var exchangeAndEmit = async (client, discovery, host, assertion, json3, reused) => {
|
|
170976
|
+
const token = await client.auth.identity.exchange({ tokenEndpoint: discovery.tokenEndpoint, assertion }).catch((err) => {
|
|
170977
|
+
process.stderr.write(
|
|
170978
|
+
`Token exchange at ${discovery.tokenEndpoint} failed: ${truncateError(
|
|
170979
|
+
err instanceof Error ? err.message : String(err)
|
|
170980
|
+
)}
|
|
170981
|
+
`
|
|
170982
|
+
);
|
|
170983
|
+
return null;
|
|
170984
|
+
});
|
|
170985
|
+
if (!token) return false;
|
|
170986
|
+
emitAccessToken(token.accessToken, discovery, host, json3, reused);
|
|
170987
|
+
return true;
|
|
170988
|
+
};
|
|
170989
|
+
var completeServiceClaim = async (client, discovery, host, claimToken, userCode, json3) => {
|
|
170990
|
+
if (!discovery.claimEndpoint) {
|
|
170991
|
+
process.stderr.write(
|
|
170992
|
+
"The service advertises no claim endpoint \u2014 cannot complete the claim.\n"
|
|
170993
|
+
);
|
|
170994
|
+
return false;
|
|
170995
|
+
}
|
|
170996
|
+
for (let attempt = 0; attempt < CLAIM_NOT_CONFIRMED_RETRIES; attempt++) {
|
|
170997
|
+
const result = await client.auth.identity.completeClaim({
|
|
170998
|
+
claimEndpoint: discovery.claimEndpoint,
|
|
170999
|
+
claimToken,
|
|
171000
|
+
userCode
|
|
171001
|
+
}).catch((err) => {
|
|
171002
|
+
process.stderr.write(
|
|
171003
|
+
`
|
|
171004
|
+
Claim completion failed: ${truncateError(
|
|
171005
|
+
err instanceof Error ? err.message : String(err)
|
|
171006
|
+
)}
|
|
171007
|
+
`
|
|
171008
|
+
);
|
|
171009
|
+
return null;
|
|
171010
|
+
});
|
|
171011
|
+
if (result === null) return false;
|
|
171012
|
+
if (result.status === "not_confirmed") {
|
|
171013
|
+
if (!json3) process.stderr.write(".");
|
|
171014
|
+
await sleep2(CLAIM_NOT_CONFIRMED_INTERVAL_S * 1e3);
|
|
171015
|
+
continue;
|
|
171016
|
+
}
|
|
171017
|
+
if (result.status === "invalid_code") {
|
|
171018
|
+
process.stderr.write(
|
|
171019
|
+
"\nThat pairing code was not accepted. Ask the account owner to re-read the code from the claim page and try again.\n"
|
|
171020
|
+
);
|
|
171021
|
+
return false;
|
|
171022
|
+
}
|
|
171023
|
+
if (result.status === "expired") {
|
|
171024
|
+
process.stderr.write(
|
|
171025
|
+
`
|
|
171026
|
+
The claim attempt is no longer valid (${result.code}). Re-run \`zero auth identity ${host}\` for a fresh one.
|
|
171027
|
+
`
|
|
171028
|
+
);
|
|
171029
|
+
updateServiceIdentity(host, ({ pendingClaim: _drop, ...rest }) => rest);
|
|
171030
|
+
return false;
|
|
171031
|
+
}
|
|
171032
|
+
updateServiceIdentity(host, ({ pendingClaim: _drop, ...rest }) => ({
|
|
171033
|
+
...rest,
|
|
171034
|
+
assertion: result.identityAssertion,
|
|
171035
|
+
...result.assertionExpires && {
|
|
171036
|
+
assertionExpires: result.assertionExpires
|
|
171037
|
+
},
|
|
171038
|
+
...result.refreshToken && { refreshToken: result.refreshToken }
|
|
171039
|
+
}));
|
|
171040
|
+
return exchangeAndEmit(
|
|
171041
|
+
client,
|
|
171042
|
+
discovery,
|
|
171043
|
+
host,
|
|
171044
|
+
result.identityAssertion,
|
|
171045
|
+
json3,
|
|
171046
|
+
false
|
|
171047
|
+
);
|
|
171048
|
+
}
|
|
171049
|
+
process.stderr.write(
|
|
171050
|
+
"\nThe account owner never confirmed the claim on the page. Re-run with --claim-code once they have.\n"
|
|
171051
|
+
);
|
|
171052
|
+
return false;
|
|
171053
|
+
};
|
|
171054
|
+
var authIdentityCommand = (appContext) => new Command("identity").description(
|
|
171055
|
+
"Sign in to a service that accepts ID-JAG identity assertion \u2014 mints one from Zero, registers it, and prints a bearer token for the service's API"
|
|
171056
|
+
).argument("<url>", "The service host, or any URL on it").option(
|
|
171057
|
+
"--claim-code <code>",
|
|
171058
|
+
"Finish an interaction_required claim with the pairing code the account owner read off the claim page"
|
|
171059
|
+
).option("--json", "Emit machine-readable JSON instead of human text").action(
|
|
171060
|
+
async (rawUrl, opts) => {
|
|
171061
|
+
const { client, analyticsService } = appContext.services;
|
|
171062
|
+
const json3 = opts.json ?? false;
|
|
171063
|
+
const target = normalizeUrl(rawUrl);
|
|
171064
|
+
if (!target) {
|
|
171065
|
+
process.stderr.write(`Not a valid URL or host: ${rawUrl}
|
|
171066
|
+
`);
|
|
171067
|
+
process.exitCode = 1;
|
|
171068
|
+
return;
|
|
171069
|
+
}
|
|
171070
|
+
const host = target.host;
|
|
171071
|
+
const capture = (outcome2) => analyticsService.capture("auth_identity_asserted", {
|
|
171072
|
+
host,
|
|
171073
|
+
outcome: outcome2,
|
|
171074
|
+
json: json3
|
|
171075
|
+
});
|
|
171076
|
+
if (client.getCredentials().kind !== "session") {
|
|
171077
|
+
process.stderr.write(
|
|
171078
|
+
"Identity assertion needs a signed-in Zero session. Run `zero auth login` (humans) or `zero auth agent register` + `zero auth agent claim` (agents) first.\n"
|
|
171079
|
+
);
|
|
171080
|
+
process.exitCode = 1;
|
|
171081
|
+
return;
|
|
171082
|
+
}
|
|
171083
|
+
let discovery;
|
|
171084
|
+
try {
|
|
171085
|
+
discovery = await client.auth.identity.discover(target.toString());
|
|
171086
|
+
} catch (err) {
|
|
171087
|
+
capture("unsupported");
|
|
171088
|
+
process.stderr.write(
|
|
171089
|
+
`${truncateError(err instanceof Error ? err.message : String(err))}
|
|
171090
|
+
This host does not appear to support agent auth. If it serves an /auth.md, follow that instead.
|
|
171091
|
+
`
|
|
171092
|
+
);
|
|
171093
|
+
process.exitCode = 1;
|
|
171094
|
+
return;
|
|
171095
|
+
}
|
|
171096
|
+
if (opts.claimCode) {
|
|
171097
|
+
const pending = readConfig(getConfigPath()).serviceIdentities?.[host]?.pendingClaim;
|
|
171098
|
+
if (!pending) {
|
|
171099
|
+
process.stderr.write(
|
|
171100
|
+
`No pending identity claim for ${host}. Run \`zero auth identity ${host}\` first.
|
|
171101
|
+
`
|
|
171102
|
+
);
|
|
171103
|
+
process.exitCode = 1;
|
|
171104
|
+
return;
|
|
171105
|
+
}
|
|
171106
|
+
const ok = await completeServiceClaim(
|
|
171107
|
+
client,
|
|
171108
|
+
discovery,
|
|
171109
|
+
host,
|
|
171110
|
+
pending.token,
|
|
171111
|
+
opts.claimCode.trim(),
|
|
171112
|
+
json3
|
|
171113
|
+
);
|
|
171114
|
+
capture(ok ? "claim_completed" : "error");
|
|
171115
|
+
if (!ok) process.exitCode = 1;
|
|
171116
|
+
return;
|
|
171117
|
+
}
|
|
171118
|
+
if (!discovery.identityAssertionSupported) {
|
|
171119
|
+
capture("unsupported");
|
|
171120
|
+
process.stderr.write(
|
|
171121
|
+
`${discovery.resourceName ?? host} does not accept identity assertion. Fall back to its standard agent auth (see ${target.origin}/auth.md).
|
|
171122
|
+
`
|
|
171123
|
+
);
|
|
171124
|
+
process.exitCode = 1;
|
|
171125
|
+
return;
|
|
171126
|
+
}
|
|
171127
|
+
const stored = readConfig(getConfigPath()).serviceIdentities?.[host];
|
|
171128
|
+
if (stored?.assertion && isUsable(stored.assertionExpires)) {
|
|
171129
|
+
const token = await client.auth.identity.exchange({
|
|
171130
|
+
tokenEndpoint: discovery.tokenEndpoint,
|
|
171131
|
+
assertion: stored.assertion
|
|
171132
|
+
}).catch(() => null);
|
|
171133
|
+
if (token) {
|
|
171134
|
+
capture("reused");
|
|
171135
|
+
emitAccessToken(token.accessToken, discovery, host, json3, true);
|
|
171136
|
+
return;
|
|
171137
|
+
}
|
|
171138
|
+
}
|
|
171139
|
+
const runAssert = async () => {
|
|
171140
|
+
try {
|
|
171141
|
+
return await client.auth.identity.assert({
|
|
171142
|
+
url: target.toString(),
|
|
171143
|
+
discovery
|
|
171144
|
+
});
|
|
171145
|
+
} catch (err) {
|
|
171146
|
+
capture("error");
|
|
171147
|
+
if (err instanceof ZeroApiError && err.body?.error === "account_unclaimed") {
|
|
171148
|
+
process.stderr.write(
|
|
171149
|
+
"This Zero account has no human owner yet \u2014 identity assertion is only available on claimed accounts. Run `zero auth agent claim <email>` first.\n"
|
|
171150
|
+
);
|
|
171151
|
+
} else {
|
|
171152
|
+
process.stderr.write(
|
|
171153
|
+
`Identity assertion failed: ${truncateError(err instanceof Error ? err.message : String(err))}
|
|
171154
|
+
`
|
|
171155
|
+
);
|
|
171156
|
+
}
|
|
171157
|
+
return null;
|
|
171158
|
+
}
|
|
171159
|
+
};
|
|
171160
|
+
let outcome = await runAssert();
|
|
171161
|
+
if (!outcome) {
|
|
171162
|
+
process.exitCode = 1;
|
|
171163
|
+
return;
|
|
171164
|
+
}
|
|
171165
|
+
if (outcome.status === "consent_required") {
|
|
171166
|
+
const requested = await client.auth.identity.requestGrant({
|
|
171167
|
+
audience: discovery.mintAudience,
|
|
171168
|
+
resourceUrl: target.origin
|
|
171169
|
+
}).catch((err) => {
|
|
171170
|
+
process.stderr.write(
|
|
171171
|
+
`Could not create the consent request: ${truncateError(err instanceof Error ? err.message : String(err))}
|
|
171172
|
+
`
|
|
171173
|
+
);
|
|
171174
|
+
return null;
|
|
171175
|
+
});
|
|
171176
|
+
if (!requested) {
|
|
171177
|
+
capture("error");
|
|
171178
|
+
process.exitCode = 1;
|
|
171179
|
+
return;
|
|
171180
|
+
}
|
|
171181
|
+
process.stderr.write(
|
|
171182
|
+
[
|
|
171183
|
+
"",
|
|
171184
|
+
`Signing in to ${discovery.resourceName ?? host} needs the user's one-time consent.`,
|
|
171185
|
+
`Send them here to approve: ${requested.approveUrl}`,
|
|
171186
|
+
`(valid until ${requested.expiresAt}; the decision is remembered on their Zero account)`,
|
|
171187
|
+
"Waiting for their decision\u2026"
|
|
171188
|
+
].join("\n")
|
|
171189
|
+
);
|
|
171190
|
+
let decision = "expired";
|
|
171191
|
+
for (; ; ) {
|
|
171192
|
+
const status = await client.auth.identity.grantRequest(requested.requestId).catch(() => null);
|
|
171193
|
+
if (status && status.status !== "pending") {
|
|
171194
|
+
decision = status.status;
|
|
171195
|
+
break;
|
|
171196
|
+
}
|
|
171197
|
+
process.stderr.write(".");
|
|
171198
|
+
await sleep2(CONSENT_POLL_INTERVAL_S * 1e3);
|
|
171199
|
+
}
|
|
171200
|
+
process.stderr.write("\n");
|
|
171201
|
+
if (decision === "denied") {
|
|
171202
|
+
capture("consent_denied");
|
|
171203
|
+
process.stderr.write(
|
|
171204
|
+
"The user denied the request \u2014 not signing in.\n"
|
|
171205
|
+
);
|
|
171206
|
+
process.exitCode = 1;
|
|
171207
|
+
return;
|
|
171208
|
+
}
|
|
171209
|
+
if (decision === "expired") {
|
|
171210
|
+
capture("consent_expired");
|
|
171211
|
+
process.stderr.write(
|
|
171212
|
+
"The approval link expired before the user decided. Re-run to mint a fresh one.\n"
|
|
171213
|
+
);
|
|
171214
|
+
process.exitCode = 1;
|
|
171215
|
+
return;
|
|
171216
|
+
}
|
|
171217
|
+
outcome = await runAssert();
|
|
171218
|
+
if (!outcome) {
|
|
171219
|
+
process.exitCode = 1;
|
|
171220
|
+
return;
|
|
171221
|
+
}
|
|
171222
|
+
if (outcome.status === "consent_required") {
|
|
171223
|
+
capture("error");
|
|
171224
|
+
process.stderr.write(
|
|
171225
|
+
"The issuer still reports consent_required after approval \u2014 retry, and report this if it persists.\n"
|
|
171226
|
+
);
|
|
171227
|
+
process.exitCode = 1;
|
|
171228
|
+
return;
|
|
171229
|
+
}
|
|
171230
|
+
}
|
|
171231
|
+
switch (outcome.status) {
|
|
171232
|
+
case "ok": {
|
|
171233
|
+
updateServiceIdentity(host, ({ pendingClaim: _drop, ...rest }) => ({
|
|
171234
|
+
...rest,
|
|
171235
|
+
registrationId: outcome.registration.registrationId,
|
|
171236
|
+
assertion: outcome.registration.identityAssertion,
|
|
171237
|
+
...outcome.registration.assertionExpires && {
|
|
171238
|
+
assertionExpires: outcome.registration.assertionExpires
|
|
171239
|
+
},
|
|
171240
|
+
...outcome.registration.refreshToken && {
|
|
171241
|
+
refreshToken: outcome.registration.refreshToken
|
|
171242
|
+
},
|
|
171243
|
+
...discovery.resourceName && {
|
|
171244
|
+
resourceName: discovery.resourceName
|
|
171245
|
+
}
|
|
171246
|
+
}));
|
|
171247
|
+
const ok = await exchangeAndEmit(
|
|
171248
|
+
client,
|
|
171249
|
+
discovery,
|
|
171250
|
+
host,
|
|
171251
|
+
outcome.registration.identityAssertion,
|
|
171252
|
+
json3,
|
|
171253
|
+
false
|
|
171254
|
+
);
|
|
171255
|
+
capture(ok ? "ok" : "error");
|
|
171256
|
+
if (!ok) process.exitCode = 1;
|
|
171257
|
+
return;
|
|
171258
|
+
}
|
|
171259
|
+
case "unsupported":
|
|
171260
|
+
case "issuer_not_enabled": {
|
|
171261
|
+
capture(outcome.status);
|
|
171262
|
+
process.stderr.write(
|
|
171263
|
+
`${discovery.resourceName ?? host} does not accept Zero identity assertions${outcome.status === "issuer_not_enabled" ? " (Zero is not on its issuer trust list)" : ""}. Fall back to its standard agent auth (see ${target.origin}/auth.md).
|
|
171264
|
+
`
|
|
171265
|
+
);
|
|
171266
|
+
process.exitCode = 1;
|
|
171267
|
+
return;
|
|
171268
|
+
}
|
|
171269
|
+
case "login_required": {
|
|
171270
|
+
capture("login_required");
|
|
171271
|
+
process.stderr.write(
|
|
171272
|
+
`The service requires a fresher Zero sign-in${outcome.description ? ` (${outcome.description})` : ""}. Run \`zero auth login\` again, then retry \u2014 nothing at the service side helps.
|
|
171273
|
+
`
|
|
171274
|
+
);
|
|
171275
|
+
process.exitCode = 1;
|
|
171276
|
+
return;
|
|
171277
|
+
}
|
|
171278
|
+
case "interaction_required": {
|
|
171279
|
+
capture("interaction_required");
|
|
171280
|
+
const { claim: claim3 } = outcome;
|
|
171281
|
+
if (!claim3.claimToken || !claim3.verificationUri) {
|
|
171282
|
+
process.stderr.write(
|
|
171283
|
+
`The service requires account-owner confirmation but returned no claim handle${claim3.description ? ` (${claim3.description})` : ""}.
|
|
171284
|
+
`
|
|
171285
|
+
);
|
|
171286
|
+
process.exitCode = 1;
|
|
171287
|
+
return;
|
|
171288
|
+
}
|
|
171289
|
+
updateServiceIdentity(host, (current) => ({
|
|
171290
|
+
...current,
|
|
171291
|
+
pendingClaim: {
|
|
171292
|
+
token: claim3.claimToken,
|
|
171293
|
+
verificationUri: claim3.verificationUri ?? void 0,
|
|
171294
|
+
expiresAt: claim3.claimTokenExpires ?? void 0
|
|
171295
|
+
}
|
|
171296
|
+
}));
|
|
171297
|
+
if (json3) {
|
|
171298
|
+
process.stdout.write(
|
|
171299
|
+
`${JSON.stringify({
|
|
171300
|
+
status: "interaction_required",
|
|
171301
|
+
verificationUri: claim3.verificationUri,
|
|
171302
|
+
expiresAt: claim3.claimTokenExpires,
|
|
171303
|
+
next: `The claim page shows the account owner a pairing code. Re-run \`zero auth identity ${host} --claim-code <code>\` with it.`
|
|
171304
|
+
})}
|
|
171305
|
+
`
|
|
171306
|
+
);
|
|
171307
|
+
} else {
|
|
171308
|
+
process.stderr.write(
|
|
171309
|
+
[
|
|
171310
|
+
"",
|
|
171311
|
+
`Your email already has an account at ${discovery.resourceName ?? host} \u2014 its owner must confirm the link.`,
|
|
171312
|
+
`Send them here: ${claim3.verificationUri}`,
|
|
171313
|
+
"The page shows THEM a pairing code.",
|
|
171314
|
+
...claim3.claimTokenExpires ? [`(link valid until ${claim3.claimTokenExpires})`] : [],
|
|
171315
|
+
""
|
|
171316
|
+
].join("\n")
|
|
171317
|
+
);
|
|
171318
|
+
}
|
|
171319
|
+
if (!process.stdin.isTTY) {
|
|
171320
|
+
if (!json3) {
|
|
171321
|
+
process.stderr.write(
|
|
171322
|
+
`Once they read the code back, run: zero auth identity ${host} --claim-code <code>
|
|
171323
|
+
`
|
|
171324
|
+
);
|
|
171325
|
+
}
|
|
171326
|
+
return;
|
|
171327
|
+
}
|
|
171328
|
+
const rl = createInterface$1({
|
|
171329
|
+
input: process.stdin,
|
|
171330
|
+
output: process.stderr
|
|
171331
|
+
});
|
|
171332
|
+
const userCode = (await rl.question("Enter the pairing code they read back: ")).trim();
|
|
171333
|
+
rl.close();
|
|
171334
|
+
if (!userCode) {
|
|
171335
|
+
process.stderr.write(
|
|
171336
|
+
`No code entered. Re-run \`zero auth identity ${host} --claim-code <code>\` when you have it.
|
|
171337
|
+
`
|
|
171338
|
+
);
|
|
171339
|
+
process.exitCode = 1;
|
|
171340
|
+
return;
|
|
171341
|
+
}
|
|
171342
|
+
const ok = await completeServiceClaim(
|
|
171343
|
+
client,
|
|
171344
|
+
discovery,
|
|
171345
|
+
host,
|
|
171346
|
+
claim3.claimToken,
|
|
171347
|
+
userCode,
|
|
171348
|
+
json3
|
|
171349
|
+
);
|
|
171350
|
+
if (!ok) process.exitCode = 1;
|
|
171351
|
+
return;
|
|
171352
|
+
}
|
|
171353
|
+
}
|
|
171354
|
+
}
|
|
171355
|
+
);
|
|
171356
|
+
|
|
171357
|
+
// src/commands/auth-command.ts
|
|
171358
|
+
var getConfigPath2 = () => join$1(homedir(), ".zero", "config.json");
|
|
169683
171359
|
var FINISH_POLL_INTERVAL_S = 2;
|
|
169684
171360
|
var FINISH_MAX_WAIT_MS = 10 * 60 * 1e3;
|
|
169685
|
-
var
|
|
171361
|
+
var sleep3 = (ms) => new Promise((resolve7) => setTimeout(resolve7, ms));
|
|
169686
171362
|
var persistSession = (result) => {
|
|
169687
|
-
const path3 =
|
|
171363
|
+
const path3 = getConfigPath2();
|
|
169688
171364
|
ensureSecureDir(dirname(path3));
|
|
169689
171365
|
const current = readConfig(path3);
|
|
169690
171366
|
const next = {
|
|
@@ -169702,7 +171378,7 @@ var LEGACY_KEY_NOTICE = {
|
|
|
169702
171378
|
message: "A wallet private key from a previous setup is still on this machine. Now that you're signed in, your managed Zero wallet signs payments \u2014 the old key is no longer used.",
|
|
169703
171379
|
keep: "zero wallet set <key>"
|
|
169704
171380
|
};
|
|
169705
|
-
var hasLegacyPrivateKey = () => readConfig(
|
|
171381
|
+
var hasLegacyPrivateKey = () => readConfig(getConfigPath2()).privateKey !== void 0;
|
|
169706
171382
|
var reportSignedIn = (result, json3, la) => {
|
|
169707
171383
|
const legacyKeyPresent = hasLegacyPrivateKey();
|
|
169708
171384
|
la?.analytics.capture("auth_login_completed", {
|
|
@@ -169802,7 +171478,7 @@ var runFinish = async (client, deviceCode, json3, la) => {
|
|
|
169802
171478
|
} else if (!json3) {
|
|
169803
171479
|
process.stdout.write(".");
|
|
169804
171480
|
}
|
|
169805
|
-
await
|
|
171481
|
+
await sleep3(FINISH_POLL_INTERVAL_S * 1e3);
|
|
169806
171482
|
continue;
|
|
169807
171483
|
}
|
|
169808
171484
|
if (result.status === "expired") {
|
|
@@ -169829,7 +171505,7 @@ User code: ${start.userCode}
|
|
|
169829
171505
|
});
|
|
169830
171506
|
}
|
|
169831
171507
|
while (Date.now() < start.expiresAt) {
|
|
169832
|
-
await
|
|
171508
|
+
await sleep3(start.pollInterval * 1e3);
|
|
169833
171509
|
const result = await client.auth.device.poll(start.deviceCode);
|
|
169834
171510
|
if (result.status === "pending") {
|
|
169835
171511
|
process.stdout.write(".");
|
|
@@ -169865,7 +171541,7 @@ var authLoginCommand = (appContext) => new Command("login").description("Sign in
|
|
|
169865
171541
|
return;
|
|
169866
171542
|
}
|
|
169867
171543
|
const mode = opts.finish ? "finish" : "interactive";
|
|
169868
|
-
const hadPriorSession = readConfig(
|
|
171544
|
+
const hadPriorSession = readConfig(getConfigPath2()).session !== void 0;
|
|
169869
171545
|
analyticsService.capture("auth_login_started", { mode, json: json3 });
|
|
169870
171546
|
const la = {
|
|
169871
171547
|
analytics: analyticsService,
|
|
@@ -169890,7 +171566,7 @@ var authLoginCommand = (appContext) => new Command("login").description("Sign in
|
|
|
169890
171566
|
);
|
|
169891
171567
|
var authLogoutCommand = (appContext) => new Command("logout").description("Sign out of Zero").action(async () => {
|
|
169892
171568
|
const { client, analyticsService } = appContext.services;
|
|
169893
|
-
const path3 =
|
|
171569
|
+
const path3 = getConfigPath2();
|
|
169894
171570
|
const config3 = readConfig(path3);
|
|
169895
171571
|
const hadSession = config3.session !== void 0;
|
|
169896
171572
|
if (config3.session) {
|
|
@@ -169995,7 +171671,7 @@ var authAgentRegisterCommand = (appContext) => new Command("register").descripti
|
|
|
169995
171671
|
).option("--json", "Emit machine-readable JSON instead of human text").action(async (opts) => {
|
|
169996
171672
|
const { client } = appContext.services;
|
|
169997
171673
|
const json3 = opts.json ?? false;
|
|
169998
|
-
const path3 =
|
|
171674
|
+
const path3 = getConfigPath2();
|
|
169999
171675
|
if (readConfig(path3).session) {
|
|
170000
171676
|
process.stderr.write(
|
|
170001
171677
|
"Already signed in. Run `zero auth logout` first if you want a fresh account.\n"
|
|
@@ -170075,12 +171751,12 @@ Agent registration may not be enabled for this service yet.
|
|
|
170075
171751
|
].join("\n")
|
|
170076
171752
|
);
|
|
170077
171753
|
});
|
|
170078
|
-
var
|
|
170079
|
-
var
|
|
171754
|
+
var CLAIM_NOT_CONFIRMED_RETRIES2 = 12;
|
|
171755
|
+
var CLAIM_NOT_CONFIRMED_INTERVAL_S2 = 5;
|
|
170080
171756
|
var completeClaimAndExchange = async (agentAuth, claimToken, userCode, email5, json3) => {
|
|
170081
|
-
const path3 =
|
|
171757
|
+
const path3 = getConfigPath2();
|
|
170082
171758
|
let verified = null;
|
|
170083
|
-
for (let attempt = 0; attempt <
|
|
171759
|
+
for (let attempt = 0; attempt < CLAIM_NOT_CONFIRMED_RETRIES2; attempt++) {
|
|
170084
171760
|
const result = await agentAuth.completeClaim({ claimToken, userCode }).catch((err) => {
|
|
170085
171761
|
process.stderr.write(
|
|
170086
171762
|
`
|
|
@@ -170092,7 +171768,7 @@ Claim completion failed: ${truncateError(err instanceof Error ? err.message : St
|
|
|
170092
171768
|
if (result === null) return false;
|
|
170093
171769
|
if (result.status === "not_confirmed") {
|
|
170094
171770
|
if (!json3) process.stdout.write(".");
|
|
170095
|
-
await
|
|
171771
|
+
await sleep3(CLAIM_NOT_CONFIRMED_INTERVAL_S2 * 1e3);
|
|
170096
171772
|
continue;
|
|
170097
171773
|
}
|
|
170098
171774
|
if (result.status === "invalid_code") {
|
|
@@ -170160,7 +171836,7 @@ var authAgentClaimCommand = (appContext) => new Command("claim").description(
|
|
|
170160
171836
|
).option("--json", "Emit machine-readable JSON instead of human text").action(async (email5, opts) => {
|
|
170161
171837
|
const { client } = appContext.services;
|
|
170162
171838
|
const json3 = opts.json ?? false;
|
|
170163
|
-
const config3 = readConfig(
|
|
171839
|
+
const config3 = readConfig(getConfigPath2());
|
|
170164
171840
|
const registration = config3.agentRegistration;
|
|
170165
171841
|
if (!registration?.claimToken) {
|
|
170166
171842
|
process.stderr.write(
|
|
@@ -170253,13 +171929,13 @@ var authAgentCommand = (appContext) => {
|
|
|
170253
171929
|
return cmd;
|
|
170254
171930
|
};
|
|
170255
171931
|
var ensureAuthenticated = async (client, shouldOpen = true) => {
|
|
170256
|
-
const session5 = readConfig(
|
|
171932
|
+
const session5 = readConfig(getConfigPath2()).session;
|
|
170257
171933
|
if (session5) return;
|
|
170258
171934
|
process.stdout.write(
|
|
170259
171935
|
"\nZero requires authentication before handing off to Claude.\n\n"
|
|
170260
171936
|
);
|
|
170261
171937
|
await runInteractive(client, shouldOpen);
|
|
170262
|
-
if (!readConfig(
|
|
171938
|
+
if (!readConfig(getConfigPath2()).session) {
|
|
170263
171939
|
process.exitCode = 1;
|
|
170264
171940
|
process.exit(1);
|
|
170265
171941
|
}
|
|
@@ -170268,6 +171944,7 @@ var authCommand = (appContext) => {
|
|
|
170268
171944
|
const cmd = new Command("auth").description("Authentication commands");
|
|
170269
171945
|
cmd.addCommand(authLoginCommand(appContext).alias("register"));
|
|
170270
171946
|
cmd.addCommand(authAgentCommand(appContext));
|
|
171947
|
+
cmd.addCommand(authIdentityCommand(appContext));
|
|
170271
171948
|
cmd.addCommand(authLogoutCommand(appContext));
|
|
170272
171949
|
cmd.addCommand(authExchangeCommand(appContext));
|
|
170273
171950
|
cmd.addCommand(authWhoamiCommand(appContext), { hidden: true });
|
|
@@ -170666,7 +172343,7 @@ var fetchCommand = (appContext) => new Command("fetch").description(
|
|
|
170666
172343
|
"Bind this fetch to a capability (uid or slug) so a reviewable run is recorded even without a prior `zero search`"
|
|
170667
172344
|
).option(
|
|
170668
172345
|
"--json",
|
|
170669
|
-
"Emit
|
|
172346
|
+
"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
172347
|
).option(
|
|
170671
172348
|
"--raw-body",
|
|
170672
172349
|
"With --json: keep `body` as the raw response string instead of parsing JSON. `bodyRaw` still reflects the raw text."
|
|
@@ -170864,8 +172541,19 @@ var fetchCommand = (appContext) => new Command("fetch").description(
|
|
|
170864
172541
|
});
|
|
170865
172542
|
} catch (err) {
|
|
170866
172543
|
const message2 = err instanceof Error ? err.message : "Fetch failed";
|
|
172544
|
+
const fetchContext = fetchErrorContext(err);
|
|
170867
172545
|
analyticsService.capture("fetch_error", {
|
|
170868
172546
|
cliErrorClass: "network",
|
|
172547
|
+
fetchId: fetchContext.fetchId,
|
|
172548
|
+
failureStage: fetchContext.diagnostics?.failureStage,
|
|
172549
|
+
failureCode: fetchContext.diagnostics?.failureCode,
|
|
172550
|
+
paymentProtocol: fetchContext.diagnostics?.paymentProtocol,
|
|
172551
|
+
paymentMode: fetchContext.diagnostics?.paymentMode,
|
|
172552
|
+
fundingSource: fetchContext.diagnostics?.fundingSource,
|
|
172553
|
+
diagnosticCodes: fetchContext.diagnostics?.issues?.map(
|
|
172554
|
+
(issue3) => issue3.code
|
|
172555
|
+
),
|
|
172556
|
+
stageDurationsMs: fetchContext.diagnostics?.stageDurationsMs,
|
|
170869
172557
|
url: redactUrl(resolvedUrl),
|
|
170870
172558
|
error: truncateError(message2)
|
|
170871
172559
|
});
|
|
@@ -170874,6 +172562,7 @@ var fetchCommand = (appContext) => new Command("fetch").description(
|
|
|
170874
172562
|
return;
|
|
170875
172563
|
}
|
|
170876
172564
|
const {
|
|
172565
|
+
fetchId,
|
|
170877
172566
|
runId,
|
|
170878
172567
|
status,
|
|
170879
172568
|
latencyMs,
|
|
@@ -170886,7 +172575,9 @@ var fetchCommand = (appContext) => new Command("fetch").description(
|
|
|
170886
172575
|
warnings: sdkWarnings,
|
|
170887
172576
|
runTrackingSkipped: sdkSkipReasons,
|
|
170888
172577
|
error: resultError,
|
|
170889
|
-
capabilityResolution
|
|
172578
|
+
capabilityResolution,
|
|
172579
|
+
settlementState,
|
|
172580
|
+
diagnostics
|
|
170890
172581
|
} = result;
|
|
170891
172582
|
const isBinary = bodyEncoding === "base64";
|
|
170892
172583
|
const bodyBytes = isBinary && bodyRaw ? Buffer.from(bodyRaw, "base64") : void 0;
|
|
@@ -170992,6 +172683,15 @@ var fetchCommand = (appContext) => new Command("fetch").description(
|
|
|
170992
172683
|
);
|
|
170993
172684
|
analyticsService.capture("fetch_error", {
|
|
170994
172685
|
cliErrorClass,
|
|
172686
|
+
fetchId,
|
|
172687
|
+
settlementState,
|
|
172688
|
+
failureStage: diagnostics?.failureStage,
|
|
172689
|
+
failureCode: diagnostics?.failureCode,
|
|
172690
|
+
paymentProtocol: diagnostics?.paymentProtocol,
|
|
172691
|
+
paymentMode: diagnostics?.paymentMode,
|
|
172692
|
+
fundingSource: diagnostics?.fundingSource,
|
|
172693
|
+
diagnosticCodes: diagnostics?.issues.map((issue3) => issue3.code),
|
|
172694
|
+
stageDurationsMs: diagnostics?.stageDurationsMs,
|
|
170995
172695
|
capabilityUid: capabilityUid ?? void 0,
|
|
170996
172696
|
capabilitySlug: capabilitySlug ?? void 0,
|
|
170997
172697
|
capabilityId: capabilityId ?? void 0,
|
|
@@ -171058,11 +172758,18 @@ var fetchCommand = (appContext) => new Command("fetch").description(
|
|
|
171058
172758
|
];
|
|
171059
172759
|
console.log(
|
|
171060
172760
|
JSON.stringify({
|
|
172761
|
+
fetchId,
|
|
171061
172762
|
runId,
|
|
171062
172763
|
ok,
|
|
172764
|
+
// The canonical FetchOutcome discriminator — the field an
|
|
172765
|
+
// agent branches on (payment_failed vs insufficient_funds
|
|
172766
|
+
// vs server_error vs …). `ok` alone can't distinguish them.
|
|
172767
|
+
outcome,
|
|
171063
172768
|
status,
|
|
171064
172769
|
latencyMs,
|
|
171065
172770
|
payment: payment ?? null,
|
|
172771
|
+
settlementState,
|
|
172772
|
+
diagnostics,
|
|
171066
172773
|
body: envBody,
|
|
171067
172774
|
bodyRaw: status === null ? null : bodyRaw,
|
|
171068
172775
|
...isBinary && { bodyEncoding: "base64" },
|
|
@@ -175130,11 +176837,11 @@ var PostHogCoreStateless = class {
|
|
|
175130
176837
|
let timeoutHandle;
|
|
175131
176838
|
try {
|
|
175132
176839
|
return await Promise.race([
|
|
175133
|
-
new Promise((_,
|
|
176840
|
+
new Promise((_, reject2) => {
|
|
175134
176841
|
timeoutHandle = safeSetTimeout(() => {
|
|
175135
176842
|
this._logger.error("Timed out while shutting down PostHog");
|
|
175136
176843
|
hasTimedOut = true;
|
|
175137
|
-
|
|
176844
|
+
reject2("Timeout while shutting down PostHog. Some events may not have been sent.");
|
|
175138
176845
|
}, shutdownTimeoutMs);
|
|
175139
176846
|
}),
|
|
175140
176847
|
doShutdown()
|
|
@@ -176583,7 +178290,7 @@ var FeatureFlagsPoller = class {
|
|
|
176583
178290
|
const shutdownResult = this.cacheProvider.shutdown();
|
|
176584
178291
|
if (shutdownResult instanceof Promise) await Promise.race([
|
|
176585
178292
|
shutdownResult,
|
|
176586
|
-
new Promise((_,
|
|
178293
|
+
new Promise((_, reject2) => setTimeout(() => reject2(new Error(`Cache shutdown timeout after ${timeoutMs}ms`)), timeoutMs))
|
|
176587
178294
|
]);
|
|
176588
178295
|
} catch (err) {
|
|
176589
178296
|
this.onError?.(new Error(`Error during cache shutdown: ${err}`));
|
|
@@ -177738,7 +179445,18 @@ var mapSdkEventToCliEvent = (event) => {
|
|
|
177738
179445
|
latencyMs: p.latency_ms,
|
|
177739
179446
|
hasPayment: p.has_payment,
|
|
177740
179447
|
paymentProtocol: orUndef(p.payment_protocol),
|
|
179448
|
+
fundingSource: orUndef(p.funding_source),
|
|
177741
179449
|
paymentAmount: dropUnknownAmount(p.payment_amount),
|
|
179450
|
+
paymentChain: orUndef(p.payment_chain),
|
|
179451
|
+
paymentMode: orUndef(p.payment_mode),
|
|
179452
|
+
paymentSessionChannelId: orUndef(p.payment_session_channel_id),
|
|
179453
|
+
hasSettlementAnchor: p.has_settlement_anchor,
|
|
179454
|
+
settlementState: orUndef(p.settlement_state),
|
|
179455
|
+
warningCodes: p.warning_codes,
|
|
179456
|
+
failureStage: orUndef(p.failure_stage),
|
|
179457
|
+
failureCode: orUndef(p.failure_code),
|
|
179458
|
+
diagnosticCodes: p.diagnostic_codes,
|
|
179459
|
+
stageDurationsMs: p.stage_durations_ms,
|
|
177742
179460
|
runId: orUndef(p.run_id),
|
|
177743
179461
|
runTracked: p.run_tracked,
|
|
177744
179462
|
error: orUndef(p.error),
|