@ondc/automation-mock-runner 1.3.21 → 1.3.22
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 +1 -0
- package/dist/lib/MockRunner.js +7 -0
- package/dist/lib/configHelper.d.ts +2 -0
- package/dist/lib/configHelper.js +5 -0
- package/dist/lib/types/mock-config.d.ts +3 -0
- package/dist/lib/types/mock-config.js +1 -0
- package/dist/lib/utils/validateConfig.d.ts +1 -0
- package/dist/lib/utils/validateConfig.js +32 -0
- package/package.json +1 -1
package/dist/lib/MockRunner.d.ts
CHANGED
package/dist/lib/MockRunner.js
CHANGED
|
@@ -373,6 +373,13 @@ class MockRunner {
|
|
|
373
373
|
required: ["email", "password"],
|
|
374
374
|
additionalProperties: false,
|
|
375
375
|
},
|
|
376
|
+
sampleData: {
|
|
377
|
+
email: "john.doe@example.com",
|
|
378
|
+
age: 28,
|
|
379
|
+
password: "SecurePass1",
|
|
380
|
+
website: "https://example.com",
|
|
381
|
+
country: "US",
|
|
382
|
+
},
|
|
376
383
|
},
|
|
377
384
|
},
|
|
378
385
|
};
|
|
@@ -67,6 +67,7 @@ export declare function generatePlaygroundConfigFromFlowConfig(payloads: Payload
|
|
|
67
67
|
inputs: {
|
|
68
68
|
id?: string | undefined;
|
|
69
69
|
jsonSchema?: any;
|
|
70
|
+
sampleData?: any;
|
|
70
71
|
};
|
|
71
72
|
formHtml?: string | undefined;
|
|
72
73
|
};
|
|
@@ -81,4 +82,5 @@ export declare function generatePlaygroundConfigFromFlowConfig(payloads: Payload
|
|
|
81
82
|
validationLib: string;
|
|
82
83
|
helperLib: string;
|
|
83
84
|
}>;
|
|
85
|
+
export declare function validateConfigForDeployment(config: MockPlaygroundConfigType): void;
|
|
84
86
|
export {};
|
package/dist/lib/configHelper.js
CHANGED
|
@@ -5,9 +5,11 @@ exports.convertToFlowConfig = convertToFlowConfig;
|
|
|
5
5
|
exports.createOptimizedMockConfig = createOptimizedMockConfig;
|
|
6
6
|
exports.getMinifiedCode = getMinifiedCode;
|
|
7
7
|
exports.generatePlaygroundConfigFromFlowConfig = generatePlaygroundConfigFromFlowConfig;
|
|
8
|
+
exports.validateConfigForDeployment = validateConfigForDeployment;
|
|
8
9
|
const MockRunner_1 = require("./MockRunner");
|
|
9
10
|
const uuid_1 = require("uuid");
|
|
10
11
|
const terser_1 = require("terser");
|
|
12
|
+
const validateConfig_1 = require("./utils/validateConfig");
|
|
11
13
|
function createInitialMockConfig(domain, version, flowId) {
|
|
12
14
|
return {
|
|
13
15
|
meta: {
|
|
@@ -253,3 +255,6 @@ const cityInputs = {
|
|
|
253
255
|
required: ["city_code"],
|
|
254
256
|
},
|
|
255
257
|
};
|
|
258
|
+
function validateConfigForDeployment(config) {
|
|
259
|
+
(0, validateConfig_1.validateGoodConfig)(config);
|
|
260
|
+
}
|
|
@@ -26,6 +26,7 @@ export declare const MockConfigSchema: z.ZodObject<{
|
|
|
26
26
|
inputs: z.ZodObject<{
|
|
27
27
|
id: z.ZodOptional<z.ZodString>;
|
|
28
28
|
jsonSchema: z.ZodOptional<z.ZodAny>;
|
|
29
|
+
sampleData: z.ZodOptional<z.ZodAny>;
|
|
29
30
|
}, z.core.$strip>;
|
|
30
31
|
formHtml: z.ZodOptional<z.ZodBase64>;
|
|
31
32
|
}, z.core.$strip>;
|
|
@@ -49,6 +50,7 @@ export declare const PlaygroundActionStepSchema: z.ZodObject<{
|
|
|
49
50
|
inputs: z.ZodObject<{
|
|
50
51
|
id: z.ZodOptional<z.ZodString>;
|
|
51
52
|
jsonSchema: z.ZodOptional<z.ZodAny>;
|
|
53
|
+
sampleData: z.ZodOptional<z.ZodAny>;
|
|
52
54
|
}, z.core.$strip>;
|
|
53
55
|
formHtml: z.ZodOptional<z.ZodBase64>;
|
|
54
56
|
}, z.core.$strip>;
|
|
@@ -94,6 +96,7 @@ export declare const MockPlaygroundConfigSchema: z.ZodObject<{
|
|
|
94
96
|
inputs: z.ZodObject<{
|
|
95
97
|
id: z.ZodOptional<z.ZodString>;
|
|
96
98
|
jsonSchema: z.ZodOptional<z.ZodAny>;
|
|
99
|
+
sampleData: z.ZodOptional<z.ZodAny>;
|
|
97
100
|
}, z.core.$strip>;
|
|
98
101
|
formHtml: z.ZodOptional<z.ZodBase64>;
|
|
99
102
|
}, z.core.$strip>;
|
|
@@ -27,6 +27,7 @@ exports.MockConfigSchema = zod_1.z.object({
|
|
|
27
27
|
inputs: zod_1.z.object({
|
|
28
28
|
id: zod_1.z.string().min(1, "Input ID is required").optional(),
|
|
29
29
|
jsonSchema: zod_1.z.any().optional(),
|
|
30
|
+
sampleData: zod_1.z.any().optional(),
|
|
30
31
|
}),
|
|
31
32
|
formHtml: zod_1.z.base64().optional(),
|
|
32
33
|
});
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.validateConfigWithErrors = validateConfigWithErrors;
|
|
4
|
+
exports.validateGoodConfig = validateGoodConfig;
|
|
4
5
|
const mock_config_1 = require("../types/mock-config");
|
|
6
|
+
const errors_1 = require("./errors");
|
|
5
7
|
function validateConfigWithErrors(config) {
|
|
6
8
|
const result = mock_config_1.MockPlaygroundConfigSchema.safeParse(config);
|
|
7
9
|
if (result.success) {
|
|
@@ -14,3 +16,33 @@ function validateConfigWithErrors(config) {
|
|
|
14
16
|
};
|
|
15
17
|
}
|
|
16
18
|
}
|
|
19
|
+
function validateGoodConfig(config) {
|
|
20
|
+
// 1. Validate base schema
|
|
21
|
+
const baseResult = validateConfigWithErrors(config);
|
|
22
|
+
if (!baseResult.success && baseResult.errors) {
|
|
23
|
+
const messages = baseResult.errors.map((e) => `[${e.path.join(".") || "root"}] ${e.message}`);
|
|
24
|
+
throw new errors_1.ValidationError(`Config schema validation failed with ${messages.length} error(s)`, messages, { flowId: config?.meta?.flowId });
|
|
25
|
+
}
|
|
26
|
+
const errors = [];
|
|
27
|
+
// 2. If inputs.id is present, both sampleData and jsonSchema must also be present
|
|
28
|
+
config.steps.forEach((step, index) => {
|
|
29
|
+
const { id, sampleData, jsonSchema } = step.mock.inputs;
|
|
30
|
+
if (id !== undefined) {
|
|
31
|
+
if (sampleData === undefined || sampleData === null) {
|
|
32
|
+
errors.push(`steps[${index}] (action_id: "${step.action_id}"): inputs.sampleData is required when inputs.id is set`);
|
|
33
|
+
}
|
|
34
|
+
if (jsonSchema === undefined || jsonSchema === null) {
|
|
35
|
+
errors.push(`steps[${index}] (action_id: "${step.action_id}"): inputs.jsonSchema is required when inputs.id is set`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
// 3. Length of steps must equal length of transaction_history
|
|
40
|
+
// if (config.steps.length !== config.transaction_history.length) {
|
|
41
|
+
// errors.push(
|
|
42
|
+
// `steps length (${config.steps.length}) must equal transaction_history length (${config.transaction_history.length})`,
|
|
43
|
+
// );
|
|
44
|
+
// }
|
|
45
|
+
if (errors.length > 0) {
|
|
46
|
+
throw new errors_1.ValidationError(`Config validation failed with ${errors.length} error(s)`, errors, { flowId: config.meta.flowId });
|
|
47
|
+
}
|
|
48
|
+
}
|