@plitzi/sdk-server 0.38.20 → 0.38.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +141 -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/tokens.d.ts +1 -1
- package/dist/core/configSeam.js +12 -2
- package/dist/core/services/functionRoutes.js +7 -2
- package/dist/core/services/realtime.js +5 -2
- package/dist/functions-api.d.ts +176 -3
- 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/hosts/project/serveProject.js +16 -1
- package/dist/modules/actions/index.js +17 -4
- 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/errors.d.ts +9 -1
- package/dist/modules/actions/runtime/errors.js +12 -2
- 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 +9 -1
- package/dist/modules/actions/types.d.ts +22 -6
- package/dist/modules/functions/capabilities.js +124 -13
- package/dist/modules/functions/config.d.ts +20 -0
- package/dist/modules/functions/context.d.ts +2 -2
- package/dist/modules/functions/context.js +16 -3
- package/dist/modules/functions/contract.d.ts +97 -3
- package/dist/modules/functions/driver.js +136 -9
- 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.d.ts +2 -0
- package/dist/modules/functions/manifest.js +37 -4
- package/dist/modules/functions/native.js +2 -1
- package/dist/modules/functions/oauth.d.ts +3 -2
- package/dist/modules/functions/oauth.js +53 -19
- package/dist/modules/functions/protocol.d.ts +98 -7
- package/dist/modules/functions/protocol.js +15 -1
- package/dist/modules/functions/routes.d.ts +9 -1
- package/dist/modules/functions/routes.js +50 -25
- package/dist/modules/functions/runner/messages.d.ts +0 -1
- package/dist/modules/functions/runner/messages.js +46 -5
- package/dist/modules/functions/runner/remote.js +60 -8
- package/dist/modules/functions/runner/service.js +54 -8
- package/dist/modules/functions/sandbox/guest.js +5 -3
- package/dist/modules/functions/sandbox/isolate.js +7 -8
- 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
|
@@ -22,9 +22,15 @@ export declare class ActionRunError extends Error {
|
|
|
22
22
|
* URL, a credential's name, and a page is shown to anybody. This one says, by its type, that its message was written
|
|
23
23
|
* to be read. A run that ends on it answers `status: 'failed'` with the message as `error`, which a page's flow reads
|
|
24
24
|
* as `{{ step.error }}` — the same place a refusal before the run began puts its own.
|
|
25
|
+
*
|
|
26
|
+
* `code` names the refusal for code that catches it (`oauth-not-connected`): what to tell apart by, never the message,
|
|
27
|
+
* which is written for a person and may change.
|
|
25
28
|
*/
|
|
26
29
|
export declare class ActionRefusal extends Error {
|
|
27
|
-
|
|
30
|
+
code?: string;
|
|
31
|
+
constructor(message: string, options?: {
|
|
32
|
+
code?: string;
|
|
33
|
+
});
|
|
28
34
|
}
|
|
29
35
|
/**
|
|
30
36
|
* Whether an error is a refusal — told apart by its NAME, never by `instanceof`: a functions bundle carries its own copy
|
|
@@ -32,3 +38,5 @@ export declare class ActionRefusal extends Error {
|
|
|
32
38
|
* its reason was dropped on the way to the page.
|
|
33
39
|
*/
|
|
34
40
|
export declare const isActionRefusal: (error: unknown) => error is Error;
|
|
41
|
+
/** A refusal's code, when it has one that is a string — read off a refusal made by any copy of the class. */
|
|
42
|
+
export declare const refusalCodeOf: (error: unknown) => string | undefined;
|
|
@@ -26,11 +26,16 @@ var ActionRunError = class extends Error {
|
|
|
26
26
|
* URL, a credential's name, and a page is shown to anybody. This one says, by its type, that its message was written
|
|
27
27
|
* to be read. A run that ends on it answers `status: 'failed'` with the message as `error`, which a page's flow reads
|
|
28
28
|
* as `{{ step.error }}` — the same place a refusal before the run began puts its own.
|
|
29
|
+
*
|
|
30
|
+
* `code` names the refusal for code that catches it (`oauth-not-connected`): what to tell apart by, never the message,
|
|
31
|
+
* which is written for a person and may change.
|
|
29
32
|
*/
|
|
30
33
|
var ActionRefusal = class extends Error {
|
|
31
|
-
|
|
34
|
+
code;
|
|
35
|
+
constructor(message, options) {
|
|
32
36
|
super(message);
|
|
33
37
|
this.name = "ActionRefusal";
|
|
38
|
+
if (options?.code !== void 0) this.code = options.code;
|
|
34
39
|
}
|
|
35
40
|
};
|
|
36
41
|
/**
|
|
@@ -39,5 +44,10 @@ var ActionRefusal = class extends Error {
|
|
|
39
44
|
* its reason was dropped on the way to the page.
|
|
40
45
|
*/
|
|
41
46
|
var isActionRefusal = (error) => error instanceof Error && error.name === "ActionRefusal";
|
|
47
|
+
/** A refusal's code, when it has one that is a string — read off a refusal made by any copy of the class. */
|
|
48
|
+
var refusalCodeOf = (error) => {
|
|
49
|
+
const code = isActionRefusal(error) && "code" in error ? error.code : void 0;
|
|
50
|
+
return typeof code === "string" ? code : void 0;
|
|
51
|
+
};
|
|
42
52
|
//#endregion
|
|
43
|
-
export { ActionRefusal, ActionRunError, isActionRefusal };
|
|
53
|
+
export { ActionRefusal, ActionRunError, isActionRefusal, refusalCodeOf };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { TaskContextRequest } from './taskContext';
|
|
2
|
+
import { FunctionJobsService } from '../../functions/jobs';
|
|
2
3
|
import { ActionRunRequest, ActionRunResult, ActionsConfig, ActionTaskContext, ActionTaskRegistry } from '../types';
|
|
3
|
-
import {
|
|
4
|
+
import { JobQueue } from '@plitzi/sdk-shared';
|
|
4
5
|
export type ActionRunner = {
|
|
5
6
|
runAction: (request: ActionRunRequest) => Promise<ActionRunResult>;
|
|
6
7
|
};
|
|
@@ -18,6 +19,8 @@ export type TaskContextSource = (request: TaskContextRequest, signal: AbortSigna
|
|
|
18
19
|
*/
|
|
19
20
|
export declare const createActionRunner: (config: ActionsConfig, registryFor: (request: ActionRunRequest) => ActionTaskRegistry | Promise<ActionTaskRegistry>, baseFetch?: typeof fetch,
|
|
20
21
|
/** The queue runs set for later go into, read when asked: it is made after the runner, and a server may run none. */
|
|
21
|
-
jobsQueue?: () =>
|
|
22
|
+
jobsQueue?: () => JobQueue | undefined,
|
|
23
|
+
/** The space's jobs, for a function's `ctx.jobs` — made beside the runner, and reading back its `taskContext`. */
|
|
24
|
+
functionJobs?: FunctionJobsService) => ActionRunner & {
|
|
22
25
|
taskContext: TaskContextSource;
|
|
23
26
|
};
|
|
@@ -222,7 +222,7 @@ var runNode = async (node, scope, registry, buildContext) => {
|
|
|
222
222
|
* input contract — lives HERE rather than in a transport, because a deployment mounting its own trigger calls this
|
|
223
223
|
* directly. A check in the endpoint would be a check a custom trigger silently skips.
|
|
224
224
|
*/
|
|
225
|
-
var createActionRunner = (config, registryFor, baseFetch = fetch, jobsQueue = () => void 0) => {
|
|
225
|
+
var createActionRunner = (config, registryFor, baseFetch = fetch, jobsQueue = () => void 0, functionJobs) => {
|
|
226
226
|
const kv = createKvStore(config.kv ?? createMemoryKv());
|
|
227
227
|
const emailSender = createEmailSender({
|
|
228
228
|
...config.email,
|
|
@@ -270,7 +270,8 @@ var createActionRunner = (config, registryFor, baseFetch = fetch, jobsQueue = ()
|
|
|
270
270
|
email: emailSender,
|
|
271
271
|
redactor,
|
|
272
272
|
signing,
|
|
273
|
-
later
|
|
273
|
+
later,
|
|
274
|
+
...functionJobs ? { jobs: functionJobs } : {}
|
|
274
275
|
}, request, signal, runFetch);
|
|
275
276
|
/** The request budget ran out: said on the server's log at once, and in the step that hit it. */
|
|
276
277
|
let budgetSpent;
|
|
@@ -583,7 +584,8 @@ var createActionRunner = (config, registryFor, baseFetch = fetch, jobsQueue = ()
|
|
|
583
584
|
email: emailSender,
|
|
584
585
|
redactor: createRedactor(),
|
|
585
586
|
signing,
|
|
586
|
-
later
|
|
587
|
+
later,
|
|
588
|
+
...functionJobs ? { jobs: functionJobs } : {}
|
|
587
589
|
}, contextRequest, signal, createRunFetch(baseFetch, signal, resolveLimits(config.limits, void 0), lineage))({});
|
|
588
590
|
return {
|
|
589
591
|
runAction,
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { createEmailSender } from './email';
|
|
2
2
|
import { createRedactor } from './scope';
|
|
3
3
|
import { createSigning } from './signing';
|
|
4
|
+
import { FunctionJobsService } from '../../functions/jobs';
|
|
4
5
|
import { LaterDeps } from '../jobs/later';
|
|
5
6
|
import { ActionKvStore, ActionRunRequest, ActionsConfig, ActionTaskContext, ResolvedActionLimits } from '../types';
|
|
7
|
+
import { RunUser } from '@plitzi/sdk-shared';
|
|
6
8
|
/**
|
|
7
9
|
* Counts outbound calls, refuses past the budget, caps what one answer may carry back, and stamps the run's
|
|
8
10
|
* lineage on every one of them.
|
|
@@ -31,12 +33,19 @@ export type TaskContextDeps = {
|
|
|
31
33
|
signing?: ReturnType<typeof createSigning>;
|
|
32
34
|
/** What runs set for later go through: the module's queue, read when asked. */
|
|
33
35
|
later: LaterDeps;
|
|
36
|
+
/** The space's jobs, for a function's `ctx.jobs`. */
|
|
37
|
+
jobs?: FunctionJobsService;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Who and what the context is for — a run's request, or anything shaped like one (a function's route, a job's slice,
|
|
41
|
+
* whose user is who started it and holds no session).
|
|
42
|
+
*/
|
|
43
|
+
export type TaskContextRequest = Pick<ActionRunRequest, 'runId' | 'spaceId' | 'environment' | 'trigger' | 'callerId' | 'at' | 'emit' | 'origin'> & {
|
|
44
|
+
user?: RunUser;
|
|
34
45
|
};
|
|
35
|
-
/** Who and what the context is for — a run's request, or anything shaped like one (a function's route). */
|
|
36
|
-
export type TaskContextRequest = Pick<ActionRunRequest, 'runId' | 'spaceId' | 'environment' | 'trigger' | 'user' | 'callerId' | 'at' | 'emit' | 'origin'>;
|
|
37
46
|
/**
|
|
38
47
|
* What a task runs with — the one place it is made, for a step of a run and for a function answering a route alike:
|
|
39
48
|
* every secret it resolves registered with the redactor, the space's `kv` namespace, the run's outbound budget, the
|
|
40
49
|
* space's channels. Everything but `log`, which is the STEP's: each step keeps what it logged.
|
|
41
50
|
*/
|
|
42
|
-
export declare const taskContextFor: (config: ActionsConfig, { kv, email, redactor, signing, later }: TaskContextDeps, request: TaskContextRequest, signal: AbortSignal, runFetch: typeof fetch) => ((scope: Record<string, unknown>) => Omit<ActionTaskContext, "log">);
|
|
51
|
+
export declare const taskContextFor: (config: ActionsConfig, { kv, email, redactor, signing, later, jobs }: TaskContextDeps, request: TaskContextRequest, signal: AbortSignal, runFetch: typeof fetch) => ((scope: Record<string, unknown>) => Omit<ActionTaskContext, "log">);
|
|
@@ -67,12 +67,14 @@ var createRunFetch = (base, signal, limits, lineage, onBudgetSpent) => {
|
|
|
67
67
|
* every secret it resolves registered with the redactor, the space's `kv` namespace, the run's outbound budget, the
|
|
68
68
|
* space's channels. Everything but `log`, which is the STEP's: each step keeps what it logged.
|
|
69
69
|
*/
|
|
70
|
-
var taskContextFor = (config, { kv, email, redactor, signing, later }, request, signal, runFetch) => {
|
|
70
|
+
var taskContextFor = (config, { kv, email, redactor, signing, later, jobs }, request, signal, runFetch) => {
|
|
71
71
|
const { realtime } = config;
|
|
72
|
+
const oauthCallbackOrigin = config.functions?.oauth?.callbackOrigin;
|
|
72
73
|
const readData = projectDataReader(config.lookups.getData, request.spaceId, request.at);
|
|
73
74
|
return (scope) => ({
|
|
74
75
|
runId: request.runId,
|
|
75
76
|
...request.origin ? { origin: request.origin } : {},
|
|
77
|
+
...oauthCallbackOrigin ? { oauthCallbackOrigin } : {},
|
|
76
78
|
spaceId: request.spaceId,
|
|
77
79
|
environment: request.environment,
|
|
78
80
|
trigger: request.trigger,
|
|
@@ -118,6 +120,12 @@ var taskContextFor = (config, { kv, email, redactor, signing, later }, request,
|
|
|
118
120
|
environment: request.environment,
|
|
119
121
|
...request.at ? { at: request.at } : {}
|
|
120
122
|
}) : {},
|
|
123
|
+
...jobs ? { jobs: (declared) => jobs.forRun({
|
|
124
|
+
spaceId: request.spaceId,
|
|
125
|
+
environment: request.environment,
|
|
126
|
+
...request.at ? { at: request.at } : {},
|
|
127
|
+
...request.user ? { user: request.user } : {}
|
|
128
|
+
}, declared) } : {},
|
|
121
129
|
...realtime ? {
|
|
122
130
|
publish: (topic, type, data) => realtime.publish({
|
|
123
131
|
spaceId: request.spaceId,
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { LaterAnswer, LaterRequest } from './jobs/later';
|
|
2
2
|
import { ActionEmailSender } from './runtime/email';
|
|
3
3
|
import { FunctionsConfig } from '../functions/config';
|
|
4
|
+
import { FunctionJobs } from '../functions/contract';
|
|
4
5
|
import { SpaceFunctions } from '../functions/protocol';
|
|
5
6
|
import { KvChangeLifetime } from './runtime/kvChange';
|
|
6
7
|
import { KvListEntry, KvListPut, KvListPutOptions, KvListRange } from './runtime/kvList';
|
|
7
8
|
import { SpaceSigning } from './runtime/signing';
|
|
8
|
-
import { ActionEmailConfig,
|
|
9
|
+
import { ActionEmailConfig, Job, JobQueue, ActionEntry, ActionLimits, ActionRejectRecord, ActionRunRecord, ActionRunStatus, ActionRunStep, ActionTriggerType, ConnectorManifest, Environment, FunctionJobManifest, FunctionJobView, InteractionCallbackParam, InteractionNode, InteractionNodeStatus, RunUser, Schema, SpaceRevision, SSRServerConfig, SSRUser } from '@plitzi/sdk-shared';
|
|
9
10
|
/** Resolved secret material, as the connector engine already models it. */
|
|
10
11
|
export type ActionCredential = Record<string, string>;
|
|
11
12
|
/**
|
|
@@ -152,7 +153,8 @@ export type ActionTaskContext = {
|
|
|
152
153
|
spaceId: number;
|
|
153
154
|
environment: Environment;
|
|
154
155
|
trigger: ActionTriggerType;
|
|
155
|
-
|
|
156
|
+
/** Who is asking, as the session named them — or, for a job's slice, who started it. Never the session itself. */
|
|
157
|
+
user?: RunUser;
|
|
156
158
|
/**
|
|
157
159
|
* Who is asking, as the transport identified them: `user:<id>` for a session, `ip:<address>` for everyone else,
|
|
158
160
|
* and `render` or `schedule` for the runs no visitor started.
|
|
@@ -204,6 +206,11 @@ export type ActionTaskContext = {
|
|
|
204
206
|
later?: (request: LaterRequest) => Promise<LaterAnswer>;
|
|
205
207
|
/** Drops the runs waiting under `key`, and answers how many. */
|
|
206
208
|
cancelLater?: (key: string) => Promise<number>;
|
|
209
|
+
/**
|
|
210
|
+
* The space's jobs, for code over the jobs it declares (`functions/jobs.ts`) — `undefined` when the server runs no
|
|
211
|
+
* jobs. What a function's `ctx.jobs` goes through.
|
|
212
|
+
*/
|
|
213
|
+
jobs?: (declared: Readonly<Record<string, FunctionJobManifest>>) => FunctionJobs;
|
|
207
214
|
/** Signs with the space's own key (`ActionsConfig.signingSecret`) — `undefined` when the deployment gave none. */
|
|
208
215
|
sign?: SpaceSigning['sign'];
|
|
209
216
|
verify?: SpaceSigning['verify'];
|
|
@@ -212,10 +219,12 @@ export type ActionTaskContext = {
|
|
|
212
219
|
open?: SpaceSigning['open'];
|
|
213
220
|
/**
|
|
214
221
|
* The public origin of the request that started the run (`https://shop.example.com`), as the server resolved it —
|
|
215
|
-
*
|
|
216
|
-
*
|
|
222
|
+
* where a visitor is sent back to (after an OAuth consent). `undefined` for a run no request started: a schedule, a
|
|
223
|
+
* job.
|
|
217
224
|
*/
|
|
218
225
|
origin?: string;
|
|
226
|
+
/** Where OAuth providers send a visitor back, when the deployment fixed it (`functions.oauth.callbackOrigin`). */
|
|
227
|
+
oauthCallbackOrigin?: string;
|
|
219
228
|
/**
|
|
220
229
|
* One file of the space's data (`products.json`), parsed, as of the run's revision — read-only, and refused when
|
|
221
230
|
* the deployment keeps no data (`lookups.getData`, or `dataDir`). One lookup per run, whichever step reads it.
|
|
@@ -236,6 +245,13 @@ export type ActionRealtime = {
|
|
|
236
245
|
spaceId: number;
|
|
237
246
|
environment: string;
|
|
238
247
|
}, topic: string, grant?: string) => Promise<void>;
|
|
248
|
+
/** Says a job of the space's functions as it is now, on its own topic (`$job:<id>`), kept for a page that joins. */
|
|
249
|
+
publishJob?: (space: {
|
|
250
|
+
spaceId: number;
|
|
251
|
+
environment: string;
|
|
252
|
+
}, jobId: string, view: FunctionJobView) => Promise<void>;
|
|
253
|
+
/** Hands the realtime the way to a job, for the door of its topic: who started it, and who its `watch` lets in. */
|
|
254
|
+
watchJobs?: (lookup: (spaceId: number, jobId: string) => Promise<Job | undefined>) => void;
|
|
239
255
|
};
|
|
240
256
|
/**
|
|
241
257
|
* One step a server action can take.
|
|
@@ -353,14 +369,14 @@ export type ActionsConfig = {
|
|
|
353
369
|
*
|
|
354
370
|
* Supplying nothing still schedules — over an in-process queue, which is correct for one replica and silently
|
|
355
371
|
* wrong for two, since each gets its own copy of every schedule. A deployment with more than one supplies a
|
|
356
|
-
* {@link
|
|
372
|
+
* {@link JobQueue} over a store they share.
|
|
357
373
|
*/
|
|
358
374
|
export type ActionJobsConfig = {
|
|
359
375
|
/**
|
|
360
376
|
* Where jobs and schedules live. Omitted → this process's memory: nothing survives a restart, and a second
|
|
361
377
|
* replica produces the same fires all over again.
|
|
362
378
|
*/
|
|
363
|
-
queue?:
|
|
379
|
+
queue?: JobQueue;
|
|
364
380
|
/**
|
|
365
381
|
* How many jobs this replica runs at once. Default 4; `0` makes it a producer that never consumes.
|
|
366
382
|
*
|
|
@@ -129,21 +129,76 @@ var fetchInitOf = (value) => {
|
|
|
129
129
|
};
|
|
130
130
|
};
|
|
131
131
|
var optionalString = (value, what) => value === void 0 || value === null ? void 0 : stringArg(value, what);
|
|
132
|
+
/** The code's number for a request it may cut short — see {@link FunctionCall}. */
|
|
133
|
+
var requestArg = (value) => {
|
|
134
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) throw new CallError("A request is named by a whole number");
|
|
135
|
+
return value;
|
|
136
|
+
};
|
|
137
|
+
var cutShort = (value) => value === void 0 || value === null ? {} : { request: requestArg(value) };
|
|
138
|
+
/** A call to `ctx.jobs`, read into the one method it names: a name and an object for `start`, an id for the rest. */
|
|
139
|
+
var jobsCallOf = (call) => {
|
|
140
|
+
switch (call.method) {
|
|
141
|
+
case "start": {
|
|
142
|
+
const key = optionalString(call.key, "A key");
|
|
143
|
+
if (call.input !== void 0 && !isRecord(call.input)) throw new CallError("A job is handed an object as its input");
|
|
144
|
+
return {
|
|
145
|
+
op: "jobs",
|
|
146
|
+
method: "start",
|
|
147
|
+
name: stringArg(call.name, "A job"),
|
|
148
|
+
input: isRecord(call.input) ? call.input : {},
|
|
149
|
+
...key === void 0 ? {} : { key }
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
case "get":
|
|
153
|
+
case "pause":
|
|
154
|
+
case "resume":
|
|
155
|
+
case "cancel": return {
|
|
156
|
+
op: "jobs",
|
|
157
|
+
method: call.method,
|
|
158
|
+
id: stringArg(call.id, "A job id")
|
|
159
|
+
};
|
|
160
|
+
default: throw new CallError("Not a jobs method the platform answers");
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
/** A job's `save` or `report`, from its slice. */
|
|
164
|
+
var jobCallOf = (call) => {
|
|
165
|
+
if (call.method === "save") return {
|
|
166
|
+
op: "job",
|
|
167
|
+
method: "save",
|
|
168
|
+
state: call.state
|
|
169
|
+
};
|
|
170
|
+
if (call.method === "report") {
|
|
171
|
+
if (typeof call.fraction !== "number" || !Number.isFinite(call.fraction)) throw new CallError("job.report takes how far it is, a number from 0 to 1");
|
|
172
|
+
const step = optionalString(call.step, "A step");
|
|
173
|
+
return {
|
|
174
|
+
op: "job",
|
|
175
|
+
method: "report",
|
|
176
|
+
fraction: call.fraction,
|
|
177
|
+
...step === void 0 ? {} : { step }
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
throw new CallError("Not a job method the platform answers");
|
|
181
|
+
};
|
|
132
182
|
/** A call to `ctx.oauth`, read into the one method it names: what each method takes, and an owner only as a string. */
|
|
133
183
|
var oauthCallOf = (call) => {
|
|
134
184
|
const connection = stringArg(call.connection, "An OAuth connection");
|
|
135
185
|
const owner = optionalString(call.owner, "An OAuth owner");
|
|
136
186
|
const own = owner === void 0 ? {} : { owner };
|
|
137
187
|
switch (call.method) {
|
|
138
|
-
case "connect":
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
188
|
+
case "connect": {
|
|
189
|
+
const params = call.authorizeParams === void 0 ? void 0 : recordArg(call.authorizeParams, "authorizeParams");
|
|
190
|
+
return {
|
|
191
|
+
op: "oauth",
|
|
192
|
+
method: "connect",
|
|
193
|
+
connection,
|
|
194
|
+
returnTo: stringArg(call.returnTo, "returnTo"),
|
|
195
|
+
...params === void 0 ? {} : { authorizeParams: Object.fromEntries(Object.entries(params).map(([key, value]) => [key, stringArg(value, `authorizeParams.${key}`)])) },
|
|
196
|
+
...own
|
|
197
|
+
};
|
|
198
|
+
}
|
|
145
199
|
case "status":
|
|
146
|
-
case "disconnect":
|
|
200
|
+
case "disconnect":
|
|
201
|
+
case "token": return {
|
|
147
202
|
op: "oauth",
|
|
148
203
|
method: call.method,
|
|
149
204
|
connection,
|
|
@@ -157,7 +212,8 @@ var oauthCallOf = (call) => {
|
|
|
157
212
|
connection,
|
|
158
213
|
url: stringArg(call.url, "A URL"),
|
|
159
214
|
init,
|
|
160
|
-
...own
|
|
215
|
+
...own,
|
|
216
|
+
...cutShort(call.request)
|
|
161
217
|
};
|
|
162
218
|
}
|
|
163
219
|
default: throw new CallError("Not an OAuth method the platform answers");
|
|
@@ -198,7 +254,12 @@ var readCall = (value) => {
|
|
|
198
254
|
case "fetch": return {
|
|
199
255
|
op: "fetch",
|
|
200
256
|
url: stringArg(call.url, "A URL"),
|
|
201
|
-
init: fetchInitOf(call.init ?? {})
|
|
257
|
+
init: fetchInitOf(call.init ?? {}),
|
|
258
|
+
...cutShort(call.request)
|
|
259
|
+
};
|
|
260
|
+
case "abort": return {
|
|
261
|
+
op: "abort",
|
|
262
|
+
request: requestArg(call.request)
|
|
202
263
|
};
|
|
203
264
|
case "publish": return {
|
|
204
265
|
op: "publish",
|
|
@@ -249,6 +310,8 @@ var readCall = (value) => {
|
|
|
249
310
|
file: stringArg(call.file, "A file")
|
|
250
311
|
};
|
|
251
312
|
case "oauth": return oauthCallOf(call);
|
|
313
|
+
case "jobs": return jobsCallOf(call);
|
|
314
|
+
case "job": return jobCallOf(call);
|
|
252
315
|
case "log": return {
|
|
253
316
|
op: "log",
|
|
254
317
|
values: Array.isArray(call.values) ? call.values : []
|
|
@@ -260,6 +323,31 @@ var readCall = (value) => {
|
|
|
260
323
|
default: throw new CallError("Not a call the platform answers");
|
|
261
324
|
}
|
|
262
325
|
};
|
|
326
|
+
/** Keyed by the invocation's context: every call of one invocation is answered with the same one. */
|
|
327
|
+
var cutsByRun = /* @__PURE__ */ new WeakMap();
|
|
328
|
+
var cutsOf = (ctx) => {
|
|
329
|
+
const known = cutsByRun.get(ctx);
|
|
330
|
+
if (known) return known;
|
|
331
|
+
const made = {
|
|
332
|
+
live: /* @__PURE__ */ new Map(),
|
|
333
|
+
early: /* @__PURE__ */ new Set()
|
|
334
|
+
};
|
|
335
|
+
cutsByRun.set(ctx, made);
|
|
336
|
+
return made;
|
|
337
|
+
};
|
|
338
|
+
/** The work of a request the code numbered, handed the signal its `abort` fires — even one that arrived first. */
|
|
339
|
+
var cuttable = async (ctx, request, work) => {
|
|
340
|
+
if (request === void 0) return work({});
|
|
341
|
+
const cuts = cutsOf(ctx);
|
|
342
|
+
const controller = new AbortController();
|
|
343
|
+
if (cuts.early.delete(request)) controller.abort();
|
|
344
|
+
cuts.live.set(request, controller);
|
|
345
|
+
try {
|
|
346
|
+
return await work({ signal: controller.signal });
|
|
347
|
+
} finally {
|
|
348
|
+
cuts.live.delete(request);
|
|
349
|
+
}
|
|
350
|
+
};
|
|
263
351
|
/**
|
|
264
352
|
* Answers one call from a space's code with the run's own {@link FunctionContext} — the same object a self-hosted
|
|
265
353
|
* server hands its functions, so the sandbox can do exactly what native code can and not one thing more.
|
|
@@ -267,7 +355,17 @@ var readCall = (value) => {
|
|
|
267
355
|
var answerCall = async (ctx, call) => {
|
|
268
356
|
switch (call.op) {
|
|
269
357
|
case "kv": return kvCall(ctx.kv, call.method, call.args);
|
|
270
|
-
case "fetch": return wireResponseOf(await ctx.fetch(call.url,
|
|
358
|
+
case "fetch": return cuttable(ctx, call.request, async (cut) => wireResponseOf(await ctx.fetch(call.url, {
|
|
359
|
+
...call.init,
|
|
360
|
+
...cut
|
|
361
|
+
})));
|
|
362
|
+
case "abort": {
|
|
363
|
+
const cuts = cutsOf(ctx);
|
|
364
|
+
const live = cuts.live.get(call.request);
|
|
365
|
+
if (live) live.abort();
|
|
366
|
+
else cuts.early.add(call.request);
|
|
367
|
+
return null;
|
|
368
|
+
}
|
|
271
369
|
case "publish": return ctx.publish(call.topic, call.type, call.data);
|
|
272
370
|
case "grant": return ctx.grant(call.topic, call.ttlSeconds);
|
|
273
371
|
case "revoke": return ctx.revoke(call.topic, call.grant);
|
|
@@ -281,16 +379,29 @@ var answerCall = async (ctx, call) => {
|
|
|
281
379
|
switch (call.method) {
|
|
282
380
|
case "connect": return ctx.oauth.connect(call.connection, {
|
|
283
381
|
returnTo: call.returnTo,
|
|
382
|
+
...call.authorizeParams === void 0 ? {} : { authorizeParams: call.authorizeParams },
|
|
284
383
|
...call.owner === void 0 ? {} : { owner: call.owner }
|
|
285
384
|
});
|
|
286
385
|
case "status": return ctx.oauth.status(call.connection, call.owner === void 0 ? {} : { owner: call.owner });
|
|
287
386
|
case "disconnect": return ctx.oauth.disconnect(call.connection, call.owner === void 0 ? {} : { owner: call.owner });
|
|
288
|
-
case "
|
|
387
|
+
case "token": return ctx.oauth.token(call.connection, call.owner === void 0 ? {} : { owner: call.owner });
|
|
388
|
+
case "fetch": return cuttable(ctx, call.request, async (cut) => wireResponseOf(await ctx.oauth.fetch(call.connection, call.url, {
|
|
289
389
|
...call.init,
|
|
390
|
+
...cut,
|
|
290
391
|
...call.owner === void 0 ? {} : { owner: call.owner }
|
|
291
|
-
}));
|
|
392
|
+
})));
|
|
393
|
+
}
|
|
394
|
+
break;
|
|
395
|
+
case "jobs":
|
|
396
|
+
switch (call.method) {
|
|
397
|
+
case "start": return ctx.jobs.start(call.name, call.input, call.key === void 0 ? {} : { key: call.key });
|
|
398
|
+
case "get": return await ctx.jobs.get(call.id) ?? null;
|
|
399
|
+
case "pause": return ctx.jobs.pause(call.id);
|
|
400
|
+
case "resume": return ctx.jobs.resume(call.id);
|
|
401
|
+
case "cancel": return ctx.jobs.cancel(call.id);
|
|
292
402
|
}
|
|
293
403
|
break;
|
|
404
|
+
case "job": throw new CallError("job.save and job.report belong to a job, inside its run");
|
|
294
405
|
case "log":
|
|
295
406
|
ctx.log(...call.values);
|
|
296
407
|
return;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { FunctionsDefinition } from './contract';
|
|
2
|
+
import { FunctionJobLimits } from './jobs';
|
|
2
3
|
import { FunctionLimits, FunctionRunner, FunctionUsage } from './protocol';
|
|
3
4
|
import { FunctionTimeLimits } from '@plitzi/sdk-shared';
|
|
4
5
|
/** One invocation of a space's task, as metering sees it. */
|
|
@@ -39,6 +40,25 @@ export type FunctionsConfig = {
|
|
|
39
40
|
admit?: (spaceId: number) => Promise<string | undefined>;
|
|
40
41
|
/** Told what each invocation spent, however it ended: what `admit` budgets by, and what a deployment meters. */
|
|
41
42
|
onUsage?: (record: FunctionUsageRecord) => void;
|
|
43
|
+
/** The spaces' jobs (`defineFunctions({ jobs })`): what each may spend. */
|
|
44
|
+
jobs?: {
|
|
45
|
+
/**
|
|
46
|
+
* What one space's jobs may spend — its plan's — each unset one `DEFAULT_FUNCTION_JOB_LIMITS`'. `pool` names the
|
|
47
|
+
* spaces whose running jobs count together: an account's.
|
|
48
|
+
*/
|
|
49
|
+
limitsFor?: (spaceId: number) => Promise<Partial<FunctionJobLimits> | undefined>;
|
|
50
|
+
};
|
|
51
|
+
/** The spaces' OAuth connections (`ctx.oauth`). */
|
|
52
|
+
oauth?: {
|
|
53
|
+
/**
|
|
54
|
+
* The origin every provider sends a visitor back to (`<origin>/fn/oauth/callback`), whichever address they opened
|
|
55
|
+
* the space on — the one address to register, which a server reached on several (`localhost`, its loopback, its
|
|
56
|
+
* address on the network) needs. The visitor is then sent on to the address they started from. Only for a server
|
|
57
|
+
* of one space, such as a project's (`serveProject` sets its `publicUrl`): one of many spaces tells them apart by
|
|
58
|
+
* host, and answers each callback on the space's own. Left out, the address the visitor started on.
|
|
59
|
+
*/
|
|
60
|
+
callbackOrigin?: string;
|
|
61
|
+
};
|
|
42
62
|
};
|
|
43
63
|
/** What an invocation gets unless its task asks for more CPU or time. */
|
|
44
64
|
export declare const DEFAULT_FUNCTION_LIMITS: FunctionLimits;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FunctionContext } from './contract';
|
|
2
2
|
import { FunctionScope } from './scope';
|
|
3
3
|
import { ActionTaskContext } from '../actions/types';
|
|
4
|
-
import { FunctionOAuthConnection } from '@plitzi/sdk-shared';
|
|
4
|
+
import { FunctionJobManifest, FunctionOAuthConnection } from '@plitzi/sdk-shared';
|
|
5
5
|
/**
|
|
6
6
|
* Whether `hostname` is one the space declared: exactly, or under a `*.` wildcard (`*.example.com` is every subdomain of
|
|
7
7
|
* it, and not `example.com` itself).
|
|
@@ -17,4 +17,4 @@ export declare const lineOf: (values: readonly unknown[]) => string;
|
|
|
17
17
|
* A self-hosted server hands it to the code directly; the platform answers the sandbox's calls with it. With a `scope`,
|
|
18
18
|
* it is a plugin's code, and gets the plugin's corner of the space (`./scope`).
|
|
19
19
|
*/
|
|
20
|
-
export declare const functionContextFor: (ctx: ActionTaskContext, hosts: readonly string[], scope?: FunctionScope, oauth?: Readonly<Record<string, FunctionOAuthConnection>>) => FunctionContext;
|
|
20
|
+
export declare const functionContextFor: (ctx: ActionTaskContext, hosts: readonly string[], scope?: FunctionScope, oauth?: Readonly<Record<string, FunctionOAuthConnection>>, jobs?: Readonly<Record<string, FunctionJobManifest>>) => FunctionContext;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { prefixKv } from "../actions/runtime/namespaceKv.js";
|
|
2
2
|
import { fetchOutbound } from "../../helpers/outboundGuard.js";
|
|
3
3
|
import { countRate, refusedOver } from "../actions/runtime/rateLimit.js";
|
|
4
|
-
import { noOAuth, oauthFor } from "./oauth.js";
|
|
5
4
|
import { pluginKvPrefix, pluginSigned } from "./scope.js";
|
|
5
|
+
import { noOAuth, oauthFor } from "./oauth.js";
|
|
6
6
|
import { processTwigParam } from "@plitzi/sdk-shared/helpers/twigWrapper";
|
|
7
7
|
//#region src/modules/functions/context.ts
|
|
8
8
|
/**
|
|
@@ -46,7 +46,7 @@ var functionFetch = (ctx, hosts, scope) => async (input, init = {}) => {
|
|
|
46
46
|
method: init.method ?? "GET",
|
|
47
47
|
headers,
|
|
48
48
|
body: init.body === void 0 ? void 0 : render(init.body),
|
|
49
|
-
signal: ctx.signal
|
|
49
|
+
signal: init.signal ? AbortSignal.any([ctx.signal, init.signal]) : ctx.signal
|
|
50
50
|
});
|
|
51
51
|
};
|
|
52
52
|
/**
|
|
@@ -66,6 +66,17 @@ var lineOf = (values) => values.map((value) => {
|
|
|
66
66
|
var unavailable = (what) => () => Promise.reject(/* @__PURE__ */ new Error(`This server has no realtime channels (${what})`));
|
|
67
67
|
var unsigned = () => Promise.reject(/* @__PURE__ */ new Error("This server signs nothing: its actions were given no signingSecret"));
|
|
68
68
|
var noJobs = () => Promise.reject(/* @__PURE__ */ new Error("This server runs no jobs: nothing can be set to run later"));
|
|
69
|
+
/** `ctx.jobs` where there is none to give: a server with no queue, or a plugin's code — the space's jobs are the space's. */
|
|
70
|
+
var noFunctionJobs = (why) => {
|
|
71
|
+
const refused = () => Promise.reject(new Error(why));
|
|
72
|
+
return {
|
|
73
|
+
start: refused,
|
|
74
|
+
get: refused,
|
|
75
|
+
pause: refused,
|
|
76
|
+
resume: refused,
|
|
77
|
+
cancel: refused
|
|
78
|
+
};
|
|
79
|
+
};
|
|
69
80
|
/**
|
|
70
81
|
* A plugin reads none of its space's data. The space keeps there what its pages must not carry, and a plugin was trusted
|
|
71
82
|
* to draw, not with what the space keeps — the same line as its credentials: handed the data, its `fetch` could send
|
|
@@ -77,7 +88,7 @@ var noData = (file) => Promise.reject(/* @__PURE__ */ new Error(`The functions o
|
|
|
77
88
|
* A self-hosted server hands it to the code directly; the platform answers the sandbox's calls with it. With a `scope`,
|
|
78
89
|
* it is a plugin's code, and gets the plugin's corner of the space (`./scope`).
|
|
79
90
|
*/
|
|
80
|
-
var functionContextFor = (ctx, hosts, scope, oauth = {}) => {
|
|
91
|
+
var functionContextFor = (ctx, hosts, scope, oauth = {}, jobs = {}) => {
|
|
81
92
|
const shared = {
|
|
82
93
|
spaceId: ctx.spaceId,
|
|
83
94
|
environment: ctx.environment,
|
|
@@ -102,6 +113,7 @@ var functionContextFor = (ctx, hosts, scope, oauth = {}) => {
|
|
|
102
113
|
later: ctx.later ?? noJobs,
|
|
103
114
|
cancelLater: ctx.cancelLater ?? noJobs,
|
|
104
115
|
data: ctx.data,
|
|
116
|
+
jobs: ctx.jobs ? ctx.jobs(jobs) : noFunctionJobs("This server runs no jobs: its actions have no queue"),
|
|
105
117
|
oauth: oauthFor(ctx, oauth, (url) => {
|
|
106
118
|
if (!hostAllowed(url.hostname, hosts)) throw new Error(`"${url.hostname}" is not among the hosts this space's functions may reach (allow.hosts)`);
|
|
107
119
|
})
|
|
@@ -122,6 +134,7 @@ var functionContextFor = (ctx, hosts, scope, oauth = {}) => {
|
|
|
122
134
|
later: noLater,
|
|
123
135
|
cancelLater: noLater,
|
|
124
136
|
data: noData,
|
|
137
|
+
jobs: noFunctionJobs("The functions of a plugin start none of the jobs of its space"),
|
|
125
138
|
oauth: noOAuth("The functions of a plugin make none of the OAuth connections of its space")
|
|
126
139
|
};
|
|
127
140
|
};
|