@theholocron/http-client 1.7.0 → 1.8.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/README.md +16 -1
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -41,7 +41,13 @@ const data = await client.request<{ id: string }>("/widgets/42");
|
|
|
41
41
|
|
|
42
42
|
### `createResolveToken(config)`
|
|
43
43
|
|
|
44
|
-
Factory for the standard
|
|
44
|
+
Factory for the standard token resolution used by all holocron plugins. Resolution order:
|
|
45
|
+
|
|
46
|
+
1. `cliToken` — value from `--token` CLI flag
|
|
47
|
+
2. `HOLOCRON_*` env var (e.g. `HOLOCRON_EXAMPLE_TOKEN`)
|
|
48
|
+
3. Vendor env var (e.g. `EXAMPLE_TOKEN`)
|
|
49
|
+
4. Keyring `<service>.<org>` — only when an org is active (see `ResolveTokenInput.org`)
|
|
50
|
+
5. Keyring `<service>` — unnamespaced fallback; backward-compatible default
|
|
45
51
|
|
|
46
52
|
```ts
|
|
47
53
|
import { createResolveToken, AuthError } from "@theholocron/http-client";
|
|
@@ -56,6 +62,15 @@ export const resolveToken = createResolveToken({
|
|
|
56
62
|
});
|
|
57
63
|
```
|
|
58
64
|
|
|
65
|
+
The returned `resolveToken(input?)` function accepts a `ResolveTokenInput`:
|
|
66
|
+
|
|
67
|
+
| Field | Type | Description |
|
|
68
|
+
| ---------- | -------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
69
|
+
| `cliToken` | `string` | Token from `--token` CLI flag; takes highest priority |
|
|
70
|
+
| `env` | `NodeJS.ProcessEnv` | Env vars to consult; defaults to `process.env` |
|
|
71
|
+
| `keyring` | `(provider: string) => string \| null` | Keyring lookup fn; defaults to the keyring injected by `@theholocron/cli` |
|
|
72
|
+
| `org` | `string` | Active org name; tries `keyring("<service>.<org>")` before the unnamespaced fallback. Also auto-read from `env["HOLOCRON_ORG"]` when not provided. |
|
|
73
|
+
|
|
59
74
|
### `ProviderApiError`
|
|
60
75
|
|
|
61
76
|
Thrown by `createRestClient` on non-2xx responses and transport failures. Carries `status` (HTTP code, `0` for transport failures) and `details` (raw response text).
|
package/dist/index.d.mts
CHANGED
|
@@ -9,6 +9,8 @@ interface ResolveTokenInput {
|
|
|
9
9
|
env?: NodeJS.ProcessEnv;
|
|
10
10
|
/** Keyring lookup fn; passed in for testability. */
|
|
11
11
|
keyring?: (provider: string) => string | null;
|
|
12
|
+
/** Active org name — drives namespaced keyring lookup (`<service>.<org>`). */
|
|
13
|
+
org?: string;
|
|
12
14
|
}
|
|
13
15
|
interface ResolveTokenConfig {
|
|
14
16
|
/** HOLOCRON_* env var (e.g. `"HOLOCRON_GH_TOKEN"`). */
|
package/dist/index.mjs
CHANGED
|
@@ -21,7 +21,8 @@ function createResolveToken(config) {
|
|
|
21
21
|
return function resolveToken(input = {}) {
|
|
22
22
|
const env = input.env ?? process.env;
|
|
23
23
|
const keyring = input.keyring ?? defaultKeyring;
|
|
24
|
-
const
|
|
24
|
+
const org = input.org ?? env["HOLOCRON_ORG"];
|
|
25
|
+
const token = input.cliToken || env[config.envName] || env[config.vendorEnvName] || (org ? keyring(`${config.keyringService}.${org}`) : null) || keyring(config.keyringService);
|
|
25
26
|
if (!token) throw new AuthError(config.errorMessage);
|
|
26
27
|
return token;
|
|
27
28
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theholocron/http-client",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "Shared HTTP primitives for theholocron — REST client factory, auth resolver, and error types",
|
|
5
5
|
"homepage": "https://github.com/theholocron/clients/tree/main/packages/http-client#readme",
|
|
6
6
|
"bugs": "https://github.com/theholocron/clients/issues",
|