@plitzi/sdk-server 0.39.0 → 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 +22 -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 +17 -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 +9 -2
- package/skills/plitzi-authoring/reference/auth.md +6 -1
- package/skills/plitzi-authoring/reference/authoring-errors.md +7 -4
- package/skills/plitzi-authoring/reference/flows.md +9 -9
- package/skills/plitzi-authoring/reference/kept-state.md +12 -0
- package/skills/plitzi-authoring/reference/lists.md +7 -1
- package/skills/plitzi-authoring/reference/plugins.md +5 -2
- package/skills/plitzi-authoring/reference/testing.md +3 -3
- 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 -396
- 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 -332
- 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
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
import { lookup } from "node:dns/promises";
|
|
2
|
-
import { BlockList, isIP } from "node:net";
|
|
3
|
-
//#region src/helpers/outboundGuard.ts
|
|
4
|
-
/**
|
|
5
|
-
* Where a customer-authored request may go.
|
|
6
|
-
*
|
|
7
|
-
* Two things reach the outside world on somebody else's say-so: the `http.request` task, whose URL is typed into
|
|
8
|
-
* a flow, and the connector engine, whose `baseUrl` is typed into a manifest. Both run inside the cluster, from a
|
|
9
|
-
* trusted network position, which is what turns "fetch this URL for me" into a way to read the instance's cloud
|
|
10
|
-
* credentials at `169.254.169.254` or talk to Redis on `localhost`. One rule, in one place, for both of them.
|
|
11
|
-
*/
|
|
12
|
-
/**
|
|
13
|
-
* Every range that is never a public peer, as ranges rather than string patterns.
|
|
14
|
-
*
|
|
15
|
-
* A `BlockList` also judges an IPv4-mapped IPv6 address (`::ffff:7f00:1`) against the IPv4 rules, which is the form a
|
|
16
|
-
* URL parser turns `[::ffff:127.0.0.1]` into and a dual-stack socket happily connects to loopback. The prefix
|
|
17
|
-
* patterns this replaced matched neither that nor `::`, and matched DNS names that merely began with `fc` or `fe8`.
|
|
18
|
-
*/
|
|
19
|
-
var privateRanges = new BlockList();
|
|
20
|
-
var IPV4_RANGES = [
|
|
21
|
-
["0.0.0.0", 8],
|
|
22
|
-
["10.0.0.0", 8],
|
|
23
|
-
["100.64.0.0", 10],
|
|
24
|
-
["127.0.0.0", 8],
|
|
25
|
-
["169.254.0.0", 16],
|
|
26
|
-
["172.16.0.0", 12],
|
|
27
|
-
["192.0.0.0", 24],
|
|
28
|
-
["192.168.0.0", 16],
|
|
29
|
-
["198.18.0.0", 15],
|
|
30
|
-
["224.0.0.0", 4],
|
|
31
|
-
["240.0.0.0", 4]
|
|
32
|
-
];
|
|
33
|
-
var IPV6_RANGES = [
|
|
34
|
-
["::", 96],
|
|
35
|
-
["64:ff9b:1::", 48],
|
|
36
|
-
["fc00::", 7],
|
|
37
|
-
["fe80::", 10],
|
|
38
|
-
["ff00::", 8]
|
|
39
|
-
];
|
|
40
|
-
/** An IPv4 address as the two 16-bit groups it occupies inside an IPv6 one. */
|
|
41
|
-
var ipv4Groups = (address) => {
|
|
42
|
-
const [a = 0, b = 0, c = 0, d = 0] = address.split(".").map(Number);
|
|
43
|
-
return [(a << 8 | b).toString(16), (c << 8 | d).toString(16)];
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* The same private IPv4 ranges where IPv6 carries an IPv4 address inside it.
|
|
47
|
-
*
|
|
48
|
-
* NAT64 (`64:ff9b::/96`) is how an IPv6-only cluster reaches EVERY IPv4 host — DNS64 answers a public API with an address
|
|
49
|
-
* in it — so the prefix cannot be refused whole; what it carries is judged instead. 6to4 (`2002::/16`) carries its
|
|
50
|
-
* address in bits 16–47.
|
|
51
|
-
*/
|
|
52
|
-
var EMBEDDED_IPV4_RANGES = IPV4_RANGES.flatMap(([network, prefix]) => {
|
|
53
|
-
const [high, low] = ipv4Groups(network);
|
|
54
|
-
return [[`64:ff9b::${high}:${low}`, 96 + prefix], [`2002:${high}:${low}::`, 16 + prefix]];
|
|
55
|
-
});
|
|
56
|
-
IPV4_RANGES.forEach(([network, prefix]) => privateRanges.addSubnet(network, prefix, "ipv4"));
|
|
57
|
-
[...IPV6_RANGES, ...EMBEDDED_IPV4_RANGES].forEach(([network, prefix]) => privateRanges.addSubnet(network, prefix, "ipv6"));
|
|
58
|
-
var isBlockedName = (host) => host === "localhost" || host.endsWith(".localhost") || host.endsWith(".internal");
|
|
59
|
-
/**
|
|
60
|
-
* Whether a hostname — or an address a name resolved to — may never be the other end of an authored request.
|
|
61
|
-
*
|
|
62
|
-
* A NAME is only refused for what it says it is (`localhost`, `*.internal`); anything else about a name is decided by
|
|
63
|
-
* what it resolves to, in `assertOutboundAllowed`.
|
|
64
|
-
*/
|
|
65
|
-
var isBlockedHost = (hostname) => {
|
|
66
|
-
const host = hostname.toLowerCase().replace(/^\[|\]$/g, "").replace(/%.*$/, "");
|
|
67
|
-
const family = isIP(host);
|
|
68
|
-
if (family === 0) return isBlockedName(host);
|
|
69
|
-
return privateRanges.check(host, family === 6 ? "ipv6" : "ipv4");
|
|
70
|
-
};
|
|
71
|
-
var resolveAll = (hostname) => lookup(hostname, {
|
|
72
|
-
all: true,
|
|
73
|
-
verbatim: true
|
|
74
|
-
});
|
|
75
|
-
/**
|
|
76
|
-
* The deployment's own origins as `new URL(…).origin` writes them, refusing what is not one — said when the server is
|
|
77
|
-
* built, rather than as every request that should have reached it failing.
|
|
78
|
-
*/
|
|
79
|
-
var privateOriginsOf = (origins) => (origins ?? []).map((origin) => {
|
|
80
|
-
let url;
|
|
81
|
-
try {
|
|
82
|
-
url = new URL(origin);
|
|
83
|
-
} catch {
|
|
84
|
-
throw new Error(`outbound.privateOrigins: "${origin}" is not an origin — write it as http://host:port`);
|
|
85
|
-
}
|
|
86
|
-
if (url.protocol !== "http:" && url.protocol !== "https:" || url.origin !== origin.replace(/\/$/, "")) throw new Error(`outbound.privateOrigins: "${origin}" is not an origin — write it as http://host:port, no path`);
|
|
87
|
-
return url.origin;
|
|
88
|
-
});
|
|
89
|
-
/**
|
|
90
|
-
* Checks the URL an authored document asked for, including what its hostname RESOLVES to — unless it is one of the
|
|
91
|
-
* origins the deployment names as its own (`privateOrigins`).
|
|
92
|
-
*
|
|
93
|
-
* The literal check alone was never enough and said so: `http://metadata.example.com/` is a public-looking name
|
|
94
|
-
* whose A record can be `169.254.169.254`, and nothing about the string gives that away. So the name is resolved
|
|
95
|
-
* and every address it answers is judged — a name that resolves to a private address is refused whatever it is
|
|
96
|
-
* spelled like.
|
|
97
|
-
*
|
|
98
|
-
* A name that does not resolve is ALLOWED through: there is nothing to judge, and the request is about to fail on
|
|
99
|
-
* its own with a better error than this could give. What remains open is DNS rebinding — an attacker's own server
|
|
100
|
-
* answering a public address here and a private one when the socket is opened a moment later — which is closed
|
|
101
|
-
* only by resolving and connecting to the same address, and that belongs in the transport rather than here.
|
|
102
|
-
*/
|
|
103
|
-
var assertOutboundAllowed = async (url, { lookup = resolveAll, privateOrigins = [] } = {}) => {
|
|
104
|
-
if (url.protocol !== "https:" && url.protocol !== "http:") throw new Error(`Request protocol "${url.protocol}" is not allowed`);
|
|
105
|
-
if (privateOrigins.includes(url.origin)) return;
|
|
106
|
-
if (isBlockedHost(url.hostname)) throw new Error("Request host is not allowed");
|
|
107
|
-
let addresses;
|
|
108
|
-
try {
|
|
109
|
-
addresses = await lookup(url.hostname.replace(/^\[|\]$/g, ""));
|
|
110
|
-
} catch {
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
if (addresses.some(({ address }) => isBlockedHost(address))) throw new Error("Request host is not allowed");
|
|
114
|
-
};
|
|
115
|
-
var MAX_REDIRECTS = 5;
|
|
116
|
-
var REDIRECT_STATUSES = [
|
|
117
|
-
301,
|
|
118
|
-
302,
|
|
119
|
-
303,
|
|
120
|
-
307,
|
|
121
|
-
308
|
|
122
|
-
];
|
|
123
|
-
/** What the Fetch standard strips when a redirect leaves the origin that was given them. */
|
|
124
|
-
var CROSS_ORIGIN_HEADERS = [
|
|
125
|
-
"authorization",
|
|
126
|
-
"cookie",
|
|
127
|
-
"proxy-authorization"
|
|
128
|
-
];
|
|
129
|
-
var BODY_HEADERS = [
|
|
130
|
-
"content-type",
|
|
131
|
-
"content-length",
|
|
132
|
-
"content-encoding",
|
|
133
|
-
"content-language",
|
|
134
|
-
"content-location"
|
|
135
|
-
];
|
|
136
|
-
/**
|
|
137
|
-
* The request a redirect continues as — the rules `fetch` itself follows, applied by hand because it no longer does.
|
|
138
|
-
*
|
|
139
|
-
* A 303, and a 301/302 answering a POST, become a bodiless GET; 307 and 308 repeat the request exactly. Leaving the
|
|
140
|
-
* origin drops the headers the Fetch standard drops, and only those: a key the author put in a header of its own
|
|
141
|
-
* travels on as it did before, and the author already decides where it is sent.
|
|
142
|
-
*/
|
|
143
|
-
var redirectedInit = (init, status, crossOrigin) => {
|
|
144
|
-
const method = (init.method ?? "GET").toUpperCase();
|
|
145
|
-
const becomesGet = status === 303 && method !== "HEAD" || (status === 301 || status === 302) && method === "POST";
|
|
146
|
-
const headers = new Headers(init.headers);
|
|
147
|
-
if (crossOrigin) CROSS_ORIGIN_HEADERS.forEach((name) => headers.delete(name));
|
|
148
|
-
if (!becomesGet) return {
|
|
149
|
-
...init,
|
|
150
|
-
headers
|
|
151
|
-
};
|
|
152
|
-
BODY_HEADERS.forEach((name) => headers.delete(name));
|
|
153
|
-
return {
|
|
154
|
-
...init,
|
|
155
|
-
method: "GET",
|
|
156
|
-
body: void 0,
|
|
157
|
-
headers
|
|
158
|
-
};
|
|
159
|
-
};
|
|
160
|
-
/**
|
|
161
|
-
* Sends an authored request, judging EVERY hop it takes by `assertOutboundAllowed`.
|
|
162
|
-
*
|
|
163
|
-
* Checking the URL and handing it to `fetch` judged only the first hop: `fetch` follows redirects on its own, so a
|
|
164
|
-
* public server answering `302 Location: http://169.254.169.254/` took the request wherever it liked. Redirects are
|
|
165
|
-
* therefore taken manually and each destination is checked before anything is sent to it.
|
|
166
|
-
*
|
|
167
|
-
* `base` is the caller's own transport — the action runner's is budgeted and capped — so every hop is also counted
|
|
168
|
-
* against whatever that transport enforces.
|
|
169
|
-
*/
|
|
170
|
-
var fetchOutbound = async (base, url, init = {}, options = {}) => {
|
|
171
|
-
let target = url;
|
|
172
|
-
let request = init;
|
|
173
|
-
for (let hop = 0;; hop += 1) {
|
|
174
|
-
await assertOutboundAllowed(target, options);
|
|
175
|
-
const response = await base(target.toString(), {
|
|
176
|
-
...request,
|
|
177
|
-
redirect: "manual"
|
|
178
|
-
});
|
|
179
|
-
const location = response.headers.get("location");
|
|
180
|
-
if (!REDIRECT_STATUSES.includes(response.status) || !location) return response;
|
|
181
|
-
await response.body?.cancel();
|
|
182
|
-
if (hop >= MAX_REDIRECTS) throw new Error(`Request followed more than ${MAX_REDIRECTS} redirects`);
|
|
183
|
-
const next = new URL(location, target);
|
|
184
|
-
request = redirectedInit(request, response.status, next.origin !== target.origin);
|
|
185
|
-
target = next;
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
/**
|
|
189
|
-
* Holds an answer to what its reader is allowed to carry — an action's run, a page server's read of another site.
|
|
190
|
-
*
|
|
191
|
-
* Two checks rather than one, because a body arrives in two ways. `Content-Length` is refused before a byte is
|
|
192
|
-
* read, which is the cheap half; a chunked answer that declares nothing is counted AS it streams and errored the
|
|
193
|
-
* moment it goes over — so the ceiling holds for a backend that lies about its size or never states one.
|
|
194
|
-
*
|
|
195
|
-
* The cap is on one response and not on the run or the page: it exists so that a single answer cannot be unbounded, which is
|
|
196
|
-
* a different failure from a flow that makes many small calls (that is `maxRequests`).
|
|
197
|
-
*/
|
|
198
|
-
var cappedResponse = (response, maxBytes, refuse) => {
|
|
199
|
-
const declared = Number(response.headers.get("content-length") ?? "");
|
|
200
|
-
if (Number.isFinite(declared) && declared > maxBytes) throw refuse(`Response is larger than the ${String(maxBytes)} byte budget`);
|
|
201
|
-
if (!response.body) return response;
|
|
202
|
-
let seen = 0;
|
|
203
|
-
const counted = response.body.pipeThrough(new TransformStream({ transform: (chunk, controller) => {
|
|
204
|
-
seen += chunk.byteLength;
|
|
205
|
-
if (seen > maxBytes) {
|
|
206
|
-
controller.error(refuse(`Response exceeded the ${String(maxBytes)} byte budget`));
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
209
|
-
controller.enqueue(chunk);
|
|
210
|
-
} }));
|
|
211
|
-
return new Response(counted, {
|
|
212
|
-
status: response.status,
|
|
213
|
-
statusText: response.statusText,
|
|
214
|
-
headers: response.headers
|
|
215
|
-
});
|
|
216
|
-
};
|
|
217
|
-
//#endregion
|
|
218
|
-
export { assertOutboundAllowed, cappedResponse, fetchOutbound, isBlockedHost, privateOriginsOf };
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { getKeyDecoded } from "@plitzi/sdk-shared/helpers";
|
|
2
|
-
import { paintedStateCookieName } from "@plitzi/sdk-shared/state";
|
|
3
|
-
//#region src/helpers/paintedCookie.ts
|
|
4
|
-
/**
|
|
5
|
-
* The name the painted state of a server-rendered page is kept under, for this request's host.
|
|
6
|
-
*
|
|
7
|
-
* The page this server sends carries no `webKey`, so the SDK keeps its state under the web id an empty key decodes to —
|
|
8
|
-
* the same one its web storage key uses. One helper for both readers of the cookie, the render and the HTML cache key,
|
|
9
|
-
* so they cannot come to disagree about which cookie the page was drawn from.
|
|
10
|
-
*/
|
|
11
|
-
var ssrPaintedCookieName = (host) => paintedStateCookieName(getKeyDecoded("", true), host);
|
|
12
|
-
//#endregion
|
|
13
|
-
export { ssrPaintedCookieName };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
//#region src/helpers/readCookie.ts
|
|
2
|
-
var readCookie = (cookieHeader, name) => {
|
|
3
|
-
if (!cookieHeader) return;
|
|
4
|
-
for (const part of cookieHeader.split(";")) {
|
|
5
|
-
const eq = part.indexOf("=");
|
|
6
|
-
if (eq === -1) continue;
|
|
7
|
-
if (part.slice(0, eq).trim() === name) return decodeURIComponent(part.slice(eq + 1).trim());
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
//#endregion
|
|
11
|
-
export { readCookie };
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { serverLog } from "./serverLog.js";
|
|
2
|
-
//#region src/helpers/reportReactBuild.ts
|
|
3
|
-
var reported = false;
|
|
4
|
-
/**
|
|
5
|
-
* Says, once per process, that a production server is rendering with React's development build.
|
|
6
|
-
*
|
|
7
|
-
* React picks its build from `NODE_ENV` when it is first imported, not from anything a server is configured with, so
|
|
8
|
-
* `devMode: false` without `NODE_ENV=production` renders every page with the development build — measured at about 40%
|
|
9
|
-
* fewer pages a second. An `error` because it is the only level a production server shows, and a deployment that
|
|
10
|
-
* never sees this line never learns why it needs twice the CPU.
|
|
11
|
-
*/
|
|
12
|
-
var reportReactBuild = (devMode, nodeEnv = process.env.NODE_ENV) => {
|
|
13
|
-
if (reported || devMode || nodeEnv === "production") return;
|
|
14
|
-
reported = true;
|
|
15
|
-
serverLog.error("server", `NODE_ENV is ${nodeEnv === void 0 ? "unset" : `"${nodeEnv}"`}: React renders with its development build. Start the process with NODE_ENV=production.`);
|
|
16
|
-
};
|
|
17
|
-
//#endregion
|
|
18
|
-
export { reportReactBuild };
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
//#region src/helpers/resolveDebugMode.ts
|
|
2
|
-
/**
|
|
3
|
-
* Whether a render may expose debugging: the panel, element ids in the markup, the store.
|
|
4
|
-
*
|
|
5
|
-
* An SSR page loads the same SDK a client-rendered one does, so it follows the same rule: the page's `debugMode`
|
|
6
|
-
* authorizes it (`devMode` when the server did not say otherwise), and the 'plitzi_debug' cookie is only the
|
|
7
|
-
* visitor's preference within that — it exists so the SSR render matches what the client hydrates with. Being
|
|
8
|
-
* client-owned, the cookie can turn debugging off, never on: otherwise any visitor of a published site could set it
|
|
9
|
-
* and get the debug render.
|
|
10
|
-
*/
|
|
11
|
-
var resolveDebugMode = (authorized, debugCookie) => Boolean(authorized) && debugCookie !== "false";
|
|
12
|
-
//#endregion
|
|
13
|
-
export { resolveDebugMode };
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
//#region src/helpers/runMiddlewares.ts
|
|
2
|
-
var runMiddlewares = async (middlewares, req, res) => {
|
|
3
|
-
let index = 0;
|
|
4
|
-
const state = { stopped: false };
|
|
5
|
-
const next = async () => {
|
|
6
|
-
if (state.stopped) return;
|
|
7
|
-
const mw = index < middlewares.length ? middlewares[index++] : void 0;
|
|
8
|
-
if (!mw) return;
|
|
9
|
-
const nextState = { called: false };
|
|
10
|
-
await mw(req, res, async () => {
|
|
11
|
-
nextState.called = true;
|
|
12
|
-
await next();
|
|
13
|
-
});
|
|
14
|
-
if (!nextState.called) state.stopped = true;
|
|
15
|
-
};
|
|
16
|
-
await next();
|
|
17
|
-
if (req.spaceDeployment) req.ctx.spaceDeployment = req.spaceDeployment;
|
|
18
|
-
return state.stopped;
|
|
19
|
-
};
|
|
20
|
-
//#endregion
|
|
21
|
-
export { runMiddlewares };
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { LogLevel, ServerLogEvent, ServerLogger } from '@plitzi/sdk-shared';
|
|
2
|
-
/** One line for any {@link ServerLogEvent}: an HTTP request reads as an access-log line
|
|
3
|
-
* (`[SSR] 203.0.113.7 GET /pricing 200 12ms ok`), the MCP events as what happened inside one
|
|
4
|
-
* (`[MCP] tools/call plitzi_apply {operations:[3]} 41ms ok`), a server action as what its flow did
|
|
5
|
-
* (`[Action] send-invoice via call space=1 completed 12ms ok`) and a refused one as what turned it away
|
|
6
|
-
* (`[Action] checkout via webhook space=1 REFUSED invalid_signature`). Rendering is a pure format — the dispatcher
|
|
7
|
-
* already stripped query values, collected no headers, cookies or tokens, summarised tool args by shape and
|
|
8
|
-
* reduced a run to its steps; the client IP it does carry is personal data, so a sink that persists these lines
|
|
9
|
-
* must say so. */
|
|
10
|
-
export declare const renderLogEvent: (event: ServerLogEvent) => string;
|
|
11
|
-
/**
|
|
12
|
-
* How severe an event is: what it says it is, or — for a request, a tool call, a run — whether it went wrong. A
|
|
13
|
-
* refusal is never `ok` yet never the server's failure: the caller was turned away, which is a `warn`.
|
|
14
|
-
*/
|
|
15
|
-
export declare const logLevelOf: (event: ServerLogEvent) => LogLevel;
|
|
16
|
-
/** Whether a server at `threshold` says something at `level`. */
|
|
17
|
-
export declare const isLogged: (threshold: LogLevel | "silent", level: LogLevel) => boolean;
|
|
18
|
-
/** What a server says when the deployment did not choose: what went wrong in production, more while developing. */
|
|
19
|
-
export declare const defaultLogLevel: (devMode?: boolean) => LogLevel;
|
|
20
|
-
/** A drop-in `SSRServerConfig.logger` for consumers that just want the log on the console. Consumers with their
|
|
21
|
-
* own logging stack should pass their own sink instead and read the structured event. */
|
|
22
|
-
export declare const consoleLogger: ServerLogger;
|
|
23
|
-
export declare const configureServerLog: (options: {
|
|
24
|
-
level: LogLevel | "silent";
|
|
25
|
-
logger?: ServerLogger;
|
|
26
|
-
}) => void;
|
|
27
|
-
/** The server's own voice: `serverLog.error('RSC', 'element failed to resolve', error)`. Below the threshold, nothing. */
|
|
28
|
-
export declare const serverLog: {
|
|
29
|
-
error: (scope: string, message: string, cause?: unknown) => void;
|
|
30
|
-
warn: (scope: string, message: string, cause?: unknown) => void;
|
|
31
|
-
info: (scope: string, message: string, cause?: unknown) => void;
|
|
32
|
-
debug: (scope: string, message: string, cause?: unknown) => void;
|
|
33
|
-
/** Whether a level would be said — to skip building a costly message nobody will read. */
|
|
34
|
-
enabled: (level: LogLevel) => boolean;
|
|
35
|
-
/** Hands an event to a sink the consumer wired itself (`onRun`, `onReject`) only when the process would say it. */
|
|
36
|
-
emit: (logger: ServerLogger, event: ServerLogEvent) => void;
|
|
37
|
-
};
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
//#region src/helpers/serverLog.ts
|
|
2
|
-
var outcomeOf = (event) => event.ok ? "ok" : `ERROR ${event.error ?? ""}`.trim();
|
|
3
|
-
var renderRequest = (event) => {
|
|
4
|
-
const client = event.clientIp ? `${event.clientIp} ` : "";
|
|
5
|
-
const operation = event.operation ? ` ${event.operation}` : "";
|
|
6
|
-
const timing = `${Math.round(event.durationMs)}ms`;
|
|
7
|
-
return `[${event.server}] ${client}${event.method} ${event.path}${operation} ${event.status} ${timing} ${outcomeOf(event)}`;
|
|
8
|
-
};
|
|
9
|
-
var renderTool = (event) => {
|
|
10
|
-
const args = event.argsSummary ? ` ${event.argsSummary}` : "";
|
|
11
|
-
return `[MCP] tools/call ${event.name}${args} ${Math.round(event.durationMs)}ms ${outcomeOf(event)}`;
|
|
12
|
-
};
|
|
13
|
-
var renderResource = (event) => `[MCP] resources/read ${event.name} ${Math.round(event.durationMs)}ms ${outcomeOf(event)}`;
|
|
14
|
-
/** The steps go on the line only when the run ended badly. On a run that worked they are noise on every single
|
|
15
|
-
* call; on one that did not they are the answer — which step stopped, and what the ones before it did. */
|
|
16
|
-
var renderRun = (event) => {
|
|
17
|
-
const steps = event.ok || event.steps.length === 0 ? "" : ` [${event.steps.join(" → ")}]`;
|
|
18
|
-
return `[Action] ${event.name} via ${event.trigger} space=${event.spaceId} ${event.status} ${Math.round(event.durationMs)}ms ${outcomeOf(event)}${steps}`;
|
|
19
|
-
};
|
|
20
|
-
/** A refusal reads as what refused it: `[Action] checkout via webhook space=1 REFUSED invalid_signature`. The
|
|
21
|
-
* reason is the whole point of the line — "401" is what the request log already said. */
|
|
22
|
-
var renderReject = (event) => {
|
|
23
|
-
const caller = event.callerId ? ` from ${event.callerId}` : "";
|
|
24
|
-
return `[Action] ${event.name} via ${event.trigger} space=${event.spaceId} REFUSED ${event.reason}${caller} ${outcomeOf(event)}`;
|
|
25
|
-
};
|
|
26
|
-
var renderMessage = (event) => `[${event.scope}] ${event.message}${event.error ? `: ${event.error}` : ""}`;
|
|
27
|
-
/** One line for any {@link ServerLogEvent}: an HTTP request reads as an access-log line
|
|
28
|
-
* (`[SSR] 203.0.113.7 GET /pricing 200 12ms ok`), the MCP events as what happened inside one
|
|
29
|
-
* (`[MCP] tools/call plitzi_apply {operations:[3]} 41ms ok`), a server action as what its flow did
|
|
30
|
-
* (`[Action] send-invoice via call space=1 completed 12ms ok`) and a refused one as what turned it away
|
|
31
|
-
* (`[Action] checkout via webhook space=1 REFUSED invalid_signature`). Rendering is a pure format — the dispatcher
|
|
32
|
-
* already stripped query values, collected no headers, cookies or tokens, summarised tool args by shape and
|
|
33
|
-
* reduced a run to its steps; the client IP it does carry is personal data, so a sink that persists these lines
|
|
34
|
-
* must say so. */
|
|
35
|
-
var renderLogEvent = (event) => {
|
|
36
|
-
switch (event.kind) {
|
|
37
|
-
case "request": return renderRequest(event);
|
|
38
|
-
case "tool": return renderTool(event);
|
|
39
|
-
case "resource": return renderResource(event);
|
|
40
|
-
case "run": return renderRun(event);
|
|
41
|
-
case "reject": return renderReject(event);
|
|
42
|
-
case "message": return renderMessage(event);
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
var RANK = {
|
|
46
|
-
silent: 0,
|
|
47
|
-
error: 1,
|
|
48
|
-
warn: 2,
|
|
49
|
-
info: 3,
|
|
50
|
-
debug: 4
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* How severe an event is: what it says it is, or — for a request, a tool call, a run — whether it went wrong. A
|
|
54
|
-
* refusal is never `ok` yet never the server's failure: the caller was turned away, which is a `warn`.
|
|
55
|
-
*/
|
|
56
|
-
var logLevelOf = (event) => {
|
|
57
|
-
if (event.kind === "message") return event.level;
|
|
58
|
-
if (event.kind === "reject") return "warn";
|
|
59
|
-
return event.ok ? "info" : "error";
|
|
60
|
-
};
|
|
61
|
-
/** Whether a server at `threshold` says something at `level`. */
|
|
62
|
-
var isLogged = (threshold, level) => RANK[level] <= RANK[threshold];
|
|
63
|
-
/** What a server says when the deployment did not choose: what went wrong in production, more while developing. */
|
|
64
|
-
var defaultLogLevel = (devMode = false) => devMode ? "info" : "error";
|
|
65
|
-
/** A drop-in `SSRServerConfig.logger` for consumers that just want the log on the console. Consumers with their
|
|
66
|
-
* own logging stack should pass their own sink instead and read the structured event. */
|
|
67
|
-
var consoleLogger = (event) => {
|
|
68
|
-
const line = renderLogEvent(event);
|
|
69
|
-
const level = logLevelOf(event);
|
|
70
|
-
if (level === "error") console.error(line);
|
|
71
|
-
else if (level === "warn") console.warn(line);
|
|
72
|
-
else console.log(line);
|
|
73
|
-
};
|
|
74
|
-
var errorText = (cause) => cause instanceof Error ? cause.stack ?? cause.message : typeof cause === "string" ? cause : JSON.stringify(cause);
|
|
75
|
-
/**
|
|
76
|
-
* Where everything the server says that is not a request goes — one threshold and one sink for the process.
|
|
77
|
-
*
|
|
78
|
-
* Process-wide because what speaks is often created before any server exists (an adapter, a job worker) and has no
|
|
79
|
-
* config to read. `createServer` sets it from its own `logLevel` and `logger`; until then it is `error` under
|
|
80
|
-
* `NODE_ENV=production` and `info` otherwise, to the console.
|
|
81
|
-
*/
|
|
82
|
-
var state = {
|
|
83
|
-
level: process.env.NODE_ENV === "production" ? "error" : "info",
|
|
84
|
-
sink: consoleLogger
|
|
85
|
-
};
|
|
86
|
-
var configureServerLog = (options) => {
|
|
87
|
-
state.level = options.level;
|
|
88
|
-
state.sink = options.logger ?? consoleLogger;
|
|
89
|
-
};
|
|
90
|
-
var say = (level, scope, message, cause) => {
|
|
91
|
-
if (!isLogged(state.level, level)) return;
|
|
92
|
-
state.sink({
|
|
93
|
-
kind: "message",
|
|
94
|
-
level,
|
|
95
|
-
scope,
|
|
96
|
-
message,
|
|
97
|
-
ok: level !== "error",
|
|
98
|
-
...cause === void 0 ? {} : { error: errorText(cause) },
|
|
99
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
100
|
-
});
|
|
101
|
-
};
|
|
102
|
-
/** The server's own voice: `serverLog.error('RSC', 'element failed to resolve', error)`. Below the threshold, nothing. */
|
|
103
|
-
var serverLog = {
|
|
104
|
-
error: (scope, message, cause) => say("error", scope, message, cause),
|
|
105
|
-
warn: (scope, message, cause) => say("warn", scope, message, cause),
|
|
106
|
-
info: (scope, message, cause) => say("info", scope, message, cause),
|
|
107
|
-
debug: (scope, message, cause) => say("debug", scope, message, cause),
|
|
108
|
-
/** Whether a level would be said — to skip building a costly message nobody will read. */
|
|
109
|
-
enabled: (level) => isLogged(state.level, level),
|
|
110
|
-
/** Hands an event to a sink the consumer wired itself (`onRun`, `onReject`) only when the process would say it. */
|
|
111
|
-
emit: (logger, event) => {
|
|
112
|
-
if (isLogged(state.level, logLevelOf(event))) logger(event);
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
//#endregion
|
|
116
|
-
export { configureServerLog, consoleLogger, defaultLogLevel, isLogged, logLevelOf, renderLogEvent, serverLog };
|
package/dist/helpers/wsFrame.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
//#region src/helpers/wsFrame.ts
|
|
2
|
-
/** A WebSocket frame as text, whichever of its three shapes `ws` delivered it in. */
|
|
3
|
-
var frameText = (frame) => Buffer.isBuffer(frame) ? frame.toString("utf8") : Array.isArray(frame) ? Buffer.concat(frame).toString("utf8") : Buffer.from(frame).toString("utf8");
|
|
4
|
-
//#endregion
|
|
5
|
-
export { frameText };
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { serverLog } from "../../helpers/serverLog.js";
|
|
2
|
-
import { PREVIEW_TOKEN_PARAM, readDraftToken } from "../../core/previewToken.js";
|
|
3
|
-
import { createServer } from "../../core/createServer.js";
|
|
4
|
-
import { isRecord } from "@plitzi/sdk-shared/helpers";
|
|
5
|
-
import { randomBytes } from "node:crypto";
|
|
6
|
-
import path from "node:path";
|
|
7
|
-
import { mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
|
|
8
|
-
//#region src/hosts/authoringHost/index.ts
|
|
9
|
-
/** The one space the host serves, which every page is a draft of. */
|
|
10
|
-
var SPACE_ID = 1;
|
|
11
|
-
/** An id is a file's name and a query's value: nothing that could be read as a path or need escaping. */
|
|
12
|
-
var ID = /^[\w-]{1,64}$/;
|
|
13
|
-
/** A day: how long a browser remembers which page it was looking at, for a reload that lost the address. */
|
|
14
|
-
var SESSION_TTL_MS = 864e5;
|
|
15
|
-
var isDocuments = (value) => isRecord(value) && isRecord(value.schema) && isRecord(value.style);
|
|
16
|
-
/** The pages `dir` holds — what is not one is said, and left where it is. */
|
|
17
|
-
var readPages = (dir) => {
|
|
18
|
-
const pages = /* @__PURE__ */ new Map();
|
|
19
|
-
for (const file of readdirSync(dir).filter((name) => name.endsWith(".json"))) {
|
|
20
|
-
const id = file.slice(0, -5);
|
|
21
|
-
let parsed;
|
|
22
|
-
try {
|
|
23
|
-
parsed = JSON.parse(readFileSync(path.join(dir, file), "utf-8"));
|
|
24
|
-
} catch {
|
|
25
|
-
parsed = void 0;
|
|
26
|
-
}
|
|
27
|
-
if (ID.test(id) && isDocuments(parsed)) pages.set(id, {
|
|
28
|
-
schema: parsed.schema,
|
|
29
|
-
style: parsed.style
|
|
30
|
-
});
|
|
31
|
-
else serverLog.warn("AuthoringHost", `${path.join(dir, file)} is not a page this host wrote: left out`);
|
|
32
|
-
}
|
|
33
|
-
return pages;
|
|
34
|
-
};
|
|
35
|
-
var createAuthoringHost = ({ dir, frameAncestors, ...config }) => {
|
|
36
|
-
mkdirSync(dir, { recursive: true });
|
|
37
|
-
const pages = readPages(dir);
|
|
38
|
-
const fileOf = (id) => path.join(dir, `${id}.json`);
|
|
39
|
-
const keep = (id, data) => {
|
|
40
|
-
writeFileSync(fileOf(id), JSON.stringify({
|
|
41
|
-
schema: data.schema,
|
|
42
|
-
style: data.style
|
|
43
|
-
}));
|
|
44
|
-
pages.set(id, {
|
|
45
|
-
schema: data.schema,
|
|
46
|
-
style: data.style
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
const drop = (id) => {
|
|
50
|
-
if (!pages.delete(id)) return false;
|
|
51
|
-
rmSync(fileOf(id), { force: true });
|
|
52
|
-
return true;
|
|
53
|
-
};
|
|
54
|
-
const draftStore = {
|
|
55
|
-
put: (token, data) => {
|
|
56
|
-
if (ID.test(token)) keep(token, data);
|
|
57
|
-
},
|
|
58
|
-
take: (token) => {
|
|
59
|
-
const data = pages.get(token);
|
|
60
|
-
return data ? {
|
|
61
|
-
data,
|
|
62
|
-
reusable: true,
|
|
63
|
-
spaceId: SPACE_ID
|
|
64
|
-
} : void 0;
|
|
65
|
-
},
|
|
66
|
-
drop: (token) => {
|
|
67
|
-
drop(token);
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
const deployment = {
|
|
71
|
-
spaceId: SPACE_ID,
|
|
72
|
-
environment: "main",
|
|
73
|
-
revision: 0,
|
|
74
|
-
...frameAncestors ? { frameAncestors } : {}
|
|
75
|
-
};
|
|
76
|
-
const server = createServer({
|
|
77
|
-
livePages: true,
|
|
78
|
-
...config,
|
|
79
|
-
preview: {
|
|
80
|
-
sessionTtlMs: SESSION_TTL_MS,
|
|
81
|
-
...config.preview
|
|
82
|
-
},
|
|
83
|
-
draftStore,
|
|
84
|
-
adapters: {
|
|
85
|
-
getOfflineData: () => Promise.resolve(void 0),
|
|
86
|
-
getSpaceDeployment: (req) => {
|
|
87
|
-
const id = readDraftToken(req);
|
|
88
|
-
if (id === void 0) return Promise.resolve({ error: {
|
|
89
|
-
code: 404,
|
|
90
|
-
message: `Nothing here: each page of this host is at the address put() answered — /?${PREVIEW_TOKEN_PARAM}=<id>`
|
|
91
|
-
} });
|
|
92
|
-
if (!pages.has(id)) return Promise.resolve({ error: {
|
|
93
|
-
code: 404,
|
|
94
|
-
message: `No page "${id}" here: put() it, or it was dropped`
|
|
95
|
-
} });
|
|
96
|
-
return Promise.resolve(deployment);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
return {
|
|
101
|
-
server,
|
|
102
|
-
put: (documents, { id = randomBytes(16).toString("base64url") } = {}) => {
|
|
103
|
-
if (!ID.test(id)) throw new Error(`A page id is letters, digits, "-" and "_", up to 64 of them — not "${id}"`);
|
|
104
|
-
const replacing = pages.has(id);
|
|
105
|
-
keep(id, documents);
|
|
106
|
-
const updated = replacing ? server.updatePages(documents, { draft: id }) : 0;
|
|
107
|
-
return {
|
|
108
|
-
id,
|
|
109
|
-
path: `/?${PREVIEW_TOKEN_PARAM}=${id}`,
|
|
110
|
-
updated
|
|
111
|
-
};
|
|
112
|
-
},
|
|
113
|
-
drop,
|
|
114
|
-
ids: () => [...pages.keys()]
|
|
115
|
-
};
|
|
116
|
-
};
|
|
117
|
-
//#endregion
|
|
118
|
-
export { createAuthoringHost };
|