@adonisjs/session 7.0.0 → 7.1.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.
@@ -17,7 +17,14 @@ import { ExceptionHandler } from "@adonisjs/core/http";
17
17
  import lodash from "@poppinss/utils/lodash";
18
18
  import { cuid } from "@adonisjs/core/helpers";
19
19
  var Session = class {
20
- #config;
20
+ constructor(config, storeFactory, emitter, ctx) {
21
+ this.config = config;
22
+ this.#ctx = ctx;
23
+ this.#emitter = emitter;
24
+ this.#store = storeFactory(ctx, config);
25
+ this.#sessionIdFromCookie = ctx.request.cookie(config.cookieName, void 0);
26
+ this.#sessionId = this.#sessionIdFromCookie || cuid();
27
+ }
21
28
  #store;
22
29
  #emitter;
23
30
  #ctx;
@@ -100,14 +107,6 @@ var Session = class {
100
107
  get hasBeenModified() {
101
108
  return this.#valuesStore?.hasBeenModified ?? false;
102
109
  }
103
- constructor(config, storeFactory, emitter, ctx) {
104
- this.#ctx = ctx;
105
- this.#config = config;
106
- this.#emitter = emitter;
107
- this.#store = storeFactory(ctx, config);
108
- this.#sessionIdFromCookie = ctx.request.cookie(config.cookieName, void 0);
109
- this.#sessionId = this.#sessionIdFromCookie || cuid();
110
- }
111
110
  /**
112
111
  * Returns the flash messages store for a given
113
112
  * mode
@@ -262,7 +261,7 @@ var Session = class {
262
261
  }
263
262
  return result;
264
263
  }, {});
265
- this.flashExcept(["_csrf", "_method"]);
264
+ this.flashExcept(["_csrf", "_method", "password", "password_confirmation"]);
266
265
  this.flash("inputErrorsBag", errorsBag);
267
266
  this.flash("errors", errorsBag);
268
267
  }
@@ -323,7 +322,7 @@ var Session = class {
323
322
  this.put(this.flashKey, { ...reflashed, ...input, ...others });
324
323
  }
325
324
  debug_default("committing session data");
326
- this.#ctx.response.cookie(this.#config.cookieName, this.#sessionId, this.#config.cookie);
325
+ this.#ctx.response.cookie(this.config.cookieName, this.#sessionId, this.config.cookie);
327
326
  if (this.isEmpty) {
328
327
  if (this.#sessionIdFromCookie) {
329
328
  await this.#store.destroy(this.#sessionIdFromCookie);
@@ -399,4 +398,4 @@ var SessionMiddleware = class {
399
398
  export {
400
399
  SessionMiddleware
401
400
  };
402
- //# sourceMappingURL=chunk-K4OSGJVW.js.map
401
+ //# sourceMappingURL=chunk-S3VYZEQN.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/session_middleware.ts","../src/session.ts"],"sourcesContent":["/*\n * @adonisjs/session\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { EmitterService } from '@adonisjs/core/types'\nimport type { NextFn } from '@adonisjs/core/types/http'\nimport { ExceptionHandler, HttpContext } from '@adonisjs/core/http'\n\nimport { Session } from './session.js'\nimport type { SessionConfig, SessionStoreFactory } from './types.js'\n\n/**\n * HttpContext augmentations\n */\ndeclare module '@adonisjs/core/http' {\n export interface HttpContext {\n session: Session\n }\n}\n\n/**\n * Overwriting validation exception renderer\n */\nconst originalErrorHandler = ExceptionHandler.prototype.renderValidationErrorAsHTML\nExceptionHandler.macro('renderValidationErrorAsHTML', async function (error, ctx) {\n if (ctx.session) {\n ctx.session.flashValidationErrors(error)\n ctx.response.redirect('back', true)\n } else {\n return originalErrorHandler(error, ctx)\n }\n})\n\n/**\n * Session middleware is used to initiate the session store\n * and commit its values during an HTTP request\n */\nexport default class SessionMiddleware<KnownStores extends Record<string, SessionStoreFactory>> {\n #config: SessionConfig & {\n store: keyof KnownStores\n stores: KnownStores\n }\n #emitter: EmitterService\n\n constructor(\n config: SessionConfig & {\n store: keyof KnownStores\n stores: KnownStores\n },\n emitter: EmitterService\n ) {\n this.#config = config\n this.#emitter = emitter\n }\n\n async handle(ctx: HttpContext, next: NextFn) {\n if (!this.#config.enabled) {\n return next()\n }\n\n ctx.session = new Session(\n this.#config,\n this.#config.stores[this.#config.store], // reference to store factory\n this.#emitter,\n ctx\n )\n\n /**\n * Initiate session store\n */\n await ctx.session.initiate(false)\n\n /**\n * Call next middlewares or route handler\n */\n const response = await next()\n\n /**\n * Commit store mutations\n */\n await ctx.session.commit()\n\n /**\n * Return response\n */\n return response\n }\n}\n","/*\n * @adonisjs/session\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport lodash from '@poppinss/utils/lodash'\nimport { cuid } from '@adonisjs/core/helpers'\nimport type { HttpContext } from '@adonisjs/core/http'\nimport type { EmitterService } from '@adonisjs/core/types'\nimport type { HttpError } from '@adonisjs/core/types/http'\n\nimport debug from './debug.js'\nimport * as errors from './errors.js'\nimport { ReadOnlyValuesStore, ValuesStore } from './values_store.js'\nimport type {\n SessionData,\n SessionConfig,\n SessionStoreFactory,\n AllowedSessionValues,\n SessionStoreContract,\n} from './types.js'\n\n/**\n * The session class exposes the API to read and write values to\n * the session store.\n *\n * A session instance is isolated between requests but\n * uses a centralized persistence store and\n */\nexport class Session {\n #store: SessionStoreContract\n #emitter: EmitterService\n #ctx: HttpContext\n #readonly: boolean = false\n\n /**\n * Session values store\n */\n #valuesStore?: ValuesStore\n\n /**\n * Session id refers to the session id that will be committed\n * as a cookie during the response.\n */\n #sessionId: string\n\n /**\n * Session id from cookie refers to the value we read from the\n * cookie during the HTTP request.\n *\n * This only might not exist during the first request. Also during\n * session id re-generation, this value will be different from\n * the session id.\n */\n #sessionIdFromCookie?: string\n\n /**\n * Store of flash messages that be written during the\n * HTTP request\n */\n responseFlashMessages = new ValuesStore({})\n\n /**\n * Store of flash messages for the current HTTP request.\n */\n flashMessages = new ValuesStore({})\n\n /**\n * The key to use for storing flash messages inside\n * the session store.\n */\n flashKey: string = '__flash__'\n\n /**\n * Session id for the current HTTP request\n */\n get sessionId() {\n return this.#sessionId\n }\n\n /**\n * A boolean to know if a fresh session is created during\n * the request\n */\n get fresh(): boolean {\n return this.#sessionIdFromCookie === undefined\n }\n\n /**\n * A boolean to know if session is in readonly\n * state\n */\n get readonly() {\n return this.#readonly\n }\n\n /**\n * A boolean to know if session store has been initiated\n */\n get initiated() {\n return !!this.#valuesStore\n }\n\n /**\n * A boolean to know if the session id has been re-generated\n * during the current request\n */\n get hasRegeneratedSession() {\n return !!(this.#sessionIdFromCookie && this.#sessionIdFromCookie !== this.#sessionId)\n }\n\n /**\n * A boolean to know if the session store is empty\n */\n get isEmpty() {\n return this.#valuesStore?.isEmpty ?? true\n }\n\n /**\n * A boolean to know if the session store has been\n * modified\n */\n get hasBeenModified() {\n return this.#valuesStore?.hasBeenModified ?? false\n }\n\n constructor(\n public config: SessionConfig,\n storeFactory: SessionStoreFactory,\n emitter: EmitterService,\n ctx: HttpContext\n ) {\n this.#ctx = ctx\n this.#emitter = emitter\n this.#store = storeFactory(ctx, config)\n this.#sessionIdFromCookie = ctx.request.cookie(config.cookieName, undefined)\n this.#sessionId = this.#sessionIdFromCookie || cuid()\n }\n\n /**\n * Returns the flash messages store for a given\n * mode\n */\n #getFlashStore(mode: 'write' | 'read'): ValuesStore {\n if (!this.#valuesStore) {\n throw new errors.E_SESSION_NOT_READY()\n }\n\n if (mode === 'write' && this.readonly) {\n throw new errors.E_SESSION_NOT_MUTABLE()\n }\n\n return this.responseFlashMessages\n }\n\n /**\n * Returns the store instance for a given mode\n */\n #getValuesStore(mode: 'write' | 'read'): ValuesStore {\n if (!this.#valuesStore) {\n throw new errors.E_SESSION_NOT_READY()\n }\n\n if (mode === 'write' && this.readonly) {\n throw new errors.E_SESSION_NOT_MUTABLE()\n }\n\n return this.#valuesStore\n }\n\n /**\n * Initiates the session store. The method results in a noop\n * when called multiple times\n */\n async initiate(readonly: boolean): Promise<void> {\n if (this.#valuesStore) {\n return\n }\n\n debug('initiating session (readonly: %s)', readonly)\n\n this.#readonly = readonly\n const contents = await this.#store.read(this.#sessionId)\n this.#valuesStore = new ValuesStore(contents)\n\n /**\n * Extract flash messages from the store and keep a local\n * copy of it.\n */\n if (this.has(this.flashKey)) {\n debug('reading flash data')\n if (this.#readonly) {\n this.flashMessages.update(this.get(this.flashKey, null))\n } else {\n this.flashMessages.update(this.pull(this.flashKey, null))\n }\n }\n\n /**\n * Share session with the templates. We assume the view property\n * is a reference to edge templates\n */\n if ('view' in this.#ctx) {\n this.#ctx.view.share({\n session: new ReadOnlyValuesStore(this.#valuesStore.all()),\n flashMessages: new ReadOnlyValuesStore(this.flashMessages.all()),\n old: function (key: string, defaultValue?: any) {\n return this.flashMessages.get(key, defaultValue)\n },\n })\n }\n\n this.#emitter.emit('session:initiated', { session: this })\n }\n\n /**\n * Put a key-value pair to the session data store\n */\n put(key: string, value: AllowedSessionValues) {\n this.#getValuesStore('write').set(key, value)\n }\n\n /**\n * Check if a key exists inside the datastore\n */\n has(key: string): boolean {\n return this.#getValuesStore('read').has(key)\n }\n\n /**\n * Get the value of a key from the session datastore.\n * You can specify a default value to use, when key\n * does not exists or has undefined value.\n */\n get(key: string, defaultValue?: any) {\n return this.#getValuesStore('read').get(key, defaultValue)\n }\n\n /**\n * Get everything from the session store\n */\n all() {\n return this.#getValuesStore('read').all()\n }\n\n /**\n * Remove a key from the session datastore\n */\n forget(key: string) {\n return this.#getValuesStore('write').unset(key)\n }\n\n /**\n * Read value for a key from the session datastore\n * and remove it simultaneously.\n */\n pull(key: string, defaultValue?: any) {\n return this.#getValuesStore('write').pull(key, defaultValue)\n }\n\n /**\n * Increment the value of a key inside the session\n * store.\n *\n * A new key will be defined if does not exists already.\n * The value of a new key will be 1\n */\n increment(key: string, steps: number = 1) {\n return this.#getValuesStore('write').increment(key, steps)\n }\n\n /**\n * Increment the value of a key inside the session\n * store.\n *\n * A new key will be defined if does not exists already.\n * The value of a new key will be -1\n */\n decrement(key: string, steps: number = 1) {\n return this.#getValuesStore('write').decrement(key, steps)\n }\n\n /**\n * Empty the session store\n */\n clear() {\n return this.#getValuesStore('write').clear()\n }\n\n /**\n * Add a key-value pair to flash messages\n */\n flash(key: string, value: AllowedSessionValues): void\n flash(keyValue: SessionData): void\n flash(key: string | SessionData, value?: AllowedSessionValues): void {\n if (typeof key === 'string') {\n if (value) {\n this.#getFlashStore('write').set(key, value)\n }\n } else {\n this.#getFlashStore('write').merge(key)\n }\n }\n\n /**\n * Flash errors to the errorsBag. You can read these\n * errors via the \"@error\" tag.\n *\n * Appends new messages to the existing collection.\n */\n flashErrors(errorsCollection: Record<string, string | string[]>) {\n this.flash({ errorsBag: errorsCollection })\n }\n\n /**\n * Flash validation error messages. Make sure the error\n * is an instance of VineJS ValidationException.\n *\n * Overrides existing inputErrors\n */\n flashValidationErrors(error: HttpError) {\n const errorsBag = error.messages.reduce((result: Record<string, string[]>, message: any) => {\n if (result[message.field]) {\n result[message.field].push(message.message)\n } else {\n result[message.field] = [message.message]\n }\n return result\n }, {})\n\n this.flashExcept(['_csrf', '_method', 'password', 'password_confirmation'])\n\n /**\n * Adding to inputErrorsBag for \"@inputError\" tag\n * to read validation errors\n */\n this.flash('inputErrorsBag', errorsBag)\n\n /**\n * For legacy support and not to break apps using\n * the older version of @adonisjs/session package\n */\n this.flash('errors', errorsBag)\n }\n\n /**\n * Flash form input data to the flash messages store\n */\n flashAll() {\n return this.#getFlashStore('write').set('input', this.#ctx.request.original())\n }\n\n /**\n * Flash form input data (except some keys) to the flash messages store\n */\n flashExcept(keys: string[]): void {\n this.#getFlashStore('write').set('input', lodash.omit(this.#ctx.request.original(), keys))\n }\n\n /**\n * Flash form input data (only some keys) to the flash messages store\n */\n flashOnly(keys: string[]): void {\n this.#getFlashStore('write').set('input', lodash.pick(this.#ctx.request.original(), keys))\n }\n\n /**\n * Reflash messages from the last request in the current response\n */\n reflash(): void {\n this.#getFlashStore('write').set('reflashed', this.flashMessages.all())\n }\n\n /**\n * Reflash messages (only some keys) from the last\n * request in the current response\n */\n reflashOnly(keys: string[]) {\n this.#getFlashStore('write').set('reflashed', lodash.pick(this.flashMessages.all(), keys))\n }\n\n /**\n * Reflash messages (except some keys) from the last\n * request in the current response\n */\n reflashExcept(keys: string[]) {\n this.#getFlashStore('write').set('reflashed', lodash.omit(this.flashMessages.all(), keys))\n }\n\n /**\n * Re-generate the session id and migrate data to it.\n */\n regenerate() {\n this.#sessionId = cuid()\n }\n\n /**\n * Commit session changes. No more mutations will be\n * allowed after commit.\n */\n async commit() {\n if (!this.#valuesStore || this.readonly) {\n return\n }\n\n /**\n * If the flash messages store is not empty, we should put\n * its messages inside main session store.\n */\n if (!this.responseFlashMessages.isEmpty) {\n const { input, reflashed, ...others } = this.responseFlashMessages.all()\n this.put(this.flashKey, { ...reflashed, ...input, ...others })\n }\n\n debug('committing session data')\n\n /**\n * Touch the session id cookie to stay alive\n */\n this.#ctx.response.cookie(this.config.cookieName, this.#sessionId, this.config.cookie!)\n\n /**\n * Delete the session data when the session store\n * is empty.\n *\n * Also we only destroy the session id we read from the cookie.\n * If there was no session id in the cookie, there won't be\n * any data inside the store either.\n */\n if (this.isEmpty) {\n if (this.#sessionIdFromCookie) {\n await this.#store.destroy(this.#sessionIdFromCookie)\n }\n this.#emitter.emit('session:committed', { session: this })\n return\n }\n\n /**\n * Touch the store expiry when the session store was\n * not modified.\n */\n if (!this.hasBeenModified) {\n if (this.#sessionIdFromCookie && this.#sessionIdFromCookie !== this.#sessionId) {\n await this.#store.destroy(this.#sessionIdFromCookie)\n await this.#store.write(this.#sessionId, this.#valuesStore.toJSON())\n this.#emitter.emit('session:migrated', {\n fromSessionId: this.#sessionIdFromCookie,\n toSessionId: this.sessionId,\n session: this,\n })\n } else {\n await this.#store.touch(this.#sessionId)\n }\n this.#emitter.emit('session:committed', { session: this })\n return\n }\n\n /**\n * Otherwise commit to the session store\n */\n if (this.#sessionIdFromCookie && this.#sessionIdFromCookie !== this.#sessionId) {\n await this.#store.destroy(this.#sessionIdFromCookie)\n await this.#store.write(this.#sessionId, this.#valuesStore.toJSON())\n this.#emitter.emit('session:migrated', {\n fromSessionId: this.#sessionIdFromCookie,\n toSessionId: this.sessionId,\n session: this,\n })\n } else {\n await this.#store.write(this.#sessionId, this.#valuesStore.toJSON())\n }\n\n this.#emitter.emit('session:committed',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AAO,KAAK;AAAA,IACd;AAEA,QAAI,UAAU,IAAI;AAAA,MAChB,KAAK;AAAA,MACL,KAAK,QAAQ,OAAO,KAAK,QAAQ,KAAK;AAAA;AAAA,MACtC,KAAK;AAAA,MACL;AAAA,IACF;AAKA,UAAM,IAAI,QAAQ,SAAS,KAAK;AAKhC,UAAM,WAAW,MAAM,KAAK;AAK5B,UAAM,IAAI,QAAQ,OAAO;AAKzB,WAAO;AAAA,EACT;AACF;","names":[]}
@@ -3,7 +3,7 @@ import {
3
3
  } from "../chunk-7YIO32ZH.js";
4
4
  import {
5
5
  SessionMiddleware
6
- } from "../chunk-K4OSGJVW.js";
6
+ } from "../chunk-S3VYZEQN.js";
7
7
  import "../chunk-2X5L327N.js";
8
8
  import "../chunk-TE5JP3SX.js";
9
9
  import "../chunk-WBAYBMJJ.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  SessionMiddleware
3
- } from "../chunk-K4OSGJVW.js";
3
+ } from "../chunk-S3VYZEQN.js";
4
4
  import "../chunk-2X5L327N.js";
