CodeSampleX

Sample

accepts 2.0.0

Verified sample for npm accepts 2.0.0. The contract ran on node 22 · linux alpine/x64 · docker and passed: accepts(req).types() negotiates acceptable media…

sha256:e44de29f7ad1f15f392f4eaa6155ef7360ea90f2a010dbed22b4ceb2cd99fe53

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Verification-run environments

Environment Contract Stages Run
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

Case

HOW
Goal
verify pkg:npm/accepts@2.0.0
Packages
Environment
node 22.23.2
Created
2026-08-20T13:16:26Z

Contract

  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

Files

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

Download the source artifact (tar.gz)

Source

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

Origin Seeder

anonymous