@contember/engine-http 2.2.0-alpha.7 → 2.2.0-alpha.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/CLAUDE.md +1 -1
  2. package/dist/development/src/MasterContainer.cjs +4 -2
  3. package/dist/development/src/MasterContainer.cjs.map +1 -1
  4. package/dist/development/src/MasterContainer.js +4 -2
  5. package/dist/development/src/MasterContainer.js.map +1 -1
  6. package/dist/development/src/application/application.cjs +1 -1
  7. package/dist/development/src/application/application.cjs.map +1 -1
  8. package/dist/development/src/application/application.js +1 -1
  9. package/dist/development/src/application/application.js.map +1 -1
  10. package/dist/development/src/application/forceHttpOk.cjs +2 -9
  11. package/dist/development/src/application/forceHttpOk.cjs.map +1 -1
  12. package/dist/development/src/application/forceHttpOk.js +2 -9
  13. package/dist/development/src/application/forceHttpOk.js.map +1 -1
  14. package/dist/development/src/config/configSchema.cjs +3 -0
  15. package/dist/development/src/config/configSchema.cjs.map +1 -1
  16. package/dist/development/src/config/configSchema.js +3 -0
  17. package/dist/development/src/config/configSchema.js.map +1 -1
  18. package/dist/development/src/config/configTemplate.cjs +2 -0
  19. package/dist/development/src/config/configTemplate.cjs.map +1 -1
  20. package/dist/development/src/config/configTemplate.js +2 -0
  21. package/dist/development/src/config/configTemplate.js.map +1 -1
  22. package/dist/development/src/content/ContentApiControllerFactory.cjs +11 -3
  23. package/dist/development/src/content/ContentApiControllerFactory.cjs.map +1 -1
  24. package/dist/development/src/content/ContentApiControllerFactory.js +11 -3
  25. package/dist/development/src/content/ContentApiControllerFactory.js.map +1 -1
  26. package/dist/development/src/projectGroup/ProjectGroupContainer.cjs +26 -22
  27. package/dist/development/src/projectGroup/ProjectGroupContainer.cjs.map +1 -1
  28. package/dist/development/src/projectGroup/ProjectGroupContainer.js +26 -22
  29. package/dist/development/src/projectGroup/ProjectGroupContainer.js.map +1 -1
  30. package/dist/development/src/utils/serverTermination.cjs +5 -1
  31. package/dist/development/src/utils/serverTermination.cjs.map +1 -1
  32. package/dist/development/src/utils/serverTermination.js +5 -1
  33. package/dist/development/src/utils/serverTermination.js.map +1 -1
  34. package/dist/development/src/utils/truthyHeader.cjs +13 -0
  35. package/dist/development/src/utils/truthyHeader.cjs.map +1 -0
  36. package/dist/development/src/utils/truthyHeader.js +13 -0
  37. package/dist/development/src/utils/truthyHeader.js.map +1 -0
  38. package/dist/production/src/MasterContainer.cjs +4 -2
  39. package/dist/production/src/MasterContainer.cjs.map +1 -1
  40. package/dist/production/src/MasterContainer.js +4 -2
  41. package/dist/production/src/MasterContainer.js.map +1 -1
  42. package/dist/production/src/application/application.cjs +1 -1
  43. package/dist/production/src/application/application.cjs.map +1 -1
  44. package/dist/production/src/application/application.js +1 -1
  45. package/dist/production/src/application/application.js.map +1 -1
  46. package/dist/production/src/application/forceHttpOk.cjs +2 -9
  47. package/dist/production/src/application/forceHttpOk.cjs.map +1 -1
  48. package/dist/production/src/application/forceHttpOk.js +2 -9
  49. package/dist/production/src/application/forceHttpOk.js.map +1 -1
  50. package/dist/production/src/config/configSchema.cjs +3 -0
  51. package/dist/production/src/config/configSchema.cjs.map +1 -1
  52. package/dist/production/src/config/configSchema.js +3 -0
  53. package/dist/production/src/config/configSchema.js.map +1 -1
  54. package/dist/production/src/config/configTemplate.cjs +2 -0
  55. package/dist/production/src/config/configTemplate.cjs.map +1 -1
  56. package/dist/production/src/config/configTemplate.js +2 -0
  57. package/dist/production/src/config/configTemplate.js.map +1 -1
  58. package/dist/production/src/content/ContentApiControllerFactory.cjs +11 -3
  59. package/dist/production/src/content/ContentApiControllerFactory.cjs.map +1 -1
  60. package/dist/production/src/content/ContentApiControllerFactory.js +11 -3
  61. package/dist/production/src/content/ContentApiControllerFactory.js.map +1 -1
  62. package/dist/production/src/projectGroup/ProjectGroupContainer.cjs +26 -22
  63. package/dist/production/src/projectGroup/ProjectGroupContainer.cjs.map +1 -1
  64. package/dist/production/src/projectGroup/ProjectGroupContainer.js +26 -22
  65. package/dist/production/src/projectGroup/ProjectGroupContainer.js.map +1 -1
  66. package/dist/production/src/utils/serverTermination.cjs +5 -1
  67. package/dist/production/src/utils/serverTermination.cjs.map +1 -1
  68. package/dist/production/src/utils/serverTermination.js +5 -1
  69. package/dist/production/src/utils/serverTermination.js.map +1 -1
  70. package/dist/production/src/utils/truthyHeader.cjs +13 -0
  71. package/dist/production/src/utils/truthyHeader.cjs.map +1 -0
  72. package/dist/production/src/utils/truthyHeader.js +13 -0
  73. package/dist/production/src/utils/truthyHeader.js.map +1 -0
  74. package/dist/tests/cases/unit/forcePrimary.test.d.ts +2 -0
  75. package/dist/tests/cases/unit/forcePrimary.test.d.ts.map +1 -0
  76. package/dist/tests/cases/unit/serverTermination.fixture.d.ts +2 -0
  77. package/dist/tests/cases/unit/serverTermination.fixture.d.ts.map +1 -0
  78. package/dist/tests/cases/unit/serverTermination.test.d.ts +2 -0
  79. package/dist/tests/cases/unit/serverTermination.test.d.ts.map +1 -0
  80. package/dist/tests/tsconfig.tsbuildinfo +1 -1
  81. package/dist/types/MasterContainer.d.ts +2 -0
  82. package/dist/types/MasterContainer.d.ts.map +1 -1
  83. package/dist/types/application/forceHttpOk.d.ts.map +1 -1
  84. package/dist/types/config/configSchema.d.ts +5 -0
  85. package/dist/types/config/configSchema.d.ts.map +1 -1
  86. package/dist/types/config/configTemplate.d.ts.map +1 -1
  87. package/dist/types/content/ContentApiControllerFactory.d.ts +2 -1
  88. package/dist/types/content/ContentApiControllerFactory.d.ts.map +1 -1
  89. package/dist/types/projectGroup/ProjectGroupContainer.d.ts.map +1 -1
  90. package/dist/types/tsconfig.tsbuildinfo +1 -1
  91. package/dist/types/utils/serverTermination.d.ts +9 -1
  92. package/dist/types/utils/serverTermination.d.ts.map +1 -1
  93. package/dist/types/utils/truthyHeader.d.ts +3 -0
  94. package/dist/types/utils/truthyHeader.d.ts.map +1 -0
  95. package/package.json +15 -15
  96. package/src/MasterContainer.ts +2 -0
  97. package/src/application/application.ts +1 -1
  98. package/src/application/forceHttpOk.ts +2 -10
  99. package/src/config/configSchema.ts +3 -0
  100. package/src/config/configTemplate.ts +2 -0
  101. package/src/content/ContentApiControllerFactory.ts +12 -2
  102. package/src/projectGroup/ProjectGroupContainer.ts +28 -24
  103. package/src/utils/serverTermination.ts +19 -1
  104. package/src/utils/truthyHeader.ts +12 -0
  105. package/tests/cases/unit/forcePrimary.test.ts +293 -0
  106. package/tests/cases/unit/serverConfig.test.ts +16 -0
  107. package/tests/cases/unit/serverTermination.fixture.ts +13 -0
  108. package/tests/cases/unit/serverTermination.test.ts +49 -0
package/CLAUDE.md CHANGED
@@ -43,7 +43,7 @@ Two resolution modes:
43
43
  - `application/application.ts` — Koa app, route registration, request lifecycle
44
44
  - `application/forceHttpOk.ts` — opt-in `X-Contember-Force-Ok` header that coerces GraphQL API responses to HTTP 200 (errors stay in the JSON body); gated by `http.responseStatusHeader` config
45
45
  - `MasterContainer.ts` — DI container factory with all service definitions
46
- - `content/ContentApiControllerFactory.ts` — Content API: schema resolution, membership check, GraphQL execution
46
+ - `content/ContentApiControllerFactory.ts` — Content API: schema resolution, membership check, GraphQL execution; honours `X-Contember-Force-Primary` only when `contentApi.forcePrimaryHeader` is enabled, and then marks mutations of projects with a read replica
47
47
  - `projectGroup/ProjectGroupResolver.ts` — Tenant resolution
48
48
  - `common/Authorizator.ts` — Token verification
49
49
  - `config/configSchema.ts` — Server config validation schema
@@ -145,14 +145,16 @@ class MasterContainerFactory {
145
145
  executionContainerFactory,
146
146
  contentQueryHandlerFactory,
147
147
  graphQlSchemaFactory,
148
- testTransactionService
148
+ testTransactionService,
149
+ serverConfig: serverConfig2
149
150
  }) => new ContentApiControllerFactory.ContentApiControllerFactory(
150
151
  notModifiedChecker,
151
152
  executionContainerFactory,
152
153
  contentQueryHandlerFactory,
153
154
  projectContextResolver,
154
155
  graphQlSchemaFactory,
155
- testTransactionService
156
+ testTransactionService,
157
+ serverConfig2.contentApi?.forcePrimaryHeader ?? false
156
158
  )
