@http-forge/core 0.6.12 → 0.6.16

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 CHANGED
@@ -1,8 +1,19 @@
1
+ <div align="center">
2
+
3
+ <a href="https://marketplace.visualstudio.com/items?itemName=henry-huang.http-forge">
4
+ <img src="https://raw.githubusercontent.com/hsl1230/http-forge/main/resources/http-forge-icon.png" alt="HTTP Forge" width="120"/>
5
+ </a>
6
+
7
+ </div>
8
+
1
9
  # @http-forge/core
2
10
 
3
11
  **Standalone HTTP testing engine with Postman collection support and JavaScript-based automation.**
4
12
 
5
13
  [![npm version](https://img.shields.io/npm/v/@http-forge/core.svg)](https://www.npmjs.com/package/@http-forge/core)
14
+ [![npm downloads](https://img.shields.io/npm/dm/%40http-forge%2Fcore)](https://www.npmjs.com/package/@http-forge/core)
15
+ [![node](https://img.shields.io/node/v/%40http-forge%2Fcore)](https://www.npmjs.com/package/@http-forge/core)
16
+ [![VS Code Marketplace](https://img.shields.io/visual-studio-marketplace/v/henry-huang.http-forge?label=VS%20Code%20Marketplace)](https://marketplace.visualstudio.com/items?itemName=henry-huang.http-forge)
6
17
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
18
 
8
19
  ## 📦 What is @http-forge/core?
@@ -10,17 +21,15 @@
10
21
  `@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
22
 
12
23
  **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
24
+ | Capability | What you get | Typical use case |
25
+ |---|---|---|
26
+ | **Postman-compatible execution** | Run `.postman_collection.json` and `.forge.json` with high `pm.*` API compatibility | Migrate existing Postman suites without rewriting tests |
27
+ | **AI and MCP automation** | Agent-ready MCP runtime and tools for listing, running, and managing API workflows | Copilot/agent integrations and autonomous API operations |
28
+ | **Built-in scripting and assertions** | Pre-request and post-response scripts with `pm.test()` and Chai `expect()` | API contract checks in CI/CD |
29
+ | **Variables and environments** | `{{variables}}` resolution across global, collection, environment, and runtime scopes; dynamic values like `{{$timestamp}}` and `{{$uuid}}` | Multi-environment testing (dev/staging/prod) |
30
+ | **Stateful request flows** | Automatic cookie persistence and flow control with `pm.setNextRequest()` / `pm.execution.skipRequest()` | Auth/login chains and dependent request sequences |
31
+ | **OpenAPI and docs-ready workflows** | Request metadata stays aligned with API contracts and generated artifacts | Spec-driven API lifecycle and governance |
32
+ | **Extensible architecture** | Custom HTTP clients, interceptors, module loaders, and file-watching hooks | Internal platform tooling and custom runners |
24
33
 
25
34
  **Ideal for:**
26
35
  - CI/CD pipeline integration (GitHub Actions, GitLab CI, Jenkins)
@@ -29,17 +38,133 @@
29
38
  - Load testing and performance monitoring
30
39
  - Automated integration test suites
31
40
 
32
- ## 🎯 Installation
41
+ ## 🧭 Quick Navigation
33
42
 
34
- Requires Node.js `20+`.
43
+ - Pick the right entry point: [Start Here](#-start-here)
44
+ - AI/agent integrations: [AI and MCP Features](#-ai-and-mcp-features)
45
+ - First integration run: [Quick Start](#-quick-start)
46
+ - Common setup issues: [Troubleshooting](#-troubleshooting)
47
+ - Install: [Installation](#-installation)
48
+ - Core architecture and execution model: [Core Concepts](#-core-concepts)
49
+ - Advanced customization: [Advanced Features](#-advanced-features)
50
+ - Types and contracts: [API Reference](#-api-reference)
51
+ - End-to-end examples: [Use Cases](#-use-cases)
52
+ - Ecosystem links: [Links](#-links)
53
+
54
+ ## 🚦 Start Here
55
+
56
+ If you installed `@http-forge/core` from npm and do not have source access, this section is the fastest way to get productive.
57
+
58
+ ### 1. 30-Second Path: Pick The Right Entry Point
59
+
60
+ | Goal | Best Entry | Start Here |
61
+ |---|---|---|
62
+ | Visual authoring + debugging | HTTP Forge Extension | https://marketplace.visualstudio.com/items?itemName=henry-huang.http-forge |
63
+ | CI/CD automation + reports | HTTP Forge CLI | https://github.com/hsl1230/http-forge.cli#readme |
64
+ | Custom runtime/framework integration | `@http-forge/core` | Continue in this README |
65
+
66
+ Open-source implementation references:
67
+ - Extension source: https://github.com/hsl1230/http-forge
68
+ - CLI source: https://github.com/hsl1230/http-forge.cli
69
+
70
+ ### 2. Minimal Integration Template
71
+
72
+ Create a file such as `run-core.ts`:
73
+
74
+ ```typescript
75
+ import { ForgeContainer } from '@http-forge/core';
76
+
77
+ async function main() {
78
+ const forge = new ForgeContainer({
79
+ enableCookies: true,
80
+ requestTimeout: 15000,
81
+ });
82
+
83
+ // Load a collection (folder or file format)
84
+ const collection = await forge.loadCollection('./collections/my-api.forge.json');
85
+
86
+ // Optional: inject environment values used by {{variables}}
87
+ forge.setEnvironment({
88
+ baseUrl: 'https://api.example.com',
89
+ apiKey: process.env.API_KEY || ''
90
+ });
91
+
92
+ // Execute first request
93
+ const request = collection.items[0];
94
+ const result = await forge.execute(request, collection);
95
+
96
+ console.log('status:', result.response.status);
97
+ console.log('body:', result.response.body);
98
+ console.log('tests:', result.postResponseResult?.assertions || []);
99
+ }
100
+
101
+ main().catch((err) => {
102
+ console.error(err);
103
+ process.exit(1);
104
+ });
105
+ ```
106
+
107
+ Run it with your preferred TypeScript runtime or compile and execute with Node.
108
+
109
+ ### 3. Production Usage Checklist
110
+
111
+ - Set `requestTimeout` to match your environment/SLA.
112
+ - Enable cookies if your flow includes session-based auth.
113
+ - Feed secrets via environment variables, never hardcoded strings.
114
+ - Exit non-zero when assertions fail in CI pipelines.
115
+ - Keep collections/environments in source control for repeatability.
116
+
117
+ ### 4. Learn Faster From Real Products Built On Core
118
+
119
+ - HTTP Forge extension (UI-first workflow): https://marketplace.visualstudio.com/items?itemName=henry-huang.http-forge
120
+ - HTTP Forge CLI docs (automation workflow): https://github.com/hsl1230/http-forge.cli#readme
121
+
122
+ Both are powered by `@http-forge/core` patterns you can reuse.
123
+
124
+ ### 5. Postman Compatibility Matrix
125
+
126
+ | Capability | Compatibility |
127
+ |---|---|
128
+ | Postman collection import/export flows | Yes |
129
+ | Environment and variable interpolation (`{{var}}`) | Yes |
130
+ | `pm.test()` and assertions | Yes |
131
+ | `pm.variables`, `pm.environment`, `pm.collectionVariables`, `pm.globals` | Yes |
132
+ | `pm.execution.setNextRequest()` / `pm.setNextRequest()` | Yes |
133
+ | Cookie jar and persistence | Yes |
134
+ | Dynamic variables (`{{$timestamp}}`, `{{$uuid}}`, etc.) | Yes |
135
+ | Pre-request and post-response scripting | Yes |
136
+
137
+ ### 6. From Postman To HTTP Forge In 3 Steps
35
138
 
36
139
  ```bash
37
- npm install @http-forge/core
140
+ # 1) Import Postman assets with HTTP Forge CLI
141
+ http-forge import collection --postman ./MyApi.postman_collection.json
142
+ http-forge import env --postman ./MyEnv.postman_environment.json --env staging --overwrite
143
+
144
+ # 2) Run them in CI-ready mode
145
+ http-forge run collection "MyApi" --env staging --exit-code
146
+
147
+ # 3) Embed the same collection with @http-forge/core (see Minimal Integration Template)
38
148
  ```
39
149
 
40
- Or using the tarball:
150
+ ## 🤖 AI and MCP Features
151
+
152
+ `@http-forge/core` includes MCP runtime capabilities used by HTTP Forge agent workflows.
153
+
154
+ - Exposes MCP-compatible operations for collections, environments, and test execution.
155
+ - Enables AI agents to inspect, run, and update API testing resources programmatically.
156
+ - Powers HTTP Forge CLI/extension AI workflows through shared runtime behavior.
157
+
158
+ Learn more:
159
+ - Runtime API (MCP runtime): [RUNTIME-API.md](RUNTIME-API.md)
160
+ - MCP management tools reference: [docs/MCP_MANAGEMENT_TOOLS.md](docs/MCP_MANAGEMENT_TOOLS.md)
161
+
162
+ ## 🎯 Installation
163
+
164
+ Requires Node.js `20+`.
165
+
41
166
  ```bash
42
- npm install ./http-forge-core-0.1.0.tgz
167
+ npm install @http-forge/core
43
168
  ```
44
169
 
45
170
  ## ⚡ Quick Start
@@ -102,6 +227,33 @@ const forge = new ForgeContainer({
102
227
  });
103
228
  ```
104
229
 
230
+ ## 🧯 Troubleshooting
231
+
232
+ ### Collection Not Found
233
+
234
+ - Verify the path passed to `loadCollection()` points to an existing `.forge.json` file or collection folder.
235
+ - Use absolute paths in CI to avoid working-directory drift.
236
+
237
+ ### Variables Not Resolving (`{{baseUrl}}` remains literal)
238
+
239
+ - Ensure variables are set before `execute()` via `setEnvironment(...)` or environment config.
240
+ - Check for typos and case mismatches in variable names.
241
+
242
+ ### Script Timeout Or Stuck Script
243
+
244
+ - Increase `scriptTimeout` for heavy scripts.
245
+ - Remove long-running loops and external network calls from scripts.
246
+
247
+ ### Authentication/Cookie Flows Failing Across Requests
248
+
249
+ - Enable `enableCookies: true` in `ForgeContainer` options.
250
+ - Confirm login responses include `Set-Cookie` and that subsequent requests reuse the same container instance.
251
+
252
+ ### CI Does Not Fail On Test Assertion Errors
253
+
254
+ - Inspect `postResponseResult?.assertions` after each request and exit with non-zero code when failures exist.
255
+ - If using CLI, include `--exit-code`.
256
+
105
257
  ## 📚 Core Concepts
106
258
 
107
259
  ### ForgeContainer
@@ -723,65 +875,10 @@ MIT © Henry Huang
723
875
 
724
876
  ## 🔗 Links
725
877
 
726
- - [HTTP Forge Extension](https://marketplace.visualstudio.com/items?itemName=your-publisher.http-forge)
878
+ - [HTTP Forge Extension](https://marketplace.visualstudio.com/items?itemName=henry-huang.http-forge)
879
+ - [HTTP Forge CLI](https://github.com/hsl1230/http-forge.cli#readme)
880
+ - [Core Reference Docs](docs/core-reference.md)
881
+ - [Changelog](CHANGELOG.md)
727
882
  - [GitHub Repository](https://github.com/hsl1230/http-forge)
728
883
  - [Issues](https://github.com/hsl1230/http-forge/issues)
729
884
 
730
- ## 📝 Changelog
731
-
732
- ### 0.2.16 (Duplicate Collection & Folder)
733
-
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
737
-
738
- ### 0.2.5 (OpenAPI Constraint Round-Trip & Collision Merging)
739
-
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
744
-
745
- ### 0.2.4 (File Watching & Request Documentation)
746
-
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
752
-
753
- ### 0.2.0 (Postman API Parity)
754
-
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)
770
-
771
- ### 0.1.0 (Initial Release)
772
-
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**