@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.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,
|
|
@@ -240,12 +263,13 @@ async function checkPayment(input) {
|
|
|
240
263
|
isValid: false
|
|
241
264
|
};
|
|
242
265
|
}
|
|
243
|
-
|
|
266
|
+
let baseLogEntry = null;
|
|
267
|
+
if (onPaymentSettled || telemetry) {
|
|
244
268
|
try {
|
|
245
269
|
const headerObj = decodePaymentHeader(paymentHeader);
|
|
246
270
|
const { authorization } = headerObj.payload;
|
|
247
271
|
const assetConfig = getDefaultAssetForNetwork(network);
|
|
248
|
-
|
|
272
|
+
baseLogEntry = {
|
|
249
273
|
id: authorization.nonce,
|
|
250
274
|
from: authorization.from,
|
|
251
275
|
to: authorization.to,
|
|
@@ -257,12 +281,12 @@ async function checkPayment(input) {
|
|
|
257
281
|
facilitatorUrl,
|
|
258
282
|
paymentRequirements
|
|
259
283
|
};
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
);
|
|
284
|
+
debugLog(telemetry, "verify", "\u2705 Payment verified", {
|
|
285
|
+
nonce: authorization.nonce,
|
|
286
|
+
route: routeKey
|
|
287
|
+
});
|
|
288
|
+
if (onPaymentSettled) {
|
|
289
|
+
onPaymentSettled(baseLogEntry);
|
|
266
290
|
}
|
|
267
291
|
} catch (err) {
|
|
268
292
|
console.error(
|
|
@@ -271,11 +295,41 @@ async function checkPayment(input) {
|
|
|
271
295
|
);
|
|
272
296
|
}
|
|
273
297
|
}
|
|
298
|
+
const sendTelemetryAfterResponse = telemetry && baseLogEntry ? (responseStatus, error) => {
|
|
299
|
+
try {
|
|
300
|
+
debugLog(telemetry, "callback", "\u{1F4E4} Telemetry callback invoked", {
|
|
301
|
+
responseStatus,
|
|
302
|
+
hasError: !!error
|
|
303
|
+
});
|
|
304
|
+
const event = createTelemetryEvent(baseLogEntry, telemetry);
|
|
305
|
+
event.responseStatus = responseStatus;
|
|
306
|
+
event.errorMessage = error;
|
|
307
|
+
event.serviceDelivered = responseStatus >= 200 && responseStatus < 300;
|
|
308
|
+
sendTelemetry(event, telemetry.endpoint, telemetry.debug).catch(
|
|
309
|
+
(err) => console.error("[x402-telemetry] Async send failed:", err)
|
|
310
|
+
);
|
|
311
|
+
} catch (err) {
|
|
312
|
+
console.error("[x402-telemetry] Error creating telemetry event:", err);
|
|
313
|
+
}
|
|
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
|
+
}
|
|
274
327
|
return {
|
|
275
328
|
status: "verified",
|
|
276
329
|
statusCode: 200,
|
|
277
330
|
responseBody: null,
|
|
278
|
-
isValid: true
|
|
331
|
+
isValid: true,
|
|
332
|
+
sendTelemetryAfterResponse
|
|
279
333
|
};
|
|
280
334
|
} catch (err) {
|
|
281
335
|
console.error(
|
|
@@ -301,6 +355,12 @@ __export(express_exports, {
|
|
|
301
355
|
createPaymentMiddleware: () => createPaymentMiddleware,
|
|
302
356
|
mantlePaywall: () => mantlePaywall
|
|
303
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
|
+
}
|
|
304
364
|
function createPaymentMiddleware(config) {
|
|
305
365
|
const { facilitatorUrl, receiverAddress, routes, apiKey, onPaymentSettled, telemetry } = config;
|
|
306
366
|
if (!facilitatorUrl) {
|
|
@@ -351,6 +411,25 @@ function createPaymentMiddleware(config) {
|
|
|
351
411
|
res.status(result.statusCode).json(result.responseBody);
|
|
352
412
|
return;
|
|
353
413
|
}
|
|
414
|
+
debugLog2(telemetry, "handler", "\u25B6\uFE0F Handler execution started (Express middleware)");
|
|
415
|
+
if (result.sendTelemetryAfterResponse) {
|
|
416
|
+
res.on("finish", () => {
|
|
417
|
+
const statusCode = res.statusCode;
|
|
418
|
+
debugLog2(telemetry, "handler", `\u2705 Handler completed: ${statusCode}`);
|
|
419
|
+
const errorMessage = statusCode >= 400 ? `Handler returned ${statusCode}` : void 0;
|
|
420
|
+
debugLog2(telemetry, "callback", `\u{1F4E4} Calling telemetry callback with status ${statusCode}`);
|
|
421
|
+
result.sendTelemetryAfterResponse(statusCode, errorMessage);
|
|
422
|
+
});
|
|
423
|
+
res.on("close", () => {
|
|
424
|
+
if (!res.writableEnded) {
|
|
425
|
+
debugLog2(telemetry, "handler", "\u274C Response closed without finishing");
|
|
426
|
+
debugLog2(telemetry, "callback", "\u{1F4E4} Calling telemetry callback with error");
|
|
427
|
+
result.sendTelemetryAfterResponse(500, "Response closed without finishing");
|
|
428
|
+
}
|
|
429
|
+
});
|
|
430
|
+
} else {
|
|
431
|
+
debugLog2(telemetry, "callback", "\u26A0\uFE0F No telemetry callback to call");
|
|
432
|
+
}
|
|
354
433
|
next();
|
|
355
434
|
};
|
|
356
435
|
}
|
|
@@ -386,6 +465,12 @@ __export(nextjs_exports, {
|
|
|
386
465
|
mantlePaywall: () => mantlePaywall2
|
|
387
466
|
});
|
|
388
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
|
+
}
|
|
389
474
|
function mantlePaywall2(opts) {
|
|
390
475
|
const { priceUsd, payTo, facilitatorUrl, apiKey, telemetry, onPaymentSettled } = opts;
|
|
391
476
|
validateAddress(payTo, "payTo");
|
|
@@ -428,7 +513,26 @@ function mantlePaywall2(opts) {
|
|
|
428
513
|
status: result.statusCode
|
|
429
514
|
});
|
|
430
515
|
}
|
|
431
|
-
|
|
516
|
+
try {
|
|
517
|
+
debugLog3(telemetry, "handler", "\u25B6\uFE0F Handler execution started");
|
|
518
|
+
const response = await handler(req);
|
|
519
|
+
debugLog3(telemetry, "handler", `\u2705 Handler completed: ${response.status}`);
|
|
520
|
+
if (result.sendTelemetryAfterResponse) {
|
|
521
|
+
debugLog3(telemetry, "callback", `\u{1F4E4} Calling telemetry callback with status ${response.status}`);
|
|
522
|
+
result.sendTelemetryAfterResponse(response.status);
|
|
523
|
+
} else {
|
|
524
|
+
debugLog3(telemetry, "callback", "\u26A0\uFE0F No telemetry callback to call");
|
|
525
|
+
}
|
|
526
|
+
return response;
|
|
527
|
+
} catch (err) {
|
|
528
|
+
const errorMessage = err instanceof Error ? err.message : "Unknown error";
|
|
529
|
+
debugLog3(telemetry, "handler", `\u274C Handler error: ${errorMessage}`);
|
|
530
|
+
if (result.sendTelemetryAfterResponse) {
|
|
531
|
+
debugLog3(telemetry, "callback", "\u{1F4E4} Calling telemetry callback with error");
|
|
532
|
+
result.sendTelemetryAfterResponse(500, errorMessage);
|
|
533
|
+
}
|
|
534
|
+
throw err;
|
|
535
|
+
}
|
|
432
536
|
};
|
|
433
537
|
};
|
|
434
538
|
}
|
|
@@ -441,6 +545,12 @@ var web_standards_exports = {};
|
|
|
441
545
|
__export(web_standards_exports, {
|
|
442
546
|
mantlePaywall: () => mantlePaywall3
|
|
443
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
|
+
}
|
|
444
554
|
function mantlePaywall3(opts) {
|
|
445
555
|
const { priceUsd, payTo, facilitatorUrl, apiKey, telemetry, onPaymentSettled } = opts;
|
|
446
556
|
validateAddress(payTo, "payTo");
|
|
@@ -486,7 +596,26 @@ function mantlePaywall3(opts) {
|
|
|
486
596
|
}
|
|
487
597
|
});
|
|
488
598
|
}
|
|
489
|
-
|
|
599
|
+
try {
|
|
600
|
+
debugLog4(telemetry, "handler", "\u25B6\uFE0F Handler execution started");
|
|
601
|
+
const response = await handler(request);
|
|
602
|
+
debugLog4(telemetry, "handler", `\u2705 Handler completed: ${response.status}`);
|
|
603
|
+
if (result.sendTelemetryAfterResponse) {
|
|
604
|
+
debugLog4(telemetry, "callback", `\u{1F4E4} Calling telemetry callback with status ${response.status}`);
|
|
605
|
+
result.sendTelemetryAfterResponse(response.status);
|
|
606
|
+
} else {
|
|
607
|
+
debugLog4(telemetry, "callback", "\u26A0\uFE0F No telemetry callback to call");
|
|
608
|
+
}
|
|
609
|
+
return response;
|
|
610
|
+
} catch (err) {
|
|
611
|
+
const errorMessage = err instanceof Error ? err.message : "Unknown error";
|
|
612
|
+
debugLog4(telemetry, "handler", `\u274C Handler error: ${errorMessage}`);
|
|
613
|
+
if (result.sendTelemetryAfterResponse) {
|
|
614
|
+
debugLog4(telemetry, "callback", "\u{1F4E4} Calling telemetry callback with error");
|
|
615
|
+
result.sendTelemetryAfterResponse(500, errorMessage);
|
|
616
|
+
}
|
|
617
|
+
throw err;
|
|
618
|
+
}
|
|
490
619
|
};
|
|
491
620
|
};
|
|
492
621
|
}
|
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,
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { N as NetworkId, P as PaymentRequirements } from './types-BFUqKBBO.cjs';
|
|
2
|
+
|
|
3
|
+
/** Unique key for a protected route, e.g. "GET /api/protected". */
|
|
4
|
+
type RouteKey = string;
|
|
5
|
+
/** Pricing config for a single route. */
|
|
6
|
+
interface RoutePricingConfig {
|
|
7
|
+
/** Price in USD cents, e.g. 1 => $0.01. */
|
|
8
|
+
priceUsdCents: number;
|
|
9
|
+
/** Network identifier (e.g. "mantle-mainnet"). */
|
|
10
|
+
network: NetworkId;
|
|
11
|
+
}
|
|
12
|
+
/** Map of route keys to pricing config. */
|
|
13
|
+
type RoutesConfig = Record<RouteKey, RoutePricingConfig>;
|
|
14
|
+
/** Log entry for a successfully settled payment. */
|
|
15
|
+
interface PaymentLogEntry {
|
|
16
|
+
id: string;
|
|
17
|
+
from: string;
|
|
18
|
+
to: string;
|
|
19
|
+
valueAtomic: string;
|
|
20
|
+
network: NetworkId;
|
|
21
|
+
asset: string;
|
|
22
|
+
route?: RouteKey;
|
|
23
|
+
txHash?: string;
|
|
24
|
+
timestamp: number;
|
|
25
|
+
facilitatorUrl?: string;
|
|
26
|
+
paymentRequirements?: PaymentRequirements;
|
|
27
|
+
}
|
|
28
|
+
/** Config for optional telemetry (billing/analytics). */
|
|
29
|
+
interface TelemetryConfig {
|
|
30
|
+
/** Project key from nosubs.ai dashboard. */
|
|
31
|
+
projectKey: string;
|
|
32
|
+
/**
|
|
33
|
+
* Telemetry endpoint URL.
|
|
34
|
+
* If not specified, uses DEFAULT_TELEMETRY_ENDPOINT (see server/constants.ts).
|
|
35
|
+
*/
|
|
36
|
+
endpoint?: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Minimal config for mantlePaywall() - simplified API for single-route protection.
|
|
40
|
+
* This is the "sweet path" for Mantle mainnet + USDC with sensible defaults.
|
|
41
|
+
*/
|
|
42
|
+
interface MinimalPaywallOptions {
|
|
43
|
+
/** Price in USD (e.g. 0.01 for 1 cent). */
|
|
44
|
+
priceUsd: number;
|
|
45
|
+
/** Recipient address (developer wallet). Validated at runtime. */
|
|
46
|
+
payTo: string;
|
|
47
|
+
/** Optional facilitator URL (defaults to localhost:8080 or NEXT_PUBLIC_FACILITATOR_URL). */
|
|
48
|
+
facilitatorUrl?: string;
|
|
49
|
+
/**
|
|
50
|
+
* Optional API key for hosted facilitator billing.
|
|
51
|
+
* Required when using hosted facilitator (e.g., https://facilitator.x402mantlesdk.xyz).
|
|
52
|
+
* Not needed for self-hosted facilitator.
|
|
53
|
+
*/
|
|
54
|
+
apiKey?: string;
|
|
55
|
+
/** Optional telemetry config. */
|
|
56
|
+
telemetry?: TelemetryConfig;
|
|
57
|
+
/** Optional payment settled hook. */
|
|
58
|
+
onPaymentSettled?: (entry: PaymentLogEntry) => void;
|
|
59
|
+
}
|
|
60
|
+
/** Input for checkPayment function. */
|
|
61
|
+
interface PaymentCheckInput {
|
|
62
|
+
/** X-PAYMENT header value (base64 encoded), or null if not present. */
|
|
63
|
+
paymentHeader: string | null;
|
|
64
|
+
/** Payment requirements for this route. */
|
|
65
|
+
paymentRequirements: PaymentRequirements;
|
|
66
|
+
/** Facilitator URL for verification. */
|
|
67
|
+
facilitatorUrl: string;
|
|
68
|
+
/** Optional API key for hosted facilitator billing. */
|
|
69
|
+
apiKey?: string;
|
|
70
|
+
/** Route key for logging, e.g. "POST /api/generate-image". */
|
|
71
|
+
routeKey?: RouteKey;
|
|
72
|
+
/** Network ID for this payment. */
|
|
73
|
+
network: NetworkId;
|
|
74
|
+
/** Asset address (ERC-20 token). */
|
|
75
|
+
asset: string;
|
|
76
|
+
/** Telemetry config (optional). */
|
|
77
|
+
telemetry?: TelemetryConfig;
|
|
78
|
+
/** Payment settled callback (optional). */
|
|
79
|
+
onPaymentSettled?: (entry: PaymentLogEntry) => void;
|
|
80
|
+
}
|
|
81
|
+
/** Result from checkPayment function. */
|
|
82
|
+
interface PaymentCheckResult {
|
|
83
|
+
/** Status of the payment check. */
|
|
84
|
+
status: "require_payment" | "verification_error" | "invalid_payment" | "verified";
|
|
85
|
+
/** HTTP status code to return. */
|
|
86
|
+
statusCode: 402 | 500 | 200;
|
|
87
|
+
/** Response body to return (null if verified). */
|
|
88
|
+
responseBody: any | null;
|
|
89
|
+
/** Whether payment is valid (only true if status is "verified"). */
|
|
90
|
+
isValid: boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Callback to send telemetry after handler execution.
|
|
93
|
+
* Only present when payment is verified and telemetry is enabled.
|
|
94
|
+
* Adapters should call this after the protected route handler completes.
|
|
95
|
+
*
|
|
96
|
+
* @param responseStatus - HTTP status code from handler (200, 500, etc.)
|
|
97
|
+
* @param error - Optional error message if handler threw
|
|
98
|
+
*/
|
|
99
|
+
sendTelemetryAfterResponse?: (responseStatus: number, error?: string) => void;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export type { MinimalPaywallOptions as M, PaymentLogEntry as P, RouteKey as R, TelemetryConfig as T, RoutePricingConfig as a, RoutesConfig as b, PaymentCheckInput as c, PaymentCheckResult as d };
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { N as NetworkId, P as PaymentRequirements } from './types-BFUqKBBO.js';
|
|
2
|
+
|
|
3
|
+
/** Unique key for a protected route, e.g. "GET /api/protected". */
|
|
4
|
+
type RouteKey = string;
|
|
5
|
+
/** Pricing config for a single route. */
|
|
6
|
+
interface RoutePricingConfig {
|
|
7
|
+
/** Price in USD cents, e.g. 1 => $0.01. */
|
|
8
|
+
priceUsdCents: number;
|
|
9
|
+
/** Network identifier (e.g. "mantle-mainnet"). */
|
|
10
|
+
network: NetworkId;
|
|
11
|
+
}
|
|
12
|
+
/** Map of route keys to pricing config. */
|
|
13
|
+
type RoutesConfig = Record<RouteKey, RoutePricingConfig>;
|
|
14
|
+
/** Log entry for a successfully settled payment. */
|
|
15
|
+
interface PaymentLogEntry {
|
|
16
|
+
id: string;
|
|
17
|
+
from: string;
|
|
18
|
+
to: string;
|
|
19
|
+
valueAtomic: string;
|
|
20
|
+
network: NetworkId;
|
|
21
|
+
asset: string;
|
|
22
|
+
route?: RouteKey;
|
|
23
|
+
txHash?: string;
|
|
24
|
+
timestamp: number;
|
|
25
|
+
facilitatorUrl?: string;
|
|
26
|
+
paymentRequirements?: PaymentRequirements;
|
|
27
|
+
}
|
|
28
|
+
/** Config for optional telemetry (billing/analytics). */
|
|
29
|
+
interface TelemetryConfig {
|
|
30
|
+
/** Project key from nosubs.ai dashboard. */
|
|
31
|
+
projectKey: string;
|
|
32
|
+
/**
|
|
33
|
+
* Telemetry endpoint URL.
|
|
34
|
+
* If not specified, uses DEFAULT_TELEMETRY_ENDPOINT (see server/constants.ts).
|
|
35
|
+
*/
|
|
36
|
+
endpoint?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Enable debug logging for telemetry flow.
|
|
39
|
+
* When true, logs detailed information about payment verification,
|
|
40
|
+
* handler execution, and telemetry transmission.
|
|
41
|
+
*/
|
|
42
|
+
debug?: boolean;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Minimal config for mantlePaywall() - simplified API for single-route protection.
|
|
46
|
+
* This is the "sweet path" for Mantle mainnet + USDC with sensible defaults.
|
|
47
|
+
*/
|
|
48
|
+
interface MinimalPaywallOptions {
|
|
49
|
+
/** Price in USD (e.g. 0.01 for 1 cent). */
|
|
50
|
+
priceUsd: number;
|
|
51
|
+
/** Recipient address (developer wallet). Validated at runtime. */
|
|
52
|
+
payTo: string;
|
|
53
|
+
/** Optional facilitator URL (defaults to localhost:8080 or NEXT_PUBLIC_FACILITATOR_URL). */
|
|
54
|
+
facilitatorUrl?: string;
|
|
55
|
+
/**
|
|
56
|
+
* Optional API key for hosted facilitator billing.
|
|
57
|
+
* Required when using hosted facilitator (e.g., https://facilitator.x402mantlesdk.xyz).
|
|
58
|
+
* Not needed for self-hosted facilitator.
|
|
59
|
+
*/
|
|
60
|
+
apiKey?: string;
|
|
61
|
+
/** Optional telemetry config. */
|
|
62
|
+
telemetry?: TelemetryConfig;
|
|
63
|
+
/** Optional payment settled hook. */
|
|
64
|
+
onPaymentSettled?: (entry: PaymentLogEntry) => void;
|
|
65
|
+
}
|
|
66
|
+
/** Input for checkPayment function. */
|
|
67
|
+
interface PaymentCheckInput {
|
|
68
|
+
/** X-PAYMENT header value (base64 encoded), or null if not present. */
|
|
69
|
+
paymentHeader: string | null;
|
|
70
|
+
/** Payment requirements for this route. */
|
|
71
|
+
paymentRequirements: PaymentRequirements;
|
|
72
|
+
/** Facilitator URL for verification. */
|
|
73
|
+
facilitatorUrl: string;
|
|
74
|
+
/** Optional API key for hosted facilitator billing. */
|
|
75
|
+
apiKey?: string;
|
|
76
|
+
/** Route key for logging, e.g. "POST /api/generate-image". */
|
|
77
|
+
routeKey?: RouteKey;
|
|
78
|
+
/** Network ID for this payment. */
|
|
79
|
+
network: NetworkId;
|
|
80
|
+
/** Asset address (ERC-20 token). */
|
|
81
|
+
asset: string;
|
|
82
|
+
/** Telemetry config (optional). */
|
|
83
|
+
telemetry?: TelemetryConfig;
|
|
84
|
+
/** Payment settled callback (optional). */
|
|
85
|
+
onPaymentSettled?: (entry: PaymentLogEntry) => void;
|
|
86
|
+
}
|
|
87
|
+
/** Result from checkPayment function. */
|
|
88
|
+
interface PaymentCheckResult {
|
|
89
|
+
/** Status of the payment check. */
|
|
90
|
+
status: "require_payment" | "verification_error" | "invalid_payment" | "verified";
|
|
91
|
+
/** HTTP status code to return. */
|
|
92
|
+
statusCode: 402 | 500 | 200;
|
|
93
|
+
/** Response body to return (null if verified). */
|
|
94
|
+
responseBody: any | null;
|
|
95
|
+
/** Whether payment is valid (only true if status is "verified"). */
|
|
96
|
+
isValid: boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Callback to send telemetry after handler execution.
|
|
99
|
+
* Only present when payment is verified and telemetry is enabled.
|
|
100
|
+
* Adapters should call this after the protected route handler completes.
|
|
101
|
+
*
|
|
102
|
+
* @param responseStatus - HTTP status code from handler (200, 500, etc.)
|
|
103
|
+
* @param error - Optional error message if handler threw
|
|
104
|
+
*/
|
|
105
|
+
sendTelemetryAfterResponse?: (responseStatus: number, error?: string) => void;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export type { MinimalPaywallOptions as M, PaymentLogEntry as P, RouteKey as R, TelemetryConfig as T, RoutePricingConfig as a, RoutesConfig as b, PaymentCheckInput as c, PaymentCheckResult as d };
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { N as NetworkId, P as PaymentRequirements } from './types-BFUqKBBO.cjs';
|
|
2
|
+
|
|
3
|
+
/** Unique key for a protected route, e.g. "GET /api/protected". */
|
|
4
|
+
type RouteKey = string;
|
|
5
|
+
/** Pricing config for a single route. */
|
|
6
|
+
interface RoutePricingConfig {
|
|
7
|
+
/** Price in USD cents, e.g. 1 => $0.01. */
|
|
8
|
+
priceUsdCents: number;
|
|
9
|
+
/** Network identifier (e.g. "mantle-mainnet"). */
|
|
10
|
+
network: NetworkId;
|
|
11
|
+
}
|
|
12
|
+
/** Map of route keys to pricing config. */
|
|
13
|
+
type RoutesConfig = Record<RouteKey, RoutePricingConfig>;
|
|
14
|
+
/** Log entry for a successfully settled payment. */
|
|
15
|
+
interface PaymentLogEntry {
|
|
16
|
+
id: string;
|
|
17
|
+
from: string;
|
|
18
|
+
to: string;
|
|
19
|
+
valueAtomic: string;
|
|
20
|
+
network: NetworkId;
|
|
21
|
+
asset: string;
|
|
22
|
+
route?: RouteKey;
|
|
23
|
+
txHash?: string;
|
|
24
|
+
timestamp: number;
|
|
25
|
+
facilitatorUrl?: string;
|
|
26
|
+
paymentRequirements?: PaymentRequirements;
|
|
27
|
+
}
|
|
28
|
+
/** Config for optional telemetry (billing/analytics). */
|
|
29
|
+
interface TelemetryConfig {
|
|
30
|
+
/** Project key from nosubs.ai dashboard. */
|
|
31
|
+
projectKey: string;
|
|
32
|
+
/**
|
|
33
|
+
* Telemetry endpoint URL.
|
|
34
|
+
* If not specified, uses DEFAULT_TELEMETRY_ENDPOINT (see server/constants.ts).
|
|
35
|
+
*/
|
|
36
|
+
endpoint?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Enable debug logging for telemetry flow.
|
|
39
|
+
* When true, logs detailed information about payment verification,
|
|
40
|
+
* handler execution, and telemetry transmission.
|
|
41
|
+
*/
|
|
42
|
+
debug?: boolean;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Minimal config for mantlePaywall() - simplified API for single-route protection.
|
|
46
|
+
* This is the "sweet path" for Mantle mainnet + USDC with sensible defaults.
|
|
47
|
+
*/
|
|
48
|
+
interface MinimalPaywallOptions {
|
|
49
|
+
/** Price in USD (e.g. 0.01 for 1 cent). */
|
|
50
|
+
priceUsd: number;
|
|
51
|
+
/** Recipient address (developer wallet). Validated at runtime. */
|
|
52
|
+
payTo: string;
|
|
53
|
+
/** Optional facilitator URL (defaults to localhost:8080 or NEXT_PUBLIC_FACILITATOR_URL). */
|
|
54
|
+
facilitatorUrl?: string;
|
|
55
|
+
/**
|
|
56
|
+
* Optional API key for hosted facilitator billing.
|
|
57
|
+
* Required when using hosted facilitator (e.g., https://facilitator.x402mantlesdk.xyz).
|
|
58
|
+
* Not needed for self-hosted facilitator.
|
|
59
|
+
*/
|
|
60
|
+
apiKey?: string;
|
|
61
|
+
/** Optional telemetry config. */
|
|
62
|
+
telemetry?: TelemetryConfig;
|
|
63
|
+
/** Optional payment settled hook. */
|
|
64
|
+
onPaymentSettled?: (entry: PaymentLogEntry) => void;
|
|
65
|
+
}
|
|
66
|
+
/** Input for checkPayment function. */
|
|
67
|
+
interface PaymentCheckInput {
|
|
68
|
+
/** X-PAYMENT header value (base64 encoded), or null if not present. */
|
|
69
|
+
paymentHeader: string | null;
|
|
70
|
+
/** Payment requirements for this route. */
|
|
71
|
+
paymentRequirements: PaymentRequirements;
|
|
72
|
+
/** Facilitator URL for verification. */
|
|
73
|
+
facilitatorUrl: string;
|
|
74
|
+
/** Optional API key for hosted facilitator billing. */
|
|
75
|
+
apiKey?: string;
|
|
76
|
+
/** Route key for logging, e.g. "POST /api/generate-image". */
|
|
77
|
+
routeKey?: RouteKey;
|
|
78
|
+
/** Network ID for this payment. */
|
|
79
|
+
network: NetworkId;
|
|
80
|
+
/** Asset address (ERC-20 token). */
|
|
81
|
+
asset: string;
|
|
82
|
+
/** Telemetry config (optional). */
|
|
83
|
+
telemetry?: TelemetryConfig;
|
|
84
|
+
/** Payment settled callback (optional). */
|
|
85
|
+
onPaymentSettled?: (entry: PaymentLogEntry) => void;
|
|
86
|
+
}
|
|
87
|
+
/** Result from checkPayment function. */
|
|
88
|
+
interface PaymentCheckResult {
|
|
89
|
+
/** Status of the payment check. */
|
|
90
|
+
status: "require_payment" | "verification_error" | "invalid_payment" | "verified";
|
|
91
|
+
/** HTTP status code to return. */
|
|
92
|
+
statusCode: 402 | 500 | 200;
|
|
93
|
+
/** Response body to return (null if verified). */
|
|
94
|
+
responseBody: any | null;
|
|
95
|
+
/** Whether payment is valid (only true if status is "verified"). */
|
|
96
|
+
isValid: boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Callback to send telemetry after handler execution.
|
|
99
|
+
* Only present when payment is verified and telemetry is enabled.
|
|
100
|
+
* Adapters should call this after the protected route handler completes.
|
|
101
|
+
*
|
|
102
|
+
* @param responseStatus - HTTP status code from handler (200, 500, etc.)
|
|
103
|
+
* @param error - Optional error message if handler threw
|
|
104
|
+
*/
|
|
105
|
+
sendTelemetryAfterResponse?: (responseStatus: number, error?: string) => void;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export type { MinimalPaywallOptions as M, PaymentLogEntry as P, RouteKey as R, TelemetryConfig as T, RoutePricingConfig as a, RoutesConfig as b, PaymentCheckInput as c, PaymentCheckResult as d };
|