@adonisjs/session 8.0.0-next.3 → 8.0.0-next.5
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/{database-vbrhCOPd.js → database-JbWAJqhn.js} +13 -9
- package/build/factories/main.js +4 -4
- package/build/index.js +3 -3
- package/build/providers/session_provider.js +3 -3
- package/build/{redis-D8D9UtiD.js → redis-rAHxNQ_8.js} +5 -1
- package/build/{session-Dd5u7w5Y.js → session-BfIGZlCr.js} +7 -0
- package/build/{session-DZqZLOtR.js → session-C9ZmQmpM.js} +6 -3
- package/build/{session_collection-D9JQJjpq.js → session_collection-WwQCTUbm.js} +1 -1
- package/build/{session_middleware-BoOMxNVH.js → session_middleware-DE_8mcot.js} +1 -1
- package/build/src/session.d.ts +5 -0
- package/build/src/session_collection.d.ts +1 -1
- package/build/src/session_middleware.js +2 -2
- package/build/src/stores/database.d.ts +2 -1
- package/build/src/stores/memory.d.ts +8 -1
- package/build/src/stores/redis.d.ts +8 -1
- package/build/src/types.d.ts +34 -30
- package/package.json +1 -1
|
@@ -28,6 +28,14 @@ var DatabaseStore = class {
|
|
|
28
28
|
return null;
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
+
#rowToTaggedSession(row) {
|
|
32
|
+
const data = this.#parseSessionData(row.data, row.id);
|
|
33
|
+
if (!data) return null;
|
|
34
|
+
return {
|
|
35
|
+
id: row.id,
|
|
36
|
+
data
|
|
37
|
+
};
|
|
38
|
+
}
|
|
31
39
|
async read(sessionId) {
|
|
32
40
|
debug_default("database store: reading session data %s", sessionId);
|
|
33
41
|
const row = await this.#client.from(this.#tableName).where("id", sessionId).first();
|
|
@@ -60,23 +68,19 @@ var DatabaseStore = class {
|
|
|
60
68
|
await this.#client.from(this.#tableName).where("id", sessionId).update({ expires_at: expiresAt });
|
|
61
69
|
}
|
|
62
70
|
async tag(sessionId, userId) {
|
|
63
|
-
debug_default("database store:
|
|
71
|
+
debug_default("database store: associating user %s with session %s", userId, sessionId);
|
|
64
72
|
const data = new MessageBuilder().build({}, void 0, sessionId);
|
|
65
73
|
const expiresAt = new Date(Date.now() + this.#ttlSeconds * 1e3);
|
|
66
74
|
await this.#client.insertQuery().table(this.#tableName).insert({
|
|
67
75
|
id: sessionId,
|
|
68
|
-
user_id: userId,
|
|
76
|
+
user_id: String(userId),
|
|
69
77
|
data,
|
|
70
78
|
expires_at: expiresAt
|
|
71
79
|
}).knexQuery.onConflict("id").merge(["user_id"]);
|
|
72
80
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return {
|
|
77
|
-
id: row.id,
|
|
78
|
-
data
|
|
79
|
-
};
|
|
81
|
+
async untag(sessionId, userId) {
|
|
82
|
+
debug_default("database store: dissociating user %s from session %s", userId, sessionId);
|
|
83
|
+
await this.#client.query().from(this.#tableName).update({ user_id: null }).where({ id: sessionId });
|
|
80
84
|
}
|
|
81
85
|
async tagged(userId) {
|
|
82
86
|
debug_default("database store: getting sessions tagged with user %s", userId);
|
package/build/factories/main.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import "../session-
|
|
1
|
+
import "../session-BfIGZlCr.js";
|
|
2
2
|
import "../main-kn40V-hF.js";
|
|
3
|
-
import { t as defineConfig } from "../session-
|
|
3
|
+
import { t as defineConfig } from "../session-C9ZmQmpM.js";
|
|
4
4
|
import "../debug-BZVg83L1.js";
|
|
5
5
|
import "../values_store-CvR1Sn37.js";
|
|
6
|
-
import "../session_collection-
|
|
7
|
-
import { t as SessionMiddleware } from "../session_middleware-
|
|
6
|
+
import "../session_collection-WwQCTUbm.js";
|
|
7
|
+
import { t as SessionMiddleware } from "../session_middleware-DE_8mcot.js";
|
|
8
8
|
import { Emitter } from "@adonisjs/core/events";
|
|
9
9
|
import { AppFactory } from "@adonisjs/core/factories/app";
|
|
10
10
|
var SessionMiddlewareFactory = class {
|
package/build/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { r as errors_exports, t as Session } from "./session-
|
|
1
|
+
import { r as errors_exports, t as Session } from "./session-BfIGZlCr.js";
|
|
2
2
|
import { t as stubsRoot } from "./main-kn40V-hF.js";
|
|
3
|
-
import { n as stores, r as configure, t as defineConfig } from "./session-
|
|
3
|
+
import { n as stores, r as configure, t as defineConfig } from "./session-C9ZmQmpM.js";
|
|
4
4
|
import "./debug-BZVg83L1.js";
|
|
5
5
|
import { n as ValuesStore, t as ReadOnlyValuesStore } from "./values_store-CvR1Sn37.js";
|
|
6
|
-
import { t as SessionCollection } from "./session_collection-
|
|
6
|
+
import { t as SessionCollection } from "./session_collection-WwQCTUbm.js";
|
|
7
7
|
export { ReadOnlyValuesStore, Session, SessionCollection, ValuesStore, configure, defineConfig, errors_exports as errors, stores, stubsRoot };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import "../session-
|
|
1
|
+
import "../session-BfIGZlCr.js";
|
|
2
2
|
import "../debug-BZVg83L1.js";
|
|
3
3
|
import "../values_store-CvR1Sn37.js";
|
|
4
|
-
import { t as SessionCollection } from "../session_collection-
|
|
5
|
-
import { t as SessionMiddleware } from "../session_middleware-
|
|
4
|
+
import { t as SessionCollection } from "../session_collection-WwQCTUbm.js";
|
|
5
|
+
import { t as SessionMiddleware } from "../session_middleware-DE_8mcot.js";
|
|
6
6
|
import { RuntimeException } from "@adonisjs/core/exceptions";
|
|
7
7
|
import { configProvider } from "@adonisjs/core";
|
|
8
8
|
var SessionProvider = class {
|
|
@@ -71,7 +71,11 @@ var RedisStore = class {
|
|
|
71
71
|
}
|
|
72
72
|
async tag(sessionId, userId) {
|
|
73
73
|
debug_default("redis store: tagging session %s with user %s", sessionId, userId);
|
|
74
|
-
await this.#connection.sadd(this.#getTagKey(userId), sessionId);
|
|
74
|
+
await this.#connection.sadd(this.#getTagKey(userId.toString()), sessionId);
|
|
75
|
+
}
|
|
76
|
+
async untag(sessionId, userId) {
|
|
77
|
+
debug_default("redis store: untagging session %s from user %s", sessionId, userId);
|
|
78
|
+
await this.#connection.srem(this.#getTagKey(userId.toString()), sessionId);
|
|
75
79
|
}
|
|
76
80
|
async tagged(userId) {
|
|
77
81
|
debug_default("redis store: getting sessions tagged with user %s", userId);
|
|
@@ -184,10 +184,17 @@ var Session = class extends Macroable {
|
|
|
184
184
|
reflashExcept(keys) {
|
|
185
185
|
this.#getFlashStore("write").set("reflashed", lodash.omit(this.flashMessages.all(), keys));
|
|
186
186
|
}
|
|
187
|
+
supportsTagging() {
|
|
188
|
+
return "tag" in this.#store && "tagged" in this.#store;
|
|
189
|
+
}
|
|
187
190
|
async tag(userId) {
|
|
188
191
|
if (!("tag" in this.#store)) throw new E_SESSION_TAGGING_NOT_SUPPORTED();
|
|
189
192
|
await this.#store.tag(this.#sessionId, userId);
|
|
190
193
|
}
|
|
194
|
+
async untag(userId) {
|
|
195
|
+
if (!("tag" in this.#store)) throw new E_SESSION_TAGGING_NOT_SUPPORTED();
|
|
196
|
+
await this.#store.untag(this.#sessionId, userId);
|
|
197
|
+
}
|
|
191
198
|
regenerate() {
|
|
192
199
|
this.#sessionId = randomUUID();
|
|
193
200
|
}
|
|
@@ -32,7 +32,10 @@ var MemoryStore = class MemoryStore {
|
|
|
32
32
|
}
|
|
33
33
|
touch(_) {}
|
|
34
34
|
tag(sessionId, userId) {
|
|
35
|
-
MemoryStore.tags.set(sessionId, userId);
|
|
35
|
+
MemoryStore.tags.set(sessionId, String(userId));
|
|
36
|
+
}
|
|
37
|
+
untag(sessionId, _userId) {
|
|
38
|
+
MemoryStore.tags.delete(sessionId);
|
|
36
39
|
}
|
|
37
40
|
tagged(userId) {
|
|
38
41
|
const sessions = [];
|
|
@@ -93,7 +96,7 @@ const stores = {
|
|
|
93
96
|
},
|
|
94
97
|
redis: (config) => {
|
|
95
98
|
return configProvider.create(async (app) => {
|
|
96
|
-
const { RedisStore } = await import("./redis-
|
|
99
|
+
const { RedisStore } = await import("./redis-rAHxNQ_8.js");
|
|
97
100
|
const redis = await app.container.make("redis");
|
|
98
101
|
return (_, sessionConfig) => {
|
|
99
102
|
return new RedisStore(redis.connection(config.connection), sessionConfig.age);
|
|
@@ -123,7 +126,7 @@ const stores = {
|
|
|
123
126
|
},
|
|
124
127
|
database: (config) => {
|
|
125
128
|
return configProvider.create(async (app) => {
|
|
126
|
-
const { DatabaseStore } = await import("./database-
|
|
129
|
+
const { DatabaseStore } = await import("./database-JbWAJqhn.js");
|
|
127
130
|
const db = await app.container.make("lucid.db");
|
|
128
131
|
const connectionName = config?.connectionName || db.primaryConnectionName;
|
|
129
132
|
if (!db.manager.has(connectionName)) throw new RuntimeException(`Invalid database connection "${connectionName}" referenced in session config`);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as Session } from "./session-
|
|
1
|
+
import { t as Session } from "./session-BfIGZlCr.js";
|
|
2
2
|
import { ExceptionHandler } from "@adonisjs/core/http";
|
|
3
3
|
const originalErrorHandler = ExceptionHandler.prototype.renderValidationErrorAsHTML;
|
|
4
4
|
ExceptionHandler.macro("renderValidationErrorAsHTML", async function(error, ctx) {
|
package/build/src/session.d.ts
CHANGED
|
@@ -268,6 +268,10 @@ export declare class Session extends Macroable {
|
|
|
268
268
|
* session.reflashExcept(['error', 'warning'])
|
|
269
269
|
*/
|
|
270
270
|
reflashExcept(keys: string[]): void;
|
|
271
|
+
/**
|
|
272
|
+
* Check if the current store supports tagging
|
|
273
|
+
*/
|
|
274
|
+
supportsTagging(): boolean;
|
|
271
275
|
/**
|
|
272
276
|
* Tag the current session with a user ID.
|
|
273
277
|
* Only supported by Memory, Redis, and Database stores.
|
|
@@ -280,6 +284,7 @@ export declare class Session extends Macroable {
|
|
|
280
284
|
* await session.tag(String(user.id))
|
|
281
285
|
*/
|
|
282
286
|
tag(userId: string): Promise<void>;
|
|
287
|
+
untag(userId: string): Promise<void>;
|
|
283
288
|
/**
|
|
284
289
|
* Re-generates the session id and migrates data to it
|
|
285
290
|
*
|
|
@@ -6,7 +6,7 @@
|
|
|
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 type {
|
|
9
|
+
import type { SessionData, TaggedSession, ResolvedSessionConfig } from './types.ts';
|
|
10
10
|
/**
|
|
11
11
|
* SessionCollection provides APIs for programmatic session
|
|
12
12
|
* management. It allows reading, destroying, and tagging
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "../session-
|
|
1
|
+
import "../session-BfIGZlCr.js";
|
|
2
2
|
import "../debug-BZVg83L1.js";
|
|
3
3
|
import "../values_store-CvR1Sn37.js";
|
|
4
|
-
import { t as SessionMiddleware } from "../session_middleware-
|
|
4
|
+
import { t as SessionMiddleware } from "../session_middleware-DE_8mcot.js";
|
|
5
5
|
export { SessionMiddleware as default };
|
|
@@ -60,7 +60,8 @@ export declare class DatabaseStore implements SessionStoreWithTaggingContract {
|
|
|
60
60
|
* @param sessionId - Session identifier
|
|
61
61
|
* @param userId - User identifier to tag the session with
|
|
62
62
|
*/
|
|
63
|
-
tag(sessionId: string, userId: string): Promise<void>;
|
|
63
|
+
tag(sessionId: string, userId: string | number): Promise<void>;
|
|
64
|
+
untag(sessionId: string, userId: string | number): Promise<void>;
|
|
64
65
|
/**
|
|
65
66
|
* Get all sessions for a given user ID (tag)
|
|
66
67
|
*
|
|
@@ -64,7 +64,14 @@ export declare class MemoryStore implements SessionStoreWithTaggingContract {
|
|
|
64
64
|
* @param sessionId - Session identifier
|
|
65
65
|
* @param userId - User identifier to tag the session with
|
|
66
66
|
*/
|
|
67
|
-
tag(sessionId: string, userId: string): void;
|
|
67
|
+
tag(sessionId: string, userId: string | number): void;
|
|
68
|
+
/**
|
|
69
|
+
* Untag a session from a user ID
|
|
70
|
+
*
|
|
71
|
+
* @param sessionId - Session identifier
|
|
72
|
+
* @param userId - User identifier (unused in memory store, as sessionId uniquely identifies the tag)
|
|
73
|
+
*/
|
|
74
|
+
untag(sessionId: string, _userId: string | number): void;
|
|
68
75
|
/**
|
|
69
76
|
* Get all sessions for a given user ID (tag)
|
|
70
77
|
*
|
|
@@ -67,7 +67,14 @@ export declare class RedisStore implements SessionStoreWithTaggingContract {
|
|
|
67
67
|
* @param sessionId - Session identifier
|
|
68
68
|
* @param userId - User identifier to tag the session with
|
|
69
69
|
*/
|
|
70
|
-
tag(sessionId: string, userId: string): Promise<void>;
|
|
70
|
+
tag(sessionId: string, userId: string | number): Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* Untag a session from a user ID
|
|
73
|
+
*
|
|
74
|
+
* @param sessionId - Session identifier
|
|
75
|
+
* @param userId - User identifier to untag the session from
|
|
76
|
+
*/
|
|
77
|
+
untag(sessionId: string, userId: string | number): Promise<void>;
|
|
71
78
|
/**
|
|
72
79
|
* Get all sessions for a given user ID (tag)
|
|
73
80
|
*
|
package/build/src/types.d.ts
CHANGED
|
@@ -84,6 +84,40 @@ export interface SessionStoreContract {
|
|
|
84
84
|
*/
|
|
85
85
|
touch(sessionId: string): Promise<void> | void;
|
|
86
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Extended session store contract that supports tagging sessions with user IDs.
|
|
89
|
+
* This enables querying all sessions for a specific user, useful for features
|
|
90
|
+
* like "logout from all devices" or "view active sessions".
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* class MyStore implements SessionStoreWithTaggingContract {
|
|
94
|
+
* // ... base SessionStoreContract methods ...
|
|
95
|
+
*
|
|
96
|
+
* async tag(sessionId: string, userId: string) {
|
|
97
|
+
* await this.storage.tag(sessionId, userId)
|
|
98
|
+
* }
|
|
99
|
+
*
|
|
100
|
+
* async tagged(userId: string) {
|
|
101
|
+
* return await this.storage.getSessionsByUser(userId)
|
|
102
|
+
* }
|
|
103
|
+
* }
|
|
104
|
+
*/
|
|
105
|
+
export interface SessionStoreWithTaggingContract extends SessionStoreContract {
|
|
106
|
+
/**
|
|
107
|
+
* Associates a session with a user ID (tag).
|
|
108
|
+
* This allows querying all sessions for a specific user.
|
|
109
|
+
*/
|
|
110
|
+
tag(sessionId: string, userId: string | number): Promise<void> | void;
|
|
111
|
+
/**
|
|
112
|
+
* Dissociate a session from the user ID (tag).
|
|
113
|
+
*/
|
|
114
|
+
untag(sessionId: string, userId: string | number): Promise<void> | void;
|
|
115
|
+
/**
|
|
116
|
+
* Returns all sessions associated with a given user ID (tag).
|
|
117
|
+
* Only returns non-expired sessions.
|
|
118
|
+
*/
|
|
119
|
+
tagged(userId: string | number): Promise<TaggedSession[]> | TaggedSession[];
|
|
120
|
+
}
|
|
87
121
|
/**
|
|
88
122
|
* Base configuration interface for session management.
|
|
89
123
|
* Used by the session manager and middleware to control session behavior.
|
|
@@ -210,36 +244,6 @@ export type DynamoDBStoreConfig = ({
|
|
|
210
244
|
* }
|
|
211
245
|
*/
|
|
212
246
|
export type SessionStoreFactory = (ctx: HttpContext, sessionConfig: SessionConfig) => SessionStoreContract;
|
|
213
|
-
/**
|
|
214
|
-
* Extended session store contract that supports tagging sessions with user IDs.
|
|
215
|
-
* This enables querying all sessions for a specific user, useful for features
|
|
216
|
-
* like "logout from all devices" or "view active sessions".
|
|
217
|
-
*
|
|
218
|
-
* @example
|
|
219
|
-
* class MyStore implements SessionStoreWithTaggingContract {
|
|
220
|
-
* // ... base SessionStoreContract methods ...
|
|
221
|
-
*
|
|
222
|
-
* async tag(sessionId: string, userId: string) {
|
|
223
|
-
* await this.storage.tag(sessionId, userId)
|
|
224
|
-
* }
|
|
225
|
-
*
|
|
226
|
-
* async tagged(userId: string) {
|
|
227
|
-
* return await this.storage.getSessionsByUser(userId)
|
|
228
|
-
* }
|
|
229
|
-
* }
|
|
230
|
-
*/
|
|
231
|
-
export interface SessionStoreWithTaggingContract extends SessionStoreContract {
|
|
232
|
-
/**
|
|
233
|
-
* Associates a session with a user ID (tag).
|
|
234
|
-
* This allows querying all sessions for a specific user.
|
|
235
|
-
*/
|
|
236
|
-
tag(sessionId: string, userId: string): Promise<void> | void;
|
|
237
|
-
/**
|
|
238
|
-
* Returns all sessions associated with a given user ID (tag).
|
|
239
|
-
* Only returns non-expired sessions.
|
|
240
|
-
*/
|
|
241
|
-
tagged(userId: string): Promise<TaggedSession[]> | TaggedSession[];
|
|
242
|
-
}
|
|
243
247
|
/**
|
|
244
248
|
* Represents a tagged session with its ID and data
|
|
245
249
|
*/
|