@telorun/http-client 0.2.2 → 0.3.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/LICENSE +2 -2
- package/README.md +64 -38
- package/dist/http-request-controller.js +8 -3
- package/package.json +4 -4
- package/src/http-request-controller.ts +8 -3
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# SUSTAINABLE USE LICENSE (Fair-code)
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2026
|
|
3
|
+
Copyright (c) 2026 CodeNet Sp. z o.o.
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to use, copy, modify, and distribute the Software for any purpose—including commercial purposes—subject to the following conditions:
|
|
6
6
|
|
|
@@ -14,4 +14,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
14
14
|
|
|
15
15
|
5. DISCLAIMER: The Software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the Software or the use or other dealings in the Software.
|
|
16
16
|
|
|
17
|
-
For commercial licensing, managed hosting exemptions, or enterprise inquiries, please contact
|
|
17
|
+
For commercial licensing, managed hosting exemptions, or enterprise inquiries, please contact <contact@codenet.pl>.
|
package/README.md
CHANGED
|
@@ -1,29 +1,63 @@
|
|
|
1
|
-
#
|
|
1
|
+
# HTTP Client
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Outgoing HTTP calls for Telo. Language- and engine-neutral request/response contract, with shared `Http.Client` defaults and per-call `Http.Request` overrides.
|
|
4
4
|
|
|
5
|
-
|
|
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.
|
|
5
|
+
## Why use this
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
- **Engine-neutral contract** — `fetch`, `reqwest`, or anything else; the same manifest serializes input and deserializes output the same way.
|
|
8
|
+
- **Shared client defaults** — `Http.Client` defines base URL, headers, timeout, and redirect behaviour once; `Http.Request` overrides per call.
|
|
9
|
+
- **Network vs. HTTP errors** — 4xx/5xx return a normal response object; only true network failures throw a structured `NetworkError`.
|
|
10
|
+
- **JSON-aware** — `content-type: application/json` request bodies are serialized; JSON responses are parsed automatically.
|
|
11
|
+
- **Buffer or stream** — pick `mode: stream` to receive a readable stream without buffering the response body.
|
|
12
|
+
- **Built-in retries** — `retries: N` retries on network errors only, leaving HTTP responses to manifest logic.
|
|
9
13
|
|
|
10
|
-
##
|
|
14
|
+
## Kinds
|
|
11
15
|
|
|
12
|
-
|
|
16
|
+
| Kind | Purpose |
|
|
17
|
+
| --- | --- |
|
|
18
|
+
| `Http.Client` | Long-lived client carrying base URL, default headers, timeout, and redirect policy. |
|
|
19
|
+
| `Http.Request` | Per-call HTTP request invocable; references an `Http.Client` for shared defaults. |
|
|
13
20
|
|
|
14
|
-
|
|
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.
|
|
21
|
+
## Example
|
|
19
22
|
|
|
23
|
+
```yaml
|
|
24
|
+
kind: Telo.Application
|
|
25
|
+
metadata: { name: fetcher, version: 1.0.0 }
|
|
26
|
+
---
|
|
27
|
+
kind: Telo.Import
|
|
28
|
+
metadata: { name: Http }
|
|
29
|
+
source: pkg:npm/@telorun/http-client@^1.0.0
|
|
30
|
+
---
|
|
31
|
+
kind: Http.Client
|
|
32
|
+
metadata: { name: GitHub }
|
|
33
|
+
baseUrl: https://api.github.com
|
|
34
|
+
headers:
|
|
35
|
+
accept: application/vnd.github+json
|
|
36
|
+
timeout: 5000
|
|
20
37
|
---
|
|
38
|
+
kind: Http.Request
|
|
39
|
+
metadata: { name: GetUser }
|
|
40
|
+
client: GitHub
|
|
41
|
+
inputs:
|
|
42
|
+
url: /users/octocat
|
|
43
|
+
method: GET
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Implementation Contract
|
|
21
47
|
|
|
22
|
-
|
|
48
|
+
### 1. Request contract (input serialization)
|
|
49
|
+
|
|
50
|
+
When the Telo kernel executes an `Http.Request`, the underlying module must construct the outgoing request according to strict rules.
|
|
23
51
|
|
|
24
|
-
|
|
52
|
+
- **Headers normalization:** all header keys provided in the manifest MUST be normalized to lowercase before sending.
|
|
53
|
+
- **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`.
|
|
54
|
+
- **Payload serialization (body):**
|
|
55
|
+
- If the `headers` include `content-type: application/json` (the default when `body` is an object), the module MUST serialize the `body` to a JSON string.
|
|
56
|
+
- If the `content-type` is `application/x-www-form-urlencoded`, the module MUST serialize the object into a URL-encoded string.
|
|
25
57
|
|
|
26
|
-
###
|
|
58
|
+
### 2. Response contract (output deserialization)
|
|
59
|
+
|
|
60
|
+
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.
|
|
27
61
|
|
|
28
62
|
```json
|
|
29
63
|
{
|
|
@@ -39,27 +73,23 @@ The output of an `Http.Request` becomes available to the Telo engine (e.g., for
|
|
|
39
73
|
}
|
|
40
74
|
```
|
|
41
75
|
|
|
42
|
-
- **Header
|
|
43
|
-
- **Body
|
|
44
|
-
- **JSON:**
|
|
45
|
-
- **Text/
|
|
46
|
-
|
|
47
|
-
---
|
|
48
|
-
|
|
49
|
-
## 3. Error Handling Contract (Network vs. HTTP)
|
|
76
|
+
- **Header normalization:** the module MUST normalize all incoming response headers to lowercase keys.
|
|
77
|
+
- **Body deserialization:**
|
|
78
|
+
- **JSON:** if the response `content-type` includes `application/json`, the module MUST attempt to parse the body as JSON. If the response is empty (0 bytes) but claims to be JSON, the module MUST return `null` for the body rather than throw.
|
|
79
|
+
- **Text/other:** for any other content type, or if JSON parsing fails gracefully, the `body` MUST be returned as a raw string.
|
|
50
80
|
|
|
51
|
-
|
|
81
|
+
### 3. Error handling (network vs. HTTP)
|
|
52
82
|
|
|
53
|
-
|
|
83
|
+
It is crucial to differentiate between an HTTP error (the external server responded) and a network error (the kernel couldn't reach the server).
|
|
54
84
|
|
|
55
|
-
|
|
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') }}`).
|
|
85
|
+
#### 3.1 HTTP status errors (4xx and 5xx)
|
|
57
86
|
|
|
58
|
-
|
|
87
|
+
- **Standard:** by default, HTTP status codes like `400`, `404`, or `500` MUST NOT throw a kernel execution error.
|
|
88
|
+
- They are considered successful network executions. The module MUST return the standard Telo Response Object with the respective `status` code. Manifest authors handle these via CEL mappings (e.g. `${{ result.status == 200 ? result.body : throw('API Failed') }}`).
|
|
59
89
|
|
|
60
|
-
|
|
90
|
+
#### 3.2 Network and engine errors
|
|
61
91
|
|
|
62
|
-
|
|
92
|
+
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.
|
|
63
93
|
|
|
64
94
|
```json
|
|
65
95
|
{
|
|
@@ -72,13 +102,9 @@ If the request fails at the network layer (e.g., DNS resolution failure, connect
|
|
|
72
102
|
}
|
|
73
103
|
```
|
|
74
104
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
---
|
|
78
|
-
|
|
79
|
-
## 4. Execution Policies (Timeouts & Redirects)
|
|
105
|
+
Valid `code` values MUST include: `TIMEOUT`, `CONNECTION_REFUSED`, `DNS_RESOLUTION_FAILED`, `SSL_ERROR`. Modules must map their native engine errors to these generic codes.
|
|
80
106
|
|
|
81
|
-
|
|
107
|
+
### 4. Execution policies (timeouts and redirects)
|
|
82
108
|
|
|
83
|
-
- **Timeouts:**
|
|
84
|
-
- **Redirects:**
|
|
109
|
+
- **Timeouts:** the module MUST enforce a default request timeout of 10,000 ms unless overridden. Timeout failures MUST throw a `NetworkError` with code `TIMEOUT`.
|
|
110
|
+
- **Redirects:** the module MUST automatically follow `301` and `302` redirects, up to a maximum of 5, to prevent infinite redirect loops.
|
|
@@ -165,8 +165,12 @@ class HttpRequestResource {
|
|
|
165
165
|
? resolvedTimeout
|
|
166
166
|
: DEFAULT_TIMEOUT;
|
|
167
167
|
}
|
|
168
|
-
//
|
|
169
|
-
//
|
|
168
|
+
// Build the effective inputs by layering, lowest precedence to highest:
|
|
169
|
+
// 1. manifest-level fields (url, method, ...) — fallback defaults
|
|
170
|
+
// 2. m.inputs — manifest-baked inputs (legacy, still supported when present)
|
|
171
|
+
// 3. call-site `input` — the canonical sibling-form invocation args
|
|
172
|
+
// CEL expressions inside any of these resolve against `input` as the context.
|
|
173
|
+
const callerInput = (input ?? {});
|
|
170
174
|
const manifestInputs = {
|
|
171
175
|
url: m.url,
|
|
172
176
|
method: m.method,
|
|
@@ -174,8 +178,9 @@ class HttpRequestResource {
|
|
|
174
178
|
headers: m.headers,
|
|
175
179
|
body: m.body,
|
|
176
180
|
...m.inputs,
|
|
181
|
+
...callerInput,
|
|
177
182
|
};
|
|
178
|
-
const resolved = ctx.expandValue(manifestInputs,
|
|
183
|
+
const resolved = ctx.expandValue(manifestInputs, callerInput);
|
|
179
184
|
const rawUrl = resolved.url;
|
|
180
185
|
const method = ((resolved.method ?? "GET") || "GET").toUpperCase();
|
|
181
186
|
const requestHeaders = normalizeHeaders((resolved.headers ?? {}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telorun/http-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Telo HTTP Client module - HTTP client resource kinds for Telo manifests.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"telo",
|
|
@@ -34,13 +34,13 @@
|
|
|
34
34
|
"dist",
|
|
35
35
|
"src/**"
|
|
36
36
|
],
|
|
37
|
-
"dependencies": {
|
|
38
|
-
"@telorun/sdk": "0.11.1"
|
|
39
|
-
},
|
|
40
37
|
"devDependencies": {
|
|
41
38
|
"@types/node": "^20.0.0",
|
|
42
39
|
"typescript": "^5.0.0"
|
|
43
40
|
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"@telorun/sdk": "0.12.0"
|
|
43
|
+
},
|
|
44
44
|
"scripts": {
|
|
45
45
|
"build": "tsc -p tsconfig.lib.json"
|
|
46
46
|
}
|
|
@@ -229,8 +229,12 @@ class HttpRequestResource implements ResourceInstance {
|
|
|
229
229
|
: DEFAULT_TIMEOUT;
|
|
230
230
|
}
|
|
231
231
|
|
|
232
|
-
//
|
|
233
|
-
//
|
|
232
|
+
// Build the effective inputs by layering, lowest precedence to highest:
|
|
233
|
+
// 1. manifest-level fields (url, method, ...) — fallback defaults
|
|
234
|
+
// 2. m.inputs — manifest-baked inputs (legacy, still supported when present)
|
|
235
|
+
// 3. call-site `input` — the canonical sibling-form invocation args
|
|
236
|
+
// CEL expressions inside any of these resolve against `input` as the context.
|
|
237
|
+
const callerInput = (input ?? {}) as Record<string, unknown>;
|
|
234
238
|
const manifestInputs: HttpRequestInputs = {
|
|
235
239
|
url: m.url,
|
|
236
240
|
method: m.method,
|
|
@@ -238,8 +242,9 @@ class HttpRequestResource implements ResourceInstance {
|
|
|
238
242
|
headers: m.headers,
|
|
239
243
|
body: m.body,
|
|
240
244
|
...m.inputs,
|
|
245
|
+
...callerInput,
|
|
241
246
|
};
|
|
242
|
-
const resolved = ctx.expandValue(manifestInputs,
|
|
247
|
+
const resolved = ctx.expandValue(manifestInputs, callerInput) as HttpRequestInputs;
|
|
243
248
|
const rawUrl = resolved.url as string;
|
|
244
249
|
const method = ((resolved.method ?? "GET") || "GET").toUpperCase();
|
|
245
250
|
const requestHeaders = normalizeHeaders((resolved.headers ?? {}) as Record<string, string>);
|