サンプル
accepts 2.0.0
検証済みサンプル — npm accepts 2.0.0. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: accepts(req).types() negotiates acceptable media types and returns…
sha256:e44de29f7ad1f15f392f4eaa6155ef7360ea90f2a010dbed22b4ceb2cd99fe53
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。
MIT-0
実行証拠
宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。
- 証拠の基準
- 署名済みコントラクト合格
- 検証レシート
- 1
- ビルドした署名鍵
- 1
宣言された環境
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
検証実行環境
| 環境 | コントラクト | ステージ | 実行日 |
|---|---|---|---|
| node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1 |
2026-08-20 |
ケース
HOW- ゴール
- verify pkg:npm/accepts@2.0.0
- パッケージ
- 環境
- node 22.23.2
- 作成日
- 2026-08-20T13:16:26Z
コントラクト
- 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
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.cjs
ソース
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@2.0.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/accepts@2.0.0
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:5c73c68eecdb0447d3069e38611904aaa084f6afff2d175a4298f94c58dc5937","constraints":{"executionContext":"node"},"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@2.0.0","kind":"HOW","packages":["pkg:npm/accepts@2.0.0"],"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/accepts@2.0.0"],"schemaVersion":1,"verifierAdapter":"node-typescript@1"}
{
"name": "accepts-sample",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "accepts-sample",
"version": "1.0.0",
"dependencies": {
"accepts": "2.0.0"
}
},
"node_modules/accepts": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/accepts/-/accepts-2.0.0.tgz",
"integrity": "sha512-5cvg6CtKwfgdmVqY1WIiXKc3Q1bkRqGLi+2W/6ao+6Y7gu/RCwRuAhGEzh5B4KlszSuTLgZYuqFqo5bImjNKng==",
"license": "MIT",
"dependencies": {
"mime-types": "^3.0.0",
"negotiator": "^1.0.0"
},
"engines": {
"node": ">= 0.6"
}
},
"node_modules/mime-db": {
"version": "1.54.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.54.0.tgz",
"integrity": "sha512-aU5EJuIN2WDemCcAp2vFBfp/m4EAhWJnUNSSw0ixs7/kXbd6Pg64EmwJkNdFhB8aWt1sH2CTXrLxo/iAGV3oPQ==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/mime-types": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-3.0.2.tgz",
"integrity": "sha512-Lbgzdk0h4juoQ9fCKXW4by0UJqj+nOOrI9MJ1sSj4nI8aI2eo1qmvQEie4VD1glsS250n15LsWsYtCugiStS5A==",
"license": "MIT",
"dependencies": {
"mime-db": "^1.54.0"
},
"engines": {
"node": ">=18"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/negotiator": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-1.0.0.tgz",
"integrity": "sha512-8Ofs/AUQh8MaEcrlq5xOX0CQ9ypTF5dl78mjlMNfOK08fzpgTHQRQPBxcPlEtIw0yRpws+Zo/3r+5WRby7u3Gg==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
}
}
}
{
"name": "accepts-sample",
"version": "1.0.0",
"description": "Minimal sample verifying accepts",
"main": "src/index.js",
"scripts": {
"test": "node test/contract.cjs"
},
"dependencies": {
"accepts": "2.0.0"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/accepts@2.0.0",
"kind": "HOW",
"packages": [
"pkg:npm/accepts@2.0.0"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
'use strict';
const accepts = require('accepts');
/**
* Negotiates the best media type for a request given a list of candidate types.
*
* @param {object} req - HTTP request object with headers.
* @param {string|string[]} candidateTypes - Acceptable MIME types or extensions.
* @returns {string|false} - Best matching type or false.
*/
function negotiateType(req, candidateTypes) {
const accept = accepts(req);
return accept.type(candidateTypes);
}
/**
* Negotiates the best encoding for a request given a list of candidate encodings.
*
* @param {object} req - HTTP request object with headers.
* @param {string|string[]} candidateEncodings - Acceptable encodings (e.g. ['gzip', 'deflate', 'identity']).
* @returns {string|false} - Best matching encoding or false.
*/
function negotiateEncoding(req, candidateEncodings) {
const accept = accepts(req);
return accept.encoding(candidateEncodings);
}
/**
* Negotiates the best charset for a request given a list of candidate charsets.
*
* @param {object} req - HTTP request object with headers.
* @param {string|string[]} candidateCharsets - Acceptable charsets (e.g. ['utf-8', 'iso-8859-1']).
* @returns {string|false} - Best matching charset or false.
*/
function negotiateCharset(req, candidateCharsets) {
const accept = accepts(req);
return accept.charset(candidateCharsets);
}
/**
* Negotiates the best language for a request given a list of candidate languages.
*
* @param {object} req - HTTP request object with headers.
* @param {string|string[]} candidateLanguages - Acceptable languages (e.g. ['en', 'es', 'fr']).
* @returns {string|false} - Best matching language or false.
*/
function negotiateLanguage(req, candidateLanguages) {
const accept = accepts(req);
return accept.language(candidateLanguages);
}
module.exports = {
accepts,
negotiateType,
negotiateEncoding,
negotiateCharset,
negotiateLanguage,
};
const assert = require('node:assert/strict');
const accepts = require('accepts');
const {
negotiateType,
negotiateEncoding,
negotiateCharset,
negotiateLanguage,
} = require('../src/index.js');
function createMockReq(headers = {}) {
return {
headers: { ...headers },
};
}
async function main() {
// Contract 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'));
}
// Contract 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');
}
// Contract 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');
}
// Contract 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');
}
// Contract 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 contracts verified successfully.');
}
main().catch((err) => {
console.error(err);
process.exit(1);
});
オリジンシーダー
匿名