@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
|
@@ -0,0 +1,1450 @@
|
|
|
1
|
+
import { $ as visitorScheme, C as createOfflineDataLoader, F as offlineDataWith, I as spaceDocument, N as digest, P as hydrationPayload, Y as offlineDataCacheKeyOf, _ as buildServerInfo, et as readCookie, g as resolveDebugMode, it as requestPaintedState, x as scriptTemplateParams, y as googleFontsUrlOf } from "./core-TlrWmT4B.js";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { fetchOutbound, privateOriginsOf } from "@plitzi/sdk-kernel/outbound";
|
|
4
|
+
import { collectServerElements, isOgType, jsonForScript, mayReceive, notFoundProvider, pageElementTypes, pageHeadTags, pageNotFound, pageSeoText, pageServerContext, pageStructuredData, pageWithheldOf, spaceIdentity, withholdPages } from "@plitzi/sdk-shared/schema";
|
|
5
|
+
import fs from "node:fs/promises";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { requestAuthority, requestOrigin } from "@plitzi/sdk-kernel/http";
|
|
8
|
+
import { serverLog } from "@plitzi/sdk-kernel/log";
|
|
9
|
+
import { flagUserFromSSR, flagValues, requestFlagOverrides, resolveFlags } from "@plitzi/sdk-shared/flags";
|
|
10
|
+
import { getPaths, matchRoutePath } from "@plitzi/sdk-shared/navigation";
|
|
11
|
+
import { IMAGE_PATH, IMAGE_WIDTHS, isImageWidth } from "@plitzi/sdk-shared/helpers";
|
|
12
|
+
import { PREVIEW_COOKIE, PREVIEW_TOKEN_PARAM, SPACE_TOKEN_PARAM, authorizesDebugging, readDraftToken } from "@plitzi/sdk-kernel/identity";
|
|
13
|
+
import { debugCookieName } from "@plitzi/sdk-shared/devTools";
|
|
14
|
+
import { themeFromCookies } from "@plitzi/sdk-shared/theme/cookie";
|
|
15
|
+
import crypto, { createHash } from "node:crypto";
|
|
16
|
+
import { fontUrlResolver, fontsToHead } from "@plitzi/sdk-shared/style";
|
|
17
|
+
import { pathToFileURL } from "node:url";
|
|
18
|
+
import { statSync } from "node:fs";
|
|
19
|
+
import { writeFileAtomic } from "@plitzi/sdk-kernel/files";
|
|
20
|
+
import { renderToString } from "react-dom/server";
|
|
21
|
+
import PlitziSdk from "@plitzi/plitzi-sdk";
|
|
22
|
+
import { jsx } from "react/jsx-runtime";
|
|
23
|
+
import { pluginDeclarationOf, pluginTypesOf } from "@plitzi/sdk-shared/plugins";
|
|
24
|
+
// src/modules/rsc/matchRscPage.ts
|
|
25
|
+
/**
|
|
26
|
+
* The schema's routes, for a visitor signed out and one signed in — made once per schema object, which the adapters
|
|
27
|
+
* hand every render until the space changes (and a visitor's withheld copy is one per group): every page's route was
|
|
28
|
+
* worked out again on every render to match one address against them.
|
|
29
|
+
*/
|
|
30
|
+
var routes = /* @__PURE__ */ new WeakMap();
|
|
31
|
+
var routesOf = (schema, signedIn) => {
|
|
32
|
+
const known = routes.get(schema) ?? {};
|
|
33
|
+
routes.set(schema, known);
|
|
34
|
+
const kept = signedIn ? known.signedIn : known.signedOut;
|
|
35
|
+
if (kept) return kept;
|
|
36
|
+
const pages = schema.pages.reduce((acum, pageId) => {
|
|
37
|
+
const page = schema.flat[pageId];
|
|
38
|
+
if (page) acum[pageId] = page;
|
|
39
|
+
return acum;
|
|
40
|
+
}, {});
|
|
41
|
+
const made = getPaths(pages, schema.pageFolders, signedIn);
|
|
42
|
+
if (signedIn) known.signedIn = made;
|
|
43
|
+
else known.signedOut = made;
|
|
44
|
+
return made;
|
|
45
|
+
};
|
|
46
|
+
var matchRscPage = (schema, path, user) => {
|
|
47
|
+
const { pageId, pathMatch } = matchRoutePath(routesOf(schema, !!user), path, !!user);
|
|
48
|
+
if (!pageId) return;
|
|
49
|
+
return {
|
|
50
|
+
pageId,
|
|
51
|
+
routeParams: pathMatch?.params ?? {}
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
// src/modules/ssr/loadPluginComponents.ts
|
|
55
|
+
/** Module-level cache: the bundle's stamped identity → loaded React component. */
|
|
56
|
+
var componentCache = /* @__PURE__ */ new Map();
|
|
57
|
+
/**
|
|
58
|
+
* When the bundle behind an entry was built, taken from the URL the page is told to load.
|
|
59
|
+
*
|
|
60
|
+
* The manager stamps that URL for the browser's benefit — the assets are served `immutable`, so a rebuilt plugin
|
|
61
|
+
* needs a new URL to reach anyone — and the server needs exactly the same fact for exactly the same reason: Node's
|
|
62
|
+
* ESM registry caches a module by URL for the life of the process, and a rebuild lands back on the same path. Reading
|
|
63
|
+
* the stamp the manager already publishes keeps the two sides on one answer instead of inventing a second one.
|
|
64
|
+
*
|
|
65
|
+
* Without it a dev server renders the component it imported when it started while the browser loads the rebuilt one,
|
|
66
|
+
* and the two disagree about the markup — which React reports as a hydration mismatch and answers by throwing away
|
|
67
|
+
* the whole tree, taking the panels beside it with it.
|
|
68
|
+
*/
|
|
69
|
+
var stampOf = (entry) => {
|
|
70
|
+
const at = entry.js?.indexOf("?v=") ?? -1;
|
|
71
|
+
return at === -1 ? "" : entry.js.slice(at + 3);
|
|
72
|
+
};
|
|
73
|
+
/** Bumped on invalidation and appended to the import URL. Node's ESM registry caches a module by URL for the
|
|
74
|
+
* life of the process — clearing the Map above is not enough, since a rebuilt plugin lands back on the same
|
|
75
|
+
* path and `import()` would hand back the module loaded before it. A changed URL is the only way to re-read.
|
|
76
|
+
* Stays at 0 until something actually invalidates, so a normal render imports the plain path and every
|
|
77
|
+
* subsequent one hits Node's cache. Superseded generations stay resident: the registry has no eviction, which
|
|
78
|
+
* is the price of reloading at all and why this is driven by explicit invalidation rather than per-request. */
|
|
79
|
+
var generation = 0;
|
|
80
|
+
var importUrl = (filePath, stamp) => generation === 0 && !stamp ? filePath : `${pathToFileURL(filePath).href}?v=${stamp}&g=${generation}`;
|
|
81
|
+
/**
|
|
82
|
+
* Plugins that failed to import (e.g. browser-only code like `document`).
|
|
83
|
+
* These are permanently skipped on the server and fall through to client-side rendering.
|
|
84
|
+
*/
|
|
85
|
+
var failedImports = /* @__PURE__ */ new Set();
|
|
86
|
+
/**
|
|
87
|
+
* Dynamically imports plugin components from their compiled filesystem paths and returns
|
|
88
|
+
* a Record<keyName, FC> suitable for passing to <PlitziSdk.Plugin>.
|
|
89
|
+
*
|
|
90
|
+
* File-source plugins are cached by filePath so subsequent requests skip the import().
|
|
91
|
+
* Plugins that fail to import are added to a permanent skip-list — they are not retried
|
|
92
|
+
* and will be rendered client-side instead.
|
|
93
|
+
* Component-source plugins (already in memory via getComponents()) are merged in directly.
|
|
94
|
+
*/
|
|
95
|
+
var loadPluginComponents = async (entries, inlineComponents) => {
|
|
96
|
+
const result = {};
|
|
97
|
+
if (inlineComponents) for (const [key, component] of Object.entries(inlineComponents)) result[key] = {
|
|
98
|
+
component,
|
|
99
|
+
props: {}
|
|
100
|
+
};
|
|
101
|
+
await Promise.all(entries.filter((e) => e.filePath).map(async (e) => {
|
|
102
|
+
const filePath = e.filePath;
|
|
103
|
+
if (failedImports.has(filePath)) return;
|
|
104
|
+
const cacheKey = importUrl(filePath, stampOf(e));
|
|
105
|
+
let component = componentCache.get(cacheKey);
|
|
106
|
+
if (!component) try {
|
|
107
|
+
const mod = await import(cacheKey);
|
|
108
|
+
component = mod.default ?? mod;
|
|
109
|
+
componentCache.set(cacheKey, component);
|
|
110
|
+
} catch (err) {
|
|
111
|
+
serverLog.warn("SSR", `Plugin "${e.keyName}" cannot be imported server-side, falling back to client rendering`, err);
|
|
112
|
+
failedImports.add(filePath);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
result[e.keyName] = {
|
|
116
|
+
component,
|
|
117
|
+
props: e.props
|
|
118
|
+
};
|
|
119
|
+
}));
|
|
120
|
+
return result;
|
|
121
|
+
};
|
|
122
|
+
/** Drop the loaded-component and failed-import caches and force the next import to re-read from disk. A plugin
|
|
123
|
+
* rebuilt at the SAME version lands back on the same path, so without this an invalidation refreshes the build
|
|
124
|
+
* on disk while every render keeps serving the component imported before it. The plugin manager owns its own
|
|
125
|
+
* caches and cannot reach these, which is why invalidation has to clear both sides. */
|
|
126
|
+
var invalidatePluginComponentCache = () => {
|
|
127
|
+
componentCache.clear();
|
|
128
|
+
failedImports.clear();
|
|
129
|
+
generation += 1;
|
|
130
|
+
};
|
|
131
|
+
// src/modules/ssr/preview.ts
|
|
132
|
+
/** The READ side of draft-preview: a render resolving a stashed draft from its token. The write side — applying
|
|
133
|
+
* unsaved operations and rendering the result — lives in `@plitzi/sdk-mcp`, which is what knows how to interpret an
|
|
134
|
+
* operation; a page-only deployment keeps this much and never loads that. */
|
|
135
|
+
/** Every method of the store, for the copy a server's workers share (`FleetStores`, `core/server/fleet/link.ts`). */
|
|
136
|
+
var DRAFT_STORE_METHODS = {
|
|
137
|
+
put: true,
|
|
138
|
+
take: true,
|
|
139
|
+
drop: true
|
|
140
|
+
};
|
|
141
|
+
/** In-memory draft store — the default when the consumer injects none. Fine for a single replica; a multi-replica
|
|
142
|
+
* deployment must inject a shared store so a preview URL resolves on any replica. */
|
|
143
|
+
var createMemoryDraftStore = () => {
|
|
144
|
+
const store = /* @__PURE__ */ new Map();
|
|
145
|
+
return {
|
|
146
|
+
put(token, data, { ttlMs, reusable = false, spaceId, inspected = false }) {
|
|
147
|
+
store.set(token, {
|
|
148
|
+
data,
|
|
149
|
+
expiresAt: Date.now() + ttlMs,
|
|
150
|
+
reusable,
|
|
151
|
+
spaceId,
|
|
152
|
+
inspected
|
|
153
|
+
});
|
|
154
|
+
},
|
|
155
|
+
take(token) {
|
|
156
|
+
const hit = store.get(token);
|
|
157
|
+
if (!hit) return;
|
|
158
|
+
if (!hit.reusable || hit.expiresAt <= Date.now()) store.delete(token);
|
|
159
|
+
return hit.expiresAt > Date.now() ? {
|
|
160
|
+
data: hit.data,
|
|
161
|
+
reusable: hit.reusable,
|
|
162
|
+
spaceId: hit.spaceId,
|
|
163
|
+
...hit.inspected ? { inspected: true } : {}
|
|
164
|
+
} : void 0;
|
|
165
|
+
},
|
|
166
|
+
drop(token) {
|
|
167
|
+
store.delete(token);
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
};
|
|
171
|
+
/**
|
|
172
|
+
* Resolve the draft this request is looking at, if any.
|
|
173
|
+
*
|
|
174
|
+
* Returns undefined on a normal request (renders persisted state) and on a token the store no longer has — expired,
|
|
175
|
+
* dropped, or a one-shot that has already been rendered once.
|
|
176
|
+
*/
|
|
177
|
+
var takeDraftOverride = async (req, config) => {
|
|
178
|
+
const token = readDraftToken(req);
|
|
179
|
+
if (!token || !config.draftStore) return;
|
|
180
|
+
const entry = await config.draftStore.take(token);
|
|
181
|
+
if (!entry || entry.spaceId !== req.ctx.spaceDeployment?.spaceId) return;
|
|
182
|
+
return {
|
|
183
|
+
data: entry.data,
|
|
184
|
+
reusable: entry.reusable,
|
|
185
|
+
inspected: entry.inspected === true,
|
|
186
|
+
token
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
/** The `Set-Cookie` that carries a draft session through the rest of the visit. */
|
|
190
|
+
var draftSessionCookie = (req, token, ttlMs) => [
|
|
191
|
+
`${PREVIEW_COOKIE}=${encodeURIComponent(token)}`,
|
|
192
|
+
"Path=/",
|
|
193
|
+
"HttpOnly",
|
|
194
|
+
"SameSite=Lax",
|
|
195
|
+
`Max-Age=${Math.max(0, Math.floor(ttlMs / 1e3))}`,
|
|
196
|
+
...req.protocol === "https" ? ["Secure"] : []
|
|
197
|
+
].join("; ");
|
|
198
|
+
// src/core/services/resolve.ts
|
|
199
|
+
var resolveServices = (config) => {
|
|
200
|
+
const services = config.services ?? {};
|
|
201
|
+
return {
|
|
202
|
+
ssr: services.ssr ?? true,
|
|
203
|
+
rsc: services.rsc ?? !!config.adapters.getRscData
|
|
204
|
+
};
|
|
205
|
+
};
|
|
206
|
+
var resolveRscEndpoint = (config) => {
|
|
207
|
+
if (!resolveServices(config).rsc || !(config.rsc?.enabled ?? true) || !config.adapters.getRscData) return;
|
|
208
|
+
return config.rsc?.path ?? "/_rsc";
|
|
209
|
+
};
|
|
210
|
+
// src/modules/ssr/meterPage.ts
|
|
211
|
+
var meterPage = async (req, config, spaceId, environment, revision, cached) => {
|
|
212
|
+
if (!config.adapters.meter) return;
|
|
213
|
+
const started = config.devMode ? performance.now() : 0;
|
|
214
|
+
try {
|
|
215
|
+
return await config.adapters.meter({
|
|
216
|
+
kind: "page_view",
|
|
217
|
+
cached,
|
|
218
|
+
req,
|
|
219
|
+
spaceId,
|
|
220
|
+
environment,
|
|
221
|
+
revision
|
|
222
|
+
});
|
|
223
|
+
} catch {
|
|
224
|
+
return;
|
|
225
|
+
} finally {
|
|
226
|
+
if (config.devMode) req.ctx.timings = [...req.ctx.timings ?? [], {
|
|
227
|
+
name: "meter",
|
|
228
|
+
dur: Math.round(performance.now() - started)
|
|
229
|
+
}];
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
// src/modules/ssr/spaceDocument.ts
|
|
233
|
+
/**
|
|
234
|
+
* The whole space as a resource of its own, beside the page rather than inside it.
|
|
235
|
+
*
|
|
236
|
+
* Embedded, it was most of every document — megabytes of a big space, before the first word of the page — and it was
|
|
237
|
+
* downloaded again on every page and every visit. Apart, the page arrives at the size of what it shows, and the space
|
|
238
|
+
* is fetched while the scripts are, once: its address is its content's hash, so it is kept until it changes.
|
|
239
|
+
*
|
|
240
|
+
* It is still the whole space: the server draws the first page, and every page after it is the browser's, with no
|
|
241
|
+
* server to ask.
|
|
242
|
+
*/
|
|
243
|
+
var SPACE_DOCUMENT_PATH = "/_plitzi/space/";
|
|
244
|
+
/** The space as it is now, for a page that renders it itself rather than one the server drew (`handleCurrentSpace`). */
|
|
245
|
+
var CURRENT_SPACE_PATH = "/_plitzi/space.json";
|
|
246
|
+
var DOCUMENT_PATH = /^\/_plitzi\/space\/([\w-]{1,64})\.json$/;
|
|
247
|
+
/**
|
|
248
|
+
* The documents this process just put in a page, so the request that follows is answered without reading the space
|
|
249
|
+
* again. Bounded: a document is megabytes, and only the latest of each space is ever asked for twice.
|
|
250
|
+
*/
|
|
251
|
+
var RECENT = 8;
|
|
252
|
+
var recent = /* @__PURE__ */ new Map();
|
|
253
|
+
var recentKey = (spaceId, environment, hash) => `${String(spaceId)}|${environment}|${hash}`;
|
|
254
|
+
/** Where the page fetches `document` from — and the promise that this process can answer it. */
|
|
255
|
+
var publishSpaceDocument = (spaceId, environment, document, kept = []) => {
|
|
256
|
+
const key = recentKey(spaceId, environment, document.hash);
|
|
257
|
+
recent.delete(key);
|
|
258
|
+
recent.set(key, {
|
|
259
|
+
json: document.json,
|
|
260
|
+
kept
|
|
261
|
+
});
|
|
262
|
+
for (const oldest of recent.keys()) {
|
|
263
|
+
if (recent.size <= RECENT) break;
|
|
264
|
+
recent.delete(oldest);
|
|
265
|
+
}
|
|
266
|
+
return `${SPACE_DOCUMENT_PATH}${document.hash}.json`;
|
|
267
|
+
};
|
|
268
|
+
var sendNoData = (res, spaceId, environment) => {
|
|
269
|
+
res.setStatus(404);
|
|
270
|
+
res.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
271
|
+
res.send(JSON.stringify({
|
|
272
|
+
error: `This request resolves to space ${String(spaceId)} (${environment}), which has no data: getSpaceDeployment chose it from what this request carries — its host and credentials, never the page’s path or query`,
|
|
273
|
+
reason: "not_found"
|
|
274
|
+
}));
|
|
275
|
+
};
|
|
276
|
+
/**
|
|
277
|
+
* The space this request resolves to, as this visitor may be sent it — the pages they may not see emptied — and
|
|
278
|
+
* published, so the page that names it next is answered without reading the space again. Kept as a page render keeps
|
|
279
|
+
* it (`prepareRender`): an environment that is not the live draft is read once per version, and `cached` says this
|
|
280
|
+
* request was answered from that copy — the cheaper visit, as a page served from the cache is.
|
|
281
|
+
*/
|
|
282
|
+
var documentNow = async (req, config, offlineDataCache, { linkStyle }) => {
|
|
283
|
+
const { environment = "main", revision = 0 } = req.ctx.spaceDeployment ?? {};
|
|
284
|
+
const spaceId = req.ctx.spaceDeployment?.spaceId ?? 1;
|
|
285
|
+
const cacheKey = offlineDataCacheKeyOf(req.ctx.spaceDeployment);
|
|
286
|
+
const held = cacheKey ? offlineDataCache?.get(cacheKey) : void 0;
|
|
287
|
+
const offlineData = held ?? await config.adapters.getOfflineData(spaceId, environment, revision);
|
|
288
|
+
if (!offlineData) return;
|
|
289
|
+
if (cacheKey && !held) offlineDataCache?.set(cacheKey, offlineData);
|
|
290
|
+
const { schema, kept } = withholdPages(offlineData.schema, req.ctx.user);
|
|
291
|
+
const document = spaceDocument(offlineDataWith(offlineData, schema), { linkStyle });
|
|
292
|
+
publishSpaceDocument(spaceId, environment, document, kept);
|
|
293
|
+
return {
|
|
294
|
+
document,
|
|
295
|
+
cached: held !== void 0
|
|
296
|
+
};
|
|
297
|
+
};
|
|
298
|
+
/**
|
|
299
|
+
* Answers `/_plitzi/space/<hash>.json` for the space this host serves, behind the same gates as its pages.
|
|
300
|
+
*
|
|
301
|
+
* Every page of a space already carried all of it, so whoever may open one page may read this. A hash this process
|
|
302
|
+
* did not just publish is looked up from the space as it is now: the same text when another process published it,
|
|
303
|
+
* or the space as it changed since — answered all the same, since it is what the page will find on its next load,
|
|
304
|
+
* but not to be kept under a name that is not its own.
|
|
305
|
+
*/
|
|
306
|
+
var handleSpaceDocument = async (req, res, config, offlineDataCache) => {
|
|
307
|
+
const hash = DOCUMENT_PATH.exec(req.path)?.[1];
|
|
308
|
+
const { environment = "main" } = req.ctx.spaceDeployment ?? {};
|
|
309
|
+
const spaceId = req.ctx.spaceDeployment?.spaceId ?? 1;
|
|
310
|
+
if (!hash) {
|
|
311
|
+
res.setStatus(404);
|
|
312
|
+
res.end();
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
const known = recent.get(recentKey(spaceId, environment, hash));
|
|
316
|
+
let json = known && mayReceive(known.kept, req.ctx.user) ? known.json : void 0;
|
|
317
|
+
let current = json !== void 0;
|
|
318
|
+
if (json === void 0) {
|
|
319
|
+
const found = await documentNow(req, config, offlineDataCache, { linkStyle: !req.query[SPACE_TOKEN_PARAM] });
|
|
320
|
+
if (!found) {
|
|
321
|
+
sendNoData(res, spaceId, environment);
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
json = found.document.json;
|
|
325
|
+
current = found.document.hash === hash;
|
|
326
|
+
}
|
|
327
|
+
res.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
328
|
+
res.setHeader("Cache-Control", current ? `${req.ctx.user ? "private" : "public"}, max-age=31536000, immutable` : "no-store");
|
|
329
|
+
res.send(json);
|
|
330
|
+
};
|
|
331
|
+
/**
|
|
332
|
+
* Lets a page of another origin read the space with its credential: the origins the credential was granted for
|
|
333
|
+
* (`renderGrant` checked the page's against them), never any other. A page this host serves needs none of it.
|
|
334
|
+
*/
|
|
335
|
+
var allowOrigin = (req, res) => {
|
|
336
|
+
const origin = req.headers.origin;
|
|
337
|
+
if (!origin || !req.ctx.spaceDeployment?.grantOrigins) return;
|
|
338
|
+
res.setHeader("Access-Control-Allow-Origin", origin);
|
|
339
|
+
res.setHeader("Access-Control-Allow-Credentials", "true");
|
|
340
|
+
res.setHeader("Vary", "Origin");
|
|
341
|
+
};
|
|
342
|
+
/**
|
|
343
|
+
* The browser's question before a page of another origin sends its credential: answered for any origin, because the
|
|
344
|
+
* answer only lets it ASK — the request that follows is checked against the credential's own origins, and refused there.
|
|
345
|
+
*/
|
|
346
|
+
var answerCurrentSpacePreflight = (req, res) => {
|
|
347
|
+
const origin = req.headers.origin;
|
|
348
|
+
res.setStatus(204);
|
|
349
|
+
if (origin) {
|
|
350
|
+
res.setHeader("Access-Control-Allow-Origin", origin);
|
|
351
|
+
res.setHeader("Access-Control-Allow-Credentials", "true");
|
|
352
|
+
res.setHeader("Access-Control-Allow-Methods", "GET");
|
|
353
|
+
res.setHeader("Access-Control-Allow-Headers", "authorization");
|
|
354
|
+
res.setHeader("Access-Control-Max-Age", "600");
|
|
355
|
+
res.setHeader("Vary", "Origin");
|
|
356
|
+
}
|
|
357
|
+
res.end();
|
|
358
|
+
};
|
|
359
|
+
/**
|
|
360
|
+
* Answers `/_plitzi/space.json`: the space as it is now, for a page that renders it itself — a site published as
|
|
361
|
+
* files, an embed, the desktop app, a page this host serves that was not drawn here. The same document a page drawn
|
|
362
|
+
* here fetches, with the decision about this visit beside it, which such a page is handed in its bootstrap.
|
|
363
|
+
*
|
|
364
|
+
* The space is whichever the request resolves to, as every request here: the host — a custom domain, the space's
|
|
365
|
+
* own address — or the space's `render` credential (`renderGrant`), which names the environment and the revision with
|
|
366
|
+
* it. A space chosen by its credential carries its stylesheet: the page asking may be anywhere, and a stylesheet
|
|
367
|
+
* linked here would be asked for by the host, and answered with the host's own space. So does one asked for with
|
|
368
|
+
* `?style=carried`, by a page drawing the space where its own stylesheet does not reach.
|
|
369
|
+
*
|
|
370
|
+
* A visit: counted as a page drawn here is, and held back as one is. Asked again unchanged, a `304`.
|
|
371
|
+
*/
|
|
372
|
+
var handleCurrentSpace = async (req, res, config, offlineDataCache) => {
|
|
373
|
+
const deployment = req.ctx.spaceDeployment;
|
|
374
|
+
const { environment = "main", revision = 0 } = deployment ?? {};
|
|
375
|
+
const spaceId = deployment?.spaceId ?? 1;
|
|
376
|
+
allowOrigin(req, res);
|
|
377
|
+
res.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
378
|
+
const asked = req.query.environment;
|
|
379
|
+
if (!deployment?.grantOrigins && asked && asked !== environment) {
|
|
380
|
+
res.setStatus(400);
|
|
381
|
+
res.setHeader("Cache-Control", "no-store");
|
|
382
|
+
res.send(JSON.stringify({
|
|
383
|
+
error: `This host serves the ${environment} environment of its space, not ${asked}: ask without one, or for ${asked} with the space's render credential (Authorization: Bearer)`,
|
|
384
|
+
reason: "environment"
|
|
385
|
+
}));
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
const found = await documentNow(req, config, offlineDataCache, { linkStyle: !deployment?.grantOrigins && req.query.style !== "carried" });
|
|
389
|
+
if (!found) {
|
|
390
|
+
sendNoData(res, spaceId, environment);
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
const { document, cached } = found;
|
|
394
|
+
const decision = deployment?.authoring ? void 0 : await meterPage(req, config, spaceId, environment, revision, cached);
|
|
395
|
+
if (decision?.unavailable !== void 0) {
|
|
396
|
+
res.setStatus(503);
|
|
397
|
+
res.setHeader("Cache-Control", "no-store");
|
|
398
|
+
res.send(JSON.stringify({
|
|
399
|
+
error: decision.unavailable,
|
|
400
|
+
reason: "unavailable"
|
|
401
|
+
}));
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
const visit = {
|
|
405
|
+
...decision?.degrade ? { overQuota: true } : {},
|
|
406
|
+
...decision?.quotaNear && !decision.degrade ? { quotaNear: true } : {},
|
|
407
|
+
...decision?.badge ? { badge: decision.badge } : {}
|
|
408
|
+
};
|
|
409
|
+
const visitJson = JSON.stringify(visit);
|
|
410
|
+
const etag = `"${document.hash}.${digest(visitJson)}"`;
|
|
411
|
+
res.setHeader("Cache-Control", "private, no-cache");
|
|
412
|
+
res.setHeader("ETag", etag);
|
|
413
|
+
if (req.headers["if-none-match"] === etag) {
|
|
414
|
+
res.setStatus(304);
|
|
415
|
+
res.end();
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
res.send(`{"space":${document.json},"visit":${visitJson}}`);
|
|
419
|
+
};
|
|
420
|
+
// src/modules/ssr/applySSRResult.ts
|
|
421
|
+
/**
|
|
422
|
+
* What names the render rather than the page: the space (`access-token`, on a host serving many) and the draft (`__pt`).
|
|
423
|
+
* A redirect within the site that dropped them landed on another space, or the live one, without its preview session —
|
|
424
|
+
* a space's journey on a page for signed-in visitors, opened by the server's runner, lost the space it was playing.
|
|
425
|
+
*/
|
|
426
|
+
var RENDER_PARAMS = [SPACE_TOKEN_PARAM, PREVIEW_TOKEN_PARAM];
|
|
427
|
+
/** The render's own parameters the request carried, to keep on a redirect within the site. */
|
|
428
|
+
var renderParamsOf = (query) => RENDER_PARAMS.flatMap((name) => query[name] ? [[name, query[name]]] : []);
|
|
429
|
+
/**
|
|
430
|
+
* `location` with the render's parameters, when it is on this site — a path. An address on another origin is never
|
|
431
|
+
* given them: a space token sent there is a credential handed to somebody else.
|
|
432
|
+
*/
|
|
433
|
+
var withRenderParams = (location, params) => {
|
|
434
|
+
if (params.length === 0 || !location.startsWith("/") || location.startsWith("//")) return location;
|
|
435
|
+
const url = new URL(location, "http://site.invalid");
|
|
436
|
+
for (const [name, value] of params) if (!url.searchParams.has(name)) url.searchParams.set(name, value);
|
|
437
|
+
return `${url.pathname}${url.search}${url.hash}`;
|
|
438
|
+
};
|
|
439
|
+
var applySSRResult = (res, result, kept = []) => {
|
|
440
|
+
if (result.headers) for (const [name, value] of Object.entries(result.headers)) res.setHeader(name, value);
|
|
441
|
+
if (result.redirect !== void 0) {
|
|
442
|
+
res.setStatus(result.status ?? 302);
|
|
443
|
+
res.setHeader("Location", withRenderParams(result.redirect, kept));
|
|
444
|
+
res.send("");
|
|
445
|
+
return true;
|
|
446
|
+
}
|
|
447
|
+
if (result.status !== void 0) res.setStatus(result.status);
|
|
448
|
+
return false;
|
|
449
|
+
};
|
|
450
|
+
/**
|
|
451
|
+
* Whether a render may be kept and served again: only a page that answered 200. A cached page is sent without the
|
|
452
|
+
* status it was rendered with, and a "not found" kept per address would let anybody asking for addresses at random
|
|
453
|
+
* push every real page out of the cache.
|
|
454
|
+
*/
|
|
455
|
+
var isReusable = (result) => result.status === void 0 || result.status === 200;
|
|
456
|
+
/**
|
|
457
|
+
* A page a server provider said shows nothing (`notFound`) answers 404 — unless the render decided something of its
|
|
458
|
+
* own first: a redirect, or a status the navigation set.
|
|
459
|
+
*/
|
|
460
|
+
var withNotFound = (result, notFound) => {
|
|
461
|
+
if (notFound && result.redirect === void 0 && result.status === void 0) result.status = 404;
|
|
462
|
+
};
|
|
463
|
+
/**
|
|
464
|
+
* A page withheld from this visitor answers 401 signed out and 403 signed in without the access — unless the render
|
|
465
|
+
* decided something of its own first: the redirect to signing in a page declares, say.
|
|
466
|
+
*/
|
|
467
|
+
var withRefusal = (result, refused) => {
|
|
468
|
+
if (refused && result.redirect === void 0 && result.status === void 0) result.status = refused === "unauthenticated" ? 401 : 403;
|
|
469
|
+
};
|
|
470
|
+
// src/modules/ssr/Component.tsx
|
|
471
|
+
var Component = ({ server, renderMode = "raw", previewMode = true, offlineData, environment = "main", plugins, ssrResult, sdkDevToolsStylePath, sdkIconsStylePath, debugMode = false, overQuota, quotaNear, badge, theme, scheme, state, serverFlags, forcedFlags }) => {
|
|
472
|
+
const serverWithResult = {
|
|
473
|
+
...server,
|
|
474
|
+
ssr: {
|
|
475
|
+
...server.ssr,
|
|
476
|
+
renderResult: ssrResult
|
|
477
|
+
}
|
|
478
|
+
};
|
|
479
|
+
return /* @__PURE__ */ jsx(PlitziSdk, {
|
|
480
|
+
environment,
|
|
481
|
+
server: serverWithResult,
|
|
482
|
+
previewMode,
|
|
483
|
+
renderMode,
|
|
484
|
+
offlineMode: !!offlineData && Object.keys(offlineData).length > 0,
|
|
485
|
+
offlineData,
|
|
486
|
+
sdkDevToolsStylePath,
|
|
487
|
+
sdkIconsStylePath,
|
|
488
|
+
debugMode,
|
|
489
|
+
...overQuota === void 0 ? {} : { overQuota },
|
|
490
|
+
...quotaNear === void 0 ? {} : { quotaNear },
|
|
491
|
+
...badge === void 0 ? {} : { badge },
|
|
492
|
+
...theme === void 0 ? {} : { theme },
|
|
493
|
+
...scheme === void 0 ? {} : { scheme },
|
|
494
|
+
...state === void 0 ? {} : { state },
|
|
495
|
+
...serverFlags === void 0 ? {} : { serverFlags },
|
|
496
|
+
...forcedFlags === void 0 ? {} : { forcedFlags },
|
|
497
|
+
children: plugins && Object.keys(plugins).map((key) => /* @__PURE__ */ jsx(PlitziSdk.Plugin, {
|
|
498
|
+
renderType: key,
|
|
499
|
+
component: plugins[key].component,
|
|
500
|
+
...plugins[key].props
|
|
501
|
+
}, key))
|
|
502
|
+
});
|
|
503
|
+
};
|
|
504
|
+
// src/modules/ssr/registerExternalPlugins.ts
|
|
505
|
+
var MANIFEST_TTL_MS = 6e5;
|
|
506
|
+
var manifestCache = /* @__PURE__ */ new Map();
|
|
507
|
+
var refreshing = /* @__PURE__ */ new Set();
|
|
508
|
+
var cacheDir;
|
|
509
|
+
var manifestCacheDir = (pluginManager) => {
|
|
510
|
+
cacheDir ??= path.join(pluginManager.outputDir, ".manifest-cache");
|
|
511
|
+
return cacheDir;
|
|
512
|
+
};
|
|
513
|
+
var cacheFilePath = (dir, resource) => path.join(dir, `${crypto.createHash("sha1").update(resource).digest("hex")}.json`);
|
|
514
|
+
var readDiskEntry = async (dir, resource) => {
|
|
515
|
+
try {
|
|
516
|
+
const raw = await fs.readFile(cacheFilePath(dir, resource), "utf-8");
|
|
517
|
+
return JSON.parse(raw);
|
|
518
|
+
} catch {
|
|
519
|
+
return null;
|
|
520
|
+
}
|
|
521
|
+
};
|
|
522
|
+
var writeDiskEntry = async (dir, resource, entry) => {
|
|
523
|
+
try {
|
|
524
|
+
await fs.mkdir(dir, { recursive: true });
|
|
525
|
+
await writeFileAtomic(cacheFilePath(dir, resource), JSON.stringify(entry));
|
|
526
|
+
} catch (err) {
|
|
527
|
+
serverLog.warn("SSR", `Failed to persist plugin manifest cache for ${resource}`, err);
|
|
528
|
+
}
|
|
529
|
+
};
|
|
530
|
+
var fetchAndStore = async (dir, resource, reach) => {
|
|
531
|
+
try {
|
|
532
|
+
const url = `${resource}/plugin-manifest.json`;
|
|
533
|
+
const res = await fetchOutbound(fetch, new URL(url), {}, reach);
|
|
534
|
+
if (!res.ok) {
|
|
535
|
+
serverLog.warn("SSR", `Failed to fetch plugin manifest from ${url}: HTTP ${res.status}`);
|
|
536
|
+
return null;
|
|
537
|
+
}
|
|
538
|
+
const manifest = await res.json();
|
|
539
|
+
const entry = {
|
|
540
|
+
manifest,
|
|
541
|
+
expiresAt: Date.now() + MANIFEST_TTL_MS
|
|
542
|
+
};
|
|
543
|
+
manifestCache.set(resource, entry);
|
|
544
|
+
await writeDiskEntry(dir, resource, entry);
|
|
545
|
+
return manifest;
|
|
546
|
+
} catch (err) {
|
|
547
|
+
serverLog.warn("SSR", `Error fetching plugin manifest from ${resource}`, err);
|
|
548
|
+
return null;
|
|
549
|
+
}
|
|
550
|
+
};
|
|
551
|
+
var revalidate = (dir, resource, reach) => {
|
|
552
|
+
if (refreshing.has(resource)) return;
|
|
553
|
+
refreshing.add(resource);
|
|
554
|
+
fetchAndStore(dir, resource, reach).finally(() => refreshing.delete(resource));
|
|
555
|
+
};
|
|
556
|
+
var fetchManifest = async (pluginManager, resource, reach) => {
|
|
557
|
+
const dir = manifestCacheDir(pluginManager);
|
|
558
|
+
const cached = manifestCache.get(resource) ?? await readDiskEntry(dir, resource) ?? void 0;
|
|
559
|
+
if (cached) {
|
|
560
|
+
manifestCache.set(resource, cached);
|
|
561
|
+
if (cached.expiresAt <= Date.now()) revalidate(dir, resource, reach);
|
|
562
|
+
return cached.manifest;
|
|
563
|
+
}
|
|
564
|
+
return fetchAndStore(dir, resource, reach);
|
|
565
|
+
};
|
|
566
|
+
var resolveAssetUrl = (resource, asset) => {
|
|
567
|
+
if (asset.url) return asset.url;
|
|
568
|
+
if (asset.src) return `${resource}/${asset.src}`;
|
|
569
|
+
return null;
|
|
570
|
+
};
|
|
571
|
+
var findAsset = (manifest, type, resource) => {
|
|
572
|
+
const assets = Object.values(manifest.assets);
|
|
573
|
+
const main = assets.find((a) => a.type === type && a.isMain) ?? assets.find((a) => a.type === type);
|
|
574
|
+
return main ? resolveAssetUrl(resource, main) ?? void 0 : void 0;
|
|
575
|
+
};
|
|
576
|
+
var isAbsoluteUrl = (url) => url.startsWith("http://") || url.startsWith("https://");
|
|
577
|
+
var registerPlugin = async (pluginManager, plugin, reach) => {
|
|
578
|
+
if (!plugin.resource || !isAbsoluteUrl(plugin.resource)) return null;
|
|
579
|
+
const manifest = await fetchManifest(pluginManager, plugin.resource, reach);
|
|
580
|
+
if (!manifest) return null;
|
|
581
|
+
const jsUrl = findAsset(manifest, "script", plugin.resource);
|
|
582
|
+
if (!jsUrl) {
|
|
583
|
+
serverLog.warn("SSR", `Plugin "${plugin.type}" has no JS asset in manifest, skipping`);
|
|
584
|
+
return null;
|
|
585
|
+
}
|
|
586
|
+
const source = {
|
|
587
|
+
js: jsUrl,
|
|
588
|
+
css: findAsset(manifest, "style", plugin.resource),
|
|
589
|
+
action: "cdn",
|
|
590
|
+
version: manifest.version
|
|
591
|
+
};
|
|
592
|
+
return pluginManager.ensure(plugin.type, source);
|
|
593
|
+
};
|
|
594
|
+
/**
|
|
595
|
+
* Reads plugins listed in offlineData.plugins, fetches their manifests, downloads and caches
|
|
596
|
+
* JS/CSS via the PluginManager, and returns the effective plugin keys to pass to getEntries().
|
|
597
|
+
*
|
|
598
|
+
* `registered`: the types this deployment registers itself — a project's own build of a plugin the space also lists
|
|
599
|
+
* on its CDN. Those are never looked for elsewhere: the deployment's copy is the one rendered, and asking the CDN for a
|
|
600
|
+
* manifest nobody will use is a request, and a warning, for nothing.
|
|
601
|
+
*/
|
|
602
|
+
var registerExternalPlugins = async (pluginManager, offlineData, reach = {}, registered = /* @__PURE__ */ new Set()) => {
|
|
603
|
+
const plugins = offlineData?.plugins?.filter((plugin) => !registered.has(plugin.type));
|
|
604
|
+
if (!plugins || plugins.length === 0) return [];
|
|
605
|
+
return (await Promise.all(plugins.map((p) => registerPlugin(pluginManager, p, reach)))).filter((k) => k !== null);
|
|
606
|
+
};
|
|
607
|
+
// src/modules/ssr/reportMissingPlugins.ts
|
|
608
|
+
var reported = /* @__PURE__ */ new Set();
|
|
609
|
+
var customRendersOf = /* @__PURE__ */ new WeakMap();
|
|
610
|
+
/**
|
|
611
|
+
* The plugins a schema's elements render, read once per schema object: the adapters hand every render the same one
|
|
612
|
+
* until the space changes, and walking every element of a large space on each render was a few percent of its CPU.
|
|
613
|
+
*/
|
|
614
|
+
var customRenders = (schema) => {
|
|
615
|
+
const known = customRendersOf.get(schema);
|
|
616
|
+
if (known) return known;
|
|
617
|
+
const renders = /* @__PURE__ */ new Map();
|
|
618
|
+
for (const element of Object.values(schema.flat)) {
|
|
619
|
+
const { renderType, isPlugin, scriptUrl } = element.attributes;
|
|
620
|
+
const loadsItself = isPlugin === true && typeof scriptUrl === "string" && scriptUrl !== "";
|
|
621
|
+
if (element.definition.type !== "custom" || typeof renderType !== "string" || renderType === "" || loadsItself) continue;
|
|
622
|
+
if (!renders.has(renderType)) renders.set(renderType, element.id);
|
|
623
|
+
}
|
|
624
|
+
customRendersOf.set(schema, renders);
|
|
625
|
+
return renders;
|
|
626
|
+
};
|
|
627
|
+
var reportMissingPlugins = (spaceId, schema, available) => {
|
|
628
|
+
if (!schema || !serverLog.enabled("error")) return;
|
|
629
|
+
for (const [renderType, elementId] of customRenders(schema)) {
|
|
630
|
+
const key = `${spaceId}:${renderType}`;
|
|
631
|
+
if (available.has(renderType) || reported.has(key)) continue;
|
|
632
|
+
reported.add(key);
|
|
633
|
+
serverLog.error("SSR", `Space ${String(spaceId)} renders the plugin "${renderType}" (element "${elementId}"), and this server has none by that name, so the page shows "Custom Component ${renderType} Not Found". Register it in \`plugins\` and name it in the deployment's \`pluginNames\`.`);
|
|
634
|
+
}
|
|
635
|
+
};
|
|
636
|
+
// src/modules/ssr/resolvePageSeo.ts
|
|
637
|
+
/**
|
|
638
|
+
* The title and description the addressed page declares for itself.
|
|
639
|
+
*
|
|
640
|
+
* The page element has carried `seoEnabled` / `seoPageTitle` / `seoPageDescription` all along — the builder edits
|
|
641
|
+
* them and the client renders them into the head through Helmet — but the SSR document was built from a constant,
|
|
642
|
+
* so every server-rendered page arrived titled the same. That is the half a crawler and a link preview see, which
|
|
643
|
+
* is the half that matters: they read the document as delivered and never run the client.
|
|
644
|
+
*
|
|
645
|
+
* `seoEnabled: false` returns nothing rather than a default, so the deployment's own title stays in charge of a
|
|
646
|
+
* page that opted out. Blank strings are treated as absent for the same reason — the builder writes one for a
|
|
647
|
+
* field the author cleared, and an empty <title> is worse than a generic one.
|
|
648
|
+
*
|
|
649
|
+
* Either may be a template over the page's server providers and the address (`pageServerContext`): a detail page says
|
|
650
|
+
* the title of the record it shows, in the HTML a crawler reads. One that does not evaluate is nothing, as a blank is.
|
|
651
|
+
* So may each text of its JSON-LD (`pageStructuredData`).
|
|
652
|
+
*/
|
|
653
|
+
var resolvePageSeo = (schema, pageId, context = {}) => {
|
|
654
|
+
if (!schema || !pageId) return {};
|
|
655
|
+
const page = schema.flat[pageId];
|
|
656
|
+
if (!page?.attributes.seoEnabled) return {};
|
|
657
|
+
const title = pageSeoText(page.attributes.seoPageTitle, context);
|
|
658
|
+
const description = pageSeoText(page.attributes.seoPageDescription, context);
|
|
659
|
+
const robots = typeof page.attributes.seoRobots === "string" ? page.attributes.seoRobots.trim() : "";
|
|
660
|
+
const structuredData = pageStructuredData(page.attributes.seoStructuredData, context).map(jsonForScript);
|
|
661
|
+
const image = pageSeoText(page.attributes.seoImage, context);
|
|
662
|
+
const imageAlt = pageSeoText(page.attributes.seoImageAlt, context);
|
|
663
|
+
const { seoType } = page.attributes;
|
|
664
|
+
return {
|
|
665
|
+
...title ? { title } : {},
|
|
666
|
+
...description ? { description } : {},
|
|
667
|
+
...robots ? { robots } : {},
|
|
668
|
+
...structuredData.length > 0 ? { structuredData } : {},
|
|
669
|
+
...image ? { image } : {},
|
|
670
|
+
...image && imageAlt ? { imageAlt } : {},
|
|
671
|
+
...isOgType(seoType) ? { type: seoType } : {}
|
|
672
|
+
};
|
|
673
|
+
};
|
|
674
|
+
// src/modules/images/allowlist.ts
|
|
675
|
+
/**
|
|
676
|
+
* Whether a host is one a picture may come from: named exactly (`images.example.com`), or under a wildcard
|
|
677
|
+
* (`*.example.com` — its subdomains, not `example.com` itself, which is named on its own when it is meant).
|
|
678
|
+
*/
|
|
679
|
+
var isAllowedImageHost = (domains, hostname) => {
|
|
680
|
+
const host = hostname.toLowerCase().replace(/\.$/, "");
|
|
681
|
+
return domains.some((entry) => {
|
|
682
|
+
const domain = entry.toLowerCase().trim();
|
|
683
|
+
if (domain.startsWith("*.")) {
|
|
684
|
+
const parent = domain.slice(2);
|
|
685
|
+
return host.endsWith(`.${parent}`);
|
|
686
|
+
}
|
|
687
|
+
return host === domain;
|
|
688
|
+
});
|
|
689
|
+
};
|
|
690
|
+
// src/modules/images/imageProxy.ts
|
|
691
|
+
/** The formats a picture may arrive in, as the file extension it is kept under. SVG is not one: served from this
|
|
692
|
+
* origin, an SVG is a document that can run script. */
|
|
693
|
+
var SOURCE_TYPES = {
|
|
694
|
+
"image/jpeg": "jpg",
|
|
695
|
+
"image/png": "png",
|
|
696
|
+
"image/gif": "gif",
|
|
697
|
+
"image/webp": "webp",
|
|
698
|
+
"image/avif": "avif"
|
|
699
|
+
};
|
|
700
|
+
var TYPE_OF_EXTENSION = Object.fromEntries(Object.entries(SOURCE_TYPES).map(([type, extension]) => [extension, type]));
|
|
701
|
+
/** The largest picture fetched, and how long fetching it may take. */
|
|
702
|
+
var MAX_SOURCE_BYTES = 15728640;
|
|
703
|
+
var FETCH_TIMEOUT_MS = 1e4;
|
|
704
|
+
/**
|
|
705
|
+
* How long a kept original answers without asking the other site again. Past it the kept files still answer — at once —
|
|
706
|
+
* while the original is asked for with its `ETag` / `Last-Modified`: unchanged, nothing is fetched or resized again.
|
|
707
|
+
*/
|
|
708
|
+
var FRESH_MS = 6048e5;
|
|
709
|
+
/** How long a picture that could not be fetched is not asked for again: a broken address is not a reason to keep asking. */
|
|
710
|
+
var FAILED_MS = 3e5;
|
|
711
|
+
var CACHE_CONTROL = "public, max-age=86400, stale-while-revalidate=604800";
|
|
712
|
+
var HostNotAllowed = class extends Error {};
|
|
713
|
+
var answer = (status, message) => ({
|
|
714
|
+
status,
|
|
715
|
+
headers: {
|
|
716
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
717
|
+
"Cache-Control": "no-store"
|
|
718
|
+
},
|
|
719
|
+
body: message
|
|
720
|
+
});
|
|
721
|
+
/** What a request is answered with when it gets no picture, carried up from wherever it was decided. */
|
|
722
|
+
var Refusal = class extends Error {
|
|
723
|
+
answer;
|
|
724
|
+
constructor(answer) {
|
|
725
|
+
super(String(answer.body));
|
|
726
|
+
this.answer = answer;
|
|
727
|
+
}
|
|
728
|
+
};
|
|
729
|
+
var refuse = (status, message) => new Refusal(answer(status, message));
|
|
730
|
+
/**
|
|
731
|
+
* A vector picture is sent back to where it is: there is no size of it to make, and an SVG served from this origin is a
|
|
732
|
+
* document that can run script. The browser loads it from its own host, as it would without this endpoint.
|
|
733
|
+
*/
|
|
734
|
+
var toOriginal = (source) => new Refusal({
|
|
735
|
+
status: 307,
|
|
736
|
+
headers: {
|
|
737
|
+
Location: source.href,
|
|
738
|
+
"Cache-Control": CACHE_CONTROL
|
|
739
|
+
},
|
|
740
|
+
body: ""
|
|
741
|
+
});
|
|
742
|
+
var isVector = (pathname) => /\.svgz?$/i.test(pathname);
|
|
743
|
+
/** One of each at a time: a second request for what is being made waits for the first. */
|
|
744
|
+
var oneAtATime = () => {
|
|
745
|
+
const running = /* @__PURE__ */ new Map();
|
|
746
|
+
return (key, make) => {
|
|
747
|
+
const known = running.get(key);
|
|
748
|
+
if (known) return known;
|
|
749
|
+
const made = make().finally(() => running.delete(key));
|
|
750
|
+
running.set(key, made);
|
|
751
|
+
return made;
|
|
752
|
+
};
|
|
753
|
+
};
|
|
754
|
+
/** What the browser takes, best first; `original` when it takes neither modern format. */
|
|
755
|
+
var negotiate = (accept) => {
|
|
756
|
+
if (accept.includes("image/avif")) return "avif";
|
|
757
|
+
return accept.includes("image/webp") ? "webp" : "original";
|
|
758
|
+
};
|
|
759
|
+
var FORMATS = [
|
|
760
|
+
"avif",
|
|
761
|
+
"webp",
|
|
762
|
+
"original"
|
|
763
|
+
];
|
|
764
|
+
var isOriginalMeta = (value) => typeof value === "object" && value !== null && "type" in value && typeof value.type === "string" && "checkedAt" in value && typeof value.checkedAt === "number" && "version" in value && typeof value.version === "string";
|
|
765
|
+
var sha = (text) => createHash("sha256").update(text).digest("hex");
|
|
766
|
+
/**
|
|
767
|
+
* Another site's picture, at a width this server makes, in the best format the browser takes.
|
|
768
|
+
*
|
|
769
|
+
* Each original is fetched once and kept, and each size of it is made once from the kept original and kept too: a page
|
|
770
|
+
* asking for eight widths in two formats costs one download and sixteen resizes, ever — not one of each per request,
|
|
771
|
+
* nor again a week later. Past a week the kept files still answer at once while the other site is asked, with the
|
|
772
|
+
* original's `ETag` / `Last-Modified`, whether it changed; only a changed original makes its sizes again.
|
|
773
|
+
*
|
|
774
|
+
* Only from the hosts the deployment allows, with every hop (redirects included) held to the allowlist and to the
|
|
775
|
+
* rule every outbound request is: a picture endpoint that fetched anything would be a way to make this server read
|
|
776
|
+
* its own network.
|
|
777
|
+
*/
|
|
778
|
+
var createImageProxy = (options) => {
|
|
779
|
+
const { domains, cacheDir, transform, outbound, now = Date.now } = options;
|
|
780
|
+
const failedUntil = /* @__PURE__ */ new Map();
|
|
781
|
+
const revalidating = oneAtATime();
|
|
782
|
+
const fetchingOriginal = oneAtATime();
|
|
783
|
+
const resizing = oneAtATime();
|
|
784
|
+
const allowedFetch = (input, init) => {
|
|
785
|
+
const target = new URL(input instanceof Request ? input.url : String(input));
|
|
786
|
+
if (!isAllowedImageHost(domains, target.hostname)) return Promise.reject(new HostNotAllowed(target.hostname));
|
|
787
|
+
return options.fetch(input, init);
|
|
788
|
+
};
|
|
789
|
+
const originalFile = (urlKey, extension) => path.join(cacheDir, "originals", urlKey.slice(0, 2), `${urlKey}.${extension}`);
|
|
790
|
+
const variantKey = (urlKey, version, width, format) => sha(`${urlKey}\n${version}\n${String(width)}\n${format}`);
|
|
791
|
+
const variantFile = (key, extension) => path.join(cacheDir, key.slice(0, 2), `${key}.${extension}`);
|
|
792
|
+
const write = async (file, data) => {
|
|
793
|
+
await fs.mkdir(path.dirname(file), { recursive: true });
|
|
794
|
+
await writeFileAtomic(file, data);
|
|
795
|
+
};
|
|
796
|
+
const readMeta = async (urlKey) => {
|
|
797
|
+
try {
|
|
798
|
+
const parsed = JSON.parse(await fs.readFile(originalFile(urlKey, "json"), "utf-8"));
|
|
799
|
+
return isOriginalMeta(parsed) ? parsed : void 0;
|
|
800
|
+
} catch {
|
|
801
|
+
return;
|
|
802
|
+
}
|
|
803
|
+
};
|
|
804
|
+
const readFile = async (file) => {
|
|
805
|
+
try {
|
|
806
|
+
return await fs.readFile(file);
|
|
807
|
+
} catch {
|
|
808
|
+
return;
|
|
809
|
+
}
|
|
810
|
+
};
|
|
811
|
+
/** A size already made, in whichever type it came out as. */
|
|
812
|
+
const keptVariant = async (key) => {
|
|
813
|
+
for (const [extension, type] of Object.entries(TYPE_OF_EXTENSION)) {
|
|
814
|
+
const body = await readFile(variantFile(key, extension));
|
|
815
|
+
if (body) return {
|
|
816
|
+
body,
|
|
817
|
+
type
|
|
818
|
+
};
|
|
819
|
+
}
|
|
820
|
+
};
|
|
821
|
+
/** The original from the other site — asked conditionally when one is kept. Throws an answer to give back. */
|
|
822
|
+
const fetchOriginal = async (source, kept) => {
|
|
823
|
+
const headers = { accept: "image/avif,image/webp,image/*" };
|
|
824
|
+
if (kept?.etag) headers["if-none-match"] = kept.etag;
|
|
825
|
+
if (kept?.lastModified) headers["if-modified-since"] = kept.lastModified;
|
|
826
|
+
let response;
|
|
827
|
+
try {
|
|
828
|
+
response = await fetchOutbound(allowedFetch, source, {
|
|
829
|
+
headers,
|
|
830
|
+
signal: AbortSignal.timeout(FETCH_TIMEOUT_MS)
|
|
831
|
+
}, outbound);
|
|
832
|
+
} catch (error) {
|
|
833
|
+
throw error instanceof HostNotAllowed ? refuse(403, `The picture moved to ${error.message}, which is not an allowed host.`) : refuse(502, "The picture could not be fetched.");
|
|
834
|
+
}
|
|
835
|
+
if (kept && response.status === 304) {
|
|
836
|
+
await response.body?.cancel();
|
|
837
|
+
return { changed: false };
|
|
838
|
+
}
|
|
839
|
+
const type = (response.headers.get("content-type") ?? "").split(";")[0].trim().toLowerCase();
|
|
840
|
+
if (response.ok && type === "image/svg+xml") {
|
|
841
|
+
await response.body?.cancel();
|
|
842
|
+
throw toOriginal(source);
|
|
843
|
+
}
|
|
844
|
+
if (!response.ok || !Object.hasOwn(SOURCE_TYPES, type)) {
|
|
845
|
+
await response.body?.cancel();
|
|
846
|
+
throw refuse(502, response.ok ? `Not a picture this endpoint serves (${type || "no type"}).` : "The picture could not be fetched.");
|
|
847
|
+
}
|
|
848
|
+
if (Number(response.headers.get("content-length") ?? 0) > MAX_SOURCE_BYTES) {
|
|
849
|
+
await response.body?.cancel();
|
|
850
|
+
throw refuse(413, "The picture is too large.");
|
|
851
|
+
}
|
|
852
|
+
const body = Buffer.from(await response.arrayBuffer());
|
|
853
|
+
if (body.length > MAX_SOURCE_BYTES) throw refuse(413, "The picture is too large.");
|
|
854
|
+
const etag = response.headers.get("etag");
|
|
855
|
+
const lastModified = response.headers.get("last-modified");
|
|
856
|
+
return {
|
|
857
|
+
changed: true,
|
|
858
|
+
body,
|
|
859
|
+
meta: {
|
|
860
|
+
type,
|
|
861
|
+
...etag ? { etag } : {},
|
|
862
|
+
...lastModified ? { lastModified } : {},
|
|
863
|
+
checkedAt: now(),
|
|
864
|
+
version: sha(body).slice(0, 16)
|
|
865
|
+
}
|
|
866
|
+
};
|
|
867
|
+
};
|
|
868
|
+
/** Keeps a new original and its meta, and drops the sizes made from the one it replaces. */
|
|
869
|
+
const keepOriginal = async (urlKey, fetched, previous) => {
|
|
870
|
+
await write(originalFile(urlKey, SOURCE_TYPES[fetched.meta.type]), fetched.body);
|
|
871
|
+
await write(originalFile(urlKey, "json"), JSON.stringify(fetched.meta));
|
|
872
|
+
if (!previous || previous.version === fetched.meta.version) return;
|
|
873
|
+
if (previous.type !== fetched.meta.type) await fs.rm(originalFile(urlKey, SOURCE_TYPES[previous.type]), { force: true });
|
|
874
|
+
const stale = IMAGE_WIDTHS.flatMap((width) => FORMATS.flatMap((format) => {
|
|
875
|
+
const key = variantKey(urlKey, previous.version, width, format);
|
|
876
|
+
return Object.keys(TYPE_OF_EXTENSION).map((extension) => variantFile(key, extension));
|
|
877
|
+
}));
|
|
878
|
+
await Promise.all(stale.map((file) => fs.rm(file, { force: true })));
|
|
879
|
+
};
|
|
880
|
+
/** Asks the other site whether a kept original changed: unchanged costs a header, changed makes new sizes later. */
|
|
881
|
+
const revalidate = (urlKey, source, meta) => revalidating(urlKey, async () => {
|
|
882
|
+
try {
|
|
883
|
+
const fetched = await fetchOriginal(source, meta);
|
|
884
|
+
if (fetched.changed) await keepOriginal(urlKey, fetched, meta);
|
|
885
|
+
else await write(originalFile(urlKey, "json"), JSON.stringify({
|
|
886
|
+
...meta,
|
|
887
|
+
checkedAt: now()
|
|
888
|
+
}));
|
|
889
|
+
} catch {}
|
|
890
|
+
});
|
|
891
|
+
/** The original, kept or fetched: its bytes and its meta. Throws an answer to give back. */
|
|
892
|
+
const original = async (urlKey, source) => {
|
|
893
|
+
const meta = await readMeta(urlKey);
|
|
894
|
+
const body = meta && await readFile(originalFile(urlKey, SOURCE_TYPES[meta.type]));
|
|
895
|
+
if (meta && body) return {
|
|
896
|
+
body,
|
|
897
|
+
meta
|
|
898
|
+
};
|
|
899
|
+
if ((failedUntil.get(urlKey) ?? 0) > now()) throw refuse(502, "The picture could not be fetched a moment ago; it is asked for again in a few minutes.");
|
|
900
|
+
return fetchingOriginal(urlKey, async () => {
|
|
901
|
+
try {
|
|
902
|
+
const fetched = await fetchOriginal(source);
|
|
903
|
+
if (!fetched.changed) throw refuse(502, "The picture could not be fetched.");
|
|
904
|
+
await keepOriginal(urlKey, fetched, meta);
|
|
905
|
+
return fetched;
|
|
906
|
+
} catch (error) {
|
|
907
|
+
if (!(error instanceof Refusal && error.answer.status === 307)) failedUntil.set(urlKey, now() + FAILED_MS);
|
|
908
|
+
throw error;
|
|
909
|
+
}
|
|
910
|
+
});
|
|
911
|
+
};
|
|
912
|
+
/** One size of the original, made once and kept. A GIF is passed through: resizing one keeps its first frame. */
|
|
913
|
+
const makeVariant = (key, source, width, format) => resizing(key, async () => {
|
|
914
|
+
let body = source.body;
|
|
915
|
+
let type = source.meta.type;
|
|
916
|
+
if (transform && type !== "image/gif") try {
|
|
917
|
+
body = await transform(source.body, width, format);
|
|
918
|
+
type = format === "original" ? type : `image/${format}`;
|
|
919
|
+
} catch {
|
|
920
|
+
body = source.body;
|
|
921
|
+
type = source.meta.type;
|
|
922
|
+
}
|
|
923
|
+
await write(variantFile(key, SOURCE_TYPES[type]), body);
|
|
924
|
+
return {
|
|
925
|
+
body,
|
|
926
|
+
type
|
|
927
|
+
};
|
|
928
|
+
});
|
|
929
|
+
return async ({ url, width, accept = "" }) => {
|
|
930
|
+
let source;
|
|
931
|
+
try {
|
|
932
|
+
source = new URL(url ?? "");
|
|
933
|
+
} catch {
|
|
934
|
+
return answer(400, "`url` is the picture’s address.");
|
|
935
|
+
}
|
|
936
|
+
if (source.protocol !== "https:" && source.protocol !== "http:") return answer(400, "`url` is the picture’s web address.");
|
|
937
|
+
const requested = Number(width);
|
|
938
|
+
if (!isImageWidth(requested)) return answer(400, `\`w\` is one of ${IMAGE_WIDTHS.join(", ")}.`);
|
|
939
|
+
if (!isAllowedImageHost(domains, source.hostname)) return answer(403, `${source.hostname} is not one of the hosts this server takes pictures from.`);
|
|
940
|
+
if (isVector(source.pathname)) return toOriginal(source).answer;
|
|
941
|
+
const format = transform ? negotiate(accept) : "original";
|
|
942
|
+
const urlKey = sha(source.href);
|
|
943
|
+
try {
|
|
944
|
+
const kept = await readMeta(urlKey);
|
|
945
|
+
if (kept && now() - kept.checkedAt >= FRESH_MS) revalidate(urlKey, source, kept);
|
|
946
|
+
const made = kept && await keptVariant(variantKey(urlKey, kept.version, requested, format));
|
|
947
|
+
if (made) return {
|
|
948
|
+
status: 200,
|
|
949
|
+
headers: headersOf(made.type),
|
|
950
|
+
body: made.body
|
|
951
|
+
};
|
|
952
|
+
const from = await original(urlKey, source);
|
|
953
|
+
const variant = await makeVariant(variantKey(urlKey, from.meta.version, requested, format), from, requested, format);
|
|
954
|
+
return {
|
|
955
|
+
status: 200,
|
|
956
|
+
headers: headersOf(variant.type),
|
|
957
|
+
body: variant.body
|
|
958
|
+
};
|
|
959
|
+
} catch (error) {
|
|
960
|
+
if (error instanceof Refusal) return error.answer;
|
|
961
|
+
throw error;
|
|
962
|
+
}
|
|
963
|
+
};
|
|
964
|
+
};
|
|
965
|
+
var headersOf = (type) => ({
|
|
966
|
+
"Content-Type": type,
|
|
967
|
+
"Cache-Control": CACHE_CONTROL,
|
|
968
|
+
Vary: "Accept",
|
|
969
|
+
"X-Content-Type-Options": "nosniff",
|
|
970
|
+
"Content-Security-Policy": "default-src 'none'; sandbox"
|
|
971
|
+
});
|
|
972
|
+
// src/modules/images/transform.ts
|
|
973
|
+
var isSharpFactory = (value) => typeof value === "function";
|
|
974
|
+
/** The transform `sharp` makes, or `undefined` when it is not installed. */
|
|
975
|
+
var loadSharpTransform = async () => {
|
|
976
|
+
const name = "sharp";
|
|
977
|
+
let loaded;
|
|
978
|
+
try {
|
|
979
|
+
loaded = await import(
|
|
980
|
+
/* @vite-ignore */
|
|
981
|
+
name
|
|
982
|
+
);
|
|
983
|
+
} catch {
|
|
984
|
+
return;
|
|
985
|
+
}
|
|
986
|
+
const factory = typeof loaded === "object" && loaded !== null && "default" in loaded ? loaded.default : loaded;
|
|
987
|
+
if (!isSharpFactory(factory)) return;
|
|
988
|
+
return async (input, width, format) => {
|
|
989
|
+
const pipeline = factory(input).rotate().resize({
|
|
990
|
+
width,
|
|
991
|
+
withoutEnlargement: true
|
|
992
|
+
});
|
|
993
|
+
if (format === "avif") return pipeline.avif({ quality: 55 }).toBuffer();
|
|
994
|
+
if (format === "webp") return pipeline.webp({ quality: 75 }).toBuffer();
|
|
995
|
+
return pipeline.toBuffer();
|
|
996
|
+
};
|
|
997
|
+
};
|
|
998
|
+
// src/core/http/stages/images.ts
|
|
999
|
+
/** Where pictures are resized, when this server resizes them: published to the SDK, which builds every `srcset` on it. */
|
|
1000
|
+
var imagesPathOf = (config) => config.images && config.images.domains.length > 0 ? IMAGE_PATH : void 0;
|
|
1001
|
+
/** One proxy per configuration, made on the first request: `sharp` is looked for once, and said once when missing. */
|
|
1002
|
+
var proxies = /* @__PURE__ */ new WeakMap();
|
|
1003
|
+
var proxyFor = (images, outbound) => {
|
|
1004
|
+
const known = proxies.get(images);
|
|
1005
|
+
if (known) return known;
|
|
1006
|
+
const made = loadSharpTransform().then((transform) => {
|
|
1007
|
+
if (!transform) serverLog.warn("IMAGES", "sharp is not installed: pictures are passed through and kept, not resized (npm i sharp).");
|
|
1008
|
+
return createImageProxy({
|
|
1009
|
+
domains: images.domains,
|
|
1010
|
+
cacheDir: path.resolve(images.cacheDir ?? "tmp/images"),
|
|
1011
|
+
fetch: globalThis.fetch,
|
|
1012
|
+
transform,
|
|
1013
|
+
outbound: { privateOrigins: privateOriginsOf(outbound?.privateOrigins) }
|
|
1014
|
+
});
|
|
1015
|
+
});
|
|
1016
|
+
proxies.set(images, made);
|
|
1017
|
+
return made;
|
|
1018
|
+
};
|
|
1019
|
+
/** `/_plitzi/img?url=…&w=…` — a remote picture at one of the widths the SDK asks for. See `SSRImagesConfig`. */
|
|
1020
|
+
var imagesStage = async (ctx) => {
|
|
1021
|
+
const { images } = ctx.config;
|
|
1022
|
+
if (!images || imagesPathOf(ctx.config) === void 0 || ctx.req.path !== IMAGE_PATH) return false;
|
|
1023
|
+
if (ctx.req.method !== "GET" && ctx.req.method !== "HEAD") {
|
|
1024
|
+
ctx.res.setStatus(405);
|
|
1025
|
+
ctx.res.setHeader("Allow", "GET, HEAD");
|
|
1026
|
+
ctx.res.send("Method not allowed");
|
|
1027
|
+
return true;
|
|
1028
|
+
}
|
|
1029
|
+
const answer = await (await proxyFor(images, ctx.config.outbound))({
|
|
1030
|
+
url: ctx.req.query.url,
|
|
1031
|
+
width: ctx.req.query.w,
|
|
1032
|
+
accept: ctx.req.headers.accept ?? ""
|
|
1033
|
+
});
|
|
1034
|
+
ctx.res.setStatus(answer.status);
|
|
1035
|
+
for (const [name, value] of Object.entries(answer.headers)) ctx.res.setHeader(name, value);
|
|
1036
|
+
ctx.res.send(answer.body);
|
|
1037
|
+
return true;
|
|
1038
|
+
};
|
|
1039
|
+
// src/core/sdkAssets.ts
|
|
1040
|
+
/** Where the rendered page is told to fetch the SDK bundle from. Emitted by the render, so it is also served. */
|
|
1041
|
+
var SDK_ASSETS_PREFIX = "/sdk-assets";
|
|
1042
|
+
/**
|
|
1043
|
+
* The SDK's built output, resolved through the module system rather than guessed from `process.cwd()`.
|
|
1044
|
+
*
|
|
1045
|
+
* The rendered page asks for `/sdk-assets/plitzi-sdk.js` — the server puts that URL there itself — so the server is
|
|
1046
|
+
* also what should answer it. It used to be a mount every deployment had to declare, and forgetting it produced no
|
|
1047
|
+
* error at all: the asset requests fell through to the page renderer, which answered each one with a 200 and an HTML
|
|
1048
|
+
* document. The browser then refused them for their MIME type and the page stayed blank. A missing line of config
|
|
1049
|
+
* that looks like a broken SDK is not a choice worth offering.
|
|
1050
|
+
*
|
|
1051
|
+
* Returns undefined if the SDK is not installed, which is legitimate: a server rendering `ssrOnly` pages, or one
|
|
1052
|
+
* whose deployment serves the bundle from a CDN, needs none of this.
|
|
1053
|
+
*/
|
|
1054
|
+
var resolveSdkAssetsDir = () => {
|
|
1055
|
+
try {
|
|
1056
|
+
const require = createRequire(import.meta.url);
|
|
1057
|
+
return path.dirname(require.resolve("@plitzi/plitzi-sdk/plitzi-sdk.css"));
|
|
1058
|
+
} catch {
|
|
1059
|
+
return;
|
|
1060
|
+
}
|
|
1061
|
+
};
|
|
1062
|
+
/**
|
|
1063
|
+
* A cache-buster for the SDK URLs, taken from the bundle's own mtime.
|
|
1064
|
+
*
|
|
1065
|
+
* The assets are served with a long `Cache-Control`, so something has to change in the URL when the bundle does or
|
|
1066
|
+
* browsers keep the old one. Since the version a deployment runs IS the version of this package, the server can work
|
|
1067
|
+
* it out — nobody should have to compute it and pass it in, and forgetting to is a stale bundle nobody can explain.
|
|
1068
|
+
*/
|
|
1069
|
+
var cachedVersion;
|
|
1070
|
+
var sdkAssetVersion = () => {
|
|
1071
|
+
if (cachedVersion !== void 0) return cachedVersion;
|
|
1072
|
+
const dir = resolveSdkAssetsDir();
|
|
1073
|
+
try {
|
|
1074
|
+
cachedVersion = dir ? Math.floor(statSync(path.join(dir, "plitzi-sdk.js")).mtimeMs).toString(36) : "";
|
|
1075
|
+
} catch {
|
|
1076
|
+
cachedVersion = "";
|
|
1077
|
+
}
|
|
1078
|
+
return cachedVersion;
|
|
1079
|
+
};
|
|
1080
|
+
var pageAssets = (assetVersion) => {
|
|
1081
|
+
const version = assetVersion ?? sdkAssetVersion();
|
|
1082
|
+
const v = version ? `?v=${version}` : "";
|
|
1083
|
+
return {
|
|
1084
|
+
jsPath: `${SDK_ASSETS_PREFIX}/plitzi-sdk.js${v}`,
|
|
1085
|
+
cssPath: `${SDK_ASSETS_PREFIX}/plitzi-sdk.css${v}`,
|
|
1086
|
+
iconsCssPath: `${SDK_ASSETS_PREFIX}/plitzi-sdk-icons.css${v}`,
|
|
1087
|
+
devToolsCssPath: `${SDK_ASSETS_PREFIX}/plitzi-sdk-devtools.css${v}`,
|
|
1088
|
+
vendorJsPath: `${SDK_ASSETS_PREFIX}/plitzi-sdk-vendor.js${v}`,
|
|
1089
|
+
devVendorJsPath: `${SDK_ASSETS_PREFIX}/plitzi-sdk-dev-vendor.js${v}`
|
|
1090
|
+
};
|
|
1091
|
+
};
|
|
1092
|
+
// src/modules/ssr/prepareRender.tsx
|
|
1093
|
+
/** Last resort only: used for a page that declares no SEO title and a deployment that supplies none either. */
|
|
1094
|
+
var DEFAULT_TITLE = "Plitzi App";
|
|
1095
|
+
/**
|
|
1096
|
+
* The theme a space declares a first visit starts in, when it declares one other than `system`.
|
|
1097
|
+
*
|
|
1098
|
+
* `Partial`, because a style document written before themes existed has no `theme` at all, and a published space
|
|
1099
|
+
* is rendered from whatever document it was published with.
|
|
1100
|
+
*/
|
|
1101
|
+
var declaredTheme = (style) => {
|
|
1102
|
+
const declared = style?.theme?.default;
|
|
1103
|
+
return declared && declared !== "system" ? declared : void 0;
|
|
1104
|
+
};
|
|
1105
|
+
var declarations = /* @__PURE__ */ new WeakMap();
|
|
1106
|
+
var declarationOf = (component) => {
|
|
1107
|
+
const known = declarations.get(component);
|
|
1108
|
+
if (known) return known;
|
|
1109
|
+
const declaration = pluginDeclarationOf(component);
|
|
1110
|
+
declarations.set(component, declaration);
|
|
1111
|
+
return declaration;
|
|
1112
|
+
};
|
|
1113
|
+
var prepareRender = async (req, config, spaceId, environment, revision, pluginManager, offlineDataCache, metrics, offlineDataOverride, published = {}) => {
|
|
1114
|
+
const m = (name, fn) => metrics ? metrics.measure(name, fn) : Promise.resolve(fn());
|
|
1115
|
+
const offlineCacheKey = offlineDataCacheKeyOf({
|
|
1116
|
+
spaceId,
|
|
1117
|
+
environment,
|
|
1118
|
+
revision,
|
|
1119
|
+
flagsVersion: req.ctx.spaceDeployment?.flagsVersion,
|
|
1120
|
+
draftVersion: req.ctx.spaceDeployment?.draftVersion
|
|
1121
|
+
});
|
|
1122
|
+
const cachedOfflineData = offlineDataOverride === void 0 && offlineCacheKey ? offlineDataCache?.get(offlineCacheKey) : void 0;
|
|
1123
|
+
const loadOfflineData = createOfflineDataLoader(() => {
|
|
1124
|
+
if (offlineDataOverride !== void 0) return Promise.resolve(offlineDataOverride);
|
|
1125
|
+
if (cachedOfflineData) return Promise.resolve(cachedOfflineData);
|
|
1126
|
+
return m("schema", () => config.adapters.getOfflineData(spaceId, environment, revision));
|
|
1127
|
+
});
|
|
1128
|
+
const rawOfflineData = await loadOfflineData();
|
|
1129
|
+
/**
|
|
1130
|
+
* The space as this visitor may be sent it: a page whose `access` they do not meet is emptied before anything reads
|
|
1131
|
+
* it — the render, the payload, the document the browser fetches — so its content never leaves this server for them.
|
|
1132
|
+
* The shared cache below keeps the whole space; only what is sent is cut.
|
|
1133
|
+
*/
|
|
1134
|
+
const withholding = rawOfflineData ? withholdPages(rawOfflineData.schema, req.ctx.user) : void 0;
|
|
1135
|
+
const offlineData = rawOfflineData && withholding ? offlineDataWith(rawOfflineData, withholding.schema) : rawOfflineData;
|
|
1136
|
+
const rscPath = resolveRscEndpoint(config);
|
|
1137
|
+
const schema = offlineData?.schema;
|
|
1138
|
+
const pageMatch = schema !== void 0 ? matchRscPage(schema, req.path, req.ctx.user) : void 0;
|
|
1139
|
+
const refused = pageMatch ? pageWithheldOf(schema?.flat[pageMatch.pageId]?.attributes) : void 0;
|
|
1140
|
+
const rscEnabled = rscPath !== void 0 && schema !== void 0 && schema.rsc?.enabled !== false;
|
|
1141
|
+
const debugAuthorized = !Boolean(req.query[PREVIEW_TOKEN_PARAM]) && authorizesDebugging(config, schema?.settings);
|
|
1142
|
+
const flagOverrides = await requestFlagOverrides(config, {
|
|
1143
|
+
cookie: req.headers.cookie,
|
|
1144
|
+
authority: requestAuthority(req)
|
|
1145
|
+
}, {
|
|
1146
|
+
spaceId: req.ctx.spaceDeployment?.spaceId ?? spaceId,
|
|
1147
|
+
environment: req.ctx.spaceDeployment?.environment ?? environment
|
|
1148
|
+
}, debugAuthorized);
|
|
1149
|
+
const pageFlags = schema !== void 0 && pageMatch !== void 0 ? flagValues(resolveFlags(schema.flags, {
|
|
1150
|
+
environment: req.ctx.spaceDeployment?.environment ?? environment,
|
|
1151
|
+
hostname: req.hostname,
|
|
1152
|
+
routeParams: pageMatch.routeParams,
|
|
1153
|
+
queryParams: req.query,
|
|
1154
|
+
user: flagUserFromSSR(req.ctx.user)
|
|
1155
|
+
}, flagOverrides)) : void 0;
|
|
1156
|
+
const serverElements = rscEnabled && pageMatch !== void 0 ? collectServerElements(schema, pageMatch.pageId, void 0, pageFlags) : [];
|
|
1157
|
+
const hasTargets = serverElements.length > 0;
|
|
1158
|
+
const rscData = hasTargets && config.adapters.getRscData ? await m("rsc", () => config.adapters.getRscData?.({
|
|
1159
|
+
req,
|
|
1160
|
+
spaceId: req.ctx.spaceDeployment?.spaceId ?? spaceId,
|
|
1161
|
+
environment: req.ctx.spaceDeployment?.environment ?? environment,
|
|
1162
|
+
revision: req.ctx.spaceDeployment?.revision ?? revision,
|
|
1163
|
+
user: req.ctx.user,
|
|
1164
|
+
loadOfflineData,
|
|
1165
|
+
flagOverrides
|
|
1166
|
+
})) : rscPath ? { serverData: {} } : void 0;
|
|
1167
|
+
const navigation = {
|
|
1168
|
+
routeParams: pageMatch?.routeParams ?? {},
|
|
1169
|
+
queryParams: req.query
|
|
1170
|
+
};
|
|
1171
|
+
const pageContext = pageServerContext(serverElements, rscData?.serverData ?? {}, navigation);
|
|
1172
|
+
const pageSeo = resolvePageSeo(schema, pageMatch?.pageId, pageContext);
|
|
1173
|
+
const notFound = pageMatch !== void 0 && rscData?.serverData !== void 0 ? notFoundProvider(serverElements, rscData.serverData, navigation) !== void 0 || pageNotFound(schema?.flat[pageMatch.pageId]?.attributes.notFound, pageContext) : false;
|
|
1174
|
+
const server = buildServerInfo(req, config, {
|
|
1175
|
+
rscPath,
|
|
1176
|
+
rscData,
|
|
1177
|
+
actionPath: published.actionPath,
|
|
1178
|
+
realtimePath: published.realtimePath,
|
|
1179
|
+
realtimeTransport: published.realtimeTransport,
|
|
1180
|
+
imagePath: imagesPathOf(config)
|
|
1181
|
+
});
|
|
1182
|
+
if (offlineDataOverride === void 0 && !cachedOfflineData && offlineCacheKey && rawOfflineData !== void 0) offlineDataCache?.set(offlineCacheKey, rawOfflineData);
|
|
1183
|
+
const assets = pageAssets(config.assetVersion);
|
|
1184
|
+
const sdkDevToolsStylePath = assets.devToolsCssPath;
|
|
1185
|
+
const sdkIconsStylePath = assets.iconsCssPath;
|
|
1186
|
+
/**
|
|
1187
|
+
* Two facts, and they have to leave this server separately.
|
|
1188
|
+
*
|
|
1189
|
+
* `debugAuthorized` is the deployment's decision and is what the client bootstrap is handed, because on the
|
|
1190
|
+
* client that argument is what arms the shortcut and the "currently hidden" console hint. Collapsing the
|
|
1191
|
+
* cookie into it — which is what this used to send — made hiding the panel on an SSR page permanent: the page
|
|
1192
|
+
* came back authorizing nothing, so the shortcut was dead and nothing on screen or in the console said why.
|
|
1193
|
+
*
|
|
1194
|
+
* `debugRendered` is what this particular render draws, preference included. The client derives the same
|
|
1195
|
+
* product from the same cookie on its first pass, so the markup it hydrates matches.
|
|
1196
|
+
*
|
|
1197
|
+
* Who may authorize it: the server first, through `debugMode`. When it said nothing, a development server does, and
|
|
1198
|
+
* so does the space itself (`settings.debugMode`) — an owner inspecting their own published site. The space is read
|
|
1199
|
+
* from what this server loaded, never from the request, so a visitor has no say in it.
|
|
1200
|
+
*/
|
|
1201
|
+
const debugRendered = resolveDebugMode(debugAuthorized, readCookie(req.headers.cookie, debugCookieName(requestAuthority(req))));
|
|
1202
|
+
/**
|
|
1203
|
+
* The runs this render's server elements started, handed to a page that may debug them — and to no other.
|
|
1204
|
+
*
|
|
1205
|
+
* Same authorization as the panel itself: a page nobody authorized is told nothing about the flows behind it, not
|
|
1206
|
+
* even that they ran. A render carrying them is also one nobody else may be served from a cache: those runs are
|
|
1207
|
+
* this request's.
|
|
1208
|
+
*/
|
|
1209
|
+
const actionRuns = debugAuthorized && req.ctx.actionRuns?.length ? req.ctx.actionRuns : void 0;
|
|
1210
|
+
const runStatus = debugAuthorized && req.ctx.runStatus === true;
|
|
1211
|
+
const inspector = req.ctx.inspectedDraft === true;
|
|
1212
|
+
const { degrade, badge: meteredBadge, quotaNear: meteredNear, analytics } = req.ctx.meter ?? {};
|
|
1213
|
+
const clientAnalytics = analytics ? {
|
|
1214
|
+
...analytics,
|
|
1215
|
+
firstViewCounted: true
|
|
1216
|
+
} : void 0;
|
|
1217
|
+
const overQuota = degrade ? true : void 0;
|
|
1218
|
+
const quotaNear = meteredNear && !degrade ? true : void 0;
|
|
1219
|
+
const badge = meteredBadge;
|
|
1220
|
+
/**
|
|
1221
|
+
* The visitor's theme, from the cookie the SDK writes it to.
|
|
1222
|
+
*
|
|
1223
|
+
* This is the whole reason it is a cookie and not web storage: read here, the class goes on `<html>` in the
|
|
1224
|
+
* document the server sends, so the page arrives already painted in the right theme — no blocking script in the
|
|
1225
|
+
* head, and no first paint in the other theme for the SDK to correct four hundred milliseconds later.
|
|
1226
|
+
*
|
|
1227
|
+
* It travels to the browser too. The class alone would settle what the page LOOKS like, but a space can bind to
|
|
1228
|
+
* `{{ theme.resolved }}` or gate a rule on the scheme, and a client that started at `system` while the server
|
|
1229
|
+
* rendered `dark` would hydrate different markup and throw away the tree.
|
|
1230
|
+
*
|
|
1231
|
+
* Absent — a first visit — the space's own default applies (`style.theme.default`), painted by the server like a
|
|
1232
|
+
* choice would be. A default of `system` stamps nothing and the stylesheet's media queries answer, which is exactly
|
|
1233
|
+
* right for a space that did not pick.
|
|
1234
|
+
*/
|
|
1235
|
+
const theme = themeFromCookies(req.headers.cookie) ?? declaredTheme(offlineData?.style);
|
|
1236
|
+
/**
|
|
1237
|
+
* And what a `system` theme resolves to, as the browser will resolve it: the machine's scheme, from the client hint
|
|
1238
|
+
* (Chromium, once asked — `Accept-CH`) or the cookie the SDK keeps it in. Without it the server drew `light`, and a
|
|
1239
|
+
* picture whose address names the scheme was asked for in light and again in dark as the page hydrated.
|
|
1240
|
+
*/
|
|
1241
|
+
const scheme = visitorScheme(req);
|
|
1242
|
+
/**
|
|
1243
|
+
* The kept state the first paint depends on, from the cookie the SDK writes the space's `settings.paintedState` to.
|
|
1244
|
+
*
|
|
1245
|
+
* The theme's reasoning, for the space's own state: web storage is the browser's alone, so what a visitor chose — the
|
|
1246
|
+
* tool a toolbar shows, their name in an avatar — would reach the page only after hydration, and be swapped in over
|
|
1247
|
+
* the defaults the server drew. Read here, the server draws with it, and the page starts from the same values: it
|
|
1248
|
+
* travels as the SDK's `state`, the starting `runtime.state`, in the render and in the payload alike, or the client
|
|
1249
|
+
* would hydrate other markup. Only the keys the space declares, only with `keepState` on, and of an entry another
|
|
1250
|
+
* account wrote than the one this request proved, only the browser's (`browserState`).
|
|
1251
|
+
*/
|
|
1252
|
+
const paintedState = requestPaintedState(req, schema?.settings, req.ctx.user?.id).state;
|
|
1253
|
+
/**
|
|
1254
|
+
* The two layers of the space's flags this server answers for. Its own (`config.flags`), asked per space when it
|
|
1255
|
+
* serves several; and the ones a tester forced from the dev tools, read from their cookie — only for a page allowed
|
|
1256
|
+
* to debug, or any visitor could switch on a feature still behind a flag. Both travel to the browser beside the
|
|
1257
|
+
* page, so it hydrates with the flags it was drawn with.
|
|
1258
|
+
*/
|
|
1259
|
+
const { server: serverFlags, qa: forcedFlags } = flagOverrides;
|
|
1260
|
+
/**
|
|
1261
|
+
* The space travels beside the page rather than in it, fetched while the scripts are — see `spaceDocument`.
|
|
1262
|
+
*
|
|
1263
|
+
* Not for a draft, which no other process could produce when the fetch reaches it, and not for a deployment's own
|
|
1264
|
+
* template, which was written for the space inline; a page with no script needs no space at all.
|
|
1265
|
+
*/
|
|
1266
|
+
/**
|
|
1267
|
+
* A page that named its space with a token in its address (`?access-token=`, how a host serving many spaces is asked
|
|
1268
|
+
* for one) has its document asked for the same way: fetched bare, the host's own space answered it — another space's
|
|
1269
|
+
* document, hydrated over this one's page.
|
|
1270
|
+
*/
|
|
1271
|
+
const spaceToken = req.query[SPACE_TOKEN_PARAM];
|
|
1272
|
+
/**
|
|
1273
|
+
* The compiled stylesheet as a file the page's head links, rather than in the page (`styleSheetOf`) — except where no
|
|
1274
|
+
* other request could answer for that file: a draft's unsaved styles, and a space named by a token, whose file would
|
|
1275
|
+
* be asked for by the host and answered with the host's own space; and under a deployment's own template, which does
|
|
1276
|
+
* not know to link it.
|
|
1277
|
+
*/
|
|
1278
|
+
const linkStyle = offlineDataOverride === void 0 && !spaceToken && config.templateFn === void 0;
|
|
1279
|
+
const document = offlineData !== void 0 ? spaceDocument(offlineData, { linkStyle }) : void 0;
|
|
1280
|
+
const publishedDocument = document !== void 0 && offlineDataOverride === void 0 && config.templateFn === void 0 && config.ssrOnly !== true ? publishSpaceDocument(spaceId, environment, document, withholding?.kept ?? []) : void 0;
|
|
1281
|
+
const spaceDocumentPath = publishedDocument && spaceToken ? `${publishedDocument}?${SPACE_TOKEN_PARAM}=${encodeURIComponent(spaceToken)}` : publishedDocument;
|
|
1282
|
+
const offlineDataStr = hydrationPayload(offlineData, {
|
|
1283
|
+
offlineMode: true,
|
|
1284
|
+
environment,
|
|
1285
|
+
renderMode: "raw",
|
|
1286
|
+
server,
|
|
1287
|
+
sdkDevToolsStylePath,
|
|
1288
|
+
sdkIconsStylePath,
|
|
1289
|
+
...theme ? { theme } : {},
|
|
1290
|
+
...scheme ? { scheme } : {},
|
|
1291
|
+
...paintedState ? { state: paintedState } : {},
|
|
1292
|
+
...clientAnalytics ? { analytics: clientAnalytics } : {},
|
|
1293
|
+
...overQuota ? { overQuota } : {},
|
|
1294
|
+
...quotaNear ? { quotaNear } : {},
|
|
1295
|
+
...badge ? { badge } : {},
|
|
1296
|
+
...actionRuns ? { actionRuns } : {},
|
|
1297
|
+
...runStatus ? { runStatus } : {},
|
|
1298
|
+
...inspector ? { inspector } : {},
|
|
1299
|
+
...serverFlags ? { serverFlags } : {},
|
|
1300
|
+
...forcedFlags ? { forcedFlags } : {}
|
|
1301
|
+
}, {
|
|
1302
|
+
apart: spaceDocumentPath !== void 0,
|
|
1303
|
+
linkStyle
|
|
1304
|
+
});
|
|
1305
|
+
const pluginNames = req.ctx.spaceDeployment?.pluginNames ?? [];
|
|
1306
|
+
const pluginSources = req.ctx.spaceDeployment?.pluginSources;
|
|
1307
|
+
const pluginBaseNames = new Set(pluginNames.map((n) => n.replace(/@[^@]*$/, "")));
|
|
1308
|
+
const dynamicNames = [];
|
|
1309
|
+
if (pluginSources) for (const [pluginName, pluginSource] of Object.entries(pluginSources)) {
|
|
1310
|
+
const key = pluginManager.ensure(pluginName, pluginSource);
|
|
1311
|
+
if (!pluginBaseNames.has(pluginName)) dynamicNames.push(key);
|
|
1312
|
+
}
|
|
1313
|
+
const externalNames = config.autoLoadSchemaPlugins !== false ? await m("extPlugins", () => registerExternalPlugins(pluginManager, offlineData, { privateOrigins: privateOriginsOf(config.outbound?.privateOrigins) }, pluginBaseNames)) : [];
|
|
1314
|
+
const allPluginNames = [
|
|
1315
|
+
...pluginNames,
|
|
1316
|
+
...dynamicNames,
|
|
1317
|
+
...externalNames
|
|
1318
|
+
];
|
|
1319
|
+
const entries = allPluginNames.length > 0 ? await pluginManager.getEntries(allPluginNames) : [];
|
|
1320
|
+
const pluginComponents = await m("plugins", () => loadPluginComponents(entries, pluginManager.getComponents()));
|
|
1321
|
+
reportMissingPlugins(spaceId, schema, /* @__PURE__ */ new Set([...Object.keys(pluginComponents), ...entries.map((entry) => entry.keyName)]));
|
|
1322
|
+
const templateEntries = entries.length > 0 ? entries : req.ctx.spaceDeployment?.templateProps?.plugins;
|
|
1323
|
+
/**
|
|
1324
|
+
* The plugins this page draws none of: the browser is sent what they declare, and loads one when a page that draws
|
|
1325
|
+
* it is opened. Their code is what the first paint waited on — a page of the website downloaded the builder's.
|
|
1326
|
+
*
|
|
1327
|
+
* Only one the server holds the component of can wait, since its declaration is read from it; a page matched to
|
|
1328
|
+
* nothing, which cannot say what it draws, waits for none.
|
|
1329
|
+
*/
|
|
1330
|
+
const pageTypes = schema !== void 0 && pageMatch !== void 0 ? pageElementTypes(schema, pageMatch.pageId) : void 0;
|
|
1331
|
+
const deferredOf = (entry) => {
|
|
1332
|
+
const plugin = pageTypes && entry.js ? pluginComponents[entry.keyName] : void 0;
|
|
1333
|
+
if (!plugin) return;
|
|
1334
|
+
const declaration = declarationOf(plugin.component);
|
|
1335
|
+
return pluginTypesOf(entry.keyName, declaration).some((type) => pageTypes?.has(type)) ? void 0 : declaration;
|
|
1336
|
+
};
|
|
1337
|
+
const templatePlugins = templateEntries?.map((entry) => {
|
|
1338
|
+
const deferred = deferredOf(entry);
|
|
1339
|
+
return {
|
|
1340
|
+
...entry,
|
|
1341
|
+
ssr: entry.keyName in pluginComponents,
|
|
1342
|
+
...deferred ? { deferred } : {}
|
|
1343
|
+
};
|
|
1344
|
+
});
|
|
1345
|
+
const vendorJs = debugRendered ? assets.devVendorJsPath : assets.vendorJsPath;
|
|
1346
|
+
const deploymentProps = req.ctx.spaceDeployment?.templateProps;
|
|
1347
|
+
const origin = requestOrigin(req);
|
|
1348
|
+
const head = pageHeadTags({
|
|
1349
|
+
title: pageSeo.title ?? deploymentProps?.title ?? DEFAULT_TITLE,
|
|
1350
|
+
...pageSeo.description ?? deploymentProps?.description ? { description: pageSeo.description ?? deploymentProps?.description } : {},
|
|
1351
|
+
...pageSeo.robots ? { robots: pageSeo.robots } : {},
|
|
1352
|
+
...pageSeo.image ? { image: pageSeo.image } : {},
|
|
1353
|
+
...pageSeo.imageAlt ? { imageAlt: pageSeo.imageAlt } : {},
|
|
1354
|
+
...pageSeo.type ? { type: pageSeo.type } : {}
|
|
1355
|
+
}, spaceIdentity(schema?.settings), origin === "" ? "" : `${origin}${req.path}`);
|
|
1356
|
+
return {
|
|
1357
|
+
componentProps: {
|
|
1358
|
+
plugins: Object.keys(pluginComponents).length > 0 ? pluginComponents : void 0,
|
|
1359
|
+
offlineData: document?.data,
|
|
1360
|
+
server,
|
|
1361
|
+
environment: req.ctx.spaceDeployment?.environment ?? environment,
|
|
1362
|
+
debugMode: debugRendered,
|
|
1363
|
+
sdkDevToolsStylePath,
|
|
1364
|
+
sdkIconsStylePath,
|
|
1365
|
+
overQuota,
|
|
1366
|
+
quotaNear,
|
|
1367
|
+
badge,
|
|
1368
|
+
theme,
|
|
1369
|
+
...scheme ? { scheme } : {},
|
|
1370
|
+
...paintedState ? { state: paintedState } : {},
|
|
1371
|
+
...serverFlags ? { serverFlags } : {},
|
|
1372
|
+
...forcedFlags ? { forcedFlags } : {}
|
|
1373
|
+
},
|
|
1374
|
+
entries,
|
|
1375
|
+
templateParams: {
|
|
1376
|
+
...scriptTemplateParams(config, req.ctx.spaceDeployment),
|
|
1377
|
+
title: DEFAULT_TITLE,
|
|
1378
|
+
jsPath: assets.jsPath,
|
|
1379
|
+
cssPath: assets.cssPath,
|
|
1380
|
+
iconsCssPath: sdkIconsStylePath,
|
|
1381
|
+
spaceDocumentPath,
|
|
1382
|
+
styleSheetPath: document?.data.style.cacheHref,
|
|
1383
|
+
react: vendorJs,
|
|
1384
|
+
reactJsx: vendorJs,
|
|
1385
|
+
reactDom: vendorJs,
|
|
1386
|
+
reactDomClient: vendorJs,
|
|
1387
|
+
reactCompilerRuntime: vendorJs,
|
|
1388
|
+
/**
|
|
1389
|
+
* The class this document wears, straight onto `<html>` — see `theme` above.
|
|
1390
|
+
*
|
|
1391
|
+
* `system` and "never chose" both write nothing, and the silence is the mechanism: the stylesheet's
|
|
1392
|
+
* `prefers-color-scheme` queries are guarded on the absence of these classes, so stamping one would freeze the
|
|
1393
|
+
* page against the machine it is running on.
|
|
1394
|
+
*/
|
|
1395
|
+
themeClass: theme && theme !== "system" ? theme : void 0,
|
|
1396
|
+
/**
|
|
1397
|
+
* The space's own families, requested by the document itself.
|
|
1398
|
+
*
|
|
1399
|
+
* Ahead of the deployment's `templateProps` because a deployment cannot know them: they are a fact about the
|
|
1400
|
+
* space's style document, and a page whose text is laid out in a face the browser has not been asked for is
|
|
1401
|
+
* a page that renders in a fallback and then reflows.
|
|
1402
|
+
*/
|
|
1403
|
+
fonts: fontsToHead(offlineData?.style.fonts ?? [], fontUrlResolver(config.fonts?.baseUrl), googleFontsUrlOf(config)),
|
|
1404
|
+
...req.ctx.spaceDeployment?.templateProps,
|
|
1405
|
+
...pageSeo,
|
|
1406
|
+
head,
|
|
1407
|
+
plugins: templatePlugins,
|
|
1408
|
+
debugMode: debugAuthorized,
|
|
1409
|
+
ssrOnly: config.ssrOnly === true,
|
|
1410
|
+
livePages: config.livePages === true,
|
|
1411
|
+
hotPlugins: config.livePages === true && config.devMode === true,
|
|
1412
|
+
...config.livePages === true && offlineDataOverride !== void 0 ? { liveDraft: readDraftToken(req) } : {},
|
|
1413
|
+
offlineData: offlineDataStr
|
|
1414
|
+
},
|
|
1415
|
+
cacheable: actionRuns === void 0 && forcedFlags === void 0 && req.ctx.readAsVisitor !== true && !(environment === "main" && hasTargets),
|
|
1416
|
+
notFound,
|
|
1417
|
+
...refused ? { refused } : {}
|
|
1418
|
+
};
|
|
1419
|
+
};
|
|
1420
|
+
// src/modules/ssr/buildBody.tsx
|
|
1421
|
+
var buildBody = async (req, config, spaceId, environment, revision, renderFn, pluginManager, offlineDataCache, metrics, offlineDataOverride, published) => {
|
|
1422
|
+
const prep = await prepareRender(req, config, spaceId, environment, revision, pluginManager, offlineDataCache, metrics, offlineDataOverride, published);
|
|
1423
|
+
const result = {};
|
|
1424
|
+
const reactStart = metrics ? performance.now() : 0;
|
|
1425
|
+
const html = renderToString(/* @__PURE__ */ jsx(Component, {
|
|
1426
|
+
...prep.componentProps,
|
|
1427
|
+
ssrResult: result
|
|
1428
|
+
})).trim();
|
|
1429
|
+
metrics?.record("react", Math.round(performance.now() - reactStart));
|
|
1430
|
+
withNotFound(result, prep.notFound);
|
|
1431
|
+
withRefusal(result, prep.refused);
|
|
1432
|
+
if (result.redirect !== void 0) return {
|
|
1433
|
+
result,
|
|
1434
|
+
cacheable: prep.cacheable,
|
|
1435
|
+
nonce: ""
|
|
1436
|
+
};
|
|
1437
|
+
const templateStart = metrics ? performance.now() : 0;
|
|
1438
|
+
const body = renderFn({
|
|
1439
|
+
...prep.templateParams,
|
|
1440
|
+
html
|
|
1441
|
+
});
|
|
1442
|
+
metrics?.record("template", Math.round(performance.now() - templateStart));
|
|
1443
|
+
return {
|
|
1444
|
+
body,
|
|
1445
|
+
result,
|
|
1446
|
+
cacheable: prep.cacheable,
|
|
1447
|
+
nonce: prep.templateParams.nonce ?? ""
|
|
1448
|
+
};
|
|
1449
|
+
};
|
|
1450
|
+
export { draftSessionCookie as C, matchRscPage as E, createMemoryDraftStore as S, invalidatePluginComponentCache as T, handleSpaceDocument as _, resolveSdkAssetsDir as a, resolveServices as b, applySSRResult as c, withNotFound as d, withRefusal as f, handleCurrentSpace as g, answerCurrentSpacePreflight as h, pageAssets as i, isReusable as l, SPACE_DOCUMENT_PATH as m, prepareRender as n, imagesStage as o, CURRENT_SPACE_PATH as p, SDK_ASSETS_PREFIX as r, Component as s, buildBody as t, renderParamsOf as u, meterPage as v, takeDraftOverride as w, DRAFT_STORE_METHODS as x, resolveRscEndpoint as y };
|