webspresso 0.0.103 ā 0.0.105
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/AGENTS.md +6 -0
- package/.agents/ARCHITECTURE.md +23 -0
- package/.agents/CACHE.md +147 -0
- package/.agents/CLI.md +1 -1
- package/.agents/EARLY_HINTS.md +120 -0
- package/.agents/HEALTH.md +118 -0
- package/.agents/LIMITS.md +109 -0
- package/.agents/ORM.md +155 -1
- package/.agents/PLUGINS.md +28 -0
- package/.agents/RESILIENCE.md +235 -0
- package/AGENTS.md +6 -0
- package/README.md +2 -2
- package/bin/commands/add-docker.js +6 -6
- package/bin/commands/dev.js +4 -3
- package/bin/commands/new.js +5 -5
- package/bin/commands/openapi.js +1 -1
- package/bin/commands/start.js +1 -1
- package/bin/utils/orm-map-html.js +2 -8
- package/bin/utils/project.js +2 -2
- package/core/auth/hash.js +5 -4
- package/core/auth/jwt.js +6 -57
- package/core/auth/magic-link.js +4 -5
- package/core/auth/manager.js +3 -5
- package/core/auth/oauth.js +45 -30
- package/core/auth/totp.js +5 -16
- package/core/auth/user-agent.js +1 -21
- package/core/cache/byte-size.js +123 -0
- package/core/cache/index.js +21 -0
- package/core/cache/lru.js +477 -0
- package/core/cache/tagged-lru.js +346 -0
- package/core/commands/registry.js +6 -20
- package/core/content/renderer.js +1 -13
- package/core/early-hints/index.js +267 -0
- package/core/errors/domain.js +48 -0
- package/core/errors/http.js +31 -0
- package/core/errors/index.js +10 -0
- package/core/errors/middleware.js +2 -8
- package/core/errors/normalize.js +88 -2
- package/core/events/discovery.js +6 -24
- package/core/events/dispatcher.js +2 -7
- package/core/forms/form-builder.js +1 -9
- package/core/health/index.js +41 -0
- package/core/health/middleware.js +213 -0
- package/core/health/normalize.js +140 -0
- package/core/health/probes.js +203 -0
- package/core/limits/index.js +34 -0
- package/core/limits/middleware.js +317 -0
- package/core/limits/normalize.js +222 -0
- package/core/orm/batch.js +70 -0
- package/core/orm/cache/fingerprint.js +2 -2
- package/core/orm/cache/memory-provider.js +27 -110
- package/core/orm/index.js +76 -8
- package/core/orm/json-fields.js +22 -8
- package/core/orm/model.js +10 -0
- package/core/orm/query-builder.js +63 -9
- package/core/orm/query-filters.js +393 -0
- package/core/orm/repository.js +318 -19
- package/core/orm/schema-helpers.js +8 -10
- package/core/orm/scopes.js +321 -1
- package/core/orm/transaction.js +10 -2
- package/core/orm/utils.js +4 -86
- package/core/queue/adapters/database.js +4 -8
- package/core/queue/manager.js +55 -41
- package/core/resilience/circuit-breaker.js +391 -0
- package/core/resilience/errors.js +63 -0
- package/core/resilience/index.js +53 -0
- package/core/resilience/registry.js +97 -0
- package/core/resilience/retry.js +203 -0
- package/core/schema-cache.js +9 -2
- package/core/shutdown/http-adapter.js +4 -1
- package/core/shutdown/shutdown-manager.js +132 -31
- package/core/utils/array.js +12 -0
- package/core/utils/base64url.js +8 -0
- package/core/utils/crypto.js +191 -0
- package/core/utils/ensure-leading-slash.js +6 -0
- package/core/utils/escape-html.js +7 -0
- package/core/utils/escape-regexp.js +7 -0
- package/core/utils/fetch.js +121 -0
- package/core/utils/fs.js +144 -0
- package/core/utils/get-client-ip.js +6 -0
- package/core/utils/hmac.js +6 -0
- package/core/utils/html.js +72 -0
- package/core/utils/ip.js +86 -0
- package/core/utils/json.js +98 -0
- package/core/utils/object.js +106 -0
- package/core/utils/random.js +9 -0
- package/core/utils/regex.js +77 -0
- package/core/utils/safe-compare.js +3 -0
- package/core/utils/sha256.js +6 -0
- package/core/utils/string.js +87 -0
- package/core/utils/strip-trailing-slash.js +6 -0
- package/core/utils/time.js +96 -0
- package/core/utils/timeout.js +348 -0
- package/core/utils/url.js +106 -0
- package/core/utils/walk.js +7 -0
- package/index.d.ts +627 -2
- package/index.js +158 -0
- package/package.json +1 -2
- package/plugins/admin-panel/auth.js +15 -7
- package/plugins/admin-panel/client/parts/01-state-api-breadcrumb.js +82 -10
- package/plugins/admin-panel/client/parts/05-rich-text-file-helpers.js +4 -2
- package/plugins/admin-panel/client/parts/08-record-list.js +3 -2
- package/plugins/admin-panel/client/parts/10-export-registry.js +6 -0
- package/plugins/admin-panel/core/api-extensions.js +3 -80
- package/plugins/admin-panel/index.js +1 -1
- package/plugins/admin-panel/lib/login-rate-limiter.js +15 -13
- package/plugins/admin-panel/modules/menu.js +1 -1
- package/plugins/api-key/crypto.js +3 -26
- package/plugins/api-key/scopes.js +5 -7
- package/plugins/audit-log/api-handlers.js +8 -7
- package/plugins/audit-log/middleware.js +11 -2
- package/plugins/audit-log/parse.js +3 -3
- package/plugins/basic-auth/index.js +2 -26
- package/plugins/cors.js +2 -2
- package/plugins/csrf/index.js +7 -23
- package/plugins/dashboard/app.js +2 -2
- package/plugins/dashboard/index.js +5 -5
- package/plugins/data-exchange/record-selection.js +2 -5
- package/plugins/email/api-handlers.js +5 -18
- package/plugins/email/auth-bridge.js +3 -2
- package/plugins/file-manager/admin-component.js +3 -1
- package/plugins/file-manager/core.js +34 -4
- package/plugins/health-check.js +2 -1
- package/plugins/index.js +2 -0
- package/plugins/lazy.js +5 -6
- package/plugins/mcp/auth.js +1 -13
- package/plugins/mcp/discovery.js +18 -17
- package/plugins/mcp/index.js +23 -1
- package/plugins/mcp/transports/sse.js +10 -1
- package/plugins/orm-cache-admin/admin-component.js +3 -2
- package/plugins/polar/src/api.js +11 -3
- package/plugins/polar/src/webhooks.js +7 -13
- package/plugins/rate-limit/index.js +3 -1
- package/plugins/recaptcha/helpers.js +1 -7
- package/plugins/recaptcha/verify.js +37 -23
- package/plugins/redirect/index.js +57 -7
- package/plugins/rest-resources/index.js +1 -207
- package/plugins/rls/index.js +170 -0
- package/plugins/schema-explorer/admin-component.js +4 -2
- package/plugins/schema-explorer.js +40 -29
- package/plugins/seo-checker/index.js +5 -2
- package/plugins/site-analytics/tracking.js +21 -18
- package/plugins/sitemap.js +21 -17
- package/plugins/swagger.js +13 -17
- package/plugins/upload/index.js +4 -3
- package/plugins/upload/orphan-pruner.js +4 -3
- package/plugins/webhooks/crypto.js +6 -28
- package/plugins/webhooks/dispatcher.js +14 -9
- package/plugins/webhooks/index.js +6 -0
- package/plugins/webhooks/matcher.js +28 -17
- package/plugins/webhooks/sender.js +40 -13
- package/src/app-context.js +41 -5
- package/src/dev/banner.js +6 -2
- package/src/dev-reload/index.js +47 -6
- package/src/file-router.js +1 -3
- package/src/helpers.js +180 -33
- package/src/modules/module-discovery.js +1 -9
- package/src/pages/page-loader.js +53 -1
- package/src/plugin-manager.js +90 -17
- package/src/server.js +137 -26
- package/src/services/discovery.js +19 -40
- package/src/services/executor.js +86 -25
- package/src/services/memoize.js +3 -25
- package/src/services/registry.js +6 -0
- package/src/template/precompile.js +8 -19
package/index.js
CHANGED
|
@@ -14,6 +14,8 @@ const {
|
|
|
14
14
|
hasShutdownManager,
|
|
15
15
|
getServiceRegistry,
|
|
16
16
|
hasServiceRegistry,
|
|
17
|
+
getCache,
|
|
18
|
+
hasCache,
|
|
17
19
|
resetAppContext,
|
|
18
20
|
setAppContext,
|
|
19
21
|
} = require('./src/app-context');
|
|
@@ -24,6 +26,11 @@ const {
|
|
|
24
26
|
} = require('./src/services');
|
|
25
27
|
const { ShutdownManager, NodeHttpAdapter } = require('./core/shutdown');
|
|
26
28
|
const compression = require('./core/compression');
|
|
29
|
+
const earlyHints = require('./core/early-hints');
|
|
30
|
+
const limits = require('./core/limits');
|
|
31
|
+
const health = require('./core/health');
|
|
32
|
+
const cache = require('./core/cache');
|
|
33
|
+
const resilience = require('./core/resilience');
|
|
27
34
|
const errors = require('./core/errors');
|
|
28
35
|
const {
|
|
29
36
|
mountPages,
|
|
@@ -91,6 +98,8 @@ module.exports = {
|
|
|
91
98
|
hasShutdownManager,
|
|
92
99
|
getServiceRegistry,
|
|
93
100
|
hasServiceRegistry,
|
|
101
|
+
getCache,
|
|
102
|
+
hasCache,
|
|
94
103
|
resetAppContext,
|
|
95
104
|
setAppContext,
|
|
96
105
|
|
|
@@ -118,6 +127,54 @@ module.exports = {
|
|
|
118
127
|
compression,
|
|
119
128
|
createCompressionMiddleware: compression.createCompressionMiddleware,
|
|
120
129
|
|
|
130
|
+
// HTTP 103 Early Hints
|
|
131
|
+
earlyHints,
|
|
132
|
+
sendEarlyHints: earlyHints.sendEarlyHints,
|
|
133
|
+
createEarlyHintsMiddleware: earlyHints.createEarlyHintsMiddleware,
|
|
134
|
+
formatLink: earlyHints.formatLink,
|
|
135
|
+
formatLinkHeader: earlyHints.formatLinkHeader,
|
|
136
|
+
inferAsType: earlyHints.inferAsType,
|
|
137
|
+
|
|
138
|
+
// Payload Limits & DoS Protection
|
|
139
|
+
limits,
|
|
140
|
+
normalizeLimits: limits.normalizeLimits,
|
|
141
|
+
setupLimitsMiddleware: limits.setupLimitsMiddleware,
|
|
142
|
+
createLimitsMiddleware: limits.createLimitsMiddleware,
|
|
143
|
+
parseByteSize: limits.parseByteSize,
|
|
144
|
+
|
|
145
|
+
// Health & Readiness Probes
|
|
146
|
+
health,
|
|
147
|
+
normalizeHealthConfig: health.normalizeHealthConfig,
|
|
148
|
+
setupHealthMiddleware: health.setupHealthMiddleware,
|
|
149
|
+
createHealthManager: health.createHealthManager,
|
|
150
|
+
probeDatabase: health.probeDatabase,
|
|
151
|
+
probeQueue: health.probeQueue,
|
|
152
|
+
|
|
153
|
+
// High-Performance In-Memory & Tagged LRU Cache Engine
|
|
154
|
+
cache,
|
|
155
|
+
LruCache: cache.LruCache,
|
|
156
|
+
createLruCache: cache.createLruCache,
|
|
157
|
+
TaggedLruCache: cache.TaggedLruCache,
|
|
158
|
+
createTaggedLruCache: cache.createTaggedLruCache,
|
|
159
|
+
approximateByteSize: cache.approximateByteSize,
|
|
160
|
+
|
|
161
|
+
// Enterprise Resilience & Fault Tolerance (Circuit Breaker & Retry Engine)
|
|
162
|
+
resilience,
|
|
163
|
+
CircuitBreaker: resilience.CircuitBreaker,
|
|
164
|
+
createCircuitBreaker: resilience.createCircuitBreaker,
|
|
165
|
+
STATE_CLOSED: resilience.STATE_CLOSED,
|
|
166
|
+
STATE_OPEN: resilience.STATE_OPEN,
|
|
167
|
+
STATE_HALF_OPEN: resilience.STATE_HALF_OPEN,
|
|
168
|
+
retry: resilience.retry,
|
|
169
|
+
withRetry: resilience.withRetry,
|
|
170
|
+
isTransientError: resilience.isTransientError,
|
|
171
|
+
calculateBackoffDelay: resilience.calculateBackoffDelay,
|
|
172
|
+
CircuitBreakerRegistry: resilience.CircuitBreakerRegistry,
|
|
173
|
+
circuitBreakerRegistry: resilience.circuitBreakerRegistry,
|
|
174
|
+
getBreaker: resilience.getBreaker,
|
|
175
|
+
CircuitBreakerOpenError: resilience.CircuitBreakerOpenError,
|
|
176
|
+
CircuitBreakerTimeoutError: resilience.CircuitBreakerTimeoutError,
|
|
177
|
+
|
|
121
178
|
// Exceptions & Error Handling
|
|
122
179
|
errors,
|
|
123
180
|
WebspressoError: errors.WebspressoError,
|
|
@@ -131,7 +188,12 @@ module.exports = {
|
|
|
131
188
|
PayloadTooLargeError: errors.PayloadTooLargeError,
|
|
132
189
|
UnsupportedMediaTypeError: errors.UnsupportedMediaTypeError,
|
|
133
190
|
UnprocessableEntityError: errors.UnprocessableEntityError,
|
|
191
|
+
RequestTimeoutError: errors.RequestTimeoutError,
|
|
134
192
|
TooManyRequestsError: errors.TooManyRequestsError,
|
|
193
|
+
ServiceUnavailableError: errors.ServiceUnavailableError,
|
|
194
|
+
GatewayTimeoutError: errors.GatewayTimeoutError,
|
|
195
|
+
CircuitBreakerOpenError: errors.CircuitBreakerOpenError,
|
|
196
|
+
CircuitBreakerTimeoutError: errors.CircuitBreakerTimeoutError,
|
|
135
197
|
ValidationError: errors.ValidationError,
|
|
136
198
|
ConfigurationError: errors.ConfigurationError,
|
|
137
199
|
PluginError: errors.PluginError,
|
|
@@ -219,6 +281,92 @@ module.exports = {
|
|
|
219
281
|
defineSignal: require('./core/events').defineSignal,
|
|
220
282
|
defineListener: require('./core/events').defineListener,
|
|
221
283
|
loadListeners: require('./core/events').loadListeners,
|
|
284
|
+
|
|
285
|
+
// Shared Fetch, Crypto & HTML Utilities
|
|
286
|
+
fetchWithTimeout: require('./core/utils/fetch').fetchWithTimeout,
|
|
287
|
+
safeCompare: require('./core/utils/crypto').safeCompare,
|
|
288
|
+
sha256: require('./core/utils/crypto').sha256,
|
|
289
|
+
hmacSha256: require('./core/utils/crypto').hmacSha256,
|
|
290
|
+
randomToken: require('./core/utils/crypto').randomToken,
|
|
291
|
+
randomId: require('./core/utils/crypto').randomId,
|
|
292
|
+
base64UrlEncode: require('./core/utils/crypto').base64UrlEncode,
|
|
293
|
+
base64UrlDecode: require('./core/utils/crypto').base64UrlDecode,
|
|
294
|
+
escapeHtml: require('./core/utils/html').escapeHtml,
|
|
295
|
+
unescapeHtml: require('./core/utils/html').unescapeHtml,
|
|
296
|
+
walkDirectory: require('./core/utils/fs').walkDirectory,
|
|
297
|
+
walkDirectoryDetailed: require('./core/utils/fs').walkDirectoryDetailed,
|
|
298
|
+
stripTrailingSlash: require('./core/utils/url').stripTrailingSlash,
|
|
299
|
+
ensureLeadingSlash: require('./core/utils/url').ensureLeadingSlash,
|
|
300
|
+
ensureTrailingSlash: require('./core/utils/url').ensureTrailingSlash,
|
|
301
|
+
stripLeadingSlash: require('./core/utils/url').stripLeadingSlash,
|
|
302
|
+
joinUrl: require('./core/utils/url').joinUrl,
|
|
303
|
+
escapeRegExp: require('./core/utils/regex').escapeRegExp,
|
|
304
|
+
escapeRegex: require('./core/utils/regex').escapeRegExp,
|
|
305
|
+
globToRegExp: require('./core/utils/regex').globToRegExp,
|
|
306
|
+
parseDurationSec: require('./core/utils/time').parseDurationSec,
|
|
307
|
+
parseDuration: require('./core/utils/time').parseDurationSec,
|
|
308
|
+
parseDurationMs: require('./core/utils/time').parseDurationMs,
|
|
309
|
+
sleep: require('./core/utils/time').sleep,
|
|
310
|
+
safeJsonParse: require('./core/utils/json').safeJsonParse,
|
|
311
|
+
safeJsonStringify: require('./core/utils/json').safeJsonStringify,
|
|
312
|
+
isValidJson: require('./core/utils/json').isValidJson,
|
|
313
|
+
toSnakeCase: require('./core/utils/string').toSnakeCase,
|
|
314
|
+
snakeToCamel: require('./core/utils/string').snakeToCamel,
|
|
315
|
+
camelToSnake: require('./core/utils/string').camelToSnake,
|
|
316
|
+
toKebabCase: require('./core/utils/string').toKebabCase,
|
|
317
|
+
toPascalCase: require('./core/utils/string').toPascalCase,
|
|
318
|
+
ensureArray: require('./core/utils/object').ensureArray,
|
|
319
|
+
pick: require('./core/utils/object').pick,
|
|
320
|
+
omit: require('./core/utils/object').omit,
|
|
321
|
+
deepClone: require('./core/utils/object').deepClone,
|
|
322
|
+
|
|
323
|
+
// Timeout Utilities & Middleware
|
|
324
|
+
DEFAULT_TIMEOUTS: require('./core/utils/timeout').DEFAULT_TIMEOUTS,
|
|
325
|
+
normalizeTimeouts: require('./core/utils/timeout').normalizeTimeouts,
|
|
326
|
+
withTimeout: require('./core/utils/timeout').withTimeout,
|
|
327
|
+
createTimeoutMiddleware: require('./core/utils/timeout').createTimeoutMiddleware,
|
|
328
|
+
TimeoutError: require('./core/utils/timeout').TimeoutError,
|
|
329
|
+
|
|
330
|
+
// Native Cloud & Kubernetes Health & Readiness Probes
|
|
331
|
+
health,
|
|
332
|
+
normalizeHealthConfig: health.normalizeHealthConfig,
|
|
333
|
+
setupHealthMiddleware: health.setupHealthMiddleware,
|
|
334
|
+
createHealthManager: health.createHealthManager,
|
|
335
|
+
probeDatabase: health.probeDatabase,
|
|
336
|
+
probeQueue: health.probeQueue,
|
|
337
|
+
probeCustomChecks: health.probeCustomChecks,
|
|
338
|
+
formatMb: health.formatMb,
|
|
339
|
+
createEventLoopMonitor: health.createEventLoopMonitor,
|
|
340
|
+
getSystemMetrics: health.getSystemMetrics,
|
|
341
|
+
|
|
342
|
+
// Payload Limits & DoS Protection
|
|
343
|
+
limits,
|
|
344
|
+
normalizeLimits: limits.normalizeLimits,
|
|
345
|
+
setupLimitsMiddleware: limits.setupLimitsMiddleware,
|
|
346
|
+
createLimitsMiddleware: limits.createLimitsMiddleware,
|
|
347
|
+
parseByteSize: limits.parseByteSize,
|
|
348
|
+
PayloadTooLargeError: errors.PayloadTooLargeError,
|
|
349
|
+
BadRequestError: errors.BadRequestError,
|
|
350
|
+
|
|
351
|
+
// High-Performance In-Memory LRU & Tagged Cache
|
|
352
|
+
cache,
|
|
353
|
+
normalizeCacheConfig: cache.normalizeCacheConfig,
|
|
354
|
+
parseCacheTtlMs: cache.parseCacheTtlMs,
|
|
355
|
+
LruCache: cache.LruCache,
|
|
356
|
+
TaggedLruCache: cache.TaggedLruCache,
|
|
357
|
+
createTaggedLruCache: cache.createTaggedLruCache,
|
|
358
|
+
createOrmCacheProvider: cache.createOrmCacheProvider,
|
|
359
|
+
|
|
360
|
+
// Enterprise Resilience & Circuit Breaker Engine
|
|
361
|
+
resilience,
|
|
362
|
+
CircuitBreaker: resilience.CircuitBreaker,
|
|
363
|
+
CircuitBreakerRegistry: resilience.CircuitBreakerRegistry,
|
|
364
|
+
circuitBreakerRegistry: resilience.circuitBreakerRegistry,
|
|
365
|
+
getBreaker: resilience.getBreaker,
|
|
366
|
+
retry: resilience.retry,
|
|
367
|
+
withRetry: resilience.withRetry,
|
|
368
|
+
CircuitBreakerOpenError: resilience.CircuitBreakerOpenError,
|
|
369
|
+
CircuitBreakerTimeoutError: resilience.CircuitBreakerTimeoutError,
|
|
222
370
|
};
|
|
223
371
|
|
|
224
372
|
// Define lazy getters for plugins, ORM, and heavy core subsystems
|
|
@@ -276,6 +424,8 @@ Object.defineProperties(module.exports, {
|
|
|
276
424
|
FactoryBuilder: { get: () => getOrm().FactoryBuilder, enumerable: true, configurable: true },
|
|
277
425
|
diffSchema: { get: () => getOrm().diffSchema, enumerable: true, configurable: true },
|
|
278
426
|
makeMigrations: { get: () => getOrm().makeMigrations, enumerable: true, configurable: true },
|
|
427
|
+
calculateSafeChunkSize: { get: () => getOrm().calculateSafeChunkSize, enumerable: true, configurable: true },
|
|
428
|
+
chunkArray: { get: () => getOrm().chunkArray, enumerable: true, configurable: true },
|
|
279
429
|
|
|
280
430
|
// Cascading Middleware & Layouts
|
|
281
431
|
cascading: { get: () => require('./src/routing/cascading'), enumerable: true, configurable: true },
|
|
@@ -319,6 +469,10 @@ Object.defineProperties(module.exports, {
|
|
|
319
469
|
generateQrDataUri: { get: () => require('./core/auth/qrcode').generateQrDataUri, enumerable: true, configurable: true },
|
|
320
470
|
createAuthMiddleware: { get: () => require('./core/auth').createAuthMiddleware, enumerable: true, configurable: true },
|
|
321
471
|
setupAuthMiddleware: { get: () => require('./core/auth').setupAuthMiddleware, enumerable: true, configurable: true },
|
|
472
|
+
getClientIp: { get: () => require('./core/utils/ip').getClientIp, enumerable: true, configurable: true },
|
|
473
|
+
parseUserAgent: { get: () => require('./core/auth').parseUserAgent, enumerable: true, configurable: true },
|
|
474
|
+
sessions: { get: () => require('./core/auth').sessions, enumerable: true, configurable: true },
|
|
475
|
+
SessionManager: { get: () => require('./core/auth').SessionManager, enumerable: true, configurable: true },
|
|
322
476
|
|
|
323
477
|
// Validation
|
|
324
478
|
z: { get: () => require('./core/validation').z, enumerable: true, configurable: true },
|
|
@@ -371,5 +525,9 @@ Object.defineProperties(module.exports, {
|
|
|
371
525
|
defineCommand: { get: () => require('./core/commands').defineCommand, enumerable: true, configurable: true },
|
|
372
526
|
createCommandRegistry: { get: () => require('./core/commands').createCommandRegistry, enumerable: true, configurable: true },
|
|
373
527
|
executeCommand: { get: () => require('./core/commands').executeCommand, enumerable: true, configurable: true },
|
|
528
|
+
|
|
529
|
+
// Row Level Security (RLS) plugin
|
|
530
|
+
rlsPlugin: { get: () => require('./plugins/rls').rlsPlugin, enumerable: true, configurable: true },
|
|
531
|
+
createRlsMiddleware: { get: () => require('./plugins/rls').createRlsMiddleware, enumerable: true, configurable: true },
|
|
374
532
|
});
|
|
375
533
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webspresso",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.105",
|
|
4
4
|
"description": "Minimal, production-ready SSR framework for Node.js with file-based routing, Nunjucks templating, built-in i18n, and CLI tooling",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -115,7 +115,6 @@
|
|
|
115
115
|
"bcrypt": "^5.1.1",
|
|
116
116
|
"commander": "^11.1.0",
|
|
117
117
|
"compression": "^1.8.2",
|
|
118
|
-
"connect-timeout": "^1.9.1",
|
|
119
118
|
"cookie-parser": "^1.4.7",
|
|
120
119
|
"csv-parse": "^7.0.2",
|
|
121
120
|
"dayjs": "^1.11.19",
|
|
@@ -115,13 +115,21 @@ async function login(adminUserRepo, email, password, compare) {
|
|
|
115
115
|
*/
|
|
116
116
|
async function logout(req, res) {
|
|
117
117
|
return new Promise((resolve, reject) => {
|
|
118
|
-
req.session
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
118
|
+
if (!req || !req.session) {
|
|
119
|
+
return resolve();
|
|
120
|
+
}
|
|
121
|
+
if (typeof req.session.destroy === 'function') {
|
|
122
|
+
req.session.destroy((err) => {
|
|
123
|
+
if (err) {
|
|
124
|
+
reject(err);
|
|
125
|
+
} else {
|
|
126
|
+
resolve();
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
} else {
|
|
130
|
+
delete req.session.adminUser;
|
|
131
|
+
resolve();
|
|
132
|
+
}
|
|
125
133
|
});
|
|
126
134
|
}
|
|
127
135
|
|
|
@@ -1,14 +1,82 @@
|
|
|
1
1
|
|
|
2
|
+
/**
|
|
3
|
+
* Shared client-side fetch wrapper with AbortController, timeout, and signal composition.
|
|
4
|
+
* @param {string} url
|
|
5
|
+
* @param {RequestInit & { timeout?: number }} [options]
|
|
6
|
+
* @returns {Promise<Response>}
|
|
7
|
+
*/
|
|
8
|
+
async function fetchWithTimeout(url, options = {}) {
|
|
9
|
+
const { timeout = 30000, signal, ...fetchOptions } = options;
|
|
10
|
+
|
|
11
|
+
if (signal && signal.aborted) {
|
|
12
|
+
const reason = (signal.reason !== undefined && signal.reason !== null)
|
|
13
|
+
? signal.reason
|
|
14
|
+
: new Error('This operation was aborted');
|
|
15
|
+
throw reason;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (typeof AbortController === 'undefined') {
|
|
19
|
+
return fetch(url, { ...fetchOptions, signal });
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const controller = new AbortController();
|
|
23
|
+
let timer = null;
|
|
24
|
+
let callerSignalListener = null;
|
|
25
|
+
|
|
26
|
+
if (typeof timeout === 'number' && timeout > 0 && typeof setTimeout !== 'undefined') {
|
|
27
|
+
timer = setTimeout(() => {
|
|
28
|
+
const err = new Error('Request timed out after ' + timeout + 'ms');
|
|
29
|
+
err.name = 'TimeoutError';
|
|
30
|
+
err.code = 'ETIMEDOUT';
|
|
31
|
+
controller.abort(err);
|
|
32
|
+
}, timeout);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (signal) {
|
|
36
|
+
callerSignalListener = () => {
|
|
37
|
+
controller.abort(signal.reason);
|
|
38
|
+
};
|
|
39
|
+
signal.addEventListener('abort', callerSignalListener, { once: true });
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
return await fetch(url, {
|
|
44
|
+
...fetchOptions,
|
|
45
|
+
signal: controller.signal,
|
|
46
|
+
});
|
|
47
|
+
} catch (err) {
|
|
48
|
+
if (controller.signal.aborted && controller.signal.reason) {
|
|
49
|
+
const reason = controller.signal.reason;
|
|
50
|
+
if (reason instanceof Error && (reason.name === 'TimeoutError' || reason.code === 'ETIMEDOUT')) {
|
|
51
|
+
throw reason;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (err && err.name === 'AbortError' && controller.signal.aborted && controller.signal.reason) {
|
|
55
|
+
throw controller.signal.reason;
|
|
56
|
+
}
|
|
57
|
+
throw err;
|
|
58
|
+
} finally {
|
|
59
|
+
if (timer) clearTimeout(timer);
|
|
60
|
+
if (signal && callerSignalListener) {
|
|
61
|
+
signal.removeEventListener('abort', callerSignalListener);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
2
66
|
// API helper
|
|
3
67
|
const api = {
|
|
68
|
+
fetch: fetchWithTimeout,
|
|
4
69
|
async request(path, options = {}) {
|
|
5
70
|
const adminPath = window.__ADMIN_PATH__ || '/_admin';
|
|
6
71
|
const url = adminPath + '/api' + path;
|
|
7
|
-
const
|
|
8
|
-
|
|
72
|
+
const { timeout = 30000, signal, ...fetchOpts } = options;
|
|
73
|
+
const response = await fetchWithTimeout(url, {
|
|
74
|
+
...fetchOpts,
|
|
75
|
+
timeout,
|
|
76
|
+
signal,
|
|
9
77
|
headers: {
|
|
10
78
|
'Content-Type': 'application/json',
|
|
11
|
-
...
|
|
79
|
+
...fetchOpts.headers,
|
|
12
80
|
},
|
|
13
81
|
credentials: 'include',
|
|
14
82
|
});
|
|
@@ -28,20 +96,24 @@ const api = {
|
|
|
28
96
|
return response.json();
|
|
29
97
|
},
|
|
30
98
|
|
|
31
|
-
get(path) { return this.request(path, { method: 'GET' }); },
|
|
32
|
-
post(path, data) { return this.request(path, { method: 'POST', body: JSON.stringify(data) }); },
|
|
33
|
-
put(path, data) { return this.request(path, { method: 'PUT', body: JSON.stringify(data) }); },
|
|
34
|
-
delete(path) { return this.request(path, { method: 'DELETE' }); },
|
|
99
|
+
get(path, options) { return this.request(path, { ...options, method: 'GET' }); },
|
|
100
|
+
post(path, data, options) { return this.request(path, { ...options, method: 'POST', body: JSON.stringify(data) }); },
|
|
101
|
+
put(path, data, options) { return this.request(path, { ...options, method: 'PUT', body: JSON.stringify(data) }); },
|
|
102
|
+
delete(path, options) { return this.request(path, { ...options, method: 'DELETE' }); },
|
|
35
103
|
};
|
|
36
104
|
|
|
37
105
|
/** POST /data-exchange/export/:model ā validates JSON errors vs .xlsx blob */
|
|
38
|
-
async function downloadDataExchangeXlsx(modelName, payload) {
|
|
106
|
+
async function downloadDataExchangeXlsx(modelName, payload, options = {}) {
|
|
39
107
|
const adminPath = window.__ADMIN_PATH__ || '/_admin';
|
|
40
|
-
const
|
|
108
|
+
const { timeout = 60000, signal, headers = {}, ...restOpts } = options;
|
|
109
|
+
const res = await fetchWithTimeout(adminPath + '/api/data-exchange/export/' + modelName, {
|
|
41
110
|
method: 'POST',
|
|
42
111
|
credentials: 'include',
|
|
43
|
-
headers: { 'Content-Type': 'application/json' },
|
|
112
|
+
headers: { 'Content-Type': 'application/json', ...headers },
|
|
44
113
|
body: JSON.stringify(payload),
|
|
114
|
+
timeout,
|
|
115
|
+
signal,
|
|
116
|
+
...restOpts,
|
|
45
117
|
});
|
|
46
118
|
const ct = (res.headers.get('content-type') || '').toLowerCase();
|
|
47
119
|
if (!res.ok || ct.indexOf('spreadsheet') === -1) {
|
|
@@ -572,7 +572,8 @@ async function handleAdminFileUpload(file, onChange, meta, state) {
|
|
|
572
572
|
var fd = new FormData();
|
|
573
573
|
fd.append('file', file);
|
|
574
574
|
try {
|
|
575
|
-
var
|
|
575
|
+
var fetchFn = (typeof fetchWithTimeout === 'function' ? fetchWithTimeout : fetch);
|
|
576
|
+
var res = await fetchFn(uploadUrl, { method: 'POST', body: fd, credentials: 'include', timeout: 60000 });
|
|
576
577
|
var data = {};
|
|
577
578
|
try { data = await res.json(); } catch (e2) { data = {}; }
|
|
578
579
|
if (!res.ok) {
|
|
@@ -619,7 +620,8 @@ async function handleAdminMultipleFilesUpload(files, onChange, meta, state, curr
|
|
|
619
620
|
var fd = new FormData();
|
|
620
621
|
fd.append('file', file);
|
|
621
622
|
try {
|
|
622
|
-
var
|
|
623
|
+
var fetchFn = (typeof fetchWithTimeout === 'function' ? fetchWithTimeout : fetch);
|
|
624
|
+
var res = await fetchFn(uploadUrl, { method: 'POST', body: fd, credentials: 'include', timeout: 60000 });
|
|
623
625
|
var data = {};
|
|
624
626
|
try { data = await res.json(); } catch (_) { data = {}; }
|
|
625
627
|
if (res.ok && (data.url || data.publicUrl)) {
|
|
@@ -316,10 +316,11 @@ const RecordList = {
|
|
|
316
316
|
const fd = new FormData();
|
|
317
317
|
fd.append('file', file);
|
|
318
318
|
try {
|
|
319
|
-
const
|
|
319
|
+
const fetchFn = (typeof fetchWithTimeout === 'function' ? fetchWithTimeout : fetch);
|
|
320
|
+
const res = await fetchFn(
|
|
320
321
|
adminPath + '/api/data-exchange/import/' + modelName +
|
|
321
322
|
'?mode=' + encodeURIComponent(mode) + '&upsertKey=' + encodeURIComponent(upsertKey),
|
|
322
|
-
{ method: 'POST', body: fd, credentials: 'include' }
|
|
323
|
+
{ method: 'POST', body: fd, credentials: 'include', timeout: 60000 }
|
|
323
324
|
);
|
|
324
325
|
const body = await res.json().catch(function () { return ({}); });
|
|
325
326
|
if (!res.ok) {
|
|
@@ -8,6 +8,8 @@ window.__ADMIN_COMPONENTS__ = {
|
|
|
8
8
|
RecordForm,
|
|
9
9
|
api,
|
|
10
10
|
state,
|
|
11
|
+
fetch: typeof fetchWithTimeout !== 'undefined' ? fetchWithTimeout : undefined,
|
|
12
|
+
fetchWithTimeout: typeof fetchWithTimeout !== 'undefined' ? fetchWithTimeout : undefined,
|
|
11
13
|
notify: typeof window !== 'undefined' ? window.notify : undefined,
|
|
12
14
|
confirmModal: typeof window !== 'undefined' ? window.confirmModal : undefined,
|
|
13
15
|
toastState: typeof window !== 'undefined' ? window.toastState : undefined,
|
|
@@ -22,6 +24,10 @@ if (typeof window !== 'undefined') {
|
|
|
22
24
|
window.Admin = window.Admin || {};
|
|
23
25
|
window.Admin.api = api;
|
|
24
26
|
window.Admin.state = state;
|
|
27
|
+
if (typeof fetchWithTimeout !== 'undefined') {
|
|
28
|
+
window.Admin.fetch = fetchWithTimeout;
|
|
29
|
+
window.Admin.fetchWithTimeout = fetchWithTimeout;
|
|
30
|
+
}
|
|
25
31
|
if (typeof window.AdminUI !== 'undefined') {
|
|
26
32
|
window.Admin.ui = window.AdminUI;
|
|
27
33
|
}
|
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
const os = require('os');
|
|
8
8
|
const https = require('https');
|
|
9
9
|
const { sanitizeForOutput } = require('../../../core/orm/utils');
|
|
10
|
+
const { buildFilteredQuery } = require('../../../core/orm/query-filters');
|
|
11
|
+
const { safeJsonParse } = require('../../../core/utils/json');
|
|
10
12
|
|
|
11
13
|
function getWebspressoVersion() {
|
|
12
14
|
try {
|
|
@@ -115,82 +117,7 @@ function formatBytes(bytes) {
|
|
|
115
117
|
return (bytes / (1024 * 1024)).toFixed(1) + ' MB';
|
|
116
118
|
}
|
|
117
119
|
|
|
118
|
-
/**
|
|
119
|
-
* Build query with filters applied
|
|
120
|
-
* @param {Object} repo - Repository instance
|
|
121
|
-
* @param {Object} filters - Filter object from frontend
|
|
122
|
-
* @param {Object} [options] - Options
|
|
123
|
-
* @param {boolean} [options.onlyTrashed] - For soft delete: only trashed records
|
|
124
|
-
* @returns {Object} Query builder with filters applied
|
|
125
|
-
*/
|
|
126
|
-
function buildFilteredQuery(repo, filters, options = {}) {
|
|
127
|
-
let query = repo.query();
|
|
128
|
-
if (options.onlyTrashed) {
|
|
129
|
-
query = query.onlyTrashed();
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
if (!filters || Object.keys(filters).length === 0) {
|
|
133
|
-
return query;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
for (const [column, filter] of Object.entries(filters)) {
|
|
137
|
-
if (!filter) continue;
|
|
138
|
-
|
|
139
|
-
const op = filter.op || filter.operator || 'contains';
|
|
140
120
|
|
|
141
|
-
if (op === 'is_null') {
|
|
142
|
-
query = query.whereNull(column);
|
|
143
|
-
continue;
|
|
144
|
-
}
|
|
145
|
-
if (op === 'is_not_null') {
|
|
146
|
-
query = query.whereNotNull(column);
|
|
147
|
-
continue;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
if (filter.value === '' && !filter.from && !filter.to) continue;
|
|
151
|
-
|
|
152
|
-
switch (op) {
|
|
153
|
-
case 'contains':
|
|
154
|
-
query = query.where(column, 'like', `%${filter.value}%`);
|
|
155
|
-
break;
|
|
156
|
-
case 'equals':
|
|
157
|
-
query = query.where(column, '=', filter.value);
|
|
158
|
-
break;
|
|
159
|
-
case 'starts_with':
|
|
160
|
-
query = query.where(column, 'like', `${filter.value}%`);
|
|
161
|
-
break;
|
|
162
|
-
case 'ends_with':
|
|
163
|
-
query = query.where(column, 'like', `%${filter.value}`);
|
|
164
|
-
break;
|
|
165
|
-
case 'eq':
|
|
166
|
-
query = query.where(column, '=', filter.value);
|
|
167
|
-
break;
|
|
168
|
-
case 'gt':
|
|
169
|
-
query = query.where(column, '>', filter.value);
|
|
170
|
-
break;
|
|
171
|
-
case 'gte':
|
|
172
|
-
query = query.where(column, '>=', filter.value);
|
|
173
|
-
break;
|
|
174
|
-
case 'lt':
|
|
175
|
-
query = query.where(column, '<', filter.value);
|
|
176
|
-
break;
|
|
177
|
-
case 'lte':
|
|
178
|
-
query = query.where(column, '<=', filter.value);
|
|
179
|
-
break;
|
|
180
|
-
case 'between':
|
|
181
|
-
if (filter.from) query = query.where(column, '>=', filter.from);
|
|
182
|
-
if (filter.to) query = query.where(column, '<=', filter.to);
|
|
183
|
-
break;
|
|
184
|
-
case 'in':
|
|
185
|
-
if (Array.isArray(filter.value) && filter.value.length > 0) {
|
|
186
|
-
query = query.whereIn(column, filter.value);
|
|
187
|
-
}
|
|
188
|
-
break;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
return query;
|
|
193
|
-
}
|
|
194
121
|
|
|
195
122
|
/**
|
|
196
123
|
* Get all record IDs matching filters (for selectAll mode)
|
|
@@ -755,11 +682,7 @@ function createExtensionApiHandlers(options) {
|
|
|
755
682
|
let filters = body.filters ?? req.query.filters;
|
|
756
683
|
if (typeof selectAll === 'string') selectAll = selectAll === 'true';
|
|
757
684
|
if (typeof filters === 'string') {
|
|
758
|
-
|
|
759
|
-
filters = JSON.parse(filters);
|
|
760
|
-
} catch {
|
|
761
|
-
filters = undefined;
|
|
762
|
-
}
|
|
685
|
+
filters = safeJsonParse(filters, undefined);
|
|
763
686
|
}
|
|
764
687
|
|
|
765
688
|
// Support IDs from query string (GET) or body (POST)
|
|
@@ -608,7 +608,7 @@ function adminPanelPlugin(options = {}) {
|
|
|
608
608
|
}
|
|
609
609
|
|
|
610
610
|
// Log admin panel URL
|
|
611
|
-
console.log(`\nš Admin Panel v2.0 available at: http://localhost:${process.env.PORT ||
|
|
611
|
+
console.log(`\nš Admin Panel v2.0 available at: http://localhost:${process.env.PORT || 7331}${adminPath}\n`);
|
|
612
612
|
},
|
|
613
613
|
|
|
614
614
|
/**
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const { getClientIp } = require('../../../core/utils/ip');
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
6
|
* In-memory brute-force rate limiter for admin login.
|
|
5
7
|
* Zero external dependencies.
|
|
@@ -20,19 +22,7 @@ class LoginRateLimiter {
|
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
getClientIp(req) {
|
|
23
|
-
|
|
24
|
-
if (req.ip) return String(req.ip);
|
|
25
|
-
if (req.headers && req.headers['x-forwarded-for']) {
|
|
26
|
-
const forwarded = String(req.headers['x-forwarded-for']).split(',')[0].trim();
|
|
27
|
-
if (forwarded) return forwarded;
|
|
28
|
-
}
|
|
29
|
-
if (req.connection && req.connection.remoteAddress) {
|
|
30
|
-
return String(req.connection.remoteAddress);
|
|
31
|
-
}
|
|
32
|
-
if (req.socket && req.socket.remoteAddress) {
|
|
33
|
-
return String(req.socket.remoteAddress);
|
|
34
|
-
}
|
|
35
|
-
return '127.0.0.1';
|
|
25
|
+
return getClientIp(req);
|
|
36
26
|
}
|
|
37
27
|
|
|
38
28
|
isBlocked(req) {
|
|
@@ -111,6 +101,18 @@ class LoginRateLimiter {
|
|
|
111
101
|
this.attempts.delete(ip);
|
|
112
102
|
}
|
|
113
103
|
}
|
|
104
|
+
|
|
105
|
+
// Hard ceiling to prevent unbounded memory growth under distributed IP attacks
|
|
106
|
+
const MAX_ENTRIES = 5000;
|
|
107
|
+
if (this.attempts.size > MAX_ENTRIES) {
|
|
108
|
+
const excess = this.attempts.size - MAX_ENTRIES;
|
|
109
|
+
let count = 0;
|
|
110
|
+
for (const ip of this.attempts.keys()) {
|
|
111
|
+
this.attempts.delete(ip);
|
|
112
|
+
count++;
|
|
113
|
+
if (count >= excess) break;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
114
116
|
}
|
|
115
117
|
}
|
|
116
118
|
|
|
@@ -498,7 +498,7 @@ const VersionUpdateToast = {
|
|
|
498
498
|
m('div.mt-2.5.flex.items-center.gap-2', [
|
|
499
499
|
m('code.text-[11px].bg-gray-100.dark:bg-slate-800.text-gray-800.dark:text-slate-200.px-2.py-1.rounded.font-mono.border.border-gray-200.dark:border-slate-700.select-all', 'npm i webspresso@latest'),
|
|
500
500
|
m('a.text-xs.font-medium.text-indigo-600.dark:text-indigo-400.hover:underline.ml-auto', {
|
|
501
|
-
href: 'https://github.com/
|
|
501
|
+
href: 'https://github.com/litepacks/webspresso/releases',
|
|
502
502
|
target: '_blank',
|
|
503
503
|
rel: 'noopener noreferrer',
|
|
504
504
|
}, 'Changelog')
|
|
@@ -8,30 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
const crypto = require('crypto');
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
* Compare two strings in constant time to prevent timing attacks.
|
|
13
|
-
* Uses dummy buffer comparison if lengths differ to avoid leaking length via response timing.
|
|
14
|
-
*
|
|
15
|
-
* @param {string} a
|
|
16
|
-
* @param {string} b
|
|
17
|
-
* @returns {boolean}
|
|
18
|
-
*/
|
|
19
|
-
function safeCompare(a, b) {
|
|
20
|
-
if (typeof a !== 'string' || typeof b !== 'string') {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const bufA = Buffer.from(a, 'utf8');
|
|
25
|
-
const bufB = Buffer.from(b, 'utf8');
|
|
26
|
-
|
|
27
|
-
if (bufA.length !== bufB.length) {
|
|
28
|
-
// Perform dummy timing-safe comparison with itself to preserve constant execution time
|
|
29
|
-
crypto.timingSafeEqual(bufA, bufA);
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return crypto.timingSafeEqual(bufA, bufB);
|
|
34
|
-
}
|
|
11
|
+
const { safeCompare, sha256, randomToken } = require('../../core/utils/crypto');
|
|
35
12
|
|
|
36
13
|
/**
|
|
37
14
|
* Hash a raw API key using SHA-256
|
|
@@ -43,7 +20,7 @@ function hashKey(rawKey) {
|
|
|
43
20
|
if (typeof rawKey !== 'string' || rawKey.length === 0) {
|
|
44
21
|
return '';
|
|
45
22
|
}
|
|
46
|
-
return
|
|
23
|
+
return sha256(rawKey);
|
|
47
24
|
}
|
|
48
25
|
|
|
49
26
|
/**
|
|
@@ -80,7 +57,7 @@ function generateKey(options = {}) {
|
|
|
80
57
|
const prefix = typeof options.prefix === 'string' ? options.prefix : 'wsp_live_';
|
|
81
58
|
const byteLength = typeof options.byteLength === 'number' && options.byteLength > 0 ? options.byteLength : 24;
|
|
82
59
|
|
|
83
|
-
const randomPart =
|
|
60
|
+
const randomPart = randomToken(byteLength, 'base64url');
|
|
84
61
|
const key = `${prefix}${randomPart}`;
|
|
85
62
|
const hash = hashKey(key);
|
|
86
63
|
const hint = maskKey(key, prefix);
|