@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
package/dist/entries/view.js
CHANGED
|
@@ -1,7 +1,182 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// ../../src/core/view/etaViewEngine.ts
|
|
3
|
-
import { join } from "path";
|
|
3
|
+
import { join, relative } from "path";
|
|
4
4
|
import { Eta } from "eta";
|
|
5
|
+
|
|
6
|
+
// ../../src/core/view/assertEtaHtmlSource.ts
|
|
7
|
+
var HTML_TAGS = new Set([
|
|
8
|
+
"a",
|
|
9
|
+
"abbr",
|
|
10
|
+
"address",
|
|
11
|
+
"article",
|
|
12
|
+
"aside",
|
|
13
|
+
"audio",
|
|
14
|
+
"b",
|
|
15
|
+
"blockquote",
|
|
16
|
+
"body",
|
|
17
|
+
"button",
|
|
18
|
+
"canvas",
|
|
19
|
+
"caption",
|
|
20
|
+
"cite",
|
|
21
|
+
"code",
|
|
22
|
+
"col",
|
|
23
|
+
"colgroup",
|
|
24
|
+
"data",
|
|
25
|
+
"datalist",
|
|
26
|
+
"dd",
|
|
27
|
+
"del",
|
|
28
|
+
"details",
|
|
29
|
+
"dfn",
|
|
30
|
+
"dialog",
|
|
31
|
+
"div",
|
|
32
|
+
"dl",
|
|
33
|
+
"dt",
|
|
34
|
+
"em",
|
|
35
|
+
"fieldset",
|
|
36
|
+
"figcaption",
|
|
37
|
+
"figure",
|
|
38
|
+
"footer",
|
|
39
|
+
"form",
|
|
40
|
+
"h1",
|
|
41
|
+
"h2",
|
|
42
|
+
"h3",
|
|
43
|
+
"h4",
|
|
44
|
+
"h5",
|
|
45
|
+
"h6",
|
|
46
|
+
"header",
|
|
47
|
+
"hgroup",
|
|
48
|
+
"hr",
|
|
49
|
+
"html",
|
|
50
|
+
"i",
|
|
51
|
+
"iframe",
|
|
52
|
+
"img",
|
|
53
|
+
"input",
|
|
54
|
+
"ins",
|
|
55
|
+
"kbd",
|
|
56
|
+
"label",
|
|
57
|
+
"legend",
|
|
58
|
+
"li",
|
|
59
|
+
"main",
|
|
60
|
+
"map",
|
|
61
|
+
"mark",
|
|
62
|
+
"menu",
|
|
63
|
+
"meter",
|
|
64
|
+
"nav",
|
|
65
|
+
"object",
|
|
66
|
+
"ol",
|
|
67
|
+
"optgroup",
|
|
68
|
+
"option",
|
|
69
|
+
"output",
|
|
70
|
+
"p",
|
|
71
|
+
"picture",
|
|
72
|
+
"pre",
|
|
73
|
+
"progress",
|
|
74
|
+
"q",
|
|
75
|
+
"rp",
|
|
76
|
+
"rt",
|
|
77
|
+
"ruby",
|
|
78
|
+
"s",
|
|
79
|
+
"samp",
|
|
80
|
+
"script",
|
|
81
|
+
"search",
|
|
82
|
+
"section",
|
|
83
|
+
"select",
|
|
84
|
+
"slot",
|
|
85
|
+
"small",
|
|
86
|
+
"source",
|
|
87
|
+
"span",
|
|
88
|
+
"strong",
|
|
89
|
+
"style",
|
|
90
|
+
"sub",
|
|
91
|
+
"summary",
|
|
92
|
+
"sup",
|
|
93
|
+
"table",
|
|
94
|
+
"tbody",
|
|
95
|
+
"td",
|
|
96
|
+
"template",
|
|
97
|
+
"textarea",
|
|
98
|
+
"tfoot",
|
|
99
|
+
"th",
|
|
100
|
+
"thead",
|
|
101
|
+
"time",
|
|
102
|
+
"title",
|
|
103
|
+
"tr",
|
|
104
|
+
"track",
|
|
105
|
+
"u",
|
|
106
|
+
"ul",
|
|
107
|
+
"var",
|
|
108
|
+
"video",
|
|
109
|
+
"wbr"
|
|
110
|
+
]);
|
|
111
|
+
var TAG_PATTERN = "([a-z][a-z0-9]*)";
|
|
112
|
+
var CLASS_OR_ID_PATTERN = "[.#][\\w-]+";
|
|
113
|
+
var CLASS_ID_SHORTHAND = new RegExp(`^${TAG_PATTERN}(?:${CLASS_OR_ID_PATTERN})+`);
|
|
114
|
+
var ATTRIBUTE_SHORTHAND = new RegExp(`^${TAG_PATTERN}(?:${CLASS_OR_ID_PATTERN})*\\s+[\\w:-]+=`);
|
|
115
|
+
var TAG_SHORTHAND = new RegExp(`^${TAG_PATTERN}(?:>|\\s+\\S|$)`);
|
|
116
|
+
function htmlTagName(match) {
|
|
117
|
+
const tag = match?.[1];
|
|
118
|
+
return tag && HTML_TAGS.has(tag) ? tag : undefined;
|
|
119
|
+
}
|
|
120
|
+
function describePugLikeLine(line) {
|
|
121
|
+
if (/^\|(?:\s|$)/.test(line)) {
|
|
122
|
+
return "piped text";
|
|
123
|
+
}
|
|
124
|
+
if (htmlTagName(line.match(CLASS_ID_SHORTHAND))) {
|
|
125
|
+
return "class/id shorthand";
|
|
126
|
+
}
|
|
127
|
+
if (htmlTagName(line.match(ATTRIBUTE_SHORTHAND))) {
|
|
128
|
+
return "attribute shorthand";
|
|
129
|
+
}
|
|
130
|
+
if (htmlTagName(line.match(TAG_SHORTHAND))) {
|
|
131
|
+
return "tag shorthand";
|
|
132
|
+
}
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
function updateSkipBlock(lower, skipBlock) {
|
|
136
|
+
if (skipBlock) {
|
|
137
|
+
if (skipBlock === "comment" && lower.includes("-->")) {
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
if (skipBlock !== "comment" && lower.includes(`</${skipBlock}`)) {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
return skipBlock;
|
|
144
|
+
}
|
|
145
|
+
if (lower.startsWith("<!--") && !lower.includes("-->")) {
|
|
146
|
+
return "comment";
|
|
147
|
+
}
|
|
148
|
+
if (lower.startsWith("<script") && !lower.includes("</script")) {
|
|
149
|
+
return "script";
|
|
150
|
+
}
|
|
151
|
+
if (lower.startsWith("<style") && !lower.includes("</style")) {
|
|
152
|
+
return "style";
|
|
153
|
+
}
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
function assertEtaHtmlSource(templateName, source) {
|
|
157
|
+
let skipBlock = null;
|
|
158
|
+
for (const rawLine of source.split(/\r?\n/)) {
|
|
159
|
+
const trimmed = rawLine.trim();
|
|
160
|
+
if (!trimmed) {
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
const lower = trimmed.toLowerCase();
|
|
164
|
+
const nextSkipBlock = updateSkipBlock(lower, skipBlock);
|
|
165
|
+
if (skipBlock || nextSkipBlock) {
|
|
166
|
+
skipBlock = nextSkipBlock;
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
if (trimmed.startsWith("<") || trimmed.startsWith("<%")) {
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
const kind = describePugLikeLine(trimmed);
|
|
173
|
+
if (kind) {
|
|
174
|
+
throw new Error(`Eta view "${templateName}" contains Pug-like markup (${kind}: ${trimmed}). Eta views must be HTML + <% %> tags, not Pug.`);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// ../../src/core/view/etaViewEngine.ts
|
|
5
180
|
var DEFAULT_VIEWS_DIRECTORY = join(process.cwd(), "resources/views");
|
|
6
181
|
var DEFAULT_LAYOUT = "layouts/app.eta";
|
|
7
182
|
|
|
@@ -14,6 +189,12 @@ class EtaViewEngine {
|
|
|
14
189
|
autoTrim: false
|
|
15
190
|
});
|
|
16
191
|
this.resolveLayoutData = resolveLayoutData;
|
|
192
|
+
const readFile = this.eta.readFile?.bind(this.eta);
|
|
193
|
+
this.eta.readFile = (path) => {
|
|
194
|
+
const source = readFile ? readFile(path) : "";
|
|
195
|
+
assertEtaHtmlSource(relative(viewsDirectory, path) || path, source);
|
|
196
|
+
return source;
|
|
197
|
+
};
|
|
17
198
|
}
|
|
18
199
|
async render(name, data = {}, options = {}) {
|
|
19
200
|
const template = name.endsWith(".eta") ? name : `${name}.eta`;
|
|
@@ -48,391 +229,14 @@ function isHtmxRequest(request) {
|
|
|
48
229
|
import { currentAuthUser } from "@getstrata/core/auth/authContext";
|
|
49
230
|
import { currentRequestMeta as currentRequestMeta2 } from "@getstrata/core/http/requestMetaContext";
|
|
50
231
|
|
|
51
|
-
// ../../src/
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
CORE_TOKEN_SERVICE_TOKEN
|
|
60
|
-
} from "@getstrata/core/contracts/serviceTokens";
|
|
61
|
-
var DEFAULT_QUEUE_DRIVER = "sync";
|
|
62
|
-
|
|
63
|
-
// ../../src/modules/user/provider.ts
|
|
64
|
-
import { OidcProvider } from "@getstrata/core/auth/oauth/oidcProvider";
|
|
65
|
-
import { GitHubOAuthProvider, MockOAuthProvider } from "@getstrata/core/auth/oauth/providers";
|
|
66
|
-
import { SamlProvider } from "@getstrata/core/auth/oauth/samlProvider";
|
|
67
|
-
|
|
68
|
-
// ../../src/config/features.ts
|
|
69
|
-
function readFeatureFlags() {
|
|
70
|
-
return {
|
|
71
|
-
webhooks: (process.env.FEATURE_WEBHOOKS ?? "true") !== "false",
|
|
72
|
-
fullTextSearch: (process.env.FEATURE_SEARCH ?? "true") !== "false",
|
|
73
|
-
auditLog: (process.env.FEATURE_AUDIT_LOG ?? "true") !== "false",
|
|
74
|
-
oauthLogin: (process.env.FEATURE_OAUTH ?? "true") !== "false",
|
|
75
|
-
samlLogin: (process.env.FEATURE_SAML ?? "false") === "true",
|
|
76
|
-
scim: (process.env.FEATURE_SCIM ?? "true") !== "false",
|
|
77
|
-
billing: (process.env.FEATURE_BILLING ?? "true") !== "false",
|
|
78
|
-
siemExport: (process.env.FEATURE_SIEM_EXPORT ?? "true") !== "false",
|
|
79
|
-
publicReads: (process.env.FEATURE_PUBLIC_READS ?? "true") !== "false",
|
|
80
|
-
emailVerification: (process.env.FEATURE_EMAIL_VERIFICATION ?? "false") === "true",
|
|
81
|
-
mfa: (process.env.FEATURE_MFA ?? "false") === "true"
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
var featureFlags = readFeatureFlags();
|
|
85
|
-
function isFeatureEnabled(feature) {
|
|
86
|
-
return readFeatureFlags()[feature];
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// ../../src/modules/user/apiTokenRepository.ts
|
|
90
|
-
import { BaseRepository } from "@getstrata/core/database/baseRepository";
|
|
91
|
-
|
|
92
|
-
// ../../src/config/database.ts
|
|
93
|
-
function readInteger(name, fallback) {
|
|
94
|
-
const parsed = Number.parseInt(process.env[name] ?? String(fallback), 10);
|
|
95
|
-
return Number.isInteger(parsed) && parsed >= 0 ? parsed : fallback;
|
|
96
|
-
}
|
|
97
|
-
var databaseConfig = {
|
|
98
|
-
url: process.env.DATABASE_URL ?? "",
|
|
99
|
-
poolMax: readInteger("DB_POOL_MAX", 10),
|
|
100
|
-
idleTimeoutSeconds: readInteger("DB_POOL_IDLE_TIMEOUT", 30),
|
|
101
|
-
maxLifetimeSeconds: readInteger("DB_POOL_MAX_LIFETIME", 3600),
|
|
102
|
-
connectionTimeoutSeconds: readInteger("DB_CONNECTION_TIMEOUT", 10)
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
// ../../src/core/runtime/asyncContextStore.ts
|
|
106
|
-
import { AsyncLocalStorage } from "async_hooks";
|
|
107
|
-
function createAsyncContextStore(key) {
|
|
108
|
-
const symbol = Symbol.for(key);
|
|
109
|
-
const globalRecord = globalThis;
|
|
110
|
-
const existing = globalRecord[symbol];
|
|
111
|
-
if (existing) {
|
|
112
|
-
return existing;
|
|
113
|
-
}
|
|
114
|
-
const store = new AsyncLocalStorage;
|
|
115
|
-
globalRecord[symbol] = store;
|
|
116
|
-
return store;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// ../../src/core/database/connectionContext.ts
|
|
120
|
-
var activeConnection = createAsyncContextStore("@getstrata/databaseConnectionContext");
|
|
121
|
-
function runWithDatabaseConnection(connection, callback) {
|
|
122
|
-
return activeConnection.run(connection, callback);
|
|
123
|
-
}
|
|
124
|
-
function getActiveDatabaseConnection(fallback) {
|
|
125
|
-
return activeConnection.getStore() ?? fallback;
|
|
126
|
-
}
|
|
127
|
-
function hasActiveDatabaseConnection() {
|
|
128
|
-
return activeConnection.getStore() !== undefined;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// ../../src/core/database/queryProxy.ts
|
|
132
|
-
var POOL_CONNECTION_METHODS = new Set(["begin", "close", "connect"]);
|
|
133
|
-
function createDatabaseQueryProxy(pool) {
|
|
134
|
-
function resolveDatabase() {
|
|
135
|
-
return getActiveDatabaseConnection(pool);
|
|
136
|
-
}
|
|
137
|
-
function resolveDatabaseForProperty(property) {
|
|
138
|
-
if (typeof property === "string" && POOL_CONNECTION_METHODS.has(property)) {
|
|
139
|
-
return pool;
|
|
140
|
-
}
|
|
141
|
-
return resolveDatabase();
|
|
142
|
-
}
|
|
143
|
-
return new Proxy(function database() {}, {
|
|
144
|
-
apply(_target, _thisArg, args) {
|
|
145
|
-
return resolveDatabase()(...args);
|
|
146
|
-
},
|
|
147
|
-
get(_target, property) {
|
|
148
|
-
const connection = resolveDatabaseForProperty(property);
|
|
149
|
-
const value = connection[property];
|
|
150
|
-
return typeof value === "function" ? value.bind(connection) : value;
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// ../../src/core/database/defaultConnection.ts
|
|
156
|
-
var defaultPool = {
|
|
157
|
-
connection: null
|
|
158
|
-
};
|
|
159
|
-
var defaultQuery = {
|
|
160
|
-
connection: null
|
|
161
|
-
};
|
|
162
|
-
function registerDefaultDatabasePool(connection) {
|
|
163
|
-
defaultPool.connection = connection;
|
|
164
|
-
defaultQuery.connection = createDatabaseQueryProxy(connection);
|
|
165
|
-
}
|
|
166
|
-
function getDefaultDatabaseQuery() {
|
|
167
|
-
if (!defaultQuery.connection) {
|
|
168
|
-
throw new Error("Default database query handle is not registered. Call registerDefaultDatabasePool() during app bootstrap.");
|
|
169
|
-
}
|
|
170
|
-
return defaultQuery.connection;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// ../../src/db/connection/createConnection.ts
|
|
174
|
-
var {SQL } = globalThis.Bun;
|
|
175
|
-
function createDatabaseConnection(config) {
|
|
176
|
-
if (!config.url) {
|
|
177
|
-
throw new Error("DATABASE_URL is not configured. Set DATABASE_URL before starting the app or running integration tests.");
|
|
178
|
-
}
|
|
179
|
-
return new SQL({
|
|
180
|
-
url: config.url,
|
|
181
|
-
max: config.poolMax,
|
|
182
|
-
idleTimeout: config.idleTimeoutSeconds,
|
|
183
|
-
maxLifetime: config.maxLifetimeSeconds,
|
|
184
|
-
connectionTimeout: config.connectionTimeoutSeconds
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
// ../../src/db/connection/index.ts
|
|
189
|
-
var connectionHolder = {
|
|
190
|
-
connection: null
|
|
191
|
-
};
|
|
192
|
-
function getDatabase() {
|
|
193
|
-
if (!connectionHolder.connection) {
|
|
194
|
-
connectionHolder.connection = createDatabaseConnection(databaseConfig);
|
|
195
|
-
registerDefaultDatabasePool(connectionHolder.connection);
|
|
196
|
-
}
|
|
197
|
-
return connectionHolder.connection;
|
|
198
|
-
}
|
|
199
|
-
function getDb() {
|
|
200
|
-
getDatabase();
|
|
201
|
-
return getDefaultDatabaseQuery();
|
|
202
|
-
}
|
|
203
|
-
var db = new Proxy(function database() {}, {
|
|
204
|
-
apply(_target, _thisArg, args) {
|
|
205
|
-
return getDb()(...args);
|
|
206
|
-
},
|
|
207
|
-
get(_target, property) {
|
|
208
|
-
const connection = getDb();
|
|
209
|
-
const value = connection[property];
|
|
210
|
-
return typeof value === "function" ? value.bind(connection) : value;
|
|
211
|
-
}
|
|
212
|
-
});
|
|
213
|
-
var connection_default = db;
|
|
214
|
-
|
|
215
|
-
// ../../src/modules/user/apiTokenTable.ts
|
|
216
|
-
import { defineTable } from "@getstrata/core/database/table";
|
|
217
|
-
var apiTokenTable = defineTable({
|
|
218
|
-
name: "api_token",
|
|
219
|
-
primaryKey: "id",
|
|
220
|
-
columns: [
|
|
221
|
-
"id",
|
|
222
|
-
"user_id",
|
|
223
|
-
"name",
|
|
224
|
-
"token_hash",
|
|
225
|
-
"abilities",
|
|
226
|
-
"last_used_at",
|
|
227
|
-
"expires_at",
|
|
228
|
-
"created_at"
|
|
229
|
-
],
|
|
230
|
-
defaultOrderBy: { column: "id", direction: "ASC" }
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
// ../../src/modules/user/authService.ts
|
|
234
|
-
import { verifyPassword } from "@getstrata/core/auth/password";
|
|
235
|
-
import { revealMfaSecret } from "@getstrata/core/crypto/mfaSecret";
|
|
236
|
-
import { UnauthorizedError } from "@getstrata/core/errors/http";
|
|
237
|
-
import { logSecurityEvent } from "@getstrata/core/security/securityEvents";
|
|
238
|
-
import { resolveDefaultTokenExpiryDays } from "@getstrata/core/security/tokenExpiry";
|
|
239
|
-
import { verifyTotp } from "@getstrata/core/security/totp";
|
|
240
|
-
import { currentTenantId } from "@getstrata/core/tenant/tenantContext";
|
|
241
|
-
|
|
242
|
-
// ../../src/domain/abilities.ts
|
|
243
|
-
var MEMBER_ABILITIES = [
|
|
244
|
-
"organizations:read",
|
|
245
|
-
"projects:read",
|
|
246
|
-
"projects:create",
|
|
247
|
-
"tasks:read",
|
|
248
|
-
"tasks:create",
|
|
249
|
-
"comments:read",
|
|
250
|
-
"comments:create",
|
|
251
|
-
"attachments:read",
|
|
252
|
-
"attachments:create",
|
|
253
|
-
"auth:tokens:read",
|
|
254
|
-
"auth:tokens:write"
|
|
255
|
-
];
|
|
256
|
-
var ADMIN_ABILITIES = [
|
|
257
|
-
...MEMBER_ABILITIES,
|
|
258
|
-
"organizations:create",
|
|
259
|
-
"organizations:update",
|
|
260
|
-
"organizations:delete",
|
|
261
|
-
"projects:update",
|
|
262
|
-
"projects:delete",
|
|
263
|
-
"tasks:update",
|
|
264
|
-
"tasks:delete",
|
|
265
|
-
"comments:update",
|
|
266
|
-
"comments:delete",
|
|
267
|
-
"attachments:delete",
|
|
268
|
-
"webhooks:read",
|
|
269
|
-
"webhooks:write",
|
|
270
|
-
"audit:read"
|
|
271
|
-
];
|
|
272
|
-
var PLATFORM_ADMIN_ABILITIES = ["*"];
|
|
273
|
-
function resolveAbilitiesForRole(role) {
|
|
274
|
-
if (role === "admin") {
|
|
275
|
-
return [...PLATFORM_ADMIN_ABILITIES];
|
|
276
|
-
}
|
|
277
|
-
return [...MEMBER_ABILITIES];
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
// ../../src/modules/user/authService.ts
|
|
281
|
-
class AuthService {
|
|
282
|
-
users;
|
|
283
|
-
tokens;
|
|
284
|
-
oauthIdentities;
|
|
285
|
-
oauthProviders = new Map;
|
|
286
|
-
constructor(users, tokens, oauthIdentities) {
|
|
287
|
-
this.users = users;
|
|
288
|
-
this.tokens = tokens;
|
|
289
|
-
this.oauthIdentities = oauthIdentities;
|
|
290
|
-
}
|
|
291
|
-
registerOAuthProvider(provider) {
|
|
292
|
-
this.oauthProviders.set(provider.name, provider);
|
|
293
|
-
}
|
|
294
|
-
getOAuthProvider(name) {
|
|
295
|
-
return this.oauthProviders.get(name);
|
|
296
|
-
}
|
|
297
|
-
async loginWithPassword(email, password, options = {}) {
|
|
298
|
-
const user = await this.users.findByEmail(email);
|
|
299
|
-
if (!user?.password_hash) {
|
|
300
|
-
logSecurityEvent("auth_login_failed", { reason: "unknown_user", email });
|
|
301
|
-
throw new UnauthorizedError("Invalid credentials.");
|
|
302
|
-
}
|
|
303
|
-
const valid = await verifyPassword(password, user.password_hash);
|
|
304
|
-
if (!valid) {
|
|
305
|
-
logSecurityEvent("auth_login_failed", { reason: "invalid_password", user_id: user.id });
|
|
306
|
-
throw new UnauthorizedError("Invalid credentials.");
|
|
307
|
-
}
|
|
308
|
-
if (isFeatureEnabled("emailVerification") && !user.email_verified_at) {
|
|
309
|
-
logSecurityEvent("auth_login_blocked", { reason: "email_unverified", user_id: user.id });
|
|
310
|
-
throw new UnauthorizedError("Email address is not verified.");
|
|
311
|
-
}
|
|
312
|
-
if (isFeatureEnabled("mfa") && user.mfa_enabled) {
|
|
313
|
-
const mfaSecret = revealMfaSecret(user.mfa_secret);
|
|
314
|
-
if (!mfaSecret || !options.mfaCode || !verifyTotp(mfaSecret, options.mfaCode)) {
|
|
315
|
-
logSecurityEvent("auth_login_failed", { reason: "invalid_mfa", user_id: user.id });
|
|
316
|
-
throw new UnauthorizedError("Invalid MFA code.");
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
logSecurityEvent("auth_login_success", { user_id: user.id, method: "password" });
|
|
320
|
-
return await this.tokens.createToken(user.id, {
|
|
321
|
-
name: "password-login",
|
|
322
|
-
abilities: resolveAbilitiesForRole(user.role),
|
|
323
|
-
expiresInDays: resolveDefaultTokenExpiryDays() ?? undefined
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
async loginWithOAuth(providerName, code) {
|
|
327
|
-
const provider = this.oauthProviders.get(providerName);
|
|
328
|
-
if (!provider) {
|
|
329
|
-
throw new UnauthorizedError("Unsupported OAuth provider.");
|
|
330
|
-
}
|
|
331
|
-
const profile = await provider.exchangeCode(code);
|
|
332
|
-
const user = await this.findOrCreateOAuthUser(providerName, profile);
|
|
333
|
-
logSecurityEvent("auth_login_success", { user_id: user.id, method: `oauth:${providerName}` });
|
|
334
|
-
return await this.tokens.createToken(user.id, {
|
|
335
|
-
name: `${providerName}-oauth`,
|
|
336
|
-
abilities: resolveAbilitiesForRole(user.role),
|
|
337
|
-
expiresInDays: resolveDefaultTokenExpiryDays() ?? undefined
|
|
338
|
-
});
|
|
339
|
-
}
|
|
340
|
-
buildOAuthAuthorizationUrl(providerName, state) {
|
|
341
|
-
const provider = this.oauthProviders.get(providerName);
|
|
342
|
-
if (!provider) {
|
|
343
|
-
throw new UnauthorizedError("Unsupported OAuth provider.");
|
|
344
|
-
}
|
|
345
|
-
return provider.getAuthorizationUrl(state);
|
|
346
|
-
}
|
|
347
|
-
async findOrCreateOAuthUser(providerName, profile) {
|
|
348
|
-
const existingIdentity = await this.oauthIdentities.findByProviderUser(providerName, profile.providerUserId);
|
|
349
|
-
if (existingIdentity) {
|
|
350
|
-
return await this.users.findByIdOrThrow(existingIdentity.user_id);
|
|
351
|
-
}
|
|
352
|
-
const existingUser = await this.users.findByEmail(profile.email);
|
|
353
|
-
const user = existingUser ?? await this.users.create({
|
|
354
|
-
name: profile.name,
|
|
355
|
-
email: profile.email,
|
|
356
|
-
role: "member",
|
|
357
|
-
tenant_id: currentTenantId(),
|
|
358
|
-
email_verified_at: new Date,
|
|
359
|
-
created_at: new Date,
|
|
360
|
-
updated_at: new Date
|
|
361
|
-
});
|
|
362
|
-
await this.oauthIdentities.create({
|
|
363
|
-
user_id: user.id,
|
|
364
|
-
provider: providerName,
|
|
365
|
-
provider_user_id: profile.providerUserId,
|
|
366
|
-
email: profile.email,
|
|
367
|
-
created_at: new Date
|
|
368
|
-
});
|
|
369
|
-
return user;
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
// ../../src/modules/user/notificationRepository.ts
|
|
374
|
-
import { BaseRepository as BaseRepository2 } from "@getstrata/core/database/baseRepository";
|
|
375
|
-
|
|
376
|
-
// ../../src/modules/user/notificationTable.ts
|
|
377
|
-
import { defineTable as defineTable2 } from "@getstrata/core/database/table";
|
|
378
|
-
var notificationTable = defineTable2({
|
|
379
|
-
name: "notification",
|
|
380
|
-
primaryKey: "id",
|
|
381
|
-
columns: ["id", "user_id", "tenant_id", "type", "title", "body", "data", "read_at", "created_at"],
|
|
382
|
-
defaultOrderBy: { column: "created_at", direction: "DESC" }
|
|
383
|
-
});
|
|
384
|
-
|
|
385
|
-
// ../../src/modules/user/notificationService.ts
|
|
386
|
-
import { NotFoundError } from "@getstrata/core/errors/http";
|
|
387
|
-
|
|
388
|
-
// ../../src/modules/user/oauthIdentityRepository.ts
|
|
389
|
-
import { BaseRepository as BaseRepository3 } from "@getstrata/core/database/baseRepository";
|
|
390
|
-
import { defineTable as defineTable3 } from "@getstrata/core/database/table";
|
|
391
|
-
var oauthIdentityTable = defineTable3({
|
|
392
|
-
name: "oauth_identity",
|
|
393
|
-
primaryKey: "id",
|
|
394
|
-
columns: ["id", "user_id", "provider", "provider_user_id", "email", "created_at"]
|
|
395
|
-
});
|
|
396
|
-
|
|
397
|
-
// ../../src/modules/user/repository.ts
|
|
398
|
-
import {
|
|
399
|
-
emailLookupForQuery,
|
|
400
|
-
protectEmail,
|
|
401
|
-
revealEmail
|
|
402
|
-
} from "@getstrata/core/crypto/fieldEncryption";
|
|
403
|
-
import { revealMfaSecret as revealMfaSecret2 } from "@getstrata/core/crypto/mfaSecret";
|
|
404
|
-
import { BaseRepository as BaseRepository4 } from "@getstrata/core/database/baseRepository";
|
|
405
|
-
import { currentTenantId as currentTenantId2 } from "@getstrata/core/tenant/tenantContext";
|
|
406
|
-
|
|
407
|
-
// ../../src/modules/user/table.ts
|
|
408
|
-
import { defineTable as defineTable4 } from "@getstrata/core/database/table";
|
|
409
|
-
var userTable = defineTable4({
|
|
410
|
-
name: "users",
|
|
411
|
-
primaryKey: "id",
|
|
412
|
-
columns: [
|
|
413
|
-
"id",
|
|
414
|
-
"name",
|
|
415
|
-
"email",
|
|
416
|
-
"email_lookup",
|
|
417
|
-
"role",
|
|
418
|
-
"tenant_id",
|
|
419
|
-
"password_hash",
|
|
420
|
-
"email_verified_at",
|
|
421
|
-
"mfa_secret",
|
|
422
|
-
"mfa_enabled",
|
|
423
|
-
"created_at",
|
|
424
|
-
"updated_at"
|
|
425
|
-
],
|
|
426
|
-
defaultOrderBy: { column: "id", direction: "ASC" }
|
|
427
|
-
});
|
|
428
|
-
|
|
429
|
-
// ../../src/modules/user/tokenService.ts
|
|
430
|
-
import { hashApiToken } from "@getstrata/core/auth/tokenHash";
|
|
431
|
-
import { ForbiddenError, NotFoundError as NotFoundError2 } from "@getstrata/core/errors/http";
|
|
432
|
-
import { resolveDefaultTokenExpiryDays as resolveDefaultTokenExpiryDays2 } from "@getstrata/core/security/tokenExpiry";
|
|
433
|
-
|
|
434
|
-
// ../../src/modules/user/provider.ts
|
|
435
|
-
var tokenServiceToken = CORE_TOKEN_SERVICE_TOKEN;
|
|
232
|
+
// ../../src/core/contracts/serviceTokens.ts
|
|
233
|
+
var CORE_CONFIG_TOKEN = "core.config";
|
|
234
|
+
var CORE_CACHE_TOKEN = "core.cache";
|
|
235
|
+
var CORE_QUEUE_TOKEN = "core.queue";
|
|
236
|
+
var CORE_EVENT_BUS_TOKEN = "core.eventBus";
|
|
237
|
+
var CORE_POLICY_GATE_TOKEN = "core.policyGate";
|
|
238
|
+
var CORE_AUTH_TOKEN = "core.auth";
|
|
239
|
+
var CORE_TOKEN_SERVICE_TOKEN = "core.tokenService";
|
|
436
240
|
|
|
437
241
|
// ../../src/core/http/csrfToken.ts
|
|
438
242
|
import { timingSafeEqual } from "crypto";
|
|
@@ -465,6 +269,20 @@ function readBunRequestCookie(request, name) {
|
|
|
465
269
|
return request.cookies.get(name) ?? readRequestCookie(request, name);
|
|
466
270
|
}
|
|
467
271
|
|
|
272
|
+
// ../../src/core/runtime/asyncContextStore.ts
|
|
273
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
274
|
+
function createAsyncContextStore(key) {
|
|
275
|
+
const symbol = Symbol.for(key);
|
|
276
|
+
const globalRecord = globalThis;
|
|
277
|
+
const existing = globalRecord[symbol];
|
|
278
|
+
if (existing) {
|
|
279
|
+
return existing;
|
|
280
|
+
}
|
|
281
|
+
const store = new AsyncLocalStorage;
|
|
282
|
+
globalRecord[symbol] = store;
|
|
283
|
+
return store;
|
|
284
|
+
}
|
|
285
|
+
|
|
468
286
|
// ../../src/core/http/requestMetaContext.ts
|
|
469
287
|
var requestMetaContext = createAsyncContextStore("@getstrata/requestMetaContext");
|
|
470
288
|
function runWithRequestMeta(meta, callback) {
|
|
@@ -496,9 +314,10 @@ function tokensMatch(left, right) {
|
|
|
496
314
|
}
|
|
497
315
|
function createCsrfTokenCookie() {
|
|
498
316
|
const token = Bun.CSRF.generate(resolveCsrfSecret(), { expiresIn: CSRF_TTL_MS });
|
|
317
|
+
const secure = process.env.APP_ENV === "production" ? "; Secure" : "";
|
|
499
318
|
return {
|
|
500
319
|
token,
|
|
501
|
-
cookie: `${CSRF_COOKIE}=${encodeURIComponent(token)}; Path=/; SameSite=Lax; Max-Age=${Math.floor(CSRF_TTL_MS / 1000)}`
|
|
320
|
+
cookie: `${CSRF_COOKIE}=${encodeURIComponent(token)}; Path=/; SameSite=Lax; Max-Age=${Math.floor(CSRF_TTL_MS / 1000)}${secure}`
|
|
502
321
|
};
|
|
503
322
|
}
|
|
504
323
|
function resolveCsrfToken(request) {
|
|
@@ -666,7 +485,7 @@ async function resolveWebLayoutData(container, request) {
|
|
|
666
485
|
if (!Number.isInteger(userId) || userId <= 0) {
|
|
667
486
|
return { authUser: null, csrfToken, flash };
|
|
668
487
|
}
|
|
669
|
-
if (!container.has(
|
|
488
|
+
if (!container.has(CORE_TOKEN_SERVICE_TOKEN)) {
|
|
670
489
|
return {
|
|
671
490
|
authUser: {
|
|
672
491
|
id: userId,
|
|
@@ -677,7 +496,7 @@ async function resolveWebLayoutData(container, request) {
|
|
|
677
496
|
flash
|
|
678
497
|
};
|
|
679
498
|
}
|
|
680
|
-
const tokenService = container.resolve(
|
|
499
|
+
const tokenService = container.resolve(CORE_TOKEN_SERVICE_TOKEN);
|
|
681
500
|
try {
|
|
682
501
|
const user = await tokenService.findByIdOrThrow(userId);
|
|
683
502
|
return {
|
|
@@ -694,9 +513,9 @@ async function resolveWebLayoutData(container, request) {
|
|
|
694
513
|
}
|
|
695
514
|
}
|
|
696
515
|
export {
|
|
697
|
-
|
|
698
|
-
isHtmxRequest,
|
|
699
|
-
htmlResponse,
|
|
516
|
+
DEFAULT_VIEWS_DIRECTORY,
|
|
700
517
|
EtaViewEngine,
|
|
701
|
-
|
|
518
|
+
htmlResponse,
|
|
519
|
+
isHtmxRequest,
|
|
520
|
+
resolveWebLayoutData
|
|
702
521
|
};
|
|
@@ -10,7 +10,7 @@ export type { AuthUser } from "../core/auth/authContext.ts";
|
|
|
10
10
|
export { authContext, currentAuthUser, runWithAuthUser } from "../core/auth/authContext.ts";
|
|
11
11
|
export type { AuthGuard } from "../core/auth/guard.ts";
|
|
12
12
|
export { ApiTokenGuard, AuthManager, CompositeGuard, DatabaseTokenGuard, GuestGuard, } from "../core/auth/guard.ts";
|
|
13
|
-
export { currentOrganizationIds, currentOrgRole, hasMinimumOrgRole, hasOrgMembership, } from "../core/auth/membershipContext.ts";
|
|
13
|
+
export { configureMembershipLookup, currentOrganizationIds, currentOrgRole, hasMinimumOrgRole, hasOrgMembership, } from "../core/auth/membershipContext.ts";
|
|
14
14
|
export { createMembershipMiddleware } from "../core/auth/membershipMiddleware.ts";
|
|
15
15
|
export { appendOrganizationScope, appendProjectScope, assertOrganizationReadable, assertResourceInCurrentTenant, emptyPaginateResult, resolveOrganizationScope, scopedOrganizationIds, } from "../core/auth/membershipScope.ts";
|
|
16
16
|
export { default as MembershipService, resolveMembershipService, } from "../core/auth/membershipService.ts";
|
|
@@ -53,6 +53,7 @@ export { EventBus, eventBus } from "../core/events/eventBus.ts";
|
|
|
53
53
|
export { modelEventName } from "../core/events/index.ts";
|
|
54
54
|
export { auth, cache, config, events, log, mail, policyGate, queue, storage, } from "../core/facades/index.ts";
|
|
55
55
|
export { createBodySizeLimitMiddleware } from "../core/http/bodySizeLimitMiddleware.ts";
|
|
56
|
+
export { readClientIp, trustForwardedFor } from "../core/http/clientIp.ts";
|
|
56
57
|
export { conditionalJsonResponse } from "../core/http/conditionalResponse.ts";
|
|
57
58
|
export { readBunRequestCookie, readRequestCookie } from "../core/http/cookies.ts";
|
|
58
59
|
export { createCorsMiddleware } from "../core/http/corsMiddleware.ts";
|
|
@@ -106,6 +107,8 @@ export type { SecurityEventDetails } from "../core/security/securityEvents.ts";
|
|
|
106
107
|
export { logSecurityEvent } from "../core/security/securityEvents.ts";
|
|
107
108
|
export type { StorageDriver } from "../core/storage/storage.ts";
|
|
108
109
|
export { createStorageDriver, LocalStorageDriver, resetDefaultStorage, StorageManager, } from "../core/storage/storage.ts";
|
|
110
|
+
export type { TenancyDriver } from "../core/tenant/tenancyConfig.ts";
|
|
111
|
+
export { isTenancyEnabled, readTenancyDriver } from "../core/tenant/tenancyConfig.ts";
|
|
109
112
|
export type { TenantContext } from "../core/tenant/tenantContext.ts";
|
|
110
113
|
export { currentTenant, currentTenantId, rateLimitMultiplierForPlan, runWithTenant, } from "../core/tenant/tenantContext.ts";
|
|
111
114
|
export { isInsideTenantDatabaseScope, runWithTenantDatabase, } from "../core/tenant/tenantDatabaseScope.ts";
|