@ondc/automation-mock-runner 0.0.9 → 0.1.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.
- package/dist/lib/MockRunner.d.ts +4 -1
- package/dist/lib/MockRunner.js +97 -2
- package/package.json +1 -1
package/dist/lib/MockRunner.d.ts
CHANGED
|
@@ -12,8 +12,11 @@ export declare class MockRunner {
|
|
|
12
12
|
errors?: import("zod/v4/core").$ZodIssue[];
|
|
13
13
|
};
|
|
14
14
|
runGeneratePayload(actionId: string, inputs?: any): Promise<ExecutionResult>;
|
|
15
|
+
runGeneratePayloadWithSession(actionId: string, sessionData: any): Promise<ExecutionResult>;
|
|
15
16
|
runValidatePayload(actionId: string, targetPayload: any): Promise<ExecutionResult>;
|
|
16
|
-
|
|
17
|
+
runValidatePayloadWithSession(actionId: string, targetPayload: any, sessionData: any): Promise<ExecutionResult>;
|
|
18
|
+
runMeetRequirements(actionId: string): Promise<ExecutionResult>;
|
|
19
|
+
runMeetRequirementsWithSession(actionId: string, sessionData: any): Promise<ExecutionResult>;
|
|
17
20
|
getDefaultStep(api: string, actionId: string): MockPlaygroundConfigType["steps"][0];
|
|
18
21
|
generateContext(actionId: string, action: string): any;
|
|
19
22
|
getSessionDataUpToStep(index: number): Record<string, any>;
|
package/dist/lib/MockRunner.js
CHANGED
|
@@ -103,6 +103,53 @@ class MockRunner {
|
|
|
103
103
|
};
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
|
+
async runGeneratePayloadWithSession(actionId, sessionData) {
|
|
107
|
+
const executionId = this.logger.createExecutionContext(actionId);
|
|
108
|
+
const startTime = Date.now();
|
|
109
|
+
try {
|
|
110
|
+
this.logger.logExecution(executionId, "Starting payload generation with session data", {
|
|
111
|
+
actionId,
|
|
112
|
+
sessionKeys: Object.keys(sessionData),
|
|
113
|
+
});
|
|
114
|
+
const step = this.config.steps.find((s) => s.action_id === actionId);
|
|
115
|
+
if (!step) {
|
|
116
|
+
const availableActions = this.config.steps.map((s) => s.action_id);
|
|
117
|
+
throw new errors_1.ActionNotFoundError(actionId, availableActions);
|
|
118
|
+
}
|
|
119
|
+
const index = this.config.steps.findIndex((s) => s.action_id === actionId);
|
|
120
|
+
// Deep clone to avoid mutations
|
|
121
|
+
const defaultPayload = JSON.parse(JSON.stringify(step.mock.defaultPayload));
|
|
122
|
+
const context = this.generateContext(step.action_id, step.api);
|
|
123
|
+
defaultPayload.context = context;
|
|
124
|
+
const schema = (0, function_registry_1.getFunctionSchema)("generate");
|
|
125
|
+
const result = await this.getRunnerInstance().execute(MockRunner.decodeBase64(step.mock.generate), schema, [defaultPayload, sessionData]);
|
|
126
|
+
const executionTime = Date.now() - startTime;
|
|
127
|
+
this.logger.logExecution(executionId, "Payload generation with session data completed", {
|
|
128
|
+
actionId,
|
|
129
|
+
success: result.success,
|
|
130
|
+
output: result.result,
|
|
131
|
+
executionTime,
|
|
132
|
+
});
|
|
133
|
+
return result;
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
const executionTime = Date.now() - startTime;
|
|
137
|
+
this.logger.error("Payload generation with session data failed", { actionId, executionTime }, error);
|
|
138
|
+
return {
|
|
139
|
+
timestamp: new Date().toISOString(),
|
|
140
|
+
success: false,
|
|
141
|
+
error: {
|
|
142
|
+
name: error instanceof Error
|
|
143
|
+
? error.constructor.name
|
|
144
|
+
: "PayloadGenerationError",
|
|
145
|
+
message: error.message || "Unknown error",
|
|
146
|
+
},
|
|
147
|
+
logs: [],
|
|
148
|
+
executionTime,
|
|
149
|
+
validation: { isValid: false, errors: [], warnings: [] },
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
}
|
|
106
153
|
async runValidatePayload(actionId, targetPayload) {
|
|
107
154
|
try {
|
|
108
155
|
const step = this.config.steps.find((s) => s.action_id === actionId);
|
|
@@ -129,7 +176,31 @@ class MockRunner {
|
|
|
129
176
|
};
|
|
130
177
|
}
|
|
131
178
|
}
|
|
132
|
-
async
|
|
179
|
+
async runValidatePayloadWithSession(actionId, targetPayload, sessionData) {
|
|
180
|
+
try {
|
|
181
|
+
const step = this.config.steps.find((s) => s.action_id === actionId);
|
|
182
|
+
if (!step) {
|
|
183
|
+
throw new Error(`Action step with ID ${actionId} not found.`);
|
|
184
|
+
}
|
|
185
|
+
const schema = (0, function_registry_1.getFunctionSchema)("validate");
|
|
186
|
+
const result = await this.getRunnerInstance().execute(MockRunner.decodeBase64(step.mock.validate), schema, [targetPayload, sessionData]);
|
|
187
|
+
return result;
|
|
188
|
+
}
|
|
189
|
+
catch (error) {
|
|
190
|
+
return {
|
|
191
|
+
timestamp: new Date().toISOString(),
|
|
192
|
+
success: false,
|
|
193
|
+
error: {
|
|
194
|
+
name: "PayloadValidationError",
|
|
195
|
+
message: error.message || "Unknown error",
|
|
196
|
+
},
|
|
197
|
+
logs: [],
|
|
198
|
+
executionTime: 0,
|
|
199
|
+
validation: { isValid: false, errors: [], warnings: [] },
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
async runMeetRequirements(actionId) {
|
|
133
204
|
try {
|
|
134
205
|
const step = this.config.steps.find((s) => s.action_id === actionId);
|
|
135
206
|
if (!step) {
|
|
@@ -138,7 +209,31 @@ class MockRunner {
|
|
|
138
209
|
const index = this.config.steps.findIndex((s) => s.action_id === actionId);
|
|
139
210
|
const schema = (0, function_registry_1.getFunctionSchema)("meetsRequirements");
|
|
140
211
|
const sessionData = this.getSessionDataUpToStep(index);
|
|
141
|
-
const result = await this.getRunnerInstance().execute(MockRunner.decodeBase64(step.mock.requirements), schema, [
|
|
212
|
+
const result = await this.getRunnerInstance().execute(MockRunner.decodeBase64(step.mock.requirements), schema, [sessionData]);
|
|
213
|
+
return result;
|
|
214
|
+
}
|
|
215
|
+
catch (error) {
|
|
216
|
+
return {
|
|
217
|
+
timestamp: new Date().toISOString(),
|
|
218
|
+
success: false,
|
|
219
|
+
error: {
|
|
220
|
+
name: "MeetRequirementsError",
|
|
221
|
+
message: error.message || "Unknown error",
|
|
222
|
+
},
|
|
223
|
+
logs: [],
|
|
224
|
+
executionTime: 0,
|
|
225
|
+
validation: { isValid: false, errors: [], warnings: [] },
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
async runMeetRequirementsWithSession(actionId, sessionData) {
|
|
230
|
+
try {
|
|
231
|
+
const step = this.config.steps.find((s) => s.action_id === actionId);
|
|
232
|
+
if (!step) {
|
|
233
|
+
throw new Error(`Action step with ID ${actionId} not found.`);
|
|
234
|
+
}
|
|
235
|
+
const schema = (0, function_registry_1.getFunctionSchema)("meetsRequirements");
|
|
236
|
+
const result = await this.getRunnerInstance().execute(MockRunner.decodeBase64(step.mock.requirements), schema, [sessionData]);
|
|
142
237
|
return result;
|
|
143
238
|
}
|
|
144
239
|
catch (error) {
|