reqon-dsl 0.2.0
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/.claude/settings.local.json +31 -0
- package/.claude/skills/api-integration.md +125 -0
- package/.claude/skills/database-schema.md +51 -0
- package/.claude/skills/dsl-design.md +80 -0
- package/.claude/skills/property-testing.md +143 -0
- package/.claude/skills/reqon/SKILL.md +44 -0
- package/.claude/skills/reqon/references/examples.md +206 -0
- package/.claude/skills/reqon/references/syntax.md +263 -0
- package/.claude/skills/vscode-extension.md +113 -0
- package/.github/dependabot.yml +32 -0
- package/.github/pull_request_template.md +21 -0
- package/.github/workflows/ci.yml +174 -0
- package/.github/workflows/release.yml +73 -0
- package/CLAUDE.md +72 -0
- package/CONTRIBUTING.md +161 -0
- package/README.md +235 -0
- package/TODO.md +51 -0
- package/dist/ast/index.d.ts +1 -0
- package/dist/ast/index.js +1 -0
- package/dist/ast/nodes.d.ts +237 -0
- package/dist/ast/nodes.js +12 -0
- package/dist/auth/auth.test.d.ts +1 -0
- package/dist/auth/auth.test.js +255 -0
- package/dist/auth/circuit-breaker.d.ts +115 -0
- package/dist/auth/circuit-breaker.js +267 -0
- package/dist/auth/credentials.d.ts +91 -0
- package/dist/auth/credentials.js +169 -0
- package/dist/auth/index.d.ts +5 -0
- package/dist/auth/index.js +8 -0
- package/dist/auth/oauth2-provider.d.ts +41 -0
- package/dist/auth/oauth2-provider.js +131 -0
- package/dist/auth/rate-limiter.d.ts +61 -0
- package/dist/auth/rate-limiter.js +380 -0
- package/dist/auth/token-store.d.ts +30 -0
- package/dist/auth/token-store.js +148 -0
- package/dist/auth/types.d.ts +142 -0
- package/dist/auth/types.js +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +270 -0
- package/dist/errors/errors.test.d.ts +1 -0
- package/dist/errors/errors.test.js +165 -0
- package/dist/errors/index.d.ts +83 -0
- package/dist/errors/index.js +159 -0
- package/dist/execution/execution.test.d.ts +1 -0
- package/dist/execution/execution.test.js +246 -0
- package/dist/execution/index.d.ts +4 -0
- package/dist/execution/index.js +2 -0
- package/dist/execution/state.d.ts +136 -0
- package/dist/execution/state.js +82 -0
- package/dist/execution/store.d.ts +52 -0
- package/dist/execution/store.js +120 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +57 -0
- package/dist/integration.test.d.ts +1 -0
- package/dist/integration.test.js +168 -0
- package/dist/interpreter/context.d.ts +15 -0
- package/dist/interpreter/context.js +29 -0
- package/dist/interpreter/evaluator.d.ts +5 -0
- package/dist/interpreter/evaluator.js +223 -0
- package/dist/interpreter/evaluator.test.d.ts +1 -0
- package/dist/interpreter/evaluator.test.js +512 -0
- package/dist/interpreter/executor.d.ts +131 -0
- package/dist/interpreter/executor.js +663 -0
- package/dist/interpreter/fetch-handler.d.ts +43 -0
- package/dist/interpreter/fetch-handler.js +203 -0
- package/dist/interpreter/http.d.ts +57 -0
- package/dist/interpreter/http.js +210 -0
- package/dist/interpreter/http.test.d.ts +1 -0
- package/dist/interpreter/http.test.js +299 -0
- package/dist/interpreter/index.d.ts +7 -0
- package/dist/interpreter/index.js +7 -0
- package/dist/interpreter/pagination.d.ts +63 -0
- package/dist/interpreter/pagination.js +155 -0
- package/dist/interpreter/progress.test.d.ts +1 -0
- package/dist/interpreter/progress.test.js +216 -0
- package/dist/interpreter/schema-matcher.d.ts +16 -0
- package/dist/interpreter/schema-matcher.js +136 -0
- package/dist/interpreter/schema-matcher.test.d.ts +1 -0
- package/dist/interpreter/schema-matcher.test.js +122 -0
- package/dist/interpreter/signals.d.ts +57 -0
- package/dist/interpreter/signals.js +73 -0
- package/dist/interpreter/step-handlers/for-handler.d.ts +17 -0
- package/dist/interpreter/step-handlers/for-handler.js +51 -0
- package/dist/interpreter/step-handlers/index.d.ts +8 -0
- package/dist/interpreter/step-handlers/index.js +8 -0
- package/dist/interpreter/step-handlers/map-handler.d.ts +10 -0
- package/dist/interpreter/step-handlers/map-handler.js +20 -0
- package/dist/interpreter/step-handlers/match-handler.d.ts +27 -0
- package/dist/interpreter/step-handlers/match-handler.js +61 -0
- package/dist/interpreter/step-handlers/store-handler.d.ts +13 -0
- package/dist/interpreter/step-handlers/store-handler.js +66 -0
- package/dist/interpreter/step-handlers/types.d.ts +15 -0
- package/dist/interpreter/step-handlers/types.js +1 -0
- package/dist/interpreter/step-handlers/validate-handler.d.ts +10 -0
- package/dist/interpreter/step-handlers/validate-handler.js +26 -0
- package/dist/interpreter/step-handlers/webhook-handler.d.ts +36 -0
- package/dist/interpreter/step-handlers/webhook-handler.js +104 -0
- package/dist/lexer/index.d.ts +10 -0
- package/dist/lexer/index.js +12 -0
- package/dist/lexer/lexer.d.ts +24 -0
- package/dist/lexer/lexer.js +264 -0
- package/dist/lexer/lexer.test.d.ts +1 -0
- package/dist/lexer/lexer.test.js +259 -0
- package/dist/lexer/tokens.d.ts +69 -0
- package/dist/lexer/tokens.js +146 -0
- package/dist/loader/index.d.ts +36 -0
- package/dist/loader/index.js +220 -0
- package/dist/loader/loader.test.d.ts +1 -0
- package/dist/loader/loader.test.js +287 -0
- package/dist/oas/index.d.ts +4 -0
- package/dist/oas/index.js +2 -0
- package/dist/oas/loader.d.ts +21 -0
- package/dist/oas/loader.js +82 -0
- package/dist/oas/oas.test.d.ts +1 -0
- package/dist/oas/oas.test.js +218 -0
- package/dist/oas/validator.d.ts +12 -0
- package/dist/oas/validator.js +227 -0
- package/dist/parser/base.d.ts +33 -0
- package/dist/parser/base.js +97 -0
- package/dist/parser/expressions.d.ts +27 -0
- package/dist/parser/expressions.js +248 -0
- package/dist/parser/expressions.test.d.ts +1 -0
- package/dist/parser/expressions.test.js +378 -0
- package/dist/parser/index.d.ts +3 -0
- package/dist/parser/index.js +3 -0
- package/dist/parser/match.test.d.ts +1 -0
- package/dist/parser/match.test.js +254 -0
- package/dist/parser/parser.d.ts +68 -0
- package/dist/parser/parser.js +1229 -0
- package/dist/parser/parser.test.d.ts +1 -0
- package/dist/parser/parser.test.js +333 -0
- package/dist/parser/schedule.test.d.ts +1 -0
- package/dist/parser/schedule.test.js +241 -0
- package/dist/plugin.d.ts +35 -0
- package/dist/plugin.js +68 -0
- package/dist/scheduler/cron-parser.d.ts +32 -0
- package/dist/scheduler/cron-parser.js +198 -0
- package/dist/scheduler/cron-parser.test.d.ts +1 -0
- package/dist/scheduler/cron-parser.test.js +188 -0
- package/dist/scheduler/index.d.ts +3 -0
- package/dist/scheduler/index.js +2 -0
- package/dist/scheduler/scheduler.d.ts +81 -0
- package/dist/scheduler/scheduler.js +376 -0
- package/dist/scheduler/types.d.ts +65 -0
- package/dist/scheduler/types.js +1 -0
- package/dist/stores/factory.d.ts +36 -0
- package/dist/stores/factory.js +73 -0
- package/dist/stores/file.d.ts +60 -0
- package/dist/stores/file.js +173 -0
- package/dist/stores/file.test.d.ts +1 -0
- package/dist/stores/file.test.js +165 -0
- package/dist/stores/index.d.ts +6 -0
- package/dist/stores/index.js +5 -0
- package/dist/stores/memory.d.ts +19 -0
- package/dist/stores/memory.js +51 -0
- package/dist/stores/memory.test.d.ts +1 -0
- package/dist/stores/memory.test.js +157 -0
- package/dist/stores/postgrest.d.ts +55 -0
- package/dist/stores/postgrest.js +217 -0
- package/dist/stores/stores.test.d.ts +1 -0
- package/dist/stores/stores.test.js +158 -0
- package/dist/stores/types.d.ts +31 -0
- package/dist/stores/types.js +26 -0
- package/dist/sync/index.d.ts +4 -0
- package/dist/sync/index.js +2 -0
- package/dist/sync/state.d.ts +69 -0
- package/dist/sync/state.js +66 -0
- package/dist/sync/store.d.ts +49 -0
- package/dist/sync/store.js +93 -0
- package/dist/sync/sync.test.d.ts +1 -0
- package/dist/sync/sync.test.js +221 -0
- package/dist/utils/async.d.ts +7 -0
- package/dist/utils/async.js +9 -0
- package/dist/utils/file.d.ts +38 -0
- package/dist/utils/file.js +92 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/logger.d.ts +34 -0
- package/dist/utils/logger.js +39 -0
- package/dist/utils/path.d.ts +12 -0
- package/dist/utils/path.js +41 -0
- package/dist/webhook/index.d.ts +8 -0
- package/dist/webhook/index.js +7 -0
- package/dist/webhook/server.d.ts +84 -0
- package/dist/webhook/server.js +319 -0
- package/dist/webhook/store.d.ts +67 -0
- package/dist/webhook/store.js +193 -0
- package/dist/webhook/types.d.ts +88 -0
- package/dist/webhook/types.js +6 -0
- package/docusaurus/README.md +41 -0
- package/docusaurus/docs/advanced/execution-state.md +283 -0
- package/docusaurus/docs/advanced/extending-reqon.md +388 -0
- package/docusaurus/docs/advanced/multi-file-missions.md +250 -0
- package/docusaurus/docs/advanced/parallel-execution.md +353 -0
- package/docusaurus/docs/api-reference.md +443 -0
- package/docusaurus/docs/authentication/api-key.md +339 -0
- package/docusaurus/docs/authentication/basic.md +276 -0
- package/docusaurus/docs/authentication/bearer.md +282 -0
- package/docusaurus/docs/authentication/oauth2.md +317 -0
- package/docusaurus/docs/authentication/overview.md +251 -0
- package/docusaurus/docs/cli.md +229 -0
- package/docusaurus/docs/core-concepts/actions.md +286 -0
- package/docusaurus/docs/core-concepts/missions.md +264 -0
- package/docusaurus/docs/core-concepts/schemas.md +353 -0
- package/docusaurus/docs/core-concepts/sources.md +339 -0
- package/docusaurus/docs/core-concepts/stores.md +332 -0
- package/docusaurus/docs/dsl-syntax/expressions.md +361 -0
- package/docusaurus/docs/dsl-syntax/fetch.md +293 -0
- package/docusaurus/docs/dsl-syntax/for-loops.md +324 -0
- package/docusaurus/docs/dsl-syntax/map.md +345 -0
- package/docusaurus/docs/dsl-syntax/match.md +387 -0
- package/docusaurus/docs/dsl-syntax/pipelines.md +397 -0
- package/docusaurus/docs/dsl-syntax/validate.md +401 -0
- package/docusaurus/docs/error-handling/dead-letter-queues.md +399 -0
- package/docusaurus/docs/error-handling/flow-control.md +337 -0
- package/docusaurus/docs/error-handling/retry-strategies.md +368 -0
- package/docusaurus/docs/examples.md +488 -0
- package/docusaurus/docs/getting-started.md +256 -0
- package/docusaurus/docs/http/circuit-breaker.md +401 -0
- package/docusaurus/docs/http/incremental-sync.md +394 -0
- package/docusaurus/docs/http/pagination.md +361 -0
- package/docusaurus/docs/http/rate-limiting.md +383 -0
- package/docusaurus/docs/http/requests.md +328 -0
- package/docusaurus/docs/http/retry.md +402 -0
- package/docusaurus/docs/intro.md +90 -0
- package/docusaurus/docs/openapi/loading-specs.md +305 -0
- package/docusaurus/docs/openapi/operation-calls.md +314 -0
- package/docusaurus/docs/openapi/overview.md +212 -0
- package/docusaurus/docs/openapi/response-validation.md +344 -0
- package/docusaurus/docs/scheduling/cron.md +305 -0
- package/docusaurus/docs/scheduling/daemon-mode.md +317 -0
- package/docusaurus/docs/scheduling/intervals.md +289 -0
- package/docusaurus/docs/scheduling/overview.md +231 -0
- package/docusaurus/docs/stores/custom-adapters.md +376 -0
- package/docusaurus/docs/stores/file.md +236 -0
- package/docusaurus/docs/stores/memory.md +193 -0
- package/docusaurus/docs/stores/overview.md +274 -0
- package/docusaurus/docs/stores/postgrest.md +316 -0
- package/docusaurus/docusaurus.config.ts +148 -0
- package/docusaurus/package-lock.json +18029 -0
- package/docusaurus/package.json +47 -0
- package/docusaurus/sidebars.ts +155 -0
- package/docusaurus/src/components/HomepageFeatures/index.tsx +105 -0
- package/docusaurus/src/components/HomepageFeatures/styles.module.css +12 -0
- package/docusaurus/src/css/custom.css +169 -0
- package/docusaurus/src/pages/index.module.css +48 -0
- package/docusaurus/src/pages/index.tsx +110 -0
- package/docusaurus/src/pages/markdown-page.md +7 -0
- package/docusaurus/static/.nojekyll +0 -0
- package/docusaurus/static/img/docusaurus-social-card.jpg +0 -0
- package/docusaurus/static/img/docusaurus.png +0 -0
- package/docusaurus/static/img/favicon.ico +0 -0
- package/docusaurus/static/img/logo.svg +10 -0
- package/docusaurus/static/img/undraw_docusaurus_mountain.svg +171 -0
- package/docusaurus/static/img/undraw_docusaurus_react.svg +170 -0
- package/docusaurus/static/img/undraw_docusaurus_tree.svg +40 -0
- package/docusaurus/tsconfig.json +8 -0
- package/examples/README.md +112 -0
- package/examples/error-handling/README.md +150 -0
- package/examples/error-handling/payment-processor.vague +287 -0
- package/examples/github-sync/README.md +74 -0
- package/examples/github-sync/fetch-issues.vague +47 -0
- package/examples/github-sync/fetch-prs.vague +40 -0
- package/examples/github-sync/mission.vague +101 -0
- package/examples/github-sync/normalize.vague +70 -0
- package/examples/jsonplaceholder/README.md +28 -0
- package/examples/jsonplaceholder/posts.vague +48 -0
- package/examples/petstore/README.md +35 -0
- package/examples/petstore/openapi.yaml +97 -0
- package/examples/petstore/sync.vague +52 -0
- package/examples/temporal-comparison/README.md +297 -0
- package/examples/temporal-comparison/reconciliation.vague +355 -0
- package/examples/temporal-comparison/temporal/activities/index.ts +8 -0
- package/examples/temporal-comparison/temporal/activities/shipstation.ts +225 -0
- package/examples/temporal-comparison/temporal/activities/shopify.ts +257 -0
- package/examples/temporal-comparison/temporal/activities/storage.ts +198 -0
- package/examples/temporal-comparison/temporal/activities/stripe.ts +169 -0
- package/examples/temporal-comparison/temporal/activities/validation.ts +205 -0
- package/examples/temporal-comparison/temporal/client/schedule.ts +218 -0
- package/examples/temporal-comparison/temporal/config/retry.ts +63 -0
- package/examples/temporal-comparison/temporal/types/index.ts +129 -0
- package/examples/temporal-comparison/temporal/workers/main.ts +130 -0
- package/examples/temporal-comparison/temporal/workflows/orderReconciliation.ts +262 -0
- package/examples/xero/README.md +88 -0
- package/examples/xero/invoices.vague +189 -0
- package/package.json +40 -0
- package/src/api-integration.test.ts +954 -0
- package/src/ast/index.ts +1 -0
- package/src/ast/nodes.ts +310 -0
- package/src/auth/auth.test.ts +326 -0
- package/src/auth/circuit-breaker.test.ts +390 -0
- package/src/auth/circuit-breaker.ts +379 -0
- package/src/auth/credentials.test.ts +273 -0
- package/src/auth/credentials.ts +246 -0
- package/src/auth/index.ts +40 -0
- package/src/auth/oauth2-provider.ts +177 -0
- package/src/auth/rate-limiter.ts +459 -0
- package/src/auth/token-store.ts +177 -0
- package/src/auth/types.ts +159 -0
- package/src/benchmark/e2e.bench.ts +288 -0
- package/src/benchmark/evaluator.bench.ts +331 -0
- package/src/benchmark/fixtures.ts +295 -0
- package/src/benchmark/index.ts +108 -0
- package/src/benchmark/lexer.bench.ts +69 -0
- package/src/benchmark/parser.bench.ts +103 -0
- package/src/benchmark/resilience.bench.ts +193 -0
- package/src/benchmark/store.bench.ts +147 -0
- package/src/benchmark/utils.ts +230 -0
- package/src/cli.ts +313 -0
- package/src/errors/errors.test.ts +234 -0
- package/src/errors/index.ts +223 -0
- package/src/execution/execution.test.ts +307 -0
- package/src/execution/index.ts +21 -0
- package/src/execution/state.ts +207 -0
- package/src/execution/store.ts +188 -0
- package/src/index.ts +169 -0
- package/src/integration.test.ts +192 -0
- package/src/interpreter/context.ts +57 -0
- package/src/interpreter/evaluator.test.ts +796 -0
- package/src/interpreter/evaluator.ts +245 -0
- package/src/interpreter/executor.ts +946 -0
- package/src/interpreter/fetch-handler.ts +302 -0
- package/src/interpreter/http.test.ts +423 -0
- package/src/interpreter/http.ts +308 -0
- package/src/interpreter/index.ts +32 -0
- package/src/interpreter/pagination.ts +207 -0
- package/src/interpreter/progress.test.ts +276 -0
- package/src/interpreter/schema-matcher.test.ts +160 -0
- package/src/interpreter/schema-matcher.ts +168 -0
- package/src/interpreter/signals.ts +73 -0
- package/src/interpreter/step-handlers/for-handler.ts +65 -0
- package/src/interpreter/step-handlers/index.ts +17 -0
- package/src/interpreter/step-handlers/map-handler.ts +24 -0
- package/src/interpreter/step-handlers/match-handler.ts +101 -0
- package/src/interpreter/step-handlers/store-handler.ts +78 -0
- package/src/interpreter/step-handlers/types.ts +17 -0
- package/src/interpreter/step-handlers/validate-handler.ts +30 -0
- package/src/interpreter/step-handlers/webhook-handler.ts +142 -0
- package/src/lexer/index.ts +18 -0
- package/src/lexer/lexer.test.ts +316 -0
- package/src/lexer/tokens.ts +179 -0
- package/src/loader/index.ts +288 -0
- package/src/loader/loader.test.ts +360 -0
- package/src/oas/index.ts +4 -0
- package/src/oas/loader.ts +126 -0
- package/src/oas/oas.test.ts +254 -0
- package/src/oas/validator.ts +299 -0
- package/src/parser/base.ts +124 -0
- package/src/parser/expressions.test.ts +525 -0
- package/src/parser/expressions.ts +314 -0
- package/src/parser/index.ts +3 -0
- package/src/parser/match.test.ts +296 -0
- package/src/parser/parser.test.ts +739 -0
- package/src/parser/parser.ts +1469 -0
- package/src/parser/schedule.test.ts +287 -0
- package/src/parser/webhook.test.ts +248 -0
- package/src/plugin.ts +83 -0
- package/src/scheduler/cron-parser.test.ts +236 -0
- package/src/scheduler/cron-parser.ts +236 -0
- package/src/scheduler/index.ts +10 -0
- package/src/scheduler/scheduler.ts +443 -0
- package/src/scheduler/types.ts +71 -0
- package/src/stores/factory.ts +104 -0
- package/src/stores/file.test.ts +276 -0
- package/src/stores/file.ts +211 -0
- package/src/stores/index.ts +6 -0
- package/src/stores/memory.test.ts +238 -0
- package/src/stores/memory.ts +63 -0
- package/src/stores/postgrest.test.ts +488 -0
- package/src/stores/postgrest.ts +263 -0
- package/src/stores/stores.test.ts +197 -0
- package/src/stores/types.ts +58 -0
- package/src/sync/index.ts +16 -0
- package/src/sync/state.ts +126 -0
- package/src/sync/store.ts +139 -0
- package/src/sync/sync.test.ts +271 -0
- package/src/utils/async.ts +10 -0
- package/src/utils/file.ts +106 -0
- package/src/utils/index.ts +14 -0
- package/src/utils/logger.ts +53 -0
- package/src/utils/path.ts +47 -0
- package/src/webhook/index.ts +15 -0
- package/src/webhook/server.test.ts +253 -0
- package/src/webhook/server.ts +389 -0
- package/src/webhook/store.ts +239 -0
- package/src/webhook/types.ts +93 -0
- package/tsconfig.json +17 -0
- package/vitest.config.ts +39 -0
|
@@ -0,0 +1,663 @@
|
|
|
1
|
+
import { isParallelStage } from '../ast/nodes.js';
|
|
2
|
+
import { createContext, setVariable } from './context.js';
|
|
3
|
+
import { evaluate } from './evaluator.js';
|
|
4
|
+
import { HttpClient, BearerAuthProvider, OAuth2AuthProvider } from './http.js';
|
|
5
|
+
import { createStore, resolveStoreType } from '../stores/index.js';
|
|
6
|
+
import { loadOAS } from '../oas/index.js';
|
|
7
|
+
import { AdaptiveRateLimiter } from '../auth/rate-limiter.js';
|
|
8
|
+
import { CircuitBreaker } from '../auth/circuit-breaker.js';
|
|
9
|
+
import { createExecutionState, findResumePoint, FileExecutionStore, } from '../execution/index.js';
|
|
10
|
+
import { FileSyncStore, } from '../sync/index.js';
|
|
11
|
+
import { FetchHandler } from './fetch-handler.js';
|
|
12
|
+
import { ForHandler, MapHandler, ValidateHandler, StoreHandler, MatchHandler, WebhookHandler, SkipSignal, RetrySignal, JumpSignal, QueueSignal, } from './step-handlers/index.js';
|
|
13
|
+
export class MissionExecutor {
|
|
14
|
+
config;
|
|
15
|
+
ctx;
|
|
16
|
+
errors = [];
|
|
17
|
+
actionsRun = [];
|
|
18
|
+
oasSources = new Map();
|
|
19
|
+
sourceConfigs = new Map();
|
|
20
|
+
rateLimiter;
|
|
21
|
+
circuitBreaker;
|
|
22
|
+
executionStore;
|
|
23
|
+
executionState;
|
|
24
|
+
syncStore;
|
|
25
|
+
missionName;
|
|
26
|
+
constructor(config = {}) {
|
|
27
|
+
this.config = config;
|
|
28
|
+
this.ctx = createContext();
|
|
29
|
+
this.rateLimiter = new AdaptiveRateLimiter();
|
|
30
|
+
this.circuitBreaker = new CircuitBreaker();
|
|
31
|
+
// Set up rate limit callbacks with default logging if verbose
|
|
32
|
+
const callbacks = config.rateLimitCallbacks ?? {};
|
|
33
|
+
if (config.verbose && !callbacks.onRateLimited) {
|
|
34
|
+
callbacks.onRateLimited = (event) => {
|
|
35
|
+
console.log(`[Reqon] Rate limited on ${event.source}${event.endpoint ? `:${event.endpoint}` : ''} - ` +
|
|
36
|
+
`waiting ${event.waitSeconds}s (strategy: ${event.strategy})`);
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
if (config.verbose && !callbacks.onResumed) {
|
|
40
|
+
callbacks.onResumed = (event) => {
|
|
41
|
+
console.log(`[Reqon] Rate limit cleared for ${event.source}${event.endpoint ? `:${event.endpoint}` : ''} ` +
|
|
42
|
+
`(waited ${event.waitedSeconds}s)`);
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
if (config.verbose && !callbacks.onWaiting) {
|
|
46
|
+
callbacks.onWaiting = (event) => {
|
|
47
|
+
console.log(`[Reqon] Still waiting for ${event.source}${event.endpoint ? `:${event.endpoint}` : ''} - ` +
|
|
48
|
+
`${event.waitSeconds}s remaining (elapsed: ${event.elapsedSeconds}s)`);
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
this.rateLimiter.setCallbacks(callbacks);
|
|
52
|
+
// Set up circuit breaker callbacks with default logging if verbose
|
|
53
|
+
const cbCallbacks = config.circuitBreakerCallbacks ?? {};
|
|
54
|
+
if (config.verbose && !cbCallbacks.onOpen) {
|
|
55
|
+
cbCallbacks.onOpen = (event) => {
|
|
56
|
+
console.log(`[Reqon] Circuit breaker OPEN for ${event.source}${event.endpoint ? `:${event.endpoint}` : ''} - ` +
|
|
57
|
+
`${event.failures} failures (${event.reason ?? 'threshold exceeded'})`);
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
if (config.verbose && !cbCallbacks.onHalfOpen) {
|
|
61
|
+
cbCallbacks.onHalfOpen = (event) => {
|
|
62
|
+
console.log(`[Reqon] Circuit breaker HALF-OPEN for ${event.source}${event.endpoint ? `:${event.endpoint}` : ''} - ` +
|
|
63
|
+
`testing recovery`);
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
if (config.verbose && !cbCallbacks.onClose) {
|
|
67
|
+
cbCallbacks.onClose = (event) => {
|
|
68
|
+
console.log(`[Reqon] Circuit breaker CLOSED for ${event.source}${event.endpoint ? `:${event.endpoint}` : ''} - ` +
|
|
69
|
+
`recovery successful`);
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
if (config.verbose && !cbCallbacks.onRejected) {
|
|
73
|
+
cbCallbacks.onRejected = (event) => {
|
|
74
|
+
console.log(`[Reqon] Request REJECTED by circuit breaker for ${event.source}${event.endpoint ? `:${event.endpoint}` : ''} - ` +
|
|
75
|
+
`retry in ${Math.ceil(event.nextAttemptIn / 1000)}s`);
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
this.circuitBreaker.setCallbacks(cbCallbacks);
|
|
79
|
+
// Initialize execution store if persistence enabled
|
|
80
|
+
if (config.persistState) {
|
|
81
|
+
this.executionStore = config.executionStore ?? new FileExecutionStore(`${config.dataDir ?? '.reqon-data'}/executions`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async execute(program) {
|
|
85
|
+
const startTime = Date.now();
|
|
86
|
+
// Find mission definition
|
|
87
|
+
const mission = program.statements.find((s) => s.type === 'MissionDefinition');
|
|
88
|
+
if (!mission) {
|
|
89
|
+
return {
|
|
90
|
+
success: false,
|
|
91
|
+
duration: Date.now() - startTime,
|
|
92
|
+
actionsRun: [],
|
|
93
|
+
errors: [{ action: '', step: '', message: 'No mission found in program' }],
|
|
94
|
+
stores: this.ctx.stores,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
// Initialize or resume execution state
|
|
98
|
+
await this.initializeExecutionState(mission);
|
|
99
|
+
try {
|
|
100
|
+
await this.executeMission(mission);
|
|
101
|
+
// Mark execution as completed
|
|
102
|
+
if (this.executionState) {
|
|
103
|
+
this.executionState.status = 'completed';
|
|
104
|
+
this.executionState.completedAt = new Date();
|
|
105
|
+
this.executionState.duration = Date.now() - startTime;
|
|
106
|
+
await this.saveExecutionState();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
this.errors.push({
|
|
111
|
+
action: 'mission',
|
|
112
|
+
step: 'execute',
|
|
113
|
+
message: error.message,
|
|
114
|
+
details: error,
|
|
115
|
+
});
|
|
116
|
+
// Mark execution as failed
|
|
117
|
+
if (this.executionState) {
|
|
118
|
+
this.executionState.status = 'failed';
|
|
119
|
+
this.executionState.completedAt = new Date();
|
|
120
|
+
this.executionState.duration = Date.now() - startTime;
|
|
121
|
+
await this.saveExecutionState();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const duration = Date.now() - startTime;
|
|
125
|
+
const success = this.errors.length === 0;
|
|
126
|
+
// Emit onExecutionComplete callback - count stages in a single pass
|
|
127
|
+
const stageCounts = this.executionState?.stages.reduce((acc, s) => {
|
|
128
|
+
if (s.status === 'completed')
|
|
129
|
+
acc.completed++;
|
|
130
|
+
else if (s.status === 'failed')
|
|
131
|
+
acc.failed++;
|
|
132
|
+
return acc;
|
|
133
|
+
}, { completed: 0, failed: 0 });
|
|
134
|
+
const stagesCompleted = stageCounts?.completed ?? this.actionsRun.length;
|
|
135
|
+
const stagesFailed = stageCounts?.failed ?? (success ? 0 : 1);
|
|
136
|
+
this.config.progress?.onExecutionComplete?.({
|
|
137
|
+
executionId: this.executionState?.id ?? 'ephemeral',
|
|
138
|
+
mission: mission.name,
|
|
139
|
+
success,
|
|
140
|
+
duration,
|
|
141
|
+
stagesCompleted,
|
|
142
|
+
stagesFailed,
|
|
143
|
+
errors: this.errors,
|
|
144
|
+
});
|
|
145
|
+
return {
|
|
146
|
+
success,
|
|
147
|
+
duration,
|
|
148
|
+
actionsRun: this.actionsRun,
|
|
149
|
+
errors: this.errors,
|
|
150
|
+
stores: this.ctx.stores,
|
|
151
|
+
executionId: this.executionState?.id,
|
|
152
|
+
state: this.executionState,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
async initializeExecutionState(mission) {
|
|
156
|
+
let isResume = false;
|
|
157
|
+
if (this.executionStore) {
|
|
158
|
+
// Resume from previous execution?
|
|
159
|
+
if (this.config.resumeFrom) {
|
|
160
|
+
const previous = await this.executionStore.load(this.config.resumeFrom);
|
|
161
|
+
if (previous) {
|
|
162
|
+
this.executionState = previous;
|
|
163
|
+
this.executionState.status = 'running';
|
|
164
|
+
this.log(`Resuming execution ${previous.id} from previous run`);
|
|
165
|
+
await this.saveExecutionState();
|
|
166
|
+
isResume = true;
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
this.log(`Warning: Could not find execution ${this.config.resumeFrom} to resume`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (!this.executionState) {
|
|
173
|
+
// Create new execution state
|
|
174
|
+
const stages = mission.pipeline.stages.map((s) => this.getStageName(s));
|
|
175
|
+
this.executionState = createExecutionState({
|
|
176
|
+
mission: mission.name,
|
|
177
|
+
stages,
|
|
178
|
+
metadata: this.config.metadata,
|
|
179
|
+
});
|
|
180
|
+
this.executionState.status = 'running';
|
|
181
|
+
await this.saveExecutionState();
|
|
182
|
+
this.log(`Started execution ${this.executionState.id}`);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
// Emit onExecutionStart callback
|
|
186
|
+
this.config.progress?.onExecutionStart?.({
|
|
187
|
+
executionId: this.executionState?.id ?? 'ephemeral',
|
|
188
|
+
mission: mission.name,
|
|
189
|
+
stageCount: mission.pipeline.stages.length,
|
|
190
|
+
isResume,
|
|
191
|
+
metadata: this.config.metadata,
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
async saveExecutionState() {
|
|
195
|
+
if (this.executionStore && this.executionState) {
|
|
196
|
+
await this.executionStore.save(this.executionState);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
updateStageState(stageIndex, updates) {
|
|
200
|
+
if (!this.executionState)
|
|
201
|
+
return;
|
|
202
|
+
const stage = this.executionState.stages[stageIndex];
|
|
203
|
+
if (!stage)
|
|
204
|
+
return;
|
|
205
|
+
if (updates.status === 'running' && !stage.startedAt) {
|
|
206
|
+
stage.startedAt = new Date();
|
|
207
|
+
}
|
|
208
|
+
if (updates.status === 'completed' || updates.status === 'failed') {
|
|
209
|
+
stage.completedAt = new Date();
|
|
210
|
+
}
|
|
211
|
+
if (updates.status) {
|
|
212
|
+
stage.status = updates.status;
|
|
213
|
+
}
|
|
214
|
+
if (updates.error) {
|
|
215
|
+
stage.error = updates.error;
|
|
216
|
+
this.executionState.errors.push({
|
|
217
|
+
stageIndex,
|
|
218
|
+
action: stage.action,
|
|
219
|
+
step: 'unknown',
|
|
220
|
+
message: updates.error,
|
|
221
|
+
timestamp: new Date(),
|
|
222
|
+
attempt: stage.attempt,
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
async executeMission(mission) {
|
|
227
|
+
this.log(`Executing mission: ${mission.name}`);
|
|
228
|
+
this.missionName = mission.name;
|
|
229
|
+
// Initialize sync store
|
|
230
|
+
this.syncStore = this.config.syncStore ?? new FileSyncStore(mission.name, `${this.config.dataDir ?? '.reqon-data'}/sync`);
|
|
231
|
+
// Initialize sources (HTTP clients)
|
|
232
|
+
for (const source of mission.sources) {
|
|
233
|
+
await this.initializeSource(source);
|
|
234
|
+
}
|
|
235
|
+
// Initialize stores
|
|
236
|
+
for (const store of mission.stores) {
|
|
237
|
+
await this.initializeStore(store);
|
|
238
|
+
}
|
|
239
|
+
// Initialize schemas (for match step schema matching)
|
|
240
|
+
for (const schema of mission.schemas) {
|
|
241
|
+
this.ctx.schemas.set(schema.name, schema);
|
|
242
|
+
this.log(`Registered schema: ${schema.name}`);
|
|
243
|
+
}
|
|
244
|
+
// Build action lookup
|
|
245
|
+
const actions = new Map();
|
|
246
|
+
for (const action of mission.actions) {
|
|
247
|
+
actions.set(action.name, action);
|
|
248
|
+
}
|
|
249
|
+
// Determine resume point
|
|
250
|
+
const resumeIndex = this.executionState ? findResumePoint(this.executionState) : 0;
|
|
251
|
+
if (resumeIndex > 0) {
|
|
252
|
+
const resumeStage = mission.pipeline.stages[resumeIndex];
|
|
253
|
+
const stageName = this.getStageName(resumeStage);
|
|
254
|
+
this.log(`Resuming from stage ${resumeIndex} (${stageName})`);
|
|
255
|
+
}
|
|
256
|
+
// Execute pipeline
|
|
257
|
+
for (let i = 0; i < mission.pipeline.stages.length; i++) {
|
|
258
|
+
const stage = mission.pipeline.stages[i];
|
|
259
|
+
// Skip already completed stages when resuming
|
|
260
|
+
if (i < resumeIndex) {
|
|
261
|
+
this.log(`Skipping ${this.getStageName(stage)} (already completed)`);
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
// Check condition if present
|
|
265
|
+
if (stage.condition) {
|
|
266
|
+
const shouldRun = evaluate(stage.condition, this.ctx);
|
|
267
|
+
if (!shouldRun) {
|
|
268
|
+
this.log(`Skipping ${this.getStageName(stage)} (condition not met)`);
|
|
269
|
+
this.updateStageState(i, { status: 'skipped' });
|
|
270
|
+
await this.saveExecutionState();
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
// Execute stage (parallel or sequential)
|
|
275
|
+
if (isParallelStage(stage)) {
|
|
276
|
+
await this.executeParallelStage(i, stage, actions, mission);
|
|
277
|
+
}
|
|
278
|
+
else if (stage.action) {
|
|
279
|
+
await this.executeSequentialStage(i, stage.action, actions, mission);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
getStageName(stage) {
|
|
284
|
+
if (isParallelStage(stage)) {
|
|
285
|
+
return `[${stage.actions.join(', ')}]`;
|
|
286
|
+
}
|
|
287
|
+
return stage.action ?? 'unknown';
|
|
288
|
+
}
|
|
289
|
+
async executeSequentialStage(stageIndex, actionName, actions, mission) {
|
|
290
|
+
const action = actions.get(actionName);
|
|
291
|
+
if (!action) {
|
|
292
|
+
throw new Error(`Action not found: ${actionName}`);
|
|
293
|
+
}
|
|
294
|
+
// Update stage state to running
|
|
295
|
+
this.updateStageState(stageIndex, { status: 'running' });
|
|
296
|
+
await this.saveExecutionState();
|
|
297
|
+
const stageStartTime = Date.now();
|
|
298
|
+
// Emit onStageStart callback
|
|
299
|
+
this.config.progress?.onStageStart?.({
|
|
300
|
+
executionId: this.executionState?.id ?? 'ephemeral',
|
|
301
|
+
mission: mission.name,
|
|
302
|
+
stageIndex,
|
|
303
|
+
stageName: actionName,
|
|
304
|
+
totalStages: mission.pipeline.stages.length,
|
|
305
|
+
});
|
|
306
|
+
try {
|
|
307
|
+
await this.executeAction(action);
|
|
308
|
+
this.actionsRun.push(action.name);
|
|
309
|
+
// Mark stage as completed
|
|
310
|
+
this.updateStageState(stageIndex, { status: 'completed' });
|
|
311
|
+
await this.saveExecutionState();
|
|
312
|
+
// Emit onStageComplete callback (success)
|
|
313
|
+
this.config.progress?.onStageComplete?.({
|
|
314
|
+
executionId: this.executionState?.id ?? 'ephemeral',
|
|
315
|
+
mission: mission.name,
|
|
316
|
+
stageIndex,
|
|
317
|
+
stageName: actionName,
|
|
318
|
+
totalStages: mission.pipeline.stages.length,
|
|
319
|
+
success: true,
|
|
320
|
+
duration: Date.now() - stageStartTime,
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
catch (error) {
|
|
324
|
+
// Mark stage as failed
|
|
325
|
+
this.updateStageState(stageIndex, {
|
|
326
|
+
status: 'failed',
|
|
327
|
+
error: error.message,
|
|
328
|
+
});
|
|
329
|
+
await this.saveExecutionState();
|
|
330
|
+
// Emit onStageComplete callback (failure)
|
|
331
|
+
this.config.progress?.onStageComplete?.({
|
|
332
|
+
executionId: this.executionState?.id ?? 'ephemeral',
|
|
333
|
+
mission: mission.name,
|
|
334
|
+
stageIndex,
|
|
335
|
+
stageName: actionName,
|
|
336
|
+
totalStages: mission.pipeline.stages.length,
|
|
337
|
+
success: false,
|
|
338
|
+
duration: Date.now() - stageStartTime,
|
|
339
|
+
error: error.message,
|
|
340
|
+
});
|
|
341
|
+
throw error; // Re-throw to stop execution
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
async executeParallelStage(stageIndex, stage, actions, mission) {
|
|
345
|
+
const actionNames = stage.actions;
|
|
346
|
+
const stageName = `[${actionNames.join(', ')}]`;
|
|
347
|
+
// Validate all actions exist
|
|
348
|
+
const actionDefs = [];
|
|
349
|
+
for (const name of actionNames) {
|
|
350
|
+
const action = actions.get(name);
|
|
351
|
+
if (!action) {
|
|
352
|
+
throw new Error(`Action not found: ${name}`);
|
|
353
|
+
}
|
|
354
|
+
actionDefs.push(action);
|
|
355
|
+
}
|
|
356
|
+
// Update stage state to running
|
|
357
|
+
this.updateStageState(stageIndex, { status: 'running' });
|
|
358
|
+
await this.saveExecutionState();
|
|
359
|
+
const stageStartTime = Date.now();
|
|
360
|
+
// Emit onStageStart callback
|
|
361
|
+
this.config.progress?.onStageStart?.({
|
|
362
|
+
executionId: this.executionState?.id ?? 'ephemeral',
|
|
363
|
+
mission: mission.name,
|
|
364
|
+
stageIndex,
|
|
365
|
+
stageName,
|
|
366
|
+
totalStages: mission.pipeline.stages.length,
|
|
367
|
+
});
|
|
368
|
+
this.log(`Executing parallel stage: ${stageName}`);
|
|
369
|
+
try {
|
|
370
|
+
// Execute all actions in parallel
|
|
371
|
+
const results = await Promise.allSettled(actionDefs.map(action => this.executeAction(action)));
|
|
372
|
+
// Check for failures
|
|
373
|
+
const failures = [];
|
|
374
|
+
for (let i = 0; i < results.length; i++) {
|
|
375
|
+
const result = results[i];
|
|
376
|
+
if (result.status === 'fulfilled') {
|
|
377
|
+
this.actionsRun.push(actionDefs[i].name);
|
|
378
|
+
}
|
|
379
|
+
else {
|
|
380
|
+
failures.push({ name: actionDefs[i].name, error: result.reason });
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
if (failures.length > 0) {
|
|
384
|
+
const errorMsg = failures.map(f => `${f.name}: ${f.error.message}`).join('; ');
|
|
385
|
+
throw new Error(`Parallel stage failed: ${errorMsg}`);
|
|
386
|
+
}
|
|
387
|
+
// Mark stage as completed
|
|
388
|
+
this.updateStageState(stageIndex, { status: 'completed' });
|
|
389
|
+
await this.saveExecutionState();
|
|
390
|
+
// Emit onStageComplete callback (success)
|
|
391
|
+
this.config.progress?.onStageComplete?.({
|
|
392
|
+
executionId: this.executionState?.id ?? 'ephemeral',
|
|
393
|
+
mission: mission.name,
|
|
394
|
+
stageIndex,
|
|
395
|
+
stageName,
|
|
396
|
+
totalStages: mission.pipeline.stages.length,
|
|
397
|
+
success: true,
|
|
398
|
+
duration: Date.now() - stageStartTime,
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
catch (error) {
|
|
402
|
+
// Mark stage as failed
|
|
403
|
+
this.updateStageState(stageIndex, {
|
|
404
|
+
status: 'failed',
|
|
405
|
+
error: error.message,
|
|
406
|
+
});
|
|
407
|
+
await this.saveExecutionState();
|
|
408
|
+
// Emit onStageComplete callback (failure)
|
|
409
|
+
this.config.progress?.onStageComplete?.({
|
|
410
|
+
executionId: this.executionState?.id ?? 'ephemeral',
|
|
411
|
+
mission: mission.name,
|
|
412
|
+
stageIndex,
|
|
413
|
+
stageName,
|
|
414
|
+
totalStages: mission.pipeline.stages.length,
|
|
415
|
+
success: false,
|
|
416
|
+
duration: Date.now() - stageStartTime,
|
|
417
|
+
error: error.message,
|
|
418
|
+
});
|
|
419
|
+
throw error; // Re-throw to stop execution
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
async initializeSource(source) {
|
|
423
|
+
// Store source config for later reference
|
|
424
|
+
this.sourceConfigs.set(source.name, source);
|
|
425
|
+
const authConfig = this.config.auth?.[source.name];
|
|
426
|
+
let authProvider;
|
|
427
|
+
if (authConfig) {
|
|
428
|
+
if (authConfig.type === 'bearer' && authConfig.token) {
|
|
429
|
+
authProvider = new BearerAuthProvider(authConfig.token);
|
|
430
|
+
}
|
|
431
|
+
else if (authConfig.type === 'oauth2' && authConfig.accessToken) {
|
|
432
|
+
authProvider = new OAuth2AuthProvider({
|
|
433
|
+
accessToken: authConfig.accessToken,
|
|
434
|
+
refreshToken: authConfig.refreshToken,
|
|
435
|
+
tokenEndpoint: authConfig.tokenEndpoint,
|
|
436
|
+
clientId: authConfig.clientId,
|
|
437
|
+
clientSecret: authConfig.clientSecret,
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
// If source has OAS spec, load it
|
|
442
|
+
let baseUrl = source.config.base;
|
|
443
|
+
if (source.specPath) {
|
|
444
|
+
try {
|
|
445
|
+
const oasSource = await loadOAS(source.specPath);
|
|
446
|
+
this.oasSources.set(source.name, oasSource);
|
|
447
|
+
// Use base URL from OAS if not explicitly provided
|
|
448
|
+
if (!baseUrl) {
|
|
449
|
+
baseUrl = oasSource.baseUrl;
|
|
450
|
+
}
|
|
451
|
+
this.log(`Loaded OAS spec for ${source.name}: ${oasSource.operations.size} operations`);
|
|
452
|
+
}
|
|
453
|
+
catch (error) {
|
|
454
|
+
throw new Error(`Failed to load OAS spec for ${source.name}: ${error.message}`);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
if (!baseUrl) {
|
|
458
|
+
throw new Error(`Source ${source.name} has no base URL (provide 'base' or OAS spec with servers)`);
|
|
459
|
+
}
|
|
460
|
+
// Configure rate limiter for this source
|
|
461
|
+
if (source.config.rateLimit) {
|
|
462
|
+
this.rateLimiter.configure(source.name, {
|
|
463
|
+
strategy: source.config.rateLimit.strategy,
|
|
464
|
+
maxWait: source.config.rateLimit.maxWait,
|
|
465
|
+
fallbackRpm: source.config.rateLimit.fallbackRpm,
|
|
466
|
+
});
|
|
467
|
+
this.log(`Rate limit config for ${source.name}: strategy=${source.config.rateLimit.strategy ?? 'pause'}, ` +
|
|
468
|
+
`maxWait=${source.config.rateLimit.maxWait ?? 300}s`);
|
|
469
|
+
}
|
|
470
|
+
// Configure circuit breaker for this source
|
|
471
|
+
if (source.config.circuitBreaker) {
|
|
472
|
+
this.circuitBreaker.configure(source.name, {
|
|
473
|
+
failureThreshold: source.config.circuitBreaker.failureThreshold,
|
|
474
|
+
// Convert seconds to milliseconds for the circuit breaker
|
|
475
|
+
resetTimeout: source.config.circuitBreaker.resetTimeout
|
|
476
|
+
? source.config.circuitBreaker.resetTimeout * 1000
|
|
477
|
+
: undefined,
|
|
478
|
+
successThreshold: source.config.circuitBreaker.successThreshold,
|
|
479
|
+
failureWindow: source.config.circuitBreaker.failureWindow
|
|
480
|
+
? source.config.circuitBreaker.failureWindow * 1000
|
|
481
|
+
: undefined,
|
|
482
|
+
});
|
|
483
|
+
this.log(`Circuit breaker config for ${source.name}: ` +
|
|
484
|
+
`failureThreshold=${source.config.circuitBreaker.failureThreshold ?? 5}, ` +
|
|
485
|
+
`resetTimeout=${source.config.circuitBreaker.resetTimeout ?? 30}s`);
|
|
486
|
+
}
|
|
487
|
+
const client = new HttpClient({
|
|
488
|
+
baseUrl,
|
|
489
|
+
auth: authProvider,
|
|
490
|
+
rateLimiter: this.rateLimiter,
|
|
491
|
+
circuitBreaker: this.circuitBreaker,
|
|
492
|
+
sourceName: source.name,
|
|
493
|
+
});
|
|
494
|
+
this.ctx.sources.set(source.name, client);
|
|
495
|
+
this.log(`Initialized source: ${source.name}`);
|
|
496
|
+
}
|
|
497
|
+
async initializeStore(store) {
|
|
498
|
+
// Check for custom store adapter
|
|
499
|
+
if (this.config.stores?.[store.name]) {
|
|
500
|
+
this.ctx.stores.set(store.name, this.config.stores[store.name]);
|
|
501
|
+
this.log(`Initialized store: ${store.name} (custom adapter)`);
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
// Use store factory to create appropriate adapter
|
|
505
|
+
const developmentMode = this.config.developmentMode ?? true;
|
|
506
|
+
const storeType = resolveStoreType(store.storeType, developmentMode);
|
|
507
|
+
const adapter = createStore({
|
|
508
|
+
type: storeType,
|
|
509
|
+
name: store.target,
|
|
510
|
+
baseDir: this.config.dataDir,
|
|
511
|
+
});
|
|
512
|
+
this.ctx.stores.set(store.name, adapter);
|
|
513
|
+
this.log(`Initialized store: ${store.name} (${storeType}${storeType !== store.storeType ? ` <- ${store.storeType}` : ''})`);
|
|
514
|
+
}
|
|
515
|
+
async executeAction(action) {
|
|
516
|
+
this.log(`Executing action: ${action.name}`);
|
|
517
|
+
for (const step of action.steps) {
|
|
518
|
+
await this.executeStep(step, action.name);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
async executeStep(step, actionName, ctx) {
|
|
522
|
+
// Use provided context or default to this.ctx
|
|
523
|
+
const execCtx = ctx ?? this.ctx;
|
|
524
|
+
const originalCtx = this.ctx;
|
|
525
|
+
// Temporarily use the provided context
|
|
526
|
+
if (ctx) {
|
|
527
|
+
this.ctx = ctx;
|
|
528
|
+
}
|
|
529
|
+
try {
|
|
530
|
+
switch (step.type) {
|
|
531
|
+
case 'FetchStep':
|
|
532
|
+
await this.executeFetch(step);
|
|
533
|
+
break;
|
|
534
|
+
case 'ForStep':
|
|
535
|
+
await this.executeFor(step, actionName);
|
|
536
|
+
break;
|
|
537
|
+
case 'MapStep':
|
|
538
|
+
await this.executeMap(step);
|
|
539
|
+
break;
|
|
540
|
+
case 'ValidateStep':
|
|
541
|
+
await this.executeValidate(step);
|
|
542
|
+
break;
|
|
543
|
+
case 'StoreStep':
|
|
544
|
+
await this.executeStore(step);
|
|
545
|
+
break;
|
|
546
|
+
case 'MatchStep':
|
|
547
|
+
await this.executeMatch(step, actionName);
|
|
548
|
+
break;
|
|
549
|
+
case 'LetStep':
|
|
550
|
+
await this.executeLet(step);
|
|
551
|
+
break;
|
|
552
|
+
case 'WebhookStep':
|
|
553
|
+
await this.executeWebhook(step);
|
|
554
|
+
break;
|
|
555
|
+
default:
|
|
556
|
+
throw new Error(`Unknown step type: ${step.type}`);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
catch (error) {
|
|
560
|
+
// Re-throw flow control signals without recording as errors
|
|
561
|
+
if (error instanceof SkipSignal ||
|
|
562
|
+
error instanceof RetrySignal ||
|
|
563
|
+
error instanceof JumpSignal ||
|
|
564
|
+
error instanceof QueueSignal) {
|
|
565
|
+
throw error;
|
|
566
|
+
}
|
|
567
|
+
// AbortError is a controlled abort, still record it
|
|
568
|
+
this.errors.push({
|
|
569
|
+
action: actionName,
|
|
570
|
+
step: step.type,
|
|
571
|
+
message: error.message,
|
|
572
|
+
details: error,
|
|
573
|
+
});
|
|
574
|
+
throw error;
|
|
575
|
+
}
|
|
576
|
+
finally {
|
|
577
|
+
// Restore original context
|
|
578
|
+
if (ctx) {
|
|
579
|
+
this.ctx = originalCtx;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
async executeFetch(step) {
|
|
584
|
+
const fetchHandler = new FetchHandler({
|
|
585
|
+
ctx: this.ctx,
|
|
586
|
+
oasSources: this.oasSources,
|
|
587
|
+
sourceConfigs: this.sourceConfigs,
|
|
588
|
+
syncStore: this.syncStore,
|
|
589
|
+
missionName: this.missionName,
|
|
590
|
+
executionId: this.executionState?.id,
|
|
591
|
+
dryRun: this.config.dryRun,
|
|
592
|
+
log: (msg) => this.log(msg),
|
|
593
|
+
});
|
|
594
|
+
const result = await fetchHandler.execute(step);
|
|
595
|
+
this.ctx.response = result.data;
|
|
596
|
+
// Update sync checkpoint after successful fetch
|
|
597
|
+
if (result.checkpointKey && this.syncStore) {
|
|
598
|
+
await fetchHandler.recordCheckpoint(result.checkpointKey, step, result.data);
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
async executeFor(step, actionName) {
|
|
602
|
+
const handler = new ForHandler({
|
|
603
|
+
ctx: this.ctx,
|
|
604
|
+
log: (msg) => this.log(msg),
|
|
605
|
+
executeStep: (s, a, c) => this.executeStep(s, a, c),
|
|
606
|
+
actionName,
|
|
607
|
+
});
|
|
608
|
+
await handler.execute(step);
|
|
609
|
+
}
|
|
610
|
+
async executeMap(step) {
|
|
611
|
+
const handler = new MapHandler({
|
|
612
|
+
ctx: this.ctx,
|
|
613
|
+
log: (msg) => this.log(msg),
|
|
614
|
+
});
|
|
615
|
+
await handler.execute(step);
|
|
616
|
+
}
|
|
617
|
+
async executeValidate(step) {
|
|
618
|
+
const handler = new ValidateHandler({
|
|
619
|
+
ctx: this.ctx,
|
|
620
|
+
log: (msg) => this.log(msg),
|
|
621
|
+
});
|
|
622
|
+
await handler.execute(step);
|
|
623
|
+
}
|
|
624
|
+
async executeStore(step) {
|
|
625
|
+
const handler = new StoreHandler({
|
|
626
|
+
ctx: this.ctx,
|
|
627
|
+
log: (msg) => this.log(msg),
|
|
628
|
+
});
|
|
629
|
+
await handler.execute(step);
|
|
630
|
+
}
|
|
631
|
+
async executeMatch(step, actionName) {
|
|
632
|
+
const handler = new MatchHandler({
|
|
633
|
+
ctx: this.ctx,
|
|
634
|
+
log: (msg) => this.log(msg),
|
|
635
|
+
executeStep: (s, a, c) => this.executeStep(s, a, c),
|
|
636
|
+
actionName,
|
|
637
|
+
});
|
|
638
|
+
await handler.execute(step);
|
|
639
|
+
// Flow control signals (SkipSignal, RetrySignal, etc.) will propagate up
|
|
640
|
+
}
|
|
641
|
+
async executeLet(step) {
|
|
642
|
+
const value = evaluate(step.value, this.ctx);
|
|
643
|
+
setVariable(this.ctx, step.name, value);
|
|
644
|
+
this.log(`Set variable '${step.name}' = ${JSON.stringify(value)}`);
|
|
645
|
+
}
|
|
646
|
+
async executeWebhook(step) {
|
|
647
|
+
if (!this.config.webhookServer) {
|
|
648
|
+
throw new Error('Webhook server not configured. Use --webhook flag or configure webhookServer in executor config.');
|
|
649
|
+
}
|
|
650
|
+
const handler = new WebhookHandler({
|
|
651
|
+
ctx: this.ctx,
|
|
652
|
+
webhookServer: this.config.webhookServer,
|
|
653
|
+
executionId: this.executionState?.id ?? 'ephemeral',
|
|
654
|
+
log: (msg) => this.log(msg),
|
|
655
|
+
});
|
|
656
|
+
await handler.execute(step);
|
|
657
|
+
}
|
|
658
|
+
log(message) {
|
|
659
|
+
if (this.config.verbose) {
|
|
660
|
+
console.log(`[Reqon] ${message}`);
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
}
|