@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 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
- const client = new ApiClient({ baseUrl: 'https://thub.example.com', token: 'agt_...' });
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andrian.yablonskyy/thub-common",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "Shared job-spec schema, state enums and a thin API client used by the Agent and Client",
5
5
  "main": "src/index.js",
6
6
  "files": [
package/src/api-client.js CHANGED
@@ -20,12 +20,15 @@
20
20
  * and manual usage identical").
21
21
  */
22
22
  class ApiClient{
23
- constructor({ baseUrl, token }){
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
  }