@adonisjs/session 6.2.0 → 6.2.3

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.
@@ -1,3 +1,4 @@
1
1
  /// <reference path="session.d.ts" />
2
2
  /// <reference path="context.d.ts" />
3
3
  /// <reference path="container.d.ts" />
4
+ /// <reference path="tests.d.ts" />
@@ -9,3 +9,4 @@
9
9
  /// <reference path="./session.ts" />
10
10
  /// <reference path="./context.ts" />
11
11
  /// <reference path="./container.ts" />
12
+ /// <reference path="./tests.ts" />
@@ -231,7 +231,7 @@ declare module '@ioc:Adonis/Addons/Session' {
231
231
  /**
232
232
  * Load session data from the driver
233
233
  */
234
- load(): Promise<{
234
+ load(cookies: Record<string, any>): Promise<{
235
235
  session: Record<string, any>;
236
236
  flashMessages: Record<string, any> | null;
237
237
  }>;
@@ -6,11 +6,11 @@ declare module '@japa/api-client' {
6
6
  /**
7
7
  * Send session values in the request
8
8
  */
9
- withSession(session: Record<string, AllowedSessionValues>): this;
9
+ session(session: Record<string, AllowedSessionValues>): this;
10
10
  /**
11
11
  * Send flash messages in the request
12
12
  */
13
- withFlashMessages(messages: Record<string, AllowedSessionValues>): this;
13
+ flashMessages(messages: Record<string, AllowedSessionValues>): this;
14
14
  }
15
15
  interface ApiResponse {
16
16
  /**
@@ -22,7 +22,7 @@ function defineTestsBindings(ApiRequest, ApiResponse, ApiClient, SessionManager)
22
22
  /**
23
23
  * Send session values in the request
24
24
  */
25
- ApiRequest.macro('withSession', function (session) {
25
+ ApiRequest.macro('session', function (session) {
26
26
  if (!this.sessionClient.isEnabled()) {
27
27
  throw new Error('Cannot set session. Make sure to enable it inside "config/session" file');
28
28
  }
@@ -32,7 +32,7 @@ function defineTestsBindings(ApiRequest, ApiResponse, ApiClient, SessionManager)
32
32
  /**
33
33
  * Send flash messages in the request
34
34
  */
35
- ApiRequest.macro('withFlashMessages', function (messages) {
35
+ ApiRequest.macro('flashMessages', function (messages) {
36
36
  if (!this.sessionClient.isEnabled()) {
37
37
  throw new Error('Cannot set flash messages. Make sure to enable the session inside "config/session" file');
38
38
  }
@@ -90,36 +90,42 @@ function defineTestsBindings(ApiRequest, ApiResponse, ApiClient, SessionManager)
90
90
  this.assert.notProperty(this.flashMessages(), name);
91
91
  });
92
92
  /**
93
- * Hook into request and persist session data to be available
94
- * on the server during the request.
93
+ * Adding hooks directly on the request object moves the hooks to
94
+ * the end of the queue (basically after the globally hooks)
95
95
  */
96
- ApiClient.setup(async (request) => {
96
+ ApiClient.onRequest((req) => {
97
97
  /**
98
- * Persist session data and set the session id within the
99
- * cookie
98
+ * Hook into request and persist session data to be available
99
+ * on the server during the request.
100
100
  */
101
- const { cookieName, sessionId } = await request.sessionClient.commit();
102
- request.cookie(cookieName, sessionId);
101
+ req.setup(async (request) => {
102
+ /**
103
+ * Persist session data and set the session id within the
104
+ * cookie
105
+ */
106
+ const { cookieName, sessionId } = await request.sessionClient.commit();
107
+ request.cookie(cookieName, sessionId);
108
+ /**
109
+ * Cleanup if request has error. Otherwise the teardown
110
+ * hook will clear
111
+ */
112
+ return async (error) => {
113
+ if (error) {
114
+ await request.sessionClient.forget();
115
+ }
116
+ };
117
+ });
103
118
  /**
104
- * Cleanup if request has error. Otherwise the teardown
105
- * hook will clear
119
+ * Load messages from the session store and keep a reference to it
120
+ * inside the response object.
121
+ *
122
+ * We also destroy the session after getting a copy of the session
123
+ * data
106
124
  */
107
- return async (error) => {
108
- if (error) {
109
- await request.sessionClient.forget();
110
- }
111
- };
112
- });
113
- /**
114
- * Load messages from the session store and keep a reference to it
115
- * inside the response object.
116
- *
117
- * We also destroy the session after getting a copy of the session
118
- * data
119
- */
120
- ApiClient.teardown(async (response) => {
121
- response.sessionJar = await response.request.sessionClient.load();
122
- await response.request.sessionClient.forget();
125
+ req.teardown(async (response) => {
126
+ response.sessionJar = await response.request.sessionClient.load(response.cookies());
127
+ await response.request.sessionClient.forget();
128
+ });
123
129
  });
124
130
  }
125
131
  exports.defineTestsBindings = defineTestsBindings;
@@ -34,7 +34,7 @@ export declare class SessionClient extends Store implements SessionClientContrac
34
34
  /**
35
35
  * Load session from the driver
36
36
  */
37
- load(): Promise<{
37
+ load(cookies: Record<string, any>): Promise<{
38
38
  session: any;
39
39
  flashMessages: any;
40
40
  }>;
@@ -45,8 +45,10 @@ class SessionClient extends Store_1.Store {
45
45
  /**
46
46
  * Load session from the driver
47
47
  */
48
- async load() {
49
- const contents = await this.driver.read(this.sessionId);
48
+ async load(cookies) {
49
+ const sessionIdCookie = cookies[this.config.cookieName];
50
+ const sessionId = sessionIdCookie ? sessionIdCookie.value : this.sessionId;
51
+ const contents = await this.driver.read(sessionId);
50
52
  const store = new Store_1.Store(contents);
51
53
  const flashMessages = store.pull(this.flashMessagesKey, null);
52
54
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adonisjs/session",
3
- "version": "6.2.0",
3
+ "version": "6.2.3",
4
4
  "description": "Session provider for AdonisJS",
5
5
  "typings": "./build/adonis-typings/index.d.ts",
6
6
  "main": "build/providers/SessionProvider.js",
@@ -12,40 +12,41 @@
12
12
  "build/instructions.md"
13
13
  ],
14
14
  "dependencies": {
15
- "@poppinss/utils": "^4.0.2",
16
- "fs-extra": "^10.0.1"
15
+ "@poppinss/utils": "^4.0.4",
16
+ "fs-extra": "^10.1.0"
17
17
  },
18
18
  "peerDependencies": {
19
19
  "@adonisjs/core": "^5.5.0"
20
20
  },
21
21
  "devDependencies": {
22
- "@adonisjs/core": "^5.6.2",
22
+ "@adonisjs/core": "^5.7.6",
23
23
  "@adonisjs/mrm-preset": "^5.0.3",
24
- "@adonisjs/redis": "^7.1.1",
25
- "@adonisjs/require-ts": "^2.0.10",
26
- "@japa/assert": "^1.3.3",
27
- "@japa/preset-adonis": "^1.0.11",
24
+ "@adonisjs/redis": "^7.2.0",
25
+ "@adonisjs/require-ts": "^2.0.11",
26
+ "@japa/assert": "^1.3.4",
27
+ "@japa/preset-adonis": "^1.0.15",
28
28
  "@japa/run-failed-tests": "^1.0.7",
29
- "@japa/runner": "^2.0.6",
29
+ "@japa/runner": "^2.0.7",
30
30
  "@japa/spec-reporter": "^1.1.12",
31
- "@poppinss/dev-utils": "^2.0.2",
32
- "@types/node": "^17.0.23",
31
+ "@poppinss/dev-utils": "^2.0.3",
32
+ "@types/node": "^17.0.32",
33
33
  "@types/supertest": "^2.0.12",
34
34
  "commitizen": "^4.2.4",
35
35
  "copyfiles": "^2.4.1",
36
36
  "cz-conventional-changelog": "^3.3.0",
37
37
  "del-cli": "^4.0.1",
38
- "eslint": "^8.12.0",
38
+ "eslint": "^8.15.0",
39
39
  "eslint-config-prettier": "^8.5.0",
40
40
  "eslint-plugin-adonis": "^2.1.0",
41
41
  "eslint-plugin-prettier": "^4.0.0",
42
- "github-label-sync": "^2.1.1",
43
- "husky": "^7.0.4",
42
+ "github-label-sync": "^2.2.0",
43
+ "husky": "^8.0.1",
44
44
  "mrm": "^4.0.0",
45
45
  "np": "^7.6.1",
46
46
  "prettier": "^2.6.2",
47
- "supertest": "^6.2.2",
48
- "typescript": "^4.6.3"
47
+ "set-cookie-parser": "^2.4.8",
48
+ "supertest": "^6.2.3",
49
+ "typescript": "^4.6.4"
49
50
  },
50
51
  "scripts": {
51
52
  "mrm": "mrm --preset=@adonisjs/mrm-preset",