@getstrata/core 2.2.59 → 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.
- package/CHANGELOG.md +27 -0
- package/dist/core/audit/exportAuditLogs.d.ts +12 -3
- package/dist/core/audit/exportStore.d.ts +6 -2
- package/dist/core/audit/siemFormatter.d.ts +2 -2
- package/dist/core/auth/abilityCatalog.d.ts +1 -9
- package/dist/core/auth/authContext.d.ts +2 -0
- package/dist/core/auth/authOutcome.d.ts +32 -0
- package/dist/core/auth/authReader.d.ts +22 -0
- package/dist/core/auth/basicAuthGuard.d.ts +19 -3
- package/dist/core/auth/emailVerification.d.ts +1 -1
- package/dist/core/auth/guard.d.ts +27 -6
- package/dist/core/auth/intendedUrlCookie.d.ts +13 -7
- package/dist/core/auth/jwt.d.ts +5 -4
- package/dist/core/auth/jwtGuard.d.ts +7 -6
- package/dist/core/auth/membershipContext.d.ts +10 -7
- package/dist/core/auth/membershipContextMiddleware.d.ts +3 -3
- package/dist/core/auth/membershipMiddleware.d.ts +1 -2
- package/dist/core/auth/membershipServiceImplementation.d.ts +1 -1
- package/dist/core/auth/oauth/oidcIdToken.d.ts +25 -16
- package/dist/core/auth/oauth/oidcProvider.d.ts +6 -4
- package/dist/core/auth/oauth/providers.d.ts +3 -1
- package/dist/core/auth/oneTimeToken.d.ts +2 -3
- package/dist/core/auth/passwordConfirmCookie.d.ts +15 -6
- package/dist/core/auth/passwordLogin.d.ts +5 -5
- package/dist/core/auth/pendingMfaCookie.d.ts +2 -2
- package/dist/core/auth/policy.d.ts +23 -10
- package/dist/core/auth/requireAuthCapability.d.ts +3 -0
- package/dist/core/auth/resolveMembershipService.d.ts +3 -2
- package/dist/core/auth/saml/samlAssertionReplay.d.ts +4 -4
- package/dist/core/auth/saml/samlServiceProvider.d.ts +11 -7
- package/dist/core/auth/scimAuthMiddleware.d.ts +10 -3
- package/dist/core/auth/sessionCookie.d.ts +20 -9
- package/dist/core/auth/sessionGuard.d.ts +14 -3
- package/dist/core/cache/createCacheStore.d.ts +6 -3
- package/dist/core/cache/redisCacheStore.d.ts +5 -1
- package/dist/core/cache/repository.d.ts +5 -1
- package/dist/core/cache/simpleCache.d.ts +2 -1
- package/dist/core/cache/tokens.d.ts +8 -0
- package/dist/core/config/applicationConfig.d.ts +21 -0
- package/dist/core/config/configSnapshot.d.ts +3 -0
- package/dist/core/config/envSchema.d.ts +3 -2
- package/dist/core/contracts/application.d.ts +153 -0
- package/dist/core/contracts/authUserDirectory.d.ts +24 -7
- package/dist/core/contracts/container.d.ts +20 -23
- package/dist/core/contracts/di.d.ts +4 -2
- package/dist/core/contracts/executionContext.d.ts +5 -0
- package/dist/core/contracts/executionOperations.d.ts +10 -0
- package/dist/core/contracts/executionOwnership.d.ts +38 -0
- package/dist/core/contracts/persistence.d.ts +20 -0
- package/dist/core/contracts/serviceTokens.d.ts +32 -18
- package/dist/core/contracts/services.d.ts +63 -0
- package/dist/core/contracts/token.d.ts +19 -0
- package/dist/core/crypto/fieldEncryption.d.ts +19 -7
- package/dist/core/crypto/fieldEncryptionRotation.d.ts +21 -5
- package/dist/core/crypto/mfaSecret.d.ts +10 -3
- package/dist/core/database/baseRepository.d.ts +14 -10
- package/dist/core/database/bindings.d.ts +6 -0
- package/dist/core/database/bunSql.d.ts +3 -12
- package/dist/core/database/definitions.d.ts +209 -0
- package/dist/core/database/dialect.d.ts +5 -24
- package/dist/core/database/driverPorts.d.ts +116 -0
- package/dist/core/database/errors.d.ts +47 -7
- package/dist/core/database/factory.d.ts +51 -31
- package/dist/core/database/index.d.ts +9 -10
- package/dist/core/database/keyset.d.ts +2 -1
- package/dist/core/database/legacyNativeTransaction.d.ts +5 -0
- package/dist/core/database/manager.d.ts +12 -0
- package/dist/core/database/model.d.ts +91 -97
- package/dist/core/database/modelQuery.d.ts +9 -5
- package/dist/core/database/modelRegistry.d.ts +52 -33
- package/dist/core/database/mysqlConnection.d.ts +1 -19
- package/dist/core/database/mysqlNative.d.ts +38 -0
- package/dist/core/database/nativeTransactions.d.ts +16 -0
- package/dist/core/database/ormInternal.d.ts +85 -0
- package/dist/core/database/ormRuntime.d.ts +4 -0
- package/dist/core/database/ownedReadOnlyObservation.d.ts +16 -0
- package/dist/core/database/postgresNative.d.ts +11 -0
- package/dist/core/database/query.d.ts +24 -23
- package/dist/core/database/queryPlanSnapshot.d.ts +7 -0
- package/dist/core/database/rawMysql.d.ts +7 -0
- package/dist/core/database/rawPostgres.d.ts +23 -0
- package/dist/core/database/rawSqlite.d.ts +6 -0
- package/dist/core/database/relationQueries.d.ts +3 -2
- package/dist/core/database/relationQuery.d.ts +24 -6
- package/dist/core/database/repositoryQuery.d.ts +6 -1
- package/dist/core/database/schema/driver.d.ts +1 -1
- package/dist/core/database/seeders/types.d.ts +1 -1
- package/dist/core/database/session.d.ts +13 -0
- package/dist/core/database/sessionFactory.d.ts +9 -0
- package/dist/core/database/sqlDialects.d.ts +22 -0
- package/dist/core/database/tokens.d.ts +7 -0
- package/dist/core/database/transactionSession.d.ts +43 -0
- package/dist/core/errors/http.d.ts +4 -1
- package/dist/core/events/{eventBus.d.ts → eventBusClass.d.ts} +1 -3
- package/dist/core/events/index.d.ts +2 -3
- package/dist/core/events/outbox/index.d.ts +44 -13
- package/dist/core/events/outbox/metrics.d.ts +4 -4
- package/dist/core/events/outbox/workerTransport.d.ts +17 -0
- package/dist/core/http/authMiddleware.d.ts +2 -2
- package/dist/core/http/authorizeMiddleware.d.ts +2 -2
- package/dist/core/http/bodySizeLimitMiddleware.d.ts +1 -1
- package/dist/core/http/conditionalResponse.d.ts +7 -2
- package/dist/core/http/contentSecurityPolicy.d.ts +4 -3
- package/dist/core/http/corsMiddleware.d.ts +2 -1
- package/dist/core/http/csrfMiddleware.d.ts +6 -1
- package/dist/core/http/csrfToken.d.ts +17 -7
- package/dist/core/http/databaseError.d.ts +4 -0
- package/dist/core/http/etag.d.ts +5 -2
- package/dist/core/http/flashMiddleware.d.ts +1 -1
- package/dist/core/http/flashSession.d.ts +13 -7
- package/dist/core/http/index.d.ts +1 -1
- package/dist/core/http/loginThrottleMiddleware.d.ts +3 -3
- package/dist/core/http/memoryThrottleMiddleware.d.ts +2 -2
- package/dist/core/http/parseMultipartUpload.d.ts +3 -2
- package/dist/core/http/requestMetaContext.d.ts +5 -0
- package/dist/core/http/requireAbilityMiddleware.d.ts +1 -1
- package/dist/core/http/requireAuthMiddleware.d.ts +2 -2
- package/dist/core/http/requirePasswordConfirmMiddleware.d.ts +2 -1
- package/dist/core/http/requireVerifiedMiddleware.d.ts +2 -2
- package/dist/core/http/requireWebAuthMiddleware.d.ts +2 -2
- package/dist/core/http/response.d.ts +4 -3
- package/dist/core/http/scimThrottleMiddleware.d.ts +4 -3
- package/dist/core/http/securedRouteModelBinding.d.ts +10 -3
- package/dist/core/http/securityHeadersMiddleware.d.ts +1 -2
- package/dist/core/http/signedUrl.d.ts +8 -6
- package/dist/core/http/throttleMiddleware.d.ts +9 -5
- package/dist/core/http/uploads.d.ts +9 -3
- package/dist/core/http/webErrorResponse.d.ts +8 -2
- package/dist/core/jobs/exportAuditLogsJob.d.ts +5 -2
- package/dist/core/jobs/invalidateCacheTagsJob.d.ts +5 -4
- package/dist/core/lifecycle/gracefulShutdown.d.ts +2 -5
- package/dist/core/logging/requestLoggingMiddleware.d.ts +1 -1
- package/dist/core/mail/mailer.d.ts +7 -5
- package/dist/core/openapi/generator.d.ts +12 -4
- package/dist/core/openapi/registeredRoute.d.ts +4 -4
- package/dist/core/queue/createAppQueue.d.ts +9 -4
- package/dist/core/queue/failedJobMetrics.d.ts +11 -2
- package/dist/core/queue/failedJobRepository.d.ts +6 -3
- package/dist/core/queue/failedJobService.d.ts +1 -0
- package/dist/core/queue/index.d.ts +16 -6
- package/dist/core/queue/jobRegistry.d.ts +3 -2
- package/dist/core/queue/jobRunner.d.ts +10 -4
- package/dist/core/queue/publicQueue.d.ts +18 -9
- package/dist/core/queue/queueConfig.d.ts +20 -10
- package/dist/core/queue/queueHandoff.d.ts +31 -0
- package/dist/core/queue/queueMetrics.d.ts +10 -3
- package/dist/core/queue/queueServices.d.ts +28 -0
- package/dist/core/queue/queueWorkerTransport.d.ts +28 -0
- package/dist/core/queue/redisQueue.d.ts +19 -10
- package/dist/core/queue/redisQueueKeys.d.ts +5 -5
- package/dist/core/queue/redisStreams.d.ts +17 -10
- package/dist/core/queue/resilientQueue.d.ts +10 -4
- package/dist/core/queue/types.d.ts +1 -0
- package/dist/core/runtime/appKeyPrefix.d.ts +5 -5
- package/dist/core/runtime/application.d.ts +7 -0
- package/dist/core/runtime/executionContext.d.ts +9 -0
- package/dist/core/runtime/executionTasks.d.ts +49 -0
- package/dist/core/runtime/resourceJournal.d.ts +67 -0
- package/dist/core/runtime/serviceGraph.d.ts +14 -0
- package/dist/core/security/oauthState.d.ts +13 -9
- package/dist/core/security/publicReads.d.ts +2 -2
- package/dist/core/security/safeFetch.d.ts +1 -0
- package/dist/core/security/safeUrl.d.ts +3 -0
- package/dist/core/security/scimTenantTokens.d.ts +1 -1
- package/dist/core/security/tokenExpiry.d.ts +1 -1
- package/dist/core/security/webhookSignature.d.ts +1 -1
- package/dist/core/storage/storage.d.ts +24 -16
- package/dist/core/tenant/databaseTenantContext.d.ts +5 -7
- package/dist/core/tenant/resolveTenant.d.ts +2 -2
- package/dist/core/tenant/scopedDatabasePolicy.d.ts +8 -0
- package/dist/core/tenant/tenantDatabaseScope.d.ts +3 -7
- package/dist/core/tenant/tenantMiddleware.d.ts +15 -4
- package/dist/core/tracing/otel.d.ts +4 -6
- package/dist/core/tracing/tracingMiddleware.d.ts +3 -3
- package/dist/core/view/etaViewEngine.d.ts +1 -1
- package/dist/core/view/index.d.ts +5 -4
- package/dist/core/view/tokens.d.ts +8 -0
- package/dist/core/view/viewRenderer.d.ts +2 -2
- package/dist/core/view/webErrorView.d.ts +8 -7
- package/dist/core/view/webLayoutData.d.ts +6 -4
- package/dist/entries/audit/exportAuditLogs.js +87 -1024
- package/dist/entries/audit/siemFormatter.js +4 -90
- package/dist/entries/auth/abilityCatalog.js +28 -0
- package/dist/entries/auth/accessControl.js +5 -16
- package/dist/entries/auth/accountStateMigration.js +216 -236
- package/dist/entries/auth/authOutcome.js +80 -0
- package/dist/entries/auth/authReader.js +68 -0
- package/dist/entries/auth/basicAuthGuard.js +144 -1249
- package/dist/entries/auth/emailVerification.js +2 -2
- package/dist/entries/auth/intendedUrlCookie.js +35 -59
- package/dist/entries/auth/jwt.js +22 -47
- package/dist/entries/auth/jwtGuard.js +99 -231
- package/dist/entries/auth/membershipMiddleware.js +71 -10
- package/dist/entries/auth/membershipScope.js +16 -22
- package/dist/entries/auth/membershipService.js +11 -28
- package/dist/entries/auth/oauth/oidcProvider.js +59 -64
- package/dist/entries/auth/oauth/providers.js +12 -95
- package/dist/entries/auth/oauth/samlProvider.js +53 -1080
- package/dist/entries/auth/oneTimeToken.js +27 -289
- package/dist/entries/auth/passwordConfirmCookie.js +40 -63
- package/dist/entries/auth/passwordLogin.js +94 -399
- package/dist/entries/auth/pendingMfaCookie.js +6 -6
- package/dist/entries/auth/policy.js +22 -56
- package/dist/entries/auth/saml/samlServiceProvider.js +55 -1084
- package/dist/entries/auth/scimAuthMiddleware.js +16 -3358
- package/dist/entries/auth/sessionCookie.js +58 -73
- package/dist/entries/auth/sessionGuard.js +95 -248
- package/dist/entries/auth/tokenHash.js +11 -43
- package/dist/entries/cache/createCacheStore.js +126 -117
- package/dist/entries/cache/repository.js +25 -0
- package/dist/entries/cache/simpleCache.js +12 -7
- package/dist/entries/cache/tokens.js +9 -0
- package/dist/entries/config/applicationConfig.js +163 -0
- package/dist/entries/config/envSchema.js +21 -4
- package/dist/entries/contracts/application.js +1 -0
- package/dist/entries/contracts/authUserDirectory.js +10 -0
- package/dist/entries/contracts/container.js +99 -26
- package/dist/entries/contracts/di.js +3 -0
- package/dist/entries/contracts/executionContext.js +7 -0
- package/dist/entries/contracts/executionOperations.js +7 -0
- package/dist/entries/contracts/executionOwnership.js +7 -0
- package/dist/entries/contracts/membership.js +1 -0
- package/dist/entries/contracts/persistence.js +1 -0
- package/dist/entries/contracts/serviceTokens.js +26 -116
- package/dist/entries/contracts/services.js +98 -0
- package/dist/entries/contracts/token.js +41 -0
- package/dist/entries/crypto/fieldEncryption.js +49 -50
- package/dist/entries/crypto/mfaSecret.js +86 -82
- package/dist/entries/database/acquisitionMetrics.js +107 -0
- package/dist/entries/database/baseRepository.d.ts +2 -0
- package/dist/entries/database/bindings.js +2082 -0
- package/dist/entries/database/definitions.js +175 -0
- package/dist/entries/database/errors.js +114 -89
- package/dist/entries/database/factory.js +67 -28
- package/dist/entries/database/migrations.js +172 -224
- package/dist/entries/database/model.d.ts +1 -0
- package/dist/entries/database/ownedReadOnlyObservation.js +1282 -0
- package/dist/entries/database/query.js +159 -161
- package/dist/entries/database/repositoryQuery.d.ts +1 -0
- package/dist/entries/database/repositoryQuery.js +1 -1373
- package/dist/entries/database/schema.js +216 -236
- package/dist/entries/database/session.js +1 -0
- package/dist/entries/database/sqliteConnection.js +525 -83
- package/dist/entries/database/tokens.js +9 -0
- package/dist/entries/errors/http.js +118 -1
- package/dist/entries/http/authMiddleware.js +8 -5
- package/dist/entries/http/authorizeMiddleware.js +1 -1
- package/dist/entries/http/bodySizeLimitMiddleware.js +2 -2
- package/dist/entries/http/clientIp.js +2 -2
- package/dist/entries/http/conditionalResponse.js +19 -7
- package/dist/entries/http/corsMiddleware.js +6 -101
- package/dist/entries/http/csrfMiddleware.js +92 -106
- package/dist/entries/http/csrfToken.js +58 -94
- package/dist/entries/http/etag.js +7 -4
- package/dist/entries/http/flashMiddleware.js +57 -99
- package/dist/entries/http/flashSession.js +41 -68
- package/dist/entries/http/memoryThrottleMiddleware.js +43 -186
- package/dist/entries/http/metricsMiddleware.js +2 -16
- package/dist/entries/http/parseMultipartUpload.js +15 -29
- package/dist/entries/http/requireAbilityMiddleware.js +2 -2
- package/dist/entries/http/requirePasswordConfirmMiddleware.js +19 -31
- package/dist/entries/http/requireVerifiedMiddleware.js +4 -7
- package/dist/entries/http/requireWebAuthMiddleware.js +2 -2
- package/dist/entries/http/response.js +67 -233
- package/dist/entries/http/routeMiddleware.js +0 -14
- package/dist/entries/http/scimThrottleMiddleware.js +43 -237
- package/dist/entries/http/securedRouteModelBinding.js +37 -25
- package/dist/entries/http/securityHeadersMiddleware.js +8 -25
- package/dist/entries/http/signedUrl.js +20 -110
- package/dist/entries/http/throttleMiddleware.js +41 -185
- package/dist/entries/http/uploads.js +9 -24
- package/dist/entries/jobs/exportAuditLogsJob.js +17 -1498
- package/dist/entries/jobs/invalidateCacheTagsJob.js +12 -47
- package/dist/entries/logging/requestLoggingMiddleware.js +4 -4
- package/dist/entries/mail/mailer.js +68 -78
- package/dist/entries/openapi/generator.js +33 -100
- package/dist/entries/queue/createAppQueue.js +416 -254
- package/dist/entries/queue/failedJobRepository.js +19 -8
- package/dist/entries/queue/failedJobService.js +1 -0
- package/dist/entries/queue/jobRunner.js +141 -66
- package/dist/entries/queue/publicQueue.js +411 -255
- package/dist/entries/queue/queueConfig.js +61 -0
- package/dist/entries/queue/queueHandoff.js +318 -0
- package/dist/entries/queue/queueMetrics.js +989 -1384
- package/dist/entries/queue/queueServices.js +133 -0
- package/dist/entries/queue/queueWorkerTransport.js +1703 -0
- package/dist/entries/queue/redisQueue.js +282 -180
- package/dist/entries/queue.js +6 -45
- package/dist/entries/runtime/application.js +1585 -0
- package/dist/entries/runtime/asyncContextStore.js +0 -16
- package/dist/entries/security/oauthState.js +35 -67
- package/dist/entries/security/publicReads.js +4 -4
- package/dist/entries/security/safeFetch.js +1 -0
- package/dist/entries/security/scimTenantTokens.js +3 -3
- package/dist/entries/security/tokenExpiry.js +2 -2
- package/dist/entries/security/totp.js +1 -87
- package/dist/entries/security/webhookSignature.js +2 -90
- package/dist/entries/storage/storage.js +120 -45
- package/dist/entries/tenant/databaseTenantContext.js +6 -907
- package/dist/entries/tenant/publicTenantHost.js +78 -0
- package/dist/entries/tenant/resolveTenant.js +14 -0
- package/dist/entries/tenant/scopedDatabasePolicy.js +75 -0
- package/dist/entries/tenant/tenancyConfig.js +1 -19
- package/dist/entries/tenant/tenantDatabaseScope.js +3 -892
- package/dist/entries/tracing/tracingMiddleware.js +104 -173
- package/dist/entries/view/tokens.js +11 -0
- package/dist/framework/public-api.d.ts +62 -44
- package/dist/index.js +10433 -11347
- package/dist/internal/ormInternal.js +117 -0
- package/dist/internal/ormRuntime.js +5000 -0
- package/package.json +158 -46
- package/dist/core/database/bindConnection.d.ts +0 -1
- package/dist/core/database/boundConnection.d.ts +0 -5
- package/dist/core/database/defaultConnection.d.ts +0 -7
- package/dist/core/database/namedConnections.d.ts +0 -15
- package/dist/core/database/readOnlyCollector.d.ts +0 -7
- package/dist/core/database/repositoryConnection.d.ts +0 -4
- package/dist/core/database/transaction.d.ts +0 -23
- package/dist/core/database/transactionControl.d.ts +0 -6
- package/dist/core/events/deferredModelEvents.d.ts +0 -7
- package/dist/core/facades/index.d.ts +0 -10
- package/dist/core/runtime/applicationRegistry.d.ts +0 -18
- package/dist/entries/database/bindConnection.js +0 -1
- package/dist/entries/database/boundConnection.js +0 -1
- package/dist/entries/database/defaultConnection.js +0 -1
- package/dist/entries/database/namedConnections.js +0 -1
- package/dist/entries/database/repositoryConnection.js +0 -1
- package/dist/entries/database/transaction.js +0 -1
- package/dist/entries/facades.js +0 -711
- package/dist/entries/runtime/applicationRegistry.js +0 -1
|
@@ -24,8 +24,8 @@ import { createCipheriv, createDecipheriv, createHmac, randomBytes } from "crypt
|
|
|
24
24
|
var ENCRYPTION_PREFIX = "enc:v1:";
|
|
25
25
|
var IV_LENGTH = 12;
|
|
26
26
|
var TAG_LENGTH = 16;
|
|
27
|
-
function resolveEncryptionKey() {
|
|
28
|
-
const raw =
|
|
27
|
+
function resolveEncryptionKey(env) {
|
|
28
|
+
const raw = env.KMS_ENCRYPTION_KEY?.trim();
|
|
29
29
|
if (!raw) {
|
|
30
30
|
return null;
|
|
31
31
|
}
|
|
@@ -38,15 +38,45 @@ function resolveEncryptionKey() {
|
|
|
38
38
|
}
|
|
39
39
|
throw new Error("KMS_ENCRYPTION_KEY must be 32 bytes (hex or base64).");
|
|
40
40
|
}
|
|
41
|
-
function
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
41
|
+
function createFieldEncryptionCodec(env) {
|
|
42
|
+
const configured = resolveFieldEncryptionKeyring(env);
|
|
43
|
+
const key = resolveEncryptionKey(env);
|
|
44
|
+
const enabled = env.FEATURE_FIELD_ENCRYPTION === "false" ? false : env.FEATURE_FIELD_ENCRYPTION === "true" ? true : Boolean(configured || key);
|
|
45
|
+
return Object.freeze({
|
|
46
|
+
isFieldEncryptionEnabled: () => enabled,
|
|
47
|
+
protectEmail(email) {
|
|
48
|
+
const normalized = normalizeEmail(email);
|
|
49
|
+
if (configured && enabled)
|
|
50
|
+
return {
|
|
51
|
+
storedEmail: configured.encrypt(normalized, "email"),
|
|
52
|
+
emailLookup: configured.keyring.lookup(normalized)
|
|
53
|
+
};
|
|
54
|
+
if (!key || !enabled)
|
|
55
|
+
return { storedEmail: normalized, emailLookup: normalized };
|
|
56
|
+
return {
|
|
57
|
+
storedEmail: encryptField(normalized, key),
|
|
58
|
+
emailLookup: hashLookupValue(normalized, key)
|
|
59
|
+
};
|
|
60
|
+
},
|
|
61
|
+
revealEmail(storedEmail) {
|
|
62
|
+
if (configured && storedEmail.startsWith("enc:"))
|
|
63
|
+
return configured.keyring.decrypt(storedEmail, "email");
|
|
64
|
+
if (storedEmail.startsWith("enc:") && !storedEmail.startsWith(ENCRYPTION_PREFIX))
|
|
65
|
+
throw new Error("Identified encrypted fields require KMS_ENCRYPTION_KEYRING.");
|
|
66
|
+
if (!key || !storedEmail.startsWith(ENCRYPTION_PREFIX))
|
|
67
|
+
return storedEmail;
|
|
68
|
+
return decryptField(storedEmail, key);
|
|
69
|
+
},
|
|
70
|
+
emailLookupForQuery(email) {
|
|
71
|
+
const normalized = normalizeEmail(email);
|
|
72
|
+
if (configured && enabled)
|
|
73
|
+
return configured.keyring.lookup(normalized);
|
|
74
|
+
return !key || !enabled ? normalized : hashLookupValue(normalized, key);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
function isFieldEncryptionEnabled(codec) {
|
|
79
|
+
return codec.isFieldEncryptionEnabled();
|
|
50
80
|
}
|
|
51
81
|
function encryptField(plaintext, key) {
|
|
52
82
|
const iv = randomBytes(IV_LENGTH);
|
|
@@ -74,46 +104,14 @@ function hashLookupValue(normalizedValue, key) {
|
|
|
74
104
|
function normalizeEmail(email) {
|
|
75
105
|
return email.trim().toLowerCase();
|
|
76
106
|
}
|
|
77
|
-
function protectEmail(email) {
|
|
78
|
-
|
|
79
|
-
const configured = resolveFieldEncryptionKeyring();
|
|
80
|
-
if (configured && isFieldEncryptionEnabled()) {
|
|
81
|
-
return {
|
|
82
|
-
storedEmail: configured.encrypt(normalized, "email"),
|
|
83
|
-
emailLookup: configured.keyring.lookup(normalized)
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
const key = resolveEncryptionKey();
|
|
87
|
-
if (!key || !isFieldEncryptionEnabled()) {
|
|
88
|
-
return { storedEmail: normalized, emailLookup: normalized };
|
|
89
|
-
}
|
|
90
|
-
return {
|
|
91
|
-
storedEmail: encryptField(normalized, key),
|
|
92
|
-
emailLookup: hashLookupValue(normalized, key)
|
|
93
|
-
};
|
|
107
|
+
function protectEmail(email, codec) {
|
|
108
|
+
return codec.protectEmail(email);
|
|
94
109
|
}
|
|
95
|
-
function revealEmail(storedEmail) {
|
|
96
|
-
|
|
97
|
-
if (configured && storedEmail.startsWith("enc:"))
|
|
98
|
-
return configured.keyring.decrypt(storedEmail, "email");
|
|
99
|
-
if (storedEmail.startsWith("enc:") && !storedEmail.startsWith(ENCRYPTION_PREFIX))
|
|
100
|
-
throw new Error("Identified encrypted fields require KMS_ENCRYPTION_KEYRING.");
|
|
101
|
-
const key = resolveEncryptionKey();
|
|
102
|
-
if (!key || !storedEmail.startsWith(ENCRYPTION_PREFIX)) {
|
|
103
|
-
return storedEmail;
|
|
104
|
-
}
|
|
105
|
-
return decryptField(storedEmail, key);
|
|
110
|
+
function revealEmail(storedEmail, codec) {
|
|
111
|
+
return codec.revealEmail(storedEmail);
|
|
106
112
|
}
|
|
107
|
-
function emailLookupForQuery(email) {
|
|
108
|
-
|
|
109
|
-
const configured = resolveFieldEncryptionKeyring();
|
|
110
|
-
if (configured && isFieldEncryptionEnabled())
|
|
111
|
-
return configured.keyring.lookup(normalized);
|
|
112
|
-
const key = resolveEncryptionKey();
|
|
113
|
-
if (!key || !isFieldEncryptionEnabled()) {
|
|
114
|
-
return normalized;
|
|
115
|
-
}
|
|
116
|
-
return hashLookupValue(normalized, key);
|
|
113
|
+
function emailLookupForQuery(email, codec) {
|
|
114
|
+
return codec.emailLookupForQuery(email);
|
|
117
115
|
}
|
|
118
116
|
function createFieldEncryptionKeyring(options) {
|
|
119
117
|
const identifier = /^[A-Za-z0-9_-]{1,64}$/;
|
|
@@ -194,7 +192,7 @@ function createFieldEncryptionKeyring(options) {
|
|
|
194
192
|
}
|
|
195
193
|
});
|
|
196
194
|
}
|
|
197
|
-
function resolveFieldEncryptionKeyring(env
|
|
195
|
+
function resolveFieldEncryptionKeyring(env) {
|
|
198
196
|
const raw = env.KMS_ENCRYPTION_KEYRING;
|
|
199
197
|
if (raw === undefined)
|
|
200
198
|
return null;
|
|
@@ -244,41 +242,47 @@ function resolveFieldEncryptionKeyring(env = process.env) {
|
|
|
244
242
|
}
|
|
245
243
|
|
|
246
244
|
// ../../src/core/crypto/mfaSecret.ts
|
|
247
|
-
function
|
|
248
|
-
const configured = resolveFieldEncryptionKeyring();
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
245
|
+
function createMfaSecretCodec(env) {
|
|
246
|
+
const configured = resolveFieldEncryptionKeyring(env);
|
|
247
|
+
const key = resolveEncryptionKey(env);
|
|
248
|
+
const production = isProductionEnv(env);
|
|
249
|
+
return Object.freeze({
|
|
250
|
+
protectMfaSecret(secret) {
|
|
251
|
+
if (configured)
|
|
252
|
+
return configured.encrypt(secret, "mfa");
|
|
253
|
+
if (!key)
|
|
254
|
+
throw new Error("MFA secrets require KMS_ENCRYPTION_KEY.");
|
|
255
|
+
return encryptField(secret, key);
|
|
256
|
+
},
|
|
257
|
+
revealMfaSecret(stored) {
|
|
258
|
+
if (!stored)
|
|
259
|
+
return null;
|
|
260
|
+
if (configured) {
|
|
261
|
+
if (!stored.startsWith("enc:"))
|
|
262
|
+
throw new Error("MFA secrets must be encrypted.");
|
|
263
|
+
return configured.keyring.decrypt(stored, "mfa");
|
|
264
|
+
}
|
|
265
|
+
if (stored.startsWith("enc:") && !stored.startsWith("enc:v1:"))
|
|
266
|
+
throw new Error("Identified MFA secrets require KMS_ENCRYPTION_KEYRING.");
|
|
267
|
+
if (!stored.startsWith("enc:v1:")) {
|
|
268
|
+
if (production || key)
|
|
269
|
+
throw new Error("MFA secrets must be encrypted.");
|
|
270
|
+
return stored;
|
|
271
|
+
}
|
|
272
|
+
if (!key)
|
|
273
|
+
throw new Error("MFA secrets require KMS_ENCRYPTION_KEY.");
|
|
274
|
+
return decryptField(stored, key);
|
|
272
275
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
return
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
function protectMfaSecret(secret, codec) {
|
|
279
|
+
return codec.protectMfaSecret(secret);
|
|
280
|
+
}
|
|
281
|
+
function revealMfaSecret(stored, codec) {
|
|
282
|
+
return codec.revealMfaSecret(stored);
|
|
280
283
|
}
|
|
281
284
|
export {
|
|
285
|
+
createMfaSecretCodec,
|
|
282
286
|
protectMfaSecret,
|
|
283
287
|
revealMfaSecret
|
|
284
288
|
};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// ../../src/core/database/acquisitionMetrics.ts
|
|
3
|
+
var ACQUISITION_BUCKETS_SECONDS = [
|
|
4
|
+
0.001,
|
|
5
|
+
0.005,
|
|
6
|
+
0.01,
|
|
7
|
+
0.025,
|
|
8
|
+
0.05,
|
|
9
|
+
0.1,
|
|
10
|
+
0.25,
|
|
11
|
+
0.5,
|
|
12
|
+
1,
|
|
13
|
+
2.5,
|
|
14
|
+
5,
|
|
15
|
+
10
|
|
16
|
+
];
|
|
17
|
+
var outcomes = ["acquired", "failed", "aborted"];
|
|
18
|
+
var metricsBrand = Symbol("transaction acquisition metrics");
|
|
19
|
+
var states = new WeakMap;
|
|
20
|
+
function createTransactionAcquisitionMetrics() {
|
|
21
|
+
const state = {
|
|
22
|
+
inflight: 0,
|
|
23
|
+
outcomes: outcomes.map((outcome) => ({
|
|
24
|
+
outcome,
|
|
25
|
+
count: 0,
|
|
26
|
+
sumSeconds: 0,
|
|
27
|
+
buckets: ACQUISITION_BUCKETS_SECONDS.map(() => 0)
|
|
28
|
+
}))
|
|
29
|
+
};
|
|
30
|
+
const metrics = {
|
|
31
|
+
[metricsBrand]: true,
|
|
32
|
+
snapshot: () => ({
|
|
33
|
+
inflight: state.inflight,
|
|
34
|
+
outcomes: state.outcomes.map((histogram) => ({
|
|
35
|
+
...histogram,
|
|
36
|
+
buckets: [...histogram.buckets]
|
|
37
|
+
}))
|
|
38
|
+
})
|
|
39
|
+
};
|
|
40
|
+
states.set(metrics, state);
|
|
41
|
+
return metrics;
|
|
42
|
+
}
|
|
43
|
+
async function observeTransactionAcquisition(metrics, acquire, signal) {
|
|
44
|
+
const state = states.get(metrics);
|
|
45
|
+
if (!state)
|
|
46
|
+
throw new TypeError("Transaction acquisition metrics must be created by the framework factory.");
|
|
47
|
+
const started = performance.now();
|
|
48
|
+
state.inflight++;
|
|
49
|
+
let outcome = "acquired";
|
|
50
|
+
try {
|
|
51
|
+
return await acquire();
|
|
52
|
+
} catch (error) {
|
|
53
|
+
outcome = signal?.aborted ? "aborted" : "failed";
|
|
54
|
+
throw error;
|
|
55
|
+
} finally {
|
|
56
|
+
state.inflight--;
|
|
57
|
+
const elapsed = Math.max(0, performance.now() - started) / 1000;
|
|
58
|
+
const histogram = state.outcomes[outcomes.indexOf(outcome)];
|
|
59
|
+
if (histogram) {
|
|
60
|
+
histogram.count++;
|
|
61
|
+
histogram.sumSeconds += elapsed;
|
|
62
|
+
for (let index = 0;index < ACQUISITION_BUCKETS_SECONDS.length; index++) {
|
|
63
|
+
const bound = ACQUISITION_BUCKETS_SECONDS[index];
|
|
64
|
+
if (bound !== undefined && elapsed <= bound)
|
|
65
|
+
histogram.buckets[index] = (histogram.buckets[index] ?? 0) + 1;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function renderTransactionAcquisitionMetrics(snapshot) {
|
|
71
|
+
const invalid = () => new TypeError("Invalid transaction acquisition metrics.");
|
|
72
|
+
if (!Number.isSafeInteger(snapshot.inflight) || snapshot.inflight < 0 || snapshot.outcomes.length !== outcomes.length)
|
|
73
|
+
throw invalid();
|
|
74
|
+
const name = "strata_database_transaction_acquisition_duration_seconds";
|
|
75
|
+
const lines = [
|
|
76
|
+
"# HELP strata_database_acquisition_collector_success Whether transaction acquisition observation succeeded.",
|
|
77
|
+
"# TYPE strata_database_acquisition_collector_success gauge",
|
|
78
|
+
"strata_database_acquisition_collector_success 1",
|
|
79
|
+
"# HELP strata_database_transaction_acquisition_inflight Native transaction checkouts awaiting settlement in this process.",
|
|
80
|
+
"# TYPE strata_database_transaction_acquisition_inflight gauge",
|
|
81
|
+
`strata_database_transaction_acquisition_inflight ${snapshot.inflight}`,
|
|
82
|
+
`# HELP ${name} Native checkout duration, including pool wait and connection establishment, for explicitly observed transactions.`,
|
|
83
|
+
`# TYPE ${name} histogram`
|
|
84
|
+
];
|
|
85
|
+
for (let i = 0;i < outcomes.length; i++) {
|
|
86
|
+
const histogram = snapshot.outcomes[i];
|
|
87
|
+
if (!histogram || histogram.outcome !== outcomes[i] || !Number.isSafeInteger(histogram.count) || histogram.count < 0 || !Number.isFinite(histogram.sumSeconds) || histogram.sumSeconds < 0 || histogram.buckets.length !== ACQUISITION_BUCKETS_SECONDS.length)
|
|
88
|
+
throw invalid();
|
|
89
|
+
let previous = 0;
|
|
90
|
+
for (let index = 0;index < ACQUISITION_BUCKETS_SECONDS.length; index++) {
|
|
91
|
+
const value = histogram.buckets[index];
|
|
92
|
+
if (value === undefined || !Number.isSafeInteger(value) || value < previous || value > histogram.count)
|
|
93
|
+
throw invalid();
|
|
94
|
+
previous = value;
|
|
95
|
+
lines.push(`${name}_bucket{outcome="${histogram.outcome}",le="${ACQUISITION_BUCKETS_SECONDS[index]}"} ${value}`);
|
|
96
|
+
}
|
|
97
|
+
lines.push(`${name}_bucket{outcome="${histogram.outcome}",le="+Inf"} ${histogram.count}`, `${name}_count{outcome="${histogram.outcome}"} ${histogram.count}`, `${name}_sum{outcome="${histogram.outcome}"} ${histogram.sumSeconds}`);
|
|
98
|
+
}
|
|
99
|
+
return `${lines.join(`
|
|
100
|
+
`)}
|
|
101
|
+
`;
|
|
102
|
+
}
|
|
103
|
+
export {
|
|
104
|
+
createTransactionAcquisitionMetrics,
|
|
105
|
+
observeTransactionAcquisition,
|
|
106
|
+
renderTransactionAcquisitionMetrics
|
|
107
|
+
};
|