@plitzi/sdk-server 0.37.1 → 0.37.3
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 +1296 -0
- package/README.md +126 -7
- package/dist/actions.d.ts +20 -8
- package/dist/actions.js +11 -4
- package/dist/adapters/cloudAdapters.js +4 -3
- package/dist/adapters/jsonAdapters.js +28 -6
- 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 +14 -1
- package/dist/core/server/baseServer.js +43 -11
- package/dist/core/server/closeOnSignals.d.ts +28 -0
- package/dist/core/server/closeOnSignals.js +47 -0
- package/dist/core/server/closeOnSignals.test.d.ts +1 -0
- 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 +36 -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 +8 -1
- package/dist/index.js +6 -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 +41 -13
- package/dist/modules/actions/index.js +52 -9
- 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 +33 -0
- package/dist/modules/actions/jobs/index.js +59 -0
- package/dist/modules/actions/jobs/memoryQueue.d.ts +33 -0
- package/dist/modules/actions/jobs/memoryQueue.js +194 -0
- package/dist/modules/actions/jobs/memoryStores.test.d.ts +1 -0
- package/dist/modules/actions/jobs/scheduler.d.ts +64 -0
- package/dist/modules/actions/jobs/scheduler.js +130 -0
- package/dist/modules/actions/jobs/scheduler.test.d.ts +1 -0
- package/dist/modules/actions/jobs/schedules.d.ts +23 -0
- package/dist/modules/actions/jobs/schedules.js +47 -0
- package/dist/modules/actions/jobs/storeClock.d.ts +16 -0
- package/dist/modules/actions/jobs/storeClock.js +32 -0
- package/dist/modules/actions/jobs/testing/jobQueueContract.d.ts +25 -0
- package/dist/modules/actions/jobs/worker.d.ts +64 -0
- package/dist/modules/actions/jobs/worker.js +267 -0
- package/dist/modules/actions/jobs/worker.test.d.ts +1 -0
- package/dist/modules/actions/moduleFor.js +6 -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 +5 -9
- 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/renderResolver.js +2 -2
- 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 +6 -3
- 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 +5 -4
- package/dist/modules/actions/types.d.ts +162 -4
- 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/index.d.ts +4 -0
- package/dist/modules/mongo/jobQueue.d.ts +38 -0
- package/dist/modules/mongo/jobQueue.js +335 -0
- package/dist/modules/mongo/kv.d.ts +15 -0
- package/dist/modules/mongo/kv.js +129 -0
- package/dist/modules/mongo/stores.integration.test.d.ts +1 -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 +5 -0
- package/dist/modules/mysql/jobs/jobQueue.d.ts +40 -0
- package/dist/modules/mysql/jobs/jobQueue.js +375 -0
- package/dist/modules/mysql/jobs/kv.d.ts +18 -0
- package/dist/modules/mysql/jobs/kv.js +108 -0
- package/dist/modules/mysql/jobs/schema.d.ts +33 -0
- package/dist/modules/mysql/jobs/schema.js +113 -0
- package/dist/modules/mysql/jobs/stores.integration.test.d.ts +1 -0
- 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 +4 -5
- package/dist/modules/ssr/Component.js +2 -2
- package/dist/modules/ssr/handler.js +10 -2
- package/dist/modules/ssr/loadPluginComponents.js +2 -1
- package/dist/modules/ssr/prepareRender.js +39 -13
- 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/mongo.d.ts +25 -0
- package/dist/mongo.js +3 -0
- package/dist/mysql.d.ts +11 -0
- package/dist/mysql.js +4 -1
- 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 +52 -11
- package/skills/plitzi-authoring/SKILL.md +153 -263
- 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 +180 -0
- package/skills/plitzi-authoring/reference/elements-and-styles.md +161 -0
- package/skills/plitzi-authoring/reference/flows.md +171 -0
- package/skills/plitzi-authoring/reference/layouts.md +140 -0
- 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 +67 -0
- package/skills/plitzi-authoring/reference/structure.md +83 -0
- package/skills/plitzi-authoring/reference/templates-and-export.md +54 -0
- package/skills/plitzi-authoring/reference/templates.md +109 -0
- package/skills/plitzi-authoring/reference/testing.md +119 -0
- package/skills/plitzi-authoring/reference/validation.md +73 -0
- package/dist/modules/actions/runtime/schedule.d.ts +0 -35
- package/dist/modules/actions/runtime/schedule.js +0 -76
- /package/dist/{modules/actions/runtime/schedule.test.d.ts → adapters/jsonAdapters.test.d.ts} +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { createServer, resolveServices } from './core/createServer';
|
|
2
|
+
export { closeOnSignals } from './core/server/closeOnSignals';
|
|
3
|
+
export { loadFunctions, readFunctionsDir } from './modules/functions/load';
|
|
2
4
|
export { registerHealthCheck, buildHealthPayload } from './core/health';
|
|
3
|
-
export { consoleLogger, renderLogEvent } from './helpers/serverLog';
|
|
5
|
+
export { consoleLogger, isLogged, logLevelOf, renderLogEvent, serverLog } from './helpers/serverLog';
|
|
4
6
|
export type { HealthCheckApp, HealthIdentity } from './core/health';
|
|
5
7
|
export { createCloudAdapters } from './adapters/cloudAdapters';
|
|
6
8
|
export { createJsonAdapters } from './adapters/jsonAdapters';
|
|
@@ -8,6 +10,8 @@ export { createAuthAdapters } from './adapters/authAdapters';
|
|
|
8
10
|
export { authoringPreview, createMemoryCache, createSpaceAdapters, fixedSpace, presentsCredential, refuse, verifiedDomain, wildcardSubdomain } from './adapters/space';
|
|
9
11
|
export { createLocalFontStore, hostedPathsOf } from './core/fontStore';
|
|
10
12
|
export { createMemoryDraftStore, takeDraftOverride } from './modules/ssr/preview';
|
|
13
|
+
export { createMemoryPubSub } from './modules/realtime/memoryPubSub';
|
|
14
|
+
export { createRedisPubSub } from './modules/realtime/redisPubSub';
|
|
11
15
|
export { PREVIEW_TOKEN_PARAM } from './core/previewToken';
|
|
12
16
|
export { resolveRscData } from './modules/rsc/resolveRscData';
|
|
13
17
|
export { fetchConnectorRecords, rebaseMedia, writeConnectorRecord, createConnectorResolver } from './modules/connectors';
|
|
@@ -18,5 +22,8 @@ export type { AuthoringPreviewOptions, DeploymentRow, FrameAncestorsConfig, Spac
|
|
|
18
22
|
export type { RscElementResolver, RscResolveContext, ResolveRscDataOptions } from './modules/rsc/resolveRscData';
|
|
19
23
|
export type { ConnectorAuth, ConnectorCredential, ConnectorEndpoints, ConnectorFilter, ConnectorLookups, ConnectorManifest, ConnectorManifestDraft, ConnectorPageInfo, ConnectorPagination, ConnectorQuery, ConnectorReadEndpoint, ConnectorRecord, ConnectorResponseMapping, ConnectorResult, ProviderPagination } from './modules/connectors';
|
|
20
24
|
export type { FontStore, StoredFont } from './core/fontStore';
|
|
25
|
+
export type { PubSubAdapter, SSRRealtimeConfig } from '@plitzi/sdk-shared';
|
|
26
|
+
export type { RedisPubSubClients } from './modules/realtime/redisPubSub';
|
|
21
27
|
export type { ResolvedServices } from './core/createServer';
|
|
28
|
+
export type { Closable, CloseOnSignalsOptions } from './core/server/closeOnSignals';
|
|
22
29
|
export type { BaseContext, PipelineExtensions, SSRContext, Stage } from './core/http/types';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { consoleLogger, isLogged, logLevelOf, renderLogEvent, serverLog } from "./helpers/serverLog.js";
|
|
1
2
|
import { fetchConnectorRecords, rebaseMedia, writeConnectorRecord } from "./modules/connectors/engine.js";
|
|
3
|
+
import { createMemoryPubSub } from "./modules/realtime/memoryPubSub.js";
|
|
2
4
|
import { createConnectorResolver } from "./modules/connectors/resolver.js";
|
|
3
5
|
import { resolveRscData } from "./modules/rsc/resolveRscData.js";
|
|
4
6
|
import { PREVIEW_TOKEN_PARAM } from "./core/previewToken.js";
|
|
@@ -6,7 +8,8 @@ import { createMemoryDraftStore, takeDraftOverride } from "./modules/ssr/preview
|
|
|
6
8
|
import { resolveServices } from "./core/services/resolve.js";
|
|
7
9
|
import { buildHealthPayload, registerHealthCheck } from "./core/health.js";
|
|
8
10
|
import { createServer } from "./core/createServer.js";
|
|
9
|
-
import {
|
|
11
|
+
import { closeOnSignals } from "./core/server/closeOnSignals.js";
|
|
12
|
+
import { loadFunctions, readFunctionsDir } from "./modules/functions/load.js";
|
|
10
13
|
import { createCloudAdapters } from "./adapters/cloudAdapters.js";
|
|
11
14
|
import { createJsonAdapters } from "./adapters/jsonAdapters.js";
|
|
12
15
|
import { createAuthAdapters } from "./adapters/authAdapters.js";
|
|
@@ -14,4 +17,5 @@ import { createMemoryCache, refuse } from "./adapters/space/types.js";
|
|
|
14
17
|
import { authoringPreview, fixedSpace, presentsCredential, verifiedDomain, wildcardSubdomain } from "./adapters/space/resolvers.js";
|
|
15
18
|
import { createSpaceAdapters } from "./adapters/space/index.js";
|
|
16
19
|
import { createLocalFontStore, hostedPathsOf } from "./core/fontStore.js";
|
|
17
|
-
|
|
20
|
+
import { createRedisPubSub } from "./modules/realtime/redisPubSub.js";
|
|
21
|
+
export { PREVIEW_TOKEN_PARAM, authoringPreview, buildHealthPayload, closeOnSignals, consoleLogger, createAuthAdapters, createCloudAdapters, createConnectorResolver, createJsonAdapters, createLocalFontStore, createMemoryCache, createMemoryDraftStore, createMemoryPubSub, createRedisPubSub, createServer, createSpaceAdapters, fetchConnectorRecords, fixedSpace, hostedPathsOf, isLogged, loadFunctions, logLevelOf, presentsCredential, readFunctionsDir, rebaseMedia, refuse, registerHealthCheck, renderLogEvent, resolveRscData, resolveServices, serverLog, takeDraftOverride, verifiedDomain, wildcardSubdomain, writeConnectorRecord };
|
package/dist/kernel.d.ts
CHANGED
|
@@ -16,8 +16,9 @@ export { healthStage } from './core/http/stages/health';
|
|
|
16
16
|
export { configStaticStage, publicDirStage, wellKnownStage } from './core/http/stages/static';
|
|
17
17
|
export { buildHealthPayload, registerHealthCheck } from './core/health';
|
|
18
18
|
export { clientIp, parseRequest, readRawBody, requestOrigin } from './core/requestParser';
|
|
19
|
-
export { consoleLogger, renderLogEvent } from './helpers/serverLog';
|
|
19
|
+
export { consoleLogger, isLogged, logLevelOf, renderLogEvent, serverLog } from './helpers/serverLog';
|
|
20
20
|
export { PREVIEW_TOKEN_PARAM } from './core/previewToken';
|
|
21
|
+
export { assertOutboundAllowed, isBlockedHost } from './helpers/outboundGuard';
|
|
21
22
|
export type { HttpServerParts } from './core/server/baseServer';
|
|
22
23
|
export type { BuildContext } from './core/http/dispatcher';
|
|
23
24
|
export type { HealthCheckApp, HealthIdentity } from './core/health';
|
package/dist/kernel.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { consoleLogger, isLogged, logLevelOf, renderLogEvent, serverLog } from "./helpers/serverLog.js";
|
|
2
|
+
import { assertOutboundAllowed, isBlockedHost } from "./helpers/outboundGuard.js";
|
|
1
3
|
import { clientIp, parseRequest, readRawBody, requestOrigin } from "./core/requestParser.js";
|
|
2
4
|
import { createHttpServer } from "./core/server/baseServer.js";
|
|
3
5
|
import { PREVIEW_TOKEN_PARAM } from "./core/previewToken.js";
|
|
@@ -5,5 +7,4 @@ import { makeHandler } from "./core/http/dispatcher.js";
|
|
|
5
7
|
import { buildHealthPayload, registerHealthCheck } from "./core/health.js";
|
|
6
8
|
import { healthStage } from "./core/http/stages/health.js";
|
|
7
9
|
import { configStaticStage, publicDirStage, wellKnownStage } from "./core/http/stages/static.js";
|
|
8
|
-
|
|
9
|
-
export { PREVIEW_TOKEN_PARAM, buildHealthPayload, clientIp, configStaticStage, consoleLogger, createHttpServer, healthStage, makeHandler, parseRequest, publicDirStage, readRawBody, registerHealthCheck, renderLogEvent, requestOrigin, wellKnownStage };
|
|
10
|
+
export { PREVIEW_TOKEN_PARAM, assertOutboundAllowed, buildHealthPayload, clientIp, configStaticStage, consoleLogger, createHttpServer, healthStage, isBlockedHost, isLogged, logLevelOf, makeHandler, parseRequest, publicDirStage, readRawBody, registerHealthCheck, renderLogEvent, requestOrigin, serverLog, wellKnownStage };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { serverLog } from "../../helpers/serverLog.js";
|
|
1
2
|
import { writeConnectorRecord } from "../connectors/engine.js";
|
|
2
3
|
//#region src/modules/actions/connectorWrite.ts
|
|
3
4
|
var parseBody = (body) => {
|
|
@@ -72,7 +73,7 @@ var handleAction = async (req, res, config, lookups) => {
|
|
|
72
73
|
res.setHeader("Cache-Control", "no-store");
|
|
73
74
|
res.send(JSON.stringify({ record: record ?? null }));
|
|
74
75
|
} catch (err) {
|
|
75
|
-
|
|
76
|
+
serverLog.error("Action", "connector write failed", err);
|
|
76
77
|
fail(res, 502, "Connector write failed");
|
|
77
78
|
}
|
|
78
79
|
};
|
|
@@ -1,30 +1,58 @@
|
|
|
1
|
+
import { ActionJobs } from './jobs';
|
|
1
2
|
import { RunGuards } from './runtime/guards';
|
|
2
3
|
import { ActionRunner } from './runtime/runAction';
|
|
3
|
-
import { ActionKvStore, ActionsConfig, ActionTaskRegistry, ResolvedActionLimits } from './types';
|
|
4
|
+
import { ActionKvStore, ActionsConfig, ActionTaskRegistry, ResolvedActionLimits, SpaceRevision } from './types';
|
|
5
|
+
import { FunctionsSource } from '../functions/build';
|
|
6
|
+
import { ManifestReading } from '../functions/manifest';
|
|
7
|
+
import { RouteHandler, RouteVisit } from '../functions/routes';
|
|
8
|
+
import { PreparedFunctions } from '../functions/space';
|
|
4
9
|
import { ActionDocument } from '@plitzi/sdk-shared';
|
|
5
10
|
export type ActionsModule = ActionRunner & {
|
|
11
|
+
/** The deployment's own tasks: shipped, and its native functions. */
|
|
6
12
|
registry: ActionTaskRegistry;
|
|
13
|
+
/**
|
|
14
|
+
* What a space's actions can use as of that revision: the deployment's tasks and the space's own functions — what
|
|
15
|
+
* its catalog offers, what a check checks against and what its runs run.
|
|
16
|
+
*/
|
|
17
|
+
registryFor: (spaceId: number, at?: SpaceRevision) => Promise<ActionTaskRegistry>;
|
|
18
|
+
/**
|
|
19
|
+
* A space's functions source, built, read and checked — ready to store, or the problems to show where they are. The
|
|
20
|
+
* one way a space's functions become storable; refused when this server has no runner.
|
|
21
|
+
*/
|
|
22
|
+
prepareFunctions: (source: FunctionsSource) => Promise<PreparedFunctions>;
|
|
23
|
+
/**
|
|
24
|
+
* What a space's code declares, read by every rule a saved space's functions meet — for code that is not built here:
|
|
25
|
+
* a space runtime's, described by the runtime itself when it starts. The manifest, and the problems that refuse it.
|
|
26
|
+
*/
|
|
27
|
+
readManifest: (declared: unknown) => ManifestReading;
|
|
28
|
+
/**
|
|
29
|
+
* The function that answers `method path` under `/api/` for this visit — the deployment's own routes, then the space's
|
|
30
|
+
* — or none, and the page server answers as it would have.
|
|
31
|
+
*/
|
|
32
|
+
routeFor: (visit: RouteVisit, method: string, path: string) => Promise<RouteHandler | undefined>;
|
|
7
33
|
guards: RunGuards;
|
|
8
34
|
/** The key/value store, namespaced to one space — the same one the `kv` tasks write through, so a rate limit the
|
|
9
35
|
* transport keeps and a counter a flow keeps cannot end up in different places. */
|
|
10
36
|
kv: (spaceId: number) => ActionKvStore;
|
|
11
37
|
/** What this server will allow one run of that document to spend — the deployment's ceilings, tightened by it. */
|
|
12
38
|
limitsFor: (document: ActionDocument) => ResolvedActionLimits;
|
|
39
|
+
/**
|
|
40
|
+
* Scheduled runs: the queue, the sweep that fills it and the workers that drain it.
|
|
41
|
+
*
|
|
42
|
+
* Built but NOT started — whoever owns the process decides when background work begins, and a server nobody
|
|
43
|
+
* listened on must not be quietly claiming jobs. Absent when the deployment cannot list a space's actions, since
|
|
44
|
+
* there is then no way to know what is scheduled.
|
|
45
|
+
*/
|
|
46
|
+
jobs?: ActionJobs;
|
|
13
47
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
*
|
|
17
|
-
* Constructed rather than imported piecemeal so the task registry is validated ONCE, at boot, and so the guards
|
|
18
|
-
* are a single set for the process — two instances would each think they were the only run in flight, which is
|
|
19
|
-
* the same as having no single-flight at all. Nothing outside this folder needs to know how a run is assembled.
|
|
20
|
-
*/
|
|
21
|
-
export declare const createActionsModule: (config: ActionsConfig) => ActionsModule;
|
|
22
|
-
export { ActionRunError } from './runtime/errors';
|
|
48
|
+
export declare const createActionsModule: (given: ActionsConfig) => ActionsModule;
|
|
49
|
+
export { ActionRefusal, ActionRunError } from './runtime/errors';
|
|
23
50
|
export { precheckRun } from './runtime/precheck';
|
|
51
|
+
export { spaceKvPatterns } from './runtime/namespaceKv';
|
|
24
52
|
export { checkAction } from './runtime/check';
|
|
25
53
|
export { DEFAULT_LIMITS, resolveLimits } from './runtime/limits';
|
|
26
54
|
export { createRunGuards, deriveRunKey } from './runtime/guards';
|
|
27
|
-
export {
|
|
55
|
+
export { createActionJobs, createJobWorker, createMemoryJobQueue, createScheduler } from './jobs';
|
|
28
56
|
export { createMemoryKv } from './runtime/memoryKv';
|
|
29
57
|
export { createRunLogger, createRejectLogger } from './runtime/runLogger';
|
|
30
58
|
export { createTaskRegistry, taskName } from './tasks/registry';
|
|
@@ -34,8 +62,8 @@ export { handleActionCatalog } from './transport/catalogHandler';
|
|
|
34
62
|
export { handleActionWebhook } from './transport/webhookHandler';
|
|
35
63
|
export { verifySignature } from './transport/verifySignature';
|
|
36
64
|
export { handleActionCancel } from './transport/cancelHandler';
|
|
65
|
+
export type { ActionJobs, JobWorker, JobWorkerOptions, Scheduler, SchedulerOptions, SweepResult } from './jobs';
|
|
37
66
|
export type { ActiveRun, RunGuards } from './runtime/guards';
|
|
38
|
-
export type { ScheduleResult, ScheduleRunner, ScheduleTick } from './runtime/schedule';
|
|
39
67
|
export type { ActionTaskDescriptor } from './taskCatalog';
|
|
40
68
|
export type { TaskRegistryOptions } from './tasks/registry';
|
|
41
|
-
export type { ActionCredential, ActionDbDriver, ActionEmailConfig, ActionEmailDelivery, ActionEmailMessage, ActionEmailTransport, ActionKvStore, ActionLookups, ActionRejectRecord, ActionRunRecord, ActionRunRequest, ActionRunResult, ActionsConfig, ActionTask, ActionTaskContext, ActionTaskRegistry, RegisteredTask, ResolvedConnector } from './types';
|
|
69
|
+
export type { ActionCredential, ActionDbDriver, ActionEmailConfig, ActionEmailDelivery, ActionEmailMessage, ActionEmailTransport, ActionJobsConfig, ActionKvStore, ActionLookups, ActionRejectRecord, ActionRunRecord, ActionRunRequest, ActionRunResult, ActionsConfig, ActionTask, ActionTaskContext, ActionTaskRegistry, RegisteredTask, ResolvedConnector } from './types';
|
|
@@ -1,14 +1,21 @@
|
|
|
1
|
+
import "./jobs/memoryQueue.js";
|
|
2
|
+
import "./jobs/scheduler.js";
|
|
1
3
|
import "./runtime/errors.js";
|
|
4
|
+
import "./jobs/worker.js";
|
|
5
|
+
import { fleetStore } from "../../core/server/fleet/link.js";
|
|
6
|
+
import { createActionJobs } from "./jobs/index.js";
|
|
2
7
|
import { createRunGuards } from "./runtime/guards.js";
|
|
3
8
|
import { createKvStore } from "./runtime/kvStore.js";
|
|
4
9
|
import { resolveLimits } from "./runtime/limits.js";
|
|
5
|
-
import { createMemoryKv } from "./runtime/memoryKv.js";
|
|
6
|
-
import { namespaceKv } from "./runtime/namespaceKv.js";
|
|
10
|
+
import { KV_METHODS, createMemoryKv } from "./runtime/memoryKv.js";
|
|
11
|
+
import { namespaceKv, spaceKvPatterns } from "./runtime/namespaceKv.js";
|
|
7
12
|
import "./runtime/precheck.js";
|
|
8
13
|
import { createActionRunner } from "./runtime/runAction.js";
|
|
9
14
|
import { createTaskRegistry } from "./tasks/registry.js";
|
|
15
|
+
import { readManifest } from "../functions/manifest.js";
|
|
16
|
+
import { createRoutes } from "../functions/routes.js";
|
|
17
|
+
import { createSpaceRegistries, prepareFunctions } from "../functions/space.js";
|
|
10
18
|
import "./runtime/check.js";
|
|
11
|
-
import "./runtime/schedule.js";
|
|
12
19
|
import "./runtime/runLogger.js";
|
|
13
20
|
import "./taskCatalog.js";
|
|
14
21
|
import { handleActionCall } from "./transport/callHandler.js";
|
|
@@ -24,9 +31,32 @@ import { handleActionCancel } from "./transport/cancelHandler.js";
|
|
|
24
31
|
* are a single set for the process — two instances would each think they were the only run in flight, which is
|
|
25
32
|
* the same as having no single-flight at all. Nothing outside this folder needs to know how a run is assembled.
|
|
26
33
|
*/
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
34
|
+
/**
|
|
35
|
+
* The workers of one server are one replica, so with no `kv` configured they share the primary's: a flow's counter,
|
|
36
|
+
* a webhook's rate limit, a run's single-flight key, a cancel and a replayed answer then mean the same whichever
|
|
37
|
+
* worker the request lands on — the path a deployment with its own shared store already takes. One process keeps
|
|
38
|
+
* its own map.
|
|
39
|
+
*/
|
|
40
|
+
var withFleetKv = (config) => {
|
|
41
|
+
if (config.kv) return config;
|
|
42
|
+
return {
|
|
43
|
+
...config,
|
|
44
|
+
kv: fleetStore("actions.kv", KV_METHODS) ?? createMemoryKv()
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
var createActionsModule = (given) => {
|
|
48
|
+
const config = withFleetKv(given);
|
|
49
|
+
const registry = createTaskRegistry(config.functions?.native, { db: (config.dbDrivers?.length ?? 0) > 0 });
|
|
50
|
+
const spaceRegistries = createSpaceRegistries(registry, config.functions);
|
|
51
|
+
const reserved = new Set(registry.list().map((task) => task.namespace));
|
|
52
|
+
const registryFor = async (spaceId, at) => spaceRegistries.registryFor(await config.lookups.getFunctions?.(spaceId, at));
|
|
53
|
+
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);
|
|
54
|
+
const { runAction, taskContext } = createActionRunner(config, registryForRun, config.fetchImpl);
|
|
55
|
+
const routes = createRoutes({
|
|
56
|
+
config: config.functions ?? {},
|
|
57
|
+
...config.lookups.getFunctions ? { getFunctions: config.lookups.getFunctions } : {},
|
|
58
|
+
taskContext
|
|
59
|
+
});
|
|
30
60
|
/**
|
|
31
61
|
* Single-flight over the store the deployment already gave the `kv` tasks — its own Redis, table or whatever it
|
|
32
62
|
* runs — because per process it is not a guarantee: the same double-click behind a load balancer lands on two
|
|
@@ -34,13 +64,26 @@ var createActionsModule = (config) => {
|
|
|
34
64
|
*/
|
|
35
65
|
const guards = createRunGuards(config.concurrency, config.kv, config.idempotency);
|
|
36
66
|
const kv = createKvStore(config.kv ?? createMemoryKv());
|
|
37
|
-
|
|
67
|
+
const limitsFor = (document) => resolveLimits(config.limits, document.limits);
|
|
68
|
+
const module = {
|
|
38
69
|
runAction,
|
|
39
70
|
registry,
|
|
71
|
+
registryFor,
|
|
72
|
+
routeFor: routes.routeFor,
|
|
73
|
+
prepareFunctions: (source) => {
|
|
74
|
+
const runner = config.functions?.runner;
|
|
75
|
+
return runner ? prepareFunctions(source, runner, reserved) : Promise.resolve({
|
|
76
|
+
ok: false,
|
|
77
|
+
problems: [{ message: "This server runs no space functions" }]
|
|
78
|
+
});
|
|
79
|
+
},
|
|
80
|
+
readManifest: (declared) => readManifest(declared, reserved),
|
|
40
81
|
guards,
|
|
41
82
|
kv: (spaceId) => namespaceKv(kv, spaceId),
|
|
42
|
-
limitsFor
|
|
83
|
+
limitsFor
|
|
43
84
|
};
|
|
85
|
+
if (config.jobs !== false && config.lookups.listActions) module.jobs = createActionJobs(config.jobs ?? {}, module, config.lookups);
|
|
86
|
+
return module;
|
|
44
87
|
};
|
|
45
88
|
//#endregion
|
|
46
|
-
export { createActionsModule, handleActionCall, handleActionCancel, handleActionCatalog, handleActionWebhook };
|
|
89
|
+
export { createActionsModule, handleActionCall, handleActionCancel, handleActionCatalog, handleActionWebhook, spaceKvPatterns };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** How long a pass may keep failing before it is reported as the error it has become. */
|
|
2
|
+
export declare const FAILURE_STREAK_ESCALATION_MS = 60000;
|
|
3
|
+
export type FailureStreak = {
|
|
4
|
+
failed: (error: unknown) => void;
|
|
5
|
+
succeeded: () => void;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* How a pass that runs again by itself reports failing: a schedule sweep, a claim, a heartbeat.
|
|
9
|
+
*
|
|
10
|
+
* A store that drops its connections for a moment — a failover, a driver resetting its pool because the host stalled
|
|
11
|
+
* — fails one pass, and the next, seconds later, works. Nothing is lost: every pass is safe to repeat. Reported as an
|
|
12
|
+
* error with a stack, each of those read as an incident, and the ones that are an incident read the same.
|
|
13
|
+
*
|
|
14
|
+
* So the first failure of a streak is a warning with its reason; a streak still going after `escalateAfterMs` is the
|
|
15
|
+
* error, with the whole cause, once; and the pass that ends a streak that got that far says so.
|
|
16
|
+
*/
|
|
17
|
+
export declare const createFailureStreak: (scope: string, what: string, escalateAfterMs?: number, now?: () => number) => FailureStreak;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { serverLog } from "../../../helpers/serverLog.js";
|
|
2
|
+
//#region src/modules/actions/jobs/failureStreak.ts
|
|
3
|
+
/** How long a pass may keep failing before it is reported as the error it has become. */
|
|
4
|
+
var FAILURE_STREAK_ESCALATION_MS = 6e4;
|
|
5
|
+
var reasonOf = (error) => error instanceof Error ? error.message : String(error);
|
|
6
|
+
/**
|
|
7
|
+
* How a pass that runs again by itself reports failing: a schedule sweep, a claim, a heartbeat.
|
|
8
|
+
*
|
|
9
|
+
* A store that drops its connections for a moment — a failover, a driver resetting its pool because the host stalled
|
|
10
|
+
* — fails one pass, and the next, seconds later, works. Nothing is lost: every pass is safe to repeat. Reported as an
|
|
11
|
+
* error with a stack, each of those read as an incident, and the ones that are an incident read the same.
|
|
12
|
+
*
|
|
13
|
+
* So the first failure of a streak is a warning with its reason; a streak still going after `escalateAfterMs` is the
|
|
14
|
+
* error, with the whole cause, once; and the pass that ends a streak that got that far says so.
|
|
15
|
+
*/
|
|
16
|
+
var createFailureStreak = (scope, what, escalateAfterMs = FAILURE_STREAK_ESCALATION_MS, now = Date.now) => {
|
|
17
|
+
let since;
|
|
18
|
+
let failures = 0;
|
|
19
|
+
let escalated = false;
|
|
20
|
+
return {
|
|
21
|
+
failed: (error) => {
|
|
22
|
+
failures += 1;
|
|
23
|
+
if (since === void 0) {
|
|
24
|
+
since = now();
|
|
25
|
+
serverLog.warn(scope, `${what} failed, trying again`, reasonOf(error));
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const elapsed = now() - since;
|
|
29
|
+
if (!escalated && elapsed >= escalateAfterMs) {
|
|
30
|
+
escalated = true;
|
|
31
|
+
serverLog.error(scope, `${what} has been failing for ${String(Math.round(elapsed / 1e3))}s`, error);
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
succeeded: () => {
|
|
35
|
+
if (since === void 0) return;
|
|
36
|
+
if (escalated) {
|
|
37
|
+
const seconds = Math.round((now() - since) / 1e3);
|
|
38
|
+
serverLog.info(scope, `${what} is working again, after ${String(failures)} failures over ${String(seconds)}s`);
|
|
39
|
+
}
|
|
40
|
+
since = void 0;
|
|
41
|
+
failures = 0;
|
|
42
|
+
escalated = false;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
//#endregion
|
|
47
|
+
export { FAILURE_STREAK_ESCALATION_MS, createFailureStreak };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Scheduler } from './scheduler';
|
|
2
|
+
import { JobWorker } from './worker';
|
|
3
|
+
import { ActionsModule } from '../index';
|
|
4
|
+
import { ActionJobsConfig, ActionLookups } from '../types';
|
|
5
|
+
import { ActionJobQueue } from '@plitzi/sdk-shared';
|
|
6
|
+
export type ActionJobs = {
|
|
7
|
+
queue: ActionJobQueue;
|
|
8
|
+
scheduler: Scheduler;
|
|
9
|
+
worker: JobWorker;
|
|
10
|
+
start: () => void;
|
|
11
|
+
stop: () => Promise<void>;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* The scheduling half of actions: a producer, a consumer and the store they meet in.
|
|
15
|
+
*
|
|
16
|
+
* Both halves run in EVERY replica by default, and neither needs to know about the others. The producer is safe to
|
|
17
|
+
* duplicate because a fire's job id is the fire's own instant; the consumer is safe to duplicate because a claim is
|
|
18
|
+
* atomic. What a deployment tunes is how many jobs each replica carries (`workers`) and whether it produces at all
|
|
19
|
+
* — a pod dedicated to running jobs sets `produce: false`, a pod serving pages sets `workers: 0`.
|
|
20
|
+
*
|
|
21
|
+
* With no `queue` supplied this is one process's memory, which is right for a single replica and wrong the moment
|
|
22
|
+
* there are two. That is a sentence rather than a silent behaviour because the failure is invisible: everything
|
|
23
|
+
* works, and the nightly email goes out once per replica. The workers of one server are one replica: they share
|
|
24
|
+
* the primary's queue, and only one of them runs the scheduler and the jobs (`runsFleetJobs`).
|
|
25
|
+
*/
|
|
26
|
+
export declare const createActionJobs: (config: ActionJobsConfig, module: ActionsModule, lookups: ActionLookups) => ActionJobs;
|
|
27
|
+
export { createMemoryJobQueue } from './memoryQueue';
|
|
28
|
+
export { createScheduler } from './scheduler';
|
|
29
|
+
export { createJobWorker } from './worker';
|
|
30
|
+
export { DEFAULT_MAX_ATTEMPTS, scheduleFor, scheduleJobId, schedulesFor } from './schedules';
|
|
31
|
+
export type { MemoryJobQueueOptions } from './memoryQueue';
|
|
32
|
+
export type { Scheduler, SchedulerOptions, SweepResult } from './scheduler';
|
|
33
|
+
export type { JobWorker, JobWorkerOptions } from './worker';
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { JOB_QUEUE_METHODS, createMemoryJobQueue } from "./memoryQueue.js";
|
|
2
|
+
import { DEFAULT_MAX_ATTEMPTS, scheduleFor, scheduleJobId, schedulesFor } from "./schedules.js";
|
|
3
|
+
import { createScheduler } from "./scheduler.js";
|
|
4
|
+
import { createJobWorker } from "./worker.js";
|
|
5
|
+
import { fleetStore } from "../../../core/server/fleet/link.js";
|
|
6
|
+
//#region src/modules/actions/jobs/index.ts
|
|
7
|
+
/**
|
|
8
|
+
* The scheduling half of actions: a producer, a consumer and the store they meet in.
|
|
9
|
+
*
|
|
10
|
+
* Both halves run in EVERY replica by default, and neither needs to know about the others. The producer is safe to
|
|
11
|
+
* duplicate because a fire's job id is the fire's own instant; the consumer is safe to duplicate because a claim is
|
|
12
|
+
* atomic. What a deployment tunes is how many jobs each replica carries (`workers`) and whether it produces at all
|
|
13
|
+
* — a pod dedicated to running jobs sets `produce: false`, a pod serving pages sets `workers: 0`.
|
|
14
|
+
*
|
|
15
|
+
* With no `queue` supplied this is one process's memory, which is right for a single replica and wrong the moment
|
|
16
|
+
* there are two. That is a sentence rather than a silent behaviour because the failure is invisible: everything
|
|
17
|
+
* works, and the nightly email goes out once per replica. The workers of one server are one replica: they share
|
|
18
|
+
* the primary's queue, and only one of them runs the scheduler and the jobs (`runsFleetJobs`).
|
|
19
|
+
*/
|
|
20
|
+
var createActionJobs = (config, module, lookups) => {
|
|
21
|
+
const queue = config.queue ?? fleetStore("actions.jobs", JOB_QUEUE_METHODS) ?? createMemoryJobQueue();
|
|
22
|
+
const { produce = true, workers = 4 } = config;
|
|
23
|
+
const scheduler = createScheduler({
|
|
24
|
+
queue,
|
|
25
|
+
lookups,
|
|
26
|
+
...config.environment ? { environment: config.environment } : {},
|
|
27
|
+
...config.schedulePollMs ? { pollMs: config.schedulePollMs } : {},
|
|
28
|
+
...config.maxAttempts ? { maxAttempts: config.maxAttempts } : {},
|
|
29
|
+
...config.reconcileMs ? { reconcileMs: config.reconcileMs } : {},
|
|
30
|
+
...config.spaces ? { spaces: config.spaces } : {},
|
|
31
|
+
...config.onError ? { onError: config.onError } : {}
|
|
32
|
+
});
|
|
33
|
+
const worker = createJobWorker({
|
|
34
|
+
queue,
|
|
35
|
+
lookups,
|
|
36
|
+
module,
|
|
37
|
+
workers,
|
|
38
|
+
...config.pollMs ? { pollMs: config.pollMs } : {},
|
|
39
|
+
...config.leaseMs ? { leaseMs: config.leaseMs } : {},
|
|
40
|
+
...config.backoff ? { backoff: config.backoff } : {},
|
|
41
|
+
...config.workerId ? { workerId: config.workerId } : {},
|
|
42
|
+
...config.onError ? { onError: config.onError } : {}
|
|
43
|
+
});
|
|
44
|
+
return {
|
|
45
|
+
queue,
|
|
46
|
+
scheduler,
|
|
47
|
+
worker,
|
|
48
|
+
start: () => {
|
|
49
|
+
if (produce) scheduler.start();
|
|
50
|
+
worker.start();
|
|
51
|
+
},
|
|
52
|
+
stop: async () => {
|
|
53
|
+
scheduler.stop();
|
|
54
|
+
await worker.stop();
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
//#endregion
|
|
59
|
+
export { DEFAULT_MAX_ATTEMPTS, createActionJobs, createJobWorker, createMemoryJobQueue, createScheduler, scheduleFor, scheduleJobId, schedulesFor };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { StoreMethods } from '../../../core/server/fleet/channel';
|
|
2
|
+
import { ActionJobQueue } from '@plitzi/sdk-shared';
|
|
3
|
+
export type MemoryJobQueueOptions = {
|
|
4
|
+
/**
|
|
5
|
+
* How many finished jobs to keep before the oldest are dropped.
|
|
6
|
+
*
|
|
7
|
+
* A bound rather than a retention period, because this store has no eviction of its own and an unbounded history
|
|
8
|
+
* in a long-lived process is a leak with a nice name. A deployment that wants jobs it can still read next week
|
|
9
|
+
* supplies a queue backed by something that survives a restart.
|
|
10
|
+
*/
|
|
11
|
+
retainFinished?: number;
|
|
12
|
+
/**
|
|
13
|
+
* What this queue calls now, in epoch ms.
|
|
14
|
+
*
|
|
15
|
+
* The seam that makes a lease, a backoff and an overdue schedule testable without waiting for one — and the
|
|
16
|
+
* shape of the rule a shared store keeps too: everything here reads ONE clock, and it is the store's.
|
|
17
|
+
*/
|
|
18
|
+
clock?: () => number;
|
|
19
|
+
};
|
|
20
|
+
/** Every method of the queue, for the copy a server's workers share (see `fleet/stores.ts`). */
|
|
21
|
+
export declare const JOB_QUEUE_METHODS: StoreMethods<ActionJobQueue>;
|
|
22
|
+
/**
|
|
23
|
+
* The default queue: one process's Maps.
|
|
24
|
+
*
|
|
25
|
+
* Correct for a deployment that runs ONE replica, which is most self-hosted ones, and honest about the rest — a
|
|
26
|
+
* second replica running on this gets its own schedules and its own jobs, so a nightly digest goes out twice. The
|
|
27
|
+
* cure is any store the replicas share, behind the same {@link ActionJobQueue} seam.
|
|
28
|
+
*
|
|
29
|
+
* It keeps the contract exactly, rather than approximately: enqueue is idempotent by id, a claim reaps lapsed
|
|
30
|
+
* leases, and every instant is read here rather than accepted from a caller. A test that passes against this one
|
|
31
|
+
* is testing the rules a shared store has to keep too.
|
|
32
|
+
*/
|
|
33
|
+
export declare const createMemoryJobQueue: ({ retainFinished, clock }?: MemoryJobQueueOptions) => ActionJobQueue;
|