@getstrata/core 1.0.3 → 1.0.5

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.
Files changed (51) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +1 -1
  3. package/dist/core/runtime/appEnv.d.ts +16 -2
  4. package/dist/core/runtime/appKeyPrefix.d.ts +8 -1
  5. package/dist/entries/audit/exportAuditLogs.js +83 -18
  6. package/dist/entries/audit/siemFormatter.js +32 -3
  7. package/dist/entries/auth/intendedUrlCookie.js +33 -4
  8. package/dist/entries/auth/jwt.js +36 -4
  9. package/dist/entries/auth/jwtGuard.js +36 -4
  10. package/dist/entries/auth/oauth/providers.js +32 -3
  11. package/dist/entries/auth/oauth/samlProvider.js +32 -3
  12. package/dist/entries/auth/passwordConfirmCookie.js +35 -6
  13. package/dist/entries/auth/sessionCookie.js +35 -6
  14. package/dist/entries/auth/sessionGuard.js +35 -6
  15. package/dist/entries/auth/tokenHash.js +33 -4
  16. package/dist/entries/cache/createCacheStore.js +32 -3
  17. package/dist/entries/database/mysqlConnection.js +1 -132
  18. package/dist/entries/facades.js +32 -3
  19. package/dist/entries/http/corsMiddleware.js +16 -1
  20. package/dist/entries/http/csrfMiddleware.js +34 -5
  21. package/dist/entries/http/csrfToken.js +34 -5
  22. package/dist/entries/http/flashMiddleware.js +33 -4
  23. package/dist/entries/http/flashSession.js +33 -4
  24. package/dist/entries/http/loginThrottleMiddleware.js +1 -373
  25. package/dist/entries/http/memoryThrottleMiddleware.js +32 -58
  26. package/dist/entries/http/response.js +16 -56
  27. package/dist/entries/http/scimThrottleMiddleware.js +32 -3
  28. package/dist/entries/http/securityHeadersMiddleware.js +32 -3
  29. package/dist/entries/http/signedUrl.js +33 -4
  30. package/dist/entries/http/throttleMiddleware.js +32 -58
  31. package/dist/entries/http/webErrorResponse.js +1 -401
  32. package/dist/entries/jobs/exportAuditLogsJob.js +83 -18
  33. package/dist/entries/lifecycle/gracefulShutdown.js +1 -50
  34. package/dist/entries/mail/mailer.js +32 -3
  35. package/dist/entries/openapi/generator.js +32 -3
  36. package/dist/entries/queue/createAppQueue.js +32 -3
  37. package/dist/entries/queue/publicQueue.js +32 -3
  38. package/dist/entries/queue/queueMetrics.js +32 -3
  39. package/dist/entries/queue/redisQueue.js +32 -3
  40. package/dist/entries/runtime/appEnv.js +18 -1
  41. package/dist/entries/runtime/appKeyPrefix.js +1 -70
  42. package/dist/entries/security/oauthState.js +33 -4
  43. package/dist/entries/security/safeFetch.js +32 -9
  44. package/dist/entries/security/safeUrl.js +1 -105
  45. package/dist/entries/security/totp.js +32 -3
  46. package/dist/entries/tenant/databaseTenantContext.js +48 -6
  47. package/dist/entries/tracing/tracingMiddleware.js +32 -3
  48. package/dist/entries/view.js +1 -778
  49. package/dist/framework/public-api.d.ts +28 -19
  50. package/dist/index.js +448 -53
  51. package/package.json +2 -2
@@ -110,8 +110,23 @@ import { toHttpError as toHttpError2, ValidationError } from "@getstrata/core/er
110
110
  import { appLogger } from "@getstrata/core/logging/logger";
111
111
 
112
112
  // ../../src/core/runtime/appEnv.ts
113
+ var NON_PRODUCTION_APP_ENVS = new Set(["local", "development", "dev", "test", "testing", "ci"]);
114
+ function normalizeEnvValue(value) {
115
+ return (value ?? "").trim().toLowerCase();
116
+ }
113
117
  function isProductionEnv(env = process.env) {
114
- return env.APP_ENV === "production" || env.NODE_ENV === "production";
118
+ const appEnv = normalizeEnvValue(env.APP_ENV);
119
+ const nodeEnv = normalizeEnvValue(env.NODE_ENV);
120
+ if (appEnv === "production" || nodeEnv === "production") {
121
+ return true;
122
+ }
123
+ if (appEnv === "") {
124
+ return false;
125
+ }
126
+ return !NON_PRODUCTION_APP_ENVS.has(appEnv);
127
+ }
128
+ function envFlagEnabled(value) {
129
+ return value === "true";
115
130
  }
