@ondc/automation-mock-runner 1.3.21 → 1.3.23
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 +55 -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,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.validateConfigWithErrors = validateConfigWithErrors;
|
|
7
|
+
exports.validateGoodConfig = validateGoodConfig;
|
|
4
8
|
const mock_config_1 = require("../types/mock-config");
|
|
9
|
+
const errors_1 = require("./errors");
|
|
10
|
+
const ajv_1 = __importDefault(require("ajv"));
|
|
5
11
|
function validateConfigWithErrors(config) {
|
|
6
12
|
const result = mock_config_1.MockPlaygroundConfigSchema.safeParse(config);
|
|
7
13
|
if (result.success) {
|
|
@@ -14,3 +20,52 @@ function validateConfigWithErrors(config) {
|
|
|
14
20
|
};
|
|
15
21
|
}
|
|
16
22
|
}
|
|
23
|
+
function validateGoodConfig(config) {
|
|
24
|
+
// 1. Validate base schema
|
|
25
|
+
const baseResult = validateConfigWithErrors(config);
|
|
26
|
+
if (!baseResult.success && baseResult.errors) {
|
|
27
|
+
const messages = baseResult.errors.map((e) => `[${e.path.join(".") || "root"}] ${e.message}`);
|
|
28
|
+
throw new errors_1.ValidationError(`Config schema validation failed with ${messages.length} error(s)`, messages, { flowId: config?.meta?.flowId });
|
|
29
|
+
}
|
|
30
|
+
const errors = [];
|
|
31
|
+
// 2. If inputs.id is present, both sampleData and jsonSchema must also be present
|
|
32
|
+
// Also validate sampleData against jsonSchema when both are present
|
|
33
|
+
const ajv = new ajv_1.default();
|
|
34
|
+
config.steps.forEach((step, index) => {
|
|
35
|
+
const { id, sampleData, jsonSchema } = step.mock.inputs;
|
|
36
|
+
if (step.mock.inputs !== undefined) {
|
|
37
|
+
if (id === undefined || id === null) {
|
|
38
|
+
errors.push(`steps[${index}] (action_id: "${step.action_id}"): inputs.id is required when inputs is defined`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (id !== undefined) {
|
|
42
|
+
if (sampleData === undefined || sampleData === null) {
|
|
43
|
+
errors.push(`steps[${index}] (action_id: "${step.action_id}"): inputs.sampleData is required when inputs.id is set`);
|
|
44
|
+
}
|
|
45
|
+
if (jsonSchema === undefined || jsonSchema === null) {
|
|
46
|
+
errors.push(`steps[${index}] (action_id: "${step.action_id}"): inputs.jsonSchema is required when inputs.id is set`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (sampleData !== undefined &&
|
|
50
|
+
sampleData !== null &&
|
|
51
|
+
jsonSchema !== undefined &&
|
|
52
|
+
jsonSchema !== null) {
|
|
53
|
+
const validate = ajv.compile(jsonSchema);
|
|
54
|
+
const valid = validate(sampleData);
|
|
55
|
+
if (!valid && validate.errors) {
|
|
56
|
+
validate.errors.forEach((e) => {
|
|
57
|
+
errors.push(`steps[${index}] (action_id: "${step.action_id}"): inputs.sampleData${e.dataPath} ${e.message}`);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
// 3. Length of steps must equal length of transaction_history
|
|
63
|
+
// if (config.steps.length !== config.transaction_history.length) {
|
|
64
|
+
// errors.push(
|
|
65
|
+
// `steps length (${config.steps.length}) must equal transaction_history length (${config.transaction_history.length})`,
|
|
66
|
+
// );
|
|
67
|
+
// }
|
|
68
|
+
if (errors.length > 0) {
|
|
69
|
+
throw new errors_1.ValidationError(`Config validation failed with ${errors.length} error(s)`, errors, { flowId: config.meta.flowId });
|
|
70
|
+
}
|
|
71
|
+
}
|