@puga-labs/x402-mantle-sdk 0.3.1 → 0.3.3

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.
Files changed (71) hide show
  1. package/dist/{chunk-HTZ3QFY4.js → chunk-23QNUJIB.js} +4 -3
  2. package/dist/chunk-CXRILT3C.js +68 -0
  3. package/dist/{chunk-CTI5CRDY.js → chunk-E46A7I6B.js} +1 -1
  4. package/dist/{chunk-XAQGMFSR.js → chunk-HEZZ74SI.js} +6 -0
  5. package/dist/chunk-NQWSCY44.js +70 -0
  6. package/dist/chunk-PCJEJYP6.js +68 -0
  7. package/dist/chunk-PPVS3X5Z.js +99 -0
  8. package/dist/chunk-QWQUSRLY.js +99 -0
  9. package/dist/chunk-U73CZU3X.js +237 -0
  10. package/dist/chunk-WO2MYZXT.js +0 -0
  11. package/dist/chunk-ZLCKBFVJ.js +237 -0
  12. package/dist/chunk-ZROK2XOB.js +70 -0
  13. package/dist/client.d.cts +4 -4
  14. package/dist/client.d.ts +4 -4
  15. package/dist/client.js +2 -2
  16. package/dist/{constants-CVFF0ray.d.ts → constants-0ncqvV_O.d.ts} +1 -1
  17. package/dist/{constants-DzCGK0Q3.d.cts → constants-CsIL25uQ.d.cts} +1 -1
  18. package/dist/{createMantleClient-NN0Nitp9.d.cts → createMantleClient-CO0uWPb-.d.cts} +1 -1
  19. package/dist/{createMantleClient-DVFkbBfS.d.ts → createMantleClient-CuiPsTa6.d.ts} +1 -1
  20. package/dist/express-D8EwEcOL.d.ts +66 -0
  21. package/dist/express-eQOPxfnI.d.cts +66 -0
  22. package/dist/index.cjs +186 -109
  23. package/dist/index.d.cts +6 -4
  24. package/dist/index.d.ts +6 -4
  25. package/dist/index.js +6 -4
  26. package/dist/nextjs-Duecps0q.d.cts +45 -0
  27. package/dist/nextjs-TFhFiQuL.d.ts +45 -0
  28. package/dist/react.cjs +3 -2
  29. package/dist/react.d.cts +7 -4
  30. package/dist/react.d.ts +7 -4
  31. package/dist/react.js +3 -3
  32. package/dist/server-express.cjs +368 -0
  33. package/dist/server-express.d.cts +5 -0
  34. package/dist/server-express.d.ts +5 -0
  35. package/dist/server-express.js +13 -0
  36. package/dist/server-nextjs.cjs +339 -0
  37. package/dist/server-nextjs.d.cts +5 -0
  38. package/dist/server-nextjs.d.ts +5 -0
  39. package/dist/server-nextjs.js +11 -0
  40. package/dist/server-web.cjs +339 -0
  41. package/dist/server-web.d.cts +4 -0
  42. package/dist/server-web.d.ts +4 -0
  43. package/dist/server-web.js +11 -0
  44. package/dist/server.cjs +316 -111
  45. package/dist/server.d.cts +67 -104
  46. package/dist/server.d.ts +67 -104
  47. package/dist/server.js +29 -5
  48. package/dist/{types-2zqbJvcz.d.cts → types-BFUqKBBO.d.cts} +1 -1
  49. package/dist/{types-2zqbJvcz.d.ts → types-BFUqKBBO.d.ts} +1 -1
  50. package/dist/types-CoOdbZSp.d.cts +97 -0
  51. package/dist/types-CqQ6OgRi.d.ts +85 -0
  52. package/dist/types-CrOsOHcX.d.cts +85 -0
  53. package/dist/types-DTzov_EE.d.ts +97 -0
  54. package/dist/web-standards-BNQyWzBC.d.cts +77 -0
  55. package/dist/web-standards-D8j1kZxd.d.ts +77 -0
  56. package/package.json +49 -2
  57. package/dist/chunk-DA6ZBXNO.js +0 -275
  58. package/dist/chunk-FD4HG7KR.js +0 -135
  59. package/dist/chunk-GWVWPS3R.js +0 -277
  60. package/dist/chunk-MQALBRGV.js +0 -135
  61. package/dist/chunk-PYIYE3HI.js +0 -135
  62. package/dist/chunk-Q6SPMEIW.js +0 -235
  63. package/dist/chunk-RNKXSBT7.js +0 -135
  64. package/dist/chunk-SPCXFN7C.js +0 -284
  65. package/dist/chunk-T5DRYLNB.js +0 -135
  66. package/dist/chunk-TSEE5NSJ.js +0 -297
  67. package/dist/chunk-WELDWRDX.js +0 -307
  68. package/dist/constants-C7aY8u5b.d.cts +0 -77
  69. package/dist/constants-C7aY8u5b.d.ts +0 -77
  70. package/dist/createMantleClient-DS1Ghqrz.d.cts +0 -51
  71. package/dist/createMantleClient-DS1Ghqrz.d.ts +0 -51
