@plitzi/sdk-server 0.32.25 → 0.33.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/README.md +326 -162
- package/dist/adapters/authAdapters.d.ts +21 -0
- package/dist/adapters/authAdapters.js +12 -0
- package/dist/adapters/jsonAdapters.d.ts +15 -0
- package/dist/adapters/jsonAdapters.js +9 -4
- package/dist/core/auth/api.d.ts +148 -0
- package/dist/core/auth/api.js +286 -0
- package/dist/core/auth/authorize.d.ts +96 -0
- package/dist/core/auth/authorize.js +92 -0
- package/dist/core/auth/createAuth.d.ts +165 -0
- package/dist/core/auth/createAuth.js +105 -0
- package/dist/core/auth/credentials.d.ts +29 -0
- package/dist/core/auth/credentials.js +48 -0
- package/dist/core/auth/domains.d.ts +41 -0
- package/dist/core/auth/domains.js +78 -0
- package/dist/core/auth/identity.d.ts +108 -0
- package/dist/core/auth/identity.js +164 -0
- package/dist/core/auth/oauth/client.d.ts +5 -0
- package/dist/core/auth/oauth/client.js +47 -0
- package/dist/core/auth/oauth/index.d.ts +78 -0
- package/dist/core/auth/oauth/index.js +113 -0
- package/dist/core/auth/oauth/providers/github.d.ts +2 -0
- package/dist/core/auth/oauth/providers/github.js +48 -0
- package/dist/core/auth/oauth/providers/google.d.ts +2 -0
- package/dist/core/auth/oauth/providers/google.js +30 -0
- package/dist/core/auth/oauth/state.d.ts +23 -0
- package/dist/core/auth/oauth/state.js +55 -0
- package/dist/core/auth/oauth/types.d.ts +51 -0
- package/dist/core/auth/oauth/types.js +13 -0
- package/dist/core/auth/routes.d.ts +50 -0
- package/dist/core/auth/routes.js +129 -0
- package/dist/core/auth/session.d.ts +128 -0
- package/dist/core/auth/session.js +165 -0
- package/dist/core/auth/spaceTokens.d.ts +137 -0
- package/dist/core/auth/spaceTokens.js +212 -0
- package/dist/core/auth/tokens.d.ts +151 -0
- package/dist/core/auth/tokens.js +221 -0
- package/dist/core/createServer.d.ts +29 -0
- package/dist/core/createServer.js +28 -14
- package/dist/core/handlers/authMiddleware.d.ts +27 -0
- package/dist/core/handlers/authMiddleware.js +38 -0
- package/dist/core/handlers/authRouteHandlers.d.ts +46 -0
- package/dist/core/handlers/authRouteHandlers.js +75 -0
- package/dist/core/handlers/types.d.ts +37 -0
- package/dist/{src/core → core}/http/dispatcher.d.ts +2 -2
- package/dist/core/http/dispatcher.js +8 -6
- package/dist/core/http/navigation.d.ts +11 -0
- package/dist/core/http/navigation.js +16 -0
- package/dist/core/http/securityHeaders.js +6 -4
- package/dist/core/http/stages/authApi.d.ts +17 -0
- package/dist/core/http/stages/authApi.js +66 -0
- package/dist/core/http/stages/authRoutes.js +40 -11
- package/dist/core/http/stages/exchangeRoute.d.ts +15 -0
- package/dist/core/http/stages/exchangeRoute.js +67 -0
- package/dist/core/http/stages/health.d.ts +11 -0
- package/dist/core/http/stages/health.js +25 -3
- package/dist/core/http/stages/middlewares.d.ts +2 -0
- package/dist/core/http/stages/static.d.ts +13 -0
- package/dist/core/http/stages/static.js +21 -6
- package/dist/core/http/types.d.ts +35 -0
- package/dist/{modules/mcp/constants.js → core/previewToken.js} +1 -1
- package/dist/core/sdkAssets.d.ts +16 -0
- package/dist/core/sdkAssets.js +46 -0
- package/dist/core/server/baseServer.js +40 -5
- package/dist/core/server/pageServer.d.ts +7 -0
- package/dist/core/server/pageServer.js +13 -17
- package/dist/core/services/action.d.ts +9 -0
- package/dist/core/services/action.js +21 -0
- package/dist/core/services/registry.d.ts +3 -0
- package/dist/core/services/registry.js +9 -19
- package/dist/{src/core → core}/services/resolve.d.ts +1 -0
- package/dist/core/services/resolve.js +6 -4
- package/dist/core/services/rsc.js +3 -2
- package/dist/core/staticFiles.js +1 -1
- package/dist/{src/core → core}/transports.d.ts +3 -0
- package/dist/core/transports.js +7 -6
- package/dist/handlers.d.ts +58 -0
- package/dist/handlers.js +3 -0
- package/dist/{src/helpers → helpers}/buildResponseHelpers.d.ts +2 -1
- package/dist/helpers/buildResponseHelpers.js +13 -4
- package/dist/helpers/buildServerInfo.d.ts +3 -0
- package/dist/helpers/buildServerInfo.js +25 -3
- package/dist/{src/helpers → helpers}/cache/keys.d.ts +5 -1
- package/dist/helpers/cache/keys.js +1 -1
- package/dist/helpers/compress.d.ts +18 -0
- package/dist/helpers/compress.js +47 -11
- package/dist/helpers/offlineDataLoader.d.ts +11 -0
- package/dist/helpers/offlineDataLoader.js +15 -0
- package/dist/helpers/resolveDebugMode.d.ts +10 -0
- package/dist/helpers/resolveDebugMode.js +13 -0
- package/dist/index.d.ts +16 -2
- package/dist/index.js +9 -20
- package/dist/kernel.d.ts +41 -0
- package/dist/kernel.js +22 -0
- package/dist/middlewares/spaceDeployment.d.ts +2 -0
- package/dist/middlewares/spaceDeployment.js +2 -1
- package/dist/modules/actions/handler.d.ts +11 -0
- package/dist/modules/actions/handler.js +77 -0
- package/dist/modules/connectors/engine.d.ts +42 -0
- package/dist/modules/connectors/engine.js +221 -0
- package/dist/modules/connectors/getByPath.d.ts +8 -0
- package/dist/modules/connectors/getByPath.js +21 -0
- package/dist/modules/connectors/index.d.ts +7 -0
- package/dist/modules/connectors/projection.d.ts +18 -0
- package/dist/modules/connectors/projection.js +108 -0
- package/dist/modules/connectors/resolver.d.ts +18 -0
- package/dist/modules/connectors/resolver.js +68 -0
- package/dist/modules/connectors/types.d.ts +19 -0
- package/dist/{src/modules → modules}/rsc/handler.d.ts +2 -2
- package/dist/modules/rsc/handler.js +54 -2
- package/dist/modules/rsc/resolveRscData.d.ts +35 -0
- package/dist/modules/rsc/resolveRscData.js +74 -0
- package/dist/{src/modules → modules}/ssr/Component.d.ts +4 -1
- package/dist/modules/ssr/Component.js +10 -3
- package/dist/modules/ssr/buildBody.d.ts +9 -0
- package/dist/modules/ssr/handler.d.ts +4 -0
- package/dist/modules/ssr/handler.js +18 -1
- package/dist/{src/modules → modules}/ssr/loadPluginComponents.d.ts +5 -2
- package/dist/modules/ssr/loadPluginComponents.js +20 -2
- package/dist/{src/modules → modules}/ssr/prepareRender.d.ts +2 -2
- package/dist/modules/ssr/prepareRender.js +24 -7
- package/dist/modules/ssr/preview.d.ts +10 -0
- package/dist/modules/ssr/preview.js +5 -78
- package/dist/modules/ssr/registerExternalPlugins.js +1 -1
- package/dist/modules/ssr/streamBody.d.ts +5 -0
- package/dist/modules/ssr/streamBody.js +1 -1
- package/dist/modules/ssr/template.d.ts +2 -0
- package/dist/modules/ssr/template.js +1 -1
- package/dist/plugins/compile.js +1 -1
- package/dist/plugins/manager.js +12 -8
- package/dist/ssr.d.ts +15 -0
- package/dist/ssr.js +4 -0
- package/package.json +29 -25
- package/dist/.gitkeep +0 -0
- package/dist/core/server/mcpServer.js +0 -29
- package/dist/core/services/mcp.js +0 -27
- package/dist/core/services/oauth.js +0 -116
- package/dist/core/services/preview.js +0 -37
- package/dist/core/services/proxy.js +0 -12
- package/dist/mcp.d.ts +0 -2
- package/dist/mcp.js +0 -7
- package/dist/modules/ai/AIEngine.js +0 -120
- package/dist/modules/ai/toolkit.js +0 -59
- package/dist/modules/mcp/apps/example/view/index.tsx +0 -70
- package/dist/modules/mcp/apps/index.js +0 -16
- package/dist/modules/mcp/apps/render/index.js +0 -17
- package/dist/modules/mcp/apps/render/styles.js +0 -54
- package/dist/modules/mcp/apps/render/view/heldBatch.ts +0 -107
- package/dist/modules/mcp/apps/render/view/index.tsx +0 -314
- package/dist/modules/mcp/apps/render/view/streamProgress.ts +0 -137
- package/dist/modules/mcp/apps/shared/assets.js +0 -10
- package/dist/modules/mcp/apps/shared/bundle.js +0 -23
- package/dist/modules/mcp/apps/shared/page.js +0 -34
- package/dist/modules/mcp/apps/shared/registerApp.js +0 -43
- package/dist/modules/mcp/apps/shared/resolve.js +0 -5
- package/dist/modules/mcp/apps/shared/shell.ejs +0 -59
- package/dist/modules/mcp/apps/shared/zodEnglishOnly.js +0 -23
- package/dist/modules/mcp/catalogs/builtinCallbacks.js +0 -204
- package/dist/modules/mcp/catalogs/builtinComponents.js +0 -170
- package/dist/modules/mcp/catalogs/builtinElementCallbacks.js +0 -50
- package/dist/modules/mcp/catalogs/builtinTransformers.js +0 -148
- package/dist/modules/mcp/catalogs/builtinUtilities.js +0 -90
- package/dist/modules/mcp/catalogs/cssCatalog/border.js +0 -30
- package/dist/modules/mcp/catalogs/cssCatalog/box.js +0 -31
- package/dist/modules/mcp/catalogs/cssCatalog/helpers.js +0 -185
- package/dist/modules/mcp/catalogs/cssCatalog/index.js +0 -131
- package/dist/modules/mcp/catalogs/cssCatalog/layout.js +0 -98
- package/dist/modules/mcp/catalogs/cssCatalog/visual.js +0 -144
- package/dist/modules/mcp/catalogs/observed.js +0 -90
- package/dist/modules/mcp/catalogs/paramSpec.js +0 -69
- package/dist/modules/mcp/catalogs/registry.js +0 -89
- package/dist/modules/mcp/handler.js +0 -83
- package/dist/modules/mcp/helpers/agentPrompt.js +0 -104
- package/dist/modules/mcp/helpers/computeVersion.js +0 -16
- package/dist/modules/mcp/helpers/guide.js +0 -467
- package/dist/modules/mcp/helpers/interactions.js +0 -123
- package/dist/modules/mcp/helpers/log.js +0 -64
- package/dist/modules/mcp/helpers/opResult.js +0 -18
- package/dist/modules/mcp/helpers/space.js +0 -300
- package/dist/modules/mcp/helpers/uris.js +0 -44
- package/dist/modules/mcp/previewClient.js +0 -31
- package/dist/modules/mcp/proxy/config.js +0 -63
- package/dist/modules/mcp/proxy/fetch.js +0 -91
- package/dist/modules/mcp/proxy/grant.js +0 -67
- package/dist/modules/mcp/proxy/guard.js +0 -38
- package/dist/modules/mcp/proxy/handler.js +0 -99
- package/dist/modules/mcp/proxy/payload.js +0 -29
- package/dist/modules/mcp/proxy/rewrite.js +0 -138
- package/dist/modules/mcp/proxy/sign.js +0 -15
- package/dist/modules/mcp/proxy/types.js +0 -9
- package/dist/modules/mcp/resources/canonical.js +0 -30
- package/dist/modules/mcp/resources/core.js +0 -18
- package/dist/modules/mcp/resources/envelope.js +0 -14
- package/dist/modules/mcp/resources/primer.js +0 -31
- package/dist/modules/mcp/resources/register.js +0 -190
- package/dist/modules/mcp/resources/renderGuide.js +0 -451
- package/dist/modules/mcp/resources/router.js +0 -37
- package/dist/modules/mcp/resources/schema.js +0 -43
- package/dist/modules/mcp/resources/style.js +0 -34
- package/dist/modules/mcp/screenshotClient.js +0 -47
- package/dist/modules/mcp/server.js +0 -113
- package/dist/modules/mcp/tools/apply/dispatch.js +0 -105
- package/dist/modules/mcp/tools/apply/index.js +0 -150
- package/dist/modules/mcp/tools/apply/writeResult.js +0 -37
- package/dist/modules/mcp/tools/index.js +0 -24
- package/dist/modules/mcp/tools/operations/index.js +0 -45
- package/dist/modules/mcp/tools/operations/schema/bindings/deleteBinding.js +0 -32
- package/dist/modules/mcp/tools/operations/schema/bindings/patchBinding.js +0 -36
- package/dist/modules/mcp/tools/operations/schema/bindings/upsertBinding.js +0 -47
- package/dist/modules/mcp/tools/operations/schema/elements/deleteElement.js +0 -29
- package/dist/modules/mcp/tools/operations/schema/elements/moveElement.js +0 -41
- package/dist/modules/mcp/tools/operations/schema/elements/patchElement.js +0 -58
- package/dist/modules/mcp/tools/operations/schema/elements/repeatElement.js +0 -148
- package/dist/modules/mcp/tools/operations/schema/elements/upsertElement.js +0 -65
- package/dist/modules/mcp/tools/operations/schema/folders/deleteFolder.js +0 -30
- package/dist/modules/mcp/tools/operations/schema/folders/upsertFolder.js +0 -49
- package/dist/modules/mcp/tools/operations/schema/interactions/deleteInteraction.js +0 -52
- package/dist/modules/mcp/tools/operations/schema/interactions/patchInteractionNode.js +0 -47
- package/dist/modules/mcp/tools/operations/schema/interactions/upsertInteractionFlow.js +0 -44
- package/dist/modules/mcp/tools/operations/schema/operations.js +0 -41
- package/dist/modules/mcp/tools/operations/schema/pages/deletePage.js +0 -25
- package/dist/modules/mcp/tools/operations/schema/pages/upsertPage.js +0 -75
- package/dist/modules/mcp/tools/operations/schema/settings/patchSettings.js +0 -45
- package/dist/modules/mcp/tools/operations/schema/shared.js +0 -122
- package/dist/modules/mcp/tools/operations/schema/translator.js +0 -215
- package/dist/modules/mcp/tools/operations/schema/variables/deleteVariable.js +0 -18
- package/dist/modules/mcp/tools/operations/schema/variables/upsertVariable.js +0 -42
- package/dist/modules/mcp/tools/operations/schema/write.js +0 -109
- package/dist/modules/mcp/tools/operations/schemaIds.js +0 -54
- package/dist/modules/mcp/tools/operations/style/definitions/deleteDefinition.js +0 -21
- package/dist/modules/mcp/tools/operations/style/definitions/patchDefinition.js +0 -28
- package/dist/modules/mcp/tools/operations/style/definitions/upsertDefinition.js +0 -24
- package/dist/modules/mcp/tools/operations/style/definitions/upsertDefinitions.js +0 -40
- package/dist/modules/mcp/tools/operations/style/globalStyles/deleteGlobalStyle.js +0 -21
- package/dist/modules/mcp/tools/operations/style/globalStyles/patchGlobalStyle.js +0 -28
- package/dist/modules/mcp/tools/operations/style/globalStyles/upsertGlobalStyle.js +0 -24
- package/dist/modules/mcp/tools/operations/style/idStyles/deleteIdStyle.js +0 -21
- package/dist/modules/mcp/tools/operations/style/idStyles/patchIdStyle.js +0 -28
- package/dist/modules/mcp/tools/operations/style/idStyles/upsertIdStyle.js +0 -24
- package/dist/modules/mcp/tools/operations/style/operations.js +0 -29
- package/dist/modules/mcp/tools/operations/style/shared.js +0 -59
- package/dist/modules/mcp/tools/operations/style/translator.js +0 -101
- package/dist/modules/mcp/tools/operations/style/variables/deleteStyleVariable.js +0 -21
- package/dist/modules/mcp/tools/operations/style/variables/upsertStyleVariable.js +0 -22
- package/dist/modules/mcp/tools/operations/style/write.js +0 -108
- package/dist/modules/mcp/tools/preview.js +0 -37
- package/dist/modules/mcp/tools/read.js +0 -51
- package/dist/modules/mcp/tools/render.js +0 -184
- package/dist/modules/mcp/tools/screenshot.js +0 -83
- package/dist/modules/mcp/tools/search.js +0 -115
- package/dist/modules/mcp/tools/shared/expandOperations.js +0 -44
- package/dist/modules/mcp/tools/shared/tool.js +0 -33
- package/dist/modules/mcp/tools/shared/validator/audit.js +0 -124
- package/dist/modules/mcp/tools/shared/validator/batch.js +0 -39
- package/dist/modules/mcp/tools/shared/validator/bindings.js +0 -70
- package/dist/modules/mcp/tools/shared/validator/context.js +0 -35
- package/dist/modules/mcp/tools/shared/validator/css.js +0 -39
- package/dist/modules/mcp/tools/shared/validator/elements.js +0 -68
- package/dist/modules/mcp/tools/shared/validator/index.js +0 -246
- package/dist/modules/mcp/tools/shared/validator/interactions.js +0 -103
- package/dist/modules/mcp/tools/shared/validator/refs.js +0 -28
- package/dist/modules/mcp/tools/validate.js +0 -47
- package/dist/modules/oauth/authorize.js +0 -177
- package/dist/modules/oauth/challenge.js +0 -33
- package/dist/modules/oauth/consentPage.js +0 -118
- package/dist/modules/oauth/metadata.js +0 -69
- package/dist/modules/oauth/params.js +0 -5
- package/dist/modules/oauth/pkce.js +0 -15
- package/dist/modules/oauth/records.js +0 -46
- package/dist/modules/oauth/register.js +0 -55
- package/dist/modules/oauth/respond.js +0 -44
- package/dist/modules/oauth/token.js +0 -100
- package/dist/public/.gitkeep +0 -0
- package/dist/src/adapters/jsonAdapters.d.ts +0 -7
- package/dist/src/core/createServer.d.ts +0 -14
- package/dist/src/core/http/stages/health.d.ts +0 -2
- package/dist/src/core/http/stages/middlewares.d.ts +0 -2
- package/dist/src/core/http/stages/static.d.ts +0 -5
- package/dist/src/core/http/types.d.ts +0 -22
- package/dist/src/core/server/mcpServer.d.ts +0 -2
- package/dist/src/core/server/pageServer.d.ts +0 -10
- package/dist/src/core/services/mcp.d.ts +0 -3
- package/dist/src/core/services/oauth.d.ts +0 -18
- package/dist/src/core/services/preview.d.ts +0 -2
- package/dist/src/core/services/proxy.d.ts +0 -2
- package/dist/src/core/services/registry.d.ts +0 -4
- package/dist/src/helpers/buildServerInfo.d.ts +0 -2
- package/dist/src/helpers/compress.d.ts +0 -3
- package/dist/src/index.d.ts +0 -15
- package/dist/src/mcp.d.ts +0 -14
- package/dist/src/middlewares/spaceDeployment.d.ts +0 -2
- package/dist/src/modules/ai/AIEngine.d.ts +0 -20
- package/dist/src/modules/ai/index.d.ts +0 -4
- package/dist/src/modules/ai/toolkit.d.ts +0 -17
- package/dist/src/modules/mcp/apps/example/index.d.ts +0 -8
- package/dist/src/modules/mcp/apps/index.d.ts +0 -11
- package/dist/src/modules/mcp/apps/render/index.d.ts +0 -4
- package/dist/src/modules/mcp/apps/render/styles.d.ts +0 -10
- package/dist/src/modules/mcp/apps/shared/assets.d.ts +0 -10
- package/dist/src/modules/mcp/apps/shared/bundle.d.ts +0 -4
- package/dist/src/modules/mcp/apps/shared/index.d.ts +0 -3
- package/dist/src/modules/mcp/apps/shared/page.d.ts +0 -2
- package/dist/src/modules/mcp/apps/shared/registerApp.d.ts +0 -5
- package/dist/src/modules/mcp/apps/shared/resolve.d.ts +0 -1
- package/dist/src/modules/mcp/apps/shared/zodEnglishOnly.d.ts +0 -4
- package/dist/src/modules/mcp/catalogs/builtinCallbacks.d.ts +0 -23
- package/dist/src/modules/mcp/catalogs/builtinComponents.d.ts +0 -4
- package/dist/src/modules/mcp/catalogs/builtinElementCallbacks.d.ts +0 -20
- package/dist/src/modules/mcp/catalogs/builtinTransformers.d.ts +0 -28
- package/dist/src/modules/mcp/catalogs/builtinUtilities.d.ts +0 -18
- package/dist/src/modules/mcp/catalogs/cssCatalog/border.d.ts +0 -4
- package/dist/src/modules/mcp/catalogs/cssCatalog/box.d.ts +0 -4
- package/dist/src/modules/mcp/catalogs/cssCatalog/helpers.d.ts +0 -34
- package/dist/src/modules/mcp/catalogs/cssCatalog/index.d.ts +0 -19
- package/dist/src/modules/mcp/catalogs/cssCatalog/layout.d.ts +0 -9
- package/dist/src/modules/mcp/catalogs/cssCatalog/visual.d.ts +0 -8
- package/dist/src/modules/mcp/catalogs/index.d.ts +0 -9
- package/dist/src/modules/mcp/catalogs/observed.d.ts +0 -48
- package/dist/src/modules/mcp/catalogs/paramSpec.d.ts +0 -42
- package/dist/src/modules/mcp/catalogs/registry.d.ts +0 -35
- package/dist/src/modules/mcp/e2e/index.d.ts +0 -6
- package/dist/src/modules/mcp/e2e/mcpEndpoint.d.ts +0 -27
- package/dist/src/modules/mcp/e2e/postMessageChannel.d.ts +0 -22
- package/dist/src/modules/mcp/e2e/renderingHost.d.ts +0 -34
- package/dist/src/modules/mcp/handler.d.ts +0 -22
- package/dist/src/modules/mcp/helpers/agentPrompt.d.ts +0 -4
- package/dist/src/modules/mcp/helpers/computeVersion.d.ts +0 -1
- package/dist/src/modules/mcp/helpers/guide.d.ts +0 -4
- package/dist/src/modules/mcp/helpers/index.d.ts +0 -8
- package/dist/src/modules/mcp/helpers/interactions.d.ts +0 -30
- package/dist/src/modules/mcp/helpers/log.d.ts +0 -8
- package/dist/src/modules/mcp/helpers/opResult.d.ts +0 -13
- package/dist/src/modules/mcp/helpers/space.d.ts +0 -115
- package/dist/src/modules/mcp/helpers/uris.d.ts +0 -28
- package/dist/src/modules/mcp/index.d.ts +0 -13
- package/dist/src/modules/mcp/previewClient.d.ts +0 -13
- package/dist/src/modules/mcp/proxy/config.d.ts +0 -19
- package/dist/src/modules/mcp/proxy/fetch.d.ts +0 -18
- package/dist/src/modules/mcp/proxy/grant.d.ts +0 -25
- package/dist/src/modules/mcp/proxy/guard.d.ts +0 -6
- package/dist/src/modules/mcp/proxy/handler.d.ts +0 -8
- package/dist/src/modules/mcp/proxy/index.d.ts +0 -8
- package/dist/src/modules/mcp/proxy/payload.d.ts +0 -8
- package/dist/src/modules/mcp/proxy/rewrite.d.ts +0 -18
- package/dist/src/modules/mcp/proxy/sign.d.ts +0 -6
- package/dist/src/modules/mcp/proxy/types.d.ts +0 -45
- package/dist/src/modules/mcp/resources/canonical.d.ts +0 -6
- package/dist/src/modules/mcp/resources/core.d.ts +0 -5
- package/dist/src/modules/mcp/resources/envelope.d.ts +0 -10
- package/dist/src/modules/mcp/resources/index.d.ts +0 -8
- package/dist/src/modules/mcp/resources/primer.d.ts +0 -7
- package/dist/src/modules/mcp/resources/register.d.ts +0 -10
- package/dist/src/modules/mcp/resources/renderGuide.d.ts +0 -10
- package/dist/src/modules/mcp/resources/router.d.ts +0 -10
- package/dist/src/modules/mcp/resources/schema.d.ts +0 -5
- package/dist/src/modules/mcp/resources/style.d.ts +0 -5
- package/dist/src/modules/mcp/screenshotClient.d.ts +0 -13
- package/dist/src/modules/mcp/server.d.ts +0 -31
- package/dist/src/modules/mcp/tests/helpers.d.ts +0 -13
- package/dist/src/modules/mcp/tools/apply/dispatch.d.ts +0 -6
- package/dist/src/modules/mcp/tools/apply/index.d.ts +0 -470
- package/dist/src/modules/mcp/tools/apply/writeResult.d.ts +0 -8
- package/dist/src/modules/mcp/tools/index.d.ts +0 -18
- package/dist/src/modules/mcp/tools/operations/index.d.ts +0 -928
- package/dist/src/modules/mcp/tools/operations/schema/bindings/deleteBinding.d.ts +0 -17
- package/dist/src/modules/mcp/tools/operations/schema/bindings/patchBinding.d.ts +0 -25
- package/dist/src/modules/mcp/tools/operations/schema/bindings/upsertBinding.d.ts +0 -27
- package/dist/src/modules/mcp/tools/operations/schema/elements/deleteElement.d.ts +0 -10
- package/dist/src/modules/mcp/tools/operations/schema/elements/moveElement.d.ts +0 -16
- package/dist/src/modules/mcp/tools/operations/schema/elements/patchElement.d.ts +0 -22
- package/dist/src/modules/mcp/tools/operations/schema/elements/repeatElement.d.ts +0 -55
- package/dist/src/modules/mcp/tools/operations/schema/elements/upsertElement.d.ts +0 -16
- package/dist/src/modules/mcp/tools/operations/schema/folders/deleteFolder.d.ts +0 -9
- package/dist/src/modules/mcp/tools/operations/schema/folders/upsertFolder.d.ts +0 -12
- package/dist/src/modules/mcp/tools/operations/schema/index.d.ts +0 -21
- package/dist/src/modules/mcp/tools/operations/schema/interactions/deleteInteraction.d.ts +0 -12
- package/dist/src/modules/mcp/tools/operations/schema/interactions/patchInteractionNode.d.ts +0 -18
- package/dist/src/modules/mcp/tools/operations/schema/interactions/upsertInteractionFlow.d.ts +0 -27
- package/dist/src/modules/mcp/tools/operations/schema/operations.d.ts +0 -229
- package/dist/src/modules/mcp/tools/operations/schema/pages/deletePage.d.ts +0 -9
- package/dist/src/modules/mcp/tools/operations/schema/pages/upsertPage.d.ts +0 -14
- package/dist/src/modules/mcp/tools/operations/schema/settings/patchSettings.d.ts +0 -34
- package/dist/src/modules/mcp/tools/operations/schema/shared.d.ts +0 -92
- package/dist/src/modules/mcp/tools/operations/schema/translator.d.ts +0 -12
- package/dist/src/modules/mcp/tools/operations/schema/variables/deleteVariable.d.ts +0 -9
- package/dist/src/modules/mcp/tools/operations/schema/variables/upsertVariable.d.ts +0 -16
- package/dist/src/modules/mcp/tools/operations/schema/write.d.ts +0 -42
- package/dist/src/modules/mcp/tools/operations/schemaIds.d.ts +0 -6
- package/dist/src/modules/mcp/tools/operations/style/definitions/deleteDefinition.d.ts +0 -9
- package/dist/src/modules/mcp/tools/operations/style/definitions/patchDefinition.d.ts +0 -37
- package/dist/src/modules/mcp/tools/operations/style/definitions/upsertDefinition.d.ts +0 -37
- package/dist/src/modules/mcp/tools/operations/style/definitions/upsertDefinitions.d.ts +0 -41
- package/dist/src/modules/mcp/tools/operations/style/globalStyles/deleteGlobalStyle.d.ts +0 -9
- package/dist/src/modules/mcp/tools/operations/style/globalStyles/patchGlobalStyle.d.ts +0 -37
- package/dist/src/modules/mcp/tools/operations/style/globalStyles/upsertGlobalStyle.d.ts +0 -37
- package/dist/src/modules/mcp/tools/operations/style/idStyles/deleteIdStyle.d.ts +0 -9
- package/dist/src/modules/mcp/tools/operations/style/idStyles/patchIdStyle.d.ts +0 -37
- package/dist/src/modules/mcp/tools/operations/style/idStyles/upsertIdStyle.d.ts +0 -37
- package/dist/src/modules/mcp/tools/operations/style/index.d.ts +0 -15
- package/dist/src/modules/mcp/tools/operations/style/operations.d.ts +0 -264
- package/dist/src/modules/mcp/tools/operations/style/shared.d.ts +0 -116
- package/dist/src/modules/mcp/tools/operations/style/translator.d.ts +0 -12
- package/dist/src/modules/mcp/tools/operations/style/variables/deleteStyleVariable.d.ts +0 -15
- package/dist/src/modules/mcp/tools/operations/style/variables/upsertStyleVariable.d.ts +0 -20
- package/dist/src/modules/mcp/tools/operations/style/write.d.ts +0 -12
- package/dist/src/modules/mcp/tools/preview.d.ts +0 -465
- package/dist/src/modules/mcp/tools/read.d.ts +0 -9
- package/dist/src/modules/mcp/tools/render.d.ts +0 -499
- package/dist/src/modules/mcp/tools/render.test.d.ts +0 -1
- package/dist/src/modules/mcp/tools/screenshot.d.ts +0 -470
- package/dist/src/modules/mcp/tools/search.d.ts +0 -15
- package/dist/src/modules/mcp/tools/shared/expandOperations.d.ts +0 -13
- package/dist/src/modules/mcp/tools/shared/tool.d.ts +0 -72
- package/dist/src/modules/mcp/tools/shared/validator/audit.d.ts +0 -4
- package/dist/src/modules/mcp/tools/shared/validator/batch.d.ts +0 -5
- package/dist/src/modules/mcp/tools/shared/validator/bindings.d.ts +0 -6
- package/dist/src/modules/mcp/tools/shared/validator/context.d.ts +0 -38
- package/dist/src/modules/mcp/tools/shared/validator/css.d.ts +0 -4
- package/dist/src/modules/mcp/tools/shared/validator/elements.d.ts +0 -7
- package/dist/src/modules/mcp/tools/shared/validator/index.d.ts +0 -8
- package/dist/src/modules/mcp/tools/shared/validator/interactions.d.ts +0 -3
- package/dist/src/modules/mcp/tools/shared/validator/refs.d.ts +0 -4
- package/dist/src/modules/mcp/tools/validate.d.ts +0 -467
- package/dist/src/modules/mcp/types/aiSchema.d.ts +0 -218
- package/dist/src/modules/mcp/types/appTypes.d.ts +0 -26
- package/dist/src/modules/mcp/types/index.d.ts +0 -5
- package/dist/src/modules/mcp/types/previewTypes.d.ts +0 -25
- package/dist/src/modules/mcp/types/screenshotTypes.d.ts +0 -29
- package/dist/src/modules/mcp/types/toolTypes.d.ts +0 -138
- package/dist/src/modules/oauth/authorize.d.ts +0 -7
- package/dist/src/modules/oauth/challenge.d.ts +0 -11
- package/dist/src/modules/oauth/consentPage.d.ts +0 -7
- package/dist/src/modules/oauth/metadata.d.ts +0 -40
- package/dist/src/modules/oauth/params.d.ts +0 -5
- package/dist/src/modules/oauth/pkce.d.ts +0 -6
- package/dist/src/modules/oauth/records.d.ts +0 -71
- package/dist/src/modules/oauth/register.d.ts +0 -5
- package/dist/src/modules/oauth/respond.d.ts +0 -13
- package/dist/src/modules/oauth/token.d.ts +0 -5
- package/dist/src/modules/ssr/buildBody.d.ts +0 -9
- package/dist/src/modules/ssr/handler.d.ts +0 -4
- package/dist/src/modules/ssr/preview.d.ts +0 -16
- package/dist/src/modules/ssr/streamBody.d.ts +0 -5
- package/dist/src/modules/ssr/template.d.ts +0 -6
- package/dist/src/standalone/alias-loader.d.mts +0 -2
- package/dist/src/standalone/plugins/ClientInfo.d.ts +0 -2
- package/dist/src/standalone/plugins/ServerInfo.d.ts +0 -2
- package/dist/src/standalone/plugins/SharedInfo.d.ts +0 -2
- package/dist/src/standalone/plugins/styles.d.ts +0 -5
- package/dist/src/standalone/register-alias.d.mts +0 -1
- package/dist/src/standalone/server.d.ts +0 -1
- package/dist/src/standalone/stubs/react-syntax-highlighter.d.mts +0 -31
- package/skills/plitzi-render/SKILL.md +0 -174
- /package/dist/{src/core/http/dispatcher.test.d.ts → core/auth/api.test.d.ts} +0 -0
- /package/dist/{src/core/server/mcpServer.test.d.ts → core/auth/authorize.test.d.ts} +0 -0
- /package/dist/{src/modules/ai/toolkit.test.d.ts → core/auth/createAuth.test.d.ts} +0 -0
- /package/dist/{src/modules/mcp/apps/apps.test.d.ts → core/auth/domains.test.d.ts} +0 -0
- /package/dist/{src/modules/mcp/apps/render/styles.test.d.ts → core/auth/identity.test.d.ts} +0 -0
- /package/dist/{src/modules → core/auth}/oauth/oauth.test.d.ts +0 -0
- /package/dist/{src/modules/mcp/catalogs/builtinTransformers.test.d.ts → core/auth/routes.test.d.ts} +0 -0
- /package/dist/{src/modules/mcp/catalogs/cssCatalog/cssCatalog.test.d.ts → core/auth/session.test.d.ts} +0 -0
- /package/dist/{src/modules/mcp/e2e/connector.test.d.ts → core/auth/spaceTokens.test.d.ts} +0 -0
- /package/dist/{src/modules/mcp/e2e/host.test.d.ts → core/auth/tokens.test.d.ts} +0 -0
- /package/dist/{src/modules/mcp/e2e/oauthConnector.test.d.ts → core/createServer.test.d.ts} +0 -0
- /package/dist/{src/modules/mcp/helpers/log.test.d.ts → core/handlers/handlers.test.d.ts} +0 -0
- /package/dist/{src/core → core}/health.d.ts +0 -0
- /package/dist/{src/modules/mcp/mcp.bench.d.ts → core/http/dispatcher.test.d.ts} +0 -0
- /package/dist/{src/core → core}/http/securityHeaders.d.ts +0 -0
- /package/dist/{src/core → core}/http/stages/authRoutes.d.ts +0 -0
- /package/dist/{src/core → core}/http/stages/pluginAssets.d.ts +0 -0
- /package/dist/{src/core → core}/mimeTypes.d.ts +0 -0
- /package/dist/{src/modules/mcp/constants.d.ts → core/previewToken.d.ts} +0 -0
- /package/dist/{src/core → core}/requestParser.d.ts +0 -0
- /package/dist/{src/core → core}/server/baseServer.d.ts +0 -0
- /package/dist/{src/modules/mcp/proxy/endpoint.test.d.ts → core/server/baseServer.test.d.ts} +0 -0
- /package/dist/{src/modules/mcp/proxy/proxy.test.d.ts → core/services/resolve.test.d.ts} +0 -0
- /package/dist/{src/core → core}/services/rsc.d.ts +0 -0
- /package/dist/{src/core → core}/services/ssr.d.ts +0 -0
- /package/dist/{src/core → core}/staticFiles.d.ts +0 -0
- /package/dist/{src/modules/mcp/proxy/wiring.test.d.ts → helpers/buildResponseHelpers.test.d.ts} +0 -0
- /package/dist/{src/helpers → helpers}/cache/TtlCache.d.ts +0 -0
- /package/dist/{src/helpers → helpers}/cache/cacheManager.d.ts +0 -0
- /package/dist/{src/helpers → helpers}/cache/defaults.d.ts +0 -0
- /package/dist/{src/helpers → helpers}/cache/index.d.ts +0 -0
- /package/dist/{src/modules/mcp/tests/apply.test.d.ts → helpers/cache/keys.test.d.ts} +0 -0
- /package/dist/{src/helpers → helpers}/cache/serverCaches.d.ts +0 -0
- /package/dist/{src/modules/mcp/tests/bindings.test.d.ts → helpers/compress.test.d.ts} +0 -0
- /package/dist/{src/helpers → helpers}/escapeJson.d.ts +0 -0
- /package/dist/{src/helpers → helpers}/metrics.d.ts +0 -0
- /package/dist/{src/helpers → helpers}/normalizePlugins.d.ts +0 -0
- /package/dist/{src/modules/mcp/tests/css.test.d.ts → helpers/offlineDataLoader.test.d.ts} +0 -0
- /package/dist/{src/helpers → helpers}/readCookie.d.ts +0 -0
- /package/dist/{src/modules/mcp/tests/interactions.test.d.ts → helpers/resolveDebugMode.test.d.ts} +0 -0
- /package/dist/{src/helpers → helpers}/runMiddlewares.d.ts +0 -0
- /package/dist/{src/helpers → helpers}/serverLog.d.ts +0 -0
- /package/dist/{src/middlewares → middlewares}/auth.d.ts +0 -0
- /package/dist/{src/middlewares → middlewares}/basicAuth.d.ts +0 -0
- /package/dist/{src/modules/mcp/tests/pages.test.d.ts → middlewares/spaceDeployment.test.d.ts} +0 -0
- /package/dist/{src/modules/mcp/tests/reads.test.d.ts → modules/actions/handler.test.d.ts} +0 -0
- /package/dist/{src/modules/mcp/tests/schemaIds.test.d.ts → modules/connectors/engine.test.d.ts} +0 -0
- /package/dist/{src/modules/mcp/tests/search.test.d.ts → modules/connectors/projection.test.d.ts} +0 -0
- /package/dist/{src/modules/mcp/tests/skill.test.d.ts → modules/connectors/resolver.test.d.ts} +0 -0
- /package/dist/{src/modules/mcp/tests/styles.test.d.ts → modules/rsc/resolveRscData.test.d.ts} +0 -0
- /package/dist/{src/modules → modules}/ssr/applySSRResult.d.ts +0 -0
- /package/dist/{src/modules/mcp/tests/tools.test.d.ts → modules/ssr/loadPluginComponents.test.d.ts} +0 -0
- /package/dist/{src/modules/mcp/tests/validation.test.d.ts → modules/ssr/metering.test.d.ts} +0 -0
- /package/dist/{src/modules → modules}/ssr/registerExternalPlugins.d.ts +0 -0
- /package/dist/{src/plugins → plugins}/compile.d.ts +0 -0
- /package/dist/{src/plugins → plugins}/copy.d.ts +0 -0
- /package/dist/{src/plugins → plugins}/detect.d.ts +0 -0
- /package/dist/{src/plugins → plugins}/manager.d.ts +0 -0
- /package/dist/{src/plugins → plugins}/validate.d.ts +0 -0
- /package/dist/{src/plugins → plugins}/validate.test.d.ts +0 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { normalizeDomain } from "./domains.js";
|
|
2
|
+
//#region src/core/auth/spaceTokens.ts
|
|
3
|
+
var ROTATION_WARNING = "The previous token stopped working. Every site embedding it must be redeployed.";
|
|
4
|
+
var DAY_SECONDS = 86400;
|
|
5
|
+
var now = () => Math.floor(Date.now() / 1e3);
|
|
6
|
+
var notFound = {
|
|
7
|
+
ok: false,
|
|
8
|
+
status: 404,
|
|
9
|
+
body: { error: "Token not found" }
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* The lifecycle of a space's own credentials, over whatever stores them.
|
|
13
|
+
*
|
|
14
|
+
* Minting one is `tokens.generateSpaceToken`; everything around it is here, and it is all rule rather than storage:
|
|
15
|
+
* a credential whose claims changed is a **different credential**, so every edit below re-mints and the previous one
|
|
16
|
+
* stops working the instant it returns. Saying that once, in one place, is the point — a self-hoster who has to
|
|
17
|
+
* rediscover it discovers it as a published site that went dark.
|
|
18
|
+
*/
|
|
19
|
+
var createSpaceTokenApi = ({ tokens, adapters }) => {
|
|
20
|
+
/** Never empty: a credential with no origins is one that works nowhere. */
|
|
21
|
+
const withFloor = (domains, defaults) => {
|
|
22
|
+
if (domains.includes("*")) return ["*"];
|
|
23
|
+
const merged = [.../* @__PURE__ */ new Set([...defaults, ...domains])];
|
|
24
|
+
return merged.length > 0 ? merged : ["*"];
|
|
25
|
+
};
|
|
26
|
+
const remint = async (record, context, changes = {}) => {
|
|
27
|
+
const origins = withFloor(changes.origins ?? record.origins, context.defaultDomains);
|
|
28
|
+
const expiresAt = changes.expiresAt === void 0 ? record.expiresAt : changes.expiresAt;
|
|
29
|
+
const token = tokens.generateSpaceToken(context.spaceId, origins, record.scope, { expiresAt });
|
|
30
|
+
await adapters.save(record.id, {
|
|
31
|
+
token,
|
|
32
|
+
origins,
|
|
33
|
+
expiresAt
|
|
34
|
+
});
|
|
35
|
+
return {
|
|
36
|
+
token,
|
|
37
|
+
origins,
|
|
38
|
+
expiresAt
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
return {
|
|
42
|
+
/**
|
|
43
|
+
* The space's public credential, rotated in place when it no longer verifies. Rotating on *outdated* and not only
|
|
44
|
+
* on expired is what this endpoint exists for: a site stranded on a credential from a previous token version would
|
|
45
|
+
* otherwise have no way back — nothing else can hand it a working one.
|
|
46
|
+
*/
|
|
47
|
+
async read(context) {
|
|
48
|
+
const record = await adapters.loadDefault(context.spaceId);
|
|
49
|
+
if (!record) return notFound;
|
|
50
|
+
if (!tokens.needsRotation(record.token)) return {
|
|
51
|
+
ok: true,
|
|
52
|
+
body: {
|
|
53
|
+
token: record.token,
|
|
54
|
+
domains: record.origins
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const { token, origins } = await remint(record, context);
|
|
58
|
+
return {
|
|
59
|
+
ok: true,
|
|
60
|
+
body: {
|
|
61
|
+
token,
|
|
62
|
+
domains: origins
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
/**
|
|
67
|
+
* Replace the public credential with a fresh one, keeping everything it declared. This is the control that expiry
|
|
68
|
+
* is often mistaken for: a render credential is meant to outlive any deadline, so revoking a leaked one is an act,
|
|
69
|
+
* not a wait.
|
|
70
|
+
*/
|
|
71
|
+
async rotate(context) {
|
|
72
|
+
const record = await adapters.loadDefault(context.spaceId);
|
|
73
|
+
if (!record) return notFound;
|
|
74
|
+
const { token, origins } = await remint(record, context);
|
|
75
|
+
return {
|
|
76
|
+
ok: true,
|
|
77
|
+
body: {
|
|
78
|
+
token,
|
|
79
|
+
domains: origins,
|
|
80
|
+
warning: ROTATION_WARNING
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
},
|
|
84
|
+
async readDomains(context) {
|
|
85
|
+
const record = await adapters.loadDefault(context.spaceId);
|
|
86
|
+
return record ? {
|
|
87
|
+
ok: true,
|
|
88
|
+
body: { domains: record.origins }
|
|
89
|
+
} : notFound;
|
|
90
|
+
},
|
|
91
|
+
async setDomains(context, domains) {
|
|
92
|
+
if (!Array.isArray(domains) || domains.some((domain) => typeof domain !== "string")) return {
|
|
93
|
+
ok: false,
|
|
94
|
+
status: 400,
|
|
95
|
+
body: { error: "domains must be an array of strings" }
|
|
96
|
+
};
|
|
97
|
+
const normalized = [];
|
|
98
|
+
const rejected = [];
|
|
99
|
+
for (const domain of domains) {
|
|
100
|
+
const value = normalizeDomain(domain);
|
|
101
|
+
if (value) normalized.push(value);
|
|
102
|
+
else rejected.push(domain);
|
|
103
|
+
}
|
|
104
|
+
if (rejected.length > 0) return {
|
|
105
|
+
ok: false,
|
|
106
|
+
status: 400,
|
|
107
|
+
body: {
|
|
108
|
+
error: "Invalid domains",
|
|
109
|
+
domains: rejected
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
const record = await adapters.loadDefault(context.spaceId);
|
|
113
|
+
if (!record) return notFound;
|
|
114
|
+
const { token, origins } = await remint(record, context, { origins: normalized });
|
|
115
|
+
await adapters.onDomainsChanged?.(context.spaceId);
|
|
116
|
+
return {
|
|
117
|
+
ok: true,
|
|
118
|
+
body: {
|
|
119
|
+
token,
|
|
120
|
+
domains: origins,
|
|
121
|
+
...origins.includes("*") && { warning: "This token now works on any domain. Anyone who copies it from a page can use it elsewhere." }
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
},
|
|
125
|
+
async readExpiry(context) {
|
|
126
|
+
const record = await adapters.loadDefault(context.spaceId);
|
|
127
|
+
return record ? {
|
|
128
|
+
ok: true,
|
|
129
|
+
body: {
|
|
130
|
+
expiresAt: record.expiresAt,
|
|
131
|
+
neverExpires: record.expiresAt === null
|
|
132
|
+
}
|
|
133
|
+
} : notFound;
|
|
134
|
+
},
|
|
135
|
+
/**
|
|
136
|
+
* When the public credential should stop working — or never, which is the default. Both are legitimate: a site
|
|
137
|
+
* deployed once and left alone wants no deadline (an expiry there is a scheduled outage), while a campaign page
|
|
138
|
+
* meant to go quiet, or a credential handed to an agency for a fixed engagement, wants one.
|
|
139
|
+
*/
|
|
140
|
+
async setExpiry(context, expiresInDays) {
|
|
141
|
+
const forever = expiresInDays === null || expiresInDays === void 0;
|
|
142
|
+
if (!forever && (typeof expiresInDays !== "number" || !Number.isFinite(expiresInDays) || expiresInDays <= 0)) return {
|
|
143
|
+
ok: false,
|
|
144
|
+
status: 400,
|
|
145
|
+
body: { error: "expiresInDays must be a positive number, or null to never expire" }
|
|
146
|
+
};
|
|
147
|
+
const record = await adapters.loadDefault(context.spaceId);
|
|
148
|
+
if (!record) return notFound;
|
|
149
|
+
const expiry = forever ? null : now() + Math.round(expiresInDays * DAY_SECONDS);
|
|
150
|
+
const { token, expiresAt } = await remint(record, context, { expiresAt: expiry });
|
|
151
|
+
return {
|
|
152
|
+
ok: true,
|
|
153
|
+
body: {
|
|
154
|
+
token,
|
|
155
|
+
expiresAt,
|
|
156
|
+
neverExpires: expiresAt === null,
|
|
157
|
+
warning: ROTATION_WARNING
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
},
|
|
161
|
+
/**
|
|
162
|
+
* The space's credentials, so a leak can be seen and acted on. Never the secrets themselves: an `agent` grant
|
|
163
|
+
* writes, and listing it would turn permission to read into a way to obtain it. The public one is published by
|
|
164
|
+
* construction and has its own endpoint.
|
|
165
|
+
*/
|
|
166
|
+
async list(context) {
|
|
167
|
+
return {
|
|
168
|
+
ok: true,
|
|
169
|
+
body: { tokens: (await adapters.list(context.spaceId)).map(({ token, origins, ...rest }) => {
|
|
170
|
+
return {
|
|
171
|
+
...rest,
|
|
172
|
+
...rest.scope === "render" ? { domains: origins } : { label: origins.join(",") }
|
|
173
|
+
};
|
|
174
|
+
}) }
|
|
175
|
+
};
|
|
176
|
+
},
|
|
177
|
+
/**
|
|
178
|
+
* Revoke one credential. Dropping the record IS the revocation: every grant is looked up as it is verified, so it
|
|
179
|
+
* stops working at once whatever its claims still say.
|
|
180
|
+
*
|
|
181
|
+
* The public credential is deliberately not revocable this way — removing it leaves the published site with no
|
|
182
|
+
* credential at all, and replacing it is what a leak of that one calls for.
|
|
183
|
+
*/
|
|
184
|
+
async revoke(context, tokenId) {
|
|
185
|
+
if (!Number.isFinite(tokenId)) return {
|
|
186
|
+
ok: false,
|
|
187
|
+
status: 400,
|
|
188
|
+
body: { error: "tokenId must be a number" }
|
|
189
|
+
};
|
|
190
|
+
const record = await adapters.find(context.spaceId, tokenId);
|
|
191
|
+
if (!record) return notFound;
|
|
192
|
+
if (record.isDefault) return {
|
|
193
|
+
ok: false,
|
|
194
|
+
status: 400,
|
|
195
|
+
body: {
|
|
196
|
+
error: "The space’s public token cannot be deleted — rotate it instead",
|
|
197
|
+
rotate: `/spaces/${context.spaceId}/token/rotate`
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
await adapters.remove(record.id);
|
|
201
|
+
return {
|
|
202
|
+
ok: true,
|
|
203
|
+
body: {
|
|
204
|
+
message: "Token revoked",
|
|
205
|
+
tokenId
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
};
|
|
211
|
+
//#endregion
|
|
212
|
+
export { createSpaceTokenApi };
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { Algorithm } from 'jsonwebtoken';
|
|
2
|
+
/**
|
|
3
|
+
* Every credential this server mints is a JWT built from REGISTERED claims (RFC 7519) plus `scope` (RFC 6749). There
|
|
4
|
+
* are no bespoke `typ`/`data`/`version` claims: anyone who has read a JWT before can read one of these.
|
|
5
|
+
*
|
|
6
|
+
* iss which deployment minted it — the environment boundary
|
|
7
|
+
* sub who or what it is about: a user id, or a space id
|
|
8
|
+
* aud the API audiences it is meant for
|
|
9
|
+
* scope what it is and what it may do (below)
|
|
10
|
+
* exp / iat / nbf / jti lifetime and identity, as usual
|
|
11
|
+
*
|
|
12
|
+
* The one custom claim is `origins`, because JWT registers nothing for "the web origins this credential may be
|
|
13
|
+
* presented from" — it is what binds a public render token to its domains.
|
|
14
|
+
*/
|
|
15
|
+
export declare const SCOPES: {
|
|
16
|
+
readonly user: "user";
|
|
17
|
+
readonly refresh: "refresh";
|
|
18
|
+
readonly widget: "widget";
|
|
19
|
+
readonly spaceRender: "space:render";
|
|
20
|
+
readonly spaceAgent: "space:agent";
|
|
21
|
+
};
|
|
22
|
+
export type TokenScope = (typeof SCOPES)[keyof typeof SCOPES];
|
|
23
|
+
export type SpaceScope = 'render' | 'agent';
|
|
24
|
+
/** Why a credential was refused. A reason rather than a status, because each transport maps it onto its own. */
|
|
25
|
+
export type AuthFailure = 'missing' | 'malformed' | 'expired' | 'outdated' | 'revoked' | 'wrong-type' | 'scope-mismatch' | 'issuer-not-allowed' | 'origin-not-allowed' | 'domain-not-allowed' | 'inactive';
|
|
26
|
+
export declare const authFailureMessage: Record<AuthFailure, string>;
|
|
27
|
+
/**
|
|
28
|
+
* How long each credential lives. One rule, applied by how much damage the credential can do and whether something
|
|
29
|
+
* can renew it:
|
|
30
|
+
*
|
|
31
|
+
* - The **public render token** is the only one that may live forever, and defaults to it: it is embedded in
|
|
32
|
+
* published sites, where an expiry is a scheduled outage. A space may still give it a date.
|
|
33
|
+
* - **Everything else expires**, 30 days being the baseline.
|
|
34
|
+
* - **The most dangerous one is the shortest.** A session access token rides on every request and is the credential
|
|
35
|
+
* an attacker most wants, so it lasts a day — which costs nobody anything, because the refresh token silently
|
|
36
|
+
* renews it. That pairing is the whole reason it can be this short.
|
|
37
|
+
*/
|
|
38
|
+
export declare const DEFAULT_LIFETIMES: {
|
|
39
|
+
readonly access: 86400;
|
|
40
|
+
readonly refresh: number;
|
|
41
|
+
readonly agent: number;
|
|
42
|
+
readonly widget: number;
|
|
43
|
+
};
|
|
44
|
+
export type TokenLifetimes = Partial<typeof DEFAULT_LIFETIMES>;
|
|
45
|
+
export type TokenConfig = {
|
|
46
|
+
secret: string;
|
|
47
|
+
/** What this deployment mints under. Also accepted on the way back in, along with `alsoAccept`. */
|
|
48
|
+
issuer: string;
|
|
49
|
+
/** Extra issuers to honour — a migration, or a sibling deployment whose credentials are meant to work here. */
|
|
50
|
+
alsoAccept?: string[];
|
|
51
|
+
/**
|
|
52
|
+
* The API audiences a credential is meant for. Defaults to the issuer, which is right for the common case of a
|
|
53
|
+
* deployment that is its own audience — and stops it being a required field that everyone fills in by copying
|
|
54
|
+
* `issuer` into it.
|
|
55
|
+
*/
|
|
56
|
+
audience?: string[];
|
|
57
|
+
algorithms?: Algorithm[];
|
|
58
|
+
lifetimes?: TokenLifetimes;
|
|
59
|
+
};
|
|
60
|
+
interface BaseClaims {
|
|
61
|
+
iss: string;
|
|
62
|
+
aud: string[];
|
|
63
|
+
scope: TokenScope;
|
|
64
|
+
/** Absent on a credential that is revoked rather than expired — see `generateSpaceToken`. */
|
|
65
|
+
exp?: number;
|
|
66
|
+
iat: number;
|
|
67
|
+
nbf: number;
|
|
68
|
+
jti: string;
|
|
69
|
+
}
|
|
70
|
+
export interface UserTokenPayload extends BaseClaims {
|
|
71
|
+
scope: typeof SCOPES.user;
|
|
72
|
+
sub: string;
|
|
73
|
+
}
|
|
74
|
+
export interface RefreshTokenPayload extends BaseClaims {
|
|
75
|
+
scope: typeof SCOPES.refresh;
|
|
76
|
+
sub: string;
|
|
77
|
+
}
|
|
78
|
+
export interface SpaceTokenPayload extends BaseClaims {
|
|
79
|
+
scope: typeof SCOPES.spaceRender | typeof SCOPES.spaceAgent;
|
|
80
|
+
sub: string;
|
|
81
|
+
/** Web origins the space may be embedded on. No registered claim covers this. */
|
|
82
|
+
origins: string[];
|
|
83
|
+
}
|
|
84
|
+
/** The grant that deliberately reaches no space, so it carries no subject either. */
|
|
85
|
+
export interface WidgetTokenPayload extends BaseClaims {
|
|
86
|
+
scope: typeof SCOPES.widget;
|
|
87
|
+
}
|
|
88
|
+
export type TokenPayload = UserTokenPayload | RefreshTokenPayload | SpaceTokenPayload | WidgetTokenPayload;
|
|
89
|
+
export type VerifyResult<T> = {
|
|
90
|
+
ok: true;
|
|
91
|
+
payload: T;
|
|
92
|
+
} | {
|
|
93
|
+
ok: false;
|
|
94
|
+
reason: AuthFailure;
|
|
95
|
+
};
|
|
96
|
+
export interface SpaceTokenOptions {
|
|
97
|
+
/**
|
|
98
|
+
* When the token should stop working, as a unix timestamp. `null`/omitted on a `render` token means never — the
|
|
99
|
+
* space's choice, not a rule. An `agent` grant always gets a lifetime; only the public token may forgo one.
|
|
100
|
+
*/
|
|
101
|
+
expiresAt?: number | null;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* The credential mint and its verifier, bound to one deployment's signing key and issuer.
|
|
105
|
+
*
|
|
106
|
+
* A factory rather than a module of functions because the configuration is the deployment's: its secret, the issuer
|
|
107
|
+
* that separates its universe of credentials from every other, and how long each kind lives. A customer running this
|
|
108
|
+
* server issues under their own and nothing they mint is worth anything here, or the other way round.
|
|
109
|
+
*/
|
|
110
|
+
export declare const createTokens: (config: TokenConfig) => {
|
|
111
|
+
lifetimes: {
|
|
112
|
+
access: 86400;
|
|
113
|
+
refresh: number;
|
|
114
|
+
agent: number;
|
|
115
|
+
widget: number;
|
|
116
|
+
};
|
|
117
|
+
generateUserToken: (userId: number | string) => string;
|
|
118
|
+
generateRefreshToken: (userId: number | string) => string;
|
|
119
|
+
generateWidgetToken: () => string;
|
|
120
|
+
/**
|
|
121
|
+
* A `render` token may live forever, and defaults to it, because it is embedded in a published site — often a
|
|
122
|
+
* SPA deployed once and left alone — where an expiry is a scheduled outage: the site breaks weeks later with
|
|
123
|
+
* nobody having touched anything. The deadline also buys little there, since the token is public by
|
|
124
|
+
* construction. What limits it is what it may do (read published content), where it may be presented (its
|
|
125
|
+
* declared domains), and the row behind it, which the owner can rotate or delete at any moment — revocation,
|
|
126
|
+
* not expiry, is the control.
|
|
127
|
+
*
|
|
128
|
+
* An `agent` grant is the opposite default and always carries a lifetime: it writes, and it is held by a
|
|
129
|
+
* third-party host.
|
|
130
|
+
*/
|
|
131
|
+
generateSpaceToken: (spaceId: number | string, origins: string[], scope?: SpaceScope, { expiresAt }?: SpaceTokenOptions) => string;
|
|
132
|
+
verifyUserToken: (token: string) => VerifyResult<UserTokenPayload>;
|
|
133
|
+
verifyRefreshToken: (token: string) => VerifyResult<RefreshTokenPayload>;
|
|
134
|
+
verifyWidgetToken: (token: string) => VerifyResult<WidgetTokenPayload>;
|
|
135
|
+
verifySpaceToken: (token: string) => VerifyResult<SpaceTokenPayload & {
|
|
136
|
+
spaceId: number;
|
|
137
|
+
spaceScope: SpaceScope;
|
|
138
|
+
}>;
|
|
139
|
+
/**
|
|
140
|
+
* A token that no longer verifies for any reason the issuer can fix by re-minting — expiry, a pre-registered-
|
|
141
|
+
* claims shape, or an issuer from a deployment this one is not. Used by the endpoints that hand tokens back
|
|
142
|
+
* out, so a caller never has to know why.
|
|
143
|
+
*/
|
|
144
|
+
needsRotation: (token: string) => boolean;
|
|
145
|
+
/** Undefined for a credential that never expires, which is what a host should read as "no renewal needed". */
|
|
146
|
+
expiresInSeconds: (token: string) => number | undefined;
|
|
147
|
+
};
|
|
148
|
+
export type Tokens = ReturnType<typeof createTokens>;
|
|
149
|
+
/** The user id a session or refresh token is about. */
|
|
150
|
+
export declare const userIdOf: (payload: UserTokenPayload | RefreshTokenPayload) => number;
|
|
151
|
+
export {};
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
import jwt from "jsonwebtoken";
|
|
3
|
+
//#region src/core/auth/tokens.ts
|
|
4
|
+
/**
|
|
5
|
+
* Every credential this server mints is a JWT built from REGISTERED claims (RFC 7519) plus `scope` (RFC 6749). There
|
|
6
|
+
* are no bespoke `typ`/`data`/`version` claims: anyone who has read a JWT before can read one of these.
|
|
7
|
+
*
|
|
8
|
+
* iss which deployment minted it — the environment boundary
|
|
9
|
+
* sub who or what it is about: a user id, or a space id
|
|
10
|
+
* aud the API audiences it is meant for
|
|
11
|
+
* scope what it is and what it may do (below)
|
|
12
|
+
* exp / iat / nbf / jti lifetime and identity, as usual
|
|
13
|
+
*
|
|
14
|
+
* The one custom claim is `origins`, because JWT registers nothing for "the web origins this credential may be
|
|
15
|
+
* presented from" — it is what binds a public render token to its domains.
|
|
16
|
+
*/
|
|
17
|
+
var SCOPES = {
|
|
18
|
+
user: "user",
|
|
19
|
+
refresh: "refresh",
|
|
20
|
+
widget: "widget",
|
|
21
|
+
spaceRender: "space:render",
|
|
22
|
+
spaceAgent: "space:agent"
|
|
23
|
+
};
|
|
24
|
+
var authFailureMessage = {
|
|
25
|
+
missing: "Authentication required",
|
|
26
|
+
malformed: "Token Invalid",
|
|
27
|
+
expired: "Token expired",
|
|
28
|
+
outdated: "Token outdated",
|
|
29
|
+
revoked: "Token Invalid",
|
|
30
|
+
"wrong-type": "Token Invalid",
|
|
31
|
+
"scope-mismatch": "Token Invalid",
|
|
32
|
+
"issuer-not-allowed": "Token was issued by another environment",
|
|
33
|
+
"origin-not-allowed": "Access Not Authorized",
|
|
34
|
+
"domain-not-allowed": "This token is not allowed on this domain",
|
|
35
|
+
inactive: "Account is not active"
|
|
36
|
+
};
|
|
37
|
+
var DAY = 86400;
|
|
38
|
+
/**
|
|
39
|
+
* How long each credential lives. One rule, applied by how much damage the credential can do and whether something
|
|
40
|
+
* can renew it:
|
|
41
|
+
*
|
|
42
|
+
* - The **public render token** is the only one that may live forever, and defaults to it: it is embedded in
|
|
43
|
+
* published sites, where an expiry is a scheduled outage. A space may still give it a date.
|
|
44
|
+
* - **Everything else expires**, 30 days being the baseline.
|
|
45
|
+
* - **The most dangerous one is the shortest.** A session access token rides on every request and is the credential
|
|
46
|
+
* an attacker most wants, so it lasts a day — which costs nobody anything, because the refresh token silently
|
|
47
|
+
* renews it. That pairing is the whole reason it can be this short.
|
|
48
|
+
*/
|
|
49
|
+
var DEFAULT_LIFETIMES = {
|
|
50
|
+
access: DAY,
|
|
51
|
+
refresh: 30 * DAY,
|
|
52
|
+
agent: 30 * DAY,
|
|
53
|
+
widget: 30 * DAY
|
|
54
|
+
};
|
|
55
|
+
var spaceScopeToClaim = {
|
|
56
|
+
render: SCOPES.spaceRender,
|
|
57
|
+
agent: SCOPES.spaceAgent
|
|
58
|
+
};
|
|
59
|
+
var claimToSpaceScope = {
|
|
60
|
+
[SCOPES.spaceRender]: "render",
|
|
61
|
+
[SCOPES.spaceAgent]: "agent"
|
|
62
|
+
};
|
|
63
|
+
var isLegacyShape = (payload) => "data" in payload || "version" in payload;
|
|
64
|
+
var subjectId = (payload) => {
|
|
65
|
+
if (typeof payload.sub !== "string") return;
|
|
66
|
+
const id = Number(payload.sub);
|
|
67
|
+
return Number.isInteger(id) ? id : void 0;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* The credential mint and its verifier, bound to one deployment's signing key and issuer.
|
|
71
|
+
*
|
|
72
|
+
* A factory rather than a module of functions because the configuration is the deployment's: its secret, the issuer
|
|
73
|
+
* that separates its universe of credentials from every other, and how long each kind lives. A customer running this
|
|
74
|
+
* server issues under their own and nothing they mint is worth anything here, or the other way round.
|
|
75
|
+
*/
|
|
76
|
+
var createTokens = (config) => {
|
|
77
|
+
const lifetimes = {
|
|
78
|
+
...DEFAULT_LIFETIMES,
|
|
79
|
+
...config.lifetimes
|
|
80
|
+
};
|
|
81
|
+
const allowedIssuers = [config.issuer, ...config.alsoAccept ?? []];
|
|
82
|
+
const algorithms = config.algorithms ?? ["HS256"];
|
|
83
|
+
const baseClaims = (scope, ttlSeconds) => {
|
|
84
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
85
|
+
return {
|
|
86
|
+
iss: config.issuer,
|
|
87
|
+
aud: config.audience ?? [config.issuer],
|
|
88
|
+
scope,
|
|
89
|
+
...ttlSeconds === void 0 ? {} : { exp: now + ttlSeconds },
|
|
90
|
+
iat: now,
|
|
91
|
+
jti: randomBytes(8).toString("hex"),
|
|
92
|
+
nbf: now
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
const sign = (payload) => jwt.sign(payload, config.secret, { algorithm: algorithms[0] });
|
|
96
|
+
const verify = (token) => {
|
|
97
|
+
if (!token) return {
|
|
98
|
+
ok: false,
|
|
99
|
+
reason: "missing"
|
|
100
|
+
};
|
|
101
|
+
let decoded;
|
|
102
|
+
try {
|
|
103
|
+
decoded = jwt.verify(token, config.secret, { algorithms });
|
|
104
|
+
} catch (e) {
|
|
105
|
+
return {
|
|
106
|
+
ok: false,
|
|
107
|
+
reason: e.name === "TokenExpiredError" ? "expired" : "malformed"
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
const payload = decoded;
|
|
111
|
+
if (isLegacyShape(payload)) return {
|
|
112
|
+
ok: false,
|
|
113
|
+
reason: "outdated"
|
|
114
|
+
};
|
|
115
|
+
if (typeof payload.scope !== "string") return {
|
|
116
|
+
ok: false,
|
|
117
|
+
reason: "malformed"
|
|
118
|
+
};
|
|
119
|
+
if (typeof payload.iss !== "string" || !allowedIssuers.includes(payload.iss)) return {
|
|
120
|
+
ok: false,
|
|
121
|
+
reason: "issuer-not-allowed"
|
|
122
|
+
};
|
|
123
|
+
return {
|
|
124
|
+
ok: true,
|
|
125
|
+
payload
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
const verifyScoped = (token, scopes) => {
|
|
129
|
+
const result = verify(token);
|
|
130
|
+
if (!result.ok) return result;
|
|
131
|
+
if (!scopes.includes(result.payload.scope)) return {
|
|
132
|
+
ok: false,
|
|
133
|
+
reason: "wrong-type"
|
|
134
|
+
};
|
|
135
|
+
return {
|
|
136
|
+
ok: true,
|
|
137
|
+
payload: result.payload
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
const withSubject = (result) => {
|
|
141
|
+
if (!result.ok) return result;
|
|
142
|
+
return subjectId(result.payload) === void 0 ? {
|
|
143
|
+
ok: false,
|
|
144
|
+
reason: "malformed"
|
|
145
|
+
} : result;
|
|
146
|
+
};
|
|
147
|
+
return {
|
|
148
|
+
lifetimes,
|
|
149
|
+
generateUserToken: (userId) => sign({
|
|
150
|
+
sub: String(userId),
|
|
151
|
+
...baseClaims(SCOPES.user, lifetimes.access)
|
|
152
|
+
}),
|
|
153
|
+
generateRefreshToken: (userId) => sign({
|
|
154
|
+
sub: String(userId),
|
|
155
|
+
...baseClaims(SCOPES.refresh, lifetimes.refresh)
|
|
156
|
+
}),
|
|
157
|
+
generateWidgetToken: () => sign(baseClaims(SCOPES.widget, lifetimes.widget)),
|
|
158
|
+
/**
|
|
159
|
+
* A `render` token may live forever, and defaults to it, because it is embedded in a published site — often a
|
|
160
|
+
* SPA deployed once and left alone — where an expiry is a scheduled outage: the site breaks weeks later with
|
|
161
|
+
* nobody having touched anything. The deadline also buys little there, since the token is public by
|
|
162
|
+
* construction. What limits it is what it may do (read published content), where it may be presented (its
|
|
163
|
+
* declared domains), and the row behind it, which the owner can rotate or delete at any moment — revocation,
|
|
164
|
+
* not expiry, is the control.
|
|
165
|
+
*
|
|
166
|
+
* An `agent` grant is the opposite default and always carries a lifetime: it writes, and it is held by a
|
|
167
|
+
* third-party host.
|
|
168
|
+
*/
|
|
169
|
+
generateSpaceToken: (spaceId, origins, scope = "render", { expiresAt } = {}) => {
|
|
170
|
+
const defaultTtl = scope === "agent" ? lifetimes.agent : void 0;
|
|
171
|
+
const ttlSeconds = expiresAt == null ? defaultTtl : Math.max(0, expiresAt - Math.floor(Date.now() / 1e3));
|
|
172
|
+
return sign({
|
|
173
|
+
sub: String(spaceId),
|
|
174
|
+
origins,
|
|
175
|
+
...baseClaims(spaceScopeToClaim[scope], ttlSeconds)
|
|
176
|
+
});
|
|
177
|
+
},
|
|
178
|
+
verifyUserToken: (token) => withSubject(verifyScoped(token, [SCOPES.user])),
|
|
179
|
+
verifyRefreshToken: (token) => withSubject(verifyScoped(token, [SCOPES.refresh])),
|
|
180
|
+
verifyWidgetToken: (token) => verifyScoped(token, [SCOPES.widget]),
|
|
181
|
+
verifySpaceToken: (token) => {
|
|
182
|
+
const result = withSubject(verifyScoped(token, [SCOPES.spaceRender, SCOPES.spaceAgent]));
|
|
183
|
+
if (!result.ok) return result;
|
|
184
|
+
const spaceId = subjectId(result.payload);
|
|
185
|
+
const spaceScope = claimToSpaceScope[result.payload.scope];
|
|
186
|
+
if (spaceId === void 0 || !spaceScope) return {
|
|
187
|
+
ok: false,
|
|
188
|
+
reason: "malformed"
|
|
189
|
+
};
|
|
190
|
+
const origins = result.payload.origins;
|
|
191
|
+
return {
|
|
192
|
+
ok: true,
|
|
193
|
+
payload: {
|
|
194
|
+
...result.payload,
|
|
195
|
+
origins: Array.isArray(origins) ? origins : [],
|
|
196
|
+
spaceId,
|
|
197
|
+
spaceScope
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
},
|
|
201
|
+
/**
|
|
202
|
+
* A token that no longer verifies for any reason the issuer can fix by re-minting — expiry, a pre-registered-
|
|
203
|
+
* claims shape, or an issuer from a deployment this one is not. Used by the endpoints that hand tokens back
|
|
204
|
+
* out, so a caller never has to know why.
|
|
205
|
+
*/
|
|
206
|
+
needsRotation: (token) => {
|
|
207
|
+
const result = verify(token);
|
|
208
|
+
return !result.ok && result.reason !== "malformed";
|
|
209
|
+
},
|
|
210
|
+
/** Undefined for a credential that never expires, which is what a host should read as "no renewal needed". */
|
|
211
|
+
expiresInSeconds: (token) => {
|
|
212
|
+
const result = verify(token);
|
|
213
|
+
if (!result.ok || result.payload.exp === void 0) return;
|
|
214
|
+
return Math.max(0, result.payload.exp - Math.floor(Date.now() / 1e3));
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
};
|
|
218
|
+
/** The user id a session or refresh token is about. */
|
|
219
|
+
var userIdOf = (payload) => Number(payload.sub);
|
|
220
|
+
//#endregion
|
|
221
|
+
export { DEFAULT_LIFETIMES, SCOPES, authFailureMessage, createTokens, userIdOf };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Auth } from './auth/createAuth';
|
|
2
|
+
import { PipelineExtensions } from './http/types';
|
|
3
|
+
import { SSRPageAdapters, SSRServer, SSRServerConfig } from '@plitzi/sdk-shared';
|
|
4
|
+
export { resolveServices } from './services/resolve';
|
|
5
|
+
export type { PipelineExtensions } from './http/types';
|
|
6
|
+
export type { ResolvedServices } from './services/resolve';
|
|
7
|
+
export type ServerConfig = Omit<SSRServerConfig, 'adapters'> & {
|
|
8
|
+
/** A page server resolves and renders a space on every request, so the two adapters that do it are required
|
|
9
|
+
* here — see {@link SSRPageAdapters}. They are optional on the shared type because a server that renders no
|
|
10
|
+
* page (a dedicated MCP one) has nothing to answer them with. */
|
|
11
|
+
adapters: SSRPageAdapters;
|
|
12
|
+
/**
|
|
13
|
+
* A `createAuth(...)` result, and the whole of wiring sessions into a page server: the three adapters it answers
|
|
14
|
+
* for get filled in, and the cookie naming comes with them.
|
|
15
|
+
*
|
|
16
|
+
* That last part is the reason this takes the object rather than leaving a deployment to spread `ssrAdapters`
|
|
17
|
+
* itself. The naming would then be declared twice — here and in `createAuth` — and the two halves would write and
|
|
18
|
+
* read a session under different names the first time one of them was edited alone. Anything set explicitly on
|
|
19
|
+
* `adapters` or `authCookie` still wins, so a deployment can override one piece without giving up the rest.
|
|
20
|
+
*/
|
|
21
|
+
auth?: Auth;
|
|
22
|
+
};
|
|
23
|
+
/** The server this package makes: pages and RSC, mounting whatever the config enables, plus any stages a
|
|
24
|
+
* companion package contributes through `extensions`. The MCP endpoint, the widget proxy and draft-preview
|
|
25
|
+
* arrive that way from `@plitzi/sdk-mcp`, which a page-only deployment never installs.
|
|
26
|
+
*
|
|
27
|
+
* A dedicated MCP server is `createServer` from `@plitzi/sdk-mcp` — it builds none of the render template,
|
|
28
|
+
* caches or plugin manager this one does. */
|
|
29
|
+
export declare const createServer: ({ auth, ...config }: ServerConfig, extensions?: PipelineExtensions) => SSRServer;
|
|
@@ -1,19 +1,33 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createAuthApiStage } from "./http/stages/authApi.js";
|
|
2
2
|
import { resolveServices } from "./services/resolve.js";
|
|
3
|
-
import { createPageServer
|
|
3
|
+
import { createPageServer } from "./server/pageServer.js";
|
|
4
4
|
//#region src/core/createServer.ts
|
|
5
|
-
/** The
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
/** The server this package makes: pages and RSC, mounting whatever the config enables, plus any stages a
|
|
6
|
+
* companion package contributes through `extensions`. The MCP endpoint, the widget proxy and draft-preview
|
|
7
|
+
* arrive that way from `@plitzi/sdk-mcp`, which a page-only deployment never installs.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
* A dedicated MCP server is `createServer` from `@plitzi/sdk-mcp` — it builds none of the render template,
|
|
10
|
+
* caches or plugin manager this one does. */
|
|
11
|
+
var createServer = ({ auth, ...config }, extensions) => {
|
|
12
|
+
if (!auth) return createPageServer(config, resolveServices(config), extensions);
|
|
13
|
+
const entries = Object.entries(config.adapters);
|
|
14
|
+
const supplied = Object.fromEntries(entries.filter(([, value]) => value !== void 0));
|
|
15
|
+
const resolved = {
|
|
16
|
+
loginPath: false,
|
|
17
|
+
logoutPath: false,
|
|
18
|
+
exchangePath: false,
|
|
19
|
+
...config,
|
|
20
|
+
authCookie: config.authCookie ?? auth.cookieConfig,
|
|
21
|
+
adapters: {
|
|
22
|
+
...auth.ssrAdapters,
|
|
23
|
+
...supplied
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const withAuthRoutes = {
|
|
27
|
+
...extensions,
|
|
28
|
+
preAuth: [...extensions?.preAuth ?? [], createAuthApiStage(auth, auth.basePath)]
|
|
29
|
+
};
|
|
30
|
+
return createPageServer(resolved, resolveServices(resolved), withAuthRoutes);
|
|
17
31
|
};
|
|
18
32
|
//#endregion
|
|
19
|
-
export {
|
|
33
|
+
export { createServer, resolveServices };
|