@contember/engine-http 2.2.0-alpha.1 → 2.2.0-alpha.11
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/CLAUDE.md +3 -1
- package/dist/development/index.cjs +28 -0
- package/dist/development/index.cjs.map +1 -1
- package/dist/development/index.js +27 -2
- package/dist/development/index.js.map +1 -1
- package/dist/development/src/MasterContainer.cjs +44 -19
- package/dist/development/src/MasterContainer.cjs.map +1 -1
- package/dist/development/src/MasterContainer.js +44 -19
- package/dist/development/src/MasterContainer.js.map +1 -1
- package/dist/development/src/application/PanelApiMount.cjs +8 -0
- package/dist/development/src/application/PanelApiMount.cjs.map +1 -0
- package/dist/development/src/application/PanelApiMount.js +8 -0
- package/dist/development/src/application/PanelApiMount.js.map +1 -0
- package/dist/development/src/application/application.cjs +296 -69
- package/dist/development/src/application/application.cjs.map +1 -1
- package/dist/development/src/application/application.js +298 -71
- package/dist/development/src/application/application.js.map +1 -1
- package/dist/development/src/application/forceHttpOk.cjs +2 -9
- package/dist/development/src/application/forceHttpOk.cjs.map +1 -1
- package/dist/development/src/application/forceHttpOk.js +2 -9
- package/dist/development/src/application/forceHttpOk.js.map +1 -1
- package/dist/development/src/common/Authorizator.cjs +22 -19
- package/dist/development/src/common/Authorizator.cjs.map +1 -1
- package/dist/development/src/common/Authorizator.js +22 -19
- package/dist/development/src/common/Authorizator.js.map +1 -1
- package/dist/development/src/common/HttpResponse.cjs +5 -3
- package/dist/development/src/common/HttpResponse.cjs.map +1 -1
- package/dist/development/src/common/HttpResponse.js +5 -3
- package/dist/development/src/common/HttpResponse.js.map +1 -1
- package/dist/development/src/config/config.cjs +2 -1
- package/dist/development/src/config/config.cjs.map +1 -1
- package/dist/development/src/config/config.js +2 -1
- package/dist/development/src/config/config.js.map +1 -1
- package/dist/development/src/config/configSchema.cjs +71 -0
- package/dist/development/src/config/configSchema.cjs.map +1 -1
- package/dist/development/src/config/configSchema.js +71 -0
- package/dist/development/src/config/configSchema.js.map +1 -1
- package/dist/development/src/config/configTemplate.cjs +35 -1
- package/dist/development/src/config/configTemplate.cjs.map +1 -1
- package/dist/development/src/config/configTemplate.js +35 -1
- package/dist/development/src/config/configTemplate.js.map +1 -1
- package/dist/development/src/config/projectConfigResolver.cjs +1 -0
- package/dist/development/src/config/projectConfigResolver.cjs.map +1 -1
- package/dist/development/src/config/projectConfigResolver.js +2 -1
- package/dist/development/src/config/projectConfigResolver.js.map +1 -1
- package/dist/development/src/content/ContentApiControllerFactory.cjs +30 -4
- package/dist/development/src/content/ContentApiControllerFactory.cjs.map +1 -1
- package/dist/development/src/content/ContentApiControllerFactory.js +30 -4
- package/dist/development/src/content/ContentApiControllerFactory.js.map +1 -1
- package/dist/development/src/content/ContentApiSpecificCache.cjs +44 -16
- package/dist/development/src/content/ContentApiSpecificCache.cjs.map +1 -1
- package/dist/development/src/content/ContentApiSpecificCache.js +44 -16
- package/dist/development/src/content/ContentApiSpecificCache.js.map +1 -1
- package/dist/development/src/content/ContentQueryHandlerFactory.cjs +2 -1
- package/dist/development/src/content/ContentQueryHandlerFactory.cjs.map +1 -1
- package/dist/development/src/content/ContentQueryHandlerFactory.js +2 -1
- package/dist/development/src/content/ContentQueryHandlerFactory.js.map +1 -1
- package/dist/development/src/content/GraphQlSchemaFactory.cjs +26 -3
- package/dist/development/src/content/GraphQlSchemaFactory.cjs.map +1 -1
- package/dist/development/src/content/GraphQlSchemaFactory.js +26 -3
- package/dist/development/src/content/GraphQlSchemaFactory.js.map +1 -1
- package/dist/development/src/graphql/execution.cjs +19 -4
- package/dist/development/src/graphql/execution.cjs.map +1 -1
- package/dist/development/src/graphql/execution.js +19 -4
- package/dist/development/src/graphql/execution.js.map +1 -1
- package/dist/development/src/misc/HomepageMiddlewareFactory.cjs +1 -0
- package/dist/development/src/misc/HomepageMiddlewareFactory.cjs.map +1 -1
- package/dist/development/src/misc/HomepageMiddlewareFactory.js +1 -0
- package/dist/development/src/misc/HomepageMiddlewareFactory.js.map +1 -1
- package/dist/development/src/project/ProjectContainer.cjs +1 -0
- package/dist/development/src/project/ProjectContainer.cjs.map +1 -1
- package/dist/development/src/project/ProjectContainer.js +1 -0
- package/dist/development/src/project/ProjectContainer.js.map +1 -1
- package/dist/development/src/project-common/ProjectContextResolver.cjs +1 -0
- package/dist/development/src/project-common/ProjectContextResolver.cjs.map +1 -1
- package/dist/development/src/project-common/ProjectContextResolver.js +1 -0
- package/dist/development/src/project-common/ProjectContextResolver.js.map +1 -1
- package/dist/development/src/projectGroup/ProjectGroupContainer.cjs +27 -22
- package/dist/development/src/projectGroup/ProjectGroupContainer.cjs.map +1 -1
- package/dist/development/src/projectGroup/ProjectGroupContainer.js +27 -22
- package/dist/development/src/projectGroup/ProjectGroupContainer.js.map +1 -1
- package/dist/development/src/projectGroup/ProjectGroupResolver.cjs +1 -0
- package/dist/development/src/projectGroup/ProjectGroupResolver.cjs.map +1 -1
- package/dist/development/src/projectGroup/ProjectGroupResolver.js +1 -0
- package/dist/development/src/projectGroup/ProjectGroupResolver.js.map +1 -1
- package/dist/development/src/prometheus/dbMetrics.cjs +4 -1
- package/dist/development/src/prometheus/dbMetrics.cjs.map +1 -1
- package/dist/development/src/prometheus/dbMetrics.js +5 -2
- package/dist/development/src/prometheus/dbMetrics.js.map +1 -1
- package/dist/development/src/system/SystemApiMiddlewareFactory.cjs +1 -0
- package/dist/development/src/system/SystemApiMiddlewareFactory.cjs.map +1 -1
- package/dist/development/src/system/SystemApiMiddlewareFactory.js +1 -0
- package/dist/development/src/system/SystemApiMiddlewareFactory.js.map +1 -1
- package/dist/development/src/telemetry/FilteringSpanProcessor.cjs +15 -0
- package/dist/development/src/telemetry/FilteringSpanProcessor.cjs.map +1 -0
- package/dist/development/src/telemetry/FilteringSpanProcessor.js +15 -0
- package/dist/development/src/telemetry/FilteringSpanProcessor.js.map +1 -0
- package/dist/development/src/telemetry/ProjectGroupContainerTelemetryHook.cjs +59 -0
- package/dist/development/src/telemetry/ProjectGroupContainerTelemetryHook.cjs.map +1 -0
- package/dist/development/src/telemetry/ProjectGroupContainerTelemetryHook.js +59 -0
- package/dist/development/src/telemetry/ProjectGroupContainerTelemetryHook.js.map +1 -0
- package/dist/development/src/telemetry/TelemetryFactory.cjs +87 -0
- package/dist/development/src/telemetry/TelemetryFactory.cjs.map +1 -0
- package/dist/development/src/telemetry/TelemetryFactory.js +87 -0
- package/dist/development/src/telemetry/TelemetryFactory.js.map +1 -0
- package/dist/development/src/telemetry/incomingTrace.cjs +32 -0
- package/dist/development/src/telemetry/incomingTrace.cjs.map +1 -0
- package/dist/development/src/telemetry/incomingTrace.js +32 -0
- package/dist/development/src/telemetry/incomingTrace.js.map +1 -0
- package/dist/development/src/telemetry/sqlSpans.cjs +59 -0
- package/dist/development/src/telemetry/sqlSpans.cjs.map +1 -0
- package/dist/development/src/telemetry/sqlSpans.js +59 -0
- package/dist/development/src/telemetry/sqlSpans.js.map +1 -0
- package/dist/development/src/tenant/OidcBackchannelLogoutMiddlewareFactory.cjs +1 -0
- package/dist/development/src/tenant/OidcBackchannelLogoutMiddlewareFactory.cjs.map +1 -1
- package/dist/development/src/tenant/OidcBackchannelLogoutMiddlewareFactory.js +1 -0
- package/dist/development/src/tenant/OidcBackchannelLogoutMiddlewareFactory.js.map +1 -1
- package/dist/development/src/tenant/TenantApiMiddlewareFactory.cjs +13 -14
- package/dist/development/src/tenant/TenantApiMiddlewareFactory.cjs.map +1 -1
- package/dist/development/src/tenant/TenantApiMiddlewareFactory.js +13 -14
- package/dist/development/src/tenant/TenantApiMiddlewareFactory.js.map +1 -1
- package/dist/development/src/testing/TestTransactions.cjs +21 -11
- package/dist/development/src/testing/TestTransactions.cjs.map +1 -1
- package/dist/development/src/testing/TestTransactions.js +21 -11
- package/dist/development/src/testing/TestTransactions.js.map +1 -1
- package/dist/development/src/transfer/ExportApiControllerFactory.cjs +1 -0
- package/dist/development/src/transfer/ExportApiControllerFactory.cjs.map +1 -1
- package/dist/development/src/transfer/ExportApiControllerFactory.js +1 -0
- package/dist/development/src/transfer/ExportApiControllerFactory.js.map +1 -1
- package/dist/development/src/transfer/ImportApiMiddlewareFactory.cjs +1 -0
- package/dist/development/src/transfer/ImportApiMiddlewareFactory.cjs.map +1 -1
- package/dist/development/src/transfer/ImportApiMiddlewareFactory.js +1 -0
- package/dist/development/src/transfer/ImportApiMiddlewareFactory.js.map +1 -1
- package/dist/development/src/transfer/ImportExecutor.cjs +1 -0
- package/dist/development/src/transfer/ImportExecutor.cjs.map +1 -1
- package/dist/development/src/transfer/ImportExecutor.js +1 -0
- package/dist/development/src/transfer/ImportExecutor.js.map +1 -1
- package/dist/development/src/utils/remoteAddress.cjs +9 -1
- package/dist/development/src/utils/remoteAddress.cjs.map +1 -1
- package/dist/development/src/utils/remoteAddress.js +10 -2
- package/dist/development/src/utils/remoteAddress.js.map +1 -1
- package/dist/development/src/utils/sentry.cjs +4 -1
- package/dist/development/src/utils/sentry.cjs.map +1 -1
- package/dist/development/src/utils/sentry.js +4 -1
- package/dist/development/src/utils/sentry.js.map +1 -1
- package/dist/development/src/utils/serverTermination.cjs +21 -3
- package/dist/development/src/utils/serverTermination.cjs.map +1 -1
- package/dist/development/src/utils/serverTermination.js +21 -3
- package/dist/development/src/utils/serverTermination.js.map +1 -1
- package/dist/development/src/utils/truthyHeader.cjs +13 -0
- package/dist/development/src/utils/truthyHeader.cjs.map +1 -0
- package/dist/development/src/utils/truthyHeader.js +13 -0
- package/dist/development/src/utils/truthyHeader.js.map +1 -0
- package/dist/production/index.cjs +28 -0
- package/dist/production/index.cjs.map +1 -1
- package/dist/production/index.js +27 -2
- package/dist/production/index.js.map +1 -1
- package/dist/production/src/MasterContainer.cjs +44 -19
- package/dist/production/src/MasterContainer.cjs.map +1 -1
- package/dist/production/src/MasterContainer.js +44 -19
- package/dist/production/src/MasterContainer.js.map +1 -1
- package/dist/production/src/application/PanelApiMount.cjs +8 -0
- package/dist/production/src/application/PanelApiMount.cjs.map +1 -0
- package/dist/production/src/application/PanelApiMount.js +8 -0
- package/dist/production/src/application/PanelApiMount.js.map +1 -0
- package/dist/production/src/application/application.cjs +296 -69
- package/dist/production/src/application/application.cjs.map +1 -1
- package/dist/production/src/application/application.js +298 -71
- package/dist/production/src/application/application.js.map +1 -1
- package/dist/production/src/application/forceHttpOk.cjs +2 -9
- package/dist/production/src/application/forceHttpOk.cjs.map +1 -1
- package/dist/production/src/application/forceHttpOk.js +2 -9
- package/dist/production/src/application/forceHttpOk.js.map +1 -1
- package/dist/production/src/common/Authorizator.cjs +22 -19
- package/dist/production/src/common/Authorizator.cjs.map +1 -1
- package/dist/production/src/common/Authorizator.js +22 -19
- package/dist/production/src/common/Authorizator.js.map +1 -1
- package/dist/production/src/common/HttpResponse.cjs +5 -3
- package/dist/production/src/common/HttpResponse.cjs.map +1 -1
- package/dist/production/src/common/HttpResponse.js +5 -3
- package/dist/production/src/common/HttpResponse.js.map +1 -1
- package/dist/production/src/config/config.cjs +2 -1
- package/dist/production/src/config/config.cjs.map +1 -1
- package/dist/production/src/config/config.js +2 -1
- package/dist/production/src/config/config.js.map +1 -1
- package/dist/production/src/config/configSchema.cjs +71 -0
- package/dist/production/src/config/configSchema.cjs.map +1 -1
- package/dist/production/src/config/configSchema.js +71 -0
- package/dist/production/src/config/configSchema.js.map +1 -1
- package/dist/production/src/config/configTemplate.cjs +35 -1
- package/dist/production/src/config/configTemplate.cjs.map +1 -1
- package/dist/production/src/config/configTemplate.js +35 -1
- package/dist/production/src/config/configTemplate.js.map +1 -1
- package/dist/production/src/config/projectConfigResolver.cjs +1 -0
- package/dist/production/src/config/projectConfigResolver.cjs.map +1 -1
- package/dist/production/src/config/projectConfigResolver.js +2 -1
- package/dist/production/src/config/projectConfigResolver.js.map +1 -1
- package/dist/production/src/content/ContentApiControllerFactory.cjs +30 -4
- package/dist/production/src/content/ContentApiControllerFactory.cjs.map +1 -1
- package/dist/production/src/content/ContentApiControllerFactory.js +30 -4
- package/dist/production/src/content/ContentApiControllerFactory.js.map +1 -1
- package/dist/production/src/content/ContentApiSpecificCache.cjs +44 -16
- package/dist/production/src/content/ContentApiSpecificCache.cjs.map +1 -1
- package/dist/production/src/content/ContentApiSpecificCache.js +44 -16
- package/dist/production/src/content/ContentApiSpecificCache.js.map +1 -1
- package/dist/production/src/content/ContentQueryHandlerFactory.cjs +2 -1
- package/dist/production/src/content/ContentQueryHandlerFactory.cjs.map +1 -1
- package/dist/production/src/content/ContentQueryHandlerFactory.js +2 -1
- package/dist/production/src/content/ContentQueryHandlerFactory.js.map +1 -1
- package/dist/production/src/content/GraphQlSchemaFactory.cjs +26 -3
- package/dist/production/src/content/GraphQlSchemaFactory.cjs.map +1 -1
- package/dist/production/src/content/GraphQlSchemaFactory.js +26 -3
- package/dist/production/src/content/GraphQlSchemaFactory.js.map +1 -1
- package/dist/production/src/graphql/execution.cjs +19 -4
- package/dist/production/src/graphql/execution.cjs.map +1 -1
- package/dist/production/src/graphql/execution.js +19 -4
- package/dist/production/src/graphql/execution.js.map +1 -1
- package/dist/production/src/misc/HomepageMiddlewareFactory.cjs +1 -0
- package/dist/production/src/misc/HomepageMiddlewareFactory.cjs.map +1 -1
- package/dist/production/src/misc/HomepageMiddlewareFactory.js +1 -0
- package/dist/production/src/misc/HomepageMiddlewareFactory.js.map +1 -1
- package/dist/production/src/project/ProjectContainer.cjs +1 -0
- package/dist/production/src/project/ProjectContainer.cjs.map +1 -1
- package/dist/production/src/project/ProjectContainer.js +1 -0
- package/dist/production/src/project/ProjectContainer.js.map +1 -1
- package/dist/production/src/project-common/ProjectContextResolver.cjs +1 -0
- package/dist/production/src/project-common/ProjectContextResolver.cjs.map +1 -1
- package/dist/production/src/project-common/ProjectContextResolver.js +1 -0
- package/dist/production/src/project-common/ProjectContextResolver.js.map +1 -1
- package/dist/production/src/projectGroup/ProjectGroupContainer.cjs +27 -22
- package/dist/production/src/projectGroup/ProjectGroupContainer.cjs.map +1 -1
- package/dist/production/src/projectGroup/ProjectGroupContainer.js +27 -22
- package/dist/production/src/projectGroup/ProjectGroupContainer.js.map +1 -1
- package/dist/production/src/projectGroup/ProjectGroupResolver.cjs +1 -0
- package/dist/production/src/projectGroup/ProjectGroupResolver.cjs.map +1 -1
- package/dist/production/src/projectGroup/ProjectGroupResolver.js +1 -0
- package/dist/production/src/projectGroup/ProjectGroupResolver.js.map +1 -1
- package/dist/production/src/prometheus/dbMetrics.cjs +4 -1
- package/dist/production/src/prometheus/dbMetrics.cjs.map +1 -1
- package/dist/production/src/prometheus/dbMetrics.js +5 -2
- package/dist/production/src/prometheus/dbMetrics.js.map +1 -1
- package/dist/production/src/system/SystemApiMiddlewareFactory.cjs +1 -0
- package/dist/production/src/system/SystemApiMiddlewareFactory.cjs.map +1 -1
- package/dist/production/src/system/SystemApiMiddlewareFactory.js +1 -0
- package/dist/production/src/system/SystemApiMiddlewareFactory.js.map +1 -1
- package/dist/production/src/telemetry/FilteringSpanProcessor.cjs +15 -0
- package/dist/production/src/telemetry/FilteringSpanProcessor.cjs.map +1 -0
- package/dist/production/src/telemetry/FilteringSpanProcessor.js +15 -0
- package/dist/production/src/telemetry/FilteringSpanProcessor.js.map +1 -0
- package/dist/production/src/telemetry/ProjectGroupContainerTelemetryHook.cjs +59 -0
- package/dist/production/src/telemetry/ProjectGroupContainerTelemetryHook.cjs.map +1 -0
- package/dist/production/src/telemetry/ProjectGroupContainerTelemetryHook.js +59 -0
- package/dist/production/src/telemetry/ProjectGroupContainerTelemetryHook.js.map +1 -0
- package/dist/production/src/telemetry/TelemetryFactory.cjs +87 -0
- package/dist/production/src/telemetry/TelemetryFactory.cjs.map +1 -0
- package/dist/production/src/telemetry/TelemetryFactory.js +87 -0
- package/dist/production/src/telemetry/TelemetryFactory.js.map +1 -0
- package/dist/production/src/telemetry/incomingTrace.cjs +32 -0
- package/dist/production/src/telemetry/incomingTrace.cjs.map +1 -0
- package/dist/production/src/telemetry/incomingTrace.js +32 -0
- package/dist/production/src/telemetry/incomingTrace.js.map +1 -0
- package/dist/production/src/telemetry/sqlSpans.cjs +59 -0
- package/dist/production/src/telemetry/sqlSpans.cjs.map +1 -0
- package/dist/production/src/telemetry/sqlSpans.js +59 -0
- package/dist/production/src/telemetry/sqlSpans.js.map +1 -0
- package/dist/production/src/tenant/OidcBackchannelLogoutMiddlewareFactory.cjs +1 -0
- package/dist/production/src/tenant/OidcBackchannelLogoutMiddlewareFactory.cjs.map +1 -1
- package/dist/production/src/tenant/OidcBackchannelLogoutMiddlewareFactory.js +1 -0
- package/dist/production/src/tenant/OidcBackchannelLogoutMiddlewareFactory.js.map +1 -1
- package/dist/production/src/tenant/TenantApiMiddlewareFactory.cjs +13 -14
- package/dist/production/src/tenant/TenantApiMiddlewareFactory.cjs.map +1 -1
- package/dist/production/src/tenant/TenantApiMiddlewareFactory.js +13 -14
- package/dist/production/src/tenant/TenantApiMiddlewareFactory.js.map +1 -1
- package/dist/production/src/testing/TestTransactions.cjs +21 -11
- package/dist/production/src/testing/TestTransactions.cjs.map +1 -1
- package/dist/production/src/testing/TestTransactions.js +21 -11
- package/dist/production/src/testing/TestTransactions.js.map +1 -1
- package/dist/production/src/transfer/ExportApiControllerFactory.cjs +1 -0
- package/dist/production/src/transfer/ExportApiControllerFactory.cjs.map +1 -1
- package/dist/production/src/transfer/ExportApiControllerFactory.js +1 -0
- package/dist/production/src/transfer/ExportApiControllerFactory.js.map +1 -1
- package/dist/production/src/transfer/ImportApiMiddlewareFactory.cjs +1 -0
- package/dist/production/src/transfer/ImportApiMiddlewareFactory.cjs.map +1 -1
- package/dist/production/src/transfer/ImportApiMiddlewareFactory.js +1 -0
- package/dist/production/src/transfer/ImportApiMiddlewareFactory.js.map +1 -1
- package/dist/production/src/transfer/ImportExecutor.cjs +1 -0
- package/dist/production/src/transfer/ImportExecutor.cjs.map +1 -1
- package/dist/production/src/transfer/ImportExecutor.js +1 -0
- package/dist/production/src/transfer/ImportExecutor.js.map +1 -1
- package/dist/production/src/utils/remoteAddress.cjs +9 -1
- package/dist/production/src/utils/remoteAddress.cjs.map +1 -1
- package/dist/production/src/utils/remoteAddress.js +10 -2
- package/dist/production/src/utils/remoteAddress.js.map +1 -1
- package/dist/production/src/utils/sentry.cjs +4 -1
- package/dist/production/src/utils/sentry.cjs.map +1 -1
- package/dist/production/src/utils/sentry.js +4 -1
- package/dist/production/src/utils/sentry.js.map +1 -1
- package/dist/production/src/utils/serverTermination.cjs +21 -3
- package/dist/production/src/utils/serverTermination.cjs.map +1 -1
- package/dist/production/src/utils/serverTermination.js +21 -3
- package/dist/production/src/utils/serverTermination.js.map +1 -1
- package/dist/production/src/utils/truthyHeader.cjs +13 -0
- package/dist/production/src/utils/truthyHeader.cjs.map +1 -0
- package/dist/production/src/utils/truthyHeader.js +13 -0
- package/dist/production/src/utils/truthyHeader.js.map +1 -0
- package/dist/tests/cases/integration/requestMemoryBudget.test.d.ts +2 -0
- package/dist/tests/cases/integration/requestMemoryBudget.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/applicationShutdown.test.d.ts +2 -0
- package/dist/tests/cases/unit/applicationShutdown.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/contentApiSpecificCacheLimit.test.d.ts +2 -0
- package/dist/tests/cases/unit/contentApiSpecificCacheLimit.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/forcePrimary.test.d.ts +2 -0
- package/dist/tests/cases/unit/forcePrimary.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/graphQlSchemaFactory.test.d.ts +2 -0
- package/dist/tests/cases/unit/graphQlSchemaFactory.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/incomingTrace.test.d.ts +2 -0
- package/dist/tests/cases/unit/incomingTrace.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/requestMemoryBudget.test.d.ts +2 -0
- package/dist/tests/cases/unit/requestMemoryBudget.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/requestTracing.test.d.ts +2 -0
- package/dist/tests/cases/unit/requestTracing.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/serverTermination.fixture.d.ts +2 -0
- package/dist/tests/cases/unit/serverTermination.fixture.d.ts.map +1 -0
- package/dist/tests/cases/unit/serverTermination.test.d.ts +2 -0
- package/dist/tests/cases/unit/serverTermination.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/spanFiltering.test.d.ts +2 -0
- package/dist/tests/cases/unit/spanFiltering.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/sqlSpans.test.d.ts +2 -0
- package/dist/tests/cases/unit/sqlSpans.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/telemetryConfig.test.d.ts +2 -0
- package/dist/tests/cases/unit/telemetryConfig.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/timerFacade.test.d.ts +2 -0
- package/dist/tests/cases/unit/timerFacade.test.d.ts.map +1 -0
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/dist/types/MasterContainer.d.ts +66 -6
- package/dist/types/MasterContainer.d.ts.map +1 -1
- package/dist/types/application/PanelApiMount.d.ts +29 -0
- package/dist/types/application/PanelApiMount.d.ts.map +1 -0
- package/dist/types/application/application.d.ts +19 -1
- package/dist/types/application/application.d.ts.map +1 -1
- package/dist/types/application/forceHttpOk.d.ts.map +1 -1
- package/dist/types/application/index.d.ts +1 -0
- package/dist/types/application/index.d.ts.map +1 -1
- package/dist/types/bootstrap/Initializer.d.ts.map +1 -1
- package/dist/types/common/Authorizator.d.ts +9 -1
- package/dist/types/common/Authorizator.d.ts.map +1 -1
- package/dist/types/common/HttpResponse.d.ts +6 -2
- package/dist/types/common/HttpResponse.d.ts.map +1 -1
- package/dist/types/common/ModuleInfoMiddleware.d.ts.map +1 -1
- package/dist/types/common/index.d.ts +2 -0
- package/dist/types/common/index.d.ts.map +1 -1
- package/dist/types/config/config.d.ts +3 -1
- package/dist/types/config/config.d.ts.map +1 -1
- package/dist/types/config/configSchema.d.ts +358 -11
- package/dist/types/config/configSchema.d.ts.map +1 -1
- package/dist/types/config/configTemplate.d.ts.map +1 -1
- package/dist/types/config/projectConfigResolver.d.ts +1 -0
- package/dist/types/config/projectConfigResolver.d.ts.map +1 -1
- package/dist/types/config/tenantConfigResolver.d.ts.map +1 -1
- package/dist/types/content/ContentApiControllerFactory.d.ts +4 -1
- package/dist/types/content/ContentApiControllerFactory.d.ts.map +1 -1
- package/dist/types/content/ContentApiSpecificCache.d.ts +5 -0
- package/dist/types/content/ContentApiSpecificCache.d.ts.map +1 -1
- package/dist/types/content/ContentGraphqlContext.d.ts +2 -0
- package/dist/types/content/ContentGraphqlContext.d.ts.map +1 -1
- package/dist/types/content/ContentQueryHandlerFactory.d.ts.map +1 -1
- package/dist/types/content/ContentSchemaResolver.d.ts.map +1 -1
- package/dist/types/content/GraphQLSchemaContributor.d.ts +4 -0
- package/dist/types/content/GraphQLSchemaContributor.d.ts.map +1 -1
- package/dist/types/content/GraphQlSchemaFactory.d.ts +2 -0
- package/dist/types/content/GraphQlSchemaFactory.d.ts.map +1 -1
- package/dist/types/content/NotModifiedChecker.d.ts.map +1 -1
- package/dist/types/content/ProjectMembershipFetcher.d.ts.map +1 -1
- package/dist/types/content/ProjectMembershipResolver.d.ts.map +1 -1
- package/dist/types/graphql/dbQueriesListener.d.ts.map +1 -1
- package/dist/types/graphql/execution.d.ts +4 -1
- package/dist/types/graphql/execution.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/project/ProjectContainer.d.ts.map +1 -1
- package/dist/types/project/ProjectContainerResolver.d.ts.map +1 -1
- package/dist/types/project/ProjectContainerStore.d.ts.map +1 -1
- package/dist/types/project/ProjectDatabaseMetadataResolver.d.ts.map +1 -1
- package/dist/types/project/ProjectInitializer.d.ts.map +1 -1
- package/dist/types/project/ProjectSchemaResolver.d.ts.map +1 -1
- package/dist/types/project-common/ProjectContextResolver.d.ts.map +1 -1
- package/dist/types/projectGroup/ProjectGroupContainer.d.ts.map +1 -1
- package/dist/types/projectGroup/ProjectGroupContainerResolver.d.ts.map +1 -1
- package/dist/types/projectGroup/ProjectGroupResolver.d.ts.map +1 -1
- package/dist/types/prometheus/CollectHttpMetricsMiddelware.d.ts.map +1 -1
- package/dist/types/prometheus/CustomMetric.d.ts.map +1 -1
- package/dist/types/prometheus/ProjectGroupContainerMetricsHook.d.ts.map +1 -1
- package/dist/types/prometheus/PrometheusRegistryFactory.d.ts.map +1 -1
- package/dist/types/prometheus/ShowMetricsMiddleware.d.ts.map +1 -1
- package/dist/types/prometheus/contemberEngineInfoMetric.d.ts.map +1 -1
- package/dist/types/prometheus/dbMetrics.d.ts.map +1 -1
- package/dist/types/providers.d.ts.map +1 -1
- package/dist/types/system/ContentQueryExecutor.d.ts.map +1 -1
- package/dist/types/system/SystemApiMiddlewareFactory.d.ts.map +1 -1
- package/dist/types/system/SystemGraphQLContextFactory.d.ts.map +1 -1
- package/dist/types/system/SystemGraphQLHandlerFactory.d.ts.map +1 -1
- package/dist/types/telemetry/FilteringSpanProcessor.d.ts +8 -0
- package/dist/types/telemetry/FilteringSpanProcessor.d.ts.map +1 -0
- package/dist/types/telemetry/ProjectGroupContainerTelemetryHook.d.ts +18 -0
- package/dist/types/telemetry/ProjectGroupContainerTelemetryHook.d.ts.map +1 -0
- package/dist/types/telemetry/TelemetryFactory.d.ts +19 -0
- package/dist/types/telemetry/TelemetryFactory.d.ts.map +1 -0
- package/dist/types/telemetry/incomingTrace.d.ts +18 -0
- package/dist/types/telemetry/incomingTrace.d.ts.map +1 -0
- package/dist/types/telemetry/index.d.ts +6 -0
- package/dist/types/telemetry/index.d.ts.map +1 -0
- package/dist/types/telemetry/sqlSpans.d.ts +16 -0
- package/dist/types/telemetry/sqlSpans.d.ts.map +1 -0
- package/dist/types/tenant/OidcBackchannelLogoutMiddlewareFactory.d.ts.map +1 -1
- package/dist/types/tenant/TenantApiMiddlewareFactory.d.ts.map +1 -1
- package/dist/types/tenant/TenantGraphQLHandlerFactory.d.ts.map +1 -1
- package/dist/types/testing/TestTransactions.d.ts.map +1 -1
- package/dist/types/transfer/Command.d.ts +5 -5
- package/dist/types/transfer/Command.d.ts.map +1 -1
- package/dist/types/transfer/ContentSchemaTransferMappingFactory.d.ts.map +1 -1
- package/dist/types/transfer/ExportApiControllerFactory.d.ts.map +1 -1
- package/dist/types/transfer/ExportExecutor.d.ts.map +1 -1
- package/dist/types/transfer/ImportApiMiddlewareFactory.d.ts.map +1 -1
- package/dist/types/transfer/ImportExecutor.d.ts.map +1 -1
- package/dist/types/transfer/SystemSchemaTransferMappingFactory.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/dist/types/utils/CryptoWrapper.d.ts +1 -1
- package/dist/types/utils/CryptoWrapper.d.ts.map +1 -1
- package/dist/types/utils/memoizeObject.d.ts.map +1 -1
- package/dist/types/utils/remoteAddress.d.ts +1 -0
- package/dist/types/utils/remoteAddress.d.ts.map +1 -1
- package/dist/types/utils/sentry.d.ts.map +1 -1
- package/dist/types/utils/serverStartup.d.ts +1 -0
- package/dist/types/utils/serverStartup.d.ts.map +1 -1
- package/dist/types/utils/serverTermination.d.ts +13 -1
- package/dist/types/utils/serverTermination.d.ts.map +1 -1
- package/dist/types/utils/strings.d.ts.map +1 -1
- package/dist/types/utils/truthyHeader.d.ts +3 -0
- package/dist/types/utils/truthyHeader.d.ts.map +1 -0
- package/dist/types/workers/ApplicationWorkerManager.d.ts.map +1 -1
- package/package.json +16 -15
- package/src/MasterContainer.ts +50 -16
- package/src/application/PanelApiMount.ts +33 -0
- package/src/application/application.ts +315 -76
- package/src/application/forceHttpOk.ts +2 -10
- package/src/application/index.ts +1 -0
- package/src/common/Authorizator.ts +41 -21
- package/src/common/HttpResponse.ts +4 -0
- package/src/common/index.ts +2 -0
- package/src/config/config.ts +4 -1
- package/src/config/configSchema.ts +72 -0
- package/src/config/configTemplate.ts +34 -0
- package/src/config/projectConfigResolver.ts +1 -1
- package/src/content/ContentApiControllerFactory.ts +32 -4
- package/src/content/ContentApiSpecificCache.ts +56 -17
- package/src/content/ContentGraphqlContext.ts +2 -0
- package/src/content/ContentQueryHandlerFactory.ts +1 -0
- package/src/content/GraphQLSchemaContributor.ts +4 -0
- package/src/content/GraphQlSchemaFactory.ts +29 -3
- package/src/graphql/execution.ts +27 -4
- package/src/index.ts +2 -0
- package/src/projectGroup/ProjectGroupContainer.ts +28 -24
- package/src/prometheus/dbMetrics.ts +5 -2
- package/src/telemetry/FilteringSpanProcessor.ts +22 -0
- package/src/telemetry/ProjectGroupContainerTelemetryHook.ts +67 -0
- package/src/telemetry/TelemetryFactory.ts +118 -0
- package/src/telemetry/incomingTrace.ts +47 -0
- package/src/telemetry/index.ts +5 -0
- package/src/telemetry/sqlSpans.ts +76 -0
- package/src/tenant/TenantApiMiddlewareFactory.ts +14 -14
- package/src/testing/TestTransactions.ts +21 -11
- package/src/tsconfig.json +1 -0
- package/src/utils/remoteAddress.ts +9 -2
- package/src/utils/sentry.ts +5 -0
- package/src/utils/serverTermination.ts +41 -3
- package/src/utils/truthyHeader.ts +12 -0
- package/tests/cases/integration/requestMemoryBudget.test.ts +88 -0
- package/tests/cases/unit/applicationShutdown.test.ts +149 -0
- package/tests/cases/unit/contentApiSpecificCache.tst.js +22 -0
- package/tests/cases/unit/contentApiSpecificCacheLimit.test.ts +63 -0
- package/tests/cases/unit/forcePrimary.test.ts +295 -0
- package/tests/cases/unit/graphQlSchemaFactory.test.ts +87 -0
- package/tests/cases/unit/incomingTrace.test.ts +100 -0
- package/tests/cases/unit/remoteAddress.test.ts +13 -1
- package/tests/cases/unit/requestMemoryBudget.test.ts +172 -0
- package/tests/cases/unit/requestTracing.test.ts +224 -0
- package/tests/cases/unit/serverConfig.test.ts +35 -0
- package/tests/cases/unit/serverTermination.fixture.ts +13 -0
- package/tests/cases/unit/serverTermination.test.ts +97 -0
- package/tests/cases/unit/spanFiltering.test.ts +71 -0
- package/tests/cases/unit/sqlSpans.test.ts +198 -0
- package/tests/cases/unit/telemetryConfig.test.ts +186 -0
- package/tests/cases/unit/timerFacade.test.ts +78 -0
|
@@ -77,20 +77,20 @@ export class Authenticator {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
public async authenticate(
|
|
80
|
-
{ request, timer, clientIp }: {
|
|
80
|
+
{ request, timer, clientIp, fallbackIdentity }: {
|
|
81
|
+
request: IncomingMessage
|
|
82
|
+
timer: Timer
|
|
83
|
+
clientIp?: string
|
|
84
|
+
/**
|
|
85
|
+
* Identity to act as when the request carries no Authorization header. Lets a first-party UI
|
|
86
|
+
* served by this process reach a pre-sign-in surface without a token existing anywhere to be
|
|
87
|
+
* leaked or misconfigured — the roles come from the caller, not from the database. An actual
|
|
88
|
+
* Authorization header always wins, so this can never widen a credentialed request.
|
|
89
|
+
*/
|
|
90
|
+
fallbackIdentity?: VerifyResult
|
|
91
|
+
},
|
|
81
92
|
): Promise<AuthResult | null> {
|
|
82
|
-
const authHeader = request.headers.authorization
|
|
83
|
-
if (!authHeader) {
|
|
84
|
-
return null
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const authHeaderPattern = /^Bearer\s+(\w+)$/i
|
|
88
|
-
|
|
89
|
-
const match = authHeader.match(authHeaderPattern)
|
|
90
|
-
if (match === null) {
|
|
91
|
-
throw this.createAuthError(`invalid Authorization header format`)
|
|
92
|
-
}
|
|
93
|
-
const [, token] = match
|
|
93
|
+
const authHeader = request.headers.authorization || undefined
|
|
94
94
|
const socketIp = sanitizeIp(clientIp)
|
|
95
95
|
const socketUserAgent = sanitizeUserAgent(readHeader(request, 'user-agent'))
|
|
96
96
|
const forwardedIp = sanitizeIp(readHeader(request, forwardedClientIpHeader))
|
|
@@ -104,18 +104,17 @@ export class Authenticator {
|
|
|
104
104
|
const forwardedInfo = (forwardedIp !== undefined || forwardedUserAgent !== undefined)
|
|
105
105
|
? { ip: forwardedIp, userAgent: forwardedUserAgent }
|
|
106
106
|
: undefined
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
)
|
|
111
|
-
|
|
112
|
-
throw this.createAuthError(authResult.errorMessage)
|
|
107
|
+
const verified = authHeader !== undefined
|
|
108
|
+
? await this.verifyAuthorizationHeader(authHeader, timer, socketInfo, forwardedInfo)
|
|
109
|
+
: fallbackIdentity
|
|
110
|
+
if (verified === undefined) {
|
|
111
|
+
return null
|
|
113
112
|
}
|
|
114
113
|
const assumedIdentityId = request.headers[assumeIdentityHeader] ?? undefined
|
|
115
114
|
if (Array.isArray(assumedIdentityId)) {
|
|
116
115
|
throw new HttpErrorResponse(400, `Invalid ${assumedIdentityId} header format`)
|
|
117
116
|
}
|
|
118
|
-
const trustForwarded =
|
|
117
|
+
const trustForwarded = verified.trustForwardedInfo && forwardedInfo !== undefined
|
|
119
118
|
// A03: the geo country is only ever exposed under the exact same gate as the
|
|
120
119
|
// forwarded IP/UA — a trusted key that actually forwarded client info. This
|
|
121
120
|
// keeps the signals consistent: we never score a real client country against
|
|
@@ -124,7 +123,7 @@ export class Authenticator {
|
|
|
124
123
|
// yields no country.
|
|
125
124
|
const trustGeo = trustForwarded && forwardedGeoCountry !== undefined
|
|
126
125
|
return {
|
|
127
|
-
...
|
|
126
|
+
...verified,
|
|
128
127
|
assumedIdentityId,
|
|
129
128
|
clientIp: trustForwarded ? (forwardedInfo?.ip ?? socketIp) : socketIp,
|
|
130
129
|
clientUserAgent: trustForwarded ? (forwardedInfo?.userAgent ?? socketUserAgent) : socketUserAgent,
|
|
@@ -133,4 +132,25 @@ export class Authenticator {
|
|
|
133
132
|
geoCountry: trustGeo ? forwardedGeoCountry : undefined,
|
|
134
133
|
}
|
|
135
134
|
}
|
|
135
|
+
|
|
136
|
+
private async verifyAuthorizationHeader(
|
|
137
|
+
authHeader: string,
|
|
138
|
+
timer: Timer,
|
|
139
|
+
socketInfo: { ip?: string; userAgent?: string },
|
|
140
|
+
forwardedInfo: { ip?: string; userAgent?: string } | undefined,
|
|
141
|
+
): Promise<VerifyResult> {
|
|
142
|
+
const match = authHeader.match(/^Bearer\s+(\w+)$/i)
|
|
143
|
+
if (match === null) {
|
|
144
|
+
throw this.createAuthError(`invalid Authorization header format`)
|
|
145
|
+
}
|
|
146
|
+
const [, token] = match
|
|
147
|
+
const authResult = await timer(
|
|
148
|
+
'Auth',
|
|
149
|
+
() => this.apiKeyManager.verifyAndProlong(this.tenantDatabase, this.tenantReadDatabase, token, socketInfo, forwardedInfo),
|
|
150
|
+
)
|
|
151
|
+
if (!authResult.ok) {
|
|
152
|
+
throw this.createAuthError(authResult.errorMessage)
|
|
153
|
+
}
|
|
154
|
+
return authResult.result
|
|
155
|
+
}
|
|
136
156
|
}
|
|
@@ -3,6 +3,8 @@ export class HttpResponse {
|
|
|
3
3
|
public readonly code: number,
|
|
4
4
|
public readonly body?: string,
|
|
5
5
|
public readonly contentType?: string,
|
|
6
|
+
/** Extra response headers. Use for signals a client must act on, since an error body is not always readable. */
|
|
7
|
+
public readonly headers?: Readonly<Record<string, string>>,
|
|
6
8
|
) {
|
|
7
9
|
}
|
|
8
10
|
}
|
|
@@ -11,11 +13,13 @@ export class HttpErrorResponse extends HttpResponse {
|
|
|
11
13
|
constructor(
|
|
12
14
|
code: number,
|
|
13
15
|
public readonly message?: string,
|
|
16
|
+
headers?: Readonly<Record<string, string>>,
|
|
14
17
|
) {
|
|
15
18
|
super(
|
|
16
19
|
code,
|
|
17
20
|
message ? JSON.stringify({ errors: [{ code, message }] }) : undefined,
|
|
18
21
|
'application/json',
|
|
22
|
+
headers,
|
|
19
23
|
)
|
|
20
24
|
}
|
|
21
25
|
}
|
package/src/common/index.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export * from './Authorizator.js'
|
|
2
|
+
/** Re-exported so a first-party UI package can build the pre-sign-in caller without depending on the tenant API. */
|
|
3
|
+
export { createUnpersistedLoginVerifyResult } from '@contember/engine-tenant-api'
|
|
2
4
|
export * from './HttpResponse.js'
|
|
3
5
|
export * from './ModuleInfoMiddleware.js'
|
|
4
6
|
export * from './NotFoundMiddleware.js'
|
package/src/config/config.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ConfigLoader, createObjectParametersResolver, Merger, resolveParameters } from '@contember/config-loader'
|
|
2
2
|
|
|
3
|
-
import { serverConfigSchema as defaultServerConfigSchema, tenantConfigSchema } from './configSchema.js'
|
|
3
|
+
import { serverConfigSchema as defaultServerConfigSchema, telemetryConfigSchema, tenantConfigSchema } from './configSchema.js'
|
|
4
4
|
import { configTemplate } from './configTemplate.js'
|
|
5
5
|
import { createProjectConfigResolver, ProjectConfigResolver } from './projectConfigResolver.js'
|
|
6
6
|
import { createTenantConfigResolver, TenantConfigResolver } from './tenantConfigResolver.js'
|
|
@@ -9,6 +9,7 @@ import { ConfigProcessor } from './ConfigProcessor.js'
|
|
|
9
9
|
|
|
10
10
|
export type ServerConfig = ReturnType<typeof defaultServerConfigSchema>
|
|
11
11
|
export type TenantConfig = ReturnType<typeof tenantConfigSchema>
|
|
12
|
+
export type TelemetryConfig = ReturnType<typeof telemetryConfigSchema>
|
|
12
13
|
|
|
13
14
|
export type ConfigSource = { data: string; type: 'file' | 'json' | 'yaml' }
|
|
14
15
|
|
|
@@ -22,6 +23,7 @@ export async function readConfig<T extends ServerConfig>(
|
|
|
22
23
|
serverConfig: T
|
|
23
24
|
projectConfigResolver: ProjectConfigResolver
|
|
24
25
|
tenantConfigResolver: TenantConfigResolver
|
|
26
|
+
env: Env
|
|
25
27
|
}> {
|
|
26
28
|
const loader = new ConfigLoader()
|
|
27
29
|
const configs = await Promise.all(
|
|
@@ -49,5 +51,6 @@ export async function readConfig<T extends ServerConfig>(
|
|
|
49
51
|
serverConfig,
|
|
50
52
|
projectConfigResolver: createProjectConfigResolver(env, rawConfig, configProcessors),
|
|
51
53
|
tenantConfigResolver: createTenantConfigResolver(env, rawConfig.tenant),
|
|
54
|
+
env,
|
|
52
55
|
}
|
|
53
56
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as Typesafe from '@contember/typesafe'
|
|
2
2
|
import { MailerOptions } from '@contember/engine-tenant-api'
|
|
3
|
+
import { validateRequestMemoryBudgetOptions } from '@contember/database'
|
|
3
4
|
import { upperCaseFirst } from '../utils/strings.js'
|
|
4
5
|
import ipaddr from 'ipaddr.js'
|
|
5
6
|
|
|
@@ -16,6 +17,8 @@ const dbConfigOptional = {
|
|
|
16
17
|
statementTimeoutMs: Typesafe.number,
|
|
17
18
|
lockTimeoutMs: Typesafe.number,
|
|
18
19
|
connectionTimeoutMs: Typesafe.number,
|
|
20
|
+
keepAlive: Typesafe.boolean,
|
|
21
|
+
keepAliveInitialDelayMs: Typesafe.number,
|
|
19
22
|
maxConnectionsPerRequest: Typesafe.number,
|
|
20
23
|
pool: Typesafe.partial({
|
|
21
24
|
maxConnections: Typesafe.number,
|
|
@@ -103,9 +106,60 @@ export const tenantConfigSchema = Typesafe.intersection(
|
|
|
103
106
|
}),
|
|
104
107
|
)
|
|
105
108
|
|
|
109
|
+
const positiveInteger: Typesafe.Type<number> = (input, path = []) => {
|
|
110
|
+
const value = Typesafe.integer(input, path)
|
|
111
|
+
return value > 0 ? value : Typesafe.fail(path, 'must be a positive integer')
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export const telemetryConfigSchema = Typesafe.partial({
|
|
115
|
+
resource: Typesafe.partial({
|
|
116
|
+
serviceName: Typesafe.string,
|
|
117
|
+
attributes: Typesafe.record(Typesafe.string, Typesafe.string),
|
|
118
|
+
}),
|
|
119
|
+
traces: Typesafe.partial({
|
|
120
|
+
enabled: Typesafe.boolean,
|
|
121
|
+
exporter: Typesafe.partial({
|
|
122
|
+
type: Typesafe.enumeration('otlp-http', 'console'),
|
|
123
|
+
endpoint: Typesafe.string,
|
|
124
|
+
headers: Typesafe.record(Typesafe.string, Typesafe.string),
|
|
125
|
+
timeoutMs: Typesafe.number,
|
|
126
|
+
}),
|
|
127
|
+
sampler: Typesafe.enumeration('always', 'never', 'ratio', 'parentRatio'),
|
|
128
|
+
samplerRatio: Typesafe.number,
|
|
129
|
+
// Whether a client-supplied traceparent may become the parent of the request span.
|
|
130
|
+
acceptIncoming: Typesafe.enumeration('none', 'trusted-proxies', 'all'),
|
|
131
|
+
// Whether outgoing Actions webhooks carry a traceparent header. Enabled when absent.
|
|
132
|
+
propagateToWebhooks: Typesafe.boolean,
|
|
133
|
+
traceIdResponseHeader: Typesafe.boolean,
|
|
134
|
+
maxSpansPerRequest: Typesafe.number,
|
|
135
|
+
sql: Typesafe.partial({
|
|
136
|
+
enabled: Typesafe.boolean,
|
|
137
|
+
includeQueryText: Typesafe.boolean,
|
|
138
|
+
minDurationMs: Typesafe.number,
|
|
139
|
+
}),
|
|
140
|
+
batch: Typesafe.partial({
|
|
141
|
+
maxQueueSize: positiveInteger,
|
|
142
|
+
maxBatchSize: positiveInteger,
|
|
143
|
+
delayMs: positiveInteger,
|
|
144
|
+
}),
|
|
145
|
+
}),
|
|
146
|
+
})
|
|
147
|
+
|
|
106
148
|
export const serverConfigSchema = Typesafe.partial({
|
|
107
149
|
port: Typesafe.number,
|
|
108
150
|
http: Typesafe.partial({
|
|
151
|
+
// Both thresholds come from separate environment variables, so an empty object means "disabled".
|
|
152
|
+
requestMemoryBudget: (input: unknown, path: PropertyKey[] = []): { warnBytes: number; maxBytes: number } | undefined => {
|
|
153
|
+
const { warnBytes, maxBytes } = Typesafe.partial({ warnBytes: Typesafe.integer, maxBytes: Typesafe.integer })(input, path)
|
|
154
|
+
if (warnBytes === undefined && maxBytes === undefined) {
|
|
155
|
+
return undefined
|
|
156
|
+
}
|
|
157
|
+
if (warnBytes === undefined || maxBytes === undefined) {
|
|
158
|
+
return Typesafe.fail(path, 'warnBytes and maxBytes must be set together')
|
|
159
|
+
}
|
|
160
|
+
const optionsError = validateRequestMemoryBudgetOptions({ warnBytes, maxBytes })
|
|
161
|
+
return optionsError ? Typesafe.fail(path, optionsError) : { warnBytes, maxBytes }
|
|
162
|
+
},
|
|
109
163
|
requestBodySize: Typesafe.string,
|
|
110
164
|
// Allows clients to opt in (via the X-Contember-Force-Ok request header) to receiving HTTP 200
|
|
111
165
|
// for GraphQL API responses, keeping error info in the JSON body. Defaults to enabled; set to
|
|
@@ -181,6 +235,14 @@ export const serverConfigSchema = Typesafe.partial({
|
|
|
181
235
|
}),
|
|
182
236
|
contentApi: Typesafe.partial({
|
|
183
237
|
schemaCacheTtlSeconds: Typesafe.integer,
|
|
238
|
+
schemaCacheMaxEntries: (input: unknown, path: PropertyKey[] = []): number | undefined => {
|
|
239
|
+
if (input === undefined) {
|
|
240
|
+
return undefined
|
|
241
|
+
}
|
|
242
|
+
const maxEntries = Typesafe.integer(input, path)
|
|
243
|
+
return maxEntries > 0 ? maxEntries : Typesafe.fail(path, 'must be a positive integer')
|
|
244
|
+
},
|
|
245
|
+
forcePrimaryHeader: Typesafe.boolean,
|
|
184
246
|
whereOptimizer: Typesafe.partial({
|
|
185
247
|
disable: Typesafe.boolean,
|
|
186
248
|
maxCrossOptimizationInput: Typesafe.number,
|
|
@@ -194,6 +256,7 @@ export const serverConfigSchema = Typesafe.partial({
|
|
|
194
256
|
}),
|
|
195
257
|
}),
|
|
196
258
|
),
|
|
259
|
+
telemetry: telemetryConfigSchema,
|
|
197
260
|
projectGroup: (val: unknown, path: PropertyKey[] = []) =>
|
|
198
261
|
Typesafe.valueAt(val, ['domainMapping']) === undefined
|
|
199
262
|
? undefined
|
|
@@ -206,9 +269,18 @@ export const serverConfigSchema = Typesafe.partial({
|
|
|
206
269
|
configEncryptionKey: Typesafe.string,
|
|
207
270
|
}),
|
|
208
271
|
)(val, path),
|
|
272
|
+
// Management panel served by the engine (@contember/engine-panel). Off by default: the API port is
|
|
273
|
+
// often public, so a login page appears only when an operator asks for it. `path` is the mount
|
|
274
|
+
// point, e.g. "/panel"; the panel's API lives directly under it.
|
|
275
|
+
panel: Typesafe.partial({
|
|
276
|
+
enabled: Typesafe.boolean,
|
|
277
|
+
path: Typesafe.string,
|
|
278
|
+
}),
|
|
209
279
|
monitoringPort: Typesafe.number,
|
|
210
280
|
workerCount: Typesafe.union(Typesafe.number, Typesafe.string),
|
|
211
281
|
applicationWorker: Typesafe.string,
|
|
282
|
+
// How long the engine keeps serving after SIGTERM before it shuts down; unset means at once.
|
|
283
|
+
shutdownDelayMs: Typesafe.number,
|
|
212
284
|
test: Typesafe.partial({
|
|
213
285
|
transactions: Typesafe.boolean,
|
|
214
286
|
transactionTtlSeconds: Typesafe.number,
|
|
@@ -5,6 +5,8 @@ const createDbConfigTemplate = (prefix: string) => {
|
|
|
5
5
|
statementTimeoutMs: `%?${prefix}_STATEMENT_TIMEOUT_MS::number%`,
|
|
6
6
|
lockTimeoutMs: `%?${prefix}_LOCK_TIMEOUT_MS::number%`,
|
|
7
7
|
connectionTimeoutMs: `%?${prefix}_CONNECTION_TIMEOUT_MS::number%`,
|
|
8
|
+
keepAlive: `%?${prefix}_KEEP_ALIVE::bool%`,
|
|
9
|
+
keepAliveInitialDelayMs: `%?${prefix}_KEEP_ALIVE_INITIAL_DELAY_MS::number%`,
|
|
8
10
|
maxConnectionsPerRequest: `%?${prefix}_MAX_CONNECTIONS_PER_REQUEST::number%`,
|
|
9
11
|
pool: {
|
|
10
12
|
maxConnections: `%?${prefix}_POOL_MAX_CONNECTIONS::number%`,
|
|
@@ -85,15 +87,26 @@ export const configTemplate: any = {
|
|
|
85
87
|
monitoringPort: '%?env.CONTEMBER_MONITORING_PORT::number%',
|
|
86
88
|
workerCount: '%?env.CONTEMBER_WORKER_COUNT::string%',
|
|
87
89
|
applicationWorker: '%?env.CONTEMBER_APPLICATION_WORKER::string%',
|
|
90
|
+
shutdownDelayMs: '%?env.CONTEMBER_SHUTDOWN_DELAY_MS::number%',
|
|
88
91
|
http: {
|
|
89
92
|
requestBodySize: '%?env.CONTEMBER_HTTP_REQUEST_BODY_SIZE::string%',
|
|
90
93
|
suppressAccessLog: '%?env.CONTEMBER_HTTP_SUPPRESS_ACCESS_LOG::string%',
|
|
91
94
|
trustedProxies: '%?env.CONTEMBER_HTTP_TRUSTED_PROXIES::string%',
|
|
92
95
|
responseStatusHeader: '%?env.CONTEMBER_HTTP_RESPONSE_STATUS_HEADER::string%',
|
|
93
96
|
geoCountryHeader: '%?env.CONTEMBER_HTTP_GEO_COUNTRY_HEADER::string%',
|
|
97
|
+
requestMemoryBudget: {
|
|
98
|
+
warnBytes: '%?env.CONTEMBER_HTTP_REQUEST_MEMORY_BUDGET_WARN_BYTES::number%',
|
|
99
|
+
maxBytes: '%?env.CONTEMBER_HTTP_REQUEST_MEMORY_BUDGET_MAX_BYTES::number%',
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
panel: {
|
|
103
|
+
enabled: '%?env.CONTEMBER_PANEL_ENABLED::bool%',
|
|
104
|
+
path: '%?env.CONTEMBER_PANEL_PATH%',
|
|
94
105
|
},
|
|
95
106
|
contentApi: {
|
|
96
107
|
schemaCacheTtlSeconds: '%?env.CONTEMBER_CONTENT_API_SCHEMA_CACHE_TTL_SECONDS::number%',
|
|
108
|
+
schemaCacheMaxEntries: '%?env.CONTEMBER_CONTENT_API_SCHEMA_CACHE_MAX_ENTRIES::number%',
|
|
109
|
+
forcePrimaryHeader: '%?env.CONTEMBER_CONTENT_API_FORCE_PRIMARY_HEADER::bool%',
|
|
97
110
|
whereOptimizer: {
|
|
98
111
|
disable: '%?env.CONTEMBER_CONTENT_API_WHERE_OPTIMIZER_DISABLE::bool%',
|
|
99
112
|
maxCrossOptimizationInput: '%?env.CONTEMBER_CONTENT_API_MAX_CROSS_OPTIMIZATION_INPUT::number%',
|
|
@@ -109,6 +122,27 @@ export const configTemplate: any = {
|
|
|
109
122
|
dsn: '%?env.SENTRY_DSN%',
|
|
110
123
|
},
|
|
111
124
|
},
|
|
125
|
+
telemetry: {
|
|
126
|
+
traces: {
|
|
127
|
+
enabled: '%?env.CONTEMBER_TELEMETRY_TRACES_ENABLED::bool%',
|
|
128
|
+
exporter: {
|
|
129
|
+
type: '%?env.CONTEMBER_TELEMETRY_EXPORTER_TYPE%',
|
|
130
|
+
endpoint: '%?env.CONTEMBER_TELEMETRY_OTLP_ENDPOINT%',
|
|
131
|
+
timeoutMs: '%?env.CONTEMBER_TELEMETRY_OTLP_TIMEOUT_MS::number%',
|
|
132
|
+
},
|
|
133
|
+
sampler: '%?env.CONTEMBER_TELEMETRY_SAMPLER%',
|
|
134
|
+
samplerRatio: '%?env.CONTEMBER_TELEMETRY_SAMPLER_RATIO::number%',
|
|
135
|
+
acceptIncoming: '%?env.CONTEMBER_TELEMETRY_ACCEPT_INCOMING%',
|
|
136
|
+
propagateToWebhooks: '%?env.CONTEMBER_TELEMETRY_PROPAGATE_TO_WEBHOOKS::bool%',
|
|
137
|
+
traceIdResponseHeader: '%?env.CONTEMBER_TELEMETRY_TRACE_ID_RESPONSE_HEADER::bool%',
|
|
138
|
+
maxSpansPerRequest: '%?env.CONTEMBER_TELEMETRY_MAX_SPANS_PER_REQUEST::number%',
|
|
139
|
+
sql: {
|
|
140
|
+
enabled: '%?env.CONTEMBER_TELEMETRY_SQL_ENABLED::bool%',
|
|
141
|
+
includeQueryText: '%?env.CONTEMBER_TELEMETRY_SQL_INCLUDE_QUERY_TEXT::bool%',
|
|
142
|
+
minDurationMs: '%?env.CONTEMBER_TELEMETRY_SQL_MIN_DURATION_MS::number%',
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
},
|
|
112
146
|
test: {
|
|
113
147
|
transactions: '%?env.CONTEMBER_TEST_TRANSACTIONS::bool%',
|
|
114
148
|
transactionTtlSeconds: '%?env.CONTEMBER_TEST_TRANSACTION_TTL_SECONDS::number%',
|
|
@@ -77,7 +77,7 @@ const createProjectParametersResolver = (slug: string, env: Env, secrets: Projec
|
|
|
77
77
|
throw new UndefinedParameterError(`Parameter "${parts.join('.')}" not found.`)
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
const projectNameToEnvName = (projectName: string): string => {
|
|
80
|
+
export const projectNameToEnvName = (projectName: string): string => {
|
|
81
81
|
const envName = projectName.toUpperCase().replace(/-/g, '_')
|
|
82
82
|
if (envName === 'TENANT') {
|
|
83
83
|
throw new Error('Forbidden project name')
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createAclVariables, ExecutionContainerFactory } from '@contember/engine-content-api'
|
|
2
2
|
import { StageBySlugQuery } from '@contember/engine-system-api'
|
|
3
|
-
import { Client } from '@contember/database'
|
|
3
|
+
import { Client, RequestMemoryBudget, RequestMemoryBudgetOptions } from '@contember/database'
|
|
4
4
|
import { GraphQLSchema } from 'graphql'
|
|
5
5
|
import { HttpController } from '../application/index.js'
|
|
6
6
|
import { HttpErrorResponse, HttpResponse } from '../common/index.js'
|
|
@@ -10,9 +10,11 @@ import { ContentQueryHandler, ContentQueryHandlerFactory } from './ContentQueryH
|
|
|
10
10
|
import { GraphQlSchemaFactory } from './GraphQlSchemaFactory.js'
|
|
11
11
|
import { NotModifiedChecker } from './NotModifiedChecker.js'
|
|
12
12
|
import { TestTransactionService } from '../testing/index.js'
|
|
13
|
+
import { isTruthyHeader } from '../utils/truthyHeader.js'
|
|
13
14
|
|
|
14
15
|
const debugHeader = 'x-contember-debug'
|
|
15
16
|
const testSessionHeader = 'x-contember-test-session'
|
|
17
|
+
const forcePrimaryHeader = 'x-contember-force-primary'
|
|
16
18
|
|
|
17
19
|
export class ContentApiControllerFactory {
|
|
18
20
|
constructor(
|
|
@@ -22,6 +24,8 @@ export class ContentApiControllerFactory {
|
|
|
22
24
|
private readonly projectContextResolver: ProjectContextResolver,
|
|
23
25
|
private readonly graphQlSchemaFactory: GraphQlSchemaFactory,
|
|
24
26
|
private readonly testTransactionService: TestTransactionService,
|
|
27
|
+
private readonly forcePrimaryHeaderEnabled: boolean,
|
|
28
|
+
private readonly memoryBudgetOptions?: RequestMemoryBudgetOptions,
|
|
25
29
|
) {
|
|
26
30
|
}
|
|
27
31
|
|
|
@@ -38,7 +42,10 @@ export class ContentApiControllerFactory {
|
|
|
38
42
|
project: project.slug,
|
|
39
43
|
})
|
|
40
44
|
|
|
41
|
-
const
|
|
45
|
+
const forcePrimary = this.forcePrimaryHeaderEnabled && isTruthyHeader(request, forcePrimaryHeader)
|
|
46
|
+
// Without a replica, forced reads change nothing, so clients need not open a window.
|
|
47
|
+
const markMutations = this.forcePrimaryHeaderEnabled && projectContainer.readConnection !== projectContainer.connection
|
|
48
|
+
const systemDatabase = forcePrimary ? projectContainer.systemDatabaseContext : projectContainer.systemReadDatabaseContext
|
|
42
49
|
const stage = await systemDatabase.queryHandler.fetch(new StageBySlugQuery(params.stageSlug))
|
|
43
50
|
if (!stage) {
|
|
44
51
|
return new HttpErrorResponse(404, `Stage ${params.stageSlug} NOT found`)
|
|
@@ -132,12 +139,16 @@ export class ContentApiControllerFactory {
|
|
|
132
139
|
handler({
|
|
133
140
|
request: koa.request,
|
|
134
141
|
response: koa.response,
|
|
135
|
-
createContext: ({ operation }) => {
|
|
142
|
+
createContext: ({ operation, queryHash }) => {
|
|
143
|
+
// Clients open a primary read window only on this marker, so it must not be sent while the header is ignored.
|
|
144
|
+
if (operation === 'mutation' && markMutations) {
|
|
145
|
+
koa.response.set('X-Contember-Mutation', '1')
|
|
146
|
+
}
|
|
136
147
|
;(koa.state as GraphQLKoaState).graphql = {
|
|
137
148
|
operationName: operation,
|
|
138
149
|
}
|
|
139
150
|
|
|
140
|
-
const baseConnection = operation === 'query' ? projectContainer.readConnection : projectContainer.connection
|
|
151
|
+
const baseConnection = operation === 'query' && !forcePrimary ? projectContainer.readConnection : projectContainer.connection
|
|
141
152
|
const maxConnectionsPerRequest = 'maxConnectionsPerRequest' in project.db
|
|
142
153
|
? project.db.maxConnectionsPerRequest
|
|
143
154
|
: undefined
|
|
@@ -146,7 +157,22 @@ export class ContentApiControllerFactory {
|
|
|
146
157
|
const connection = maxConnectionsPerRequest !== undefined
|
|
147
158
|
? baseConnection.withMaxConnections(maxConnectionsPerRequest)
|
|
148
159
|
: baseConnection
|
|
160
|
+
const memoryBudget = this.memoryBudgetOptions
|
|
161
|
+
? new RequestMemoryBudget(this.memoryBudgetOptions)
|
|
162
|
+
: undefined
|
|
149
163
|
const contentDatabase = testContentDatabase ?? connection.createClient(stage.schema, { module: 'content' })
|
|
164
|
+
if (memoryBudget) {
|
|
165
|
+
const logMemory = () => {
|
|
166
|
+
koa.res.off('finish', logMemory)
|
|
167
|
+
koa.res.off('close', logMemory)
|
|
168
|
+
const memory = memoryBudget.snapshot()
|
|
169
|
+
if (memory.warningThresholdExceeded) {
|
|
170
|
+
logger.warn('Content request memory usage', { operation, queryHash, ...memory })
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
koa.res.once('finish', logMemory)
|
|
174
|
+
koa.res.once('close', logMemory)
|
|
175
|
+
}
|
|
150
176
|
|
|
151
177
|
const identityVariables = createAclVariables(schema.acl, memberships)
|
|
152
178
|
let identityId = authResult.identityId
|
|
@@ -159,6 +185,7 @@ export class ContentApiControllerFactory {
|
|
|
159
185
|
|
|
160
186
|
const executionContainer = this.executionContainerFactory.create({
|
|
161
187
|
db: contentDatabase,
|
|
188
|
+
memoryBudget,
|
|
162
189
|
identityVariables,
|
|
163
190
|
identityId,
|
|
164
191
|
schema,
|
|
@@ -177,6 +204,7 @@ export class ContentApiControllerFactory {
|
|
|
177
204
|
|
|
178
205
|
return {
|
|
179
206
|
db: contentDatabase,
|
|
207
|
+
memoryBudget,
|
|
180
208
|
identityVariables,
|
|
181
209
|
identityId,
|
|
182
210
|
executionContainer,
|
|
@@ -1,16 +1,28 @@
|
|
|
1
1
|
import { clearTimeout } from 'node:timers'
|
|
2
2
|
|
|
3
|
+
type RecencyToken<V> = {
|
|
4
|
+
// weak, so the recency order keeps neither the Map nor its ObjectKey alive
|
|
5
|
+
cacheMapRef: WeakRef<Map<string, Entry<V>>>
|
|
6
|
+
scalarKey: string
|
|
7
|
+
}
|
|
8
|
+
|
|
3
9
|
type Entry<V> = {
|
|
4
10
|
timer?: ReturnType<typeof setTimeout>
|
|
5
11
|
value: V
|
|
12
|
+
recency: RecencyToken<V>
|
|
6
13
|
}
|
|
7
14
|
|
|
8
15
|
export class ContentApiSpecificCache<ObjectKey extends object, Value> {
|
|
9
16
|
private cache = new WeakMap<ObjectKey, Map<string, Entry<Value>>>()
|
|
10
17
|
|
|
18
|
+
// Least recently used first, tracked only with maxEntries: nothing else removes a token whose Map was garbage-collected.
|
|
19
|
+
// With maxEntries, such a token stays counted until it is evicted as the oldest.
|
|
20
|
+
private recency = new Set<RecencyToken<Value>>()
|
|
21
|
+
|
|
11
22
|
constructor(
|
|
12
23
|
private options: {
|
|
13
24
|
ttlSeconds?: number
|
|
25
|
+
maxEntries?: number
|
|
14
26
|
},
|
|
15
27
|
) {
|
|
16
28
|
}
|
|
@@ -24,28 +36,55 @@ export class ContentApiSpecificCache<ObjectKey extends object, Value> {
|
|
|
24
36
|
}
|
|
25
37
|
|
|
26
38
|
const cacheValue = cacheMap.get(scalarKey)
|
|
39
|
+
if (cacheValue) {
|
|
40
|
+
this.markUsed(cacheValue)
|
|
41
|
+
return cacheValue.value
|
|
42
|
+
}
|
|
27
43
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const cacheMapRef = new WeakRef(cacheMap)
|
|
32
|
-
timer = setTimeout(() => {
|
|
33
|
-
cacheMapRef.deref()?.delete(scalarKey)
|
|
34
|
-
}, this.options.ttlSeconds * 1000)
|
|
44
|
+
const entry: Entry<Value> = {
|
|
45
|
+
value: createValue(),
|
|
46
|
+
recency: { cacheMapRef: new WeakRef(cacheMap), scalarKey },
|
|
35
47
|
}
|
|
48
|
+
cacheMap.set(scalarKey, entry)
|
|
49
|
+
this.markUsed(entry)
|
|
50
|
+
this.evictOverLimit()
|
|
36
51
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
52
|
+
return entry.value
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
private markUsed(entry: Entry<Value>): void {
|
|
56
|
+
clearTimeout(entry.timer)
|
|
57
|
+
if (this.options.ttlSeconds) {
|
|
58
|
+
const token = entry.recency
|
|
59
|
+
entry.timer = setTimeout(() => this.remove(token), this.options.ttlSeconds * 1000)
|
|
41
60
|
}
|
|
61
|
+
if (this.options.maxEntries) {
|
|
62
|
+
this.recency.delete(entry.recency)
|
|
63
|
+
this.recency.add(entry.recency)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
42
66
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
67
|
+
private evictOverLimit(): void {
|
|
68
|
+
const maxEntries = this.options.maxEntries
|
|
69
|
+
if (!maxEntries) {
|
|
70
|
+
return
|
|
71
|
+
}
|
|
72
|
+
for (const token of this.recency) {
|
|
73
|
+
if (this.recency.size <= maxEntries) {
|
|
74
|
+
return
|
|
75
|
+
}
|
|
76
|
+
this.remove(token)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
48
79
|
|
|
49
|
-
|
|
80
|
+
private remove(token: RecencyToken<Value>): void {
|
|
81
|
+
this.recency.delete(token)
|
|
82
|
+
const cacheMap = token.cacheMapRef.deref()
|
|
83
|
+
const entry = cacheMap?.get(token.scalarKey)
|
|
84
|
+
if (!cacheMap || entry?.recency !== token) {
|
|
85
|
+
return
|
|
86
|
+
}
|
|
87
|
+
clearTimeout(entry.timer)
|
|
88
|
+
cacheMap.delete(token.scalarKey)
|
|
50
89
|
}
|
|
51
90
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Context } from '@contember/engine-content-api'
|
|
2
|
+
import { RequestMemoryBudget } from '@contember/database'
|
|
2
3
|
|
|
3
4
|
export type ContentGraphqlContext = Context & {
|
|
4
5
|
identityId: string
|
|
5
6
|
requestDebug: boolean
|
|
6
7
|
project: { slug: string }
|
|
8
|
+
memoryBudget?: RequestMemoryBudget
|
|
7
9
|
}
|
|
@@ -10,6 +10,10 @@ export type GraphQLSchemaContributorContext = {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export interface GraphQLSchemaContributor {
|
|
13
|
+
/**
|
|
14
|
+
* Must change whenever the output of createSchema can change, including everything it derives from the identity.
|
|
15
|
+
* The cache does not key the GraphQL schema by roles; role combinations with identical content permissions share it.
|
|
16
|
+
*/
|
|
13
17
|
getCacheKey?: (context: GraphQLSchemaContributorContext) => string
|
|
14
18
|
createSchema(context: GraphQLSchemaContributorContext): undefined | GraphQLSchema | GraphQLSchemaConfig
|
|
15
19
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Authorizator,
|
|
3
3
|
Context,
|
|
4
|
+
ContextualPermissions,
|
|
4
5
|
EntityRulesResolver,
|
|
5
6
|
GraphQlSchemaBuilderFactory,
|
|
6
7
|
IntrospectionSchemaDefinitionFactory,
|
|
@@ -9,6 +10,7 @@ import {
|
|
|
9
10
|
} from '@contember/engine-content-api'
|
|
10
11
|
import { Acl, Schema } from '@contember/schema'
|
|
11
12
|
import { GraphQLFieldConfig, GraphQLNamedType, GraphQLSchema } from 'graphql'
|
|
13
|
+
import { createHash } from 'node:crypto'
|
|
12
14
|
import { GraphQLSchemaContributor } from './GraphQLSchemaContributor.js'
|
|
13
15
|
import { Identity } from './Identity.js'
|
|
14
16
|
import { ContentApiSpecificCache } from './ContentApiSpecificCache.js'
|
|
@@ -21,6 +23,8 @@ export interface GraphQLSchemaFactoryResult {
|
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
export class GraphQlSchemaFactory {
|
|
26
|
+
private readonly permissionsKeys = new WeakMap<Schema, Map<string, string>>()
|
|
27
|
+
|
|
24
28
|
constructor(
|
|
25
29
|
private readonly cache: ContentApiSpecificCache<Schema, GraphQLSchemaFactoryResult>,
|
|
26
30
|
private readonly graphqlSchemaBuilderFactory: GraphQlSchemaBuilderFactory,
|
|
@@ -29,12 +33,12 @@ export class GraphQlSchemaFactory {
|
|
|
29
33
|
) {}
|
|
30
34
|
|
|
31
35
|
public create(schema: Schema, identity: Identity, project: ProjectConfig): GraphQLSchemaFactoryResult {
|
|
32
|
-
const
|
|
36
|
+
const { permissionsKey, computedPermissions } = this.getPermissionsKey(schema, identity.projectRoles)
|
|
33
37
|
const contributorsKey = this.schemaContributors.map(it => it.getCacheKey?.({ schema, identity, project }) ?? '').join('\xff')
|
|
34
|
-
const cacheKey = `${
|
|
38
|
+
const cacheKey = `${permissionsKey}\xff\xff${contributorsKey}`
|
|
35
39
|
|
|
36
40
|
return this.cache.fetch(schema, cacheKey, () => {
|
|
37
|
-
const { root: permissions, all: allPermissions } = this.permissionFactory.createContextual(schema, identity.projectRoles)
|
|
41
|
+
const { root: permissions, all: allPermissions } = computedPermissions ?? this.permissionFactory.createContextual(schema, identity.projectRoles)
|
|
38
42
|
|
|
39
43
|
const authorizator = new Authorizator(
|
|
40
44
|
allPermissions,
|
|
@@ -87,4 +91,26 @@ export class GraphQlSchemaFactory {
|
|
|
87
91
|
return { schema: graphQlSchema, permissions, allPermissions }
|
|
88
92
|
})
|
|
89
93
|
}
|
|
94
|
+
|
|
95
|
+
// Role combinations with identical permissions share one GraphQL schema. The key is memoized per combination,
|
|
96
|
+
// so a request does not rebuild the permissions only to find its schema.
|
|
97
|
+
private getPermissionsKey(
|
|
98
|
+
schema: Schema,
|
|
99
|
+
roles: readonly string[],
|
|
100
|
+
): { permissionsKey: string; computedPermissions?: ContextualPermissions } {
|
|
101
|
+
let keysByRoles = this.permissionsKeys.get(schema)
|
|
102
|
+
if (!keysByRoles) {
|
|
103
|
+
keysByRoles = new Map()
|
|
104
|
+
this.permissionsKeys.set(schema, keysByRoles)
|
|
105
|
+
}
|
|
106
|
+
const rolesKey = [...roles].sort().join('\xff')
|
|
107
|
+
const cachedKey = keysByRoles.get(rolesKey)
|
|
108
|
+
if (cachedKey !== undefined) {
|
|
109
|
+
return { permissionsKey: cachedKey }
|
|
110
|
+
}
|
|
111
|
+
const computedPermissions = this.permissionFactory.createContextual(schema, roles)
|
|
112
|
+
const permissionsKey = createHash('sha256').update(JSON.stringify([computedPermissions.root, computedPermissions.all])).digest('hex')
|
|
113
|
+
keysByRoles.set(rolesKey, permissionsKey)
|
|
114
|
+
return { permissionsKey, computedPermissions }
|
|
115
|
+
}
|
|
90
116
|
}
|