@puga-labs/x402-mantle-sdk 0.3.6 → 0.3.8

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 (45) hide show
  1. package/dist/chunk-26OQ36EN.js +179 -0
  2. package/dist/chunk-33WHNZDS.js +74 -0
  3. package/dist/chunk-5TTSYEOF.js +73 -0
  4. package/dist/chunk-7SOCLVGM.js +301 -0
  5. package/dist/chunk-B4GST723.js +101 -0
  6. package/dist/chunk-EKEVUVF3.js +237 -0
  7. package/dist/chunk-F2OTZ3BB.js +70 -0
  8. package/dist/chunk-MBJTUNDL.js +99 -0
  9. package/dist/chunk-OW2BDRGZ.js +239 -0
  10. package/dist/chunk-T63MVWX3.js +71 -0
  11. package/dist/client.cjs +20 -5
  12. package/dist/client.js +1 -1
  13. package/dist/express-D8L5Dg1D.d.ts +68 -0
  14. package/dist/express-Pukmnwuu.d.cts +68 -0
  15. package/dist/index.cjs +28 -9
  16. package/dist/index.d.cts +3 -3
  17. package/dist/index.d.ts +3 -3
  18. package/dist/index.js +4 -4
  19. package/dist/nextjs-CSUWjcxv.d.cts +89 -0
  20. package/dist/nextjs-DUdgN0d_.d.ts +89 -0
  21. package/dist/react.cjs +20 -5
  22. package/dist/react.js +2 -2
  23. package/dist/server-express.cjs +8 -4
  24. package/dist/server-express.d.cts +2 -2
  25. package/dist/server-express.d.ts +2 -2
  26. package/dist/server-express.js +2 -2
  27. package/dist/server-nextjs.cjs +6 -3
  28. package/dist/server-nextjs.d.cts +2 -2
  29. package/dist/server-nextjs.d.ts +2 -2
  30. package/dist/server-nextjs.js +2 -2
  31. package/dist/server-web.cjs +6 -3
  32. package/dist/server-web.d.cts +2 -2
  33. package/dist/server-web.d.ts +2 -2
  34. package/dist/server-web.js +2 -2
  35. package/dist/server.cjs +12 -6
  36. package/dist/server.d.cts +6 -6
  37. package/dist/server.d.ts +6 -6
  38. package/dist/server.js +4 -4
  39. package/dist/types-BWfKovFm.d.cts +103 -0
  40. package/dist/types-BmK0G74m.d.cts +93 -0
  41. package/dist/types-CXdNC0Ra.d.ts +93 -0
  42. package/dist/types-DgfVPQFb.d.ts +103 -0
  43. package/dist/web-standards-BvMLEKlU.d.cts +77 -0
  44. package/dist/web-standards-g2rYUpgc.d.ts +77 -0
  45. package/package.json +1 -1
