manifest 6.0.0 → 7.0.0

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/CONTRACT.md CHANGED
@@ -15,13 +15,13 @@ The SDK talks to the configured Manifest API using `Authorization: Bearer <proje
15
15
  }
16
16
  ```
17
17
 
18
- Credential filtering and body limits are described in the README. Capture gates live in `runtime.ts`; the server owns repair policy.
18
+ Any 4xx response is captured except 401, 402, 403 and 429; those and every 5xx pass through untouched, because auth, billing, rate limiting and server faults are not repaired by editing the request. JSON bodies and `application/x-www-form-urlencoded` bodies are sent as structured JSON values. Credential filtering and body limits are described in the README. Capture gates live in `runtime.ts`; the server owns repair policy.
19
19
 
20
20
  A successful heal response may contain `status: patched|unverified`, `healAttemptId`, `operations` and `healedRequest` with `url`, `headers` or `body`. Only these two statuses authorize a retry. No patch, malformed responses and unavailable service return the original error response. HTTP 403 with `{"error":"project_disabled"}` suppresses healing for five minutes.
21
21
 
22
22
  ## Apply
23
23
 
24
- A healed URL replaces the URL only within the original origin. Headers set or replace case-insensitively; null removes a header. Content length is recalculated. Objects merge using the server's healed body as the authoritative copy of fields sent to the server; withheld local credential fields are restored. Non-object JSON replaces the body. Incomplete request or error captures are not retried.
24
+ A healed URL replaces the URL only within the original origin. Headers set or replace case-insensitively; null removes a header. Content length is recalculated. Objects merge using the server's healed body as the authoritative copy of fields sent to the server; withheld local credential fields are restored. Non-object JSON replaces the body. Form-urlencoded retries use the original encoding and are re-encoded from the parsed structure, so repeated keys return as indexed keys; a non-object healed body is not retried for them. Incomplete or malformed request captures and incomplete error captures are not retried.
25
25
 
26
26
  Each captured failure permits one retry. A retry response, including another failure, is returned to the caller. A transport failure returns the original response. Successful response streams are not eagerly consumed.
27
27
 
package/README.md CHANGED
@@ -1,52 +1,46 @@
1
1
  # Manifest for Node.js
2
2
 
