@http-forge/core 0.4.6 → 0.4.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/README.md +55 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +214 -214
- package/dist/index.mjs +214 -214
- package/dist/infrastructure/auth/oauth2-token-manager.d.ts +1 -1
- package/dist/infrastructure/config/config-service.d.ts +1 -0
- package/dist/infrastructure/config/config.interface.d.ts +8 -0
- package/dist/infrastructure/environment/variable-interpolator.d.ts +24 -1
- package/dist/infrastructure/execution/request-executor.d.ts +1 -0
- package/dist/infrastructure/script/async-drain.d.ts +53 -0
- package/dist/infrastructure/script/interfaces.d.ts +1 -0
- package/dist/infrastructure/script/request-script-session.d.ts +21 -1
- package/dist/infrastructure/script/script-executor.d.ts +6 -1
- package/dist/infrastructure/script/script-factories.d.ts +1 -0
- package/dist/runtime/mcp-tool-name.d.ts +46 -0
- package/dist/runtime/mcp-tool-schemas.d.ts +170 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -252,6 +252,35 @@ if (pm.response.headers.has('Set-Cookie')) {
|
|
|
252
252
|
}
|
|
253
253
|
```
|
|
254
254
|
|
|
255
|
+
#### Response Body Type
|
|
256
|
+
|
|
257
|
+
Like Postman, `pm.response.body` is the **raw response string** — it is not eagerly parsed. Parse JSON on demand:
|
|
258
|
+
|
|
259
|
+
```javascript
|
|
260
|
+
const data = pm.response.json(); // parsed object (null if not JSON)
|
|
261
|
+
const text = pm.response.text(); // raw string
|
|
262
|
+
const obj = JSON.parse(pm.response.body); // body is a string
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
`json()` tolerates an already-parsed object body for backward compatibility, but new code should treat `pm.response.body` as a string.
|
|
266
|
+
|
|
267
|
+
#### Legacy Postman Globals
|
|
268
|
+
|
|
269
|
+
Older Postman scripts and many Newman-exported collections rely on bare globals from the pre-`pm.*` sandbox. The core injects these so legacy scripts run unchanged.
|
|
270
|
+
|
|
271
|
+
Available in **both** pre-request and test scripts: `request` (`{ id, name, description, url, method, headers, data }`), `environment` (read snapshot), `globals` (read snapshot), `data` (iteration row), `iteration` (index), and `tv4` (`tv4.validate(data, schema)` — when the optional `tv4` module is installed).
|
|
272
|
+
|
|
273
|
+
Available in **test** scripts only: `responseBody` (raw string), `responseCode` (`{ code, name, detail }`), `responseHeaders`, `responseTime`, `responseCookies` (`[{ name, value }]`), `tests` (`tests['name'] = boolean`), plus `postman.getResponseHeader(name)` and `postman.getResponseCookie(name)` (case-insensitive, return `null` if absent).
|
|
274
|
+
|
|
275
|
+
```javascript
|
|
276
|
+
// Legacy-style test script — runs unmodified
|
|
277
|
+
tests['status 200'] = responseCode.code === 200;
|
|
278
|
+
tests['has token'] = JSON.parse(responseBody).token !== undefined;
|
|
279
|
+
tests['is json'] = /application\/json/.test(postman.getResponseHeader('Content-Type'));
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
> `environment` and `globals` are read snapshots — direct assignment was never persisted in legacy Postman either. Use `postman.setEnvironmentVariable()` / `postman.setGlobalVariable()` (or the modern `pm.environment.set()` / `pm.globals.set()`) to persist changes.
|
|
283
|
+
|
|
255
284
|
#### Script Scope
|
|
256
285
|
|
|
257
286
|
Control how script levels (collection → folder → request) and the pre-request/post-response phases share a JavaScript scope via `scripts.scope` in `http-forge.config.json` (or the `scriptScope` SDK option):
|
|
@@ -267,6 +296,31 @@ const forge = ForgeContainer.create({ scriptScope: 'isolated' });
|
|
|
267
296
|
|
|
268
297
|
Use `'isolated'` when importing Postman collections whose scripts re-declare the same identifiers at multiple levels, which would otherwise throw `Identifier already declared` in shared mode.
|
|
269
298
|
|
|
299
|
+
#### Async Script Execution (Event-Loop Draining)
|
|
300
|
+
|
|
301
|
+
Like Postman, scripts do **not** end when their synchronous code returns. After the sync body completes, the core keeps the sandbox alive and drains pending timers (`setTimeout`/`setInterval`) and microtasks (un-awaited `Promise`s), then commits variable scopes — so deferred `pm.globals` / `pm.environment` / `pm.variables` writes are visible to the next request **without** `await`.
|
|
302
|
+
|
|
303
|
+
```typescript
|
|
304
|
+
// Post-response script — committed for the next request, no await required
|
|
305
|
+
setTimeout(() => pm.globals.set('authToken', generateToken()), 1500);
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
The drain is bounded by `scripts.timeout` (the `scriptTimeout` SDK option), default **5000 ms**, which caps **both** synchronous CPU time and the async-drain window:
|
|
309
|
+
|
|
310
|
+
```typescript
|
|
311
|
+
const forge = ForgeContainer.create({ scriptTimeout: 10000 });
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
| Behavior | Notes |
|
|
315
|
+
|----------|-------|
|
|
316
|
+
| Sandbox kept alive after sync return | Pending timers/microtasks drained before the request advances |
|
|
317
|
+
| Deferred `pm.*` writes committed | Visible to the next request without `await` |
|
|
318
|
+
| Errors in timer/Promise callbacks | Reported as a console error, **non-fatal** — the request/test is not failed |
|
|
319
|
+
| Runaway timers | A never-clearing `setInterval` or infinite timer loop is force-cancelled at the timeout, with a warning |
|
|
320
|
+
| No async work | Returns immediately; draining adds no measurable latency |
|
|
321
|
+
|
|
322
|
+
**Divergences from Postman:** uses real Node timers with a poll-based wall-clock drain (no exact pending-promise count, so pathological microtask recursion is bounded by the budget rather than a precise idle signal); a single `scripts.timeout` bounds both CPU time and the async window.
|
|
323
|
+
|
|
270
324
|
### Environment Management
|
|
271
325
|
|
|
272
326
|
```typescript
|
|
@@ -431,7 +485,7 @@ interface ForgeContainerOptions {
|
|
|
431
485
|
|
|
432
486
|
// Script Settings
|
|
433
487
|
scriptRunner?: IScriptRunner; // Custom script runner
|
|
434
|
-
scriptTimeout?: number; // Script
|
|
488
|
+
scriptTimeout?: number; // Script budget (ms); caps CPU time + async-drain window. Default 5000
|
|
435
489
|
|
|
436
490
|
// History
|
|
437
491
|
enableHistory?: boolean; // Enable request history
|
package/dist/index.d.ts
CHANGED
|
@@ -20,6 +20,9 @@ export { ForgeContainer } from './container';
|
|
|
20
20
|
export type { ForgeContainerOptions, StorageFormat } from './container';
|
|
21
21
|
export { getServiceContainer, registerCoreServices, ServiceContainer, ServiceIdentifiers } from './di';
|
|
22
22
|
export type { PlatformAdapters, ServiceIdentifier } from './di';
|
|
23
|
+
export { buildCollectionToolDescription, buildCollectionToolName, buildFolderToolDescription, buildFolderToolName, buildRequestToolDescription, buildRequestToolName, buildSuiteToolDescription, buildSuiteToolName, mcpToolToken, parseMcpToolName, resolveFolderToken, resolveToken } from './runtime/mcp-tool-name';
|
|
24
|
+
export type { McpToolKind, ParsedMcpToolName } from './runtime/mcp-tool-name';
|
|
25
|
+
export { COLLECTION_INPUT_SCHEMA, FOLDER_INPUT_SCHEMA, REQUEST_INPUT_SCHEMA, SUITE_INPUT_SCHEMA } from './runtime/mcp-tool-schemas';
|
|
23
26
|
export { createMcpRuntime, runCollection, runFolder, runRequest, runSuite } from './runtime/runtime-contracts';
|
|
24
27
|
export type { McpRuntimeHandle, McpRuntimeOptions, RunCollectionOptions, RunRequestOptions, RunSuiteOptions } from './runtime/runtime-contracts';
|
|
25
28
|
export { bootstrapNodeRuntime, createNodeContainer } from './runtime/node-bootstrap';
|