{"name":"@eggjs/cookies","version":"4.0.2-beta.26","description":"cookies module for egg","homepage":"https://github.com/eggjs/egg/tree/next/packages/cookies","license":"MIT","author":{"name":"fengmk2","email":"fengmk2@gmail.com","url":"https://github.com/fengmk2"},"repository":{"type":"git","url":"git+https://github.com/eggjs/egg.git","directory":"packages/cookies"},"type":"module","main":"./dist/index.js","module":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":"./dist/index.js","./package.json":"./package.json"},"publishConfig":{"access":"public","exports":{".":"./dist/index.js","./package.json":"./package.json"}},"scripts":{"typecheck":"tsgo --noEmit"},"dependencies":{"should-send-same-site-none":"^2.0.5","utility":"^2.5.0"},"devDependencies":{"@eggjs/tsconfig":"3.1.2-beta.26","beautify-benchmark":"^0.2.4","benchmark":"^2.1.4","cookies":"^0.9.1","keygrip":"^1.0.2","typescript":"^5.9.3"},"engines":{"node":">=22.18.0"},"readmeFilename":"README.zh-CN.md","gitHead":"2b18475d501defd6f3b7b2c42e02426c1c3e0f84","_id":"@eggjs/cookies@4.0.2-beta.26","bugs":{"url":"https://github.com/eggjs/egg/issues"},"_nodeVersion":"24.19.0","_npmVersion":"11.17.0","dist":{"integrity":"sha512-4mJnl7dKKekExk9j3Q3yHlKjf8PaOOoeRr5DFLxD8TVzxOfKlXYgRUOBHRDCOF4/ujKe4FE8bJKycO8MZaV7dA==","shasum":"057e413c8c1c44ffdeac4871d1e3c3f29c851f0b","tarball":"http://registry-npm.ywwl.com/@eggjs/cookies/download/@eggjs/cookies-4.0.2-beta.26.tgz","fileCount":14,"unpackedSize":25159,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@eggjs%2fcookies@4.0.2-beta.26","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIBm93OE95aEYtpH0fFqBsE6LkaCoVkc626wCxdxl3yh6AiBhrKodAIta6uOLQFTHQE4rwXjFIF90tn+XNp+xhgMAzg=="}],"size":8680,"noattachment":false,"key":"/@eggjs/cookies/-/@eggjs/cookies-4.0.2-beta.26.tgz"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:dec5895a-942e-4a7a-b521-175cf6fd9653"}},"directories":{},"maintainers":[{"name":"gxkl","email":"gxkl203@gmail.com"},{"name":"eggjs-admin","email":"fengmk2+eggjs@gmail.com"},{"name":"fengmk2","email":"fengmk2@gmail.com"},{"name":"atian25","email":"atian25@qq.com"},{"name":"hyj1991","email":"yeekwanvong@gmail.com"},{"name":"killagu","email":"killa07071201@gmail.com"},{"name":"coolme200","email":"2001-wms@163.com"},{"name":"akitasummer","email":"644171127@qq.com"},{"name":"elrrrrrrr","email":"elrrrrrrr@gmail.com"},{"name":"niania","email":"ljracm@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/cookies_4.0.2-beta.26_1786086568422_0.17941178939065594"},"_hasShrinkwrap":false,"readme":"# @eggjs/cookies\n\n[![NPM version][npm-image]][npm-url]\n[![npm download][download-image]][download-url]\n\n[npm-image]: https://img.shields.io/npm/v/@eggjs/cookies.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/@eggjs/cookies\n[download-image]: https://img.shields.io/npm/dm/@eggjs/cookies.svg?style=flat-square\n[download-url]: https://npmjs.org/package/@eggjs/cookies\n\n为 egg 提供 cookie 操作的封装。\n\n```ts\nctx.cookies = new Cookies(ctx, keys[, defaultCookieOptions]);\n\nctx.cookies.get('key', 'value', options);\nctx.cookies.set('key', 'value', options);\n```\n\n## 初始化\n\n初始化时需要传递 Array 类型 的keys 参数，否则无法使用 cookies 的 `signed` 和 `encrypt` 功能。\n\n每次设置或读取 signed cookie 或者 encrypt cookie 的时候，会用 keys 进行加密。每次加密都通过 keys 数组的第一个 key 进行加密，解密会从先到后逐个 key 尝试解密。读取 signed cookie 时，如果发现不是用第一个 key 进行加密时，会更新签名为第一个 key 加密的值。读取 encrypt cookie 时不会进行更新操作。\n\n### `defaultCookieOptions`\n\n全局默认配置：\n\n- autoChips - `Boolean` 是否开启 [CHIPS](https://developers.google.com/privacy-sandbox/3pcd/chips#security_design) 的自动适配方案，\n  会自动给 Cookie 新增一个 `_CHIPS-` 为前缀的分区 Cookie，优先读取非分区 Cookie，读取失败则尝试读取 `_CHIPS-` 前缀的同名 Cookie 适配三方 Cookie 禁止逻辑。\n  一旦 `cookies.set` 设置 `partitioned=true`，那么会强制忽略 `autoChips` 参数。\n\n## 设置 cookie\n\n通过 `cookies.set(key, value, options)` 的方式来设置一个 cookie。其中 options 支持的参数有：\n\n- path - `String` cookie 的有效路径，默认为 `/`。\n- domain - `String` cookie 的有效域名范围，默认为 `undefined`。\n- expires - `Date` cookie 的失效时间。\n- maxAge - `Number` cookie 的最大有效时间，如果设置了 maxAge，将会覆盖 expires 的值。\n- secure - `Boolean` 是否只在加密信道中传输，注意，如果请求为 http 时，不允许设置为 `true`，https 时自动设置为 `true`。\n- partitioned - `Boolean` 是否设置独立分区状态（[CHIPS](https://developers.google.com/privacy-sandbox/3pcd/chips)）的 Cookie。注意，只有 `secure` 为 `true` 的时候此配置才会生效。\n- removeUnpartitioned - `Boolean` 是否删除非独立分区状态的同名 cookie。注意，只有 `partitioned` 为 `true` 的时候此配置才会生效。\n- httpOnly - `Boolean` 如果设置为 `true`，则浏览器中不允许读取这个 cookie 的值。\n- overwrite - `Boolean` 如果设置为 `true`，在一个请求上重复写入同一个 key 将覆盖前一次写入的值，默认为 `false`。\n- signed - `Boolean` 是否需要对 cookie 进行签名，需要配合 get 时传递 signed 参数，此时前端无法篡改这个 cookie，默认为 `true`。\n- encrypt - `Boolean` 是否需要对 cookie 进行加密，需要配合 get 时传递 encrypt 参数，此时前端无法读到真实的 cookie 值，默认为 `false`。\n- priority - `String` 表示 cookie 优先级的字符串，可以设置为 `'low'`, `'medium'`, `'high'`，默认为 `undefined`。[A Retention Priority Attribute for HTTP Cookies](https://datatracker.ietf.org/doc/html/draft-west-cookie-priority)\n\n## 读取 cookie\n\n通过 `cookies.get(key, value, options)` 的方式来读取一个 cookie。其中 options 支持的参数有：\n\n- signed - `Boolean` 是否需要对 cookie 进行验签，需要配合 set 时传递 signed 参数，此时前端无法篡改这个 cookie，默认为 true。\n- encrypt - `Boolean` 是否需要对 cookie 进行解密，需要配合 set 时传递 encrypt 参数，此时前端无法读到真实的 cookie 值，默认为 false。\n\n## 删除 cookie\n\n通过 `cookie.set(key, null)` 来删除一个 cookie。如果传递了 `signed` 参数，签名也会被删除。\n\n## License\n\n[MIT](LICENSE)\n\n## Contributors\n\n[![Contributors](https://contrib.rocks/image?repo=eggjs/egg)](https://github.com/eggjs/egg/graphs/contributors)\n\nMade with [contributors-img](https://contrib.rocks).\n","publish_time":1786086568601,"_cnpm_publish_time":1786086568601,"dist-tags":{"beta":"4.0.2-beta.27","latest":"4.1.0","rc":"4.0.2-rc.1"}}