@zintrust/core 0.1.19 → 0.1.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 (528) hide show
  1. package/README.md +10 -10
  2. package/bin/zintrust-main.d.ts.map +1 -1
  3. package/bin/zintrust-main.js +9 -0
  4. package/package.json +3 -2
  5. package/public/error-pages/404.html +145 -0
  6. package/public/error-pages/500.html +266 -0
  7. package/public/error-pages/error.css +628 -0
  8. package/public/error-pages/error.js +428 -0
  9. package/public/zintrust.svg +30 -0
  10. package/routes/api.d.ts.map +1 -1
  11. package/routes/api.js +41 -17
  12. package/routes/metrics.d.ts +9 -0
  13. package/routes/metrics.d.ts.map +1 -0
  14. package/routes/metrics.js +20 -0
  15. package/routes/openapi.d.ts +9 -0
  16. package/routes/openapi.d.ts.map +1 -0
  17. package/routes/openapi.js +76 -0
  18. package/src/boot/Application.d.ts +2 -2
  19. package/src/boot/Application.d.ts.map +1 -1
  20. package/src/boot/Application.js +66 -13
  21. package/src/boot/Server.d.ts +3 -2
  22. package/src/boot/Server.d.ts.map +1 -1
  23. package/src/boot/Server.js +39 -165
  24. package/src/boot/bootstrap.js +2 -0
  25. package/src/cache/Cache.d.ts +1 -1
  26. package/src/cache/Cache.d.ts.map +1 -1
  27. package/src/cache/CacheDriver.d.ts +4 -0
  28. package/src/cache/CacheDriver.d.ts.map +1 -1
  29. package/src/cache/drivers/KVDriver.d.ts +1 -1
  30. package/src/cache/drivers/KVDriver.d.ts.map +1 -1
  31. package/src/cache/drivers/MemoryDriver.d.ts +1 -1
  32. package/src/cache/drivers/MemoryDriver.d.ts.map +1 -1
  33. package/src/cache/drivers/MemoryDriver.js +16 -0
  34. package/src/cache/drivers/MongoDriver.d.ts +1 -1
  35. package/src/cache/drivers/MongoDriver.d.ts.map +1 -1
  36. package/src/cache/drivers/RedisDriver.d.ts +1 -1
  37. package/src/cache/drivers/RedisDriver.d.ts.map +1 -1
  38. package/src/cli/CLI.d.ts.map +1 -1
  39. package/src/cli/CLI.js +10 -4
  40. package/src/cli/commands/AddCommand.d.ts +2 -2
  41. package/src/cli/commands/AddCommand.d.ts.map +1 -1
  42. package/src/cli/commands/AddCommand.js +135 -58
  43. package/src/cli/commands/ConfigCommand.d.ts +1 -1
  44. package/src/cli/commands/ConfigCommand.d.ts.map +1 -1
  45. package/src/cli/commands/CreateCommand.d.ts +15 -0
  46. package/src/cli/commands/CreateCommand.d.ts.map +1 -0
  47. package/src/cli/commands/CreateCommand.js +143 -0
  48. package/src/cli/commands/D1MigrateCommand.d.ts +1 -1
  49. package/src/cli/commands/D1MigrateCommand.d.ts.map +1 -1
  50. package/src/cli/commands/D1MigrateCommand.js +16 -20
  51. package/src/cli/commands/DbSeedCommand.d.ts +9 -0
  52. package/src/cli/commands/DbSeedCommand.d.ts.map +1 -0
  53. package/src/cli/commands/DbSeedCommand.js +171 -0
  54. package/src/cli/commands/DebugCommand.d.ts +1 -1
  55. package/src/cli/commands/DebugCommand.d.ts.map +1 -1
  56. package/src/cli/commands/FixCommand.d.ts +1 -1
  57. package/src/cli/commands/FixCommand.d.ts.map +1 -1
  58. package/src/cli/commands/JwtDevCommand.d.ts +8 -0
  59. package/src/cli/commands/JwtDevCommand.d.ts.map +1 -0
  60. package/src/cli/commands/JwtDevCommand.js +114 -0
  61. package/src/cli/commands/KeyGenerateCommand.d.ts +1 -1
  62. package/src/cli/commands/KeyGenerateCommand.d.ts.map +1 -1
  63. package/src/cli/commands/LogsCommand.d.ts +2 -2
  64. package/src/cli/commands/LogsCommand.d.ts.map +1 -1
  65. package/src/cli/commands/LogsCommand.js +36 -2
  66. package/src/cli/commands/MakeMailTemplateCommand.d.ts +1 -1
  67. package/src/cli/commands/MakeMailTemplateCommand.d.ts.map +1 -1
  68. package/src/cli/commands/MakeNotificationTemplateCommand.d.ts +1 -1
  69. package/src/cli/commands/MakeNotificationTemplateCommand.d.ts.map +1 -1
  70. package/src/cli/commands/MigrateCommand.d.ts +1 -1
  71. package/src/cli/commands/MigrateCommand.d.ts.map +1 -1
  72. package/src/cli/commands/MigrateCommand.js +324 -35
  73. package/src/cli/commands/NewCommand.d.ts +1 -1
  74. package/src/cli/commands/NewCommand.d.ts.map +1 -1
  75. package/src/cli/commands/NewCommand.js +12 -4
  76. package/src/cli/commands/PluginCommand.d.ts +1 -1
  77. package/src/cli/commands/PluginCommand.d.ts.map +1 -1
  78. package/src/cli/commands/PrepareCommand.d.ts +1 -1
  79. package/src/cli/commands/PrepareCommand.d.ts.map +1 -1
  80. package/src/cli/commands/QACommand.d.ts +2 -2
  81. package/src/cli/commands/QACommand.d.ts.map +1 -1
  82. package/src/cli/commands/RoutesCommand.d.ts +10 -0
  83. package/src/cli/commands/RoutesCommand.d.ts.map +1 -0
  84. package/src/cli/commands/RoutesCommand.js +242 -0
  85. package/src/cli/commands/SimulateCommand.d.ts +1 -1
  86. package/src/cli/commands/SimulateCommand.d.ts.map +1 -1
  87. package/src/cli/commands/index.d.ts +3 -0
  88. package/src/cli/commands/index.d.ts.map +1 -1
  89. package/src/cli/commands/index.js +3 -0
  90. package/src/cli/config/ConfigManager.d.ts +1 -1
  91. package/src/cli/config/ConfigManager.d.ts.map +1 -1
  92. package/src/cli/config/ConfigValidator.d.ts +1 -1
  93. package/src/cli/config/ConfigValidator.d.ts.map +1 -1
  94. package/src/cli/config/ConfigValidator.js +1 -1
  95. package/src/cli/d1/D1SqlMigrations.d.ts +20 -0
  96. package/src/cli/d1/D1SqlMigrations.d.ts.map +1 -0
  97. package/src/cli/d1/D1SqlMigrations.js +229 -0
  98. package/src/cli/d1/WranglerConfig.d.ts +4 -0
  99. package/src/cli/d1/WranglerConfig.d.ts.map +1 -0
  100. package/src/cli/d1/WranglerConfig.js +122 -0
  101. package/src/cli/d1/WranglerD1.d.ts +11 -0
  102. package/src/cli/d1/WranglerD1.d.ts.map +1 -0
  103. package/src/cli/d1/WranglerD1.js +16 -0
  104. package/src/cli/scaffolding/ControllerGenerator.d.ts.map +1 -1
  105. package/src/cli/scaffolding/ControllerGenerator.js +76 -26
  106. package/src/cli/scaffolding/FactoryGenerator.d.ts.map +1 -1
  107. package/src/cli/scaffolding/FactoryGenerator.js +3 -1
  108. package/src/cli/scaffolding/GovernanceScaffolder.d.ts +23 -0
  109. package/src/cli/scaffolding/GovernanceScaffolder.d.ts.map +1 -0
  110. package/src/cli/scaffolding/GovernanceScaffolder.js +327 -0
  111. package/src/cli/scaffolding/MigrationGenerator.d.ts +10 -0
  112. package/src/cli/scaffolding/MigrationGenerator.d.ts.map +1 -1
  113. package/src/cli/scaffolding/MigrationGenerator.js +137 -51
  114. package/src/cli/scaffolding/ModelGenerator.js +1 -1
  115. package/src/cli/scaffolding/ProjectScaffolder.d.ts.map +1 -1
  116. package/src/cli/scaffolding/ProjectScaffolder.js +36 -4
  117. package/src/cli/scaffolding/RouteGenerator.d.ts.map +1 -1
  118. package/src/cli/scaffolding/RouteGenerator.js +79 -43
  119. package/src/cli/scaffolding/SeederGenerator.d.ts +5 -0
  120. package/src/cli/scaffolding/SeederGenerator.d.ts.map +1 -1
  121. package/src/cli/scaffolding/SeederGenerator.js +63 -15
  122. package/src/cli/scaffolding/ServiceScaffolder.d.ts.map +1 -1
  123. package/src/cli/scaffolding/ServiceScaffolder.js +28 -7
  124. package/src/cli/scaffolding/index.d.ts +2 -0
  125. package/src/cli/scaffolding/index.d.ts.map +1 -1
  126. package/src/cli/scaffolding/index.js +1 -0
  127. package/src/common/index.d.ts +8 -0
  128. package/src/common/index.d.ts.map +1 -1
  129. package/src/common/index.js +28 -0
  130. package/src/common/utility.d.ts +38 -0
  131. package/src/common/utility.d.ts.map +1 -0
  132. package/src/common/utility.js +101 -0
  133. package/src/config/FileLogWriter.d.ts +2 -1
  134. package/src/config/FileLogWriter.d.ts.map +1 -1
  135. package/src/config/FileLogWriter.js +83 -2
  136. package/src/config/app.d.ts.map +1 -1
  137. package/src/config/app.js +3 -1
  138. package/src/config/broadcast.d.ts +14 -28
  139. package/src/config/broadcast.d.ts.map +1 -1
  140. package/src/config/broadcast.js +69 -35
  141. package/src/config/cache.d.ts +13 -45
  142. package/src/config/cache.d.ts.map +1 -1
  143. package/src/config/cache.js +69 -25
  144. package/src/config/cloudflare.d.ts +1 -1
  145. package/src/config/cloudflare.d.ts.map +1 -1
  146. package/src/config/database.d.ts +22 -64
  147. package/src/config/database.d.ts.map +1 -1
  148. package/src/config/database.js +191 -37
  149. package/src/config/env.d.ts +12 -0
  150. package/src/config/env.d.ts.map +1 -1
  151. package/src/config/env.js +14 -0
  152. package/src/config/index.d.ts +33 -137
  153. package/src/config/index.d.ts.map +1 -1
  154. package/src/config/logging/KvLogger.js +1 -1
  155. package/src/config/logging/SlackLogger.js +2 -2
  156. package/src/config/mail.d.ts +19 -55
  157. package/src/config/mail.d.ts.map +1 -1
  158. package/src/config/mail.js +63 -21
  159. package/src/config/middleware.d.ts +44 -1
  160. package/src/config/middleware.d.ts.map +1 -1
  161. package/src/config/middleware.js +157 -5
  162. package/src/config/notification.d.ts +14 -27
  163. package/src/config/notification.d.ts.map +1 -1
  164. package/src/config/notification.js +82 -36
  165. package/src/config/queue.d.ts +21 -51
  166. package/src/config/queue.d.ts.map +1 -1
  167. package/src/config/queue.js +72 -27
  168. package/src/config/security.d.ts +1 -1
  169. package/src/config/security.js +1 -1
  170. package/src/config/storage.d.ts +27 -34
  171. package/src/config/storage.d.ts.map +1 -1
  172. package/src/config/storage.js +97 -56
  173. package/src/config/type.d.ts +13 -2
  174. package/src/config/type.d.ts.map +1 -1
  175. package/src/events/EventDispatcher.d.ts.map +1 -1
  176. package/src/events/EventDispatcher.js +6 -4
  177. package/src/exceptions/ZintrustError.d.ts +7 -0
  178. package/src/exceptions/ZintrustError.d.ts.map +1 -1
  179. package/src/exceptions/ZintrustError.js +56 -0
  180. package/src/features/Auth.d.ts +1 -1
  181. package/src/features/Auth.d.ts.map +1 -1
  182. package/src/features/Auth.js +3 -3
  183. package/src/features/Queue.js +1 -1
  184. package/src/functions/cloudflare.d.ts.map +1 -1
  185. package/src/functions/cloudflare.js +3 -14
  186. package/src/functions/deno.d.ts.map +1 -1
  187. package/src/functions/deno.js +3 -14
  188. package/src/functions/lambda.d.ts.map +1 -1
  189. package/src/functions/lambda.js +3 -14
  190. package/src/health/StartupHealthChecks.js +1 -1
  191. package/src/http/Controller.d.ts +2 -2
  192. package/src/http/Controller.d.ts.map +1 -1
  193. package/src/http/FileUpload.d.ts +68 -0
  194. package/src/http/FileUpload.d.ts.map +1 -0
  195. package/src/http/FileUpload.js +120 -0
  196. package/src/http/Kernel.d.ts +5 -5
  197. package/src/http/Kernel.d.ts.map +1 -1
  198. package/src/http/Kernel.js +139 -23
  199. package/src/http/Request.d.ts +20 -1
  200. package/src/http/Request.d.ts.map +1 -1
  201. package/src/http/Request.js +23 -0
  202. package/src/http/RequestContext.d.ts +6 -0
  203. package/src/http/RequestContext.d.ts.map +1 -1
  204. package/src/http/RequestContext.js +77 -1
  205. package/src/http/Response.d.ts +1 -1
  206. package/src/http/Response.d.ts.map +1 -1
  207. package/src/http/ValidationHelper.d.ts +78 -0
  208. package/src/http/ValidationHelper.d.ts.map +1 -0
  209. package/src/http/ValidationHelper.js +121 -0
  210. package/src/http/error-pages/ErrorPageRenderer.d.ts +17 -0
  211. package/src/http/error-pages/ErrorPageRenderer.d.ts.map +1 -0
  212. package/src/http/error-pages/ErrorPageRenderer.js +88 -0
  213. package/src/http/middleware/BodyParsingMiddleware.d.ts +12 -0
  214. package/src/http/middleware/BodyParsingMiddleware.d.ts.map +1 -0
  215. package/src/http/middleware/BodyParsingMiddleware.js +251 -0
  216. package/src/http/middleware/FileUploadMiddleware.d.ts +12 -0
  217. package/src/http/middleware/FileUploadMiddleware.d.ts.map +1 -0
  218. package/src/http/middleware/FileUploadMiddleware.js +74 -0
  219. package/src/http/parsers/BodyParsers.d.ts +32 -0
  220. package/src/http/parsers/BodyParsers.d.ts.map +1 -0
  221. package/src/http/parsers/BodyParsers.js +159 -0
  222. package/src/http/parsers/MultipartParser.d.ts +33 -0
  223. package/src/http/parsers/MultipartParser.d.ts.map +1 -0
  224. package/src/http/parsers/MultipartParser.js +156 -0
  225. package/src/http/parsers/MultipartParserRegistry.d.ts +34 -0
  226. package/src/http/parsers/MultipartParserRegistry.d.ts.map +1 -0
  227. package/src/http/parsers/MultipartParserRegistry.js +20 -0
  228. package/src/http/validated.d.ts +12 -0
  229. package/src/http/validated.d.ts.map +1 -0
  230. package/src/http/validated.js +41 -0
  231. package/src/index.d.ts +73 -12
  232. package/src/index.d.ts.map +1 -1
  233. package/src/index.js +60 -5
  234. package/src/microservices/PostgresAdapter.d.ts.map +1 -1
  235. package/src/microservices/PostgresAdapter.js +0 -1
  236. package/src/microservices/RequestTracingMiddleware.d.ts +2 -2
  237. package/src/microservices/RequestTracingMiddleware.d.ts.map +1 -1
  238. package/src/microservices/RequestTracingMiddleware.js +3 -0
  239. package/src/microservices/ServiceAuthMiddleware.d.ts +2 -2
  240. package/src/microservices/ServiceAuthMiddleware.d.ts.map +1 -1
  241. package/src/middleware/AuthMiddleware.d.ts +10 -0
  242. package/src/middleware/AuthMiddleware.d.ts.map +1 -0
  243. package/src/middleware/AuthMiddleware.js +16 -0
  244. package/src/middleware/CsrfMiddleware.d.ts +11 -1
  245. package/src/middleware/CsrfMiddleware.d.ts.map +1 -1
  246. package/src/middleware/CsrfMiddleware.js +33 -0
  247. package/src/middleware/JwtAuthMiddleware.d.ts +11 -0
  248. package/src/middleware/JwtAuthMiddleware.d.ts.map +1 -0
  249. package/src/middleware/JwtAuthMiddleware.js +73 -0
  250. package/src/middleware/LoggingMiddleware.d.ts.map +1 -1
  251. package/src/middleware/LoggingMiddleware.js +8 -3
  252. package/src/middleware/MiddlewareStack.d.ts +2 -2
  253. package/src/middleware/MiddlewareStack.d.ts.map +1 -1
  254. package/src/middleware/RateLimiter.d.ts +2 -2
  255. package/src/middleware/RateLimiter.d.ts.map +1 -1
  256. package/src/middleware/SanitizeBodyMiddleware.d.ts +12 -0
  257. package/src/middleware/SanitizeBodyMiddleware.d.ts.map +1 -0
  258. package/src/middleware/SanitizeBodyMiddleware.js +31 -0
  259. package/src/middleware/SecurityMiddleware.d.ts +1 -1
  260. package/src/middleware/SecurityMiddleware.d.ts.map +1 -1
  261. package/src/middleware/SessionMiddleware.d.ts +1 -1
  262. package/src/middleware/SessionMiddleware.d.ts.map +1 -1
  263. package/src/middleware/ValidationMiddleware.d.ts +25 -0
  264. package/src/middleware/ValidationMiddleware.d.ts.map +1 -0
  265. package/src/middleware/ValidationMiddleware.js +251 -0
  266. package/src/migrations/MigrationDiscovery.d.ts +5 -0
  267. package/src/migrations/MigrationDiscovery.d.ts.map +1 -0
  268. package/src/migrations/MigrationDiscovery.js +16 -0
  269. package/src/migrations/MigrationLoader.d.ts +5 -0
  270. package/src/migrations/MigrationLoader.d.ts.map +1 -0
  271. package/src/migrations/MigrationLoader.js +43 -0
  272. package/src/migrations/MigrationLock.d.ts +4 -0
  273. package/src/migrations/MigrationLock.d.ts.map +1 -0
  274. package/src/migrations/MigrationLock.js +33 -0
  275. package/src/migrations/Migrator.d.ts +23 -0
  276. package/src/migrations/Migrator.d.ts.map +1 -0
  277. package/src/migrations/Migrator.js +4 -0
  278. package/src/migrations/MigratorFactory.d.ts +25 -0
  279. package/src/migrations/MigratorFactory.d.ts.map +1 -0
  280. package/src/migrations/MigratorFactory.js +339 -0
  281. package/src/migrations/schema/Blueprint.d.ts +5 -0
  282. package/src/migrations/schema/Blueprint.d.ts.map +1 -0
  283. package/src/migrations/schema/Blueprint.js +189 -0
  284. package/src/migrations/schema/Schema.d.ts +8 -0
  285. package/src/migrations/schema/Schema.d.ts.map +1 -0
  286. package/src/migrations/schema/Schema.js +141 -0
  287. package/src/migrations/schema/SchemaCompiler.d.ts +20 -0
  288. package/src/migrations/schema/SchemaCompiler.d.ts.map +1 -0
  289. package/src/migrations/schema/SchemaCompiler.js +262 -0
  290. package/src/migrations/schema/index.d.ts +5 -0
  291. package/src/migrations/schema/index.d.ts.map +1 -0
  292. package/src/migrations/schema/index.js +3 -0
  293. package/src/migrations/schema/types.d.ts +86 -0
  294. package/src/migrations/schema/types.d.ts.map +1 -0
  295. package/src/migrations/schema/types.js +1 -0
  296. package/src/migrations/types.d.ts +45 -0
  297. package/src/migrations/types.d.ts.map +1 -0
  298. package/src/migrations/types.js +1 -0
  299. package/src/node-singletons/crypto.d.ts +1 -1
  300. package/src/node-singletons/crypto.d.ts.map +1 -1
  301. package/src/node-singletons/crypto.js +1 -1
  302. package/src/node-singletons/fs.d.ts +2 -2
  303. package/src/node-singletons/fs.d.ts.map +1 -1
  304. package/src/node-singletons/fs.js +1 -1
  305. package/src/node-singletons/util.d.ts +6 -0
  306. package/src/node-singletons/util.d.ts.map +1 -0
  307. package/src/node-singletons/util.js +5 -0
  308. package/src/node.d.ts +3 -1
  309. package/src/node.d.ts.map +1 -1
  310. package/src/node.js +6 -2
  311. package/src/observability/OpenTelemetry.d.ts +62 -0
  312. package/src/observability/OpenTelemetry.d.ts.map +1 -0
  313. package/src/observability/OpenTelemetry.js +167 -0
  314. package/src/observability/PrometheusMetrics.d.ts +25 -0
  315. package/src/observability/PrometheusMetrics.d.ts.map +1 -0
  316. package/src/observability/PrometheusMetrics.js +114 -0
  317. package/src/openapi/OpenApiGenerator.d.ts +68 -0
  318. package/src/openapi/OpenApiGenerator.d.ts.map +1 -0
  319. package/src/openapi/OpenApiGenerator.js +287 -0
  320. package/src/orm/Database.d.ts +5 -2
  321. package/src/orm/Database.d.ts.map +1 -1
  322. package/src/orm/Database.js +219 -63
  323. package/src/orm/DatabaseAdapter.d.ts +14 -0
  324. package/src/orm/DatabaseAdapter.d.ts.map +1 -1
  325. package/src/orm/DatabaseAdapterRegistry.d.ts.map +1 -1
  326. package/src/orm/DatabaseAdapterRegistry.js +3 -1
  327. package/src/orm/DatabaseRuntimeRegistration.d.ts.map +1 -1
  328. package/src/orm/DatabaseRuntimeRegistration.js +12 -0
  329. package/src/orm/Model.d.ts +30 -2
  330. package/src/orm/Model.d.ts.map +1 -1
  331. package/src/orm/Model.js +255 -62
  332. package/src/orm/QueryBuilder.d.ts +22 -1
  333. package/src/orm/QueryBuilder.d.ts.map +1 -1
  334. package/src/orm/QueryBuilder.js +406 -99
  335. package/src/orm/Relationships.d.ts +7 -1
  336. package/src/orm/Relationships.d.ts.map +1 -1
  337. package/src/orm/Relationships.js +18 -0
  338. package/src/orm/SchemaCompiler.d.ts +9 -0
  339. package/src/orm/SchemaCompiler.d.ts.map +1 -0
  340. package/src/orm/SchemaCompiler.js +145 -0
  341. package/src/orm/adapters/D1Adapter.d.ts +1 -1
  342. package/src/orm/adapters/D1Adapter.d.ts.map +1 -1
  343. package/src/orm/adapters/MySQLAdapter.d.ts +1 -1
  344. package/src/orm/adapters/MySQLAdapter.d.ts.map +1 -1
  345. package/src/orm/adapters/MySQLAdapter.js +88 -69
  346. package/src/orm/adapters/PostgreSQLAdapter.d.ts +1 -1
  347. package/src/orm/adapters/PostgreSQLAdapter.d.ts.map +1 -1
  348. package/src/orm/adapters/PostgreSQLAdapter.js +88 -69
  349. package/src/orm/adapters/SQLServerAdapter.d.ts +1 -1
  350. package/src/orm/adapters/SQLServerAdapter.d.ts.map +1 -1
  351. package/src/orm/adapters/SQLiteAdapter.d.ts +1 -1
  352. package/src/orm/adapters/SQLiteAdapter.d.ts.map +1 -1
  353. package/src/orm/adapters/SQLiteAdapter.js +59 -3
  354. package/src/orm/maintenance/SqliteMaintenance.d.ts +5 -0
  355. package/src/orm/maintenance/SqliteMaintenance.d.ts.map +1 -0
  356. package/src/orm/maintenance/SqliteMaintenance.js +14 -0
  357. package/src/orm/migrations/MigrationStore.d.ts +38 -0
  358. package/src/orm/migrations/MigrationStore.d.ts.map +1 -0
  359. package/src/orm/migrations/MigrationStore.js +157 -0
  360. package/src/performance/CodeGenerationBenchmark.d.ts.map +1 -1
  361. package/src/performance/Optimizer.d.ts +7 -6
  362. package/src/performance/Optimizer.d.ts.map +1 -1
  363. package/src/performance/Optimizer.js +170 -55
  364. package/src/profiling/MemoryProfiler.d.ts +1 -1
  365. package/src/profiling/MemoryProfiler.d.ts.map +1 -1
  366. package/src/profiling/N1Detector.d.ts +1 -1
  367. package/src/profiling/N1Detector.d.ts.map +1 -1
  368. package/src/profiling/QueryLogger.d.ts +1 -1
  369. package/src/profiling/QueryLogger.d.ts.map +1 -1
  370. package/src/profiling/RequestProfiler.d.ts +3 -3
  371. package/src/profiling/RequestProfiler.d.ts.map +1 -1
  372. package/src/routes/metrics.d.ts +2 -0
  373. package/src/routes/metrics.d.ts.map +1 -0
  374. package/src/routes/metrics.js +1 -0
  375. package/src/routing/CoreRoutes.d.ts +12 -0
  376. package/src/routing/CoreRoutes.d.ts.map +1 -0
  377. package/src/routing/CoreRoutes.js +151 -0
  378. package/src/routing/RouteRegistry.d.ts +39 -0
  379. package/src/routing/RouteRegistry.d.ts.map +1 -0
  380. package/src/routing/RouteRegistry.js +44 -0
  381. package/src/routing/Router.d.ts +26 -9
  382. package/src/routing/Router.d.ts.map +1 -1
  383. package/src/routing/Router.js +79 -35
  384. package/src/routing/common.d.ts +15 -0
  385. package/src/routing/common.d.ts.map +1 -0
  386. package/src/routing/common.js +47 -0
  387. package/src/routing/doc.d.ts +27 -0
  388. package/src/routing/doc.d.ts.map +1 -0
  389. package/src/routing/doc.js +110 -0
  390. package/src/routing/error.d.ts +21 -0
  391. package/src/routing/error.d.ts.map +1 -0
  392. package/src/routing/error.js +126 -0
  393. package/src/routing/errorPages.d.ts +14 -0
  394. package/src/routing/errorPages.d.ts.map +1 -0
  395. package/src/routing/errorPages.js +103 -0
  396. package/src/routing/publicRoot.d.ts +27 -0
  397. package/src/routing/publicRoot.d.ts.map +1 -0
  398. package/src/routing/publicRoot.js +110 -0
  399. package/src/runtime/PluginAutoImports.d.ts +21 -0
  400. package/src/runtime/PluginAutoImports.d.ts.map +1 -0
  401. package/src/runtime/PluginAutoImports.js +59 -0
  402. package/src/runtime/PluginManager.d.ts +1 -5
  403. package/src/runtime/PluginManager.d.ts.map +1 -1
  404. package/src/runtime/PluginManager.js +25 -18
  405. package/src/runtime/RuntimeDetector.d.ts +1 -1
  406. package/src/runtime/RuntimeDetector.d.ts.map +1 -1
  407. package/src/runtime/StartupConfigFileRegistry.d.ts +20 -0
  408. package/src/runtime/StartupConfigFileRegistry.d.ts.map +1 -0
  409. package/src/runtime/StartupConfigFileRegistry.js +44 -0
  410. package/src/runtime/adapters/CloudflareAdapter.d.ts +1 -1
  411. package/src/runtime/adapters/CloudflareAdapter.d.ts.map +1 -1
  412. package/src/runtime/adapters/CloudflareAdapter.js +1 -1
  413. package/src/runtime/adapters/DenoAdapter.d.ts +1 -1
  414. package/src/runtime/adapters/DenoAdapter.d.ts.map +1 -1
  415. package/src/runtime/adapters/DenoAdapter.js +1 -1
  416. package/src/runtime/adapters/LambdaAdapter.d.ts +1 -1
  417. package/src/runtime/adapters/LambdaAdapter.d.ts.map +1 -1
  418. package/src/runtime/adapters/LambdaAdapter.js +1 -1
  419. package/src/runtime/adapters/NodeServerAdapter.d.ts +1 -1
  420. package/src/runtime/adapters/NodeServerAdapter.d.ts.map +1 -1
  421. package/src/runtime/getKernel.d.ts +9 -0
  422. package/src/runtime/getKernel.d.ts.map +1 -0
  423. package/src/runtime/getKernel.js +27 -0
  424. package/src/runtime/useFileLoader.d.ts +26 -0
  425. package/src/runtime/useFileLoader.d.ts.map +1 -0
  426. package/src/runtime/useFileLoader.js +188 -0
  427. package/src/scripts/TemplateImportsCheck.js +40 -0
  428. package/src/scripts/TemplateSync.js +90 -24
  429. package/src/security/Encryptor.d.ts.map +1 -1
  430. package/src/security/Encryptor.js +64 -7
  431. package/src/security/JwtManager.d.ts +1 -0
  432. package/src/security/JwtManager.d.ts.map +1 -1
  433. package/src/security/JwtManager.js +33 -0
  434. package/src/security/Sanitizer.d.ts +76 -0
  435. package/src/security/Sanitizer.d.ts.map +1 -0
  436. package/src/security/Sanitizer.js +412 -0
  437. package/src/security/TokenRevocation.d.ts +7 -0
  438. package/src/security/TokenRevocation.d.ts.map +1 -0
  439. package/src/security/TokenRevocation.js +57 -0
  440. package/src/security/XssProtection.d.ts.map +1 -1
  441. package/src/security/XssProtection.js +62 -14
  442. package/src/seeders/SeederDiscovery.d.ts +5 -0
  443. package/src/seeders/SeederDiscovery.d.ts.map +1 -0
  444. package/src/seeders/SeederDiscovery.js +21 -0
  445. package/src/seeders/SeederLoader.d.ts +5 -0
  446. package/src/seeders/SeederLoader.d.ts.map +1 -0
  447. package/src/seeders/SeederLoader.js +60 -0
  448. package/src/seeders/types.d.ts +18 -0
  449. package/src/seeders/types.d.ts.map +1 -0
  450. package/src/seeders/types.js +1 -0
  451. package/src/session/SessionManager.js +1 -1
  452. package/src/templates/adapters/MySQLAdapter.ts.tpl +109 -85
  453. package/src/templates/adapters/PostgreSQLAdapter.ts.tpl +129 -88
  454. package/src/templates/adapters/SQLServerAdapter.ts.tpl +5 -9
  455. package/src/templates/adapters/SQLiteAdapter.ts.tpl +78 -11
  456. package/src/templates/features/Queue.ts.tpl +3 -2
  457. package/src/templates/project/basic/app/Controllers/AuthController.ts.tpl +217 -0
  458. package/src/templates/project/basic/app/Controllers/UserController.ts.tpl +1 -12
  459. package/src/templates/project/basic/app/Types/controller.ts.tpl +46 -0
  460. package/src/templates/project/basic/config/FileLogWriter.ts.tpl +5 -236
  461. package/src/templates/project/basic/config/SecretsManager.ts.tpl +10 -447
  462. package/src/templates/project/basic/config/StartupConfigValidator.ts.tpl +9 -268
  463. package/src/templates/project/basic/config/app.ts.tpl +13 -153
  464. package/src/templates/project/basic/config/broadcast.ts.tpl +29 -126
  465. package/src/templates/project/basic/config/cache.ts.tpl +12 -70
  466. package/src/templates/project/basic/config/cloudflare.ts.tpl +4 -39
  467. package/src/templates/project/basic/config/constants.ts.tpl +9 -65
  468. package/src/templates/project/basic/config/database.ts.tpl +66 -123
  469. package/src/templates/project/basic/config/env.ts.tpl +5 -169
  470. package/src/templates/project/basic/config/features.ts.tpl +6 -54
  471. package/src/templates/project/basic/config/index.ts.tpl +8 -23
  472. package/src/templates/project/basic/config/logging/HttpLogger.ts.tpl +7 -114
  473. package/src/templates/project/basic/config/mail.ts.tpl +9 -62
  474. package/src/templates/project/basic/config/microservices.ts.tpl +11 -97
  475. package/src/templates/project/basic/config/middleware.ts.tpl +25 -43
  476. package/src/templates/project/basic/config/notification.ts.tpl +13 -114
  477. package/src/templates/project/basic/config/queue.ts.tpl +9 -40
  478. package/src/templates/project/basic/config/security.ts.tpl +11 -163
  479. package/src/templates/project/basic/config/startup.ts.tpl +10 -21
  480. package/src/templates/project/basic/config/storage.ts.tpl +57 -137
  481. package/src/templates/project/basic/config/type.ts.tpl +32 -451
  482. package/src/templates/project/basic/database/factories/UserFactory.ts.tpl +80 -0
  483. package/src/templates/project/basic/database/migrations/create_tasks_table.ts.tpl +28 -0
  484. package/src/templates/project/basic/database/migrations/create_users_table.ts.tpl +29 -0
  485. package/src/templates/project/basic/database/seeders/DatabaseSeeder.ts.tpl +19 -0
  486. package/src/templates/project/basic/database/seeders/UserSeeder.ts.tpl +18 -0
  487. package/src/templates/project/basic/database/seeders/index.ts.tpl +2 -0
  488. package/src/templates/project/basic/routes/api.ts.tpl +71 -33
  489. package/src/templates/project/basic/routes/metrics.ts.tpl +22 -0
  490. package/src/templates/project/basic/src/index.ts.tpl +3 -0
  491. package/src/templates/project/basic/tsconfig.json.tpl +12 -11
  492. package/src/testing/TestEnvironment.d.ts +40 -0
  493. package/src/testing/TestEnvironment.d.ts.map +1 -0
  494. package/src/testing/TestEnvironment.js +141 -0
  495. package/src/testing/TestHttp.d.ts +29 -0
  496. package/src/testing/TestHttp.d.ts.map +1 -0
  497. package/src/testing/TestHttp.js +96 -0
  498. package/src/testing/index.d.ts +5 -0
  499. package/src/testing/index.d.ts.map +1 -0
  500. package/src/testing/index.js +2 -0
  501. package/src/time/DateTime.d.ts +181 -0
  502. package/src/time/DateTime.d.ts.map +1 -0
  503. package/src/time/DateTime.js +300 -0
  504. package/src/time/index.d.ts +7 -0
  505. package/src/time/index.d.ts.map +1 -0
  506. package/src/time/index.js +5 -0
  507. package/src/tools/http/Http.d.ts.map +1 -1
  508. package/src/tools/http/Http.js +4 -0
  509. package/src/tools/mail/drivers/Smtp.js +1 -1
  510. package/src/tools/queue/drivers/InMemory.d.ts +1 -1
  511. package/src/tools/queue/drivers/InMemory.d.ts.map +1 -1
  512. package/src/tools/queue/drivers/InMemory.js +1 -1
  513. package/src/tools/queue/drivers/Redis.d.ts +1 -1
  514. package/src/tools/queue/drivers/Redis.d.ts.map +1 -1
  515. package/src/tools/queue/drivers/Redis.js +1 -1
  516. package/src/validation/ValidationError.d.ts.map +1 -1
  517. package/src/validation/ValidationError.js +4 -2
  518. package/src/validation/Validator.d.ts +49 -16
  519. package/src/validation/Validator.d.ts.map +1 -1
  520. package/src/validation/Validator.js +307 -5
  521. package/src/common/uuid.d.ts +0 -3
  522. package/src/common/uuid.d.ts.map +0 -1
  523. package/src/common/uuid.js +0 -30
  524. package/src/templates/project/basic/.env.example.tpl +0 -74
  525. package/src/templates/project/basic/.env.tpl +0 -166
  526. package/src/templates/project/basic/config/logging/KvLogger.ts.tpl +0 -181
  527. package/src/templates/project/basic/config/logging/SlackLogger.ts.tpl +0 -156
  528. package/src/templates/project/basic/database/migrations/index.ts.tpl +0 -2
