@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
|
@@ -1,57 +1,16 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
// ../../src/core/queue/jobRegistry.ts
|
|
3
|
-
class JobRegistry {
|
|
4
|
-
factories = new Map;
|
|
5
|
-
instances = new WeakMap;
|
|
6
|
-
register(name, factory) {
|
|
7
|
-
this.factories.set(name, factory);
|
|
8
|
-
}
|
|
9
|
-
resolveName(job) {
|
|
10
|
-
return this.instances.get(job);
|
|
11
|
-
}
|
|
12
|
-
track(name, job) {
|
|
13
|
-
this.instances.set(job, name);
|
|
14
|
-
return job;
|
|
15
|
-
}
|
|
16
|
-
create(name) {
|
|
17
|
-
const factory = this.factories.get(name);
|
|
18
|
-
if (!factory) {
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
return factory();
|
|
22
|
-
}
|
|
23
|
-
names() {
|
|
24
|
-
return [...this.factories.keys()];
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
var JOB_REGISTRY_KEY = Symbol.for("@getstrata/jobRegistry");
|
|
28
|
-
function readSharedJobRegistry() {
|
|
29
|
-
const globalRegistry = globalThis[JOB_REGISTRY_KEY];
|
|
30
|
-
if (globalRegistry) {
|
|
31
|
-
return globalRegistry;
|
|
32
|
-
}
|
|
33
|
-
const registry = new JobRegistry;
|
|
34
|
-
globalThis[JOB_REGISTRY_KEY] = registry;
|
|
35
|
-
return registry;
|
|
36
|
-
}
|
|
37
|
-
var jobRegistry = readSharedJobRegistry();
|
|
38
|
-
|
|
39
2
|
// ../../src/core/queue/index.ts
|
|
40
3
|
class Job {
|
|
41
4
|
static jobName;
|
|
42
5
|
maxAttempts;
|
|
43
6
|
backoffMs;
|
|
44
7
|
priority;
|
|
45
|
-
constructor() {
|
|
46
|
-
const jobName = this.constructor.jobName;
|
|
47
|
-
if (jobName) {
|
|
48
|
-
jobRegistry.track(jobName, this);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
8
|
}
|
|
52
9
|
|
|
53
10
|
class SyncQueue {
|
|
54
|
-
async dispatch(job, payload) {
|
|
11
|
+
async dispatch(job, payload, options) {
|
|
12
|
+
if (options?.handoff !== undefined)
|
|
13
|
+
throw new Error("Identity handoff requires an application queue.");
|
|
55
14
|
await job.handle(payload);
|
|
56
15
|
}
|
|
57
16
|
}
|
|
@@ -76,7 +35,9 @@ class AsyncQueue {
|
|
|
76
35
|
this.active.delete(running);
|
|
77
36
|
});
|
|
78
37
|
}
|
|
79
|
-
async dispatch(job, payload) {
|
|
38
|
+
async dispatch(job, payload, options) {
|
|
39
|
+
if (options?.handoff !== undefined)
|
|
40
|
+
throw new Error("Identity handoff requires an application queue.");
|
|
80
41
|
this.enqueue(() => job.handle(payload), (error) => {
|
|
81
42
|
console.error("[AsyncQueue] Job failed:", error);
|
|
82
43
|
});
|
|
@@ -97,12 +58,16 @@ function createQueue(driver) {
|
|
|
97
58
|
// ../../src/core/jobs/invalidateCacheTagsJob.ts
|
|
98
59
|
class InvalidateCacheTagsJob extends Job {
|
|
99
60
|
cache;
|
|
61
|
+
static jobName = "cache.invalidate-tags";
|
|
100
62
|
constructor(cache) {
|
|
101
63
|
super();
|
|
102
64
|
this.cache = cache;
|
|
103
65
|
}
|
|
104
|
-
async handle(payload) {
|
|
105
|
-
|
|
66
|
+
async handle(payload, context) {
|
|
67
|
+
const cache = this.cache ?? context?.cache;
|
|
68
|
+
if (!cache)
|
|
69
|
+
throw new Error("Cache invalidation requires an explicit invocation cache.");
|
|
70
|
+
await cache.tags(...payload.tags).flush();
|
|
106
71
|
}
|
|
107
72
|
}
|
|
108
73
|
var invalidateCacheTagsJob_default = InvalidateCacheTagsJob;
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
|
|
9
9
|
// ../../src/core/http/clientIp.ts
|
|
10
10
|
import { currentRequestMeta } from "@getstrata/core/http/requestMetaContext";
|
|
11
|
-
function trustForwardedFor(env =
|
|
11
|
+
function trustForwardedFor(env = {}) {
|
|
12
12
|
return (env.TRUST_FORWARDED_FOR ?? "false") === "true";
|
|
13
13
|
}
|
|
14
14
|
function isPrivateAddress(address) {
|
|
@@ -28,7 +28,7 @@ function forwardedClientIp(request) {
|
|
|
28
28
|
}
|
|
29
29
|
return request.headers.get("x-real-ip")?.trim() || undefined;
|
|
30
30
|
}
|
|
31
|
-
function readClientIp(request, env =
|
|
31
|
+
function readClientIp(request, env = {}) {
|
|
32
32
|
if (trustForwardedFor(env)) {
|
|
33
33
|
const forwarded = forwardedClientIp(request);
|
|
34
34
|
if (forwarded) {
|
|
@@ -75,9 +75,9 @@ class Logger {
|
|
|
75
75
|
var appLogger = new Logger("app");
|
|
76
76
|
|
|
77
77
|
// ../../src/core/logging/requestLoggingMiddleware.ts
|
|
78
|
-
function createRequestLoggingMiddleware() {
|
|
78
|
+
function createRequestLoggingMiddleware(trustForwardedFor = false) {
|
|
79
79
|
return async (request, next) => {
|
|
80
|
-
const ipAddress = readClientIp(request) ?? null;
|
|
80
|
+
const ipAddress = readClientIp(request, { TRUST_FORWARDED_FOR: String(trustForwardedFor) }) ?? null;
|
|
81
81
|
const requestId = resolveRequestId(request);
|
|
82
82
|
return await runWithRequestMeta({
|
|
83
83
|
...currentRequestMeta2(),
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
// @bun
|
|
2
|
+
// ../../src/core/mail/mailer.ts
|
|
3
|
+
import { CORE_MAIL_TOKEN } from "@getstrata/core/contracts/serviceTokens";
|
|
4
|
+
|
|
2
5
|
// ../../src/core/runtime/appEnv.ts
|
|
3
6
|
var NON_PRODUCTION_APP_ENVS = new Set(["local", "development", "dev", "test", "testing", "ci"]);
|
|
4
7
|
function normalizeEnvValue(value) {
|
|
@@ -20,14 +23,14 @@ function envFlagEnabled(value) {
|
|
|
20
23
|
}
|
|
21
24
|
|
|
22
25
|
// ../../src/core/runtime/appKeyPrefix.ts
|
|
23
|
-
function appKeyPrefix() {
|
|
24
|
-
return
|
|
26
|
+
function appKeyPrefix(env = process.env) {
|
|
27
|
+
return env.APP_KEY_PREFIX?.trim() || "strata";
|
|
25
28
|
}
|
|
26
|
-
function appCookieName(kind) {
|
|
27
|
-
return `${appKeyPrefix()}_${kind}`;
|
|
29
|
+
function appCookieName(kind, env = process.env) {
|
|
30
|
+
return `${appKeyPrefix(env)}_${kind}`;
|
|
28
31
|
}
|
|
29
|
-
function appDevSecret(kind) {
|
|
30
|
-
return `${appKeyPrefix()}-dev-${kind}`;
|
|
32
|
+
function appDevSecret(kind, env = process.env) {
|
|
33
|
+
return `${appKeyPrefix(env)}-dev-${kind}`;
|
|
31
34
|
}
|
|
32
35
|
function requireConfiguredSecret(names, devKind, env = process.env) {
|
|
33
36
|
for (const name of names) {
|
|
@@ -39,50 +42,18 @@ function requireConfiguredSecret(names, devKind, env = process.env) {
|
|
|
39
42
|
if (isProductionEnv(env)) {
|
|
40
43
|
throw new Error(`${names[0]} must be set outside development. Do not derive secrets from the app name.`);
|
|
41
44
|
}
|
|
42
|
-
return appDevSecret(devKind);
|
|
45
|
+
return appDevSecret(devKind, env);
|
|
43
46
|
}
|
|
44
47
|
function namespacedRedisKey(kind) {
|
|
45
48
|
return `${appKeyPrefix()}:${kind}`;
|
|
46
49
|
}
|
|
47
|
-
function smtpEhloHost() {
|
|
48
|
-
const raw =
|
|
50
|
+
function smtpEhloHost(env = process.env) {
|
|
51
|
+
const raw = env.MAIL_EHLO?.trim() || `${appKeyPrefix(env)}.local`;
|
|
49
52
|
const safe = raw.replace(/[^a-zA-Z0-9.-]/g, "");
|
|
50
53
|
return safe || "strata.local";
|
|
51
54
|
}
|
|
52
|
-
function
|
|
53
|
-
return
|
|
54
|
-
}
|
|
55
|
-
function appUserAgent() {
|
|
56
|
-
return process.env.APP_USER_AGENT?.trim() || appKeyPrefix();
|
|
57
|
-
}
|
|
58
|
-
function otelServiceName() {
|
|
59
|
-
return process.env.OTEL_SERVICE_NAME?.trim() || `${appKeyPrefix()}-api`;
|
|
60
|
-
}
|
|
61
|
-
function webhookSignatureHeader() {
|
|
62
|
-
return process.env.WEBHOOK_SIGNATURE_HEADER?.trim() || `x-${appKeyPrefix()}-signature`;
|
|
63
|
-
}
|
|
64
|
-
function appDisplayName() {
|
|
65
|
-
return process.env.APP_NAME?.trim() || "Strata";
|
|
66
|
-
}
|
|
67
|
-
function appEnv() {
|
|
68
|
-
return process.env.APP_ENV?.trim() || "local";
|
|
69
|
-
}
|
|
70
|
-
function appUrl() {
|
|
71
|
-
return (process.env.APP_URL?.trim() || "http://localhost:3000").replace(/\/$/, "");
|
|
72
|
-
}
|
|
73
|
-
function apiPrefix() {
|
|
74
|
-
const raw = process.env.API_PREFIX?.trim() || "/api/v1";
|
|
75
|
-
const withSlash = raw.startsWith("/") ? raw : `/${raw}`;
|
|
76
|
-
const trimmed = withSlash.replace(/\/+$/, "");
|
|
77
|
-
return trimmed || "/api/v1";
|
|
78
|
-
}
|
|
79
|
-
function sdkClientClassName() {
|
|
80
|
-
const override = process.env.APP_SDK_CLASS?.trim();
|
|
81
|
-
if (override && /^[A-Za-z_][A-Za-z0-9_]*$/.test(override)) {
|
|
82
|
-
return override;
|
|
83
|
-
}
|
|
84
|
-
const fromName = appDisplayName().replace(/[^A-Za-z0-9]/g, "");
|
|
85
|
-
return fromName ? `${fromName}Client` : "AppClient";
|
|
55
|
+
function otelServiceName(env = process.env) {
|
|
56
|
+
return env.OTEL_SERVICE_NAME?.trim() || `${appKeyPrefix(env)}-api`;
|
|
86
57
|
}
|
|
87
58
|
|
|
88
59
|
// ../../src/core/mail/smtpMessage.ts
|
|
@@ -190,28 +161,58 @@ function buildSmtpPayload(from, message) {
|
|
|
190
161
|
}
|
|
191
162
|
|
|
192
163
|
// ../../src/core/mail/mailer.ts
|
|
193
|
-
function resolveSmtpConfig() {
|
|
194
|
-
const
|
|
164
|
+
function resolveSmtpConfig(environment) {
|
|
165
|
+
const env = environment ?? process.env;
|
|
166
|
+
const host = env.MAIL_HOST?.trim();
|
|
195
167
|
if (!host) {
|
|
196
168
|
throw new Error('MAIL_DRIVER="smtp" requires MAIL_HOST to be set.');
|
|
197
169
|
}
|
|
198
|
-
const from =
|
|
170
|
+
const from = env.MAIL_FROM?.trim();
|
|
199
171
|
if (!from) {
|
|
200
172
|
throw new Error('MAIL_DRIVER="smtp" requires MAIL_FROM to be set.');
|
|
201
173
|
}
|
|
202
|
-
|
|
174
|
+
if (env.MAIL_SECURE !== undefined && !["true", "false"].includes(env.MAIL_SECURE))
|
|
175
|
+
throw new TypeError("MAIL_SECURE must be true or false.");
|
|
176
|
+
const port = Number(env.MAIL_PORT ?? "587");
|
|
203
177
|
if (!Number.isInteger(port) || port <= 0 || port > 65535) {
|
|
204
178
|
throw new Error('Environment variable "MAIL_PORT" must be a positive integer.');
|
|
205
179
|
}
|
|
206
|
-
return {
|
|
180
|
+
return snapshotSmtpConfig({
|
|
207
181
|
host,
|
|
182
|
+
ehloHost: smtpEhloHost(env),
|
|
208
183
|
port,
|
|
209
184
|
from,
|
|
210
|
-
secure: (
|
|
211
|
-
...
|
|
212
|
-
...
|
|
213
|
-
...
|
|
214
|
-
};
|
|
185
|
+
secure: (env.MAIL_SECURE ?? "false") === "true",
|
|
186
|
+
...env.MAIL_TIMEOUT_MS !== undefined ? { timeoutMs: smtpTimeout(Number(env.MAIL_TIMEOUT_MS)) } : {},
|
|
187
|
+
...env.MAIL_USERNAME?.trim() ? { username: env.MAIL_USERNAME.trim() } : {},
|
|
188
|
+
...env.MAIL_PASSWORD?.trim() ? { password: env.MAIL_PASSWORD.trim() } : {}
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
function snapshotSmtpConfig(config) {
|
|
192
|
+
if (typeof config.host !== "string" || !config.host.trim() || /[\r\n\0]/.test(config.host) || !Number.isInteger(config.port) || config.port < 1 || config.port > 65535)
|
|
193
|
+
throw new RangeError("SMTP requires a host and a port between 1 and 65535.");
|
|
194
|
+
if (typeof config.secure !== "boolean")
|
|
195
|
+
throw new TypeError("SMTP secure must be a boolean.");
|
|
196
|
+
if (Boolean(config.username) !== Boolean(config.password))
|
|
197
|
+
throw new Error("SMTP authentication requires both username and password.");
|
|
198
|
+
if (config.username)
|
|
199
|
+
assertSafeSmtpField(config.username, "username");
|
|
200
|
+
if (config.password)
|
|
201
|
+
assertSafeSmtpField(config.password, "password");
|
|
202
|
+
assertSafeSmtpAddress(config.from, "from");
|
|
203
|
+
const tls = config.tls === undefined ? undefined : Object.freeze(structuredClone(config.tls));
|
|
204
|
+
if (tls && Array.isArray(tls.ca))
|
|
205
|
+
Object.freeze(tls.ca);
|
|
206
|
+
return Object.freeze({
|
|
207
|
+
host: config.host,
|
|
208
|
+
port: config.port,
|
|
209
|
+
from: config.from,
|
|
210
|
+
secure: config.secure,
|
|
211
|
+
timeoutMs: smtpTimeout(config.timeoutMs),
|
|
212
|
+
ehloHost: (config.ehloHost ?? "strata.local").replace(/[^a-zA-Z0-9.-]/g, "") || "strata.local",
|
|
213
|
+
...config.username ? { username: config.username, password: config.password } : {},
|
|
214
|
+
...tls ? { tls } : {}
|
|
215
|
+
});
|
|
215
216
|
}
|
|
216
217
|
function redactMailBody(body) {
|
|
217
218
|
return body.replace(/https?:\/\/[^\s]+/giu, "[redacted-url]").replace(/[?&](token|signature|expires|code)=[^&\s]+/giu, "[redacted-query]");
|
|
@@ -223,17 +224,9 @@ function smtpTimeout(value = 1e4) {
|
|
|
223
224
|
return value;
|
|
224
225
|
}
|
|
225
226
|
async function defaultSmtpTransport(config, message) {
|
|
227
|
+
config = snapshotSmtpConfig(config);
|
|
226
228
|
const timeoutMs = smtpTimeout(config.timeoutMs);
|
|
227
|
-
|
|
228
|
-
throw new RangeError("SMTP requires a host and a port between 1 and 65535.");
|
|
229
|
-
}
|
|
230
|
-
if (Boolean(config.username) !== Boolean(config.password)) {
|
|
231
|
-
throw new Error("SMTP authentication requires both username and password.");
|
|
232
|
-
}
|
|
233
|
-
if (config.username)
|
|
234
|
-
assertSafeSmtpField(config.username, "username");
|
|
235
|
-
if (config.password)
|
|
236
|
-
assertSafeSmtpField(config.password, "password");
|
|
229
|
+
const ehloHost = config.ehloHost === undefined ? "strata.local" : config.ehloHost.replace(/[^a-zA-Z0-9.-]/g, "") || "strata.local";
|
|
237
230
|
const fromHeader = assertSafeSmtpAddress(config.from, "from");
|
|
238
231
|
const toHeader = assertSafeSmtpAddress(message.to, "to");
|
|
239
232
|
assertSafeSmtpField(message.subject, "subject");
|
|
@@ -404,7 +397,7 @@ async function defaultSmtpTransport(config, message) {
|
|
|
404
397
|
}, () => {});
|
|
405
398
|
socket = await Promise.race([connecting, failurePromise]);
|
|
406
399
|
await readResponse(["220"]);
|
|
407
|
-
await write(`EHLO ${
|
|
400
|
+
await write(`EHLO ${ehloHost}\r
|
|
408
401
|
`);
|
|
409
402
|
await readResponse(["250"]);
|
|
410
403
|
if (config.username && config.password) {
|
|
@@ -459,14 +452,14 @@ class LogMailDriver {
|
|
|
459
452
|
}
|
|
460
453
|
|
|
461
454
|
class SmtpMailDriver {
|
|
462
|
-
config;
|
|
463
455
|
transport;
|
|
456
|
+
config;
|
|
464
457
|
constructor(config, transport = defaultSmtpTransport) {
|
|
465
|
-
this.config = config;
|
|
466
458
|
this.transport = transport;
|
|
459
|
+
this.config = snapshotSmtpConfig(config);
|
|
467
460
|
}
|
|
468
461
|
send(message) {
|
|
469
|
-
return this.transport(this.config, message);
|
|
462
|
+
return this.transport(snapshotSmtpConfig(this.config), message);
|
|
470
463
|
}
|
|
471
464
|
}
|
|
472
465
|
|
|
@@ -481,20 +474,17 @@ class Mailer {
|
|
|
481
474
|
return this.driver.send(message);
|
|
482
475
|
}
|
|
483
476
|
}
|
|
484
|
-
function createMailDriver() {
|
|
485
|
-
const driver =
|
|
477
|
+
function createMailDriver(env = process.env) {
|
|
478
|
+
const driver = env.MAIL_DRIVER ?? "log";
|
|
486
479
|
if (driver === "smtp") {
|
|
487
|
-
return new SmtpMailDriver(resolveSmtpConfig());
|
|
480
|
+
return new SmtpMailDriver(resolveSmtpConfig(env));
|
|
488
481
|
}
|
|
482
|
+
if (driver !== "log")
|
|
483
|
+
throw new TypeError("Unknown mail driver.");
|
|
489
484
|
return new LogMailDriver;
|
|
490
485
|
}
|
|
491
|
-
var appMailer;
|
|
492
|
-
function mailer() {
|
|
493
|
-
if (!appMailer)
|
|
494
|
-
appMailer = new Mailer(createMailDriver());
|
|
495
|
-
return appMailer;
|
|
496
|
-
}
|
|
497
486
|
export {
|
|
487
|
+
CORE_MAIL_TOKEN,
|
|
498
488
|
LogMailDriver,
|
|
499
489
|
Mailer,
|
|
500
490
|
SmtpMailDriver,
|
|
@@ -503,8 +493,8 @@ export {
|
|
|
503
493
|
buildSmtpPayload,
|
|
504
494
|
createMailDriver,
|
|
505
495
|
defaultSmtpTransport,
|
|
506
|
-
mailer,
|
|
507
496
|
redactMailBody,
|
|
508
497
|
resolveSmtpConfig,
|
|
509
|
-
smtpEnvelopeAddress
|
|
498
|
+
smtpEnvelopeAddress,
|
|
499
|
+
snapshotSmtpConfig
|
|
510
500
|
};
|
|
@@ -1,91 +1,19 @@
|
|
|
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
|
-
// ../../src/core/runtime/appKeyPrefix.ts
|
|
23
|
-
function appKeyPrefix() {
|
|
24
|
-
return process.env.APP_KEY_PREFIX?.trim() || "strata";
|
|
25
|
-
}
|
|
26
|
-
function appCookieName(kind) {
|
|
27
|
-
return `${appKeyPrefix()}_${kind}`;
|
|
28
|
-
}
|
|
29
|
-
function appDevSecret(kind) {
|
|
30
|
-
return `${appKeyPrefix()}-dev-${kind}`;
|
|
31
|
-
}
|
|
32
|
-
function requireConfiguredSecret(names, devKind, env = process.env) {
|
|
33
|
-
for (const name of names) {
|
|
34
|
-
const value = env[name]?.trim();
|
|
35
|
-
if (value) {
|
|
36
|
-
return value;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
if (isProductionEnv(env)) {
|
|
40
|
-
throw new Error(`${names[0]} must be set outside development. Do not derive secrets from the app name.`);
|
|
41
|
-
}
|
|
42
|
-
return appDevSecret(devKind);
|
|
43
|
-
}
|
|
44
|
-
function namespacedRedisKey(kind) {
|
|
45
|
-
return `${appKeyPrefix()}:${kind}`;
|
|
46
|
-
}
|
|
47
|
-
function smtpEhloHost() {
|
|
48
|
-
const raw = process.env.MAIL_EHLO?.trim() || `${appKeyPrefix()}.local`;
|
|
49
|
-
const safe = raw.replace(/[^a-zA-Z0-9.-]/g, "");
|
|
50
|
-
return safe || "strata.local";
|
|
51
|
-
}
|
|
52
|
-
function siemEventType() {
|
|
53
|
-
return process.env.SIEM_EVENT_TYPE?.trim() || `${appKeyPrefix()}.audit`;
|
|
54
|
-
}
|
|
55
|
-
function appUserAgent() {
|
|
56
|
-
return process.env.APP_USER_AGENT?.trim() || appKeyPrefix();
|
|
57
|
-
}
|
|
58
|
-
function otelServiceName() {
|
|
59
|
-
return process.env.OTEL_SERVICE_NAME?.trim() || `${appKeyPrefix()}-api`;
|
|
60
|
-
}
|
|
61
|
-
function webhookSignatureHeader() {
|
|
62
|
-
return process.env.WEBHOOK_SIGNATURE_HEADER?.trim() || `x-${appKeyPrefix()}-signature`;
|
|
63
|
-
}
|
|
64
|
-
function appDisplayName() {
|
|
65
|
-
return process.env.APP_NAME?.trim() || "Strata";
|
|
66
|
-
}
|
|
67
|
-
function appEnv() {
|
|
68
|
-
return process.env.APP_ENV?.trim() || "local";
|
|
69
|
-
}
|
|
70
|
-
function appUrl() {
|
|
71
|
-
return (process.env.APP_URL?.trim() || "http://localhost:3000").replace(/\/$/, "");
|
|
72
|
-
}
|
|
73
|
-
function apiPrefix() {
|
|
74
|
-
const raw = process.env.API_PREFIX?.trim() || "/api/v1";
|
|
75
|
-
const withSlash = raw.startsWith("/") ? raw : `/${raw}`;
|
|
76
|
-
const trimmed = withSlash.replace(/\/+$/, "");
|
|
77
|
-
return trimmed || "/api/v1";
|
|
78
|
-
}
|
|
79
|
-
function sdkClientClassName() {
|
|
80
|
-
const override = process.env.APP_SDK_CLASS?.trim();
|
|
81
|
-
if (override && /^[A-Za-z_][A-Za-z0-9_]*$/.test(override)) {
|
|
82
|
-
return override;
|
|
83
|
-
}
|
|
84
|
-
const fromName = appDisplayName().replace(/[^A-Za-z0-9]/g, "");
|
|
85
|
-
return fromName ? `${fromName}Client` : "AppClient";
|
|
86
|
-
}
|
|
87
|
-
|
|
88
2
|
// ../../src/core/openapi/generator.ts
|
|
3
|
+
function resolveOpenApiConfig(env) {
|
|
4
|
+
const appName = env.APP_NAME?.trim() || "Strata";
|
|
5
|
+
const rawPrefix = env.API_PREFIX?.trim() || "/api/v1";
|
|
6
|
+
const prefix = (rawPrefix.startsWith("/") ? rawPrefix : `/${rawPrefix}`).replace(/\/+$/, "") || "/api/v1";
|
|
7
|
+
const override = env.APP_SDK_CLASS?.trim();
|
|
8
|
+
const name = appName.replace(/[^A-Za-z0-9]/g, "");
|
|
9
|
+
return Object.freeze({
|
|
10
|
+
appName,
|
|
11
|
+
appUrl: (env.APP_URL?.trim() || "http://localhost:3000").replace(/\/$/, ""),
|
|
12
|
+
apiPrefix: prefix,
|
|
13
|
+
sdkClassName: override && /^[A-Za-z_][A-Za-z0-9_]*$/.test(override) ? override : name ? `${name}Client` : "AppClient"
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
var defaultOpenApiConfig = resolveOpenApiConfig({});
|
|
89
17
|
var PUBLIC_ROUTE_DESCRIPTIONS = {
|
|
90
18
|
"GET /auth/me": "Current authenticated user",
|
|
91
19
|
"POST /auth/login": "Login with email and password",
|
|
@@ -170,8 +98,7 @@ var PUBLIC_ROUTE_DESCRIPTIONS = {
|
|
|
170
98
|
function toOpenApiPath(path) {
|
|
171
99
|
return path.replace(/:([A-Za-z_][A-Za-z0-9_]*)/g, "{$1}");
|
|
172
100
|
}
|
|
173
|
-
function toRelativeApiPath(path) {
|
|
174
|
-
const prefix = apiPrefix();
|
|
101
|
+
function toRelativeApiPath(path, prefix) {
|
|
175
102
|
if (path === prefix) {
|
|
176
103
|
return "/";
|
|
177
104
|
}
|
|
@@ -180,8 +107,8 @@ function toRelativeApiPath(path) {
|
|
|
180
107
|
}
|
|
181
108
|
return path;
|
|
182
109
|
}
|
|
183
|
-
function requiresBearerAuth(path, method) {
|
|
184
|
-
const relative = toRelativeApiPath(path);
|
|
110
|
+
function requiresBearerAuth(path, method, prefix) {
|
|
111
|
+
const relative = toRelativeApiPath(path, prefix);
|
|
185
112
|
if (relative.startsWith("/auth/login") || relative.startsWith("/auth/two-factor-challenge") || relative.startsWith("/auth/register") || relative.startsWith("/auth/forgot-password") || relative.startsWith("/auth/reset-password") || relative.startsWith("/auth/email/verification-notification") || relative.startsWith("/auth/oauth") || relative === "/auth/token" || relative === "/apply/login" || relative === "/login" || path === "/login" || path === "/api/login" || path === "/api/apply/login") {
|
|
186
113
|
return false;
|
|
187
114
|
}
|
|
@@ -206,16 +133,21 @@ var DEFAULT_RESPONSES = {
|
|
|
206
133
|
"404": { description: "Not Found" },
|
|
207
134
|
"422": { description: "Validation Error" }
|
|
208
135
|
};
|
|
209
|
-
function generateOpenApiSpec(routes) {
|
|
136
|
+
function generateOpenApiSpec(routes, config = defaultOpenApiConfig) {
|
|
210
137
|
const paths = {};
|
|
211
|
-
|
|
138
|
+
const expanded = routes.flatMap((route) => route.method === "*" ? ["GET", "HEAD", "POST", "PUT", "DELETE", "PATCH", "OPTIONS", "TRACE"].map((method) => ({
|
|
139
|
+
...route,
|
|
140
|
+
method,
|
|
141
|
+
openApi: undefined
|
|
142
|
+
})) : []);
|
|
143
|
+
for (const route of [...expanded, ...routes.filter((route) => route.method !== "*")]) {
|
|
212
144
|
const openApiPath = toOpenApiPath(route.path);
|
|
213
145
|
const method = route.method.toLowerCase();
|
|
214
|
-
const description = PUBLIC_ROUTE_DESCRIPTIONS[`${route.method} ${toRelativeApiPath(route.path)}`] ?? PUBLIC_ROUTE_DESCRIPTIONS[`${route.method} ${route.path}`] ?? `${route.method} ${route.path}`;
|
|
146
|
+
const description = PUBLIC_ROUTE_DESCRIPTIONS[`${route.method} ${toRelativeApiPath(route.path, config.apiPrefix)}`] ?? PUBLIC_ROUTE_DESCRIPTIONS[`${route.method} ${route.path}`] ?? `${route.method} ${route.path}`;
|
|
215
147
|
paths[openApiPath] ??= {};
|
|
216
148
|
paths[openApiPath][method] = {
|
|
217
149
|
summary: description,
|
|
218
|
-
...requiresBearerAuth(route.path, route.method) ? { security: [{ bearerAuth: [] }] } : {},
|
|
150
|
+
...requiresBearerAuth(route.path, route.method, config.apiPrefix) ? { security: [{ bearerAuth: [] }] } : {},
|
|
219
151
|
...route.openApi,
|
|
220
152
|
responses: route.openApi?.responses ?? structuredClone(DEFAULT_RESPONSES)
|
|
221
153
|
};
|
|
@@ -223,12 +155,12 @@ function generateOpenApiSpec(routes) {
|
|
|
223
155
|
return {
|
|
224
156
|
openapi: "3.1.0",
|
|
225
157
|
info: {
|
|
226
|
-
title: `${
|
|
158
|
+
title: `${config.appName} API`,
|
|
227
159
|
version: "1.0.0"
|
|
228
160
|
},
|
|
229
161
|
servers: [
|
|
230
|
-
{ url: `${appUrl
|
|
231
|
-
{ url: appUrl
|
|
162
|
+
{ url: `${config.appUrl}${config.apiPrefix}`, description: `${config.appName} API` },
|
|
163
|
+
{ url: config.appUrl, description: "Root (health, metrics, SCIM)" }
|
|
232
164
|
],
|
|
233
165
|
paths,
|
|
234
166
|
components: {
|
|
@@ -289,9 +221,9 @@ function toMethodName(method, path, apiPrefix) {
|
|
|
289
221
|
function toRequestPath(path, apiPrefix) {
|
|
290
222
|
return path.startsWith(apiPrefix) ? path.slice(apiPrefix.length) || "/" : path;
|
|
291
223
|
}
|
|
292
|
-
function renderTypeScriptSdk(spec, prefix = apiPrefix
|
|
224
|
+
function renderTypeScriptSdk(spec, prefix = defaultOpenApiConfig.apiPrefix, className = defaultOpenApiConfig.sdkClassName) {
|
|
293
225
|
const lines = [
|
|
294
|
-
`export class ${
|
|
226
|
+
`export class ${className} {`,
|
|
295
227
|
` constructor(private readonly baseUrl = "${spec.servers[0]?.url ?? ""}") {}`,
|
|
296
228
|
"",
|
|
297
229
|
" private async request(path: string, init: RequestInit = {}): Promise<Response> {",
|
|
@@ -341,5 +273,6 @@ function renderTypeScriptSdk(spec, prefix = apiPrefix()) {
|
|
|
341
273
|
export {
|
|
342
274
|
generateOpenApiSpec,
|
|
343
275
|
renderOpenApiDocument,
|
|
344
|
-
renderTypeScriptSdk
|
|
276
|
+
renderTypeScriptSdk,
|
|
277
|
+
resolveOpenApiConfig
|
|
345
278
|
};
|