@postman-enricher/core 1.2.6 → 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
- * ID Preservation - Maintains IDs across collection regenerations
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
- * ID Preservation - Maintains IDs across collection regenerations
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';
@@ -10,17 +10,36 @@ 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);
14
+ const requestBodyMap = buildRequestBodyMap(existing);
13
15
  // Restore collection ID
14
16
  if (existing.info?._postman_id) {
15
17
  collection.info._postman_id = existing.info._postman_id;
16
18
  }
17
- // Restore item IDs
19
+ // Restore item IDs, response IDs, and request bodies
18
20
  walkCollection(collection.item, (item) => {
19
21
  const key = getItemKey(item);
20
22
  const existingId = idMap.get(key);
21
23
  if (existingId) {
22
24
  item.id = existingId;
23
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
+ }
33
+ // Restore response IDs
34
+ if (isRequest(item) && item.response) {
35
+ for (const response of item.response) {
36
+ const responseKey = getResponseKey(key, response.name, response.code);
37
+ const existingResponseId = responseIdMap.get(responseKey);
38
+ if (existingResponseId) {
39
+ response.id = existingResponseId;
40
+ }
41
+ }
42
+ }
24
43
  });
25
44
  return collection;
26
45
  }
@@ -38,6 +57,31 @@ function buildIdMap(collection) {
38
57
  });
39
58
  return map;
40
59
  }
60
+ function buildResponseIdMap(collection) {
61
+ const map = new Map();
62
+ walkCollection(collection.item, (item) => {
63
+ if (isRequest(item) && item.response) {
64
+ const itemKey = getItemKey(item);
65
+ for (const response of item.response) {
66
+ if (response.id) {
67
+ const responseKey = getResponseKey(itemKey, response.name, response.code);
68
+ map.set(responseKey, response.id);
69
+ }
70
+ }
71
+ }
72
+ });
73
+ return map;
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
+ }
41
85
  function getItemKey(item) {
42
86
  if (isRequest(item)) {
43
87
  const method = getRequestMethod(item);
@@ -45,3 +89,6 @@ function getItemKey(item) {
45
89
  }
46
90
  return `folder_${item.name}`;
47
91
  }
92
+ function getResponseKey(itemKey, responseName, statusCode) {
93
+ return `${itemKey}_${responseName}_${statusCode}`;
94
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@postman-enricher/core",
3
- "version": "1.2.6",
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.6"
20
+ "@postman-enricher/shared": "^1.2.8"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@anolilab/semantic-release-pnpm": "^3.0.0",