@getstrata/core 3.0.5 → 3.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -9
- package/README.md +17 -9
- package/dist/core/auth/policy.d.ts +4 -1
- package/dist/core/auth/saml/samlServiceProvider.d.ts +2 -3
- package/dist/core/cache/store.d.ts +2 -2
- package/dist/core/cache/tokens.d.ts +1 -1
- package/dist/core/config/envSchema.d.ts +13 -0
- package/dist/core/contracts/application.d.ts +4 -0
- package/dist/core/contracts/di.d.ts +2 -2
- package/dist/core/contracts/provider.d.ts +13 -0
- package/dist/core/contracts/serviceTokens.d.ts +12 -11
- package/dist/core/database/factory.d.ts +3 -0
- package/dist/core/database/index.d.ts +1 -1
- package/dist/core/database/migrations/declaration.d.ts +11 -0
- package/dist/core/database/migrations/runner.d.ts +2 -0
- package/dist/core/database/model.d.ts +16 -3
- package/dist/core/database/modelQuery.d.ts +1 -10
- package/dist/core/database/modelRelationLoader.d.ts +31 -0
- package/dist/core/database/mysqlConnection.d.ts +2 -2
- package/dist/core/database/mysqlNative.d.ts +2 -0
- package/dist/core/database/ormRuntime.d.ts +1 -1
- package/dist/core/database/rawMysql.d.ts +1 -1
- package/dist/core/events/eventBusClass.d.ts +6 -3
- package/dist/core/events/index.d.ts +1 -1
- package/dist/core/http/formRequest.d.ts +2 -0
- package/dist/core/http/loginThrottleMiddleware.d.ts +1 -2
- package/dist/core/http/memoryThrottleMiddleware.d.ts +1 -3
- package/dist/core/http/webFormRequest.d.ts +3 -5
- package/dist/core/mail/mailer.d.ts +6 -3
- package/dist/core/mail/markdownMailable.d.ts +2 -2
- package/dist/core/notifications/dispatcher.d.ts +5 -5
- package/dist/core/notifications/index.d.ts +1 -1
- package/dist/core/notifications/types.d.ts +9 -2
- package/dist/core/queue/index.d.ts +8 -3
- package/dist/core/queue/queueHandoff.d.ts +2 -2
- package/dist/core/runtime/application.d.ts +2 -0
- package/dist/core/security/oauthState.d.ts +12 -2
- package/dist/core/security/safeUrl.d.ts +1 -11
- package/dist/core/storage/storage.d.ts +23 -6
- package/dist/core/testing.d.ts +5 -0
- package/dist/core/testingState.d.ts +22 -0
- package/dist/entries/audit/exportAuditLogs.js +1 -0
- package/dist/entries/auth/intendedUrlCookie.js +68 -2
- package/dist/entries/auth/jwt.js +68 -6
- package/dist/entries/auth/jwtGuard.js +76 -12
- package/dist/entries/auth/oauth/samlProvider.js +4 -5
- package/dist/entries/auth/passwordConfirmCookie.js +69 -3
- package/dist/entries/auth/saml/samlServiceProvider.js +5 -7
- package/dist/entries/auth/sessionCookie.js +69 -6
- package/dist/entries/auth/sessionGuard.js +69 -6
- package/dist/entries/cache/repository.js +4 -5
- package/dist/entries/config/envSchema.js +13 -0
- package/dist/entries/contracts/serviceTokens.js +2 -0
- package/dist/entries/database/bindings.js +18 -90
- package/dist/entries/database/factory.js +4 -0
- package/dist/entries/database/migrations.js +714 -1
- package/dist/entries/http/formRequest.js +12 -6
- package/dist/entries/http/memoryThrottleMiddleware.js +7 -9
- package/dist/entries/http/pagination.js +4 -4
- package/dist/entries/http/parseMultipartUpload.js +62 -9
- package/dist/entries/http/routeModelBinding.js +4 -4
- package/dist/entries/http/securedRouteModelBinding.js +4 -4
- package/dist/entries/http/uploads.js +62 -9
- package/dist/entries/http/validation.js +4 -4
- package/dist/entries/http/webFormRequest.js +74 -95
- package/dist/entries/jobs/exportAuditLogsJob.js +9 -4
- package/dist/entries/jobs/invalidateCacheTagsJob.js +9 -4
- package/dist/entries/queue/createAppQueue.js +10 -5
- package/dist/entries/queue/publicQueue.js +10 -5
- package/dist/entries/queue/queueWorkerTransport.js +10 -5
- package/dist/entries/queue.js +9 -4
- package/dist/entries/runtime/application.js +50 -3
- package/dist/entries/security/oauthState.js +61 -2
- package/dist/entries/security/tokenExpiry.js +62 -9
- package/dist/entries/storage/storage.js +102 -1
- package/dist/entries/testing.js +18 -0
- package/dist/framework/public-api.d.ts +16 -13
- package/dist/index.js +316 -222
- package/dist/internal/mysqlNative.js +97 -0
- package/dist/internal/ormRuntime.js +41 -4
- package/dist/internal/testingState.js +31 -0
- package/dist/types/services.d.ts +4 -1
- package/package.json +17 -4
package/dist/index.js
CHANGED
|
@@ -1,4 +1,28 @@
|
|
|
1
1
|
// @bun
|
|
2
|
+
// ../../src/core/contracts/provider.ts
|
|
3
|
+
function defineProvider(options) {
|
|
4
|
+
const { name, requires, services, setup, boot } = options;
|
|
5
|
+
if (typeof name !== "string" || name.trim().length === 0) {
|
|
6
|
+
throw new TypeError("Provider names must be nonempty strings.");
|
|
7
|
+
}
|
|
8
|
+
if (requires !== undefined && (!Array.isArray(requires) || requires.some((name) => typeof name !== "string" || name.trim().length === 0))) {
|
|
9
|
+
throw new TypeError("Provider dependencies must be an array of nonempty names.");
|
|
10
|
+
}
|
|
11
|
+
if (services !== undefined && !Array.isArray(services)) {
|
|
12
|
+
throw new TypeError("Provider services must be an array.");
|
|
13
|
+
}
|
|
14
|
+
if (setup !== undefined && typeof setup !== "function" || boot !== undefined && typeof boot !== "function") {
|
|
15
|
+
throw new TypeError("Provider hooks must be functions.");
|
|
16
|
+
}
|
|
17
|
+
return Object.freeze({
|
|
18
|
+
name,
|
|
19
|
+
requires: Object.freeze([...requires ?? []]),
|
|
20
|
+
services: Object.freeze([...services ?? []]),
|
|
21
|
+
setup: setup ?? (() => {}),
|
|
22
|
+
...boot ? { boot } : {}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
2
26
|
// ../../src/framework/public-api.ts
|
|
3
27
|
import { AuthenticationRequiredError as AuthenticationRequiredError2 } from "@getstrata/core/auth/authOutcome";
|
|
4
28
|
import { Policy, PolicyDeniedError, PolicyGate } from "@getstrata/core/auth/policy";
|
|
@@ -50,7 +74,7 @@ import { DATABASE_SESSION_TOKEN as DATABASE_SESSION_TOKEN2 } from "@getstrata/co
|
|
|
50
74
|
import {
|
|
51
75
|
BadRequestError as BadRequestError9,
|
|
52
76
|
ConflictError as ConflictError3,
|
|
53
|
-
ForbiddenError as
|
|
77
|
+
ForbiddenError as ForbiddenError14,
|
|
54
78
|
HttpError as HttpError3,
|
|
55
79
|
InternalServerError as InternalServerError3,
|
|
56
80
|
InvalidCredentialsError as InvalidCredentialsError3,
|
|
@@ -61,7 +85,7 @@ import {
|
|
|
61
85
|
toHttpError as toHttpError4,
|
|
62
86
|
UnauthorizedError as UnauthorizedError4,
|
|
63
87
|
UnprocessableEntityError as UnprocessableEntityError5,
|
|
64
|
-
ValidationError as
|
|
88
|
+
ValidationError as ValidationError4
|
|
65
89
|
} from "@getstrata/core/errors/http";
|
|
66
90
|
import {
|
|
67
91
|
createIdentityQueue as createIdentityQueue2,
|
|
@@ -73,6 +97,7 @@ import {
|
|
|
73
97
|
BaseRepository as BaseRepository4,
|
|
74
98
|
BelongsToManyRelationQuery,
|
|
75
99
|
BelongsToRelationQuery,
|
|
100
|
+
createModel,
|
|
76
101
|
HasManyRelationQuery,
|
|
77
102
|
HasManyThroughRelationQuery,
|
|
78
103
|
HasOneRelationQuery,
|
|
@@ -609,10 +634,11 @@ function resolveJwtSecret(secret) {
|
|
|
609
634
|
throw new TypeError("Explicit JWT secret is required.");
|
|
610
635
|
}
|
|
611
636
|
function jwtTtlSeconds(override) {
|
|
612
|
-
if (
|
|
613
|
-
return
|
|
614
|
-
|
|
615
|
-
|
|
637
|
+
if (override === undefined)
|
|
638
|
+
return 3600;
|
|
639
|
+
if (!Number.isSafeInteger(override) || override <= 0)
|
|
640
|
+
throw new TypeError("JWT ttlSeconds must be a positive safe integer.");
|
|
641
|
+
return override;
|
|
616
642
|
}
|
|
617
643
|
function encodeJson(value) {
|
|
618
644
|
return Buffer.from(JSON.stringify(value)).toString("base64url");
|
|
@@ -1225,7 +1251,7 @@ import { createHash as createHash2, randomBytes as randomBytes2 } from "crypto";
|
|
|
1225
1251
|
// ../../src/core/security/safeUrl.ts
|
|
1226
1252
|
import { lookup as dnsLookupImpl } from "dns/promises";
|
|
1227
1253
|
import { BadRequestError } from "@getstrata/core/errors/http";
|
|
1228
|
-
|
|
1254
|
+
import { testState } from "#strata-test-state";
|
|
1229
1255
|
var BLOCKED_HOSTNAMES = new Set([
|
|
1230
1256
|
"localhost",
|
|
1231
1257
|
"127.0.0.1",
|
|
@@ -1450,7 +1476,7 @@ async function resolveSafeOutboundTarget(rawUrl, options = {}) {
|
|
|
1450
1476
|
}
|
|
1451
1477
|
let results;
|
|
1452
1478
|
try {
|
|
1453
|
-
results = await dnsLookup(hostname, { all: true, verbatim: true });
|
|
1479
|
+
results = testState.dnsLookup ? await testState.dnsLookup(hostname, { all: true, verbatim: true }) : await dnsLookupImpl(hostname, { all: true, verbatim: true });
|
|
1454
1480
|
} catch {
|
|
1455
1481
|
throw new BadRequestError("Webhook URL targets a blocked host.");
|
|
1456
1482
|
}
|
|
@@ -1462,12 +1488,6 @@ async function resolveSafeOutboundTarget(rawUrl, options = {}) {
|
|
|
1462
1488
|
async function assertSafeOutboundUrlResolved(rawUrl, options = {}) {
|
|
1463
1489
|
return (await resolveSafeOutboundTarget(rawUrl, options)).url;
|
|
1464
1490
|
}
|
|
1465
|
-
function setDnsLookupForTests(lookupFn) {
|
|
1466
|
-
dnsLookup = lookupFn;
|
|
1467
|
-
}
|
|
1468
|
-
function resetDnsLookupForTests() {
|
|
1469
|
-
dnsLookup = dnsLookupImpl;
|
|
1470
|
-
}
|
|
1471
1491
|
|
|
1472
1492
|
// ../../src/core/security/safeFetch.ts
|
|
1473
1493
|
var DEFAULT_FETCH_TIMEOUT_MS = 1e4;
|
|
@@ -1885,6 +1905,9 @@ class OidcProvider {
|
|
|
1885
1905
|
};
|
|
1886
1906
|
}
|
|
1887
1907
|
}
|
|
1908
|
+
// ../../src/core/auth/saml/samlServiceProvider.ts
|
|
1909
|
+
import { testState as testState2 } from "#strata-test-state";
|
|
1910
|
+
|
|
1888
1911
|
// ../../src/core/runtime/optionalPeer.ts
|
|
1889
1912
|
function missingOptionalPeer(packageName, reason, error) {
|
|
1890
1913
|
return new Error(`Install ${packageName} ${reason} (\`bun add ${packageName}\`).`, {
|
|
@@ -1992,20 +2015,16 @@ function readSamlEnvOptions(env = process.env) {
|
|
|
1992
2015
|
disableRequestedAuthnContext: env.SAML_DISABLE_REQUESTED_AUTHN_CONTEXT === "true"
|
|
1993
2016
|
};
|
|
1994
2017
|
}
|
|
1995
|
-
var nodeSamlLoader = null;
|
|
1996
2018
|
async function defaultLoadNodeSaml() {
|
|
1997
2019
|
return await import("@node-saml/node-saml");
|
|
1998
2020
|
}
|
|
1999
2021
|
async function loadNodeSaml() {
|
|
2000
2022
|
try {
|
|
2001
|
-
return await (nodeSamlLoader ?? defaultLoadNodeSaml)();
|
|
2023
|
+
return await (testState2.nodeSamlLoader ?? defaultLoadNodeSaml)();
|
|
2002
2024
|
} catch (error) {
|
|
2003
2025
|
throw missingOptionalPeer("@node-saml/node-saml", "to verify SAML assertions", error);
|
|
2004
2026
|
}
|
|
2005
2027
|
}
|
|
2006
|
-
function setNodeSamlLoaderForTests(loader) {
|
|
2007
|
-
nodeSamlLoader = loader;
|
|
2008
|
-
}
|
|
2009
2028
|
|
|
2010
2029
|
class SamlServiceProvider {
|
|
2011
2030
|
client = null;
|
|
@@ -2958,6 +2977,9 @@ class TaggedCache {
|
|
|
2958
2977
|
constructor(store, tags) {
|
|
2959
2978
|
this.store = store;
|
|
2960
2979
|
this.tags = tags;
|
|
2980
|
+
if (typeof store.getOrSetTagged !== "function") {
|
|
2981
|
+
throw new TypeError("Cache tags require atomic tagged loading support.");
|
|
2982
|
+
}
|
|
2961
2983
|
}
|
|
2962
2984
|
async put(key, value, ttlMs) {
|
|
2963
2985
|
await this.store.set(key, value, ttlMs, this.tags);
|
|
@@ -2966,11 +2988,7 @@ class TaggedCache {
|
|
|
2966
2988
|
await this.store.set(key, value, null, this.tags);
|
|
2967
2989
|
}
|
|
2968
2990
|
async remember(key, callback, ttlMs) {
|
|
2969
|
-
|
|
2970
|
-
return this.store.getOrSetTagged(key, callback, this.tags, ttlMs);
|
|
2971
|
-
const value = await this.store.getOrSet(key, callback, ttlMs);
|
|
2972
|
-
await this.store.attachTags(key, this.tags);
|
|
2973
|
-
return value;
|
|
2991
|
+
return this.store.getOrSetTagged(key, callback, this.tags, ttlMs);
|
|
2974
2992
|
}
|
|
2975
2993
|
async flush() {
|
|
2976
2994
|
return this.store.flushTags(this.tags);
|
|
@@ -4271,7 +4289,6 @@ import {
|
|
|
4271
4289
|
|
|
4272
4290
|
// ../../src/core/events/eventBusClass.ts
|
|
4273
4291
|
class EventBus {
|
|
4274
|
-
constructor() {}
|
|
4275
4292
|
transactionalListeners = new Map;
|
|
4276
4293
|
listenTransactional(event, listener) {
|
|
4277
4294
|
const handlers = this.transactionalListeners.get(event) ?? new Set;
|
|
@@ -4665,87 +4682,8 @@ function createBoundRegistryFactory(prepared, context, ownership, configuredPool
|
|
|
4665
4682
|
};
|
|
4666
4683
|
}
|
|
4667
4684
|
|
|
4668
|
-
// ../../src/core/database/
|
|
4669
|
-
|
|
4670
|
-
var mysqlModule;
|
|
4671
|
-
var mysqlPending;
|
|
4672
|
-
var importMysql = defaultImportMysql;
|
|
4673
|
-
async function defaultImportMysql() {
|
|
4674
|
-
return import("mysql2/promise");
|
|
4675
|
-
}
|
|
4676
|
-
function resetMysqlLoaderForTests(importer) {
|
|
4677
|
-
mysqlModule = undefined;
|
|
4678
|
-
mysqlPending = undefined;
|
|
4679
|
-
importMysql = importer ? async () => await importer() : defaultImportMysql;
|
|
4680
|
-
}
|
|
4681
|
-
function mysqlApi(mod) {
|
|
4682
|
-
if (typeof mod.createPool === "function") {
|
|
4683
|
-
return mod;
|
|
4684
|
-
}
|
|
4685
|
-
const withDefault = mod;
|
|
4686
|
-
if (typeof withDefault.default?.createPool === "function") {
|
|
4687
|
-
return withDefault.default;
|
|
4688
|
-
}
|
|
4689
|
-
throw new Error("mysql2/promise did not export createPool.");
|
|
4690
|
-
}
|
|
4691
|
-
async function loadMysql() {
|
|
4692
|
-
if (mysqlModule) {
|
|
4693
|
-
return mysqlModule;
|
|
4694
|
-
}
|
|
4695
|
-
if (!mysqlPending) {
|
|
4696
|
-
mysqlPending = (async () => {
|
|
4697
|
-
let mod;
|
|
4698
|
-
try {
|
|
4699
|
-
mod = await importMysql();
|
|
4700
|
-
} catch (error) {
|
|
4701
|
-
mysqlPending = undefined;
|
|
4702
|
-
throw missingOptionalPeer("mysql2", "to open a MySQL connection", error);
|
|
4703
|
-
}
|
|
4704
|
-
try {
|
|
4705
|
-
mysqlModule = mysqlApi(mod);
|
|
4706
|
-
return mysqlModule;
|
|
4707
|
-
} catch (error) {
|
|
4708
|
-
mysqlPending = undefined;
|
|
4709
|
-
throw error;
|
|
4710
|
-
}
|
|
4711
|
-
})();
|
|
4712
|
-
}
|
|
4713
|
-
return mysqlPending;
|
|
4714
|
-
}
|
|
4715
|
-
function rowsFromResult(result) {
|
|
4716
|
-
if (Array.isArray(result)) {
|
|
4717
|
-
return result;
|
|
4718
|
-
}
|
|
4719
|
-
if (result && typeof result === "object") {
|
|
4720
|
-
return [result];
|
|
4721
|
-
}
|
|
4722
|
-
return [];
|
|
4723
|
-
}
|
|
4724
|
-
async function executeMysql(target, query, params) {
|
|
4725
|
-
const [result] = params.length === 0 && target.query ? await target.query(query) : await target.execute(query, [...params]);
|
|
4726
|
-
return rowsFromResult(result);
|
|
4727
|
-
}
|
|
4728
|
-
function pinSessionToUtc(connection) {
|
|
4729
|
-
connection.query(MYSQL_SESSION_UTC, (error) => {
|
|
4730
|
-
if (error) {
|
|
4731
|
-
console.warn("[mysql] Could not set the session time zone to UTC; DATETIME comparisons may drift.");
|
|
4732
|
-
}
|
|
4733
|
-
});
|
|
4734
|
-
}
|
|
4735
|
-
function createPoolFromModule(mysql, url, max) {
|
|
4736
|
-
const pool = mysql.createPool({
|
|
4737
|
-
uri: url,
|
|
4738
|
-
timezone: "Z",
|
|
4739
|
-
...max === undefined ? {} : { connectionLimit: max }
|
|
4740
|
-
});
|
|
4741
|
-
pool.on("connection", (connection) => {
|
|
4742
|
-
pinSessionToUtc(connection);
|
|
4743
|
-
});
|
|
4744
|
-
return pool;
|
|
4745
|
-
}
|
|
4746
|
-
async function createMysqlPool(url, max) {
|
|
4747
|
-
return createPoolFromModule(await loadMysql(), url, max);
|
|
4748
|
-
}
|
|
4685
|
+
// ../../src/core/database/rawMysql.ts
|
|
4686
|
+
import { createMysqlPool, executeMysql } from "#strata-mysql-native";
|
|
4749
4687
|
|
|
4750
4688
|
// ../../src/core/database/nativeTransactions.ts
|
|
4751
4689
|
var failure = (error) => Object.freeze({ error });
|
|
@@ -4985,6 +4923,7 @@ function createMysqlPin(connection) {
|
|
|
4985
4923
|
async function createRawMysqlPool(options) {
|
|
4986
4924
|
const pool = await createMysqlPool(options.url, options.max);
|
|
4987
4925
|
let closed = false;
|
|
4926
|
+
let closing;
|
|
4988
4927
|
let retainedCleanup;
|
|
4989
4928
|
const acquire = async () => {
|
|
4990
4929
|
if (closed)
|
|
@@ -5068,11 +5007,16 @@ async function createRawMysqlPool(options) {
|
|
|
5068
5007
|
return { ok: false, error, disposition: "unknown", cleanupErrors: [acknowledgement.error] };
|
|
5069
5008
|
}
|
|
5070
5009
|
},
|
|
5071
|
-
|
|
5072
|
-
if (
|
|
5073
|
-
|
|
5074
|
-
await pool.end();
|
|
5010
|
+
close() {
|
|
5011
|
+
if (closing)
|
|
5012
|
+
return closing;
|
|
5075
5013
|
closed = true;
|
|
5014
|
+
closing = Promise.resolve().then(async () => {
|
|
5015
|
+
if (retainedCleanup)
|
|
5016
|
+
throw retainedCleanup.error;
|
|
5017
|
+
await pool.end();
|
|
5018
|
+
});
|
|
5019
|
+
return closing;
|
|
5076
5020
|
}
|
|
5077
5021
|
});
|
|
5078
5022
|
}
|
|
@@ -5146,6 +5090,7 @@ function postgresPin(connection) {
|
|
|
5146
5090
|
}
|
|
5147
5091
|
function createRawPostgresPoolFromNative(pool) {
|
|
5148
5092
|
let closed = false;
|
|
5093
|
+
let closing;
|
|
5149
5094
|
return Object.freeze({
|
|
5150
5095
|
dialect: dialectFor("pgsql"),
|
|
5151
5096
|
capabilities: Object.freeze({
|
|
@@ -5178,9 +5123,12 @@ function createRawPostgresPoolFromNative(pool) {
|
|
|
5178
5123
|
return { ok: false, error, disposition: "not-acquired" };
|
|
5179
5124
|
}
|
|
5180
5125
|
},
|
|
5181
|
-
|
|
5182
|
-
|
|
5126
|
+
close() {
|
|
5127
|
+
if (closing)
|
|
5128
|
+
return closing;
|
|
5183
5129
|
closed = true;
|
|
5130
|
+
closing = Promise.resolve().then(() => pool.close());
|
|
5131
|
+
return closing;
|
|
5184
5132
|
}
|
|
5185
5133
|
});
|
|
5186
5134
|
}
|
|
@@ -6255,7 +6203,7 @@ async function rollbackDatabase(db, migrations, options = {}) {
|
|
|
6255
6203
|
return rolledBack;
|
|
6256
6204
|
}
|
|
6257
6205
|
async function freshDatabase(db, migrations, options = {}) {
|
|
6258
|
-
if (options.destructive && isProductionEnv()) {
|
|
6206
|
+
if (options.destructive && isProductionEnv(options.environment ?? process.env)) {
|
|
6259
6207
|
throw new Error("Destructive migration reset is only available in development/test environments.");
|
|
6260
6208
|
}
|
|
6261
6209
|
validateMigrations(migrations);
|
|
@@ -6385,6 +6333,13 @@ function applyCasts(values, casts, direction) {
|
|
|
6385
6333
|
return result;
|
|
6386
6334
|
})();
|
|
6387
6335
|
}
|
|
6336
|
+
// ../../src/core/database/mysqlConnection.ts
|
|
6337
|
+
import {
|
|
6338
|
+
createMysqlPool as createMysqlPool2,
|
|
6339
|
+
executeMysql as executeMysql2,
|
|
6340
|
+
loadMysql
|
|
6341
|
+
} from "#strata-mysql-native";
|
|
6342
|
+
|
|
6388
6343
|
// ../../src/core/database/isolatedReadOnlyObservation.ts
|
|
6389
6344
|
var childSource = `
|
|
6390
6345
|
import { Database } from 'bun:sqlite';
|
|
@@ -6562,22 +6517,39 @@ function createMysqlAdapter(getPool, close, observer) {
|
|
|
6562
6517
|
const transactions = new WeakSet;
|
|
6563
6518
|
const observations = new Set;
|
|
6564
6519
|
let observationsClosed = false;
|
|
6520
|
+
let closing;
|
|
6521
|
+
const operations = new Set;
|
|
6522
|
+
function assertOpen() {
|
|
6523
|
+
if (observationsClosed)
|
|
6524
|
+
throw new Error("MySQL connection is closed.");
|
|
6525
|
+
}
|
|
6526
|
+
function track(operation) {
|
|
6527
|
+
operations.add(operation);
|
|
6528
|
+
operation.finally(() => operations.delete(operation)).catch(() => {});
|
|
6529
|
+
return operation;
|
|
6530
|
+
}
|
|
6565
6531
|
const connection = {
|
|
6566
6532
|
async unsafe(query, params = []) {
|
|
6567
6533
|
const active = getActiveDatabaseConnection(connection);
|
|
6568
6534
|
if (transactions.has(active))
|
|
6569
6535
|
return active.unsafe(query, params);
|
|
6570
|
-
|
|
6536
|
+
assertOpen();
|
|
6537
|
+
return track((async () => {
|
|
6538
|
+
return executeMysql2(await getPool(), query, params);
|
|
6539
|
+
})());
|
|
6571
6540
|
},
|
|
6572
6541
|
async begin(callback) {
|
|
6573
|
-
|
|
6574
|
-
|
|
6575
|
-
|
|
6576
|
-
|
|
6577
|
-
|
|
6578
|
-
|
|
6579
|
-
|
|
6580
|
-
|
|
6542
|
+
assertOpen();
|
|
6543
|
+
return track((async () => {
|
|
6544
|
+
if (transactions.has(getActiveDatabaseConnection(connection))) {
|
|
6545
|
+
throw new Error("Use the active transaction handle for nested MySQL work.");
|
|
6546
|
+
}
|
|
6547
|
+
const pool = await getPool();
|
|
6548
|
+
if (!pool.getConnection)
|
|
6549
|
+
throw new Error("MySQL transactions require a pool with getConnection().");
|
|
6550
|
+
const reserved = await pool.getConnection();
|
|
6551
|
+
return legacyNativeTransaction(createMysqlPin(reserved), callback, transactions);
|
|
6552
|
+
})());
|
|
6581
6553
|
},
|
|
6582
6554
|
async observeReadOnly(operation, options) {
|
|
6583
6555
|
if (observationsClosed)
|
|
@@ -6595,10 +6567,18 @@ function createMysqlAdapter(getPool, close, observer) {
|
|
|
6595
6567
|
observations.delete(work);
|
|
6596
6568
|
}
|
|
6597
6569
|
},
|
|
6598
|
-
|
|
6570
|
+
close() {
|
|
6571
|
+
if (transactions.has(getActiveDatabaseConnection(connection)))
|
|
6572
|
+
return Promise.reject(new Error("Cannot close MySQL from inside its active transaction."));
|
|
6573
|
+
if (closing)
|
|
6574
|
+
return closing;
|
|
6599
6575
|
observationsClosed = true;
|
|
6600
|
-
|
|
6601
|
-
|
|
6576
|
+
closing = Promise.resolve().then(async () => {
|
|
6577
|
+
while (operations.size || observations.size)
|
|
6578
|
+
await Promise.allSettled([...operations, ...observations]);
|
|
6579
|
+
await close();
|
|
6580
|
+
});
|
|
6581
|
+
return closing;
|
|
6602
6582
|
}
|
|
6603
6583
|
};
|
|
6604
6584
|
return connection;
|
|
@@ -6615,7 +6595,7 @@ function createMysqlConnection(url) {
|
|
|
6615
6595
|
let poolPending;
|
|
6616
6596
|
function ensurePool() {
|
|
6617
6597
|
if (!poolPending) {
|
|
6618
|
-
poolPending =
|
|
6598
|
+
poolPending = createMysqlPool2(url).catch((error) => {
|
|
6619
6599
|
poolPending = undefined;
|
|
6620
6600
|
throw error;
|
|
6621
6601
|
});
|
|
@@ -9371,7 +9351,7 @@ function createOutboxWorkerTransport(token, options = {}) {
|
|
|
9371
9351
|
pollMs,
|
|
9372
9352
|
[workerApplicationShutdown]: applicationShutdown
|
|
9373
9353
|
});
|
|
9374
|
-
running = Promise.resolve().then(() => controller.signal.aborted ? undefined : selected.work(workOptions)).catch((error) => {
|
|
9354
|
+
running = Promise.resolve().then(() => controller.signal.aborted || applicationShutdown?.aborted ? undefined : selected.work(workOptions)).catch((error) => {
|
|
9375
9355
|
if (!controller.signal.aborted && !applicationShutdown?.aborted || !expectedStop(error))
|
|
9376
9356
|
throw error;
|
|
9377
9357
|
});
|
|
@@ -11354,8 +11334,8 @@ function parseOptionalPositiveIntQueryParam(params, name) {
|
|
|
11354
11334
|
if (value === null || value.trim() === "") {
|
|
11355
11335
|
return;
|
|
11356
11336
|
}
|
|
11357
|
-
const parsed = Number
|
|
11358
|
-
if (!Number.
|
|
11337
|
+
const parsed = Number(value);
|
|
11338
|
+
if (!/^[0-9]+$/.test(value.trim()) || !Number.isSafeInteger(parsed) || parsed <= 0) {
|
|
11359
11339
|
throw new BadRequestError3(`Invalid query parameter "${name}". Expected a positive integer.`);
|
|
11360
11340
|
}
|
|
11361
11341
|
return parsed;
|
|
@@ -11451,8 +11431,8 @@ function readOptionalPositiveInt(payload, field) {
|
|
|
11451
11431
|
return readRequiredPositiveInt(payload, field);
|
|
11452
11432
|
}
|
|
11453
11433
|
function parsePositiveIntParam(value, name = "id") {
|
|
11454
|
-
const parsed = Number
|
|
11455
|
-
if (!Number.
|
|
11434
|
+
const parsed = Number(value);
|
|
11435
|
+
if (!/^[0-9]+$/.test(value.trim()) || !Number.isSafeInteger(parsed) || parsed <= 0) {
|
|
11456
11436
|
throw new BadRequestError3(`Invalid ${name}. Expected a positive integer.`);
|
|
11457
11437
|
}
|
|
11458
11438
|
return parsed;
|
|
@@ -11463,11 +11443,17 @@ class FormRequest {
|
|
|
11463
11443
|
authorize(_request) {
|
|
11464
11444
|
return true;
|
|
11465
11445
|
}
|
|
11446
|
+
validatePayload(payload) {
|
|
11447
|
+
return this.parse(payload);
|
|
11448
|
+
}
|
|
11449
|
+
readPayload(request) {
|
|
11450
|
+
return parseJsonBody(request, (payload) => payload);
|
|
11451
|
+
}
|
|
11466
11452
|
async validate(request) {
|
|
11467
|
-
if (
|
|
11453
|
+
if (await this.authorize(request) !== true) {
|
|
11468
11454
|
throw new ForbiddenError6;
|
|
11469
11455
|
}
|
|
11470
|
-
return await
|
|
11456
|
+
return this.validatePayload(await this.readPayload(request));
|
|
11471
11457
|
}
|
|
11472
11458
|
}
|
|
11473
11459
|
|
|
@@ -11921,6 +11907,9 @@ function securedBindRouteModelByKey(param, resolver, authorization, handler, por
|
|
|
11921
11907
|
return response;
|
|
11922
11908
|
};
|
|
11923
11909
|
}
|
|
11910
|
+
// ../../src/core/http/loginThrottleMiddleware.ts
|
|
11911
|
+
import { testState as testState3 } from "#strata-test-state";
|
|
11912
|
+
|
|
11924
11913
|
// ../../src/core/runtime/boundedThrottleStore.ts
|
|
11925
11914
|
class BoundedThrottleStore {
|
|
11926
11915
|
decayMs;
|
|
@@ -12154,7 +12143,6 @@ function createThrottleMiddleware(options) {
|
|
|
12154
12143
|
}
|
|
12155
12144
|
|
|
12156
12145
|
// ../../src/core/http/loginThrottleMiddleware.ts
|
|
12157
|
-
var resetGeneration = 0;
|
|
12158
12146
|
function resolveLoginIdentity(request, trustForwardedFor = false) {
|
|
12159
12147
|
return readClientIp(request, { TRUST_FORWARDED_FOR: String(trustForwardedFor) }) ?? "unknown";
|
|
12160
12148
|
}
|
|
@@ -12177,11 +12165,11 @@ function createMemoryLoginThrottleMiddleware(options) {
|
|
|
12177
12165
|
const store = new BoundedThrottleStore(options.decaySeconds * 1000, options);
|
|
12178
12166
|
if (!Number.isSafeInteger(options.maxAttempts) || options.maxAttempts < 0)
|
|
12179
12167
|
throw new Error("Invalid memory throttle limit.");
|
|
12180
|
-
let generation =
|
|
12168
|
+
let generation = testState3.loginThrottleGeneration;
|
|
12181
12169
|
const middleware = async (request, next) => {
|
|
12182
|
-
if (generation !==
|
|
12170
|
+
if (generation !== testState3.loginThrottleGeneration) {
|
|
12183
12171
|
store.clear();
|
|
12184
|
-
generation =
|
|
12172
|
+
generation = testState3.loginThrottleGeneration;
|
|
12185
12173
|
}
|
|
12186
12174
|
const email = await resolveLoginEmail(request);
|
|
12187
12175
|
const key = redisThrottleKey(request, options.keyPrefix ?? "login-throttle", JSON.stringify([resolveLoginIdentity(request, options.trustForwardedFor), email]), undefined, options.namespace);
|
|
@@ -12224,21 +12212,18 @@ function createLoginThrottleMiddleware(options) {
|
|
|
12224
12212
|
}
|
|
12225
12213
|
return createMemoryLoginThrottleMiddleware(options);
|
|
12226
12214
|
}
|
|
12227
|
-
function resetMemoryLoginThrottleForTests() {
|
|
12228
|
-
resetGeneration++;
|
|
12229
|
-
}
|
|
12230
12215
|
// ../../src/core/http/memoryThrottleMiddleware.ts
|
|
12231
|
-
|
|
12216
|
+
import { testState as testState4 } from "#strata-test-state";
|
|
12232
12217
|
function createMemoryThrottleMiddleware(options) {
|
|
12233
12218
|
options = Object.freeze({ ...options });
|
|
12234
12219
|
const store = new BoundedThrottleStore(options.decaySeconds * 1000, options);
|
|
12235
12220
|
if (!Number.isSafeInteger(options.maxAttempts) || options.maxAttempts < 0)
|
|
12236
12221
|
throw new Error("Invalid memory throttle limit.");
|
|
12237
|
-
let generation =
|
|
12222
|
+
let generation = testState4.throttleGeneration;
|
|
12238
12223
|
const middleware = async (request, next) => {
|
|
12239
|
-
if (generation !==
|
|
12224
|
+
if (generation !== testState4.throttleGeneration) {
|
|
12240
12225
|
store.clear();
|
|
12241
|
-
generation =
|
|
12226
|
+
generation = testState4.throttleGeneration;
|
|
12242
12227
|
}
|
|
12243
12228
|
let maxAttempts;
|
|
12244
12229
|
try {
|
|
@@ -12255,9 +12240,6 @@ function createMemoryThrottleMiddleware(options) {
|
|
|
12255
12240
|
};
|
|
12256
12241
|
return Object.assign(middleware, { dispose: () => store.dispose(), stats: () => store.stats() });
|
|
12257
12242
|
}
|
|
12258
|
-
function resetMemoryThrottleForTests() {
|
|
12259
|
-
resetGeneration2++;
|
|
12260
|
-
}
|
|
12261
12243
|
// ../../src/core/metrics/prometheus.ts
|
|
12262
12244
|
var HTTP_DURATION_BUCKETS_MS = [5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000, 1e4];
|
|
12263
12245
|
function emptyHistogram() {
|
|
@@ -12723,9 +12705,6 @@ function createValidateSignatureMiddleware(options) {
|
|
|
12723
12705
|
return await next();
|
|
12724
12706
|
};
|
|
12725
12707
|
}
|
|
12726
|
-
// ../../src/core/http/webFormRequest.ts
|
|
12727
|
-
import { ForbiddenError as ForbiddenError12, ValidationError as ValidationError3 } from "@getstrata/core/errors/http";
|
|
12728
|
-
|
|
12729
12708
|
// ../../src/core/http/parseFormBody.ts
|
|
12730
12709
|
import { BadRequestError as BadRequestError8 } from "@getstrata/core/errors/http";
|
|
12731
12710
|
async function parseFormBody(request, options = {}) {
|
|
@@ -12757,30 +12736,15 @@ function formDataToRecord(formData, options = {}) {
|
|
|
12757
12736
|
}
|
|
12758
12737
|
|
|
12759
12738
|
// ../../src/core/http/webFormRequest.ts
|
|
12760
|
-
class WebFormRequest {
|
|
12739
|
+
class WebFormRequest extends FormRequest {
|
|
12761
12740
|
#preserveRepeated;
|
|
12762
12741
|
constructor(options = {}) {
|
|
12742
|
+
super();
|
|
12763
12743
|
this.#preserveRepeated = options.preserveRepeated === true;
|
|
12764
12744
|
}
|
|
12765
|
-
|
|
12766
|
-
|
|
12767
|
-
|
|
12768
|
-
validatePayload(payload) {
|
|
12769
|
-
return this.parse(payload);
|
|
12770
|
-
}
|
|
12771
|
-
async validate(request) {
|
|
12772
|
-
if (!await this.authorize(request)) {
|
|
12773
|
-
throw new ForbiddenError12;
|
|
12774
|
-
}
|
|
12775
|
-
const payload = requestPrefersJson(request) ? await parseJsonBody(request, (body) => body) : await parseFormBody(request, { preserveRepeated: this.#preserveRepeated });
|
|
12776
|
-
try {
|
|
12777
|
-
return this.validatePayload(payload);
|
|
12778
|
-
} catch (error) {
|
|
12779
|
-
if (error instanceof ValidationError3) {
|
|
12780
|
-
throw error;
|
|
12781
|
-
}
|
|
12782
|
-
throw error;
|
|
12783
|
-
}
|
|
12745
|
+
readPayload(request) {
|
|
12746
|
+
const mediaType = request.headers.get("content-type")?.split(";", 1)[0]?.trim().toLowerCase();
|
|
12747
|
+
return mediaType === "application/json" || mediaType?.match(/^application\/[^/]+\+json$/) ? parseJsonBody(request, (body) => body) : parseFormBody(request, { preserveRepeated: this.#preserveRepeated });
|
|
12784
12748
|
}
|
|
12785
12749
|
}
|
|
12786
12750
|
// ../../src/core/lifecycle/gracefulShutdown.ts
|
|
@@ -13501,20 +13465,45 @@ async function sendMarkdownMail(mailer, input) {
|
|
|
13501
13465
|
// ../../src/core/notifications/dispatcher.ts
|
|
13502
13466
|
class NotificationDispatcher {
|
|
13503
13467
|
mailer;
|
|
13504
|
-
|
|
13505
|
-
constructor(mailer, databaseStore = null) {
|
|
13468
|
+
channels;
|
|
13469
|
+
constructor(mailer, databaseStore = null, channels = {}) {
|
|
13506
13470
|
this.mailer = mailer;
|
|
13507
|
-
|
|
13471
|
+
if (!mailer || typeof mailer.send !== "function") {
|
|
13472
|
+
throw new TypeError('Notification channel "mail" requires a mail sender.');
|
|
13473
|
+
}
|
|
13474
|
+
if (databaseStore && typeof databaseStore.create !== "function") {
|
|
13475
|
+
throw new TypeError('Notification channel "database" requires a database store.');
|
|
13476
|
+
}
|
|
13477
|
+
const registrations = Object.create(null);
|
|
13478
|
+
registrations.mail = { send: (recipient, message) => this.sendMail(recipient, message) };
|
|
13479
|
+
if (databaseStore) {
|
|
13480
|
+
registrations.database = {
|
|
13481
|
+
send: (recipient, message) => this.sendDatabase(databaseStore, recipient, message)
|
|
13482
|
+
};
|
|
13483
|
+
}
|
|
13484
|
+
for (const [name, channel] of Object.entries(channels)) {
|
|
13485
|
+
if (!name || !channel || typeof channel.send !== "function") {
|
|
13486
|
+
throw new TypeError(`Invalid notification channel registration: "${name}".`);
|
|
13487
|
+
}
|
|
13488
|
+
const send = channel.send.bind(channel);
|
|
13489
|
+
registrations[name] = Object.freeze({ send });
|
|
13490
|
+
}
|
|
13491
|
+
this.channels = Object.freeze(registrations);
|
|
13508
13492
|
}
|
|
13509
13493
|
async send(notifiable, notification) {
|
|
13510
|
-
|
|
13511
|
-
|
|
13512
|
-
|
|
13513
|
-
|
|
13514
|
-
|
|
13515
|
-
|
|
13516
|
-
|
|
13494
|
+
const channels = [...notification.via(notifiable)];
|
|
13495
|
+
const handlers = channels.map((name) => {
|
|
13496
|
+
const channel = Object.hasOwn(this.channels, name) ? this.channels[name] : undefined;
|
|
13497
|
+
if (!channel) {
|
|
13498
|
+
if (name === "database") {
|
|
13499
|
+
throw new Error('Notification channel "database" requires a database store.');
|
|
13500
|
+
}
|
|
13501
|
+
throw new Error(`Unsupported notification channel: "${name}".`);
|
|
13517
13502
|
}
|
|
13503
|
+
return channel;
|
|
13504
|
+
});
|
|
13505
|
+
for (const channel of handlers) {
|
|
13506
|
+
await channel.send(notifiable, notification);
|
|
13518
13507
|
}
|
|
13519
13508
|
}
|
|
13520
13509
|
async sendMail(notifiable, notification) {
|
|
@@ -13537,25 +13526,28 @@ class NotificationDispatcher {
|
|
|
13537
13526
|
await this.mailer.send({
|
|
13538
13527
|
to: String(routed),
|
|
13539
13528
|
subject: message.subject,
|
|
13540
|
-
body: message.body ?? ""
|
|
13529
|
+
body: message.body ?? "",
|
|
13530
|
+
...message.html !== undefined ? { html: message.html } : {}
|
|
13541
13531
|
});
|
|
13542
13532
|
}
|
|
13543
|
-
async sendDatabase(notifiable, notification) {
|
|
13544
|
-
if (!this.databaseStore) {
|
|
13545
|
-
return;
|
|
13546
|
-
}
|
|
13533
|
+
async sendDatabase(store, notifiable, notification) {
|
|
13547
13534
|
const payload = notification.toDatabase(notifiable);
|
|
13548
13535
|
if (!payload) {
|
|
13549
13536
|
return;
|
|
13550
13537
|
}
|
|
13551
|
-
|
|
13552
|
-
|
|
13553
|
-
|
|
13538
|
+
const key = notifiable.getNotificationKey();
|
|
13539
|
+
const userId = typeof key === "string" && /^[0-9]+$/.test(key) ? Number(key) : key;
|
|
13540
|
+
if (typeof userId !== "number" || !Number.isSafeInteger(userId) || userId <= 0) {
|
|
13541
|
+
throw new TypeError('Notification channel "database" requires a positive safe-integer user ID.');
|
|
13542
|
+
}
|
|
13543
|
+
await store.create({
|
|
13544
|
+
...payload,
|
|
13545
|
+
userId
|
|
13554
13546
|
});
|
|
13555
13547
|
}
|
|
13556
13548
|
}
|
|
13557
|
-
function createNotificationDispatcher(mailer, databaseStore) {
|
|
13558
|
-
return new NotificationDispatcher(mailer, databaseStore ?? null);
|
|
13549
|
+
function createNotificationDispatcher(mailer, databaseStore, channels = {}) {
|
|
13550
|
+
return new NotificationDispatcher(mailer, databaseStore ?? null, channels);
|
|
13559
13551
|
}
|
|
13560
13552
|
// ../../src/core/notifications/notification.ts
|
|
13561
13553
|
class Notification {
|
|
@@ -13706,6 +13698,14 @@ class AsyncQueue {
|
|
|
13706
13698
|
if (this.closed)
|
|
13707
13699
|
throw new Error("Async queue is closed.");
|
|
13708
13700
|
}
|
|
13701
|
+
track(running) {
|
|
13702
|
+
const settled = running.then(() => {}, () => {});
|
|
13703
|
+
this.active.add(settled);
|
|
13704
|
+
settled.then(() => {
|
|
13705
|
+
this.active.delete(settled);
|
|
13706
|
+
});
|
|
13707
|
+
return running;
|
|
13708
|
+
}
|
|
13709
13709
|
enqueue(task, onError) {
|
|
13710
13710
|
this.assertOpen();
|
|
13711
13711
|
const running = new Promise((resolve) => {
|
|
@@ -13713,10 +13713,7 @@ class AsyncQueue {
|
|
|
13713
13713
|
Promise.resolve().then(task).catch(onError).finally(resolve);
|
|
13714
13714
|
}, 0);
|
|
13715
13715
|
});
|
|
13716
|
-
this.
|
|
13717
|
-
running.then(() => {
|
|
13718
|
-
this.active.delete(running);
|
|
13719
|
-
});
|
|
13716
|
+
this.track(running);
|
|
13720
13717
|
}
|
|
13721
13718
|
async dispatch(job, payload, options) {
|
|
13722
13719
|
if (options?.handoff !== undefined)
|
|
@@ -15056,7 +15053,7 @@ class ResilientQueue extends AsyncQueue {
|
|
|
15056
15053
|
});
|
|
15057
15054
|
return;
|
|
15058
15055
|
}
|
|
15059
|
-
await runQueueJob(envelope, this.failedJobs, this.registry, { retryPolicy: this.retryPolicy });
|
|
15056
|
+
await this.track(Promise.resolve().then(() => runQueueJob(envelope, this.failedJobs, this.registry, { retryPolicy: this.retryPolicy })));
|
|
15060
15057
|
}
|
|
15061
15058
|
}
|
|
15062
15059
|
|
|
@@ -15506,10 +15503,52 @@ function signedWebhookHeaders(secret, body, headerName = "x-strata-signature") {
|
|
|
15506
15503
|
};
|
|
15507
15504
|
}
|
|
15508
15505
|
// ../../src/core/storage/storage.ts
|
|
15509
|
-
import { mkdir, readFile, unlink, writeFile } from "fs/promises";
|
|
15506
|
+
import { mkdir, readFile, stat, unlink, writeFile } from "fs/promises";
|
|
15510
15507
|
import { dirname, resolve as resolve3 } from "path";
|
|
15511
15508
|
import { CORE_STORAGE_TOKEN } from "@getstrata/core/contracts/serviceTokens";
|
|
15512
15509
|
var {S3Client } = globalThis.Bun;
|
|
15510
|
+
function requireStreamingStorage(storage) {
|
|
15511
|
+
if (!("readStream" in storage) || typeof storage.readStream !== "function" || !("writeStream" in storage) || typeof storage.writeStream !== "function")
|
|
15512
|
+
throw new TypeError("Storage does not support streaming.");
|
|
15513
|
+
if (storage instanceof StorageManager)
|
|
15514
|
+
storage.streamingDriver();
|
|
15515
|
+
return storage;
|
|
15516
|
+
}
|
|
15517
|
+
async function openStream(source, missingCode) {
|
|
15518
|
+
const reader = source.getReader();
|
|
15519
|
+
let first;
|
|
15520
|
+
try {
|
|
15521
|
+
first = await reader.read();
|
|
15522
|
+
} catch (error) {
|
|
15523
|
+
reader.releaseLock();
|
|
15524
|
+
if (hasErrorCode(error, missingCode))
|
|
15525
|
+
return null;
|
|
15526
|
+
throw error;
|
|
15527
|
+
}
|
|
15528
|
+
return new ReadableStream({
|
|
15529
|
+
async pull(controller) {
|
|
15530
|
+
try {
|
|
15531
|
+
const next = first ?? await reader.read();
|
|
15532
|
+
first = undefined;
|
|
15533
|
+
if (next.done) {
|
|
15534
|
+
reader.releaseLock();
|
|
15535
|
+
controller.close();
|
|
15536
|
+
} else
|
|
15537
|
+
controller.enqueue(next.value);
|
|
15538
|
+
} catch (error) {
|
|
15539
|
+
reader.releaseLock();
|
|
15540
|
+
controller.error(error);
|
|
15541
|
+
}
|
|
15542
|
+
},
|
|
15543
|
+
async cancel(reason) {
|
|
15544
|
+
try {
|
|
15545
|
+
await reader.cancel(reason);
|
|
15546
|
+
} finally {
|
|
15547
|
+
reader.releaseLock();
|
|
15548
|
+
}
|
|
15549
|
+
}
|
|
15550
|
+
}, { highWaterMark: 0 });
|
|
15551
|
+
}
|
|
15513
15552
|
function hasErrorCode(error, code) {
|
|
15514
15553
|
return typeof error === "object" && error !== null && "code" in error && error.code === code;
|
|
15515
15554
|
}
|
|
@@ -15539,6 +15578,24 @@ class LocalStorageDriver {
|
|
|
15539
15578
|
throw error;
|
|
15540
15579
|
}
|
|
15541
15580
|
}
|
|
15581
|
+
async readStream(path) {
|
|
15582
|
+
const absolutePath = this.resolvePath(path);
|
|
15583
|
+
try {
|
|
15584
|
+
if (!(await stat(absolutePath)).isFile())
|
|
15585
|
+
throw new Error("Storage path is not a file.");
|
|
15586
|
+
} catch (error) {
|
|
15587
|
+
if (hasErrorCode(error, "ENOENT"))
|
|
15588
|
+
return null;
|
|
15589
|
+
throw error;
|
|
15590
|
+
}
|
|
15591
|
+
return openStream(Bun.file(absolutePath).stream(), "ENOENT");
|
|
15592
|
+
}
|
|
15593
|
+
async writeStream(path, contents) {
|
|
15594
|
+
const absolutePath = this.resolvePath(path);
|
|
15595
|
+
await mkdir(dirname(absolutePath), { recursive: true });
|
|
15596
|
+
await Bun.write(absolutePath, contents);
|
|
15597
|
+
return path;
|
|
15598
|
+
}
|
|
15542
15599
|
async delete(path) {
|
|
15543
15600
|
try {
|
|
15544
15601
|
await unlink(this.resolvePath(path));
|
|
@@ -15569,6 +15626,33 @@ class S3StorageDriver {
|
|
|
15569
15626
|
throw error;
|
|
15570
15627
|
}
|
|
15571
15628
|
}
|
|
15629
|
+
readStream(path) {
|
|
15630
|
+
return openStream(this.client.file(path.replace(/^\/+/, "")).stream(), "NoSuchKey");
|
|
15631
|
+
}
|
|
15632
|
+
async writeStream(path, contents) {
|
|
15633
|
+
const file = this.client.file(path.replace(/^\/+/, ""));
|
|
15634
|
+
if (contents instanceof Blob)
|
|
15635
|
+
await file.write(contents);
|
|
15636
|
+
else {
|
|
15637
|
+
const writer = file.writer();
|
|
15638
|
+
try {
|
|
15639
|
+
await contents.pipeTo(new WritableStream({
|
|
15640
|
+
async write(chunk) {
|
|
15641
|
+
await writer.write(chunk);
|
|
15642
|
+
},
|
|
15643
|
+
async close() {
|
|
15644
|
+
await writer.end();
|
|
15645
|
+
}
|
|
15646
|
+
}));
|
|
15647
|
+
} catch (error) {
|
|
15648
|
+
try {
|
|
15649
|
+
await writer.end(error instanceof Error ? error : new Error(String(error)));
|
|
15650
|
+
} catch {}
|
|
15651
|
+
throw error;
|
|
15652
|
+
}
|
|
15653
|
+
}
|
|
15654
|
+
return path;
|
|
15655
|
+
}
|
|
15572
15656
|
async delete(path) {
|
|
15573
15657
|
try {
|
|
15574
15658
|
await this.client.unlink(path.replace(/^\/+/, ""));
|
|
@@ -15591,6 +15675,19 @@ class StorageManager {
|
|
|
15591
15675
|
get(path) {
|
|
15592
15676
|
return this.driver.get(path);
|
|
15593
15677
|
}
|
|
15678
|
+
streamingDriver() {
|
|
15679
|
+
return requireStreamingStorage(this.driver);
|
|
15680
|
+
}
|
|
15681
|
+
readStream(path) {
|
|
15682
|
+
if (!("readStream" in this.driver) || typeof this.driver.readStream !== "function")
|
|
15683
|
+
return Promise.reject(new TypeError("Storage driver does not support streaming reads."));
|
|
15684
|
+
return this.driver.readStream(path);
|
|
15685
|
+
}
|
|
15686
|
+
writeStream(path, contents) {
|
|
15687
|
+
if (!("writeStream" in this.driver) || typeof this.driver.writeStream !== "function")
|
|
15688
|
+
return Promise.reject(new TypeError("Storage driver does not support streaming writes."));
|
|
15689
|
+
return this.driver.writeStream(path, contents);
|
|
15690
|
+
}
|
|
15594
15691
|
delete(path) {
|
|
15595
15692
|
return this.driver.delete(path);
|
|
15596
15693
|
}
|
|
@@ -15684,25 +15781,25 @@ function runWithTenantDatabase(selected, policy, tenant, callback) {
|
|
|
15684
15781
|
}
|
|
15685
15782
|
// ../../src/core/tenant/tenantMiddleware.ts
|
|
15686
15783
|
import { createHash as createHash8 } from "crypto";
|
|
15687
|
-
import { ForbiddenError as
|
|
15784
|
+
import { ForbiddenError as ForbiddenError13 } from "@getstrata/core/errors/http";
|
|
15688
15785
|
|
|
15689
15786
|
// ../../src/core/tenant/publicTenantHost.ts
|
|
15690
15787
|
import { BlockList, isIP as isIP2 } from "net";
|
|
15691
|
-
import { ForbiddenError as
|
|
15788
|
+
import { ForbiddenError as ForbiddenError12 } from "@getstrata/core/errors/http";
|
|
15692
15789
|
function normalizeTenantHostname(authority) {
|
|
15693
15790
|
if (!authority || authority !== authority.trim() || /[\s\\/@?#%,]/.test(authority)) {
|
|
15694
|
-
throw new
|
|
15791
|
+
throw new ForbiddenError12("Invalid tenant hostname.");
|
|
15695
15792
|
}
|
|
15696
15793
|
let url;
|
|
15697
15794
|
try {
|
|
15698
15795
|
url = new URL(`http://${authority}`);
|
|
15699
15796
|
} catch {
|
|
15700
|
-
throw new
|
|
15797
|
+
throw new ForbiddenError12("Invalid tenant hostname.");
|
|
15701
15798
|
}
|
|
15702
15799
|
const hostname = url.hostname.toLowerCase().replace(/\.$/, "");
|
|
15703
15800
|
const ip = hostname.startsWith("[") ? hostname.slice(1, -1) : hostname;
|
|
15704
15801
|
if (!isIP2(ip) && (hostname.length > 253 || !hostname.split(".").every((label) => label.length > 0 && label.length <= 63 && /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/.test(label)))) {
|
|
15705
|
-
throw new
|
|
15802
|
+
throw new ForbiddenError12("Invalid tenant hostname.");
|
|
15706
15803
|
}
|
|
15707
15804
|
return hostname;
|
|
15708
15805
|
}
|
|
@@ -15725,7 +15822,7 @@ function createPublicTenantSelector(options) {
|
|
|
15725
15822
|
const authority = forwarded ?? request.headers.get("host") ?? new URL(request.url).host;
|
|
15726
15823
|
const id = await options.resolveTenantId(normalizeTenantHostname(authority));
|
|
15727
15824
|
if (id === null)
|
|
15728
|
-
throw new
|
|
15825
|
+
throw new ForbiddenError12("Tenant host not found.");
|
|
15729
15826
|
if (!Number.isSafeInteger(id) || id <= 0)
|
|
15730
15827
|
throw new Error("Public tenant resolver returned an invalid identity.");
|
|
15731
15828
|
return id;
|
|
@@ -15751,40 +15848,40 @@ async function resolveTenantForRequest(request, options, resolver, selectPublicT
|
|
|
15751
15848
|
const userTenantId = await options.userTenantId(userId);
|
|
15752
15849
|
if (!isGlobalAdmin(user)) {
|
|
15753
15850
|
if (Number.isSafeInteger(parsedHeader) && parsedHeader > 0 && parsedHeader !== userTenantId) {
|
|
15754
|
-
throw new
|
|
15851
|
+
throw new ForbiddenError13("Tenant header does not match your account.");
|
|
15755
15852
|
}
|
|
15756
15853
|
const memberTenant = await resolver(userTenantId);
|
|
15757
15854
|
if (memberTenant) {
|
|
15758
15855
|
return memberTenant;
|
|
15759
15856
|
}
|
|
15760
|
-
throw new
|
|
15857
|
+
throw new ForbiddenError13("Tenant not found.");
|
|
15761
15858
|
}
|
|
15762
15859
|
if (Number.isSafeInteger(parsedHeader) && parsedHeader > 0) {
|
|
15763
15860
|
const headerTenant = await resolver(parsedHeader);
|
|
15764
15861
|
if (headerTenant) {
|
|
15765
15862
|
return headerTenant;
|
|
15766
15863
|
}
|
|
15767
|
-
throw new
|
|
15864
|
+
throw new ForbiddenError13("Tenant not found.");
|
|
15768
15865
|
}
|
|
15769
15866
|
const adminTenant = await resolver(userTenantId);
|
|
15770
15867
|
if (adminTenant) {
|
|
15771
15868
|
return adminTenant;
|
|
15772
15869
|
}
|
|
15773
|
-
throw new
|
|
15870
|
+
throw new ForbiddenError13("Tenant not found.");
|
|
15774
15871
|
}
|
|
15775
15872
|
}
|
|
15776
15873
|
const headerTenantId = Number.isSafeInteger(parsedHeader) && parsedHeader > 0 ? parsedHeader : null;
|
|
15777
15874
|
const tenantId = hostTenantId !== null ? hostTenantId : !options.config.production && options.config.allowDevHeaders && headerTenantId !== null ? headerTenantId : DEFAULT_TENANT.id;
|
|
15778
15875
|
if (options.config.production && !selectPublicTenant) {
|
|
15779
|
-
throw new
|
|
15876
|
+
throw new ForbiddenError13("Public tenant host resolver is required.");
|
|
15780
15877
|
}
|
|
15781
15878
|
const guestTenant = await resolver(tenantId);
|
|
15782
15879
|
if (selectPublicTenant && !guestTenant)
|
|
15783
|
-
throw new
|
|
15880
|
+
throw new ForbiddenError13("Tenant not found.");
|
|
15784
15881
|
if (guestTenant) {
|
|
15785
15882
|
return guestTenant;
|
|
15786
15883
|
}
|
|
15787
|
-
throw new
|
|
15884
|
+
throw new ForbiddenError13("Tenant not found.");
|
|
15788
15885
|
}
|
|
15789
15886
|
function createTenantMiddleware(options) {
|
|
15790
15887
|
const selectPublicTenant = options.publicTenancy ? createPublicTenantSelector(options.publicTenancy) : undefined;
|
|
@@ -15792,7 +15889,7 @@ function createTenantMiddleware(options) {
|
|
|
15792
15889
|
const tenant = !options.config.enabled ? DEFAULT_TENANT : await resolveTenantForRequest(request, options, async (id) => {
|
|
15793
15890
|
const value = await options.resolveTenant(id);
|
|
15794
15891
|
if (!value)
|
|
15795
|
-
throw new
|
|
15892
|
+
throw new ForbiddenError13("Tenant not found.");
|
|
15796
15893
|
if (value.id !== id)
|
|
15797
15894
|
throw new Error("Tenant resolver returned a different tenant identity.");
|
|
15798
15895
|
return value;
|
|
@@ -16150,7 +16247,7 @@ function createTracingMiddleware(runtime) {
|
|
|
16150
16247
|
};
|
|
16151
16248
|
}
|
|
16152
16249
|
// ../../src/core/validation/rules.ts
|
|
16153
|
-
import { ValidationError as
|
|
16250
|
+
import { ValidationError as ValidationError3 } from "@getstrata/core/errors/http";
|
|
16154
16251
|
function required() {
|
|
16155
16252
|
return (field, value) => {
|
|
16156
16253
|
if (value === undefined || value === null || typeof value === "string" && value.trim() === "") {
|
|
@@ -16206,7 +16303,7 @@ function emailRule() {
|
|
|
16206
16303
|
}
|
|
16207
16304
|
function validateObject(payload, schema) {
|
|
16208
16305
|
if (payload === null || typeof payload !== "object" || Array.isArray(payload)) {
|
|
16209
|
-
throw new
|
|
16306
|
+
throw new ValidationError3("Request body must be a JSON object.");
|
|
16210
16307
|
}
|
|
16211
16308
|
const body = payload;
|
|
16212
16309
|
const errors = {};
|
|
@@ -16223,7 +16320,7 @@ function validateObject(payload, schema) {
|
|
|
16223
16320
|
}
|
|
16224
16321
|
}
|
|
16225
16322
|
if (Object.keys(errors).length > 0) {
|
|
16226
|
-
throw new
|
|
16323
|
+
throw new ValidationError3("The given data was invalid.", errors);
|
|
16227
16324
|
}
|
|
16228
16325
|
return output;
|
|
16229
16326
|
}
|
|
@@ -16653,7 +16750,7 @@ export {
|
|
|
16653
16750
|
Factory,
|
|
16654
16751
|
FailedJobRepository,
|
|
16655
16752
|
failedJobService_default as FailedJobService,
|
|
16656
|
-
|
|
16753
|
+
ForbiddenError14 as ForbiddenError,
|
|
16657
16754
|
ForeignIdColumnDefinition,
|
|
16658
16755
|
FormRequest,
|
|
16659
16756
|
GuestGuard,
|
|
@@ -16719,7 +16816,7 @@ export {
|
|
|
16719
16816
|
UnauthorizedError4 as UnauthorizedError,
|
|
16720
16817
|
UnprocessableEntityError5 as UnprocessableEntityError,
|
|
16721
16818
|
UnsupportedSchemaFeatureError,
|
|
16722
|
-
|
|
16819
|
+
ValidationError4 as ValidationError,
|
|
16723
16820
|
ViewRenderer,
|
|
16724
16821
|
WebFormRequest,
|
|
16725
16822
|
WhereBuilder,
|
|
@@ -16805,9 +16902,10 @@ export {
|
|
|
16805
16902
|
createMemoryLoginThrottleMiddleware,
|
|
16806
16903
|
createMemoryThrottleMiddleware,
|
|
16807
16904
|
createMetricsMiddleware,
|
|
16905
|
+
createModel,
|
|
16808
16906
|
createMysqlConnection,
|
|
16809
16907
|
createMysqlConnectionFromPool,
|
|
16810
|
-
createMysqlPool,
|
|
16908
|
+
createMysqlPool2 as createMysqlPool,
|
|
16811
16909
|
createNotificationDispatcher,
|
|
16812
16910
|
createOidcHandshake,
|
|
16813
16911
|
createOutboxMetricsCollector,
|
|
@@ -16853,6 +16951,7 @@ export {
|
|
|
16853
16951
|
currentTraceId,
|
|
16854
16952
|
defineFactory,
|
|
16855
16953
|
defineModel,
|
|
16954
|
+
defineProvider,
|
|
16856
16955
|
defineRepository2 as defineRepository,
|
|
16857
16956
|
defineTable,
|
|
16858
16957
|
dehydrateValue,
|
|
@@ -16984,11 +17083,8 @@ export {
|
|
|
16984
17083
|
requestMetaContext,
|
|
16985
17084
|
requireAuthCapability,
|
|
16986
17085
|
requireConfiguredSecret,
|
|
17086
|
+
requireStreamingStorage,
|
|
16987
17087
|
required,
|
|
16988
|
-
resetDnsLookupForTests,
|
|
16989
|
-
resetMemoryLoginThrottleForTests,
|
|
16990
|
-
resetMemoryThrottleForTests,
|
|
16991
|
-
resetMysqlLoaderForTests,
|
|
16992
17088
|
resolveContentSecurityPolicy,
|
|
16993
17089
|
resolveCsrfToken,
|
|
16994
17090
|
resolveCsrfTokenForRequest,
|
|
@@ -17038,8 +17134,6 @@ export {
|
|
|
17038
17134
|
serializeDate,
|
|
17039
17135
|
serverHtmxContentSecurityPolicy,
|
|
17040
17136
|
service3 as service,
|
|
17041
|
-
setDnsLookupForTests,
|
|
17042
|
-
setNodeSamlLoaderForTests,
|
|
17043
17137
|
siemEventType,
|
|
17044
17138
|
signJwt,
|
|
17045
17139
|
signWebhookBody,
|