CodeSampleX

Sample

raw-body 2.5.1: raw-body

Verified sample for npm raw-body 2.5.1: raw-body. The contract ran on node 22 · linux debian/x64 · docker and passed: getRawBody(stream) resolves to a Buffer…

sha256:568615ab443dd5aa1dde1efb9fe9d66b346cb9650e5ea1b286954fca4a0f61e3

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Verification-run environments

Environment Contract Stages Run
node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-11-21

Case

HOW
Goal
verify raw-body in pkg:npm/raw-body@2.5.1
Packages
Symbols
  • raw-body
Environment
node 22.23.2
Created
2026-11-21T19:15:53Z

Contract

  1. getRawBody(stream) resolves to a Buffer containing all chunks read from a Readable stream
  2. getRawBody(stream, true) and getRawBody(stream, 'utf-8') decode multi-byte UTF-8 chunks into a string
  3. getRawBody(stream, { encoding, length, limit }) accepts byte string limits such as '1kb' and returns the decoded body when length matches
  4. getRawBody supports callback overloads (stream, cb) and (stream, options, cb), and throws TypeError synchronously when callback is not a function
  5. exceeding limit upfront (length > limit) or during streaming rejects with 413 status and type 'entity.too.large'
  6. receiving a byte count different from options.length rejects with 400 status and type 'request.size.invalid'
  7. passing an unrecognized encoding rejects with 415 status and type 'encoding.unsupported'
  8. passing a stream with encoding already set rejects with 500 status and type 'stream.encoding.set'
  9. passing a non-readable stream rejects with 500 status and type 'stream.not.readable'
  10. emitting 'aborted' before stream end rejects with 400 status, code 'ECONNABORTED', and type 'request.aborted'

Files

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • test/contract.js

Download the source artifact (tar.gz)