@@ -0,0 +1,89 @@
1
+ import { NextRequest } from 'next/server';
2
+ import { M as MinimalPaywallOptions } from './types-BmK0G74m.cjs';
3
+ import { P as PaymentRequirements } from './types-BFUqKBBO.cjs';
4
+
5
+ /**
6
+ * Error response returned when payment verification fails.
7
+ * This can be due to missing payment, invalid payment, or verification errors.
8
+ */
9
+ interface PaywallErrorResponse {
10
+ error: string;
11
+ paymentRequirements?: PaymentRequirements;
12
+ paymentHeader?: null;
13
+ invalidReason?: string | null;
14
+ details?: string;
15
+ }
16
+ /**
17
+ * Simple promise-or-value helper.
18
+ */
19
+ type Awaitable<T> = T | Promise<T>;
20
+ /**
21
+ * Next.js App Router route handler type.
22
+ *
23
+ * Accepts anything that is a valid `Response` to avoid forcing users
24
+ * to annotate union bodies on every handler.
25
+ */
26
+ type NextJSHandler = (req: NextRequest) => Awaitable<Response>;
27
+ /**
28
+ * Wrapper function that adds x402 payment verification to Next.js route handler.
29
+ * Returns a handler that may return either the original handler's response
30
+ * or a PaywallErrorResponse if payment verification fails.
31
+ */
32
+ type NextJSPaywallWrapper = (handler: NextJSHandler) => NextJSHandler;
33
+ /**
34
+ * Create Next.js App Router middleware for x402 payment verification.
35
+ * Uses Mantle mainnet defaults (USDC, exact scheme, etc.).
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * // app/api/generate-image/route.ts
40
+ * import { mantlePaywall } from '@puga-labs/x402-mantle-sdk/server/nextjs'
41
+ *
42
+ * const pay = mantlePaywall({
43
+ * priceUsd: 0.01,
44
+ * payTo: process.env.PAY_TO!,
45
+ * });
46
+ *
47
+ * // No 'as any' needed! TypeScript correctly infers the union type
48
+ * export const POST = pay(async (req: NextRequest) => {
49
+ * const { prompt } = await req.json();
50
+ * // Your handler code here
51
+ * return NextResponse.json({ success: true, imageUrl: "..." });
52
+ * });
53
+ * // TypeScript knows POST returns: NextResponse<{ success: boolean; imageUrl: string } | PaywallErrorResponse>
54
+ * ```
55
+ *
56
+ * @param opts - Minimal configuration (price, payTo, optional facilitator/telemetry).
57
+ * @returns Function that wraps Next.js route handlers with payment verification.
58
+ */
59
+ declare function mantlePaywall(opts: MinimalPaywallOptions): NextJSPaywallWrapper;
60
+ /**
61
+ * Type guard to check if a response is a paywall error response.
62
+ * Useful for handling the union type returned by the paywall wrapper.
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * const response = await fetch('/api/protected');
67
+ * const data = await response.json();
68
+ *
69
+ * if (isPaywallErrorResponse(data)) {
70
+ * // Handle error: data.error, data.paymentRequirements, etc.
71
+ * console.error('Payment required:', data.paymentRequirements);
72
+ * } else {
73
+ * // Handle success: data has type T
74
+ * console.log('Success:', data);
75
+ * }
76
+ * ```
77
+ */
78
+ declare function isPaywallErrorResponse(response: unknown): response is PaywallErrorResponse;
79
+
80
+ type nextjs_NextJSHandler = NextJSHandler;
81
+ type nextjs_NextJSPaywallWrapper = NextJSPaywallWrapper;
82
+ type nextjs_PaywallErrorResponse = PaywallErrorResponse;
83
+ declare const nextjs_isPaywallErrorResponse: typeof isPaywallErrorResponse;
84
+ declare const nextjs_mantlePaywall: typeof mantlePaywall;
85
+ declare namespace nextjs {
86
+ export { type nextjs_NextJSHandler as NextJSHandler, type nextjs_NextJSPaywallWrapper as NextJSPaywallWrapper, type nextjs_PaywallErrorResponse as PaywallErrorResponse, nextjs_isPaywallErrorResponse as isPaywallErrorResponse, nextjs_mantlePaywall as mantlePaywall };
87
+ }
88
+
89
+ export { type NextJSHandler as N, type PaywallErrorResponse as P, type NextJSPaywallWrapper as a, isPaywallErrorResponse as i, mantlePaywall as m, nextjs as n };
@@ -0,0 +1,89 @@
1
+ import { NextRequest } from 'next/server';
2
+ import { M as MinimalPaywallOptions } from './types-CXdNC0Ra.js';
3
+ import { P as PaymentRequirements } from './types-BFUqKBBO.js';
4
+
5
+ /**
6
+ * Error response returned when payment verification fails.
7
+ * This can be due to missing payment, invalid payment, or verification errors.
8
+ */
9
+ interface PaywallErrorResponse {
10
+ error: string;
11
+ paymentRequirements?: PaymentRequirements;
12
+ paymentHeader?: null;
13
+ invalidReason?: string | null;
14
+ details?: string;
15
+ }
16
+ /**
17
+ * Simple promise-or-value helper.
18
+ */
19
+ type Awaitable<T> = T | Promise<T>;
20
+ /**
21
+ * Next.js App Router route handler type.
22
+ *
23
+ * Accepts anything that is a valid `Response` to avoid forcing users
24
+ * to annotate union bodies on every handler.
25
+ */
26
+ type NextJSHandler = (req: NextRequest) => Awaitable<Response>;
27
+ /**
28
+ * Wrapper function that adds x402 payment verification to Next.js route handler.
29
+ * Returns a handler that may return either the original handler's response
30
+ * or a PaywallErrorResponse if payment verification fails.
31
+ */
32
+ type NextJSPaywallWrapper = (handler: NextJSHandler) => NextJSHandler;
33
+ /**
34
+ * Create Next.js App Router middleware for x402 payment verification.
35
+ * Uses Mantle mainnet defaults (USDC, exact scheme, etc.).
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * // app/api/generate-image/route.ts
40
+ * import { mantlePaywall } from '@puga-labs/x402-mantle-sdk/server/nextjs'
41
+ *
42
+ * const pay = mantlePaywall({
43
+ * priceUsd: 0.01,
44
+ * payTo: process.env.PAY_TO!,
45
+ * });
46
+ *
47
+ * // No 'as any' needed! TypeScript correctly infers the union type
48
+ * export const POST = pay(async (req: NextRequest) => {
49
+ * const { prompt } = await req.json();
50
+ * // Your handler code here
51
+ * return NextResponse.json({ success: true, imageUrl: "..." });
52
+ * });
53
+ * // TypeScript knows POST returns: NextResponse<{ success: boolean; imageUrl: string } | PaywallErrorResponse>
54
+ * ```
55
+ *
56
+ * @param opts - Minimal configuration (price, payTo, optional facilitator/telemetry).
57
+ * @returns Function that wraps Next.js route handlers with payment verification.
58
+ */
59
+ declare function mantlePaywall(opts: MinimalPaywallOptions): NextJSPaywallWrapper;
60
+ /**
61
+ * Type guard to check if a response is a paywall error response.
62
+ * Useful for handling the union type returned by the paywall wrapper.
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * const response = await fetch('/api/protected');
67
+ * const data = await response.json();
68
+ *
69
+ * if (isPaywallErrorResponse(data)) {
70
+ * // Handle error: data.error, data.paymentRequirements, etc.
71
+ * console.error('Payment required:', data.paymentRequirements);
72
+ * } else {
73
+ * // Handle success: data has type T
74
+ * console.log('Success:', data);
75
+ * }
76
+ * ```
77
+ */
78
+ declare function isPaywallErrorResponse(response: unknown): response is PaywallErrorResponse;
79
+
80
+ type nextjs_NextJSHandler = NextJSHandler;
81
+ type nextjs_NextJSPaywallWrapper = NextJSPaywallWrapper;
82
+ type nextjs_PaywallErrorResponse = PaywallErrorResponse;
83
+ declare const nextjs_isPaywallErrorResponse: typeof isPaywallErrorResponse;
84
+ declare const nextjs_mantlePaywall: typeof mantlePaywall;
85
+ declare namespace nextjs {
86
+ export { type nextjs_NextJSHandler as NextJSHandler, type nextjs_NextJSPaywallWrapper as NextJSPaywallWrapper, type nextjs_PaywallErrorResponse as PaywallErrorResponse, nextjs_isPaywallErrorResponse as isPaywallErrorResponse, nextjs_mantlePaywall as mantlePaywall };
87
+ }
88
+
89
+ export { type NextJSHandler as N, type PaywallErrorResponse as P, type NextJSPaywallWrapper as a, isPaywallErrorResponse as i, mantlePaywall as m, nextjs as n };
package/dist/react.cjs CHANGED
@@ -353,11 +353,26 @@ function createPaymentClient(config) {
353
353
  validBefore,
354
354
  nonce
355
355
  };
