@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
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// ../../src/core/queue/queueConfig.ts
|
|
3
|
+
var DEFAULT_QUEUE_VISIBILITY_MS = 60000;
|
|
4
|
+
function snapshotQueueRetryPolicy(policy) {
|
|
5
|
+
const { maxAttempts, backoffMs } = policy;
|
|
6
|
+
if (!Number.isSafeInteger(maxAttempts) || maxAttempts < 1)
|
|
7
|
+
throw new TypeError("QUEUE_MAX_ATTEMPTS must be a positive safe integer.");
|
|
8
|
+
if (!Number.isSafeInteger(backoffMs) || backoffMs < 0 || backoffMs > 2147483647)
|
|
9
|
+
throw new TypeError("QUEUE_BACKOFF_MS must be a non-negative integer within the timer range.");
|
|
10
|
+
return Object.freeze({ maxAttempts, backoffMs });
|
|
11
|
+
}
|
|
12
|
+
function resolveQueueConfig(env = process.env) {
|
|
13
|
+
const driver = env.QUEUE_DRIVER ?? "sync";
|
|
14
|
+
if (!["sync", "async", "redis"].includes(driver))
|
|
15
|
+
throw new TypeError("Unknown queue driver.");
|
|
16
|
+
const policy = snapshotQueueRetryPolicy({
|
|
17
|
+
maxAttempts: Number(env.QUEUE_MAX_ATTEMPTS ?? "3"),
|
|
18
|
+
backoffMs: Number(env.QUEUE_BACKOFF_MS ?? "1000")
|
|
19
|
+
});
|
|
20
|
+
return Object.freeze({ driver, ...policy });
|
|
21
|
+
}
|
|
22
|
+
function resolveRedisQueueTransport(env = process.env) {
|
|
23
|
+
const transport = env.QUEUE_REDIS_TRANSPORT ?? "lists";
|
|
24
|
+
if (transport !== "lists" && transport !== "streams")
|
|
25
|
+
throw new Error('QUEUE_REDIS_TRANSPORT must be "lists" or "streams".');
|
|
26
|
+
return transport;
|
|
27
|
+
}
|
|
28
|
+
function readQueueVisibilityMs(env = process.env) {
|
|
29
|
+
const value = Number(env.QUEUE_VISIBILITY_MS ?? "60000");
|
|
30
|
+
if (!Number.isSafeInteger(value) || value < 30 || value > 2147483647)
|
|
31
|
+
throw new Error("QUEUE_VISIBILITY_MS must be an integer from 30 through 2147483647 milliseconds.");
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
function snapshotQueueRuntimeConfig(config) {
|
|
35
|
+
if (config.transport !== "lists" && config.transport !== "streams" || typeof config.visibilityMs !== "number")
|
|
36
|
+
throw new TypeError("Queue runtime requires explicit transport and numeric visibility.");
|
|
37
|
+
if (!Array.isArray(config.queueKeys) || config.queueKeys.length !== 3 || config.queueKeys.some((key) => typeof key !== "string" || !key.length) || new Set(config.queueKeys).size !== 3)
|
|
38
|
+
throw new TypeError("Queue runtime requires three distinct nonempty priority keys.");
|
|
39
|
+
return Object.freeze({
|
|
40
|
+
queueKeys: Object.freeze([...config.queueKeys]),
|
|
41
|
+
transport: resolveRedisQueueTransport({ QUEUE_REDIS_TRANSPORT: config.transport }),
|
|
42
|
+
visibilityMs: readQueueVisibilityMs({ QUEUE_VISIBILITY_MS: String(config.visibilityMs) })
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
function resolveQueueRuntimeConfig(env = process.env) {
|
|
46
|
+
const prefix = env.APP_KEY_PREFIX?.trim() || "strata";
|
|
47
|
+
return snapshotQueueRuntimeConfig({
|
|
48
|
+
transport: resolveRedisQueueTransport(env),
|
|
49
|
+
visibilityMs: readQueueVisibilityMs(env),
|
|
50
|
+
queueKeys: [`${prefix}:queue:high`, `${prefix}:queue:default`, `${prefix}:queue:low`]
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
export {
|
|
54
|
+
DEFAULT_QUEUE_VISIBILITY_MS,
|
|
55
|
+
readQueueVisibilityMs,
|
|
56
|
+
resolveQueueConfig,
|
|
57
|
+
resolveQueueRuntimeConfig,
|
|
58
|
+
resolveRedisQueueTransport,
|
|
59
|
+
snapshotQueueRetryPolicy,
|
|
60
|
+
snapshotQueueRuntimeConfig
|
|
61
|
+
};
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// ../../src/core/queue/queueHandoff.ts
|
|
3
|
+
import { createHash, createHmac, timingSafeEqual } from "crypto";
|
|
4
|
+
|
|
5
|
+
// ../../src/core/config/configSnapshot.ts
|
|
6
|
+
function copyApplicationConfig(value, ancestors = new Set) {
|
|
7
|
+
if (value === null || typeof value === "string" || typeof value === "boolean")
|
|
8
|
+
return value;
|
|
9
|
+
if (typeof value === "number" && Number.isFinite(value))
|
|
10
|
+
return value;
|
|
11
|
+
if (typeof value !== "object" || ancestors.has(value)) {
|
|
12
|
+
throw new TypeError("Application config must contain acyclic plain data.");
|
|
13
|
+
}
|
|
14
|
+
const array = Array.isArray(value);
|
|
15
|
+
const prototype = Object.getPrototypeOf(value);
|
|
16
|
+
if (prototype !== (array ? Array.prototype : Object.prototype) && !(prototype === null && !array)) {
|
|
17
|
+
throw new TypeError("Application config must contain only plain objects and arrays.");
|
|
18
|
+
}
|
|
19
|
+
if (Object.getOwnPropertySymbols(value).length > 0) {
|
|
20
|
+
throw new TypeError("Application config cannot contain symbol keys.");
|
|
21
|
+
}
|
|
22
|
+
const descriptors = Object.getOwnPropertyDescriptors(value);
|
|
23
|
+
for (const [key, descriptor] of Object.entries(descriptors)) {
|
|
24
|
+
if (!(array && key === "length") && (!descriptor.enumerable || !("value" in descriptor))) {
|
|
25
|
+
throw new TypeError("Application config cannot contain accessors or hidden properties.");
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
ancestors.add(value);
|
|
29
|
+
try {
|
|
30
|
+
if (array) {
|
|
31
|
+
const length = descriptors.length.value;
|
|
32
|
+
if (Object.keys(descriptors).length !== length + 1) {
|
|
33
|
+
throw new TypeError("Application config arrays must be dense and have no extra properties.");
|
|
34
|
+
}
|
|
35
|
+
const result = [];
|
|
36
|
+
for (let index = 0;index < length; index++) {
|
|
37
|
+
const descriptor = descriptors[String(index)];
|
|
38
|
+
if (!descriptor)
|
|
39
|
+
throw new TypeError("Application config arrays must be dense.");
|
|
40
|
+
result.push(copyApplicationConfig(descriptor.value, ancestors));
|
|
41
|
+
}
|
|
42
|
+
return Object.freeze(result);
|
|
43
|
+
}
|
|
44
|
+
const result = {};
|
|
45
|
+
for (const [key, descriptor] of Object.entries(descriptors)) {
|
|
46
|
+
Object.defineProperty(result, key, {
|
|
47
|
+
value: copyApplicationConfig(descriptor.value, ancestors),
|
|
48
|
+
enumerable: true
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return Object.freeze(result);
|
|
52
|
+
} finally {
|
|
53
|
+
ancestors.delete(value);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// ../../src/core/runtime/executionContext.ts
|
|
58
|
+
function signalAccessor(name) {
|
|
59
|
+
const getter = Object.getOwnPropertyDescriptor(AbortSignal.prototype, name)?.get;
|
|
60
|
+
if (!getter)
|
|
61
|
+
throw new TypeError("Platform AbortSignal accessors are required.");
|
|
62
|
+
return getter;
|
|
63
|
+
}
|
|
64
|
+
var signalAborted = signalAccessor("aborted");
|
|
65
|
+
var signalReason = signalAccessor("reason");
|
|
66
|
+
var addListener = EventTarget.prototype.addEventListener;
|
|
67
|
+
var removeListener = EventTarget.prototype.removeEventListener;
|
|
68
|
+
function aborted(signal) {
|
|
69
|
+
return signalAborted.call(signal);
|
|
70
|
+
}
|
|
71
|
+
function reason(signal) {
|
|
72
|
+
return signalReason.call(signal);
|
|
73
|
+
}
|
|
74
|
+
function record(input, keys) {
|
|
75
|
+
if (input === null || typeof input !== "object" || Array.isArray(input)) {
|
|
76
|
+
throw new TypeError("Execution data must be a plain record.");
|
|
77
|
+
}
|
|
78
|
+
const prototype = Object.getPrototypeOf(input);
|
|
79
|
+
if (prototype !== Object.prototype && prototype !== null) {
|
|
80
|
+
throw new TypeError("Execution data must be a plain record.");
|
|
81
|
+
}
|
|
82
|
+
const result = Object.create(null);
|
|
83
|
+
for (const key of Reflect.ownKeys(input)) {
|
|
84
|
+
if (typeof key !== "string" || !keys.includes(key)) {
|
|
85
|
+
throw new TypeError("Unknown execution data field.");
|
|
86
|
+
}
|
|
87
|
+
const descriptor = Object.getOwnPropertyDescriptor(input, key);
|
|
88
|
+
if (!descriptor || !("value" in descriptor) || !descriptor.enumerable) {
|
|
89
|
+
throw new TypeError("Execution data must contain enumerable own data fields.");
|
|
90
|
+
}
|
|
91
|
+
result[key] = descriptor.value;
|
|
92
|
+
}
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
function metadata(value) {
|
|
96
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
97
|
+
throw new TypeError("Execution metadata must be a plain record.");
|
|
98
|
+
}
|
|
99
|
+
return copyApplicationConfig(value);
|
|
100
|
+
}
|
|
101
|
+
function nonempty(value) {
|
|
102
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
103
|
+
throw new TypeError("Execution identifiers and policies must be nonempty strings.");
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function actor(input) {
|
|
107
|
+
const value = record(input, ["kind", "claims", "policy"]);
|
|
108
|
+
if (value.kind === "principal" && !("policy" in value)) {
|
|
109
|
+
return Object.freeze({ kind: "principal", claims: metadata(value.claims) });
|
|
110
|
+
}
|
|
111
|
+
if (value.kind === "system" && !("claims" in value)) {
|
|
112
|
+
nonempty(value.policy);
|
|
113
|
+
return Object.freeze({ kind: "system", policy: value.policy });
|
|
114
|
+
}
|
|
115
|
+
throw new TypeError("Invalid execution actor.");
|
|
116
|
+
}
|
|
117
|
+
function normalizeExecutionEnvelope(input) {
|
|
118
|
+
const value = record(input, [
|
|
119
|
+
"kind",
|
|
120
|
+
"actor",
|
|
121
|
+
"externalId",
|
|
122
|
+
"metadata",
|
|
123
|
+
"tenant",
|
|
124
|
+
"signal",
|
|
125
|
+
"deadlineAtMs"
|
|
126
|
+
]);
|
|
127
|
+
if (value.kind !== "command" && value.kind !== "request" && value.kind !== "job") {
|
|
128
|
+
throw new TypeError("Invalid execution kind.");
|
|
129
|
+
}
|
|
130
|
+
const result = { kind: value.kind };
|
|
131
|
+
if (value.actor !== undefined)
|
|
132
|
+
result.actor = actor(value.actor);
|
|
133
|
+
else if (value.kind === "job")
|
|
134
|
+
throw new TypeError("Job executions require an actor.");
|
|
135
|
+
if (value.externalId !== undefined) {
|
|
136
|
+
nonempty(value.externalId);
|
|
137
|
+
result.externalId = value.externalId;
|
|
138
|
+
}
|
|
139
|
+
result.metadata = metadata(value.metadata === undefined ? {} : value.metadata);
|
|
140
|
+
if (value.tenant !== undefined)
|
|
141
|
+
result.tenant = metadata(value.tenant);
|
|
142
|
+
if (value.signal !== undefined) {
|
|
143
|
+
aborted(value.signal);
|
|
144
|
+
reason(value.signal);
|
|
145
|
+
result.signal = value.signal;
|
|
146
|
+
}
|
|
147
|
+
if (value.deadlineAtMs !== undefined) {
|
|
148
|
+
if (typeof value.deadlineAtMs !== "number")
|
|
149
|
+
throw new TypeError("Invalid execution deadline.");
|
|
150
|
+
if (!Number.isSafeInteger(value.deadlineAtMs) || value.deadlineAtMs < 0) {
|
|
151
|
+
throw new RangeError("Execution deadline must be a nonnegative safe integer.");
|
|
152
|
+
}
|
|
153
|
+
result.deadlineAtMs = value.deadlineAtMs;
|
|
154
|
+
}
|
|
155
|
+
return Object.freeze(result);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
class ExecutionDeadlineError extends Error {
|
|
159
|
+
applicationId;
|
|
160
|
+
executionId;
|
|
161
|
+
code = "EXECUTION_DEADLINE";
|
|
162
|
+
constructor(applicationId, executionId) {
|
|
163
|
+
super("EXECUTION_DEADLINE");
|
|
164
|
+
this.applicationId = applicationId;
|
|
165
|
+
this.executionId = executionId;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
function ownExecutionContext(envelope, applicationId, appSignal) {
|
|
169
|
+
const executionId = crypto.randomUUID();
|
|
170
|
+
const controller = new AbortController;
|
|
171
|
+
const subscriptions = [];
|
|
172
|
+
let timer;
|
|
173
|
+
let disposed = false;
|
|
174
|
+
const cancel = (signal) => {
|
|
175
|
+
if (!disposed && aborted(signal) && !controller.signal.aborted)
|
|
176
|
+
controller.abort(reason(signal));
|
|
177
|
+
};
|
|
178
|
+
const subscribe = (signal) => {
|
|
179
|
+
const listener = () => cancel(signal);
|
|
180
|
+
addListener.call(signal, "abort", listener);
|
|
181
|
+
subscriptions.push({ signal, listener });
|
|
182
|
+
cancel(signal);
|
|
183
|
+
};
|
|
184
|
+
const dispose = () => {
|
|
185
|
+
disposed = true;
|
|
186
|
+
clearTimeout(timer);
|
|
187
|
+
for (const { signal, listener } of subscriptions) {
|
|
188
|
+
removeListener.call(signal, "abort", listener);
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
try {
|
|
192
|
+
if (envelope.signal !== undefined)
|
|
193
|
+
subscribe(envelope.signal);
|
|
194
|
+
subscribe(appSignal);
|
|
195
|
+
const deadline = envelope.deadlineAtMs;
|
|
196
|
+
const refreshDeadline = () => {
|
|
197
|
+
if (disposed || controller.signal.aborted || deadline === undefined)
|
|
198
|
+
return;
|
|
199
|
+
const remaining = deadline - Date.now();
|
|
200
|
+
if (remaining <= 0) {
|
|
201
|
+
controller.abort(new ExecutionDeadlineError(applicationId, executionId));
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
return remaining;
|
|
205
|
+
};
|
|
206
|
+
const check = () => {
|
|
207
|
+
refreshDeadline();
|
|
208
|
+
if (controller.signal.aborted)
|
|
209
|
+
throw controller.signal.reason;
|
|
210
|
+
};
|
|
211
|
+
if (deadline !== undefined) {
|
|
212
|
+
const tick = () => {
|
|
213
|
+
const remaining = refreshDeadline();
|
|
214
|
+
if (remaining !== undefined)
|
|
215
|
+
timer = setTimeout(tick, Math.min(remaining, 2147483647));
|
|
216
|
+
};
|
|
217
|
+
tick();
|
|
218
|
+
}
|
|
219
|
+
const context = Object.freeze({
|
|
220
|
+
...envelope,
|
|
221
|
+
applicationId,
|
|
222
|
+
executionId,
|
|
223
|
+
signal: controller.signal
|
|
224
|
+
});
|
|
225
|
+
return { context, dispose, check };
|
|
226
|
+
} catch (error) {
|
|
227
|
+
dispose();
|
|
228
|
+
throw error;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// ../../src/core/queue/queueHandoff.ts
|
|
233
|
+
class QueueHandoffError extends TypeError {
|
|
234
|
+
code = "QUEUE_HANDOFF_INVALID";
|
|
235
|
+
constructor() {
|
|
236
|
+
super("Queue handoff is invalid for this job/application.");
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
var MAX_HANDOFF_BYTES = 32768;
|
|
240
|
+
function payloadHash(payload) {
|
|
241
|
+
return createHash("sha256").update(JSON.stringify(copyApplicationConfig(payload), (_key, value) => value && typeof value === "object" && !Array.isArray(value) ? Object.fromEntries(Object.keys(value).sort().map((key) => [key, value[key]])) : value)).digest("hex");
|
|
242
|
+
}
|
|
243
|
+
function snapshotIdentity(identity) {
|
|
244
|
+
const data = copyApplicationConfig(identity);
|
|
245
|
+
if (!data || typeof data !== "object" || Array.isArray(data) || Object.keys(data).some((field) => field !== "actor" && field !== "tenant"))
|
|
246
|
+
throw new TypeError("Queue identity must contain only actor and tenant data.");
|
|
247
|
+
const envelope = normalizeExecutionEnvelope({ kind: "job", ...data });
|
|
248
|
+
if (envelope.kind !== "job")
|
|
249
|
+
throw new TypeError("Job identity is required.");
|
|
250
|
+
return Object.freeze({
|
|
251
|
+
actor: envelope.actor,
|
|
252
|
+
...envelope.tenant ? { tenant: envelope.tenant } : {}
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
function createQueueHandoff(options) {
|
|
256
|
+
if (!(options.key instanceof Uint8Array) || options.key.byteLength < 32)
|
|
257
|
+
throw new TypeError("Queue handoff requires at least 32 key bytes.");
|
|
258
|
+
if (typeof options.audience !== "string" || !options.audience.trim() || options.audience.length > 256)
|
|
259
|
+
throw new TypeError("Queue handoff requires a bounded application audience.");
|
|
260
|
+
const key = Buffer.from(options.key);
|
|
261
|
+
const audience = options.audience;
|
|
262
|
+
const sign = (body) => createHmac("sha256", key).update(body).digest();
|
|
263
|
+
return Object.freeze({
|
|
264
|
+
seal(name, payload, identity) {
|
|
265
|
+
if (typeof name !== "string" || !name || name.length > 256)
|
|
266
|
+
throw new TypeError("Invalid handoff job name.");
|
|
267
|
+
const body = Buffer.from(JSON.stringify({
|
|
268
|
+
version: 1,
|
|
269
|
+
audience,
|
|
270
|
+
name,
|
|
271
|
+
payloadHash: payloadHash(payload),
|
|
272
|
+
identity: snapshotIdentity(identity)
|
|
273
|
+
})).toString("base64url");
|
|
274
|
+
const token = `${body}.${sign(body).toString("base64url")}`;
|
|
275
|
+
if (token.length > MAX_HANDOFF_BYTES)
|
|
276
|
+
throw new TypeError("Queue handoff is too large.");
|
|
277
|
+
return token;
|
|
278
|
+
},
|
|
279
|
+
verify(job) {
|
|
280
|
+
try {
|
|
281
|
+
const token = job.handoff;
|
|
282
|
+
if (typeof token !== "string" || token.length > MAX_HANDOFF_BYTES)
|
|
283
|
+
throw new TypeError("Invalid queue handoff.");
|
|
284
|
+
const pieces = token.split(".");
|
|
285
|
+
if (pieces.length !== 2 || !pieces.every((piece) => /^[A-Za-z0-9_-]+$/.test(piece)))
|
|
286
|
+
throw new TypeError("Malformed queue handoff.");
|
|
287
|
+
const body = pieces[0];
|
|
288
|
+
const signature = Buffer.from(pieces[1], "base64url");
|
|
289
|
+
const expected = sign(body);
|
|
290
|
+
if (signature.length !== expected.length || !timingSafeEqual(signature, expected))
|
|
291
|
+
throw new TypeError("Untrusted queue handoff.");
|
|
292
|
+
const decoded = JSON.parse(Buffer.from(body, "base64url").toString("utf8"));
|
|
293
|
+
if (!decoded || typeof decoded !== "object" || Array.isArray(decoded) || Object.keys(decoded).sort().join(",") !== "audience,identity,name,payloadHash,version" || decoded.version !== 1 || decoded.audience !== audience || decoded.name !== job.name || decoded.payloadHash !== payloadHash(job.payload))
|
|
294
|
+
throw new TypeError("Queue handoff does not match this job/application.");
|
|
295
|
+
return snapshotIdentity(decoded.identity);
|
|
296
|
+
} catch {
|
|
297
|
+
throw new QueueHandoffError;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
function createIdentityQueue(queue, registry, handoff, identity) {
|
|
303
|
+
const captured = snapshotIdentity(identity);
|
|
304
|
+
return Object.freeze({
|
|
305
|
+
async dispatch(job, payload) {
|
|
306
|
+
const name = registry.resolveName(job);
|
|
307
|
+
if (!name)
|
|
308
|
+
throw new Error("Job is not registered with the queue worker registry.");
|
|
309
|
+
const snapshot = copyApplicationConfig(payload);
|
|
310
|
+
await queue.dispatch(job, snapshot, { handoff: handoff.seal(name, snapshot, captured) });
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
export {
|
|
315
|
+
QueueHandoffError,
|
|
316
|
+
createIdentityQueue,
|
|
317
|
+
createQueueHandoff
|
|
318
|
+
};
|