5
5
  import "../chunk-TE5JP3SX.js";
6
6
  import "../chunk-WBAYBMJJ.js";
@@ -12,6 +12,7 @@ import type { SessionData, SessionConfig, SessionStoreFactory, AllowedSessionVal
12
12
  */
13
13
  export declare class Session {
14
14
  #private;
15
+ config: SessionConfig;
15
16
  /**
16
17
  * Store of flash messages that be written during the
17
18
  * HTTP request
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  SessionMiddleware
3
- } from "../chunk-K4OSGJVW.js";
3
+ } from "../chunk-S3VYZEQN.js";
4
4
  import "../chunk-2X5L327N.js";
5
5
  import "../chunk-TE5JP3SX.js";
6
6
  import "../chunk-WBAYBMJJ.js";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@adonisjs/session",
3
3
  "description": "Session provider for AdonisJS",
4
- "version": "7.0.0",
4
+ "version": "7.1.1",
5
5
  "engines": {
6
6
  "node": ">=18.16.0"
7
7
  },
@@ -43,8 +43,8 @@
43
43
  "quick:test": "node --enable-source-maps --loader=ts-node/esm bin/test.ts"
44
44
  },
45
45
  "devDependencies": {
46
- "@adonisjs/assembler": "^7.0.0",
47
- "@adonisjs/core": "^6.2.0",
46
+ "@adonisjs/assembler": "^7.1.0",
47
+ "@adonisjs/core": "^6.2.1",
48
48
  "@adonisjs/eslint-config": "^1.2.1",
49
49
  "@adonisjs/prettier-config": "^1.2.1",
50
50
  "@adonisjs/redis": "^8.0.0",
@@ -52,16 +52,16 @@
52
52
  "@japa/api-client": "^2.0.2",
53
53
  "@japa/assert": "^2.1.0",
54
54
  "@japa/browser-client": "^2.0.2",
55
- "@japa/file-system": "^2.1.1",
55
+ "@japa/file-system": "^2.2.0",
56
56
  "@japa/plugin-adonisjs": "^3.0.0",
57
57
  "@japa/runner": "^3.1.1",
58
58
  "@japa/snapshot": "^2.0.4",
59
- "@swc/core": "^1.3.102",
60
- "@types/node": "^20.10.7",
59
+ "@swc/core": "^1.3.105",
60
+ "@types/node": "^20.11.5",
61
61
  "@types/set-cookie-parser": "^2.4.7",
62
62
  "@types/supertest": "^6.0.2",
63
63
  "@vinejs/vine": "^1.7.0",
64
- "c8": "^9.0.0",
64
+ "c8": "^9.1.0",
65
65
  "copyfiles": "^2.4.1",
66
66
  "cross-env": "^7.0.3",
67
67
  "del-cli": "^5.0.0",
@@ -71,16 +71,16 @@
71
71
  "github-label-sync": "^2.3.1",
72
72
  "husky": "^8.0.3",
73
73
  "np": "^9.2.0",
74
- "playwright": "^1.40.1",
75
- "prettier": "^3.1.1",
74
+ "playwright": "^1.41.1",
75
+ "prettier": "^3.2.4",
76
76
  "set-cookie-parser": "^2.6.0",
77
- "supertest": "^6.3.3",
77
+ "supertest": "^6.3.4",
78
78
  "ts-node": "^10.9.2",
79
79
  "tsup": "^8.0.1",
80
80
  "typescript": "^5.3.3"
81
81
  },
82
82
  "dependencies": {
83
- "@poppinss/utils": "^6.7.0"
83
+ "@poppinss/utils": "^6.7.1"
84
84
  },
85
85
  "peerDependencies": {
86
86
  "@adonisjs/core": "^6.2.0",
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/session_middleware.ts","../src/session.ts"],"sourcesContent":["/*\n * @adonisjs/session\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { EmitterService } from '@adonisjs/core/types'\nimport type { NextFn } from '@adonisjs/core/types/http'\nimport { ExceptionHandler, HttpContext } from '@adonisjs/core/http'\n\nimport { Session } from './session.js'\nimport type { SessionConfig, SessionStoreFactory } from './types.js'\n\n/**\n * HttpContext augmentations\n */\ndeclare module '@adonisjs/core/http' {\n export interface HttpContext {\n session: Session\n }\n}\n\n/**\n * Overwriting validation exception renderer\n */\nconst originalErrorHandler = ExceptionHandler.prototype.renderValidationErrorAsHTML\nExceptionHandler.macro('renderValidationErrorAsHTML', async function (error, ctx) {\n if (ctx.session) {\n ctx.session.flashValidationErrors(error)\n ctx.response.redirect('back', true)\n } else {\n return originalErrorHandler(error, ctx)\n }\n})\n\n/**\n * Session middleware is used to initiate the session store\n * and commit its values during an HTTP request\n */\nexport default class SessionMiddleware<KnownStores extends Record<string, SessionStoreFactory>> {\n #config: SessionConfig & {\n store: keyof KnownStores\n stores: KnownStores\n }\n #emitter: EmitterService\n\n constructor(\n config: SessionConfig & {\n store: keyof KnownStores\n stores: KnownStores\n },\n emitter: EmitterService\n ) {\n this.#config = config\n this.#emitter = emitter\n }\n\n async handle(ctx: HttpContext, next: NextFn) {\n if (!this.#config.enabled) {\n return next()\n }\n\n ctx.session = new Session(\n this.#config,\n this.#config.stores[this.#config.store], // reference to store factory\n this.#emitter,\n ctx\n )\n\n /**\n * Initiate session store\n */\n await ctx.session.initiate(false)\n\n /**\n * Call next middlewares or route handler\n */\n const response = await next()\n\n /**\n * Commit store mutations\n */\n await ctx.session.commit()\n\n /**\n * Return response\n */\n return response\n }\n}\n","/*\n * @adonisjs/session\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport lodash from '@poppinss/utils/lodash'\nimport { cuid } from '@adonisjs/core/helpers'\nimport type { HttpContext } from '@adonisjs/core/http'\nimport type { EmitterService } from '@adonisjs/core/types'\nimport type { HttpError } from '@adonisjs/core/types/http'\n\nimport debug from './debug.js'\nimport * as errors from './errors.js'\nimport { ReadOnlyValuesStore, ValuesStore } from './values_store.js'\nimport type {\n SessionData,\n SessionConfig,\n SessionStoreFactory,\n AllowedSessionValues,\n SessionStoreContract,\n} from './types.js'\n\n/**\n * The session class exposes the API to read and write values to\n * the session store.\n *\n * A session instance is isolated between requests but\n * uses a centralized persistence store and\n */\nexport class Session {\n #config: SessionConfig\n #store: SessionStoreContract\n #emitter: EmitterService\n #ctx: HttpContext\n #readonly: boolean = false\n\n /**\n * Session values store\n */\n #valuesStore?: ValuesStore\n\n /**\n * Session id refers to the session id that will be committed\n * as a cookie during the response.\n */\n #sessionId: string\n\n /**\n * Session id from cookie refers to the value we read from the\n * cookie during the HTTP request.\n *\n * This only might not exist during the first request. Also during\n * session id re-generation, this value will be different from\n * the session id.\n */\n #sessionIdFromCookie?: string\n\n /**\n * Store of flash messages that be written during the\n * HTTP request\n */\n responseFlashMessages = new ValuesStore({})\n\n /**\n * Store of flash messages for the current HTTP request.\n */\n flashMessages = new ValuesStore({})\n\n /**\n * The key to use for storing flash messages inside\n * the session store.\n */\n flashKey: string = '__flash__'\n\n /**\n * Session id for the current HTTP request\n */\n get sessionId() {\n return this.#sessionId\n }\n\n /**\n * A boolean to know if a fresh session is created during\n * the request\n */\n get fresh(): boolean {\n return this.#sessionIdFromCookie === undefined\n }\n\n /**\n * A boolean to know if session is in readonly\n * state\n */\n get readonly() {\n return this.#readonly\n }\n\n /**\n * A boolean to know if session store has been initiated\n */\n get initiated() {\n return !!this.#valuesStore\n }\n\n /**\n * A boolean to know if the session id has been re-generated\n * during the current request\n */\n get hasRegeneratedSession() {\n return !!(this.#sessionIdFromCookie && this.#sessionIdFromCookie !== this.#sessionId)\n }\n\n /**\n * A boolean to know if the session store is empty\n */\n get isEmpty() {\n return this.#valuesStore?.isEmpty ?? true\n }\n\n /**\n * A boolean to know if the session store has been\n * modified\n */\n get hasBeenModified() {\n return this.#valuesStore?.hasBeenModified ?? false\n }\n\n constructor(\n config: SessionConfig,\n storeFactory: SessionStoreFactory,\n emitter: EmitterService,\n ctx: HttpContext\n ) {\n this.#ctx = ctx\n this.#config = config\n this.#emitter = emitter\n this.#store = storeFactory(ctx, config)\n this.#sessionIdFromCookie = ctx.request.cookie(config.cookieName, undefined)\n this.#sessionId = this.#sessionIdFromCookie || cuid()\n }\n\n /**\n * Returns the flash messages store for a given\n * mode\n */\n #getFlashStore(mode: 'write' | 'read'): ValuesStore {\n if (!this.#valuesStore) {\n throw new errors.E_SESSION_NOT_READY()\n }\n\n if (mode === 'write' && this.readonly) {\n throw new errors.E_SESSION_NOT_MUTABLE()\n }\n\n return this.responseFlashMessages\n }\n\n /**\n * Returns the store instance for a given mode\n */\n #getValuesStore(mode: 'write' | 'read'): ValuesStore {\n if (!this.#valuesStore) {\n throw new errors.E_SESSION_NOT_READY()\n }\n\n if (mode === 'write' && this.readonly) {\n throw new errors.E_SESSION_NOT_MUTABLE()\n }\n\n return this.#valuesStore\n }\n\n /**\n * Initiates the session store. The method results in a noop\n * when called multiple times\n */\n async initiate(readonly: boolean): Promise<void> {\n if (this.#valuesStore) {\n return\n }\n\n debug('initiating session (readonly: %s)', readonly)\n\n this.#readonly = readonly\n const contents = await this.#store.read(this.#sessionId)\n this.#valuesStore = new ValuesStore(contents)\n\n /**\n * Extract flash messages from the store and keep a local\n * copy of it.\n */\n if (this.has(this.flashKey)) {\n debug('reading flash data')\n if (this.#readonly) {\n this.flashMessages.update(this.get(this.flashKey, null))\n } else {\n this.flashMessages.update(this.pull(this.flashKey, null))\n }\n }\n\n /**\n * Share session with the templates. We assume the view property\n * is a reference to edge templates\n */\n if ('view' in this.#ctx) {\n this.#ctx.view.share({\n session: new ReadOnlyValuesStore(this.#valuesStore.all()),\n flashMessages: new ReadOnlyValuesStore(this.flashMessages.all()),\n old: function (key: string, defaultValue?: any) {\n return this.flashMessages.get(key, defaultValue)\n },\n })\n }\n\n this.#emitter.emit('session:initiated', { session: this })\n }\n\n /**\n * Put a key-value pair to the session data store\n */\n put(key: string, value: AllowedSessionValues) {\n this.#getValuesStore('write').set(key, value)\n }\n\n /**\n * Check if a key exists inside the datastore\n */\n has(key: string): boolean {\n return this.#getValuesStore('read').has(key)\n }\n\n /**\n * Get the value of a key from the session datastore.\n * You can specify a default value to use, when key\n * does not exists or has undefined value.\n */\n get(key: string, defaultValue?: any) {\n return this.#getValuesStore('read').get(key, defaultValue)\n }\n\n /**\n * Get everything from the session store\n */\n all() {\n return this.#getValuesStore('read').all()\n }\n\n /**\n * Remove a key from the session datastore\n */\n forget(key: string) {\n return this.#getValuesStore('write').unset(key)\n }\n\n /**\n * Read value for a key from the session datastore\n * and remove it simultaneously.\n */\n pull(key: string, defaultValue?: any) {\n return this.#getValuesStore('write').pull(key, defaultValue)\n }\n\n /**\n * Increment the value of a key inside the session\n * store.\n *\n * A new key will be defined if does not exists already.\n * The value of a new key will be 1\n */\n increment(key: string, steps: number = 1) {\n return this.#getValuesStore('write').increment(key, steps)\n }\n\n /**\n * Increment the value of a key inside the session\n * store.\n *\n * A new key will be defined if does not exists already.\n * The value of a new key will be -1\n */\n decrement(key: string, steps: number = 1) {\n return this.#getValuesStore('write').decrement(key, steps)\n }\n\n /**\n * Empty the session store\n */\n clear() {\n return this.#getValuesStore('write').clear()\n }\n\n /**\n * Add a key-value pair to flash messages\n */\n flash(key: string, value: AllowedSessionValues): void\n flash(keyValue: SessionData): void\n flash(key: string | SessionData, value?: AllowedSessionValues): void {\n if (typeof key === 'string') {\n if (value) {\n this.#getFlashStore('write').set(key, value)\n }\n } else {\n this.#getFlashStore('write').merge(key)\n }\n }\n\n /**\n * Flash errors to the errorsBag. You can read these\n * errors via the \"@error\" tag.\n *\n * Appends new messages to the existing collection.\n */\n flashErrors(errorsCollection: Record<string, string | string[]>) {\n this.flash({ errorsBag: errorsCollection })\n }\n\n /**\n * Flash validation error messages. Make sure the error\n * is an instance of VineJS ValidationException.\n *\n * Overrides existing inputErrors\n */\n flashValidationErrors(error: HttpError) {\n const errorsBag = error.messages.reduce((result: Record<string, string[]>, message: any) => {\n if (result[message.field]) {\n result[message.field].push(message.message)\n } else {\n result[message.field] = [message.message]\n }\n return result\n }, {})\n\n this.flashExcept(['_csrf', '_method'])\n\n /**\n * Adding to inputErrorsBag for \"@inputError\" tag\n * to read validation errors\n */\n this.flash('inputErrorsBag', errorsBag)\n\n /**\n * For legacy support and not to break apps using\n * the older version of @adonisjs/session package\n */\n this.flash('errors', errorsBag)\n }\n\n /**\n * Flash form input data to the flash messages store\n */\n flashAll() {\n return this.#getFlashStore('write').set('input', this.#ctx.request.original())\n }\n\n /**\n * Flash form input data (except some keys) to the flash messages store\n */\n flashExcept(keys: string[]): void {\n this.#getFlashStore('write').set('input', lodash.omit(this.#ctx.request.original(), keys))\n }\n\n /**\n * Flash form input data (only some keys) to the flash messages store\n */\n flashOnly(keys: string[]): void {\n this.#getFlashStore('write').set('input', lodash.pick(this.#ctx.request.original(), keys))\n }\n\n /**\n * Reflash messages from the last request in the current response\n */\n reflash(): void {\n this.#getFlashStore('write').set('reflashed', this.flashMessages.all())\n }\n\n /**\n * Reflash messages (only some keys) from the last\n * request in the current response\n */\n reflashOnly(keys: string[]) {\n this.#getFlashStore('write').set('reflashed', lodash.pick(this.flashMessages.all(), keys))\n }\n\n /**\n * Reflash messages (except some keys) from the last\n * request in the current response\n */\n reflashExcept(keys: string[]) {\n this.#getFlashStore('write').set('reflashed', lodash.omit(this.flashMessages.all(), keys))\n }\n\n /**\n * Re-generate the session id and migrate data to it.\n */\n regenerate() {\n this.#sessionId = cuid()\n }\n\n /**\n * Commit session changes. No more mutations will be\n * allowed after commit.\n */\n async commit() {\n if (!this.#valuesStore || this.readonly) {\n return\n }\n\n /**\n * If the flash messages store is not empty, we should put\n * its messages inside main session store.\n */\n if (!this.responseFlashMessages.isEmpty) {\n const { input, reflashed, ...others } = this.responseFlashMessages.all()\n this.put(this.flashKey, { ...reflashed, ...input, ...others })\n }\n\n debug('committing session data')\n\n /**\n * Touch the session id cookie to stay alive\n */\n this.#ctx.response.cookie(this.#config.cookieName, this.#sessionId, this.#config.cookie!)\n\n /**\n * Delete the session data when the session store\n * is empty.\n *\n * Also we only destroy the session id we read from the cookie.\n * If there was no session id in the cookie, there won't be\n * any data inside the store either.\n */\n if (this.isEmpty) {\n if (this.#sessionIdFromCookie) {\n await this.#store.destroy(this.#sessionIdFromCookie)\n }\n this.#emitter.emit('session:committed', { session: this })\n return\n }\n\n /**\n * Touch the store expiry when the session store was\n * not modified.\n */\n if (!this.hasBeenModified) {\n if (this.#sessionIdFromCookie && this.#sessionIdFromCookie !== this.#sessionId) {\n await this.#store.destroy(this.#sessionIdFromCookie)\n await this.#store.write(this.#sessionId, this.#valuesStore.toJSON())\n this.#emitter.emit('session:migrated', {\n fromSessionId: this.#sessionIdFromCookie,\n toSessionId: this.sessionId,\n session: this,\n })\n } else {\n await this.#store.touch(this.#sessionId)\n }\n this.#emitter.emit('session:committed', { session: this })\n return\n }\n\n /**\n * Otherwise commit to the session store\n */\n if (this.#sessionIdFromCookie && this.#sessionIdFromCookie !== this.#sessionId) {\n await this.#store.destroy(this.#sessionIdFromCookie)\n await this.#store.write(this.#sessionId, this.#valuesStore.toJSON())\n this.#emitter.emit('session:migrated', {\n fromSessionId: this.#sessionIdFromCookie,\n toSessionId: this.sessionId,\n session: this,\n })\n } else {\n await this.#store.write(this.#sessionId, this.#valuesStore.toJSON())\n }\n\n this.#emitter.emit('session:committed', { session: this })\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAWA,SAAS,wBAAqC;;;ACF9C,OAAO,YAAY;AACnB,SAAS,YAAY;AAuBd,IAAM,UAAN,MAAc;AAAA,EACnB;AAAA,EACA;AAA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