@ondc/automation-mock-runner 1.3.22 → 1.3.25
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 +9 -0
- package/dist/lib/configHelper.d.ts +9 -0
- package/dist/lib/configHelper.js +3 -0
- package/dist/lib/types/mock-config.d.ts +24 -0
- package/dist/lib/types/mock-config.js +11 -0
- package/dist/lib/utils/validateConfig.js +23 -0
- package/dist/test/helper-config.test.js +3 -0
- package/package.json +1 -1
package/dist/lib/MockRunner.d.ts
CHANGED
|
@@ -15,6 +15,9 @@ export declare class MockRunner {
|
|
|
15
15
|
version: string;
|
|
16
16
|
flowId: string;
|
|
17
17
|
config_version?: string | undefined;
|
|
18
|
+
description?: string | undefined;
|
|
19
|
+
use_case_id?: string | undefined;
|
|
20
|
+
flowName?: string | undefined;
|
|
18
21
|
};
|
|
19
22
|
transaction_data: {
|
|
20
23
|
transaction_id: string;
|
|
@@ -45,6 +48,12 @@ export declare class MockRunner {
|
|
|
45
48
|
formHtml?: string | undefined;
|
|
46
49
|
};
|
|
47
50
|
repeatCount?: number | null | undefined;
|
|
51
|
+
examples?: {
|
|
52
|
+
name: string;
|
|
53
|
+
payload: any;
|
|
54
|
+
type: "request" | "response";
|
|
55
|
+
description?: string | undefined;
|
|
56
|
+
}[] | undefined;
|
|
48
57
|
}[];
|
|
49
58
|
transaction_history: {
|
|
50
59
|
action_id: string;
|
|
@@ -42,6 +42,9 @@ export declare function generatePlaygroundConfigFromFlowConfig(payloads: Payload
|
|
|
42
42
|
version: string;
|
|
43
43
|
flowId: string;
|
|
44
44
|
config_version?: string | undefined;
|
|
45
|
+
description?: string | undefined;
|
|
46
|
+
use_case_id?: string | undefined;
|
|
47
|
+
flowName?: string | undefined;
|
|
45
48
|
};
|
|
46
49
|
transaction_data: {
|
|
47
50
|
transaction_id: string;
|
|
@@ -72,6 +75,12 @@ export declare function generatePlaygroundConfigFromFlowConfig(payloads: Payload
|
|
|
72
75
|
formHtml?: string | undefined;
|
|
73
76
|
};
|
|
74
77
|
repeatCount?: number | null | undefined;
|
|
78
|
+
examples?: {
|
|
79
|
+
name: string;
|
|
80
|
+
payload: any;
|
|
81
|
+
type: "request" | "response";
|
|
82
|
+
description?: string | undefined;
|
|
83
|
+
}[] | undefined;
|
|
75
84
|
}[];
|
|
76
85
|
transaction_history: {
|
|
77
86
|
action_id: string;
|
package/dist/lib/configHelper.js
CHANGED
|
@@ -8,6 +8,9 @@ export declare const MetaSchema: z.ZodObject<{
|
|
|
8
8
|
version: z.ZodString;
|
|
9
9
|
flowId: z.ZodString;
|
|
10
10
|
config_version: z.ZodOptional<z.ZodString>;
|
|
11
|
+
description: z.ZodOptional<z.ZodString>;
|
|
12
|
+
use_case_id: z.ZodOptional<z.ZodString>;
|
|
13
|
+
flowName: z.ZodOptional<z.ZodString>;
|
|
11
14
|
}, z.core.$strip>;
|
|
12
15
|
export declare const TransactionDataSchema: z.ZodObject<{
|
|
13
16
|
transaction_id: z.ZodString;
|
|
@@ -54,6 +57,15 @@ export declare const PlaygroundActionStepSchema: z.ZodObject<{
|
|
|
54
57
|
}, z.core.$strip>;
|
|
55
58
|
formHtml: z.ZodOptional<z.ZodBase64>;
|
|
56
59
|
}, z.core.$strip>;
|
|
60
|
+
examples: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
61
|
+
name: z.ZodString;
|
|
62
|
+
description: z.ZodOptional<z.ZodString>;
|
|
63
|
+
payload: z.ZodAny;
|
|
64
|
+
type: z.ZodEnum<{
|
|
65
|
+
request: "request";
|
|
66
|
+
response: "response";
|
|
67
|
+
}>;
|
|
68
|
+
}, z.core.$strip>>>;
|
|
57
69
|
}, z.core.$strip>;
|
|
58
70
|
export declare const TransactionHistoryItemSchema: z.ZodObject<{
|
|
59
71
|
action_id: z.ZodString;
|
|
@@ -67,6 +79,9 @@ export declare const MockPlaygroundConfigSchema: z.ZodObject<{
|
|
|
67
79
|
version: z.ZodString;
|
|
68
80
|
flowId: z.ZodString;
|
|
69
81
|
config_version: z.ZodOptional<z.ZodString>;
|
|
82
|
+
description: z.ZodOptional<z.ZodString>;
|
|
83
|
+
use_case_id: z.ZodOptional<z.ZodString>;
|
|
84
|
+
flowName: z.ZodOptional<z.ZodString>;
|
|
70
85
|
}, z.core.$strip>;
|
|
71
86
|
transaction_data: z.ZodObject<{
|
|
72
87
|
transaction_id: z.ZodString;
|
|
@@ -100,6 +115,15 @@ export declare const MockPlaygroundConfigSchema: z.ZodObject<{
|
|
|
100
115
|
}, z.core.$strip>;
|
|
101
116
|
formHtml: z.ZodOptional<z.ZodBase64>;
|
|
102
117
|
}, z.core.$strip>;
|
|
118
|
+
examples: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
119
|
+
name: z.ZodString;
|
|
120
|
+
description: z.ZodOptional<z.ZodString>;
|
|
121
|
+
payload: z.ZodAny;
|
|
122
|
+
type: z.ZodEnum<{
|
|
123
|
+
request: "request";
|
|
124
|
+
response: "response";
|
|
125
|
+
}>;
|
|
126
|
+
}, z.core.$strip>>>;
|
|
103
127
|
}, z.core.$strip>>;
|
|
104
128
|
transaction_history: z.ZodArray<z.ZodObject<{
|
|
105
129
|
action_id: z.ZodString;
|
|
@@ -9,6 +9,9 @@ exports.MetaSchema = zod_1.z.object({
|
|
|
9
9
|
version: zod_1.z.string().min(1, "Version is required"),
|
|
10
10
|
flowId: zod_1.z.string().min(1, "Flow ID is required"),
|
|
11
11
|
config_version: zod_1.z.string().optional(),
|
|
12
|
+
description: zod_1.z.string().optional(),
|
|
13
|
+
use_case_id: zod_1.z.string().optional(),
|
|
14
|
+
flowName: zod_1.z.string().optional(),
|
|
12
15
|
});
|
|
13
16
|
exports.TransactionDataSchema = zod_1.z.object({
|
|
14
17
|
transaction_id: zod_1.z.string().min(1, "Transaction ID is required"),
|
|
@@ -44,6 +47,14 @@ exports.PlaygroundActionStepSchema = zod_1.z.object({
|
|
|
44
47
|
.optional()
|
|
45
48
|
.nullable(),
|
|
46
49
|
mock: exports.MockConfigSchema,
|
|
50
|
+
examples: zod_1.z
|
|
51
|
+
.array(zod_1.z.object({
|
|
52
|
+
name: zod_1.z.string().min(1, "Example name is required"),
|
|
53
|
+
description: zod_1.z.string().optional(),
|
|
54
|
+
payload: zod_1.z.any(),
|
|
55
|
+
type: zod_1.z.enum(["request", "response"]),
|
|
56
|
+
}))
|
|
57
|
+
.optional(),
|
|
47
58
|
});
|
|
48
59
|
exports.TransactionHistoryItemSchema = zod_1.z.object({
|
|
49
60
|
action_id: zod_1.z.string().min(1, "Action ID is required"),
|
|
@@ -1,9 +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;
|
|
4
7
|
exports.validateGoodConfig = validateGoodConfig;
|
|
5
8
|
const mock_config_1 = require("../types/mock-config");
|
|
6
9
|
const errors_1 = require("./errors");
|
|
10
|
+
const ajv_1 = __importDefault(require("ajv"));
|
|
7
11
|
function validateConfigWithErrors(config) {
|
|
8
12
|
const result = mock_config_1.MockPlaygroundConfigSchema.safeParse(config);
|
|
9
13
|
if (result.success) {
|
|
@@ -25,8 +29,15 @@ function validateGoodConfig(config) {
|
|
|
25
29
|
}
|
|
26
30
|
const errors = [];
|
|
27
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();
|
|
28
34
|
config.steps.forEach((step, index) => {
|
|
29
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
|
+
}
|
|
30
41
|
if (id !== undefined) {
|
|
31
42
|
if (sampleData === undefined || sampleData === null) {
|
|
32
43
|
errors.push(`steps[${index}] (action_id: "${step.action_id}"): inputs.sampleData is required when inputs.id is set`);
|
|
@@ -35,6 +46,18 @@ function validateGoodConfig(config) {
|
|
|
35
46
|
errors.push(`steps[${index}] (action_id: "${step.action_id}"): inputs.jsonSchema is required when inputs.id is set`);
|
|
36
47
|
}
|
|
37
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
|
+
}
|
|
38
61
|
});
|
|
39
62
|
// 3. Length of steps must equal length of transaction_history
|
|
40
63
|
// if (config.steps.length !== config.transaction_history.length) {
|
|
@@ -438,6 +438,9 @@ describe("configHelper", () => {
|
|
|
438
438
|
domain: "ONDC:TRV14",
|
|
439
439
|
version: "2.0.0",
|
|
440
440
|
flowId: "test-flow",
|
|
441
|
+
config_version: "0.0.0001",
|
|
442
|
+
description: "",
|
|
443
|
+
use_case_id: "",
|
|
441
444
|
});
|
|
442
445
|
});
|
|
443
446
|
it("should generate a UUID for transaction_id", () => {
|