@theholocron/http-client 1.58.0-alpha.3 → 1.58.0-alpha.4

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
@@ -1,7 +1,10 @@
1
1
  import { ErrorSink, Logger } from "@theholocron/observability/core";
2
+ /** Thrown by a token resolver when no token was found in any source. */
2
3
  export declare class AuthError extends Error {
4
+ /** The error name, `AuthError`. */
3
5
  name: string;
4
6
  }
7
+ /** Where `resolveToken` looks for a token. */
5
8
  interface ResolveTokenInput {
6
9
  /** From `--token` CLI flag. */
7
10
  cliToken?: string;
@@ -12,6 +15,7 @@ interface ResolveTokenInput {
12
15
  /** Active org name — drives namespaced keyring lookup (`<service>.<org>`). */
13
16
  org?: string;
14
17
  }
18
+ /** How `createResolveToken` finds a vendor's token. */
15
19
  interface ResolveTokenConfig {
16
20
  /** HOLOCRON_* env var (e.g. `"HOLOCRON_GH_TOKEN"`). */
17
21
  envName: string;
@@ -26,8 +30,15 @@ interface ResolveTokenConfig {
26
30
  }
27
31
  /**
28
32
  * Returns a `resolveToken(input?)` function wired to the given env vars
29
- * and keyring service. Plugins call this once at module level:
33
+ * and keyring service. Plugins call this once at module level.
30
34
  *
35
+ * @remarks
36
+ * The resolver tries, in order: the `cliToken` input (the `--token` flag), the
37
+ * `HOLOCRON_*` env var, the vendor's own env var, the keyring entry
38
+ * `<service>.<org>` (only when an org is known), then the keyring entry
39
+ * `<service>`. It throws {@link AuthError} when none has a token.
40
+ *
41
+ * @example
31
42
  * ```ts
32
43
  * export const resolveToken = createResolveToken({
33
44
  * envName: "HOLOCRON_GITHUB_TOKEN",
@@ -45,11 +56,19 @@ export declare function createResolveToken(config: ResolveTokenConfig): (input?:
45
56
  * orchestrators can soft-skip rather than abort.
46
57
  */
47
58
  export declare class ProviderApiError extends Error {
59
+ /** The HTTP status code; `0` for a transport failure that got no response. */
48
60
  readonly status: number | undefined;
61
+ /** The raw response body as a string (not parsed JSON); `undefined` when there is none. */
49
62
  readonly details?: unknown | undefined;
63
+ /** The error name, `ProviderApiError`. */
50
64
  name: string;
51
- constructor(message: string, status: number | undefined, details?: unknown | undefined);
65
+ constructor(message: string,
66
+ /** The HTTP status code; `0` for a transport failure that got no response. */
67
+ status: number | undefined,
68
+ /** The raw response body as a string (not parsed JSON); `undefined` when there is none. */
69
+ details?: unknown | undefined);
52
70
  }
71
+ /** Settings for `createRestClient`. */
53
72
  interface RestClientConfig {
54
73
  /** Default base URL (e.g. "https://api.github.com"). */
55
74
  baseUrl: string;
@@ -104,8 +123,11 @@ interface RestClientConfig {
104
123
  */
105
124
  retryStatuses?: readonly number[];
106
125
  }
126
+ /** Options for one `RestClient.request` call. */
107
127
  interface RequestOptions {
128
+ /** The HTTP method. Defaults to `"GET"`. */
108
129
  method?: "GET" | "POST" | "PATCH" | "PUT" | "DELETE";
130
+ /** The request body; sent as JSON with a `content-type` header. Left out or `undefined`, no body is sent. */
109
131
  body?: unknown;
110
132
  /** Per-request query params, merged after `defaultQuery`. */
111
133
  query?: Record<string, string>;
@@ -118,16 +140,22 @@ interface RequestOptions {
118
140
  */
119
141
  onResponse?: (headers: Headers) => void;
120
142
  }
143
+ /** A JSON REST client bound to one vendor's base URL and credentials. */
121
144
  interface RestClient {
145
+ /** The base URL with any trailing slashes removed. */
122
146
  readonly baseUrl: string;
147
+ /** Sends a request to `path` and resolves with the parsed JSON body, or `undefined` for an empty or 204 response; rejects with a `ProviderApiError`. */
123
148
  request<T>(path: string, opts?: RequestOptions): Promise<T>;
124
149
  }
150
+ /** Creates a `RestClient` that sends the configured auth header and retries safe transport failures. */
125
151
  export declare function createRestClient(config: RestClientConfig): RestClient;
126
152
  /** A request about to be sent again after a transport failure, or an HTTP status the client was told to retry. */
127
153
  interface RetryEvent {
128
154
  /** The client's `vendor` label, e.g. `GitHub`. */
129
155
  vendor?: string;
156
+ /** The HTTP method of the request, such as `GET`. */
130
157
  method: string;
158
+ /** The request path, relative to the client's base URL. */
131
159
  path: string;
132
160
  /**
133
161
  * What went wrong (`ECONNRESET`, `UND_ERR_CONNECT_TIMEOUT`, or `HTTP 503` for a retried status); a failure with no
package/dist/index.mjs CHANGED
@@ -1,13 +1,22 @@
1
1
  import { createEnvLookup, firstEnv } from "@theholocron/env-utils/lookup";
2
2
  import { NoopErrorSink, NoopLogger } from "@theholocron/observability/core";
3
3
  // src/auth-resolver.ts
4
+ /** Thrown by a token resolver when no token was found in any source. */
4
5
  var AuthError = class extends Error {
6
+ /** The error name, `AuthError`. */
5
7
  name = "AuthError";
6
8
  };
7
9
  /**
8
10
  * Returns a `resolveToken(input?)` function wired to the given env vars
9
- * and keyring service. Plugins call this once at module level:
11
+ * and keyring service. Plugins call this once at module level.
10
12
  *
13
+ * @remarks
14
+ * The resolver tries, in order: the `cliToken` input (the `--token` flag), the
15
+ * `HOLOCRON_*` env var, the vendor's own env var, the keyring entry
16
+ * `<service>.<org>` (only when an org is known), then the keyring entry
17
+ * `<service>`. It throws {@link AuthError} when none has a token.
18
+ *
19
+ * @example
11
20
  * ```ts
12
21
  * export const resolveToken = createResolveToken({
13
22
  * envName: "HOLOCRON_GITHUB_TOKEN",
@@ -38,6 +47,7 @@ function createResolveToken(config) {
38
47
  var ProviderApiError = class extends Error {
39
48
  status;
40
49
  details;
50
+ /** The error name, `ProviderApiError`. */
41
51
  name = "ProviderApiError";
42
52
  constructor(message, status, details) {
43
53
  super(message);
@@ -123,6 +133,7 @@ function retriedNote(res, attempt) {
123
133
  const header = REQUEST_ID_HEADERS.find((name) => res.headers.has(name));
124
134
  return ` (after ${attempt + 1} attempts${header ? `; ${header}: ${res.headers.get(header)}` : ""})`;
125
135
  }
136
+ /** Creates a `RestClient` that sends the configured auth header and retries safe transport failures. */
126
137
  function createRestClient(config) {
127
138
  const fetchImpl = config.fetch ?? globalThis.fetch;
128
139
  const vendor = config.vendor ?? "";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/http-client",
3
- "version": "1.58.0-alpha.3",
3
+ "version": "1.58.0-alpha.4",
4
4
  "description": "Shared HTTP primitives for theholocron — REST client factory, auth resolver, and error types",
5
5
  "keywords": [
6
6
  "typescript",
@@ -36,7 +36,7 @@
36
36
  "dist"
37
37
  ],
38
38
  "dependencies": {
39
- "@theholocron/env-utils": "^1.16.1-alpha.1",
39
+ "@theholocron/env-utils": "^1.16.1-alpha.3",
40
40
  "@theholocron/observability": "^0.6.1-alpha.1"
41
41
  },
42
42
  "devDependencies": {
@@ -49,10 +49,10 @@
49
49
  "tsdown": "^0.23.3",
50
50
  "typescript": "^5.9.3",
51
51
  "vitest": "^5.0.5",
52
- "@theholocron/tsconfig": "^8.9.0-alpha.3",
53
- "@theholocron/tsdown-config": "^8.9.0-alpha.3",
54
- "@theholocron/eslint-config": "^8.9.0-alpha.3",
55
- "@theholocron/vitest-config": "^8.9.0-alpha.3"
52
+ "@theholocron/tsconfig": "^8.9.0-alpha.5",
53
+ "@theholocron/tsdown-config": "^8.9.0-alpha.5",
54
+ "@theholocron/eslint-config": "^8.9.0-alpha.5",
55
+ "@theholocron/vitest-config": "^8.9.0-alpha.5"
56
56
  },
57
57
  "peerDependencies": {
58
58
  "vitest": ">=4.0.0"