{"name":"@eggjs/cookies","version":"3.1.0","engines":{"node":">= 18.19.0"},"publishConfig":{"access":"public"},"description":"cookies module for egg","dependencies":{"should-send-same-site-none":"^2.0.5","utility":"^2.1.0"},"devDependencies":{"beautify-benchmark":"^0.2.4","benchmark":"^2.1.4","cookies":"^0.7.1","keygrip":"^1.0.2","@arethetypeswrong/cli":"^0.15.3","@eggjs/tsconfig":"1","@types/node":"20","@types/mocha":"10","egg-bin":"6","eslint":"8","eslint-config-egg":"14","tshy":"1","tshy-after":"1","typescript":"5"},"repository":{"type":"git","url":"git://github.com/eggjs/egg-cookies.git"},"homepage":"https://github.com/eggjs/egg-cookies","author":{"name":"fengmk2","email":"fengmk2@gmail.com","url":"https://github.com/fengmk2"},"license":"MIT","scripts":{"lint":"eslint --cache src test --ext .ts","test":"npm run lint -- --fix && egg-bin test","ci":"npm run lint && egg-bin cov && npm run prepublishOnly && attw --pack","prepublishOnly":"tshy && tshy-after"},"type":"module","tshy":{"exports":{".":"./src/index.ts","./package.json":"./package.json"}},"exports":{".":{"import":{"source":"./src/index.ts","types":"./dist/esm/index.d.ts","default":"./dist/esm/index.js"},"require":{"source":"./src/index.ts","types":"./dist/commonjs/index.d.ts","default":"./dist/commonjs/index.js"}},"./package.json":"./package.json"},"types":"./dist/commonjs/index.d.ts","main":"./dist/commonjs/index.js","module":"./dist/esm/index.js","_id":"@eggjs/cookies@3.1.0","gitHead":"58ef4ea497a0eb4dd711d7e9751e56bc5fcee004","bugs":{"url":"https://github.com/eggjs/egg-cookies/issues"},"_nodeVersion":"20.18.1","_npmVersion":"10.8.2","dist":{"integrity":"sha512-rFDJqUHYanrsKWtVqYutVYjQSgi60MSYagdG0N5795vGd9LyJdxFQCG9dMOWUzHumRMfxFi4EjcjDZA+CcErdw==","shasum":"a143c0ea366e5a10884fe166f32d5329328c9cd9","tarball":"http://registry-npm.ywwl.com/@eggjs/cookies/download/@eggjs/cookies-3.1.0.tgz","fileCount":32,"unpackedSize":119407,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@eggjs%2fcookies@3.1.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDwsO7P4bZ08cVQbtYTNDNxATRkQeASVbQ+JAqsyRmd7wIhANiVv2/rfTpPZb1IKXR4feaK6xJBxuIrwz6djpegQlPw"}],"size":25039,"noattachment":false,"key":"/@eggjs/cookies/-/@eggjs/cookies-3.1.0.tgz"},"_npmUser":{"name":"fengmk2","email":"fengmk2@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/cookies_3.1.0_1735200561498_0.9797222123300067"},"_hasShrinkwrap":false,"readme":"# @eggjs/cookies\n\n[![NPM version][npm-image]][npm-url]\n[![build status][ci-image]][ci-url]\n[![Test coverage][codecov-image]][codecov-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[ci-image]: https://github.com/eggjs/egg-cookies/actions/workflows/nodejs.yml/badge.svg\n[ci-url]: https://github.com/eggjs/egg-cookies/actions/workflows/nodejs.yml\n[codecov-image]: https://codecov.io/gh/eggjs/egg-cookies/branch/master/graph/badge.svg\n[codecov-url]: https://codecov.io/gh/eggjs/egg-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-cookies)](https://github.com/eggjs/egg-cookies/graphs/contributors)\n\nMade with [contributors-img](https://contrib.rocks).\n","publish_time":1735200561686,"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":"dead_horse","email":"dead_horse@qq.com"},{"name":"wanghx","email":"whxaxes@gmail.com"},{"name":"hyj1991","email":"yeekwanvong@gmail.com"},{"name":"killagu","email":"killa07071201@gmail.com"},{"name":"coolme200","email":"2001-wms@163.com"},{"name":"mansonchor.zzw","email":"mansonchor1987@gmail.com"},{"name":"hubcarl","email":"hubcarl@126.com"},{"name":"gemwuu","email":"gemwuu@gmail.com"},{"name":"akitasummer","email":"644171127@qq.com"}],"_cnpm_publish_time":1735200561686,"dist-tags":{"beta":"4.0.2-beta.27","latest":"4.1.0","rc":"4.0.2-rc.1"}}