@plitzi/sdk-server 0.38.24 → 0.39.0

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 (233) hide show
  1. package/CHANGELOG.md +152 -1
  2. package/README.md +55 -9
  3. package/dist/actions.d.ts +4 -1
  4. package/dist/actions.js +3 -2
  5. package/dist/auth.d.ts +2 -2
  6. package/dist/auth.js +5 -4
  7. package/dist/core/auth/api/accounts.d.ts +11 -0
  8. package/dist/core/auth/api/accounts.js +175 -0
  9. package/dist/core/auth/api/admin.d.ts +41 -0
  10. package/dist/core/auth/api/admin.js +146 -0
  11. package/dist/core/auth/api/context.d.ts +119 -0
  12. package/dist/core/auth/api/context.js +262 -0
  13. package/dist/core/auth/api/factors.d.ts +31 -0
  14. package/dist/core/auth/api/factors.js +209 -0
  15. package/dist/core/auth/api/index.d.ts +94 -0
  16. package/dist/core/auth/api/index.js +43 -0
  17. package/dist/core/auth/api/profile.d.ts +43 -0
  18. package/dist/core/auth/api/profile.js +243 -0
  19. package/dist/core/auth/api/session.d.ts +62 -0
  20. package/dist/core/auth/api/session.js +312 -0
  21. package/dist/core/auth/{api.d.ts → api/types.d.ts} +41 -195
  22. package/dist/core/auth/api/values.d.ts +67 -0
  23. package/dist/core/auth/api/values.js +90 -0
  24. package/dist/core/auth/createAuth.d.ts +49 -39
  25. package/dist/core/auth/createAuth.js +21 -1
  26. package/dist/core/auth/oauth/client.d.ts +2 -2
  27. package/dist/core/auth/oauth/client.js +6 -1
  28. package/dist/core/auth/oauth/index.d.ts +30 -7
  29. package/dist/core/auth/oauth/index.js +33 -14
  30. package/dist/core/auth/oauth/providers/github.js +1 -1
  31. package/dist/core/auth/oauth/providers/google.js +1 -1
  32. package/dist/core/auth/oauth/providers/oidc.d.ts +40 -0
  33. package/dist/core/auth/oauth/providers/oidc.js +197 -0
  34. package/dist/core/auth/oauth/state.d.ts +2 -0
  35. package/dist/core/auth/oauth/state.js +2 -0
  36. package/dist/core/auth/oauth/types.d.ts +21 -3
  37. package/dist/core/auth/oauth/types.js +4 -1
  38. package/dist/core/auth/routes.js +1 -1
  39. package/dist/core/auth/tokens.d.ts +3 -1
  40. package/dist/core/auth/tokens.js +2 -1
  41. package/dist/core/configSeam.d.ts +0 -4
  42. package/dist/core/configSeam.js +12 -1
  43. package/dist/core/createServer.js +16 -4
  44. package/dist/core/freePort.d.ts +10 -0
  45. package/dist/core/freePort.js +39 -1
  46. package/dist/core/handlers/socialRouteHandlers.d.ts +9 -1
  47. package/dist/core/handlers/socialRouteHandlers.js +46 -12
  48. package/dist/core/health.d.ts +1 -0
  49. package/dist/core/health.js +2 -1
  50. package/dist/core/http/stages/authRoutes.d.ts +6 -0
  51. package/dist/core/http/stages/authRoutes.js +42 -1
  52. package/dist/core/http/stages/images.js +5 -3
  53. package/dist/core/http/stages/livePages.js +1 -1
  54. package/dist/core/server/fleet/relay.js +9 -1
  55. package/dist/core/server/fleet/stores.d.ts +7 -0
  56. package/dist/core/server/fleet/stores.js +15 -2
  57. package/dist/core/server/pageServer.js +5 -1
  58. package/dist/core/services/realtime.js +4 -2
  59. package/dist/core/services/registry.js +7 -1
  60. package/dist/core/services/robotsTxt.d.ts +16 -0
  61. package/dist/core/services/robotsTxt.js +50 -0
  62. package/dist/core/services/servedSpace.d.ts +8 -0
  63. package/dist/core/services/servedSpace.js +16 -0
  64. package/dist/core/services/sitemapXml.d.ts +7 -0
  65. package/dist/core/services/sitemapXml.js +37 -0
  66. package/dist/functions-api.d.ts +69 -2
  67. package/dist/helpers/fileStore.d.ts +60 -0
  68. package/dist/helpers/fileStore.js +127 -0
  69. package/dist/helpers/outboundGuard.d.ts +32 -3
  70. package/dist/helpers/outboundGuard.js +50 -5
  71. package/dist/hosts/project/agentRuns.d.ts +24 -0
  72. package/dist/hosts/project/agentRuns.js +107 -0
  73. package/dist/hosts/project/laterAsks.d.ts +41 -0
  74. package/dist/hosts/project/laterAsks.js +117 -0
  75. package/dist/hosts/project/plugins.js +11 -4
  76. package/dist/hosts/project/serveProject.d.ts +8 -1
  77. package/dist/hosts/project/serveProject.js +81 -24
  78. package/dist/hosts/project/spaceFailure.d.ts +4 -0
  79. package/dist/hosts/project/spaceFailure.js +10 -0
  80. package/dist/hosts/project/watchSpace.d.ts +5 -5
  81. package/dist/hosts/project/watchSpace.js +15 -6
  82. package/dist/index.js +2 -2
  83. package/dist/kernel.js +1 -1
  84. package/dist/modules/actions/connectorWrite.js +3 -1
  85. package/dist/modules/actions/index.js +1 -1
  86. package/dist/modules/actions/jobs/fileQueue.d.ts +34 -0
  87. package/dist/modules/actions/jobs/fileQueue.js +72 -0
  88. package/dist/modules/actions/jobs/index.js +3 -3
  89. package/dist/modules/actions/jobs/memoryQueue.js +6 -215
  90. package/dist/modules/actions/jobs/queueDocument.d.ts +14 -0
  91. package/dist/modules/actions/jobs/queueDocument.js +22 -0
  92. package/dist/modules/actions/jobs/queueRules.d.ts +39 -0
  93. package/dist/modules/actions/jobs/queueRules.js +270 -0
  94. package/dist/modules/actions/moduleFor.js +2 -0
  95. package/dist/modules/actions/runtime/fileKv.d.ts +3 -1
  96. package/dist/modules/actions/runtime/fileKv.js +12 -98
  97. package/dist/modules/actions/runtime/guards.d.ts +19 -1
  98. package/dist/modules/actions/runtime/guards.js +10 -1
  99. package/dist/modules/actions/runtime/kvChange.d.ts +40 -0
  100. package/dist/modules/actions/runtime/kvChange.js +23 -1
  101. package/dist/modules/actions/runtime/kvList.d.ts +4 -0
  102. package/dist/modules/actions/runtime/kvList.js +5 -1
  103. package/dist/modules/actions/runtime/kvStore.js +15 -1
  104. package/dist/modules/actions/runtime/namespaceKv.js +2 -0
  105. package/dist/modules/actions/runtime/renderResolver.js +31 -5
  106. package/dist/modules/actions/runtime/runAction.js +16 -6
  107. package/dist/modules/actions/runtime/scope.js +11 -0
  108. package/dist/modules/actions/runtime/taskContext.js +11 -32
  109. package/dist/modules/actions/tasks/auth.js +2 -0
  110. package/dist/modules/actions/tasks/connector.js +6 -2
  111. package/dist/modules/actions/tasks/flow.js +5 -0
  112. package/dist/modules/actions/tasks/http.js +2 -1
  113. package/dist/modules/actions/tasks/kv.js +5 -0
  114. package/dist/modules/actions/tasks/list.js +11 -2
  115. package/dist/modules/actions/tasks/transform.js +2 -0
  116. package/dist/modules/actions/transport/callHandler.js +25 -4
  117. package/dist/modules/actions/types.d.ts +46 -1
  118. package/dist/modules/connectors/engine.d.ts +7 -2
  119. package/dist/modules/connectors/engine.js +4 -4
  120. package/dist/modules/connectors/resolver.d.ts +2 -1
  121. package/dist/modules/connectors/resolver.js +3 -2
  122. package/dist/modules/functions/build.d.ts +7 -2
  123. package/dist/modules/functions/build.js +90 -6
  124. package/dist/modules/functions/capabilities.js +16 -0
  125. package/dist/modules/functions/context.js +6 -2
  126. package/dist/modules/functions/contract.d.ts +39 -1
  127. package/dist/modules/functions/driver.d.ts +2 -1
  128. package/dist/modules/functions/driver.js +35 -0
  129. package/dist/modules/functions/load.d.ts +1 -1
  130. package/dist/modules/functions/load.js +2 -2
  131. package/dist/modules/functions/manifest.js +7 -1
  132. package/dist/modules/functions/oauth.d.ts +1 -1
  133. package/dist/modules/functions/oauth.js +4 -4
  134. package/dist/modules/functions/protocol.d.ts +6 -0
  135. package/dist/modules/functions/sandbox/guest/bytes.d.ts +27 -0
  136. package/dist/modules/functions/sandbox/guest/bytes.js +108 -0
  137. package/dist/modules/functions/sandbox/guest/crypto.d.ts +47 -0
  138. package/dist/modules/functions/sandbox/guest/crypto.js +144 -0
  139. package/dist/modules/functions/sandbox/guest/events.d.ts +152 -0
  140. package/dist/modules/functions/sandbox/guest/events.js +143 -0
  141. package/dist/modules/functions/sandbox/guest/fetch.d.ts +305 -0
  142. package/dist/modules/functions/sandbox/guest/fetch.js +237 -0
  143. package/dist/modules/functions/sandbox/guest/index.d.ts +28 -0
  144. package/dist/modules/functions/sandbox/guest/index.js +130 -0
  145. package/dist/modules/functions/sandbox/{guest.d.ts → guest/types.d.ts} +5 -12
  146. package/dist/modules/functions/sandbox/isolate.js +20 -6
  147. package/dist/modules/functions/space.js +2 -8
  148. package/dist/modules/images/imageProxy.d.ts +3 -2
  149. package/dist/modules/images/imageProxy.js +2 -2
  150. package/dist/modules/mongo/jobQueue.js +0 -19
  151. package/dist/modules/mysql/accounts.js +12 -5
  152. package/dist/modules/mysql/jobs/index.d.ts +1 -1
  153. package/dist/modules/mysql/jobs/schema.d.ts +0 -6
  154. package/dist/modules/mysql/jobs/schema.js +2 -46
  155. package/dist/modules/mysql/schema.js +26 -1
  156. package/dist/modules/mysql/sessions.js +2 -1
  157. package/dist/modules/realtime/handlers.d.ts +9 -4
  158. package/dist/modules/realtime/handlers.js +20 -3
  159. package/dist/modules/realtime/hub.d.ts +4 -2
  160. package/dist/modules/realtime/hub.js +36 -4
  161. package/dist/modules/realtime/index.d.ts +14 -0
  162. package/dist/modules/realtime/index.js +14 -1
  163. package/dist/modules/realtime/presence.d.ts +33 -0
  164. package/dist/modules/realtime/presence.js +56 -0
  165. package/dist/modules/realtime/socket.d.ts +3 -1
  166. package/dist/modules/realtime/socket.js +2 -2
  167. package/dist/modules/rsc/connectorRscData.d.ts +6 -1
  168. package/dist/modules/rsc/connectorRscData.js +27 -6
  169. package/dist/modules/rsc/externalQueryReader.d.ts +28 -0
  170. package/dist/modules/rsc/externalQueryReader.js +43 -0
  171. package/dist/modules/rsc/handler.js +1 -1
  172. package/dist/modules/rsc/resolveRscData.d.ts +11 -1
  173. package/dist/modules/rsc/resolveRscData.js +86 -16
  174. package/dist/modules/runtime/inside.js +1 -1
  175. package/dist/modules/runtime/runner.js +2 -1
  176. package/dist/modules/sqlite/jobQueue.d.ts +35 -0
  177. package/dist/modules/sqlite/jobQueue.js +56 -0
  178. package/dist/modules/sqlite/kv.d.ts +1 -1
  179. package/dist/modules/sqlite/kv.js +2 -10
  180. package/dist/modules/sqlite/open.d.ts +3 -0
  181. package/dist/modules/sqlite/open.js +13 -0
  182. package/dist/modules/ssr/Component.d.ts +5 -1
  183. package/dist/modules/ssr/Component.js +3 -1
  184. package/dist/modules/ssr/applySSRResult.d.ts +8 -1
  185. package/dist/modules/ssr/applySSRResult.js +23 -3
  186. package/dist/modules/ssr/handler.js +30 -5
  187. package/dist/modules/ssr/prepareRender.js +27 -5
  188. package/dist/modules/ssr/preview.d.ts +2 -0
  189. package/dist/modules/ssr/preview.js +6 -3
  190. package/dist/modules/ssr/registerExternalPlugins.d.ts +2 -6
  191. package/dist/modules/ssr/registerExternalPlugins.js +2 -2
  192. package/dist/modules/ssr/resolvePageSeo.d.ts +11 -0
  193. package/dist/modules/ssr/resolvePageSeo.js +13 -2
  194. package/dist/modules/ssr/streamBody.js +2 -2
  195. package/dist/modules/ssr/views/template.ejs +21 -17
  196. package/dist/mysql.d.ts +1 -1
  197. package/dist/mysql.js +2 -2
  198. package/dist/plugins/manager.d.ts +5 -0
  199. package/dist/plugins/manager.js +9 -0
  200. package/dist/sqlite.d.ts +8 -1
  201. package/dist/sqlite.js +3 -1
  202. package/package.json +5 -5
  203. package/skills/plitzi-authoring/CHEATSHEET.md +6 -6
  204. package/skills/plitzi-authoring/SKILL.md +4 -2
  205. package/skills/plitzi-authoring/recipes/accordion.ts +2 -1
  206. package/skills/plitzi-authoring/recipes/carousel.ts +24 -3
  207. package/skills/plitzi-authoring/recipes/detail-page.ts +0 -1
  208. package/skills/plitzi-authoring/recipes/embed-and-svg.ts +3 -1
  209. package/skills/plitzi-authoring/recipes/filter-a-list.ts +0 -1
  210. package/skills/plitzi-authoring/recipes/show-data.ts +0 -1
  211. package/skills/plitzi-authoring/recipes/typed-data.ts +0 -1
  212. package/skills/plitzi-authoring/reference/accessibility.md +7 -2
  213. package/skills/plitzi-authoring/reference/auth.md +15 -4
  214. package/skills/plitzi-authoring/reference/authoring-errors.md +51 -10
  215. package/skills/plitzi-authoring/reference/colours-and-motion.md +7 -1
  216. package/skills/plitzi-authoring/reference/components.md +4 -1
  217. package/skills/plitzi-authoring/reference/data-and-visibility.md +31 -22
  218. package/skills/plitzi-authoring/reference/efficiency.md +2 -1
  219. package/skills/plitzi-authoring/reference/elements-and-styles.md +16 -15
  220. package/skills/plitzi-authoring/reference/flows.md +20 -8
  221. package/skills/plitzi-authoring/reference/kept-state.md +8 -0
  222. package/skills/plitzi-authoring/reference/layouts.md +18 -2
  223. package/skills/plitzi-authoring/reference/lists.md +20 -4
  224. package/skills/plitzi-authoring/reference/plugin-reach.md +12 -0
  225. package/skills/plitzi-authoring/reference/plugins.md +13 -2
  226. package/skills/plitzi-authoring/reference/realtime.md +8 -5
  227. package/skills/plitzi-authoring/reference/structure.md +17 -1
  228. package/skills/plitzi-authoring/reference/templates.md +11 -3
  229. package/skills/plitzi-authoring/reference/testing.md +82 -5
  230. package/skills/plitzi-authoring/reference/typed-sources.md +6 -0
  231. package/skills/plitzi-authoring/reference/validation.md +1 -1
  232. package/dist/core/auth/api.js +0 -1323
  233. package/dist/modules/functions/sandbox/guest.js +0 -662
