@telorun/http-client 0.1.3 → 0.1.5
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 +84 -0
- package/package.json +20 -2
package/README.md
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# Telo HTTP Client Standard Specification (v1.0 Draft)
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
The `Http.Request` (and optionally `Http.Client`) definitions represent outgoing HTTP calls made by the Telo kernel to external services.
|
|
6
|
+
Because different programming languages implement HTTP clients differently (e.g., `fetch` in Node.js, `reqwest` in Rust), all Telo HTTP Client modules MUST adhere to this exact behavior to ensure cross-language compatibility.
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## 1. The Request Contract (Input Serialization)
|
|
11
|
+
|
|
12
|
+
When the Telo kernel executes an `Http.Request`, the underlying module must construct the outgoing request according to strict rules.
|
|
13
|
+
|
|
14
|
+
- **Headers Normalization:** All header keys provided in the manifest MUST be normalized to lowercase before sending.
|
|
15
|
+
- **Query Parameters:** If `query` is provided as an object, the module MUST safely URL-encode the keys and values and append them to the `url`.
|
|
16
|
+
- **Payload Serialization (Body):**
|
|
17
|
+
- If the `headers` include `content-type: application/json` (which should be the default if `body` is an object), the module MUST serialize the `body` to a JSON string.
|
|
18
|
+
- If the `content-type` is `application/x-www-form-urlencoded`, the module MUST serialize the object into a URL-encoded string.
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## 2. The Response Contract (Output Deserialization)
|
|
23
|
+
|
|
24
|
+
The output of an `Http.Request` becomes available to the Telo engine (e.g., for mapping via CEL expressions). The underlying engine MUST return a standardized **Telo Response Object**.
|
|
25
|
+
|
|
26
|
+
### Standardized Return Object
|
|
27
|
+
|
|
28
|
+
```json
|
|
29
|
+
{
|
|
30
|
+
"status": 200,
|
|
31
|
+
"headers": {
|
|
32
|
+
"content-type": "application/json",
|
|
33
|
+
"x-ratelimit-remaining": "99"
|
|
34
|
+
},
|
|
35
|
+
"body": {
|
|
36
|
+
"userId": 1,
|
|
37
|
+
"title": "Hello World"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
- **Header Normalization:** The module MUST normalize all incoming response headers to lowercase keys.
|
|
43
|
+
- **Body Deserialization Rules:**
|
|
44
|
+
- **JSON:** If the response header `content-type` includes `application/json`, the module MUST attempt to parse the response body as a JSON object. _Edge Case:_ If the response is empty (0 bytes) but claims to be JSON, the module MUST return `null` for the body, not throw a parsing error.
|
|
45
|
+
- **Text/Other:** For any other content type, or if JSON parsing fails gracefully, the `body` MUST be returned as a raw String.
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## 3. Error Handling Contract (Network vs. HTTP)
|
|
50
|
+
|
|
51
|
+
It is crucial to differentiate between an HTTP error (the external server responded) and a Network error (the kernel couldn't reach the server).
|
|
52
|
+
|
|
53
|
+
### 3.1. HTTP Status Errors (4xx and 5xx)
|
|
54
|
+
|
|
55
|
+
- **Standard:** By default, HTTP status codes like `400`, `404`, or `500` **MUST NOT** throw a kernel execution error.
|
|
56
|
+
- They are considered successful _network_ executions. The module MUST return the standard Telo Response Object with the respective `status` code. It is up to the Telo manifest author to handle these via CEL mappings (e.g., `${{ result.status == 200 ? result.body : throw('API Failed') }}`).
|
|
57
|
+
|
|
58
|
+
### 3.2. Network & Engine Errors
|
|
59
|
+
|
|
60
|
+
If the request fails at the network layer (e.g., DNS resolution failure, connection refused, SSL error), the module MUST throw a standardized **Telo Network Error** that stops execution.
|
|
61
|
+
|
|
62
|
+
**Standardized Error Format:**
|
|
63
|
+
|
|
64
|
+
```json
|
|
65
|
+
{
|
|
66
|
+
"error": "NetworkError",
|
|
67
|
+
"code": "CONNECTION_REFUSED",
|
|
68
|
+
"message": "Failed to connect to api.external.com",
|
|
69
|
+
"details": {
|
|
70
|
+
"url": "https://api.external.com/data"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
_Valid `code` enumerations MUST include:_ `TIMEOUT`, `CONNECTION_REFUSED`, `DNS_RESOLUTION_FAILED`, `SSL_ERROR`. Modules must map their native engine errors to these generic codes.
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## 4. Execution Policies (Timeouts & Redirects)
|
|
80
|
+
|
|
81
|
+
To prevent hanging processes, Telo enforces strict default limits on outgoing requests.
|
|
82
|
+
|
|
83
|
+
- **Timeouts:** The module MUST enforce a default request timeout of **10,000 milliseconds (10 seconds)** unless overridden in the manifest. If the timeout is reached, it MUST throw a `NetworkError` with the code `TIMEOUT`.
|
|
84
|
+
- **Redirects:** The module MUST automatically follow `301` and `302` redirects, up to a maximum of **5 redirects**, to prevent infinite redirect loops.
|
package/package.json
CHANGED
|
@@ -1,6 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telorun/http-client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
|
+
"description": "Telo HTTP Client module - HTTP client resource kinds for Telo manifests.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"telo",
|
|
7
|
+
"http",
|
|
8
|
+
"client",
|
|
9
|
+
"request"
|
|
10
|
+
],
|
|
11
|
+
"author": "Bartosz Pasiński <bartosz.pasinski@codenet.pl>",
|
|
12
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/telorun/telo.git",
|
|
16
|
+
"directory": "modules/http-client/nodejs"
|
|
17
|
+
},
|
|
18
|
+
"homepage": "https://github.com/telorun/telo#readme",
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/telorun/telo/issues"
|
|
21
|
+
},
|
|
4
22
|
"type": "module",
|
|
5
23
|
"exports": {
|
|
6
24
|
"./http-client": {
|
|
@@ -17,7 +35,7 @@
|
|
|
17
35
|
"src/**"
|
|
18
36
|
],
|
|
19
37
|
"dependencies": {
|
|
20
|
-
"@telorun/sdk": "0.
|
|
38
|
+
"@telorun/sdk": "0.3.0"
|
|
21
39
|
},
|
|
22
40
|
"devDependencies": {
|
|
23
41
|
"@types/node": "^20.0.0",
|