{"_id":"@blockia-pay/blockia-server-sdk","_rev":"2-ab61a7e5bf11f8a390ffedfec1ed3a9f","name":"@blockia-pay/blockia-server-sdk","dist-tags":{"latest":"0.2.0"},"versions":{"0.1.0":{"name":"@blockia-pay/blockia-server-sdk","version":"0.1.0","_id":"@blockia-pay/blockia-server-sdk@0.1.0","maintainers":[{"name":"blockialabs","email":"kristijan.boshev@blockialabs.com"}],"dist":{"shasum":"25fd778b9183d6756f0477dc380edd31afadf092","tarball":"https://registry.npmjs.org/@blockia-pay/blockia-server-sdk/-/blockia-server-sdk-0.1.0.tgz","fileCount":39,"integrity":"sha512-DoWegIUcuinAX218GCOGLbI27zTisj/7P0ORqP80MYlXbXsOMQWGE+enhtzGuchSiMKGDPBs89V5Ndst9CPhOw==","signatures":[{"sig":"MEQCIC6uCjQ0ie1X574B2Z6R04OFq+tS0oc7QbgOStxs/dqgAiAc170yXslYBYXolYNyZwBsJBE702RxBDxjvXJYC2fdow==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":112770},"main":"./dist/index.js","type":"module","_from":"file:blockia-pay-blockia-server-sdk-0.1.0.tgz","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"}},"private":false,"scripts":{"dev":"tsc -p tsconfig.lib.json --watch","lint":"eslint . --ext .ts --max-warnings 0","test":"echo 'No tests configured for blockia-server-sdk'","build":"tsc -p tsconfig.lib.json","clean":"rm -rf dist","lint:fix":"eslint . --ext .ts --fix","typecheck":"tsc --noEmit"},"_npmUser":{"name":"blockialabs","email":"kristijan.boshev@blockialabs.com"},"_resolved":"/private/var/folders/y3/bl9kqw_510v82kwzjm1sd74m0000gq/T/84cd58e2b43c8e16e4ec3513031cfb9c/blockia-pay-blockia-server-sdk-0.1.0.tgz","_integrity":"sha512-DoWegIUcuinAX218GCOGLbI27zTisj/7P0ORqP80MYlXbXsOMQWGE+enhtzGuchSiMKGDPBs89V5Ndst9CPhOw==","_npmVersion":"10.9.2","description":"Backend SDK for merchants to integrate Blockia Pay X402 protocol into their APIs. Enables pay-per-use endpoints and automatic payment processing.","directories":{},"_nodeVersion":"22.17.1","dependencies":{"zod":"^3.22.4","axios":"^1.6.5","axios-retry":"^4.5.0"},"_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.5.3","@types/node":"^20.11.17","@types/express":"^4.17.21"},"peerDependencies":{"express":"^4.18.0"},"_npmOperationalInternal":{"tmp":"tmp/blockia-server-sdk_0.1.0_1762256667649_0.8154402773846894","host":"s3://npm-registry-packages-npm-production"}},"0.2.0":{"name":"@blockia-pay/blockia-server-sdk","version":"0.2.0","private":false,"type":"module","main":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"}},"scripts":{"build":"tsc -p tsconfig.lib.json","dev":"tsc -p tsconfig.lib.json --watch","clean":"rm -rf dist","typecheck":"tsc --noEmit","lint":"eslint . --ext .ts --max-warnings 0","lint:fix":"eslint . --ext .ts --fix","test":"echo 'No tests configured for blockia-server-sdk'"},"dependencies":{"axios":"^1.6.5","axios-retry":"^4.5.0","zod":"^3.22.4"},"devDependencies":{"@types/express":"^4.17.21","@types/node":"^20.11.17","typescript":"^5.5.3"},"peerDependencies":{"express":"^4.18.0"},"_id":"@blockia-pay/blockia-server-sdk@0.2.0","gitHead":"7952cd6e5c1cd3ba44b380b489ad125b87943726","description":"Backend SDK for merchants to integrate Blockia Pay X402 protocol into their APIs. Enables pay-per-use endpoints and automatic payment processing.","_nodeVersion":"22.15.1","_npmVersion":"10.9.2","dist":{"integrity":"sha512-Qo4zjdSCvuXO21rDaA/o9ATyMsCsJUpLeyDUVbVjEYFQEwT7usTacIz6lQ5RqsKkCf6Jaf5OUiKNlF29ufl2DQ==","shasum":"f64d47b78989611a216ed1da5cbe5154f62a9bab","tarball":"https://registry.npmjs.org/@blockia-pay/blockia-server-sdk/-/blockia-server-sdk-0.2.0.tgz","fileCount":38,"unpackedSize":112487,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQC6ONNthby61xMIhL4vfg5W/z7qqq30AnmL/Z4HD77cfwIhAKUb+4fnjyP96HW5rm4GOB9hqpqsVGkIs67xjMdMOru0"}]},"_npmUser":{"name":"blockialabs","email":"kristijan.boshev@blockialabs.com"},"directories":{},"maintainers":[{"name":"blockialabs","email":"kristijan.boshev@blockialabs.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/blockia-server-sdk_0.2.0_1763980441130_0.5120016018019262"},"_hasShrinkwrap":false}},"time":{"created":"2025-11-04T11:44:27.503Z","modified":"2025-11-24T10:34:01.499Z","0.1.0":"2025-11-04T11:44:27.817Z","0.2.0":"2025-11-24T10:34:01.313Z"},"description":"Backend SDK for merchants to integrate Blockia Pay X402 protocol into their APIs. Enables pay-per-use endpoints and automatic payment processing.","maintainers":[{"name":"blockialabs","email":"kristijan.boshev@blockialabs.com"}],"readme":"# @blockia/server-sdk\n\nBackend SDK for merchants to integrate Blockia Pay X402 protocol into their\nAPIs. Enables pay-per-use endpoints and automatic payment processing.\n\n## Installation\n\n```bash\nnpm install @blockia/server-sdk\n# or\nyarn add @blockia/server-sdk\n# or\npnpm add @blockia/server-sdk\n```\n\n## Quick Start\n\n### Basic Usage\n\n```typescript\nimport { BlockiaServer } from '@blockia/server-sdk';\n\nconst blockiaServer = new BlockiaServer({\n  apiUrl: 'https://api.blockia.com',\n  secretKey: 'sk_live_...', // Your secret key from Blockia dashboard\n});\n\n// Create a payment record\nconst paymentRecord = await blockiaServer.createPaymentRecord({\n  amount: 9.99,\n  description: 'Premium API Access',\n  successUrl: 'https://yourapp.com/success',\n  cancelUrl: 'https://yourapp.com/cancel',\n});\n\nconsole.log(paymentRecord.url); // Payment URL for customers\n```\n\n### Express Middleware for X402 Protection\n\n```typescript\nimport express from 'express';\nimport { x402Middleware } from '@blockia/server-sdk';\n\nconst app = express();\n\n// Protect endpoints with payment requirements\napp.use(\n  x402Middleware({\n    secretKey: 'sk_live_...',\n    protectedEndpoints: {\n      '/api/premium/data': 0.1, // $0.10 per request\n      '/api/premium/analytics': 0.5, // $0.50 per request\n    },\n  })\n);\n\n// Protected endpoint\napp.get('/api/premium/data', (req, res) => {\n  // Payment already verified by middleware\n  const { recordId, transactionHash, amount } = req.payment;\n\n  res.json({\n    data: 'premium content',\n    payment: { recordId, transactionHash, amount },\n  });\n});\n\napp.listen(3000);\n```\n\n## API Reference\n\n### BlockiaServer\n\n#### Constructor\n\n```typescript\nnew BlockiaServer(config: BlockiaServerConfig)\n```\n\n**Parameters:**\n\n- `config.apiUrl`: Base URL for the Blockia API\n- `config.secretKey`: Your secret key for API authentication\n\n#### Methods\n\n##### createPaymentRecord(request: CreatePaymentRecordRequest): Promise<CreatePaymentRecordResponse>\n\nCreates a new payment record.\n\n**Parameters:**\n\n- `request.amount`: Payment amount (number)\n- `request.description`: Payment description (string)\n- `request.successUrl?`: URL to redirect after successful payment\n- `request.cancelUrl?`: URL to redirect after cancelled payment\n- `request.metadata?`: Custom metadata object\n- `request.expiresInHours?`: Payment expiration time\n\n##### `validatePaymentRecord(recordId: string): Promise<ValidatePaymentRecordResponse>`\n\nValidates a payment record status.\n\n##### `getPaymentRecord(recordId: string): Promise<CreatePaymentRecordResponse>`\n\nGets payment record details.\n\n##### `generateX402Requirements(recordId: string): Promise<X402PaymentRequirementsResponse>`\n\nGenerates X402 payment requirements for a payment.\n\n##### `payWithX402(recordId: string, paymentRequest: X402PaymentRequest): Promise<PaymentSettlementResponse>`\n\nProcesses an X402 payment.\n\n### Middleware\n\n#### `x402Middleware(config: X402MiddlewareConfig)`\n\nExpress middleware that protects endpoints with X402 payments.\n\n**Config:**\n\n- `secretKey`: Your secret key\n- `protectedEndpoints`: Object mapping endpoint paths to payment amounts\n- `apiUrl?`: Custom API URL\n\n#### `x402Protect(secretKey: string, amount: number, apiUrl?: string)`\n\nConvenience function for protecting individual endpoints.\n\n## Agent Client SDK Updates\n\nThe Blockia Agent SDK now includes `fetchWithPayment()` for automatic X402\npayment handling:\n\n```typescript\nimport { BlockiaAgent } from '@blockia/agent-sdk';\n\nconst agent = new BlockiaAgent({\n  privateKey: '0x...',\n  apiUrl: 'https://api.blockia.com',\n});\n\n// Automatically handles payments for protected endpoints\nconst response = await agent.fetchWithPayment(\n  'https://api.example.com/premium/data'\n);\nconst data = await response.json();\n```\n\n## Error Handling\n\nAll methods throw errors for failed requests. Common errors:\n\n- `NetworkError`: API communication failures\n- `ValidationError`: Invalid parameters or responses\n\n## Environment Variables\n\n```bash\nBLOCKIA_API_URL=https://api.blockia.com\nBLOCKIA_SECRET_KEY=sk_live_...\n```\n\n## License\n\nMIT\n","readmeFilename":"README.md"}