@plitzi/sdk-server 0.37.2 → 0.37.4
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 +1170 -0
- package/README.md +100 -7
- package/dist/actions.d.ts +6 -2
- package/dist/actions.js +5 -2
- package/dist/adapters/cloudAdapters.js +4 -3
- package/dist/adapters/jsonAdapters.js +28 -6
- package/dist/adapters/jsonAdapters.test.d.ts +1 -0
- package/dist/auth.d.ts +7 -4
- package/dist/auth.js +8 -6
- package/dist/core/auth/api.d.ts +29 -1
- package/dist/core/auth/api.js +47 -13
- package/dist/core/auth/createAuth.d.ts +4 -0
- package/dist/core/auth/createAuth.js +3 -3
- package/dist/core/auth/credentials.d.ts +3 -0
- package/dist/core/auth/credentials.js +1 -1
- package/dist/core/auth/csrf.d.ts +25 -1
- package/dist/core/auth/csrf.js +29 -4
- package/dist/core/auth/renewal.d.ts +26 -0
- package/dist/core/auth/renewal.js +24 -0
- package/dist/core/auth/routes.js +8 -6
- package/dist/core/auth/session.d.ts +45 -0
- package/dist/core/auth/session.js +47 -1
- package/dist/core/auth/sessionActivity.d.ts +11 -0
- package/dist/core/auth/sessionActivity.js +14 -0
- package/dist/core/auth/throttle.d.ts +15 -0
- package/dist/core/auth/throttle.js +29 -1
- package/dist/core/auth/totp.d.ts +9 -1
- package/dist/core/auth/totp.js +11 -6
- package/dist/core/createServer.actions.test.d.ts +1 -0
- package/dist/core/createServer.d.ts +14 -1
- package/dist/core/createServer.functions.test.d.ts +1 -0
- package/dist/core/createServer.js +22 -12
- package/dist/core/fontStore.js +1 -1
- package/dist/core/handlers/authRouteHandlers.d.ts +1 -1
- package/dist/core/handlers/authRouteHandlers.js +57 -21
- package/dist/core/handlers/csrfMiddleware.d.ts +23 -0
- package/dist/core/handlers/csrfMiddleware.js +31 -7
- package/dist/core/handlers/csrfMiddleware.test.d.ts +1 -0
- package/dist/core/handlers/oauthRouteHandlers.js +5 -3
- package/dist/core/handlers/socialRouteHandlers.d.ts +1 -1
- package/dist/core/handlers/socialRouteHandlers.js +2 -1
- package/dist/core/http/dispatcher.d.ts +9 -1
- package/dist/core/http/dispatcher.js +38 -11
- package/dist/core/http/navigation.d.ts +5 -2
- package/dist/core/http/navigation.js +7 -4
- package/dist/core/http/socketResponse.d.ts +18 -0
- package/dist/core/http/socketResponse.js +59 -0
- package/dist/core/http/sse.d.ts +26 -0
- package/dist/core/http/sse.js +78 -0
- package/dist/core/http/stages/authRoutes.js +3 -1
- package/dist/core/http/stages/exchangeRoute.test.d.ts +1 -0
- package/dist/core/http/stages/middlewares.d.ts +1 -1
- package/dist/core/http/stages/middlewares.js +16 -10
- package/dist/core/http/stages/middlewares.test.d.ts +1 -0
- package/dist/core/http/stages/oauth.js +2 -2
- package/dist/core/http/stages/sessionRenewal.d.ts +16 -0
- package/dist/core/http/stages/sessionRenewal.js +81 -0
- package/dist/core/http/stages/sessionRenewal.test.d.ts +1 -0
- package/dist/core/http/stages/signInRoute.d.ts +2 -0
- package/dist/core/http/stages/signInRoute.js +139 -0
- package/dist/core/http/stages/signInRoute.test.d.ts +1 -0
- package/dist/core/http/types.d.ts +9 -0
- package/dist/core/http/webExchange.d.ts +18 -0
- package/dist/core/http/webExchange.js +53 -0
- package/dist/core/oauth/authorize.js +37 -13
- package/dist/core/oauth/consentPage.js +11 -0
- package/dist/core/oauth/issueContext.d.ts +14 -0
- package/dist/core/oauth/issueContext.js +32 -0
- package/dist/core/oauth/records.d.ts +7 -0
- package/dist/core/oauth/register.d.ts +2 -0
- package/dist/core/oauth/register.js +32 -11
- package/dist/core/oauth/register.test.d.ts +1 -0
- package/dist/core/oauth/token.js +21 -6
- package/dist/core/oauth/token.test.d.ts +1 -0
- package/dist/core/requestParser.d.ts +4 -0
- package/dist/core/requestParser.js +14 -7
- package/dist/core/sdkAssets.js +1 -1
- package/dist/core/server/baseServer.d.ts +10 -0
- package/dist/core/server/baseServer.js +42 -11
- package/dist/core/server/closeOnSignals.js +4 -3
- package/dist/core/server/drain.d.ts +18 -0
- package/dist/core/server/drain.js +62 -0
- package/dist/core/server/drain.test.d.ts +1 -0
- package/dist/core/server/fleet/channel.d.ts +103 -0
- package/dist/core/server/fleet/channel.js +191 -0
- package/dist/core/server/fleet/channel.test.d.ts +1 -0
- package/dist/core/server/fleet/fixtures/fleetServer.d.ts +1 -0
- package/dist/core/server/fleet/fleet.integration.test.d.ts +1 -0
- package/dist/core/server/fleet/link.d.ts +23 -0
- package/dist/core/server/fleet/link.js +70 -0
- package/dist/core/server/fleet/relay.d.ts +11 -0
- package/dist/core/server/fleet/relay.js +104 -0
- package/dist/core/server/fleet/relay.test.d.ts +1 -0
- package/dist/core/server/fleet/role.d.ts +46 -0
- package/dist/core/server/fleet/role.js +59 -0
- package/dist/core/server/fleet/role.test.d.ts +1 -0
- package/dist/core/server/fleet/stores.d.ts +7 -0
- package/dist/core/server/fleet/stores.js +19 -0
- package/dist/core/server/fleet/supervisor.d.ts +26 -0
- package/dist/core/server/fleet/supervisor.js +108 -0
- package/dist/core/server/fleet/supervisor.test.d.ts +1 -0
- package/dist/core/server/pageServer.js +34 -5
- package/dist/core/services/action.js +10 -2
- package/dist/core/services/functionRoutes.d.ts +9 -0
- package/dist/core/services/functionRoutes.js +47 -0
- package/dist/core/services/realtime.d.ts +8 -0
- package/dist/core/services/realtime.js +57 -0
- package/dist/core/services/registry.js +6 -2
- package/dist/core/staticFiles.js +12 -4
- package/dist/core/staticFiles.test.d.ts +1 -0
- package/dist/core/transports.d.ts +13 -3
- package/dist/core/transports.js +14 -5
- package/dist/functions-api.d.ts +281 -0
- package/dist/functions.d.ts +19 -0
- package/dist/functions.js +5 -0
- package/dist/functionsRunner.d.ts +15 -0
- package/dist/functionsRunner.js +6 -0
- package/dist/handlers.d.ts +2 -2
- package/dist/handlers.js +2 -2
- package/dist/helpers/atomicFile.d.ts +10 -0
- package/dist/helpers/atomicFile.js +33 -0
- package/dist/helpers/atomicFile.test.d.ts +1 -0
- package/dist/helpers/buildResponseHelpers.js +35 -11
- package/dist/helpers/buildServerInfo.js +4 -2
- package/dist/helpers/buildServerInfo.test.d.ts +1 -0
- package/dist/helpers/cache/CompressedFileCache.d.ts +18 -0
- package/dist/helpers/cache/CompressedFileCache.js +44 -0
- package/dist/helpers/cache/CompressedFileCache.test.d.ts +1 -0
- package/dist/helpers/cache/cacheManager.d.ts +1 -1
- package/dist/helpers/cache/cacheManager.js +2 -1
- package/dist/helpers/cache/cacheManager.test.d.ts +1 -0
- package/dist/helpers/cache/index.d.ts +1 -1
- package/dist/helpers/cache/keys.d.ts +15 -1
- package/dist/helpers/cache/keys.js +47 -5
- package/dist/helpers/cache/serverCaches.d.ts +7 -1
- package/dist/helpers/compress.d.ts +3 -1
- package/dist/helpers/compress.js +11 -3
- package/dist/helpers/hydrationPayload.d.ts +11 -0
- package/dist/helpers/hydrationPayload.js +51 -0
- package/dist/helpers/hydrationPayload.test.d.ts +1 -0
- package/dist/helpers/metrics.d.ts +1 -1
- package/dist/helpers/metrics.js +3 -2
- package/dist/helpers/outboundGuard.d.ts +14 -6
- package/dist/helpers/outboundGuard.js +132 -8
- package/dist/helpers/paintedCookie.d.ts +8 -0
- package/dist/helpers/paintedCookie.js +13 -0
- package/dist/helpers/reportReactBuild.d.ts +9 -0
- package/dist/helpers/reportReactBuild.js +18 -0
- package/dist/helpers/reportReactBuild.test.d.ts +1 -0
- package/dist/helpers/serverLog.d.ts +25 -1
- package/dist/helpers/serverLog.js +68 -3
- package/dist/helpers/serverLog.test.d.ts +1 -0
- package/dist/helpers/wsFrame.d.ts +3 -0
- package/dist/helpers/wsFrame.js +5 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.js +5 -2
- package/dist/kernel.d.ts +2 -1
- package/dist/kernel.js +3 -2
- package/dist/modules/actions/connectorWrite.js +2 -1
- package/dist/modules/actions/index.d.ts +29 -10
- package/dist/modules/actions/index.js +43 -6
- package/dist/modules/actions/jobs/failureStreak.d.ts +17 -0
- package/dist/modules/actions/jobs/failureStreak.js +47 -0
- package/dist/modules/actions/jobs/failureStreak.test.d.ts +1 -0
- package/dist/modules/actions/jobs/index.d.ts +2 -1
- package/dist/modules/actions/jobs/index.js +5 -3
- package/dist/modules/actions/jobs/memoryQueue.d.ts +3 -0
- package/dist/modules/actions/jobs/memoryQueue.js +17 -1
- package/dist/modules/actions/jobs/scheduler.d.ts +2 -0
- package/dist/modules/actions/jobs/scheduler.js +12 -7
- package/dist/modules/actions/jobs/worker.d.ts +3 -1
- package/dist/modules/actions/jobs/worker.js +9 -4
- package/dist/modules/actions/moduleFor.js +5 -2
- package/dist/modules/actions/runtime/errors.d.ts +12 -0
- package/dist/modules/actions/runtime/errors.js +16 -1
- package/dist/modules/actions/runtime/kvChange.d.ts +27 -0
- package/dist/modules/actions/runtime/kvChange.js +23 -0
- package/dist/modules/actions/runtime/kvList.d.ts +51 -0
- package/dist/modules/actions/runtime/kvList.js +52 -0
- package/dist/modules/actions/runtime/kvStore.d.ts +8 -0
- package/dist/modules/actions/runtime/kvStore.js +46 -20
- package/dist/modules/actions/runtime/memoryKv.d.ts +3 -0
- package/dist/modules/actions/runtime/memoryKv.js +19 -1
- package/dist/modules/actions/runtime/namespaceKv.d.ts +4 -6
- package/dist/modules/actions/runtime/namespaceKv.js +15 -3
- package/dist/modules/actions/runtime/namespaceKv.test.d.ts +1 -0
- package/dist/modules/actions/runtime/precheck.js +4 -8
- package/dist/modules/actions/runtime/rateLimit.d.ts +19 -0
- package/dist/modules/actions/runtime/rateLimit.js +19 -0
- package/dist/modules/actions/runtime/redisKv.d.ts +27 -0
- package/dist/modules/actions/runtime/redisKv.integration.test.d.ts +1 -0
- package/dist/modules/actions/runtime/redisKv.js +46 -0
- package/dist/modules/actions/runtime/report.js +2 -1
- package/dist/modules/actions/runtime/runAction.d.ts +10 -2
- package/dist/modules/actions/runtime/runAction.js +52 -116
- package/dist/modules/actions/runtime/runLogger.d.ts +5 -0
- package/dist/modules/actions/runtime/runLogger.js +8 -2
- package/dist/modules/actions/runtime/signing.d.ts +20 -0
- package/dist/modules/actions/runtime/signing.js +25 -0
- package/dist/modules/actions/runtime/signing.test.d.ts +1 -0
- package/dist/modules/actions/runtime/taskContext.d.ts +33 -0
- package/dist/modules/actions/runtime/taskContext.js +124 -0
- package/dist/modules/actions/tasks/builtins.js +5 -1
- package/dist/modules/actions/tasks/flow.js +81 -10
- package/dist/modules/actions/tasks/helpers.js +2 -2
- package/dist/modules/actions/tasks/http.js +2 -3
- package/dist/modules/actions/tasks/kv.js +39 -0
- package/dist/modules/actions/tasks/list.d.ts +2 -0
- package/dist/modules/actions/tasks/list.js +145 -0
- package/dist/modules/actions/tasks/realtime.d.ts +2 -0
- package/dist/modules/actions/tasks/realtime.js +104 -0
- package/dist/modules/actions/tasks/registry.d.ts +10 -1
- package/dist/modules/actions/tasks/registry.js +17 -6
- package/dist/modules/actions/transport/callHandler.js +5 -2
- package/dist/modules/actions/transport/catalogHandler.d.ts +5 -2
- package/dist/modules/actions/transport/catalogHandler.js +3 -2
- package/dist/modules/actions/transport/stream.d.ts +4 -5
- package/dist/modules/actions/transport/stream.js +12 -76
- package/dist/modules/actions/transport/webhookHandler.js +4 -3
- package/dist/modules/actions/types.d.ts +86 -3
- package/dist/modules/connectors/engine.js +3 -5
- package/dist/modules/functions/build.d.ts +22 -0
- package/dist/modules/functions/build.js +122 -0
- package/dist/modules/functions/build.test.d.ts +1 -0
- package/dist/modules/functions/capabilities.d.ts +22 -0
- package/dist/modules/functions/capabilities.js +228 -0
- package/dist/modules/functions/config.d.ts +34 -0
- package/dist/modules/functions/config.js +24 -0
- package/dist/modules/functions/context.d.ts +17 -0
- package/dist/modules/functions/context.js +88 -0
- package/dist/modules/functions/contract.d.ts +121 -0
- package/dist/modules/functions/contract.js +9 -0
- package/dist/modules/functions/driver.d.ts +36 -0
- package/dist/modules/functions/driver.js +150 -0
- package/dist/modules/functions/load.d.ts +15 -0
- package/dist/modules/functions/load.js +45 -0
- package/dist/modules/functions/load.test.d.ts +1 -0
- package/dist/modules/functions/local.d.ts +29 -0
- package/dist/modules/functions/local.js +61 -0
- package/dist/modules/functions/local.test.d.ts +1 -0
- package/dist/modules/functions/manifest.d.ts +24 -0
- package/dist/modules/functions/manifest.js +163 -0
- package/dist/modules/functions/manifest.test.d.ts +1 -0
- package/dist/modules/functions/native.d.ts +8 -0
- package/dist/modules/functions/native.js +21 -0
- package/dist/modules/functions/native.test.d.ts +1 -0
- package/dist/modules/functions/protocol.d.ts +216 -0
- package/dist/modules/functions/protocol.js +18 -0
- package/dist/modules/functions/routes.d.ts +36 -0
- package/dist/modules/functions/routes.js +181 -0
- package/dist/modules/functions/routes.test.d.ts +1 -0
- package/dist/modules/functions/runner/messages.d.ts +5 -0
- package/dist/modules/functions/runner/messages.js +188 -0
- package/dist/modules/functions/runner/remote.d.ts +19 -0
- package/dist/modules/functions/runner/remote.js +116 -0
- package/dist/modules/functions/runner/remote.test.d.ts +1 -0
- package/dist/modules/functions/runner/service.d.ts +32 -0
- package/dist/modules/functions/runner/service.js +209 -0
- package/dist/modules/functions/sandbox/guest.d.ts +45 -0
- package/dist/modules/functions/sandbox/guest.js +660 -0
- package/dist/modules/functions/sandbox/isolate.d.ts +37 -0
- package/dist/modules/functions/sandbox/isolate.js +347 -0
- package/dist/modules/functions/sandbox/isolate.test.d.ts +1 -0
- package/dist/modules/functions/sandbox/prelude.d.ts +2 -0
- package/dist/modules/functions/sandbox/prelude.js +49 -0
- package/dist/modules/functions/space.d.ts +40 -0
- package/dist/modules/functions/space.js +162 -0
- package/dist/modules/functions/testing/tasksOf.d.ts +4 -0
- package/dist/modules/functions/tryEntry.d.ts +9 -0
- package/dist/modules/functions/tryEntry.js +49 -0
- package/dist/modules/mongo/kv.js +31 -0
- package/dist/modules/mysql/accounts.js +19 -9
- package/dist/modules/mysql/index.d.ts +2 -1
- package/dist/modules/mysql/jobs/index.d.ts +1 -1
- package/dist/modules/mysql/jobs/kv.js +30 -0
- package/dist/modules/mysql/jobs/schema.d.ts +9 -0
- package/dist/modules/mysql/jobs/schema.js +21 -4
- package/dist/modules/mysql/schema.js +25 -0
- package/dist/modules/mysql/sessions.d.ts +1 -11
- package/dist/modules/mysql/sessions.js +6 -1
- package/dist/modules/realtime/declarations.d.ts +11 -0
- package/dist/modules/realtime/declarations.js +26 -0
- package/dist/modules/realtime/grants.d.ts +23 -0
- package/dist/modules/realtime/grants.js +61 -0
- package/dist/modules/realtime/handlers.d.ts +74 -0
- package/dist/modules/realtime/handlers.js +224 -0
- package/dist/modules/realtime/hub.d.ts +62 -0
- package/dist/modules/realtime/hub.js +141 -0
- package/dist/modules/realtime/index.d.ts +51 -0
- package/dist/modules/realtime/index.js +62 -0
- package/dist/modules/realtime/memoryPubSub.d.ts +10 -0
- package/dist/modules/realtime/memoryPubSub.js +43 -0
- package/dist/modules/realtime/realtime.test.d.ts +1 -0
- package/dist/modules/realtime/redisPubSub.d.ts +24 -0
- package/dist/modules/realtime/redisPubSub.js +36 -0
- package/dist/modules/realtime/redisPubSub.test.d.ts +1 -0
- package/dist/modules/realtime/socket.d.ts +25 -0
- package/dist/modules/realtime/socket.js +122 -0
- package/dist/modules/realtime/socket.test.d.ts +1 -0
- package/dist/modules/rsc/handler.d.ts +16 -0
- package/dist/modules/rsc/handler.js +17 -10
- package/dist/modules/rsc/handler.test.d.ts +1 -0
- package/dist/modules/rsc/resolveRscData.js +2 -1
- package/dist/modules/runtime/bundle.d.ts +24 -0
- package/dist/modules/runtime/bundle.js +102 -0
- package/dist/modules/runtime/contract.d.ts +37 -0
- package/dist/modules/runtime/contract.js +21 -0
- package/dist/modules/runtime/entry.test.d.ts +1 -0
- package/dist/modules/runtime/host.d.ts +38 -0
- package/dist/modules/runtime/host.js +68 -0
- package/dist/modules/runtime/inside.d.ts +15 -0
- package/dist/modules/runtime/inside.js +47 -0
- package/dist/modules/runtime/inside.test.d.ts +1 -0
- package/dist/modules/runtime/runner.d.ts +11 -0
- package/dist/modules/runtime/runner.js +38 -0
- package/dist/modules/runtime/runtime.test.d.ts +1 -0
- package/dist/modules/runtime/stages.d.ts +50 -0
- package/dist/modules/runtime/stages.js +117 -0
- package/dist/modules/ssr/Component.d.ts +3 -1
- package/dist/modules/ssr/Component.js +2 -1
- package/dist/modules/ssr/handler.js +10 -2
- package/dist/modules/ssr/loadPluginComponents.js +2 -1
- package/dist/modules/ssr/prepareRender.js +39 -10
- package/dist/modules/ssr/preview.d.ts +3 -0
- package/dist/modules/ssr/preview.js +17 -7
- package/dist/modules/ssr/redirect.test.d.ts +1 -0
- package/dist/modules/ssr/registerExternalPlugins.d.ts +6 -1
- package/dist/modules/ssr/registerExternalPlugins.js +19 -16
- package/dist/modules/ssr/registerExternalPlugins.test.d.ts +1 -0
- package/dist/modules/ssr/reportMissingPlugins.d.ts +9 -0
- package/dist/modules/ssr/reportMissingPlugins.js +24 -0
- package/dist/modules/ssr/reportMissingPlugins.test.d.ts +1 -0
- package/dist/modules/ssr/streamBody.d.ts +2 -2
- package/dist/modules/ssr/streamBody.js +4 -1
- package/dist/modules/ssr/template.js +1 -1
- package/dist/modules/ssr/views/template.ejs +8 -5
- package/dist/mysql.d.ts +1 -1
- package/dist/mysql.js +2 -2
- package/dist/oauth.js +2 -2
- package/dist/plugins/compile.js +9 -4
- package/dist/plugins/copy.js +3 -3
- package/dist/plugins/manager.d.ts +35 -3
- package/dist/plugins/manager.js +109 -38
- package/dist/runtime.d.ts +15 -0
- package/dist/runtime.js +7 -0
- package/package.json +39 -8
- package/skills/plitzi-authoring/SKILL.md +98 -14
- package/skills/plitzi-authoring/reference/accessibility.md +111 -0
- package/skills/plitzi-authoring/reference/authoring-errors.md +70 -0
- package/skills/plitzi-authoring/reference/data-and-visibility.md +84 -18
- package/skills/plitzi-authoring/reference/elements-and-styles.md +61 -7
- package/skills/plitzi-authoring/reference/flows.md +108 -17
- package/skills/plitzi-authoring/reference/lists.md +74 -0
- package/skills/plitzi-authoring/reference/performance.md +67 -0
- package/skills/plitzi-authoring/reference/plugins.md +167 -0
- package/skills/plitzi-authoring/reference/review-checklist.md +19 -2
- package/skills/plitzi-authoring/reference/templates.md +67 -27
- package/skills/plitzi-authoring/reference/testing.md +72 -5
- package/skills/plitzi-authoring/reference/validation.md +73 -0
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { ActionRefusal } from "../runtime/errors.js";
|
|
1
2
|
import onAbort from "../../../helpers/onAbort.js";
|
|
3
|
+
import { countRate } from "../runtime/rateLimit.js";
|
|
2
4
|
//#region src/modules/actions/tasks/flow.ts
|
|
3
5
|
var MAX_DELAY_MS = 5e3;
|
|
4
6
|
/**
|
|
@@ -30,19 +32,31 @@ var delay = {
|
|
|
30
32
|
return { waited: waitMs };
|
|
31
33
|
}
|
|
32
34
|
};
|
|
33
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* Ends the run as failed, on purpose. The message reaches the trace — and, with `tellCaller`, the caller too, as the
|
|
37
|
+
* run's `error`: a guard whose reason the page should show ("that name is taken") rather than a generic failure.
|
|
38
|
+
*/
|
|
34
39
|
var fail = {
|
|
35
40
|
namespace: "flow",
|
|
36
41
|
action: "fail",
|
|
37
42
|
title: "Fail",
|
|
38
|
-
params: {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
params: {
|
|
44
|
+
message: {
|
|
45
|
+
type: "text",
|
|
46
|
+
canBind: true,
|
|
47
|
+
defaultValue: "",
|
|
48
|
+
label: "Message"
|
|
49
|
+
},
|
|
50
|
+
tellCaller: {
|
|
51
|
+
type: "boolean",
|
|
52
|
+
canBind: true,
|
|
53
|
+
defaultValue: false,
|
|
54
|
+
label: "Tell the caller why"
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
run: ({ message, tellCaller }) => {
|
|
58
|
+
const text = message || "Action failed";
|
|
59
|
+
throw tellCaller === true || tellCaller === "true" ? new ActionRefusal(text) : new Error(text);
|
|
46
60
|
}
|
|
47
61
|
};
|
|
48
62
|
/**
|
|
@@ -121,7 +135,64 @@ var flowTasks = [
|
|
|
121
135
|
delay,
|
|
122
136
|
fail,
|
|
123
137
|
output,
|
|
124
|
-
onFailure
|
|
138
|
+
onFailure,
|
|
139
|
+
{
|
|
140
|
+
namespace: "flow",
|
|
141
|
+
action: "rateLimit",
|
|
142
|
+
title: "Rate Limit",
|
|
143
|
+
params: {
|
|
144
|
+
bucket: {
|
|
145
|
+
type: "text",
|
|
146
|
+
canBind: true,
|
|
147
|
+
defaultValue: "",
|
|
148
|
+
label: "Name (what is counted — \"comments\")"
|
|
149
|
+
},
|
|
150
|
+
limit: {
|
|
151
|
+
type: "text",
|
|
152
|
+
canBind: true,
|
|
153
|
+
defaultValue: "10",
|
|
154
|
+
label: "At most"
|
|
155
|
+
},
|
|
156
|
+
windowSeconds: {
|
|
157
|
+
type: "text",
|
|
158
|
+
canBind: true,
|
|
159
|
+
defaultValue: "60",
|
|
160
|
+
label: "Every (seconds)"
|
|
161
|
+
},
|
|
162
|
+
per: {
|
|
163
|
+
type: "select",
|
|
164
|
+
canBind: true,
|
|
165
|
+
defaultValue: "caller",
|
|
166
|
+
label: "Counted",
|
|
167
|
+
options: [{
|
|
168
|
+
label: "For each person",
|
|
169
|
+
value: "caller"
|
|
170
|
+
}, {
|
|
171
|
+
label: "For everyone together",
|
|
172
|
+
value: "everyone"
|
|
173
|
+
}]
|
|
174
|
+
},
|
|
175
|
+
message: {
|
|
176
|
+
type: "text",
|
|
177
|
+
canBind: true,
|
|
178
|
+
defaultValue: "",
|
|
179
|
+
label: "Refusal (what the caller is told)"
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
run: async ({ bucket, limit, windowSeconds, per, message }, ctx) => {
|
|
183
|
+
const perSeconds = Number(windowSeconds);
|
|
184
|
+
const { allowed, count, remaining } = await countRate(ctx.kv, ctx.callerId, bucket, {
|
|
185
|
+
most: Number(limit),
|
|
186
|
+
perSeconds,
|
|
187
|
+
per: per === "everyone" ? "everyone" : "caller"
|
|
188
|
+
});
|
|
189
|
+
if (!allowed) throw new ActionRefusal(message || `Too many at once — try again in ${String(perSeconds)} seconds`);
|
|
190
|
+
return {
|
|
191
|
+
count,
|
|
192
|
+
remaining
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
}
|
|
125
196
|
];
|
|
126
197
|
var streamTasks = [emit];
|
|
127
198
|
//#endregion
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { processTwigParam } from "@plitzi/sdk-shared/helpers/twigWrapper";
|
|
2
2
|
//#region src/modules/actions/tasks/helpers.ts
|
|
3
3
|
/**
|
|
4
4
|
* Renders a task's own params, with its own credential in scope.
|
|
@@ -22,7 +22,7 @@ var renderTaskParams = async (params, ctx, credentialId) => {
|
|
|
22
22
|
...credential ? { credential } : {}
|
|
23
23
|
};
|
|
24
24
|
return Object.entries(params).reduce((acum, [key, value]) => {
|
|
25
|
-
acum[key] = typeof value === "string" ?
|
|
25
|
+
acum[key] = typeof value === "string" ? processTwigParam(value, scope) : value;
|
|
26
26
|
return acum;
|
|
27
27
|
}, {});
|
|
28
28
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { fetchOutbound } from "../../../helpers/outboundGuard.js";
|
|
2
2
|
import { renderTaskParams } from "./helpers.js";
|
|
3
3
|
//#region src/modules/actions/tasks/http.ts
|
|
4
4
|
var BODYLESS = ["GET", "HEAD"];
|
|
@@ -81,7 +81,6 @@ var httpTasks = [{
|
|
|
81
81
|
} catch {
|
|
82
82
|
throw new Error("Request URL is not a valid absolute URL");
|
|
83
83
|
}
|
|
84
|
-
await assertOutboundAllowed(url);
|
|
85
84
|
const headers = Object.entries(parseJsonParam(params.headers, "Headers")).reduce((acum, [key, value]) => {
|
|
86
85
|
acum[key] = typeof value === "string" ? value : JSON.stringify(value);
|
|
87
86
|
return acum;
|
|
@@ -89,7 +88,7 @@ var httpTasks = [{
|
|
|
89
88
|
const hasBody = !BODYLESS.includes(method) && params.body !== "";
|
|
90
89
|
const declaresContentType = Object.keys(headers).some((name) => name.toLowerCase() === "content-type");
|
|
91
90
|
if (hasBody && !declaresContentType) headers["Content-Type"] = "application/json";
|
|
92
|
-
const response = await ctx.fetch
|
|
91
|
+
const response = await fetchOutbound(ctx.fetch, url, {
|
|
93
92
|
method,
|
|
94
93
|
headers,
|
|
95
94
|
body: hasBody ? JSON.stringify(parseJsonParam(params.body, "Body")) : void 0,
|
|
@@ -50,6 +50,45 @@ var kvTasks = [
|
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
52
|
},
|
|
53
|
+
{
|
|
54
|
+
namespace: "kv",
|
|
55
|
+
action: "setIf",
|
|
56
|
+
title: "Write Value If Unchanged",
|
|
57
|
+
params: {
|
|
58
|
+
key: {
|
|
59
|
+
type: "text",
|
|
60
|
+
canBind: true,
|
|
61
|
+
defaultValue: "",
|
|
62
|
+
label: "Key"
|
|
63
|
+
},
|
|
64
|
+
expected: {
|
|
65
|
+
type: "codemirror-text",
|
|
66
|
+
canBind: true,
|
|
67
|
+
defaultValue: "",
|
|
68
|
+
label: "Only if it holds (the value read; empty = only if it holds nothing)"
|
|
69
|
+
},
|
|
70
|
+
value: {
|
|
71
|
+
type: "codemirror-text",
|
|
72
|
+
canBind: true,
|
|
73
|
+
defaultValue: "",
|
|
74
|
+
label: "Value"
|
|
75
|
+
},
|
|
76
|
+
ttlSeconds: {
|
|
77
|
+
type: "text",
|
|
78
|
+
canBind: true,
|
|
79
|
+
defaultValue: "",
|
|
80
|
+
label: "TTL (seconds)"
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
run: async ({ key, expected, value, ttlSeconds }, ctx) => {
|
|
84
|
+
const ttl = ttlSeconds === "" ? void 0 : toNumber(ttlSeconds, 0) || void 0;
|
|
85
|
+
return {
|
|
86
|
+
key,
|
|
87
|
+
written: await ctx.kv.swap(key, expected === "" || expected === null ? void 0 : expected, value, ttl),
|
|
88
|
+
value: await ctx.kv.get(key) ?? null
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
},
|
|
53
92
|
{
|
|
54
93
|
namespace: "kv",
|
|
55
94
|
action: "increment",
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import "../runtime/kvList.js";
|
|
2
|
+
//#region src/modules/actions/tasks/list.ts
|
|
3
|
+
var toNumber = (value, fallback) => {
|
|
4
|
+
if (value === void 0 || value === "") return fallback;
|
|
5
|
+
const parsed = typeof value === "number" ? value : Number(value);
|
|
6
|
+
return Number.isFinite(parsed) ? parsed : fallback;
|
|
7
|
+
};
|
|
8
|
+
/** What a typed value means: JSON when it reads as JSON, the text itself when it does not. A bound value as it is. */
|
|
9
|
+
var valueOf = (value) => {
|
|
10
|
+
if (typeof value !== "string") return value ?? null;
|
|
11
|
+
if (value === "") return null;
|
|
12
|
+
try {
|
|
13
|
+
return JSON.parse(value);
|
|
14
|
+
} catch {
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
var nameParam = {
|
|
19
|
+
type: "text",
|
|
20
|
+
canBind: true,
|
|
21
|
+
defaultValue: "",
|
|
22
|
+
label: "List"
|
|
23
|
+
};
|
|
24
|
+
var listTasks = [
|
|
25
|
+
{
|
|
26
|
+
namespace: "list",
|
|
27
|
+
action: "put",
|
|
28
|
+
title: "Add To List",
|
|
29
|
+
params: {
|
|
30
|
+
list: nameParam,
|
|
31
|
+
id: {
|
|
32
|
+
type: "text",
|
|
33
|
+
canBind: true,
|
|
34
|
+
defaultValue: "",
|
|
35
|
+
label: "Entry id"
|
|
36
|
+
},
|
|
37
|
+
score: {
|
|
38
|
+
type: "text",
|
|
39
|
+
canBind: true,
|
|
40
|
+
defaultValue: "0",
|
|
41
|
+
label: "Score (highest first)"
|
|
42
|
+
},
|
|
43
|
+
value: {
|
|
44
|
+
type: "codemirror-json",
|
|
45
|
+
canBind: true,
|
|
46
|
+
defaultValue: "",
|
|
47
|
+
label: "Value"
|
|
48
|
+
},
|
|
49
|
+
keep: {
|
|
50
|
+
type: "text",
|
|
51
|
+
canBind: true,
|
|
52
|
+
defaultValue: "",
|
|
53
|
+
label: `Keep at most (≤ 500)`
|
|
54
|
+
},
|
|
55
|
+
higherOnly: {
|
|
56
|
+
type: "boolean",
|
|
57
|
+
canBind: true,
|
|
58
|
+
defaultValue: false,
|
|
59
|
+
label: "Only replace a lower score (a best score, the latest of two writes)"
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
run: async ({ list, id, score, value, keep, higherOnly }, ctx) => {
|
|
63
|
+
const sorted = toNumber(score, void 0);
|
|
64
|
+
if (sorted === void 0) throw new Error(`A score is a number, and "${String(score)}" is not one`);
|
|
65
|
+
const put = await ctx.kv.listPut(list, {
|
|
66
|
+
id,
|
|
67
|
+
score: sorted,
|
|
68
|
+
value: valueOf(value)
|
|
69
|
+
}, {
|
|
70
|
+
keep: toNumber(keep, void 0),
|
|
71
|
+
higherOnly: higherOnly === true || higherOnly === "true"
|
|
72
|
+
});
|
|
73
|
+
return {
|
|
74
|
+
list,
|
|
75
|
+
id,
|
|
76
|
+
stored: put.stored,
|
|
77
|
+
dropped: put.dropped.map((entry) => entry.id)
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
namespace: "list",
|
|
83
|
+
action: "range",
|
|
84
|
+
title: "Read List",
|
|
85
|
+
params: {
|
|
86
|
+
list: nameParam,
|
|
87
|
+
offset: {
|
|
88
|
+
type: "text",
|
|
89
|
+
canBind: true,
|
|
90
|
+
defaultValue: "0",
|
|
91
|
+
label: "Skip"
|
|
92
|
+
},
|
|
93
|
+
limit: {
|
|
94
|
+
type: "text",
|
|
95
|
+
canBind: true,
|
|
96
|
+
defaultValue: "20",
|
|
97
|
+
label: "How many"
|
|
98
|
+
},
|
|
99
|
+
order: {
|
|
100
|
+
type: "select",
|
|
101
|
+
canBind: true,
|
|
102
|
+
defaultValue: "desc",
|
|
103
|
+
label: "Order",
|
|
104
|
+
options: [{
|
|
105
|
+
label: "Highest score first",
|
|
106
|
+
value: "desc"
|
|
107
|
+
}, {
|
|
108
|
+
label: "Lowest score first",
|
|
109
|
+
value: "asc"
|
|
110
|
+
}]
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
run: async ({ list, offset, limit, order }, ctx) => {
|
|
114
|
+
return {
|
|
115
|
+
list,
|
|
116
|
+
entries: await ctx.kv.listRange(list, {
|
|
117
|
+
offset: toNumber(offset, 0),
|
|
118
|
+
limit: toNumber(limit, void 0),
|
|
119
|
+
order: order === "asc" ? "asc" : "desc"
|
|
120
|
+
})
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
namespace: "list",
|
|
126
|
+
action: "remove",
|
|
127
|
+
title: "Remove From List",
|
|
128
|
+
params: {
|
|
129
|
+
list: nameParam,
|
|
130
|
+
id: {
|
|
131
|
+
type: "text",
|
|
132
|
+
canBind: true,
|
|
133
|
+
defaultValue: "",
|
|
134
|
+
label: "Entry id"
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
run: async ({ list, id }, ctx) => ({
|
|
138
|
+
list,
|
|
139
|
+
id,
|
|
140
|
+
removed: await ctx.kv.listRemove(list, id)
|
|
141
|
+
})
|
|
142
|
+
}
|
|
143
|
+
];
|
|
144
|
+
//#endregion
|
|
145
|
+
export { listTasks };
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { DEFAULT_GRANT_SECONDS, MAX_GRANT_SECONDS } from "../../realtime/grants.js";
|
|
2
|
+
//#region src/modules/actions/tasks/realtime.ts
|
|
3
|
+
var parse = (value) => {
|
|
4
|
+
if (typeof value !== "string") return value;
|
|
5
|
+
try {
|
|
6
|
+
return JSON.parse(value);
|
|
7
|
+
} catch {
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
var realtimeTasks = [
|
|
12
|
+
{
|
|
13
|
+
namespace: "realtime",
|
|
14
|
+
action: "publish",
|
|
15
|
+
title: "Publish On Channel",
|
|
16
|
+
description: "Sends a message to every page subscribed to a topic of one of the space’s channels.",
|
|
17
|
+
params: {
|
|
18
|
+
topic: {
|
|
19
|
+
type: "text",
|
|
20
|
+
canBind: true,
|
|
21
|
+
defaultValue: "",
|
|
22
|
+
label: "Topic (board:{{ input.board }})"
|
|
23
|
+
},
|
|
24
|
+
type: {
|
|
25
|
+
type: "text",
|
|
26
|
+
canBind: true,
|
|
27
|
+
defaultValue: "",
|
|
28
|
+
label: "Type"
|
|
29
|
+
},
|
|
30
|
+
data: {
|
|
31
|
+
type: "codemirror-json",
|
|
32
|
+
canBind: true,
|
|
33
|
+
defaultValue: "{}",
|
|
34
|
+
label: "Data"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
run: async ({ topic, type, data }, ctx) => {
|
|
38
|
+
if (!ctx.publish) throw new Error("This server has no realtime channels");
|
|
39
|
+
await ctx.publish(topic, type, parse(data));
|
|
40
|
+
return {
|
|
41
|
+
topic,
|
|
42
|
+
published: true
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
namespace: "realtime",
|
|
48
|
+
action: "grant",
|
|
49
|
+
title: "Grant Channel",
|
|
50
|
+
description: "Answers a grant that lets this visitor’s page open one topic of a private (`grant: true`) channel.",
|
|
51
|
+
params: {
|
|
52
|
+
topic: {
|
|
53
|
+
type: "text",
|
|
54
|
+
canBind: true,
|
|
55
|
+
defaultValue: "",
|
|
56
|
+
label: "Topic (room:{{ input.room }})"
|
|
57
|
+
},
|
|
58
|
+
ttlSeconds: {
|
|
59
|
+
type: "text",
|
|
60
|
+
canBind: true,
|
|
61
|
+
defaultValue: String(DEFAULT_GRANT_SECONDS),
|
|
62
|
+
label: `For how long (seconds, at most ${String(MAX_GRANT_SECONDS)})`
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
run: async ({ topic, ttlSeconds }, ctx) => {
|
|
66
|
+
if (!ctx.grant) throw new Error("This server has no realtime channels");
|
|
67
|
+
const seconds = ttlSeconds === "" ? void 0 : Number(ttlSeconds);
|
|
68
|
+
return {
|
|
69
|
+
topic,
|
|
70
|
+
grant: await ctx.grant(topic, Number.isFinite(seconds) ? seconds : void 0)
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
namespace: "realtime",
|
|
76
|
+
action: "revoke",
|
|
77
|
+
title: "Revoke Channel Grant",
|
|
78
|
+
description: "Takes back one grant to a private channel’s topic — or all of them — and lets go whoever is on it with one.",
|
|
79
|
+
params: {
|
|
80
|
+
topic: {
|
|
81
|
+
type: "text",
|
|
82
|
+
canBind: true,
|
|
83
|
+
defaultValue: "",
|
|
84
|
+
label: "Topic (room:{{ input.room }})"
|
|
85
|
+
},
|
|
86
|
+
grant: {
|
|
87
|
+
type: "text",
|
|
88
|
+
canBind: true,
|
|
89
|
+
defaultValue: "",
|
|
90
|
+
label: "Grant (empty = every grant for the topic)"
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
run: async ({ topic, grant }, ctx) => {
|
|
94
|
+
if (!ctx.revoke) throw new Error("This server has no realtime channels");
|
|
95
|
+
await ctx.revoke(topic, grant ? grant : void 0);
|
|
96
|
+
return {
|
|
97
|
+
topic,
|
|
98
|
+
revoked: grant ? "one" : "all"
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
];
|
|
103
|
+
//#endregion
|
|
104
|
+
export { realtimeTasks };
|
|
@@ -1,5 +1,14 @@
|
|
|
1
|
+
import { FunctionsDefinition } from '../../functions/contract';
|
|
1
2
|
import { ActionTask, ActionTaskRegistry } from '../types';
|
|
2
3
|
export declare const taskName: (task: Pick<ActionTask, "namespace" | "action">) => string;
|
|
4
|
+
/** The namespaces the platform's own tasks use: nobody else's task may take one. */
|
|
5
|
+
export declare const RESERVED_NAMESPACES: ReadonlySet<string>;
|
|
6
|
+
/**
|
|
7
|
+
* What is wrong with a task's name, or nothing — one rule for a deployment's tasks at boot and a space's own when its
|
|
8
|
+
* functions are built. A malformed name is unreachable from any document; one in a namespace taken by another task
|
|
9
|
+
* set silently changes what every action using that set does.
|
|
10
|
+
*/
|
|
11
|
+
export declare const taskNameProblem: (task: Pick<ActionTask, "namespace" | "action">, reserved?: ReadonlySet<string>) => string | undefined;
|
|
3
12
|
/** The shipped tasks that are only real when the deployment supplied what they run through. */
|
|
4
13
|
export type TaskRegistryOptions = {
|
|
5
14
|
/** At least one database driver is registered, so `db.query` has an engine to run against. */
|
|
@@ -12,4 +21,4 @@ export type TaskRegistryOptions = {
|
|
|
12
21
|
* name is unreachable from any document, and one shadowing a built-in silently changes what every existing action
|
|
13
22
|
* in that deployment does. Both are invisible until a run misbehaves in production.
|
|
14
23
|
*/
|
|
15
|
-
export declare const createTaskRegistry: (
|
|
24
|
+
export declare const createTaskRegistry: (functions?: readonly FunctionsDefinition[], { db }?: TaskRegistryOptions) => ActionTaskRegistry;
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import { builtinTasks } from "./builtins.js";
|
|
2
2
|
import { dbTasks } from "./db.js";
|
|
3
|
+
import { nativeTasks } from "../../functions/native.js";
|
|
3
4
|
//#region src/modules/actions/tasks/registry.ts
|
|
4
5
|
var NAME_PATTERN = /^[a-z][a-zA-Z0-9]*$/;
|
|
5
6
|
var taskName = (task) => `${task.namespace}.${task.action}`;
|
|
6
|
-
|
|
7
|
+
/** The namespaces the platform's own tasks use: nobody else's task may take one. */
|
|
8
|
+
var RESERVED_NAMESPACES = new Set([...builtinTasks, ...dbTasks].map((task) => task.namespace));
|
|
9
|
+
/**
|
|
10
|
+
* What is wrong with a task's name, or nothing — one rule for a deployment's tasks at boot and a space's own when its
|
|
11
|
+
* functions are built. A malformed name is unreachable from any document; one in a namespace taken by another task
|
|
12
|
+
* set silently changes what every action using that set does.
|
|
13
|
+
*/
|
|
14
|
+
var taskNameProblem = (task, reserved = RESERVED_NAMESPACES) => {
|
|
15
|
+
if (!NAME_PATTERN.test(task.namespace) || !NAME_PATTERN.test(task.action)) return `Invalid task name "${taskName(task)}": expected camelCase namespace and action`;
|
|
16
|
+
if (reserved.has(task.namespace)) return `Namespace "${task.namespace}" is reserved by another task set`;
|
|
17
|
+
};
|
|
7
18
|
/**
|
|
8
19
|
* Builds the set of tasks this server can run.
|
|
9
20
|
*
|
|
@@ -11,15 +22,15 @@ var reservedNamespaces = new Set([...builtinTasks, ...dbTasks].map((task) => tas
|
|
|
11
22
|
* name is unreachable from any document, and one shadowing a built-in silently changes what every existing action
|
|
12
23
|
* in that deployment does. Both are invisible until a run misbehaves in production.
|
|
13
24
|
*/
|
|
14
|
-
var createTaskRegistry = (
|
|
25
|
+
var createTaskRegistry = (functions = [], { db = false } = {}) => {
|
|
15
26
|
const tasks = /* @__PURE__ */ new Map();
|
|
16
27
|
(db ? [...builtinTasks, ...dbTasks] : builtinTasks).forEach((task) => tasks.set(taskName(task), {
|
|
17
28
|
...task,
|
|
18
29
|
name: taskName(task)
|
|
19
30
|
}));
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (
|
|
31
|
+
nativeTasks(functions).forEach((task) => {
|
|
32
|
+
const problem = taskNameProblem(task);
|
|
33
|
+
if (problem) throw new Error(`[Actions] ${problem}`);
|
|
23
34
|
const name = taskName(task);
|
|
24
35
|
if (tasks.has(name)) throw new Error(`[Actions] Task "${name}" is registered twice`);
|
|
25
36
|
tasks.set(name, {
|
|
@@ -33,4 +44,4 @@ var createTaskRegistry = (custom = [], { db = false } = {}) => {
|
|
|
33
44
|
};
|
|
34
45
|
};
|
|
35
46
|
//#endregion
|
|
36
|
-
export { createTaskRegistry, taskName };
|
|
47
|
+
export { RESERVED_NAMESPACES, createTaskRegistry, taskName, taskNameProblem };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { serverLog } from "../../../helpers/serverLog.js";
|
|
1
2
|
import { triggerParams } from "../runtime/triggers.js";
|
|
2
3
|
import { ActionRunError } from "../runtime/errors.js";
|
|
3
4
|
import { precheckRun } from "../runtime/precheck.js";
|
|
@@ -215,6 +216,7 @@ var handleActionCall = async (deps) => {
|
|
|
215
216
|
runId: result.runId,
|
|
216
217
|
status: result.status,
|
|
217
218
|
output: result.output,
|
|
219
|
+
...result.error === void 0 ? {} : { error: result.error },
|
|
218
220
|
...outline ? { steps: result.steps } : {}
|
|
219
221
|
}
|
|
220
222
|
});
|
|
@@ -224,7 +226,8 @@ var handleActionCall = async (deps) => {
|
|
|
224
226
|
const payload = {
|
|
225
227
|
runId: result.runId,
|
|
226
228
|
status: result.status,
|
|
227
|
-
output: result.output
|
|
229
|
+
output: result.output,
|
|
230
|
+
...result.error === void 0 ? {} : { error: result.error }
|
|
228
231
|
};
|
|
229
232
|
if (outline) payload.steps = result.steps;
|
|
230
233
|
if (fullTrace) payload.trace = result.trace;
|
|
@@ -232,7 +235,7 @@ var handleActionCall = async (deps) => {
|
|
|
232
235
|
} catch (error) {
|
|
233
236
|
const reason = error instanceof ActionRunError ? error.reason : "failed";
|
|
234
237
|
const message = error instanceof ActionRunError ? error.message : "Action failed";
|
|
235
|
-
if (!(error instanceof ActionRunError))
|
|
238
|
+
if (!(error instanceof ActionRunError)) serverLog.error("Actions", "run failed", error);
|
|
236
239
|
const steps = error instanceof ActionRunError && error.steps && await showsOutline() ? error.steps : void 0;
|
|
237
240
|
if (stream) {
|
|
238
241
|
stream.send({
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { ActionsModule } from '../index';
|
|
2
|
-
import { SSRResponseHelpers } from '@plitzi/sdk-shared';
|
|
2
|
+
import { SpaceRevision, SSRResponseHelpers } from '@plitzi/sdk-shared';
|
|
3
3
|
export type ActionCatalogDeps = {
|
|
4
4
|
res: SSRResponseHelpers;
|
|
5
5
|
module: ActionsModule;
|
|
6
|
+
/** The space asking, as of the revision it is serving: its own functions are part of what it can run. */
|
|
7
|
+
spaceId?: number;
|
|
8
|
+
at?: SpaceRevision;
|
|
6
9
|
};
|
|
7
10
|
/**
|
|
8
11
|
* Serves the tasks this server can run.
|
|
@@ -15,4 +18,4 @@ export type ActionCatalogDeps = {
|
|
|
15
18
|
* Session-gated by the pipeline: the catalog names a deployment's server-side capabilities, which is not something
|
|
16
19
|
* to hand an anonymous visitor.
|
|
17
20
|
*/
|
|
18
|
-
export declare const handleActionCatalog: ({ res, module }: ActionCatalogDeps) => void
|
|
21
|
+
export declare const handleActionCatalog: ({ res, module, spaceId, at }: ActionCatalogDeps) => Promise<void>;
|
|
@@ -11,11 +11,12 @@ import { describeCatalog } from "../taskCatalog.js";
|
|
|
11
11
|
* Session-gated by the pipeline: the catalog names a deployment's server-side capabilities, which is not something
|
|
12
12
|
* to hand an anonymous visitor.
|
|
13
13
|
*/
|
|
14
|
-
var handleActionCatalog = ({ res, module }) => {
|
|
14
|
+
var handleActionCatalog = async ({ res, module, spaceId, at }) => {
|
|
15
|
+
const registry = spaceId === void 0 ? module.registry : await module.registryFor(spaceId, at);
|
|
15
16
|
res.setStatus(200);
|
|
16
17
|
res.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
17
18
|
res.setHeader("Cache-Control", "no-store");
|
|
18
|
-
res.send(JSON.stringify({ tasks: describeCatalog(
|
|
19
|
+
res.send(JSON.stringify({ tasks: describeCatalog(registry) }));
|
|
19
20
|
};
|
|
20
21
|
//#endregion
|
|
21
22
|
export { handleActionCatalog };
|
|
@@ -10,12 +10,11 @@ export type ActionStream = {
|
|
|
10
10
|
isOpen: () => boolean;
|
|
11
11
|
};
|
|
12
12
|
/**
|
|
13
|
-
* Opens a Server-Sent Events response.
|
|
13
|
+
* Opens a run's Server-Sent Events response.
|
|
14
14
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* until its buffer fills and turns a live stream into one late burst.
|
|
15
|
+
* The run's id travels on the response head rather than in a frame: a streaming step returns as soon as the stream
|
|
16
|
+
* OPENS — that is what makes it a stream — so anything it learns from a frame arrives after the flow has already
|
|
17
|
+
* carried on. The head is the one place a caller can read the id in time to cancel the run it just started.
|
|
19
18
|
*/
|
|
20
19
|
export declare const openStream: (raw: RawResponse, onAbort: () => void, runId: string) => ActionStream;
|
|
21
20
|
/** Whether this caller asked for a stream. The negotiation is the client's, so a page that cannot read one never
|