@getstrata/core 0.5.55 → 0.5.57
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/README.md +3 -1
- package/dist/{domain/abilities.d.ts → core/auth/abilityCatalog.d.ts} +9 -1
- package/dist/core/auth/accessControl.d.ts +1 -1
- package/dist/core/auth/membershipContext.d.ts +6 -4
- package/dist/core/auth/membershipService.d.ts +5 -6
- package/dist/core/contracts/authUserDirectory.d.ts +11 -0
- package/dist/core/contracts/membership.d.ts +20 -0
- package/dist/core/http/clientIp.d.ts +3 -0
- package/dist/core/jobs/dispatchWebhookJob.d.ts +2 -0
- package/dist/core/media/imageTransform.d.ts +13 -0
- package/dist/core/scheduler/osCron.d.ts +14 -0
- package/dist/core/tenant/tenancyConfig.d.ts +5 -0
- package/dist/core/tenant/tenantMiddleware.d.ts +1 -1
- package/dist/core/terminal/runShell.d.ts +6 -0
- package/dist/core/view/assertEtaHtmlSource.d.ts +5 -0
- package/dist/core/view/etaViewEngine.d.ts +4 -0
- package/dist/entries/audit/exportAuditLogs.js +2 -2
- package/dist/entries/audit/siemFormatter.js +2 -2
- package/dist/entries/auth/accessControl.js +4 -4
- package/dist/entries/auth/membershipMiddleware.js +21 -161
- package/dist/entries/auth/membershipScope.js +26 -166
- package/dist/entries/auth/membershipService.js +21 -161
- package/dist/entries/auth/oauth/providers.js +2 -2
- package/dist/entries/auth/password.js +2 -2
- package/dist/entries/auth/policy.js +2 -2
- package/dist/entries/auth/scimAuthMiddleware.js +22 -4
- package/dist/entries/auth/sessionCookie.js +4 -4
- package/dist/entries/auth/sessionGuard.js +12 -349
- package/dist/entries/auth/tokenHash.js +2 -2
- package/dist/entries/config/envSchema.js +2 -2
- package/dist/entries/contracts/container.js +2 -2
- package/dist/entries/contracts/di.js +2 -2
- package/dist/entries/contracts/serviceTokens.js +6 -6
- package/dist/entries/crypto/fieldEncryption.js +8 -8
- package/dist/entries/crypto/mfaSecret.js +2 -2
- package/dist/entries/database/errors.js +2 -2
- package/dist/entries/database/migrations.js +8 -8
- package/dist/entries/database/model.js +5 -5
- package/dist/entries/database/query.js +19 -19
- package/dist/entries/database/relationships.js +13 -13
- package/dist/entries/database/schema.js +13 -13
- package/dist/entries/database/seeders.js +2 -2
- package/dist/entries/facades.js +8 -8
- package/dist/entries/http/authMiddleware.js +2 -2
- package/dist/entries/http/bodySizeLimitMiddleware.js +2 -2
- package/dist/entries/http/clientIp.js +19 -0
- package/dist/entries/http/cookies.js +2 -2
- package/dist/entries/http/csrfMiddleware.js +2 -1
- package/dist/entries/http/csrfProtection.js +2 -2
- package/dist/entries/http/csrfToken.js +8 -7
- package/dist/entries/http/etag.js +8 -8
- package/dist/entries/http/flashSession.js +4 -4
- package/dist/entries/http/formRequest.js +2 -2
- package/dist/entries/http/loginThrottleMiddleware.js +20 -3
- package/dist/entries/http/memoryThrottleMiddleware.js +16 -1
- package/dist/entries/http/metricsMiddleware.js +2 -2
- package/dist/entries/http/pagination.js +4 -4
- package/dist/entries/http/parseFormBody.js +2 -2
- package/dist/entries/http/parseMultipartUpload.js +2 -2
- package/dist/entries/http/resources.js +2 -2
- package/dist/entries/http/response.js +214 -395
- package/dist/entries/http/scimThrottleMiddleware.js +40 -1
- package/dist/entries/http/securedRouteModelBinding.js +2 -2
- package/dist/entries/http/throttleMiddleware.js +20 -3
- package/dist/entries/http/validation.js +13 -13
- package/dist/entries/http/webErrorResponse.js +212 -393
- package/dist/entries/jobs/dispatchWebhookJob.js +111 -5
- package/dist/entries/lifecycle/gracefulShutdown.js +3 -3
- package/dist/entries/logging/logger.js +2 -2
- package/dist/entries/logging/requestLoggingMiddleware.js +16 -1
- package/dist/entries/mail/mailer.js +6 -6
- package/dist/entries/mail/markdownMail.js +3 -3
- package/dist/entries/mail/markdownMailable.js +2 -2
- package/dist/entries/media/imageTransform.js +40 -0
- package/dist/entries/metrics/prometheus.js +2 -2
- package/dist/entries/openapi/generator.js +2 -2
- package/dist/entries/queue/createAppQueue.js +4 -4
- package/dist/entries/queue/publicQueue.js +10 -10
- package/dist/entries/queue/queueMetrics.js +2 -2
- package/dist/entries/queue/redisQueue.js +7 -7
- package/dist/entries/queue.js +3 -3
- package/dist/entries/scheduler/osCron.js +27 -0
- package/dist/entries/scheduler/schedule.js +2 -2
- package/dist/entries/security/oauthState.js +3 -3
- package/dist/entries/security/publicReads.js +2 -2
- package/dist/entries/security/safeFetch.js +2 -2
- package/dist/entries/security/safeUrl.js +5 -5
- package/dist/entries/security/scimTenantTokens.js +3 -6
- package/dist/entries/security/totp.js +2 -2
- package/dist/entries/storage/storage.js +7 -7
- package/dist/entries/tenant/tenancyConfig.js +12 -0
- package/dist/entries/tenant/tenantDatabaseScope.js +13 -2
- package/dist/entries/terminal/runShell.js +18 -0
- package/dist/entries/validation/rules.js +12 -12
- package/dist/entries/view.js +212 -393
- package/dist/framework/public-api.d.ts +4 -1
- package/dist/index.js +2591 -2686
- package/package.json +27 -2
- package/dist/config/database.d.ts +0 -10
- package/dist/db/connection/createConnection.d.ts +0 -6
- package/dist/db/connection/index.d.ts +0 -11
- package/dist/domain/auth.d.ts +0 -4
- package/dist/domain/scim.d.ts +0 -9
- package/dist/modules/organization/memberRepository.d.ts +0 -14
- package/dist/modules/organization/memberTypes.d.ts +0 -9
- 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
|
@@ -66,7 +66,7 @@ async function withDatabaseErrorHandling(operation) {
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
// ../../src/core/http/webErrorResponse.ts
|
|
69
|
-
import { HttpError as HttpError2, UnauthorizedError
|
|
69
|
+
import { HttpError as HttpError2, UnauthorizedError, ValidationError } from "@getstrata/core/errors/http";
|
|
70
70
|
|
|
71
71
|
// ../../src/config/frontend.ts
|
|
72
72
|
function readFrontendMode() {
|
|
@@ -84,8 +84,183 @@ function isViewsEnabled() {
|
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
// ../../src/core/view/etaViewEngine.ts
|
|
87
|
-
import { join } from "path";
|
|
87
|
+
import { join, relative } from "path";
|
|
88
88
|
import { Eta } from "eta";
|
|
89
|
+
|
|
90
|
+
// ../../src/core/view/assertEtaHtmlSource.ts
|
|
91
|
+
var HTML_TAGS = new Set([
|
|
92
|
+
"a",
|
|
93
|
+
"abbr",
|
|
94
|
+
"address",
|
|
95
|
+
"article",
|
|
96
|
+
"aside",
|
|
97
|
+
"audio",
|
|
98
|
+
"b",
|
|
99
|
+
"blockquote",
|
|
100
|
+
"body",
|
|
101
|
+
"button",
|
|
102
|
+
"canvas",
|
|
103
|
+
"caption",
|
|
104
|
+
"cite",
|
|
105
|
+
"code",
|
|
106
|
+
"col",
|
|
107
|
+
"colgroup",
|
|
108
|
+
"data",
|
|
109
|
+
"datalist",
|
|
110
|
+
"dd",
|
|
111
|
+
"del",
|
|
112
|
+
"details",
|
|
113
|
+
"dfn",
|
|
114
|
+
"dialog",
|
|
115
|
+
"div",
|
|
116
|
+
"dl",
|
|
117
|
+
"dt",
|
|
118
|
+
"em",
|
|
119
|
+
"fieldset",
|
|
120
|
+
"figcaption",
|
|
121
|
+
"figure",
|
|
122
|
+
"footer",
|
|
123
|
+
"form",
|
|
124
|
+
"h1",
|
|
125
|
+
"h2",
|
|
126
|
+
"h3",
|
|
127
|
+
"h4",
|
|
128
|
+
"h5",
|
|
129
|
+
"h6",
|
|
130
|
+
"header",
|
|
131
|
+
"hgroup",
|
|
132
|
+
"hr",
|
|
133
|
+
"html",
|
|
134
|
+
"i",
|
|
135
|
+
"iframe",
|
|
136
|
+
"img",
|
|
137
|
+
"input",
|
|
138
|
+
"ins",
|
|
139
|
+
"kbd",
|
|
140
|
+
"label",
|
|
141
|
+
"legend",
|
|
142
|
+
"li",
|
|
143
|
+
"main",
|
|
144
|
+
"map",
|
|
145
|
+
"mark",
|
|
146
|
+
"menu",
|
|
147
|
+
"meter",
|
|
148
|
+
"nav",
|
|
149
|
+
"object",
|
|
150
|
+
"ol",
|
|
151
|
+
"optgroup",
|
|
152
|
+
"option",
|
|
153
|
+
"output",
|
|
154
|
+
"p",
|
|
155
|
+
"picture",
|
|
156
|
+
"pre",
|
|
157
|
+
"progress",
|
|
158
|
+
"q",
|
|
159
|
+
"rp",
|
|
160
|
+
"rt",
|
|
161
|
+
"ruby",
|
|
162
|
+
"s",
|
|
163
|
+
"samp",
|
|
164
|
+
"script",
|
|
165
|
+
"search",
|
|
166
|
+
"section",
|
|
167
|
+
"select",
|
|
168
|
+
"slot",
|
|
169
|
+
"small",
|
|
170
|
+
"source",
|
|
171
|
+
"span",
|
|
172
|
+
"strong",
|
|
173
|
+
"style",
|
|
174
|
+
"sub",
|
|
175
|
+
"summary",
|
|
176
|
+
"sup",
|
|
177
|
+
"table",
|
|
178
|
+
"tbody",
|
|
179
|
+
"td",
|
|
180
|
+
"template",
|
|
181
|
+
"textarea",
|
|
182
|
+
"tfoot",
|
|
183
|
+
"th",
|
|
184
|
+
"thead",
|
|
185
|
+
"time",
|
|
186
|
+
"title",
|
|
187
|
+
"tr",
|
|
188
|
+
"track",
|
|
189
|
+
"u",
|
|
190
|
+
"ul",
|
|
191
|
+
"var",
|
|
192
|
+
"video",
|
|
193
|
+
"wbr"
|
|
194
|
+
]);
|
|
195
|
+
var TAG_PATTERN = "([a-z][a-z0-9]*)";
|
|
196
|
+
var CLASS_OR_ID_PATTERN = "[.#][\\w-]+";
|
|
197
|
+
var CLASS_ID_SHORTHAND = new RegExp(`^${TAG_PATTERN}(?:${CLASS_OR_ID_PATTERN})+`);
|
|
198
|
+
var ATTRIBUTE_SHORTHAND = new RegExp(`^${TAG_PATTERN}(?:${CLASS_OR_ID_PATTERN})*\\s+[\\w:-]+=`);
|
|
199
|
+
var TAG_SHORTHAND = new RegExp(`^${TAG_PATTERN}(?:>|\\s+\\S|$)`);
|
|
200
|
+
function htmlTagName(match) {
|
|
201
|
+
const tag = match?.[1];
|
|
202
|
+
return tag && HTML_TAGS.has(tag) ? tag : undefined;
|
|
203
|
+
}
|
|
204
|
+
function describePugLikeLine(line) {
|
|
205
|
+
if (/^\|(?:\s|$)/.test(line)) {
|
|
206
|
+
return "piped text";
|
|
207
|
+
}
|
|
208
|
+
if (htmlTagName(line.match(CLASS_ID_SHORTHAND))) {
|
|
209
|
+
return "class/id shorthand";
|
|
210
|
+
}
|
|
211
|
+
if (htmlTagName(line.match(ATTRIBUTE_SHORTHAND))) {
|
|
212
|
+
return "attribute shorthand";
|
|
213
|
+
}
|
|
214
|
+
if (htmlTagName(line.match(TAG_SHORTHAND))) {
|
|
215
|
+
return "tag shorthand";
|
|
216
|
+
}
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
function updateSkipBlock(lower, skipBlock) {
|
|
220
|
+
if (skipBlock) {
|
|
221
|
+
if (skipBlock === "comment" && lower.includes("-->")) {
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
if (skipBlock !== "comment" && lower.includes(`</${skipBlock}`)) {
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
return skipBlock;
|
|
228
|
+
}
|
|
229
|
+
if (lower.startsWith("<!--") && !lower.includes("-->")) {
|
|
230
|
+
return "comment";
|
|
231
|
+
}
|
|
232
|
+
if (lower.startsWith("<script") && !lower.includes("</script")) {
|
|
233
|
+
return "script";
|
|
234
|
+
}
|
|
235
|
+
if (lower.startsWith("<style") && !lower.includes("</style")) {
|
|
236
|
+
return "style";
|
|
237
|
+
}
|
|
238
|
+
return null;
|
|
239
|
+
}
|
|
240
|
+
function assertEtaHtmlSource(templateName, source) {
|
|
241
|
+
let skipBlock = null;
|
|
242
|
+
for (const rawLine of source.split(/\r?\n/)) {
|
|
243
|
+
const trimmed = rawLine.trim();
|
|
244
|
+
if (!trimmed) {
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
const lower = trimmed.toLowerCase();
|
|
248
|
+
const nextSkipBlock = updateSkipBlock(lower, skipBlock);
|
|
249
|
+
if (skipBlock || nextSkipBlock) {
|
|
250
|
+
skipBlock = nextSkipBlock;
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
if (trimmed.startsWith("<") || trimmed.startsWith("<%")) {
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
const kind = describePugLikeLine(trimmed);
|
|
257
|
+
if (kind) {
|
|
258
|
+
throw new Error(`Eta view "${templateName}" contains Pug-like markup (${kind}: ${trimmed}). Eta views must be HTML + <% %> tags, not Pug.`);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// ../../src/core/view/etaViewEngine.ts
|
|
89
264
|
var DEFAULT_VIEWS_DIRECTORY = join(process.cwd(), "resources/views");
|
|
90
265
|
var DEFAULT_LAYOUT = "layouts/app.eta";
|
|
91
266
|
|
|
@@ -98,6 +273,12 @@ class EtaViewEngine {
|
|
|
98
273
|
autoTrim: false
|
|
99
274
|
});
|
|
100
275
|
this.resolveLayoutData = resolveLayoutData;
|
|
276
|
+
const readFile = this.eta.readFile?.bind(this.eta);
|
|
277
|
+
this.eta.readFile = (path) => {
|
|
278
|
+
const source = readFile ? readFile(path) : "";
|
|
279
|
+
assertEtaHtmlSource(relative(viewsDirectory, path) || path, source);
|
|
280
|
+
return source;
|
|
281
|
+
};
|
|
101
282
|
}
|
|
102
283
|
async render(name, data = {}, options = {}) {
|
|
103
284
|
const template = name.endsWith(".eta") ? name : `${name}.eta`;
|
|
@@ -132,391 +313,14 @@ function isHtmxRequest(request) {
|
|
|
132
313
|
import { currentAuthUser } from "@getstrata/core/auth/authContext";
|
|
133
314
|
import { currentRequestMeta as currentRequestMeta2 } from "@getstrata/core/http/requestMetaContext";
|
|
134
315
|
|
|
135
|
-
// ../../src/
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
CORE_TOKEN_SERVICE_TOKEN
|
|
144
|
-
} from "@getstrata/core/contracts/serviceTokens";
|
|
145
|
-
var DEFAULT_QUEUE_DRIVER = "sync";
|
|
146
|
-
|
|
147
|
-
// ../../src/modules/user/provider.ts
|
|
148
|
-
import { OidcProvider } from "@getstrata/core/auth/oauth/oidcProvider";
|
|
149
|
-
import { GitHubOAuthProvider, MockOAuthProvider } from "@getstrata/core/auth/oauth/providers";
|
|
150
|
-
import { SamlProvider } from "@getstrata/core/auth/oauth/samlProvider";
|
|
151
|
-
|
|
152
|
-
// ../../src/config/features.ts
|
|
153
|
-
function readFeatureFlags() {
|
|
154
|
-
return {
|
|
155
|
-
webhooks: (process.env.FEATURE_WEBHOOKS ?? "true") !== "false",
|
|
156
|
-
fullTextSearch: (process.env.FEATURE_SEARCH ?? "true") !== "false",
|
|
157
|
-
auditLog: (process.env.FEATURE_AUDIT_LOG ?? "true") !== "false",
|
|
158
|
-
oauthLogin: (process.env.FEATURE_OAUTH ?? "true") !== "false",
|
|
159
|
-
samlLogin: (process.env.FEATURE_SAML ?? "false") === "true",
|
|
160
|
-
scim: (process.env.FEATURE_SCIM ?? "true") !== "false",
|
|
161
|
-
billing: (process.env.FEATURE_BILLING ?? "true") !== "false",
|
|
162
|
-
siemExport: (process.env.FEATURE_SIEM_EXPORT ?? "true") !== "false",
|
|
163
|
-
publicReads: (process.env.FEATURE_PUBLIC_READS ?? "true") !== "false",
|
|
164
|
-
emailVerification: (process.env.FEATURE_EMAIL_VERIFICATION ?? "false") === "true",
|
|
165
|
-
mfa: (process.env.FEATURE_MFA ?? "false") === "true"
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
var featureFlags = readFeatureFlags();
|
|
169
|
-
function isFeatureEnabled(feature) {
|
|
170
|
-
return readFeatureFlags()[feature];
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// ../../src/modules/user/apiTokenRepository.ts
|
|
174
|
-
import { BaseRepository } from "@getstrata/core/database/baseRepository";
|
|
175
|
-
|
|
176
|
-
// ../../src/config/database.ts
|
|
177
|
-
function readInteger(name, fallback) {
|
|
178
|
-
const parsed = Number.parseInt(process.env[name] ?? String(fallback), 10);
|
|
179
|
-
return Number.isInteger(parsed) && parsed >= 0 ? parsed : fallback;
|
|
180
|
-
}
|
|
181
|
-
var databaseConfig = {
|
|
182
|
-
url: process.env.DATABASE_URL ?? "",
|
|
183
|
-
poolMax: readInteger("DB_POOL_MAX", 10),
|
|
184
|
-
idleTimeoutSeconds: readInteger("DB_POOL_IDLE_TIMEOUT", 30),
|
|
185
|
-
maxLifetimeSeconds: readInteger("DB_POOL_MAX_LIFETIME", 3600),
|
|
186
|
-
connectionTimeoutSeconds: readInteger("DB_CONNECTION_TIMEOUT", 10)
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
// ../../src/core/runtime/asyncContextStore.ts
|
|
190
|
-
import { AsyncLocalStorage } from "async_hooks";
|
|
191
|
-
function createAsyncContextStore(key) {
|
|
192
|
-
const symbol = Symbol.for(key);
|
|
193
|
-
const globalRecord = globalThis;
|
|
194
|
-
const existing = globalRecord[symbol];
|
|
195
|
-
if (existing) {
|
|
196
|
-
return existing;
|
|
197
|
-
}
|
|
198
|
-
const store = new AsyncLocalStorage;
|
|
199
|
-
globalRecord[symbol] = store;
|
|
200
|
-
return store;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// ../../src/core/database/connectionContext.ts
|
|
204
|
-
var activeConnection = createAsyncContextStore("@getstrata/databaseConnectionContext");
|
|
205
|
-
function runWithDatabaseConnection(connection, callback) {
|
|
206
|
-
return activeConnection.run(connection, callback);
|
|
207
|
-
}
|
|
208
|
-
function getActiveDatabaseConnection(fallback) {
|
|
209
|
-
return activeConnection.getStore() ?? fallback;
|
|
210
|
-
}
|
|
211
|
-
function hasActiveDatabaseConnection() {
|
|
212
|
-
return activeConnection.getStore() !== undefined;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
// ../../src/core/database/queryProxy.ts
|
|
216
|
-
var POOL_CONNECTION_METHODS = new Set(["begin", "close", "connect"]);
|
|
217
|
-
function createDatabaseQueryProxy(pool) {
|
|
218
|
-
function resolveDatabase() {
|
|
219
|
-
return getActiveDatabaseConnection(pool);
|
|
220
|
-
}
|
|
221
|
-
function resolveDatabaseForProperty(property) {
|
|
222
|
-
if (typeof property === "string" && POOL_CONNECTION_METHODS.has(property)) {
|
|
223
|
-
return pool;
|
|
224
|
-
}
|
|
225
|
-
return resolveDatabase();
|
|
226
|
-
}
|
|
227
|
-
return new Proxy(function database() {}, {
|
|
228
|
-
apply(_target, _thisArg, args) {
|
|
229
|
-
return resolveDatabase()(...args);
|
|
230
|
-
},
|
|
231
|
-
get(_target, property) {
|
|
232
|
-
const connection = resolveDatabaseForProperty(property);
|
|
233
|
-
const value = connection[property];
|
|
234
|
-
return typeof value === "function" ? value.bind(connection) : value;
|
|
235
|
-
}
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
// ../../src/core/database/defaultConnection.ts
|
|
240
|
-
var defaultPool = {
|
|
241
|
-
connection: null
|
|
242
|
-
};
|
|
243
|
-
var defaultQuery = {
|
|
244
|
-
connection: null
|
|
245
|
-
};
|
|
246
|
-
function registerDefaultDatabasePool(connection) {
|
|
247
|
-
defaultPool.connection = connection;
|
|
248
|
-
defaultQuery.connection = createDatabaseQueryProxy(connection);
|
|
249
|
-
}
|
|
250
|
-
function getDefaultDatabaseQuery() {
|
|
251
|
-
if (!defaultQuery.connection) {
|
|
252
|
-
throw new Error("Default database query handle is not registered. Call registerDefaultDatabasePool() during app bootstrap.");
|
|
253
|
-
}
|
|
254
|
-
return defaultQuery.connection;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
// ../../src/db/connection/createConnection.ts
|
|
258
|
-
var {SQL } = globalThis.Bun;
|
|
259
|
-
function createDatabaseConnection(config) {
|
|
260
|
-
if (!config.url) {
|
|
261
|
-
throw new Error("DATABASE_URL is not configured. Set DATABASE_URL before starting the app or running integration tests.");
|
|
262
|
-
}
|
|
263
|
-
return new SQL({
|
|
264
|
-
url: config.url,
|
|
265
|
-
max: config.poolMax,
|
|
266
|
-
idleTimeout: config.idleTimeoutSeconds,
|
|
267
|
-
maxLifetime: config.maxLifetimeSeconds,
|
|
268
|
-
connectionTimeout: config.connectionTimeoutSeconds
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
// ../../src/db/connection/index.ts
|
|
273
|
-
var connectionHolder = {
|
|
274
|
-
connection: null
|
|
275
|
-
};
|
|
276
|
-
function getDatabase() {
|
|
277
|
-
if (!connectionHolder.connection) {
|
|
278
|
-
connectionHolder.connection = createDatabaseConnection(databaseConfig);
|
|
279
|
-
registerDefaultDatabasePool(connectionHolder.connection);
|
|
280
|
-
}
|
|
281
|
-
return connectionHolder.connection;
|
|
282
|
-
}
|
|
283
|
-
function getDb() {
|
|
284
|
-
getDatabase();
|
|
285
|
-
return getDefaultDatabaseQuery();
|
|
286
|
-
}
|
|
287
|
-
var db = new Proxy(function database() {}, {
|
|
288
|
-
apply(_target, _thisArg, args) {
|
|
289
|
-
return getDb()(...args);
|
|
290
|
-
},
|
|
291
|
-
get(_target, property) {
|
|
292
|
-
const connection = getDb();
|
|
293
|
-
const value = connection[property];
|
|
294
|
-
return typeof value === "function" ? value.bind(connection) : value;
|
|
295
|
-
}
|
|
296
|
-
});
|
|
297
|
-
var connection_default = db;
|
|
298
|
-
|
|
299
|
-
// ../../src/modules/user/apiTokenTable.ts
|
|
300
|
-
import { defineTable } from "@getstrata/core/database/table";
|
|
301
|
-
var apiTokenTable = defineTable({
|
|
302
|
-
name: "api_token",
|
|
303
|
-
primaryKey: "id",
|
|
304
|
-
columns: [
|
|
305
|
-
"id",
|
|
306
|
-
"user_id",
|
|
307
|
-
"name",
|
|
308
|
-
"token_hash",
|
|
309
|
-
"abilities",
|
|
310
|
-
"last_used_at",
|
|
311
|
-
"expires_at",
|
|
312
|
-
"created_at"
|
|
313
|
-
],
|
|
314
|
-
defaultOrderBy: { column: "id", direction: "ASC" }
|
|
315
|
-
});
|
|
316
|
-
|
|
317
|
-
// ../../src/modules/user/authService.ts
|
|
318
|
-
import { verifyPassword } from "@getstrata/core/auth/password";
|
|
319
|
-
import { revealMfaSecret } from "@getstrata/core/crypto/mfaSecret";
|
|
320
|
-
import { UnauthorizedError } from "@getstrata/core/errors/http";
|
|
321
|
-
import { logSecurityEvent } from "@getstrata/core/security/securityEvents";
|
|
322
|
-
import { resolveDefaultTokenExpiryDays } from "@getstrata/core/security/tokenExpiry";
|
|
323
|
-
import { verifyTotp } from "@getstrata/core/security/totp";
|
|
324
|
-
import { currentTenantId } from "@getstrata/core/tenant/tenantContext";
|
|
325
|
-
|
|
326
|
-
// ../../src/domain/abilities.ts
|
|
327
|
-
var MEMBER_ABILITIES = [
|
|
328
|
-
"organizations:read",
|
|
329
|
-
"projects:read",
|
|
330
|
-
"projects:create",
|
|
331
|
-
"tasks:read",
|
|
332
|
-
"tasks:create",
|
|
333
|
-
"comments:read",
|
|
334
|
-
"comments:create",
|
|
335
|
-
"attachments:read",
|
|
336
|
-
"attachments:create",
|
|
337
|
-
"auth:tokens:read",
|
|
338
|
-
"auth:tokens:write"
|
|
339
|
-
];
|
|
340
|
-
var ADMIN_ABILITIES = [
|
|
341
|
-
...MEMBER_ABILITIES,
|
|
342
|
-
"organizations:create",
|
|
343
|
-
"organizations:update",
|
|
344
|
-
"organizations:delete",
|
|
345
|
-
"projects:update",
|
|
346
|
-
"projects:delete",
|
|
347
|
-
"tasks:update",
|
|
348
|
-
"tasks:delete",
|
|
349
|
-
"comments:update",
|
|
350
|
-
"comments:delete",
|
|
351
|
-
"attachments:delete",
|
|
352
|
-
"webhooks:read",
|
|
353
|
-
"webhooks:write",
|
|
354
|
-
"audit:read"
|
|
355
|
-
];
|
|
356
|
-
var PLATFORM_ADMIN_ABILITIES = ["*"];
|
|
357
|
-
function resolveAbilitiesForRole(role) {
|
|
358
|
-
if (role === "admin") {
|
|
359
|
-
return [...PLATFORM_ADMIN_ABILITIES];
|
|
360
|
-
}
|
|
361
|
-
return [...MEMBER_ABILITIES];
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
// ../../src/modules/user/authService.ts
|
|
365
|
-
class AuthService {
|
|
366
|
-
users;
|
|
367
|
-
tokens;
|
|
368
|
-
oauthIdentities;
|
|
369
|
-
oauthProviders = new Map;
|
|
370
|
-
constructor(users, tokens, oauthIdentities) {
|
|
371
|
-
this.users = users;
|
|
372
|
-
this.tokens = tokens;
|
|
373
|
-
this.oauthIdentities = oauthIdentities;
|
|
374
|
-
}
|
|
375
|
-
registerOAuthProvider(provider) {
|
|
376
|
-
this.oauthProviders.set(provider.name, provider);
|
|
377
|
-
}
|
|
378
|
-
getOAuthProvider(name) {
|
|
379
|
-
return this.oauthProviders.get(name);
|
|
380
|
-
}
|
|
381
|
-
async loginWithPassword(email, password, options = {}) {
|
|
382
|
-
const user = await this.users.findByEmail(email);
|
|
383
|
-
if (!user?.password_hash) {
|
|
384
|
-
logSecurityEvent("auth_login_failed", { reason: "unknown_user", email });
|
|
385
|
-
throw new UnauthorizedError("Invalid credentials.");
|
|
386
|
-
}
|
|
387
|
-
const valid = await verifyPassword(password, user.password_hash);
|
|
388
|
-
if (!valid) {
|
|
389
|
-
logSecurityEvent("auth_login_failed", { reason: "invalid_password", user_id: user.id });
|
|
390
|
-
throw new UnauthorizedError("Invalid credentials.");
|
|
391
|
-
}
|
|
392
|
-
if (isFeatureEnabled("emailVerification") && !user.email_verified_at) {
|
|
393
|
-
logSecurityEvent("auth_login_blocked", { reason: "email_unverified", user_id: user.id });
|
|
394
|
-
throw new UnauthorizedError("Email address is not verified.");
|
|
395
|
-
}
|
|
396
|
-
if (isFeatureEnabled("mfa") && user.mfa_enabled) {
|
|
397
|
-
const mfaSecret = revealMfaSecret(user.mfa_secret);
|
|
398
|
-
if (!mfaSecret || !options.mfaCode || !verifyTotp(mfaSecret, options.mfaCode)) {
|
|
399
|
-
logSecurityEvent("auth_login_failed", { reason: "invalid_mfa", user_id: user.id });
|
|
400
|
-
throw new UnauthorizedError("Invalid MFA code.");
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
logSecurityEvent("auth_login_success", { user_id: user.id, method: "password" });
|
|
404
|
-
return await this.tokens.createToken(user.id, {
|
|
405
|
-
name: "password-login",
|
|
406
|
-
abilities: resolveAbilitiesForRole(user.role),
|
|
407
|
-
expiresInDays: resolveDefaultTokenExpiryDays() ?? undefined
|
|
408
|
-
});
|
|
409
|
-
}
|
|
410
|
-
async loginWithOAuth(providerName, code) {
|
|
411
|
-
const provider = this.oauthProviders.get(providerName);
|
|
412
|
-
if (!provider) {
|
|
413
|
-
throw new UnauthorizedError("Unsupported OAuth provider.");
|
|
414
|
-
}
|
|
415
|
-
const profile = await provider.exchangeCode(code);
|
|
416
|
-
const user = await this.findOrCreateOAuthUser(providerName, profile);
|
|
417
|
-
logSecurityEvent("auth_login_success", { user_id: user.id, method: `oauth:${providerName}` });
|
|
418
|
-
return await this.tokens.createToken(user.id, {
|
|
419
|
-
name: `${providerName}-oauth`,
|
|
420
|
-
abilities: resolveAbilitiesForRole(user.role),
|
|
421
|
-
expiresInDays: resolveDefaultTokenExpiryDays() ?? undefined
|
|
422
|
-
});
|
|
423
|
-
}
|
|
424
|
-
buildOAuthAuthorizationUrl(providerName, state) {
|
|
425
|
-
const provider = this.oauthProviders.get(providerName);
|
|
426
|
-
if (!provider) {
|
|
427
|
-
throw new UnauthorizedError("Unsupported OAuth provider.");
|
|
428
|
-
}
|
|
429
|
-
return provider.getAuthorizationUrl(state);
|
|
430
|
-
}
|
|
431
|
-
async findOrCreateOAuthUser(providerName, profile) {
|
|
432
|
-
const existingIdentity = await this.oauthIdentities.findByProviderUser(providerName, profile.providerUserId);
|
|
433
|
-
if (existingIdentity) {
|
|
434
|
-
return await this.users.findByIdOrThrow(existingIdentity.user_id);
|
|
435
|
-
}
|
|
436
|
-
const existingUser = await this.users.findByEmail(profile.email);
|
|
437
|
-
const user = existingUser ?? await this.users.create({
|
|
438
|
-
name: profile.name,
|
|
439
|
-
email: profile.email,
|
|
440
|
-
role: "member",
|
|
441
|
-
tenant_id: currentTenantId(),
|
|
442
|
-
email_verified_at: new Date,
|
|
443
|
-
created_at: new Date,
|
|
444
|
-
updated_at: new Date
|
|
445
|
-
});
|
|
446
|
-
await this.oauthIdentities.create({
|
|
447
|
-
user_id: user.id,
|
|
448
|
-
provider: providerName,
|
|
449
|
-
provider_user_id: profile.providerUserId,
|
|
450
|
-
email: profile.email,
|
|
451
|
-
created_at: new Date
|
|
452
|
-
});
|
|
453
|
-
return user;
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
// ../../src/modules/user/notificationRepository.ts
|
|
458
|
-
import { BaseRepository as BaseRepository2 } from "@getstrata/core/database/baseRepository";
|
|
459
|
-
|
|
460
|
-
// ../../src/modules/user/notificationTable.ts
|
|
461
|
-
import { defineTable as defineTable2 } from "@getstrata/core/database/table";
|
|
462
|
-
var notificationTable = defineTable2({
|
|
463
|
-
name: "notification",
|
|
464
|
-
primaryKey: "id",
|
|
465
|
-
columns: ["id", "user_id", "tenant_id", "type", "title", "body", "data", "read_at", "created_at"],
|
|
466
|
-
defaultOrderBy: { column: "created_at", direction: "DESC" }
|
|
467
|
-
});
|
|
468
|
-
|
|
469
|
-
// ../../src/modules/user/notificationService.ts
|
|
470
|
-
import { NotFoundError } from "@getstrata/core/errors/http";
|
|
471
|
-
|
|
472
|
-
// ../../src/modules/user/oauthIdentityRepository.ts
|
|
473
|
-
import { BaseRepository as BaseRepository3 } from "@getstrata/core/database/baseRepository";
|
|
474
|
-
import { defineTable as defineTable3 } from "@getstrata/core/database/table";
|
|
475
|
-
var oauthIdentityTable = defineTable3({
|
|
476
|
-
name: "oauth_identity",
|
|
477
|
-
primaryKey: "id",
|
|
478
|
-
columns: ["id", "user_id", "provider", "provider_user_id", "email", "created_at"]
|
|
479
|
-
});
|
|
480
|
-
|
|
481
|
-
// ../../src/modules/user/repository.ts
|
|
482
|
-
import {
|
|
483
|
-
emailLookupForQuery,
|
|
484
|
-
protectEmail,
|
|
485
|
-
revealEmail
|
|
486
|
-
} from "@getstrata/core/crypto/fieldEncryption";
|
|
487
|
-
import { revealMfaSecret as revealMfaSecret2 } from "@getstrata/core/crypto/mfaSecret";
|
|
488
|
-
import { BaseRepository as BaseRepository4 } from "@getstrata/core/database/baseRepository";
|
|
489
|
-
import { currentTenantId as currentTenantId2 } from "@getstrata/core/tenant/tenantContext";
|
|
490
|
-
|
|
491
|
-
// ../../src/modules/user/table.ts
|
|
492
|
-
import { defineTable as defineTable4 } from "@getstrata/core/database/table";
|
|
493
|
-
var userTable = defineTable4({
|
|
494
|
-
name: "users",
|
|
495
|
-
primaryKey: "id",
|
|
496
|
-
columns: [
|
|
497
|
-
"id",
|
|
498
|
-
"name",
|
|
499
|
-
"email",
|
|
500
|
-
"email_lookup",
|
|
501
|
-
"role",
|
|
502
|
-
"tenant_id",
|
|
503
|
-
"password_hash",
|
|
504
|
-
"email_verified_at",
|
|
505
|
-
"mfa_secret",
|
|
506
|
-
"mfa_enabled",
|
|
507
|
-
"created_at",
|
|
508
|
-
"updated_at"
|
|
509
|
-
],
|
|
510
|
-
defaultOrderBy: { column: "id", direction: "ASC" }
|
|
511
|
-
});
|
|
512
|
-
|
|
513
|
-
// ../../src/modules/user/tokenService.ts
|
|
514
|
-
import { hashApiToken } from "@getstrata/core/auth/tokenHash";
|
|
515
|
-
import { ForbiddenError, NotFoundError as NotFoundError2 } from "@getstrata/core/errors/http";
|
|
516
|
-
import { resolveDefaultTokenExpiryDays as resolveDefaultTokenExpiryDays2 } from "@getstrata/core/security/tokenExpiry";
|
|
517
|
-
|
|
518
|
-
// ../../src/modules/user/provider.ts
|
|
519
|
-
var tokenServiceToken = CORE_TOKEN_SERVICE_TOKEN;
|
|
316
|
+
// ../../src/core/contracts/serviceTokens.ts
|
|
317
|
+
var CORE_CONFIG_TOKEN = "core.config";
|
|
318
|
+
var CORE_CACHE_TOKEN = "core.cache";
|
|
319
|
+
var CORE_QUEUE_TOKEN = "core.queue";
|
|
320
|
+
var CORE_EVENT_BUS_TOKEN = "core.eventBus";
|
|
321
|
+
var CORE_POLICY_GATE_TOKEN = "core.policyGate";
|
|
322
|
+
var CORE_AUTH_TOKEN = "core.auth";
|
|
323
|
+
var CORE_TOKEN_SERVICE_TOKEN = "core.tokenService";
|
|
520
324
|
|
|
521
325
|
// ../../src/core/http/csrfToken.ts
|
|
522
326
|
import { timingSafeEqual } from "crypto";
|
|
@@ -549,6 +353,20 @@ function readBunRequestCookie(request, name) {
|
|
|
549
353
|
return request.cookies.get(name) ?? readRequestCookie(request, name);
|
|
550
354
|
}
|
|
551
355
|
|
|
356
|
+
// ../../src/core/runtime/asyncContextStore.ts
|
|
357
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
358
|
+
function createAsyncContextStore(key) {
|
|
359
|
+
const symbol = Symbol.for(key);
|
|
360
|
+
const globalRecord = globalThis;
|
|
361
|
+
const existing = globalRecord[symbol];
|
|
362
|
+
if (existing) {
|
|
363
|
+
return existing;
|
|
364
|
+
}
|
|
365
|
+
const store = new AsyncLocalStorage;
|
|
366
|
+
globalRecord[symbol] = store;
|
|
367
|
+
return store;
|
|
368
|
+
}
|
|
369
|
+
|
|
552
370
|
// ../../src/core/http/requestMetaContext.ts
|
|
553
371
|
var requestMetaContext = createAsyncContextStore("@getstrata/requestMetaContext");
|
|
554
372
|
function runWithRequestMeta(meta, callback) {
|
|
@@ -580,9 +398,10 @@ function tokensMatch(left, right) {
|
|
|
580
398
|
}
|
|
581
399
|
function createCsrfTokenCookie() {
|
|
582
400
|
const token = Bun.CSRF.generate(resolveCsrfSecret(), { expiresIn: CSRF_TTL_MS });
|
|
401
|
+
const secure = process.env.APP_ENV === "production" ? "; Secure" : "";
|
|
583
402
|
return {
|
|
584
403
|
token,
|
|
585
|
-
cookie: `${CSRF_COOKIE}=${encodeURIComponent(token)}; Path=/; SameSite=Lax; Max-Age=${Math.floor(CSRF_TTL_MS / 1000)}`
|
|
404
|
+
cookie: `${CSRF_COOKIE}=${encodeURIComponent(token)}; Path=/; SameSite=Lax; Max-Age=${Math.floor(CSRF_TTL_MS / 1000)}${secure}`
|
|
586
405
|
};
|
|
587
406
|
}
|
|
588
407
|
function resolveCsrfToken(request) {
|
|
@@ -750,7 +569,7 @@ async function resolveWebLayoutData(container, request) {
|
|
|
750
569
|
if (!Number.isInteger(userId) || userId <= 0) {
|
|
751
570
|
return { authUser: null, csrfToken, flash };
|
|
752
571
|
}
|
|
753
|
-
if (!container.has(
|
|
572
|
+
if (!container.has(CORE_TOKEN_SERVICE_TOKEN)) {
|
|
754
573
|
return {
|
|
755
574
|
authUser: {
|
|
756
575
|
id: userId,
|
|
@@ -761,7 +580,7 @@ async function resolveWebLayoutData(container, request) {
|
|
|
761
580
|
flash
|
|
762
581
|
};
|
|
763
582
|
}
|
|
764
|
-
const tokenService = container.resolve(
|
|
583
|
+
const tokenService = container.resolve(CORE_TOKEN_SERVICE_TOKEN);
|
|
765
584
|
try {
|
|
766
585
|
const user = await tokenService.findByIdOrThrow(userId);
|
|
767
586
|
return {
|
|
@@ -822,7 +641,7 @@ function webErrorResponse(error, request) {
|
|
|
822
641
|
return null;
|
|
823
642
|
}
|
|
824
643
|
const mappedError = error instanceof HttpError2 ? error : mapDatabaseError(error);
|
|
825
|
-
if (mappedError instanceof
|
|
644
|
+
if (mappedError instanceof UnauthorizedError) {
|
|
826
645
|
const redirectTarget = encodeURIComponent(new URL(request.url).pathname);
|
|
827
646
|
return Response.redirect(`/login?redirect=${redirectTarget}`, 302);
|
|
828
647
|
}
|
|
@@ -872,9 +691,9 @@ function withErrorHandling(handler) {
|
|
|
872
691
|
};
|
|
873
692
|
}
|
|
874
693
|
export {
|
|
875
|
-
|
|
876
|
-
noContentResponse,
|
|
877
|
-
jsonResponse,
|
|
694
|
+
createdResponse,
|
|
878
695
|
errorResponse,
|
|
879
|
-
|
|
696
|
+
jsonResponse,
|
|
697
|
+
noContentResponse,
|
|
698
|
+
withErrorHandling
|
|
880
699
|
};
|