@ondc/automation-mock-runner 1.3.6 → 1.3.8

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.
@@ -39,6 +39,7 @@ export declare class MockRunner {
39
39
  id?: string | undefined;
40
40
  jsonSchema?: any;
41
41
  };
42
+ formHtml?: string | undefined;
42
43
  };
43
44
  repeatCount?: number | null | undefined;
44
45
  }[];
@@ -60,7 +61,7 @@ export declare class MockRunner {
60
61
  runValidatePayloadWithSession(actionId: string, targetPayload: any, sessionData: any): Promise<ExecutionResult>;
61
62
  runMeetRequirements(actionId: string): Promise<ExecutionResult>;
62
63
  runMeetRequirementsWithSession(actionId: string, sessionData: any): Promise<ExecutionResult>;
63
- getDefaultStep(api: string, actionId: string): MockPlaygroundConfigType["steps"][0];
64
+ getDefaultStep(api: string, actionId: string, formType?: "dynamic_form" | "html_form"): MockPlaygroundConfigType["steps"][0];
64
65
  generateContext(actionId: string, action: string, sessionData?: any): any;
65
66
  getSessionDataUpToStep(index: number): Promise<Record<string, any>>;
66
67
  static runGetSave(payload: any, expression: string): Promise<ExecutionResult>;
@@ -283,7 +283,29 @@ class MockRunner {
283
283
  };
284
284
  }
285
285
  }
