post-api-sync 0.1.8 → 0.1.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.
- package/package.json +1 -1
- package/src/collection/postman.js +48 -32
package/package.json
CHANGED
|
@@ -14,20 +14,21 @@ function buildPostmanCollection(endpoints, config) {
|
|
|
14
14
|
items = buildTaggedItems(endpoints);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
// IMPORTANT: variable comes BEFORE item in the collection structure
|
|
17
18
|
return {
|
|
18
19
|
info: {
|
|
20
|
+
_postman_id: nanoid(),
|
|
19
21
|
name,
|
|
20
|
-
schema: 'https://schema.getpostman.com/json/collection/v2.1.0/collection.json'
|
|
21
|
-
_postman_id: nanoid()
|
|
22
|
+
schema: 'https://schema.getpostman.com/json/collection/v2.1.0/collection.json'
|
|
22
23
|
},
|
|
23
|
-
item: items,
|
|
24
24
|
variable: [
|
|
25
25
|
{ key: 'baseUrl', value: baseUrl, type: 'string' },
|
|
26
26
|
{ key: 'authToken', value: '', type: 'string' },
|
|
27
27
|
{ key: 'userId', value: '', type: 'string' },
|
|
28
28
|
{ key: 'orderId', value: '', type: 'string' },
|
|
29
29
|
{ key: 'wholesaleCustomerId', value: '', type: 'string' }
|
|
30
|
-
]
|
|
30
|
+
],
|
|
31
|
+
item: items
|
|
31
32
|
};
|
|
32
33
|
}
|
|
33
34
|
|
|
@@ -122,48 +123,63 @@ function buildItem(endpoint) {
|
|
|
122
123
|
if (hasBody) {
|
|
123
124
|
headers.push({ key: 'Content-Type', value: 'application/json', type: 'text' });
|
|
124
125
|
}
|
|
125
|
-
// Add Authorization header for protected endpoints (heuristic: /admin, /me, /user paths)
|
|
126
|
-
|
|
126
|
+
// Add Authorization header for protected endpoints (heuristic: /admin, /me, /user paths or auth/ping)
|
|
127
|
+
const needsAuth = path.includes('/admin') || path.includes('/me') || path.includes('/user') || path.includes('/ping') || endpoint.auth;
|
|
128
|
+
if (needsAuth) {
|
|
127
129
|
headers.push({ key: 'Authorization', value: 'Bearer {{authToken}}', type: 'text' });
|
|
128
130
|
}
|
|
129
131
|
|
|
130
|
-
// Build query string
|
|
132
|
+
// Build query string for raw URL
|
|
131
133
|
let rawUrl = `{{baseUrl}}${path}`;
|
|
132
134
|
const queryString = queryParams
|
|
135
|
+
.filter(q => !q.disabled)
|
|
133
136
|
.map(q => {
|
|
134
|
-
const value = q.example || (q.type === 'number' ? '20' : q.required ?
|
|
137
|
+
const value = q.value || q.example || (q.type === 'number' ? '20' : q.required ? `{{${q.name}}}` : '');
|
|
135
138
|
return `${q.key || q.name}=${value}`;
|
|
136
139
|
})
|
|
137
140
|
.filter(Boolean)
|
|
138
141
|
.join('&');
|
|
139
142
|
if (queryString) rawUrl += '?' + queryString;
|
|
140
143
|
|
|
144
|
+
const url = {
|
|
145
|
+
raw: rawUrl,
|
|
146
|
+
host: ['{{baseUrl}}'],
|
|
147
|
+
path: splitPath(path)
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
// Only include query/variable arrays if they have content
|
|
151
|
+
if (queryParams.length > 0) {
|
|
152
|
+
url.query = queryParams.map((q) => {
|
|
153
|
+
const item = {
|
|
154
|
+
key: q.key || q.name,
|
|
155
|
+
value: q.value || q.example || ''
|
|
156
|
+
};
|
|
157
|
+
if (q.disabled) item.disabled = true;
|
|
158
|
+
return item;
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (pathParams.length > 0) {
|
|
163
|
+
url.variable = pathParams.map((p) => ({ key: p, value: '' }));
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const request = {
|
|
167
|
+
method: endpoint.method,
|
|
168
|
+
header: headers,
|
|
169
|
+
url,
|
|
170
|
+
description: endpoint.description || `${endpoint.method} ${endpoint.path}`
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
if (hasBody) {
|
|
174
|
+
request.body = {
|
|
175
|
+
mode: 'raw',
|
|
176
|
+
raw: JSON.stringify(example || {}, null, 2)
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
141
180
|
return {
|
|
142
181
|
name: endpoint.description || `${endpoint.method} ${endpoint.path}`,
|
|
143
|
-
request
|
|
144
|
-
method: endpoint.method,
|
|
145
|
-
header: headers,
|
|
146
|
-
url: {
|
|
147
|
-
raw: rawUrl,
|
|
148
|
-
host: ['{{baseUrl}}'],
|
|
149
|
-
path: splitPath(path),
|
|
150
|
-
query: queryParams.map((q) => ({
|
|
151
|
-
key: q.key || q.name,
|
|
152
|
-
value: q.example || '',
|
|
153
|
-
disabled: !q.required
|
|
154
|
-
})),
|
|
155
|
-
variable: pathParams.map((p) => ({ key: p, value: '' }))
|
|
156
|
-
},
|
|
157
|
-
body: hasBody
|
|
158
|
-
? {
|
|
159
|
-
mode: 'raw',
|
|
160
|
-
raw: JSON.stringify(example || {}, null, 2),
|
|
161
|
-
options: { raw: { language: 'json' } }
|
|
162
|
-
}
|
|
163
|
-
: undefined,
|
|
164
|
-
description: endpoint.description || ''
|
|
165
|
-
},
|
|
166
|
-
response: []
|
|
182
|
+
request
|
|
167
183
|
};
|
|
168
184
|
}
|
|
169
185
|
|