@adonisjs/session 8.0.0-next.0 → 8.0.0-next.2

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.
Files changed (50) hide show
  1. package/build/commands/commands.json +1 -0
  2. package/build/commands/main.d.ts +4 -0
  3. package/build/commands/main.js +36 -0
  4. package/build/commands/make_session_table.d.ts +9 -0
  5. package/build/commands/make_session_table.js +13 -0
  6. package/build/cookie--JOJxrtW.js +31 -0
  7. package/build/database-vbrhCOPd.js +86 -0
  8. package/build/debug-BZVg83L1.js +3 -0
  9. package/build/dynamodb-BFVgTQSf.js +72 -0
  10. package/build/factories/main.js +27 -45
  11. package/build/file-BBU02j4z.js +71 -0
  12. package/build/index.d.ts +1 -0
  13. package/build/index.js +7 -25
  14. package/build/main-kn40V-hF.js +2 -0
  15. package/build/make/migration/sessions.stub +26 -0
  16. package/build/providers/session_provider.d.ts +2 -1
  17. package/build/providers/session_provider.js +34 -48
  18. package/build/redis-D8D9UtiD.js +91 -0
  19. package/build/session-C9DdRahS.js +215 -0
  20. package/build/session-Cb9-DoMh.js +139 -0
  21. package/build/session_collection-CvS5yIq6.js +31 -0
  22. package/build/session_middleware-gegOBxmm.js +27 -0
  23. package/build/src/client.js +38 -7
  24. package/build/src/debug.d.ts +1 -1
  25. package/build/src/define_config.d.ts +14 -6
  26. package/build/src/errors.d.ts +9 -0
  27. package/build/src/plugins/edge.d.ts +5 -1
  28. package/build/src/plugins/edge.js +74 -124
  29. package/build/src/plugins/japa/api_client.js +76 -96
  30. package/build/src/plugins/japa/browser_client.js +58 -81
  31. package/build/src/session.d.ts +12 -0
  32. package/build/src/session_collection.d.ts +81 -0
  33. package/build/src/session_middleware.js +5 -9
  34. package/build/src/stores/database.d.ts +70 -0
  35. package/build/src/stores/memory.d.ts +19 -2
  36. package/build/src/stores/redis.d.ts +15 -2
  37. package/build/src/types.d.ts +62 -8
  38. package/build/src/types.js +1 -0
  39. package/build/values_store-CvR1Sn37.js +78 -0
  40. package/package.json +65 -42
  41. package/build/chunk-DFXWYDMY.js +0 -62
  42. package/build/chunk-HAD4PFFM.js +0 -229
  43. package/build/chunk-MVBWJOEG.js +0 -187
  44. package/build/chunk-SBOMJK4T.js +0 -14
  45. package/build/chunk-SHD6OX52.js +0 -488
  46. package/build/chunk-Y566BNUT.js +0 -113
  47. package/build/cookie-YBBGLCO5.js +0 -88
  48. package/build/dynamodb-PLZABBFD.js +0 -153
  49. package/build/file-CCJ5ESE2.js +0 -151
  50. package/build/redis-NXJWWWVB.js +0 -89
