@adonisjs/session 7.0.0-11 → 7.0.0-13
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/configure.js +1 -1
- package/build/factories/session_middleware_factory.d.ts +9 -4
- package/build/factories/session_middleware_factory.js +5 -4
- package/build/index.d.ts +1 -3
- package/build/index.js +1 -3
- package/build/providers/session_provider.d.ts +22 -5
- package/build/providers/session_provider.js +21 -21
- package/build/src/client.d.ts +2 -2
- package/build/src/client.js +14 -14
- package/build/src/debug.d.ts +1 -1
- package/build/src/define_config.d.ts +24 -3
- package/build/src/define_config.js +80 -17
- package/build/src/plugins/japa/api_client.d.ts +2 -2
- package/build/src/plugins/japa/api_client.js +8 -12
- package/build/src/plugins/japa/browser_client.d.ts +2 -2
- package/build/src/plugins/japa/browser_client.js +8 -12
- package/build/src/session.d.ts +7 -7
- package/build/src/session.js +40 -37
- package/build/src/session_middleware.d.ts +7 -4
- package/build/src/session_middleware.js +2 -3
- package/build/src/{drivers → stores}/cookie.d.ts +4 -4
- package/build/src/{drivers → stores}/cookie.js +7 -7
- package/build/src/{drivers → stores}/file.d.ts +4 -4
- package/build/src/{drivers → stores}/file.js +8 -8
- package/build/src/{drivers → stores}/memory.d.ts +3 -3
- package/build/src/{drivers → stores}/memory.js +5 -5
- package/build/src/{drivers → stores}/redis.d.ts +5 -5
- package/build/src/{drivers → stores}/redis.js +14 -18
- package/build/src/{types/main.d.ts → types.d.ts} +11 -31
- package/build/src/{store.d.ts → values_store.d.ts} +3 -3
- package/build/src/{store.js → values_store.js} +2 -2
- package/build/stubs/config.stub +18 -18
- package/package.json +20 -20
- package/build/src/drivers_collection.d.ts +0 -21
- package/build/src/drivers_collection.js +0 -38
- package/build/src/helpers.d.ts +0 -6
- package/build/src/helpers.js +0 -43
- package/build/src/types/extended.d.ts +0 -19
- package/build/src/types/main.js +0 -9
- /package/build/src/{types/extended.js → types.js} +0 -0
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { HttpContext } from '@adonisjs/core/http';
|
|
2
2
|
import { RedisConnections } from '@adonisjs/redis/types';
|
|
3
3
|
import type { CookieOptions } from '@adonisjs/core/types/http';
|
|
4
|
-
import type { FileDriver } from '../drivers/file.js';
|
|
5
|
-
import type { RedisDriver } from '../drivers/redis.js';
|
|
6
|
-
import type { MemoryDriver } from '../drivers/memory.js';
|
|
7
|
-
import type { CookieDriver } from '../drivers/cookie.js';
|
|
8
4
|
/**
|
|
9
5
|
* The values allowed by the `session.put` method
|
|
10
6
|
*/
|
|
11
7
|
export type AllowedSessionValues = string | boolean | number | object | Date | Array<any>;
|
|
12
8
|
export type SessionData = Record<string, AllowedSessionValues>;
|
|
13
9
|
/**
|
|
14
|
-
* Session
|
|
10
|
+
* Session stores must implement the session store contract.
|
|
15
11
|
*/
|
|
16
|
-
export interface
|
|
12
|
+
export interface SessionStoreContract {
|
|
17
13
|
/**
|
|
18
14
|
* The read method is used to read the data from the persistence
|
|
19
15
|
* store and return it back as an object
|
|
@@ -36,17 +32,14 @@ export interface SessionDriverContract {
|
|
|
36
32
|
touch(sessionId: string): Promise<void> | void;
|
|
37
33
|
}
|
|
38
34
|
/**
|
|
39
|
-
*
|
|
35
|
+
* Base configuration for managing sessions without
|
|
36
|
+
* stores.
|
|
40
37
|
*/
|
|
41
38
|
export interface SessionConfig {
|
|
42
39
|
/**
|
|
43
40
|
* Enable/disable sessions temporarily
|
|
44
41
|
*/
|
|
45
42
|
enabled: boolean;
|
|
46
|
-
/**
|
|
47
|
-
* The drivers to use
|
|
48
|
-
*/
|
|
49
|
-
driver: keyof SessionDriversList;
|
|
50
43
|
/**
|
|
51
44
|
* The name of the cookie for storing the session id.
|
|
52
45
|
*/
|
|
@@ -76,31 +69,18 @@ export interface SessionConfig {
|
|
|
76
69
|
cookie: Omit<Partial<CookieOptions>, 'maxAge' | 'expires'>;
|
|
77
70
|
}
|
|
78
71
|
/**
|
|
79
|
-
* Configuration used by the file
|
|
72
|
+
* Configuration used by the file store.
|
|
80
73
|
*/
|
|
81
|
-
export type
|
|
74
|
+
export type FileStoreConfig = {
|
|
82
75
|
location: string;
|
|
83
76
|
};
|
|
84
77
|
/**
|
|
85
|
-
* Configuration used by the redis
|
|
78
|
+
* Configuration used by the redis store.
|
|
86
79
|
*/
|
|
87
|
-
export type
|
|
80
|
+
export type RedisStoreConfig = {
|
|
88
81
|
connection: keyof RedisConnections;
|
|
89
82
|
};
|
|
90
83
|
/**
|
|
91
|
-
*
|
|
84
|
+
* Factory function to instantiate session store
|
|
92
85
|
*/
|
|
93
|
-
export
|
|
94
|
-
file?: FileDriverConfig;
|
|
95
|
-
redis?: RedisDriverConfig;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* List of the session drivers. The list can be extended using
|
|
99
|
-
* declaration merging
|
|
100
|
-
*/
|
|
101
|
-
export interface SessionDriversList {
|
|
102
|
-
file: (config: SessionConfig, ctx: HttpContext) => FileDriver;
|
|
103
|
-
cookie: (config: SessionConfig, ctx: HttpContext) => CookieDriver;
|
|
104
|
-
redis: (config: SessionConfig, ctx: HttpContext) => RedisDriver;
|
|
105
|
-
memory: (config: SessionConfig, ctx?: HttpContext) => MemoryDriver;
|
|
106
|
-
}
|
|
86
|
+
export type SessionStoreFactory = (ctx: HttpContext, sessionConfig: SessionConfig) => SessionStoreContract;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { AllowedSessionValues, SessionData } from './types
|
|
1
|
+
import type { AllowedSessionValues, SessionData } from './types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Readonly session store
|
|
4
4
|
*/
|
|
5
|
-
export declare class
|
|
5
|
+
export declare class ReadOnlyValuesStore {
|
|
6
6
|
/**
|
|
7
7
|
* Underlying store values
|
|
8
8
|
*/
|
|
@@ -42,7 +42,7 @@ export declare class ReadOnlyStore {
|
|
|
42
42
|
* Session store encapsulates the session data and offers a
|
|
43
43
|
* declarative API to mutate it.
|
|
44
44
|
*/
|
|
45
|
-
export declare class
|
|
45
|
+
export declare class ValuesStore extends ReadOnlyValuesStore {
|
|
46
46
|
#private;
|
|
47
47
|
constructor(values: SessionData | null);
|
|
48
48
|
/**
|
|
@@ -11,7 +11,7 @@ import { RuntimeException } from '@poppinss/utils';
|
|
|
11
11
|
/**
|
|
12
12
|
* Readonly session store
|
|
13
13
|
*/
|
|
14
|
-
export class
|
|
14
|
+
export class ReadOnlyValuesStore {
|
|
15
15
|
/**
|
|
16
16
|
* Underlying store values
|
|
17
17
|
*/
|
|
@@ -75,7 +75,7 @@ export class ReadOnlyStore {
|
|
|
75
75
|
* Session store encapsulates the session data and offers a
|
|
76
76
|
* declarative API to mutate it.
|
|
77
77
|
*/
|
|
78
|
-
export class
|
|
78
|
+
export class ValuesStore extends ReadOnlyValuesStore {
|
|
79
79
|
/**
|
|
80
80
|
* A boolean to know if store has been
|
|
81
81
|
* modified
|
package/build/stubs/config.stub
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
to:
|
|
3
|
-
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.configPath('session.ts') })
|
|
3
|
+
}}}
|
|
4
4
|
import env from '#start/env'
|
|
5
|
-
import
|
|
5
|
+
import app from '@adonisjs/core/services/app'
|
|
6
|
+
import { defineConfig, stores } from '@adonisjs/session'
|
|
6
7
|
|
|
7
8
|
export default defineConfig({
|
|
8
9
|
enabled: true,
|
|
@@ -21,29 +22,28 @@ export default defineConfig({
|
|
|
21
22
|
age: '2h',
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* errors.
|
|
25
|
+
* Configuration for session cookie and the
|
|
26
|
+
* cookie store
|
|
27
27
|
*/
|
|
28
|
-
driver: env.get('SESSION_DRIVER'),
|
|
29
|
-
|
|
30
28
|
cookie: {
|
|
31
29
|
path: '/',
|
|
32
30
|
httpOnly: true,
|
|
33
|
-
|
|
31
|
+
secure: app.inProduction,
|
|
32
|
+
sameSite: 'lax',
|
|
34
33
|
},
|
|
35
34
|
|
|
36
35
|
/**
|
|
37
|
-
*
|
|
36
|
+
* The store to use. Make sure to validate the environment
|
|
37
|
+
* variable in order to infer the store name without any
|
|
38
|
+
* errors.
|
|
38
39
|
*/
|
|
39
|
-
|
|
40
|
-
// location: app.tmpPath('sessions'),
|
|
41
|
-
// },
|
|
40
|
+
store: env.get('SESSION_DRIVER'),
|
|
42
41
|
|
|
43
42
|
/**
|
|
44
|
-
*
|
|
43
|
+
* List of configured stores. Refer documentation to see
|
|
44
|
+
* list of available stores and their config.
|
|
45
45
|
*/
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
stores: {
|
|
47
|
+
cookie: stores.cookie(),
|
|
48
|
+
}
|
|
49
49
|
})
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonisjs/session",
|
|
3
3
|
"description": "Session provider for AdonisJS",
|
|
4
|
-
"version": "7.0.0-
|
|
4
|
+
"version": "7.0.0-13",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=18.16.0"
|
|
7
7
|
},
|
|
@@ -45,30 +45,30 @@
|
|
|
45
45
|
"quick:test": "node --enable-source-maps --loader=ts-node/esm bin/test.ts"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@adonisjs/assembler": "^6.1.3-
|
|
49
|
-
"@adonisjs/core": "^6.1.5-
|
|
48
|
+
"@adonisjs/assembler": "^6.1.3-25",
|
|
49
|
+
"@adonisjs/core": "^6.1.5-28",
|
|
50
50
|
"@adonisjs/eslint-config": "^1.1.8",
|
|
51
51
|
"@adonisjs/prettier-config": "^1.1.8",
|
|
52
|
-
"@adonisjs/redis": "^8.0.0-
|
|
52
|
+
"@adonisjs/redis": "^8.0.0-11",
|
|
53
53
|
"@adonisjs/tsconfig": "^1.1.8",
|
|
54
|
-
"@japa/api-client": "^2.0.0
|
|
55
|
-
"@japa/assert": "^2.0.0
|
|
56
|
-
"@japa/browser-client": "^2.0.0
|
|
57
|
-
"@japa/file-system": "^2.0.0
|
|
58
|
-
"@japa/plugin-adonisjs": "^2.0.0
|
|
59
|
-
"@japa/runner": "^3.0.
|
|
60
|
-
"@japa/snapshot": "^2.0.0
|
|
54
|
+
"@japa/api-client": "^2.0.0",
|
|
55
|
+
"@japa/assert": "^2.0.0",
|
|
56
|
+
"@japa/browser-client": "^2.0.0",
|
|
57
|
+
"@japa/file-system": "^2.0.0",
|
|
58
|
+
"@japa/plugin-adonisjs": "^2.0.0",
|
|
59
|
+
"@japa/runner": "^3.0.4",
|
|
60
|
+
"@japa/snapshot": "^2.0.0",
|
|
61
61
|
"@swc/core": "1.3.82",
|
|
62
|
-
"@types/node": "^20.
|
|
63
|
-
"@types/set-cookie-parser": "^2.4.
|
|
64
|
-
"@types/supertest": "^2.0.
|
|
62
|
+
"@types/node": "^20.8.7",
|
|
63
|
+
"@types/set-cookie-parser": "^2.4.4",
|
|
64
|
+
"@types/supertest": "^2.0.14",
|
|
65
65
|
"@vinejs/vine": "^1.6.0",
|
|
66
66
|
"c8": "^8.0.0",
|
|
67
67
|
"copyfiles": "^2.4.1",
|
|
68
68
|
"cross-env": "^7.0.3",
|
|
69
69
|
"del-cli": "^5.0.0",
|
|
70
70
|
"edge.js": "^6.0.0-8",
|
|
71
|
-
"eslint": "^8.
|
|
71
|
+
"eslint": "^8.51.0",
|
|
72
72
|
"get-port": "^7.0.0",
|
|
73
73
|
"github-label-sync": "^2.3.1",
|
|
74
74
|
"husky": "^8.0.3",
|
|
@@ -81,13 +81,13 @@
|
|
|
81
81
|
"typescript": "^5.1.6"
|
|
82
82
|
},
|
|
83
83
|
"dependencies": {
|
|
84
|
-
"@poppinss/utils": "^6.5.0
|
|
84
|
+
"@poppinss/utils": "^6.5.0"
|
|
85
85
|
},
|
|
86
86
|
"peerDependencies": {
|
|
87
|
-
"@adonisjs/core": "^6.1.5-
|
|
88
|
-
"@adonisjs/redis": "^8.0.0-
|
|
89
|
-
"@japa/api-client": "^2.0.0
|
|
90
|
-
"@japa/browser-client": "^2.0.0
|
|
87
|
+
"@adonisjs/core": "^6.1.5-28",
|
|
88
|
+
"@adonisjs/redis": "^8.0.0-11",
|
|
89
|
+
"@japa/api-client": "^2.0.0",
|
|
90
|
+
"@japa/browser-client": "^2.0.0",
|
|
91
91
|
"edge.js": "^6.0.0-8"
|
|
92
92
|
},
|
|
93
93
|
"peerDependenciesMeta": {
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { SessionDriversList } from './types/main.js';
|
|
2
|
-
/**
|
|
3
|
-
* A global collection of session drivers
|
|
4
|
-
*/
|
|
5
|
-
declare class SessionDriversCollection {
|
|
6
|
-
/**
|
|
7
|
-
* List of registered drivers
|
|
8
|
-
*/
|
|
9
|
-
list: Partial<SessionDriversList>;
|
|
10
|
-
/**
|
|
11
|
-
* Extend drivers collection and add a custom
|
|
12
|
-
* driver to it.
|
|
13
|
-
*/
|
|
14
|
-
extend<Name extends keyof SessionDriversList>(driverName: Name, factoryCallback: SessionDriversList[Name]): this;
|
|
15
|
-
/**
|
|
16
|
-
* Creates the driver instance with config
|
|
17
|
-
*/
|
|
18
|
-
create<Name extends keyof SessionDriversList>(name: Name, ...args: Parameters<SessionDriversList[Name]>): ReturnType<SessionDriversList[Name]>;
|
|
19
|
-
}
|
|
20
|
-
declare const sessionDriversList: SessionDriversCollection;
|
|
21
|
-
export default sessionDriversList;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @adonisjs/session
|
|
3
|
-
*
|
|
4
|
-
* (c) AdonisJS
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
import { RuntimeException } from '@poppinss/utils';
|
|
10
|
-
/**
|
|
11
|
-
* A global collection of session drivers
|
|
12
|
-
*/
|
|
13
|
-
class SessionDriversCollection {
|
|
14
|
-
/**
|
|
15
|
-
* List of registered drivers
|
|
16
|
-
*/
|
|
17
|
-
list = {};
|
|
18
|
-
/**
|
|
19
|
-
* Extend drivers collection and add a custom
|
|
20
|
-
* driver to it.
|
|
21
|
-
*/
|
|
22
|
-
extend(driverName, factoryCallback) {
|
|
23
|
-
this.list[driverName] = factoryCallback;
|
|
24
|
-
return this;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Creates the driver instance with config
|
|
28
|
-
*/
|
|
29
|
-
create(name, ...args) {
|
|
30
|
-
const driverFactory = this.list[name];
|
|
31
|
-
if (!driverFactory) {
|
|
32
|
-
throw new RuntimeException(`Unknown session driver "${String(name)}". Make sure the driver is registered`);
|
|
33
|
-
}
|
|
34
|
-
return driverFactory(args[0], args[1]);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
const sessionDriversList = new SessionDriversCollection();
|
|
38
|
-
export default sessionDriversList;
|
package/build/src/helpers.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { ApplicationService } from '@adonisjs/core/types';
|
|
2
|
-
import type { SessionDriversList } from './types/main.js';
|
|
3
|
-
/**
|
|
4
|
-
* Lazily imports and registers a driver with the sessionDriversList
|
|
5
|
-
*/
|
|
6
|
-
export declare function registerSessionDriver(app: ApplicationService, driverInUse: keyof SessionDriversList): Promise<void>;
|
package/build/src/helpers.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @adonisjs/session
|
|
3
|
-
*
|
|
4
|
-
* (c) AdonisJS
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
import debug from './debug.js';
|
|
10
|
-
import sessionDriversList from './drivers_collection.js';
|
|
11
|
-
/**
|
|
12
|
-
* Lazily imports and registers a driver with the sessionDriversList
|
|
13
|
-
*/
|
|
14
|
-
export async function registerSessionDriver(app, driverInUse) {
|
|
15
|
-
/**
|
|
16
|
-
* Noop when the driver is already registered
|
|
17
|
-
*/
|
|
18
|
-
if (sessionDriversList.list[driverInUse]) {
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
debug('registering %s driver', driverInUse);
|
|
22
|
-
if (driverInUse === 'cookie') {
|
|
23
|
-
const { CookieDriver } = await import('../src/drivers/cookie.js');
|
|
24
|
-
sessionDriversList.extend('cookie', (config, ctx) => new CookieDriver(config.cookie, ctx));
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
if (driverInUse === 'memory') {
|
|
28
|
-
const { MemoryDriver } = await import('../src/drivers/memory.js');
|
|
29
|
-
sessionDriversList.extend('memory', () => new MemoryDriver());
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
if (driverInUse === 'file') {
|
|
33
|
-
const { FileDriver } = await import('../src/drivers/file.js');
|
|
34
|
-
sessionDriversList.extend('file', (config) => new FileDriver(config.file, config.age));
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
if (driverInUse === 'redis') {
|
|
38
|
-
const { RedisDriver } = await import('../src/drivers/redis.js');
|
|
39
|
-
const redis = await app.container.make('redis');
|
|
40
|
-
sessionDriversList.extend('redis', (config) => new RedisDriver(redis, config.redis, config.age));
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { Session } from '../session.js';
|
|
2
|
-
/**
|
|
3
|
-
* Events emitted by the session class
|
|
4
|
-
*/
|
|
5
|
-
declare module '@adonisjs/core/types' {
|
|
6
|
-
interface EventsList {
|
|
7
|
-
'session:initiated': {
|
|
8
|
-
session: Session;
|
|
9
|
-
};
|
|
10
|
-
'session:committed': {
|
|
11
|
-
session: Session;
|
|
12
|
-
};
|
|
13
|
-
'session:migrated': {
|
|
14
|
-
fromSessionId: string;
|
|
15
|
-
toSessionId: string;
|
|
16
|
-
session: Session;
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
}
|
package/build/src/types/main.js
DELETED
|
File without changes
|