116
131
 
117
132
  // ../../src/core/runtime/frontendMode.ts
@@ -157,9 +172,6 @@ function readSpaPrefix() {
157
172
  import { currentRequestMeta } from "@getstrata/core/http/requestMetaContext";
158
173
 
159
174
  // ../../src/core/view/htmlResponse.ts
160
- function withCharset(contentType) {
161
- return contentType.includes("charset=") ? contentType : `${contentType}; charset=utf-8`;
162
- }
163
175
  function htmlResponse(html, init = {}) {
164
176
  return new Response(html, {
165
177
  status: init.status ?? 200,
@@ -169,42 +181,9 @@ function htmlResponse(html, init = {}) {
169
181
  }
170
182
  });
171
183
  }
172
- function isHtmxRequest(request) {
173
- return request.headers.get("HX-Request") === "true";
174
- }
175
- function redirectResponse(location, status = 302) {
176
- return new Response(null, {
177
- status,
178
- headers: {
179
- Location: location
180
- }
181
- });
182
- }
183
- function textResponse(body, init = {}) {
184
- return new Response(body, {
185
- status: init.status ?? 200,
186
- headers: {
187
- "Content-Type": "text/plain; charset=utf-8"
188
- }
189
- });
190
- }
191
- function xmlResponse(body, init = {}) {
192
- return new Response(body, {
193
- status: init.status ?? 200,
194
- headers: {
195
- "Content-Type": withCharset(init.contentType ?? "application/xml")
196
- }
197
- });
198
- }
199
- function rssResponse(body, init = {}) {
200
- return xmlResponse(body, { ...init, contentType: "application/rss+xml" });
201
- }
202
184
 
203
185
  // ../../src/core/view/webErrorView.ts
204
186
  var configuredErrorView = {};
205
- function configureWebErrorView(options) {
206
- configuredErrorView = { ...options };
207
- }
208
187
  function escapeHtml(value) {
209
188
  return value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;");
210
189
  }
@@ -238,15 +217,6 @@ function renderKernelErrorChrome(input) {
238
217
  </html>
239
218
  `;
240
219
  }
241
- function errorTemplateName(status) {
242
- if (status === 404) {
243
- return "errors/not-found";
244
- }
245
- if (status === 403) {
246
- return "errors/forbidden";
247
- }
248
- return "errors/error";
249
- }
250
220
  async function renderWebErrorHtml(input) {
251
221
  const render = configuredErrorView.render;
252
222
  if (!render) {
@@ -264,16 +234,6 @@ async function renderWebErrorHtml(input) {
264
234
  async function htmlErrorResponse(input) {
265
235
  return htmlResponse(await renderWebErrorHtml(input), { status: input.status });
266
236
  }
267
- async function notFoundHtmlResponse(body) {
268
- if (body !== undefined) {
269
- return htmlResponse(body, { status: 404 });
270
- }
271
- return htmlErrorResponse({
272
- status: 404,
273
- title: "Not Found",
274
- message: "The page you requested was not found."
275
- });
276
- }
277
237
 
278
238
  // ../../src/core/http/contentNegotiation.ts
279
239
  function requestPrefersJson(request) {
@@ -2,6 +2,26 @@
2
2
  // ../../src/core/http/scimThrottleMiddleware.ts
3
3
  var {RedisClient } = globalThis.Bun;
4
4
 
5
+ // ../../src/core/runtime/appEnv.ts
6
+ var NON_PRODUCTION_APP_ENVS = new Set(["local", "development", "dev", "test", "testing", "ci"]);
7
+ function normalizeEnvValue(value) {
8
+ return (value ?? "").trim().toLowerCase();
9
+ }
10
+ function isProductionEnv(env = process.env) {
11
+ const appEnv = normalizeEnvValue(env.APP_ENV);
12
+ const nodeEnv = normalizeEnvValue(env.NODE_ENV);
13
+ if (appEnv === "production" || nodeEnv === "production") {
14
+ return true;
15
+ }
16
+ if (appEnv === "") {
17
+ return false;
18
+ }
19
+ return !NON_PRODUCTION_APP_ENVS.has(appEnv);
20
+ }
21
+ function envFlagEnabled(value) {
22
+ return value === "true";
23
+ }
24
+
5
25
  // ../../src/core/runtime/appKeyPrefix.ts
6
26
  function appKeyPrefix() {
7
27
  return process.env.APP_KEY_PREFIX?.trim() || "strata";
@@ -12,6 +32,18 @@ function appCookieName(kind) {
12
32
  function appDevSecret(kind) {
13
33
  return `${appKeyPrefix()}-dev-${kind}`;
14
34
  }
35
+ function requireConfiguredSecret(names, devKind, env = process.env) {
36
+ for (const name of names) {
37
+ const value = env[name]?.trim();
38
+ if (value) {
39
+ return value;
40
+ }
41
+ }
42
+ if (isProductionEnv(env)) {
43
+ throw new Error(`${names[0]} must be set outside development. Do not derive secrets from the app name.`);
44
+ }
45
+ return appDevSecret(devKind);
46
+ }
15
47
  function namespacedRedisKey(kind) {
16
48
  return `${appKeyPrefix()}:${kind}`;
17
49
  }
@@ -29,9 +61,6 @@ function appUserAgent() {
29
61
  function otelServiceName() {
30
62
  return process.env.OTEL_SERVICE_NAME?.trim() || `${appKeyPrefix()}-api`;
31
63
  }
32
- function webhookSignatureHeader() {
33
- return process.env.WEBHOOK_SIGNATURE_HEADER?.trim() || `x-${appKeyPrefix()}-signature`;
34
- }
35
64
  function appDisplayName() {
36
65
  return process.env.APP_NAME?.trim() || "Strata";
37
66
  }
@@ -7,6 +7,26 @@ import {
7
7
  } from "@getstrata/core/http/contentSecurityPolicy";
8
8
  import { currentRequestMeta, runWithRequestMeta } from "@getstrata/core/http/requestMetaContext";
9
9
 
10
+ // ../../src/core/runtime/appEnv.ts
11
+ var NON_PRODUCTION_APP_ENVS = new Set(["local", "development", "dev", "test", "testing", "ci"]);
12
+ function normalizeEnvValue(value) {
13
+ return (value ?? "").trim().toLowerCase();
14
+ }
15
+ function isProductionEnv(env = process.env) {
16
+ const appEnv = normalizeEnvValue(env.APP_ENV);
17
+ const nodeEnv = normalizeEnvValue(env.NODE_ENV);
18
+ if (appEnv === "production" || nodeEnv === "production") {
19
+ return true;
20
+ }
21
+ if (appEnv === "") {
22
+ return false;
23
+ }
24
+ return !NON_PRODUCTION_APP_ENVS.has(appEnv);
25
+ }
26
+ function envFlagEnabled(value) {
27
+ return value === "true";
28
+ }
29
+
10
30
  // ../../src/core/runtime/appKeyPrefix.ts
11
31
  function appKeyPrefix() {
12
32
  return process.env.APP_KEY_PREFIX?.trim() || "strata";
@@ -17,6 +37,18 @@ function appCookieName(kind) {
17
37
  function appDevSecret(kind) {
18
38
  return `${appKeyPrefix()}-dev-${kind}`;
19
39
  }
40
+ function requireConfiguredSecret(names, devKind, env = process.env) {
41
+ for (const name of names) {
42
+ const value = env[name]?.trim();
43
+ if (value) {
44
+ return value;
45
+ }
46
+ }
47
+ if (isProductionEnv(env)) {
48
+ throw new Error(`${names[0]} must be set outside development. Do not derive secrets from the app name.`);
49
+ }
50
+ return appDevSecret(devKind);
51
+ }
20
52
  function namespacedRedisKey(kind) {
21
53
  return `${appKeyPrefix()}:${kind}`;
22
54
  }
@@ -34,9 +66,6 @@ function appUserAgent() {
34
66
  function otelServiceName() {
35
67
  return process.env.OTEL_SERVICE_NAME?.trim() || `${appKeyPrefix()}-api`;
36
68
  }
37
- function webhookSignatureHeader() {
38
- return process.env.WEBHOOK_SIGNATURE_HEADER?.trim() || `x-${appKeyPrefix()}-signature`;
39
- }
40
69
  function appDisplayName() {
41
70
  return process.env.APP_NAME?.trim() || "Strata";
42
71
  }
@@ -4,6 +4,26 @@ import { createHmac } from "crypto";
4
4
  import { ForbiddenError } from "@getstrata/core/errors/http";
5
5
  import { timingSafeCompareString } from "@getstrata/core/security/timingSafeCompare";
6
6
 
7
+ // ../../src/core/runtime/appEnv.ts
8
+ var NON_PRODUCTION_APP_ENVS = new Set(["local", "development", "dev", "test", "testing", "ci"]);
9
+ function normalizeEnvValue(value) {
10
+ return (value ?? "").trim().toLowerCase();
11
+ }
12
+ function isProductionEnv(env = process.env) {
13
+ const appEnv = normalizeEnvValue(env.APP_ENV);
14
+ const nodeEnv = normalizeEnvValue(env.NODE_ENV);
15
+ if (appEnv === "production" || nodeEnv === "production") {
16
+ return true;
17
+ }
18
+ if (appEnv === "") {
19
+ return false;
20
+ }
21
+ return !NON_PRODUCTION_APP_ENVS.has(appEnv);
22
+ }
23
+ function envFlagEnabled(value) {
24
+ return value === "true";
25
+ }
26
+
7
27
  // ../../src/core/runtime/appKeyPrefix.ts
8
28
  function appKeyPrefix() {
9
29
  return process.env.APP_KEY_PREFIX?.trim() || "strata";
@@ -14,6 +34,18 @@ function appCookieName(kind) {
14
34
  function appDevSecret(kind) {
15
35
  return `${appKeyPrefix()}-dev-${kind}`;
16
36
  }
37
+ function requireConfiguredSecret(names, devKind, env = process.env) {
38
+ for (const name of names) {
39
+ const value = env[name]?.trim();
40
+ if (value) {
41
+ return value;
42
+ }
43
+ }
44
+ if (isProductionEnv(env)) {
45
+ throw new Error(`${names[0]} must be set outside development. Do not derive secrets from the app name.`);
46
+ }
47
+ return appDevSecret(devKind);
48
+ }
17
49
  function namespacedRedisKey(kind) {
18
50
  return `${appKeyPrefix()}:${kind}`;
19
51
  }
@@ -31,9 +63,6 @@ function appUserAgent() {
31
63
  function otelServiceName() {
32
64
  return process.env.OTEL_SERVICE_NAME?.trim() || `${appKeyPrefix()}-api`;
33
65
  }
34
- function webhookSignatureHeader() {
35
- return process.env.WEBHOOK_SIGNATURE_HEADER?.trim() || `x-${appKeyPrefix()}-signature`;
36
- }
37
66
  function appDisplayName() {
38
67
  return process.env.APP_NAME?.trim() || "Strata";
39
68
  }
@@ -60,7 +89,7 @@ function sdkClientClassName() {
60
89
 
61
90
  // ../../src/core/http/signedUrl.ts
62
91
  function resolveSignedUrlSecret() {
63
- return process.env.SIGNED_URL_SECRET?.trim() || process.env.SESSION_SECRET?.trim() || process.env.OAUTH_STATE_SECRET?.trim() || appDevSecret("signed-url-secret");
92
+ return requireConfiguredSecret(["SIGNED_URL_SECRET", "SESSION_SECRET", "OAUTH_STATE_SECRET"], "signed-url-secret");
64
93
  }
65
94
  function resolveSignedUrlOrigin() {
66
95
  return (process.env.APP_URL ?? "http://localhost:3000").replace(/\/$/, "");
@@ -4,6 +4,26 @@ import { currentAuthUser } from "@getstrata/core/auth/authContext";
4
4
  import { currentTenant, rateLimitMultiplierForPlan } from "@getstrata/core/tenant/tenantContext";
5
5
  var {RedisClient } = globalThis.Bun;
6
6
 
7
+ // ../../src/core/runtime/appEnv.ts
8
+ var NON_PRODUCTION_APP_ENVS = new Set(["local", "development", "dev", "test", "testing", "ci"]);
9
+ function normalizeEnvValue(value) {
10
+ return (value ?? "").trim().toLowerCase();
11
+ }
12
+ function isProductionEnv(env = process.env) {
13
+ const appEnv = normalizeEnvValue(env.APP_ENV);
14
+ const nodeEnv = normalizeEnvValue(env.NODE_ENV);
15
+ if (appEnv === "production" || nodeEnv === "production") {
16
+ return true;
17
+ }
18
+ if (appEnv === "") {
19
+ return false;
20
+ }
21
+ return !NON_PRODUCTION_APP_ENVS.has(appEnv);
22
+ }
23
+ function envFlagEnabled(value) {
24
+ return value === "true";
25
+ }
26
+
7
27
  // ../../src/core/runtime/appKeyPrefix.ts
8
28
  function appKeyPrefix() {
9
29
  return process.env.APP_KEY_PREFIX?.trim() || "strata";
@@ -14,6 +34,18 @@ function appCookieName(kind) {
14
34
  function appDevSecret(kind) {
15
35
  return `${appKeyPrefix()}-dev-${kind}`;
16
36
  }
37
+ function requireConfiguredSecret(names, devKind, env = process.env) {
38
+ for (const name of names) {
39
+ const value = env[name]?.trim();
40
+ if (value) {
41
+ return value;
42
+ }
43
+ }
44
+ if (isProductionEnv(env)) {
45
+ throw new Error(`${names[0]} must be set outside development. Do not derive secrets from the app name.`);
46
+ }
47
+ return appDevSecret(devKind);
48
+ }
17
49
  function namespacedRedisKey(kind) {
18
50
  return `${appKeyPrefix()}:${kind}`;
19
51
  }
@@ -31,9 +63,6 @@ function appUserAgent() {
31
63
  function otelServiceName() {
32
64
  return process.env.OTEL_SERVICE_NAME?.trim() || `${appKeyPrefix()}-api`;
33
65
  }
34
- function webhookSignatureHeader() {
35
- return process.env.WEBHOOK_SIGNATURE_HEADER?.trim() || `x-${appKeyPrefix()}-signature`;
36
- }
37
66
  function appDisplayName() {
38
67
  return process.env.APP_NAME?.trim() || "Strata";
39
68
  }
@@ -133,9 +162,6 @@ function readSpaPrefix() {
133
162
  import { currentRequestMeta as currentRequestMeta2 } from "@getstrata/core/http/requestMetaContext";
134
163
 
135
164
  // ../../src/core/view/htmlResponse.ts
136
- function withCharset(contentType) {
137
- return contentType.includes("charset=") ? contentType : `${contentType}; charset=utf-8`;
138
- }
139
165
  function htmlResponse(html, init = {}) {
140
166
  return new Response(html, {
141
167
  status: init.status ?? 200,
@@ -145,42 +171,9 @@ function htmlResponse(html, init = {}) {
145
171
  }
146
172
  });
147
173
  }
148
- function isHtmxRequest(request) {
149
- return request.headers.get("HX-Request") === "true";
150
- }
151
- function redirectResponse(location, status = 302) {
152
- return new Response(null, {
153
- status,
154
- headers: {
155
- Location: location
156
- }
157
- });
158
- }
159
- function textResponse(body, init = {}) {
160
- return new Response(body, {
161
- status: init.status ?? 200,
162
- headers: {
163
- "Content-Type": "text/plain; charset=utf-8"
164
- }
165
- });
166
- }
167
- function xmlResponse(body, init = {}) {
168
- return new Response(body, {
169
- status: init.status ?? 200,
170
- headers: {
171
- "Content-Type": withCharset(init.contentType ?? "application/xml")
172
- }
173
- });
174
- }
175
- function rssResponse(body, init = {}) {
176
- return xmlResponse(body, { ...init, contentType: "application/rss+xml" });
177
- }
178
174
 
179
175
  // ../../src/core/view/webErrorView.ts
180
176
  var configuredErrorView = {};
181
- function configureWebErrorView(options) {
182
- configuredErrorView = { ...options };
183
- }
184
177
  function escapeHtml(value) {
185
178
  return value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;");
186
179
  }
@@ -214,15 +207,6 @@ function renderKernelErrorChrome(input) {
214
207
  </html>
215
208
  `;
216
209
  }
217
- function errorTemplateName(status) {
218
- if (status === 404) {
219
- return "errors/not-found";
220
- }
221
- if (status === 403) {
222
- return "errors/forbidden";
223
- }
224
- return "errors/error";
225
- }
226
210
  async function renderWebErrorHtml(input) {
227
211
  const render = configuredErrorView.render;
228
212
  if (!render) {
@@ -240,16 +224,6 @@ async function renderWebErrorHtml(input) {
240
224
  async function htmlErrorResponse(input) {
241
225
  return htmlResponse(await renderWebErrorHtml(input), { status: input.status });
242
226
  }
243
- async function notFoundHtmlResponse(body) {
244
- if (body !== undefined) {
245
- return htmlResponse(body, { status: 404 });
246
- }
247
- return htmlErrorResponse({
248
- status: 404,
249
- title: "Not Found",
250
- message: "The page you requested was not found."
251
- });
252
- }
253
227
 
254
228
  // ../../src/core/http/contentNegotiation.ts
255
229
  function requestPrefersJson(request) {