3
3
  [![CI](https://github.com/mnfst/manifest-node/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/mnfst/manifest-node/actions/workflows/ci.yml)
4
+ [![npm version](https://img.shields.io/npm/v/manifest?label=npm)](https://www.npmjs.com/package/manifest)
5
+ [![npm downloads](https://img.shields.io/npm/dm/manifest?label=npm%20downloads)](https://www.npmjs.com/package/manifest)
4
6
 
5
- Repair failed JSON API requests automatically. Works with Node's built-in `fetch`, for everyday APIs and LLMs alike.
7
+ **An API rejects your request. Manifest fixes it and retries. You do nothing.**
8
+
9
+ ```sh
10
+ npm install manifest
11
+ ```
6
12
 
7
13
  ```js
8
14
  import { manifest } from 'manifest';
9
15
 
10
- manifest();
16
+ manifest(); // once, at startup
11
17
  // Keep making your API calls as usual.
12
18
  ```
13
19
 
14
- Your API rejects a request → Manifest finds a repair → the SDK retries once, locally.
15
-
16
- ## Setup
17
-
18
- ### 1. Install
19
-
20
- Requires **Node.js 22+**:
21
-
22
- ```sh
23
- npm install manifest
24
- ```
20
+ Works with built-in `fetch`, `node:http`, `node:https` and Axios, for JSON and form-urlencoded bodies. Node.js 22+. TypeScript, ESM and CommonJS. Zero dependencies.
25
21
 
26
- JavaScript, TypeScript, ESM and CommonJS are supported; there are no runtime dependencies.
22
+ ![How Manifest heals a failed request: a 400 reaches Manifest, drops to a patch from the knowledge base or the healing agents, and is retried once, returning a 200 OK](docs/healing-diagram.svg)
27
23
 
28
- ### 2. Connect your project
24
+ ## Setup
29
25
 
30
- Create a project in your Manifest dashboard and copy the project key shown during setup. In **Project Settings**, turn **Autofix** on to enable repairs.
26
+ 1. Create a project in your Manifest dashboard and copy its project key.
27
+ 2. Turn on **Autofix** in **Project Settings**.
28
+ 3. Set the key:
31
29
 
32
30
  ```sh
33
31
  export MNFST_KEY='your-project-key'
34
32
  ```
35
33
 
36
- The SDK defaults to `https://api.manifest.build`. For a local app running on port 5310, also set:
34
+ Call `manifest()` before any library grabs its own reference to `fetch` or `node:http`. To install before any of your modules run, preload it instead:
37
35
 
38
36
  ```sh
39
- export MNFST_URL='http://127.0.0.1:5310'
37
+ node --import manifest/register app.js
40
38
  ```
41
39
 
42
- Your server must support the [SDK API contract](CONTRACT.md). The local app must already be running.
43
-
44
- ### 3. Initialize before your requests
45
-
46
- Call `manifest()` once at startup, before other libraries save a reference to `fetch`. Save this as `example.mjs`, replacing the example endpoint and payload with your own:
40
+ ## See it work
47
41
 
48
42
  ```js
49
- import { manifest, flush } from 'manifest';
43
+ import { manifest } from 'manifest';
50
44
 
51
45
  manifest({
52
46
  onHeal(event) {
@@ -54,36 +48,19 @@ manifest({
54
48
  },
55
49
  });
56
50
 
57
- try {
58
- const response = await fetch('https://api.example.com/orders', {
59
- method: 'POST',
60
- headers: { 'content-type': 'application/json' },
61
- body: JSON.stringify({ limit: 500 }),
62
- });
63
- console.log(response.status, await response.text());
64
- } finally {
65
- await flush({ timeoutMs: 5000 });
66
- }
51
+ const res = await fetch('https://api.example.com/orders', {
52
+ method: 'POST',
53
+ headers: { 'content-type': 'application/json' },
54
+ body: JSON.stringify({ limit: 500 }), // rejected? Manifest retries with a valid limit
55
+ });
67
56
  ```
68
57
 
69
- Run it with `node example.mjs`. For an API that rejects `limit: 500` and has a matching repair, Manifest can retry with a valid limit. Repairs depend on the API error and available patches.
70
-
71
- CommonJS uses `const { manifest, flush } = require('manifest')`.
72
-
73
- ## Check that it works
74
-
75
- Send a JSON request that your test API rejects with **400, 404 or 422**. Check the failure in your project's dashboard and the `onHeal` callback for the repair result. A successful request alone does not contact Manifest. `flush()` lets a short script wait for outcome reports before exiting.
76
-
77
- ## What to expect
78
-
79
- - **One retry.** Manifest returns a repair; the SDK sends the corrected request directly to your API.
80
- - **Original error if healing is unavailable.** A heal call can add up to 60 seconds. If a retry returns an HTTP response, that response reaches your application.
81
- - **Built-in fetch.** Browser JavaScript, default Axios, `node:http` and separately imported fetch implementations are not intercepted.
82
- - **Retry semantics still matter.** Use idempotency keys where needed; a repeated request can repeat side effects.
83
-
84
- ## Privacy
58
+ ## Good to know
85
59
 
86
- Manifest receives failed request URLs, headers, JSON bodies and error responses. Known credential fields are masked or withheld, but nested secrets, prompts and business data can still be sent. Enable it only for traffic you permit your Manifest server to process and store.
60
+ - **Retries repeat side effects.** Use idempotency keys on non-idempotent calls.
61
+ - **A heal adds up to 60 s** to a failed request. Successful requests are untouched.
62
+ - **Not intercepted:** browsers, HTTP/2, and directly imported `undici`.
63
+ - **Privacy.** Failed URLs, headers, JSON or form-urlencoded bodies, and error responses are sent to Manifest. Known credentials are masked, but nested secrets and business data are not. Enable it only for traffic you allow Manifest to process.
87
64
 
88
65
  ## More
89
66