@plitzi/sdk-server 0.38.20 → 0.38.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (245) hide show
  1. package/CHANGELOG.md +141 -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/auth/createAuth.d.ts +1 -1
  6. package/dist/core/auth/tokens.d.ts +1 -1
  7. package/dist/core/configSeam.js +12 -2
  8. package/dist/core/services/functionRoutes.js +7 -2
  9. package/dist/core/services/realtime.js +5 -2
  10. package/dist/functions-api.d.ts +176 -3
  11. package/dist/functions.d.ts +3 -1
  12. package/dist/functions.js +2 -1
  13. package/dist/helpers/serverLog.d.ts +1 -1
  14. package/dist/helpers/serverLog.js +1 -1
  15. package/dist/hosts/project/plugins.js +20 -3
  16. package/dist/hosts/project/serveProject.js +16 -1
  17. package/dist/modules/actions/index.js +17 -4
  18. package/dist/modules/actions/jobs/index.d.ts +4 -3
  19. package/dist/modules/actions/jobs/index.js +2 -1
  20. package/dist/modules/actions/jobs/later.d.ts +2 -2
  21. package/dist/modules/actions/jobs/later.js +5 -2
  22. package/dist/modules/actions/jobs/memoryQueue.d.ts +4 -4
  23. package/dist/modules/actions/jobs/memoryQueue.js +69 -25
  24. package/dist/modules/actions/jobs/scheduler.d.ts +2 -2
  25. package/dist/modules/actions/jobs/scheduler.js +5 -2
  26. package/dist/modules/actions/jobs/worker.d.ts +6 -3
  27. package/dist/modules/actions/jobs/worker.js +104 -10
  28. package/dist/modules/actions/runtime/errors.d.ts +9 -1
  29. package/dist/modules/actions/runtime/errors.js +12 -2
  30. package/dist/modules/actions/runtime/runAction.d.ts +5 -2
  31. package/dist/modules/actions/runtime/runAction.js +5 -3
  32. package/dist/modules/actions/runtime/taskContext.d.ts +12 -3
  33. package/dist/modules/actions/runtime/taskContext.js +9 -1
  34. package/dist/modules/actions/types.d.ts +22 -6
  35. package/dist/modules/functions/capabilities.js +124 -13
  36. package/dist/modules/functions/config.d.ts +20 -0
  37. package/dist/modules/functions/context.d.ts +2 -2
  38. package/dist/modules/functions/context.js +16 -3
  39. package/dist/modules/functions/contract.d.ts +97 -3
  40. package/dist/modules/functions/driver.js +136 -9
  41. package/dist/modules/functions/jobControl.d.ts +21 -0
  42. package/dist/modules/functions/jobControl.js +43 -0
  43. package/dist/modules/functions/jobs.d.ts +98 -0
  44. package/dist/modules/functions/jobs.js +438 -0
  45. package/dist/modules/functions/manifest.d.ts +2 -0
  46. package/dist/modules/functions/manifest.js +37 -4
  47. package/dist/modules/functions/native.js +2 -1
  48. package/dist/modules/functions/oauth.d.ts +3 -2
  49. package/dist/modules/functions/oauth.js +53 -19
  50. package/dist/modules/functions/protocol.d.ts +98 -7
  51. package/dist/modules/functions/protocol.js +15 -1
  52. package/dist/modules/functions/routes.d.ts +9 -1
  53. package/dist/modules/functions/routes.js +50 -25
  54. package/dist/modules/functions/runner/messages.d.ts +0 -1
  55. package/dist/modules/functions/runner/messages.js +46 -5
  56. package/dist/modules/functions/runner/remote.js +60 -8
  57. package/dist/modules/functions/runner/service.js +54 -8
  58. package/dist/modules/functions/sandbox/guest.js +5 -3
  59. package/dist/modules/functions/sandbox/isolate.js +7 -8
  60. package/dist/modules/functions/space.js +4 -4
  61. package/dist/modules/mongo/jobQueue.d.ts +3 -3
  62. package/dist/modules/mongo/jobQueue.js +137 -26
  63. package/dist/modules/mysql/jobs/jobQueue.d.ts +3 -3
  64. package/dist/modules/mysql/jobs/jobQueue.js +97 -33
  65. package/dist/modules/mysql/jobs/schema.js +38 -11
  66. package/dist/modules/realtime/handlers.d.ts +5 -2
  67. package/dist/modules/realtime/handlers.js +15 -4
  68. package/dist/modules/realtime/index.d.ts +11 -1
  69. package/dist/modules/realtime/index.js +8 -1
  70. package/dist/modules/realtime/jobs.d.ts +20 -0
  71. package/dist/modules/realtime/jobs.js +41 -0
  72. package/dist/modules/realtime/retained.d.ts +3 -2
  73. package/dist/modules/realtime/retained.js +2 -2
  74. package/dist/modules/realtime/socket.d.ts +4 -1
  75. package/dist/modules/realtime/socket.js +2 -2
  76. package/dist/modules/rsc/resolveRscData.js +2 -1
  77. package/dist/modules/runtime/host.js +1 -1
  78. package/dist/modules/runtime/runner.d.ts +1 -1
  79. package/dist/modules/runtime/runner.js +12 -2
  80. package/dist/modules/runtime/stages.js +1 -1
  81. package/dist/modules/ssr/applySSRResult.d.ts +5 -0
  82. package/dist/modules/ssr/applySSRResult.js +8 -1
  83. package/dist/modules/ssr/buildBody.js +2 -1
  84. package/dist/modules/ssr/prepareRender.d.ts +3 -0
  85. package/dist/modules/ssr/prepareRender.js +17 -5
  86. package/dist/modules/ssr/spaceDocument.d.ts +2 -1
  87. package/dist/modules/ssr/spaceDocument.js +14 -5
  88. package/dist/modules/ssr/streamBody.js +2 -1
  89. package/package.json +3 -3
  90. package/skills/plitzi-authoring/reference/auth.md +6 -0
  91. package/skills/plitzi-authoring/reference/authoring-errors.md +1 -0
  92. package/skills/plitzi-authoring/reference/plugin-reach.md +3 -0
  93. package/skills/plitzi-authoring/reference/realtime.md +4 -0
  94. package/dist/adapters/cloudAdapters.test.d.ts +0 -1
  95. package/dist/adapters/jsonAdapters.test.d.ts +0 -1
  96. package/dist/adapters/space/space.test.d.ts +0 -1
  97. package/dist/core/auth/api.test.d.ts +0 -1
  98. package/dist/core/auth/authorize.test.d.ts +0 -1
  99. package/dist/core/auth/createAuth.test.d.ts +0 -1
  100. package/dist/core/auth/csrf.test.d.ts +0 -1
  101. package/dist/core/auth/domains.test.d.ts +0 -1
  102. package/dist/core/auth/identity.test.d.ts +0 -1
  103. package/dist/core/auth/lifecycle.test.d.ts +0 -1
  104. package/dist/core/auth/oauth/oauth.test.d.ts +0 -1
  105. package/dist/core/auth/redirects.test.d.ts +0 -1
  106. package/dist/core/auth/routes.test.d.ts +0 -1
  107. package/dist/core/auth/session.test.d.ts +0 -1
  108. package/dist/core/auth/spaceTokens.test.d.ts +0 -1
  109. package/dist/core/auth/throttle.test.d.ts +0 -1
  110. package/dist/core/auth/tokens.test.d.ts +0 -1
  111. package/dist/core/auth/totp.test.d.ts +0 -1
  112. package/dist/core/configSeam.test.d.ts +0 -1
  113. package/dist/core/createServer.actions.test.d.ts +0 -1
  114. package/dist/core/createServer.functions.test.d.ts +0 -1
  115. package/dist/core/createServer.livePages.test.d.ts +0 -1
  116. package/dist/core/createServer.notFound.test.d.ts +0 -1
  117. package/dist/core/createServer.oauth.test.d.ts +0 -1
  118. package/dist/core/createServer.publicData.test.d.ts +0 -1
  119. package/dist/core/createServer.test.d.ts +0 -1
  120. package/dist/core/fontStore.test.d.ts +0 -1
  121. package/dist/core/freePort.test.d.ts +0 -1
  122. package/dist/core/handlers/csrfMiddleware.test.d.ts +0 -1
  123. package/dist/core/handlers/handlers.test.d.ts +0 -1
  124. package/dist/core/handlers/socialRouteHandlers.test.d.ts +0 -1
  125. package/dist/core/http/dispatcher.test.d.ts +0 -1
  126. package/dist/core/http/stages/crossSiteWrites.test.d.ts +0 -1
  127. package/dist/core/http/stages/exchangeRoute.test.d.ts +0 -1
  128. package/dist/core/http/stages/images.test.d.ts +0 -1
  129. package/dist/core/http/stages/middlewares.test.d.ts +0 -1
  130. package/dist/core/http/stages/sessionRenewal.test.d.ts +0 -1
  131. package/dist/core/http/stages/signInRoute.test.d.ts +0 -1
  132. package/dist/core/oauth/authorize.test.d.ts +0 -1
  133. package/dist/core/oauth/register.test.d.ts +0 -1
  134. package/dist/core/oauth/token.test.d.ts +0 -1
  135. package/dist/core/requestParser.test.d.ts +0 -1
  136. package/dist/core/server/baseServer.test.d.ts +0 -1
  137. package/dist/core/server/closeOnSignals.test.d.ts +0 -1
  138. package/dist/core/server/drain.test.d.ts +0 -1
  139. package/dist/core/server/fleet/channel.test.d.ts +0 -1
  140. package/dist/core/server/fleet/fixtures/fleetServer.d.ts +0 -1
  141. package/dist/core/server/fleet/fleet.integration.test.d.ts +0 -1
  142. package/dist/core/server/fleet/relay.test.d.ts +0 -1
  143. package/dist/core/server/fleet/role.test.d.ts +0 -1
  144. package/dist/core/server/fleet/supervisor.test.d.ts +0 -1
  145. package/dist/core/services/resolve.test.d.ts +0 -1
  146. package/dist/core/staticFiles.test.d.ts +0 -1
  147. package/dist/env.test.d.ts +0 -1
  148. package/dist/helpers/atomicFile.test.d.ts +0 -1
  149. package/dist/helpers/buildResponseHelpers.test.d.ts +0 -1
  150. package/dist/helpers/buildServerInfo.test.d.ts +0 -1
  151. package/dist/helpers/cache/CompressedFileCache.test.d.ts +0 -1
  152. package/dist/helpers/cache/cacheManager.test.d.ts +0 -1
  153. package/dist/helpers/cache/keys.test.d.ts +0 -1
  154. package/dist/helpers/compress.test.d.ts +0 -1
  155. package/dist/helpers/hydrationPayload.test.d.ts +0 -1
  156. package/dist/helpers/offlineDataLoader.test.d.ts +0 -1
  157. package/dist/helpers/onAbort.test.d.ts +0 -1
  158. package/dist/helpers/outboundGuard.test.d.ts +0 -1
  159. package/dist/helpers/reportReactBuild.test.d.ts +0 -1
  160. package/dist/helpers/resolveDebugMode.test.d.ts +0 -1
  161. package/dist/helpers/serverLog.test.d.ts +0 -1
  162. package/dist/hosts/authoringHost/index.test.d.ts +0 -1
  163. package/dist/hosts/project/serveProject.test.d.ts +0 -1
  164. package/dist/layers.test.d.ts +0 -1
  165. package/dist/middlewares/spaceDeployment.test.d.ts +0 -1
  166. package/dist/modules/actions/connectorWrite.test.d.ts +0 -1
  167. package/dist/modules/actions/jobs/failureStreak.test.d.ts +0 -1
  168. package/dist/modules/actions/jobs/later.test.d.ts +0 -1
  169. package/dist/modules/actions/jobs/memoryStores.test.d.ts +0 -1
  170. package/dist/modules/actions/jobs/scheduler.test.d.ts +0 -1
  171. package/dist/modules/actions/jobs/testing/jobQueueContract.d.ts +0 -25
  172. package/dist/modules/actions/jobs/worker.test.d.ts +0 -1
  173. package/dist/modules/actions/moduleFor.test.d.ts +0 -1
  174. package/dist/modules/actions/runtime/check.test.d.ts +0 -1
  175. package/dist/modules/actions/runtime/credentials.test.d.ts +0 -1
  176. package/dist/modules/actions/runtime/email.test.d.ts +0 -1
  177. package/dist/modules/actions/runtime/fileKv.test.d.ts +0 -1
  178. package/dist/modules/actions/runtime/flags.test.d.ts +0 -1
  179. package/dist/modules/actions/runtime/guards.test.d.ts +0 -1
  180. package/dist/modules/actions/runtime/kvStore.test.d.ts +0 -1
  181. package/dist/modules/actions/runtime/namespaceKv.test.d.ts +0 -1
  182. package/dist/modules/actions/runtime/redisKv.integration.test.d.ts +0 -1
  183. package/dist/modules/actions/runtime/renderResolver.test.d.ts +0 -1
  184. package/dist/modules/actions/runtime/renderShare.test.d.ts +0 -1
  185. package/dist/modules/actions/runtime/runAction.test.d.ts +0 -1
  186. package/dist/modules/actions/runtime/runLogger.test.d.ts +0 -1
  187. package/dist/modules/actions/runtime/signing.test.d.ts +0 -1
  188. package/dist/modules/actions/taskCatalog.test.d.ts +0 -1
  189. package/dist/modules/actions/tasks/db.test.d.ts +0 -1
  190. package/dist/modules/actions/tasks/email.test.d.ts +0 -1
  191. package/dist/modules/actions/tasks/http.test.d.ts +0 -1
  192. package/dist/modules/actions/tasks/kv.test.d.ts +0 -1
  193. package/dist/modules/actions/transport/callHandler.test.d.ts +0 -1
  194. package/dist/modules/actions/transport/webhookHandler.test.d.ts +0 -1
  195. package/dist/modules/connectors/engine.test.d.ts +0 -1
  196. package/dist/modules/connectors/projection.test.d.ts +0 -1
  197. package/dist/modules/connectors/resolver.test.d.ts +0 -1
  198. package/dist/modules/functions/build.test.d.ts +0 -1
  199. package/dist/modules/functions/load.test.d.ts +0 -1
  200. package/dist/modules/functions/local.test.d.ts +0 -1
  201. package/dist/modules/functions/manifest.test.d.ts +0 -1
  202. package/dist/modules/functions/native.test.d.ts +0 -1
  203. package/dist/modules/functions/oauth.test.d.ts +0 -1
  204. package/dist/modules/functions/plugins.test.d.ts +0 -1
  205. package/dist/modules/functions/routes.test.d.ts +0 -1
  206. package/dist/modules/functions/runner/remote.test.d.ts +0 -1
  207. package/dist/modules/functions/sandbox/isolate.test.d.ts +0 -1
  208. package/dist/modules/functions/testing/tasksOf.d.ts +0 -4
  209. package/dist/modules/images/imageProxy.test.d.ts +0 -1
  210. package/dist/modules/images/transform.test.d.ts +0 -1
  211. package/dist/modules/mongo/stores.integration.test.d.ts +0 -1
  212. package/dist/modules/mysql/accounts.test.d.ts +0 -1
  213. package/dist/modules/mysql/jobs/stores.integration.test.d.ts +0 -1
  214. package/dist/modules/mysql/schema.test.d.ts +0 -1
  215. package/dist/modules/mysql/store.integration.test.d.ts +0 -1
  216. package/dist/modules/realtime/realtime.test.d.ts +0 -1
  217. package/dist/modules/realtime/redisPubSub.test.d.ts +0 -1
  218. package/dist/modules/realtime/retained.test.d.ts +0 -1
  219. package/dist/modules/realtime/socket.test.d.ts +0 -1
  220. package/dist/modules/rsc/connectorRscData.test.d.ts +0 -1
  221. package/dist/modules/rsc/handler.test.d.ts +0 -1
  222. package/dist/modules/rsc/publicFileResolver.test.d.ts +0 -1
  223. package/dist/modules/rsc/resolveRscData.test.d.ts +0 -1
  224. package/dist/modules/runtime/elsewhere.test.d.ts +0 -1
  225. package/dist/modules/runtime/entry.test.d.ts +0 -1
  226. package/dist/modules/runtime/inside.test.d.ts +0 -1
  227. package/dist/modules/runtime/ownServer.test.d.ts +0 -1
  228. package/dist/modules/runtime/runtime.test.d.ts +0 -1
  229. package/dist/modules/sqlite/kv.test.d.ts +0 -1
  230. package/dist/modules/ssr/draftSession.test.d.ts +0 -1
  231. package/dist/modules/ssr/loadPluginComponents.test.d.ts +0 -1
  232. package/dist/modules/ssr/metering.test.d.ts +0 -1
  233. package/dist/modules/ssr/prepareRender.test.d.ts +0 -1
  234. package/dist/modules/ssr/redirect.test.d.ts +0 -1
  235. package/dist/modules/ssr/registerExternalPlugins.test.d.ts +0 -1
  236. package/dist/modules/ssr/reportMissingPlugins.test.d.ts +0 -1
  237. package/dist/modules/ssr/resolvePageSeo.test.d.ts +0 -1
  238. package/dist/modules/ssr/spaceDocument.test.d.ts +0 -1
  239. package/dist/modules/ssr/template.test.d.ts +0 -1
  240. package/dist/modules/ssr/testing/offlineData.d.ts +0 -5
  241. package/dist/modules/ssr/vendor.test.d.ts +0 -1
  242. package/dist/plugins/compile.test.d.ts +0 -1
  243. package/dist/plugins/copy.test.d.ts +0 -1
  244. package/dist/plugins/manager.test.d.ts +0 -1
  245. package/dist/plugins/validate.test.d.ts +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,146 @@
