@postman-enricher/core 1.2.7 → 1.2.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.
@@ -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,26 +10,31 @@ 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
+ const responseMap = buildResponseMap(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 response IDs
19
+ // Restore item IDs, response IDs/bodies, 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
  }
25
- // Restore response IDs
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 responses from existing collection
26
34
  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
- }
35
+ const existingResponses = responseMap.get(key);
36
+ if (existingResponses) {
37
+ item.response = existingResponses;
33
38
  }
34
39
  }
35
40
  });
@@ -49,17 +54,22 @@ function buildIdMap(collection) {
49
54
  });
50
55
  return map;
51
56
  }
52
- function buildResponseIdMap(collection) {
57
+ function buildResponseMap(collection) {
53
58
  const map = new Map();
54
59
  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
- }
60
+ if (isRequest(item) && item.response && item.response.length > 0) {
61
+ const key = getItemKey(item);
62
+ map.set(key, item.response);
63
+ }
64
+ });
65
+ return map;
66
+ }
67
+ function buildRequestBodyMap(collection) {
68
+ const map = new Map();
69
+ walkCollection(collection.item, (item) => {
70
+ if (isRequest(item) && item.request?.body?.raw) {
71
+ const key = getItemKey(item);
72
+ map.set(key, item.request.body.raw);
63
73
  }
64
74
  });
65
75
  return map;
@@ -71,6 +81,3 @@ function getItemKey(item) {
71
81
  }
72
82
  return `folder_${item.name}`;
73
83
  }
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.7",
3
+ "version": "1.2.9",
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.7"
20
+ "@postman-enricher/shared": "^1.2.9"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@anolilab/semantic-release-pnpm": "^3.0.0",