{"_id":"@bit-gpt/h402-proxy","_rev":"2-460dd0af2405e630a36bc5d1e2c1d715","name":"@bit-gpt/h402-proxy","dist-tags":{"latest":"0.0.3"},"versions":{"0.0.2":{"name":"@bit-gpt/h402-proxy","version":"0.0.2","keywords":["h402","proxy","payment","middleware","express","api","monetization"],"author":{"name":"BitGPT"},"license":"Apache-2.0","_id":"@bit-gpt/h402-proxy@0.0.2","maintainers":[{"name":"bit-gpt","email":"dan@bitgpt.xyz"}],"homepage":"https://github.com/bit-gpt/h402#readme","bugs":{"url":"https://github.com/bit-gpt/h402/issues"},"dist":{"shasum":"fa61e76710e3c711c7eeeda908e02c2385ca316c","tarball":"https://registry.npmjs.org/@bit-gpt/h402-proxy/-/h402-proxy-0.0.2.tgz","fileCount":9,"integrity":"sha512-nWKIepz7VBtkJ400qrg/AKai9ipESJeBfI47Nk4gaB5mLJSZp0+NI/E02csK95Un1u5fs6nQwAIRjVnh9/IZyg==","signatures":[{"sig":"MEUCIQCD9B8XW0tg/U8EnkAKDG53GK9YFCB/7tst5wwlfcmARQIgaxiR6bC7N//Kl08anvxMwm1g00yJXKnNhZ3O6pV+YxE=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":48807},"main":"./dist/cjs/index.js","_from":"file:bit-gpt-h402-proxy-0.0.2.tgz","types":"./dist/index.d.ts","module":"./dist/esm/index.js","exports":{".":{"import":{"types":"./dist/esm/index.d.mts","default":"./dist/esm/index.mjs"},"require":{"types":"./dist/cjs/index.d.ts","default":"./dist/cjs/index.js"}}},"scripts":{"lint":"eslint . --ext .ts --fix","build":"tsup","start":"tsx --env-file=.env index.ts","watch":"tsc --watch","format":"prettier -c .prettierrc --write \"**/*.{ts,js,cjs,json,md}\"","lint:check":"eslint . --ext .ts","format:check":"prettier -c .prettierrc --check \"**/*.{ts,js,cjs,json,md}\""},"_npmUser":{"name":"bit-gpt","email":"dan@bitgpt.xyz"},"_resolved":"/tmp/c89d6678511b220ea9a5ab3c388d5033/bit-gpt-h402-proxy-0.0.2.tgz","_integrity":"sha512-nWKIepz7VBtkJ400qrg/AKai9ipESJeBfI47Nk4gaB5mLJSZp0+NI/E02csK95Un1u5fs6nQwAIRjVnh9/IZyg==","repository":{"url":"git+https://github.com/bit-gpt/h402.git","type":"git"},"_npmVersion":"10.9.4","description":"h402 Payment Protocol proxy middleware for Express - monetize any API with crypto payments","directories":{},"_nodeVersion":"22.21.0","dependencies":{"zod":"^3.24.2","express":"^4.18.2","@bit-gpt/h402":"^0.0.21","@bit-gpt/h402-express":"0.0.7","http-proxy-middleware":"^3.0.0"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.19.2","tsup":"^8.4.0","vite":"^6.2.6","eslint":"^9.24.0","prettier":"3.5.2","@eslint/js":"^9.24.0","typescript":"^5.7.3","@types/node":"^22.13.4","@types/express":"^5.0.1","eslint-plugin-jsdoc":"^50.6.9","vite-tsconfig-paths":"^5.1.4","eslint-plugin-import":"^2.31.0","eslint-plugin-prettier":"^5.2.6","@typescript-eslint/parser":"^8.29.1","@typescript-eslint/eslint-plugin":"^8.29.1"},"_npmOperationalInternal":{"tmp":"tmp/h402-proxy_0.0.2_1761488885209_0.816047164812898","host":"s3://npm-registry-packages-npm-production"}},"0.0.3":{"name":"@bit-gpt/h402-proxy","version":"0.0.3","main":"./dist/cjs/index.js","module":"./dist/esm/index.js","types":"./dist/index.d.ts","keywords":["h402","proxy","payment","middleware","express","api","monetization"],"license":"Apache-2.0","author":{"name":"BitGPT"},"repository":{"type":"git","url":"git+https://github.com/bit-gpt/h402.git"},"description":"h402 Payment Protocol proxy middleware for Express - monetize any API with crypto payments","devDependencies":{"@eslint/js":"^9.24.0","@types/express":"^5.0.1","@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"},"dependencies":{"express":"^4.18.2","http-proxy-middleware":"^3.0.0","zod":"^3.24.2","@bit-gpt/h402":"^0.0.22","@bit-gpt/h402-express":"0.0.8"},"exports":{".":{"import":{"types":"./dist/esm/index.d.mts","default":"./dist/esm/index.mjs"},"require":{"types":"./dist/cjs/index.d.ts","default":"./dist/cjs/index.js"}}},"scripts":{"start":"tsx --env-file=.env index.ts","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":"@bit-gpt/h402-proxy@0.0.3","bugs":{"url":"https://github.com/bit-gpt/h402/issues"},"homepage":"https://github.com/bit-gpt/h402#readme","_integrity":"sha512-YrIETzGD4kYGs1UAiPe/7vDmUs2li+8CE8/tnS4g1ewbY8YRFioMY7IFOUiFb3dyzW+eLPMMG+L1O6+9F0sRGA==","_resolved":"/tmp/1dc1d2583bd239696bc30d7ff9007bd1/bit-gpt-h402-proxy-0.0.3.tgz","_from":"file:bit-gpt-h402-proxy-0.0.3.tgz","_nodeVersion":"22.21.1","_npmVersion":"10.9.4","dist":{"integrity":"sha512-YrIETzGD4kYGs1UAiPe/7vDmUs2li+8CE8/tnS4g1ewbY8YRFioMY7IFOUiFb3dyzW+eLPMMG+L1O6+9F0sRGA==","shasum":"59ef3dd691f5766f0002cd51bf7100211cf292cc","tarball":"https://registry.npmjs.org/@bit-gpt/h402-proxy/-/h402-proxy-0.0.3.tgz","fileCount":9,"unpackedSize":48807,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDBXMoPgqz+3is8sxrUNobGvv5i14l815ltM8J0TmR/CQIgfvDPVKLa8dNQVJNU5MmfdLzKEmdr568n/ynN05dlGq4="}]},"_npmUser":{"name":"bit-gpt","email":"dan@bitgpt.xyz"},"directories":{},"maintainers":[{"name":"bit-gpt","email":"dan@bitgpt.xyz"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/h402-proxy_0.0.3_1762447586582_0.6625319011916977"},"_hasShrinkwrap":false}},"time":{"created":"2025-10-26T14:28:05.085Z","modified":"2025-11-06T16:46:26.966Z","0.0.2":"2025-10-26T14:28:05.424Z","0.0.3":"2025-11-06T16:46:26.776Z"},"bugs":{"url":"https://github.com/bit-gpt/h402/issues"},"author":{"name":"BitGPT"},"license":"Apache-2.0","homepage":"https://github.com/bit-gpt/h402#readme","keywords":["h402","proxy","payment","middleware","express","api","monetization"],"repository":{"type":"git","url":"git+https://github.com/bit-gpt/h402.git"},"description":"h402 Payment Protocol proxy middleware for Express - monetize any API with crypto payments","maintainers":[{"name":"bit-gpt","email":"dan@bitgpt.xyz"}],"readme":"# h402-proxy\n\nExpress middleware integration for the h402 Payment Protocol that enables you to monetize any external API with crypto payments. This package allows you to easily add paywall functionality to external services using the h402 protocol.\n\n## Installation\n\n```bash\nnpm install @bit-gpt/h402-proxy\n```\n\n## Quick Start\n\n```typescript\nimport express from \"express\";\nimport { h402Proxy, createRouteConfigFromPrice } from \"@bit-gpt/h402-proxy\";\n\nconst app = express();\n\n// Proxy to Anthropic Claude with payment protection\napp.use('/claude', h402Proxy({\n  target: 'https://api.anthropic.com',\n  routes: {\n    '/v1/messages': createRouteConfigFromPrice('$0.03', 'base', '0xYourAddress')\n  },\n  headers: {\n    'x-api-key': process.env.ANTHROPIC_KEY\n  }\n}));\n\napp.listen(3000);\n```\n\n## Configuration\n\nThe `h402Proxy` function accepts the following configuration:\n\n### Basic Configuration\n\n```typescript\ninterface ProxyConfig {\n  /** Target URL to proxy requests to */\n  target: string;\n  \n  /** h402 payment configuration for routes */\n  routes: RoutesConfig;\n  \n  /** Headers to inject into proxied requests */\n  headers?: Record<string, string>;\n  \n  /** Proxy-specific options */\n  proxyOptions?: ProxyOptions;\n  \n  /** h402 facilitator configuration */\n  facilitator?: FacilitatorConfig;\n  \n}\n```\n\n### Route Configuration\n\nRoutes are configured using the same pattern as `h402-express`:\n\n```typescript\nimport { createRouteConfigFromPrice } from \"@bit-gpt/h402-proxy\";\n\nconst routes = {\n  // Simple price string\n  '/v1/messages': '$0.03',\n  \n  // Advanced configuration\n  '/v1/chat/completions': createRouteConfigFromPrice('$0.05', 'base', '0xYourAddress'),\n  \n  // Multiple payment options\n  '/premium/*': {\n    paymentRequirements: [\n      {\n        scheme: \"exact\",\n        namespace: \"evm\",\n        tokenAddress: \"0x...\",\n        amountRequired: 0.01,\n        amountRequiredFormat: \"humanReadable\",\n        networkId: \"8453\",\n        payToAddress: \"0x...\",\n        description: \"Premium API access\"\n      }\n    ]\n  }\n};\n```\n\n### Proxy Options\n\n```typescript\ninterface ProxyOptions {\n  /** Change the origin of the host header to the target URL */\n  changeOrigin?: boolean;\n  \n  /** Rewrite the request path before proxying */\n  pathRewrite?: (path: string, req: Request) => string;\n  \n  /** Request timeout in milliseconds (default: 30000) */\n  timeout?: number;\n  \n  /** Follow redirects (default: false) */\n  followRedirects?: boolean;\n  \n  /** Hook called before proxying the request */\n  onProxyReq?: (proxyReq: ClientRequest, req: Request, res: Response) => void;\n  \n  /** Hook called when proxy response is received */\n  onProxyRes?: (proxyRes: IncomingMessage, req: Request, res: Response) => void;\n  \n  /** Hook called when proxy encounters an error */\n  onError?: (err: Error, req: Request, res: Response) => void;\n}\n```\n\n## Examples\n\n### Anthropic Claude\n\n```typescript\napp.use('/claude', h402Proxy({\n  target: 'https://api.anthropic.com',\n  routes: {\n    '/v1/messages': createRouteConfigFromPrice('$0.03', 'base', YOUR_ADDRESS)\n  },\n  headers: {\n    'x-api-key': process.env.ANTHROPIC_KEY,\n    'anthropic-version': '2023-06-01'\n  }\n}));\n```\n\n### OpenAI\n\n```typescript\napp.use('/openai', h402Proxy({\n  target: 'https://api.openai.com',\n  routes: {\n    '/v1/chat/completions': '$0.05',\n    '/v1/embeddings': '$0.01'\n  },\n  headers: {\n    'Authorization': `Bearer ${process.env.OPENAI_KEY}`\n  },\n  proxyOptions: {\n    timeout: 60000\n  }\n}));\n```\n### Path Rewriting\n\n```typescript\napp.use('/api', h402Proxy({\n  target: 'https://backend.example.com',\n  routes: { '/*': '$0.01' },\n  headers: { 'Authorization': `Bearer ${process.env.SERVICE_KEY}` },\n  proxyOptions: {\n    pathRewrite: (path) => path.replace('/api', '/v2'),\n    timeout: 30000\n  }\n}));\n```\n","readmeFilename":"README.md"}