webspresso 0.0.108 → 0.0.110

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 (184) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +3 -3
  3. package/bin/commands/add-esbuild.js +7 -3
  4. package/bin/commands/add-tailwind.js +9 -5
  5. package/bin/commands/build.js +20 -4
  6. package/bin/commands/dev.js +57 -7
  7. package/bin/commands/doctor.js +42 -1
  8. package/bin/commands/favicon-generate.js +10 -3
  9. package/bin/commands/new.js +8 -3
  10. package/bin/commands/start.js +3 -1
  11. package/bin/utils/add-command.js +16 -0
  12. package/core/app.js +45 -3
  13. package/core/auth/authenticate.js +3 -3
  14. package/core/auth/hash.js +167 -43
  15. package/core/auth/index.js +13 -1
  16. package/core/auth/jwt.js +21 -2
  17. package/core/auth/manager.js +63 -14
  18. package/core/auth/middleware.js +4 -2
  19. package/core/auth/oauth.js +5 -1
  20. package/core/auth/tokens.js +7 -2
  21. package/core/auth/totp.js +42 -6
  22. package/core/auth/user-agent.js +2 -0
  23. package/core/client/adapter/datastar.js +1401 -0
  24. package/core/client/api.js +1337 -0
  25. package/core/client/controller.js +1706 -0
  26. package/core/client/debug.js +367 -0
  27. package/core/client/devtool.js +1134 -0
  28. package/core/client/forms.js +1164 -0
  29. package/core/client/fragments.js +894 -0
  30. package/core/client/index.d.ts +59 -0
  31. package/core/client/index.js +391 -0
  32. package/core/client/lite.js +175 -0
  33. package/core/client/server-fragments.js +868 -0
  34. package/core/client/storage.js +339 -0
  35. package/core/client/utils.js +281 -0
  36. package/core/compression/middleware.js +277 -26
  37. package/core/context/app-context.js +25 -3
  38. package/core/context/request.js +32 -4
  39. package/core/errors/middleware.js +14 -0
  40. package/core/events/dispatcher.js +33 -0
  41. package/core/forms/flash.js +136 -102
  42. package/core/health/middleware.js +36 -6
  43. package/core/http/pipeline.js +45 -6
  44. package/core/index.js +25 -7
  45. package/core/kernel/view.js +41 -10
  46. package/core/metrics/middleware.js +30 -6
  47. package/core/metrics/registry.js +13 -5
  48. package/core/orm/cache/fingerprint.js +32 -11
  49. package/core/orm/cache/layer.js +19 -2
  50. package/core/orm/hidden.js +145 -0
  51. package/core/orm/model.js +48 -2
  52. package/core/orm/query-builder.js +343 -6
  53. package/core/orm/query-filters.js +14 -2
  54. package/core/orm/repository.js +64 -13
  55. package/core/orm/schema-helpers.js +9 -6
  56. package/core/orm/transaction.js +50 -6
  57. package/core/orm/types.js +4 -0
  58. package/core/queue/adapters/database.js +184 -2
  59. package/core/queue/adapters/memory.js +153 -5
  60. package/core/queue/adapters/redis.js +59 -4
  61. package/core/queue/job.js +14 -1
  62. package/core/queue/manager.js +115 -0
  63. package/core/resilience/circuit-breaker.js +27 -8
  64. package/core/services/builtins/exchange.js +174 -7
  65. package/core/services/builtins/file-manager.js +36 -0
  66. package/core/services/builtins/mail.js +27 -0
  67. package/core/services/builtins/queue.js +144 -0
  68. package/core/services/builtins/security.js +118 -0
  69. package/core/services/builtins/webhook.js +110 -0
  70. package/core/services/executor.js +38 -16
  71. package/core/services/index.js +4 -1
  72. package/core/sse/stream.js +28 -5
  73. package/core/utils/timeout.js +8 -1
  74. package/core/validation/compiler.js +10 -7
  75. package/index.d.ts +1320 -74
  76. package/index.js +128 -8
  77. package/package.json +75 -27
  78. package/plugins/admin-panel/client/parts/08-record-list.js +717 -70
  79. package/plugins/admin-panel/index.js +19 -8
  80. package/plugins/csrf/index.js +3 -3
  81. package/plugins/data-exchange/export.js +214 -0
  82. package/plugins/data-exchange/import.js +48 -5
  83. package/plugins/data-exchange/index.js +70 -28
  84. package/plugins/data-exchange/preview.js +266 -0
  85. package/plugins/data-exchange/template.js +242 -0
  86. package/plugins/email/admin-component.js +783 -141
  87. package/plugins/email/api-handlers.js +51 -1
  88. package/plugins/email/index.js +5 -0
  89. package/plugins/email/service.js +48 -0
  90. package/plugins/file-manager/admin-component.js +1546 -70
  91. package/plugins/file-manager/api-handlers.js +166 -1
  92. package/plugins/file-manager/core.js +598 -8
  93. package/plugins/file-manager/index.js +8 -0
  94. package/plugins/index.js +7 -0
  95. package/plugins/mcp/auth.js +3 -3
  96. package/plugins/oauth/index.js +36 -3
  97. package/plugins/queue/admin-component.js +1092 -0
  98. package/plugins/queue/api-handlers.js +248 -0
  99. package/plugins/queue/index.js +69 -0
  100. package/plugins/rest-resources/index.js +7 -2
  101. package/plugins/security/admin-component.js +689 -0
  102. package/plugins/security/api-handlers.js +169 -0
  103. package/plugins/security/audit.js +153 -0
  104. package/plugins/security/bruteforce.js +244 -0
  105. package/plugins/security/firewall.js +459 -0
  106. package/plugins/security/headers.js +214 -0
  107. package/plugins/security/honeypot.js +234 -0
  108. package/plugins/security/incident-recorder.js +137 -0
  109. package/plugins/security/index.js +211 -0
  110. package/plugins/seo-checker/analyzer.js +20 -7
  111. package/plugins/upload/index.js +36 -0
  112. package/plugins/webhooks/admin-component.js +702 -175
  113. package/plugins/webhooks/api-handlers.js +75 -1
  114. package/plugins/webhooks/dispatcher.js +290 -11
  115. package/plugins/webhooks/index.js +37 -2
  116. package/plugins/webhooks/sender.js +56 -0
  117. package/plugins/xlsx/engine.js +19 -4
  118. package/src/api/api-loader.js +19 -1
  119. package/src/bundle/index.js +443 -17
  120. package/src/client-runtime/bootstrap-swup.js +9 -0
  121. package/src/client-runtime/mount.js +15 -20
  122. package/src/client-runtime/resolve.js +3 -2
  123. package/src/dev/api-typegen.js +1300 -0
  124. package/src/dev/banner.js +10 -1
  125. package/src/dev/colors.js +1 -1
  126. package/src/dev/index.js +7 -1
  127. package/src/dev/typegen.js +173 -17
  128. package/src/dev-reload/index.js +1 -1
  129. package/src/discovery/file-route-parser.js +17 -3
  130. package/src/discovery/scan-routes.js +4 -1
  131. package/src/file-router.js +253 -69
  132. package/src/helpers.js +46 -26
  133. package/src/njk-frontmatter.js +30 -4
  134. package/src/routing/cascading.js +26 -8
  135. package/src/routing/mount-discovered-routes.js +76 -0
  136. package/src/server.js +231 -70
  137. package/views/partials/webspresso-client-runtime.njk +1 -9
  138. package/.agents/ADMIN.md +0 -426
  139. package/.agents/AGENTS.md +0 -96
  140. package/.agents/ARCHITECTURE.md +0 -163
  141. package/.agents/AUTH.md +0 -581
  142. package/.agents/CACHE.md +0 -148
  143. package/.agents/CLI.md +0 -649
  144. package/.agents/COMPRESSION.md +0 -59
  145. package/.agents/CONTEXT.md +0 -152
  146. package/.agents/CONVENTIONS.md +0 -50
  147. package/.agents/EARLY_HINTS.md +0 -120
  148. package/.agents/EMAIL.md +0 -223
  149. package/.agents/ERRORS.md +0 -260
  150. package/.agents/EVENTS.md +0 -179
  151. package/.agents/FLAGS.md +0 -118
  152. package/.agents/HEALTH.md +0 -118
  153. package/.agents/LIMITS.md +0 -109
  154. package/.agents/LOGGING.md +0 -93
  155. package/.agents/MCP.md +0 -103
  156. package/.agents/METRICS.md +0 -127
  157. package/.agents/MIGRATION_JOBS.md +0 -95
  158. package/.agents/ORM.md +0 -700
  159. package/.agents/PLUGINS.md +0 -729
  160. package/.agents/QUEUE.md +0 -290
  161. package/.agents/RATE_LIMIT.md +0 -147
  162. package/.agents/REALTIME.md +0 -213
  163. package/.agents/RESILIENCE.md +0 -235
  164. package/.agents/ROUTING.md +0 -605
  165. package/.agents/SCALE_OUT.md +0 -109
  166. package/.agents/SECRETS.md +0 -117
  167. package/.agents/SERVICES.md +0 -341
  168. package/.agents/SHUTDOWN.md +0 -74
  169. package/.agents/STREAMING.md +0 -108
  170. package/.agents/WORKFLOW.md +0 -27
  171. package/.agents/internal/DOCUMENTATION_REVIEW.md +0 -485
  172. package/.agents/internal/TECHNICAL_REVIEW.md +0 -428
  173. package/.agents/skills/webspresso-admin-and-plugins/SKILL.md +0 -122
  174. package/.agents/skills/webspresso-framework/SKILL.md +0 -89
  175. package/.agents/skills/webspresso-orm-and-database/SKILL.md +0 -127
  176. package/.agents/skills/webspresso-routing-and-api/SKILL.md +0 -130
  177. package/.agents/skills/webspresso-services/SKILL.md +0 -134
  178. package/.cursorrules +0 -14
  179. package/AGENTS.md +0 -203
  180. package/CLAUDE.md +0 -54
  181. package/core/kernel/run-demo.js +0 -58
  182. package/plugins/admin-panel/styles.js +0 -9
  183. package/plugins/data-exchange/export-xlsx.js +0 -119
  184. package/src/client-runtime/bootstrap-alpine-swup.js +0 -34
