{"name":"@eggjs/cookies","version":"4.0.0-beta.16","author":{"url":"https://github.com/fengmk2","name":"fengmk2","email":"fengmk2@gmail.com"},"license":"MIT","_id":"@eggjs/cookies@4.0.0-beta.16","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":"akitasummer@outlook.com"}],"homepage":"https://github.com/eggjs/egg/tree/next/packages/cookies","bugs":{"url":"https://github.com/eggjs/egg/issues"},"dist":{"shasum":"7e8c0e08329b2628767b7cccdfa79696cc5ddaf0","tarball":"http://registry-npm.ywwl.com/@eggjs/cookies/download/@eggjs/cookies-4.0.0-beta.16.tgz","fileCount":14,"integrity":"sha512-X5uaa59coacW3b1cgd5YJArafQNK4FZM29lC+B/0hSii4B8jZ4/vElK4jzGxLsfulhMiFWb9O/l7Z1+i0rftgA==","signatures":[{"sig":"MEYCIQCJrVmTrTKmEY4tCtvJ+rLZT+wM6uY6BIzvJw8nu02dTAIhAOqsXKjou7DdHks4xaYArBoXVLZuWboUHnNfih1NYfYs","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@eggjs%2fcookies@4.0.0-beta.16","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":25439,"size":8824,"noattachment":false,"key":"/@eggjs/cookies/-/@eggjs/cookies-4.0.0-beta.16.tgz"},"main":"./dist/index.js","type":"module","_from":"file:eggjs-cookies-4.0.0-beta.16.tgz","types":"./dist/index.d.ts","module":"./dist/index.js","engines":{"node":">=22.18.0"},"exports":{".":"./dist/index.js","./package.json":"./package.json"},"scripts":{"ci":"vitest run --coverage","lint":"oxlint --type-aware","test":"npm run lint:fix && vitest run","build":"tsdown","lint:fix":"npm run lint -- --fix","typecheck":"tsc --noEmit"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:dec5895a-942e-4a7a-b521-175cf6fd9653"}},"_resolved":"/tmp/174023076aab3eb999e601dbc68226fd/eggjs-cookies-4.0.0-beta.16.tgz","_integrity":"sha512-X5uaa59coacW3b1cgd5YJArafQNK4FZM29lC+B/0hSii4B8jZ4/vElK4jzGxLsfulhMiFWb9O/l7Z1+i0rftgA==","repository":{"url":"git://github.com/eggjs/egg.git","type":"git","directory":"packages/cookies"},"_npmVersion":"11.6.1","description":"cookies module for egg","directories":{},"_nodeVersion":"22.19.0","dependencies":{"utility":"^2.5.0","should-send-same-site-none":"^2.0.5"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"readmeFilename":"README.zh-CN.md","devDependencies":{"oxlint":"^1.18.0","tsdown":"^0.15.4","cookies":"^0.9.1","keygrip":"^1.0.2","benchmark":"^2.1.4","typescript":"5.9.2","@eggjs/tsconfig":"3.1.0-beta.16","beautify-benchmark":"^0.2.4"},"_npmOperationalInternal":{"tmp":"tmp/cookies_4.0.0-beta.16_1759046730470_0.7884269543720963","host":"s3://npm-registry-packages-npm-production"},"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":1759046730686,"_cnpm_publish_time":1759046730686,"dist-tags":{"beta":"4.0.2-beta.27","latest":"4.1.0","rc":"4.0.2-rc.1"}}