@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,25 +1,44 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Session
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-SHD6OX52.js";
|
|
4
4
|
|
|
5
5
|
// src/session_middleware.ts
|
|
6
6
|
import { ExceptionHandler } from "@adonisjs/core/http";
|
|
7
7
|
var originalErrorHandler = ExceptionHandler.prototype.renderValidationErrorAsHTML;
|
|
8
8
|
ExceptionHandler.macro("renderValidationErrorAsHTML", async function(error, ctx) {
|
|
9
9
|
if (ctx.session) {
|
|
10
|
-
ctx.
|
|
10
|
+
const withInput = ctx.request.header("X-Inertia") ? false : true;
|
|
11
|
+
ctx.session.flashValidationErrors(error, withInput);
|
|
11
12
|
ctx.response.redirect("back", true);
|
|
12
13
|
} else {
|
|
13
14
|
return originalErrorHandler(error, ctx);
|
|
14
15
|
}
|
|
15
16
|
});
|
|
16
17
|
var SessionMiddleware = class {
|
|
18
|
+
/**
|
|
19
|
+
* Session configuration including store settings
|
|
20
|
+
*/
|
|
17
21
|
#config;
|
|
22
|
+
/**
|
|
23
|
+
* Event emitter service for session events
|
|
24
|
+
*/
|
|
18
25
|
#emitter;
|
|
26
|
+
/**
|
|
27
|
+
* Creates a new session middleware instance
|
|
28
|
+
*
|
|
29
|
+
* @param config - Session configuration with store settings
|
|
30
|
+
* @param emitter - Event emitter service
|
|
31
|
+
*/
|
|
19
32
|
constructor(config, emitter) {
|
|
20
33
|
this.#config = config;
|
|
21
34
|
this.#emitter = emitter;
|
|
22
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Handles the HTTP request by initializing session and committing changes
|
|
38
|
+
*
|
|
39
|
+
* @param ctx - HTTP context
|
|
40
|
+
* @param next - Next middleware function
|
|
41
|
+
*/
|
|
23
42
|
async handle(ctx, next) {
|
|
24
43
|
if (!this.#config.enabled) {
|
|
25
44
|
return next();
|
|
@@ -41,4 +60,3 @@ var SessionMiddleware = class {
|
|
|
41
60
|
export {
|
|
42
61
|
SessionMiddleware
|
|
43
62
|
};
|
|
44
|
-
//# sourceMappingURL=chunk-TZLOND27.js.map
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
// src/values_store.ts
|
|
2
|
+
import lodash from "@poppinss/utils/lodash";
|
|
3
|
+
import { RuntimeException } from "@adonisjs/core/exceptions";
|
|
4
|
+
var ReadOnlyValuesStore = class {
|
|
5
|
+
/**
|
|
6
|
+
* Underlying store values containing session data
|
|
7
|
+
*/
|
|
8
|
+
values;
|
|
9
|
+
/**
|
|
10
|
+
* Returns true if the store is empty
|
|
11
|
+
*/
|
|
12
|
+
get isEmpty() {
|
|
13
|
+
return !this.values || Object.keys(this.values).length === 0;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new readonly values store
|
|
17
|
+
*
|
|
18
|
+
* @param values - Initial session data or null
|
|
19
|
+
*/
|
|
20
|
+
constructor(values) {
|
|
21
|
+
this.values = values || {};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Gets value for a given key
|
|
25
|
+
*
|
|
26
|
+
* @param key - The key or key path to retrieve
|
|
27
|
+
* @param defaultValue - Default value if key doesn't exist
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* store.get('username', 'guest')
|
|
31
|
+
* store.get(['user', 'preferences', 'theme'], 'light')
|
|
32
|
+
*/
|
|
33
|
+
get(key, defaultValue) {
|
|
34
|
+
const value = lodash.get(this.values, key);
|
|
35
|
+
if (defaultValue !== void 0 && (value === null || value === void 0)) {
|
|
36
|
+
return defaultValue;
|
|
37
|
+
}
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Checks if a value exists. Includes extra guards to check arrays for length.
|
|
42
|
+
*
|
|
43
|
+
* @param key - The key or key path to check
|
|
44
|
+
* @param checkForArraysLength - Whether to check array length (default: true)
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* store.has('username') // Check if key exists
|
|
48
|
+
* store.has(['user', 'roles']) // Check nested key
|
|
49
|
+
* store.has('items', false) // Don't check array length
|
|
50
|
+
*/
|
|
51
|
+
has(key, checkForArraysLength = true) {
|
|
52
|
+
const value = this.get(key);
|
|
53
|
+
if (!Array.isArray(value)) {
|
|
54
|
+
return !!value;
|
|
55
|
+
}
|
|
56
|
+
return checkForArraysLength ? value.length > 0 : !!value;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Gets all values from the store
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* const allData = store.all()
|
|
63
|
+
*/
|
|
64
|
+
all() {
|
|
65
|
+
return this.values;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Returns object representation of values
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* const obj = store.toObject()
|
|
72
|
+
*/
|
|
73
|
+
toObject() {
|
|
74
|
+
return this.all();
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Returns the store values as JSON-serializable data
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* const json = store.toJSON()
|
|
81
|
+
*/
|
|
82
|
+
toJSON() {
|
|
83
|
+
return this.all();
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Returns string representation of the store
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* const str = store.toString()
|
|
90
|
+
*/
|
|
91
|
+
toString() {
|
|
92
|
+
return JSON.stringify(this.all());
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
var ValuesStore = class extends ReadOnlyValuesStore {
|
|
96
|
+
/**
|
|
97
|
+
* Flag to track if the store has been modified
|
|
98
|
+
*/
|
|
99
|
+
#modified = false;
|
|
100
|
+
/**
|
|
101
|
+
* Creates a new values store
|
|
102
|
+
*
|
|
103
|
+
* @param values - Initial session data or null
|
|
104
|
+
*/
|
|
105
|
+
constructor(values) {
|
|
106
|
+
super(values);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Returns true if the store has been modified
|
|
110
|
+
*/
|
|
111
|
+
get hasBeenModified() {
|
|
112
|
+
return this.#modified;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Sets a key/value pair in the store
|
|
116
|
+
*
|
|
117
|
+
* @param key - The key or key path to set
|
|
118
|
+
* @param value - The value to set
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* store.set('username', 'john')
|
|
122
|
+
* store.set(['user', 'preferences'], { theme: 'dark' })
|
|
123
|
+
*/
|
|
124
|
+
set(key, value) {
|
|
125
|
+
this.#modified = true;
|
|
126
|
+
lodash.set(this.values, key, value);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Removes a key from the store
|
|
130
|
+
*
|
|
131
|
+
* @param key - The key or key path to remove
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* store.unset('temp_data')
|
|
135
|
+
* store.unset(['user', 'cache'])
|
|
136
|
+
*/
|
|
137
|
+
unset(key) {
|
|
138
|
+
this.#modified = true;
|
|
139
|
+
lodash.unset(this.values, key);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Pulls value from the store. Same as calling store.get then store.unset.
|
|
143
|
+
*
|
|
144
|
+
* @param key - The key or key path to pull
|
|
145
|
+
* @param defaultValue - Default value if key doesn't exist
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* const message = store.pull('notification', 'No messages')
|
|
149
|
+
* const data = store.pull(['temp', 'data'])
|
|
150
|
+
*/
|
|
151
|
+
pull(key, defaultValue) {
|
|
152
|
+
return ((value) => {
|
|
153
|
+
this.unset(key);
|
|
154
|
+
return value;
|
|
155
|
+
})(this.get(key, defaultValue));
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Increments a numeric value. Raises an error when underlying value is not a number.
|
|
159
|
+
*
|
|
160
|
+
* @param key - The key or key path to increment
|
|
161
|
+
* @param steps - Number of steps to increment (default: 1)
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* store.increment('page_views') // Increments by 1
|
|
165
|
+
* store.increment('score', 10) // Increments by 10
|
|
166
|
+
*/
|
|
167
|
+
increment(key, steps = 1) {
|
|
168
|
+
const value = this.get(key, 0);
|
|
169
|
+
if (typeof value !== "number") {
|
|
170
|
+
throw new RuntimeException(`Cannot increment "${key}". Existing value is not a number`);
|
|
171
|
+
}
|
|
172
|
+
this.set(key, value + steps);
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Decrements a numeric value. Raises an error when underlying value is not a number.
|
|
176
|
+
*
|
|
177
|
+
* @param key - The key or key path to decrement
|
|
178
|
+
* @param steps - Number of steps to decrement (default: 1)
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* store.decrement('attempts') // Decrements by 1
|
|
182
|
+
* store.decrement('credits', 5) // Decrements by 5
|
|
183
|
+
*/
|
|
184
|
+
decrement(key, steps = 1) {
|
|
185
|
+
const value = this.get(key, 0);
|
|
186
|
+
if (typeof value !== "number") {
|
|
187
|
+
throw new RuntimeException(`Cannot decrement "${key}". Existing value is not a number`);
|
|
188
|
+
}
|
|
189
|
+
this.set(key, value - steps);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Overwrites existing store data with new values
|
|
193
|
+
*
|
|
194
|
+
* @param values - New values to replace existing data
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* store.update({ username: 'jane', theme: 'light' })
|
|
198
|
+
*/
|
|
199
|
+
update(values) {
|
|
200
|
+
this.#modified = true;
|
|
201
|
+
this.values = values;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Merges values with existing store data
|
|
205
|
+
*
|
|
206
|
+
* @param values - Values to merge with existing data
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* store.merge({ newField: 'value', existingField: 'updated' })
|
|
210
|
+
*/
|
|
211
|
+
merge(values) {
|
|
212
|
+
this.#modified = true;
|
|
213
|
+
lodash.merge(this.values, values);
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Resets store by clearing all values
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* store.clear() // Removes all data from store
|
|
220
|
+
*/
|
|
221
|
+
clear() {
|
|
222
|
+
this.update({});
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
export {
|
|
227
|
+
ReadOnlyValuesStore,
|
|
228
|
+
ValuesStore
|
|
229
|
+
};
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
debug_default
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-SBOMJK4T.js";
|
|
4
4
|
|
|
5
5
|
// stubs/main.ts
|
|
6
|
-
|
|
7
|
-
var stubsRoot = getDirname(import.meta.url);
|
|
6
|
+
var stubsRoot = import.meta.dirname;
|
|
8
7
|
|
|
9
8
|
// configure.ts
|
|
10
9
|
async function configure(command) {
|
|
@@ -28,32 +27,56 @@ async function configure(command) {
|
|
|
28
27
|
}
|
|
29
28
|
|
|
30
29
|
// src/define_config.ts
|
|
31
|
-
import string from "@poppinss/utils/string";
|
|
32
30
|
import { configProvider } from "@adonisjs/core";
|
|
33
|
-
import
|
|
31
|
+
import string from "@adonisjs/core/helpers/string";
|
|
32
|
+
import { InvalidArgumentsException } from "@adonisjs/core/exceptions";
|
|
34
33
|
|
|
35
34
|
// src/stores/memory.ts
|
|
36
35
|
var MemoryStore = class _MemoryStore {
|
|
36
|
+
/**
|
|
37
|
+
* Static map to store all session data in memory
|
|
38
|
+
*/
|
|
37
39
|
static sessions = /* @__PURE__ */ new Map();
|
|
38
40
|
/**
|
|
39
|
-
*
|
|
41
|
+
* Reads session value from memory
|
|
42
|
+
*
|
|
43
|
+
* @param sessionId - Session identifier
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* const data = store.read('sess_abc123')
|
|
40
47
|
*/
|
|
41
48
|
read(sessionId) {
|
|
42
49
|
return _MemoryStore.sessions.get(sessionId) || null;
|
|
43
50
|
}
|
|
44
51
|
/**
|
|
45
|
-
*
|
|
52
|
+
* Saves session value in memory for a given session id
|
|
53
|
+
*
|
|
54
|
+
* @param sessionId - Session identifier
|
|
55
|
+
* @param values - Session data to store
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* store.write('sess_abc123', { userId: 123, theme: 'dark' })
|
|
46
59
|
*/
|
|
47
60
|
write(sessionId, values) {
|
|
48
61
|
_MemoryStore.sessions.set(sessionId, values);
|
|
49
62
|
}
|
|
50
63
|
/**
|
|
51
|
-
*
|
|
64
|
+
* Removes a single session from memory
|
|
65
|
+
*
|
|
66
|
+
* @param sessionId - Session identifier to remove
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* store.destroy('sess_abc123')
|
|
52
70
|
*/
|
|
53
71
|
destroy(sessionId) {
|
|
54
72
|
_MemoryStore.sessions.delete(sessionId);
|
|
55
73
|
}
|
|
56
|
-
|
|
74
|
+
/**
|
|
75
|
+
* No-op for memory store as there's no expiry mechanism
|
|
76
|
+
*
|
|
77
|
+
* @param sessionId - Session identifier (unused)
|
|
78
|
+
*/
|
|
79
|
+
touch(_) {
|
|
57
80
|
}
|
|
58
81
|
};
|
|
59
82
|
|
|
@@ -98,34 +121,52 @@ function defineConfig(config) {
|
|
|
98
121
|
});
|
|
99
122
|
}
|
|
100
123
|
var stores = {
|
|
124
|
+
/**
|
|
125
|
+
* Creates a file-based session store
|
|
126
|
+
*
|
|
127
|
+
* @param config - File store configuration
|
|
128
|
+
*/
|
|
101
129
|
file: (config) => {
|
|
102
130
|
return configProvider.create(async () => {
|
|
103
|
-
const { FileStore } = await import("./file-
|
|
131
|
+
const { FileStore } = await import("./file-CCJ5ESE2.js");
|
|
104
132
|
return (_, sessionConfig) => {
|
|
105
133
|
return new FileStore(config, sessionConfig.age);
|
|
106
134
|
};
|
|
107
135
|
});
|
|
108
136
|
},
|
|
137
|
+
/**
|
|
138
|
+
* Creates a Redis-based session store
|
|
139
|
+
*
|
|
140
|
+
* @param config - Redis store configuration
|
|
141
|
+
*/
|
|
109
142
|
redis: (config) => {
|
|
110
143
|
return configProvider.create(async (app) => {
|
|
111
|
-
const { RedisStore } = await import("./redis-
|
|
144
|
+
const { RedisStore } = await import("./redis-NXJWWWVB.js");
|
|
112
145
|
const redis = await app.container.make("redis");
|
|
113
146
|
return (_, sessionConfig) => {
|
|
114
147
|
return new RedisStore(redis.connection(config.connection), sessionConfig.age);
|
|
115
148
|
};
|
|
116
149
|
});
|
|
117
150
|
},
|
|
151
|
+
/**
|
|
152
|
+
* Creates a cookie-based session store
|
|
153
|
+
*/
|
|
118
154
|
cookie: () => {
|
|
119
155
|
return configProvider.create(async () => {
|
|
120
|
-
const { CookieStore } = await import("./cookie-
|
|
156
|
+
const { CookieStore } = await import("./cookie-YBBGLCO5.js");
|
|
121
157
|
return (ctx, sessionConfig) => {
|
|
122
158
|
return new CookieStore(sessionConfig.cookie, ctx);
|
|
123
159
|
};
|
|
124
160
|
});
|
|
125
161
|
},
|
|
162
|
+
/**
|
|
163
|
+
* Creates a DynamoDB-based session store
|
|
164
|
+
*
|
|
165
|
+
* @param config - DynamoDB store configuration
|
|
166
|
+
*/
|
|
126
167
|
dynamodb: (config) => {
|
|
127
168
|
return configProvider.create(async () => {
|
|
128
|
-
const { DynamoDBStore } = await import("./dynamodb-
|
|
169
|
+
const { DynamoDBStore } = await import("./dynamodb-PLZABBFD.js");
|
|
129
170
|
const { DynamoDBClient } = await import("@aws-sdk/client-dynamodb");
|
|
130
171
|
const client = "clientConfig" in config ? new DynamoDBClient(config.clientConfig) : config.client;
|
|
131
172
|
return (_, sessionConfig) => {
|
|
@@ -144,4 +185,3 @@ export {
|
|
|
144
185
|
defineConfig,
|
|
145
186
|
stores
|
|
146
187
|
};
|
|
147
|
-
//# sourceMappingURL=chunk-WUWXIKIB.js.map
|
|
@@ -5,11 +5,10 @@ var __export = (target, all) => {
|
|
|
5
5
|
};
|
|
6
6
|
|
|
7
7
|
// src/debug.ts
|
|
8
|
-
import { debuglog } from "
|
|
8
|
+
import { debuglog } from "util";
|
|
9
9
|
var debug_default = debuglog("adonisjs:session");
|
|
10
10
|
|
|
11
11
|
export {
|
|
12
12
|
__export,
|
|
13
13
|
debug_default
|
|
14
14
|
};
|
|
15
|
-
//# sourceMappingURL=chunk-ZVSEMDIC.js.map
|