@plitzi/sdk-server 0.38.20 → 0.38.21

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.
Files changed (238) hide show
  1. package/CHANGELOG.md +117 -0
  2. package/README.md +2 -2
  3. package/dist/actions.d.ts +6 -0
  4. package/dist/actions.js +2 -1
  5. package/dist/core/configSeam.js +2 -2
  6. package/dist/core/services/functionRoutes.js +7 -2
  7. package/dist/core/services/realtime.js +5 -2
  8. package/dist/functions-api.d.ts +155 -0
  9. package/dist/functions.d.ts +3 -1
  10. package/dist/functions.js +2 -1
  11. package/dist/helpers/serverLog.d.ts +1 -1
  12. package/dist/helpers/serverLog.js +1 -1
  13. package/dist/hosts/project/plugins.js +20 -3
  14. package/dist/modules/actions/index.js +16 -3
  15. package/dist/modules/actions/jobs/index.d.ts +4 -3
  16. package/dist/modules/actions/jobs/index.js +2 -1
  17. package/dist/modules/actions/jobs/later.d.ts +2 -2
  18. package/dist/modules/actions/jobs/later.js +5 -2
  19. package/dist/modules/actions/jobs/memoryQueue.d.ts +4 -4
  20. package/dist/modules/actions/jobs/memoryQueue.js +69 -25
  21. package/dist/modules/actions/jobs/scheduler.d.ts +2 -2
  22. package/dist/modules/actions/jobs/scheduler.js +5 -2
  23. package/dist/modules/actions/jobs/worker.d.ts +6 -3
  24. package/dist/modules/actions/jobs/worker.js +104 -10
  25. package/dist/modules/actions/runtime/runAction.d.ts +5 -2
  26. package/dist/modules/actions/runtime/runAction.js +5 -3
  27. package/dist/modules/actions/runtime/taskContext.d.ts +12 -3
  28. package/dist/modules/actions/runtime/taskContext.js +7 -1
  29. package/dist/modules/actions/types.d.ts +18 -4
  30. package/dist/modules/functions/capabilities.js +59 -1
  31. package/dist/modules/functions/config.d.ts +9 -0
  32. package/dist/modules/functions/context.d.ts +2 -2
  33. package/dist/modules/functions/context.js +14 -1
  34. package/dist/modules/functions/contract.d.ts +84 -1
  35. package/dist/modules/functions/driver.js +94 -2
  36. package/dist/modules/functions/jobControl.d.ts +21 -0
  37. package/dist/modules/functions/jobControl.js +43 -0
  38. package/dist/modules/functions/jobs.d.ts +98 -0
  39. package/dist/modules/functions/jobs.js +438 -0
  40. package/dist/modules/functions/manifest.js +36 -3
  41. package/dist/modules/functions/native.js +2 -1
  42. package/dist/modules/functions/oauth.d.ts +2 -1
  43. package/dist/modules/functions/oauth.js +15 -2
  44. package/dist/modules/functions/protocol.d.ts +71 -4
  45. package/dist/modules/functions/protocol.js +2 -1
  46. package/dist/modules/functions/routes.d.ts +9 -1
  47. package/dist/modules/functions/routes.js +48 -23
  48. package/dist/modules/functions/runner/messages.d.ts +0 -1
  49. package/dist/modules/functions/runner/messages.js +40 -2
  50. package/dist/modules/functions/runner/remote.js +58 -3
  51. package/dist/modules/functions/runner/service.js +53 -7
  52. package/dist/modules/functions/sandbox/isolate.js +5 -3
  53. package/dist/modules/functions/space.js +4 -4
  54. package/dist/modules/mongo/jobQueue.d.ts +3 -3
  55. package/dist/modules/mongo/jobQueue.js +137 -26
  56. package/dist/modules/mysql/jobs/jobQueue.d.ts +3 -3
  57. package/dist/modules/mysql/jobs/jobQueue.js +97 -33
  58. package/dist/modules/mysql/jobs/schema.js +38 -11
  59. package/dist/modules/realtime/handlers.d.ts +5 -2
  60. package/dist/modules/realtime/handlers.js +15 -4
  61. package/dist/modules/realtime/index.d.ts +11 -1
  62. package/dist/modules/realtime/index.js +8 -1
  63. package/dist/modules/realtime/jobs.d.ts +20 -0
  64. package/dist/modules/realtime/jobs.js +41 -0
  65. package/dist/modules/realtime/retained.d.ts +3 -2
  66. package/dist/modules/realtime/retained.js +2 -2
  67. package/dist/modules/realtime/socket.d.ts +4 -1
  68. package/dist/modules/realtime/socket.js +2 -2
  69. package/dist/modules/rsc/resolveRscData.js +2 -1
  70. package/dist/modules/runtime/host.js +1 -1
  71. package/dist/modules/runtime/runner.d.ts +1 -1
  72. package/dist/modules/runtime/runner.js +12 -2
  73. package/dist/modules/runtime/stages.js +1 -1
  74. package/dist/modules/ssr/applySSRResult.d.ts +5 -0
  75. package/dist/modules/ssr/applySSRResult.js +8 -1
  76. package/dist/modules/ssr/buildBody.js +2 -1
  77. package/dist/modules/ssr/prepareRender.d.ts +3 -0
  78. package/dist/modules/ssr/prepareRender.js +17 -5
  79. package/dist/modules/ssr/spaceDocument.d.ts +2 -1
  80. package/dist/modules/ssr/spaceDocument.js +14 -5
  81. package/dist/modules/ssr/streamBody.js +2 -1
  82. package/package.json +3 -3
  83. package/skills/plitzi-authoring/reference/auth.md +6 -0
  84. package/skills/plitzi-authoring/reference/authoring-errors.md +1 -0
  85. package/skills/plitzi-authoring/reference/plugin-reach.md +3 -0
  86. package/skills/plitzi-authoring/reference/realtime.md +4 -0
  87. package/dist/adapters/cloudAdapters.test.d.ts +0 -1
  88. package/dist/adapters/jsonAdapters.test.d.ts +0 -1
  89. package/dist/adapters/space/space.test.d.ts +0 -1
  90. package/dist/core/auth/api.test.d.ts +0 -1
  91. package/dist/core/auth/authorize.test.d.ts +0 -1
  92. package/dist/core/auth/createAuth.test.d.ts +0 -1
  93. package/dist/core/auth/csrf.test.d.ts +0 -1
  94. package/dist/core/auth/domains.test.d.ts +0 -1
  95. package/dist/core/auth/identity.test.d.ts +0 -1
  96. package/dist/core/auth/lifecycle.test.d.ts +0 -1
  97. package/dist/core/auth/oauth/oauth.test.d.ts +0 -1
  98. package/dist/core/auth/redirects.test.d.ts +0 -1
  99. package/dist/core/auth/routes.test.d.ts +0 -1
  100. package/dist/core/auth/session.test.d.ts +0 -1
  101. package/dist/core/auth/spaceTokens.test.d.ts +0 -1
  102. package/dist/core/auth/throttle.test.d.ts +0 -1
  103. package/dist/core/auth/tokens.test.d.ts +0 -1
  104. package/dist/core/auth/totp.test.d.ts +0 -1
  105. package/dist/core/configSeam.test.d.ts +0 -1
  106. package/dist/core/createServer.actions.test.d.ts +0 -1
  107. package/dist/core/createServer.functions.test.d.ts +0 -1
  108. package/dist/core/createServer.livePages.test.d.ts +0 -1
  109. package/dist/core/createServer.notFound.test.d.ts +0 -1
  110. package/dist/core/createServer.oauth.test.d.ts +0 -1
  111. package/dist/core/createServer.publicData.test.d.ts +0 -1
  112. package/dist/core/createServer.test.d.ts +0 -1
  113. package/dist/core/fontStore.test.d.ts +0 -1
  114. package/dist/core/freePort.test.d.ts +0 -1
  115. package/dist/core/handlers/csrfMiddleware.test.d.ts +0 -1
  116. package/dist/core/handlers/handlers.test.d.ts +0 -1
  117. package/dist/core/handlers/socialRouteHandlers.test.d.ts +0 -1
  118. package/dist/core/http/dispatcher.test.d.ts +0 -1
  119. package/dist/core/http/stages/crossSiteWrites.test.d.ts +0 -1
  120. package/dist/core/http/stages/exchangeRoute.test.d.ts +0 -1
  121. package/dist/core/http/stages/images.test.d.ts +0 -1
  122. package/dist/core/http/stages/middlewares.test.d.ts +0 -1
  123. package/dist/core/http/stages/sessionRenewal.test.d.ts +0 -1
  124. package/dist/core/http/stages/signInRoute.test.d.ts +0 -1
  125. package/dist/core/oauth/authorize.test.d.ts +0 -1
  126. package/dist/core/oauth/register.test.d.ts +0 -1
  127. package/dist/core/oauth/token.test.d.ts +0 -1
  128. package/dist/core/requestParser.test.d.ts +0 -1
  129. package/dist/core/server/baseServer.test.d.ts +0 -1
  130. package/dist/core/server/closeOnSignals.test.d.ts +0 -1
  131. package/dist/core/server/drain.test.d.ts +0 -1
  132. package/dist/core/server/fleet/channel.test.d.ts +0 -1
  133. package/dist/core/server/fleet/fixtures/fleetServer.d.ts +0 -1
  134. package/dist/core/server/fleet/fleet.integration.test.d.ts +0 -1
  135. package/dist/core/server/fleet/relay.test.d.ts +0 -1
  136. package/dist/core/server/fleet/role.test.d.ts +0 -1
  137. package/dist/core/server/fleet/supervisor.test.d.ts +0 -1
  138. package/dist/core/services/resolve.test.d.ts +0 -1
  139. package/dist/core/staticFiles.test.d.ts +0 -1
  140. package/dist/env.test.d.ts +0 -1
  141. package/dist/helpers/atomicFile.test.d.ts +0 -1
  142. package/dist/helpers/buildResponseHelpers.test.d.ts +0 -1
  143. package/dist/helpers/buildServerInfo.test.d.ts +0 -1
  144. package/dist/helpers/cache/CompressedFileCache.test.d.ts +0 -1
  145. package/dist/helpers/cache/cacheManager.test.d.ts +0 -1
  146. package/dist/helpers/cache/keys.test.d.ts +0 -1
  147. package/dist/helpers/compress.test.d.ts +0 -1
  148. package/dist/helpers/hydrationPayload.test.d.ts +0 -1
  149. package/dist/helpers/offlineDataLoader.test.d.ts +0 -1
  150. package/dist/helpers/onAbort.test.d.ts +0 -1
  151. package/dist/helpers/outboundGuard.test.d.ts +0 -1
  152. package/dist/helpers/reportReactBuild.test.d.ts +0 -1
  153. package/dist/helpers/resolveDebugMode.test.d.ts +0 -1
  154. package/dist/helpers/serverLog.test.d.ts +0 -1
  155. package/dist/hosts/authoringHost/index.test.d.ts +0 -1
  156. package/dist/hosts/project/serveProject.test.d.ts +0 -1
  157. package/dist/layers.test.d.ts +0 -1
  158. package/dist/middlewares/spaceDeployment.test.d.ts +0 -1
  159. package/dist/modules/actions/connectorWrite.test.d.ts +0 -1
  160. package/dist/modules/actions/jobs/failureStreak.test.d.ts +0 -1
  161. package/dist/modules/actions/jobs/later.test.d.ts +0 -1
  162. package/dist/modules/actions/jobs/memoryStores.test.d.ts +0 -1
  163. package/dist/modules/actions/jobs/scheduler.test.d.ts +0 -1
  164. package/dist/modules/actions/jobs/testing/jobQueueContract.d.ts +0 -25
  165. package/dist/modules/actions/jobs/worker.test.d.ts +0 -1
  166. package/dist/modules/actions/moduleFor.test.d.ts +0 -1
  167. package/dist/modules/actions/runtime/check.test.d.ts +0 -1
  168. package/dist/modules/actions/runtime/credentials.test.d.ts +0 -1
  169. package/dist/modules/actions/runtime/email.test.d.ts +0 -1
  170. package/dist/modules/actions/runtime/fileKv.test.d.ts +0 -1
  171. package/dist/modules/actions/runtime/flags.test.d.ts +0 -1
  172. package/dist/modules/actions/runtime/guards.test.d.ts +0 -1
  173. package/dist/modules/actions/runtime/kvStore.test.d.ts +0 -1
  174. package/dist/modules/actions/runtime/namespaceKv.test.d.ts +0 -1
  175. package/dist/modules/actions/runtime/redisKv.integration.test.d.ts +0 -1
  176. package/dist/modules/actions/runtime/renderResolver.test.d.ts +0 -1
  177. package/dist/modules/actions/runtime/renderShare.test.d.ts +0 -1
  178. package/dist/modules/actions/runtime/runAction.test.d.ts +0 -1
  179. package/dist/modules/actions/runtime/runLogger.test.d.ts +0 -1
  180. package/dist/modules/actions/runtime/signing.test.d.ts +0 -1
  181. package/dist/modules/actions/taskCatalog.test.d.ts +0 -1
  182. package/dist/modules/actions/tasks/db.test.d.ts +0 -1
  183. package/dist/modules/actions/tasks/email.test.d.ts +0 -1
  184. package/dist/modules/actions/tasks/http.test.d.ts +0 -1
  185. package/dist/modules/actions/tasks/kv.test.d.ts +0 -1
  186. package/dist/modules/actions/transport/callHandler.test.d.ts +0 -1
  187. package/dist/modules/actions/transport/webhookHandler.test.d.ts +0 -1
  188. package/dist/modules/connectors/engine.test.d.ts +0 -1
  189. package/dist/modules/connectors/projection.test.d.ts +0 -1
  190. package/dist/modules/connectors/resolver.test.d.ts +0 -1
  191. package/dist/modules/functions/build.test.d.ts +0 -1
  192. package/dist/modules/functions/load.test.d.ts +0 -1
  193. package/dist/modules/functions/local.test.d.ts +0 -1
  194. package/dist/modules/functions/manifest.test.d.ts +0 -1
  195. package/dist/modules/functions/native.test.d.ts +0 -1
  196. package/dist/modules/functions/oauth.test.d.ts +0 -1
  197. package/dist/modules/functions/plugins.test.d.ts +0 -1
  198. package/dist/modules/functions/routes.test.d.ts +0 -1
  199. package/dist/modules/functions/runner/remote.test.d.ts +0 -1
  200. package/dist/modules/functions/sandbox/isolate.test.d.ts +0 -1
  201. package/dist/modules/functions/testing/tasksOf.d.ts +0 -4
  202. package/dist/modules/images/imageProxy.test.d.ts +0 -1
  203. package/dist/modules/images/transform.test.d.ts +0 -1
  204. package/dist/modules/mongo/stores.integration.test.d.ts +0 -1
  205. package/dist/modules/mysql/accounts.test.d.ts +0 -1
  206. package/dist/modules/mysql/jobs/stores.integration.test.d.ts +0 -1
  207. package/dist/modules/mysql/schema.test.d.ts +0 -1
  208. package/dist/modules/mysql/store.integration.test.d.ts +0 -1
  209. package/dist/modules/realtime/realtime.test.d.ts +0 -1
  210. package/dist/modules/realtime/redisPubSub.test.d.ts +0 -1
  211. package/dist/modules/realtime/retained.test.d.ts +0 -1
  212. package/dist/modules/realtime/socket.test.d.ts +0 -1
  213. package/dist/modules/rsc/connectorRscData.test.d.ts +0 -1
  214. package/dist/modules/rsc/handler.test.d.ts +0 -1
  215. package/dist/modules/rsc/publicFileResolver.test.d.ts +0 -1
  216. package/dist/modules/rsc/resolveRscData.test.d.ts +0 -1
  217. package/dist/modules/runtime/elsewhere.test.d.ts +0 -1
  218. package/dist/modules/runtime/entry.test.d.ts +0 -1
  219. package/dist/modules/runtime/inside.test.d.ts +0 -1
  220. package/dist/modules/runtime/ownServer.test.d.ts +0 -1
  221. package/dist/modules/runtime/runtime.test.d.ts +0 -1
  222. package/dist/modules/sqlite/kv.test.d.ts +0 -1
  223. package/dist/modules/ssr/draftSession.test.d.ts +0 -1
  224. package/dist/modules/ssr/loadPluginComponents.test.d.ts +0 -1
  225. package/dist/modules/ssr/metering.test.d.ts +0 -1
  226. package/dist/modules/ssr/prepareRender.test.d.ts +0 -1
  227. package/dist/modules/ssr/redirect.test.d.ts +0 -1
  228. package/dist/modules/ssr/registerExternalPlugins.test.d.ts +0 -1
  229. package/dist/modules/ssr/reportMissingPlugins.test.d.ts +0 -1
  230. package/dist/modules/ssr/resolvePageSeo.test.d.ts +0 -1
  231. package/dist/modules/ssr/spaceDocument.test.d.ts +0 -1
  232. package/dist/modules/ssr/template.test.d.ts +0 -1
  233. package/dist/modules/ssr/testing/offlineData.d.ts +0 -5
  234. package/dist/modules/ssr/vendor.test.d.ts +0 -1
  235. package/dist/plugins/compile.test.d.ts +0 -1
  236. package/dist/plugins/copy.test.d.ts +0 -1
  237. package/dist/plugins/manager.test.d.ts +0 -1
  238. package/dist/plugins/validate.test.d.ts +0 -1
