@puga-labs/x402-mantle-sdk 0.3.9 → 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-JXMWK3BO.js +96 -0
- package/dist/chunk-P5FKQVHW.js +99 -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/index.cjs +58 -2
- 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/server-express.cjs +58 -2
- 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 +58 -2
- 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 +58 -2
- 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 +84 -2
- package/dist/server.d.cts +8 -7
- package/dist/server.d.ts +8 -7
- package/dist/server.js +4 -4
- 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/web-standards-DsCZRJPE.d.ts +77 -0
- package/dist/web-standards-QCbyQ14G.d.cts +77 -0
- package/package.json +1 -1
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,
|
|
@@ -252,6 +275,10 @@ async function checkPayment(input) {
|
|
|
252
275
|
facilitatorUrl,
|
|
253
276
|
paymentRequirements
|
|
254
277
|
};
|
|
278
|
+
debugLog(telemetry, "verify", "\u2705 Payment verified", {
|
|
279
|
+
nonce: authorization.nonce,
|
|
280
|
+
route: routeKey
|
|
281
|
+
});
|
|
255
282
|
if (onPaymentSettled) {
|
|
256
283
|
onPaymentSettled(baseLogEntry);
|
|
257
284
|
}
|
|
@@ -264,17 +291,33 @@ async function checkPayment(input) {
|
|
|
264
291
|
}
|
|
265
292
|
const sendTelemetryAfterResponse = telemetry && baseLogEntry ? (responseStatus, error) => {
|
|
266
293
|
try {
|
|
294
|
+
debugLog(telemetry, "callback", "\u{1F4E4} Telemetry callback invoked", {
|
|
295
|
+
responseStatus,
|
|
296
|
+
hasError: !!error
|
|
297
|
+
});
|
|
267
298
|
const event = createTelemetryEvent(baseLogEntry, telemetry);
|
|
268
299
|
event.responseStatus = responseStatus;
|
|
269
300
|
event.errorMessage = error;
|
|
270
301
|
event.serviceDelivered = responseStatus >= 200 && responseStatus < 300;
|
|
271
|
-
sendTelemetry(event, telemetry.endpoint).catch(
|
|
302
|
+
sendTelemetry(event, telemetry.endpoint, telemetry.debug).catch(
|
|
272
303
|
(err) => console.error("[x402-telemetry] Async send failed:", err)
|
|
273
304
|
);
|
|
274
305
|
} catch (err) {
|
|
275
306
|
console.error("[x402-telemetry] Error creating telemetry event:", err);
|
|
276
307
|
}
|
|
277
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
|
+
}
|
|
278
321
|
return {
|
|
279
322
|
status: "verified",
|
|
280
323
|
statusCode: 200,
|
|
@@ -301,6 +344,12 @@ async function checkPayment(input) {
|
|
|
301
344
|
}
|
|
302
345
|
|
|
303
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
|
+
}
|
|
304
353
|
function mantlePaywall(opts) {
|
|
305
354
|
const { priceUsd, payTo, facilitatorUrl, apiKey, telemetry, onPaymentSettled } = opts;
|
|
306
355
|
validateAddress(payTo, "payTo");
|
|
@@ -344,14 +393,21 @@ function mantlePaywall(opts) {
|
|
|
344
393
|
});
|
|
345
394
|
}
|
|
346
395
|
try {
|
|
396
|
+
debugLog2(telemetry, "handler", "\u25B6\uFE0F Handler execution started");
|
|
347
397
|
const response = await handler(req);
|
|
398
|
+
debugLog2(telemetry, "handler", `\u2705 Handler completed: ${response.status}`);
|
|
348
399
|
if (result.sendTelemetryAfterResponse) {
|
|
400
|
+
debugLog2(telemetry, "callback", `\u{1F4E4} Calling telemetry callback with status ${response.status}`);
|
|
349
401
|
result.sendTelemetryAfterResponse(response.status);
|
|
402
|
+
} else {
|
|
403
|
+
debugLog2(telemetry, "callback", "\u26A0\uFE0F No telemetry callback to call");
|
|
350
404
|
}
|
|
351
405
|
return response;
|
|
352
406
|
} catch (err) {
|
|
353
407
|
const errorMessage = err instanceof Error ? err.message : "Unknown error";
|
|
408
|
+
debugLog2(telemetry, "handler", `\u274C Handler error: ${errorMessage}`);
|
|
354
409
|
if (result.sendTelemetryAfterResponse) {
|
|
410
|
+
debugLog2(telemetry, "callback", "\u{1F4E4} Calling telemetry callback with error");
|
|
355
411
|
result.sendTelemetryAfterResponse(500, errorMessage);
|
|
356
412
|
}
|
|
357
413
|
throw err;
|
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,
|
|
@@ -248,6 +271,10 @@ async function checkPayment(input) {
|
|
|
248
271
|
facilitatorUrl,
|
|
249
272
|
paymentRequirements
|
|
250
273
|
};
|
|
274
|
+
debugLog(telemetry, "verify", "\u2705 Payment verified", {
|
|
275
|
+
nonce: authorization.nonce,
|
|
276
|
+
route: routeKey
|
|
277
|
+
});
|
|
251
278
|
if (onPaymentSettled) {
|
|
252
279
|
onPaymentSettled(baseLogEntry);
|
|
253
280
|
}
|
|
@@ -260,17 +287,33 @@ async function checkPayment(input) {
|
|
|
260
287
|
}
|
|
261
288
|
const sendTelemetryAfterResponse = telemetry && baseLogEntry ? (responseStatus, error) => {
|
|
262
289
|
try {
|
|
290
|
+
debugLog(telemetry, "callback", "\u{1F4E4} Telemetry callback invoked", {
|
|
291
|
+
responseStatus,
|
|
292
|
+
hasError: !!error
|
|
293
|
+
});
|
|
263
294
|
const event = createTelemetryEvent(baseLogEntry, telemetry);
|
|
264
295
|
event.responseStatus = responseStatus;
|
|
265
296
|
event.errorMessage = error;
|
|
266
297
|
event.serviceDelivered = responseStatus >= 200 && responseStatus < 300;
|
|
267
|
-
sendTelemetry(event, telemetry.endpoint).catch(
|
|
298
|
+
sendTelemetry(event, telemetry.endpoint, telemetry.debug).catch(
|
|
268
299
|
(err) => console.error("[x402-telemetry] Async send failed:", err)
|
|
269
300
|
);
|
|
270
301
|
} catch (err) {
|
|
271
302
|
console.error("[x402-telemetry] Error creating telemetry event:", err);
|
|
272
303
|
}
|
|
273
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
|
+
}
|
|
274
317
|
return {
|
|
275
318
|
status: "verified",
|
|
276
319
|
statusCode: 200,
|
|
@@ -297,6 +340,12 @@ async function checkPayment(input) {
|
|
|
297
340
|
}
|
|
298
341
|
|
|
299
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
|
+
}
|
|
300
349
|
function mantlePaywall(opts) {
|
|
301
350
|
const { priceUsd, payTo, facilitatorUrl, apiKey, telemetry, onPaymentSettled } = opts;
|
|
302
351
|
validateAddress(payTo, "payTo");
|
|
@@ -343,14 +392,21 @@ function mantlePaywall(opts) {
|
|
|
343
392
|
});
|
|
344
393
|
}
|
|
345
394
|
try {
|
|
395
|
+
debugLog2(telemetry, "handler", "\u25B6\uFE0F Handler execution started");
|
|
346
396
|
const response = await handler(request);
|
|
397
|
+
debugLog2(telemetry, "handler", `\u2705 Handler completed: ${response.status}`);
|
|
347
398
|
if (result.sendTelemetryAfterResponse) {
|
|
399
|
+
debugLog2(telemetry, "callback", `\u{1F4E4} Calling telemetry callback with status ${response.status}`);
|
|
348
400
|
result.sendTelemetryAfterResponse(response.status);
|
|
401
|
+
} else {
|
|
402
|
+
debugLog2(telemetry, "callback", "\u26A0\uFE0F No telemetry callback to call");
|
|
349
403
|
}
|
|
350
404
|
return response;
|
|
351
405
|
} catch (err) {
|
|
352
406
|
const errorMessage = err instanceof Error ? err.message : "Unknown error";
|
|
407
|
+
debugLog2(telemetry, "handler", `\u274C Handler error: ${errorMessage}`);
|
|
353
408
|
if (result.sendTelemetryAfterResponse) {
|
|
409
|
+
debugLog2(telemetry, "callback", "\u{1F4E4} Calling telemetry callback with error");
|
|
354
410
|
result.sendTelemetryAfterResponse(500, errorMessage);
|
|
355
411
|
}
|
|
356
412
|
throw err;
|
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';
|
package/dist/server-web.js
CHANGED
package/dist/server.cjs
CHANGED
|
@@ -146,9 +146,20 @@ function createTelemetryEvent(entry, config) {
|
|
|
146
146
|
priceUsd: entry.paymentRequirements?.price
|
|
147
147
|
};
|
|
148
148
|
}
|
|
149
|
-
async function sendTelemetry(event, endpoint) {
|
|
149
|
+
async function sendTelemetry(event, endpoint, debug) {
|
|
150
150
|
const targetEndpoint = endpoint ?? DEFAULT_TELEMETRY_ENDPOINT;
|
|
151
|
+
if (debug) {
|
|
152
|
+
console.log(`[x402-debug:telemetry] \u{1F4E4} Sending telemetry event:`, {
|
|
153
|
+
event: event.event,
|
|
154
|
+
endpoint: targetEndpoint,
|
|
155
|
+
projectKey: event.projectKey.substring(0, 10) + "...",
|
|
156
|
+
route: event.route,
|
|
157
|
+
responseStatus: event.responseStatus,
|
|
158
|
+
serviceDelivered: event.serviceDelivered
|
|
159
|
+
});
|
|
160
|
+
}
|
|
151
161
|
if (!targetEndpoint) {
|
|
162
|
+
if (debug) console.log(`[x402-debug:telemetry] \u26A0\uFE0F No endpoint configured, skipping`);
|
|
152
163
|
return;
|
|
153
164
|
}
|
|
154
165
|
try {
|
|
@@ -160,17 +171,29 @@ async function sendTelemetry(event, endpoint) {
|
|
|
160
171
|
},
|
|
161
172
|
body: JSON.stringify(event)
|
|
162
173
|
});
|
|
174
|
+
if (debug) {
|
|
175
|
+
console.log(`[x402-debug:telemetry] ${response.ok ? "\u2705" : "\u274C"} Telemetry sent: HTTP ${response.status}`);
|
|
176
|
+
}
|
|
163
177
|
if (!response.ok) {
|
|
164
178
|
console.warn(
|
|
165
179
|
`[x402-telemetry] Failed to send event: HTTP ${response.status}`
|
|
166
180
|
);
|
|
167
181
|
}
|
|
168
182
|
} catch (err) {
|
|
183
|
+
if (debug) {
|
|
184
|
+
console.error(`[x402-debug:telemetry] \u274C Error sending:`, err);
|
|
185
|
+
}
|
|
169
186
|
console.error("[x402-telemetry] Error sending telemetry:", err);
|
|
170
187
|
}
|
|
171
188
|
}
|
|
172
189
|
|
|
173
190
|
// src/server/core/verifyPayment.ts
|
|
191
|
+
function debugLog(config, prefix, message, data) {
|
|
192
|
+
if (config?.debug) {
|
|
193
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
194
|
+
console.log(`[${timestamp}] [x402-debug:${prefix}]`, message, data || "");
|
|
195
|
+
}
|
|
196
|
+
}
|
|
174
197
|
async function checkPayment(input) {
|
|
175
198
|
const {
|
|
176
199
|
paymentHeader,
|
|
@@ -258,6 +281,10 @@ async function checkPayment(input) {
|
|
|
258
281
|
facilitatorUrl,
|
|
259
282
|
paymentRequirements
|
|
260
283
|
};
|
|
284
|
+
debugLog(telemetry, "verify", "\u2705 Payment verified", {
|
|
285
|
+
nonce: authorization.nonce,
|
|
286
|
+
route: routeKey
|
|
287
|
+
});
|
|
261
288
|
if (onPaymentSettled) {
|
|
262
289
|
onPaymentSettled(baseLogEntry);
|
|
263
290
|
}
|
|
@@ -270,17 +297,33 @@ async function checkPayment(input) {
|
|
|
270
297
|
}
|
|
271
298
|
const sendTelemetryAfterResponse = telemetry && baseLogEntry ? (responseStatus, error) => {
|
|
272
299
|
try {
|
|
300
|
+
debugLog(telemetry, "callback", "\u{1F4E4} Telemetry callback invoked", {
|
|
301
|
+
responseStatus,
|
|
302
|
+
hasError: !!error
|
|
303
|
+
});
|
|
273
304
|
const event = createTelemetryEvent(baseLogEntry, telemetry);
|
|
274
305
|
event.responseStatus = responseStatus;
|
|
275
306
|
event.errorMessage = error;
|
|
276
307
|
event.serviceDelivered = responseStatus >= 200 && responseStatus < 300;
|
|
277
|
-
sendTelemetry(event, telemetry.endpoint).catch(
|
|
308
|
+
sendTelemetry(event, telemetry.endpoint, telemetry.debug).catch(
|
|
278
309
|
(err) => console.error("[x402-telemetry] Async send failed:", err)
|
|
279
310
|
);
|
|
280
311
|
} catch (err) {
|
|
281
312
|
console.error("[x402-telemetry] Error creating telemetry event:", err);
|
|
282
313
|
}
|
|
283
314
|
} : void 0;
|
|
315
|
+
if (telemetry && baseLogEntry) {
|
|
316
|
+
debugLog(telemetry, "callback", "\u2705 Telemetry callback created", {
|
|
317
|
+
route: routeKey,
|
|
318
|
+
hasTelemetryConfig: !!telemetry,
|
|
319
|
+
hasLogEntry: !!baseLogEntry
|
|
320
|
+
});
|
|
321
|
+
} else if (telemetry) {
|
|
322
|
+
debugLog(telemetry, "callback", "\u26A0\uFE0F Telemetry callback NOT created", {
|
|
323
|
+
hasTelemetryConfig: !!telemetry,
|
|
324
|
+
hasLogEntry: !!baseLogEntry
|
|
325
|
+
});
|
|
326
|
+
}
|
|
284
327
|
return {
|
|
285
328
|
status: "verified",
|
|
286
329
|
statusCode: 200,
|
|
@@ -312,6 +355,12 @@ __export(express_exports, {
|
|
|
312
355
|
createPaymentMiddleware: () => createPaymentMiddleware,
|
|
313
356
|
mantlePaywall: () => mantlePaywall
|
|
314
357
|
});
|
|
358
|
+
function debugLog2(config, prefix, message, data) {
|
|
359
|
+
if (config?.debug) {
|
|
360
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
361
|
+
console.log(`[${timestamp}] [x402-debug:${prefix}]`, message, data || "");
|
|
362
|
+
}
|
|
363
|
+
}
|
|
315
364
|
function createPaymentMiddleware(config) {
|
|
316
365
|
const { facilitatorUrl, receiverAddress, routes, apiKey, onPaymentSettled, telemetry } = config;
|
|
317
366
|
if (!facilitatorUrl) {
|
|
@@ -362,17 +411,24 @@ function createPaymentMiddleware(config) {
|
|
|
362
411
|
res.status(result.statusCode).json(result.responseBody);
|
|
363
412
|
return;
|
|
364
413
|
}
|
|
414
|
+
debugLog2(telemetry, "handler", "\u25B6\uFE0F Handler execution started (Express middleware)");
|
|
365
415
|
if (result.sendTelemetryAfterResponse) {
|
|
366
416
|
res.on("finish", () => {
|
|
367
417
|
const statusCode = res.statusCode;
|
|
418
|
+
debugLog2(telemetry, "handler", `\u2705 Handler completed: ${statusCode}`);
|
|
368
419
|
const errorMessage = statusCode >= 400 ? `Handler returned ${statusCode}` : void 0;
|
|
420
|
+
debugLog2(telemetry, "callback", `\u{1F4E4} Calling telemetry callback with status ${statusCode}`);
|
|
369
421
|
result.sendTelemetryAfterResponse(statusCode, errorMessage);
|
|
370
422
|
});
|
|
371
423
|
res.on("close", () => {
|
|
372
424
|
if (!res.writableEnded) {
|
|
425
|
+
debugLog2(telemetry, "handler", "\u274C Response closed without finishing");
|
|
426
|
+
debugLog2(telemetry, "callback", "\u{1F4E4} Calling telemetry callback with error");
|
|
373
427
|
result.sendTelemetryAfterResponse(500, "Response closed without finishing");
|
|
374
428
|
}
|
|
375
429
|
});
|
|
430
|
+
} else {
|
|
431
|
+
debugLog2(telemetry, "callback", "\u26A0\uFE0F No telemetry callback to call");
|
|
376
432
|
}
|
|
377
433
|
next();
|
|
378
434
|
};
|
|
@@ -409,6 +465,12 @@ __export(nextjs_exports, {
|
|
|
409
465
|
mantlePaywall: () => mantlePaywall2
|
|
410
466
|
});
|
|
411
467
|
var import_server = require("next/server");
|
|
468
|
+
function debugLog3(config, prefix, message, data) {
|
|
469
|
+
if (config?.debug) {
|
|
470
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
471
|
+
console.log(`[${timestamp}] [x402-debug:${prefix}]`, message, data || "");
|
|
472
|
+
}
|
|
473
|
+
}
|
|
412
474
|
function mantlePaywall2(opts) {
|
|
413
475
|
const { priceUsd, payTo, facilitatorUrl, apiKey, telemetry, onPaymentSettled } = opts;
|
|
414
476
|
validateAddress(payTo, "payTo");
|
|
@@ -452,14 +514,21 @@ function mantlePaywall2(opts) {
|
|
|
452
514
|
});
|
|
453
515
|
}
|
|
454
516
|
try {
|
|
517
|
+
debugLog3(telemetry, "handler", "\u25B6\uFE0F Handler execution started");
|
|
455
518
|
const response = await handler(req);
|
|
519
|
+
debugLog3(telemetry, "handler", `\u2705 Handler completed: ${response.status}`);
|
|
456
520
|
if (result.sendTelemetryAfterResponse) {
|
|
521
|
+
debugLog3(telemetry, "callback", `\u{1F4E4} Calling telemetry callback with status ${response.status}`);
|
|
457
522
|
result.sendTelemetryAfterResponse(response.status);
|
|
523
|
+
} else {
|
|
524
|
+
debugLog3(telemetry, "callback", "\u26A0\uFE0F No telemetry callback to call");
|
|
458
525
|
}
|
|
459
526
|
return response;
|
|
460
527
|
} catch (err) {
|
|
461
528
|
const errorMessage = err instanceof Error ? err.message : "Unknown error";
|
|
529
|
+
debugLog3(telemetry, "handler", `\u274C Handler error: ${errorMessage}`);
|
|
462
530
|
if (result.sendTelemetryAfterResponse) {
|
|
531
|
+
debugLog3(telemetry, "callback", "\u{1F4E4} Calling telemetry callback with error");
|
|
463
532
|
result.sendTelemetryAfterResponse(500, errorMessage);
|
|
464
533
|
}
|
|
465
534
|
throw err;
|
|
@@ -476,6 +545,12 @@ var web_standards_exports = {};
|
|
|
476
545
|
__export(web_standards_exports, {
|
|
477
546
|
mantlePaywall: () => mantlePaywall3
|
|
478
547
|
});
|
|
548
|
+
function debugLog4(config, prefix, message, data) {
|
|
549
|
+
if (config?.debug) {
|
|
550
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
551
|
+
console.log(`[${timestamp}] [x402-debug:${prefix}]`, message, data || "");
|
|
552
|
+
}
|
|
553
|
+
}
|
|
479
554
|
function mantlePaywall3(opts) {
|
|
480
555
|
const { priceUsd, payTo, facilitatorUrl, apiKey, telemetry, onPaymentSettled } = opts;
|
|
481
556
|
validateAddress(payTo, "payTo");
|
|
@@ -522,14 +597,21 @@ function mantlePaywall3(opts) {
|
|
|
522
597
|
});
|
|
523
598
|
}
|
|
524
599
|
try {
|
|
600
|
+
debugLog4(telemetry, "handler", "\u25B6\uFE0F Handler execution started");
|
|
525
601
|
const response = await handler(request);
|
|
602
|
+
debugLog4(telemetry, "handler", `\u2705 Handler completed: ${response.status}`);
|
|
526
603
|
if (result.sendTelemetryAfterResponse) {
|
|
604
|
+
debugLog4(telemetry, "callback", `\u{1F4E4} Calling telemetry callback with status ${response.status}`);
|
|
527
605
|
result.sendTelemetryAfterResponse(response.status);
|
|
606
|
+
} else {
|
|
607
|
+
debugLog4(telemetry, "callback", "\u26A0\uFE0F No telemetry callback to call");
|
|
528
608
|
}
|
|
529
609
|
return response;
|
|
530
610
|
} catch (err) {
|
|
531
611
|
const errorMessage = err instanceof Error ? err.message : "Unknown error";
|
|
612
|
+
debugLog4(telemetry, "handler", `\u274C Handler error: ${errorMessage}`);
|
|
532
613
|
if (result.sendTelemetryAfterResponse) {
|
|
614
|
+
debugLog4(telemetry, "callback", "\u{1F4E4} Calling telemetry callback with error");
|
|
533
615
|
result.sendTelemetryAfterResponse(500, errorMessage);
|
|
534
616
|
}
|
|
535
617
|
throw err;
|
package/dist/server.d.cts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { c as PaymentCheckInput, d as PaymentCheckResult } from './types-
|
|
2
|
-
export { M as MinimalPaywallOptions, P as PaymentLogEntry, R as RouteKey, a as RoutePricingConfig, b as RoutesConfig, T as TelemetryConfig } from './types-
|
|
1
|
+
import { c as PaymentCheckInput, d as PaymentCheckResult } from './types-BkGUHT4x.cjs';
|
|
2
|
+
export { M as MinimalPaywallOptions, P as PaymentLogEntry, R as RouteKey, a as RoutePricingConfig, b as RoutesConfig, T as TelemetryConfig } from './types-BkGUHT4x.cjs';
|
|
3
3
|
import { c as PaymentHeaderObject } from './types-BFUqKBBO.cjs';
|
|
4
|
-
export { M as MantleMiddleware, c as createPaymentMiddleware, e as express, m as mantlePaywall } from './express-
|
|
5
|
-
export { n as nextjs } from './nextjs-
|
|
6
|
-
export { w as web } from './web-standards-
|
|
7
|
-
import { P as PaymentLogEntry, T as TelemetryConfig, c as TelemetryEvent } from './types-
|
|
4
|
+
export { M as MantleMiddleware, c as createPaymentMiddleware, e as express, m as mantlePaywall } from './express-BWE0nQty.cjs';
|
|
5
|
+
export { n as nextjs } from './nextjs-Bujo9Okf.cjs';
|
|
6
|
+
export { w as web } from './web-standards-QCbyQ14G.cjs';
|
|
7
|
+
import { P as PaymentLogEntry, T as TelemetryConfig, c as TelemetryEvent } from './types-DrBw0xwj.cjs';
|
|
8
8
|
import 'express';
|
|
9
9
|
import 'next/server';
|
|
10
10
|
|
|
@@ -73,7 +73,8 @@ declare function createTelemetryEvent(entry: PaymentLogEntry, config: TelemetryC
|
|
|
73
73
|
*
|
|
74
74
|
* @param event - The telemetry event to send
|
|
75
75
|
* @param endpoint - The telemetry endpoint URL (optional, falls back to DEFAULT_TELEMETRY_ENDPOINT)
|
|
76
|
+
* @param debug - Enable debug logging for telemetry transmission
|
|
76
77
|
*/
|
|
77
|
-
declare function sendTelemetry(event: TelemetryEvent, endpoint?: string): Promise<void>;
|
|
78
|
+
declare function sendTelemetry(event: TelemetryEvent, endpoint?: string, debug?: boolean): Promise<void>;
|
|
78
79
|
|
|
79
80
|
export { DEFAULT_TELEMETRY_ENDPOINT, PaymentCheckInput, PaymentCheckResult, buildRouteKey, checkPayment, createTelemetryEvent, decodePaymentHeader, sendTelemetry, validateAddress };
|
package/dist/server.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { c as PaymentCheckInput, d as PaymentCheckResult } from './types-
|
|
2
|
-
export { M as MinimalPaywallOptions, P as PaymentLogEntry, R as RouteKey, a as RoutePricingConfig, b as RoutesConfig, T as TelemetryConfig } from './types-
|
|
1
|
+
import { c as PaymentCheckInput, d as PaymentCheckResult } from './types-Ba0v9XsC.js';
|
|
2
|
+
export { M as MinimalPaywallOptions, P as PaymentLogEntry, R as RouteKey, a as RoutePricingConfig, b as RoutesConfig, T as TelemetryConfig } from './types-Ba0v9XsC.js';
|
|
3
3
|
import { c as PaymentHeaderObject } from './types-BFUqKBBO.js';
|
|
4
|
-
export { M as MantleMiddleware, c as createPaymentMiddleware, e as express, m as mantlePaywall } from './express-
|
|
5
|
-
export { n as nextjs } from './nextjs-
|
|
6
|
-
export { w as web } from './web-standards-
|
|
7
|
-
import { P as PaymentLogEntry, T as TelemetryConfig, c as TelemetryEvent } from './types-
|
|
4
|
+
export { M as MantleMiddleware, c as createPaymentMiddleware, e as express, m as mantlePaywall } from './express-BvuN0Lx1.js';
|
|
5
|
+
export { n as nextjs } from './nextjs-CzSejZe8.js';
|
|
6
|
+
export { w as web } from './web-standards-DsCZRJPE.js';
|
|
7
|
+
import { P as PaymentLogEntry, T as TelemetryConfig, c as TelemetryEvent } from './types-DEpSrXCf.js';
|
|
8
8
|
import 'express';
|
|
9
9
|
import 'next/server';
|
|
10
10
|
|
|
@@ -73,7 +73,8 @@ declare function createTelemetryEvent(entry: PaymentLogEntry, config: TelemetryC
|
|
|
73
73
|
*
|
|
74
74
|
* @param event - The telemetry event to send
|
|
75
75
|
* @param endpoint - The telemetry endpoint URL (optional, falls back to DEFAULT_TELEMETRY_ENDPOINT)
|
|
76
|
+
* @param debug - Enable debug logging for telemetry transmission
|
|
76
77
|
*/
|
|
77
|
-
declare function sendTelemetry(event: TelemetryEvent, endpoint?: string): Promise<void>;
|
|
78
|
+
declare function sendTelemetry(event: TelemetryEvent, endpoint?: string, debug?: boolean): Promise<void>;
|
|
78
79
|
|
|
79
80
|
export { DEFAULT_TELEMETRY_ENDPOINT, PaymentCheckInput, PaymentCheckResult, buildRouteKey, checkPayment, createTelemetryEvent, decodePaymentHeader, sendTelemetry, validateAddress };
|
package/dist/server.js
CHANGED
|
@@ -3,13 +3,13 @@ import {
|
|
|
3
3
|
createPaymentMiddleware,
|
|
4
4
|
express_exports,
|
|
5
5
|
mantlePaywall
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-3DGAB7HD.js";
|
|
7
7
|
import {
|
|
8
8
|
nextjs_exports
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-P5FKQVHW.js";
|
|
10
10
|
import {
|
|
11
11
|
web_standards_exports
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-JXMWK3BO.js";
|
|
13
13
|
import {
|
|
14
14
|
DEFAULT_TELEMETRY_ENDPOINT,
|
|
15
15
|
buildRouteKey,
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
decodePaymentHeader,
|
|
19
19
|
sendTelemetry,
|
|
20
20
|
validateAddress
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-UVYA6H32.js";
|
|
22
22
|
import "./chunk-HEZZ74SI.js";
|
|
23
23
|
export {
|
|
24
24
|
DEFAULT_TELEMETRY_ENDPOINT,
|