@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,164 @@
|
|
|
1
|
+
import { domainAllowed } from "./domains.js";
|
|
2
|
+
//#region src/core/auth/identity.ts
|
|
3
|
+
var createIdentity = ({ tokens, carriers, adapters, config = {}, presentedOrigin }) => {
|
|
4
|
+
const { platformHosts = [], platformOrigins = [], allowWithoutOrigin = false, log } = config;
|
|
5
|
+
/**
|
|
6
|
+
* The single user-token validator. Every transport goes through it, so there is one expiry rule and one status
|
|
7
|
+
* rule — the alternative, which this replaced, was a variant per role where only one of them checked `status`.
|
|
8
|
+
*/
|
|
9
|
+
const resolveActorFromToken = async (token) => {
|
|
10
|
+
const verified = tokens.verifyUserToken(token);
|
|
11
|
+
if (!verified.ok) return verified;
|
|
12
|
+
const actor = await adapters.findAccountByToken(token);
|
|
13
|
+
if (!actor || String(actor.id) !== verified.payload.sub) return {
|
|
14
|
+
ok: false,
|
|
15
|
+
reason: "revoked"
|
|
16
|
+
};
|
|
17
|
+
if (!actor.expiresAt || actor.expiresAt < Math.round(Date.now() / 1e3)) return {
|
|
18
|
+
ok: false,
|
|
19
|
+
reason: "expired"
|
|
20
|
+
};
|
|
21
|
+
return {
|
|
22
|
+
ok: true,
|
|
23
|
+
actor
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
const resolveActor = async (carrier) => {
|
|
27
|
+
const candidates = carriers.userTokenCandidates(carrier);
|
|
28
|
+
if (candidates.length === 0) return {
|
|
29
|
+
ok: false,
|
|
30
|
+
reason: "missing"
|
|
31
|
+
};
|
|
32
|
+
let lastFailure = "missing";
|
|
33
|
+
for (const candidate of candidates) {
|
|
34
|
+
const result = await resolveActorFromToken(candidate);
|
|
35
|
+
if (result.ok) return result;
|
|
36
|
+
if (result.reason !== "wrong-type") lastFailure = result.reason;
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
ok: false,
|
|
40
|
+
reason: lastFailure
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
const originAllowed = (origin, origins) => origins.includes("*") || [...platformOrigins, ...origins].includes(origin);
|
|
44
|
+
const resolveGrantFromToken = async (token, origin, { skipOrigin = false, host } = {}) => {
|
|
45
|
+
const verified = tokens.verifySpaceToken(token);
|
|
46
|
+
if (!verified.ok) return verified;
|
|
47
|
+
const { spaceId, spaceScope: scope, origins } = verified.payload;
|
|
48
|
+
const stored = await adapters.findSpaceToken?.(token);
|
|
49
|
+
if (!stored || stored.spaceId !== spaceId) return {
|
|
50
|
+
ok: false,
|
|
51
|
+
reason: "revoked"
|
|
52
|
+
};
|
|
53
|
+
if (stored.scope !== scope) return {
|
|
54
|
+
ok: false,
|
|
55
|
+
reason: "scope-mismatch"
|
|
56
|
+
};
|
|
57
|
+
const grant = {
|
|
58
|
+
spaceId,
|
|
59
|
+
scope,
|
|
60
|
+
userId: stored.userId,
|
|
61
|
+
origins
|
|
62
|
+
};
|
|
63
|
+
if (scope === "render" && host !== void 0 && !domainAllowed(host, origins, platformHosts)) {
|
|
64
|
+
log?.("Access Not Authorized - Domain", {
|
|
65
|
+
spaceId,
|
|
66
|
+
host,
|
|
67
|
+
origins
|
|
68
|
+
});
|
|
69
|
+
return {
|
|
70
|
+
ok: false,
|
|
71
|
+
reason: "domain-not-allowed"
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
if (skipOrigin) return {
|
|
75
|
+
ok: true,
|
|
76
|
+
grant
|
|
77
|
+
};
|
|
78
|
+
if (origins.length === 0 && !allowWithoutOrigin) {
|
|
79
|
+
log?.("Access Not Authorized - Origin", {
|
|
80
|
+
spaceId,
|
|
81
|
+
allowWithoutOrigin: false
|
|
82
|
+
});
|
|
83
|
+
return {
|
|
84
|
+
ok: false,
|
|
85
|
+
reason: "origin-not-allowed"
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
if (!origin) return allowWithoutOrigin ? {
|
|
89
|
+
ok: true,
|
|
90
|
+
grant
|
|
91
|
+
} : {
|
|
92
|
+
ok: false,
|
|
93
|
+
reason: "origin-not-allowed"
|
|
94
|
+
};
|
|
95
|
+
if (!originAllowed(origin, origins)) {
|
|
96
|
+
log?.("Access Not Authorized - Origin", {
|
|
97
|
+
spaceId,
|
|
98
|
+
origin,
|
|
99
|
+
origins
|
|
100
|
+
});
|
|
101
|
+
return {
|
|
102
|
+
ok: false,
|
|
103
|
+
reason: "origin-not-allowed"
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
ok: true,
|
|
108
|
+
grant
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
const resolveGrant = async (carrier, options = {}) => {
|
|
112
|
+
const candidates = carriers.spaceTokenCandidates(carrier);
|
|
113
|
+
if (candidates.length === 0) return {
|
|
114
|
+
ok: false,
|
|
115
|
+
reason: "missing"
|
|
116
|
+
};
|
|
117
|
+
const origin = presentedOrigin(carrier);
|
|
118
|
+
const host = options.host ?? carrier.hostname;
|
|
119
|
+
let lastFailure = "missing";
|
|
120
|
+
for (const candidate of candidates) {
|
|
121
|
+
const result = await resolveGrantFromToken(candidate, origin, {
|
|
122
|
+
...options,
|
|
123
|
+
host
|
|
124
|
+
});
|
|
125
|
+
if (result.ok) return result;
|
|
126
|
+
if (result.reason !== "wrong-type") lastFailure = result.reason;
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
ok: false,
|
|
130
|
+
reason: lastFailure
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* May this actor do this, here?
|
|
135
|
+
*
|
|
136
|
+
* Both halves are required. The global capability says the account is allowed to do this kind of thing at all;
|
|
137
|
+
* the space role says it may do it *in this space*. A global permission is a property of the account and never an
|
|
138
|
+
* assertion about a particular space, which is why neither half alone is an answer.
|
|
139
|
+
*/
|
|
140
|
+
const can = async (actor, spaceId, permission) => {
|
|
141
|
+
if (!actor.verified || !actor.permissions.includes(permission)) return false;
|
|
142
|
+
const membership = await adapters.findMembership?.(actor.id, spaceId);
|
|
143
|
+
return membership !== void 0 && membership.permissions.includes(permission);
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* An `agent` grant carries no session — its authority is the member who consented, resolved live, so that losing
|
|
147
|
+
* access to the space revokes every agent token that member authorised.
|
|
148
|
+
*/
|
|
149
|
+
const grantCan = async (grant, permission) => {
|
|
150
|
+
if (grant.scope !== "agent" || !grant.userId) return false;
|
|
151
|
+
const membership = await adapters.findMembership?.(grant.userId, grant.spaceId);
|
|
152
|
+
return membership !== void 0 && membership.permissions.includes(permission);
|
|
153
|
+
};
|
|
154
|
+
return {
|
|
155
|
+
resolveActor,
|
|
156
|
+
resolveActorFromToken,
|
|
157
|
+
resolveGrant,
|
|
158
|
+
resolveGrantFromToken,
|
|
159
|
+
can,
|
|
160
|
+
grantCan
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
//#endregion
|
|
164
|
+
export { createIdentity };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { OAuthFlowState } from './state';
|
|
2
|
+
import { OAuthProvider } from './types';
|
|
3
|
+
export declare function buildAuthorizationUrl(provider: OAuthProvider, state: OAuthFlowState, challenge?: string): string;
|
|
4
|
+
export declare function exchangeCodeForToken(provider: OAuthProvider, code: string, state: OAuthFlowState): Promise<string>;
|
|
5
|
+
export declare function requestProfileJson<T>(url: string, headers: Record<string, string>): Promise<T>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { OAuthFailure } from "./types.js";
|
|
2
|
+
//#region src/core/auth/oauth/client.ts
|
|
3
|
+
function buildAuthorizationUrl(provider, state, challenge) {
|
|
4
|
+
const params = new URLSearchParams({
|
|
5
|
+
client_id: provider.config.clientId,
|
|
6
|
+
redirect_uri: provider.config.redirectUri,
|
|
7
|
+
response_type: "code",
|
|
8
|
+
scope: provider.scope,
|
|
9
|
+
state: state.nonce,
|
|
10
|
+
...provider.authorizationParams
|
|
11
|
+
});
|
|
12
|
+
if (provider.usePkce && challenge) {
|
|
13
|
+
params.set("code_challenge", challenge);
|
|
14
|
+
params.set("code_challenge_method", "S256");
|
|
15
|
+
}
|
|
16
|
+
return `${provider.authorizationUrl}?${params.toString()}`;
|
|
17
|
+
}
|
|
18
|
+
async function exchangeCodeForToken(provider, code, state) {
|
|
19
|
+
const body = new URLSearchParams({
|
|
20
|
+
code,
|
|
21
|
+
client_id: provider.config.clientId,
|
|
22
|
+
client_secret: provider.config.clientSecret,
|
|
23
|
+
redirect_uri: provider.config.redirectUri,
|
|
24
|
+
grant_type: "authorization_code"
|
|
25
|
+
});
|
|
26
|
+
if (provider.usePkce) body.set("code_verifier", state.verifier);
|
|
27
|
+
const response = await fetch(provider.tokenUrl, {
|
|
28
|
+
method: "POST",
|
|
29
|
+
headers: {
|
|
30
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
31
|
+
Accept: "application/json",
|
|
32
|
+
...provider.tokenHeaders
|
|
33
|
+
},
|
|
34
|
+
body
|
|
35
|
+
});
|
|
36
|
+
if (!response.ok) throw new OAuthFailure("exchange_failed", `${provider.id} rejected the authorization code (${response.status})`);
|
|
37
|
+
const payload = await response.json();
|
|
38
|
+
if (!payload.access_token) throw new OAuthFailure("exchange_failed", `${provider.id} returned no access token (${payload.error ?? "unknown"})`);
|
|
39
|
+
return payload.access_token;
|
|
40
|
+
}
|
|
41
|
+
async function requestProfileJson(url, headers) {
|
|
42
|
+
const response = await fetch(url, { headers });
|
|
43
|
+
if (!response.ok) throw new OAuthFailure("profile_failed", `Failed to read the profile from ${url} (${response.status})`);
|
|
44
|
+
return await response.json();
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
export { buildAuthorizationUrl, exchangeCodeForToken, requestProfileJson };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { OAuthFailureReason, OAuthProfile, OAuthProvider, OAuthProviderConfig } from './types';
|
|
2
|
+
import { AccountRecord } from '../api';
|
|
3
|
+
export { OAuthFailure } from './types';
|
|
4
|
+
export { requestProfileJson } from './client';
|
|
5
|
+
export type { OAuthFailureReason, OAuthProfile, OAuthProvider, OAuthProviderConfig } from './types';
|
|
6
|
+
export type OAuthProviderFactory = (config: OAuthProviderConfig) => OAuthProvider;
|
|
7
|
+
/** The adapters shipped with the server. A deployment adds its credentials and gets the provider; nothing else. */
|
|
8
|
+
export declare const BUILT_IN_PROVIDERS: Partial<Record<string, OAuthProviderFactory>>;
|
|
9
|
+
export interface SocialAuthConfig {
|
|
10
|
+
/** Signs the flow state the browser carries between the two legs. */
|
|
11
|
+
secret: string;
|
|
12
|
+
/** How long a started flow stays valid. Defaults to ten minutes — long enough to sign in, short enough to matter. */
|
|
13
|
+
stateTtl?: number;
|
|
14
|
+
/** Where the browser lands when the caller asked for nowhere in particular. */
|
|
15
|
+
defaultRedirect: string;
|
|
16
|
+
/** Extra origins a caller may name as its landing page. The default target's origin is always allowed. */
|
|
17
|
+
allowedRedirects?: string[];
|
|
18
|
+
/** `<base>/auth/<id>/callback` unless a provider's own config names one. */
|
|
19
|
+
callbackBaseUrl?: string;
|
|
20
|
+
loginBaseUrl?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface SocialAuthAdapters {
|
|
23
|
+
/**
|
|
24
|
+
* Turn a provider profile into an account here, linking or creating as the deployment sees fit. Throwing an
|
|
25
|
+
* {@link OAuthFailure} reports the reason to the browser; anything else is a server error.
|
|
26
|
+
*/
|
|
27
|
+
linkAccount: (provider: string, profile: OAuthProfile) => Promise<AccountRecord>;
|
|
28
|
+
}
|
|
29
|
+
export type StartedFlow = {
|
|
30
|
+
redirectTo: string;
|
|
31
|
+
stateCookie: string;
|
|
32
|
+
ttl: number;
|
|
33
|
+
};
|
|
34
|
+
export type CompletedFlow = {
|
|
35
|
+
ok: true;
|
|
36
|
+
redirectTo: string;
|
|
37
|
+
account: AccountRecord;
|
|
38
|
+
} | {
|
|
39
|
+
ok: false;
|
|
40
|
+
redirectTo?: string;
|
|
41
|
+
error: string;
|
|
42
|
+
reason: OAuthFailureReason;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Social sign-in, as two functions and a list.
|
|
46
|
+
*
|
|
47
|
+
* The authorization-code grant is the same everywhere and none of it is anyone's product: the CSRF nonce, PKCE, the
|
|
48
|
+
* vetted redirect, the token exchange, reading the profile. What differs per deployment is which providers it has
|
|
49
|
+
* credentials for and what it does with the person who comes back — so those are the adapters, and everything else
|
|
50
|
+
* is here, once.
|
|
51
|
+
*
|
|
52
|
+
* Neither function touches a response: `start` hands back where to send the browser and the state to store, and
|
|
53
|
+
* `complete` hands back where to send it next and who came back. The binding mints the session and writes cookies.
|
|
54
|
+
*/
|
|
55
|
+
export declare const createSocialAuth: ({ config, adapters, providers: configured, customProviders }: {
|
|
56
|
+
config: SocialAuthConfig;
|
|
57
|
+
adapters: SocialAuthAdapters;
|
|
58
|
+
/** Credentials per provider id. One with no client id or secret is simply not registered. */
|
|
59
|
+
providers: Record<string, Partial<OAuthProviderConfig> | undefined>;
|
|
60
|
+
/** Adapters for providers the server does not ship, merged over the built-in ones and selected the same way. */
|
|
61
|
+
customProviders?: Partial<Record<string, OAuthProviderFactory>>;
|
|
62
|
+
}) => {
|
|
63
|
+
/** Registered providers, so a front-end renders exactly the buttons that will work. */
|
|
64
|
+
list: () => {
|
|
65
|
+
id: string;
|
|
66
|
+
label: string;
|
|
67
|
+
url: string;
|
|
68
|
+
}[];
|
|
69
|
+
get: (id: string) => OAuthProvider | undefined;
|
|
70
|
+
start: (providerId: string, redirect: unknown) => StartedFlow | undefined;
|
|
71
|
+
complete: (providerId: string, params: {
|
|
72
|
+
code?: string;
|
|
73
|
+
state?: string;
|
|
74
|
+
error?: string;
|
|
75
|
+
stateCookie?: string;
|
|
76
|
+
}) => Promise<CompletedFlow>;
|
|
77
|
+
};
|
|
78
|
+
export type SocialAuth = ReturnType<typeof createSocialAuth>;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { OAuthFailure } from "./types.js";
|
|
2
|
+
import { buildAuthorizationUrl, exchangeCodeForToken, requestProfileJson } from "./client.js";
|
|
3
|
+
import { createGitHubProvider } from "./providers/github.js";
|
|
4
|
+
import { createGoogleProvider } from "./providers/google.js";
|
|
5
|
+
import { codeChallenge, consumeFlow, startFlow } from "./state.js";
|
|
6
|
+
//#region src/core/auth/oauth/index.ts
|
|
7
|
+
/** The adapters shipped with the server. A deployment adds its credentials and gets the provider; nothing else. */
|
|
8
|
+
var BUILT_IN_PROVIDERS = {
|
|
9
|
+
google: createGoogleProvider,
|
|
10
|
+
github: createGitHubProvider
|
|
11
|
+
};
|
|
12
|
+
var originOf = (value) => {
|
|
13
|
+
try {
|
|
14
|
+
return new URL(value).origin;
|
|
15
|
+
} catch {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Social sign-in, as two functions and a list.
|
|
21
|
+
*
|
|
22
|
+
* The authorization-code grant is the same everywhere and none of it is anyone's product: the CSRF nonce, PKCE, the
|
|
23
|
+
* vetted redirect, the token exchange, reading the profile. What differs per deployment is which providers it has
|
|
24
|
+
* credentials for and what it does with the person who comes back — so those are the adapters, and everything else
|
|
25
|
+
* is here, once.
|
|
26
|
+
*
|
|
27
|
+
* Neither function touches a response: `start` hands back where to send the browser and the state to store, and
|
|
28
|
+
* `complete` hands back where to send it next and who came back. The binding mints the session and writes cookies.
|
|
29
|
+
*/
|
|
30
|
+
var createSocialAuth = ({ config, adapters, providers: configured, customProviders = {} }) => {
|
|
31
|
+
const stateTtl = config.stateTtl ?? 600;
|
|
32
|
+
const registry = /* @__PURE__ */ new Map();
|
|
33
|
+
for (const [id, credentials] of Object.entries(configured)) {
|
|
34
|
+
const factory = customProviders[id] ?? BUILT_IN_PROVIDERS[id];
|
|
35
|
+
if (!factory || !credentials?.clientId || !credentials.clientSecret) continue;
|
|
36
|
+
registry.set(id, factory({
|
|
37
|
+
clientId: credentials.clientId,
|
|
38
|
+
clientSecret: credentials.clientSecret,
|
|
39
|
+
redirectUri: credentials.redirectUri || `${config.callbackBaseUrl ?? ""}/auth/${id}/callback`
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
const sanitizeRedirect = (target) => {
|
|
43
|
+
const fallback = config.defaultRedirect;
|
|
44
|
+
if (typeof target !== "string" || target === "") return fallback;
|
|
45
|
+
if (target.startsWith("/") && !target.startsWith("//") && !target.startsWith("/\\")) return target;
|
|
46
|
+
const origin = originOf(target);
|
|
47
|
+
if (!origin) return fallback;
|
|
48
|
+
return [fallback, ...config.allowedRedirects ?? []].map(originOf).filter((value) => value !== null).includes(origin) ? target : fallback;
|
|
49
|
+
};
|
|
50
|
+
const withError = (target, reason) => `${target}${target.includes("?") ? "&" : "?"}error=${encodeURIComponent(reason)}`;
|
|
51
|
+
return {
|
|
52
|
+
/** Registered providers, so a front-end renders exactly the buttons that will work. */
|
|
53
|
+
list: () => [...registry.values()].map((provider) => ({
|
|
54
|
+
id: provider.id,
|
|
55
|
+
label: provider.label,
|
|
56
|
+
url: `${config.loginBaseUrl ?? config.callbackBaseUrl ?? ""}/auth/${provider.id}/login`
|
|
57
|
+
})),
|
|
58
|
+
get: (id) => registry.get(id),
|
|
59
|
+
start: (providerId, redirect) => {
|
|
60
|
+
const provider = registry.get(providerId);
|
|
61
|
+
if (!provider) return;
|
|
62
|
+
const { state, cookie } = startFlow(provider.id, sanitizeRedirect(redirect), config.secret, stateTtl);
|
|
63
|
+
return {
|
|
64
|
+
redirectTo: buildAuthorizationUrl(provider, state, codeChallenge(state.verifier)),
|
|
65
|
+
stateCookie: cookie,
|
|
66
|
+
ttl: stateTtl
|
|
67
|
+
};
|
|
68
|
+
},
|
|
69
|
+
complete: async (providerId, params) => {
|
|
70
|
+
const provider = registry.get(providerId);
|
|
71
|
+
if (!provider) return {
|
|
72
|
+
ok: false,
|
|
73
|
+
error: "Unknown provider",
|
|
74
|
+
reason: "invalid_state"
|
|
75
|
+
};
|
|
76
|
+
const flow = consumeFlow(params.stateCookie, provider.id, params.state, config.secret);
|
|
77
|
+
if (!flow) return {
|
|
78
|
+
ok: false,
|
|
79
|
+
error: "Invalid or expired authorization state",
|
|
80
|
+
reason: "invalid_state"
|
|
81
|
+
};
|
|
82
|
+
if (params.error || !params.code) {
|
|
83
|
+
const reason = params.error ? "access_denied" : "invalid_state";
|
|
84
|
+
return {
|
|
85
|
+
ok: false,
|
|
86
|
+
redirectTo: withError(flow.redirect, reason),
|
|
87
|
+
error: params.error ?? "",
|
|
88
|
+
reason
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
try {
|
|
92
|
+
const accessToken = await exchangeCodeForToken(provider, params.code, flow);
|
|
93
|
+
const profile = await provider.fetchProfile(accessToken);
|
|
94
|
+
const account = await adapters.linkAccount(provider.id, profile);
|
|
95
|
+
return {
|
|
96
|
+
ok: true,
|
|
97
|
+
redirectTo: flow.redirect,
|
|
98
|
+
account
|
|
99
|
+
};
|
|
100
|
+
} catch (error) {
|
|
101
|
+
const reason = error instanceof OAuthFailure ? error.reason : "server_error";
|
|
102
|
+
return {
|
|
103
|
+
ok: false,
|
|
104
|
+
redirectTo: withError(flow.redirect, reason),
|
|
105
|
+
error: error instanceof Error ? error.message : "server_error",
|
|
106
|
+
reason
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
//#endregion
|
|
113
|
+
export { BUILT_IN_PROVIDERS, OAuthFailure, createSocialAuth, requestProfileJson };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { requestProfileJson } from "../client.js";
|
|
2
|
+
//#region src/core/auth/oauth/providers/github.ts
|
|
3
|
+
var USER_URL = "https://api.github.com/user";
|
|
4
|
+
var EMAILS_URL = "https://api.github.com/user/emails";
|
|
5
|
+
var apiHeaders = (accessToken) => ({
|
|
6
|
+
Authorization: `Bearer ${accessToken}`,
|
|
7
|
+
Accept: "application/vnd.github+json",
|
|
8
|
+
"X-GitHub-Api-Version": "2022-11-28",
|
|
9
|
+
"User-Agent": "plitzi-sdk-server"
|
|
10
|
+
});
|
|
11
|
+
var createGitHubProvider = (config) => ({
|
|
12
|
+
id: "github",
|
|
13
|
+
label: "GitHub",
|
|
14
|
+
config,
|
|
15
|
+
authorizationUrl: "https://github.com/login/oauth/authorize",
|
|
16
|
+
tokenUrl: "https://github.com/login/oauth/access_token",
|
|
17
|
+
scope: "read:user user:email",
|
|
18
|
+
usePkce: false,
|
|
19
|
+
async verifyAudience(accessToken) {
|
|
20
|
+
const credentials = Buffer.from(`${config.clientId}:${config.clientSecret}`).toString("base64");
|
|
21
|
+
return (await fetch(`https://api.github.com/applications/${config.clientId}/token`, {
|
|
22
|
+
method: "POST",
|
|
23
|
+
headers: {
|
|
24
|
+
Authorization: `Basic ${credentials}`,
|
|
25
|
+
Accept: "application/vnd.github+json",
|
|
26
|
+
"X-GitHub-Api-Version": "2022-11-28",
|
|
27
|
+
"User-Agent": "plitzi-sdk-server",
|
|
28
|
+
"Content-Type": "application/json"
|
|
29
|
+
},
|
|
30
|
+
body: JSON.stringify({ access_token: accessToken })
|
|
31
|
+
})).ok;
|
|
32
|
+
},
|
|
33
|
+
async fetchProfile(accessToken) {
|
|
34
|
+
const headers = apiHeaders(accessToken);
|
|
35
|
+
const user = await requestProfileJson(USER_URL, headers);
|
|
36
|
+
const emails = await requestProfileJson(EMAILS_URL, headers);
|
|
37
|
+
const verified = emails.find((entry) => entry.primary && entry.verified) ?? emails.find((entry) => entry.verified);
|
|
38
|
+
const address = verified ?? emails.find((entry) => entry.primary) ?? emails.at(0);
|
|
39
|
+
return {
|
|
40
|
+
id: String(user.id),
|
|
41
|
+
email: address?.email ?? user.email ?? "",
|
|
42
|
+
emailVerified: verified !== void 0,
|
|
43
|
+
username: user.name ?? user.login
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
//#endregion
|
|
48
|
+
export { createGitHubProvider };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { requestProfileJson } from "../client.js";
|
|
2
|
+
//#region src/core/auth/oauth/providers/google.ts
|
|
3
|
+
var USERINFO_URL = "https://openidconnect.googleapis.com/v1/userinfo";
|
|
4
|
+
var TOKENINFO_URL = "https://oauth2.googleapis.com/tokeninfo";
|
|
5
|
+
var createGoogleProvider = (config) => ({
|
|
6
|
+
id: "google",
|
|
7
|
+
label: "Google",
|
|
8
|
+
config,
|
|
9
|
+
authorizationUrl: "https://accounts.google.com/o/oauth2/v2/auth",
|
|
10
|
+
tokenUrl: "https://oauth2.googleapis.com/token",
|
|
11
|
+
scope: "openid email profile",
|
|
12
|
+
usePkce: true,
|
|
13
|
+
authorizationParams: { prompt: "select_account" },
|
|
14
|
+
async verifyAudience(accessToken) {
|
|
15
|
+
const response = await fetch(`${TOKENINFO_URL}?access_token=${encodeURIComponent(accessToken)}`);
|
|
16
|
+
if (!response.ok) return false;
|
|
17
|
+
return (await response.json()).aud === config.clientId;
|
|
18
|
+
},
|
|
19
|
+
async fetchProfile(accessToken) {
|
|
20
|
+
const profile = await requestProfileJson(USERINFO_URL, { Authorization: `Bearer ${accessToken}` });
|
|
21
|
+
return {
|
|
22
|
+
id: profile.sub,
|
|
23
|
+
email: profile.email ?? "",
|
|
24
|
+
emailVerified: profile.email_verified === true,
|
|
25
|
+
username: profile.name ?? ""
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
//#endregion
|
|
30
|
+
export { createGoogleProvider };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface OAuthFlowState {
|
|
2
|
+
provider: string;
|
|
3
|
+
nonce: string;
|
|
4
|
+
verifier: string;
|
|
5
|
+
redirect: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const codeChallenge: (verifier: string) => string;
|
|
8
|
+
/**
|
|
9
|
+
* Starts a flow. The whole state is signed into a value the browser holds, and the provider only ever sees the
|
|
10
|
+
* nonce: that is what binds the callback to the browser that began it, and it keeps the PKCE verifier out of every
|
|
11
|
+
* URL the authorization code travels through.
|
|
12
|
+
*
|
|
13
|
+
* The value is returned rather than written — whoever calls this owns the cookie.
|
|
14
|
+
*/
|
|
15
|
+
export declare const startFlow: (provider: string, redirect: string, secret: string, ttlSeconds: number) => {
|
|
16
|
+
state: OAuthFlowState;
|
|
17
|
+
cookie: string;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Reads back the flow started above. Null unless the value is intact, unexpired, for this same provider, and its
|
|
21
|
+
* nonce matches the one the provider echoed back — the four things that together make a callback trustworthy.
|
|
22
|
+
*/
|
|
23
|
+
export declare const consumeFlow: (cookie: string | undefined, provider: string, nonce: unknown, secret: string) => OAuthFlowState | null;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
|
|
2
|
+
import jwt from "jsonwebtoken";
|
|
3
|
+
//#region src/core/auth/oauth/state.ts
|
|
4
|
+
var base64Url = (value) => value.toString("base64url");
|
|
5
|
+
var createCodeVerifier = () => base64Url(randomBytes(32));
|
|
6
|
+
var codeChallenge = (verifier) => base64Url(createHash("sha256").update(verifier).digest());
|
|
7
|
+
var equals = (a, b) => {
|
|
8
|
+
const left = Buffer.from(a);
|
|
9
|
+
const right = Buffer.from(b);
|
|
10
|
+
return left.length === right.length && timingSafeEqual(left, right);
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Starts a flow. The whole state is signed into a value the browser holds, and the provider only ever sees the
|
|
14
|
+
* nonce: that is what binds the callback to the browser that began it, and it keeps the PKCE verifier out of every
|
|
15
|
+
* URL the authorization code travels through.
|
|
16
|
+
*
|
|
17
|
+
* The value is returned rather than written — whoever calls this owns the cookie.
|
|
18
|
+
*/
|
|
19
|
+
var startFlow = (provider, redirect, secret, ttlSeconds) => {
|
|
20
|
+
const state = {
|
|
21
|
+
provider,
|
|
22
|
+
nonce: base64Url(randomBytes(16)),
|
|
23
|
+
verifier: createCodeVerifier(),
|
|
24
|
+
redirect
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
state,
|
|
28
|
+
cookie: jwt.sign(state, secret, {
|
|
29
|
+
algorithm: "HS256",
|
|
30
|
+
expiresIn: ttlSeconds
|
|
31
|
+
})
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Reads back the flow started above. Null unless the value is intact, unexpired, for this same provider, and its
|
|
36
|
+
* nonce matches the one the provider echoed back — the four things that together make a callback trustworthy.
|
|
37
|
+
*/
|
|
38
|
+
var consumeFlow = (cookie, provider, nonce, secret) => {
|
|
39
|
+
if (!cookie || typeof nonce !== "string" || nonce === "") return null;
|
|
40
|
+
let claims;
|
|
41
|
+
try {
|
|
42
|
+
claims = jwt.verify(cookie, secret, { algorithms: ["HS256"] });
|
|
43
|
+
} catch {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
if (claims.provider !== provider || !equals(claims.nonce, nonce)) return null;
|
|
47
|
+
return {
|
|
48
|
+
provider: claims.provider,
|
|
49
|
+
nonce: claims.nonce,
|
|
50
|
+
verifier: claims.verifier,
|
|
51
|
+
redirect: claims.redirect
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
//#endregion
|
|
55
|
+
export { codeChallenge, consumeFlow, startFlow };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export interface OAuthProviderConfig {
|
|
2
|
+
clientId: string;
|
|
3
|
+
clientSecret: string;
|
|
4
|
+
redirectUri: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* The identity a provider reports back. `emailVerified` is what makes linking safe: an incoming account may only be
|
|
8
|
+
* matched onto an existing one by an address the provider itself checked.
|
|
9
|
+
*/
|
|
10
|
+
export interface OAuthProfile {
|
|
11
|
+
id: string;
|
|
12
|
+
email: string;
|
|
13
|
+
emailVerified: boolean;
|
|
14
|
+
username: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* What every social provider declares. Everything shared by the authorization-code grant — the redirect, the CSRF
|
|
18
|
+
* nonce, PKCE, the token exchange, issuing the session — is the flow's; an adapter only names this provider's
|
|
19
|
+
* endpoints and maps its user payload onto {@link OAuthProfile}.
|
|
20
|
+
*/
|
|
21
|
+
export interface OAuthProvider {
|
|
22
|
+
/** Route segment (`/auth/<id>`) and the value stored against the linked identity. Never change it once users exist. */
|
|
23
|
+
id: string;
|
|
24
|
+
label: string;
|
|
25
|
+
config: OAuthProviderConfig;
|
|
26
|
+
authorizationUrl: string;
|
|
27
|
+
tokenUrl: string;
|
|
28
|
+
scope: string;
|
|
29
|
+
/** PKCE is only sent to providers that implement RFC 7636; GitHub OAuth apps ignore the challenge. */
|
|
30
|
+
usePkce: boolean;
|
|
31
|
+
/** Provider-specific extras for the authorization request (Google's `prompt`, for instance). */
|
|
32
|
+
authorizationParams?: Record<string, string>;
|
|
33
|
+
/** Extra headers on the token request. GitHub returns form-encoded bodies unless asked for JSON. */
|
|
34
|
+
tokenHeaders?: Record<string, string>;
|
|
35
|
+
fetchProfile: (accessToken: string) => Promise<OAuthProfile>;
|
|
36
|
+
/**
|
|
37
|
+
* Proves a token was issued **for this application**, and not merely that it is a valid token belonging to
|
|
38
|
+
* somebody. Only the credential exchange needs it, where the token arrives from a browser rather than from a code
|
|
39
|
+
* this server redeemed itself — without it, any other site the user signed into with the same provider could
|
|
40
|
+
* present their token here and be issued a session as them. An adapter that cannot check leaves it undefined, and
|
|
41
|
+
* the exchange refuses that provider outright.
|
|
42
|
+
*/
|
|
43
|
+
verifyAudience?: (accessToken: string) => Promise<boolean>;
|
|
44
|
+
}
|
|
45
|
+
export type OAuthFailureReason = 'access_denied' | 'invalid_state' | 'exchange_failed' | 'profile_failed' | 'email_unverified' | 'email_missing' | 'account_inactive' | 'server_error';
|
|
46
|
+
/** Carried all the way to the browser as `?error=<reason>` on the redirect target, so a front-end can tell "you
|
|
47
|
+
* cancelled" from "that account is disabled" without parsing prose. */
|
|
48
|
+
export declare class OAuthFailure extends Error {
|
|
49
|
+
readonly reason: OAuthFailureReason;
|
|
50
|
+
constructor(reason: OAuthFailureReason, message: string);
|
|
51
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/core/auth/oauth/types.ts
|
|
2
|
+
/** Carried all the way to the browser as `?error=<reason>` on the redirect target, so a front-end can tell "you
|
|
3
|
+
* cancelled" from "that account is disabled" without parsing prose. */
|
|
4
|
+
var OAuthFailure = class extends Error {
|
|
5
|
+
reason;
|
|
6
|
+
constructor(reason, message) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = "OAuthFailure";
|
|
9
|
+
this.reason = reason;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
//#endregion
|
|
13
|
+
export { OAuthFailure };
|