@getstrata/bootstrap 0.2.65 → 0.2.68
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 +17 -0
- package/README.md +5 -5
- package/dist/bootstrap/createWebRoutes.d.ts +7 -3
- package/dist/bootstrap/dogfoodApp.d.ts +7 -0
- package/dist/bootstrap/public-api.d.ts +1 -0
- package/dist/bootstrap/rateLimit.d.ts +10 -0
- package/dist/bootstrap/web/session.d.ts +18 -3
- package/dist/entries/buildModuleRoutes.js +35 -30
- package/dist/entries/buildWebModuleRoutes.js +35 -30
- package/dist/entries/cache/modelCacheTags.js +7 -2
- package/dist/entries/context.js +13 -163
- package/dist/entries/createRoutes.js +60 -880
- package/dist/entries/createWebRoutes.js +39 -36
- package/dist/entries/dependencies.js +13 -163
- package/dist/entries/discoverModules.js +7 -2
- package/dist/entries/httpKernel.js +28 -28
- package/dist/entries/listeners/invalidateCacheOnModelWrite.js +7 -2
- package/dist/entries/providers/view.js +5 -160
- package/dist/entries/providers.js +13 -163
- package/dist/entries/secretsGuard.js +25 -40
- package/dist/entries/web/routing.js +28 -28
- package/dist/entries/web/session.js +24 -10
- package/dist/index.js +93 -246
- package/package.json +2 -2
- package/dist/bootstrap/scimRoutes.d.ts +0 -24
|
@@ -47,7 +47,33 @@ import { isPublicReadsEnabled } from "@getstrata/core/security/publicReads";
|
|
|
47
47
|
import { createTenantMiddleware } from "@getstrata/core/tenant/tenantMiddleware";
|
|
48
48
|
import { createTracingMiddleware } from "@getstrata/core/tracing/tracingMiddleware";
|
|
49
49
|
|
|
50
|
-
// ../../src/config
|
|
50
|
+
// ../../src/bootstrap/config.ts
|
|
51
|
+
import {
|
|
52
|
+
CORE_ABILITY_CHECKER_TOKEN,
|
|
53
|
+
CORE_AUTH_TOKEN,
|
|
54
|
+
CORE_AUTH_USER_DIRECTORY_TOKEN,
|
|
55
|
+
CORE_CACHE_TOKEN,
|
|
56
|
+
CORE_CONFIG_TOKEN,
|
|
57
|
+
CORE_EVENT_BUS_TOKEN,
|
|
58
|
+
CORE_POLICY_GATE_TOKEN,
|
|
59
|
+
CORE_QUEUE_TOKEN,
|
|
60
|
+
CORE_TOKEN_SERVICE_TOKEN
|
|
61
|
+
} from "@getstrata/core/contracts/serviceTokens";
|
|
62
|
+
var APP_PORT_CONFIG_KEY = "app.port";
|
|
63
|
+
var CACHE_TTL_MS_CONFIG_KEY = "cache.ttlMs";
|
|
64
|
+
var CACHE_MAX_ENTRIES_CONFIG_KEY = "cache.maxEntries";
|
|
65
|
+
var CACHE_DRIVER_CONFIG_KEY = "cache.driver";
|
|
66
|
+
var REDIS_URL_CONFIG_KEY = "cache.redisUrl";
|
|
67
|
+
var DATABASE_URL_CONFIG_KEY = "database.url";
|
|
68
|
+
var AUTH_DEV_HEADERS_CONFIG_KEY = "auth.allowDevHeaders";
|
|
69
|
+
var DEFAULT_APP_PORT = 3000;
|
|
70
|
+
var DEFAULT_CACHE_TTL_MS = 3600000;
|
|
71
|
+
var DEFAULT_CACHE_MAX_ENTRIES = 100;
|
|
72
|
+
var DEFAULT_CACHE_DRIVER = "array";
|
|
73
|
+
var DEFAULT_API_TOKEN = "";
|
|
74
|
+
var DEFAULT_QUEUE_DRIVER = "sync";
|
|
75
|
+
|
|
76
|
+
// ../../src/bootstrap/rateLimit.ts
|
|
51
77
|
var LOCAL_LOGIN_RATE_LIMIT = {
|
|
52
78
|
maxAttempts: 100,
|
|
53
79
|
decaySeconds: 60
|
|
@@ -93,32 +119,6 @@ function resolveRegisterRateLimit() {
|
|
|
93
119
|
};
|
|
94
120
|
}
|
|
95
121
|
|
|
96
|
-
// ../../src/bootstrap/config.ts
|
|
97
|
-
import {
|
|
98
|
-
CORE_ABILITY_CHECKER_TOKEN,
|
|
99
|
-
CORE_AUTH_TOKEN,
|
|
100
|
-
CORE_AUTH_USER_DIRECTORY_TOKEN,
|
|
101
|
-
CORE_CACHE_TOKEN,
|
|
102
|
-
CORE_CONFIG_TOKEN,
|
|
103
|
-
CORE_EVENT_BUS_TOKEN,
|
|
104
|
-
CORE_POLICY_GATE_TOKEN,
|
|
105
|
-
CORE_QUEUE_TOKEN,
|
|
106
|
-
CORE_TOKEN_SERVICE_TOKEN
|
|
107
|
-
} from "@getstrata/core/contracts/serviceTokens";
|
|
108
|
-
var APP_PORT_CONFIG_KEY = "app.port";
|
|
109
|
-
var CACHE_TTL_MS_CONFIG_KEY = "cache.ttlMs";
|
|
110
|
-
var CACHE_MAX_ENTRIES_CONFIG_KEY = "cache.maxEntries";
|
|
111
|
-
var CACHE_DRIVER_CONFIG_KEY = "cache.driver";
|
|
112
|
-
var REDIS_URL_CONFIG_KEY = "cache.redisUrl";
|
|
113
|
-
var DATABASE_URL_CONFIG_KEY = "database.url";
|
|
114
|
-
var AUTH_DEV_HEADERS_CONFIG_KEY = "auth.allowDevHeaders";
|
|
115
|
-
var DEFAULT_APP_PORT = 3000;
|
|
116
|
-
var DEFAULT_CACHE_TTL_MS = 3600000;
|
|
117
|
-
var DEFAULT_CACHE_MAX_ENTRIES = 100;
|
|
118
|
-
var DEFAULT_CACHE_DRIVER = "array";
|
|
119
|
-
var DEFAULT_API_TOKEN = "";
|
|
120
|
-
var DEFAULT_QUEUE_DRIVER = "sync";
|
|
121
|
-
|
|
122
122
|
// ../../src/bootstrap/httpKernel.ts
|
|
123
123
|
class HttpKernel {
|
|
124
124
|
dependencies;
|
|
@@ -189,7 +189,7 @@ class HttpKernel {
|
|
|
189
189
|
wrapWeb(handler) {
|
|
190
190
|
return withErrorHandling(this.wrap("web", handler));
|
|
191
191
|
}
|
|
192
|
-
wrapWebGuest(handler, home = "/
|
|
192
|
+
wrapWebGuest(handler, home = "/") {
|
|
193
193
|
const auth = this.dependencies.container.resolve(CORE_AUTH_TOKEN);
|
|
194
194
|
return this.wrapWeb(async (request) => {
|
|
195
195
|
const user = await auth.resolve(request);
|
|
@@ -349,7 +349,12 @@ function readDiscoverModulesState() {
|
|
|
349
349
|
return state;
|
|
350
350
|
}
|
|
351
351
|
function configureModulesDirectory(modulesDir) {
|
|
352
|
-
readDiscoverModulesState()
|
|
352
|
+
const state = readDiscoverModulesState();
|
|
353
|
+
if (state.configuredModulesDir !== modulesDir) {
|
|
354
|
+
state.appModules.length = 0;
|
|
355
|
+
state.modulesReady = undefined;
|
|
356
|
+
}
|
|
357
|
+
state.configuredModulesDir = modulesDir;
|
|
353
358
|
}
|
|
354
359
|
function resolveModulesDirectory(options) {
|
|
355
360
|
const state = readDiscoverModulesState();
|
|
@@ -359,7 +364,7 @@ function resolveModulesDirectory(options) {
|
|
|
359
364
|
if (state.configuredModulesDir) {
|
|
360
365
|
return state.configuredModulesDir;
|
|
361
366
|
}
|
|
362
|
-
throw new Error("configureModulesDirectory() must be called before discovering modules.
|
|
367
|
+
throw new Error("configureModulesDirectory() must be called before discovering modules. The app preload (or starter) should call it.");
|
|
363
368
|
}
|
|
364
369
|
async function loadDiscoveredModules(options) {
|
|
365
370
|
const modulesDirectory = resolveModulesDirectory(options);
|
|
@@ -506,12 +511,10 @@ function buildWebModuleRoutes(dependencies, options = {}) {
|
|
|
506
511
|
function registerRoute(method, path, middleware) {
|
|
507
512
|
routeRegistry.register({ method, path, middleware });
|
|
508
513
|
}
|
|
509
|
-
function createWebRoutes(dependencies) {
|
|
514
|
+
function createWebRoutes(dependencies, options = {}) {
|
|
510
515
|
const wrappedRoutes = buildWebModuleRoutes(dependencies, {
|
|
511
516
|
clearRegistry: false,
|
|
512
|
-
|
|
513
|
-
"/": () => Response.redirect("/organizations", 302)
|
|
514
|
-
}
|
|
517
|
+
modules: options.modules
|
|
515
518
|
});
|
|
516
519
|
registerRoute("GET", "/", ["global", "web"]);
|
|
517
520
|
wrappedRoutes["/assets/*"] = async (request) => {
|
|
@@ -527,12 +530,12 @@ function createWebRoutes(dependencies) {
|
|
|
527
530
|
registerRoute("GET", "/assets/*", ["global", "web"]);
|
|
528
531
|
return wrappedRoutes;
|
|
529
532
|
}
|
|
530
|
-
function mergeWebRoutes(dependencies, routes) {
|
|
533
|
+
function mergeWebRoutes(dependencies, routes, options = {}) {
|
|
531
534
|
if (!isViewsEnabled2()) {
|
|
532
535
|
return routes;
|
|
533
536
|
}
|
|
534
537
|
return {
|
|
535
|
-
...createWebRoutes(dependencies),
|
|
538
|
+
...createWebRoutes(dependencies, options),
|
|
536
539
|
...routes
|
|
537
540
|
};
|
|
538
541
|
}
|
|
@@ -40,7 +40,12 @@ function readDiscoverModulesState() {
|
|
|
40
40
|
return state;
|
|
41
41
|
}
|
|
42
42
|
function configureModulesDirectory(modulesDir) {
|
|
43
|
-
readDiscoverModulesState()
|
|
43
|
+
const state = readDiscoverModulesState();
|
|
44
|
+
if (state.configuredModulesDir !== modulesDir) {
|
|
45
|
+
state.appModules.length = 0;
|
|
46
|
+
state.modulesReady = undefined;
|
|
47
|
+
}
|
|
48
|
+
state.configuredModulesDir = modulesDir;
|
|
44
49
|
}
|
|
45
50
|
function resolveModulesDirectory(options) {
|
|
46
51
|
const state = readDiscoverModulesState();
|
|
@@ -50,7 +55,7 @@ function resolveModulesDirectory(options) {
|
|
|
50
55
|
if (state.configuredModulesDir) {
|
|
51
56
|
return state.configuredModulesDir;
|
|
52
57
|
}
|
|
53
|
-
throw new Error("configureModulesDirectory() must be called before discovering modules.
|
|
58
|
+
throw new Error("configureModulesDirectory() must be called before discovering modules. The app preload (or starter) should call it.");
|
|
54
59
|
}
|
|
55
60
|
async function loadDiscoveredModules(options) {
|
|
56
61
|
const modulesDirectory = resolveModulesDirectory(options);
|
|
@@ -170,7 +175,7 @@ import { validateEnv } from "@getstrata/core/config/envSchema";
|
|
|
170
175
|
|
|
171
176
|
// ../../src/config/app.ts
|
|
172
177
|
var appConfig = {
|
|
173
|
-
name: process.env.APP_NAME?.trim() || "
|
|
178
|
+
name: process.env.APP_NAME?.trim() || "Strata",
|
|
174
179
|
env: process.env.APP_ENV ?? "local",
|
|
175
180
|
debug: (process.env.APP_DEBUG ?? "true") !== "false",
|
|
176
181
|
url: process.env.APP_URL ?? "http://localhost:3000",
|
|
@@ -480,7 +485,6 @@ var storageProvider = {
|
|
|
480
485
|
var storage_default = storageProvider;
|
|
481
486
|
|
|
482
487
|
// ../../src/bootstrap/providers/view.ts
|
|
483
|
-
import { resolveMembershipLookup } from "@getstrata/core/auth/membershipContext";
|
|
484
488
|
import { currentRequestMeta } from "@getstrata/core/http/requestMetaContext";
|
|
485
489
|
import { appDisplayName } from "@getstrata/core/runtime/appKeyPrefix";
|
|
486
490
|
import { isViewsEnabled } from "@getstrata/core/runtime/frontendMode";
|
|
@@ -492,148 +496,6 @@ import {
|
|
|
492
496
|
errorTemplateName,
|
|
493
497
|
resolveWebLayoutData
|
|
494
498
|
} from "@getstrata/core/view";
|
|
495
|
-
|
|
496
|
-
// ../../src/modules/organization/repository.ts
|
|
497
|
-
import { BaseRepository } from "@getstrata/core/database/baseRepository";
|
|
498
|
-
import { NotFoundError } from "@getstrata/core/errors/http";
|
|
499
|
-
import { currentTenantId } from "@getstrata/core/tenant/tenantContext";
|
|
500
|
-
|
|
501
|
-
// ../../src/modules/organization/table.ts
|
|
502
|
-
import { defineTable } from "@getstrata/core/database/table";
|
|
503
|
-
|
|
504
|
-
// ../../src/domain/workhub.ts
|
|
505
|
-
var ORGANIZATION_TABLE = "organization";
|
|
506
|
-
|
|
507
|
-
// ../../src/modules/organization/table.ts
|
|
508
|
-
var organizationTable = defineTable({
|
|
509
|
-
name: ORGANIZATION_TABLE,
|
|
510
|
-
primaryKey: "id",
|
|
511
|
-
columns: ["id", "tenant_id", "name", "slug", "created_at", "updated_at", "deleted_at"],
|
|
512
|
-
softDeletes: true,
|
|
513
|
-
defaultOrderBy: { column: "id", direction: "ASC" }
|
|
514
|
-
});
|
|
515
|
-
|
|
516
|
-
// ../../src/modules/organization/repository.ts
|
|
517
|
-
class OrganizationRepository extends BaseRepository {
|
|
518
|
-
constructor() {
|
|
519
|
-
super(organizationTable);
|
|
520
|
-
}
|
|
521
|
-
async findBySlug(slug) {
|
|
522
|
-
return await this.firstOrNull({ slug });
|
|
523
|
-
}
|
|
524
|
-
async listForTenant(options) {
|
|
525
|
-
return await this.findAll({
|
|
526
|
-
limit: options.limit,
|
|
527
|
-
offset: options.offset,
|
|
528
|
-
where: { tenant_id: options.tenantId ?? currentTenantId() }
|
|
529
|
-
});
|
|
530
|
-
}
|
|
531
|
-
async countForTenant(tenantId = currentTenantId()) {
|
|
532
|
-
return await this.countWhere({ tenant_id: tenantId });
|
|
533
|
-
}
|
|
534
|
-
async findForTenantOrThrow(id, tenantId = currentTenantId()) {
|
|
535
|
-
const organization = await this.findById(id);
|
|
536
|
-
if (!organization || organization.tenant_id !== tenantId) {
|
|
537
|
-
throw new NotFoundError(`SCIM group ${id} not found.`);
|
|
538
|
-
}
|
|
539
|
-
return organization;
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
var repository_default = OrganizationRepository;
|
|
543
|
-
|
|
544
|
-
// ../../src/modules/user/repository.ts
|
|
545
|
-
import {
|
|
546
|
-
emailLookupForQuery,
|
|
547
|
-
protectEmail,
|
|
548
|
-
revealEmail
|
|
549
|
-
} from "@getstrata/core/crypto/fieldEncryption";
|
|
550
|
-
import { revealMfaSecret } from "@getstrata/core/crypto/mfaSecret";
|
|
551
|
-
import { BaseRepository as BaseRepository2 } from "@getstrata/core/database/baseRepository";
|
|
552
|
-
import { currentTenantId as currentTenantId2 } from "@getstrata/core/tenant/tenantContext";
|
|
553
|
-
|
|
554
|
-
// ../../src/modules/user/table.ts
|
|
555
|
-
import { defineTable as defineTable2 } from "@getstrata/core/database/table";
|
|
556
|
-
var userTable = defineTable2({
|
|
557
|
-
name: "users",
|
|
558
|
-
primaryKey: "id",
|
|
559
|
-
columns: [
|
|
560
|
-
"id",
|
|
561
|
-
"name",
|
|
562
|
-
"email",
|
|
563
|
-
"email_lookup",
|
|
564
|
-
"role",
|
|
565
|
-
"tenant_id",
|
|
566
|
-
"password_hash",
|
|
567
|
-
"email_verified_at",
|
|
568
|
-
"mfa_secret",
|
|
569
|
-
"mfa_enabled",
|
|
570
|
-
"mfa_recovery_codes",
|
|
571
|
-
"profile_photo_path",
|
|
572
|
-
"session_valid_after",
|
|
573
|
-
"current_organization_id",
|
|
574
|
-
"created_at",
|
|
575
|
-
"updated_at"
|
|
576
|
-
],
|
|
577
|
-
defaultOrderBy: { column: "id", direction: "ASC" }
|
|
578
|
-
});
|
|
579
|
-
|
|
580
|
-
// ../../src/modules/user/repository.ts
|
|
581
|
-
class UserRepository extends BaseRepository2 {
|
|
582
|
-
constructor() {
|
|
583
|
-
super(userTable);
|
|
584
|
-
}
|
|
585
|
-
decode(record) {
|
|
586
|
-
return {
|
|
587
|
-
...record,
|
|
588
|
-
email: revealEmail(record.email),
|
|
589
|
-
mfa_secret: revealMfaSecret(record.mfa_secret)
|
|
590
|
-
};
|
|
591
|
-
}
|
|
592
|
-
async findById(id) {
|
|
593
|
-
const record = await super.findById(id);
|
|
594
|
-
return record ? this.decode(record) : null;
|
|
595
|
-
}
|
|
596
|
-
async findAll(options = {}) {
|
|
597
|
-
const records = await super.findAll(options);
|
|
598
|
-
return records.map((record) => this.decode(record));
|
|
599
|
-
}
|
|
600
|
-
async create(values) {
|
|
601
|
-
const email = values.email;
|
|
602
|
-
if (!email) {
|
|
603
|
-
throw new Error("Email is required.");
|
|
604
|
-
}
|
|
605
|
-
const protectedEmail = protectEmail(email);
|
|
606
|
-
const record = await super.create({
|
|
607
|
-
...values,
|
|
608
|
-
tenant_id: values.tenant_id ?? currentTenantId2(),
|
|
609
|
-
email: protectedEmail.storedEmail,
|
|
610
|
-
email_lookup: protectedEmail.emailLookup,
|
|
611
|
-
password_hash: values.password_hash ?? ""
|
|
612
|
-
});
|
|
613
|
-
return this.decode(record);
|
|
614
|
-
}
|
|
615
|
-
async updateByIdOrThrow(id, values, errorFactory) {
|
|
616
|
-
const changes = { ...values };
|
|
617
|
-
if (values.email !== undefined) {
|
|
618
|
-
const protectedEmail = protectEmail(values.email);
|
|
619
|
-
changes.email = protectedEmail.storedEmail;
|
|
620
|
-
changes.email_lookup = protectedEmail.emailLookup;
|
|
621
|
-
}
|
|
622
|
-
const record = await super.updateByIdOrThrow(id, changes, errorFactory);
|
|
623
|
-
return this.decode(record);
|
|
624
|
-
}
|
|
625
|
-
async findByEmail(email) {
|
|
626
|
-
const records = await this.findWhere({ email_lookup: emailLookupForQuery(email) }, { limit: 1 });
|
|
627
|
-
const record = records[0];
|
|
628
|
-
return record ? this.decode(record) : null;
|
|
629
|
-
}
|
|
630
|
-
async countForTenant(tenantId = currentTenantId2()) {
|
|
631
|
-
return await this.countWhere({ tenant_id: tenantId });
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
var repository_default2 = UserRepository;
|
|
635
|
-
|
|
636
|
-
// ../../src/bootstrap/providers/view.ts
|
|
637
499
|
var CORE_VIEW_TOKEN = "core.view";
|
|
638
500
|
var VIEW_DIRECTORY_CONFIG_KEY = "view.directory";
|
|
639
501
|
var viewProvider = {
|
|
@@ -647,23 +509,11 @@ var viewProvider = {
|
|
|
647
509
|
const engine = new EtaViewEngine(viewsDirectory, (request) => resolveWebLayoutData(container, request ?? currentRequestMeta().request));
|
|
648
510
|
container.set(CORE_VIEW_TOKEN, engine);
|
|
649
511
|
configureWebLayoutData({
|
|
650
|
-
extra: async (
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
try {
|
|
656
|
-
const record = await new repository_default2().findByIdOrThrow(user.id);
|
|
657
|
-
const memberships = await resolveMembershipLookup().listForUser(record.id);
|
|
658
|
-
const organizationsRepo = new repository_default;
|
|
659
|
-
const organizations = (await Promise.all(memberships.map((membership) => organizationsRepo.findById(membership.organization_id)))).filter((organization) => Boolean(organization && !organization.deleted_at));
|
|
660
|
-
const currentId = record.current_organization_id ?? null;
|
|
661
|
-
const currentOrganization = organizations.find((organization) => organization.id === currentId) ?? organizations[0] ?? null;
|
|
662
|
-
return { appName, currentOrganization, organizations };
|
|
663
|
-
} catch {
|
|
664
|
-
return { appName, currentOrganization: null, organizations: [] };
|
|
665
|
-
}
|
|
666
|
-
}
|
|
512
|
+
extra: async () => ({
|
|
513
|
+
appName: appDisplayName(),
|
|
514
|
+
currentOrganization: null,
|
|
515
|
+
organizations: []
|
|
516
|
+
})
|
|
667
517
|
});
|
|
668
518
|
configureWebErrorView({
|
|
669
519
|
render: async (input) => engine.render(errorTemplateName(input.status), {
|
|
@@ -16,7 +16,12 @@ function readDiscoverModulesState() {
|
|
|
16
16
|
return state;
|
|
17
17
|
}
|
|
18
18
|
function configureModulesDirectory(modulesDir) {
|
|
19
|
-
readDiscoverModulesState()
|
|
19
|
+
const state = readDiscoverModulesState();
|
|
20
|
+
if (state.configuredModulesDir !== modulesDir) {
|
|
21
|
+
state.appModules.length = 0;
|
|
22
|
+
state.modulesReady = undefined;
|
|
23
|
+
}
|
|
24
|
+
state.configuredModulesDir = modulesDir;
|
|
20
25
|
}
|
|
21
26
|
function resolveModulesDirectory(options) {
|
|
22
27
|
const state = readDiscoverModulesState();
|
|
@@ -26,7 +31,7 @@ function resolveModulesDirectory(options) {
|
|
|
26
31
|
if (state.configuredModulesDir) {
|
|
27
32
|
return state.configuredModulesDir;
|
|
28
33
|
}
|
|
29
|
-
throw new Error("configureModulesDirectory() must be called before discovering modules.
|
|
34
|
+
throw new Error("configureModulesDirectory() must be called before discovering modules. The app preload (or starter) should call it.");
|
|
30
35
|
}
|
|
31
36
|
async function loadDiscoveredModules(options) {
|
|
32
37
|
const modulesDirectory = resolveModulesDirectory(options);
|
|
@@ -35,7 +35,33 @@ import { isPublicReadsEnabled } from "@getstrata/core/security/publicReads";
|
|
|
35
35
|
import { createTenantMiddleware } from "@getstrata/core/tenant/tenantMiddleware";
|
|
36
36
|
import { createTracingMiddleware } from "@getstrata/core/tracing/tracingMiddleware";
|
|
37
37
|
|
|
38
|
-
// ../../src/config
|
|
38
|
+
// ../../src/bootstrap/config.ts
|
|
39
|
+
import {
|
|
40
|
+
CORE_ABILITY_CHECKER_TOKEN,
|
|
41
|
+
CORE_AUTH_TOKEN,
|
|
42
|
+
CORE_AUTH_USER_DIRECTORY_TOKEN,
|
|
43
|
+
CORE_CACHE_TOKEN,
|
|
44
|
+
CORE_CONFIG_TOKEN,
|
|
45
|
+
CORE_EVENT_BUS_TOKEN,
|
|
46
|
+
CORE_POLICY_GATE_TOKEN,
|
|
47
|
+
CORE_QUEUE_TOKEN,
|
|
48
|
+
CORE_TOKEN_SERVICE_TOKEN
|
|
49
|
+
} from "@getstrata/core/contracts/serviceTokens";
|
|
50
|
+
var APP_PORT_CONFIG_KEY = "app.port";
|
|
51
|
+
var CACHE_TTL_MS_CONFIG_KEY = "cache.ttlMs";
|
|
52
|
+
var CACHE_MAX_ENTRIES_CONFIG_KEY = "cache.maxEntries";
|
|
53
|
+
var CACHE_DRIVER_CONFIG_KEY = "cache.driver";
|
|
54
|
+
var REDIS_URL_CONFIG_KEY = "cache.redisUrl";
|
|
55
|
+
var DATABASE_URL_CONFIG_KEY = "database.url";
|
|
56
|
+
var AUTH_DEV_HEADERS_CONFIG_KEY = "auth.allowDevHeaders";
|
|
57
|
+
var DEFAULT_APP_PORT = 3000;
|
|
58
|
+
var DEFAULT_CACHE_TTL_MS = 3600000;
|
|
59
|
+
var DEFAULT_CACHE_MAX_ENTRIES = 100;
|
|
60
|
+
var DEFAULT_CACHE_DRIVER = "array";
|
|
61
|
+
var DEFAULT_API_TOKEN = "";
|
|
62
|
+
var DEFAULT_QUEUE_DRIVER = "sync";
|
|
63
|
+
|
|
64
|
+
// ../../src/bootstrap/rateLimit.ts
|
|
39
65
|
var LOCAL_LOGIN_RATE_LIMIT = {
|
|
40
66
|
maxAttempts: 100,
|
|
41
67
|
decaySeconds: 60
|
|
@@ -81,32 +107,6 @@ function resolveRegisterRateLimit() {
|
|
|
81
107
|
};
|
|
82
108
|
}
|
|
83
109
|
|
|
84
|
-
// ../../src/bootstrap/config.ts
|
|
85
|
-
import {
|
|
86
|
-
CORE_ABILITY_CHECKER_TOKEN,
|
|
87
|
-
CORE_AUTH_TOKEN,
|
|
88
|
-
CORE_AUTH_USER_DIRECTORY_TOKEN,
|
|
89
|
-
CORE_CACHE_TOKEN,
|
|
90
|
-
CORE_CONFIG_TOKEN,
|
|
91
|
-
CORE_EVENT_BUS_TOKEN,
|
|
92
|
-
CORE_POLICY_GATE_TOKEN,
|
|
93
|
-
CORE_QUEUE_TOKEN,
|
|
94
|
-
CORE_TOKEN_SERVICE_TOKEN
|
|
95
|
-
} from "@getstrata/core/contracts/serviceTokens";
|
|
96
|
-
var APP_PORT_CONFIG_KEY = "app.port";
|
|
97
|
-
var CACHE_TTL_MS_CONFIG_KEY = "cache.ttlMs";
|
|
98
|
-
var CACHE_MAX_ENTRIES_CONFIG_KEY = "cache.maxEntries";
|
|
99
|
-
var CACHE_DRIVER_CONFIG_KEY = "cache.driver";
|
|
100
|
-
var REDIS_URL_CONFIG_KEY = "cache.redisUrl";
|
|
101
|
-
var DATABASE_URL_CONFIG_KEY = "database.url";
|
|
102
|
-
var AUTH_DEV_HEADERS_CONFIG_KEY = "auth.allowDevHeaders";
|
|
103
|
-
var DEFAULT_APP_PORT = 3000;
|
|
104
|
-
var DEFAULT_CACHE_TTL_MS = 3600000;
|
|
105
|
-
var DEFAULT_CACHE_MAX_ENTRIES = 100;
|
|
106
|
-
var DEFAULT_CACHE_DRIVER = "array";
|
|
107
|
-
var DEFAULT_API_TOKEN = "";
|
|
108
|
-
var DEFAULT_QUEUE_DRIVER = "sync";
|
|
109
|
-
|
|
110
110
|
// ../../src/bootstrap/httpKernel.ts
|
|
111
111
|
class HttpKernel {
|
|
112
112
|
dependencies;
|
|
@@ -177,7 +177,7 @@ class HttpKernel {
|
|
|
177
177
|
wrapWeb(handler) {
|
|
178
178
|
return withErrorHandling(this.wrap("web", handler));
|
|
179
179
|
}
|
|
180
|
-
wrapWebGuest(handler, home = "/
|
|
180
|
+
wrapWebGuest(handler, home = "/") {
|
|
181
181
|
const auth = this.dependencies.container.resolve(CORE_AUTH_TOKEN);
|
|
182
182
|
return this.wrapWeb(async (request) => {
|
|
183
183
|
const user = await auth.resolve(request);
|
|
@@ -34,7 +34,12 @@ function readDiscoverModulesState() {
|
|
|
34
34
|
return state;
|
|
35
35
|
}
|
|
36
36
|
function configureModulesDirectory(modulesDir) {
|
|
37
|
-
readDiscoverModulesState()
|
|
37
|
+
const state = readDiscoverModulesState();
|
|
38
|
+
if (state.configuredModulesDir !== modulesDir) {
|
|
39
|
+
state.appModules.length = 0;
|
|
40
|
+
state.modulesReady = undefined;
|
|
41
|
+
}
|
|
42
|
+
state.configuredModulesDir = modulesDir;
|
|
38
43
|
}
|
|
39
44
|
function resolveModulesDirectory(options) {
|
|
40
45
|
const state = readDiscoverModulesState();
|
|
@@ -44,7 +49,7 @@ function resolveModulesDirectory(options) {
|
|
|
44
49
|
if (state.configuredModulesDir) {
|
|
45
50
|
return state.configuredModulesDir;
|
|
46
51
|
}
|
|
47
|
-
throw new Error("configureModulesDirectory() must be called before discovering modules.
|
|
52
|
+
throw new Error("configureModulesDirectory() must be called before discovering modules. The app preload (or starter) should call it.");
|
|
48
53
|
}
|
|
49
54
|
async function loadDiscoveredModules(options) {
|
|
50
55
|
const modulesDirectory = resolveModulesDirectory(options);
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
var __jsonParse = (a) => JSON.parse(a);
|
|
3
3
|
|
|
4
4
|
// ../../src/bootstrap/providers/view.ts
|
|
5
|
-
import { resolveMembershipLookup } from "@getstrata/core/auth/membershipContext";
|
|
6
5
|
import { currentRequestMeta } from "@getstrata/core/http/requestMetaContext";
|
|
7
6
|
import { appDisplayName } from "@getstrata/core/runtime/appKeyPrefix";
|
|
8
7
|
import { isViewsEnabled } from "@getstrata/core/runtime/frontendMode";
|
|
@@ -14,148 +13,6 @@ import {
|
|
|
14
13
|
errorTemplateName,
|
|
15
14
|
resolveWebLayoutData
|
|
16
15
|
} from "@getstrata/core/view";
|
|
17
|
-
|
|
18
|
-
// ../../src/modules/organization/repository.ts
|
|
19
|
-
import { BaseRepository } from "@getstrata/core/database/baseRepository";
|
|
20
|
-
import { NotFoundError } from "@getstrata/core/errors/http";
|
|
21
|
-
import { currentTenantId } from "@getstrata/core/tenant/tenantContext";
|
|
22
|
-
|
|
23
|
-
// ../../src/modules/organization/table.ts
|
|
24
|
-
import { defineTable } from "@getstrata/core/database/table";
|
|
25
|
-
|
|
26
|
-
// ../../src/domain/workhub.ts
|
|
27
|
-
var ORGANIZATION_TABLE = "organization";
|
|
28
|
-
|
|
29
|
-
// ../../src/modules/organization/table.ts
|
|
30
|
-
var organizationTable = defineTable({
|
|
31
|
-
name: ORGANIZATION_TABLE,
|
|
32
|
-
primaryKey: "id",
|
|
33
|
-
columns: ["id", "tenant_id", "name", "slug", "created_at", "updated_at", "deleted_at"],
|
|
34
|
-
softDeletes: true,
|
|
35
|
-
defaultOrderBy: { column: "id", direction: "ASC" }
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
// ../../src/modules/organization/repository.ts
|
|
39
|
-
class OrganizationRepository extends BaseRepository {
|
|
40
|
-
constructor() {
|
|
41
|
-
super(organizationTable);
|
|
42
|
-
}
|
|
43
|
-
async findBySlug(slug) {
|
|
44
|
-
return await this.firstOrNull({ slug });
|
|
45
|
-
}
|
|
46
|
-
async listForTenant(options) {
|
|
47
|
-
return await this.findAll({
|
|
48
|
-
limit: options.limit,
|
|
49
|
-
offset: options.offset,
|
|
50
|
-
where: { tenant_id: options.tenantId ?? currentTenantId() }
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
async countForTenant(tenantId = currentTenantId()) {
|
|
54
|
-
return await this.countWhere({ tenant_id: tenantId });
|
|
55
|
-
}
|
|
56
|
-
async findForTenantOrThrow(id, tenantId = currentTenantId()) {
|
|
57
|
-
const organization = await this.findById(id);
|
|
58
|
-
if (!organization || organization.tenant_id !== tenantId) {
|
|
59
|
-
throw new NotFoundError(`SCIM group ${id} not found.`);
|
|
60
|
-
}
|
|
61
|
-
return organization;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
var repository_default = OrganizationRepository;
|
|
65
|
-
|
|
66
|
-
// ../../src/modules/user/repository.ts
|
|
67
|
-
import {
|
|
68
|
-
emailLookupForQuery,
|
|
69
|
-
protectEmail,
|
|
70
|
-
revealEmail
|
|
71
|
-
} from "@getstrata/core/crypto/fieldEncryption";
|
|
72
|
-
import { revealMfaSecret } from "@getstrata/core/crypto/mfaSecret";
|
|
73
|
-
import { BaseRepository as BaseRepository2 } from "@getstrata/core/database/baseRepository";
|
|
74
|
-
import { currentTenantId as currentTenantId2 } from "@getstrata/core/tenant/tenantContext";
|
|
75
|
-
|
|
76
|
-
// ../../src/modules/user/table.ts
|
|
77
|
-
import { defineTable as defineTable2 } from "@getstrata/core/database/table";
|
|
78
|
-
var userTable = defineTable2({
|
|
79
|
-
name: "users",
|
|
80
|
-
primaryKey: "id",
|
|
81
|
-
columns: [
|
|
82
|
-
"id",
|
|
83
|
-
"name",
|
|
84
|
-
"email",
|
|
85
|
-
"email_lookup",
|
|
86
|
-
"role",
|
|
87
|
-
"tenant_id",
|
|
88
|
-
"password_hash",
|
|
89
|
-
"email_verified_at",
|
|
90
|
-
"mfa_secret",
|
|
91
|
-
"mfa_enabled",
|
|
92
|
-
"mfa_recovery_codes",
|
|
93
|
-
"profile_photo_path",
|
|
94
|
-
"session_valid_after",
|
|
95
|
-
"current_organization_id",
|
|
96
|
-
"created_at",
|
|
97
|
-
"updated_at"
|
|
98
|
-
],
|
|
99
|
-
defaultOrderBy: { column: "id", direction: "ASC" }
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
// ../../src/modules/user/repository.ts
|
|
103
|
-
class UserRepository extends BaseRepository2 {
|
|
104
|
-
constructor() {
|
|
105
|
-
super(userTable);
|
|
106
|
-
}
|
|
107
|
-
decode(record) {
|
|
108
|
-
return {
|
|
109
|
-
...record,
|
|
110
|
-
email: revealEmail(record.email),
|
|
111
|
-
mfa_secret: revealMfaSecret(record.mfa_secret)
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
async findById(id) {
|
|
115
|
-
const record = await super.findById(id);
|
|
116
|
-
return record ? this.decode(record) : null;
|
|
117
|
-
}
|
|
118
|
-
async findAll(options = {}) {
|
|
119
|
-
const records = await super.findAll(options);
|
|
120
|
-
return records.map((record) => this.decode(record));
|
|
121
|
-
}
|
|
122
|
-
async create(values) {
|
|
123
|
-
const email = values.email;
|
|
124
|
-
if (!email) {
|
|
125
|
-
throw new Error("Email is required.");
|
|
126
|
-
}
|
|
127
|
-
const protectedEmail = protectEmail(email);
|
|
128
|
-
const record = await super.create({
|
|
129
|
-
...values,
|
|
130
|
-
tenant_id: values.tenant_id ?? currentTenantId2(),
|
|
131
|
-
email: protectedEmail.storedEmail,
|
|
132
|
-
email_lookup: protectedEmail.emailLookup,
|
|
133
|
-
password_hash: values.password_hash ?? ""
|
|
134
|
-
});
|
|
135
|
-
return this.decode(record);
|
|
136
|
-
}
|
|
137
|
-
async updateByIdOrThrow(id, values, errorFactory) {
|
|
138
|
-
const changes = { ...values };
|
|
139
|
-
if (values.email !== undefined) {
|
|
140
|
-
const protectedEmail = protectEmail(values.email);
|
|
141
|
-
changes.email = protectedEmail.storedEmail;
|
|
142
|
-
changes.email_lookup = protectedEmail.emailLookup;
|
|
143
|
-
}
|
|
144
|
-
const record = await super.updateByIdOrThrow(id, changes, errorFactory);
|
|
145
|
-
return this.decode(record);
|
|
146
|
-
}
|
|
147
|
-
async findByEmail(email) {
|
|
148
|
-
const records = await this.findWhere({ email_lookup: emailLookupForQuery(email) }, { limit: 1 });
|
|
149
|
-
const record = records[0];
|
|
150
|
-
return record ? this.decode(record) : null;
|
|
151
|
-
}
|
|
152
|
-
async countForTenant(tenantId = currentTenantId2()) {
|
|
153
|
-
return await this.countWhere({ tenant_id: tenantId });
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
var repository_default2 = UserRepository;
|
|
157
|
-
|
|
158
|
-
// ../../src/bootstrap/providers/view.ts
|
|
159
16
|
var CORE_VIEW_TOKEN = "core.view";
|
|
160
17
|
var VIEW_DIRECTORY_CONFIG_KEY = "view.directory";
|
|
161
18
|
var viewProvider = {
|
|
@@ -169,23 +26,11 @@ var viewProvider = {
|
|
|
169
26
|
const engine = new EtaViewEngine(viewsDirectory, (request) => resolveWebLayoutData(container, request ?? currentRequestMeta().request));
|
|
170
27
|
container.set(CORE_VIEW_TOKEN, engine);
|
|
171
28
|
configureWebLayoutData({
|
|
172
|
-
extra: async (
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
try {
|
|
178
|
-
const record = await new repository_default2().findByIdOrThrow(user.id);
|
|
179
|
-
const memberships = await resolveMembershipLookup().listForUser(record.id);
|
|
180
|
-
const organizationsRepo = new repository_default;
|
|
181
|
-
const organizations = (await Promise.all(memberships.map((membership) => organizationsRepo.findById(membership.organization_id)))).filter((organization) => Boolean(organization && !organization.deleted_at));
|
|
182
|
-
const currentId = record.current_organization_id ?? null;
|
|
183
|
-
const currentOrganization = organizations.find((organization) => organization.id === currentId) ?? organizations[0] ?? null;
|
|
184
|
-
return { appName, currentOrganization, organizations };
|
|
185
|
-
} catch {
|
|
186
|
-
return { appName, currentOrganization: null, organizations: [] };
|
|
187
|
-
}
|
|
188
|
-
}
|
|
29
|
+
extra: async () => ({
|
|
30
|
+
appName: appDisplayName(),
|
|
31
|
+
currentOrganization: null,
|
|
32
|
+
organizations: []
|
|
33
|
+
})
|
|
189
34
|
});
|
|
190
35
|
configureWebErrorView({
|
|
191
36
|
render: async (input) => engine.render(errorTemplateName(input.status), {
|