@ranger-testing/ranger-cli 2.0.5 → 2.0.6
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/build/cli.js +1 -914
- package/build/commands/addEnv.js +1 -1
- package/build/commands/authEncrypt.js +1 -36
- package/build/commands/clean.js +1 -1
- package/build/commands/config.js +1 -93
- package/build/commands/env.js +1 -98
- package/build/commands/feature.js +1 -653
- package/build/commands/hook.js +1 -33
- package/build/commands/hooks/autoPrompt.js +1 -32
- package/build/commands/hooks/disable.js +1 -33
- package/build/commands/hooks/enable.js +1 -58
- package/build/commands/hooks/exitPlanMode.js +1 -35
- package/build/commands/hooks/index.js +1 -12
- package/build/commands/hooks/output.js +1 -71
- package/build/commands/hooks/planReminder.js +1 -46
- package/build/commands/hooks/planStart.js +1 -30
- package/build/commands/hooks/postEdit.js +1 -43
- package/build/commands/hooks/preCompact.js +1 -30
- package/build/commands/hooks/sessionEnd.js +1 -25
- package/build/commands/hooks/sessionStart.js +1 -93
- package/build/commands/hooks/stopHook.js +1 -155
- package/build/commands/index.js +1 -12
- package/build/commands/login.js +1 -26
- package/build/commands/setupCi.js +1 -189
- package/build/commands/skillup.js +1 -80
- package/build/commands/start.js +1 -1
- package/build/commands/status.js +1 -198
- package/build/commands/update.js +1 -182
- package/build/commands/updateEnv.js +1 -1
- package/build/commands/useEnv.js +1 -1
- package/build/commands/utils/activeProfile.js +1 -76
- package/build/commands/utils/browserSessionsApi.js +1 -1
- package/build/commands/utils/claudeConfig.js +1 -73
- package/build/commands/utils/claudePlugin.js +1 -85
- package/build/commands/utils/crypto.js +1 -42
- package/build/commands/utils/desirePathLog.js +1 -139
- package/build/commands/utils/deviceAuth.js +1 -232
- package/build/commands/utils/environment.js +1 -65
- package/build/commands/utils/featureApi.js +1 -371
- package/build/commands/utils/featureReportGenerator.js +1 -204
- package/build/commands/utils/git.js +1 -44
- package/build/commands/utils/keychain.js +1 -1
- package/build/commands/utils/localAgentInstallationsApi.js +1 -1
- package/build/commands/utils/profileMessages.js +1 -8
- package/build/commands/utils/profileSetupBanner.js +1 -167
- package/build/commands/utils/rangerRoot.js +1 -60
- package/build/commands/utils/reportGenerator.js +1 -130
- package/build/commands/utils/retry.js +1 -25
- package/build/commands/utils/sessionCache.js +1 -299
- package/build/commands/utils/settings.js +1 -313
- package/build/commands/utils/skillContent.js +1 -28
- package/build/commands/utils/skills.js +1 -1
- package/build/commands/utils/telemetry.js +1 -254
- package/build/commands/utils/userApi.js +1 -32
- package/build/commands/utils/version.js +1 -62
- package/build/commands/verifyFeature.js +1 -1343
- package/build/commands/verifyInBrowser.js +1 -1
- package/package.json +1 -1
- package/build/cli.js.map +0 -1
- package/build/commands/addEnv.js.map +0 -1
- package/build/commands/authEncrypt.js.map +0 -1
- package/build/commands/clean.js.map +0 -1
- package/build/commands/config.js.map +0 -1
- package/build/commands/env.js.map +0 -1
- package/build/commands/feature.js.map +0 -1
- package/build/commands/hook.js.map +0 -1
- package/build/commands/hooks/autoPrompt.js.map +0 -1
- package/build/commands/hooks/disable.js.map +0 -1
- package/build/commands/hooks/enable.js.map +0 -1
- package/build/commands/hooks/exitPlanMode.js.map +0 -1
- package/build/commands/hooks/index.js.map +0 -1
- package/build/commands/hooks/output.js.map +0 -1
- package/build/commands/hooks/planReminder.js.map +0 -1
- package/build/commands/hooks/planStart.js.map +0 -1
- package/build/commands/hooks/postEdit.js.map +0 -1
- package/build/commands/hooks/preCompact.js.map +0 -1
- package/build/commands/hooks/sessionEnd.js.map +0 -1
- package/build/commands/hooks/sessionStart.js.map +0 -1
- package/build/commands/hooks/stopHook.js.map +0 -1
- package/build/commands/index.js.map +0 -1
- package/build/commands/login.js.map +0 -1
- package/build/commands/setupCi.js.map +0 -1
- package/build/commands/skillup.js.map +0 -1
- package/build/commands/start.js.map +0 -1
- package/build/commands/status.js.map +0 -1
- package/build/commands/update.js.map +0 -1
- package/build/commands/updateEnv.js.map +0 -1
- package/build/commands/useEnv.js.map +0 -1
- package/build/commands/utils/activeProfile.js.map +0 -1
- package/build/commands/utils/browserSessionsApi.js.map +0 -1
- package/build/commands/utils/claudeConfig.js.map +0 -1
- package/build/commands/utils/claudePlugin.js.map +0 -1
- package/build/commands/utils/crypto.js.map +0 -1
- package/build/commands/utils/desirePathLog.js.map +0 -1
- package/build/commands/utils/deviceAuth.js.map +0 -1
- package/build/commands/utils/environment.js.map +0 -1
- package/build/commands/utils/featureApi.js.map +0 -1
- package/build/commands/utils/featureReportGenerator.js.map +0 -1
- package/build/commands/utils/git.js.map +0 -1
- package/build/commands/utils/keychain.js.map +0 -1
- package/build/commands/utils/localAgentInstallationsApi.js.map +0 -1
- package/build/commands/utils/profileMessages.js.map +0 -1
- package/build/commands/utils/profileSetupBanner.js.map +0 -1
- package/build/commands/utils/rangerRoot.js.map +0 -1
- package/build/commands/utils/reportGenerator.js.map +0 -1
- package/build/commands/utils/retry.js.map +0 -1
- package/build/commands/utils/sessionCache.js.map +0 -1
- package/build/commands/utils/settings.js.map +0 -1
- package/build/commands/utils/skillContent.js.map +0 -1
- package/build/commands/utils/skills.js.map +0 -1
- package/build/commands/utils/telemetry.js.map +0 -1
- package/build/commands/utils/userApi.js.map +0 -1
- package/build/commands/utils/version.js.map +0 -1
- package/build/commands/verifyFeature.js.map +0 -1
- package/build/commands/verifyInBrowser.js.map +0 -1
|
@@ -1,232 +1 @@
|
|
|
1
|
-
import { exec } from 'child_process';
|
|
2
|
-
import { getCurrentEnvironment, ENVIRONMENT_CONFIGS, getApiBaseUrl, } from './environment.js';
|
|
3
|
-
import { storeToken, storeRefreshToken } from './keychain.js';
|
|
4
|
-
const WORKOS_DEVICE_AUTH_URL = 'https://api.workos.com/user_management/authorize/device';
|
|
5
|
-
const WORKOS_TOKEN_URL = 'https://api.workos.com/user_management/authenticate';
|
|
6
|
-
/**
|
|
7
|
-
* Request a device code from WorkOS for the device authorization flow.
|
|
8
|
-
*/
|
|
9
|
-
export async function requestDeviceCode(clientId) {
|
|
10
|
-
const response = await fetch(WORKOS_DEVICE_AUTH_URL, {
|
|
11
|
-
method: 'POST',
|
|
12
|
-
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
13
|
-
body: new URLSearchParams({
|
|
14
|
-
client_id: clientId,
|
|
15
|
-
}),
|
|
16
|
-
});
|
|
17
|
-
if (!response.ok) {
|
|
18
|
-
const text = await response.text();
|
|
19
|
-
throw new Error(`Failed to request device code: ${response.status} ${text}`);
|
|
20
|
-
}
|
|
21
|
-
return response.json();
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Poll WorkOS for token exchange after user authorizes the device.
|
|
25
|
-
* Resolves when the user completes auth, or rejects on expiry/error.
|
|
26
|
-
*/
|
|
27
|
-
export async function pollForTokens(clientId, deviceCode, interval, expiresIn) {
|
|
28
|
-
const deadline = Date.now() + expiresIn * 1000;
|
|
29
|
-
let pollInterval = interval * 1000;
|
|
30
|
-
while (Date.now() < deadline) {
|
|
31
|
-
await sleep(pollInterval);
|
|
32
|
-
const response = await fetch(WORKOS_TOKEN_URL, {
|
|
33
|
-
method: 'POST',
|
|
34
|
-
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
35
|
-
body: new URLSearchParams({
|
|
36
|
-
client_id: clientId,
|
|
37
|
-
device_code: deviceCode,
|
|
38
|
-
grant_type: 'urn:ietf:params:oauth:grant-type:device_code',
|
|
39
|
-
}),
|
|
40
|
-
});
|
|
41
|
-
if (response.ok) {
|
|
42
|
-
return response.json();
|
|
43
|
-
}
|
|
44
|
-
const body = await response.json();
|
|
45
|
-
if (body.error === 'authorization_pending') {
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
48
|
-
if (body.error === 'slow_down') {
|
|
49
|
-
pollInterval += 1000;
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
// expired_token, access_denied, or other terminal error
|
|
53
|
-
throw new Error(body.error_description || body.error || 'Authentication failed');
|
|
54
|
-
}
|
|
55
|
-
throw new Error('Device authorization timed out');
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Fetch the authenticated user's profile from the backend.
|
|
59
|
-
*/
|
|
60
|
-
async function fetchUserProfile(workosAccessToken) {
|
|
61
|
-
const apiBaseUrl = getApiBaseUrl();
|
|
62
|
-
try {
|
|
63
|
-
const res = await fetch(`${apiBaseUrl}/organization/me`, {
|
|
64
|
-
method: 'GET',
|
|
65
|
-
headers: { 'workos-token': workosAccessToken },
|
|
66
|
-
});
|
|
67
|
-
if (res.ok)
|
|
68
|
-
return res.json();
|
|
69
|
-
}
|
|
70
|
-
catch {
|
|
71
|
-
// ignore
|
|
72
|
-
}
|
|
73
|
-
return null;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Build a unique CLI API key name by checking existing keys and incrementing.
|
|
77
|
-
* First key: "Alice's CLI Key"
|
|
78
|
-
* Second key: "Alice's CLI Key (2)"
|
|
79
|
-
* Third key: "Alice's CLI Key (3)"
|
|
80
|
-
*/
|
|
81
|
-
function buildKeyName(baseName, existingKeys) {
|
|
82
|
-
const matching = existingKeys.filter((k) => k.name === baseName || k.name.startsWith(`${baseName} (`));
|
|
83
|
-
if (matching.length === 0)
|
|
84
|
-
return baseName;
|
|
85
|
-
return `${baseName} (${matching.length + 1})`;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Call the backend POST /api-keys endpoint to auto-provision an MCP API key,
|
|
89
|
-
* authenticated via the WorkOS access token.
|
|
90
|
-
*
|
|
91
|
-
* Names keys like "Alice's CLI Key", incrementing a number suffix if the user
|
|
92
|
-
* provisions multiple keys.
|
|
93
|
-
*/
|
|
94
|
-
export async function provisionApiKey(workosAccessToken) {
|
|
95
|
-
const apiBaseUrl = getApiBaseUrl();
|
|
96
|
-
const headers = {
|
|
97
|
-
'Content-Type': 'application/json',
|
|
98
|
-
'workos-token': workosAccessToken,
|
|
99
|
-
};
|
|
100
|
-
const profile = await fetchUserProfile(workosAccessToken);
|
|
101
|
-
const firstName = profile?.firstName || profile?.email?.split('@')[0];
|
|
102
|
-
const baseName = firstName ? `${firstName}'s CLI Key` : 'CLI Key';
|
|
103
|
-
// List existing keys to determine the right suffix
|
|
104
|
-
let existingKeys = [];
|
|
105
|
-
try {
|
|
106
|
-
const listRes = await fetch(`${apiBaseUrl}/api-keys`, {
|
|
107
|
-
method: 'GET',
|
|
108
|
-
headers,
|
|
109
|
-
});
|
|
110
|
-
if (listRes.ok) {
|
|
111
|
-
const data = await listRes.json();
|
|
112
|
-
existingKeys = data.apiKeys;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
catch {
|
|
116
|
-
// If listing fails, just use the base name
|
|
117
|
-
}
|
|
118
|
-
const keyName = buildKeyName(baseName, existingKeys);
|
|
119
|
-
const response = await fetch(`${apiBaseUrl}/api-keys`, {
|
|
120
|
-
method: 'POST',
|
|
121
|
-
headers,
|
|
122
|
-
body: JSON.stringify({
|
|
123
|
-
name: keyName,
|
|
124
|
-
scope: 'mcp:write',
|
|
125
|
-
}),
|
|
126
|
-
});
|
|
127
|
-
if (!response.ok) {
|
|
128
|
-
const text = await response.text();
|
|
129
|
-
throw new Error(`Failed to provision API key: ${response.status} ${text}`);
|
|
130
|
-
}
|
|
131
|
-
const data = await response.json();
|
|
132
|
-
return data.apiKey.token;
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Open a URL in the user's default browser.
|
|
136
|
-
*/
|
|
137
|
-
export function openBrowser(url) {
|
|
138
|
-
const platform = process.platform;
|
|
139
|
-
const cmd = platform === 'darwin'
|
|
140
|
-
? 'open'
|
|
141
|
-
: platform === 'win32'
|
|
142
|
-
? 'start'
|
|
143
|
-
: 'xdg-open';
|
|
144
|
-
exec(`${cmd} ${JSON.stringify(url)}`);
|
|
145
|
-
}
|
|
146
|
-
function decodeJwtPayload(token) {
|
|
147
|
-
const parts = token.split('.');
|
|
148
|
-
if (parts.length !== 3)
|
|
149
|
-
throw new Error('Invalid JWT format');
|
|
150
|
-
const payload = Buffer.from(parts[1], 'base64url').toString('utf-8');
|
|
151
|
-
return JSON.parse(payload);
|
|
152
|
-
}
|
|
153
|
-
async function selfServeSignup(accessToken) {
|
|
154
|
-
const apiBaseUrl = getApiBaseUrl();
|
|
155
|
-
const response = await fetch(`${apiBaseUrl}/organization/self-serve-signup`, {
|
|
156
|
-
method: 'POST',
|
|
157
|
-
headers: {
|
|
158
|
-
'Content-Type': 'application/json',
|
|
159
|
-
'workos-token': accessToken,
|
|
160
|
-
},
|
|
161
|
-
});
|
|
162
|
-
if (!response.ok) {
|
|
163
|
-
const text = await response.text();
|
|
164
|
-
throw new Error(`Failed to create organization: ${response.status} ${text}`);
|
|
165
|
-
}
|
|
166
|
-
return response.json();
|
|
167
|
-
}
|
|
168
|
-
async function refreshTokenWithOrg(clientId, refreshToken, organizationId) {
|
|
169
|
-
const response = await fetch(WORKOS_TOKEN_URL, {
|
|
170
|
-
method: 'POST',
|
|
171
|
-
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
172
|
-
body: new URLSearchParams({
|
|
173
|
-
client_id: clientId,
|
|
174
|
-
grant_type: 'refresh_token',
|
|
175
|
-
refresh_token: refreshToken,
|
|
176
|
-
organization_id: organizationId,
|
|
177
|
-
}),
|
|
178
|
-
});
|
|
179
|
-
if (!response.ok) {
|
|
180
|
-
const text = await response.text();
|
|
181
|
-
throw new Error(`Failed to refresh token with org: ${response.status} ${text}`);
|
|
182
|
-
}
|
|
183
|
-
return response.json();
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* Run the full device authorization flow:
|
|
187
|
-
* 1. Request device code from WorkOS
|
|
188
|
-
* 2. Open browser for user to authenticate
|
|
189
|
-
* 3. Poll for tokens
|
|
190
|
-
* 4. If no org_id in token, run self-serve signup + refresh
|
|
191
|
-
* 5. Provision an MCP API key via the backend
|
|
192
|
-
* 6. Store the API key and refresh token
|
|
193
|
-
*
|
|
194
|
-
* Returns the provisioned API token.
|
|
195
|
-
*/
|
|
196
|
-
export async function runDeviceAuthFlow() {
|
|
197
|
-
const env = getCurrentEnvironment();
|
|
198
|
-
const clientId = ENVIRONMENT_CONFIGS[env].workosClientId;
|
|
199
|
-
// Step 1: Request device code
|
|
200
|
-
const deviceCode = await requestDeviceCode(clientId);
|
|
201
|
-
// Step 2: Open browser and show code
|
|
202
|
-
console.log('\n🔐 Opening browser to log in...\n');
|
|
203
|
-
openBrowser(deviceCode.verification_uri_complete);
|
|
204
|
-
console.log(`If the browser doesn't open, visit: ${deviceCode.verification_uri_complete}`);
|
|
205
|
-
console.log(`Code: ${deviceCode.user_code}\n`);
|
|
206
|
-
// Step 3: Poll for tokens
|
|
207
|
-
process.stdout.write('Waiting for authentication...');
|
|
208
|
-
let tokens = await pollForTokens(clientId, deviceCode.device_code, deviceCode.interval, deviceCode.expires_in);
|
|
209
|
-
console.log(' ✓');
|
|
210
|
-
// Step 4: Check if token has an org_id; if not, self-serve signup
|
|
211
|
-
const claims = decodeJwtPayload(tokens.access_token);
|
|
212
|
-
if (!claims.org_id) {
|
|
213
|
-
process.stdout.write('Setting up your organization...');
|
|
214
|
-
const { organizationId } = await selfServeSignup(tokens.access_token);
|
|
215
|
-
tokens = await refreshTokenWithOrg(clientId, tokens.refresh_token, organizationId);
|
|
216
|
-
console.log(' ✓');
|
|
217
|
-
}
|
|
218
|
-
// Step 5: Provision API key
|
|
219
|
-
process.stdout.write('Provisioning API key...');
|
|
220
|
-
const apiToken = await provisionApiKey(tokens.access_token);
|
|
221
|
-
console.log(' ✓');
|
|
222
|
-
// Step 6: Store credentials
|
|
223
|
-
await storeToken(apiToken);
|
|
224
|
-
if (tokens.refresh_token) {
|
|
225
|
-
await storeRefreshToken(tokens.refresh_token);
|
|
226
|
-
}
|
|
227
|
-
return apiToken;
|
|
228
|
-
}
|
|
229
|
-
function sleep(ms) {
|
|
230
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
231
|
-
}
|
|
232
|
-
//# sourceMappingURL=deviceAuth.js.map
|
|
1
|
+
function _0x4616(){const _0x4cdd79=['utf-8','access_token','stdout','https://api.workos.com/user_management/authorize/device','length','toString','json','ZqTbA','GIYLC','xdg-open','text','Provisioning\x20API\x20key...','eYsBo','393870VnCtnt','refresh_token','8532744TLVSQI','write','urn:ietf:params:oauth:grant-type:device_code','log','authorization_pending','uNmpE','GET','pjZoe','IhNyU','jkPXP','error','YLKmQ','apiKeys','kzyFA','\x27s\x20CLI\x20Key','144RBkHOP','TlvXU','apiKey','Failed\x20to\x20create\x20organization:\x20','BCcPI','nwuEY','CLI\x20Key','pnZOh','2658762RhiJjy','uXbnp','org_id','KeUeC','/api-keys','Failed\x20to\x20refresh\x20token\x20with\x20org:\x20','startsWith','UvMNM','error_description','xPFYX','KigKD','23928hzjQQY','start','expires_in','1XWBRsJ','elTar','21blDthM','oDROg','37198634wzYJjQ','/organization/me','AhZTB','name','token','status','If\x20the\x20browser\x20doesn\x27t\x20open,\x20visit:\x20','parse','\x0a🔐\x20Opening\x20browser\x20to\x20log\x20in...\x0a','OhUXK','filter','platform','application/x-www-form-urlencoded','Setting\x20up\x20your\x20organization...','base64url','1024532WEOnzJ','jrviy','stringify','open','from','5vKlLKB','519072DYlWDU'];_0x4616=function(){return _0x4cdd79;};return _0x4616();}const _0x384460=_0x5d10;(function(_0x5d45a5,_0x3d11e6){const _0x1de578=_0x5d10,_0x1f7f0a=_0x5d45a5();while(!![]){try{const _0x1a662c=parseInt(_0x1de578(0x17c))/0x1*(-parseInt(_0x1de578(0x18f))/0x2)+-parseInt(_0x1de578(0x16e))/0x3+-parseInt(_0x1de578(0x179))/0x4*(-parseInt(_0x1de578(0x194))/0x5)+-parseInt(_0x1de578(0x195))/0x6*(-parseInt(_0x1de578(0x17e))/0x7)+-parseInt(_0x1de578(0x157))/0x8+parseInt(_0x1de578(0x166))/0x9*(-parseInt(_0x1de578(0x155))/0xa)+parseInt(_0x1de578(0x180))/0xb;if(_0x1a662c===_0x3d11e6)break;else _0x1f7f0a['push'](_0x1f7f0a['shift']());}catch(_0xfe05db){_0x1f7f0a['push'](_0x1f7f0a['shift']());}}}(_0x4616,0x86be3));function _0x5d10(_0x29dbbf,_0x5c6654){_0x29dbbf=_0x29dbbf-0x14b;const _0x4616c3=_0x4616();let _0x5d10f1=_0x4616c3[_0x29dbbf];return _0x5d10f1;}import{exec}from'child_process';import{getCurrentEnvironment,ENVIRONMENT_CONFIGS,getApiBaseUrl}from'./environment.js';import{storeToken,storeRefreshToken}from'./keychain.js';const WORKOS_DEVICE_AUTH_URL=_0x384460(0x14b),WORKOS_TOKEN_URL='https://api.workos.com/user_management/authenticate';export async function requestDeviceCode(_0x2a31c6){const _0x2ac469=_0x384460,_0x50bd8f={'IhNyU':_0x2ac469(0x18c)},_0xc07a65=await fetch(WORKOS_DEVICE_AUTH_URL,{'method':'POST','headers':{'Content-Type':_0x50bd8f[_0x2ac469(0x15f)]},'body':new URLSearchParams({'client_id':_0x2a31c6})});if(!_0xc07a65['ok']){const _0x37dfc1=await _0xc07a65[_0x2ac469(0x152)]();throw new Error('Failed\x20to\x20request\x20device\x20code:\x20'+_0xc07a65[_0x2ac469(0x185)]+'\x20'+_0x37dfc1);}return _0xc07a65[_0x2ac469(0x14e)]();}export async function pollForTokens(_0x4fbdd3,_0x5436a4,_0x2e7b41,_0xc40e1e){const _0x102d82=_0x384460,_0x5bde19={'UvMNM':function(_0x1dae1a,_0x81d682){return _0x1dae1a*_0x81d682;},'elTar':function(_0x242efa,_0x1a2a12){return _0x242efa<_0x1a2a12;},'ZqTbA':function(_0x548919,_0x2509a6){return _0x548919(_0x2509a6);},'TlvXU':function(_0xd95814,_0x4b596,_0x136c27){return _0xd95814(_0x4b596,_0x136c27);},'uTJjN':_0x102d82(0x18c),'GIYLC':_0x102d82(0x15b),'AhZTB':'slow_down','nwuEY':'Authentication\x20failed','xPFYX':'Device\x20authorization\x20timed\x20out'},_0x159bf0=Date['now']()+_0x5bde19[_0x102d82(0x175)](_0xc40e1e,0x3e8);let _0xccc670=_0x5bde19[_0x102d82(0x175)](_0x2e7b41,0x3e8);while(_0x5bde19[_0x102d82(0x17d)](Date['now'](),_0x159bf0)){await _0x5bde19[_0x102d82(0x14f)](sleep,_0xccc670);const _0x5839d8=await _0x5bde19[_0x102d82(0x167)](fetch,WORKOS_TOKEN_URL,{'method':'POST','headers':{'Content-Type':_0x5bde19['uTJjN']},'body':new URLSearchParams({'client_id':_0x4fbdd3,'device_code':_0x5436a4,'grant_type':_0x102d82(0x159)})});if(_0x5839d8['ok'])return _0x5839d8[_0x102d82(0x14e)]();const _0x386b79=await _0x5839d8[_0x102d82(0x14e)]();if(_0x386b79['error']===_0x5bde19[_0x102d82(0x150)])continue;if(_0x386b79['error']===_0x5bde19[_0x102d82(0x182)]){_0xccc670+=0x3e8;continue;}throw new Error(_0x386b79[_0x102d82(0x176)]||_0x386b79[_0x102d82(0x161)]||_0x5bde19[_0x102d82(0x16b)]);}throw new Error(_0x5bde19[_0x102d82(0x177)]);}async function fetchUserProfile(_0x25a11d){const _0x383756=_0x384460,_0x3e7423={'UICie':function(_0x188c41){return _0x188c41();},'oDROg':_0x383756(0x15d)},_0x4517b9=_0x3e7423['UICie'](getApiBaseUrl);try{const _0x3cb08e=await fetch(_0x4517b9+_0x383756(0x181),{'method':_0x3e7423[_0x383756(0x17f)],'headers':{'workos-token':_0x25a11d}});if(_0x3cb08e['ok'])return _0x3cb08e['json']();}catch{}return null;}function buildKeyName(_0x24e5ea,_0x355b7b){const _0x2c0c9e=_0x384460,_0x42ee7e={'pnZOh':function(_0x22b1f4,_0x9e967d){return _0x22b1f4===_0x9e967d;}},_0x24385a=_0x355b7b[_0x2c0c9e(0x18a)](_0x4cad50=>_0x4cad50['name']===_0x24e5ea||_0x4cad50[_0x2c0c9e(0x183)][_0x2c0c9e(0x174)](_0x24e5ea+'\x20('));if(_0x42ee7e[_0x2c0c9e(0x16d)](_0x24385a['length'],0x0))return _0x24e5ea;return _0x24e5ea+'\x20('+(_0x24385a[_0x2c0c9e(0x14c)]+0x1)+')';}export async function provisionApiKey(_0x308fa5){const _0x39caa5=_0x384460,_0x488d79={'MqWul':'application/json','DmaFs':function(_0x1e9bbf,_0x1cc1b3){return _0x1e9bbf(_0x1cc1b3);},'BCcPI':'GET','kzyFA':function(_0x5e471b,_0x1fc3ab,_0x498045){return _0x5e471b(_0x1fc3ab,_0x498045);}},_0x4137e7=getApiBaseUrl(),_0xd409a5={'Content-Type':_0x488d79['MqWul'],'workos-token':_0x308fa5},_0x78b776=await _0x488d79['DmaFs'](fetchUserProfile,_0x308fa5),_0x9dd9d6=_0x78b776?.['firstName']||_0x78b776?.['email']?.['split']('@')[0x0],_0x2a7956=_0x9dd9d6?_0x9dd9d6+_0x39caa5(0x165):_0x39caa5(0x16c);let _0x397c8c=[];try{const _0x277a7c=await fetch(_0x4137e7+_0x39caa5(0x172),{'method':_0x488d79[_0x39caa5(0x16a)],'headers':_0xd409a5});if(_0x277a7c['ok']){const _0x1d3be7=await _0x277a7c['json']();_0x397c8c=_0x1d3be7[_0x39caa5(0x163)];}}catch{}const _0x504cd0=_0x488d79[_0x39caa5(0x164)](buildKeyName,_0x2a7956,_0x397c8c),_0x5c9a3e=await fetch(_0x4137e7+'/api-keys',{'method':'POST','headers':_0xd409a5,'body':JSON['stringify']({'name':_0x504cd0,'scope':'mcp:write'})});if(!_0x5c9a3e['ok']){const _0x17e74e=await _0x5c9a3e['text']();throw new Error('Failed\x20to\x20provision\x20API\x20key:\x20'+_0x5c9a3e['status']+'\x20'+_0x17e74e);}const _0x57279a=await _0x5c9a3e['json']();return _0x57279a[_0x39caa5(0x168)][_0x39caa5(0x184)];}export function openBrowser(_0x13a525){const _0x439f13=_0x384460,_0x342561={'uNmpE':_0x439f13(0x192),'OhUXK':function(_0xfe5499,_0xfe5970){return _0xfe5499===_0xfe5970;},'DDRow':function(_0x4ab88a,_0x42761d){return _0x4ab88a(_0x42761d);}},_0x170afe=process[_0x439f13(0x18b)],_0x57ce37=_0x170afe==='darwin'?_0x342561[_0x439f13(0x15c)]:_0x342561[_0x439f13(0x189)](_0x170afe,'win32')?_0x439f13(0x17a):_0x439f13(0x151);_0x342561['DDRow'](exec,_0x57ce37+'\x20'+JSON[_0x439f13(0x191)](_0x13a525));}function decodeJwtPayload(_0x2e9ba9){const _0x26c172=_0x384460,_0x1820d9={'uToDV':function(_0x5dacc0,_0x1f46e0){return _0x5dacc0!==_0x1f46e0;},'KBzED':'Invalid\x20JWT\x20format','vUReX':_0x26c172(0x18e),'pjZoe':_0x26c172(0x196)},_0x28e40d=_0x2e9ba9['split']('.');if(_0x1820d9['uToDV'](_0x28e40d['length'],0x3))throw new Error(_0x1820d9['KBzED']);const _0x5dba11=Buffer[_0x26c172(0x193)](_0x28e40d[0x1],_0x1820d9['vUReX'])[_0x26c172(0x14d)](_0x1820d9[_0x26c172(0x15e)]);return JSON[_0x26c172(0x187)](_0x5dba11);}async function selfServeSignup(_0x3651a5){const _0x5d2d15=_0x384460,_0x50869f={'KeUeC':function(_0x1f0f64){return _0x1f0f64();},'YVyyo':function(_0x4f6737,_0x1a812e,_0x43d5aa){return _0x4f6737(_0x1a812e,_0x43d5aa);},'FDQkA':'POST','eYsBo':'application/json'},_0x2e6630=_0x50869f[_0x5d2d15(0x171)](getApiBaseUrl),_0x1e2de5=await _0x50869f['YVyyo'](fetch,_0x2e6630+'/organization/self-serve-signup',{'method':_0x50869f['FDQkA'],'headers':{'Content-Type':_0x50869f[_0x5d2d15(0x154)],'workos-token':_0x3651a5}});if(!_0x1e2de5['ok']){const _0x25c7c9=await _0x1e2de5[_0x5d2d15(0x152)]();throw new Error(_0x5d2d15(0x169)+_0x1e2de5[_0x5d2d15(0x185)]+'\x20'+_0x25c7c9);}return _0x1e2de5['json']();}async function refreshTokenWithOrg(_0x3ab1ad,_0x588a3d,_0x5386be){const _0x10a684=_0x384460,_0x39618a={'TTCeS':'POST'},_0x52c53b=await fetch(WORKOS_TOKEN_URL,{'method':_0x39618a['TTCeS'],'headers':{'Content-Type':_0x10a684(0x18c)},'body':new URLSearchParams({'client_id':_0x3ab1ad,'grant_type':_0x10a684(0x156),'refresh_token':_0x588a3d,'organization_id':_0x5386be})});if(!_0x52c53b['ok']){const _0x241ad6=await _0x52c53b['text']();throw new Error(_0x10a684(0x173)+_0x52c53b['status']+'\x20'+_0x241ad6);}return _0x52c53b['json']();}export async function runDeviceAuthFlow(){const _0x117972=_0x384460,_0x2b7986={'YLKmQ':function(_0xea944b){return _0xea944b();},'jrviy':function(_0x3adb56,_0x564e28){return _0x3adb56(_0x564e28);},'kkGol':'Waiting\x20for\x20authentication...','jkPXP':_0x117972(0x18d),'uXbnp':_0x117972(0x153),'KigKD':function(_0x5bcad9,_0x2cf84b){return _0x5bcad9(_0x2cf84b);}},_0x734bff=_0x2b7986[_0x117972(0x162)](getCurrentEnvironment),_0x352081=ENVIRONMENT_CONFIGS[_0x734bff]['workosClientId'],_0x17bbd9=await _0x2b7986[_0x117972(0x190)](requestDeviceCode,_0x352081);console[_0x117972(0x15a)](_0x117972(0x188)),_0x2b7986['jrviy'](openBrowser,_0x17bbd9['verification_uri_complete']),console['log'](_0x117972(0x186)+_0x17bbd9['verification_uri_complete']),console[_0x117972(0x15a)]('Code:\x20'+_0x17bbd9['user_code']+'\x0a'),process[_0x117972(0x198)][_0x117972(0x158)](_0x2b7986['kkGol']);let _0x4d7a91=await pollForTokens(_0x352081,_0x17bbd9['device_code'],_0x17bbd9['interval'],_0x17bbd9[_0x117972(0x17b)]);console[_0x117972(0x15a)]('\x20✓');const _0x378f3e=_0x2b7986['jrviy'](decodeJwtPayload,_0x4d7a91[_0x117972(0x197)]);if(!_0x378f3e[_0x117972(0x170)]){process['stdout'][_0x117972(0x158)](_0x2b7986[_0x117972(0x160)]);const {organizationId:_0x577b33}=await _0x2b7986['jrviy'](selfServeSignup,_0x4d7a91['access_token']);_0x4d7a91=await refreshTokenWithOrg(_0x352081,_0x4d7a91['refresh_token'],_0x577b33),console[_0x117972(0x15a)]('\x20✓');}process[_0x117972(0x198)][_0x117972(0x158)](_0x2b7986[_0x117972(0x16f)]);const _0x360f06=await _0x2b7986[_0x117972(0x178)](provisionApiKey,_0x4d7a91['access_token']);return console[_0x117972(0x15a)]('\x20✓'),await storeToken(_0x360f06),_0x4d7a91['refresh_token']&&await storeRefreshToken(_0x4d7a91[_0x117972(0x156)]),_0x360f06;}function sleep(_0x111426){return new Promise(_0x15f6c5=>setTimeout(_0x15f6c5,_0x111426));}
|
|
@@ -1,65 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Centralized environment configuration for the CLI.
|
|
3
|
-
*
|
|
4
|
-
* Supports three environments: prod, staging, and local.
|
|
5
|
-
* Each environment has its own API base URL.
|
|
6
|
-
*
|
|
7
|
-
* End users always use prod (default).
|
|
8
|
-
* Developers can override by setting RANGER_CLI_ENV=staging or RANGER_CLI_ENV=local.
|
|
9
|
-
*/
|
|
10
|
-
/**
|
|
11
|
-
* Environment configurations for API URLs.
|
|
12
|
-
*/
|
|
13
|
-
export const ENVIRONMENT_CONFIGS = {
|
|
14
|
-
prod: {
|
|
15
|
-
apiBaseUrl: 'https://api.ranger.net',
|
|
16
|
-
workosClientId: 'client_01J9CBYM7M5ZETCF7G6614DXR2',
|
|
17
|
-
aiProxyUrl: 'https://ai-proxy-716115358910.us-central1.run.app',
|
|
18
|
-
},
|
|
19
|
-
staging: {
|
|
20
|
-
apiBaseUrl: 'https://api.staging.ranger.net',
|
|
21
|
-
workosClientId: 'client_01J9CBYM2DKWV9HM17D95Z540K',
|
|
22
|
-
aiProxyUrl: 'https://ai-proxy-301751771437.us-central1.run.app',
|
|
23
|
-
},
|
|
24
|
-
local: {
|
|
25
|
-
apiBaseUrl: 'http://localhost:8080',
|
|
26
|
-
workosClientId: 'client_01J9CBYM2DKWV9HM17D95Z540K',
|
|
27
|
-
aiProxyUrl: 'http://localhost:8090',
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
/**
|
|
31
|
-
* Default environment when none is specified.
|
|
32
|
-
*/
|
|
33
|
-
export const DEFAULT_ENVIRONMENT = 'prod';
|
|
34
|
-
/**
|
|
35
|
-
* Validate that a string is a valid environment name.
|
|
36
|
-
*/
|
|
37
|
-
export function isValidEnvironment(env) {
|
|
38
|
-
return env === 'prod' || env === 'staging' || env === 'local';
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Get the current environment from RANGER_CLI_ENV env var.
|
|
42
|
-
* Defaults to 'prod' for end users.
|
|
43
|
-
* Developers can set RANGER_CLI_ENV=staging or RANGER_CLI_ENV=local.
|
|
44
|
-
*/
|
|
45
|
-
export function getCurrentEnvironment() {
|
|
46
|
-
const env = process.env.RANGER_CLI_ENV;
|
|
47
|
-
if (env && isValidEnvironment(env)) {
|
|
48
|
-
return env;
|
|
49
|
-
}
|
|
50
|
-
return DEFAULT_ENVIRONMENT;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Get the API base URL for the current environment.
|
|
54
|
-
* Priority: RANGER_API_URL env var > RANGER_CLI_ENV-based config > prod default
|
|
55
|
-
*/
|
|
56
|
-
export function getApiBaseUrl() {
|
|
57
|
-
return ENVIRONMENT_CONFIGS[getCurrentEnvironment()].apiBaseUrl;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Get the AI Proxy URL for the current environment.
|
|
61
|
-
*/
|
|
62
|
-
export function getAiProxyUrl() {
|
|
63
|
-
return ENVIRONMENT_CONFIGS[getCurrentEnvironment()].aiProxyUrl;
|
|
64
|
-
}
|
|
65
|
-
//# sourceMappingURL=environment.js.map
|
|
1
|
+
const _0x2e4663=_0x2584;(function(_0x587023,_0x2a0e4c){const _0x2de5e8=_0x2584,_0x49ddad=_0x587023();while(!![]){try{const _0x1e773e=-parseInt(_0x2de5e8(0x99))/0x1*(-parseInt(_0x2de5e8(0xac))/0x2)+parseInt(_0x2de5e8(0xae))/0x3*(-parseInt(_0x2de5e8(0xa7))/0x4)+parseInt(_0x2de5e8(0x96))/0x5+-parseInt(_0x2de5e8(0x9c))/0x6*(parseInt(_0x2de5e8(0xa4))/0x7)+parseInt(_0x2de5e8(0xa0))/0x8*(-parseInt(_0x2de5e8(0xa9))/0x9)+parseInt(_0x2de5e8(0x97))/0xa*(parseInt(_0x2de5e8(0xa5))/0xb)+parseInt(_0x2de5e8(0xa8))/0xc*(parseInt(_0x2de5e8(0x9e))/0xd);if(_0x1e773e===_0x2a0e4c)break;else _0x49ddad['push'](_0x49ddad['shift']());}catch(_0x5b34fd){_0x49ddad['push'](_0x49ddad['shift']());}}}(_0x18be,0x32761));function _0x2584(_0xf86fbf,_0x4e2d5d){_0xf86fbf=_0xf86fbf-0x96;const _0x18bec3=_0x18be();let _0x2584b1=_0x18bec3[_0xf86fbf];return _0x2584b1;}export const ENVIRONMENT_CONFIGS={'prod':{'apiBaseUrl':_0x2e4663(0xaf),'workosClientId':_0x2e4663(0xad),'aiProxyUrl':_0x2e4663(0xa3)},'staging':{'apiBaseUrl':'https://api.staging.ranger.net','workosClientId':_0x2e4663(0x98),'aiProxyUrl':_0x2e4663(0xa2)},'local':{'apiBaseUrl':_0x2e4663(0x9d),'workosClientId':_0x2e4663(0x98),'aiProxyUrl':'http://localhost:8090'}};export const DEFAULT_ENVIRONMENT='prod';export function isValidEnvironment(_0x636f2f){const _0x415803=_0x2e4663,_0x1caa5a={'DbNCK':function(_0x1d91b5,_0x3ec11d){return _0x1d91b5===_0x3ec11d;},'HJmAJ':'prod','hTnpL':_0x415803(0xab),'QVaal':function(_0x10ebc3,_0x4a8a32){return _0x10ebc3===_0x4a8a32;}};return _0x1caa5a[_0x415803(0xa1)](_0x636f2f,_0x1caa5a['HJmAJ'])||_0x636f2f===_0x1caa5a[_0x415803(0xaa)]||_0x1caa5a[_0x415803(0x9a)](_0x636f2f,'local');}export function getCurrentEnvironment(){const _0x42e469=_0x2e4663,_0x1d4ae7={'CyTDg':function(_0x20ecc8,_0x3e15c8){return _0x20ecc8(_0x3e15c8);}},_0xff500c=process['env'][_0x42e469(0x9b)];if(_0xff500c&&_0x1d4ae7[_0x42e469(0xa6)](isValidEnvironment,_0xff500c))return _0xff500c;return DEFAULT_ENVIRONMENT;}function _0x18be(){const _0x435114=['801vgMHIy','hTnpL','staging','7538pmeCYU','client_01J9CBYM7M5ZETCF7G6614DXR2','4353Lphmty','https://api.ranger.net','399190jkOelv','2969460oQjlIZ','client_01J9CBYM2DKWV9HM17D95Z540K','7AZxlOP','QVaal','RANGER_CLI_ENV','350466vRTvUu','http://localhost:8080','1599REXfpe','apiBaseUrl','30128tLrfbb','DbNCK','https://ai-proxy-301751771437.us-central1.run.app','https://ai-proxy-716115358910.us-central1.run.app','21uXvaDD','11gCuSFc','CyTDg','84KrfguA','33600DTodkl'];_0x18be=function(){return _0x435114;};return _0x18be();}export function getApiBaseUrl(){const _0x122715=_0x2e4663;return ENVIRONMENT_CONFIGS[getCurrentEnvironment()][_0x122715(0x9f)];}export function getAiProxyUrl(){const _0x44b448={'ZHWDe':function(_0x4f05d3){return _0x4f05d3();}};return ENVIRONMENT_CONFIGS[_0x44b448['ZHWDe'](getCurrentEnvironment)]['aiProxyUrl'];}
|