@adonisjs/session 7.5.0 → 8.0.0-next.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/{chunk-TZLOND27.js → chunk-DFXWYDMY.js} +21 -3
- package/build/chunk-HAD4PFFM.js +229 -0
- package/build/{chunk-WUWXIKIB.js → chunk-MVBWJOEG.js} +54 -14
- package/build/{chunk-ZVSEMDIC.js → chunk-SBOMJK4T.js} +1 -2
- package/build/{chunk-OCQGCVXK.js → chunk-SHD6OX52.js} +169 -75
- package/build/chunk-Y566BNUT.js +113 -0
- package/build/{cookie-WBWYVEDW.js → cookie-YBBGLCO5.js} +38 -6
- package/build/{dynamodb-3PG52TE3.js → dynamodb-PLZABBFD.js} +54 -8
- package/build/factories/main.d.ts +1 -1
- package/build/factories/main.js +5 -6
- package/build/factories/session_middleware_factory.d.ts +2 -2
- package/build/{file-B6QKOZXW.js → file-CCJ5ESE2.js} +49 -14
- package/build/index.d.ts +6 -6
- package/build/index.js +4 -5
- package/build/providers/session_provider.d.ts +1 -1
- package/build/providers/session_provider.js +5 -6
- package/build/{redis-CAY24YIA.js → redis-NXJWWWVB.js} +39 -8
- package/build/src/client.d.ts +46 -10
- package/build/src/client.js +3 -4
- package/build/src/define_config.d.ts +37 -4
- package/build/src/errors.d.ts +20 -4
- package/build/src/plugins/edge.d.ts +12 -2
- package/build/src/plugins/edge.js +1 -2
- package/build/src/plugins/japa/api_client.d.ts +22 -4
- package/build/src/plugins/japa/api_client.js +5 -5
- package/build/src/plugins/japa/browser_client.d.ts +18 -4
- package/build/src/plugins/japa/browser_client.js +5 -5
- package/build/src/session.d.ts +171 -58
- package/build/src/session_middleware.d.ts +28 -5
- package/build/src/session_middleware.js +4 -5
- package/build/src/stores/cookie.d.ts +41 -7
- package/build/src/stores/dynamodb.d.ts +44 -8
- package/build/src/stores/file.d.ts +34 -8
- package/build/src/stores/memory.d.ts +34 -5
- package/build/src/stores/redis.d.ts +37 -7
- package/build/src/types.d.ts +155 -34
- package/build/src/types.js +0 -1
- package/build/src/values_store.d.ts +113 -21
- package/package.json +47 -44
- package/build/chunk-GB5FBZCV.js +0 -85
- package/build/chunk-GB5FBZCV.js.map +0 -1
- package/build/chunk-OCQGCVXK.js.map +0 -1
- package/build/chunk-TE5JP3SX.js +0 -151
- package/build/chunk-TE5JP3SX.js.map +0 -1
- package/build/chunk-TZLOND27.js.map +0 -1
- package/build/chunk-WUWXIKIB.js.map +0 -1
- package/build/chunk-ZVSEMDIC.js.map +0 -1
- package/build/cookie-WBWYVEDW.js.map +0 -1
- package/build/dynamodb-3PG52TE3.js.map +0 -1
- package/build/factories/main.js.map +0 -1
- package/build/file-B6QKOZXW.js.map +0 -1
- package/build/index.js.map +0 -1
- package/build/providers/session_provider.js.map +0 -1
- package/build/redis-CAY24YIA.js.map +0 -1
- package/build/src/client.js.map +0 -1
- package/build/src/plugins/edge.js.map +0 -1
- package/build/src/plugins/japa/api_client.js.map +0 -1
- package/build/src/plugins/japa/browser_client.js.map +0 -1
- package/build/src/session_middleware.js.map +0 -1
- package/build/src/types.js.map +0 -1
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import '@japa/plugin-adonisjs';
|
|
1
2
|
import type { PluginFn } from '@japa/runner/types';
|
|
2
3
|
import type { ApplicationService } from '@adonisjs/core/types';
|
|
3
|
-
import { SessionClient } from '../../client.
|
|
4
|
-
import type { SessionData } from '../../types.
|
|
4
|
+
import { SessionClient } from '../../client.ts';
|
|
5
|
+
import type { SessionData } from '../../types.ts';
|
|
5
6
|
declare module '@japa/api-client' {
|
|
6
7
|
interface ApiRequest {
|
|
7
8
|
sessionClient: SessionClient;
|
|
@@ -69,7 +70,24 @@ declare module '@japa/api-client' {
|
|
|
69
70
|
}
|
|
70
71
|
}
|
|
71
72
|
/**
|
|
72
|
-
* Hooks AdonisJS Session with the Japa API client
|
|
73
|
-
*
|
|
73
|
+
* Hooks AdonisJS Session with the Japa API client plugin.
|
|
74
|
+
* Provides session methods and assertions for API testing.
|
|
75
|
+
*
|
|
76
|
+
* @param app - AdonisJS application service
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* // Register in test setup
|
|
80
|
+
* import { sessionApiClient } from '@adonisjs/session/plugins/japa/api_client'
|
|
81
|
+
*
|
|
82
|
+
* // Use in API tests
|
|
83
|
+
* test('can authenticate user', async ({ client }) => {
|
|
84
|
+
* const response = await client
|
|
85
|
+
* .post('/login')
|
|
86
|
+
* .withSession({ remember: true })
|
|
87
|
+
* .json({ email: 'user@example.com', password: 'secret' })
|
|
88
|
+
*
|
|
89
|
+
* response.assertSession('userId', 123)
|
|
90
|
+
* response.assertFlashMessage('success', 'Welcome back!')
|
|
91
|
+
* })
|
|
74
92
|
*/
|
|
75
93
|
export declare const sessionApiClient: (app: ApplicationService) => PluginFn;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SessionClient
|
|
3
|
-
} from "../../../chunk-
|
|
4
|
-
import "../../../chunk-
|
|
5
|
-
import "../../../chunk-
|
|
3
|
+
} from "../../../chunk-Y566BNUT.js";
|
|
4
|
+
import "../../../chunk-HAD4PFFM.js";
|
|
5
|
+
import "../../../chunk-SBOMJK4T.js";
|
|
6
6
|
|
|
7
7
|
// src/plugins/japa/api_client.ts
|
|
8
|
+
import "@japa/plugin-adonisjs";
|
|
8
9
|
import lodash from "@poppinss/utils/lodash";
|
|
9
10
|
import { configProvider } from "@adonisjs/core";
|
|
10
|
-
import { RuntimeException } from "@
|
|
11
|
+
import { RuntimeException } from "@adonisjs/core/exceptions";
|
|
11
12
|
import { ApiClient, ApiRequest, ApiResponse } from "@japa/api-client";
|
|
12
13
|
var sessionApiClient = (app) => {
|
|
13
14
|
const pluginFn = async function() {
|
|
@@ -97,4 +98,3 @@ var sessionApiClient = (app) => {
|
|
|
97
98
|
export {
|
|
98
99
|
sessionApiClient
|
|
99
100
|
};
|
|
100
|
-
//# sourceMappingURL=api_client.js.map
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import '@japa/plugin-adonisjs';
|
|
1
2
|
import type { PluginFn } from '@japa/runner/types';
|
|
2
3
|
import type { ApplicationService } from '@adonisjs/core/types';
|
|
3
4
|
import type { CookieOptions as AdonisCookieOptions } from '@adonisjs/core/types/http';
|
|
4
|
-
import { SessionClient } from '../../client.
|
|
5
|
-
import type { SessionData } from '../../types.
|
|
5
|
+
import { SessionClient } from '../../client.ts';
|
|
6
|
+
import type { SessionData } from '../../types.ts';
|
|
6
7
|
declare module 'playwright' {
|
|
7
8
|
interface BrowserContext {
|
|
8
9
|
sessionClient: SessionClient;
|
|
@@ -30,7 +31,20 @@ declare module 'playwright' {
|
|
|
30
31
|
}
|
|
31
32
|
}
|
|
32
33
|
/**
|
|
33
|
-
* Hooks AdonisJS Session with the Japa browser client
|
|
34
|
-
*
|
|
34
|
+
* Hooks AdonisJS Session with the Japa browser client plugin.
|
|
35
|
+
* Provides session methods for browser testing context.
|
|
36
|
+
*
|
|
37
|
+
* @param app - AdonisJS application service
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* // Register in test setup
|
|
41
|
+
* import { sessionBrowserClient } from '@adonisjs/session/plugins/japa/browser_client'
|
|
42
|
+
*
|
|
43
|
+
* // Use in browser tests
|
|
44
|
+
* test('can set session data', async ({ visit }) => {
|
|
45
|
+
* await visit.context().setSession({ userId: 123 })
|
|
46
|
+
* const response = await visit('/profile')
|
|
47
|
+
* // Assert profile page shows user data
|
|
48
|
+
* })
|
|
35
49
|
*/
|
|
36
50
|
export declare const sessionBrowserClient: (app: ApplicationService) => PluginFn;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SessionClient
|
|
3
|
-
} from "../../../chunk-
|
|
4
|
-
import "../../../chunk-
|
|
5
|
-
import "../../../chunk-
|
|
3
|
+
} from "../../../chunk-Y566BNUT.js";
|
|
4
|
+
import "../../../chunk-HAD4PFFM.js";
|
|
5
|
+
import "../../../chunk-SBOMJK4T.js";
|
|
6
6
|
|
|
7
7
|
// src/plugins/japa/browser_client.ts
|
|
8
|
+
import "@japa/plugin-adonisjs";
|
|
8
9
|
import { configProvider } from "@adonisjs/core";
|
|
9
|
-
import { RuntimeException } from "@poppinss/utils";
|
|
10
10
|
import { decoratorsCollection } from "@japa/browser-client";
|
|
11
|
+
import { RuntimeException } from "@adonisjs/core/exceptions";
|
|
11
12
|
function transformSameSiteOption(sameSite) {
|
|
12
13
|
if (!sameSite) {
|
|
13
14
|
return;
|
|
@@ -85,4 +86,3 @@ var sessionBrowserClient = (app) => {
|
|
|
85
86
|
export {
|
|
86
87
|
sessionBrowserClient
|
|
87
88
|
};
|
|
88
|
-
//# sourceMappingURL=browser_client.js.map
|
package/build/src/session.d.ts
CHANGED
|
@@ -2,169 +2,282 @@ import Macroable from '@poppinss/macroable';
|
|
|
2
2
|
import type { HttpContext } from '@adonisjs/core/http';
|
|
3
3
|
import type { EmitterService } from '@adonisjs/core/types';
|
|
4
4
|
import type { HttpError } from '@adonisjs/core/types/http';
|
|
5
|
-
import { ValuesStore } from './values_store.
|
|
6
|
-
import type { SessionData, SessionConfig, SessionStoreFactory, AllowedSessionValues } from './types.
|
|
5
|
+
import { ValuesStore } from './values_store.ts';
|
|
6
|
+
import type { SessionData, SessionConfig, SessionStoreFactory, AllowedSessionValues } from './types.ts';
|
|
7
7
|
/**
|
|
8
8
|
* The session class exposes the API to read and write values to
|
|
9
9
|
* the session store.
|
|
10
10
|
*
|
|
11
11
|
* A session instance is isolated between requests but
|
|
12
|
-
* uses a centralized persistence store
|
|
12
|
+
* uses a centralized persistence store.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // Creating and using a session
|
|
16
|
+
* const session = new Session(config, storeFactory, emitter, ctx)
|
|
17
|
+
* await session.initiate(false)
|
|
18
|
+
*
|
|
19
|
+
* session.put('username', 'john')
|
|
20
|
+
* const username = session.get('username')
|
|
21
|
+
*
|
|
22
|
+
* await session.commit()
|
|
13
23
|
*/
|
|
14
24
|
export declare class Session extends Macroable {
|
|
15
25
|
#private;
|
|
16
26
|
config: SessionConfig;
|
|
17
27
|
/**
|
|
18
|
-
* Store of flash messages that be written during the
|
|
19
|
-
* HTTP request
|
|
28
|
+
* Store of flash messages that will be written during the HTTP request
|
|
20
29
|
*/
|
|
21
30
|
responseFlashMessages: ValuesStore;
|
|
22
31
|
/**
|
|
23
|
-
* Store of flash messages for the current HTTP request
|
|
32
|
+
* Store of flash messages for the current HTTP request
|
|
24
33
|
*/
|
|
25
34
|
flashMessages: ValuesStore;
|
|
26
35
|
/**
|
|
27
|
-
* The key
|
|
28
|
-
* the session store.
|
|
36
|
+
* The key used for storing flash messages inside the session store
|
|
29
37
|
*/
|
|
30
38
|
flashKey: string;
|
|
31
39
|
/**
|
|
32
|
-
*
|
|
40
|
+
* Gets the session id for the current HTTP request
|
|
33
41
|
*/
|
|
34
42
|
get sessionId(): string;
|
|
35
43
|
/**
|
|
36
|
-
*
|
|
37
|
-
* the request
|
|
44
|
+
* Returns true if a fresh session was created during the request
|
|
38
45
|
*/
|
|
39
46
|
get fresh(): boolean;
|
|
40
47
|
/**
|
|
41
|
-
*
|
|
42
|
-
* state
|
|
48
|
+
* Returns true if the session is in readonly state
|
|
43
49
|
*/
|
|
44
50
|
get readonly(): boolean;
|
|
45
51
|
/**
|
|
46
|
-
*
|
|
52
|
+
* Returns true if the session store has been initiated
|
|
47
53
|
*/
|
|
48
54
|
get initiated(): boolean;
|
|
49
55
|
/**
|
|
50
|
-
*
|
|
51
|
-
* during the current request
|
|
56
|
+
* Returns true if the session id has been re-generated during the current request
|
|
52
57
|
*/
|
|
53
58
|
get hasRegeneratedSession(): boolean;
|
|
54
59
|
/**
|
|
55
|
-
*
|
|
60
|
+
* Returns true if the session store is empty
|
|
56
61
|
*/
|
|
57
62
|
get isEmpty(): boolean;
|
|
58
63
|
/**
|
|
59
|
-
*
|
|
60
|
-
* modified
|
|
64
|
+
* Returns true if the session store has been modified
|
|
61
65
|
*/
|
|
62
66
|
get hasBeenModified(): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Creates a new session instance
|
|
69
|
+
*
|
|
70
|
+
* @param config - Session configuration
|
|
71
|
+
* @param storeFactory - Factory function to create session store
|
|
72
|
+
* @param emitter - Event emitter service
|
|
73
|
+
* @param ctx - HTTP context
|
|
74
|
+
*/
|
|
63
75
|
constructor(config: SessionConfig, storeFactory: SessionStoreFactory, emitter: EmitterService, ctx: HttpContext);
|
|
64
76
|
/**
|
|
65
|
-
* Initiates the session store. The method results in a noop
|
|
66
|
-
*
|
|
77
|
+
* Initiates the session store. The method results in a noop when called multiple times.
|
|
78
|
+
*
|
|
79
|
+
* @param readonly - Whether to initiate the session in readonly mode
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* await session.initiate(false) // Read-write mode
|
|
83
|
+
* await session.initiate(true) // Readonly mode
|
|
67
84
|
*/
|
|
68
85
|
initiate(readonly: boolean): Promise<void>;
|
|
69
86
|
/**
|
|
70
|
-
*
|
|
87
|
+
* Puts a key-value pair to the session data store
|
|
88
|
+
*
|
|
89
|
+
* @param key - The key to store the value under
|
|
90
|
+
* @param value - The value to store
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* session.put('username', 'john')
|
|
94
|
+
* session.put('user.preferences', { theme: 'dark' })
|
|
71
95
|
*/
|
|
72
96
|
put(key: string, value: AllowedSessionValues): void;
|
|
73
97
|
/**
|
|
74
|
-
*
|
|
98
|
+
* Checks if a key exists inside the datastore
|
|
99
|
+
*
|
|
100
|
+
* @param key - The key to check for existence
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* if (session.has('username')) {
|
|
104
|
+
* console.log('User is logged in')
|
|
105
|
+
* }
|
|
75
106
|
*/
|
|
76
107
|
has(key: string): boolean;
|
|
77
108
|
/**
|
|
78
|
-
*
|
|
79
|
-
* You can specify a default value to use
|
|
80
|
-
*
|
|
109
|
+
* Gets the value of a key from the session datastore.
|
|
110
|
+
* You can specify a default value to use when key does not exist or has undefined value.
|
|
111
|
+
*
|
|
112
|
+
* @param key - The key to retrieve
|
|
113
|
+
* @param defaultValue - Default value to return if key doesn't exist
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* const username = session.get('username', 'guest')
|
|
117
|
+
* const preferences = session.get('user.preferences', {})
|
|
81
118
|
*/
|
|
82
119
|
get(key: string, defaultValue?: any): any;
|
|
83
120
|
/**
|
|
84
|
-
*
|
|
121
|
+
* Gets everything from the session store
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* const allData = session.all()
|
|
125
|
+
* console.log(allData) // { username: 'john', theme: 'dark' }
|
|
85
126
|
*/
|
|
86
127
|
all(): any;
|
|
87
128
|
/**
|
|
88
|
-
*
|
|
129
|
+
* Removes a key from the session datastore
|
|
130
|
+
*
|
|
131
|
+
* @param key - The key to remove
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* session.forget('temp_data')
|
|
135
|
+
* session.forget('user.cache')
|
|
89
136
|
*/
|
|
90
137
|
forget(key: string): void;
|
|
91
138
|
/**
|
|
92
|
-
*
|
|
93
|
-
*
|
|
139
|
+
* Reads value for a key from the session datastore and removes it simultaneously
|
|
140
|
+
*
|
|
141
|
+
* @param key - The key to pull
|
|
142
|
+
* @param defaultValue - Default value to return if key doesn't exist
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* const message = session.pull('notification', 'No messages')
|
|
146
|
+
* // message contains the value, and it's removed from session
|
|
94
147
|
*/
|
|
95
148
|
pull(key: string, defaultValue?: any): any;
|
|
96
149
|
/**
|
|
97
|
-
*
|
|
98
|
-
*
|
|
150
|
+
* Increments the value of a key inside the session store.
|
|
151
|
+
* A new key will be defined if it doesn't exist already with value 1.
|
|
152
|
+
*
|
|
153
|
+
* @param key - The key to increment
|
|
154
|
+
* @param steps - Number of steps to increment (default: 1)
|
|
99
155
|
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
156
|
+
* @example
|
|
157
|
+
* session.increment('page_views') // Increments by 1
|
|
158
|
+
* session.increment('score', 10) // Increments by 10
|
|
102
159
|
*/
|
|
103
160
|
increment(key: string, steps?: number): void;
|
|
104
161
|
/**
|
|
105
|
-
*
|
|
106
|
-
*
|
|
162
|
+
* Decrements the value of a key inside the session store.
|
|
163
|
+
* A new key will be defined if it doesn't exist already with value -1.
|
|
107
164
|
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
165
|
+
* @param key - The key to decrement
|
|
166
|
+
* @param steps - Number of steps to decrement (default: 1)
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* session.decrement('attempts') // Decrements by 1
|
|
170
|
+
* session.decrement('credits', 5) // Decrements by 5
|
|
110
171
|
*/
|
|
111
172
|
decrement(key: string, steps?: number): void;
|
|
112
173
|
/**
|
|
113
|
-
*
|
|
174
|
+
* Empties the session store
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* session.clear() // Removes all session data
|
|
114
178
|
*/
|
|
115
179
|
clear(): void;
|
|
116
180
|
/**
|
|
117
|
-
*
|
|
181
|
+
* Adds a key-value pair to flash messages
|
|
182
|
+
*
|
|
183
|
+
* @param key - The key or object of key-value pairs to flash
|
|
184
|
+
* @param value - The value to flash (when key is a string)
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* session.flash('success', 'Data saved successfully!')
|
|
188
|
+
* session.flash({ error: 'Validation failed', info: 'Try again' })
|
|
118
189
|
*/
|
|
119
190
|
flash(key: string, value: AllowedSessionValues): void;
|
|
120
191
|
flash(keyValue: SessionData): void;
|
|
121
192
|
/**
|
|
122
|
-
*
|
|
123
|
-
* errors via the "@error" tag.
|
|
124
|
-
*
|
|
193
|
+
* Flashes errors to the errorsBag. You can read these errors via the "@error" tag.
|
|
125
194
|
* Appends new messages to the existing collection.
|
|
195
|
+
*
|
|
196
|
+
* @param errorsCollection - Collection of error messages
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* session.flashErrors({
|
|
200
|
+
* general: 'Something went wrong',
|
|
201
|
+
* validation: ['Name is required', 'Email is invalid']
|
|
202
|
+
* })
|
|
126
203
|
*/
|
|
127
204
|
flashErrors(errorsCollection: Record<string, string | string[]>): void;
|
|
128
205
|
/**
|
|
129
|
-
*
|
|
130
|
-
*
|
|
206
|
+
* Flashes validation error messages. Make sure the error is an instance of VineJS ValidationException.
|
|
207
|
+
* Overrides existing inputErrors.
|
|
208
|
+
*
|
|
209
|
+
* @param error - HTTP error containing validation messages
|
|
131
210
|
*
|
|
132
|
-
*
|
|
211
|
+
* @example
|
|
212
|
+
* try {
|
|
213
|
+
* await request.validate(schema)
|
|
214
|
+
* } catch (error) {
|
|
215
|
+
* session.flashValidationErrors(error)
|
|
216
|
+
* }
|
|
133
217
|
*/
|
|
134
|
-
flashValidationErrors(error: HttpError): void;
|
|
218
|
+
flashValidationErrors(error: HttpError, withInput?: boolean): void;
|
|
135
219
|
/**
|
|
136
|
-
*
|
|
220
|
+
* Flashes all form input data to the flash messages store
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* session.flashAll() // Flashes all request input for next request
|
|
137
224
|
*/
|
|
138
225
|
flashAll(): void;
|
|
139
226
|
/**
|
|
140
|
-
*
|
|
227
|
+
* Flashes form input data (except some keys) to the flash messages store
|
|
228
|
+
*
|
|
229
|
+
* @param keys - Array of keys to exclude from flashing
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* session.flashExcept(['password', '_csrf'])
|
|
141
233
|
*/
|
|
142
234
|
flashExcept(keys: string[]): void;
|
|
143
235
|
/**
|
|
144
|
-
*
|
|
236
|
+
* Flashes form input data (only some keys) to the flash messages store
|
|
237
|
+
*
|
|
238
|
+
* @param keys - Array of keys to include in flashing
|
|
239
|
+
*
|
|
240
|
+
* @example
|
|
241
|
+
* session.flashOnly(['name', 'email'])
|
|
145
242
|
*/
|
|
146
243
|
flashOnly(keys: string[]): void;
|
|
147
244
|
/**
|
|
148
|
-
*
|
|
245
|
+
* Reflashes messages from the last request in the current response
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
* session.reflash() // Keep all flash messages for another request
|
|
149
249
|
*/
|
|
150
250
|
reflash(): void;
|
|
151
251
|
/**
|
|
152
|
-
*
|
|
153
|
-
*
|
|
252
|
+
* Reflashes messages (only some keys) from the last request in the current response
|
|
253
|
+
*
|
|
254
|
+
* @param keys - Array of keys to reflash
|
|
255
|
+
*
|
|
256
|
+
* @example
|
|
257
|
+
* session.reflashOnly(['success', 'info'])
|
|
154
258
|
*/
|
|
155
259
|
reflashOnly(keys: string[]): void;
|
|
156
260
|
/**
|
|
157
|
-
*
|
|
158
|
-
*
|
|
261
|
+
* Reflashes messages (except some keys) from the last request in the current response
|
|
262
|
+
*
|
|
263
|
+
* @param keys - Array of keys to exclude from reflashing
|
|
264
|
+
*
|
|
265
|
+
* @example
|
|
266
|
+
* session.reflashExcept(['error', 'warning'])
|
|
159
267
|
*/
|
|
160
268
|
reflashExcept(keys: string[]): void;
|
|
161
269
|
/**
|
|
162
|
-
* Re-
|
|
270
|
+
* Re-generates the session id and migrates data to it
|
|
271
|
+
*
|
|
272
|
+
* @example
|
|
273
|
+
* session.regenerate() // Generates new session ID for security
|
|
163
274
|
*/
|
|
164
275
|
regenerate(): void;
|
|
165
276
|
/**
|
|
166
|
-
*
|
|
167
|
-
*
|
|
277
|
+
* Commits session changes. No more mutations will be allowed after commit.
|
|
278
|
+
*
|
|
279
|
+
* @example
|
|
280
|
+
* await session.commit() // Save all changes to the session store
|
|
168
281
|
*/
|
|
169
282
|
commit(): Promise<void>;
|
|
170
283
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { EmitterService } from '@adonisjs/core/types';
|
|
2
1
|
import type { NextFn } from '@adonisjs/core/types/http';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
2
|
+
import { type EmitterService } from '@adonisjs/core/types';
|
|
3
|
+
import { type HttpContext } from '@adonisjs/core/http';
|
|
4
|
+
import { Session } from './session.ts';
|
|
5
|
+
import type { SessionConfig, SessionStoreFactory } from './types.ts';
|
|
6
6
|
/**
|
|
7
7
|
* HttpContext augmentations
|
|
8
8
|
*/
|
|
@@ -13,13 +13,36 @@ declare module '@adonisjs/core/http' {
|
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
15
|
* Session middleware is used to initiate the session store
|
|
16
|
-
* and commit its values during an HTTP request
|
|
16
|
+
* and commit its values during an HTTP request.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* // Register middleware in start/kernel.ts
|
|
20
|
+
* server.use([
|
|
21
|
+
* () => import('#middleware/session_middleware')
|
|
22
|
+
* ])
|
|
23
|
+
*
|
|
24
|
+
* // Access session in route handler
|
|
25
|
+
* Route.get('/', ({ session }) => {
|
|
26
|
+
* session.put('visited', true)
|
|
27
|
+
* })
|
|
17
28
|
*/
|
|
18
29
|
export default class SessionMiddleware<KnownStores extends Record<string, SessionStoreFactory>> {
|
|
19
30
|
#private;
|
|
31
|
+
/**
|
|
32
|
+
* Creates a new session middleware instance
|
|
33
|
+
*
|
|
34
|
+
* @param config - Session configuration with store settings
|
|
35
|
+
* @param emitter - Event emitter service
|
|
36
|
+
*/
|
|
20
37
|
constructor(config: SessionConfig & {
|
|
21
38
|
store: keyof KnownStores;
|
|
22
39
|
stores: KnownStores;
|
|
23
40
|
}, emitter: EmitterService);
|
|
41
|
+
/**
|
|
42
|
+
* Handles the HTTP request by initializing session and committing changes
|
|
43
|
+
*
|
|
44
|
+
* @param ctx - HTTP context
|
|
45
|
+
* @param next - Next middleware function
|
|
46
|
+
*/
|
|
24
47
|
handle(ctx: HttpContext, next: NextFn): Promise<any>;
|
|
25
48
|
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SessionMiddleware
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
5
|
-
import "../chunk-
|
|
6
|
-
import "../chunk-
|
|
3
|
+
} from "../chunk-DFXWYDMY.js";
|
|
4
|
+
import "../chunk-SHD6OX52.js";
|
|
5
|
+
import "../chunk-HAD4PFFM.js";
|
|
6
|
+
import "../chunk-SBOMJK4T.js";
|
|
7
7
|
export {
|
|
8
8
|
SessionMiddleware as default
|
|
9
9
|
};
|
|
10
|
-
//# sourceMappingURL=session_middleware.js.map
|
|
@@ -1,27 +1,61 @@
|
|
|
1
1
|
import type { HttpContext } from '@adonisjs/core/http';
|
|
2
2
|
import type { CookieOptions } from '@adonisjs/core/types/http';
|
|
3
|
-
import type { SessionData, SessionStoreContract } from '../types.
|
|
3
|
+
import type { SessionData, SessionStoreContract } from '../types.ts';
|
|
4
4
|
/**
|
|
5
|
-
* Cookie store stores the session data inside an encrypted
|
|
6
|
-
*
|
|
5
|
+
* Cookie store stores the session data inside an encrypted cookie.
|
|
6
|
+
* Best for simple applications with minimal session data.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const cookieStore = new CookieStore({
|
|
10
|
+
* httpOnly: true,
|
|
11
|
+
* secure: true,
|
|
12
|
+
* sameSite: 'strict'
|
|
13
|
+
* }, ctx)
|
|
7
14
|
*/
|
|
8
15
|
export declare class CookieStore implements SessionStoreContract {
|
|
9
16
|
#private;
|
|
17
|
+
/**
|
|
18
|
+
* Creates a new cookie store instance
|
|
19
|
+
*
|
|
20
|
+
* @param config - Cookie configuration options
|
|
21
|
+
* @param ctx - HTTP context
|
|
22
|
+
*/
|
|
10
23
|
constructor(config: Partial<CookieOptions>, ctx: HttpContext);
|
|
11
24
|
/**
|
|
12
|
-
*
|
|
25
|
+
* Reads session value from the encrypted cookie
|
|
26
|
+
*
|
|
27
|
+
* @param sessionId - Session identifier used as cookie name
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* const data = store.read('sess_abc123')
|
|
13
31
|
*/
|
|
14
32
|
read(sessionId: string): SessionData | null;
|
|
15
33
|
/**
|
|
16
|
-
*
|
|
34
|
+
* Writes session values to an encrypted cookie
|
|
35
|
+
*
|
|
36
|
+
* @param sessionId - Session identifier used as cookie name
|
|
37
|
+
* @param values - Session data to store
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* store.write('sess_abc123', { userId: 123, theme: 'dark' })
|
|
17
41
|
*/
|
|
18
42
|
write(sessionId: string, values: SessionData): void;
|
|
19
43
|
/**
|
|
20
|
-
* Removes the session cookie
|
|
44
|
+
* Removes the session cookie from the client
|
|
45
|
+
*
|
|
46
|
+
* @param sessionId - Session identifier used as cookie name
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* store.destroy('sess_abc123')
|
|
21
50
|
*/
|
|
22
51
|
destroy(sessionId: string): void;
|
|
23
52
|
/**
|
|
24
|
-
* Updates the cookie with existing
|
|
53
|
+
* Updates the cookie expiry by rewriting it with existing values
|
|
54
|
+
*
|
|
55
|
+
* @param sessionId - Session identifier used as cookie name
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* store.touch('sess_abc123') // Refreshes cookie expiry
|
|
25
59
|
*/
|
|
26
60
|
touch(sessionId: string): void;
|
|
27
61
|
}
|
|
@@ -6,13 +6,29 @@
|
|
|
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 { DynamoDBClient } from '@aws-sdk/client-dynamodb';
|
|
10
|
-
import type { SessionStoreContract, SessionData } from '../types.
|
|
9
|
+
import { type DynamoDBClient } from '@aws-sdk/client-dynamodb';
|
|
10
|
+
import type { SessionStoreContract, SessionData } from '../types.ts';
|
|
11
11
|
/**
|
|
12
|
-
* DynamoDB store to read/write session to DynamoDB
|
|
12
|
+
* DynamoDB store to read/write session data to AWS DynamoDB.
|
|
13
|
+
* Provides highly scalable, managed session storage with automatic expiry.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* const dynamoStore = new DynamoDBStore(dynamoClient, '2 hours', {
|
|
17
|
+
* tableName: 'Sessions',
|
|
18
|
+
* keyAttribute: 'sessionId'
|
|
19
|
+
* })
|
|
13
20
|
*/
|
|
14
21
|
export declare class DynamoDBStore implements SessionStoreContract {
|
|
15
22
|
#private;
|
|
23
|
+
/**
|
|
24
|
+
* Creates a new DynamoDB store instance
|
|
25
|
+
*
|
|
26
|
+
* @param client - DynamoDB client instance
|
|
27
|
+
* @param age - Session age in seconds or time expression (e.g. '2 hours')
|
|
28
|
+
* @param options - Configuration options
|
|
29
|
+
* @param options.tableName - DynamoDB table name (defaults to "Session")
|
|
30
|
+
* @param options.keyAttribute - Key attribute name (defaults to "key")
|
|
31
|
+
*/
|
|
16
32
|
constructor(client: DynamoDBClient, age: string | number, options?: {
|
|
17
33
|
/**
|
|
18
34
|
* Defaults to "Session"
|
|
@@ -24,20 +40,40 @@ export declare class DynamoDBStore implements SessionStoreContract {
|
|
|
24
40
|
keyAttribute?: string;
|
|
25
41
|
});
|
|
26
42
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
43
|
+
* Reads session data from DynamoDB
|
|
44
|
+
*
|
|
45
|
+
* @param sessionId - Session identifier
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* const data = await store.read('sess_abc123')
|
|
29
49
|
*/
|
|
30
50
|
read(sessionId: string): Promise<SessionData | null>;
|
|
31
51
|
/**
|
|
32
|
-
*
|
|
52
|
+
* Writes session values to DynamoDB with expiry
|
|
53
|
+
*
|
|
54
|
+
* @param sessionId - Session identifier
|
|
55
|
+
* @param values - Session data to store
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* await store.write('sess_abc123', { userId: 123 })
|
|
33
59
|
*/
|
|
34
60
|
write(sessionId: string, values: Object): Promise<void>;
|
|
35
61
|
/**
|
|
36
|
-
*
|
|
62
|
+
* Removes session data from DynamoDB
|
|
63
|
+
*
|
|
64
|
+
* @param sessionId - Session identifier to remove
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* await store.destroy('sess_abc123')
|
|
37
68
|
*/
|
|
38
69
|
destroy(sessionId: string): Promise<void>;
|
|
39
70
|
/**
|
|
40
|
-
* Updates the
|
|
71
|
+
* Updates the session expiry time in DynamoDB
|
|
72
|
+
*
|
|
73
|
+
* @param sessionId - Session identifier
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* await store.touch('sess_abc123')
|
|
41
77
|
*/
|
|
42
78
|
touch(sessionId: string): Promise<void>;
|
|
43
79
|
}
|