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

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 (70) hide show
  1. package/dist/chunk-23QNUJIB.js +136 -0
  2. package/dist/chunk-6GLR5EBK.js +96 -0
  3. package/dist/chunk-BRGW36P7.js +211 -0
  4. package/dist/chunk-E46A7I6B.js +274 -0
  5. package/dist/chunk-FHU6CFHF.js +0 -0
  6. package/dist/chunk-GHUWTX7J.js +66 -0
  7. package/dist/chunk-HEZZ74SI.js +62 -0
  8. package/dist/chunk-NQWSCY44.js +70 -0
  9. package/dist/chunk-PCJEJYP6.js +68 -0
  10. package/dist/chunk-PPVS3X5Z.js +99 -0
  11. package/dist/chunk-U73CZU3X.js +237 -0
  12. package/dist/chunk-WAKJRVUP.js +135 -0
  13. package/dist/chunk-WFUDGBKK.js +68 -0
  14. package/dist/chunk-WO2MYZXT.js +0 -0
  15. package/dist/client.d.cts +4 -4
  16. package/dist/client.d.ts +4 -4
  17. package/dist/client.js +2 -2
  18. package/dist/constants-0ncqvV_O.d.ts +17 -0
  19. package/dist/constants-CsIL25uQ.d.cts +17 -0
  20. package/dist/createMantleClient-CO0uWPb-.d.cts +87 -0
  21. package/dist/createMantleClient-CuiPsTa6.d.ts +87 -0
  22. package/dist/express-Ck7eryef.d.cts +66 -0
  23. package/dist/express-CmEg5hR3.d.ts +66 -0
  24. package/dist/express-D8EwEcOL.d.ts +66 -0
  25. package/dist/express-eQOPxfnI.d.cts +66 -0
  26. package/dist/index.cjs +186 -109
  27. package/dist/index.d.cts +6 -4
  28. package/dist/index.d.ts +6 -4
  29. package/dist/index.js +6 -4
  30. package/dist/nextjs-Bp8DxYDN.d.ts +45 -0
  31. package/dist/nextjs-CliiaTPe.d.cts +45 -0
  32. package/dist/nextjs-D7t-BC4N.d.ts +45 -0
  33. package/dist/nextjs-Duecps0q.d.cts +45 -0
  34. package/dist/nextjs-TFhFiQuL.d.ts +45 -0
  35. package/dist/nextjs-ZO2J9mdo.d.cts +45 -0
  36. package/dist/react.cjs +3 -2
  37. package/dist/react.d.cts +7 -4
  38. package/dist/react.d.ts +7 -4
  39. package/dist/react.js +3 -3
  40. package/dist/server-express.cjs +368 -0
  41. package/dist/server-express.d.cts +5 -0
  42. package/dist/server-express.d.ts +5 -0
  43. package/dist/server-express.js +13 -0
  44. package/dist/server-nextjs.cjs +339 -0
  45. package/dist/server-nextjs.d.cts +5 -0
  46. package/dist/server-nextjs.d.ts +5 -0
  47. package/dist/server-nextjs.js +11 -0
  48. package/dist/server-web.cjs +339 -0
  49. package/dist/server-web.d.cts +4 -0
  50. package/dist/server-web.d.ts +4 -0
  51. package/dist/server-web.js +11 -0
  52. package/dist/server.cjs +316 -111
  53. package/dist/server.d.cts +67 -104
  54. package/dist/server.d.ts +67 -104
  55. package/dist/server.js +29 -5
  56. package/dist/types-BFUqKBBO.d.cts +63 -0
  57. package/dist/types-BFUqKBBO.d.ts +63 -0
  58. package/dist/types-C7EPJ6Hd.d.ts +85 -0
  59. package/dist/types-CEttmr1U.d.cts +97 -0
  60. package/dist/types-CoOdbZSp.d.cts +97 -0
  61. package/dist/types-CqQ6OgRi.d.ts +85 -0
  62. package/dist/types-CrOsOHcX.d.cts +85 -0
  63. package/dist/types-D20K36pc.d.ts +97 -0
  64. package/dist/types-DTzov_EE.d.ts +97 -0
  65. package/dist/types-xkNm0uzE.d.cts +85 -0
  66. package/dist/web-standards-BNQyWzBC.d.cts +77 -0
  67. package/dist/web-standards-C3D2vdTg.d.ts +77 -0
  68. package/dist/web-standards-D8j1kZxd.d.ts +77 -0
  69. package/dist/web-standards-DOYp0UDT.d.cts +77 -0
  70. package/package.json +49 -2
