@plitzi/sdk-server 0.38.19 → 0.38.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +178 -0
- package/README.md +2 -2
- package/dist/actions.d.ts +6 -0
- package/dist/actions.js +2 -1
- package/dist/core/auth/createAuth.d.ts +1 -1
- package/dist/core/auth/csrf.js +13 -8
- package/dist/core/auth/tokens.d.ts +1 -1
- package/dist/core/configSeam.js +2 -2
- package/dist/core/services/functionRoutes.js +8 -2
- package/dist/core/services/realtime.js +5 -2
- package/dist/functions-api.d.ts +228 -0
- package/dist/functions.d.ts +4 -2
- package/dist/functions.js +2 -1
- package/dist/helpers/serverLog.d.ts +1 -1
- package/dist/helpers/serverLog.js +1 -1
- package/dist/hosts/project/plugins.js +20 -3
- package/dist/modules/actions/index.js +16 -3
- package/dist/modules/actions/jobs/index.d.ts +4 -3
- package/dist/modules/actions/jobs/index.js +2 -1
- package/dist/modules/actions/jobs/later.d.ts +2 -2
- package/dist/modules/actions/jobs/later.js +5 -2
- package/dist/modules/actions/jobs/memoryQueue.d.ts +4 -4
- package/dist/modules/actions/jobs/memoryQueue.js +69 -25
- package/dist/modules/actions/jobs/scheduler.d.ts +2 -2
- package/dist/modules/actions/jobs/scheduler.js +5 -2
- package/dist/modules/actions/jobs/worker.d.ts +6 -3
- package/dist/modules/actions/jobs/worker.js +104 -10
- package/dist/modules/actions/runtime/runAction.d.ts +5 -2
- package/dist/modules/actions/runtime/runAction.js +5 -3
- package/dist/modules/actions/runtime/signing.d.ts +7 -0
- package/dist/modules/actions/runtime/signing.js +23 -1
- package/dist/modules/actions/runtime/taskContext.d.ts +12 -3
- package/dist/modules/actions/runtime/taskContext.js +8 -1
- package/dist/modules/actions/transport/callHandler.js +3 -0
- package/dist/modules/actions/types.d.ts +29 -4
- package/dist/modules/functions/capabilities.js +107 -0
- package/dist/modules/functions/config.d.ts +9 -0
- package/dist/modules/functions/context.d.ts +2 -1
- package/dist/modules/functions/context.js +21 -3
- package/dist/modules/functions/contract.d.ts +129 -1
- package/dist/modules/functions/driver.js +128 -2
- package/dist/modules/functions/jobControl.d.ts +21 -0
- package/dist/modules/functions/jobControl.js +43 -0
- package/dist/modules/functions/jobs.d.ts +98 -0
- package/dist/modules/functions/jobs.js +438 -0
- package/dist/modules/functions/manifest.js +117 -2
- package/dist/modules/functions/native.js +2 -1
- package/dist/modules/functions/oauth.d.ts +31 -0
- package/dist/modules/functions/oauth.js +326 -0
- package/dist/modules/functions/protocol.d.ts +88 -3
- package/dist/modules/functions/protocol.js +2 -1
- package/dist/modules/functions/routes.d.ts +11 -1
- package/dist/modules/functions/routes.js +71 -30
- package/dist/modules/functions/runner/messages.d.ts +0 -1
- package/dist/modules/functions/runner/messages.js +40 -2
- package/dist/modules/functions/runner/remote.js +58 -3
- package/dist/modules/functions/runner/service.js +53 -7
- package/dist/modules/functions/sandbox/isolate.js +5 -3
- package/dist/modules/functions/space.js +4 -4
- package/dist/modules/mongo/jobQueue.d.ts +3 -3
- package/dist/modules/mongo/jobQueue.js +137 -26
- package/dist/modules/mysql/jobs/jobQueue.d.ts +3 -3
- package/dist/modules/mysql/jobs/jobQueue.js +97 -33
- package/dist/modules/mysql/jobs/schema.js +38 -11
- package/dist/modules/realtime/handlers.d.ts +5 -2
- package/dist/modules/realtime/handlers.js +15 -4
- package/dist/modules/realtime/index.d.ts +11 -1
- package/dist/modules/realtime/index.js +8 -1
- package/dist/modules/realtime/jobs.d.ts +20 -0
- package/dist/modules/realtime/jobs.js +41 -0
- package/dist/modules/realtime/retained.d.ts +3 -2
- package/dist/modules/realtime/retained.js +2 -2
- package/dist/modules/realtime/socket.d.ts +4 -1
- package/dist/modules/realtime/socket.js +2 -2
- package/dist/modules/rsc/resolveRscData.js +2 -1
- package/dist/modules/runtime/host.js +1 -1
- package/dist/modules/runtime/runner.d.ts +1 -1
- package/dist/modules/runtime/runner.js +12 -2
- package/dist/modules/runtime/stages.js +1 -1
- package/dist/modules/ssr/applySSRResult.d.ts +5 -0
- package/dist/modules/ssr/applySSRResult.js +8 -1
- package/dist/modules/ssr/buildBody.js +2 -1
- package/dist/modules/ssr/prepareRender.d.ts +3 -0
- package/dist/modules/ssr/prepareRender.js +17 -5
- package/dist/modules/ssr/spaceDocument.d.ts +2 -1
- package/dist/modules/ssr/spaceDocument.js +14 -5
- package/dist/modules/ssr/streamBody.js +2 -1
- package/package.json +6 -3
- package/skills/plitzi-authoring/reference/auth.md +6 -0
- package/skills/plitzi-authoring/reference/authoring-errors.md +1 -0
- package/skills/plitzi-authoring/reference/plugin-reach.md +3 -0
- package/skills/plitzi-authoring/reference/realtime.md +4 -0
- package/dist/adapters/cloudAdapters.test.d.ts +0 -1
- package/dist/adapters/jsonAdapters.test.d.ts +0 -1
- package/dist/adapters/space/space.test.d.ts +0 -1
- package/dist/core/auth/api.test.d.ts +0 -1
- package/dist/core/auth/authorize.test.d.ts +0 -1
- package/dist/core/auth/createAuth.test.d.ts +0 -1
- package/dist/core/auth/csrf.test.d.ts +0 -1
- package/dist/core/auth/domains.test.d.ts +0 -1
- package/dist/core/auth/identity.test.d.ts +0 -1
- package/dist/core/auth/lifecycle.test.d.ts +0 -1
- package/dist/core/auth/oauth/oauth.test.d.ts +0 -1
- package/dist/core/auth/redirects.test.d.ts +0 -1
- package/dist/core/auth/routes.test.d.ts +0 -1
- package/dist/core/auth/session.test.d.ts +0 -1
- package/dist/core/auth/spaceTokens.test.d.ts +0 -1
- package/dist/core/auth/throttle.test.d.ts +0 -1
- package/dist/core/auth/tokens.test.d.ts +0 -1
- package/dist/core/auth/totp.test.d.ts +0 -1
- package/dist/core/configSeam.test.d.ts +0 -1
- package/dist/core/createServer.actions.test.d.ts +0 -1
- package/dist/core/createServer.functions.test.d.ts +0 -1
- package/dist/core/createServer.livePages.test.d.ts +0 -1
- package/dist/core/createServer.notFound.test.d.ts +0 -1
- package/dist/core/createServer.publicData.test.d.ts +0 -1
- package/dist/core/createServer.test.d.ts +0 -1
- package/dist/core/fontStore.test.d.ts +0 -1
- package/dist/core/freePort.test.d.ts +0 -1
- package/dist/core/handlers/csrfMiddleware.test.d.ts +0 -1
- package/dist/core/handlers/handlers.test.d.ts +0 -1
- package/dist/core/handlers/socialRouteHandlers.test.d.ts +0 -1
- package/dist/core/http/dispatcher.test.d.ts +0 -1
- package/dist/core/http/stages/crossSiteWrites.test.d.ts +0 -1
- package/dist/core/http/stages/exchangeRoute.test.d.ts +0 -1
- package/dist/core/http/stages/images.test.d.ts +0 -1
- package/dist/core/http/stages/middlewares.test.d.ts +0 -1
- package/dist/core/http/stages/sessionRenewal.test.d.ts +0 -1
- package/dist/core/http/stages/signInRoute.test.d.ts +0 -1
- package/dist/core/oauth/authorize.test.d.ts +0 -1
- package/dist/core/oauth/register.test.d.ts +0 -1
- package/dist/core/oauth/token.test.d.ts +0 -1
- package/dist/core/requestParser.test.d.ts +0 -1
- package/dist/core/server/baseServer.test.d.ts +0 -1
- package/dist/core/server/closeOnSignals.test.d.ts +0 -1
- package/dist/core/server/drain.test.d.ts +0 -1
- package/dist/core/server/fleet/channel.test.d.ts +0 -1
- package/dist/core/server/fleet/fixtures/fleetServer.d.ts +0 -1
- package/dist/core/server/fleet/fleet.integration.test.d.ts +0 -1
- package/dist/core/server/fleet/relay.test.d.ts +0 -1
- package/dist/core/server/fleet/role.test.d.ts +0 -1
- package/dist/core/server/fleet/supervisor.test.d.ts +0 -1
- package/dist/core/services/resolve.test.d.ts +0 -1
- package/dist/core/staticFiles.test.d.ts +0 -1
- package/dist/env.test.d.ts +0 -1
- package/dist/helpers/atomicFile.test.d.ts +0 -1
- package/dist/helpers/buildResponseHelpers.test.d.ts +0 -1
- package/dist/helpers/buildServerInfo.test.d.ts +0 -1
- package/dist/helpers/cache/CompressedFileCache.test.d.ts +0 -1
- package/dist/helpers/cache/cacheManager.test.d.ts +0 -1
- package/dist/helpers/cache/keys.test.d.ts +0 -1
- package/dist/helpers/compress.test.d.ts +0 -1
- package/dist/helpers/hydrationPayload.test.d.ts +0 -1
- package/dist/helpers/offlineDataLoader.test.d.ts +0 -1
- package/dist/helpers/onAbort.test.d.ts +0 -1
- package/dist/helpers/outboundGuard.test.d.ts +0 -1
- package/dist/helpers/reportReactBuild.test.d.ts +0 -1
- package/dist/helpers/resolveDebugMode.test.d.ts +0 -1
- package/dist/helpers/serverLog.test.d.ts +0 -1
- package/dist/hosts/authoringHost/index.test.d.ts +0 -1
- package/dist/hosts/project/serveProject.test.d.ts +0 -1
- package/dist/layers.test.d.ts +0 -1
- package/dist/middlewares/spaceDeployment.test.d.ts +0 -1
- package/dist/modules/actions/connectorWrite.test.d.ts +0 -1
- package/dist/modules/actions/jobs/failureStreak.test.d.ts +0 -1
- package/dist/modules/actions/jobs/later.test.d.ts +0 -1
- package/dist/modules/actions/jobs/memoryStores.test.d.ts +0 -1
- package/dist/modules/actions/jobs/scheduler.test.d.ts +0 -1
- package/dist/modules/actions/jobs/testing/jobQueueContract.d.ts +0 -25
- package/dist/modules/actions/jobs/worker.test.d.ts +0 -1
- package/dist/modules/actions/moduleFor.test.d.ts +0 -1
- package/dist/modules/actions/runtime/check.test.d.ts +0 -1
- package/dist/modules/actions/runtime/credentials.test.d.ts +0 -1
- package/dist/modules/actions/runtime/email.test.d.ts +0 -1
- package/dist/modules/actions/runtime/fileKv.test.d.ts +0 -1
- package/dist/modules/actions/runtime/flags.test.d.ts +0 -1
- package/dist/modules/actions/runtime/guards.test.d.ts +0 -1
- package/dist/modules/actions/runtime/kvStore.test.d.ts +0 -1
- package/dist/modules/actions/runtime/namespaceKv.test.d.ts +0 -1
- package/dist/modules/actions/runtime/redisKv.integration.test.d.ts +0 -1
- package/dist/modules/actions/runtime/renderResolver.test.d.ts +0 -1
- package/dist/modules/actions/runtime/renderShare.test.d.ts +0 -1
- package/dist/modules/actions/runtime/runAction.test.d.ts +0 -1
- package/dist/modules/actions/runtime/runLogger.test.d.ts +0 -1
- package/dist/modules/actions/runtime/signing.test.d.ts +0 -1
- package/dist/modules/actions/taskCatalog.test.d.ts +0 -1
- package/dist/modules/actions/tasks/db.test.d.ts +0 -1
- package/dist/modules/actions/tasks/email.test.d.ts +0 -1
- package/dist/modules/actions/tasks/http.test.d.ts +0 -1
- package/dist/modules/actions/tasks/kv.test.d.ts +0 -1
- package/dist/modules/actions/transport/callHandler.test.d.ts +0 -1
- package/dist/modules/actions/transport/webhookHandler.test.d.ts +0 -1
- package/dist/modules/connectors/engine.test.d.ts +0 -1
- package/dist/modules/connectors/projection.test.d.ts +0 -1
- package/dist/modules/connectors/resolver.test.d.ts +0 -1
- package/dist/modules/functions/build.test.d.ts +0 -1
- package/dist/modules/functions/load.test.d.ts +0 -1
- package/dist/modules/functions/local.test.d.ts +0 -1
- package/dist/modules/functions/manifest.test.d.ts +0 -1
- package/dist/modules/functions/native.test.d.ts +0 -1
- package/dist/modules/functions/plugins.test.d.ts +0 -1
- package/dist/modules/functions/routes.test.d.ts +0 -1
- package/dist/modules/functions/runner/remote.test.d.ts +0 -1
- package/dist/modules/functions/sandbox/isolate.test.d.ts +0 -1
- package/dist/modules/functions/testing/tasksOf.d.ts +0 -4
- package/dist/modules/images/imageProxy.test.d.ts +0 -1
- package/dist/modules/images/transform.test.d.ts +0 -1
- package/dist/modules/mongo/stores.integration.test.d.ts +0 -1
- package/dist/modules/mysql/accounts.test.d.ts +0 -1
- package/dist/modules/mysql/jobs/stores.integration.test.d.ts +0 -1
- package/dist/modules/mysql/schema.test.d.ts +0 -1
- package/dist/modules/mysql/store.integration.test.d.ts +0 -1
- package/dist/modules/realtime/realtime.test.d.ts +0 -1
- package/dist/modules/realtime/redisPubSub.test.d.ts +0 -1
- package/dist/modules/realtime/retained.test.d.ts +0 -1
- package/dist/modules/realtime/socket.test.d.ts +0 -1
- package/dist/modules/rsc/connectorRscData.test.d.ts +0 -1
- package/dist/modules/rsc/handler.test.d.ts +0 -1
- package/dist/modules/rsc/publicFileResolver.test.d.ts +0 -1
- package/dist/modules/rsc/resolveRscData.test.d.ts +0 -1
- package/dist/modules/runtime/elsewhere.test.d.ts +0 -1
- package/dist/modules/runtime/entry.test.d.ts +0 -1
- package/dist/modules/runtime/inside.test.d.ts +0 -1
- package/dist/modules/runtime/ownServer.test.d.ts +0 -1
- package/dist/modules/runtime/runtime.test.d.ts +0 -1
- package/dist/modules/sqlite/kv.test.d.ts +0 -1
- package/dist/modules/ssr/draftSession.test.d.ts +0 -1
- package/dist/modules/ssr/loadPluginComponents.test.d.ts +0 -1
- package/dist/modules/ssr/metering.test.d.ts +0 -1
- package/dist/modules/ssr/prepareRender.test.d.ts +0 -1
- package/dist/modules/ssr/redirect.test.d.ts +0 -1
- package/dist/modules/ssr/registerExternalPlugins.test.d.ts +0 -1
- package/dist/modules/ssr/reportMissingPlugins.test.d.ts +0 -1
- package/dist/modules/ssr/resolvePageSeo.test.d.ts +0 -1
- package/dist/modules/ssr/spaceDocument.test.d.ts +0 -1
- package/dist/modules/ssr/template.test.d.ts +0 -1
- package/dist/modules/ssr/testing/offlineData.d.ts +0 -5
- package/dist/modules/ssr/vendor.test.d.ts +0 -1
- package/dist/plugins/compile.test.d.ts +0 -1
- package/dist/plugins/copy.test.d.ts +0 -1
- package/dist/plugins/manager.test.d.ts +0 -1
- package/dist/plugins/validate.test.d.ts +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,183 @@
|
|
|
1
1
|
# @plitzi/sdk-server
|
|
2
2
|
|
|
3
|
+
## 0.38.21
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 19fbc45: ## Server
|
|
8
|
+
|
|
9
|
+
- **Jobs: work longer than a request** (`@plitzi/sdk-server`, `@plitzi/sdk-shared`, `@plitzi/sdk-elements`,
|
|
10
|
+
`@plitzi/plitzi-sdk`, `@plitzi/sdk-authoring`) — PZ-136. A space's code declares them in
|
|
11
|
+
`defineFunctions({ jobs: { train: { watch, maxSeconds, run(input, job, ctx) } } })` and starts them with
|
|
12
|
+
`ctx.jobs.start(name, input, { key })` (`get`, `pause`, `resume`, `cancel` beside it). They run in the actions' durable
|
|
13
|
+
queue — leased, taken over when a server dies, retried with backoff — slice by slice, in the sandbox, in a space's
|
|
14
|
+
runtime and natively alike: `job.save(state)` is the one checkpoint and the next slice starts with `job.state`;
|
|
15
|
+
`job.report(fraction, step)` says how far it is; on `job.signal` (`job.stopping`: `pause`, `cancel`, `limit`,
|
|
16
|
+
`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
|
|
17
|
+
saved since it began — one that saved nothing fails, so a job cannot loop forever; a runtime's runs until the job's
|
|
18
|
+
time is up. A real pause: `paused` keeps what it saved until resumed. Who may watch it is RBAC: whoever started it, and
|
|
19
|
+
whoever its `watch` (a channel's access) lets in, on `$job:<id>` — the platform's topic, retained — read with
|
|
20
|
+
`useJob(id)` or a `channel` element on `$job:{{ id }}`; the view never carries its input, its state, or an error other
|
|
21
|
+
than the code's own refusal. Limits per space (its plan) through `functions.jobs.limitsFor` —
|
|
22
|
+
`DEFAULT_FUNCTION_JOB_LIMITS` otherwise: 10 running across the account's spaces (`pool`, the oldest first), 1,000
|
|
23
|
+
waiting, 6 h, slices of 5 min / 30 s CPU / 10,000 calls, 1 MB of state.
|
|
24
|
+
- **The queue's types are the queue's** (`@plitzi/sdk-shared`, `@plitzi/sdk-server`): `ActionJobQueue`, `ActionJob`,
|
|
25
|
+
`ActionJobInput`, `ActionJobStatus`, `ActionJobAttempt`, `ActionJobSettlement`, `ActionJobQuery` are `JobQueue`, `Job`,
|
|
26
|
+
`JobInput`, `JobStatus`, `JobAttempt`, `JobSettlement`, `JobQuery` (`ACTION_JOB_STATUSES` → `JOB_STATUSES`,
|
|
27
|
+
`isJobStatus`, `TERMINAL_JOB_STATUSES`) — the queue holds a schedule's fires, the runs set for later and the jobs of
|
|
28
|
+
the spaces' functions. **What a job runs is its `target`**: `{ kind: 'action', name, trigger }` or
|
|
29
|
+
`{ kind: 'function', name, user, watch, at }`, in place of `actionId`, `trigger` and `function`; `listJobs` filters
|
|
30
|
+
by `kind` and `name`. Also on the queue: `paused` with `pause`/`resume`, `write` for what a running job saves and
|
|
31
|
+
reports, `state`/`progress`/`result`/`activeMs`, `heartbeat` answering `{ jobId, stop: 'cancel' | 'pause' }[]`, a
|
|
32
|
+
settlement's explicit `refund`, `requeue(…, { input, fresh })`. The helpers bring a store a release before left up
|
|
33
|
+
to it by themselves: MySQL's `ensureJobTables` gives each job its target from `action_id`/`trigger_type` and drops
|
|
34
|
+
them (`mysqlJobSchemaUpgrades` lists the statements for a deployment's own migrations); Mongo's queue does the same
|
|
35
|
+
to the documents on first use and drops the `spaceId_1_actionId_1_updatedAt_-1` index. A deployment with a queue of
|
|
36
|
+
its own: the contract tests (`describeJobQueue`) say what it must now do.
|
|
37
|
+
- **A runtime's routes stream** (`@plitzi/sdk-server`): a route under `/fn/` answered by a space's runtime is passed on
|
|
38
|
+
as it is written — its head at once, its body as the code writes it, with the platform's `ctx` — over the functions
|
|
39
|
+
protocol's new `head`/`chunk` messages, with no time limit once it answered; the deployment's own routes stream too.
|
|
40
|
+
A runtime's `endpoints` are for addresses outside `/fn/` (an MCP server at `/mcp`); anything that can live under
|
|
41
|
+
`/fn/` is a route. A sandbox's routes are answered whole, as before.
|
|
42
|
+
- **`createJobControl({ queue, realtime: { pubsub, kv } })`** (`@plitzi/sdk-server/actions`): an operator's
|
|
43
|
+
`pause`/`resume`/`cancel`/`requeue` from a process that serves no pages — a Queue panel's API — each said on
|
|
44
|
+
`$job:<id>` through the page server's own pub/sub and retained store, so a watcher hears what an operator did.
|
|
45
|
+
- **A run's user carries no session** (`RunUser`): what a step, a function and a job see of who asked.
|
|
46
|
+
- **The builder shows the jobs** (`@plitzi/plitzi-builder`, `@plitzi/sdk-shared`): **Server → Functions** lists the
|
|
47
|
+
jobs the code declares as it is typed (how long each may run; one spread in or built by a call is counted, not
|
|
48
|
+
guessed), and the inspector of one says how it is started and who may watch it, with the space's runs of it — live
|
|
49
|
+
while one moves, progress and step as its code reported them — and **Pause**, **Resume**, **Cancel** and **Run
|
|
50
|
+
again**. Through two new builder operations, `SpaceJobs(kind, name, status, page, pageSize)` — a `SpaceJob` each:
|
|
51
|
+
what it runs, where it is and how far, never its input, state or result — and `SpaceControlJob(jobId, control)`
|
|
52
|
+
(`JobControlAction`). Beside them in `@plitzi/sdk-shared/actions`: `JOB_KINDS`/`isJobKind`, and `actionAccessOf`, the
|
|
53
|
+
one reading of a channel's access, which the functions' manifest now reads a job's `watch` with too.
|
|
54
|
+
|
|
55
|
+
- **`ctx.oauth.token` for an SDK in the page** (`@plitzi/sdk-server`, `@plitzi/sdk-shared`): Spotify's Web Playback,
|
|
56
|
+
Google's Picker and their kind ask the page for the access token themselves, and `ctx.oauth` kept every token on the
|
|
57
|
+
server. A connection that declares `exposeToken: true` now answers `ctx.oauth.token(name, { owner })` —
|
|
58
|
+
`{ token, type, expiresAt, scopes }`, renewed first when about to lapse — for a route of the code to hand to the
|
|
59
|
+
connection's owner. The refresh token never leaves; a connection without `exposeToken` refuses `token`, naming the
|
|
60
|
+
field. Through the sandbox's protocol and natively alike.
|
|
61
|
+
|
|
62
|
+
- **A page for some permissions, kept by the server** (`@plitzi/sdk-shared`, `@plitzi/sdk-server`,
|
|
63
|
+
`@plitzi/sdk-authoring`, `@plitzi/sdk-elements`, `@plitzi/plitzi-builder`): a page says
|
|
64
|
+
`access: { permissions: [...] }`, and a visitor without every one is answered 401 (or the page's sign-in redirect) or
|
|
65
|
+
403 with a refusal drawn in the page's layout. Its content is withheld from everything that visitor is sent — the
|
|
66
|
+
render, the hydration payload, the space document (and a document built for somebody with access is not handed to
|
|
67
|
+
somebody without it by its name) and the page's server data. The builder's page settings take the permissions;
|
|
68
|
+
authoring refuses an `access` the server could not keep (`page-access`). A space read back as code — `plitzi create
|
|
69
|
+
--from`, the Export — keeps each page's `access`, so a protected page is never exported open. A page's handle carries
|
|
70
|
+
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
|
|
71
|
+
behind a session (`plitzi upgrade` rewrites an untouched one).
|
|
72
|
+
- **A project's first plugin is picked up while it runs** (`@plitzi/sdk-server`): `start:dev` registers a plugin folder
|
|
73
|
+
added under `src/plugins/` and reloads the open pages — but only watched that folder when it existed at boot, so a
|
|
74
|
+
project with no plugin yet (one taken out of a space that had none) showed nothing of its first `plitzi plugin add`
|
|
75
|
+
until a restart. With no folder, the server waits for it to appear and takes what it holds then.
|
|
76
|
+
|
|
77
|
+
## Packaging
|
|
78
|
+
- **No package ships the declarations of its tests** (`@plitzi/sdk-server`, `@plitzi/sdk-mcp`, `@plitzi/plitzi-sdk`,
|
|
79
|
+
`@plitzi/plitzi-builder`, `@plitzi/sdk-elements`, `@plitzi/sdk-shared`): each app wrote its declarations with its own
|
|
80
|
+
`dts({ exclude })`, and the ones that left the tests out of it shipped a `.test.d.ts` beside their modules — 148 in
|
|
81
|
+
sdk-server alone — and the base config let a `.bench.d.ts` through. Every `dts()` now excludes
|
|
82
|
+
`'**/*.(test|bench).(ts|tsx)'`, and `yarn check:dist-exports` (CI, after `build:prod`) fails a build of any published
|
|
83
|
+
package that holds one.
|
|
84
|
+
- **`@plitzi/plitzi-builder` depends on `graphql` ^16** (was ^17): Apollo Server — the builder's API — supports only
|
|
85
|
+
16, so a host installing the builder beside it got two copies. The builder uses nothing of 17's.
|
|
86
|
+
|
|
87
|
+
## Elements
|
|
88
|
+
- **A dropdown closes when a link in it is chosen** (`@plitzi/sdk-elements`): a link stops its click from bubbling,
|
|
89
|
+
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
|
|
90
|
+
cancelled, which would have kept an external link from going anywhere. The popup now hears the click as it goes down
|
|
91
|
+
and lets it through.
|
|
92
|
+
|
|
93
|
+
## CLI
|
|
94
|
+
- **A refused push says why** (`@plitzi/cli`): `space push functions` and the data push read any 409 as "changed since
|
|
95
|
+
your pull" — and the platform also answers 409 when the space has no private bucket to keep its code or data in, so
|
|
96
|
+
a first push to a space with no storage sent its author to pull, which changed nothing. The CLI now names a conflict
|
|
97
|
+
only when the refusal says `version`, and prints the platform's own words otherwise (where to add the bucket).
|
|
98
|
+
- **`create` points at the Academy** (`@plitzi/cli`): its last lines name the docs' Academy,
|
|
99
|
+
`https://docs.plitzi.com/academy`, for whoever is new to Plitzi — and the README the docs themselves.
|
|
100
|
+
|
|
101
|
+
## Builder
|
|
102
|
+
- **A space served by Plitzi has a server, and the builder says so** (`@plitzi/plitzi-builder`, `@plitzi/sdk-shared`):
|
|
103
|
+
whether a space can run its actions and resolve its connectors was read off an SSR _credential_, which only a space
|
|
104
|
+
deployed to a page server of its own has — so every space served at `<space>.plitzi.app` showed "No server-rendered
|
|
105
|
+
deployment" over Server and counted its actions unavailable, while they ran. The deployments now carry what serves
|
|
106
|
+
them (`provider`), and a deployment served by SSR — Plitzi's or the space's — counts.
|
|
107
|
+
- **New Layout saves the layout** (`@plitzi/sdk-schema`): a layout is a root of the pages' tree, added with no anchor,
|
|
108
|
+
and `flatMapOf` found no tree for an empty anchor — so the server refused every new layout, saying it was "already
|
|
109
|
+
added". A root now goes into the pages' tree, and the refusal says which of the two it is.
|
|
110
|
+
- **Settings → Realtime: a space's channels, declared by hand** (`@plitzi/plitzi-builder`): `settings.channels` was
|
|
111
|
+
written only in code or by an agent over MCP, so a space made in the builder could not open a channel. The section
|
|
112
|
+
lists the channels with who may join (anyone, signed-in visitors, visitors with permissions), who may speak (pages, or
|
|
113
|
+
only the server's `Publish On Channel`), presence, a grant, keeping the last message and the two limits — saved only
|
|
114
|
+
when `channelProblems` passes, with what is wrong said under the channel otherwise.
|
|
115
|
+
|
|
116
|
+
- Updated dependencies [19fbc45]
|
|
117
|
+
- @plitzi/plitzi-sdk@0.38.21
|
|
118
|
+
- @plitzi/sdk-shared@0.38.21
|
|
119
|
+
|
|
120
|
+
## 0.38.20
|
|
121
|
+
|
|
122
|
+
### Patch Changes
|
|
123
|
+
|
|
124
|
+
- c7c241a: ## Security
|
|
125
|
+
|
|
126
|
+
- **The `Origin` fallback reads the request's own authority before a forwarded one** (`@plitzi/sdk-server`): 0.38.19
|
|
127
|
+
took `X-Forwarded-Host` first, and with no proxy in front a client could send one naming this host on another port,
|
|
128
|
+
making that port's `Origin` this server's own. Now `:authority` or `Host` decide whenever they name the host the
|
|
129
|
+
request is answered as; `X-Forwarded-Host` only when they do not — a host that took its hostname from the header
|
|
130
|
+
(Express's `trust proxy`) trusts the proxy that wrote it. No option to set: what the host resolved says which one it
|
|
131
|
+
believes. The write guard (`crossSiteWrites`), the sign-in's login-CSRF check and `createOriginGuardMiddleware`
|
|
132
|
+
share it.
|
|
133
|
+
|
|
134
|
+
## Server
|
|
135
|
+
- **`ctx.oauth`: OAuth 2.0 for a space's code, any provider** (`@plitzi/sdk-server`, `@plitzi/sdk-shared`): a
|
|
136
|
+
connection is data in `defineFunctions({ oauth: { calendar: { issuer | authorizeUrl + tokenUrl, credential, scopes,
|
|
137
|
+
authorizeParams, clientAuth } } })` — an OpenID provider by its `issuer` (endpoints discovered), any other by its
|
|
138
|
+
endpoints; none is known to the platform by name. `ctx.oauth.connect(name, { returnTo, owner? })` answers the
|
|
139
|
+
consent URL (authorization code with PKCE); the platform answers `/fn/oauth/callback` — the one address to register
|
|
140
|
+
with every provider — exchanges the code with the app's id and secret from the named credential, and sends the
|
|
141
|
+
visitor back to `returnTo` with `?oauth=<name>&oauth_result=connected` (or `&oauth_error=`). `ctx.oauth.fetch(name,
|
|
142
|
+
url)` writes the token in, renewed before it lapses and once more on a 401, only to `allow.hosts`; `status` and
|
|
143
|
+
`disconnect` (revoked where the provider says). A token is a signed-in visitor's own by default, `{ owner: 'space' }`
|
|
144
|
+
the space's, or a key of the code's own; it is kept in the space's `kv` sealed with a key of the space's that no
|
|
145
|
+
`ctx.sign` reaches, so the code never holds one. In the sandbox, natively and in a space's runtime alike; a plugin's
|
|
146
|
+
functions declare and reach none. Needs `signingSecret`. Runs also carry the `origin` of the request that started
|
|
147
|
+
them (`ctx.origin` of a task context), what the callback address is made of.
|
|
148
|
+
|
|
149
|
+
## Packages
|
|
150
|
+
- **No path a package does not export is written anywhere in the packages** (`@plitzi/plitzi-sdk`,
|
|
151
|
+
`@plitzi/sdk-shared`): two JSDoc comments sent readers to `@plitzi/sdk-authoring/testing`, which is not an entry —
|
|
152
|
+
`inspectRenders` is exported by `@plitzi/sdk-authoring`. `yarn check:specifiers` (in CI after the build) reads every
|
|
153
|
+
`@plitzi/<package>/<path>` the workspace writes — the code, its built declarations, JSDoc, skills and docs — against
|
|
154
|
+
what that package exports, so an import somebody would copy into a project and get `ERR_MODULE_NOT_FOUND` from cannot
|
|
155
|
+
be published again.
|
|
156
|
+
|
|
157
|
+
- **The packages that run in Node say which Node** (`@plitzi/sdk-server`, `@plitzi/cli`, `@plitzi/sdk-mcp`,
|
|
158
|
+
`@plitzi/sdk-authoring`): `"engines": { "node": ">=22.18" }`, the floor every project the CLI makes already declares —
|
|
159
|
+
installed on an older Node they now say so, instead of failing on the first API it lacks (`--env-file-if-exists`,
|
|
160
|
+
`--permission`, `Set#union`). The browser's packages declare none: a bundler reads them.
|
|
161
|
+
|
|
162
|
+
- **A short render guide, and each part of it alone** (`@plitzi/sdk-mcp`): `renderGuideText` stays the whole guide
|
|
163
|
+
(~30k characters); `renderGuideCore` is a third of it for an agent that counts its tokens — a voice assistant, a small
|
|
164
|
+
model — with the model of a render, the element types, the host's theme and what to do on a refusal, and the address
|
|
165
|
+
of every other section; `renderGuideTopics[topic]` and `renderGuideTopicUri(topic)` (`plitzi://render/guide/repeat`,
|
|
166
|
+
`…/data`…) serve each one, cut from the one text. The MCP server answers them as resources and through `plitzi_read`.
|
|
167
|
+
|
|
168
|
+
## CLI
|
|
169
|
+
- **What Plitzi decided reaches the agent writing a report** (`@plitzi/cli`): `plitzi feedback`'s brief lists what was
|
|
170
|
+
reported and kept as it is — with why, and what to do instead — so a report files it under `changed` as `decided`
|
|
171
|
+
rather than carrying it as open, and the page has that status.
|
|
172
|
+
|
|
173
|
+
- **The CLI skill says what `ERR_MODULE_NOT_FOUND` into a `@plitzi` package's `dist` is** (`@plitzi/cli`): an import of
|
|
174
|
+
a path the package does not export — a file rather than its folder — with `plitzi doctor` to name each one and
|
|
175
|
+
`plitzi upgrade migrations --write` to rewrite it.
|
|
176
|
+
|
|
177
|
+
- Updated dependencies [c7c241a]
|
|
178
|
+
- @plitzi/plitzi-sdk@0.38.20
|
|
179
|
+
- @plitzi/sdk-shared@0.38.20
|
|
180
|
+
|
|
3
181
|
## 0.38.19
|
|
4
182
|
|
|
5
183
|
### 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#
|
|
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 `
|
|
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<"
|
|
72
|
+
lifetimes: Record<"refresh" | "access" | "session" | "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;
|
package/dist/core/auth/csrf.js
CHANGED
|
@@ -76,12 +76,17 @@ var readCookieHeader = (carrier, name) => {
|
|
|
76
76
|
}
|
|
77
77
|
};
|
|
78
78
|
/**
|
|
79
|
-
* Whether `origin` is the request's own: its host AND port, as the request was addressed
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
79
|
+
* Whether `origin` is the request's own: its host AND port, as the request was addressed.
|
|
80
|
+
*
|
|
81
|
+
* The authority is the one that names the hostname the request is answered as, compared port included:
|
|
82
|
+
*
|
|
83
|
+
* - **the request's own** first — HTTP/2's `:authority` (which carries no `Host` header at all), or `Host`;
|
|
84
|
+
* - **`X-Forwarded-Host`** only when that does not: a host that took its hostname from the header trusts the proxy in
|
|
85
|
+
* front of it (Express's `trust proxy`), and that proxy wrote it. Read before the request's own, a client could send
|
|
86
|
+
* one naming this host on another port, and that port would count as this server's.
|
|
87
|
+
*
|
|
88
|
+
* None naming it: nothing says which port the request reached, so the origin is not taken as its own — comparing the
|
|
89
|
+
* name alone made every port and every scheme of this host count.
|
|
85
90
|
*/
|
|
86
91
|
var isOwnOrigin = (origin, carrier) => {
|
|
87
92
|
let url;
|
|
@@ -92,9 +97,9 @@ var isOwnOrigin = (origin, carrier) => {
|
|
|
92
97
|
}
|
|
93
98
|
const forwarded = header(carrier, "x-forwarded-host")?.split(",")[0]?.trim();
|
|
94
99
|
for (const authority of [
|
|
95
|
-
forwarded,
|
|
96
100
|
header(carrier, ":authority"),
|
|
97
|
-
header(carrier, "host")
|
|
101
|
+
header(carrier, "host"),
|
|
102
|
+
forwarded
|
|
98
103
|
]) {
|
|
99
104
|
if (!authority) continue;
|
|
100
105
|
let own;
|
|
@@ -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<"
|
|
177
|
+
lifetimes: Record<"refresh" | "access" | "session" | "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;
|
package/dist/core/configSeam.js
CHANGED
|
@@ -112,7 +112,7 @@ 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)));
|
|
116
116
|
/** The deployment's database drivers, each held to what a `db` task calls — or why one is not, as the server starts. */
|
|
117
117
|
var dbDriversOf = (drivers) => {
|
|
118
118
|
if (drivers === void 0) return;
|
|
@@ -123,7 +123,7 @@ var dbDriversOf = (drivers) => {
|
|
|
123
123
|
/** The deployment's functions config, held to what runs a space's code — or why it is not, as the server starts. */
|
|
124
124
|
var functionsConfigOf = (config) => {
|
|
125
125
|
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
|
|
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`, `jobs` with a `limitsFor` function.");
|
|
127
127
|
return config;
|
|
128
128
|
};
|
|
129
129
|
//#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
|
/**
|
|
@@ -21,6 +22,7 @@ var functionRoutesStage = async (ctx) => {
|
|
|
21
22
|
},
|
|
22
23
|
...req.ctx.user ? { user: req.ctx.user } : {},
|
|
23
24
|
callerId: req.ctx.user ? `user:${String(req.ctx.user.id)}` : `ip:${clientIp(ctx.raw, req)}`,
|
|
25
|
+
...requestOrigin(req) ? { origin: requestOrigin(req) } : {},
|
|
24
26
|
signal: ctx.signal
|
|
25
27
|
}, req.method, req.path.slice(FUNCTION_ROUTES_PREFIX.length));
|
|
26
28
|
if (!route) return false;
|
|
@@ -30,16 +32,20 @@ var functionRoutesStage = async (ctx) => {
|
|
|
30
32
|
if (!name.startsWith(":") && value !== void 0) headers.set(name, Array.isArray(value) ? value.join(", ") : value);
|
|
31
33
|
});
|
|
32
34
|
const hasBody = req.method !== "GET" && req.method !== "HEAD";
|
|
33
|
-
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}`, {
|
|
34
36
|
method: req.method,
|
|
35
37
|
headers,
|
|
36
38
|
...hasBody ? { body: new Uint8Array(await readRawBytes(ctx.raw)) } : {}
|
|
37
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
|
+
}
|
|
38
45
|
ctx.res.setStatus(response.status);
|
|
39
46
|
response.headers.forEach((value, name) => {
|
|
40
47
|
ctx.res.setHeader(name, value);
|
|
41
48
|
});
|
|
42
|
-
if (!response.headers.has("cache-control")) ctx.res.setHeader("Cache-Control", "no-store");
|
|
43
49
|
ctx.res.send(Buffer.from(await response.arrayBuffer()));
|
|
44
50
|
return true;
|
|
45
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
|
}
|
package/dist/functions-api.d.ts
CHANGED
|
@@ -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
|
*
|
|
@@ -110,6 +135,10 @@ export declare type FunctionContext = {
|
|
|
110
135
|
data: (file: string) => Promise<unknown>;
|
|
111
136
|
/** A line for whoever reads the run: the builder's Try, and the deployment's logs. */
|
|
112
137
|
log: (...values: unknown[]) => void;
|
|
138
|
+
/** OAuth 2.0 through the space's declared connections — see {@link FunctionOAuth}. */
|
|
139
|
+
oauth: FunctionOAuth;
|
|
140
|
+
/** The space's jobs — see {@link FunctionJobs}. */
|
|
141
|
+
jobs: FunctionJobs;
|
|
113
142
|
/** Progress for a caller that asked for a stream — a no-op when nobody did. */
|
|
114
143
|
emit: (chunk: unknown) => void;
|
|
115
144
|
/** Aborted when the run is: cancelled, or out of time. Hand it to what can stop early. */
|
|
@@ -131,6 +160,184 @@ export declare type FunctionFetchInit = {
|
|
|
131
160
|
credential?: string;
|
|
132
161
|
};
|
|
133
162
|
|
|
163
|
+
/** A job of the space's: work longer than a request, run on the server slice by slice until it answers. */
|
|
164
|
+
export declare type FunctionJob<I extends Record<string, unknown> = Record<string, unknown>, S = unknown, R = unknown> = {
|
|
165
|
+
/**
|
|
166
|
+
* Who may watch it (`$job:<id>`, `useJob`) besides whoever started it — a channel's access, read against the visitor's
|
|
167
|
+
* permissions in the space. Absent, only whoever started it.
|
|
168
|
+
*/
|
|
169
|
+
watch?: ActionAccess;
|
|
170
|
+
/** How long it may run, every slice together, in seconds — within what the server allows. */
|
|
171
|
+
maxSeconds?: number;
|
|
172
|
+
/**
|
|
173
|
+
* The work. What it answers is the job's result; an `ActionRefusal` fails it without a retry. A method, not a property:
|
|
174
|
+
* so a job typed with an input and a state of its own is still one of `FunctionsDefinition['jobs']`, and one written
|
|
175
|
+
* in place there gets an object for its input and `unknown` for its state.
|
|
176
|
+
*/
|
|
177
|
+
run(input: I, job: FunctionJobHandle<S>, ctx: FunctionContext): R | Promise<R>;
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* 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,
|
|
182
|
+
* a lost server or its time in one go ending one — and every slice but the first starts from what the one before saved.
|
|
183
|
+
*/
|
|
184
|
+
export declare type FunctionJobHandle<S = unknown> = {
|
|
185
|
+
id: string;
|
|
186
|
+
name: string;
|
|
187
|
+
/** What it last saved — `undefined` on its first slice, and whenever it never saved. */
|
|
188
|
+
state: S | undefined;
|
|
189
|
+
/** Which attempt this is, from 1: a slice after a failure is the next attempt, from the last save. */
|
|
190
|
+
attempt: number;
|
|
191
|
+
/**
|
|
192
|
+
* Keeps `state` durably: the next slice starts with it. JSON, within what the server keeps for one job. A method, not
|
|
193
|
+
* a property: so a job whose state has a type of its own is still one of `FunctionsDefinition['jobs']`.
|
|
194
|
+
*/
|
|
195
|
+
save(state: S): Promise<void>;
|
|
196
|
+
/** How far it is, from 0 to 1, and what it is doing — for whoever watches it. Never fails the job. */
|
|
197
|
+
report: (fraction: number, step?: string) => void;
|
|
198
|
+
/** Why this slice is asked to end, once it is (`signal` aborted): save, and return. */
|
|
199
|
+
readonly stopping: FunctionJobStop | undefined;
|
|
200
|
+
/** Aborted when the slice is asked to end — the same as `ctx.signal`. Some seconds later it is cut. */
|
|
201
|
+
signal: AbortSignal;
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* 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
|
|
206
|
+
* called from its routes and tasks, behind its own checks.
|
|
207
|
+
*/
|
|
208
|
+
export declare type FunctionJobs = {
|
|
209
|
+
/**
|
|
210
|
+
* Starts one of the jobs this code declares (`jobs` in `defineFunctions`), with `input`: answered at once, the job
|
|
211
|
+
* `pending`. With `key`, at most one of that key runs at a time — starting it again while one is under way answers that
|
|
212
|
+
* one (a button pressed twice), and once it ended starts it over with the new input.
|
|
213
|
+
*/
|
|
214
|
+
start: (name: string, input?: Record<string, unknown>, options?: {
|
|
215
|
+
key?: string;
|
|
216
|
+
}) => Promise<FunctionJobView>;
|
|
217
|
+
/** One of the space's jobs, as whoever may watch it sees it — or nothing, when there is none by that id. */
|
|
218
|
+
get: (id: string) => Promise<FunctionJobView | undefined>;
|
|
219
|
+
/** Sets it aside: it stops once its code saved, and waits as `paused`. Answers whether anything changed. */
|
|
220
|
+
pause: (id: string) => Promise<boolean>;
|
|
221
|
+
/** Puts a paused job back in the queue, to go on from what it saved. */
|
|
222
|
+
resume: (id: string) => Promise<boolean>;
|
|
223
|
+
/** Stops it for good: dropped if it waits, aborted if it runs. */
|
|
224
|
+
cancel: (id: string) => Promise<boolean>;
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Why a slice of a job is asked to end (`job.stopping`): it was set aside (`pause`) or cancelled (`cancel`), its time in
|
|
229
|
+
* one go is up (`limit`) or the server is going away (`shutdown`). Whichever, what was saved is where it goes on from.
|
|
230
|
+
*/
|
|
231
|
+
export declare type FunctionJobStop = 'pause' | 'cancel' | 'limit' | 'shutdown';
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* A job as whoever may watch it sees it: what `ctx.jobs.get` answers, what `$job:<id>` says each time it moves, and
|
|
235
|
+
* what `useJob` holds. Never its input or what it saved: those are its code's.
|
|
236
|
+
*/
|
|
237
|
+
declare type FunctionJobView = {
|
|
238
|
+
id: string;
|
|
239
|
+
/** The job's name, as the functions declare it. */
|
|
240
|
+
name: string;
|
|
241
|
+
status: JobStatus;
|
|
242
|
+
/** From 0 to 1, as its code last reported. */
|
|
243
|
+
progress?: number;
|
|
244
|
+
/** What it is doing, in its code's words. */
|
|
245
|
+
step?: string;
|
|
246
|
+
/** What it answered, once it succeeded. */
|
|
247
|
+
result?: unknown;
|
|
248
|
+
/** Why it failed — for a refusal, its code's own words; for anything else, that it failed. */
|
|
249
|
+
error?: string;
|
|
250
|
+
/** Epoch ms. */
|
|
251
|
+
createdAt: number;
|
|
252
|
+
updatedAt: number;
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* OAuth 2.0 on behalf of whoever the space serves, through the connections it declared (`oauth` in its functions): the
|
|
257
|
+
* consent, the code exchanged, the token kept sealed and renewed by the platform. The code never holds a token, as it
|
|
258
|
+
* never holds a credential — it names the connection.
|
|
259
|
+
*/
|
|
260
|
+
export declare type FunctionOAuth = {
|
|
261
|
+
/**
|
|
262
|
+
* Where to send the visitor to consent (authorization code, PKCE). They come back to `/fn/oauth/callback` — the
|
|
263
|
+
* address to register with the provider, on the space's host — and from there to `returnTo`, a path of the space,
|
|
264
|
+
* with `?oauth=<connection>&oauth_result=connected` or `&oauth_error=<what>`.
|
|
265
|
+
*/
|
|
266
|
+
connect: (connection: string, options: {
|
|
267
|
+
returnTo: string;
|
|
268
|
+
} & FunctionOAuthOwner) => Promise<{
|
|
269
|
+
url: string;
|
|
270
|
+
}>;
|
|
271
|
+
status: (connection: string, options?: FunctionOAuthOwner) => Promise<FunctionOAuthStatus>;
|
|
272
|
+
/**
|
|
273
|
+
* A request to the provider's API with the token written in (`Authorization: Bearer`), renewed when it is about to
|
|
274
|
+
* lapse and once more if the answer is 401. Only to the hosts the space declared (`allow.hosts`).
|
|
275
|
+
*/
|
|
276
|
+
fetch: (connection: string, url: string | URL, init?: Omit<FunctionFetchInit, 'credential'> & FunctionOAuthOwner) => Promise<Response>;
|
|
277
|
+
/** Forgets the connection — revoked at the provider when it says where — and answers whether there was one. */
|
|
278
|
+
disconnect: (connection: string, options?: FunctionOAuthOwner) => Promise<boolean>;
|
|
279
|
+
/**
|
|
280
|
+
* The access token itself, renewed first when it is about to lapse — only of a connection that declares
|
|
281
|
+
* `exposeToken: true`, for a provider's SDK in the page that asks for it (`getOAuthToken`). Whoever the code hands it
|
|
282
|
+
* to holds it until it lapses: answer it only to whom the connection is (its owner), from a route that checks so.
|
|
283
|
+
*/
|
|
284
|
+
token: (connection: string, options?: FunctionOAuthOwner) => Promise<FunctionOAuthToken>;
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
/** What a space's functions declare, read from the bundle when it is saved: its tasks, routes and reachable hosts. */
|
|
288
|
+
/**
|
|
289
|
+
* One OAuth 2.0 connection a space's code makes on its visitors' (or its own) behalf, declared as data: any provider,
|
|
290
|
+
* none of them known to the platform by name. `issuer` for one that publishes OpenID metadata — its endpoints are read
|
|
291
|
+
* from `<issuer>/.well-known/openid-configuration` — or the endpoints themselves for one that does not.
|
|
292
|
+
*/
|
|
293
|
+
declare type FunctionOAuthConnection = {
|
|
294
|
+
/** An OpenID provider's issuer (`https://accounts.google.com`): the endpoints are discovered from it. */
|
|
295
|
+
issuer?: string;
|
|
296
|
+
/** Where the visitor is sent to consent, when there is no `issuer` (or to override what it publishes). */
|
|
297
|
+
authorizeUrl?: string;
|
|
298
|
+
/** Where the code is exchanged and the token refreshed, when there is no `issuer` (or to override it). */
|
|
299
|
+
tokenUrl?: string;
|
|
300
|
+
/** Where a token is revoked on `disconnect`, when the provider has one. */
|
|
301
|
+
revokeUrl?: string;
|
|
302
|
+
/** The space's credential holding the app's `clientId` and `clientSecret`: the code names it, never holds it. */
|
|
303
|
+
credential: string;
|
|
304
|
+
/** What is asked for, as the provider spells it. */
|
|
305
|
+
scopes?: string[];
|
|
306
|
+
/** More of the consent URL, as the provider needs it: `{ access_type: 'offline', prompt: 'consent' }`. */
|
|
307
|
+
authorizeParams?: Record<string, string>;
|
|
308
|
+
/** How the app proves who it is to `tokenUrl`: in the body (the default) or as HTTP Basic. */
|
|
309
|
+
clientAuth?: 'body' | 'basic';
|
|
310
|
+
/**
|
|
311
|
+
* The code may read the access token (`ctx.oauth.token`), for a provider's SDK that runs in the page and asks for it
|
|
312
|
+
* itself — Spotify's Web Playback, Google's Picker. Off by default: the token then leaves the server, as far as the
|
|
313
|
+
* code hands it. The refresh token never does.
|
|
314
|
+
*/
|
|
315
|
+
exposeToken?: boolean;
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Whose an OAuth connection is: a signed-in visitor's own by default (`user:<id>`); `space` for one the whole space
|
|
320
|
+
* shares; or a key the code keeps for whom it serves — a profile, a team (`profile:ana`). Letters, digits and `:._@-`.
|
|
321
|
+
*/
|
|
322
|
+
export declare type FunctionOAuthOwner = {
|
|
323
|
+
owner?: string;
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
/** What `ctx.oauth.status` says of a connection — never its token. */
|
|
327
|
+
export declare type FunctionOAuthStatus = {
|
|
328
|
+
connected: boolean;
|
|
329
|
+
scopes?: string[];
|
|
330
|
+
expiresAt?: number;
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
/** The access token `ctx.oauth.token` hands out — never the refresh token, which stays with the platform. */
|
|
334
|
+
export declare type FunctionOAuthToken = {
|
|
335
|
+
token: string;
|
|
336
|
+
type: string;
|
|
337
|
+
expiresAt?: number;
|
|
338
|
+
scopes?: string[];
|
|
339
|
+
};
|
|
340
|
+
|
|
134
341
|
/**
|
|
135
342
|
* An HTTP endpoint of the space, under `/fn/`: a web-standard handler, the shape every edge runtime runs. The request
|
|
136
343
|
* carries no credentials — `ctx.user` says who is asking — and the response sets no cookies: the host's are the
|
|
@@ -154,6 +361,13 @@ export declare type FunctionsDefinition = {
|
|
|
154
361
|
routes?: Record<string, FunctionRoute>;
|
|
155
362
|
/** More CPU or time than an invocation gets by default, for every task and route — a task may ask for its own. */
|
|
156
363
|
limits?: FunctionTimeLimits;
|
|
364
|
+
/**
|
|
365
|
+
* The OAuth connections its code makes (`ctx.oauth`), by the name it calls them — any provider, as data: its `issuer`
|
|
366
|
+
* (OpenID) or its endpoints, the credential with the app's id and secret, the scopes.
|
|
367
|
+
*/
|
|
368
|
+
oauth?: Record<string, FunctionOAuthConnection>;
|
|
369
|
+
/** Its jobs, by name (`ctx.jobs.start(name, input)`): work that outlives a request, run slice by slice. */
|
|
370
|
+
jobs?: Record<string, FunctionJob>;
|
|
157
371
|
};
|
|
158
372
|
|
|
159
373
|
/**
|
|
@@ -279,6 +493,20 @@ declare type InteractionCallbackParamValues<T extends Record<string, unknown> =
|
|
|
279
493
|
|
|
280
494
|
declare type InteractionParamType = 'boolean' | 'select' | 'text' | 'number' | 'textarea' | 'codemirror-text' | 'codemirror-json' | 'elements';
|
|
281
495
|
|
|
496
|
+
/**
|
|
497
|
+
* The durable queue the server's work waits in: a schedule's fires, the runs set for later, and the jobs of the spaces'
|
|
498
|
+
* functions — one queue, one contract (`JobQueue`), whatever store a deployment keeps it in.
|
|
499
|
+
*/
|
|
500
|
+
/**
|
|
501
|
+
* Where a job is, as the only durable answer to "did it happen".
|
|
502
|
+
*
|
|
503
|
+
* `pending` is waiting to be taken, `running` is held by a worker under a lease, `paused` is a job of a space's functions
|
|
504
|
+
* set aside with what it saved, until it is resumed — and the other four are terminal, except that an operator may put
|
|
505
|
+
* a `failed`, `dead` or `cancelled` one back to `pending`. `dead` is a job that used up every attempt it was given: it
|
|
506
|
+
* stays, visibly, because the alternative is work that quietly evaporated.
|
|
507
|
+
*/
|
|
508
|
+
declare type JobStatus = 'pending' | 'running' | 'paused' | 'succeeded' | 'failed' | 'dead' | 'cancelled';
|
|
509
|
+
|
|
282
510
|
/**
|
|
283
511
|
* The lifetime a change writes with: a number of seconds, one worked out from the value written, or none.
|
|
284
512
|
*/
|