@agentcash/router 1.10.4 → 1.10.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +20 -4
- package/dist/index.d.cts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +20 -4
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2106,6 +2106,7 @@ function invalidPaymentVerification(failure) {
|
|
|
2106
2106
|
}
|
|
2107
2107
|
|
|
2108
2108
|
// src/protocols/x402/strategy.ts
|
|
2109
|
+
var SETTLE_RETRY_DELAYS_MS = [500, 1e3];
|
|
2109
2110
|
function formatVerifyFailureMessage(failure) {
|
|
2110
2111
|
if (failure.reason === "permit2_allowance_required") {
|
|
2111
2112
|
const wallet = failure.payer ?? "<the payer wallet>";
|
|
@@ -2196,7 +2197,17 @@ async function settleX402(args) {
|
|
|
2196
2197
|
const { payload, requirements } = token;
|
|
2197
2198
|
const override = routeEntry.billing === "exact" ? void 0 : { amount: billedAmount };
|
|
2198
2199
|
try {
|
|
2199
|
-
|
|
2200
|
+
let settle = await settleX402Payment(deps.x402Server, payload, requirements, override);
|
|
2201
|
+
for (let attempt = 0; !settle.result?.success && attempt < SETTLE_RETRY_DELAYS_MS.length; attempt++) {
|
|
2202
|
+
report("warn", "Retrying x402 settlement", {
|
|
2203
|
+
attempt: attempt + 1,
|
|
2204
|
+
errorReason: settle.result?.errorReason
|
|
2205
|
+
});
|
|
2206
|
+
await new Promise((resolve) => {
|
|
2207
|
+
setTimeout(resolve, SETTLE_RETRY_DELAYS_MS[attempt]);
|
|
2208
|
+
});
|
|
2209
|
+
settle = await settleX402Payment(deps.x402Server, payload, requirements, override);
|
|
2210
|
+
}
|
|
2200
2211
|
if (!settle.result?.success) {
|
|
2201
2212
|
throw Object.assign(
|
|
2202
2213
|
new Error(settle.result?.errorReason ?? "x402 settlement returned success=false"),
|
|
@@ -3590,7 +3601,8 @@ var RouteBuilder = class _RouteBuilder {
|
|
|
3590
3601
|
providerConfig: void 0,
|
|
3591
3602
|
validateFn: void 0,
|
|
3592
3603
|
settlement: void 0,
|
|
3593
|
-
mppInfo: void 0
|
|
3604
|
+
mppInfo: void 0,
|
|
3605
|
+
hasCheckout: false
|
|
3594
3606
|
};
|
|
3595
3607
|
}
|
|
3596
3608
|
fork() {
|
|
@@ -3681,6 +3693,7 @@ var RouteBuilder = class _RouteBuilder {
|
|
|
3681
3693
|
if (resolvedOptions.minPrice) next.#s.minPrice = resolvedOptions.minPrice;
|
|
3682
3694
|
if (resolvedOptions.payTo) next.#s.payTo = resolvedOptions.payTo;
|
|
3683
3695
|
if (resolvedOptions.mpp) next.#s.mppInfo = resolvedOptions.mpp;
|
|
3696
|
+
if (resolvedOptions.checkout) next.#s.hasCheckout = true;
|
|
3684
3697
|
next.#s.billing = billing;
|
|
3685
3698
|
if (tickCost) next.#s.tickCost = tickCost;
|
|
3686
3699
|
if (unitType) next.#s.unitType = unitType;
|
|
@@ -4114,6 +4127,7 @@ var RouteBuilder = class _RouteBuilder {
|
|
|
4114
4127
|
validateFn: this.#s.validateFn,
|
|
4115
4128
|
settlement: this.#s.settlement,
|
|
4116
4129
|
mppInfo: this.#s.mppInfo,
|
|
4130
|
+
hasCheckout: this.#s.hasCheckout ? true : void 0,
|
|
4117
4131
|
tickCost: this.#s.tickCost,
|
|
4118
4132
|
unitType: this.#s.unitType
|
|
4119
4133
|
};
|
|
@@ -4320,6 +4334,7 @@ function buildOperation(routeKey, entry, tag) {
|
|
|
4320
4334
|
const requiresSiwxScheme = entry.authMode === "siwx" || Boolean(entry.siwxEnabled);
|
|
4321
4335
|
const requiresApiKeyScheme = Boolean(entry.apiKeyResolver) && entry.authMode !== "siwx";
|
|
4322
4336
|
const pricingInfo = buildPricingInfo(entry);
|
|
4337
|
+
const hasCheckout = entry.hasCheckout === true;
|
|
4323
4338
|
const operation = {
|
|
4324
4339
|
operationId: routeKey.replace(/\//g, "_"),
|
|
4325
4340
|
summary: entry.description ?? routeKey,
|
|
@@ -4345,10 +4360,11 @@ function buildOperation(routeKey, entry, tag) {
|
|
|
4345
4360
|
}
|
|
4346
4361
|
}
|
|
4347
4362
|
};
|
|
4348
|
-
if (paymentRequired && (pricingInfo || protocols)) {
|
|
4363
|
+
if (paymentRequired && (pricingInfo || protocols || hasCheckout)) {
|
|
4349
4364
|
operation["x-payment-info"] = {
|
|
4350
4365
|
...pricingInfo ?? {},
|
|
4351
|
-
...protocols && { protocols }
|
|
4366
|
+
...protocols && { protocols },
|
|
4367
|
+
...hasCheckout && { has_checkout: true }
|
|
4352
4368
|
};
|
|
4353
4369
|
}
|
|
4354
4370
|
if (requiresSiwxScheme) {
|
package/dist/index.d.cts
CHANGED
|
@@ -227,6 +227,8 @@ interface PaidOptions {
|
|
|
227
227
|
payTo?: PayToConfig;
|
|
228
228
|
/** Override MPP protocol metadata in x-payment-info discovery. */
|
|
229
229
|
mpp?: MppProtocolInfo;
|
|
230
|
+
/** Signal in discovery that clients should use an explicit checkout flow before payment. */
|
|
231
|
+
checkout?: boolean;
|
|
230
232
|
}
|
|
231
233
|
type PaidArg = (PaidOptions & {
|
|
232
234
|
price: string;
|
|
@@ -371,6 +373,7 @@ interface RouteEntry {
|
|
|
371
373
|
validateFn?: (body: unknown) => void | Promise<void>;
|
|
372
374
|
settlement?: SettlementLifecycle;
|
|
373
375
|
mppInfo?: MppProtocolInfo;
|
|
376
|
+
hasCheckout?: boolean;
|
|
374
377
|
/** Per-tick cost (decimal-dollar). Required when `metered` is true. */
|
|
375
378
|
tickCost?: string;
|
|
376
379
|
/** Cosmetic unit label for 402 challenges and client UIs. */
|
|
@@ -554,7 +557,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
554
557
|
* - `{ price }` — fixed price (object form of the string sugar).
|
|
555
558
|
* - `{ field, tiers, default? }` — pick a tier from `body[field]`.
|
|
556
559
|
*
|
|
557
|
-
* Common knobs (`protocols`, `maxPrice`, `minPrice`, `payTo`, `mpp`) live
|
|
560
|
+
* Common knobs (`protocols`, `maxPrice`, `minPrice`, `payTo`, `mpp`, `checkout`) live
|
|
558
561
|
* alongside the pricing shape. For handler-computed billing use `.upTo()`;
|
|
559
562
|
* for per-tick billing use `.metered()`.
|
|
560
563
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -227,6 +227,8 @@ interface PaidOptions {
|
|
|
227
227
|
payTo?: PayToConfig;
|
|
228
228
|
/** Override MPP protocol metadata in x-payment-info discovery. */
|
|
229
229
|
mpp?: MppProtocolInfo;
|
|
230
|
+
/** Signal in discovery that clients should use an explicit checkout flow before payment. */
|
|
231
|
+
checkout?: boolean;
|
|
230
232
|
}
|
|
231
233
|
type PaidArg = (PaidOptions & {
|
|
232
234
|
price: string;
|
|
@@ -371,6 +373,7 @@ interface RouteEntry {
|
|
|
371
373
|
validateFn?: (body: unknown) => void | Promise<void>;
|
|
372
374
|
settlement?: SettlementLifecycle;
|
|
373
375
|
mppInfo?: MppProtocolInfo;
|
|
376
|
+
hasCheckout?: boolean;
|
|
374
377
|
/** Per-tick cost (decimal-dollar). Required when `metered` is true. */
|
|
375
378
|
tickCost?: string;
|
|
376
379
|
/** Cosmetic unit label for 402 challenges and client UIs. */
|
|
@@ -554,7 +557,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
554
557
|
* - `{ price }` — fixed price (object form of the string sugar).
|
|
555
558
|
* - `{ field, tiers, default? }` — pick a tier from `body[field]`.
|
|
556
559
|
*
|
|
557
|
-
* Common knobs (`protocols`, `maxPrice`, `minPrice`, `payTo`, `mpp`) live
|
|
560
|
+
* Common knobs (`protocols`, `maxPrice`, `minPrice`, `payTo`, `mpp`, `checkout`) live
|
|
558
561
|
* alongside the pricing shape. For handler-computed billing use `.upTo()`;
|
|
559
562
|
* for per-tick billing use `.metered()`.
|
|
560
563
|
*
|
package/dist/index.js
CHANGED
|
@@ -2064,6 +2064,7 @@ function invalidPaymentVerification(failure) {
|
|
|
2064
2064
|
}
|
|
2065
2065
|
|
|
2066
2066
|
// src/protocols/x402/strategy.ts
|
|
2067
|
+
var SETTLE_RETRY_DELAYS_MS = [500, 1e3];
|
|
2067
2068
|
function formatVerifyFailureMessage(failure) {
|
|
2068
2069
|
if (failure.reason === "permit2_allowance_required") {
|
|
2069
2070
|
const wallet = failure.payer ?? "<the payer wallet>";
|
|
@@ -2154,7 +2155,17 @@ async function settleX402(args) {
|
|
|
2154
2155
|
const { payload, requirements } = token;
|
|
2155
2156
|
const override = routeEntry.billing === "exact" ? void 0 : { amount: billedAmount };
|
|
2156
2157
|
try {
|
|
2157
|
-
|
|
2158
|
+
let settle = await settleX402Payment(deps.x402Server, payload, requirements, override);
|
|
2159
|
+
for (let attempt = 0; !settle.result?.success && attempt < SETTLE_RETRY_DELAYS_MS.length; attempt++) {
|
|
2160
|
+
report("warn", "Retrying x402 settlement", {
|
|
2161
|
+
attempt: attempt + 1,
|
|
2162
|
+
errorReason: settle.result?.errorReason
|
|
2163
|
+
});
|
|
2164
|
+
await new Promise((resolve) => {
|
|
2165
|
+
setTimeout(resolve, SETTLE_RETRY_DELAYS_MS[attempt]);
|
|
2166
|
+
});
|
|
2167
|
+
settle = await settleX402Payment(deps.x402Server, payload, requirements, override);
|
|
2168
|
+
}
|
|
2158
2169
|
if (!settle.result?.success) {
|
|
2159
2170
|
throw Object.assign(
|
|
2160
2171
|
new Error(settle.result?.errorReason ?? "x402 settlement returned success=false"),
|
|
@@ -3548,7 +3559,8 @@ var RouteBuilder = class _RouteBuilder {
|
|
|
3548
3559
|
providerConfig: void 0,
|
|
3549
3560
|
validateFn: void 0,
|
|
3550
3561
|
settlement: void 0,
|
|
3551
|
-
mppInfo: void 0
|
|
3562
|
+
mppInfo: void 0,
|
|
3563
|
+
hasCheckout: false
|
|
3552
3564
|
};
|
|
3553
3565
|
}
|
|
3554
3566
|
fork() {
|
|
@@ -3639,6 +3651,7 @@ var RouteBuilder = class _RouteBuilder {
|
|
|
3639
3651
|
if (resolvedOptions.minPrice) next.#s.minPrice = resolvedOptions.minPrice;
|
|
3640
3652
|
if (resolvedOptions.payTo) next.#s.payTo = resolvedOptions.payTo;
|
|
3641
3653
|
if (resolvedOptions.mpp) next.#s.mppInfo = resolvedOptions.mpp;
|
|
3654
|
+
if (resolvedOptions.checkout) next.#s.hasCheckout = true;
|
|
3642
3655
|
next.#s.billing = billing;
|
|
3643
3656
|
if (tickCost) next.#s.tickCost = tickCost;
|
|
3644
3657
|
if (unitType) next.#s.unitType = unitType;
|
|
@@ -4072,6 +4085,7 @@ var RouteBuilder = class _RouteBuilder {
|
|
|
4072
4085
|
validateFn: this.#s.validateFn,
|
|
4073
4086
|
settlement: this.#s.settlement,
|
|
4074
4087
|
mppInfo: this.#s.mppInfo,
|
|
4088
|
+
hasCheckout: this.#s.hasCheckout ? true : void 0,
|
|
4075
4089
|
tickCost: this.#s.tickCost,
|
|
4076
4090
|
unitType: this.#s.unitType
|
|
4077
4091
|
};
|
|
@@ -4278,6 +4292,7 @@ function buildOperation(routeKey, entry, tag) {
|
|
|
4278
4292
|
const requiresSiwxScheme = entry.authMode === "siwx" || Boolean(entry.siwxEnabled);
|
|
4279
4293
|
const requiresApiKeyScheme = Boolean(entry.apiKeyResolver) && entry.authMode !== "siwx";
|
|
4280
4294
|
const pricingInfo = buildPricingInfo(entry);
|
|
4295
|
+
const hasCheckout = entry.hasCheckout === true;
|
|
4281
4296
|
const operation = {
|
|
4282
4297
|
operationId: routeKey.replace(/\//g, "_"),
|
|
4283
4298
|
summary: entry.description ?? routeKey,
|
|
@@ -4303,10 +4318,11 @@ function buildOperation(routeKey, entry, tag) {
|
|
|
4303
4318
|
}
|
|
4304
4319
|
}
|
|
4305
4320
|
};
|
|
4306
|
-
if (paymentRequired && (pricingInfo || protocols)) {
|
|
4321
|
+
if (paymentRequired && (pricingInfo || protocols || hasCheckout)) {
|
|
4307
4322
|
operation["x-payment-info"] = {
|
|
4308
4323
|
...pricingInfo ?? {},
|
|
4309
|
-
...protocols && { protocols }
|
|
4324
|
+
...protocols && { protocols },
|
|
4325
|
+
...hasCheckout && { has_checkout: true }
|
|
4310
4326
|
};
|
|
4311
4327
|
}
|
|
4312
4328
|
if (requiresSiwxScheme) {
|