157
159
  ).addService("tenantApiMiddlewareFactory", () => new TenantApiMiddlewareFactory.TenantApiMiddlewareFactory()).addService("oidcBackchannelLogoutMiddlewareFactory", () => new OidcBackchannelLogoutMiddlewareFactory.OidcBackchannelLogoutMiddlewareFactory()).addService("systemGraphQLContextFactory", () => new SystemGraphQLContextFactory.SystemGraphQLContextFactory()).addService(
158
160
  "systemApiMiddlewareFactory",
@@ -1 +1 @@
1
- {"version":3,"file":"MasterContainer.cjs","sources":["../../../../packages/engine-http/src/MasterContainer.ts"],"sourcesContent":["import { Builder } from '@contember/dic'\nimport { SystemContainerFactory } from '@contember/engine-system-api'\nimport { TenantContainerFactory } from '@contember/engine-tenant-api'\nimport { ModificationHandlerFactory } from '@contember/schema-migrations'\nimport { Initializer } from './bootstrap/index.js'\nimport { Env, ServerConfig } from './config/config.js'\n\nimport { DatabaseMetadataResolver } from '@contember/database'\nimport { ExecutionContainerFactory, GraphQlSchemaBuilderFactory, PermissionFactory } from '@contember/engine-content-api'\nimport { Logger } from '@contember/logger'\nimport { Schema } from '@contember/schema'\nimport Koa from 'koa'\nimport { createSecretKey } from 'node:crypto'\nimport { Application, DisabledPanelApiMount, PanelApiMount } from './application/index.js'\nimport { createNotFoundMiddleware, HttpResponse } from './common/index.js'\nimport { ProjectConfigResolver } from './config/projectConfigResolver.js'\nimport { TenantConfigResolver } from './config/tenantConfigResolver.js'\nimport {\n\tContentApiControllerFactory,\n\tContentQueryHandlerFactory,\n\tGraphQLSchemaContributor,\n\tGraphQlSchemaFactory,\n\tGraphQLSchemaFactoryResult,\n\tNotModifiedChecker,\n} from './content/index.js'\nimport { ContentApiSpecificCache } from './content/ContentApiSpecificCache.js'\nimport { homepageController } from './misc/index.js'\nimport { Plugin } from './plugin/Plugin.js'\nimport { ProjectContainerFactoryFactory } from './project/index.js'\nimport { ProjectContextResolver } from './project-common/index.js'\nimport { ProjectGroupContainerFactory } from './projectGroup/ProjectGroupContainer.js'\nimport { ProjectGroupContainerResolver } from './projectGroup/ProjectGroupContainerResolver.js'\nimport { ProjectGroupResolver } from './projectGroup/ProjectGroupResolver.js'\nimport { createColllectHttpMetricsMiddleware, createShowMetricsMiddleware } from './prometheus/index.js'\nimport { ProjectGroupContainerMetricsHook } from './prometheus/ProjectGroupContainerMetricsHook.js'\nimport { PrometheusRegistryFactory } from './prometheus/PrometheusRegistryFactory.js'\nimport { createProviders, Providers } from './providers.js'\nimport { SystemApiMiddlewareFactory, SystemGraphQLContextFactory, SystemGraphQLHandlerFactory } from './system/index.js'\nimport { ContentQueryExecutorImpl } from './system/ContentQueryExecutor.js'\nimport { OidcBackchannelLogoutMiddlewareFactory, TenantApiMiddlewareFactory, TenantGraphQLHandlerFactory } from './tenant/index.js'\nimport {\n\tContentSchemaTransferMappingFactory,\n\tExportApiControllerFactory,\n\tExportExecutor,\n\tImportApiMiddlewareFactory,\n\tImportExecutor,\n\tSystemSchemaTransferMappingFactory,\n} from './transfer/index.js'\nimport { CryptoWrapper } from './utils/CryptoWrapper.js'\nimport { ApplicationWorkerManager } from './workers/index.js'\nimport { TestTransactionService } from './testing/index.js'\n\nexport type ProcessType =\n\t| 'singleNode'\n\t| 'clusterMaster'\n\t| 'clusterWorker'\n\nexport interface MasterContainer {\n\tinitializer: Initializer\n\tapplication: Application\n\tproviders: Providers\n\tapplicationWorkers: ApplicationWorkerManager\n\tmonitoringKoa: Koa\n}\n\nexport interface MasterContainerArgs {\n\tdebugMode: boolean\n\tserverConfig: ServerConfig\n\tprojectConfigResolver: ProjectConfigResolver\n\ttenantConfigResolver: TenantConfigResolver\n\t/** The environment the config was resolved from, so a plugin can read its own `<PROJECT>_*` values out of it. */\n\tenv: Env\n\tplugins: Plugin[]\n\tlogger: Logger\n\tversion?: string\n\tprocessType: ProcessType\n}\n\nexport type MasterContainerBuilder = ReturnType<MasterContainerFactory['createBuilderInternal']>\nexport type MasterContainerHook = (builder: MasterContainerBuilder) => MasterContainerBuilder\n\nexport class MasterContainerFactory {\n\tcreateBuilder(args: MasterContainerArgs): MasterContainerBuilder {\n\t\tconst builder = this.createBuilderInternal(args)\n\t\tconst hooks = args.plugins\n\t\t\t.map(it => it.getMasterContainerHook?.())\n\t\t\t.filter((it): it is MasterContainerHook => it !== undefined)\n\t\treturn hooks.reduce((acc, cb) => cb(acc), builder)\n\t}\n\n\tcreateBuilderInternal({\n\t\tserverConfig,\n\t\tdebugMode,\n\t\tplugins,\n\t\tprojectConfigResolver,\n\t\ttenantConfigResolver,\n\t\tenv,\n\t\tversion,\n\t\tlogger,\n\t\tprocessType,\n\t}: MasterContainerArgs) {\n\t\treturn new Builder({})\n\t\t\t.addService('serverConfig', () => serverConfig)\n\t\t\t.addService('env', () => env)\n\t\t\t.addService('debugMode', () => debugMode)\n\t\t\t.addService('version', () => version)\n\t\t\t.addService('processType', () => processType)\n\t\t\t.addService('projectConfigResolver', () => projectConfigResolver)\n\t\t\t.addService('tenantConfigResolver', () => tenantConfigResolver)\n\t\t\t.addService('plugins', () => plugins)\n\t\t\t.addService('providers', () => createProviders())\n\t\t\t.addService('tenantContainerFactory', ({ providers }) => new TenantContainerFactory(providers))\n\t\t\t.addService('modificationHandlerFactory', () => new ModificationHandlerFactory(ModificationHandlerFactory.defaultFactoryMap))\n\t\t\t.addService(\n\t\t\t\t'executionContainerFactory',\n\t\t\t\t({ providers, serverConfig }) => new ExecutionContainerFactory(providers, serverConfig.contentApi?.whereOptimizer),\n\t\t\t)\n\t\t\t.addService('graphQlSchemaBuilderFactory', () => new GraphQlSchemaBuilderFactory())\n\t\t\t.addService(\n\t\t\t\t'contentQueryExecutor',\n\t\t\t\t({ executionContainerFactory, graphQlSchemaBuilderFactory }) =>\n\t\t\t\t\tnew ContentQueryExecutorImpl(executionContainerFactory, graphQlSchemaBuilderFactory),\n\t\t\t)\n\t\t\t.addService(\n\t\t\t\t'systemContainerFactory',\n\t\t\t\t({ providers, modificationHandlerFactory, contentQueryExecutor }) =>\n\t\t\t\t\tnew SystemContainerFactory(providers, modificationHandlerFactory, contentQueryExecutor),\n\t\t\t)\n\t\t\t.addService('contentPermissionFactory', ({}) => new PermissionFactory())\n\t\t\t.addService('databaseMetadataResolver', () => new DatabaseMetadataResolver())\n\t\t\t.addService('graphqlSchemaCache', ({ serverConfig }) =>\n\t\t\t\tnew ContentApiSpecificCache<Schema, GraphQLSchemaFactoryResult>({\n\t\t\t\t\tttlSeconds: serverConfig.contentApi?.schemaCacheTtlSeconds,\n\t\t\t\t}))\n\t\t\t.addService('graphQlSchemaFactory', ({ plugins, providers, graphqlSchemaCache, contentPermissionFactory, graphQlSchemaBuilderFactory }) => {\n\t\t\t\tconst contributors = plugins\n\t\t\t\t\t.map(it => (it.getSchemaContributor ? it.getSchemaContributor({ providers }) : null))\n\t\t\t\t\t.filter((it): it is GraphQLSchemaContributor => !!it)\n\n\t\t\t\treturn new GraphQlSchemaFactory(\n\t\t\t\t\tgraphqlSchemaCache,\n\t\t\t\t\tgraphQlSchemaBuilderFactory,\n\t\t\t\t\tcontentPermissionFactory,\n\t\t\t\t\tcontributors,\n\t\t\t\t)\n\t\t\t})\n\t\t\t.addService(\n\t\t\t\t'projectContainerFactoryFactory',\n\t\t\t\t({ plugins, providers, databaseMetadataResolver }) => new ProjectContainerFactoryFactory(plugins, providers, databaseMetadataResolver),\n\t\t\t)\n\t\t\t.addService('tenantGraphQLHandlerFactory', () => new TenantGraphQLHandlerFactory())\n\t\t\t.addService('systemGraphQLHandlerFactory', ({ debugMode }) => new SystemGraphQLHandlerFactory(debugMode))\n\t\t\t.addService('logger', () => logger)\n\t\t\t.addService(\n\t\t\t\t'projectGroupContainerFactory',\n\t\t\t\t({\n\t\t\t\t\tdebugMode,\n\t\t\t\t\tproviders,\n\t\t\t\t\tsystemContainerFactory,\n\t\t\t\t\ttenantContainerFactory,\n\t\t\t\t\tprojectContainerFactoryFactory,\n\t\t\t\t\tprojectConfigResolver,\n\t\t\t\t\ttenantGraphQLHandlerFactory,\n\t\t\t\t\tsystemGraphQLHandlerFactory,\n\t\t\t\t\tlogger,\n\t\t\t\t\tserverConfig,\n\t\t\t\t}) =>\n\t\t\t\t\tnew ProjectGroupContainerFactory(\n\t\t\t\t\t\tdebugMode,\n\t\t\t\t\t\tproviders,\n\t\t\t\t\t\tsystemContainerFactory,\n\t\t\t\t\t\ttenantContainerFactory,\n\t\t\t\t\t\tprojectContainerFactoryFactory,\n\t\t\t\t\t\tprojectConfigResolver,\n\t\t\t\t\t\ttenantGraphQLHandlerFactory,\n\t\t\t\t\t\tsystemGraphQLHandlerFactory,\n\t\t\t\t\t\tlogger,\n\t\t\t\t\t\tserverConfig.http?.geoCountryHeader,\n\t\t\t\t\t),\n\t\t\t)\n\t\t\t.addService(\n\t\t\t\t'projectGroupContainerResolver',\n\t\t\t\t({ tenantConfigResolver, projectGroupContainerFactory }) => new ProjectGroupContainerResolver(tenantConfigResolver, projectGroupContainerFactory),\n\t\t\t)\n\t\t\t.addService('promRegistryFactory', ({ processType, version }) => new PrometheusRegistryFactory(processType, { version }))\n\t\t\t.addService(\n\t\t\t\t'projectGroupContainerMetricsHook',\n\t\t\t\t({ projectGroupContainerResolver }) => new ProjectGroupContainerMetricsHook(projectGroupContainerResolver),\n\t\t\t)\n\t\t\t.addService('promRegistry', ({ promRegistryFactory, projectGroupContainerMetricsHook }) => {\n\t\t\t\tconst registry = promRegistryFactory.create()\n\t\t\t\tprojectGroupContainerMetricsHook.register(registry)\n\t\t\t\treturn registry\n\t\t\t})\n\t\t\t.addService(\n\t\t\t\t'projectGroupContainer',\n\t\t\t\t({ tenantConfigResolver, projectGroupContainerFactory }) =>\n\t\t\t\t\tprojectGroupContainerFactory.create({ slug: undefined, config: tenantConfigResolver(undefined, {}) }),\n\t\t\t)\n\t\t\t.addService('projectGroupResolver', ({ serverConfig, projectGroupContainerResolver }): ProjectGroupResolver => {\n\t\t\t\tconst encryptionKey = serverConfig.projectGroup?.configEncryptionKey\n\t\t\t\t\t? createSecretKey(Buffer.from(serverConfig.projectGroup?.configEncryptionKey, 'hex'))\n\t\t\t\t\t: undefined\n\t\t\t\treturn new ProjectGroupResolver(\n\t\t\t\t\tserverConfig.projectGroup?.domainMapping,\n\t\t\t\t\tserverConfig.projectGroup?.configHeader,\n\t\t\t\t\tserverConfig.projectGroup?.configEncryptionKey ? new CryptoWrapper(encryptionKey) : undefined,\n\t\t\t\t\tprojectGroupContainerResolver,\n\t\t\t\t)\n\t\t\t})\n\t\t\t.addService('testTransactionService', ({ serverConfig }) =>\n\t\t\t\tnew TestTransactionService(\n\t\t\t\t\tserverConfig.test?.transactions ?? false,\n\t\t\t\t\t(serverConfig.test?.transactionTtlSeconds ?? 60) * 1000,\n\t\t\t\t))\n\t\t\t.addService('notModifiedChecker', () => new NotModifiedChecker())\n\t\t\t.addService('contentQueryHandlerFactory', ({ debugMode }) => new ContentQueryHandlerFactory(debugMode))\n\t\t\t.addService('projectContextResolver', () => new ProjectContextResolver())\n\t\t\t.addService(\n\t\t\t\t'contentApiMiddlewareFactory',\n\t\t\t\t(\n\t\t\t\t\t{\n\t\t\t\t\t\tprojectContextResolver,\n\t\t\t\t\t\tnotModifiedChecker,\n\t\t\t\t\t\texecutionContainerFactory,\n\t\t\t\t\t\tcontentQueryHandlerFactory,\n\t\t\t\t\t\tgraphQlSchemaFactory,\n\t\t\t\t\t\ttestTransactionService,\n\t\t\t\t\t},\n\t\t\t\t) =>\n\t\t\t\t\tnew ContentApiControllerFactory(\n\t\t\t\t\t\tnotModifiedChecker,\n\t\t\t\t\t\texecutionContainerFactory,\n\t\t\t\t\t\tcontentQueryHandlerFactory,\n\t\t\t\t\t\tprojectContextResolver,\n\t\t\t\t\t\tgraphQlSchemaFactory,\n\t\t\t\t\t\ttestTransactionService,\n\t\t\t\t\t),\n\t\t\t)\n\t\t\t.addService('tenantApiMiddlewareFactory', () => new TenantApiMiddlewareFactory())\n\t\t\t.addService('oidcBackchannelLogoutMiddlewareFactory', () => new OidcBackchannelLogoutMiddlewareFactory())\n\t\t\t.addService('systemGraphQLContextFactory', () => new SystemGraphQLContextFactory())\n\t\t\t.addService(\n\t\t\t\t'systemApiMiddlewareFactory',\n\t\t\t\t({ debugMode, systemGraphQLContextFactory, projectContextResolver }) =>\n\t\t\t\t\tnew SystemApiMiddlewareFactory(debugMode, systemGraphQLContextFactory, projectContextResolver),\n\t\t\t)\n\t\t\t.addService('contentSchemaTransferMappingFactory', () => new ContentSchemaTransferMappingFactory())\n\t\t\t.addService('systemSchemaTransferMappingFactory', () => new SystemSchemaTransferMappingFactory())\n\t\t\t.addService(\n\t\t\t\t'importExecutor',\n\t\t\t\t({ contentSchemaTransferMappingFactory, systemSchemaTransferMappingFactory, databaseMetadataResolver }) =>\n\t\t\t\t\tnew ImportExecutor(contentSchemaTransferMappingFactory, systemSchemaTransferMappingFactory, databaseMetadataResolver),\n\t\t\t)\n\t\t\t.addService(\n\t\t\t\t'exportExecutor',\n\t\t\t\t({ contentSchemaTransferMappingFactory, systemSchemaTransferMappingFactory }) =>\n\t\t\t\t\tnew ExportExecutor(contentSchemaTransferMappingFactory, systemSchemaTransferMappingFactory),\n\t\t\t)\n\t\t\t.addService(\n\t\t\t\t'importApiMiddlewareFactory',\n\t\t\t\t({ projectGroupResolver, importExecutor }) => new ImportApiMiddlewareFactory(projectGroupResolver, importExecutor),\n\t\t\t)\n\t\t\t.addService(\n\t\t\t\t'exportApiMiddlewareFactory',\n\t\t\t\t({ projectGroupResolver, exportExecutor }) => new ExportApiControllerFactory(projectGroupResolver, exportExecutor),\n\t\t\t)\n\t\t\t// Replaced by the panel plugin when it serves the panel; see `PanelApiMount`. Declared here so\n\t\t\t// a plugin can mount its API into the panel without depending on the panel package.\n\t\t\t.addService('panelApiMount', (): PanelApiMount => new DisabledPanelApiMount())\n\t\t\t.addService('application', ({ projectGroupResolver, serverConfig, logger, debugMode, version, promRegistry }) => {\n\t\t\t\tconst app = new Application(\n\t\t\t\t\tprojectGroupResolver,\n\t\t\t\t\tserverConfig,\n\t\t\t\t\tdebugMode,\n\t\t\t\t\tversion,\n\t\t\t\t\tlogger,\n\t\t\t\t)\n\t\t\t\tapp.addMiddleware(createColllectHttpMetricsMiddleware(promRegistry))\n\n\t\t\t\treturn app\n\t\t\t})\n\t\t\t.setupService(\n\t\t\t\t'application',\n\t\t\t\t(\n\t\t\t\t\tit,\n\t\t\t\t\t{\n\t\t\t\t\t\tcontentApiMiddlewareFactory,\n\t\t\t\t\t\ttenantApiMiddlewareFactory,\n\t\t\t\t\t\toidcBackchannelLogoutMiddlewareFactory,\n\t\t\t\t\t\tsystemApiMiddlewareFactory,\n\t\t\t\t\t\timportApiMiddlewareFactory,\n\t\t\t\t\t\texportApiMiddlewareFactory,\n\t\t\t\t\t\ttestTransactionService,\n\t\t\t\t\t},\n\t\t\t\t) => {\n\t\t\t\t\tit.addRoute('content', '/content/:projectSlug/:stageSlug', contentApiMiddlewareFactory.create())\n\t\t\t\t\tit.addRoute('tenant', '/tenant', tenantApiMiddlewareFactory.create())\n\t\t\t\t\t// Register under a dedicated, non-GraphQL module so it is excluded from `forceHttpOk`\n\t\t\t\t\t// status coercion (graphqlModules = content/tenant/system): the OIDC Back-Channel Logout\n\t\t\t\t\t// response is not a GraphQL `{data,errors}` envelope and its HTTP status is part of the\n\t\t\t\t\t// spec contract (the IdP relies on a non-2xx status to detect/retry a failed logout).\n\t\t\t\t\tit.addRoute('oidc', '/oidc/backchannel-logout', oidcBackchannelLogoutMiddlewareFactory.create())\n\t\t\t\t\tit.addRoute('system', '/system/:projectSlug', systemApiMiddlewareFactory.create())\n\t\t\t\t\tit.addRoute('transfer', '/import', importApiMiddlewareFactory.create())\n\t\t\t\t\tit.addRoute('transfer', '/export', exportApiMiddlewareFactory.create())\n\t\t\t\t\tit.addRoute('misc', '/', homepageController)\n\n\t\t\t\t\tit.addInternalRoute('internal', '/health', () => {\n\t\t\t\t\t\treturn new HttpResponse(200, 'OK')\n\t\t\t\t\t})\n\n\t\t\t\t\tif (testTransactionService.isEnabled()) {\n\t\t\t\t\t\tit.addInternalRoute('test', '/test/transaction', async ({ koa }) => {\n\t\t\t\t\t\t\tconst method = koa.request.method\n\t\t\t\t\t\t\tif (method === 'POST') {\n\t\t\t\t\t\t\t\treturn new HttpResponse(200, JSON.stringify({ token: testTransactionService.begin() }), 'application/json')\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (method === 'DELETE') {\n\t\t\t\t\t\t\t\tconst token = koa.get('x-contember-test-session')\n\t\t\t\t\t\t\t\tconst ok = token ? await testTransactionService.rollback(token) : false\n\t\t\t\t\t\t\t\treturn new HttpResponse(ok ? 200 : 404, JSON.stringify({ ok }), 'application/json')\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn new HttpResponse(405, JSON.stringify({ error: 'Method not allowed' }), 'application/json')\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t)\n\t\t\t.addService('initializer', ({ projectGroupContainer }) => new Initializer(projectGroupContainer))\n\t\t\t.addService('applicationWorkers', () => new ApplicationWorkerManager())\n\t\t\t.setupService('executionContainerFactory', (it, { plugins }) => {\n\t\t\t\tfor (const plugin of plugins) {\n\t\t\t\t\tif (plugin.getExecutionContainerHook) {\n\t\t\t\t\t\tit.hooks.push(plugin.getExecutionContainerHook())\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t})\n\t\t\t.addService('monitoringKoa', ({ promRegistry }) => {\n\t\t\t\tconst app = new Koa()\n\t\t\t\tapp.use(createShowMetricsMiddleware(promRegistry))\n\t\t\t\tapp.use(createNotFoundMiddleware())\n\n\t\t\t\treturn app\n\t\t\t})\n\t}\n\n\tcreate(args: MasterContainerArgs): MasterContainer {\n\t\tconst container = this.createBuilder(args).build()\n\t\treturn container.pick('initializer', 'application', 'providers', 'applicationWorkers', 'monitoringKoa')\n\t}\n}\n"],"names":["Builder","createProviders","providers","TenantContainerFactory","ModificationHandlerFactory","serverConfig","ExecutionContainerFactory","GraphQlSchemaBuilderFactory","ContentQueryExecutorImpl","SystemContainerFactory","PermissionFactory","DatabaseMetadataResolver","ContentApiSpecificCache","plugins","GraphQlSchemaFactory","ProjectContainerFactoryFactory","TenantGraphQLHandlerFactory","debugMode","SystemGraphQLHandlerFactory","projectConfigResolver","logger","ProjectGroupContainerFactory","tenantConfigResolver","ProjectGroupContainerResolver","processType","version","PrometheusRegistryFactory","ProjectGroupContainerMetricsHook","createSecretKey","ProjectGroupResolver","CryptoWrapper","TestTransactionService","NotModifiedChecker","ContentQueryHandlerFactory","ProjectContextResolver","ContentApiControllerFactory","TenantApiMiddlewareFactory","OidcBackchannelLogoutMiddlewareFactory","SystemGraphQLContextFactory","SystemApiMiddlewareFactory","ContentSchemaTransferMappingFactory","SystemSchemaTransferMappingFactory","ImportExecutor","ExportExecutor","ImportApiMiddlewareFactory","ExportApiControllerFactory","DisabledPanelApiMount","Application","createColllectHttpMetricsMiddleware","homepageController","HttpResponse","Initializer","ApplicationWorkerManager","createShowMetricsMiddleware","createNotFoundMiddleware"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiFO,MAAM,uBAAuB;AAAA,EACnC,cAAc,MAAmD;AAChE,UAAM,UAAU,KAAK,sBAAsB,IAAI;AAC/C,UAAM,QAAQ,KAAK,QACjB,IAAI,CAAA,OAAM,GAAG,yBAAA,CAA0B,EACvC,OAAO,CAAC,OAAkC,OAAO,MAAS;AAC5D,WAAO,MAAM,OAAO,CAAC,KAAK,OAAO,GAAG,GAAG,GAAG,OAAO;AAAA,EAClD;AAAA,EAEA,sBAAsB;AAAA,IACrB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,GACuB;AACvB,WAAO,IAAIA,IAAAA,QAAQ,CAAA,CAAE,EACnB,WAAW,gBAAgB,MAAM,YAAY,EAC7C,WAAW,OAAO,MAAM,GAAG,EAC3B,WAAW,aAAa,MAAM,SAAS,EACvC,WAAW,WAAW,MAAM,OAAO,EACnC,WAA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AA6B,CAAC,IAAI,EAAE,SAAAvC,eAAc;AAC/D,iBAAW,UAAUA,UAAS;AAC7B,YAAI,OAAO,2BAA2B;AACrC,aAAG,MAAM,KAAK,OAAO,0BAAA,CAA2B;AAAA,QACjD;AAAA,MACD;AAAA,IACD,CAAC,EACA,WAAW,iBAAiB,CAAC,EAAE,mBAAmB;AAClD,YAAM,MAAM,IAAI,IAAA;AAChB,UAAI,IAAIwC,kDAA4B,YAAY,CAAC;AACjD,UAAI,IAAIC,mBAAAA,0BAA0B;AAElC,aAAO;AAAA,IACR,CAAC;AAAA,EACH;AAAA,EAEA,OAAO,MAA4C;AAClD,UAAM,YAAY,KAAK,cAAc,IAAI,EAAE,MAAA;AAC3C,WAAO,UAAU,KAAK,eAAe,eAAe,aAAa,sBAAsB,eAAe;AAAA,EACvG;AACD;;"}
1
+ {"version":3,"file":"MasterContainer.cjs","sources":["../../../../packages/engine-http/src/MasterContainer.ts"],"sourcesContent":["import { Builder } from '@contember/dic'\nimport { SystemContainerFactory } from '@contember/engine-system-api'\nimport { TenantContainerFactory } from '@contember/engine-tenant-api'\nimport { ModificationHandlerFactory } from '@contember/schema-migrations'\nimport { Initializer } from './bootstrap/index.js'\nimport { Env, ServerConfig } from './config/config.js'\n\nimport { DatabaseMetadataResolver } from '@contember/database'\nimport { ExecutionContainerFactory, GraphQlSchemaBuilderFactory, PermissionFactory } from '@contember/engine-content-api'\nimport { Logger } from '@contember/logger'\nimport { Schema } from '@contember/schema'\nimport Koa from 'koa'\nimport { createSecretKey } from 'node:crypto'\nimport { Application, DisabledPanelApiMount, PanelApiMount } from './application/index.js'\nimport { createNotFoundMiddleware, HttpResponse } from './common/index.js'\nimport { ProjectConfigResolver } from './config/projectConfigResolver.js'\nimport { TenantConfigResolver } from './config/tenantConfigResolver.js'\nimport {\n\tContentApiControllerFactory,\n\tContentQueryHandlerFactory,\n\tGraphQLSchemaContributor,\n\tGraphQlSchemaFactory,\n\tGraphQLSchemaFactoryResult,\n\tNotModifiedChecker,\n} from './content/index.js'\nimport { ContentApiSpecificCache } from './content/ContentApiSpecificCache.js'\nimport { homepageController } from './misc/index.js'\nimport { Plugin } from './plugin/Plugin.js'\nimport { ProjectContainerFactoryFactory } from './project/index.js'\nimport { ProjectContextResolver } from './project-common/index.js'\nimport { ProjectGroupContainerFactory } from './projectGroup/ProjectGroupContainer.js'\nimport { ProjectGroupContainerResolver } from './projectGroup/ProjectGroupContainerResolver.js'\nimport { ProjectGroupResolver } from './projectGroup/ProjectGroupResolver.js'\nimport { createColllectHttpMetricsMiddleware, createShowMetricsMiddleware } from './prometheus/index.js'\nimport { ProjectGroupContainerMetricsHook } from './prometheus/ProjectGroupContainerMetricsHook.js'\nimport { PrometheusRegistryFactory } from './prometheus/PrometheusRegistryFactory.js'\nimport { createProviders, Providers } from './providers.js'\nimport { SystemApiMiddlewareFactory, SystemGraphQLContextFactory, SystemGraphQLHandlerFactory } from './system/index.js'\nimport { ContentQueryExecutorImpl } from './system/ContentQueryExecutor.js'\nimport { OidcBackchannelLogoutMiddlewareFactory, TenantApiMiddlewareFactory, TenantGraphQLHandlerFactory } from './tenant/index.js'\nimport {\n\tContentSchemaTransferMappingFactory,\n\tExportApiControllerFactory,\n\tExportExecutor,\n\tImportApiMiddlewareFactory,\n\tImportExecutor,\n\tSystemSchemaTransferMappingFactory,\n} from './transfer/index.js'\nimport { CryptoWrapper } from './utils/CryptoWrapper.js'\nimport { ApplicationWorkerManager } from './workers/index.js'\nimport { TestTransactionService } from './testing/index.js'\n\nexport type ProcessType =\n\t| 'singleNode'\n\t| 'clusterMaster'\n\t| 'clusterWorker'\n\nexport interface MasterContainer {\n\tinitializer: Initializer\n\tapplication: Application\n\tproviders: Providers\n\tapplicationWorkers: ApplicationWorkerManager\n\tmonitoringKoa: Koa\n}\n\nexport interface MasterContainerArgs {\n\tdebugMode: boolean\n\tserverConfig: ServerConfig\n\tprojectConfigResolver: ProjectConfigResolver\n\ttenantConfigResolver: TenantConfigResolver\n\t/** The environment the config was resolved from, so a plugin can read its own `<PROJECT>_*` values out of it. */\n\tenv: Env\n\tplugins: Plugin[]\n\tlogger: Logger\n\tversion?: string\n\tprocessType: ProcessType\n}\n\nexport type MasterContainerBuilder = ReturnType<MasterContainerFactory['createBuilderInternal']>\nexport type MasterContainerHook = (builder: MasterContainerBuilder) => MasterContainerBuilder\n\nexport class MasterContainerFactory {\n\tcreateBuilder(args: MasterContainerArgs): MasterContainerBuilder {\n\t\tconst builder = this.createBuilderInternal(args)\n\t\tconst hooks = args.plugins\n\t\t\t.map(it => it.getMasterContainerHook?.())\n\t\t\t.filter((it): it is MasterContainerHook => it !== undefined)\n\t\treturn hooks.reduce((acc, cb) => cb(acc), builder)\n\t}\n\n\tcreateBuilderInternal({\n\t\tserverConfig,\n\t\tdebugMode,\n\t\tplugins,\n\t\tprojectConfigResolver,\n\t\ttenantConfigResolver,\n\t\tenv,\n\t\tversion,\n\t\tlogger,\n\t\tprocessType,\n\t}: MasterContainerArgs) {\n\t\treturn new Builder({})\n\t\t\t.addService('serverConfig', () => serverConfig)\n\t\t\t.addService('env', () => env)\n\t\t\t.addService('debugMode', () => debugMode)\n\t\t\t.addService('version', () => version)\n\t\t\t.addService('processType', () => processType)\n\t\t\t.addService('projectConfigResolver', () => projectConfigResolver)\n\t\t\t.addService('tenantConfigResolver', () => tenantConfigResolver)\n\t\t\t.addService('plugins', () => plugins)\n\t\t\t.addService('providers', () => createProviders())\n\t\t\t.addService('tenantContainerFactory', ({ providers }) => new TenantContainerFactory(providers))\n\t\t\t.addService('modificationHandlerFactory', () => new ModificationHandlerFactory(ModificationHandlerFactory.defaultFactoryMap))\n\t\t\t.addService(\n\t\t\t\t'executionContainerFactory',\n\t\t\t\t({ providers, serverConfig }) => new ExecutionContainerFactory(providers, serverConfig.contentApi?.whereOptimizer),\n\t\t\t)\n\t\t\t.addService('graphQlSchemaBuilderFactory', () => new GraphQlSchemaBuilderFactory())\n\t\t\t.addService(\n\t\t\t\t'contentQueryExecutor',\n\t\t\t\t({ executionContainerFactory, graphQlSchemaBuilderFactory }) =>\n\t\t\t\t\tnew ContentQueryExecutorImpl(executionContainerFactory, graphQlSchemaBuilderFactory),\n\t\t\t)\n\t\t\t.addService(\n\t\t\t\t'systemContainerFactory',\n\t\t\t\t({ providers, modificationHandlerFactory, contentQueryExecutor }) =>\n\t\t\t\t\tnew SystemContainerFactory(providers, modificationHandlerFactory, contentQueryExecutor),\n\t\t\t)\n\t\t\t.addService('contentPermissionFactory', ({}) => new PermissionFactory())\n\t\t\t.addService('databaseMetadataResolver', () => new DatabaseMetadataResolver())\n\t\t\t.addService('graphqlSchemaCache', ({ serverConfig }) =>\n\t\t\t\tnew ContentApiSpecificCache<Schema, GraphQLSchemaFactoryResult>({\n\t\t\t\t\tttlSeconds: serverConfig.contentApi?.schemaCacheTtlSeconds,\n\t\t\t\t}))\n\t\t\t.addService('graphQlSchemaFactory', ({ plugins, providers, graphqlSchemaCache, contentPermissionFactory, graphQlSchemaBuilderFactory }) => {\n\t\t\t\tconst contributors = plugins\n\t\t\t\t\t.map(it => (it.getSchemaContributor ? it.getSchemaContributor({ providers }) : null))\n\t\t\t\t\t.filter((it): it is GraphQLSchemaContributor => !!it)\n\n\t\t\t\treturn new GraphQlSchemaFactory(\n\t\t\t\t\tgraphqlSchemaCache,\n\t\t\t\t\tgraphQlSchemaBuilderFactory,\n\t\t\t\t\tcontentPermissionFactory,\n\t\t\t\t\tcontributors,\n\t\t\t\t)\n\t\t\t})\n\t\t\t.addService(\n\t\t\t\t'projectContainerFactoryFactory',\n\t\t\t\t({ plugins, providers, databaseMetadataResolver }) => new ProjectContainerFactoryFactory(plugins, providers, databaseMetadataResolver),\n\t\t\t)\n\t\t\t.addService('tenantGraphQLHandlerFactory', () => new TenantGraphQLHandlerFactory())\n\t\t\t.addService('systemGraphQLHandlerFactory', ({ debugMode }) => new SystemGraphQLHandlerFactory(debugMode))\n\t\t\t.addService('logger', () => logger)\n\t\t\t.addService(\n\t\t\t\t'projectGroupContainerFactory',\n\t\t\t\t({\n\t\t\t\t\tdebugMode,\n\t\t\t\t\tproviders,\n\t\t\t\t\tsystemContainerFactory,\n\t\t\t\t\ttenantContainerFactory,\n\t\t\t\t\tprojectContainerFactoryFactory,\n\t\t\t\t\tprojectConfigResolver,\n\t\t\t\t\ttenantGraphQLHandlerFactory,\n\t\t\t\t\tsystemGraphQLHandlerFactory,\n\t\t\t\t\tlogger,\n\t\t\t\t\tserverConfig,\n\t\t\t\t}) =>\n\t\t\t\t\tnew ProjectGroupContainerFactory(\n\t\t\t\t\t\tdebugMode,\n\t\t\t\t\t\tproviders,\n\t\t\t\t\t\tsystemContainerFactory,\n\t\t\t\t\t\ttenantContainerFactory,\n\t\t\t\t\t\tprojectContainerFactoryFactory,\n\t\t\t\t\t\tprojectConfigResolver,\n\t\t\t\t\t\ttenantGraphQLHandlerFactory,\n\t\t\t\t\t\tsystemGraphQLHandlerFactory,\n\t\t\t\t\t\tlogger,\n\t\t\t\t\t\tserverConfig.http?.geoCountryHeader,\n\t\t\t\t\t),\n\t\t\t)\n\t\t\t.addService(\n\t\t\t\t'projectGroupContainerResolver',\n\t\t\t\t({ tenantConfigResolver, projectGroupContainerFactory }) => new ProjectGroupContainerResolver(tenantConfigResolver, projectGroupContainerFactory),\n\t\t\t)\n\t\t\t.addService('promRegistryFactory', ({ processType, version }) => new PrometheusRegistryFactory(processType, { version }))\n\t\t\t.addService(\n\t\t\t\t'projectGroupContainerMetricsHook',\n\t\t\t\t({ projectGroupContainerResolver }) => new ProjectGroupContainerMetricsHook(projectGroupContainerResolver),\n\t\t\t)\n\t\t\t.addService('promRegistry', ({ promRegistryFactory, projectGroupContainerMetricsHook }) => {\n\t\t\t\tconst registry = promRegistryFactory.create()\n\t\t\t\tprojectGroupContainerMetricsHook.register(registry)\n\t\t\t\treturn registry\n\t\t\t})\n\t\t\t.addService(\n\t\t\t\t'projectGroupContainer',\n\t\t\t\t({ tenantConfigResolver, projectGroupContainerFactory }) =>\n\t\t\t\t\tprojectGroupContainerFactory.create({ slug: undefined, config: tenantConfigResolver(undefined, {}) }),\n\t\t\t)\n\t\t\t.addService('projectGroupResolver', ({ serverConfig, projectGroupContainerResolver }): ProjectGroupResolver => {\n\t\t\t\tconst encryptionKey = serverConfig.projectGroup?.configEncryptionKey\n\t\t\t\t\t? createSecretKey(Buffer.from(serverConfig.projectGroup?.configEncryptionKey, 'hex'))\n\t\t\t\t\t: undefined\n\t\t\t\treturn new ProjectGroupResolver(\n\t\t\t\t\tserverConfig.projectGroup?.domainMapping,\n\t\t\t\t\tserverConfig.projectGroup?.configHeader,\n\t\t\t\t\tserverConfig.projectGroup?.configEncryptionKey ? new CryptoWrapper(encryptionKey) : undefined,\n\t\t\t\t\tprojectGroupContainerResolver,\n\t\t\t\t)\n\t\t\t})\n\t\t\t.addService('testTransactionService', ({ serverConfig }) =>\n\t\t\t\tnew TestTransactionService(\n\t\t\t\t\tserverConfig.test?.transactions ?? false,\n\t\t\t\t\t(serverConfig.test?.transactionTtlSeconds ?? 60) * 1000,\n\t\t\t\t))\n\t\t\t.addService('notModifiedChecker', () => new NotModifiedChecker())\n\t\t\t.addService('contentQueryHandlerFactory', ({ debugMode }) => new ContentQueryHandlerFactory(debugMode))\n\t\t\t.addService('projectContextResolver', () => new ProjectContextResolver())\n\t\t\t.addService(\n\t\t\t\t'contentApiMiddlewareFactory',\n\t\t\t\t(\n\t\t\t\t\t{\n\t\t\t\t\t\tprojectContextResolver,\n\t\t\t\t\t\tnotModifiedChecker,\n\t\t\t\t\t\texecutionContainerFactory,\n\t\t\t\t\t\tcontentQueryHandlerFactory,\n\t\t\t\t\t\tgraphQlSchemaFactory,\n\t\t\t\t\t\ttestTransactionService,\n\t\t\t\t\t\tserverConfig,\n\t\t\t\t\t},\n\t\t\t\t) =>\n\t\t\t\t\tnew ContentApiControllerFactory(\n\t\t\t\t\t\tnotModifiedChecker,\n\t\t\t\t\t\texecutionContainerFactory,\n\t\t\t\t\t\tcontentQueryHandlerFactory,\n\t\t\t\t\t\tprojectContextResolver,\n\t\t\t\t\t\tgraphQlSchemaFactory,\n\t\t\t\t\t\ttestTransactionService,\n\t\t\t\t\t\tserverConfig.contentApi?.forcePrimaryHeader ?? false,\n\t\t\t\t\t),\n\t\t\t)\n\t\t\t.addService('tenantApiMiddlewareFactory', () => new TenantApiMiddlewareFactory())\n\t\t\t.addService('oidcBackchannelLogoutMiddlewareFactory', () => new OidcBackchannelLogoutMiddlewareFactory())\n\t\t\t.addService('systemGraphQLContextFactory', () => new SystemGraphQLContextFactory())\n\t\t\t.addService(\n\t\t\t\t'systemApiMiddlewareFactory',\n\t\t\t\t({ debugMode, systemGraphQLContextFactory, projectContextResolver }) =>\n\t\t\t\t\tnew SystemApiMiddlewareFactory(debugMode, systemGraphQLContextFactory, projectContextResolver),\n\t\t\t)\n\t\t\t.addService('contentSchemaTransferMappingFactory', () => new ContentSchemaTransferMappingFactory())\n\t\t\t.addService('systemSchemaTransferMappingFactory', () => new SystemSchemaTransferMappingFactory())\n\t\t\t.addService(\n\t\t\t\t'importExecutor',\n\t\t\t\t({ contentSchemaTransferMappingFactory, systemSchemaTransferMappingFactory, databaseMetadataResolver }) =>\n\t\t\t\t\tnew ImportExecutor(contentSchemaTransferMappingFactory, systemSchemaTransferMappingFactory, databaseMetadataResolver),\n\t\t\t)\n\t\t\t.addService(\n\t\t\t\t'exportExecutor',\n\t\t\t\t({ contentSchemaTransferMappingFactory, systemSchemaTransferMappingFactory }) =>\n\t\t\t\t\tnew ExportExecutor(contentSchemaTransferMappingFactory, systemSchemaTransferMappingFactory),\n\t\t\t)\n\t\t\t.addService(\n\t\t\t\t'importApiMiddlewareFactory',\n\t\t\t\t({ projectGroupResolver, importExecutor }) => new ImportApiMiddlewareFactory(projectGroupResolver, importExecutor),\n\t\t\t)\n\t\t\t.addService(\n\t\t\t\t'exportApiMiddlewareFactory',\n\t\t\t\t({ projectGroupResolver, exportExecutor }) => new ExportApiControllerFactory(projectGroupResolver, exportExecutor),\n\t\t\t)\n\t\t\t// Replaced by the panel plugin when it serves the panel; see `PanelApiMount`. Declared here so\n\t\t\t// a plugin can mount its API into the panel without depending on the panel package.\n\t\t\t.addService('panelApiMount', (): PanelApiMount => new DisabledPanelApiMount())\n\t\t\t.addService('application', ({ projectGroupResolver, serverConfig, logger, debugMode, version, promRegistry }) => {\n\t\t\t\tconst app = new Application(\n\t\t\t\t\tprojectGroupResolver,\n\t\t\t\t\tserverConfig,\n\t\t\t\t\tdebugMode,\n\t\t\t\t\tversion,\n\t\t\t\t\tlogger,\n\t\t\t\t)\n\t\t\t\tapp.addMiddleware(createColllectHttpMetricsMiddleware(promRegistry))\n\n\t\t\t\treturn app\n\t\t\t})\n\t\t\t.setupService(\n\t\t\t\t'application',\n\t\t\t\t(\n\t\t\t\t\tit,\n\t\t\t\t\t{\n\t\t\t\t\t\tcontentApiMiddlewareFactory,\n\t\t\t\t\t\ttenantApiMiddlewareFactory,\n\t\t\t\t\t\toidcBackchannelLogoutMiddlewareFactory,\n\t\t\t\t\t\tsystemApiMiddlewareFactory,\n\t\t\t\t\t\timportApiMiddlewareFactory,\n\t\t\t\t\t\texportApiMiddlewareFactory,\n\t\t\t\t\t\ttestTransactionService,\n\t\t\t\t\t},\n\t\t\t\t) => {\n\t\t\t\t\tit.addRoute('content', '/content/:projectSlug/:stageSlug', contentApiMiddlewareFactory.create())\n\t\t\t\t\tit.addRoute('tenant', '/tenant', tenantApiMiddlewareFactory.create())\n\t\t\t\t\t// Register under a dedicated, non-GraphQL module so it is excluded from `forceHttpOk`\n\t\t\t\t\t// status coercion (graphqlModules = content/tenant/system): the OIDC Back-Channel Logout\n\t\t\t\t\t// response is not a GraphQL `{data,errors}` envelope and its HTTP status is part of the\n\t\t\t\t\t// spec contract (the IdP relies on a non-2xx status to detect/retry a failed logout).\n\t\t\t\t\tit.addRoute('oidc', '/oidc/backchannel-logout', oidcBackchannelLogoutMiddlewareFactory.create())\n\t\t\t\t\tit.addRoute('system', '/system/:projectSlug', systemApiMiddlewareFactory.create())\n\t\t\t\t\tit.addRoute('transfer', '/import', importApiMiddlewareFactory.create())\n\t\t\t\t\tit.addRoute('transfer', '/export', exportApiMiddlewareFactory.create())\n\t\t\t\t\tit.addRoute('misc', '/', homepageController)\n\n\t\t\t\t\tit.addInternalRoute('internal', '/health', () => {\n\t\t\t\t\t\treturn new HttpResponse(200, 'OK')\n\t\t\t\t\t})\n\n\t\t\t\t\tif (testTransactionService.isEnabled()) {\n\t\t\t\t\t\tit.addInternalRoute('test', '/test/transaction', async ({ koa }) => {\n\t\t\t\t\t\t\tconst method = koa.request.method\n\t\t\t\t\t\t\tif (method === 'POST') {\n\t\t\t\t\t\t\t\treturn new HttpResponse(200, JSON.stringify({ token: testTransactionService.begin() }), 'application/json')\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (method === 'DELETE') {\n\t\t\t\t\t\t\t\tconst token = koa.get('x-contember-test-session')\n\t\t\t\t\t\t\t\tconst ok = token ? await testTransactionService.rollback(token) : false\n\t\t\t\t\t\t\t\treturn new HttpResponse(ok ? 200 : 404, JSON.stringify({ ok }), 'application/json')\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn new HttpResponse(405, JSON.stringify({ error: 'Method not allowed' }), 'application/json')\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t)\n\t\t\t.addService('initializer', ({ projectGroupContainer }) => new Initializer(projectGroupContainer))\n\t\t\t.addService('applicationWorkers', () => new ApplicationWorkerManager())\n\t\t\t.setupService('executionContainerFactory', (it, { plugins }) => {\n\t\t\t\tfor (const plugin of plugins) {\n\t\t\t\t\tif (plugin.getExecutionContainerHook) {\n\t\t\t\t\t\tit.hooks.push(plugin.getExecutionContainerHook())\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t})\n\t\t\t.addService('monitoringKoa', ({ promRegistry }) => {\n\t\t\t\tconst app = new Koa()\n\t\t\t\tapp.use(createShowMetricsMiddleware(promRegistry))\n\t\t\t\tapp.use(createNotFoundMiddleware())\n\n\t\t\t\treturn app\n\t\t\t})\n\t}\n\n\tcreate(args: MasterContainerArgs): MasterContainer {\n\t\tconst container = this.createBuilder(args).build()\n\t\treturn container.pick('initializer', 'application', 'providers', 'applicationWorkers', 'monitoringKoa')\n\t}\n}\n"],"names":["Builder","createProviders","providers","TenantContainerFactory","ModificationHandlerFactory","serverConfig","ExecutionContainerFactory","GraphQlSchemaBuilderFactory","ContentQueryExecutorImpl","SystemContainerFactory","PermissionFactory","DatabaseMetadataResolver","ContentApiSpecificCache","plugins","GraphQlSchemaFactory","ProjectContainerFactoryFactory","TenantGraphQLHandlerFactory","debugMode","SystemGraphQLHandlerFactory","projectConfigResolver","logger","ProjectGroupContainerFactory","tenantConfigResolver","ProjectGroupContainerResolver","processType","version","PrometheusRegistryFactory","ProjectGroupContainerMetricsHook","createSecretKey","ProjectGroupResolver","CryptoWrapper","TestTransactionService","NotModifiedChecker","ContentQueryHandlerFactory","ProjectContextResolver","ContentApiControllerFactory","TenantApiMiddlewareFactory","OidcBackchannelLogoutMiddlewareFactory","SystemGraphQLContextFactory","SystemApiMiddlewareFactory","ContentSchemaTransferMappingFactory","SystemSchemaTransferMappingFactory","ImportExecutor","ExportExecutor","ImportApiMiddlewareFactory","ExportApiControllerFactory","DisabledPanelApiMount","Application","createColllectHttpMetricsMiddleware","homepageController","HttpResponse","Initializer","ApplicationWorkerManager","createShowMetricsMiddleware","createNotFoundMiddleware"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiFO,MAAM,uBAAuB;AAAA,EACnC,cAAc,MAAmD;AAChE,UAAM,UAAU,KAAK,sBAAsB,IAAI;AAC/C,UAAM,QAAQ,KAAK,QACjB,IAAI,CAAA,OAAM,GAAG,yBAAA,CAA0B,EACvC,OAAO,CAAC,OAAkC,OAAO,MAAS;AAC5D,WAAO,MAAM,OAAO,CAAC,KAAK,OAAO,GAAG,GAAG,GAAG,OAAO;AA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AAClE,qBAAO,IAAIA,aAAAA,aAAa,KAAK,MAAM,KAAK,KAAK,UAAU,EAAE,IAAI,GAAG,kBAAkB;AAAA,YACnF;AACA,mBAAO,IAAIA,aAAAA,aAAa,KAAK,KAAK,UAAU,EAAE,OAAO,sBAAsB,GAAG,kBAAkB;AAAA,UACjG,CAAC;AAAA,QACF;AAAA,MACD;AAAA,IAAA,EAEA,WAAW,eAAe,CAAC,EAAE,sBAAA,MAA4B,IAAIC,YAAAA,YAAY,qBAAqB,CAAC,EAC/F,WAAW,sBAAsB,MAAM,IAAIC,yBAAAA,0BAA0B,EACrE,aAAa,6BAA6B,CAAC,IAAI,EAAE,SAAAvC,eAAc;AAC/D,iBAAW,UAAUA,UAAS;AAC7B,YAAI,OAAO,2BAA2B;AACrC,aAAG,MAAM,KAAK,OAAO,0BAAA,CAA2B;AAAA,QACjD;AAAA,MACD;AAAA,IACD,CAAC,EACA,WAAW,iBAAiB,CAAC,EAAE,mBAAmB;AAClD,YAAM,MAAM,IAAI,IAAA;AAChB,UAAI,IAAIwC,kDAA4B,YAAY,CAAC;AACjD,UAAI,IAAIC,mBAAAA,0BAA0B;AAElC,aAAO;AAAA,IACR,CAAC;AAAA,EACH;AAAA,EAEA,OAAO,MAA4C;AAClD,UAAM,YAAY,KAAK,cAAc,IAAI,EAAE,MAAA;AAC3C,WAAO,UAAU,KAAK,eAAe,eAAe,aAAa,sBAAsB,eAAe;AAAA,EACvG;AACD;;"}
@@ -143,14 +143,16 @@ class MasterContainerFactory {
143
143
  executionContainerFactory,
144
144
  contentQueryHandlerFactory,
145
145
  graphQlSchemaFactory,
146
- testTransactionService
146
+ testTransactionService,
147
+ serverConfig: serverConfig2
147
148
  }) => new ContentApiControllerFactory(
148
149
  notModifiedChecker,
149
150
  executionContainerFactory,
150
151
  contentQueryHandlerFactory,
151
152
  projectContextResolver,
152
153
  graphQlSchemaFactory,
153
- testTransactionService
154
+ testTransactionService,
155
+ serverConfig2.contentApi?.forcePrimaryHeader ?? false
154
156
  )
155
157
  ).addService("tenantApiMiddlewareFactory", () => new TenantApiMiddlewareFactory()).addService("oidcBackchannelLogoutMiddlewareFactory", () => new OidcBackchannelLogoutMiddlewareFactory()).addService("systemGraphQLContextFactory", () => new SystemGraphQLContextFactory()).addService(
156
158
  "systemApiMiddlewareFactory",
@@ -1 +1 @@
1
- {"version":3,"file":"MasterContainer.js","sources":["../../../../packages/engine-http/src/MasterContainer.ts"],"sourcesContent":["import { Builder } from '@contember/dic'\nimport { SystemContainerFactory } from '@contember/engine-system-api'\nimport { TenantContainerFactory } from '@contember/engine-tenant-api'\nimport { ModificationHandlerFactory } from '@contember/schema-migrations'\nimport { Initializer } from './bootstrap/index.js'\nimport { Env, ServerConfig } from './config/config.js'\n\nimport { DatabaseMetadataResolver } from '@contember/database'\nimport { ExecutionContainerFactory, GraphQlSchemaBuilderFactory, PermissionFactory } from '@contember/engine-content-api'\nimport { Logger } from '@contember/logger'\nimport { Schema } from '@contember/schema'\nimport Koa from 'koa'\nimport { createSecretKey } from 'node:crypto'\nimport { Application, DisabledPanelApiMount, PanelApiMount } from './application/index.js'\nimport { createNotFoundMiddleware, HttpResponse } from './common/index.js'\nimport { ProjectConfigResolver } from './config/projectConfigResolver.js'\nimport { TenantConfigResolver } from './config/tenantConfigResolver.js'\nimport {\n\tContentApiControllerFactory,\n\tContentQueryHandlerFactory,\n\tGraphQLSchemaContributor,\n\tGraphQlSchemaFactory,\n\tGraphQLSchemaFactoryResult,\n\tNotModifiedChecker,\n} from './content/index.js'\nimport { ContentApiSpecificCache } from './content/ContentApiSpecificCache.js'\nimport { homepageController } from './misc/index.js'\nimport { Plugin } from './plugin/Plugin.js'\nimport { ProjectContainerFactoryFactory } from './project/index.js'\nimport { ProjectContextResolver } from './project-common/index.js'\nimport { ProjectGroupContainerFactory } from './projectGroup/ProjectGroupContainer.js'\nimport { ProjectGroupContainerResolver } from './projectGroup/ProjectGroupContainerResolver.js'\nimport { ProjectGroupResolver } from './projectGroup/ProjectGroupResolver.js'\nimport { createColllectHttpMetricsMiddleware, createShowMetricsMiddleware } from './prometheus/index.js'\nimport { ProjectGroupContainerMetricsHook } from './prometheus/ProjectGroupContainerMetricsHook.js'\nimport { PrometheusRegistryFactory } from './prometheus/PrometheusRegistryFactory.js'\nimport { createProviders, Providers } from './providers.js'\nimport { SystemApiMiddlewareFactory, SystemGraphQLContextFactory, SystemGraphQLHandlerFactory } from './system/index.js'\nimport { ContentQueryExecutorImpl } from './system/ContentQueryExecutor.js'\nimport { OidcBackchannelLogoutMiddlewareFactory, TenantApiMiddlewareFactory, TenantGraphQLHandlerFactory } from './tenant/index.js'\nimport {\n\tContentSchemaTransferMappingFactory,\n\tExportApiControllerFactory,\n\tExportExecutor,\n\tImportApiMiddlewareFactory,\n\tImportExecutor,\n\tSystemSchemaTransferMappingFactory,\n} from './transfer/index.js'\nimport { CryptoWrapper } from './utils/CryptoWrapper.js'\nimport { ApplicationWorkerManager } from './workers/index.js'\nimport { TestTransactionService } from './testing/index.js'\n\nexport type ProcessType =\n\t| 'singleNode'\n\t| 'clusterMaster'\n\t| 'clusterWorker'\n\nexport interface MasterContainer {\n\tinitializer: Initializer\n\tapplication: Application\n\tproviders: Providers\n\tapplicationWorkers: ApplicationWorkerManager\n\tmonitoringKoa: Koa\n}\n\nexport interface MasterContainerArgs {\n\tdebugMode: boolean\n\tserverConfig: ServerConfig\n\tprojectConfigResolver: ProjectConfigResolver\n\ttenantConfigResolver: TenantConfigResolver\n\t/** The environment the config was resolved from, so a plugin can read its own `<PROJECT>_*` values out of it. */\n\tenv: Env\n\tplugins: Plugin[]\n\tlogger: Logger\n\tversion?: string\n\tprocessType: ProcessType\n}\n\nexport type MasterContainerBuilder = ReturnType<MasterContainerFactory['createBuilderInternal']>\nexport type MasterContainerHook = (builder: MasterContainerBuilder) => MasterContainerBuilder\n\nexport class MasterContainerFactory {\n\tcreateBuilder(args: MasterContainerArgs): MasterContainerBuilder {\n\t\tconst builder = this.createBuilderInternal(args)\n\t\tconst hooks = args.plugins\n\t\t\t.map(it => it.getMasterContainerHook?.())\n\t\t\t.filter((it): it is MasterContainerHook => it !== undefined)\n\t\treturn hooks.reduce((acc, cb) => cb(acc), builder)\n\t}\n\n\tcreateBuilderInternal({\n\t\tserverConfig,\n\t\tdebugMode,\n\t\tplugins,\n\t\tprojectConfigResolver,\n\t\ttenantConfigResolver,\n\t\tenv,\n\t\tversion,\n\t\tlogger,\n\t\tprocessType,\n\t}: MasterContainerArgs) {\n\t\treturn new Builder({})\n\t\t\t.addService('serverConfig', () => serverConfig)\n\t\t\t.addService('env', () => env)\n\t\t\t.addService('debugMode', () => debugMode)\n\t\t\t.addService('version', () => version)\n\t\t\t.addService('processType', () => processType)\n\t\t\t.addService('projectConfigResolver', () => projectConfigResolver)\n\t\t\t.addService('tenantConfigResolver', () => tenantConfigResolver)\n\t\t\t.addService('plugins', () => plugins)\n\t\t\t.addService('providers', () => createProviders())\n\t\t\t.addService('tenantContainerFactory', ({ providers }) => new TenantContainerFactory(providers))\n\t\t\t.addService('modificationHandlerFactory', () => new ModificationHandlerFactory(ModificationHandlerFactory.defaultFactoryMap))\n\t\t\t.addService(\n\t\t\t\t'executionContainerFactory',\n\t\t\t\t({ providers, serverConfig }) => new ExecutionContainerFactory(providers, serverConfig.contentApi?.whereOptimizer),\n\t\t\t)\n\t\t\t.addService('graphQlSchemaBuilderFactory', () => new GraphQlSchemaBuilderFactory())\n\t\t\t.addService(\n\t\t\t\t'contentQueryExecutor',\n\t\t\t\t({ executionContainerFactory, graphQlSchemaBuilderFactory }) =>\n\t\t\t\t\tnew ContentQueryExecutorImpl(executionContainerFactory, graphQlSchemaBuilderFactory),\n\t\t\t)\n\t\t\t.addService(\n\t\t\t\t'systemContainerFactory',\n\t\t\t\t({ providers, modificationHandlerFactory, contentQueryExecutor }) =>\n\t\t\t\t\tnew SystemContainerFactory(providers, modificationHandlerFactory, contentQueryExecutor),\n\t\t\t)\n\t\t\t.addService('contentPermissionFactory', ({}) => new PermissionFactory())\n\t\t\t.addService('databaseMetadataResolver', () => new DatabaseMetadataResolver())\n\t\t\t.addService('graphqlSchemaCache', ({ serverConfig }) =>\n\t\t\t\tnew ContentApiSpecificCache<Schema, GraphQLSchemaFactoryResult>({\n\t\t\t\t\tttlSeconds: serverConfig.contentApi?.schemaCacheTtlSeconds,\n\t\t\t\t}))\n\t\t\t.addService('graphQlSchemaFactory', ({ plugins, providers, graphqlSchemaCache, contentPermissionFactory, graphQlSchemaBuilderFactory }) => {\n\t\t\t\tconst contributors = plugins\n\t\t\t\t\t.map(it => (it.getSchemaContributor ? it.getSchemaContributor({ providers }) : null))\n\t\t\t\t\t.filter((it): it is GraphQLSchemaContributor => !!it)\n\n\t\t\t\treturn new GraphQlSchemaFactory(\n\t\t\t\t\tgraphqlSchemaCache,\n\t\t\t\t\tgraphQlSchemaBuilderFactory,\n\t\t\t\t\tcontentPermissionFactory,\n\t\t\t\t\tcontributors,\n\t\t\t\t)\n\t\t\t})\n\t\t\t.addService(\n\t\t\t\t'projectContainerFactoryFactory',\n\t\t\t\t({ plugins, providers, databaseMetadataResolver }) => new ProjectContainerFactoryFactory(plugins, providers, databaseMetadataResolver),\n\t\t\t)\n\t\t\t.addService('tenantGraphQLHandlerFactory', () => new TenantGraphQLHandlerFactory())\n\t\t\t.addService('systemGraphQLHandlerFactory', ({ debugMode }) => new SystemGraphQLHandlerFactory(debugMode))\n\t\t\t.addService('logger', () => logger)\n\t\t\t.addService(\n\t\t\t\t'projectGroupContainerFactory',\n\t\t\t\t({\n\t\t\t\t\tdebugMode,\n\t\t\t\t\tproviders,\n\t\t\t\t\tsystemContainerFactory,\n\t\t\t\t\ttenantContainerFactory,\n\t\t\t\t\tprojectContainerFactoryFactory,\n\t\t\t\t\tprojectConfigResolver,\n\t\t\t\t\ttenantGraphQLHandlerFactory,\n\t\t\t\t\tsystemGraphQLHandlerFactory,\n\t\t\t\t\tlogger,\n\t\t\t\t\tserverConfig,\n\t\t\t\t}) =>\n\t\t\t\t\tnew ProjectGroupContainerFactory(\n\t\t\t\t\t\tdebugMode,\n\t\t\t\t\t\tproviders,\n\t\t\t\t\t\tsystemContainerFactory,\n\t\t\t\t\t\ttenantContainerFactory,\n\t\t\t\t\t\tprojectContainerFactoryFactory,\n\t\t\t\t\t\tprojectConfigResolver,\n\t\t\t\t\t\ttenantGraphQLHandlerFactory,\n\t\t\t\t\t\tsystemGraphQLHandlerFactory,\n\t\t\t\t\t\tlogger,\n\t\t\t\t\t\tserverConfig.http?.geoCountryHeader,\n\t\t\t\t\t),\n\t\t\t)\n\t\t\t.addService(\n\t\t\t\t'projectGroupContainerResolver',\n\t\t\t\t({ tenantConfigResolver, projectGroupContainerFactory }) => new ProjectGroupContainerResolver(tenantConfigResolver, projectGroupContainerFactory),\n\t\t\t)\n\t\t\t.addService('promRegistryFactory', ({ processType, version }) => new PrometheusRegistryFactory(processType, { version }))\n\t\t\t.addService(\n\t\t\t\t'projectGroupContainerMetricsHook',\n\t\t\t\t({ projectGroupContainerResolver }) => new ProjectGroupContainerMetricsHook(projectGroupContainerResolver),\n\t\t\t)\n\t\t\t.addService('promRegistry', ({ promRegistryFactory, projectGroupContainerMetricsHook }) => {\n\t\t\t\tconst registry = promRegistryFactory.create()\n\t\t\t\tprojectGroupContainerMetricsHook.register(registry)\n\t\t\t\treturn registry\n\t\t\t})\n\t\t\t.addService(\n\t\t\t\t'projectGroupContainer',\n\t\t\t\t({ tenantConfigResolver, projectGroupContainerFactory }) =>\n\t\t\t\t\tprojectGroupContainerFactory.create({ slug: undefined, config: tenantConfigResolver(undefined, {}) }),\n\t\t\t)\n\t\t\t.addService('projectGroupResolver', ({ serverConfig, projectGroupContainerResolver }): ProjectGroupResolver => {\n\t\t\t\tconst encryptionKey = serverConfig.projectGroup?.configEncryptionKey\n\t\t\t\t\t? createSecretKey(Buffer.from(serverConfig.projectGroup?.configEncryptionKey, 'hex'))\n\t\t\t\t\t: undefined\n\t\t\t\treturn new ProjectGroupResolver(\n\t\t\t\t\tserverConfig.projectGroup?.domainMapping,\n\t\t\t\t\tserverConfig.projectGroup?.configHeader,\n\t\t\t\t\tserverConfig.projectGroup?.configEncryptionKey ? new CryptoWrapper(encryptionKey) : undefined,\n\t\t\t\t\tprojectGroupContainerResolver,\n\t\t\t\t)\n\t\t\t})\n\t\t\t.addService('testTransactionService', ({ serverConfig }) =>\n\t\t\t\tnew TestTransactionService(\n\t\t\t\t\tserverConfig.test?.transactions ?? false,\n\t\t\t\t\t(serverConfig.test?.transactionTtlSeconds ?? 60) * 1000,\n\t\t\t\t))\n\t\t\t.addService('notModifiedChecker', () => new NotModifiedChecker())\n\t\t\t.addService('contentQueryHandlerFactory', ({ debugMode }) => new ContentQueryHandlerFactory(debugMode))\n\t\t\t.addService('projectContextResolver', () => new ProjectContextResolver())\n\t\t\t.addService(\n\t\t\t\t'contentApiMiddlewareFactory',\n\t\t\t\t(\n\t\t\t\t\t{\n\t\t\t\t\t\tprojectContextResolver,\n\t\t\t\t\t\tnotModifiedChecker,\n\t\t\t\t\t\texecutionContainerFactory,\n\t\t\t\t\t\tcontentQueryHandlerFactory,\n\t\t\t\t\t\tgraphQlSchemaFactory,\n\t\t\t\t\t\ttestTransactionService,\n\t\t\t\t\t},\n\t\t\t\t) =>\n\t\t\t\t\tnew ContentApiControllerFactory(\n\t\t\t\t\t\tnotModifiedChecker,\n\t\t\t\t\t\texecutionContainerFactory,\n\t\t\t\t\t\tcontentQueryHandlerFactory,\n\t\t\t\t\t\tprojectContextResolver,\n\t\t\t\t\t\tgraphQlSchemaFactory,\n\t\t\t\t\t\ttestTransactionService,\n\t\t\t\t\t),\n\t\t\t)\n\t\t\t.addService('tenantApiMiddlewareFactory', () => new TenantApiMiddlewareFactory())\n\t\t\t.addService('oidcBackchannelLogoutMiddlewareFactory', () => new OidcBackchannelLogoutMiddlewareFactory())\n\t\t\t.addService('systemGraphQLContextFactory', () => new SystemGraphQLContextFactory())\n\t\t\t.addService(\n\t\t\t\t'systemApiMiddlewareFactory',\n\t\t\t\t({ debugMode, systemGraphQLContextFactory, projectContextResolver }) =>\n\t\t\t\t\tnew SystemApiMiddlewareFactory(debugMode, systemGraphQLContextFactory, projectContextResolver),\n\t\t\t)\n\t\t\t.addService('contentSchemaTransferMappingFactory', () => new ContentSchemaTransferMappingFactory())\n\t\t\t.addService('systemSchemaTransferMappingFactory', () => new SystemSchemaTransferMappingFactory())\n\t\t\t.addService(\n\t\t\t\t'importExecutor',\n\t\t\t\t({ contentSchemaTransferMappingFactory, systemSchemaTransferMappingFactory, databaseMetadataResolver }) =>\n\t\t\t\t\tnew ImportExecutor(contentSchemaTransferMappingFactory, systemSchemaTransferMappingFactory, databaseMetadataResolver),\n\t\t\t)\n\t\t\t.addService(\n\t\t\t\t'exportExecutor',\n\t\t\t\t({ contentSchemaTransferMappingFactory, systemSchemaTransferMappingFactory }) =>\n\t\t\t\t\tnew ExportExecutor(contentSchemaTransferMappingFactory, systemSchemaTransferMappingFactory),\n\t\t\t)\n\t\t\t.addService(\n\t\t\t\t'importApiMiddlewareFactory',\n\t\t\t\t({ projectGroupResolver, importExecutor }) => new ImportApiMiddlewareFactory(projectGroupResolver, importExecutor),\n\t\t\t)\n\t\t\t.addService(\n\t\t\t\t'exportApiMiddlewareFactory',\n\t\t\t\t({ projectGroupResolver, exportExecutor }) => new ExportApiControllerFactory(projectGroupResolver, exportExecutor),\n\t\t\t)\n\t\t\t// Replaced by the panel plugin when it serves the panel; see `PanelApiMount`. Declared here so\n\t\t\t// a plugin can mount its API into the panel without depending on the panel package.\n\t\t\t.addService('panelApiMount', (): PanelApiMount => new DisabledPanelApiMount())\n\t\t\t.addService('application', ({ projectGroupResolver, serverConfig, logger, debugMode, version, promRegistry }) => {\n\t\t\t\tconst app = new Application(\n\t\t\t\t\tprojectGroupResolver,\n\t\t\t\t\tserverConfig,\n\t\t\t\t\tdebugMode,\n\t\t\t\t\tversion,\n\t\t\t\t\tlogger,\n\t\t\t\t)\n\t\t\t\tapp.addMiddleware(createColllectHttpMetricsMiddleware(promRegistry))\n\n\t\t\t\treturn app\n\t\t\t})\n\t\t\t.setupService(\n\t\t\t\t'application',\n\t\t\t\t(\n\t\t\t\t\tit,\n\t\t\t\t\t{\n\t\t\t\t\t\tcontentApiMiddlewareFactory,\n\t\t\t\t\t\ttenantApiMiddlewareFactory,\n\t\t\t\t\t\toidcBackchannelLogoutMiddlewareFactory,\n\t\t\t\t\t\tsystemApiMiddlewareFactory,\n\t\t\t\t\t\timportApiMiddlewareFactory,\n\t\t\t\t\t\texportApiMiddlewareFactory,\n\t\t\t\t\t\ttestTransactionService,\n\t\t\t\t\t},\n\t\t\t\t) => {\n\t\t\t\t\tit.addRoute('content', '/content/:projectSlug/:stageSlug', contentApiMiddlewareFactory.create())\n\t\t\t\t\tit.addRoute('tenant', '/tenant', tenantApiMiddlewareFactory.create())\n\t\t\t\t\t// Register under a dedicated, non-GraphQL module so it is excluded from `forceHttpOk`\n\t\t\t\t\t// status coercion (graphqlModules = content/tenant/system): the OIDC Back-Channel Logout\n\t\t\t\t\t// response is not a GraphQL `{data,errors}` envelope and its HTTP status is part of the\n\t\t\t\t\t// spec contract (the IdP relies on a non-2xx status to detect/retry a failed logout).\n\t\t\t\t\tit.addRoute('oidc', '/oidc/backchannel-logout', oidcBackchannelLogoutMiddlewareFactory.create())\n\t\t\t\t\tit.addRoute('system', '/system/:projectSlug', systemApiMiddlewareFactory.create())\n\t\t\t\t\tit.addRoute('transfer', '/import', importApiMiddlewareFactory.create())\n\t\t\t\t\tit.addRoute('transfer', '/export', exportApiMiddlewareFactory.create())\n\t\t\t\t\tit.addRoute('misc', '/', homepageController)\n\n\t\t\t\t\tit.addInternalRoute('internal', '/health', () => {\n\t\t\t\t\t\treturn new HttpResponse(200, 'OK')\n\t\t\t\t\t})\n\n\t\t\t\t\tif (testTransactionService.isEnabled()) {\n\t\t\t\t\t\tit.addInternalRoute('test', '/test/transaction', async ({ koa }) => {\n\t\t\t\t\t\t\tconst method = koa.request.method\n\t\t\t\t\t\t\tif (method === 'POST') {\n\t\t\t\t\t\t\t\treturn new HttpResponse(200, JSON.stringify({ token: testTransactionService.begin() }), 'application/json')\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (method === 'DELETE') {\n\t\t\t\t\t\t\t\tconst token = koa.get('x-contember-test-session')\n\t\t\t\t\t\t\t\tconst ok = token ? await testTransactionService.rollback(token) : false\n\t\t\t\t\t\t\t\treturn new HttpResponse(ok ? 200 : 404, JSON.stringify({ ok }), 'application/json')\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn new HttpResponse(405, JSON.stringify({ error: 'Method not allowed' }), 'application/json')\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t)\n\t\t\t.addService('initializer', ({ projectGroupContainer }) => new Initializer(projectGroupContainer))\n\t\t\t.addService('applicationWorkers', () => new ApplicationWorkerManager())\n\t\t\t.setupService('executionContainerFactory', (it, { plugins }) => {\n\t\t\t\tfor (const plugin of plugins) {\n\t\t\t\t\tif (plugin.getExecutionContainerHook) {\n\t\t\t\t\t\tit.hooks.push(plugin.getExecutionContainerHook())\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t})\n\t\t\t.addService('monitoringKoa', ({ promRegistry }) => {\n\t\t\t\tconst app = new Koa()\n\t\t\t\tapp.use(createShowMetricsMiddleware(promRegistry))\n\t\t\t\tapp.use(createNotFoundMiddleware())\n\n\t\t\t\treturn app\n\t\t\t})\n\t}\n\n\tcreate(args: MasterContainerArgs): MasterContainer {\n\t\tconst container = this.createBuilder(args).build()\n\t\treturn container.pick('initializer', 'application', 'providers', 'applicationWorkers', 'monitoringKoa')\n\t}\n}\n"],"names":["serverConfig","plugins","debugMode","projectConfigResolver","logger","tenantConfigResolver","processType","version"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiFO,MAAM,uBAAuB;AAAA,EACnC,cAAc,MAAmD;AAChE,UAAM,UAAU,KAAK,sBAAs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,MAAM,IAAI,0BAA0B,EACrE,aAAa,6BAA6B,CAAC,IAAI,EAAE,SAAAH,eAAc;AAC/D,iBAAW,UAAUA,UAAS;AAC7B,YAAI,OAAO,2BAA2B;AACrC,aAAG,MAAM,KAAK,OAAO,0BAAA,CAA2B;AAAA,QACjD;AAAA,MACD;AAAA,IACD,CAAC,EACA,WAAW,iBAAiB,CAAC,EAAE,mBAAmB;AAClD,YAAM,MAAM,IAAI,IAAA;AAChB,UAAI,IAAI,4BAA4B,YAAY,CAAC;AACjD,UAAI,IAAI,0BAA0B;AAElC,aAAO;AAAA,IACR,CAAC;AAAA,EACH;AAAA,EAEA,OAAO,MAA4C;AAClD,UAAM,YAAY,KAAK,cAAc,IAAI,EAAE,MAAA;AAC3C,WAAO,UAAU,KAAK,eAAe,eAAe,aAAa,sBAAsB,eAAe;AAAA,EACvG;AACD;"}
1
+ {"version":3,"file":"MasterContainer.js","sources":["../../../../packages/engine-http/src/MasterContainer.ts"],"sourcesContent":["import { Builder } from '@contember/dic'\nimport { SystemContainerFactory } from '@contember/engine-system-api'\nimport { TenantContainerFactory } from '@contember/engine-tenant-api'\nimport { ModificationHandlerFactory } from '@contember/schema-migrations'\nimport { Initializer } from './bootstrap/index.js'\nimport { Env, ServerConfig } from './config/config.js'\n\nimport { DatabaseMetadataResolver } from '@contember/database'\nimport { ExecutionContainerFactory, GraphQlSchemaBuilderFactory, PermissionFactory } from '@contember/engine-content-api'\nimport { Logger } from '@contember/logger'\nimport { Schema } from '@contember/schema'\nimport Koa from 'koa'\nimport { createSecretKey } from 'node:crypto'\nimport { Application, DisabledPanelApiMount, PanelApiMount } from './application/index.js'\nimport { createNotFoundMiddleware, HttpResponse } from './common/index.js'\nimport { ProjectConfigResolver } from './config/projectConfigResolver.js'\nimport { TenantConfigResolver } from './config/tenantConfigResolver.js'\nimport {\n\tContentApiControllerFactory,\n\tContentQueryHandlerFactory,\n\tGraphQLSchemaContributor,\n\tGraphQlSchemaFactory,\n\tGraphQLSchemaFactoryResult,\n\tNotModifiedChecker,\n} from './content/index.js'\nimport { ContentApiSpecificCache } from './content/ContentApiSpecificCache.js'\nimport { homepageController } from './misc/index.js'\nimport { Plugin } from './plugin/Plugin.js'\nimport { ProjectContainerFactoryFactory } from './project/index.js'\nimport { ProjectContextResolver } from './project-common/index.js'\nimport { ProjectGroupContainerFactory } from './projectGroup/ProjectGroupContainer.js'\nimport { ProjectGroupContainerResolver } from './projectGroup/ProjectGroupContainerResolver.js'\nimport { ProjectGroupResolver } from './projectGroup/ProjectGroupResolver.js'\nimport { createColllectHttpMetricsMiddleware, createShowMetricsMiddleware } from './prometheus/index.js'\nimport { ProjectGroupContainerMetricsHook } from './prometheus/ProjectGroupContainerMetricsHook.js'\nimport { PrometheusRegistryFactory } from './prometheus/PrometheusRegistryFactory.js'\nimport { createProviders, Providers } from './providers.js'\nimport { SystemApiMiddlewareFactory, SystemGraphQLContextFactory, SystemGraphQLHandlerFactory } from './system/index.js'\nimport { ContentQueryExecutorImpl } from './system/ContentQueryExecutor.js'\nimport { OidcBackchannelLogoutMiddlewareFactory, TenantApiMiddlewareFactory, TenantGraphQLHandlerFactory } from './tenant/index.js'\nimport {\n\tContentSchemaTransferMappingFactory,\n\tExportApiControllerFactory,\n\tExportExecutor,\n\tImportApiMiddlewareFactory,\n\tImportExecutor,\n\tSystemSchemaTransferMappingFactory,\n} from './transfer/index.js'\nimport { CryptoWrapper } from './utils/CryptoWrapper.js'\nimport { ApplicationWorkerManager } from './workers/index.js'\nimport { TestTransactionService } from './testing/index.js'\n\nexport type ProcessType =\n\t| 'singleNode'\n\t| 'clusterMaster'\n\t| 'clusterWorker'\n\nexport interface MasterContainer {\n\tinitializer: Initializer\n\tapplication: Application\n\tproviders: Providers\n\tapplicationWorkers: ApplicationWorkerManager\n\tmonitoringKoa: Koa\n}\n\nexport interface MasterContainerArgs {\n\tdebugMode: boolean\n\tserverConfig: ServerConfig\n\tprojectConfigResolver: ProjectConfigResolver\n\ttenantConfigResolver: TenantConfigResolver\n\t/** The environment the config was resolved from, so a plugin can read its own `<PROJECT>_*` values out of it. */\n\tenv: Env\n\tplugins: Plugin[]\n\tlogger: Logger\n\tversion?: string\n\tprocessType: ProcessType\n}\n\nexport type MasterContainerBuilder = ReturnType<MasterContainerFactory['createBuilderInternal']>\nexport type MasterContainerHook = (builder: MasterContainerBuilder) => MasterContainerBuilder\n\nexport class MasterContainerFactory {\n\tcreateBuilder(args: MasterContainerArgs): MasterContainerBuilder {\n\t\tconst builder = this.createBuilderInternal(args)\n\t\tconst hooks = args.plugins\n\t\t\t.map(it => it.getMasterContainerHook?.())\n\t\t\t.filter((it): it is MasterContainerHook => it !== undefined)\n\t\treturn hooks.reduce((acc, cb) => cb(acc), builder)\n\t}\n\n\tcreateBuilderInternal({\n\t\tserverConfig,\n\t\tdebugMode,\n\t\tplugins,\n\t\tprojectConfigResolver,\n\t\ttenantConfigResolver,\n\t\tenv,\n\t\tversion,\n\t\tlogger,\n\t\tprocessType,\n\t}: MasterContainerArgs) {\n\t\treturn new Builder({})\n\t\t\t.addService('serverConfig', () => serverConfig)\n\t\t\t.addService('env', () => env)\n\t\t\t.addService('debugMode', () => debugMode)\n\t\t\t.addService('version', () => version)\n\t\t\t.addService('processType', () => processType)\n\t\t\t.addService('projectConfigResolver', () => projectConfigResolver)\n\t\t\t.addService('tenantConfigResolver', () => tenantConfigResolver)\n\t\t\t.addService('plugins', () => plugins)\n\t\t\t.addService('providers', () => createProviders())\n\t\t\t.addService('tenantContainerFactory', ({ providers }) => new TenantContainerFactory(providers))\n\t\t\t.addService('modificationHandlerFactory', () => new ModificationHandlerFactory(ModificationHandlerFactory.defaultFactoryMap))\n\t\t\t.addService(\n\t\t\t\t'executionContainerFactory',\n\t\t\t\t({ providers, serverConfig }) => new ExecutionContainerFactory(providers, serverConfig.contentApi?.whereOptimizer),\n\t\t\t)\n\t\t\t.addService('graphQlSchemaBuilderFactory', () => new GraphQlSchemaBuilderFactory())\n\t\t\t.addService(\n\t\t\t\t'contentQueryExecutor',\n\t\t\t\t({ executionContainerFactory, graphQlSchemaBuilderFactory }) =>\n\t\t\t\t\tnew ContentQueryExecutorImpl(executionContainerFactory, graphQlSchemaBuilderFactory),\n\t\t\t)\n\t\t\t.addService(\n\t\t\t\t'systemContainerFactory',\n\t\t\t\t({ providers, modificationHandlerFactory, contentQueryExecutor }) =>\n\t\t\t\t\tnew SystemContainerFactory(providers, modificationHandlerFactory, contentQueryExecutor),\n\t\t\t)\n\t\t\t.addService('contentPermissionFactory', ({}) => new PermissionFactory())\n\t\t\t.addService('databaseMetadataResolver', () => new DatabaseMetadataResolver())\n\t\t\t.addService('graphqlSchemaCache', ({ serverConfig }) =>\n\t\t\t\tnew ContentApiSpecificCache<Schema, GraphQLSchemaFactoryResult>({\n\t\t\t\t\tttlSeconds: serverConfig.contentApi?.schemaCacheTtlSeconds,\n\t\t\t\t}))\n\t\t\t.addService('graphQlSchemaFactory', ({ plugins, providers, graphqlSchemaCache, contentPermissionFactory, graphQlSchemaBuilderFactory }) => {\n\t\t\t\tconst contributors = plugins\n\t\t\t\t\t.map(it => (it.getSchemaContributor ? it.getSchemaContributor({ providers }) : null))\n\t\t\t\t\t.filter((it): it is GraphQLSchemaContributor => !!it)\n\n\t\t\t\treturn new GraphQlSchemaFactory(\n\t\t\t\t\tgraphqlSchemaCache,\n\t\t\t\t\tgraphQlSchemaBuilderFactory,\n\t\t\t\t\tcontentPermissionFactory,\n\t\t\t\t\tcontributors,\n\t\t\t\t)\n\t\t\t})\n\t\t\t.addService(\n\t\t\t\t'projectContainerFactoryFactory',\n\t\t\t\t({ plugins, providers, databaseMetadataResolver }) => new ProjectContainerFactoryFactory(plugins, providers, databaseMetadataResolver),\n\t\t\t)\n\t\t\t.addService('tenantGraphQLHandlerFactory', () => new TenantGraphQLHandlerFactory())\n\t\t\t.addService('systemGraphQLHandlerFactory', ({ debugMode }) => new SystemGraphQLHandlerFactory(debugMode))\n\t\t\t.addService('logger', () => logger)\n\t\t\t.addService(\n\t\t\t\t'projectGroupContainerFactory',\n\t\t\t\t({\n\t\t\t\t\tdebugMode,\n\t\t\t\t\tproviders,\n\t\t\t\t\tsystemContainerFactory,\n\t\t\t\t\ttenantContainerFactory,\n\t\t\t\t\tprojectContainerFactoryFactory,\n\t\t\t\t\tprojectConfigResolver,\n\t\t\t\t\ttenantGraphQLHandlerFactory,\n\t\t\t\t\tsystemGraphQLHandlerFactory,\n\t\t\t\t\tlogger,\n\t\t\t\t\tserverConfig,\n\t\t\t\t}) =>\n\t\t\t\t\tnew ProjectGroupContainerFactory(\n\t\t\t\t\t\tdebugMode,\n\t\t\t\t\t\tproviders,\n\t\t\t\t\t\tsystemContainerFactory,\n\t\t\t\t\t\ttenantContainerFactory,\n\t\t\t\t\t\tprojectContainerFactoryFactory,\n\t\t\t\t\t\tprojectConfigResolver,\n\t\t\t\t\t\ttenantGraphQLHandlerFactory,\n\t\t\t\t\t\tsystemGraphQLHandlerFactory,\n\t\t\t\t\t\tlogger,\n\t\t\t\t\t\tserverConfig.http?.geoCountryHeader,\n\t\t\t\t\t),\n\t\t\t)\n\t\t\t.addService(\n\t\t\t\t'projectGroupContainerResolver',\n\t\t\t\t({ tenantConfigResolver, projectGroupContainerFactory }) => new ProjectGroupContainerResolver(tenantConfigResolver, projectGroupContainerFactory),\n\t\t\t)\n\t\t\t.addService('promRegistryFactory', ({ processType, version }) => new PrometheusRegistryFactory(processType, { version }))\n\t\t\t.addService(\n\t\t\t\t'projectGroupContainerMetricsHook',\n\t\t\t\t({ projectGroupContainerResolver }) => new ProjectGroupContainerMetricsHook(projectGroupContainerResolver),\n\t\t\t)\n\t\t\t.addService('promRegistry', ({ promRegistryFactory, projectGroupContainerMetricsHook }) => {\n\t\t\t\tconst registry = promRegistryFactory.create()\n\t\t\t\tprojectGroupContainerMetricsHook.register(registry)\n\t\t\t\treturn registry\n\t\t\t})\n\t\t\t.addService(\n\t\t\t\t'projectGroupContainer',\n\t\t\t\t({ tenantConfigResolver, projectGroupContainerFactory }) =>\n\t\t\t\t\tprojectGroupContainerFactory.create({ slug: undefined, config: tenantConfigResolver(undefined, {}) }),\n\t\t\t)\n\t\t\t.addService('projectGroupResolver', ({ serverConfig, projectGroupContainerResolver }): ProjectGroupResolver => {\n\t\t\t\tconst encryptionKey = serverConfig.projectGroup?.configEncryptionKey\n\t\t\t\t\t? createSecretKey(Buffer.from(serverConfig.projectGroup?.configEncryptionKey, 'hex'))\n\t\t\t\t\t: undefined\n\t\t\t\treturn new ProjectGroupResolver(\n\t\t\t\t\tserverConfig.projectGroup?.domainMapping,\n\t\t\t\t\tserverConfig.projectGroup?.configHeader,\n\t\t\t\t\tserverConfig.projectGroup?.configEncryptionKey ? new CryptoWrapper(encryptionKey) : undefined,\n\t\t\t\t\tprojectGroupContainerResolver,\n\t\t\t\t)\n\t\t\t})\n\t\t\t.addService('testTransactionService', ({ serverConfig }) =>\n\t\t\t\tnew TestTransactionService(\n\t\t\t\t\tserverConfig.test?.transactions ?? false,\n\t\t\t\t\t(serverConfig.test?.transactionTtlSeconds ?? 60) * 1000,\n\t\t\t\t))\n\t\t\t.addService('notModifiedChecker', () => new NotModifiedChecker())\n\t\t\t.addService('contentQueryHandlerFactory', ({ debugMode }) => new ContentQueryHandlerFactory(debugMode))\n\t\t\t.addService('projectContextResolver', () => new ProjectContextResolver())\n\t\t\t.addService(\n\t\t\t\t'contentApiMiddlewareFactory',\n\t\t\t\t(\n\t\t\t\t\t{\n\t\t\t\t\t\tprojectContextResolver,\n\t\t\t\t\t\tnotModifiedChecker,\n\t\t\t\t\t\texecutionContainerFactory,\n\t\t\t\t\t\tcontentQueryHandlerFactory,\n\t\t\t\t\t\tgraphQlSchemaFactory,\n\t\t\t\t\t\ttestTransactionService,\n\t\t\t\t\t\tserverConfig,\n\t\t\t\t\t},\n\t\t\t\t) =>\n\t\t\t\t\tnew ContentApiControllerFactory(\n\t\t\t\t\t\tnotModifiedChecker,\n\t\t\t\t\t\texecutionContainerFactory,\n\t\t\t\t\t\tcontentQueryHandlerFactory,\n\t\t\t\t\t\tprojectContextResolver,\n\t\t\t\t\t\tgraphQlSchemaFactory,\n\t\t\t\t\t\ttestTransactionService,\n\t\t\t\t\t\tserverConfig.contentApi?.forcePrimaryHeader ?? false,\n\t\t\t\t\t),\n\t\t\t)\n\t\t\t.addService('tenantApiMiddlewareFactory', () => new TenantApiMiddlewareFactory())\n\t\t\t.addService('oidcBackchannelLogoutMiddlewareFactory', () => new OidcBackchannelLogoutMiddlewareFactory())\n\t\t\t.addService('systemGraphQLContextFactory', () => new SystemGraphQLContextFactory())\n\t\t\t.addService(\n\t\t\t\t'systemApiMiddlewareFactory',\n\t\t\t\t({ debugMode, systemGraphQLContextFactory, projectContextResolver }) =>\n\t\t\t\t\tnew SystemApiMiddlewareFactory(debugMode, systemGraphQLContextFactory, projectContextResolver),\n\t\t\t)\n\t\t\t.addService('contentSchemaTransferMappingFactory', () => new ContentSchemaTransferMappingFactory())\n\t\t\t.addService('systemSchemaTransferMappingFactory', () => new SystemSchemaTransferMappingFactory())\n\t\t\t.addService(\n\t\t\t\t'importExecutor',\n\t\t\t\t({ contentSchemaTransferMappingFactory, systemSchemaTransferMappingFactory, databaseMetadataResolver }) =>\n\t\t\t\t\tnew ImportExecutor(contentSchemaTransferMappingFactory, systemSchemaTransferMappingFactory, databaseMetadataResolver),\n\t\t\t)\n\t\t\t.addService(\n\t\t\t\t'exportExecutor',\n\t\t\t\t({ contentSchemaTransferMappingFactory, systemSchemaTransferMappingFactory }) =>\n\t\t\t\t\tnew ExportExecutor(contentSchemaTransferMappingFactory, systemSchemaTransferMappingFactory),\n\t\t\t)\n\t\t\t.addService(\n\t\t\t\t'importApiMiddlewareFactory',\n\t\t\t\t({ projectGroupResolver, importExecutor }) => new ImportApiMiddlewareFactory(projectGroupResolver, importExecutor),\n\t\t\t)\n\t\t\t.addService(\n\t\t\t\t'exportApiMiddlewareFactory',\n\t\t\t\t({ projectGroupResolver, exportExecutor }) => new ExportApiControllerFactory(projectGroupResolver, exportExecutor),\n\t\t\t)\n\t\t\t// Replaced by the panel plugin when it serves the panel; see `PanelApiMount`. Declared here so\n\t\t\t// a plugin can mount its API into the panel without depending on the panel package.\n\t\t\t.addService('panelApiMount', (): PanelApiMount => new DisabledPanelApiMount())\n\t\t\t.addService('application', ({ projectGroupResolver, serverConfig, logger, debugMode, version, promRegistry }) => {\n\t\t\t\tconst app = new Application(\n\t\t\t\t\tprojectGroupResolver,\n\t\t\t\t\tserverConfig,\n\t\t\t\t\tdebugMode,\n\t\t\t\t\tversion,\n\t\t\t\t\tlogger,\n\t\t\t\t)\n\t\t\t\tapp.addMiddleware(createColllectHttpMetricsMiddleware(promRegistry))\n\n\t\t\t\treturn app\n\t\t\t})\n\t\t\t.setupService(\n\t\t\t\t'application',\n\t\t\t\t(\n\t\t\t\t\tit,\n\t\t\t\t\t{\n\t\t\t\t\t\tcontentApiMiddlewareFactory,\n\t\t\t\t\t\ttenantApiMiddlewareFactory,\n\t\t\t\t\t\toidcBackchannelLogoutMiddlewareFactory,\n\t\t\t\t\t\tsystemApiMiddlewareFactory,\n\t\t\t\t\t\timportApiMiddlewareFactory,\n\t\t\t\t\t\texportApiMiddlewareFactory,\n\t\t\t\t\t\ttestTransactionService,\n\t\t\t\t\t},\n\t\t\t\t) => {\n\t\t\t\t\tit.addRoute('content', '/content/:projectSlug/:stageSlug', contentApiMiddlewareFactory.create())\n\t\t\t\t\tit.addRoute('tenant', '/tenant', tenantApiMiddlewareFactory.create())\n\t\t\t\t\t// Register under a dedicated, non-GraphQL module so it is excluded from `forceHttpOk`\n\t\t\t\t\t// status coercion (graphqlModules = content/tenant/system): the OIDC Back-Channel Logout\n\t\t\t\t\t// response is not a GraphQL `{data,errors}` envelope and its HTTP status is part of the\n\t\t\t\t\t// spec contract (the IdP relies on a non-2xx status to detect/retry a failed logout).\n\t\t\t\t\tit.addRoute('oidc', '/oidc/backchannel-logout', oidcBackchannelLogoutMiddlewareFactory.create())\n\t\t\t\t\tit.addRoute('system', '/system/:projectSlug', systemApiMiddlewareFactory.create())\n\t\t\t\t\tit.addRoute('transfer', '/import', importApiMiddlewareFactory.create())\n\t\t\t\t\tit.addRoute('transfer', '/export', exportApiMiddlewareFactory.create())\n\t\t\t\t\tit.addRoute('misc', '/', homepageController)\n\n\t\t\t\t\tit.addInternalRoute('internal', '/health', () => {\n\t\t\t\t\t\treturn new HttpResponse(200, 'OK')\n\t\t\t\t\t})\n\n\t\t\t\t\tif (testTransactionService.isEnabled()) {\n\t\t\t\t\t\tit.addInternalRoute('test', '/test/transaction', async ({ koa }) => {\n\t\t\t\t\t\t\tconst method = koa.request.method\n\t\t\t\t\t\t\tif (method === 'POST') {\n\t\t\t\t\t\t\t\treturn new HttpResponse(200, JSON.stringify({ token: testTransactionService.begin() }), 'application/json')\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (method === 'DELETE') {\n\t\t\t\t\t\t\t\tconst token = koa.get('x-contember-test-session')\n\t\t\t\t\t\t\t\tconst ok = token ? await testTransactionService.rollback(token) : false\n\t\t\t\t\t\t\t\treturn new HttpResponse(ok ? 200 : 404, JSON.stringify({ ok }), 'application/json')\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn new HttpResponse(405, JSON.stringify({ error: 'Method not allowed' }), 'application/json')\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t)\n\t\t\t.addService('initializer', ({ projectGroupContainer }) => new Initializer(projectGroupContainer))\n\t\t\t.addService('applicationWorkers', () => new ApplicationWorkerManager())\n\t\t\t.setupService('executionContainerFactory', (it, { plugins }) => {\n\t\t\t\tfor (const plugin of plugins) {\n\t\t\t\t\tif (plugin.getExecutionContainerHook) {\n\t\t\t\t\t\tit.hooks.push(plugin.getExecutionContainerHook())\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t})\n\t\t\t.addService('monitoringKoa', ({ promRegistry }) => {\n\t\t\t\tconst app = new Koa()\n\t\t\t\tapp.use(createShowMetricsMiddleware(promRegistry))\n\t\t\t\tapp.use(createNotFoundMiddleware())\n\n\t\t\t\treturn app\n\t\t\t})\n\t}\n\n\tcreate(args: MasterContainerArgs): MasterContainer {\n\t\tconst container = this.createBuilder(args).build()\n\t\treturn container.pick('initializer', 'application', 'providers', 'applicationWorkers', 'monitoringKoa')\n\t}\n}\n"],"names":["serverConfig","plugins","debugMode","projectConfigResolver","logger","tenantConfigResolver","processType","version"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiFO,MAAM,uBAAuB;AAAA,EACnC,cAAc,MAAmD;AAChE,UAAM,UAAU,KAAK,sBAAsB,IAAI;AAC/C,UAAM,QAAQ,KAAK,QACjB,IAAI,CAAA,OAAM,GAAG,yBAAA,CAA0B,EACvC,OAAO,CAAC,OAAkC,OAAO,MAAS;AAC5D,WAAO,MAAM,OAAO,CAAC,KAAK,OAAO,GAAG,GAAG,GAAG,OAAO;AAAA,EAClD;AAAA,EAEA,sBAAsB;AAAA,IACrB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,GACuB;AACvB,WAAO,IAAI,QAAQ,CAAA,CAAE,EACnB,WAAW,gBAAgB,MAAM,YAAY,EAC7C,WAAW,OAAO,MAAM,GAAG,EAC3B,WAAW,aAAa,MAAM,SAAS,EACvC,WAAW,WAAW,MAAM,OAAO,EACnC,WAAW,eAAe,MAAM,WAAW,EAC3C,WAAW,yBAAyB,MAAM,qBAAqB,EAC/D,WAAW,wBAAwB,MAAM,oBAAoB,EAC7D,WAAW,WAAW,MAAM,OAAO,EACnC,WAAW,aAAa,MAAM,gBAAA,CAAiB,EAC/C,WAAW,0BAA0B,CAAC,EAAE,UAAA,MAAgB,IAAI,uBAAuB,SAAS,CAAC,EAC7F,WAAW,8BAA8B,MAAM,IAAI,2BAA2B,2BAA2B,iBAAiB,CAAC,EAC3H;AAAA,MACA;AAAA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AkB;AAAA,YAC3G;AACA,gBAAI,WAAW,UAAU;AACxB,oBAAM,QAAQ,IAAI,IAAI,0BAA0B;AAChD,oBAAM,KAAK,QAAQ,MAAM,uBAAuB,SAAS,KAAK,IAAI;AAClE,qBAAO,IAAI,aAAa,KAAK,MAAM,KAAK,KAAK,UAAU,EAAE,IAAI,GAAG,kBAAkB;AAAA,YACnF;AACA,mBAAO,IAAI,aAAa,KAAK,KAAK,UAAU,EAAE,OAAO,sBAAsB,GAAG,kBAAkB;AAAA,UACjG,CAAC;AAAA,QACF;AAAA,MACD;AAAA,IAAA,EAEA,WAAW,eAAe,CAAC,EAAE,sBAAA,MAA4B,IAAI,YAAY,qBAAqB,CAAC,EAC/F,WAAW,sBAAsB,MAAM,IAAI,0BAA0B,EACrE,aAAa,6BAA6B,CAAC,IAAI,EAAE,SAAAH,eAAc;AAC/D,iBAAW,UAAUA,UAAS;AAC7B,YAAI,OAAO,2BAA2B;AACrC,aAAG,MAAM,KAAK,OAAO,0BAAA,CAA2B;AAAA,QACjD;AAAA,MACD;AAAA,IACD,CAAC,EACA,WAAW,iBAAiB,CAAC,EAAE,mBAAmB;AAClD,YAAM,MAAM,IAAI,IAAA;AAChB,UAAI,IAAI,4BAA4B,YAAY,CAAC;AACjD,UAAI,IAAI,0BAA0B;AAElC,aAAO;AAAA,IACR,CAAC;AAAA,EACH;AAAA,EAEA,OAAO,MAA4C;AAClD,UAAM,YAAY,KAAK,cAAc,IAAI,EAAE,MAAA;AAC3C,WAAO,UAAU,KAAK,eAAe,eAAe,aAAa,sBAAsB,eAAe;AAAA,EACvG;AACD;"}
@@ -102,7 +102,7 @@ class Application {
102
102
  koa.use(bodyParser({
103
103
  jsonLimit: this.serverConfig.http?.requestBodySize || "1mb"
104
104
  }));
105
- koa.use(corsMiddleware());
105
+ koa.use(corsMiddleware({ exposeHeaders: ["X-Contember-Mutation"] }));
106
106
  const versionMatch = this.version?.match(/^(0\.\d+|\d+)/);
107
107
  const versionSimplified = versionMatch?.[1] ?? "unknown";
108
108
  koa.use(async (ctx) => {
@@ -1 +1 @@
1
- {"version":3,"file":"application.cjs","sources":["../../../../../packages/engine-http/src/application/application.ts"],"sourcesContent":["import { pathToRegexp } from 'path-to-regexp'\nimport { KoaContext, KoaMiddleware } from './types.js'\nimport { AuthResult, HttpErrorResponse, HttpResponse } from '../common/index.js'\nimport Koa from 'koa'\nimport * as http from 'node:http'\nimport { IncomingMessage, Server, ServerResponse } from 'node:http'\nimport { WebSocket, WebSocketServer } from 'ws'\nimport { FingerCrossedLoggerHandler, Logger } from '@contember/logger'\nimport koaCompress from 'koa-compress'\nimport bodyParser from 'koa-bodyparser'\nimport { ServerConfig } from '../config/config.js'\nimport corsMiddleware from '@koa/cors'\nimport stream, { Duplex, Readable } from 'node:stream'\nimport { ProjectGroupResolver } from '../projectGroup/ProjectGroupResolver.js'\nimport { ProjectGroupContainer } from '../projectGroup/ProjectGroupContainer.js'\nimport { URL } from 'node:url'\nimport { cpuUsage, memoryUsage } from 'node:process'\nimport { performance } from 'node:perf_hooks'\nimport { getClientIP } from '../utils/remoteAddress.js'\nimport { isForceHttpOkRequested, shouldForceHttpOk } from './forceHttpOk.js'\n\nconst websocketCloseTimeoutMs = 5_000\n\ntype Route<C> = { match: RequestMatcher; controller: C; module: string }\nexport class Application {\n\tprivate middlewares: KoaMiddleware<any>[] = []\n\n\tprivate routes: Route<HttpController>[] = []\n\tprivate internalRoutes: Route<InternalHttpController>[] = []\n\tprivate websocketRoutes: Route<WebSocketController>[] = []\n\n\tprivate suppressAccessLog: boolean | RegExp\n\tprivate trustedProxies: string[]\n\tprivate forceHttpOkEnabled: boolean\n\n\tconstructor(\n\t\tprivate readonly projectGroupResolver: ProjectGroupResolver,\n\t\tprivate readonly serverConfig: ServerConfig,\n\t\tprivate readonly debugMode: boolean,\n\t\tprivate readonly version: string | undefined,\n\t\tprivate readonly logger: Logger,\n\t) {\n\t\tconst suppressAccessLogRaw = serverConfig.http?.suppressAccessLog\n\t\tthis.suppressAccessLog = suppressAccessLogRaw === true ? true : suppressAccessLogRaw ? new RegExp(suppressAccessLogRaw) : false\n\t\tthis.trustedProxies = serverConfig.http?.trustedProxies ?? []\n\t\tthis.forceHttpOkEnabled = serverConfig.http?.responseStatusHeader ?? true\n\t}\n\n\taddMiddleware(middleware: KoaMiddleware<any>) {\n\t\tthis.middlewares.push(middleware)\n\t}\n\n\tpublic addRoute(module: string, mask: string, controller: HttpController): void {\n\t\tthis.routes.push({\n\t\t\tmodule,\n\t\t\tcontroller,\n\t\t\tmatch: createRequestMatcher(mask),\n\t\t})\n\t}\n\n\tpublic addInternalRoute(module: string, mask: string, controller: InternalHttpController): void {\n\t\tthis.internalRoutes.push({\n\t\t\tmodule,\n\t\t\tcontroller,\n\t\t\tmatch: createRequestMatcher(mask),\n\t\t})\n\t}\n\n\tpublic addWebsocketRoute(module: string, mask: string, controller: WebSocketController): void {\n\t\tthis.websocketRoutes.push({\n\t\t\tmodule,\n\t\t\tcontroller,\n\t\t\tmatch: createRequestMatcher(mask),\n\t\t})\n\t}\n\n\tasync listen(): Promise<RunningApplication> {\n\t\tconst koa = new Koa()\n\t\tconst wss = new WebSocketServer({ noServer: true })\n\t\tlet closing = false\n\t\tkoa.use(async (ctx, next) => {\n\t\t\tif (closing) {\n\t\t\t\tctx.status = 503\n\t\t\t\tctx.set('Connection', 'close')\n\t\t\t\treturn\n\t\t\t}\n\t\t\tawait next()\n\t\t})\n\t\tfor (const middleware of this.middlewares) {\n\t\t\tkoa.use(middleware)\n\t\t}\n\t\tkoa.use(koaCompress({\n\t\t\tbr: false,\n\t\t}))\n\t\tkoa.use(bodyParser({\n\t\t\tjsonLimit: this.serverConfig.http?.requestBodySize || '1mb',\n\t\t}))\n\t\tkoa.use(corsMiddleware())\n\t\tconst versionMatch = this.version?.match(/^(0\\.\\d+|\\d+)/)\n\t\tconst versionSimplified = versionMatch?.[1] ?? 'unknown'\n\t\tkoa.use(async ctx => {\n\t\t\tctx.response.set('X-Powered-By', `Contember ${versionSimplified}` + (this.debugMode ? '-dev' : ''))\n\t\t\tawait this.handleHttpRequest(ctx)\n\t\t})\n\n\t\tconst activeHttpRequests = new Set<Promise<void>>()\n\t\tconst handleHttpRequest = koa.callback()\n\t\tconst server = http.createServer((request, response) => {\n\t\t\tif (closing) {\n\t\t\t\thandleHttpRequest(request, response)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tlet resolveRequest = () => {}\n\t\t\tconst completed = new Promise<void>(resolve => {\n\t\t\t\tresolveRequest = resolve\n\t\t\t})\n\t\t\tactiveHttpRequests.add(completed)\n\t\t\tconst complete = () => {\n\t\t\t\tresponse.off('finish', complete)\n\t\t\t\tresponse.off('close', complete)\n\t\t\t\tactiveHttpRequests.delete(completed)\n\t\t\t\tresolveRequest()\n\t\t\t}\n\t\t\tresponse.once('finish', complete)\n\t\t\tresponse.once('close', complete)\n\t\t\thandleHttpRequest(request, response)\n\t\t})\n\t\tconst abortController = new AbortController()\n\n\t\tconst wsRequests: (Promise<void>)[] = []\n\t\tserver.on('upgrade', (req, socket, head) => {\n\t\t\tif (closing) {\n\t\t\t\tthis.sendRawHttpResponse(socket, new HttpErrorResponse(503, 'Server is shutting down'))\n\t\t\t\treturn\n\t\t\t}\n\t\t\twsRequests.push(this.handleWebsocketRequest(wss, abortController.signal, req, socket, head))\n\t\t})\n\t\tawait new Promise<void>(resolve => {\n\t\t\tserver.listen(this.serverConfig.port, () => resolve())\n\t\t})\n\n\t\treturn {\n\t\t\tserver,\n\t\t\tclose: async () => {\n\t\t\t\tclosing = true\n\t\t\t\tabortController.abort()\n\t\t\t\tawait Promise.all([...wsRequests, ...activeHttpRequests])\n\t\t\t\tif (process.versions.bun !== undefined) {\n\t\t\t\t\t// Bun does not finish server.close() after a WebSocket upgrade unless all connections are closed first.\n\t\t\t\t\tserver.closeAllConnections()\n\t\t\t\t} else {\n\t\t\t\t\tserver.closeIdleConnections()\n\t\t\t\t}\n\t\t\t\tif (server.listening) {\n\t\t\t\t\tawait new Promise<void>(resolve =>\n\t\t\t\t\t\tserver.close(error => {\n\t\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\t\tthis.logger.error(error)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tresolve()\n\t\t\t\t\t\t})\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t},\n\t\t}\n\t}\n\n\tprivate async handleWebsocketRequest(\n\t\twss: WebSocketServer,\n\t\tabortSignal: AbortSignal,\n\t\treq: IncomingMessage,\n\t\tsocket: stream.Duplex,\n\t\thead: Buffer,\n\t): Promise<void> {\n\t\tlet webSocketContext: WebSocketContext | null = null\n\t\tlet requestLogger = this.logger\n\t\tconst { timer, send: sendTimer } = this.createTimer()\n\t\tconst clientIp = getClientIP(req, this.trustedProxies)\n\t\ttry {\n\t\t\tconst url = new URL(req.url ?? '/', `http://${req.headers.host}`)\n\t\t\tconst matchedRequest = this.matchRequest(this.websocketRoutes, url)\n\t\t\tif (!matchedRequest) {\n\t\t\t\tthrow new HttpErrorResponse(404, 'Route not found')\n\t\t\t}\n\t\t\trequestLogger = this.createRequestLogger(req, undefined, matchedRequest.module, clientIp)\n\n\t\t\tconst groupContainer = await this.projectGroupResolver.resolveContainer({ request: req })\n\n\t\t\trequestLogger = requestLogger.child({\n\t\t\t\tprojectGroup: groupContainer.slug,\n\t\t\t})\n\n\t\t\tconst authResult = await groupContainer.authenticator.authenticate({ request: req, timer, clientIp })\n\t\t\trequestLogger.debug('User authenticated', { authResult })\n\t\t\trequestLogger = requestLogger.child({\n\t\t\t\tuser: authResult?.identityId,\n\t\t\t})\n\n\t\t\tconst effectiveClientIp = authResult?.clientIp ?? clientIp\n\n\t\t\tif (abortSignal.aborted) {\n\t\t\t\tthrow new HttpErrorResponse(503, 'Server is shutting down')\n\t\t\t}\n\t\t\tconst ws = await new Promise<WebSocket>(resolve =>\n\t\t\t\twss.handleUpgrade(req, socket, head, (ws, request) => {\n\t\t\t\t\tresolve(ws)\n\t\t\t\t})\n\t\t\t)\n\t\t\tconst wsEstablished = performance.now()\n\t\t\tws.on('error', e => {\n\t\t\t\trequestLogger.error(e, {\n\t\t\t\t\twebsocketOpenMs: performance.now() - wsEstablished,\n\t\t\t\t})\n\t\t\t})\n\t\t\tif (abortSignal.aborted) {\n\t\t\t\tawait this.closeWebsocket(ws)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tconst pendingWork: Promise<void>[] = []\n\t\t\twebSocketContext = {\n\t\t\t\tws,\n\t\t\t\tabortSignal,\n\t\t\t\tlogger: requestLogger,\n\t\t\t\ttimer,\n\t\t\t\turl,\n\t\t\t\trequest: req,\n\t\t\t\tclientIp: effectiveClientIp,\n\t\t\t\tauthResult,\n\t\t\t\tparams: matchedRequest.params,\n\t\t\t\tprojectGroup: groupContainer,\n\t\t\t\twaitUntil: promise => pendingWork.push(promise),\n\t\t\t}\n\t\t\tawait matchedRequest.controller(webSocketContext)\n\t\t\tif (abortSignal.aborted && ws.readyState === WebSocket.OPEN) {\n\t\t\t\tws.close(1012)\n\t\t\t}\n\t\t\trequestLogger.debug('Websocket connection established')\n\n\t\t\tif (ws.readyState !== WebSocket.CLOSED) {\n\t\t\t\tawait new Promise<void>(resolve => {\n\t\t\t\t\tws.on('close', () => {\n\t\t\t\t\t\trequestLogger.debug('Websocket connection closed', {\n\t\t\t\t\t\t\twebsocketOpenMs: performance.now() - wsEstablished,\n\t\t\t\t\t\t})\n\t\t\t\t\t\tresolve()\n\t\t\t\t\t})\n\t\t\t\t})\n\t\t\t}\n\t\t\tawait Promise.allSettled(pendingWork)\n\t\t} catch (e) {\n\t\t\tif (e instanceof HttpResponse) {\n\t\t\t\tthis.sendRawHttpResponse(socket, e)\n\t\t\t} else {\n\t\t\t\tthis.sendRawHttpResponse(socket, new HttpErrorResponse(500, 'Internal server error'))\n\t\t\t\trequestLogger.error(e)\n\t\t\t}\n\t\t\trequestLogger.debug('Websocket connection failed')\n\t\t} finally {\n\t\t\tsendTimer({\n\t\t\t\treq,\n\t\t\t\trequestDebugMode: false,\n\t\t\t\tlogger: requestLogger,\n\t\t\t})\n\t\t}\n\t}\n\n\tprivate async handleHttpRequest(ctx: KoaContext<{ module?: string; projectGroup?: string; project?: string }>) {\n\t\tconst matchedRequest = this.matchRequest(this.routes, ctx.request.URL)\n\t\tif (!matchedRequest) {\n\t\t\tconst internalMatchedRequest = this.matchRequest(this.internalRoutes, ctx.request.URL)\n\t\t\tif (internalMatchedRequest) {\n\t\t\t\treturn await this.handleInternalRequest(internalMatchedRequest, ctx)\n\t\t\t}\n\t\t}\n\t\tlet httpContext: HttpContext | null = null\n\t\tconst clientIp = getClientIP(ctx.req, this.trustedProxies)\n\t\tlet requestLogger = this.createRequestLogger(ctx.req, ctx.request.body, matchedRequest?.module, clientIp)\n\t\tconst { timer, send: sendTimer } = this.createTimer()\n\n\t\ttry {\n\t\t\tif (!matchedRequest) {\n\t\t\t\treturn this.sendHttpResponse(ctx, new HttpErrorResponse(404, 'Route not found'))\n\t\t\t}\n\t\t\trequestLogger.debug('Request processing started', {\n\t\t\t\tbody: ctx.request.body,\n\t\t\t\tquery: ctx.request.query,\n\t\t\t})\n\n\t\t\t// todo: solve without koa context (required by prom metrics)\n\t\t\tctx.state.module = matchedRequest.module\n\n\t\t\tconst groupContainer = await this.projectGroupResolver.resolveContainer({ request: ctx.req })\n\t\t\trequestLogger = requestLogger.child({\n\t\t\t\tprojectGroup: groupContainer.slug,\n\t\t\t})\n\t\t\tctx.state.projectGroup = groupContainer.slug\n\t\t\tctx.state.project = matchedRequest.params.projectSlug\n\n\t\t\tconst authResult = await groupContainer.authenticator.authenticate({ request: ctx.req, timer, clientIp })\n\t\t\trequestLogger.debug('User authenticated', { authResult })\n\t\t\trequestLogger = requestLogger.child({\n\t\t\t\tuser: authResult?.identityId,\n\t\t\t})\n\n\t\t\tconst effectiveClientIp = authResult?.clientIp ?? clientIp\n\n\t\t\tconst response = await requestLogger.scope(async logger => {\n\t\t\t\thttpContext = {\n\t\t\t\t\tkoa: ctx,\n\t\t\t\t\tbody: ctx.request.body,\n\t\t\t\t\turl: ctx.request.URL,\n\t\t\t\t\tclientIp: effectiveClientIp,\n\t\t\t\t\tlogger,\n\t\t\t\t\ttimer,\n\t\t\t\t\trequest: ctx.req,\n\t\t\t\t\tresponse: ctx.res,\n\t\t\t\t\trequestDebugMode: false,\n\t\t\t\t\tauthResult,\n\t\t\t\t\tparams: matchedRequest.params,\n\t\t\t\t\tprojectGroup: groupContainer,\n\t\t\t\t}\n\t\t\t\treturn await matchedRequest.controller(httpContext)\n\t\t\t})\n\t\t\tif (response) {\n\t\t\t\tthis.sendHttpResponse(ctx, response)\n\t\t\t}\n\t\t} catch (e) {\n\t\t\tif (e instanceof HttpResponse) {\n\t\t\t\tthis.sendHttpResponse(ctx, e)\n\t\t\t} else {\n\t\t\t\tthis.sendHttpResponse(ctx, new HttpErrorResponse(500, 'Internal server error'))\n\t\t\t\trequestLogger.error(e)\n\t\t\t}\n\t\t} finally {\n\t\t\tthis.maybeForceHttpOk(ctx, matchedRequest?.module)\n\t\t\tsendTimer({\n\t\t\t\treq: ctx.req,\n\t\t\t\tresponse: ctx.res,\n\t\t\t\tbody: ctx.response.body,\n\t\t\t\trequestDebugMode: (httpContext as HttpContext | null)?.requestDebugMode ?? false,\n\t\t\t\tlogger: requestLogger,\n\t\t\t})\n\t\t\trequestLogger.debug('Request processing finished')\n\t\t}\n\t}\n\n\tprivate async handleInternalRequest(matchedRequest: MatchedRequest<InternalHttpController>, ctx: KoaContext<{ module?: string }>) {\n\t\ttry {\n\t\t\tconst response = await this.logger.scope(async logger => {\n\t\t\t\treturn await matchedRequest.controller({\n\t\t\t\t\tkoa: ctx,\n\t\t\t\t\tclientIp: getClientIP(ctx.req, this.trustedProxies),\n\t\t\t\t\tbody: ctx.request.body,\n\t\t\t\t\turl: ctx.request.URL,\n\t\t\t\t\tlogger,\n\t\t\t\t\trequest: ctx.req,\n\t\t\t\t\tresponse: ctx.res,\n\t\t\t\t\tparams: matchedRequest.params,\n\t\t\t\t})\n\t\t\t})\n\t\t\tif (response) {\n\t\t\t\tthis.sendHttpResponse(ctx, response)\n\t\t\t}\n\t\t} catch (e) {\n\t\t\tif (e instanceof HttpResponse) {\n\t\t\t\tthis.sendHttpResponse(ctx, e)\n\t\t\t} else {\n\t\t\t\tthis.sendHttpResponse(ctx, new HttpErrorResponse(500, 'Internal server error'))\n\t\t\t\tthis.logger.error(e)\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * When the X-Contember-Force-Ok header is present (and the capability is enabled in config),\n\t * coerce the HTTP status of a GraphQL API response (content/tenant/system) to 200, keeping the\n\t * error information in the JSON body. Scoped to those modules so non-JSON / non-GraphQL responses\n\t * are not mislabeled. Default behavior (real status codes) is preserved when the header is absent.\n\t */\n\tprivate maybeForceHttpOk(ctx: KoaContext<{}>, module: string | undefined) {\n\t\tconst coerce = shouldForceHttpOk({\n\t\t\tenabled: this.forceHttpOkEnabled,\n\t\t\tstatus: ctx.status,\n\t\t\tmodule,\n\t\t\thasBody: ctx.body !== undefined && ctx.body !== null,\n\t\t\theaderRequested: isForceHttpOkRequested(ctx.req),\n\t\t})\n\t\tif (!coerce) {\n\t\t\treturn\n\t\t}\n\t\tctx.set('X-Contember-Original-Status', String(ctx.status))\n\t\tctx.status = 200\n\t}\n\n\tprivate sendHttpResponse(ctx: KoaContext<{}>, response: HttpResponse) {\n\t\tif (response.contentType) {\n\t\t\tctx.set('Content-type', response.contentType)\n\t\t}\n\t\tfor (const [name, value] of Object.entries(response.headers ?? {})) {\n\t\t\tctx.set(name, value)\n\t\t}\n\t\tctx.status = response.code\n\t\tif (response.body !== undefined) {\n\t\t\tctx.body = response.body\n\t\t}\n\t}\n\n\tprivate async closeWebsocket(ws: WebSocket): Promise<void> {\n\t\tif (ws.readyState === WebSocket.CLOSED) {\n\t\t\treturn\n\t\t}\n\t\tws.close(1012) // Service Restart\n\t\tawait new Promise<void>(resolve => {\n\t\t\t// ws only gives up on the close handshake after 30 s, which outlives a typical shutdown grace period\n\t\t\tconst timeout = setTimeout(() => {\n\t\t\t\tws.terminate()\n\t\t\t\tresolve()\n\t\t\t}, websocketCloseTimeoutMs)\n\t\t\tws.once('close', () => {\n\t\t\t\tclearTimeout(timeout)\n\t\t\t\tresolve()\n\t\t\t})\n\t\t})\n\t}\n\n\tprivate sendRawHttpResponse(socket: Duplex, response: HttpResponse) {\n\t\tconst headers: Record<string, string> = {\n\t\t\t...response.headers,\n\t\t\t'Connection': 'close',\n\t\t\t'Content-Type': response.contentType ?? 'text/plain',\n\t\t\t'Content-Length': String(response.body?.length ?? 0),\n\t\t}\n\n\t\tsocket.once('finish', socket.destroy)\n\n\t\tsocket.end(\n\t\t\t`HTTP/1.1 ${response.code} ${http.STATUS_CODES[response.code]}\\r\\n`\n\t\t\t\t+ Object.keys(headers)\n\t\t\t\t\t.map(h => `${h}: ${headers[h]}`)\n\t\t\t\t\t.join('\\r\\n')\n\t\t\t\t+ '\\r\\n\\r\\n'\n\t\t\t\t+ (response.body ?? ''),\n\t\t)\n\t}\n\n\tprivate createRequestLogger(request: IncomingMessage, body: any, module?: string, remoteAddress?: string): Logger {\n\t\treturn this.logger.child({\n\t\t\tmethod: request.method,\n\t\t\turi: request.url,\n\t\t\trequestId: Math.random().toString().substring(2),\n\t\t\tmodule,\n\t\t\tremoteAddress,\n\t\t\t[LoggerRequestBody]: body,\n\t\t}, {\n\t\t\thandler: FingerCrossedLoggerHandler.factory(),\n\t\t})\n\t}\n\n\tprivate createTimer() {\n\t\tconst times: EventTime[] = []\n\t\tconst globalStart = performance.now()\n\t\tconst cpuUsageStart = cpuUsage()\n\t\tconst memoryUsageStart = memoryUsage()\n\t\tconst timer: Timer = (name: string, cb) => {\n\t\t\tconst start = performance.now()\n\t\t\tconst time: EventTime = { label: name, start: Math.round(start - globalStart) }\n\t\t\ttimes.push(time)\n\t\t\tconst res = cb()\n\n\t\t\tif (res instanceof Promise) {\n\t\t\t\t;(async () => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait res\n\t\t\t\t\t} catch {\n\t\t\t\t\t} finally {\n\t\t\t\t\t\ttime.duration = Math.round(performance.now() - start)\n\t\t\t\t\t}\n\t\t\t\t})()\n\t\t\t}\n\t\t\treturn res\n\t\t}\n\n\t\tconst send = (ctx: { req: IncomingMessage; response?: ServerResponse; body?: unknown; requestDebugMode: boolean; logger: Logger }) => {\n\t\t\tif (ctx.response && !ctx.response.headersSent && (ctx.requestDebugMode || this.debugMode) && times.length) {\n\t\t\t\tctx.response.setHeader('server-timing', times.map(it => `${it.label};desc=\"${it.label} T+${it.start}\";dur=${it.duration ?? -1}`).join(', '))\n\t\t\t}\n\n\t\t\tconst emit = () => {\n\t\t\t\tconst total = performance.now() - globalStart\n\t\t\t\tconst timeLabel = total > 500 ? 'TIME_SLOW' : 'TIME_OK'\n\t\t\t\tconst shouldSuppress = this.suppressAccessLog === true || !ctx.req.url\n\t\t\t\t\t|| (this.suppressAccessLog !== false && this.suppressAccessLog.test(ctx.req.url))\n\n\t\t\t\tconst cpuUsageEnd = cpuUsage()\n\t\t\t\tconst memoryUsageEnd = memoryUsage()\n\n\t\t\t\tconst cpuUsageDiffMs = (cpuUsageEnd.user - cpuUsageStart.user) / 1000\n\t\t\t\tconst memoryUsageDiff = memoryUsageEnd.heapUsed - memoryUsageStart.heapUsed\n\t\t\t\tconst level = shouldSuppress ? 'debug' : 'info'\n\t\t\t\tctx.logger.log(level, !ctx.response ? 'Connection established' : ctx.response.statusCode < 400 ? `Request successful` : 'Request failed', {\n\t\t\t\t\tstatus: ctx.response?.statusCode,\n\t\t\t\t\ttimeLabel: timeLabel,\n\t\t\t\t\ttotalTimeMs: Math.round(total),\n\t\t\t\t\tevents: times,\n\t\t\t\t\tcpuUsageDiffMs,\n\t\t\t\t\tmemoryUsageDiff,\n\t\t\t\t\tresponseBodySize: ctx.body && typeof ctx.body === 'string' ? ctx.body.length : undefined,\n\t\t\t\t})\n\t\t\t}\n\n\t\t\tif (ctx.body instanceof Readable) {\n\t\t\t\tconst body = ctx.body\n\t\t\t\tconst streamTimer = timer('Stream', () => {\n\t\t\t\t\treturn new Promise(resolve => {\n\t\t\t\t\t\tbody.addListener('close', () => {\n\t\t\t\t\t\t\tresolve(null)\n\t\t\t\t\t\t})\n\t\t\t\t\t})\n\t\t\t\t})\n\n\t\t\t\tstreamTimer.then(emit).catch(emit)\n\t\t\t} else {\n\t\t\t\temit()\n\t\t\t}\n\t\t}\n\t\treturn { timer, send }\n\t}\n\n\tprivate matchRequest<C>(routes: Route<C>[], url: URL): MatchedRequest<C> | null {\n\t\tfor (const route of routes) {\n\t\t\tconst params = route.match({ url })\n\t\t\tif (params !== null) {\n\t\t\t\treturn { params, controller: route.controller, module: route.module }\n\t\t\t}\n\t\t}\n\t\treturn null\n\t}\n}\n\ntype EventTime = { label: string; start: number; duration?: number }\n\nexport type Timer = <T>(event: string, cb: () => T) => T\n\nexport type MatchedRequest<C> = { params: Params; controller: C; module: string }\n\nexport type BaseRequestContext = {\n\tlogger: Logger\n\trequest: IncomingMessage\n\turl: URL\n\tparams: Params\n\tclientIp: string\n}\n\nexport type ApplicationContext =\n\t& BaseRequestContext\n\t& {\n\t\tprojectGroup: ProjectGroupContainer\n\t\tauthResult: AuthResult | null\n\t\ttimer: Timer\n\t}\n\nexport type BaseHttpRequestContext = {\n\tkoa: KoaContext<{}>\n\tbody: unknown\n\tresponse: ServerResponse\n}\n\nexport type HttpContext =\n\t& ApplicationContext\n\t& BaseHttpRequestContext\n\t& {\n\t\trequestDebugMode: boolean\n\t}\n\nexport type InternalHttpContext =\n\t& BaseRequestContext\n\t& BaseHttpRequestContext\n\nexport type WebSocketContext =\n\t& ApplicationContext\n\t& {\n\t\tws: WebSocket\n\t\tabortSignal: AbortSignal\n\t\twaitUntil(promise: Promise<void>): void\n\t}\n\nexport type HttpControllerResponse = Promise<HttpErrorResponse | undefined | void> | HttpErrorResponse | undefined | void\nexport type HttpController = (context: HttpContext) => HttpControllerResponse\nexport type InternalHttpController = (context: InternalHttpContext) => HttpControllerResponse\n\nexport type WebSocketController = (context: WebSocketContext) => void\n\ntype Params = { [param: string]: string }\n\ntype RequestMatcher = (args: { url: URL }) => Params | null\nconst createRequestMatcher = (\n\tmask: string,\n): RequestMatcher => {\n\tconst { regexp, keys } = pathToRegexp(mask)\n\n\tconst match = function(url: string): Params | null {\n\t\tconst match = regexp.exec(url)\n\t\tif (match) {\n\t\t\treturn match.slice(1).reduce((acc, value, i) => ({ ...acc, [keys[i].name]: value }), {})\n\t\t}\n\t\treturn null\n\t}\n\n\treturn request => {\n\t\treturn match(request.url.pathname)\n\t}\n}\n\nexport const LoggerRequestBody = Symbol('RequestBody')\n\nexport interface RunningApplication {\n\tclose(): Promise<void>\n\treadonly server: Server\n}\n"],"names":["logger","module","WebSocketServer","http","HttpErrorResponse","getClientIP","URL","ws","performance","WebSocket","HttpResponse","shouldForceHttpOk","isForceHttpOkRequested","remoteAddress","FingerCrossedLoggerHandler","cpuUsage","memoryUsage","Readable","pathToRegexp","match"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,MAAM,0BAA0B;AAGzB,MAAM,YAAY;AAAA,EAWxB,YACkB,sBACA,cACA,WACA,SACAA,SAChB;AALgB,SAAA,uBAAA;AACA,SAAA,eAAA;AACA,SAAA,YAAA;AACA,SAAA,UAAA;AACA,SAAA,SAAAA;AAflB,kBAAA,MAAQ,eAAoC,EAAC;AAE7C,kBAAA,MAAQ,UAAkC,EAAC;AAC3C,kBAAA,MAAQ,kBAAkD,EAAC;AAC3D,kBAAA,MAAQ,mBAAgD,EAAC;AAEzD,kBAAA,MAAQ,mBAAA;AACR,kBAAA,MAAQ,gBAAA;AACR,kBAAA,MAAQ,oBAAA;AASP,UAAM,uBAAuB,aAAa,MAAM;AAChD,SAAK,oBAAoB,yBAAyB,OAAO,OAAO,uBAAuB,IAAI,OAAO,oBAAoB,IAAI;AAC1H,SAAK,iBAAiB,aAAa,MAAM,kBAAkB,CAAA;AAC3D,SAAK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,SAAS,KAA4B;AAClD,UAAMC,SAAQ,OAAO,KAAK,GAAG;AAC7B,QAAIA,QAAO;AACV,aAAOA,OAAM,MAAM,CAAC,EAAE,OAAO,CAAC,KAAK,OAAO,OAAO,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,EAAE,IAAI,GAAG,MAAA,IAAU,EAAE;AAAA,IACxF;AACA,WAAO;AAAA,EACR;AAEA,SAAO,CAAA,YAAW;AACjB,WAAO,MAAM,QAAQ,IAAI,QAAQ;AAAA,EAClC;AACD;AAEO,MAAM,2CAA2B,aAAa;;;"}
1
+ {"version":3,"file":"application.cjs","sources":["../../../../../packages/engine-http/src/application/application.ts"],"sourcesContent":["import { pathToRegexp } from 'path-to-regexp'\nimport { KoaContext, KoaMiddleware } from './types.js'\nimport { AuthResult, HttpErrorResponse, HttpResponse } from '../common/index.js'\nimport Koa from 'koa'\nimport * as http from 'node:http'\nimport { IncomingMessage, Server, ServerResponse } from 'node:http'\nimport { WebSocket, WebSocketServer } from 'ws'\nimport { FingerCrossedLoggerHandler, Logger } from '@contember/logger'\nimport koaCompress from 'koa-compress'\nimport bodyParser from 'koa-bodyparser'\nimport { ServerConfig } from '../config/config.js'\nimport corsMiddleware from '@koa/cors'\nimport stream, { Duplex, Readable } from 'node:stream'\nimport { ProjectGroupResolver } from '../projectGroup/ProjectGroupResolver.js'\nimport { ProjectGroupContainer } from '../projectGroup/ProjectGroupContainer.js'\nimport { URL } from 'node:url'\nimport { cpuUsage, memoryUsage } from 'node:process'\nimport { performance } from 'node:perf_hooks'\nimport { getClientIP } from '../utils/remoteAddress.js'\nimport { isForceHttpOkRequested, shouldForceHttpOk } from './forceHttpOk.js'\n\nconst websocketCloseTimeoutMs = 5_000\n\ntype Route<C> = { match: RequestMatcher; controller: C; module: string }\nexport class Application {\n\tprivate middlewares: KoaMiddleware<any>[] = []\n\n\tprivate routes: Route<HttpController>[] = []\n\tprivate internalRoutes: Route<InternalHttpController>[] = []\n\tprivate websocketRoutes: Route<WebSocketController>[] = []\n\n\tprivate suppressAccessLog: boolean | RegExp\n\tprivate trustedProxies: string[]\n\tprivate forceHttpOkEnabled: boolean\n\n\tconstructor(\n\t\tprivate readonly projectGroupResolver: ProjectGroupResolver,\n\t\tprivate readonly serverConfig: ServerConfig,\n\t\tprivate readonly debugMode: boolean,\n\t\tprivate readonly version: string | undefined,\n\t\tprivate readonly logger: Logger,\n\t) {\n\t\tconst suppressAccessLogRaw = serverConfig.http?.suppressAccessLog\n\t\tthis.suppressAccessLog = suppressAccessLogRaw === true ? true : suppressAccessLogRaw ? new RegExp(suppressAccessLogRaw) : false\n\t\tthis.trustedProxies = serverConfig.http?.trustedProxies ?? []\n\t\tthis.forceHttpOkEnabled = serverConfig.http?.responseStatusHeader ?? true\n\t}\n\n\taddMiddleware(middleware: KoaMiddleware<any>) {\n\t\tthis.middlewares.push(middleware)\n\t}\n\n\tpublic addRoute(module: string, mask: string, controller: HttpController): void {\n\t\tthis.routes.push({\n\t\t\tmodule,\n\t\t\tcontroller,\n\t\t\tmatch: createRequestMatcher(mask),\n\t\t})\n\t}\n\n\tpublic addInternalRoute(module: string, mask: string, controller: InternalHttpController): void {\n\t\tthis.internalRoutes.push({\n\t\t\tmodule,\n\t\t\tcontroller,\n\t\t\tmatch: createRequestMatcher(mask),\n\t\t})\n\t}\n\n\tpublic addWebsocketRoute(module: string, mask: string, controller: WebSocketController): void {\n\t\tthis.websocketRoutes.push({\n\t\t\tmodule,\n\t\t\tcontroller,\n\t\t\tmatch: createRequestMatcher(mask),\n\t\t})\n\t}\n\n\tasync listen(): Promise<RunningApplication> {\n\t\tconst koa = new Koa()\n\t\tconst wss = new WebSocketServer({ noServer: true })\n\t\tlet closing = false\n\t\tkoa.use(async (ctx, next) => {\n\t\t\tif (closing) {\n\t\t\t\tctx.status = 503\n\t\t\t\tctx.set('Connection', 'close')\n\t\t\t\treturn\n\t\t\t}\n\t\t\tawait next()\n\t\t})\n\t\tfor (const middleware of this.middlewares) {\n\t\t\tkoa.use(middleware)\n\t\t}\n\t\tkoa.use(koaCompress({\n\t\t\tbr: false,\n\t\t}))\n\t\tkoa.use(bodyParser({\n\t\t\tjsonLimit: this.serverConfig.http?.requestBodySize || '1mb',\n\t\t}))\n\t\tkoa.use(corsMiddleware({ exposeHeaders: ['X-Contember-Mutation'] }))\n\t\tconst versionMatch = this.version?.match(/^(0\\.\\d+|\\d+)/)\n\t\tconst versionSimplified = versionMatch?.[1] ?? 'unknown'\n\t\tkoa.use(async ctx => {\n\t\t\tctx.response.set('X-Powered-By', `Contember ${versionSimplified}` + (this.debugMode ? '-dev' : ''))\n\t\t\tawait this.handleHttpRequest(ctx)\n\t\t})\n\n\t\tconst activeHttpRequests = new Set<Promise<void>>()\n\t\tconst handleHttpRequest = koa.callback()\n\t\tconst server = http.createServer((request, response) => {\n\t\t\tif (closing) {\n\t\t\t\thandleHttpRequest(request, response)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tlet resolveRequest = () => {}\n\t\t\tconst completed = new Promise<void>(resolve => {\n\t\t\t\tresolveRequest = resolve\n\t\t\t})\n\t\t\tactiveHttpRequests.add(completed)\n\t\t\tconst complete = () => {\n\t\t\t\tresponse.off('finish', complete)\n\t\t\t\tresponse.off('close', complete)\n\t\t\t\tactiveHttpRequests.delete(completed)\n\t\t\t\tresolveRequest()\n\t\t\t}\n\t\t\tresponse.once('finish', complete)\n\t\t\tresponse.once('close', complete)\n\t\t\thandleHttpRequest(request, response)\n\t\t})\n\t\tconst abortController = new AbortController()\n\n\t\tconst wsRequests: (Promise<void>)[] = []\n\t\tserver.on('upgrade', (req, socket, head) => {\n\t\t\tif (closing) {\n\t\t\t\tthis.sendRawHttpResponse(socket, new HttpErrorResponse(503, 'Server is shutting down'))\n\t\t\t\treturn\n\t\t\t}\n\t\t\twsRequests.push(this.handleWebsocketRequest(wss, abortController.signal, req, socket, head))\n\t\t})\n\t\tawait new Promise<void>(resolve => {\n\t\t\tserver.listen(this.serverConfig.port, () => resolve())\n\t\t})\n\n\t\treturn {\n\t\t\tserver,\n\t\t\tclose: async () => {\n\t\t\t\tclosing = true\n\t\t\t\tabortController.abort()\n\t\t\t\tawait Promise.all([...wsRequests, ...activeHttpRequests])\n\t\t\t\tif (process.versions.bun !== undefined) {\n\t\t\t\t\t// Bun does not finish server.close() after a WebSocket upgrade unless all connections are closed first.\n\t\t\t\t\tserver.closeAllConnections()\n\t\t\t\t} else {\n\t\t\t\t\tserver.closeIdleConnections()\n\t\t\t\t}\n\t\t\t\tif (server.listening) {\n\t\t\t\t\tawait new Promise<void>(resolve =>\n\t\t\t\t\t\tserver.close(error => {\n\t\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\t\tthis.logger.error(error)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tresolve()\n\t\t\t\t\t\t})\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t},\n\t\t}\n\t}\n\n\tprivate async handleWebsocketRequest(\n\t\twss: WebSocketServer,\n\t\tabortSignal: AbortSignal,\n\t\treq: IncomingMessage,\n\t\tsocket: stream.Duplex,\n\t\thead: Buffer,\n\t): Promise<void> {\n\t\tlet webSocketContext: WebSocketContext | null = null\n\t\tlet requestLogger = this.logger\n\t\tconst { timer, send: sendTimer } = this.createTimer()\n\t\tconst clientIp = getClientIP(req, this.trustedProxies)\n\t\ttry {\n\t\t\tconst url = new URL(req.url ?? '/', `http://${req.headers.host}`)\n\t\t\tconst matchedRequest = this.matchRequest(this.websocketRoutes, url)\n\t\t\tif (!matchedRequest) {\n\t\t\t\tthrow new HttpErrorResponse(404, 'Route not found')\n\t\t\t}\n\t\t\trequestLogger = this.createRequestLogger(req, undefined, matchedRequest.module, clientIp)\n\n\t\t\tconst groupContainer = await this.projectGroupResolver.resolveContainer({ request: req })\n\n\t\t\trequestLogger = requestLogger.child({\n\t\t\t\tprojectGroup: groupContainer.slug,\n\t\t\t})\n\n\t\t\tconst authResult = await groupContainer.authenticator.authenticate({ request: req, timer, clientIp })\n\t\t\trequestLogger.debug('User authenticated', { authResult })\n\t\t\trequestLogger = requestLogger.child({\n\t\t\t\tuser: authResult?.identityId,\n\t\t\t})\n\n\t\t\tconst effectiveClientIp = authResult?.clientIp ?? clientIp\n\n\t\t\tif (abortSignal.aborted) {\n\t\t\t\tthrow new HttpErrorResponse(503, 'Server is shutting down')\n\t\t\t}\n\t\t\tconst ws = await new Promise<WebSocket>(resolve =>\n\t\t\t\twss.handleUpgrade(req, socket, head, (ws, request) => {\n\t\t\t\t\tresolve(ws)\n\t\t\t\t})\n\t\t\t)\n\t\t\tconst wsEstablished = performance.now()\n\t\t\tws.on('error', e => {\n\t\t\t\trequestLogger.error(e, {\n\t\t\t\t\twebsocketOpenMs: performance.now() - wsEstablished,\n\t\t\t\t})\n\t\t\t})\n\t\t\tif (abortSignal.aborted) {\n\t\t\t\tawait this.closeWebsocket(ws)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tconst pendingWork: Promise<void>[] = []\n\t\t\twebSocketContext = {\n\t\t\t\tws,\n\t\t\t\tabortSignal,\n\t\t\t\tlogger: requestLogger,\n\t\t\t\ttimer,\n\t\t\t\turl,\n\t\t\t\trequest: req,\n\t\t\t\tclientIp: effectiveClientIp,\n\t\t\t\tauthResult,\n\t\t\t\tparams: matchedRequest.params,\n\t\t\t\tprojectGroup: groupContainer,\n\t\t\t\twaitUntil: promise => pendingWork.push(promise),\n\t\t\t}\n\t\t\tawait matchedRequest.controller(webSocketContext)\n\t\t\tif (abortSignal.aborted && ws.readyState === WebSocket.OPEN) {\n\t\t\t\tws.close(1012)\n\t\t\t}\n\t\t\trequestLogger.debug('Websocket connection established')\n\n\t\t\tif (ws.readyState !== WebSocket.CLOSED) {\n\t\t\t\tawait new Promise<void>(resolve => {\n\t\t\t\t\tws.on('close', () => {\n\t\t\t\t\t\trequestLogger.debug('Websocket connection closed', {\n\t\t\t\t\t\t\twebsocketOpenMs: performance.now() - wsEstablished,\n\t\t\t\t\t\t})\n\t\t\t\t\t\tresolve()\n\t\t\t\t\t})\n\t\t\t\t})\n\t\t\t}\n\t\t\tawait Promise.allSettled(pendingWork)\n\t\t} catch (e) {\n\t\t\tif (e instanceof HttpResponse) {\n\t\t\t\tthis.sendRawHttpResponse(socket, e)\n\t\t\t} else {\n\t\t\t\tthis.sendRawHttpResponse(socket, new HttpErrorResponse(500, 'Internal server error'))\n\t\t\t\trequestLogger.error(e)\n\t\t\t}\n\t\t\trequestLogger.debug('Websocket connection failed')\n\t\t} finally {\n\t\t\tsendTimer({\n\t\t\t\treq,\n\t\t\t\trequestDebugMode: false,\n\t\t\t\tlogger: requestLogger,\n\t\t\t})\n\t\t}\n\t}\n\n\tprivate async handleHttpRequest(ctx: KoaContext<{ module?: string; projectGroup?: string; project?: string }>) {\n\t\tconst matchedRequest = this.matchRequest(this.routes, ctx.request.URL)\n\t\tif (!matchedRequest) {\n\t\t\tconst internalMatchedRequest = this.matchRequest(this.internalRoutes, ctx.request.URL)\n\t\t\tif (internalMatchedRequest) {\n\t\t\t\treturn await this.handleInternalRequest(internalMatchedRequest, ctx)\n\t\t\t}\n\t\t}\n\t\tlet httpContext: HttpContext | null = null\n\t\tconst clientIp = getClientIP(ctx.req, this.trustedProxies)\n\t\tlet requestLogger = this.createRequestLogger(ctx.req, ctx.request.body, matchedRequest?.module, clientIp)\n\t\tconst { timer, send: sendTimer } = this.createTimer()\n\n\t\ttry {\n\t\t\tif (!matchedRequest) {\n\t\t\t\treturn this.sendHttpResponse(ctx, new HttpErrorResponse(404, 'Route not found'))\n\t\t\t}\n\t\t\trequestLogger.debug('Request processing started', {\n\t\t\t\tbody: ctx.request.body,\n\t\t\t\tquery: ctx.request.query,\n\t\t\t})\n\n\t\t\t// todo: solve without koa context (required by prom metrics)\n\t\t\tctx.state.module = matchedRequest.module\n\n\t\t\tconst groupContainer = await this.projectGroupResolver.resolveContainer({ request: ctx.req })\n\t\t\trequestLogger = requestLogger.child({\n\t\t\t\tprojectGroup: groupContainer.slug,\n\t\t\t})\n\t\t\tctx.state.projectGroup = groupContainer.slug\n\t\t\tctx.state.project = matchedRequest.params.projectSlug\n\n\t\t\tconst authResult = await groupContainer.authenticator.authenticate({ request: ctx.req, timer, clientIp })\n\t\t\trequestLogger.debug('User authenticated', { authResult })\n\t\t\trequestLogger = requestLogger.child({\n\t\t\t\tuser: authResult?.identityId,\n\t\t\t})\n\n\t\t\tconst effectiveClientIp = authResult?.clientIp ?? clientIp\n\n\t\t\tconst response = await requestLogger.scope(async logger => {\n\t\t\t\thttpContext = {\n\t\t\t\t\tkoa: ctx,\n\t\t\t\t\tbody: ctx.request.body,\n\t\t\t\t\turl: ctx.request.URL,\n\t\t\t\t\tclientIp: effectiveClientIp,\n\t\t\t\t\tlogger,\n\t\t\t\t\ttimer,\n\t\t\t\t\trequest: ctx.req,\n\t\t\t\t\tresponse: ctx.res,\n\t\t\t\t\trequestDebugMode: false,\n\t\t\t\t\tauthResult,\n\t\t\t\t\tparams: matchedRequest.params,\n\t\t\t\t\tprojectGroup: groupContainer,\n\t\t\t\t}\n\t\t\t\treturn await matchedRequest.controller(httpContext)\n\t\t\t})\n\t\t\tif (response) {\n\t\t\t\tthis.sendHttpResponse(ctx, response)\n\t\t\t}\n\t\t} catch (e) {\n\t\t\tif (e instanceof HttpResponse) {\n\t\t\t\tthis.sendHttpResponse(ctx, e)\n\t\t\t} else {\n\t\t\t\tthis.sendHttpResponse(ctx, new HttpErrorResponse(500, 'Internal server error'))\n\t\t\t\trequestLogger.error(e)\n\t\t\t}\n\t\t} finally {\n\t\t\tthis.maybeForceHttpOk(ctx, matchedRequest?.module)\n\t\t\tsendTimer({\n\t\t\t\treq: ctx.req,\n\t\t\t\tresponse: ctx.res,\n\t\t\t\tbody: ctx.response.body,\n\t\t\t\trequestDebugMode: (httpContext as HttpContext | null)?.requestDebugMode ?? false,\n\t\t\t\tlogger: requestLogger,\n\t\t\t})\n\t\t\trequestLogger.debug('Request processing finished')\n\t\t}\n\t}\n\n\tprivate async handleInternalRequest(matchedRequest: MatchedRequest<InternalHttpController>, ctx: KoaContext<{ module?: string }>) {\n\t\ttry {\n\t\t\tconst response = await this.logger.scope(async logger => {\n\t\t\t\treturn await matchedRequest.controller({\n\t\t\t\t\tkoa: ctx,\n\t\t\t\t\tclientIp: getClientIP(ctx.req, this.trustedProxies),\n\t\t\t\t\tbody: ctx.request.body,\n\t\t\t\t\turl: ctx.request.URL,\n\t\t\t\t\tlogger,\n\t\t\t\t\trequest: ctx.req,\n\t\t\t\t\tresponse: ctx.res,\n\t\t\t\t\tparams: matchedRequest.params,\n\t\t\t\t})\n\t\t\t})\n\t\t\tif (response) {\n\t\t\t\tthis.sendHttpResponse(ctx, response)\n\t\t\t}\n\t\t} catch (e) {\n\t\t\tif (e instanceof HttpResponse) {\n\t\t\t\tthis.sendHttpResponse(ctx, e)\n\t\t\t} else {\n\t\t\t\tthis.sendHttpResponse(ctx, new HttpErrorResponse(500, 'Internal server error'))\n\t\t\t\tthis.logger.error(e)\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * When the X-Contember-Force-Ok header is present (and the capability is enabled in config),\n\t * coerce the HTTP status of a GraphQL API response (content/tenant/system) to 200, keeping the\n\t * error information in the JSON body. Scoped to those modules so non-JSON / non-GraphQL responses\n\t * are not mislabeled. Default behavior (real status codes) is preserved when the header is absent.\n\t */\n\tprivate maybeForceHttpOk(ctx: KoaContext<{}>, module: string | undefined) {\n\t\tconst coerce = shouldForceHttpOk({\n\t\t\tenabled: this.forceHttpOkEnabled,\n\t\t\tstatus: ctx.status,\n\t\t\tmodule,\n\t\t\thasBody: ctx.body !== undefined && ctx.body !== null,\n\t\t\theaderRequested: isForceHttpOkRequested(ctx.req),\n\t\t})\n\t\tif (!coerce) {\n\t\t\treturn\n\t\t}\n\t\tctx.set('X-Contember-Original-Status', String(ctx.status))\n\t\tctx.status = 200\n\t}\n\n\tprivate sendHttpResponse(ctx: KoaContext<{}>, response: HttpResponse) {\n\t\tif (response.contentType) {\n\t\t\tctx.set('Content-type', response.contentType)\n\t\t}\n\t\tfor (const [name, value] of Object.entries(response.headers ?? {})) {\n\t\t\tctx.set(name, value)\n\t\t}\n\t\tctx.status = response.code\n\t\tif (response.body !== undefined) {\n\t\t\tctx.body = response.body\n\t\t}\n\t}\n\n\tprivate async closeWebsocket(ws: WebSocket): Promise<void> {\n\t\tif (ws.readyState === WebSocket.CLOSED) {\n\t\t\treturn\n\t\t}\n\t\tws.close(1012) // Service Restart\n\t\tawait new Promise<void>(resolve => {\n\t\t\t// ws only gives up on the close handshake after 30 s, which outlives a typical shutdown grace period\n\t\t\tconst timeout = setTimeout(() => {\n\t\t\t\tws.terminate()\n\t\t\t\tresolve()\n\t\t\t}, websocketCloseTimeoutMs)\n\t\t\tws.once('close', () => {\n\t\t\t\tclearTimeout(timeout)\n\t\t\t\tresolve()\n\t\t\t})\n\t\t})\n\t}\n\n\tprivate sendRawHttpResponse(socket: Duplex, response: HttpResponse) {\n\t\tconst headers: Record<string, string> = {\n\t\t\t...response.headers,\n\t\t\t'Connection': 'close',\n\t\t\t'Content-Type': response.contentType ?? 'text/plain',\n\t\t\t'Content-Length': String(response.body?.length ?? 0),\n\t\t}\n\n\t\tsocket.once('finish', socket.destroy)\n\n\t\tsocket.end(\n\t\t\t`HTTP/1.1 ${response.code} ${http.STATUS_CODES[response.code]}\\r\\n`\n\t\t\t\t+ Object.keys(headers)\n\t\t\t\t\t.map(h => `${h}: ${headers[h]}`)\n\t\t\t\t\t.join('\\r\\n')\n\t\t\t\t+ '\\r\\n\\r\\n'\n\t\t\t\t+ (response.body ?? ''),\n\t\t)\n\t}\n\n\tprivate createRequestLogger(request: IncomingMessage, body: any, module?: string, remoteAddress?: string): Logger {\n\t\treturn this.logger.child({\n\t\t\tmethod: request.method,\n\t\t\turi: request.url,\n\t\t\trequestId: Math.random().toString().substring(2),\n\t\t\tmodule,\n\t\t\tremoteAddress,\n\t\t\t[LoggerRequestBody]: body,\n\t\t}, {\n\t\t\thandler: FingerCrossedLoggerHandler.factory(),\n\t\t})\n\t}\n\n\tprivate createTimer() {\n\t\tconst times: EventTime[] = []\n\t\tconst globalStart = performance.now()\n\t\tconst cpuUsageStart = cpuUsage()\n\t\tconst memoryUsageStart = memoryUsage()\n\t\tconst timer: Timer = (name: string, cb) => {\n\t\t\tconst start = performance.now()\n\t\t\tconst time: EventTime = { label: name, start: Math.round(start - globalStart) }\n\t\t\ttimes.push(time)\n\t\t\tconst res = cb()\n\n\t\t\tif (res instanceof Promise) {\n\t\t\t\t;(async () => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait res\n\t\t\t\t\t} catch {\n\t\t\t\t\t} finally {\n\t\t\t\t\t\ttime.duration = Math.round(performance.now() - start)\n\t\t\t\t\t}\n\t\t\t\t})()\n\t\t\t}\n\t\t\treturn res\n\t\t}\n\n\t\tconst send = (ctx: { req: IncomingMessage; response?: ServerResponse; body?: unknown; requestDebugMode: boolean; logger: Logger }) => {\n\t\t\tif (ctx.response && !ctx.response.headersSent && (ctx.requestDebugMode || this.debugMode) && times.length) {\n\t\t\t\tctx.response.setHeader('server-timing', times.map(it => `${it.label};desc=\"${it.label} T+${it.start}\";dur=${it.duration ?? -1}`).join(', '))\n\t\t\t}\n\n\t\t\tconst emit = () => {\n\t\t\t\tconst total = performance.now() - globalStart\n\t\t\t\tconst timeLabel = total > 500 ? 'TIME_SLOW' : 'TIME_OK'\n\t\t\t\tconst shouldSuppress = this.suppressAccessLog === true || !ctx.req.url\n\t\t\t\t\t|| (this.suppressAccessLog !== false && this.suppressAccessLog.test(ctx.req.url))\n\n\t\t\t\tconst cpuUsageEnd = cpuUsage()\n\t\t\t\tconst memoryUsageEnd = memoryUsage()\n\n\t\t\t\tconst cpuUsageDiffMs = (cpuUsageEnd.user - cpuUsageStart.user) / 1000\n\t\t\t\tconst memoryUsageDiff = memoryUsageEnd.heapUsed - memoryUsageStart.heapUsed\n\t\t\t\tconst level = shouldSuppress ? 'debug' : 'info'\n\t\t\t\tctx.logger.log(level, !ctx.response ? 'Connection established' : ctx.response.statusCode < 400 ? `Request successful` : 'Request failed', {\n\t\t\t\t\tstatus: ctx.response?.statusCode,\n\t\t\t\t\ttimeLabel: timeLabel,\n\t\t\t\t\ttotalTimeMs: Math.round(total),\n\t\t\t\t\tevents: times,\n\t\t\t\t\tcpuUsageDiffMs,\n\t\t\t\t\tmemoryUsageDiff,\n\t\t\t\t\tresponseBodySize: ctx.body && typeof ctx.body === 'string' ? ctx.body.length : undefined,\n\t\t\t\t})\n\t\t\t}\n\n\t\t\tif (ctx.body instanceof Readable) {\n\t\t\t\tconst body = ctx.body\n\t\t\t\tconst streamTimer = timer('Stream', () => {\n\t\t\t\t\treturn new Promise(resolve => {\n\t\t\t\t\t\tbody.addListener('close', () => {\n\t\t\t\t\t\t\tresolve(null)\n\t\t\t\t\t\t})\n\t\t\t\t\t})\n\t\t\t\t})\n\n\t\t\t\tstreamTimer.then(emit).catch(emit)\n\t\t\t} else {\n\t\t\t\temit()\n\t\t\t}\n\t\t}\n\t\treturn { timer, send }\n\t}\n\n\tprivate matchRequest<C>(routes: Route<C>[], url: URL): MatchedRequest<C> | null {\n\t\tfor (const route of routes) {\n\t\t\tconst params = route.match({ url })\n\t\t\tif (params !== null) {\n\t\t\t\treturn { params, controller: route.controller, module: route.module }\n\t\t\t}\n\t\t}\n\t\treturn null\n\t}\n}\n\ntype EventTime = { label: string; start: number; duration?: number }\n\nexport type Timer = <T>(event: string, cb: () => T) => T\n\nexport type MatchedRequest<C> = { params: Params; controller: C; module: string }\n\nexport type BaseRequestContext = {\n\tlogger: Logger\n\trequest: IncomingMessage\n\turl: URL\n\tparams: Params\n\tclientIp: string\n}\n\nexport type ApplicationContext =\n\t& BaseRequestContext\n\t& {\n\t\tprojectGroup: ProjectGroupContainer\n\t\tauthResult: AuthResult | null\n\t\ttimer: Timer\n\t}\n\nexport type BaseHttpRequestContext = {\n\tkoa: KoaContext<{}>\n\tbody: unknown\n\tresponse: ServerResponse\n}\n\nexport type HttpContext =\n\t& ApplicationContext\n\t& BaseHttpRequestContext\n\t& {\n\t\trequestDebugMode: boolean\n\t}\n\nexport type InternalHttpContext =\n\t& BaseRequestContext\n\t& BaseHttpRequestContext\n\nexport type WebSocketContext =\n\t& ApplicationContext\n\t& {\n\t\tws: WebSocket\n\t\tabortSignal: AbortSignal\n\t\twaitUntil(promise: Promise<void>): void\n\t}\n\nexport type HttpControllerResponse = Promise<HttpErrorResponse | undefined | void> | HttpErrorResponse | undefined | void\nexport type HttpController = (context: HttpContext) => HttpControllerResponse\nexport type InternalHttpController = (context: InternalHttpContext) => HttpControllerResponse\n\nexport type WebSocketController = (context: WebSocketContext) => void\n\ntype Params = { [param: string]: string }\n\ntype RequestMatcher = (args: { url: URL }) => Params | null\nconst createRequestMatcher = (\n\tmask: string,\n): RequestMatcher => {\n\tconst { regexp, keys } = pathToRegexp(mask)\n\n\tconst match = function(url: string): Params | null {\n\t\tconst match = regexp.exec(url)\n\t\tif (match) {\n\t\t\treturn match.slice(1).reduce((acc, value, i) => ({ ...acc, [keys[i].name]: value }), {})\n\t\t}\n\t\treturn null\n\t}\n\n\treturn request => {\n\t\treturn match(request.url.pathname)\n\t}\n}\n\nexport const LoggerRequestBody = Symbol('RequestBody')\n\nexport interface RunningApplication {\n\tclose(): Promise<void>\n\treadonly server: Server\n}\n"],"names":["logger","module","WebSocketServer","http","HttpErrorResponse","getClientIP","URL","ws","performance","WebSocket","HttpResponse","shouldForceHttpOk","isForceHttpOkRequested","remoteAddress","FingerCrossedLoggerHandler","cpuUsage","memoryUsage","Readable","pathToRegexp","match"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,MAAM,0BAA0B;AAGzB,MAAM,YAAY;AAAA,EAWxB,YACkB,sBACA,cACA,WACA,SACAA,SAChB;AALgB,SAAA,uBAAA;AACA,SAAA,eAAA;AACA,SAAA,YAAA;AACA,SAAA,UAAA;AACA,SAAA,SAAAA;AAflB,kBAAA,MAAQ,eAAoC,EAAC;AAE7C,kBAAA,MAAQ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AO,EAAE,OAAO,KAAA;AAAA,EACjB;AAAA,EAEQ,aAAgB,QAAoB,KAAoC;AAC/E,eAAW,SAAS,QAAQ;AAC3B,YAAM,SAAS,MAAM,MAAM,EAAE,KAAK;AAClC,UAAI,WAAW,MAAM;AACpB,eAAO,EAAE,QAAQ,YAAY,MAAM,YAAY,QAAQ,MAAM,OAAA;AAAA,MAC9D;AAAA,IACD;AACA,WAAO;AAAA,EACR;AACD;AA0DA,MAAM,uBAAuB,CAC5B,SACoB;AACpB,QAAM,EAAE,QAAQ,SAASC,aAAAA,aAAa,IAAI;AAE1C,QAAM,QAAQ,SAAS,KAA4B;AAClD,UAAMC,SAAQ,OAAO,KAAK,GAAG;AAC7B,QAAIA,QAAO;AACV,aAAOA,OAAM,MAAM,CAAC,EAAE,OAAO,CAAC,KAAK,OAAO,OAAO,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,EAAE,IAAI,GAAG,MAAA,IAAU,EAAE;AAAA,IACxF;AACA,WAAO;AAAA,EACR;AAEA,SAAO,CAAA,YAAW;AACjB,WAAO,MAAM,QAAQ,IAAI,QAAQ;AAAA,EAClC;AACD;AAEO,MAAM,2CAA2B,aAAa;;;"}
@@ -83,7 +83,7 @@ class Application {
83
83
  koa.use(bodyParser({
84
84
  jsonLimit: this.serverConfig.http?.requestBodySize || "1mb"
85
85
  }));
86
- koa.use(corsMiddleware());
86
+ koa.use(corsMiddleware({ exposeHeaders: ["X-Contember-Mutation"] }));
87
87
  const versionMatch = this.version?.match(/^(0\.\d+|\d+)/);
88
88
  const versionSimplified = versionMatch?.[1] ?? "unknown";
89
89
  koa.use(async (ctx) => {