{"name":"@eggjs/session","version":"5.0.0-beta.28","keywords":["egg","egg-plugin","eggPlugin","session","cookie"],"author":{"name":"dead_horse"},"_id":"@eggjs/session@5.0.0-beta.28","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/plugins/session#readme","bugs":{"url":"https://github.com/eggjs/egg/issues"},"dist":{"shasum":"1d2078225f8d08735c80ee1dc412b53386e0d535","tarball":"http://registry-npm.ywwl.com/@eggjs/session/download/@eggjs/session-5.0.0-beta.28.tgz","fileCount":15,"integrity":"sha512-YCBw7zbRgSJ82QFqxJAhZ4FzDAB1Xjwl0VYcf4XpKywKV8SOlZmcs5AaS0t5LqP55x9o4vuzJU4+mxyp7bxSIA==","signatures":[{"sig":"MEUCIQDyvjjRy3DR/aS10LngKZSHo/hul5M3FpjoYOtRj54w5gIgSZ7qYwOUNNY69jx1DNvPs412MLWe1LKexb6PWQw5V/g=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@eggjs%2fsession@5.0.0-beta.28","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":16855,"size":6013,"noattachment":false,"key":"/@eggjs/session/-/@eggjs/session-5.0.0-beta.28.tgz"},"main":"./dist/index.js","type":"module","_from":"file:eggjs-session-5.0.0-beta.28.tgz","types":"./dist/index.d.ts","module":"./dist/index.js","engines":{"node":">= 22.18.0"},"exports":{".":"./dist/index.js","./app":"./dist/app.js","./types":"./dist/types.js","./package.json":"./package.json","./config/config.default":"./dist/config/config.default.js","./app/extend/application":"./dist/app/extend/application.js","./app/middleware/session":"./dist/app/middleware/session.js"},"scripts":{"lint":"oxlint --type-aware","test":"npm run lint:fix && vitest","build":"tsdown && rimraf dist *.tsbuildinfo && tsc -p tsconfig.build.json","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:1500a3c4-3085-4b44-b062-17ba4eb49acd"}},"_resolved":"/tmp/d62a79de7fb9f30eccb46c4f78750600/eggjs-session-5.0.0-beta.28.tgz","eggPlugin":{"name":"session"},"_integrity":"sha512-YCBw7zbRgSJ82QFqxJAhZ4FzDAB1Xjwl0VYcf4XpKywKV8SOlZmcs5AaS0t5LqP55x9o4vuzJU4+mxyp7bxSIA==","repository":{"url":"git://github.com/eggjs/egg.git","type":"git","directory":"plugins/session"},"_npmVersion":"11.6.2","description":"session plugin for egg","directories":{},"_nodeVersion":"22.20.0","dependencies":{"zod":"^3.24.1","koa-session":"^7.0.2"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"tsdown":"^0.15.6","vitest":"4.0.0-beta.18","typescript":"^5.9.3","@eggjs/mock":"7.0.0-beta.28","@types/node":"^24.7.2","@eggjs/redis":"4.0.0-beta.28","@eggjs/tsconfig":"3.1.0-beta.28","@eggjs/supertest":"9.0.0-beta.28"},"peerDependencies":{"egg":"4.1.0-beta.28"},"_npmOperationalInternal":{"tmp":"tmp/session_5.0.0-beta.28_1760711588886_0.11152737424948511","host":"s3://npm-registry-packages-npm-production"},"readme":"# @eggjs/session\n\n[![NPM version][npm-image]][npm-url]\n[![Known Vulnerabilities][snyk-image]][snyk-url]\n[![npm download][download-image]][download-url]\n[![Node.js Version](https://img.shields.io/node/v/@eggjs/session.svg?style=flat)](https://nodejs.org/en/download/)\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://makeapullrequest.com)\n![CodeRabbit Pull Request Reviews](https://img.shields.io/coderabbit/prs/github/eggjs/session)\n\n[npm-image]: https://img.shields.io/npm/v/@eggjs/session.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/@eggjs/session\n[snyk-image]: https://snyk.io/test/npm/@eggjs/session/badge.svg?style=flat-square\n[snyk-url]: https://snyk.io/test/npm/@eggjs/session\n[download-image]: https://img.shields.io/npm/dm/@eggjs/session.svg?style=flat-square\n[download-url]: https://npmjs.org/package/@eggjs/session\n\nSession plugin for egg, based on [koa-session](https://github.com/koajs/session).\n\n## Usage\n\n`session` is a built-in plugin in egg and enabled by default.\n\n```js\n// {app_root}/config/plugin.js\nexports.session = true; // enable by default\n```\n\n### External Store\n\negg-session support external store, you can store your sessions in redis, memcached or other databases.\n\nFor example, if you want to store session in redis, you must:\n\n1. Dependent [@eggjs/redis](https://github.com/eggjs/egg/tree/next/plugins/redis)\n\n```bash\nnpm i --save @eggjs/redis\n```\n\n2. Import `@eggjs/redis` as a plugin and set the configuration\n\n```js\n// config/plugin.js\nexports.redis = {\n  enable: true,\n  package: '@eggjs/redis',\n};\n```\n\n```js\n// config/config.default.js\nexports.redis = {\n  // your redis configurations\n};\n```\n\n3. Implement a session store with redis\n\n```js\n// app.js\n\nmodule.exports = (app) => {\n  // set redis session store\n  // session store must have 3 methods\n  // define sessionStore in `app.js` so you can access `app.redis`\n  app.sessionStore = {\n    async get(key) {\n      const res = await app.redis.get(key);\n      if (!res) return null;\n      return JSON.parse(res);\n    },\n\n    async set(key, value, maxAge) {\n      // maxAge not present means session cookies\n      // we can't exactly know the maxAge and just set an appropriate value like one day\n      if (!maxAge) maxAge = 24 * 60 * 60 * 1000;\n      value = JSON.stringify(value);\n      await app.redis.set(key, value, 'PX', maxAge);\n    },\n\n    async destroy(key) {\n      await app.redis.del(key);\n    },\n  };\n\n  // session store can be a session store class\n  // app.sessionStore = class Store {\n  //   constructor(app) {\n  //     this.app = app;\n  //   }\n  //   async get() {}\n  //   async set() {}\n  //   async destroy() {}\n  // };\n};\n```\n\nOnce you use external session store, session is strong dependent on your external store, you can't access session if your external store is down. **Use external session stores only if necessary, avoid use session as a cache, keep session lean and stored by cookie!**\n\n## Configuration\n\nSupport all configurations in [koa-session](https://github.com/koajs/session).\n\n- logValue\n\n```bash\nSupport not to print the session value when session event trigger log. Default to be true.\n```\n\n[View the default configurations](https://github.com/eggjs/egg/tree/next/plugins/session/src/config/config.default.ts)\n\n## Questions & Suggestions\n\nPlease open an issue [here](https://github.com/eggjs/egg/issues).\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":1760711589070,"_cnpm_publish_time":1760711589070,"dist-tags":{"beta":"5.0.2-beta.27","latest":"5.1.0","rc":"5.0.2-rc.1"}}