@mondaydotcomorg/atp-server 0.17.14
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/README.md +489 -0
- package/dist/aggregator/index.d.ts +59 -0
- package/dist/aggregator/index.d.ts.map +1 -0
- package/dist/aggregator/index.js +171 -0
- package/dist/aggregator/index.js.map +1 -0
- package/dist/callback/index.d.ts +98 -0
- package/dist/callback/index.d.ts.map +1 -0
- package/dist/callback/index.js +136 -0
- package/dist/callback/index.js.map +1 -0
- package/dist/client-sessions.d.ts +82 -0
- package/dist/client-sessions.d.ts.map +1 -0
- package/dist/client-sessions.js +174 -0
- package/dist/client-sessions.js.map +1 -0
- package/dist/controllers/definitions.controller.d.ts +4 -0
- package/dist/controllers/definitions.controller.d.ts.map +1 -0
- package/dist/controllers/definitions.controller.js +11 -0
- package/dist/controllers/definitions.controller.js.map +1 -0
- package/dist/controllers/execute.controller.d.ts +18 -0
- package/dist/controllers/execute.controller.d.ts.map +1 -0
- package/dist/controllers/execute.controller.js +122 -0
- package/dist/controllers/execute.controller.js.map +1 -0
- package/dist/controllers/info.controller.d.ts +3 -0
- package/dist/controllers/info.controller.d.ts.map +1 -0
- package/dist/controllers/info.controller.js +13 -0
- package/dist/controllers/info.controller.js.map +1 -0
- package/dist/controllers/resume.controller.d.ts +11 -0
- package/dist/controllers/resume.controller.d.ts.map +1 -0
- package/dist/controllers/resume.controller.js +61 -0
- package/dist/controllers/resume.controller.js.map +1 -0
- package/dist/controllers/search.controller.d.ts +4 -0
- package/dist/controllers/search.controller.d.ts.map +1 -0
- package/dist/controllers/search.controller.js +7 -0
- package/dist/controllers/search.controller.js.map +1 -0
- package/dist/controllers/stream.controller.d.ts +19 -0
- package/dist/controllers/stream.controller.d.ts.map +1 -0
- package/dist/controllers/stream.controller.js +141 -0
- package/dist/controllers/stream.controller.js.map +1 -0
- package/dist/core/config.d.ts +161 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +7 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/http.d.ts +4 -0
- package/dist/core/http.d.ts.map +1 -0
- package/dist/core/http.js +17 -0
- package/dist/core/http.js.map +1 -0
- package/dist/create-server.d.ts +120 -0
- package/dist/create-server.d.ts.map +1 -0
- package/dist/create-server.js +423 -0
- package/dist/create-server.js.map +1 -0
- package/dist/execution-state/index.d.ts +95 -0
- package/dist/execution-state/index.d.ts.map +1 -0
- package/dist/execution-state/index.js +128 -0
- package/dist/execution-state/index.js.map +1 -0
- package/dist/executor/ast-provenance-bridge.d.ts +12 -0
- package/dist/executor/ast-provenance-bridge.d.ts.map +1 -0
- package/dist/executor/ast-provenance-bridge.js +66 -0
- package/dist/executor/ast-provenance-bridge.js.map +1 -0
- package/dist/executor/ast-tracking-runtime.d.ts +7 -0
- package/dist/executor/ast-tracking-runtime.d.ts.map +1 -0
- package/dist/executor/ast-tracking-runtime.js +559 -0
- package/dist/executor/ast-tracking-runtime.js.map +1 -0
- package/dist/executor/bootstrap-generated.d.ts +32 -0
- package/dist/executor/bootstrap-generated.d.ts.map +1 -0
- package/dist/executor/bootstrap-generated.js +90 -0
- package/dist/executor/bootstrap-generated.js.map +1 -0
- package/dist/executor/compiler-config.d.ts +32 -0
- package/dist/executor/compiler-config.d.ts.map +1 -0
- package/dist/executor/compiler-config.js +99 -0
- package/dist/executor/compiler-config.js.map +1 -0
- package/dist/executor/constants.d.ts +4 -0
- package/dist/executor/constants.d.ts.map +1 -0
- package/dist/executor/constants.js +4 -0
- package/dist/executor/constants.js.map +1 -0
- package/dist/executor/error-handler.d.ts +9 -0
- package/dist/executor/error-handler.d.ts.map +1 -0
- package/dist/executor/error-handler.js +95 -0
- package/dist/executor/error-handler.js.map +1 -0
- package/dist/executor/execution-error-handler.d.ts +7 -0
- package/dist/executor/execution-error-handler.d.ts.map +1 -0
- package/dist/executor/execution-error-handler.js +136 -0
- package/dist/executor/execution-error-handler.js.map +1 -0
- package/dist/executor/executor.d.ts +20 -0
- package/dist/executor/executor.d.ts.map +1 -0
- package/dist/executor/executor.js +452 -0
- package/dist/executor/executor.js.map +1 -0
- package/dist/executor/index.d.ts +4 -0
- package/dist/executor/index.d.ts.map +1 -0
- package/dist/executor/index.js +3 -0
- package/dist/executor/index.js.map +1 -0
- package/dist/executor/resume-handler.d.ts +9 -0
- package/dist/executor/resume-handler.d.ts.map +1 -0
- package/dist/executor/resume-handler.js +22 -0
- package/dist/executor/resume-handler.js.map +1 -0
- package/dist/executor/sandbox-builder.d.ts +29 -0
- package/dist/executor/sandbox-builder.d.ts.map +1 -0
- package/dist/executor/sandbox-builder.js +538 -0
- package/dist/executor/sandbox-builder.js.map +1 -0
- package/dist/executor/sandbox-injector.d.ts +7 -0
- package/dist/executor/sandbox-injector.d.ts.map +1 -0
- package/dist/executor/sandbox-injector.js +293 -0
- package/dist/executor/sandbox-injector.js.map +1 -0
- package/dist/executor/types.d.ts +21 -0
- package/dist/executor/types.d.ts.map +1 -0
- package/dist/executor/types.js +2 -0
- package/dist/executor/types.js.map +1 -0
- package/dist/explorer/index.d.ts +69 -0
- package/dist/explorer/index.d.ts.map +1 -0
- package/dist/explorer/index.js +228 -0
- package/dist/explorer/index.js.map +1 -0
- package/dist/handlers/definitions.handler.d.ts +3 -0
- package/dist/handlers/definitions.handler.d.ts.map +1 -0
- package/dist/handlers/definitions.handler.js +11 -0
- package/dist/handlers/definitions.handler.js.map +1 -0
- package/dist/handlers/execute.handler.d.ts +7 -0
- package/dist/handlers/execute.handler.d.ts.map +1 -0
- package/dist/handlers/execute.handler.js +225 -0
- package/dist/handlers/execute.handler.js.map +1 -0
- package/dist/handlers/explorer.handler.d.ts +4 -0
- package/dist/handlers/explorer.handler.d.ts.map +1 -0
- package/dist/handlers/explorer.handler.js +10 -0
- package/dist/handlers/explorer.handler.js.map +1 -0
- package/dist/handlers/init.handler.d.ts +5 -0
- package/dist/handlers/init.handler.d.ts.map +1 -0
- package/dist/handlers/init.handler.js +41 -0
- package/dist/handlers/init.handler.js.map +1 -0
- package/dist/handlers/resume.handler.d.ts +6 -0
- package/dist/handlers/resume.handler.d.ts.map +1 -0
- package/dist/handlers/resume.handler.js +256 -0
- package/dist/handlers/resume.handler.js.map +1 -0
- package/dist/handlers/search.handler.d.ts +5 -0
- package/dist/handlers/search.handler.d.ts.map +1 -0
- package/dist/handlers/search.handler.js +11 -0
- package/dist/handlers/search.handler.js.map +1 -0
- package/dist/http/request-handler.d.ts +15 -0
- package/dist/http/request-handler.d.ts.map +1 -0
- package/dist/http/request-handler.js +94 -0
- package/dist/http/request-handler.js.map +1 -0
- package/dist/http/router.d.ts +4 -0
- package/dist/http/router.d.ts.map +1 -0
- package/dist/http/router.js +32 -0
- package/dist/http/router.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/instrumentation/index.d.ts +5 -0
- package/dist/instrumentation/index.d.ts.map +1 -0
- package/dist/instrumentation/index.js +5 -0
- package/dist/instrumentation/index.js.map +1 -0
- package/dist/instrumentation/serializer.d.ts +61 -0
- package/dist/instrumentation/serializer.d.ts.map +1 -0
- package/dist/instrumentation/serializer.js +334 -0
- package/dist/instrumentation/serializer.js.map +1 -0
- package/dist/instrumentation/state-manager.d.ts +61 -0
- package/dist/instrumentation/state-manager.d.ts.map +1 -0
- package/dist/instrumentation/state-manager.js +205 -0
- package/dist/instrumentation/state-manager.js.map +1 -0
- package/dist/instrumentation/transformer.d.ts +9 -0
- package/dist/instrumentation/transformer.d.ts.map +1 -0
- package/dist/instrumentation/transformer.js +70 -0
- package/dist/instrumentation/transformer.js.map +1 -0
- package/dist/instrumentation/types.d.ts +59 -0
- package/dist/instrumentation/types.d.ts.map +1 -0
- package/dist/instrumentation/types.js +5 -0
- package/dist/instrumentation/types.js.map +1 -0
- package/dist/middleware/audit.d.ts +18 -0
- package/dist/middleware/audit.d.ts.map +1 -0
- package/dist/middleware/audit.js +76 -0
- package/dist/middleware/audit.js.map +1 -0
- package/dist/openapi/index.d.ts +133 -0
- package/dist/openapi/index.d.ts.map +1 -0
- package/dist/openapi/index.js +235 -0
- package/dist/openapi/index.js.map +1 -0
- package/dist/openapi-loader.d.ts +87 -0
- package/dist/openapi-loader.d.ts.map +1 -0
- package/dist/openapi-loader.js +491 -0
- package/dist/openapi-loader.js.map +1 -0
- package/dist/routes/index.d.ts +21 -0
- package/dist/routes/index.d.ts.map +1 -0
- package/dist/routes/index.js +47 -0
- package/dist/routes/index.js.map +1 -0
- package/dist/search/index.d.ts +48 -0
- package/dist/search/index.d.ts.map +1 -0
- package/dist/search/index.js +156 -0
- package/dist/search/index.js.map +1 -0
- package/dist/security/index.d.ts +2 -0
- package/dist/security/index.d.ts.map +1 -0
- package/dist/security/index.js +2 -0
- package/dist/security/index.js.map +1 -0
- package/dist/shutdown.d.ts +19 -0
- package/dist/shutdown.d.ts.map +1 -0
- package/dist/shutdown.js +87 -0
- package/dist/shutdown.js.map +1 -0
- package/dist/utils/banner.d.ts +12 -0
- package/dist/utils/banner.d.ts.map +1 -0
- package/dist/utils/banner.js +18 -0
- package/dist/utils/banner.js.map +1 -0
- package/dist/utils/context.d.ts +16 -0
- package/dist/utils/context.d.ts.map +1 -0
- package/dist/utils/context.js +44 -0
- package/dist/utils/context.js.map +1 -0
- package/dist/utils/error.d.ts +8 -0
- package/dist/utils/error.d.ts.map +1 -0
- package/dist/utils/error.js +17 -0
- package/dist/utils/error.js.map +1 -0
- package/dist/utils/hint-based-instrumentation.d.ts +14 -0
- package/dist/utils/hint-based-instrumentation.d.ts.map +1 -0
- package/dist/utils/hint-based-instrumentation.js +84 -0
- package/dist/utils/hint-based-instrumentation.js.map +1 -0
- package/dist/utils/index.d.ts +8 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +8 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/info.d.ts +20 -0
- package/dist/utils/info.d.ts.map +1 -0
- package/dist/utils/info.js +15 -0
- package/dist/utils/info.js.map +1 -0
- package/dist/utils/provenance-reattachment.d.ts +32 -0
- package/dist/utils/provenance-reattachment.d.ts.map +1 -0
- package/dist/utils/provenance-reattachment.js +115 -0
- package/dist/utils/provenance-reattachment.js.map +1 -0
- package/dist/utils/request.d.ts +21 -0
- package/dist/utils/request.d.ts.map +1 -0
- package/dist/utils/request.js +44 -0
- package/dist/utils/request.js.map +1 -0
- package/dist/utils/response.d.ts +30 -0
- package/dist/utils/response.d.ts.map +1 -0
- package/dist/utils/response.js +53 -0
- package/dist/utils/response.js.map +1 -0
- package/dist/utils/runtime-types.d.ts +6 -0
- package/dist/utils/runtime-types.d.ts.map +1 -0
- package/dist/utils/runtime-types.js +14 -0
- package/dist/utils/runtime-types.js.map +1 -0
- package/dist/utils/schema.d.ts +9 -0
- package/dist/utils/schema.d.ts.map +1 -0
- package/dist/utils/schema.js +13 -0
- package/dist/utils/schema.js.map +1 -0
- package/dist/utils/token-emitter.d.ts +21 -0
- package/dist/utils/token-emitter.d.ts.map +1 -0
- package/dist/utils/token-emitter.js +129 -0
- package/dist/utils/token-emitter.js.map +1 -0
- package/dist/validator/index.d.ts +36 -0
- package/dist/validator/index.d.ts.map +1 -0
- package/dist/validator/index.js +224 -0
- package/dist/validator/index.js.map +1 -0
- package/package.json +68 -0
- package/src/aggregator/index.ts +207 -0
- package/src/callback/index.ts +191 -0
- package/src/client-sessions.ts +234 -0
- package/src/controllers/definitions.controller.ts +19 -0
- package/src/controllers/execute.controller.ts +166 -0
- package/src/controllers/info.controller.ts +14 -0
- package/src/controllers/resume.controller.ts +92 -0
- package/src/controllers/search.controller.ts +16 -0
- package/src/controllers/stream.controller.ts +190 -0
- package/src/core/config.ts +180 -0
- package/src/core/http.ts +21 -0
- package/src/create-server.ts +536 -0
- package/src/execution-state/index.ts +204 -0
- package/src/executor/ast-provenance-bridge.ts +80 -0
- package/src/executor/ast-tracking-runtime.ts +558 -0
- package/src/executor/bootstrap-generated.ts +90 -0
- package/src/executor/compiler-config.ts +146 -0
- package/src/executor/constants.ts +5 -0
- package/src/executor/error-handler.ts +118 -0
- package/src/executor/execution-error-handler.ts +178 -0
- package/src/executor/executor.ts +631 -0
- package/src/executor/index.ts +3 -0
- package/src/executor/resume-handler.ts +39 -0
- package/src/executor/sandbox-builder.ts +684 -0
- package/src/executor/sandbox-injector.ts +345 -0
- package/src/executor/types.ts +22 -0
- package/src/explorer/index.ts +297 -0
- package/src/handlers/definitions.handler.ts +13 -0
- package/src/handlers/execute.handler.ts +286 -0
- package/src/handlers/explorer.handler.ts +18 -0
- package/src/handlers/init.handler.ts +53 -0
- package/src/handlers/resume.handler.ts +316 -0
- package/src/handlers/search.handler.ts +32 -0
- package/src/http/request-handler.ts +117 -0
- package/src/http/router.ts +29 -0
- package/src/index.ts +60 -0
- package/src/instrumentation/index.ts +4 -0
- package/src/instrumentation/serializer.ts +421 -0
- package/src/instrumentation/state-manager.ts +237 -0
- package/src/instrumentation/transformer.ts +84 -0
- package/src/instrumentation/types.ts +76 -0
- package/src/middleware/audit.ts +101 -0
- package/src/openapi/index.ts +378 -0
- package/src/openapi-loader.ts +744 -0
- package/src/routes/index.ts +93 -0
- package/src/search/index.ts +216 -0
- package/src/security/index.ts +1 -0
- package/src/shutdown.ts +108 -0
- package/src/utils/banner.ts +25 -0
- package/src/utils/context.ts +58 -0
- package/src/utils/error.ts +25 -0
- package/src/utils/hint-based-instrumentation.ts +99 -0
- package/src/utils/index.ts +15 -0
- package/src/utils/info.ts +31 -0
- package/src/utils/provenance-reattachment.ts +144 -0
- package/src/utils/request.ts +53 -0
- package/src/utils/response.ts +69 -0
- package/src/utils/runtime-types.ts +14 -0
- package/src/utils/schema.ts +18 -0
- package/src/utils/token-emitter.ts +182 -0
- package/src/validator/index.ts +253 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provenance Re-attachment Utility
|
|
3
|
+
*
|
|
4
|
+
* Re-attaches provenance to values based on verified hints
|
|
5
|
+
*/
|
|
6
|
+
import {
|
|
7
|
+
getProvenance,
|
|
8
|
+
getProvenanceForPrimitive,
|
|
9
|
+
createProvenanceProxy,
|
|
10
|
+
markPrimitiveTainted,
|
|
11
|
+
computeDigest,
|
|
12
|
+
type ProvenanceMetadata,
|
|
13
|
+
} from '@mondaydotcomorg/atp-provenance';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Global registry of hint maps per execution
|
|
17
|
+
* Key: executionId, Value: Map<digest, metadata>
|
|
18
|
+
*/
|
|
19
|
+
const executionHintMaps = new Map<string, Map<string, ProvenanceMetadata>>();
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Global registry of hint values per execution
|
|
23
|
+
* Key: executionId, Value: Map<value, metadata> for substring checking
|
|
24
|
+
*/
|
|
25
|
+
const executionHintValues = new Map<string, Map<string, ProvenanceMetadata>>();
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Store hint map for an execution
|
|
29
|
+
*/
|
|
30
|
+
export function storeHintMap(executionId: string, hintMap: Map<string, ProvenanceMetadata>): void {
|
|
31
|
+
executionHintMaps.set(executionId, hintMap);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Store a hint value for substring matching
|
|
36
|
+
*/
|
|
37
|
+
export function storeHintValue(
|
|
38
|
+
executionId: string,
|
|
39
|
+
value: string,
|
|
40
|
+
metadata: ProvenanceMetadata
|
|
41
|
+
): void {
|
|
42
|
+
let valueMap = executionHintValues.get(executionId);
|
|
43
|
+
if (!valueMap) {
|
|
44
|
+
valueMap = new Map();
|
|
45
|
+
executionHintValues.set(executionId, valueMap);
|
|
46
|
+
}
|
|
47
|
+
valueMap.set(value, metadata);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Get hint map for an execution
|
|
52
|
+
*/
|
|
53
|
+
export function getHintMap(executionId: string): Map<string, ProvenanceMetadata> | undefined {
|
|
54
|
+
return executionHintMaps.get(executionId);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Get hint values for an execution (for substring matching)
|
|
59
|
+
*/
|
|
60
|
+
export function getHintValues(executionId: string): Map<string, ProvenanceMetadata> | undefined {
|
|
61
|
+
return executionHintValues.get(executionId);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Clear hint map for an execution (cleanup)
|
|
66
|
+
*/
|
|
67
|
+
export function clearHintMap(executionId: string): void {
|
|
68
|
+
executionHintMaps.delete(executionId);
|
|
69
|
+
executionHintValues.delete(executionId);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Re-attach provenance from hints to tool arguments
|
|
74
|
+
* Scans arguments recursively and attaches provenance based on value digests
|
|
75
|
+
*/
|
|
76
|
+
export function reattachProvenanceFromHints(
|
|
77
|
+
args: Record<string, unknown>,
|
|
78
|
+
hintMap: Map<string, ProvenanceMetadata>
|
|
79
|
+
): void {
|
|
80
|
+
if (!hintMap || hintMap.size === 0) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const visited = new WeakSet<object>();
|
|
85
|
+
|
|
86
|
+
function processValue(value: unknown): void {
|
|
87
|
+
if (value === null || value === undefined) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Handle primitives (string/number)
|
|
92
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
93
|
+
// Skip if already has provenance
|
|
94
|
+
if (getProvenanceForPrimitive(value)) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Compute digest and check hint map
|
|
99
|
+
const digest = computeDigest(value);
|
|
100
|
+
if (digest && hintMap.has(digest)) {
|
|
101
|
+
const metadata = hintMap.get(digest)!;
|
|
102
|
+
markPrimitiveTainted(value, metadata);
|
|
103
|
+
}
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Handle objects/arrays
|
|
108
|
+
if (typeof value === 'object') {
|
|
109
|
+
// Prevent circular reference processing
|
|
110
|
+
if (visited.has(value as object)) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
visited.add(value as object);
|
|
114
|
+
|
|
115
|
+
// Skip if already has provenance
|
|
116
|
+
if (getProvenance(value)) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Check if object itself has provenance in hints
|
|
121
|
+
const digest = computeDigest(value);
|
|
122
|
+
if (digest && hintMap.has(digest)) {
|
|
123
|
+
const metadata = hintMap.get(digest)!;
|
|
124
|
+
// Note: We can't modify the object in place, but we mark primitives inside
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Process children
|
|
128
|
+
if (Array.isArray(value)) {
|
|
129
|
+
for (const item of value) {
|
|
130
|
+
processValue(item);
|
|
131
|
+
}
|
|
132
|
+
} else {
|
|
133
|
+
for (const childValue of Object.values(value as Record<string, unknown>)) {
|
|
134
|
+
processValue(childValue);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Process all argument values
|
|
141
|
+
for (const value of Object.values(args)) {
|
|
142
|
+
processValue(value);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { IncomingMessage } from 'node:http';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Default maximum request body size (10MB)
|
|
5
|
+
*/
|
|
6
|
+
export const DEFAULT_MAX_BODY_SIZE = 10 * 1024 * 1024;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Reads the full request body as a string
|
|
10
|
+
* @param req - The HTTP request
|
|
11
|
+
* @param maxSize - Maximum allowed body size in bytes (default: 10MB)
|
|
12
|
+
* @returns Promise resolving to the complete body string
|
|
13
|
+
* @throws Error if body exceeds maxSize
|
|
14
|
+
*/
|
|
15
|
+
export function readBody(req: IncomingMessage, maxSize = DEFAULT_MAX_BODY_SIZE): Promise<string> {
|
|
16
|
+
return new Promise((resolve, reject) => {
|
|
17
|
+
let body = '';
|
|
18
|
+
let size = 0;
|
|
19
|
+
|
|
20
|
+
req.on('data', (chunk) => {
|
|
21
|
+
size += chunk.length;
|
|
22
|
+
|
|
23
|
+
if (size > maxSize) {
|
|
24
|
+
req.destroy();
|
|
25
|
+
reject(new Error(`Request body too large (max ${maxSize} bytes)`));
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
body += chunk.toString();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
req.on('end', () => resolve(body));
|
|
33
|
+
req.on('error', reject);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Reads and parses request body as JSON
|
|
39
|
+
* @param req - The HTTP request
|
|
40
|
+
* @param maxSize - Maximum allowed body size in bytes
|
|
41
|
+
* @returns Promise resolving to the parsed JSON object
|
|
42
|
+
*/
|
|
43
|
+
export async function readJsonBody<T = any>(
|
|
44
|
+
req: IncomingMessage,
|
|
45
|
+
maxSize = DEFAULT_MAX_BODY_SIZE
|
|
46
|
+
): Promise<T> {
|
|
47
|
+
const body = await readBody(req, maxSize);
|
|
48
|
+
try {
|
|
49
|
+
return body ? JSON.parse(body) : (null as T);
|
|
50
|
+
} catch (error) {
|
|
51
|
+
throw new Error('Invalid JSON');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { ServerResponse } from 'node:http';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Sends a JSON response
|
|
5
|
+
*/
|
|
6
|
+
export function sendJson(res: ServerResponse, data: unknown, status = 200): void {
|
|
7
|
+
res.writeHead(status, { 'Content-Type': 'application/json' });
|
|
8
|
+
res.end(JSON.stringify(data));
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Sends an error response
|
|
13
|
+
*/
|
|
14
|
+
export function sendError(
|
|
15
|
+
res: ServerResponse,
|
|
16
|
+
error: string | Error,
|
|
17
|
+
status = 500,
|
|
18
|
+
requestId?: string
|
|
19
|
+
): void {
|
|
20
|
+
const message = error instanceof Error ? error.message : error;
|
|
21
|
+
sendJson(
|
|
22
|
+
res,
|
|
23
|
+
{
|
|
24
|
+
error: message,
|
|
25
|
+
...(requestId && { requestId }),
|
|
26
|
+
},
|
|
27
|
+
status
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Sends a 404 Not Found response
|
|
33
|
+
*/
|
|
34
|
+
export function send404(res: ServerResponse): void {
|
|
35
|
+
sendJson(res, { error: 'Not found' }, 404);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Sends a 400 Bad Request response
|
|
40
|
+
*/
|
|
41
|
+
export function sendBadRequest(res: ServerResponse, message: string): void {
|
|
42
|
+
sendJson(res, { error: message }, 400);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Sends a 503 Service Unavailable response
|
|
47
|
+
*/
|
|
48
|
+
export function sendServiceUnavailable(res: ServerResponse, message: string): void {
|
|
49
|
+
sendJson(res, { error: message }, 503);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Sets CORS headers on a response
|
|
54
|
+
*/
|
|
55
|
+
export function setCorsHeaders(res: ServerResponse, origin = '*'): void {
|
|
56
|
+
res.setHeader('Access-Control-Allow-Origin', origin);
|
|
57
|
+
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
|
|
58
|
+
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization, X-Client-ID');
|
|
59
|
+
res.setHeader('Access-Control-Max-Age', '86400');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Handles OPTIONS preflight requests
|
|
64
|
+
*/
|
|
65
|
+
export function handleOptions(res: ServerResponse): void {
|
|
66
|
+
setCorsHeaders(res);
|
|
67
|
+
res.writeHead(204);
|
|
68
|
+
res.end();
|
|
69
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime SDK Type Generator
|
|
3
|
+
*
|
|
4
|
+
* Generates TypeScript definitions from the runtime API registry.
|
|
5
|
+
*/
|
|
6
|
+
import { GENERATED_METADATA, generateRuntimeTypes as generate } from '@mondaydotcomorg/atp-runtime';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Generates TypeScript definitions for the runtime SDK
|
|
10
|
+
* Delegates to the runtime package's own type generator
|
|
11
|
+
*/
|
|
12
|
+
export function generateRuntimeTypes(): string {
|
|
13
|
+
return generate(GENERATED_METADATA);
|
|
14
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a simple type map to a JSON Schema object
|
|
3
|
+
*/
|
|
4
|
+
export function toJSONSchema(types: Record<string, string>): {
|
|
5
|
+
type: 'object';
|
|
6
|
+
properties: Record<string, unknown>;
|
|
7
|
+
required: string[];
|
|
8
|
+
} {
|
|
9
|
+
const properties: Record<string, unknown> = {};
|
|
10
|
+
const required: string[] = [];
|
|
11
|
+
|
|
12
|
+
for (const [key, type] of Object.entries(types)) {
|
|
13
|
+
properties[key] = { type };
|
|
14
|
+
required.push(key);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return { type: 'object', properties, required };
|
|
18
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import {
|
|
2
|
+
issueProvenanceToken,
|
|
3
|
+
type ProvenanceMetadata,
|
|
4
|
+
type ProvenanceMode,
|
|
5
|
+
ProvenanceMode as PM,
|
|
6
|
+
} from '@mondaydotcomorg/atp-provenance';
|
|
7
|
+
import type { CacheProvider } from '@mondaydotcomorg/atp-protocol';
|
|
8
|
+
import type { log } from '@mondaydotcomorg/atp-runtime';
|
|
9
|
+
|
|
10
|
+
type Logger = ReturnType<typeof log.child>;
|
|
11
|
+
|
|
12
|
+
interface TokenEmission {
|
|
13
|
+
path: string;
|
|
14
|
+
token: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Emits provenance tokens for all values in the result that have provenance in the snapshot.
|
|
19
|
+
* This works by:
|
|
20
|
+
* 1. Traversing the actual serialized result object
|
|
21
|
+
* 2. For each value, checking if it matches provenance in the snapshot
|
|
22
|
+
* 3. Emitting tokens with the ACTUAL value for correct digest matching
|
|
23
|
+
*/
|
|
24
|
+
export async function emitProvenanceTokens(
|
|
25
|
+
result: unknown,
|
|
26
|
+
clientId: string,
|
|
27
|
+
executionId: string,
|
|
28
|
+
provenanceMode: ProvenanceMode,
|
|
29
|
+
cacheProvider: CacheProvider,
|
|
30
|
+
logger: Logger,
|
|
31
|
+
maxTokens: number = 5000,
|
|
32
|
+
tokenTTL: number = 3600,
|
|
33
|
+
provenanceSnapshot?: {
|
|
34
|
+
registry: Array<[string, ProvenanceMetadata]>;
|
|
35
|
+
primitives: Array<[string, ProvenanceMetadata]>;
|
|
36
|
+
}
|
|
37
|
+
): Promise<TokenEmission[]> {
|
|
38
|
+
if (provenanceMode === PM.NONE || !result || !provenanceSnapshot) {
|
|
39
|
+
logger.debug('Skipping token emission', {
|
|
40
|
+
hasResult: !!result,
|
|
41
|
+
hasSnapshot: !!provenanceSnapshot,
|
|
42
|
+
mode: provenanceMode,
|
|
43
|
+
});
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
logger.info('Token emission starting from snapshot', {
|
|
48
|
+
executionId,
|
|
49
|
+
registrySize: provenanceSnapshot.registry.length,
|
|
50
|
+
primitiveMapSize: provenanceSnapshot.primitives.length,
|
|
51
|
+
resultType: typeof result,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const tokens: TokenEmission[] = [];
|
|
55
|
+
const visited = new WeakSet<object>();
|
|
56
|
+
const primitiveMap = new Map<string, ProvenanceMetadata>(provenanceSnapshot.primitives);
|
|
57
|
+
|
|
58
|
+
const taintedValues = new Set<string>();
|
|
59
|
+
for (const [key] of provenanceSnapshot.primitives) {
|
|
60
|
+
if (key.startsWith('tainted:')) {
|
|
61
|
+
taintedValues.add(key.slice('tainted:'.length));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const queue: Array<{ value: unknown; path: string }> = [{ value: result, path: '' }];
|
|
66
|
+
|
|
67
|
+
while (queue.length > 0 && tokens.length < maxTokens) {
|
|
68
|
+
const { value, path } = queue.shift()!;
|
|
69
|
+
|
|
70
|
+
if (value === null || value === undefined) {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
75
|
+
const valueStr = String(value);
|
|
76
|
+
|
|
77
|
+
const taintedKey = `tainted:${valueStr}`;
|
|
78
|
+
let meta = primitiveMap.get(taintedKey);
|
|
79
|
+
|
|
80
|
+
if (!meta) {
|
|
81
|
+
for (const [key, metadata] of primitiveMap.entries()) {
|
|
82
|
+
if (!key.startsWith('tainted:')) {
|
|
83
|
+
const parts = key.split(':');
|
|
84
|
+
if (parts.length >= 3) {
|
|
85
|
+
const derivedValue = parts.slice(2).join(':');
|
|
86
|
+
if (derivedValue === valueStr) {
|
|
87
|
+
meta = metadata;
|
|
88
|
+
logger.debug('Found property-derived primitive match', {
|
|
89
|
+
path,
|
|
90
|
+
key,
|
|
91
|
+
valuePreview: valueStr.substring(0, 30),
|
|
92
|
+
});
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (meta) {
|
|
101
|
+
try {
|
|
102
|
+
const token = await issueProvenanceToken(
|
|
103
|
+
meta,
|
|
104
|
+
value,
|
|
105
|
+
clientId,
|
|
106
|
+
executionId,
|
|
107
|
+
cacheProvider,
|
|
108
|
+
tokenTTL
|
|
109
|
+
);
|
|
110
|
+
if (token) {
|
|
111
|
+
tokens.push({ path, token });
|
|
112
|
+
logger.debug('Emitted token for primitive', {
|
|
113
|
+
path,
|
|
114
|
+
valuePreview: typeof value === 'string' ? value.substring(0, 30) : value,
|
|
115
|
+
tokenPrefix: token.substring(0, 10),
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
} catch (error) {
|
|
119
|
+
logger.warn('Failed to issue token for primitive', { path, error });
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (typeof value === 'object') {
|
|
126
|
+
if (visited.has(value as object)) {
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
visited.add(value as object);
|
|
130
|
+
|
|
131
|
+
// For objects, we need to check if ANY of the registry metadata applies
|
|
132
|
+
// Since we can't match by identity, we emit tokens for ALL registry entries
|
|
133
|
+
// and let the client match by digest
|
|
134
|
+
if (provenanceSnapshot.registry.length > 0 && path === '') {
|
|
135
|
+
for (const [id, meta] of provenanceSnapshot.registry) {
|
|
136
|
+
if (tokens.length >= maxTokens) break;
|
|
137
|
+
|
|
138
|
+
try {
|
|
139
|
+
const token = await issueProvenanceToken(
|
|
140
|
+
meta,
|
|
141
|
+
value,
|
|
142
|
+
clientId,
|
|
143
|
+
executionId,
|
|
144
|
+
cacheProvider,
|
|
145
|
+
tokenTTL
|
|
146
|
+
);
|
|
147
|
+
if (token) {
|
|
148
|
+
tokens.push({ path, token });
|
|
149
|
+
logger.debug('Emitted token for object', {
|
|
150
|
+
path,
|
|
151
|
+
id,
|
|
152
|
+
tokenPrefix: token.substring(0, 10),
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
} catch (error) {
|
|
156
|
+
logger.warn('Failed to issue token for object', { path, id, error });
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (Array.isArray(value)) {
|
|
162
|
+
for (let i = 0; i < value.length; i++) {
|
|
163
|
+
queue.push({ value: value[i], path: `${path}/${i}` });
|
|
164
|
+
}
|
|
165
|
+
} else {
|
|
166
|
+
for (const key in value) {
|
|
167
|
+
if (Object.prototype.hasOwnProperty.call(value, key)) {
|
|
168
|
+
const escapedKey = key.replace(/~/g, '~0').replace(/\//g, '~1');
|
|
169
|
+
queue.push({ value: (value as any)[key], path: `${path}/${escapedKey}` });
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (tokens.length >= maxTokens) {
|
|
177
|
+
logger.warn('Max provenance tokens reached', { executionId, maxTokens });
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
logger.info('Token emission completed', { executionId, tokenCount: tokens.length });
|
|
181
|
+
return tokens;
|
|
182
|
+
}
|