@plitzi/sdk-server 0.38.20 → 0.38.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +117 -0
- package/README.md +2 -2
- package/dist/actions.d.ts +6 -0
- package/dist/actions.js +2 -1
- package/dist/core/configSeam.js +2 -2
- package/dist/core/services/functionRoutes.js +7 -2
- package/dist/core/services/realtime.js +5 -2
- package/dist/functions-api.d.ts +155 -0
- package/dist/functions.d.ts +3 -1
- package/dist/functions.js +2 -1
- package/dist/helpers/serverLog.d.ts +1 -1
- package/dist/helpers/serverLog.js +1 -1
- package/dist/hosts/project/plugins.js +20 -3
- package/dist/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/taskContext.d.ts +12 -3
- package/dist/modules/actions/runtime/taskContext.js +7 -1
- package/dist/modules/actions/types.d.ts +18 -4
- package/dist/modules/functions/capabilities.js +59 -1
- package/dist/modules/functions/config.d.ts +9 -0
- package/dist/modules/functions/context.d.ts +2 -2
- package/dist/modules/functions/context.js +14 -1
- package/dist/modules/functions/contract.d.ts +84 -1
- package/dist/modules/functions/driver.js +94 -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 +36 -3
- package/dist/modules/functions/native.js +2 -1
- package/dist/modules/functions/oauth.d.ts +2 -1
- package/dist/modules/functions/oauth.js +15 -2
- package/dist/modules/functions/protocol.d.ts +71 -4
- package/dist/modules/functions/protocol.js +2 -1
- package/dist/modules/functions/routes.d.ts +9 -1
- package/dist/modules/functions/routes.js +48 -23
- 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 +3 -3
- package/skills/plitzi-authoring/reference/auth.md +6 -0
- package/skills/plitzi-authoring/reference/authoring-errors.md +1 -0
- package/skills/plitzi-authoring/reference/plugin-reach.md +3 -0
- package/skills/plitzi-authoring/reference/realtime.md +4 -0
- package/dist/adapters/cloudAdapters.test.d.ts +0 -1
- package/dist/adapters/jsonAdapters.test.d.ts +0 -1
- package/dist/adapters/space/space.test.d.ts +0 -1
- package/dist/core/auth/api.test.d.ts +0 -1
- package/dist/core/auth/authorize.test.d.ts +0 -1
- package/dist/core/auth/createAuth.test.d.ts +0 -1
- package/dist/core/auth/csrf.test.d.ts +0 -1
- package/dist/core/auth/domains.test.d.ts +0 -1
- package/dist/core/auth/identity.test.d.ts +0 -1
- package/dist/core/auth/lifecycle.test.d.ts +0 -1
- package/dist/core/auth/oauth/oauth.test.d.ts +0 -1
- package/dist/core/auth/redirects.test.d.ts +0 -1
- package/dist/core/auth/routes.test.d.ts +0 -1
- package/dist/core/auth/session.test.d.ts +0 -1
- package/dist/core/auth/spaceTokens.test.d.ts +0 -1
- package/dist/core/auth/throttle.test.d.ts +0 -1
- package/dist/core/auth/tokens.test.d.ts +0 -1
- package/dist/core/auth/totp.test.d.ts +0 -1
- package/dist/core/configSeam.test.d.ts +0 -1
- package/dist/core/createServer.actions.test.d.ts +0 -1
- package/dist/core/createServer.functions.test.d.ts +0 -1
- package/dist/core/createServer.livePages.test.d.ts +0 -1
- package/dist/core/createServer.notFound.test.d.ts +0 -1
- package/dist/core/createServer.oauth.test.d.ts +0 -1
- package/dist/core/createServer.publicData.test.d.ts +0 -1
- package/dist/core/createServer.test.d.ts +0 -1
- package/dist/core/fontStore.test.d.ts +0 -1
- package/dist/core/freePort.test.d.ts +0 -1
- package/dist/core/handlers/csrfMiddleware.test.d.ts +0 -1
- package/dist/core/handlers/handlers.test.d.ts +0 -1
- package/dist/core/handlers/socialRouteHandlers.test.d.ts +0 -1
- package/dist/core/http/dispatcher.test.d.ts +0 -1
- package/dist/core/http/stages/crossSiteWrites.test.d.ts +0 -1
- package/dist/core/http/stages/exchangeRoute.test.d.ts +0 -1
- package/dist/core/http/stages/images.test.d.ts +0 -1
- package/dist/core/http/stages/middlewares.test.d.ts +0 -1
- package/dist/core/http/stages/sessionRenewal.test.d.ts +0 -1
- package/dist/core/http/stages/signInRoute.test.d.ts +0 -1
- package/dist/core/oauth/authorize.test.d.ts +0 -1
- package/dist/core/oauth/register.test.d.ts +0 -1
- package/dist/core/oauth/token.test.d.ts +0 -1
- package/dist/core/requestParser.test.d.ts +0 -1
- package/dist/core/server/baseServer.test.d.ts +0 -1
- package/dist/core/server/closeOnSignals.test.d.ts +0 -1
- package/dist/core/server/drain.test.d.ts +0 -1
- package/dist/core/server/fleet/channel.test.d.ts +0 -1
- package/dist/core/server/fleet/fixtures/fleetServer.d.ts +0 -1
- package/dist/core/server/fleet/fleet.integration.test.d.ts +0 -1
- package/dist/core/server/fleet/relay.test.d.ts +0 -1
- package/dist/core/server/fleet/role.test.d.ts +0 -1
- package/dist/core/server/fleet/supervisor.test.d.ts +0 -1
- package/dist/core/services/resolve.test.d.ts +0 -1
- package/dist/core/staticFiles.test.d.ts +0 -1
- package/dist/env.test.d.ts +0 -1
- package/dist/helpers/atomicFile.test.d.ts +0 -1
- package/dist/helpers/buildResponseHelpers.test.d.ts +0 -1
- package/dist/helpers/buildServerInfo.test.d.ts +0 -1
- package/dist/helpers/cache/CompressedFileCache.test.d.ts +0 -1
- package/dist/helpers/cache/cacheManager.test.d.ts +0 -1
- package/dist/helpers/cache/keys.test.d.ts +0 -1
- package/dist/helpers/compress.test.d.ts +0 -1
- package/dist/helpers/hydrationPayload.test.d.ts +0 -1
- package/dist/helpers/offlineDataLoader.test.d.ts +0 -1
- package/dist/helpers/onAbort.test.d.ts +0 -1
- package/dist/helpers/outboundGuard.test.d.ts +0 -1
- package/dist/helpers/reportReactBuild.test.d.ts +0 -1
- package/dist/helpers/resolveDebugMode.test.d.ts +0 -1
- package/dist/helpers/serverLog.test.d.ts +0 -1
- package/dist/hosts/authoringHost/index.test.d.ts +0 -1
- package/dist/hosts/project/serveProject.test.d.ts +0 -1
- package/dist/layers.test.d.ts +0 -1
- package/dist/middlewares/spaceDeployment.test.d.ts +0 -1
- package/dist/modules/actions/connectorWrite.test.d.ts +0 -1
- package/dist/modules/actions/jobs/failureStreak.test.d.ts +0 -1
- package/dist/modules/actions/jobs/later.test.d.ts +0 -1
- package/dist/modules/actions/jobs/memoryStores.test.d.ts +0 -1
- package/dist/modules/actions/jobs/scheduler.test.d.ts +0 -1
- package/dist/modules/actions/jobs/testing/jobQueueContract.d.ts +0 -25
- package/dist/modules/actions/jobs/worker.test.d.ts +0 -1
- package/dist/modules/actions/moduleFor.test.d.ts +0 -1
- package/dist/modules/actions/runtime/check.test.d.ts +0 -1
- package/dist/modules/actions/runtime/credentials.test.d.ts +0 -1
- package/dist/modules/actions/runtime/email.test.d.ts +0 -1
- package/dist/modules/actions/runtime/fileKv.test.d.ts +0 -1
- package/dist/modules/actions/runtime/flags.test.d.ts +0 -1
- package/dist/modules/actions/runtime/guards.test.d.ts +0 -1
- package/dist/modules/actions/runtime/kvStore.test.d.ts +0 -1
- package/dist/modules/actions/runtime/namespaceKv.test.d.ts +0 -1
- package/dist/modules/actions/runtime/redisKv.integration.test.d.ts +0 -1
- package/dist/modules/actions/runtime/renderResolver.test.d.ts +0 -1
- package/dist/modules/actions/runtime/renderShare.test.d.ts +0 -1
- package/dist/modules/actions/runtime/runAction.test.d.ts +0 -1
- package/dist/modules/actions/runtime/runLogger.test.d.ts +0 -1
- package/dist/modules/actions/runtime/signing.test.d.ts +0 -1
- package/dist/modules/actions/taskCatalog.test.d.ts +0 -1
- package/dist/modules/actions/tasks/db.test.d.ts +0 -1
- package/dist/modules/actions/tasks/email.test.d.ts +0 -1
- package/dist/modules/actions/tasks/http.test.d.ts +0 -1
- package/dist/modules/actions/tasks/kv.test.d.ts +0 -1
- package/dist/modules/actions/transport/callHandler.test.d.ts +0 -1
- package/dist/modules/actions/transport/webhookHandler.test.d.ts +0 -1
- package/dist/modules/connectors/engine.test.d.ts +0 -1
- package/dist/modules/connectors/projection.test.d.ts +0 -1
- package/dist/modules/connectors/resolver.test.d.ts +0 -1
- package/dist/modules/functions/build.test.d.ts +0 -1
- package/dist/modules/functions/load.test.d.ts +0 -1
- package/dist/modules/functions/local.test.d.ts +0 -1
- package/dist/modules/functions/manifest.test.d.ts +0 -1
- package/dist/modules/functions/native.test.d.ts +0 -1
- package/dist/modules/functions/oauth.test.d.ts +0 -1
- package/dist/modules/functions/plugins.test.d.ts +0 -1
- package/dist/modules/functions/routes.test.d.ts +0 -1
- package/dist/modules/functions/runner/remote.test.d.ts +0 -1
- package/dist/modules/functions/sandbox/isolate.test.d.ts +0 -1
- package/dist/modules/functions/testing/tasksOf.d.ts +0 -4
- package/dist/modules/images/imageProxy.test.d.ts +0 -1
- package/dist/modules/images/transform.test.d.ts +0 -1
- package/dist/modules/mongo/stores.integration.test.d.ts +0 -1
- package/dist/modules/mysql/accounts.test.d.ts +0 -1
- package/dist/modules/mysql/jobs/stores.integration.test.d.ts +0 -1
- package/dist/modules/mysql/schema.test.d.ts +0 -1
- package/dist/modules/mysql/store.integration.test.d.ts +0 -1
- package/dist/modules/realtime/realtime.test.d.ts +0 -1
- package/dist/modules/realtime/redisPubSub.test.d.ts +0 -1
- package/dist/modules/realtime/retained.test.d.ts +0 -1
- package/dist/modules/realtime/socket.test.d.ts +0 -1
- package/dist/modules/rsc/connectorRscData.test.d.ts +0 -1
- package/dist/modules/rsc/handler.test.d.ts +0 -1
- package/dist/modules/rsc/publicFileResolver.test.d.ts +0 -1
- package/dist/modules/rsc/resolveRscData.test.d.ts +0 -1
- package/dist/modules/runtime/elsewhere.test.d.ts +0 -1
- package/dist/modules/runtime/entry.test.d.ts +0 -1
- package/dist/modules/runtime/inside.test.d.ts +0 -1
- package/dist/modules/runtime/ownServer.test.d.ts +0 -1
- package/dist/modules/runtime/runtime.test.d.ts +0 -1
- package/dist/modules/sqlite/kv.test.d.ts +0 -1
- package/dist/modules/ssr/draftSession.test.d.ts +0 -1
- package/dist/modules/ssr/loadPluginComponents.test.d.ts +0 -1
- package/dist/modules/ssr/metering.test.d.ts +0 -1
- package/dist/modules/ssr/prepareRender.test.d.ts +0 -1
- package/dist/modules/ssr/redirect.test.d.ts +0 -1
- package/dist/modules/ssr/registerExternalPlugins.test.d.ts +0 -1
- package/dist/modules/ssr/reportMissingPlugins.test.d.ts +0 -1
- package/dist/modules/ssr/resolvePageSeo.test.d.ts +0 -1
- package/dist/modules/ssr/spaceDocument.test.d.ts +0 -1
- package/dist/modules/ssr/template.test.d.ts +0 -1
- package/dist/modules/ssr/testing/offlineData.d.ts +0 -5
- package/dist/modules/ssr/vendor.test.d.ts +0 -1
- package/dist/plugins/compile.test.d.ts +0 -1
- package/dist/plugins/copy.test.d.ts +0 -1
- package/dist/plugins/manager.test.d.ts +0 -1
- package/dist/plugins/validate.test.d.ts +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,122 @@
|
|
|
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
|
+
|
|
3
120
|
## 0.38.20
|
|
4
121
|
|
|
5
122
|
### 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 };
|
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
|
/**
|
|
@@ -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
|
}
|
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
|
*
|
|
@@ -112,6 +137,8 @@ export declare type FunctionContext = {
|
|
|
112
137
|
log: (...values: unknown[]) => void;
|
|
113
138
|
/** OAuth 2.0 through the space's declared connections — see {@link FunctionOAuth}. */
|
|
114
139
|
oauth: FunctionOAuth;
|
|
140
|
+
/** The space's jobs — see {@link FunctionJobs}. */
|
|
141
|
+
jobs: FunctionJobs;
|
|
115
142
|
/** Progress for a caller that asked for a stream — a no-op when nobody did. */
|
|
116
143
|
emit: (chunk: unknown) => void;
|
|
117
144
|
/** Aborted when the run is: cancelled, or out of time. Hand it to what can stop early. */
|
|
@@ -133,6 +160,98 @@ export declare type FunctionFetchInit = {
|
|
|
133
160
|
credential?: string;
|
|
134
161
|
};
|
|
135
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
|
+
|
|
136
255
|
/**
|
|
137
256
|
* OAuth 2.0 on behalf of whoever the space serves, through the connections it declared (`oauth` in its functions): the
|
|
138
257
|
* consent, the code exchanged, the token kept sealed and renewed by the platform. The code never holds a token, as it
|
|
@@ -157,6 +276,12 @@ export declare type FunctionOAuth = {
|
|
|
157
276
|
fetch: (connection: string, url: string | URL, init?: Omit<FunctionFetchInit, 'credential'> & FunctionOAuthOwner) => Promise<Response>;
|
|
158
277
|
/** Forgets the connection — revoked at the provider when it says where — and answers whether there was one. */
|
|
159
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>;
|
|
160
285
|
};
|
|
161
286
|
|
|
162
287
|
/** What a space's functions declare, read from the bundle when it is saved: its tasks, routes and reachable hosts. */
|
|
@@ -182,6 +307,12 @@ declare type FunctionOAuthConnection = {
|
|
|
182
307
|
authorizeParams?: Record<string, string>;
|
|
183
308
|
/** How the app proves who it is to `tokenUrl`: in the body (the default) or as HTTP Basic. */
|
|
184
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;
|
|
185
316
|
};
|
|
186
317
|
|
|
187
318
|
/**
|
|
@@ -199,6 +330,14 @@ export declare type FunctionOAuthStatus = {
|
|
|
199
330
|
expiresAt?: number;
|
|
200
331
|
};
|
|
201
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
|
+
|
|
202
341
|
/**
|
|
203
342
|
* An HTTP endpoint of the space, under `/fn/`: a web-standard handler, the shape every edge runtime runs. The request
|
|
204
343
|
* carries no credentials — `ctx.user` says who is asking — and the response sets no cookies: the host's are the
|
|
@@ -227,6 +366,8 @@ export declare type FunctionsDefinition = {
|
|
|
227
366
|
* (OpenID) or its endpoints, the credential with the app's id and secret, the scopes.
|
|
228
367
|
*/
|
|
229
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>;
|
|
230
371
|
};
|
|
231
372
|
|
|
232
373
|
/**
|
|
@@ -352,6 +493,20 @@ declare type InteractionCallbackParamValues<T extends Record<string, unknown> =
|
|
|
352
493
|
|
|
353
494
|
declare type InteractionParamType = 'boolean' | 'select' | 'text' | 'number' | 'textarea' | 'codemirror-text' | 'codemirror-json' | 'elements';
|
|
354
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
|
+
|
|
355
510
|
/**
|
|
356
511
|
* The lifetime a change writes with: a number of seconds, one worked out from the value written, or none.
|
|
357
512
|
*/
|
package/dist/functions.d.ts
CHANGED
|
@@ -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]
|
|
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]
|
|
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
|
|
@@ -2,9 +2,11 @@ import { loadFunctions, loadFunctionsSource } from "../../modules/functions/load
|
|
|
2
2
|
import { PLUGIN_FUNCTIONS_SOURCE } from "@plitzi/sdk-shared/actions";
|
|
3
3
|
import { isRecord } from "@plitzi/sdk-shared/helpers";
|
|
4
4
|
import path from "node:path";
|
|
5
|
-
import { existsSync, readFileSync, readdirSync, watch } from "node:fs";
|
|
5
|
+
import { existsSync, readFileSync, readdirSync, unwatchFile, watch, watchFile } from "node:fs";
|
|
6
6
|
import { PLUGINS_DIR, PLUGIN_FUNCTIONS_DIR, VENDOR_PLUGINS_DIR, checkPluginFolder, layoutFindingText, pluginEntry, pluginTypeOf, readVendorPlugin } from "@plitzi/sdk-shared/project";
|
|
7
7
|
//#region src/hosts/project/plugins.ts
|
|
8
|
+
/** How often a project with no `src/plugins` looks for it — the time between `plitzi plugin add` and the page. */
|
|
9
|
+
var FOLDER_POLL_MS = 500;
|
|
8
10
|
/**
|
|
9
11
|
* `action: 'compile'` is what makes a folder's plugin SERVER-rendered: the server builds the entry with esbuild, keeps
|
|
10
12
|
* React external so the plugin runs on the one copy the page already has, serves the bundle to the browser AND
|
|
@@ -94,12 +96,26 @@ var projectPlugins = async (root) => {
|
|
|
94
96
|
*/
|
|
95
97
|
var watchProjectPlugins = (root, server, plugins) => {
|
|
96
98
|
const dir = path.join(root, PLUGINS_DIR);
|
|
97
|
-
if (
|
|
99
|
+
if (existsSync(dir)) return watchPluginsFolder(root, dir, server, plugins, false);
|
|
100
|
+
let stop;
|
|
101
|
+
const appeared = (now) => {
|
|
102
|
+
if (stop || !now.isDirectory()) return;
|
|
103
|
+
unwatchFile(dir, appeared);
|
|
104
|
+
stop = watchPluginsFolder(root, dir, server, plugins, true);
|
|
105
|
+
};
|
|
106
|
+
watchFile(dir, { interval: FOLDER_POLL_MS }, appeared);
|
|
107
|
+
return () => {
|
|
108
|
+
unwatchFile(dir, appeared);
|
|
109
|
+
stop?.();
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
/** `late`: the folder appeared after boot, so what it holds already is new — said and registered at once. */
|
|
113
|
+
var watchPluginsFolder = (root, dir, server, plugins, late) => {
|
|
98
114
|
const { names, fromFolders } = plugins;
|
|
99
115
|
let timer;
|
|
100
116
|
const reloading = /* @__PURE__ */ new Map();
|
|
101
117
|
/** What was said of each folder last — at boot, by the layout check — so a save says only what changed. */
|
|
102
|
-
const said = new Map(foldersOf(dir).map((folder) => [folder, checkPluginFolder(root, folder).map(layoutFindingText).join("\n")]));
|
|
118
|
+
const said = new Map(late ? [] : foldersOf(dir).map((folder) => [folder, checkPluginFolder(root, folder).map(layoutFindingText).join("\n")]));
|
|
103
119
|
const sayOf = (folder) => {
|
|
104
120
|
const findings = checkPluginFolder(root, folder);
|
|
105
121
|
const text = findings.map(layoutFindingText).join("\n");
|
|
@@ -151,6 +167,7 @@ var watchProjectPlugins = (root, server, plugins) => {
|
|
|
151
167
|
clearTimeout(timer);
|
|
152
168
|
timer = setTimeout(sync, 300);
|
|
153
169
|
});
|
|
170
|
+
if (late) timer = setTimeout(sync, 300);
|
|
154
171
|
return () => {
|
|
155
172
|
clearTimeout(timer);
|
|
156
173
|
reloading.forEach(clearTimeout);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import "./jobs/memoryQueue.js";
|
|
2
|
+
import "./jobs/schedules.js";
|
|
2
3
|
import "./jobs/scheduler.js";
|
|
3
4
|
import "./runtime/errors.js";
|
|
4
5
|
import "./jobs/worker.js";
|
|
@@ -11,8 +12,9 @@ import { KV_METHODS, createMemoryKv } from "./runtime/memoryKv.js";
|
|
|
11
12
|
import { namespaceKv, spaceKvPatterns } from "./runtime/namespaceKv.js";
|
|
12
13
|
import "./runtime/precheck.js";
|
|
13
14
|
import { createActionRunner } from "./runtime/runAction.js";
|
|
14
|
-
import { createTaskRegistry } from "./tasks/registry.js";
|
|
15
15
|
import { functionCeilings } from "../functions/config.js";
|
|
16
|
+
import { createFunctionJobs } from "../functions/jobs.js";
|
|
17
|
+
import { createTaskRegistry } from "./tasks/registry.js";
|
|
16
18
|
import { readManifest } from "../functions/manifest.js";
|
|
17
19
|
import { createRoutes } from "../functions/routes.js";
|
|
18
20
|
import { createSpaceRegistries, prepareFunctions } from "../functions/space.js";
|
|
@@ -65,7 +67,16 @@ var createActionsModule = (given) => {
|
|
|
65
67
|
};
|
|
66
68
|
const registryForRun = (request) => Object.values(request.entry.document.nodes).every((node) => node.type !== "task" || !node.action || registry.get(node.action)) ? registry : registryFor(request.spaceId, request.at);
|
|
67
69
|
let jobsQueue;
|
|
68
|
-
const {
|
|
70
|
+
const { realtime } = config;
|
|
71
|
+
const functionJobs = createFunctionJobs({
|
|
72
|
+
queue: () => jobsQueue,
|
|
73
|
+
config: config.functions ?? {},
|
|
74
|
+
...config.lookups.getFunctions ? { getFunctions: config.lookups.getFunctions } : {},
|
|
75
|
+
taskContext: () => taskContext,
|
|
76
|
+
...realtime?.publishJob ? { publish: realtime.publishJob } : {},
|
|
77
|
+
maxAttempts: (config.jobs === false ? void 0 : config.jobs?.maxAttempts) ?? 3
|
|
78
|
+
});
|
|
79
|
+
const { runAction, taskContext } = createActionRunner(config, registryForRun, config.fetchImpl, () => jobsQueue, functionJobs);
|
|
69
80
|
const routes = createRoutes({
|
|
70
81
|
config: config.functions ?? {},
|
|
71
82
|
plugins: () => plugins,
|
|
@@ -107,8 +118,10 @@ var createActionsModule = (given) => {
|
|
|
107
118
|
}
|
|
108
119
|
};
|
|
109
120
|
if (config.jobs !== false && config.lookups.listActions) {
|
|
110
|
-
module.jobs = createActionJobs(config.jobs ?? {}, module, config.lookups);
|
|
121
|
+
module.jobs = createActionJobs(config.jobs ?? {}, module, config.lookups, functionJobs);
|
|
111
122
|
jobsQueue = module.jobs.queue;
|
|
123
|
+
const queue = module.jobs.queue;
|
|
124
|
+
realtime?.watchJobs?.((spaceId, jobId) => queue.getJob([spaceId], jobId));
|
|
112
125
|
}
|
|
113
126
|
return module;
|
|
114
127
|
};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Scheduler } from './scheduler';
|
|
2
2
|
import { JobWorker } from './worker';
|
|
3
|
+
import { FunctionJobsService } from '../../functions/jobs';
|
|
3
4
|
import { ActionsModule } from '../index';
|
|
4
5
|
import { ActionJobsConfig, ActionLookups } from '../types';
|
|
5
|
-
import {
|
|
6
|
+
import { JobQueue } from '@plitzi/sdk-shared';
|
|
6
7
|
export type ActionJobs = {
|
|
7
|
-
queue:
|
|
8
|
+
queue: JobQueue;
|
|
8
9
|
scheduler: Scheduler;
|
|
9
10
|
worker: JobWorker;
|
|
10
11
|
start: () => void;
|
|
@@ -23,7 +24,7 @@ export type ActionJobs = {
|
|
|
23
24
|
* works, and the nightly email goes out once per replica. The workers of one server are one replica: they share
|
|
24
25
|
* the primary's queue, and only one of them runs the scheduler and the jobs (`runsFleetJobs`).
|
|
25
26
|
*/
|
|
26
|
-
export declare const createActionJobs: (config: ActionJobsConfig, module: ActionsModule, lookups: ActionLookups) => ActionJobs;
|
|
27
|
+
export declare const createActionJobs: (config: ActionJobsConfig, module: ActionsModule, lookups: ActionLookups, functionJobs?: FunctionJobsService) => ActionJobs;
|
|
27
28
|
export { createMemoryJobQueue } from './memoryQueue';
|
|
28
29
|
export { createScheduler } from './scheduler';
|
|
29
30
|
export { createJobWorker } from './worker';
|
|
@@ -17,7 +17,7 @@ import { fleetStore } from "../../../core/server/fleet/link.js";
|
|
|
17
17
|
* works, and the nightly email goes out once per replica. The workers of one server are one replica: they share
|
|
18
18
|
* the primary's queue, and only one of them runs the scheduler and the jobs (`runsFleetJobs`).
|
|
19
19
|
*/
|
|
20
|
-
var createActionJobs = (config, module, lookups) => {
|
|
20
|
+
var createActionJobs = (config, module, lookups, functionJobs) => {
|
|
21
21
|
const queue = config.queue ?? fleetStore("actions.jobs", JOB_QUEUE_METHODS) ?? createMemoryJobQueue();
|
|
22
22
|
const { produce = true, workers = 4 } = config;
|
|
23
23
|
const scheduler = createScheduler({
|
|
@@ -34,6 +34,7 @@ var createActionJobs = (config, module, lookups) => {
|
|
|
34
34
|
queue,
|
|
35
35
|
lookups,
|
|
36
36
|
module,
|
|
37
|
+
...functionJobs ? { functionJobs } : {},
|
|
37
38
|
workers,
|
|
38
39
|
...config.pollMs ? { pollMs: config.pollMs } : {},
|
|
39
40
|
...config.leaseMs ? { leaseMs: config.leaseMs } : {},
|