@eggjs/session 5.0.0-beta.34 → 5.0.0-beta.36
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/dist/app/extend/application.d.ts +35 -31
- package/dist/app/extend/application.js +48 -49
- package/dist/app/middleware/session.d.ts +2 -2
- package/dist/app/middleware/session.js +7 -3
- package/dist/app.d.ts +9 -5
- package/dist/app.js +26 -25
- package/dist/config/config.default.d.ts +10 -7
- package/dist/config/config.default.js +15 -15
- package/dist/index.d.ts +7 -4
- package/dist/index.js +11 -8
- package/dist/types.d.ts +13 -11
- package/dist/types.js +1 -2
- package/package.json +31 -37
|
@@ -1,33 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { SessionConfig } from "../../config/config.default.js";
|
|
2
|
+
import { Application } from "egg";
|
|
3
|
+
|
|
4
|
+
//#region src/app/extend/application.d.ts
|
|
5
|
+
type SessionStore = Required<SessionConfig>["store"];
|
|
6
|
+
type SessionStoreOrAppSessionStoreClass = SessionStore | {
|
|
7
|
+
new (app: Application): SessionStore;
|
|
6
8
|
};
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
9
|
+
declare class SessionApplication extends Application {
|
|
10
|
+
/**
|
|
11
|
+
* set session external store
|
|
12
|
+
*
|
|
13
|
+
* ```js
|
|
14
|
+
* app.sessionStore = {
|
|
15
|
+
* get(key): Promise<unknown>,
|
|
16
|
+
* set(key, data): Promise<void>,
|
|
17
|
+
* destroy(key): Promise<void>,
|
|
18
|
+
* };
|
|
19
|
+
*
|
|
20
|
+
* app.sessionStore = class SessionStore {
|
|
21
|
+
* constructor(app) {
|
|
22
|
+
* }
|
|
23
|
+
* get(key): Promise<unknown>,
|
|
24
|
+
* set(key, data): Promise<void>,
|
|
25
|
+
* destroy(key): Promise<void>,
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
* @param {Class|Object} store session store class or instance
|
|
29
|
+
*/
|
|
30
|
+
set sessionStore(store: SessionStoreOrAppSessionStoreClass | null | undefined);
|
|
31
|
+
/**
|
|
32
|
+
* get sessionStore instance
|
|
33
|
+
*/
|
|
34
|
+
get sessionStore(): SessionStore | undefined;
|
|
33
35
|
}
|
|
36
|
+
//#endregion
|
|
37
|
+
export { SessionStore, SessionStoreOrAppSessionStoreClass, SessionApplication as default };
|
|
@@ -1,49 +1,48 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXBwbGljYXR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QU8sS0FBSyxDQUFDLEdBQUcsS0FBSyxVQUFVLEVBQUUsNEJBQTRCLENBQUMsQ0FBQztRQUN0RSxNQUFNLENBQUMsT0FBTyxLQUFLLENBQUMsT0FBTyxLQUFLLFVBQVUsRUFBRSxnQ0FBZ0MsQ0FBQyxDQUFDO1FBQzlFLElBQUksQ0FBQyxNQUFNLENBQUMsT0FBTyxDQUFDLEtBQUssR0FBRyxLQUFLLENBQUM7SUFDcEMsQ0FBQztJQUVEOztPQUVHO0lBQ0gsSUFBSSxZQUFZO1FBQ2QsT0FBTyxJQUFJLENBQUMsTUFBTSxDQUFDLE9BQU8sQ0FBQyxLQUFLLENBQUM7SUFDbkMsQ0FBQztDQUNGIn0=
|
|
1
|
+
import { Application } from "egg";
|
|
2
|
+
import assert from "node:assert";
|
|
3
|
+
|
|
4
|
+
//#region src/app/extend/application.ts
|
|
5
|
+
var SessionApplication = class extends Application {
|
|
6
|
+
/**
|
|
7
|
+
* set session external store
|
|
8
|
+
*
|
|
9
|
+
* ```js
|
|
10
|
+
* app.sessionStore = {
|
|
11
|
+
* get(key): Promise<unknown>,
|
|
12
|
+
* set(key, data): Promise<void>,
|
|
13
|
+
* destroy(key): Promise<void>,
|
|
14
|
+
* };
|
|
15
|
+
*
|
|
16
|
+
* app.sessionStore = class SessionStore {
|
|
17
|
+
* constructor(app) {
|
|
18
|
+
* }
|
|
19
|
+
* get(key): Promise<unknown>,
|
|
20
|
+
* set(key, data): Promise<void>,
|
|
21
|
+
* destroy(key): Promise<void>,
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
* @param {Class|Object} store session store class or instance
|
|
25
|
+
*/
|
|
26
|
+
set sessionStore(store) {
|
|
27
|
+
if (this.config.session.store && this.config.env !== "unittest") this.coreLogger.warn("[@eggjs/session] sessionStore already exists and will be overwrite");
|
|
28
|
+
if (!store) {
|
|
29
|
+
this.config.session.store = void 0;
|
|
30
|
+
this.coreLogger.info("[@eggjs/session] sessionStore is disabled");
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (typeof store === "function") store = new store(this);
|
|
34
|
+
assert(typeof store.get === "function", "store.get must be function");
|
|
35
|
+
assert(typeof store.set === "function", "store.set must be function");
|
|
36
|
+
assert(typeof store.destroy === "function", "store.destroy must be function");
|
|
37
|
+
this.config.session.store = store;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* get sessionStore instance
|
|
41
|
+
*/
|
|
42
|
+
get sessionStore() {
|
|
43
|
+
return this.config.session.store;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
//#endregion
|
|
48
|
+
export { SessionApplication as default };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { createSession } from
|
|
2
|
-
export default
|
|
1
|
+
import { createSession } from "koa-session";
|
|
2
|
+
export { createSession as default };
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
import { createSession } from
|
|
2
|
-
|
|
3
|
-
//#
|
|
1
|
+
import { createSession } from "koa-session";
|
|
2
|
+
|
|
3
|
+
//#region src/app/middleware/session.ts
|
|
4
|
+
var session_default = createSession;
|
|
5
|
+
|
|
6
|
+
//#endregion
|
|
7
|
+
export { session_default as default };
|
package/dist/app.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { Application, ILifecycleBoot } from "egg";
|
|
2
|
+
|
|
3
|
+
//#region src/app.d.ts
|
|
4
|
+
declare class AppBoot implements ILifecycleBoot {
|
|
5
|
+
private readonly app;
|
|
6
|
+
constructor(app: Application);
|
|
7
|
+
configWillLoad(): void;
|
|
6
8
|
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { AppBoot as default };
|
package/dist/app.js
CHANGED
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
import { SessionConfig } from "./config/config.default.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
//#
|
|
2
|
+
|
|
3
|
+
//#region src/app.ts
|
|
4
|
+
var AppBoot = class {
|
|
5
|
+
app;
|
|
6
|
+
constructor(app) {
|
|
7
|
+
this.app = app;
|
|
8
|
+
}
|
|
9
|
+
configWillLoad() {
|
|
10
|
+
const app = this.app;
|
|
11
|
+
SessionConfig.parse(app.config.session);
|
|
12
|
+
if (!app.config.session.httpOnly) app.coreLogger.warn("[@eggjs/session]: please set `config.session.httpOnly` to true. It is very dangerous if session can read by client JavaScript.");
|
|
13
|
+
app.config.coreMiddleware.push("session");
|
|
14
|
+
app.on("session:missed", ({ ctx, key }) => {
|
|
15
|
+
ctx.coreLogger.warn("[session][missed] key(%s)", key);
|
|
16
|
+
});
|
|
17
|
+
app.on("session:expired", ({ ctx, key, value }) => {
|
|
18
|
+
ctx.coreLogger.warn("[session][expired] key(%s) value(%j)", key, app.config.session.logValue ? value : "");
|
|
19
|
+
});
|
|
20
|
+
app.on("session:invalid", ({ ctx, key, value }) => {
|
|
21
|
+
ctx.coreLogger.warn("[session][invalid] key(%s) value(%j)", key, app.config.session.logValue ? value : "");
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
export { AppBoot as default };
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { SessionOptions } from "koa-session";
|
|
2
|
+
import z from "zod";
|
|
3
|
+
|
|
4
|
+
//#region src/config/config.default.d.ts
|
|
5
|
+
declare const SessionConfig: z.ZodType<typeof SessionOptions._type & {
|
|
6
|
+
logValue: boolean;
|
|
5
7
|
}>;
|
|
6
|
-
|
|
8
|
+
type SessionConfig = z.infer<typeof SessionConfig>;
|
|
7
9
|
declare const config: {
|
|
8
|
-
|
|
10
|
+
session: SessionConfig;
|
|
9
11
|
};
|
|
10
|
-
|
|
12
|
+
//#endregion
|
|
13
|
+
export { SessionConfig, config as default };
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
const config = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
import { SessionOptions } from "koa-session";
|
|
2
|
+
import z from "zod";
|
|
3
|
+
|
|
4
|
+
//#region src/config/config.default.ts
|
|
5
|
+
const SessionConfig = SessionOptions.extend({ logValue: z.boolean().default(true) });
|
|
6
|
+
const config = { session: SessionConfig.parse({
|
|
7
|
+
maxAge: 24 * 3600 * 1e3,
|
|
8
|
+
key: "EGG_SESS",
|
|
9
|
+
httpOnly: true,
|
|
10
|
+
encrypt: true
|
|
11
|
+
}) };
|
|
12
|
+
var config_default_default = config;
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
export { SessionConfig, config_default_default as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
1
|
+
import { SessionConfig } from "./config/config.default.js";
|
|
2
|
+
import "./types.js";
|
|
3
|
+
import { EggPluginFactory } from "egg";
|
|
4
|
+
|
|
5
|
+
//#region src/index.d.ts
|
|
4
6
|
declare const _default: EggPluginFactory;
|
|
5
|
-
|
|
7
|
+
//#endregion
|
|
8
|
+
export { SessionConfig, _default as default };
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import { definePluginFactory } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { SessionConfig } from "./config/config.default.js";
|
|
2
|
+
import { definePluginFactory } from "egg";
|
|
3
|
+
|
|
4
|
+
//#region src/index.ts
|
|
5
|
+
var src_default = definePluginFactory({
|
|
6
|
+
name: "session",
|
|
7
|
+
enable: true,
|
|
8
|
+
path: import.meta.dirname
|
|
8
9
|
});
|
|
9
|
-
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
export { SessionConfig, src_default as default };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { SessionConfig } from "./config/config.default.js";
|
|
2
|
+
import { SessionStore, SessionStoreOrAppSessionStoreClass } from "./app/extend/application.js";
|
|
3
|
+
|
|
4
|
+
//#region src/types.d.ts
|
|
5
|
+
declare module "egg" {
|
|
6
|
+
interface EggAppConfig {
|
|
7
|
+
session: SessionConfig;
|
|
8
|
+
}
|
|
9
|
+
interface Application {
|
|
10
|
+
set sessionStore(store: SessionStoreOrAppSessionStoreClass | null | undefined);
|
|
11
|
+
get sessionStore(): SessionStore | undefined;
|
|
12
|
+
}
|
|
13
|
+
}
|
package/dist/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export {};
|
|
2
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvdHlwZXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiJ9
|
|
1
|
+
export { };
|
package/package.json
CHANGED
|
@@ -1,28 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eggjs/session",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.36",
|
|
4
4
|
"description": "session plugin for egg",
|
|
5
|
-
"repository": {
|
|
6
|
-
"type": "git",
|
|
7
|
-
"url": "git://github.com/eggjs/egg.git",
|
|
8
|
-
"directory": "plugins/session"
|
|
9
|
-
},
|
|
10
|
-
"homepage": "https://github.com/eggjs/egg/tree/next/plugins/session#readme",
|
|
11
|
-
"bugs": {
|
|
12
|
-
"url": "https://github.com/eggjs/egg/issues"
|
|
13
|
-
},
|
|
14
|
-
"author": "dead_horse",
|
|
15
5
|
"keywords": [
|
|
6
|
+
"cookie",
|
|
16
7
|
"egg",
|
|
17
8
|
"egg-plugin",
|
|
18
9
|
"eggPlugin",
|
|
19
|
-
"session"
|
|
20
|
-
"cookie"
|
|
10
|
+
"session"
|
|
21
11
|
],
|
|
22
|
-
"
|
|
23
|
-
|
|
12
|
+
"homepage": "https://github.com/eggjs/egg/tree/next/plugins/session#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/eggjs/egg/issues"
|
|
15
|
+
},
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"author": "dead_horse",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/eggjs/egg.git",
|
|
21
|
+
"directory": "plugins/session"
|
|
24
22
|
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
25
26
|
"type": "module",
|
|
27
|
+
"main": "./dist/index.js",
|
|
28
|
+
"module": "./dist/index.js",
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
26
30
|
"exports": {
|
|
27
31
|
".": "./dist/index.js",
|
|
28
32
|
"./app": "./dist/app.js",
|
|
@@ -39,31 +43,21 @@
|
|
|
39
43
|
"koa-session": "^7.0.2",
|
|
40
44
|
"zod": "^3.24.1"
|
|
41
45
|
},
|
|
42
|
-
"peerDependencies": {
|
|
43
|
-
"egg": "4.1.0-beta.34"
|
|
44
|
-
},
|
|
45
46
|
"devDependencies": {
|
|
46
|
-
"@types/node": "^24.
|
|
47
|
-
"tsdown": "0.15.11",
|
|
47
|
+
"@types/node": "^24.10.2",
|
|
48
48
|
"typescript": "^5.9.3",
|
|
49
|
-
"
|
|
50
|
-
"@eggjs/
|
|
51
|
-
"@eggjs/redis": "4.0.0-beta.
|
|
52
|
-
"
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
"@eggjs/mock": "7.0.0-beta.36",
|
|
50
|
+
"@eggjs/supertest": "9.0.0-beta.36",
|
|
51
|
+
"@eggjs/redis": "4.0.0-beta.36",
|
|
52
|
+
"egg": "4.1.0-beta.36"
|
|
53
|
+
},
|
|
54
|
+
"peerDependencies": {
|
|
55
|
+
"egg": "4.1.0-beta.36"
|
|
56
|
+
},
|
|
57
|
+
"engines": {
|
|
58
|
+
"node": ">= 22.18.0"
|
|
55
59
|
},
|
|
56
|
-
"files": [
|
|
57
|
-
"dist"
|
|
58
|
-
],
|
|
59
|
-
"main": "./dist/index.js",
|
|
60
|
-
"module": "./dist/index.js",
|
|
61
|
-
"types": "./dist/index.d.ts",
|
|
62
60
|
"scripts": {
|
|
63
|
-
"
|
|
64
|
-
"typecheck": "tsc --noEmit",
|
|
65
|
-
"lint": "oxlint --type-aware",
|
|
66
|
-
"lint:fix": "npm run lint -- --fix",
|
|
67
|
-
"test": "npm run lint:fix && vitest"
|
|
61
|
+
"typecheck": "tsgo --noEmit"
|
|
68
62
|
}
|
|
69
63
|
}
|