@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.
@@ -0,0 +1,126 @@
1
+ import {
2
+ buildRouteKey,
3
+ checkPayment,
4
+ validateAddress
5
+ } from "./chunk-UVYA6H32.js";
6
+ import {
7
+ MANTLE_DEFAULTS,
8
+ __export,
9
+ getDefaultAssetForNetwork,
10
+ usdCentsToAtomic
11
+ } from "./chunk-HEZZ74SI.js";
12
+
13
+ // src/server/adapters/express.ts
14
+ var express_exports = {};
15
+ __export(express_exports, {
16
+ createPaymentMiddleware: () => createPaymentMiddleware,
17
+ mantlePaywall: () => mantlePaywall
18
+ });
19
+ function debugLog(config, prefix, message, data) {
20
+ if (config?.debug) {
21
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString();
22
+ console.log(`[${timestamp}] [x402-debug:${prefix}]`, message, data || "");
23
+ }
24
+ }
25
+ function createPaymentMiddleware(config) {
26
+ const { facilitatorUrl, receiverAddress, routes, apiKey, onPaymentSettled, telemetry } = config;
27
+ if (!facilitatorUrl) {
28
+ throw new Error("facilitatorUrl is required");
29
+ }
30
+ if (!receiverAddress) {
31
+ throw new Error("receiverAddress is required");
32
+ }
33
+ validateAddress(receiverAddress, "receiverAddress");
34
+ if (!routes || Object.keys(routes).length === 0) {
35
+ throw new Error("routes config must not be empty");
36
+ }
37
+ return async function paymentMiddleware(req, res, next) {
38
+ const routeKey = buildRouteKey(req.method, req.path);
39
+ const routeConfig = routes[routeKey];
40
+ if (!routeConfig) {
41
+ next();
42
+ return;
43
+ }
44
+ const { priceUsdCents, network } = routeConfig;
45
+ const assetConfig = getDefaultAssetForNetwork(network);
46
+ const maxAmountRequiredBigInt = usdCentsToAtomic(
47
+ priceUsdCents,
48
+ assetConfig.decimals
49
+ );
50
+ const paymentRequirements = {
51
+ scheme: "exact",
52
+ network,
53
+ asset: assetConfig.address,
54
+ maxAmountRequired: maxAmountRequiredBigInt.toString(),
55
+ payTo: receiverAddress,
56
+ price: `$${(priceUsdCents / 100).toFixed(2)}`,
57
+ currency: "USD"
58
+ };
59
+ const paymentHeader = req.header("X-PAYMENT") || req.header("x-payment") || null;
60
+ const result = await checkPayment({
61
+ paymentHeader,
62
+ paymentRequirements,
63
+ facilitatorUrl,
64
+ apiKey,
65
+ routeKey,
66
+ network,
67
+ asset: assetConfig.address,
68
+ telemetry,
69
+ onPaymentSettled
70
+ });
71
+ if (!result.isValid) {
72
+ res.status(result.statusCode).json(result.responseBody);
73
+ return;
74
+ }
75
+ debugLog(telemetry, "handler", "\u25B6\uFE0F Handler execution started (Express middleware)");
76
+ if (result.sendTelemetryAfterResponse) {
77
+ res.on("finish", () => {
78
+ const statusCode = res.statusCode;
79
+ debugLog(telemetry, "handler", `\u2705 Handler completed: ${statusCode}`);
80
+ const errorMessage = statusCode >= 400 ? `Handler returned ${statusCode}` : void 0;
81
+ debugLog(telemetry, "callback", `\u{1F4E4} Calling telemetry callback with status ${statusCode}`);
82
+ result.sendTelemetryAfterResponse(statusCode, errorMessage);
83
+ });
84
+ res.on("close", () => {
85
+ if (!res.writableEnded) {
86
+ debugLog(telemetry, "handler", "\u274C Response closed without finishing");
87
+ debugLog(telemetry, "callback", "\u{1F4E4} Calling telemetry callback with error");
88
+ result.sendTelemetryAfterResponse(500, "Response closed without finishing");
89
+ }
90
+ });
91
+ } else {
92
+ debugLog(telemetry, "callback", "\u26A0\uFE0F No telemetry callback to call");
93
+ }
94
+ next();
95
+ };
96
+ }
97
+ function mantlePaywall(opts) {
98
+ const { priceUsd, payTo, facilitatorUrl, apiKey, telemetry, onPaymentSettled } = opts;
99
+ validateAddress(payTo, "payTo");
100
+ const priceUsdCents = Math.round(priceUsd * 100);
101
+ return async (req, res, next) => {
102
+ const method = (req.method || "GET").toUpperCase();
103
+ const path = req.path || "/";
104
+ const routeKey = `${method} ${path}`;
105
+ const middleware = createPaymentMiddleware({
106
+ facilitatorUrl: facilitatorUrl || MANTLE_DEFAULTS.FACILITATOR_URL,
107
+ receiverAddress: payTo,
108
+ routes: {
109
+ [routeKey]: {
110
+ priceUsdCents,
111
+ network: MANTLE_DEFAULTS.NETWORK
112
+ }
113
+ },
114
+ apiKey,
115
+ telemetry,
116
+ onPaymentSettled
117
+ });
118
+ return middleware(req, res, next);
119
+ };
120
+ }
121
+
122
+ export {
123
+ createPaymentMiddleware,
124
+ mantlePaywall,
125
+ express_exports
126
+ };
@@ -0,0 +1,96 @@
1
+ import {
2
+ buildRouteKey,
3
+ checkPayment,
4
+ validateAddress
5
+ } from "./chunk-UVYA6H32.js";
6
+ import {
7
+ MANTLE_DEFAULTS,
8
+ __export,
9
+ getDefaultAssetForNetwork,
10
+ usdCentsToAtomic
11
+ } from "./chunk-HEZZ74SI.js";
12
+
13
+ // src/server/adapters/web-standards.ts
14
+ var web_standards_exports = {};
15
+ __export(web_standards_exports, {
16
+ mantlePaywall: () => mantlePaywall
17
+ });
18
+ function debugLog(config, prefix, message, data) {
19
+ if (config?.debug) {
20
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString();
21
+ console.log(`[${timestamp}] [x402-debug:${prefix}]`, message, data || "");
22
+ }
23
+ }
24
+ function mantlePaywall(opts) {
25
+ const { priceUsd, payTo, facilitatorUrl, apiKey, telemetry, onPaymentSettled } = opts;
26
+ validateAddress(payTo, "payTo");
27
+ const priceUsdCents = Math.round(priceUsd * 100);
28
+ return function(handler) {
29
+ return async (request) => {
30
+ const url = new URL(request.url);
31
+ const method = request.method;
32
+ const path = url.pathname;
33
+ const routeKey = buildRouteKey(method, path);
34
+ const network = MANTLE_DEFAULTS.NETWORK;
35
+ const assetConfig = getDefaultAssetForNetwork(network);
36
+ const maxAmountRequiredBigInt = usdCentsToAtomic(
37
+ priceUsdCents,
38
+ assetConfig.decimals
39
+ );
40
+ const paymentRequirements = {
41
+ scheme: "exact",
42
+ network,
43
+ asset: assetConfig.address,
44
+ maxAmountRequired: maxAmountRequiredBigInt.toString(),
45
+ payTo,
46
+ price: `$${(priceUsdCents / 100).toFixed(2)}`,
47
+ currency: "USD"
48
+ };
49
+ const paymentHeader = request.headers.get("X-PAYMENT") || request.headers.get("x-payment") || null;
50
+ const result = await checkPayment({
51
+ paymentHeader,
52
+ paymentRequirements,
53
+ facilitatorUrl: facilitatorUrl || MANTLE_DEFAULTS.FACILITATOR_URL,
54
+ apiKey,
55
+ routeKey,
56
+ network,
57
+ asset: assetConfig.address,
58
+ telemetry,
59
+ onPaymentSettled
60
+ });
61
+ if (!result.isValid) {
62
+ return new Response(JSON.stringify(result.responseBody), {
63
+ status: result.statusCode,
64
+ headers: {
65
+ "Content-Type": "application/json"
66
+ }
67
+ });
68
+ }
69
+ try {
70
+ debugLog(telemetry, "handler", "\u25B6\uFE0F Handler execution started");
71
+ const response = await handler(request);
72
+ debugLog(telemetry, "handler", `\u2705 Handler completed: ${response.status}`);
73
+ if (result.sendTelemetryAfterResponse) {
74
+ debugLog(telemetry, "callback", `\u{1F4E4} Calling telemetry callback with status ${response.status}`);
75
+ result.sendTelemetryAfterResponse(response.status);
76
+ } else {
77
+ debugLog(telemetry, "callback", "\u26A0\uFE0F No telemetry callback to call");
78
+ }
79
+ return response;
80
+ } catch (err) {
81
+ const errorMessage = err instanceof Error ? err.message : "Unknown error";
82
+ debugLog(telemetry, "handler", `\u274C Handler error: ${errorMessage}`);
83
+ if (result.sendTelemetryAfterResponse) {
84
+ debugLog(telemetry, "callback", "\u{1F4E4} Calling telemetry callback with error");
85
+ result.sendTelemetryAfterResponse(500, errorMessage);
86
+ }
87
+ throw err;
88
+ }
89
+ };
90
+ };
91
+ }
92
+
93
+ export {
94
+ mantlePaywall,
95
+ web_standards_exports
96
+ };
@@ -0,0 +1,99 @@
1
+ import {
2
+ buildRouteKey,
3
+ checkPayment,
4
+ validateAddress
5
+ } from "./chunk-UVYA6H32.js";
6
+ import {
7
+ MANTLE_DEFAULTS,
8
+ __export,
9
+ getDefaultAssetForNetwork,
10
+ usdCentsToAtomic
11
+ } from "./chunk-HEZZ74SI.js";
12
+
13
+ // src/server/adapters/nextjs.ts
14
+ var nextjs_exports = {};
15
+ __export(nextjs_exports, {
16
+ isPaywallErrorResponse: () => isPaywallErrorResponse,
17
+ mantlePaywall: () => mantlePaywall
18
+ });
19
+ import { NextResponse } from "next/server";
20
+ function debugLog(config, prefix, message, data) {
21
+ if (config?.debug) {
22
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString();
23
+ console.log(`[${timestamp}] [x402-debug:${prefix}]`, message, data || "");
24
+ }
25
+ }
26
+ function mantlePaywall(opts) {
27
+ const { priceUsd, payTo, facilitatorUrl, apiKey, telemetry, onPaymentSettled } = opts;
28
+ validateAddress(payTo, "payTo");
29
+ const priceUsdCents = Math.round(priceUsd * 100);
30
+ return function(handler) {
31
+ return async (req) => {
32
+ const url = new URL(req.url);
33
+ const method = req.method;
34
+ const path = url.pathname;
35
+ const routeKey = buildRouteKey(method, path);
36
+ const network = MANTLE_DEFAULTS.NETWORK;
37
+ const assetConfig = getDefaultAssetForNetwork(network);
38
+ const maxAmountRequiredBigInt = usdCentsToAtomic(
39
+ priceUsdCents,
40
+ assetConfig.decimals
41
+ );
42
+ const paymentRequirements = {
43
+ scheme: "exact",
44
+ network,
45
+ asset: assetConfig.address,
46
+ maxAmountRequired: maxAmountRequiredBigInt.toString(),
47
+ payTo,
48
+ price: `$${(priceUsdCents / 100).toFixed(2)}`,
49
+ currency: "USD"
50
+ };
51
+ const paymentHeader = req.headers.get("X-PAYMENT") || req.headers.get("x-payment") || null;
52
+ const result = await checkPayment({
53
+ paymentHeader,
54
+ paymentRequirements,
55
+ facilitatorUrl: facilitatorUrl || MANTLE_DEFAULTS.FACILITATOR_URL,
56
+ apiKey,
57
+ routeKey,
58
+ network,
59
+ asset: assetConfig.address,
60
+ telemetry,
61
+ onPaymentSettled
62
+ });
63
+ if (!result.isValid) {
64
+ return NextResponse.json(result.responseBody, {
65
+ status: result.statusCode
66
+ });
67
+ }
68
+ try {
69
+ debugLog(telemetry, "handler", "\u25B6\uFE0F Handler execution started");
70
+ const response = await handler(req);
71
+ debugLog(telemetry, "handler", `\u2705 Handler completed: ${response.status}`);
72
+ if (result.sendTelemetryAfterResponse) {
73
+ debugLog(telemetry, "callback", `\u{1F4E4} Calling telemetry callback with status ${response.status}`);
74
+ result.sendTelemetryAfterResponse(response.status);
75
+ } else {
76
+ debugLog(telemetry, "callback", "\u26A0\uFE0F No telemetry callback to call");
77
+ }
78
+ return response;
79
+ } catch (err) {
80
+ const errorMessage = err instanceof Error ? err.message : "Unknown error";
81
+ debugLog(telemetry, "handler", `\u274C Handler error: ${errorMessage}`);
82
+ if (result.sendTelemetryAfterResponse) {
83
+ debugLog(telemetry, "callback", "\u{1F4E4} Calling telemetry callback with error");
84
+ result.sendTelemetryAfterResponse(500, errorMessage);
85
+ }
86
+ throw err;
87
+ }
88
+ };
89
+ };
90
+ }
91
+ function isPaywallErrorResponse(response) {
92
+ return typeof response === "object" && response !== null && "error" in response && typeof response.error === "string";
93
+ }
94
+
95
+ export {
96
+ mantlePaywall,
97
+ isPaywallErrorResponse,
98
+ nextjs_exports
99
+ };
@@ -0,0 +1,293 @@
1
+ import {
2
+ getDefaultAssetForNetwork
3
+ } from "./chunk-HEZZ74SI.js";
4
+
5
+ // src/server/core/utils.ts
6
+ function validateAddress(address, paramName = "address") {
7
+ if (!address) {
8
+ throw new Error(`${paramName} is required`);
9
+ }
10
+ if (typeof address !== "string") {
11
+ throw new Error(`${paramName} must be a string, got ${typeof address}`);
12
+ }
13
+ if (!address.startsWith("0x")) {
14
+ const preview = address.length > 10 ? `${address.substring(0, 10)}...` : address;
15
+ throw new Error(
16
+ `${paramName} must start with "0x", got: ${preview}`
17
+ );
18
+ }
19
+ if (address.length !== 42) {
20
+ throw new Error(
21
+ `${paramName} must be 42 characters (0x + 40 hex), got ${address.length} characters`
22
+ );
23
+ }
24
+ const hexPart = address.slice(2);
25
+ if (!/^[0-9a-fA-F]{40}$/.test(hexPart)) {
26
+ throw new Error(
27
+ `${paramName} must contain only hexadecimal characters (0-9, a-f, A-F) after "0x"`
28
+ );
29
+ }
30
+ }
31
+ function decodePaymentHeader(paymentHeaderBase64) {
32
+ try {
33
+ if (typeof Buffer !== "undefined") {
34
+ const json = Buffer.from(paymentHeaderBase64, "base64").toString("utf8");
35
+ return JSON.parse(json);
36
+ }
37
+ if (typeof atob === "function") {
38
+ const json = atob(paymentHeaderBase64);
39
+ return JSON.parse(json);
40
+ }
41
+ throw new Error("No base64 decoding available in this environment");
42
+ } catch (err) {
43
+ const msg = err instanceof Error ? err.message : "Unknown error";
44
+ throw new Error(`Failed to decode paymentHeader: ${msg}`);
45
+ }
46
+ }
47
+ function buildRouteKey(method, path) {
48
+ const normalizedMethod = (method || "GET").toUpperCase();
49
+ const normalizedPath = path || "/";
50
+ return `${normalizedMethod} ${normalizedPath}`;
51
+ }
52
+
53
+ // src/server/constants.ts
54
+ var DEFAULT_TELEMETRY_ENDPOINT = "https://x402mantlesdk.xyz/api/telemetry/settled";
55
+
56
+ // src/server/telemetry.ts
57
+ function createTelemetryEvent(entry, config) {
58
+ const assetConfig = getDefaultAssetForNetwork(entry.network);
59
+ return {
60
+ event: "payment_verified",
61
+ ts: entry.timestamp,
62
+ projectKey: config.projectKey,
63
+ network: entry.network,
64
+ buyer: entry.from,
65
+ payTo: entry.to,
66
+ amountAtomic: entry.valueAtomic,
67
+ asset: entry.asset,
68
+ decimals: assetConfig.decimals,
69
+ nonce: entry.id,
70
+ route: entry.route ?? "unknown",
71
+ // Facilitator metadata
72
+ facilitatorType: "hosted",
73
+ // SDK always uses hosted mode
74
+ facilitatorUrl: entry.facilitatorUrl,
75
+ // From PaymentLogEntry
76
+ // facilitatorAddress is undefined for SDK (not available)
77
+ // Optional metadata
78
+ txHash: entry.txHash,
79
+ priceUsd: entry.paymentRequirements?.price
80
+ };
81
+ }
82
+ async function sendTelemetry(event, endpoint, debug) {
83
+ const targetEndpoint = endpoint ?? DEFAULT_TELEMETRY_ENDPOINT;
84
+ if (debug) {
85
+ console.log(`[x402-debug:telemetry] \u{1F4E4} Sending telemetry event:`, {
86
+ event: event.event,
87
+ endpoint: targetEndpoint,
88
+ projectKey: event.projectKey.substring(0, 10) + "...",
89
+ route: event.route,
90
+ responseStatus: event.responseStatus,
91
+ serviceDelivered: event.serviceDelivered
92
+ });
93
+ }
94
+ if (!targetEndpoint) {
95
+ if (debug) console.log(`[x402-debug:telemetry] \u26A0\uFE0F No endpoint configured, skipping`);
96
+ return;
97
+ }
98
+ try {
99
+ const response = await fetch(targetEndpoint, {
100
+ method: "POST",
101
+ headers: {
102
+ "Content-Type": "application/json",
103
+ "Authorization": `Bearer ${event.projectKey}`
104
+ },
105
+ body: JSON.stringify(event)
106
+ });
107
+ if (debug) {
108
+ console.log(`[x402-debug:telemetry] ${response.ok ? "\u2705" : "\u274C"} Telemetry sent: HTTP ${response.status}`);
109
+ }
110
+ if (!response.ok) {
111
+ console.warn(
112
+ `[x402-telemetry] Failed to send event: HTTP ${response.status}`
113
+ );
114
+ }
115
+ } catch (err) {
116
+ if (debug) {
117
+ console.error(`[x402-debug:telemetry] \u274C Error sending:`, err);
118
+ }
119
+ console.error("[x402-telemetry] Error sending telemetry:", err);
120
+ }
121
+ }
122
+
123
+ // src/server/core/verifyPayment.ts
124
+ function debugLog(config, prefix, message, data) {
125
+ if (config?.debug) {
126
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString();
127
+ console.log(`[${timestamp}] [x402-debug:${prefix}]`, message, data || "");
128
+ }
129
+ }
130
+ async function checkPayment(input) {
131
+ const {
132
+ paymentHeader,
133
+ paymentRequirements,
134
+ facilitatorUrl,
135
+ apiKey,
136
+ routeKey,
137
+ network,
138
+ asset,
139
+ telemetry,
140
+ onPaymentSettled
141
+ } = input;
142
+ if (!paymentHeader || paymentHeader.trim() === "") {
143
+ return {
144
+ status: "require_payment",
145
+ statusCode: 402,
146
+ responseBody: {
147
+ error: "Payment Required",
148
+ paymentRequirements,
149
+ paymentHeader: null
150
+ },
151
+ isValid: false
152
+ };
153
+ }
154
+ try {
155
+ const verifyUrl = `${facilitatorUrl.replace(/\/+$/, "")}/verify`;
156
+ const verifyRes = await fetch(verifyUrl, {
157
+ method: "POST",
158
+ headers: {
159
+ "Content-Type": "application/json",
160
+ ...apiKey && { "Authorization": `Bearer ${apiKey}` }
161
+ },
162
+ body: JSON.stringify({
163
+ x402Version: 1,
164
+ paymentHeader,
165
+ paymentRequirements
166
+ })
167
+ });
168
+ if (!verifyRes.ok) {
169
+ const text = await verifyRes.text().catch(() => "");
170
+ console.error(
171
+ "[x402-mantle-sdk] Facilitator /verify returned non-OK:",
172
+ verifyRes.status,
173
+ text
174
+ );
175
+ return {
176
+ status: "verification_error",
177
+ statusCode: 500,
178
+ responseBody: {
179
+ error: "Payment verification error",
180
+ details: `Facilitator responded with HTTP ${verifyRes.status}`
181
+ },
182
+ isValid: false
183
+ };
184
+ }
185
+ const verifyJson = await verifyRes.json();
186
+ if (!verifyJson.isValid) {
187
+ return {
188
+ status: "invalid_payment",
189
+ statusCode: 402,
190
+ responseBody: {
191
+ error: "Payment verification failed",
192
+ invalidReason: verifyJson.invalidReason ?? null,
193
+ paymentRequirements,
194
+ paymentHeader: null
195
+ },
196
+ isValid: false
197
+ };
198
+ }
199
+ let baseLogEntry = null;
200
+ if (onPaymentSettled || telemetry) {
201
+ try {
202
+ const headerObj = decodePaymentHeader(paymentHeader);
203
+ const { authorization } = headerObj.payload;
204
+ const assetConfig = getDefaultAssetForNetwork(network);
205
+ baseLogEntry = {
206
+ id: authorization.nonce,
207
+ from: authorization.from,
208
+ to: authorization.to,
209
+ valueAtomic: authorization.value,
210
+ network,
211
+ asset,
212
+ route: routeKey,
213
+ timestamp: Date.now(),
214
+ facilitatorUrl,
215
+ paymentRequirements
216
+ };
217
+ debugLog(telemetry, "verify", "\u2705 Payment verified", {
218
+ nonce: authorization.nonce,
219
+ route: routeKey
220
+ });
221
+ if (onPaymentSettled) {
222
+ onPaymentSettled(baseLogEntry);
223
+ }
224
+ } catch (err) {
225
+ console.error(
226
+ "[x402-mantle-sdk] Error calling onPaymentSettled hook:",
227
+ err
228
+ );
229
+ }
230
+ }
231
+ const sendTelemetryAfterResponse = telemetry && baseLogEntry ? (responseStatus, error) => {
232
+ try {
233
+ debugLog(telemetry, "callback", "\u{1F4E4} Telemetry callback invoked", {
234
+ responseStatus,
235
+ hasError: !!error
236
+ });
237
+ const event = createTelemetryEvent(baseLogEntry, telemetry);
238
+ event.responseStatus = responseStatus;
239
+ event.errorMessage = error;
240
+ event.serviceDelivered = responseStatus >= 200 && responseStatus < 300;
241
+ sendTelemetry(event, telemetry.endpoint, telemetry.debug).catch(
242
+ (err) => console.error("[x402-telemetry] Async send failed:", err)
243
+ );
244
+ } catch (err) {
245
+ console.error("[x402-telemetry] Error creating telemetry event:", err);
246
+ }
247
+ } : void 0;
248
+ if (telemetry && baseLogEntry) {
249
+ debugLog(telemetry, "callback", "\u2705 Telemetry callback created", {
250
+ route: routeKey,
251
+ hasTelemetryConfig: !!telemetry,
252
+ hasLogEntry: !!baseLogEntry
253
+ });
254
+ } else if (telemetry) {
255
+ debugLog(telemetry, "callback", "\u26A0\uFE0F Telemetry callback NOT created", {
256
+ hasTelemetryConfig: !!telemetry,
257
+ hasLogEntry: !!baseLogEntry
258
+ });
259
+ }
260
+ return {
261
+ status: "verified",
262
+ statusCode: 200,
263
+ responseBody: null,
264
+ isValid: true,
265
+ sendTelemetryAfterResponse
266
+ };
267
+ } catch (err) {
268
+ console.error(
269
+ "[x402-mantle-sdk] Error while calling facilitator /verify:",
270
+ err
271
+ );
272
+ const message = err instanceof Error ? err.message : "Unknown verification error";
273
+ return {
274
+ status: "verification_error",
275
+ statusCode: 500,
276
+ responseBody: {
277
+ error: "Payment verification error",
278
+ details: message
279
+ },
280
+ isValid: false
281
+ };
282
+ }
283
+ }
284
+
285
+ export {
286
+ validateAddress,
287
+ decodePaymentHeader,
288
+ buildRouteKey,
289
+ DEFAULT_TELEMETRY_ENDPOINT,
290
+ createTelemetryEvent,
291
+ sendTelemetry,
292
+ checkPayment
293
+ };
@@ -0,0 +1,68 @@
1
+ import { Request, Response, NextFunction } from 'express';
2
+ import { b as RoutesConfig, M as MinimalPaywallOptions } from './types-BkGUHT4x.cjs';
3
+
4
+ /**
5
+ * Express middleware function type for Mantle paywall.
6
+ */
7
+ type MantleMiddleware = (req: Request, res: Response, next: NextFunction) => Promise<void>;
8
+ /** Config for createPaymentMiddleware. */
9
+ interface PaymentMiddlewareConfig {
10
+ /** Base URL of facilitator, e.g. https://facilitator.nosubs.ai */
11
+ facilitatorUrl: string;
12
+ /** Recipient address (developer). Validated at runtime. */
13
+ receiverAddress: string;
14
+ /** Map of protected routes and their pricing. */
15
+ routes: RoutesConfig;
16
+ /** Optional API key for hosted facilitator billing. */
17
+ apiKey?: string;
18
+ /**
19
+ * Optional hook called whenever a payment is successfully settled.
20
+ */
21
+ onPaymentSettled?: MinimalPaywallOptions["onPaymentSettled"];
22
+ /** Optional: Send usage telemetry for billing/analytics. */
23
+ telemetry?: MinimalPaywallOptions["telemetry"];
24
+ }
25
+ /**
26
+ * Create Express middleware for x402 payment verification on multiple routes.
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * const middleware = createPaymentMiddleware({
31
+ * facilitatorUrl: 'https://facilitator.nosubs.ai',
32
+ * receiverAddress: '0x...',
33
+ * routes: {
34
+ * 'POST /api/generate': { priceUsdCents: 1, network: 'mantle-mainnet' },
35
+ * 'GET /api/data': { priceUsdCents: 5, network: 'mantle-mainnet' },
36
+ * }
37
+ * });
38
+ *
39
+ * app.use(middleware);
40
+ * ```
41
+ */
42
+ declare function createPaymentMiddleware(config: PaymentMiddlewareConfig): MantleMiddleware;
43
+ /**
44
+ * Simplified wrapper for protecting a single route with x402 payments.
45
+ * Uses Mantle mainnet defaults (USDC, exact scheme, etc.).
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * const pay = mantlePaywall({ priceUsd: 0.01, payTo: "0x..." });
50
+ * app.post('/api/generate', pay, async (req, res) => {
51
+ * // Your handler code here
52
+ * });
53
+ * ```
54
+ *
55
+ * @param opts - Minimal configuration (price, payTo, optional facilitator/telemetry).
56
+ * @returns Express middleware function for single-route protection.
57
+ */
58
+ declare function mantlePaywall(opts: MinimalPaywallOptions): MantleMiddleware;
59
+
60
+ type express_MantleMiddleware = MantleMiddleware;
61
+ type express_PaymentMiddlewareConfig = PaymentMiddlewareConfig;
62
+ declare const express_createPaymentMiddleware: typeof createPaymentMiddleware;
63
+ declare const express_mantlePaywall: typeof mantlePaywall;
64
+ declare namespace express {
65
+ export { type express_MantleMiddleware as MantleMiddleware, type express_PaymentMiddlewareConfig as PaymentMiddlewareConfig, express_createPaymentMiddleware as createPaymentMiddleware, express_mantlePaywall as mantlePaywall };
66
+ }
67
+
68
+ export { type MantleMiddleware as M, type PaymentMiddlewareConfig as P, createPaymentMiddleware as c, express as e, mantlePaywall as m };