@adonisjs/session 7.0.0-0 → 7.0.0-10

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.
Files changed (53) hide show
  1. package/README.md +18 -38
  2. package/build/configure.js +29 -2
  3. package/build/factories/main.d.ts +1 -0
  4. package/build/factories/main.js +9 -0
  5. package/build/factories/session_middleware_factory.d.ts +22 -0
  6. package/build/factories/session_middleware_factory.js +47 -0
  7. package/build/index.d.ts +5 -3
  8. package/build/index.js +5 -3
  9. package/build/providers/session_provider.d.ts +15 -4
  10. package/build/providers/session_provider.js +37 -20
  11. package/build/src/client.d.ts +13 -25
  12. package/build/src/client.js +24 -43
  13. package/build/src/debug.d.ts +3 -0
  14. package/build/src/debug.js +10 -0
  15. package/build/src/define_config.d.ts +6 -3
  16. package/build/src/define_config.js +34 -5
  17. package/build/src/drivers/cookie.d.ts +7 -9
  18. package/build/src/drivers/cookie.js +10 -6
  19. package/build/src/drivers/file.d.ts +11 -14
  20. package/build/src/drivers/file.js +90 -34
  21. package/build/src/drivers/memory.d.ts +4 -8
  22. package/build/src/drivers/memory.js +0 -3
  23. package/build/src/drivers/redis.d.ts +4 -6
  24. package/build/src/drivers/redis.js +25 -29
  25. package/build/src/drivers_collection.d.ts +22 -0
  26. package/build/src/drivers_collection.js +38 -0
  27. package/build/src/edge_plugin_adonisjs_session.d.ts +6 -0
  28. package/build/src/edge_plugin_adonisjs_session.js +92 -0
  29. package/build/src/errors.d.ts +8 -0
  30. package/build/src/errors.js +17 -0
  31. package/build/src/helpers.d.ts +6 -0
  32. package/build/src/helpers.js +43 -0
  33. package/build/src/session.d.ts +86 -59
  34. package/build/src/session.js +235 -224
  35. package/build/src/session_middleware.d.ts +19 -2
  36. package/build/src/session_middleware.js +43 -4
  37. package/build/src/store.d.ts +48 -35
  38. package/build/src/store.js +85 -57
  39. package/build/src/types/extended.d.ts +19 -0
  40. package/build/src/types/main.d.ts +106 -0
  41. package/build/src/types/main.js +9 -0
  42. package/build/stubs/config.stub +28 -92
  43. package/package.json +37 -26
  44. package/build/src/bindings/api_client.d.ts +0 -2
  45. package/build/src/bindings/api_client.js +0 -135
  46. package/build/src/bindings/http_context.d.ts +0 -5
  47. package/build/src/bindings/http_context.js +0 -17
  48. package/build/src/bindings/types.d.ts +0 -77
  49. package/build/src/session_manager.d.ts +0 -38
  50. package/build/src/session_manager.js +0 -149
  51. package/build/src/types.d.ts +0 -61
  52. package/build/src/types.js +0 -1
  53. /package/build/src/{bindings/types.js → types/extended.js} +0 -0
package/README.md CHANGED
@@ -1,53 +1,33 @@
1
- <div align="center">
2
- <img src="https://res.cloudinary.com/adonisjs/image/upload/q_100/v1558612869/adonis-readme_zscycu.jpg" width="600px">
3
- </div>
1
+ # @adonisjs/session
4
2
 
5
3
  <br />
6
4
 
7
- <div align="center">
8
- <h3>Sessions</h3>
9
- <p>This package adds support for sessions to AdonisJS</p>
10
- </div>
5
+ [![gh-workflow-image]][gh-workflow-url] [![npm-image]][npm-url] ![][typescript-image] [![license-image]][license-url]
11
6
 
12
- <br />
13
-
14
- <div align="center">
7
+ ## Introduction
8
+ Use sessions in your AdonisJS applications with a unified API to persist session data across different data-stores. Has inbuilt support for **cookie**, **files**, and **redis** drivers.
15
9
 
