@puga-labs/x402-mantle-sdk 0.3.8 → 0.3.10
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/chunk-3DGAB7HD.js +126 -0
- package/dist/chunk-CKBTOS7X.js +86 -0
- package/dist/chunk-IEJB5W26.js +113 -0
- package/dist/chunk-IXIFGPJ2.js +250 -0
- package/dist/chunk-JXMWK3BO.js +96 -0
- package/dist/chunk-P5FKQVHW.js +99 -0
- package/dist/chunk-T4DIHTBP.js +83 -0
- package/dist/chunk-UVYA6H32.js +293 -0
- package/dist/express-BWE0nQty.d.cts +68 -0
- package/dist/express-BvuN0Lx1.d.ts +68 -0
- package/dist/express-DqyVgO5n.d.cts +68 -0
- package/dist/express-DxxlKmmF.d.ts +68 -0
- package/dist/index.cjs +89 -10
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/nextjs-Bujo9Okf.d.cts +89 -0
- package/dist/nextjs-CzSejZe8.d.ts +89 -0
- package/dist/nextjs-DGcN_MGa.d.ts +89 -0
- package/dist/nextjs-EoISXVEo.d.cts +89 -0
- package/dist/server-express.cjs +89 -10
- package/dist/server-express.d.cts +2 -2
- package/dist/server-express.d.ts +2 -2
- package/dist/server-express.js +2 -2
- package/dist/server-nextjs.cjs +90 -11
- package/dist/server-nextjs.d.cts +2 -2
- package/dist/server-nextjs.d.ts +2 -2
- package/dist/server-nextjs.js +2 -2
- package/dist/server-web.cjs +90 -11
- package/dist/server-web.d.cts +2 -2
- package/dist/server-web.d.ts +2 -2
- package/dist/server-web.js +2 -2
- package/dist/server.cjs +141 -12
- package/dist/server.d.cts +8 -7
- package/dist/server.d.ts +8 -7
- package/dist/server.js +4 -4
- package/dist/types-B87bD2yo.d.cts +102 -0
- package/dist/types-Ba0v9XsC.d.ts +108 -0
- package/dist/types-BkGUHT4x.d.cts +108 -0
- package/dist/types-DEpSrXCf.d.ts +112 -0
- package/dist/types-DrBw0xwj.d.cts +112 -0
- package/dist/types-DvKDSdL6.d.ts +106 -0
- package/dist/types-X6DeBEgb.d.cts +106 -0
- package/dist/types-vicT7qsY.d.ts +102 -0
- package/dist/web-standards-BJcdcxD6.d.ts +77 -0
- package/dist/web-standards-C6JwCDmd.d.cts +77 -0
- package/dist/web-standards-DsCZRJPE.d.ts +77 -0
- package/dist/web-standards-QCbyQ14G.d.cts +77 -0
- package/package.json +1 -1
package/dist/server-express.cjs
CHANGED
|
@@ -137,9 +137,20 @@ function createTelemetryEvent(entry, config) {
|
|
|
137
137
|
priceUsd: entry.paymentRequirements?.price
|
|
138
138
|
};
|
|
139
139
|
}
|
|
140
|
-
async function sendTelemetry(event, endpoint) {
|
|
140
|
+
async function sendTelemetry(event, endpoint, debug) {
|
|
141
141
|
const targetEndpoint = endpoint ?? DEFAULT_TELEMETRY_ENDPOINT;
|
|
142
|
+
if (debug) {
|
|
143
|
+
console.log(`[x402-debug:telemetry] \u{1F4E4} Sending telemetry event:`, {
|
|
144
|
+
event: event.event,
|
|
145
|
+
endpoint: targetEndpoint,
|
|
146
|
+
projectKey: event.projectKey.substring(0, 10) + "...",
|
|
147
|
+
route: event.route,
|
|
148
|
+
responseStatus: event.responseStatus,
|
|
149
|
+
serviceDelivered: event.serviceDelivered
|
|
150
|
+
});
|
|
151
|
+
}
|
|
142
152
|
if (!targetEndpoint) {
|
|
153
|
+
if (debug) console.log(`[x402-debug:telemetry] \u26A0\uFE0F No endpoint configured, skipping`);
|
|
143
154
|
return;
|
|
144
155
|
}
|
|
145
156
|
try {
|
|
@@ -151,17 +162,29 @@ async function sendTelemetry(event, endpoint) {
|
|
|
151
162
|
},
|
|
152
163
|
body: JSON.stringify(event)
|
|
153
164
|
});
|
|
165
|
+
if (debug) {
|
|
166
|
+
console.log(`[x402-debug:telemetry] ${response.ok ? "\u2705" : "\u274C"} Telemetry sent: HTTP ${response.status}`);
|
|
167
|
+
}
|
|
154
168
|
if (!response.ok) {
|
|
155
169
|
console.warn(
|
|
156
170
|
`[x402-telemetry] Failed to send event: HTTP ${response.status}`
|
|
157
171
|
);
|
|
158
172
|
}
|
|
159
173
|
} catch (err) {
|
|
174
|
+
if (debug) {
|
|
175
|
+
console.error(`[x402-debug:telemetry] \u274C Error sending:`, err);
|
|
176
|
+
}
|
|
160
177
|
console.error("[x402-telemetry] Error sending telemetry:", err);
|
|
161
178
|
}
|
|
162
179
|
}
|
|
163
180
|
|
|
164
181
|
// src/server/core/verifyPayment.ts
|
|
182
|
+
function debugLog(config, prefix, message, data) {
|
|
183
|
+
if (config?.debug) {
|
|
184
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
185
|
+
console.log(`[${timestamp}] [x402-debug:${prefix}]`, message, data || "");
|
|
186
|
+
}
|
|
187
|
+
}
|
|
165
188
|
async function checkPayment(input) {
|
|
166
189
|
const {
|
|
167
190
|
paymentHeader,
|
|
@@ -231,12 +254,13 @@ async function checkPayment(input) {
|
|
|
231
254
|
isValid: false
|
|
232
255
|
};
|
|
233
256
|
}
|
|
234
|
-
|
|
257
|
+
let baseLogEntry = null;
|
|
258
|
+
if (onPaymentSettled || telemetry) {
|
|
235
259
|
try {
|
|
236
260
|
const headerObj = decodePaymentHeader(paymentHeader);
|
|
237
261
|
const { authorization } = headerObj.payload;
|
|
238
262
|
const assetConfig = getDefaultAssetForNetwork(network);
|
|
239
|
-
|
|
263
|
+
baseLogEntry = {
|
|
240
264
|
id: authorization.nonce,
|
|
241
265
|
from: authorization.from,
|
|
242
266
|
to: authorization.to,
|
|
@@ -248,12 +272,12 @@ async function checkPayment(input) {
|
|
|
248
272
|
facilitatorUrl,
|
|
249
273
|
paymentRequirements
|
|
250
274
|
};
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
);
|
|
275
|
+
debugLog(telemetry, "verify", "\u2705 Payment verified", {
|
|
276
|
+
nonce: authorization.nonce,
|
|
277
|
+
route: routeKey
|
|
278
|
+
});
|
|
279
|
+
if (onPaymentSettled) {
|
|
280
|
+
onPaymentSettled(baseLogEntry);
|
|
257
281
|
}
|
|
258
282
|
} catch (err) {
|
|
259
283
|
console.error(
|
|
@@ -262,11 +286,41 @@ async function checkPayment(input) {
|
|
|
262
286
|
);
|
|
263
287
|
}
|
|
264
288
|
}
|
|
289
|
+
const sendTelemetryAfterResponse = telemetry && baseLogEntry ? (responseStatus, error) => {
|
|
290
|
+
try {
|
|
291
|
+
debugLog(telemetry, "callback", "\u{1F4E4} Telemetry callback invoked", {
|
|
292
|
+
responseStatus,
|
|
293
|
+
hasError: !!error
|
|
294
|
+
});
|
|
295
|
+
const event = createTelemetryEvent(baseLogEntry, telemetry);
|
|
296
|
+
event.responseStatus = responseStatus;
|
|
297
|
+
event.errorMessage = error;
|
|
298
|
+
event.serviceDelivered = responseStatus >= 200 && responseStatus < 300;
|
|
299
|
+
sendTelemetry(event, telemetry.endpoint, telemetry.debug).catch(
|
|
300
|
+
(err) => console.error("[x402-telemetry] Async send failed:", err)
|
|
301
|
+
);
|
|
302
|
+
} catch (err) {
|
|
303
|
+
console.error("[x402-telemetry] Error creating telemetry event:", err);
|
|
304
|
+
}
|
|
305
|
+
} : void 0;
|
|
306
|
+
if (telemetry && baseLogEntry) {
|
|
307
|
+
debugLog(telemetry, "callback", "\u2705 Telemetry callback created", {
|
|
308
|
+
route: routeKey,
|
|
309
|
+
hasTelemetryConfig: !!telemetry,
|
|
310
|
+
hasLogEntry: !!baseLogEntry
|
|
311
|
+
});
|
|
312
|
+
} else if (telemetry) {
|
|
313
|
+
debugLog(telemetry, "callback", "\u26A0\uFE0F Telemetry callback NOT created", {
|
|
314
|
+
hasTelemetryConfig: !!telemetry,
|
|
315
|
+
hasLogEntry: !!baseLogEntry
|
|
316
|
+
});
|
|
317
|
+
}
|
|
265
318
|
return {
|
|
266
319
|
status: "verified",
|
|
267
320
|
statusCode: 200,
|
|
268
321
|
responseBody: null,
|
|
269
|
-
isValid: true
|
|
322
|
+
isValid: true,
|
|
323
|
+
sendTelemetryAfterResponse
|
|
270
324
|
};
|
|
271
325
|
} catch (err) {
|
|
272
326
|
console.error(
|
|
@@ -287,6 +341,12 @@ async function checkPayment(input) {
|
|
|
287
341
|
}
|
|
288
342
|
|
|
289
343
|
// src/server/adapters/express.ts
|
|
344
|
+
function debugLog2(config, prefix, message, data) {
|
|
345
|
+
if (config?.debug) {
|
|
346
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
347
|
+
console.log(`[${timestamp}] [x402-debug:${prefix}]`, message, data || "");
|
|
348
|
+
}
|
|
349
|
+
}
|
|
290
350
|
function createPaymentMiddleware(config) {
|
|
291
351
|
const { facilitatorUrl, receiverAddress, routes, apiKey, onPaymentSettled, telemetry } = config;
|
|
292
352
|
if (!facilitatorUrl) {
|
|
@@ -337,6 +397,25 @@ function createPaymentMiddleware(config) {
|
|
|
337
397
|
res.status(result.statusCode).json(result.responseBody);
|
|
338
398
|
return;
|
|
339
399
|
}
|
|
400
|
+
debugLog2(telemetry, "handler", "\u25B6\uFE0F Handler execution started (Express middleware)");
|
|
401
|
+
if (result.sendTelemetryAfterResponse) {
|
|
402
|
+
res.on("finish", () => {
|
|
403
|
+
const statusCode = res.statusCode;
|
|
404
|
+
debugLog2(telemetry, "handler", `\u2705 Handler completed: ${statusCode}`);
|
|
405
|
+
const errorMessage = statusCode >= 400 ? `Handler returned ${statusCode}` : void 0;
|
|
406
|
+
debugLog2(telemetry, "callback", `\u{1F4E4} Calling telemetry callback with status ${statusCode}`);
|
|
407
|
+
result.sendTelemetryAfterResponse(statusCode, errorMessage);
|
|
408
|
+
});
|
|
409
|
+
res.on("close", () => {
|
|
410
|
+
if (!res.writableEnded) {
|
|
411
|
+
debugLog2(telemetry, "handler", "\u274C Response closed without finishing");
|
|
412
|
+
debugLog2(telemetry, "callback", "\u{1F4E4} Calling telemetry callback with error");
|
|
413
|
+
result.sendTelemetryAfterResponse(500, "Response closed without finishing");
|
|
414
|
+
}
|
|
415
|
+
});
|
|
416
|
+
} else {
|
|
417
|
+
debugLog2(telemetry, "callback", "\u26A0\uFE0F No telemetry callback to call");
|
|
418
|
+
}
|
|
340
419
|
next();
|
|
341
420
|
};
|
|
342
421
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { M as MantleMiddleware, P as PaymentMiddlewareConfig, c as createPaymentMiddleware, m as mantlePaywall } from './express-
|
|
2
|
-
export { M as MinimalPaywallOptions, c as PaymentCheckInput, d as PaymentCheckResult, P as PaymentLogEntry, R as RouteKey, a as RoutePricingConfig, b as RoutesConfig, T as TelemetryConfig } from './types-
|
|
1
|
+
export { M as MantleMiddleware, P as PaymentMiddlewareConfig, c as createPaymentMiddleware, m as mantlePaywall } from './express-BWE0nQty.cjs';
|
|
2
|
+
export { M as MinimalPaywallOptions, c as PaymentCheckInput, d as PaymentCheckResult, P as PaymentLogEntry, R as RouteKey, a as RoutePricingConfig, b as RoutesConfig, T as TelemetryConfig } from './types-BkGUHT4x.cjs';
|
|
3
3
|
export { A as AssetConfig, a as Authorization, E as EIP1193Provider, N as NetworkId, d as PaymentHeaderBase64, c as PaymentHeaderObject, b as PaymentHeaderPayload, P as PaymentRequirements } from './types-BFUqKBBO.cjs';
|
|
4
4
|
export { M as MANTLE_DEFAULTS } from './constants-CsIL25uQ.cjs';
|
|
5
5
|
import 'express';
|
package/dist/server-express.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { M as MantleMiddleware, P as PaymentMiddlewareConfig, c as createPaymentMiddleware, m as mantlePaywall } from './express-
|
|
2
|
-
export { M as MinimalPaywallOptions, c as PaymentCheckInput, d as PaymentCheckResult, P as PaymentLogEntry, R as RouteKey, a as RoutePricingConfig, b as RoutesConfig, T as TelemetryConfig } from './types-
|
|
1
|
+
export { M as MantleMiddleware, P as PaymentMiddlewareConfig, c as createPaymentMiddleware, m as mantlePaywall } from './express-BvuN0Lx1.js';
|
|
2
|
+
export { M as MinimalPaywallOptions, c as PaymentCheckInput, d as PaymentCheckResult, P as PaymentLogEntry, R as RouteKey, a as RoutePricingConfig, b as RoutesConfig, T as TelemetryConfig } from './types-Ba0v9XsC.js';
|
|
3
3
|
export { A as AssetConfig, a as Authorization, E as EIP1193Provider, N as NetworkId, d as PaymentHeaderBase64, c as PaymentHeaderObject, b as PaymentHeaderPayload, P as PaymentRequirements } from './types-BFUqKBBO.js';
|
|
4
4
|
export { M as MANTLE_DEFAULTS } from './constants-0ncqvV_O.js';
|
|
5
5
|
import 'express';
|
package/dist/server-express.js
CHANGED
package/dist/server-nextjs.cjs
CHANGED
|
@@ -140,9 +140,20 @@ function createTelemetryEvent(entry, config) {
|
|
|
140
140
|
priceUsd: entry.paymentRequirements?.price
|
|
141
141
|
};
|
|
142
142
|
}
|
|
143
|
-
async function sendTelemetry(event, endpoint) {
|
|
143
|
+
async function sendTelemetry(event, endpoint, debug) {
|
|
144
144
|
const targetEndpoint = endpoint ?? DEFAULT_TELEMETRY_ENDPOINT;
|
|
145
|
+
if (debug) {
|
|
146
|
+
console.log(`[x402-debug:telemetry] \u{1F4E4} Sending telemetry event:`, {
|
|
147
|
+
event: event.event,
|
|
148
|
+
endpoint: targetEndpoint,
|
|
149
|
+
projectKey: event.projectKey.substring(0, 10) + "...",
|
|
150
|
+
route: event.route,
|
|
151
|
+
responseStatus: event.responseStatus,
|
|
152
|
+
serviceDelivered: event.serviceDelivered
|
|
153
|
+
});
|
|
154
|
+
}
|
|
145
155
|
if (!targetEndpoint) {
|
|
156
|
+
if (debug) console.log(`[x402-debug:telemetry] \u26A0\uFE0F No endpoint configured, skipping`);
|
|
146
157
|
return;
|
|
147
158
|
}
|
|
148
159
|
try {
|
|
@@ -154,17 +165,29 @@ async function sendTelemetry(event, endpoint) {
|
|
|
154
165
|
},
|
|
155
166
|
body: JSON.stringify(event)
|
|
156
167
|
});
|
|
168
|
+
if (debug) {
|
|
169
|
+
console.log(`[x402-debug:telemetry] ${response.ok ? "\u2705" : "\u274C"} Telemetry sent: HTTP ${response.status}`);
|
|
170
|
+
}
|
|
157
171
|
if (!response.ok) {
|
|
158
172
|
console.warn(
|
|
159
173
|
`[x402-telemetry] Failed to send event: HTTP ${response.status}`
|
|
160
174
|
);
|
|
161
175
|
}
|
|
162
176
|
} catch (err) {
|
|
177
|
+
if (debug) {
|
|
178
|
+
console.error(`[x402-debug:telemetry] \u274C Error sending:`, err);
|
|
179
|
+
}
|
|
163
180
|
console.error("[x402-telemetry] Error sending telemetry:", err);
|
|
164
181
|
}
|
|
165
182
|
}
|
|
166
183
|
|
|
167
184
|
// src/server/core/verifyPayment.ts
|
|
185
|
+
function debugLog(config, prefix, message, data) {
|
|
186
|
+
if (config?.debug) {
|
|
187
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
188
|
+
console.log(`[${timestamp}] [x402-debug:${prefix}]`, message, data || "");
|
|
189
|
+
}
|
|
190
|
+
}
|
|
168
191
|
async function checkPayment(input) {
|
|
169
192
|
const {
|
|
170
193
|
paymentHeader,
|
|
@@ -234,12 +257,13 @@ async function checkPayment(input) {
|
|
|
234
257
|
isValid: false
|
|
235
258
|
};
|
|
236
259
|
}
|
|
237
|
-
|
|
260
|
+
let baseLogEntry = null;
|
|
261
|
+
if (onPaymentSettled || telemetry) {
|
|
238
262
|
try {
|
|
239
263
|
const headerObj = decodePaymentHeader(paymentHeader);
|
|
240
264
|
const { authorization } = headerObj.payload;
|
|
241
265
|
const assetConfig = getDefaultAssetForNetwork(network);
|
|
242
|
-
|
|
266
|
+
baseLogEntry = {
|
|
243
267
|
id: authorization.nonce,
|
|
244
268
|
from: authorization.from,
|
|
245
269
|
to: authorization.to,
|
|
@@ -251,12 +275,12 @@ async function checkPayment(input) {
|
|
|
251
275
|
facilitatorUrl,
|
|
252
276
|
paymentRequirements
|
|
253
277
|
};
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
);
|
|
278
|
+
debugLog(telemetry, "verify", "\u2705 Payment verified", {
|
|
279
|
+
nonce: authorization.nonce,
|
|
280
|
+
route: routeKey
|
|
281
|
+
});
|
|
282
|
+
if (onPaymentSettled) {
|
|
283
|
+
onPaymentSettled(baseLogEntry);
|
|
260
284
|
}
|
|
261
285
|
} catch (err) {
|
|
262
286
|
console.error(
|
|
@@ -265,11 +289,41 @@ async function checkPayment(input) {
|
|
|
265
289
|
);
|
|
266
290
|
}
|
|
267
291
|
}
|
|
292
|
+
const sendTelemetryAfterResponse = telemetry && baseLogEntry ? (responseStatus, error) => {
|
|
293
|
+
try {
|
|
294
|
+
debugLog(telemetry, "callback", "\u{1F4E4} Telemetry callback invoked", {
|
|
295
|
+
responseStatus,
|
|
296
|
+
hasError: !!error
|
|
297
|
+
});
|
|
298
|
+
const event = createTelemetryEvent(baseLogEntry, telemetry);
|
|
299
|
+
event.responseStatus = responseStatus;
|
|
300
|
+
event.errorMessage = error;
|
|
301
|
+
event.serviceDelivered = responseStatus >= 200 && responseStatus < 300;
|
|
302
|
+
sendTelemetry(event, telemetry.endpoint, telemetry.debug).catch(
|
|
303
|
+
(err) => console.error("[x402-telemetry] Async send failed:", err)
|
|
304
|
+
);
|
|
305
|
+
} catch (err) {
|
|
306
|
+
console.error("[x402-telemetry] Error creating telemetry event:", err);
|
|
307
|
+
}
|
|
308
|
+
} : void 0;
|
|
309
|
+
if (telemetry && baseLogEntry) {
|
|
310
|
+
debugLog(telemetry, "callback", "\u2705 Telemetry callback created", {
|
|
311
|
+
route: routeKey,
|
|
312
|
+
hasTelemetryConfig: !!telemetry,
|
|
313
|
+
hasLogEntry: !!baseLogEntry
|
|
314
|
+
});
|
|
315
|
+
} else if (telemetry) {
|
|
316
|
+
debugLog(telemetry, "callback", "\u26A0\uFE0F Telemetry callback NOT created", {
|
|
317
|
+
hasTelemetryConfig: !!telemetry,
|
|
318
|
+
hasLogEntry: !!baseLogEntry
|
|
319
|
+
});
|
|
320
|
+
}
|
|
268
321
|
return {
|
|
269
322
|
status: "verified",
|
|
270
323
|
statusCode: 200,
|
|
271
324
|
responseBody: null,
|
|
272
|
-
isValid: true
|
|
325
|
+
isValid: true,
|
|
326
|
+
sendTelemetryAfterResponse
|
|
273
327
|
};
|
|
274
328
|
} catch (err) {
|
|
275
329
|
console.error(
|
|
@@ -290,6 +344,12 @@ async function checkPayment(input) {
|
|
|
290
344
|
}
|
|
291
345
|
|
|
292
346
|
// src/server/adapters/nextjs.ts
|
|
347
|
+
function debugLog2(config, prefix, message, data) {
|
|
348
|
+
if (config?.debug) {
|
|
349
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
350
|
+
console.log(`[${timestamp}] [x402-debug:${prefix}]`, message, data || "");
|
|
351
|
+
}
|
|
352
|
+
}
|
|
293
353
|
function mantlePaywall(opts) {
|
|
294
354
|
const { priceUsd, payTo, facilitatorUrl, apiKey, telemetry, onPaymentSettled } = opts;
|
|
295
355
|
validateAddress(payTo, "payTo");
|
|
@@ -332,7 +392,26 @@ function mantlePaywall(opts) {
|
|
|
332
392
|
status: result.statusCode
|
|
333
393
|
});
|
|
334
394
|
}
|
|
335
|
-
|
|
395
|
+
try {
|
|
396
|
+
debugLog2(telemetry, "handler", "\u25B6\uFE0F Handler execution started");
|
|
397
|
+
const response = await handler(req);
|
|
398
|
+
debugLog2(telemetry, "handler", `\u2705 Handler completed: ${response.status}`);
|
|
399
|
+
if (result.sendTelemetryAfterResponse) {
|
|
400
|
+
debugLog2(telemetry, "callback", `\u{1F4E4} Calling telemetry callback with status ${response.status}`);
|
|
401
|
+
result.sendTelemetryAfterResponse(response.status);
|
|
402
|
+
} else {
|
|
403
|
+
debugLog2(telemetry, "callback", "\u26A0\uFE0F No telemetry callback to call");
|
|
404
|
+
}
|
|
405
|
+
return response;
|
|
406
|
+
} catch (err) {
|
|
407
|
+
const errorMessage = err instanceof Error ? err.message : "Unknown error";
|
|
408
|
+
debugLog2(telemetry, "handler", `\u274C Handler error: ${errorMessage}`);
|
|
409
|
+
if (result.sendTelemetryAfterResponse) {
|
|
410
|
+
debugLog2(telemetry, "callback", "\u{1F4E4} Calling telemetry callback with error");
|
|
411
|
+
result.sendTelemetryAfterResponse(500, errorMessage);
|
|
412
|
+
}
|
|
413
|
+
throw err;
|
|
414
|
+
}
|
|
336
415
|
};
|
|
337
416
|
};
|
|
338
417
|
}
|
package/dist/server-nextjs.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { N as NextJSHandler, a as NextJSPaywallWrapper, P as PaywallErrorResponse, i as isPaywallErrorResponse, m as mantlePaywall } from './nextjs-
|
|
2
|
-
export { M as MinimalPaywallOptions, c as PaymentCheckInput, d as PaymentCheckResult, P as PaymentLogEntry, R as RouteKey, a as RoutePricingConfig, b as RoutesConfig, T as TelemetryConfig } from './types-
|
|
1
|
+
export { N as NextJSHandler, a as NextJSPaywallWrapper, P as PaywallErrorResponse, i as isPaywallErrorResponse, m as mantlePaywall } from './nextjs-Bujo9Okf.cjs';
|
|
2
|
+
export { M as MinimalPaywallOptions, c as PaymentCheckInput, d as PaymentCheckResult, P as PaymentLogEntry, R as RouteKey, a as RoutePricingConfig, b as RoutesConfig, T as TelemetryConfig } from './types-BkGUHT4x.cjs';
|
|
3
3
|
export { A as AssetConfig, a as Authorization, E as EIP1193Provider, N as NetworkId, d as PaymentHeaderBase64, c as PaymentHeaderObject, b as PaymentHeaderPayload, P as PaymentRequirements } from './types-BFUqKBBO.cjs';
|
|
4
4
|
export { M as MANTLE_DEFAULTS } from './constants-CsIL25uQ.cjs';
|
|
5
5
|
import 'next/server';
|
package/dist/server-nextjs.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { N as NextJSHandler, a as NextJSPaywallWrapper, P as PaywallErrorResponse, i as isPaywallErrorResponse, m as mantlePaywall } from './nextjs-
|
|
2
|
-
export { M as MinimalPaywallOptions, c as PaymentCheckInput, d as PaymentCheckResult, P as PaymentLogEntry, R as RouteKey, a as RoutePricingConfig, b as RoutesConfig, T as TelemetryConfig } from './types-
|
|
1
|
+
export { N as NextJSHandler, a as NextJSPaywallWrapper, P as PaywallErrorResponse, i as isPaywallErrorResponse, m as mantlePaywall } from './nextjs-CzSejZe8.js';
|
|
2
|
+
export { M as MinimalPaywallOptions, c as PaymentCheckInput, d as PaymentCheckResult, P as PaymentLogEntry, R as RouteKey, a as RoutePricingConfig, b as RoutesConfig, T as TelemetryConfig } from './types-Ba0v9XsC.js';
|
|
3
3
|
export { A as AssetConfig, a as Authorization, E as EIP1193Provider, N as NetworkId, d as PaymentHeaderBase64, c as PaymentHeaderObject, b as PaymentHeaderPayload, P as PaymentRequirements } from './types-BFUqKBBO.js';
|
|
4
4
|
export { M as MANTLE_DEFAULTS } from './constants-0ncqvV_O.js';
|
|
5
5
|
import 'next/server';
|
package/dist/server-nextjs.js
CHANGED
package/dist/server-web.cjs
CHANGED
|
@@ -136,9 +136,20 @@ function createTelemetryEvent(entry, config) {
|
|
|
136
136
|
priceUsd: entry.paymentRequirements?.price
|
|
137
137
|
};
|
|
138
138
|
}
|
|
139
|
-
async function sendTelemetry(event, endpoint) {
|
|
139
|
+
async function sendTelemetry(event, endpoint, debug) {
|
|
140
140
|
const targetEndpoint = endpoint ?? DEFAULT_TELEMETRY_ENDPOINT;
|
|
141
|
+
if (debug) {
|
|
142
|
+
console.log(`[x402-debug:telemetry] \u{1F4E4} Sending telemetry event:`, {
|
|
143
|
+
event: event.event,
|
|
144
|
+
endpoint: targetEndpoint,
|
|
145
|
+
projectKey: event.projectKey.substring(0, 10) + "...",
|
|
146
|
+
route: event.route,
|
|
147
|
+
responseStatus: event.responseStatus,
|
|
148
|
+
serviceDelivered: event.serviceDelivered
|
|
149
|
+
});
|
|
150
|
+
}
|
|
141
151
|
if (!targetEndpoint) {
|
|
152
|
+
if (debug) console.log(`[x402-debug:telemetry] \u26A0\uFE0F No endpoint configured, skipping`);
|
|
142
153
|
return;
|
|
143
154
|
}
|
|
144
155
|
try {
|
|
@@ -150,17 +161,29 @@ async function sendTelemetry(event, endpoint) {
|
|
|
150
161
|
},
|
|
151
162
|
body: JSON.stringify(event)
|
|
152
163
|
});
|
|
164
|
+
if (debug) {
|
|
165
|
+
console.log(`[x402-debug:telemetry] ${response.ok ? "\u2705" : "\u274C"} Telemetry sent: HTTP ${response.status}`);
|
|
166
|
+
}
|
|
153
167
|
if (!response.ok) {
|
|
154
168
|
console.warn(
|
|
155
169
|
`[x402-telemetry] Failed to send event: HTTP ${response.status}`
|
|
156
170
|
);
|
|
157
171
|
}
|
|
158
172
|
} catch (err) {
|
|
173
|
+
if (debug) {
|
|
174
|
+
console.error(`[x402-debug:telemetry] \u274C Error sending:`, err);
|
|
175
|
+
}
|
|
159
176
|
console.error("[x402-telemetry] Error sending telemetry:", err);
|
|
160
177
|
}
|
|
161
178
|
}
|
|
162
179
|
|
|
163
180
|
// src/server/core/verifyPayment.ts
|
|
181
|
+
function debugLog(config, prefix, message, data) {
|
|
182
|
+
if (config?.debug) {
|
|
183
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
184
|
+
console.log(`[${timestamp}] [x402-debug:${prefix}]`, message, data || "");
|
|
185
|
+
}
|
|
186
|
+
}
|
|
164
187
|
async function checkPayment(input) {
|
|
165
188
|
const {
|
|
166
189
|
paymentHeader,
|
|
@@ -230,12 +253,13 @@ async function checkPayment(input) {
|
|
|
230
253
|
isValid: false
|
|
231
254
|
};
|
|
232
255
|
}
|
|
233
|
-
|
|
256
|
+
let baseLogEntry = null;
|
|
257
|
+
if (onPaymentSettled || telemetry) {
|
|
234
258
|
try {
|
|
235
259
|
const headerObj = decodePaymentHeader(paymentHeader);
|
|
236
260
|
const { authorization } = headerObj.payload;
|
|
237
261
|
const assetConfig = getDefaultAssetForNetwork(network);
|
|
238
|
-
|
|
262
|
+
baseLogEntry = {
|
|
239
263
|
id: authorization.nonce,
|
|
240
264
|
from: authorization.from,
|
|
241
265
|
to: authorization.to,
|
|
@@ -247,12 +271,12 @@ async function checkPayment(input) {
|
|
|
247
271
|
facilitatorUrl,
|
|
248
272
|
paymentRequirements
|
|
249
273
|
};
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
);
|
|
274
|
+
debugLog(telemetry, "verify", "\u2705 Payment verified", {
|
|
275
|
+
nonce: authorization.nonce,
|
|
276
|
+
route: routeKey
|
|
277
|
+
});
|
|
278
|
+
if (onPaymentSettled) {
|
|
279
|
+
onPaymentSettled(baseLogEntry);
|
|
256
280
|
}
|
|
257
281
|
} catch (err) {
|
|
258
282
|
console.error(
|
|
@@ -261,11 +285,41 @@ async function checkPayment(input) {
|
|
|
261
285
|
);
|
|
262
286
|
}
|
|
263
287
|
}
|
|
288
|
+
const sendTelemetryAfterResponse = telemetry && baseLogEntry ? (responseStatus, error) => {
|
|
289
|
+
try {
|
|
290
|
+
debugLog(telemetry, "callback", "\u{1F4E4} Telemetry callback invoked", {
|
|
291
|
+
responseStatus,
|
|
292
|
+
hasError: !!error
|
|
293
|
+
});
|
|
294
|
+
const event = createTelemetryEvent(baseLogEntry, telemetry);
|
|
295
|
+
event.responseStatus = responseStatus;
|
|
296
|
+
event.errorMessage = error;
|
|
297
|
+
event.serviceDelivered = responseStatus >= 200 && responseStatus < 300;
|
|
298
|
+
sendTelemetry(event, telemetry.endpoint, telemetry.debug).catch(
|
|
299
|
+
(err) => console.error("[x402-telemetry] Async send failed:", err)
|
|
300
|
+
);
|
|
301
|
+
} catch (err) {
|
|
302
|
+
console.error("[x402-telemetry] Error creating telemetry event:", err);
|
|
303
|
+
}
|
|
304
|
+
} : void 0;
|
|
305
|
+
if (telemetry && baseLogEntry) {
|
|
306
|
+
debugLog(telemetry, "callback", "\u2705 Telemetry callback created", {
|
|
307
|
+
route: routeKey,
|
|
308
|
+
hasTelemetryConfig: !!telemetry,
|
|
309
|
+
hasLogEntry: !!baseLogEntry
|
|
310
|
+
});
|
|
311
|
+
} else if (telemetry) {
|
|
312
|
+
debugLog(telemetry, "callback", "\u26A0\uFE0F Telemetry callback NOT created", {
|
|
313
|
+
hasTelemetryConfig: !!telemetry,
|
|
314
|
+
hasLogEntry: !!baseLogEntry
|
|
315
|
+
});
|
|
316
|
+
}
|
|
264
317
|
return {
|
|
265
318
|
status: "verified",
|
|
266
319
|
statusCode: 200,
|
|
267
320
|
responseBody: null,
|
|
268
|
-
isValid: true
|
|
321
|
+
isValid: true,
|
|
322
|
+
sendTelemetryAfterResponse
|
|
269
323
|
};
|
|
270
324
|
} catch (err) {
|
|
271
325
|
console.error(
|
|
@@ -286,6 +340,12 @@ async function checkPayment(input) {
|
|
|
286
340
|
}
|
|
287
341
|
|
|
288
342
|
// src/server/adapters/web-standards.ts
|
|
343
|
+
function debugLog2(config, prefix, message, data) {
|
|
344
|
+
if (config?.debug) {
|
|
345
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
346
|
+
console.log(`[${timestamp}] [x402-debug:${prefix}]`, message, data || "");
|
|
347
|
+
}
|
|
348
|
+
}
|
|
289
349
|
function mantlePaywall(opts) {
|
|
290
350
|
const { priceUsd, payTo, facilitatorUrl, apiKey, telemetry, onPaymentSettled } = opts;
|
|
291
351
|
validateAddress(payTo, "payTo");
|
|
@@ -331,7 +391,26 @@ function mantlePaywall(opts) {
|
|
|
331
391
|
}
|
|
332
392
|
});
|
|
333
393
|
}
|
|
334
|
-
|
|
394
|
+
try {
|
|
395
|
+
debugLog2(telemetry, "handler", "\u25B6\uFE0F Handler execution started");
|
|
396
|
+
const response = await handler(request);
|
|
397
|
+
debugLog2(telemetry, "handler", `\u2705 Handler completed: ${response.status}`);
|
|
398
|
+
if (result.sendTelemetryAfterResponse) {
|
|
399
|
+
debugLog2(telemetry, "callback", `\u{1F4E4} Calling telemetry callback with status ${response.status}`);
|
|
400
|
+
result.sendTelemetryAfterResponse(response.status);
|
|
401
|
+
} else {
|
|
402
|
+
debugLog2(telemetry, "callback", "\u26A0\uFE0F No telemetry callback to call");
|
|
403
|
+
}
|
|
404
|
+
return response;
|
|
405
|
+
} catch (err) {
|
|
406
|
+
const errorMessage = err instanceof Error ? err.message : "Unknown error";
|
|
407
|
+
debugLog2(telemetry, "handler", `\u274C Handler error: ${errorMessage}`);
|
|
408
|
+
if (result.sendTelemetryAfterResponse) {
|
|
409
|
+
debugLog2(telemetry, "callback", "\u{1F4E4} Calling telemetry callback with error");
|
|
410
|
+
result.sendTelemetryAfterResponse(500, errorMessage);
|
|
411
|
+
}
|
|
412
|
+
throw err;
|
|
413
|
+
}
|
|
335
414
|
};
|
|
336
415
|
};
|
|
337
416
|
}
|
package/dist/server-web.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { W as WebHandler, a as WebPaywallWrapper, m as mantlePaywall } from './web-standards-
|
|
2
|
-
export { M as MinimalPaywallOptions, c as PaymentCheckInput, d as PaymentCheckResult, P as PaymentLogEntry, R as RouteKey, a as RoutePricingConfig, b as RoutesConfig, T as TelemetryConfig } from './types-
|
|
1
|
+
export { W as WebHandler, a as WebPaywallWrapper, m as mantlePaywall } from './web-standards-QCbyQ14G.cjs';
|
|
2
|
+
export { M as MinimalPaywallOptions, c as PaymentCheckInput, d as PaymentCheckResult, P as PaymentLogEntry, R as RouteKey, a as RoutePricingConfig, b as RoutesConfig, T as TelemetryConfig } from './types-BkGUHT4x.cjs';
|
|
3
3
|
export { A as AssetConfig, a as Authorization, E as EIP1193Provider, N as NetworkId, d as PaymentHeaderBase64, c as PaymentHeaderObject, b as PaymentHeaderPayload, P as PaymentRequirements } from './types-BFUqKBBO.cjs';
|
|
4
4
|
export { M as MANTLE_DEFAULTS } from './constants-CsIL25uQ.cjs';
|
package/dist/server-web.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { W as WebHandler, a as WebPaywallWrapper, m as mantlePaywall } from './web-standards-
|
|
2
|
-
export { M as MinimalPaywallOptions, c as PaymentCheckInput, d as PaymentCheckResult, P as PaymentLogEntry, R as RouteKey, a as RoutePricingConfig, b as RoutesConfig, T as TelemetryConfig } from './types-
|
|
1
|
+
export { W as WebHandler, a as WebPaywallWrapper, m as mantlePaywall } from './web-standards-DsCZRJPE.js';
|
|
2
|
+
export { M as MinimalPaywallOptions, c as PaymentCheckInput, d as PaymentCheckResult, P as PaymentLogEntry, R as RouteKey, a as RoutePricingConfig, b as RoutesConfig, T as TelemetryConfig } from './types-Ba0v9XsC.js';
|
|
3
3
|
export { A as AssetConfig, a as Authorization, E as EIP1193Provider, N as NetworkId, d as PaymentHeaderBase64, c as PaymentHeaderObject, b as PaymentHeaderPayload, P as PaymentRequirements } from './types-BFUqKBBO.js';
|
|
4
4
|
export { M as MANTLE_DEFAULTS } from './constants-0ncqvV_O.js';
|