356
- const { signature, from } = await signAuthorizationWithProvider(
357
- provider,
358
- authorization,
359
- paymentRequirements
360
- );
356
+ let signature;
357
+ let from;
358
+ try {
359
+ const signed = await signAuthorizationWithProvider(
360
+ provider,
361
+ authorization,
362
+ paymentRequirements
363
+ );
364
+ signature = signed.signature;
365
+ from = signed.from;
366
+ } catch (err) {
367
+ const code = err?.code;
368
+ if (code === 4001 || code === "ACTION_REJECTED") {
369
+ const userErr = new Error("User rejected payment signature");
370
+ userErr.code = "USER_REJECTED_SIGNATURE";
371
+ userErr.userRejected = true;
372
+ throw userErr;
373
+ }
374
+ throw err;
375
+ }
361
376
  authorization = {
362
377
  ...authorization,
363
378
  from
package/dist/react.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  useEthersWallet,
3
3
  useMantleX402
4
- } from "./chunk-APBCF3SX.js";
5
- import "./chunk-VNO4LJWC.js";
4
+ } from "./chunk-26OQ36EN.js";
5
+ import "./chunk-7SOCLVGM.js";
6
6
  import "./chunk-HEZZ74SI.js";
7
7
  export {
8
8
  useEthersWallet,
@@ -109,7 +109,7 @@ function usdCentsToAtomic(cents, decimals) {
109
109
  }
110
110
 
111
111
  // src/server/constants.ts
112
- var DEFAULT_TELEMETRY_ENDPOINT = void 0;
112
+ var DEFAULT_TELEMETRY_ENDPOINT = "https://x402mantlesdk.xyz/api/telemetry/settled";
113
113
 
114
114
  // src/server/telemetry.ts
115
115
  function createTelemetryEvent(entry, config) {
@@ -167,6 +167,7 @@ async function checkPayment(input) {
167
167
  paymentHeader,
168
168
  paymentRequirements,
169
169
  facilitatorUrl,
170
+ apiKey,
170
171
  routeKey,
171
172
  network,
172
173
  asset,
@@ -190,7 +191,8 @@ async function checkPayment(input) {
190
191
  const verifyRes = await fetch(verifyUrl, {
191
192
  method: "POST",
192
193
  headers: {
193
- "Content-Type": "application/json"
194
+ "Content-Type": "application/json",
195
+ ...apiKey && { "Authorization": `Bearer ${apiKey}` }
194
196
  },
195
197
  body: JSON.stringify({
196
198
  x402Version: 1,
@@ -286,7 +288,7 @@ async function checkPayment(input) {
286
288
 
287
289
  // src/server/adapters/express.ts
288
290
  function createPaymentMiddleware(config) {
289
- const { facilitatorUrl, receiverAddress, routes, onPaymentSettled, telemetry } = config;
291
+ const { facilitatorUrl, receiverAddress, routes, apiKey, onPaymentSettled, telemetry } = config;
290
292
  if (!facilitatorUrl) {
291
293
  throw new Error("facilitatorUrl is required");
292
294
  }
@@ -324,6 +326,7 @@ function createPaymentMiddleware(config) {
324
326
  paymentHeader,
325
327
  paymentRequirements,
326
328
  facilitatorUrl,
329
+ apiKey,
327
330
  routeKey,
328
331
  network,
329
332
  asset: assetConfig.address,
@@ -338,7 +341,7 @@ function createPaymentMiddleware(config) {
338
341
  };
339
342
  }
340
343
  function mantlePaywall(opts) {
341
- const { priceUsd, payTo, facilitatorUrl, telemetry, onPaymentSettled } = opts;
344
+ const { priceUsd, payTo, facilitatorUrl, apiKey, telemetry, onPaymentSettled } = opts;
342
345
  validateAddress(payTo, "payTo");
343
346
  const priceUsdCents = Math.round(priceUsd * 100);
344
347
  return async (req, res, next) => {
@@ -354,6 +357,7 @@ function mantlePaywall(opts) {
354
357
  network: MANTLE_DEFAULTS.NETWORK
355
358
  }
356
359
  },
360
+ apiKey,
357
361
  telemetry,
358
362
  onPaymentSettled
359
363
  });
@@ -1,5 +1,5 @@
1
- export { M as MantleMiddleware, P as PaymentMiddlewareConfig, c as createPaymentMiddleware, m as mantlePaywall } from './express-eQOPxfnI.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-CrOsOHcX.cjs';
1
+ export { M as MantleMiddleware, P as PaymentMiddlewareConfig, c as createPaymentMiddleware, m as mantlePaywall } from './express-Pukmnwuu.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-BmK0G74m.cjs';
3
3
  export { A as AssetConfig, a as Authorization, E as EIP1193Provider, N as NetworkId, d as PaymentHeaderBase64, c as PaymentHeaderObject, b as PaymentHeaderPayload, P as PaymentRequirements } from './types-BFUqKBBO.cjs';
4
4
  export { M as MANTLE_DEFAULTS } from './constants-CsIL25uQ.cjs';
5
5
  import 'express';
@@ -1,5 +1,5 @@
1
- export { M as MantleMiddleware, P as PaymentMiddlewareConfig, c as createPaymentMiddleware, m as mantlePaywall } from './express-D8EwEcOL.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-CqQ6OgRi.js';
1
+ export { M as MantleMiddleware, P as PaymentMiddlewareConfig, c as createPaymentMiddleware, m as mantlePaywall } from './express-D8L5Dg1D.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-CXdNC0Ra.js';
3
3
  export { A as AssetConfig, a as Authorization, E as EIP1193Provider, N as NetworkId, d as PaymentHeaderBase64, c as PaymentHeaderObject, b as PaymentHeaderPayload, P as PaymentRequirements } from './types-BFUqKBBO.js';
4
4
  export { M as MANTLE_DEFAULTS } from './constants-0ncqvV_O.js';
5
5
  import 'express';
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  createPaymentMiddleware,
3
3
  mantlePaywall
4
- } from "./chunk-QWQUSRLY.js";
5
- import "./chunk-ZLCKBFVJ.js";
4
+ } from "./chunk-B4GST723.js";
5
+ import "./chunk-OW2BDRGZ.js";
6
6
  import {
7
7
  MANTLE_DEFAULTS
8
8
  } from "./chunk-HEZZ74SI.js";
@@ -112,7 +112,7 @@ function usdCentsToAtomic(cents, decimals) {
112
112
  }
113
113
 
114
114
  // src/server/constants.ts
115
- var DEFAULT_TELEMETRY_ENDPOINT = void 0;
115
+ var DEFAULT_TELEMETRY_ENDPOINT = "https://x402mantlesdk.xyz/api/telemetry/settled";
116
116
 
117
117
  // src/server/telemetry.ts
118
118
  function createTelemetryEvent(entry, config) {
@@ -170,6 +170,7 @@ async function checkPayment(input) {
170
170
  paymentHeader,
171
171
  paymentRequirements,
172
172
  facilitatorUrl,
173
+ apiKey,
173
174
  routeKey,
174
175
  network,
175
176
  asset,
@@ -193,7 +194,8 @@ async function checkPayment(input) {
193
194
  const verifyRes = await fetch(verifyUrl, {
194
195
  method: "POST",
195
196
  headers: {
196
- "Content-Type": "application/json"
197
+ "Content-Type": "application/json",
198
+ ...apiKey && { "Authorization": `Bearer ${apiKey}` }
197
199
  },
198
200
  body: JSON.stringify({
199
201
  x402Version: 1,
@@ -289,7 +291,7 @@ async function checkPayment(input) {
289
291
 
290
292
  // src/server/adapters/nextjs.ts
291
293
  function mantlePaywall(opts) {
292
- const { priceUsd, payTo, facilitatorUrl, telemetry, onPaymentSettled } = opts;
294
+ const { priceUsd, payTo, facilitatorUrl, apiKey, telemetry, onPaymentSettled } = opts;
293
295
  validateAddress(payTo, "payTo");
294
296
  const priceUsdCents = Math.round(priceUsd * 100);
295
297
  return function(handler) {
@@ -318,6 +320,7 @@ function mantlePaywall(opts) {
318
320
  paymentHeader,
319
321
  paymentRequirements,
320
322
  facilitatorUrl: facilitatorUrl || MANTLE_DEFAULTS.FACILITATOR_URL,
323
+ apiKey,
321
324
  routeKey,
322
325
  network,
323
326
  asset: assetConfig.address,
@@ -1,5 +1,5 @@
1
- export { N as NextJSHandler, a as NextJSPaywallWrapper, P as PaywallErrorResponse, i as isPaywallErrorResponse, m as mantlePaywall } from './nextjs-CGOVHJXl.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-CrOsOHcX.cjs';
1
+ export { N as NextJSHandler, a as NextJSPaywallWrapper, P as PaywallErrorResponse, i as isPaywallErrorResponse, m as mantlePaywall } from './nextjs-CSUWjcxv.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-BmK0G74m.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';
@@ -1,5 +1,5 @@
1
- export { N as NextJSHandler, a as NextJSPaywallWrapper, P as PaywallErrorResponse, i as isPaywallErrorResponse, m as mantlePaywall } from './nextjs-w61gRvpz.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-CqQ6OgRi.js';
1
+ export { N as NextJSHandler, a as NextJSPaywallWrapper, P as PaywallErrorResponse, i as isPaywallErrorResponse, m as mantlePaywall } from './nextjs-DUdgN0d_.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-CXdNC0Ra.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';
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  isPaywallErrorResponse,
3
3
  mantlePaywall
4
- } from "./chunk-IT6VV6YL.js";
5
- import "./chunk-ZLCKBFVJ.js";
4
+ } from "./chunk-33WHNZDS.js";
5
+ import "./chunk-OW2BDRGZ.js";
6
6
  import {
7
7
  MANTLE_DEFAULTS
8
8
  } from "./chunk-HEZZ74SI.js";
@@ -108,7 +108,7 @@ function usdCentsToAtomic(cents, decimals) {
108
108
  }
109
109
 
110
110
  // src/server/constants.ts
111
- var DEFAULT_TELEMETRY_ENDPOINT = void 0;
111
+ var DEFAULT_TELEMETRY_ENDPOINT = "https://x402mantlesdk.xyz/api/telemetry/settled";
112
112
 
113
113
  // src/server/telemetry.ts
114
114
  function createTelemetryEvent(entry, config) {
@@ -166,6 +166,7 @@ async function checkPayment(input) {
166
166
  paymentHeader,
167
167
  paymentRequirements,
168
168
  facilitatorUrl,
169
+ apiKey,
169
170
  routeKey,
170
171
  network,
171
172
  asset,
@@ -189,7 +190,8 @@ async function checkPayment(input) {
189
190
  const verifyRes = await fetch(verifyUrl, {
190
191
  method: "POST",
191
192
  headers: {
192
- "Content-Type": "application/json"
193
+ "Content-Type": "application/json",
194
+ ...apiKey && { "Authorization": `Bearer ${apiKey}` }
193
195
  },
194
196
  body: JSON.stringify({
195
197
  x402Version: 1,
@@ -285,7 +287,7 @@ async function checkPayment(input) {
285
287
 
286
288
  // src/server/adapters/web-standards.ts
287
289
  function mantlePaywall(opts) {
288
- const { priceUsd, payTo, facilitatorUrl, telemetry, onPaymentSettled } = opts;
290
+ const { priceUsd, payTo, facilitatorUrl, apiKey, telemetry, onPaymentSettled } = opts;
289
291
  validateAddress(payTo, "payTo");
290
292
  const priceUsdCents = Math.round(priceUsd * 100);
291
293
  return function(handler) {
@@ -314,6 +316,7 @@ function mantlePaywall(opts) {
314
316
  paymentHeader,
315
317
  paymentRequirements,
316
318
  facilitatorUrl: facilitatorUrl || MANTLE_DEFAULTS.FACILITATOR_URL,
319
+ apiKey,
317
320
  routeKey,
318
321
  network,
319
322
  asset: assetConfig.address,
@@ -1,4 +1,4 @@
1
- export { W as WebHandler, a as WebPaywallWrapper, m as mantlePaywall } from './web-standards-BNQyWzBC.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-CrOsOHcX.cjs';
1
+ export { W as WebHandler, a as WebPaywallWrapper, m as mantlePaywall } from './web-standards-BvMLEKlU.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-BmK0G74m.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';
@@ -1,4 +1,4 @@
1
- export { W as WebHandler, a as WebPaywallWrapper, m as mantlePaywall } from './web-standards-D8j1kZxd.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-CqQ6OgRi.js';
1
+ export { W as WebHandler, a as WebPaywallWrapper, m as mantlePaywall } from './web-standards-g2rYUpgc.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-CXdNC0Ra.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';
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  mantlePaywall
3
- } from "./chunk-ZROK2XOB.js";
4
- import "./chunk-ZLCKBFVJ.js";
3
+ } from "./chunk-T63MVWX3.js";
4
+ import "./chunk-OW2BDRGZ.js";
5
5
  import {
6
6
  MANTLE_DEFAULTS
7
7
  } from "./chunk-HEZZ74SI.js";
package/dist/server.cjs CHANGED
@@ -118,7 +118,7 @@ function usdCentsToAtomic(cents, decimals) {
118
118
  }
119
119
 
120
120
  // src/server/constants.ts
121
- var DEFAULT_TELEMETRY_ENDPOINT = void 0;
121
+ var DEFAULT_TELEMETRY_ENDPOINT = "https://x402mantlesdk.xyz/api/telemetry/settled";
122
122
 
123
123
  // src/server/telemetry.ts
124
124
  function createTelemetryEvent(entry, config) {
@@ -176,6 +176,7 @@ async function checkPayment(input) {
176
176
  paymentHeader,
177
177
  paymentRequirements,
178
178
  facilitatorUrl,
179
+ apiKey,
179
180
  routeKey,
180
181
  network,
181
182
  asset,
@@ -199,7 +200,8 @@ async function checkPayment(input) {
199
200
  const verifyRes = await fetch(verifyUrl, {
200
201
  method: "POST",
201
202
  headers: {
202
- "Content-Type": "application/json"
203
+ "Content-Type": "application/json",
204
+ ...apiKey && { "Authorization": `Bearer ${apiKey}` }
203
205
  },
204
206
  body: JSON.stringify({
205
207
  x402Version: 1,
@@ -300,7 +302,7 @@ __export(express_exports, {
300
302
  mantlePaywall: () => mantlePaywall
301
303
  });
302
304
  function createPaymentMiddleware(config) {
303
- const { facilitatorUrl, receiverAddress, routes, onPaymentSettled, telemetry } = config;
305
+ const { facilitatorUrl, receiverAddress, routes, apiKey, onPaymentSettled, telemetry } = config;
304
306
  if (!facilitatorUrl) {
305
307
  throw new Error("facilitatorUrl is required");
306
308
  }
@@ -338,6 +340,7 @@ function createPaymentMiddleware(config) {
338
340
  paymentHeader,
339
341
  paymentRequirements,
340
342
  facilitatorUrl,
343
+ apiKey,
341
344
  routeKey,
342
345
  network,
343
346
  asset: assetConfig.address,
@@ -352,7 +355,7 @@ function createPaymentMiddleware(config) {
352
355
  };
353
356
  }
354
357
  function mantlePaywall(opts) {
355
- const { priceUsd, payTo, facilitatorUrl, telemetry, onPaymentSettled } = opts;
358
+ const { priceUsd, payTo, facilitatorUrl, apiKey, telemetry, onPaymentSettled } = opts;
356
359
  validateAddress(payTo, "payTo");
357
360
  const priceUsdCents = Math.round(priceUsd * 100);
358
361
  return async (req, res, next) => {
@@ -368,6 +371,7 @@ function mantlePaywall(opts) {
368
371
  network: MANTLE_DEFAULTS.NETWORK
369
372
  }
370
373
  },
374
+ apiKey,
371
375
  telemetry,
372
376
  onPaymentSettled
373
377
  });
@@ -383,7 +387,7 @@ __export(nextjs_exports, {
383
387
  });
384
388
  var import_server = require("next/server");
385
389
  function mantlePaywall2(opts) {
386
- const { priceUsd, payTo, facilitatorUrl, telemetry, onPaymentSettled } = opts;
390
+ const { priceUsd, payTo, facilitatorUrl, apiKey, telemetry, onPaymentSettled } = opts;
387
391
  validateAddress(payTo, "payTo");
388
392
  const priceUsdCents = Math.round(priceUsd * 100);
389
393
  return function(handler) {
@@ -412,6 +416,7 @@ function mantlePaywall2(opts) {
412
416
  paymentHeader,
413
417
  paymentRequirements,
414
418
  facilitatorUrl: facilitatorUrl || MANTLE_DEFAULTS.FACILITATOR_URL,
419
+ apiKey,
415
420
  routeKey,
416
421
  network,
417
422
  asset: assetConfig.address,
@@ -437,7 +442,7 @@ __export(web_standards_exports, {
437
442
  mantlePaywall: () => mantlePaywall3
438
443
  });
439
444
  function mantlePaywall3(opts) {
440
- const { priceUsd, payTo, facilitatorUrl, telemetry, onPaymentSettled } = opts;
445
+ const { priceUsd, payTo, facilitatorUrl, apiKey, telemetry, onPaymentSettled } = opts;
441
446
  validateAddress(payTo, "payTo");
442
447
  const priceUsdCents = Math.round(priceUsd * 100);
443
448
  return function(handler) {
@@ -466,6 +471,7 @@ function mantlePaywall3(opts) {
466
471
  paymentHeader,
467
472
  paymentRequirements,
468
473
  facilitatorUrl: facilitatorUrl || MANTLE_DEFAULTS.FACILITATOR_URL,
474
+ apiKey,
469
475
  routeKey,
470
476
  network,
471
477
  asset: assetConfig.address,
package/dist/server.d.cts CHANGED
@@ -1,10 +1,10 @@
1
- import { c as PaymentCheckInput, d as PaymentCheckResult } from './types-CrOsOHcX.cjs';
2
- export { M as MinimalPaywallOptions, P as PaymentLogEntry, R as RouteKey, a as RoutePricingConfig, b as RoutesConfig, T as TelemetryConfig } from './types-CrOsOHcX.cjs';
1
+ import { c as PaymentCheckInput, d as PaymentCheckResult } from './types-BmK0G74m.cjs';
2
+ export { M as MinimalPaywallOptions, P as PaymentLogEntry, R as RouteKey, a as RoutePricingConfig, b as RoutesConfig, T as TelemetryConfig } from './types-BmK0G74m.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-eQOPxfnI.cjs';
5
- export { n as nextjs } from './nextjs-CGOVHJXl.cjs';
6
- export { w as web } from './web-standards-BNQyWzBC.cjs';
7
- import { P as PaymentLogEntry, T as TelemetryConfig, c as TelemetryEvent } from './types-CoOdbZSp.cjs';
4
+ export { M as MantleMiddleware, c as createPaymentMiddleware, e as express, m as mantlePaywall } from './express-Pukmnwuu.cjs';
5
+ export { n as nextjs } from './nextjs-CSUWjcxv.cjs';
6
+ export { w as web } from './web-standards-BvMLEKlU.cjs';
7
+ import { P as PaymentLogEntry, T as TelemetryConfig, c as TelemetryEvent } from './types-BWfKovFm.cjs';
8
8
  import 'express';
9
9
  import 'next/server';
10
10
 
package/dist/server.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- import { c as PaymentCheckInput, d as PaymentCheckResult } from './types-CqQ6OgRi.js';
2
- export { M as MinimalPaywallOptions, P as PaymentLogEntry, R as RouteKey, a as RoutePricingConfig, b as RoutesConfig, T as TelemetryConfig } from './types-CqQ6OgRi.js';
1
+ import { c as PaymentCheckInput, d as PaymentCheckResult } from './types-CXdNC0Ra.js';
2
+ export { M as MinimalPaywallOptions, P as PaymentLogEntry, R as RouteKey, a as RoutePricingConfig, b as RoutesConfig, T as TelemetryConfig } from './types-CXdNC0Ra.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-D8EwEcOL.js';
5
- export { n as nextjs } from './nextjs-w61gRvpz.js';
6
- export { w as web } from './web-standards-D8j1kZxd.js';
7
- import { P as PaymentLogEntry, T as TelemetryConfig, c as TelemetryEvent } from './types-DTzov_EE.js';
4
+ export { M as MantleMiddleware, c as createPaymentMiddleware, e as express, m as mantlePaywall } from './express-D8L5Dg1D.js';
5
+ export { n as nextjs } from './nextjs-DUdgN0d_.js';
6
+ export { w as web } from './web-standards-g2rYUpgc.js';
7
+ import { P as PaymentLogEntry, T as TelemetryConfig, c as TelemetryEvent } from './types-DgfVPQFb.js';
8
8
  import 'express';
9
9
  import 'next/server';
10
10
 
package/dist/server.js CHANGED
@@ -3,13 +3,13 @@ import {
3
3
  createPaymentMiddleware,
4
4
  express_exports,
5
5
  mantlePaywall
6
- } from "./chunk-QWQUSRLY.js";
6
+ } from "./chunk-B4GST723.js";
7
7
  import {
8
8
  nextjs_exports
9
- } from "./chunk-IT6VV6YL.js";
9
+ } from "./chunk-33WHNZDS.js";
10
10
  import {
11
11
  web_standards_exports
12
- } from "./chunk-ZROK2XOB.js";
12
+ } from "./chunk-T63MVWX3.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-ZLCKBFVJ.js";
21
+ } from "./chunk-OW2BDRGZ.js";
22
22
  import "./chunk-HEZZ74SI.js";
23
23
  export {
24
24
  DEFAULT_TELEMETRY_ENDPOINT,