CodeSampleX

샘플

accepts 1.3.8

검증된 샘플 — npm accepts 1.3.8. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: accepts(req).types() negotiates acceptable media types and returns…

sha256:760b58a9e85132934a4cee339b0cfe5b70bfbd2e26cb7dcdbc5daccba8e22e7c

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

실행 증거

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

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

검증 실행 환경

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

케이스

HOW
목표
verify pkg:npm/accepts@1.3.8
패키지
생성일
2026-09-16T22:04:38Z

컨트랙트

  1. accepts(req).types() negotiates acceptable media types and returns the best match or false when unmatched
  2. accepts(req).encodings() negotiates acceptable transfer/content encodings based on Accept-Encoding header
  3. accepts(req).charsets() negotiates acceptable character sets based on Accept-Charset header
  4. accepts(req).languages() negotiates acceptable languages based on Accept-Language header
  5. accepts handles requests with missing headers by returning default fallback or full preferred list

파일

  • 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/accepts@1.3.8
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/accepts@1.3.8

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:cc206bad6fcc504953715fd1f1f31d9f7cf66e7cdff1994e83d968e83cb7e831","contract":["accepts(req).types() negotiates acceptable media types and returns the best match or false when unmatched","accepts(req).encodings() negotiates acceptable transfer/content encodings based on Accept-Encoding header","accepts(req).charsets() negotiates acceptable character sets based on Accept-Charset header","accepts(req).languages() negotiates acceptable languages based on Accept-Language header","accepts handles requests with missing headers by returning default fallback or full preferred list"],"goal":"verify pkg:npm/accepts@1.3.8","kind":"HOW","packages":["pkg:npm/accepts@1.3.8"],"schemaVersion":1},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/accepts@1.3.8"],"schemaVersion":1,"subject":"pkg:npm/accepts@1.3.8","verifierAdapter":"node-typescript@1"}
index.js
const accepts = require('accepts');

/**
 * Negotiates acceptable media types for an HTTP request.
 *
 * @param {object} req - HTTP request object containing headers.
 * @param {string|string[]} [types] - Acceptable media types or extensions.
 * @returns {string|string[]|false} - Matching type, array of preferred types, or false.
 */
function negotiateType(req, types) {
  const accept = accepts(req);
  return types !== undefined ? accept.type(types) : accept.types();
}

/**
 * Negotiates acceptable encodings for an HTTP request.
 *
 * @param {object} req - HTTP request object containing headers.
 * @param {string|string[]} [encodings] - Acceptable encodings.
 * @returns {string|string[]|false} - Matching encoding, array of preferred encodings, or false.
 */
function negotiateEncoding(req, encodings) {
  const accept = accepts(req);
  return encodings !== undefined ? accept.encoding(encodings) : accept.encodings();
}

/**
 * Negotiates acceptable character sets for an HTTP request.
 *
 * @param {object} req - HTTP request object containing headers.
 * @param {string|string[]} [charsets] - Acceptable charsets.
 * @returns {string|string[]|false} - Matching charset, array of preferred charsets, or false.
 */
function negotiateCharset(req, charsets) {
  const accept = accepts(req);
  return charsets !== undefined ? accept.charset(charsets) : accept.charsets();
}

/**
 * Negotiates acceptable languages for an HTTP request.
 *
 * @param {object} req - HTTP request object containing headers.
 * @param {string|string[]} [languages] - Acceptable languages.
 * @returns {string|string[]|false} - Matching language, array of preferred languages, or false.
 */
function negotiateLanguage(req, languages) {
  const accept = accepts(req);
  return languages !== undefined ? accept.language(languages) : accept.languages();
}

