@ondc/automation-mock-runner 1.1.7 → 1.1.9

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.
@@ -25,9 +25,47 @@ function createInitialMockConfig(domain, version, flowId) {
25
25
  steps: [],
26
26
  transaction_history: [],
27
27
  validationLib: "",
28
- helperLib: "",
28
+ helperLib: MockRunner_1.MockRunner.encodeBase64(defaultHelpers),
29
29
  };
30
30
  }
31
+ const defaultHelpers = `/*
32
+ Custom helper functions available in all mock generation functions.
33
+ these are appended below the generate function for each step.
34
+ */
35
+
36
+ // Generates a UUID v4
37
+ function uuidv4() {
38
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
39
+ const r = Math.random() * 16 | 0;
40
+ const v = c === 'x' ? r : (r & 0x3 | 0x8);
41
+ return v.toString(16);
42
+ });
43
+ }
44
+
45
+ // Generate a 6 digit string ID
46
+ function generate6DigitId() {
47
+ return Math.floor(100000 + Math.random() * 900000).toString();
48
+ }
49
+
50
+ // Returns the current ISO timestamp
51
+ function currentTimestamp() {
52
+ return new Date().toISOString();
53
+ }
54
+
55
+ // Converts ISO 8601 duration string to total seconds
56
+ const isoDurToSec = (duration) => {
57
+ const durRE = /P((\d+)Y)?((\d+)M)?((\d+)W)?((\d+)D)?T?((\d+)H)?((\d+)M)?((\d+)S)?/;
58
+ const s = durRE.exec(duration);
59
+ if (!s) return 0;
60
+
61
+ return (Number(s?.[2]) || 0) * 31536000 +
62
+ (Number(s?.[4]) || 0) * 2628288 +
63
+ (Number(s?.[6]) || 0) * 604800 +
64
+ (Number(s?.[8]) || 0) * 86400 +
65
+ (Number(s?.[10]) || 0) * 3600 +
66
+ (Number(s?.[12]) || 0) * 60 +
67
+ (Number(s?.[14]) || 0);
68
+ };`;
31
69
  function convertToFlowConfig(config) {
32
70
  const flowConfig = {};
33
71
  flowConfig.id = config.meta.flowId;
@@ -25,7 +25,7 @@ exports.FUNCTION_REGISTRY = {
25
25
  description: "The generated payload object to be sent in the API request",
26
26
  },
27
27
  description: "Generates the mock payload for an API call",
28
- timeout: 60 * 1000,
28
+ timeout: 35 * 1000,
29
29
  defaultBody: ` return defaultPayload;`,
30
30
  template: (body) => `/**
31
31
  * Generates the mock payload for an API call in the transaction flow.
@@ -460,7 +460,6 @@ describe("configHelper", () => {
460
460
  expect(result.steps).toEqual([]);
461
461
  expect(result.transaction_history).toEqual([]);
462
462
  expect(result.validationLib).toBe("");
463
- expect(result.helperLib).toBe("");
464
463
  });
465
464
  it("should handle different domain formats", () => {
466
465
  const result1 = (0, configHelper_1.createInitialMockConfig)("ONDC:RET10", "1.0.0", "test");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ondc/automation-mock-runner",
3
- "version": "1.1.7",
3
+ "version": "1.1.9",
4
4
  "description": "A TypeScript library for ONDC automation mock runner",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -108,8 +108,8 @@ function createSandbox() {
108
108
  decodeURIComponent,
109
109
  // Utility functions for ONDC operations
110
110
  setTimeout: (fn, delay) => {
111
- if (delay < 1 || delay > 1000) {
112
- throw new Error("Timeout must be between 1-1000ms");
111
+ if (delay < 1 || delay > 35 * 1000) {
112
+ throw new Error("Timeout must be between 1-35000ms");
113
113
  }
114
114
  return setTimeout(fn, delay);
115
115
  },
@@ -151,7 +151,7 @@ parentPort?.on("message", async (message) => {
151
151
 
152
152
  // Execute the script
153
153
  script.runInContext(context, {
154
- timeout: timeout || 5000,
154
+ timeout: timeout || 35000,
155
155
  breakOnSigint: true,
156
156
  });
157
157
 
@@ -168,8 +168,8 @@ parentPort?.on("message", async (message) => {
168
168
  new Promise((_, reject) =>
169
169
  setTimeout(
170
170
  () => reject(new Error("Function execution timeout")),
171
- timeout || 5000
172
- )
171
+ timeout || 5000,
172
+ ),
173
173
  ),
174
174
  ]);
175
175