@getstrata/core 2.2.60 → 3.0.3

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 (330) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/core/audit/exportAuditLogs.d.ts +12 -3
  3. package/dist/core/audit/exportStore.d.ts +6 -2
  4. package/dist/core/audit/siemFormatter.d.ts +2 -2
  5. package/dist/core/auth/abilityCatalog.d.ts +1 -9
  6. package/dist/core/auth/authContext.d.ts +2 -0
  7. package/dist/core/auth/authOutcome.d.ts +32 -0
  8. package/dist/core/auth/authReader.d.ts +22 -0
  9. package/dist/core/auth/basicAuthGuard.d.ts +19 -3
  10. package/dist/core/auth/emailVerification.d.ts +1 -1
  11. package/dist/core/auth/guard.d.ts +27 -6
  12. package/dist/core/auth/intendedUrlCookie.d.ts +13 -7
  13. package/dist/core/auth/jwt.d.ts +5 -4
  14. package/dist/core/auth/jwtGuard.d.ts +7 -6
  15. package/dist/core/auth/membershipContext.d.ts +10 -7
  16. package/dist/core/auth/membershipContextMiddleware.d.ts +3 -3
  17. package/dist/core/auth/membershipMiddleware.d.ts +1 -2
  18. package/dist/core/auth/membershipServiceImplementation.d.ts +1 -1
  19. package/dist/core/auth/oauth/oidcIdToken.d.ts +25 -16
  20. package/dist/core/auth/oauth/oidcProvider.d.ts +6 -4
  21. package/dist/core/auth/oauth/providers.d.ts +3 -1
  22. package/dist/core/auth/oneTimeToken.d.ts +2 -3
  23. package/dist/core/auth/passwordConfirmCookie.d.ts +15 -6
  24. package/dist/core/auth/passwordLogin.d.ts +5 -5
  25. package/dist/core/auth/pendingMfaCookie.d.ts +2 -2
  26. package/dist/core/auth/policy.d.ts +23 -10
  27. package/dist/core/auth/requireAuthCapability.d.ts +3 -0
  28. package/dist/core/auth/resolveMembershipService.d.ts +3 -2
  29. package/dist/core/auth/saml/samlAssertionReplay.d.ts +4 -4
  30. package/dist/core/auth/saml/samlServiceProvider.d.ts +11 -7
  31. package/dist/core/auth/scimAuthMiddleware.d.ts +10 -3
  32. package/dist/core/auth/sessionCookie.d.ts +20 -9
  33. package/dist/core/auth/sessionGuard.d.ts +14 -3
  34. package/dist/core/cache/createCacheStore.d.ts +6 -3
  35. package/dist/core/cache/redisCacheStore.d.ts +5 -1
  36. package/dist/core/cache/repository.d.ts +5 -1
  37. package/dist/core/cache/simpleCache.d.ts +2 -1
  38. package/dist/core/cache/tokens.d.ts +8 -0
  39. package/dist/core/config/applicationConfig.d.ts +21 -0
  40. package/dist/core/config/configSnapshot.d.ts +3 -0
  41. package/dist/core/config/envSchema.d.ts +3 -2
  42. package/dist/core/contracts/application.d.ts +153 -0
  43. package/dist/core/contracts/authUserDirectory.d.ts +24 -7
  44. package/dist/core/contracts/container.d.ts +20 -23
  45. package/dist/core/contracts/di.d.ts +4 -2
  46. package/dist/core/contracts/executionContext.d.ts +5 -0
  47. package/dist/core/contracts/executionOperations.d.ts +10 -0
  48. package/dist/core/contracts/executionOwnership.d.ts +38 -0
  49. package/dist/core/contracts/persistence.d.ts +20 -0
  50. package/dist/core/contracts/serviceTokens.d.ts +32 -18
  51. package/dist/core/contracts/services.d.ts +63 -0
  52. package/dist/core/contracts/token.d.ts +19 -0
  53. package/dist/core/crypto/fieldEncryption.d.ts +19 -7
  54. package/dist/core/crypto/fieldEncryptionRotation.d.ts +21 -5
  55. package/dist/core/crypto/mfaSecret.d.ts +10 -3
  56. package/dist/core/database/baseRepository.d.ts +14 -10
  57. package/dist/core/database/bindings.d.ts +6 -0
  58. package/dist/core/database/bunSql.d.ts +3 -12
  59. package/dist/core/database/definitions.d.ts +209 -0
  60. package/dist/core/database/dialect.d.ts +5 -24
  61. package/dist/core/database/driverPorts.d.ts +116 -0
  62. package/dist/core/database/errors.d.ts +47 -7
  63. package/dist/core/database/factory.d.ts +51 -31
  64. package/dist/core/database/index.d.ts +9 -10
  65. package/dist/core/database/keyset.d.ts +2 -1
  66. package/dist/core/database/legacyNativeTransaction.d.ts +5 -0
  67. package/dist/core/database/manager.d.ts +12 -0
  68. package/dist/core/database/model.d.ts +91 -97
  69. package/dist/core/database/modelQuery.d.ts +9 -5
  70. package/dist/core/database/modelRegistry.d.ts +52 -33
  71. package/dist/core/database/mysqlConnection.d.ts +1 -19
  72. package/dist/core/database/mysqlNative.d.ts +38 -0
  73. package/dist/core/database/nativeTransactions.d.ts +16 -0
  74. package/dist/core/database/ormInternal.d.ts +85 -0
  75. package/dist/core/database/ormRuntime.d.ts +4 -0
  76. package/dist/core/database/ownedReadOnlyObservation.d.ts +16 -0
  77. package/dist/core/database/postgresNative.d.ts +11 -0
  78. package/dist/core/database/query.d.ts +24 -23
  79. package/dist/core/database/queryPlanSnapshot.d.ts +7 -0
  80. package/dist/core/database/rawMysql.d.ts +7 -0
  81. package/dist/core/database/rawPostgres.d.ts +23 -0
  82. package/dist/core/database/rawSqlite.d.ts +6 -0
  83. package/dist/core/database/relationQueries.d.ts +3 -2
  84. package/dist/core/database/relationQuery.d.ts +24 -6
  85. package/dist/core/database/repositoryQuery.d.ts +6 -1
  86. package/dist/core/database/schema/driver.d.ts +1 -1
  87. package/dist/core/database/seeders/types.d.ts +1 -1
  88. package/dist/core/database/session.d.ts +13 -0
  89. package/dist/core/database/sessionFactory.d.ts +9 -0
  90. package/dist/core/database/sqlDialects.d.ts +22 -0
  91. package/dist/core/database/tokens.d.ts +7 -0
  92. package/dist/core/database/transactionSession.d.ts +43 -0
  93. package/dist/core/errors/http.d.ts +4 -1
  94. package/dist/core/events/{eventBus.d.ts → eventBusClass.d.ts} +1 -3
  95. package/dist/core/events/index.d.ts +2 -3
  96. package/dist/core/events/outbox/index.d.ts +44 -13
  97. package/dist/core/events/outbox/metrics.d.ts +4 -4
  98. package/dist/core/events/outbox/workerTransport.d.ts +17 -0
  99. package/dist/core/http/authMiddleware.d.ts +2 -2
  100. package/dist/core/http/authorizeMiddleware.d.ts +2 -2
  101. package/dist/core/http/bodySizeLimitMiddleware.d.ts +1 -1
  102. package/dist/core/http/conditionalResponse.d.ts +7 -2
  103. package/dist/core/http/contentSecurityPolicy.d.ts +4 -3
  104. package/dist/core/http/corsMiddleware.d.ts +2 -1
  105. package/dist/core/http/csrfMiddleware.d.ts +6 -1
  106. package/dist/core/http/csrfToken.d.ts +17 -7
  107. package/dist/core/http/databaseError.d.ts +4 -0
  108. package/dist/core/http/etag.d.ts +5 -2
  109. package/dist/core/http/flashMiddleware.d.ts +1 -1
  110. package/dist/core/http/flashSession.d.ts +13 -7
  111. package/dist/core/http/index.d.ts +1 -1
  112. package/dist/core/http/loginThrottleMiddleware.d.ts +3 -3
  113. package/dist/core/http/memoryThrottleMiddleware.d.ts +2 -2
  114. package/dist/core/http/parseMultipartUpload.d.ts +3 -2
  115. package/dist/core/http/requestMetaContext.d.ts +5 -0
  116. package/dist/core/http/requireAbilityMiddleware.d.ts +1 -1
  117. package/dist/core/http/requireAuthMiddleware.d.ts +2 -2
  118. package/dist/core/http/requirePasswordConfirmMiddleware.d.ts +2 -1
  119. package/dist/core/http/requireVerifiedMiddleware.d.ts +2 -2
  120. package/dist/core/http/requireWebAuthMiddleware.d.ts +2 -2
  121. package/dist/core/http/response.d.ts +4 -3
  122. package/dist/core/http/scimThrottleMiddleware.d.ts +4 -3
  123. package/dist/core/http/securedRouteModelBinding.d.ts +10 -3
  124. package/dist/core/http/securityHeadersMiddleware.d.ts +1 -2
  125. package/dist/core/http/signedUrl.d.ts +8 -6
  126. package/dist/core/http/throttleMiddleware.d.ts +9 -5
  127. package/dist/core/http/uploads.d.ts +9 -3
  128. package/dist/core/http/webErrorResponse.d.ts +8 -2
  129. package/dist/core/jobs/exportAuditLogsJob.d.ts +5 -2
  130. package/dist/core/jobs/invalidateCacheTagsJob.d.ts +5 -4
  131. package/dist/core/lifecycle/gracefulShutdown.d.ts +2 -5
  132. package/dist/core/logging/requestLoggingMiddleware.d.ts +1 -1
  133. package/dist/core/mail/mailer.d.ts +7 -5
  134. package/dist/core/openapi/generator.d.ts +12 -4
  135. package/dist/core/openapi/registeredRoute.d.ts +4 -4
  136. package/dist/core/queue/createAppQueue.d.ts +9 -4
  137. package/dist/core/queue/failedJobMetrics.d.ts +11 -2
  138. package/dist/core/queue/failedJobRepository.d.ts +6 -3
  139. package/dist/core/queue/failedJobService.d.ts +1 -0
  140. package/dist/core/queue/index.d.ts +16 -6
  141. package/dist/core/queue/jobRegistry.d.ts +3 -2
  142. package/dist/core/queue/jobRunner.d.ts +10 -4
  143. package/dist/core/queue/publicQueue.d.ts +18 -9
  144. package/dist/core/queue/queueConfig.d.ts +20 -10
  145. package/dist/core/queue/queueHandoff.d.ts +31 -0
  146. package/dist/core/queue/queueMetrics.d.ts +10 -3
  147. package/dist/core/queue/queueServices.d.ts +28 -0
  148. package/dist/core/queue/queueWorkerTransport.d.ts +28 -0
  149. package/dist/core/queue/redisQueue.d.ts +19 -10
  150. package/dist/core/queue/redisQueueKeys.d.ts +5 -5
  151. package/dist/core/queue/redisStreams.d.ts +17 -10
  152. package/dist/core/queue/resilientQueue.d.ts +10 -4
  153. package/dist/core/queue/types.d.ts +1 -0
  154. package/dist/core/runtime/appKeyPrefix.d.ts +5 -5
  155. package/dist/core/runtime/application.d.ts +7 -0
  156. package/dist/core/runtime/executionContext.d.ts +9 -0
  157. package/dist/core/runtime/executionTasks.d.ts +49 -0
  158. package/dist/core/runtime/resourceJournal.d.ts +67 -0
  159. package/dist/core/runtime/serviceGraph.d.ts +14 -0
  160. package/dist/core/security/oauthState.d.ts +13 -9
  161. package/dist/core/security/publicReads.d.ts +2 -2
  162. package/dist/core/security/safeFetch.d.ts +1 -0
  163. package/dist/core/security/safeUrl.d.ts +3 -0
  164. package/dist/core/security/scimTenantTokens.d.ts +1 -1
  165. package/dist/core/security/tokenExpiry.d.ts +1 -1
  166. package/dist/core/security/webhookSignature.d.ts +1 -1
  167. package/dist/core/storage/storage.d.ts +24 -16
  168. package/dist/core/tenant/databaseTenantContext.d.ts +5 -7
  169. package/dist/core/tenant/resolveTenant.d.ts +2 -2
  170. package/dist/core/tenant/scopedDatabasePolicy.d.ts +8 -0
  171. package/dist/core/tenant/tenantDatabaseScope.d.ts +3 -7
  172. package/dist/core/tenant/tenantMiddleware.d.ts +15 -4
  173. package/dist/core/tracing/otel.d.ts +4 -6
  174. package/dist/core/tracing/tracingMiddleware.d.ts +3 -3
  175. package/dist/core/view/etaViewEngine.d.ts +1 -1
  176. package/dist/core/view/index.d.ts +5 -4
  177. package/dist/core/view/tokens.d.ts +8 -0
  178. package/dist/core/view/viewRenderer.d.ts +2 -2
  179. package/dist/core/view/webErrorView.d.ts +8 -7
  180. package/dist/core/view/webLayoutData.d.ts +6 -4
  181. package/dist/entries/audit/exportAuditLogs.js +87 -1024
  182. package/dist/entries/audit/siemFormatter.js +4 -90
  183. package/dist/entries/auth/abilityCatalog.js +28 -0
  184. package/dist/entries/auth/accessControl.js +5 -16
  185. package/dist/entries/auth/accountStateMigration.js +216 -236
  186. package/dist/entries/auth/authOutcome.js +80 -0
  187. package/dist/entries/auth/authReader.js +68 -0
  188. package/dist/entries/auth/basicAuthGuard.js +144 -1249
  189. package/dist/entries/auth/emailVerification.js +2 -2
  190. package/dist/entries/auth/intendedUrlCookie.js +35 -59
  191. package/dist/entries/auth/jwt.js +22 -47
  192. package/dist/entries/auth/jwtGuard.js +99 -231
  193. package/dist/entries/auth/membershipMiddleware.js +71 -10
  194. package/dist/entries/auth/membershipScope.js +16 -22
  195. package/dist/entries/auth/membershipService.js +11 -28
  196. package/dist/entries/auth/oauth/oidcProvider.js +59 -64
  197. package/dist/entries/auth/oauth/providers.js +12 -95
  198. package/dist/entries/auth/oauth/samlProvider.js +53 -1080
  199. package/dist/entries/auth/oneTimeToken.js +27 -289
  200. package/dist/entries/auth/passwordConfirmCookie.js +40 -63
  201. package/dist/entries/auth/passwordLogin.js +94 -399
  202. package/dist/entries/auth/pendingMfaCookie.js +6 -6
  203. package/dist/entries/auth/policy.js +22 -56
  204. package/dist/entries/auth/saml/samlServiceProvider.js +55 -1084
  205. package/dist/entries/auth/scimAuthMiddleware.js +16 -3358
  206. package/dist/entries/auth/sessionCookie.js +58 -73
  207. package/dist/entries/auth/sessionGuard.js +95 -248
  208. package/dist/entries/auth/tokenHash.js +11 -43
  209. package/dist/entries/cache/createCacheStore.js +126 -117
  210. package/dist/entries/cache/repository.js +25 -0
  211. package/dist/entries/cache/simpleCache.js +12 -7
  212. package/dist/entries/cache/tokens.js +9 -0
  213. package/dist/entries/config/applicationConfig.js +163 -0
  214. package/dist/entries/config/envSchema.js +21 -4
  215. package/dist/entries/contracts/application.js +1 -0
  216. package/dist/entries/contracts/authUserDirectory.js +10 -0
  217. package/dist/entries/contracts/container.js +99 -26
  218. package/dist/entries/contracts/di.js +3 -0
  219. package/dist/entries/contracts/executionContext.js +7 -0
  220. package/dist/entries/contracts/executionOperations.js +7 -0
  221. package/dist/entries/contracts/executionOwnership.js +7 -0
  222. package/dist/entries/contracts/membership.js +1 -0
  223. package/dist/entries/contracts/persistence.js +1 -0
  224. package/dist/entries/contracts/serviceTokens.js +26 -116
  225. package/dist/entries/contracts/services.js +98 -0
  226. package/dist/entries/contracts/token.js +41 -0
  227. package/dist/entries/crypto/fieldEncryption.js +49 -50
  228. package/dist/entries/crypto/mfaSecret.js +86 -82
  229. package/dist/entries/database/acquisitionMetrics.js +107 -0
  230. package/dist/entries/database/baseRepository.d.ts +2 -0
  231. package/dist/entries/database/bindings.js +2082 -0
  232. package/dist/entries/database/definitions.js +175 -0
  233. package/dist/entries/database/errors.js +114 -89
  234. package/dist/entries/database/factory.js +67 -28
  235. package/dist/entries/database/migrations.js +172 -224
  236. package/dist/entries/database/model.d.ts +1 -0
  237. package/dist/entries/database/ownedReadOnlyObservation.js +1282 -0
  238. package/dist/entries/database/query.js +159 -161
  239. package/dist/entries/database/repositoryQuery.d.ts +1 -0
  240. package/dist/entries/database/repositoryQuery.js +1 -1373
  241. package/dist/entries/database/schema.js +216 -236
  242. package/dist/entries/database/session.js +1 -0
  243. package/dist/entries/database/sqliteConnection.js +525 -83
  244. package/dist/entries/database/tokens.js +9 -0
  245. package/dist/entries/errors/http.js +118 -1
  246. package/dist/entries/http/authMiddleware.js +8 -5
  247. package/dist/entries/http/authorizeMiddleware.js +1 -1
  248. package/dist/entries/http/bodySizeLimitMiddleware.js +2 -2
  249. package/dist/entries/http/clientIp.js +2 -2
  250. package/dist/entries/http/conditionalResponse.js +19 -7
  251. package/dist/entries/http/corsMiddleware.js +6 -101
  252. package/dist/entries/http/csrfMiddleware.js +92 -106
  253. package/dist/entries/http/csrfToken.js +58 -94
  254. package/dist/entries/http/etag.js +7 -4
  255. package/dist/entries/http/flashMiddleware.js +57 -99
  256. package/dist/entries/http/flashSession.js +41 -68
  257. package/dist/entries/http/memoryThrottleMiddleware.js +43 -186
  258. package/dist/entries/http/metricsMiddleware.js +2 -16
  259. package/dist/entries/http/parseMultipartUpload.js +15 -29
  260. package/dist/entries/http/requireAbilityMiddleware.js +2 -2
  261. package/dist/entries/http/requirePasswordConfirmMiddleware.js +19 -31
  262. package/dist/entries/http/requireVerifiedMiddleware.js +4 -7
  263. package/dist/entries/http/requireWebAuthMiddleware.js +2 -2
  264. package/dist/entries/http/response.js +67 -233
  265. package/dist/entries/http/routeMiddleware.js +0 -14
  266. package/dist/entries/http/scimThrottleMiddleware.js +43 -237
  267. package/dist/entries/http/securedRouteModelBinding.js +37 -25
  268. package/dist/entries/http/securityHeadersMiddleware.js +8 -25
  269. package/dist/entries/http/signedUrl.js +20 -110
  270. package/dist/entries/http/throttleMiddleware.js +41 -185
  271. package/dist/entries/http/uploads.js +9 -24
  272. package/dist/entries/jobs/exportAuditLogsJob.js +17 -1498
  273. package/dist/entries/jobs/invalidateCacheTagsJob.js +12 -47
  274. package/dist/entries/logging/requestLoggingMiddleware.js +4 -4
  275. package/dist/entries/mail/mailer.js +68 -78
  276. package/dist/entries/openapi/generator.js +33 -100
  277. package/dist/entries/queue/createAppQueue.js +416 -256
  278. package/dist/entries/queue/failedJobRepository.js +17 -8
  279. package/dist/entries/queue/failedJobService.js +1 -0
  280. package/dist/entries/queue/jobRunner.js +141 -66
  281. package/dist/entries/queue/publicQueue.js +411 -257
  282. package/dist/entries/queue/queueConfig.js +61 -0
  283. package/dist/entries/queue/queueHandoff.js +318 -0
  284. package/dist/entries/queue/queueMetrics.js +989 -1386
  285. package/dist/entries/queue/queueServices.js +133 -0
  286. package/dist/entries/queue/queueWorkerTransport.js +1703 -0
  287. package/dist/entries/queue/redisQueue.js +282 -180
  288. package/dist/entries/queue.js +6 -45
  289. package/dist/entries/runtime/application.js +1585 -0
  290. package/dist/entries/runtime/asyncContextStore.js +0 -16
  291. package/dist/entries/security/oauthState.js +35 -67
  292. package/dist/entries/security/publicReads.js +4 -4
  293. package/dist/entries/security/safeFetch.js +1 -0
  294. package/dist/entries/security/scimTenantTokens.js +3 -3
  295. package/dist/entries/security/tokenExpiry.js +2 -2
  296. package/dist/entries/security/totp.js +1 -87
  297. package/dist/entries/security/webhookSignature.js +2 -90
  298. package/dist/entries/storage/storage.js +120 -45
  299. package/dist/entries/tenant/databaseTenantContext.js +6 -907
  300. package/dist/entries/tenant/publicTenantHost.js +78 -0
  301. package/dist/entries/tenant/resolveTenant.js +14 -0
  302. package/dist/entries/tenant/scopedDatabasePolicy.js +75 -0
  303. package/dist/entries/tenant/tenancyConfig.js +1 -19
  304. package/dist/entries/tenant/tenantDatabaseScope.js +3 -892
  305. package/dist/entries/tracing/tracingMiddleware.js +104 -173
  306. package/dist/entries/view/tokens.js +11 -0
  307. package/dist/framework/public-api.d.ts +62 -44
  308. package/dist/index.js +10435 -11351
  309. package/dist/internal/ormInternal.js +117 -0
  310. package/dist/internal/ormRuntime.js +5000 -0
  311. package/package.json +158 -46
  312. package/dist/core/database/bindConnection.d.ts +0 -1
  313. package/dist/core/database/boundConnection.d.ts +0 -5
  314. package/dist/core/database/defaultConnection.d.ts +0 -7
  315. package/dist/core/database/namedConnections.d.ts +0 -15
  316. package/dist/core/database/readOnlyCollector.d.ts +0 -7
  317. package/dist/core/database/repositoryConnection.d.ts +0 -4
  318. package/dist/core/database/transaction.d.ts +0 -23
  319. package/dist/core/database/transactionControl.d.ts +0 -6
  320. package/dist/core/events/deferredModelEvents.d.ts +0 -7
  321. package/dist/core/facades/index.d.ts +0 -10
  322. package/dist/core/runtime/applicationRegistry.d.ts +0 -18
  323. package/dist/entries/database/bindConnection.js +0 -1
  324. package/dist/entries/database/boundConnection.js +0 -1
  325. package/dist/entries/database/defaultConnection.js +0 -1
  326. package/dist/entries/database/namedConnections.js +0 -1
  327. package/dist/entries/database/repositoryConnection.js +0 -1
  328. package/dist/entries/database/transaction.js +0 -1
  329. package/dist/entries/facades.js +0 -711
  330. package/dist/entries/runtime/applicationRegistry.js +0 -1
