@sembix/cli 1.2.1 → 1.4.0
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/COMMANDS.md +1522 -0
- package/QUICKSTART.md +829 -0
- package/README.md +1976 -309
- package/USAGE-EXAMPLES.md +872 -0
- package/config.example.yaml +3 -0
- package/dist/commands/configure.d.ts.map +1 -1
- package/dist/commands/configure.js +172 -2
- package/dist/commands/configure.js.map +1 -1
- package/dist/commands/index.d.ts +10 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/index.js +11 -0
- package/dist/commands/index.js.map +1 -0
- package/dist/commands/login.d.ts +19 -0
- package/dist/commands/login.d.ts.map +1 -0
- package/dist/commands/login.js +118 -0
- package/dist/commands/login.js.map +1 -0
- package/dist/commands/logout.d.ts +21 -0
- package/dist/commands/logout.d.ts.map +1 -0
- package/dist/commands/logout.js +66 -0
- package/dist/commands/logout.js.map +1 -0
- package/dist/commands/profile-project.d.ts +14 -0
- package/dist/commands/profile-project.d.ts.map +1 -0
- package/dist/commands/profile-project.js +123 -0
- package/dist/commands/profile-project.js.map +1 -0
- package/dist/commands/profile.d.ts +26 -0
- package/dist/commands/profile.d.ts.map +1 -0
- package/dist/commands/profile.js +177 -0
- package/dist/commands/profile.js.map +1 -0
- package/dist/commands/project.d.ts +16 -0
- package/dist/commands/project.d.ts.map +1 -0
- package/dist/commands/project.js +153 -0
- package/dist/commands/project.js.map +1 -0
- package/dist/commands/setup.js +3 -0
- package/dist/commands/setup.js.map +1 -1
- package/dist/commands/workflow.d.ts +91 -0
- package/dist/commands/workflow.d.ts.map +1 -0
- package/dist/commands/workflow.js +1201 -0
- package/dist/commands/workflow.js.map +1 -0
- package/dist/config-schema.d.ts +26 -0
- package/dist/config-schema.d.ts.map +1 -1
- package/dist/config-schema.js +24 -1
- package/dist/config-schema.js.map +1 -1
- package/dist/config.d.ts +4 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +23 -2
- package/dist/config.js.map +1 -1
- package/dist/index.js +324 -1
- package/dist/index.js.map +1 -1
- package/dist/prompts/environment-setup.d.ts.map +1 -1
- package/dist/prompts/environment-setup.js +12 -0
- package/dist/prompts/environment-setup.js.map +1 -1
- package/dist/prompts/project-selection.d.ts +8 -0
- package/dist/prompts/project-selection.d.ts.map +1 -0
- package/dist/prompts/project-selection.js +132 -0
- package/dist/prompts/project-selection.js.map +1 -0
- package/dist/prompts/workflow-inputs.d.ts +10 -0
- package/dist/prompts/workflow-inputs.d.ts.map +1 -0
- package/dist/prompts/workflow-inputs.js +71 -0
- package/dist/prompts/workflow-inputs.js.map +1 -0
- package/dist/prompts/workflow-selection.d.ts +8 -0
- package/dist/prompts/workflow-selection.d.ts.map +1 -0
- package/dist/prompts/workflow-selection.js +147 -0
- package/dist/prompts/workflow-selection.js.map +1 -0
- package/dist/sembix-cli-1.4.0.tgz +0 -0
- package/dist/services/cognito-auth.d.ts +92 -0
- package/dist/services/cognito-auth.d.ts.map +1 -0
- package/dist/services/cognito-auth.js +319 -0
- package/dist/services/cognito-auth.js.map +1 -0
- package/dist/services/studio-api-client.d.ts +127 -0
- package/dist/services/studio-api-client.d.ts.map +1 -0
- package/dist/services/studio-api-client.js +291 -0
- package/dist/services/studio-api-client.js.map +1 -0
- package/dist/types/studio.d.ts +82 -0
- package/dist/types/studio.d.ts.map +1 -0
- package/dist/types/studio.js +7 -0
- package/dist/types/studio.js.map +1 -0
- package/dist/types.d.ts +286 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -1
- package/dist/utils/browser-auth.d.ts +45 -0
- package/dist/utils/browser-auth.d.ts.map +1 -0
- package/dist/utils/browser-auth.js +168 -0
- package/dist/utils/browser-auth.js.map +1 -0
- package/dist/utils/cognito-auth.d.ts +3 -0
- package/dist/utils/cognito-auth.d.ts.map +1 -0
- package/dist/utils/cognito-auth.js +3 -0
- package/dist/utils/cognito-auth.js.map +1 -0
- package/dist/utils/config-file.d.ts +40 -0
- package/dist/utils/config-file.d.ts.map +1 -1
- package/dist/utils/config-file.js +158 -4
- package/dist/utils/config-file.js.map +1 -1
- package/dist/utils/config-loader.d.ts.map +1 -1
- package/dist/utils/config-loader.js +15 -2
- package/dist/utils/config-loader.js.map +1 -1
- package/dist/utils/environment.d.ts +22 -0
- package/dist/utils/environment.d.ts.map +1 -0
- package/dist/utils/environment.js +39 -0
- package/dist/utils/environment.js.map +1 -0
- package/dist/utils/error-handler.d.ts +53 -0
- package/dist/utils/error-handler.d.ts.map +1 -0
- package/dist/utils/error-handler.js +174 -0
- package/dist/utils/error-handler.js.map +1 -0
- package/dist/utils/fuzzy-match.d.ts +31 -0
- package/dist/utils/fuzzy-match.d.ts.map +1 -0
- package/dist/utils/fuzzy-match.js +138 -0
- package/dist/utils/fuzzy-match.js.map +1 -0
- package/dist/utils/input-parser.d.ts +14 -0
- package/dist/utils/input-parser.d.ts.map +1 -0
- package/dist/utils/input-parser.js +34 -0
- package/dist/utils/input-parser.js.map +1 -0
- package/dist/utils/output.d.ts +55 -0
- package/dist/utils/output.d.ts.map +1 -0
- package/dist/utils/output.js +80 -0
- package/dist/utils/output.js.map +1 -0
- package/dist/utils/recent-workflows.d.ts +37 -0
- package/dist/utils/recent-workflows.d.ts.map +1 -0
- package/dist/utils/recent-workflows.js +172 -0
- package/dist/utils/recent-workflows.js.map +1 -0
- package/dist/utils/studio-api-client.d.ts +3 -0
- package/dist/utils/studio-api-client.d.ts.map +1 -0
- package/dist/utils/studio-api-client.js +3 -0
- package/dist/utils/studio-api-client.js.map +1 -0
- package/dist/utils/studio-api.d.ts +53 -0
- package/dist/utils/studio-api.d.ts.map +1 -0
- package/dist/utils/studio-api.js +102 -0
- package/dist/utils/studio-api.js.map +1 -0
- package/dist/utils/studio-config.d.ts +74 -0
- package/dist/utils/studio-config.d.ts.map +1 -0
- package/dist/utils/studio-config.js +213 -0
- package/dist/utils/studio-config.js.map +1 -0
- package/dist/utils/token-manager.d.ts +4 -0
- package/dist/utils/token-manager.d.ts.map +1 -0
- package/dist/utils/token-manager.js +3 -0
- package/dist/utils/token-manager.js.map +1 -0
- package/dist/utils/ui.d.ts +55 -1
- package/dist/utils/ui.d.ts.map +1 -1
- package/dist/utils/ui.js +151 -2
- package/dist/utils/ui.js.map +1 -1
- package/package.json +4 -1
- package/dist/__tests__/config-schema.test.d.ts +0 -2
- package/dist/__tests__/config-schema.test.d.ts.map +0 -1
- package/dist/__tests__/config-schema.test.js +0 -471
- package/dist/__tests__/config-schema.test.js.map +0 -1
- package/dist/__tests__/config.test.d.ts +0 -2
- package/dist/__tests__/config.test.d.ts.map +0 -1
- package/dist/__tests__/config.test.js +0 -75
- package/dist/__tests__/config.test.js.map +0 -1
- package/dist/__tests__/integration/configure.test.d.ts +0 -2
- package/dist/__tests__/integration/configure.test.d.ts.map +0 -1
- package/dist/__tests__/integration/configure.test.js +0 -247
- package/dist/__tests__/integration/configure.test.js.map +0 -1
- package/dist/__tests__/integration/fixtures/configs.d.ts +0 -477
- package/dist/__tests__/integration/fixtures/configs.d.ts.map +0 -1
- package/dist/__tests__/integration/fixtures/configs.js +0 -175
- package/dist/__tests__/integration/fixtures/configs.js.map +0 -1
- package/dist/__tests__/integration/helpers/cli-runner.d.ts +0 -63
- package/dist/__tests__/integration/helpers/cli-runner.d.ts.map +0 -1
- package/dist/__tests__/integration/helpers/cli-runner.js +0 -152
- package/dist/__tests__/integration/helpers/cli-runner.js.map +0 -1
- package/dist/__tests__/integration/helpers/command-runner.d.ts +0 -53
- package/dist/__tests__/integration/helpers/command-runner.d.ts.map +0 -1
- package/dist/__tests__/integration/helpers/command-runner.js +0 -117
- package/dist/__tests__/integration/helpers/command-runner.js.map +0 -1
- package/dist/__tests__/integration/studio-create.test.d.ts +0 -2
- package/dist/__tests__/integration/studio-create.test.d.ts.map +0 -1
- package/dist/__tests__/integration/studio-create.test.js +0 -209
- package/dist/__tests__/integration/studio-create.test.js.map +0 -1
- package/dist/__tests__/integration/studio-update.test.d.ts +0 -2
- package/dist/__tests__/integration/studio-update.test.d.ts.map +0 -1
- package/dist/__tests__/integration/studio-update.test.js +0 -166
- package/dist/__tests__/integration/studio-update.test.js.map +0 -1
- package/dist/commands/__tests__/configure.test.d.ts +0 -2
- package/dist/commands/__tests__/configure.test.d.ts.map +0 -1
- package/dist/commands/__tests__/configure.test.js +0 -229
- package/dist/commands/__tests__/configure.test.js.map +0 -1
- package/dist/prompts/__tests__/environment-setup.test.d.ts +0 -2
- package/dist/prompts/__tests__/environment-setup.test.d.ts.map +0 -1
- package/dist/prompts/__tests__/environment-setup.test.js +0 -206
- package/dist/prompts/__tests__/environment-setup.test.js.map +0 -1
- package/dist/prompts/__tests__/hub-integration.test.d.ts +0 -2
- package/dist/prompts/__tests__/hub-integration.test.d.ts.map +0 -1
- package/dist/prompts/__tests__/hub-integration.test.js +0 -126
- package/dist/prompts/__tests__/hub-integration.test.js.map +0 -1
- package/dist/prompts/__tests__/prompt-helpers.test.d.ts +0 -2
- package/dist/prompts/__tests__/prompt-helpers.test.d.ts.map +0 -1
- package/dist/prompts/__tests__/prompt-helpers.test.js +0 -235
- package/dist/prompts/__tests__/prompt-helpers.test.js.map +0 -1
- package/dist/sembix-cli-1.2.1.tgz +0 -0
- package/dist/utils/__tests__/config-file.test.d.ts +0 -2
- package/dist/utils/__tests__/config-file.test.d.ts.map +0 -1
- package/dist/utils/__tests__/config-file.test.js +0 -218
- package/dist/utils/__tests__/config-file.test.js.map +0 -1
- package/dist/utils/__tests__/config-loader.test.d.ts +0 -2
- package/dist/utils/__tests__/config-loader.test.d.ts.map +0 -1
- package/dist/utils/__tests__/config-loader.test.js +0 -325
- package/dist/utils/__tests__/config-loader.test.js.map +0 -1
- package/dist/utils/__tests__/github.test.d.ts +0 -2
- package/dist/utils/__tests__/github.test.d.ts.map +0 -1
- package/dist/utils/__tests__/github.test.js +0 -282
- package/dist/utils/__tests__/github.test.js.map +0 -1
- package/dist/utils/__tests__/ui.test.d.ts +0 -2
- package/dist/utils/__tests__/ui.test.d.ts.map +0 -1
- package/dist/utils/__tests__/ui.test.js +0 -256
- package/dist/utils/__tests__/ui.test.js.map +0 -1
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import { createServer } from 'http';
|
|
2
|
+
import { randomBytes, createHash } from 'crypto';
|
|
3
|
+
import { saveTokens, loadTokens, isTokenValid } from '../utils/studio-config.js';
|
|
4
|
+
/**
|
|
5
|
+
* CognitoAuthService handles OAuth 2.0 Authorization Code flow with PKCE
|
|
6
|
+
* for Cognito authentication. It manages the browser-based login flow,
|
|
7
|
+
* token exchange, and token refresh operations.
|
|
8
|
+
*/
|
|
9
|
+
export class CognitoAuthService {
|
|
10
|
+
profile;
|
|
11
|
+
constructor(profile) {
|
|
12
|
+
this.profile = profile;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Initiates the OAuth login flow by starting a local callback server,
|
|
16
|
+
* generating PKCE parameters, and exchanging the authorization code for tokens.
|
|
17
|
+
*
|
|
18
|
+
* @returns Promise resolving to authentication tokens
|
|
19
|
+
* @throws Error if authentication fails or times out
|
|
20
|
+
*/
|
|
21
|
+
async initiateLogin() {
|
|
22
|
+
// Generate PKCE parameters for secure OAuth flow
|
|
23
|
+
const { verifier, challenge } = this.generatePKCE();
|
|
24
|
+
// Start local HTTP server to receive OAuth callback
|
|
25
|
+
const { port, codePromise } = await this.startLocalServer();
|
|
26
|
+
// Build authorization URL
|
|
27
|
+
const redirectUri = `http://localhost:${port}/callback`;
|
|
28
|
+
const state = randomBytes(16).toString('base64url');
|
|
29
|
+
const authUrl = this.buildAuthorizationUrl(redirectUri, challenge, state);
|
|
30
|
+
// Display instructions to user
|
|
31
|
+
console.log('\nOpening browser for authentication...');
|
|
32
|
+
console.log(`If browser doesn't open automatically, visit:\n${authUrl}\n`);
|
|
33
|
+
try {
|
|
34
|
+
// Attempt to open browser (best effort)
|
|
35
|
+
await this.openBrowser(authUrl);
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
// Browser opening failed, user will use manual URL
|
|
39
|
+
console.log('Could not open browser automatically. Please use the URL above.');
|
|
40
|
+
}
|
|
41
|
+
// Wait for OAuth callback with authorization code (5 minute timeout)
|
|
42
|
+
const code = await Promise.race([
|
|
43
|
+
codePromise,
|
|
44
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error('Authentication timeout after 5 minutes')), 300000))
|
|
45
|
+
]);
|
|
46
|
+
// Exchange authorization code for tokens
|
|
47
|
+
const tokenSet = await this.exchangeCodeForTokens(code, verifier, redirectUri);
|
|
48
|
+
// Convert to StudioAuthTokens format and calculate expiry
|
|
49
|
+
const expiresAt = new Date(Date.now() + tokenSet.expires_in * 1000).toISOString();
|
|
50
|
+
const tokens = {
|
|
51
|
+
accessToken: tokenSet.access_token,
|
|
52
|
+
idToken: tokenSet.id_token,
|
|
53
|
+
refreshToken: tokenSet.refresh_token,
|
|
54
|
+
expiresAt
|
|
55
|
+
};
|
|
56
|
+
// Store tokens securely
|
|
57
|
+
await saveTokens(this.profile.name, tokens);
|
|
58
|
+
return tokens;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Refreshes expired access tokens using the refresh token.
|
|
62
|
+
*
|
|
63
|
+
* @param refreshToken - The refresh token from previous authentication
|
|
64
|
+
* @returns Promise resolving to new authentication tokens
|
|
65
|
+
* @throws Error if token refresh fails
|
|
66
|
+
*/
|
|
67
|
+
async refreshTokens(refreshToken) {
|
|
68
|
+
const tokenEndpoint = `${this.profile.cognitoDomain}/oauth2/token`;
|
|
69
|
+
const params = new URLSearchParams({
|
|
70
|
+
grant_type: 'refresh_token',
|
|
71
|
+
client_id: this.profile.cognitoClientId,
|
|
72
|
+
refresh_token: refreshToken
|
|
73
|
+
});
|
|
74
|
+
const response = await fetch(tokenEndpoint, {
|
|
75
|
+
method: 'POST',
|
|
76
|
+
headers: {
|
|
77
|
+
'Content-Type': 'application/x-www-form-urlencoded'
|
|
78
|
+
},
|
|
79
|
+
body: params.toString()
|
|
80
|
+
});
|
|
81
|
+
if (!response.ok) {
|
|
82
|
+
const errorText = await response.text();
|
|
83
|
+
throw new Error(`Token refresh failed: ${response.statusText}. ${errorText}`);
|
|
84
|
+
}
|
|
85
|
+
const tokenSet = await response.json();
|
|
86
|
+
// Calculate new expiry time
|
|
87
|
+
const expiresAt = new Date(Date.now() + tokenSet.expires_in * 1000).toISOString();
|
|
88
|
+
const tokens = {
|
|
89
|
+
accessToken: tokenSet.access_token,
|
|
90
|
+
idToken: tokenSet.id_token,
|
|
91
|
+
refreshToken: tokenSet.refresh_token || refreshToken, // Use new refresh token if provided, otherwise keep existing
|
|
92
|
+
expiresAt
|
|
93
|
+
};
|
|
94
|
+
// Update stored tokens
|
|
95
|
+
await saveTokens(this.profile.name, tokens);
|
|
96
|
+
return tokens;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Authenticates using OAuth 2.0 Client Credentials flow
|
|
100
|
+
* Used for machine-to-machine authentication (CI/CD)
|
|
101
|
+
*
|
|
102
|
+
* @param clientId - M2M client ID
|
|
103
|
+
* @param clientSecret - M2M client secret
|
|
104
|
+
* @returns Promise resolving to authentication tokens
|
|
105
|
+
* @throws Error if authentication fails
|
|
106
|
+
*/
|
|
107
|
+
async authenticateWithClientCredentials(clientId, clientSecret) {
|
|
108
|
+
const tokenEndpoint = `${this.profile.cognitoDomain}/oauth2/token`;
|
|
109
|
+
const params = new URLSearchParams({
|
|
110
|
+
grant_type: 'client_credentials',
|
|
111
|
+
client_id: clientId,
|
|
112
|
+
client_secret: clientSecret,
|
|
113
|
+
scope: 'sembix-api/projects.read sembix-api/workflows.read sembix-api/workflows.execute'
|
|
114
|
+
});
|
|
115
|
+
const response = await fetch(tokenEndpoint, {
|
|
116
|
+
method: 'POST',
|
|
117
|
+
headers: {
|
|
118
|
+
'Content-Type': 'application/x-www-form-urlencoded'
|
|
119
|
+
},
|
|
120
|
+
body: params.toString()
|
|
121
|
+
});
|
|
122
|
+
if (!response.ok) {
|
|
123
|
+
const errorText = await response.text();
|
|
124
|
+
throw new Error(`Client credentials authentication failed: ${response.statusText}. ${errorText}`);
|
|
125
|
+
}
|
|
126
|
+
const tokenSet = await response.json();
|
|
127
|
+
// Validate response
|
|
128
|
+
if (!tokenSet.access_token) {
|
|
129
|
+
throw new Error('Invalid token response: missing access_token');
|
|
130
|
+
}
|
|
131
|
+
// Client credentials flow doesn't return id_token or refresh_token
|
|
132
|
+
return {
|
|
133
|
+
accessToken: tokenSet.access_token,
|
|
134
|
+
idToken: '', // Not provided in client credentials
|
|
135
|
+
refreshToken: '', // Not provided in client credentials
|
|
136
|
+
expiresAt: new Date(Date.now() + tokenSet.expires_in * 1000).toISOString()
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Generates PKCE code verifier and challenge for secure OAuth flow.
|
|
141
|
+
* Uses SHA256 hashing as required by OAuth 2.0 PKCE specification.
|
|
142
|
+
*
|
|
143
|
+
* @returns Object containing base64url-encoded verifier and challenge
|
|
144
|
+
*/
|
|
145
|
+
generatePKCE() {
|
|
146
|
+
// Generate cryptographically secure random verifier (43-128 characters)
|
|
147
|
+
const verifier = randomBytes(32).toString('base64url');
|
|
148
|
+
// Create SHA256 hash of verifier for challenge
|
|
149
|
+
const challenge = createHash('sha256')
|
|
150
|
+
.update(verifier)
|
|
151
|
+
.digest('base64url');
|
|
152
|
+
return { verifier, challenge };
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Starts a temporary HTTP server on localhost to receive OAuth callback.
|
|
156
|
+
* Finds an available port in the range 3000-9000.
|
|
157
|
+
*
|
|
158
|
+
* @returns Promise resolving to server port and a promise for the authorization code
|
|
159
|
+
*/
|
|
160
|
+
async startLocalServer() {
|
|
161
|
+
return new Promise((resolve, reject) => {
|
|
162
|
+
let codeResolver;
|
|
163
|
+
let codeRejector;
|
|
164
|
+
const codePromise = new Promise((res, rej) => {
|
|
165
|
+
codeResolver = res;
|
|
166
|
+
codeRejector = rej;
|
|
167
|
+
});
|
|
168
|
+
const server = createServer((req, res) => {
|
|
169
|
+
const url = new URL(req.url || '', `http://localhost`);
|
|
170
|
+
if (url.pathname === '/callback') {
|
|
171
|
+
const code = url.searchParams.get('code');
|
|
172
|
+
const error = url.searchParams.get('error');
|
|
173
|
+
if (error) {
|
|
174
|
+
const errorDescription = url.searchParams.get('error_description') || error;
|
|
175
|
+
res.writeHead(400, { 'Content-Type': 'text/html' });
|
|
176
|
+
res.end(`<html><body><h1>Authentication Failed</h1><p>${errorDescription}</p></body></html>`);
|
|
177
|
+
codeRejector(new Error(`OAuth error: ${errorDescription}`));
|
|
178
|
+
server.close();
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
if (!code) {
|
|
182
|
+
res.writeHead(400, { 'Content-Type': 'text/html' });
|
|
183
|
+
res.end('<html><body><h1>Authentication Failed</h1><p>No authorization code received</p></body></html>');
|
|
184
|
+
codeRejector(new Error('No authorization code received'));
|
|
185
|
+
server.close();
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
// Success response
|
|
189
|
+
res.writeHead(200, { 'Content-Type': 'text/html' });
|
|
190
|
+
res.end('<html><body><h1>Authentication Successful</h1><p>You can close this window and return to the CLI.</p></body></html>');
|
|
191
|
+
codeResolver(code);
|
|
192
|
+
server.close();
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
res.writeHead(404);
|
|
196
|
+
res.end('Not Found');
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
// Try to find an available port in range 3000-9000
|
|
200
|
+
const tryPort = (port) => {
|
|
201
|
+
server.listen(port, 'localhost', () => {
|
|
202
|
+
resolve({ port, codePromise });
|
|
203
|
+
});
|
|
204
|
+
server.on('error', (err) => {
|
|
205
|
+
if (err.code === 'EADDRINUSE' && port < 9000) {
|
|
206
|
+
// Port in use, try next one
|
|
207
|
+
tryPort(port + 1);
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
reject(new Error(`Failed to start callback server: ${err.message}`));
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
};
|
|
214
|
+
tryPort(3000);
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Builds the Cognito authorization URL with PKCE parameters.
|
|
219
|
+
*
|
|
220
|
+
* @param redirectUri - Callback URL for OAuth flow
|
|
221
|
+
* @param codeChallenge - PKCE code challenge
|
|
222
|
+
* @param state - Random state parameter for CSRF protection
|
|
223
|
+
* @returns Complete authorization URL
|
|
224
|
+
*/
|
|
225
|
+
buildAuthorizationUrl(redirectUri, codeChallenge, state) {
|
|
226
|
+
const params = new URLSearchParams({
|
|
227
|
+
response_type: 'code',
|
|
228
|
+
client_id: this.profile.cognitoClientId,
|
|
229
|
+
redirect_uri: redirectUri,
|
|
230
|
+
code_challenge: codeChallenge,
|
|
231
|
+
code_challenge_method: 'S256',
|
|
232
|
+
state,
|
|
233
|
+
scope: 'openid email' // OpenID Connect scopes for CLI authentication
|
|
234
|
+
});
|
|
235
|
+
return `${this.profile.cognitoDomain}/oauth2/authorize?${params.toString()}`;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Exchanges authorization code for access tokens via Cognito token endpoint.
|
|
239
|
+
*
|
|
240
|
+
* @param code - Authorization code from OAuth callback
|
|
241
|
+
* @param codeVerifier - PKCE code verifier
|
|
242
|
+
* @param redirectUri - Must match the redirect_uri used in authorization request
|
|
243
|
+
* @returns Promise resolving to token set
|
|
244
|
+
* @throws Error if token exchange fails
|
|
245
|
+
*/
|
|
246
|
+
async exchangeCodeForTokens(code, codeVerifier, redirectUri) {
|
|
247
|
+
const tokenEndpoint = `${this.profile.cognitoDomain}/oauth2/token`;
|
|
248
|
+
const params = new URLSearchParams({
|
|
249
|
+
grant_type: 'authorization_code',
|
|
250
|
+
client_id: this.profile.cognitoClientId,
|
|
251
|
+
code,
|
|
252
|
+
code_verifier: codeVerifier,
|
|
253
|
+
redirect_uri: redirectUri
|
|
254
|
+
});
|
|
255
|
+
const response = await fetch(tokenEndpoint, {
|
|
256
|
+
method: 'POST',
|
|
257
|
+
headers: {
|
|
258
|
+
'Content-Type': 'application/x-www-form-urlencoded'
|
|
259
|
+
},
|
|
260
|
+
body: params.toString()
|
|
261
|
+
});
|
|
262
|
+
if (!response.ok) {
|
|
263
|
+
const errorText = await response.text();
|
|
264
|
+
throw new Error(`Token exchange failed: ${response.statusText}. ${errorText}`);
|
|
265
|
+
}
|
|
266
|
+
const tokenSet = await response.json();
|
|
267
|
+
// Validate required fields
|
|
268
|
+
if (!tokenSet.access_token || !tokenSet.id_token || !tokenSet.refresh_token) {
|
|
269
|
+
throw new Error('Invalid token response: missing required tokens');
|
|
270
|
+
}
|
|
271
|
+
return tokenSet;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Attempts to open the authorization URL in the default browser.
|
|
275
|
+
* Uses platform-specific commands (open on macOS, start on Windows, xdg-open on Linux).
|
|
276
|
+
*
|
|
277
|
+
* @param url - URL to open
|
|
278
|
+
* @throws Error if browser cannot be opened (non-fatal, user can use manual URL)
|
|
279
|
+
*/
|
|
280
|
+
async openBrowser(url) {
|
|
281
|
+
const { exec } = await import('child_process');
|
|
282
|
+
const { promisify } = await import('util');
|
|
283
|
+
const execAsync = promisify(exec);
|
|
284
|
+
const platform = process.platform;
|
|
285
|
+
let command;
|
|
286
|
+
switch (platform) {
|
|
287
|
+
case 'darwin':
|
|
288
|
+
command = `open "${url}"`;
|
|
289
|
+
break;
|
|
290
|
+
case 'win32':
|
|
291
|
+
command = `start "" "${url}"`;
|
|
292
|
+
break;
|
|
293
|
+
default: // Linux and others
|
|
294
|
+
command = `xdg-open "${url}"`;
|
|
295
|
+
break;
|
|
296
|
+
}
|
|
297
|
+
await execAsync(command);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Validates if a token is still valid based on expiration time.
|
|
302
|
+
*
|
|
303
|
+
* @param tokens - Authentication tokens to validate
|
|
304
|
+
* @returns true if token is valid, false if expired
|
|
305
|
+
*/
|
|
306
|
+
export function validateToken(tokens) {
|
|
307
|
+
return isTokenValid(tokens);
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Loads stored tokens for a profile.
|
|
311
|
+
*
|
|
312
|
+
* @param profileName - Name of the profile
|
|
313
|
+
* @returns Promise resolving to tokens or null if not found
|
|
314
|
+
*/
|
|
315
|
+
export async function getStoredTokens(profileName) {
|
|
316
|
+
const tokens = await loadTokens(profileName);
|
|
317
|
+
return tokens ?? null;
|
|
318
|
+
}
|
|
319
|
+
//# sourceMappingURL=cognito-auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cognito-auth.js","sourceRoot":"","sources":["../../src/services/cognito-auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEjD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEjF;;;;GAIG;AACH,MAAM,OAAO,kBAAkB;IACT;IAApB,YAAoB,OAAsB;QAAtB,YAAO,GAAP,OAAO,CAAe;IAAG,CAAC;IAE9C;;;;;;OAMG;IACH,KAAK,CAAC,aAAa;QACjB,iDAAiD;QACjD,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QAEpD,oDAAoD;QACpD,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,MAAM,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAE5D,0BAA0B;QAC1B,MAAM,WAAW,GAAG,oBAAoB,IAAI,WAAW,CAAC;QACxD,MAAM,KAAK,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;QACpD,MAAM,OAAO,GAAG,IAAI,CAAC,qBAAqB,C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AY,CAAC,MAAM,CAAC,CAAC;AAC9B,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,WAAmB;IACvD,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,WAAW,CAAC,CAAC;IAC7C,OAAO,MAAM,IAAI,IAAI,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import type { StudioProfile, StudioAuthTokens, Project, ProjectSearchParams, ProjectListResponse, Workflow, WorkflowSearchParams, WorkflowListResponse, WorkflowTemplate, WorkflowTemplateSearchParams, WorkflowTemplateListResponse, StartWorkflowConfiguration, WorkflowStartResponse, FetchWorkflowRunResponse, FetchWorkflowRunListItem, SearchParams } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Client for interacting with Sembix Studio API endpoints.
|
|
4
|
+
* Handles authenticated requests, automatic token refresh, and error handling.
|
|
5
|
+
*/
|
|
6
|
+
export declare class StudioApiClient {
|
|
7
|
+
private profile;
|
|
8
|
+
private tokens;
|
|
9
|
+
private cognitoService;
|
|
10
|
+
constructor(profile: StudioProfile, tokens: StudioAuthTokens);
|
|
11
|
+
/**
|
|
12
|
+
* Search for projects by name or IDs.
|
|
13
|
+
* @param params - Search parameters (projectName, projectIds)
|
|
14
|
+
* @returns Promise resolving to project list response
|
|
15
|
+
*/
|
|
16
|
+
searchProjects(params?: ProjectSearchParams): Promise<ProjectListResponse>;
|
|
17
|
+
/**
|
|
18
|
+
* Get a specific project by ID.
|
|
19
|
+
* Note: API doesn't have a direct GET endpoint, so we search with projectIds filter.
|
|
20
|
+
* @param projectId - The project ID
|
|
21
|
+
* @returns Promise resolving to project or null if not found
|
|
22
|
+
*/
|
|
23
|
+
getProject(projectId: string): Promise<Project | null>;
|
|
24
|
+
/**
|
|
25
|
+
* List workflows with optional filters.
|
|
26
|
+
* @param params - Filter parameters (projectId, workflowId, workflowTemplateIds, parentWorkflowId)
|
|
27
|
+
* @returns Promise resolving to workflow list response
|
|
28
|
+
*/
|
|
29
|
+
listWorkflows(params?: WorkflowSearchParams): Promise<WorkflowListResponse>;
|
|
30
|
+
/**
|
|
31
|
+
* Get a specific workflow by ID.
|
|
32
|
+
* @param projectId - The project ID
|
|
33
|
+
* @param workflowId - The workflow ID
|
|
34
|
+
* @returns Promise resolving to workflow details
|
|
35
|
+
*/
|
|
36
|
+
getWorkflow(projectId: string, workflowId: string): Promise<Workflow>;
|
|
37
|
+
/**
|
|
38
|
+
* Find a workflow by name within a project.
|
|
39
|
+
* Searches all workflows in the project and returns the first match.
|
|
40
|
+
* API returns only parent workflows by default (unless parentWorkflowId is specified).
|
|
41
|
+
* @param projectId - The project ID
|
|
42
|
+
* @param workflowName - The workflow name (case-insensitive)
|
|
43
|
+
* @returns Promise resolving to workflow or null if not found
|
|
44
|
+
*/
|
|
45
|
+
findWorkflowByName(projectId: string, workflowName: string): Promise<Workflow | null>;
|
|
46
|
+
/**
|
|
47
|
+
* Resolves a parent workflow to its published child workflow with the highest version.
|
|
48
|
+
* This is required because workflow lists show parent workflows, but you must start child workflows.
|
|
49
|
+
* @param projectId - The project ID
|
|
50
|
+
* @param parentWorkflowId - The parent workflow ID to resolve
|
|
51
|
+
* @returns Promise resolving to the published child workflow with highest version
|
|
52
|
+
* @throws Error if no published children found
|
|
53
|
+
*/
|
|
54
|
+
resolveToPublishedChild(projectId: string, parentWorkflowId: string): Promise<Workflow>;
|
|
55
|
+
/**
|
|
56
|
+
* Start a workflow execution.
|
|
57
|
+
* @param projectId - The project ID
|
|
58
|
+
* @param workflowId - The workflow ID
|
|
59
|
+
* @param startConfiguration - Workflow start configuration with input variables
|
|
60
|
+
* @returns Promise resolving to workflow start response with runId and taskArn
|
|
61
|
+
*/
|
|
62
|
+
startWorkflow(projectId: string, workflowId: string, startConfiguration: StartWorkflowConfiguration): Promise<WorkflowStartResponse>;
|
|
63
|
+
/**
|
|
64
|
+
* Get details of a specific workflow run.
|
|
65
|
+
* @param workflowId - The workflow ID
|
|
66
|
+
* @param runId - The run ID
|
|
67
|
+
* @returns Promise resolving to workflow run details
|
|
68
|
+
*/
|
|
69
|
+
getWorkflowRun(workflowId: string, runId: string): Promise<FetchWorkflowRunResponse>;
|
|
70
|
+
/**
|
|
71
|
+
* Search workflow runs with optional filters.
|
|
72
|
+
* @param params - Search parameters for filtering and pagination
|
|
73
|
+
* @returns Promise resolving to list of workflow runs
|
|
74
|
+
*/
|
|
75
|
+
searchWorkflowRuns(params: SearchParams): Promise<FetchWorkflowRunListItem>;
|
|
76
|
+
/**
|
|
77
|
+
* Stop a running workflow.
|
|
78
|
+
* @param projectId - The project ID
|
|
79
|
+
* @param workflowId - The workflow ID
|
|
80
|
+
* @param runId - The run ID to stop
|
|
81
|
+
* @returns Promise resolving when workflow is stopped
|
|
82
|
+
*/
|
|
83
|
+
stopWorkflowRun(projectId: string, workflowId: string, runId: string): Promise<void>;
|
|
84
|
+
/**
|
|
85
|
+
* Get a specific workflow template by ID.
|
|
86
|
+
* @param projectId - The project ID
|
|
87
|
+
* @param templateId - The workflow template ID
|
|
88
|
+
* @returns Promise resolving to template details
|
|
89
|
+
*/
|
|
90
|
+
getWorkflowTemplate(projectId: string, templateId: string): Promise<WorkflowTemplate>;
|
|
91
|
+
/**
|
|
92
|
+
* List workflow templates with optional filters.
|
|
93
|
+
* @param params - Filter parameters (templateIds, category, tags)
|
|
94
|
+
* @returns Promise resolving to template list response
|
|
95
|
+
*/
|
|
96
|
+
listWorkflowTemplates(params?: WorkflowTemplateSearchParams): Promise<WorkflowTemplateListResponse>;
|
|
97
|
+
/**
|
|
98
|
+
* Get workflow template for a specific workflow.
|
|
99
|
+
* Convenience method that fetches workflow and then its template.
|
|
100
|
+
* @param projectId - The project ID
|
|
101
|
+
* @param workflowId - The workflow ID
|
|
102
|
+
* @returns Promise resolving to template details or null if workflow has no template
|
|
103
|
+
*/
|
|
104
|
+
getWorkflowTemplateForWorkflow(projectId: string, workflowId: string): Promise<WorkflowTemplate | null>;
|
|
105
|
+
/**
|
|
106
|
+
* Make an authenticated HTTP request to the Studio API.
|
|
107
|
+
* Handles token refresh on 401 responses and retries the request.
|
|
108
|
+
* @param method - HTTP method
|
|
109
|
+
* @param path - API endpoint path
|
|
110
|
+
* @param body - Optional request body
|
|
111
|
+
* @param queryParams - Optional query parameters
|
|
112
|
+
* @returns Promise resolving to parsed response
|
|
113
|
+
*/
|
|
114
|
+
private _makeRequest;
|
|
115
|
+
/**
|
|
116
|
+
* Handle HTTP response, parsing JSON or throwing errors.
|
|
117
|
+
* @param response - Fetch response object
|
|
118
|
+
* @returns Promise resolving to parsed response body
|
|
119
|
+
*/
|
|
120
|
+
private _handleResponse;
|
|
121
|
+
/**
|
|
122
|
+
* Refresh authentication tokens and update stored tokens.
|
|
123
|
+
* @throws Error if token refresh fails
|
|
124
|
+
*/
|
|
125
|
+
private _refreshTokensAndRetry;
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=studio-api-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"studio-api-client.d.ts","sourceRoot":"","sources":["../../src/services/studio-api-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,gBAAgB,EAChB,OAAO,EACP,mBAAmB,EACnB,mBAAmB,EACnB,QAAQ,EACR,oBAAoB,EACpB,oBAAoB,EACpB,gBAAgB,EAChB,4BAA4B,EAC5B,4BAA4B,EAC5B,0BAA0B,EAC1B,qBAAqB,EACrB,wBAAwB,EACxB,wBAAwB,EACxB,YAAY,EACb,MAAM,aAAa,CAAC;AAKrB;;;GAGG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,MAAM,CAAmB;IACjC,OAAO,CAAC,cAAc,CAAqB;gBAE/B,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,gBAAgB;IAM5D;;;;OAIG;IACG,cAAc,CAAC,MAAM,GAAE,mBAAwB,GAAG,OAAO,CAAC,mBAAmB,C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