@agilecustoms/envctl 1.18.0 → 1.18.2
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.
|
@@ -38,8 +38,15 @@ export class HttpClient {
|
|
|
38
38
|
}
|
|
39
39
|
options.method = options.method || 'GET';
|
|
40
40
|
options.headers = headers;
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
if (logger.isDebugEnabled()) {
|
|
42
|
+
const debugHeaders = Object.fromEntries(headers.entries());
|
|
43
|
+
const auth = debugHeaders['authorization'];
|
|
44
|
+
if (auth) {
|
|
45
|
+
debugHeaders['authorization'] = auth.slice(0, -2).replace(/./g, '*') + auth.slice(-2);
|
|
46
|
+
}
|
|
47
|
+
const reqJson = JSON.stringify({ ...options, headers: debugHeaders });
|
|
48
|
+
logger.debug(`--> ${options.method} ${url} ${reqJson}`);
|
|
49
|
+
}
|
|
43
50
|
let response;
|
|
44
51
|
try {
|
|
45
52
|
response = await fetch(url, options);
|
package/dist/logger.js
CHANGED
|
@@ -6,6 +6,9 @@ export class Logger {
|
|
|
6
6
|
this.now = now;
|
|
7
7
|
this.verbose = verbose;
|
|
8
8
|
}
|
|
9
|
+
isDebugEnabled() {
|
|
10
|
+
return this.verbose;
|
|
11
|
+
}
|
|
9
12
|
debug(msg) {
|
|
10
13
|
this.log('debug', msg);
|
|
11
14
|
}
|
|
@@ -22,7 +25,7 @@ export class Logger {
|
|
|
22
25
|
const date = new Date(this.now()).toISOString();
|
|
23
26
|
const detailedMessage = `${date} [${level}] ${msg}`;
|
|
24
27
|
this.buffer.push(detailedMessage);
|
|
25
|
-
if (!this.
|
|
28
|
+
if (!this.isDebugEnabled() && level === 'debug') {
|
|
26
29
|
return;
|
|
27
30
|
}
|
|
28
31
|
const method = console[level];
|
|
@@ -2,18 +2,18 @@ import * as fs from 'node:fs';
|
|
|
2
2
|
import * as os from 'node:os';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import { KnownException } from '../exceptions.js';
|
|
5
|
-
const CONFIG_DIR = path.join(os.homedir(), '.envctl');
|
|
6
5
|
export const DEFAULT_HOST = 'cli.maintenance.agilecustoms.com';
|
|
7
|
-
var EnvKey;
|
|
6
|
+
export var EnvKey;
|
|
8
7
|
(function (EnvKey) {
|
|
9
8
|
EnvKey["API_KEY"] = "ENVCTL_API_KEY";
|
|
9
|
+
EnvKey["HOME"] = "ENVCTL_HOME";
|
|
10
10
|
EnvKey["PROFILE"] = "ENVCTL_PROFILE";
|
|
11
11
|
})(EnvKey || (EnvKey = {}));
|
|
12
12
|
function env(key) {
|
|
13
13
|
return process.env[key];
|
|
14
14
|
}
|
|
15
|
-
function
|
|
16
|
-
return
|
|
15
|
+
function configDir() {
|
|
16
|
+
return env(EnvKey.HOME) || path.join(os.homedir(), '.envctl');
|
|
17
17
|
}
|
|
18
18
|
export class ConfigService {
|
|
19
19
|
config;
|
|
@@ -24,7 +24,7 @@ export class ConfigService {
|
|
|
24
24
|
throw new Error('load config second time?');
|
|
25
25
|
const customProfile = profile || env(EnvKey.PROFILE);
|
|
26
26
|
profile = customProfile || 'default';
|
|
27
|
-
const configPath = path.join(
|
|
27
|
+
const configPath = path.join(configDir(), `${profile}.json`);
|
|
28
28
|
if (fs.existsSync(configPath)) {
|
|
29
29
|
const data = fs.readFileSync(configPath, 'utf-8');
|
|
30
30
|
this.config = JSON.parse(data);
|
|
@@ -37,15 +37,15 @@ export class ConfigService {
|
|
|
37
37
|
saveConfig(profile, config) {
|
|
38
38
|
const mergedConfig = { ...this.loadConfig(profile, false), ...config };
|
|
39
39
|
const data = JSON.stringify(mergedConfig, null, 2);
|
|
40
|
-
fs.mkdirSync(
|
|
41
|
-
const configPath = path.join(
|
|
40
|
+
fs.mkdirSync(configDir(), { recursive: true });
|
|
41
|
+
const configPath = path.join(configDir(), `${profile}.json`);
|
|
42
42
|
fs.writeFileSync(configPath, data);
|
|
43
43
|
}
|
|
44
|
-
init(profile) {
|
|
44
|
+
init(profile = undefined) {
|
|
45
45
|
this.loadConfig(profile);
|
|
46
46
|
const apiKey = this.getApiKey();
|
|
47
47
|
if (!apiKey) {
|
|
48
|
-
if (
|
|
48
|
+
if (!!process.env['CI']) {
|
|
49
49
|
throw new KnownException('API key is missing, set env variable ' + EnvKey.API_KEY);
|
|
50
50
|
}
|
|
51
51
|
throw new KnownException('API key is missing, call \'envctl configure\' or set env variable ' + EnvKey.API_KEY);
|