1
1
  # @plitzi/sdk-server
2
2
 
3
+ ## 0.38.22
4
+
5
+ ### Patch Changes
6
+
7
+ - 19fbc45: ## Server
8
+
9
+ - **`ctx.oauth`, after a project moved onto it** (`@plitzi/sdk-server`, `@plitzi/sdk-shared`) — PZ-155..158.
10
+ `functions.oauth.callbackOrigin` fixes the one address providers send a visitor back to, on a server of one space
11
+ reached on several: `serveProject` sets it to the address people reach it on, or its loopback `127.0.0.1` when that is
12
+ plain HTTP (providers refuse `http` past loopback, and `localhost`), and prints it as it starts; the callback then sends
13
+ the visitor on to `returnTo` on the address they started from — its `location` is absolute now. `connect(name,
14
+ { returnTo, authorizeParams })` adds to the connection's parameters for one consent (`prompt: 'select_account'`), and
15
+ refuses one the platform writes. `ctx.fetch` and `ctx.oauth.fetch` take `init.signal`: in the sandbox and a runtime the
16
+ request is numbered and the code's `abort` cuts it on the platform. `ActionRefusal` takes `{ code }`; `ctx.oauth`
17
+ refuses with `oauth-not-connected` and `oauth-no-owner`.
18
+ - **A refusal of the platform's stays one across the sandbox** (`@plitzi/sdk-server`). A call answered with an
19
+ `ActionRefusal` crossed the isolate, the runner service and a runtime as a plain error: caught, the code could not tell
20
+ it apart; uncaught, a route answered 500 `This route failed` instead of 400 and the reason. The answer carries
21
+ `refused` and `code` now, and the code catches the refusal it was thrown.
22
+
23
+ - Updated dependencies [19fbc45]
24
+ - @plitzi/plitzi-sdk@0.38.22
25
+ - @plitzi/sdk-shared@0.38.22
26
+
27
+ ## 0.38.21
28
+
29
+ ### Patch Changes
30
+
31
+ - 19fbc45: ## Server
32
+
33
+ - **Jobs: work longer than a request** (`@plitzi/sdk-server`, `@plitzi/sdk-shared`, `@plitzi/sdk-elements`,
34
+ `@plitzi/plitzi-sdk`, `@plitzi/sdk-authoring`) — PZ-136. A space's code declares them in
35
+ `defineFunctions({ jobs: { train: { watch, maxSeconds, run(input, job, ctx) } } })` and starts them with
36
+ `ctx.jobs.start(name, input, { key })` (`get`, `pause`, `resume`, `cancel` beside it). They run in the actions' durable
37
+ queue — leased, taken over when a server dies, retried with backoff — slice by slice, in the sandbox, in a space's
38
+ runtime and natively alike: `job.save(state)` is the one checkpoint and the next slice starts with `job.state`;
39
+ `job.report(fraction, step)` says how far it is; on `job.signal` (`job.stopping`: `pause`, `cancel`, `limit`,
40
+ `shutdown`) the code has 5 s to save and return. A sandbox slice runs at most `sliceMs` and goes on in the next if it
41
+ saved since it began — one that saved nothing fails, so a job cannot loop forever; a runtime's runs until the job's
42
+ time is up. A real pause: `paused` keeps what it saved until resumed. Who may watch it is RBAC: whoever started it, and
43
+ whoever its `watch` (a channel's access) lets in, on `$job:<id>` — the platform's topic, retained — read with
44
+ `useJob(id)` or a `channel` element on `$job:{{ id }}`; the view never carries its input, its state, or an error other
45
+ than the code's own refusal. Limits per space (its plan) through `functions.jobs.limitsFor` —
46
+ `DEFAULT_FUNCTION_JOB_LIMITS` otherwise: 10 running across the account's spaces (`pool`, the oldest first), 1,000
47
+ waiting, 6 h, slices of 5 min / 30 s CPU / 10,000 calls, 1 MB of state.
48
+ - **The queue's types are the queue's** (`@plitzi/sdk-shared`, `@plitzi/sdk-server`): `ActionJobQueue`, `ActionJob`,
49
+ `ActionJobInput`, `ActionJobStatus`, `ActionJobAttempt`, `ActionJobSettlement`, `ActionJobQuery` are `JobQueue`, `Job`,
50
+ `JobInput`, `JobStatus`, `JobAttempt`, `JobSettlement`, `JobQuery` (`ACTION_JOB_STATUSES` → `JOB_STATUSES`,
51
+ `isJobStatus`, `TERMINAL_JOB_STATUSES`) — the queue holds a schedule's fires, the runs set for later and the jobs of
52
+ the spaces' functions. **What a job runs is its `target`**: `{ kind: 'action', name, trigger }` or
53
+ `{ kind: 'function', name, user, watch, at }`, in place of `actionId`, `trigger` and `function`; `listJobs` filters
54
+ by `kind` and `name`. Also on the queue: `paused` with `pause`/`resume`, `write` for what a running job saves and
55
+ reports, `state`/`progress`/`result`/`activeMs`, `heartbeat` answering `{ jobId, stop: 'cancel' | 'pause' }[]`, a
56
+ settlement's explicit `refund`, `requeue(…, { input, fresh })`. The helpers bring a store a release before left up
57
+ to it by themselves: MySQL's `ensureJobTables` gives each job its target from `action_id`/`trigger_type` and drops
58
+ them (`mysqlJobSchemaUpgrades` lists the statements for a deployment's own migrations); Mongo's queue does the same
59
+ to the documents on first use and drops the `spaceId_1_actionId_1_updatedAt_-1` index. A deployment with a queue of
60
+ its own: the contract tests (`describeJobQueue`) say what it must now do.
61
+ - **A runtime's routes stream** (`@plitzi/sdk-server`): a route under `/fn/` answered by a space's runtime is passed on
62
+ as it is written — its head at once, its body as the code writes it, with the platform's `ctx` — over the functions
63
+ protocol's new `head`/`chunk` messages, with no time limit once it answered; the deployment's own routes stream too.
64
+ A runtime's `endpoints` are for addresses outside `/fn/` (an MCP server at `/mcp`); anything that can live under
65
+ `/fn/` is a route. A sandbox's routes are answered whole, as before.
66
+ - **`createJobControl({ queue, realtime: { pubsub, kv } })`** (`@plitzi/sdk-server/actions`): an operator's
67
+ `pause`/`resume`/`cancel`/`requeue` from a process that serves no pages — a Queue panel's API — each said on
68
+ `$job:<id>` through the page server's own pub/sub and retained store, so a watcher hears what an operator did.
69
+ - **A run's user carries no session** (`RunUser`): what a step, a function and a job see of who asked.
70
+ - **The builder shows the jobs** (`@plitzi/plitzi-builder`, `@plitzi/sdk-shared`): **Server → Functions** lists the
71
+ jobs the code declares as it is typed (how long each may run; one spread in or built by a call is counted, not
72
+ guessed), and the inspector of one says how it is started and who may watch it, with the space's runs of it — live
73
+ while one moves, progress and step as its code reported them — and **Pause**, **Resume**, **Cancel** and **Run
74
+ again**. Through two new builder operations, `SpaceJobs(kind, name, status, page, pageSize)` — a `SpaceJob` each:
75
+ what it runs, where it is and how far, never its input, state or result — and `SpaceControlJob(jobId, control)`
76
+ (`JobControlAction`). Beside them in `@plitzi/sdk-shared/actions`: `JOB_KINDS`/`isJobKind`, and `actionAccessOf`, the
77
+ one reading of a channel's access, which the functions' manifest now reads a job's `watch` with too.
78
+
79
+ - **`ctx.oauth.token` for an SDK in the page** (`@plitzi/sdk-server`, `@plitzi/sdk-shared`): Spotify's Web Playback,
80
+ Google's Picker and their kind ask the page for the access token themselves, and `ctx.oauth` kept every token on the
81
+ server. A connection that declares `exposeToken: true` now answers `ctx.oauth.token(name, { owner })` —
82
+ `{ token, type, expiresAt, scopes }`, renewed first when about to lapse — for a route of the code to hand to the
83
+ connection's owner. The refresh token never leaves; a connection without `exposeToken` refuses `token`, naming the
84
+ field. Through the sandbox's protocol and natively alike.
85
+
86
+ - **A page for some permissions, kept by the server** (`@plitzi/sdk-shared`, `@plitzi/sdk-server`,
87
+ `@plitzi/sdk-authoring`, `@plitzi/sdk-elements`, `@plitzi/plitzi-builder`): a page says
88
+ `access: { permissions: [...] }`, and a visitor without every one is answered 401 (or the page's sign-in redirect) or
89
+ 403 with a refusal drawn in the page's layout. Its content is withheld from everything that visitor is sent — the
90
+ render, the hydration payload, the space document (and a document built for somebody with access is not handed to
91
+ somebody without it by its name) and the page's server data. The builder's page settings take the permissions;
92
+ authoring refuses an `access` the server could not keep (`page-access`). A space read back as code — `plitzi create
93
+ --from`, the Export — keeps each page's `access`, so a protected page is never exported open. A page's handle carries
94
+ its `access` too, and a project's `visual/home.spec.ts` leaves such a page to a test that signs in, as it does a page
95
+ behind a session (`plitzi upgrade` rewrites an untouched one).
96
+ - **A project's first plugin is picked up while it runs** (`@plitzi/sdk-server`): `start:dev` registers a plugin folder
97
+ added under `src/plugins/` and reloads the open pages — but only watched that folder when it existed at boot, so a
98
+ project with no plugin yet (one taken out of a space that had none) showed nothing of its first `plitzi plugin add`
99
+ until a restart. With no folder, the server waits for it to appear and takes what it holds then.
100
+
101
+ ## Packaging
102
+ - **No package ships the declarations of its tests** (`@plitzi/sdk-server`, `@plitzi/sdk-mcp`, `@plitzi/plitzi-sdk`,
103
+ `@plitzi/plitzi-builder`, `@plitzi/sdk-elements`, `@plitzi/sdk-shared`): each app wrote its declarations with its own
104
+ `dts({ exclude })`, and the ones that left the tests out of it shipped a `.test.d.ts` beside their modules — 148 in
105
+ sdk-server alone — and the base config let a `.bench.d.ts` through. Every `dts()` now excludes
106
+ `'**/*.(test|bench).(ts|tsx)'`, and `yarn check:dist-exports` (CI, after `build:prod`) fails a build of any published
107
+ package that holds one.
108
+ - **`@plitzi/plitzi-builder` depends on `graphql` ^16** (was ^17): Apollo Server — the builder's API — supports only
109
+ 16, so a host installing the builder beside it got two copies. The builder uses nothing of 17's.
110
+
111
+ ## Elements
112
+ - **A dropdown closes when a link in it is chosen** (`@plitzi/sdk-elements`): a link stops its click from bubbling,
113
+ and the popup listened for clicks on the way up — so no menu of links ever closed, and a click that did reach it was
114
+ cancelled, which would have kept an external link from going anywhere. The popup now hears the click as it goes down
115
+ and lets it through.
116
+
117
+ ## CLI
118
+ - **A refused push says why** (`@plitzi/cli`): `space push functions` and the data push read any 409 as "changed since
119
+ your pull" — and the platform also answers 409 when the space has no private bucket to keep its code or data in, so
120
+ a first push to a space with no storage sent its author to pull, which changed nothing. The CLI now names a conflict
121
+ only when the refusal says `version`, and prints the platform's own words otherwise (where to add the bucket).
122
+ - **`create` points at the Academy** (`@plitzi/cli`): its last lines name the docs' Academy,
123
+ `https://docs.plitzi.com/academy`, for whoever is new to Plitzi — and the README the docs themselves.
124
+
125
+ ## Builder
126
+ - **A space served by Plitzi has a server, and the builder says so** (`@plitzi/plitzi-builder`, `@plitzi/sdk-shared`):
127
+ whether a space can run its actions and resolve its connectors was read off an SSR _credential_, which only a space
128
+ deployed to a page server of its own has — so every space served at `<space>.plitzi.app` showed "No server-rendered
129
+ deployment" over Server and counted its actions unavailable, while they ran. The deployments now carry what serves
130
+ them (`provider`), and a deployment served by SSR — Plitzi's or the space's — counts.
131
+ - **New Layout saves the layout** (`@plitzi/sdk-schema`): a layout is a root of the pages' tree, added with no anchor,
132
+ and `flatMapOf` found no tree for an empty anchor — so the server refused every new layout, saying it was "already
133
+ added". A root now goes into the pages' tree, and the refusal says which of the two it is.
134
+ - **Settings → Realtime: a space's channels, declared by hand** (`@plitzi/plitzi-builder`): `settings.channels` was
135
+ written only in code or by an agent over MCP, so a space made in the builder could not open a channel. The section
136
+ lists the channels with who may join (anyone, signed-in visitors, visitors with permissions), who may speak (pages, or
137
+ only the server's `Publish On Channel`), presence, a grant, keeping the last message and the two limits — saved only
138
+ when `channelProblems` passes, with what is wrong said under the channel otherwise.
139
+
140
+ - Updated dependencies [19fbc45]
141
+ - @plitzi/plitzi-sdk@0.38.21
142
+ - @plitzi/sdk-shared@0.38.21
143
+
3
144
  ## 0.38.20
4
145
 
5
146
  ### Patch Changes
package/README.md CHANGED
@@ -891,7 +891,7 @@ server.functions.setPlugin('board', board);
891
891
  `loadFunctionsSource(files)` loads one from its files rather than a folder: what a packed plugin carries as
892
892
  `functions.source.json`. The plugins a space uploaded reach a run through `action.lookups.getPluginFunctions`. The
893
893
  whole of it — `ctx`, routes, how a packed plugin carries it — is in
894
- [functions § a plugin's server half](../../docs/en/functions.md#10-a-plugins-server-half).
894
+ [functions § a plugin's server half](../../docs/en/functions.md#11-a-plugins-server-half).
895
895
 
896
896
  ## React Server Components (RSC)
897
897
 
@@ -1512,7 +1512,7 @@ SIGTERM until something kills the process.
1512
1512
  `@plitzi/sdk-server/mysql` has the same pair over a `mysql2` pool (`createMysqlJobQueue`, `createMysqlKv`). With no
1513
1513
  database at all, `kv` survives a restart in a file: `createFileKv` (`@plitzi/sdk-server/actions`, one process, JSON) or
1514
1514
  `createSqliteKv` (`@plitzi/sdk-server/sqlite`, any number of processes on the file). Anything
1515
- else is the `ActionJobQueue` contract written against your store — see
1515
+ else is the `JobQueue` contract written against your store — see
1516
1516
  [server actions § self-hosted](https://github.com/plitzi/plitzi-workspace/blob/main/docs/en/server-actions.md#13-for-a-self-hosted-deployment).
1517
1517
 
1518
1518
  ## Running it locally
package/dist/actions.d.ts CHANGED
@@ -25,6 +25,12 @@ export { createActionsModule, spaceKvPatterns } from './modules/actions';
25
25
  */
26
26
  export { createActionJobs, createJobWorker, createMemoryJobQueue, createScheduler } from './modules/actions/jobs';
27
27
  export { DEFAULT_MAX_ATTEMPTS, scheduleFor, scheduleJobId, schedulesFor } from './modules/actions/jobs';
28
+ /**
29
+ * An operator's hold on the jobs from a process that serves no pages — a Queue panel's API: pause, resume, cancel and
30
+ * requeue, each said on `$job:<id>` to whoever watches a job of the spaces' functions.
31
+ */
32
+ export { createJobControl } from './modules/functions/jobControl';
33
+ export type { JobControl, JobControlOptions } from './modules/functions/jobControl';
28
34
  /**
29
35
  * Cron, straight from `sdk-shared`, where the parser lives because the validator needs it too.
30
36
  *
package/dist/actions.js CHANGED
@@ -15,7 +15,8 @@ import { checkAction } from "./modules/actions/runtime/check.js";
15
15
  import { createRejectLogger, createRunLogger } from "./modules/actions/runtime/runLogger.js";
16
16
  import { describeCatalog, describeTask } from "./modules/actions/taskCatalog.js";
17
17
  import { createActionsModule } from "./modules/actions/index.js";
18
+ import { createJobControl } from "./modules/functions/jobControl.js";
18
19
  import { createFileKv } from "./modules/actions/runtime/fileKv.js";
19
20
  import { createRedisKv } from "./modules/actions/runtime/redisKv.js";
20
21
  import { cronFiresBetween, cronMatches, cronNextFire, parseCron } from "@plitzi/sdk-shared/actions";
21
- export { ActionRefusal, ActionRunError, DEFAULT_LIMITS, DEFAULT_MAX_ATTEMPTS, MAX_LIST_BYTES, MAX_LIST_ENTRIES, MIN_SIGNING_SECRET_LENGTH, checkAction, createActionJobs, createActionsModule, createFileKv, createJobWorker, createKvStore, createMemoryJobQueue, createMemoryKv, createRedisKv, createRejectLogger, createRunLogger, createScheduler, createTaskRegistry, cronFiresBetween, cronMatches, cronNextFire, describeCatalog, describeTask, parseCron, scheduleFor, scheduleJobId, schedulesFor, spaceKvPatterns, taskName };
22
+ export { ActionRefusal, ActionRunError, DEFAULT_LIMITS, DEFAULT_MAX_ATTEMPTS, MAX_LIST_BYTES, MAX_LIST_ENTRIES, MIN_SIGNING_SECRET_LENGTH, checkAction, createActionJobs, createActionsModule, createFileKv, createJobControl, createJobWorker, createKvStore, createMemoryJobQueue, createMemoryKv, createRedisKv, createRejectLogger, createRunLogger, createScheduler, createTaskRegistry, cronFiresBetween, cronMatches, cronNextFire, describeCatalog, describeTask, parseCron, scheduleFor, scheduleJobId, schedulesFor, spaceKvPatterns, taskName };
@@ -69,7 +69,7 @@ export interface AuthConfig {
69
69
  */
70
70
  export declare const createAuth: (config: AuthConfig) => {
71
71
  tokens: {
72
- lifetimes: Record<"refresh" | "access" | "session" | "widget" | "agent" | "mfaChallenge", number>;
72
+ lifetimes: Record<"session" | "refresh" | "access" | "widget" | "agent" | "mfaChallenge", number>;
73
73
  issuer: string;
74
74
  generateUserToken: (userId: number | string, { actingAs, ttlSeconds }?: import('./tokens').UserTokenOptions) => string;
75
75
  generateRefreshToken: (userId: number | string) => string;
@@ -174,7 +174,7 @@ export interface SpaceTokenOptions {
174
174
  * server issues under their own and nothing they mint is worth anything here, or the other way round.
175
175
  */
176
176
  export declare const createTokens: (config: TokenConfig) => {
177
- lifetimes: Record<"refresh" | "access" | "session" | "widget" | "agent" | "mfaChallenge", number>;
177
+ lifetimes: Record<"session" | "refresh" | "access" | "widget" | "agent" | "mfaChallenge", number>;
178
178
  /** What this deployment mints under. Read by anything that has to name the deployment — an enrolment URI, say. */
179
179
  issuer: string;
180
180
  generateUserToken: (userId: number | string, { actingAs, ttlSeconds }?: UserTokenOptions) => string;
@@ -112,7 +112,15 @@ var isFunction = (value) => typeof value === "function";
112
112
  /** A driver as `createDbDrivers` builds one: the engine a credential names, and how to query it. */
113
113
  var isDbDriver = (value) => isRecord(value) && typeof value.engine === "string" && isFunction(value.query);
114
114
  /** The functions config as `@plitzi/sdk-server/functions` builds it: native and plugin definitions, a runner, ceilings. */
115
- var isFunctionsConfig = (value) => isRecord(value) && (value.native === void 0 || Array.isArray(value.native) && value.native.every(isRecord)) && (value.plugins === void 0 || isRecord(value.plugins) && Object.values(value.plugins).every(isRecord)) && (value.runner === void 0 || isRecord(value.runner) && isFunction(value.runner.describe) && isFunction(value.runner.invoke)) && (value.limits === void 0 || isRecord(value.limits));
115
+ var isFunctionsConfig = (value) => isRecord(value) && (value.native === void 0 || Array.isArray(value.native) && value.native.every(isRecord)) && (value.plugins === void 0 || isRecord(value.plugins) && Object.values(value.plugins).every(isRecord)) && (value.runner === void 0 || isRecord(value.runner) && isFunction(value.runner.describe) && isFunction(value.runner.invoke)) && (value.limits === void 0 || isRecord(value.limits)) && (value.jobs === void 0 || isRecord(value.jobs) && (value.jobs.limitsFor === void 0 || isFunction(value.jobs.limitsFor))) && (value.oauth === void 0 || isRecord(value.oauth) && (value.oauth.callbackOrigin === void 0 || typeof value.oauth.callbackOrigin === "string"));
116
+ /** Whether a value is an origin as a browser writes it — `https://example.com`, no path or trailing slash. */
117
+ var isOrigin = (value) => {
118
+ try {
119
+ return new URL(value).origin === value;
120
+ } catch {
121
+ return false;
122
+ }
123
+ };
116
124
  /** The deployment's database drivers, each held to what a `db` task calls — or why one is not, as the server starts. */
117
125
  var dbDriversOf = (drivers) => {
118
126
  if (drivers === void 0) return;
@@ -123,7 +131,9 @@ var dbDriversOf = (drivers) => {
123
131
  /** The deployment's functions config, held to what runs a space's code — or why it is not, as the server starts. */
124
132
  var functionsConfigOf = (config) => {
125
133
  if (config === void 0) return;
126
- if (!isFunctionsConfig(config)) throw new Error("`functions` is not what @plitzi/sdk-server/functions configures: `native` definitions, `plugins` by type, a `runner` with `describe` and `invoke`, `limits`.");
134
+ if (!isFunctionsConfig(config)) throw new Error("`functions` is not what @plitzi/sdk-server/functions configures: `native` definitions, `plugins` by type, a `runner` with `describe` and `invoke`, `limits`, `jobs` with a `limitsFor` function, `oauth` with a `callbackOrigin`.");
135
+ const callbackOrigin = config.oauth?.callbackOrigin;
136
+ if (callbackOrigin !== void 0 && !isOrigin(callbackOrigin)) throw new Error(`\`functions.oauth.callbackOrigin\` is an origin, as a browser writes it — \`https://example.com\`, no path or slash — not "${callbackOrigin}"`);
127
137
  return config;
128
138
  };
129
139
  //#endregion
@@ -1,4 +1,5 @@
1
1
  import { clientIp, readRawBytes, requestOrigin } from "../requestParser.js";
2
+ import { writeWebResponse } from "../http/webExchange.js";
2
3
  import { FUNCTION_ROUTES_PREFIX } from "@plitzi/sdk-shared/actions";
3
4
  //#region src/core/services/functionRoutes.ts
4
5
  /**
@@ -31,16 +32,20 @@ var functionRoutesStage = async (ctx) => {
31
32
  if (!name.startsWith(":") && value !== void 0) headers.set(name, Array.isArray(value) ? value.join(", ") : value);
32
33
  });
33
34
  const hasBody = req.method !== "GET" && req.method !== "HEAD";
34
- const response = await route.handle(new Request(`${requestOrigin(req) || `${req.protocol}://${req.hostname}`}${req.url}`, {
35
+ const { response, streamed } = await route.handle(new Request(`${requestOrigin(req) || `${req.protocol}://${req.hostname}`}${req.url}`, {
35
36
  method: req.method,
36
37
  headers,
37
38
  ...hasBody ? { body: new Uint8Array(await readRawBytes(ctx.raw)) } : {}
38
39
  }));
40
+ if (!response.headers.has("cache-control")) response.headers.set("Cache-Control", "no-store");
41
+ if (streamed) {
42
+ await writeWebResponse(ctx.rawRes, response, ctx.signal);
43
+ return true;
44
+ }
39
45
  ctx.res.setStatus(response.status);
40
46
  response.headers.forEach((value, name) => {
41
47
  ctx.res.setHeader(name, value);
42
48
  });
43
- if (!response.headers.has("cache-control")) ctx.res.setHeader("Cache-Control", "no-store");
44
49
  ctx.res.send(Buffer.from(await response.arrayBuffer()));
45
50
  return true;
46
51
  };
@@ -11,6 +11,7 @@ import { handleRealtimeSocket } from "../../modules/realtime/socket.js";
11
11
  var realtimeStage = async (ctx) => {
12
12
  const { realtime, req } = ctx;
13
13
  if (!realtime || req.path !== realtime.path) return false;
14
+ const jobs = realtime.jobs();
14
15
  if (ctx.upgrade) {
15
16
  ctx.operation = "realtime:socket";
16
17
  await handleRealtimeSocket({
@@ -21,7 +22,8 @@ var realtimeStage = async (ctx) => {
21
22
  hub: realtime.hub,
22
23
  resolveChannels: realtime.resolveChannels,
23
24
  grants: realtime.grants,
24
- allowedOrigins: realtime.allowedOrigins
25
+ allowedOrigins: realtime.allowedOrigins,
26
+ ...jobs ? { jobs } : {}
25
27
  });
26
28
  return true;
27
29
  }
@@ -34,7 +36,8 @@ var realtimeStage = async (ctx) => {
34
36
  signal: ctx.signal,
35
37
  hub: realtime.hub,
36
38
  resolveChannels: realtime.resolveChannels,
37
- grants: realtime.grants
39
+ grants: realtime.grants,
40
+ ...jobs ? { jobs } : {}
38
41
  });
39
42
  return true;
40
43
  }
@@ -1,3 +1,28 @@
1
+ /**
2
+ * Who may start a run through ONE way in. Resolved against the auth kernel — never re-implemented here.
3
+ *
4
+ * It belongs to the trigger and not to the action, because the two are different questions: a webhook is reachable
5
+ * by anyone who learns its URL and is gated on its signature, while the same flow called from a page may well
6
+ * require a session. Stating it once for the action forced the loosest of its ways in onto all of them.
7
+ *
8
+ * There is no implicit default: a trigger that declares no access is refused at save time rather than falling back
9
+ * to something a reader has to guess at.
10
+ */
11
+ declare type ActionAccess =
12
+ /** Anyone, including an anonymous visitor. Implicit for a webhook; anywhere else it is a deliberate choice. */
13
+ {
14
+ mode: 'public';
15
+ }
16
+ /** Any request carrying a valid session for this space. */
17
+ | {
18
+ mode: 'session';
19
+ }
20
+ /** A session holding every one of these space permissions. */
21
+ | {
22
+ mode: 'role';
23
+ permissions: string[];
24
+ };
25
+
1
26
  /**
2
27
  * The `kv` tasks' own view: values rather than strings, and a TTL that means what a caller expects.
3
28
  *
@@ -40,9 +65,15 @@ declare type ActionKvStore = {
40
65
  * URL, a credential's name, and a page is shown to anybody. This one says, by its type, that its message was written
41
66
  * to be read. A run that ends on it answers `status: 'failed'` with the message as `error`, which a page's flow reads
42
67
  * as `{{ step.error }}` — the same place a refusal before the run began puts its own.
68
+ *
69
+ * `code` names the refusal for code that catches it (`oauth-not-connected`): what to tell apart by, never the message,
70
+ * which is written for a person and may change.
43
71
  */
44
72
  export declare class ActionRefusal extends Error {
45
- constructor(message: string);
73
+ code?: string;
74
+ constructor(message: string, options?: {
75
+ code?: string;
76
+ });
46
77
  }
47
78
 
48
79
  /**
@@ -112,6 +143,8 @@ export declare type FunctionContext = {
112
143
  log: (...values: unknown[]) => void;
113
144
  /** OAuth 2.0 through the space's declared connections — see {@link FunctionOAuth}. */
114
145
  oauth: FunctionOAuth;
146
+ /** The space's jobs — see {@link FunctionJobs}. */
147
+ jobs: FunctionJobs;
115
148
  /** Progress for a caller that asked for a stream — a no-op when nobody did. */
116
149
  emit: (chunk: unknown) => void;
117
150
  /** Aborted when the run is: cancelled, or out of time. Hand it to what can stop early. */
@@ -131,6 +164,100 @@ export declare type FunctionFetchInit = {
131
164
  headers?: Record<string, string>;
132
165
  body?: string;
133
166
  credential?: string;
167
+ /** Cuts the request short when it aborts (`AbortSignal.timeout(12_000)`); the run's own end cuts it regardless. */
168
+ signal?: AbortSignal;
169
+ };
170
+
171
+ /** A job of the space's: work longer than a request, run on the server slice by slice until it answers. */
172
+ export declare type FunctionJob<I extends Record<string, unknown> = Record<string, unknown>, S = unknown, R = unknown> = {
173
+ /**
174
+ * Who may watch it (`$job:<id>`, `useJob`) besides whoever started it — a channel's access, read against the visitor's
175
+ * permissions in the space. Absent, only whoever started it.
176
+ */
177
+ watch?: ActionAccess;
178
+ /** How long it may run, every slice together, in seconds — within what the server allows. */
179
+ maxSeconds?: number;
180
+ /**
181
+ * The work. What it answers is the job's result; an `ActionRefusal` fails it without a retry. A method, not a property:
182
+ * so a job typed with an input and a state of its own is still one of `FunctionsDefinition['jobs']`, and one written
183
+ * in place there gets an object for its input and `unknown` for its state.
184
+ */
185
+ run(input: I, job: FunctionJobHandle<S>, ctx: FunctionContext): R | Promise<R>;
186
+ };
187
+
188
+ /**
189
+ * What a job's `run` is handed besides its input: the job, and how it keeps where it is. A job runs in slices — a pause,
190
+ * a lost server or its time in one go ending one — and every slice but the first starts from what the one before saved.
191
+ */
192
+ export declare type FunctionJobHandle<S = unknown> = {
193
+ id: string;
194
+ name: string;
195
+ /** What it last saved — `undefined` on its first slice, and whenever it never saved. */
196
+ state: S | undefined;
197
+ /** Which attempt this is, from 1: a slice after a failure is the next attempt, from the last save. */
198
+ attempt: number;
199
+ /**
200
+ * Keeps `state` durably: the next slice starts with it. JSON, within what the server keeps for one job. A method, not
201
+ * a property: so a job whose state has a type of its own is still one of `FunctionsDefinition['jobs']`.
202
+ */
203
+ save(state: S): Promise<void>;
204
+ /** How far it is, from 0 to 1, and what it is doing — for whoever watches it. Never fails the job. */
205
+ report: (fraction: number, step?: string) => void;
206
+ /** Why this slice is asked to end, once it is (`signal` aborted): save, and return. */
207
+ readonly stopping: FunctionJobStop | undefined;
208
+ /** Aborted when the slice is asked to end — the same as `ctx.signal`. Some seconds later it is cut. */
209
+ signal: AbortSignal;
210
+ };
211
+
212
+ /**
213
+ * The space's jobs, from its code: what starts one, reads it and stops it. Who may is the code's to decide — these are
214
+ * called from its routes and tasks, behind its own checks.
215
+ */
216
+ export declare type FunctionJobs = {
217
+ /**
218
+ * Starts one of the jobs this code declares (`jobs` in `defineFunctions`), with `input`: answered at once, the job
219
+ * `pending`. With `key`, at most one of that key runs at a time — starting it again while one is under way answers that
220
+ * one (a button pressed twice), and once it ended starts it over with the new input.
221
+ */
222
+ start: (name: string, input?: Record<string, unknown>, options?: {
223
+ key?: string;
224
+ }) => Promise<FunctionJobView>;
225
+ /** One of the space's jobs, as whoever may watch it sees it — or nothing, when there is none by that id. */
226
+ get: (id: string) => Promise<FunctionJobView | undefined>;
227
+ /** Sets it aside: it stops once its code saved, and waits as `paused`. Answers whether anything changed. */
228
+ pause: (id: string) => Promise<boolean>;
229
+ /** Puts a paused job back in the queue, to go on from what it saved. */
230
+ resume: (id: string) => Promise<boolean>;
231
+ /** Stops it for good: dropped if it waits, aborted if it runs. */
232
+ cancel: (id: string) => Promise<boolean>;
233
+ };
234
+
235
+ /**
236
+ * Why a slice of a job is asked to end (`job.stopping`): it was set aside (`pause`) or cancelled (`cancel`), its time in
237
+ * one go is up (`limit`) or the server is going away (`shutdown`). Whichever, what was saved is where it goes on from.
238
+ */
239
+ export declare type FunctionJobStop = 'pause' | 'cancel' | 'limit' | 'shutdown';
240
+
241
+ /**
242
+ * A job as whoever may watch it sees it: what `ctx.jobs.get` answers, what `$job:<id>` says each time it moves, and
243
+ * what `useJob` holds. Never its input or what it saved: those are its code's.
244
+ */
245
+ declare type FunctionJobView = {
246
+ id: string;
247
+ /** The job's name, as the functions declare it. */
248
+ name: string;
249
+ status: JobStatus;
250
+ /** From 0 to 1, as its code last reported. */
251
+ progress?: number;
252
+ /** What it is doing, in its code's words. */
253
+ step?: string;
254
+ /** What it answered, once it succeeded. */
255
+ result?: unknown;
256
+ /** Why it failed — for a refusal, its code's own words; for anything else, that it failed. */
257
+ error?: string;
258
+ /** Epoch ms. */
259
+ createdAt: number;
260
+ updatedAt: number;
134
261
  };
135
262
 
136
263
  /**
@@ -142,21 +269,31 @@ export declare type FunctionOAuth = {
142
269
  /**
143
270
  * Where to send the visitor to consent (authorization code, PKCE). They come back to `/fn/oauth/callback` — the
144
271
  * address to register with the provider, on the space's host — and from there to `returnTo`, a path of the space,
145
- * with `?oauth=<connection>&oauth_result=connected` or `&oauth_error=<what>`.
272
+ * with `?oauth=<connection>&oauth_result=connected` or `&oauth_error=<what>`. `authorizeParams` adds to the
273
+ * connection's for this consent alone — `{ prompt: 'select_account' }` to choose another account — never one the
274
+ * platform writes (`state`, `redirect_uri`, `scope`, PKCE's).
146
275
  */
147
276
  connect: (connection: string, options: {
148
277
  returnTo: string;
278
+ authorizeParams?: Record<string, string>;
149
279
  } & FunctionOAuthOwner) => Promise<{
150
280
  url: string;
151
281
  }>;
152
282
  status: (connection: string, options?: FunctionOAuthOwner) => Promise<FunctionOAuthStatus>;
153
283
  /**
154
284
  * A request to the provider's API with the token written in (`Authorization: Bearer`), renewed when it is about to
155
- * lapse and once more if the answer is 401. Only to the hosts the space declared (`allow.hosts`).
285
+ * lapse and once more if the answer is 401. Only to the hosts the space declared (`allow.hosts`). With nobody
286
+ * connected it refuses, `code: 'oauth-not-connected'` ({@link FunctionOAuthRefusal}).
156
287
  */
157
288
  fetch: (connection: string, url: string | URL, init?: Omit<FunctionFetchInit, 'credential'> & FunctionOAuthOwner) => Promise<Response>;
158
289
  /** Forgets the connection — revoked at the provider when it says where — and answers whether there was one. */
159
290
  disconnect: (connection: string, options?: FunctionOAuthOwner) => Promise<boolean>;
291
+ /**
292
+ * The access token itself, renewed first when it is about to lapse — only of a connection that declares
293
+ * `exposeToken: true`, for a provider's SDK in the page that asks for it (`getOAuthToken`). Whoever the code hands it
294
+ * to holds it until it lapses: answer it only to whom the connection is (its owner), from a route that checks so.
295
+ */
296
+ token: (connection: string, options?: FunctionOAuthOwner) => Promise<FunctionOAuthToken>;
160
297
  };
161
298
 
162
299
  /** What a space's functions declare, read from the bundle when it is saved: its tasks, routes and reachable hosts. */
@@ -182,6 +319,12 @@ declare type FunctionOAuthConnection = {
182
319
  authorizeParams?: Record<string, string>;
183
320
  /** How the app proves who it is to `tokenUrl`: in the body (the default) or as HTTP Basic. */
184
321
  clientAuth?: 'body' | 'basic';
322
+ /**
323
+ * The code may read the access token (`ctx.oauth.token`), for a provider's SDK that runs in the page and asks for it
324
+ * itself — Spotify's Web Playback, Google's Picker. Off by default: the token then leaves the server, as far as the
325
+ * code hands it. The refresh token never does.
326
+ */
327
+ exposeToken?: boolean;
185
328
  };
186
329
 
187
330
  /**
@@ -192,6 +335,12 @@ export declare type FunctionOAuthOwner = {
192
335
  owner?: string;
193
336
  };
194
337
 
338
+ /**
339
+ * The `code` of a refusal `ctx.oauth` throws (an `ActionRefusal`), to tell it apart by: `oauth-not-connected` — no
340
+ * account connected for that owner yet, so `connect` first; `oauth-no-owner` — nobody signed in and no `owner` named.
341
+ */
342
+ export declare type FunctionOAuthRefusal = 'oauth-not-connected' | 'oauth-no-owner';
343
+
195
344
  /** What `ctx.oauth.status` says of a connection — never its token. */
196
345
  export declare type FunctionOAuthStatus = {
197
346
  connected: boolean;
@@ -199,6 +348,14 @@ export declare type FunctionOAuthStatus = {
199
348
  expiresAt?: number;
200
349
  };
201
350
 
351
+ /** The access token `ctx.oauth.token` hands out — never the refresh token, which stays with the platform. */
352
+ export declare type FunctionOAuthToken = {
353
+ token: string;
354
+ type: string;
355
+ expiresAt?: number;
356
+ scopes?: string[];
357
+ };
358
+
202
359
  /**
203
360
  * An HTTP endpoint of the space, under `/fn/`: a web-standard handler, the shape every edge runtime runs. The request
204
361
  * carries no credentials — `ctx.user` says who is asking — and the response sets no cookies: the host's are the
@@ -227,6 +384,8 @@ export declare type FunctionsDefinition = {
227
384
  * (OpenID) or its endpoints, the credential with the app's id and secret, the scopes.
228
385
  */
229
386
  oauth?: Record<string, FunctionOAuthConnection>;
387
+ /** Its jobs, by name (`ctx.jobs.start(name, input)`): work that outlives a request, run slice by slice. */
388
+ jobs?: Record<string, FunctionJob>;
230
389
  };
231
390
 
232
391
  /**
@@ -352,6 +511,20 @@ declare type InteractionCallbackParamValues<T extends Record<string, unknown> =
352
511
 
353
512
  declare type InteractionParamType = 'boolean' | 'select' | 'text' | 'number' | 'textarea' | 'codemirror-text' | 'codemirror-json' | 'elements';
354
513
 
514
+ /**
515
+ * The durable queue the server's work waits in: a schedule's fires, the runs set for later, and the jobs of the spaces'
516
+ * functions — one queue, one contract (`JobQueue`), whatever store a deployment keeps it in.
517
+ */
518
+ /**
519
+ * Where a job is, as the only durable answer to "did it happen".
520
+ *
521
+ * `pending` is waiting to be taken, `running` is held by a worker under a lease, `paused` is a job of a space's functions
522
+ * set aside with what it saved, until it is resumed — and the other four are terminal, except that an operator may put
523
+ * a `failed`, `dead` or `cancelled` one back to `pending`. `dead` is a job that used up every attempt it was given: it
524
+ * stays, visibly, because the alternative is work that quietly evaporated.
525
+ */
526
+ declare type JobStatus = 'pending' | 'running' | 'paused' | 'succeeded' | 'failed' | 'dead' | 'cancelled';
527
+
355
528
  /**
356
529
  * The lifetime a change writes with: a number of seconds, one worked out from the value written, or none.
357
530
  */
@@ -4,8 +4,10 @@
4
4
  * the contract alone, and nothing that runs it.
5
5
  */
6
6
  export { ActionRefusal, defineFunctions } from './modules/functions/contract';
7
- export type { FunctionContext, FunctionFetch, FunctionFetchInit, FunctionOAuth, FunctionOAuthOwner, FunctionOAuthStatus, FunctionRoute, FunctionRouteContext, FunctionsDefinition, FunctionTask, FunctionUser } from './modules/functions/contract';
7
+ export type { FunctionContext, FunctionFetch, FunctionFetchInit, FunctionJob, FunctionJobHandle, FunctionJobs, FunctionJobStop, FunctionOAuth, FunctionOAuthOwner, FunctionOAuthStatus, FunctionOAuthToken, FunctionRoute, FunctionRouteContext, FunctionsDefinition, FunctionTask, FunctionUser } from './modules/functions/contract';
8
8
  export type { FunctionsConfig, FunctionUsageRecord } from './modules/functions/config';
9
+ export type { FunctionJobLimits } from './modules/functions/jobs';
10
+ export { DEFAULT_FUNCTION_JOB_LIMITS } from './modules/functions/jobs';
9
11
  export { DEFAULT_FUNCTION_CEILINGS, DEFAULT_FUNCTION_LIMITS } from './modules/functions/config';
10
12
  /**
11
13
  * What the platform keeps of a space's functions, and what it hands a runner: the built bundle and what it declared
package/dist/functions.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { ActionRefusal } from "./modules/actions/runtime/errors.js";
2
2
  import { DEFAULT_FUNCTION_CEILINGS, DEFAULT_FUNCTION_LIMITS } from "./modules/functions/config.js";
3
+ import { DEFAULT_FUNCTION_JOB_LIMITS } from "./modules/functions/jobs.js";
3
4
  import { defineFunctions } from "./modules/functions/contract.js";
4
5
  import { TRY_STEP, functionTryEntry } from "./modules/functions/tryEntry.js";
5
- export { ActionRefusal, DEFAULT_FUNCTION_CEILINGS, DEFAULT_FUNCTION_LIMITS, TRY_STEP, defineFunctions, functionTryEntry };
6
+ export { ActionRefusal, DEFAULT_FUNCTION_CEILINGS, DEFAULT_FUNCTION_JOB_LIMITS, DEFAULT_FUNCTION_LIMITS, TRY_STEP, defineFunctions, functionTryEntry };
@@ -2,7 +2,7 @@ import { LogLevel, ServerLogEvent, ServerLogger } from '@plitzi/sdk-shared';
2
2
  /** One line for any {@link ServerLogEvent}: an HTTP request reads as an access-log line
3
3
  * (`[SSR] 203.0.113.7 GET /pricing 200 12ms ok`), the MCP events as what happened inside one
4
4
  * (`[MCP] tools/call plitzi_apply {operations:[3]} 41ms ok`), a server action as what its flow did
5
- * (`[Action] shipping-quote via call space=1 completed 12ms ok`) and a refused one as what turned it away
5
+ * (`[Action] send-invoice via call space=1 completed 12ms ok`) and a refused one as what turned it away
6
6
  * (`[Action] checkout via webhook space=1 REFUSED invalid_signature`). Rendering is a pure format — the dispatcher
7
7
  * already stripped query values, collected no headers, cookies or tokens, summarised tool args by shape and
8
8
  * reduced a run to its steps; the client IP it does carry is personal data, so a sink that persists these lines
@@ -27,7 +27,7 @@ var renderMessage = (event) => `[${event.scope}] ${event.message}${event.error ?
27
27
  /** One line for any {@link ServerLogEvent}: an HTTP request reads as an access-log line
28
28
  * (`[SSR] 203.0.113.7 GET /pricing 200 12ms ok`), the MCP events as what happened inside one
29
29
  * (`[MCP] tools/call plitzi_apply {operations:[3]} 41ms ok`), a server action as what its flow did
30
- * (`[Action] shipping-quote via call space=1 completed 12ms ok`) and a refused one as what turned it away
30
+ * (`[Action] send-invoice via call space=1 completed 12ms ok`) and a refused one as what turned it away
31
31
  * (`[Action] checkout via webhook space=1 REFUSED invalid_signature`). Rendering is a pure format — the dispatcher
32
32
  * already stripped query values, collected no headers, cookies or tokens, summarised tool args by shape and
33
33
  * reduced a run to its steps; the client IP it does carry is personal data, so a sink that persists these lines