run402-mcp
Version:
MCP server for Run402 — full-stack backend infrastructure for AI agents: Postgres, auth, storage, serverless functions and atomic deploys. Paid with x402/MPP. Includes $0.03 image generation.
27 lines • 1.18 kB
JavaScript
import { setTimeout as delay } from "node:timers/promises";
import { isRun402Error } from "../errors.js";
/** A confirmed faucet receipt can precede visibility on the buyer's RPC.
* Retry only the buyer's proven pre-payment balance miss, never a payment.
* Called only immediately after a successful faucet in this workflow.
*/
export async function afterFaucet(pay, options = {}) {
const sleep = options.sleep ?? delay;
const now = options.now ?? Date.now;
const deadline = now() + 30_000;
for (let retry = 0;; retry++) {
try {
return await pay();
}
catch (error) {
const details = isRun402Error(error) ? error.details : undefined;
if (!isRun402Error(error) || error.code !== "X402_INSUFFICIENT_FUNDS"
|| details?.phase !== "balance_preflight" || details.payment_started !== false
|| error.mutationState !== "not_started" || retry >= 30 || now() >= deadline)
throw error;
await sleep(Math.min(1000, deadline - now()));
if (now() >= deadline)
throw error;
}
}
}
//# sourceMappingURL=funded-payment.js.map