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,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin system for custom directives.
|
|
3
|
+
* Register custom directives without modifying the core engine.
|
|
4
|
+
*/
|
|
5
|
+
export type CustomDirectiveHandler = (content: string, match: RegExpMatchArray, param: Record<string, any>, parser: (content: string, param: Record<string, any>) => string) => string;
|
|
6
|
+
export interface CustomDirective {
|
|
7
|
+
/** Regex to match the directive (must capture the full directive) */
|
|
8
|
+
pattern: RegExp;
|
|
9
|
+
/** Check if this directive matches the given string (e.g. matched.startsWith("@custom")) */
|
|
10
|
+
matches?: (matched: string) => boolean;
|
|
11
|
+
handler: CustomDirectiveHandler;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Register a custom directive.
|
|
15
|
+
* Custom directives are checked before built-in ones.
|
|
16
|
+
*/
|
|
17
|
+
export declare function registerDirective(directive: CustomDirective): void;
|
|
18
|
+
/**
|
|
19
|
+
* Unregister all custom directives.
|
|
20
|
+
*/
|
|
21
|
+
export declare function clearCustomDirectives(): void;
|
|
22
|
+
/**
|
|
23
|
+
* Get regex source strings for custom directives (for combined regex).
|
|
24
|
+
*/
|
|
25
|
+
export declare function getCustomPatterns(): string[];
|
|
26
|
+
/**
|
|
27
|
+
* Find a custom directive handler for the given match.
|
|
28
|
+
*/
|
|
29
|
+
export declare function findCustomDirective(matched: string, fullMatch: RegExpMatchArray): CustomDirective | null;
|
|
30
|
+
//# sourceMappingURL=plugins.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugins.d.ts","sourceRoot":"","sources":["../../../jcc-express-mvc/lib/Templating-engine/plugins.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,MAAM,sBAAsB,GAAG,CACnC,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,gBAAgB,EACvB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC1B,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,MAAM,KAC5D,MAAM,CAAC;AAEZ,MAAM,WAAW,eAAe;IAC9B,qEAAqE;IACrE,OAAO,EAAE,MAAM,CAAC;IAChB,4FAA4F;IAC5F,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC;IACvC,OAAO,EAAE,sBAAsB,CAAC;CACjC;AAID;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,eAAe,GAAG,IAAI,CAElE;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,IAAI,CAE5C;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,EAAE,CAE5C;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,gBAAgB,GAAG,eAAe,GAAG,IAAI,CAUxG"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Plugin system for custom directives.
|
|
4
|
+
* Register custom directives without modifying the core engine.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.registerDirective = registerDirective;
|
|
8
|
+
exports.clearCustomDirectives = clearCustomDirectives;
|
|
9
|
+
exports.getCustomPatterns = getCustomPatterns;
|
|
10
|
+
exports.findCustomDirective = findCustomDirective;
|
|
11
|
+
const customDirectives = [];
|
|
12
|
+
/**
|
|
13
|
+
* Register a custom directive.
|
|
14
|
+
* Custom directives are checked before built-in ones.
|
|
15
|
+
*/
|
|
16
|
+
function registerDirective(directive) {
|
|
17
|
+
customDirectives.push(directive);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Unregister all custom directives.
|
|
21
|
+
*/
|
|
22
|
+
function clearCustomDirectives() {
|
|
23
|
+
customDirectives.length = 0;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Get regex source strings for custom directives (for combined regex).
|
|
27
|
+
*/
|
|
28
|
+
function getCustomPatterns() {
|
|
29
|
+
return customDirectives.map((d) => `(${d.pattern.source})`);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Find a custom directive handler for the given match.
|
|
33
|
+
*/
|
|
34
|
+
function findCustomDirective(matched, fullMatch) {
|
|
35
|
+
for (const d of customDirectives) {
|
|
36
|
+
if (d.matches) {
|
|
37
|
+
if (d.matches(matched))
|
|
38
|
+
return d;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
// Use new RegExp to avoid mutating pattern.lastIndex (problematic with 'g' flag)
|
|
42
|
+
if (new RegExp(d.pattern.source).test(matched))
|
|
43
|
+
return d;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
package/lib/Type/index.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ export type ValidationObject = {
|
|
|
25
25
|
export type HttpMethodType = "get" | "post" | "patch" | "put" | "delete";
|
|
26
26
|
export type RouteHandler = ExpressCallback | [BaseController, string] | string;
|
|
27
27
|
export type Middleware = ExpressCallback[] | ExpressCallback;
|
|
28
|
+
export type MiddlewareInput = Middleware | string | Array<Middleware | string>;
|
|
28
29
|
export type HttpRoutes = Array<{
|
|
29
30
|
url: string;
|
|
30
31
|
method: HttpMethodType;
|
package/lib/Type/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../jcc-express-mvc/lib/Type/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EACL,cAAc,EACd,eAAe,EACf,iBAAiB,EAClB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAU,MAAM,WAAW,CAAC;AAI7D,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAIF,MAAM,MAAM,UAAU,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1C,MAAM,MAAM,gBAAgB,GAAG;IAC7B,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IAChB,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,GAAG,QAAQ,CAAC;AAEzE,MAAM,MA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,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;AACrD,MAAM,MAAM,YAAY,CAAC,CAAC,GAAG,GAAG,IAAI,WAAW,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAEhE,MAAM,MAAM,eAAe,CAAC,CAAC,GAAG,GAAG,IAC/B,CAAC,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC,GAC3B,CAAC,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;AAE5B,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;AAEtD,MAAM,MAAM,mBAAmB,GAAG,UAAU,iBAAiB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CustomValidation.d.ts","sourceRoot":"","sources":["../../../../jcc-express-mvc/lib/Validation/Validator/CustomValidation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAE/C,qBAAa,gBAAgB;IAI3B,MAAM,CAAC,QAAQ,CACb,IAAI,EAAE,GAAG,EACT,KAAK,EAAE,SAAS,EAChB,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,UAAU;WASP,MAAM,CACjB,IAAI,EAAE,GAAG,EACT,KAAK,EAAE,SAAS,EAChB,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,UAAU;
|
|
1
|
+
{"version":3,"file":"CustomValidation.d.ts","sourceRoot":"","sources":["../../../../jcc-express-mvc/lib/Validation/Validator/CustomValidation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAE/C,qBAAa,gBAAgB;IAI3B,MAAM,CAAC,QAAQ,CACb,IAAI,EAAE,GAAG,EACT,KAAK,EAAE,SAAS,EAChB,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,UAAU;WASP,MAAM,CACjB,IAAI,EAAE,GAAG,EACT,KAAK,EAAE,SAAS,EAChB,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,UAAU;IAkBpB,MAAM,CAAC,IAAI,CACT,IAAI,EAAE,GAAG,EACT,KAAK,EAAE,SAAS,EAChB,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,UAAU;IAQpB,MAAM,CAAC,KAAK,CACV,IAAI,EAAE,GAAG,EACT,KAAK,EAAE,SAAS,EAChB,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,UAAU;WAQP,MAAM,CACjB,IAAI,EAAE,GAAG,EACT,KAAK,EAAE,SAAS,EAChB,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,UAAU;CAerB;AAED,eAAO,MAAM,gBAAgB;;;;;;CAM5B,CAAC"}
|
|
@@ -16,7 +16,7 @@ class CustomValidation {
|
|
|
16
16
|
if (!this.ruleValue || !attribute) {
|
|
17
17
|
return passes(false, "Invalid unique rule definition.");
|
|
18
18
|
}
|
|
19
|
-
const result = await (0, helper_1.existsHelper)(attribute, value, this.ruleValue);
|
|
19
|
+
const result = await (0, helper_1.existsHelper)(this.attribute || attribute, value, this.ruleValue);
|
|
20
20
|
if (result) {
|
|
21
21
|
return passes(false, `This ${this.attribute} has already been taken`);
|
|
22
22
|
}
|
|
@@ -38,7 +38,7 @@ class CustomValidation {
|
|
|
38
38
|
if (!value) {
|
|
39
39
|
return passes(false, "The field is required.");
|
|
40
40
|
}
|
|
41
|
-
const result = await (0, helper_1.existsHelper)(attribute, value, this.ruleValue);
|
|
41
|
+
const result = await (0, helper_1.existsHelper)(this.attribute || attribute, value, this.ruleValue);
|
|
42
42
|
if (!result) {
|
|
43
43
|
return passes(false, `The ${this.attribute} does not exist`);
|
|
44
44
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../../../../jcc-express-mvc/lib/Validation/Validator/helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../../../../jcc-express-mvc/lib/Validation/Validator/helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAQnC;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,GACvB,WAAW,MAAM,EACjB,OAAO,SAAS,EAChB,WAAW,MAAM,iBAwBlB,CAAC"}
|
|
@@ -14,11 +14,18 @@ const existsHelper = async (attribute, value, ruleValue) => {
|
|
|
14
14
|
const Model = (0, index_1.getModelFile)(model);
|
|
15
15
|
const modelInstance = (0, index_1.getModel)(Model);
|
|
16
16
|
let result;
|
|
17
|
-
if (
|
|
17
|
+
if ((0, index_1.isMongooseModel)()) {
|
|
18
18
|
result = await modelInstance[Model].findOne({
|
|
19
19
|
[column || attribute]: value,
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
|
+
else if ((0, index_1.isSequelizeModel)()) {
|
|
23
|
+
result = await modelInstance[Model].findOne({
|
|
24
|
+
where: {
|
|
25
|
+
[column || attribute]: value,
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
}
|
|
22
29
|
else {
|
|
23
30
|
result = await modelInstance[Model].where(column || attribute, value).exists();
|
|
24
31
|
}
|
package/lib/util/index.d.ts
CHANGED
|
@@ -75,6 +75,9 @@ export declare const verifyHash: (password: string, hashPassword: string) => Pro
|
|
|
75
75
|
* @param {object} data - The data to be encoded in the token.
|
|
76
76
|
* @returns {string} - Signed JWT token.
|
|
77
77
|
*/
|
|
78
|
+
export type JwtTokenKind = "access" | "refresh" | "legacy";
|
|
79
|
+
/** `typ` claim: access for API/session, refresh for refresh flow only. */
|
|
80
|
+
export declare const jwtTokenType: (payload: unknown) => JwtTokenKind;
|
|
78
81
|
export declare const jwtSign: (data: string | Record<string, any>, options?: Record<string, any>) => string | any;
|
|
79
82
|
/**
|
|
80
83
|
* Function to verify a JWT token.
|
|
@@ -82,6 +85,32 @@ export declare const jwtSign: (data: string | Record<string, any>, options?: Rec
|
|
|
82
85
|
* @returns {object} - Decoded JWT payload.
|
|
83
86
|
*/
|
|
84
87
|
export declare const jwtVerify: (token: string) => string | any;
|
|
88
|
+
/** User id from JWT payload (jwt.sign stores subject as `{ id }` from jwtSign string helper). */
|
|
89
|
+
export declare const jwtSubjectId: (payload: unknown) => string | number;
|
|
90
|
+
/** Shared options for `auth_token` / `refresh_token` cookies (set and clear). */
|
|
91
|
+
export declare function authSessionCookieOptions(): {
|
|
92
|
+
path: "/";
|
|
93
|
+
httpOnly: true;
|
|
94
|
+
secure: boolean;
|
|
95
|
+
sameSite: "lax";
|
|
96
|
+
};
|
|
97
|
+
/** When `JWT_REQUIRE_TYPED_TOKENS=true`, legacy access tokens (no `typ`) are rejected. */
|
|
98
|
+
export declare function jwtLegacyAccessTokenRejected(payload: unknown): boolean;
|
|
99
|
+
export type JwtAccessTokenPayloadResult = {
|
|
100
|
+
ok: true;
|
|
101
|
+
} | {
|
|
102
|
+
ok: false;
|
|
103
|
+
reason: "refresh" | "legacy";
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* After `jwtVerify`, ensures the payload is a session/API access token, not refresh
|
|
107
|
+
* and not a disallowed legacy token when strict mode is on.
|
|
108
|
+
*/
|
|
109
|
+
export declare function checkJwtAccessTokenPayload(payload: unknown): JwtAccessTokenPayloadResult;
|
|
110
|
+
/**
|
|
111
|
+
* In production, refuse weak or missing JWT_SECRET (call once at bootstrap).
|
|
112
|
+
*/
|
|
113
|
+
export declare function assertProductionJwtSecret(): void;
|
|
85
114
|
/**
|
|
86
115
|
* Function to save an image file.
|
|
87
116
|
* @param {object} req - The request object containing the file.
|
|
@@ -114,7 +143,9 @@ export declare const getJobClass: (jobName: string) => any;
|
|
|
114
143
|
export declare const pluralizeStr: (str: string) => string;
|
|
115
144
|
/** Universal user finder that supports MongoDB, Sequelize, and JCC ORM */
|
|
116
145
|
export declare const findUserById: (User: any, userId: string | number) => Promise<any>;
|
|
117
|
-
export declare const
|
|
146
|
+
export declare const isMongooseModel: () => boolean;
|
|
147
|
+
export declare const isSequelizeModel: () => boolean;
|
|
148
|
+
export declare const resolveModelBinding: (req: AppRequest, ModelClass: typeof Model | any, resolved: any) => Promise<any>;
|
|
118
149
|
/**
|
|
119
150
|
* Passes the value to a callback and returns the value.
|
|
120
151
|
*
|
|
@@ -124,4 +155,14 @@ export declare const resolveModelBinding: (req: AppRequest, ModelClass: typeof M
|
|
|
124
155
|
* @returns {Promise<T>}
|
|
125
156
|
*/
|
|
126
157
|
export declare const tap: <T>(data: T, callback?: (data: T) => any) => Promise<T>;
|
|
158
|
+
/**
|
|
159
|
+
* Checks if a model is an instance of a model.
|
|
160
|
+
* @param {any} model - The model to check.
|
|
161
|
+
* @returns {boolean} - True if the model is an instance of a model, false otherwise.
|
|
162
|
+
*/
|
|
163
|
+
export declare const isModelInstance: (model: any) => boolean;
|
|
164
|
+
export declare const extractQuery: (url: string) => {
|
|
165
|
+
[k: string]: string;
|
|
166
|
+
};
|
|
167
|
+
export declare const JSInBuilTClass: (className: string) => boolean;
|
|
127
168
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/util/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../jcc-express-mvc/lib/util/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAW,UAAU,EAAe,MAAM,cAAc,CAAC;AAIhE,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAKxC;;;;GAIG;AACH,eAAO,MAAM,QAAQ,GA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GAIG;AACH,eAAO,MAAM,YAAY,GACtB,MAAM,GAAG,KAAG,GAEsC,CAAC;AAEtD,eAAO,MAAM,YAAY,GAAI,WAAW,MAAM,KAAG,MAEhD,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,MAAM,GAAG,KAAG,GAezC,CAAC;AAEL,eAAO,MAAM,WAAW,GAAI,SAAS,MAAM,KAAG,GAQ7C,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GAAI,KAAK,MAAM,KAAG,MAG1C,CAAC;AAOF,0EAA0E;AAC1E,eAAO,MAAM,YAAY,GAAU,MAAM,GAAG,EAAE,QAAQ,MAAM,GAAG,MAAM,iBAoBpE,CAAC;AAEF,eAAO,MAAM,eAAe,eAQ3B,CAAC;AAEF,eAAO,MAAM,gBAAgB,eAI5B,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAC9B,KAAK,UAAU,EACf,YAAY,OAAO,KAAK,GAAG,GAAG,EAC9B,UAAU,GAAG,iBA8Cd,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,GAAG,GAAU,CAAC,EACzB,MAAM,CAAC,EACP,WAAW,CAAC,IAAI,EAAE,CAAC,KAAK,GAAG,KAC1B,OAAO,CAAC,CAAC,CASX,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAI,OAAO,GAAG,KAAG,OAc5C,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,KAAK,MAAM;;CAGvC,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,WAAW,MAAM,KAAG,OAIlD,CAAC"}
|
package/lib/util/index.js
CHANGED
|
@@ -3,7 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.tap = exports.resolveModelBinding = exports.findUserById = exports.pluralizeStr = exports.getJobClass = exports.cloudinaryUpload = exports.getModelFile = exports.asyncHandler = exports.capitalize = exports.saveImage = exports.jwtVerify = exports.jwtSign = exports.verifyHash = exports.bcrypt = exports.getProvider = exports.getProviders = exports.getRoute = exports.getRequest = exports.getMiddleware = exports.getModel = exports.getApiController = exports.getController = exports.loadRoute = exports.loadRoutes = exports.rootPath = void 0;
|
|
6
|
+
exports.JSInBuilTClass = exports.extractQuery = exports.isModelInstance = exports.tap = exports.resolveModelBinding = exports.isSequelizeModel = exports.isMongooseModel = exports.findUserById = exports.pluralizeStr = exports.getJobClass = exports.cloudinaryUpload = exports.getModelFile = exports.asyncHandler = exports.capitalize = exports.saveImage = exports.jwtSubjectId = exports.jwtVerify = exports.jwtSign = exports.jwtTokenType = exports.verifyHash = exports.bcrypt = exports.getProvider = exports.getProviders = exports.getRoute = exports.getRequest = exports.getMiddleware = exports.getModel = exports.getApiController = exports.getController = exports.loadRoute = exports.loadRoutes = exports.rootPath = void 0;
|
|
7
|
+
exports.authSessionCookieOptions = authSessionCookieOptions;
|
|
8
|
+
exports.jwtLegacyAccessTokenRejected = jwtLegacyAccessTokenRejected;
|
|
9
|
+
exports.checkJwtAccessTokenPayload = checkJwtAccessTokenPayload;
|
|
10
|
+
exports.assertProductionJwtSecret = assertProductionJwtSecret;
|
|
7
11
|
const bcryptjs_1 = __importDefault(require("bcryptjs"));
|
|
8
12
|
const app_root_path_1 = __importDefault(require("app-root-path"));
|
|
9
13
|
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
@@ -15,6 +19,7 @@ const error_1 = require("../Error/Constants/error");
|
|
|
15
19
|
const inflection_1 = require("inflection");
|
|
16
20
|
const cloudinary_1 = require("cloudinary");
|
|
17
21
|
const Str_1 = require("./Str");
|
|
22
|
+
const Jcc_eloquent_1 = require("../Jcc-eloquent");
|
|
18
23
|
// import { camelize, singularize } from "inflection";
|
|
19
24
|
const getRootPath = app_root_path_1.default.path;
|
|
20
25
|
/**
|
|
@@ -22,7 +27,7 @@ const getRootPath = app_root_path_1.default.path;
|
|
|
22
27
|
* @param {string} file - The file path relative to the project root.
|
|
23
28
|
* @returns {string} - Absolute path of the specified file.
|
|
24
29
|
*/
|
|
25
|
-
const rootPath = (file) => require(`${path_1.default.resolve(`${getRootPath}/${
|
|
30
|
+
const rootPath = (file) => require(`${path_1.default.resolve(`${getRootPath}/${file}`)}`);
|
|
26
31
|
exports.rootPath = rootPath;
|
|
27
32
|
/**
|
|
28
33
|
* Function load all route files
|
|
@@ -102,8 +107,8 @@ const getProvider = (name) => {
|
|
|
102
107
|
try {
|
|
103
108
|
return require(`${getRootPath}/app/Providers/${name}`);
|
|
104
109
|
}
|
|
105
|
-
catch {
|
|
106
|
-
console.
|
|
110
|
+
catch (error) {
|
|
111
|
+
console.error("Cannot find module", error.message);
|
|
107
112
|
}
|
|
108
113
|
};
|
|
109
114
|
exports.getProvider = getProvider;
|
|
@@ -127,17 +132,28 @@ const verifyHash = async (password, hashPassword) => {
|
|
|
127
132
|
return bcryptjs_1.default.compare(`${password || ""}`, hashPassword);
|
|
128
133
|
};
|
|
129
134
|
exports.verifyHash = verifyHash;
|
|
130
|
-
/**
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
+
/** `typ` claim: access for API/session, refresh for refresh flow only. */
|
|
136
|
+
const jwtTokenType = (payload) => {
|
|
137
|
+
if (payload == null || typeof payload !== "object")
|
|
138
|
+
return "legacy";
|
|
139
|
+
const typ = payload.typ;
|
|
140
|
+
if (typ === "refresh")
|
|
141
|
+
return "refresh";
|
|
142
|
+
if (typ === "access")
|
|
143
|
+
return "access";
|
|
144
|
+
return "legacy";
|
|
145
|
+
};
|
|
146
|
+
exports.jwtTokenType = jwtTokenType;
|
|
135
147
|
const jwtSign = (data, options) => {
|
|
136
148
|
try {
|
|
137
149
|
const secret = Config_1.config.get("JWT_SECRET") || "app-generated-key";
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
150
|
+
const payload = typeof data === "string"
|
|
151
|
+
? { id: data, typ: "access" }
|
|
152
|
+
: { typ: "access", ...data };
|
|
153
|
+
return jsonwebtoken_1.default.sign(payload, secret, {
|
|
154
|
+
algorithm: "HS256",
|
|
155
|
+
...options,
|
|
156
|
+
});
|
|
141
157
|
}
|
|
142
158
|
catch (error) {
|
|
143
159
|
throw new AppError_1.AppError(error?.message, error_1.JWT_SIGN_ERROR);
|
|
@@ -151,13 +167,72 @@ exports.jwtSign = jwtSign;
|
|
|
151
167
|
*/
|
|
152
168
|
const jwtVerify = (token) => {
|
|
153
169
|
try {
|
|
154
|
-
return jsonwebtoken_1.default.verify(token, Config_1.config.get(Constants_1.JWT_SECRET, "app-generated-key") || ""
|
|
170
|
+
return jsonwebtoken_1.default.verify(token, Config_1.config.get(Constants_1.JWT_SECRET, "app-generated-key") || "", {
|
|
171
|
+
algorithms: ["HS256"],
|
|
172
|
+
clockTolerance: 30,
|
|
173
|
+
});
|
|
155
174
|
}
|
|
156
175
|
catch (error) {
|
|
157
176
|
throw new AppError_1.AppError(error?.message, error_1.JWT_VERIFY_ERROR);
|
|
158
177
|
}
|
|
159
178
|
};
|
|
160
179
|
exports.jwtVerify = jwtVerify;
|
|
180
|
+
/** User id from JWT payload (jwt.sign stores subject as `{ id }` from jwtSign string helper). */
|
|
181
|
+
const jwtSubjectId = (payload) => {
|
|
182
|
+
if (payload != null && typeof payload === "object" && "id" in payload) {
|
|
183
|
+
return payload.id;
|
|
184
|
+
}
|
|
185
|
+
if (typeof payload === "string" || typeof payload === "number") {
|
|
186
|
+
return payload;
|
|
187
|
+
}
|
|
188
|
+
throw new AppError_1.AppError("Invalid token payload", error_1.JWT_VERIFY_ERROR);
|
|
189
|
+
};
|
|
190
|
+
exports.jwtSubjectId = jwtSubjectId;
|
|
191
|
+
/** Shared options for `auth_token` / `refresh_token` cookies (set and clear). */
|
|
192
|
+
function authSessionCookieOptions() {
|
|
193
|
+
return {
|
|
194
|
+
path: "/",
|
|
195
|
+
httpOnly: true,
|
|
196
|
+
secure: Config_1.config.get("APP_ENV") === "production",
|
|
197
|
+
sameSite: "lax",
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
/** When `JWT_REQUIRE_TYPED_TOKENS=true`, legacy access tokens (no `typ`) are rejected. */
|
|
201
|
+
function jwtLegacyAccessTokenRejected(payload) {
|
|
202
|
+
if (Config_1.config.get("JWT_REQUIRE_TYPED_TOKENS", "").toLowerCase() !== "true") {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
return (0, exports.jwtTokenType)(payload) === "legacy";
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* After `jwtVerify`, ensures the payload is a session/API access token, not refresh
|
|
209
|
+
* and not a disallowed legacy token when strict mode is on.
|
|
210
|
+
*/
|
|
211
|
+
function checkJwtAccessTokenPayload(payload) {
|
|
212
|
+
if ((0, exports.jwtTokenType)(payload) === "refresh") {
|
|
213
|
+
return { ok: false, reason: "refresh" };
|
|
214
|
+
}
|
|
215
|
+
if (jwtLegacyAccessTokenRejected(payload)) {
|
|
216
|
+
return { ok: false, reason: "legacy" };
|
|
217
|
+
}
|
|
218
|
+
return { ok: true };
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* In production, refuse weak or missing JWT_SECRET (call once at bootstrap).
|
|
222
|
+
*/
|
|
223
|
+
function assertProductionJwtSecret() {
|
|
224
|
+
const secret = (Config_1.config.get(Constants_1.JWT_SECRET, "") || "").trim();
|
|
225
|
+
const appEnv = (Config_1.config.get("APP_ENV", "") || "").trim().toLowerCase();
|
|
226
|
+
const isProduction = process.env.NODE_ENV === "production" || appEnv === "production";
|
|
227
|
+
if (!isProduction)
|
|
228
|
+
return;
|
|
229
|
+
if (secret.length < 32) {
|
|
230
|
+
throw new Error("[security] JWT_SECRET must be at least 32 characters in production.");
|
|
231
|
+
}
|
|
232
|
+
if (secret === "app-generated-key") {
|
|
233
|
+
throw new Error("[security] JWT_SECRET must not use the default placeholder in production.");
|
|
234
|
+
}
|
|
235
|
+
}
|
|
161
236
|
/**
|
|
162
237
|
* Function to save an image file.
|
|
163
238
|
* @param {object} req - The request object containing the file.
|
|
@@ -218,8 +293,8 @@ const cloudinaryUpload = (path) => new Promise((resolve, reject) => {
|
|
|
218
293
|
exports.cloudinaryUpload = cloudinaryUpload;
|
|
219
294
|
const getJobClass = (jobName) => {
|
|
220
295
|
try {
|
|
221
|
-
const
|
|
222
|
-
return
|
|
296
|
+
const jobModule = require(`${getRootPath}/app/Jobs/${jobName}`);
|
|
297
|
+
return jobModule[jobName] ?? jobModule.default ?? false;
|
|
223
298
|
}
|
|
224
299
|
catch (error) {
|
|
225
300
|
console.log(`No Job found with the name of ${jobName}`);
|
|
@@ -245,7 +320,8 @@ exports.pluralizeStr = pluralizeStr;
|
|
|
245
320
|
/** Universal user finder that supports MongoDB, Sequelize, and JCC ORM */
|
|
246
321
|
const findUserById = async (User, userId) => {
|
|
247
322
|
const orm = Config_1.config.get("DB_ORM");
|
|
248
|
-
if (orm === "mongodb"
|
|
323
|
+
if (orm === "mongodb" ||
|
|
324
|
+
(orm === "mongoose" && typeof User.findById === "function")) {
|
|
249
325
|
return await User.findById(userId);
|
|
250
326
|
}
|
|
251
327
|
if (orm === "sequelize" && typeof User.findByPk === "function") {
|
|
@@ -259,14 +335,37 @@ const findUserById = async (User, userId) => {
|
|
|
259
335
|
throw new Error("User lookup method not found for current ORM.");
|
|
260
336
|
};
|
|
261
337
|
exports.findUserById = findUserById;
|
|
338
|
+
const isMongooseModel = () => {
|
|
339
|
+
const dbConnection = Config_1.config.get("DB_CONNECTION").toLowerCase();
|
|
340
|
+
const dbOrm = Config_1.config.get("DB_ORM").toLowerCase();
|
|
341
|
+
return (dbConnection === "mongodb" ||
|
|
342
|
+
dbConnection === "mongoose" ||
|
|
343
|
+
dbOrm === "mongoose");
|
|
344
|
+
};
|
|
345
|
+
exports.isMongooseModel = isMongooseModel;
|
|
346
|
+
const isSequelizeModel = () => {
|
|
347
|
+
const dbConnection = Config_1.config.get("DB_CONNECTION").toLowerCase();
|
|
348
|
+
const dbOrm = Config_1.config.get("DB_ORM").toLowerCase();
|
|
349
|
+
return dbConnection === "sequelize" || dbOrm === "sequelize";
|
|
350
|
+
};
|
|
351
|
+
exports.isSequelizeModel = isSequelizeModel;
|
|
262
352
|
const resolveModelBinding = async (req, ModelClass, resolved) => {
|
|
263
|
-
|
|
353
|
+
//
|
|
354
|
+
const modelParamName = (0, exports.isMongooseModel)()
|
|
355
|
+
? Str_1.Str.camel(ModelClass.modelName)
|
|
356
|
+
: Str_1.Str.camel(ModelClass.name);
|
|
264
357
|
const params = req.params;
|
|
265
358
|
// ---------------------------------
|
|
266
359
|
// 1. Standard binding: /users/:user
|
|
267
360
|
// ---------------------------------
|
|
268
361
|
if (params[modelParamName] !== undefined) {
|
|
269
362
|
const id = params[modelParamName];
|
|
363
|
+
if ((0, exports.isMongooseModel)()) {
|
|
364
|
+
return await ModelClass.findById(id);
|
|
365
|
+
}
|
|
366
|
+
if ((0, exports.isSequelizeModel)()) {
|
|
367
|
+
return await ModelClass.findByPk(id);
|
|
368
|
+
}
|
|
270
369
|
return await ModelClass.find(id);
|
|
271
370
|
}
|
|
272
371
|
// ---------------------------------------------------
|
|
@@ -277,6 +376,14 @@ const resolveModelBinding = async (req, ModelClass, resolved) => {
|
|
|
277
376
|
if (key.endsWith(suffix)) {
|
|
278
377
|
const column = key.replace(suffix, "");
|
|
279
378
|
const value = params[key];
|
|
379
|
+
if ((0, exports.isMongooseModel)()) {
|
|
380
|
+
return await ModelClass.findOne({ [column]: value });
|
|
381
|
+
}
|
|
382
|
+
if ((0, exports.isSequelizeModel)()) {
|
|
383
|
+
return await ModelClass.findOne({
|
|
384
|
+
where: { [column]: value },
|
|
385
|
+
});
|
|
386
|
+
}
|
|
280
387
|
return await ModelClass.where(column, value).first();
|
|
281
388
|
}
|
|
282
389
|
}
|
|
@@ -303,3 +410,33 @@ const tap = async (data, callback) => {
|
|
|
303
410
|
}
|
|
304
411
|
};
|
|
305
412
|
exports.tap = tap;
|
|
413
|
+
/**
|
|
414
|
+
* Checks if a model is an instance of a model.
|
|
415
|
+
* @param {any} model - The model to check.
|
|
416
|
+
* @returns {boolean} - True if the model is an instance of a model, false otherwise.
|
|
417
|
+
*/
|
|
418
|
+
const isModelInstance = (model) => {
|
|
419
|
+
const dbOrm = Config_1.config.get("DB_ORM").toLowerCase();
|
|
420
|
+
const dbConnection = Config_1.config.get("DB_CONNECTION").toLowerCase();
|
|
421
|
+
if (dbOrm === "mongoose" || dbConnection === "mongodb") {
|
|
422
|
+
const { mongoose } = require("mongoose");
|
|
423
|
+
return model instanceof mongoose.Model;
|
|
424
|
+
}
|
|
425
|
+
if (dbOrm === "sequelize" || dbConnection === "sequelize") {
|
|
426
|
+
const { Model } = require("sequelize");
|
|
427
|
+
return model instanceof Model;
|
|
428
|
+
}
|
|
429
|
+
return model instanceof Jcc_eloquent_1.Model;
|
|
430
|
+
};
|
|
431
|
+
exports.isModelInstance = isModelInstance;
|
|
432
|
+
const extractQuery = (url) => {
|
|
433
|
+
const parsed = new URL(url, process.env.APP_URL); // base required for relative URLs
|
|
434
|
+
return Object.fromEntries(parsed.searchParams.entries());
|
|
435
|
+
};
|
|
436
|
+
exports.extractQuery = extractQuery;
|
|
437
|
+
const JSInBuilTClass = (className) => {
|
|
438
|
+
return Str_1.Str.lower(className) == "string" || "number" || "boolean" || "object"
|
|
439
|
+
? true
|
|
440
|
+
: false;
|
|
441
|
+
};
|
|
442
|
+
exports.JSInBuilTClass = JSInBuilTClass;
|