@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,204 @@
|
|
|
1
|
+
import { log } from '@mondaydotcomorg/atp-runtime';
|
|
2
|
+
import type { ExecutionConfig, CallbackType, CacheProvider } from '@mondaydotcomorg/atp-protocol';
|
|
3
|
+
import type { ProvenanceState, ProvenanceSnapshot } from '@mondaydotcomorg/atp-provenance';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Callback request sent to client when execution is paused
|
|
7
|
+
*/
|
|
8
|
+
export interface CallbackRequest {
|
|
9
|
+
type: CallbackType;
|
|
10
|
+
operation: string;
|
|
11
|
+
payload: Record<string, unknown>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Callback execution record for replay
|
|
16
|
+
*/
|
|
17
|
+
export interface CallbackRecord {
|
|
18
|
+
type: CallbackType;
|
|
19
|
+
operation: string;
|
|
20
|
+
payload: Record<string, unknown>;
|
|
21
|
+
result?: unknown;
|
|
22
|
+
timestamp: number;
|
|
23
|
+
sequenceNumber: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Paused execution state
|
|
28
|
+
*/
|
|
29
|
+
export interface PausedExecution {
|
|
30
|
+
executionId: string;
|
|
31
|
+
code: string;
|
|
32
|
+
config: ExecutionConfig;
|
|
33
|
+
clientId: string;
|
|
34
|
+
callbackRequest: CallbackRequest;
|
|
35
|
+
pausedAt: number;
|
|
36
|
+
|
|
37
|
+
callbackHistory: CallbackRecord[];
|
|
38
|
+
currentCallbackIndex: number;
|
|
39
|
+
|
|
40
|
+
context: {
|
|
41
|
+
variables?: Record<string, unknown>;
|
|
42
|
+
codeTransformed?: boolean;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
provenanceState?: ProvenanceState | ProvenanceSnapshot;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Execution state manager using CacheProvider
|
|
50
|
+
* Works with any CacheProvider (MemoryCache, RedisCache, etc.)
|
|
51
|
+
*/
|
|
52
|
+
export class ExecutionStateManager {
|
|
53
|
+
private cache: CacheProvider;
|
|
54
|
+
private keyPrefix: string;
|
|
55
|
+
private ttl: number;
|
|
56
|
+
private maxPauseDuration: number;
|
|
57
|
+
private metrics: {
|
|
58
|
+
totalPauses: number;
|
|
59
|
+
totalResumes: number;
|
|
60
|
+
totalExpired: number;
|
|
61
|
+
totalFailed: number;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
constructor(
|
|
65
|
+
cache: CacheProvider,
|
|
66
|
+
options?: {
|
|
67
|
+
keyPrefix?: string;
|
|
68
|
+
ttl?: number;
|
|
69
|
+
maxPauseDuration?: number;
|
|
70
|
+
}
|
|
71
|
+
) {
|
|
72
|
+
this.cache = cache;
|
|
73
|
+
this.keyPrefix = options?.keyPrefix || 'atp:execution:';
|
|
74
|
+
this.ttl = options?.ttl || 3600;
|
|
75
|
+
this.maxPauseDuration = (options?.maxPauseDuration ?? 3600) * 1000;
|
|
76
|
+
this.metrics = {
|
|
77
|
+
totalPauses: 0,
|
|
78
|
+
totalResumes: 0,
|
|
79
|
+
totalExpired: 0,
|
|
80
|
+
totalFailed: 0,
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
log.info('ExecutionStateManager initialized', {
|
|
84
|
+
cacheProvider: cache.name,
|
|
85
|
+
ttl: this.ttl,
|
|
86
|
+
maxPauseDuration: this.maxPauseDuration / 1000,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Saves paused execution state
|
|
92
|
+
*/
|
|
93
|
+
async pause(state: PausedExecution): Promise<void> {
|
|
94
|
+
this.metrics.totalPauses++;
|
|
95
|
+
|
|
96
|
+
const key = this.getKey(state.executionId);
|
|
97
|
+
const serialized = JSON.stringify(state);
|
|
98
|
+
await this.cache.set(key, serialized, this.ttl);
|
|
99
|
+
|
|
100
|
+
log.info('Execution paused', {
|
|
101
|
+
executionId: state.executionId,
|
|
102
|
+
clientId: state.clientId,
|
|
103
|
+
callbackType: state.callbackRequest.type,
|
|
104
|
+
cacheProvider: this.cache.name,
|
|
105
|
+
ttl: this.ttl,
|
|
106
|
+
maxPauseDuration: this.maxPauseDuration / 1000,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Retrieves paused execution state
|
|
112
|
+
*/
|
|
113
|
+
async get(executionId: string): Promise<PausedExecution | null> {
|
|
114
|
+
const key = this.getKey(executionId);
|
|
115
|
+
const serialized = await this.cache.get(key);
|
|
116
|
+
|
|
117
|
+
if (!serialized) {
|
|
118
|
+
log.warn('Execution not found or expired', { executionId });
|
|
119
|
+
this.metrics.totalExpired++;
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const state = JSON.parse(serialized as string) as PausedExecution;
|
|
124
|
+
|
|
125
|
+
const pauseDuration = Date.now() - state.pausedAt;
|
|
126
|
+
if (pauseDuration > this.maxPauseDuration) {
|
|
127
|
+
log.warn('Execution pause duration exceeded maximum', {
|
|
128
|
+
executionId,
|
|
129
|
+
pauseDuration: pauseDuration / 1000,
|
|
130
|
+
maxDuration: this.maxPauseDuration / 1000,
|
|
131
|
+
});
|
|
132
|
+
await this.delete(executionId);
|
|
133
|
+
this.metrics.totalExpired++;
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
await this.cache.set(key, serialized, this.ttl);
|
|
138
|
+
|
|
139
|
+
this.metrics.totalResumes++;
|
|
140
|
+
return state;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Deletes execution state
|
|
145
|
+
*/
|
|
146
|
+
async delete(executionId: string): Promise<void> {
|
|
147
|
+
const key = this.getKey(executionId);
|
|
148
|
+
await this.cache.delete(key);
|
|
149
|
+
log.debug('Execution state deleted', { executionId });
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Gets the full cache key for an execution ID
|
|
154
|
+
*/
|
|
155
|
+
private getKey(executionId: string): string {
|
|
156
|
+
return `${this.keyPrefix}${executionId}`;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Closes connections and cleanup
|
|
161
|
+
*/
|
|
162
|
+
async close(): Promise<void> {
|
|
163
|
+
if (this.cache.disconnect) {
|
|
164
|
+
await this.cache.disconnect();
|
|
165
|
+
}
|
|
166
|
+
log.debug('ExecutionStateManager closed');
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Gets storage type from cache provider
|
|
171
|
+
*/
|
|
172
|
+
getStorageType(): string {
|
|
173
|
+
return this.cache.name;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Gets pause/resume metrics
|
|
178
|
+
*/
|
|
179
|
+
getMetrics() {
|
|
180
|
+
return {
|
|
181
|
+
...this.metrics,
|
|
182
|
+
successRate:
|
|
183
|
+
this.metrics.totalResumes > 0
|
|
184
|
+
? ((this.metrics.totalResumes / (this.metrics.totalPauses || 1)) * 100).toFixed(2) + '%'
|
|
185
|
+
: '0%',
|
|
186
|
+
expiredRate:
|
|
187
|
+
this.metrics.totalExpired > 0
|
|
188
|
+
? ((this.metrics.totalExpired / (this.metrics.totalPauses || 1)) * 100).toFixed(2) + '%'
|
|
189
|
+
: '0%',
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Resets metrics (useful for testing)
|
|
195
|
+
*/
|
|
196
|
+
resetMetrics(): void {
|
|
197
|
+
this.metrics = {
|
|
198
|
+
totalPauses: 0,
|
|
199
|
+
totalResumes: 0,
|
|
200
|
+
totalExpired: 0,
|
|
201
|
+
totalFailed: 0,
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bridge between AST tracker in isolated-vm and host policy engine
|
|
3
|
+
*/
|
|
4
|
+
import * as ivm from 'isolated-vm';
|
|
5
|
+
import { getProvenance, getProvenanceForPrimitive } from '@mondaydotcomorg/atp-provenance';
|
|
6
|
+
|
|
7
|
+
// Store active isolate contexts for AST mode provenance checking
|
|
8
|
+
const activeIsolates = new Map<string, ivm.Context>();
|
|
9
|
+
|
|
10
|
+
// Cache the getProvenance function to avoid repeated requires
|
|
11
|
+
let cachedGetProvenance: ((value: unknown) => any) | null = null;
|
|
12
|
+
|
|
13
|
+
export function registerIsolateContext(executionId: string, context: ivm.Context): void {
|
|
14
|
+
activeIsolates.set(executionId, context);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function unregisterIsolateContext(executionId: string): void {
|
|
18
|
+
activeIsolates.delete(executionId);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Create a getProvenance function that can check AST tracker inside the isolate
|
|
23
|
+
* Falls back to host-side getProvenance for hint-based tracking
|
|
24
|
+
*/
|
|
25
|
+
export function createASTProvenanceChecker(executionId: string): (value: unknown) => any {
|
|
26
|
+
return (value: unknown) => {
|
|
27
|
+
const context = activeIsolates.get(executionId);
|
|
28
|
+
|
|
29
|
+
// First, try checking in the isolate's AST tracker
|
|
30
|
+
if (context) {
|
|
31
|
+
try {
|
|
32
|
+
// Serialize the value to pass into isolate for checking
|
|
33
|
+
const valueStr =
|
|
34
|
+
typeof value === 'string' || typeof value === 'number'
|
|
35
|
+
? JSON.stringify(String(value))
|
|
36
|
+
: JSON.stringify(value);
|
|
37
|
+
|
|
38
|
+
// Call __check_provenance inside the isolate
|
|
39
|
+
const checkCode = `
|
|
40
|
+
(function() {
|
|
41
|
+
try {
|
|
42
|
+
if (typeof globalThis.__check_provenance !== 'function') {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
const value = ${valueStr};
|
|
46
|
+
const result = globalThis.__check_provenance(value);
|
|
47
|
+
return result;
|
|
48
|
+
} catch (e) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
})()
|
|
52
|
+
`;
|
|
53
|
+
|
|
54
|
+
const result = context.evalSync(checkCode, { timeout: 100, copy: true });
|
|
55
|
+
if (result) {
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
} catch (error) {
|
|
59
|
+
// Fall through to host check
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Fall back to host-side provenance check (for hints and registered metadata)
|
|
64
|
+
// This is critical for checking primitives that were registered via hints
|
|
65
|
+
if (!cachedGetProvenance) {
|
|
66
|
+
cachedGetProvenance = getProvenance;
|
|
67
|
+
}
|
|
68
|
+
const hostResult = cachedGetProvenance?.(value);
|
|
69
|
+
|
|
70
|
+
// Also check getProvenanceForPrimitive for tainted primitives
|
|
71
|
+
if (!hostResult && (typeof value === 'string' || typeof value === 'number')) {
|
|
72
|
+
const primitiveResult = getProvenanceForPrimitive?.(value);
|
|
73
|
+
if (primitiveResult) {
|
|
74
|
+
return primitiveResult;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return hostResult;
|
|
79
|
+
};
|
|
80
|
+
}
|