@ductape/sdk 0.4.1 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/context/execution-context.d.ts +3 -0
- package/dist/context/execution-context.js +39 -0
- package/dist/context/execution-context.js.map +1 -1
- package/dist/features/feature-executor.js +17 -9
- package/dist/features/feature-executor.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -18,6 +18,8 @@ export interface DuctapeAssetSpan {
|
|
|
18
18
|
end: number;
|
|
19
19
|
duration_ms: number;
|
|
20
20
|
error_message?: string;
|
|
21
|
+
input?: unknown;
|
|
22
|
+
output?: unknown;
|
|
21
23
|
}
|
|
22
24
|
export interface DuctapeExecutionContext {
|
|
23
25
|
/** Probe internals are represented by one healthcheck observation, not API logs. */
|
|
@@ -64,4 +66,5 @@ export declare function withAssetSpan<T>(asset: {
|
|
|
64
66
|
tag: string;
|
|
65
67
|
operation: string;
|
|
66
68
|
action?: string;
|
|
69
|
+
input?: unknown;
|
|
67
70
|
}, fn: () => Promise<T>): Promise<T>;
|
|
@@ -36,12 +36,47 @@ function executionContextFields(context = currentExecutionContext()) {
|
|
|
36
36
|
const { session: _secretSession, baggage: _baggage, asset_span_sink: _assetSpanSink, healthcheck_probe: _healthcheckProbe, kind: execution_kind } = context, fields = __rest(context, ["session", "baggage", "asset_span_sink", "healthcheck_probe", "kind"]);
|
|
37
37
|
return Object.assign(Object.assign({}, fields), { execution_kind });
|
|
38
38
|
}
|
|
39
|
+
function spanPayload(value, depth = 0) {
|
|
40
|
+
if (depth > 8)
|
|
41
|
+
return '[truncated]';
|
|
42
|
+
if (value === undefined)
|
|
43
|
+
return null;
|
|
44
|
+
if (typeof value === 'bigint')
|
|
45
|
+
return value.toString();
|
|
46
|
+
if (value instanceof Date)
|
|
47
|
+
return value.toISOString();
|
|
48
|
+
if (typeof value === 'string') {
|
|
49
|
+
try {
|
|
50
|
+
const parsed = JSON.parse(value);
|
|
51
|
+
if (parsed && typeof parsed === 'object')
|
|
52
|
+
return spanPayload(parsed, depth + 1);
|
|
53
|
+
}
|
|
54
|
+
catch ( /* Plain strings are valid payloads. */_a) { /* Plain strings are valid payloads. */ }
|
|
55
|
+
return value.slice(0, 16384);
|
|
56
|
+
}
|
|
57
|
+
if (Array.isArray(value))
|
|
58
|
+
return value.slice(0, 100).map(item => spanPayload(item, depth + 1));
|
|
59
|
+
if (!value || typeof value !== 'object')
|
|
60
|
+
return value;
|
|
61
|
+
return Object.fromEntries(Object.entries(value).slice(0, 200).map(([key, item]) => [key,
|
|
62
|
+
/authorization|cookie|token|secret|password|credential|private[_-]?key|access[_-]?key|api[_-]?key|connection[_-]?(url|string)|^session$|^pin$|^transaction$/i.test(key)
|
|
63
|
+
? '[REDACTED]' : spanPayload(item, depth + 1)]));
|
|
64
|
+
}
|
|
65
|
+
function safeSpanPayload(value) {
|
|
66
|
+
try {
|
|
67
|
+
return spanPayload(value);
|
|
68
|
+
}
|
|
69
|
+
catch (_a) {
|
|
70
|
+
return '[unavailable]';
|
|
71
|
+
}
|
|
72
|
+
}
|
|
39
73
|
async function withAssetSpan(asset, fn) {
|
|
40
74
|
const parent = currentExecutionContext();
|
|
41
75
|
if (!(parent === null || parent === void 0 ? void 0 : parent.asset_span_sink))
|
|
42
76
|
return fn();
|
|
43
77
|
const context = createExecutionContext({ kind: 'asset' }, parent);
|
|
44
78
|
const start = Date.now();
|
|
79
|
+
const input = safeSpanPayload(asset.input);
|
|
45
80
|
try {
|
|
46
81
|
const result = await runWithExecutionContext(context, fn);
|
|
47
82
|
const end = Date.now();
|
|
@@ -60,6 +95,8 @@ async function withAssetSpan(asset, fn) {
|
|
|
60
95
|
asset_operation: asset.operation,
|
|
61
96
|
asset_action: asset.action,
|
|
62
97
|
status: 'success',
|
|
98
|
+
input,
|
|
99
|
+
output: safeSpanPayload(result),
|
|
63
100
|
start,
|
|
64
101
|
end,
|
|
65
102
|
duration_ms: end - start,
|
|
@@ -83,6 +120,8 @@ async function withAssetSpan(asset, fn) {
|
|
|
83
120
|
asset_operation: asset.operation,
|
|
84
121
|
asset_action: asset.action,
|
|
85
122
|
status: 'fail',
|
|
123
|
+
input,
|
|
124
|
+
output: null,
|
|
86
125
|
start,
|
|
87
126
|
end,
|
|
88
127
|
duration_ms: end - start,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execution-context.js","sourceRoot":"","sources":["../../src/context/execution-context.ts"],"names":[],"mappings":";;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"execution-context.js","sourceRoot":"","sources":["../../src/context/execution-context.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAkEA,0DAEC;AAED,wDAYC;AAED,0DAEC;AAGD,wDAWC;AAyBD,sCA6DC;AA1LD,6CAAgD;AAChD,mCAAoC;AA+DpC,MAAM,OAAO,GAAG,IAAI,+BAAiB,EAA2B,CAAC;AAEjE,SAAgB,uBAAuB;IACrC,OAAO,OAAO,CAAC,QAAQ,EAAE,CAAC;AAC5B,CAAC;AAED,SAAgB,sBAAsB,CACpC,MAAwC,EACxC,SAA8C,uBAAuB,EAAE;;IAEvE,qDACK,MAAM,GACN,MAAM,KACT,IAAI,EAAE,MAAA,MAAA,MAAM,CAAC,IAAI,mCAAI,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,mCAAI,WAAW,EAChD,QAAQ,EAAE,MAAA,MAAA,MAAM,CAAC,QAAQ,mCAAI,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,QAAQ,mCAAI,IAAA,mBAAU,GAAE,EAC7D,OAAO,EAAE,MAAA,MAAM,CAAC,OAAO,mCAAI,IAAA,mBAAU,GAAE,EACvC,cAAc,EAAE,MAAA,MAAM,CAAC,cAAc,mCAAI,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,OAAO,IACxD;AACJ,CAAC;AAED,S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B,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,sBAAsB,EAAE,OAAO,CAAC,sBAAsB;YACtD,UAAU,EAAE,KAAK,CAAC,IAAI;YACtB,SAAS,EAAE,KAAK,CAAC,GAAG;YACpB,eAAe,EAAE,KAAK,CAAC,SAAS;YAChC,YAAY,EAAE,KAAK,CAAC,MAAM;YAC1B,MAAM,EAAE,MAAM;YACd,KAAK;YACL,MAAM,EAAE,IAAI;YACZ,KAAK;YACL,GAAG;YACH,WAAW,EAAE,GAAG,GAAG,KAAK;YACxB,aAAa,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;SACtE,CAAC,CAAC;QACH,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -8,6 +8,17 @@
|
|
|
8
8
|
* - Tracking feature state and completed steps
|
|
9
9
|
* - Handling signals and checkpoints
|
|
10
10
|
*/
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
11
22
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
23
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
24
|
};
|
|
@@ -443,14 +454,11 @@ class FeatureExecutor {
|
|
|
443
454
|
const encKey = this.getProcessorResultEncryptionKey();
|
|
444
455
|
const processorResult = Object.assign(Object.assign({}, (0, context_1.executionContextFields)()), { process_id: this.state.feature_id, product_id: this.productId || null, env: this.state.env, component: types_1.LogEventTypes.FEATURE, status, start: this.state.started_at, end: Date.now(), retryable: true, result: encKey ? (0, processor_utils_1.encrypt)(resultStr, encKey) : resultStr, input: encKey ? (0, processor_utils_1.encrypt)(inputStr, encKey) : inputStr, feature_id: this.state.feature_id, feature_tag: this.state.feature_tag, product_tag: this.state.product, workspace_id: this.config.workspace_id });
|
|
445
456
|
const assetResults = this.assetSpans.splice(0).map((span) => {
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
});
|
|
452
|
-
const spanInput = stringifyProcessorValue({});
|
|
453
|
-
return Object.assign(Object.assign({}, span), { process_id: span.span_id, product_id: this.productId || null, product_tag: this.state.product, workspace_id: this.config.workspace_id, env: this.state.env, component: 'asset_invocation', execution_kind: 'asset', retryable: true, result: encKey ? (0, processor_utils_1.encrypt)(spanResult, encKey) : spanResult, input: encKey ? (0, processor_utils_1.encrypt)(spanInput, encKey) : spanInput, asset_duration_ms: span.duration_ms, asset_error: span.error_message });
|
|
457
|
+
var _a, _b;
|
|
458
|
+
const { input: _input, output: _output } = span, spanMetadata = __rest(span, ["input", "output"]);
|
|
459
|
+
const spanResult = stringifyProcessorValue((_a = span.output) !== null && _a !== void 0 ? _a : null);
|
|
460
|
+
const spanInput = stringifyProcessorValue((_b = span.input) !== null && _b !== void 0 ? _b : null);
|
|
461
|
+
return Object.assign(Object.assign({}, spanMetadata), { process_id: span.span_id, product_id: this.productId || null, product_tag: this.state.product, workspace_id: this.config.workspace_id, env: this.state.env, component: 'asset_invocation', execution_kind: 'asset', retryable: true, result: encKey ? (0, processor_utils_1.encrypt)(spanResult, encKey) : spanResult, input: encKey ? (0, processor_utils_1.encrypt)(spanInput, encKey) : spanInput, asset_duration_ms: span.duration_ms, asset_error: span.error_message });
|
|
454
462
|
});
|
|
455
463
|
this.trace('execution.persistence.sent', { status, payload: resultData });
|
|
456
464
|
this.processorApiService.enqueueResultsBatch([...this.pendingProcessorResults.splice(0), ...assetResults, processorResult], this.getAuthPayload());
|
|
@@ -930,7 +938,7 @@ class FeatureExecutor {
|
|
|
930
938
|
}
|
|
931
939
|
return value;
|
|
932
940
|
};
|
|
933
|
-
let output = asset ? await (0, context_1.withAssetSpan)(asset, runOperation) : await runOperation();
|
|
941
|
+
let output = asset ? await (0, context_1.withAssetSpan)(Object.assign(Object.assign({}, asset), { input: resolvedInput }), runOperation) : await runOperation();
|
|
934
942
|
(0, exports.assertSuccessfulStepOutput)(output, step.tag);
|
|
935
943
|
// For action steps with no app: if step.output is a template with $ refs (e.g. $Sequence{main}{step-a}{value}-b),
|
|
936
944
|
// resolve it so downstream steps get the correct value (checkpoint / closure-style steps).
|