@theholocron/http-client 1.3.2 → 1.3.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 +40 -40
- package/dist/index.mjs +29 -29
- package/package.json +7 -6
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,43 @@
|
|
|
1
|
+
//#region src/auth-resolver.d.ts
|
|
2
|
+
declare class AuthError extends Error {
|
|
3
|
+
name: string;
|
|
4
|
+
}
|
|
5
|
+
interface ResolveTokenInput {
|
|
6
|
+
/** From `--token` CLI flag. */
|
|
7
|
+
cliToken?: string;
|
|
8
|
+
/** Env vars; passed in for testability. Defaults to `process.env`. */
|
|
9
|
+
env?: NodeJS.ProcessEnv;
|
|
10
|
+
/** Keyring lookup fn; passed in for testability. */
|
|
11
|
+
keyring?: (provider: string) => string | null;
|
|
12
|
+
}
|
|
13
|
+
interface ResolveTokenConfig {
|
|
14
|
+
/** HOLOCRON_* env var (e.g. `"HOLOCRON_GH_TOKEN"`). */
|
|
15
|
+
envName: string;
|
|
16
|
+
/** Vendor's own env var (e.g. `"GITHUB_TOKEN"`). */
|
|
17
|
+
vendorEnvName: string;
|
|
18
|
+
/** Keyring service key (e.g. `"github"`). */
|
|
19
|
+
keyringService: string;
|
|
20
|
+
/** Full error message shown when no token is found. */
|
|
21
|
+
errorMessage: string;
|
|
22
|
+
/** Keyring backend — injected by the CLI layer. Defaults to no-op. */
|
|
23
|
+
getKeyringToken?: (provider: string) => string | null;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Returns a `resolveToken(input?)` function wired to the given env vars
|
|
27
|
+
* and keyring service. Plugins call this once at module level:
|
|
28
|
+
*
|
|
29
|
+
* ```ts
|
|
30
|
+
* export const resolveToken = createResolveToken({
|
|
31
|
+
* envName: "HOLOCRON_GITHUB_TOKEN",
|
|
32
|
+
* vendorEnvName: "GITHUB_TOKEN",
|
|
33
|
+
* keyringService: "github",
|
|
34
|
+
* errorMessage: "no GitHub token found ...",
|
|
35
|
+
* getKeyringToken, // injected from @theholocron/cli
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
declare function createResolveToken(config: ResolveTokenConfig): (input?: ResolveTokenInput) => string;
|
|
40
|
+
//#endregion
|
|
1
41
|
//#region src/errors.d.ts
|
|
2
42
|
/**
|
|
3
43
|
* Surfaced from every capability call that hits a vendor API. Wraps
|
|
@@ -52,44 +92,4 @@ interface RestClient {
|
|
|
52
92
|
}
|
|
53
93
|
declare function createRestClient(config: RestClientConfig): RestClient;
|
|
54
94
|
//#endregion
|
|
55
|
-
//#region src/auth-resolver.d.ts
|
|
56
|
-
declare class AuthError extends Error {
|
|
57
|
-
name: string;
|
|
58
|
-
}
|
|
59
|
-
interface ResolveTokenInput {
|
|
60
|
-
/** From `--token` CLI flag. */
|
|
61
|
-
cliToken?: string;
|
|
62
|
-
/** Env vars; passed in for testability. Defaults to `process.env`. */
|
|
63
|
-
env?: NodeJS.ProcessEnv;
|
|
64
|
-
/** Keyring lookup fn; passed in for testability. */
|
|
65
|
-
keyring?: (provider: string) => string | null;
|
|
66
|
-
}
|
|
67
|
-
interface ResolveTokenConfig {
|
|
68
|
-
/** HOLOCRON_* env var (e.g. `"HOLOCRON_GH_TOKEN"`). */
|
|
69
|
-
envName: string;
|
|
70
|
-
/** Vendor's own env var (e.g. `"GITHUB_TOKEN"`). */
|
|
71
|
-
vendorEnvName: string;
|
|
72
|
-
/** Keyring service key (e.g. `"github"`). */
|
|
73
|
-
keyringService: string;
|
|
74
|
-
/** Full error message shown when no token is found. */
|
|
75
|
-
errorMessage: string;
|
|
76
|
-
/** Keyring backend — injected by the CLI layer. Defaults to no-op. */
|
|
77
|
-
getKeyringToken?: (provider: string) => string | null;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Returns a `resolveToken(input?)` function wired to the given env vars
|
|
81
|
-
* and keyring service. Plugins call this once at module level:
|
|
82
|
-
*
|
|
83
|
-
* ```ts
|
|
84
|
-
* export const resolveToken = createResolveToken({
|
|
85
|
-
* envName: "HOLOCRON_GITHUB_TOKEN",
|
|
86
|
-
* vendorEnvName: "GITHUB_TOKEN",
|
|
87
|
-
* keyringService: "github",
|
|
88
|
-
* errorMessage: "no GitHub token found ...",
|
|
89
|
-
* getKeyringToken, // injected from @theholocron/cli
|
|
90
|
-
* });
|
|
91
|
-
* ```
|
|
92
|
-
*/
|
|
93
|
-
declare function createResolveToken(config: ResolveTokenConfig): (input?: ResolveTokenInput) => string;
|
|
94
|
-
//#endregion
|
|
95
95
|
export { AuthError, ProviderApiError, type RequestOptions, type ResolveTokenConfig, type ResolveTokenInput, type RestClient, type RestClientConfig, createResolveToken, createRestClient };
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,32 @@
|
|
|
1
|
+
//#region src/auth-resolver.ts
|
|
2
|
+
var AuthError = class extends Error {
|
|
3
|
+
name = "AuthError";
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Returns a `resolveToken(input?)` function wired to the given env vars
|
|
7
|
+
* and keyring service. Plugins call this once at module level:
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* export const resolveToken = createResolveToken({
|
|
11
|
+
* envName: "HOLOCRON_GITHUB_TOKEN",
|
|
12
|
+
* vendorEnvName: "GITHUB_TOKEN",
|
|
13
|
+
* keyringService: "github",
|
|
14
|
+
* errorMessage: "no GitHub token found ...",
|
|
15
|
+
* getKeyringToken, // injected from @theholocron/cli
|
|
16
|
+
* });
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
function createResolveToken(config) {
|
|
20
|
+
const defaultKeyring = config.getKeyringToken ?? (() => null);
|
|
21
|
+
return function resolveToken(input = {}) {
|
|
22
|
+
const env = input.env ?? process.env;
|
|
23
|
+
const keyring = input.keyring ?? defaultKeyring;
|
|
24
|
+
const token = input.cliToken || env[config.envName] || env[config.vendorEnvName] || keyring(config.keyringService);
|
|
25
|
+
if (!token) throw new AuthError(config.errorMessage);
|
|
26
|
+
return token;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
1
30
|
//#region src/errors.ts
|
|
2
31
|
/**
|
|
3
32
|
* Surfaced from every capability call that hits a vendor API. Wraps
|
|
@@ -60,33 +89,4 @@ function createRestClient(config) {
|
|
|
60
89
|
};
|
|
61
90
|
}
|
|
62
91
|
//#endregion
|
|
63
|
-
//#region src/auth-resolver.ts
|
|
64
|
-
var AuthError = class extends Error {
|
|
65
|
-
name = "AuthError";
|
|
66
|
-
};
|
|
67
|
-
/**
|
|
68
|
-
* Returns a `resolveToken(input?)` function wired to the given env vars
|
|
69
|
-
* and keyring service. Plugins call this once at module level:
|
|
70
|
-
*
|
|
71
|
-
* ```ts
|
|
72
|
-
* export const resolveToken = createResolveToken({
|
|
73
|
-
* envName: "HOLOCRON_GITHUB_TOKEN",
|
|
74
|
-
* vendorEnvName: "GITHUB_TOKEN",
|
|
75
|
-
* keyringService: "github",
|
|
76
|
-
* errorMessage: "no GitHub token found ...",
|
|
77
|
-
* getKeyringToken, // injected from @theholocron/cli
|
|
78
|
-
* });
|
|
79
|
-
* ```
|
|
80
|
-
*/
|
|
81
|
-
function createResolveToken(config) {
|
|
82
|
-
const defaultKeyring = config.getKeyringToken ?? (() => null);
|
|
83
|
-
return function resolveToken(input = {}) {
|
|
84
|
-
const env = input.env ?? process.env;
|
|
85
|
-
const keyring = input.keyring ?? defaultKeyring;
|
|
86
|
-
const token = input.cliToken || env[config.envName] || env[config.vendorEnvName] || keyring(config.keyringService);
|
|
87
|
-
if (!token) throw new AuthError(config.errorMessage);
|
|
88
|
-
return token;
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
//#endregion
|
|
92
92
|
export { AuthError, ProviderApiError, createResolveToken, createRestClient };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theholocron/http-client",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.4",
|
|
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",
|
|
@@ -43,16 +43,17 @@
|
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@types/node": "^26.1.1",
|
|
46
|
-
"@theholocron/eslint-config": "^7.
|
|
47
|
-
"@theholocron/tsconfig": "^7.
|
|
48
|
-
"@theholocron/tsdown-config": "^7.
|
|
49
|
-
"@theholocron/vitest-config": "^7.
|
|
46
|
+
"@theholocron/eslint-config": "^7.6.0",
|
|
47
|
+
"@theholocron/tsconfig": "^7.4.1",
|
|
48
|
+
"@theholocron/tsdown-config": "^7.4.1",
|
|
49
|
+
"@theholocron/vitest-config": "^7.4.1",
|
|
50
50
|
"@vitest/coverage-v8": "^4.1.10",
|
|
51
51
|
"@vitest/eslint-plugin": "^1.6.23",
|
|
52
52
|
"eslint": "^10.7.0",
|
|
53
53
|
"eslint-plugin-n": "^18.2.2",
|
|
54
|
+
"eslint-plugin-simple-import-sort": "^14.0.0",
|
|
54
55
|
"globals": "^17.7.0",
|
|
55
|
-
"tsdown": "^0.22.
|
|
56
|
+
"tsdown": "^0.22.13",
|
|
56
57
|
"typescript": "^5.9.3",
|
|
57
58
|
"vitest": "^4.1.10"
|
|
58
59
|
},
|