@relai-fi/x402 0.6.11-rc.2 → 0.6.11-rc.3
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 +17 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +17 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -5516,12 +5516,22 @@ function buildRequestError(response, payload) {
|
|
|
5516
5516
|
function isNotFoundResponse(response, payload) {
|
|
5517
5517
|
return response.status === 404 || payload.errorCode === "not_found";
|
|
5518
5518
|
}
|
|
5519
|
+
function inferStoredPaymentCodeKind(normalizedCode) {
|
|
5520
|
+
if (normalizedCode.length === 8 && (normalizedCode.startsWith("D") || normalizedCode.startsWith("S"))) {
|
|
5521
|
+
return "solana";
|
|
5522
|
+
}
|
|
5523
|
+
return null;
|
|
5524
|
+
}
|
|
5519
5525
|
async function fetchStoredCodeWithFallback(facilitatorUrl, normalizedCode, options = {}) {
|
|
5520
5526
|
const suffix = options.suffix ? `/${options.suffix.replace(/^\/+/, "")}` : "";
|
|
5527
|
+
const inferredKind = options.preferredKind ?? inferStoredPaymentCodeKind(normalizedCode);
|
|
5521
5528
|
const attempts = [
|
|
5522
5529
|
{ kind: "evm", url: `${facilitatorUrl}/payment-codes/${normalizedCode}${suffix}` },
|
|
5523
5530
|
{ kind: "solana", url: `${facilitatorUrl}/solana-payment-codes/${normalizedCode}${suffix}` }
|
|
5524
5531
|
];
|
|
5532
|
+
if (inferredKind) {
|
|
5533
|
+
attempts.sort((left, right) => Number(right.kind === inferredKind) - Number(left.kind === inferredKind));
|
|
5534
|
+
}
|
|
5525
5535
|
let lastError = null;
|
|
5526
5536
|
for (const attempt of attempts) {
|
|
5527
5537
|
const { response, payload } = await fetchWithPayload(attempt.url, options.init);
|
|
@@ -5742,6 +5752,7 @@ async function redeemStoredPaymentCode(config2, code, params) {
|
|
|
5742
5752
|
const normalizedCode = code.trim().toUpperCase();
|
|
5743
5753
|
const { payload } = await fetchStoredCodeWithFallback(facilitatorUrl, normalizedCode, {
|
|
5744
5754
|
suffix: "redeem",
|
|
5755
|
+
preferredKind: params.solanaNetwork ? "solana" : params.evmNetwork ? "evm" : void 0,
|
|
5745
5756
|
init: {
|
|
5746
5757
|
method: "POST",
|
|
5747
5758
|
headers: { "Content-Type": "application/json" },
|
|
@@ -5757,7 +5768,9 @@ async function redeemStoredPaymentCode(config2, code, params) {
|
|
|
5757
5768
|
async function cancelStoredPaymentCode(config2, code, params = {}) {
|
|
5758
5769
|
const facilitatorUrl = config2.facilitatorUrl ?? DEFAULT_FACILITATOR4;
|
|
5759
5770
|
const normalizedCode = code.trim().toUpperCase();
|
|
5760
|
-
const statusInfo = await fetchStoredCodeWithFallback(facilitatorUrl, normalizedCode
|
|
5771
|
+
const statusInfo = await fetchStoredCodeWithFallback(facilitatorUrl, normalizedCode, {
|
|
5772
|
+
preferredKind: params.network === "solana" || params.network === "solana-devnet" ? "solana" : params.network ? "evm" : void 0
|
|
5773
|
+
});
|
|
5761
5774
|
if (statusInfo.kind === "solana") {
|
|
5762
5775
|
if (!params.solanaWallet) {
|
|
5763
5776
|
throw new Error("A Solana wallet is required to cancel this payment code");
|
|
@@ -5887,7 +5900,9 @@ async function payPayRequestWithStoredCode(config2, request, paymentCode, option
|
|
|
5887
5900
|
const normalizedPaymentCode = paymentCode.trim().toUpperCase();
|
|
5888
5901
|
const requestInfo = isPaymentRequestObject(request) ? request : await getPayRequest(config2, request.trim().toUpperCase());
|
|
5889
5902
|
const normalizedRequestCode = isPaymentRequestObject(request) ? requestInfo.code.trim().toUpperCase() : request.trim().toUpperCase();
|
|
5890
|
-
const codeStatusInfo = await fetchStoredCodeWithFallback(facilitatorUrl, normalizedPaymentCode
|
|
5903
|
+
const codeStatusInfo = await fetchStoredCodeWithFallback(facilitatorUrl, normalizedPaymentCode, {
|
|
5904
|
+
preferredKind: inferStoredPaymentCodeKind(normalizedPaymentCode) ?? void 0
|
|
5905
|
+
});
|
|
5891
5906
|
if (codeStatusInfo.kind === "solana") {
|
|
5892
5907
|
if (!normalizedRequestCode) {
|
|
5893
5908
|
throw new Error("A payment request object with a valid code is required when paying a request with a stored Solana code");
|