webspresso 0.0.105 → 0.0.106
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 +15 -2
- package/.agents/CLI.md +219 -7
- package/.agents/FLAGS.md +118 -0
- package/.agents/LOGGING.md +93 -0
- package/.agents/METRICS.md +127 -0
- package/.agents/MIGRATION_JOBS.md +95 -0
- package/.agents/PLUGINS.md +10 -3
- package/.agents/QUEUE.md +42 -0
- package/.agents/RATE_LIMIT.md +147 -0
- package/.agents/SCALE_OUT.md +109 -0
- package/.agents/SECRETS.md +117 -0
- package/AGENTS.md +10 -0
- package/bin/commands/add-aws.js +396 -0
- package/bin/commands/add-ci.js +523 -0
- package/bin/commands/add-cloudflare.js +240 -0
- package/bin/commands/add-cloudrun.js +381 -0
- package/bin/commands/add-migration-job.js +396 -0
- package/bin/commands/assets-sync.js +209 -0
- package/bin/commands/client-generate.js +52 -0
- package/bin/commands/console.js +53 -0
- package/bin/commands/db-migrate.js +47 -2
- package/bin/commands/db-studio.js +84 -0
- package/bin/commands/deploy-check.js +242 -13
- package/bin/commands/export.js +87 -0
- package/bin/commands/secrets-pull.js +208 -0
- package/bin/utils/db.js +7 -1
- package/bin/webspresso.js +22 -0
- package/core/app.js +421 -0
- package/core/auth/authenticate.js +93 -0
- package/core/auth/index.js +34 -4
- package/core/auth/manager.js +50 -5
- package/core/auth/middleware.js +16 -68
- package/core/auth/redis-session.js +1008 -0
- package/core/auth/sessions.js +156 -0
- package/core/cache/cdn.js +296 -0
- package/core/cache/index.js +12 -0
- package/core/cache/tagged-lru.js +9 -1
- package/core/console/commands.js +148 -0
- package/core/console/context.js +260 -0
- package/core/console/eval.js +70 -0
- package/core/console/index.js +22 -0
- package/core/console/repl.js +102 -0
- package/core/errors/domain.js +1 -0
- package/core/events/dispatcher.js +7 -0
- package/core/events/signal.js +7 -0
- package/core/export/discovery.js +191 -0
- package/core/export/exporter.js +277 -0
- package/core/export/index.js +24 -0
- package/core/flags/evaluator.js +252 -0
- package/core/flags/hasher.js +37 -0
- package/core/flags/index.js +21 -0
- package/core/flags/manager.js +263 -0
- package/core/flags/store.js +126 -0
- package/core/health/middleware.js +3 -3
- package/core/http/adapter.js +74 -0
- package/core/http/express-adapter.js +46 -0
- package/core/http/hono-adapter.js +531 -0
- package/core/http/index.js +41 -0
- package/core/http/pipeline.js +485 -0
- package/core/index.js +336 -0
- package/core/limits/middleware.js +9 -1
- package/core/logger/formatters.js +264 -0
- package/core/logger/index.js +260 -0
- package/core/logger/trace.js +137 -0
- package/core/metrics/collectors.js +125 -0
- package/core/metrics/index.js +45 -0
- package/core/metrics/middleware.js +230 -0
- package/core/metrics/registry.js +366 -0
- package/core/orm/d1.js +265 -0
- package/core/orm/index.js +105 -5
- package/core/orm/migrate-cloud.js +194 -0
- package/core/orm/pool.js +97 -0
- package/core/orm/query-builder.js +9 -0
- package/core/queue/adapters/cloudflare.js +131 -0
- package/core/queue/adapters/pubsub.js +400 -0
- package/core/queue/adapters/sqs.js +419 -0
- package/core/queue/adapters/wait-until.js +77 -0
- package/core/queue/index.js +8 -0
- package/core/queue/manager.js +11 -0
- package/core/rate-limit/index.js +22 -0
- package/core/rate-limit/limiter.js +219 -0
- package/core/rate-limit/stores/memory.js +129 -0
- package/core/rate-limit/stores/redis.js +151 -0
- package/core/rate-limit/utils.js +112 -0
- package/core/resilience/circuit-breaker.js +31 -0
- package/core/secrets/index.js +113 -0
- package/core/secrets/manager.js +308 -0
- package/core/secrets/providers/aws.js +288 -0
- package/core/secrets/providers/env.js +44 -0
- package/core/secrets/providers/gcp.js +307 -0
- package/core/secrets/providers/memory.js +76 -0
- package/core/shutdown/shutdown-manager.js +9 -0
- package/core/stream/index.js +19 -0
- package/core/stream/text-stream.js +326 -0
- package/core/studio/index.js +43 -0
- package/core/studio/inspector.js +258 -0
- package/core/studio/server.js +325 -0
- package/core/studio/ui.js +681 -0
- package/index.d.ts +934 -2
- package/index.js +125 -3
- package/package.json +3 -1
- package/plugins/admin-panel/index.js +12 -5
- package/plugins/api-key/index.js +3 -2
- package/plugins/audit-log/index.js +3 -1
- package/plugins/basic-auth/index.js +3 -2
- package/plugins/cors.js +3 -2
- package/plugins/csrf/index.js +4 -3
- package/plugins/csv/index.js +8 -5
- package/plugins/email/index.js +11 -9
- package/plugins/index.js +3 -0
- package/plugins/queue/index.js +18 -2
- package/plugins/redirect/index.js +7 -2
- package/plugins/seo-checker/index.js +2 -2
- package/plugins/site-analytics/index.js +3 -1
- package/plugins/swagger.js +8 -2
- package/plugins/upload/gcs-provider.js +148 -0
- package/plugins/upload/index.js +132 -74
- package/plugins/upload/s3-provider.js +257 -0
- package/plugins/webhooks/index.js +27 -23
- package/plugins/xlsx/index.js +7 -5
- package/src/api/api-loader.js +12 -95
- package/src/api/define-api.js +1 -0
- package/src/client-runtime/constants.js +10 -0
- package/src/client-runtime/mount.js +2 -3
- package/src/dev/client-gen.js +458 -0
- package/src/discovery/scan-routes.js +5 -2
- package/src/file-router.js +2 -0
- package/src/helpers.js +53 -0
- package/src/pages/page-loader.js +12 -205
- package/src/plugin-manager.js +9 -1
- package/src/server.js +231 -140
- package/src/services/executor.js +9 -0
- package/src/services/registry.js +9 -1
- package/src/services/validator.js +38 -20
|
@@ -113,34 +113,39 @@ function webhooksPlugin(options = {}) {
|
|
|
113
113
|
// Attach dispatcher to app and request objects
|
|
114
114
|
if (ctx.app) {
|
|
115
115
|
ctx.app.webhooks = dispatcher;
|
|
116
|
-
|
|
116
|
+
}
|
|
117
|
+
const target = ctx.http || ctx.app;
|
|
118
|
+
if (target && typeof target.use === 'function') {
|
|
119
|
+
target.use((req, res, next) => {
|
|
117
120
|
req.webhooks = dispatcher;
|
|
118
121
|
next();
|
|
119
122
|
});
|
|
123
|
+
}
|
|
120
124
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
if (!ctx.app.serviceRegistry.has('webhook.retry')) {
|
|
134
|
-
ctx.app.serviceRegistry.register('webhook.retry', {
|
|
135
|
-
handler: async (input) => dispatcher.retryDelivery(input.deliveryId),
|
|
136
|
-
});
|
|
137
|
-
}
|
|
125
|
+
// Register built-in services in app.serviceRegistry if available
|
|
126
|
+
const registry = ctx.serviceRegistry || ctx.services || ctx.app?.serviceRegistry;
|
|
127
|
+
if (registry && typeof registry.register === 'function') {
|
|
128
|
+
if (!registry.has('webhook.dispatch')) {
|
|
129
|
+
registry.register('webhook.dispatch', {
|
|
130
|
+
handler: async (input) => dispatcher.dispatch(input.event, input.payload, input),
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
if (!registry.has('webhook.ping')) {
|
|
134
|
+
registry.register('webhook.ping', {
|
|
135
|
+
handler: async (input) => dispatcher.pingEndpoint(input.endpointId),
|
|
136
|
+
});
|
|
138
137
|
}
|
|
138
|
+
if (!registry.has('webhook.retry')) {
|
|
139
|
+
registry.register('webhook.retry', {
|
|
140
|
+
handler: async (input) => dispatcher.retryDelivery(input.deliveryId),
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}
|
|
139
144
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
145
|
+
// Integrate with core/queue if queue is present
|
|
146
|
+
const queueManager = options.queue || ctx.queue || ctx.app?.queue;
|
|
147
|
+
if (queueManager && typeof queueManager.define === 'function') {
|
|
148
|
+
dispatcher.setQueue(queueManager);
|
|
144
149
|
if (!queueManager.handlers?.has?.('webhooks.deliver')) {
|
|
145
150
|
queueManager.define('webhooks.deliver', async (job) => {
|
|
146
151
|
const { endpointId, deliveryId, event, payload, attempt } = job.data;
|
|
@@ -167,7 +172,6 @@ function webhooksPlugin(options = {}) {
|
|
|
167
172
|
});
|
|
168
173
|
}
|
|
169
174
|
}
|
|
170
|
-
}
|
|
171
175
|
|
|
172
176
|
return () => {
|
|
173
177
|
dispatcher.dispose();
|
package/plugins/xlsx/index.js
CHANGED
|
@@ -53,12 +53,13 @@ function xlsxPlugin(options = {}) {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
// 2. Register built-in services (xlsx.generate, xlsx.parse, xlsx.exportModel)
|
|
56
|
-
|
|
56
|
+
const registry = ctx.serviceRegistry || ctx.services || ctx.app?.serviceRegistry;
|
|
57
|
+
if (registry && typeof registry.register === 'function') {
|
|
57
58
|
const db = dbOption ?? ctx.db ?? ctx.app?.get?.('db') ?? null;
|
|
58
59
|
const services = createXlsxServices({ db, ...options });
|
|
59
60
|
for (const [name, def] of Object.entries(services)) {
|
|
60
|
-
if (!
|
|
61
|
-
|
|
61
|
+
if (!registry.has(name)) {
|
|
62
|
+
registry.register(name, def);
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
65
|
}
|
|
@@ -74,8 +75,9 @@ function xlsxPlugin(options = {}) {
|
|
|
74
75
|
ctx.middlewares.xlsx = middleware;
|
|
75
76
|
}
|
|
76
77
|
|
|
77
|
-
|
|
78
|
-
|
|
78
|
+
const target = ctx.http || ctx.app;
|
|
79
|
+
if (target && typeof target.use === 'function') {
|
|
80
|
+
target.use(middleware);
|
|
79
81
|
}
|
|
80
82
|
},
|
|
81
83
|
};
|
package/src/api/api-loader.js
CHANGED
|
@@ -11,6 +11,7 @@ const { ZodError } = require('zod');
|
|
|
11
11
|
const { z: zForApi } = require('../../core/validation');
|
|
12
12
|
const { resolveMiddlewares } = require('../file-router');
|
|
13
13
|
const { translateValidationIssues, getTranslatorForRequest } = require('./validation-i18n');
|
|
14
|
+
const { executeApiPipeline, enrichRouteError } = require('../../core/http');
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* Compiles a schema definition from an API module
|
|
@@ -136,110 +137,26 @@ function createApiHandler(descriptor, context) {
|
|
|
136
137
|
}
|
|
137
138
|
}
|
|
138
139
|
|
|
139
|
-
// 2.
|
|
140
|
-
if (db) req.db = db;
|
|
141
|
-
if (serviceRegistry) {
|
|
142
|
-
req.service = (name, input, opts) =>
|
|
143
|
-
serviceRegistry.call(name, input, { req, res, db }, opts);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// 3. Schema validation
|
|
147
|
-
if (compiledSchema) {
|
|
148
|
-
try {
|
|
149
|
-
validateRequestInput(req, compiledSchema);
|
|
150
|
-
} catch (err) {
|
|
151
|
-
if (err instanceof ZodError || err.name === 'ZodError' || Array.isArray(err?.issues)) {
|
|
152
|
-
const pagesDir = context.pagesDir || appOptions.pagesDir || 'pages';
|
|
153
|
-
const routeDir = descriptor.file ? path.dirname(descriptor.file) : '';
|
|
154
|
-
const translatedIssues = translateValidationIssues(err.issues, {
|
|
155
|
-
req,
|
|
156
|
-
pagesDir,
|
|
157
|
-
routeDir,
|
|
158
|
-
isDev,
|
|
159
|
-
});
|
|
160
|
-
return res.status(400).json({
|
|
161
|
-
error: 'Validation Error',
|
|
162
|
-
issues: translatedIssues,
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
throw err;
|
|
166
|
-
}
|
|
167
|
-
} else {
|
|
168
|
-
req.input = {
|
|
169
|
-
body: req.body,
|
|
170
|
-
params: req.params,
|
|
171
|
-
query: req.query,
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// 4. Resolve and execute middlewares (module-local first, cached across requests)
|
|
140
|
+
// 2. Resolve middlewares (module-local first, cached across requests)
|
|
176
141
|
if (!cachedMiddlewares) {
|
|
177
142
|
const moduleMiddlewares = descriptor.moduleConfig?.middlewares || {};
|
|
178
143
|
const combinedRegistry = Object.assign({}, middlewares, moduleMiddlewares);
|
|
179
144
|
cachedMiddlewares = resolveMiddlewares(apiDef.middleware, combinedRegistry);
|
|
180
145
|
}
|
|
181
146
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
} catch (syncErr) {
|
|
191
|
-
reject(syncErr);
|
|
192
|
-
}
|
|
193
|
-
});
|
|
194
|
-
if (res.headersSent) return;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
// 5. Execute handler
|
|
198
|
-
const pagesDir = context.pagesDir || appOptions.pagesDir || 'pages';
|
|
199
|
-
const routeDir = descriptor.file ? path.dirname(descriptor.file) : '';
|
|
200
|
-
const tr = getTranslatorForRequest(req, { pagesDir, routeDir, isDev });
|
|
201
|
-
|
|
202
|
-
const apiCtx = {
|
|
147
|
+
// 3. Execute framework-agnostic API pipeline
|
|
148
|
+
await executeApiPipeline({
|
|
149
|
+
descriptor,
|
|
150
|
+
context,
|
|
151
|
+
apiDef,
|
|
152
|
+
handlerFn,
|
|
153
|
+
compiledSchema,
|
|
154
|
+
middlewares: cachedMiddlewares,
|
|
203
155
|
req,
|
|
204
156
|
res,
|
|
205
|
-
|
|
206
|
-
query: req.query || {},
|
|
207
|
-
body: req.body || {},
|
|
208
|
-
input: req.input,
|
|
209
|
-
locale: tr.locale,
|
|
210
|
-
t: tr.t,
|
|
211
|
-
service: (name, input, opts) =>
|
|
212
|
-
serviceRegistry ? serviceRegistry.call(name, input, { req, res, db }, opts) : null,
|
|
213
|
-
module: descriptor.module || null,
|
|
214
|
-
config: appOptions,
|
|
215
|
-
logger: console,
|
|
216
|
-
db,
|
|
217
|
-
sse: (sourceOrOptions, maybeOptions) => res.sse(sourceOrOptions, maybeOptions),
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
req.ctx = apiCtx;
|
|
221
|
-
res.service = apiCtx.service;
|
|
222
|
-
res.input = apiCtx.input;
|
|
223
|
-
res.module = apiCtx.module;
|
|
224
|
-
|
|
225
|
-
const result = await handlerFn(req, res, apiCtx);
|
|
226
|
-
|
|
227
|
-
// 6. Auto-respond if handler returned a value and response not yet sent
|
|
228
|
-
if (!res.headersSent) {
|
|
229
|
-
if (result !== undefined) {
|
|
230
|
-
return res.json(result);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
157
|
+
});
|
|
233
158
|
} catch (err) {
|
|
234
|
-
|
|
235
|
-
if (!err.route) err.route = descriptor.path;
|
|
236
|
-
if (!err.method) err.method = descriptor.method ? descriptor.method.toUpperCase() : (req.method || 'GET');
|
|
237
|
-
if (!err.source) err.source = descriptor.source || descriptor.file;
|
|
238
|
-
if (!err.file) err.file = descriptor.file;
|
|
239
|
-
if (!err.module) err.module = descriptor.module || null;
|
|
240
|
-
if (!err.phase) err.phase = 'handler';
|
|
241
|
-
if (!err.requestId) err.requestId = req.id || (req.headers && req.headers['x-request-id']) || null;
|
|
242
|
-
}
|
|
159
|
+
enrichRouteError(err, descriptor, req);
|
|
243
160
|
return next(err);
|
|
244
161
|
}
|
|
245
162
|
};
|
package/src/api/define-api.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
* @param {string} [config.description] - Endpoint description for OpenAPI
|
|
12
12
|
* @param {Array<string>} [config.tags] - Endpoint tags for OpenAPI
|
|
13
13
|
* @param {Array<string|Function>} [config.middleware] - Named or functional middlewares
|
|
14
|
+
* @param {string|{ key: string, statusCode?: number, message?: string }} [config.flag] - Feature flag required to access this endpoint
|
|
14
15
|
* @param {Object|Function} [config.schema] - Request schemas (params, query, body, headers)
|
|
15
16
|
* @param {Object} [config.response] - Expected response schemas by status code
|
|
16
17
|
* @param {Function} config.handler - Request handler: async (req, ctx) => data
|
|
@@ -4,9 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
const path = require('path');
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
const CLIENT_RUNTIME_BASE = '/__webspresso/client-runtime';
|
|
7
|
+
const { CLIENT_RUNTIME_BASE } = require('./constants');
|
|
10
8
|
|
|
11
9
|
/** Resolve a file next to the package's resolved main entry (works with package "exports"). */
|
|
12
10
|
function pkgFileFromMain(pkg, ...segments) {
|
|
@@ -21,6 +19,7 @@ function pkgFileFromMain(pkg, ...segments) {
|
|
|
21
19
|
function mountClientRuntime(app, flags) {
|
|
22
20
|
if (!flags || (!flags.alpine && !flags.swup)) return;
|
|
23
21
|
|
|
22
|
+
const express = require('express');
|
|
24
23
|
const router = express.Router();
|
|
25
24
|
|
|
26
25
|
function send(res, filePath) {
|