Exemplo
raw-body 2.5.1
Amostra verificada para npm raw-body 2.5.1. O contrato rodou em node 22 · linux debian/x64 · docker e passou: getRawBody(stream) resolves to a concatenated…
sha256:29fe83c3c8b38191db8e7d80d44a0d38c0c234804aabc315a77ace6ed45c2f9f
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-11-21 |
Caso
HOW- Objetivo
- verify pkg:npm/raw-body@2.5.1
- Pacotes
- Ambiente
- node 22.23.2
- Criado
- 2026-11-21T18:42:05Z
Contrato
- getRawBody(stream) resolves to a concatenated Buffer when no encoding option is given
- getRawBody(stream, 'utf-8') and encoding: true decode multi-byte UTF-8 chunks into a string
- getRawBody(stream, options, callback) invokes callback(null, decodedString) when length and limit match
- exceeding limit rejects with status 413 and type 'entity.too.large'
- mismatched length rejects with status 400, type 'request.size.invalid', expected and received byte counts
- unsupported encoding rejects with status 415 and type 'encoding.unsupported'
- stream with setEncoding() already applied rejects with status 500 and type 'stream.encoding.set'
- stream emitting 'aborted' before end rejects with status 400, code 'ECONNABORTED', and type 'request.aborted'
- passing a non-function third argument throws a synchronous TypeError
Arquivos
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.cjs
- test/contract.cjs
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.1
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/raw-body@2.5.1
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:6596b54db41dcbc91f3ef1bd912c9e916dc7e95f2dc14bdac44c70587649c76d","constraints":{"executionContext":"node"},"contract":["getRawBody(stream) resolves to a concatenated Buffer when no encoding option is given","getRawBody(stream, 'utf-8') and encoding: true decode multi-byte UTF-8 chunks into a string","getRawBody(stream, options, callback) invokes callback(null, decodedString) when length and limit match","exceeding limit rejects with status 413 and type 'entity.too.large'","mismatched length rejects with status 400, type 'request.size.invalid', expected and received byte counts","unsupported encoding rejects with status 415 and type 'encoding.unsupported'","stream with setEncoding() already applied rejects with status 500 and type 'stream.encoding.set'","stream emitting 'aborted' before end rejects with status 400, code 'ECONNABORTED', and type 'request.aborted'","passing a non-function third argument throws a synchronous TypeError"],"goal":"verify pkg:npm/raw-body@2.5.1","kind":"HOW","packages":["pkg:npm/raw-body@2.5.1"],"schemaVersion":1},"contractCommand":["node","test/contract.cjs"],"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","verifierAdapter":"node-typescript@1"}
{
"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"
}
}
}
}
{
"name": "raw-body-sample",
"version": "1.0.0",
"private": true,
"license": "MIT-0",
"scripts": {
"test": "node test/contract.cjs"
},
"dependencies": {
"raw-body": "2.5.1"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/raw-body@2.5.1",
"kind": "HOW",
"packages": [
"pkg:npm/raw-body@2.5.1"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
'use strict';
const getRawBody = require('raw-body');
function readBuffer(stream, options) {
return getRawBody(stream, options);
}
function readUtf8(stream, options) {
if (!options) {
return getRawBody(stream, 'utf-8');
}
return getRawBody(stream, Object.assign({ encoding: true }, options));
}
function readWithCallback(stream, options, callback) {
return getRawBody(stream, options, callback);
}
module.exports = {
readBuffer,
readUtf8,
readWithCallback,
};
'use strict';
const assert = require('node:assert/strict');
const { Readable } = require('node:stream');
const getRawBody = require('raw-body');
const { readBuffer, readUtf8, readWithCallback } = require('../src/index.cjs');
function streamFromChunks(chunks) {
return Readable.from(chunks);
}
async function main() {
// 1. Default promise mode returns concatenated Buffer
const buf = await readBuffer(
streamFromChunks([Buffer.from('hello '), Buffer.from('world')])
);
assert.ok(Buffer.isBuffer(buf));
assert.equal(buf.toString('utf8'), 'hello world');
// 2. Encoding string shortcut and multi-byte UTF-8 split across chunks
const utf8Bytes = Buffer.from('caf\u00e9-\u2603', 'utf8');
const splitChunks = [utf8Bytes.subarray(0, 4), utf8Bytes.subarray(4)];
const decoded = await readUtf8(streamFromChunks(splitChunks));
assert.equal(typeof decoded, 'string');
assert.equal(decoded, 'caf\u00e9-\u2603');
// 3. encoding: true with exact length and bytes-string limit succeeds
const exact = await readUtf8(streamFromChunks([Buffer.from('payload')]), {
length: 7,
limit: '1kb',
});
assert.equal(exact, 'payload');
// 4. Classic callback style returns decoded string
const cbResult = await new Promise((resolve, reject) => {
readWithCallback(
streamFromChunks([Buffer.from('callback-ok')]),
{ encoding: 'utf-8', length: 11, limit: 64 },
(err, str) => {
if (err) return reject(err);
resolve(str);
}
);
});
assert.equal(cbResult, 'callback-ok');
// 5. Rejects with 413 entity.too.large when stream exceeds limit
await assert.rejects(
() =>
getRawBody(streamFromChunks([Buffer.from('0123456789')]), {
limit: 5,
}),
(err) => {
assert.equal(err.status, 413);
assert.equal(err.statusCode, 413);
assert.equal(err.type, 'entity.too.large');
assert.equal(err.limit, 5);
return true;
}
);
// 6. Rejects with 400 request.size.invalid when received length mismatches expected length
await assert.rejects(
() =>
getRawBody(streamFromChunks([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.received, 5);
return true;
}
);
// 7. Rejects with 415 encoding.unsupported for unknown encoding
await assert.rejects(
() =>
getRawBody(streamFromChunks([Buffer.from('data')]), {
encoding: 'not-a-real-encoding',
}),
(err) => {
assert.equal(err.status, 415);
assert.equal(err.statusCode, 415);
assert.equal(err.type, 'encoding.unsupported');
assert.equal(err.encoding, 'not-a-real-encoding');
return true;
}
);
// 8. Rejects with 500 stream.encoding.set when stream already has encoding set
const encodedStream = new Readable({
read() {
this.push('text');
this.push(null);
},
});
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;
}
);
// 9. Rejects with 400 request.aborted when stream emits aborted before ending
const abortingStream = new Readable({
read() {},
});
const abortPromise = getRawBody(abortingStream, { length: 10 });
abortingStream.push(Buffer.from('part'));
abortingStream.emit('aborted');
await assert.rejects(
() => abortPromise,
(err) => {
assert.equal(err.status, 400);
assert.equal(err.code, 'ECONNABORTED');
assert.equal(err.type, 'request.aborted');
return true;
}
);
// 10. Non-function callback throws TypeError synchronously
assert.throws(
() => getRawBody(streamFromChunks([Buffer.from('x')]), {}, 'not-a-fn'),
{
name: 'TypeError',
message: 'argument callback must be a function',
}
);
}
main().catch((err) => {
console.error(err);
process.exit(1);
});
Seeder de origem
anônimo