@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
package/dist/helpers/compress.js
CHANGED
|
@@ -1,17 +1,53 @@
|
|
|
1
1
|
import { brotliCompressSync, constants, gzipSync } from "node:zlib";
|
|
2
2
|
//#region src/helpers/compress.ts
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
/** What the server does when the deployment says nothing: Brotli where the client takes it, gzip otherwise. */
|
|
4
|
+
var DEFAULT_COMPRESSION = {
|
|
5
|
+
encodings: ["br", "gzip"],
|
|
6
|
+
threshold: 1024,
|
|
7
|
+
brotliQuality: 4,
|
|
8
|
+
gzipLevel: 6
|
|
9
9
|
};
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
/**
|
|
11
|
+
* The deployment's compression policy, with the gaps filled in. `false` means never compress, and is expressed as
|
|
12
|
+
* an empty encoding list so there is one shape downstream rather than a boolean to re-test at every use.
|
|
13
|
+
*/
|
|
14
|
+
var resolveCompression = (config) => {
|
|
15
|
+
if (config === false) return {
|
|
16
|
+
...DEFAULT_COMPRESSION,
|
|
17
|
+
encodings: []
|
|
18
|
+
};
|
|
19
|
+
return {
|
|
20
|
+
...DEFAULT_COMPRESSION,
|
|
21
|
+
...config
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* What the client will accept, as a set of tokens it did NOT refuse.
|
|
26
|
+
*
|
|
27
|
+
* `q=0` is a refusal, and the header is the one place a client can say "not Brotli" — a proxy that mangles it, an
|
|
28
|
+
* old client that decodes it wrongly. Matching on substrings alone honoured the offer and ignored the refusal,
|
|
29
|
+
* which is the one way this can produce a body the caller cannot read.
|
|
30
|
+
*/
|
|
31
|
+
var acceptedEncodings = (acceptEncoding) => {
|
|
32
|
+
const accepted = /* @__PURE__ */ new Set();
|
|
33
|
+
for (const part of acceptEncoding.split(",")) {
|
|
34
|
+
const [token, ...params] = part.trim().split(";");
|
|
35
|
+
const quality = params.map((param) => /^\s*q=([\d.]+)\s*$/iu.exec(param)).find((match) => match !== null)?.[1];
|
|
36
|
+
if (quality === void 0 || Number(quality) > 0) accepted.add(token.trim().toLowerCase());
|
|
37
|
+
}
|
|
38
|
+
return accepted;
|
|
39
|
+
};
|
|
40
|
+
/** The first encoding this server prefers that the client actually takes. `*` counts as taking anything. */
|
|
41
|
+
var selectEncoding = (acceptEncoding, compression = DEFAULT_COMPRESSION) => {
|
|
42
|
+
if (!acceptEncoding || compression.encodings.length === 0) return "identity";
|
|
43
|
+
const accepted = acceptedEncodings(acceptEncoding);
|
|
44
|
+
return compression.encodings.find((encoding) => accepted.has(encoding) || accepted.has("*")) ?? "identity";
|
|
45
|
+
};
|
|
46
|
+
var compressBody = (body, encoding, compression = DEFAULT_COMPRESSION) => {
|
|
47
|
+
if (encoding === "identity" || body.length < compression.threshold) return body;
|
|
12
48
|
const buf = Buffer.from(body, "utf-8");
|
|
13
|
-
if (encoding === "br") return brotliCompressSync(buf, { params: { [constants.BROTLI_PARAM_QUALITY]:
|
|
14
|
-
return gzipSync(buf, { level:
|
|
49
|
+
if (encoding === "br") return brotliCompressSync(buf, { params: { [constants.BROTLI_PARAM_QUALITY]: compression.brotliQuality } });
|
|
50
|
+
return gzipSync(buf, { level: compression.gzipLevel });
|
|
15
51
|
};
|
|
16
52
|
//#endregion
|
|
17
|
-
export { compressBody, selectEncoding };
|
|
53
|
+
export { DEFAULT_COMPRESSION, compressBody, resolveCompression, selectEncoding };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { OfflineDataRaw } from '@plitzi/sdk-shared';
|
|
2
|
+
export type OfflineDataLoader = () => Promise<OfflineDataRaw | undefined>;
|
|
3
|
+
/**
|
|
4
|
+
* One read of the space per request, however many things ask for it.
|
|
5
|
+
*
|
|
6
|
+
* The page render and the RSC read both need the schema and are deliberately started in parallel, so neither can
|
|
7
|
+
* hand its result to the other. Sharing the promise is what makes that safe: whichever asks first begins the read
|
|
8
|
+
* and the other joins it. It holds the promise, not the value — there is no cache here and nothing to invalidate,
|
|
9
|
+
* because it lives exactly as long as the request that made it.
|
|
10
|
+
*/
|
|
11
|
+
export declare const createOfflineDataLoader: (read: OfflineDataLoader) => OfflineDataLoader;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/helpers/offlineDataLoader.ts
|
|
2
|
+
/**
|
|
3
|
+
* One read of the space per request, however many things ask for it.
|
|
4
|
+
*
|
|
5
|
+
* The page render and the RSC read both need the schema and are deliberately started in parallel, so neither can
|
|
6
|
+
* hand its result to the other. Sharing the promise is what makes that safe: whichever asks first begins the read
|
|
7
|
+
* and the other joins it. It holds the promise, not the value — there is no cache here and nothing to invalidate,
|
|
8
|
+
* because it lives exactly as long as the request that made it.
|
|
9
|
+
*/
|
|
10
|
+
var createOfflineDataLoader = (read) => {
|
|
11
|
+
let pending;
|
|
12
|
+
return () => pending ??= read();
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
15
|
+
export { createOfflineDataLoader };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a render may expose debugging: the panel, element ids in the markup, the store.
|
|
3
|
+
*
|
|
4
|
+
* An SSR page loads the same SDK a client-rendered one does, so it follows the same rule: the page's `debugMode`
|
|
5
|
+
* authorizes it (`devMode` when the server did not say otherwise), and the 'plitzi_debug' cookie is only the
|
|
6
|
+
* visitor's preference within that — it exists so the SSR render matches what the client hydrates with. Being
|
|
7
|
+
* client-owned, the cookie can turn debugging off, never on: otherwise any visitor of a published site could set it
|
|
8
|
+
* and get the debug render.
|
|
9
|
+
*/
|
|
10
|
+
export declare const resolveDebugMode: (authorized: boolean | undefined, debugCookie: string | undefined) => boolean;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/helpers/resolveDebugMode.ts
|
|
2
|
+
/**
|
|
3
|
+
* Whether a render may expose debugging: the panel, element ids in the markup, the store.
|
|
4
|
+
*
|
|
5
|
+
* An SSR page loads the same SDK a client-rendered one does, so it follows the same rule: the page's `debugMode`
|
|
6
|
+
* authorizes it (`devMode` when the server did not say otherwise), and the 'plitzi_debug' cookie is only the
|
|
7
|
+
* visitor's preference within that — it exists so the SSR render matches what the client hydrates with. Being
|
|
8
|
+
* client-owned, the cookie can turn debugging off, never on: otherwise any visitor of a published site could set it
|
|
9
|
+
* and get the debug render.
|
|
10
|
+
*/
|
|
11
|
+
var resolveDebugMode = (authorized, debugCookie) => Boolean(authorized) && debugCookie !== "false";
|
|
12
|
+
//#endregion
|
|
13
|
+
export { resolveDebugMode };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,16 @@
|
|
|
1
|
-
export
|
|
2
|
-
export {}
|
|
1
|
+
export { createServer, resolveServices } from './core/createServer';
|
|
2
|
+
export { registerHealthCheck, buildHealthPayload } from './core/health';
|
|
3
|
+
export { consoleLogger, renderLogEvent } from './helpers/serverLog';
|
|
4
|
+
export type { HealthCheckApp, HealthIdentity } from './core/health';
|
|
5
|
+
export { createJsonAdapters } from './adapters/jsonAdapters';
|
|
6
|
+
export { createAuthAdapters } from './adapters/authAdapters';
|
|
7
|
+
export { createMemoryDraftStore, takeDraftOverride } from './modules/ssr/preview';
|
|
8
|
+
export { PREVIEW_TOKEN_PARAM } from './core/previewToken';
|
|
9
|
+
export { resolveRscData } from './modules/rsc/resolveRscData';
|
|
10
|
+
export { fetchConnectorRecords, rebaseMedia, writeConnectorRecord, createConnectorResolver } from './modules/connectors';
|
|
11
|
+
export type { JsonAdaptersConfig } from './adapters/jsonAdapters';
|
|
12
|
+
export type { AuthAdapters, AuthAdaptersConfig } from './adapters/authAdapters';
|
|
13
|
+
export type { RscElementResolver, RscResolveContext, ResolveRscDataOptions } from './modules/rsc/resolveRscData';
|
|
14
|
+
export type { ConnectorAuth, ConnectorCredential, ConnectorEndpoints, ConnectorFilter, ConnectorLookups, ConnectorManifest, ConnectorManifestDraft, ConnectorPageInfo, ConnectorPagination, ConnectorQuery, ConnectorReadEndpoint, ConnectorRecord, ConnectorResponseMapping, ConnectorResult, ProviderPagination } from './modules/connectors';
|
|
15
|
+
export type { ResolvedServices } from './core/createServer';
|
|
16
|
+
export type { BaseContext, PipelineExtensions, SSRContext, Stage } from './core/http/types';
|
package/dist/index.js
CHANGED
|
@@ -1,23 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { apply, applyShape } from "./modules/mcp/tools/apply/index.js";
|
|
5
|
-
import { read, readShape } from "./modules/mcp/tools/read.js";
|
|
6
|
-
import { search, searchShape } from "./modules/mcp/tools/search.js";
|
|
7
|
-
import { validate, validateShape } from "./modules/mcp/tools/validate.js";
|
|
8
|
-
import { tools } from "./modules/mcp/tools/index.js";
|
|
9
|
-
import { bindTools, getAllowedModes, isCallToolResult, isToolActive, resolveToolHandler, toolResponseErr, toolResponseFromResult, toolResponseOk, zodToJsonSchema } from "./modules/ai/toolkit.js";
|
|
10
|
-
import { createMcpServer } from "./modules/mcp/server.js";
|
|
11
|
-
import { handleMcp, readMcpBody, serveMcp } from "./modules/mcp/handler.js";
|
|
12
|
-
import { createHttpPreviewClient } from "./modules/mcp/previewClient.js";
|
|
13
|
-
import { PREVIEW_TOKEN_PARAM } from "./modules/mcp/constants.js";
|
|
14
|
-
import { createHttpScreenshotClient } from "./modules/mcp/screenshotClient.js";
|
|
15
|
-
import { createMemoryDraftStore, createPreview } from "./modules/ssr/preview.js";
|
|
16
|
-
import { buildHealthPayload, registerHealthCheck } from "./core/health.js";
|
|
17
|
-
import { createMCPServer } from "./core/server/mcpServer.js";
|
|
1
|
+
import { PREVIEW_TOKEN_PARAM } from "./core/previewToken.js";
|
|
2
|
+
import { createMemoryDraftStore, takeDraftOverride } from "./modules/ssr/preview.js";
|
|
3
|
+
import { fetchConnectorRecords, rebaseMedia, writeConnectorRecord } from "./modules/connectors/engine.js";
|
|
18
4
|
import { resolveServices } from "./core/services/resolve.js";
|
|
19
|
-
import {
|
|
5
|
+
import { buildHealthPayload, registerHealthCheck } from "./core/health.js";
|
|
20
6
|
import { createServer } from "./core/createServer.js";
|
|
7
|
+
import { consoleLogger, renderLogEvent } from "./helpers/serverLog.js";
|
|
21
8
|
import { createJsonAdapters } from "./adapters/jsonAdapters.js";
|
|
22
|
-
import
|
|
23
|
-
|
|
9
|
+
import { createAuthAdapters } from "./adapters/authAdapters.js";
|
|
10
|
+
import { resolveRscData } from "./modules/rsc/resolveRscData.js";
|
|
11
|
+
import { createConnectorResolver } from "./modules/connectors/resolver.js";
|
|
12
|
+
export { PREVIEW_TOKEN_PARAM, buildHealthPayload, consoleLogger, createAuthAdapters, createConnectorResolver, createJsonAdapters, createMemoryDraftStore, createServer, fetchConnectorRecords, rebaseMedia, registerHealthCheck, renderLogEvent, resolveRscData, resolveServices, takeDraftOverride, writeConnectorRecord };
|
package/dist/kernel.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** The HTTP kernel: everything needed to stand up a Plitzi server that is NOT a page server, and nothing else.
|
|
2
|
+
*
|
|
3
|
+
* Import it as `@plitzi/sdk-server/kernel`. The package root is a barrel over the render path (SSR, RSC,
|
|
4
|
+
* plugins, React), and ESM re-exports load eagerly — so a sibling server package that pulled `createHttpServer`
|
|
5
|
+
* from there would load that whole graph. This entry's closure is the dispatcher, the transports and the base
|
|
6
|
+
* stages: no React, no template, no plugin manager.
|
|
7
|
+
*
|
|
8
|
+
* A server built on it supplies its own pipeline; `@plitzi/sdk-mcp` is the in-tree example. */
|
|
9
|
+
export { createHttpServer } from './core/server/baseServer';
|
|
10
|
+
export { makeHandler } from './core/http/dispatcher';
|
|
11
|
+
export { healthStage } from './core/http/stages/health';
|
|
12
|
+
export { configStaticStage, publicDirStage, wellKnownStage } from './core/http/stages/static';
|
|
13
|
+
export { buildHealthPayload, registerHealthCheck } from './core/health';
|
|
14
|
+
export { clientIp, parseRequest, readRawBody, requestOrigin } from './core/requestParser';
|
|
15
|
+
export { clearFlowCookie, clearSessionCookies, createSessionCookies, isLocalHost, readFlowCookie, readRefreshToken, readSessionToken, sessionCookieParams, sessionHintValue, writeFlowCookie, writeSessionCookies } from './core/auth/session';
|
|
16
|
+
export { SCOPES, authFailureMessage, createTokens, userIdOf } from './core/auth/tokens';
|
|
17
|
+
export { createCarriers, presentedOrigin } from './core/auth/credentials';
|
|
18
|
+
export { ANY_DOMAIN, corsOrigins, domainAllowed, frameAncestors, hostnameOf, normalizeDomain } from './core/auth/domains';
|
|
19
|
+
export { createIdentity } from './core/auth/identity';
|
|
20
|
+
export { checkPermission, checkSpaceAccess, createAuthorizer, requirementFor } from './core/auth/authorize';
|
|
21
|
+
export { createAuth } from './core/auth/createAuth';
|
|
22
|
+
export { createAuthApi } from './core/auth/api';
|
|
23
|
+
export { applySessionOutcome, authPolicyRules, authRoutes } from './core/auth/routes';
|
|
24
|
+
export { createSpaceTokenApi } from './core/auth/spaceTokens';
|
|
25
|
+
export { BUILT_IN_PROVIDERS, OAuthFailure, createSocialAuth, requestProfileJson } from './core/auth/oauth';
|
|
26
|
+
export { consoleLogger, renderLogEvent } from './helpers/serverLog';
|
|
27
|
+
export { PREVIEW_TOKEN_PARAM } from './core/previewToken';
|
|
28
|
+
export type { HttpServerParts } from './core/server/baseServer';
|
|
29
|
+
export type { BuildContext } from './core/http/dispatcher';
|
|
30
|
+
export type { HealthCheckApp, HealthIdentity } from './core/health';
|
|
31
|
+
export type { BaseContext, PipelineExtensions, SSRContext, Stage } from './core/http/types';
|
|
32
|
+
export type { CookieCarrier, CookieSink, SessionCookieParams, SessionCookies } from './core/auth/session';
|
|
33
|
+
export type { CredentialCarrier } from './core/auth/credentials';
|
|
34
|
+
export type { Actor, ActorResult, Grant, GrantOptions, GrantResult, Identity, IdentityAdapters, IdentityConfig, SpaceMembership, StoredSpaceToken } from './core/auth/identity';
|
|
35
|
+
export type { AuthPolicy, AuthorizeResult, Authorizer, MembershipFacts, PathMatcher, PermissionCheck, Requirement, SpaceAccessCheck } from './core/auth/authorize';
|
|
36
|
+
export type { AuthRequest, AuthRoute } from './core/auth/routes';
|
|
37
|
+
export type { Auth, AuthConfig } from './core/auth/createAuth';
|
|
38
|
+
export type { CompletedFlow, OAuthFailureReason, OAuthProfile, OAuthProvider, OAuthProviderConfig, SocialAuth, SocialAuthAdapters, SocialAuthConfig, StartedFlow } from './core/auth/oauth';
|
|
39
|
+
export type { AccountAccess, AccountAdapters, AccountRecord, AuthApi, AuthApiConfig, AuthOutcome } from './core/auth/api';
|
|
40
|
+
export type { SpaceTokenAdapters, SpaceTokenApi, SpaceTokenContext, SpaceTokenOutcome, SpaceTokenRecord, SpaceTokenSummary } from './core/auth/spaceTokens';
|
|
41
|
+
export type { AuthFailure, RefreshTokenPayload, SpaceScope, SpaceTokenOptions, SpaceTokenPayload, TokenConfig, TokenScope, Tokens, UserTokenPayload, VerifyResult, WidgetTokenPayload } from './core/auth/tokens';
|
package/dist/kernel.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { clientIp, parseRequest, readRawBody, requestOrigin } from "./core/requestParser.js";
|
|
2
|
+
import { createHttpServer } from "./core/server/baseServer.js";
|
|
3
|
+
import { PREVIEW_TOKEN_PARAM } from "./core/previewToken.js";
|
|
4
|
+
import { makeHandler } from "./core/http/dispatcher.js";
|
|
5
|
+
import { clearFlowCookie, clearSessionCookies, createSessionCookies, isLocalHost, readFlowCookie, readRefreshToken, readSessionToken, sessionCookieParams, sessionHintValue, writeFlowCookie, writeSessionCookies } from "./core/auth/session.js";
|
|
6
|
+
import { buildHealthPayload, registerHealthCheck } from "./core/health.js";
|
|
7
|
+
import { healthStage } from "./core/http/stages/health.js";
|
|
8
|
+
import { configStaticStage, publicDirStage, wellKnownStage } from "./core/http/stages/static.js";
|
|
9
|
+
import { consoleLogger, renderLogEvent } from "./helpers/serverLog.js";
|
|
10
|
+
import { SCOPES, authFailureMessage, createTokens, userIdOf } from "./core/auth/tokens.js";
|
|
11
|
+
import { createCarriers, presentedOrigin } from "./core/auth/credentials.js";
|
|
12
|
+
import { ANY_DOMAIN, corsOrigins, domainAllowed, frameAncestors, hostnameOf, normalizeDomain } from "./core/auth/domains.js";
|
|
13
|
+
import { createIdentity } from "./core/auth/identity.js";
|
|
14
|
+
import { checkPermission, checkSpaceAccess, createAuthorizer, requirementFor } from "./core/auth/authorize.js";
|
|
15
|
+
import { createAuthApi } from "./core/auth/api.js";
|
|
16
|
+
import { applySessionOutcome, authPolicyRules, authRoutes } from "./core/auth/routes.js";
|
|
17
|
+
import { createAuth } from "./core/auth/createAuth.js";
|
|
18
|
+
import { createSpaceTokenApi } from "./core/auth/spaceTokens.js";
|
|
19
|
+
import { OAuthFailure } from "./core/auth/oauth/types.js";
|
|
20
|
+
import { requestProfileJson } from "./core/auth/oauth/client.js";
|
|
21
|
+
import { BUILT_IN_PROVIDERS, createSocialAuth } from "./core/auth/oauth/index.js";
|
|
22
|
+
export { ANY_DOMAIN, BUILT_IN_PROVIDERS, OAuthFailure, PREVIEW_TOKEN_PARAM, SCOPES, applySessionOutcome, authFailureMessage, authPolicyRules, authRoutes, buildHealthPayload, checkPermission, checkSpaceAccess, clearFlowCookie, clearSessionCookies, clientIp, configStaticStage, consoleLogger, corsOrigins, createAuth, createAuthApi, createAuthorizer, createCarriers, createHttpServer, createIdentity, createSessionCookies, createSocialAuth, createSpaceTokenApi, createTokens, domainAllowed, frameAncestors, healthStage, hostnameOf, isLocalHost, makeHandler, normalizeDomain, parseRequest, presentedOrigin, publicDirStage, readFlowCookie, readRawBody, readRefreshToken, readSessionToken, registerHealthCheck, renderLogEvent, requestOrigin, requestProfileJson, requirementFor, sessionCookieParams, sessionHintValue, userIdOf, wellKnownStage, writeFlowCookie, writeSessionCookies };
|
|
@@ -3,12 +3,13 @@ var spaceDeploymentMiddleware = (adapters) => {
|
|
|
3
3
|
return async (req, res, next) => {
|
|
4
4
|
const deployment = await adapters.getSpaceDeployment(req);
|
|
5
5
|
req.ctx.spaceDeployment = deployment;
|
|
6
|
-
const { spaceId, error } = deployment;
|
|
6
|
+
const { spaceId, error, frameAncestors } = deployment;
|
|
7
7
|
if (spaceId == null || error) {
|
|
8
8
|
res.setStatus(error?.code ?? 404);
|
|
9
9
|
res.send(error?.message ?? "Space not found");
|
|
10
10
|
return;
|
|
11
11
|
}
|
|
12
|
+
if (frameAncestors && frameAncestors.length > 0) res.setHeader("Content-Security-Policy", `frame-ancestors ${frameAncestors.join(" ")}`);
|
|
12
13
|
await next();
|
|
13
14
|
};
|
|
14
15
|
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ConnectorLookups } from '../connectors/resolver';
|
|
2
|
+
import { SSRPageServerConfig, SSRRequest, SSRResponseHelpers } from '@plitzi/sdk-shared';
|
|
3
|
+
/**
|
|
4
|
+
* Handles POST /_action — the write counterpart of the RSC read endpoint.
|
|
5
|
+
*
|
|
6
|
+
* The browser names an **element**, never a connector or a URL. The element must exist in the published schema,
|
|
7
|
+
* be server-driven and declare a connector, and the connector must declare the action. That chain is what stops
|
|
8
|
+
* the endpoint from being a general-purpose proxy into the customer's backend: nothing reachable here is
|
|
9
|
+
* reachable that the page itself does not already do.
|
|
10
|
+
*/
|
|
11
|
+
export declare const handleAction: (req: SSRRequest, res: SSRResponseHelpers, config: SSRPageServerConfig, lookups: ConnectorLookups) => Promise<void>;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { writeConnectorRecord } from "../connectors/engine.js";
|
|
2
|
+
//#region src/modules/actions/handler.ts
|
|
3
|
+
var parseBody = (body) => {
|
|
4
|
+
if (!body) return;
|
|
5
|
+
try {
|
|
6
|
+
const parsed = JSON.parse(body);
|
|
7
|
+
return parsed !== null && typeof parsed === "object" ? parsed : void 0;
|
|
8
|
+
} catch {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
var fail = (res, status, error) => {
|
|
13
|
+
res.setStatus(status);
|
|
14
|
+
res.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
15
|
+
res.send(JSON.stringify({ error }));
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Handles POST /_action — the write counterpart of the RSC read endpoint.
|
|
19
|
+
*
|
|
20
|
+
* The browser names an **element**, never a connector or a URL. The element must exist in the published schema,
|
|
21
|
+
* be server-driven and declare a connector, and the connector must declare the action. That chain is what stops
|
|
22
|
+
* the endpoint from being a general-purpose proxy into the customer's backend: nothing reachable here is
|
|
23
|
+
* reachable that the page itself does not already do.
|
|
24
|
+
*/
|
|
25
|
+
var handleAction = async (req, res, config, lookups) => {
|
|
26
|
+
const { environment = "main", spaceId, revision = 0 } = req.ctx.spaceDeployment ?? {};
|
|
27
|
+
if (typeof spaceId !== "number") {
|
|
28
|
+
fail(res, 400, "Invalid space deployment");
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const body = parseBody(req.body);
|
|
32
|
+
const action = body?.action;
|
|
33
|
+
if (!body?.elementId || !action) {
|
|
34
|
+
fail(res, 400, "Expected { elementId, action, values }");
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const element = (await config.adapters.getOfflineData(spaceId, environment, revision))?.schema.flat[body.elementId];
|
|
38
|
+
if (!element || element.definition.runtime !== "server") {
|
|
39
|
+
fail(res, 404, "Unknown provider element");
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const { connector: connectorId, resource } = element.attributes;
|
|
43
|
+
if (!connectorId) {
|
|
44
|
+
fail(res, 400, "Element has no connector");
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const manifest = await lookups.getConnector(spaceId, connectorId);
|
|
48
|
+
if (!manifest) {
|
|
49
|
+
fail(res, 404, "Unknown connector");
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (!manifest.endpoints.write?.[action]) {
|
|
53
|
+
fail(res, 405, `Connector does not allow "${action}"`);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const credential = manifest.credential && lookups.getCredential ? await lookups.getCredential(spaceId, manifest.credential) : void 0;
|
|
57
|
+
try {
|
|
58
|
+
const record = await writeConnectorRecord({
|
|
59
|
+
manifest,
|
|
60
|
+
credential,
|
|
61
|
+
action,
|
|
62
|
+
resource,
|
|
63
|
+
recordId: body.recordId,
|
|
64
|
+
values: body.values,
|
|
65
|
+
fetchImpl: lookups.fetchImpl
|
|
66
|
+
});
|
|
67
|
+
res.setStatus(200);
|
|
68
|
+
res.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
69
|
+
res.setHeader("Cache-Control", "no-store");
|
|
70
|
+
res.send(JSON.stringify({ record: record ?? null }));
|
|
71
|
+
} catch (err) {
|
|
72
|
+
console.error("[Action] connector write failed:", err);
|
|
73
|
+
fail(res, 502, "Connector write failed");
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
//#endregion
|
|
77
|
+
export { handleAction };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ConnectorCredential, ConnectorManifest, ConnectorQuery, ConnectorRecord, ConnectorResult } from './types';
|
|
2
|
+
export type FetchConnectorOptions = {
|
|
3
|
+
manifest: ConnectorManifest;
|
|
4
|
+
/** Which read endpoint to execute. Defaults to `list`, the one an element addresses when it names none. */
|
|
5
|
+
endpoint?: string;
|
|
6
|
+
credential?: ConnectorCredential;
|
|
7
|
+
query?: ConnectorQuery;
|
|
8
|
+
/** Injected so tests — and a future edge runtime — can supply their own transport. */
|
|
9
|
+
fetchImpl?: typeof fetch;
|
|
10
|
+
};
|
|
11
|
+
export type WriteConnectorOptions = {
|
|
12
|
+
manifest: ConnectorManifest;
|
|
13
|
+
credential?: ConnectorCredential;
|
|
14
|
+
/** Name of the write endpoint to execute, as declared in the manifest. */
|
|
15
|
+
action: string;
|
|
16
|
+
resource?: string;
|
|
17
|
+
recordId?: string;
|
|
18
|
+
values?: Record<string, unknown>;
|
|
19
|
+
fetchImpl?: typeof fetch;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Rebases the relative media paths a CMS returns (`/uploads/cover.jpg`) onto the manifest's media host.
|
|
23
|
+
*
|
|
24
|
+
* The rule is keyed on the property name, not on the value: a body field whose text happens to start with a slash
|
|
25
|
+
* must never be rewritten, and only a name ending in `url`, `src` or `href` claims to hold a location. Protocol
|
|
26
|
+
* relative values are already absolute enough and are left alone.
|
|
27
|
+
*/
|
|
28
|
+
export declare const rebaseMedia: (value: unknown, baseUrl: string) => unknown;
|
|
29
|
+
/**
|
|
30
|
+
* Executes one connector read and normalizes the response into records + page info.
|
|
31
|
+
*
|
|
32
|
+
* Everything provider-specific — the endpoint, the auth header, where the array lives, how paging is expressed —
|
|
33
|
+
* comes from the manifest, so a new CMS is configuration rather than code.
|
|
34
|
+
*/
|
|
35
|
+
export declare const fetchConnectorRecords: ({ manifest, endpoint, credential, query, fetchImpl }: FetchConnectorOptions) => Promise<ConnectorResult>;
|
|
36
|
+
/**
|
|
37
|
+
* Executes one connector write.
|
|
38
|
+
*
|
|
39
|
+
* An action the manifest does not declare is refused rather than inferred: a connector is read-only until its
|
|
40
|
+
* owner says otherwise, so a form can never reach a provider that was never meant to be written to.
|
|
41
|
+
*/
|
|
42
|
+
export declare const writeConnectorRecord: ({ manifest, credential, action, resource, recordId, values, fetchImpl }: WriteConnectorOptions) => Promise<ConnectorRecord | undefined>;
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { getByPath } from "./getByPath.js";
|
|
2
|
+
import { BODYLESS_METHODS, DEFAULT_READ_ENDPOINT, EMPTY_RESPONSE_METHODS } from "@plitzi/sdk-shared/connectors";
|
|
3
|
+
import { processTwig } from "@plitzi/sdk-shared/helpers/twigWrapper";
|
|
4
|
+
//#region src/modules/connectors/engine.ts
|
|
5
|
+
var DEFAULT_LIMIT = 10;
|
|
6
|
+
/** Only scalars can become a URL fragment, a header or a record key. Anything else is treated as absent. */
|
|
7
|
+
var toScalar = (value) => {
|
|
8
|
+
if (typeof value === "string") return value;
|
|
9
|
+
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
10
|
+
};
|
|
11
|
+
var render = (template, variables) => toScalar(processTwig(template, variables)) ?? "";
|
|
12
|
+
var renderEntries = (entries, variables) => Object.entries(entries).reduce((acum, [key, template]) => {
|
|
13
|
+
const value = render(template, variables);
|
|
14
|
+
if (value !== "" && !value.includes("{{")) acum[key] = value;
|
|
15
|
+
return acum;
|
|
16
|
+
}, {});
|
|
17
|
+
var isTemplate = (value) => typeof value === "string" && value.includes("{{");
|
|
18
|
+
/**
|
|
19
|
+
* Resolves a filter's own field and value before the operator template ever sees them.
|
|
20
|
+
*
|
|
21
|
+
* A detail page filters on `{{routeParams.slug}}`; without this pass that token reaches the CMS verbatim and the
|
|
22
|
+
* page matches nothing — or worse, the token is dropped and the query returns the whole collection, so an
|
|
23
|
+
* arbitrary record renders at a URL that addressed a specific one.
|
|
24
|
+
*
|
|
25
|
+
* `unresolved` reports a template that produced nothing. The caller answers with an empty result rather than a
|
|
26
|
+
* broader query: a page that cannot identify its record has no record, and that is a 404, not a different post.
|
|
27
|
+
*/
|
|
28
|
+
var resolveFilters = (filters, variables) => filters.reduce((acum, filter) => {
|
|
29
|
+
const field = isTemplate(filter.field) ? render(filter.field, variables) : filter.field;
|
|
30
|
+
const value = isTemplate(filter.value) ? render(filter.value, variables) : filter.value;
|
|
31
|
+
if (!field || field.includes("{{") || value === "" || typeof value === "string" && value.includes("{{")) {
|
|
32
|
+
acum.unresolved = true;
|
|
33
|
+
return acum;
|
|
34
|
+
}
|
|
35
|
+
acum.resolved.push({
|
|
36
|
+
...filter,
|
|
37
|
+
field,
|
|
38
|
+
value
|
|
39
|
+
});
|
|
40
|
+
return acum;
|
|
41
|
+
}, {
|
|
42
|
+
resolved: [],
|
|
43
|
+
unresolved: false
|
|
44
|
+
});
|
|
45
|
+
/** Turns a filter into `key=value` query entries through the manifest's operator templates. */
|
|
46
|
+
var renderFilters = (filters, operators, variables) => filters.reduce((acum, filter) => {
|
|
47
|
+
const template = operators?.[filter.operator];
|
|
48
|
+
if (!template) return acum;
|
|
49
|
+
const rendered = render(template, {
|
|
50
|
+
...variables,
|
|
51
|
+
field: filter.field,
|
|
52
|
+
value: filter.value
|
|
53
|
+
});
|
|
54
|
+
const separator = rendered.indexOf("=");
|
|
55
|
+
if (separator === -1) return acum;
|
|
56
|
+
acum[rendered.slice(0, separator)] = rendered.slice(separator + 1);
|
|
57
|
+
return acum;
|
|
58
|
+
}, {});
|
|
59
|
+
/** A relative media path is only ever carried by a key that names a location. */
|
|
60
|
+
var MEDIA_KEY = /(url|src|href)$/i;
|
|
61
|
+
/**
|
|
62
|
+
* Rebases the relative media paths a CMS returns (`/uploads/cover.jpg`) onto the manifest's media host.
|
|
63
|
+
*
|
|
64
|
+
* The rule is keyed on the property name, not on the value: a body field whose text happens to start with a slash
|
|
65
|
+
* must never be rewritten, and only a name ending in `url`, `src` or `href` claims to hold a location. Protocol
|
|
66
|
+
* relative values are already absolute enough and are left alone.
|
|
67
|
+
*/
|
|
68
|
+
var rebaseMedia = (value, baseUrl) => {
|
|
69
|
+
if (Array.isArray(value)) return value.map((item) => rebaseMedia(item, baseUrl));
|
|
70
|
+
if (value === null || typeof value !== "object") return value;
|
|
71
|
+
return Object.entries(value).reduce((acum, [key, item]) => {
|
|
72
|
+
if (typeof item === "string" && MEDIA_KEY.test(key) && item.startsWith("/") && !item.startsWith("//")) {
|
|
73
|
+
acum[key] = `${baseUrl.replace(/\/+$/, "")}${item}`;
|
|
74
|
+
return acum;
|
|
75
|
+
}
|
|
76
|
+
acum[key] = rebaseMedia(item, baseUrl);
|
|
77
|
+
return acum;
|
|
78
|
+
}, {});
|
|
79
|
+
};
|
|
80
|
+
/** Builds the outbound headers and, for query-carried schemes, mutates `url` with the auth parameter. */
|
|
81
|
+
var applyAuth = (connection, variables, url) => {
|
|
82
|
+
const headers = renderEntries(connection.headers ?? {}, variables);
|
|
83
|
+
if (!connection.auth) return headers;
|
|
84
|
+
const value = render(connection.auth.value, variables);
|
|
85
|
+
if (connection.auth.in === "header") headers[connection.auth.name] = value;
|
|
86
|
+
else url.searchParams.set(connection.auth.name, value);
|
|
87
|
+
return headers;
|
|
88
|
+
};
|
|
89
|
+
var buildPageInfo = (records, total, offset, limit, nextCursor) => {
|
|
90
|
+
const to = offset + records.length;
|
|
91
|
+
const hasNextPage = total === void 0 ? records.length === limit : to < total;
|
|
92
|
+
return {
|
|
93
|
+
hasPrevPage: offset > 0,
|
|
94
|
+
hasNextPage,
|
|
95
|
+
prevCursor: "",
|
|
96
|
+
nextCursor: hasNextPage ? nextCursor : "",
|
|
97
|
+
from: offset,
|
|
98
|
+
to,
|
|
99
|
+
total: total ?? to,
|
|
100
|
+
page: Math.floor(offset / Math.max(limit, 1)) + 1,
|
|
101
|
+
pageCount: total === void 0 ? 0 : Math.ceil(total / Math.max(limit, 1))
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
/** The window a query addressed, when it is known before the provider is called (or instead of calling it). */
|
|
105
|
+
var emptyResult = (offset, limit) => ({
|
|
106
|
+
records: [],
|
|
107
|
+
pageInfo: buildPageInfo([], 0, offset, limit, "")
|
|
108
|
+
});
|
|
109
|
+
var toRecords = (items, mapping) => items.reduce((acum, item, index) => {
|
|
110
|
+
if (item === null || typeof item !== "object") return acum;
|
|
111
|
+
const id = toScalar(getByPath(item, mapping.idPath ?? "id"));
|
|
112
|
+
const values = getByPath(item, mapping.valuesPath ?? ".");
|
|
113
|
+
acum.push({
|
|
114
|
+
id: id ?? String(index),
|
|
115
|
+
values: values !== null && typeof values === "object" ? values : {}
|
|
116
|
+
});
|
|
117
|
+
return acum;
|
|
118
|
+
}, []);
|
|
119
|
+
/**
|
|
120
|
+
* Executes one connector read and normalizes the response into records + page info.
|
|
121
|
+
*
|
|
122
|
+
* Everything provider-specific — the endpoint, the auth header, where the array lives, how paging is expressed —
|
|
123
|
+
* comes from the manifest, so a new CMS is configuration rather than code.
|
|
124
|
+
*/
|
|
125
|
+
var fetchConnectorRecords = async ({ manifest, endpoint = DEFAULT_READ_ENDPOINT, credential = {}, query = {}, fetchImpl = fetch }) => {
|
|
126
|
+
const { endpoints, ...connection } = manifest;
|
|
127
|
+
const read = Object.hasOwn(endpoints.read, endpoint) ? endpoints.read[endpoint] : void 0;
|
|
128
|
+
if (!read) throw new Error(`Connector ${connection.id} has no read endpoint named "${endpoint}"`);
|
|
129
|
+
const limit = query.limit ?? DEFAULT_LIMIT;
|
|
130
|
+
const offset = query.offset ?? 0;
|
|
131
|
+
const variables = {
|
|
132
|
+
credential,
|
|
133
|
+
resource: query.resource ?? "",
|
|
134
|
+
limit,
|
|
135
|
+
offset,
|
|
136
|
+
page: query.page ?? Math.floor(offset / limit) + 1,
|
|
137
|
+
cursor: query.cursor ?? "",
|
|
138
|
+
routeParams: query.routeParams ?? {},
|
|
139
|
+
queryParams: query.queryParams ?? {},
|
|
140
|
+
params: {
|
|
141
|
+
...query.queryParams,
|
|
142
|
+
...query.routeParams
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
const { resolved, unresolved } = resolveFilters(query.filters ?? [], variables);
|
|
146
|
+
if (unresolved) return emptyResult(offset, limit);
|
|
147
|
+
const url = new URL(render(read.path, variables), connection.baseUrl);
|
|
148
|
+
Object.entries({
|
|
149
|
+
...renderEntries(read.query ?? {}, variables),
|
|
150
|
+
...renderFilters(resolved, connection.operators, variables)
|
|
151
|
+
}).forEach(([key, value]) => url.searchParams.set(key, value));
|
|
152
|
+
const method = read.method ?? "GET";
|
|
153
|
+
const headers = {
|
|
154
|
+
...applyAuth(connection, variables, url),
|
|
155
|
+
...renderEntries(read.headers ?? {}, variables)
|
|
156
|
+
};
|
|
157
|
+
const sendsBody = !BODYLESS_METHODS.includes(method);
|
|
158
|
+
if (sendsBody) headers["Content-Type"] = "application/json";
|
|
159
|
+
const response = await fetchImpl(url.toString(), {
|
|
160
|
+
method,
|
|
161
|
+
headers,
|
|
162
|
+
body: sendsBody ? JSON.stringify(renderEntries(read.body ?? {}, variables)) : void 0
|
|
163
|
+
});
|
|
164
|
+
if (!response.ok) throw new Error(`Connector ${connection.id} responded ${response.status} for ${url.pathname}`);
|
|
165
|
+
const payload = await response.json();
|
|
166
|
+
const rawItems = getByPath(payload, read.itemsPath);
|
|
167
|
+
const items = Array.isArray(rawItems) ? rawItems : [];
|
|
168
|
+
const rawTotal = read.totalPath ? getByPath(payload, read.totalPath) : void 0;
|
|
169
|
+
const total = typeof rawTotal === "number" ? rawTotal : void 0;
|
|
170
|
+
const mediaBaseUrl = connection.media?.baseUrl;
|
|
171
|
+
const records = toRecords(items, read).map((record) => mediaBaseUrl ? {
|
|
172
|
+
...record,
|
|
173
|
+
values: rebaseMedia(record.values, mediaBaseUrl)
|
|
174
|
+
} : record);
|
|
175
|
+
return {
|
|
176
|
+
records,
|
|
177
|
+
pageInfo: buildPageInfo(records, total, offset, limit, String(offset + records.length))
|
|
178
|
+
};
|
|
179
|
+
};
|
|
180
|
+
/** Nests the payload the way the provider expects it: `data` produces `{ data: values }`. */
|
|
181
|
+
var wrapBody = (values, bodyPath) => {
|
|
182
|
+
if (!bodyPath || bodyPath === ".") return values;
|
|
183
|
+
return bodyPath.split(".").reduceRight((acum, key) => ({ [key]: acum }), values);
|
|
184
|
+
};
|
|
185
|
+
/**
|
|
186
|
+
* Executes one connector write.
|
|
187
|
+
*
|
|
188
|
+
* An action the manifest does not declare is refused rather than inferred: a connector is read-only until its
|
|
189
|
+
* owner says otherwise, so a form can never reach a provider that was never meant to be written to.
|
|
190
|
+
*/
|
|
191
|
+
var writeConnectorRecord = async ({ manifest, credential = {}, action, resource, recordId, values = {}, fetchImpl = fetch }) => {
|
|
192
|
+
const { endpoints, ...connection } = manifest;
|
|
193
|
+
const operation = endpoints.write?.[action];
|
|
194
|
+
if (!operation) throw new Error(`Connector ${connection.id} does not allow "${action}"`);
|
|
195
|
+
const variables = {
|
|
196
|
+
credential,
|
|
197
|
+
resource: resource ?? "",
|
|
198
|
+
id: recordId ?? "",
|
|
199
|
+
values
|
|
200
|
+
};
|
|
201
|
+
const url = new URL(render(operation.path, variables), connection.baseUrl);
|
|
202
|
+
Object.entries(renderEntries(operation.query ?? {}, variables)).forEach(([key, value]) => url.searchParams.set(key, value));
|
|
203
|
+
const headers = {
|
|
204
|
+
...applyAuth(connection, variables, url),
|
|
205
|
+
...renderEntries(operation.headers ?? {}, variables)
|
|
206
|
+
};
|
|
207
|
+
headers["Content-Type"] = "application/json";
|
|
208
|
+
const response = await fetchImpl(url.toString(), {
|
|
209
|
+
method: operation.method,
|
|
210
|
+
headers,
|
|
211
|
+
body: BODYLESS_METHODS.includes(operation.method) ? void 0 : JSON.stringify(wrapBody(values, operation.bodyPath))
|
|
212
|
+
});
|
|
213
|
+
if (!response.ok) throw new Error(`Connector ${connection.id} responded ${response.status} for ${action} on ${url.pathname}`);
|
|
214
|
+
if (EMPTY_RESPONSE_METHODS.includes(operation.method) || response.status === 204) return;
|
|
215
|
+
const mapping = operation.response ?? {};
|
|
216
|
+
const payload = await response.json();
|
|
217
|
+
const item = getByPath(payload, mapping.itemsPath === void 0 ? "." : mapping.itemsPath);
|
|
218
|
+
return toRecords(Array.isArray(item) ? item : [item], mapping)[0];
|
|
219
|
+
};
|
|
220
|
+
//#endregion
|
|
221
|
+
export { fetchConnectorRecords, rebaseMedia, writeConnectorRecord };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads a dot path out of an arbitrary JSON response (`data.items`, `meta.pagination.total`). Kept local and
|
|
3
|
+
* dependency-free on purpose: the equivalent helper in plitzi-ui would drag the UI bundle into the request path.
|
|
4
|
+
*
|
|
5
|
+
* A path of `.` or an empty path returns the value itself, which is how a manifest says "the response *is* the
|
|
6
|
+
* array" or "the record *is* its own values".
|
|
7
|
+
*/
|
|
8
|
+
export declare const getByPath: (source: unknown, path?: string) => unknown;
|