@plitzi/sdk-server 0.32.24 → 0.33.0
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 +22 -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 -46
- package/dist/modules/mcp/proxy/fetch.js +0 -91
- package/dist/modules/mcp/proxy/grant.js +0 -65
- package/dist/modules/mcp/proxy/guard.js +0 -38
- package/dist/modules/mcp/proxy/handler.js +0 -68
- package/dist/modules/mcp/proxy/rewrite.js +0 -72
- 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 -17
- package/dist/src/modules/mcp/proxy/fetch.d.ts +0 -18
- package/dist/src/modules/mcp/proxy/grant.d.ts +0 -23
- 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 -7
- package/dist/src/modules/mcp/proxy/rewrite.d.ts +0 -13
- 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,50 @@
|
|
|
1
|
+
import { AuthApi, AuthOutcome } from './api';
|
|
2
|
+
import { AuthPolicy, Requirement } from './authorize';
|
|
3
|
+
import { CredentialCarrier } from './credentials';
|
|
4
|
+
import { Actor } from './identity';
|
|
5
|
+
import { CookieSink, SessionCookies } from './session';
|
|
6
|
+
/**
|
|
7
|
+
* A request, as the auth flows need to read one. Everything here is either already on a `node:http` request or was
|
|
8
|
+
* put there by the host: the parsed body, and the actor the guard resolved. No framework appears in it, because the
|
|
9
|
+
* flows below have no opinion about how the request arrived.
|
|
10
|
+
*/
|
|
11
|
+
export interface AuthRequest extends CredentialCarrier {
|
|
12
|
+
body?: unknown;
|
|
13
|
+
/** Whoever `createAuthorizer` resolved for this request, when it resolved anyone. */
|
|
14
|
+
actor?: Actor;
|
|
15
|
+
}
|
|
16
|
+
export interface AuthRoute {
|
|
17
|
+
method: 'GET' | 'POST';
|
|
18
|
+
/** Relative to wherever the host mounts them — `/auth`, conventionally. */
|
|
19
|
+
path: string;
|
|
20
|
+
/**
|
|
21
|
+
* What a caller must present. Carried on the descriptor because it is a property OF the flow, not of the host: a
|
|
22
|
+
* sign-in endpoint is public because signing in is what a stranger does, and `/auth/refresh` and `/auth/logout` are
|
|
23
|
+
* public because they authenticate themselves with the refresh credential — a session whose access token has
|
|
24
|
+
* lapsed must still be able to renew or end itself, or a live refresh token could never be revoked.
|
|
25
|
+
*/
|
|
26
|
+
requirement: Requirement;
|
|
27
|
+
handler: (req: AuthRequest) => Promise<AuthOutcome> | AuthOutcome;
|
|
28
|
+
}
|
|
29
|
+
/** The flows, ready to mount. Which of them actually answer is decided by the API itself — no adapter, no endpoint —
|
|
30
|
+
* so mounting all of them is correct even for a deployment that offers three. */
|
|
31
|
+
export declare const authRoutes: ({ api, cookies }: {
|
|
32
|
+
api: AuthApi;
|
|
33
|
+
cookies: SessionCookies;
|
|
34
|
+
}) => AuthRoute[];
|
|
35
|
+
/**
|
|
36
|
+
* The same flows as authorization rules, for the guard that runs in front of them.
|
|
37
|
+
*
|
|
38
|
+
* Derived rather than restated, because a host keeping its own list has to remember to edit it every time this table
|
|
39
|
+
* changes. Forgetting in one direction hides a sign-in endpoint behind the session it exists to create; forgetting in
|
|
40
|
+
* the other opens one that was never meant to be reachable. `prefix` is wherever the host mounted them.
|
|
41
|
+
*/
|
|
42
|
+
export declare const authPolicyRules: (prefix?: string) => AuthPolicy["rules"];
|
|
43
|
+
/**
|
|
44
|
+
* Does what an outcome says about the session cookies. Separate from sending the body because only the host knows how
|
|
45
|
+
* to do that, and because getting this half wrong — writing the session but not its readable hint, or clearing one of
|
|
46
|
+
* the three on sign-out — is the failure that looks like a session that exists and then does not.
|
|
47
|
+
*/
|
|
48
|
+
export declare const applySessionOutcome: (req: {
|
|
49
|
+
hostname: string;
|
|
50
|
+
}, res: CookieSink, outcome: AuthOutcome, cookies: SessionCookies) => void;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
//#region src/core/auth/routes.ts
|
|
2
|
+
var body = (req) => req.body ?? {};
|
|
3
|
+
/** A body field as a string, whatever arrived. Handlers validate what they need; this only stops `[object Object]`. */
|
|
4
|
+
var field = (req, name) => {
|
|
5
|
+
const value = body(req)[name];
|
|
6
|
+
return typeof value === "string" ? value : "";
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* The whole `/auth` surface as data: which method and path each flow answers on, what a caller must present, and what
|
|
10
|
+
* to call.
|
|
11
|
+
*
|
|
12
|
+
* A table rather than a router, because this server does not know what the host is — a deployment may serve it from
|
|
13
|
+
* Express, from Fastify, or from a bare `node:http` switch. Mapping twelve descriptors onto any of those is a handful
|
|
14
|
+
* of lines; getting the paths, the methods and the credential precedence subtly wrong is a session that silently does
|
|
15
|
+
* not work.
|
|
16
|
+
*
|
|
17
|
+
* One table, read twice — once for the handlers and once for the guard in front of them — so the two can never
|
|
18
|
+
* disagree about which of these a stranger may reach.
|
|
19
|
+
*/
|
|
20
|
+
var FLOWS = [
|
|
21
|
+
{
|
|
22
|
+
method: "GET",
|
|
23
|
+
path: "/capabilities",
|
|
24
|
+
requirement: "public",
|
|
25
|
+
run: (api) => api.describe()
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
method: "GET",
|
|
29
|
+
path: "/session",
|
|
30
|
+
requirement: "actor",
|
|
31
|
+
run: (api, _cookies, req) => api.session(req.actor)
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
method: "POST",
|
|
35
|
+
path: "/login",
|
|
36
|
+
requirement: "public",
|
|
37
|
+
run: (api, _cookies, req) => api.login(body(req))
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
method: "POST",
|
|
41
|
+
path: "/refresh",
|
|
42
|
+
requirement: "public",
|
|
43
|
+
run: (api, cookies, req) => api.refresh(cookies.resolveRefreshToken(req, req.body))
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
method: "POST",
|
|
47
|
+
path: "/logout",
|
|
48
|
+
requirement: "public",
|
|
49
|
+
run: (api, cookies, req) => api.logout({
|
|
50
|
+
accessToken: cookies.resolveSessionToken(req),
|
|
51
|
+
refreshToken: cookies.resolveRefreshToken(req, req.body)
|
|
52
|
+
})
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
method: "POST",
|
|
56
|
+
path: "/sessions/revoke",
|
|
57
|
+
requirement: "actor",
|
|
58
|
+
run: (api, _cookies, req) => api.revokeSessions(req.actor?.id)
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
method: "POST",
|
|
62
|
+
path: "/exchange",
|
|
63
|
+
requirement: "grant",
|
|
64
|
+
run: (api, _cookies, req) => api.exchange(field(req, "provider"), field(req, "token"), req)
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
method: "POST",
|
|
68
|
+
path: "/signup",
|
|
69
|
+
requirement: "public",
|
|
70
|
+
run: (api, _cookies, req) => api.signup(body(req))
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
method: "POST",
|
|
74
|
+
path: "/forgot-password",
|
|
75
|
+
requirement: "public",
|
|
76
|
+
run: (api, _cookies, req) => api.forgotPassword(field(req, "email"))
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
method: "POST",
|
|
80
|
+
path: "/reset-password",
|
|
81
|
+
requirement: "public",
|
|
82
|
+
run: (api, _cookies, req) => api.resetPassword(field(req, "token"), field(req, "password"))
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
method: "POST",
|
|
86
|
+
path: "/validate-account",
|
|
87
|
+
requirement: "public",
|
|
88
|
+
run: (api, _cookies, req) => api.validateAccount(field(req, "token"))
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
method: "POST",
|
|
92
|
+
path: "/resend-verification-email",
|
|
93
|
+
requirement: "public",
|
|
94
|
+
run: (api, _cookies, req) => api.resendVerification(field(req, "email"))
|
|
95
|
+
}
|
|
96
|
+
];
|
|
97
|
+
/** The flows, ready to mount. Which of them actually answer is decided by the API itself — no adapter, no endpoint —
|
|
98
|
+
* so mounting all of them is correct even for a deployment that offers three. */
|
|
99
|
+
var authRoutes = ({ api, cookies }) => FLOWS.map(({ run, ...route }) => ({
|
|
100
|
+
...route,
|
|
101
|
+
handler: (req) => run(api, cookies, req)
|
|
102
|
+
}));
|
|
103
|
+
/**
|
|
104
|
+
* The same flows as authorization rules, for the guard that runs in front of them.
|
|
105
|
+
*
|
|
106
|
+
* Derived rather than restated, because a host keeping its own list has to remember to edit it every time this table
|
|
107
|
+
* changes. Forgetting in one direction hides a sign-in endpoint behind the session it exists to create; forgetting in
|
|
108
|
+
* the other opens one that was never meant to be reachable. `prefix` is wherever the host mounted them.
|
|
109
|
+
*/
|
|
110
|
+
var authPolicyRules = (prefix = "/auth") => {
|
|
111
|
+
const byRequirement = /* @__PURE__ */ new Map();
|
|
112
|
+
for (const { path, requirement } of FLOWS) byRequirement.set(requirement, [...byRequirement.get(requirement) ?? [], `${prefix}${path}`]);
|
|
113
|
+
return [...byRequirement].map(([requirement, paths]) => ({
|
|
114
|
+
match: paths,
|
|
115
|
+
requirement
|
|
116
|
+
}));
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* Does what an outcome says about the session cookies. Separate from sending the body because only the host knows how
|
|
120
|
+
* to do that, and because getting this half wrong — writing the session but not its readable hint, or clearing one of
|
|
121
|
+
* the three on sign-out — is the failure that looks like a session that exists and then does not.
|
|
122
|
+
*/
|
|
123
|
+
var applySessionOutcome = (req, res, outcome, cookies) => {
|
|
124
|
+
if (!outcome.ok) return;
|
|
125
|
+
if (outcome.session) cookies.write(req, res, outcome.session);
|
|
126
|
+
if (outcome.endSession) cookies.clear(req, res);
|
|
127
|
+
};
|
|
128
|
+
//#endregion
|
|
129
|
+
export { applySessionOutcome, authPolicyRules, authRoutes };
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { SSRAuthCookie, SSRRequest, SSRSession } from '@plitzi/sdk-shared';
|
|
2
|
+
/**
|
|
3
|
+
* Anything that can carry `Set-Cookie`. Express `Response` and this server's own helpers both satisfy it, which is
|
|
4
|
+
* what lets one writer serve both — a deployment that wrote its own would drift from the one SSR uses, and a session
|
|
5
|
+
* established on one side would be invisible to the other.
|
|
6
|
+
*/
|
|
7
|
+
export interface CookieSink {
|
|
8
|
+
setHeader: (name: string, value: string | string[]) => void;
|
|
9
|
+
getHeader?: (name: string) => string | string[] | number | undefined;
|
|
10
|
+
headers?: Record<string, string | string[] | number | undefined>;
|
|
11
|
+
}
|
|
12
|
+
export type SessionCookieParams = {
|
|
13
|
+
name: string;
|
|
14
|
+
domain?: string;
|
|
15
|
+
secure: boolean;
|
|
16
|
+
sameSite: 'lax' | 'none';
|
|
17
|
+
refreshPath: string;
|
|
18
|
+
hintSuffix: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Whether the host is a loopback name or a `.localhost` sibling. Local hosts get no Domain on their cookies (browsers
|
|
22
|
+
* refuse one on a single-label host) and lax SameSite, because Secure + SameSite=None over plain http is dropped.
|
|
23
|
+
*/
|
|
24
|
+
export declare const isLocalHost: (hostname: string) => boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Everything about how a session cookie is written, derived from the request host unless the deployment says
|
|
27
|
+
* otherwise. The defaults are the ones a server on a real domain needs: a cookie shared across sub-domains, and
|
|
28
|
+
* SameSite=None + Secure so it survives the app and the API being different hosts. A local server gets the
|
|
29
|
+
* opposite, because Secure + SameSite=None over plain http is dropped by every browser.
|
|
30
|
+
*/
|
|
31
|
+
export declare const sessionCookieParams: (hostname: string, config?: SSRAuthCookie) => SessionCookieParams;
|
|
32
|
+
/**
|
|
33
|
+
* The value of the readable companion cookie: `<access expiry>.<refresh expiry>`, unix seconds, refresh optional.
|
|
34
|
+
*
|
|
35
|
+
* It exists because the session cookie is httpOnly — correctly — which leaves a page unable to tell whether the
|
|
36
|
+
* browser holds a session at all. Answering that costs a request per page load otherwise, and the answer is usually
|
|
37
|
+
* "nobody is signed in". This carries no credential: any script that can read it could have asked the backend the
|
|
38
|
+
* same question with `credentials: 'include'`.
|
|
39
|
+
*/
|
|
40
|
+
export declare const sessionHintValue: (expiresAt: number, refreshExpiresAt?: number) => string;
|
|
41
|
+
/**
|
|
42
|
+
* Writes a granted session onto the response: the credential itself, the refresh half confined to its own path, and
|
|
43
|
+
* the readable hint. One call, because the three only make sense together — a hint that outlives its session sends
|
|
44
|
+
* clients to renew something that is gone, and one that dies early signs out a live session.
|
|
45
|
+
*/
|
|
46
|
+
export declare const writeSessionCookies: (req: {
|
|
47
|
+
hostname: string;
|
|
48
|
+
}, res: CookieSink, session: SSRSession, config?: SSRAuthCookie) => void;
|
|
49
|
+
/** Ends the session in this browser. Every cookie the grant wrote is cleared, the readable one included. */
|
|
50
|
+
export declare const clearSessionCookies: (req: {
|
|
51
|
+
hostname: string;
|
|
52
|
+
}, res: CookieSink, config?: SSRAuthCookie) => void;
|
|
53
|
+
/**
|
|
54
|
+
* The cookie a social sign-in leaves behind while the browser is away at the provider. Same family, same policy, so
|
|
55
|
+
* it is written here rather than by whoever happens to be driving the flow. Path `/` because a deployment may serve
|
|
56
|
+
* its API under a prefix, and the callback would then miss a cookie scoped to `/auth`.
|
|
57
|
+
*/
|
|
58
|
+
export declare const writeFlowCookie: (req: {
|
|
59
|
+
hostname: string;
|
|
60
|
+
}, res: CookieSink, value: string, ttlSeconds: number, config?: SSRAuthCookie) => void;
|
|
61
|
+
export declare const clearFlowCookie: (req: {
|
|
62
|
+
hostname: string;
|
|
63
|
+
}, res: CookieSink, config?: SSRAuthCookie) => void;
|
|
64
|
+
/** The value that flow cookie carries, for the callback leg. */
|
|
65
|
+
export declare const readFlowCookie: (req: SSRRequest | {
|
|
66
|
+
headers: {
|
|
67
|
+
cookie?: string;
|
|
68
|
+
};
|
|
69
|
+
hostname: string;
|
|
70
|
+
}, config?: SSRAuthCookie) => string | undefined;
|
|
71
|
+
/** The session credential this request carries, for an adapter that resolves identity from it. */
|
|
72
|
+
export declare const readSessionToken: (req: SSRRequest | {
|
|
73
|
+
headers: {
|
|
74
|
+
cookie?: string;
|
|
75
|
+
};
|
|
76
|
+
hostname: string;
|
|
77
|
+
}, config?: SSRAuthCookie) => string | undefined;
|
|
78
|
+
/** The renewal credential, which rides in its own cookie confined to the refresh path. */
|
|
79
|
+
export declare const readRefreshToken: (req: SSRRequest | {
|
|
80
|
+
headers: {
|
|
81
|
+
cookie?: string;
|
|
82
|
+
};
|
|
83
|
+
hostname: string;
|
|
84
|
+
}, config?: SSRAuthCookie) => string | undefined;
|
|
85
|
+
/** Anything a credential can be read off: this server's own request, an Express one, a bare `node:http` one. */
|
|
86
|
+
export type CookieCarrier = SSRRequest | {
|
|
87
|
+
headers: {
|
|
88
|
+
cookie?: string;
|
|
89
|
+
authorization?: string;
|
|
90
|
+
};
|
|
91
|
+
hostname: string;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* The cookie side of a session with this deployment's naming already bound in.
|
|
95
|
+
*
|
|
96
|
+
* The functions above take the naming on every call, which is right for the server's own internals and tedious for a
|
|
97
|
+
* host that answers dozens of requests with the same configuration. Nothing here knows about any framework: it takes
|
|
98
|
+
* a request that can be read and something that can carry `Set-Cookie`, which is as true of `node:http` as it is of
|
|
99
|
+
* Express — a self-hoster running neither still gets the whole cycle.
|
|
100
|
+
*/
|
|
101
|
+
export declare const createSessionCookies: (config?: SSRAuthCookie) => {
|
|
102
|
+
write: (req: {
|
|
103
|
+
hostname: string;
|
|
104
|
+
}, res: CookieSink, session: SSRSession) => void;
|
|
105
|
+
clear: (req: {
|
|
106
|
+
hostname: string;
|
|
107
|
+
}, res: CookieSink) => void;
|
|
108
|
+
/** Holds a social sign-in between its two legs: the CSRF nonce and the PKCE verifier. */
|
|
109
|
+
writeFlow: (req: {
|
|
110
|
+
hostname: string;
|
|
111
|
+
}, res: CookieSink, value: string, ttlSeconds: number) => void;
|
|
112
|
+
clearFlow: (req: {
|
|
113
|
+
hostname: string;
|
|
114
|
+
}, res: CookieSink) => void;
|
|
115
|
+
readFlow: (req: CookieCarrier) => string | undefined;
|
|
116
|
+
/**
|
|
117
|
+
* The session credential from `Authorization: Bearer` or the cookie, so one endpoint serves a bearer client and a
|
|
118
|
+
* browser. The header wins: a caller that went to the trouble of presenting one means it.
|
|
119
|
+
*/
|
|
120
|
+
resolveSessionToken: (req: CookieCarrier) => string | undefined;
|
|
121
|
+
/**
|
|
122
|
+
* The renewal credential from the request body (`refresh_token`, for API clients) or its cookie (for browsers).
|
|
123
|
+
* The body wins when both are present, mirroring how the session credential is resolved. `body` is whatever the
|
|
124
|
+
* host parsed — this only reads one field off it, so a host that parses JSON its own way still fits.
|
|
125
|
+
*/
|
|
126
|
+
resolveRefreshToken: (req: CookieCarrier, body?: unknown) => string | undefined;
|
|
127
|
+
};
|
|
128
|
+
export type SessionCookies = ReturnType<typeof createSessionCookies>;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { isIP } from "node:net";
|
|
2
|
+
//#region src/core/auth/session.ts
|
|
3
|
+
var LOCAL_HOSTS = [
|
|
4
|
+
"localhost",
|
|
5
|
+
"127.0.0.1",
|
|
6
|
+
"::1"
|
|
7
|
+
];
|
|
8
|
+
/**
|
|
9
|
+
* Whether the host is a loopback name or a `.localhost` sibling. Local hosts get no Domain on their cookies (browsers
|
|
10
|
+
* refuse one on a single-label host) and lax SameSite, because Secure + SameSite=None over plain http is dropped.
|
|
11
|
+
*/
|
|
12
|
+
var isLocalHost = (hostname) => LOCAL_HOSTS.includes(hostname) || hostname.endsWith(".localhost");
|
|
13
|
+
var isIpAddress = (hostname) => isIP(hostname) !== 0;
|
|
14
|
+
/**
|
|
15
|
+
* The last two labels of the host, so a session established on one sub-domain is carried by its siblings — an app
|
|
16
|
+
* and the API it talks to are rarely the same host. Local and IP hosts get no domain at all: browsers refuse a
|
|
17
|
+
* Domain on a single-label host, and one written for an address would never be sent back to it.
|
|
18
|
+
*/
|
|
19
|
+
var registrableDomain = (hostname) => {
|
|
20
|
+
if (isLocalHost(hostname) || isIpAddress(hostname)) return;
|
|
21
|
+
const match = /([^.]+\.[^.]+)$/.exec(hostname);
|
|
22
|
+
return match ? `.${match[1]}` : void 0;
|
|
23
|
+
};
|
|
24
|
+
var resolve = (value, hostname, fallback) => {
|
|
25
|
+
if (typeof value === "function") return value(hostname);
|
|
26
|
+
return value ?? fallback;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Everything about how a session cookie is written, derived from the request host unless the deployment says
|
|
30
|
+
* otherwise. The defaults are the ones a server on a real domain needs: a cookie shared across sub-domains, and
|
|
31
|
+
* SameSite=None + Secure so it survives the app and the API being different hosts. A local server gets the
|
|
32
|
+
* opposite, because Secure + SameSite=None over plain http is dropped by every browser.
|
|
33
|
+
*/
|
|
34
|
+
var sessionCookieParams = (hostname, config = {}) => {
|
|
35
|
+
const local = isLocalHost(hostname);
|
|
36
|
+
return {
|
|
37
|
+
name: resolve(config.name, hostname, "plitzi_session"),
|
|
38
|
+
domain: resolve(config.domain, hostname, registrableDomain(hostname)),
|
|
39
|
+
secure: config.secure ?? !local,
|
|
40
|
+
sameSite: config.sameSite ?? (local ? "lax" : "none"),
|
|
41
|
+
refreshPath: config.refreshPath ?? "/auth",
|
|
42
|
+
hintSuffix: config.hintSuffix ?? "_hint"
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* The value of the readable companion cookie: `<access expiry>.<refresh expiry>`, unix seconds, refresh optional.
|
|
47
|
+
*
|
|
48
|
+
* It exists because the session cookie is httpOnly — correctly — which leaves a page unable to tell whether the
|
|
49
|
+
* browser holds a session at all. Answering that costs a request per page load otherwise, and the answer is usually
|
|
50
|
+
* "nobody is signed in". This carries no credential: any script that can read it could have asked the backend the
|
|
51
|
+
* same question with `credentials: 'include'`.
|
|
52
|
+
*/
|
|
53
|
+
var sessionHintValue = (expiresAt, refreshExpiresAt) => `${Math.floor(expiresAt)}.${refreshExpiresAt === void 0 ? "" : Math.floor(refreshExpiresAt)}`;
|
|
54
|
+
var serializeCookie = (name, value, maxAgeSeconds, params, { httpOnly = true, path = "/" } = {}) => {
|
|
55
|
+
const parts = [
|
|
56
|
+
`${name}=${encodeURIComponent(value)}`,
|
|
57
|
+
`Path=${path}`,
|
|
58
|
+
...httpOnly ? ["HttpOnly"] : [],
|
|
59
|
+
`SameSite=${params.sameSite === "none" ? "None" : "Lax"}`,
|
|
60
|
+
`Max-Age=${Math.max(0, Math.floor(maxAgeSeconds))}`
|
|
61
|
+
];
|
|
62
|
+
if (params.domain) parts.push(`Domain=${params.domain}`);
|
|
63
|
+
if (params.secure) parts.push("Secure");
|
|
64
|
+
return parts.join("; ");
|
|
65
|
+
};
|
|
66
|
+
var nowInSeconds = () => Math.floor(Date.now() / 1e3);
|
|
67
|
+
/**
|
|
68
|
+
* Adds to `Set-Cookie` rather than replacing it. A handler may already have written one — clearing an OAuth flow
|
|
69
|
+
* before granting the session it produced is exactly that — and replacing the header would silently drop it.
|
|
70
|
+
*/
|
|
71
|
+
var appendCookies = (res, cookies) => {
|
|
72
|
+
const existing = res.getHeader?.("set-cookie") ?? res.headers?.["set-cookie"];
|
|
73
|
+
const previous = Array.isArray(existing) ? existing : typeof existing === "string" ? [existing] : [];
|
|
74
|
+
res.setHeader("Set-Cookie", [...previous, ...cookies]);
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Writes a granted session onto the response: the credential itself, the refresh half confined to its own path, and
|
|
78
|
+
* the readable hint. One call, because the three only make sense together — a hint that outlives its session sends
|
|
79
|
+
* clients to renew something that is gone, and one that dies early signs out a live session.
|
|
80
|
+
*/
|
|
81
|
+
var writeSessionCookies = (req, res, session, config) => {
|
|
82
|
+
const params = sessionCookieParams(req.hostname, config);
|
|
83
|
+
const now = nowInSeconds();
|
|
84
|
+
const cookies = [serializeCookie(params.name, session.token, session.expiresAt - now, params)];
|
|
85
|
+
if (session.refreshToken) cookies.push(serializeCookie(`${params.name}_refresh`, session.refreshToken, (session.refreshExpiresAt ?? session.expiresAt) - now, params, { path: params.refreshPath }));
|
|
86
|
+
cookies.push(serializeCookie(`${params.name}${params.hintSuffix}`, sessionHintValue(session.expiresAt, session.refreshExpiresAt), (session.refreshExpiresAt ?? session.expiresAt) - now, params, { httpOnly: false }));
|
|
87
|
+
appendCookies(res, cookies);
|
|
88
|
+
};
|
|
89
|
+
/** Ends the session in this browser. Every cookie the grant wrote is cleared, the readable one included. */
|
|
90
|
+
var clearSessionCookies = (req, res, config) => {
|
|
91
|
+
const params = sessionCookieParams(req.hostname, config);
|
|
92
|
+
appendCookies(res, [
|
|
93
|
+
serializeCookie(params.name, "", 0, params),
|
|
94
|
+
serializeCookie(`${params.name}_refresh`, "", 0, params, { path: params.refreshPath }),
|
|
95
|
+
serializeCookie(`${params.name}${params.hintSuffix}`, "", 0, params, { httpOnly: false })
|
|
96
|
+
]);
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* The cookie a social sign-in leaves behind while the browser is away at the provider. Same family, same policy, so
|
|
100
|
+
* it is written here rather than by whoever happens to be driving the flow. Path `/` because a deployment may serve
|
|
101
|
+
* its API under a prefix, and the callback would then miss a cookie scoped to `/auth`.
|
|
102
|
+
*/
|
|
103
|
+
var writeFlowCookie = (req, res, value, ttlSeconds, config) => {
|
|
104
|
+
const params = sessionCookieParams(req.hostname, config);
|
|
105
|
+
appendCookies(res, [serializeCookie(`${params.name}_oauth`, value, ttlSeconds, params)]);
|
|
106
|
+
};
|
|
107
|
+
var clearFlowCookie = (req, res, config) => {
|
|
108
|
+
const params = sessionCookieParams(req.hostname, config);
|
|
109
|
+
appendCookies(res, [serializeCookie(`${params.name}_oauth`, "", 0, params)]);
|
|
110
|
+
};
|
|
111
|
+
/** The value that flow cookie carries, for the callback leg. */
|
|
112
|
+
var readFlowCookie = (req, config) => readCookie(req, `${sessionCookieParams(req.hostname, config).name}_oauth`);
|
|
113
|
+
var parseCookieHeader = (header) => {
|
|
114
|
+
const cookies = {};
|
|
115
|
+
for (const part of header.split(";")) {
|
|
116
|
+
const separator = part.indexOf("=");
|
|
117
|
+
if (separator === -1) continue;
|
|
118
|
+
cookies[part.slice(0, separator).trim()] = decodeURIComponent(part.slice(separator + 1).trim());
|
|
119
|
+
}
|
|
120
|
+
return cookies;
|
|
121
|
+
};
|
|
122
|
+
var readCookie = (req, name) => {
|
|
123
|
+
const header = req.headers.cookie;
|
|
124
|
+
return header ? parseCookieHeader(header)[name] || void 0 : void 0;
|
|
125
|
+
};
|
|
126
|
+
/** The session credential this request carries, for an adapter that resolves identity from it. */
|
|
127
|
+
var readSessionToken = (req, config) => readCookie(req, sessionCookieParams(req.hostname, config).name);
|
|
128
|
+
/** The renewal credential, which rides in its own cookie confined to the refresh path. */
|
|
129
|
+
var readRefreshToken = (req, config) => readCookie(req, `${sessionCookieParams(req.hostname, config).name}_refresh`);
|
|
130
|
+
/**
|
|
131
|
+
* The cookie side of a session with this deployment's naming already bound in.
|
|
132
|
+
*
|
|
133
|
+
* The functions above take the naming on every call, which is right for the server's own internals and tedious for a
|
|
134
|
+
* host that answers dozens of requests with the same configuration. Nothing here knows about any framework: it takes
|
|
135
|
+
* a request that can be read and something that can carry `Set-Cookie`, which is as true of `node:http` as it is of
|
|
136
|
+
* Express — a self-hoster running neither still gets the whole cycle.
|
|
137
|
+
*/
|
|
138
|
+
var createSessionCookies = (config) => ({
|
|
139
|
+
write: (req, res, session) => writeSessionCookies(req, res, session, config),
|
|
140
|
+
clear: (req, res) => clearSessionCookies(req, res, config),
|
|
141
|
+
/** Holds a social sign-in between its two legs: the CSRF nonce and the PKCE verifier. */
|
|
142
|
+
writeFlow: (req, res, value, ttlSeconds) => writeFlowCookie(req, res, value, ttlSeconds, config),
|
|
143
|
+
clearFlow: (req, res) => clearFlowCookie(req, res, config),
|
|
144
|
+
readFlow: (req) => readFlowCookie(req, config),
|
|
145
|
+
/**
|
|
146
|
+
* The session credential from `Authorization: Bearer` or the cookie, so one endpoint serves a bearer client and a
|
|
147
|
+
* browser. The header wins: a caller that went to the trouble of presenting one means it.
|
|
148
|
+
*/
|
|
149
|
+
resolveSessionToken: (req) => {
|
|
150
|
+
const header = req.headers.authorization;
|
|
151
|
+
return (header?.startsWith("Bearer ") ? header.slice(7).trim() : "") || readSessionToken(req, config);
|
|
152
|
+
},
|
|
153
|
+
/**
|
|
154
|
+
* The renewal credential from the request body (`refresh_token`, for API clients) or its cookie (for browsers).
|
|
155
|
+
* The body wins when both are present, mirroring how the session credential is resolved. `body` is whatever the
|
|
156
|
+
* host parsed — this only reads one field off it, so a host that parses JSON its own way still fits.
|
|
157
|
+
*/
|
|
158
|
+
resolveRefreshToken: (req, body) => {
|
|
159
|
+
const presented = body?.refresh_token;
|
|
160
|
+
if (typeof presented === "string" && presented.trim() !== "") return presented.trim();
|
|
161
|
+
return readRefreshToken(req, config);
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
//#endregion
|
|
165
|
+
export { clearFlowCookie, clearSessionCookies, createSessionCookies, isLocalHost, readFlowCookie, readRefreshToken, readSessionToken, sessionCookieParams, sessionHintValue, writeFlowCookie, writeSessionCookies };
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { SpaceScope, Tokens } from './tokens';
|
|
2
|
+
/**
|
|
3
|
+
* A stored space credential, as whatever stores them reports one. `origins` is already parsed: how a deployment keeps
|
|
4
|
+
* the list (a joined column, a join table, a JSON blob) is its business and never leaks into the rules below.
|
|
5
|
+
*/
|
|
6
|
+
export interface SpaceTokenRecord {
|
|
7
|
+
id: number;
|
|
8
|
+
token: string;
|
|
9
|
+
scope: SpaceScope;
|
|
10
|
+
/** The space's public credential — the one published sites embed. Exactly one row per space carries this. */
|
|
11
|
+
isDefault: boolean;
|
|
12
|
+
origins: string[];
|
|
13
|
+
/** Unix seconds, or null for a credential that never expires. */
|
|
14
|
+
expiresAt: number | null;
|
|
15
|
+
userId?: number | null;
|
|
16
|
+
createdAt?: number;
|
|
17
|
+
updatedAt?: number;
|
|
18
|
+
}
|
|
19
|
+
export interface SpaceTokenAdapters {
|
|
20
|
+
loadDefault: (spaceId: number) => Promise<SpaceTokenRecord | undefined>;
|
|
21
|
+
find: (spaceId: number, tokenId: number) => Promise<SpaceTokenRecord | undefined>;
|
|
22
|
+
list: (spaceId: number) => Promise<SpaceTokenRecord[]>;
|
|
23
|
+
save: (id: number, values: {
|
|
24
|
+
token: string;
|
|
25
|
+
origins?: string[];
|
|
26
|
+
expiresAt?: number | null;
|
|
27
|
+
}) => Promise<void>;
|
|
28
|
+
remove: (id: number) => Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* The domain list is two policies at once — where the credential may be presented, and who may frame the space — so
|
|
31
|
+
* a deployment that caches either gets told the moment it changes, rather than serving the old one until its TTL.
|
|
32
|
+
*/
|
|
33
|
+
onDomainsChanged?: (spaceId: number) => Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The floor a space is always reachable on: the platform-owned domain it is published under. Merged into every list so
|
|
37
|
+
* narrowing the domains to a custom one cannot lock a published site out of its own credential. Which domains those
|
|
38
|
+
* are is the deployment's to say — the rule that they are never dropped is not.
|
|
39
|
+
*/
|
|
40
|
+
export interface SpaceTokenContext {
|
|
41
|
+
spaceId: number;
|
|
42
|
+
defaultDomains: string[];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* What a handler answers. The success body is typed per handler so a binding can reshape it — Plitzi's `GET /token`
|
|
46
|
+
* serves the bare credential for compatibility with its own older API — without casting its way back to it.
|
|
47
|
+
*/
|
|
48
|
+
export type SpaceTokenOutcome<B extends object = object> = {
|
|
49
|
+
ok: true;
|
|
50
|
+
status?: number;
|
|
51
|
+
body: B;
|
|
52
|
+
} | {
|
|
53
|
+
ok: false;
|
|
54
|
+
status: number;
|
|
55
|
+
body: {
|
|
56
|
+
error: string;
|
|
57
|
+
} & Record<string, unknown>;
|
|
58
|
+
};
|
|
59
|
+
export type SpaceTokenSummary = Omit<SpaceTokenRecord, 'token' | 'origins'> & {
|
|
60
|
+
domains?: string[];
|
|
61
|
+
label?: string;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* The lifecycle of a space's own credentials, over whatever stores them.
|
|
65
|
+
*
|
|
66
|
+
* Minting one is `tokens.generateSpaceToken`; everything around it is here, and it is all rule rather than storage:
|
|
67
|
+
* a credential whose claims changed is a **different credential**, so every edit below re-mints and the previous one
|
|
68
|
+
* stops working the instant it returns. Saying that once, in one place, is the point — a self-hoster who has to
|
|
69
|
+
* rediscover it discovers it as a published site that went dark.
|
|
70
|
+
*/
|
|
71
|
+
export declare const createSpaceTokenApi: ({ tokens, adapters }: {
|
|
72
|
+
tokens: Tokens;
|
|
73
|
+
adapters: SpaceTokenAdapters;
|
|
74
|
+
}) => {
|
|
75
|
+
/**
|
|
76
|
+
* The space's public credential, rotated in place when it no longer verifies. Rotating on *outdated* and not only
|
|
77
|
+
* on expired is what this endpoint exists for: a site stranded on a credential from a previous token version would
|
|
78
|
+
* otherwise have no way back — nothing else can hand it a working one.
|
|
79
|
+
*/
|
|
80
|
+
read(context: SpaceTokenContext): Promise<SpaceTokenOutcome<{
|
|
81
|
+
token: string;
|
|
82
|
+
domains: string[];
|
|
83
|
+
}>>;
|
|
84
|
+
/**
|
|
85
|
+
* Replace the public credential with a fresh one, keeping everything it declared. This is the control that expiry
|
|
86
|
+
* is often mistaken for: a render credential is meant to outlive any deadline, so revoking a leaked one is an act,
|
|
87
|
+
* not a wait.
|
|
88
|
+
*/
|
|
89
|
+
rotate(context: SpaceTokenContext): Promise<SpaceTokenOutcome<{
|
|
90
|
+
token: string;
|
|
91
|
+
domains: string[];
|
|
92
|
+
warning: string;
|
|
93
|
+
}>>;
|
|
94
|
+
readDomains(context: SpaceTokenContext): Promise<SpaceTokenOutcome<{
|
|
95
|
+
domains: string[];
|
|
96
|
+
}>>;
|
|
97
|
+
setDomains(context: SpaceTokenContext, domains: unknown): Promise<SpaceTokenOutcome<{
|
|
98
|
+
token: string;
|
|
99
|
+
domains: string[];
|
|
100
|
+
warning?: string;
|
|
101
|
+
}>>;
|
|
102
|
+
readExpiry(context: SpaceTokenContext): Promise<SpaceTokenOutcome<{
|
|
103
|
+
expiresAt: number | null;
|
|
104
|
+
neverExpires: boolean;
|
|
105
|
+
}>>;
|
|
106
|
+
/**
|
|
107
|
+
* When the public credential should stop working — or never, which is the default. Both are legitimate: a site
|
|
108
|
+
* deployed once and left alone wants no deadline (an expiry there is a scheduled outage), while a campaign page
|
|
109
|
+
* meant to go quiet, or a credential handed to an agency for a fixed engagement, wants one.
|
|
110
|
+
*/
|
|
111
|
+
setExpiry(context: SpaceTokenContext, expiresInDays: unknown): Promise<SpaceTokenOutcome<{
|
|
112
|
+
token: string;
|
|
113
|
+
expiresAt: number | null;
|
|
114
|
+
neverExpires: boolean;
|
|
115
|
+
warning: string;
|
|
116
|
+
}>>;
|
|
117
|
+
/**
|
|
118
|
+
* The space's credentials, so a leak can be seen and acted on. Never the secrets themselves: an `agent` grant
|
|
119
|
+
* writes, and listing it would turn permission to read into a way to obtain it. The public one is published by
|
|
120
|
+
* construction and has its own endpoint.
|
|
121
|
+
*/
|
|
122
|
+
list(context: SpaceTokenContext): Promise<SpaceTokenOutcome<{
|
|
123
|
+
tokens: SpaceTokenSummary[];
|
|
124
|
+
}>>;
|
|
125
|
+
/**
|
|
126
|
+
* Revoke one credential. Dropping the record IS the revocation: every grant is looked up as it is verified, so it
|
|
127
|
+
* stops working at once whatever its claims still say.
|
|
128
|
+
*
|
|
129
|
+
* The public credential is deliberately not revocable this way — removing it leaves the published site with no
|
|
130
|
+
* credential at all, and replacing it is what a leak of that one calls for.
|
|
131
|
+
*/
|
|
132
|
+
revoke(context: SpaceTokenContext, tokenId: number): Promise<SpaceTokenOutcome<{
|
|
133
|
+
message: string;
|
|
134
|
+
tokenId: number;
|
|
135
|
+
}>>;
|
|
136
|
+
};
|
|
137
|
+
export type SpaceTokenApi = ReturnType<typeof createSpaceTokenApi>;
|