Beispiel
cookie 1.1.1: serialize
Verifiziertes Beispiel für npm cookie 1.1.1: serialize. Der Vertrag lief auf node 22 · linux debian/x64 · docker und bestand: cookie.serialize formats…
sha256:48a20f6e9f6cc42f438b92b88cfc8839ae319214c5db5cc3dd9bde1cfcab9000
Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen.
Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen.
MIT-0
Ausführungsbelege
Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.
- Beleggrundlage
- Signierter Vertrag bestanden
- Verifizierungsbelege
- 1
- Signaturschlüssel, die es gebaut haben
- 1
Deklarierte Umgebung
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
Umgebungen der Verifizierungsläufe
| Umgebung | Contract | Stufen | Lauf |
|---|---|---|---|
| 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-06 |
Fall
HOW- Ziel
- verify cookie.serialize in pkg:npm/cookie@1.1.1
- Pakete
- Symbole
-
- cookie.serialize
- Umgebung
- node 22.23.2
- Erstellt
- 2026-09-06T01:15:05Z
Contract
- cookie.serialize formats name-value string pairs into standard HTTP Set-Cookie header format
- cookie.serialize accepts a SetCookie object containing name, value, and cookie attributes
- cookie.serialize encodes values using encodeURIComponent by default and supports custom encode functions
- cookie.serialize serializes standard attributes Path, Domain, HttpOnly, Secure, Max-Age, and UTC-formatted Expires
- cookie.serialize serializes SameSite attribute supporting boolean, strict, lax, and none values
- cookie.serialize serializes modern Partitioned boolean and Priority attributes
- cookie.serialize validates inputs throwing TypeError on invalid cookie names, unencoded invalid characters, or invalid option types
Dateien
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.js
Quelltext
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 cookie.serialize in pkg:npm/cookie@1.1.1
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/cookie@1.1.1
Demonstrate these symbols/APIs:
- cookie.serialize
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:0174ac5084b28561ca01f09baa0353a2902fb5098ce9f8140475684417ca1edb","constraints":{"executionContext":"node"},"contract":["cookie.serialize formats name-value string pairs into standard HTTP Set-Cookie header format","cookie.serialize accepts a SetCookie object containing name, value, and cookie attributes","cookie.serialize encodes values using encodeURIComponent by default and supports custom encode functions","cookie.serialize serializes standard attributes Path, Domain, HttpOnly, Secure, Max-Age, and UTC-formatted Expires","cookie.serialize serializes SameSite attribute supporting boolean, strict, lax, and none values","cookie.serialize serializes modern Partitioned boolean and Priority attributes","cookie.serialize validates inputs throwing TypeError on invalid cookie names, unencoded invalid characters, or invalid option types"],"goal":"verify cookie.serialize in pkg:npm/cookie@1.1.1","kind":"HOW","packages":["pkg:npm/cookie@1.1.1"],"schemaVersion":1,"symbols":["cookie.serialize"]},"contractCommand":["node","test/contract.js"],"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/cookie@1.1.1"],"schemaVersion":1,"subject":"pkg:npm/cookie@1.1.1","symbols":["cookie.serialize"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-cookie-serialize",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-cookie-serialize",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"cookie": "1.1.1"
}
},
"node_modules/cookie": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/cookie/-/cookie-1.1.1.tgz",
"integrity": "sha512-ei8Aos7ja0weRpFzJnEA9UHJ/7XQmqglbRwnf2ATjcB9Wq874VKH9kfjjirM6UhU2/E5fFYadylyhFldcqSidQ==",
"license": "MIT",
"engines": {
"node": ">=18"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
}
}
}
{
"name": "sample-cookie-serialize",
"version": "1.0.0",
"private": true,
"description": "Clean-room verification sample for cookie.serialize in cookie@1.1.1",
"main": "src/index.js",
"scripts": {
"test": "node test/contract.js"
},
"dependencies": {
"cookie": "1.1.1"
},
"license": "MIT-0"
}
{
"schemaVersion": 1,
"goal": "verify cookie.serialize in pkg:npm/cookie@1.1.1",
"kind": "HOW",
"packages": [
"pkg:npm/cookie@1.1.1"
],
"symbols": [
"cookie.serialize"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
const cookie = require('cookie');
function serialize(nameOrCookie, valueOrOptions, options) {
return cookie.serialize(nameOrCookie, valueOrOptions, options);
}
function serializeCookieObject(cookieObj, options) {
return cookie.serialize(cookieObj, options);
}
function serializeSessionCookie(name, value, maxAgeSeconds) {
return cookie.serialize(name, value, {
httpOnly: true,
secure: true,
sameSite: 'lax',
path: '/',
maxAge: maxAgeSeconds
});
}
module.exports = {
cookie,
serialize,
serializeCookieObject,
serializeSessionCookie
};
const assert = require('node:assert');
const cookie = require('cookie');
const {
serialize,
serializeCookieObject,
serializeSessionCookie
} = require('../src/index.js');
// 1. cookie.serialize formats name-value string pairs into standard HTTP Set-Cookie header format
const basic = cookie.serialize('session_id', 'abc123xyz');
assert.strictEqual(basic, 'session_id=abc123xyz');
assert.strictEqual(serialize('token', 'value99'), 'token=value99');
assert.strictEqual(cookie.serialize('empty_val', ''), 'empty_val=');
// 2. cookie.serialize accepts a SetCookie object containing name, value, and cookie attributes
const objCookie = cookie.serialize({
name: 'user_pref',
value: 'dark_theme',
path: '/settings',
secure: true
});
assert.strictEqual(objCookie, 'user_pref=dark_theme; Path=/settings; Secure');
assert.strictEqual(
serializeCookieObject({ name: 'theme', value: 'light' }),
'theme=light'
);
// 3. cookie.serialize encodes values using encodeURIComponent by default and supports custom encode functions
const encoded = cookie.serialize('query', 'hello world & more');
assert.strictEqual(encoded, 'query=hello%20world%20%26%20more');
const customEncoded = cookie.serialize('payload', 'hello world', {
encode: (val) => Buffer.from(val).toString('base64')
});
assert.strictEqual(customEncoded, 'payload=aGVsbG8gd29ybGQ=');
// 4. cookie.serialize serializes standard attributes Path, Domain, HttpOnly, Secure, Max-Age, and UTC-formatted Expires
const expireDate = new Date('2030-06-15T12:00:00.000Z');
const fullAttributes = cookie.serialize('session_token', 'sec789', {
path: '/admin',
domain: 'example.com',
maxAge: 3600,
expires: expireDate,
httpOnly: true,
secure: true
});
assert.strictEqual(
fullAttributes,
`session_token=sec789; Max-Age=3600; Domain=example.com; Path=/admin; Expires=${expireDate.toUTCString()}; HttpOnly; Secure`
);
assert.strictEqual(
serializeSessionCookie('auth', 'tok123', 86400),
'auth=tok123; Max-Age=86400; Path=/; HttpOnly; Secure; SameSite=Lax'
);
// 5. cookie.serialize serializes SameSite attribute supporting boolean, strict, lax, and none values
assert.strictEqual(
cookie.serialize('k1', 'v1', { sameSite: true }),
'k1=v1; SameSite=Strict'
);
assert.strictEqual(
cookie.serialize('k2', 'v2', { sameSite: 'strict' }),
'k2=v2; SameSite=Strict'
);
assert.strictEqual(
cookie.serialize('k3', 'v3', { sameSite: 'lax' }),
'k3=v3; SameSite=Lax'
);
assert.strictEqual(
cookie.serialize('k4', 'v4', { sameSite: 'none', secure: true }),
'k4=v4; Secure; SameSite=None'
);
// 6. cookie.serialize serializes modern Partitioned boolean and Priority attributes
const partitioned = cookie.serialize('cross_site_id', 'id42', {
partitioned: true,
secure: true
});
assert.strictEqual(partitioned, 'cross_site_id=id42; Secure; Partitioned');
assert.strictEqual(
cookie.serialize('p_low', '1', { priority: 'low' }),
'p_low=1; Priority=Low'
);
assert.strictEqual(
cookie.serialize('p_med', '2', { priority: 'medium' }),
'p_med=2; Priority=Medium'
);
assert.strictEqual(
cookie.serialize('p_high', '3', { priority: 'high' }),
'p_high=3; Priority=High'
);
// 7. cookie.serialize validates inputs throwing TypeError on invalid cookie names, unencoded invalid characters, or invalid option types
assert.throws(
() => cookie.serialize('invalid;name', 'val'),
/argument name is invalid/
);
assert.throws(
() => cookie.serialize('bad name', 'val'),
/argument name is invalid/
);
assert.throws(
() => cookie.serialize('val_err', 'invalid val with spaces', { encode: (v) => v }),
/argument val is invalid/
);
assert.throws(
() => cookie.serialize('name', 'val', { maxAge: 12.5 }),
/option maxAge is invalid/
);
assert.throws(
() => cookie.serialize('name', 'val', { domain: 'invalid domain' }),
/option domain is invalid/
);
assert.throws(
() => cookie.serialize('name', 'val', { sameSite: 'invalid_samesite' }),
/option sameSite is invalid/
);
assert.throws(
() => cookie.serialize('name', 'val', { priority: 'highest' }),
/option priority is invalid/
);
assert.throws(
() => cookie.serialize('name', 'val', { expires: new Date('invalid_date') }),
/option expires is invalid/
);
console.log('Contract tests passed successfully.');
process.exit(0);
Ursprungs-Seeder
anonym