jcc-express-mvc 1.8.7 → 1.8.21
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/Core/index.d.ts +4 -0
- package/Core/index.d.ts.map +1 -1
- package/Core/index.js +5 -0
- package/__tests__/Job.test.d.ts +2 -0
- package/__tests__/Job.test.d.ts.map +1 -0
- package/__tests__/Job.test.js +205 -0
- package/__tests__/MySqlSchemaBlueprint.test.d.ts +2 -0
- package/__tests__/MySqlSchemaBlueprint.test.d.ts.map +1 -0
- package/__tests__/MySqlSchemaBlueprint.test.js +55 -0
- package/__tests__/PostgresTranslator.test.d.ts +2 -0
- package/__tests__/PostgresTranslator.test.d.ts.map +1 -0
- package/__tests__/PostgresTranslator.test.js +82 -0
- package/__tests__/SQLiteTranslator.test.d.ts +2 -0
- package/__tests__/SQLiteTranslator.test.d.ts.map +1 -0
- package/__tests__/SQLiteTranslator.test.js +125 -0
- package/__tests__/SchemaAlterBlueprint.test.d.ts +2 -0
- package/__tests__/SchemaAlterBlueprint.test.d.ts.map +1 -0
- package/__tests__/SchemaAlterBlueprint.test.js +35 -0
- package/global.d.ts +3 -1
- package/index.d.ts +28 -3
- package/index.d.ts.map +1 -1
- package/index.js +33 -75
- package/lib/Application/Application.d.ts.map +1 -1
- package/lib/Application/Application.js +2 -2
- package/lib/Application/ApplicationBuilder.d.ts.map +1 -1
- package/lib/Application/ApplicationBuilder.js +22 -11
- package/lib/Auth/AuthMiddleware.d.ts.map +1 -1
- package/lib/Auth/AuthMiddleware.js +29 -12
- package/lib/Auth/index.d.ts +17 -3
- package/lib/Auth/index.d.ts.map +1 -1
- package/lib/Auth/index.js +128 -26
- package/lib/Auth/loginRateLimit.d.ts +6 -0
- package/lib/Auth/loginRateLimit.d.ts.map +1 -0
- package/lib/Auth/loginRateLimit.js +25 -0
- package/lib/Auth/refreshTokenStore.d.ts +24 -0
- package/lib/Auth/refreshTokenStore.d.ts.map +1 -0
- package/lib/Auth/refreshTokenStore.js +46 -0
- package/lib/Command-Line/DBCommand.d.ts.map +1 -1
- package/lib/Command-Line/DBCommand.js +9 -3
- package/lib/Command-Line/KeyGenerateCommand.d.ts +6 -0
- package/lib/Command-Line/KeyGenerateCommand.d.ts.map +1 -0
- package/lib/Command-Line/KeyGenerateCommand.js +47 -0
- package/lib/Command-Line/MakeCommand.d.ts +1 -0
- package/lib/Command-Line/MakeCommand.d.ts.map +1 -1
- package/lib/Command-Line/MakeCommand.js +36 -32
- package/lib/Command-Line/NodeArtisanCommand.d.ts +2 -0
- package/lib/Command-Line/NodeArtisanCommand.d.ts.map +1 -1
- package/lib/Command-Line/NodeArtisanCommand.js +24 -6
- package/lib/Command-Line/NodeTinker/Tinker.d.ts +5 -2
- package/lib/Command-Line/NodeTinker/Tinker.d.ts.map +1 -1
- package/lib/Command-Line/NodeTinker/Tinker.js +13 -3
- package/lib/Command-Line/WatchCommand.d.ts +29 -0
- package/lib/Command-Line/WatchCommand.d.ts.map +1 -0
- package/lib/Command-Line/WatchCommand.js +234 -0
- package/lib/Command-Line/files/Models.d.ts.map +1 -1
- package/lib/Command-Line/files/Models.js +67 -0
- package/lib/Console/Command.d.ts +18 -0
- package/lib/Console/Command.d.ts.map +1 -1
- package/lib/Console/Command.js +29 -0
- package/lib/Container/index.d.ts.map +1 -1
- package/lib/Container/index.js +22 -8
- package/lib/Database/Database.d.ts +21 -0
- package/lib/Database/Database.d.ts.map +1 -0
- package/lib/Database/Database.js +55 -0
- package/lib/Database/DatabaseServiceProvider.d.ts +22 -0
- package/lib/Database/DatabaseServiceProvider.d.ts.map +1 -0
- package/lib/Database/DatabaseServiceProvider.js +50 -0
- package/lib/Database/Drivers/KnexDriver.d.ts +13 -0
- package/lib/Database/Drivers/KnexDriver.d.ts.map +1 -0
- package/lib/Database/Drivers/KnexDriver.js +29 -0
- package/lib/Database/Drivers/MongooseDriver.d.ts +20 -0
- package/lib/Database/Drivers/MongooseDriver.d.ts.map +1 -0
- package/lib/Database/Drivers/MongooseDriver.js +57 -0
- package/lib/Database/Drivers/SequelizeDriver.d.ts +24 -0
- package/lib/Database/Drivers/SequelizeDriver.d.ts.map +1 -0
- package/lib/Database/Drivers/SequelizeDriver.js +82 -0
- package/lib/Database/index.d.ts +7 -0
- package/lib/Database/index.d.ts.map +1 -0
- package/lib/Database/index.js +11 -0
- package/lib/Database/interface.d.ts +14 -0
- package/lib/Database/interface.d.ts.map +1 -0
- package/lib/Database/interface.js +2 -0
- package/lib/Database/type.d.ts +18 -0
- package/lib/Database/type.d.ts.map +1 -0
- package/lib/Database/type.js +2 -0
- package/lib/Error/DisplayErrorCode.d.ts.map +1 -1
- package/lib/Error/DisplayErrorCode.js +27 -17
- package/lib/Error/MissMatchTokenException/index.d.ts +4 -0
- package/lib/Error/MissMatchTokenException/index.d.ts.map +1 -0
- package/lib/Error/MissMatchTokenException/index.js +9 -0
- package/lib/Error/SocialiteAuthError/SocialiteAuthError.d.ts +9 -0
- package/lib/Error/SocialiteAuthError/SocialiteAuthError.d.ts.map +1 -0
- package/lib/Error/SocialiteAuthError/SocialiteAuthError.js +17 -0
- package/lib/Global/helpers.d.ts.map +1 -1
- package/lib/Global/helpers.js +7 -6
- package/lib/Http/index.d.ts +3 -1
- package/lib/Http/index.d.ts.map +1 -1
- package/lib/Http/index.js +26 -5
- package/lib/Interface/index.d.ts +17 -3
- package/lib/Interface/index.d.ts.map +1 -1
- package/lib/Jcc-eloquent/lib/Builder.d.ts +12 -1
- package/lib/Jcc-eloquent/lib/Builder.d.ts.map +1 -1
- package/lib/Jcc-eloquent/lib/Builder.js +119 -5
- package/lib/Jcc-eloquent/lib/Database/index.d.ts.map +1 -1
- package/lib/Jcc-eloquent/lib/Database/index.js +2 -1
- package/lib/Jcc-eloquent/lib/Interfaces/index.d.ts +37 -2
- package/lib/Jcc-eloquent/lib/Interfaces/index.d.ts.map +1 -1
- package/lib/Jcc-eloquent/lib/Migration.d.ts +6 -0
- package/lib/Jcc-eloquent/lib/Migration.d.ts.map +1 -1
- package/lib/Jcc-eloquent/lib/Migration.js +24 -2
- package/lib/Jcc-eloquent/lib/Model.d.ts +24 -7
- package/lib/Jcc-eloquent/lib/Model.d.ts.map +1 -1
- package/lib/Jcc-eloquent/lib/Model.js +35 -2
- package/lib/Jcc-eloquent/lib/QueryBuilder.d.ts +2 -1
- package/lib/Jcc-eloquent/lib/QueryBuilder.d.ts.map +1 -1
- package/lib/Jcc-eloquent/lib/QueryBuilder.js +10 -1
- package/lib/Jcc-eloquent/lib/Rollback.d.ts.map +1 -1
- package/lib/Jcc-eloquent/lib/Rollback.js +9 -2
- package/lib/Jcc-eloquent/lib/Schema/BaseSchemaEntity/index.d.ts.map +1 -1
- package/lib/Jcc-eloquent/lib/Schema/BaseSchemaEntity/index.js +3 -3
- package/lib/Jcc-eloquent/lib/Schema/BluePrint/index.d.ts +6 -2
- package/lib/Jcc-eloquent/lib/Schema/BluePrint/index.d.ts.map +1 -1
- package/lib/Jcc-eloquent/lib/Schema/BluePrint/index.js +41 -12
- package/lib/Jcc-eloquent/lib/Schema/Translator/Sqlite.d.ts.map +1 -1
- package/lib/Jcc-eloquent/lib/Schema/Translator/Sqlite.js +21 -3
- package/lib/Jcc-eloquent/lib/Schema/Translator/postgres.d.ts +1 -0
- package/lib/Jcc-eloquent/lib/Schema/Translator/postgres.d.ts.map +1 -1
- package/lib/Jcc-eloquent/lib/Schema/Translator/postgres.js +70 -14
- package/lib/Jcc-eloquent/lib/Schema/index.d.ts +12 -0
- package/lib/Jcc-eloquent/lib/Schema/index.d.ts.map +1 -1
- package/lib/Jcc-eloquent/lib/Schema/index.js +27 -6
- package/lib/Jcc-eloquent/lib/utils/index.d.ts +13 -0
- package/lib/Jcc-eloquent/lib/utils/index.d.ts.map +1 -1
- package/lib/Jcc-eloquent/lib/utils/index.js +62 -0
- package/lib/Middleware/index.d.ts +1 -0
- package/lib/Middleware/index.d.ts.map +1 -1
- package/lib/Middleware/index.js +20 -8
- package/lib/Model/Sequelize.d.ts +3 -0
- package/lib/Model/Sequelize.d.ts.map +1 -0
- package/lib/Model/Sequelize.js +6 -0
- package/lib/Providers/RouteServiceProvider.d.ts.map +1 -1
- package/lib/Providers/RouteServiceProvider.js +3 -0
- package/lib/Providers/SessionServiceProvider.d.ts +12 -0
- package/lib/Providers/SessionServiceProvider.d.ts.map +1 -0
- package/lib/Providers/SessionServiceProvider.js +47 -0
- package/lib/Queue/Controllers/QueueControllers.d.ts +31 -0
- package/lib/Queue/Controllers/QueueControllers.d.ts.map +1 -0
- package/lib/Queue/Controllers/QueueControllers.js +126 -0
- package/lib/Queue/Drivers/DatabaseDriver.d.ts +6 -1
- package/lib/Queue/Drivers/DatabaseDriver.d.ts.map +1 -1
- package/lib/Queue/Drivers/DatabaseDriver.js +76 -21
- package/lib/Queue/Drivers/MemoryDriver.d.ts +17 -6
- package/lib/Queue/Drivers/MemoryDriver.d.ts.map +1 -1
- package/lib/Queue/Drivers/MemoryDriver.js +323 -14
- package/lib/Queue/Drivers/RedisDriver.d.ts +48 -0
- package/lib/Queue/Drivers/RedisDriver.d.ts.map +1 -0
- package/lib/Queue/Drivers/RedisDriver.js +533 -0
- package/lib/Queue/Job.d.ts +8 -0
- package/lib/Queue/Job.d.ts.map +1 -1
- package/lib/Queue/Job.js +25 -1
- package/lib/Queue/JobsLogger.d.ts.map +1 -1
- package/lib/Queue/JobsLogger.js +6 -3
- package/lib/Queue/Queue.d.ts +17 -0
- package/lib/Queue/Queue.d.ts.map +1 -1
- package/lib/Queue/Queue.js +146 -11
- package/lib/Queue/QueueServiceProvider.d.ts +6 -0
- package/lib/Queue/QueueServiceProvider.d.ts.map +1 -0
- package/lib/Queue/QueueServiceProvider.js +18 -0
- package/lib/Queue/Route/web.d.ts +2 -0
- package/lib/Queue/Route/web.d.ts.map +1 -0
- package/lib/Queue/Route/web.js +16 -0
- package/lib/Queue/index.d.ts +1 -0
- package/lib/Queue/index.d.ts.map +1 -1
- package/lib/Queue/index.js +3 -0
- package/lib/Queue/interface.d.ts +25 -0
- package/lib/Queue/interface.d.ts.map +1 -1
- package/lib/Queue/middleware/queueDashboardGuard.d.ts +7 -0
- package/lib/Queue/middleware/queueDashboardGuard.d.ts.map +1 -0
- package/lib/Queue/middleware/queueDashboardGuard.js +43 -0
- package/lib/Queue/type.d.ts +12 -1
- package/lib/Queue/type.d.ts.map +1 -1
- package/lib/Response/index.d.ts.map +1 -1
- package/lib/Response/index.js +6 -1
- package/lib/Routes/Route.d.ts +2 -2
- package/lib/Routes/Route.d.ts.map +1 -1
- package/lib/Routes/RouteBuilder.d.ts +2 -2
- package/lib/Routes/RouteBuilder.d.ts.map +1 -1
- package/lib/Security/CsrfMiddleware.d.ts +37 -0
- package/lib/Security/CsrfMiddleware.d.ts.map +1 -0
- package/lib/Security/CsrfMiddleware.js +85 -0
- package/lib/Security/MethodSpoofingMiddleware.d.ts +36 -0
- package/lib/Security/MethodSpoofingMiddleware.d.ts.map +1 -0
- package/lib/Security/MethodSpoofingMiddleware.js +51 -0
- package/lib/Security/index.d.ts +5 -0
- package/lib/Security/index.d.ts.map +1 -0
- package/lib/Security/index.js +7 -0
- package/lib/Session/DatabaseSession.d.ts +9 -3
- package/lib/Session/DatabaseSession.d.ts.map +1 -1
- package/lib/Session/DatabaseSession.js +38 -36
- package/lib/Session/ExpressJccSession.d.ts +23 -0
- package/lib/Session/ExpressJccSession.d.ts.map +1 -0
- package/lib/Session/ExpressJccSession.js +110 -0
- package/lib/Session/RedisSession.d.ts +2 -2
- package/lib/Session/RedisSession.d.ts.map +1 -1
- package/lib/Session/RedisSession.js +19 -5
- package/lib/Session/SessionManager.d.ts +18 -4
- package/lib/Session/SessionManager.d.ts.map +1 -1
- package/lib/Session/SessionManager.js +53 -17
- package/lib/Socialite/AbstractProvider.d.ts +60 -0
- package/lib/Socialite/AbstractProvider.d.ts.map +1 -0
- package/lib/Socialite/AbstractProvider.js +136 -0
- package/lib/Socialite/Drivers/facebook/FacebookDriver.d.ts +9 -0
- package/lib/Socialite/Drivers/facebook/FacebookDriver.d.ts.map +1 -0
- package/lib/Socialite/Drivers/facebook/FacebookDriver.js +40 -0
- package/lib/Socialite/Drivers/facebook/FacebookProvider.d.ts +15 -0
- package/lib/Socialite/Drivers/facebook/FacebookProvider.d.ts.map +1 -0
- package/lib/Socialite/Drivers/facebook/FacebookProvider.js +28 -0
- package/lib/Socialite/Drivers/github/GitHubDriver.d.ts +9 -0
- package/lib/Socialite/Drivers/github/GitHubDriver.d.ts.map +1 -0
- package/lib/Socialite/Drivers/github/GitHubDriver.js +54 -0
- package/lib/Socialite/Drivers/github/GitHubProvider.d.ts +15 -0
- package/lib/Socialite/Drivers/github/GitHubProvider.d.ts.map +1 -0
- package/lib/Socialite/Drivers/github/GitHubProvider.js +28 -0
- package/lib/Socialite/Drivers/gitlab/GitLabDriver.d.ts +10 -0
- package/lib/Socialite/Drivers/gitlab/GitLabDriver.d.ts.map +1 -0
- package/lib/Socialite/Drivers/gitlab/GitLabDriver.js +37 -0
- package/lib/Socialite/Drivers/gitlab/GitLabProvider.d.ts +15 -0
- package/lib/Socialite/Drivers/gitlab/GitLabProvider.d.ts.map +1 -0
- package/lib/Socialite/Drivers/gitlab/GitLabProvider.js +28 -0
- package/lib/Socialite/Drivers/google/GoogleDriver.d.ts +9 -0
- package/lib/Socialite/Drivers/google/GoogleDriver.d.ts.map +1 -0
- package/lib/Socialite/Drivers/google/GoogleDriver.js +39 -0
- package/lib/Socialite/Drivers/google/GoogleProvider.d.ts +15 -0
- package/lib/Socialite/Drivers/google/GoogleProvider.d.ts.map +1 -0
- package/lib/Socialite/Drivers/google/GoogleProvider.js +28 -0
- package/lib/Socialite/Drivers/slack/SlackDriver.d.ts +9 -0
- package/lib/Socialite/Drivers/slack/SlackDriver.d.ts.map +1 -0
- package/lib/Socialite/Drivers/slack/SlackDriver.js +41 -0
- package/lib/Socialite/Drivers/slack/SlackProvider.d.ts +16 -0
- package/lib/Socialite/Drivers/slack/SlackProvider.d.ts.map +1 -0
- package/lib/Socialite/Drivers/slack/SlackProvider.js +37 -0
- package/lib/Socialite/Drivers/twitter/TwitterDriver.d.ts +9 -0
- package/lib/Socialite/Drivers/twitter/TwitterDriver.d.ts.map +1 -0
- package/lib/Socialite/Drivers/twitter/TwitterDriver.js +57 -0
- package/lib/Socialite/Drivers/twitter/TwitterProvider.d.ts +16 -0
- package/lib/Socialite/Drivers/twitter/TwitterProvider.d.ts.map +1 -0
- package/lib/Socialite/Drivers/twitter/TwitterProvider.js +38 -0
- package/lib/Socialite/SocialUser.d.ts +42 -0
- package/lib/Socialite/SocialUser.d.ts.map +1 -0
- package/lib/Socialite/SocialUser.js +116 -0
- package/lib/Socialite/Socialite.d.ts +13 -0
- package/lib/Socialite/Socialite.d.ts.map +1 -0
- package/lib/Socialite/Socialite.js +41 -0
- package/lib/Socialite/SocialiteProvider.d.ts +9 -0
- package/lib/Socialite/SocialiteProvider.d.ts.map +1 -0
- package/lib/Socialite/SocialiteProvider.js +15 -0
- package/lib/Socialite/config.d.ts +7 -0
- package/lib/Socialite/config.d.ts.map +1 -0
- package/lib/Socialite/config.js +44 -0
- package/lib/Socialite/constant.d.ts +18 -0
- package/lib/Socialite/constant.d.ts.map +1 -0
- package/lib/Socialite/constant.js +20 -0
- package/lib/Socialite/index.d.ts +13 -0
- package/lib/Socialite/index.d.ts.map +1 -0
- package/lib/Socialite/index.js +25 -0
- package/lib/Socialite/types.d.ts +13 -0
- package/lib/Socialite/types.d.ts.map +1 -0
- package/lib/Socialite/types.js +2 -0
- package/lib/Templating-engine/benchmark.d.ts +7 -0
- package/lib/Templating-engine/benchmark.d.ts.map +1 -0
- package/lib/Templating-engine/benchmark.js +44 -0
- package/lib/Templating-engine/engineHelper.d.ts +37 -8
- package/lib/Templating-engine/engineHelper.d.ts.map +1 -1
- package/lib/Templating-engine/engineHelper.js +203 -26
- package/lib/Templating-engine/errors.d.ts +15 -0
- package/lib/Templating-engine/errors.d.ts.map +1 -0
- package/lib/Templating-engine/errors.js +35 -0
- package/lib/Templating-engine/expressions.d.ts +24 -0
- package/lib/Templating-engine/expressions.d.ts.map +1 -1
- package/lib/Templating-engine/expressions.js +27 -5
- package/lib/Templating-engine/index.d.ts +87 -17
- package/lib/Templating-engine/index.d.ts.map +1 -1
- package/lib/Templating-engine/index.js +701 -96
- package/lib/Templating-engine/plugins.d.ts +30 -0
- package/lib/Templating-engine/plugins.d.ts.map +1 -0
- package/lib/Templating-engine/plugins.js +47 -0
- package/lib/Type/index.d.ts +1 -0
- package/lib/Type/index.d.ts.map +1 -1
- package/lib/Validation/Validator/CustomValidation.d.ts.map +1 -1
- package/lib/Validation/Validator/CustomValidation.js +2 -2
- package/lib/Validation/Validator/helper.d.ts.map +1 -1
- package/lib/Validation/Validator/helper.js +8 -1
- package/lib/util/index.d.ts +42 -1
- package/lib/util/index.d.ts.map +1 -1
- package/lib/util/index.js +154 -17
- package/package.json +1 -1
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.csrf = csrf;
|
|
7
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
8
|
+
const MissMatchTokenException_1 = require("../Error/MissMatchTokenException");
|
|
9
|
+
const UNSAFE_METHODS = new Set(["POST", "PUT", "PATCH", "DELETE"]);
|
|
10
|
+
function generateToken(length) {
|
|
11
|
+
return crypto_1.default.randomBytes(length).toString("hex");
|
|
12
|
+
}
|
|
13
|
+
function isExcluded(path, except) {
|
|
14
|
+
for (const pattern of except) {
|
|
15
|
+
if (typeof pattern === "string") {
|
|
16
|
+
if (path === pattern || path.startsWith(pattern + "/"))
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
else if (pattern.test(path)) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* CSRF protection middleware.
|
|
27
|
+
*
|
|
28
|
+
* Generates a per-session token and validates it on unsafe HTTP methods.
|
|
29
|
+
* The token is available via:
|
|
30
|
+
* - `req.csrfToken()` (programmatic)
|
|
31
|
+
* - `res.locals._token` (for templates / @csrf directive)
|
|
32
|
+
*
|
|
33
|
+
* Usage in Kernel:
|
|
34
|
+
* ```ts
|
|
35
|
+
* import { csrf } from "../../jcc-express-mvc";
|
|
36
|
+
* export class Kernel {
|
|
37
|
+
* public middlewares = [
|
|
38
|
+
* // ...session, cookieParser, etc.
|
|
39
|
+
* csrf(), // default options
|
|
40
|
+
* csrf({ except: ["/webhooks"] }), // with exclusions
|
|
41
|
+
* ];
|
|
42
|
+
* }
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
function csrf(options = {}) {
|
|
46
|
+
const { except = [], sessionKey = "_csrf_token", fieldName = "_token", headerName = "x-csrf-token", tokenLength = 32, skipApi = true, } = options;
|
|
47
|
+
return (req, res, next) => {
|
|
48
|
+
const session = req.session;
|
|
49
|
+
if (!session) {
|
|
50
|
+
console.warn("[CSRF] No session found – make sure express-session is registered before csrf().");
|
|
51
|
+
return next();
|
|
52
|
+
}
|
|
53
|
+
// Ensure a token exists in the session
|
|
54
|
+
if (!session[sessionKey]) {
|
|
55
|
+
session[sessionKey] = generateToken(tokenLength);
|
|
56
|
+
}
|
|
57
|
+
const token = session[sessionKey];
|
|
58
|
+
// Expose token to templates and programmatically
|
|
59
|
+
res.locals._token = token;
|
|
60
|
+
req.csrfToken = () => token;
|
|
61
|
+
// Read-safe methods pass through
|
|
62
|
+
if (!UNSAFE_METHODS.has(req.method.toUpperCase()))
|
|
63
|
+
return next();
|
|
64
|
+
// Skip API routes
|
|
65
|
+
if (skipApi && req.path.startsWith("/api"))
|
|
66
|
+
return next();
|
|
67
|
+
// Check exclusions
|
|
68
|
+
if (isExcluded(req.path, except))
|
|
69
|
+
return next();
|
|
70
|
+
// Validate token
|
|
71
|
+
const submitted = req.body?.[fieldName] ||
|
|
72
|
+
req.headers[headerName] ||
|
|
73
|
+
req.headers[headerName.toLowerCase()];
|
|
74
|
+
if (!submitted) {
|
|
75
|
+
throw new MissMatchTokenException_1.MissMatchTokenException("CSRF token mismatch.");
|
|
76
|
+
}
|
|
77
|
+
const submittedBuf = Buffer.from(String(submitted), "utf8");
|
|
78
|
+
const tokenBuf = Buffer.from(token, "utf8");
|
|
79
|
+
if (submittedBuf.length !== tokenBuf.length ||
|
|
80
|
+
!crypto_1.default.timingSafeEqual(submittedBuf, tokenBuf)) {
|
|
81
|
+
throw new MissMatchTokenException_1.MissMatchTokenException("CSRF token mismatch.");
|
|
82
|
+
}
|
|
83
|
+
next();
|
|
84
|
+
};
|
|
85
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { AppNext, AppRequest, AppResponse } from "../Interface";
|
|
2
|
+
export interface MethodSpoofingOptions {
|
|
3
|
+
/** Form field name that contains the spoofed method. Default: "_method" */
|
|
4
|
+
fieldName?: string;
|
|
5
|
+
/** Also check the X-HTTP-Method-Override header. Default: true */
|
|
6
|
+
checkHeader?: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Method spoofing middleware.
|
|
10
|
+
*
|
|
11
|
+
* HTML forms only support GET and POST. This middleware allows overriding
|
|
12
|
+
* the HTTP method via a hidden `_method` form field or the
|
|
13
|
+
* `X-HTTP-Method-Override` header.
|
|
14
|
+
*
|
|
15
|
+
* Usage in Kernel:
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { methodSpoofing } from "../../jcc-express-mvc";
|
|
18
|
+
* export class Kernel {
|
|
19
|
+
* public middlewares = [
|
|
20
|
+
* // ...
|
|
21
|
+
* methodSpoofing(),
|
|
22
|
+
* ];
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* In a Blade template:
|
|
27
|
+
* ```html
|
|
28
|
+
* <form method="POST" action="/users/1">
|
|
29
|
+
* @csrf
|
|
30
|
+
* @method('DELETE')
|
|
31
|
+
* <button type="submit">Delete</button>
|
|
32
|
+
* </form>
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare function methodSpoofing(options?: MethodSpoofingOptions): (req: AppRequest, _res: AppResponse, next: AppNext) => void;
|
|
36
|
+
//# sourceMappingURL=MethodSpoofingMiddleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MethodSpoofingMiddleware.d.ts","sourceRoot":"","sources":["../../../jcc-express-mvc/lib/Security/MethodSpoofingMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhE,MAAM,WAAW,qBAAqB;IACpC,2EAA2E;IAC3E,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kEAAkE;IAClE,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAID;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,cAAc,CAAC,OAAO,GAAE,qBAA0B,IAGxD,KAAK,UAAU,EAAE,MAAM,WAAW,EAAE,MAAM,OAAO,UAoB1D"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.methodSpoofing = methodSpoofing;
|
|
4
|
+
const ALLOWED_METHODS = new Set(["PUT", "PATCH", "DELETE"]);
|
|
5
|
+
/**
|
|
6
|
+
* Method spoofing middleware.
|
|
7
|
+
*
|
|
8
|
+
* HTML forms only support GET and POST. This middleware allows overriding
|
|
9
|
+
* the HTTP method via a hidden `_method` form field or the
|
|
10
|
+
* `X-HTTP-Method-Override` header.
|
|
11
|
+
*
|
|
12
|
+
* Usage in Kernel:
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { methodSpoofing } from "../../jcc-express-mvc";
|
|
15
|
+
* export class Kernel {
|
|
16
|
+
* public middlewares = [
|
|
17
|
+
* // ...
|
|
18
|
+
* methodSpoofing(),
|
|
19
|
+
* ];
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* In a Blade template:
|
|
24
|
+
* ```html
|
|
25
|
+
* <form method="POST" action="/users/1">
|
|
26
|
+
* @csrf
|
|
27
|
+
* @method('DELETE')
|
|
28
|
+
* <button type="submit">Delete</button>
|
|
29
|
+
* </form>
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
function methodSpoofing(options = {}) {
|
|
33
|
+
const { fieldName = "_method", checkHeader = true } = options;
|
|
34
|
+
return (req, _res, next) => {
|
|
35
|
+
if (req.method.toUpperCase() !== "POST")
|
|
36
|
+
return next();
|
|
37
|
+
const override = req.body?.[fieldName] ||
|
|
38
|
+
(checkHeader && req.headers["x-http-method-override"]);
|
|
39
|
+
if (override) {
|
|
40
|
+
const method = String(override).toUpperCase();
|
|
41
|
+
if (ALLOWED_METHODS.has(method)) {
|
|
42
|
+
req.method = method;
|
|
43
|
+
// Clean up the _method field so it doesn't leak into controller data
|
|
44
|
+
if (req.body?.[fieldName]) {
|
|
45
|
+
delete req.body[fieldName];
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
next();
|
|
50
|
+
};
|
|
51
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../jcc-express-mvc/lib/Security/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,YAAY,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,YAAY,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.methodSpoofing = exports.csrf = void 0;
|
|
4
|
+
var CsrfMiddleware_1 = require("./CsrfMiddleware");
|
|
5
|
+
Object.defineProperty(exports, "csrf", { enumerable: true, get: function () { return CsrfMiddleware_1.csrf; } });
|
|
6
|
+
var MethodSpoofingMiddleware_1 = require("./MethodSpoofingMiddleware");
|
|
7
|
+
Object.defineProperty(exports, "methodSpoofing", { enumerable: true, get: function () { return MethodSpoofingMiddleware_1.methodSpoofing; } });
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import { SessionData, SessionStore } from "../Interface";
|
|
2
|
+
/**
|
|
3
|
+
* Database session store (Laravel-style `sessions` table).
|
|
4
|
+
* Requires Jcc-eloquent / Knex (`DB`) to be configured. Not for Sequelize-only apps.
|
|
5
|
+
*
|
|
6
|
+
* Expected columns: `id` (varchar, session id), `payload` (longtext), `last_activity` (int, unix).
|
|
7
|
+
*/
|
|
2
8
|
export declare class DatabaseSessionStore implements SessionStore {
|
|
3
|
-
private tableName;
|
|
4
|
-
|
|
9
|
+
private readonly tableName;
|
|
10
|
+
constructor(tableName?: string);
|
|
5
11
|
get(sessionId: string): Promise<SessionData | null>;
|
|
6
12
|
set(sessionId: string, data: SessionData, maxAge?: number): Promise<void>;
|
|
7
13
|
destroy(sessionId: string): Promise<void>;
|
|
8
14
|
touch(sessionId: string, maxAge?: number): Promise<void>;
|
|
9
|
-
clear(): Promise<
|
|
15
|
+
clear(): Promise<void>;
|
|
10
16
|
}
|
|
11
17
|
//# sourceMappingURL=DatabaseSession.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DatabaseSession.d.ts","sourceRoot":"","sources":["../../../jcc-express-mvc/lib/Session/DatabaseSession.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEzD,qBAAa,oBAAqB,YAAW,YAAY;
|
|
1
|
+
{"version":3,"file":"DatabaseSession.d.ts","sourceRoot":"","sources":["../../../jcc-express-mvc/lib/Session/DatabaseSession.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEzD;;;;;GAKG;AACH,qBAAa,oBAAqB,YAAW,YAAY;IAC3C,OAAO,CAAC,QAAQ,CAAC,SAAS;gBAAT,SAAS,GAAE,MAAmB;IAErD,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAenD,GAAG,CACP,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,WAAW,EACjB,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,IAAI,CAAC;IA2BV,OAAO,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQzC,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAYxD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAO7B"}
|
|
@@ -2,36 +2,25 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DatabaseSessionStore = void 0;
|
|
4
4
|
const Jcc_eloquent_1 = require("../Jcc-eloquent");
|
|
5
|
+
/**
|
|
6
|
+
* Database session store (Laravel-style `sessions` table).
|
|
7
|
+
* Requires Jcc-eloquent / Knex (`DB`) to be configured. Not for Sequelize-only apps.
|
|
8
|
+
*
|
|
9
|
+
* Expected columns: `id` (varchar, session id), `payload` (longtext), `last_activity` (int, unix).
|
|
10
|
+
*/
|
|
5
11
|
class DatabaseSessionStore {
|
|
6
|
-
constructor() {
|
|
7
|
-
this.tableName =
|
|
8
|
-
}
|
|
9
|
-
async createTable() {
|
|
10
|
-
const sqlQuery = Jcc_eloquent_1.Schema.create("sessions", function (table) {
|
|
11
|
-
table.id();
|
|
12
|
-
table.string("uuid");
|
|
13
|
-
table.foreignId("user_id").nullable().index();
|
|
14
|
-
table.string("ip_address", 45).nullable();
|
|
15
|
-
table.text("user_agent").nullable();
|
|
16
|
-
table.text("payload");
|
|
17
|
-
table.integer("last_activity").index();
|
|
18
|
-
table.timestamps();
|
|
19
|
-
});
|
|
20
|
-
try {
|
|
21
|
-
await Jcc_eloquent_1.DB.runQuery(sqlQuery);
|
|
22
|
-
}
|
|
23
|
-
catch (error) {
|
|
24
|
-
console.error("Failed to create sessions table:", error);
|
|
25
|
-
}
|
|
12
|
+
constructor(tableName = "sessions") {
|
|
13
|
+
this.tableName = tableName;
|
|
26
14
|
}
|
|
27
15
|
async get(sessionId) {
|
|
28
16
|
try {
|
|
29
|
-
const
|
|
17
|
+
const row = (await Jcc_eloquent_1.DB.table(this.tableName)
|
|
30
18
|
.select("payload")
|
|
31
|
-
.where("
|
|
32
|
-
.where("expires", ">", Date.now())
|
|
19
|
+
.where("id", sessionId)
|
|
33
20
|
.first());
|
|
34
|
-
|
|
21
|
+
if (!row?.payload)
|
|
22
|
+
return null;
|
|
23
|
+
return JSON.parse(row.payload);
|
|
35
24
|
}
|
|
36
25
|
catch (error) {
|
|
37
26
|
console.error("Failed to get session from database:", error);
|
|
@@ -40,13 +29,25 @@ class DatabaseSessionStore {
|
|
|
40
29
|
}
|
|
41
30
|
async set(sessionId, data, maxAge) {
|
|
42
31
|
try {
|
|
43
|
-
const
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
32
|
+
const payload = JSON.stringify(data);
|
|
33
|
+
const lastActivity = Math.floor(Date.now() / 1000);
|
|
34
|
+
const existing = await Jcc_eloquent_1.DB.table(this.tableName)
|
|
35
|
+
.where("id", sessionId)
|
|
36
|
+
.first();
|
|
37
|
+
if (existing) {
|
|
38
|
+
await Jcc_eloquent_1.DB.table(this.tableName).where("id", sessionId).update({
|
|
39
|
+
payload,
|
|
40
|
+
last_activity: lastActivity,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
await Jcc_eloquent_1.DB.table(this.tableName).insert({
|
|
45
|
+
id: sessionId,
|
|
46
|
+
payload,
|
|
47
|
+
last_activity: lastActivity,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
void maxAge;
|
|
50
51
|
}
|
|
51
52
|
catch (error) {
|
|
52
53
|
console.error("Failed to set session in database:", error);
|
|
@@ -54,7 +55,7 @@ class DatabaseSessionStore {
|
|
|
54
55
|
}
|
|
55
56
|
async destroy(sessionId) {
|
|
56
57
|
try {
|
|
57
|
-
await Jcc_eloquent_1.DB.table(this.tableName).where("
|
|
58
|
+
await Jcc_eloquent_1.DB.table(this.tableName).where("id", sessionId).delete();
|
|
58
59
|
}
|
|
59
60
|
catch (error) {
|
|
60
61
|
console.error("Failed to destroy session in database:", error);
|
|
@@ -62,10 +63,11 @@ class DatabaseSessionStore {
|
|
|
62
63
|
}
|
|
63
64
|
async touch(sessionId, maxAge) {
|
|
64
65
|
try {
|
|
65
|
-
const
|
|
66
|
+
const lastActivity = Math.floor(Date.now() / 1000);
|
|
66
67
|
await Jcc_eloquent_1.DB.table(this.tableName)
|
|
67
|
-
.where("
|
|
68
|
-
.update({
|
|
68
|
+
.where("id", sessionId)
|
|
69
|
+
.update({ last_activity: lastActivity });
|
|
70
|
+
void maxAge;
|
|
69
71
|
}
|
|
70
72
|
catch (error) {
|
|
71
73
|
console.error("Failed to touch session in database:", error);
|
|
@@ -73,7 +75,7 @@ class DatabaseSessionStore {
|
|
|
73
75
|
}
|
|
74
76
|
async clear() {
|
|
75
77
|
try {
|
|
76
|
-
|
|
78
|
+
await Jcc_eloquent_1.DB.table(this.tableName).delete();
|
|
77
79
|
}
|
|
78
80
|
catch (error) {
|
|
79
81
|
console.error("Failed to clear sessions from database:", error);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { AppRequest } from "../Interface";
|
|
2
|
+
import type { SessionData } from "../Interface";
|
|
3
|
+
import type { Session } from "./index";
|
|
4
|
+
export declare class ExpressJccSession {
|
|
5
|
+
private readonly req;
|
|
6
|
+
constructor(req: AppRequest);
|
|
7
|
+
flash(key: string, value: any): void;
|
|
8
|
+
getFlash(key: string, defaultValue?: any): any;
|
|
9
|
+
get(key: string, defaultValue?: any): any;
|
|
10
|
+
put(key: string, value: any): void;
|
|
11
|
+
has(key: string): boolean;
|
|
12
|
+
forget(key: string): void;
|
|
13
|
+
all(): SessionData;
|
|
14
|
+
only(keys: string[]): SessionData;
|
|
15
|
+
except(keys: string[]): SessionData;
|
|
16
|
+
flush(): void;
|
|
17
|
+
load(): Promise<void>;
|
|
18
|
+
save(): Promise<void>;
|
|
19
|
+
regenerate(): Promise<void>;
|
|
20
|
+
getId(): string;
|
|
21
|
+
}
|
|
22
|
+
export declare function createExpressJccSession(req: AppRequest): Session;
|
|
23
|
+
//# sourceMappingURL=ExpressJccSession.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExpressJccSession.d.ts","sourceRoot":"","sources":["../../../jcc-express-mvc/lib/Session/ExpressJccSession.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAWvC,qBAAa,iBAAiB;IAChB,OAAO,CAAC,QAAQ,CAAC,GAAG;gBAAH,GAAG,EAAE,UAAU;IAE5C,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI;IAIpC,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,GAAG,GAAG,GAAG;IAO9C,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,GAAG,GAAG,GAAG;IAOzC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI;IAMlC,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAKzB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAKzB,GAAG,IAAI,WAAW;IAKlB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,WAAW;IAQjC,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,WAAW;IAUnC,KAAK,IAAI,IAAI;IASP,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAIrB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAQrB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAUjC,KAAK,IAAI,MAAM;CAGhB;AAED,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAEhE"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExpressJccSession = void 0;
|
|
4
|
+
exports.createExpressJccSession = createExpressJccSession;
|
|
5
|
+
/**
|
|
6
|
+
* Bridges `req.jccSession` to the same underlying store as `express-session` +
|
|
7
|
+
* `connect-flash`, so flash messages set via `res.with()` or `req.flash()` stay
|
|
8
|
+
* in sync with `jccSession.flash()` / `getFlash()`.
|
|
9
|
+
*/
|
|
10
|
+
function sessionRecord(req) {
|
|
11
|
+
return req.session;
|
|
12
|
+
}
|
|
13
|
+
class ExpressJccSession {
|
|
14
|
+
constructor(req) {
|
|
15
|
+
this.req = req;
|
|
16
|
+
}
|
|
17
|
+
flash(key, value) {
|
|
18
|
+
this.req.flash(key, value);
|
|
19
|
+
}
|
|
20
|
+
getFlash(key, defaultValue) {
|
|
21
|
+
const raw = this.req.flash(key);
|
|
22
|
+
if (raw === undefined || raw === null)
|
|
23
|
+
return defaultValue;
|
|
24
|
+
if (Array.isArray(raw))
|
|
25
|
+
return raw.length ? raw[0] : defaultValue;
|
|
26
|
+
return raw;
|
|
27
|
+
}
|
|
28
|
+
get(key, defaultValue) {
|
|
29
|
+
const s = sessionRecord(this.req);
|
|
30
|
+
if (!s)
|
|
31
|
+
return defaultValue;
|
|
32
|
+
const v = s[key];
|
|
33
|
+
return v !== undefined ? v : defaultValue;
|
|
34
|
+
}
|
|
35
|
+
put(key, value) {
|
|
36
|
+
const s = sessionRecord(this.req);
|
|
37
|
+
if (!s)
|
|
38
|
+
return;
|
|
39
|
+
s[key] = value;
|
|
40
|
+
}
|
|
41
|
+
has(key) {
|
|
42
|
+
const s = sessionRecord(this.req);
|
|
43
|
+
return s != null && s[key] !== undefined;
|
|
44
|
+
}
|
|
45
|
+
forget(key) {
|
|
46
|
+
const s = sessionRecord(this.req);
|
|
47
|
+
if (s && key in s)
|
|
48
|
+
delete s[key];
|
|
49
|
+
}
|
|
50
|
+
all() {
|
|
51
|
+
const s = sessionRecord(this.req);
|
|
52
|
+
return s ? { ...s } : {};
|
|
53
|
+
}
|
|
54
|
+
only(keys) {
|
|
55
|
+
const out = {};
|
|
56
|
+
for (const key of keys) {
|
|
57
|
+
if (this.has(key))
|
|
58
|
+
out[key] = this.get(key);
|
|
59
|
+
}
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
62
|
+
except(keys) {
|
|
63
|
+
const full = this.all();
|
|
64
|
+
const skip = new Set(keys);
|
|
65
|
+
const out = {};
|
|
66
|
+
for (const k of Object.keys(full)) {
|
|
67
|
+
if (!skip.has(k))
|
|
68
|
+
out[k] = full[k];
|
|
69
|
+
}
|
|
70
|
+
return out;
|
|
71
|
+
}
|
|
72
|
+
flush() {
|
|
73
|
+
const s = sessionRecord(this.req);
|
|
74
|
+
if (!s)
|
|
75
|
+
return;
|
|
76
|
+
const keep = new Set(["cookie"]);
|
|
77
|
+
for (const k of Object.keys(s)) {
|
|
78
|
+
if (!keep.has(k))
|
|
79
|
+
delete s[k];
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
async load() {
|
|
83
|
+
/* express-session already populated req.session */
|
|
84
|
+
}
|
|
85
|
+
async save() {
|
|
86
|
+
return new Promise((resolve, reject) => {
|
|
87
|
+
const s = this.req.session;
|
|
88
|
+
if (s?.save)
|
|
89
|
+
s.save((err) => (err ? reject(err) : resolve()));
|
|
90
|
+
else
|
|
91
|
+
resolve();
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
async regenerate() {
|
|
95
|
+
return new Promise((resolve, reject) => {
|
|
96
|
+
const s = this.req.session;
|
|
97
|
+
if (s?.regenerate)
|
|
98
|
+
s.regenerate((err) => (err ? reject(err) : resolve()));
|
|
99
|
+
else
|
|
100
|
+
resolve();
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
getId() {
|
|
104
|
+
return this.req.sessionID ?? "";
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
exports.ExpressJccSession = ExpressJccSession;
|
|
108
|
+
function createExpressJccSession(req) {
|
|
109
|
+
return new ExpressJccSession(req);
|
|
110
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SessionData, SessionStore } from "../Interface";
|
|
2
2
|
export declare class RedisSessionStore implements SessionStore {
|
|
3
|
-
private client;
|
|
4
|
-
private prefix;
|
|
3
|
+
private readonly client;
|
|
4
|
+
private readonly prefix;
|
|
5
5
|
constructor(redisUrl: string, prefix?: string);
|
|
6
6
|
private getKey;
|
|
7
7
|
get(sessionId: string): Promise<SessionData | null>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RedisSession.d.ts","sourceRoot":"","sources":["../../../jcc-express-mvc/lib/Session/RedisSession.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"RedisSession.d.ts","sourceRoot":"","sources":["../../../jcc-express-mvc/lib/Session/RedisSession.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AA6BzD,qBAAa,iBAAkB,YAAW,YAAY;IACpD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAkB;IACzC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;gBAEpB,QAAQ,EAAE,MAAM,EAAE,MAAM,GAAE,MAAmB;IAOzD,OAAO,CAAC,MAAM;IAIR,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAgBnD,GAAG,CACP,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,WAAW,EACjB,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,IAAI,CAAC;IAeV,OAAO,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IASzC,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAYxD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAU7B"}
|
|
@@ -1,12 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RedisSessionStore = void 0;
|
|
4
|
-
|
|
4
|
+
function loadRedisCreateClient() {
|
|
5
|
+
try {
|
|
6
|
+
// Optional peer dependency — only required when SESSION_DRIVER=redis
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
8
|
+
const redis = require("redis");
|
|
9
|
+
if (typeof redis.createClient !== "function") {
|
|
10
|
+
throw new Error("invalid redis module");
|
|
11
|
+
}
|
|
12
|
+
return redis.createClient;
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
throw new Error('Session driver "redis" needs the optional package: npm install redis');
|
|
16
|
+
}
|
|
17
|
+
}
|
|
5
18
|
class RedisSessionStore {
|
|
6
19
|
constructor(redisUrl, prefix = "session:") {
|
|
7
|
-
|
|
20
|
+
const createClient = loadRedisCreateClient();
|
|
21
|
+
this.client = createClient({ url: redisUrl });
|
|
8
22
|
this.prefix = prefix;
|
|
9
|
-
this.client.connect();
|
|
23
|
+
void this.client.connect();
|
|
10
24
|
}
|
|
11
25
|
getKey(sessionId) {
|
|
12
26
|
return `${this.prefix}${sessionId}`;
|
|
@@ -46,7 +60,7 @@ class RedisSessionStore {
|
|
|
46
60
|
await this.client.del(key);
|
|
47
61
|
}
|
|
48
62
|
catch (error) {
|
|
49
|
-
console.error("Failed to destroy session
|
|
63
|
+
console.error("Failed to destroy session from Redis:", error);
|
|
50
64
|
}
|
|
51
65
|
}
|
|
52
66
|
async touch(sessionId, maxAge) {
|
|
@@ -64,7 +78,7 @@ class RedisSessionStore {
|
|
|
64
78
|
try {
|
|
65
79
|
const keys = await this.client.keys(`${this.prefix}*`);
|
|
66
80
|
if (keys.length > 0) {
|
|
67
|
-
await this.client.del(keys);
|
|
81
|
+
await this.client.del(...keys);
|
|
68
82
|
}
|
|
69
83
|
}
|
|
70
84
|
catch (error) {
|
|
@@ -1,12 +1,26 @@
|
|
|
1
|
+
import type { RequestHandler } from "express";
|
|
1
2
|
import { Session } from "./index";
|
|
2
3
|
import { SessionConfig } from "../Interface";
|
|
4
|
+
/**
|
|
5
|
+
* Laravel-style session manager: resolves a store by `driver` and exposes
|
|
6
|
+
* `express-session` middleware backed by that store.
|
|
7
|
+
*/
|
|
3
8
|
export declare class SessionManager {
|
|
4
|
-
private
|
|
5
|
-
private
|
|
9
|
+
private readonly store;
|
|
10
|
+
private readonly expressStore;
|
|
11
|
+
private readonly config;
|
|
6
12
|
constructor(config: SessionConfig);
|
|
13
|
+
getConfig(): SessionConfig;
|
|
7
14
|
private createStore;
|
|
8
|
-
|
|
9
|
-
|
|
15
|
+
static buildRedisUrl(r: NonNullable<SessionConfig["redis"]>): string;
|
|
16
|
+
/**
|
|
17
|
+
* `express-session` middleware using the configured driver store.
|
|
18
|
+
*/
|
|
19
|
+
getExpressMiddleware(): RequestHandler;
|
|
20
|
+
private buildExpressStore;
|
|
21
|
+
/**
|
|
22
|
+
* Optional: standalone {@link Session} instances backed by the same store (advanced use).
|
|
23
|
+
*/
|
|
10
24
|
createSession(sessionId: string): Promise<Session>;
|
|
11
25
|
}
|
|
12
26
|
//# sourceMappingURL=SessionManager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SessionManager.d.ts","sourceRoot":"","sources":["../../../jcc-express-mvc/lib/Session/SessionManager.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"SessionManager.d.ts","sourceRoot":"","sources":["../../../jcc-express-mvc/lib/Session/SessionManager.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,aAAa,EAA6B,MAAM,cAAc,CAAC;AAIxE;;;GAGG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAe;IACrC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAgB;IAC7C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;gBAE3B,MAAM,EAAE,aAAa;IAMjC,SAAS,IAAI,aAAa;IAI1B,OAAO,CAAC,WAAW;IA0BnB,MAAM,CAAC,aAAa,CAAC,CAAC,EAAE,WAAW,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,GAAG,MAAM;IAUpE;;OAEG;IACH,oBAAoB,IAAI,cAAc;IAqBtC,OAAO,CAAC,iBAAiB;IAsDzB;;OAEG;IACG,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAKzD"}
|