package/dist/index.cjs CHANGED
@@ -82,6 +82,54 @@ function usdCentsToAtomic(cents, decimals) {
82
82
  return BigInt(cents) * base;
83
83
  }
84
84
 
85
+ // src/server/core/utils.ts
86
+ function validateAddress(address, paramName = "address") {
87
+ if (!address) {
88
+ throw new Error(`${paramName} is required`);
89
+ }
90
+ if (typeof address !== "string") {
91
+ throw new Error(`${paramName} must be a string, got ${typeof address}`);
92
+ }
93
+ if (!address.startsWith("0x")) {
94
+ const preview = address.length > 10 ? `${address.substring(0, 10)}...` : address;
95
+ throw new Error(
96
+ `${paramName} must start with "0x", got: ${preview}`
97
+ );
98
+ }
99
+ if (address.length !== 42) {
100
+ throw new Error(
101
+ `${paramName} must be 42 characters (0x + 40 hex), got ${address.length} characters`
102
+ );
103
+ }
104
+ const hexPart = address.slice(2);
105
+ if (!/^[0-9a-fA-F]{40}$/.test(hexPart)) {
106
+ throw new Error(
107
+ `${paramName} must contain only hexadecimal characters (0-9, a-f, A-F) after "0x"`
108
+ );
109
+ }
110
+ }
111
+ function decodePaymentHeader(paymentHeaderBase64) {
112
+ try {
113
+ if (typeof Buffer !== "undefined") {
114
+ const json = Buffer.from(paymentHeaderBase64, "base64").toString("utf8");
115
+ return JSON.parse(json);
116
+ }
117
+ if (typeof atob === "function") {
118
+ const json = atob(paymentHeaderBase64);
119
+ return JSON.parse(json);
120
+ }
121
+ throw new Error("No base64 decoding available in this environment");
122
+ } catch (err) {
123
+ const msg = err instanceof Error ? err.message : "Unknown error";
124
+ throw new Error(`Failed to decode paymentHeader: ${msg}`);
125
+ }
126
+ }
127
+ function buildRouteKey(method, path) {
128
+ const normalizedMethod = (method || "GET").toUpperCase();
129
+ const normalizedPath = path || "/";
130
+ return `${normalizedMethod} ${normalizedPath}`;
131
+ }
132
+
85
133
  // src/server/constants.ts
86
134
  var DEFAULT_TELEMETRY_ENDPOINT = void 0;
87
135
 
@@ -135,28 +183,130 @@ async function sendTelemetry(event, endpoint) {
135
183
  }
136
184
  }
137
185
 
