@argos-ci/api-client 0.30.0 → 0.31.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/dist/index.d.mts CHANGED
@@ -10226,12 +10226,20 @@ declare class APIError extends Error {
10226
10226
  //#endregion
10227
10227
  //#region src/index.d.ts
10228
10228
  type ArgosAPIClient = ReturnType<typeof createClient>;
10229
+ /**
10230
+ * A `User-Agent` value, or a resolver for it. The resolver may be async and is
10231
+ * called per request, so a caller that only learns its identity asynchronously
10232
+ * (the CLI detecting the coding agent driving it) does not have to await that
10233
+ * before it can build a client.
10234
+ */
10235
+ type UserAgentOption = string | (() => string | undefined | Promise<string | undefined>);
10229
10236
  /**
10230
10237
  * Create Argos API client.
10231
10238
  */
10232
10239
  declare function createClient(options?: {
10233
10240
  baseUrl?: string;
10234
10241
  authToken?: string;
10242
+ userAgent?: UserAgentOption;
10235
10243
  }): import("openapi-fetch").Client<paths, `${string}/${string}`>;
10236
10244
  /**
10237
10245
  * Format an API error into a human-readable message.
@@ -10249,4 +10257,4 @@ declare function formatAPIError(error: unknown, response?: Response): string;
10249
10257
  */
10250
10258
  declare function throwAPIError(error: unknown, response?: Response): never;
10251
10259
  //#endregion
10252
- export { APIError, ArgosAPIClient, schema_d_exports as ArgosAPISchema, createClient, formatAPIError, throwAPIError };
10260
+ export { APIError, ArgosAPIClient, schema_d_exports as ArgosAPISchema, UserAgentOption, createClient, formatAPIError, throwAPIError };
package/dist/index.mjs CHANGED
@@ -71,14 +71,28 @@ var schema_exports = /* @__PURE__ */ __exportAll({});
71
71
  //#endregion
72
72
  //#region src/index.ts
73
73
  /**
74
+ * Wrap {@link apiFetch} so every request carries a `User-Agent`.
75
+ *
76
+ * The header is set on the request openapi-fetch just built for this call — no
77
+ * one else observes it — and `apiFetch` copies the headers before retrying, so
78
+ * every attempt keeps the value.
79
+ */
80
+ function createUserAgentFetch(userAgent) {
81
+ return async (input, options) => {
82
+ const value = typeof userAgent === "function" ? await userAgent() : userAgent;
83
+ if (value) input.headers.set("user-agent", value);
84
+ return apiFetch(input, options);
85
+ };
86
+ }
87
+ /**
74
88
  * Create Argos API client.
75
89
  */
76
90
  function createClient(options) {
77
- const { baseUrl, authToken } = options || {};
91
+ const { baseUrl, authToken, userAgent } = options || {};
78
92
  return createFetchClient({
79
93
  baseUrl: baseUrl || "https://api.argos-ci.com/v2/",
80
94
  headers: { Authorization: authToken ? `Bearer ${authToken}` : void 0 },
81
- fetch: apiFetch
95
+ fetch: userAgent ? createUserAgentFetch(userAgent) : apiFetch
82
96
  });
83
97
  }
84
98
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@argos-ci/api-client",
3
3
  "description": "Argos API Client library.",
4
- "version": "0.30.0",
4
+ "version": "0.31.0",
5
5
  "author": "Smooth Code",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -54,5 +54,5 @@
54
54
  "openapi-fetch": "^0.17.0",
55
55
  "p-retry": "^8.0.0"
56
56
  },
57
- "gitHead": "222412bc6a73428b03c094bc230d74ed47038c76"
57
+ "gitHead": "180580eb5a263a65ed15cbd18cdd98d39f3a5325"
58
58
  }