@@ -65,11 +65,52 @@ var logoutStage = async (ctx) => {
65
65
  res.end();
66
66
  return true;
67
67
  };
68
+ var isSessionScope = (value) => value === "site" || value === "all";
69
+ /**
70
+ * Signing the person out on every device (`endSessions`): `{ scope: 'site' }`, this host's sessions — a space's visitor
71
+ * ending it on their phone too; `{ scope: 'all' }`, every session of the account. Said, never assumed: a sign-out the
72
+ * page did not mean is one the person did not ask for. Guarded as a sign-out is — a page of another origin is refused.
73
+ */
74
+ var logoutEverywhereStage = async (ctx) => {
75
+ const { config, raw, req, res } = ctx;
76
+ const path = config.logoutEverywherePath === false ? null : config.logoutEverywherePath ?? "/auth/logout-everywhere";
77
+ const { endSessions } = config.adapters;
78
+ if (!path || !endSessions || req.method !== "POST" || req.path !== path) return false;
79
+ if (refusedCrossSite(ctx)) return true;
80
+ req.body = await readRawBody(raw);
81
+ const { scope } = parseCredentials(req);
82
+ const answer = (status, body) => {
83
+ res.setStatus(status);
84
+ res.setHeader("Content-Type", "application/json");
85
+ res.send(JSON.stringify(body));
86
+ return true;
87
+ };
88
+ if (!isSessionScope(scope)) return answer(400, {
89
+ error: "Say which sessions end: { \"scope\": \"site\" } for this site's, { \"scope\": \"all\" } for every one of the account",
90
+ reason: "invalid"
91
+ });
92
+ if (!await endSessions(req, scope)) return answer(401, {
93
+ error: "Nobody is signed in here",
94
+ reason: "missing"
95
+ });
96
+ clearSessionCookies(req, res, config.authCookie);
97
+ if (isNavigation(req)) {
98
+ res.setStatus(303);
99
+ res.setHeader("Location", safeRedirectTarget(req));
100
+ res.end();
101
+ return true;
102
+ }
103
+ return answer(200, {
104
+ scope,
105
+ ended: true
106
+ });
107
+ };
68
108
  var authRoutesStages = [
69
109
  loginStage,
70
110
  logoutStage,
111
+ logoutEverywhereStage,
71
112
  exchangeStage,
72
113
  signInStage
73
114
  ];
