@midwayjs/session 3.0.3 → 3.0.4-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,19 +1,18 @@
1
1
  {
2
2
  "name": "@midwayjs/session",
3
3
  "description": "midway session component for koa and faas",
4
- "version": "3.0.3",
4
+ "version": "3.0.4-beta.1",
5
5
  "main": "dist/index",
6
6
  "typings": "index.d.ts",
7
7
  "files": [
8
8
  "dist/**/*.js",
9
9
  "dist/**/*.d.ts",
10
- "index.d.ts",
11
- "dist/**/*.js.map"
10
+ "index.d.ts"
12
11
  ],
13
12
  "devDependencies": {
14
- "@midwayjs/core": "^3.0.2",
15
- "@midwayjs/decorator": "^3.0.2",
16
- "@midwayjs/mock": "^3.0.2"
13
+ "@midwayjs/core": "^3.0.4-beta.1",
14
+ "@midwayjs/decorator": "^3.0.4-beta.1",
15
+ "@midwayjs/mock": "^3.0.4-beta.1"
17
16
  },
18
17
  "dependencies": {
19
18
  "@midwayjs/cookies": "1.0.1"
@@ -41,5 +40,5 @@
41
40
  "type": "git",
42
41
  "url": "https://github.com/midwayjs/midway.git"
43
42
  },
44
- "gitHead": "43a5971b284aa918d22d191236c5664b011f8d87"
43
+ "gitHead": "52bc37e7a570806c121b33a0e8ac1cd084445f5d"
45
44
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.default.js","sourceRoot":"","sources":["../../src/config/config.default.ts"],"names":[],"mappings":";;;AAAa,QAAA,OAAO,GAAG;IACrB,MAAM,EAAE,IAAI;IACZ,MAAM,EAAE,EAAE,GAAG,IAAI,GAAG,IAAI;IACxB,GAAG,EAAE,SAAS;IACd,QAAQ,EAAE,IAAI;IACd,kBAAkB;IAClB,QAAQ,EAAE,IAAI;CACf,CAAC","sourcesContent":["export const session = {\n enable: true,\n maxAge: 24 * 3600 * 1000, // ms\n key: 'MW_SESS',\n httpOnly: true,\n // sameSite: null,\n logValue: true,\n};\n"]}
@@ -1 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aAAa,CAAC,2BAAiB,CAAC,CAAC;YACvC,CAAC,CAAC,CAAC;SACJ;IACH,CAAC;CACF,CAAA;AApCC;IADC,IAAA,kBAAM,GAAE;8BACW,+BAAwB;gEAAC;AAG7C;IADC,IAAA,kBAAM,EAAC,YAAY,CAAC;;oDACd;AAGP;IADC,IAAA,kBAAM,EAAC,SAAS,CAAC;;2DACJ;AARH,oBAAoB;IARhC,IAAA,yBAAa,EAAC;QACb,SAAS,EAAE,SAAS;QACpB,aAAa,EAAE;YACb;gBACE,OAAO,EAAE,aAAa;aACvB;SACF;KACF,CAAC;GACW,oBAAoB,CAsChC;AAtCY,oDAAoB","sourcesContent":["import { Config, Configuration, Inject, Logger } from '@midwayjs/decorator';\nimport * as DefaultConfig from './config/config.default';\nimport { SessionMiddleware } from './middleware/session';\nimport { MidwayApplicationManager } from '@midwayjs/core';\n\n@Configuration({\n namespace: 'session',\n importConfigs: [\n {\n default: DefaultConfig,\n },\n ],\n})\nexport class SessionConfiguration {\n @Inject()\n applicationManager: MidwayApplicationManager;\n\n @Logger('coreLogger')\n logger;\n\n @Config('session')\n sessionConfig;\n\n async onReady() {\n if (this.sessionConfig.enable) {\n this.applicationManager.getApplications(['koa', 'faas']).forEach(app => {\n if ((app as any).on) {\n // listen on session's events\n (app as any).on('session:missed', ({ ctx, key }) => {\n this.logger.warn('[session][missed] key(%s)', key);\n });\n (app as any).on('session:expired', ({ ctx, key, value }) => {\n this.logger.warn(\n '[session][expired] key(%s) value(%j)',\n key,\n this.sessionConfig.logValue ? value : ''\n );\n });\n (app as any).on('session:invalid', ({ ctx, key, value }) => {\n this.logger.warn(\n '[session][invalid] key(%s) value(%j)',\n key,\n this.sessionConfig.logValue ? value : ''\n );\n });\n }\n\n app.useMiddleware(SessionMiddleware);\n });\n }\n }\n}\n"]}
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,iDAAwE;AAA/D,8GAAA,oBAAoB,OAAiB;AAC9C,uDAAqC;AACrC,8CAA4B","sourcesContent":["export * from './interface';\nexport { SessionConfiguration as Configuration } from './configuration';\nexport * from './middleware/session';\nexport * from './lib/store';\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"interface.js","sourceRoot":"","sources":["../src/interface.ts"],"names":[],"mappings":";;;AAsHA,MAAsB,YAAY;CAIjC;AAJD,oCAIC","sourcesContent":["import { CookieSetOptions } from '@midwayjs/cookies';\nimport { opts } from 'koa-session';\n\nexport interface ISession {\n /**\n * JSON representation of the session.\n */\n toJSON(): object;\n\n /**\n * Return how many values there are in the session object.\n * Used to see if it\"s \"populated\".\n */\n readonly length: number;\n\n /**\n * populated flag, which is just a boolean alias of .length.\n */\n readonly populated: boolean;\n\n /**\n * get/set session maxAge\n */\n maxAge: opts[\"maxAge\"];\n\n /**\n * save this session no matter whether it is populated\n */\n save(): void;\n\n /**\n * allow to put any value on session object\n */\n [_: string]: any;\n}\n\ninterface ExternalKeys {\n /**\n * get session object by key\n */\n get(ctx: any): string;\n\n /**\n * set session object for key, with a maxAge (in ms)\n */\n set(ctx: any, value: any): void;\n}\n\nexport interface SessionOptions extends Omit<CookieSetOptions, 'maxAge'> {\n enable: boolean;\n /**\n * cookie key (default is koa:sess)\n */\n key: string;\n\n /**\n * maxAge in ms (default is 1 days)\n * \"session\" will result in a cookie that expires when session/browser is closed\n * Warning: If a session cookie is stolen, this cookie will never expire\n */\n maxAge?: number | \"session\" | undefined;\n\n /**\n * custom encode method\n */\n encode: (str: string) => Record<any, any>;\n\n /**\n * custom decode method\n */\n decode: (obj: Record<any, any>) => string;\n\n /**\n * The way of generating external session id is controlled by the options.genid, which defaults to Date.now() + \"-\" + uid.sync(24).\n */\n genid: () => string;\n\n /**\n * Force a session identifier cookie to be set on every response. The expiration is reset to the original maxAge, resetting the expiration countdown. default is false\n */\n rolling?: boolean | undefined;\n\n /**\n * Renew session when session is nearly expired, so we can always keep user logged in. (default is false)\n */\n renew?: boolean | undefined;\n\n /**\n * External key is used the cookie by default,\n * but you can use options.externalKey to customize your own external key methods.\n */\n externalKey?: ExternalKeys | undefined;\n\n /**\n * If your session store requires data or utilities from context, opts.ContextStore is alse supported.\n * ContextStore must be a class which claims three instance methods demonstrated above.\n * new ContextStore(ctx) will be executed on every request.\n */\n ContextStore?: { new(ctx: any): SessionStore } | undefined;\n\n /**\n * If you want to add prefix for all external session id, you can use options.prefix, it will not work if options.genid present.\n */\n prefix?: string | undefined;\n\n /**\n * Hook: valid session value before use it\n */\n valid?(ctx: any, session: Partial<ISession>): void;\n\n /**\n * Hook: before save session\n */\n beforeSave?(ctx: any, session: ISession): void;\n\n autoCommit: boolean;\n}\n\nexport abstract class SessionStore {\n abstract get(key: string);\n abstract set(key: string, value: string, maxAge: number);\n abstract destroy(key);\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/lib/context.ts"],"names":[],"mappings":";;;AAAA,+BAAgC;AAChC,iCAAwD;AACxD,uCAAoC;AACpC,MAAM,KAAK,GAAG,IAAA,eAAQ,EAAC,iBAAiB,CAAC,CAAC;AAE1C,MAAa,cAAc;IASzB;;;OAGG;IACH,YAAY,GAAG,EAAE,IAAI;QACnB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;QACpC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,YAAY;YACjC,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC;YACjC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;IACtB,CAAC;IAED;;;;;OAKG;IAEH,GAAG;QACD,MAAM,OAAO,GAAG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AAC,QAAQ,GAAG,IAAI,CAAC;SACtB;aAAM;YACL,uBAAuB;YACvB,IAAI,CAAC,OAAO,GAAG,MAAM,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YACnC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;SACvB;QAED,yBAAyB;QACzB,IAAI,WAAW,EAAE;YACf,KAAK,CAAC,4BAA4B,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;YACvD,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;gBAC9B,oCAAoC;gBACpC,MAAM,IAAI,KAAK,CAAC;aACjB;YACD,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE;gBAC9C,OAAO;gBACP,GAAG,EAAE,IAAI,CAAC,GAAG;gBACb,OAAO,EAAE,IAAI,CAAC,OAAO;aACtB,CAAC,CAAC;YACH,IAAI,IAAI,CAAC,WAAW,EAAE;gBACpB,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;aAC7C;iBAAM;gBACL,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC;aAC9C;YACD,OAAO;SACR;QAED,iBAAiB;QACjB,KAAK,CAAC,mBAAmB,EAAE,IAAI,CAAC,CAAC;QACjC,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACzB,KAAK,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;QAEvB,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IACxC,CAAC;CACF;AA3VD,wCA2VC","sourcesContent":["import { debuglog } from 'util';\nimport { ONE_DAY, COOKIE_EXP_DATE, hash } from './util';\nimport { Session } from './session';\nconst debug = debuglog('session:context');\n\nexport class ContextSession {\n private ctx: any;\n private app: any;\n private opts: any;\n private session;\n private externalKey: string;\n private prevHash: number;\n store: any;\n\n /**\n * context session constructor\n * @api public\n */\n constructor(ctx, opts) {\n this.ctx = ctx;\n this.app = ctx.app;\n this.opts = Object.assign({}, opts);\n this.store = this.opts.ContextStore\n ? new this.opts.ContextStore(ctx)\n : this.opts.store;\n }\n\n /**\n * internal logic of `ctx.session`\n * @return {Session} session object\n *\n * @api public\n */\n\n get() {\n const session = this.session;\n // already retrieved\n if (session) return session;\n // unset\n if (session === false) return null;\n\n // create an empty session or init from cookie\n this.store ? this.create() : this.initFromCookie();\n return this.session;\n }\n\n /**\n * internal logic of `ctx.session=`\n * @param {Object} val session object\n *\n * @api public\n */\n\n set(val) {\n if (val === null) {\n this.session = false;\n return;\n }\n if (typeof val === 'object') {\n // use the original `externalKey` if exists to avoid waste storage\n this.create(val, this.externalKey);\n return;\n }\n throw new Error('this.session can only be set as null or an object.');\n }\n\n /**\n * init session from external store\n * will be called in the front of session middleware\n *\n * @api public\n */\n\n async initFromExternal() {\n debug('init from external');\n const ctx = this.ctx;\n const opts = this.opts;\n\n let externalKey;\n if (opts.externalKey) {\n externalKey = opts.externalKey.get(ctx);\n debug('get external key from custom %s', externalKey);\n } else {\n externalKey = ctx.cookies.get(opts.key, opts);\n debug('get external key from cookie %s', externalKey);\n }\n\n if (!externalKey) {\n // create a new `externalKey`\n this.create();\n return;\n }\n\n const json = await this.store.get(externalKey, opts.maxAge, {\n ctx,\n rolling: opts.rolling,\n });\n if (!this.valid(json, externalKey)) {\n // create a new `externalKey`\n this.create();\n return;\n }\n\n // create with original `externalKey`\n this.create(json, externalKey);\n this.prevHash = hash(this.session.toJSON());\n }\n\n /**\n * init session from cookie\n * @api private\n */\n\n initFromCookie() {\n debug('init from cookie');\n const ctx = this.ctx;\n const opts = this.opts;\n\n const cookie = ctx.cookies.get(opts.key, opts);\n if (!cookie) {\n this.create();\n return;\n }\n\n let json;\n debug('parse %s', cookie);\n try {\n json = opts.decode(cookie);\n } catch (err) {\n // backwards compatibility:\n // create a new session if parsing fails.\n // new Buffer(string, 'base64') does not seem to crash\n // when `string` is not base64-encoded.\n // but `JSON.parse(string)` will crash.\n debug('decode %j error: %s', cookie, err);\n if (!(err instanceof SyntaxError)) {\n // clean this cookie to ensure next request won't throw again\n ctx.cookies.set(opts.key, '', opts);\n // ctx.onerror will unset all headers, and set those specified in err\n err.headers = {\n 'set-cookie': ctx.response.get('set-cookie'),\n };\n throw err;\n }\n this.create();\n return;\n }\n\n debug('parsed %j', json);\n\n if (!this.valid(json)) {\n this.create();\n return;\n }\n\n // support access `ctx.session` before session middleware\n this.create(json);\n this.prevHash = hash(this.session.toJSON());\n }\n\n /**\n * verify session(expired or )\n * @param {Object} value session object\n * @param {Object} key session externalKey(optional)\n * @return {Boolean} valid\n * @api private\n */\n\n valid(value, key?) {\n const ctx = this.ctx;\n if (!value) {\n this.emit('missed', { key, value, ctx });\n return false;\n }\n\n if (value._expire && value._expire < Date.now()) {\n debug('expired session');\n this.emit('expired', { key, value, ctx });\n return false;\n }\n\n const valid = this.opts.valid;\n if (typeof valid === 'function' && !valid(ctx, value)) {\n // valid session value fail, ignore this session\n debug('invalid session');\n this.emit('invalid', { key, value, ctx });\n return false;\n }\n return true;\n }\n\n /**\n * @param {String} event event name\n * @param {Object} data event data\n * @api private\n */\n emit(event, data) {\n setImmediate(() => {\n this.app.emit(`session:${event}`, data);\n });\n }\n\n /**\n * create a new session and attach to ctx.sess\n *\n * @param {Object} [val] session data\n * @param {String} [externalKey] session external key\n * @api private\n */\n\n create(val?, externalKey?) {\n debug('create session with val: %j externalKey: %s', val, externalKey);\n if (this.store) {\n this.externalKey =\n externalKey || (this.opts.genid && this.opts.genid(this.ctx));\n }\n this.session = new Session(this, val, this.externalKey);\n }\n\n /**\n * Commit the session changes or removal.\n *\n * @api public\n */\n\n async commit() {\n const session = this.session;\n const opts = this.opts;\n const ctx = this.ctx;\n\n // not accessed\n if (undefined === session) return;\n\n // removed\n if (session === false) {\n await this.remove();\n return;\n }\n\n const reason = this._shouldSaveSession();\n debug('should save session: %s', reason);\n if (!reason) return;\n\n if (typeof opts.beforeSave === 'function') {\n debug('before save');\n opts.beforeSave(ctx, session);\n }\n const changed = reason === 'changed';\n await this.save(changed);\n }\n\n _shouldSaveSession() {\n const prevHash = this.prevHash;\n const session = this.session;\n\n // force save session when `session._requireSave` set\n if (session._requireSave) return 'force';\n\n // do nothing if new and not populated\n const json = session.toJSON();\n if (!prevHash && !Object.keys(json).length) return '';\n\n // save if session changed\n const changed = prevHash !== hash(json);\n if (changed) return 'changed';\n\n // save if opts.rolling set\n if (this.opts.rolling) return 'rolling';\n\n // save if opts.renew and session will expired\n if (this.opts.renew) {\n const expire = session._expire;\n const maxAge = session.maxAge;\n // renew when session will expired in maxAge / 2\n if (expire && maxAge && expire - Date.now() < maxAge / 2) return 'renew';\n }\n\n return '';\n }\n\n /**\n * remove session\n * @api private\n */\n\n async remove() {\n // Override the default options so that we can properly expire the session cookies\n const opts = Object.assign({}, this.opts, {\n expires: COOKIE_EXP_DATE,\n maxAge: false,\n });\n\n const ctx = this.ctx;\n const key = opts.key;\n const externalKey = this.externalKey;\n\n if (externalKey) {\n await this.store.destroy(externalKey, { ctx });\n }\n ctx.cookies.set(key, '', opts);\n }\n\n /**\n * save session\n * @api private\n */\n\n async save(changed) {\n const opts = this.opts;\n const key = opts.key;\n const externalKey = this.externalKey;\n let json = this.session.toJSON();\n // set expire for check\n let maxAge = opts.maxAge ? opts.maxAge : ONE_DAY;\n if (maxAge === 'session') {\n // do not set _expire in json if maxAge is set to 'session'\n // also delete maxAge from options\n opts.maxAge = undefined;\n json._session = true;\n } else {\n // set expire for check\n json._expire = maxAge + Date.now();\n json._maxAge = maxAge;\n }\n\n // save to external store\n if (externalKey) {\n debug('save %j to external key %s', json, externalKey);\n if (typeof maxAge === 'number') {\n // ensure store expired after cookie\n maxAge += 10000;\n }\n await this.store.set(externalKey, json, maxAge, {\n changed,\n ctx: this.ctx,\n rolling: opts.rolling,\n });\n if (opts.externalKey) {\n opts.externalKey.set(this.ctx, externalKey);\n } else {\n this.ctx.cookies.set(key, externalKey, opts);\n }\n return;\n }\n\n // save to cookie\n debug('save %j to cookie', json);\n json = opts.encode(json);\n debug('save %s', json);\n\n this.ctx.cookies.set(key, json, opts);\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"crc.js","sourceRoot":"","sources":["../../src/lib/crc.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,MAAM,QAAQ,GAAG;IACf,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IACtE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IACtE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IACtE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IACtE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IACtE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IACtE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IACtE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IACtE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IACtE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IACtE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IACtE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IACtE,UAAU,EAAE,UAAU,EAAE,U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K,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;KAChE;IACD,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;IACzB,OAAO,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;AACtC,CAAC;AAPD,sBAOC","sourcesContent":["/**\n * code from https://gist.github.com/nanha/1385106/ead7b3d7eba5401989d138322cc5e10c8962da76\n * Thanks nanha\n */\nconst crc32tab = [\n 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,\n 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,\n 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,\n 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,\n 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,\n 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,\n 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,\n 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,\n 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,\n 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,\n 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,\n 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,\n 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,\n 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,\n 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,\n 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,\n 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,\n 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,\n 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,\n 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,\n 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,\n 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,\n 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,\n 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,\n 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,\n 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,\n 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,\n 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,\n 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,\n 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,\n 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,\n 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,\n 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,\n 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,\n 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,\n 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,\n 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,\n 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,\n 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,\n 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,\n 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,\n 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,\n 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d,\n];\n\n/**\n * Calculates the CRC32 checksum of a string.\n *\n * @param {String} str\n * @return {String} checksum\n * @api public\n */\nexport function crc32(str, hex = false): number | string {\n let crc = ~0;\n for (let i = 0, l = str.length; i < l; i++) {\n crc = (crc >>> 8) ^ crc32tab[(crc ^ str.charCodeAt(i)) & 0xff];\n }\n crc = Math.abs(cr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OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC;IAC3C,CAAC;IAED;;;;;OAKG;IAEH,IAAI,SAAS;QACX,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;IACvB,CAAC;IAED;;;;;OAKG;IAEH,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC;IACzC,CAAC;IAED;;;;;OAKG;IAEH,IAAI,MAAM,CAAC,GAAG;QACZ,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,MAAM,GAAG,GAAG,CAAC;QACtC,gDAAgD;QAChD,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;IAC3B,CAAC;IAED;;;OAGG;IACH,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED;;;;OAIG;IAEH,IAAI;QACF,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;IAC3B,CAAC;IAED;;;;OAIG;IAEH,KAAK,CAAC,cAAc;QAClB,MAAM,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;IAC/B,CAAC;CACF;AA1HD,0BA0HC","sourcesContent":["/**\n * Session model.\n */\nimport { ISession } from '../interface';\n\nexport class Session implements ISession {\n private _sessCtx;\n private _ctx: any;\n private _externalKey;\n _requireSave;\n isNew = true;\n\n /**\n * Session constructor\n * @param sessionContext\n * @param {Object} obj\n * @param externalKey\n */\n constructor(sessionContext, obj, externalKey) {\n this._sessCtx = sessionContext;\n this._ctx = sessionContext.ctx;\n this._externalKey = externalKey;\n if (!obj) {\n this.isNew = true;\n } else {\n for (const k in obj) {\n // restore maxAge from store\n if (k === '_maxAge') this._ctx.sessionOptions.maxAge = obj._maxAge;\n else if (k === '_session') this._ctx.sessionOptions.maxAge = 'session';\n else this[k] = obj[k];\n }\n }\n }\n\n /**\n * JSON representation of the session.\n *\n * @return {Object}\n * @api public\n */\n\n toJSON() {\n const obj = {};\n\n Object.keys(this).forEach(key => {\n if (key === 'isNew') return;\n if (key[0] === '_') return;\n obj[key] = this[key];\n });\n\n return obj;\n }\n\n /**\n * Return how many values there are in the session object.\n * Used to see if it's \"populated\".\n *\n * @return {Number}\n * @api public\n */\n\n get length() {\n return Object.keys(this.toJSON()).length;\n }\n\n /**\n * populated flag, which is just a boolean alias of .length.\n *\n * @return {Boolean}\n * @api public\n */\n\n get populated() {\n return !!this.length;\n }\n\n /**\n * get session maxAge\n *\n * @return {Number}\n * @api public\n */\n\n get maxAge() {\n return this._ctx.sessionOptions.maxAge;\n }\n\n /**\n * set session maxAge\n *\n * @api public\n * @param val\n */\n\n set maxAge(val) {\n this._ctx.sessionOptions.maxAge = val;\n // maxAge changed, must save to cookie and store\n this._requireSave = true;\n }\n\n /**\n * get session external key\n * only exist if opts.store present\n */\n get externalKey() {\n return this._externalKey;\n }\n\n /**\n * save this session no matter whether it is populated\n *\n * @api public\n */\n\n save() {\n this._requireSave = true;\n }\n\n /**\n * commit this session's headers if autoCommit is set to false\n *\n * @api public\n */\n\n async manuallyCommit() {\n await this._sessCtx.commit();\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/lib/store.ts"],"names":[],"mappings":";;;;;;;;;AAAA,mDAAgE;AAKhE,IAAa,mBAAmB,GAAhC,MAAa,mBAAmB;IAE9B,eAAe,CAAC,YAAY;QAC1B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;IACD,eAAe;QACb,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;CACF,CAAA;AARY,mBAAmB;IAF/B,IAAA,mBAAO,GAAE;IACT,IAAA,iBAAK,EAAC,qBAAS,CAAC,SAAS,CAAC;GACd,mBAAmB,CAQ/B;AARY,kDAAmB","sourcesContent":["import { Provide, Scope, ScopeEnum } from '@midwayjs/decorator';\nimport { SessionStore } from '../interface';\n\n@Provide()\n@Scope(ScopeEnum.Singleton)\nexport class SessionStoreManager {\n private sessionStore: SessionStore;\n setSessionStore(sessionStore) {\n this.sessionStore = sessionStore;\n }\n getSessionStore() {\n return this.sessionStore;\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/lib/util.ts"],"names":[],"mappings":";;;AAAA,+BAA8B;AAE9B;;;;;;GAMG;AACH,SAAgB,MAAM,CAAC,MAAM;IAC3B,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC5D,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAHD,wBAGC;AAED;;;;;;GAMG;AAEH,SAAgB,MAAM,CAAC,IAAI;IACzB,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAC5B,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAC9C,CAAC;AAHD,wBAGC;AAED,SAAgB,IAAI,CAAC,IAAI;IACvB,OAAO,IAAA,WAAK,EAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAW,CAAC;AAC/C,CAAC;AAFD,oBAEC;AAEY,QAAA,eAAe,GAAG,IAAI,IAAI,CAAC,+BAA+B,CAAC,CAAC;AAE5D,QAAA,OAAO,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC","sourcesContent":["import { crc32 } from './crc';\n\n/**\n * Decode the base64 cookie value to an object.\n *\n * @param {String} string\n * @return {Object}\n * @api private\n */\nexport function decode(string) {\n const body = Buffer.from(string, 'base64').toString('utf8');\n return JSON.parse(body);\n}\n\n/**\n * Encode an object into a base64-encoded JSON string.\n *\n * @param {Object} body\n * @return {String}\n * @api private\n */\n\nexport function encode(body) {\n body = JSON.stringify(body);\n return Buffer.from(body).toString('base64');\n}\n\nexport function hash(sess): number {\n return crc32(JSON.stringify(sess)) as number;\n}\n\nexport const COOKIE_EXP_DATE = new Date('Thu, 01 Jan 1970 00:00:00 GMT');\n\nexport const ONE_DAY = 24 * 60 * 60 * 1000;\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/middleware/session.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mDAO6B;AAE7B,wCAAmD;AACnD,sCAA6C;AAC7C,iCAAiC;AACjC,4CAAgD;AAGhD,MAAM,eAAe,GAAG,MAAM,CAAC,wBAAwB,CAAC,CAAC;AACzD,MAAM,gBAAgB,GAAG,MAAM,CAAC,yBAAyB,CAAC,CAAC;AAE3D;;;;;;GAMG;AACH,SAAS,UAAU,CAAC,IAAI;IACtB,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;IAClB,MAAM;IACN,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,IAAI,UAAU,CAAC;IAElC,qBAAqB;IACrB,IAAI,CAAC,CAAC,QAAQ,IAAI,IAAI,CAAC;QAAE,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IAEnD,WAAW;IACX,IAAI,IAAI,CAAC,SAAS,IAAI,IAAI;QAAE,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IAClD,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI;QAAE,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;IAChD,8BAA8B;IAC9B,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI;QAAE,OAAO,IAAI,CAAC,QAAQ,CAAC;IAChD,IAAI,IAAI,CAAC,MAAM,IAAI,IAAI;QAAE,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;IAC5C,IAAI,IAAI,CAAC,UAAU,IAAI,IAAI;QAAE,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;IAEpD,0BAA0B;IAC1B,IAAI,OAAO,IAAI,CAAC,M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AO,CAAC,GAAG;QACT,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE;YAChC,IAAI,CAAC,MAAM,CAAC,IAAI,CACd,gIAAgI,CACjI,CAAC;SACH;QACD,MAAM,KAAK,GAAG,IAAI,CAAC,mBAAmB,CAAC,eAAe,EAAE,CAAC;QACzD,IAAI,KAAK,EAAE;YACT,IAAI,CAAC,aAAa,CAAC,KAAK,GAAG,KAAK,CAAC;SAClC;QAED,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC,aAAa,CAAmB,CAAC;QAC9D,aAAa,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAEjC,OAAO,KAAK,UAAU,OAAO,CAAC,GAAG,EAAE,IAAI;YACrC,MAAM,IAAI,GAAG,GAAG,CAAC,eAAe,CAAmB,CAAC;YACpD,IAAI,IAAI,CAAC,KAAK,EAAE;gBACd,MAAM,IAAI,CAAC,gBAAgB,EAAE,CAAC;aAC/B;YACD,IAAI;gBACF,MAAM,IAAI,EAAE,CAAC;aACd;oBAAS;gBACR,IAAI,IAAI,CAAC,UAAU,EAAE;oBACnB,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC;iBACrB;aACF;QACH,CAAC,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,OAAO;QACZ,OAAO,SAAS,CAAC;IACnB,CAAC;CACF,CAAA;AAxCC;IADC,IAAA,kBAAM,EAAC,SAAS,CAAC;;wDACJ;AAGd;IADC,IAAA,kBAAM,GAAE;;iDACF;AAGP;IADC,IAAA,kBAAM,GAAE;8BACY,2BAAmB;8DAAC;AAR9B,iBAAiB;IAD7B,IAAA,sBAAU,GAAE;GACA,iBAAiB,CA0C7B;AA1CY,8CAAiB","sourcesContent":["import {\n Config,\n Inject,\n Logger,\n Middleware,\n Types,\n Utils,\n} from '@midwayjs/decorator';\nimport { IMiddleware } from '@midwayjs/core';\nimport { SessionStoreManager } from '../lib/store';\nimport { decode, encode } from '../lib/util';\nimport * as assert from 'assert';\nimport { ContextSession } from '../lib/context';\nimport { SessionOptions } from '../interface';\n\nconst CONTEXT_SESSION = Symbol('context#contextSession');\nconst _CONTEXT_SESSION = Symbol('context#_contextSession');\n\n/**\n * format and check session options\n * @param {Object} opts session options\n * @return {Object} new session options\n *\n * @api private\n */\nfunction formatOpts(opts) {\n opts = opts || {};\n // key\n opts.key = opts.key || 'koa.sess';\n\n // back-compat maxage\n if (!('maxAge' in opts)) opts.maxAge = opts.maxage;\n\n // defaults\n if (opts.overwrite == null) opts.overwrite = true;\n if (opts.httpOnly == null) opts.httpOnly = true;\n // delete null sameSite config\n if (opts.sameSite == null) delete opts.sameSite;\n if (opts.signed == null) opts.signed = true;\n if (opts.autoCommit == null) opts.autoCommit = true;\n\n // setup encoding/decoding\n if (typeof opts.encode !== 'function') {\n opts.encode = encode;\n }\n if (typeof opts.decode !== 'function') {\n opts.decode = decode;\n }\n\n const store = opts.store;\n if (store) {\n assert(Types.isFunction(store.get), 'store.get must be function');\n assert(Types.isFunction(store.set), 'store.set must be function');\n assert(Types.isFunction(store.destroy), 'store.destroy must be function');\n }\n\n const externalKey = opts.externalKey;\n if (externalKey) {\n assert(\n Types.isFunction(externalKey.get),\n 'externalKey.get must be function'\n );\n assert(\n Types.isFunction(externalKey.set),\n 'externalKey.set must be function'\n );\n }\n\n const ContextStore = opts.ContextStore;\n if (ContextStore) {\n assert(Types.isClass(ContextStore), 'ContextStore must be a class');\n assert(\n Types.isFunction(ContextStore.prototype.get),\n 'ContextStore.prototype.get must be function'\n );\n assert(\n Types.isFunction(ContextStore.prototype.set),\n 'ContextStore.prototype.set must be function'\n );\n assert(\n Types.isFunction(ContextStore.prototype.destroy),\n 'ContextStore.prototype.destroy must be function'\n );\n }\n\n if (!opts.genid) {\n if (opts.prefix) {\n opts.genid = () => `${opts.prefix}${Utils.randomUUID()}`;\n } else {\n opts.genid = Utils.randomUUID;\n }\n }\n\n return opts;\n}\n\n/**\n * extend context prototype, add session properties\n *\n * @param {Object} context koa's context prototype\n * @param {Object} opts session options\n *\n * @api private\n */\n\nfunction extendContext(context, opts) {\n // eslint-disable-next-line no-prototype-builtins\n if (context.hasOwnProperty(CONTEXT_SESSION)) {\n return;\n }\n Object.defineProperties(context, {\n [CONTEXT_SESSION]: {\n get() {\n if (this[_CONTEXT_SESSION]) {\n return this[_CONTEXT_SESSION];\n }\n this[_CONTEXT_SESSION] = new ContextSession(this, opts);\n return this[_CONTEXT_SESSION];\n },\n },\n session: {\n get() {\n return this[CONTEXT_SESSION].get();\n },\n set(val) {\n this[CONTEXT_SESSION].set(val);\n },\n configurable: true,\n },\n sessionOptions: {\n get() {\n return this[CONTEXT_SESSION].opts;\n },\n },\n });\n}\n\n@Middleware()\nexport class SessionMiddleware implements IMiddleware<any, any> {\n @Config('session')\n sessionConfig;\n\n @Logger()\n logger;\n\n @Inject()\n sessionStoreManager: SessionStoreManager;\n\n resolve(app) {\n if (!this.sessionConfig.httpOnly) {\n this.logger.warn(\n '[midway-session]: please set `config.session.httpOnly` to true. It is very dangerous if session can read by client JavaScript.'\n );\n }\n const store = this.sessionStoreManager.getSessionStore();\n if (store) {\n this.sessionConfig.store = store;\n }\n\n const opts = formatOpts(this.sessionConfig) as SessionOptions;\n extendContext(app.context, opts);\n\n return async function session(ctx, next) {\n const sess = ctx[CONTEXT_SESSION] as ContextSession;\n if (sess.store) {\n await sess.initFromExternal();\n }\n try {\n await next();\n } finally {\n if (opts.autoCommit) {\n await sess.commit();\n }\n }\n };\n }\n\n static getName() {\n return 'session';\n }\n}\n"]}