post-api-sync 0.1.3 → 0.1.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "post-api-sync",
3
- "version": "0.1.3",
3
+ "version": "0.1.8",
4
4
  "description": "Sync Postman and Insomnia collections from API code",
5
5
  "repository": {
6
6
  "type": "git",
@@ -49,4 +49,4 @@
49
49
  "package.json"
50
50
  ],
51
51
  "license": "MIT"
52
- }
52
+ }
@@ -21,7 +21,13 @@ function buildPostmanCollection(endpoints, config) {
21
21
  _postman_id: nanoid()
22
22
  },
23
23
  item: items,
24
- variable: [{ key: 'baseUrl', value: baseUrl }]
24
+ variable: [
25
+ { key: 'baseUrl', value: baseUrl, type: 'string' },
26
+ { key: 'authToken', value: '', type: 'string' },
27
+ { key: 'userId', value: '', type: 'string' },
28
+ { key: 'orderId', value: '', type: 'string' },
29
+ { key: 'wholesaleCustomerId', value: '', type: 'string' }
30
+ ]
25
31
  };
26
32
  }
27
33
 
@@ -57,7 +63,12 @@ function buildFolderItems(endpoints) {
57
63
  }
58
64
 
59
65
  if (!root._folders[moduleName]) {
60
- const folder = { name: moduleName, item: [], _folders: {} };
66
+ const folder = {
67
+ name: moduleName,
68
+ description: `All endpoints from ${endpoint.filePath || 'this module'}`,
69
+ item: [],
70
+ _folders: {}
71
+ };
61
72
  root.item.push(folder);
62
73
  root._folders[moduleName] = folder;
63
74
  }
@@ -106,16 +117,41 @@ function buildItem(endpoint) {
106
117
 
107
118
  const example = hasBody ? exampleFromSchema(bodySchema) : null;
108
119
 
120
+ // Build headers
121
+ const headers = [];
122
+ if (hasBody) {
123
+ headers.push({ key: 'Content-Type', value: 'application/json', type: 'text' });
124
+ }
125
+ // Add Authorization header for protected endpoints (heuristic: /admin, /me, /user paths)
126
+ if (path.includes('/admin') || path.includes('/me') || path.includes('/user') || endpoint.auth) {
127
+ headers.push({ key: 'Authorization', value: 'Bearer {{authToken}}', type: 'text' });
128
+ }
129
+
130
+ // Build query string
131
+ let rawUrl = `{{baseUrl}}${path}`;
132
+ const queryString = queryParams
133
+ .map(q => {
134
+ const value = q.example || (q.type === 'number' ? '20' : q.required ? '{{' + q.name + '}}' : '');
135
+ return `${q.key || q.name}=${value}`;
136
+ })
137
+ .filter(Boolean)
138
+ .join('&');
139
+ if (queryString) rawUrl += '?' + queryString;
140
+
109
141
  return {
110
142
  name: endpoint.description || `${endpoint.method} ${endpoint.path}`,
111
143
  request: {
112
144
  method: endpoint.method,
113
- header: hasBody ? [{ key: 'Content-Type', value: 'application/json' }] : [],
145
+ header: headers,
114
146
  url: {
115
- raw: `{{baseUrl}}${path}`,
147
+ raw: rawUrl,
116
148
  host: ['{{baseUrl}}'],
117
149
  path: splitPath(path),
118
- query: queryParams.map((q) => ({ key: q.name, value: '', disabled: !q.required })),
150
+ query: queryParams.map((q) => ({
151
+ key: q.key || q.name,
152
+ value: q.example || '',
153
+ disabled: !q.required
154
+ })),
119
155
  variable: pathParams.map((p) => ({ key: p, value: '' }))
120
156
  },
121
157
  body: hasBody
@@ -124,7 +160,8 @@ function buildItem(endpoint) {
124
160
  raw: JSON.stringify(example || {}, null, 2),
125
161
  options: { raw: { language: 'json' } }
126
162
  }
127
- : undefined
163
+ : undefined,
164
+ description: endpoint.description || ''
128
165
  },
129
166
  response: []
130
167
  };