@procedures/http 0.2.3 → 0.4.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/CHANGELOG.md ADDED
@@ -0,0 +1,71 @@
1
+ # @procedures/http
2
+
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - ff87747: `http.ndjson` and `http.sse` send a POST too. Their inputs have `method` (`GET` or `POST`), `json` (a body of JSON) and `body` (a body of text), as `http.request` has them. The default method is `POST` with a body, and `GET` without one. An LLM API sends its answer to a POST as server-sent events: `http.sse` now reads such a stream.
8
+
9
+ A POST of a stream gets the host check, the size limit of the request body, `timeoutMs`, `idleTimeoutMs` and the deadline of the call. Two bodies, or a `GET` with a body, fail before the request.
10
+
11
+ A POST can change remote data, so the two streams now declare `writes: ["network"]`, as `http.json` does. Before, they declared `writes: []`.
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies [d919678]
16
+ - Updated dependencies [057d69a]
17
+ - Updated dependencies [b2a1a1e]
18
+ - Updated dependencies [057d69a]
19
+ - Updated dependencies [057d69a]
20
+ - Updated dependencies [057d69a]
21
+ - Updated dependencies [057d69a]
22
+ - Updated dependencies [057d69a]
23
+ - Updated dependencies [afd6a19]
24
+ - Updated dependencies [057d69a]
25
+ - Updated dependencies [4e751da]
26
+ - @procedures/client@0.4.0
27
+
28
+ ## 0.3.0
29
+
30
+ ### Minor Changes
31
+
32
+ - a6b01a9: The new package `@procedures/http` (roadmap R38) has four procedures: `http.request` (each method, a body of text, JSON or base64, and a response as text, JSON or base64), `http.json` (a GET or a POST of JSON), `http.ndjson` (a stream of the JSON values of the lines) and `http.sse` (a stream of server-sent events). `http.request` and `http.json` declare `reads: ["network"]` and `writes: ["network"]`. The two streams send only a GET, so they declare `writes: []`, and they declare `stream: { unbounded: true }`.
33
+
34
+ The default module reaches each public host and refuses loopback, private, link-local, shared, multicast and reserved addresses. `createHttpModule({ allow, publicHosts, maxRequestBytes, maxResponseBytes, resolve })` gives the procedures with more hosts: host names, wildcards, IP addresses and CIDR ranges, each with an optional port. The check resolves the host name, and the connection uses only the addresses that passed the check. Each redirect gets the same check. A refusal has the code `FORBIDDEN` and the new reason `host-not-allowed` (the type `ForbiddenReason` of `@procedures/client`).
35
+
36
+ A call stops at the earliest of its deadline, the abort of the caller and `timeoutMs`. A stream also stops after `idleTimeoutMs` without data. The body of a response has a limit of 10 MiB by default, and the limit counts the decoded bytes of a compressed body.
37
+
38
+ ### Patch Changes
39
+
40
+ - Updated dependencies [ddea529]
41
+ - Updated dependencies [b2a3e3a]
42
+ - Updated dependencies [a8c47f1]
43
+ - Updated dependencies [381ce3a]
44
+ - Updated dependencies [0c627f8]
45
+ - Updated dependencies [ae7f05f]
46
+ - Updated dependencies [7873940]
47
+ - Updated dependencies [a70d445]
48
+ - Updated dependencies [bc70357]
49
+ - Updated dependencies [07cc998]
50
+ - Updated dependencies [a6b01a9]
51
+ - Updated dependencies [c799cdd]
52
+ - Updated dependencies [540f8d9]
53
+ - Updated dependencies [b6daaec]
54
+ - Updated dependencies [5b9264e]
55
+ - Updated dependencies [956e88b]
56
+ - Updated dependencies [ff62281]
57
+ - Updated dependencies [d81d0ed]
58
+ - Updated dependencies [aa67cc7]
59
+ - Updated dependencies [061fa22]
60
+ - Updated dependencies [cfb9d69]
61
+ - Updated dependencies [43f7de5]
62
+ - Updated dependencies [b07bb50]
63
+ - Updated dependencies [4a3bfa1]
64
+ - Updated dependencies [bd0b626]
65
+ - Updated dependencies [a6be873]
66
+ - Updated dependencies [fb30718]
67
+ - Updated dependencies [c5528e4]
68
+ - Updated dependencies [fee5d9c]
69
+ - Updated dependencies [21f7743]
70
+ - Updated dependencies [31a0b46]
71
+ - @procedures/client@0.3.0
package/README.md CHANGED
@@ -14,10 +14,10 @@ HTTP requests as procedures. A host allowlist refuses loopback, private and link
14
14
  |---|---|---|