module.exports = {
  accepts,
  negotiateType,
  negotiateEncoding,
  negotiateCharset,
  negotiateLanguage,
};
package-lock.json
{
  "name": "sample-accepts",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-accepts",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "accepts": "1.3.8"
      }
    },
    "node_modules/accepts": {
      "version": "1.3.8",
      "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz",
      "integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==",
      "license": "MIT",
      "dependencies": {
        "mime-types": "~2.1.34",
        "negotiator": "0.6.3"
      },
      "engines": {
        "node": ">= 0.6"
      }
    },
    "node_modules/mime-db": {
      "version": "1.52.0",
      "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
      "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.6"
      }
    },
    "node_modules/mime-types": {
      "version": "2.1.35",
      "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
      "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
      "license": "MIT",
      "dependencies": {
        "mime-db": "1.52.0"
      },
      "engines": {
        "node": ">= 0.6"
      }
    },
    "node_modules/negotiator": {
      "version": "0.6.3",
      "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz",
      "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.6"
      }
    }
  }
}
package.json
{
  "name": "sample-accepts",
  "version": "1.0.0",
  "description": "Clean-room sample verifying pkg:npm/accepts@1.3.8 functionality",
  "main": "index.js",
  "license": "MIT-0",
  "dependencies": {
    "accepts": "1.3.8"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/accepts@1.3.8",
  "kind": "HOW",
  "packages": [
    "pkg:npm/accepts@1.3.8"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import accepts from 'accepts';
import sample from '../index.js';

const {
  negotiateType,
  negotiateEncoding,
  negotiateCharset,
  negotiateLanguage,
} = sample;

function createMockReq(headers = {}) {
  return {
    headers: { ...headers },
  };
}

// 1. accepts(req).types() negotiates acceptable media types and returns the best match or false when unmatched
{
  const req1 = createMockReq({
    accept: 'text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, */*;q=0.8',
  });
  const accept1 = accepts(req1);
  assert.strictEqual(accept1.type(['json', 'html']), 'html');
  assert.strictEqual(accept1.type('application/json', 'text/html'), 'text/html');
  assert.strictEqual(negotiateType(req1, ['json', 'html']), 'html');

  const reqJson = createMockReq({ accept: 'application/json, text/plain' });
  const acceptJson = accepts(reqJson);
  assert.strictEqual(acceptJson.type(['html', 'json']), 'json');
  assert.strictEqual(negotiateType(reqJson, ['html', 'json']), 'json');

  const reqNone = createMockReq({ accept: 'image/png' });
  const acceptNone = accepts(reqNone);
  assert.strictEqual(acceptNone.type(['html', 'json']), false);
  assert.strictEqual(negotiateType(reqNone, ['html', 'json']), false);

  const allTypes = accept1.types();
  assert.ok(Array.isArray(allTypes));
  assert.ok(allTypes.includes('text/html'));
}

// 2. accepts(req).encodings() negotiates acceptable transfer/content encodings based on Accept-Encoding header
{
  const req = createMockReq({
    'accept-encoding': 'gzip, deflate, br;q=0.5',
  });
  const accept = accepts(req);

  assert.strictEqual(accept.encoding(['gzip', 'identity']), 'gzip');
  assert.strictEqual(accept.encoding(['br', 'deflate']), 'deflate');
  assert.strictEqual(accept.encoding('compress'), false);

  assert.strictEqual(negotiateEncoding(req, ['gzip', 'identity']), 'gzip');
  assert.strictEqual(negotiateEncoding(req, ['br', 'deflate']), 'deflate');
  assert.strictEqual(negotiateEncoding(req, ['compress']), false);

  const allEncodings = accept.encodings();
  assert.ok(Array.isArray(allEncodings));
  assert.strictEqual(allEncodings[0], 'gzip');
}

// 3. accepts(req).charsets() negotiates acceptable character sets based on Accept-Charset header
{
  const req = createMockReq({
    'accept-charset': 'utf-8, iso-8859-1;q=0.8, utf-16;q=0.2',
  });
  const accept = accepts(req);

  assert.strictEqual(accept.charset(['utf-8', 'iso-8859-1']), 'utf-8');
  assert.strictEqual(accept.charset(['iso-8859-1', 'utf-16']), 'iso-8859-1');
  assert.strictEqual(accept.charset(['windows-1252']), false);

  assert.strictEqual(negotiateCharset(req, ['utf-8', 'iso-8859-1']), 'utf-8');
  assert.strictEqual(negotiateCharset(req, ['iso-8859-1', 'utf-16']), 'iso-8859-1');
  assert.strictEqual(negotiateCharset(req, ['windows-1252']), false);

  const allCharsets = accept.charsets();
  assert.ok(Array.isArray(allCharsets));
  assert.strictEqual(allCharsets[0], 'utf-8');
}

// 4. accepts(req).languages() negotiates acceptable languages based on Accept-Language header
{
  const req = createMockReq({
    'accept-language': 'en-US, en;q=0.9, ko;q=0.8, fr;q=0.7',
  });
  const accept = accepts(req);

  assert.strictEqual(accept.language(['en-US', 'ko']), 'en-US');
  assert.strictEqual(accept.language(['ko', 'fr']), 'ko');
  assert.strictEqual(accept.language(['de', 'ja']), false);

  assert.strictEqual(negotiateLanguage(req, ['en-US', 'ko']), 'en-US');
  assert.strictEqual(negotiateLanguage(req, ['ko', 'fr']), 'ko');
  assert.strictEqual(negotiateLanguage(req, ['de', 'ja']), false);

  const allLangs = accept.languages();
  assert.ok(Array.isArray(allLangs));
  assert.strictEqual(allLangs[0], 'en-US');
}

// 5. accepts handles requests with missing headers by returning default fallback or full preferred list
{
  const emptyReq = createMockReq({});
  const accept = accepts(emptyReq);

  // When no Accept header, first provided type is returned as fallback
  assert.strictEqual(accept.type(['application/json', 'text/html']), 'application/json');
  assert.strictEqual(negotiateType(emptyReq, ['application/json', 'text/html']), 'application/json');

  // When no encodings requested, identity is accepted
  assert.strictEqual(accept.encoding(['gzip', 'identity']), 'identity');

  // When no charset header, first provided charset is returned
  assert.strictEqual(accept.charset(['utf-8', 'iso-8859-1']), 'utf-8');

  // When no language header, first provided language is returned
  assert.strictEqual(accept.language(['en', 'ko']), 'en');
}

console.log('All contract assertions passed.');

오리진 시더

익명