{"name":"@eggjs/cookies","version":"4.0.2","author":{"url":"https://github.com/fengmk2","name":"fengmk2","email":"fengmk2@gmail.com"},"license":"MIT","_id":"@eggjs/cookies@4.0.2","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"}],"homepage":"https://github.com/eggjs/egg/tree/next/packages/cookies","bugs":{"url":"https://github.com/eggjs/egg/issues"},"dist":{"shasum":"75b2873bdc0ed96b0212ab5efcd237a2f9779872","tarball":"http://registry-npm.ywwl.com/@eggjs/cookies/download/@eggjs/cookies-4.0.2.tgz","fileCount":14,"integrity":"sha512-thrMH5wCwUmslE2ppZ374mMB1BItgemmflXGaNrV5Mz83gMbF0fw6hxJC9ic8H7h95GCFHba5uyqeeGG2a6R3A==","signatures":[{"sig":"MEYCIQCcofORkONBR/7BHOKougNrjk8VXqocLCKmNieEkunE+wIhANpGe0HS/4bV1+xAvnrqNLwZYwVIUraQ4oZ3JhIbZ039","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"sig":"MEYCIQDp+vRNa5NVg7g+cnO0gI9OtPtE/slz84CnK5cbUYHvuQIhAMpStORPssnLvc66gbMGG9Agx0VhK7fIoXs/ieJBCH6X","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@eggjs%2fcookies@4.0.2","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":25025,"size":8644,"noattachment":false,"key":"/@eggjs/cookies/-/@eggjs/cookies-4.0.2.tgz"},"type":"module","types":"./dist/index.d.ts","engines":{"node":">=22.18.0"},"exports":{".":"./dist/index.js","./package.json":"./package.json"},"gitHead":"cd042a2c1fa06414f4f3290240a92a0e528b24c3","scripts":{"typecheck":"tsc --noEmit"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"c941292d-4aff-474b-a7aa-d2964f23ee9c"}},"repository":{"url":"git+https://github.com/eggjs/egg.git","type":"git","directory":"packages/cookies"},"_npmVersion":"11.19.0","description":"cookies module for egg","directories":{},"_nodeVersion":"24.21.0","dependencies":{"utility":"^2.5.0","should-send-same-site-none":"^2.0.5"},"publishConfig":{"access":"public","exports":{".":"./dist/index.js","./package.json":"./package.json"}},"_hasShrinkwrap":false,"devDependencies":{"cookies":"^0.9.1","keygrip":"^1.0.2","benchmark":"^2.1.4","typescript":"^7.0.2","@eggjs/tsconfig":"3.1.2","beautify-benchmark":"^0.2.4"},"_npmOperationalInternal":{"tmp":"tmp/cookies_4.0.2_1791297084361_0.886472662038762","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":1791297084456,"_cnpm_publish_time":1791297084456,"dist-tags":{"beta":"4.0.2-beta.27","latest":"4.1.0","rc":"4.0.2-rc.1"}}