highspot-cli 0.2.0 → 0.2.1
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 +11 -0
- package/dist/lib/api.js +1 -2
- package/dist/lib/command.js +1 -1
- package/dist/lib/config.js +34 -8
- package/dist/lib/help.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -31,6 +31,12 @@ export HIGHSPOT_API_KEY_ID=hs_key_id_xxx
|
|
|
31
31
|
export HIGHSPOT_API_KEY_SECRET=hs_key_secret_xxx
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
+
Or provide a precomputed Basic auth header directly:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
export HIGHSPOT_BASIC_AUTH="Basic <base64(id:secret)>"
|
|
38
|
+
```
|
|
39
|
+
|
|
34
40
|
Optional:
|
|
35
41
|
|
|
36
42
|
```bash
|
|
@@ -44,6 +50,10 @@ It is not implied by the API key:
|
|
|
44
50
|
- `hs-user` sets an explicit user context for requests where impersonation is needed.
|
|
45
51
|
- CLI flag precedence still applies, so `--hs-user` overrides `HIGHSPOT_HS_USER`.
|
|
46
52
|
|
|
53
|
+
Auth precedence:
|
|
54
|
+
- `HIGHSPOT_BASIC_AUTH` is used directly when set.
|
|
55
|
+
- Otherwise, `HIGHSPOT_API_KEY_ID` + `HIGHSPOT_API_KEY_SECRET` are used to compute `Authorization: Basic ...`.
|
|
56
|
+
|
|
47
57
|
## Config Files
|
|
48
58
|
|
|
49
59
|
Config precedence (highest to lowest):
|
|
@@ -63,6 +73,7 @@ Example `.highspot-cli.json`:
|
|
|
63
73
|
"maxRetries": 3,
|
|
64
74
|
"retryDelayMs": 1200,
|
|
65
75
|
"timeoutMs": 30000,
|
|
76
|
+
"basicAuth": "Basic <base64(id:secret)>",
|
|
66
77
|
"apiKeyId": "hs_key_id_xxx",
|
|
67
78
|
"apiKeySecret": "hs_key_secret_xxx"
|
|
68
79
|
}
|
package/dist/lib/api.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Buffer } from "node:buffer";
|
|
2
1
|
const TEXTUAL_CONTENT_TYPE_HINTS = [
|
|
3
2
|
"application/xml",
|
|
4
3
|
"application/xhtml+xml",
|
|
@@ -40,7 +39,7 @@ export class HighspotClient {
|
|
|
40
39
|
#retryDelayMs;
|
|
41
40
|
#timeoutMs;
|
|
42
41
|
constructor(config) {
|
|
43
|
-
this.#authorizationHeader =
|
|
42
|
+
this.#authorizationHeader = config.authorizationHeader;
|
|
44
43
|
this.#endpoint = sanitizeEndpoint(config.endpoint);
|
|
45
44
|
this.#hsUser = config.hsUser;
|
|
46
45
|
this.#maxRetries = config.maxRetries;
|
package/dist/lib/command.js
CHANGED
|
@@ -54,7 +54,7 @@ export class BaseCommand extends Command {
|
|
|
54
54
|
if (error instanceof ConfigError) {
|
|
55
55
|
writeError(mode, {
|
|
56
56
|
error: error.message,
|
|
57
|
-
hint: "Set HIGHSPOT_API_KEY_ID and HIGHSPOT_API_KEY_SECRET, or configure .highspot-cli.json.",
|
|
57
|
+
hint: "Set HIGHSPOT_BASIC_AUTH, or set HIGHSPOT_API_KEY_ID and HIGHSPOT_API_KEY_SECRET, or configure .highspot-cli.json.",
|
|
58
58
|
});
|
|
59
59
|
this.exit(2);
|
|
60
60
|
}
|
package/dist/lib/config.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
1
2
|
import { existsSync, readFileSync } from "node:fs";
|
|
2
3
|
import { join } from "node:path";
|
|
3
4
|
export class ConfigError extends Error {
|
|
@@ -43,6 +44,9 @@ function normalize(config) {
|
|
|
43
44
|
maxRetries: toInteger(config.maxRetries),
|
|
44
45
|
retryDelayMs: toInteger(config.retryDelayMs),
|
|
45
46
|
timeoutMs: toInteger(config.timeoutMs),
|
|
47
|
+
basicAuth: typeof config.basicAuth === "string"
|
|
48
|
+
? config.basicAuth.trim()
|
|
49
|
+
: undefined,
|
|
46
50
|
apiKeyId: typeof config.apiKeyId === "string" ? config.apiKeyId.trim() : undefined,
|
|
47
51
|
apiKeySecret: typeof config.apiKeySecret === "string"
|
|
48
52
|
? config.apiKeySecret.trim()
|
|
@@ -77,10 +81,38 @@ function fromEnv() {
|
|
|
77
81
|
maxRetries: process.env.HIGHSPOT_MAX_RETRIES,
|
|
78
82
|
retryDelayMs: process.env.HIGHSPOT_RETRY_DELAY_MS,
|
|
79
83
|
timeoutMs: process.env.HIGHSPOT_TIMEOUT_MS,
|
|
84
|
+
basicAuth: process.env.HIGHSPOT_BASIC_AUTH,
|
|
80
85
|
apiKeyId: process.env.HIGHSPOT_API_KEY_ID,
|
|
81
86
|
apiKeySecret: process.env.HIGHSPOT_API_KEY_SECRET,
|
|
82
87
|
});
|
|
83
88
|
}
|
|
89
|
+
function normalizeAuthorizationHeader(value) {
|
|
90
|
+
const trimmed = value?.trim();
|
|
91
|
+
if (!trimmed) {
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
if (/^Basic\s+/i.test(trimmed)) {
|
|
95
|
+
return trimmed;
|
|
96
|
+
}
|
|
97
|
+
return `Basic ${trimmed}`;
|
|
98
|
+
}
|
|
99
|
+
function resolveAuthorizationHeader(config) {
|
|
100
|
+
const explicitBasicAuth = normalizeAuthorizationHeader(config.basicAuth);
|
|
101
|
+
if (explicitBasicAuth) {
|
|
102
|
+
return explicitBasicAuth;
|
|
103
|
+
}
|
|
104
|
+
if (!config.apiKeyId && !config.apiKeySecret) {
|
|
105
|
+
throw new ConfigError("Missing auth configuration. Set HIGHSPOT_BASIC_AUTH, or set both HIGHSPOT_API_KEY_ID and HIGHSPOT_API_KEY_SECRET.");
|
|
106
|
+
}
|
|
107
|
+
if (!config.apiKeyId) {
|
|
108
|
+
throw new ConfigError("Missing HIGHSPOT_API_KEY_ID. Set HIGHSPOT_BASIC_AUTH, or configure apiKeyId with apiKeySecret in .highspot-cli.json.");
|
|
109
|
+
}
|
|
110
|
+
if (!config.apiKeySecret) {
|
|
111
|
+
throw new ConfigError("Missing HIGHSPOT_API_KEY_SECRET. Set HIGHSPOT_BASIC_AUTH, or configure apiKeySecret with apiKeyId in .highspot-cli.json.");
|
|
112
|
+
}
|
|
113
|
+
const token = Buffer.from(`${config.apiKeyId}:${config.apiKeySecret}`).toString("base64");
|
|
114
|
+
return `Basic ${token}`;
|
|
115
|
+
}
|
|
84
116
|
function overlay(base, next) {
|
|
85
117
|
return {
|
|
86
118
|
...base,
|
|
@@ -96,19 +128,13 @@ export function loadResolvedConfig(overrides = {}) {
|
|
|
96
128
|
const maxRetries = toInteger(config.maxRetries) ?? DEFAULT_MAX_RETRIES;
|
|
97
129
|
const retryDelayMs = toInteger(config.retryDelayMs) ?? DEFAULT_RETRY_DELAY_MS;
|
|
98
130
|
const timeoutMs = toInteger(config.timeoutMs) ?? DEFAULT_TIMEOUT_MS;
|
|
99
|
-
|
|
100
|
-
throw new ConfigError("Missing HIGHSPOT_API_KEY_ID. Set env vars or configure apiKeyId in .highspot-cli.json.");
|
|
101
|
-
}
|
|
102
|
-
if (!config.apiKeySecret) {
|
|
103
|
-
throw new ConfigError("Missing HIGHSPOT_API_KEY_SECRET. Set env vars or configure apiKeySecret in .highspot-cli.json.");
|
|
104
|
-
}
|
|
131
|
+
const authorizationHeader = resolveAuthorizationHeader(config);
|
|
105
132
|
return {
|
|
106
133
|
endpoint: config.endpoint || DEFAULT_ENDPOINT,
|
|
107
134
|
hsUser: config.hsUser,
|
|
108
135
|
maxRetries,
|
|
109
136
|
retryDelayMs,
|
|
110
137
|
timeoutMs,
|
|
111
|
-
|
|
112
|
-
apiKeySecret: config.apiKeySecret,
|
|
138
|
+
authorizationHeader,
|
|
113
139
|
};
|
|
114
140
|
}
|
package/dist/lib/help.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Help as OclifHelp } from "@oclif/core";
|
|
2
|
-
const AUTH_TEXT = "Requires HIGHSPOT_API_KEY_ID and HIGHSPOT_API_KEY_SECRET via env or config file.";
|
|
2
|
+
const AUTH_TEXT = "Requires HIGHSPOT_BASIC_AUTH, or HIGHSPOT_API_KEY_ID and HIGHSPOT_API_KEY_SECRET, via env or config file.";
|
|
3
3
|
const CONFIG_TEXT = "Precedence: flags > env > project config (.highspot-cli.json) > user config (~/.config/highspot-cli/config.json) > system config.";
|
|
4
4
|
export default class Help extends OclifHelp {
|
|
5
5
|
formatRoot() {
|