@@ -1,153 +0,0 @@
1
- import {
2
- debug_default
3
- } from "./chunk-SBOMJK4T.js";
4
-
5
- // src/stores/dynamodb.ts
6
- import string from "@adonisjs/core/helpers/string";
7
- import { MessageBuilder } from "@adonisjs/core/helpers";
8
- import { marshall, unmarshall } from "@aws-sdk/util-dynamodb";
9
- import {
10
- GetItemCommand,
11
- PutItemCommand,
12
- DeleteItemCommand,
13
- UpdateItemCommand
14
- } from "@aws-sdk/client-dynamodb";
15
- var DynamoDBStore = class {
16
- /**
17
- * DynamoDB client instance
18
- */
19
- #client;
20
- /**
21
- * DynamoDB table name
22
- */
23
- #tableName;
24
- /**
25
- * Attribute name for the session key
26
- */
27
- #keyAttribute;
28
- /**
29
- * Time-to-live in seconds for session expiry
30
- */
31
- #ttlSeconds;
32
- /**
33
- * Attribute name for the session value
34
- */
35
- #valueAttribute = "value";
36
- /**
37
- * Attribute name for the expiry timestamp
38
- */
39
- #expiresAtAttribute = "expires_at";
40
- /**
41
- * Creates a new DynamoDB store instance
42
- *
43
- * @param client - DynamoDB client instance
44
- * @param age - Session age in seconds or time expression (e.g. '2 hours')
45
- * @param options - Configuration options
46
- * @param options.tableName - DynamoDB table name (defaults to "Session")
47
- * @param options.keyAttribute - Key attribute name (defaults to "key")
48
- */
49
- constructor(client, age, options) {
50
- this.#client = client;
51
- this.#tableName = options?.tableName ?? "Session";
52
- this.#keyAttribute = options?.keyAttribute ?? "key";
53
- this.#ttlSeconds = string.seconds.parse(age);
54
- debug_default("initiating dynamodb store");
55
- }
56
- /**
57
- * Reads session data from DynamoDB
58
- *
59
- * @param sessionId - Session identifier
60
- *
61
- * @example
62
- * const data = await store.read('sess_abc123')
63
- */
64
- async read(sessionId) {
65
- debug_default("dynamodb store: reading session data %s", sessionId);
66
- const command = new GetItemCommand({
67
- TableName: this.#tableName,
68
- Key: marshall({ [this.#keyAttribute]: sessionId })
69
- });
70
- const response = await this.#client.send(command);
71
- if (!response.Item) {
72
- return null;
73
- }
74
- if (!response.Item[this.#valueAttribute]) {
75
- return null;
76
- }
77
- const item = unmarshall(response.Item);
78
- const contents = item[this.#valueAttribute];
79
- const expiresAt = item[this.#expiresAtAttribute];
80
- if (Date.now() > expiresAt) {
81
- return null;
82
- }
83
- try {
84
- return new MessageBuilder().verify(contents, sessionId);
85
- } catch {
86
- return null;
87
- }
88
- }
89
- /**
90
- * Writes session values to DynamoDB with expiry
91
- *
92
- * @param sessionId - Session identifier
93
- * @param values - Session data to store
94
- *
95
- * @example
96
- * await store.write('sess_abc123', { userId: 123 })
97
- */
98
- async write(sessionId, values) {
99
- debug_default("dynamodb store: writing session data %s, %O", sessionId, values);
100
- const message = new MessageBuilder().build(values, void 0, sessionId);
101
- const command = new PutItemCommand({
102
- TableName: this.#tableName,
103
- Item: marshall({
104
- [this.#keyAttribute]: sessionId,
105
- [this.#valueAttribute]: message,
106
- [this.#expiresAtAttribute]: Date.now() + this.#ttlSeconds * 1e3
107
- })
108
- });
109
- await this.#client.send(command);
110
- }
111
- /**
112
- * Removes session data from DynamoDB
113
- *
114
- * @param sessionId - Session identifier to remove
115
- *
116
- * @example
117
- * await store.destroy('sess_abc123')
118
- */
119
- async destroy(sessionId) {
120
- debug_default("dynamodb store: destroying session data %s", sessionId);
121
- const command = new DeleteItemCommand({
122
- TableName: this.#tableName,
123
- Key: marshall({ [this.#keyAttribute]: sessionId })
124
- });
125
- await this.#client.send(command);
126
- }
127
- /**
128
- * Updates the session expiry time in DynamoDB
129
- *
130
- * @param sessionId - Session identifier
131
- *
132
- * @example
133
- * await store.touch('sess_abc123')
134
- */
135
- async touch(sessionId) {
136
- debug_default("dynamodb store: touching session data %s", sessionId);
137
- const command = new UpdateItemCommand({
138
- TableName: this.#tableName,
139
- Key: marshall({ [this.#keyAttribute]: sessionId }),
140
- UpdateExpression: "SET #expires_at = :expires_at",
141
- ExpressionAttributeNames: {
142
- "#expires_at": this.#expiresAtAttribute
143
- },
144
- ExpressionAttributeValues: marshall({
145
- ":expires_at": Date.now() + this.#ttlSeconds * 1e3
146
- })
147
- });
148
- await this.#client.send(command);
149
- }
150
- };
151
- export {
152
- DynamoDBStore
153
- };
@@ -1,151 +0,0 @@
1
- import {
2
- debug_default
3
- } from "./chunk-SBOMJK4T.js";
4
-
5
- // src/stores/file.ts
6
- import { dirname, join } from "path";
7
- import string from "@adonisjs/core/helpers/string";
8
- import { MessageBuilder } from "@adonisjs/core/helpers";
9
- import { access, mkdir, readFile, rm, writeFile, utimes, stat } from "fs/promises";
10
- var FileStore = class {
11
- /**
12
- * File store configuration
13
- */
14
- #config;
15
- /**
16
- * Session age/expiry time
17
- */
18
- #age;
19
- /**
20
- * Creates a new file store instance
21
- *
22
- * @param config - File store configuration
23
- * @param age - Session age in seconds or time expression (e.g. '2 hours')
24
- */
25
- constructor(config, age) {
26
- this.#config = config;
27
- this.#age = age;
28
- debug_default("initiating file store %O", this.#config);
29
- }
30
- /**
31
- * Returns an absolute path to the session id file
32
- *
33
- * @param sessionId - Session identifier
34
- */
35
- #getFilePath(sessionId) {
36
- return join(this.#config.location, `${sessionId}.txt`);
37
- }
38
- /**
39
- * Checks if a file exists at a given path
40
- *
41
- * @param path - File path to check
42
- */
43
- async #pathExists(path) {
44
- try {
45
- await access(path);
46
- return true;
47
- } catch {
48
- return false;
49
- }
50
- }
51
- /**
52
- * Returns file stats, ignoring missing files
53
- *
54
- * @param path - File path to get stats for
55
- */
56
- async #stats(path) {
57
- try {
58
- const stats = await stat(path);
59
- return stats;
60
- } catch {
61
- return null;
62
- }
63
- }
64
- /**
65
- * Outputs file with contents to the given path, creating directories if needed
66
- *
67
- * @param path - File path to write to
68
- * @param contents - File contents to write
69
- */
70
- async #outputFile(path, contents) {
71
- const pathDirname = dirname(path);
72
- const dirExists = await this.#pathExists(pathDirname);
73
- if (!dirExists) {
74
- await mkdir(pathDirname, { recursive: true });
75
- }
76
- await writeFile(path, contents, "utf-8");
77
- }
78
- /**
79
- * Reads the session data from the disk
80
- *
81
- * @param sessionId - Session identifier
82
- *
83
- * @example
84
- * const data = await store.read('sess_abc123')
85
- */
86
- async read(sessionId) {
87
- const filePath = this.#getFilePath(sessionId);
88
- debug_default("file store: reading session data %", sessionId);
89
- const stats = await this.#stats(filePath);
90
- if (!stats) {
91
- return null;
92
- }
93
- const sessionWillExpireAt = stats.mtimeMs + string.seconds.parse(this.#age) * 1e3;
94
- if (Date.now() > sessionWillExpireAt) {
95
- debug_default("file store: expired session data %s", sessionId);
96
- return null;
97
- }
98
- let contents = await readFile(filePath, "utf-8");
99
- contents = contents.trim();
100
- if (!contents) {
101
- return null;
102
- }
103
- try {
104
- return new MessageBuilder().verify(contents, sessionId);
105
- } catch {
106
- return null;
107
- }
108
- }
109
- /**
110
- * Writes the session data to the disk as a string
111
- *
112
- * @param sessionId - Session identifier
113
- * @param values - Session data to store
114
- *
115
- * @example
116
- * await store.write('sess_abc123', { userId: 123 })
117
- */
118
- async write(sessionId, values) {
119
- debug_default("file store: writing session data %s: %O", sessionId, values);
120
- const filePath = this.#getFilePath(sessionId);
121
- const message = new MessageBuilder().build(values, void 0, sessionId);
122
- await this.#outputFile(filePath, message);
123
- }
124
- /**
125
- * Removes the session file from the disk
126
- *
127
- * @param sessionId - Session identifier
128
- *
129
- * @example
130
- * await store.destroy('sess_abc123')
131
- */
132
- async destroy(sessionId) {
133
- debug_default("file store: destroying session data %s", sessionId);
134
- await rm(this.#getFilePath(sessionId), { force: true });
135
- }
136
- /**
137
- * Updates the session expiry by updating the file's modification time
138
- *
139
- * @param sessionId - Session identifier
140
- *
141
- * @example
142
- * await store.touch('sess_abc123')
143
- */
144
- async touch(sessionId) {
145
- debug_default("file store: touching session data %s", sessionId);
146
- await utimes(this.#getFilePath(sessionId), /* @__PURE__ */ new Date(), /* @__PURE__ */ new Date());
147
- }
148
- };
149
- export {
150
- FileStore
151
- };
@@ -1,89 +0,0 @@
1
- import {
2
- debug_default
3
- } from "./chunk-SBOMJK4T.js";
4
-
5
- // src/stores/redis.ts
6
- import string from "@adonisjs/core/helpers/string";
7
- import { MessageBuilder } from "@adonisjs/core/helpers";
8
- var RedisStore = class {
9
- /**
10
- * Redis connection instance
11
- */
12
- #connection;
13
- /**
14
- * Time-to-live in seconds for session expiry
15
- */
16
- #ttlSeconds;
17
- /**
18
- * Creates a new Redis store instance
19
- *
20
- * @param connection - Redis connection instance
21
- * @param age - Session age in seconds or time expression (e.g. '2 hours')
22
- */
23
- constructor(connection, age) {
24
- this.#connection = connection;
25
- this.#ttlSeconds = string.seconds.parse(age);
26
- debug_default("initiating redis store");
27
- }
28
- /**
29
- * Reads session data from Redis
30
- *
31
- * @param sessionId - Session identifier
32
- *
33
- * @example
34
- * const data = await store.read('sess_abc123')
35
- */
36
- async read(sessionId) {
37
- debug_default("redis store: reading session data %s", sessionId);
38
- const contents = await this.#connection.get(sessionId);
39
- if (!contents) {
40
- return null;
41
- }
42
- try {
43
- return new MessageBuilder().verify(contents, sessionId);
44
- } catch {
45
- return null;
46
- }
47
- }
48
- /**
49
- * Writes session values to Redis with expiry
50
- *
51
- * @param sessionId - Session identifier
52
- * @param values - Session data to store
53
- *
54
- * @example
55
- * await store.write('sess_abc123', { userId: 123 })
56
- */
57
- async write(sessionId, values) {
58
- debug_default("redis store: writing session data %s, %O", sessionId, values);
59
- const message = new MessageBuilder().build(values, void 0, sessionId);
60
- await this.#connection.setex(sessionId, this.#ttlSeconds, message);
61
- }
62
- /**
63
- * Removes session data from Redis
64
- *
65
- * @param sessionId - Session identifier to remove
66
- *
67
- * @example
68
- * await store.destroy('sess_abc123')
69
- */
70
- async destroy(sessionId) {
71
- debug_default("redis store: destroying session data %s", sessionId);
72
- await this.#connection.del(sessionId);
73
- }
74
- /**
75
- * Updates the session expiry time in Redis
76
- *
77
- * @param sessionId - Session identifier
78
- *
79
- * @example
80
- * await store.touch('sess_abc123')
81
- */
82
- async touch(sessionId) {
83
- debug_default("redis store: touching session data %s", sessionId);
84
- await this.#connection.expire(sessionId, this.#ttlSeconds);
85
- }
86
- };
87
- export {
88
- RedisStore
89
- };