サンプル
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
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。
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
コントラクト
- 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
ファイル
- PROMPT.md
- csx.json
- index.js
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
ソース
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.
{"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"}
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,
};
{
"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"
}
}
}
}
{
"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"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/accepts@1.3.8",
"kind": "HOW",
"packages": [
"pkg:npm/accepts@1.3.8"
]
}
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.');
オリジンシーダー
匿名