@plitzi/sdk-server 0.38.20 → 0.38.22
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 +141 -0
- package/README.md +2 -2
- package/dist/actions.d.ts +6 -0
- package/dist/actions.js +2 -1
- package/dist/core/auth/createAuth.d.ts +1 -1
- package/dist/core/auth/tokens.d.ts +1 -1
- package/dist/core/configSeam.js +12 -2
- package/dist/core/services/functionRoutes.js +7 -2
- package/dist/core/services/realtime.js +5 -2
- package/dist/functions-api.d.ts +176 -3
- package/dist/functions.d.ts +3 -1
- package/dist/functions.js +2 -1
- package/dist/helpers/serverLog.d.ts +1 -1
- package/dist/helpers/serverLog.js +1 -1
- package/dist/hosts/project/plugins.js +20 -3
- package/dist/hosts/project/serveProject.js +16 -1
- package/dist/modules/actions/index.js +17 -4
- package/dist/modules/actions/jobs/index.d.ts +4 -3
- package/dist/modules/actions/jobs/index.js +2 -1
- package/dist/modules/actions/jobs/later.d.ts +2 -2
- package/dist/modules/actions/jobs/later.js +5 -2
- package/dist/modules/actions/jobs/memoryQueue.d.ts +4 -4
- package/dist/modules/actions/jobs/memoryQueue.js +69 -25
- package/dist/modules/actions/jobs/scheduler.d.ts +2 -2
- package/dist/modules/actions/jobs/scheduler.js +5 -2
- package/dist/modules/actions/jobs/worker.d.ts +6 -3
- package/dist/modules/actions/jobs/worker.js +104 -10
- package/dist/modules/actions/runtime/errors.d.ts +9 -1
- package/dist/modules/actions/runtime/errors.js +12 -2
- package/dist/modules/actions/runtime/runAction.d.ts +5 -2
- package/dist/modules/actions/runtime/runAction.js +5 -3
- package/dist/modules/actions/runtime/taskContext.d.ts +12 -3
- package/dist/modules/actions/runtime/taskContext.js +9 -1
- package/dist/modules/actions/types.d.ts +22 -6
- package/dist/modules/functions/capabilities.js +124 -13
- package/dist/modules/functions/config.d.ts +20 -0
- package/dist/modules/functions/context.d.ts +2 -2
- package/dist/modules/functions/context.js +16 -3
- package/dist/modules/functions/contract.d.ts +97 -3
- package/dist/modules/functions/driver.js +136 -9
- package/dist/modules/functions/jobControl.d.ts +21 -0
- package/dist/modules/functions/jobControl.js +43 -0
- package/dist/modules/functions/jobs.d.ts +98 -0
- package/dist/modules/functions/jobs.js +438 -0
- package/dist/modules/functions/manifest.d.ts +2 -0
- package/dist/modules/functions/manifest.js +37 -4
- package/dist/modules/functions/native.js +2 -1
- package/dist/modules/functions/oauth.d.ts +3 -2
- package/dist/modules/functions/oauth.js +53 -19
- package/dist/modules/functions/protocol.d.ts +98 -7
- package/dist/modules/functions/protocol.js +15 -1
- package/dist/modules/functions/routes.d.ts +9 -1
- package/dist/modules/functions/routes.js +50 -25
- package/dist/modules/functions/runner/messages.d.ts +0 -1
- package/dist/modules/functions/runner/messages.js +46 -5
- package/dist/modules/functions/runner/remote.js +60 -8
- package/dist/modules/functions/runner/service.js +54 -8
- package/dist/modules/functions/sandbox/guest.js +5 -3
- package/dist/modules/functions/sandbox/isolate.js +7 -8
- package/dist/modules/functions/space.js +4 -4
- package/dist/modules/mongo/jobQueue.d.ts +3 -3
- package/dist/modules/mongo/jobQueue.js +137 -26
- package/dist/modules/mysql/jobs/jobQueue.d.ts +3 -3
- package/dist/modules/mysql/jobs/jobQueue.js +97 -33
- package/dist/modules/mysql/jobs/schema.js +38 -11
- package/dist/modules/realtime/handlers.d.ts +5 -2
- package/dist/modules/realtime/handlers.js +15 -4
- package/dist/modules/realtime/index.d.ts +11 -1
- package/dist/modules/realtime/index.js +8 -1
- package/dist/modules/realtime/jobs.d.ts +20 -0
- package/dist/modules/realtime/jobs.js +41 -0
- package/dist/modules/realtime/retained.d.ts +3 -2
- package/dist/modules/realtime/retained.js +2 -2
- package/dist/modules/realtime/socket.d.ts +4 -1
- package/dist/modules/realtime/socket.js +2 -2
- package/dist/modules/rsc/resolveRscData.js +2 -1
- package/dist/modules/runtime/host.js +1 -1
- package/dist/modules/runtime/runner.d.ts +1 -1
- package/dist/modules/runtime/runner.js +12 -2
- package/dist/modules/runtime/stages.js +1 -1
- package/dist/modules/ssr/applySSRResult.d.ts +5 -0
- package/dist/modules/ssr/applySSRResult.js +8 -1
- package/dist/modules/ssr/buildBody.js +2 -1
- package/dist/modules/ssr/prepareRender.d.ts +3 -0
- package/dist/modules/ssr/prepareRender.js +17 -5
- package/dist/modules/ssr/spaceDocument.d.ts +2 -1
- package/dist/modules/ssr/spaceDocument.js +14 -5
- package/dist/modules/ssr/streamBody.js +2 -1
- package/package.json +3 -3
- package/skills/plitzi-authoring/reference/auth.md +6 -0
- package/skills/plitzi-authoring/reference/authoring-errors.md +1 -0
- package/skills/plitzi-authoring/reference/plugin-reach.md +3 -0
- package/skills/plitzi-authoring/reference/realtime.md +4 -0
- package/dist/adapters/cloudAdapters.test.d.ts +0 -1
- package/dist/adapters/jsonAdapters.test.d.ts +0 -1
- package/dist/adapters/space/space.test.d.ts +0 -1
- package/dist/core/auth/api.test.d.ts +0 -1
- package/dist/core/auth/authorize.test.d.ts +0 -1
- package/dist/core/auth/createAuth.test.d.ts +0 -1
- package/dist/core/auth/csrf.test.d.ts +0 -1
- package/dist/core/auth/domains.test.d.ts +0 -1
- package/dist/core/auth/identity.test.d.ts +0 -1
- package/dist/core/auth/lifecycle.test.d.ts +0 -1
- package/dist/core/auth/oauth/oauth.test.d.ts +0 -1
- package/dist/core/auth/redirects.test.d.ts +0 -1
- package/dist/core/auth/routes.test.d.ts +0 -1
- package/dist/core/auth/session.test.d.ts +0 -1
- package/dist/core/auth/spaceTokens.test.d.ts +0 -1
- package/dist/core/auth/throttle.test.d.ts +0 -1
- package/dist/core/auth/tokens.test.d.ts +0 -1
- package/dist/core/auth/totp.test.d.ts +0 -1
- package/dist/core/configSeam.test.d.ts +0 -1
- package/dist/core/createServer.actions.test.d.ts +0 -1
- package/dist/core/createServer.functions.test.d.ts +0 -1
- package/dist/core/createServer.livePages.test.d.ts +0 -1
- package/dist/core/createServer.notFound.test.d.ts +0 -1
- package/dist/core/createServer.oauth.test.d.ts +0 -1
- package/dist/core/createServer.publicData.test.d.ts +0 -1
- package/dist/core/createServer.test.d.ts +0 -1
- package/dist/core/fontStore.test.d.ts +0 -1
- package/dist/core/freePort.test.d.ts +0 -1
- package/dist/core/handlers/csrfMiddleware.test.d.ts +0 -1
- package/dist/core/handlers/handlers.test.d.ts +0 -1
- package/dist/core/handlers/socialRouteHandlers.test.d.ts +0 -1
- package/dist/core/http/dispatcher.test.d.ts +0 -1
- package/dist/core/http/stages/crossSiteWrites.test.d.ts +0 -1
- package/dist/core/http/stages/exchangeRoute.test.d.ts +0 -1
- package/dist/core/http/stages/images.test.d.ts +0 -1
- package/dist/core/http/stages/middlewares.test.d.ts +0 -1
- package/dist/core/http/stages/sessionRenewal.test.d.ts +0 -1
- package/dist/core/http/stages/signInRoute.test.d.ts +0 -1
- package/dist/core/oauth/authorize.test.d.ts +0 -1
- package/dist/core/oauth/register.test.d.ts +0 -1
- package/dist/core/oauth/token.test.d.ts +0 -1
- package/dist/core/requestParser.test.d.ts +0 -1
- package/dist/core/server/baseServer.test.d.ts +0 -1
- package/dist/core/server/closeOnSignals.test.d.ts +0 -1
- package/dist/core/server/drain.test.d.ts +0 -1
- package/dist/core/server/fleet/channel.test.d.ts +0 -1
- package/dist/core/server/fleet/fixtures/fleetServer.d.ts +0 -1
- package/dist/core/server/fleet/fleet.integration.test.d.ts +0 -1
- package/dist/core/server/fleet/relay.test.d.ts +0 -1
- package/dist/core/server/fleet/role.test.d.ts +0 -1
- package/dist/core/server/fleet/supervisor.test.d.ts +0 -1
- package/dist/core/services/resolve.test.d.ts +0 -1
- package/dist/core/staticFiles.test.d.ts +0 -1
- package/dist/env.test.d.ts +0 -1
- package/dist/helpers/atomicFile.test.d.ts +0 -1
- package/dist/helpers/buildResponseHelpers.test.d.ts +0 -1
- package/dist/helpers/buildServerInfo.test.d.ts +0 -1
- package/dist/helpers/cache/CompressedFileCache.test.d.ts +0 -1
- package/dist/helpers/cache/cacheManager.test.d.ts +0 -1
- package/dist/helpers/cache/keys.test.d.ts +0 -1
- package/dist/helpers/compress.test.d.ts +0 -1
- package/dist/helpers/hydrationPayload.test.d.ts +0 -1
- package/dist/helpers/offlineDataLoader.test.d.ts +0 -1
- package/dist/helpers/onAbort.test.d.ts +0 -1
- package/dist/helpers/outboundGuard.test.d.ts +0 -1
- package/dist/helpers/reportReactBuild.test.d.ts +0 -1
- package/dist/helpers/resolveDebugMode.test.d.ts +0 -1
- package/dist/helpers/serverLog.test.d.ts +0 -1
- package/dist/hosts/authoringHost/index.test.d.ts +0 -1
- package/dist/hosts/project/serveProject.test.d.ts +0 -1
- package/dist/layers.test.d.ts +0 -1
- package/dist/middlewares/spaceDeployment.test.d.ts +0 -1
- package/dist/modules/actions/connectorWrite.test.d.ts +0 -1
- package/dist/modules/actions/jobs/failureStreak.test.d.ts +0 -1
- package/dist/modules/actions/jobs/later.test.d.ts +0 -1
- package/dist/modules/actions/jobs/memoryStores.test.d.ts +0 -1
- package/dist/modules/actions/jobs/scheduler.test.d.ts +0 -1
- package/dist/modules/actions/jobs/testing/jobQueueContract.d.ts +0 -25
- package/dist/modules/actions/jobs/worker.test.d.ts +0 -1
- package/dist/modules/actions/moduleFor.test.d.ts +0 -1
- package/dist/modules/actions/runtime/check.test.d.ts +0 -1
- package/dist/modules/actions/runtime/credentials.test.d.ts +0 -1
- package/dist/modules/actions/runtime/email.test.d.ts +0 -1
- package/dist/modules/actions/runtime/fileKv.test.d.ts +0 -1
- package/dist/modules/actions/runtime/flags.test.d.ts +0 -1
- package/dist/modules/actions/runtime/guards.test.d.ts +0 -1
- package/dist/modules/actions/runtime/kvStore.test.d.ts +0 -1
- package/dist/modules/actions/runtime/namespaceKv.test.d.ts +0 -1
- package/dist/modules/actions/runtime/redisKv.integration.test.d.ts +0 -1
- package/dist/modules/actions/runtime/renderResolver.test.d.ts +0 -1
- package/dist/modules/actions/runtime/renderShare.test.d.ts +0 -1
- package/dist/modules/actions/runtime/runAction.test.d.ts +0 -1
- package/dist/modules/actions/runtime/runLogger.test.d.ts +0 -1
- package/dist/modules/actions/runtime/signing.test.d.ts +0 -1
- package/dist/modules/actions/taskCatalog.test.d.ts +0 -1
- package/dist/modules/actions/tasks/db.test.d.ts +0 -1
- package/dist/modules/actions/tasks/email.test.d.ts +0 -1
- package/dist/modules/actions/tasks/http.test.d.ts +0 -1
- package/dist/modules/actions/tasks/kv.test.d.ts +0 -1
- package/dist/modules/actions/transport/callHandler.test.d.ts +0 -1
- package/dist/modules/actions/transport/webhookHandler.test.d.ts +0 -1
- package/dist/modules/connectors/engine.test.d.ts +0 -1
- package/dist/modules/connectors/projection.test.d.ts +0 -1
- package/dist/modules/connectors/resolver.test.d.ts +0 -1
- package/dist/modules/functions/build.test.d.ts +0 -1
- package/dist/modules/functions/load.test.d.ts +0 -1
- package/dist/modules/functions/local.test.d.ts +0 -1
- package/dist/modules/functions/manifest.test.d.ts +0 -1
- package/dist/modules/functions/native.test.d.ts +0 -1
- package/dist/modules/functions/oauth.test.d.ts +0 -1
- package/dist/modules/functions/plugins.test.d.ts +0 -1
- package/dist/modules/functions/routes.test.d.ts +0 -1
- package/dist/modules/functions/runner/remote.test.d.ts +0 -1
- package/dist/modules/functions/sandbox/isolate.test.d.ts +0 -1
- package/dist/modules/functions/testing/tasksOf.d.ts +0 -4
- package/dist/modules/images/imageProxy.test.d.ts +0 -1
- package/dist/modules/images/transform.test.d.ts +0 -1
- package/dist/modules/mongo/stores.integration.test.d.ts +0 -1
- package/dist/modules/mysql/accounts.test.d.ts +0 -1
- package/dist/modules/mysql/jobs/stores.integration.test.d.ts +0 -1
- package/dist/modules/mysql/schema.test.d.ts +0 -1
- package/dist/modules/mysql/store.integration.test.d.ts +0 -1
- package/dist/modules/realtime/realtime.test.d.ts +0 -1
- package/dist/modules/realtime/redisPubSub.test.d.ts +0 -1
- package/dist/modules/realtime/retained.test.d.ts +0 -1
- package/dist/modules/realtime/socket.test.d.ts +0 -1
- package/dist/modules/rsc/connectorRscData.test.d.ts +0 -1
- package/dist/modules/rsc/handler.test.d.ts +0 -1
- package/dist/modules/rsc/publicFileResolver.test.d.ts +0 -1
- package/dist/modules/rsc/resolveRscData.test.d.ts +0 -1
- package/dist/modules/runtime/elsewhere.test.d.ts +0 -1
- package/dist/modules/runtime/entry.test.d.ts +0 -1
- package/dist/modules/runtime/inside.test.d.ts +0 -1
- package/dist/modules/runtime/ownServer.test.d.ts +0 -1
- package/dist/modules/runtime/runtime.test.d.ts +0 -1
- package/dist/modules/sqlite/kv.test.d.ts +0 -1
- package/dist/modules/ssr/draftSession.test.d.ts +0 -1
- package/dist/modules/ssr/loadPluginComponents.test.d.ts +0 -1
- package/dist/modules/ssr/metering.test.d.ts +0 -1
- package/dist/modules/ssr/prepareRender.test.d.ts +0 -1
- package/dist/modules/ssr/redirect.test.d.ts +0 -1
- package/dist/modules/ssr/registerExternalPlugins.test.d.ts +0 -1
- package/dist/modules/ssr/reportMissingPlugins.test.d.ts +0 -1
- package/dist/modules/ssr/resolvePageSeo.test.d.ts +0 -1
- package/dist/modules/ssr/spaceDocument.test.d.ts +0 -1
- package/dist/modules/ssr/template.test.d.ts +0 -1
- package/dist/modules/ssr/testing/offlineData.d.ts +0 -5
- package/dist/modules/ssr/vendor.test.d.ts +0 -1
- package/dist/plugins/compile.test.d.ts +0 -1
- package/dist/plugins/copy.test.d.ts +0 -1
- package/dist/plugins/manager.test.d.ts +0 -1
- package/dist/plugins/validate.test.d.ts +0 -1
|
@@ -9,7 +9,7 @@ import { createFunctionsDriver, describeFunctions } from "../functions/driver.js
|
|
|
9
9
|
* A runtime's functions as a runner: the same protocol as the sandbox's, answered by code loaded in this process. The
|
|
10
10
|
* driver is the sandbox's own (`createFunctionsDriver`), so a task behaves the same in both — its `ctx` is calls to the
|
|
11
11
|
* platform, `ctx.kv.change` the same loop, a refusal the same answer. What it does not share is the isolate: there are
|
|
12
|
-
* no limits here but the platform's clock, since this process is the space's alone.
|
|
12
|
+
* no limits here but the platform's clock, since this process is the space's alone — and a route's answer streams.
|
|
13
13
|
*
|
|
14
14
|
* The bundle a request names is not asked for: the code is the one this runtime was started with.
|
|
15
15
|
*/
|
|
@@ -21,7 +21,17 @@ var createRuntimeRunner = (definition = {}) => ({
|
|
|
21
21
|
signal,
|
|
22
22
|
responseOf: (wire) => responseOf(wireResponseFrom(wire)),
|
|
23
23
|
requestOf: requestFromWire,
|
|
24
|
-
wireOfResponse: async (response) =>
|
|
24
|
+
wireOfResponse: async (response) => {
|
|
25
|
+
if (!(response instanceof Response)) return;
|
|
26
|
+
if (!response.body) return wireResponseOf(response);
|
|
27
|
+
return {
|
|
28
|
+
streamed: true,
|
|
29
|
+
status: response.status,
|
|
30
|
+
statusText: response.statusText,
|
|
31
|
+
headers: [...response.headers],
|
|
32
|
+
body: response.body
|
|
33
|
+
};
|
|
34
|
+
},
|
|
25
35
|
changeKv,
|
|
26
36
|
refusal: (message) => new ActionRefusal(message)
|
|
27
37
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { clientIp, requestOrigin } from "../../core/requestParser.js";
|
|
2
|
-
import { endpointFor, endpointProblem } from "./contract.js";
|
|
3
2
|
import { webRequestOf, writeWebResponse } from "../../core/http/webExchange.js";
|
|
3
|
+
import { endpointFor, endpointProblem } from "./contract.js";
|
|
4
4
|
import { PLATFORM_HEADERS } from "./host.js";
|
|
5
5
|
import http from "node:http";
|
|
6
6
|
import https from "node:https";
|
|
@@ -11,3 +11,8 @@ export declare const isReusable: (result: SSRRenderResult) => boolean;
|
|
|
11
11
|
* own first: a redirect, or a status the navigation set.
|
|
12
12
|
*/
|
|
13
13
|
export declare const withNotFound: (result: SSRRenderResult, notFound: boolean) => void;
|
|
14
|
+
/**
|
|
15
|
+
* A page withheld from this visitor answers 401 signed out and 403 signed in without the access — unless the render
|
|
16
|
+
* decided something of its own first: the redirect to signing in a page declares, say.
|
|
17
|
+
*/
|
|
18
|
+
export declare const withRefusal: (result: SSRRenderResult, refused: "unauthenticated" | "forbidden" | undefined) => void;
|
|
@@ -23,5 +23,12 @@ var isReusable = (result) => result.status === void 0 || result.status === 200;
|
|
|
23
23
|
var withNotFound = (result, notFound) => {
|
|
24
24
|
if (notFound && result.redirect === void 0 && result.status === void 0) result.status = 404;
|
|
25
25
|
};
|
|
26
|
+
/**
|
|
27
|
+
* A page withheld from this visitor answers 401 signed out and 403 signed in without the access — unless the render
|
|
28
|
+
* decided something of its own first: the redirect to signing in a page declares, say.
|
|
29
|
+
*/
|
|
30
|
+
var withRefusal = (result, refused) => {
|
|
31
|
+
if (refused && result.redirect === void 0 && result.status === void 0) result.status = refused === "unauthenticated" ? 401 : 403;
|
|
32
|
+
};
|
|
26
33
|
//#endregion
|
|
27
|
-
export { applySSRResult, isReusable, withNotFound };
|
|
34
|
+
export { applySSRResult, isReusable, withNotFound, withRefusal };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { withNotFound } from "./applySSRResult.js";
|
|
1
|
+
import { withNotFound, withRefusal } from "./applySSRResult.js";
|
|
2
2
|
import Component from "./Component.js";
|
|
3
3
|
import { prepareRender } from "./prepareRender.js";
|
|
4
4
|
import { renderToString } from "react-dom/server";
|
|
@@ -14,6 +14,7 @@ var buildBody = async (req, config, spaceId, environment, revision, renderFn, pl
|
|
|
14
14
|
})).trim();
|
|
15
15
|
metrics?.record("react", Math.round(performance.now() - reactStart));
|
|
16
16
|
withNotFound(result, prep.notFound);
|
|
17
|
+
withRefusal(result, prep.refused);
|
|
17
18
|
if (result.redirect !== void 0) return {
|
|
18
19
|
result,
|
|
19
20
|
cacheable: prep.cacheable
|
|
@@ -3,6 +3,7 @@ import { TtlCache } from '../../helpers/cache';
|
|
|
3
3
|
import { RequestMetrics } from '../../helpers/metrics';
|
|
4
4
|
import { PluginManager } from '../../plugins/manager';
|
|
5
5
|
import { Environment, OfflineDataRaw, PluginEntry, SSRPageServerConfig, SSRRequest, SSRTemplateProps } from '@plitzi/sdk-shared';
|
|
6
|
+
import { PageWithheld } from '@plitzi/sdk-shared/schema';
|
|
6
7
|
export type RenderPrep = {
|
|
7
8
|
componentProps: ComponentProps;
|
|
8
9
|
entries: PluginEntry[];
|
|
@@ -13,5 +14,7 @@ export type RenderPrep = {
|
|
|
13
14
|
cacheable: boolean;
|
|
14
15
|
/** A server provider of the page said its address shows nothing (`notFound`): sent with status 404. */
|
|
15
16
|
notFound: boolean;
|
|
17
|
+
/** The page asked for was withheld from this visitor (`access`): sent with 401 or 403, its refusal drawn. */
|
|
18
|
+
refused?: PageWithheld;
|
|
16
19
|
};
|
|
17
20
|
export declare const prepareRender: (req: SSRRequest, config: SSRPageServerConfig, spaceId: number, environment: Environment, revision: number, pluginManager: PluginManager, offlineDataCache?: TtlCache<string>, metrics?: RequestMetrics, offlineDataOverride?: OfflineDataRaw) => Promise<RenderPrep>;
|
|
@@ -21,7 +21,7 @@ import { sdkAssetVersion } from "../../core/sdkAssets.js";
|
|
|
21
21
|
import { buildServerInfo } from "../../helpers/buildServerInfo.js";
|
|
22
22
|
import { resolveDebugMode } from "../../helpers/resolveDebugMode.js";
|
|
23
23
|
import { flagUserFromSSR, flagValues, resolveFlags } from "@plitzi/sdk-shared/flags";
|
|
24
|
-
import { collectServerElements, notFoundProvider, pageElementTypes, pageNotFound, pageServerContext } from "@plitzi/sdk-shared/schema";
|
|
24
|
+
import { collectServerElements, notFoundProvider, pageElementTypes, pageNotFound, pageServerContext, pageWithheldOf, withholdPages } from "@plitzi/sdk-shared/schema";
|
|
25
25
|
import { debugCookieName } from "@plitzi/sdk-shared/devTools";
|
|
26
26
|
import { themeFromCookies } from "@plitzi/sdk-shared/theme/cookie";
|
|
27
27
|
import { paintedKeys, paintedStateFor } from "@plitzi/sdk-shared/state";
|
|
@@ -57,10 +57,21 @@ var prepareRender = async (req, config, spaceId, environment, revision, pluginMa
|
|
|
57
57
|
if (cachedOfflineStr) return Promise.resolve(JSON.parse(cachedOfflineStr));
|
|
58
58
|
return m("schema", () => config.adapters.getOfflineData(spaceId, environment, revision));
|
|
59
59
|
});
|
|
60
|
-
const
|
|
60
|
+
const rawOfflineData = await loadOfflineData();
|
|
61
|
+
/**
|
|
62
|
+
* The space as this visitor may be sent it: a page whose `access` they do not meet is emptied before anything reads
|
|
63
|
+
* it — the render, the payload, the document the browser fetches — so its content never leaves this server for them.
|
|
64
|
+
* The shared cache below keeps the whole space; only what is sent is cut.
|
|
65
|
+
*/
|
|
66
|
+
const withholding = rawOfflineData ? withholdPages(rawOfflineData.schema, req.ctx.user) : void 0;
|
|
67
|
+
const offlineData = rawOfflineData && withholding && withholding.withheld.length > 0 ? {
|
|
68
|
+
...rawOfflineData,
|
|
69
|
+
schema: withholding.schema
|
|
70
|
+
} : rawOfflineData;
|
|
61
71
|
const rscPath = resolveRscEndpoint(config);
|
|
62
72
|
const schema = offlineData?.schema;
|
|
63
73
|
const pageMatch = schema !== void 0 ? matchRscPage(schema, req.path, req.ctx.user) : void 0;
|
|
74
|
+
const refused = pageMatch ? pageWithheldOf(schema?.flat[pageMatch.pageId]?.attributes) : void 0;
|
|
64
75
|
const rscEnabled = rscPath !== void 0 && schema !== void 0 && schema.rsc?.enabled !== false;
|
|
65
76
|
const debugAuthorized = !Boolean(req.query["__pt"]) && authorizesDebugging(config, schema?.settings);
|
|
66
77
|
const flagOverrides = await requestFlagOverrides(config, req, {
|
|
@@ -99,7 +110,7 @@ var prepareRender = async (req, config, spaceId, environment, revision, pluginMa
|
|
|
99
110
|
realtimeTransport: realtimeModuleFor(config)?.transport,
|
|
100
111
|
imagePath: imagesPathOf(config)
|
|
101
112
|
});
|
|
102
|
-
if (offlineDataOverride === void 0 && !cachedOfflineStr && offlineCacheKey &&
|
|
113
|
+
if (offlineDataOverride === void 0 && !cachedOfflineStr && offlineCacheKey && rawOfflineData !== void 0) offlineDataCache?.set(offlineCacheKey, JSON.stringify(rawOfflineData));
|
|
103
114
|
const version = config.assetVersion ?? sdkAssetVersion();
|
|
104
115
|
const v = version ? `?v=${version}` : "";
|
|
105
116
|
const sdkDevToolsStylePath = `/sdk-assets/plitzi-sdk-devtools.css${v}`;
|
|
@@ -173,7 +184,7 @@ var prepareRender = async (req, config, spaceId, environment, revision, pluginMa
|
|
|
173
184
|
* Not for a draft, which no other process could produce when the fetch reaches it, and not for a deployment's own
|
|
174
185
|
* template, which was written for the space inline; a page with no script needs no space at all.
|
|
175
186
|
*/
|
|
176
|
-
const publishedDocument = offlineData !== void 0 && offlineDataOverride === void 0 && config.templateFn === void 0 && config.ssrOnly !== true ? publishSpaceDocument(spaceId, environment, spaceDocument(offlineData)) : void 0;
|
|
187
|
+
const publishedDocument = offlineData !== void 0 && offlineDataOverride === void 0 && config.templateFn === void 0 && config.ssrOnly !== true ? publishSpaceDocument(spaceId, environment, spaceDocument(offlineData), withholding?.kept ?? []) : void 0;
|
|
177
188
|
/**
|
|
178
189
|
* A page that named its space with a token in its address (`?access-token=`, how a host serving many spaces is asked
|
|
179
190
|
* for one) has its document asked for the same way: fetched bare, the host's own space answered it — another space's
|
|
@@ -291,7 +302,8 @@ var prepareRender = async (req, config, spaceId, environment, revision, pluginMa
|
|
|
291
302
|
offlineData: offlineDataStr
|
|
292
303
|
},
|
|
293
304
|
cacheable: actionRuns === void 0 && forcedFlags === void 0,
|
|
294
|
-
notFound
|
|
305
|
+
notFound,
|
|
306
|
+
...refused ? { refused } : {}
|
|
295
307
|
};
|
|
296
308
|
};
|
|
297
309
|
//#endregion
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { TtlCache } from '../../helpers/cache';
|
|
2
2
|
import { SpaceDocument } from '../../helpers/hydrationPayload';
|
|
3
3
|
import { Environment, SSRPageServerConfig, SSRRequest, SSRResponseHelpers } from '@plitzi/sdk-shared';
|
|
4
|
+
import { PageAccess } from '@plitzi/sdk-shared/schema';
|
|
4
5
|
/**
|
|
5
6
|
* The whole space as a resource of its own, beside the page rather than inside it.
|
|
6
7
|
*
|
|
@@ -13,7 +14,7 @@ import { Environment, SSRPageServerConfig, SSRRequest, SSRResponseHelpers } from
|
|
|
13
14
|
*/
|
|
14
15
|
export declare const SPACE_DOCUMENT_PATH = "/_plitzi/space/";
|
|
15
16
|
/** Where the page fetches `document` from — and the promise that this process can answer it. */
|
|
16
|
-
export declare const publishSpaceDocument: (spaceId: number, environment: Environment, document: SpaceDocument) => string;
|
|
17
|
+
export declare const publishSpaceDocument: (spaceId: number, environment: Environment, document: SpaceDocument, kept?: PageAccess[]) => string;
|
|
17
18
|
/**
|
|
18
19
|
* Answers `/_plitzi/space/<hash>.json` for the space this host serves, behind the same gates as its pages.
|
|
19
20
|
*
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { buildOfflineDataCacheKey } from "../../helpers/cache/keys.js";
|
|
2
2
|
import { spaceDocument } from "../../helpers/hydrationPayload.js";
|
|
3
|
+
import { mayReceive, withholdPages } from "@plitzi/sdk-shared/schema";
|
|
3
4
|
//#region src/modules/ssr/spaceDocument.ts
|
|
4
5
|
/**
|
|
5
6
|
* The whole space as a resource of its own, beside the page rather than inside it.
|
|
@@ -21,10 +22,13 @@ var RECENT = 8;
|
|
|
21
22
|
var recent = /* @__PURE__ */ new Map();
|
|
22
23
|
var recentKey = (spaceId, environment, hash) => `${String(spaceId)}|${environment}|${hash}`;
|
|
23
24
|
/** Where the page fetches `document` from — and the promise that this process can answer it. */
|
|
24
|
-
var publishSpaceDocument = (spaceId, environment, document) => {
|
|
25
|
+
var publishSpaceDocument = (spaceId, environment, document, kept = []) => {
|
|
25
26
|
const key = recentKey(spaceId, environment, document.hash);
|
|
26
27
|
recent.delete(key);
|
|
27
|
-
recent.set(key,
|
|
28
|
+
recent.set(key, {
|
|
29
|
+
json: document.json,
|
|
30
|
+
kept
|
|
31
|
+
});
|
|
28
32
|
for (const oldest of recent.keys()) {
|
|
29
33
|
if (recent.size <= RECENT) break;
|
|
30
34
|
recent.delete(oldest);
|
|
@@ -48,7 +52,8 @@ var handleSpaceDocument = async (req, res, config, offlineDataCache) => {
|
|
|
48
52
|
res.end();
|
|
49
53
|
return;
|
|
50
54
|
}
|
|
51
|
-
|
|
55
|
+
const known = recent.get(recentKey(spaceId, environment, hash));
|
|
56
|
+
let json = known && mayReceive(known.kept, req.ctx.user) ? known.json : void 0;
|
|
52
57
|
let current = json !== void 0;
|
|
53
58
|
if (json === void 0) {
|
|
54
59
|
const cacheKey = environment !== "main" ? buildOfflineDataCacheKey(spaceId, environment, revision, flagsVersion) : void 0;
|
|
@@ -63,8 +68,12 @@ var handleSpaceDocument = async (req, res, config, offlineDataCache) => {
|
|
|
63
68
|
}));
|
|
64
69
|
return;
|
|
65
70
|
}
|
|
66
|
-
const
|
|
67
|
-
|
|
71
|
+
const { schema, withheld, kept } = withholdPages(offlineData.schema, req.ctx.user);
|
|
72
|
+
const document = spaceDocument(withheld.length > 0 ? {
|
|
73
|
+
...offlineData,
|
|
74
|
+
schema
|
|
75
|
+
} : offlineData);
|
|
76
|
+
publishSpaceDocument(spaceId, environment, document, kept);
|
|
68
77
|
json = document.json;
|
|
69
78
|
current = document.hash === hash;
|
|
70
79
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { applySSRResult, isReusable, withNotFound } from "./applySSRResult.js";
|
|
1
|
+
import { applySSRResult, isReusable, withNotFound, withRefusal } from "./applySSRResult.js";
|
|
2
2
|
import Component from "./Component.js";
|
|
3
3
|
import { prepareRender } from "./prepareRender.js";
|
|
4
4
|
import { renderToPipeableStream } from "react-dom/server";
|
|
@@ -50,6 +50,7 @@ var streamBody = async (req, res, config, spaceId, environment, revision, render
|
|
|
50
50
|
metrics.log(`${req.method} ${req.path}`);
|
|
51
51
|
}
|
|
52
52
|
withNotFound(result, prep.notFound);
|
|
53
|
+
withRefusal(result, prep.refused);
|
|
53
54
|
if (applySSRResult(res, result)) {
|
|
54
55
|
abort();
|
|
55
56
|
resolve();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plitzi/sdk-server",
|
|
3
|
-
"version": "0.38.
|
|
3
|
+
"version": "0.38.22",
|
|
4
4
|
"license": "AGPL-3.0",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -114,8 +114,8 @@
|
|
|
114
114
|
"./dist/env.js"
|
|
115
115
|
],
|
|
116
116
|
"dependencies": {
|
|
117
|
-
"@plitzi/plitzi-sdk": "0.38.
|
|
118
|
-
"@plitzi/sdk-shared": "0.38.
|
|
117
|
+
"@plitzi/plitzi-sdk": "0.38.22",
|
|
118
|
+
"@plitzi/sdk-shared": "0.38.22",
|
|
119
119
|
"ejs": "^7.0.2",
|
|
120
120
|
"esbuild": "^0.28.2",
|
|
121
121
|
"jsonwebtoken": "^9.0.3",
|
|
@@ -63,6 +63,12 @@ A page's `accessLevel`: `'authenticated'` (signed in), `'public'` (signed OUT on
|
|
|
63
63
|
twin on the same slug. `unauthorizedRedirect` names where a visitor the page is not for goes — a page's id or slug
|
|
64
64
|
(`''` is the home page), or a URL; without it they are answered 403.
|
|
65
65
|
|
|
66
|
+
A page for some permissions says so: `access: { permissions: ['postPublish'] }` — every one held, by a signed-in visitor
|
|
67
|
+
(the permissions of their visitor roles; on Plitzi's own spaces, their account's). The server keeps it: anybody else is
|
|
68
|
+
answered 401 or 403 and the page's refusal, and its content is never sent to them — not in the page, not in the space
|
|
69
|
+
the browser fetches. Signed out, they go to `unauthorizedRedirect` when the page names one. Hiding a part of a page on
|
|
70
|
+
`auth.details.permissions` is not this: the part was still sent.
|
|
71
|
+
|
|
66
72
|
## What a visitor may do
|
|
67
73
|
|
|
68
74
|
`settings.visitorRoles` — `{ author: ['postPublish'] }` — is what each role gives. A visitor holds exactly the
|
|
@@ -105,6 +105,7 @@ The space is not written until these are fixed.
|
|
|
105
105
|
| `not-found-not-a-template` | `notFound`, a provider's or a page's, that is not one `{{ expression }}` — never `true`, so never a 404 | `notFound: '{{ source.found == false }}'` |
|
|
106
106
|
| `notifications-shape` | `notifications` with a field it does not have, or a value that is not one CSS value | the field it suggests, or one it lists; one CSS value, like 'var(--card)', '12px' or '500' |
|
|
107
107
|
| `outside-ancestor` | an element that reads the state of an element it is not inside | nest it in the element the message names |
|
|
108
|
+
| `page-access` | a page `access` the server cannot keep: no permissions, or one that is not a name | `access: { permissions: ['…'] }` with at least one permission name, or no `access` for a page anybody may see |
|
|
108
109
|
| `page-access-level` | an `accessLevel` that is not one the router reads | one of the values the message lists |
|
|
109
110
|
| `page-route-reserved` | a page under `/fn`, where the space's functions answer | another slug |
|
|
110
111
|
| `page-route-taken` | two pages at one address for the same visitors | another slug — or `accessLevel` `'public'` on one and `'authenticated'` on the other |
|
|
@@ -79,6 +79,9 @@ room.publish('react', { emoji }, { echo: true }); // and heard here too
|
|
|
79
79
|
room.members; // who is here, with the state each announced
|
|
80
80
|
```
|
|
81
81
|
|
|
82
|
+
A job of the space's functions, live in a plugin: `const job = useJob(jobId)` — `job?.progress`, `job?.status`,
|
|
83
|
+
`job?.result` — for whoever the job lets watch it (its `watch`), `undefined` until it is heard.
|
|
84
|
+
|
|
82
85
|
Messages arrive through the callback and re-render nothing. Take the topic as a prop
|
|
83
86
|
(`bindTemplate('roomTopic', 'board.id', 'room:{{ source }}')`) so the space names its channels, and trust a message
|
|
84
87
|
you act on only when `message.from === 'server'`. The page has one connection and is one member per topic, however
|
|
@@ -44,6 +44,10 @@ channels: { desk: { access: { mode: 'session' }, publish: 'server', retain: true
|
|
|
44
44
|
// a flow: { task: 'realtime.publish', params: { topic: 'desk', type: 'lists', data: '{{ saved.lists }}' } }
|
|
45
45
|
```
|
|
46
46
|
|
|
47
|
+
A job of the space's functions (`ctx.jobs.start`) says how it goes on `$job:<id>`, a topic no space declares — opened
|
|
48
|
+
for whoever started it and whoever the job's `watch` lets in: `channel({ id: 'training', topic: '$job:{{ state.job }}' })`
|
|
49
|
+
binds `training.retained.job` (`{ status, progress, step, result, error }`).
|
|
50
|
+
|
|
47
51
|
Two people writing the same thing at once: `kv.setIf` writes only if the value is still the one the flow read (empty
|
|
48
52
|
`expected` = only if nothing is there yet — claim a seat, a username), `list.put`/`list.range` keep an ordered list
|
|
49
53
|
(latest first, a leaderboard), and `flow.rateLimit` first in a public action that writes.
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/env.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/layers.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { ActionKvAdapter } from '../../types';
|
|
2
|
-
import { ActionJobQueue } from '@plitzi/sdk-shared';
|
|
3
|
-
/**
|
|
4
|
-
* What every {@link ActionJobQueue} must do, written once and run against each one this package ships.
|
|
5
|
-
*
|
|
6
|
-
* The memory queue, the Mongo helper and the MySQL helper are three implementations of one contract, and the contract
|
|
7
|
-
* is where a scheduling bug lives: a claim that is not atomic runs a job twice, a heartbeat that does not renew hands a
|
|
8
|
-
* running job to another replica, a settlement from a worker that lost its lease overwrites a live attempt. Asserting
|
|
9
|
-
* those once per store is what makes "swap the store" a one-line change rather than a new set of bugs.
|
|
10
|
-
*
|
|
11
|
-
* Real time, real stores: leases are tens of milliseconds and the tests wait them out, because the store's own clock
|
|
12
|
-
* is part of what is being tested.
|
|
13
|
-
*/
|
|
14
|
-
export type QueueSubject = {
|
|
15
|
-
queue: ActionJobQueue;
|
|
16
|
-
/** Empties whatever the queue keeps, between tests. */
|
|
17
|
-
clear: () => Promise<void>;
|
|
18
|
-
};
|
|
19
|
-
export declare const describeJobQueue: (name: string, open: () => Promise<QueueSubject>, enabled?: boolean) => void;
|
|
20
|
-
export type KvSubject = {
|
|
21
|
-
kv: ActionKvAdapter;
|
|
22
|
-
clear: () => Promise<void>;
|
|
23
|
-
};
|
|
24
|
-
/** What every {@link ActionKvAdapter} must do: strings, a TTL the store enforces, and an increment nobody can race. */
|
|
25
|
-
export declare const describeKv: (name: string, open: () => Promise<KvSubject>, enabled?: boolean) => void;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|