@@ -3,99 +3,8 @@
3
3
  import { createHmac } from "crypto";
4
4
  import { ForbiddenError } from "@getstrata/core/errors/http";
5
5
  import { timingSafeCompareString } from "@getstrata/core/security/timingSafeCompare";
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
-
27
- // ../../src/core/runtime/appKeyPrefix.ts
28
- function appKeyPrefix() {
29
- return process.env.APP_KEY_PREFIX?.trim() || "strata";
30
- }
31
- function appCookieName(kind) {
32
- return `${appKeyPrefix()}_${kind}`;
33
- }
34
- function appDevSecret(kind) {
35
- return `${appKeyPrefix()}-dev-${kind}`;
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
- }
49
- function namespacedRedisKey(kind) {
50
- return `${appKeyPrefix()}:${kind}`;
51
- }
52
- function smtpEhloHost() {
53
- const raw = process.env.MAIL_EHLO?.trim() || `${appKeyPrefix()}.local`;
54
- const safe = raw.replace(/[^a-zA-Z0-9.-]/g, "");
55
- return safe || "strata.local";
56
- }
57
- function siemEventType() {
58
- return process.env.SIEM_EVENT_TYPE?.trim() || `${appKeyPrefix()}.audit`;
59
- }
60
- function appUserAgent() {
61
- return process.env.APP_USER_AGENT?.trim() || appKeyPrefix();
62
- }
63
- function otelServiceName() {
64
- return process.env.OTEL_SERVICE_NAME?.trim() || `${appKeyPrefix()}-api`;
65
- }
66
- function webhookSignatureHeader() {
67
- return process.env.WEBHOOK_SIGNATURE_HEADER?.trim() || `x-${appKeyPrefix()}-signature`;
68
- }
69
- function appDisplayName() {
70
- return process.env.APP_NAME?.trim() || "Strata";
71
- }
72
- function appEnv() {
73
- return process.env.APP_ENV?.trim() || "local";
74
- }
75
- function appUrl() {
76
- return (process.env.APP_URL?.trim() || "http://localhost:3000").replace(/\/$/, "");
77
- }
78
- function apiPrefix() {
79
- const raw = process.env.API_PREFIX?.trim() || "/api/v1";
80
- const withSlash = raw.startsWith("/") ? raw : `/${raw}`;
81
- const trimmed = withSlash.replace(/\/+$/, "");
82
- return trimmed || "/api/v1";
83
- }
84
- function sdkClientClassName() {
85
- const override = process.env.APP_SDK_CLASS?.trim();
86
- if (override && /^[A-Za-z_][A-Za-z0-9_]*$/.test(override)) {
87
- return override;
88
- }
89
- const fromName = appDisplayName().replace(/[^A-Za-z0-9]/g, "");
90
- return fromName ? `${fromName}Client` : "AppClient";
91
- }
92
-
93
- // ../../src/core/http/signedUrl.ts
94
- function resolveSignedUrlSecret() {
95
- return requireConfiguredSecret(["SIGNED_URL_SECRET", "SESSION_SECRET", "OAUTH_STATE_SECRET"], "signed-url-secret");
96
- }
97
- function resolveSignedUrlOrigin() {
98
- return (process.env.APP_URL ?? "http://localhost:3000").replace(/\/$/, "");
6
+ function missingSignedUrlSecret() {
7
+ throw new TypeError("Explicit signed URL secret is required.");
99
8
  }
100
9
  function normalizeSignedPath(path) {
101
10
  const trimmed = path.trim();
@@ -111,11 +20,11 @@ function sortedQueryString(params) {
111
20
  const entries = [...params.entries()].filter(([key]) => key !== "signature").sort(([left], [right]) => left.localeCompare(right));
112
21
  return new URLSearchParams(entries).toString();
113
22
  }
114
- function signCanonicalPayload(path, query) {
115
- return createHmac("sha256", resolveSignedUrlSecret()).update(`${path}
23
+ function signCanonicalPayload(path, query, secret) {
24
+ return createHmac("sha256", secret ?? missingSignedUrlSecret()).update(`${path}
116
25
  ${query}`).digest("hex");
117
26
  }
118
- function buildSignedSearchParams(path, query = {}, expiresAt) {
27
+ function buildSignedSearchParams(path, query = {}, expiresAt, secret) {
119
28
  const params = new URLSearchParams;
120
29
  for (const [key, value] of Object.entries(query)) {
121
30
  if (key === "signature" || key === "expires") {
@@ -126,36 +35,36 @@ function buildSignedSearchParams(path, query = {}, expiresAt) {
126
35
  if (expiresAt !== undefined) {
127
36
  params.set("expires", String(expiresAt));
128
37
  }
129
- params.set("signature", signCanonicalPayload(path, sortedQueryString(params)));
38
+ params.set("signature", signCanonicalPayload(path, sortedQueryString(params), secret));
130
39
  return params;
131
40
  }
132
- function signedUrl(path, query = {}) {
41
+ function signedUrl(path, query = {}, secret) {
133
42
  const normalizedPath = normalizeSignedPath(path);
134
- const params = buildSignedSearchParams(normalizedPath, query);
43
+ const params = buildSignedSearchParams(normalizedPath, query, undefined, secret);
135
44
  return `${normalizedPath}?${params.toString()}`;
136
45
  }
137
- function temporarySignedUrl(path, expiresInSeconds, query = {}) {
46
+ function temporarySignedUrl(path, expiresInSeconds, query = {}, secret) {
138
47
  if (!Number.isInteger(expiresInSeconds) || expiresInSeconds <= 0) {
139
48
  throw new Error("Signed URL expiry must be a positive integer number of seconds.");
140
49
  }
141
50
  const normalizedPath = normalizeSignedPath(path);
142
51
  const expiresAt = Math.floor(Date.now() / 1000) + expiresInSeconds;
143
- const params = buildSignedSearchParams(normalizedPath, query, expiresAt);
52
+ const params = buildSignedSearchParams(normalizedPath, query, expiresAt, secret);
144
53
  return `${normalizedPath}?${params.toString()}`;
145
54
  }
146
- function absoluteTemporarySignedUrl(path, expiresInSeconds, query = {}, origin = resolveSignedUrlOrigin()) {
147
- return `${origin.replace(/\/$/, "")}${temporarySignedUrl(path, expiresInSeconds, query)}`;
55
+ function absoluteTemporarySignedUrl(path, expiresInSeconds, query = {}, origin, secret) {
56
+ return `${origin.replace(/\/$/, "")}${temporarySignedUrl(path, expiresInSeconds, query, secret)}`;
148
57
  }
149
58
  function readSignedRequestUrl(input) {
150
59
  if (input instanceof URL) {
151
60
  return input;
152
61
  }
153
62
  if (typeof input === "string") {
154
- return new URL(input, resolveSignedUrlOrigin());
63
+ return new URL(input, "http://signed-url.invalid");
155
64
  }
156
65
  return new URL(input.url);
157
66
  }
158
- function hasValidSignature(input) {
67
+ function hasValidSignature(input, secret) {
159
68
  const url = readSignedRequestUrl(input);
160
69
  const signature = url.searchParams.get("signature");
161
70
  if (!signature) {
@@ -169,17 +78,18 @@ function hasValidSignature(input) {
169
78
  if (!Number.isInteger(expiresAt) || expiresAt <= Math.floor(Date.now() / 1000)) {
170
79
  return false;
171
80
  }
172
- const expected = signCanonicalPayload(url.pathname, sortedQueryString(url.searchParams));
81
+ const expected = signCanonicalPayload(url.pathname, sortedQueryString(url.searchParams), secret);
173
82
  return timingSafeCompareString(signature, expected);
174
83
  }
175
- function assertValidSignature(input) {
176
- if (!hasValidSignature(input)) {
84
+ function assertValidSignature(input, secret) {
85
+ if (!hasValidSignature(input, secret)) {
177
86
  throw new ForbiddenError("Invalid or expired signed URL.");
178
87
  }
179
88
  }
180
- function createValidateSignatureMiddleware() {
89
+ function createValidateSignatureMiddleware(options) {
90
+ const secret = options?.secret ?? missingSignedUrlSecret();
181
91
  return async (request, next) => {
182
- assertValidSignature(request);
92
+ assertValidSignature(request, secret);
183
93
  return await next();
184
94
  };
185
95
  }
@@ -1,126 +1,13 @@
1
1
  // @bun
2
- var __esm = (fn, res, err) => () => {
3
- if (fn)
4
- try {
5
- res = fn(fn = 0);
6
- } catch (e) {
7
- err = [e];
8
- }
9
- if (err)
10
- throw err[0];
11
- return res;
12
- };
13
-
14
- // ../../src/core/runtime/asyncContextStore.ts
15
- import { AsyncLocalStorage } from "async_hooks";
16
- function createAsyncContextStore(key) {
17
- const symbol = Symbol.for(key);
18
- const globalRecord = globalThis;
19
- const existing = globalRecord[symbol];
20
- if (existing) {
21
- return existing;
22
- }
23
- const store = new AsyncLocalStorage;
24
- globalRecord[symbol] = store;
25
- return store;
26
- }
27
- var init_asyncContextStore = () => {};
28
-
29
2
  // ../../src/core/http/throttleMiddleware.ts
30
3
  import { createHash } from "crypto";
31
4
  import { currentAuthUser } from "@getstrata/core/auth/authContext";
32
5
  import { currentTenant } from "@getstrata/core/tenant/tenantContext";
33
6
  var {RedisClient } = globalThis.Bun;
34
7
 
35
- // ../../src/core/runtime/appEnv.ts
36
- var NON_PRODUCTION_APP_ENVS = new Set(["local", "development", "dev", "test", "testing", "ci"]);
37
- function normalizeEnvValue(value) {
38
- return (value ?? "").trim().toLowerCase();
39
- }
40
- function isProductionEnv(env = process.env) {
41
- const appEnv = normalizeEnvValue(env.APP_ENV);
42
- const nodeEnv = normalizeEnvValue(env.NODE_ENV);
43
- if (appEnv === "production" || nodeEnv === "production") {
44
- return true;
45
- }
46
- if (appEnv === "") {
47
- return false;
48
- }
49
- return !NON_PRODUCTION_APP_ENVS.has(appEnv);
50
- }
51
- function envFlagEnabled(value) {
52
- return value === "true";
53
- }
54
-
55
- // ../../src/core/runtime/appKeyPrefix.ts
56
- function appKeyPrefix() {
57
- return process.env.APP_KEY_PREFIX?.trim() || "strata";
58
- }
59
- function appCookieName(kind) {
60
- return `${appKeyPrefix()}_${kind}`;
61
- }
62
- function appDevSecret(kind) {
63
- return `${appKeyPrefix()}-dev-${kind}`;
64
- }
65
- function requireConfiguredSecret(names, devKind, env = process.env) {
66
- for (const name of names) {
67
- const value = env[name]?.trim();
68
- if (value) {
69
- return value;
70
- }
71
- }
72
- if (isProductionEnv(env)) {
73
- throw new Error(`${names[0]} must be set outside development. Do not derive secrets from the app name.`);
74
- }
75
- return appDevSecret(devKind);
76
- }
77
- function namespacedRedisKey(kind) {
78
- return `${appKeyPrefix()}:${kind}`;
79
- }
80
- function smtpEhloHost() {
81
- const raw = process.env.MAIL_EHLO?.trim() || `${appKeyPrefix()}.local`;
82
- const safe = raw.replace(/[^a-zA-Z0-9.-]/g, "");
83
- return safe || "strata.local";
84
- }
85
- function siemEventType() {
86
- return process.env.SIEM_EVENT_TYPE?.trim() || `${appKeyPrefix()}.audit`;
87
- }
88
- function appUserAgent() {
89
- return process.env.APP_USER_AGENT?.trim() || appKeyPrefix();
90
- }
91
- function otelServiceName() {
92
- return process.env.OTEL_SERVICE_NAME?.trim() || `${appKeyPrefix()}-api`;
93
- }
94
- function webhookSignatureHeader() {
95
- return process.env.WEBHOOK_SIGNATURE_HEADER?.trim() || `x-${appKeyPrefix()}-signature`;
96
- }
97
- function appDisplayName() {
98
- return process.env.APP_NAME?.trim() || "Strata";
99
- }
100
- function appEnv() {
101
- return process.env.APP_ENV?.trim() || "local";
102
- }
103
- function appUrl() {
104
- return (process.env.APP_URL?.trim() || "http://localhost:3000").replace(/\/$/, "");
105
- }
106
- function apiPrefix() {
107
- const raw = process.env.API_PREFIX?.trim() || "/api/v1";
108
- const withSlash = raw.startsWith("/") ? raw : `/${raw}`;
109
- const trimmed = withSlash.replace(/\/+$/, "");
110
- return trimmed || "/api/v1";
111
- }
112
- function sdkClientClassName() {
113
- const override = process.env.APP_SDK_CLASS?.trim();
114
- if (override && /^[A-Za-z_][A-Za-z0-9_]*$/.test(override)) {
115
- return override;
116
- }
117
- const fromName = appDisplayName().replace(/[^A-Za-z0-9]/g, "");
118
- return fromName ? `${fromName}Client` : "AppClient";
119
- }
120
-
121
8
  // ../../src/core/http/clientIp.ts
122
9
  import { currentRequestMeta } from "@getstrata/core/http/requestMetaContext";
123
- function trustForwardedFor(env = process.env) {
10
+ function trustForwardedFor(env = {}) {
124
11
  return (env.TRUST_FORWARDED_FOR ?? "false") === "true";
125
12
  }
126
13
  function isPrivateAddress(address) {
@@ -140,7 +27,7 @@ function forwardedClientIp(request) {
140
27
  }
141
28
  return request.headers.get("x-real-ip")?.trim() || undefined;
142
29
  }
143
- function readClientIp(request, env = process.env) {
30
+ function readClientIp(request, env = {}) {
144
31
  if (trustForwardedFor(env)) {
145
32
  const forwarded = forwardedClientIp(request);
146
33
  if (forwarded) {
@@ -150,8 +37,21 @@ function readClientIp(request, env = process.env) {
150
37
  return currentRequestMeta().ipAddress ?? undefined;
151
38
  }
152
39
 
40
+ // ../../src/core/runtime/asyncContextStore.ts
41
+ import { AsyncLocalStorage } from "async_hooks";
42
+ function createAsyncContextStore(key) {
43
+ const symbol = Symbol.for(key);
44
+ const globalRecord = globalThis;
45
+ const existing = globalRecord[symbol];
46
+ if (existing) {
47
+ return existing;
48
+ }
49
+ const store = new AsyncLocalStorage;
50
+ globalRecord[symbol] = store;
51
+ return store;
52
+ }
53
+
153
54
  // ../../src/core/http/requestMetaContext.ts
154
- init_asyncContextStore();
155
55
  var requestMetaContext = createAsyncContextStore("@getstrata/requestMetaContext");
156
56
  function runWithRequestMeta(meta, callback) {
157
57
  return requestMetaContext.run(meta, callback);
@@ -163,51 +63,6 @@ function currentRequestMeta2() {
163
63
  };
164
64
  }
165
65
 
166
- // ../../src/core/runtime/frontendMode.ts
167
- var FRONTEND_MODES = ["api", "server-htmx", "spa-react", "hybrid"];
168
- var DEFAULT_SPA_PREFIX = "/app";
169
- var FRONTEND_MODE_PATTERN = new RegExp(`^(${FRONTEND_MODES.join("|")})$`);
170
- function parseFrontendMode(value) {
171
- const mode = (value ?? "api").trim();
172
- if (mode === "server-htmx" || mode === "spa-react" || mode === "hybrid") {
173
- return mode;
174
- }
175
- return "api";
176
- }
177
- function readFrontendMode() {
178
- return parseFrontendMode(process.env.FRONTEND_MODE);
179
- }
180
- function isViewsMode(mode) {
181
- return mode === "server-htmx" || mode === "hybrid";
182
- }
183
- function isSpaMode(mode) {
184
- return mode === "spa-react" || mode === "hybrid";
185
- }
186
- function isViewsEnabled() {
187
- return isViewsMode(readFrontendMode());
188
- }
189
- function isSpaEnabled() {
190
- return isSpaMode(readFrontendMode());
191
- }
192
- function normalizeSpaPrefix(value) {
193
- const raw = (value ?? DEFAULT_SPA_PREFIX).trim() || DEFAULT_SPA_PREFIX;
194
- const withSlash = raw.startsWith("/") ? raw : `/${raw}`;
195
- const trimmed = withSlash.replace(/\/+$/, "");
196
- if (trimmed.length === 0 || trimmed === "/") {
197
- return DEFAULT_SPA_PREFIX;
198
- }
199
- return trimmed;
200
- }
201
- function validateSpaPrefix(value) {
202
- const prefix = normalizeSpaPrefix(value);
203
- if (!/^\/[A-Za-z0-9._~-]+(?:\/[A-Za-z0-9._~-]+)*$/.test(prefix) || prefix.split("/").some((part) => part === "." || part === "..") || prefix === "/api" || prefix.startsWith("/api/") || prefix === "/assets" || prefix.startsWith("/assets/") || ["/health", "/ready", "/metrics"].includes(prefix))
204
- throw new Error("SPA_PREFIX must be a dedicated URL path outside API, assets and health/metrics routes.");
205
- return prefix;
206
- }
207
- function readSpaPrefix() {
208
- return validateSpaPrefix(process.env.SPA_PREFIX);
209
- }
210
-
211
66
  // ../../src/core/view/webErrorView.ts
212
67
  import { currentRequestMeta as currentRequestMeta3 } from "@getstrata/core/http/requestMetaContext";
213
68
 
@@ -286,7 +141,18 @@ function htmlResponse(html, init = {}) {
286
141
  }
287
142
 
288
143
  // ../../src/core/view/webErrorView.ts
289
- var configuredErrorView = {};
144
+ function createWebErrorView(options = {}) {
145
+ const render = options.render;
146
+ return async (input) => {
147
+ const resolved = { ...input, request: input.request ?? currentRequestMeta3().request };
148
+ if (render) {
149
+ try {
150
+ return await render(resolved);
151
+ } catch {}
152
+ }
153
+ return renderKernelErrorChrome(resolved);
154
+ };
155
+ }
290
156
  function escapeHtml(value) {
291
157
  return value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;");
292
158
  }
@@ -333,22 +199,11 @@ function renderKernelErrorChrome(input) {
333
199
  </html>
334
200
  `;
335
201
  }
336
- async function renderWebErrorHtml(input) {
337
- const render = configuredErrorView.render;
338
- if (!render) {
339
- return renderKernelErrorChrome(input);
340
- }
341
- try {
342
- return await render({
343
- ...input,
344
- request: input.request ?? currentRequestMeta3().request
345
- });
346
- } catch {
347
- return renderKernelErrorChrome(input);
348
- }
202
+ async function renderWebErrorHtml(input, render = currentRequestMeta3().webErrorView ?? createWebErrorView()) {
203
+ return render(input);
349
204
  }
350
- async function htmlErrorResponse(input) {
351
- const response = htmlResponse(await renderWebErrorHtml(input), { status: input.status });
205
+ async function htmlErrorResponse(input, render) {
206
+ const response = htmlResponse(await renderWebErrorHtml(input, render), { status: input.status });
352
207
  response.headers.set("Cache-Control", "no-store");
353
208
  return response;
354
209
  }
@@ -387,7 +242,7 @@ function requestPrefersJson(request) {
387
242
  // ../../src/core/http/throttleResponse.ts
388
243
  async function tooManyRequestsResponse(request, message, decaySeconds) {
389
244
  const retryAfter = { "retry-after": String(decaySeconds) };
390
- if (requestPrefersJson(request) || !isViewsEnabled()) {
245
+ if (currentRequestMeta2().errorFormat === "json" || requestPrefersJson(request) || !(currentRequestMeta2().viewsEnabled ?? false)) {
391
246
  return Response.json({ error: message }, {
392
247
  status: 429,
393
248
  headers: retryAfter
@@ -405,7 +260,7 @@ async function tooManyRequestsResponse(request, message, decaySeconds) {
405
260
  }
406
261
 
407
262
  // ../../src/core/http/throttleMiddleware.ts
408
- function resolveThrottleIdentity(request) {
263
+ function resolveThrottleIdentity(request, trustForwardedFor = false) {
409
264
  const user = currentAuthUser();
410
265
  if (user?.tokenId !== undefined) {
411
266
  return `token:${user.tokenId}`;
@@ -413,7 +268,7 @@ function resolveThrottleIdentity(request) {
413
268
  if (user) {
414
269
  return `user:${user.id}`;
415
270
  }
416
- return readClientIp(request) ?? "unknown";
271
+ return readClientIp(request, { TRUST_FORWARDED_FOR: String(trustForwardedFor) }) ?? "unknown";
417
272
  }
418
273
  var CONSUME_THROTTLE = `
419
274
  local count = redis.call('INCR', KEYS[1])
@@ -423,14 +278,14 @@ if ttl < 0 then
423
278
  end
424
279
  return count
425
280
  `;
426
- function redisThrottleKey(request, prefix, identity, tenantId = currentTenant()?.id ?? null) {
281
+ function redisThrottleKey(request, prefix, identity, tenantId = currentTenant()?.id ?? null, namespace = "strata") {
427
282
  const bucket = JSON.stringify([
428
283
  tenantId,
429
284
  request.method,
430
285
  currentRequestMeta2().routeTemplate ?? "__unmatched__",
431
286
  identity
432
287
  ]);
433
- return namespacedRedisKey(`${prefix}:${createHash("sha256").update(bucket).digest("hex")}`);
288
+ return `${namespace}:${prefix}:${createHash("sha256").update(bucket).digest("hex")}`;
434
289
  }
435
290
  async function consumeRedisThrottle(client, key, decaySeconds, timeoutMs = 1000, signal) {
436
291
  const expiryMs = Math.max(1, Math.ceil(decaySeconds * 1000));
@@ -506,7 +361,7 @@ function throttleUnavailableResponse() {
506
361
  headers: { "retry-after": "1" }
507
362
  });
508
363
  }
509
- function resolveThrottleQuota(request, options, identity = resolveThrottleIdentity(request)) {
364
+ function resolveThrottleQuota(request, options, identity = resolveThrottleIdentity(request, options.trustForwardedFor)) {
510
365
  const limit = options.quotaPolicy ? options.quotaPolicy({
511
366
  request,
512
367
  tenant: currentTenant(),
@@ -520,20 +375,21 @@ function resolveThrottleQuota(request, options, identity = resolveThrottleIdenti
520
375
  return limit;
521
376
  }
522
377
  function createThrottleMiddleware(options) {
378
+ options = Object.freeze({ ...options });
523
379
  if (!Number.isSafeInteger(options.maxAttempts) || options.maxAttempts < 0) {
524
380
  throw new Error("Throttle maxAttempts must be a non-negative safe integer.");
525
381
  }
526
382
  const consume = createRedisThrottleConsumer(options);
527
383
  const prefix = options.keyPrefix ?? "throttle";
528
384
  const middleware = async (request, next) => {
529
- const identity = resolveThrottleIdentity(request);
385
+ const identity = resolveThrottleIdentity(request, options.trustForwardedFor);
530
386
  let maxAttempts;
531
387
  try {
532
388
  maxAttempts = resolveThrottleQuota(request, options, identity);
533
389
  } catch {
534
390
  return throttleUnavailableResponse();
535
391
  }
536
- const key = redisThrottleKey(request, prefix, identity);
392
+ const key = redisThrottleKey(request, prefix, identity, undefined, options.namespace);
537
393
  let attempts;
538
394
  try {
539
395
  attempts = await consume(key, options.decaySeconds);
@@ -1,24 +1,4 @@
1
1
  // @bun
2
- // ../../src/core/runtime/appEnv.ts
3
- var NON_PRODUCTION_APP_ENVS = new Set(["local", "development", "dev", "test", "testing", "ci"]);
4
- function normalizeEnvValue(value) {
5
- return (value ?? "").trim().toLowerCase();
6
- }
7
- function isProductionEnv(env = process.env) {
8
- const appEnv = normalizeEnvValue(env.APP_ENV);
9
- const nodeEnv = normalizeEnvValue(env.NODE_ENV);
10
- if (appEnv === "production" || nodeEnv === "production") {
11
- return true;
12
- }
13
- if (appEnv === "") {
14
- return false;
15
- }
16
- return !NON_PRODUCTION_APP_ENVS.has(appEnv);
17
- }
18
- function envFlagEnabled(value) {
19
- return value === "true";
20
- }
21
-
22
2
  // ../../src/core/http/uploads.ts
23
3
  var DEFAULT_MAX_UPLOAD_BYTES = 5 * 1024 * 1024;
24
4
  var ALLOWED_UPLOAD_MIME_TYPES = new Set([
@@ -33,8 +13,12 @@ var ALLOWED_UPLOAD_MIME_TYPES = new Set([
33
13
  "text/plain",
34
14
  "text/csv"
35
15
  ]);
36
- function resolveMaxUploadBytes() {
37
- const raw = process.env.MAX_UPLOAD_BYTES?.trim() ?? process.env.MAX_REQUEST_BODY_BYTES?.trim();
16
+ var DEFAULT_UPLOAD_POLICY = Object.freeze({
17
+ maxBytes: DEFAULT_MAX_UPLOAD_BYTES,
18
+ allowUnknownMime: false
19
+ });
20
+ function resolveMaxUploadBytes(value) {
21
+ const raw = value?.trim();
38
22
  if (!raw) {
39
23
  return DEFAULT_MAX_UPLOAD_BYTES;
40
24
  }
@@ -47,16 +31,17 @@ function resolveMaxUploadBytes() {
47
31
  function normalizeMimeType(mimeType) {
48
32
  return mimeType.split(";")[0]?.trim().toLowerCase() ?? "";
49
33
  }
50
- function isAllowedMimeType(mimeType) {
34
+ function isAllowedMimeType(mimeType, allowUnknownMime = false) {
51
35
  const normalized = normalizeMimeType(mimeType);
52
36
  if (!normalized || normalized === "application/octet-stream") {
53
- return envFlagEnabled(process.env.UPLOAD_ALLOW_UNKNOWN_MIME);
37
+ return allowUnknownMime;
54
38
  }
55
39
  return ALLOWED_UPLOAD_MIME_TYPES.has(normalized);
56
40
  }
57
41
  export {
58
42
  ALLOWED_UPLOAD_MIME_TYPES,
59
43
  DEFAULT_MAX_UPLOAD_BYTES,
44
+ DEFAULT_UPLOAD_POLICY,
60
45
  isAllowedMimeType,
61
46
  resolveMaxUploadBytes
62
47
  };