138
- // src/server/paymentMiddleware.ts
139
- function getRouteKey(req) {
140
- const method = (req.method || "GET").toUpperCase();
141
- const path = req.path || "/";
142
- return `${method} ${path}`;
143
- }
144
- function decodePaymentHeader(paymentHeaderBase64) {
186
+ // src/server/core/verifyPayment.ts
187
+ async function checkPayment(input) {
188
+ const {
189
+ paymentHeader,
190
+ paymentRequirements,
191
+ facilitatorUrl,
192
+ routeKey,
193
+ network,
194
+ asset,
195
+ telemetry,
196
+ onPaymentSettled
197
+ } = input;
198
+ if (!paymentHeader || paymentHeader.trim() === "") {
199
+ return {
200
+ status: "require_payment",
201
+ statusCode: 402,
202
+ responseBody: {
203
+ error: "Payment Required",
204
+ paymentRequirements,
205
+ paymentHeader: null
206
+ },
207
+ isValid: false
208
+ };
209
+ }
145
210
  try {
146
- if (typeof Buffer !== "undefined") {
147
- const json = Buffer.from(paymentHeaderBase64, "base64").toString("utf8");
148
- return JSON.parse(json);
211
+ const verifyUrl = `${facilitatorUrl.replace(/\/+$/, "")}/verify`;
212
+ const verifyRes = await fetch(verifyUrl, {
213
+ method: "POST",
214
+ headers: {
215
+ "Content-Type": "application/json"
216
+ },
217
+ body: JSON.stringify({
218
+ x402Version: 1,
219
+ paymentHeader,
220
+ paymentRequirements
221
+ })
222
+ });
223
+ if (!verifyRes.ok) {
224
+ const text = await verifyRes.text().catch(() => "");
225
+ console.error(
226
+ "[x402-mantle-sdk] Facilitator /verify returned non-OK:",
227
+ verifyRes.status,
228
+ text
229
+ );
230
+ return {
231
+ status: "verification_error",
232
+ statusCode: 500,
233
+ responseBody: {
234
+ error: "Payment verification error",
235
+ details: `Facilitator responded with HTTP ${verifyRes.status}`
236
+ },
237
+ isValid: false
238
+ };
149
239
  }
150
- if (typeof atob === "function") {
151
- const json = atob(paymentHeaderBase64);
152
- return JSON.parse(json);
240
+ const verifyJson = await verifyRes.json();
241
+ if (!verifyJson.isValid) {
242
+ return {
243
+ status: "invalid_payment",
244
+ statusCode: 402,
245
+ responseBody: {
246
+ error: "Payment verification failed",
247
+ invalidReason: verifyJson.invalidReason ?? null,
248
+ paymentRequirements,
249
+ paymentHeader: null
250
+ },
251
+ isValid: false
252
+ };
153
253
  }
154
- throw new Error("No base64 decoding available in this environment");
254
+ if (onPaymentSettled) {
255
+ try {
256
+ const headerObj = decodePaymentHeader(paymentHeader);
257
+ const { authorization } = headerObj.payload;
258
+ const assetConfig = getDefaultAssetForNetwork(network);
259
+ const logEntry = {
260
+ id: authorization.nonce,
261
+ from: authorization.from,
262
+ to: authorization.to,
263
+ valueAtomic: authorization.value,
264
+ network,
265
+ asset,
266
+ route: routeKey,
267
+ timestamp: Date.now(),
268
+ facilitatorUrl,
269
+ paymentRequirements
270
+ };
271
+ onPaymentSettled(logEntry);
272
+ if (telemetry) {
273
+ const event = createTelemetryEvent(logEntry, telemetry);
274
+ sendTelemetry(event, telemetry.endpoint).catch(
275
+ (err) => console.error("[x402-telemetry] Async send failed:", err)
276
+ );
277
+ }
278
+ } catch (err) {
279
+ console.error(
280
+ "[x402-mantle-sdk] Error calling onPaymentSettled hook:",
281
+ err
282
+ );
283
+ }
284
+ }
285
+ return {
286
+ status: "verified",
287
+ statusCode: 200,
288
+ responseBody: null,
289
+ isValid: true
290
+ };
155
291
  } catch (err) {
156
- const msg = err instanceof Error ? err.message : "Unknown error";
157
- throw new Error(`Failed to decode paymentHeader: ${msg}`);
292
+ console.error(
293
+ "[x402-mantle-sdk] Error while calling facilitator /verify:",
294
+ err
295
+ );
296
+ const message = err instanceof Error ? err.message : "Unknown verification error";
297
+ return {
298
+ status: "verification_error",
299
+ statusCode: 500,
300
+ responseBody: {
301
+ error: "Payment verification error",
302
+ details: message
303
+ },
304
+ isValid: false
305
+ };
158
306
  }
159
307
  }
308
+
309
+ // src/server/adapters/express.ts
160
310
  function createPaymentMiddleware(config) {
161
311
  const { facilitatorUrl, receiverAddress, routes, onPaymentSettled, telemetry } = config;
162
312
  if (!facilitatorUrl) {
@@ -165,11 +315,12 @@ function createPaymentMiddleware(config) {
165
315
  if (!receiverAddress) {
166
316
  throw new Error("receiverAddress is required");
167
317
  }
318
+ validateAddress(receiverAddress, "receiverAddress");
168
319
  if (!routes || Object.keys(routes).length === 0) {
169
320
  throw new Error("routes config must not be empty");
170
321
  }
171
322
  return async function paymentMiddleware(req, res, next) {
172
- const routeKey = getRouteKey(req);
323
+ const routeKey = buildRouteKey(req.method, req.path);
173
324
  const routeConfig = routes[routeKey];
174
325
  if (!routeConfig) {
175
326
  next();
@@ -190,102 +341,27 @@ function createPaymentMiddleware(config) {
190
341
  price: `$${(priceUsdCents / 100).toFixed(2)}`,
191
342
  currency: "USD"
192
343
  };
193
- const paymentHeader = req.header("X-PAYMENT") ?? req.header("x-payment");
194
- if (!paymentHeader) {
195
- res.status(402).json({
196
- error: "Payment Required",
197
- paymentRequirements,
198
- paymentHeader: null
199
- });
200
- return;
201
- }
202
- try {
203
- const verifyUrl = `${facilitatorUrl.replace(/\/+$/, "")}/verify`;
204
- const verifyRes = await fetch(verifyUrl, {
205
- method: "POST",
206
- headers: {
207
- "Content-Type": "application/json"
208
- },
209
- body: JSON.stringify({
210
- x402Version: 1,
211
- paymentHeader,
212
- paymentRequirements
213
- })
214
- });
215
- if (!verifyRes.ok) {
216
- const text = await verifyRes.text().catch(() => "");
217
- console.error(
218
- "[x402-mantle-sdk] Facilitator /verify returned non-OK:",
219
- verifyRes.status,
220
- text
221
- );
222
- res.status(500).json({
223
- error: "Payment verification error",
224
- details: `Facilitator responded with HTTP ${verifyRes.status}`
225
- });
226
- return;
227
- }
228
- const verifyJson = await verifyRes.json();
229
- if (!verifyJson.isValid) {
230
- res.status(402).json({
231
- error: "Payment verification failed",
232
- invalidReason: verifyJson.invalidReason ?? null,
233
- paymentRequirements,
234
- paymentHeader: null
235
- });
236
- return;
237
- }
238
- if (onPaymentSettled) {
239
- try {
240
- const headerObj = decodePaymentHeader(paymentHeader);
241
- const { authorization } = headerObj.payload;
242
- const logEntry = {
243
- id: authorization.nonce,
244
- from: authorization.from,
245
- to: authorization.to,
246
- valueAtomic: authorization.value,
247
- network,
248
- asset: assetConfig.address,
249
- route: routeKey,
250
- timestamp: Date.now(),
251
- facilitatorUrl,
252
- // Pass from config closure
253
- paymentRequirements
254
- };
255
- onPaymentSettled(logEntry);
256
- if (telemetry) {
257
- const event = createTelemetryEvent(logEntry, telemetry);
258
- sendTelemetry(event, telemetry.endpoint).catch(
259
- (err) => console.error("[x402-telemetry] Async send failed:", err)
260
- );
261
- }
262
- } catch (err) {
263
- console.error(
264
- "[x402-mantle-sdk] Error calling onPaymentSettled hook:",
265
- err
266
- );
267
- }
268
- }
269
- next();
270
- return;
271
- } catch (err) {
272
- console.error(
273
- "[x402-mantle-sdk] Error while calling facilitator /verify:",
274
- err
275
- );
276
- const message = err instanceof Error ? err.message : "Unknown verification error";
277
- res.status(500).json({
278
- error: "Payment verification error",
279
- details: message
280
- });
344
+ const paymentHeader = req.header("X-PAYMENT") || req.header("x-payment") || null;
345
+ const result = await checkPayment({
346
+ paymentHeader,
347
+ paymentRequirements,
348
+ facilitatorUrl,
349
+ routeKey,
350
+ network,
351
+ asset: assetConfig.address,
352
+ telemetry,
353
+ onPaymentSettled
354
+ });
355
+ if (!result.isValid) {
356
+ res.status(result.statusCode).json(result.responseBody);
281
357
  return;
282
358
  }
359
+ next();
283
360
  };
284
361
  }
285
-
286
- // src/server/mantlePaywall.ts
287
362
  function mantlePaywall(opts) {
288
363
  const { priceUsd, payTo, facilitatorUrl, telemetry, onPaymentSettled } = opts;
364
+ validateAddress(payTo, "payTo");
289
365
  const priceUsdCents = Math.round(priceUsd * 100);
290
366
  return async (req, res, next) => {
291
367
  const method = (req.method || "GET").toUpperCase();
@@ -658,13 +734,14 @@ function useEthersWallet(options) {
658
734
  }
659
735
  };
660
736
  }, []);
737
+ const shouldAutoConnect = options?.autoConnect !== false;
661
738
  (0, import_react.useEffect)(() => {
662
- if (options?.autoConnect) {
739
+ if (shouldAutoConnect) {
663
740
  connect().catch((err) => {
664
741
  console.warn("[useEthersWallet] Auto-connect failed:", err);
665
742
  });
666
743
  }
667
- }, [options?.autoConnect, connect]);
744
+ }, [shouldAutoConnect, connect]);
668
745
  return {
669
746
  address,
670
747
  isConnected,
package/dist/index.d.cts CHANGED
@@ -1,8 +1,10 @@
1
- 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-2zqbJvcz.cjs';
2
- export { M as MANTLE_DEFAULTS } from './constants-DzCGK0Q3.cjs';
3
- export { MantleMiddleware, MinimalPaywallOptions, PaymentLogEntry, PaymentMiddlewareConfig, RouteKey, RoutePricingConfig, RoutesConfig, TelemetryConfig, TelemetryEvent, createPaymentMiddleware, mantlePaywall } from './server.cjs';
4
- export { C as CallWithPaymentResult, M as MantleClient, a as MantleClientConfig, b as PaymentClient, P as PaymentClientConfig, c as createMantleClient } from './createMantleClient-NN0Nitp9.cjs';
1
+ 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';
2
+ export { M as MANTLE_DEFAULTS } from './constants-CsIL25uQ.cjs';
3
+ export { M as MantleMiddleware, e as MinimalPaywallOptions, P as PaymentLogEntry, d as PaymentMiddlewareConfig, R as RouteKey, a as RoutePricingConfig, b as RoutesConfig, T as TelemetryConfig, c as TelemetryEvent } from './types-CoOdbZSp.cjs';
4
+ export { c as createPaymentMiddleware, m as mantlePaywall } from './express-eQOPxfnI.cjs';
5
+ export { C as CallWithPaymentResult, M as MantleClient, a as MantleClientConfig, b as PaymentClient, P as PaymentClientConfig, c as createMantleClient } from './createMantleClient-CO0uWPb-.cjs';
5
6
  export { createPaymentClient } from './client.cjs';
6
7
  export { UseEthersWalletOptions, UseEthersWalletReturn, UseMantleX402Options, useEthersWallet, useMantleX402 } from './react.cjs';
7
8
  import 'express';
9
+ import './types-CrOsOHcX.cjs';
8
10
  import 'ethers';
package/dist/index.d.ts CHANGED
@@ -1,8 +1,10 @@
1
- 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-2zqbJvcz.js';
2
- export { M as MANTLE_DEFAULTS } from './constants-CVFF0ray.js';
3
- export { MantleMiddleware, MinimalPaywallOptions, PaymentLogEntry, PaymentMiddlewareConfig, RouteKey, RoutePricingConfig, RoutesConfig, TelemetryConfig, TelemetryEvent, createPaymentMiddleware, mantlePaywall } from './server.js';
4
- export { C as CallWithPaymentResult, M as MantleClient, a as MantleClientConfig, b as PaymentClient, P as PaymentClientConfig, c as createMantleClient } from './createMantleClient-DVFkbBfS.js';
1
+ 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';
2
+ export { M as MANTLE_DEFAULTS } from './constants-0ncqvV_O.js';
3
+ export { M as MantleMiddleware, e as MinimalPaywallOptions, P as PaymentLogEntry, d as PaymentMiddlewareConfig, R as RouteKey, a as RoutePricingConfig, b as RoutesConfig, T as TelemetryConfig, c as TelemetryEvent } from './types-DTzov_EE.js';
4
+ export { c as createPaymentMiddleware, m as mantlePaywall } from './express-D8EwEcOL.js';
5
+ export { C as CallWithPaymentResult, M as MantleClient, a as MantleClientConfig, b as PaymentClient, P as PaymentClientConfig, c as createMantleClient } from './createMantleClient-CuiPsTa6.js';
5
6
  export { createPaymentClient } from './client.js';
6
7
  export { UseEthersWalletOptions, UseEthersWalletReturn, UseMantleX402Options, useEthersWallet, useMantleX402 } from './react.js';
7
8
  import 'express';
9
+ import './types-CqQ6OgRi.js';
8
10
  import 'ethers';
package/dist/index.js CHANGED
@@ -1,18 +1,20 @@
1
1
  import {
2
2
  useEthersWallet,
3
3
  useMantleX402
4
- } from "./chunk-T5DRYLNB.js";
4
+ } from "./chunk-23QNUJIB.js";
5
5
  import {
6
6
  createMantleClient,
7
7
  createPaymentClient
8
- } from "./chunk-CTI5CRDY.js";
8
+ } from "./chunk-E46A7I6B.js";
9
+ import "./chunk-WO2MYZXT.js";
9
10
  import {
10
11
  createPaymentMiddleware,
11
12
  mantlePaywall
12
- } from "./chunk-Q6SPMEIW.js";
13
+ } from "./chunk-QWQUSRLY.js";
14
+ import "./chunk-ZLCKBFVJ.js";
13
15
  import {
14
16
  MANTLE_DEFAULTS
15
- } from "./chunk-XAQGMFSR.js";
17
+ } from "./chunk-HEZZ74SI.js";
16
18
  export {
17
19
  MANTLE_DEFAULTS,
18
20
  createMantleClient,
@@ -0,0 +1,45 @@
1
+ import { NextRequest, NextResponse } from 'next/server';
2
+ import { M as MinimalPaywallOptions } from './types-CrOsOHcX.cjs';
3
+
4
+ /**
5
+ * Next.js App Router route handler type.
6
+ */
7
+ type NextJSHandler<T = any> = (req: NextRequest) => Promise<NextResponse<T>>;
8
+ /**
9
+ * Wrapper function that adds x402 payment verification to Next.js route handler.
10
+ */
11
+ type NextJSPaywallWrapper = <T>(handler: NextJSHandler<T>) => NextJSHandler<T>;
12
+ /**
13
+ * Create Next.js App Router middleware for x402 payment verification.
14
+ * Uses Mantle mainnet defaults (USDC, exact scheme, etc.).
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * // app/api/generate-image/route.ts
19
+ * import { mantlePaywall } from '@puga-labs/x402-mantle-sdk/server/nextjs'
20
+ *
21
+ * const pay = mantlePaywall({
22
+ * priceUsd: 0.01,
23
+ * payTo: process.env.PAY_TO!,
24
+ * });
25
+ *
26
+ * export const POST = pay(async (req: NextRequest) => {
27
+ * const { prompt } = await req.json();
28
+ * // Your handler code here
29
+ * return NextResponse.json({ success: true });
30
+ * });
31
+ * ```
32
+ *
33
+ * @param opts - Minimal configuration (price, payTo, optional facilitator/telemetry).
34
+ * @returns Function that wraps Next.js route handlers with payment verification.
35
+ */
36
+ declare function mantlePaywall(opts: MinimalPaywallOptions): NextJSPaywallWrapper;
37
+
38
+ type nextjs_NextJSHandler<T = any> = NextJSHandler<T>;
39
+ type nextjs_NextJSPaywallWrapper = NextJSPaywallWrapper;
40
+ declare const nextjs_mantlePaywall: typeof mantlePaywall;
41
+ declare namespace nextjs {
42
+ export { type nextjs_NextJSHandler as NextJSHandler, type nextjs_NextJSPaywallWrapper as NextJSPaywallWrapper, nextjs_mantlePaywall as mantlePaywall };
43
+ }
44
+
45
+ export { type NextJSHandler as N, type NextJSPaywallWrapper as a, mantlePaywall as m, nextjs as n };
@@ -0,0 +1,45 @@
1
+ import { NextRequest, NextResponse } from 'next/server';
2
+ import { M as MinimalPaywallOptions } from './types-CqQ6OgRi.js';
3
+
4
+ /**
5
+ * Next.js App Router route handler type.
6
+ */
7
+ type NextJSHandler<T = any> = (req: NextRequest) => Promise<NextResponse<T>>;
8
+ /**
9
+ * Wrapper function that adds x402 payment verification to Next.js route handler.
10
+ */
11
+ type NextJSPaywallWrapper = <T>(handler: NextJSHandler<T>) => NextJSHandler<T>;
12
+ /**
13
+ * Create Next.js App Router middleware for x402 payment verification.
14
+ * Uses Mantle mainnet defaults (USDC, exact scheme, etc.).
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * // app/api/generate-image/route.ts
19
+ * import { mantlePaywall } from '@puga-labs/x402-mantle-sdk/server/nextjs'
20
+ *
21
+ * const pay = mantlePaywall({
22
+ * priceUsd: 0.01,
23
+ * payTo: process.env.PAY_TO!,
24
+ * });
25
+ *
26
+ * export const POST = pay(async (req: NextRequest) => {
27
+ * const { prompt } = await req.json();
28
+ * // Your handler code here
29
+ * return NextResponse.json({ success: true });
30
+ * });
31
+ * ```
32
+ *
33
+ * @param opts - Minimal configuration (price, payTo, optional facilitator/telemetry).
34
+ * @returns Function that wraps Next.js route handlers with payment verification.
35
+ */
36
+ declare function mantlePaywall(opts: MinimalPaywallOptions): NextJSPaywallWrapper;
37
+
38
+ type nextjs_NextJSHandler<T = any> = NextJSHandler<T>;
39
+ type nextjs_NextJSPaywallWrapper = NextJSPaywallWrapper;
40
+ declare const nextjs_mantlePaywall: typeof mantlePaywall;
41
+ declare namespace nextjs {
42
+ export { type nextjs_NextJSHandler as NextJSHandler, type nextjs_NextJSPaywallWrapper as NextJSPaywallWrapper, nextjs_mantlePaywall as mantlePaywall };
43
+ }
44
+
45
+ export { type NextJSHandler as N, type NextJSPaywallWrapper as a, mantlePaywall as m, nextjs as n };
package/dist/react.cjs CHANGED
@@ -121,13 +121,14 @@ function useEthersWallet(options) {
121
121
  }
122
122
  };
123
123
  }, []);
