orchestrix 16.1.2 → 16.1.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.
- package/lib/license.js +36 -4
- package/package.json +1 -1
package/lib/license.js
CHANGED
|
@@ -2,14 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const path = require('path');
|
|
5
|
+
const os = require('os');
|
|
5
6
|
const ui = require('./ui');
|
|
6
7
|
|
|
8
|
+
// License key format: orch_{tier}_{identifier}
|
|
9
|
+
// Examples: orch_live_xxx, orch_trial_xxx, ORCH-TEAM-xxx
|
|
10
|
+
const KEY_PATTERN = /^(orch_[a-z]+_[\w]+|ORCH-[A-Z]+-[\w-]+)$/;
|
|
11
|
+
|
|
12
|
+
function isValidKeyFormat(key) {
|
|
13
|
+
return KEY_PATTERN.test(key);
|
|
14
|
+
}
|
|
15
|
+
|
|
7
16
|
/**
|
|
8
17
|
* Resolve license key from multiple sources (priority order):
|
|
9
18
|
* 1. --key CLI flag
|
|
10
19
|
* 2. ORCHESTRIX_LICENSE_KEY env var
|
|
11
|
-
* 3. .
|
|
12
|
-
* 4.
|
|
20
|
+
* 3. .orchestrix-key hidden file (project dir → home dir)
|
|
21
|
+
* 4. .env.local file in cwd
|
|
22
|
+
* 5. Interactive prompt (saves to .orchestrix-key for next time)
|
|
13
23
|
*/
|
|
14
24
|
async function resolveKey(flags) {
|
|
15
25
|
// 1. CLI flag
|
|
@@ -23,7 +33,23 @@ async function resolveKey(flags) {
|
|
|
23
33
|
return process.env.ORCHESTRIX_LICENSE_KEY;
|
|
24
34
|
}
|
|
25
35
|
|
|
26
|
-
// 3. .
|
|
36
|
+
// 3. .orchestrix-key hidden file (project dir first, then home dir)
|
|
37
|
+
const keyLocations = [
|
|
38
|
+
path.join(process.cwd(), '.orchestrix-key'),
|
|
39
|
+
path.join(os.homedir(), '.orchestrix-key'),
|
|
40
|
+
];
|
|
41
|
+
for (const keyPath of keyLocations) {
|
|
42
|
+
if (fs.existsSync(keyPath)) {
|
|
43
|
+
const raw = fs.readFileSync(keyPath, 'utf-8').trim();
|
|
44
|
+
if (raw && isValidKeyFormat(raw)) {
|
|
45
|
+
const rel = keyPath.startsWith(process.cwd()) ? '.orchestrix-key' : '~/.orchestrix-key';
|
|
46
|
+
ui.info(`Using license key from ${rel}`);
|
|
47
|
+
return raw;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// 4. .env.local file
|
|
27
53
|
const envLocalPath = path.join(process.cwd(), '.env.local');
|
|
28
54
|
if (fs.existsSync(envLocalPath)) {
|
|
29
55
|
const content = fs.readFileSync(envLocalPath, 'utf-8');
|
|
@@ -34,11 +60,17 @@ async function resolveKey(flags) {
|
|
|
34
60
|
}
|
|
35
61
|
}
|
|
36
62
|
|
|
37
|
-
//
|
|
63
|
+
// 5. Interactive prompt
|
|
38
64
|
const key = await ui.prompt('Enter your Orchestrix license key');
|
|
39
65
|
if (!key) {
|
|
40
66
|
throw new Error('License key is required. Use --key <KEY> or set ORCHESTRIX_LICENSE_KEY env var.');
|
|
41
67
|
}
|
|
68
|
+
|
|
69
|
+
// Save to ~/.orchestrix-key for future use
|
|
70
|
+
const globalKeyPath = path.join(os.homedir(), '.orchestrix-key');
|
|
71
|
+
fs.writeFileSync(globalKeyPath, key + '\n', { mode: 0o600 });
|
|
72
|
+
ui.success(`License key saved to ~/.orchestrix-key`);
|
|
73
|
+
|
|
42
74
|
return key;
|
|
43
75
|
}
|
|
44
76
|
|