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.
Files changed (296) hide show
  1. package/Core/index.d.ts +4 -0
  2. package/Core/index.d.ts.map +1 -1
  3. package/Core/index.js +5 -0
  4. package/__tests__/Job.test.d.ts +2 -0
  5. package/__tests__/Job.test.d.ts.map +1 -0
  6. package/__tests__/Job.test.js +205 -0
  7. package/__tests__/MySqlSchemaBlueprint.test.d.ts +2 -0
  8. package/__tests__/MySqlSchemaBlueprint.test.d.ts.map +1 -0
  9. package/__tests__/MySqlSchemaBlueprint.test.js +55 -0
  10. package/__tests__/PostgresTranslator.test.d.ts +2 -0
  11. package/__tests__/PostgresTranslator.test.d.ts.map +1 -0
  12. package/__tests__/PostgresTranslator.test.js +82 -0
  13. package/__tests__/SQLiteTranslator.test.d.ts +2 -0
  14. package/__tests__/SQLiteTranslator.test.d.ts.map +1 -0
  15. package/__tests__/SQLiteTranslator.test.js +125 -0
  16. package/__tests__/SchemaAlterBlueprint.test.d.ts +2 -0
  17. package/__tests__/SchemaAlterBlueprint.test.d.ts.map +1 -0
  18. package/__tests__/SchemaAlterBlueprint.test.js +35 -0
  19. package/global.d.ts +3 -1
  20. package/index.d.ts +28 -3
  21. package/index.d.ts.map +1 -1
  22. package/index.js +33 -75
  23. package/lib/Application/Application.d.ts.map +1 -1
  24. package/lib/Application/Application.js +2 -2
  25. package/lib/Application/ApplicationBuilder.d.ts.map +1 -1
  26. package/lib/Application/ApplicationBuilder.js +22 -11
  27. package/lib/Auth/AuthMiddleware.d.ts.map +1 -1
  28. package/lib/Auth/AuthMiddleware.js +29 -12
  29. package/lib/Auth/index.d.ts +17 -3
  30. package/lib/Auth/index.d.ts.map +1 -1
  31. package/lib/Auth/index.js +128 -26
  32. package/lib/Auth/loginRateLimit.d.ts +6 -0
  33. package/lib/Auth/loginRateLimit.d.ts.map +1 -0
  34. package/lib/Auth/loginRateLimit.js +25 -0
  35. package/lib/Auth/refreshTokenStore.d.ts +24 -0
  36. package/lib/Auth/refreshTokenStore.d.ts.map +1 -0
  37. package/lib/Auth/refreshTokenStore.js +46 -0
  38. package/lib/Command-Line/DBCommand.d.ts.map +1 -1
  39. package/lib/Command-Line/DBCommand.js +9 -3
  40. package/lib/Command-Line/KeyGenerateCommand.d.ts +6 -0
  41. package/lib/Command-Line/KeyGenerateCommand.d.ts.map +1 -0
  42. package/lib/Command-Line/KeyGenerateCommand.js +47 -0
  43. package/lib/Command-Line/MakeCommand.d.ts +1 -0
  44. package/lib/Command-Line/MakeCommand.d.ts.map +1 -1
  45. package/lib/Command-Line/MakeCommand.js +36 -32
  46. package/lib/Command-Line/NodeArtisanCommand.d.ts +2 -0
  47. package/lib/Command-Line/NodeArtisanCommand.d.ts.map +1 -1
  48. package/lib/Command-Line/NodeArtisanCommand.js +24 -6
  49. package/lib/Command-Line/NodeTinker/Tinker.d.ts +5 -2
  50. package/lib/Command-Line/NodeTinker/Tinker.d.ts.map +1 -1
  51. package/lib/Command-Line/NodeTinker/Tinker.js +13 -3
  52. package/lib/Command-Line/WatchCommand.d.ts +29 -0
  53. package/lib/Command-Line/WatchCommand.d.ts.map +1 -0
  54. package/lib/Command-Line/WatchCommand.js +234 -0
  55. package/lib/Command-Line/files/Models.d.ts.map +1 -1
  56. package/lib/Command-Line/files/Models.js +67 -0
  57. package/lib/Console/Command.d.ts +18 -0
  58. package/lib/Console/Command.d.ts.map +1 -1
  59. package/lib/Console/Command.js +29 -0
  60. package/lib/Container/index.d.ts.map +1 -1
  61. package/lib/Container/index.js +22 -8
  62. package/lib/Database/Database.d.ts +21 -0
  63. package/lib/Database/Database.d.ts.map +1 -0
  64. package/lib/Database/Database.js +55 -0
  65. package/lib/Database/DatabaseServiceProvider.d.ts +22 -0
  66. package/lib/Database/DatabaseServiceProvider.d.ts.map +1 -0
  67. package/lib/Database/DatabaseServiceProvider.js +50 -0
  68. package/lib/Database/Drivers/KnexDriver.d.ts +13 -0
  69. package/lib/Database/Drivers/KnexDriver.d.ts.map +1 -0
  70. package/lib/Database/Drivers/KnexDriver.js +29 -0
  71. package/lib/Database/Drivers/MongooseDriver.d.ts +20 -0
  72. package/lib/Database/Drivers/MongooseDriver.d.ts.map +1 -0
  73. package/lib/Database/Drivers/MongooseDriver.js +57 -0
  74. package/lib/Database/Drivers/SequelizeDriver.d.ts +24 -0
  75. package/lib/Database/Drivers/SequelizeDriver.d.ts.map +1 -0
  76. package/lib/Database/Drivers/SequelizeDriver.js +82 -0
  77. package/lib/Database/index.d.ts +7 -0
  78. package/lib/Database/index.d.ts.map +1 -0
  79. package/lib/Database/index.js +11 -0
  80. package/lib/Database/interface.d.ts +14 -0
  81. package/lib/Database/interface.d.ts.map +1 -0
  82. package/lib/Database/interface.js +2 -0
  83. package/lib/Database/type.d.ts +18 -0
  84. package/lib/Database/type.d.ts.map +1 -0
  85. package/lib/Database/type.js +2 -0
  86. package/lib/Error/DisplayErrorCode.d.ts.map +1 -1
  87. package/lib/Error/DisplayErrorCode.js +27 -17
  88. package/lib/Error/MissMatchTokenException/index.d.ts +4 -0
  89. package/lib/Error/MissMatchTokenException/index.d.ts.map +1 -0
  90. package/lib/Error/MissMatchTokenException/index.js +9 -0
  91. package/lib/Error/SocialiteAuthError/SocialiteAuthError.d.ts +9 -0
  92. package/lib/Error/SocialiteAuthError/SocialiteAuthError.d.ts.map +1 -0
  93. package/lib/Error/SocialiteAuthError/SocialiteAuthError.js +17 -0
  94. package/lib/Global/helpers.d.ts.map +1 -1
  95. package/lib/Global/helpers.js +7 -6
  96. package/lib/Http/index.d.ts +3 -1
  97. package/lib/Http/index.d.ts.map +1 -1
  98. package/lib/Http/index.js +26 -5
  99. package/lib/Interface/index.d.ts +17 -3
  100. package/lib/Interface/index.d.ts.map +1 -1
  101. package/lib/Jcc-eloquent/lib/Builder.d.ts +12 -1
  102. package/lib/Jcc-eloquent/lib/Builder.d.ts.map +1 -1
  103. package/lib/Jcc-eloquent/lib/Builder.js +119 -5
  104. package/lib/Jcc-eloquent/lib/Database/index.d.ts.map +1 -1
  105. package/lib/Jcc-eloquent/lib/Database/index.js +2 -1
  106. package/lib/Jcc-eloquent/lib/Interfaces/index.d.ts +37 -2
  107. package/lib/Jcc-eloquent/lib/Interfaces/index.d.ts.map +1 -1
  108. package/lib/Jcc-eloquent/lib/Migration.d.ts +6 -0
  109. package/lib/Jcc-eloquent/lib/Migration.d.ts.map +1 -1
  110. package/lib/Jcc-eloquent/lib/Migration.js +24 -2
  111. package/lib/Jcc-eloquent/lib/Model.d.ts +24 -7
  112. package/lib/Jcc-eloquent/lib/Model.d.ts.map +1 -1
  113. package/lib/Jcc-eloquent/lib/Model.js +35 -2
  114. package/lib/Jcc-eloquent/lib/QueryBuilder.d.ts +2 -1
  115. package/lib/Jcc-eloquent/lib/QueryBuilder.d.ts.map +1 -1
  116. package/lib/Jcc-eloquent/lib/QueryBuilder.js +10 -1
  117. package/lib/Jcc-eloquent/lib/Rollback.d.ts.map +1 -1
  118. package/lib/Jcc-eloquent/lib/Rollback.js +9 -2
  119. package/lib/Jcc-eloquent/lib/Schema/BaseSchemaEntity/index.d.ts.map +1 -1
  120. package/lib/Jcc-eloquent/lib/Schema/BaseSchemaEntity/index.js +3 -3
  121. package/lib/Jcc-eloquent/lib/Schema/BluePrint/index.d.ts +6 -2
  122. package/lib/Jcc-eloquent/lib/Schema/BluePrint/index.d.ts.map +1 -1
  123. package/lib/Jcc-eloquent/lib/Schema/BluePrint/index.js +41 -12
  124. package/lib/Jcc-eloquent/lib/Schema/Translator/Sqlite.d.ts.map +1 -1
  125. package/lib/Jcc-eloquent/lib/Schema/Translator/Sqlite.js +21 -3
  126. package/lib/Jcc-eloquent/lib/Schema/Translator/postgres.d.ts +1 -0
  127. package/lib/Jcc-eloquent/lib/Schema/Translator/postgres.d.ts.map +1 -1
  128. package/lib/Jcc-eloquent/lib/Schema/Translator/postgres.js +70 -14
  129. package/lib/Jcc-eloquent/lib/Schema/index.d.ts +12 -0
  130. package/lib/Jcc-eloquent/lib/Schema/index.d.ts.map +1 -1
  131. package/lib/Jcc-eloquent/lib/Schema/index.js +27 -6
  132. package/lib/Jcc-eloquent/lib/utils/index.d.ts +13 -0
  133. package/lib/Jcc-eloquent/lib/utils/index.d.ts.map +1 -1
  134. package/lib/Jcc-eloquent/lib/utils/index.js +62 -0
  135. package/lib/Middleware/index.d.ts +1 -0
  136. package/lib/Middleware/index.d.ts.map +1 -1
  137. package/lib/Middleware/index.js +20 -8
  138. package/lib/Model/Sequelize.d.ts +3 -0
  139. package/lib/Model/Sequelize.d.ts.map +1 -0
  140. package/lib/Model/Sequelize.js +6 -0
  141. package/lib/Providers/RouteServiceProvider.d.ts.map +1 -1
  142. package/lib/Providers/RouteServiceProvider.js +3 -0
  143. package/lib/Providers/SessionServiceProvider.d.ts +12 -0
  144. package/lib/Providers/SessionServiceProvider.d.ts.map +1 -0
  145. package/lib/Providers/SessionServiceProvider.js +47 -0
  146. package/lib/Queue/Controllers/QueueControllers.d.ts +31 -0
  147. package/lib/Queue/Controllers/QueueControllers.d.ts.map +1 -0
  148. package/lib/Queue/Controllers/QueueControllers.js +126 -0
  149. package/lib/Queue/Drivers/DatabaseDriver.d.ts +6 -1
  150. package/lib/Queue/Drivers/DatabaseDriver.d.ts.map +1 -1
  151. package/lib/Queue/Drivers/DatabaseDriver.js +76 -21
  152. package/lib/Queue/Drivers/MemoryDriver.d.ts +17 -6
  153. package/lib/Queue/Drivers/MemoryDriver.d.ts.map +1 -1
  154. package/lib/Queue/Drivers/MemoryDriver.js +323 -14
  155. package/lib/Queue/Drivers/RedisDriver.d.ts +48 -0
  156. package/lib/Queue/Drivers/RedisDriver.d.ts.map +1 -0
  157. package/lib/Queue/Drivers/RedisDriver.js +533 -0
  158. package/lib/Queue/Job.d.ts +8 -0
  159. package/lib/Queue/Job.d.ts.map +1 -1
  160. package/lib/Queue/Job.js +25 -1
  161. package/lib/Queue/JobsLogger.d.ts.map +1 -1
  162. package/lib/Queue/JobsLogger.js +6 -3
  163. package/lib/Queue/Queue.d.ts +17 -0
  164. package/lib/Queue/Queue.d.ts.map +1 -1
  165. package/lib/Queue/Queue.js +146 -11
  166. package/lib/Queue/QueueServiceProvider.d.ts +6 -0
  167. package/lib/Queue/QueueServiceProvider.d.ts.map +1 -0
  168. package/lib/Queue/QueueServiceProvider.js +18 -0
  169. package/lib/Queue/Route/web.d.ts +2 -0
  170. package/lib/Queue/Route/web.d.ts.map +1 -0
  171. package/lib/Queue/Route/web.js +16 -0
  172. package/lib/Queue/index.d.ts +1 -0
  173. package/lib/Queue/index.d.ts.map +1 -1
  174. package/lib/Queue/index.js +3 -0
  175. package/lib/Queue/interface.d.ts +25 -0
  176. package/lib/Queue/interface.d.ts.map +1 -1
  177. package/lib/Queue/middleware/queueDashboardGuard.d.ts +7 -0
  178. package/lib/Queue/middleware/queueDashboardGuard.d.ts.map +1 -0
  179. package/lib/Queue/middleware/queueDashboardGuard.js +43 -0
  180. package/lib/Queue/type.d.ts +12 -1
  181. package/lib/Queue/type.d.ts.map +1 -1
  182. package/lib/Response/index.d.ts.map +1 -1
  183. package/lib/Response/index.js +6 -1
  184. package/lib/Routes/Route.d.ts +2 -2
  185. package/lib/Routes/Route.d.ts.map +1 -1
  186. package/lib/Routes/RouteBuilder.d.ts +2 -2
  187. package/lib/Routes/RouteBuilder.d.ts.map +1 -1
  188. package/lib/Security/CsrfMiddleware.d.ts +37 -0
  189. package/lib/Security/CsrfMiddleware.d.ts.map +1 -0
  190. package/lib/Security/CsrfMiddleware.js +85 -0
  191. package/lib/Security/MethodSpoofingMiddleware.d.ts +36 -0
  192. package/lib/Security/MethodSpoofingMiddleware.d.ts.map +1 -0
  193. package/lib/Security/MethodSpoofingMiddleware.js +51 -0
  194. package/lib/Security/index.d.ts +5 -0
  195. package/lib/Security/index.d.ts.map +1 -0
  196. package/lib/Security/index.js +7 -0
  197. package/lib/Session/DatabaseSession.d.ts +9 -3
  198. package/lib/Session/DatabaseSession.d.ts.map +1 -1
  199. package/lib/Session/DatabaseSession.js +38 -36
  200. package/lib/Session/ExpressJccSession.d.ts +23 -0
  201. package/lib/Session/ExpressJccSession.d.ts.map +1 -0
  202. package/lib/Session/ExpressJccSession.js +110 -0
  203. package/lib/Session/RedisSession.d.ts +2 -2
  204. package/lib/Session/RedisSession.d.ts.map +1 -1
  205. package/lib/Session/RedisSession.js +19 -5
  206. package/lib/Session/SessionManager.d.ts +18 -4
  207. package/lib/Session/SessionManager.d.ts.map +1 -1
  208. package/lib/Session/SessionManager.js +53 -17
  209. package/lib/Socialite/AbstractProvider.d.ts +60 -0
  210. package/lib/Socialite/AbstractProvider.d.ts.map +1 -0
  211. package/lib/Socialite/AbstractProvider.js +136 -0
  212. package/lib/Socialite/Drivers/facebook/FacebookDriver.d.ts +9 -0
  213. package/lib/Socialite/Drivers/facebook/FacebookDriver.d.ts.map +1 -0
  214. package/lib/Socialite/Drivers/facebook/FacebookDriver.js +40 -0
  215. package/lib/Socialite/Drivers/facebook/FacebookProvider.d.ts +15 -0
  216. package/lib/Socialite/Drivers/facebook/FacebookProvider.d.ts.map +1 -0
  217. package/lib/Socialite/Drivers/facebook/FacebookProvider.js +28 -0
  218. package/lib/Socialite/Drivers/github/GitHubDriver.d.ts +9 -0
  219. package/lib/Socialite/Drivers/github/GitHubDriver.d.ts.map +1 -0
  220. package/lib/Socialite/Drivers/github/GitHubDriver.js +54 -0
  221. package/lib/Socialite/Drivers/github/GitHubProvider.d.ts +15 -0
  222. package/lib/Socialite/Drivers/github/GitHubProvider.d.ts.map +1 -0
  223. package/lib/Socialite/Drivers/github/GitHubProvider.js +28 -0
  224. package/lib/Socialite/Drivers/gitlab/GitLabDriver.d.ts +10 -0
  225. package/lib/Socialite/Drivers/gitlab/GitLabDriver.d.ts.map +1 -0
  226. package/lib/Socialite/Drivers/gitlab/GitLabDriver.js +37 -0
  227. package/lib/Socialite/Drivers/gitlab/GitLabProvider.d.ts +15 -0
  228. package/lib/Socialite/Drivers/gitlab/GitLabProvider.d.ts.map +1 -0
  229. package/lib/Socialite/Drivers/gitlab/GitLabProvider.js +28 -0
  230. package/lib/Socialite/Drivers/google/GoogleDriver.d.ts +9 -0
  231. package/lib/Socialite/Drivers/google/GoogleDriver.d.ts.map +1 -0
  232. package/lib/Socialite/Drivers/google/GoogleDriver.js +39 -0
  233. package/lib/Socialite/Drivers/google/GoogleProvider.d.ts +15 -0
  234. package/lib/Socialite/Drivers/google/GoogleProvider.d.ts.map +1 -0
  235. package/lib/Socialite/Drivers/google/GoogleProvider.js +28 -0
  236. package/lib/Socialite/Drivers/slack/SlackDriver.d.ts +9 -0
  237. package/lib/Socialite/Drivers/slack/SlackDriver.d.ts.map +1 -0
  238. package/lib/Socialite/Drivers/slack/SlackDriver.js +41 -0
  239. package/lib/Socialite/Drivers/slack/SlackProvider.d.ts +16 -0
  240. package/lib/Socialite/Drivers/slack/SlackProvider.d.ts.map +1 -0
  241. package/lib/Socialite/Drivers/slack/SlackProvider.js +37 -0
  242. package/lib/Socialite/Drivers/twitter/TwitterDriver.d.ts +9 -0
  243. package/lib/Socialite/Drivers/twitter/TwitterDriver.d.ts.map +1 -0
  244. package/lib/Socialite/Drivers/twitter/TwitterDriver.js +57 -0
  245. package/lib/Socialite/Drivers/twitter/TwitterProvider.d.ts +16 -0
  246. package/lib/Socialite/Drivers/twitter/TwitterProvider.d.ts.map +1 -0
  247. package/lib/Socialite/Drivers/twitter/TwitterProvider.js +38 -0
  248. package/lib/Socialite/SocialUser.d.ts +42 -0
  249. package/lib/Socialite/SocialUser.d.ts.map +1 -0
  250. package/lib/Socialite/SocialUser.js +116 -0
  251. package/lib/Socialite/Socialite.d.ts +13 -0
  252. package/lib/Socialite/Socialite.d.ts.map +1 -0
  253. package/lib/Socialite/Socialite.js +41 -0
  254. package/lib/Socialite/SocialiteProvider.d.ts +9 -0
  255. package/lib/Socialite/SocialiteProvider.d.ts.map +1 -0
  256. package/lib/Socialite/SocialiteProvider.js +15 -0
  257. package/lib/Socialite/config.d.ts +7 -0
  258. package/lib/Socialite/config.d.ts.map +1 -0
  259. package/lib/Socialite/config.js +44 -0
  260. package/lib/Socialite/constant.d.ts +18 -0
  261. package/lib/Socialite/constant.d.ts.map +1 -0
  262. package/lib/Socialite/constant.js +20 -0
  263. package/lib/Socialite/index.d.ts +13 -0
  264. package/lib/Socialite/index.d.ts.map +1 -0
  265. package/lib/Socialite/index.js +25 -0
  266. package/lib/Socialite/types.d.ts +13 -0
  267. package/lib/Socialite/types.d.ts.map +1 -0
  268. package/lib/Socialite/types.js +2 -0
  269. package/lib/Templating-engine/benchmark.d.ts +7 -0
  270. package/lib/Templating-engine/benchmark.d.ts.map +1 -0
  271. package/lib/Templating-engine/benchmark.js +44 -0
  272. package/lib/Templating-engine/engineHelper.d.ts +37 -8
  273. package/lib/Templating-engine/engineHelper.d.ts.map +1 -1
  274. package/lib/Templating-engine/engineHelper.js +203 -26
  275. package/lib/Templating-engine/errors.d.ts +15 -0
  276. package/lib/Templating-engine/errors.d.ts.map +1 -0
  277. package/lib/Templating-engine/errors.js +35 -0
  278. package/lib/Templating-engine/expressions.d.ts +24 -0
  279. package/lib/Templating-engine/expressions.d.ts.map +1 -1
  280. package/lib/Templating-engine/expressions.js +27 -5
  281. package/lib/Templating-engine/index.d.ts +87 -17
  282. package/lib/Templating-engine/index.d.ts.map +1 -1
  283. package/lib/Templating-engine/index.js +701 -96
  284. package/lib/Templating-engine/plugins.d.ts +30 -0
  285. package/lib/Templating-engine/plugins.d.ts.map +1 -0
  286. package/lib/Templating-engine/plugins.js +47 -0
  287. package/lib/Type/index.d.ts +1 -0
  288. package/lib/Type/index.d.ts.map +1 -1
  289. package/lib/Validation/Validator/CustomValidation.d.ts.map +1 -1
  290. package/lib/Validation/Validator/CustomValidation.js +2 -2
  291. package/lib/Validation/Validator/helper.d.ts.map +1 -1
  292. package/lib/Validation/Validator/helper.js +8 -1
  293. package/lib/util/index.d.ts +42 -1
  294. package/lib/util/index.d.ts.map +1 -1
  295. package/lib/util/index.js +154 -17
  296. 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
