@getstrata/core 0.5.48 → 0.5.50
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 +25 -0
- package/dist/core/auth/membershipContextMiddleware.d.ts +1 -1
- package/dist/core/auth/scimAuthMiddleware.d.ts +1 -1
- package/dist/core/database/errors.d.ts +1 -1
- package/dist/core/facades/index.d.ts +1 -1
- package/dist/core/http/authMiddleware.d.ts +2 -2
- package/dist/core/http/authorizeMiddleware.d.ts +2 -2
- package/dist/core/http/index.d.ts +1 -1
- package/dist/core/http/requireAuthMiddleware.d.ts +1 -1
- package/dist/core/http/requireWebAuthMiddleware.d.ts +1 -1
- package/dist/core/http/securedRouteModelBinding.d.ts +1 -1
- package/dist/core/logging/requestLoggingMiddleware.d.ts +1 -1
- package/dist/core/queue/failedJobRepository.d.ts +1 -1
- package/dist/core/queue/failedJobTable.d.ts +1 -1
- package/dist/core/runtime/applicationRegistry.d.ts +3 -3
- package/dist/core/tracing/tracingMiddleware.d.ts +1 -1
- package/dist/entries/audit/exportAuditLogs.js +9 -175
- package/dist/entries/auth/membershipMiddleware.js +2 -74
- package/dist/entries/auth/scimAuthMiddleware.js +10 -96
- package/dist/entries/auth/sessionGuard.js +138 -2732
- package/dist/entries/database/errors.js +6 -66
- package/dist/entries/database/model.js +2 -65
- package/dist/entries/http/authMiddleware.js +1 -23
- package/dist/entries/http/authorizeMiddleware.js +2 -89
- package/dist/entries/http/bodySizeLimitMiddleware.js +1 -66
- package/dist/entries/http/conditionalResponse.js +3 -66
- package/dist/entries/http/csrfMiddleware.js +2 -65
- package/dist/entries/http/etag.js +3 -66
- package/dist/entries/http/formRequest.js +5 -110
- package/dist/entries/http/pagination.js +8 -113
- package/dist/entries/http/parseFormBody.js +1 -66
- package/dist/entries/http/parseMultipartUpload.js +3 -66
- package/dist/entries/http/requireAbilityMiddleware.js +2 -89
- package/dist/entries/http/requireAuthMiddleware.js +1 -66
- package/dist/entries/http/requireGlobalAdminMiddleware.js +4 -128
- package/dist/entries/http/requireWebAuthMiddleware.js +2 -65
- package/dist/entries/http/routeModelBinding.js +3 -111
- package/dist/entries/http/securedRouteModelBinding.js +15 -206
- package/dist/entries/http/throttleMiddleware.js +2 -47
- package/dist/entries/http/webErrorResponse.js +222 -2732
- package/dist/entries/http/webFormRequest.js +8 -112
- package/dist/entries/jobs/dispatchWebhookJob.js +5 -174
- package/dist/entries/logging/requestLoggingMiddleware.js +2 -25
- package/dist/entries/queue/createAppQueue.js +13 -2332
- package/dist/entries/queue/failedJobRepository.js +4 -2324
- package/dist/entries/queue/jobRunner.js +9 -8
- package/dist/entries/queue/publicQueue.js +13 -2332
- package/dist/entries/queue/queueMetrics.js +13 -2332
- package/dist/entries/queue/redisQueue.js +9 -8
- package/dist/entries/security/safeFetch.js +1 -68
- package/dist/entries/security/safeUrl.js +1 -68
- package/dist/entries/security/stripeWebhook.js +1 -68
- package/dist/entries/tenant/databaseTenantContext.js +3 -105
- package/dist/entries/tenant/tenantDatabaseScope.js +3 -61
- package/dist/entries/validation/rules.js +1 -66
- package/dist/entries/view.js +159 -2735
- package/package.json +2 -2
|
@@ -39,15 +39,16 @@ function readSharedJobRegistry() {
|
|
|
39
39
|
}
|
|
40
40
|
var jobRegistry = readSharedJobRegistry();
|
|
41
41
|
|
|
42
|
-
// ../../src/core/contracts/serviceTokens.ts
|
|
43
|
-
var CORE_CONFIG_TOKEN = "core.config";
|
|
44
|
-
var CORE_CACHE_TOKEN = "core.cache";
|
|
45
|
-
var CORE_QUEUE_TOKEN = "core.queue";
|
|
46
|
-
var CORE_EVENT_BUS_TOKEN = "core.eventBus";
|
|
47
|
-
var CORE_POLICY_GATE_TOKEN = "core.policyGate";
|
|
48
|
-
var CORE_AUTH_TOKEN = "core.auth";
|
|
49
|
-
var CORE_TOKEN_SERVICE_TOKEN = "core.tokenService";
|
|
50
42
|
// ../../src/bootstrap/config.ts
|
|
43
|
+
import {
|
|
44
|
+
CORE_AUTH_TOKEN,
|
|
45
|
+
CORE_CACHE_TOKEN,
|
|
46
|
+
CORE_CONFIG_TOKEN,
|
|
47
|
+
CORE_EVENT_BUS_TOKEN,
|
|
48
|
+
CORE_POLICY_GATE_TOKEN,
|
|
49
|
+
CORE_QUEUE_TOKEN,
|
|
50
|
+
CORE_TOKEN_SERVICE_TOKEN
|
|
51
|
+
} from "@getstrata/core/contracts/serviceTokens";
|
|
51
52
|
var DEFAULT_QUEUE_DRIVER = "sync";
|
|
52
53
|
|
|
53
54
|
// ../../src/config/queue.ts
|
|
@@ -10,74 +10,7 @@ var appConfig = {
|
|
|
10
10
|
|
|
11
11
|
// ../../src/core/security/safeUrl.ts
|
|
12
12
|
import { lookup as dnsLookupImpl } from "dns/promises";
|
|
13
|
-
|
|
14
|
-
// ../../src/core/errors/http.ts
|
|
15
|
-
class HttpError extends Error {
|
|
16
|
-
status;
|
|
17
|
-
details;
|
|
18
|
-
constructor(status, message, details) {
|
|
19
|
-
super(message);
|
|
20
|
-
this.name = new.target.name;
|
|
21
|
-
this.status = status;
|
|
22
|
-
this.details = details;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
class BadRequestError extends HttpError {
|
|
27
|
-
constructor(message = "Bad Request", details) {
|
|
28
|
-
super(400, message, details);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
class NotFoundError extends HttpError {
|
|
33
|
-
constructor(message = "Not Found", details) {
|
|
34
|
-
super(404, message, details);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
class ConflictError extends HttpError {
|
|
39
|
-
constructor(message = "Conflict", details) {
|
|
40
|
-
super(409, message, details);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
class UnprocessableEntityError extends HttpError {
|
|
45
|
-
constructor(message = "Unprocessable Entity", details) {
|
|
46
|
-
super(422, message, details);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
class ValidationError extends HttpError {
|
|
51
|
-
constructor(message = "Validation failed", details) {
|
|
52
|
-
super(422, message, details);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
class ForbiddenError extends HttpError {
|
|
57
|
-
constructor(message = "Forbidden", details) {
|
|
58
|
-
super(403, message, details);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
class UnauthorizedError extends HttpError {
|
|
63
|
-
constructor(message = "Unauthorized", details) {
|
|
64
|
-
super(401, message, details);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
class PayloadTooLargeError extends HttpError {
|
|
69
|
-
constructor(message = "Payload Too Large", details) {
|
|
70
|
-
super(413, message, details);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
class PreconditionFailedError extends HttpError {
|
|
75
|
-
constructor(message = "Precondition Failed", details) {
|
|
76
|
-
super(412, message, details);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// ../../src/core/security/safeUrl.ts
|
|
13
|
+
import { BadRequestError } from "@getstrata/core/errors/http";
|
|
81
14
|
var dnsLookup = dnsLookupImpl;
|
|
82
15
|
var BLOCKED_HOSTNAMES = new Set([
|
|
83
16
|
"localhost",
|
|
@@ -1,74 +1,7 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// ../../src/core/security/safeUrl.ts
|
|
3
3
|
import { lookup as dnsLookupImpl } from "dns/promises";
|
|
4
|
-
|
|
5
|
-
// ../../src/core/errors/http.ts
|
|
6
|
-
class HttpError extends Error {
|
|
7
|
-
status;
|
|
8
|
-
details;
|
|
9
|
-
constructor(status, message, details) {
|
|
10
|
-
super(message);
|
|
11
|
-
this.name = new.target.name;
|
|
12
|
-
this.status = status;
|
|
13
|
-
this.details = details;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
class BadRequestError extends HttpError {
|
|
18
|
-
constructor(message = "Bad Request", details) {
|
|
19
|
-
super(400, message, details);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
class NotFoundError extends HttpError {
|
|
24
|
-
constructor(message = "Not Found", details) {
|
|
25
|
-
super(404, message, details);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
class ConflictError extends HttpError {
|
|
30
|
-
constructor(message = "Conflict", details) {
|
|
31
|
-
super(409, message, details);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
class UnprocessableEntityError extends HttpError {
|
|
36
|
-
constructor(message = "Unprocessable Entity", details) {
|
|
37
|
-
super(422, message, details);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
class ValidationError extends HttpError {
|
|
42
|
-
constructor(message = "Validation failed", details) {
|
|
43
|
-
super(422, message, details);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
class ForbiddenError extends HttpError {
|
|
48
|
-
constructor(message = "Forbidden", details) {
|
|
49
|
-
super(403, message, details);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
class UnauthorizedError extends HttpError {
|
|
54
|
-
constructor(message = "Unauthorized", details) {
|
|
55
|
-
super(401, message, details);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
class PayloadTooLargeError extends HttpError {
|
|
60
|
-
constructor(message = "Payload Too Large", details) {
|
|
61
|
-
super(413, message, details);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
class PreconditionFailedError extends HttpError {
|
|
66
|
-
constructor(message = "Precondition Failed", details) {
|
|
67
|
-
super(412, message, details);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// ../../src/core/security/safeUrl.ts
|
|
4
|
+
import { BadRequestError } from "@getstrata/core/errors/http";
|
|
72
5
|
var dnsLookup = dnsLookupImpl;
|
|
73
6
|
var BLOCKED_HOSTNAMES = new Set([
|
|
74
7
|
"localhost",
|
|
@@ -1,74 +1,7 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// ../../src/core/security/stripeWebhook.ts
|
|
3
3
|
import { createHmac, timingSafeEqual } from "crypto";
|
|
4
|
-
|
|
5
|
-
// ../../src/core/errors/http.ts
|
|
6
|
-
class HttpError extends Error {
|
|
7
|
-
status;
|
|
8
|
-
details;
|
|
9
|
-
constructor(status, message, details) {
|
|
10
|
-
super(message);
|
|
11
|
-
this.name = new.target.name;
|
|
12
|
-
this.status = status;
|
|
13
|
-
this.details = details;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
class BadRequestError extends HttpError {
|
|
18
|
-
constructor(message = "Bad Request", details) {
|
|
19
|
-
super(400, message, details);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
class NotFoundError extends HttpError {
|
|
24
|
-
constructor(message = "Not Found", details) {
|
|
25
|
-
super(404, message, details);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
class ConflictError extends HttpError {
|
|
30
|
-
constructor(message = "Conflict", details) {
|
|
31
|
-
super(409, message, details);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
class UnprocessableEntityError extends HttpError {
|
|
36
|
-
constructor(message = "Unprocessable Entity", details) {
|
|
37
|
-
super(422, message, details);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
class ValidationError extends HttpError {
|
|
42
|
-
constructor(message = "Validation failed", details) {
|
|
43
|
-
super(422, message, details);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
class ForbiddenError extends HttpError {
|
|
48
|
-
constructor(message = "Forbidden", details) {
|
|
49
|
-
super(403, message, details);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
class UnauthorizedError extends HttpError {
|
|
54
|
-
constructor(message = "Unauthorized", details) {
|
|
55
|
-
super(401, message, details);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
class PayloadTooLargeError extends HttpError {
|
|
60
|
-
constructor(message = "Payload Too Large", details) {
|
|
61
|
-
super(413, message, details);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
class PreconditionFailedError extends HttpError {
|
|
66
|
-
constructor(message = "Precondition Failed", details) {
|
|
67
|
-
super(412, message, details);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// ../../src/core/security/stripeWebhook.ts
|
|
4
|
+
import { UnauthorizedError } from "@getstrata/core/errors/http";
|
|
72
5
|
function verifyStripeWebhookSignature(rawBody, signatureHeader, secret, toleranceSeconds = 300) {
|
|
73
6
|
if (!signatureHeader?.trim()) {
|
|
74
7
|
throw new UnauthorizedError("Missing Stripe signature.");
|
|
@@ -1,114 +1,12 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
// ../../src/core/database/boundConnection.ts
|
|
3
|
-
var boundConnectionHolder = {
|
|
4
|
-
connection: null
|
|
5
|
-
};
|
|
6
|
-
function bindDatabaseConnection(connection) {
|
|
7
|
-
boundConnectionHolder.connection = connection;
|
|
8
|
-
}
|
|
9
|
-
function getBoundDatabaseConnection() {
|
|
10
|
-
return boundConnectionHolder.connection;
|
|
11
|
-
}
|
|
12
|
-
function resetBoundDatabaseConnection() {
|
|
13
|
-
boundConnectionHolder.connection = null;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// ../../src/core/runtime/asyncContextStore.ts
|
|
17
|
-
import { AsyncLocalStorage } from "async_hooks";
|
|
18
|
-
function createAsyncContextStore(key) {
|
|
19
|
-
const symbol = Symbol.for(key);
|
|
20
|
-
const globalRecord = globalThis;
|
|
21
|
-
const existing = globalRecord[symbol];
|
|
22
|
-
if (existing) {
|
|
23
|
-
return existing;
|
|
24
|
-
}
|
|
25
|
-
const store = new AsyncLocalStorage;
|
|
26
|
-
globalRecord[symbol] = store;
|
|
27
|
-
return store;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// ../../src/core/database/connectionContext.ts
|
|
31
|
-
var activeConnection = createAsyncContextStore("@getstrata/databaseConnectionContext");
|
|
32
|
-
function runWithDatabaseConnection(connection, callback) {
|
|
33
|
-
return activeConnection.run(connection, callback);
|
|
34
|
-
}
|
|
35
|
-
function getActiveDatabaseConnection(fallback) {
|
|
36
|
-
return activeConnection.getStore() ?? fallback;
|
|
37
|
-
}
|
|
38
|
-
function hasActiveDatabaseConnection() {
|
|
39
|
-
return activeConnection.getStore() !== undefined;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// ../../src/core/database/queryProxy.ts
|
|
43
|
-
var POOL_CONNECTION_METHODS = new Set(["begin", "close", "connect"]);
|
|
44
|
-
function createDatabaseQueryProxy(pool) {
|
|
45
|
-
function resolveDatabase() {
|
|
46
|
-
return getActiveDatabaseConnection(pool);
|
|
47
|
-
}
|
|
48
|
-
function resolveDatabaseForProperty(property) {
|
|
49
|
-
if (typeof property === "string" && POOL_CONNECTION_METHODS.has(property)) {
|
|
50
|
-
return pool;
|
|
51
|
-
}
|
|
52
|
-
return resolveDatabase();
|
|
53
|
-
}
|
|
54
|
-
return new Proxy(function database() {}, {
|
|
55
|
-
apply(_target, _thisArg, args) {
|
|
56
|
-
return resolveDatabase()(...args);
|
|
57
|
-
},
|
|
58
|
-
get(_target, property) {
|
|
59
|
-
const connection = resolveDatabaseForProperty(property);
|
|
60
|
-
const value = connection[property];
|
|
61
|
-
return typeof value === "function" ? value.bind(connection) : value;
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// ../../src/core/database/defaultConnection.ts
|
|
67
|
-
var defaultPool = {
|
|
68
|
-
connection: null
|
|
69
|
-
};
|
|
70
|
-
var defaultQuery = {
|
|
71
|
-
connection: null
|
|
72
|
-
};
|
|
73
|
-
function registerDefaultDatabasePool(connection) {
|
|
74
|
-
defaultPool.connection = connection;
|
|
75
|
-
defaultQuery.connection = createDatabaseQueryProxy(connection);
|
|
76
|
-
}
|
|
77
|
-
function getDefaultDatabasePool() {
|
|
78
|
-
if (!defaultPool.connection) {
|
|
79
|
-
throw new Error("Default database pool is not registered. Call registerDefaultDatabasePool() during app bootstrap.");
|
|
80
|
-
}
|
|
81
|
-
return defaultPool.connection;
|
|
82
|
-
}
|
|
83
|
-
function getDefaultDatabaseQuery() {
|
|
84
|
-
if (!defaultQuery.connection) {
|
|
85
|
-
throw new Error("Default database query handle is not registered. Call registerDefaultDatabasePool() during app bootstrap.");
|
|
86
|
-
}
|
|
87
|
-
return defaultQuery.connection;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// ../../src/core/database/repositoryConnection.ts
|
|
91
|
-
function resolveRepositoryConnection() {
|
|
92
|
-
return getBoundDatabaseConnection() ?? getDefaultDatabaseQuery();
|
|
93
|
-
}
|
|
94
|
-
var repositoryConnection = new Proxy(function repositoryConnection2() {}, {
|
|
95
|
-
apply(_target, _thisArg, args) {
|
|
96
|
-
return resolveRepositoryConnection()(...args);
|
|
97
|
-
},
|
|
98
|
-
get(_target, property) {
|
|
99
|
-
const connection = resolveRepositoryConnection();
|
|
100
|
-
const value = connection[property];
|
|
101
|
-
return typeof value === "function" ? value.bind(connection) : value;
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
|
|
105
2
|
// ../../src/core/tenant/databaseTenantContext.ts
|
|
3
|
+
import { repositoryConnection as db } from "@getstrata/core/database/repositoryConnection";
|
|
106
4
|
async function runWithMigrationBypass(callback) {
|
|
107
|
-
await
|
|
5
|
+
await db`SELECT set_config('app.bypass_rls', 'true', false)`;
|
|
108
6
|
try {
|
|
109
7
|
return await callback();
|
|
110
8
|
} finally {
|
|
111
|
-
await
|
|
9
|
+
await db`SELECT set_config('app.bypass_rls', 'false', false)`;
|
|
112
10
|
}
|
|
113
11
|
}
|
|
114
12
|
export {
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
// @bun
|
|
2
|
+
// ../../src/core/tenant/tenantDatabaseScope.ts
|
|
3
|
+
import { getDefaultDatabasePool } from "@getstrata/core/database/defaultConnection";
|
|
4
|
+
|
|
2
5
|
// ../../src/core/runtime/asyncContextStore.ts
|
|
3
6
|
import { AsyncLocalStorage } from "async_hooks";
|
|
4
7
|
function createAsyncContextStore(key) {
|
|
@@ -25,54 +28,6 @@ function hasActiveDatabaseConnection() {
|
|
|
25
28
|
return activeConnection.getStore() !== undefined;
|
|
26
29
|
}
|
|
27
30
|
|
|
28
|
-
// ../../src/core/database/queryProxy.ts
|
|
29
|
-
var POOL_CONNECTION_METHODS = new Set(["begin", "close", "connect"]);
|
|
30
|
-
function createDatabaseQueryProxy(pool) {
|
|
31
|
-
function resolveDatabase() {
|
|
32
|
-
return getActiveDatabaseConnection(pool);
|
|
33
|
-
}
|
|
34
|
-
function resolveDatabaseForProperty(property) {
|
|
35
|
-
if (typeof property === "string" && POOL_CONNECTION_METHODS.has(property)) {
|
|
36
|
-
return pool;
|
|
37
|
-
}
|
|
38
|
-
return resolveDatabase();
|
|
39
|
-
}
|
|
40
|
-
return new Proxy(function database() {}, {
|
|
41
|
-
apply(_target, _thisArg, args) {
|
|
42
|
-
return resolveDatabase()(...args);
|
|
43
|
-
},
|
|
44
|
-
get(_target, property) {
|
|
45
|
-
const connection = resolveDatabaseForProperty(property);
|
|
46
|
-
const value = connection[property];
|
|
47
|
-
return typeof value === "function" ? value.bind(connection) : value;
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// ../../src/core/database/defaultConnection.ts
|
|
53
|
-
var defaultPool = {
|
|
54
|
-
connection: null
|
|
55
|
-
};
|
|
56
|
-
var defaultQuery = {
|
|
57
|
-
connection: null
|
|
58
|
-
};
|
|
59
|
-
function registerDefaultDatabasePool(connection) {
|
|
60
|
-
defaultPool.connection = connection;
|
|
61
|
-
defaultQuery.connection = createDatabaseQueryProxy(connection);
|
|
62
|
-
}
|
|
63
|
-
function getDefaultDatabasePool() {
|
|
64
|
-
if (!defaultPool.connection) {
|
|
65
|
-
throw new Error("Default database pool is not registered. Call registerDefaultDatabasePool() during app bootstrap.");
|
|
66
|
-
}
|
|
67
|
-
return defaultPool.connection;
|
|
68
|
-
}
|
|
69
|
-
function getDefaultDatabaseQuery() {
|
|
70
|
-
if (!defaultQuery.connection) {
|
|
71
|
-
throw new Error("Default database query handle is not registered. Call registerDefaultDatabasePool() during app bootstrap.");
|
|
72
|
-
}
|
|
73
|
-
return defaultQuery.connection;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
31
|
// ../../src/core/tenant/tenantContext.ts
|
|
77
32
|
var tenantContext = createAsyncContextStore("@getstrata/tenantContext");
|
|
78
33
|
function runWithTenant(tenant, callback) {
|
|
@@ -81,19 +36,6 @@ function runWithTenant(tenant, callback) {
|
|
|
81
36
|
function currentTenant() {
|
|
82
37
|
return tenantContext.getStore() ?? null;
|
|
83
38
|
}
|
|
84
|
-
function currentTenantId() {
|
|
85
|
-
return currentTenant()?.id ?? 1;
|
|
86
|
-
}
|
|
87
|
-
function rateLimitMultiplierForPlan(plan) {
|
|
88
|
-
switch (plan) {
|
|
89
|
-
case "enterprise":
|
|
90
|
-
return 4;
|
|
91
|
-
case "pro":
|
|
92
|
-
return 2;
|
|
93
|
-
default:
|
|
94
|
-
return 1;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
39
|
|
|
98
40
|
// ../../src/core/tenant/tenantDatabaseScope.ts
|
|
99
41
|
async function applyTenantContextToTransaction(transaction, tenantId) {
|
|
@@ -1,71 +1,6 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
// ../../src/core/errors/http.ts
|
|
3
|
-
class HttpError extends Error {
|
|
4
|
-
status;
|
|
5
|
-
details;
|
|
6
|
-
constructor(status, message, details) {
|
|
7
|
-
super(message);
|
|
8
|
-
this.name = new.target.name;
|
|
9
|
-
this.status = status;
|
|
10
|
-
this.details = details;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
class BadRequestError extends HttpError {
|
|
15
|
-
constructor(message = "Bad Request", details) {
|
|
16
|
-
super(400, message, details);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
class NotFoundError extends HttpError {
|
|
21
|
-
constructor(message = "Not Found", details) {
|
|
22
|
-
super(404, message, details);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
class ConflictError extends HttpError {
|
|
27
|
-
constructor(message = "Conflict", details) {
|
|
28
|
-
super(409, message, details);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
class UnprocessableEntityError extends HttpError {
|
|
33
|
-
constructor(message = "Unprocessable Entity", details) {
|
|
34
|
-
super(422, message, details);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
class ValidationError extends HttpError {
|
|
39
|
-
constructor(message = "Validation failed", details) {
|
|
40
|
-
super(422, message, details);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
class ForbiddenError extends HttpError {
|
|
45
|
-
constructor(message = "Forbidden", details) {
|
|
46
|
-
super(403, message, details);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
class UnauthorizedError extends HttpError {
|
|
51
|
-
constructor(message = "Unauthorized", details) {
|
|
52
|
-
super(401, message, details);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
class PayloadTooLargeError extends HttpError {
|
|
57
|
-
constructor(message = "Payload Too Large", details) {
|
|
58
|
-
super(413, message, details);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
class PreconditionFailedError extends HttpError {
|
|
63
|
-
constructor(message = "Precondition Failed", details) {
|
|
64
|
-
super(412, message, details);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
2
|
// ../../src/core/validation/rules.ts
|
|
3
|
+
import { ValidationError } from "@getstrata/core/errors/http";
|
|
69
4
|
function required() {
|
|
70
5
|
return (field, value) => {
|
|
71
6
|
if (value === undefined || value === null || typeof value === "string" && value.trim() === "") {
|