@ondc/automation-mock-runner 1.3.25 → 1.3.27
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.
|
@@ -13,83 +13,7 @@ type PayloadType = {
|
|
|
13
13
|
core_version?: string;
|
|
14
14
|
};
|
|
15
15
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
*
|
|
19
|
-
* This function takes an array of payloads and a flow configuration, then creates
|
|
20
|
-
* a mock playground configuration by mapping payloads to their corresponding flow steps.
|
|
21
|
-
* Payloads are sorted by timestamp and matched to flow sequence steps by action type.
|
|
22
|
-
*
|
|
23
|
-
* @param payloads - Array of payload objects containing context and action information
|
|
24
|
-
* @param flowConfig - Flow configuration object containing sequence of steps and flow metadata
|
|
25
|
-
*
|
|
26
|
-
* @returns A promise that resolves to a MockPlaygroundConfigType object configured with
|
|
27
|
-
* the mapped steps and their corresponding payloads
|
|
28
|
-
*
|
|
29
|
-
* @throws {Error} When insufficient payloads are provided for the flow sequence
|
|
30
|
-
* @throws {Error} When no payload is found for a required action type in the flow
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* ```typescript
|
|
34
|
-
* const payloads = [{ context: { action: 'search', timestamp: '2023-01-01' } }];
|
|
35
|
-
* const flowConfig = { id: 'flow1', sequence: [{ type: 'search', key: 'step1' }] };
|
|
36
|
-
* const config = await generatePlaygroundConfigFromFlowConfig(payloads, flowConfig);
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
export declare function generatePlaygroundConfigFromFlowConfig(payloads: PayloadType[], flowConfig: Flow): Promise<{
|
|
40
|
-
meta: {
|
|
41
|
-
domain: string;
|
|
42
|
-
version: string;
|
|
43
|
-
flowId: string;
|
|
44
|
-
config_version?: string | undefined;
|
|
45
|
-
description?: string | undefined;
|
|
46
|
-
use_case_id?: string | undefined;
|
|
47
|
-
flowName?: string | undefined;
|
|
48
|
-
};
|
|
49
|
-
transaction_data: {
|
|
50
|
-
transaction_id: string;
|
|
51
|
-
latest_timestamp: string;
|
|
52
|
-
bap_id?: string | undefined;
|
|
53
|
-
bap_uri?: string | undefined;
|
|
54
|
-
bpp_id?: string | undefined;
|
|
55
|
-
bpp_uri?: string | undefined;
|
|
56
|
-
};
|
|
57
|
-
steps: {
|
|
58
|
-
api: string;
|
|
59
|
-
action_id: string;
|
|
60
|
-
owner: "BAP" | "BPP";
|
|
61
|
-
responseFor: string | null;
|
|
62
|
-
unsolicited: boolean;
|
|
63
|
-
description: string;
|
|
64
|
-
mock: {
|
|
65
|
-
generate: string;
|
|
66
|
-
validate: string;
|
|
67
|
-
requirements: string;
|
|
68
|
-
defaultPayload: any;
|
|
69
|
-
saveData: Record<string, string>;
|
|
70
|
-
inputs: {
|
|
71
|
-
id?: string | undefined;
|
|
72
|
-
jsonSchema?: any;
|
|
73
|
-
sampleData?: any;
|
|
74
|
-
};
|
|
75
|
-
formHtml?: string | undefined;
|
|
76
|
-
};
|
|
77
|
-
repeatCount?: number | null | undefined;
|
|
78
|
-
examples?: {
|
|
79
|
-
name: string;
|
|
80
|
-
payload: any;
|
|
81
|
-
type: "request" | "response";
|
|
82
|
-
description?: string | undefined;
|
|
83
|
-
}[] | undefined;
|
|
84
|
-
}[];
|
|
85
|
-
transaction_history: {
|
|
86
|
-
action_id: string;
|
|
87
|
-
payload: any;
|
|
88
|
-
saved_info: Record<string, any>;
|
|
89
|
-
action?: string | undefined;
|
|
90
|
-
}[];
|
|
91
|
-
validationLib: string;
|
|
92
|
-
helperLib: string;
|
|
93
|
-
}>;
|
|
16
|
+
export declare function generatePlaygroundConfigFromFlowConfig(payloads: PayloadType[], flowConfig: Flow): Promise<MockPlaygroundConfigType>;
|
|
17
|
+
export declare function generatePlaygroundConfigFromFlowConfigWithMeta(payloads: PayloadType[], flowConfig: Flow, domain: string, version: string): Promise<MockPlaygroundConfigType>;
|
|
94
18
|
export declare function validateConfigForDeployment(config: MockPlaygroundConfigType): void;
|
|
95
19
|
export {};
|
package/dist/lib/configHelper.js
CHANGED
|
@@ -5,6 +5,7 @@ exports.convertToFlowConfig = convertToFlowConfig;
|
|
|
5
5
|
exports.createOptimizedMockConfig = createOptimizedMockConfig;
|
|
6
6
|
exports.getMinifiedCode = getMinifiedCode;
|
|
7
7
|
exports.generatePlaygroundConfigFromFlowConfig = generatePlaygroundConfigFromFlowConfig;
|
|
8
|
+
exports.generatePlaygroundConfigFromFlowConfigWithMeta = generatePlaygroundConfigFromFlowConfigWithMeta;
|
|
8
9
|
exports.validateConfigForDeployment = validateConfigForDeployment;
|
|
9
10
|
const MockRunner_1 = require("./MockRunner");
|
|
10
11
|
const uuid_1 = require("uuid");
|
|
@@ -200,12 +201,10 @@ async function getMinifiedCode(base64Code) {
|
|
|
200
201
|
* const config = await generatePlaygroundConfigFromFlowConfig(payloads, flowConfig);
|
|
201
202
|
* ```
|
|
202
203
|
*/
|
|
203
|
-
async function
|
|
204
|
+
async function buildConfigFromFlowConfig(payloads, flowConfig, domain, version) {
|
|
204
205
|
flowConfig = JSON.parse(JSON.stringify(flowConfig));
|
|
205
|
-
payloads = payloads.sort((a, b) => new Date(a.context.timestamp).getTime() -
|
|
206
|
+
payloads = [...payloads].sort((a, b) => new Date(a.context.timestamp).getTime() -
|
|
206
207
|
new Date(b.context.timestamp).getTime());
|
|
207
|
-
const domain = payloads[0].context.domain;
|
|
208
|
-
const version = payloads[0].context.version || payloads[0].context.core_version || "1.0.0";
|
|
209
208
|
const config = createInitialMockConfig(domain, version, `${flowConfig.id}_logs_flow_${domain}_v${version}`);
|
|
210
209
|
const mockRunner = new MockRunner_1.MockRunner(config);
|
|
211
210
|
let index = 0;
|
|
@@ -244,6 +243,17 @@ async function generatePlaygroundConfigFromFlowConfig(payloads, flowConfig) {
|
|
|
244
243
|
}
|
|
245
244
|
return config;
|
|
246
245
|
}
|
|
246
|
+
async function generatePlaygroundConfigFromFlowConfig(payloads, flowConfig) {
|
|
247
|
+
if (payloads.length === 0) {
|
|
248
|
+
throw new Error("payloads must not be empty. Use generatePlaygroundConfigFromFlowConfigWithMeta to supply domain and version explicitly.");
|
|
249
|
+
}
|
|
250
|
+
const domain = payloads[0].context.domain;
|
|
251
|
+
const version = payloads[0].context.version || payloads[0].context.core_version || "1.0.0";
|
|
252
|
+
return buildConfigFromFlowConfig(payloads, flowConfig, domain, version);
|
|
253
|
+
}
|
|
254
|
+
async function generatePlaygroundConfigFromFlowConfigWithMeta(payloads, flowConfig, domain, version) {
|
|
255
|
+
return buildConfigFromFlowConfig(payloads, flowConfig, domain, version);
|
|
256
|
+
}
|
|
247
257
|
const cityInputs = {
|
|
248
258
|
id: "ExampleInputId",
|
|
249
259
|
jsonSchema: {
|
|
@@ -54,7 +54,7 @@ function validateGoodConfig(config) {
|
|
|
54
54
|
const valid = validate(sampleData);
|
|
55
55
|
if (!valid && validate.errors) {
|
|
56
56
|
validate.errors.forEach((e) => {
|
|
57
|
-
errors.push(`steps[${index}] (action_id: "${step.action_id}"): inputs.sampleData${e.
|
|
57
|
+
errors.push(`steps[${index}] (action_id: "${step.action_id}"): inputs.sampleData${e.instancePath} ${e.message}`);
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
60
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ondc/automation-mock-runner",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.27",
|
|
4
4
|
"description": "A TypeScript library for ONDC automation mock runner",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -76,6 +76,7 @@
|
|
|
76
76
|
"dependencies": {
|
|
77
77
|
"acorn": "^8.15.0",
|
|
78
78
|
"acorn-walk": "^8.3.4",
|
|
79
|
+
"ajv": "^8.18.0",
|
|
79
80
|
"base-64": "^1.0.0",
|
|
80
81
|
"jsonpath": "^1.1.1",
|
|
81
82
|
"terser": "^5.44.1",
|