@getstrata/bootstrap 3.0.4 → 3.0.7
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/CHANGELOG.md +26 -0
- package/README.md +11 -8
- package/dist/bootstrap/application/config.d.ts +7 -0
- package/dist/bootstrap/application/services.d.ts +28 -0
- package/dist/bootstrap/application.d.ts +115 -0
- package/dist/bootstrap/auth/accountWorkflows.d.ts +68 -0
- package/dist/bootstrap/auth/runtimeConfig.d.ts +66 -0
- package/dist/bootstrap/config.d.ts +1 -1
- package/dist/bootstrap/contracts.d.ts +1 -0
- package/dist/bootstrap/createSpaRoutes.d.ts +2 -0
- package/dist/bootstrap/databaseCommands.d.ts +26 -0
- package/dist/bootstrap/discoverJobs.d.ts +1 -2
- package/dist/bootstrap/discoverListeners.d.ts +4 -0
- package/dist/bootstrap/httpKernel.d.ts +0 -1
- package/dist/bootstrap/httpResponseComposition.d.ts +32 -0
- package/dist/bootstrap/jobDiscoveryState.d.ts +12 -0
- package/dist/bootstrap/providers/events.d.ts +2 -2
- package/dist/bootstrap/public-api.d.ts +3 -2
- package/dist/bootstrap/testing.d.ts +4 -0
- package/dist/entries/application.js +1 -0
- package/dist/entries/auth/accountWorkflows.js +98 -0
- package/dist/entries/auth/runtimeConfig.js +79 -0
- package/dist/entries/buildModuleRoutes.js +114 -94
- package/dist/entries/buildWebModuleRoutes.js +114 -94
- package/dist/entries/config.js +2 -0
- package/dist/entries/context.js +12 -18
- package/dist/entries/createSpaRoutes.js +2 -2
- package/dist/entries/createWebRoutes.js +114 -94
- package/dist/entries/databaseCommands.js +103 -0
- package/dist/entries/dependencies.js +12 -18
- package/dist/entries/discoverJobs.js +2 -15
- package/dist/entries/discoverListeners.js +34 -0
- package/dist/entries/health.js +1 -0
- package/dist/entries/httpKernel.js +114 -94
- package/dist/entries/providers/auth.js +1 -0
- package/dist/entries/providers/events.js +1 -0
- package/dist/entries/providers.js +6 -15
- package/dist/entries/testing.js +10 -0
- package/dist/entries/web/routing.js +114 -94
- package/dist/entries/web/server.js +2 -1
- package/dist/index.js +3222 -2272
- package/dist/internal/jobDiscoveryState.js +14 -0
- package/package.json +35 -6
|
@@ -2,33 +2,20 @@
|
|
|
2
2
|
// ../../src/bootstrap/httpKernel.ts
|
|
3
3
|
import { establishedAuthReader as establishedAuthReader2 } from "@getstrata/core/auth/authReader";
|
|
4
4
|
import { hasVerifiedEmail } from "@getstrata/core/auth/emailVerification";
|
|
5
|
-
import {
|
|
6
|
-
CORE_TRACING_RUNTIME_TOKEN,
|
|
7
|
-
resolveAbilityChecker
|
|
8
|
-
} from "@getstrata/core/contracts/serviceTokens";
|
|
5
|
+
import { resolveAbilityChecker } from "@getstrata/core/contracts/serviceTokens";
|
|
9
6
|
import { createAuthorizeMiddleware } from "@getstrata/core/http/authorizeMiddleware";
|
|
10
|
-
import { createBodySizeLimitMiddleware } from "@getstrata/core/http/bodySizeLimitMiddleware";
|
|
11
|
-
import { createCorsMiddleware, resolveCorsConfig } from "@getstrata/core/http/corsMiddleware";
|
|
12
|
-
import { createCsrfMiddleware } from "@getstrata/core/http/csrfMiddleware";
|
|
13
7
|
import { createFlashMiddleware } from "@getstrata/core/http/flashMiddleware";
|
|
14
8
|
import { createLoginThrottleMiddleware } from "@getstrata/core/http/loginThrottleMiddleware";
|
|
15
9
|
import { createMemoryThrottleMiddleware } from "@getstrata/core/http/memoryThrottleMiddleware";
|
|
16
|
-
import { createMetricsMiddleware } from "@getstrata/core/http/metricsMiddleware";
|
|
17
|
-
import { requestIdMiddleware } from "@getstrata/core/http/middleware";
|
|
18
10
|
import { createRequireAbilityMiddleware } from "@getstrata/core/http/requireAbilityMiddleware";
|
|
19
11
|
import { createRequireAuthMiddleware } from "@getstrata/core/http/requireAuthMiddleware";
|
|
20
12
|
import { createRequireGlobalAdminMiddleware } from "@getstrata/core/http/requireGlobalAdminMiddleware";
|
|
21
13
|
import { createRequirePasswordConfirmMiddleware } from "@getstrata/core/http/requirePasswordConfirmMiddleware";
|
|
22
14
|
import { createRequireVerifiedMiddleware } from "@getstrata/core/http/requireVerifiedMiddleware";
|
|
23
15
|
import { createRequireWebAuthMiddleware } from "@getstrata/core/http/requireWebAuthMiddleware";
|
|
24
|
-
import { createJsonErrorMiddleware, createWebErrorMiddleware } from "@getstrata/core/http/response";
|
|
25
16
|
import { withMiddleware } from "@getstrata/core/http/routeMiddleware";
|
|
26
|
-
import { createSecurityHeadersMiddleware } from "@getstrata/core/http/securityHeadersMiddleware";
|
|
27
17
|
import { createValidateSignatureMiddleware } from "@getstrata/core/http/signedUrl";
|
|
28
18
|
import { createThrottleMiddleware } from "@getstrata/core/http/throttleMiddleware";
|
|
29
|
-
import { createRequestLoggingMiddleware } from "@getstrata/core/logging/requestLoggingMiddleware";
|
|
30
|
-
import { createTracingMiddleware } from "@getstrata/core/tracing/tracingMiddleware";
|
|
31
|
-
import { CORE_WEB_ERROR_VIEW_TOKEN } from "@getstrata/core/view/tokens";
|
|
32
19
|
import {
|
|
33
20
|
assertHttpHandler,
|
|
34
21
|
identityModes,
|
|
@@ -47,6 +34,7 @@ import {
|
|
|
47
34
|
CORE_EVENT_BUS_TOKEN,
|
|
48
35
|
CORE_HTTP_CLEANUP_TOKEN,
|
|
49
36
|
CORE_POLICY_GATE_TOKEN,
|
|
37
|
+
CORE_POLICY_REGISTRY_TOKEN,
|
|
50
38
|
CORE_PUBLIC_TENANCY_TOKEN,
|
|
51
39
|
CORE_QUEUE_TOKEN,
|
|
52
40
|
CORE_TENANT_RESOLVER_TOKEN,
|
|
@@ -216,39 +204,18 @@ function createHttpPersistence(invoke, options) {
|
|
|
216
204
|
};
|
|
217
205
|
}
|
|
218
206
|
|
|
219
|
-
// ../../src/bootstrap/
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
if (typeof value === "function") {
|
|
232
|
-
wrapped[path] = enter(value);
|
|
233
|
-
continue;
|
|
234
|
-
}
|
|
235
|
-
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
236
|
-
const entries = Object.entries(value);
|
|
237
|
-
if (entries.some(([, handler]) => typeof handler === "function" || handler instanceof Response)) {
|
|
238
|
-
wrapped[path] = Object.fromEntries(entries.map(([method, handler]) => {
|
|
239
|
-
const callback = handler instanceof Response ? () => handler.clone() : handler;
|
|
240
|
-
return [
|
|
241
|
-
method,
|
|
242
|
-
typeof callback === "function" ? enter(callback) : callback
|
|
243
|
-
];
|
|
244
|
-
}));
|
|
245
|
-
continue;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
wrapped[path] = value;
|
|
249
|
-
}
|
|
250
|
-
return wrapped;
|
|
251
|
-
}
|
|
207
|
+
// ../../src/bootstrap/httpResponseComposition.ts
|
|
208
|
+
import { CORE_TRACING_RUNTIME_TOKEN } from "@getstrata/core/contracts/serviceTokens";
|
|
209
|
+
import { createBodySizeLimitMiddleware } from "@getstrata/core/http/bodySizeLimitMiddleware";
|
|
210
|
+
import { createCorsMiddleware, resolveCorsConfig } from "@getstrata/core/http/corsMiddleware";
|
|
211
|
+
import { createCsrfMiddleware } from "@getstrata/core/http/csrfMiddleware";
|
|
212
|
+
import { createMetricsMiddleware } from "@getstrata/core/http/metricsMiddleware";
|
|
213
|
+
import { requestIdMiddleware } from "@getstrata/core/http/middleware";
|
|
214
|
+
import { createJsonErrorMiddleware, createWebErrorMiddleware } from "@getstrata/core/http/response";
|
|
215
|
+
import { createSecurityHeadersMiddleware } from "@getstrata/core/http/securityHeadersMiddleware";
|
|
216
|
+
import { createRequestLoggingMiddleware } from "@getstrata/core/logging/requestLoggingMiddleware";
|
|
217
|
+
import { createTracingMiddleware } from "@getstrata/core/tracing/tracingMiddleware";
|
|
218
|
+
import { CORE_WEB_ERROR_VIEW_TOKEN } from "@getstrata/core/view/tokens";
|
|
252
219
|
|
|
253
220
|
// ../../src/bootstrap/rateLimit.ts
|
|
254
221
|
var LOCAL_LOGIN_RATE_LIMIT = {
|
|
@@ -293,6 +260,97 @@ function resolveRegisterRateLimit(env = {}) {
|
|
|
293
260
|
};
|
|
294
261
|
}
|
|
295
262
|
|
|
263
|
+
// ../../src/bootstrap/httpResponseComposition.ts
|
|
264
|
+
function resolveHttpResponseSettings(dependencies, http) {
|
|
265
|
+
const config = dependencies.container.has(CORE_CONFIG_TOKEN) ? dependencies.container.resolve(CORE_CONFIG_TOKEN) : undefined;
|
|
266
|
+
const features = http?.features ?? config?.get("http.features");
|
|
267
|
+
const emailVerificationRequired = features?.emailVerificationRequired ?? false;
|
|
268
|
+
const viewsEnabled = features?.viewsEnabled ?? false;
|
|
269
|
+
const publicReadsEnabled = features?.publicReadsEnabled ?? false;
|
|
270
|
+
const etagEnabled = features?.etagEnabled ?? true;
|
|
271
|
+
const policy = http?.responsePolicy ?? config?.get("http.responsePolicy");
|
|
272
|
+
if (policy?.cors)
|
|
273
|
+
resolveCorsConfig(policy.cors);
|
|
274
|
+
const responsePolicy = Object.freeze({
|
|
275
|
+
cors: policy?.cors ? {
|
|
276
|
+
allowedOrigins: [...policy.cors.allowedOrigins ?? []],
|
|
277
|
+
additionalAllowedHeaders: [...policy.cors.additionalAllowedHeaders ?? []]
|
|
278
|
+
} : undefined,
|
|
279
|
+
securityHeaders: policy?.securityHeaders ?? {
|
|
280
|
+
production: http?.production ?? true,
|
|
281
|
+
frontendMode: viewsEnabled ? "server-htmx" : "api"
|
|
282
|
+
},
|
|
283
|
+
maxBodyBytes: policy?.maxBodyBytes ?? 1048576,
|
|
284
|
+
rateLimitPerMinute: policy?.rateLimitPerMinute ?? 120,
|
|
285
|
+
namespace: policy?.namespace ?? "strata",
|
|
286
|
+
trustForwardedFor: policy?.trustForwardedFor ?? false,
|
|
287
|
+
loginRateLimit: Object.freeze({ ...policy?.loginRateLimit ?? resolveLoginRateLimit() }),
|
|
288
|
+
registerRateLimit: Object.freeze({
|
|
289
|
+
...policy?.registerRateLimit ?? resolveRegisterRateLimit()
|
|
290
|
+
})
|
|
291
|
+
});
|
|
292
|
+
const targetOrigin = dependencies.container.has(CORE_CONFIG_TOKEN) ? dependencies.container.resolve(CORE_CONFIG_TOKEN).get(CSRF_TARGET_ORIGIN_CONFIG_KEY) : undefined;
|
|
293
|
+
const configuredCsrfMiddleware = createCsrfMiddleware({ targetOrigin, ...http?.csrf });
|
|
294
|
+
return {
|
|
295
|
+
emailVerificationRequired,
|
|
296
|
+
viewsEnabled,
|
|
297
|
+
publicReadsEnabled,
|
|
298
|
+
etagEnabled,
|
|
299
|
+
responsePolicy,
|
|
300
|
+
configuredCsrfMiddleware
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
function createHttpResponseMiddleware(dependencies, settings, errorFormat) {
|
|
304
|
+
return [
|
|
305
|
+
createCorsMiddleware(settings.responsePolicy.cors),
|
|
306
|
+
createSecurityHeadersMiddleware(settings.responsePolicy.securityHeaders),
|
|
307
|
+
createBodySizeLimitMiddleware(settings.responsePolicy.maxBodyBytes),
|
|
308
|
+
...dependencies.container.has(CORE_TRACING_RUNTIME_TOKEN) ? [createTracingMiddleware(dependencies.container.resolve(CORE_TRACING_RUNTIME_TOKEN))] : [],
|
|
309
|
+
createMetricsMiddleware(),
|
|
310
|
+
createRequestLoggingMiddleware(settings.responsePolicy.trustForwardedFor),
|
|
311
|
+
requestIdMiddleware,
|
|
312
|
+
errorFormat === "json" ? createJsonErrorMiddleware() : createWebErrorMiddleware({
|
|
313
|
+
enabled: settings.viewsEnabled,
|
|
314
|
+
production: dependencies.container.has(HTTP_PERSISTENCE_OPTIONS) ? dependencies.container.resolve(HTTP_PERSISTENCE_OPTIONS).production ?? true : true,
|
|
315
|
+
render: dependencies.container.has(CORE_WEB_ERROR_VIEW_TOKEN) ? dependencies.container.resolve(CORE_WEB_ERROR_VIEW_TOKEN) : undefined
|
|
316
|
+
})
|
|
317
|
+
];
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// ../../src/bootstrap/moduleRouteMiddleware.ts
|
|
321
|
+
function enterModuleRoutes(routes, enter) {
|
|
322
|
+
const wrapped = {};
|
|
323
|
+
for (const [path, value] of Object.entries(routes)) {
|
|
324
|
+
if (value instanceof Response) {
|
|
325
|
+
const methods = {};
|
|
326
|
+
for (const method of ["GET", "HEAD", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"]) {
|
|
327
|
+
methods[method] = enter(() => value.clone());
|
|
328
|
+
}
|
|
329
|
+
wrapped[path] = methods;
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
332
|
+
if (typeof value === "function") {
|
|
333
|
+
wrapped[path] = enter(value);
|
|
334
|
+
continue;
|
|
335
|
+
}
|
|
336
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
337
|
+
const entries = Object.entries(value);
|
|
338
|
+
if (entries.some(([, handler]) => typeof handler === "function" || handler instanceof Response)) {
|
|
339
|
+
wrapped[path] = Object.fromEntries(entries.map(([method, handler]) => {
|
|
340
|
+
const callback = handler instanceof Response ? () => handler.clone() : handler;
|
|
341
|
+
return [
|
|
342
|
+
method,
|
|
343
|
+
typeof callback === "function" ? enter(callback) : callback
|
|
344
|
+
];
|
|
345
|
+
}));
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
wrapped[path] = value;
|
|
350
|
+
}
|
|
351
|
+
return wrapped;
|
|
352
|
+
}
|
|
353
|
+
|
|
296
354
|
// ../../src/bootstrap/httpKernel.ts
|
|
297
355
|
class HttpKernel {
|
|
298
356
|
dependencies;
|
|
@@ -311,38 +369,16 @@ class HttpKernel {
|
|
|
311
369
|
this.dependencies = dependencies;
|
|
312
370
|
const http = dependencies.container.has(HTTP_PERSISTENCE_OPTIONS) ? dependencies.container.resolve(HTTP_PERSISTENCE_OPTIONS) : undefined;
|
|
313
371
|
this.httpOptions = http;
|
|
314
|
-
const
|
|
315
|
-
|
|
316
|
-
this.
|
|
317
|
-
this.
|
|
318
|
-
this.
|
|
319
|
-
this.
|
|
320
|
-
|
|
321
|
-
if (policy?.cors)
|
|
322
|
-
resolveCorsConfig(policy.cors);
|
|
323
|
-
this.responsePolicy = Object.freeze({
|
|
324
|
-
cors: policy?.cors ? {
|
|
325
|
-
allowedOrigins: [...policy.cors.allowedOrigins ?? []],
|
|
326
|
-
additionalAllowedHeaders: [...policy.cors.additionalAllowedHeaders ?? []]
|
|
327
|
-
} : undefined,
|
|
328
|
-
securityHeaders: policy?.securityHeaders ?? {
|
|
329
|
-
production: http?.production ?? true,
|
|
330
|
-
frontendMode: this.viewsEnabled ? "server-htmx" : "api"
|
|
331
|
-
},
|
|
332
|
-
maxBodyBytes: policy?.maxBodyBytes ?? 1048576,
|
|
333
|
-
rateLimitPerMinute: policy?.rateLimitPerMinute ?? 120,
|
|
334
|
-
namespace: policy?.namespace ?? "strata",
|
|
335
|
-
trustForwardedFor: policy?.trustForwardedFor ?? false,
|
|
336
|
-
loginRateLimit: Object.freeze({ ...policy?.loginRateLimit ?? resolveLoginRateLimit() }),
|
|
337
|
-
registerRateLimit: Object.freeze({
|
|
338
|
-
...policy?.registerRateLimit ?? resolveRegisterRateLimit()
|
|
339
|
-
})
|
|
340
|
-
});
|
|
341
|
-
const targetOrigin = dependencies.container.has(CORE_CONFIG_TOKEN) ? dependencies.container.resolve(CORE_CONFIG_TOKEN).get(CSRF_TARGET_ORIGIN_CONFIG_KEY) : undefined;
|
|
342
|
-
this.configuredCsrfMiddleware = createCsrfMiddleware({ targetOrigin, ...http?.csrf });
|
|
372
|
+
const settings = resolveHttpResponseSettings(dependencies, http);
|
|
373
|
+
this.emailVerificationRequired = settings.emailVerificationRequired;
|
|
374
|
+
this.viewsEnabled = settings.viewsEnabled;
|
|
375
|
+
this.publicReadsEnabled = settings.publicReadsEnabled;
|
|
376
|
+
this.etagEnabled = settings.etagEnabled;
|
|
377
|
+
this.responsePolicy = settings.responsePolicy;
|
|
378
|
+
this.configuredCsrfMiddleware = settings.configuredCsrfMiddleware;
|
|
343
379
|
this.responses = Object.freeze({
|
|
344
|
-
json: Object.freeze(
|
|
345
|
-
web: Object.freeze(
|
|
380
|
+
json: Object.freeze(createHttpResponseMiddleware(dependencies, settings, "json")),
|
|
381
|
+
web: Object.freeze(createHttpResponseMiddleware(dependencies, settings, "web"))
|
|
346
382
|
});
|
|
347
383
|
this.persistence = dependencies.container.has(HTTP_PERSISTENCE_OPTIONS) ? createHttpPersistence(dependencies.invoke, dependencies.container.resolve(HTTP_PERSISTENCE_OPTIONS)) : undefined;
|
|
348
384
|
if (dependencies.container.has(CORE_HTTP_CLEANUP_TOKEN)) {
|
|
@@ -437,22 +473,6 @@ class HttpKernel {
|
|
|
437
473
|
throw new TypeError("SCIM and identity operation declarations cannot be combined.");
|
|
438
474
|
return this.composed(handler, "json", undefined, Object.freeze([...before]));
|
|
439
475
|
}
|
|
440
|
-
responseMiddleware(errorFormat) {
|
|
441
|
-
return [
|
|
442
|
-
createCorsMiddleware(this.responsePolicy.cors),
|
|
443
|
-
createSecurityHeadersMiddleware(this.responsePolicy.securityHeaders),
|
|
444
|
-
createBodySizeLimitMiddleware(this.responsePolicy.maxBodyBytes),
|
|
445
|
-
...this.dependencies.container.has(CORE_TRACING_RUNTIME_TOKEN) ? [createTracingMiddleware(this.dependencies.container.resolve(CORE_TRACING_RUNTIME_TOKEN))] : [],
|
|
446
|
-
createMetricsMiddleware(),
|
|
447
|
-
createRequestLoggingMiddleware(this.responsePolicy.trustForwardedFor),
|
|
448
|
-
requestIdMiddleware,
|
|
449
|
-
errorFormat === "json" ? createJsonErrorMiddleware() : createWebErrorMiddleware({
|
|
450
|
-
enabled: this.viewsEnabled,
|
|
451
|
-
production: this.dependencies.container.has(HTTP_PERSISTENCE_OPTIONS) ? this.dependencies.container.resolve(HTTP_PERSISTENCE_OPTIONS).production ?? true : true,
|
|
452
|
-
render: this.dependencies.container.has(CORE_WEB_ERROR_VIEW_TOKEN) ? this.dependencies.container.resolve(CORE_WEB_ERROR_VIEW_TOKEN) : undefined
|
|
453
|
-
})
|
|
454
|
-
];
|
|
455
|
-
}
|
|
456
476
|
wrapPublicDocument(handler) {
|
|
457
477
|
assertHttpHandler(handler);
|
|
458
478
|
return ownedPublicHttpRoute(handler, (request, work) => Promise.resolve(withMiddleware(...this.responses.web)(work)(request)));
|
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
CORE_EVENT_BUS_TOKEN,
|
|
26
26
|
CORE_HTTP_CLEANUP_TOKEN,
|
|
27
27
|
CORE_POLICY_GATE_TOKEN,
|
|
28
|
+
CORE_POLICY_REGISTRY_TOKEN,
|
|
28
29
|
CORE_PUBLIC_TENANCY_TOKEN,
|
|
29
30
|
CORE_QUEUE_TOKEN,
|
|
30
31
|
CORE_TENANT_RESOLVER_TOKEN,
|
|
@@ -219,7 +220,7 @@ var appEnvSchema = defineEnvSchema({
|
|
|
219
220
|
},
|
|
220
221
|
JWT_TTL_SECONDS: {
|
|
221
222
|
integer: true,
|
|
222
|
-
minimum:
|
|
223
|
+
minimum: 1,
|
|
223
224
|
default: "3600"
|
|
224
225
|
},
|
|
225
226
|
APP_ENV: {
|
|
@@ -400,7 +401,9 @@ import { PolicyGate } from "@getstrata/core/auth/policy";
|
|
|
400
401
|
var policyProvider = {
|
|
401
402
|
name: "core.policy",
|
|
402
403
|
register({ container }) {
|
|
403
|
-
|
|
404
|
+
const gate = new PolicyGate;
|
|
405
|
+
container.set(CORE_POLICY_GATE_TOKEN, gate);
|
|
406
|
+
container.set(CORE_POLICY_REGISTRY_TOKEN, gate);
|
|
404
407
|
}
|
|
405
408
|
};
|
|
406
409
|
var policy_default = policyProvider;
|
|
@@ -469,15 +472,7 @@ async function importInfrastructure(file) {
|
|
|
469
472
|
}
|
|
470
473
|
|
|
471
474
|
// ../../src/bootstrap/discoverJobs.ts
|
|
472
|
-
|
|
473
|
-
function state(registry) {
|
|
474
|
-
let value = states.get(registry);
|
|
475
|
-
if (!value) {
|
|
476
|
-
value = { loads: new Map, registered: new Map };
|
|
477
|
-
states.set(registry, value);
|
|
478
|
-
}
|
|
479
|
-
return value;
|
|
480
|
-
}
|
|
475
|
+
import { jobDiscoveryState as state } from "#strata-job-discovery";
|
|
481
476
|
function validateClass(value, location) {
|
|
482
477
|
if (typeof value !== "function" || typeof value.jobName !== "string" || !value.jobName.trim() || !(value.prototype instanceof Job) && typeof value.prototype?.handle !== "function")
|
|
483
478
|
throw new TypeError(`Invalid job at ${location}: expected a class with nonempty static jobName and handle().`);
|
|
@@ -559,10 +554,6 @@ function discoverJobs(registry, options = {}) {
|
|
|
559
554
|
cache.set(key, pending);
|
|
560
555
|
return pending;
|
|
561
556
|
}
|
|
562
|
-
function resetDiscoverJobsForTests(registry) {
|
|
563
|
-
state(registry).loads = new Map;
|
|
564
|
-
state(registry).registered = new Map;
|
|
565
|
-
}
|
|
566
557
|
|
|
567
558
|
// ../../src/bootstrap/queue/defaultJobs.ts
|
|
568
559
|
import { ExportAuditLogsJob } from "@getstrata/core/jobs/exportAuditLogsJob";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// ../../src/bootstrap/testing.ts
|
|
3
|
+
import { jobDiscoveryState } from "#strata-job-discovery";
|
|
4
|
+
function resetDiscoverJobsForTests(registry) {
|
|
5
|
+
jobDiscoveryState(registry).loads = new Map;
|
|
6
|
+
jobDiscoveryState(registry).registered = new Map;
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
resetDiscoverJobsForTests
|
|
10
|
+
};
|
|
@@ -12,33 +12,20 @@ import {
|
|
|
12
12
|
// ../../src/bootstrap/httpKernel.ts
|
|
13
13
|
import { establishedAuthReader as establishedAuthReader2 } from "@getstrata/core/auth/authReader";
|
|
14
14
|
import { hasVerifiedEmail } from "@getstrata/core/auth/emailVerification";
|
|
15
|
-
import {
|
|
16
|
-
CORE_TRACING_RUNTIME_TOKEN,
|
|
17
|
-
resolveAbilityChecker
|
|
18
|
-
} from "@getstrata/core/contracts/serviceTokens";
|
|
15
|
+
import { resolveAbilityChecker } from "@getstrata/core/contracts/serviceTokens";
|
|
19
16
|
import { createAuthorizeMiddleware } from "@getstrata/core/http/authorizeMiddleware";
|
|
20
|
-
import { createBodySizeLimitMiddleware } from "@getstrata/core/http/bodySizeLimitMiddleware";
|
|
21
|
-
import { createCorsMiddleware, resolveCorsConfig } from "@getstrata/core/http/corsMiddleware";
|
|
22
|
-
import { createCsrfMiddleware } from "@getstrata/core/http/csrfMiddleware";
|
|
23
17
|
import { createFlashMiddleware } from "@getstrata/core/http/flashMiddleware";
|
|
24
18
|
import { createLoginThrottleMiddleware } from "@getstrata/core/http/loginThrottleMiddleware";
|
|
25
19
|
import { createMemoryThrottleMiddleware } from "@getstrata/core/http/memoryThrottleMiddleware";
|
|
26
|
-
import { createMetricsMiddleware } from "@getstrata/core/http/metricsMiddleware";
|
|
27
|
-
import { requestIdMiddleware } from "@getstrata/core/http/middleware";
|
|
28
20
|
import { createRequireAbilityMiddleware } from "@getstrata/core/http/requireAbilityMiddleware";
|
|
29
21
|
import { createRequireAuthMiddleware } from "@getstrata/core/http/requireAuthMiddleware";
|
|
30
22
|
import { createRequireGlobalAdminMiddleware } from "@getstrata/core/http/requireGlobalAdminMiddleware";
|
|
31
23
|
import { createRequirePasswordConfirmMiddleware } from "@getstrata/core/http/requirePasswordConfirmMiddleware";
|
|
32
24
|
import { createRequireVerifiedMiddleware } from "@getstrata/core/http/requireVerifiedMiddleware";
|
|
33
25
|
import { createRequireWebAuthMiddleware } from "@getstrata/core/http/requireWebAuthMiddleware";
|
|
34
|
-
import { createJsonErrorMiddleware, createWebErrorMiddleware } from "@getstrata/core/http/response";
|
|
35
26
|
import { withMiddleware } from "@getstrata/core/http/routeMiddleware";
|
|
36
|
-
import { createSecurityHeadersMiddleware } from "@getstrata/core/http/securityHeadersMiddleware";
|
|
37
27
|
import { createValidateSignatureMiddleware } from "@getstrata/core/http/signedUrl";
|
|
38
28
|
import { createThrottleMiddleware } from "@getstrata/core/http/throttleMiddleware";
|
|
39
|
-
import { createRequestLoggingMiddleware } from "@getstrata/core/logging/requestLoggingMiddleware";
|
|
40
|
-
import { createTracingMiddleware } from "@getstrata/core/tracing/tracingMiddleware";
|
|
41
|
-
import { CORE_WEB_ERROR_VIEW_TOKEN } from "@getstrata/core/view/tokens";
|
|
42
29
|
import {
|
|
43
30
|
assertHttpHandler,
|
|
44
31
|
identityModes,
|
|
@@ -57,6 +44,7 @@ import {
|
|
|
57
44
|
CORE_EVENT_BUS_TOKEN,
|
|
58
45
|
CORE_HTTP_CLEANUP_TOKEN,
|
|
59
46
|
CORE_POLICY_GATE_TOKEN,
|
|
47
|
+
CORE_POLICY_REGISTRY_TOKEN,
|
|
60
48
|
CORE_PUBLIC_TENANCY_TOKEN,
|
|
61
49
|
CORE_QUEUE_TOKEN,
|
|
62
50
|
CORE_TENANT_RESOLVER_TOKEN,
|
|
@@ -226,39 +214,18 @@ function createHttpPersistence(invoke, options) {
|
|
|
226
214
|
};
|
|
227
215
|
}
|
|
228
216
|
|
|
229
|
-
// ../../src/bootstrap/
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
if (typeof value === "function") {
|
|
242
|
-
wrapped[path] = enter(value);
|
|
243
|
-
continue;
|
|
244
|
-
}
|
|
245
|
-
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
246
|
-
const entries = Object.entries(value);
|
|
247
|
-
if (entries.some(([, handler]) => typeof handler === "function" || handler instanceof Response)) {
|
|
248
|
-
wrapped[path] = Object.fromEntries(entries.map(([method, handler]) => {
|
|
249
|
-
const callback = handler instanceof Response ? () => handler.clone() : handler;
|
|
250
|
-
return [
|
|
251
|
-
method,
|
|
252
|
-
typeof callback === "function" ? enter(callback) : callback
|
|
253
|
-
];
|
|
254
|
-
}));
|
|
255
|
-
continue;
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
wrapped[path] = value;
|
|
259
|
-
}
|
|
260
|
-
return wrapped;
|
|
261
|
-
}
|
|
217
|
+
// ../../src/bootstrap/httpResponseComposition.ts
|
|
218
|
+
import { CORE_TRACING_RUNTIME_TOKEN } from "@getstrata/core/contracts/serviceTokens";
|
|
219
|
+
import { createBodySizeLimitMiddleware } from "@getstrata/core/http/bodySizeLimitMiddleware";
|
|
220
|
+
import { createCorsMiddleware, resolveCorsConfig } from "@getstrata/core/http/corsMiddleware";
|
|
221
|
+
import { createCsrfMiddleware } from "@getstrata/core/http/csrfMiddleware";
|
|
222
|
+
import { createMetricsMiddleware } from "@getstrata/core/http/metricsMiddleware";
|
|
223
|
+
import { requestIdMiddleware } from "@getstrata/core/http/middleware";
|
|
224
|
+
import { createJsonErrorMiddleware, createWebErrorMiddleware } from "@getstrata/core/http/response";
|
|
225
|
+
import { createSecurityHeadersMiddleware } from "@getstrata/core/http/securityHeadersMiddleware";
|
|
226
|
+
import { createRequestLoggingMiddleware } from "@getstrata/core/logging/requestLoggingMiddleware";
|
|
227
|
+
import { createTracingMiddleware } from "@getstrata/core/tracing/tracingMiddleware";
|
|
228
|
+
import { CORE_WEB_ERROR_VIEW_TOKEN } from "@getstrata/core/view/tokens";
|
|
262
229
|
|
|
263
230
|
// ../../src/bootstrap/rateLimit.ts
|
|
264
231
|
var LOCAL_LOGIN_RATE_LIMIT = {
|
|
@@ -303,6 +270,97 @@ function resolveRegisterRateLimit(env = {}) {
|
|
|
303
270
|
};
|
|
304
271
|
}
|
|
305
272
|
|
|
273
|
+
// ../../src/bootstrap/httpResponseComposition.ts
|
|
274
|
+
function resolveHttpResponseSettings(dependencies, http) {
|
|
275
|
+
const config = dependencies.container.has(CORE_CONFIG_TOKEN) ? dependencies.container.resolve(CORE_CONFIG_TOKEN) : undefined;
|
|
276
|
+
const features = http?.features ?? config?.get("http.features");
|
|
277
|
+
const emailVerificationRequired = features?.emailVerificationRequired ?? false;
|
|
278
|
+
const viewsEnabled = features?.viewsEnabled ?? false;
|
|
279
|
+
const publicReadsEnabled = features?.publicReadsEnabled ?? false;
|
|
280
|
+
const etagEnabled = features?.etagEnabled ?? true;
|
|
281
|
+
const policy = http?.responsePolicy ?? config?.get("http.responsePolicy");
|
|
282
|
+
if (policy?.cors)
|
|
283
|
+
resolveCorsConfig(policy.cors);
|
|
284
|
+
const responsePolicy = Object.freeze({
|
|
285
|
+
cors: policy?.cors ? {
|
|
286
|
+
allowedOrigins: [...policy.cors.allowedOrigins ?? []],
|
|
287
|
+
additionalAllowedHeaders: [...policy.cors.additionalAllowedHeaders ?? []]
|
|
288
|
+
} : undefined,
|
|
289
|
+
securityHeaders: policy?.securityHeaders ?? {
|
|
290
|
+
production: http?.production ?? true,
|
|
291
|
+
frontendMode: viewsEnabled ? "server-htmx" : "api"
|
|
292
|
+
},
|
|
293
|
+
maxBodyBytes: policy?.maxBodyBytes ?? 1048576,
|
|
294
|
+
rateLimitPerMinute: policy?.rateLimitPerMinute ?? 120,
|
|
295
|
+
namespace: policy?.namespace ?? "strata",
|
|
296
|
+
trustForwardedFor: policy?.trustForwardedFor ?? false,
|
|
297
|
+
loginRateLimit: Object.freeze({ ...policy?.loginRateLimit ?? resolveLoginRateLimit() }),
|
|
298
|
+
registerRateLimit: Object.freeze({
|
|
299
|
+
...policy?.registerRateLimit ?? resolveRegisterRateLimit()
|
|
300
|
+
})
|
|
301
|
+
});
|
|
302
|
+
const targetOrigin = dependencies.container.has(CORE_CONFIG_TOKEN) ? dependencies.container.resolve(CORE_CONFIG_TOKEN).get(CSRF_TARGET_ORIGIN_CONFIG_KEY) : undefined;
|
|
303
|
+
const configuredCsrfMiddleware = createCsrfMiddleware({ targetOrigin, ...http?.csrf });
|
|
304
|
+
return {
|
|
305
|
+
emailVerificationRequired,
|
|
306
|
+
viewsEnabled,
|
|
307
|
+
publicReadsEnabled,
|
|
308
|
+
etagEnabled,
|
|
309
|
+
responsePolicy,
|
|
310
|
+
configuredCsrfMiddleware
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
function createHttpResponseMiddleware(dependencies, settings, errorFormat) {
|
|
314
|
+
return [
|
|
315
|
+
createCorsMiddleware(settings.responsePolicy.cors),
|
|
316
|
+
createSecurityHeadersMiddleware(settings.responsePolicy.securityHeaders),
|
|
317
|
+
createBodySizeLimitMiddleware(settings.responsePolicy.maxBodyBytes),
|
|
318
|
+
...dependencies.container.has(CORE_TRACING_RUNTIME_TOKEN) ? [createTracingMiddleware(dependencies.container.resolve(CORE_TRACING_RUNTIME_TOKEN))] : [],
|
|
319
|
+
createMetricsMiddleware(),
|
|
320
|
+
createRequestLoggingMiddleware(settings.responsePolicy.trustForwardedFor),
|
|
321
|
+
requestIdMiddleware,
|
|
322
|
+
errorFormat === "json" ? createJsonErrorMiddleware() : createWebErrorMiddleware({
|
|
323
|
+
enabled: settings.viewsEnabled,
|
|
324
|
+
production: dependencies.container.has(HTTP_PERSISTENCE_OPTIONS) ? dependencies.container.resolve(HTTP_PERSISTENCE_OPTIONS).production ?? true : true,
|
|
325
|
+
render: dependencies.container.has(CORE_WEB_ERROR_VIEW_TOKEN) ? dependencies.container.resolve(CORE_WEB_ERROR_VIEW_TOKEN) : undefined
|
|
326
|
+
})
|
|
327
|
+
];
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// ../../src/bootstrap/moduleRouteMiddleware.ts
|
|
331
|
+
function enterModuleRoutes(routes, enter) {
|
|
332
|
+
const wrapped = {};
|
|
333
|
+
for (const [path, value] of Object.entries(routes)) {
|
|
334
|
+
if (value instanceof Response) {
|
|
335
|
+
const methods = {};
|
|
336
|
+
for (const method of ["GET", "HEAD", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"]) {
|
|
337
|
+
methods[method] = enter(() => value.clone());
|
|
338
|
+
}
|
|
339
|
+
wrapped[path] = methods;
|
|
340
|
+
continue;
|
|
341
|
+
}
|
|
342
|
+
if (typeof value === "function") {
|
|
343
|
+
wrapped[path] = enter(value);
|
|
344
|
+
continue;
|
|
345
|
+
}
|
|
346
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
347
|
+
const entries = Object.entries(value);
|
|
348
|
+
if (entries.some(([, handler]) => typeof handler === "function" || handler instanceof Response)) {
|
|
349
|
+
wrapped[path] = Object.fromEntries(entries.map(([method, handler]) => {
|
|
350
|
+
const callback = handler instanceof Response ? () => handler.clone() : handler;
|
|
351
|
+
return [
|
|
352
|
+
method,
|
|
353
|
+
typeof callback === "function" ? enter(callback) : callback
|
|
354
|
+
];
|
|
355
|
+
}));
|
|
356
|
+
continue;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
wrapped[path] = value;
|
|
360
|
+
}
|
|
361
|
+
return wrapped;
|
|
362
|
+
}
|
|
363
|
+
|
|
306
364
|
// ../../src/bootstrap/httpKernel.ts
|
|
307
365
|
class HttpKernel {
|
|
308
366
|
dependencies;
|
|
@@ -321,38 +379,16 @@ class HttpKernel {
|
|
|
321
379
|
this.dependencies = dependencies;
|
|
322
380
|
const http = dependencies.container.has(HTTP_PERSISTENCE_OPTIONS) ? dependencies.container.resolve(HTTP_PERSISTENCE_OPTIONS) : undefined;
|
|
323
381
|
this.httpOptions = http;
|
|
324
|
-
const
|
|
325
|
-
|
|
326
|
-
this.
|
|
327
|
-
this.
|
|
328
|
-
this.
|
|
329
|
-
this.
|
|
330
|
-
|
|
331
|
-
if (policy?.cors)
|
|
332
|
-
resolveCorsConfig(policy.cors);
|
|
333
|
-
this.responsePolicy = Object.freeze({
|
|
334
|
-
cors: policy?.cors ? {
|
|
335
|
-
allowedOrigins: [...policy.cors.allowedOrigins ?? []],
|
|
336
|
-
additionalAllowedHeaders: [...policy.cors.additionalAllowedHeaders ?? []]
|
|
337
|
-
} : undefined,
|
|
338
|
-
securityHeaders: policy?.securityHeaders ?? {
|
|
339
|
-
production: http?.production ?? true,
|
|
340
|
-
frontendMode: this.viewsEnabled ? "server-htmx" : "api"
|
|
341
|
-
},
|
|
342
|
-
maxBodyBytes: policy?.maxBodyBytes ?? 1048576,
|
|
343
|
-
rateLimitPerMinute: policy?.rateLimitPerMinute ?? 120,
|
|
344
|
-
namespace: policy?.namespace ?? "strata",
|
|
345
|
-
trustForwardedFor: policy?.trustForwardedFor ?? false,
|
|
346
|
-
loginRateLimit: Object.freeze({ ...policy?.loginRateLimit ?? resolveLoginRateLimit() }),
|
|
347
|
-
registerRateLimit: Object.freeze({
|
|
348
|
-
...policy?.registerRateLimit ?? resolveRegisterRateLimit()
|
|
349
|
-
})
|
|
350
|
-
});
|
|
351
|
-
const targetOrigin = dependencies.container.has(CORE_CONFIG_TOKEN) ? dependencies.container.resolve(CORE_CONFIG_TOKEN).get(CSRF_TARGET_ORIGIN_CONFIG_KEY) : undefined;
|
|
352
|
-
this.configuredCsrfMiddleware = createCsrfMiddleware({ targetOrigin, ...http?.csrf });
|
|
382
|
+
const settings = resolveHttpResponseSettings(dependencies, http);
|
|
383
|
+
this.emailVerificationRequired = settings.emailVerificationRequired;
|
|
384
|
+
this.viewsEnabled = settings.viewsEnabled;
|
|
385
|
+
this.publicReadsEnabled = settings.publicReadsEnabled;
|
|
386
|
+
this.etagEnabled = settings.etagEnabled;
|
|
387
|
+
this.responsePolicy = settings.responsePolicy;
|
|
388
|
+
this.configuredCsrfMiddleware = settings.configuredCsrfMiddleware;
|
|
353
389
|
this.responses = Object.freeze({
|
|
354
|
-
json: Object.freeze(
|
|
355
|
-
web: Object.freeze(
|
|
390
|
+
json: Object.freeze(createHttpResponseMiddleware(dependencies, settings, "json")),
|
|
391
|
+
web: Object.freeze(createHttpResponseMiddleware(dependencies, settings, "web"))
|
|
356
392
|
});
|
|
357
393
|
this.persistence = dependencies.container.has(HTTP_PERSISTENCE_OPTIONS) ? createHttpPersistence(dependencies.invoke, dependencies.container.resolve(HTTP_PERSISTENCE_OPTIONS)) : undefined;
|
|
358
394
|
if (dependencies.container.has(CORE_HTTP_CLEANUP_TOKEN)) {
|
|
@@ -447,22 +483,6 @@ class HttpKernel {
|
|
|
447
483
|
throw new TypeError("SCIM and identity operation declarations cannot be combined.");
|
|
448
484
|
return this.composed(handler, "json", undefined, Object.freeze([...before]));
|
|
449
485
|
}
|
|
450
|
-
responseMiddleware(errorFormat) {
|
|
451
|
-
return [
|
|
452
|
-
createCorsMiddleware(this.responsePolicy.cors),
|
|
453
|
-
createSecurityHeadersMiddleware(this.responsePolicy.securityHeaders),
|
|
454
|
-
createBodySizeLimitMiddleware(this.responsePolicy.maxBodyBytes),
|
|
455
|
-
...this.dependencies.container.has(CORE_TRACING_RUNTIME_TOKEN) ? [createTracingMiddleware(this.dependencies.container.resolve(CORE_TRACING_RUNTIME_TOKEN))] : [],
|
|
456
|
-
createMetricsMiddleware(),
|
|
457
|
-
createRequestLoggingMiddleware(this.responsePolicy.trustForwardedFor),
|
|
458
|
-
requestIdMiddleware,
|
|
459
|
-
errorFormat === "json" ? createJsonErrorMiddleware() : createWebErrorMiddleware({
|
|
460
|
-
enabled: this.viewsEnabled,
|
|
461
|
-
production: this.dependencies.container.has(HTTP_PERSISTENCE_OPTIONS) ? this.dependencies.container.resolve(HTTP_PERSISTENCE_OPTIONS).production ?? true : true,
|
|
462
|
-
render: this.dependencies.container.has(CORE_WEB_ERROR_VIEW_TOKEN) ? this.dependencies.container.resolve(CORE_WEB_ERROR_VIEW_TOKEN) : undefined
|
|
463
|
-
})
|
|
464
|
-
];
|
|
465
|
-
}
|
|
466
486
|
wrapPublicDocument(handler) {
|
|
467
487
|
assertHttpHandler(handler);
|
|
468
488
|
return ownedPublicHttpRoute(handler, (request, work) => Promise.resolve(withMiddleware(...this.responses.web)(work)(request)));
|
|
@@ -50,6 +50,7 @@ import {
|
|
|
50
50
|
CORE_EVENT_BUS_TOKEN,
|
|
51
51
|
CORE_HTTP_CLEANUP_TOKEN,
|
|
52
52
|
CORE_POLICY_GATE_TOKEN,
|
|
53
|
+
CORE_POLICY_REGISTRY_TOKEN,
|
|
53
54
|
CORE_PUBLIC_TENANCY_TOKEN,
|
|
54
55
|
CORE_QUEUE_TOKEN,
|
|
55
56
|
CORE_TENANT_RESOLVER_TOKEN,
|
|
@@ -117,7 +118,7 @@ var appEnvSchema = defineEnvSchema({
|
|
|
117
118
|
},
|
|
118
119
|
JWT_TTL_SECONDS: {
|
|
119
120
|
integer: true,
|
|
120
|
-
minimum:
|
|
121
|
+
minimum: 1,
|
|
121
122
|
default: "3600"
|
|
122
123
|
},
|
|
123
124
|
APP_ENV: {
|