{"_id":"@aeon-ai-pay/next","name":"@aeon-ai-pay/next","dist-tags":{"latest":"2.1.0"},"versions":{"2.1.0":{"name":"@aeon-ai-pay/next","version":"2.1.0","main":"./dist/cjs/index.js","module":"./dist/esm/index.js","types":"./dist/index.d.ts","keywords":[],"license":"Apache-2.0","author":{"name":"Coinbase Inc."},"repository":{"type":"git","url":"git+https://github.com/coinbase/x402.git"},"description":"x402 Payment Protocol","devDependencies":{"@eslint/js":"^9.24.0","@types/node":"^22.13.4","@typescript-eslint/eslint-plugin":"^8.29.1","@typescript-eslint/parser":"^8.29.1","eslint":"^9.24.0","eslint-plugin-import":"^2.31.0","eslint-plugin-jsdoc":"^50.6.9","eslint-plugin-prettier":"^5.2.6","prettier":"3.5.2","tsup":"^8.4.0","tsx":"^4.19.2","typescript":"^5.7.3","vite":"^6.2.6","vite-tsconfig-paths":"^5.1.4","vitest":"^3.0.5"},"dependencies":{"@coinbase/cdp-sdk":"^1.22.0","zod":"^3.24.2","@aeon-ai-pay/core":"^2.1.0","@aeon-ai-pay/extensions":"^2.1.0"},"peerDependencies":{"next":"^16.0.10","@aeon-ai-pay/paywall":"2.1.0"},"peerDependenciesMeta":{"@aeon-ai-pay/paywall":{"optional":true}},"type":"module","exports":{".":{"import":{"types":"./dist/esm/index.d.ts","default":"./dist/esm/index.js"},"require":{"types":"./dist/cjs/index.d.cts","default":"./dist/cjs/index.cjs"}}},"publishConfig":{"access":"public"},"scripts":{"start":"tsx --env-file=.env index.ts","test":"vitest run","test:watch":"vitest","build":"tsup","watch":"tsc --watch","format":"prettier -c .prettierrc --write \"**/*.{ts,js,cjs,json,md}\"","format:check":"prettier -c .prettierrc --check \"**/*.{ts,js,cjs,json,md}\"","lint":"eslint . --ext .ts --fix","lint:check":"eslint . --ext .ts"},"_id":"@aeon-ai-pay/next@2.1.0","bugs":{"url":"https://github.com/coinbase/x402/issues"},"homepage":"https://github.com/coinbase/x402#readme","_integrity":"sha512-W7Pc7McWt8hq9HBMHAwuPFraAk8aTwK3TPDl0o5p5Lx4Vv4NWK7ryakSrztRQnppYFQeY5VhBG3VzbtoDcGSlQ==","_resolved":"/private/var/folders/rr/hyts0bs54zn73fgjjlld0tvm0000gn/T/23d85a9d2de041769e58ada2af60cf6b/aeon-ai-pay-next-2.1.0.tgz","_from":"file:aeon-ai-pay-next-2.1.0.tgz","_nodeVersion":"25.8.1","_npmVersion":"11.11.0","dist":{"integrity":"sha512-W7Pc7McWt8hq9HBMHAwuPFraAk8aTwK3TPDl0o5p5Lx4Vv4NWK7ryakSrztRQnppYFQeY5VhBG3VzbtoDcGSlQ==","shasum":"5d6832c3209e7fd6d8425e41b210780e9da5faba","tarball":"https://registry.npmjs.org/@aeon-ai-pay/next/-/next-2.1.0.tgz","fileCount":8,"unpackedSize":90442,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIFCaZbdD7nOvR1MxKn5WEsa407DJudOr+ozzrI358qAVAiEA1cgWi0ipy8Tb0hG8szOMILUeUpb048e6wm+O96Oo2tI="}]},"_npmUser":{"name":"aeon_project","email":"code@alchemypay.org"},"directories":{},"maintainers":[{"name":"aeon_project","email":"code@alchemypay.org"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/next_2.1.0_1775096349045_0.4268503703804045"},"_hasShrinkwrap":false}},"time":{"created":"2026-04-02T02:19:08.959Z","2.1.0":"2026-04-02T02:19:09.205Z","modified":"2026-04-02T02:19:09.399Z"},"maintainers":[{"name":"aeon_project","email":"code@alchemypay.org"}],"description":"x402 Payment Protocol","homepage":"https://github.com/coinbase/x402#readme","keywords":[],"repository":{"type":"git","url":"git+https://github.com/coinbase/x402.git"},"author":{"name":"Coinbase Inc."},"bugs":{"url":"https://github.com/coinbase/x402/issues"},"license":"Apache-2.0","readme":"# @x402/next\n\nNext.js integration for the x402 Payment Protocol. This package allows you to easily add paywall functionality to your Next.js applications using the x402 protocol.\n\n## Installation\n\n```bash\npnpm install @x402/next\n```\n\n## Quick Start\n\n### Protecting Page Routes\n\nPage routes are protected using the `paymentProxy`. Create a proxy (middleware) file in your Next.js project (`proxy.ts`):\n\n```typescript\nimport { paymentProxy, x402ResourceServer } from \"@x402/next\";\nimport { HTTPFacilitatorClient } from \"@x402/core/server\";\nimport { ExactEvmScheme } from \"@x402/evm/exact/server\";\n\nconst facilitatorClient = new HTTPFacilitatorClient({ url: \"https://facilitator.x402.org\" });\nconst resourceServer = new x402ResourceServer(facilitatorClient)\n  .register(\"eip155:84532\", new ExactEvmScheme());\n\nexport const proxy = paymentProxy(\n  {\n    \"/protected\": {\n      accepts: {\n        scheme: \"exact\",\n        price: \"$0.01\",\n        network: \"eip155:84532\",\n        payTo: \"0xYourAddress\",\n      },\n      description: \"Access to protected content\",\n    },\n  },\n  resourceServer,\n);\n\n// Configure which paths the middleware should run on\nexport const config = {\n  matcher: [\"/protected/:path*\"],\n};\n```\n\n### Protecting API Routes\n\nAPI routes are protected using the `withX402` route wrapper. This is the recommended approach to protect API routes as it guarantees payment settlement only AFTER successful API responses (status < 400). API routes can also be protected by `paymentProxy`, however this will charge clients for failed API responses:\n\n```typescript\n// app/api/your-endpoint/route.ts\nimport { NextRequest, NextResponse } from \"next/server\";\nimport { withX402 } from \"@x402/next\";\n\nconst handler = async (_: NextRequest) => {\n  return NextResponse.json({ data: \"your response\" });\n};\n\nexport const GET = withX402(\n  handler,\n  {\n    accepts: {\n      scheme: \"exact\",\n      price: \"$0.01\",\n      network: \"eip155:84532\",\n      payTo: \"0xYourAddress\",\n    },\n    description: \"Access to API endpoint\",\n  },\n  server, // your configured x402ResourceServer\n);\n```\n\n## Configuration\n\n### paymentProxy\n\nThe `paymentProxy` function is used to protect page routes. It can also protect API routes, however this will charge clients for failed API responses.\n\n```typescript\npaymentProxy(\n  routes: RoutesConfig,\n  server: x402ResourceServer,\n  paywallConfig?: PaywallConfig,\n  paywall?: PaywallProvider,\n  syncFacilitatorOnStart?: boolean\n)\n```\n\n#### Parameters\n\n1. **`routes`** (required): Route configurations for protected endpoints\n2. **`server`** (required): Pre-configured x402ResourceServer instance\n3. **`paywallConfig`** (optional): Configuration for the built-in paywall UI\n4. **`paywall`** (optional): Custom paywall provider\n5. **`syncFacilitatorOnStart`** (optional): Whether to sync with facilitator on startup (defaults to true)\n\n### withX402\n\nThe `withX402` function wraps API route handlers. This is the recommended approach to protect API routes as it guarantees payment settlement only AFTER successful API responses (status < 400).\n\n```typescript\nwithX402(\n  routeHandler: (request: NextRequest) => Promise<NextResponse>,\n  routeConfig: RouteConfig,\n  server: x402ResourceServer,\n  paywallConfig?: PaywallConfig,\n  paywall?: PaywallProvider,\n  syncFacilitatorOnStart?: boolean\n)\n```\n\n#### Parameters\n\n1. **`routeHandler`** (required): Your API route handler function\n2. **`routeConfig`** (required): Payment configuration for this specific route\n3. **`server`** (required): Pre-configured x402ResourceServer instance\n4. **`paywallConfig`** (optional): Configuration for the built-in paywall UI\n5. **`paywall`** (optional): Custom paywall provider\n6. **`syncFacilitatorOnStart`** (optional): Whether to sync with facilitator on startup (defaults to true)\n\n## API Reference\n\n### NextAdapter\n\nThe `NextAdapter` class implements the `HTTPAdapter` interface from `@x402/core`, providing Next.js-specific request handling:\n\n```typescript\nclass NextAdapter implements HTTPAdapter {\n  getHeader(name: string): string | undefined;\n  getMethod(): string;\n  getPath(): string;\n  getUrl(): string;\n  getAcceptHeader(): string;\n  getUserAgent(): string;\n}\n```\n\n### Route Configuration\n\n```typescript\nconst routes: RoutesConfig = {\n  \"/api/protected\": {\n    accepts: {\n      scheme: \"exact\",\n      price: \"$0.10\",\n      network: \"eip155:84532\",\n      payTo: \"0xYourAddress\",\n      maxTimeoutSeconds: 60,\n    },\n    description: \"Premium API access\",\n  },\n};\n```\n\n## Advanced Usage\n\n### Multiple Payment Networks\n\n```typescript\nimport { paymentProxy, x402ResourceServer } from \"@x402/next\";\nimport { HTTPFacilitatorClient } from \"@x402/core/server\";\nimport { registerExactEvmScheme } from \"@x402/evm/exact/server\";\nimport { registerExactSvmScheme } from \"@x402/svm/exact/server\";\n\nconst facilitatorClient = new HTTPFacilitatorClient({ url: facilitatorUrl });\nconst server = new x402ResourceServer(facilitatorClient);\n\nregisterExactEvmScheme(server);\nregisterExactSvmScheme(server);\n\nexport const middleware = paymentProxy(\n  {\n    \"/protected\": {\n      accepts: [\n        {\n          scheme: \"exact\",\n          price: \"$0.001\",\n          network: \"eip155:84532\",\n          payTo: evmAddress,\n        },\n        {\n          scheme: \"exact\",\n          price: \"$0.001\",\n          network: \"solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1\",\n          payTo: svmAddress,\n        },\n      ],\n      description: \"Premium content\",\n      mimeType: \"text/html\",\n    },\n  },\n  server,\n);\n```\n\n### Custom Paywall\n\n```typescript\nimport { createPaywall } from \"@x402/paywall\";\nimport { evmPaywall } from \"@x402/paywall/evm\";\nimport { svmPaywall } from \"@x402/paywall/svm\";\n\nconst paywall = createPaywall()\n  .withNetwork(evmPaywall)\n  .withNetwork(svmPaywall)\n  .withConfig({\n    appName: \"My App\",\n    appLogo: \"/logo.png\",\n    testnet: true,\n  })\n  .build();\n\nexport const middleware = paymentProxy(\n  routes,\n  server,\n  undefined, // paywallConfig (using custom paywall instead)\n  paywall,\n);\n```\n## Migration from x402-next\n\nIf you're migrating from the legacy `x402-next` package:\n\n1. **Update imports**: Change from `x402-next` to `@x402/next`\n2. **New API**: Create an x402ResourceServer and register payment schemes\n3. **Function rename**: `paymentMiddleware` is now `paymentProxy`\n4. **Parameter order**: Routes first, then resource server\n\n### Before (x402-next):\n\n```typescript\nimport { paymentMiddleware } from \"x402-next\";\n\nexport const middleware = paymentMiddleware(\n  \"0xYourAddress\",\n  {\n    \"/protected\": {\n      price: \"$0.01\",\n      network: \"base-sepolia\",\n      config: { description: \"Access to protected content\" },\n    },\n  },\n  facilitator,\n  paywall,\n);\n```\n\n### After (@x402/next):\n\n```typescript\nimport { paymentProxy, x402ResourceServer } from \"@x402/next\";\nimport { HTTPFacilitatorClient } from \"@x402/core/server\";\nimport { ExactEvmScheme } from \"@x402/evm/exact/server\";\n\nconst facilitator = new HTTPFacilitatorClient({ url: facilitatorUrl });\nconst resourceServer = new x402ResourceServer(facilitator)\n  .register(\"eip155:84532\", new ExactEvmScheme());\n\nexport const middleware = paymentProxy(\n  {\n    \"/protected\": {\n      accepts: {\n        scheme: \"exact\",\n        price: \"$0.01\",\n        network: \"eip155:84532\",\n        payTo: \"0xYourAddress\",\n      },\n      description: \"Access to protected content\",\n    },\n  },\n  resourceServer,\n);\n```\n\nNote: The `payTo` address is now specified within each route configuration rather than as a separate parameter.\n\n","readmeFilename":"README.md","_rev":"1-f6e94f4c110f70e2d9a98ad311170ec6"}