@blokjs/shared 0.2.1 → 0.4.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.
@@ -0,0 +1,328 @@
1
+ import GlobalError from "./GlobalError";
2
+ /**
3
+ * The categories every Blok node error falls into.
4
+ *
5
+ * Mirror of the proto `blok.runtime.v1.ErrorCategory` enum. Stored as string
6
+ * values so JSON payloads (e.g. `GlobalError.context.json`) are human-readable.
7
+ */
8
+ export const ErrorCategory = {
9
+ VALIDATION: "VALIDATION",
10
+ CONFIGURATION: "CONFIGURATION",
11
+ DEPENDENCY: "DEPENDENCY",
12
+ TIMEOUT: "TIMEOUT",
13
+ PERMISSION: "PERMISSION",
14
+ RATE_LIMIT: "RATE_LIMIT",
15
+ NOT_FOUND: "NOT_FOUND",
16
+ CONFLICT: "CONFLICT",
17
+ CANCELLED: "CANCELLED",
18
+ INTERNAL: "INTERNAL",
19
+ PROTOCOL: "PROTOCOL",
20
+ DATA: "DATA",
21
+ };
22
+ /** How severe an error is. Default for thrown errors is `ERROR`. */
23
+ export const ErrorSeverity = {
24
+ INFO: "INFO",
25
+ WARN: "WARN",
26
+ ERROR: "ERROR",
27
+ FATAL: "FATAL",
28
+ };
29
+ /**
30
+ * Default HTTP status per error category.
31
+ *
32
+ * Single source of truth — the runner uses these on `GlobalError.context.code`
33
+ * and HTTP triggers use them as the response status. Override per-error via
34
+ * `BlokErrorOpts.httpStatus`.
35
+ */
36
+ export const DEFAULT_HTTP_STATUS = {
37
+ VALIDATION: 400,
38
+ CONFIGURATION: 500,
39
+ DEPENDENCY: 502,
40
+ TIMEOUT: 504,
41
+ PERMISSION: 403,
42
+ RATE_LIMIT: 429,
43
+ NOT_FOUND: 404,
44
+ CONFLICT: 409,
45
+ CANCELLED: 499,
46
+ INTERNAL: 500,
47
+ PROTOCOL: 502,
48
+ DATA: 422,
49
+ };
50
+ /** Default retryable hint per error category. */
51
+ export const DEFAULT_RETRYABLE = {
52
+ VALIDATION: false,
53
+ CONFIGURATION: false,
54
+ DEPENDENCY: true,
55
+ TIMEOUT: true,
56
+ PERMISSION: false,
57
+ RATE_LIMIT: true,
58
+ NOT_FOUND: false,
59
+ CONFLICT: false,
60
+ CANCELLED: false,
61
+ INTERNAL: false,
62
+ PROTOCOL: false,
63
+ DATA: false,
64
+ };
65
+ /**
66
+ * Structured error type for Blok nodes. Extends {@link GlobalError} so it
67
+ * remains fully compatible with existing `instanceof GlobalError` checks and
68
+ * `GlobalError.context` consumers (HTTP trigger, RunTracker, Studio).
69
+ *
70
+ * Use the static factory methods (`BlokError.validation`,
71
+ * `BlokError.dependency`, etc.) — direct construction is private.
72
+ *
73
+ * Auto-fills `name`, `stack`, and `at`. The runner enriches `node`, `sdk`,
74
+ * `sdkVersion`, and `runtimeKind` when the error is sourced from a runtime
75
+ * adapter; module nodes can override via {@link BlokErrorOpts}.
76
+ *
77
+ * @example
78
+ * throw BlokError.dependency({
79
+ * code: "POSTGRES_CONNECT_TIMEOUT",
80
+ * message: "Could not connect to Postgres within 5s",
81
+ * description: `Tried host=${host} port=${port}; timeout=${dur}ms`,
82
+ * remediation: "Check DATABASE_URL env var and network reachability",
83
+ * cause: err,
84
+ * });
85
+ */
86
+ export default class BlokError extends GlobalError {
87
+ category;
88
+ severity;
89
+ errorCode;
90
+ description;
91
+ remediation;
92
+ docUrl;
93
+ retryable;
94
+ retryAfterMs;
95
+ details;
96
+ contextSnapshot;
97
+ causes;
98
+ at;
99
+ sdk;
100
+ sdkVersion;
101
+ runtimeKind;
102
+ httpStatus;
103
+ nodeName;
104
+ constructor(category, opts) {
105
+ super(opts.message);
106
+ Object.setPrototypeOf(this, BlokError.prototype);
107
+ this.category = category;
108
+ this.severity = opts.severity ?? ErrorSeverity.ERROR;
109
+ this.errorCode = opts.code;
110
+ this.description = opts.description ?? "";
111
+ this.remediation = opts.remediation ?? "";
112
+ this.docUrl = opts.docUrl ?? "";
113
+ this.retryable = opts.retryable ?? DEFAULT_RETRYABLE[category];
114
+ this.retryAfterMs = opts.retryAfterMs ?? 0;
115
+ this.details = opts.details ?? null;
116
+ this.contextSnapshot = opts.contextSnapshot ?? null;
117
+ this.at = new Date();
118
+ this.sdk = opts.sdk ?? "";
119
+ this.sdkVersion = opts.sdkVersion ?? "";
120
+ this.runtimeKind = opts.runtimeKind ?? "";
121
+ this.nodeName = opts.node ?? "";
122
+ this.httpStatus = opts.httpStatus ?? DEFAULT_HTTP_STATUS[category];
123
+ this.causes = opts.cause ? Object.freeze(BlokError.flattenCauses(opts.cause)) : Object.freeze([]);
124
+ // Populate the GlobalError.context fields so legacy consumers keep working.
125
+ this.setCode(this.httpStatus);
126
+ this.setName(this.nodeName);
127
+ this.setStack(this.stack);
128
+ this.setJson(this.toJSON());
129
+ }
130
+ // =========================================================================
131
+ // Factory methods (one per category)
132
+ // =========================================================================
133
+ static validation(opts) {
134
+ return new BlokError(ErrorCategory.VALIDATION, opts);
135
+ }
136
+ static configuration(opts) {
137
+ return new BlokError(ErrorCategory.CONFIGURATION, opts);
138
+ }
139
+ static dependency(opts) {
140
+ return new BlokError(ErrorCategory.DEPENDENCY, opts);
141
+ }
142
+ static timeout(opts) {
143
+ return new BlokError(ErrorCategory.TIMEOUT, opts);
144
+ }
145
+ static permission(opts) {
146
+ return new BlokError(ErrorCategory.PERMISSION, opts);
147
+ }
148
+ static rateLimit(opts) {
149
+ return new BlokError(ErrorCategory.RATE_LIMIT, opts);
150
+ }
151
+ static notFound(opts) {
152
+ return new BlokError(ErrorCategory.NOT_FOUND, opts);
153
+ }
154
+ static conflict(opts) {
155
+ return new BlokError(ErrorCategory.CONFLICT, opts);
156
+ }
157
+ static cancelled(opts) {
158
+ return new BlokError(ErrorCategory.CANCELLED, opts);
159
+ }
160
+ static internal(opts) {
161
+ return new BlokError(ErrorCategory.INTERNAL, opts);
162
+ }
163
+ static protocol(opts) {
164
+ return new BlokError(ErrorCategory.PROTOCOL, opts);
165
+ }
166
+ static data(opts) {
167
+ return new BlokError(ErrorCategory.DATA, opts);
168
+ }
169
+ // =========================================================================
170
+ // Conversion
171
+ // =========================================================================
172
+ /**
173
+ * Convert any thrown value into a `BlokError`.
174
+ *
175
+ * Used by the runner's auto-wrap layer so legacy code (`throw new
176
+ * Error("oops")`) still produces a structured error. Categorization is
177
+ * heuristic — recognizes existing `BlokError` (passthrough), `GlobalError`
178
+ * (preserves code/json), `Error` (wraps as `INTERNAL`), and anything else
179
+ * (stringified as `INTERNAL`).
180
+ */
181
+ static fromUnknown(err, ctx) {
182
+ if (err instanceof BlokError) {
183
+ return err;
184
+ }
185
+ if (err instanceof GlobalError) {
186
+ const httpStatus = err.context.code ?? 500;
187
+ const wrapped = new BlokError(ErrorCategory.INTERNAL, {
188
+ code: "GLOBAL_ERROR",
189
+ message: err.message ?? "Unknown error",
190
+ details: err.context.json ?? null,
191
+ httpStatus,
192
+ node: ctx?.node ?? err.context.name ?? "",
193
+ sdk: ctx?.sdk,
194
+ sdkVersion: ctx?.sdkVersion,
195
+ runtimeKind: ctx?.runtimeKind,
196
+ });
197
+ if (err.stack)
198
+ wrapped.setStack(err.stack);
199
+ return wrapped;
200
+ }
201
+ if (err instanceof Error) {
202
+ return new BlokError(ErrorCategory.INTERNAL, {
203
+ code: `UNCAUGHT_${err.name || "ERROR"}`.toUpperCase(),
204
+ message: err.message || "Uncaught error",
205
+ cause: err,
206
+ node: ctx?.node,
207
+ sdk: ctx?.sdk,
208
+ sdkVersion: ctx?.sdkVersion,
209
+ runtimeKind: ctx?.runtimeKind,
210
+ });
211
+ }
212
+ return new BlokError(ErrorCategory.INTERNAL, {
213
+ code: "UNCAUGHT_ERROR",
214
+ message: typeof err === "string" ? err : JSON.stringify(err),
215
+ node: ctx?.node,
216
+ sdk: ctx?.sdk,
217
+ sdkVersion: ctx?.sdkVersion,
218
+ runtimeKind: ctx?.runtimeKind,
219
+ });
220
+ }
221
+ /**
222
+ * Reconstruct a `BlokError` from a serialized {@link NodeErrorPayload}.
223
+ *
224
+ * Used by the runner's gRPC codec to convert proto `NodeError` messages
225
+ * received from SDKs back into TS-side errors.
226
+ */
227
+ static fromJSON(payload) {
228
+ const err = new BlokError(payload.category, {
229
+ code: payload.code,
230
+ message: payload.message,
231
+ description: payload.description,
232
+ remediation: payload.remediation,
233
+ docUrl: payload.docUrl,
234
+ retryable: payload.retryable,
235
+ retryAfterMs: payload.retryAfterMs,
236
+ details: payload.details,
237
+ contextSnapshot: payload.contextSnapshot,
238
+ httpStatus: payload.httpStatus,
239
+ severity: payload.severity,
240
+ node: payload.node,
241
+ sdk: payload.sdk,
242
+ sdkVersion: payload.sdkVersion,
243
+ runtimeKind: payload.runtimeKind,
244
+ });
245
+ if (payload.stack)
246
+ err.setStack(payload.stack);
247
+ // Restore frozen causes from payload (causes are NodeErrorPayload[], not BlokError).
248
+ err.causes = Object.freeze([...payload.causes]);
249
+ return err;
250
+ }
251
+ /** Serialize to the canonical {@link NodeErrorPayload} shape (matches proto wire format). */
252
+ toJSON() {
253
+ return {
254
+ code: this.errorCode,
255
+ category: this.category,
256
+ severity: this.severity,
257
+ node: this.nodeName,
258
+ sdk: this.sdk,
259
+ sdkVersion: this.sdkVersion,
260
+ runtimeKind: this.runtimeKind,
261
+ at: this.at.toISOString(),
262
+ message: this.message,
263
+ description: this.description,
264
+ remediation: this.remediation,
265
+ docUrl: this.docUrl,
266
+ causes: [...this.causes],
267
+ stack: this.stack ?? "",
268
+ contextSnapshot: this.contextSnapshot,
269
+ httpStatus: this.httpStatus,
270
+ retryable: this.retryable,
271
+ retryAfterMs: this.retryAfterMs,
272
+ details: this.details,
273
+ };
274
+ }
275
+ // =========================================================================
276
+ // Internal helpers
277
+ // =========================================================================
278
+ static flattenCauses(cause) {
279
+ const causes = [];
280
+ let current = cause;
281
+ const visited = new Set();
282
+ while (current && !visited.has(current)) {
283
+ visited.add(current);
284
+ if (current instanceof BlokError) {
285
+ // Append the BlokError's own payload (with `causes` zeroed out so we
286
+ // don't double-count) followed by its already-flattened causes. This
287
+ // keeps the final chain flat regardless of how deeply nested the
288
+ // caller's BlokError-as-cause chain was.
289
+ causes.push(BlokError.causeToPayload(current));
290
+ causes.push(...current.causes);
291
+ break;
292
+ }
293
+ causes.push(BlokError.causeToPayload(current));
294
+ const nextCause = current.cause;
295
+ current = nextCause;
296
+ }
297
+ return causes;
298
+ }
299
+ static causeToPayload(cause) {
300
+ if (cause instanceof BlokError) {
301
+ // Strip the cause's own `causes` to avoid duplication — the caller
302
+ // (flattenCauses) appends them separately to keep the final list flat.
303
+ return { ...cause.toJSON(), causes: [] };
304
+ }
305
+ return {
306
+ code: `UNCAUGHT_${cause.name || "ERROR"}`.toUpperCase(),
307
+ category: ErrorCategory.INTERNAL,
308
+ severity: ErrorSeverity.ERROR,
309
+ node: "",
310
+ sdk: "",
311
+ sdkVersion: "",
312
+ runtimeKind: "",
313
+ at: new Date().toISOString(),
314
+ message: cause.message || "Uncaught error",
315
+ description: "",
316
+ remediation: "",
317
+ docUrl: "",
318
+ causes: [],
319
+ stack: cause.stack ?? "",
320
+ contextSnapshot: null,
321
+ httpStatus: 500,
322
+ retryable: false,
323
+ retryAfterMs: 0,
324
+ details: null,
325
+ };
326
+ }
327
+ }
328
+ //# sourceMappingURL=BlokError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BlokError.js","sourceRoot":"","sources":["../src/BlokError.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,eAAe,CAAC;AAExC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG;IAC5B,UAAU,EAAE,YAAY;IACxB,aAAa,EAAE,eAAe;IAC9B,UAAU,EAAE,YAAY;IACxB,OAAO,EAAE,SAAS;IAClB,UAAU,EAAE,YAAY;IACxB,UAAU,EAAE,YAAY;IACxB,SAAS,EAAE,WAAW;IACtB,QAAQ,EAAE,UAAU;IACpB,SAAS,EAAE,WAAW;IACtB,QAAQ,EAAE,UAAU;IACpB,QAAQ,EAAE,UAAU;IACpB,IAAI,EAAE,MAAM;CACH,CAA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AAC,KAAK,CAAC;YAClG,OAAO,GAAG,SAAS,CAAC;QACrB,CAAC;QACD,OAAO,MAAM,CAAC;IACf,CAAC;IAEO,MAAM,CAAC,cAAc,CAAC,KAAwB;QACrD,IAAI,KAAK,YAAY,SAAS,EAAE,CAAC;YAChC,mEAAmE;YACnE,uEAAuE;YACvE,OAAO,EAAE,GAAG,KAAK,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;QAC1C,CAAC;QAED,OAAO;YACN,IAAI,EAAE,YAAY,KAAK,CAAC,IAAI,IAAI,OAAO,EAAE,CAAC,WAAW,EAAE;YACvD,QAAQ,EAAE,aAAa,CAAC,QAAQ;YAChC,QAAQ,EAAE,aAAa,CAAC,KAAK;YAC7B,IAAI,EAAE,EAAE;YACR,GAAG,EAAE,EAAE;YACP,UAAU,EAAE,EAAE;YACd,WAAW,EAAE,EAAE;YACf,EAAE,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YAC5B,OAAO,EAAE,KAAK,CAAC,OAAO,IAAI,gBAAgB;YAC1C,WAAW,EAAE,EAAE;YACf,WAAW,EAAE,EAAE;YACf,MAAM,EAAE,EAAE;YACV,MAAM,EAAE,EAAE;YACV,KAAK,EAAE,KAAK,CAAC,KAAK,IAAI,EAAE;YACxB,eAAe,EAAE,IAAI;YACrB,UAAU,EAAE,GAAG;YACf,SAAS,EAAE,KAAK;YAChB,YAAY,EAAE,CAAC;YACf,OAAO,EAAE,IAAI;SACb,CAAC;IACH,CAAC;CACD"}
@@ -13,14 +13,108 @@ export default abstract class NodeBase {
13
13
  active: boolean;
14
14
  stop: boolean;
15
15
  originalConfig: ParamsDictionary;
16
- set_var: boolean;
16
+ /**
17
+ * @deprecated v2 default-stores every step's output. `set_var: true` is
18
+ * a no-op (default behaviour); `set_var: false` is normalized to
19
+ * `ephemeral: true` at workflow load time. Reading this field is still
20
+ * supported for legacy code paths but new code should rely on `ephemeral`.
21
+ *
22
+ * Default is `undefined` (NOT `false`) — `false` here would short-circuit
23
+ * `PersistenceHelper.applyStepOutput` and disable the v2 default-store
24
+ * rule for every step that didn't explicitly set the field.
25
+ */
26
+ set_var?: boolean;
27
+ /**
28
+ * Alternative state key for this step's output. When set, the runner
29
+ * stores result.data at `ctx.state[as]` instead of `ctx.state[name]`.
30
+ */
31
+ as?: string;
32
+ /**
33
+ * When true, the runner shallow-merges the keys of result.data into
34
+ * `ctx.state` instead of nesting under the step name. Mutually exclusive
35
+ * with `as`.
36
+ */
37
+ spread: boolean;
38
+ /**
39
+ * When true, the runner skips persisting this step's output to state.
40
+ * Only `ctx.prev` carries the result to the immediately next step.
41
+ */
42
+ ephemeral: boolean;
43
+ /**
44
+ * Optional cache key for this step's result. When set, the runner consults
45
+ * the idempotency cache before executing — a hit returns the cached result
46
+ * (and emits a NODE_CACHED event); a miss runs the step and caches its
47
+ * result on success. Cache namespace is (workflowName, name, idempotencyKey).
48
+ *
49
+ * Author-facing values may be a literal string ("user-123") or a $ proxy
50
+ * expression compiled to `js/ctx....`. The runner resolves the expression
51
+ * against the live ctx at run time before consulting the cache.
52
+ */
53
+ idempotencyKey?: string;
54
+ /**
55
+ * Optional cache lifetime in milliseconds. Defaults to 24 hours
56
+ * (86_400_000) when undefined. Pass 0 to mark a stored result as
57
+ * immediately expired (effectively disables caching for this step).
58
+ */
59
+ idempotencyKeyTTL?: number;
60
+ /**
61
+ * Optional retry configuration with capped exponential backoff. When
62
+ * undefined, the step runs at most once (matches pre-v0.3.x behaviour).
63
+ * Per-attempt failures emit `NODE_ATTEMPT_FAILED` trace events.
64
+ */
65
+ retry?: {
66
+ maxAttempts: number;
67
+ minTimeoutInMs?: number;
68
+ maxTimeoutInMs?: number;
69
+ factor?: number;
70
+ };
71
+ /**
72
+ * Tier 2 quick-wins — per-attempt execution timeout in milliseconds.
73
+ * When set, `RunnerSteps` wraps each `step.process()` in a setTimeout-
74
+ * based Promise.race. On timeout, throws `StepTimeoutError` (which the
75
+ * retry loop treats as any other error). On final-attempt timeout,
76
+ * the run auto-flips to `"timedOut"` status. When undefined, the
77
+ * step runs without a per-attempt cap (matches pre-quick-wins
78
+ * behaviour).
79
+ *
80
+ * Originally set as a duration string or number on the step schema;
81
+ * `Configuration.getSteps` converts to milliseconds via
82
+ * `parseDuration` before assigning here.
83
+ */
84
+ maxDurationMs?: number;
85
+ /**
86
+ * Name of the workflow to invoke when this step runs. When set, the
87
+ * step's `node` ref is `"@blokjs/subworkflow"` (a sentinel) and the
88
+ * runner resolves it to a `SubworkflowNode` that looks up the child
89
+ * by this name in the `WorkflowRegistry` singleton.
90
+ */
91
+ subworkflow?: string;
92
+ /**
93
+ * If true (default), the parent step blocks until the child workflow
94
+ * completes. The child's `ctx.response` becomes the parent step's
95
+ * output (lands on `state[<id>]` like any other step).
96
+ *
97
+ * `wait: false` (fire-and-forget) is rejected at workflow load time
98
+ * in v0.3.x — the schema includes a deferred-feature error message.
99
+ */
100
+ wait?: boolean;
17
101
  process(ctx: Context, step?: Step): Promise<ResponseContext>;
18
102
  processFlow(ctx: Context): Promise<ResponseContext>;
19
103
  abstract run(ctx: Context): Promise<ResponseContext>;
20
104
  runSteps(step: Step | Step[], ctx: Context): Promise<Context>;
21
105
  runJs(str: string, ctx: Context, data?: ParamsDictionary, func?: FunctionContext, vars?: VarsContext): ParamsDictionary;
106
+ /**
107
+ * @deprecated In v2, return your output and let the runner persist it
108
+ * to `ctx.state[id]` automatically. Use `ctx.publish(name, value)` for
109
+ * explicit side-channel publication when you really need it. This
110
+ * method continues to work for legacy code.
111
+ */
22
112
  setVar(ctx: Context, vars: VarsContext): void;
23
- getVar(ctx: Context, name: string): ParamsDictionary | undefined;
113
+ /**
114
+ * @deprecated Read from `ctx.state[name]` directly, or reference it from
115
+ * a workflow step's `inputs` as `$.state[name]` / `js/ctx.state.name`.
116
+ */
117
+ getVar(ctx: Context, name: string): unknown;
24
118
  blueprintMapper: (obj: ParamsDictionary, ctx: Context, data?: ParamsDictionary) => string | ParamsDictionary;
25
119
  setError(config: ErrorContext): GlobalError;
26
120
  }