16
- [![gh-workflow-image]][gh-workflow-url] [![typescript-image]][typescript-url] [![npm-image]][npm-url] [![license-image]][license-url] [![synk-image]][synk-url]
10
+ ## Official Documentation
11
+ The documentation is available on the [AdonisJS website](https://docs.adonisjs.com/guides/sessions)
17
12
 
18
- </div>
13
+ ## Contributing
14
+ One of the primary goals of AdonisJS is to have a vibrant community of users and contributors who believes in the principles of the framework.
19
15
 
20
- <div align="center">
21
- <h3>
22
- <a href="https://adonisjs.com">
23
- Website
24
- </a>
25
- <span> | </span>
26
- <a href="https://docs.adonisjs.com/guides/session">
27
- Guides
28
- </a>
29
- <span> | </span>
30
- <a href="CONTRIBUTING.md">
31
- Contributing
32
- </a>
33
- </h3>
34
- </div>
16
+ We encourage you to read the [contribution guide](https://github.com/adonisjs/.github/blob/main/docs/CONTRIBUTING.md) before contributing to the framework.
35
17
 
36
- <div align="center">
37
- <sub>Built with ❤︎ by <a href="https://twitter.com/AmanVirk1">Harminder Virk</a>
38
- </div>
18
+ ## Code of Conduct
19
+ In order to ensure that the AdonisJS community is welcoming to all, please review and abide by the [Code of Conduct](https://github.com/adonisjs/.github/blob/main/docs/CODE_OF_CONDUCT.md).
39
20
 
40
- [gh-workflow-image]: https://img.shields.io/github/workflow/status/adonisjs/session/test?style=for-the-badge
41
- [gh-workflow-url]: https://github.com/adonisjs/session/actions/workflows/test.yml "Github action"
21
+ ## License
22
+ AdonisJS session is open-sourced software licensed under the [MIT license](LICENSE.md).
42
23
 
43
- [typescript-image]: https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge&logo=typescript
44
- [typescript-url]: "typescript"
24
+ [gh-workflow-image]: https://img.shields.io/github/actions/workflow/status/adonisjs/session/checks.yml?style=for-the-badge
25
+ [gh-workflow-url]: https://github.com/adonisjs/session/actions/workflows/checks.yml "Github action"
45
26
 
46
27
  [npm-image]: https://img.shields.io/npm/v/@adonisjs/session/latest.svg?style=for-the-badge&logo=npm
47
28
  [npm-url]: https://www.npmjs.com/package/@adonisjs/session/v/latest "npm"
48
29
 
49
- [license-image]: https://img.shields.io/npm/l/@adonisjs/session?color=blueviolet&style=for-the-badge
50
- [license-url]: LICENSE.md "license"
30
+ [typescript-image]: https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge&logo=typescript
51
31
 
52
- [synk-image]: https://img.shields.io/snyk/vulnerabilities/github/adonisjs/session?label=Synk%20Vulnerabilities&style=for-the-badge
53
- [synk-url]: https://snyk.io/test/github/adonisjs/session?targetFile=package.json "synk"
32
+ [license-url]: LICENSE.md
33
+ [license-image]: https://img.shields.io/github/license/adonisjs/session?style=for-the-badge
@@ -10,9 +10,36 @@
10
10
  * Configures the package
11
11
  */
12
12
  export async function configure(command) {
13
+ /**
14
+ * Publish config file
15
+ */
13
16
  await command.publishStub('config.stub');
14
- await command.defineEnvVariables({ SESSION_DRIVER: 'cookie' });
15
- await command.updateRcFile((rcFile) => {
17
+ const codemods = await command.createCodemods();
18
+ /**
19
+ * Define environment variables
20
+ */
21
+ await codemods.defineEnvVariables({ SESSION_DRIVER: 'cookie' });
22
+ /**
23
+ * Define environment variables validations
24
+ */
25
+ await codemods.defineEnvValidations({
26
+ variables: {
27
+ SESSION_DRIVER: `Env.schema.enum(['cookie', 'redis', 'file', 'memory'] as const)`,
28
+ },
29
+ leadingComment: 'Variables for configuring session package',
30
+ });
31
+ /**
32
+ * Register middleware
33
+ */
34
+ await codemods.registerMiddleware('router', [
35
+ {
36
+ path: '@adonisjs/session/session_middleware',
37
+ },
38
+ ]);
39
+ /**
40
+ * Register provider
41
+ */
42
+ await codemods.updateRcFile((rcFile) => {
16
43
  rcFile.addProvider('@adonisjs/session/session_provider');
17
44
  });
18
45
  }
@@ -0,0 +1 @@
1
+ export { SessionMiddlewareFactory } from './session_middleware_factory.js';
@@ -0,0 +1,9 @@
1
+ /*
2
+ * @adonisjs/session
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+ export { SessionMiddlewareFactory } from './session_middleware_factory.js';
@@ -0,0 +1,22 @@
1
+ import { Emitter } from '@adonisjs/core/events';
2
+ import { EventsList } from '@adonisjs/core/types';
3
+ import { SessionConfig } from '../src/types/main.js';
4
+ import SessionMiddleware from '../src/session_middleware.js';
5
+ /**
6
+ * Exposes the API to create an instance of the session middleware
7
+ * without additional plumbing
8
+ */
9
+ export declare class SessionMiddlewareFactory {
10
+ #private;
11
+ /**
12
+ * Merge custom options
13
+ */
14
+ merge(options: {
15
+ config?: Partial<SessionConfig>;
16
+ emitter?: Emitter<EventsList>;
17
+ }): this;
18
+ /**
19
+ * Creates an instance of the session middleware
20
+ */
21
+ create(): Promise<SessionMiddleware>;
22
+ }
@@ -0,0 +1,47 @@
1
+ /*
2
+ * @adonisjs/session
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+ import { Emitter } from '@adonisjs/core/events';
10
+ import { AppFactory } from '@adonisjs/core/factories/app';
11
+ import { defineConfig } from '../index.js';
12
+ import { registerSessionDriver } from '../src/helpers.js';
13
+ import SessionMiddleware from '../src/session_middleware.js';
14
+ /**
15
+ * Exposes the API to create an instance of the session middleware
16
+ * without additional plumbing
17
+ */
18
+ export class SessionMiddlewareFactory {
19
+ #config = { driver: 'memory' };
20
+ #emitter;
21
+ #getApp() {
22
+ return new AppFactory().create(new URL('./', import.meta.url), () => { });
23
+ }
24
+ #getEmitter() {
25
+ return this.#emitter || new Emitter(this.#getApp());
26
+ }
27
+ /**
28
+ * Merge custom options
29
+ */
30
+ merge(options) {
31
+ if (options.config) {
32
+ this.#config = options.config;
33
+ }
34
+ if (options.emitter) {
35
+ this.#emitter = options.emitter;
36
+ }
37
+ return this;
38
+ }
39
+ /**
40
+ * Creates an instance of the session middleware
41
+ */
42
+ async create() {
43
+ const config = defineConfig(this.#config);
44
+ await registerSessionDriver(this.#getApp(), config.driver);
45
+ return new SessionMiddleware(config, this.#getEmitter());
46
+ }
47
+ }
package/build/index.d.ts CHANGED
@@ -6,7 +6,9 @@
6
6
  * For the full copyright and license information, please view the LICENSE
7
7
  * file that was distributed with this source code.
8
8
  */
9
- import './src/bindings/types.js';
10
- export { defineConfig } from './src/define_config.js';
11
- export { stubsRoot } from './stubs/main.js';
9
+ import './src/types/extended.js';
10
+ export * as errors from './src/errors.js';
12
11
  export { configure } from './configure.js';
12
+ export { stubsRoot } from './stubs/main.js';
13
+ export { defineConfig } from './src/define_config.js';
14
+ export { default as driversList } from './src/drivers_collection.js';
package/build/index.js CHANGED
@@ -6,7 +6,9 @@
6
6
  * For the full copyright and license information, please view the LICENSE
7
7
  * file that was distributed with this source code.
8
8
  */
9
- import './src/bindings/types.js';
10
- export { defineConfig } from './src/define_config.js';
11
- export { stubsRoot } from './stubs/main.js';
9
+ import './src/types/extended.js';
10
+ export * as errors from './src/errors.js';
12
11
  export { configure } from './configure.js';
12
+ export { stubsRoot } from './stubs/main.js';
13
+ export { defineConfig } from './src/define_config.js';
14
+ export { default as driversList } from './src/drivers_collection.js';
@@ -1,13 +1,24 @@
1
- import { ApplicationService } from '@adonisjs/core/types';
1
+ import type { Edge } from 'edge.js';
2
+ import type { ApplicationService } from '@adonisjs/core/types';
3
+ /**
4
+ * Session provider configures the session management inside an
5
+ * AdonisJS application
6
+ */
2
7
  export default class SessionProvider {
3
8
  protected app: ApplicationService;
4
9
  constructor(app: ApplicationService);
5
10
  /**
6
- * Register Session Manager in the container
11
+ * Returns edge when it's installed
7
12
  */
8
- register(): Promise<void>;
13
+ protected getEdge(): Promise<Edge | null>;
9
14
  /**
10
- * Register bindings
15
+ * Registering muddleware
16
+ */
17
+ register(): void;
18
+ /**
19
+ * Registering the active driver when middleware is used
20
+ * +
21
+ * Adding edge tags (if edge is installed)
11
22
  */
12
23
  boot(): Promise<void>;
13
24
  }
@@ -6,38 +6,55 @@
6
6
  * For the full copyright and license information, please view the LICENSE
7
7
  * file that was distributed with this source code.
8
8
  */
9
- import { extendHttpContext } from '../src/bindings/http_context.js';
10
- import { extendApiClient } from '../src/bindings/api_client.js';
9
+ import debug from '../src/debug.js';
10
+ import { registerSessionDriver } from '../src/helpers.js';
11
+ import SessionMiddleware from '../src/session_middleware.js';
12
+ /**
13
+ * Session provider configures the session management inside an
14
+ * AdonisJS application
15
+ */
11
16
  export default class SessionProvider {
12
17
  app;
13
18
  constructor(app) {
14
19
  this.app = app;
15
20
  }
16
21
  /**
17
- * Register Session Manager in the container
22
+ * Returns edge when it's installed
18
23
  */
19
- async register() {
20
- this.app.container.singleton('session', async () => {
21
- const { SessionManager } = await import('../src/session_manager.js');
22
- const encryption = await this.app.container.make('encryption');
23
- const redis = await this.app.container.make('redis').catch(() => undefined);
24
+ async getEdge() {
25
+ try {
26
+ const { default: edge } = await import('edge.js');
27
+ debug('Detected edge.js package. Adding session primitives to it');
28
+ return edge;
29
+ }
30
+ catch {
31
+ return null;
32
+ }
33
+ }
34
+ /**
35
+ * Registering muddleware
36
+ */
37
+ register() {
38
+ this.app.container.singleton(SessionMiddleware, async (resolver) => {
24
39
  const config = this.app.config.get('session', {});
25
- return new SessionManager(config, encryption, redis);
40
+ const emitter = await resolver.make('emitter');
41
+ return new SessionMiddleware(config, emitter);
26
42
  });
27
43
  }
28
44
  /**
29
- * Register bindings
45
+ * Registering the active driver when middleware is used
46
+ * +
47
+ * Adding edge tags (if edge is installed)
30
48
  */
31
49
  async boot() {
32
- const sessionManager = await this.app.container.make('session');
33
- /**
34
- * Add `session` getter to the HttpContext class
35
- */
36
- extendHttpContext(sessionManager);
37
- /**
38
- * Add some macros and getter to japa/api-client classes for
39
- * easier testing
40
- */
41
- extendApiClient(sessionManager);
50
+ this.app.container.resolving(SessionMiddleware, async () => {
51
+ const config = this.app.config.get('session');
52
+ await registerSessionDriver(this.app, config.driver);
53
+ });
54
+ const edge = await this.getEdge();
55
+ if (edge) {
56
+ const { edgePluginAdonisJSSession } = await import('../src/edge_plugin_adonisjs_session.js');
57
+ edge.use(edgePluginAdonisJSSession);
58
+ }
42
59
  }
43
60
  }
@@ -1,41 +1,29 @@
1
- import { Store } from './store.js';
2
- import type { SessionConfig, SessionDriverContract } from './types.js';
3
1
  import type { CookieClient } from '@adonisjs/core/http';
2
+ import type { SessionConfig, SessionData, SessionDriverContract } from './types/main.js';
4
3
  /**
5
- * SessionClient exposes the API to set session data as a client
4
+ * Session client exposes the API to set session data as a client
6
5
  */
7
- export declare class SessionClient extends Store {
6
+ export declare class SessionClient {
8
7
  #private;
9
8
  /**
10
- * Each instance of client works on a single session id. Generate
11
- * multiple client instances for a different session id
9
+ * Session key for setting flash messages
12
10
  */
13
- sessionId: string;
11
+ flashKey: string;
12
+ constructor(config: SessionConfig, driver: SessionDriverContract, cookieClient: CookieClient);
14
13
  /**
15
- * Flash messages store. They are merged with the session data during
16
- * commit
14
+ * Load session data from the driver
17
15
  */
18
- flashMessages: Store;
19
- constructor(config: SessionConfig, driver: SessionDriverContract, cookieClient: CookieClient, values: {
20
- [key: string]: any;
21
- } | null);
22
- /**
23
- * Find if the sessions are enabled
24
- */
25
- isEnabled(): boolean;
26
- /**
27
- * Load session from the driver
28
- */
29
- load(cookies: Record<string, any>): Promise<{
30
- session: any;
31
- flashMessages: any;
16
+ load(cookies: Record<string, any>, sessionId?: string): Promise<{
17
+ sessionId: string;
18
+ session: SessionData;
19
+ flashMessages: SessionData;
32
20
  }>;
33
21
  /**
34
22
  * Commits the session data to the session store and returns
35
23
  * the session id and cookie name for it to be accessible
36
24
  * by the server
37
25
  */
38
- commit(): Promise<{
26
+ commit(values: SessionData | null, flashMessages: SessionData | null, sessionId?: string): Promise<{
39
27
  sessionId: string;
40
28
  signedSessionId: string;
41
29
  cookieName: string;
@@ -43,5 +31,5 @@ export declare class SessionClient extends Store {
43
31
  /**
44
32
  * Clear the session store
45
33
  */
46
- forget(): Promise<void>;
34
+ forget(sessionId?: string): Promise<void>;
47
35
  }
@@ -9,15 +9,15 @@
9
9
  import { cuid } from '@adonisjs/core/helpers';
10
10
  import { Store } from './store.js';
11
11
  /**
12
- * SessionClient exposes the API to set session data as a client
12
+ * Session client exposes the API to set session data as a client
13
13
  */
14
- export class SessionClient extends Store {
14
+ export class SessionClient {
15
15
  /**
16
16
  * Session configuration
17
17
  */
18
18
  #config;
19
19
  /**
20
- * The session driver used to read and write session data
20
+ * The session driver to use for reading and writing session data
21
21
  */
22
22
  #driver;
23
23
  /**
@@ -25,41 +25,30 @@ export class SessionClient extends Store {
25
25
  */
26
26
  #cookieClient;
27
27
  /**
28
- * Each instance of client works on a single session id. Generate
29
- * multiple client instances for a different session id
28
+ * Session to use when no explicit session id is
29
+ * defined
30
30
  */
31
- sessionId = cuid();
31
+ #sessionId = cuid();
32
32
  /**
33
33
  * Session key for setting flash messages
34
34
  */
35
- #flashMessagesKey = '__flash__';
36
- /**
37
- * Flash messages store. They are merged with the session data during
38
- * commit
39
- */
40
- flashMessages = new Store({});
41
- constructor(config, driver, cookieClient, values) {
42
- super(values);
35
+ flashKey = '__flash__';
36
+ constructor(config, driver, cookieClient) {
43
37
  this.#config = config;
44
38
  this.#driver = driver;
45
39
  this.#cookieClient = cookieClient;
46
40
  }
47
41
  /**
48
- * Find if the sessions are enabled
49
- */
50
- isEnabled() {
51
- return this.#config.enabled;
52
- }
53
- /**
54
- * Load session from the driver
42
+ * Load session data from the driver
55
43
  */
56
- async load(cookies) {
44
+ async load(cookies, sessionId) {
57
45
  const sessionIdCookie = cookies[this.#config.cookieName];
58
- const sessionId = sessionIdCookie ? sessionIdCookie.value : this.sessionId;
59
- const contents = await this.#driver.read(sessionId);
46
+ const sessId = sessionId || sessionIdCookie ? sessionIdCookie.value : this.#sessionId;
47
+ const contents = await this.#driver.read(sessId);
60
48
  const store = new Store(contents);
61
- const flashMessages = store.pull(this.#flashMessagesKey, null);
49
+ const flashMessages = store.pull(this.flashKey, null);
62
50
  return {
51
+ sessionId: sessId,
63
52
  session: store.all(),
64
53
  flashMessages,
65
54
  };
@@ -69,32 +58,24 @@ export class SessionClient extends Store {
69
58
  * the session id and cookie name for it to be accessible
70
59
  * by the server
71
60
  */
72
- async commit() {
73
- this.set(this.#flashMessagesKey, this.flashMessages.all());
74
- await this.#driver.write(this.sessionId, this.toJSON());
61
+ async commit(values, flashMessages, sessionId) {
62
+ const sessId = sessionId || this.#sessionId;
75
63
  /**
76
- * Clear from the session client memory
64
+ * Persist session data to the store, alongside flash messages
77
65
  */
78
- this.clear();
79
- this.flashMessages.clear();
66
+ if (values || flashMessages) {
67
+ await this.#driver.write(sessId, Object.assign({ [this.flashKey]: flashMessages }, values));
68
+ }
80
69
  return {
81
- sessionId: this.sessionId,
82
- signedSessionId: this.#cookieClient.sign(this.#config.cookieName, this.sessionId),
70
+ sessionId: sessId,
71
+ signedSessionId: this.#cookieClient.sign(this.#config.cookieName, sessId),
83
72
  cookieName: this.#config.cookieName,
84
73
  };
85
74
  }
86
75
  /**
87
76
  * Clear the session store
88
77
  */
89
- async forget() {
90
- /**
91
- * Clear from the session client memory
92
- */
93
- this.clear();
94
- this.flashMessages.clear();
95
- /**
96
- * Clear with the driver
97
- */
98
- await this.#driver.destroy(this.sessionId);
78
+ async forget(sessionId) {
79
+ await this.#driver.destroy(sessionId || this.#sessionId);
99
80
  }
100
81
  }
@@ -0,0 +1,3 @@
1
+ /// <reference types="@types/node" resolution-mode="require"/>
2
+ declare const _default: import("util").DebugLogger;
3
+ export default _default;
@@ -0,0 +1,10 @@
1
+ /*
2
+ * @adonisjs/session
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+ import { debuglog } from 'node:util';
10
+ export default debuglog('adonisjs:session');
@@ -1,5 +1,8 @@
1
- import { SessionConfig } from './types.js';
1
+ import type { CookieOptions } from '@adonisjs/core/types/http';
2
+ import type { SessionConfig } from './types/main.js';
2
3
  /**
3
- * Helper to define session config
4
+ * Helper to normalize session config
4
5
  */
5
- export declare function defineConfig(config: SessionConfig): SessionConfig;
6
+ export declare function defineConfig(config: Partial<SessionConfig>): SessionConfig & {
7
+ cookie: Partial<CookieOptions>;
8
+ };
@@ -1,13 +1,42 @@
1
+ /*
2
+ * @adonisjs/session
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+ import string from '@poppinss/utils/string';
1
10
  import { InvalidArgumentsException } from '@poppinss/utils';
11
+ import debug from './debug.js';
2
12
  /**
3
- * Helper to define session config
13
+ * Helper to normalize session config
4
14
  */
5
15
  export function defineConfig(config) {
6
- if (!config.cookieName) {
7
- throw new InvalidArgumentsException('Missing "cookieName" property inside the session config');
8
- }
16
+ /**
17
+ * Make sure a driver is defined
18
+ */
9
19
  if (!config.driver) {
10
20
  throw new InvalidArgumentsException('Missing "driver" property inside the session config');
11
21
  }
12
- return config;
22
+ const age = config.age || '2h';
23
+ const clearWithBrowser = config.clearWithBrowser ?? false;
24
+ const cookieOptions = { ...config.cookie };
25
+ /**
26
+ * Define maxAge property when session id cookie is
27
+ * not a session cookie.
28
+ */
29
+ if (!clearWithBrowser) {
30
+ debug('computing maxAge for session id cookie');
31
+ cookieOptions.maxAge = string.seconds.parse(config.age || age);
32
+ }
33
+ return {
34
+ enabled: true,
35
+ age,
36
+ clearWithBrowser,
37
+ cookieName: 'adonis_session',
38
+ cookie: cookieOptions,
39
+ driver: config.driver,
40
+ ...config,
41
+ };
13
42
  }
@@ -1,23 +1,21 @@
1
1
  import type { HttpContext } from '@adonisjs/core/http';
2
- import type { SessionConfig, SessionDriverContract } from '../types.js';
2
+ import { CookieOptions } from '@adonisjs/core/types/http';
3
+ import type { SessionData, SessionDriverContract } from '../types/main.js';
3
4
  /**
4
- * Cookie driver utilizes the encrypted HTTP cookies to write session value.
5
+ * Cookie driver stores the session data inside an encrypted
6
+ * cookie.
5
7
  */
6
8
  export declare class CookieDriver implements SessionDriverContract {
7
9
  #private;
8
- constructor(config: SessionConfig, ctx: HttpContext);
10
+ constructor(config: Partial<CookieOptions>, ctx: HttpContext);
9
11
  /**
10
12
  * Read session value from the cookie
11
13
  */
12
- read(sessionId: string): {
13
- [key: string]: any;
14
- } | null;
14
+ read(sessionId: string): SessionData | null;
15
15
  /**
16
16
  * Write session values to the cookie
17
17
  */
18
- write(sessionId: string, values: {
19
- [key: string]: any;
20
- }): void;
18
+ write(sessionId: string, values: SessionData): void;
21
19
  /**
22
20
  * Removes the session cookie
23
21
  */