@@ -1,166 +0,0 @@
1
- # Zintrust Framework - Environment Configuration
2
- # Copy this file to .env and configure for your environment
3
-
4
- # ============================================================================
5
- # APPLICATION
6
- # ============================================================================
7
-
8
- # Environment: development | staging | production
9
- NODE_ENV=development
10
-
11
- # Application Name
12
- APP_NAME=Zintrust App
13
-
14
- # Server Configuration
15
- HOST=
16
- PORT=
17
-
18
- # Application Encryption Key (base64 required for production)
19
- # Generate with: node -e "console.log(require('crypto').randomBytes(32).toString('base64'))"
20
- # Used for: encryption, CSRF tokens, session tokens, API keys
21
- APP_KEY=
22
-
23
- # ============================================================================
24
- # DATABASE
25
- # ============================================================================
26
-
27
- # Database Connection Driver
28
- # Options: sqlite | postgresql | mysql | sqlserver | d1
29
- DB_CONNECTION=
30
-
31
- # SQLite (default for development)
32
- DB_PATH=
33
-
34
- # PostgreSQL
35
- # DB_HOST=localhost
36
- # DB_PORT=5432
37
- # DB_DATABASE=zintrust
38
- # DB_USERNAME=postgres
39
- # DB_PASSWORD=postgres
40
-
41
- # MySQL
42
- # DB_HOST=localhost
43
- # DB_PORT=3306
44
- # DB_DATABASE=zintrust
45
- # DB_USERNAME=root
46
- # DB_PASSWORD=password
47
-
48
- # SQL Server
49
- # DB_HOST=localhost
50
- # DB_PORT=1433
51
- # DB_DATABASE=zintrust
52
- # DB_USERNAME=sa
53
- # DB_PASSWORD=Password123
54
-
55
- # ============================================================================
56
- # ADVANCED DATABASE FEATURES
57
- # ============================================================================
58
-
59
- # Raw SQL Query Support
60
- # WARNING: Only enable in development. Bypasses QueryBuilder safety.
61
- # This is checked once at application bootstrap, cached in memory.
62
- # Feature flag is initialized at startup - no runtime changes possible.
63
- USE_RAW_QRY=
64
-
65
- # ============================================================================
66
- # CACHE
67
- # ============================================================================
68
-
69
- # Cache Driver: memory | redis | mongodb | kv
70
- # - kv: Cloudflare Workers only (requires a KV binding named "CACHE")
71
- CACHE_DRIVER=
72
-
73
- # Redis Configuration (if using Redis)
74
- # REDIS_HOST=localhost
75
- # REDIS_PORT=6379
76
-
77
- # MongoDB Cache (if using mongodb)
78
- # Uses MongoDB Atlas Data API (HTTPS)
79
- # MONGO_URI=https://data.mongodb-api.com/app/<app-id>/endpoint/data/v1
80
- # MONGO_DB=zintrust_cache
81
-
82
- # ============================================================================
83
- # LOGGING
84
- # ============================================================================
85
-
86
- # Log Level: debug | info | warn | error
87
- LOG_LEVEL=
88
-
89
- # Log Channel: console | file | all
90
- LOG_CHANNEL=
91
-
92
- # ============================================================================
93
- # SECURITY
94
- # ============================================================================
95
-
96
- # JWT Secret for authentication
97
- JWT_SECRET=
98
-
99
- # Session Configuration
100
- SESSION_DRIVER=
101
- SESSION_LIFETIME=
102
-
103
- # CORS Configuration
104
- CORS_ORIGINS=
105
-
106
- # ============================================================================
107
- # MICROSERVICES
108
- # ============================================================================
109
-
110
- # Enable Microservices
111
- MICROSERVICES=
112
-
113
- # Comma-separated list of services to load
114
- SERVICES=
115
-
116
- # Service Discovery
117
- SERVICE_DISCOVERY=
118
-
119
- # Request Tracing
120
- MICROSERVICES_TRACING=
121
- MICROSERVICES_TRACING_RATE=
122
-
123
- # ============================================================================
124
- # SONARQUBE / SONARCLOUD
125
- # ============================================================================
126
-
127
- # SonarQube Server
128
- SONAR_HOST_URL=
129
-
130
- # SonarCloud
131
- # SONAR_HOST_URL=https://sonarcloud.io
132
- # SONAR_TOKEN=your_token
133
- # SONAR_ORGANIZATION=your-organization
134
-
135
- # ============================================================================
136
- # EXTERNAL SERVICES
137
- # ============================================================================
138
-
139
- # Snyk Security Token
140
- # SNYK_TOKEN=your_token
141
-
142
- # SendGrid (Email)
143
- # SENDGRID_API_KEY=your_api_key
144
-
145
- # Stripe (Payments)
146
- # STRIPE_SECRET_KEY=your_secret_key
147
- # STRIPE_PUBLIC_KEY=your_public_key
148
-
149
- # AWS S3 (File Storage)
150
- # AWS_ACCESS_KEY_ID=your_access_key
151
- # AWS_SECRET_ACCESS_KEY=your_secret_key
152
- # AWS_REGION=us-east-1
153
- # AWS_BUCKET=your_bucket_name
154
-
155
- # ============================================================================
156
- # DEVELOPMENT
157
- # ============================================================================
158
-
159
- # Debug Mode
160
- DEBUG=
161
-
162
- # Database Synchronization (auto-migrate on startup)
163
- DB_SYNCHRONIZE=
164
-
165
- # Database Logging
166
- DB_LOGGING=
@@ -1,181 +0,0 @@
1
- /**
2
- * KV Logger
3
- * Writes batches of log events to a KV namespace (Cloudflare Workers compatible)
4
- *
5
- * Enabled via env:
6
- * - KV_LOG_ENABLED (default: false)
7
- * - KV_NAMESPACE (binding name; default: 'CACHE')
8
- * - KV_LOG_RETENTION_DAYS (default: 30)
9
- */
10
-
11
- import { Cloudflare } from '@zintrust/core';
12
- import { Env } from '@zintrust/core';
13
-
14
- export type KvLogEvent = {
15
- timestamp: string;
16
- level: 'debug' | 'info' | 'warn' | 'error' | 'fatal';
17
- message: string;
18
- category?: string;
19
- data?: unknown;
20
- error?: string;
21
- };
22
-
23
- type KVNamespace = NonNullable<ReturnType<typeof Cloudflare.getKVBinding>>;
24
-
25
- type PutOptions = { expiration?: number; expirationTtl?: number; metadata?: unknown };
26
-
27
- const getRetentionTtlSeconds = (): number => {
28
- const days = Env.getInt('KV_LOG_RETENTION_DAYS', 30);
29
- const safeDays = Number.isFinite(days) && days > 0 ? days : 30;
30
- return safeDays * 24 * 60 * 60;
31
- };
32
-
33
- const getKvBindingName = (): string => {
34
- const name = Env.get('KV_NAMESPACE', 'CACHE').trim();
35
- return name.length > 0 ? name : 'CACHE';
36
- };
37
-
38
- const isEnabled = (): boolean => Env.getBool('KV_LOG_ENABLED', false);
39
-
40
- const safeRandom = (): string => {
41
- try {
42
- // Prefer crypto if available
43
- const cryptoObj = (globalThis as unknown as { crypto?: Crypto }).crypto;
44
- if (cryptoObj?.getRandomValues) {
45
- const bytes = new Uint8Array(8);
46
- cryptoObj.getRandomValues(bytes);
47
- return Array.from(bytes)
48
- .map((b) => b.toString(16).padStart(2, '0'))
49
- .join('');
50
- }
51
- } catch {
52
- // fall through
53
- }
54
- const generate = Math.random().toString(16).slice(2); // NOSONAR
55
- const fallback = generate + Math.random().toString(16).slice(2); // NOSONAR this is not used for security
56
- return fallback;
57
- };
58
-
59
- const buildKey = (timestampIso: string): string => {
60
- const date = timestampIso.slice(0, 10);
61
- const hour = timestampIso.slice(11, 13);
62
- return `logs:${date}:${hour}:${safeRandom()}`;
63
- };
64
-
65
- let buffer: KvLogEvent[] = [];
66
- let flushTimer: ReturnType<typeof setTimeout> | undefined;
67
- let flushPromise: Promise<void> | undefined;
68
-
69
- const scheduleFlush = async (): Promise<void> => {
70
- if (flushPromise !== undefined) return flushPromise;
71
-
72
- // Fixed small batching window to reduce KV write volume.
73
- const windowMs = 1000;
74
-
75
- const promise = new Promise<void>((resolve) => {
76
- const run = async (): Promise<void> => {
77
- try {
78
- await flushNow();
79
- } finally {
80
- resolve(undefined);
81
- }
82
- };
83
-
84
- if (typeof globalThis.setTimeout !== 'function') {
85
- // microtask-ish
86
- void run();
87
- return;
88
- }
89
-
90
- flushTimer = globalThis.setTimeout(() => {
91
- flushTimer = undefined;
92
- void run();
93
- }, windowMs);
94
- });
95
-
96
- flushPromise = promise.finally(() => {
97
- flushPromise = undefined;
98
- });
99
-
100
- return flushPromise;
101
- };
102
-
103
- const getKv = (): KVNamespace | null => {
104
- const bindingName = getKvBindingName();
105
- return Cloudflare.getKVBinding(bindingName);
106
- };
107
-
108
- const putBatch = async (kv: KVNamespace, events: KvLogEvent[]): Promise<void> => {
109
- if (events.length === 0) return;
110
-
111
- const timestamp = events.at(-1)?.timestamp ?? new Date().toISOString();
112
- const key = buildKey(timestamp);
113
-
114
- const payload = JSON.stringify({
115
- version: 1,
116
- createdAt: new Date().toISOString(),
117
- count: events.length,
118
- events,
119
- });
120
-
121
- const opts: PutOptions = { expirationTtl: getRetentionTtlSeconds() };
122
-
123
- await kv.put(key, payload, opts);
124
- };
125
-
126
- const flushNow = async (): Promise<void> => {
127
- if (!isEnabled()) {
128
- buffer = [];
129
- return;
130
- }
131
-
132
- const kv = getKv();
133
- if (kv === null) {
134
- buffer = [];
135
- return;
136
- }
137
-
138
- const toSend = buffer;
139
- buffer = [];
140
-
141
- try {
142
- await putBatch(kv, toSend);
143
- } catch {
144
- // Best-effort: never throw from logging.
145
- }
146
- };
147
-
148
- const flushSoon = async (): Promise<void> => {
149
- if (flushPromise !== undefined) return flushPromise;
150
-
151
- flushPromise = Promise.resolve()
152
- .then(async () => flushNow())
153
- .finally(() => {
154
- flushPromise = undefined;
155
- });
156
-
157
- return flushPromise;
158
- };
159
-
160
- export const KvLogger = Object.freeze({
161
- async enqueue(event: KvLogEvent): Promise<void> {
162
- if (!isEnabled()) return Promise.resolve();
163
-
164
- buffer.push(event);
165
-
166
- // Basic size guard: flush if it gets too large
167
- const maxBatch = 100;
168
- if (buffer.length >= maxBatch) {
169
- // Cancel scheduled flush and flush immediately
170
- if (flushTimer !== undefined) {
171
- globalThis.clearTimeout(flushTimer);
172
- flushTimer = undefined;
173
- }
174
- return flushSoon();
175
- }
176
-
177
- return scheduleFlush();
178
- },
179
- });
180
-
181
- export default KvLogger;
@@ -1,156 +0,0 @@
1
- /**
2
- * Slack Notification Logger
3
- * Sends warn/error/fatal log events to a Slack incoming webhook.
4
- *
5
- * Enabled via env:
6
- * - SLACK_LOG_ENABLED (default: false)
7
- * - SLACK_LOG_WEBHOOK_URL
8
- * - SLACK_LOG_LEVELS (comma-separated; default: "warn,error,fatal")
9
- * - SLACK_LOG_BATCH_WINDOW_MS (default: 5000)
10
- */
11
-
12
- import { Env } from '@zintrust/core';
13
- import { ErrorFactory } from '@zintrust/core';
14
- import { HttpClient } from '@zintrust/core';
15
-
16
- export type SlackLogEvent = {
17
- timestamp: string;
18
- level: 'debug' | 'info' | 'warn' | 'error' | 'fatal';
19
- message: string;
20
- category?: string;
21
- data?: unknown;
22
- error?: string;
23
- };
24
-
25
- type SlackPayload = {
26
- text?: string;
27
- attachments?: Array<{ color?: string; text: string }>;
28
- };
29
-
30
- const isEnabled = (): boolean => Env.getBool('SLACK_LOG_ENABLED', false);
31
-
32
- const getLevels = (): Set<string> => {
33
- const raw = Env.get('SLACK_LOG_LEVELS', 'warn,error,fatal');
34
- return new Set(
35
- raw
36
- .split(',')
37
- .map((s) => s.trim().toLowerCase())
38
- .filter((s) => s.length > 0)
39
- );
40
- };
41
-
42
- const levelToColor = (level: SlackLogEvent['level']): string => {
43
- if (level === 'fatal' || level === 'error') return '#D50200';
44
- if (level === 'warn') return '#D39E00';
45
- return '#439FE0';
46
- };
47
-
48
- const formatEventText = (ev: SlackLogEvent): string => {
49
- const header = `*${ev.level.toUpperCase()}* ${ev.message}`;
50
- const metaParts: string[] = [];
51
- if (ev.category !== undefined) metaParts.push(`category=${ev.category}`);
52
- metaParts.push(`ts=${ev.timestamp}`);
53
-
54
- const meta = metaParts.length > 0 ? `\n_${metaParts.join(' ')}_` : '';
55
-
56
- const err = ev.error === undefined ? '' : `\n*error:* ${String(ev.error)}`;
57
- const data = ev.data === undefined ? '' : `\n*data:* \`${JSON.stringify(ev.data)}\``;
58
-
59
- return `${header}${meta}${err}${data}`;
60
- };
61
-
62
- let buffer: SlackLogEvent[] = [];
63
- let flushPromise: Promise<void> | undefined;
64
- let dedupeKeys = new Set<string>();
65
-
66
- const dedupeKeyFor = (ev: SlackLogEvent): string => {
67
- const base = `${ev.level}:${ev.message}:${ev.error ?? ''}`;
68
- return base.length > 500 ? base.slice(0, 500) : base;
69
- };
70
-
71
- const sendBatch = async (events: SlackLogEvent[]): Promise<void> => {
72
- const webhookUrl = Env.get('SLACK_LOG_WEBHOOK_URL').trim();
73
- if (webhookUrl.length === 0) {
74
- throw ErrorFactory.createConfigError(
75
- 'SLACK_LOG_WEBHOOK_URL is required when Slack logging is enabled'
76
- );
77
- }
78
-
79
- const lines = events.map((e) => formatEventText(e)).join('\n\n');
80
-
81
- const payload: SlackPayload = {
82
- attachments: [
83
- {
84
- color: levelToColor(events[0]?.level ?? 'warn'),
85
- text: lines,
86
- },
87
- ],
88
- };
89
-
90
- await HttpClient.post(webhookUrl, payload).send();
91
- };
92
-
93
- const flushNow = async (): Promise<void> => {
94
- const toSend = buffer;
95
- buffer = [];
96
- dedupeKeys = new Set<string>();
97
-
98
- if (!isEnabled()) return;
99
- if (toSend.length === 0) return;
100
-
101
- try {
102
- await sendBatch(toSend);
103
- } catch {
104
- // Best-effort: never throw from logging.
105
- }
106
- };
107
-
108
- const scheduleFlush = async (): Promise<void> => {
109
- if (flushPromise !== undefined) return flushPromise;
110
-
111
- const windowMs = Math.max(0, Env.getInt('SLACK_LOG_BATCH_WINDOW_MS', 5000));
112
-
113
- const promise = new Promise<void>((resolve) => {
114
- const run = async (): Promise<void> => {
115
- try {
116
- await flushNow();
117
- } finally {
118
- resolve(undefined);
119
- }
120
- };
121
-
122
- if (windowMs === 0 || typeof globalThis.setTimeout !== 'function') {
123
- void run();
124
- return;
125
- }
126
-
127
- globalThis.setTimeout(() => {
128
- void run();
129
- }, windowMs);
130
- });
131
-
132
- flushPromise = promise.finally(() => {
133
- flushPromise = undefined;
134
- });
135
-
136
- return flushPromise;
137
- };
138
-
139
- export const SlackLogger = Object.freeze({
140
- async enqueue(event: SlackLogEvent): Promise<void> {
141
- if (!isEnabled()) return Promise.resolve();
142
-
143
- const levels = getLevels();
144
- if (!levels.has(event.level)) return Promise.resolve();
145
-
146
- const key = dedupeKeyFor(event);
147
- if (dedupeKeys.has(key)) return scheduleFlush();
148
-
149
- dedupeKeys.add(key);
150
- buffer.push(event);
151
-
152
- return scheduleFlush();
153
- },
154
- });
155
-
156
- export default SlackLogger;
@@ -1,2 +0,0 @@
1
- // Placeholder for migrations
2
- export const migrations = Object.freeze([] as const);