@@ -0,0 +1,135 @@
1
+ import {
2
+ createMantleClient
3
+ } from "./chunk-E46A7I6B.js";
4
+
5
+ // src/client/react/useEthersWallet.ts
6
+ import { useState, useEffect, useCallback } from "react";
7
+ import { ethers } from "ethers";
8
+ function useEthersWallet(options) {
9
+ const [address, setAddress] = useState(void 0);
10
+ const [isConnected, setIsConnected] = useState(false);
11
+ const [provider, setProvider] = useState(
12
+ void 0
13
+ );
14
+ const [chainId, setChainId] = useState(void 0);
15
+ const [error, setError] = useState(void 0);
16
+ const connect = useCallback(async () => {
17
+ try {
18
+ setError(void 0);
19
+ if (typeof window === "undefined" || !window.ethereum) {
20
+ throw new Error(
21
+ "No Ethereum wallet detected. Please install MetaMask or another wallet."
22
+ );
23
+ }
24
+ const browserProvider = new ethers.BrowserProvider(
25
+ window.ethereum
26
+ );
27
+ setProvider(browserProvider);
28
+ const accounts = await window.ethereum.request({
29
+ method: "eth_requestAccounts"
30
+ });
31
+ if (!accounts || accounts.length === 0) {
32
+ throw new Error("No accounts returned from wallet");
33
+ }
34
+ const userAddress = accounts[0];
35
+ setAddress(userAddress);
36
+ setIsConnected(true);
37
+ const network = await browserProvider.getNetwork();
38
+ setChainId(Number(network.chainId));
39
+ } catch (err) {
40
+ const errorObj = err instanceof Error ? err : new Error(String(err));
41
+ setError(errorObj);
42
+ setIsConnected(false);
43
+ setAddress(void 0);
44
+ setChainId(void 0);
45
+ throw errorObj;
46
+ }
47
+ }, []);
48
+ const disconnect = useCallback(() => {
49
+ setAddress(void 0);
50
+ setIsConnected(false);
51
+ setChainId(void 0);
52
+ setError(void 0);
53
+ }, []);
54
+ useEffect(() => {
55
+ if (typeof window === "undefined" || !window.ethereum) return;
56
+ const ethereum = window.ethereum;
57
+ const handleAccountsChanged = (accounts) => {
58
+ const accountsArray = accounts;
59
+ if (!accountsArray || accountsArray.length === 0) {
60
+ disconnect();
61
+ } else {
62
+ setAddress(accountsArray[0]);
63
+ setIsConnected(true);
64
+ }
65
+ };
66
+ if (ethereum.on) {
67
+ ethereum.on("accountsChanged", handleAccountsChanged);
68
+ }
69
+ return () => {
70
+ if (ethereum.removeListener) {
71
+ ethereum.removeListener("accountsChanged", handleAccountsChanged);
72
+ }
73
+ };
74
+ }, [disconnect]);
75
+ useEffect(() => {
76
+ if (typeof window === "undefined" || !window.ethereum) return;
77
+ const ethereum = window.ethereum;
78
+ const handleChainChanged = (chainIdHex) => {
79
+ const newChainId = parseInt(chainIdHex, 16);
80
+ setChainId(newChainId);
81
+ };
82
+ if (ethereum.on) {
83
+ ethereum.on("chainChanged", handleChainChanged);
84
+ }
85
+ return () => {
86
+ if (ethereum.removeListener) {
87
+ ethereum.removeListener("chainChanged", handleChainChanged);
88
+ }
89
+ };
90
+ }, []);
91
+ useEffect(() => {
92
+ if (options?.autoConnect) {
93
+ connect().catch((err) => {
94
+ console.warn("[useEthersWallet] Auto-connect failed:", err);
95
+ });
96
+ }
97
+ }, [options?.autoConnect, connect]);
98
+ return {
99
+ address,
100
+ isConnected,
101
+ provider,
102
+ chainId,
103
+ connect,
104
+ disconnect,
105
+ error
106
+ };
107
+ }
108
+
109
+ // src/client/react/useMantleX402.ts
110
+ function useMantleX402(opts) {
111
+ const { address, isConnected } = useEthersWallet({
112
+ autoConnect: opts?.autoConnect ?? false
113
+ });
114
+ const client = createMantleClient({
115
+ facilitatorUrl: opts?.facilitatorUrl,
116
+ resourceUrl: opts?.resourceUrl,
117
+ projectKey: opts?.projectKey,
118
+ getAccount: () => {
119
+ if (!isConnected || !address) return void 0;
120
+ return address;
121
+ },
122
+ getProvider: () => {
123
+ if (typeof window !== "undefined" && window.ethereum) {
124
+ return window.ethereum;
125
+ }
126
+ return void 0;
127
+ }
128
+ });
129
+ return client;
130
+ }
131
+
132
+ export {
133
+ useEthersWallet,
134
+ useMantleX402
135
+ };
@@ -0,0 +1,68 @@
1
+ import {
2
+ buildRouteKey,
3
+ checkPayment
4
+ } from "./chunk-BRGW36P7.js";
5
+ import {
6
+ MANTLE_DEFAULTS,
7
+ __export,
8
+ getDefaultAssetForNetwork,
9
+ usdCentsToAtomic
10
+ } from "./chunk-HEZZ74SI.js";
11
+
12
+ // src/server/adapters/web-standards.ts
13
+ var web_standards_exports = {};
14
+ __export(web_standards_exports, {
15
+ mantlePaywall: () => mantlePaywall
16
+ });
17
+ function mantlePaywall(opts) {
18
+ const { priceUsd, payTo, facilitatorUrl, telemetry, onPaymentSettled } = opts;
19
+ const priceUsdCents = Math.round(priceUsd * 100);
20
+ return function(handler) {
21
+ return async (request) => {
22
+ const url = new URL(request.url);
23
+ const method = request.method;
24
+ const path = url.pathname;
25
+ const routeKey = buildRouteKey(method, path);
26
+ const network = MANTLE_DEFAULTS.NETWORK;
27
+ const assetConfig = getDefaultAssetForNetwork(network);
28
+ const maxAmountRequiredBigInt = usdCentsToAtomic(
29
+ priceUsdCents,
30
+ assetConfig.decimals
31
+ );
32
+ const paymentRequirements = {
33
+ scheme: "exact",
34
+ network,
35
+ asset: assetConfig.address,
36
+ maxAmountRequired: maxAmountRequiredBigInt.toString(),
37
+ payTo,
38
+ price: `$${(priceUsdCents / 100).toFixed(2)}`,
39
+ currency: "USD"
40
+ };
41
+ const paymentHeader = request.headers.get("X-PAYMENT") || request.headers.get("x-payment") || null;
42
+ const result = await checkPayment({
43
+ paymentHeader,
44
+ paymentRequirements,
45
+ facilitatorUrl: facilitatorUrl || MANTLE_DEFAULTS.FACILITATOR_URL,
46
+ routeKey,
47
+ network,
48
+ asset: assetConfig.address,
49
+ telemetry,
50
+ onPaymentSettled
51
+ });
52
+ if (!result.isValid) {
53
+ return new Response(JSON.stringify(result.responseBody), {
54
+ status: result.statusCode,
55
+ headers: {
56
+ "Content-Type": "application/json"
57
+ }
58
+ });
59
+ }
60
+ return handler(request);
61
+ };
62
+ };
63
+ }
64
+
65
+ export {
66
+ mantlePaywall,
67
+ web_standards_exports
68
+ };
File without changes
package/dist/client.d.cts CHANGED
@@ -1,7 +1,7 @@
1
- import { P as PaymentClientConfig, b as PaymentClient } from './createMantleClient-NN0Nitp9.cjs';
2
- export { C as CallWithPaymentResult, M as MantleClient, a as MantleClientConfig, c as createMantleClient } from './createMantleClient-NN0Nitp9.cjs';
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-2zqbJvcz.cjs';
4
- export { M as MANTLE_DEFAULTS } from './constants-DzCGK0Q3.cjs';
1
+ import { P as PaymentClientConfig, b as PaymentClient } from './createMantleClient-CO0uWPb-.cjs';
2
+ export { C as CallWithPaymentResult, M as MantleClient, a as MantleClientConfig, c as createMantleClient } from './createMantleClient-CO0uWPb-.cjs';
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
+ export { M as MANTLE_DEFAULTS } from './constants-CsIL25uQ.cjs';
5
5
 