15
15
  | `http.request` | It sends a request with each method and gives the status, the headers and the body. | reads and writes `network` |
16
16
  | `http.json` | It sends a GET or a POST of JSON and gives the parsed body. | reads and writes `network` |
17
- | `http.ndjson` | It sends a GET and gives a stream of the JSON values of the lines. | reads `network` |
18
- | `http.sse` | It sends a GET and gives a stream of server-sent events. | reads `network` |
17
+ | `http.ndjson` | It sends a GET or a POST and gives a stream of the JSON values of the lines. | reads and writes `network` |
18
+ | `http.sse` | It sends a GET or a POST and gives a stream of server-sent events. | reads and writes `network` |
19
19
 
20
- - `http.request` and `http.json` can change remote data with a POST, a PUT or a DELETE, so they declare a write. The two stream procedures send only a GET, so they change nothing.
20
+ - Each procedure can change remote data with a POST, so each procedure declares a write. `http.request` also sends a PUT or a DELETE.
21
21
  - `http.ndjson` and `http.sse` declare `stream: { unbounded: true }`, because a server can send a stream without an end. A face that collects a stream refuses them or stops them at its limits.
22
22
 
23
23
  ```ts
@@ -27,6 +27,29 @@ await client.call(["http", "json"], { url: "https://api.github.com/repos/nodejs/
27
27
  await client.call(["http", "request"], { url: "https://example.com/upload", method: "PUT", body: "text" });
28
28
  ```
29
29
 
30
+ ### The streams of a POST
31
+
32
+ An LLM API sends its answer to a POST as server-sent events. `http.sse` and `http.ndjson` take the same request fields as `http.request`:
33
+
34
+ | Field | Meaning |
35
+ |---|---|
36
+ | `method` | `GET` or `POST`. The default is `POST` with `body` or `json`, and `GET` without them. |
37
+ | `json` | A body of JSON. The procedure sets `content-type: application/json`. |
38
+ | `body` | A body of text. The procedure sets `content-type: text/plain; charset=utf-8`. |
39
+ | `headers` | The headers of the request. A header of the input replaces a header that the procedure sets. |
40
+
41
+ ```ts
42
+ const events = client.stream(["http", "sse"], {
43
+ url: "https://api.example.com/v1/chat",
44
+ headers: { authorization: `Bearer ${key}` },
45
+ json: { prompt: "Hello", stream: true },
46
+ });
47
+ for await (const event of events) console.log(event.data);
48
+ ```
49
+
50
+ - A POST of a stream gets the same host check, size limit of the request, time limits and deadline as the other requests.
51
+ - Two bodies, or a `GET` with a body, fail before the request.
52
+
30
53
  ## The hosts
31
54
 
32
55
  The default module (`httpModule`) reaches each public host. It refuses these addresses:
@@ -106,6 +129,7 @@ const registry = createRegistry(createHttpModule({ allow: ["localhost:11434", "1
106
129
  - The parse obeys the rules of the HTML standard. A line ends at CR, LF or CRLF. A blank line sends an event. A line that starts with a colon is a comment.
107
130
  - An event has `event` (`message` by default), `data`, the last event ID `id` and `retry`.
108
131
  - The procedure does not connect again after the end of the stream. To continue, a caller sends the last ID in `lastEventId`.
132
+ - A redirect of a POST obeys the rules of the redirects. A 303, or a 301 or 302, continues with a GET without the body.
109
133
 
110
134
  ## Limits of this package
111
135