package/dist/NodeBase.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import _ from "lodash";
2
2
  import GlobalError from "./GlobalError";
3
3
  import mapper from "./utils/Mapper";
4
+ import { MapperResolutionError } from "./utils/MapperResolutionError";
4
5
  export default class NodeBase {
5
6
  flow = false;
6
7
  name = "";
@@ -8,7 +9,106 @@ export default class NodeBase {
8
9
  active = true;
9
10
  stop = false;
10
11
  originalConfig = {};
11
- set_var = false;
12
+ /**
13
+ * @deprecated v2 default-stores every step's output. `set_var: true` is
14
+ * a no-op (default behaviour); `set_var: false` is normalized to
15
+ * `ephemeral: true` at workflow load time. Reading this field is still
16
+ * supported for legacy code paths but new code should rely on `ephemeral`.
17
+ *
18
+ * Default is `undefined` (NOT `false`) — `false` here would short-circuit
19
+ * `PersistenceHelper.applyStepOutput` and disable the v2 default-store
20
+ * rule for every step that didn't explicitly set the field.
21
+ */
22
+ set_var;
23
+ // =========================================================================
24
+ // V2 persistence knobs — populated by Configuration.getSteps from the
25
+ // step definition. Read by PersistenceHelper.applyStepOutput.
26
+ // =========================================================================
27
+ /**
28
+ * Alternative state key for this step's output. When set, the runner
29
+ * stores result.data at `ctx.state[as]` instead of `ctx.state[name]`.
30
+ */
31
+ as;
32
+ /**
33
+ * When true, the runner shallow-merges the keys of result.data into
34
+ * `ctx.state` instead of nesting under the step name. Mutually exclusive
35
+ * with `as`.
36
+ */
37
+ spread = false;
38
+ /**
39
+ * When true, the runner skips persisting this step's output to state.
40
+ * Only `ctx.prev` carries the result to the immediately next step.
41
+ */
42
+ ephemeral = false;
43
+ // =========================================================================
44
+ // V2 idempotency cache + retry knobs — populated by Configuration.getSteps
45
+ // from the step definition. Read by RunnerSteps before delegating to
46
+ // `step.process()`. Caching layers ABOVE PersistenceHelper.applyStepOutput;
47
+ // retry wraps the same call site.
48
+ //
49
+ // Mirrors the Zod schema in `@blokjs/helper/src/types/StepOpts.ts`. Kept
50
+ // as a structural interface here to avoid a runtime dep from shared on
51
+ // helper.
52
+ // =========================================================================
53
+ /**
54
+ * Optional cache key for this step's result. When set, the runner consults
55
+ * the idempotency cache before executing — a hit returns the cached result
56
+ * (and emits a NODE_CACHED event); a miss runs the step and caches its
57
+ * result on success. Cache namespace is (workflowName, name, idempotencyKey).
58
+ *
59
+ * Author-facing values may be a literal string ("user-123") or a $ proxy
60
+ * expression compiled to `js/ctx....`. The runner resolves the expression
61
+ * against the live ctx at run time before consulting the cache.
62
+ */
63
+ idempotencyKey;
64
+ /**
65
+ * Optional cache lifetime in milliseconds. Defaults to 24 hours
66
+ * (86_400_000) when undefined. Pass 0 to mark a stored result as
67
+ * immediately expired (effectively disables caching for this step).
68
+ */
69
+ idempotencyKeyTTL;
70
+ /**
71
+ * Optional retry configuration with capped exponential backoff. When
72
+ * undefined, the step runs at most once (matches pre-v0.3.x behaviour).
73
+ * Per-attempt failures emit `NODE_ATTEMPT_FAILED` trace events.
74
+ */
75
+ retry;
76
+ /**
77
+ * Tier 2 quick-wins — per-attempt execution timeout in milliseconds.
78
+ * When set, `RunnerSteps` wraps each `step.process()` in a setTimeout-
79
+ * based Promise.race. On timeout, throws `StepTimeoutError` (which the
80
+ * retry loop treats as any other error). On final-attempt timeout,
81
+ * the run auto-flips to `"timedOut"` status. When undefined, the
82
+ * step runs without a per-attempt cap (matches pre-quick-wins
83
+ * behaviour).
84
+ *
85
+ * Originally set as a duration string or number on the step schema;
86
+ * `Configuration.getSteps` converts to milliseconds via
87
+ * `parseDuration` before assigning here.
88
+ */
89
+ maxDurationMs;
90
+ // =========================================================================
91
+ // V2 sub-workflow knobs — populated by Configuration.getSteps for steps
92
+ // that invoke another workflow (`subworkflow: "<name>"` shape). Read by
93
+ // `SubworkflowNode.run()` to look up the child workflow in the
94
+ // WorkflowRegistry. Mirrors the Zod schema in `@blokjs/helper`.
95
+ // =========================================================================
96
+ /**
97
+ * Name of the workflow to invoke when this step runs. When set, the
98
+ * step's `node` ref is `"@blokjs/subworkflow"` (a sentinel) and the
99
+ * runner resolves it to a `SubworkflowNode` that looks up the child
100
+ * by this name in the `WorkflowRegistry` singleton.
101
+ */
102
+ subworkflow;
103
+ /**
104
+ * If true (default), the parent step blocks until the child workflow
105
+ * completes. The child's `ctx.response` becomes the parent step's
106
+ * output (lands on `state[<id>]` like any other step).
107
+ *
108
+ * `wait: false` (fire-and-forget) is rejected at workflow load time
109
+ * in v0.3.x — the schema includes a deferred-feature error message.
110
+ */
111
+ wait;
12
112
  async process(ctx, step) {
13
113
  let response = {
14
114
  success: true,
@@ -49,11 +149,21 @@ export default class NodeBase {
49
149
  runJs(str, ctx, data = {}, func = {}, vars = {}) {
50
150
  return Function("ctx", "data", "func", "vars", `"use strict";return (${str});`)(ctx, data, func, vars);
51
151
  }
152
+ /**
153
+ * @deprecated In v2, return your output and let the runner persist it
154
+ * to `ctx.state[id]` automatically. Use `ctx.publish(name, value)` for
155
+ * explicit side-channel publication when you really need it. This
156
+ * method continues to work for legacy code.
157
+ */
52
158
  setVar(ctx, vars) {
53
159
  if (ctx.vars === undefined)
54
160
  ctx.vars = {};
55
161
  ctx.vars = { ...ctx.vars, ...vars };
56
162
  }
163
+ /**
164
+ * @deprecated Read from `ctx.state[name]` directly, or reference it from
165
+ * a workflow step's `inputs` as `$.state[name]` / `js/ctx.state.name`.
166
+ */
57
167
  getVar(ctx, name) {
58
168
  return ctx.vars?.[name];
59
169
  }
@@ -66,7 +176,15 @@ export default class NodeBase {
66
176
  mapper.replaceObjectStrings(newObj, ctx, data);
67
177
  }
68
178
  catch (e) {
69
- console.log("MAPPER ERROR", e);
179
+ // `MapperResolutionError` (strict mode) carries full diagnostic
180
+ // context — let it escape so the step's error envelope surfaces
181
+ // the workflow / step / expression that failed.
182
+ if (e instanceof MapperResolutionError)
183
+ throw e;
184
+ // Anything else here is an UNEXPECTED bug in the mapper itself
185
+ // (recursion fault, OOM, logger crash). Surface loudly via
186
+ // stderr WITH the stack trace — never silently swallow.
187
+ console.error("[blok][mapper] unexpected error during input resolution:", e);
70
188
  }
71
189
  return newObj;
72
190
  };
@@ -1 +1 @@
1
- {"version":3,"file":"NodeBase.js","sourceRoot":"","sources":["../src/NodeBase.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,QAAQ,CAAC;AACvB,OAAO,WAAW,MAAM,eAAe,CAAC;AASxC,OAAO,MAAM,MAAM,gBAAgB,CAAC;AAEpC,MAAM,CAAC,OAAO,OAAgB,QAAQ;IAC9B,IAAI,GAAG,KAAK,CAAC;IACb,IAAI,GAAG,EAAE,CAAC;IACV,WAAW,GAAG,EAAE,CAAC;IACjB,MAAM,GAAG,IAAI,CAAC;IACd,IAAI,GAAG,KAAK,CAAC;IACb,cAAc,GAAqB,EAAE,CAAC;IACtC,OAAO,GAAG,KAAK,CAAC;IAEhB,KAAK,CAAC,OAAO,CAAC,GAAY,EAAE,IAAW;QAC7C,IAAI,QAAQ,GAAoB;YAC/B,OAAO,EAAE,IAAI;YACb,IAAI,EAAE,IAAI;YACV,KAAK,EAAE,IAAI;SACX,CAAC;QAEF,MAAM,MAAM,GAAsB,GAAG,CAAC,MAAsC,CAAC;QAC7E,IAAI,CAAC,cAAc,GAAG,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACrD,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC;QAE7C,QAAQ,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAE/B,IAAI,QAAQ,CAAC,KAAK;YAAE,MAAM,QAAQ,CAAC,KAAK,CAAC;QACzC,GAAG,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAExB,OAAO,QAAQ,CAAC;IACjB,CAAC;IAEM,KAAK,CAAC,WAAW,CAAC,GAAY;QACpC,IAAI,QAAQ,GAAoB;YAC/B,OAAO,EAAE,IAAI;YACb,IAAI,EAAE,IAAI;YACV,KAAK,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,CAAC,MAAM,CAAC,CAAC;QAC9C,IAAI,MAAM,CAAC,KAAK;YAAE,YAAY,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACtD,IAAI,MAAM,CAAC,IAAI;YAAE,YAAY,CAAC,OAAO,CAAC,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QAE3F,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEhC,OAAO,YAAY,CAAC;IACrB,CAAC;CACD"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import BlokError, { type BlokErrorOpts, DEFAULT_HTTP_STATUS, DEFAULT_RETRYABLE, ErrorCategory, ErrorSeverity, type NodeErrorPayload } from "./BlokError";
1
2
  import GlobalError from "./GlobalError";
2
3
  import GlobalLogger from "./GlobalLogger";
3
4
  import { Metrics, type MetricsType } from "./Metrics";
@@ -11,6 +12,8 @@ import LoggerContext from "./types/LoggerContext";
11
12
  import NodeConfigContext from "./types/NodeConfigContext";
12
13
  import RequestContext from "./types/RequestContext";
13
14
  import ResponseContext from "./types/ResponseContext";
15
+ import StateContext from "./types/StateContext";
14
16
  import Step from "./types/Step";
17
+ import VarsContext from "./types/VarsContext";
15
18
  import MemoryUsage from "./utils/MemoryUsage";
16
- export { NodeBase, Context, RequestContext, ResponseContext, ErrorContext, LoggerContext, ConfigContext, Trigger, NodeConfigContext, FunctionContext, Step, GlobalLogger, GlobalError, Metrics, MemoryUsage, type MetricsType, };
19
+ export { NodeBase, Context, RequestContext, ResponseContext, ErrorContext, LoggerContext, ConfigContext, Trigger, NodeConfigContext, FunctionContext, StateContext, VarsContext, Step, GlobalLogger, GlobalError, BlokError, type BlokErrorOpts, type NodeErrorPayload, ErrorCategory, ErrorSeverity, DEFAULT_HTTP_STATUS, DEFAULT_RETRYABLE, Metrics, MemoryUsage, type MetricsType, };
package/dist/index.js CHANGED
@@ -1,8 +1,9 @@
1
+ import BlokError, { DEFAULT_HTTP_STATUS, DEFAULT_RETRYABLE, ErrorCategory, ErrorSeverity, } from "./BlokError";
1
2
  import GlobalError from "./GlobalError";
2
3
  import GlobalLogger from "./GlobalLogger";
3
4
  import { Metrics } from "./Metrics";
4
5
  import NodeBase from "./NodeBase";
5
6
  import Trigger from "./Trigger";
6
7
  import MemoryUsage from "./utils/MemoryUsage";
7
- export { NodeBase, Trigger, GlobalLogger, GlobalError, Metrics, MemoryUsage, };
8
+ export { NodeBase, Trigger, GlobalLogger, GlobalError, BlokError, ErrorCategory, ErrorSeverity, DEFAULT_HTTP_STATUS, DEFAULT_RETRYABLE, Metrics, MemoryUsage, };
8
9
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,eAAe,CAAC;AACxC,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAoB,MAAM,WAAW,CAAC;AACtD,OAAO,QAAQ,MAAM,YAAY,CAAC;AAClC,OAAO,OAAO,MAAM,WAAW,CAAC;AAUhC,OAAO,WAAW,MAAM,qBAAqB,CAAC;AAE9C,OAAO,EACN,QAAQ,EAOR,OAAO,EAIP,YAAY,EACZ,WAAW,EACX,OAAO,EACP,WAAW,GAEX,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,EAAE,EAEjB,mBAAmB,EACnB,iBAAiB,EACjB,aAAa,EACb,aAAa,GAEb,MAAM,aAAa,CAAC;AACrB,OAAO,WAAW,MAAM,eAAe,CAAC;AACxC,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAoB,MAAM,WAAW,CAAC;AACtD,OAAO,QAAQ,MAAM,YAAY,CAAC;AAClC,OAAO,OAAO,MAAM,WAAW,CAAC;AAYhC,OAAO,WAAW,MAAM,qBAAqB,CAAC;AAE9C,OAAO,EACN,QAAQ,EAOR,OAAO,EAMP,YAAY,EACZ,WAAW,EACX,SAAS,EAGT,aAAa,EACb,aAAa,EACb,mBAAmB,EACnB,iBAAiB,EACjB,OAAO,EACP,WAAW,GAEX,CAAC"}