6
6
  /**
7
7
  * Creates a high-level payment client that:
package/dist/client.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { P as PaymentClientConfig, b as PaymentClient } from './createMantleClient-DVFkbBfS.js';
2
- export { C as CallWithPaymentResult, M as MantleClient, a as MantleClientConfig, c as createMantleClient } from './createMantleClient-DVFkbBfS.js';
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-2zqbJvcz.js';
4
- export { M as MANTLE_DEFAULTS } from './constants-CVFF0ray.js';
1
+ import { P as PaymentClientConfig, b as PaymentClient } from './createMantleClient-CuiPsTa6.js';
2
+ export { C as CallWithPaymentResult, M as MantleClient, a as MantleClientConfig, c as createMantleClient } from './createMantleClient-CuiPsTa6.js';
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
+ export { M as MANTLE_DEFAULTS } from './constants-0ncqvV_O.js';
5
5
 
6
6
  /**
7
7
  * Creates a high-level payment client that:
package/dist/client.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  createMantleClient,
3
3
  createPaymentClient
4
- } from "./chunk-CTI5CRDY.js";
4
+ } from "./chunk-E46A7I6B.js";
5
5
  import {
6
6
  MANTLE_DEFAULTS
7
- } from "./chunk-XAQGMFSR.js";
7
+ } from "./chunk-HEZZ74SI.js";
8
8
  export {
9
9
  MANTLE_DEFAULTS,
10
10
  createMantleClient,
@@ -0,0 +1,17 @@
1
+ import './types-BFUqKBBO.js';
2
+
3
+ /**
4
+ * Default values for Mantle mainnet x402 payments.
5
+ * These are used by the simplified API (mantlePaywall, createMantleClient).
6
+ */
7
+ declare const MANTLE_DEFAULTS: {
8
+ readonly NETWORK: "mantle-mainnet";
9
+ readonly CHAIN_ID: 5000;
10
+ readonly USDC_ADDRESS: "0x09Bc4E0D864854c6aFB6eB9A9cdF58aC190D0dF9";
11
+ readonly USDC_DECIMALS: 6;
12
+ readonly CURRENCY: "USD";
13
+ readonly SCHEME: "exact";
14
+ readonly FACILITATOR_URL: string;
15
+ };
16
+
17
+ export { MANTLE_DEFAULTS as M };
@@ -0,0 +1,17 @@
1
+ import './types-BFUqKBBO.cjs';
2
+
3
+ /**
4
+ * Default values for Mantle mainnet x402 payments.
5
+ * These are used by the simplified API (mantlePaywall, createMantleClient).
6
+ */
7
+ declare const MANTLE_DEFAULTS: {
8
+ readonly NETWORK: "mantle-mainnet";
9
+ readonly CHAIN_ID: 5000;
10
+ readonly USDC_ADDRESS: "0x09Bc4E0D864854c6aFB6eB9A9cdF58aC190D0dF9";
11
+ readonly USDC_DECIMALS: 6;
12
+ readonly CURRENCY: "USD";
13
+ readonly SCHEME: "exact";
14
+ readonly FACILITATOR_URL: string;
15
+ };
16
+
17
+ export { MANTLE_DEFAULTS as M };
@@ -0,0 +1,87 @@
1
+ import { d as PaymentHeaderBase64, P as PaymentRequirements } from './types-BFUqKBBO.cjs';
2
+
3
+ /** Config for the client-side payment helper. */
4
+ interface PaymentClientConfig {
5
+ /** Base URL of your protected resource server. */
6
+ resourceUrl: string;
7
+ /** Facilitator URL (hosted or self-hosted). */
8
+ facilitatorUrl: string;
9
+ /** EIP-1193 provider (window.ethereum) or similar. */
10
+ provider: unknown;
11
+ /** Optional user address override; otherwise derived from provider. */
12
+ userAddress?: string;
13
+ /** Optional: Project key for hosted facilitator billing. */
14
+ projectKey?: string;
15
+ }
16
+ /** Result of a callWithPayment() client operation. */
17
+ interface CallWithPaymentResult<TResponseBody = unknown> {
18
+ response: TResponseBody;
19
+ txHash?: string;
20
+ paymentHeader?: PaymentHeaderBase64;
21
+ paymentRequirements?: PaymentRequirements;
22
+ }
23
+ /** Shape of the client instance returned by createPaymentClient. */
24
+ interface PaymentClient {
25
+ callWithPayment<TBody = unknown, TResp = unknown>(path: string, options?: {
26
+ method?: "GET" | "POST" | "PUT" | "DELETE";
27
+ body?: TBody;
28
+ headers?: Record<string, string>;
29
+ /**
30
+ * Optional override if you want to send less than maxAmountRequired.
31
+ * In most cases you won't need this and will just pay maxAmountRequired.
32
+ */
33
+ valueOverrideAtomic?: string;
34
+ }): Promise<CallWithPaymentResult<TResp>>;
35
+ }
36
+
37
+ /**
38
+ * Configuration for createMantleClient().
39
+ * All fields are optional - the client auto-detects sensible defaults.
40
+ */
41
+ interface MantleClientConfig {
42
+ /** Optional facilitator URL (auto-detects from NEXT_PUBLIC_FACILITATOR_URL or defaults to localhost:8080). */
43
+ facilitatorUrl?: string;
44
+ /** Optional resource URL (defaults to current origin in browser, or empty string for relative paths). */
45
+ resourceUrl?: string;
46
+ /** Function to get user's wallet address (required for payments). */
47
+ getAccount?: () => Promise<string | undefined> | string | undefined;
48
+ /** Function to get wallet provider/client (e.g., viem WalletClient or window.ethereum). */
49
+ getProvider?: () => any;
50
+ /** Optional project key for hosted facilitator billing. */
51
+ projectKey?: string;
52
+ }
53
+ /**
54
+ * Simplified Mantle payment client interface.
55
+ * Provides a clean API for making paid POST requests.
56
+ */
57
+ interface MantleClient {
58
+ /**
59
+ * Make a paid POST request to a protected endpoint.
60
+ * Automatically handles x402 flow (402 response, signing, payment, retry).
61
+ *
62
+ * @param url - API endpoint path (e.g., "/api/generate-image").
63
+ * @param body - Request body (will be JSON stringified).
64
+ * @returns Full payment result including response body and tx hash.
65
+ * @throws Error if wallet is not connected or payment fails.
66
+ */
67
+ postWithPayment<TResp = any>(url: string, body?: any): Promise<CallWithPaymentResult<TResp>>;
68
+ }
69
+ /**
70
+ * Create a simplified Mantle payment client with auto-detected defaults.
71
+ *
72
+ * Usage:
73
+ * ```typescript
74
+ * const client = createMantleClient({
75
+ * getAccount: () => account?.address,
76
+ * getProvider: () => walletClient,
77
+ * });
78
+ *
79
+ * const data = await client.postWithPayment("/api/generate", { prompt: "..." });
80
+ * ```
81
+ *
82
+ * @param config - Optional configuration (auto-detects facilitatorUrl and resourceUrl).
83
+ * @returns MantleClient instance with simplified postWithPayment() method.
84
+ */
85
+ declare function createMantleClient(config?: MantleClientConfig): MantleClient;
86
+
87
+ export { type CallWithPaymentResult as C, type MantleClient as M, type PaymentClientConfig as P, type MantleClientConfig as a, type PaymentClient as b, createMantleClient as c };
@@ -0,0 +1,87 @@
1
+ import { d as PaymentHeaderBase64, P as PaymentRequirements } from './types-BFUqKBBO.js';
2
+
3
+ /** Config for the client-side payment helper. */
4
+ interface PaymentClientConfig {
5
+ /** Base URL of your protected resource server. */
6
+ resourceUrl: string;
7
+ /** Facilitator URL (hosted or self-hosted). */
8
+ facilitatorUrl: string;
9
+ /** EIP-1193 provider (window.ethereum) or similar. */
10
+ provider: unknown;
11
+ /** Optional user address override; otherwise derived from provider. */
12
+ userAddress?: string;
13
+ /** Optional: Project key for hosted facilitator billing. */
14
+ projectKey?: string;
15
+ }
16
+ /** Result of a callWithPayment() client operation. */
17
+ interface CallWithPaymentResult<TResponseBody = unknown> {
18
+ response: TResponseBody;
19
+ txHash?: string;
20
+ paymentHeader?: PaymentHeaderBase64;
21
+ paymentRequirements?: PaymentRequirements;
22
+ }
23
+ /** Shape of the client instance returned by createPaymentClient. */
24
+ interface PaymentClient {
25
+ callWithPayment<TBody = unknown, TResp = unknown>(path: string, options?: {
26
+ method?: "GET" | "POST" | "PUT" | "DELETE";
27
+ body?: TBody;
28
+ headers?: Record<string, string>;
29
+ /**
30
+ * Optional override if you want to send less than maxAmountRequired.
31
+ * In most cases you won't need this and will just pay maxAmountRequired.
32
+ */
33
+ valueOverrideAtomic?: string;
34
+ }): Promise<CallWithPaymentResult<TResp>>;
35
+ }
36
+
37
+ /**
38
+ * Configuration for createMantleClient().
39
+ * All fields are optional - the client auto-detects sensible defaults.
40
+ */
41
+ interface MantleClientConfig {
42
+ /** Optional facilitator URL (auto-detects from NEXT_PUBLIC_FACILITATOR_URL or defaults to localhost:8080). */
43
+ facilitatorUrl?: string;
44
+ /** Optional resource URL (defaults to current origin in browser, or empty string for relative paths). */
45
+ resourceUrl?: string;
46
+ /** Function to get user's wallet address (required for payments). */
47
+ getAccount?: () => Promise<string | undefined> | string | undefined;
48
+ /** Function to get wallet provider/client (e.g., viem WalletClient or window.ethereum). */
49
+ getProvider?: () => any;
50
+ /** Optional project key for hosted facilitator billing. */
51
+ projectKey?: string;
52
+ }
53
+ /**
54
+ * Simplified Mantle payment client interface.
55
+ * Provides a clean API for making paid POST requests.
56
+ */
57
+ interface MantleClient {
58
+ /**
59
+ * Make a paid POST request to a protected endpoint.
60
+ * Automatically handles x402 flow (402 response, signing, payment, retry).
61
+ *
62
+ * @param url - API endpoint path (e.g., "/api/generate-image").
63
+ * @param body - Request body (will be JSON stringified).
64
+ * @returns Full payment result including response body and tx hash.
65
+ * @throws Error if wallet is not connected or payment fails.
66
+ */
67
+ postWithPayment<TResp = any>(url: string, body?: any): Promise<CallWithPaymentResult<TResp>>;
68
+ }
69
+ /**
70
+ * Create a simplified Mantle payment client with auto-detected defaults.
71
+ *
72
+ * Usage:
73
+ * ```typescript
74
+ * const client = createMantleClient({
75
+ * getAccount: () => account?.address,
76
+ * getProvider: () => walletClient,
77
+ * });
78
+ *
79
+ * const data = await client.postWithPayment("/api/generate", { prompt: "..." });
80
+ * ```
81
+ *
82
+ * @param config - Optional configuration (auto-detects facilitatorUrl and resourceUrl).
83
+ * @returns MantleClient instance with simplified postWithPayment() method.
84
+ */
85
+ declare function createMantleClient(config?: MantleClientConfig): MantleClient;
86
+
87
+ export { type CallWithPaymentResult as C, type MantleClient as M, type PaymentClientConfig as P, type MantleClientConfig as a, type PaymentClient as b, createMantleClient as c };
@@ -0,0 +1,66 @@
1
+ import { Request, Response, NextFunction } from 'express';
2
+ import { b as RoutesConfig, M as MinimalPaywallOptions } from './types-xkNm0uzE.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). */
13
+ receiverAddress: `0x${string}`;
14
+ /** Map of protected routes and their pricing. */
15
+ routes: RoutesConfig;
16
+ /**
17
+ * Optional hook called whenever a payment is successfully settled.
18
+ */
19
+ onPaymentSettled?: MinimalPaywallOptions["onPaymentSettled"];
20
+ /** Optional: Send usage telemetry for billing/analytics. */
21
+ telemetry?: MinimalPaywallOptions["telemetry"];
22
+ }
23
+ /**
24
+ * Create Express middleware for x402 payment verification on multiple routes.
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * const middleware = createPaymentMiddleware({
29
+ * facilitatorUrl: 'https://facilitator.nosubs.ai',
30
+ * receiverAddress: '0x...',
31
+ * routes: {
32
+ * 'POST /api/generate': { priceUsdCents: 1, network: 'mantle-mainnet' },
33
+ * 'GET /api/data': { priceUsdCents: 5, network: 'mantle-mainnet' },
34
+ * }
35
+ * });
36
+ *
37
+ * app.use(middleware);
38
+ * ```
39
+ */
40
+ declare function createPaymentMiddleware(config: PaymentMiddlewareConfig): MantleMiddleware;
41
+ /**
42
+ * Simplified wrapper for protecting a single route with x402 payments.
43
+ * Uses Mantle mainnet defaults (USDC, exact scheme, etc.).
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * const pay = mantlePaywall({ priceUsd: 0.01, payTo: "0x..." });
48
+ * app.post('/api/generate', pay, async (req, res) => {
49
+ * // Your handler code here
50
+ * });
51
+ * ```
52
+ *
53
+ * @param opts - Minimal configuration (price, payTo, optional facilitator/telemetry).
54
+ * @returns Express middleware function for single-route protection.
55
+ */
56
+ declare function mantlePaywall(opts: MinimalPaywallOptions): MantleMiddleware;
57
+
58
+ type express_MantleMiddleware = MantleMiddleware;
59
+ type express_PaymentMiddlewareConfig = PaymentMiddlewareConfig;
60
+ declare const express_createPaymentMiddleware: typeof createPaymentMiddleware;
61
+ declare const express_mantlePaywall: typeof mantlePaywall;
62
+ declare namespace express {
63
+ export { type express_MantleMiddleware as MantleMiddleware, type express_PaymentMiddlewareConfig as PaymentMiddlewareConfig, express_createPaymentMiddleware as createPaymentMiddleware, express_mantlePaywall as mantlePaywall };
64
+ }
65
+
66
+ export { type MantleMiddleware as M, type PaymentMiddlewareConfig as P, createPaymentMiddleware as c, express as e, mantlePaywall as m };
@@ -0,0 +1,66 @@
1
+ import { Request, Response, NextFunction } from 'express';
2
+ import { b as RoutesConfig, M as MinimalPaywallOptions } from './types-C7EPJ6Hd.js';
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). */
13
+ receiverAddress: `0x${string}`;
14
+ /** Map of protected routes and their pricing. */
15
+ routes: RoutesConfig;
16
+ /**
17
+ * Optional hook called whenever a payment is successfully settled.
18
+ */
19
+ onPaymentSettled?: MinimalPaywallOptions["onPaymentSettled"];
20
+ /** Optional: Send usage telemetry for billing/analytics. */
21
+ telemetry?: MinimalPaywallOptions["telemetry"];
22
+ }
23
+ /**
24
+ * Create Express middleware for x402 payment verification on multiple routes.
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * const middleware = createPaymentMiddleware({
29
+ * facilitatorUrl: 'https://facilitator.nosubs.ai',
30
+ * receiverAddress: '0x...',
31
+ * routes: {
32
+ * 'POST /api/generate': { priceUsdCents: 1, network: 'mantle-mainnet' },
33
+ * 'GET /api/data': { priceUsdCents: 5, network: 'mantle-mainnet' },
34
+ * }
35
+ * });
36
+ *
37
+ * app.use(middleware);
38
+ * ```
39
+ */
40
+ declare function createPaymentMiddleware(config: PaymentMiddlewareConfig): MantleMiddleware;
41
+ /**
42
+ * Simplified wrapper for protecting a single route with x402 payments.
43
+ * Uses Mantle mainnet defaults (USDC, exact scheme, etc.).
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * const pay = mantlePaywall({ priceUsd: 0.01, payTo: "0x..." });
48
+ * app.post('/api/generate', pay, async (req, res) => {
49
+ * // Your handler code here
50
+ * });
51
+ * ```
52
+ *
53
+ * @param opts - Minimal configuration (price, payTo, optional facilitator/telemetry).
54
+ * @returns Express middleware function for single-route protection.
55
+ */
56
+ declare function mantlePaywall(opts: MinimalPaywallOptions): MantleMiddleware;
57
+
58
+ type express_MantleMiddleware = MantleMiddleware;
59
+ type express_PaymentMiddlewareConfig = PaymentMiddlewareConfig;
60
+ declare const express_createPaymentMiddleware: typeof createPaymentMiddleware;
61
+ declare const express_mantlePaywall: typeof mantlePaywall;
62
+ declare namespace express {
63
+ export { type express_MantleMiddleware as MantleMiddleware, type express_PaymentMiddlewareConfig as PaymentMiddlewareConfig, express_createPaymentMiddleware as createPaymentMiddleware, express_mantlePaywall as mantlePaywall };
64
+ }
65
+
66
+ export { type MantleMiddleware as M, type PaymentMiddlewareConfig as P, createPaymentMiddleware as c, express as e, mantlePaywall as m };
@@ -0,0 +1,66 @@
1
+ import { Request, Response, NextFunction } from 'express';
2
+ import { b as RoutesConfig, M as MinimalPaywallOptions } from './types-CqQ6OgRi.js';
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
+ /**
17
+ * Optional hook called whenever a payment is successfully settled.
18
+ */
19
+ onPaymentSettled?: MinimalPaywallOptions["onPaymentSettled"];
20
+ /** Optional: Send usage telemetry for billing/analytics. */
21
+ telemetry?: MinimalPaywallOptions["telemetry"];
22
+ }
23
+ /**
24
+ * Create Express middleware for x402 payment verification on multiple routes.
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * const middleware = createPaymentMiddleware({
29
+ * facilitatorUrl: 'https://facilitator.nosubs.ai',
30
+ * receiverAddress: '0x...',
31
+ * routes: {
32
+ * 'POST /api/generate': { priceUsdCents: 1, network: 'mantle-mainnet' },
33
+ * 'GET /api/data': { priceUsdCents: 5, network: 'mantle-mainnet' },
34
+ * }
35
+ * });
36
+ *
37
+ * app.use(middleware);
38
+ * ```
39
+ */
40
+ declare function createPaymentMiddleware(config: PaymentMiddlewareConfig): MantleMiddleware;
41
+ /**
42
+ * Simplified wrapper for protecting a single route with x402 payments.
43
+ * Uses Mantle mainnet defaults (USDC, exact scheme, etc.).
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * const pay = mantlePaywall({ priceUsd: 0.01, payTo: "0x..." });
48
+ * app.post('/api/generate', pay, async (req, res) => {
49
+ * // Your handler code here
50
+ * });
51
+ * ```
52
+ *
53
+ * @param opts - Minimal configuration (price, payTo, optional facilitator/telemetry).
54
+ * @returns Express middleware function for single-route protection.
55
+ */
56
+ declare function mantlePaywall(opts: MinimalPaywallOptions): MantleMiddleware;
57
+
58
+ type express_MantleMiddleware = MantleMiddleware;
59
+ type express_PaymentMiddlewareConfig = PaymentMiddlewareConfig;
60
+ declare const express_createPaymentMiddleware: typeof createPaymentMiddleware;
61
+ declare const express_mantlePaywall: typeof mantlePaywall;
62
+ declare namespace express {
63
+ export { type express_MantleMiddleware as MantleMiddleware, type express_PaymentMiddlewareConfig as PaymentMiddlewareConfig, express_createPaymentMiddleware as createPaymentMiddleware, express_mantlePaywall as mantlePaywall };
64
+ }
65
+
66
+ export { type MantleMiddleware as M, type PaymentMiddlewareConfig as P, createPaymentMiddleware as c, express as e, mantlePaywall as m };