lua-cli 3.0.0-alpha.7 → 3.0.0-alpha.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.
- package/dist/services/auth.d.ts +8 -2
- package/dist/services/auth.js +35 -3
- package/package.json +1 -1
- package/template/env.example +5 -0
package/dist/services/auth.d.ts
CHANGED
|
@@ -13,9 +13,15 @@ import { UserData } from "../interfaces/admin.js";
|
|
|
13
13
|
*/
|
|
14
14
|
export declare function saveApiKey(apiKey: string): Promise<void>;
|
|
15
15
|
/**
|
|
16
|
-
* Loads API key from
|
|
16
|
+
* Loads API key from multiple sources in priority order:
|
|
17
|
+
* 1. Secure system keychain (macOS Keychain, Windows Credential Vault, Linux libsecret)
|
|
18
|
+
* 2. LUA_API_KEY environment variable
|
|
19
|
+
* 3. LUA_API_KEY from .env file
|
|
17
20
|
*
|
|
18
|
-
*
|
|
21
|
+
* This fallback mechanism allows the CLI to work in CI/CD environments where
|
|
22
|
+
* keychain access isn't available.
|
|
23
|
+
*
|
|
24
|
+
* @returns Promise resolving to API key or null if not found in any source
|
|
19
25
|
*/
|
|
20
26
|
export declare function loadApiKey(): Promise<string | null>;
|
|
21
27
|
/**
|
package/dist/services/auth.js
CHANGED
|
@@ -22,12 +22,44 @@ export async function saveApiKey(apiKey) {
|
|
|
22
22
|
await keytar.setPassword(KEYTAR_SERVICE, KEYTAR_ACCOUNT, apiKey);
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
|
-
* Loads API key from
|
|
25
|
+
* Loads API key from multiple sources in priority order:
|
|
26
|
+
* 1. Secure system keychain (macOS Keychain, Windows Credential Vault, Linux libsecret)
|
|
27
|
+
* 2. LUA_API_KEY environment variable
|
|
28
|
+
* 3. LUA_API_KEY from .env file
|
|
26
29
|
*
|
|
27
|
-
*
|
|
30
|
+
* This fallback mechanism allows the CLI to work in CI/CD environments where
|
|
31
|
+
* keychain access isn't available.
|
|
32
|
+
*
|
|
33
|
+
* @returns Promise resolving to API key or null if not found in any source
|
|
28
34
|
*/
|
|
29
35
|
export async function loadApiKey() {
|
|
30
|
-
|
|
36
|
+
// Priority 1: Check secure system keychain
|
|
37
|
+
const keychainKey = await keytar.getPassword(KEYTAR_SERVICE, KEYTAR_ACCOUNT);
|
|
38
|
+
if (keychainKey) {
|
|
39
|
+
return keychainKey;
|
|
40
|
+
}
|
|
41
|
+
// Priority 2: Check environment variable
|
|
42
|
+
if (process.env.LUA_API_KEY) {
|
|
43
|
+
return process.env.LUA_API_KEY;
|
|
44
|
+
}
|
|
45
|
+
// Priority 3: Check .env file
|
|
46
|
+
try {
|
|
47
|
+
const fs = await import('fs');
|
|
48
|
+
const path = await import('path');
|
|
49
|
+
const envPath = path.join(process.cwd(), '.env');
|
|
50
|
+
if (fs.existsSync(envPath)) {
|
|
51
|
+
const envContent = fs.readFileSync(envPath, 'utf8');
|
|
52
|
+
const match = envContent.match(/^LUA_API_KEY=(.+)$/m);
|
|
53
|
+
if (match && match[1]) {
|
|
54
|
+
// Remove quotes if present
|
|
55
|
+
return match[1].trim().replace(/^["']|["']$/g, '');
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
// Silently fail if .env file can't be read
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
31
63
|
}
|
|
32
64
|
/**
|
|
33
65
|
* Deletes API key from secure system keychain.
|
package/package.json
CHANGED
package/template/env.example
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
# Example environment variables file
|
|
2
2
|
# Copy this to .env and update with your actual API keys
|
|
3
3
|
|
|
4
|
+
# Lua API Key (optional - fallback if not in keychain)
|
|
5
|
+
# Use this for CI/CD environments or if you prefer .env over keychain
|
|
6
|
+
# Priority: 1. Keychain, 2. Environment variable, 3. .env file
|
|
7
|
+
# LUA_API_KEY=your-lua-api-key-here
|
|
8
|
+
|
|
4
9
|
# OpenAI API Key (for AI tools)
|
|
5
10
|
OPENAI_API_KEY=your-openai-api-key-here
|
|
6
11
|
|