{"_id":"@axowl/sdk-backend","_rev":"4-b17956148ac31d21be6ed1dc8da53cef","name":"@axowl/sdk-backend","dist-tags":{"latest":"0.2.0"},"versions":{"0.1.0":{"name":"@axowl/sdk-backend","version":"0.1.0","license":"MIT","_id":"@axowl/sdk-backend@0.1.0","maintainers":[{"name":"sonny72","email":"admin@axowl.com"}],"dist":{"shasum":"f2a23ce43ec955e9e7b5687499a0f132f36694eb","tarball":"https://registry.npmjs.org/@axowl/sdk-backend/-/sdk-backend-0.1.0.tgz","fileCount":21,"integrity":"sha512-wgNkXfqomCMsiJYhXoXMpdL6aeELK/Pf5dEEr0usSQsJ0+MHdqHmK1uEJ579yIGr9A8l6Sw3jd+gddduAH0JwA==","signatures":[{"sig":"MEQCIGPF4Ja3vbEZko8ro1OxRme5muLFAup4VizXgX7Mju5PAiBnzUnW4Lin4FmIN+RjOuK6N0MQ4qbLI4yw2jB2QnRdMQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":14279},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"},"./next":{"types":"./dist/next.d.ts","import":"./dist/next.js"}},"scripts":{"dev":"tsc --watch","build":"tsc","clean":"rm -rf dist","typecheck":"tsc --noEmit"},"_npmUser":{"name":"sonny72","email":"admin@axowl.com"},"_npmVersion":"10.9.2","description":"Axowl SDK for Node.js backends — JWT verification, Express/Next.js middleware","directories":{},"_nodeVersion":"24.12.0","dependencies":{"@axowl/sdk-core":"workspace:*"},"_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.7.0","@types/node":"^22.0.0"},"_npmOperationalInternal":{"tmp":"tmp/sdk-backend_0.1.0_1775730562656_0.5472497321122756","host":"s3://npm-registry-packages-npm-production"}},"0.1.1":{"name":"@axowl/sdk-backend","version":"0.1.1","license":"MIT","_id":"@axowl/sdk-backend@0.1.1","maintainers":[{"name":"sonny72","email":"admin@axowl.com"}],"dist":{"shasum":"cc82290d590621c30d688d911e38a03b3908905a","tarball":"https://registry.npmjs.org/@axowl/sdk-backend/-/sdk-backend-0.1.1.tgz","fileCount":22,"integrity":"sha512-ztOHi/+5RGMdeNoQq21zQqEzziQ8tfB10mmzHbRQcrRp8owgMGtrjZz23dyk0I4U691FAIkd7U3ohnv1EeirCQ==","signatures":[{"sig":"MEYCIQCyGhGXvE8sQXDusbXvSNifoGQvOtgMTAcifdEOJiOD1wIhAIrnVRqA81uReoaN61A1MFKPcgP1Qisd7Ai+GIZxoXjx","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":18235},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"},"./next":{"types":"./dist/next.d.ts","import":"./dist/next.js"}},"scripts":{"dev":"tsc --watch","build":"tsc","clean":"rm -rf dist","typecheck":"tsc --noEmit"},"_npmUser":{"name":"sonny72","email":"admin@axowl.com"},"_npmVersion":"10.9.2","description":"Axowl SDK for Node.js backends — JWT verification, Express/Next.js middleware","directories":{},"_nodeVersion":"24.12.0","dependencies":{"@axowl/sdk-core":"workspace:*"},"_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.7.0","@types/node":"^22.0.0"},"_npmOperationalInternal":{"tmp":"tmp/sdk-backend_0.1.1_1775730910045_0.727069431179985","host":"s3://npm-registry-packages-npm-production"}},"0.1.2":{"name":"@axowl/sdk-backend","version":"0.1.2","license":"MIT","_id":"@axowl/sdk-backend@0.1.2","maintainers":[{"name":"sonny72","email":"admin@axowl.com"}],"dist":{"shasum":"7205553268afced834fc69d43339c8bd4dc90b02","tarball":"https://registry.npmjs.org/@axowl/sdk-backend/-/sdk-backend-0.1.2.tgz","fileCount":22,"integrity":"sha512-opuSaGRrQVdu7Frk83d2m4H0MDOeCc3PwhjFL1y0Y3Kspf4/6O1/5SfAak5ieo1pIBtZqvLJd7TsKkIJJyLp6w==","signatures":[{"sig":"MEYCIQDD+vYBV1UGwI3Q949JGWPiiLQtRlGBEou/5mlI39stZAIhAKtxveyQkQe1tusoKQBcwULnRuNXkUmeRLe6tMrInvmN","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":18230},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"},"./next":{"types":"./dist/next.d.ts","import":"./dist/next.js"}},"scripts":{"dev":"tsc --watch","build":"tsc","clean":"rm -rf dist","typecheck":"tsc --noEmit"},"_npmUser":{"name":"sonny72","email":"admin@axowl.com"},"_npmVersion":"10.9.2","description":"Axowl SDK for Node.js backends — JWT verification, Express/Next.js middleware","directories":{},"_nodeVersion":"24.12.0","dependencies":{"@axowl/sdk-core":"^0.1.1"},"_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.7.0","@types/node":"^22.0.0"},"_npmOperationalInternal":{"tmp":"tmp/sdk-backend_0.1.2_1775731576351_0.7232073365992195","host":"s3://npm-registry-packages-npm-production"}},"0.2.0":{"name":"@axowl/sdk-backend","version":"0.2.0","description":"Axowl SDK for Node.js backends — JWT verification, Express/Next.js middleware","type":"module","main":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"},"./next":{"types":"./dist/next.d.ts","import":"./dist/next.js"}},"scripts":{"build":"tsc","dev":"tsc --watch","clean":"rm -rf dist","typecheck":"tsc --noEmit"},"dependencies":{"@axowl/sdk-core":"^0.2.0","jose":"^5.0.0"},"devDependencies":{"@types/node":"^22.0.0","typescript":"^5.7.0"},"license":"MIT","_id":"@axowl/sdk-backend@0.2.0","gitHead":"f4ba09d9039212a4dc3ad9012dfee1ab31da7fa6","_nodeVersion":"24.12.0","_npmVersion":"10.9.2","dist":{"integrity":"sha512-QES817NQLx1sR+By5jh0CToIX5L3ia7Rug8cfViF2XeIS1ZZXpulZibk3vWSh3VDgaX/5+jC8C2Yb16vGbYFyg==","shasum":"533768146175a6d64f5ed9d0e1737c7b9fb856b6","tarball":"https://registry.npmjs.org/@axowl/sdk-backend/-/sdk-backend-0.2.0.tgz","fileCount":26,"unpackedSize":27712,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCV7Ys25ipGC+hDdpStS3EdGBYNiVpnldbYkkGusq/5uQIhAML9u6h1wYdOExv5NW9uveFcEz/Z3l8PHngFA6cKgu7J"}]},"_npmUser":{"name":"sonny72","email":"admin@axowl.com"},"directories":{},"maintainers":[{"name":"sonny72","email":"admin@axowl.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/sdk-backend_0.2.0_1776760349745_0.9192097646829116"},"_hasShrinkwrap":false}},"time":{"created":"2026-04-09T10:29:22.546Z","modified":"2026-04-21T08:32:30.006Z","0.1.0":"2026-04-09T10:29:22.793Z","0.1.1":"2026-04-09T10:35:10.210Z","0.1.2":"2026-04-09T10:46:16.478Z","0.2.0":"2026-04-21T08:32:29.886Z"},"license":"MIT","description":"Axowl SDK for Node.js backends — JWT verification, Express/Next.js middleware","maintainers":[{"name":"sonny72","email":"admin@axowl.com"}],"readme":"# @axowl/sdk-backend\n\nAxowl SDK for Node.js backends — JWT verification, Express middleware, and Next.js helpers.\n\n## Install\n\n```bash\nnpm install @axowl/sdk-backend\n```\n\n## Express\n\n### Setup middleware\n\n```typescript\nimport express from 'express';\nimport { axowlMiddleware, requirePermission } from '@axowl/sdk-backend';\n\nconst app = express();\n\n// Verify JWT on all routes\napp.use(axowlMiddleware({\n  orgSlug: 'my-org',\n  apiKey: 'ah_live_xxxxx',\n}));\n\n// Access user info in routes\napp.get('/api/me', (req, res) => {\n  const { userId, email, permissions, orgSlug } = req.axowl;\n  res.json({ userId, email, orgSlug });\n});\n\n// Require specific permissions\napp.get('/api/reports', requirePermission('report.view'), (req, res) => {\n  res.json({ reports: [] });\n});\n\n// Require multiple permissions\napp.post('/api/reports/export', requirePermission('report.view', 'report.export'), (req, res) => {\n  res.json({ download: '...' });\n});\n```\n\n### `req.axowl` object\n\n```typescript\ninterface AxowlRequestContext {\n  token: DecodedToken;    // Full decoded JWT payload\n  userId: string;         // User ID (sub claim)\n  email?: string;         // User email\n  orgSlug?: string;       // Organization slug\n  connectedId?: string;   // Organization membership ID\n  permissions: string[];  // Permission scopes\n  raw: string;            // Raw JWT string\n}\n```\n\n## Next.js\n\n### App Router (Route Handlers)\n\n```typescript\nimport { NextRequest, NextResponse } from 'next/server';\nimport { getAuth, canAccess } from '@axowl/sdk-backend/next';\n\nexport async function GET(request: NextRequest) {\n  const auth = getAuth(request);\n\n  if (!auth) {\n    return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });\n  }\n\n  if (!canAccess(auth, 'dashboard.view')) {\n    return NextResponse.json({ error: 'Forbidden' }, { status: 403 });\n  }\n\n  return NextResponse.json({\n    userId: auth.userId,\n    email: auth.email,\n  });\n}\n```\n\n### Middleware (Edge)\n\n```typescript\n// middleware.ts\nimport { NextRequest, NextResponse } from 'next/server';\nimport { getAuth } from '@axowl/sdk-backend/next';\n\nexport function middleware(request: NextRequest) {\n  const auth = getAuth(request);\n\n  if (!auth && request.nextUrl.pathname.startsWith('/api/')) {\n    return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });\n  }\n\n  return NextResponse.next();\n}\n\nexport const config = {\n  matcher: '/api/:path*',\n};\n```\n\n## Standalone Token Verification\n\n```typescript\nimport { verifyToken, extractBearerToken } from '@axowl/sdk-backend';\n\n// From Authorization header\nconst token = extractBearerToken('Bearer eyJhbGci...');\n\nif (token) {\n  const context = verifyToken(token);\n  console.log(context.userId);\n  console.log(context.permissions);\n}\n```\n\n## Permission Utilities\n\n```typescript\nimport { hasPermission, hasAllPermissions, hasAnyPermission } from '@axowl/sdk-backend';\n\nconst permissions = ['dashboard.*', 'report.view'];\n\nhasPermission(permissions, 'dashboard.edit');       // true (wildcard match)\nhasAllPermissions(permissions, ['dashboard.view', 'report.view']); // true\nhasAnyPermission(permissions, ['billing.view', 'report.view']);    // true\n```\n\n## TypeScript\n\nAdd type support for `req.axowl`:\n\n```typescript\nimport type { AxowlRequest } from '@axowl/sdk-backend';\n\napp.get('/api/me', (req, res) => {\n  const { userId, email } = (req as AxowlRequest).axowl;\n  res.json({ userId, email });\n});\n```\n\n## API Reference\n\n| Export | Type | Description |\n|---|---|---|\n| `axowlMiddleware(config)` | Express middleware | Validates JWT, attaches `req.axowl` |\n| `requirePermission(...scopes)` | Express middleware | Checks permissions (403 if denied) |\n| `getAuth(request)` | Function | Extract auth from Next.js request |\n| `canAccess(auth, scope)` | Function | Check permission on auth context |\n| `verifyToken(token)` | Function | Decode and validate JWT |\n| `extractBearerToken(header)` | Function | Extract token from `Bearer ...` header |\n\n## License\n\nMIT\n","readmeFilename":"README.md"}