scrapme-flow 0.0.0-stage → 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.
Files changed (171) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +126 -2
  3. package/dist/src/commands/commands.models.d.ts +41 -0
  4. package/dist/src/commands/commands.models.js +2 -0
  5. package/dist/src/commands/commands.models.js.map +1 -0
  6. package/dist/src/commands/save-document.command.d.ts +9 -0
  7. package/dist/src/commands/save-document.command.js +33 -0
  8. package/dist/src/commands/save-document.command.js.map +1 -0
  9. package/dist/src/commands/scrape-page.command.d.ts +20 -0
  10. package/dist/src/commands/scrape-page.command.js +93 -0
  11. package/dist/src/commands/scrape-page.command.js.map +1 -0
  12. package/dist/src/commands/send-mail.command.d.ts +11 -0
  13. package/dist/src/commands/send-mail.command.js +39 -0
  14. package/dist/src/commands/send-mail.command.js.map +1 -0
  15. package/dist/src/config/config-builder.d.ts +24 -0
  16. package/dist/src/config/config-builder.js +129 -0
  17. package/dist/src/config/config-builder.js.map +1 -0
  18. package/dist/src/config/config-loader.d.ts +10 -0
  19. package/dist/src/config/config-loader.js +79 -0
  20. package/dist/src/config/config-loader.js.map +1 -0
  21. package/dist/src/config/config.models.d.ts +144 -0
  22. package/dist/src/config/config.models.js +2 -0
  23. package/dist/src/config/config.models.js.map +1 -0
  24. package/dist/src/config/config.schema.d.ts +75 -0
  25. package/dist/src/config/config.schema.js +87 -0
  26. package/dist/src/config/config.schema.js.map +1 -0
  27. package/dist/src/config/dsn-check.d.ts +5 -0
  28. package/dist/src/config/dsn-check.js +12 -0
  29. package/dist/src/config/dsn-check.js.map +1 -0
  30. package/dist/src/di/container.d.ts +13 -0
  31. package/dist/src/di/container.js +67 -0
  32. package/dist/src/di/container.js.map +1 -0
  33. package/dist/src/di/types.d.ts +27 -0
  34. package/dist/src/di/types.js +28 -0
  35. package/dist/src/di/types.js.map +1 -0
  36. package/dist/src/flow/command-executor.d.ts +18 -0
  37. package/dist/src/flow/command-executor.js +87 -0
  38. package/dist/src/flow/command-executor.js.map +1 -0
  39. package/dist/src/flow/command-resolver.d.ts +11 -0
  40. package/dist/src/flow/command-resolver.js +35 -0
  41. package/dist/src/flow/command-resolver.js.map +1 -0
  42. package/dist/src/flow/flow-catalog.d.ts +12 -0
  43. package/dist/src/flow/flow-catalog.js +31 -0
  44. package/dist/src/flow/flow-catalog.js.map +1 -0
  45. package/dist/src/flow/flow-errors.d.ts +66 -0
  46. package/dist/src/flow/flow-errors.js +119 -0
  47. package/dist/src/flow/flow-errors.js.map +1 -0
  48. package/dist/src/flow/flow-job-processor.d.ts +33 -0
  49. package/dist/src/flow/flow-job-processor.js +208 -0
  50. package/dist/src/flow/flow-job-processor.js.map +1 -0
  51. package/dist/src/flow/flow-params.d.ts +9 -0
  52. package/dist/src/flow/flow-params.js +52 -0
  53. package/dist/src/flow/flow-params.js.map +1 -0
  54. package/dist/src/flow/flow-runner.d.ts +36 -0
  55. package/dist/src/flow/flow-runner.js +209 -0
  56. package/dist/src/flow/flow-runner.js.map +1 -0
  57. package/dist/src/flow/flow-scheduler.d.ts +24 -0
  58. package/dist/src/flow/flow-scheduler.js +96 -0
  59. package/dist/src/flow/flow-scheduler.js.map +1 -0
  60. package/dist/src/flow/flow-validator.d.ts +29 -0
  61. package/dist/src/flow/flow-validator.js +141 -0
  62. package/dist/src/flow/flow-validator.js.map +1 -0
  63. package/dist/src/flow/flow.d.ts +32 -0
  64. package/dist/src/flow/flow.js +50 -0
  65. package/dist/src/flow/flow.js.map +1 -0
  66. package/dist/src/flow/flow.models.d.ts +288 -0
  67. package/dist/src/flow/flow.models.js +38 -0
  68. package/dist/src/flow/flow.models.js.map +1 -0
  69. package/dist/src/flow/retry-policy.d.ts +9 -0
  70. package/dist/src/flow/retry-policy.js +15 -0
  71. package/dist/src/flow/retry-policy.js.map +1 -0
  72. package/dist/src/flow/state-path.d.ts +21 -0
  73. package/dist/src/flow/state-path.js +37 -0
  74. package/dist/src/flow/state-path.js.map +1 -0
  75. package/dist/src/flow/step-input-builder.d.ts +15 -0
  76. package/dist/src/flow/step-input-builder.js +63 -0
  77. package/dist/src/flow/step-input-builder.js.map +1 -0
  78. package/dist/src/flows/scrape.flow.d.ts +6 -0
  79. package/dist/src/flows/scrape.flow.js +31 -0
  80. package/dist/src/flows/scrape.flow.js.map +1 -0
  81. package/dist/src/index.d.ts +57 -0
  82. package/dist/src/index.js +50 -0
  83. package/dist/src/index.js.map +1 -0
  84. package/dist/src/logging/logger.d.ts +17 -0
  85. package/dist/src/logging/logger.js +55 -0
  86. package/dist/src/logging/logger.js.map +1 -0
  87. package/dist/src/logging/logger.models.d.ts +25 -0
  88. package/dist/src/logging/logger.models.js +7 -0
  89. package/dist/src/logging/logger.models.js.map +1 -0
  90. package/dist/src/mail/mail.models.d.ts +15 -0
  91. package/dist/src/mail/mail.models.js +2 -0
  92. package/dist/src/mail/mail.models.js.map +1 -0
  93. package/dist/src/mail/smtp-mailer.d.ts +13 -0
  94. package/dist/src/mail/smtp-mailer.js +70 -0
  95. package/dist/src/mail/smtp-mailer.js.map +1 -0
  96. package/dist/src/mail/unconfigured-mailer.d.ts +6 -0
  97. package/dist/src/mail/unconfigured-mailer.js +20 -0
  98. package/dist/src/mail/unconfigured-mailer.js.map +1 -0
  99. package/dist/src/models.d.ts +11 -0
  100. package/dist/src/models.js +10 -0
  101. package/dist/src/models.js.map +1 -0
  102. package/dist/src/monitor/monitor-api.d.ts +18 -0
  103. package/dist/src/monitor/monitor-api.js +62 -0
  104. package/dist/src/monitor/monitor-api.js.map +1 -0
  105. package/dist/src/monitor/monitor-server.d.ts +33 -0
  106. package/dist/src/monitor/monitor-server.js +142 -0
  107. package/dist/src/monitor/monitor-server.js.map +1 -0
  108. package/dist/src/monitor/monitor.models.d.ts +27 -0
  109. package/dist/src/monitor/monitor.models.js +2 -0
  110. package/dist/src/monitor/monitor.models.js.map +1 -0
  111. package/dist/src/queue/pg-boss-flow-queue.d.ts +22 -0
  112. package/dist/src/queue/pg-boss-flow-queue.js +102 -0
  113. package/dist/src/queue/pg-boss-flow-queue.js.map +1 -0
  114. package/dist/src/queue/queue.models.d.ts +38 -0
  115. package/dist/src/queue/queue.models.js +2 -0
  116. package/dist/src/queue/queue.models.js.map +1 -0
  117. package/dist/src/reporting/lighty-error-reporter.d.ts +24 -0
  118. package/dist/src/reporting/lighty-error-reporter.js +96 -0
  119. package/dist/src/reporting/lighty-error-reporter.js.map +1 -0
  120. package/dist/src/reporting/log-error-reporter.d.ts +12 -0
  121. package/dist/src/reporting/log-error-reporter.js +35 -0
  122. package/dist/src/reporting/log-error-reporter.js.map +1 -0
  123. package/dist/src/reporting/reporting.models.d.ts +27 -0
  124. package/dist/src/reporting/reporting.models.js +2 -0
  125. package/dist/src/reporting/reporting.models.js.map +1 -0
  126. package/dist/src/scrapme.d.ts +61 -0
  127. package/dist/src/scrapme.js +133 -0
  128. package/dist/src/scrapme.js.map +1 -0
  129. package/dist/src/scrapme.models.d.ts +18 -0
  130. package/dist/src/scrapme.models.js +2 -0
  131. package/dist/src/scrapme.models.js.map +1 -0
  132. package/dist/src/storage/couch-connection.d.ts +19 -0
  133. package/dist/src/storage/couch-connection.js +67 -0
  134. package/dist/src/storage/couch-connection.js.map +1 -0
  135. package/dist/src/storage/couch-database.d.ts +44 -0
  136. package/dist/src/storage/couch-database.js +118 -0
  137. package/dist/src/storage/couch-database.js.map +1 -0
  138. package/dist/src/storage/couch-document-store.d.ts +14 -0
  139. package/dist/src/storage/couch-document-store.js +36 -0
  140. package/dist/src/storage/couch-document-store.js.map +1 -0
  141. package/dist/src/storage/couch-error.d.ts +12 -0
  142. package/dist/src/storage/couch-error.js +19 -0
  143. package/dist/src/storage/couch-error.js.map +1 -0
  144. package/dist/src/storage/couch-flow-run-store.d.ts +24 -0
  145. package/dist/src/storage/couch-flow-run-store.js +66 -0
  146. package/dist/src/storage/couch-flow-run-store.js.map +1 -0
  147. package/dist/src/storage/couch-run-store.d.ts +15 -0
  148. package/dist/src/storage/couch-run-store.js +52 -0
  149. package/dist/src/storage/couch-run-store.js.map +1 -0
  150. package/dist/src/storage/run-doc-ids.d.ts +9 -0
  151. package/dist/src/storage/run-doc-ids.js +15 -0
  152. package/dist/src/storage/run-doc-ids.js.map +1 -0
  153. package/dist/src/storage/storage.models.d.ts +95 -0
  154. package/dist/src/storage/storage.models.js +5 -0
  155. package/dist/src/storage/storage.models.js.map +1 -0
  156. package/dist/src/storage/unconfigured-document-store.d.ts +8 -0
  157. package/dist/src/storage/unconfigured-document-store.js +26 -0
  158. package/dist/src/storage/unconfigured-document-store.js.map +1 -0
  159. package/dist/src/util/preview.d.ts +10 -0
  160. package/dist/src/util/preview.js +44 -0
  161. package/dist/src/util/preview.js.map +1 -0
  162. package/dist/src/util/text.d.ts +8 -0
  163. package/dist/src/util/text.js +16 -0
  164. package/dist/src/util/text.js.map +1 -0
  165. package/dist/src/util/timing.d.ts +10 -0
  166. package/dist/src/util/timing.js +59 -0
  167. package/dist/src/util/timing.js.map +1 -0
  168. package/dist/src/util/url.d.ts +5 -0
  169. package/dist/src/util/url.js +11 -0
  170. package/dist/src/util/url.js.map +1 -0
  171. package/package.json +75 -4
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flow-job-processor.js","sourceRoot":"","sources":["../../../src/flow/flow-job-processor.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE/C,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAEvC,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAIzD,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAG7C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,UAAU,EAAE,WAAW,EAA0E,MAAM,kBAAkB,CAAC;AAGxK;;;;;;GAMG;AAEI,IAAM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M,CAAC,MAAM,CAAC,CAAa,EAAE,IAAoB;QACvD,IAAI,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,IAAI,CAAC,GAAG,CAAC,CAAC;QACrD,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC,WAAW,EAAE,MAAM,EAAE,WAAW,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;YACjG,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACvB,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF,CAAA;AA7LY,gBAAgB;IAD5B,UAAU,EAAE;IAKR,WAAA,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;IACpB,WAAA,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;IACpB,WAAA,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;IACtB,WAAA,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,CAAA;IAC7B,WAAA,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,CAAA;IAC7B,WAAA,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAA;IAC9B,WAAA,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,CAAA;GAVnB,gBAAgB,CA6L5B"}
@@ -0,0 +1,9 @@
1
+ import { type FlowDefinition } from './flow.models.js';
2
+ /**
3
+ * Checks a run input against the flow's `<param>`s and fills in defaults: required params must be there,
4
+ * typed params must have that JS type (json = anything). Extra keys are kept (the state is the input).
5
+ */
6
+ export declare class FlowParams {
7
+ apply(flow: FlowDefinition, input: Readonly<Record<string, unknown>>): Record<string, unknown>;
8
+ private static fits;
9
+ }
@@ -0,0 +1,52 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var FlowParams_1;
8
+ import { injectable } from 'inversify';
9
+ import { FlowInputError } from './flow-errors.js';
10
+ import { VALUE_TYPE } from './flow.models.js';
11
+ /**
12
+ * Checks a run input against the flow's `<param>`s and fills in defaults: required params must be there,
13
+ * typed params must have that JS type (json = anything). Extra keys are kept (the state is the input).
14
+ */
15
+ let FlowParams = FlowParams_1 = class FlowParams {
16
+ apply(flow, input) {
17
+ const state = { ...input };
18
+ const problems = [];
19
+ for (const param of flow.params) {
20
+ const given = state[param.name];
21
+ if (given === undefined) {
22
+ if (param.required)
23
+ problems.push(`missing required param "${param.name}"`);
24
+ else if (param.default !== undefined)
25
+ state[param.name] = structuredClone(param.default);
26
+ continue;
27
+ }
28
+ if (!FlowParams_1.fits(param, given))
29
+ problems.push(`param "${param.name}" must be a ${param.type}, got ${given === null ? 'null' : typeof given}`);
30
+ }
31
+ if (problems.length > 0)
32
+ throw new FlowInputError(flow.name, problems);
33
+ return state;
34
+ }
35
+ static fits(param, value) {
36
+ switch (param.type) {
37
+ case VALUE_TYPE.STRING:
38
+ return typeof value === 'string';
39
+ case VALUE_TYPE.NUMBER:
40
+ return typeof value === 'number' && Number.isFinite(value);
41
+ case VALUE_TYPE.BOOLEAN:
42
+ return typeof value === 'boolean';
43
+ case VALUE_TYPE.JSON:
44
+ return true;
45
+ }
46
+ }
47
+ };
48
+ FlowParams = FlowParams_1 = __decorate([
49
+ injectable()
50
+ ], FlowParams);
51
+ export { FlowParams };
52
+ //# sourceMappingURL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E,QAAQ,CAAC,CAAC;QACvE,OAAO,KAAK,CAAC;IACf,CAAC;IAEO,MAAM,CAAC,IAAI,CAAC,KAAgB,EAAE,KAAc;QAClD,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;YACnB,KAAK,UAAU,CAAC,MAAM;gBACpB,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;YACnC,KAAK,UAAU,CAAC,MAAM;gBACpB,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YAC7D,KAAK,UAAU,CAAC,OAAO;gBACrB,OAAO,OAAO,KAAK,KAAK,SAAS,CAAC;YACpC,KAAK,UAAU,CAAC,IAAI;gBAClB,OAAO,IAAI,CAAC;QAChB,CAAC;IACH,CAAC;CACF,CAAA;AA7BY,UAAU;IADtB,UAAU,EAAE;GACA,UAAU,CA6BtB"}
@@ -0,0 +1,36 @@
1
+ import type { ScrapmeConfig } from '../config/config.models.js';
2
+ import type { Logger } from '../logging/logger.js';
3
+ import type { ErrorReporter } from '../reporting/reporting.models.js';
4
+ import { type FlowRunStore } from '../storage/storage.models.js';
5
+ import type { CommandExecutor } from './command-executor.js';
6
+ import type { CommandResolver } from './command-resolver.js';
7
+ import type { FlowParams } from './flow-params.js';
8
+ import { type FlowDefinition, type FlowRunResult, type RunOptions } from './flow.models.js';
9
+ import type { StepInputBuilder } from './step-input-builder.js';
10
+ /**
11
+ * Executes a flow: steps in order, each through CommandExecutor (timeout + retries), its input built by
12
+ * StepInputBuilder from the state. Every failed attempt is stored (FlowRunStore) and logged into the error
13
+ * report's breadcrumbs; a step that finally fails is reported once (ErrorReporter → LightyErrors) and ends the run.
14
+ * The run itself is stored when it starts and ends.
15
+ *
16
+ * Before anything runs: input not matching the flow's params → FlowInputError (thrown, nothing stored). After that `run` never throws for a failing step — check
17
+ * `result.status`, or use `runOrThrow`.
18
+ */
19
+ export declare class FlowRunner {
20
+ private readonly config;
21
+ private readonly resolver;
22
+ private readonly executor;
23
+ private readonly inputs;
24
+ private readonly params;
25
+ private readonly store;
26
+ private readonly reporter;
27
+ private readonly logger;
28
+ constructor(config: ScrapmeConfig, logger: Logger, resolver: CommandResolver, executor: CommandExecutor, inputs: StepInputBuilder, params: FlowParams, store: FlowRunStore, reporter: ErrorReporter);
29
+ run<S extends object = Record<string, unknown>>(flow: FlowDefinition, input: Readonly<Record<string, unknown>>, options?: RunOptions): Promise<FlowRunResult<S>>;
30
+ /** Like run, but throws FlowFailedError (cause = the step's error) and returns the final state. */
31
+ runOrThrow<S extends object = Record<string, unknown>>(flow: FlowDefinition, input: Readonly<Record<string, unknown>>, options?: RunOptions): Promise<S>;
32
+ private reportFailure;
33
+ private attemptFailed;
34
+ private setupFailure;
35
+ private short;
36
+ }
@@ -0,0 +1,209 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
8
+ return function (target, key) { decorator(target, key, paramIndex); }
9
+ };
10
+ import { randomUUID } from 'node:crypto';
11
+ import { inject, injectable } from 'inversify';
12
+ import { TYPES } from '../di/types.js';
13
+ import { LINE_LEVEL } from '../logging/logger.models.js';
14
+ import { RunDocIds } from '../storage/run-doc-ids.js';
15
+ import { DOC_TYPE } from '../storage/storage.models.js';
16
+ import { Preview } from '../util/preview.js';
17
+ import { FlowCancelledError, FlowFailedError, FlowErrors } from './flow-errors.js';
18
+ import { ATTEMPT_OUTCOME, RUN_STATUS, STEP_STATUS, } from './flow.models.js';
19
+ /**
20
+ * Executes a flow: steps in order, each through CommandExecutor (timeout + retries), its input built by
21
+ * StepInputBuilder from the state. Every failed attempt is stored (FlowRunStore) and logged into the error
22
+ * report's breadcrumbs; a step that finally fails is reported once (ErrorReporter → LightyErrors) and ends the run.
23
+ * The run itself is stored when it starts and ends.
24
+ *
25
+ * Before anything runs: input not matching the flow's params → FlowInputError (thrown, nothing stored). After that `run` never throws for a failing step — check
26
+ * `result.status`, or use `runOrThrow`.
27
+ */
28
+ let FlowRunner = class FlowRunner {
29
+ config;
30
+ resolver;
31
+ executor;
32
+ inputs;
33
+ params;
34
+ store;
35
+ reporter;
36
+ logger;
37
+ constructor(config, logger, resolver, executor, inputs, params, store, reporter) {
38
+ this.config = config;
39
+ this.resolver = resolver;
40
+ this.executor = executor;
41
+ this.inputs = inputs;
42
+ this.params = params;
43
+ this.store = store;
44
+ this.reporter = reporter;
45
+ this.logger = logger.child({ component: 'flow' });
46
+ }
47
+ async run(flow, input, options = {}) {
48
+ let state = this.params.apply(flow, input);
49
+ const runId = options.runId ?? randomUUID();
50
+ const log = this.logger.child({ flow: flow.name, runId });
51
+ const started = new Date();
52
+ const doc = {
53
+ _id: RunDocIds.run(runId),
54
+ type: DOC_TYPE.FLOW_RUN,
55
+ runId,
56
+ flow: flow.name,
57
+ status: RUN_STATUS.RUNNING,
58
+ tags: { ...flow.tags },
59
+ input: this.short(state),
60
+ steps: flow.steps.map((s) => ({ key: s.key, command: s.commandName, status: STEP_STATUS.SKIPPED, attempts: [], durationMs: 0 })),
61
+ startedAt: started.toISOString(),
62
+ };
63
+ await this.store.runStarted(doc);
64
+ const keys = flow.steps.map((s) => s.key);
65
+ log.info('flow started', { steps: keys });
66
+ this.reporter.log(`flow ${flow.name} started`, { runId, steps: keys });
67
+ let failure = null;
68
+ for (const [index, step] of flow.steps.entries()) {
69
+ const stepLog = log.child({ step: step.key, command: step.commandName });
70
+ let command;
71
+ let stepInput;
72
+ try {
73
+ if (options.signal?.aborted)
74
+ throw new FlowCancelledError(options.signal.reason);
75
+ command = this.resolver.resolve(step.command);
76
+ stepInput = this.inputs.build(step.input, state, step.key);
77
+ }
78
+ catch (error) {
79
+ // a missing value or an unresolvable command: the same state gives the same error, nothing to retry
80
+ const report = this.setupFailure(error);
81
+ doc.steps[index] = { ...doc.steps[index], status: STEP_STATUS.FAILED, attempts: [report], error: report.error };
82
+ stepLog.error('step failed before it started', { error });
83
+ await this.attemptFailed(doc, step, 1, 1, error, report, true, undefined);
84
+ failure = { step, error, attempts: [report], input: undefined };
85
+ break;
86
+ }
87
+ stepLog.info('step started');
88
+ this.reporter.log(`step ${step.key} (${step.commandName}) started`, { runId });
89
+ const maxAttempts = this.executor.policy(step, command).maxAttempts;
90
+ const execution = await this.executor.execute(step, command, stepInput, { runId, flow: flow.name, step: step.key, logger: stepLog, state: Object.freeze({ ...state }) }, options.signal, async (report, error, final) => {
91
+ const message = final ? 'step failed' : `attempt failed, retrying in ${report.retryInMs} ms`;
92
+ stepLog[final ? LINE_LEVEL.ERROR : LINE_LEVEL.WARN](message, { attempt: report.attempt, maxAttempts, error });
93
+ await this.attemptFailed(doc, step, report.attempt, maxAttempts, error, report, final, stepInput);
94
+ });
95
+ const stepReport = {
96
+ key: step.key,
97
+ command: step.commandName,
98
+ status: execution.ok ? STEP_STATUS.SUCCEEDED : STEP_STATUS.FAILED,
99
+ attempts: execution.attempts,
100
+ durationMs: execution.durationMs,
101
+ };
102
+ if (execution.ok) {
103
+ state = { ...state, [step.key]: execution.value };
104
+ stepReport.output = this.short(execution.value);
105
+ doc.steps[index] = stepReport;
106
+ stepLog.info('step succeeded', { attempts: execution.attempts.length, ms: execution.durationMs });
107
+ this.reporter.log(`step ${step.key} succeeded`, { runId, attempts: execution.attempts.length, ms: execution.durationMs });
108
+ continue;
109
+ }
110
+ stepReport.error = FlowErrors.serialize(execution.error);
111
+ doc.steps[index] = stepReport;
112
+ failure = { step, error: execution.error, attempts: execution.attempts, input: stepInput };
113
+ break;
114
+ }
115
+ const finished = new Date();
116
+ const result = {
117
+ runId,
118
+ flow: flow.name,
119
+ status: failure ? RUN_STATUS.FAILED : RUN_STATUS.SUCCEEDED,
120
+ state: state,
121
+ steps: doc.steps,
122
+ startedAt: doc.startedAt,
123
+ finishedAt: finished.toISOString(),
124
+ durationMs: finished.getTime() - started.getTime(),
125
+ };
126
+ if (failure) {
127
+ await this.reportFailure(flow, runId, failure, result, doc, log);
128
+ }
129
+ else {
130
+ log.info('flow succeeded', { ms: result.durationMs });
131
+ }
132
+ doc.status = result.status;
133
+ doc.finishedAt = result.finishedAt;
134
+ doc.durationMs = result.durationMs;
135
+ await this.store.runFinished(doc);
136
+ return result;
137
+ }
138
+ /** Like run, but throws FlowFailedError (cause = the step's error) and returns the final state. */
139
+ async runOrThrow(flow, input, options = {}) {
140
+ const result = await this.run(flow, input, options);
141
+ if (result.status === RUN_STATUS.FAILED) {
142
+ const failed = result.steps.find((s) => s.status === STEP_STATUS.FAILED);
143
+ throw new FlowFailedError(flow.name, failed?.key ?? '?', result.runId, result.cause);
144
+ }
145
+ return result.state;
146
+ }
147
+ async reportFailure(flow, runId, failure, result, doc, log) {
148
+ const error = FlowErrors.serialize(failure.error);
149
+ result.error = error;
150
+ result.cause = failure.error;
151
+ const last = failure.attempts.at(-1);
152
+ const eventId = this.reporter.report(failure.error, {
153
+ flow: flow.name,
154
+ step: failure.step.key,
155
+ command: failure.step.commandName,
156
+ runId,
157
+ attempt: last?.attempt ?? 1,
158
+ maxAttempts: failure.attempts.length,
159
+ input: this.short(failure.input),
160
+ tags: { ...flow.tags },
161
+ extra: { attempts: failure.attempts.map((a) => ({ attempt: a.attempt, outcome: a.outcome, ms: a.durationMs, error: a.error?.message })) },
162
+ });
163
+ if (eventId)
164
+ result.reportEventId = eventId;
165
+ doc.error = { ...error, step: failure.step.key };
166
+ if (eventId)
167
+ doc.reportEventId = eventId;
168
+ log.error('flow failed', { step: failure.step.key, ms: result.durationMs, eventId: eventId || undefined });
169
+ await this.reporter.flush();
170
+ }
171
+ async attemptFailed(run, step, attempt, maxAttempts, error, report, final, input) {
172
+ const level = final ? LINE_LEVEL.ERROR : LINE_LEVEL.WARN;
173
+ this.reporter.log(`step ${step.key} attempt ${attempt}/${maxAttempts} failed${final ? '' : ', retrying'}`, { error: report.error?.message }, level);
174
+ const doc = {
175
+ _id: RunDocIds.error(run.runId, step.key, attempt),
176
+ type: DOC_TYPE.FLOW_ERROR,
177
+ runId: run.runId,
178
+ flow: run.flow,
179
+ step: step.key,
180
+ command: step.commandName,
181
+ attempt,
182
+ maxAttempts,
183
+ final,
184
+ error: report.error ?? FlowErrors.serialize(error),
185
+ input: this.short(input),
186
+ at: new Date().toISOString(),
187
+ };
188
+ await this.store.attemptFailed(doc);
189
+ }
190
+ setupFailure(error) {
191
+ return { attempt: 1, startedAt: new Date().toISOString(), durationMs: 0, outcome: ATTEMPT_OUTCOME.FAILED, error: FlowErrors.serialize(error) };
192
+ }
193
+ short(value) {
194
+ return Preview.of(value, this.config.flow.maxStoredChars);
195
+ }
196
+ };
197
+ FlowRunner = __decorate([
198
+ injectable(),
199
+ __param(0, inject(TYPES.Config)),
200
+ __param(1, inject(TYPES.Logger)),
201
+ __param(2, inject(TYPES.CommandResolver)),
202
+ __param(3, inject(TYPES.CommandExecutor)),
203
+ __param(4, inject(TYPES.StepInputBuilder)),
204
+ __param(5, inject(TYPES.FlowParams)),
205
+ __param(6, inject(TYPES.FlowRunStore)),
206
+ __param(7, inject(TYPES.ErrorReporter))
207
+ ], FlowRunner);
208
+ export { FlowRunner };
209
+ //# sourceMappingURL=flow-runner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flow-runner.js","sourceRoot":"","sources":["../../../src/flow/flow-runner.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE/C,OAAO,EAAE,KAAK,EAAE,MAAM,gBA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AC,CAAA;IAC7B,WAAA,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAA;IAC9B,WAAA,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;IACxB,WAAA,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,CAAA;IAC1B,WAAA,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,CAAA;GAXnB,UAAU,CA2MtB"}
@@ -0,0 +1,24 @@
1
+ import type { QueueConfig } from '../config/config.models.js';
2
+ import type { Logger } from '../logging/logger.js';
3
+ import type { FlowQueue } from '../queue/queue.models.js';
4
+ import { type RunStore } from '../storage/storage.models.js';
5
+ import type { FlowParams } from './flow-params.js';
6
+ import { type ScheduleOptions } from './flow.models.js';
7
+ import type { Flow } from './flow.js';
8
+ /**
9
+ * scrapme.flow(): checks the input, writes the run document (status queued, every step pending) and puts one job
10
+ * on the flow's queue. Returns at once — a worker runs the flow later. Run ids are UUIDv7: they sort by creation
11
+ * time, and so do the run documents.
12
+ */
13
+ export declare class FlowScheduler {
14
+ private readonly params;
15
+ private readonly store;
16
+ private readonly queue;
17
+ private readonly defaults;
18
+ private readonly logger;
19
+ constructor(params: FlowParams, store: RunStore, queue: FlowQueue, defaults: QueueConfig, logger: Logger);
20
+ /** The pg-boss queue of a flow. */
21
+ queueName(flow: Flow): string;
22
+ /** Throws FlowInputError (input vs params), TypeError (bad or taken runId). */
23
+ schedule(flow: Flow, input: Readonly<Record<string, unknown>>, options?: ScheduleOptions): Promise<string>;
24
+ }
@@ -0,0 +1,96 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
8
+ return function (target, key) { decorator(target, key, paramIndex); }
9
+ };
10
+ import { inject, injectable } from 'inversify';
11
+ import { v7 as uuidv7, validate as isUuid } from 'uuid';
12
+ import { TYPES } from '../di/types.js';
13
+ import { RunDocIds } from '../storage/run-doc-ids.js';
14
+ import { DOC_TYPE } from '../storage/storage.models.js';
15
+ import { FlowErrors } from './flow-errors.js';
16
+ import { RUN_STATUS, STEP_STATUS } from './flow.models.js';
17
+ /**
18
+ * scrapme.flow(): checks the input, writes the run document (status queued, every step pending) and puts one job
19
+ * on the flow's queue. Returns at once — a worker runs the flow later. Run ids are UUIDv7: they sort by creation
20
+ * time, and so do the run documents.
21
+ */
22
+ let FlowScheduler = class FlowScheduler {
23
+ params;
24
+ store;
25
+ queue;
26
+ defaults;
27
+ logger;
28
+ constructor(params, store, queue, defaults, logger) {
29
+ this.params = params;
30
+ this.store = store;
31
+ this.queue = queue;
32
+ this.defaults = defaults;
33
+ this.logger = logger.child({ component: 'scheduler' });
34
+ }
35
+ /** The pg-boss queue of a flow. */
36
+ queueName(flow) {
37
+ return this.defaults.prefix + flow.name;
38
+ }
39
+ /** Throws FlowInputError (input vs params), TypeError (bad or taken runId). */
40
+ async schedule(flow, input, options = {}) {
41
+ const state = this.params.apply(flow, input);
42
+ if (options.runId !== undefined && !isUuid(options.runId))
43
+ throw new TypeError(`runId must be a UUID (pg-boss job ids are), got "${options.runId}"`);
44
+ const runId = options.runId ?? uuidv7();
45
+ const q = { retries: flow.queue.retries ?? this.defaults.retries, retryDelaySeconds: flow.queue.retryDelaySeconds ?? this.defaults.retryDelaySeconds, retryBackoff: flow.queue.retryBackoff ?? this.defaults.retryBackoff, timeoutSeconds: flow.queue.timeoutSeconds ?? this.defaults.timeoutSeconds };
46
+ const now = new Date().toISOString();
47
+ const doc = {
48
+ _id: RunDocIds.run(runId),
49
+ type: DOC_TYPE.FLOW_RUN,
50
+ runId,
51
+ flow: flow.name,
52
+ status: RUN_STATUS.QUEUED,
53
+ tags: { ...flow.tags },
54
+ input: state,
55
+ steps: flow.steps.map((s) => ({ key: s.key, command: s.commandName, status: STEP_STATUS.PENDING, attempts: [] })),
56
+ currentStep: null,
57
+ flowAttempts: [],
58
+ maxFlowAttempts: q.retries + 1,
59
+ createdAt: now,
60
+ updatedAt: now,
61
+ };
62
+ if (await this.store.get(runId))
63
+ throw new TypeError(`run ${runId} exists already`);
64
+ await this.store.create(doc);
65
+ try {
66
+ await this.queue.schedule(this.queueName(flow), { runId }, {
67
+ id: runId,
68
+ retryLimit: q.retries,
69
+ retryDelaySeconds: q.retryDelaySeconds,
70
+ retryBackoff: q.retryBackoff,
71
+ expireInSeconds: q.timeoutSeconds,
72
+ ...(options.startAfter ? { startAfter: options.startAfter } : {}),
73
+ ...(options.priority !== undefined ? { priority: options.priority } : {}),
74
+ });
75
+ }
76
+ catch (error) {
77
+ await this.store.update(runId, (d) => {
78
+ d.status = RUN_STATUS.FAILED;
79
+ d.error = { ...FlowErrors.serialize(error), step: '' };
80
+ });
81
+ throw error;
82
+ }
83
+ this.logger.info('flow scheduled', { flow: flow.name, runId, attempts: q.retries + 1, timeoutSeconds: q.timeoutSeconds });
84
+ return runId;
85
+ }
86
+ };
87
+ FlowScheduler = __decorate([
88
+ injectable(),
89
+ __param(0, inject(TYPES.FlowParams)),
90
+ __param(1, inject(TYPES.RunStore)),
91
+ __param(2, inject(TYPES.FlowQueue)),
92
+ __param(3, inject(TYPES.QueueConfig)),
93
+ __param(4, inject(TYPES.Logger))
94
+ ], FlowScheduler);
95
+ export { FlowScheduler };
96
+ //# sourceMappingURL=flow-scheduler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flow-scheduler.js","sourceRoot":"","sources":["../../../src/flow/flow-scheduler.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,WAAW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AC,OAAO,GAAG,CAAC,EAAE,cAAc,EAAE,CAAC,CAAC,cAAc,EAAE,CAAC,CAAC;QAC1H,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAA;AAlEY,aAAa;IADzB,UAAU,EAAE;IAKR,WAAA,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;IACxB,WAAA,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;IACtB,WAAA,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;IACvB,WAAA,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;IACzB,WAAA,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;GARZ,aAAa,CAkEzB"}
@@ -0,0 +1,29 @@
1
+ import { type CommandRef, type FlowConfig, type FlowDefinition } from './flow.models.js';
2
+ /**
3
+ * Checks a flow config (a `*.flow.ts` file) and turns it into a FlowDefinition, or throws FlowDefinitionError saying
4
+ * where (`flow "hello": steps[0] "printed".input["text"]: …`). Shape with zod; then what zod can't see: unique keys
5
+ * (a step's key defaults to its command's name), `from` paths that start with a param or an EARLIER step, commands
6
+ * that have an `execute` method. Field functions are plain JS and are not looked into.
7
+ */
8
+ export declare class FlowValidator {
9
+ /**
10
+ * Step keys and param names become state properties and the first part of paths, so they must be plain
11
+ * identifiers. A regex is the clearest way to say that (it's a rule about characters, not about structure).
12
+ */
13
+ private static readonly IDENTIFIER;
14
+ private static readonly IDENTIFIER_RULE;
15
+ private static readonly identifier;
16
+ private static readonly int;
17
+ private static readonly field;
18
+ private static readonly schema;
19
+ validate(config: FlowConfig): FlowDefinition;
20
+ /** A class whose prototype has execute(), or an object with execute(). */
21
+ static isCommand(value: unknown): value is CommandRef;
22
+ /** Class name, the name of a FunctionCommand, or the object's class name. */
23
+ static commandName(command: CommandRef): string;
24
+ private param;
25
+ private step;
26
+ private field;
27
+ /** A path must start with a param or an earlier step's key. */
28
+ private reference;
29
+ }