@zintrust/core 0.1.20 → 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 (98) hide show
  1. package/package.json +2 -1
  2. package/src/boot/Application.d.ts.map +1 -1
  3. package/src/boot/Application.js +48 -10
  4. package/src/boot/bootstrap.js +2 -0
  5. package/src/cli/commands/MigrateCommand.d.ts.map +1 -1
  6. package/src/cli/commands/MigrateCommand.js +36 -3
  7. package/src/cli/d1/D1SqlMigrations.d.ts.map +1 -1
  8. package/src/cli/d1/D1SqlMigrations.js +6 -1
  9. package/src/cli/scaffolding/ControllerGenerator.js +4 -4
  10. package/src/cli/scaffolding/GovernanceScaffolder.js +1 -1
  11. package/src/cli/scaffolding/MigrationGenerator.js +1 -1
  12. package/src/cli/scaffolding/ModelGenerator.js +1 -1
  13. package/src/cli/scaffolding/RouteGenerator.js +1 -1
  14. package/src/cli/scaffolding/ServiceScaffolder.js +4 -4
  15. package/src/config/broadcast.d.ts +14 -28
  16. package/src/config/broadcast.d.ts.map +1 -1
  17. package/src/config/broadcast.js +69 -35
  18. package/src/config/cache.d.ts +13 -45
  19. package/src/config/cache.d.ts.map +1 -1
  20. package/src/config/cache.js +69 -25
  21. package/src/config/database.d.ts +22 -64
  22. package/src/config/database.d.ts.map +1 -1
  23. package/src/config/database.js +99 -31
  24. package/src/config/env.d.ts +6 -0
  25. package/src/config/env.d.ts.map +1 -1
  26. package/src/config/env.js +7 -0
  27. package/src/config/index.d.ts +32 -136
  28. package/src/config/index.d.ts.map +1 -1
  29. package/src/config/mail.d.ts +19 -55
  30. package/src/config/mail.d.ts.map +1 -1
  31. package/src/config/mail.js +63 -21
  32. package/src/config/middleware.d.ts +24 -0
  33. package/src/config/middleware.d.ts.map +1 -1
  34. package/src/config/middleware.js +72 -52
  35. package/src/config/notification.d.ts +14 -27
  36. package/src/config/notification.d.ts.map +1 -1
  37. package/src/config/notification.js +82 -36
  38. package/src/config/queue.d.ts +21 -51
  39. package/src/config/queue.d.ts.map +1 -1
  40. package/src/config/queue.js +72 -27
  41. package/src/config/storage.d.ts +27 -34
  42. package/src/config/storage.d.ts.map +1 -1
  43. package/src/config/storage.js +97 -56
  44. package/src/config/type.d.ts +12 -1
  45. package/src/config/type.d.ts.map +1 -1
  46. package/src/http/parsers/MultipartParser.d.ts.map +1 -1
  47. package/src/http/parsers/MultipartParser.js +69 -42
  48. package/src/index.d.ts +9 -5
  49. package/src/index.d.ts.map +1 -1
  50. package/src/index.js +1 -0
  51. package/src/microservices/PostgresAdapter.d.ts.map +1 -1
  52. package/src/microservices/PostgresAdapter.js +0 -1
  53. package/src/migrations/MigratorFactory.d.ts.map +1 -1
  54. package/src/migrations/MigratorFactory.js +18 -2
  55. package/src/node-singletons/fs.d.ts +1 -1
  56. package/src/node-singletons/fs.d.ts.map +1 -1
  57. package/src/node-singletons/fs.js +1 -1
  58. package/src/orm/Database.d.ts +2 -1
  59. package/src/orm/Database.d.ts.map +1 -1
  60. package/src/orm/Database.js +110 -67
  61. package/src/orm/DatabaseAdapter.d.ts +1 -0
  62. package/src/orm/DatabaseAdapter.d.ts.map +1 -1
  63. package/src/orm/DatabaseRuntimeRegistration.d.ts.map +1 -1
  64. package/src/orm/DatabaseRuntimeRegistration.js +12 -0
  65. package/src/orm/QueryBuilder.d.ts +1 -1
  66. package/src/orm/QueryBuilder.d.ts.map +1 -1
  67. package/src/orm/QueryBuilder.js +4 -3
  68. package/src/orm/adapters/SQLiteAdapter.js +1 -1
  69. package/src/performance/Optimizer.d.ts +6 -6
  70. package/src/performance/Optimizer.d.ts.map +1 -1
  71. package/src/performance/Optimizer.js +133 -52
  72. package/src/routing/doc.d.ts +4 -5
  73. package/src/routing/doc.d.ts.map +1 -1
  74. package/src/routing/doc.js +35 -20
  75. package/src/routing/publicRoot.d.ts +9 -0
  76. package/src/routing/publicRoot.d.ts.map +1 -1
  77. package/src/routing/publicRoot.js +63 -2
  78. package/src/runtime/StartupConfigFileRegistry.d.ts +20 -0
  79. package/src/runtime/StartupConfigFileRegistry.d.ts.map +1 -0
  80. package/src/runtime/StartupConfigFileRegistry.js +44 -0
  81. package/src/runtime/useFileLoader.d.ts +26 -0
  82. package/src/runtime/useFileLoader.d.ts.map +1 -0
  83. package/src/runtime/useFileLoader.js +188 -0
  84. package/src/scripts/TemplateSync.js +4 -4
  85. package/src/security/XssProtection.d.ts.map +1 -1
  86. package/src/security/XssProtection.js +62 -14
  87. package/src/templates/project/basic/config/broadcast.ts.tpl +33 -17
  88. package/src/templates/project/basic/config/cache.ts.tpl +35 -17
  89. package/src/templates/project/basic/config/database.ts.tpl +68 -32
  90. package/src/templates/project/basic/config/logging/HttpLogger.ts.tpl +7 -114
  91. package/src/templates/project/basic/config/mail.ts.tpl +59 -13
  92. package/src/templates/project/basic/config/notification.ts.tpl +28 -17
  93. package/src/templates/project/basic/config/queue.ts.tpl +49 -17
  94. package/src/templates/project/basic/config/storage.ts.tpl +55 -18
  95. package/src/templates/project/basic/config/type.ts.tpl +0 -1
  96. package/src/templates/project/basic/src/index.ts.tpl +3 -0
  97. package/src/templates/project/basic/config/logging/KvLogger.ts.tpl +0 -181
  98. package/src/templates/project/basic/config/logging/SlackLogger.ts.tpl +0 -156
@@ -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;