286
- getDefaultStep(api, actionId) {
286
+ getDefaultStep(api, actionId, formType) {
287
+ if (formType === "html_form") {
288
+ throw new Error("HTML form generation is not implemented yet");
289
+ }
290
+ if (formType === "dynamic_form") {
291
+ return {
292
+ api: api,
293
+ action_id: actionId,
294
+ owner: "BPP",
295
+ responseFor: null,
296
+ unsolicited: false,
297
+ description: "please add relevant description",
298
+ mock: {
299
+ generate: MockRunner.encodeBase64((0, function_registry_1.getFunctionSchema)("generate").template((0, function_registry_1.getFunctionSchema)("generate").defaultBody)),
300
+ validate: MockRunner.encodeBase64((0, function_registry_1.getFunctionSchema)("validate").template((0, function_registry_1.getFunctionSchema)("validate").defaultBody)),
301
+ requirements: MockRunner.encodeBase64((0, function_registry_1.getFunctionSchema)("meetsRequirements").template((0, function_registry_1.getFunctionSchema)("meetsRequirements").defaultBody)),
302
+ defaultPayload: {},
303
+ saveData: {},
304
+ inputs: {},
305
+ formHtml: MockRunner.encodeBase64((0, function_registry_1.getDefaultForm)()),
306
+ },
307
+ };
308
+ }
287
309
  return {
288
310
  api: api,
289
311
  action_id: actionId,
@@ -67,6 +67,7 @@ export declare function generatePlaygroundConfigFromFlowConfig(payloads: Payload
67
67
  id?: string | undefined;
68
68
  jsonSchema?: any;
69
69
  };
70
+ formHtml?: string | undefined;
70
71
  };
71
72
  repeatCount?: number | null | undefined;
72
73
  }[];
@@ -76,16 +76,40 @@ function convertToFlowConfig(config) {
76
76
  for (const step of config.steps) {
77
77
  const pair = config.steps.find((s) => s.responseFor === step.action_id)?.action_id ||
78
78
  null;
79
- const flowStep = {
80
- key: step.action_id,
81
- type: step.api,
82
- owner: step.owner,
83
- description: step.description || "",
84
- expect: index === 0 ? true : false,
85
- unsolicited: step.unsolicited,
86
- pair: pair,
87
- repeat: step.repeatCount || 1,
88
- };
79
+ let flowStep = {};
80
+ if (step.api === "dynamic_form") {
81
+ flowStep = {
82
+ key: step.action_id,
83
+ type: "DYNAMIC_FORM",
84
+ owner: step.owner,
85
+ description: step.description || "",
86
+ label: step.description || "FORM",
87
+ unsolicited: step.unsolicited,
88
+ pair: pair,
89
+ repeat: step.repeatCount || 1,
90
+ input: [
91
+ {
92
+ name: "form_submission_id",
93
+ label: "Enter form submission ID",
94
+ type: "DYNAMIC_FORM",
95
+ payloadField: "form_submission_id",
96
+ reference: `$.reference_data.${step.action_id}`,
97
+ },
98
+ ],
99
+ };
100
+ }
101
+ else {
102
+ flowStep = {
103
+ key: step.action_id,
104
+ type: step.api,
105
+ owner: step.owner,
106
+ description: step.description || "",
107
+ expect: index === 0 ? true : false,
108
+ unsolicited: step.unsolicited,
109
+ pair: pair,
110
+ repeat: step.repeatCount || 1,
111
+ };
112
+ }
89
113
  if (step.mock.inputs !== undefined &&
90
114
  step.mock.inputs !== null &&
91
115
  Object.keys(step.mock.inputs).length > 0) {
@@ -24,3 +24,4 @@ export interface FunctionSchema {
24
24
  }
25
25
  export declare const FUNCTION_REGISTRY: Record<string, FunctionSchema>;
26
26
  export declare function getFunctionSchema(property: FunctionNamesType): FunctionSchema;
27
+ export declare function getDefaultForm(): string;
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.FUNCTION_REGISTRY = void 0;
5
5
  exports.getFunctionSchema = getFunctionSchema;
6
+ exports.getDefaultForm = getDefaultForm;
6
7
  exports.FUNCTION_REGISTRY = {
7
8
  generate: {
8
9
  name: "generate",
@@ -149,3 +150,55 @@ function getFunctionSchema(property) {
149
150
  }
150
151
  return item;
151
152
  }
153
+ function getDefaultForm() {
154
+ return `<!DOCTYPE html>
155
+ <html lang="en">
156
+
157
+ <head>
158
+ <meta charset="UTF-8">
159
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
160
+ <title>Additional Details</title>
161
+ </head>
162
+
163
+ <body>
164
+ <form id="additionalDetailsForm" method="POST" action="<%= actionUrl %>">
165
+ <label for="name">Name</label>
166
+ <input type="text" id="name" name="name" />
167
+
168
+ <label for="country">Country</label>
169
+ <input type="text" id="country" name="country" />
170
+
171
+ <label for="countryCode">Country Code</label>
172
+ <input type="text" id="countryCode" name="countryCode" />
173
+
174
+ <label for="age">Age</label>
175
+ <input type="text" id="age" name="age" />
176
+
177
+ <label for="email">Email ID</label>
178
+ <input type="text" id="email" name="email" />
179
+
180
+ <label for="gender">Gender</label>
181
+ <select name="gender" id="gender">
182
+ <option value="male">Male</option>
183
+ <option value="female">Female</option>
184
+ <option value="transgender">Transgender</option>
185
+ </select>
186
+
187
+ <label for="phoneNumber">Phone number</label>
188
+ <input type="text" id="phoneNumber" name="phoneNumber" />
189
+
190
+ <label for="idProof">ID Proof</label>
191
+ <select name="idProof" id="idProof">
192
+ <option value="passport">Passport</option>
193
+ </select>
194
+
195
+ <label for="passportNumber">Passport Number</label>
196
+ <input type="text" id="passportNumber" name="passportNumber" />
197
+ <input type="hidden" id="formId" name="formId" value="FO1">
198
+ <input type="hidden" id="transactionId" name="transactionId" value="cf7bb367-c820-4bc9-9be8-f548e0bbf222">
199
+ <input type="submit" value="Submit">
200
+ </form>
201
+ </body>
202
+
203
+ </html>`;
204
+ }
@@ -26,6 +26,7 @@ export declare const MockConfigSchema: z.ZodObject<{
26
26
  id: z.ZodOptional<z.ZodString>;
27
27
  jsonSchema: z.ZodOptional<z.ZodAny>;
28
28
  }, z.core.$strip>;
29
+ formHtml: z.ZodOptional<z.ZodBase64>;
29
30
  }, z.core.$strip>;
30
31
  export declare const PlaygroundActionStepSchema: z.ZodObject<{
31
32
  api: z.ZodString;
@@ -48,6 +49,7 @@ export declare const PlaygroundActionStepSchema: z.ZodObject<{
48
49
  id: z.ZodOptional<z.ZodString>;
49
50
  jsonSchema: z.ZodOptional<z.ZodAny>;
50
51
  }, z.core.$strip>;
52
+ formHtml: z.ZodOptional<z.ZodBase64>;
51
53
  }, z.core.$strip>;
52
54
  }, z.core.$strip>;
53
55
  export declare const TransactionHistoryItemSchema: z.ZodObject<{
@@ -90,6 +92,7 @@ export declare const MockPlaygroundConfigSchema: z.ZodObject<{
90
92
  id: z.ZodOptional<z.ZodString>;
91
93
  jsonSchema: z.ZodOptional<z.ZodAny>;
92
94
  }, z.core.$strip>;
95
+ formHtml: z.ZodOptional<z.ZodBase64>;
93
96
  }, z.core.$strip>;
94
97
  }, z.core.$strip>>;
95
98
  transaction_history: z.ZodArray<z.ZodObject<{
@@ -27,6 +27,7 @@ exports.MockConfigSchema = zod_1.z.object({
27
27
  id: zod_1.z.string().min(1, "Input ID is required").optional(),
28
28
  jsonSchema: zod_1.z.any().optional(),
29
29
  }),
30
+ formHtml: zod_1.z.base64().optional(),
30
31
  });
31
32
  exports.PlaygroundActionStepSchema = zod_1.z.object({
32
33
  api: zod_1.z.string().min(1, "API is required"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ondc/automation-mock-runner",
3
- "version": "1.3.6",
3
+ "version": "1.3.8",
4
4
  "description": "A TypeScript library for ONDC automation mock runner",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",