Exemplo
raw-body 2.5.2
Amostra verificada para npm raw-body 2.5.2. O contrato rodou em node 22 · linux debian/x64 · docker e passou: getRawBody is exported as a function
sha256:2a5f9caf50cd18ea15a8f226db470f6e6a82669f68bb2448e4195be5d692c093
Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu.
Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas.
MIT-0
Evidência de execução
O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.
- Base da evidência
- Contrato assinado aprovado
- Recibos de verificação
- 1
- Chaves de assinatura que o compilaram
- 1
Ambiente declarado
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
Ambientes das execuções de verificação
| Ambiente | Contrato | Etapas | Execução |
|---|---|---|---|
| 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-09-19 |
Caso
HOW- Objetivo
- verify pkg:npm/raw-body@2.5.2
- Pacotes
- Ambiente
- node 22.23.2
- Criado
- 2026-09-18T11:52:15Z
Contrato
- getRawBody is exported as a function
- getRawBody reads readable stream into a Buffer when encoding is not specified
- getRawBody decodes stream into a string when encoding is specified
- getRawBody supports callback interface
- getRawBody enforces byte limit option and throws 413 entity.too.large when exceeded
- getRawBody validates expected length option and throws 400 request.size.invalid on mismatch
- wrapper functions in index.js read stream buffers and strings correctly
Arquivos
- PROMPT.md
- csx.json
- index.js
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
Código-fonte
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 pkg:npm/raw-body@2.5.2
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/raw-body@2.5.2
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.
{"case":{"caseId":"case:sha256:e35a72db9ca644b26f68c1fdb7353b3a82136bcb81e99488b4d228cf4a4f786a","constraints":{"executionContext":"node"},"contract":["getRawBody is exported as a function","getRawBody reads readable stream into a Buffer when encoding is not specified","getRawBody decodes stream into a string when encoding is specified","getRawBody supports callback interface","getRawBody enforces byte limit option and throws 413 entity.too.large when exceeded","getRawBody validates expected length option and throws 400 request.size.invalid on mismatch","wrapper functions in index.js read stream buffers and strings correctly"],"goal":"verify pkg:npm/raw-body@2.5.2","kind":"HOW","packages":["pkg:npm/raw-body@2.5.2"],"schemaVersion":1},"contractCommand":["node","test/contract.mjs"],"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.2"],"schemaVersion":1,"subject":"pkg:npm/raw-body@2.5.2","verifierAdapter":"node-typescript@1"}
const getRawBody = require('raw-body');
/**
* Reads the full content of a readable stream into a Buffer.
*
* @param {import('node:stream').Readable} stream - The readable stream to consume.
* @param {Object} [options] - Options passed to raw-body (e.g. { limit, length }).
* @returns {Promise<Buffer>} The accumulated stream buffer.
*/
function readStreamBuffer(stream, options) {
return getRawBody(stream, options);
}
/**
* Reads the full content of a readable stream and decodes it as a string.
*
* @param {import('node:stream').Readable} stream - The readable stream to consume.
* @param {string} [encoding='utf-8'] - Character encoding.
* @param {Object} [options] - Additional options passed to raw-body.
* @returns {Promise<string>} The decoded string.
*/
function readStreamString(stream, encoding = 'utf-8', options = {}) {
return getRawBody(stream, { ...options, encoding });
}
/**
* Reads a stream with a strict maximum byte limit.
*
* @param {import('node:stream').Readable} stream - The readable stream to consume.
* @param {number|string} limit - Maximum allowed bytes or byte string (e.g. '10kb').
* @param {Object} [options] - Additional options passed to raw-body.
* @returns {Promise<Buffer|string>} The accumulated buffer or string.
*/
function readStreamWithLimit(stream, limit, options = {}) {
return getRawBody(stream, { ...options, limit });
}
module.exports = {
getRawBody,
readStreamBuffer,
readStreamString,
readStreamWithLimit,
};
{
"name": "sample-raw-body",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-raw-body",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"raw-body": "2.5.2"
}
},
"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.2",
"resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.2.tgz",
"integrity": "sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==",
"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"
}
}
}
}
{
"name": "sample-raw-body",
"version": "1.0.0",
"description": "Clean-room sample verifying pkg:npm/raw-body@2.5.2",
"main": "index.js",
"license": "MIT-0",
"dependencies": {
"raw-body": "2.5.2"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/raw-body@2.5.2",
"kind": "HOW",
"packages": [
"pkg:npm/raw-body@2.5.2"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
import assert from 'node:assert/strict';
import { Readable } from 'node:stream';
import getRawBody from 'raw-body';
import indexPkg from '../index.js';
const { readStreamBuffer, readStreamString, readStreamWithLimit } = indexPkg;
function createStream(chunks) {
return Readable.from(chunks.map(c => Buffer.isBuffer(c) ? c : Buffer.from(c)));
}
// 1. getRawBody is exported as a function
assert.equal(typeof getRawBody, 'function');
assert.equal(typeof readStreamBuffer, 'function');
assert.equal(typeof readStreamString, 'function');
assert.equal(typeof readStreamWithLimit, 'function');
// 2. getRawBody reads readable stream into a Buffer when encoding is not specified
{
const stream = createStream(['hello ', 'world']);
const result = await getRawBody(stream);
assert.equal(Buffer.isBuffer(result), true);
assert.equal(result.toString('utf-8'), 'hello world');
}
// 3. getRawBody decodes stream into a string when encoding is specified
{
const stream = createStream(['Unicode: 안녕 ', '세상 🚀']);
const result = await getRawBody(stream, { encoding: 'utf-8' });
assert.equal(typeof result, 'string');
assert.equal(result, 'Unicode: 안녕 세상 🚀');
}
// 4. getRawBody supports callback interface
{
const stream = createStream(['callback ', 'data']);
const result = await new Promise((resolve, reject) => {
getRawBody(stream, (err, res) => {
if (err) return reject(err);
resolve(res);
});
});
assert.equal(Buffer.isBuffer(result), true);
assert.equal(result.toString('utf-8'), 'callback data');
}
// 5. getRawBody enforces byte limit option and throws 413 entity.too.large when exceeded
{
const stream = createStream(['this payload is definitely longer than five bytes']);
let errorCaught = null;
try {
await getRawBody(stream, { limit: 5 });
} catch (err) {
errorCaught = err;
}
assert.notEqual(errorCaught, null);
assert.equal(errorCaught.status, 413);
assert.equal(errorCaught.type, 'entity.too.large');
}
// 6. getRawBody validates expected length option and throws 400 request.size.invalid on mismatch
{
const stream = createStream(['exact length test']);
let errorCaught = null;
try {
await getRawBody(stream, { length: 50 });
} catch (err) {
errorCaught = err;
}
assert.notEqual(errorCaught, null);
assert.equal(errorCaught.status, 400);
assert.equal(errorCaught.type, 'request.size.invalid');
}
// 7. wrapper functions in index.js read stream buffers and strings correctly
{
const stream1 = createStream(['buffer ', 'wrapper']);
const buf = await readStreamBuffer(stream1);
assert.equal(Buffer.isBuffer(buf), true);
assert.equal(buf.toString('utf-8'), 'buffer wrapper');
const stream2 = createStream(['string ', 'wrapper']);
const str = await readStreamString(stream2, 'utf-8');
assert.equal(typeof str, 'string');
assert.equal(str, 'string wrapper');
const stream3 = createStream(['limited']);
const limited = await readStreamWithLimit(stream3, 100);
assert.equal(limited.toString('utf-8'), 'limited');
}
console.log('All contract assertions passed.');
Seeder de origem
anônimo