@adonisjs/session 7.7.0 → 8.0.0-next.1
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/cookie-aLBno-zS.js +31 -0
- package/build/debug-Ba-0Cgn9.js +3 -0
- package/build/dynamodb-CU8BrQfU.js +72 -0
- package/build/factories/main.d.ts +1 -1
- package/build/factories/main.js +25 -49
- package/build/factories/session_middleware_factory.d.ts +2 -2
- package/build/file-CNxCs957.js +71 -0
- package/build/index.d.ts +6 -7
- package/build/index.js +5 -33
- package/build/providers/session_provider.d.ts +2 -3
- package/build/providers/session_provider.js +27 -64
- package/build/redis-Bcjum7z7.js +36 -0
- package/build/session-CBqhcnvJ.js +209 -0
- package/build/session-Cc1LPXRc.js +107 -0
- package/build/session_middleware-CS0R7hmq.js +27 -0
- package/build/src/client.d.ts +46 -10
- package/build/src/client.js +38 -9
- package/build/src/debug.d.ts +1 -1
- package/build/src/define_config.d.ts +49 -10
- package/build/src/errors.d.ts +20 -9
- package/build/src/plugins/edge.d.ts +16 -2
- package/build/src/plugins/edge.js +74 -126
- package/build/src/plugins/japa/api_client.d.ts +22 -4
- package/build/src/plugins/japa/api_client.js +76 -97
- package/build/src/plugins/japa/browser_client.d.ts +18 -4
- package/build/src/plugins/japa/browser_client.js +58 -82
- package/build/src/session.d.ts +170 -65
- package/build/src/session_middleware.d.ts +28 -5
- package/build/src/session_middleware.js +5 -11
- 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 +32 -15
- package/build/src/stores/redis.d.ts +39 -16
- package/build/src/types.d.ts +151 -82
- package/build/src/types.js +1 -1
- package/build/src/values_store.d.ts +113 -21
- package/build/values_store-smX0sQBJ.js +78 -0
- package/package.json +57 -56
- package/build/chunk-5ECC6OWF.js +0 -8
- package/build/chunk-5ECC6OWF.js.map +0 -1
- package/build/chunk-6BSSM3HO.js +0 -44
- package/build/chunk-6BSSM3HO.js.map +0 -1
- package/build/chunk-G7KFHA57.js +0 -59
- package/build/chunk-G7KFHA57.js.map +0 -1
- package/build/chunk-GCO66PQD.js +0 -85
- package/build/chunk-GCO66PQD.js.map +0 -1
- package/build/chunk-PZ5AY32C.js +0 -10
- package/build/chunk-PZ5AY32C.js.map +0 -1
- package/build/chunk-Q24L5XPC.js +0 -186
- package/build/chunk-Q24L5XPC.js.map +0 -1
- package/build/chunk-TE5JP3SX.js +0 -151
- package/build/chunk-TE5JP3SX.js.map +0 -1
- package/build/chunk-V3OAEXMJ.js +0 -8
- package/build/chunk-V3OAEXMJ.js.map +0 -1
- package/build/chunk-XP3CBOXR.js +0 -414
- package/build/chunk-XP3CBOXR.js.map +0 -1
- package/build/commands/commands.json +0 -1
- package/build/commands/main.d.ts +0 -4
- package/build/commands/main.js +0 -36
- package/build/commands/make_session_table.d.ts +0 -9
- package/build/commands/make_session_table.js +0 -21
- package/build/commands/make_session_table.js.map +0 -1
- package/build/cookie-3C33DMWA.js +0 -57
- package/build/cookie-3C33DMWA.js.map +0 -1
- package/build/database-443FB7MM.js +0 -118
- package/build/database-443FB7MM.js.map +0 -1
- package/build/dynamodb-53YXEFIJ.js +0 -108
- package/build/dynamodb-53YXEFIJ.js.map +0 -1
- package/build/factories/main.js.map +0 -1
- package/build/file-K3GBSVSU.js +0 -117
- package/build/file-K3GBSVSU.js.map +0 -1
- package/build/index.js.map +0 -1
- package/build/make/migration/sessions.stub +0 -26
- package/build/providers/session_provider.js.map +0 -1
- package/build/redis-YGX2CNE2.js +0 -119
- package/build/redis-YGX2CNE2.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_collection.d.ts +0 -55
- package/build/src/session_middleware.js.map +0 -1
- package/build/src/stores/database.d.ts +0 -55
- package/build/src/types.js.map +0 -1
package/build/chunk-XP3CBOXR.js
DELETED
|
@@ -1,414 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ReadOnlyValuesStore,
|
|
3
|
-
ValuesStore
|
|
4
|
-
} from "./chunk-TE5JP3SX.js";
|
|
5
|
-
import {
|
|
6
|
-
debug_default
|
|
7
|
-
} from "./chunk-5ECC6OWF.js";
|
|
8
|
-
import {
|
|
9
|
-
__export
|
|
10
|
-
} from "./chunk-PZ5AY32C.js";
|
|
11
|
-
|
|
12
|
-
// src/errors.ts
|
|
13
|
-
var errors_exports = {};
|
|
14
|
-
__export(errors_exports, {
|
|
15
|
-
E_SESSION_NOT_MUTABLE: () => E_SESSION_NOT_MUTABLE,
|
|
16
|
-
E_SESSION_NOT_READY: () => E_SESSION_NOT_READY,
|
|
17
|
-
E_SESSION_TAGGING_NOT_SUPPORTED: () => E_SESSION_TAGGING_NOT_SUPPORTED
|
|
18
|
-
});
|
|
19
|
-
import { createError } from "@poppinss/utils";
|
|
20
|
-
var E_SESSION_NOT_MUTABLE = createError(
|
|
21
|
-
"Session store is in readonly mode and cannot be mutated",
|
|
22
|
-
"E_SESSION_NOT_MUTABLE",
|
|
23
|
-
500
|
|
24
|
-
);
|
|
25
|
-
var E_SESSION_NOT_READY = createError(
|
|
26
|
-
"Session store has not been initiated. Make sure you have registered the session middleware",
|
|
27
|
-
"E_SESSION_NOT_READY",
|
|
28
|
-
500
|
|
29
|
-
);
|
|
30
|
-
var E_SESSION_TAGGING_NOT_SUPPORTED = createError(
|
|
31
|
-
"Session store does not support tagging operations. Only Redis, Database and Memory stores support tagging.",
|
|
32
|
-
"E_SESSION_TAGGING_NOT_SUPPORTED",
|
|
33
|
-
500
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
// src/session.ts
|
|
37
|
-
import Macroable from "@poppinss/macroable";
|
|
38
|
-
import lodash from "@poppinss/utils/lodash";
|
|
39
|
-
import { cuid } from "@adonisjs/core/helpers";
|
|
40
|
-
var Session = class extends Macroable {
|
|
41
|
-
constructor(config, storeFactory, emitter, ctx) {
|
|
42
|
-
super();
|
|
43
|
-
this.config = config;
|
|
44
|
-
this.#ctx = ctx;
|
|
45
|
-
this.#emitter = emitter;
|
|
46
|
-
this.#store = storeFactory(ctx, config);
|
|
47
|
-
this.#sessionIdFromCookie = ctx.request.cookie(config.cookieName, void 0);
|
|
48
|
-
this.#sessionId = this.#sessionIdFromCookie || cuid();
|
|
49
|
-
}
|
|
50
|
-
#store;
|
|
51
|
-
#emitter;
|
|
52
|
-
#ctx;
|
|
53
|
-
#readonly = false;
|
|
54
|
-
/**
|
|
55
|
-
* Session values store
|
|
56
|
-
*/
|
|
57
|
-
#valuesStore;
|
|
58
|
-
/**
|
|
59
|
-
* Session id refers to the session id that will be committed
|
|
60
|
-
* as a cookie during the response.
|
|
61
|
-
*/
|
|
62
|
-
#sessionId;
|
|
63
|
-
/**
|
|
64
|
-
* Session id from cookie refers to the value we read from the
|
|
65
|
-
* cookie during the HTTP request.
|
|
66
|
-
*
|
|
67
|
-
* This only might not exist during the first request. Also during
|
|
68
|
-
* session id re-generation, this value will be different from
|
|
69
|
-
* the session id.
|
|
70
|
-
*/
|
|
71
|
-
#sessionIdFromCookie;
|
|
72
|
-
/**
|
|
73
|
-
* Store of flash messages that be written during the
|
|
74
|
-
* HTTP request
|
|
75
|
-
*/
|
|
76
|
-
responseFlashMessages = new ValuesStore({});
|
|
77
|
-
/**
|
|
78
|
-
* Store of flash messages for the current HTTP request.
|
|
79
|
-
*/
|
|
80
|
-
flashMessages = new ValuesStore({});
|
|
81
|
-
/**
|
|
82
|
-
* The key to use for storing flash messages inside
|
|
83
|
-
* the session store.
|
|
84
|
-
*/
|
|
85
|
-
flashKey = "__flash__";
|
|
86
|
-
/**
|
|
87
|
-
* Session id for the current HTTP request
|
|
88
|
-
*/
|
|
89
|
-
get sessionId() {
|
|
90
|
-
return this.#sessionId;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* A boolean to know if a fresh session is created during
|
|
94
|
-
* the request
|
|
95
|
-
*/
|
|
96
|
-
get fresh() {
|
|
97
|
-
return this.#sessionIdFromCookie === void 0;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* A boolean to know if session is in readonly
|
|
101
|
-
* state
|
|
102
|
-
*/
|
|
103
|
-
get readonly() {
|
|
104
|
-
return this.#readonly;
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* A boolean to know if session store has been initiated
|
|
108
|
-
*/
|
|
109
|
-
get initiated() {
|
|
110
|
-
return !!this.#valuesStore;
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* A boolean to know if the session id has been re-generated
|
|
114
|
-
* during the current request
|
|
115
|
-
*/
|
|
116
|
-
get hasRegeneratedSession() {
|
|
117
|
-
return !!(this.#sessionIdFromCookie && this.#sessionIdFromCookie !== this.#sessionId);
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* A boolean to know if the session store is empty
|
|
121
|
-
*/
|
|
122
|
-
get isEmpty() {
|
|
123
|
-
return this.#valuesStore?.isEmpty ?? true;
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* A boolean to know if the session store has been
|
|
127
|
-
* modified
|
|
128
|
-
*/
|
|
129
|
-
get hasBeenModified() {
|
|
130
|
-
return this.#valuesStore?.hasBeenModified ?? false;
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Returns the flash messages store for a given
|
|
134
|
-
* mode
|
|
135
|
-
*/
|
|
136
|
-
#getFlashStore(mode) {
|
|
137
|
-
if (!this.#valuesStore) {
|
|
138
|
-
throw new E_SESSION_NOT_READY();
|
|
139
|
-
}
|
|
140
|
-
if (mode === "write" && this.readonly) {
|
|
141
|
-
throw new E_SESSION_NOT_MUTABLE();
|
|
142
|
-
}
|
|
143
|
-
return this.responseFlashMessages;
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Returns the store instance for a given mode
|
|
147
|
-
*/
|
|
148
|
-
#getValuesStore(mode) {
|
|
149
|
-
if (!this.#valuesStore) {
|
|
150
|
-
throw new E_SESSION_NOT_READY();
|
|
151
|
-
}
|
|
152
|
-
if (mode === "write" && this.readonly) {
|
|
153
|
-
throw new E_SESSION_NOT_MUTABLE();
|
|
154
|
-
}
|
|
155
|
-
return this.#valuesStore;
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Initiates the session store. The method results in a noop
|
|
159
|
-
* when called multiple times
|
|
160
|
-
*/
|
|
161
|
-
async initiate(readonly) {
|
|
162
|
-
if (this.#valuesStore) {
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
debug_default("initiating session (readonly: %s)", readonly);
|
|
166
|
-
this.#readonly = readonly;
|
|
167
|
-
const contents = await this.#store.read(this.#sessionId);
|
|
168
|
-
this.#valuesStore = new ValuesStore(contents);
|
|
169
|
-
if (this.has(this.flashKey)) {
|
|
170
|
-
debug_default("reading flash data");
|
|
171
|
-
if (this.#readonly) {
|
|
172
|
-
this.flashMessages.update(this.get(this.flashKey, null));
|
|
173
|
-
} else {
|
|
174
|
-
this.flashMessages.update(this.pull(this.flashKey, null));
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
if ("view" in this.#ctx) {
|
|
178
|
-
this.#ctx.view.share({
|
|
179
|
-
session: new ReadOnlyValuesStore(this.#valuesStore.all()),
|
|
180
|
-
flashMessages: new ReadOnlyValuesStore(this.flashMessages.all()),
|
|
181
|
-
old: function(key, defaultValue) {
|
|
182
|
-
return this.flashMessages.get(key, defaultValue);
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
this.#emitter.emit("session:initiated", { session: this });
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* Put a key-value pair to the session data store
|
|
190
|
-
*/
|
|
191
|
-
put(key, value) {
|
|
192
|
-
this.#getValuesStore("write").set(key, value);
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Check if a key exists inside the datastore
|
|
196
|
-
*/
|
|
197
|
-
has(key) {
|
|
198
|
-
return this.#getValuesStore("read").has(key);
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* Get the value of a key from the session datastore.
|
|
202
|
-
* You can specify a default value to use, when key
|
|
203
|
-
* does not exists or has undefined value.
|
|
204
|
-
*/
|
|
205
|
-
get(key, defaultValue) {
|
|
206
|
-
return this.#getValuesStore("read").get(key, defaultValue);
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* Get everything from the session store
|
|
210
|
-
*/
|
|
211
|
-
all() {
|
|
212
|
-
return this.#getValuesStore("read").all();
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Remove a key from the session datastore
|
|
216
|
-
*/
|
|
217
|
-
forget(key) {
|
|
218
|
-
return this.#getValuesStore("write").unset(key);
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* Read value for a key from the session datastore
|
|
222
|
-
* and remove it simultaneously.
|
|
223
|
-
*/
|
|
224
|
-
pull(key, defaultValue) {
|
|
225
|
-
return this.#getValuesStore("write").pull(key, defaultValue);
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* Increment the value of a key inside the session
|
|
229
|
-
* store.
|
|
230
|
-
*
|
|
231
|
-
* A new key will be defined if does not exists already.
|
|
232
|
-
* The value of a new key will be 1
|
|
233
|
-
*/
|
|
234
|
-
increment(key, steps = 1) {
|
|
235
|
-
return this.#getValuesStore("write").increment(key, steps);
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Increment the value of a key inside the session
|
|
239
|
-
* store.
|
|
240
|
-
*
|
|
241
|
-
* A new key will be defined if does not exists already.
|
|
242
|
-
* The value of a new key will be -1
|
|
243
|
-
*/
|
|
244
|
-
decrement(key, steps = 1) {
|
|
245
|
-
return this.#getValuesStore("write").decrement(key, steps);
|
|
246
|
-
}
|
|
247
|
-
/**
|
|
248
|
-
* Empty the session store
|
|
249
|
-
*/
|
|
250
|
-
clear() {
|
|
251
|
-
return this.#getValuesStore("write").clear();
|
|
252
|
-
}
|
|
253
|
-
flash(key, value) {
|
|
254
|
-
if (typeof key === "string") {
|
|
255
|
-
if (value) {
|
|
256
|
-
this.#getFlashStore("write").set(key, value);
|
|
257
|
-
}
|
|
258
|
-
} else {
|
|
259
|
-
this.#getFlashStore("write").merge(key);
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
/**
|
|
263
|
-
* Flash errors to the errorsBag. You can read these
|
|
264
|
-
* errors via the "@error" tag.
|
|
265
|
-
*
|
|
266
|
-
* Appends new messages to the existing collection.
|
|
267
|
-
*/
|
|
268
|
-
flashErrors(errorsCollection) {
|
|
269
|
-
this.flash({ errorsBag: errorsCollection });
|
|
270
|
-
}
|
|
271
|
-
/**
|
|
272
|
-
* Flash validation error messages. Make sure the error
|
|
273
|
-
* is an instance of VineJS ValidationException.
|
|
274
|
-
*
|
|
275
|
-
* Overrides existing inputErrors
|
|
276
|
-
*/
|
|
277
|
-
flashValidationErrors(error) {
|
|
278
|
-
const errorsBag = error.messages.reduce((result, message) => {
|
|
279
|
-
if (result[message.field]) {
|
|
280
|
-
result[message.field].push(message.message);
|
|
281
|
-
} else {
|
|
282
|
-
result[message.field] = [message.message];
|
|
283
|
-
}
|
|
284
|
-
return result;
|
|
285
|
-
}, {});
|
|
286
|
-
this.flashExcept(["_csrf", "_method", "password", "password_confirmation"]);
|
|
287
|
-
let summary = "The form could not be saved. Please check the errors below.";
|
|
288
|
-
if ("i18n" in this.#ctx) {
|
|
289
|
-
summary = this.#ctx.i18n.t(
|
|
290
|
-
`errors.${error.code}`,
|
|
291
|
-
{
|
|
292
|
-
count: error.messages.length
|
|
293
|
-
},
|
|
294
|
-
summary
|
|
295
|
-
);
|
|
296
|
-
}
|
|
297
|
-
this.flashErrors({
|
|
298
|
-
[String(error.code)]: summary
|
|
299
|
-
});
|
|
300
|
-
this.flash("inputErrorsBag", errorsBag);
|
|
301
|
-
this.flash("errors", errorsBag);
|
|
302
|
-
}
|
|
303
|
-
/**
|
|
304
|
-
* Flash form input data to the flash messages store
|
|
305
|
-
*/
|
|
306
|
-
flashAll() {
|
|
307
|
-
return this.#getFlashStore("write").set("input", this.#ctx.request.original());
|
|
308
|
-
}
|
|
309
|
-
/**
|
|
310
|
-
* Flash form input data (except some keys) to the flash messages store
|
|
311
|
-
*/
|
|
312
|
-
flashExcept(keys) {
|
|
313
|
-
this.#getFlashStore("write").set("input", lodash.omit(this.#ctx.request.original(), keys));
|
|
314
|
-
}
|
|
315
|
-
/**
|
|
316
|
-
* Flash form input data (only some keys) to the flash messages store
|
|
317
|
-
*/
|
|
318
|
-
flashOnly(keys) {
|
|
319
|
-
this.#getFlashStore("write").set("input", lodash.pick(this.#ctx.request.original(), keys));
|
|
320
|
-
}
|
|
321
|
-
/**
|
|
322
|
-
* Reflash messages from the last request in the current response
|
|
323
|
-
*/
|
|
324
|
-
reflash() {
|
|
325
|
-
this.#getFlashStore("write").set("reflashed", this.flashMessages.all());
|
|
326
|
-
}
|
|
327
|
-
/**
|
|
328
|
-
* Reflash messages (only some keys) from the last
|
|
329
|
-
* request in the current response
|
|
330
|
-
*/
|
|
331
|
-
reflashOnly(keys) {
|
|
332
|
-
this.#getFlashStore("write").set("reflashed", lodash.pick(this.flashMessages.all(), keys));
|
|
333
|
-
}
|
|
334
|
-
/**
|
|
335
|
-
* Reflash messages (except some keys) from the last
|
|
336
|
-
* request in the current response
|
|
337
|
-
*/
|
|
338
|
-
reflashExcept(keys) {
|
|
339
|
-
this.#getFlashStore("write").set("reflashed", lodash.omit(this.flashMessages.all(), keys));
|
|
340
|
-
}
|
|
341
|
-
/**
|
|
342
|
-
* Re-generate the session id and migrate data to it.
|
|
343
|
-
*/
|
|
344
|
-
regenerate() {
|
|
345
|
-
this.#sessionId = cuid();
|
|
346
|
-
}
|
|
347
|
-
/**
|
|
348
|
-
* Tag the current session with a user ID. This allows you to
|
|
349
|
-
* later retrieve all sessions for a given user via SessionCollection.
|
|
350
|
-
*
|
|
351
|
-
* Only Memory, Redis and Database stores support tagging. Other stores
|
|
352
|
-
* will throw an error.
|
|
353
|
-
*/
|
|
354
|
-
async tag(userId) {
|
|
355
|
-
if (!("tag" in this.#store)) throw new E_SESSION_TAGGING_NOT_SUPPORTED();
|
|
356
|
-
await this.#store.tag(this.#sessionId, userId);
|
|
357
|
-
}
|
|
358
|
-
/**
|
|
359
|
-
* Commit session changes. No more mutations will be
|
|
360
|
-
* allowed after commit.
|
|
361
|
-
*/
|
|
362
|
-
async commit() {
|
|
363
|
-
if (!this.#valuesStore || this.readonly) {
|
|
364
|
-
return;
|
|
365
|
-
}
|
|
366
|
-
if (!this.responseFlashMessages.isEmpty) {
|
|
367
|
-
const { input, reflashed, ...others } = this.responseFlashMessages.all();
|
|
368
|
-
this.put(this.flashKey, { ...reflashed, ...input, ...others });
|
|
369
|
-
}
|
|
370
|
-
debug_default("committing session data");
|
|
371
|
-
this.#ctx.response.cookie(this.config.cookieName, this.#sessionId, this.config.cookie);
|
|
372
|
-
if (this.isEmpty) {
|
|
373
|
-
if (this.#sessionIdFromCookie) {
|
|
374
|
-
await this.#store.destroy(this.#sessionIdFromCookie);
|
|
375
|
-
}
|
|
376
|
-
this.#emitter.emit("session:committed", { session: this });
|
|
377
|
-
return;
|
|
378
|
-
}
|
|
379
|
-
if (!this.hasBeenModified) {
|
|
380
|
-
if (this.#sessionIdFromCookie && this.#sessionIdFromCookie !== this.#sessionId) {
|
|
381
|
-
await this.#store.destroy(this.#sessionIdFromCookie);
|
|
382
|
-
await this.#store.write(this.#sessionId, this.#valuesStore.toJSON());
|
|
383
|
-
this.#emitter.emit("session:migrated", {
|
|
384
|
-
fromSessionId: this.#sessionIdFromCookie,
|
|
385
|
-
toSessionId: this.sessionId,
|
|
386
|
-
session: this
|
|
387
|
-
});
|
|
388
|
-
} else {
|
|
389
|
-
await this.#store.touch(this.#sessionId);
|
|
390
|
-
}
|
|
391
|
-
this.#emitter.emit("session:committed", { session: this });
|
|
392
|
-
return;
|
|
393
|
-
}
|
|
394
|
-
if (this.#sessionIdFromCookie && this.#sessionIdFromCookie !== this.#sessionId) {
|
|
395
|
-
await this.#store.destroy(this.#sessionIdFromCookie);
|
|
396
|
-
await this.#store.write(this.#sessionId, this.#valuesStore.toJSON());
|
|
397
|
-
this.#emitter.emit("session:migrated", {
|
|
398
|
-
fromSessionId: this.#sessionIdFromCookie,
|
|
399
|
-
toSessionId: this.sessionId,
|
|
400
|
-
session: this
|
|
401
|
-
});
|
|
402
|
-
} else {
|
|
403
|
-
await this.#store.write(this.#sessionId, this.#valuesStore.toJSON());
|
|
404
|
-
}
|
|
405
|
-
this.#emitter.emit("session:committed", { session: this });
|
|
406
|
-
}
|
|
407
|
-
};
|
|
408
|
-
|
|
409
|
-
export {
|
|
410
|
-
E_SESSION_TAGGING_NOT_SUPPORTED,
|
|
411
|
-
errors_exports,
|
|
412
|
-
Session
|
|
413
|
-
};
|
|
414
|
-
//# sourceMappingURL=chunk-XP3CBOXR.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/errors.ts","../src/session.ts"],"sourcesContent":["/*\n * @adonisjs/session\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { createError } from '@poppinss/utils'\n\n/**\n * Raised when session store is not mutable\n */\nexport const E_SESSION_NOT_MUTABLE = createError(\n 'Session store is in readonly mode and cannot be mutated',\n 'E_SESSION_NOT_MUTABLE',\n 500\n)\n\n/**\n * Raised when session store has been initiated\n */\nexport const E_SESSION_NOT_READY = createError(\n 'Session store has not been initiated. Make sure you have registered the session middleware',\n 'E_SESSION_NOT_READY',\n 500\n)\n\n/**\n * Raised when trying to use tagging with a store that\n * doesn't support tagging operations\n */\nexport const E_SESSION_TAGGING_NOT_SUPPORTED = createError(\n 'Session store does not support tagging operations. Only Redis, Database and Memory stores support tagging.',\n 'E_SESSION_TAGGING_NOT_SUPPORTED',\n 500\n)\n","/*\n * @adonisjs/session\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport type { I18n } from '@adonisjs/i18n'\nimport Macroable from '@poppinss/macroable'\nimport lodash from '@poppinss/utils/lodash'\nimport { cuid } from '@adonisjs/core/helpers'\nimport type { HttpContext } from '@adonisjs/core/http'\nimport type { EmitterService } from '@adonisjs/core/types'\nimport type { HttpError } from '@adonisjs/core/types/http'\n\nimport debug from './debug.js'\nimport * as errors from './errors.js'\nimport { ReadOnlyValuesStore, ValuesStore } from './values_store.js'\nimport type {\n SessionData,\n SessionConfig,\n SessionStoreFactory,\n AllowedSessionValues,\n SessionStoreContract,\n SessionStoreWithTaggingContract,\n} from './types.js'\n\n/**\n * The session class exposes the API to read and write values to\n * the session store.\n *\n * A session instance is isolated between requests but\n * uses a centralized persistence store and\n */\nexport class Session extends Macroable {\n #store: SessionStoreContract | SessionStoreWithTaggingContract\n #emitter: EmitterService\n #ctx: HttpContext\n #readonly: boolean = false\n\n /**\n * Session values store\n */\n #valuesStore?: ValuesStore\n\n /**\n * Session id refers to the session id that will be committed\n * as a cookie during the response.\n */\n #sessionId: string\n\n /**\n * Session id from cookie refers to the value we read from the\n * cookie during the HTTP request.\n *\n * This only might not exist during the first request. Also during\n * session id re-generation, this value will be different from\n * the session id.\n */\n #sessionIdFromCookie?: string\n\n /**\n * Store of flash messages that be written during the\n * HTTP request\n */\n responseFlashMessages = new ValuesStore({})\n\n /**\n * Store of flash messages for the current HTTP request.\n */\n flashMessages = new ValuesStore({})\n\n /**\n * The key to use for storing flash messages inside\n * the session store.\n */\n flashKey: string = '__flash__'\n\n /**\n * Session id for the current HTTP request\n */\n get sessionId() {\n return this.#sessionId\n }\n\n /**\n * A boolean to know if a fresh session is created during\n * the request\n */\n get fresh(): boolean {\n return this.#sessionIdFromCookie === undefined\n }\n\n /**\n * A boolean to know if session is in readonly\n * state\n */\n get readonly() {\n return this.#readonly\n }\n\n /**\n * A boolean to know if session store has been initiated\n */\n get initiated() {\n return !!this.#valuesStore\n }\n\n /**\n * A boolean to know if the session id has been re-generated\n * during the current request\n */\n get hasRegeneratedSession() {\n return !!(this.#sessionIdFromCookie && this.#sessionIdFromCookie !== this.#sessionId)\n }\n\n /**\n * A boolean to know if the session store is empty\n */\n get isEmpty() {\n return this.#valuesStore?.isEmpty ?? true\n }\n\n /**\n * A boolean to know if the session store has been\n * modified\n */\n get hasBeenModified() {\n return this.#valuesStore?.hasBeenModified ?? false\n }\n\n constructor(\n public config: SessionConfig,\n storeFactory: SessionStoreFactory,\n emitter: EmitterService,\n ctx: HttpContext\n ) {\n super()\n this.#ctx = ctx\n this.#emitter = emitter\n this.#store = storeFactory(ctx, config)\n this.#sessionIdFromCookie = ctx.request.cookie(config.cookieName, undefined)\n this.#sessionId = this.#sessionIdFromCookie || cuid()\n }\n\n /**\n * Returns the flash messages store for a given\n * mode\n */\n #getFlashStore(mode: 'write' | 'read'): ValuesStore {\n if (!this.#valuesStore) {\n throw new errors.E_SESSION_NOT_READY()\n }\n\n if (mode === 'write' && this.readonly) {\n throw new errors.E_SESSION_NOT_MUTABLE()\n }\n\n return this.responseFlashMessages\n }\n\n /**\n * Returns the store instance for a given mode\n */\n #getValuesStore(mode: 'write' | 'read'): ValuesStore {\n if (!this.#valuesStore) {\n throw new errors.E_SESSION_NOT_READY()\n }\n\n if (mode === 'write' && this.readonly) {\n throw new errors.E_SESSION_NOT_MUTABLE()\n }\n\n return this.#valuesStore\n }\n\n /**\n * Initiates the session store. The method results in a noop\n * when called multiple times\n */\n async initiate(readonly: boolean): Promise<void> {\n if (this.#valuesStore) {\n return\n }\n\n debug('initiating session (readonly: %s)', readonly)\n\n this.#readonly = readonly\n const contents = await this.#store.read(this.#sessionId)\n this.#valuesStore = new ValuesStore(contents)\n\n /**\n * Extract flash messages from the store and keep a local\n * copy of it.\n */\n if (this.has(this.flashKey)) {\n debug('reading flash data')\n if (this.#readonly) {\n this.flashMessages.update(this.get(this.flashKey, null))\n } else {\n this.flashMessages.update(this.pull(this.flashKey, null))\n }\n }\n\n /**\n * Share session with the templates. We assume the view property\n * is a reference to edge templates\n */\n if ('view' in this.#ctx) {\n this.#ctx.view.share({\n session: new ReadOnlyValuesStore(this.#valuesStore.all()),\n flashMessages: new ReadOnlyValuesStore(this.flashMessages.all()),\n old: function (key: string, defaultValue?: any) {\n return this.flashMessages.get(key, defaultValue)\n },\n })\n }\n\n this.#emitter.emit('session:initiated', { session: this })\n }\n\n /**\n * Put a key-value pair to the session data store\n */\n put(key: string, value: AllowedSessionValues) {\n this.#getValuesStore('write').set(key, value)\n }\n\n /**\n * Check if a key exists inside the datastore\n */\n has(key: string): boolean {\n return this.#getValuesStore('read').has(key)\n }\n\n /**\n * Get the value of a key from the session datastore.\n * You can specify a default value to use, when key\n * does not exists or has undefined value.\n */\n get(key: string, defaultValue?: any) {\n return this.#getValuesStore('read').get(key, defaultValue)\n }\n\n /**\n * Get everything from the session store\n */\n all() {\n return this.#getValuesStore('read').all()\n }\n\n /**\n * Remove a key from the session datastore\n */\n forget(key: string) {\n return this.#getValuesStore('write').unset(key)\n }\n\n /**\n * Read value for a key from the session datastore\n * and remove it simultaneously.\n */\n pull(key: string, defaultValue?: any) {\n return this.#getValuesStore('write').pull(key, defaultValue)\n }\n\n /**\n * Increment the value of a key inside the session\n * store.\n *\n * A new key will be defined if does not exists already.\n * The value of a new key will be 1\n */\n increment(key: string, steps: number = 1) {\n return this.#getValuesStore('write').increment(key, steps)\n }\n\n /**\n * Increment the value of a key inside the session\n * store.\n *\n * A new key will be defined if does not exists already.\n * The value of a new key will be -1\n */\n decrement(key: string, steps: number = 1) {\n return this.#getValuesStore('write').decrement(key, steps)\n }\n\n /**\n * Empty the session store\n */\n clear() {\n return this.#getValuesStore('write').clear()\n }\n\n /**\n * Add a key-value pair to flash messages\n */\n flash(key: string, value: AllowedSessionValues): void\n flash(keyValue: SessionData): void\n flash(key: string | SessionData, value?: AllowedSessionValues): void {\n if (typeof key === 'string') {\n if (value) {\n this.#getFlashStore('write').set(key, value)\n }\n } else {\n this.#getFlashStore('write').merge(key)\n }\n }\n\n /**\n * Flash errors to the errorsBag. You can read these\n * errors via the \"@error\" tag.\n *\n * Appends new messages to the existing collection.\n */\n flashErrors(errorsCollection: Record<string, string | string[]>) {\n this.flash({ errorsBag: errorsCollection })\n }\n\n /**\n * Flash validation error messages. Make sure the error\n * is an instance of VineJS ValidationException.\n *\n * Overrides existing inputErrors\n */\n flashValidationErrors(error: HttpError) {\n const errorsBag = error.messages.reduce((result: Record<string, string[]>, message: any) => {\n if (result[message.field]) {\n result[message.field].push(message.message)\n } else {\n result[message.field] = [message.message]\n }\n return result\n }, {})\n\n this.flashExcept(['_csrf', '_method', 'password', 'password_confirmation'])\n\n /**\n * Adding the error summary to the \"errorsBag\" so that\n * we display the validation error globally using\n * the \"@error\" tag.\n */\n let summary = 'The form could not be saved. Please check the errors below.'\n if ('i18n' in this.#ctx) {\n summary = (this.#ctx.i18n as I18n).t(\n `errors.${error.code}`,\n {\n count: error.messages.length,\n },\n summary\n )\n }\n\n this.flashErrors({\n [String(error.code)]: summary,\n })\n\n /**\n * Adding to inputErrorsBag for \"@inputError\" tag\n * to read validation errors\n */\n this.flash('inputErrorsBag', errorsBag)\n\n /**\n * For legacy support and not to break apps using\n * the older version of @adonisjs/session package\n */\n this.flash('errors', errorsBag)\n }\n\n /**\n * Flash form input data to the flash messages store\n */\n flashAll() {\n return this.#getFlashStore('write').set('input', this.#ctx.request.original())\n }\n\n /**\n * Flash form input data (except some keys) to the flash messages store\n */\n flashExcept(keys: string[]): void {\n this.#getFlashStore('write').set('input', lodash.omit(this.#ctx.request.original(), keys))\n }\n\n /**\n * Flash form input data (only some keys) to the flash messages store\n */\n flashOnly(keys: string[]): void {\n this.#getFlashStore('write').set('input', lodash.pick(this.#ctx.request.original(), keys))\n }\n\n /**\n * Reflash messages from the last request in the current response\n */\n reflash(): void {\n this.#getFlashStore('write').set('reflashed', this.flashMessages.all())\n }\n\n /**\n * Reflash messages (only some keys) from the last\n * request in the current response\n */\n reflashOnly(keys: string[]) {\n this.#getFlashStore('write').set('reflashed', lodash.pick(this.flashMessages.all(), keys))\n }\n\n /**\n * Reflash messages (except some keys) from the last\n * request in the current response\n */\n reflashExcept(keys: string[]) {\n this.#getFlashStore('write').set('reflashed', lodash.omit(this.flashMessages.all(), keys))\n }\n\n /**\n * Re-generate the session id and migrate data to it.\n */\n regenerate() {\n this.#sessionId = cuid()\n }\n\n /**\n * Tag the current session with a user ID. This allows you to\n * later retrieve all sessions for a given user via SessionCollection.\n *\n * Only Memory, Redis and Database stores support tagging. Other stores\n * will throw an error.\n */\n async tag(userId: string): Promise<void> {\n if (!('tag' in this.#store)) throw new errors.E_SESSION_TAGGING_NOT_SUPPORTED()\n await this.#store.tag(this.#sessionId, userId)\n }\n\n /**\n * Commit session changes. No more mutations will be\n * allowed after commit.\n */\n async commit() {\n if (!this.#valuesStore || this.readonly) {\n return\n }\n\n /**\n * If the flash messages store is not empty, we should put\n * its messages inside main session store.\n */\n if (!this.responseFlashMessages.isEmpty) {\n const { input, reflashed, ...others } = this.responseFlashMessages.all()\n this.put(this.flashKey, { ...reflashed, ...input, ...others })\n }\n\n debug('committing session data')\n\n /**\n * Touch the session id cookie to stay alive\n */\n this.#ctx.response.cookie(this.config.cookieName, this.#sessionId, this.config.cookie!)\n\n /**\n * Delete the session data when the session store\n * is empty.\n *\n * Also we only destroy the session id we read from the cookie.\n * If there was no session id in the cookie, there won't be\n * any data inside the store either.\n */\n if (this.isEmpty) {\n if (this.#sessionIdFromCookie) {\n await this.#store.destroy(this.#sessionIdFromCookie)\n }\n this.#emitter.emit('session:committed', { session: this })\n return\n }\n\n /**\n * Touch the store expiry when the session store was\n * not modified.\n */\n if (!this.hasBeenModified) {\n if (this.#sessionIdFromCookie && this.#sessionIdFromCookie !== this.#sessionId) {\n await this.#store.destroy(this.#sessionIdFromCookie)\n await this.#store.write(this.#sessionId, this.#valuesStore.toJSON())\n this.#emitter.emit('session:migrated', {\n fromSessionId: this.#sessionIdFromCookie,\n toSessionId: this.sessionId,\n session: this,\n })\n } else {\n await this.#store.touch(this.#sessionId)\n }\n this.#emitter.emit('session:committed', { session: this })\n return\n }\n\n /**\n * Otherwise commit to the session store\n */\n if (this.#sessionIdFromCookie && this.#sessionIdFromCookie !== this.#sessionId) {\n await this.#store.destroy(this.#sessionIdFromCookie)\n await this.#store.write(this.#sessionId, this.#valuesStore.toJSON())\n this.#emitter.emit('session:migrated', {\n fromSessionId: this.#sessionIdFromCookie,\n toSessionId: this.sessionId,\n session: this,\n })\n } else {\n await this.#store.write(this.#sessionId, this.#valuesStore.toJSON())\n }\n\n this.#emitter.emit('session:committed', { session: this })\n }\n}\n"],"mappings":";;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,SAAS,mBAAmB;AAKrB,IAAM,wBAAwB;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AACF;AAKO,IAAM,sBAAsB;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AACF;AAMO,IAAM,kCAAkC;AAAA,EAC7C;AAAA,EACA;AAAA,EACA;AACF;;;AC3BA,OAAO,eAAe;AACtB,OAAO,YAAY;AACnB,SAAS,YAAY;AAwBd,IAAM,UAAN,cAAsB,UAAU;AAAA,EAiGrC,YACS,QACP,cACA,SACA,KACA;AACA,UAAM;AALC;AAMP,SAAK,OAAO;AACZ,SAAK,WAAW;AAChB,SAAK,SAAS,aAAa,KAAK,MAAM;AACtC,SAAK,uBAAuB,IAAI,QAAQ,OAAO,OAAO,YAAY,MAAS;AAC3E,SAAK,aAAa,KAAK,wBAAwB,KAAK;AAAA,EACtD;AAAA,EA5GA;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAAqB;AAAA;AAAA;AAAA;AAAA,EAKrB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA;AAAA;AAAA;AAA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,KAAK,oBAAoB;AAAA,UACrC,eAAe,KAAK;AAAA,UACpB,aAAa,KAAK;AAAA,UAClB,SAAS;AAAA,QACX,CAAC;AAAA,MACH,OAAO;AACL,cAAM,KAAK,OAAO,MAAM,KAAK,UAAU;AAAA,MACzC;AACA,WAAK,SAAS,KAAK,qBAAqB,EAAE,SAAS,KAAK,CAAC;AACzD;AAAA,IACF;AAKA,QAAI,KAAK,wBAAwB,KAAK,yBAAyB,KAAK,YAAY;AAC9E,YAAM,KAAK,OAAO,QAAQ,KAAK,oBAAoB;AACnD,YAAM,KAAK,OAAO,MAAM,KAAK,YAAY,KAAK,aAAa,OAAO,CAAC;AACnE,WAAK,SAAS,KAAK,oBAAoB;AAAA,QACrC,eAAe,KAAK;AAAA,QACpB,aAAa,KAAK;AAAA,QAClB,SAAS;AAAA,MACX,CAAC;AAAA,IACH,OAAO;AACL,YAAM,KAAK,OAAO,MAAM,KAAK,YAAY,KAAK,aAAa,OAAO,CAAC;AAAA,IACrE;AAEA,SAAK,SAAS,KAAK,qBAAqB,EAAE,SAAS,KAAK,CAAC;AAAA,EAC3D;AACF;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"commands":[{"commandName":"make:session-table","description":"Create a migration for the sessions database table","help":"","namespace":"make","aliases":[],"flags":[],"args":[],"options":{},"filePath":"make_session_table.js"}],"version":1}
|
package/build/commands/main.d.ts
DELETED
package/build/commands/main.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { readFile } from 'node:fs/promises'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* In-memory cache of commands after they have been loaded
|
|
5
|
-
*/
|
|
6
|
-
let commandsMetaData
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Reads the commands from the "./commands.json" file. Since, the commands.json
|
|
10
|
-
* file is generated automatically, we do not have to validate its contents
|
|
11
|
-
*/
|
|
12
|
-
export async function getMetaData() {
|
|
13
|
-
if (commandsMetaData) {
|
|
14
|
-
return commandsMetaData
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const commandsIndex = await readFile(new URL('./commands.json', import.meta.url), 'utf-8')
|
|
18
|
-
commandsMetaData = JSON.parse(commandsIndex).commands
|
|
19
|
-
|
|
20
|
-
return commandsMetaData
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Imports the command by lookingup its path from the commands
|
|
25
|
-
* metadata
|
|
26
|
-
*/
|
|
27
|
-
export async function getCommand(metaData) {
|
|
28
|
-
const commands = await getMetaData()
|
|
29
|
-
const command = commands.find(({ commandName }) => metaData.commandName === commandName)
|
|
30
|
-
if (!command) {
|
|
31
|
-
return null
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const { default: commandConstructor } = await import(new URL(command.filePath, import.meta.url).href)
|
|
35
|
-
return commandConstructor
|
|
36
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
stubsRoot
|
|
3
|
-
} from "../chunk-V3OAEXMJ.js";
|
|
4
|
-
import "../chunk-PZ5AY32C.js";
|
|
5
|
-
|
|
6
|
-
// commands/make_session_table.ts
|
|
7
|
-
import { BaseCommand } from "@adonisjs/core/ace";
|
|
8
|
-
var MakeSessionTable = class extends BaseCommand {
|
|
9
|
-
static commandName = "make:session-table";
|
|
10
|
-
static description = "Create a migration for the sessions database table";
|
|
11
|
-
async run() {
|
|
12
|
-
const codemods = await this.createCodemods();
|
|
13
|
-
await codemods.makeUsingStub(stubsRoot, "make/migration/sessions.stub", {
|
|
14
|
-
migration: { tableName: "sessions", prefix: Date.now() }
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
export {
|
|
19
|
-
MakeSessionTable as default
|
|
20
|
-
};
|
|
21
|
-
//# sourceMappingURL=make_session_table.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../commands/make_session_table.ts"],"sourcesContent":["/*\n * @adonisjs/session\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { stubsRoot } from '../stubs/main.js'\nimport { BaseCommand } from '@adonisjs/core/ace'\n\n/**\n * Command to create the sessions table migration\n */\nexport default class MakeSessionTable extends BaseCommand {\n static commandName = 'make:session-table'\n static description = 'Create a migration for the sessions database table'\n\n async run() {\n const codemods = await this.createCodemods()\n await codemods.makeUsingStub(stubsRoot, 'make/migration/sessions.stub', {\n migration: { tableName: 'sessions', prefix: Date.now() },\n })\n }\n}\n"],"mappings":";;;;;;AAUA,SAAS,mBAAmB;AAK5B,IAAqB,mBAArB,cAA8C,YAAY;AAAA,EACxD,OAAO,cAAc;AAAA,EACrB,OAAO,cAAc;AAAA,EAErB,MAAM,MAAM;AACV,UAAM,WAAW,MAAM,KAAK,eAAe;AAC3C,UAAM,SAAS,cAAc,WAAW,gCAAgC;AAAA,MACtE,WAAW,EAAE,WAAW,YAAY,QAAQ,KAAK,IAAI,EAAE;AAAA,IACzD,CAAC;AAAA,EACH;AACF;","names":[]}
|
package/build/cookie-3C33DMWA.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
debug_default
|
|
3
|
-
} from "./chunk-5ECC6OWF.js";
|
|
4
|
-
import "./chunk-PZ5AY32C.js";
|
|
5
|
-
|
|
6
|
-
// src/stores/cookie.ts
|
|
7
|
-
var CookieStore = class {
|
|
8
|
-
#ctx;
|
|
9
|
-
#config;
|
|
10
|
-
constructor(config, ctx) {
|
|
11
|
-
this.#config = config;
|
|
12
|
-
this.#ctx = ctx;
|
|
13
|
-
debug_default("initiating cookie store %O", this.#config);
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Read session value from the cookie
|
|
17
|
-
*/
|
|
18
|
-
read(sessionId) {
|
|
19
|
-
debug_default("cookie store: reading session data %s", sessionId);
|
|
20
|
-
const cookieValue = this.#ctx.request.encryptedCookie(sessionId);
|
|
21
|
-
if (typeof cookieValue !== "object") {
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
return cookieValue;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Write session values to the cookie
|
|
28
|
-
*/
|
|
29
|
-
write(sessionId, values) {
|
|
30
|
-
debug_default("cookie store: writing session data %s: %O", sessionId, values);
|
|
31
|
-
this.#ctx.response.encryptedCookie(sessionId, values, this.#config);
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Removes the session cookie
|
|
35
|
-
*/
|
|
36
|
-
destroy(sessionId) {
|
|
37
|
-
debug_default("cookie store: destroying session data %s", sessionId);
|
|
38
|
-
if (this.#ctx.request.cookiesList()[sessionId]) {
|
|
39
|
-
this.#ctx.response.clearCookie(sessionId);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Updates the cookie with existing cookie values
|
|
44
|
-
*/
|
|
45
|
-
touch(sessionId) {
|
|
46
|
-
const value = this.read(sessionId);
|
|
47
|
-
debug_default("cookie store: touching session data %s", sessionId);
|
|
48
|
-
if (!value) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
this.write(sessionId, value);
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
export {
|
|
55
|
-
CookieStore
|
|
56
|
-
};
|
|
57
|
-
//# sourceMappingURL=cookie-3C33DMWA.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/stores/cookie.ts"],"sourcesContent":["/*\n * @adonisjs/session\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport type { HttpContext } from '@adonisjs/core/http'\nimport type { CookieOptions } from '@adonisjs/core/types/http'\n\nimport debug from '../debug.js'\nimport type { SessionData, SessionStoreContract } from '../types.js'\n\n/**\n * Cookie store stores the session data inside an encrypted\n * cookie.\n */\nexport class CookieStore implements SessionStoreContract {\n #ctx: HttpContext\n #config: Partial<CookieOptions>\n\n constructor(config: Partial<CookieOptions>, ctx: HttpContext) {\n this.#config = config\n this.#ctx = ctx\n debug('initiating cookie store %O', this.#config)\n }\n\n /**\n * Read session value from the cookie\n */\n read(sessionId: string): SessionData | null {\n debug('cookie store: reading session data %s', sessionId)\n\n const cookieValue = this.#ctx.request.encryptedCookie(sessionId)\n if (typeof cookieValue !== 'object') {\n return null\n }\n\n return cookieValue\n }\n\n /**\n * Write session values to the cookie\n */\n write(sessionId: string, values: SessionData): void {\n debug('cookie store: writing session data %s: %O', sessionId, values)\n this.#ctx.response.encryptedCookie(sessionId, values, this.#config)\n }\n\n /**\n * Removes the session cookie\n */\n destroy(sessionId: string): void {\n debug('cookie store: destroying session data %s', sessionId)\n if (this.#ctx.request.cookiesList()[sessionId]) {\n this.#ctx.response.clearCookie(sessionId)\n }\n }\n\n /**\n * Updates the cookie with existing cookie values\n */\n touch(sessionId: string): void {\n const value = this.read(sessionId)\n debug('cookie store: touching session data %s', sessionId)\n if (!value) {\n return\n }\n\n this.write(sessionId, value)\n }\n}\n"],"mappings":";;;;;;AAmBO,IAAM,cAAN,MAAkD;AAAA,EACvD;AAAA,EACA;AAAA,EAEA,YAAY,QAAgC,KAAkB;AAC5D,SAAK,UAAU;AACf,SAAK,OAAO;AACZ,kBAAM,8BAA8B,KAAK,OAAO;AAAA,EAClD;AAAA;AAAA;AAAA;AAAA,EAKA,KAAK,WAAuC;AAC1C,kBAAM,yCAAyC,SAAS;AAExD,UAAM,cAAc,KAAK,KAAK,QAAQ,gBAAgB,SAAS;AAC/D,QAAI,OAAO,gBAAgB,UAAU;AACnC,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,WAAmB,QAA2B;AAClD,kBAAM,6CAA6C,WAAW,MAAM;AACpE,SAAK,KAAK,SAAS,gBAAgB,WAAW,QAAQ,KAAK,OAAO;AAAA,EACpE;AAAA;AAAA;AAAA;AAAA,EAKA,QAAQ,WAAyB;AAC/B,kBAAM,4CAA4C,SAAS;AAC3D,QAAI,KAAK,KAAK,QAAQ,YAAY,EAAE,SAAS,GAAG;AAC9C,WAAK,KAAK,SAAS,YAAY,SAAS;AAAA,IAC1C;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,WAAyB;AAC7B,UAAM,QAAQ,KAAK,KAAK,SAAS;AACjC,kBAAM,0CAA0C,SAAS;AACzD,QAAI,CAAC,OAAO;AACV;AAAA,IACF;AAEA,SAAK,MAAM,WAAW,KAAK;AAAA,EAC7B;AACF;","names":[]}
|