post-api-sync 0.1.7 → 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 +77 -24
package/package.json
CHANGED
|
@@ -14,14 +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
|
-
|
|
24
|
-
|
|
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
|
+
],
|
|
31
|
+
item: items
|
|
25
32
|
};
|
|
26
33
|
}
|
|
27
34
|
|
|
@@ -57,7 +64,12 @@ function buildFolderItems(endpoints) {
|
|
|
57
64
|
}
|
|
58
65
|
|
|
59
66
|
if (!root._folders[moduleName]) {
|
|
60
|
-
const folder = {
|
|
67
|
+
const folder = {
|
|
68
|
+
name: moduleName,
|
|
69
|
+
description: `All endpoints from ${endpoint.filePath || 'this module'}`,
|
|
70
|
+
item: [],
|
|
71
|
+
_folders: {}
|
|
72
|
+
};
|
|
61
73
|
root.item.push(folder);
|
|
62
74
|
root._folders[moduleName] = folder;
|
|
63
75
|
}
|
|
@@ -106,27 +118,68 @@ function buildItem(endpoint) {
|
|
|
106
118
|
|
|
107
119
|
const example = hasBody ? exampleFromSchema(bodySchema) : null;
|
|
108
120
|
|
|
121
|
+
// Build headers
|
|
122
|
+
const headers = [];
|
|
123
|
+
if (hasBody) {
|
|
124
|
+
headers.push({ key: 'Content-Type', value: 'application/json', type: 'text' });
|
|
125
|
+
}
|
|
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) {
|
|
129
|
+
headers.push({ key: 'Authorization', value: 'Bearer {{authToken}}', type: 'text' });
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Build query string for raw URL
|
|
133
|
+
let rawUrl = `{{baseUrl}}${path}`;
|
|
134
|
+
const queryString = queryParams
|
|
135
|
+
.filter(q => !q.disabled)
|
|
136
|
+
.map(q => {
|
|
137
|
+
const value = q.value || q.example || (q.type === 'number' ? '20' : q.required ? `{{${q.name}}}` : '');
|
|
138
|
+
return `${q.key || q.name}=${value}`;
|
|
139
|
+
})
|
|
140
|
+
.filter(Boolean)
|
|
141
|
+
.join('&');
|
|
142
|
+
if (queryString) rawUrl += '?' + queryString;
|
|
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
|
+
|
|
109
180
|
return {
|
|
110
181
|
name: endpoint.description || `${endpoint.method} ${endpoint.path}`,
|
|
111
|
-
request
|
|
112
|
-
method: endpoint.method,
|
|
113
|
-
header: hasBody ? [{ key: 'Content-Type', value: 'application/json' }] : [],
|
|
114
|
-
url: {
|
|
115
|
-
raw: `{{baseUrl}}${path}`,
|
|
116
|
-
host: ['{{baseUrl}}'],
|
|
117
|
-
path: splitPath(path),
|
|
118
|
-
query: queryParams.map((q) => ({ key: q.name, value: '', disabled: !q.required })),
|
|
119
|
-
variable: pathParams.map((p) => ({ key: p, value: '' }))
|
|
120
|
-
},
|
|
121
|
-
body: hasBody
|
|
122
|
-
? {
|
|
123
|
-
mode: 'raw',
|
|
124
|
-
raw: JSON.stringify(example || {}, null, 2),
|
|
125
|
-
options: { raw: { language: 'json' } }
|
|
126
|
-
}
|
|
127
|
-
: undefined
|
|
128
|
-
},
|
|
129
|
-
response: []
|
|
182
|
+
request
|
|
130
183
|
};
|
|
131
184
|
}
|
|
132
185
|
|