@postman-enricher/core 1.2.5 → 1.2.7

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.
@@ -10,17 +10,28 @@ export function preserveIds(collection, existingPath) {
10
10
  try {
11
11
  const existing = JSON.parse(readFileSync(existingPath, 'utf8'));
12
12
  const idMap = buildIdMap(existing);
13
+ const responseIdMap = buildResponseIdMap(existing);
13
14
  // Restore collection ID
14
15
  if (existing.info?._postman_id) {
15
16
  collection.info._postman_id = existing.info._postman_id;
16
17
  }
17
- // Restore item IDs
18
+ // Restore item IDs and response IDs
18
19
  walkCollection(collection.item, (item) => {
19
20
  const key = getItemKey(item);
20
21
  const existingId = idMap.get(key);
21
22
  if (existingId) {
22
23
  item.id = existingId;
23
24
  }
25
+ // Restore response IDs
26
+ if (isRequest(item) && item.response) {
27
+ for (const response of item.response) {
28
+ const responseKey = getResponseKey(key, response.name, response.code);
29
+ const existingResponseId = responseIdMap.get(responseKey);
30
+ if (existingResponseId) {
31
+ response.id = existingResponseId;
32
+ }
33
+ }
34
+ }
24
35
  });
25
36
  return collection;
26
37
  }
@@ -38,6 +49,21 @@ function buildIdMap(collection) {
38
49
  });
39
50
  return map;
40
51
  }
52
+ function buildResponseIdMap(collection) {
53
+ const map = new Map();
54
+ walkCollection(collection.item, (item) => {
55
+ if (isRequest(item) && item.response) {
56
+ const itemKey = getItemKey(item);
57
+ for (const response of item.response) {
58
+ if (response.id) {
59
+ const responseKey = getResponseKey(itemKey, response.name, response.code);
60
+ map.set(responseKey, response.id);
61
+ }
62
+ }
63
+ }
64
+ });
65
+ return map;
66
+ }
41
67
  function getItemKey(item) {
42
68
  if (isRequest(item)) {
43
69
  const method = getRequestMethod(item);
@@ -45,3 +71,6 @@ function getItemKey(item) {
45
71
  }
46
72
  return `folder_${item.name}`;
47
73
  }
74
+ function getResponseKey(itemKey, responseName, statusCode) {
75
+ return `${itemKey}_${responseName}_${statusCode}`;
76
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@postman-enricher/core",
3
- "version": "1.2.5",
3
+ "version": "1.2.7",
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.5"
20
+ "@postman-enricher/shared": "^1.2.7"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@anolilab/semantic-release-pnpm": "^3.0.0",