{"_id":"@ahadpvt.v3/resmake","_rev":"6-a8f167efbb721aaf15b9cb98074a5158","name":"@ahadpvt.v3/resmake","dist-tags":{"latest":"2.0.2"},"versions":{"1.0.0":{"name":"@ahadpvt.v3/resmake","version":"1.0.0","keywords":["http","response","builder","json","sse","stream","file","redirect","cookie","edge","lambda","cloudflare","workers","middleware"],"author":{"name":"Abdul Ahad"},"license":"MIT","_id":"@ahadpvt.v3/resmake@1.0.0","maintainers":[{"name":"ahadpvt.v3","email":"ahadpvt.v3@gmail.com"}],"dist":{"shasum":"eafeb3c7000da0296526d5591f50605062fc6a25","tarball":"https://registry.npmjs.org/@ahadpvt.v3/resmake/-/resmake-1.0.0.tgz","fileCount":6,"integrity":"sha512-MA6t18rlxBn2Z+hyTWTCHSfn/V7XZsiT9cw3z4Xx+c6j/zwP62T9QlWJGku/cvQSMBodXpT55t2GSn2oWd0S+w==","signatures":[{"sig":"MEUCIQDNAu3wjlQEBfznt2VNE8XGhq4m6SrJH1ohUzruqFNa6AIgJxJjdH1GH8Qx1l6JE9knNaM1lpgj/45v7ar7fO6PtfA=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":36865},"main":"index.js","types":"index.d.ts","engines":{"node":">=14"},"exports":{".":{"import":"./index.mjs","require":"./index.js"}},"scripts":{"test":"node test.js"},"_npmUser":{"name":"ahadpvt.v3","email":"ahadpvt.v3@gmail.com"},"_npmVersion":"9.2.0","description":"Zero-dependency, environment-aware HTTP response builder for Node.js, Edge Runtime, Cloudflare Workers and AWS Lambda","directories":{},"_nodeVersion":"18.19.1","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/resmake_1.0.0_1773467833563_0.40374837183482515","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@ahadpvt.v3/resmake","version":"1.0.1","keywords":["http","response","builder","json","sse","stream","file","redirect","cookie","edge","lambda","cloudflare","workers","middleware"],"author":{"name":"Abdul Ahad"},"license":"MIT","_id":"@ahadpvt.v3/resmake@1.0.1","maintainers":[{"name":"ahadpvt.v3","email":"ahadpvt.v3@gmail.com"}],"dist":{"shasum":"afec49d4ccdd2087afefb125715040abc9a45caf","tarball":"https://registry.npmjs.org/@ahadpvt.v3/resmake/-/resmake-1.0.1.tgz","fileCount":7,"integrity":"sha512-LPDrVSrp82AxtMTKOJ6yiWGtsFQ+Fl4BhGQ/MPDV7m11CVGQEmVg8qzBpKnsTmrBsBeQFIG6PjANEgxb/N36Qg==","signatures":[{"sig":"MEUCIQDiXwGnOYIpyshSNx4Whlmtf51VZbvigHNV0umWfp4GzwIgGUxRN4QtwEl0WvpZ6SY/dWPjIPPvd87HkfcjrW/VIzU=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":70258},"main":"index.js","types":"index.d.ts","engines":{"node":">=14"},"exports":{".":{"import":"./index.mjs","require":"./index.js"}},"scripts":{"test":"node test.js"},"_npmUser":{"name":"ahadpvt.v3","email":"ahadpvt.v3@gmail.com"},"_npmVersion":"9.2.0","description":"Zero-dependency, environment-aware HTTP response builder for Node.js, Edge Runtime, Cloudflare Workers and AWS Lambda","directories":{},"_nodeVersion":"18.19.1","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/resmake_1.0.1_1773517112916_0.9157892900493965","host":"s3://npm-registry-packages-npm-production"}},"1.0.2":{"name":"@ahadpvt.v3/resmake","version":"1.0.2","keywords":["http","response","builder","json","sse","stream","file","redirect","cookie","edge","lambda","cloudflare","workers","middleware"],"author":{"name":"Abdul Ahad"},"license":"MIT","_id":"@ahadpvt.v3/resmake@1.0.2","maintainers":[{"name":"ahadpvt.v3","email":"ahadpvt.v3@gmail.com"}],"dist":{"shasum":"f8b4ba6047a97c2ab6099b609d7c21fbc248c654","tarball":"https://registry.npmjs.org/@ahadpvt.v3/resmake/-/resmake-1.0.2.tgz","fileCount":6,"integrity":"sha512-SkUvGU3MgRIGpv9YputRyoHooarAQkrW2DfvYcaoKe72SPt1sVW2L60GzB3jxmTWF9mziT1g0XmxNHmvDjCqAA==","signatures":[{"sig":"MEUCIDNbyBRQnxRf2TQmlaOzjBfumQcW4ggs+otfARgRbGP5AiEA+5YjL5bcymALoXLLh+oU2IMoGBjhKHMPm8f2p7UB6xU=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":44882},"main":"index.js","types":"index.d.ts","engines":{"node":">=14"},"exports":{".":{"import":"./index.mjs","require":"./index.js"}},"scripts":{"test":"node test.js"},"_npmUser":{"name":"ahadpvt.v3","email":"ahadpvt.v3@gmail.com"},"_npmVersion":"9.2.0","description":"Zero-dependency, environment-aware HTTP response builder for Node.js, Edge Runtime, Cloudflare Workers and AWS Lambda","directories":{},"_nodeVersion":"18.19.1","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/resmake_1.0.2_1773517237077_0.8891453606889579","host":"s3://npm-registry-packages-npm-production"}},"2.0.0":{"name":"@ahadpvt.v3/resmake","version":"2.0.0","keywords":["http","response","builder","json","sse","stream","file","redirect","cookie","tcp","udp","edge","lambda","cloudflare","workers","middleware"],"author":{"name":"Abdul Ahad"},"license":"MIT","_id":"@ahadpvt.v3/resmake@2.0.0","maintainers":[{"name":"ahadpvt.v3","email":"ahadpvt.v3@gmail.com"}],"dist":{"shasum":"b830d82e02d020459bff85683be088c00fe60c19","tarball":"https://registry.npmjs.org/@ahadpvt.v3/resmake/-/resmake-2.0.0.tgz","fileCount":6,"integrity":"sha512-4QRS7Bsr6W2DaN0YCWk5zo7voMkXuH0V93cuIylfqnmy5tusjXaKIQQClwrITkvoUoDc+Ex7EZ+im/JgXLgbMA==","signatures":[{"sig":"MEUCIQCjNx+0ffsGo3L7YYIuCvmHOcznAOptFRZQvGeLPjQZ5AIgQW2Rre08eXShlMiHT5t5ELh3AmTGvh+V7XCGnllZ+Ro=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":51524},"main":"index.js","types":"index.d.ts","engines":{"node":">=14"},"exports":{".":{"import":"./index.mjs","require":"./index.js"}},"scripts":{"test":"node test.js"},"_npmUser":{"name":"ahadpvt.v3","email":"ahadpvt.v3@gmail.com"},"_npmVersion":"9.2.0","description":"Zero-dependency, environment-aware HTTP response builder with TCP and UDP support for Node.js, Edge Runtime, Cloudflare Workers and AWS Lambda","directories":{},"_nodeVersion":"18.19.1","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/resmake_2.0.0_1773527732502_0.06475069686684387","host":"s3://npm-registry-packages-npm-production"}},"2.0.1":{"name":"@ahadpvt.v3/resmake","version":"2.0.1","keywords":["http","response","builder","json","sse","stream","file","redirect","cookie","tcp","udp","edge","lambda","cloudflare","workers","middleware"],"author":{"name":"Abdul Ahad"},"license":"MIT","_id":"@ahadpvt.v3/resmake@2.0.1","maintainers":[{"name":"ahadpvt.v3","email":"ahadpvt.v3@gmail.com"}],"dist":{"shasum":"61ec8e2b7caf351046081a75c0265c73db6b1a1a","tarball":"https://registry.npmjs.org/@ahadpvt.v3/resmake/-/resmake-2.0.1.tgz","fileCount":6,"integrity":"sha512-T5zcM8Y1N5zCmz8uUMcjeqCAGG7q6EgZTlPoXc6NCj0HmjXptVWi4+JiOvtB9TKS3pAFF7WyItm+LCGjvsEgHg==","signatures":[{"sig":"MEQCIG3iN7ngEZtEzdG9/Fo95oUEdaS9RFSfs3wEnyNByl1TAiB0zq8yrERtGZL0UpZ2xDQPSJKNqjWQkPr8NcE7UyLyaA==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":51895},"main":"index.js","types":"index.d.ts","engines":{"node":">=14"},"exports":{".":{"import":"./index.mjs","require":"./index.js"}},"scripts":{"test":"node test.js"},"_npmUser":{"name":"ahadpvt.v3","email":"ahadpvt.v3@gmail.com"},"_npmVersion":"10.9.4","description":"Zero-dependency, environment-aware HTTP response builder with TCP and UDP support for Node.js, Edge Runtime, Cloudflare Workers and AWS Lambda","directories":{},"_nodeVersion":"22.22.1","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/resmake_2.0.1_1774162975383_0.612215598652843","host":"s3://npm-registry-packages-npm-production"}},"2.0.2":{"name":"@ahadpvt.v3/resmake","version":"2.0.2","description":"Zero-dependency, environment-aware HTTP response builder with TCP and UDP support for Node.js, Edge Runtime, Cloudflare Workers and AWS Lambda","main":"index.js","types":"index.d.ts","exports":{".":{"types":"./index.d.ts","require":"./index.js","import":"./index.mjs","default":"./index.js"}},"scripts":{"test":"node test.js"},"keywords":["http","response","builder","json","sse","stream","file","redirect","cookie","tcp","udp","edge","lambda","cloudflare","workers","middleware"],"author":{"name":"Abdul Ahad"},"license":"MIT","engines":{"node":">=14"},"type":"commonjs","sideEffects":false,"_id":"@ahadpvt.v3/resmake@2.0.2","_nodeVersion":"22.22.1","_npmVersion":"10.9.4","dist":{"integrity":"sha512-VGSRC35iMo/3vqpz9lWied02Ezk93C7qEE5WNGLDOFXSSFPWI2V914bTU8lngE7jcIwDamx/cafu87a3KObCHA==","shasum":"4b7d789100ce91c91ae764503a3612004de6983f","tarball":"https://registry.npmjs.org/@ahadpvt.v3/resmake/-/resmake-2.0.2.tgz","fileCount":6,"unpackedSize":57833,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCqIkQMknCDdcArPI4/wTSXm7xasJfJCa232uBnpobodQIgVO9y16V6Tm4Nq41M///Y/jnE4uFLwmTV+PTJV5GthJE="}]},"_npmUser":{"name":"ahadpvt.v3","email":"ahadpvt.v3@gmail.com"},"directories":{},"maintainers":[{"name":"ahadpvt.v3","email":"ahadpvt.v3@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/resmake_2.0.2_1774167070174_0.5272267974453928"},"_hasShrinkwrap":false}},"time":{"created":"2026-03-14T05:57:13.447Z","modified":"2026-03-22T08:11:10.453Z","1.0.0":"2026-03-14T05:57:13.734Z","1.0.1":"2026-03-14T19:38:33.056Z","1.0.2":"2026-03-14T19:40:37.233Z","2.0.0":"2026-03-14T22:35:32.639Z","2.0.1":"2026-03-22T07:02:55.516Z","2.0.2":"2026-03-22T08:11:10.319Z"},"author":{"name":"Abdul Ahad"},"license":"MIT","keywords":["http","response","builder","json","sse","stream","file","redirect","cookie","tcp","udp","edge","lambda","cloudflare","workers","middleware"],"description":"Zero-dependency, environment-aware HTTP response builder with TCP and UDP support for Node.js, Edge Runtime, Cloudflare Workers and AWS Lambda","maintainers":[{"name":"ahadpvt.v3","email":"ahadpvt.v3@gmail.com"}],"readme":"# @ahadpvt.v3/resmake\n\nA **zero-dependency, environment-aware HTTP response builder** — now with TCP and UDP response support — built as the response layer beneath a universal route dispatcher.\n\nTwo modes for HTTP: eager (write-style) for Node/Express, lazy (return-style) for CF Workers, Edge, and Deno. Plus dedicated response contexts for raw TCP and UDP so all protocols share the same ergonomic `res` API.\n\n---\n\n## Installation\n\n```bash\nnpm install @ahadpvt.v3/resmake\n```\n\n---\n\n## Import / Require\n\n```js\nconst { normalize, create, context, tcpContext, udpContext } = require(\"@ahadpvt.v3/resmake\")\n```\n\n---\n\n## Two HTTP Modes\n\n### Eager — Node.js, Express, Fastify\n\n```js\nconst { normalize } = require(\"@ahadpvt.v3/resmake\")\n\nhttp.createServer((req, res) => {\n  const r = normalize(res)\n  r.status(200).header(\"x-id\", \"abc\").json({ hello: \"world\" })\n})\n```\n\n### Lazy — CF Workers, Edge Runtime, Deno\n\n```js\nconst { create } = require(\"@ahadpvt.v3/resmake\")\n\n// Cloudflare Workers — app is the export directly\nexport default {\n  async fetch(request, env, ctx) {\n    const res = create()\n    res.status(200).json({ hello: \"cf\" })\n    return res.toResponse()\n  }\n}\n\n// Edge Runtime\nexport async function middleware(request) {\n  const res = create()\n  res.json({ ok: true })\n  return res.toResponse()\n}\n\n// Deno\nDeno.serve(async (req) => {\n  const res = create()\n  res.json({ hello: \"deno\" })\n  return res.toResponse()\n})\n```\n\n`toResponse()` is **synchronous** for all methods except `file()` which returns `Promise<Response>`.\n\n### Lambda\n\n```js\nexports.handler = async (event) => new Promise(resolve => {\n  const res = context(null, { resolve, _adapter: adapters.lambda(resolve) })\n  res.json({ hello: \"lambda\" })\n})\n```\n\n---\n\n## All HTTP Response Methods\n\nSame API in both eager and lazy mode.\n\n### `res.json(data, code?)`\n```js\nres.json({ user: \"Abdul\" })\nres.json({ error: \"not found\" }, 404)\n```\n\n### `res.html(str, code?)`\n```js\nres.html(\"<h1>Hello</h1>\")\n```\n\n### `res.text(str, code?)`\n```js\nres.text(\"OK\")\nres.text(\"Unauthorized\", 401)\n```\n\n### `res.binary(buf, mime?)`\n```js\nres.binary(imageBuffer, \"image/png\")\n```\n\n### `res.send(body, mime?)`\n```js\nres.header(\"content-type\", \"application/xml\").send(\"<root/>\")\nres.send(buffer, \"application/pdf\")\n```\n\n### `res.stream(readable, mime?)`\nNode/Express: zero-copy pipe. Edge/Lambda: buffers first.\n```js\nres.stream(fs.createReadStream(\"./video.mp4\"), \"video/mp4\")\n```\n\n### `res.file(filePath, opts?)`\nFull HTTP caching — ETag, Last-Modified, Range requests, 304, 206.\n\n```js\nres.file(\"./public/logo.png\")\n\nres.file(\"./dist/bundle.js\", {\n  rangeHeader : req.headers[\"range\"],\n  ifNoneMatch : req.headers[\"if-none-match\"],\n  ifModified  : req.headers[\"if-modified-since\"],\n})\n\nres.file(\"./report.pdf\", { download: true, filename: \"monthly-report.pdf\" })\n```\n\n**Lazy mode:** `toResponse()` returns `Promise<Response>` when `file()` was called.\n\n```js\nreturn await res.toResponse()\n```\n\n### `res.redirect(url, code?)`\n```js\nres.redirect(\"/login\")\nres.redirect(\"https://example.com\", 301)\n```\n\n### `res.end(code?)`\n```js\nres.end(204)\n```\n\n---\n\n## Header Methods — all chainable\n\n```js\nres.status(201)\nres.header(\"x-request-id\", \"abc-123\")\nres.headers({ \"x-foo\": \"1\", \"x-bar\": \"2\" })\nres.type(\"json\")           // shorthand\nres.type(\"image/avif\")     // full mime string\nres.vary(\"Accept-Encoding\")\n```\n\n`res.type()` shorthands: `json`, `html`, `text`, `plain`, `binary`, `form`, `xml`, `svg`, `pdf`, `js`, `css`\n\n---\n\n## Cookies\n\nRFC-correct — multiple `Set-Cookie` headers kept separate.\n\n```js\nres.cookie(\"session\", \"abc123\", {\n  httpOnly : true,\n  secure   : true,\n  sameSite : \"Lax\",\n  maxAge   : 3600,\n})\n\nres.clearCookie(\"session\")\n```\n\nOptions: `maxAge`, `domain`, `path`, `expires`, `httpOnly`, `secure`, `sameSite`, `partitioned`\n\n---\n\n## Server-Sent Events\n\n```js\n// Eager (Node)\nconst sse = res.sse()\nsse.send(\"hello\")\nsse.send({ type: \"update\", data }, \"update\", \"msg-1\", 3000)\nconst interval = setInterval(() => sse.ping(), 20_000)  // keepalive\nsse.close()\n\n// Lazy (CF Workers / Edge)\nconst res = create()\nconst sse = res.sse()\nsse.send(\"first message\")\nreturn res.toResponse()  // returns streaming Response immediately\n```\n\n---\n\n## TCP Response Context\n\nFor raw TCP, TLS, and Unix socket connections. Used internally by `dispex.tcp()`, `dispex.tls()`, `dispex.unix()`. Also usable standalone.\n\n```js\nconst { tcpContext } = require(\"@ahadpvt.v3/resmake\")\nconst net = require(\"net\")\n\nnet.createServer(socket => {\n  const res = tcpContext(socket)\n\n  res.send(\"hello\\n\")                // write string\n  res.send(Buffer.from([0x01]))      // write Buffer\n  res.pipe(fs.createReadStream(\"./file.bin\"))  // pipe stream\n  res.keepAlive(true, 30000)         // TCP keep-alive\n  res.noDelay(true)                  // disable Nagle\n  res.setTimeout(30000)              // 30s timeout\n  res.close(\"bye\\n\")                 // send final data and close\n  res.close()                        // close immediately\n})\n```\n\nIn framed mode via `dispex.tcp({ framing })`, `res.sendFramed(data)` writes a properly framed reply automatically.\n\n---\n\n## UDP Response Context\n\n```js\nconst { udpContext } = require(\"@ahadpvt.v3/resmake\")\nconst dgram = require(\"dgram\")\n\nconst server = dgram.createSocket(\"udp4\")\nserver.on(\"message\", (msg, rinfo) => {\n  const res = udpContext(server, rinfo)\n\n  res.send(Buffer.from(\"pong\"))                    // reply to sender\n  res.sendTo(Buffer.from(\"x\"), 5001, \"10.0.0.2\")  // arbitrary target\n  res.broadcast(Buffer.from(\"announce\"), 5000)     // broadcast\n})\nserver.bind(5000)\n```\n\n---\n\n## Middleware Contract\n\n`res.sent` flips to `true` after any send method. Dispatcher checks this after every middleware step.\n\n```js\nasync function authMiddleware(ctx, res, next) {\n  if (!ctx.headers.authorization) {\n    res.json({ error: \"unauthorized\" }, 401)\n    return  // do not call next — res.sent is true\n  }\n  await next()\n}\n\nasync function loggerMiddleware(ctx, res, next) {\n  res.header(\"x-request-id\", generateId())\n  await next()\n  console.log(res.statusCode, res.sent)\n}\n```\n\n---\n\n## Chaining\n\n```js\nres\n  .status(201)\n  .header(\"x-id\", \"abc\")\n  .vary(\"Accept\")\n  .cookie(\"session\", \"xyz\", { httpOnly: true })\n  .json({ created: true })\n```\n\n---\n\n## Error Handling\n\n```js\ntry {\n  res.json({ ok: true })\n  res.json({ again: true })  // throws ALREADY_SENT\n} catch (err) {\n  if (err.isResmake) {\n    switch (err.code) {\n      case \"ALREADY_SENT\":\n      case \"INVALID_RESPONSE\":\n    }\n  }\n}\n```\n\n---\n\n## Constants\n\n```js\nconst { MIME, MIME_ALIAS, EXT_MIME } = require(\"@ahadpvt.v3/resmake\")\n\nMIME.json    // \"application/json; charset=utf-8\"\nMIME.sse     // \"text/event-stream; charset=utf-8\"\n\nMIME_ALIAS.js   // \"application/javascript; charset=utf-8\"\n\nEXT_MIME[\".avif\"]  // \"image/avif\"\nEXT_MIME[\".wasm\"]  // \"application/wasm\"\nEXT_MIME[\".woff2\"] // \"font/woff2\"\n```\n\n---\n\n## Runtime Adapter (Advanced)\n\nInject runtime primitives explicitly for non-standard or sandboxed environments.\n\n```js\nconst { setRuntimeAdapter } = require(\"@ahadpvt.v3/resmake\")\n\nsetRuntimeAdapter({\n  Buffer,\n  Headers,\n  Response,\n  TransformStream,\n  TextEncoder,\n  requireBuiltin: (name) => require(name),\n  reportError: (err, meta) => console.error(\"resmake runtime error\", err, meta),\n})\n```\n\nWhen a capability is unavailable, resmake throws `UNSUPPORTED_RUNTIME` instead of failing silently.\n\n---\n\n## Testing\n\n```bash\nnpm test\n```\n\n```\n68 passed, 0 failed\n```\n\n---\n\n## License\n\nMIT © Abdul Ahad\n","readmeFilename":"README.md"}