@andrian.yablonskyy/thub-common 1.0.7 → 1.0.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 +2 -1
- package/package.json +1 -1
- package/src/api-client.js +7 -1
package/README.md
CHANGED
|
@@ -46,7 +46,8 @@ A minimal `fetch`-based HTTP client for the Coordinator's `/api/v1` surface, wit
|
|
|
46
46
|
```js
|
|
47
47
|
const { ApiClient } = require('@andrian.yablonskyy/thub-common');
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
// userAgent is optional; the Coordinator records "thub-agent/<v>" / "thub-client/<v>" versions for its dashboard
|
|
50
|
+
const client = new ApiClient({ baseUrl: 'https://thub.example.com', token: 'agt_...', userAgent: 'thub-agent/1.0.8' });
|
|
50
51
|
const job = await client.post('/jobs', spec);
|
|
51
52
|
await client.streamEvents(`/jobs/${job.jobId}/logs/stream`, {
|
|
52
53
|
onEvent: ({ event, id, data }) => console.log(event, data)
|
package/package.json
CHANGED
package/src/api-client.js
CHANGED
|
@@ -20,12 +20,15 @@
|
|
|
20
20
|
* and manual usage identical").
|
|
21
21
|
*/
|
|
22
22
|
class ApiClient{
|
|
23
|
-
|
|
23
|
+
// `userAgent` (e.g. "thub-agent/1.0.8") is how the Coordinator learns
|
|
24
|
+
// which Agent/Client version is talking to it, for the dashboard.
|
|
25
|
+
constructor({ baseUrl, token, userAgent }){
|
|
24
26
|
if (!baseUrl){
|
|
25
27
|
throw new Error('ApiClient requires baseUrl');
|
|
26
28
|
}
|
|
27
29
|
this.baseUrl = baseUrl.replace(/\/+$/, '');
|
|
28
30
|
this.token = token;
|
|
31
|
+
this.userAgent = userAgent;
|
|
29
32
|
}
|
|
30
33
|
|
|
31
34
|
_url(path){
|
|
@@ -34,6 +37,9 @@ class ApiClient{
|
|
|
34
37
|
|
|
35
38
|
_headers(extra = {}){
|
|
36
39
|
const headers = { ...extra };
|
|
40
|
+
if (this.userAgent){
|
|
41
|
+
headers['User-Agent'] = this.userAgent;
|
|
42
|
+
}
|
|
37
43
|
if (this.token){
|
|
38
44
|
headers.Authorization = `Bearer ${this.token}`;
|
|
39
45
|
}
|