@ondc/automation-mock-runner 1.3.28 → 1.3.29

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.
@@ -1,5 +1,5 @@
1
1
  import { MockPlaygroundConfigType } from "../types/mock-config";
2
- import { z } from "zod";
2
+ import z from "zod";
3
3
  export declare function validateConfigWithErrors(config: MockPlaygroundConfigType): {
4
4
  success: boolean;
5
5
  errors?: z.core.$ZodIssue[];
@@ -14,58 +14,45 @@ function validateConfigWithErrors(config) {
14
14
  return { success: true };
15
15
  }
16
16
  else {
17
- return {
18
- success: false,
19
- errors: result.error.issues,
20
- };
17
+ return { success: false, errors: result.error.issues };
21
18
  }
22
19
  }
23
20
  function validateGoodConfig(config) {
24
21
  // 1. Validate base schema
25
22
  const baseResult = validateConfigWithErrors(config);
26
23
  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 });
24
+ const messages = baseResult.errors.map((e) => `[${e.path.join(".") || "root"}]: ${e.message}`);
25
+ throw new errors_1.ValidationError(`Schema validation failed ${messages.length} issue(s):\n\n${messages.join("\n")}\n`, messages, { flowId: config?.meta?.flowId });
29
26
  }
30
27
  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
28
+ // 2. inputs validation
33
29
  const ajv = new ajv_1.default();
34
30
  config.steps.forEach((step, index) => {
35
31
  const { id, sampleData, jsonSchema } = step.mock.inputs;
32
+ const label = `steps[${index}] (action_id: "${step.action_id}")`;
36
33
  if (step.mock.inputs !== undefined) {
37
34
  if (id === undefined || id === null) {
38
- errors.push(`steps[${index}] (action_id: "${step.action_id}"): inputs.id is required when inputs is defined`);
35
+ errors.push(` ${label}: inputs.id is required when inputs is defined`);
39
36
  }
40
37
  }
41
38
  if (id !== undefined) {
42
39
  if (sampleData === undefined || sampleData === null) {
43
- errors.push(`steps[${index}] (action_id: "${step.action_id}"): inputs.sampleData is required when inputs.id is set`);
40
+ errors.push(` ${label}: inputs.sampleData is required when inputs.id is set`);
44
41
  }
45
42
  if (jsonSchema === undefined || jsonSchema === null) {
46
- errors.push(`steps[${index}] (action_id: "${step.action_id}"): inputs.jsonSchema is required when inputs.id is set`);
43
+ errors.push(` ${label}: inputs.jsonSchema is required when inputs.id is set`);
47
44
  }
48
45
  }
49
- if (sampleData !== undefined &&
50
- sampleData !== null &&
51
- jsonSchema !== undefined &&
52
- jsonSchema !== null) {
46
+ if (sampleData != null && jsonSchema != null) {
53
47
  const validate = ajv.compile(jsonSchema);
54
- const valid = validate(sampleData);
55
- if (!valid && validate.errors) {
48
+ if (!validate(sampleData) && validate.errors) {
56
49
  validate.errors.forEach((e) => {
57
- errors.push(`steps[${index}] (action_id: "${step.action_id}"): inputs.sampleData${e.instancePath} ${e.message}`);
50
+ errors.push(` ${label}: inputs.sampleData${e.instancePath} ${e.message}`);
58
51
  });
59
52
  }
60
53
  }
61
54
  });
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
55
  if (errors.length > 0) {
69
- throw new errors_1.ValidationError(`Config validation failed with ${errors.length} error(s)`, errors, { flowId: config.meta.flowId });
56
+ throw new errors_1.ValidationError(`Config validation failed ${errors.length} error(s):\n\n${errors.join("\n")}\n`, errors, { flowId: config.meta.flowId });
70
57
  }
71
58
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ondc/automation-mock-runner",
3
- "version": "1.3.28",
3
+ "version": "1.3.29",
4
4
  "description": "A TypeScript library for ONDC automation mock runner",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",