124
+ const shouldAutoConnect = options?.autoConnect !== false;
124
125
  (0, import_react.useEffect)(() => {
125
- if (options?.autoConnect) {
126
+ if (shouldAutoConnect) {
126
127
  connect().catch((err) => {
127
128
  console.warn("[useEthersWallet] Auto-connect failed:", err);
128
129
  });
129
130
  }
130
- }, [options?.autoConnect, connect]);
131
+ }, [shouldAutoConnect, connect]);
131
132
  return {
132
133
  address,
133
134
  isConnected,
package/dist/react.d.cts CHANGED
@@ -1,7 +1,7 @@
1
- import { M as MantleClient } from './createMantleClient-NN0Nitp9.cjs';
2
- export { a as MantleClientConfig } from './createMantleClient-NN0Nitp9.cjs';
1
+ import { M as MantleClient } from './createMantleClient-CO0uWPb-.cjs';
2
+ export { a as MantleClientConfig } from './createMantleClient-CO0uWPb-.cjs';
3
3
  import { ethers } from 'ethers';
4
- import './types-2zqbJvcz.cjs';
4
+ import './types-BFUqKBBO.cjs';
5
5
 
6
6
  /**
7
7
  * Options for useMantleX402 React hook.
@@ -42,7 +42,10 @@ declare function useMantleX402(opts?: UseMantleX402Options): MantleClient;
42
42
  * Options for useEthersWallet hook.
43
43
  */
44
44
  interface UseEthersWalletOptions {
45
- /** Auto-connect to wallet on mount (default: false). */
45
+ /**
46
+ * Auto-connect to existing MetaMask connection on mount.
47
+ * @default true
48
+ */
46
49
  autoConnect?: boolean;
47
50
  }
48
51
  /**
package/dist/react.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { M as MantleClient } from './createMantleClient-DVFkbBfS.js';
2
- export { a as MantleClientConfig } from './createMantleClient-DVFkbBfS.js';
1
+ import { M as MantleClient } from './createMantleClient-CuiPsTa6.js';
2
+ export { a as MantleClientConfig } from './createMantleClient-CuiPsTa6.js';
3
3
  import { ethers } from 'ethers';
4
- import './types-2zqbJvcz.js';
4
+ import './types-BFUqKBBO.js';
5
5
 
6
6
  /**
7
7
  * Options for useMantleX402 React hook.
@@ -42,7 +42,10 @@ declare function useMantleX402(opts?: UseMantleX402Options): MantleClient;
42
42
  * Options for useEthersWallet hook.
43
43
  */
44
44
  interface UseEthersWalletOptions {
45
- /** Auto-connect to wallet on mount (default: false). */
45
+ /**
46
+ * Auto-connect to existing MetaMask connection on mount.
47
+ * @default true
48
+ */
46
49
  autoConnect?: boolean;
47
50
  }
48
51
  /**
package/dist/react.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  useEthersWallet,
3
3
  useMantleX402
4
- } from "./chunk-T5DRYLNB.js";
5
- import "./chunk-CTI5CRDY.js";
6
- import "./chunk-XAQGMFSR.js";
4
+ } from "./chunk-23QNUJIB.js";
5
+ import "./chunk-E46A7I6B.js";
6
+ import "./chunk-HEZZ74SI.js";
7
7
  export {
8
8
  useEthersWallet,
9
9
  useMantleX402