@plitzi/sdk-server 0.39.1 → 0.39.2
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 +12 -0
- package/README.md +364 -61
- package/dist/adapters/authAdapters.d.ts +2 -1
- package/dist/adapters/cloudAdapters.d.ts +2 -1
- package/dist/adapters/jsonAdapters.d.ts +2 -1
- package/dist/adapters/space/index.d.ts +3 -3
- package/dist/adapters/space/resolvers.d.ts +41 -4
- package/dist/adapters/space/types.d.ts +11 -1
- package/dist/auth.d.ts +9 -29
- package/dist/auth.js +2323 -22
- package/dist/bundle.d.ts +6 -0
- package/dist/bundle.js +171 -0
- package/dist/cache.d.ts +7 -0
- package/dist/cache.js +1 -0
- package/dist/chunks/buildBody-W9D8ySNY.js +1450 -0
- package/dist/chunks/core-TlrWmT4B.js +2118 -0
- package/dist/chunks/createServer-Bd_b7T3k.js +2956 -0
- package/dist/chunks/platform-DhdFYWm5.js +38 -0
- package/dist/{core/auth/routes.js → chunks/renewal-D98v6-Jd.js} +23 -4
- package/dist/chunks/template-M3IEZ6os.js +42 -0
- package/dist/{core/auth/throttle.js → chunks/throttle-BH7JLIOF.js} +4 -5
- package/dist/chunks/token-B2uY9JzU.js +824 -0
- package/dist/chunks/views/inline/keepTaps.js +1 -0
- package/dist/chunks/views/inline/motionSeen.js +2 -0
- package/dist/{modules/ssr → chunks}/views/template.ejs +62 -100
- package/dist/core/auth/api/admin.d.ts +2 -3
- package/dist/core/auth/api/context.d.ts +24 -29
- package/dist/core/auth/api/factors.d.ts +1 -2
- package/dist/core/auth/api/index.d.ts +30 -30
- package/dist/core/auth/api/profile.d.ts +1 -1
- package/dist/core/auth/api/session.d.ts +1 -2
- package/dist/core/auth/api/types.d.ts +2 -280
- package/dist/core/auth/api/values.d.ts +2 -3
- package/dist/core/auth/createAuth.d.ts +67 -76
- package/dist/core/auth/oauth/index.d.ts +1 -1
- package/dist/core/auth/oauth/providers/oidc.d.ts +0 -6
- package/dist/core/auth/renewal.d.ts +1 -3
- package/dist/core/auth/routes.d.ts +1 -5
- package/dist/core/auth/throttle.d.ts +2 -2
- package/dist/core/createServer.d.ts +14 -5
- package/dist/core/handlers/authMiddleware.d.ts +1 -2
- package/dist/core/handlers/authRouteHandlers.d.ts +1 -2
- package/dist/core/handlers/csrfMiddleware.d.ts +1 -2
- package/dist/core/handlers/oauthRouteHandlers.d.ts +1 -1
- package/dist/core/handlers/socialRouteHandlers.d.ts +2 -3
- package/dist/core/handlers/types.d.ts +1 -3
- package/dist/core/http/pageContext.d.ts +25 -0
- package/dist/core/http/stages/authApi.d.ts +1 -1
- package/dist/core/http/stages/authRoutes.d.ts +4 -10
- package/dist/core/http/stages/cspReport.d.ts +6 -0
- package/dist/core/http/stages/defaultFavicon.d.ts +3 -0
- package/dist/core/http/stages/exchangeRoute.d.ts +3 -2
- package/dist/core/http/stages/fontAssets.d.ts +3 -2
- package/dist/core/http/stages/googleFonts.d.ts +7 -0
- package/dist/core/http/stages/images.d.ts +4 -3
- package/dist/core/http/stages/livePages.d.ts +3 -2
- package/dist/core/http/stages/oauth.d.ts +2 -2
- package/dist/core/http/stages/pluginAssets.d.ts +2 -1
- package/dist/core/http/stages/{static.d.ts → sdkAssets.d.ts} +1 -4
- package/dist/core/http/stages/sessionRenewal.d.ts +4 -3
- package/dist/core/http/stages/signInRoute.d.ts +3 -2
- package/dist/core/oauth/authorize.d.ts +1 -1
- package/dist/core/oauth/challenge.d.ts +1 -1
- package/dist/core/oauth/consentPage.d.ts +1 -1
- package/dist/core/oauth/issueContext.d.ts +1 -1
- package/dist/core/oauth/metadata.d.ts +1 -5
- package/dist/core/oauth/records.d.ts +1 -1
- package/dist/core/oauth/register.d.ts +1 -1
- package/dist/core/oauth/respond.d.ts +1 -1
- package/dist/core/oauth/token.d.ts +1 -1
- package/dist/core/platform.d.ts +13 -0
- package/dist/core/sdkAssets.d.ts +11 -1
- package/dist/core/server/pageServer.d.ts +4 -3
- package/dist/core/server/{fleet/relay.d.ts → relay.d.ts} +1 -2
- package/dist/core/server/reportCacheSharing.d.ts +11 -0
- package/dist/core/services/registry.d.ts +4 -2
- package/dist/core/services/resolve.d.ts +1 -9
- package/dist/core/services/robotsTxt.d.ts +2 -1
- package/dist/core/services/rsc.d.ts +2 -1
- package/dist/core/services/servedSpace.d.ts +1 -1
- package/dist/core/services/sitemapXml.d.ts +2 -1
- package/dist/core/services/spaceDocument.d.ts +2 -1
- package/dist/core/services/ssr.d.ts +2 -1
- package/dist/core/services/styleSheet.d.ts +3 -0
- package/dist/env.js +1 -2
- package/dist/handlers.d.ts +1 -1
- package/dist/handlers.js +517 -5
- package/dist/helpers/buildServerInfo.d.ts +3 -1
- package/dist/helpers/cache/cacheManager.d.ts +1 -1
- package/dist/helpers/cache/defaults.d.ts +22 -1
- package/dist/helpers/cache/index.d.ts +11 -4
- package/dist/helpers/cache/keys.d.ts +27 -4
- package/dist/helpers/cache/limits.d.ts +16 -0
- package/dist/helpers/cache/pages.d.ts +20 -0
- package/dist/helpers/cache/queryParams.d.ts +11 -0
- package/dist/helpers/cache/serverCaches.d.ts +24 -11
- package/dist/helpers/cache/sharedCache.d.ts +29 -0
- package/dist/helpers/hydrationPayload.d.ts +35 -8
- package/dist/helpers/metrics.d.ts +5 -1
- package/dist/helpers/paintedCookie.d.ts +13 -0
- package/dist/helpers/visitorScheme.d.ts +10 -0
- package/dist/hosts/authoringHost/index.d.ts +1 -1
- package/dist/hosts/project/agentRuns.d.ts +1 -1
- package/dist/hosts/project/bundle.d.ts +22 -0
- package/dist/hosts/project/laterAsks.d.ts +1 -1
- package/dist/hosts/project/plugins.d.ts +3 -2
- package/dist/hosts/project/serveProject.d.ts +7 -7
- package/dist/hosts/project/spaceFailure.d.ts +1 -1
- package/dist/index.d.ts +9 -18
- package/dist/index.js +168 -24
- package/dist/modules/fonts/googleFonts.d.ts +27 -0
- package/dist/modules/images/imageProxy.d.ts +1 -1
- package/dist/modules/rsc/connectorRscData.d.ts +10 -12
- package/dist/modules/rsc/externalQueryReader.d.ts +28 -5
- package/dist/modules/rsc/handler.d.ts +3 -1
- package/dist/modules/rsc/matchRscPage.d.ts +0 -8
- package/dist/modules/rsc/publicFileResolver.d.ts +1 -1
- package/dist/modules/rsc/resolveRscData.d.ts +3 -31
- package/dist/modules/ssr/Component.d.ts +6 -3
- package/dist/modules/ssr/applySSRResult.d.ts +2 -6
- package/dist/modules/ssr/buildBody.d.ts +7 -2
- package/dist/modules/ssr/defaultFavicon.d.ts +10 -0
- package/dist/modules/ssr/earlyHints.d.ts +18 -0
- package/dist/modules/ssr/handler.d.ts +4 -2
- package/dist/modules/ssr/loadPluginComponents.d.ts +2 -1
- package/dist/modules/ssr/meterPage.d.ts +4 -0
- package/dist/modules/ssr/pageCache.d.ts +47 -0
- package/dist/modules/ssr/prepareRender.d.ts +11 -3
- package/dist/modules/ssr/preview.d.ts +5 -3
- package/dist/modules/ssr/redisPageStore.d.ts +29 -0
- package/dist/modules/ssr/registerExternalPlugins.d.ts +1 -1
- package/dist/modules/ssr/renderTurns.d.ts +34 -0
- package/dist/modules/ssr/reportMissingPlugins.d.ts +0 -7
- package/dist/modules/ssr/scriptPolicy.d.ts +39 -0
- package/dist/modules/ssr/spaceDocument.d.ts +25 -2
- package/dist/modules/ssr/streamBody.d.ts +9 -3
- package/dist/modules/ssr/styleSheet.d.ts +15 -0
- package/dist/modules/ssr/template.d.ts +8 -1
- package/dist/oauth.js +139 -9
- package/dist/platform.d.ts +6 -0
- package/dist/platform.js +1 -0
- package/dist/project.js +939 -1
- package/dist/spaces.d.ts +7 -0
- package/dist/spaces.js +1 -0
- package/dist/ssr.d.ts +1 -2
- package/dist/ssr.js +1 -4
- package/dist/types/config.d.ts +252 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/server.d.ts +111 -0
- package/package.json +41 -83
- package/skills/plitzi-authoring/recipes/server-data.ts +4 -0
- package/skills/plitzi-authoring/reference/accessibility.md +6 -2
- package/skills/plitzi-authoring/reference/auth.md +6 -1
- package/skills/plitzi-authoring/reference/authoring-errors.md +3 -2
- package/skills/plitzi-authoring/reference/lists.md +7 -1
- package/dist/actions.d.ts +0 -87
- package/dist/actions.js +0 -23
- package/dist/adapters/authAdapters.js +0 -12
- package/dist/adapters/cloudAdapters.js +0 -364
- package/dist/adapters/jsonAdapters.js +0 -88
- package/dist/adapters/space/index.js +0 -122
- package/dist/adapters/space/resolvers.js +0 -79
- package/dist/adapters/space/types.js +0 -41
- package/dist/core/auth/api/accounts.js +0 -175
- package/dist/core/auth/api/admin.js +0 -146
- package/dist/core/auth/api/context.js +0 -262
- package/dist/core/auth/api/factors.js +0 -209
- package/dist/core/auth/api/index.js +0 -43
- package/dist/core/auth/api/profile.js +0 -243
- package/dist/core/auth/api/session.js +0 -312
- package/dist/core/auth/api/values.js +0 -90
- package/dist/core/auth/authorize.d.ts +0 -96
- package/dist/core/auth/authorize.js +0 -92
- package/dist/core/auth/createAuth.js +0 -216
- package/dist/core/auth/credentials.d.ts +0 -40
- package/dist/core/auth/credentials.js +0 -56
- package/dist/core/auth/csrf.d.ts +0 -143
- package/dist/core/auth/csrf.js +0 -295
- package/dist/core/auth/domains.d.ts +0 -41
- package/dist/core/auth/domains.js +0 -78
- package/dist/core/auth/identity.d.ts +0 -118
- package/dist/core/auth/identity.js +0 -194
- package/dist/core/auth/oauth/client.js +0 -52
- package/dist/core/auth/oauth/index.js +0 -130
- package/dist/core/auth/oauth/providers/github.js +0 -48
- package/dist/core/auth/oauth/providers/google.js +0 -30
- package/dist/core/auth/oauth/providers/oidc.js +0 -197
- package/dist/core/auth/oauth/state.js +0 -57
- package/dist/core/auth/oauth/types.js +0 -16
- package/dist/core/auth/passwords.d.ts +0 -15
- package/dist/core/auth/passwords.js +0 -32
- package/dist/core/auth/redirects.js +0 -31
- package/dist/core/auth/renewal.js +0 -24
- package/dist/core/auth/session.d.ts +0 -194
- package/dist/core/auth/session.js +0 -237
- package/dist/core/auth/sessionActivity.d.ts +0 -11
- package/dist/core/auth/sessionActivity.js +0 -14
- package/dist/core/auth/spaceTokens.d.ts +0 -173
- package/dist/core/auth/spaceTokens.js +0 -264
- package/dist/core/auth/tokens.d.ts +0 -224
- package/dist/core/auth/tokens.js +0 -264
- package/dist/core/auth/totp.js +0 -123
- package/dist/core/configSeam.d.ts +0 -10
- package/dist/core/configSeam.js +0 -151
- package/dist/core/createServer.js +0 -119
- package/dist/core/fontStore.js +0 -53
- package/dist/core/freePort.d.ts +0 -24
- package/dist/core/freePort.js +0 -74
- package/dist/core/handlers/authMiddleware.js +0 -38
- package/dist/core/handlers/authRouteHandlers.js +0 -112
- package/dist/core/handlers/csrfMiddleware.js +0 -56
- package/dist/core/handlers/oauthRouteHandlers.js +0 -161
- package/dist/core/handlers/socialRouteHandlers.js +0 -169
- package/dist/core/health.d.ts +0 -21
- package/dist/core/health.js +0 -40
- package/dist/core/http/dispatcher.d.ts +0 -15
- package/dist/core/http/dispatcher.js +0 -115
- package/dist/core/http/navigation.d.ts +0 -14
- package/dist/core/http/navigation.js +0 -19
- package/dist/core/http/securityHeaders.d.ts +0 -2
- package/dist/core/http/securityHeaders.js +0 -17
- package/dist/core/http/socketResponse.d.ts +0 -18
- package/dist/core/http/socketResponse.js +0 -59
- package/dist/core/http/sse.d.ts +0 -26
- package/dist/core/http/sse.js +0 -78
- package/dist/core/http/stages/authApi.js +0 -66
- package/dist/core/http/stages/authRoutes.js +0 -116
- package/dist/core/http/stages/crossSiteWrites.d.ts +0 -24
- package/dist/core/http/stages/crossSiteWrites.js +0 -45
- package/dist/core/http/stages/exchangeRoute.js +0 -69
- package/dist/core/http/stages/fontAssets.js +0 -27
- package/dist/core/http/stages/health.d.ts +0 -11
- package/dist/core/http/stages/health.js +0 -34
- package/dist/core/http/stages/images.js +0 -49
- package/dist/core/http/stages/livePages.js +0 -80
- package/dist/core/http/stages/middlewares.d.ts +0 -2
- package/dist/core/http/stages/middlewares.js +0 -23
- package/dist/core/http/stages/oauth.js +0 -118
- package/dist/core/http/stages/pluginAssets.js +0 -21
- package/dist/core/http/stages/sessionRenewal.js +0 -82
- package/dist/core/http/stages/signInRoute.js +0 -139
- package/dist/core/http/stages/static.js +0 -48
- package/dist/core/http/types.d.ts +0 -56
- package/dist/core/http/webExchange.d.ts +0 -18
- package/dist/core/http/webExchange.js +0 -53
- package/dist/core/mimeTypes.d.ts +0 -13
- package/dist/core/mimeTypes.js +0 -42
- package/dist/core/oauth/authorize.js +0 -279
- package/dist/core/oauth/challenge.js +0 -33
- package/dist/core/oauth/consentPage.js +0 -134
- package/dist/core/oauth/issueContext.js +0 -32
- package/dist/core/oauth/metadata.js +0 -71
- package/dist/core/oauth/params.js +0 -5
- package/dist/core/oauth/pkce.js +0 -15
- package/dist/core/oauth/records.js +0 -49
- package/dist/core/oauth/register.js +0 -76
- package/dist/core/oauth/respond.js +0 -59
- package/dist/core/oauth/token.js +0 -145
- package/dist/core/previewToken.d.ts +0 -21
- package/dist/core/previewToken.js +0 -32
- package/dist/core/requestParser.d.ts +0 -22
- package/dist/core/requestParser.js +0 -79
- package/dist/core/sdkAssets.js +0 -46
- package/dist/core/server/baseServer.d.ts +0 -30
- package/dist/core/server/baseServer.js +0 -106
- package/dist/core/server/closeOnSignals.d.ts +0 -28
- package/dist/core/server/closeOnSignals.js +0 -47
- package/dist/core/server/drain.d.ts +0 -18
- package/dist/core/server/drain.js +0 -82
- package/dist/core/server/fleet/channel.d.ts +0 -103
- package/dist/core/server/fleet/channel.js +0 -191
- package/dist/core/server/fleet/link.d.ts +0 -23
- package/dist/core/server/fleet/link.js +0 -70
- package/dist/core/server/fleet/relay.js +0 -112
- package/dist/core/server/fleet/role.d.ts +0 -46
- package/dist/core/server/fleet/role.js +0 -59
- package/dist/core/server/fleet/stores.d.ts +0 -21
- package/dist/core/server/fleet/stores.js +0 -46
- package/dist/core/server/fleet/supervisor.d.ts +0 -28
- package/dist/core/server/fleet/supervisor.js +0 -120
- package/dist/core/server/pageServer.js +0 -124
- package/dist/core/services/action.d.ts +0 -11
- package/dist/core/services/action.js +0 -123
- package/dist/core/services/functionRoutes.d.ts +0 -9
- package/dist/core/services/functionRoutes.js +0 -53
- package/dist/core/services/realtime.d.ts +0 -8
- package/dist/core/services/realtime.js +0 -62
- package/dist/core/services/registry.js +0 -47
- package/dist/core/services/resolve.js +0 -25
- package/dist/core/services/robotsTxt.js +0 -50
- package/dist/core/services/rsc.js +0 -13
- package/dist/core/services/servedSpace.js +0 -16
- package/dist/core/services/sitemapXml.js +0 -37
- package/dist/core/services/spaceDocument.js +0 -11
- package/dist/core/services/ssr.js +0 -13
- package/dist/core/staticFiles.d.ts +0 -3
- package/dist/core/staticFiles.js +0 -49
- package/dist/core/transports.d.ts +0 -31
- package/dist/core/transports.js +0 -61
- package/dist/core/unusedPort.d.ts +0 -10
- package/dist/core/unusedPort.js +0 -38
- package/dist/functions-api.d.ts +0 -679
- package/dist/functions.d.ts +0 -21
- package/dist/functions.js +0 -6
- package/dist/functionsRunner.d.ts +0 -20
- package/dist/functionsRunner.js +0 -7
- package/dist/helpers/atomicFile.d.ts +0 -10
- package/dist/helpers/atomicFile.js +0 -33
- package/dist/helpers/buildResponseHelpers.d.ts +0 -21
- package/dist/helpers/buildResponseHelpers.js +0 -84
- package/dist/helpers/buildServerInfo.js +0 -86
- package/dist/helpers/cache/CompressedFileCache.d.ts +0 -18
- package/dist/helpers/cache/CompressedFileCache.js +0 -44
- package/dist/helpers/cache/TtlCache.d.ts +0 -15
- package/dist/helpers/cache/TtlCache.js +0 -57
- package/dist/helpers/cache/cacheManager.js +0 -50
- package/dist/helpers/cache/defaults.js +0 -9
- package/dist/helpers/cache/keys.js +0 -130
- package/dist/helpers/cache/serverCaches.js +0 -15
- package/dist/helpers/compress.d.ts +0 -20
- package/dist/helpers/compress.js +0 -61
- package/dist/helpers/debugAuthorization.d.ts +0 -24
- package/dist/helpers/debugAuthorization.js +0 -27
- package/dist/helpers/escapeHtml.js +0 -13
- package/dist/helpers/escapeJson.js +0 -4
- package/dist/helpers/fileStore.d.ts +0 -60
- package/dist/helpers/fileStore.js +0 -127
- package/dist/helpers/flagOverrides.d.ts +0 -30
- package/dist/helpers/flagOverrides.js +0 -26
- package/dist/helpers/hydrationPayload.js +0 -57
- package/dist/helpers/metrics.js +0 -37
- package/dist/helpers/normalizePlugins.js +0 -16
- package/dist/helpers/offlineDataLoader.js +0 -15
- package/dist/helpers/onAbort.d.ts +0 -12
- package/dist/helpers/onAbort.js +0 -22
- package/dist/helpers/outboundGuard.d.ts +0 -64
- package/dist/helpers/outboundGuard.js +0 -218
- package/dist/helpers/paintedCookie.js +0 -13
- package/dist/helpers/readCookie.js +0 -11
- package/dist/helpers/reportReactBuild.js +0 -18
- package/dist/helpers/resolveDebugMode.js +0 -13
- package/dist/helpers/runMiddlewares.d.ts +0 -2
- package/dist/helpers/runMiddlewares.js +0 -21
- package/dist/helpers/serverLog.d.ts +0 -37
- package/dist/helpers/serverLog.js +0 -116
- package/dist/helpers/wsFrame.d.ts +0 -3
- package/dist/helpers/wsFrame.js +0 -5
- package/dist/hosts/authoringHost/index.js +0 -118
- package/dist/hosts/project/agentRuns.js +0 -107
- package/dist/hosts/project/laterAsks.js +0 -117
- package/dist/hosts/project/plugins.js +0 -185
- package/dist/hosts/project/serveProject.js +0 -403
- package/dist/hosts/project/spaceFailure.js +0 -86
- package/dist/hosts/project/watchSpace.js +0 -86
- package/dist/kernel.d.ts +0 -25
- package/dist/kernel.js +0 -10
- package/dist/middlewares/auth.d.ts +0 -2
- package/dist/middlewares/auth.js +0 -10
- package/dist/middlewares/basicAuth.d.ts +0 -6
- package/dist/middlewares/basicAuth.js +0 -67
- package/dist/middlewares/spaceDeployment.d.ts +0 -2
- package/dist/middlewares/spaceDeployment.js +0 -17
- package/dist/modules/actions/connectorWrite.d.ts +0 -11
- package/dist/modules/actions/connectorWrite.js +0 -83
- package/dist/modules/actions/index.d.ts +0 -78
- package/dist/modules/actions/index.js +0 -129
- package/dist/modules/actions/jobs/failureStreak.d.ts +0 -17
- package/dist/modules/actions/jobs/failureStreak.js +0 -47
- package/dist/modules/actions/jobs/fileQueue.d.ts +0 -34
- package/dist/modules/actions/jobs/fileQueue.js +0 -72
- package/dist/modules/actions/jobs/index.d.ts +0 -34
- package/dist/modules/actions/jobs/index.js +0 -60
- package/dist/modules/actions/jobs/later.d.ts +0 -43
- package/dist/modules/actions/jobs/later.js +0 -69
- package/dist/modules/actions/jobs/memoryQueue.d.ts +0 -33
- package/dist/modules/actions/jobs/memoryQueue.js +0 -42
- package/dist/modules/actions/jobs/queueDocument.d.ts +0 -14
- package/dist/modules/actions/jobs/queueDocument.js +0 -22
- package/dist/modules/actions/jobs/queueRules.d.ts +0 -39
- package/dist/modules/actions/jobs/queueRules.js +0 -270
- package/dist/modules/actions/jobs/scheduler.d.ts +0 -64
- package/dist/modules/actions/jobs/scheduler.js +0 -133
- package/dist/modules/actions/jobs/schedules.d.ts +0 -23
- package/dist/modules/actions/jobs/schedules.js +0 -47
- package/dist/modules/actions/jobs/storeClock.d.ts +0 -16
- package/dist/modules/actions/jobs/storeClock.js +0 -32
- package/dist/modules/actions/jobs/worker.d.ts +0 -67
- package/dist/modules/actions/jobs/worker.js +0 -361
- package/dist/modules/actions/moduleFor.d.ts +0 -3
- package/dist/modules/actions/moduleFor.js +0 -44
- package/dist/modules/actions/runtime/check.d.ts +0 -24
- package/dist/modules/actions/runtime/check.js +0 -122
- package/dist/modules/actions/runtime/credentials.d.ts +0 -10
- package/dist/modules/actions/runtime/credentials.js +0 -28
- package/dist/modules/actions/runtime/email.d.ts +0 -39
- package/dist/modules/actions/runtime/email.js +0 -91
- package/dist/modules/actions/runtime/errors.d.ts +0 -42
- package/dist/modules/actions/runtime/errors.js +0 -53
- package/dist/modules/actions/runtime/fileKv.d.ts +0 -35
- package/dist/modules/actions/runtime/fileKv.js +0 -81
- package/dist/modules/actions/runtime/flags.d.ts +0 -16
- package/dist/modules/actions/runtime/flags.js +0 -49
- package/dist/modules/actions/runtime/guards.d.ts +0 -144
- package/dist/modules/actions/runtime/guards.js +0 -255
- package/dist/modules/actions/runtime/kvChange.d.ts +0 -67
- package/dist/modules/actions/runtime/kvChange.js +0 -45
- package/dist/modules/actions/runtime/kvList.d.ts +0 -55
- package/dist/modules/actions/runtime/kvList.js +0 -56
- package/dist/modules/actions/runtime/kvStore.d.ts +0 -35
- package/dist/modules/actions/runtime/kvStore.js +0 -81
- package/dist/modules/actions/runtime/limits.d.ts +0 -11
- package/dist/modules/actions/runtime/limits.js +0 -35
- package/dist/modules/actions/runtime/memoryKv.d.ts +0 -28
- package/dist/modules/actions/runtime/memoryKv.js +0 -110
- package/dist/modules/actions/runtime/namespaceKv.d.ts +0 -9
- package/dist/modules/actions/runtime/namespaceKv.js +0 -35
- package/dist/modules/actions/runtime/precheck.d.ts +0 -27
- package/dist/modules/actions/runtime/precheck.js +0 -41
- package/dist/modules/actions/runtime/projectData.d.ts +0 -18
- package/dist/modules/actions/runtime/projectData.js +0 -69
- package/dist/modules/actions/runtime/rateLimit.d.ts +0 -26
- package/dist/modules/actions/runtime/rateLimit.js +0 -25
- package/dist/modules/actions/runtime/redisKv.d.ts +0 -27
- package/dist/modules/actions/runtime/redisKv.js +0 -46
- package/dist/modules/actions/runtime/renderResolver.d.ts +0 -16
- package/dist/modules/actions/runtime/renderResolver.js +0 -240
- package/dist/modules/actions/runtime/renderShare.d.ts +0 -12
- package/dist/modules/actions/runtime/renderShare.js +0 -70
- package/dist/modules/actions/runtime/report.d.ts +0 -14
- package/dist/modules/actions/runtime/report.js +0 -23
- package/dist/modules/actions/runtime/runAction.d.ts +0 -26
- package/dist/modules/actions/runtime/runAction.js +0 -606
- package/dist/modules/actions/runtime/runLogger.d.ts +0 -36
- package/dist/modules/actions/runtime/runLogger.js +0 -72
- package/dist/modules/actions/runtime/scope.d.ts +0 -40
- package/dist/modules/actions/runtime/scope.js +0 -129
- package/dist/modules/actions/runtime/signing.d.ts +0 -27
- package/dist/modules/actions/runtime/signing.js +0 -50
- package/dist/modules/actions/runtime/taskContext.d.ts +0 -51
- package/dist/modules/actions/runtime/taskContext.js +0 -125
- package/dist/modules/actions/runtime/triggers.d.ts +0 -12
- package/dist/modules/actions/runtime/triggers.js +0 -14
- package/dist/modules/actions/taskCatalog.d.ts +0 -28
- package/dist/modules/actions/taskCatalog.js +0 -25
- package/dist/modules/actions/tasks/auth.d.ts +0 -2
- package/dist/modules/actions/tasks/auth.js +0 -42
- package/dist/modules/actions/tasks/builtins.d.ts +0 -10
- package/dist/modules/actions/tasks/builtins.js +0 -32
- package/dist/modules/actions/tasks/connector.d.ts +0 -2
- package/dist/modules/actions/tasks/connector.js +0 -145
- package/dist/modules/actions/tasks/db.d.ts +0 -2
- package/dist/modules/actions/tasks/db.js +0 -59
- package/dist/modules/actions/tasks/email.d.ts +0 -2
- package/dist/modules/actions/tasks/email.js +0 -72
- package/dist/modules/actions/tasks/flow.d.ts +0 -3
- package/dist/modules/actions/tasks/flow.js +0 -282
- package/dist/modules/actions/tasks/helpers.d.ts +0 -16
- package/dist/modules/actions/tasks/helpers.js +0 -30
- package/dist/modules/actions/tasks/http.d.ts +0 -2
- package/dist/modules/actions/tasks/http.js +0 -111
- package/dist/modules/actions/tasks/kv.d.ts +0 -2
- package/dist/modules/actions/tasks/kv.js +0 -146
- package/dist/modules/actions/tasks/list.d.ts +0 -2
- package/dist/modules/actions/tasks/list.js +0 -154
- package/dist/modules/actions/tasks/realtime.d.ts +0 -2
- package/dist/modules/actions/tasks/realtime.js +0 -104
- package/dist/modules/actions/tasks/registry.d.ts +0 -26
- package/dist/modules/actions/tasks/registry.js +0 -63
- package/dist/modules/actions/tasks/transform.d.ts +0 -2
- package/dist/modules/actions/tasks/transform.js +0 -36
- package/dist/modules/actions/transport/callHandler.d.ts +0 -24
- package/dist/modules/actions/transport/callHandler.js +0 -296
- package/dist/modules/actions/transport/cancelHandler.d.ts +0 -23
- package/dist/modules/actions/transport/cancelHandler.js +0 -23
- package/dist/modules/actions/transport/catalogHandler.d.ts +0 -21
- package/dist/modules/actions/transport/catalogHandler.js +0 -22
- package/dist/modules/actions/transport/stream.d.ts +0 -22
- package/dist/modules/actions/transport/stream.js +0 -36
- package/dist/modules/actions/transport/verifySignature.d.ts +0 -16
- package/dist/modules/actions/transport/verifySignature.js +0 -72
- package/dist/modules/actions/transport/webhookHandler.d.ts +0 -25
- package/dist/modules/actions/transport/webhookHandler.js +0 -207
- package/dist/modules/actions/types.d.ts +0 -520
- package/dist/modules/connectors/engine.d.ts +0 -47
- package/dist/modules/connectors/engine.js +0 -222
- package/dist/modules/connectors/getByPath.d.ts +0 -8
- package/dist/modules/connectors/getByPath.js +0 -21
- package/dist/modules/connectors/index.d.ts +0 -7
- package/dist/modules/connectors/projection.d.ts +0 -18
- package/dist/modules/connectors/projection.js +0 -108
- package/dist/modules/connectors/resolver.d.ts +0 -27
- package/dist/modules/connectors/resolver.js +0 -74
- package/dist/modules/connectors/types.d.ts +0 -19
- package/dist/modules/functions/build.d.ts +0 -27
- package/dist/modules/functions/build.js +0 -216
- package/dist/modules/functions/capabilities.d.ts +0 -22
- package/dist/modules/functions/capabilities.js +0 -435
- package/dist/modules/functions/config.d.ts +0 -76
- package/dist/modules/functions/config.js +0 -40
- package/dist/modules/functions/context.d.ts +0 -20
- package/dist/modules/functions/context.js +0 -146
- package/dist/modules/functions/contract.d.ts +0 -329
- package/dist/modules/functions/contract.js +0 -9
- package/dist/modules/functions/driver.d.ts +0 -37
- package/dist/modules/functions/driver.js +0 -368
- package/dist/modules/functions/jobControl.d.ts +0 -21
- package/dist/modules/functions/jobControl.js +0 -43
- package/dist/modules/functions/jobs.d.ts +0 -98
- package/dist/modules/functions/jobs.js +0 -438
- package/dist/modules/functions/load.d.ts +0 -22
- package/dist/modules/functions/load.js +0 -49
- package/dist/modules/functions/local.d.ts +0 -31
- package/dist/modules/functions/local.js +0 -64
- package/dist/modules/functions/manifest.d.ts +0 -31
- package/dist/modules/functions/manifest.js +0 -337
- package/dist/modules/functions/native.d.ts +0 -9
- package/dist/modules/functions/native.js +0 -22
- package/dist/modules/functions/oauth.d.ts +0 -33
- package/dist/modules/functions/oauth.js +0 -360
- package/dist/modules/functions/protocol.d.ts +0 -344
- package/dist/modules/functions/protocol.js +0 -32
- package/dist/modules/functions/routes.d.ts +0 -51
- package/dist/modules/functions/routes.js +0 -242
- package/dist/modules/functions/runner/messages.d.ts +0 -4
- package/dist/modules/functions/runner/messages.js +0 -229
- package/dist/modules/functions/runner/remote.d.ts +0 -19
- package/dist/modules/functions/runner/remote.js +0 -168
- package/dist/modules/functions/runner/service.d.ts +0 -32
- package/dist/modules/functions/runner/service.js +0 -255
- package/dist/modules/functions/sandbox/guest/bytes.d.ts +0 -27
- package/dist/modules/functions/sandbox/guest/bytes.js +0 -108
- package/dist/modules/functions/sandbox/guest/crypto.d.ts +0 -47
- package/dist/modules/functions/sandbox/guest/crypto.js +0 -144
- package/dist/modules/functions/sandbox/guest/events.d.ts +0 -152
- package/dist/modules/functions/sandbox/guest/events.js +0 -143
- package/dist/modules/functions/sandbox/guest/fetch.d.ts +0 -305
- package/dist/modules/functions/sandbox/guest/fetch.js +0 -237
- package/dist/modules/functions/sandbox/guest/index.d.ts +0 -28
- package/dist/modules/functions/sandbox/guest/index.js +0 -130
- package/dist/modules/functions/sandbox/guest/types.d.ts +0 -38
- package/dist/modules/functions/sandbox/isolate.d.ts +0 -37
- package/dist/modules/functions/sandbox/isolate.js +0 -360
- package/dist/modules/functions/sandbox/prelude.d.ts +0 -2
- package/dist/modules/functions/sandbox/prelude.js +0 -49
- package/dist/modules/functions/scope.d.ts +0 -30
- package/dist/modules/functions/scope.js +0 -28
- package/dist/modules/functions/space.d.ts +0 -47
- package/dist/modules/functions/space.js +0 -185
- package/dist/modules/functions/tryEntry.d.ts +0 -9
- package/dist/modules/functions/tryEntry.js +0 -49
- package/dist/modules/images/allowlist.js +0 -18
- package/dist/modules/images/imageProxy.js +0 -291
- package/dist/modules/images/transform.js +0 -28
- package/dist/modules/mongo/index.d.ts +0 -4
- package/dist/modules/mongo/jobQueue.d.ts +0 -38
- package/dist/modules/mongo/jobQueue.js +0 -453
- package/dist/modules/mongo/kv.d.ts +0 -15
- package/dist/modules/mongo/kv.js +0 -129
- package/dist/modules/mysql/accounts.d.ts +0 -5
- package/dist/modules/mysql/accounts.js +0 -378
- package/dist/modules/mysql/admin.d.ts +0 -58
- package/dist/modules/mysql/admin.js +0 -133
- package/dist/modules/mysql/config.d.ts +0 -82
- package/dist/modules/mysql/config.js +0 -30
- package/dist/modules/mysql/identities.d.ts +0 -35
- package/dist/modules/mysql/identities.js +0 -43
- package/dist/modules/mysql/index.d.ts +0 -68
- package/dist/modules/mysql/index.js +0 -62
- package/dist/modules/mysql/jobs/index.d.ts +0 -5
- package/dist/modules/mysql/jobs/jobQueue.d.ts +0 -40
- package/dist/modules/mysql/jobs/jobQueue.js +0 -458
- package/dist/modules/mysql/jobs/kv.d.ts +0 -18
- package/dist/modules/mysql/jobs/kv.js +0 -108
- package/dist/modules/mysql/jobs/schema.d.ts +0 -28
- package/dist/modules/mysql/jobs/schema.js +0 -109
- package/dist/modules/mysql/pool.d.ts +0 -3
- package/dist/modules/mysql/pool.js +0 -88
- package/dist/modules/mysql/query.d.ts +0 -12
- package/dist/modules/mysql/query.js +0 -21
- package/dist/modules/mysql/schema.d.ts +0 -43
- package/dist/modules/mysql/schema.js +0 -390
- package/dist/modules/mysql/sessions.d.ts +0 -23
- package/dist/modules/mysql/sessions.js +0 -52
- package/dist/modules/mysql/spaceTokens.d.ts +0 -11
- package/dist/modules/mysql/spaceTokens.js +0 -59
- package/dist/modules/realtime/declarations.d.ts +0 -11
- package/dist/modules/realtime/declarations.js +0 -26
- package/dist/modules/realtime/failure.d.ts +0 -6
- package/dist/modules/realtime/failure.js +0 -11
- package/dist/modules/realtime/grants.d.ts +0 -23
- package/dist/modules/realtime/grants.js +0 -61
- package/dist/modules/realtime/handlers.d.ts +0 -85
- package/dist/modules/realtime/handlers.js +0 -266
- package/dist/modules/realtime/hub.d.ts +0 -71
- package/dist/modules/realtime/hub.js +0 -184
- package/dist/modules/realtime/index.d.ts +0 -75
- package/dist/modules/realtime/index.js +0 -89
- package/dist/modules/realtime/jobs.d.ts +0 -20
- package/dist/modules/realtime/jobs.js +0 -41
- package/dist/modules/realtime/memoryPubSub.d.ts +0 -10
- package/dist/modules/realtime/memoryPubSub.js +0 -43
- package/dist/modules/realtime/message.d.ts +0 -3
- package/dist/modules/realtime/message.js +0 -5
- package/dist/modules/realtime/presence.d.ts +0 -33
- package/dist/modules/realtime/presence.js +0 -56
- package/dist/modules/realtime/redisPubSub.d.ts +0 -24
- package/dist/modules/realtime/redisPubSub.js +0 -36
- package/dist/modules/realtime/retained.d.ts +0 -25
- package/dist/modules/realtime/retained.js +0 -47
- package/dist/modules/realtime/socket.d.ts +0 -30
- package/dist/modules/realtime/socket.js +0 -123
- package/dist/modules/rsc/connectorRscData.js +0 -79
- package/dist/modules/rsc/externalQueryReader.js +0 -43
- package/dist/modules/rsc/handler.js +0 -176
- package/dist/modules/rsc/matchRscPage.js +0 -26
- package/dist/modules/rsc/publicFileResolver.js +0 -73
- package/dist/modules/rsc/resolveRscData.js +0 -146
- package/dist/modules/runtime/bundle.d.ts +0 -29
- package/dist/modules/runtime/bundle.js +0 -117
- package/dist/modules/runtime/contract.d.ts +0 -37
- package/dist/modules/runtime/contract.js +0 -21
- package/dist/modules/runtime/host.d.ts +0 -38
- package/dist/modules/runtime/host.js +0 -68
- package/dist/modules/runtime/inside.d.ts +0 -36
- package/dist/modules/runtime/inside.js +0 -95
- package/dist/modules/runtime/runner.d.ts +0 -12
- package/dist/modules/runtime/runner.js +0 -48
- package/dist/modules/runtime/stages.d.ts +0 -53
- package/dist/modules/runtime/stages.js +0 -117
- package/dist/modules/sqlite/jobQueue.d.ts +0 -35
- package/dist/modules/sqlite/jobQueue.js +0 -56
- package/dist/modules/sqlite/kv.d.ts +0 -34
- package/dist/modules/sqlite/kv.js +0 -91
- package/dist/modules/sqlite/open.d.ts +0 -3
- package/dist/modules/sqlite/open.js +0 -13
- package/dist/modules/ssr/Component.js +0 -37
- package/dist/modules/ssr/applySSRResult.js +0 -54
- package/dist/modules/ssr/buildBody.js +0 -35
- package/dist/modules/ssr/handler.js +0 -103
- package/dist/modules/ssr/loadPluginComponents.js +0 -81
- package/dist/modules/ssr/prepareRender.js +0 -333
- package/dist/modules/ssr/preview.js +0 -70
- package/dist/modules/ssr/registerExternalPlugins.js +0 -111
- package/dist/modules/ssr/reportMissingPlugins.js +0 -24
- package/dist/modules/ssr/resolvePageSeo.js +0 -41
- package/dist/modules/ssr/spaceDocument.js +0 -85
- package/dist/modules/ssr/streamBody.js +0 -69
- package/dist/modules/ssr/template.js +0 -10
- package/dist/mongo.d.ts +0 -25
- package/dist/mongo.js +0 -3
- package/dist/mysql.d.ts +0 -37
- package/dist/mysql.js +0 -7
- package/dist/plugins/compile.js +0 -53
- package/dist/plugins/copy.js +0 -28
- package/dist/plugins/detect.js +0 -9
- package/dist/plugins/manager.js +0 -508
- package/dist/plugins/validate.js +0 -23
- package/dist/plugins/watch.js +0 -79
- package/dist/runtime.d.ts +0 -16
- package/dist/runtime.js +0 -7
- package/dist/sqlite.d.ts +0 -24
- package/dist/sqlite.js +0 -3
package/README.md
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
# @plitzi/sdk-server
|
|
2
2
|
|
|
3
|
-
The page server for Plitzi spaces: server-side rendering, React Server Components, plugins, connectors and
|
|
4
|
-
|
|
3
|
+
The page server for Plitzi spaces: server-side rendering, React Server Components, plugins, connectors and signing
|
|
4
|
+
people in. Ships as an HTTP/2 server by default, with support for HTTP/1.1 and HTTP/3.
|
|
5
|
+
|
|
6
|
+
What it is built on — the HTTP server and its pipeline, health and shutdown, checking who a request is — is
|
|
7
|
+
[`@plitzi/sdk-kernel`](../../packages/sdk-kernel/README.md), which every Plitzi server process shares.
|
|
5
8
|
|
|
6
9
|
This package serves **pages**. The AI surface — the MCP server, its tool engine and the draft-preview
|
|
7
|
-
endpoint — lives in [`@plitzi/sdk-mcp`](../mcp/README.md), which depends on this one's narrow
|
|
8
|
-
OAuth, and the renderer for draft preview
|
|
10
|
+
endpoint — lives in [`@plitzi/sdk-mcp`](../mcp/README.md), which runs on the kernel and depends on this one's narrow
|
|
11
|
+
entries alone (OAuth, and the renderer for draft preview), never the other way round. A deployment that only renders pages
|
|
9
12
|
never installs it, and never loads it.
|
|
10
13
|
|
|
11
14
|
## Installation
|
|
@@ -51,7 +54,8 @@ yarn add @plitzi/sdk-authoring # writing spaces is its own package, and it ins
|
|
|
51
54
|
```ts
|
|
52
55
|
// server.ts
|
|
53
56
|
import { authorSpace, container, heading, link, text } from '@plitzi/sdk-authoring';
|
|
54
|
-
import { consoleLogger
|
|
57
|
+
import { consoleLogger } from '@plitzi/sdk-kernel/log';
|
|
58
|
+
import { createJsonAdapters, createServer } from '@plitzi/sdk-server';
|
|
55
59
|
|
|
56
60
|
/** A space is a tree, some CSS and a palette. Ids, class names and the breakpoint maps are derived from it. */
|
|
57
61
|
const space = authorSpace({
|
|
@@ -189,6 +193,15 @@ with every problem (`SpaceRefusedError`): each printed as the report it is, and
|
|
|
189
193
|
its own server — the space gets a page for it at `/plitzi-preview`; a name that is no component or element type is
|
|
190
194
|
refused saying which there are (`SpacePreviewError`).
|
|
191
195
|
|
|
196
|
+
Production runs the project bundled — `bundleProject` of `@plitzi/sdk-server/bundle`, which the project's `build` calls
|
|
197
|
+
(`.plitzi/build.ts`): `dist/main.js`, and the modules the server imports by their path as it runs — the space
|
|
198
|
+
(`dist/space/index.js`) and the runtime (`dist/runtime/index.js`), where `projectModule` looks for them in a built
|
|
199
|
+
project — with what they share in `dist/chunks/`, so the three are one copy of every package. React and the SDK stay in
|
|
200
|
+
`node_modules`: the plugins the server compiles when it starts import them from there, and a second React would draw
|
|
201
|
+
with other contexts. So does a native package, found by its manifest (`gypfile`, a binary, a loader of one), and one
|
|
202
|
+
named in `external` — a package that reads its own files by a path of its own. The plugins and the functions are built
|
|
203
|
+
from their source at boot, as always.
|
|
204
|
+
|
|
192
205
|
The project is the working directory — where every script of its `package.json` runs it, and where a deployment runs
|
|
193
206
|
`node dist/main.js` — never worked out from where a file is: `serveProject` and `authorProjectSpace` refuse to start
|
|
194
207
|
anywhere else, naming what is missing (`package.json`, `src/`; `projectRoot` of `@plitzi/sdk-shared/project`, one
|
|
@@ -272,6 +285,9 @@ what `serveProject` wires itself (see [Projects](#projects)).
|
|
|
272
285
|
| `livePages` | `boolean` | `false` | Every page this server renders listens for what changes under it: new documents for the space it shows, swapped where it stands with its state, scroll and focus kept (`server.updatePages(documents, { draft? })` — a draft's pages hear their own alone), or everything loaded again (`server.reloadPages()`); and it loads again when it reconnects to a server that restarted (a new process), so a change to the server's code reaches the open page. What `serveProject` uses while developing, and `createAuthoringHost` always. With `devMode` too, a plugin whose source changes is built again and swapped where it is drawn on every open page; a plugin whose declaration changed loads the page again. Not turned on by `devMode`: each open page holds a connection for it. |
|
|
273
286
|
| `assetVersion` | `string` | — | Cache-buster appended as `?v=<assetVersion>` to all default SDK asset URLs. Compute from file mtime or package version at startup. |
|
|
274
287
|
| `cacheTtlMs` | `number` | `300000` | TTL in milliseconds for the SSR render cache. Set to `0` to disable. |
|
|
288
|
+
| `renderLimit` | `{ perSpace?: number; waitMs?: number }` | — | How many pages of ONE space this process renders at once, so one space's burst waits behind its own renders instead of taking every render from the others. A kept page takes no turn: what is held back is what costs — a visitor's own page, a draft drawn with its providers' answers, an address no kept page answers (a `?x=<random>` per request). `perSpace` is every space's unless its deployment says its own (`SSRSpaceDeployment.renderLimit`, its plan's); without either a space has no limit. A page past it waits `waitMs` (2000) for a turn, then is answered 503 with `Retry-After: 2` and "This site is busy right now"; the refusals are said once a minute per space, with how many. Per process: four workers render up to four times as many. |
|
|
289
|
+
| `cache` | `SSRCacheConfig` | — | What is kept of rendered pages (`maxBytes`, `staleMs`, `ignoredQueryParams`) and how several replicas keep them in step (`bus`, `store`). See [Render cache](#render-cache). |
|
|
290
|
+
| `earlyHints` | `boolean` | `true` | Says what every page paints with — the SDK's stylesheets — in a `103 Early Hints` before a page is rendered (not before a kept page, answered at once), and as every page's `Link` header (for a CDN that turns it into one). Not the SDK's module: it is asked once the page has painted. `false` sends neither. |
|
|
275
291
|
| `flags` | `Record<string, boolean> \| ({ spaceId, environment }) => Record<string, boolean>` | — | This deployment's say over the spaces' feature flags: above what a space declares, below the SDK's `flags` prop and a tester's dev tools, and only for flags the space declares. A function answers per space. Server actions and RSC resolve with it too. See `docs/en/feature-flags.md` in the workspace. |
|
|
276
292
|
| `loginPath` | `string \| false` | `'/auth/login'` | Path for the built-in login endpoint. Set to `false` to disable it entirely. |
|
|
277
293
|
| `logoutPath` | `string \| false` | `'/auth/logout'` | Path for the built-in logout endpoint. Set to `false` to disable it entirely. |
|
|
@@ -289,17 +305,18 @@ what `serveProject` wires itself (see [Projects](#projects)).
|
|
|
289
305
|
| `ssrOnly` | `boolean` | `false` | Omit client-side JS from the rendered page. Useful for verifying SSR HTML without hydration. |
|
|
290
306
|
| `streaming` | `boolean` | `false` | Stream HTML to the browser incrementally to reduce TTFB. See [Streaming](#streaming). |
|
|
291
307
|
| `middlewares` | `SSRMiddleware[]` | — | Array of custom middleware functions executed before the SSR renderer on every request (see [Custom middlewares](#custom-middlewares)). |
|
|
292
|
-
| `rsc` | `SSRRscConfig` | — | React Server Components endpoint configuration (see [RSC](#react-server-components-rsc)). |
|
|
308
|
+
| `rsc` | `SSRRscConfig` | — | React Server Components endpoint configuration — and `visitorCredentials`, the deployment's own APIs a server provider may ask as the visitor (see [RSC](#react-server-components-rsc) and [Asked as the visitor](#asked-as-the-visitor)). |
|
|
293
309
|
| `realtime` | `{ pubsub?, path?, transport?, allowedOrigins? } \| false` | in memory, at `/_realtime`, `sse` | Realtime channels the space declares. `transport` is what pages connect with: `sse` (a stream, publishes over `POST`) or `websocket` (one socket both ways, HTTP/1.1 only; pages fall back to the stream where a socket cannot open). `allowedOrigins` lists the other origins whose pages may open a socket. `pubsub` is how messages reach other processes — `createMemoryPubSub()` (the default, across workers) or `createRedisPubSub({ publisher, subscriber })` for several replicas. `false` serves no endpoint. See [`docs/en/realtime.md`](../../docs/en/realtime.md). |
|
|
294
310
|
| `compression` | `SSRCompressionConfig \| false` | Brotli, then gzip | Response compression (see [Compression](#compression)). `false` never compresses. |
|
|
295
311
|
| `health` | `SSRHealthConfig` | identity payload | The `/health` endpoint. `check` adds live state per probe and turns it into a readiness probe (see [Health](#health)). |
|
|
312
|
+
| `stats` | `StatsConfig` | none | `GET /_stats` behind `secret`: the process's pool, load, outcomes and health, read by `readPools` (see [Stats](#stats-and-every-process-at-once)). |
|
|
296
313
|
| `adapters` | `SSRAdapters` | — | Required. Adapter callbacks for data fetching. |
|
|
297
314
|
| `logLevel` | `'silent' \| 'error' \| 'warn' \| 'info' \| 'debug'` | `info` with `devMode`, else `error` | How much the server says, for the whole process (see [Logging](#logging)). |
|
|
298
315
|
| `logger` | `ServerLogger` | the console | Where it says it: one structured `ServerLogEvent` stream. `consoleLogger` prints each as one line. |
|
|
299
316
|
| `onListenError` | `(error, { port, host, label }) => void` | exits non-zero | What to do when the server cannot take its port. By default it prints what went wrong and what to do about it, then exits — a process whose server never bound is not running. Supply this to keep it alive and decide yourself. |
|
|
300
317
|
| `workers` | `boolean \| number \| 'auto'` | `'auto'` under `NODE_ENV=production`, else `false` | How many processes serve the port: one per core, a number (lowered to the cores there are), or one. `SDK_SERVER_WORKERS` sets it when the config does not. See [Using every core](#using-every-core). |
|
|
301
318
|
| `action` | `SSRActionConfig` | — | The space's server actions: the write endpoint (`path`, default `/_action`), `lookups` (`ActionLookupsConfig`: `getAction`, `getFunctions`, `getPluginFunctions`, `getData`…), `kv`, `jobs`, `limits`, `email`, `signingSecret`, `onRun` / `onReject`. Absent, the server serves reads only. See `docs/en/server-actions.md` § 13 in the workspace. |
|
|
302
|
-
| `functions` | `{ native?, plugins?, runner?, limits? }` | — | The server's code (`FunctionsConfig` in `@plitzi/sdk-
|
|
319
|
+
| `functions` | `{ native?, measureNative?, plugins?, runner?, limits? }` | — | The server's code (`FunctionsConfig` in `@plitzi/sdk-actions/functions`, checked as the server starts): its own tasks and routes (`native`, from `loadFunctions`), the server halves of the plugins it ships (`plugins`, by plugin type — see [A plugin's server half](#a-plugins-server-half)), the `runner` the spaces' functions run on, and the per-invocation `limits`. `measureNative` says, once per task and limit, an invocation of `native` that spends more than a sandbox would let it — calls to `ctx`, CPU, time, the bytes it answers — never stopping it: `serveProject` turns it on, since a project's functions are a hosted space's. See `docs/en/functions.md` § 8 in the workspace. |
|
|
303
320
|
| `connectors` | `ConnectorLookupsConfig` | — | `getConnector` and `getCredential` for the space's connectors, read by the RSC read path and the `/_action` write endpoint alike. See `docs/en/connectors.md` in the workspace. |
|
|
304
321
|
| `auth` | `Auth` | — | A `createAuth(...)` result: fills the three auth adapters in and brings the cookie naming. See [User authentication](#user-authentication). |
|
|
305
322
|
| `pageAuth` | `Omit<ServerAuth, 'sessionHintCookie'>` | from `auth` | What the rendered pages are told about signing in (`server.auth`): the provider and its endpoints, the hint cookie added per host. Name it when `/auth` is served by another host. |
|
|
@@ -308,7 +325,11 @@ what `serveProject` wires itself (see [Projects](#projects)).
|
|
|
308
325
|
| `exchangePath` | `string \| false` | `'/auth/exchange'` | Where a browser-obtained credential is handed over; served only with the `exchangeCredential` adapter. |
|
|
309
326
|
| `debugMode` | `boolean` | `devMode`, or the space's `devTools` | Authorizes debugging on the pages this server renders. Set, it decides for every space: `false` is a refusal no space turns around. A page loads React's development build only while its visitor has the dev tools on. |
|
|
310
327
|
| `frameOptions` | `'DENY' \| 'SAMEORIGIN' \| string[] \| false` | `'DENY'` | Who may embed the pages in a frame (CSP `frame-ancestors`, and `X-Frame-Options`); `false` omits both headers. A space adapter's `frameAncestors` derives it per space — see [Space adapters](#space-adapters-a-space-per-domain). |
|
|
311
|
-
| `
|
|
328
|
+
| `hsts` | `false \| { maxAge?, includeSubDomains?, preload? }` | a year, `includeSubDomains` | `Strict-Transport-Security` on every response over https. Never on this machine nor on a domain no public CA certifies (`.local`, `.test`, `.localhost`, `.internal`), where it would lock a development certificate out; `preload` only once the domain is submitted to the browsers' list. |
|
|
329
|
+
| `crossOriginOpenerPolicy` | `'same-origin' \| 'same-origin-allow-popups' \| 'unsafe-none' \| false` | `'same-origin-allow-popups'` | `Cross-Origin-Opener-Policy`: a window of another site cannot reach the page through `window.opener`; what the page opens (a payment, another provider's sign-in) still answers it. |
|
|
330
|
+
| `scriptPolicy` | `'report-only' \| 'enforce' \| false` | `'report-only'` | A script policy against cross-site scripting: the template's own scripts carry the render's nonce, and what they load runs (`'strict-dynamic'`); no plugin objects, no `<base>`. `'report-only'` sends it as `Content-Security-Policy-Report-Only` — the browser reports what it would refuse to `/_plitzi/csp-report`, and the server says it in its log (`CSP`), so a space's own scripts (a raw HTML block's) are seen before anything is refused; `'enforce'` refuses them, in the `Content-Security-Policy` that carries `frame-ancestors` too. A domain says its own (`SSRDeploymentSecurity.scriptPolicy`, below). A cached page keeps its render's nonce while it is kept. A page held to either never asks for `eval`: the SDK's store writes without its compiled writers. |
|
|
331
|
+
| `trustedTypes` | `'report-only' \| false` | `'report-only'` | Trusted Types, beside the script policy and always reported: markup reaches the page only through the SDK's named policies (`TRUSTED_TYPES_POLICIES`, `@plitzi/sdk-shared/security`) — what an author wrote (a raw HTML block, rich text, an SVG) through `plitzi-author-html`, cleaned with DOMPurify where the script policy is enforced; text, JSON and a worker of the page's own origin (a `blob:` it made, a file it serves) through `default`. Anything else is reported, which is how a sink nobody named is found. The policy is said on `<html data-plitzi-script-policy>` too, so a copy of the SDK's shared code the SDK does not start (the builder's, a plugin's own) holds itself to it — no `eval` from its store or zod, its author markup cleaned. |
|
|
332
|
+
| `fonts` | `{ baseUrl?, dir?, google? }` | `baseUrl: '/fonts'`, `google` on | Where the font files a space uploaded are addressed, and with `dir` served from this server under `/fonts/*`. `google`: a page's Google families served from this server's own origin (`/_plitzi/fonts/google/…`, asked of Google once and kept within `maxBytes`, 32 MB) — `false` links Google itself. See `docs/en/fonts.md` in the workspace. |
|
|
312
333
|
| `environment` | `'production' \| 'staging' \| 'development' \| 'local'` | `'production'` | The Plitzi tier whose endpoints the rendered pages are handed. |
|
|
313
334
|
| `services` | `{ ssr?, rsc? }` | `ssr` on, `rsc` with `getRscData` | Which request-handling services are mounted. |
|
|
314
335
|
| `preview` / `draftStore` | `SSRPreviewConfig` / `DraftStore` | off / in memory | The draft-preview endpoint (`enabled`, `path` `/__preview`, `secret`, `ttlMs`) and the store behind its tokens — share one across replicas. The rest of draft preview is `@plitzi/sdk-mcp`'s: see its [Draft preview](../mcp/README.md#draft-preview). |
|
|
@@ -336,14 +357,16 @@ type SSRAdapters = {
|
|
|
336
357
|
authenticate?: (credentials: Record<string, string>, req: SSRRequest) => Promise<SSRSession | undefined>;
|
|
337
358
|
endSession?: (req: SSRRequest) => Promise<void>;
|
|
338
359
|
getRscData?: (context: SSRRscContext) => Promise<SSRRscData>;
|
|
360
|
+
recordScriptPolicyReport?: (report: SSRScriptPolicyReport) => Promise<void>;
|
|
339
361
|
};
|
|
340
362
|
```
|
|
341
363
|
|
|
342
364
|
- **`getOfflineData`** — returns the space snapshot (schema, plugins, styles, collections) for SSR.
|
|
343
365
|
- **`getSpaceDeployment`** — resolves which space and environment to render for a given inbound request. Return `{ error: { code, message } }` to abort with an HTTP error. Optionally include `templateProps` to override template variables, or `pluginNames` to activate plugins for the space (see [Plugins](#plugins) and [Template props](#template-props)).
|
|
344
|
-
- **`getUser`** *(optional)* — resolves the authenticated user from the inbound request (e.g. via a session cookie or `Authorization` header). Called in parallel with `getOfflineData` on every cache miss. Return `undefined` for unauthenticated requests. What it returns is inlined into the page — `authenticated`, `user.details`, the access token and its expiry — and that does two things: it decides page-level access for guest vs. registered users during the render, and it **saves the browser its first auth request**. The SDK adopts the inlined session on boot, stores it and schedules the renewal, rather than asking the same authority the same question a few milliseconds later. Implement this one adapter and every server-rendered page starts signed in with no round trip; `createAuth` answers it for you.
|
|
366
|
+
- **`getUser`** *(optional)* — resolves the authenticated user from the inbound request (e.g. via a session cookie or `Authorization` header). Called in parallel with `getOfflineData` on every cache miss. Return `undefined` for unauthenticated requests. Its second argument is the response: a session cookie it finds over for good — revoked, ended, never a token at all, not one the refresh may still renew — it clears there (`createSessionCookies(config).clear(req, res)`), the readable hint with it, or the browser keeps believing it holds a session and a sign-in for signed-out visitors sends it round for ever. `createAuth`'s does. What it returns is inlined into the page — `authenticated`, `user.details`, the access token and its expiry — and that does two things: it decides page-level access for guest vs. registered users during the render, and it **saves the browser its first auth request**. The SDK adopts the inlined session on boot, stores it and schedules the renewal, rather than asking the same authority the same question a few milliseconds later. Implement this one adapter and every server-rendered page starts signed in with no round trip; `createAuth` answers it for you.
|
|
345
367
|
- **`authenticate`** *(optional)* — called when `POST {loginPath}` is received, with the credentials already parsed from the body (a posted form or JSON), whatever fields they are. Return a session to grant one, `undefined` to refuse — and never throw for a wrong password. **Identity only**: the cookies, their lifetimes and the readable hint are the server's, which is what keeps a session established here visible to the API side and the other way round. For a navigation (full-page form submit, `Sec-Fetch-Mode: navigate`) the server answers a `303` so the view re-renders via a GET; for a fetch it answers `200` with `{ success, access_token, expire_at }` or `401` with `{ error, reason }` — never a bodyless status, which leaves a caller holding nothing. This route knows a session and not the account behind it; `createServer({ auth })` serves the same path from the auth kernel instead, which answers the full grant.
|
|
346
368
|
- **`endSession`** *(optional)* — called when `POST {logoutPath}` is received. Revoke the session at the source; the server clears the cookies. Clearing them alone would leave the credential itself working for anyone who had already copied it. A navigation receives a `303` redirect; a fetch receives `204 No Content`.
|
|
369
|
+
- **`recordScriptPolicyReport`** *(optional)* — what a page's script policy refused, or would refuse while it reports (`scriptPolicy`, `trustedTypes`): for the space the report's HOST serves, never one the report names — anyone may post one — and once per space and violation every ten minutes per process, not on every page a visitor opens. Keep them (bounded) to show the space's owner what turning the policy on would stop; without it, the log alone says them.
|
|
347
370
|
- **`getRscData`** *(optional)* — called by the RSC endpoint (`/_rsc`), and once per page render, to fetch server-side data for schema elements with `runtime: 'server'`. Takes one `SSRRscContext`: the request, the space context, the resolved user so authenticated operations are safe, `ids` on a partial refresh (absent means every element), and `loadOfflineData`. That last one is the space itself, shared with the page render happening alongside — await it instead of fetching the schema again, and it is read once per request however many callers ask. Return `{}` when there is no server data for the current request (see [RSC](#react-server-components-rsc)).
|
|
348
371
|
|
|
349
372
|
## Space adapters (a space per domain)
|
|
@@ -353,10 +376,11 @@ more than one space, and getting any of them wrong is a real failure. `createSpa
|
|
|
353
376
|
asks you only for the lookups.
|
|
354
377
|
|
|
355
378
|
```ts
|
|
356
|
-
import { authoringPreview, createSpaceAdapters, verifiedDomain, wildcardSubdomain } from '@plitzi/sdk-server';
|
|
379
|
+
import { authoringPreview, createSpaceAdapters, renderGrant, verifiedDomain, wildcardSubdomain } from '@plitzi/sdk-server';
|
|
357
380
|
|
|
358
381
|
const spaces = createSpaceAdapters({
|
|
359
382
|
resolvers: [
|
|
383
|
+
renderGrant({ resolveGrant: auth.identity.resolveGrant, find: findSpace }),
|
|
360
384
|
authoringPreview({ hosts: platformHosts, resolveGrant: auth.identity.resolveGrant, find: findSpace }),
|
|
361
385
|
wildcardSubdomain({ suffix: 'example.app', find: findSpaceBySlug }),
|
|
362
386
|
verifiedDomain(findDeploymentByDomain)
|
|
@@ -376,15 +400,17 @@ are built in and a fourth is `(req) => …` of your own, which is how a deployme
|
|
|
376
400
|
its proxy sets or by a table nobody else has still gets everything below.
|
|
377
401
|
|
|
378
402
|
**A space is chosen by host or credential, never by the page's path or query.** `getSpaceDeployment` is asked on every
|
|
379
|
-
request, and what a page fetches after it — `/_plitzi/space/<hash>.json`, `/
|
|
403
|
+
request, and what a page fetches after it — `/_plitzi/space/<hash>.json`, `/_plitzi/style/<hash>.css`, `/_action`,
|
|
404
|
+
`/fn/…`, `/_realtime` — carries
|
|
380
405
|
nothing of the page's address but its host: a space chosen by `?space=` or `/s/<id>/` renders its first page and then
|
|
381
406
|
loses everything it asks for. Many spaces on one server are a sub-domain each (`wildcardSubdomain`).
|
|
382
407
|
|
|
383
408
|
| Built in | What it is |
|
|
384
409
|
|---|---|
|
|
385
|
-
| `
|
|
410
|
+
| `renderGrant` | A page that renders the space itself — a site published as files, an embed, a desktop app — asking with the space's public `render` key in `Authorization`, from an origin the key allows. The key names the space; `?environment=` and `?revision=` the version (the live one when none). A visit: metered. Only the header — a key in the address (`?access-token`) is a tool's page and goes on. Put it first. |
|
|
411
|
+
| `authoringPreview` | A credential presented on a host you own: a builder's preview, a tool's page (a thumbnail, a journey). A secret one (`agent`, `host`) is an author's, and the render `authoring` — metering skips it; the space's public key is an author's only when `isAuthor(req, grant)` says so (a session with a role on the space), and otherwise a visit, metered as one — it is in every published page. After `renderGrant`. |
|
|
386
412
|
| `wildcardSubdomain` | `<slug>.example.app`, with no per-space row to configure. Refuses to read a deeper sub-domain as a slug. |
|
|
387
|
-
| `verifiedDomain` | A custom domain, through a row that says it was proven. |
|
|
413
|
+
| `verifiedDomain` | A custom domain, through a row that says it was proven — and what its owner holds its pages to (`security`, below). |
|
|
388
414
|
| `fixedSpace` | Always this one — a single-space deployment, or a catch-all last in the chain. |
|
|
389
415
|
|
|
390
416
|
What it decides for you:
|
|
@@ -394,6 +420,12 @@ What it decides for you:
|
|
|
394
420
|
- **`frame-ancestors` is derived on every resolution**, from the domains the space declared plus your floor.
|
|
395
421
|
Deriving it per branch is how a deployment ends up with one branch that forgets, and that branch serves a space
|
|
396
422
|
framable by anyone.
|
|
423
|
+
- **What a domain's pages are held to is kept with its resolution** — the `security` a row returns
|
|
424
|
+
(`SSRDeploymentSecurity`): `hsts` (`'host'`, `'subdomains'` — every host under it, which on a domain of the owner's
|
|
425
|
+
own reaches hosts you do not serve, so theirs to ask for — or `'off'`), `scriptPolicy` over the server's, and
|
|
426
|
+
`frameAncestors`, the sites that may frame its pages beside the space's own. A domain with any writes its session
|
|
427
|
+
cookies `SameSite=None`, there alone, so a visitor signed in on it is signed in inside those sites' pages too.
|
|
428
|
+
`wildcardSubdomain`'s `find` may return the space's own `scriptPolicy`; the rest of a sub-domain of yours is yours.
|
|
397
429
|
- **Refusals are not cached**, so fixing a row fixes the site rather than fixing it in five minutes.
|
|
398
430
|
- **A resolver that throws is a 404 for that request**, reported through `onError`, not a dead server.
|
|
399
431
|
|
|
@@ -511,7 +543,7 @@ A deployment running the auth kernel needs none of this: `createServer({ auth })
|
|
|
511
543
|
|
|
512
544
|
## What the server does without being asked
|
|
513
545
|
|
|
514
|
-
|
|
546
|
+
What it used to make every deployment declare, each of which it can answer itself:
|
|
515
547
|
|
|
516
548
|
| | |
|
|
517
549
|
|---|---|
|
|
@@ -519,6 +551,8 @@ Four things it used to make every deployment declare, each of which it can answe
|
|
|
519
551
|
| **The transport** | `httpVersion` defaults to HTTP/2 with `tls` and HTTP/1.1 without. No browser speaks cleartext h2, so the old default of `2` meant every local run had to say otherwise |
|
|
520
552
|
| **The audience** | `tokens.audience` defaults to the issuer, which is right for a deployment that is its own audience |
|
|
521
553
|
| **The space** | `createJsonAdapters({ offlineData })` alone resolves to space 1, `main`, revision 0 |
|
|
554
|
+
| **The visitor's scheme** | A `system` theme is drawn as the machine asks — `{{ theme.resolved }}` in a picture's address, a label — from the `Sec-CH-Prefers-Color-Scheme` client hint the page asks Chromium for (`Accept-CH`), or the `theme-scheme` cookie the SDK keeps it in; `light` on a first visit without either. The page cache is keyed by it where the theme defers to the machine |
|
|
555
|
+
| **What a page paints with, first** | The SDK's stylesheets are said in a `103 Early Hints` while the page is still being rendered — the browser has them by the time the HTML arrives — and the head asks for nothing else; the SDK, the plugins and the space's document are asked once the page has painted, so they do not share a phone's network with what the paint waits for. `earlyHints: false` turns the hints off |
|
|
522
556
|
|
|
523
557
|
A page server therefore needs `port`, `adapters`, and nothing else.
|
|
524
558
|
|
|
@@ -547,6 +581,37 @@ createServer({
|
|
|
547
581
|
});
|
|
548
582
|
```
|
|
549
583
|
|
|
584
|
+
### Stats, and every process at once
|
|
585
|
+
|
|
586
|
+
`/health` answers whether a process can serve; **`/_stats`** says how it is doing. Given `stats`, a page server, a worker
|
|
587
|
+
or an MCP server answers `GET /_stats` behind its secret (`Authorization: Bearer <secret>`, 32 characters or more —
|
|
588
|
+
refused at start otherwise): its pool and instance, its version, its load (runs in flight against its slots — `calls`,
|
|
589
|
+
`renders` — CPU, memory, the event loop's p99 delay), how its runs went over the last minute, quarter and hour (failures
|
|
590
|
+
and refusals by reason, p50 and p95), and `healthy` or `degraded` with why. A functions runner answers the same behind
|
|
591
|
+
its protocol's secret, with its `isolates` and the protocol it speaks. Kept in memory, in one-minute buckets.
|
|
592
|
+
|
|
593
|
+
```ts
|
|
594
|
+
createServer({ adapters, stats: { secret: process.env.STATS_SECRET, pool: 'pages' } });
|
|
595
|
+
```
|
|
596
|
+
|
|
597
|
+
`readPools(source)` (`@plitzi/sdk-kernel/stats`) reads every instance's `/_stats` at once and answers one document per
|
|
598
|
+
pool: each instance `healthy`, `degraded` or `down` — one that did not answer, with what its orchestrator knows of why —
|
|
599
|
+
and every version they answered with, so a rolling deploy shows. The pools come from a **pool source**:
|
|
600
|
+
`createLocalPoolSource([{ pool, id, url, secret }])` for processes started where they are known, or a deployment's own
|
|
601
|
+
over its orchestrator. Changing a pool's size is a `PoolScaler`, a contract the kernel defines and ships none of: a
|
|
602
|
+
deployment without one shows its pools read-only.
|
|
603
|
+
|
|
604
|
+
```ts
|
|
605
|
+
import { createLocalPoolSource, readPools } from '@plitzi/sdk-kernel/stats';
|
|
606
|
+
|
|
607
|
+
const health = await readPools(
|
|
608
|
+
createLocalPoolSource([
|
|
609
|
+
{ pool: 'pages', id: 'pages-1', url: 'http://10.0.0.4:8080', secret },
|
|
610
|
+
{ pool: 'worker', id: 'worker-1', url: 'http://10.0.0.5:8892', secret }
|
|
611
|
+
])
|
|
612
|
+
);
|
|
613
|
+
```
|
|
614
|
+
|
|
550
615
|
## Static files
|
|
551
616
|
|
|
552
617
|
Map URL prefixes to local directories:
|
|
@@ -669,24 +734,108 @@ shape a BREACH-style attack needs.
|
|
|
669
734
|
|
|
670
735
|
## Render cache
|
|
671
736
|
|
|
672
|
-
|
|
737
|
+
A published page is kept once rendered, per `(spaceId, environment, revision, hostname, path, query)` and what of the
|
|
738
|
+
visitor changes the document (their session, theme, painted state, forced flags). The `main` environment is never
|
|
739
|
+
kept — it is the development environment and its schema changes all the time — nor a draft preview.
|
|
673
740
|
|
|
674
741
|
```ts
|
|
675
742
|
createServer({
|
|
676
|
-
cacheTtlMs: 60_000,
|
|
743
|
+
cacheTtlMs: 60_000, // how long a page is kept: 5 minutes by default, `0` keeps none
|
|
744
|
+
cache: {
|
|
745
|
+
maxBytes: 256 * 1024 * 1024, // what one process keeps of pages: SDK_SERVER_CACHE_MAX_BYTES, else 128 MB
|
|
746
|
+
staleMs: 30_000, // served this long past its TTL while it is rendered again: 60 s by default
|
|
747
|
+
ignoredQueryParams: ['utm_*', 'ref'] // rendered and kept without these: the analytics ones by default
|
|
748
|
+
},
|
|
677
749
|
adapters: { ... }
|
|
678
750
|
});
|
|
751
|
+
```
|
|
752
|
+
|
|
753
|
+
- **Kept compressed, by bytes, by use.** A page is kept in the encoding the server prefers (`compression`), a 1 MB page
|
|
754
|
+
as the ~90 KB a browser is sent, and the cache is bounded by `cache.maxBytes` — else `SDK_SERVER_CACHE_MAX_BYTES`
|
|
755
|
+
(`512MB`, `2GB`), else 128 MB a process. It is a segmented LRU: a page starts on probation and is protected once it
|
|
756
|
+
is served again, and when room is needed probation gives way first. What was asked for once — a page of a space
|
|
757
|
+
barely visited, every URL a crawler made up — never pushes out what is asked for all the time, whichever space it is
|
|
758
|
+
of: on a server that renders many spaces by host, one that just got busy earns its room from the ones that went
|
|
759
|
+
quiet. The schema data and the RSC answers are kept the same way.
|
|
760
|
+
- **Rendered once.** The requests for a page that arrive while it renders wait for that render instead of starting
|
|
761
|
+
their own — a page a publish invalidated is not rendered once per visitor who asked for it in the meantime.
|
|
762
|
+
- **Served while rendered again.** A page past its TTL is still served for `cache.staleMs`, and rendered again behind
|
|
763
|
+
that request for whoever asks next. An invalidation drops a page outright: a page a write made untrue is never served.
|
|
764
|
+
- **One page whatever the link carried.** The parameters a link carries for analytics (`utm_*`, `fbclid`, `gclid`…,
|
|
765
|
+
`DEFAULT_IGNORED_QUERY_PARAMS`) are left out of the key and of what the page is rendered with — the browser still has
|
|
766
|
+
them — and the others are keyed in one order, so `?b=2&a=1` is the page `?a=1&b=2` is. `[]` keys every parameter.
|
|
767
|
+
|
|
768
|
+
Schema data (`getOfflineData`) is also cached under the same TTL, keyed by `(spaceId, environment, revision)`. This avoids repeated adapter calls on consecutive HTML cache misses for the same space version.
|
|
769
|
+
|
|
770
|
+
Responses say `X-Cache: HIT`, `STALE` (served past its TTL while rendered again) or `MISS`. The cache is cleared and its
|
|
771
|
+
sweep timer is stopped when `server.close()` is called.
|
|
772
|
+
|
|
773
|
+
### The space's stylesheet, linked
|
|
774
|
+
|
|
775
|
+
A space's compiled stylesheet (`style.cache`) holds every page's rules — on a large space most of the page: the
|
|
776
|
+
Plitzi dashboard's was 429 KB of a 496 KB document, compressed again on every response. A server-rendered page links it
|
|
777
|
+
instead, as `/_plitzi/style/<hash>.css`, and carries only what is this request's — the variables, the custom CSS — in
|
|
778
|
+
the page. The file is compressed once, kept by the browser for good under its name, and answered by any replica from
|
|
779
|
+
the space as the request resolves it, as the space document is: a name that is no longer the stylesheet's (the space
|
|
780
|
+
changed since the page was drawn) answers the current one, `no-store`. Taking it out of the page made the dashboard's
|
|
781
|
+
render ~60% cheaper in requests a second.
|
|
782
|
+
|
|
783
|
+
The template links it in the head (`styleSheetPath`), so the page is painted with it from its first frame — linked
|
|
784
|
+
from the body, the content before the link and the styles after it were painted without it, and a theme flashed. The
|
|
785
|
+
document the page reads names it (`style.cacheHref`) with an empty `cache`, and the SDK draws only the rest. It stays
|
|
786
|
+
in the page where no other request could answer for it — a draft preview, a space named by `?access-token` — under a
|
|
787
|
+
deployment's own `templateFn`, which does not know to link it, and when a `{{ token }}` in it is replaced by the
|
|
788
|
+
variables as each request resolves them. A client-side render (no SSR) receives the stylesheet as it always did, and
|
|
789
|
+
draws it; a page whose stylesheet the browser comes to draw itself (new documents in place) drops the linked copy.
|
|
790
|
+
|
|
791
|
+
### A page that renders the space itself
|
|
792
|
+
|
|
793
|
+
`GET /_plitzi/space.json` answers the space as it is now to a page the server did not draw — a site published as
|
|
794
|
+
files, an embed, a desktop app, a page of the space's own host: `{ space, visit }`, the same document a drawn page
|
|
795
|
+
fetches and the decision about this visit (`overQuota`, `quotaNear`, `badge`) that a drawn page is handed in its
|
|
796
|
+
bootstrap. The SDK asks it when it is given no `offlineData`. The space is the one the request resolves to — the host
|
|
797
|
+
(a custom domain, the space's address: no key needed, and no other environment than the host's, which is a `400`
|
|
798
|
+
naming the fix) or the space's `render` key (`renderGrant`), which names the environment and revision with it. Chosen
|
|
799
|
+
by the key, it is answered to the page's origin (CORS, with credentials; the preflight is answered to any origin, the
|
|
800
|
+
request that follows is what is checked) and carries its stylesheet — linked, it would be asked for of the host and
|
|
801
|
+
answered with the host's own space; so does one asked with `?style=carried`, for a space drawn where the page's
|
|
802
|
+
stylesheet does not reach. Every load is a visit, metered as a drawn page is (`adapters.meter`, `page_view`; the cheaper
|
|
803
|
+
one when the space came from the server's copy) and held back as one is (`503`). Kept by the browser and asked again:
|
|
804
|
+
`private, no-cache` with an `ETag`, `304` when nothing changed.
|
|
805
|
+
|
|
806
|
+
### Several replicas
|
|
807
|
+
|
|
808
|
+
A process keeps its own pages, and its workers hear what it is told (`workers`). Replicas share nothing unless the
|
|
809
|
+
server is given what they share — and says at boot which it has:
|
|
810
|
+
|
|
811
|
+
```ts
|
|
812
|
+
import { createRedisPageStore } from '@plitzi/sdk-server';
|
|
813
|
+
import { createRedisPubSub } from '@plitzi/sdk-kernel/pubsub';
|
|
679
814
|
|
|
680
|
-
// Disable caching entirely
|
|
681
815
|
createServer({
|
|
682
|
-
|
|
816
|
+
cache: {
|
|
817
|
+
// How an invalidation reaches every replica: each subscribes, `server.cache.invalidate` publishes.
|
|
818
|
+
bus: createRedisPubSub({ publisher: redis, subscriber: redis.duplicate(), prefix: 'myapp:cache:' }),
|
|
819
|
+
// The pages they share: one a replica never rendered — a new one, after a scale-up or a restart — is served warm.
|
|
820
|
+
store: createRedisPageStore(redis)
|
|
821
|
+
},
|
|
683
822
|
adapters: { ... }
|
|
684
823
|
});
|
|
685
824
|
```
|
|
686
825
|
|
|
687
|
-
|
|
826
|
+
Only a page rendered for nobody in particular goes to the store, under a digest of its key — a signed-in visitor's
|
|
827
|
+
stays in the process that drew it. The store keeps itself under its own budget — `createRedisPageStore(client,
|
|
828
|
+
{ maxBytes })`, else `SDK_SERVER_CACHE_STORE_MAX_BYTES`, else 128 MB — by the same rule as the process's, rather than
|
|
829
|
+
leave it to Redis's eviction: the Redis a deployment runs holds job queues and sessions beside it. A store that cannot answer is a miss, said in the log: the page is rendered, not
|
|
830
|
+
refused. Without a bus, an invalidation reaches the host it was made on, and a deployment of several replicas serves a
|
|
831
|
+
page a write made untrue until each copy expires.
|
|
688
832
|
|
|
689
|
-
|
|
833
|
+
A process that writes a space without serving its pages (an API beside the page servers) says the invalidation with
|
|
834
|
+
`createCacheInvalidator({ bus, store }).invalidate({ spaceId, environment })`.
|
|
835
|
+
|
|
836
|
+
`createRedisPageStore(client, { prefix })` takes ioredis's `getBuffer` and `eval`. Its default prefix carries a hash tag
|
|
837
|
+
(`plitzi:{pages}:`), so on a Redis Cluster the store's keys share a node; give a client without a `keyPrefix` of its
|
|
838
|
+
own, and put any prefix in `prefix` instead.
|
|
690
839
|
|
|
691
840
|
### Cache manager
|
|
692
841
|
|
|
@@ -711,7 +860,18 @@ server.cache?.clear();
|
|
|
711
860
|
console.log(server.cache?.size);
|
|
712
861
|
```
|
|
713
862
|
|
|
714
|
-
`server.cache` is `null` when nothing is cached (`cacheTtlMs: 0` and `rsc.cacheTtlMs: 0`). `size` counts the entries of all three caches.
|
|
863
|
+
`server.cache` is `null` when nothing is cached (`cacheTtlMs: 0` and `rsc.cacheTtlMs: 0`). `size` counts the entries of all three caches. Given `cache.bus` or `cache.store`, an invalidation reaches every replica and the store they share.
|
|
864
|
+
|
|
865
|
+
#### The draft
|
|
866
|
+
|
|
867
|
+
The draft (`main`) is the space being developed right then — in the builder, by an agent, with `plitzi space push` — and
|
|
868
|
+
a page of it is kept only under what it is at: `SSRSpaceDeployment.draftVersion`, which the deployment returns from
|
|
869
|
+
`getSpaceDeployment` (usually its resolvers' `decorate`) and changes with every write that changes what a page of the
|
|
870
|
+
draft draws — its schema, its style, its data, its server code. A new version is a new key: an edit is the next request
|
|
871
|
+
drawn again, on every replica, with nothing to invalidate. Without one — a deployment that cannot say it, a self-hosted
|
|
872
|
+
server, a project of the CLI developing its space — the draft is never kept, and each request draws it. Neither is a
|
|
873
|
+
draft's page drawn with what its server providers answered: the draft's data is never kept (its RSC refresh neither).
|
|
874
|
+
The space read for a render is kept by the same rule, so a page served from the cache reads nothing.
|
|
715
875
|
|
|
716
876
|
#### `CacheFilter`
|
|
717
877
|
|
|
@@ -732,9 +892,9 @@ A compiled plugin is one module and its stylesheet, built as `plitzi plugin pack
|
|
|
732
892
|
Whatever stylesheet the server writes for a plugin — compiled, copied or downloaded — goes into the `plitzi-sdk-plugin` cascade layer (`inPluginLayer` from `@plitzi/sdk-shared/style`), below the space's own: a space's classes and `customCss` win over what the plugin shipped, whatever the specificity. A `css` given as a web path (`/builder-assets/…`) is linked as it is.
|
|
733
893
|
|
|
734
894
|
```ts
|
|
735
|
-
import type { SSRSpaceDeployment } from '@plitzi/sdk-
|
|
895
|
+
import type { SSRSpaceDeployment } from '@plitzi/sdk-kernel/types';
|
|
736
896
|
|
|
737
|
-
const server =
|
|
897
|
+
const server = createPlatform({
|
|
738
898
|
plugins: {
|
|
739
899
|
// From a source file — compiled to ESM with esbuild
|
|
740
900
|
'my-chart': {
|
|
@@ -847,6 +1007,11 @@ When `action` is not set, the server infers it from the `js` value:
|
|
|
847
1007
|
- `.tsx`, `.ts`, `.jsx` extension → `compile` (esbuild, ESM output, React/SDK externalized)
|
|
848
1008
|
- `.js` extension → `copy`
|
|
849
1009
|
|
|
1010
|
+
esbuild runs as a child process of its own (16–26 MiB resident). The server stops it once nothing has built for a
|
|
1011
|
+
minute (`ESBUILD_REST_MS`), and the next build starts it again. A server built on this package that builds with esbuild
|
|
1012
|
+
in the same process calls `esbuildBuild` from `@plitzi/sdk-kernel/build` instead of esbuild's `build`: a build that
|
|
1013
|
+
went to esbuild directly is not counted, and stopping the child would kill it.
|
|
1014
|
+
|
|
850
1015
|
### Plugin serving
|
|
851
1016
|
|
|
852
1017
|
Compiled and copied plugin files are served under `/sdk-plugins/{name}/`:
|
|
@@ -897,11 +1062,12 @@ A plugin can bring server code — its `functions/`, written as a space's functi
|
|
|
897
1062
|
corner of `kv`, none of the space's credentials, channels or data). This server's own plugins hand theirs over by type:
|
|
898
1063
|
|
|
899
1064
|
```ts
|
|
900
|
-
import {
|
|
1065
|
+
import { loadFunctions } from '@plitzi/sdk-actions/functions';
|
|
1066
|
+
import { createPlatform } from '@plitzi/sdk-server/platform';
|
|
901
1067
|
|
|
902
1068
|
const [board] = await loadFunctions(new URL('./plugins/Board/functions/', import.meta.url));
|
|
903
1069
|
|
|
904
|
-
const server =
|
|
1070
|
+
const server = createPlatform({ adapters, functions: { native, plugins: { board } } });
|
|
905
1071
|
|
|
906
1072
|
// While it runs: a server half loaded again — or, with none, taken away — without a restart.
|
|
907
1073
|
server.functions.setPlugin('board', board);
|
|
@@ -959,7 +1125,8 @@ Implement `getRscData` in your adapters to serve data from the `/_rsc` endpoint.
|
|
|
959
1125
|
When `ids` is provided the client is performing a **partial refresh** — only return data for those element IDs. When `ids` is absent, return data for all elements (full fetch):
|
|
960
1126
|
|
|
961
1127
|
```ts
|
|
962
|
-
import type { SSRAdapters, SSRRscContext
|
|
1128
|
+
import type { SSRAdapters, SSRRscContext } from '@plitzi/sdk-kernel/types';
|
|
1129
|
+
import type { SSRRscData } from '@plitzi/sdk-shared';
|
|
963
1130
|
|
|
964
1131
|
const getRscData = async ({ user, ids, loadOfflineData }: SSRRscContext): Promise<SSRRscData> => {
|
|
965
1132
|
// Only serve data when the schema has RSC enabled. `loadOfflineData` joins the read the page render already
|
|
@@ -1026,6 +1193,36 @@ Return `{}` (empty object) when there is no server data for the current request.
|
|
|
1026
1193
|
|
|
1027
1194
|
What a refresh asks for besides the location (`/_rsc?location=…&country=fr`) is `req.ctx.rscParams`; the action resolver hands it to the action over the `input` the element was saved with.
|
|
1028
1195
|
|
|
1196
|
+
### Asked as the visitor
|
|
1197
|
+
|
|
1198
|
+
Providers of one render that ask the same address — with the same headers, the same way — share one request to it:
|
|
1199
|
+
a page whose header and body both read the account is one call, and each provider still gives up on its own timeout
|
|
1200
|
+
(the request stops once none of them waits).
|
|
1201
|
+
|
|
1202
|
+
A server provider whose `query` is an API's address is asked without the visitor's cookies. One that says
|
|
1203
|
+
`credentials: 'include'` is asked WITH them — its page arrives with that visitor's own data (an account's dashboard)
|
|
1204
|
+
instead of drawing empty until the browser has run and asked — where the deployment says so, and nowhere else:
|
|
1205
|
+
|
|
1206
|
+
```ts
|
|
1207
|
+
createServer({
|
|
1208
|
+
rsc: {
|
|
1209
|
+
visitorCredentials: {
|
|
1210
|
+
origins: ['https://api.example.com'], // as the provider's template comes to them
|
|
1211
|
+
via: { 'https://api.example.com': 'http://api.internal:8888' }, // where this server reaches it
|
|
1212
|
+
cookies: ['session'], // the ones carried; every cookie of the page request without it
|
|
1213
|
+
spaces: ({ spaceId }) => ownSpaces.has(spaceId) // a server serving its customers' spaces too: its own alone
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
});
|
|
1217
|
+
```
|
|
1218
|
+
|
|
1219
|
+
The browser sends cookies to an API only when that API's CORS allows the page's site; the page server would send them
|
|
1220
|
+
wherever a document said — so the API and the spaces trusted to ask it are named by whoever runs the server. A provider
|
|
1221
|
+
asking an origin not named, or from a space not trusted, is its error, naming the setting — never asked as a stranger,
|
|
1222
|
+
whose answer is not the one the page was written for. A redirect away from the origin drops the cookies, as the Fetch
|
|
1223
|
+
standard does. A page or a `/_rsc` refresh read so is kept by no cache — not even the same visitor's next visit, which
|
|
1224
|
+
would show what a write a moment ago made untrue (`req.ctx.readAsVisitor`, `Cache-Control: no-store`).
|
|
1225
|
+
|
|
1029
1226
|
### `/_rsc` endpoint
|
|
1030
1227
|
|
|
1031
1228
|
The server automatically registers `GET /_rsc` when `adapters.getRscData` is provided. The endpoint:
|
|
@@ -1097,7 +1294,7 @@ The hook is backed by `RscProvider`, which fetches `/_rsc` once on mount and upd
|
|
|
1097
1294
|
|
|
1098
1295
|
## User authentication
|
|
1099
1296
|
|
|
1100
|
-
Sessions, in one call. `createAuth` takes what only your deployment knows —
|
|
1297
|
+
Sessions, in one call. `createAuth` takes what only your deployment knows — its signing key, what you call your
|
|
1101
1298
|
cookies, and the store your accounts live in — and returns the whole cycle wired together.
|
|
1102
1299
|
|
|
1103
1300
|
```ts
|
|
@@ -1105,11 +1302,20 @@ import { createServer } from '@plitzi/sdk-server';
|
|
|
1105
1302
|
import { createAuth } from '@plitzi/sdk-server/auth';
|
|
1106
1303
|
|
|
1107
1304
|
const auth = createAuth({
|
|
1108
|
-
tokens: {
|
|
1305
|
+
tokens: { keys, issuer: 'https://acme.com', audience: ['https://acme.com'] },
|
|
1306
|
+
secret: process.env.AUTH_SECRET, // signs the CSRF token: 32 characters or more
|
|
1109
1307
|
cookie: { name: 'acme_session' },
|
|
1110
1308
|
adapters: accounts
|
|
1111
1309
|
});
|
|
1310
|
+
```
|
|
1311
|
+
|
|
1312
|
+
Credentials are signed with ES256. `keys` is `{ signing: { kid, privateKey }, verifying: [{ kid, publicKey }] }`, PEM;
|
|
1313
|
+
`generateTokenKeys()` (`@plitzi/sdk-kernel/tokens`) makes a pair, once, for the deployment to keep (its private key as a secret). A process that only
|
|
1314
|
+
checks who a request is — a worker on another machine — is given `verifying` alone, and cannot mint a session even if
|
|
1315
|
+
it is compromised; asked to, it refuses and names the missing key. To rotate, sign with the new key and keep the old
|
|
1316
|
+
one's public key in `verifying` until what it signed has expired.
|
|
1112
1317
|
|
|
1318
|
+
```ts
|
|
1113
1319
|
createServer({ port: 443, adapters: { getOfflineData, getSpaceDeployment }, auth });
|
|
1114
1320
|
```
|
|
1115
1321
|
|
|
@@ -1127,8 +1333,9 @@ server asks for, and carries the cookie naming with it — so there is no second
|
|
|
1127
1333
|
every page it renders where it signs in (`server.auth`: `userProvider: 'basic'`, `loginUrl`, `userUrl`, `logoutUrl`,
|
|
1128
1334
|
`refreshUrl` and `mfaUrl` where offered, and `sessionHintCookie` named for the host), so the space declares nothing. A
|
|
1129
1335
|
setting the space does declare wins, and a space that names another provider ignores the server's altogether. Everything is
|
|
1130
|
-
still exported separately
|
|
1131
|
-
|
|
1336
|
+
still exported separately for a deployment that wants to assemble or replace one piece: signing in (`createAuthApi`,
|
|
1337
|
+
`authRoutes`, …) here, checking who a request is in the kernel — `createTokens` in `@plitzi/sdk-kernel/tokens`,
|
|
1338
|
+
`createIdentity`, `createCsrf` and the session cookies in `@plitzi/sdk-kernel/identity`.
|
|
1132
1339
|
|
|
1133
1340
|
Nothing here assumes a web framework: a request is `{ headers, hostname, cookies?, query?, body? }` and a response is
|
|
1134
1341
|
anything that can carry `Set-Cookie`, both true of bare `node:http`.
|
|
@@ -1161,7 +1368,7 @@ dispatching them is yours:
|
|
|
1161
1368
|
|
|
1162
1369
|
```ts
|
|
1163
1370
|
import { createAuthRouteHandlers } from '@plitzi/sdk-server/handlers';
|
|
1164
|
-
import { parseRequest } from '@plitzi/sdk-
|
|
1371
|
+
import { parseRequest } from '@plitzi/sdk-kernel/http';
|
|
1165
1372
|
|
|
1166
1373
|
const routes = createAuthRouteHandlers({ api: auth.api, cookies: auth.cookies });
|
|
1167
1374
|
const route = routes.find(r => r.method === req.method && `/auth${r.path}` === req.path);
|
|
@@ -1207,18 +1414,19 @@ deployment (single sign-on), `resolveProvider(id, redirectUri)`, a provider reso
|
|
|
1207
1414
|
`providerForEmail(email)`: which one signs an address in, what `GET /sso?email=` answers. A refusal of yours is an
|
|
1208
1415
|
`OAuthFailure(reason, message, detail?)`: the browser lands on its target with `?error=<reason>&detail=<detail>`.
|
|
1209
1416
|
|
|
1210
|
-
### …or don't: `@plitzi/sdk-
|
|
1417
|
+
### …or don't: `@plitzi/sdk-kernel/mysql`
|
|
1211
1418
|
|
|
1212
1419
|
If you are standing a user store up rather than adapting one you have, the table above is ceremony. Import the
|
|
1213
1420
|
store instead — it is every adapter in it, already written, over tables it creates:
|
|
1214
1421
|
|
|
1215
1422
|
```ts
|
|
1216
|
-
import { createMysqlStore } from '@plitzi/sdk-
|
|
1423
|
+
import { createMysqlStore } from '@plitzi/sdk-kernel/mysql';
|
|
1217
1424
|
|
|
1218
1425
|
const store = await createMysqlStore({ url: process.env.DATABASE_URL });
|
|
1219
1426
|
|
|
1220
1427
|
const auth = createAuth({
|
|
1221
|
-
tokens: {
|
|
1428
|
+
tokens: { keys, issuer },
|
|
1429
|
+
secret,
|
|
1222
1430
|
adapters: store.authAdapters, // spread your own on top: { ...store.authAdapters, sendMail }
|
|
1223
1431
|
});
|
|
1224
1432
|
```
|
|
@@ -1262,14 +1470,16 @@ read back, and `GET /auth/session` reports it.
|
|
|
1262
1470
|
|
|
1263
1471
|
Behaviour you do not have to get right yourself: the credential is renewed ahead of expiry and rotated when it is;
|
|
1264
1472
|
signing out revokes at the source rather than only clearing the browser's copy; a readable hint cookie rides beside
|
|
1265
|
-
the session carrying nothing but expiry timestamps, so a page can tell that nobody is signed in without a request
|
|
1473
|
+
the session carrying nothing but expiry timestamps, so a page can tell that nobody is signed in without a request —
|
|
1474
|
+
and a page server that finds the session over (revoked, signed out everywhere) clears it with the cookie, while the
|
|
1475
|
+
browser asks before restoring a token its page's server found nobody for;
|
|
1266
1476
|
and every refusal names a machine-readable `reason`, so a client can tell "renew me" from "you are gone".
|
|
1267
1477
|
|
|
1268
1478
|
### Beyond the defaults
|
|
1269
1479
|
|
|
1270
1480
|
| Config | Effect |
|
|
1271
1481
|
|---|---|
|
|
1272
|
-
| `cookie` | Name, domain, `SameSite`, `Secure`, the refresh path, the hint suffix. Defaults derive from the request host: this machine — loopback, a `.localhost` name, a private network address, its mDNS name (`studio.local`), as a phone on the Wi-Fi opens it over http — gets `SameSite=Lax` with no `Secure` and no `Domain`; any other host `SameSite=
|
|
1482
|
+
| `cookie` | Name, domain, `SameSite`, `Secure`, the refresh path, the hint suffix. Defaults derive from the request host: this machine — loopback, a `.localhost` name, a private network address, its mDNS name (`studio.local`), as a phone on the Wi-Fi opens it over http — gets `SameSite=Lax` with no `Secure` and no `Domain`; any other host `SameSite=Lax; Secure`, shared across its sub-domains — which are one site, so `Lax` reaches them all. `sameSite: 'none'` for a deployment whose pages need the session inside another site's page (a space in an iframe there); a domain that lets other sites frame it (`security.frameAncestors` of its deployment) gets it on that host alone, over https. A deployment that serves spaces of different people on sub-domains of one domain (`*.plitzi.app`) answers `domain` per host — its own hosts `registrableDomain(hostname)`, a space's host `undefined` — or one space's visitor session reaches every other's |
|
|
1273
1483
|
| `api.password` | What a password has to be. `minLength` defaults to 8 (NIST SP 800-63B's floor); `validate` is where a breach-list lookup or a strength estimator goes. Applied wherever one is set — signing up, resetting, changing |
|
|
1274
1484
|
| `api.rateLimit` | May this attempt proceed? **Defaults to an in-memory sliding window**, so no deployment is unthrottled by omission; supply one to put a single counter behind a whole fleet. Called before the password is checked, so a throttled attempt costs no hash |
|
|
1275
1485
|
| `api.adminPermission` | The global capability the `/auth/admin/*` routes require. Default `userManage` |
|
|
@@ -1288,9 +1498,9 @@ write, `04-mysql` over one you do not.
|
|
|
1288
1498
|
|
|
1289
1499
|
### Cross-site request forgery
|
|
1290
1500
|
|
|
1291
|
-
**On by default.** The session cookie defaults to `SameSite=
|
|
1292
|
-
|
|
1293
|
-
|
|
1501
|
+
**On by default.** The session cookie defaults to `SameSite=Lax`, which keeps it off the writes another site causes;
|
|
1502
|
+
a deployment that sets `sameSite: 'none'` — a space embedded in an iframe on somebody else's domain — has the browser
|
|
1503
|
+
attach it to them. That is the attack, and the token answers it whichever the deployment chose.
|
|
1294
1504
|
|
|
1295
1505
|
Two requests can never be forged into whatever they are reaching, and neither is ever asked for a token:
|
|
1296
1506
|
|
|
@@ -1421,7 +1631,7 @@ Credential comparison uses `crypto.timingSafeEqual` to prevent timing attacks. I
|
|
|
1421
1631
|
Register request-scoped middleware to run before the SSR renderer. Middlewares execute in the order they are declared and can short-circuit by not calling `next()`.
|
|
1422
1632
|
|
|
1423
1633
|
```ts
|
|
1424
|
-
import type { SSRMiddleware } from '@plitzi/sdk-
|
|
1634
|
+
import type { SSRMiddleware } from '@plitzi/sdk-kernel/types';
|
|
1425
1635
|
|
|
1426
1636
|
const corsMiddleware: SSRMiddleware = (req, res, next) => {
|
|
1427
1637
|
res.setHeader('Access-Control-Allow-Origin', 'https://app.example.com');
|
|
@@ -1535,11 +1745,12 @@ leave with it. More than one replica needs a queue and a key/value store they sh
|
|
|
1535
1745
|
live in your database; for Mongo and MySQL they are already written, over the connection you already have:
|
|
1536
1746
|
|
|
1537
1747
|
```ts
|
|
1538
|
-
import { closeOnSignals
|
|
1539
|
-
import {
|
|
1748
|
+
import { closeOnSignals } from '@plitzi/sdk-kernel/http';
|
|
1749
|
+
import { createPlatform } from '@plitzi/sdk-server/platform';
|
|
1750
|
+
import { createMongoJobQueue, createMongoKv } from '@plitzi/sdk-actions/mongo';
|
|
1540
1751
|
|
|
1541
1752
|
const db = mongoClient.db('app');
|
|
1542
|
-
const server =
|
|
1753
|
+
const server = createPlatform({
|
|
1543
1754
|
adapters,
|
|
1544
1755
|
action: { lookups, kv: createMongoKv({ db }), jobs: { queue: createMongoJobQueue({ db }) } }
|
|
1545
1756
|
});
|
|
@@ -1555,12 +1766,85 @@ ends any other event stream, lets what is being answered finish, and cuts whatev
|
|
|
1555
1766
|
(`SHUTDOWN_GRACE_MS`). A page left open on a board, or an agent's app listening, no longer holds a Ctrl+C or a
|
|
1556
1767
|
SIGTERM until something kills the process.
|
|
1557
1768
|
|
|
1558
|
-
`@plitzi/sdk-
|
|
1559
|
-
database at all, `kv` survives a restart in a file: `createFileKv` (`@plitzi/sdk-
|
|
1560
|
-
`createSqliteKv` (`@plitzi/sdk-
|
|
1769
|
+
`@plitzi/sdk-actions/mysql` has the same pair over a `mysql2` pool (`createMysqlJobQueue`, `createMysqlKv`). With no
|
|
1770
|
+
database at all, `kv` survives a restart in a file: `createFileKv` (`@plitzi/sdk-actions`, one process, JSON) or
|
|
1771
|
+
`createSqliteKv` (`@plitzi/sdk-actions/sqlite`, any number of processes on the file). Anything
|
|
1561
1772
|
else is the `JobQueue` contract written against your store — see
|
|
1562
1773
|
[server actions § self-hosted](https://github.com/plitzi/plitzi-workspace/blob/main/docs/en/server-actions.md#13-for-a-self-hosted-deployment).
|
|
1563
1774
|
|
|
1775
|
+
## Actions apart from pages (a worker)
|
|
1776
|
+
|
|
1777
|
+
`createServer` serves pages and nothing of the actions engine: `createPlatform` (`@plitzi/sdk-server/platform`) builds
|
|
1778
|
+
the engine — `action`, `functions`, `connectors`, `realtime` — and hands it to the page server, which is what one process
|
|
1779
|
+
serving both runs. Once visitors' calls, webhooks or jobs start to weigh, run them on a worker of their own:
|
|
1780
|
+
`createWorker` (`@plitzi/sdk-actions/worker`), the engine on `@plitzi/sdk-kernel` alone — no page, no RSC, no sign-in. A
|
|
1781
|
+
call is cheap in CPU, but one that reads a large answer holds the event loop every render in flight shares — parsing
|
|
1782
|
+
20 MB takes ~100 ms — and jobs run beside pages.
|
|
1783
|
+
|
|
1784
|
+
```ts
|
|
1785
|
+
import { createWorker } from '@plitzi/sdk-actions/worker';
|
|
1786
|
+
import { createPlatform } from '@plitzi/sdk-server/platform';
|
|
1787
|
+
|
|
1788
|
+
const engine = { action: { lookups, kv, jobs: { queue } }, realtime: { pubsub } };
|
|
1789
|
+
|
|
1790
|
+
// The page server: renders, and runs the actions a page renders with. It sweeps schedules into the queue, but takes
|
|
1791
|
+
// no job from it.
|
|
1792
|
+
const pages = createPlatform({ adapters, auth, ...engine, action: { ...engine.action, jobs: { queue, workers: 0 } } });
|
|
1793
|
+
|
|
1794
|
+
// The worker: `/_action` (calls, webhooks, cancels), `/fn` routes, `/_realtime`, and the jobs. Who a request is comes
|
|
1795
|
+
// from the same identity the page server has.
|
|
1796
|
+
const worker = createWorker({ adapters, identity: auth.ssrIdentityAdapters, ...engine });
|
|
1797
|
+
```
|
|
1798
|
+
|
|
1799
|
+
In front of both, route a space's host by path: `/_action`, `/fn` and `/_realtime` (and what is under them) to the
|
|
1800
|
+
worker, everything else to the page server. The browser sees one origin, so the visitor's session and its CSRF token
|
|
1801
|
+
work unchanged. Give both the same `realtime.pubsub` and the same stores.
|
|
1802
|
+
|
|
1803
|
+
A page server whose pages render no server element naming an action needs no engine at all. It is told where its pages
|
|
1804
|
+
call theirs, and runs nothing of it:
|
|
1805
|
+
|
|
1806
|
+
```ts
|
|
1807
|
+
import { engineOnWorker } from '@plitzi/sdk-actions/worker';
|
|
1808
|
+
import { createServer } from '@plitzi/sdk-server';
|
|
1809
|
+
|
|
1810
|
+
const pages = createServer({ adapters, auth, engine: engineOnWorker(engine) });
|
|
1811
|
+
```
|
|
1812
|
+
|
|
1813
|
+
A page that renders a server element naming an action or a connector can have it resolved on the worker too, so the
|
|
1814
|
+
page server runs no action at all: give the worker a `render.secret` (32 characters or more) and the page server where
|
|
1815
|
+
the worker is and that secret. Each element is asked at the worker's `POST /_render`, with the visitor this server signed
|
|
1816
|
+
in, and comes back with its data — or its error state, a refusal in the action's own words — and the runs that fed it,
|
|
1817
|
+
for a page that debugs. Keep `/_render` off the path a browser reaches: the gateway sends it nothing.
|
|
1818
|
+
|
|
1819
|
+
```ts
|
|
1820
|
+
const worker = createWorker({ adapters, identity, ...engine, render: { secret: RENDER_SECRET } });
|
|
1821
|
+
const pages = createServer({
|
|
1822
|
+
adapters,
|
|
1823
|
+
auth,
|
|
1824
|
+
engine: engineOnWorker({ ...engine, render: { url: 'http://worker:8892', secret: RENDER_SECRET } })
|
|
1825
|
+
});
|
|
1826
|
+
```
|
|
1827
|
+
|
|
1828
|
+
The worker may also be on an origin of its own (`https://actions.example.com`): give both `action.origin`, and the
|
|
1829
|
+
worker the origins of the pages that call it (`action.pageOrigins`). The pages are told the address there and call it
|
|
1830
|
+
with the visitor's cookies; the worker answers those origins with CORS and credentials, takes them as its own in its
|
|
1831
|
+
cross-site check, and refuses any other site — and refuses to start with `origin` and no `pageOrigins`. The session must
|
|
1832
|
+
be readable there (a cookie scoped to a parent domain both share, `authCookie.domain`), and its `getSpaceDeployment`
|
|
1833
|
+
sees the worker's host, not the page's. Only the actions move: a page's `/fn` routes and channels stay on its own origin.
|
|
1834
|
+
|
|
1835
|
+
```ts
|
|
1836
|
+
const engine = { action: { lookups, origin: 'https://actions.example.com' } };
|
|
1837
|
+
|
|
1838
|
+
const pages = createServer({ adapters, auth, engine: engineOnWorker(engine) });
|
|
1839
|
+
const worker = createWorker({
|
|
1840
|
+
adapters,
|
|
1841
|
+
identity: auth.ssrIdentityAdapters,
|
|
1842
|
+
action: { ...engine.action, pageOrigins: ['https://www.example.com'] }
|
|
1843
|
+
});
|
|
1844
|
+
```
|
|
1845
|
+
|
|
1846
|
+
Both ways, as three processes and as two: [`examples/self-hosting/11-actions-on-a-worker`](../../examples/self-hosting/11-actions-on-a-worker).
|
|
1847
|
+
|
|
1564
1848
|
## Running it locally
|
|
1565
1849
|
|
|
1566
1850
|
The package ships a small harness in [`dev/`](./dev) — file-backed adapters over a sample space, three demo
|
|
@@ -1613,7 +1897,7 @@ URLs become `/sdk-assets/plitzi-sdk.js?v=<assetVersion>`. This is separate from
|
|
|
1613
1897
|
By default the server uses its built-in EJS template. You can replace it with any function that receives the template params and returns an HTML string:
|
|
1614
1898
|
|
|
1615
1899
|
```ts
|
|
1616
|
-
import type { SSRTemplateFn } from '@plitzi/sdk-
|
|
1900
|
+
import type { SSRTemplateFn } from '@plitzi/sdk-server';
|
|
1617
1901
|
|
|
1618
1902
|
const templateFn: SSRTemplateFn = ({ html, offlineData, jsPath, cssPath, plugins, react, reactDom, reactDomClient, reactJsx }) => `
|
|
1619
1903
|
<!doctype html>
|
|
@@ -1639,8 +1923,17 @@ The function is called once per render (cache misses only). The built-in `templa
|
|
|
1639
1923
|
What the built-in template does that a custom one has to decide for itself:
|
|
1640
1924
|
|
|
1641
1925
|
- **The space travels beside the page.** The built-in template leaves it out of the payload, names it with
|
|
1642
|
-
`spaceDocumentPath`
|
|
1643
|
-
|
|
1926
|
+
`spaceDocumentPath` and its bootstrap fetches it before it hydrates. A custom template is handed the space inline in
|
|
1927
|
+
`offlineData`, as before.
|
|
1928
|
+
- **The page paints before anything it does not need to paint.** The head asks for the stylesheets alone, and the
|
|
1929
|
+
`Link` header and the `103 Early Hints` for the SDK's; the bootstrap asks for the SDK, the plugins the page draws,
|
|
1930
|
+
React and the space's document once the page has painted (a frame, and the task after it — at once in a tab nobody
|
|
1931
|
+
sees). On a phone's network they shared the line with the stylesheets and the page painted when all had arrived: the
|
|
1932
|
+
dashboard's space page painted at 1.06 s instead of 1.58 s, and hydrated when it did.
|
|
1933
|
+
- **What a visitor does before React listens is kept.** Until the SDK's `render` call nothing answers on the page, which
|
|
1934
|
+
has painted: a tap is made again once the page has hydrated (unless the browser acted on it itself — a link, a
|
|
1935
|
+
field, a box), a form sent is held and sent through the page (by the browser it posted the fields, passwords
|
|
1936
|
+
included, to the page's own address), and what was typed or ticked is put back over what React set the fields to.
|
|
1644
1937
|
- **Only the plugins the page draws are imported up front.** An entry with `deferred` is handed to `render()` as
|
|
1645
1938
|
`{ load: () => import(js), css, declaration }`: the SDK registers it at once and loads its code and stylesheet the
|
|
1646
1939
|
first time one of its elements is drawn. A template that imports every entry statically still works; it only loads
|
|
@@ -1671,7 +1964,7 @@ return {
|
|
|
1671
1964
|
| `jsPath` | `string` | URL for the SDK JS module. Defaults to `/sdk-assets/plitzi-sdk.js`. |
|
|
1672
1965
|
| `cssPath` | `string` | URL for the SDK stylesheet. Defaults to `/sdk-assets/plitzi-sdk.css`. |
|
|
1673
1966
|
| `iconsCssPath` | `string` | URL for Font Awesome's stylesheet, linked after `cssPath`; its fonts are files beside it. Defaults to `/sdk-assets/plitzi-sdk-icons.css`. |
|
|
1674
|
-
| `spaceDocumentPath` | `string` | Where the page fetches the space from (`/_plitzi/space/<hash>.json`),
|
|
1967
|
+
| `spaceDocumentPath` | `string` | Where the page fetches the space from (`/_plitzi/space/<hash>.json`), read by the bootstrap — once the page has painted — before it hydrates. Set by the built-in template's render; absent for a draft preview and for a custom `templateFn`, which receive the space inline in `offlineData`. |
|
|
1675
1968
|
| `builderJsPath` | `string` | URL for the builder JS module. Omitted by default. |
|
|
1676
1969
|
| `builderCssPath` | `string` | URL for the builder stylesheet. Omitted by default. |
|
|
1677
1970
|
| `plugins` | `PluginEntry[]` | Plugin entries to inject. Normally set automatically via `pluginNames`. An entry with `deferred` is one the page draws none of: its declaration, for the browser to load its code when a page that draws it is opened. |
|
|
@@ -1728,7 +2021,7 @@ tells a sink how severe each one is. The run and refusal loggers a deployment wi
|
|
|
1728
2021
|
deployment's adapters can speak through too:
|
|
1729
2022
|
|
|
1730
2023
|
```ts
|
|
1731
|
-
import { serverLog } from '@plitzi/sdk-
|
|
2024
|
+
import { serverLog } from '@plitzi/sdk-kernel/log';
|
|
1732
2025
|
|
|
1733
2026
|
serverLog.warn('Adapters', 'space 12 has no deployment, serving main');
|
|
1734
2027
|
```
|
|
@@ -1783,33 +2076,43 @@ import type {
|
|
|
1783
2076
|
`sessionRenewal` — and what a project types its own options with. `SSRContext` here is the request context a pipeline
|
|
1784
2077
|
stage sees.
|
|
1785
2078
|
|
|
1786
|
-
|
|
2079
|
+
Each type is the package's that owns it. The page server's own configuration and what it answers are this package's;
|
|
2080
|
+
what every server process is built on — the request pipeline, the adapters a deployment answers and what they are
|
|
2081
|
+
asked with — the kernel's; what the browser reads too, `@plitzi/sdk-shared`'s:
|
|
1787
2082
|
|
|
1788
2083
|
```ts
|
|
1789
2084
|
import type {
|
|
1790
|
-
SSRAdapters,
|
|
1791
2085
|
SSRServerConfig,
|
|
2086
|
+
SSRPageServerConfig,
|
|
2087
|
+
SSRServer,
|
|
2088
|
+
SSRTemplateFn,
|
|
2089
|
+
PluginRegistry,
|
|
2090
|
+
CacheFilter,
|
|
2091
|
+
CacheManager
|
|
2092
|
+
} from '@plitzi/sdk-server';
|
|
2093
|
+
import type {
|
|
2094
|
+
SSRAdapters,
|
|
2095
|
+
SSRPageAdapters,
|
|
1792
2096
|
SSRRequest,
|
|
1793
2097
|
SSRResponseHelpers,
|
|
1794
2098
|
SSRMiddleware,
|
|
1795
2099
|
SSRMiddlewareNext,
|
|
1796
2100
|
SSRSpaceDeployment,
|
|
1797
2101
|
SSRTemplateProps,
|
|
1798
|
-
SSRTemplateFn,
|
|
1799
2102
|
SSRCredential,
|
|
1800
|
-
SSRUser,
|
|
1801
2103
|
SSRHeaders,
|
|
1802
2104
|
SSRRscContext,
|
|
2105
|
+
ServerBaseConfig
|
|
2106
|
+
} from '@plitzi/sdk-kernel/types';
|
|
2107
|
+
import type {
|
|
2108
|
+
SSRUser,
|
|
1803
2109
|
SSRRscData,
|
|
1804
|
-
SSRRscConfig,
|
|
1805
|
-
SSRServer,
|
|
1806
2110
|
PluginSource,
|
|
1807
2111
|
PluginSourceFile,
|
|
1808
2112
|
PluginSourceComponent,
|
|
1809
2113
|
PluginAction,
|
|
1810
|
-
PluginEntry
|
|
1811
|
-
PluginRegistry,
|
|
1812
|
-
CacheFilter,
|
|
1813
|
-
CacheManager
|
|
2114
|
+
PluginEntry
|
|
1814
2115
|
} from '@plitzi/sdk-shared';
|
|
1815
2116
|
```
|
|
2117
|
+
|
|
2118
|
+
The engine's — the job queue, `EngineOptions` — are `@plitzi/sdk-actions/types`.
|