74
115
  //#endregion
75
- export { authRoutesStages, loginStage, logoutStage };
116
+ export { authRoutesStages, loginStage, logoutEverywhereStage, logoutStage };
@@ -1,4 +1,5 @@
1
1
  import { serverLog } from "../../../helpers/serverLog.js";
2
+ import { privateOriginsOf } from "../../../helpers/outboundGuard.js";
2
3
  import { createImageProxy } from "../../../modules/images/imageProxy.js";
3
4
  import { loadSharpTransform } from "../../../modules/images/transform.js";
4
5
  import { IMAGE_PATH } from "@plitzi/sdk-shared/helpers";
@@ -8,7 +9,7 @@ import path from "node:path";
8
9
  var imagesPathOf = (config) => config.images && config.images.domains.length > 0 ? IMAGE_PATH : void 0;
9
10
  /** One proxy per configuration, made on the first request: `sharp` is looked for once, and said once when missing. */
10
11
  var proxies = /* @__PURE__ */ new WeakMap();
11
- var proxyFor = (images) => {
12
+ var proxyFor = (images, outbound) => {
12
13
  const known = proxies.get(images);
13
14
  if (known) return known;
14
15
  const made = loadSharpTransform().then((transform) => {
@@ -17,7 +18,8 @@ var proxyFor = (images) => {
17
18
  domains: images.domains,
18
19
  cacheDir: path.resolve(images.cacheDir ?? "tmp/images"),
19
20
  fetch: globalThis.fetch,
20
- transform
21
+ transform,
22
+ outbound: { privateOrigins: privateOriginsOf(outbound?.privateOrigins) }
21
23
  });
22
24
  });
23
25
  proxies.set(images, made);
@@ -33,7 +35,7 @@ var imagesStage = async (ctx) => {
33
35
  ctx.res.send("Method not allowed");
34
36
  return true;
35
37
  }
36
- const answer = await (await proxyFor(images))({
38
+ const answer = await (await proxyFor(images, ctx.config.outbound))({
37
39
  url: ctx.req.query.url,
38
40
  width: ctx.req.query.w,
39
41
  accept: ctx.req.headers.accept ?? ""
@@ -1,5 +1,5 @@
1
- import { openEventStream } from "../sse.js";
2
1
  import "../../previewToken.js";
2
+ import { openEventStream } from "../sse.js";
3
3
  import { randomUUID } from "node:crypto";
4
4
  //#region src/core/http/stages/livePages.ts
5
5
  /** Where an open page listens for what the server has to tell it: its space changed, a plugin was built again. */
@@ -75,7 +75,8 @@ var relayPlugins = (plugins, forget, channel, label) => {
75
75
  if (payload.op === "register" && typeof payload.name === "string") {
76
76
  const source = pluginSourceOf(payload.source);
77
77
  if (source) plugins.register(payload.name, source);
78
- } else if (payload.op === "forget") forget(optionalString(payload.name), optionalString(payload.version));
78
+ } else if (payload.op === "unregister" && typeof payload.name === "string") plugins.unregister(payload.name);
79
+ else if (payload.op === "forget") forget(optionalString(payload.name), optionalString(payload.version));
79
80
  });
80
81
  return {
81
82
  register: (name, source) => {
@@ -90,6 +91,13 @@ var relayPlugins = (plugins, forget, channel, label) => {
90
91
  source
91
92
  });
92
93
  },
94
+ unregister: (name) => {
95
+ plugins.unregister(name);
96
+ broadcast(channel, {
97
+ op: "unregister",
98
+ name
99
+ });
100
+ },
93
101
  invalidate: async (name, version) => {
94
102
  await plugins.invalidate(name, version);
95
103
  broadcast(channel, {
@@ -1,12 +1,19 @@
1
1
  import { HostedStore } from './channel';
2
2
  import { FleetStoreName } from './link';
3
3
  import { ActionKvAdapter } from '../../../modules/actions/types';
4
+ import { JobQueue } from '@plitzi/sdk-shared';
4
5
  /**
5
6
  * A `kv` the deployment makes — a file — opened by ONE process of a fleet and reached by the rest: made in the primary
6
7
  * (or the single process there is), and in a worker the primary's, over the channel. Made in every worker instead,
7
8
  * each would hold its own copy of the file and write it over the others'.
8
9
  */
9
10
  export declare const fleetKv: (make: () => ActionKvAdapter) => ActionKvAdapter;
11
+ /**
12
+ * The job queue of a server — ONE for the primary and its workers, as `fleetKv` is: made in the primary (or the single
13
+ * process there is), and in a worker the primary's, over the channel. The primary's jobs made apart from what it offered
14
+ * its workers would be two queues: a worker's `ctx.later` waiting where nobody claims.
15
+ */
16
+ export declare const fleetJobQueue: (make: () => JobQueue) => JobQueue;
10
17
  /**
11
18
  * What the primary keeps for its workers: the same in-memory defaults a single server makes for itself, made here
12
19
  * once — when a worker first asks — so the fleet has one of each rather than one per worker.
@@ -7,6 +7,8 @@ import { RATE_LIMIT_METHODS, createMemoryRateLimit } from "../../auth/throttle.j
7
7
  //#region src/core/server/fleet/stores.ts
8
8
  /** The `kv` a deployment keeps somewhere of its own — a file, a database — when the primary is the one that opened it. */
9
9
  var deploymentKv;
10
+ /** The job queue the primary made — in memory, a file, a database — for its workers to reach rather than make their own. */
11
+ var deploymentJobs;
10
12
  /**
11
13
  * A `kv` the deployment makes — a file — opened by ONE process of a fleet and reached by the rest: made in the primary
12
14
  * (or the single process there is), and in a worker the primary's, over the channel. Made in every worker instead,
@@ -19,15 +21,26 @@ var fleetKv = (make) => {
19
21
  return deploymentKv;
20
22
  };
21
23
  /**
24
+ * The job queue of a server — ONE for the primary and its workers, as `fleetKv` is: made in the primary (or the single
25
+ * process there is), and in a worker the primary's, over the channel. The primary's jobs made apart from what it offered
26
+ * its workers would be two queues: a worker's `ctx.later` waiting where nobody claims.
27
+ */
28
+ var fleetJobQueue = (make) => {
29
+ const remote = fleetStore("actions.jobs", JOB_QUEUE_METHODS);
30
+ if (remote) return remote;
31
+ deploymentJobs = make();
32
+ return deploymentJobs;
33
+ };
34
+ /**
22
35
  * What the primary keeps for its workers: the same in-memory defaults a single server makes for itself, made here
23
36
  * once — when a worker first asks — so the fleet has one of each rather than one per worker.
24
37
  */
25
38
  var FLEET_STORES = {
26
39
  "actions.kv": hostable(() => deploymentKv ?? createMemoryKv(), KV_METHODS),
27
40
  "realtime.kv": hostable(createMemoryKv, KV_METHODS),
28
- "actions.jobs": hostable(() => createMemoryJobQueue(), JOB_QUEUE_METHODS),
41
+ "actions.jobs": hostable(() => deploymentJobs ?? createMemoryJobQueue(), JOB_QUEUE_METHODS),
29
42
  "ssr.drafts": hostable(createMemoryDraftStore, DRAFT_STORE_METHODS),
30
43
  "auth.rateLimit": hostable(() => ({ check: createMemoryRateLimit() }), RATE_LIMIT_METHODS)
31
44
  };
32
45
  //#endregion
33
- export { FLEET_STORES, fleetKv };
46
+ export { FLEET_STORES, fleetJobQueue, fleetKv };
@@ -1,6 +1,7 @@
1
1
  import { configureServerLog, defaultLogLevel, isLogged, logLevelOf } from "../../helpers/serverLog.js";
2
2
  import { runsFleetJobs } from "./fleet/role.js";
3
3
  import { fleetStore } from "./fleet/link.js";
4
+ import { DRAFT_STORE_METHODS, createMemoryDraftStore } from "../../modules/ssr/preview.js";
4
5
  import { realtimeModuleFor } from "../../modules/realtime/index.js";
5
6
  import { actionsModuleFor } from "../../modules/actions/moduleFor.js";
6
7
  import { createHttpServer } from "./baseServer.js";
@@ -11,7 +12,6 @@ import normalizePlugins, { normalizePluginSource } from "../../helpers/normalize
11
12
  import { reportReactBuild } from "../../helpers/reportReactBuild.js";
12
13
  import { isFunctionsDefinition } from "../../modules/functions/load.js";
13
14
  import { invalidatePluginComponentCache } from "../../modules/ssr/loadPluginComponents.js";
14
- import { DRAFT_STORE_METHODS, createMemoryDraftStore } from "../../modules/ssr/preview.js";
15
15
  import { compileTemplate } from "../../modules/ssr/template.js";
16
16
  import { PluginManager } from "../../plugins/manager.js";
17
17
  import { watchPluginSources } from "../../plugins/watch.js";
@@ -45,6 +45,10 @@ var createPageServer = (config, services, extensions) => {
45
45
  const normalized = normalizePluginSource(source);
46
46
  pluginManager.register(`${name}@${normalized.version}`, normalized);
47
47
  },
48
+ unregister: (name) => {
49
+ pluginManager.unregister(name);
50
+ invalidatePluginComponentCache();
51
+ },
48
52
  invalidate: async (name, version) => {
49
53
  await pluginManager.invalidate(name, version);
50
54
  invalidatePluginComponentCache();
@@ -23,7 +23,8 @@ var realtimeStage = async (ctx) => {
23
23
  resolveChannels: realtime.resolveChannels,
24
24
  grants: realtime.grants,
25
25
  allowedOrigins: realtime.allowedOrigins,
26
- ...jobs ? { jobs } : {}
26
+ ...jobs ? { jobs } : {},
27
+ ...realtime.admitSpace ? { admitSpace: realtime.admitSpace } : {}
27
28
  });
28
29
  return true;
29
30
  }
@@ -37,7 +38,8 @@ var realtimeStage = async (ctx) => {
37
38
  hub: realtime.hub,
38
39
  resolveChannels: realtime.resolveChannels,
39
40
  grants: realtime.grants,
40
- ...jobs ? { jobs } : {}
41
+ ...jobs ? { jobs } : {},
42
+ ...realtime.admitSpace ? { admitSpace: realtime.admitSpace } : {}
41
43
  });
42
44
  return true;
43
45
  }
@@ -1,7 +1,9 @@
1
1
  import { actionStage } from "./action.js";
2
2
  import { functionRoutesStage } from "./functionRoutes.js";
3
3
  import { realtimeStage } from "./realtime.js";
4
+ import { robotsTxtStage } from "./robotsTxt.js";
4
5
  import { rscStage } from "./rsc.js";
6
+ import { sitemapXmlStage } from "./sitemapXml.js";
5
7
  import { spaceDocumentStage } from "./spaceDocument.js";
6
8
  import { imagesStage } from "../http/stages/images.js";
7
9
  import { notFoundStage, ssrStage } from "./ssr.js";
@@ -33,7 +35,11 @@ var buildPagePipeline = (services, extensions = {}) => {
33
35
  stages.push(realtimeStage);
34
36
  stages.push(...extensions.data ?? []);
35
37
  stages.push(functionRoutesStage);
36
- if (services.ssr) stages.push(spaceDocumentStage);
38
+ if (services.ssr) {
39
+ stages.push(spaceDocumentStage);
40
+ stages.push(robotsTxtStage);
41
+ stages.push(sitemapXmlStage);
42
+ }
37
43
  stages.push(services.ssr ? ssrStage : notFoundStage);
38
44
  return stages;
39
45
  };
@@ -0,0 +1,16 @@
1
+ import { SSRContext, Stage } from '../http/types';
2
+ /** What a space that says nothing answers: everything may be crawled. */
3
+ export declare const DEFAULT_ROBOTS_TXT = "User-agent: *\nAllow: /\n";
4
+ /**
5
+ * The crawlers that gather pages to train AI models, by the user agent each reads `/robots.txt` as — what a space that
6
+ * says `blockAiCrawlers` keeps out. A search engine's own crawler is none of them: Googlebot reads on, Google-Extended
7
+ * (the one that trains) does not.
8
+ */
9
+ export declare const AI_CRAWLERS: readonly ["GPTBot", "ChatGPT-User", "OAI-SearchBot", "ClaudeBot", "anthropic-ai", "Google-Extended", "Applebot-Extended", "CCBot", "PerplexityBot", "Bytespider", "Amazonbot", "meta-externalagent"];
10
+ /**
11
+ * `/robots.txt`: the space's own (`settings.robotsTxt`) or one that lets crawlers read everything, then — when the space
12
+ * keeps them out (`settings.blockAiCrawlers`) — a `Disallow: /` for each AI crawler, and the address of its sitemap
13
+ * unless its own text names one. Never the space's page for an address it has none for: a crawler reads a 404 page as
14
+ * "no rules", and an HTML page as rules it cannot parse.
15
+ */
16
+ export declare const robotsTxtStage: Stage<SSRContext>;
@@ -0,0 +1,50 @@
1
+ import { requestOrigin } from "../requestParser.js";
2
+ import { servedSpace } from "./servedSpace.js";
3
+ //#region src/core/services/robotsTxt.ts
4
+ /** What a space that says nothing answers: everything may be crawled. */
5
+ var DEFAULT_ROBOTS_TXT = "User-agent: *\nAllow: /\n";
6
+ /**
7
+ * The crawlers that gather pages to train AI models, by the user agent each reads `/robots.txt` as — what a space that
8
+ * says `blockAiCrawlers` keeps out. A search engine's own crawler is none of them: Googlebot reads on, Google-Extended
9
+ * (the one that trains) does not.
10
+ */
11
+ var AI_CRAWLERS = [
12
+ "GPTBot",
13
+ "ChatGPT-User",
14
+ "OAI-SearchBot",
15
+ "ClaudeBot",
16
+ "anthropic-ai",
17
+ "Google-Extended",
18
+ "Applebot-Extended",
19
+ "CCBot",
20
+ "PerplexityBot",
21
+ "Bytespider",
22
+ "Amazonbot",
23
+ "meta-externalagent"
24
+ ];
25
+ var SITEMAP_LINE = /^\s*sitemap\s*:/im;
26
+ /**
27
+ * `/robots.txt`: the space's own (`settings.robotsTxt`) or one that lets crawlers read everything, then — when the space
28
+ * keeps them out (`settings.blockAiCrawlers`) — a `Disallow: /` for each AI crawler, and the address of its sitemap
29
+ * unless its own text names one. Never the space's page for an address it has none for: a crawler reads a 404 page as
30
+ * "no rules", and an HTML page as rules it cannot parse.
31
+ */
32
+ var robotsTxtStage = async (ctx) => {
33
+ const { req } = ctx;
34
+ if (req.method !== "GET" || req.path !== "/robots.txt") return false;
35
+ ctx.operation = "robots";
36
+ const settings = (await servedSpace(ctx, "/robots.txt"))?.schema.settings;
37
+ const own = settings?.robotsTxt?.trim() ? settings.robotsTxt.trim() : DEFAULT_ROBOTS_TXT.trim();
38
+ const origin = requestOrigin(req);
39
+ const sections = [
40
+ own,
41
+ ...settings?.blockAiCrawlers ? AI_CRAWLERS.map((agent) => `User-agent: ${agent}\nDisallow: /`) : [],
42
+ ...origin && !SITEMAP_LINE.test(own) ? [`Sitemap: ${origin}/sitemap.xml`] : []
43
+ ];
44
+ ctx.res.setStatus(200);
45
+ ctx.res.setHeader("Content-Type", "text/plain; charset=utf-8");
46
+ ctx.res.send(`${sections.join("\n\n")}\n`);
47
+ return true;
48
+ };
49
+ //#endregion
50
+ export { AI_CRAWLERS, DEFAULT_ROBOTS_TXT, robotsTxtStage };
@@ -0,0 +1,8 @@
1
+ import { SSRContext } from '../http/types';
2
+ import { OfflineDataRaw } from '@plitzi/sdk-shared';
3
+ /**
4
+ * The space a page at this address renders (no deployment: the server's one space), for a file the server answers from
5
+ * it — `/robots.txt`, `/sitemap.xml`. A space that cannot be read answers nothing, said in the server's log with the
6
+ * file it was read for.
7
+ */
8
+ export declare const servedSpace: (ctx: SSRContext, file: string) => Promise<OfflineDataRaw | undefined>;
@@ -0,0 +1,16 @@
1
+ import { serverLog } from "../../helpers/serverLog.js";
2
+ //#region src/core/services/servedSpace.ts
3
+ /**
4
+ * The space a page at this address renders (no deployment: the server's one space), for a file the server answers from
5
+ * it — `/robots.txt`, `/sitemap.xml`. A space that cannot be read answers nothing, said in the server's log with the
6
+ * file it was read for.
7
+ */
8
+ var servedSpace = async (ctx, file) => {
9
+ const { environment = "main", spaceId = 1, revision = 0 } = ctx.req.ctx.spaceDeployment ?? {};
10
+ if (spaceId === null) return;
11
+ return ctx.config.adapters.getOfflineData(spaceId, environment, revision).catch((error) => {
12
+ serverLog.warn("SSR", `${file} answered without the space: space ${String(spaceId)} could not be read`, error);
13
+ });
14
+ };
15
+ //#endregion
16
+ export { servedSpace };
@@ -0,0 +1,7 @@
1
+ import { SSRContext, Stage } from '../http/types';
2
+ /**
3
+ * `/sitemap.xml`: every page of the space a search engine may read (`sitemapPaths` — the same pages the builder's map
4
+ * marks as listed), at this address's origin, so a space answers its own on its own domain and on the platform's.
5
+ * A space that cannot be read answers an empty list rather than an error: a crawler retries an error, and lists nothing.
6
+ */
7
+ export declare const sitemapXmlStage: Stage<SSRContext>;
@@ -0,0 +1,37 @@
1
+ import { requestOrigin } from "../requestParser.js";
2
+ import { servedSpace } from "./servedSpace.js";
3
+ import { sitemapPaths } from "@plitzi/sdk-shared/navigation";
4
+ //#region src/core/services/sitemapXml.ts
5
+ var XML_ESCAPES = {
6
+ "&": "&amp;",
7
+ "<": "&lt;",
8
+ ">": "&gt;",
9
+ "\"": "&quot;",
10
+ "'": "&apos;"
11
+ };
12
+ var escapeXml = (value) => value.replace(/[&<>"']/g, (character) => XML_ESCAPES[character] ?? character);
13
+ /**
14
+ * `/sitemap.xml`: every page of the space a search engine may read (`sitemapPaths` — the same pages the builder's map
15
+ * marks as listed), at this address's origin, so a space answers its own on its own domain and on the platform's.
16
+ * A space that cannot be read answers an empty list rather than an error: a crawler retries an error, and lists nothing.
17
+ */
18
+ var sitemapXmlStage = async (ctx) => {
19
+ const { req } = ctx;
20
+ if (req.method !== "GET" || req.path !== "/sitemap.xml") return false;
21
+ ctx.operation = "sitemap";
22
+ const schema = (await servedSpace(ctx, "/sitemap.xml"))?.schema;
23
+ const origin = requestOrigin(req);
24
+ const urls = schema && origin ? sitemapPaths(schema).map((path) => ` <url><loc>${escapeXml(`${origin}${path}`)}</loc></url>`) : [];
25
+ ctx.res.setStatus(200);
26
+ ctx.res.setHeader("Content-Type", "application/xml; charset=utf-8");
27
+ ctx.res.send([
28
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
29
+ "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">",
30
+ ...urls,
31
+ "</urlset>",
32
+ ""
33
+ ].join("\n"));
34
+ return true;
35
+ };
36
+ //#endregion
37
+ export { sitemapXmlStage };
@@ -49,6 +49,24 @@ declare type ActionKvStore = {
49
49
  listRange: (list: string, range?: KvListRange) => Promise<KvListEntry[]>;
50
50
  /** Takes the entry with `id` out of the list, and answers whether it was there. */
51
51
  listRemove: (list: string, id: string) => Promise<boolean>;
52
+ /**
53
+ * Writes the list's entry `id` as `next` — or takes it out, `next` null — only if it is still `expected`, the entry
54
+ * `listRange` answered (or, `expected` undefined, only if there is none). Answers whether it wrote: `swap`, for one
55
+ * entry of a list.
56
+ */
57
+ listSwap: (list: string, id: string, expected: KvListEntry | undefined, next: KvListEntry | null) => Promise<boolean>;
58
+ /**
59
+ * Reads the list's entry `id`, hands it to `change` and writes back what that answers — `{ score, value }`, or `null`
60
+ * to take it out — reading and asking again when somebody wrote in between. `undefined` writes nothing. A vote that
61
+ * re-scores an entry while the track it is starts was the race (a run's queue): the entry gone, nothing is put back.
62
+ */
63
+ listChange: (list: string, id: string, change: (current: KvListEntry | undefined) => {
64
+ score: number;
65
+ value: unknown;
66
+ } | null | undefined | Promise<{
67
+ score: number;
68
+ value: unknown;
69
+ } | null | undefined>) => Promise<KvListEntry | null | undefined>;
52
70
  /**
53
71
  * Reads the key, hands its value to `change` and writes back what that answers — reading and asking again when
54
72
  * somebody wrote in between, so no writer undoes another. `change` answering `undefined` writes nothing. Answers what
@@ -121,6 +139,19 @@ export declare type FunctionContext = {
121
139
  fetch: FunctionFetch;
122
140
  /** Says something on one of the space's realtime channels, as the server. */
123
141
  publish: (topic: string, type: string, data: unknown) => Promise<void>;
142
+ /**
143
+ * Who is on a topic of one of the space's `presence: true` channels now — every page connected to it, on whichever
144
+ * replica — the earliest arrived first. A room's listeners, counted by the server rather than by what pages report.
145
+ */
146
+ presence: (topic: string) => Promise<FunctionPresence>;
147
+ /**
148
+ * The space's people, read by another: `get('mika')` or `get(7)` — public fields alone, and only of someone who
149
+ * belongs to the space (the deployment says who: its visitors and members on Plitzi, every account of its own on a
150
+ * server of yours). `undefined` for anyone else, never "exists elsewhere": a profile page, a chat's names.
151
+ */
152
+ visitors: {
153
+ get: (who: string | number) => Promise<FunctionVisitor | undefined>;
154
+ };
124
155
  /** Lets the visitor into one topic of a private (`grant: true`) channel. */
125
156
  grant: (topic: string, ttlSeconds?: number) => Promise<string>;
126
157
  /** Takes a grant back — or every grant for the topic, naming none. */
@@ -362,6 +393,19 @@ export declare type FunctionOAuthToken = {
362
393
  scopes?: string[];
363
394
  };
364
395
 
396
+ /** Who is on a presence channel's topic: how many, and each page with who is signed in on it. */
397
+ export declare type FunctionPresence = {
398
+ count: number;
399
+ members: {
400
+ from: string;
401
+ user?: {
402
+ id: number;
403
+ name: string;
404
+ };
405
+ since: number;
406
+ }[];
407
+ };
408
+
365
409
  /**
366
410
  * An HTTP endpoint of the space, under `/fn/`: a web-standard handler, the shape every edge runtime runs. The request
367
411
  * carries no credentials — `ctx.user` says who is asking — and the response sets no cookies: the host's are the
@@ -374,7 +418,10 @@ export declare type FunctionRouteContext = FunctionContext & {
374
418
  params: Record<string, string>;
375
419
  };
376
420
 
377
- /** What a space's `functions/index.ts` exports: its tasks, its routes, and where its code may reach. */
421
+ /**
422
+ * What each file at the top of a space's `functions/` exports by default — its tasks, its routes, and where its code
423
+ * may reach — merged into the one definition a bundle exports (`mergeFunctions`).
424
+ */
378
425
  export declare type FunctionsDefinition = {
379
426
  /** The hosts `ctx.fetch` may reach. Anything else is refused before it leaves. */
380
427
  allow?: {
@@ -443,6 +490,17 @@ export declare type FunctionUser = {
443
490
  roles: string[];
444
491
  };
445
492
 
493
+ /**
494
+ * A person of the space as another's code may read them: who they are to a page — never their email, their roles or
495
+ * anything they did not show. `name` and `avatar` where the deployment keeps them.
496
+ */
497
+ export declare type FunctionVisitor = {
498
+ id: number;
499
+ username: string;
500
+ name?: string;
501
+ avatar?: string;
502
+ };
503
+
446
504
  declare type InteractionCallbackParam<T extends Record<string, unknown> = Record<string, unknown>> = {
447
505
  canBind?: boolean;
448
506
  label?: string;
@@ -483,6 +541,15 @@ declare type InteractionCallbackParam<T extends Record<string, unknown> = Record
483
541
  } | {
484
542
  type: 'boolean';
485
543
  defaultValue?: boolean;
544
+ }
545
+ /**
546
+ * Several values, handed to a task as a list of text: bound to a list it is that list, and written by hand it is one
547
+ * a line (or separated by commas) — at most `maxItems`. A run's room took its genres as comma text before it.
548
+ */
549
+ | {
550
+ type: 'list';
551
+ defaultValue?: string[];
552
+ maxItems?: number;
486
553
  } | {
487
554
  /**
488
555
  * Several elements of the space, stored as their ids. The editor offers the elements of `elementType` to pick
@@ -515,7 +582,7 @@ declare type InteractionCallbackParam<T extends Record<string, unknown> = Record
515
582
 
516
583
  declare type InteractionCallbackParamValues<T extends Record<string, unknown> = Record<string, unknown>> = T;
517
584
 
518
- declare type InteractionParamType = 'boolean' | 'select' | 'text' | 'number' | 'textarea' | 'codemirror-text' | 'codemirror-json' | 'elements';
585
+ declare type InteractionParamType = 'boolean' | 'select' | 'text' | 'number' | 'textarea' | 'codemirror-text' | 'codemirror-json' | 'elements' | 'list';
519
586
 
520
587
  /**
521
588
  * The durable queue the server's work waits in: a schedule's fires, the runs set for later, and the jobs of the spaces'
@@ -0,0 +1,60 @@
1
+ /**
2
+ * What a store kept in one JSON file needs beside its own rules: the file held by one process, and its document written
3
+ * whole after each change. `createFileKv` and `createFileJobQueue` keep theirs this way.
4
+ */
5
+ /**
6
+ * Who holds a file: written beside it (`<file>.lock`) while a process has it — and, for a server, the address it
7
+ * answers at (`serves`), which a second one started beside it is pointed to.
8
+ */
9
+ export type FileHolder = {
10
+ pid: number;
11
+ since: string;
12
+ owner?: string;
13
+ serves?: string;
14
+ };
15
+ /** What a process says of itself as it takes a file: who it is, and where it answers. */
16
+ export type HolderOf = {
17
+ owner?: string;
18
+ serves?: string;
19
+ };
20
+ /**
21
+ * A file another running process holds: its message is the whole report — who holds it and how to stop it — said as it
22
+ * is when the server starts (`serveProject`). Thrown plain, it was a stack ending on its cause's `EEXIST`, and the agent
23
+ * reading the end of it found no word of what to do.
24
+ */
25
+ export declare class FileInUseError extends Error {
26
+ /** The process that holds it: a server says where it answers, for the one refused to point there. */
27
+ readonly holder: FileHolder;
28
+ constructor(message: string, holder: FileHolder, options?: ErrorOptions);
29
+ }
30
+ /** Lets go of a file this process holds. */
31
+ export declare const letGo: (lock: string) => void;
32
+ /**
33
+ * Takes the file for this process, or says who has it — `store` names the store in what is said (`createFileKv`).
34
+ *
35
+ * Two processes on one file each load it and then write their whole document over it: every change one makes, the
36
+ * other erases with its next write, and nothing anywhere says so — a second server started beside the first, a
37
+ * `--watch` left running after a restart. So a file has one holder: a second is refused, naming the first. A lock whose
38
+ * process is gone — killed, crashed — is taken over.
39
+ */
40
+ export declare const holdFile: (file: string, { owner, serves }: HolderOf, store: string) => string;
41
+ export type DocumentWriter = {
42
+ /** Says the document changed: it is written as soon as the write under way, if any, is done. */
43
+ changed: () => void;
44
+ /** Resolves once everything changed so far is on disk; rejects when it could not be written. */
45
+ flush: () => Promise<void>;
46
+ };
47
+ /**
48
+ * Writes `document()` to `file` whole after each change, through a temporary file renamed over the old one — changes
49
+ * that arrive while a write is under way are written together right after it, so a crash loses at most the changes of
50
+ * that instant and never leaves half a file. A write that failed is said in the log and tried again by the next change
51
+ * or `flush`, never in a loop against a disk that keeps refusing.
52
+ */
53
+ export declare const documentWriter: ({ file, document, store, what }: {
54
+ file: string;
55
+ document: () => string;
56
+ /** The store, as an error names it: `createFileKv`. */
57
+ store: string;
58
+ /** What the file is, as the log says it: `kv file`. */
59
+ what: string;
60
+ }) => DocumentWriter;