@@ -0,0 +1,367 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Webspresso Client Debug & Telemetry Inspector
5
+ * Tracks active controllers, active requests/concurrency states,
6
+ * mutation -> invalidation -> refresh -> patch causal chains,
7
+ * fragment timings (loadMs, renderMs, patchMs), discarded stale responses,
8
+ * and lifecycle cleanup errors without logging raw form values or sensitive payloads.
9
+ */
10
+
11
+ const { NOOP_DEBUGGER } = require('./utils');
12
+
13
+ const SENSITIVE_KEY_PATTERN = /password|passwd|secret|token|authorization|cookie|credit|card|cvv|ssn|api[-_]?key/i;
14
+
15
+ /**
16
+ * Redact keys/structures without exposing raw values by default.
17
+ * Returns only structural metadata (keys list or redacted summary).
18
+ *
19
+ * @param {unknown} payload
20
+ * @param {boolean} [includeSafePrimitives=false]
21
+ * @returns {unknown}
22
+ */
23
+ function summarizePayloadSafely(payload, includeSafePrimitives = false) {
24
+ if (payload === null || payload === undefined) return payload;
25
+ if (typeof FormData !== 'undefined' && payload instanceof FormData) {
26
+ const keys = [];
27
+ for (const key of payload.keys()) {
28
+ keys.push(key);
29
+ }
30
+ return { type: 'FormData', fields: Array.from(new Set(keys)) };
31
+ }
32
+ if (typeof Blob !== 'undefined' && payload instanceof Blob) {
33
+ return { type: 'Blob', size: payload.size, mimeType: payload.type || 'application/octet-stream' };
34
+ }
35
+ if (Array.isArray(payload)) {
36
+ return { type: 'Array', length: payload.length };
37
+ }
38
+ if (typeof payload === 'object') {
39
+ const keys = Object.keys(payload);
40
+ if (!includeSafePrimitives) {
41
+ return { type: 'Object', keys };
42
+ }
43
+ const safe = {};
44
+ for (const k of keys) {
45
+ if (SENSITIVE_KEY_PATTERN.test(k)) {
46
+ safe[k] = '[REDACTED]';
47
+ } else {
48
+ safe[k] = '[OMITTED_VALUE]';
49
+ }
50
+ }
51
+ return safe;
52
+ }
53
+ return `[${typeof payload}]`;
54
+ }
55
+
56
+ /**
57
+ * Internal active debugger implementation that allocates tracking ring buffers.
58
+ */
59
+ function createActiveDebugger(options = {}) {
60
+ let enabled = Boolean(options.enabled);
61
+ const maxEvents = typeof options.maxEvents === 'number' && options.maxEvents > 0 ? options.maxEvents : 200;
62
+ const customLogger = typeof options.logger === 'function' ? options.logger : null;
63
+
64
+ const events = [];
65
+ const activeControllers = new Map(); // instanceId -> { name, instanceId, el, mountedAt }
66
+ const activeRequests = new Map(); // requestId -> { requestId, key, method, url, policy, status, startedAt }
67
+ const causalChains = new Map(); // chainId -> { chainId, mutation, invalidation, refresh, patch, timings }
68
+ const discardedResponses = [];
69
+ const cleanupErrors = [];
70
+ const fragmentTimings = [];
71
+
72
+ let chainSeq = 0;
73
+
74
+ function pushEvent(type, detail = {}) {
75
+ const entry = {
76
+ id: `evt_${Date.now()}_${Math.random().toString(36).slice(2, 7)}`,
77
+ type,
78
+ timestamp: Date.now(),
79
+ ...detail,
80
+ };
81
+ events.push(entry);
82
+ if (events.length > maxEvents) {
83
+ events.shift();
84
+ }
85
+ if (enabled && customLogger) {
86
+ try {
87
+ customLogger(entry);
88
+ } catch (_err) {
89
+ // Never break application flow on logger failure
90
+ }
91
+ }
92
+ return entry;
93
+ }
94
+
95
+ const api = {
96
+ get enabled() {
97
+ return enabled;
98
+ },
99
+ setEnabled(val) {
100
+ enabled = Boolean(val);
101
+ },
102
+
103
+ // --- Controller tracking ---
104
+ trackControllerMount(instanceId, name, el) {
105
+ activeControllers.set(instanceId, {
106
+ instanceId,
107
+ name,
108
+ el: el || null,
109
+ tagName: el && el.tagName ? String(el.tagName).toLowerCase() : null,
110
+ mountedAt: Date.now(),
111
+ });
112
+ pushEvent('controller:mount', { instanceId, name });
113
+ },
114
+
115
+ trackControllerUnmount(instanceId, name) {
116
+ activeControllers.delete(instanceId);
117
+ pushEvent('controller:unmount', { instanceId, name });
118
+ },
119
+
120
+ trackCleanupError(instanceId, name, phase, error) {
121
+ const record = {
122
+ instanceId,
123
+ name,
124
+ phase,
125
+ message: error && error.message ? error.message : String(error),
126
+ timestamp: Date.now(),
127
+ };
128
+ cleanupErrors.push(record);
129
+ if (cleanupErrors.length > maxEvents) cleanupErrors.shift();
130
+ pushEvent('controller:cleanup-error', record);
131
+ },
132
+
133
+ // --- Request & Concurrency tracking ---
134
+ trackRequestStart({ requestId, key, method, url, policy, payload }) {
135
+ const record = {
136
+ requestId,
137
+ key,
138
+ method: String(method || 'GET').toUpperCase(),
139
+ url,
140
+ policy: policy || 'parallel',
141
+ status: 'in-flight',
142
+ payloadMeta: summarizePayloadSafely(payload, false),
143
+ startedAt: Date.now(),
144
+ };
145
+ activeRequests.set(requestId, record);
146
+ pushEvent('request:start', record);
147
+ return record;
148
+ },
149
+
150
+ trackRequestEnd(requestId, outcome = {}) {
151
+ const existing = activeRequests.get(requestId);
152
+ activeRequests.delete(requestId);
153
+ const durationMs = existing ? Math.max(0, Date.now() - existing.startedAt) : 0;
154
+ const record = {
155
+ ...(existing || { requestId }),
156
+ status: outcome.status || 'completed',
157
+ httpStatus: outcome.httpStatus || null,
158
+ errorKind: outcome.errorKind || null,
159
+ durationMs,
160
+ };
161
+ pushEvent('request:end', record);
162
+ return record;
163
+ },
164
+
165
+ trackDiscardedResponse({ source, key, instanceId, reason, version, currentVersion, url }) {
166
+ const record = {
167
+ source: source || 'api',
168
+ key: key || null,
169
+ instanceId: instanceId || null,
170
+ url: url || null,
171
+ reason: reason || 'stale',
172
+ version: version !== undefined ? version : null,
173
+ currentVersion: currentVersion !== undefined ? currentVersion : null,
174
+ timestamp: Date.now(),
175
+ };
176
+ discardedResponses.push(record);
177
+ if (discardedResponses.length > maxEvents) discardedResponses.shift();
178
+ pushEvent(`${source || 'api'}:discarded`, record);
179
+ return record;
180
+ },
181
+
182
+ // --- Causal chain: mutation -> invalidation -> refresh -> patch ---
183
+ startCausalChain({ method, url, requestId, tags }) {
184
+ const chainId = `chain_${++chainSeq}_${Date.now()}`;
185
+ const chain = {
186
+ chainId,
187
+ startedAt: Date.now(),
188
+ mutation: {
189
+ requestId: requestId || null,
190
+ method: String(method || 'POST').toUpperCase(),
191
+ url: url || null,
192
+ completedAt: Date.now(),
193
+ },
194
+ invalidation: {
195
+ tags: Array.isArray(tags) ? [...tags] : [],
196
+ triggeredAt: Date.now(),
197
+ },
198
+ refresh: null,
199
+ patch: null,
200
+ };
201
+ causalChains.set(chainId, chain);
202
+ if (causalChains.size > maxEvents) {
203
+ const oldestKey = causalChains.keys().next().value;
204
+ if (oldestKey) causalChains.delete(oldestKey);
205
+ }
206
+ pushEvent('chain:mutation-invalidated', {
207
+ chainId,
208
+ method: chain.mutation.method,
209
+ url: chain.mutation.url,
210
+ tags: chain.invalidation.tags,
211
+ });
212
+ return chainId;
213
+ },
214
+
215
+ recordChainRefresh(chainId, { fragmentIds, status, loadMs, renderMs, totalServerMs, error }) {
216
+ const chain = chainId ? causalChains.get(chainId) : null;
217
+ const refreshData = {
218
+ fragmentIds: Array.isArray(fragmentIds) ? [...fragmentIds] : [],
219
+ status: status || 'ok',
220
+ loadMs: typeof loadMs === 'number' ? loadMs : null,
221
+ renderMs: typeof renderMs === 'number' ? renderMs : null,
222
+ totalServerMs: typeof totalServerMs === 'number' ? totalServerMs : null,
223
+ error: error ? String(error.message || error) : null,
224
+ completedAt: Date.now(),
225
+ };
226
+ if (chain) {
227
+ chain.refresh = refreshData;
228
+ }
229
+ pushEvent('chain:refresh', { chainId: chainId || null, ...refreshData });
230
+ },
231
+
232
+ recordChainPatch(chainId, { instanceId, fragmentName, patchMs, loadMs, renderMs }) {
233
+ const chain = chainId ? causalChains.get(chainId) : null;
234
+ const patchData = {
235
+ instanceId,
236
+ fragmentName: fragmentName || null,
237
+ patchMs: typeof patchMs === 'number' ? patchMs : 0,
238
+ loadMs: typeof loadMs === 'number' ? loadMs : null,
239
+ renderMs: typeof renderMs === 'number' ? renderMs : null,
240
+ completedAt: Date.now(),
241
+ };
242
+ if (chain) {
243
+ if (!chain.patch) chain.patch = [];
244
+ chain.patch.push(patchData);
245
+ }
246
+ fragmentTimings.push(patchData);
247
+ if (fragmentTimings.length > maxEvents) fragmentTimings.shift();
248
+ pushEvent('chain:patch', { chainId: chainId || null, ...patchData });
249
+ },
250
+
251
+ recordEvent(type, detail = {}) {
252
+ return pushEvent(type, detail);
253
+ },
254
+
255
+ // --- Inspection Snapshot ---
256
+ getSnapshot() {
257
+ return {
258
+ enabled,
259
+ activeControllers: Array.from(activeControllers.values()).map((c) => ({
260
+ instanceId: c.instanceId,
261
+ name: c.name,
262
+ tagName: c.tagName,
263
+ mountedAt: c.mountedAt,
264
+ isConnected: Boolean(c.el && c.el.isConnected !== false),
265
+ })),
266
+ activeRequests: Array.from(activeRequests.values()),
267
+ causalChains: Array.from(causalChains.values()),
268
+ fragmentTimings: [...fragmentTimings],
269
+ discardedResponses: [...discardedResponses],
270
+ cleanupErrors: [...cleanupErrors],
271
+ events: [...events],
272
+ };
273
+ },
274
+
275
+ clear() {
276
+ events.length = 0;
277
+ activeControllers.clear();
278
+ activeRequests.clear();
279
+ causalChains.clear();
280
+ discardedResponses.length = 0;
281
+ cleanupErrors.length = 0;
282
+ fragmentTimings.length = 0;
283
+ },
284
+ };
285
+
286
+ if (typeof window !== 'undefined') {
287
+ window.__WEBSPRESSO_DEBUG__ = api;
288
+ }
289
+
290
+ return api;
291
+ }
292
+
293
+ /**
294
+ * Create a client debug collector instance.
295
+ * Returns a zero-allocation stub if debugging is disabled.
296
+ *
297
+ * @param {object} [options]
298
+ * @param {boolean} [options.enabled=false]
299
+ * @param {number} [options.maxEvents=200]
300
+ * @param {(entry: object) => void} [options.logger]
301
+ */
302
+ function createClientDebugger(options = {}) {
303
+ if (!options.enabled && process.env.NODE_ENV === 'production') {
304
+ return NOOP_DEBUGGER;
305
+ }
306
+ if (!options.enabled && !options.logger && !options.maxEvents) {
307
+ let activeInstance = null;
308
+ return {
309
+ get enabled() {
310
+ return activeInstance ? activeInstance.enabled : false;
311
+ },
312
+ setEnabled(val) {
313
+ if (val && !activeInstance) {
314
+ activeInstance = createActiveDebugger({ ...options, enabled: true });
315
+ } else if (activeInstance) {
316
+ activeInstance.setEnabled(val);
317
+ }
318
+ },
319
+ trackControllerMount(id, name, el) {
320
+ if (activeInstance) activeInstance.trackControllerMount(id, name, el);
321
+ },
322
+ trackControllerUnmount(id, name) {
323
+ if (activeInstance) activeInstance.trackControllerUnmount(id, name);
324
+ },
325
+ trackCleanupError(id, name, p, err) {
326
+ if (activeInstance) activeInstance.trackCleanupError(id, name, p, err);
327
+ },
328
+ trackRequestStart(args) {
329
+ return activeInstance
330
+ ? activeInstance.trackRequestStart(args)
331
+ : { requestId: args.requestId, status: 'in-flight' };
332
+ },
333
+ trackRequestEnd(id, out) {
334
+ return activeInstance ? activeInstance.trackRequestEnd(id, out) : { status: 'completed' };
335
+ },
336
+ trackDiscardedResponse(args) {
337
+ return activeInstance ? activeInstance.trackDiscardedResponse(args) : { reason: args.reason };
338
+ },
339
+ startCausalChain(args) {
340
+ return activeInstance ? activeInstance.startCausalChain(args) : '';
341
+ },
342
+ recordChainRefresh(id, args) {
343
+ if (activeInstance) activeInstance.recordChainRefresh(id, args);
344
+ },
345
+ recordChainPatch(id, args) {
346
+ if (activeInstance) activeInstance.recordChainPatch(id, args);
347
+ },
348
+ recordEvent(t, d) {
349
+ return activeInstance ? activeInstance.recordEvent(t, d) : null;
350
+ },
351
+ getSnapshot() {
352
+ return activeInstance ? activeInstance.getSnapshot() : NOOP_DEBUGGER.getSnapshot();
353
+ },
354
+ clear() {
355
+ if (activeInstance) activeInstance.clear();
356
+ },
357
+ };
358
+ }
359
+
360
+ return createActiveDebugger(options);
361
+ }
362
+
363
+ module.exports = {
364
+ createClientDebugger,
365
+ summarizePayloadSafely,
366
+ };
367
+