@shadowob/cli 1.1.6 → 1.1.8

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.
@@ -8,6 +8,11 @@ import { homedir } from "os";
8
8
  import { dirname, join } from "path";
9
9
  var DEFAULT_CONFIG_DIR = join(homedir(), ".shadowob");
10
10
  var _DEFAULT_CONFIG_FILE = join(DEFAULT_CONFIG_DIR, "shadowob.config.json");
11
+ function expandEnvPlaceholders(value) {
12
+ return value.replace(/\$\{(?:env:)?([A-Za-z_][A-Za-z0-9_]*)\}/g, (_match, key) => {
13
+ return process.env[key] ?? "";
14
+ });
15
+ }
11
16
  var ConfigManager = class {
12
17
  config = null;
13
18
  configFile;
@@ -39,7 +44,12 @@ var ConfigManager = class {
39
44
  const config = await this.load();
40
45
  const profileName = name ?? config.currentProfile;
41
46
  if (!profileName) return null;
42
- return config.profiles[profileName] ?? null;
47
+ const profile = config.profiles[profileName];
48
+ if (!profile) return null;
49
+ return {
50
+ serverUrl: expandEnvPlaceholders(profile.serverUrl),
51
+ token: expandEnvPlaceholders(profile.token)
52
+ };
43
53
  }
44
54
  async getCurrentProfileName() {
45
55
  const config = await this.load();
@@ -110,21 +120,23 @@ var ConfigManager = class {
110
120
  }
111
121
  for (const [name, profile] of Object.entries(config.profiles)) {
112
122
  const profileResult = { valid: true };
113
- if (!profile.serverUrl) {
123
+ const serverUrl = expandEnvPlaceholders(profile.serverUrl);
124
+ const token = expandEnvPlaceholders(profile.token);
125
+ if (!serverUrl) {
114
126
  profileResult.valid = false;
115
127
  result.errors.push(`Profile "${name}" missing serverUrl`);
116
128
  } else {
117
129
  try {
118
- new URL(profile.serverUrl);
130
+ new URL(serverUrl);
119
131
  } catch {
120
132
  profileResult.valid = false;
121
- result.errors.push(`Profile "${name}" has invalid serverUrl: ${profile.serverUrl}`);
133
+ result.errors.push(`Profile "${name}" has invalid serverUrl: ${serverUrl}`);
122
134
  }
123
135
  }
124
- if (!profile.token) {
136
+ if (!token) {
125
137
  profileResult.valid = false;
126
138
  result.errors.push(`Profile "${name}" missing token`);
127
- } else if (!profile.token.includes(".")) {
139
+ } else if (!token.includes(".")) {
128
140
  result.warnings.push(`Profile "${name}" token does not look like a JWT`);
129
141
  }
130
142
  result.profileResults[name] = profileResult;
@@ -164,6 +176,12 @@ var ConfigManager = class {
164
176
  var configManager = new ConfigManager();
165
177
 
166
178
  // src/utils/client.ts
179
+ var DEFAULT_SERVER_URL = "https://shadowob.com";
180
+ function resolveServerFlag(value) {
181
+ const server = value ?? process.env.SHADOWOB_SERVER_ID;
182
+ if (!server) throw new Error("Missing server. Pass --server or set SHADOWOB_SERVER_ID.");
183
+ return server;
184
+ }
167
185
  async function getConfig(profile) {
168
186
  const config = await configManager.getProfile(profile);
169
187
  if (!config) {
@@ -251,6 +269,8 @@ async function handleCommand(fn, options, outputFn, errorFn) {
251
269
 
252
270
  export {
253
271
  configManager,
272
+ DEFAULT_SERVER_URL,
273
+ resolveServerFlag,
254
274
  getClient,
255
275
  getClientWithToken,
256
276
  getSocket,
@@ -1,4 +1,5 @@
1
1
  import {
2
+ DEFAULT_SERVER_URL,
2
3
  formatError,
3
4
  getClient,
4
5
  getClientWithToken,
@@ -10,9 +11,11 @@ import {
10
11
  parseNonNegativeInt,
11
12
  parsePositiveInt,
12
13
  parsePrice,
13
- requireOption
14
- } from "./chunk-E364BDQO.js";
14
+ requireOption,
15
+ resolveServerFlag
16
+ } from "./chunk-S6XCO6ZW.js";
15
17
  export {
18
+ DEFAULT_SERVER_URL,
16
19
  formatError,
17
20
  getClient,
18
21
  getClientWithToken,
@@ -24,5 +27,6 @@ export {
24
27
  parseNonNegativeInt,
25
28
  parsePositiveInt,
26
29
  parsePrice,
27
- requireOption
30
+ requireOption,
31
+ resolveServerFlag
28
32
  };