@@ -1,10 +1,11 @@
1
1
  import onAbort from "../../helpers/onAbort.js";
2
2
  import { openEventStream } from "../../core/http/sse.js";
3
3
  import { warnRealtime } from "./failure.js";
4
+ import { JOB_CHANNEL, jobRefusal } from "./jobs.js";
4
5
  import { readCookies } from "../../core/auth/credentials.js";
5
6
  import { accessRefusal } from "@plitzi/sdk-shared/actions";
6
7
  import { randomBytes, randomUUID } from "node:crypto";
7
- import { OBSERVER_COOKIE_NAME, PRESENCE_TYPE, channelLimits, matchChannel } from "@plitzi/sdk-shared/realtime";
8
+ import { OBSERVER_COOKIE_NAME, PRESENCE_TYPE, channelLimits, jobOfTopic, matchChannel } from "@plitzi/sdk-shared/realtime";
8
9
  //#region src/modules/realtime/handlers.ts
9
10
  /** Topics one connection may hold. A page shows a handful; past this it is somebody enumerating. */
10
11
  var MAX_TOPICS = 8;
@@ -28,7 +29,7 @@ var grantFor = async (grants, space, topic, offered) => {
28
29
  * declares and against the visitor's access. One that fails is reported, not a reason to refuse the rest; all failing
29
30
  * is a `403`.
30
31
  */
31
- var admit = async (req, resolveChannels, grants) => {
32
+ var admit = async (req, resolveChannels, grants, jobs) => {
32
33
  const { environment = "main", spaceId, revision } = req.ctx.spaceDeployment ?? {};
33
34
  if (typeof spaceId !== "number") return {
34
35
  ok: false,
@@ -57,6 +58,16 @@ var admit = async (req, resolveChannels, grants) => {
57
58
  environment
58
59
  };
59
60
  for (const topic of requested) {
61
+ const jobId = jobOfTopic(topic);
62
+ if (jobId !== void 0) {
63
+ const refusal = await jobRefusal(jobs, spaceId, jobId, req.ctx.user);
64
+ if (refusal) refused.push({
65
+ topic,
66
+ reason: refusal
67
+ });
68
+ else accepted.set(topic, JOB_CHANNEL);
69
+ continue;
70
+ }
60
71
  const match = matchChannel(topic, channels);
61
72
  const refusal = match ? accessRefusal(match.declaration.access, req.ctx.user) : "undeclared";
62
73
  const grant = match && !refusal && match.declaration.grant === true ? await grantFor(grants, space, topic, offered) : void 0;
@@ -178,8 +189,8 @@ var publishFrom = async (hub, connection, { topic, type, data, echo }) => {
178
189
  * The first event, `ready`, tells the page its public name (`from`) and the secret its publishes carry. Resolves when
179
190
  * the page goes.
180
191
  */
181
- var handleRealtimeSubscribe = async ({ req, res, raw, signal, hub, resolveChannels, grants }) => {
182
- const admission = await admit(req, resolveChannels, grants);
192
+ var handleRealtimeSubscribe = async ({ req, res, raw, signal, hub, resolveChannels, grants, jobs }) => {
193
+ const admission = await admit(req, resolveChannels, grants, jobs);
183
194
  if (!admission.ok) {
184
195
  answer(res, admission.answer);
185
196
  return;
@@ -1,7 +1,8 @@
1
1
  import { ChannelResolver } from './declarations';
2
2
  import { RealtimeGrants } from './grants';
3
3
  import { RealtimeHub } from './hub';
4
- import { RealtimeTransport, SSRServerConfig } from '@plitzi/sdk-shared';
4
+ import { JobLookup } from './jobs';
5
+ import { FunctionJobView, RealtimeTransport, SSRServerConfig } from '@plitzi/sdk-shared';
5
6
  export { createMemoryPubSub } from './memoryPubSub';
6
7
  export { handleRealtimePublish, handleRealtimeSubscribe } from './handlers';
7
8
  export { handleRealtimeSocket } from './socket';
@@ -43,6 +44,15 @@ export type RealtimeModule = {
43
44
  spaceId: number;
44
45
  environment: string;
45
46
  }, topic: string, grant?: string) => Promise<void>;
47
+ /** Says a job of the space's functions as it is now on its topic (`$job:<id>`), kept for a page that joins later. */
48
+ publishJob: (space: {
49
+ spaceId: number;
50
+ environment: string;
51
+ }, jobId: string, view: FunctionJobView) => Promise<void>;
52
+ /** Hands the realtime the way to a job, which the actions module holds: what the door of `$job:<id>` reads. */
53
+ watchJobs: (lookup: JobLookup) => void;
54
+ /** The way to a job, once the actions module handed it — what a subscription to `$job:<id>` is decided by. */
55
+ jobs: () => JobLookup | undefined;
46
56
  };
47
57
  /**
48
58
  * The server's realtime channels, built once per config — or `undefined` when they are off or cannot be: without the
@@ -3,6 +3,7 @@ import { KV_METHODS, createMemoryKv } from "../actions/runtime/memoryKv.js";
3
3
  import { createRealtimeGrants } from "./grants.js";
4
4
  import { createChannelResolver } from "./declarations.js";
5
5
  import { createRealtimeHub } from "./hub.js";
6
+ import { publishJobView } from "./jobs.js";
6
7
  import { createMemoryPubSub } from "./memoryPubSub.js";
7
8
  import { createRealtimeRetained } from "./retained.js";
8
9
  import { handleRealtimePublish, handleRealtimeSubscribe } from "./handlers.js";
@@ -26,6 +27,7 @@ var realtimeModuleFor = (config) => {
26
27
  const hub = createRealtimeHub(config.realtime?.pubsub ?? createMemoryPubSub(), retained);
27
28
  const resolveChannels = createChannelResolver(getOfflineData);
28
29
  const grants = createRealtimeGrants(kv);
30
+ let jobLookup;
29
31
  const module = {
30
32
  hub,
31
33
  path: config.realtime?.path ?? "/_realtime",
@@ -60,7 +62,12 @@ var realtimeModuleFor = (config) => {
60
62
  if (matchChannel(topic, await resolveChannels(space.spaceId, space.environment))?.declaration.grant !== true) throw new Error(`"${topic}" is not a topic of a private (\`grant: true\`) channel of this space: it has no grants to revoke`);
61
63
  await grants.revoke(space, topic, grant);
62
64
  await hub.revoke(space, topic, grant);
63
- }
65
+ },
66
+ publishJob: (space, jobId, view) => publishJobView(hub, retained, space, jobId, view),
67
+ watchJobs: (lookup) => {
68
+ jobLookup = lookup;
69
+ },
70
+ jobs: () => jobLookup
64
71
  };
65
72
  modules.set(config, module);
66
73
  return module;
@@ -0,0 +1,20 @@
1
+ import { RealtimeHub, RealtimeSpace } from './hub';
2
+ import { RealtimeRetained } from './retained';
3
+ import { Job, ChannelDeclaration, FunctionJobView, SSRUser } from '@plitzi/sdk-shared';
4
+ /** How the realtime reaches a job, once the actions module hands it the way (`watchJobs`). */
5
+ export type JobLookup = (spaceId: number, jobId: string) => Promise<Job | undefined>;
6
+ /** A job's topic, as a channel: the server alone says how the job goes, and a page that joins hears the latest. */
7
+ export declare const JOB_CHANNEL: ChannelDeclaration;
8
+ /** How long a job's topic is kept after it last changed: as long as the queue keeps a finished job readable. */
9
+ export declare const JOB_RETAINED_SECONDS: number;
10
+ /**
11
+ * Why a page may not watch a job, or nothing when it may: whoever started it always does, and anyone else as the
12
+ * job's `watch` says — a channel's access, read against the visitor's permissions in the space. A job of another space,
13
+ * or none by that id, is no topic at all.
14
+ */
15
+ export declare const jobRefusal: (lookup: JobLookup | undefined, spaceId: number, jobId: string, user: SSRUser | undefined) => Promise<"undeclared" | "unauthenticated" | "forbidden" | undefined>;
16
+ /**
17
+ * Says a job as it is now on its topic, kept for a page that joins later — the one way it is said, by the page server's
18
+ * realtime and by an operator's panel in a process of its own alike.
19
+ */
20
+ export declare const publishJobView: (hub: Pick<RealtimeHub, "publish">, retained: RealtimeRetained, space: RealtimeSpace, jobId: string, view: FunctionJobView) => Promise<void>;
@@ -0,0 +1,41 @@
1
+ import { accessRefusal } from "@plitzi/sdk-shared/actions";
2
+ import { JOB_TYPE, jobTopic } from "@plitzi/sdk-shared/realtime";
3
+ //#region src/modules/realtime/jobs.ts
4
+ /** A job's topic, as a channel: the server alone says how the job goes, and a page that joins hears the latest. */
5
+ var JOB_CHANNEL = {
6
+ access: { mode: "session" },
7
+ publish: "server",
8
+ retain: true
9
+ };
10
+ /** How long a job's topic is kept after it last changed: as long as the queue keeps a finished job readable. */
11
+ var JOB_RETAINED_SECONDS = 2592e3;
12
+ /**
13
+ * Why a page may not watch a job, or nothing when it may: whoever started it always does, and anyone else as the
14
+ * job's `watch` says — a channel's access, read against the visitor's permissions in the space. A job of another space,
15
+ * or none by that id, is no topic at all.
16
+ */
17
+ var jobRefusal = async (lookup, spaceId, jobId, user) => {
18
+ const target = (lookup ? await lookup(spaceId, jobId) : void 0)?.target;
19
+ if (target?.kind !== "function") return "undeclared";
20
+ if (user && target.user?.id === user.id) return;
21
+ if (!target.watch) return user ? "forbidden" : "unauthenticated";
22
+ return accessRefusal(target.watch, user);
23
+ };
24
+ /**
25
+ * Says a job as it is now on its topic, kept for a page that joins later — the one way it is said, by the page server's
26
+ * realtime and by an operator's panel in a process of its own alike.
27
+ */
28
+ var publishJobView = async (hub, retained, space, jobId, view) => {
29
+ const message = {
30
+ topic: jobTopic(jobId),
31
+ type: JOB_TYPE,
32
+ data: view,
33
+ from: "server",
34
+ at: Date.now(),
35
+ retained: true
36
+ };
37
+ await retained.keep(space, message, JOB_RETAINED_SECONDS);
38
+ await hub.publish(space, message);
39
+ };
40
+ //#endregion
41
+ export { JOB_CHANNEL, JOB_RETAINED_SECONDS, jobRefusal, publishJobView };
@@ -8,9 +8,10 @@ export declare const MAX_RETAINED_BYTES: number;
8
8
  export type RealtimeRetained = {
9
9
  /**
10
10
  * Keeps `message` as its topic's latest of its type — or, with `null` data, forgets the type. Refused, before anything
11
- * is sent, past {@link MAX_RETAINED_TYPES} types or {@link MAX_RETAINED_BYTES} for the topic.
11
+ * is sent, past {@link MAX_RETAINED_TYPES} types or {@link MAX_RETAINED_BYTES} for the topic. With `ttlSeconds`, the
12
+ * topic is forgotten that long after it last changed — a job's, which ends.
12
13
  */
13
- keep: (space: RealtimeSpace, message: RealtimeMessage) => Promise<void>;
14
+ keep: (space: RealtimeSpace, message: RealtimeMessage, ttlSeconds?: number) => Promise<void>;
14
15
  /** What a topic keeps: the latest message of each type, oldest first. */
15
16
  of: (space: RealtimeSpace, topic: string) => Promise<RealtimeMessage[]>;
16
17
  };
@@ -23,7 +23,7 @@ var parseKept = (raw) => {
23
23
  var createRealtimeRetained = (store) => {
24
24
  const key = ({ spaceId, environment }, topic) => `realtime-retained:${String(spaceId)}:${environment}:${topic}`;
25
25
  return {
26
- keep: async (space, message) => {
26
+ keep: async (space, message, ttlSeconds) => {
27
27
  const at = key(space, message.topic);
28
28
  for (let attempt = 0; attempt < ATTEMPTS; attempt += 1) {
29
29
  const raw = await store.get(at);
@@ -36,7 +36,7 @@ var createRealtimeRetained = (store) => {
36
36
  if (Object.keys(next).length > 64) throw new Error(`"${message.topic}" keeps at most ${String(64)} types of message: keep fewer, larger ones (one \`lists\` holding every list), or forget one with null`);
37
37
  const written = JSON.stringify(next);
38
38
  if (Buffer.byteLength(written) > 524288) throw new Error(`"${message.topic}" keeps at most ${String(MAX_RETAINED_BYTES / 1024)} KB, and "${message.type}" would take it past that: every page that joins is sent all of it — keep there what the screens show, the rest in kv`);
39
- if (await store.swap(at, raw, written)) return;
39
+ if (await store.swap(at, raw, written, ttlSeconds)) return;
40
40
  }
41
41
  throw new Error(`"${message.topic}" changed under ${String(ATTEMPTS)} writes in a row, so "${message.type}" was not kept: publish it again`);
42
42
  },
@@ -1,6 +1,7 @@
1
1
  import { ChannelResolver } from './declarations';
2
2
  import { RealtimeGrants } from './grants';
3
3
  import { RealtimeHub } from './hub';
4
+ import { JobLookup } from './jobs';
4
5
  import { UpgradeRequest } from '../../core/http/socketResponse';
5
6
  import { SSRRequest, SSRResponseHelpers } from '@plitzi/sdk-shared';
6
7
  import { IncomingMessage } from 'node:http';
@@ -13,6 +14,8 @@ export type SocketDeps = {
13
14
  resolveChannels: ChannelResolver;
14
15
  grants: RealtimeGrants;
15
16
  allowedOrigins: readonly string[];
17
+ /** The way to the jobs `$job:<id>` is about — absent where the server runs none. */
18
+ jobs?: JobLookup;
16
19
  };
17
20
  /**
18
21
  * A page's realtime connection as a WebSocket: the same topics, rules and messages as the Server-Sent Events one, in
@@ -22,4 +25,4 @@ export type SocketDeps = {
22
25
  * Refused the way the stream is — a `403` or a `422`, in HTTP, before anything switches — so a page falls back or
23
26
  * reports it exactly as it would there.
24
27
  */
25
- export declare const handleRealtimeSocket: ({ req, res, raw, upgrade, hub, resolveChannels, grants, allowedOrigins }: SocketDeps) => Promise<void>;
28
+ export declare const handleRealtimeSocket: ({ req, res, raw, upgrade, hub, resolveChannels, grants, allowedOrigins, jobs }: SocketDeps) => Promise<void>;
@@ -50,7 +50,7 @@ var ackId = (id) => typeof id === "number" && Number.isInteger(id) || typeof id
50
50
  * Refused the way the stream is — a `403` or a `422`, in HTTP, before anything switches — so a page falls back or
51
51
  * reports it exactly as it would there.
52
52
  */
53
- var handleRealtimeSocket = async ({ req, res, raw, upgrade, hub, resolveChannels, grants, allowedOrigins }) => {
53
+ var handleRealtimeSocket = async ({ req, res, raw, upgrade, hub, resolveChannels, grants, allowedOrigins, jobs }) => {
54
54
  if (!originAllowed(raw, req, allowedOrigins)) {
55
55
  answer(res, {
56
56
  status: 403,
@@ -59,7 +59,7 @@ var handleRealtimeSocket = async ({ req, res, raw, upgrade, hub, resolveChannels
59
59
  });
60
60
  return;
61
61
  }
62
- const admission = await admit(req, resolveChannels, grants);
62
+ const admission = await admit(req, resolveChannels, grants, jobs);
63
63
  if (!admission.ok) {
64
64
  answer(res, admission.answer);
65
65
  return;
@@ -2,7 +2,7 @@ import { serverLog } from "../../helpers/serverLog.js";
2
2
  import onAbort from "../../helpers/onAbort.js";
3
3
  import { matchRscPage } from "./matchRscPage.js";
4
4
  import { flagUserFromSSR, flagValues, resolveFlags } from "@plitzi/sdk-shared/flags";
5
- import { collectServerElements } from "@plitzi/sdk-shared/schema";
5
+ import { collectServerElements, pageAccessOf, pageAccessRefusal } from "@plitzi/sdk-shared/schema";
6
6
  //#region src/modules/rsc/resolveRscData.ts
7
7
  var DEFAULT_ELEMENT_TIMEOUT_MS = 5e3;
8
8
  /**
@@ -40,6 +40,7 @@ var resolveRscData = async ({ schema, req, spaceId, environment, user, ids, reso
40
40
  const match = matchRscPage(schema, req.path, user);
41
41
  if (!match) return { serverData: {} };
42
42
  const { pageId, routeParams } = match;
43
+ if (pageAccessRefusal(pageAccessOf(schema.flat[pageId].attributes), user) !== void 0) return { serverData: {} };
43
44
  const flags = flagValues(resolveFlags(schema.flags, {
44
45
  environment,
45
46
  hostname: req.hostname,
@@ -1,9 +1,9 @@
1
+ import { webRequestOf, writeWebResponse } from "../../core/http/webExchange.js";
1
2
  import { describeFunctions } from "../functions/driver.js";
2
3
  import { startFunctionsRunnerService } from "../functions/runner/service.js";
3
4
  import { endpointFor, endpointProblem } from "./contract.js";
4
5
  import { reachSpaceInside } from "./inside.js";
5
6
  import { createRuntimeRunner } from "./runner.js";
6
- import { webRequestOf, writeWebResponse } from "../../core/http/webExchange.js";
7
7
  //#region src/modules/runtime/host.ts
8
8
  /** Where a started runtime says what it serves — under `/_`, which no endpoint may take. */
9
9
  var RUNTIME_DESCRIBE_PATH = "/_describe";
@@ -5,7 +5,7 @@ import { FunctionRunner } from '../functions/protocol';
5
5
  * A runtime's functions as a runner: the same protocol as the sandbox's, answered by code loaded in this process. The
6
6
  * driver is the sandbox's own (`createFunctionsDriver`), so a task behaves the same in both — its `ctx` is calls to the
7
7
  * platform, `ctx.kv.change` the same loop, a refusal the same answer. What it does not share is the isolate: there are
8
- * no limits here but the platform's clock, since this process is the space's alone.
8
+ * no limits here but the platform's clock, since this process is the space's alone — and a route's answer streams.
9
9
  *
10
10
  * The bundle a request names is not asked for: the code is the one this runtime was started with.
11
11
  */
@@ -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) => response instanceof Response ? wireResponseOf(response) : void 0,
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 offlineData = await loadOfflineData();
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 && offlineData !== void 0) offlineDataCache?.set(offlineCacheKey, JSON.stringify(offlineData));
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, document.json);
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
- let json = recent.get(recentKey(spaceId, environment, hash));
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 document = spaceDocument(offlineData);
67
- publishSpaceDocument(spaceId, environment, document);
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.20",
3
+ "version": "0.38.21",
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.20",
118
- "@plitzi/sdk-shared": "0.38.20",
117
+ "@plitzi/plitzi-sdk": "0.38.21",
118
+ "@plitzi/sdk-shared": "0.38.21",
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 {};