@alleyboss/micropay-solana-x402-paywall 3.0.2 → 3.0.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.
package/README.md CHANGED
@@ -60,26 +60,27 @@ app.get('/premium', x402Middleware(server, {
60
60
 
61
61
  ## 📦 Next.js (App Router)
62
62
 
63
- Use the official `@x402/next` adapter with our session management:
64
-
65
63
  ```typescript
66
64
  // app/api/premium/route.ts
67
- import { withX402 } from '@x402/next';
68
- import { x402ResourceServer } from '@x402/core/server';
65
+ import { createX402Middleware } from '@alleyboss/micropay-solana-x402-paywall/next';
69
66
 
70
- const server = new x402ResourceServer({ ... });
67
+ const withMicropay = createX402Middleware({
68
+ walletAddress: 'YOUR_WALLET_ADDRESS',
69
+ network: 'devnet'
70
+ });
71
71
 
72
72
  const handler = (req) => {
73
- return Response.json({ content: "Premium Data" });
73
+ return Response.json({ content: "Premium Data" });
74
74
  };
75
75
 
76
- export const GET = withX402(handler, {
77
- accepts: {
78
- scheme: 'exact',
79
- amount: '1000000',
80
- network: 'solana-mainnet'
81
- }
82
- }, server);
76
+ // Protect the route
77
+ export const GET = withMicropay(handler, {
78
+ description: "Unlock Premium Content",
79
+ accepts: {
80
+ amount: "1000000", // 0.001 SOL
81
+ scheme: "exact"
82
+ }
83
+ });
83
84
  ```
84
85
 
85
86
  ## 🔧 Modules
@@ -0,0 +1,34 @@
1
+ 'use strict';
2
+
3
+ var next = require('@x402/next');
4
+ var server = require('@x402/core/server');
5
+ var http = require('@x402/core/http');
6
+ var server$1 = require('@x402/svm/exact/server');
7
+
8
+ // src/next/index.ts
9
+ function createX402Middleware(config) {
10
+ const facilitatorUrl = config.facilitatorUrl || "https://x402.org/facilitator";
11
+ const client = new http.HTTPFacilitatorClient({ url: facilitatorUrl });
12
+ const server$2 = new server.x402ResourceServer(client);
13
+ server$1.registerExactSvmScheme(server$2, {});
14
+ return function withMicropay(handler, routeConfig) {
15
+ const finalConfig = routeConfig || {
16
+ accepts: {
17
+ scheme: "exact",
18
+ payTo: config.walletAddress,
19
+ maxAmountRequired: config.price?.toString() || "0",
20
+ network: config.network === "mainnet-beta" ? "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp" : "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1",
21
+ asset: "native"
22
+ }
23
+ };
24
+ return next.withX402(handler, finalConfig, server$2);
25
+ };
26
+ }
27
+ var withX402 = next.withX402;
28
+
29
+ Object.defineProperty(exports, "x402ResourceServer", {
30
+ enumerable: true,
31
+ get: function () { return server.x402ResourceServer; }
32
+ });
33
+ exports.createX402Middleware = createX402Middleware;
34
+ exports.withX402 = withX402;
@@ -0,0 +1,24 @@
1
+ import * as next_server from 'next/server';
2
+ import { withX402 as withX402$1 } from '@x402/next';
3
+ export { x402ResourceServer } from '@x402/core/server';
4
+
5
+ /**
6
+ * Configuration for the x402 middleware
7
+ */
8
+ interface X402Config {
9
+ /** x402 Facilitator URL (default: x402.org) */
10
+ facilitatorUrl?: string;
11
+ /** Wallet address to receive payments */
12
+ walletAddress: string;
13
+ /** Price in lamports (string or number) */
14
+ price?: string | number;
15
+ /** Network (mainnet-beta or devnet) */
16
+ network?: 'mainnet-beta' | 'devnet';
17
+ }
18
+ /**
19
+ * Create a specialized Next.js middleware with Solana support pre-configured
20
+ */
21
+ declare function createX402Middleware(config: X402Config): (handler: any, routeConfig?: any) => (request: next_server.NextRequest) => Promise<next_server.NextResponse<unknown>>;
22
+ declare const withX402: typeof withX402$1;
23
+
24
+ export { type X402Config, createX402Middleware, withX402 };
@@ -0,0 +1,24 @@
1
+ import * as next_server from 'next/server';
2
+ import { withX402 as withX402$1 } from '@x402/next';
3
+ export { x402ResourceServer } from '@x402/core/server';
4
+
5
+ /**
6
+ * Configuration for the x402 middleware
7
+ */
8
+ interface X402Config {
9
+ /** x402 Facilitator URL (default: x402.org) */
10
+ facilitatorUrl?: string;
11
+ /** Wallet address to receive payments */
12
+ walletAddress: string;
13
+ /** Price in lamports (string or number) */
14
+ price?: string | number;
15
+ /** Network (mainnet-beta or devnet) */
16
+ network?: 'mainnet-beta' | 'devnet';
17
+ }
18
+ /**
19
+ * Create a specialized Next.js middleware with Solana support pre-configured
20
+ */
21
+ declare function createX402Middleware(config: X402Config): (handler: any, routeConfig?: any) => (request: next_server.NextRequest) => Promise<next_server.NextResponse<unknown>>;
22
+ declare const withX402: typeof withX402$1;
23
+
24
+ export { type X402Config, createX402Middleware, withX402 };
@@ -0,0 +1,28 @@
1
+ import { withX402 as withX402$1 } from '@x402/next';
2
+ import { x402ResourceServer } from '@x402/core/server';
3
+ export { x402ResourceServer } from '@x402/core/server';
4
+ import { HTTPFacilitatorClient } from '@x402/core/http';
5
+ import { registerExactSvmScheme } from '@x402/svm/exact/server';
6
+
7
+ // src/next/index.ts
8
+ function createX402Middleware(config) {
9
+ const facilitatorUrl = config.facilitatorUrl || "https://x402.org/facilitator";
10
+ const client = new HTTPFacilitatorClient({ url: facilitatorUrl });
11
+ const server = new x402ResourceServer(client);
12
+ registerExactSvmScheme(server, {});
13
+ return function withMicropay(handler, routeConfig) {
14
+ const finalConfig = routeConfig || {
15
+ accepts: {
16
+ scheme: "exact",
17
+ payTo: config.walletAddress,
18
+ maxAmountRequired: config.price?.toString() || "0",
19
+ network: config.network === "mainnet-beta" ? "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp" : "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1",
20
+ asset: "native"
21
+ }
22
+ };
23
+ return withX402$1(handler, finalConfig, server);
24
+ };
25
+ }
26
+ var withX402 = withX402$1;
27
+
28
+ export { createX402Middleware, withX402 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alleyboss/micropay-solana-x402-paywall",
3
- "version": "3.0.2",
3
+ "version": "3.0.3",
4
4
  "description": "Production-ready Solana micropayments library wrapper for official x402 SDK",
5
5
  "author": "AlleyBoss",
6
6
  "license": "MIT",
@@ -42,6 +42,16 @@
42
42
  "default": "./dist/express/index.cjs"
43
43
  }
44
44
  },
45
+ "./next": {
46
+ "import": {
47
+ "types": "./dist/next/index.d.ts",
48
+ "default": "./dist/next/index.js"
49
+ },
50
+ "require": {
51
+ "types": "./dist/next/index.d.cts",
52
+ "default": "./dist/next/index.cjs"
53
+ }
54
+ },
45
55
  "./agent": {
46
56
  "import": {
47
57
  "types": "./dist/agent/index.d.ts",
@@ -99,6 +109,7 @@
99
109
  },
100
110
  "dependencies": {
101
111
  "@x402/core": "^2.1.0",
112
+ "@x402/next": "^2.1.0",
102
113
  "@x402/svm": "^2.1.0",
103
114
  "jose": "^6.1.3"
104
115
  },