@getstrata/core 3.0.5 → 3.0.8
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 +22 -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
|
@@ -2,6 +2,67 @@
|
|
|
2
2
|
// ../../src/core/auth/passwordConfirmCookie.ts
|
|
3
3
|
import { createHmac, timingSafeEqual } from "crypto";
|
|
4
4
|
|
|
5
|
+
// ../../src/core/config/envSchema.ts
|
|
6
|
+
function defineEnvSchema(schema) {
|
|
7
|
+
return schema;
|
|
8
|
+
}
|
|
9
|
+
function validateEnv(schema, env = process.env) {
|
|
10
|
+
const resolved = {};
|
|
11
|
+
for (const [name, rule] of Object.entries(schema)) {
|
|
12
|
+
if (rule.integer) {
|
|
13
|
+
if (rule.minimum !== undefined && !Number.isSafeInteger(rule.minimum) || rule.maximum !== undefined && !Number.isSafeInteger(rule.maximum) || rule.minimum !== undefined && rule.maximum !== undefined && rule.minimum > rule.maximum) {
|
|
14
|
+
throw new TypeError(`Environment integer rule for "${name}" has invalid bounds.`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
const rawValue = env[name];
|
|
18
|
+
if (rawValue !== undefined && typeof rawValue !== "string") {
|
|
19
|
+
throw new TypeError(`Environment variable "${name}" must be a string.`);
|
|
20
|
+
}
|
|
21
|
+
const value = rawValue === undefined || rawValue.trim() === "" ? rule.default : rawValue;
|
|
22
|
+
if (value !== undefined && typeof value !== "string") {
|
|
23
|
+
throw new TypeError(`Environment variable "${name}" must resolve to a string.`);
|
|
24
|
+
}
|
|
25
|
+
if (value === undefined || value.trim() === "") {
|
|
26
|
+
if (rule.required) {
|
|
27
|
+
throw new Error(`Missing required environment variable "${name}".`);
|
|
28
|
+
}
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (rule.integer) {
|
|
32
|
+
const completeInteger = /^[+-]?\d+$/.test(value.trim());
|
|
33
|
+
const parsed = Number.parseInt(value, 10);
|
|
34
|
+
const minimum = rule.minimum ?? Number.NEGATIVE_INFINITY;
|
|
35
|
+
const maximum = rule.maximum ?? Number.POSITIVE_INFINITY;
|
|
36
|
+
if (!completeInteger || !Number.isSafeInteger(parsed) || parsed < minimum || parsed > maximum) {
|
|
37
|
+
const comparison = minimum !== Number.NEGATIVE_INFINITY && maximum !== Number.POSITIVE_INFINITY ? `an integer between ${minimum} and ${maximum}` : maximum !== Number.POSITIVE_INFINITY ? `an integer <= ${maximum}` : minimum === Number.NEGATIVE_INFINITY ? "an integer" : `an integer >= ${minimum}`;
|
|
38
|
+
throw new Error(`Environment variable "${name}" must be ${comparison}.`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (rule.pattern && !new RegExp(rule.pattern.source, rule.pattern.flags).test(value)) {
|
|
42
|
+
throw new Error(`Environment variable "${name}" has an invalid format.`);
|
|
43
|
+
}
|
|
44
|
+
Object.defineProperty(resolved, name, {
|
|
45
|
+
value,
|
|
46
|
+
enumerable: true,
|
|
47
|
+
configurable: true,
|
|
48
|
+
writable: true
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return resolved;
|
|
52
|
+
}
|
|
53
|
+
function resolveEnv(schema, env = process.env) {
|
|
54
|
+
const validated = validateEnv(schema, env);
|
|
55
|
+
const resolved = {};
|
|
56
|
+
for (const [name, rule] of Object.entries(schema)) {
|
|
57
|
+
const value = validated[name];
|
|
58
|
+
Object.defineProperty(resolved, name, {
|
|
59
|
+
value: value === undefined ? undefined : rule.integer ? Number(value) : value,
|
|
60
|
+
enumerable: true
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return Object.freeze(resolved);
|
|
64
|
+
}
|
|
65
|
+
|
|
5
66
|
// ../../src/core/http/cookies.ts
|
|
6
67
|
function readRequestCookie(request, name) {
|
|
7
68
|
const cookies = request.cookies;
|
|
@@ -108,8 +169,13 @@ function passwordConfirmCookieName(env) {
|
|
|
108
169
|
return env.PASSWORD_CONFIRM_COOKIE_NAME?.trim() || appCookieName("password_confirmed", env);
|
|
109
170
|
}
|
|
110
171
|
function passwordConfirmTtlSeconds(env) {
|
|
111
|
-
|
|
112
|
-
|
|
172
|
+
return resolveEnv({
|
|
173
|
+
PASSWORD_CONFIRM_TIMEOUT: {
|
|
174
|
+
integer: true,
|
|
175
|
+
minimum: 1,
|
|
176
|
+
default: String(DEFAULT_PASSWORD_CONFIRM_TTL_SECONDS)
|
|
177
|
+
}
|
|
178
|
+
}, env).PASSWORD_CONFIRM_TIMEOUT;
|
|
113
179
|
}
|
|
114
180
|
function passwordConfirmOptionsFromEnvironment(env) {
|
|
115
181
|
return Object.freeze({
|
|
@@ -124,7 +190,7 @@ function missingPasswordConfirmSecret() {
|
|
|
124
190
|
}
|
|
125
191
|
function signPasswordConfirm(userId, confirmedAt, authVersion, secret) {
|
|
126
192
|
const payload = authVersion === undefined ? `${userId}.${confirmedAt}` : `v2.${userId}.${confirmedAt}.${authVersion}`;
|
|
127
|
-
const signature = createHmac("sha256", secret ?? missingPasswordConfirmSecret()).update(payload).digest("hex");
|
|
193
|
+
const signature = createHmac("sha256", secret ?? missingPasswordConfirmSecret()).update(`password-confirm:${payload}`).digest("hex");
|
|
128
194
|
return `${payload}.${signature}`;
|
|
129
195
|
}
|
|
130
196
|
function hasFreshPasswordConfirmation(request, userId, authVersion, options) {
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
// @bun
|
|
2
|
+
// ../../src/core/auth/saml/samlServiceProvider.ts
|
|
3
|
+
import { testState } from "#strata-test-state";
|
|
4
|
+
|
|
2
5
|
// ../../src/core/runtime/optionalPeer.ts
|
|
3
6
|
function missingOptionalPeer(packageName, reason, error) {
|
|
4
7
|
return new Error(`Install ${packageName} ${reason} (\`bun add ${packageName}\`).`, {
|
|
@@ -140,20 +143,16 @@ function readSamlEnvOptions(env = process.env) {
|
|
|
140
143
|
disableRequestedAuthnContext: env.SAML_DISABLE_REQUESTED_AUTHN_CONTEXT === "true"
|
|
141
144
|
};
|
|
142
145
|
}
|
|
143
|
-
var nodeSamlLoader = null;
|
|
144
146
|
async function defaultLoadNodeSaml() {
|
|
145
147
|
return await import("@node-saml/node-saml");
|
|
146
148
|
}
|
|
147
149
|
async function loadNodeSaml() {
|
|
148
150
|
try {
|
|
149
|
-
return await (nodeSamlLoader ?? defaultLoadNodeSaml)();
|
|
151
|
+
return await (testState.nodeSamlLoader ?? defaultLoadNodeSaml)();
|
|
150
152
|
} catch (error) {
|
|
151
153
|
throw missingOptionalPeer("@node-saml/node-saml", "to verify SAML assertions", error);
|
|
152
154
|
}
|
|
153
155
|
}
|
|
154
|
-
function setNodeSamlLoaderForTests(loader) {
|
|
155
|
-
nodeSamlLoader = loader;
|
|
156
|
-
}
|
|
157
156
|
|
|
158
157
|
class SamlServiceProvider {
|
|
159
158
|
client = null;
|
|
@@ -248,6 +247,5 @@ export {
|
|
|
248
247
|
SamlServiceProvider,
|
|
249
248
|
createSamlServiceProvider,
|
|
250
249
|
createSqlSamlAssertionReplayStore,
|
|
251
|
-
readSamlEnvOptions
|
|
252
|
-
setNodeSamlLoaderForTests
|
|
250
|
+
readSamlEnvOptions
|
|
253
251
|
};
|
|
@@ -2,6 +2,67 @@
|
|
|
2
2
|
// ../../src/core/auth/sessionCookie.ts
|
|
3
3
|
import { createHmac, timingSafeEqual } from "crypto";
|
|
4
4
|
|
|
5
|
+
// ../../src/core/config/envSchema.ts
|
|
6
|
+
function defineEnvSchema(schema) {
|
|
7
|
+
return schema;
|
|
8
|
+
}
|
|
9
|
+
function validateEnv(schema, env = process.env) {
|
|
10
|
+
const resolved = {};
|
|
11
|
+
for (const [name, rule] of Object.entries(schema)) {
|
|
12
|
+
if (rule.integer) {
|
|
13
|
+
if (rule.minimum !== undefined && !Number.isSafeInteger(rule.minimum) || rule.maximum !== undefined && !Number.isSafeInteger(rule.maximum) || rule.minimum !== undefined && rule.maximum !== undefined && rule.minimum > rule.maximum) {
|
|
14
|
+
throw new TypeError(`Environment integer rule for "${name}" has invalid bounds.`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
const rawValue = env[name];
|
|
18
|
+
if (rawValue !== undefined && typeof rawValue !== "string") {
|
|
19
|
+
throw new TypeError(`Environment variable "${name}" must be a string.`);
|
|
20
|
+
}
|
|
21
|
+
const value = rawValue === undefined || rawValue.trim() === "" ? rule.default : rawValue;
|
|
22
|
+
if (value !== undefined && typeof value !== "string") {
|
|
23
|
+
throw new TypeError(`Environment variable "${name}" must resolve to a string.`);
|
|
24
|
+
}
|
|
25
|
+
if (value === undefined || value.trim() === "") {
|
|
26
|
+
if (rule.required) {
|
|
27
|
+
throw new Error(`Missing required environment variable "${name}".`);
|
|
28
|
+
}
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (rule.integer) {
|
|
32
|
+
const completeInteger = /^[+-]?\d+$/.test(value.trim());
|
|
33
|
+
const parsed = Number.parseInt(value, 10);
|
|
34
|
+
const minimum = rule.minimum ?? Number.NEGATIVE_INFINITY;
|
|
35
|
+
const maximum = rule.maximum ?? Number.POSITIVE_INFINITY;
|
|
36
|
+
if (!completeInteger || !Number.isSafeInteger(parsed) || parsed < minimum || parsed > maximum) {
|
|
37
|
+
const comparison = minimum !== Number.NEGATIVE_INFINITY && maximum !== Number.POSITIVE_INFINITY ? `an integer between ${minimum} and ${maximum}` : maximum !== Number.POSITIVE_INFINITY ? `an integer <= ${maximum}` : minimum === Number.NEGATIVE_INFINITY ? "an integer" : `an integer >= ${minimum}`;
|
|
38
|
+
throw new Error(`Environment variable "${name}" must be ${comparison}.`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (rule.pattern && !new RegExp(rule.pattern.source, rule.pattern.flags).test(value)) {
|
|
42
|
+
throw new Error(`Environment variable "${name}" has an invalid format.`);
|
|
43
|
+
}
|
|
44
|
+
Object.defineProperty(resolved, name, {
|
|
45
|
+
value,
|
|
46
|
+
enumerable: true,
|
|
47
|
+
configurable: true,
|
|
48
|
+
writable: true
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return resolved;
|
|
52
|
+
}
|
|
53
|
+
function resolveEnv(schema, env = process.env) {
|
|
54
|
+
const validated = validateEnv(schema, env);
|
|
55
|
+
const resolved = {};
|
|
56
|
+
for (const [name, rule] of Object.entries(schema)) {
|
|
57
|
+
const value = validated[name];
|
|
58
|
+
Object.defineProperty(resolved, name, {
|
|
59
|
+
value: value === undefined ? undefined : rule.integer ? Number(value) : value,
|
|
60
|
+
enumerable: true
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return Object.freeze(resolved);
|
|
64
|
+
}
|
|
65
|
+
|
|
5
66
|
// ../../src/core/http/cookies.ts
|
|
6
67
|
function readRequestCookie(request, name) {
|
|
7
68
|
const cookies = request.cookies;
|
|
@@ -110,15 +171,17 @@ function createSessionReader(options) {
|
|
|
110
171
|
function sessionCookieName(env) {
|
|
111
172
|
return env.SESSION_COOKIE_NAME?.trim() || appCookieName("session", env);
|
|
112
173
|
}
|
|
113
|
-
function parsePositiveSeconds(raw, fallback) {
|
|
114
|
-
const parsed = Number.parseInt(raw ?? "", 10);
|
|
115
|
-
return Number.isInteger(parsed) && parsed > 0 ? parsed : fallback;
|
|
116
|
-
}
|
|
117
174
|
function sessionTtlSeconds(env) {
|
|
118
|
-
return
|
|
175
|
+
return resolveEnv({ SESSION_TTL_SECONDS: { integer: true, minimum: 1, default: String(SESSION_TTL_SECONDS) } }, env).SESSION_TTL_SECONDS;
|
|
119
176
|
}
|
|
120
177
|
function sessionRememberTtlSeconds(env) {
|
|
121
|
-
return
|
|
178
|
+
return resolveEnv({
|
|
179
|
+
SESSION_REMEMBER_TTL_SECONDS: {
|
|
180
|
+
integer: true,
|
|
181
|
+
minimum: 1,
|
|
182
|
+
default: String(SESSION_REMEMBER_TTL_SECONDS)
|
|
183
|
+
}
|
|
184
|
+
}, env).SESSION_REMEMBER_TTL_SECONDS;
|
|
122
185
|
}
|
|
123
186
|
function missingSessionSecret() {
|
|
124
187
|
throw new TypeError("Explicit session secret is required.");
|
|
@@ -29,6 +29,67 @@ function requireAuthCapability(value, methods, mechanism) {
|
|
|
29
29
|
// ../../src/core/auth/sessionCookie.ts
|
|
30
30
|
import { createHmac, timingSafeEqual } from "crypto";
|
|
31
31
|
|
|
32
|
+
// ../../src/core/config/envSchema.ts
|
|
33
|
+
function defineEnvSchema(schema) {
|
|
34
|
+
return schema;
|
|
35
|
+
}
|
|
36
|
+
function validateEnv(schema, env = process.env) {
|
|
37
|
+
const resolved = {};
|
|
38
|
+
for (const [name, rule] of Object.entries(schema)) {
|
|
39
|
+
if (rule.integer) {
|
|
40
|
+
if (rule.minimum !== undefined && !Number.isSafeInteger(rule.minimum) || rule.maximum !== undefined && !Number.isSafeInteger(rule.maximum) || rule.minimum !== undefined && rule.maximum !== undefined && rule.minimum > rule.maximum) {
|
|
41
|
+
throw new TypeError(`Environment integer rule for "${name}" has invalid bounds.`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const rawValue = env[name];
|
|
45
|
+
if (rawValue !== undefined && typeof rawValue !== "string") {
|
|
46
|
+
throw new TypeError(`Environment variable "${name}" must be a string.`);
|
|
47
|
+
}
|
|
48
|
+
const value = rawValue === undefined || rawValue.trim() === "" ? rule.default : rawValue;
|
|
49
|
+
if (value !== undefined && typeof value !== "string") {
|
|
50
|
+
throw new TypeError(`Environment variable "${name}" must resolve to a string.`);
|
|
51
|
+
}
|
|
52
|
+
if (value === undefined || value.trim() === "") {
|
|
53
|
+
if (rule.required) {
|
|
54
|
+
throw new Error(`Missing required environment variable "${name}".`);
|
|
55
|
+
}
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (rule.integer) {
|
|
59
|
+
const completeInteger = /^[+-]?\d+$/.test(value.trim());
|
|
60
|
+
const parsed = Number.parseInt(value, 10);
|
|
61
|
+
const minimum = rule.minimum ?? Number.NEGATIVE_INFINITY;
|
|
62
|
+
const maximum = rule.maximum ?? Number.POSITIVE_INFINITY;
|
|
63
|
+
if (!completeInteger || !Number.isSafeInteger(parsed) || parsed < minimum || parsed > maximum) {
|
|
64
|
+
const comparison = minimum !== Number.NEGATIVE_INFINITY && maximum !== Number.POSITIVE_INFINITY ? `an integer between ${minimum} and ${maximum}` : maximum !== Number.POSITIVE_INFINITY ? `an integer <= ${maximum}` : minimum === Number.NEGATIVE_INFINITY ? "an integer" : `an integer >= ${minimum}`;
|
|
65
|
+
throw new Error(`Environment variable "${name}" must be ${comparison}.`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (rule.pattern && !new RegExp(rule.pattern.source, rule.pattern.flags).test(value)) {
|
|
69
|
+
throw new Error(`Environment variable "${name}" has an invalid format.`);
|
|
70
|
+
}
|
|
71
|
+
Object.defineProperty(resolved, name, {
|
|
72
|
+
value,
|
|
73
|
+
enumerable: true,
|
|
74
|
+
configurable: true,
|
|
75
|
+
writable: true
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return resolved;
|
|
79
|
+
}
|
|
80
|
+
function resolveEnv(schema, env = process.env) {
|
|
81
|
+
const validated = validateEnv(schema, env);
|
|
82
|
+
const resolved = {};
|
|
83
|
+
for (const [name, rule] of Object.entries(schema)) {
|
|
84
|
+
const value = validated[name];
|
|
85
|
+
Object.defineProperty(resolved, name, {
|
|
86
|
+
value: value === undefined ? undefined : rule.integer ? Number(value) : value,
|
|
87
|
+
enumerable: true
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
return Object.freeze(resolved);
|
|
91
|
+
}
|
|
92
|
+
|
|
32
93
|
// ../../src/core/http/cookies.ts
|
|
33
94
|
function readRequestCookie(request, name) {
|
|
34
95
|
const cookies = request.cookies;
|
|
@@ -137,15 +198,17 @@ function createSessionReader(options) {
|
|
|
137
198
|
function sessionCookieName(env) {
|
|
138
199
|
return env.SESSION_COOKIE_NAME?.trim() || appCookieName("session", env);
|
|
139
200
|
}
|
|
140
|
-
function parsePositiveSeconds(raw, fallback) {
|
|
141
|
-
const parsed = Number.parseInt(raw ?? "", 10);
|
|
142
|
-
return Number.isInteger(parsed) && parsed > 0 ? parsed : fallback;
|
|
143
|
-
}
|
|
144
201
|
function sessionTtlSeconds(env) {
|
|
145
|
-
return
|
|
202
|
+
return resolveEnv({ SESSION_TTL_SECONDS: { integer: true, minimum: 1, default: String(SESSION_TTL_SECONDS) } }, env).SESSION_TTL_SECONDS;
|
|
146
203
|
}
|
|
147
204
|
function sessionRememberTtlSeconds(env) {
|
|
148
|
-
return
|
|
205
|
+
return resolveEnv({
|
|
206
|
+
SESSION_REMEMBER_TTL_SECONDS: {
|
|
207
|
+
integer: true,
|
|
208
|
+
minimum: 1,
|
|
209
|
+
default: String(SESSION_REMEMBER_TTL_SECONDS)
|
|
210
|
+
}
|
|
211
|
+
}, env).SESSION_REMEMBER_TTL_SECONDS;
|
|
149
212
|
}
|
|
150
213
|
function missingSessionSecret() {
|
|
151
214
|
throw new TypeError("Explicit session secret is required.");
|
|
@@ -6,6 +6,9 @@ class TaggedCache {
|
|
|
6
6
|
constructor(store, tags) {
|
|
7
7
|
this.store = store;
|
|
8
8
|
this.tags = tags;
|
|
9
|
+
if (typeof store.getOrSetTagged !== "function") {
|
|
10
|
+
throw new TypeError("Cache tags require atomic tagged loading support.");
|
|
11
|
+
}
|
|
9
12
|
}
|
|
10
13
|
async put(key, value, ttlMs) {
|
|
11
14
|
await this.store.set(key, value, ttlMs, this.tags);
|
|
@@ -14,11 +17,7 @@ class TaggedCache {
|
|
|
14
17
|
await this.store.set(key, value, null, this.tags);
|
|
15
18
|
}
|
|
16
19
|
async remember(key, callback, ttlMs) {
|
|
17
|
-
|
|
18
|
-
return this.store.getOrSetTagged(key, callback, this.tags, ttlMs);
|
|
19
|
-
const value = await this.store.getOrSet(key, callback, ttlMs);
|
|
20
|
-
await this.store.attachTags(key, this.tags);
|
|
21
|
-
return value;
|
|
20
|
+
return this.store.getOrSetTagged(key, callback, this.tags, ttlMs);
|
|
22
21
|
}
|
|
23
22
|
async flush() {
|
|
24
23
|
return this.store.flushTags(this.tags);
|
|
@@ -47,7 +47,20 @@ function validateEnv(schema, env = process.env) {
|
|
|
47
47
|
}
|
|
48
48
|
return resolved;
|
|
49
49
|
}
|
|
50
|
+
function resolveEnv(schema, env = process.env) {
|
|
51
|
+
const validated = validateEnv(schema, env);
|
|
52
|
+
const resolved = {};
|
|
53
|
+
for (const [name, rule] of Object.entries(schema)) {
|
|
54
|
+
const value = validated[name];
|
|
55
|
+
Object.defineProperty(resolved, name, {
|
|
56
|
+
value: value === undefined ? undefined : rule.integer ? Number(value) : value,
|
|
57
|
+
enumerable: true
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return Object.freeze(resolved);
|
|
61
|
+
}
|
|
50
62
|
export {
|
|
51
63
|
defineEnvSchema,
|
|
64
|
+
resolveEnv,
|
|
52
65
|
validateEnv
|
|
53
66
|
};
|
|
@@ -15,6 +15,7 @@ var FAILED_JOB_SERVICE_TOKEN = createServiceToken("core.failedJobs");
|
|
|
15
15
|
var CORE_QUEUE_TOKEN = createServiceToken("core.queue");
|
|
16
16
|
var CORE_EVENT_BUS_TOKEN = createServiceToken("core.eventBus");
|
|
17
17
|
var CORE_POLICY_GATE_TOKEN = createServiceToken("core.policyGate");
|
|
18
|
+
var CORE_POLICY_REGISTRY_TOKEN = createServiceToken("core.policyRegistry");
|
|
18
19
|
var CORE_AUTH_TOKEN = createServiceToken("core.auth");
|
|
19
20
|
var CORE_ABILITY_CHECKER_TOKEN = createServiceToken("core.abilityChecker");
|
|
20
21
|
var CORE_AUTH_USER_DIRECTORY_TOKEN = createServiceToken("core.authUserDirectory");
|
|
@@ -53,6 +54,7 @@ export {
|
|
|
53
54
|
CORE_JSON_RESPONSE_POLICY_TOKEN,
|
|
54
55
|
CORE_MAIL_TOKEN,
|
|
55
56
|
CORE_POLICY_GATE_TOKEN,
|
|
57
|
+
CORE_POLICY_REGISTRY_TOKEN,
|
|
56
58
|
CORE_PUBLIC_TENANCY_TOKEN,
|
|
57
59
|
CORE_QUEUE_TOKEN,
|
|
58
60
|
CORE_STORAGE_TOKEN,
|
|
@@ -121,7 +121,6 @@ import {
|
|
|
121
121
|
|
|
122
122
|
// ../../src/core/events/eventBusClass.ts
|
|
123
123
|
class EventBus {
|
|
124
|
-
constructor() {}
|
|
125
124
|
transactionalListeners = new Map;
|
|
126
125
|
listenTransactional(event, listener) {
|
|
127
126
|
const handlers = this.transactionalListeners.get(event) ?? new Set;
|
|
@@ -515,89 +514,8 @@ function createBoundRegistryFactory(prepared, context, ownership, configuredPool
|
|
|
515
514
|
};
|
|
516
515
|
}
|
|
517
516
|
|
|
518
|
-
// ../../src/core/
|
|
519
|
-
|
|
520
|
-
return new Error(`Install ${packageName} ${reason} (\`bun add ${packageName}\`).`, {
|
|
521
|
-
cause: error
|
|
522
|
-
});
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
// ../../src/core/database/mysqlNative.ts
|
|
526
|
-
var MYSQL_SESSION_UTC = "SET time_zone = '+00:00'";
|
|
527
|
-
var mysqlModule;
|
|
528
|
-
var mysqlPending;
|
|
529
|
-
var importMysql = defaultImportMysql;
|
|
530
|
-
async function defaultImportMysql() {
|
|
531
|
-
return import("mysql2/promise");
|
|
532
|
-
}
|
|
533
|
-
function mysqlApi(mod) {
|
|
534
|
-
if (typeof mod.createPool === "function") {
|
|
535
|
-
return mod;
|
|
536
|
-
}
|
|
537
|
-
const withDefault = mod;
|
|
538
|
-
if (typeof withDefault.default?.createPool === "function") {
|
|
539
|
-
return withDefault.default;
|
|
540
|
-
}
|
|
541
|
-
throw new Error("mysql2/promise did not export createPool.");
|
|
542
|
-
}
|
|
543
|
-
async function loadMysql() {
|
|
544
|
-
if (mysqlModule) {
|
|
545
|
-
return mysqlModule;
|
|
546
|
-
}
|
|
547
|
-
if (!mysqlPending) {
|
|
548
|
-
mysqlPending = (async () => {
|
|
549
|
-
let mod;
|
|
550
|
-
try {
|
|
551
|
-
mod = await importMysql();
|
|
552
|
-
} catch (error) {
|
|
553
|
-
mysqlPending = undefined;
|
|
554
|
-
throw missingOptionalPeer("mysql2", "to open a MySQL connection", error);
|
|
555
|
-
}
|
|
556
|
-
try {
|
|
557
|
-
mysqlModule = mysqlApi(mod);
|
|
558
|
-
return mysqlModule;
|
|
559
|
-
} catch (error) {
|
|
560
|
-
mysqlPending = undefined;
|
|
561
|
-
throw error;
|
|
562
|
-
}
|
|
563
|
-
})();
|
|
564
|
-
}
|
|
565
|
-
return mysqlPending;
|
|
566
|
-
}
|
|
567
|
-
function rowsFromResult(result) {
|
|
568
|
-
if (Array.isArray(result)) {
|
|
569
|
-
return result;
|
|
570
|
-
}
|
|
571
|
-
if (result && typeof result === "object") {
|
|
572
|
-
return [result];
|
|
573
|
-
}
|
|
574
|
-
return [];
|
|
575
|
-
}
|
|
576
|
-
async function executeMysql(target, query, params) {
|
|
577
|
-
const [result] = params.length === 0 && target.query ? await target.query(query) : await target.execute(query, [...params]);
|
|
578
|
-
return rowsFromResult(result);
|
|
579
|
-
}
|
|
580
|
-
function pinSessionToUtc(connection) {
|
|
581
|
-
connection.query(MYSQL_SESSION_UTC, (error) => {
|
|
582
|
-
if (error) {
|
|
583
|
-
console.warn("[mysql] Could not set the session time zone to UTC; DATETIME comparisons may drift.");
|
|
584
|
-
}
|
|
585
|
-
});
|
|
586
|
-
}
|
|
587
|
-
function createPoolFromModule(mysql, url, max) {
|
|
588
|
-
const pool = mysql.createPool({
|
|
589
|
-
uri: url,
|
|
590
|
-
timezone: "Z",
|
|
591
|
-
...max === undefined ? {} : { connectionLimit: max }
|
|
592
|
-
});
|
|
593
|
-
pool.on("connection", (connection) => {
|
|
594
|
-
pinSessionToUtc(connection);
|
|
595
|
-
});
|
|
596
|
-
return pool;
|
|
597
|
-
}
|
|
598
|
-
async function createMysqlPool(url, max) {
|
|
599
|
-
return createPoolFromModule(await loadMysql(), url, max);
|
|
600
|
-
}
|
|
517
|
+
// ../../src/core/database/rawMysql.ts
|
|
518
|
+
import { createMysqlPool, executeMysql } from "#strata-mysql-native";
|
|
601
519
|
|
|
602
520
|
// ../../src/core/database/nativeTransactions.ts
|
|
603
521
|
var failure = (error) => Object.freeze({ error });
|
|
@@ -990,6 +908,7 @@ function createMysqlPin(connection) {
|
|
|
990
908
|
async function createRawMysqlPool(options) {
|
|
991
909
|
const pool = await createMysqlPool(options.url, options.max);
|
|
992
910
|
let closed = false;
|
|
911
|
+
let closing;
|
|
993
912
|
let retainedCleanup;
|
|
994
913
|
const acquire = async () => {
|
|
995
914
|
if (closed)
|
|
@@ -1073,11 +992,16 @@ async function createRawMysqlPool(options) {
|
|
|
1073
992
|
return { ok: false, error, disposition: "unknown", cleanupErrors: [acknowledgement.error] };
|
|
1074
993
|
}
|
|
1075
994
|
},
|
|
1076
|
-
|
|
1077
|
-
if (
|
|
1078
|
-
|
|
1079
|
-
await pool.end();
|
|
995
|
+
close() {
|
|
996
|
+
if (closing)
|
|
997
|
+
return closing;
|
|
1080
998
|
closed = true;
|
|
999
|
+
closing = Promise.resolve().then(async () => {
|
|
1000
|
+
if (retainedCleanup)
|
|
1001
|
+
throw retainedCleanup.error;
|
|
1002
|
+
await pool.end();
|
|
1003
|
+
});
|
|
1004
|
+
return closing;
|
|
1081
1005
|
}
|
|
1082
1006
|
});
|
|
1083
1007
|
}
|
|
@@ -1151,6 +1075,7 @@ function postgresPin(connection) {
|
|
|
1151
1075
|
}
|
|
1152
1076
|
function createRawPostgresPoolFromNative(pool) {
|
|
1153
1077
|
let closed = false;
|
|
1078
|
+
let closing;
|
|
1154
1079
|
return Object.freeze({
|
|
1155
1080
|
dialect: dialectFor("pgsql"),
|
|
1156
1081
|
capabilities: Object.freeze({
|
|
@@ -1183,9 +1108,12 @@ function createRawPostgresPoolFromNative(pool) {
|
|
|
1183
1108
|
return { ok: false, error, disposition: "not-acquired" };
|
|
1184
1109
|
}
|
|
1185
1110
|
},
|
|
1186
|
-
|
|
1187
|
-
|
|
1111
|
+
close() {
|
|
1112
|
+
if (closing)
|
|
1113
|
+
return closing;
|
|
1188
1114
|
closed = true;
|
|
1115
|
+
closing = Promise.resolve().then(() => pool.close());
|
|
1116
|
+
return closing;
|
|
1189
1117
|
}
|
|
1190
1118
|
});
|
|
1191
1119
|
}
|
|
@@ -214,7 +214,11 @@ class Factory {
|
|
|
214
214
|
return this.instance.behavior.persist(values);
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
|
+
function createFactory(behavior) {
|
|
218
|
+
return Factory.from(defineFactory({ construct: () => behavior }));
|
|
219
|
+
}
|
|
217
220
|
export {
|
|
218
221
|
Factory,
|
|
222
|
+
createFactory,
|
|
219
223
|
defineFactory
|
|
220
224
|
};
|