CodeSampleX

샘플

raw-body 2.5.2

검증된 샘플 — npm raw-body 2.5.2. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: getRawBody is exported as a function

sha256:2a5f9caf50cd18ea15a8f226db470f6e6a82669f68bb2448e4195be5d692c093

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

검증 실행 환경

환경 컨트랙트 단계 실행일
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

케이스

HOW
목표
verify pkg:npm/raw-body@2.5.2
패키지
환경
node 22.23.2
생성일
2026-09-18T11:52:15Z

컨트랙트

  1. getRawBody is exported as a function
  2. getRawBody reads readable stream into a Buffer when encoding is not specified
  3. getRawBody decodes stream into a string when encoding is specified
  4. getRawBody supports callback interface
  5. getRawBody enforces byte limit option and throws 413 entity.too.large when exceeded
  6. getRawBody validates expected length option and throws 400 request.size.invalid on mismatch
  7. wrapper functions in index.js read stream buffers and strings correctly

파일

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

소스 아티팩트 내려받기 (tar.gz)

소스

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 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.
csx.json
{"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"}
index.js
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,
};
package-lock.json
{
  "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"
      }
    }
  }
}
package.json
{
  "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"
  }
}
spec.json
{
  "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"
  }
}
test/contract.mjs
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.');

오리진 시더

익명