wolverine-ai 5.2.4 → 5.2.6
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/package.json +1 -1
- package/src/middleware/x402-fastify.js +43 -49
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wolverine-ai",
|
|
3
|
-
"version": "5.2.
|
|
3
|
+
"version": "5.2.6",
|
|
4
4
|
"description": "Self-healing Node.js server framework powered by AI. Catches crashes, diagnoses errors, generates fixes, verifies, and restarts — automatically.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -16,7 +16,7 @@ const USDC_BASE = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
|
|
|
16
16
|
|
|
17
17
|
let _payTo = null;
|
|
18
18
|
let _network = "eip155:8453";
|
|
19
|
-
let _facilitatorUrl = "https://x402.org/facilitator";
|
|
19
|
+
let _facilitatorUrl = "https://www.x402.org/facilitator";
|
|
20
20
|
|
|
21
21
|
async function x402Plugin(fastify, opts) {
|
|
22
22
|
_network = opts.network || _network;
|
|
@@ -44,8 +44,8 @@ async function x402Plugin(fastify, opts) {
|
|
|
44
44
|
if (!opts.facilitator) {
|
|
45
45
|
const isTestnet = _network.includes("84532") || _network.includes("11155");
|
|
46
46
|
_facilitatorUrl = isTestnet
|
|
47
|
-
? "https://x402.org/facilitator"
|
|
48
|
-
: "https://x402.org/facilitator"; //
|
|
47
|
+
? "https://www.x402.org/facilitator"
|
|
48
|
+
: "https://www.x402.org/facilitator"; // www. avoids 308 redirect from x402.org
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
if (_payTo) {
|
|
@@ -207,66 +207,60 @@ async function x402Plugin(fastify, opts) {
|
|
|
207
207
|
|
|
208
208
|
/**
|
|
209
209
|
* Call the x402 facilitator — matches the exact format from @x402/core HTTPFacilitatorClient.
|
|
210
|
+
* Uses fetch() for automatic redirect following (x402.org → www.x402.org).
|
|
210
211
|
*
|
|
211
212
|
* POST {facilitatorUrl}/verify or /settle
|
|
212
213
|
* Body: { x402Version, paymentPayload, paymentRequirements }
|
|
213
214
|
*/
|
|
214
215
|
async function _facilitatorCall(endpoint, paymentPayload, paymentRequirements) {
|
|
215
216
|
try {
|
|
216
|
-
const
|
|
217
|
-
const http = require("http");
|
|
218
|
-
const url = new (require("url").URL)(_facilitatorUrl + endpoint);
|
|
217
|
+
const url = _facilitatorUrl + endpoint;
|
|
219
218
|
const body = JSON.stringify({
|
|
220
219
|
x402Version: paymentPayload.x402Version || 2,
|
|
221
220
|
paymentPayload,
|
|
222
221
|
paymentRequirements,
|
|
223
222
|
});
|
|
224
223
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
}, (res) => {
|
|
235
|
-
let data = "";
|
|
236
|
-
res.on("data", (c) => data += c);
|
|
237
|
-
res.on("end", () => {
|
|
238
|
-
try {
|
|
239
|
-
const parsed = JSON.parse(data);
|
|
240
|
-
if (res.statusCode >= 200 && res.statusCode < 300) {
|
|
241
|
-
// Verify: check isValid. Settle: check success.
|
|
242
|
-
if (endpoint === "/verify" && parsed.isValid === false) {
|
|
243
|
-
resolve({ ok: false, reason: parsed.invalidReason || "verification_rejected", data: parsed });
|
|
244
|
-
} else if (endpoint === "/settle" && parsed.success === false) {
|
|
245
|
-
resolve({ ok: false, reason: parsed.errorReason || "settlement_rejected", data: parsed });
|
|
246
|
-
} else {
|
|
247
|
-
resolve({ ok: true, data: parsed });
|
|
248
|
-
}
|
|
249
|
-
} else {
|
|
250
|
-
// Error response
|
|
251
|
-
const reason = parsed.invalidReason || parsed.errorReason || parsed.error || `facilitator_${res.statusCode}`;
|
|
252
|
-
console.log(` ⚠️ x402 facilitator ${endpoint} ${res.statusCode}: ${reason}`);
|
|
253
|
-
resolve({ ok: false, reason, data: parsed });
|
|
254
|
-
}
|
|
255
|
-
} catch {
|
|
256
|
-
resolve({ ok: false, reason: `facilitator_parse_error_${res.statusCode}` });
|
|
257
|
-
}
|
|
258
|
-
});
|
|
259
|
-
});
|
|
260
|
-
req.on("error", (err) => {
|
|
261
|
-
console.log(` ⚠️ x402 facilitator ${endpoint} error: ${err.message}`);
|
|
262
|
-
resolve({ ok: false, reason: "facilitator_unavailable: " + err.message });
|
|
263
|
-
});
|
|
264
|
-
req.on("timeout", () => { req.destroy(); resolve({ ok: false, reason: "facilitator_timeout" }); });
|
|
265
|
-
req.write(body);
|
|
266
|
-
req.end();
|
|
224
|
+
const controller = new AbortController();
|
|
225
|
+
const timeout = setTimeout(() => controller.abort(), 30000);
|
|
226
|
+
|
|
227
|
+
const response = await fetch(url, {
|
|
228
|
+
method: "POST",
|
|
229
|
+
headers: { "Content-Type": "application/json" },
|
|
230
|
+
body,
|
|
231
|
+
redirect: "follow",
|
|
232
|
+
signal: controller.signal,
|
|
267
233
|
});
|
|
234
|
+
|
|
235
|
+
clearTimeout(timeout);
|
|
236
|
+
const text = await response.text();
|
|
237
|
+
let parsed;
|
|
238
|
+
try { parsed = JSON.parse(text); } catch {
|
|
239
|
+
console.log(` ⚠️ x402 facilitator ${endpoint} ${response.status}: unparseable response`);
|
|
240
|
+
return { ok: false, reason: `facilitator_parse_error_${response.status}` };
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
if (!response.ok) {
|
|
244
|
+
const reason = parsed.invalidReason || parsed.errorReason || parsed.error || `facilitator_${response.status}`;
|
|
245
|
+
console.log(` ⚠️ x402 facilitator ${endpoint} ${response.status}: ${reason}`);
|
|
246
|
+
return { ok: false, reason, data: parsed };
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// Verify: check isValid. Settle: check success.
|
|
250
|
+
if (endpoint === "/verify" && parsed.isValid === false) {
|
|
251
|
+
console.log(` ⚠️ x402 verify rejected: ${parsed.invalidReason || "unknown"}`);
|
|
252
|
+
return { ok: false, reason: parsed.invalidReason || "verification_rejected", data: parsed };
|
|
253
|
+
}
|
|
254
|
+
if (endpoint === "/settle" && parsed.success === false) {
|
|
255
|
+
console.log(` ⚠️ x402 settle rejected: ${parsed.errorReason || "unknown"}`);
|
|
256
|
+
return { ok: false, reason: parsed.errorReason || "settlement_rejected", data: parsed };
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
return { ok: true, data: parsed };
|
|
268
260
|
} catch (err) {
|
|
269
|
-
|
|
261
|
+
const reason = err.name === "AbortError" ? "facilitator_timeout" : "facilitator_unavailable: " + err.message;
|
|
262
|
+
console.log(` ⚠️ x402 facilitator ${endpoint}: ${reason}`);
|
|
263
|
+
return { ok: false, reason };
|
|
270
264
|
}
|
|
271
265
|
}
|
|
272
266
|
|