Source

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify raw-body in pkg:npm/raw-body@2.5.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/raw-body@2.5.1
Demonstrate these symbols/APIs:
  - raw-body
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:92e035ead2e9190bd91434c5b9617a6701e1bd6c9aa5b9d54fc942c408a40379","constraints":{"executionContext":"node"},"contract":["getRawBody(stream) resolves to a Buffer containing all chunks read from a Readable stream","getRawBody(stream, true) and getRawBody(stream, 'utf-8') decode multi-byte UTF-8 chunks into a string","getRawBody(stream, { encoding, length, limit }) accepts byte string limits such as '1kb' and returns the decoded body when length matches","getRawBody supports callback overloads (stream, cb) and (stream, options, cb), and throws TypeError synchronously when callback is not a function","exceeding limit upfront (length \u003e limit) or during streaming rejects with 413 status and type 'entity.too.large'","receiving a byte count different from options.length rejects with 400 status and type 'request.size.invalid'","passing an unrecognized encoding rejects with 415 status and type 'encoding.unsupported'","passing a stream with encoding already set rejects with 500 status and type 'stream.encoding.set'","passing a non-readable stream rejects with 500 status and type 'stream.not.readable'","emitting 'aborted' before stream end rejects with 400 status, code 'ECONNABORTED', and type 'request.aborted'"],"goal":"verify raw-body in pkg:npm/raw-body@2.5.1","kind":"HOW","packages":["pkg:npm/raw-body@2.5.1"],"schemaVersion":1,"symbols":["raw-body"]},"contractCommand":["node","test/contract.js"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/raw-body@2.5.1"],"schemaVersion":1,"subject":"pkg:npm/raw-body@2.5.1","symbols":["raw-body"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "raw-body-sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "raw-body-sample",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "raw-body": "2.5.1"
      }
    },
    "node_modules/bytes": {
      "version": "3.1.2",
      "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz",
      "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.8"
      }
    },
    "node_modules/depd": {
      "version": "2.0.0",
      "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
      "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.8"
      }
    },
    "node_modules/http-errors": {
      "version": "2.0.0",
      "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz",
      "integrity": "sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ==",
      "license": "MIT",
      "dependencies": {
        "depd": "2.0.0",
        "inherits": "2.0.4",
        "setprototypeof": "1.2.0",
        "statuses": "2.0.1",
        "toidentifier": "1.0.1"
      },
      "engines": {
        "node": ">= 0.8"
      }
    },
    "node_modules/iconv-lite": {
      "version": "0.4.24",
      "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
      "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==",
      "license": "MIT",
      "dependencies": {
        "safer-buffer": ">= 2.1.2 < 3"
      },
      "engines": {
        "node": ">=0.10.0"
      }
    },
    "node_modules/inherits": {
      "version": "2.0.4",
      "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
      "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
      "license": "ISC"
    },
    "node_modules/raw-body": {
      "version": "2.5.1",
      "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.1.tgz",
      "integrity": "sha512-qqJBtEyVgS0ZmPGdCFPWJ3FreoqvG4MVQln/kCgF7Olq95IbOp0/BWyMwbdtn4VTvkM8Y7khCQ2Xgk/tcrCXig==",
      "license": "MIT",
      "dependencies": {
        "bytes": "3.1.2",
        "http-errors": "2.0.0",
        "iconv-lite": "0.4.24",
        "unpipe": "1.0.0"
      },
      "engines": {
        "node": ">= 0.8"
      }
    },
    "node_modules/safer-buffer": {
      "version": "2.1.2",
      "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
      "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
      "license": "MIT"
    },
    "node_modules/setprototypeof": {
      "version": "1.2.0",
      "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz",
      "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==",
      "license": "ISC"
    },
    "node_modules/statuses": {
      "version": "2.0.1",
      "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz",
      "integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.8"
      }
    },
    "node_modules/toidentifier": {
      "version": "1.0.1",
      "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz",
      "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==",
      "license": "MIT",
      "engines": {
        "node": ">=0.6"
      }
    },
    "node_modules/unpipe": {
      "version": "1.0.0",
      "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
      "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.8"
      }
    }
  }
}
package.json
{
  "name": "raw-body-sample",
  "version": "1.0.0",
  "private": true,
  "license": "MIT-0",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "raw-body": "2.5.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify raw-body in pkg:npm/raw-body@2.5.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/raw-body@2.5.1"
  ],
  "symbols": [
    "raw-body"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.js
'use strict'

const getRawBody = require('raw-body')

function readRawBuffer (stream, options) {
  return getRawBody(stream, options)
}

function readRawText (stream, options) {
  if (typeof options === 'string' || options === true) {
    return getRawBody(stream, options)
  }
  return getRawBody(stream, Object.assign({ encoding: 'utf-8' }, options))
}

function readRawCallback (stream, options, callback) {
  if (typeof options === 'function') {
    return getRawBody(stream, options)
  }
  return getRawBody(stream, options, callback)
}

module.exports = {
  getRawBody,
  readRawBuffer,
  readRawText,
  readRawCallback
}
test/contract.js
'use strict'

const assert = require('node:assert/strict')
const { Readable } = require('node:stream')
const getRawBody = require('raw-body')
const { readRawBuffer, readRawText, readRawCallback } = require('../src/index')

function createChunkedStream (chunks) {
  let index = 0
  return new Readable({
    read () {
      if (index < chunks.length) {
        this.push(chunks[index++])
      } else {
        this.push(null)
      }
    }
  })
}

async function run () {
  // 1. Default Promise API returns a Buffer containing all stream chunks
  const rawBuf = await readRawBuffer(createChunkedStream([
    Buffer.from('hello '),
    Buffer.from('raw-body')
  ]))
  assert.ok(Buffer.isBuffer(rawBuf))
  assert.equal(rawBuf.toString('utf8'), 'hello raw-body')

  // 2. Encoding shortcut `true` decodes UTF-8 across split multi-byte chunks
  const multiByte = Buffer.from('café 🚀', 'utf8')
  const splitChunks = [multiByte.subarray(0, 4), multiByte.subarray(4, 7), multiByte.subarray(7)]
  const decodedTrue = await readRawText(createChunkedStream(splitChunks), true)
  assert.equal(typeof decodedTrue, 'string')
  assert.equal(decodedTrue, 'café 🚀')

  // 3. String encoding shortcut and options object with length + string limit
  const decodedUtf8 = await getRawBody(createChunkedStream([Buffer.from('payload')]), 'utf-8')
  assert.equal(decodedUtf8, 'payload')

  const payload = Buffer.from('exact-length-body', 'utf8')
  const decodedOpts = await readRawText(createChunkedStream([payload]), {
    encoding: 'utf-8',
    length: payload.length,
    limit: '1kb'
  })
  assert.equal(decodedOpts, 'exact-length-body')

  // 4. Callback API overloads: (stream, cb) and (stream, opts, cb)
  const cbBuf = await new Promise((resolve, reject) => {
    readRawCallback(createChunkedStream([Buffer.from('cb-bytes')]), (err, buf) => {
      if (err) return reject(err)
      resolve(buf)
    })
  })
  assert.ok(Buffer.isBuffer(cbBuf))
  assert.equal(cbBuf.toString('utf8'), 'cb-bytes')

  const cbStr = await new Promise((resolve, reject) => {
    readRawCallback(createChunkedStream([Buffer.from('cb-text')]), { encoding: true }, (err, str) => {
      if (err) return reject(err)
      resolve(str)
    })
  })
  assert.equal(cbStr, 'cb-text')

  // 5. Invalid non-function callback throws TypeError synchronously
  assert.throws(
    () => getRawBody(createChunkedStream([Buffer.from('x')]), {}, 'not-a-function'),
    { name: 'TypeError', message: 'argument callback must be a function' }
  )

  // 6. Limit exceeded upfront (length > limit) rejects with 413 entity.too.large
  await assert.rejects(
    () => getRawBody(createChunkedStream([Buffer.from('0123456789')]), { length: 10, limit: 5 }),
    (err) => {
      assert.equal(err.status, 413)
      assert.equal(err.statusCode, 413)
      assert.equal(err.type, 'entity.too.large')
      assert.equal(err.expected, 10)
      assert.equal(err.length, 10)
      assert.equal(err.limit, 5)
      return true
    }
  )

  // 7. Limit exceeded while streaming rejects with 413 entity.too.large
  await assert.rejects(
    () => getRawBody(createChunkedStream([Buffer.from('1234'), Buffer.from('5678')]), { limit: 6 }),
    (err) => {
      assert.equal(err.status, 413)
      assert.equal(err.statusCode, 413)
      assert.equal(err.type, 'entity.too.large')
      assert.equal(err.limit, 6)
      assert.equal(err.received, 8)
      return true
    }
  )

  // 8. Length mismatch rejects with 400 request.size.invalid
  await assert.rejects(
    () => getRawBody(createChunkedStream([Buffer.from('short')]), { length: 10 }),
    (err) => {
      assert.equal(err.status, 400)
      assert.equal(err.statusCode, 400)
      assert.equal(err.type, 'request.size.invalid')
      assert.equal(err.expected, 10)
      assert.equal(err.length, 10)
      assert.equal(err.received, 5)
      return true
    }
  )

  // 9. Unsupported encoding rejects with 415 encoding.unsupported
  await assert.rejects(
    () => getRawBody(createChunkedStream([Buffer.from('data')]), { encoding: 'unsupported-charset-xyz' }),
    (err) => {
      assert.equal(err.status, 415)
      assert.equal(err.statusCode, 415)
      assert.equal(err.type, 'encoding.unsupported')
      assert.equal(err.encoding, 'unsupported-charset-xyz')
      return true
    }
  )

  // 10. Stream with encoding already set rejects with 500 stream.encoding.set
  const encodedStream = createChunkedStream([Buffer.from('text')])
  encodedStream.setEncoding('utf8')
  await assert.rejects(
    () => getRawBody(encodedStream),
    (err) => {
      assert.equal(err.status, 500)
      assert.equal(err.statusCode, 500)
      assert.equal(err.type, 'stream.encoding.set')
      return true
    }
  )

  // 11. Non-readable stream rejects with 500 stream.not.readable
  const closedStream = new Readable({ read () {} })
  closedStream.readable = false
  await assert.rejects(
    () => getRawBody(closedStream),
    (err) => {
      assert.equal(err.status, 500)
      assert.equal(err.statusCode, 500)
      assert.equal(err.type, 'stream.not.readable')
      return true
    }
  )

  // 12. Aborted stream rejects with 400 request.aborted and ECONNABORTED
  const abortStream = new Readable({ read () {} })
  const abortPromise = getRawBody(abortStream, { length: 10 })
  abortStream.once('data', () => {
    abortStream.emit('aborted')
  })
  abortStream.push(Buffer.from('part'))
  await assert.rejects(
    () => abortPromise,
    (err) => {
      assert.equal(err.status, 400)
      assert.equal(err.statusCode, 400)
      assert.equal(err.type, 'request.aborted')
      assert.equal(err.code, 'ECONNABORTED')
      assert.equal(err.expected, 10)
      assert.equal(err.received, 4)
      return true
    }
  )
}

run().catch((err) => {
  console.error(err)
  process.exit(1)
})

Origin Seeder

anonymous