@boltic/cli 1.0.44-dev1.2 → 1.0.44-dev1.3

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.
@@ -1,5 +1,3 @@
1
- import keytar from "keytar";
2
-
3
1
  const SERVICE_NAME = "boltic-cli";
4
2
 
5
3
  // Mapping from credential keys to environment variable names.
@@ -13,20 +11,44 @@ const ENV_VAR_MAP = {
13
11
  environment: "BOLTIC_ENVIRONMENT",
14
12
  };
15
13
 
14
+ // Lazy-load keytar via dynamic import so that a missing native dependency
15
+ // (e.g. libsecret on Linux CI runners) is caught at call time rather than
16
+ // crashing the process at startup with ERR_DLOPEN_FAILED.
17
+ // The result is cached after the first attempt.
18
+ let _keytar;
19
+ let _keytarAttempted = false;
20
+
21
+ const getKeytar = async () => {
22
+ if (_keytarAttempted) return _keytar;
23
+ _keytarAttempted = true;
24
+ try {
25
+ _keytar = (await import("keytar")).default;
26
+ } catch {
27
+ // Native library not available (e.g. libsecret missing on CI runners).
28
+ _keytar = null;
29
+ }
30
+ return _keytar;
31
+ };
32
+
16
33
  /**
17
34
  * Store a secret value securely using keytar.
18
35
  * In CI/headless environments where keytar is unavailable, logs a warning
19
36
  * instead of throwing so that env-var-based auth can still be used.
20
- * @param {string} key - The key under which to store the secret
21
- * @param {string} value - The secret value to store
22
- * @returns {Promise<void>}
23
37
  */
24
38
  export const storeSecret = async (key, value) => {
39
+ const keytar = await getKeytar();
40
+ if (!keytar) {
41
+ console.warn(
42
+ `Warning: System keychain is unavailable. Could not store '${key}'.`
43
+ );
44
+ console.warn(
45
+ `In CI environments, set credentials via environment variables (e.g. BOLTIC_TOKEN, BOLTIC_ACCOUNT_ID).`
46
+ );
47
+ return;
48
+ }
25
49
  try {
26
50
  await keytar.setPassword(SERVICE_NAME, key, value);
27
51
  } catch (error) {
28
- // In headless/CI environments the OS keychain daemon is not available.
29
- // Warn instead of throwing so callers can still rely on env var fallback.
30
52
  console.warn(
31
53
  `Warning: Could not store '${key}' in system keychain: ${error.message}`
32
54
  );
@@ -38,26 +60,27 @@ export const storeSecret = async (key, value) => {
38
60
 
39
61
  /**
40
62
  * Retrieve a secret value. Tries keytar first; falls back to env vars
41
- * (BOLTIC_TOKEN, BOLTIC_PAT, BOLTIC_ACCOUNT_ID, etc.) when keytar is unavailable.
42
- * @param {string} key - The key of the secret to retrieve
43
- * @returns {Promise<string|null>} The secret value or null if not found
63
+ * (BOLTIC_TOKEN, BOLTIC_ACCOUNT_ID, etc.) when keytar is unavailable.
44
64
  */
45
65
  export const getSecret = async (key) => {
46
- try {
47
- const val = await keytar.getPassword(SERVICE_NAME, key);
48
- if (val !== null) return val;
49
- } catch {
50
- // keytar unavailable (CI/headless) fall through to env var
66
+ const keytar = await getKeytar();
67
+ if (keytar) {
68
+ try {
69
+ const val = await keytar.getPassword(SERVICE_NAME, key);
70
+ if (val !== null) return val;
71
+ } catch {
72
+ // keytar failed — fall through to env var
73
+ }
51
74
  }
52
75
  return process.env[ENV_VAR_MAP[key]] || null;
53
76
  };
54
77
 
55
78
  /**
56
- * Delete a secret value using keytar
57
- * @param {string} key - The key of the secret to delete
58
- * @returns {Promise<boolean>} True if deletion was successful
79
+ * Delete a secret value using keytar.
59
80
  */
60
81
  export const deleteSecret = async (key) => {
82
+ const keytar = await getKeytar();
83
+ if (!keytar) return false;
61
84
  try {
62
85
  return await keytar.deletePassword(SERVICE_NAME, key);
63
86
  } catch (error) {
@@ -69,14 +92,16 @@ export const deleteSecret = async (key) => {
69
92
  /**
70
93
  * Retrieve all secrets. Tries keytar first; falls back to env vars when
71
94
  * keytar is unavailable (e.g. GitHub Actions, Docker containers).
72
- * @returns {Promise<Array<{account: string, password: string}>|null>}
73
95
  */
74
96
  export const getAllSecrets = async () => {
75
- try {
76
- const keytarSecrets = await keytar.findCredentials(SERVICE_NAME);
77
- if (keytarSecrets && keytarSecrets.length > 0) return keytarSecrets;
78
- } catch {
79
- // keytar unavailable (CI/headless) fall through to env vars
97
+ const keytar = await getKeytar();
98
+ if (keytar) {
99
+ try {
100
+ const keytarSecrets = await keytar.findCredentials(SERVICE_NAME);
101
+ if (keytarSecrets && keytarSecrets.length > 0) return keytarSecrets;
102
+ } catch {
103
+ // keytar failed — fall through to env vars
104
+ }
80
105
  }
81
106
 
82
107
  // Build credential list from env vars
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@boltic/cli",
3
- "version": "1.0.44-dev1.2",
3
+ "version": "1.0.44-dev1.3",
4
4
  "description": "Professional CLI for interacting with the Boltic platform — create, manage, and publish integrations, serverless functions, workflows, MCPs, and more with enterprise-grade features and a seamless developer experience",
5
5
  "main": "index.js",
6
6
  "bin": {