@http-forge/core 0.6.11 → 0.6.12
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/README.md +756 -51
- package/dist/index.js +113 -113
- package/dist/index.mjs +108 -108
- package/dist/infrastructure/config/config.interface.d.ts +5 -2
- package/package.json +10 -9
package/README.md
CHANGED
|
@@ -1,82 +1,787 @@
|
|
|
1
1
|
# @http-forge/core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Standalone HTTP testing engine with Postman collection support and JavaScript-based automation.**
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[](https://www.npmjs.com/package/@http-forge/core)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
[](LICENSE)
|
|
8
|
+
## 📦 What is @http-forge/core?
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
`@http-forge/core` is a headless, framework-agnostic HTTP execution engine with **full Postman collection compatibility**. Execute complex API workflows, test suites, and automated flows without the overhead of a UI.
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
12
|
+
**Core Features:**
|
|
13
|
+
- 🚀 **Postman Collections** - Load and execute `.postman_collection.json` and `.forge.json` files
|
|
14
|
+
- 📝 **JavaScript Scripting** - Pre-request and post-response scripts with full `pm.*` API (variables, assertions, execution flow, visualizer)
|
|
15
|
+
- 🔄 **Dynamic Variables** - Built-in generators: `{{$randomInt}}`, `{{$timestamp}}`, `{{$uuid}}`, `{{$guid}}`, etc.
|
|
16
|
+
- 🌍 **Environments** - Full variable scoping (globals, collection, environment, session, iterationData)
|
|
17
|
+
- 👁️ **File Watching** - Automatic reload on collection/environment file changes with notification callbacks
|
|
18
|
+
- 🍪 **Cookie Persistence** - Automatic cookie storage and reuse, `pm.cookies.jar()` and `.toObject()`
|
|
19
|
+
- 📊 **Test Assertions** - BDD-style testing with `pm.test()` (sync/async) and full Chai `expect()` chains
|
|
20
|
+
- 🔐 **CryptoJS** - Full crypto library: hash, HMAC, AES/DES/TripleDES, PBKDF2, encoding helpers
|
|
21
|
+
- 🎯 **Execution Flow** - `pm.setNextRequest()`, `pm.execution.skipRequest()` for suite runner flow control
|
|
22
|
+
- 📈 **Visualizer** - `pm.visualizer.set(template, data)` for custom Handlebars-based HTML output
|
|
23
|
+
- 🔌 **Extensible** - Custom interceptors, HTTP clients, and module loaders
|
|
17
24
|
|
|
18
|
-
|
|
25
|
+
**Ideal for:**
|
|
26
|
+
- CI/CD pipeline integration (GitHub Actions, GitLab CI, Jenkins)
|
|
27
|
+
- Headless API testing and contract validation
|
|
28
|
+
- Building custom API testing CLIs
|
|
29
|
+
- Load testing and performance monitoring
|
|
30
|
+
- Automated integration test suites
|
|
19
31
|
|
|
20
|
-
|
|
21
|
-
- HTTP Forge CLI
|
|
22
|
-
- MCP server runtime
|
|
23
|
-
- OpenAPI import/export and automation flows
|
|
24
|
-
- Custom API testing tools built on top of the engine
|
|
32
|
+
## 🎯 Installation
|
|
25
33
|
|
|
26
|
-
|
|
34
|
+
Requires Node.js `20+`.
|
|
27
35
|
|
|
28
36
|
```bash
|
|
29
37
|
npm install @http-forge/core
|
|
30
38
|
```
|
|
31
39
|
|
|
32
|
-
|
|
40
|
+
Or using the tarball:
|
|
41
|
+
```bash
|
|
42
|
+
npm install ./http-forge-core-0.1.0.tgz
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## ⚡ Quick Start
|
|
46
|
+
|
|
47
|
+
### Basic Usage
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
33
50
|
import { ForgeContainer } from '@http-forge/core';
|
|
34
51
|
|
|
52
|
+
// Create a container with default settings
|
|
35
53
|
const forge = new ForgeContainer();
|
|
54
|
+
|
|
55
|
+
// Load a collection
|
|
36
56
|
const collection = await forge.loadCollection('./my-api.forge.json');
|
|
57
|
+
|
|
58
|
+
// Execute a request
|
|
37
59
|
const result = await forge.execute(collection.items[0], collection);
|
|
38
60
|
|
|
39
|
-
console.log(result.response.status);
|
|
40
|
-
console.log(result.response.body);
|
|
61
|
+
console.log(result.response.status); // 200
|
|
62
|
+
console.log(result.response.body); // Response data
|
|
63
|
+
console.log(result.postResponseResult?.assertions); // Test results
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### With Environment Variables
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
const forge = new ForgeContainer();
|
|
70
|
+
|
|
71
|
+
// Set environment variables
|
|
72
|
+
forge.setEnvironment({
|
|
73
|
+
baseUrl: 'https://api.example.com',
|
|
74
|
+
apiKey: 'your-api-key',
|
|
75
|
+
timeout: '5000'
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// Variables are automatically interpolated in requests
|
|
79
|
+
// URL: {{baseUrl}}/users -> https://api.example.com/users
|
|
80
|
+
const result = await forge.execute(request, collection);
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### With Custom Configuration
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
const forge = new ForgeContainer({
|
|
87
|
+
// Use native Node.js http/https instead of fetch
|
|
88
|
+
useNativeHttp: true,
|
|
89
|
+
|
|
90
|
+
// Enable automatic cookie management
|
|
91
|
+
enableCookies: true,
|
|
92
|
+
|
|
93
|
+
// Set request timeout
|
|
94
|
+
requestTimeout: 10000,
|
|
95
|
+
|
|
96
|
+
// Enable request history
|
|
97
|
+
enableHistory: true,
|
|
98
|
+
maxHistoryEntries: 50,
|
|
99
|
+
|
|
100
|
+
// Storage format
|
|
101
|
+
storageFormat: 'folder' // or 'file'
|
|
102
|
+
});
|
|
41
103
|
```
|
|
42
104
|
|
|
43
|
-
## Core
|
|
105
|
+
## 📚 Core Concepts
|
|
106
|
+
|
|
107
|
+
### ForgeContainer
|
|
108
|
+
|
|
109
|
+
The main entry point - a dependency injection container that wires up all components.
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
const forge = new ForgeContainer(options);
|
|
113
|
+
|
|
114
|
+
// Load collections
|
|
115
|
+
const collection = await forge.loadCollection(path);
|
|
116
|
+
const folderCollection = await forge.loadFolderCollection(path);
|
|
117
|
+
|
|
118
|
+
// Execute requests
|
|
119
|
+
const result = await forge.execute(request, collection, options);
|
|
120
|
+
|
|
121
|
+
// Manage environments
|
|
122
|
+
forge.setEnvironment(variables);
|
|
123
|
+
forge.setActiveEnvironment(name);
|
|
124
|
+
const resolved = forge.getResolvedEnvironment();
|
|
125
|
+
|
|
126
|
+
// Access services
|
|
127
|
+
const executor = forge.getRequestExecutor();
|
|
128
|
+
const loader = forge.getCollectionLoader();
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Request Execution
|
|
132
|
+
|
|
133
|
+
Execute requests with full control over the execution pipeline:
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
const result = await forge.execute(request, collection, {
|
|
137
|
+
environment: 'production',
|
|
138
|
+
overrides: {
|
|
139
|
+
url: 'https://override.com/api',
|
|
140
|
+
headers: { 'X-Custom': 'value' }
|
|
141
|
+
},
|
|
142
|
+
skipPreRequest: false,
|
|
143
|
+
skipPostResponse: false,
|
|
144
|
+
timeout: 5000
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
// Access results
|
|
148
|
+
console.log(result.response); // HTTP response
|
|
149
|
+
console.log(result.preRequestResult); // Pre-request script output
|
|
150
|
+
console.log(result.postResponseResult); // Test results
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Dynamic Variables
|
|
154
|
+
|
|
155
|
+
Automatic variable generation within request templates:
|
|
156
|
+
|
|
157
|
+
```javascript
|
|
158
|
+
// URL with dynamic timestamp
|
|
159
|
+
https://api.example.com/events?timestamp={{$timestamp}}
|
|
160
|
+
|
|
161
|
+
// Headers with unique ID
|
|
162
|
+
X-Request-ID: {{$uuid}}
|
|
163
|
+
|
|
164
|
+
// Query parameters with random value
|
|
165
|
+
?page=1&seed={{$randomInt:1:100}}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
**Supported dynamic variables:**
|
|
169
|
+
- `{{$randomInt}}` - Random integer (0-2147483647)
|
|
170
|
+
- `{{$randomInt:min:max}}` - Random integer in range
|
|
171
|
+
- `{{$timestamp}}` - Current Unix timestamp (seconds)
|
|
172
|
+
- `{{$uuid}}` - UUID v4
|
|
173
|
+
- `{{$guid}}` - GUID (alias for uuid)
|
|
174
|
+
- `{{$randomString}}` - 10-char alphanumeric string
|
|
175
|
+
- `{{$randomHexadecimal}}` - Random hex string
|
|
176
|
+
- `{{$isoTimestamp}}` - ISO 8601 timestamp
|
|
177
|
+
|
|
178
|
+
### Script Execution
|
|
179
|
+
|
|
180
|
+
Run pre-request and post-response scripts with full Postman API compatibility:
|
|
181
|
+
|
|
182
|
+
**Pre-request script - Set variables & modify request:**
|
|
183
|
+
```javascript
|
|
184
|
+
// Set variables across scopes
|
|
185
|
+
pm.variables.set('requestId', pm.variables.randomUUID());
|
|
186
|
+
pm.environment.set('token', 'abc-123');
|
|
187
|
+
pm.collectionVariables.set('counter', '1');
|
|
188
|
+
|
|
189
|
+
// Modify request headers
|
|
190
|
+
pm.request.headers.add({
|
|
191
|
+
name: 'X-Request-ID',
|
|
192
|
+
value: pm.variables.get('requestId')
|
|
193
|
+
});
|
|
194
|
+
pm.request.headers.update({
|
|
195
|
+
name: 'Authorization',
|
|
196
|
+
value: 'Bearer ' + pm.environment.get('token')
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
// Modify URL and body
|
|
200
|
+
pm.request.url = 'https://api.example.com' + pm.request.url;
|
|
201
|
+
pm.request.body.raw = JSON.stringify({ timestamp: Date.now() });
|
|
202
|
+
|
|
203
|
+
// Set cookies for next request
|
|
204
|
+
pm.cookies.set('sessionId', 'sess_abc123');
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
**Post-response script - Test & extract data:**
|
|
208
|
+
```javascript
|
|
209
|
+
// Run assertions
|
|
210
|
+
pm.test('Status is 200', () => {
|
|
211
|
+
pm.expect(pm.response.code).to.equal(200);
|
|
212
|
+
});
|
|
213
|
+
pm.test('Response time under 1s', () => {
|
|
214
|
+
pm.expect(pm.response.responseTime).to.be.below(1000);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
// Extract data for next request
|
|
218
|
+
const data = pm.response.json();
|
|
219
|
+
pm.environment.set('userId', data.id);
|
|
220
|
+
pm.environment.set('authToken', data.token);
|
|
221
|
+
|
|
222
|
+
// Store non-string values (auto-serialized with type safety)
|
|
223
|
+
pm.environment.set('userList', data.users); // Array → stored with type marker
|
|
224
|
+
pm.environment.set('config', { retries: 3 }); // Object → stored with type marker
|
|
225
|
+
pm.environment.set('count', 42); // Number → stored with type marker
|
|
226
|
+
|
|
227
|
+
// get() auto-deserializes back to the original type
|
|
228
|
+
const users = pm.environment.get('userList'); // → Array
|
|
229
|
+
const config = pm.environment.get('config'); // → Object
|
|
230
|
+
const count = pm.environment.get('count'); // → 42 (number)
|
|
231
|
+
|
|
232
|
+
// Strings are never misinterpreted — "true" stays a string, true stays a boolean
|
|
233
|
+
pm.environment.set('flag', true); // boolean
|
|
234
|
+
pm.environment.set('label', 'true'); // string
|
|
235
|
+
pm.environment.get('flag'); // → true (boolean)
|
|
236
|
+
pm.environment.get('label'); // → "true" (string)
|
|
237
|
+
|
|
238
|
+
// Store cookies from response
|
|
239
|
+
if (pm.response.headers.has('Set-Cookie')) {
|
|
240
|
+
pm.cookies.set('authCookie', data.authCookie);
|
|
241
|
+
}
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
### Environment Management
|
|
245
|
+
|
|
246
|
+
```typescript
|
|
247
|
+
// Define multiple environments
|
|
248
|
+
forge.setEnvironmentConfig({
|
|
249
|
+
dev: { baseUrl: 'https://dev.api.com', apiKey: 'dev-key' },
|
|
250
|
+
staging: { baseUrl: 'https://staging.api.com', apiKey: 'staging-key' },
|
|
251
|
+
prod: { baseUrl: 'https://api.com', apiKey: 'prod-key' }
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
// Switch environments
|
|
255
|
+
forge.setActiveEnvironment('prod');
|
|
256
|
+
|
|
257
|
+
// Get resolved variables (with inheritance and overrides)
|
|
258
|
+
const vars = forge.getResolvedEnvironment('prod');
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
## 🔧 Advanced Features
|
|
262
|
+
|
|
263
|
+
### Custom HTTP Client
|
|
264
|
+
|
|
265
|
+
Implement your own HTTP client:
|
|
266
|
+
|
|
267
|
+
```typescript
|
|
268
|
+
import { IHttpClient, HttpRequest, HttpResponse } from '@http-forge/core';
|
|
269
|
+
|
|
270
|
+
class CustomHttpClient implements IHttpClient {
|
|
271
|
+
async send(request: HttpRequest): Promise<HttpResponse> {
|
|
272
|
+
// Your custom HTTP logic
|
|
273
|
+
return {
|
|
274
|
+
status: 200,
|
|
275
|
+
statusText: 'OK',
|
|
276
|
+
headers: {},
|
|
277
|
+
body: {},
|
|
278
|
+
duration: 100,
|
|
279
|
+
size: 1024
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const forge = new ForgeContainer({
|
|
285
|
+
httpClient: new CustomHttpClient()
|
|
286
|
+
});
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
### Request/Response Interceptors
|
|
290
|
+
|
|
291
|
+
Add custom interceptors to modify requests and responses:
|
|
292
|
+
|
|
293
|
+
```typescript
|
|
294
|
+
import { IRequestInterceptor, IResponseInterceptor } from '@http-forge/core';
|
|
295
|
+
|
|
296
|
+
// Request interceptor
|
|
297
|
+
class AuthInterceptor implements IRequestInterceptor {
|
|
298
|
+
async intercept(request: HttpRequest): Promise<HttpRequest> {
|
|
299
|
+
request.headers['Authorization'] = `Bearer ${getToken()}`;
|
|
300
|
+
return request;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// Response interceptor
|
|
305
|
+
class LoggingInterceptor implements IResponseInterceptor {
|
|
306
|
+
async intercept(response: HttpResponse, request: HttpRequest): Promise<HttpResponse> {
|
|
307
|
+
console.log(`${request.method} ${request.url} -> ${response.status}`);
|
|
308
|
+
return response;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
const forge = new ForgeContainer({
|
|
313
|
+
requestInterceptors: [new AuthInterceptor()],
|
|
314
|
+
responseInterceptors: [new LoggingInterceptor()]
|
|
315
|
+
});
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
### Cookie Management & Persistence
|
|
319
|
+
|
|
320
|
+
Automatic cookie storage and reuse across multi-request flows:
|
|
321
|
+
|
|
322
|
+
```typescript
|
|
323
|
+
const forge = new ForgeContainer({
|
|
324
|
+
enableCookies: true // Cookies persist across requests in session
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
// Login - response sets Session-ID cookie
|
|
328
|
+
const loginResult = await forge.execute(loginRequest, collection);
|
|
329
|
+
|
|
330
|
+
// Subsequent requests automatically include Session-ID
|
|
331
|
+
// No need to manually extract and re-add cookies
|
|
332
|
+
const dataResult = await forge.execute(dataRequest, collection);
|
|
333
|
+
const updateResult = await forge.execute(updateRequest, collection);
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
**Access cookies in scripts:**
|
|
337
|
+
```javascript
|
|
338
|
+
// Pre-request script - read stored cookies
|
|
339
|
+
if (pm.cookies.has('sessionId')) {
|
|
340
|
+
const sid = pm.cookies.get('sessionId');
|
|
341
|
+
pm.request.headers.add({
|
|
342
|
+
name: 'Cookie',
|
|
343
|
+
value: 'sessionId=' + sid
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// Post-response script - store new cookies
|
|
348
|
+
pm.response.cookies.forEach(cookie => {
|
|
349
|
+
pm.cookies.set(cookie.name, cookie.value);
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
// List all active cookies
|
|
353
|
+
const allCookies = pm.cookies.list(); // [{name, value}, ...]
|
|
354
|
+
|
|
355
|
+
// Clear cookies
|
|
356
|
+
pm.cookies.clear(); // When switching users/sessions
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
Cookies are automatically extracted from `Set-Cookie` response headers and reused in subsequent `Cookie` request headers.
|
|
360
|
+
|
|
361
|
+
### Request History
|
|
362
|
+
|
|
363
|
+
Track all executed requests:
|
|
364
|
+
|
|
365
|
+
```typescript
|
|
366
|
+
const forge = new ForgeContainer({
|
|
367
|
+
enableHistory: true,
|
|
368
|
+
maxHistoryEntries: 100
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
// Execute requests
|
|
372
|
+
await forge.execute(request1, collection);
|
|
373
|
+
await forge.execute(request2, collection);
|
|
374
|
+
|
|
375
|
+
// Access history
|
|
376
|
+
const history = forge.getRequestHistory();
|
|
377
|
+
const entries = history.getAll(); // All requests
|
|
378
|
+
const byId = history.getByRequestId(id); // Specific request history
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
## 📖 API Reference
|
|
382
|
+
|
|
383
|
+
### ForgeContainer
|
|
384
|
+
|
|
385
|
+
**Constructor Options:**
|
|
386
|
+
```typescript
|
|
387
|
+
interface ForgeContainerOptions {
|
|
388
|
+
forgeRoot?: string; // Path to http-forge folder
|
|
389
|
+
storageFormat?: 'file' | 'folder'; // Collection storage format
|
|
390
|
+
|
|
391
|
+
// HTTP Settings
|
|
392
|
+
useNativeHttp?: boolean; // Use native http/https
|
|
393
|
+
httpClient?: IHttpClient; // Custom HTTP client
|
|
394
|
+
httpSettings?: RequestSettings; // Default HTTP settings
|
|
395
|
+
requestTimeout?: number; // Request timeout (ms)
|
|
396
|
+
|
|
397
|
+
// Cookie Settings
|
|
398
|
+
enableCookies?: boolean; // Enable cookie jar
|
|
399
|
+
cookieJar?: ICookieJar; // Custom cookie jar
|
|
400
|
+
|
|
401
|
+
// Interceptors
|
|
402
|
+
requestInterceptors?: IRequestInterceptor[];
|
|
403
|
+
responseInterceptors?: IResponseInterceptor[];
|
|
404
|
+
errorInterceptors?: IErrorInterceptor[];
|
|
405
|
+
|
|
406
|
+
// Script Settings
|
|
407
|
+
scriptRunner?: IScriptRunner; // Custom script runner
|
|
408
|
+
scriptTimeout?: number; // Script timeout (ms)
|
|
409
|
+
|
|
410
|
+
// History
|
|
411
|
+
enableHistory?: boolean; // Enable request history
|
|
412
|
+
maxHistoryEntries?: number; // Max history size
|
|
413
|
+
|
|
414
|
+
// File Watching
|
|
415
|
+
fileWatcherFactory?: IFileWatcherFactory; // Watch for collection/environment file changes
|
|
416
|
+
}
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
**Methods:**
|
|
420
|
+
```typescript
|
|
421
|
+
// Collection loading
|
|
422
|
+
loadCollection(path: string): Promise<UnifiedCollection>
|
|
423
|
+
loadFolderCollection(path: string): Promise<UnifiedCollection>
|
|
424
|
+
|
|
425
|
+
// Request execution
|
|
426
|
+
execute(
|
|
427
|
+
request: UnifiedRequest,
|
|
428
|
+
collection: UnifiedCollection,
|
|
429
|
+
options?: ExecuteOptions
|
|
430
|
+
): Promise<ExecuteResult>
|
|
431
|
+
|
|
432
|
+
// Environment management
|
|
433
|
+
setEnvironment(variables: Record<string, string>): void
|
|
434
|
+
setEnvironmentConfig(config: EnvironmentConfig): void
|
|
435
|
+
setActiveEnvironment(name: string): void
|
|
436
|
+
getResolvedEnvironment(name?: string): Record<string, string>
|
|
437
|
+
|
|
438
|
+
// Service access
|
|
439
|
+
getRequestExecutor(): RequestExecutor
|
|
440
|
+
getCollectionLoader(): ICollectionLoader
|
|
441
|
+
getEnvironmentResolver(): EnvironmentResolver
|
|
442
|
+
getRequestHistory(): IRequestHistory
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
### ExecuteResult
|
|
446
|
+
|
|
447
|
+
```typescript
|
|
448
|
+
interface ExecuteResult {
|
|
449
|
+
response: HttpResponse; // HTTP response
|
|
450
|
+
preRequestResult?: ScriptResult; // Pre-request script output
|
|
451
|
+
postResponseResult?: ScriptResult; // Test results
|
|
452
|
+
requestId: string; // Unique request ID
|
|
453
|
+
timestamp: number; // Execution timestamp
|
|
454
|
+
}
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
### HttpResponse
|
|
458
|
+
|
|
459
|
+
```typescript
|
|
460
|
+
interface HttpResponse {
|
|
461
|
+
status: number; // HTTP status code
|
|
462
|
+
statusText: string; // Status text
|
|
463
|
+
headers: Record<string, string>; // Response headers
|
|
464
|
+
body: any; // Parsed response body
|
|
465
|
+
cookies?: Cookie[]; // Response cookies
|
|
466
|
+
duration: number; // Request duration (ms)
|
|
467
|
+
size: number; // Response size (bytes)
|
|
468
|
+
redirected?: boolean; // Whether redirected
|
|
469
|
+
}
|
|
470
|
+
```
|
|
471
|
+
|
|
472
|
+
### KeyValueEntry
|
|
473
|
+
|
|
474
|
+
Used for headers and query parameters in `CollectionRequest`. Supports OpenAPI metadata for generation and validation.
|
|
475
|
+
|
|
476
|
+
```typescript
|
|
477
|
+
interface KeyValueEntry {
|
|
478
|
+
key: string;
|
|
479
|
+
value: string;
|
|
480
|
+
enabled?: boolean;
|
|
481
|
+
// OpenAPI metadata (all optional, backward-compatible)
|
|
482
|
+
type?: 'string' | 'integer' | 'number' | 'boolean' | 'array';
|
|
483
|
+
required?: boolean;
|
|
484
|
+
description?: string;
|
|
485
|
+
format?: string; // Semantic hint (e.g. "uuid", "date-time")
|
|
486
|
+
enum?: string[]; // Allowed values
|
|
487
|
+
deprecated?: boolean;
|
|
488
|
+
// Extended constraint fields for full OpenAPI round-trip
|
|
489
|
+
pattern?: string; // Regex validation pattern
|
|
490
|
+
minimum?: number;
|
|
491
|
+
maximum?: number;
|
|
492
|
+
exclusiveMinimum?: number;
|
|
493
|
+
exclusiveMaximum?: number;
|
|
494
|
+
minLength?: number;
|
|
495
|
+
maxLength?: number;
|
|
496
|
+
oneOf?: Array<Record<string, any>>; // Merged constraint variants
|
|
497
|
+
}
|
|
498
|
+
```
|
|
499
|
+
|
|
500
|
+
### PathParamEntry
|
|
501
|
+
|
|
502
|
+
Used for path parameters (`:param` in URLs). Same constraint fields as `KeyValueEntry` minus `key`/`enabled`.
|
|
503
|
+
|
|
504
|
+
```typescript
|
|
505
|
+
interface PathParamEntry {
|
|
506
|
+
value: string;
|
|
507
|
+
type?: 'string' | 'integer' | 'number' | 'boolean';
|
|
508
|
+
description?: string;
|
|
509
|
+
format?: string;
|
|
510
|
+
enum?: string[];
|
|
511
|
+
deprecated?: boolean;
|
|
512
|
+
pattern?: string;
|
|
513
|
+
minimum?: number;
|
|
514
|
+
maximum?: number;
|
|
515
|
+
exclusiveMinimum?: number;
|
|
516
|
+
exclusiveMaximum?: number;
|
|
517
|
+
minLength?: number;
|
|
518
|
+
maxLength?: number;
|
|
519
|
+
oneOf?: Array<Record<string, any>>;
|
|
520
|
+
}
|
|
521
|
+
```
|
|
522
|
+
|
|
523
|
+
### OpenAPI Import / Export
|
|
524
|
+
|
|
525
|
+
The core library includes full OpenAPI 3.0.3 import and export with constraint preservation.
|
|
526
|
+
|
|
527
|
+
**Import** (`OpenApiImporter`):
|
|
528
|
+
- Parses OpenAPI 3.0 YAML/JSON specs into `UnifiedCollection`
|
|
529
|
+
- Extracts all parameter schema constraints (`pattern`, `minimum`, `maximum`, `exclusiveMinimum`, `exclusiveMaximum`, `minLength`, `maxLength`, `enum`, `format`)
|
|
530
|
+
- Preserves `oneOf` schemas from merged parameters, deriving combined enum hints for UI display
|
|
531
|
+
|
|
532
|
+
**Export** (`OpenApiExporter`):
|
|
533
|
+
- Generates OpenAPI 3.0.3 specs from collections
|
|
534
|
+
- **Collision-aware merging**: When multiple requests normalize to the same path + HTTP method, they are merged into a single operation:
|
|
535
|
+
- Descriptions are appended, tags are unioned
|
|
536
|
+
- Parameters with the **same constraint kind** (both enum, both pattern, etc.) are merged in-place (union enum values, widen numeric ranges, alternation-join patterns)
|
|
537
|
+
- Parameters with **different constraint kinds** are wrapped in `oneOf` — each variant keeps its self-consistent schema
|
|
538
|
+
- All constraint fields round-trip without data loss
|
|
539
|
+
|
|
540
|
+
## 🛠️ Use Cases
|
|
541
|
+
|
|
542
|
+
### CLI Tool
|
|
543
|
+
|
|
544
|
+
```typescript
|
|
545
|
+
#!/usr/bin/env node
|
|
546
|
+
import { ForgeContainer } from '@http-forge/core';
|
|
547
|
+
|
|
548
|
+
async function runTests(collectionPath: string) {
|
|
549
|
+
const forge = new ForgeContainer();
|
|
550
|
+
const collection = await forge.loadCollection(collectionPath);
|
|
551
|
+
|
|
552
|
+
for (const request of collection.items) {
|
|
553
|
+
const result = await forge.execute(request, collection);
|
|
554
|
+
const tests = result.postResponseResult?.assertions || [];
|
|
555
|
+
|
|
556
|
+
console.log(`\n${request.name}: ${result.response.status}`);
|
|
557
|
+
tests.forEach(test => {
|
|
558
|
+
console.log(` ${test.passed ? '✓' : '✗'} ${test.name}`);
|
|
559
|
+
});
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
runTests(process.argv[2]);
|
|
564
|
+
```
|
|
565
|
+
|
|
566
|
+
### CI/CD Integration
|
|
567
|
+
|
|
568
|
+
```typescript
|
|
569
|
+
import { ForgeContainer } from '@http-forge/core';
|
|
570
|
+
|
|
571
|
+
async function ciTest() {
|
|
572
|
+
const forge = new ForgeContainer({
|
|
573
|
+
enableCookies: true,
|
|
574
|
+
requestTimeout: 30000
|
|
575
|
+
});
|
|
576
|
+
|
|
577
|
+
forge.setEnvironment({
|
|
578
|
+
baseUrl: process.env.API_URL,
|
|
579
|
+
apiKey: process.env.API_KEY
|
|
580
|
+
});
|
|
581
|
+
|
|
582
|
+
const collection = await forge.loadCollection('./api-tests.forge.json');
|
|
583
|
+
|
|
584
|
+
let failedTests = 0;
|
|
585
|
+
for (const request of collection.items) {
|
|
586
|
+
const result = await forge.execute(request, collection);
|
|
587
|
+
const failed = result.postResponseResult?.assertions?.filter(t => !t.passed) || [];
|
|
588
|
+
failedTests += failed.length;
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
process.exit(failedTests > 0 ? 1 : 0);
|
|
592
|
+
}
|
|
593
|
+
```
|
|
594
|
+
|
|
595
|
+
### Custom Testing Framework
|
|
596
|
+
|
|
597
|
+
```typescript
|
|
598
|
+
import { ForgeContainer } from '@http-forge/core';
|
|
599
|
+
|
|
600
|
+
class ApiTestRunner {
|
|
601
|
+
private forge: ForgeContainer;
|
|
602
|
+
|
|
603
|
+
constructor() {
|
|
604
|
+
this.forge = new ForgeContainer({
|
|
605
|
+
enableCookies: true,
|
|
606
|
+
enableHistory: true
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
async runSuite(suites: TestSuite[]) {
|
|
611
|
+
for (const suite of suites) {
|
|
612
|
+
await this.runTests(suite);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
async runTests(suite: TestSuite) {
|
|
617
|
+
const collection = await this.forge.loadCollection(suite.collection);
|
|
618
|
+
|
|
619
|
+
for (const request of collection.items) {
|
|
620
|
+
const result = await this.forge.execute(request, collection);
|
|
621
|
+
suite.results.push(result);
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
```
|
|
626
|
+
|
|
627
|
+
### Multi-Request Workflows
|
|
628
|
+
|
|
629
|
+
Execute dependent request chains with automatic cookie and variable management:
|
|
630
|
+
|
|
631
|
+
```typescript
|
|
632
|
+
import { ForgeContainer } from '@http-forge/core';
|
|
633
|
+
|
|
634
|
+
async function apiAuthWorkflow() {
|
|
635
|
+
const forge = new ForgeContainer({
|
|
636
|
+
enableCookies: true, // Cookies persist across requests
|
|
637
|
+
enableHistory: true
|
|
638
|
+
});
|
|
639
|
+
|
|
640
|
+
// Request 1: Login (sets session cookie)
|
|
641
|
+
const loginReq = {
|
|
642
|
+
name: 'Login',
|
|
643
|
+
method: 'POST',
|
|
644
|
+
url: 'https://api.example.com/auth/login',
|
|
645
|
+
body: { type: 'raw', content: JSON.stringify({
|
|
646
|
+
username: '{{email}}',
|
|
647
|
+
password: '{{password}}'
|
|
648
|
+
})},
|
|
649
|
+
scripts: {
|
|
650
|
+
postResponse: `
|
|
651
|
+
const { token, userId } = pm.response.json();
|
|
652
|
+
pm.environment.set('authToken', token);
|
|
653
|
+
pm.environment.set('userId', userId);
|
|
654
|
+
`
|
|
655
|
+
}
|
|
656
|
+
};
|
|
657
|
+
|
|
658
|
+
const loginResult = await forge.execute(loginReq, collection);
|
|
659
|
+
console.log('✓ Logged in, token:', forge.getResolvedEnvironment()['authToken']);
|
|
660
|
+
|
|
661
|
+
// Request 2: Fetch user profile (uses session cookie automatically)
|
|
662
|
+
const profileReq = {
|
|
663
|
+
name: 'Get Profile',
|
|
664
|
+
method: 'GET',
|
|
665
|
+
url: 'https://api.example.com/users/{{userId}}',
|
|
666
|
+
headers: {
|
|
667
|
+
'Authorization': 'Bearer {{authToken}}' // Uses token from login
|
|
668
|
+
}
|
|
669
|
+
};
|
|
670
|
+
|
|
671
|
+
const profileResult = await forge.execute(profileReq, collection);
|
|
672
|
+
console.log('✓ Profile:', profileResult.response.body);
|
|
673
|
+
|
|
674
|
+
// Request 3: Update profile (session cookie still active)
|
|
675
|
+
const updateReq = {
|
|
676
|
+
name: 'Update Profile',
|
|
677
|
+
method: 'PATCH',
|
|
678
|
+
url: 'https://api.example.com/users/{{userId}}',
|
|
679
|
+
headers: {
|
|
680
|
+
'Authorization': 'Bearer {{authToken}}'
|
|
681
|
+
},
|
|
682
|
+
body: { type: 'raw', content: JSON.stringify({ status: 'active' })}
|
|
683
|
+
};
|
|
684
|
+
|
|
685
|
+
const updateResult = await forge.execute(updateReq, collection);
|
|
686
|
+
console.log('✓ Updated profile');
|
|
687
|
+
|
|
688
|
+
// Session automatically logged out - cookies cleared
|
|
689
|
+
forge.getRequestHistory().clear();
|
|
690
|
+
}
|
|
691
|
+
```
|
|
692
|
+
|
|
693
|
+
## 📦 Storage Formats
|
|
694
|
+
|
|
695
|
+
### File Format (Single JSON)
|
|
696
|
+
```
|
|
697
|
+
my-api.forge.json
|
|
698
|
+
```
|
|
699
|
+
|
|
700
|
+
### Folder Format (Directory Structure)
|
|
701
|
+
```
|
|
702
|
+
my-api/
|
|
703
|
+
collection.json
|
|
704
|
+
requests/
|
|
705
|
+
login/
|
|
706
|
+
request.json
|
|
707
|
+
doc.md # Optional request documentation (Markdown)
|
|
708
|
+
users/
|
|
709
|
+
get-users/
|
|
710
|
+
request.json
|
|
711
|
+
doc.md
|
|
712
|
+
create-user/
|
|
713
|
+
request.json
|
|
714
|
+
```
|
|
715
|
+
|
|
716
|
+
## 🤝 Contributing
|
|
717
|
+
|
|
718
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
719
|
+
|
|
720
|
+
## 📄 License
|
|
721
|
+
|
|
722
|
+
MIT © Henry Huang
|
|
723
|
+
|
|
724
|
+
## 🔗 Links
|
|
725
|
+
|
|
726
|
+
- [HTTP Forge Extension](https://marketplace.visualstudio.com/items?itemName=your-publisher.http-forge)
|
|
727
|
+
- [GitHub Repository](https://github.com/hsl1230/http-forge)
|
|
728
|
+
- [Issues](https://github.com/hsl1230/http-forge/issues)
|
|
729
|
+
|
|
730
|
+
## 📝 Changelog
|
|
731
|
+
|
|
732
|
+
### 0.2.16 (Duplicate Collection & Folder)
|
|
44
733
|
|
|
45
|
-
-
|
|
46
|
-
-
|
|
47
|
-
-
|
|
48
|
-
- Cookie persistence and execution flow control
|
|
49
|
-
- Secret resolution from AWS, Azure, Google Cloud, Vault, 1Password, and Doppler
|
|
50
|
-
- AI and MCP runtime integration
|
|
51
|
-
- Headless execution for CI/CD and custom runners
|
|
734
|
+
- ✅ **`duplicateCollection(sourceId, newName)`** — Duplicates a collection including all nested folders, requests, scripts, and schemas
|
|
735
|
+
- ✅ **`duplicateFolder(collectionId, folderId, newName)`** — Duplicates a folder within a collection, preserving all nested request content
|
|
736
|
+
- ✅ **`getItemPath(collectionId, itemId)`** — Resolves the disk path of a folder or request within a collection
|
|
52
737
|
|
|
53
|
-
|
|
738
|
+
### 0.2.5 (OpenAPI Constraint Round-Trip & Collision Merging)
|
|
54
739
|
|
|
55
|
-
- `
|
|
56
|
-
- `
|
|
57
|
-
- `
|
|
58
|
-
- `
|
|
59
|
-
- `createMcpRuntime(options)`
|
|
60
|
-
- `parseCurlCommand()`
|
|
61
|
-
- `enhanceCollection()`
|
|
62
|
-
- `detectEnvSuggestions()`
|
|
740
|
+
- ✅ **Full parameter constraint round-trip** — OpenAPI import/export now preserves all schema constraint fields: `pattern`, `minimum`, `maximum`, `exclusiveMinimum`, `exclusiveMaximum`, `minLength`, `maxLength`, and `oneOf` on both `KeyValueEntry` and `PathParamEntry`
|
|
741
|
+
- ✅ **Collision-aware OpenAPI export** — When multiple requests normalize to the same path + HTTP method, the exporter merges them into a single operation with intelligent parameter schema merging (same-kind merge in-place, different-kind wraps in `oneOf`)
|
|
742
|
+
- ✅ **`oneOf` import with UI hints** — `applyOneOfHints()` derives combined enum arrays and type hints from `oneOf` variants for downstream UI rendering (combobox vs strict dropdown)
|
|
743
|
+
- ✅ **`format` vs `pattern` separation** — `format` is a semantic hint (e.g. `"uuid"`), `pattern` is an enforced regex. Both stored and round-tripped independently
|
|
63
744
|
|
|
64
|
-
|
|
745
|
+
### 0.2.4 (File Watching & Request Documentation)
|
|
65
746
|
|
|
66
|
-
-
|
|
67
|
-
-
|
|
68
|
-
-
|
|
69
|
-
-
|
|
70
|
-
-
|
|
747
|
+
- ✅ **File watching for CollectionService** - Automatic reload and `onCollectionsChanged` callback when collection files change on disk
|
|
748
|
+
- ✅ **File watching for EnvironmentConfigService** - Automatic reload and `onEnvironmentsChanged` callback when environment JSON files change on disk
|
|
749
|
+
- ✅ **Request documentation (`doc.md`)** - Persist per-request Markdown documentation as `doc.md` alongside `request.json`
|
|
750
|
+
- ✅ **`doc` field on UnifiedRequest / CollectionRequest** - Optional `doc?: string` field for request documentation content
|
|
751
|
+
- ✅ **`fileWatcherFactory` bootstrap option** - Pass `IFileWatcherFactory` to enable file watching in both collection and environment services
|
|
71
752
|
|
|
72
|
-
|
|
753
|
+
### 0.2.0 (Postman API Parity)
|
|
73
754
|
|
|
74
|
-
-
|
|
75
|
-
-
|
|
76
|
-
-
|
|
77
|
-
-
|
|
78
|
-
-
|
|
755
|
+
- ✅ **Async `pm.test()` support** - Tests with async callbacks are properly awaited
|
|
756
|
+
- ✅ **Expect chain assertions** - `.a(type)`, `.an(type)`, `.deep.equal()`, `.lengthOf()`, `.exist`, `.members()`, `.keys()`, `.string()`
|
|
757
|
+
- ✅ **`pm.iterationData`** scope - Data-driven testing with iteration variables
|
|
758
|
+
- ✅ **Response status getters** - `response.to.be.ok`, `.error`, `.clientError`, `.serverError` work as getters and functions
|
|
759
|
+
- ✅ **Response headers HeaderList** - `.get()`, `.has()`, `.toObject()`, `.each()` on `pm.response.headers`
|
|
760
|
+
- ✅ **`pm.cookies.toObject()`** - Flat `{name: value}` cookie map
|
|
761
|
+
- ✅ **`replaceIn()` on all scopes** - Available on `pm.variables`, `pm.environment`, `pm.collectionVariables`, `pm.globals`
|
|
762
|
+
- ✅ **Sandbox globals** - `xml2Json()`, `jsonStringify()`, `jsonParse()` available in scripts
|
|
763
|
+
- ✅ **Request headers API** - `.toObject()`, `.each()` on `pm.request.headers`
|
|
764
|
+
- ✅ **`pm.execution.setNextRequest()`** - Runner flow control (jump to named request or stop with `null`)
|
|
765
|
+
- ✅ **`pm.execution.skipRequest()`** - Skip HTTP call from pre-request scripts
|
|
766
|
+
- ✅ **`pm.setNextRequest()`** - Top-level alias for flow control
|
|
767
|
+
- ✅ **`pm.visualizer.set(template, data)`** - Custom HTML visualization with Handlebars templates
|
|
768
|
+
- ✅ **`pm.request.url` as Url object** - Postman SDK-compatible Url with `getHost()`, `getPath()`, `getQueryString()`, `protocol`, `host`, `port`, `path`, `query`, `hash`
|
|
769
|
+
- ✅ **Full CryptoJS** - AES/DES/TripleDES encrypt/decrypt, PBKDF2, all hash algorithms (SHA1/256/384/512/SHA3/MD5/RIPEMD160), HMAC, encoding helpers (Hex/Base64/Utf8/Latin1/Utf16)
|
|
79
770
|
|
|
80
|
-
|
|
771
|
+
### 0.1.0 (Initial Release)
|
|
81
772
|
|
|
82
|
-
|
|
773
|
+
- ✅ **Core request execution** with Postman collection support
|
|
774
|
+
- ✅ **Dynamic variables** - 7 generators for on-the-fly value generation
|
|
775
|
+
- ✅ **Postman-compatible scripting** - `pm.*` API with full feature parity
|
|
776
|
+
- ✅ **Variable scoping** - globals, collection, environment, session, flow-level
|
|
777
|
+
- ✅ **Cookie persistence** - automatic storage and reuse across request chains
|
|
778
|
+
- ✅ **Pre-request & post-response scripts** with shared VM context
|
|
779
|
+
- ✅ **Test assertions** with BDD-style `pm.test()` and expect chains
|
|
780
|
+
- ✅ **Environment management** with variable substitution
|
|
781
|
+
- ✅ **Cookie jar** with domain-aware matching
|
|
782
|
+
- ✅ **Request/response interceptors** for customization
|
|
783
|
+
- ✅ **Request history** tracking
|
|
784
|
+
- ✅ **File and folder collection formats** (Postman-compatible)
|
|
785
|
+
- ✅ **Full TypeScript support** with comprehensive types
|
|
786
|
+
- ✅ **Dependency injection** for extensibility
|
|
787
|
+
- ✅ **Comprehensive test coverage**
|