+ }
@@ -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;
@@ -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;AAE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IAAI,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;IAapB,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;CAWrB;AAED,eAAO,MAAM,gBAAgB;;;;;;CAM5B,CAAC"}
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;AAGnC;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,GACvB,WAAW,MAAM,EACjB,OAAO,SAAS,EAChB,WAAW,MAAM,iBAkBlB,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 (process.env.DB_CONNECTION === "mongodb") {
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
  }
@@ -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 resolveModelBinding: (req: AppRequest, ModelClass: typeof Model, resolved: any) => Promise<any>;
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
@@ -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,GAAI,MAAM,MAAM,KAAG,GAC0B,CAAC;AAEnE;;GAEG;AACH,eAAO,MAAM,UAAU,QAAO,IAG7B,CAAC;AAEF,eAAO,MAAM,SAAS,GAAI,OAAO,MAAM,SAMtC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,aA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U,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}/${(0, exports.capitalize)(file)}`)}`);
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.log("Cannot find module");
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
- * Function to sign a JWT token.
132
- * @param {object} data - The data to be encoded in the token.
133
- * @returns {string} - Signed JWT token.
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
- // Wrap string payload in an object
139
- const payload = typeof data === "string" ? { id: data } : data;
140
- return jsonwebtoken_1.default.sign(payload, secret, options);
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 jobClass = require(`${getRootPath}/app/Jobs/${jobName}`);
222
- return jobClass[jobName];
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" && typeof User.findById === "function") {
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
- const modelParamName = Str_1.Str.camel(ModelClass.name);
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jcc-express-mvc",
3
- "version": "1.8.7",
3
+ "version": "1.8.21",
4
4
  "description": "express mvc structure",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",