@postman-enricher/core 1.2.7 → 1.2.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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Preservation - Maintains IDs and request bodies across collection regenerations
|
|
3
3
|
*/
|
|
4
4
|
import type { PostmanCollection } from '@postman-enricher/shared';
|
|
5
5
|
export declare function preserveIds(collection: PostmanCollection, existingPath?: string): PostmanCollection;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Preservation - Maintains IDs and request bodies across collection regenerations
|
|
3
3
|
*/
|
|
4
4
|
import { walkCollection, isRequest, getRequestMethod, } from '@postman-enricher/shared';
|
|
5
5
|
import { readFileSync, existsSync } from 'fs';
|
|
@@ -11,17 +11,25 @@ export function preserveIds(collection, existingPath) {
|
|
|
11
11
|
const existing = JSON.parse(readFileSync(existingPath, 'utf8'));
|
|
12
12
|
const idMap = buildIdMap(existing);
|
|
13
13
|
const responseIdMap = buildResponseIdMap(existing);
|
|
14
|
+
const requestBodyMap = buildRequestBodyMap(existing);
|
|
14
15
|
// Restore collection ID
|
|
15
16
|
if (existing.info?._postman_id) {
|
|
16
17
|
collection.info._postman_id = existing.info._postman_id;
|
|
17
18
|
}
|
|
18
|
-
// Restore item IDs and
|
|
19
|
+
// Restore item IDs, response IDs, and request bodies
|
|
19
20
|
walkCollection(collection.item, (item) => {
|
|
20
21
|
const key = getItemKey(item);
|
|
21
22
|
const existingId = idMap.get(key);
|
|
22
23
|
if (existingId) {
|
|
23
24
|
item.id = existingId;
|
|
24
25
|
}
|
|
26
|
+
// Restore request body
|
|
27
|
+
if (isRequest(item) && item.request?.body) {
|
|
28
|
+
const existingBody = requestBodyMap.get(key);
|
|
29
|
+
if (existingBody) {
|
|
30
|
+
item.request.body.raw = existingBody;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
25
33
|
// Restore response IDs
|
|
26
34
|
if (isRequest(item) && item.response) {
|
|
27
35
|
for (const response of item.response) {
|
|
@@ -64,6 +72,16 @@ function buildResponseIdMap(collection) {
|
|
|
64
72
|
});
|
|
65
73
|
return map;
|
|
66
74
|
}
|
|
75
|
+
function buildRequestBodyMap(collection) {
|
|
76
|
+
const map = new Map();
|
|
77
|
+
walkCollection(collection.item, (item) => {
|
|
78
|
+
if (isRequest(item) && item.request?.body?.raw) {
|
|
79
|
+
const key = getItemKey(item);
|
|
80
|
+
map.set(key, item.request.body.raw);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
return map;
|
|
84
|
+
}
|
|
67
85
|
function getItemKey(item) {
|
|
68
86
|
if (isRequest(item)) {
|
|
69
87
|
const method = getRequestMethod(item);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@postman-enricher/core",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.8",
|
|
4
4
|
"description": "Core enrichment logic for Postman Enricher",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"openapi-to-postmanv2": "^5.5.0",
|
|
19
19
|
"yaml": "^2.8.1",
|
|
20
|
-
"@postman-enricher/shared": "^1.2.
|
|
20
|
+
"@postman-enricher/shared": "^1.2.8"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@anolilab/semantic-release-pnpm": "^3.0.0",
|