@adonisjs/session 6.2.2 → 6.4.0
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/build/adonis-typings/session.d.ts +1 -1
- package/build/adonis-typings/tests.d.ts +6 -0
- package/build/config.d.ts +13 -0
- package/build/config.js +18 -0
- package/build/src/Bindings/Tests.js +10 -1
- package/build/src/Client/index.d.ts +1 -1
- package/build/src/Client/index.js +4 -2
- package/build/src/Session/index.d.ts +6 -1
- package/build/src/Session/index.js +10 -5
- package/build/templates/session.txt +3 -5
- package/package.json +14 -11
|
@@ -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
|
}>;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import '@japa/api-client';
|
|
3
|
+
import { InspectOptions } from 'util';
|
|
2
4
|
import { AllowedSessionValues, SessionClientContract } from '@ioc:Adonis/Addons/Session';
|
|
3
5
|
declare module '@japa/api-client' {
|
|
4
6
|
interface ApiRequest {
|
|
@@ -24,6 +26,10 @@ declare module '@japa/api-client' {
|
|
|
24
26
|
* Get session data
|
|
25
27
|
*/
|
|
26
28
|
session(): Record<string, any>;
|
|
29
|
+
/**
|
|
30
|
+
* Dump session
|
|
31
|
+
*/
|
|
32
|
+
dumpSession(options?: InspectOptions): this;
|
|
27
33
|
/**
|
|
28
34
|
* Get flash messages set by the server
|
|
29
35
|
*/
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @adonisjs/session
|
|
3
|
+
*
|
|
4
|
+
* (c) Harminder Virk <virk@adonisjs.com>
|
|
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 { SessionConfig } from '@ioc:Adonis/Addons/Session';
|
|
10
|
+
/**
|
|
11
|
+
* Helper to define session config
|
|
12
|
+
*/
|
|
13
|
+
export declare function sessionConfig<Config extends SessionConfig>(config: Config): Config;
|
package/build/config.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @adonisjs/session
|
|
4
|
+
*
|
|
5
|
+
* (c) Harminder Virk <virk@adonisjs.com>
|
|
6
|
+
*
|
|
7
|
+
* For the full copyright and license information, please view the LICENSE
|
|
8
|
+
* file that was distributed with this source code.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.sessionConfig = void 0;
|
|
12
|
+
/**
|
|
13
|
+
* Helper to define session config
|
|
14
|
+
*/
|
|
15
|
+
function sessionConfig(config) {
|
|
16
|
+
return config;
|
|
17
|
+
}
|
|
18
|
+
exports.sessionConfig = sessionConfig;
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
11
|
exports.defineTestsBindings = void 0;
|
|
12
|
+
const util_1 = require("util");
|
|
12
13
|
/**
|
|
13
14
|
* Define test bindings
|
|
14
15
|
*/
|
|
@@ -89,6 +90,14 @@ function defineTestsBindings(ApiRequest, ApiResponse, ApiClient, SessionManager)
|
|
|
89
90
|
this.ensureHasAssert();
|
|
90
91
|
this.assert.notProperty(this.flashMessages(), name);
|
|
91
92
|
});
|
|
93
|
+
/**
|
|
94
|
+
* Dump session to the console
|
|
95
|
+
*/
|
|
96
|
+
ApiResponse.macro('dumpSession', function (options) {
|
|
97
|
+
const inspectOptions = { depth: 2, showHidden: false, colors: true, ...options };
|
|
98
|
+
console.log(`"session" => ${(0, util_1.inspect)(this.session(), inspectOptions)}`);
|
|
99
|
+
console.log(`"flashMessages" => ${(0, util_1.inspect)(this.flashMessages(), inspectOptions)}`);
|
|
100
|
+
});
|
|
92
101
|
/**
|
|
93
102
|
* Adding hooks directly on the request object moves the hooks to
|
|
94
103
|
* the end of the queue (basically after the globally hooks)
|
|
@@ -123,7 +132,7 @@ function defineTestsBindings(ApiRequest, ApiResponse, ApiClient, SessionManager)
|
|
|
123
132
|
* data
|
|
124
133
|
*/
|
|
125
134
|
req.teardown(async (response) => {
|
|
126
|
-
response.sessionJar = await response.request.sessionClient.load();
|
|
135
|
+
response.sessionJar = await response.request.sessionClient.load(response.cookies());
|
|
127
136
|
await response.request.sessionClient.forget();
|
|
128
137
|
});
|
|
129
138
|
});
|
|
@@ -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
|
|
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 {
|
|
@@ -34,6 +34,11 @@ export declare class Session implements SessionContract {
|
|
|
34
34
|
* A copy of previously set flash messages
|
|
35
35
|
*/
|
|
36
36
|
flashMessages: Store;
|
|
37
|
+
/**
|
|
38
|
+
* Session id for the current request. It will be different
|
|
39
|
+
* from the "this.sessionId" when regenerate is called.
|
|
40
|
+
*/
|
|
41
|
+
private currentSessionId;
|
|
37
42
|
/**
|
|
38
43
|
* A instance of store with values read from the driver. The store
|
|
39
44
|
* in initiated inside the [[initiate]] method
|
|
@@ -43,7 +48,7 @@ export declare class Session implements SessionContract {
|
|
|
43
48
|
* Whether or not to re-generate the session id before comitting
|
|
44
49
|
* session values.
|
|
45
50
|
*/
|
|
46
|
-
private
|
|
51
|
+
private regeneratedSessionId;
|
|
47
52
|
/**
|
|
48
53
|
* A copy of flash messages. The `input` messages
|
|
49
54
|
* are overwritten when any of the input related
|
|
@@ -46,11 +46,16 @@ class Session {
|
|
|
46
46
|
* A copy of previously set flash messages
|
|
47
47
|
*/
|
|
48
48
|
this.flashMessages = new Store_1.Store({});
|
|
49
|
+
/**
|
|
50
|
+
* Session id for the current request. It will be different
|
|
51
|
+
* from the "this.sessionId" when regenerate is called.
|
|
52
|
+
*/
|
|
53
|
+
this.currentSessionId = this.sessionId;
|
|
49
54
|
/**
|
|
50
55
|
* Whether or not to re-generate the session id before comitting
|
|
51
56
|
* session values.
|
|
52
57
|
*/
|
|
53
|
-
this.
|
|
58
|
+
this.regeneratedSessionId = false;
|
|
54
59
|
/**
|
|
55
60
|
* A copy of flash messages. The `input` messages
|
|
56
61
|
* are overwritten when any of the input related
|
|
@@ -180,7 +185,8 @@ class Session {
|
|
|
180
185
|
*/
|
|
181
186
|
regenerate() {
|
|
182
187
|
this.ctx.logger.trace('explicitly re-generating session id');
|
|
183
|
-
this.
|
|
188
|
+
this.sessionId = (0, helpers_1.cuid)();
|
|
189
|
+
this.regeneratedSessionId = true;
|
|
184
190
|
}
|
|
185
191
|
/**
|
|
186
192
|
* Set/update session value
|
|
@@ -331,9 +337,8 @@ class Session {
|
|
|
331
337
|
/**
|
|
332
338
|
* Cleanup old session and re-generate new session
|
|
333
339
|
*/
|
|
334
|
-
if (this.
|
|
335
|
-
await this.driver.destroy(this.
|
|
336
|
-
this.sessionId = (0, helpers_1.cuid)();
|
|
340
|
+
if (this.regeneratedSessionId) {
|
|
341
|
+
await this.driver.destroy(this.currentSessionId);
|
|
337
342
|
}
|
|
338
343
|
/**
|
|
339
344
|
* Touch the session cookie to keep it alive.
|
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
|
|
8
8
|
import Env from '@ioc:Adonis/Core/Env'
|
|
9
9
|
import Application from '@ioc:Adonis/Core/Application'
|
|
10
|
-
import {
|
|
10
|
+
import { sessionConfig } from '@adonisjs/session/build/config'
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
export default sessionConfig({
|
|
13
13
|
/*
|
|
14
14
|
|--------------------------------------------------------------------------
|
|
15
15
|
| Enable/Disable sessions
|
|
@@ -113,6 +113,4 @@ const sessionConfig: SessionConfig = {
|
|
|
113
113
|
|
|
|
114
114
|
*/
|
|
115
115
|
redisConnection: 'local',
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export default sessionConfig
|
|
116
|
+
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonisjs/session",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.4.0",
|
|
4
4
|
"description": "Session provider for AdonisJS",
|
|
5
5
|
"typings": "./build/adonis-typings/index.d.ts",
|
|
6
6
|
"main": "build/providers/SessionProvider.js",
|
|
@@ -8,44 +8,47 @@
|
|
|
8
8
|
"build/adonis-typings",
|
|
9
9
|
"build/providers",
|
|
10
10
|
"build/src",
|
|
11
|
+
"build/config.js",
|
|
12
|
+
"build/config.d.ts",
|
|
11
13
|
"build/templates",
|
|
12
14
|
"build/instructions.md"
|
|
13
15
|
],
|
|
14
16
|
"dependencies": {
|
|
15
17
|
"@poppinss/utils": "^4.0.4",
|
|
16
|
-
"fs-extra": "^10.0
|
|
18
|
+
"fs-extra": "^10.1.0"
|
|
17
19
|
},
|
|
18
20
|
"peerDependencies": {
|
|
19
|
-
"@adonisjs/core": "^5.
|
|
21
|
+
"@adonisjs/core": "^5.8.0"
|
|
20
22
|
},
|
|
21
23
|
"devDependencies": {
|
|
22
|
-
"@adonisjs/core": "^5.
|
|
24
|
+
"@adonisjs/core": "^5.8.2",
|
|
23
25
|
"@adonisjs/mrm-preset": "^5.0.3",
|
|
24
|
-
"@adonisjs/redis": "^7.
|
|
26
|
+
"@adonisjs/redis": "^7.3.0",
|
|
25
27
|
"@adonisjs/require-ts": "^2.0.11",
|
|
26
28
|
"@japa/assert": "^1.3.4",
|
|
27
29
|
"@japa/preset-adonis": "^1.0.15",
|
|
28
30
|
"@japa/run-failed-tests": "^1.0.7",
|
|
29
|
-
"@japa/runner": "^2.0.
|
|
31
|
+
"@japa/runner": "^2.0.8",
|
|
30
32
|
"@japa/spec-reporter": "^1.1.12",
|
|
31
33
|
"@poppinss/dev-utils": "^2.0.3",
|
|
32
|
-
"@types/node": "^17.0.
|
|
34
|
+
"@types/node": "^17.0.34",
|
|
33
35
|
"@types/supertest": "^2.0.12",
|
|
34
36
|
"commitizen": "^4.2.4",
|
|
35
37
|
"copyfiles": "^2.4.1",
|
|
36
38
|
"cz-conventional-changelog": "^3.3.0",
|
|
37
39
|
"del-cli": "^4.0.1",
|
|
38
|
-
"eslint": "^8.
|
|
40
|
+
"eslint": "^8.15.0",
|
|
39
41
|
"eslint-config-prettier": "^8.5.0",
|
|
40
42
|
"eslint-plugin-adonis": "^2.1.0",
|
|
41
43
|
"eslint-plugin-prettier": "^4.0.0",
|
|
42
44
|
"github-label-sync": "^2.2.0",
|
|
43
|
-
"husky": "^
|
|
45
|
+
"husky": "^8.0.1",
|
|
44
46
|
"mrm": "^4.0.0",
|
|
45
47
|
"np": "^7.6.1",
|
|
46
48
|
"prettier": "^2.6.2",
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
+
"set-cookie-parser": "^2.4.8",
|
|
50
|
+
"supertest": "^6.2.3",
|
|
51
|
+
"typescript": "^4.6.4"
|
|
49
52
|
},
|
|
50
53
|
"scripts": {
|
|
51
54
|
"mrm": "mrm --preset=@adonisjs/mrm-preset",
|