@getstrata/bootstrap 0.2.22 → 0.2.25
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/dist/bootstrap/applicationRegistry.d.ts +1 -1
- package/dist/bootstrap/buildModuleRoutes.d.ts +10 -0
- package/dist/bootstrap/buildWebModuleRoutes.d.ts +9 -0
- package/dist/bootstrap/config.d.ts +1 -1
- package/dist/bootstrap/contracts.d.ts +4 -4
- package/dist/bootstrap/env.d.ts +1 -1
- package/dist/bootstrap/membershipService.d.ts +1 -1
- package/dist/bootstrap/public-api.d.ts +6 -2
- package/dist/bootstrap/routeRegistry.d.ts +1 -1
- package/dist/entries/applicationRegistry.js +12 -115
- package/dist/entries/buildModuleRoutes.js +411 -0
- package/dist/entries/buildWebModuleRoutes.js +435 -0
- package/dist/entries/config.js +9 -9
- package/dist/entries/context.js +112 -192
- package/dist/entries/contracts.js +10 -85
- package/dist/entries/createWebRoutes.js +100 -682
- package/dist/entries/dependencies.js +112 -192
- package/dist/entries/http/securedRouteModelBinding.js +0 -37
- package/dist/entries/httpKernel.js +9 -9
- package/dist/entries/membershipService.js +2 -426
- package/dist/entries/providers/view.js +9 -20
- package/dist/entries/providers.js +102 -129
- package/dist/entries/queue/defaultJobs.js +0 -37
- package/dist/entries/web/routing.js +16 -44
- package/dist/index.js +507 -730
- package/package.json +14 -4
- package/dist/cli/commands/scheduleRun.d.ts +0 -3
- package/dist/config/app.d.ts +0 -10
- package/dist/config/auth.d.ts +0 -7
- package/dist/config/contentSecurityPolicy.d.ts +0 -5
- package/dist/config/cors.d.ts +0 -9
- package/dist/config/database.d.ts +0 -10
- package/dist/config/features.d.ts +0 -18
- package/dist/config/frontend.d.ts +0 -6
- package/dist/config/queue.d.ts +0 -8
- package/dist/config/rateLimit.d.ts +0 -10
- package/dist/config/uploads.d.ts +0 -5
- package/dist/core/admin/formatValue.d.ts +0 -3
- package/dist/core/admin/index.d.ts +0 -3
- package/dist/core/admin/registry.d.ts +0 -11
- package/dist/core/admin/types.d.ts +0 -24
- package/dist/core/audit/exportAuditLogs.d.ts +0 -8
- package/dist/core/audit/siemFormatter.d.ts +0 -30
- package/dist/core/auth/abilityChecker.d.ts +0 -6
- package/dist/core/auth/accessControl.d.ts +0 -8
- package/dist/core/auth/authContext.d.ts +0 -11
- package/dist/core/auth/guard.d.ts +0 -36
- package/dist/core/auth/membershipContext.d.ts +0 -15
- package/dist/core/auth/membershipContextMiddleware.d.ts +0 -3
- package/dist/core/auth/membershipMiddleware.d.ts +0 -2
- package/dist/core/auth/membershipScope.d.ts +0 -16
- package/dist/core/auth/membershipService.d.ts +0 -23
- package/dist/core/auth/oauth/oidcProvider.d.ts +0 -18
- package/dist/core/auth/oauth/providers.d.ts +0 -22
- package/dist/core/auth/oauth/samlProvider.d.ts +0 -9
- package/dist/core/auth/oauth/types.d.ts +0 -11
- package/dist/core/auth/password.d.ts +0 -3
- package/dist/core/auth/policy.d.ts +0 -15
- package/dist/core/auth/resolveMembershipService.d.ts +0 -3
- package/dist/core/auth/scimAuthMiddleware.d.ts +0 -3
- package/dist/core/auth/sessionCookie.d.ts +0 -6
- package/dist/core/auth/sessionGuard.d.ts +0 -9
- package/dist/core/auth/tokenHash.d.ts +0 -3
- package/dist/core/cache/createCacheStore.d.ts +0 -11
- package/dist/core/cache/redisCacheStore.d.ts +0 -23
- package/dist/core/cache/repository.d.ts +0 -17
- package/dist/core/cache/simpleCache.d.ts +0 -23
- package/dist/core/cache/simpleCacheStore.d.ts +0 -16
- package/dist/core/cache/store.d.ts +0 -12
- package/dist/core/cache/taggedCache.d.ts +0 -9
- package/dist/core/cache/tags.d.ts +0 -11
- package/dist/core/config/envSchema.d.ts +0 -12
- package/dist/core/contracts/container.d.ts +0 -30
- package/dist/core/contracts/di.d.ts +0 -31
- package/dist/core/contracts/serviceContainer.d.ts +0 -1
- package/dist/core/contracts/serviceTokens.d.ts +0 -8
- package/dist/core/crypto/fieldEncryption.d.ts +0 -13
- package/dist/core/crypto/mfaSecret.d.ts +0 -3
- package/dist/core/crypto/nonCryptographicHash.d.ts +0 -2
- package/dist/core/database/baseRepository.d.ts +0 -67
- package/dist/core/database/bindConnection.d.ts +0 -3
- package/dist/core/database/boundConnection.d.ts +0 -5
- package/dist/core/database/connection.d.ts +0 -7
- package/dist/core/database/connectionContext.d.ts +0 -8
- package/dist/core/database/defaultConnection.d.ts +0 -6
- package/dist/core/database/errors.d.ts +0 -12
- package/dist/core/database/index.d.ts +0 -18
- package/dist/core/database/migrations/advisoryLock.d.ts +0 -6
- package/dist/core/database/migrations/runner.d.ts +0 -25
- package/dist/core/database/migrations/types.d.ts +0 -15
- package/dist/core/database/model.d.ts +0 -57
- package/dist/core/database/query.d.ts +0 -63
- package/dist/core/database/queryProxy.d.ts +0 -3
- package/dist/core/database/relationships.d.ts +0 -100
- package/dist/core/database/repositoryConnection.d.ts +0 -4
- package/dist/core/database/repositoryQuery.d.ts +0 -38
- package/dist/core/database/schema/blueprint.d.ts +0 -47
- package/dist/core/database/schema/columnDefinition.d.ts +0 -36
- package/dist/core/database/schema/driver.d.ts +0 -8
- package/dist/core/database/schema/errors.d.ts +0 -4
- package/dist/core/database/schema/grammars/compileStatements.d.ts +0 -8
- package/dist/core/database/schema/grammars/createGrammar.d.ts +0 -4
- package/dist/core/database/schema/grammars/grammar.d.ts +0 -10
- package/dist/core/database/schema/grammars/index.d.ts +0 -7
- package/dist/core/database/schema/grammars/mysqlGrammar.d.ts +0 -2
- package/dist/core/database/schema/grammars/postgresGrammar.d.ts +0 -2
- package/dist/core/database/schema/grammars/sqliteGrammar.d.ts +0 -2
- package/dist/core/database/schema/index.d.ts +0 -12
- package/dist/core/database/schema/schema.d.ts +0 -21
- package/dist/core/database/seeders/runner.d.ts +0 -6
- package/dist/core/database/seeders/types.d.ts +0 -8
- package/dist/core/database/table.d.ts +0 -13
- package/dist/core/database/transaction.d.ts +0 -3
- package/dist/core/database/types.d.ts +0 -66
- package/dist/core/database/whereBuilder.d.ts +0 -17
- package/dist/core/errors/http.d.ts +0 -33
- package/dist/core/events/eventBus.d.ts +0 -10
- package/dist/core/events/index.d.ts +0 -4
- package/dist/core/facades/index.d.ts +0 -10
- package/dist/core/http/authMiddleware.d.ts +0 -5
- package/dist/core/http/authorizeMiddleware.d.ts +0 -5
- package/dist/core/http/bodySizeLimitMiddleware.d.ts +0 -4
- package/dist/core/http/conditionalResponse.d.ts +0 -2
- package/dist/core/http/contentNegotiation.d.ts +0 -2
- package/dist/core/http/cookies.d.ts +0 -4
- package/dist/core/http/corsMiddleware.d.ts +0 -3
- package/dist/core/http/csrfMiddleware.d.ts +0 -3
- package/dist/core/http/csrfProtection.d.ts +0 -12
- package/dist/core/http/csrfToken.d.ts +0 -14
- package/dist/core/http/etag.d.ts +0 -18
- package/dist/core/http/flashMiddleware.d.ts +0 -3
- package/dist/core/http/flashSession.d.ts +0 -12
- package/dist/core/http/formRequest.d.ts +0 -10
- package/dist/core/http/index.d.ts +0 -27
- package/dist/core/http/loginThrottleMiddleware.d.ts +0 -11
- package/dist/core/http/memoryThrottleMiddleware.d.ts +0 -9
- package/dist/core/http/metricsMiddleware.d.ts +0 -4
- package/dist/core/http/middleware.d.ts +0 -8
- package/dist/core/http/pagination.d.ts +0 -11
- package/dist/core/http/parseFormBody.d.ts +0 -6
- package/dist/core/http/parseMultipartUpload.d.ts +0 -10
- package/dist/core/http/requestMetaContext.d.ts +0 -15
- package/dist/core/http/requireAbilityMiddleware.d.ts +0 -4
- package/dist/core/http/requireAuthMiddleware.d.ts +0 -4
- package/dist/core/http/requireGlobalAdminMiddleware.d.ts +0 -3
- package/dist/core/http/requireWebAuthMiddleware.d.ts +0 -4
- package/dist/core/http/resources.d.ts +0 -7
- package/dist/core/http/route.d.ts +0 -6
- package/dist/core/http/routeMiddleware.d.ts +0 -3
- package/dist/core/http/routeModelBinding.d.ts +0 -3
- package/dist/core/http/scimThrottleMiddleware.d.ts +0 -9
- package/dist/core/http/securedRouteModelBinding.d.ts +0 -11
- package/dist/core/http/securityHeadersMiddleware.d.ts +0 -3
- package/dist/core/http/throttleMiddleware.d.ts +0 -11
- package/dist/core/http/validation.d.ts +0 -23
- package/dist/core/http/webErrorResponse.d.ts +0 -5
- package/dist/core/http/webFormRequest.d.ts +0 -7
- package/dist/core/jobs/dispatchWebhookJob.d.ts +0 -13
- package/dist/core/jobs/invalidateCacheTagsJob.d.ts +0 -12
- package/dist/core/lifecycle/gracefulShutdown.d.ts +0 -6
- package/dist/core/logging/logger.d.ts +0 -17
- package/dist/core/logging/requestLoggingMiddleware.d.ts +0 -3
- package/dist/core/mail/mailer.d.ts +0 -38
- package/dist/core/mail/markdownMail.d.ts +0 -15
- package/dist/core/mail/markdownMailable.d.ts +0 -12
- package/dist/core/metrics/prometheus.d.ts +0 -26
- package/dist/core/notifications/dispatcher.d.ts +0 -13
- package/dist/core/notifications/index.d.ts +0 -3
- package/dist/core/notifications/notification.d.ts +0 -7
- package/dist/core/notifications/types.d.ts +0 -25
- package/dist/core/openapi/registeredRoute.d.ts +0 -6
- package/dist/core/pagination/index.d.ts +0 -27
- package/dist/core/queue/createAppQueue.d.ts +0 -5
- package/dist/core/queue/failedJobRepository.d.ts +0 -6
- package/dist/core/queue/failedJobService.d.ts +0 -16
- package/dist/core/queue/failedJobTable.d.ts +0 -3
- package/dist/core/queue/index.d.ts +0 -19
- package/dist/core/queue/jobRegistry.d.ts +0 -13
- package/dist/core/queue/jobRunner.d.ts +0 -9
- package/dist/core/queue/publicQueue.d.ts +0 -16
- package/dist/core/queue/queueMetrics.d.ts +0 -15
- package/dist/core/queue/redisQueue.d.ts +0 -29
- package/dist/core/queue/resilientQueue.d.ts +0 -9
- package/dist/core/queue/types.d.ts +0 -8
- package/dist/core/runtime/applicationRegistry.d.ts +0 -17
- package/dist/core/runtime/asyncContextStore.d.ts +0 -3
- package/dist/core/scheduler/schedule.d.ts +0 -15
- package/dist/core/security/publicReads.d.ts +0 -3
- package/dist/core/security/safeFetch.d.ts +0 -10
- package/dist/core/security/safeUrl.d.ts +0 -20
- package/dist/core/security/scimTenantTokens.d.ts +0 -3
- package/dist/core/security/securityEvents.d.ts +0 -6
- package/dist/core/security/timingSafeCompare.d.ts +0 -2
- package/dist/core/security/tokenExpiry.d.ts +0 -2
- package/dist/core/security/totp.d.ts +0 -3
- package/dist/core/storage/storage.d.ts +0 -44
- package/dist/core/tenant/databaseTenantContext.d.ts +0 -2
- package/dist/core/tenant/resolveTenant.d.ts +0 -3
- package/dist/core/tenant/tenantContext.d.ts +0 -13
- package/dist/core/tenant/tenantDatabaseScope.d.ts +0 -8
- package/dist/core/tenant/tenantMiddleware.d.ts +0 -6
- package/dist/core/tracing/otel.d.ts +0 -26
- package/dist/core/tracing/traceContext.d.ts +0 -9
- package/dist/core/tracing/tracingMiddleware.d.ts +0 -3
- package/dist/core/validation/rules.d.ts +0 -17
- package/dist/core/view/etaViewEngine.d.ts +0 -15
- package/dist/core/view/htmlResponse.d.ts +0 -6
- package/dist/core/view/index.d.ts +0 -5
- package/dist/core/view/viewEngine.d.ts +0 -6
- package/dist/core/view/webLayoutData.d.ts +0 -17
- package/dist/db/connection/createConnection.d.ts +0 -6
- package/dist/db/connection/index.d.ts +0 -11
- package/dist/domain/abilities.d.ts +0 -5
- package/dist/domain/auth.d.ts +0 -4
- package/dist/domain/scim.d.ts +0 -9
- package/dist/domain/workhub.d.ts +0 -35
- package/dist/framework/public-api.d.ts +0 -116
- package/dist/modules/organization/memberRepository.d.ts +0 -14
- package/dist/modules/organization/memberTypes.d.ts +0 -9
- package/dist/modules/organization/repository.d.ts +0 -14
- package/dist/modules/organization/table.d.ts +0 -3
- package/dist/modules/organization/types.d.ts +0 -10
- package/dist/modules/scim/controller.d.ts +0 -16
- package/dist/modules/scim/scimResponse.d.ts +0 -10
- package/dist/modules/scim/service.d.ts +0 -214
- package/dist/modules/user/apiTokenRepository.d.ts +0 -8
- package/dist/modules/user/apiTokenTable.d.ts +0 -3
- package/dist/modules/user/authService.d.ts +0 -23
- package/dist/modules/user/notificationRepository.d.ts +0 -6
- package/dist/modules/user/notificationService.d.ts +0 -25
- package/dist/modules/user/notificationTable.d.ts +0 -3
- package/dist/modules/user/notificationTypes.d.ts +0 -12
- package/dist/modules/user/oauthIdentityRepository.d.ts +0 -9
- package/dist/modules/user/provider.d.ts +0 -11
- package/dist/modules/user/repository.d.ts +0 -13
- package/dist/modules/user/table.d.ts +0 -3
- package/dist/modules/user/tokenService.d.ts +0 -29
- package/dist/modules/user/types.d.ts +0 -46
- package/dist/types/services.d.ts +0 -16
|
@@ -1,430 +1,6 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
// ../../src/
|
|
3
|
-
|
|
4
|
-
"container",
|
|
5
|
-
"cache",
|
|
6
|
-
"storage"
|
|
7
|
-
];
|
|
8
|
-
function getRequiredDependency(dependencies, key) {
|
|
9
|
-
const dependency = dependencies[key];
|
|
10
|
-
if (dependency === undefined) {
|
|
11
|
-
throw new Error(`Required dependency "${key}" is not registered.`);
|
|
12
|
-
}
|
|
13
|
-
return dependency;
|
|
14
|
-
}
|
|
15
|
-
function assertAppDependenciesComplete(dependencies) {
|
|
16
|
-
for (const key of requiredDependencyKeys) {
|
|
17
|
-
getRequiredDependency(dependencies, key);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
function resolveService(dependencies, token) {
|
|
21
|
-
return dependencies.container.resolve(token);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// ../../src/core/contracts/serviceTokens.ts
|
|
25
|
-
var CORE_CONFIG_TOKEN = "core.config";
|
|
26
|
-
var CORE_CACHE_TOKEN = "core.cache";
|
|
27
|
-
var CORE_QUEUE_TOKEN = "core.queue";
|
|
28
|
-
var CORE_EVENT_BUS_TOKEN = "core.eventBus";
|
|
29
|
-
var CORE_POLICY_GATE_TOKEN = "core.policyGate";
|
|
30
|
-
var CORE_AUTH_TOKEN = "core.auth";
|
|
31
|
-
var CORE_TOKEN_SERVICE_TOKEN = "core.tokenService";
|
|
32
|
-
|
|
33
|
-
// ../../src/core/logging/logger.ts
|
|
34
|
-
class Logger {
|
|
35
|
-
channel;
|
|
36
|
-
constructor(channel = "app") {
|
|
37
|
-
this.channel = channel;
|
|
38
|
-
}
|
|
39
|
-
write(level, message, context = {}) {
|
|
40
|
-
const entry = {
|
|
41
|
-
level,
|
|
42
|
-
channel: this.channel,
|
|
43
|
-
message,
|
|
44
|
-
timestamp: new Date().toISOString(),
|
|
45
|
-
...context
|
|
46
|
-
};
|
|
47
|
-
const line = JSON.stringify(entry);
|
|
48
|
-
if (level === "error") {
|
|
49
|
-
console.error(line);
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
console.log(line);
|
|
53
|
-
}
|
|
54
|
-
debug(message, context) {
|
|
55
|
-
this.write("debug", message, context);
|
|
56
|
-
}
|
|
57
|
-
info(message, context) {
|
|
58
|
-
this.write("info", message, context);
|
|
59
|
-
}
|
|
60
|
-
warn(message, context) {
|
|
61
|
-
this.write("warn", message, context);
|
|
62
|
-
}
|
|
63
|
-
error(message, context) {
|
|
64
|
-
this.write("error", message, context);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
var appLogger = new Logger("app");
|
|
68
|
-
|
|
69
|
-
// ../../src/core/runtime/applicationRegistry.ts
|
|
70
|
-
var APPLICATION_CONTEXT_KEY = Symbol.for("@getstrata/applicationContext");
|
|
71
|
-
var activeContext;
|
|
72
|
-
function readStoredApplicationContext() {
|
|
73
|
-
if (activeContext) {
|
|
74
|
-
return activeContext;
|
|
75
|
-
}
|
|
76
|
-
const globalContext = globalThis[APPLICATION_CONTEXT_KEY];
|
|
77
|
-
if (globalContext) {
|
|
78
|
-
activeContext = globalContext;
|
|
79
|
-
}
|
|
80
|
-
return activeContext;
|
|
81
|
-
}
|
|
82
|
-
function setActiveApplicationContext(context) {
|
|
83
|
-
activeContext = context;
|
|
84
|
-
globalThis[APPLICATION_CONTEXT_KEY] = context;
|
|
85
|
-
}
|
|
86
|
-
function requireActiveApplicationContext() {
|
|
87
|
-
const context = readStoredApplicationContext();
|
|
88
|
-
if (!context) {
|
|
89
|
-
throw new Error("The application context has not been bootstrapped.");
|
|
90
|
-
}
|
|
91
|
-
return context;
|
|
92
|
-
}
|
|
93
|
-
function resolveApplicationCache() {
|
|
94
|
-
return getRequiredDependency(requireActiveApplicationContext().dependencies, "cache");
|
|
95
|
-
}
|
|
96
|
-
function resolveApplicationQueue() {
|
|
97
|
-
return requireActiveApplicationContext().container.resolve(CORE_QUEUE_TOKEN);
|
|
98
|
-
}
|
|
99
|
-
function resolveApplicationEventBus() {
|
|
100
|
-
return requireActiveApplicationContext().container.resolve(CORE_EVENT_BUS_TOKEN);
|
|
101
|
-
}
|
|
102
|
-
function resolveApplicationAuth() {
|
|
103
|
-
return requireActiveApplicationContext().container.resolve(CORE_AUTH_TOKEN);
|
|
104
|
-
}
|
|
105
|
-
function resolveApplicationPolicyGate() {
|
|
106
|
-
return requireActiveApplicationContext().container.resolve(CORE_POLICY_GATE_TOKEN);
|
|
107
|
-
}
|
|
108
|
-
function resolveApplicationConfig() {
|
|
109
|
-
return requireActiveApplicationContext().config;
|
|
110
|
-
}
|
|
111
|
-
function resolveApplicationLogger() {
|
|
112
|
-
return appLogger;
|
|
113
|
-
}
|
|
114
|
-
function resolveApplicationDependencies() {
|
|
115
|
-
return requireActiveApplicationContext().dependencies;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// ../../src/core/errors/http.ts
|
|
119
|
-
class HttpError extends Error {
|
|
120
|
-
status;
|
|
121
|
-
details;
|
|
122
|
-
constructor(status, message, details) {
|
|
123
|
-
super(message);
|
|
124
|
-
this.name = new.target.name;
|
|
125
|
-
this.status = status;
|
|
126
|
-
this.details = details;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
class BadRequestError extends HttpError {
|
|
131
|
-
constructor(message = "Bad Request", details) {
|
|
132
|
-
super(400, message, details);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
class ConflictError extends HttpError {
|
|
136
|
-
constructor(message = "Conflict", details) {
|
|
137
|
-
super(409, message, details);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
class UnprocessableEntityError extends HttpError {
|
|
142
|
-
constructor(message = "Unprocessable Entity", details) {
|
|
143
|
-
super(422, message, details);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
class ForbiddenError extends HttpError {
|
|
147
|
-
constructor(message = "Forbidden", details) {
|
|
148
|
-
super(403, message, details);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
class UnauthorizedError extends HttpError {
|
|
153
|
-
constructor(message = "Unauthorized", details) {
|
|
154
|
-
super(401, message, details);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
class PreconditionFailedError extends HttpError {
|
|
158
|
-
constructor(message = "Precondition Failed", details) {
|
|
159
|
-
super(412, message, details);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// ../../src/core/runtime/asyncContextStore.ts
|
|
164
|
-
import { AsyncLocalStorage } from "async_hooks";
|
|
165
|
-
function createAsyncContextStore(key) {
|
|
166
|
-
const symbol = Symbol.for(key);
|
|
167
|
-
const globalRecord = globalThis;
|
|
168
|
-
const existing = globalRecord[symbol];
|
|
169
|
-
if (existing) {
|
|
170
|
-
return existing;
|
|
171
|
-
}
|
|
172
|
-
const store = new AsyncLocalStorage;
|
|
173
|
-
globalRecord[symbol] = store;
|
|
174
|
-
return store;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// ../../src/core/auth/authContext.ts
|
|
178
|
-
var authContext = createAsyncContextStore("@getstrata/authContext");
|
|
179
|
-
function currentAuthUser() {
|
|
180
|
-
return authContext.getStore() ?? null;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
// ../../src/core/auth/accessControl.ts
|
|
184
|
-
var ROLE_RANK = {
|
|
185
|
-
member: 1,
|
|
186
|
-
admin: 2,
|
|
187
|
-
owner: 3
|
|
188
|
-
};
|
|
189
|
-
function isGlobalAdmin(user) {
|
|
190
|
-
return user?.role === "admin";
|
|
191
|
-
}
|
|
192
|
-
function hasMinimumOrgRole(role, minimum) {
|
|
193
|
-
if (!role) {
|
|
194
|
-
return false;
|
|
195
|
-
}
|
|
196
|
-
return ROLE_RANK[role] >= ROLE_RANK[minimum];
|
|
197
|
-
}
|
|
198
|
-
function resolveUserId(user) {
|
|
199
|
-
const userId = typeof user.id === "number" ? user.id : Number(user.id);
|
|
200
|
-
if (!Number.isInteger(userId) || userId <= 0) {
|
|
201
|
-
throw new ForbiddenError("Invalid authenticated user.");
|
|
202
|
-
}
|
|
203
|
-
return userId;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
// ../../src/config/database.ts
|
|
207
|
-
function readInteger(name, fallback) {
|
|
208
|
-
const parsed = Number.parseInt(process.env[name] ?? String(fallback), 10);
|
|
209
|
-
return Number.isInteger(parsed) && parsed >= 0 ? parsed : fallback;
|
|
210
|
-
}
|
|
211
|
-
var databaseConfig = {
|
|
212
|
-
url: process.env.DATABASE_URL ?? "",
|
|
213
|
-
poolMax: readInteger("DB_POOL_MAX", 10),
|
|
214
|
-
idleTimeoutSeconds: readInteger("DB_POOL_IDLE_TIMEOUT", 30),
|
|
215
|
-
maxLifetimeSeconds: readInteger("DB_POOL_MAX_LIFETIME", 3600),
|
|
216
|
-
connectionTimeoutSeconds: readInteger("DB_CONNECTION_TIMEOUT", 10)
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
// ../../src/core/database/connectionContext.ts
|
|
220
|
-
var activeConnection = createAsyncContextStore("@getstrata/databaseConnectionContext");
|
|
221
|
-
function getActiveDatabaseConnection(fallback) {
|
|
222
|
-
return activeConnection.getStore() ?? fallback;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
// ../../src/core/database/queryProxy.ts
|
|
226
|
-
var POOL_CONNECTION_METHODS = new Set(["begin", "close", "connect"]);
|
|
227
|
-
function createDatabaseQueryProxy(pool) {
|
|
228
|
-
function resolveDatabase() {
|
|
229
|
-
return getActiveDatabaseConnection(pool);
|
|
230
|
-
}
|
|
231
|
-
function resolveDatabaseForProperty(property) {
|
|
232
|
-
if (typeof property === "string" && POOL_CONNECTION_METHODS.has(property)) {
|
|
233
|
-
return pool;
|
|
234
|
-
}
|
|
235
|
-
return resolveDatabase();
|
|
236
|
-
}
|
|
237
|
-
return new Proxy(function database() {}, {
|
|
238
|
-
apply(_target, _thisArg, args) {
|
|
239
|
-
return resolveDatabase()(...args);
|
|
240
|
-
},
|
|
241
|
-
get(_target, property) {
|
|
242
|
-
const connection = resolveDatabaseForProperty(property);
|
|
243
|
-
const value = connection[property];
|
|
244
|
-
return typeof value === "function" ? value.bind(connection) : value;
|
|
245
|
-
}
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
// ../../src/core/database/defaultConnection.ts
|
|
250
|
-
var defaultPool = {
|
|
251
|
-
connection: null
|
|
252
|
-
};
|
|
253
|
-
var defaultQuery = {
|
|
254
|
-
connection: null
|
|
255
|
-
};
|
|
256
|
-
function registerDefaultDatabasePool(connection) {
|
|
257
|
-
defaultPool.connection = connection;
|
|
258
|
-
defaultQuery.connection = createDatabaseQueryProxy(connection);
|
|
259
|
-
}
|
|
260
|
-
function getDefaultDatabaseQuery() {
|
|
261
|
-
if (!defaultQuery.connection) {
|
|
262
|
-
throw new Error("Default database query handle is not registered. Call registerDefaultDatabasePool() during app bootstrap.");
|
|
263
|
-
}
|
|
264
|
-
return defaultQuery.connection;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
// ../../src/db/connection/createConnection.ts
|
|
268
|
-
var {SQL } = globalThis.Bun;
|
|
269
|
-
function createDatabaseConnection(config) {
|
|
270
|
-
if (!config.url) {
|
|
271
|
-
throw new Error("DATABASE_URL is not configured. Set DATABASE_URL before starting the app or running integration tests.");
|
|
272
|
-
}
|
|
273
|
-
return new SQL({
|
|
274
|
-
url: config.url,
|
|
275
|
-
max: config.poolMax,
|
|
276
|
-
idleTimeout: config.idleTimeoutSeconds,
|
|
277
|
-
maxLifetime: config.maxLifetimeSeconds,
|
|
278
|
-
connectionTimeout: config.connectionTimeoutSeconds
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
// ../../src/db/connection/index.ts
|
|
283
|
-
var connectionHolder = {
|
|
284
|
-
connection: null
|
|
285
|
-
};
|
|
286
|
-
function getDatabase() {
|
|
287
|
-
if (!connectionHolder.connection) {
|
|
288
|
-
connectionHolder.connection = createDatabaseConnection(databaseConfig);
|
|
289
|
-
registerDefaultDatabasePool(connectionHolder.connection);
|
|
290
|
-
}
|
|
291
|
-
return connectionHolder.connection;
|
|
292
|
-
}
|
|
293
|
-
function getDb() {
|
|
294
|
-
getDatabase();
|
|
295
|
-
return getDefaultDatabaseQuery();
|
|
296
|
-
}
|
|
297
|
-
var db = new Proxy(function database() {}, {
|
|
298
|
-
apply(_target, _thisArg, args) {
|
|
299
|
-
return getDb()(...args);
|
|
300
|
-
},
|
|
301
|
-
get(_target, property) {
|
|
302
|
-
const connection = getDb();
|
|
303
|
-
const value = connection[property];
|
|
304
|
-
return typeof value === "function" ? value.bind(connection) : value;
|
|
305
|
-
}
|
|
306
|
-
});
|
|
307
|
-
var connection_default = db;
|
|
308
|
-
|
|
309
|
-
// ../../src/modules/organization/memberRepository.ts
|
|
310
|
-
class OrganizationMemberRepository {
|
|
311
|
-
constructor() {}
|
|
312
|
-
async findMembership(userId, organizationId) {
|
|
313
|
-
const rows = await connection_default`
|
|
314
|
-
SELECT id, organization_id, user_id, role, created_at
|
|
315
|
-
FROM organization_member
|
|
316
|
-
WHERE user_id = ${userId} AND organization_id = ${organizationId}
|
|
317
|
-
LIMIT 1
|
|
318
|
-
`;
|
|
319
|
-
return rows[0] ?? null;
|
|
320
|
-
}
|
|
321
|
-
async listForUser(userId) {
|
|
322
|
-
return await connection_default`
|
|
323
|
-
SELECT id, organization_id, user_id, role, created_at
|
|
324
|
-
FROM organization_member
|
|
325
|
-
WHERE user_id = ${userId}
|
|
326
|
-
ORDER BY organization_id
|
|
327
|
-
`;
|
|
328
|
-
}
|
|
329
|
-
async listForOrganization(organizationId) {
|
|
330
|
-
return await connection_default`
|
|
331
|
-
SELECT id, organization_id, user_id, role, created_at
|
|
332
|
-
FROM organization_member
|
|
333
|
-
WHERE organization_id = ${organizationId}
|
|
334
|
-
ORDER BY id
|
|
335
|
-
`;
|
|
336
|
-
}
|
|
337
|
-
async addMember(input) {
|
|
338
|
-
const rows = await connection_default`
|
|
339
|
-
INSERT INTO organization_member (organization_id, user_id, role)
|
|
340
|
-
VALUES (${input.organizationId}, ${input.userId}, ${input.role ?? "member"})
|
|
341
|
-
RETURNING id, organization_id, user_id, role, created_at
|
|
342
|
-
`;
|
|
343
|
-
const row = rows[0];
|
|
344
|
-
if (!row) {
|
|
345
|
-
throw new Error("Organization member insert did not return a row.");
|
|
346
|
-
}
|
|
347
|
-
return row;
|
|
348
|
-
}
|
|
349
|
-
async removeMember(organizationId, userId) {
|
|
350
|
-
const rows = await connection_default`
|
|
351
|
-
DELETE FROM organization_member
|
|
352
|
-
WHERE organization_id = ${organizationId} AND user_id = ${userId}
|
|
353
|
-
RETURNING id
|
|
354
|
-
`;
|
|
355
|
-
return rows.length > 0;
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
var memberRepository_default = OrganizationMemberRepository;
|
|
359
|
-
|
|
360
|
-
// ../../src/core/auth/membershipContext.ts
|
|
361
|
-
var membershipContext = createAsyncContextStore("@getstrata/membershipContext");
|
|
362
|
-
var membershipRepository = new memberRepository_default;
|
|
363
|
-
|
|
364
|
-
// ../../src/core/auth/membershipService.ts
|
|
365
|
-
class MembershipService {
|
|
366
|
-
members;
|
|
367
|
-
constructor(members = membershipRepository) {
|
|
368
|
-
this.members = members;
|
|
369
|
-
}
|
|
370
|
-
async listOrganizationIdsForUser(userId) {
|
|
371
|
-
const memberships = await this.members.listForUser(userId);
|
|
372
|
-
return memberships.map((membership) => membership.organization_id);
|
|
373
|
-
}
|
|
374
|
-
async getOrgRole(userId, organizationId) {
|
|
375
|
-
const membership = await this.members.findMembership(userId, organizationId);
|
|
376
|
-
return membership?.role ?? null;
|
|
377
|
-
}
|
|
378
|
-
async requireOrgAccess(organizationId, minimumRole = "member", user = currentAuthUser()) {
|
|
379
|
-
if (!user) {
|
|
380
|
-
throw new ForbiddenError("Authentication required.");
|
|
381
|
-
}
|
|
382
|
-
if (isGlobalAdmin(user)) {
|
|
383
|
-
return "owner";
|
|
384
|
-
}
|
|
385
|
-
const role = await this.getOrgRole(resolveUserId(user), organizationId);
|
|
386
|
-
if (!role || !hasMinimumOrgRole(role, minimumRole)) {
|
|
387
|
-
throw new ForbiddenError("Organization membership required.");
|
|
388
|
-
}
|
|
389
|
-
return role;
|
|
390
|
-
}
|
|
391
|
-
async filterAccessibleOrganizationIds(organizationIds, user = currentAuthUser()) {
|
|
392
|
-
if (!user) {
|
|
393
|
-
return [];
|
|
394
|
-
}
|
|
395
|
-
if (isGlobalAdmin(user)) {
|
|
396
|
-
return organizationIds;
|
|
397
|
-
}
|
|
398
|
-
const allowed = new Set(await this.listOrganizationIdsForUser(resolveUserId(user)));
|
|
399
|
-
return organizationIds.filter((organizationId) => allowed.has(organizationId));
|
|
400
|
-
}
|
|
401
|
-
async addOwnerOnOrganizationCreate(organizationId, userId) {
|
|
402
|
-
await this.members.addMember({
|
|
403
|
-
organizationId,
|
|
404
|
-
userId,
|
|
405
|
-
role: "owner"
|
|
406
|
-
});
|
|
407
|
-
}
|
|
408
|
-
listMembersForOrganization(organizationId) {
|
|
409
|
-
return this.members.listForOrganization(organizationId);
|
|
410
|
-
}
|
|
411
|
-
addMember(input) {
|
|
412
|
-
return this.members.addMember(input);
|
|
413
|
-
}
|
|
414
|
-
removeMember(organizationId, userId) {
|
|
415
|
-
return this.members.removeMember(organizationId, userId);
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
var membershipService_default = MembershipService;
|
|
419
|
-
|
|
420
|
-
// ../../src/core/auth/resolveMembershipService.ts
|
|
421
|
-
function resolveMembershipService() {
|
|
422
|
-
const dependencies = resolveApplicationDependencies();
|
|
423
|
-
if (dependencies.container.has("core.membership")) {
|
|
424
|
-
return dependencies.container.resolve("core.membership");
|
|
425
|
-
}
|
|
426
|
-
return new membershipService_default;
|
|
427
|
-
}
|
|
2
|
+
// ../../src/bootstrap/membershipService.ts
|
|
3
|
+
import { resolveMembershipService } from "@getstrata/core/auth/membershipService";
|
|
428
4
|
export {
|
|
429
5
|
resolveMembershipService
|
|
430
6
|
};
|
|
@@ -69,26 +69,16 @@ class EtaViewEngine {
|
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
-
// ../../src/core/view/htmlResponse.ts
|
|
73
|
-
function htmlResponse(html, init = {}) {
|
|
74
|
-
return new Response(html, {
|
|
75
|
-
status: init.status ?? 200,
|
|
76
|
-
statusText: init.statusText,
|
|
77
|
-
headers: {
|
|
78
|
-
"Content-Type": "text/html; charset=utf-8"
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
// ../../src/core/contracts/serviceTokens.ts
|
|
83
|
-
var CORE_CONFIG_TOKEN = "core.config";
|
|
84
|
-
var CORE_CACHE_TOKEN = "core.cache";
|
|
85
|
-
var CORE_QUEUE_TOKEN = "core.queue";
|
|
86
|
-
var CORE_EVENT_BUS_TOKEN = "core.eventBus";
|
|
87
|
-
var CORE_POLICY_GATE_TOKEN = "core.policyGate";
|
|
88
|
-
var CORE_AUTH_TOKEN = "core.auth";
|
|
89
|
-
var CORE_TOKEN_SERVICE_TOKEN = "core.tokenService";
|
|
90
|
-
|
|
91
72
|
// ../../src/bootstrap/config.ts
|
|
73
|
+
import {
|
|
74
|
+
CORE_AUTH_TOKEN,
|
|
75
|
+
CORE_CACHE_TOKEN,
|
|
76
|
+
CORE_CONFIG_TOKEN,
|
|
77
|
+
CORE_EVENT_BUS_TOKEN,
|
|
78
|
+
CORE_POLICY_GATE_TOKEN,
|
|
79
|
+
CORE_QUEUE_TOKEN,
|
|
80
|
+
CORE_TOKEN_SERVICE_TOKEN
|
|
81
|
+
} from "@getstrata/core/contracts/serviceTokens.ts";
|
|
92
82
|
var APP_PORT_CONFIG_KEY = "app.port";
|
|
93
83
|
var CACHE_TTL_MS_CONFIG_KEY = "cache.ttlMs";
|
|
94
84
|
var CACHE_MAX_ENTRIES_CONFIG_KEY = "cache.maxEntries";
|
|
@@ -233,7 +223,6 @@ var db = new Proxy(function database() {}, {
|
|
|
233
223
|
return typeof value === "function" ? value.bind(connection) : value;
|
|
234
224
|
}
|
|
235
225
|
});
|
|
236
|
-
var connection_default = db;
|
|
237
226
|
|
|
238
227
|
// ../../src/modules/user/apiTokenTable.ts
|
|
239
228
|
import { defineTable } from "@getstrata/core/database";
|