@solidactions/cli 3.1.0 → 3.3.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/dist/command-manifest.json +4101 -0
- package/dist/commands/connection-list.js +61 -0
- package/dist/commands/device-login.js +7 -5
- package/dist/commands/env-reset.js +60 -0
- package/dist/commands/env-set.js +19 -2
- package/dist/commands/login.js +201 -44
- package/dist/index.js +57 -28
- package/dist/utils/api.js +89 -5
- package/dist/utils/command-manifest.js +221 -0
- package/dist/utils/config-write-target.js +47 -10
- package/package.json +2 -2
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.connectionList = connectionList;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
const api_1 = require("../utils/api");
|
|
10
|
+
const table_1 = require("../utils/table");
|
|
11
|
+
const ERROR_SNIPPET_WIDTH = 40;
|
|
12
|
+
function connectionStatus(connection) {
|
|
13
|
+
const status = connection.status || '?';
|
|
14
|
+
const error = connection.error_message?.trim();
|
|
15
|
+
if (!error) {
|
|
16
|
+
return status;
|
|
17
|
+
}
|
|
18
|
+
return `${status} — ${(0, table_1.truncateCell)((0, table_1.sanitizeCell)(error), ERROR_SNIPPET_WIDTH)}`;
|
|
19
|
+
}
|
|
20
|
+
async function connectionList() {
|
|
21
|
+
const config = await (0, api_1.requireConfigWithWorkspace)();
|
|
22
|
+
try {
|
|
23
|
+
const response = await axios_1.default.get(`${config.host}/api/v1/connections`, {
|
|
24
|
+
headers: (0, api_1.getApiHeaders)(config),
|
|
25
|
+
});
|
|
26
|
+
const connections = response.data.data || [];
|
|
27
|
+
if (connections.length === 0) {
|
|
28
|
+
console.log(chalk_1.default.gray('No connections found.'));
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
console.log(chalk_1.default.blue('Connections:\n'));
|
|
32
|
+
const rows = connections.map((connection) => [
|
|
33
|
+
connection.name || '?',
|
|
34
|
+
connection.provider || '?',
|
|
35
|
+
connectionStatus(connection),
|
|
36
|
+
connection.last_used_at || '-',
|
|
37
|
+
]);
|
|
38
|
+
const lines = (0, table_1.renderTable)(['NAME', 'PROVIDER', 'STATUS', 'LAST USED'], rows, {
|
|
39
|
+
minWidths: [24, 14, 20],
|
|
40
|
+
});
|
|
41
|
+
console.log(chalk_1.default.gray(lines[0]));
|
|
42
|
+
console.log(chalk_1.default.gray(lines[1]));
|
|
43
|
+
for (const line of lines.slice(2)) {
|
|
44
|
+
console.log(line);
|
|
45
|
+
}
|
|
46
|
+
console.log('');
|
|
47
|
+
console.log(chalk_1.default.gray(`${connections.length} connection(s)`));
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
if (error.response?.status === 401) {
|
|
51
|
+
console.error(chalk_1.default.red('Authentication failed. Run "solidactions login --global" to re-configure.'));
|
|
52
|
+
}
|
|
53
|
+
else if (error.response) {
|
|
54
|
+
console.error(chalk_1.default.red(`Failed: ${error.response.status}`), error.response.data);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
console.error(chalk_1.default.red('Connection failed:'), error.message);
|
|
58
|
+
}
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -8,6 +8,7 @@ exports.pollForToken = pollForToken;
|
|
|
8
8
|
exports.deviceLogin = deviceLogin;
|
|
9
9
|
const axios_1 = __importDefault(require("axios"));
|
|
10
10
|
const chalk_1 = __importDefault(require("chalk"));
|
|
11
|
+
require("../utils/api");
|
|
11
12
|
const workspace_lookup_1 = require("../utils/workspace-lookup");
|
|
12
13
|
const login_1 = require("./login");
|
|
13
14
|
// Public device-flow client id — not a secret; matches the server-seeded
|
|
@@ -74,6 +75,7 @@ async function pollForToken(host, clientId, deviceCode, intervalSeconds, expires
|
|
|
74
75
|
async function deviceLogin(options) {
|
|
75
76
|
const resolved = (0, login_1.resolveLoginHost)(options);
|
|
76
77
|
const host = resolved.host;
|
|
78
|
+
const preflight = await (0, login_1.preflightDeviceLoginWrite)(options);
|
|
77
79
|
console.log(chalk_1.default.blue('Requesting device authorization...'));
|
|
78
80
|
const code = await requestDeviceCode(host);
|
|
79
81
|
// Deliberately the bare verification_uri, never verification_uri_complete:
|
|
@@ -95,8 +97,7 @@ async function deviceLogin(options) {
|
|
|
95
97
|
return;
|
|
96
98
|
}
|
|
97
99
|
const config = { host, apiKey: token.access_token };
|
|
98
|
-
|
|
99
|
-
// exactly as login() does via the shared completeLogin() helper.
|
|
100
|
+
await (0, login_1.persistPreflightedLoginCredential)(config, preflight, options);
|
|
100
101
|
let workspaces;
|
|
101
102
|
let scope;
|
|
102
103
|
try {
|
|
@@ -104,13 +105,14 @@ async function deviceLogin(options) {
|
|
|
104
105
|
}
|
|
105
106
|
catch (e) {
|
|
106
107
|
if (e.response?.status === 401) {
|
|
107
|
-
console.error(chalk_1.default.red(`
|
|
108
|
+
console.error(chalk_1.default.red(`Authentication was saved to ${preflight.targetPath}, but the server rejected it during workspace discovery.`));
|
|
108
109
|
}
|
|
109
110
|
else {
|
|
110
|
-
console.error(chalk_1.default.red(`
|
|
111
|
+
console.error(chalk_1.default.red(`Authentication was saved to ${preflight.targetPath}, but workspace discovery failed: ${e.message}`));
|
|
111
112
|
}
|
|
113
|
+
console.error(chalk_1.default.yellow('Run `solidactions workspace set <name>` when workspace access is available.'));
|
|
112
114
|
process.exit(1);
|
|
113
115
|
return;
|
|
114
116
|
}
|
|
115
|
-
await (0, login_1.completeLogin)(config, workspaces, options, scope);
|
|
117
|
+
await (0, login_1.completeLogin)(config, workspaces, options, scope, preflight);
|
|
116
118
|
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.envReset = envReset;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
const api_1 = require("../utils/api");
|
|
10
|
+
function describeRestoredSource(mapping) {
|
|
11
|
+
const sourceType = mapping.source_type || mapping.source || 'unknown';
|
|
12
|
+
if (sourceType === 'oauth_connection') {
|
|
13
|
+
const connection = mapping.oauth_connection_name || mapping.oauth_connection_id;
|
|
14
|
+
return connection ? `oauth_connection "${connection}"` : 'oauth_connection';
|
|
15
|
+
}
|
|
16
|
+
if (sourceType === 'global_variable') {
|
|
17
|
+
const globalKey = mapping.global_variable_key;
|
|
18
|
+
return globalKey ? `global_variable "${globalKey}"` : 'global_variable';
|
|
19
|
+
}
|
|
20
|
+
return sourceType;
|
|
21
|
+
}
|
|
22
|
+
async function envReset(projectName, key, options = {}) {
|
|
23
|
+
const config = await (0, api_1.requireConfigWithWorkspace)();
|
|
24
|
+
const environment = options.env || 'dev';
|
|
25
|
+
const projectSlug = environment === 'production'
|
|
26
|
+
? projectName
|
|
27
|
+
: `${projectName}-${environment}`;
|
|
28
|
+
try {
|
|
29
|
+
const listResponse = await axios_1.default.get(`${config.host}/api/v1/projects/${projectSlug}/variable-mappings`, { headers: (0, api_1.getApiHeaders)(config) });
|
|
30
|
+
const mappings = listResponse.data || [];
|
|
31
|
+
const mapping = mappings.find((candidate) => candidate.env_name === key);
|
|
32
|
+
if (!mapping) {
|
|
33
|
+
console.error(chalk_1.default.red(`Variable "${key}" has no variable mapping in project "${projectName}" (${environment}).`));
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
const resetResponse = await axios_1.default.post(`${config.host}/api/v1/projects/${projectSlug}/variable-mappings/${mapping.id}/reset`, {}, { headers: (0, api_1.getApiHeaders)(config, 'application/json') });
|
|
37
|
+
const restored = resetResponse.data.mapping;
|
|
38
|
+
console.log(chalk_1.default.green(`Variable "${key}" reset to ${describeRestoredSource(restored)} ` +
|
|
39
|
+
`in project "${projectName}" (${environment}).`));
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
if (error.response) {
|
|
43
|
+
if (error.response.status === 401) {
|
|
44
|
+
console.error(chalk_1.default.red('Authentication failed. Run "solidactions login --global" to re-configure.'));
|
|
45
|
+
}
|
|
46
|
+
else if (error.response.status === 404) {
|
|
47
|
+
const envsList = await (0, api_1.describeProjectEnvironments)(config, projectName);
|
|
48
|
+
console.error(chalk_1.default.red(`Project "${projectName}" has no ${environment} environment` +
|
|
49
|
+
`${envsList ? ` (exists in: ${envsList})` : ''}.`));
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
console.error(chalk_1.default.red(`Failed: ${error.response.status}`), error.response.data);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
console.error(chalk_1.default.red('Connection failed:'), error.message);
|
|
57
|
+
}
|
|
58
|
+
process.exit(1);
|
|
59
|
+
}
|
|
60
|
+
}
|
package/dist/commands/env-set.js
CHANGED
|
@@ -24,7 +24,12 @@ exports.GLOBAL_ENV_SCOPE_NOTE = [
|
|
|
24
24
|
].join('\n');
|
|
25
25
|
async function envSet(keyOrProject, valueOrKey, valueIfProject, options = {}) {
|
|
26
26
|
// Detect mode based on arguments
|
|
27
|
-
const
|
|
27
|
+
const isOauthConnectionMode = options.oauthConnection !== undefined;
|
|
28
|
+
const isProjectMode = valueIfProject !== undefined || isOauthConnectionMode;
|
|
29
|
+
if (isOauthConnectionMode && (valueIfProject !== undefined || options.global)) {
|
|
30
|
+
process.stderr.write(chalk_1.default.red('env set: --oauth-connection binds a project key; give <project> <KEY> and no value\n'));
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
28
33
|
// Jordan Wall #4 (Sweep C, → 1.23.0): a 2-positional-arg call used to fall
|
|
29
34
|
// through to GLOBAL scope silently, so a typo'd `env set KEY VALUE` (meant
|
|
30
35
|
// for a project) wrote a global var the workflow never reads. Global
|
|
@@ -65,6 +70,17 @@ async function envSet(keyOrProject, valueOrKey, valueIfProject, options = {}) {
|
|
|
65
70
|
// Auto-detect secrets
|
|
66
71
|
const isSecret = options.secret || /secret|key|token|password|credential/i.test(key);
|
|
67
72
|
try {
|
|
73
|
+
if (isOauthConnectionMode) {
|
|
74
|
+
await axios_1.default.post(`${config.host}/api/v1/projects/${projectSlug}/variable-mappings`, {
|
|
75
|
+
project_key: key,
|
|
76
|
+
oauth_connection_name: options.oauthConnection,
|
|
77
|
+
}, {
|
|
78
|
+
headers: (0, api_1.getApiHeaders)(config, 'application/json'),
|
|
79
|
+
});
|
|
80
|
+
console.log(chalk_1.default.green(`Variable "${key}" bound to OAuth connection "${options.oauthConnection}" ` +
|
|
81
|
+
`in project "${projectName}" (${environment}).`));
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
68
84
|
// Check if variable already has a value
|
|
69
85
|
if (!options.yes) {
|
|
70
86
|
const mappingsResponse = await axios_1.default.get(`${config.host}/api/v1/projects/${projectSlug}/variable-mappings?reveal=true`, { headers: (0, api_1.getApiHeaders)(config) });
|
|
@@ -110,7 +126,8 @@ async function envSet(keyOrProject, valueOrKey, valueIfProject, options = {}) {
|
|
|
110
126
|
}
|
|
111
127
|
else if (error.response.status === 404) {
|
|
112
128
|
const envsList = await (0, api_1.describeProjectEnvironments)(config, projectName);
|
|
113
|
-
console.error(chalk_1.default.red(`Project "${projectName}" has no ${environment} environment${envsList ? ` (exists in: ${envsList})` : ''}.`
|
|
129
|
+
console.error(chalk_1.default.red(`Project "${projectName}" has no ${environment} environment${envsList ? ` (exists in: ${envsList})` : ''}.`
|
|
130
|
+
+ `\nRun 'solidactions project deploy ${projectName} -e ${environment} --create' first.`));
|
|
114
131
|
}
|
|
115
132
|
else if (error.response.status === 422) {
|
|
116
133
|
console.error(chalk_1.default.red((0, api_1.formatValidationError)(error.response.data)));
|
package/dist/commands/login.js
CHANGED
|
@@ -3,19 +3,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.API_KEY_PROMPT = void 0;
|
|
6
|
+
exports.DEVICE_LOGIN_REFUSAL_MESSAGE = exports.API_KEY_PROMPT = void 0;
|
|
7
7
|
exports.resolveLoginApiKey = resolveLoginApiKey;
|
|
8
8
|
exports.getConfig = getConfig;
|
|
9
9
|
exports.saveConfig = saveConfig;
|
|
10
10
|
exports.clearConfig = clearConfig;
|
|
11
11
|
exports.resolveLoginHost = resolveLoginHost;
|
|
12
12
|
exports.backupPathFor = backupPathFor;
|
|
13
|
+
exports.preflightDeviceLoginWrite = preflightDeviceLoginWrite;
|
|
14
|
+
exports.persistPreflightedLoginCredential = persistPreflightedLoginCredential;
|
|
13
15
|
exports.loginHostLines = loginHostLines;
|
|
16
|
+
exports.selectWorkspaceInteractively = selectWorkspaceInteractively;
|
|
14
17
|
exports.completeLogin = completeLogin;
|
|
15
18
|
exports.login = login;
|
|
16
19
|
exports.logout = logout;
|
|
17
20
|
exports.whoami = whoami;
|
|
18
21
|
const fs_1 = __importDefault(require("fs"));
|
|
22
|
+
const path_1 = __importDefault(require("path"));
|
|
19
23
|
const readline_1 = __importDefault(require("readline"));
|
|
20
24
|
const chalk_1 = __importDefault(require("chalk"));
|
|
21
25
|
const prompts_1 = __importDefault(require("prompts"));
|
|
@@ -101,20 +105,120 @@ function backupPathFor(targetPath, now = new Date()) {
|
|
|
101
105
|
const LOGIN_REFUSAL_MESSAGE = 'Refusing to write config non-interactively. Pass --global to update the machine-wide config ' +
|
|
102
106
|
'at ~/.solidactions/config.json (a backup is kept if one exists), or --local to write ' +
|
|
103
107
|
'./.solidactions/config.json for just this directory.';
|
|
108
|
+
exports.DEVICE_LOGIN_REFUSAL_MESSAGE = 'No TTY detected. Re-run with the config destination made explicit: '
|
|
109
|
+
+ 'solidactions login --device --global --workspace <name>';
|
|
110
|
+
function nearestExistingPath(startPath) {
|
|
111
|
+
let candidate = startPath;
|
|
112
|
+
while (!fs_1.default.existsSync(candidate)) {
|
|
113
|
+
const parent = path_1.default.dirname(candidate);
|
|
114
|
+
if (parent === candidate)
|
|
115
|
+
break;
|
|
116
|
+
candidate = parent;
|
|
117
|
+
}
|
|
118
|
+
return candidate;
|
|
119
|
+
}
|
|
120
|
+
function failWritePreflight(targetPath, reason) {
|
|
121
|
+
console.error(chalk_1.default.red(`Cannot save configuration to ${targetPath}: ${reason}. `
|
|
122
|
+
+ 'Choose a writable destination with --local or --global and retry.'));
|
|
123
|
+
process.exit(1);
|
|
124
|
+
}
|
|
125
|
+
function assertDirectoryWritable(directoryPath, targetPath) {
|
|
126
|
+
let stat;
|
|
127
|
+
try {
|
|
128
|
+
stat = fs_1.default.statSync(directoryPath);
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
failWritePreflight(targetPath, `could not inspect ${directoryPath} (${error.message})`);
|
|
132
|
+
}
|
|
133
|
+
if (!stat.isDirectory()) {
|
|
134
|
+
failWritePreflight(targetPath, `${directoryPath} is not a directory`);
|
|
135
|
+
}
|
|
136
|
+
// accessSync is authoritative for the current identity. The mode check
|
|
137
|
+
// also catches deliberately read-only fixtures when tests run as root.
|
|
138
|
+
if ((stat.mode & 0o222) === 0 || (stat.mode & 0o111) === 0) {
|
|
139
|
+
failWritePreflight(targetPath, `${directoryPath} is not writable/searchable`);
|
|
140
|
+
}
|
|
141
|
+
try {
|
|
142
|
+
fs_1.default.accessSync(directoryPath, fs_1.default.constants.W_OK | fs_1.default.constants.X_OK);
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
failWritePreflight(targetPath, `${directoryPath} is not writable/searchable`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Resolve and validate the device-login destination before requesting a
|
|
150
|
+
* browser approval. The returned path is reused after authorization.
|
|
151
|
+
*/
|
|
152
|
+
async function preflightDeviceLoginWrite(options, dependencies = {}) {
|
|
153
|
+
const target = await (0, config_write_target_1.decideWriteTarget)(options, undefined, exports.DEVICE_LOGIN_REFUSAL_MESSAGE, {
|
|
154
|
+
isTTY: dependencies.isTTY,
|
|
155
|
+
question: dependencies.destinationQuestion,
|
|
156
|
+
});
|
|
157
|
+
const targetPath = (0, config_write_target_1.pathForTarget)(target);
|
|
158
|
+
if (fs_1.default.existsSync(targetPath)) {
|
|
159
|
+
let stat;
|
|
160
|
+
try {
|
|
161
|
+
stat = fs_1.default.statSync(targetPath);
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
failWritePreflight(targetPath, error.message);
|
|
165
|
+
}
|
|
166
|
+
if (!stat.isFile()) {
|
|
167
|
+
failWritePreflight(targetPath, 'the config path is not a regular file');
|
|
168
|
+
}
|
|
169
|
+
try {
|
|
170
|
+
fs_1.default.accessSync(targetPath, fs_1.default.constants.R_OK);
|
|
171
|
+
}
|
|
172
|
+
catch {
|
|
173
|
+
failWritePreflight(targetPath, 'the existing config is not readable for backup');
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
const existingParent = nearestExistingPath(path_1.default.dirname(targetPath));
|
|
177
|
+
assertDirectoryWritable(existingParent, targetPath);
|
|
178
|
+
let backupPath = null;
|
|
179
|
+
if (fs_1.default.existsSync(targetPath)) {
|
|
180
|
+
backupPath = backupPathFor(targetPath);
|
|
181
|
+
const proceed = await (0, config_write_target_1.confirmOverwrite)(targetPath, backupPath, {
|
|
182
|
+
isTTY: dependencies.isTTY,
|
|
183
|
+
question: dependencies.overwriteQuestion,
|
|
184
|
+
});
|
|
185
|
+
if (!proceed) {
|
|
186
|
+
console.log(chalk_1.default.yellow('Aborted. No changes were made and no device code was requested.'));
|
|
187
|
+
process.exit(0);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return {
|
|
191
|
+
target,
|
|
192
|
+
targetPath,
|
|
193
|
+
backupPath,
|
|
194
|
+
backupCreated: false,
|
|
195
|
+
credentialPersisted: false,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Persist the approved base credential before workspace discovery. Existing
|
|
200
|
+
* device-login configs are backed up exactly once.
|
|
201
|
+
*/
|
|
202
|
+
async function persistPreflightedLoginCredential(config, preflight, options) {
|
|
203
|
+
if (preflight.backupPath && !preflight.backupCreated) {
|
|
204
|
+
fs_1.default.copyFileSync(preflight.targetPath, preflight.backupPath);
|
|
205
|
+
preflight.backupCreated = true;
|
|
206
|
+
console.log(chalk_1.default.gray(`Backup saved to ${preflight.backupPath}`));
|
|
207
|
+
}
|
|
208
|
+
(0, config_1.writeConfigFile)(preflight.targetPath, config);
|
|
209
|
+
preflight.credentialPersisted = true;
|
|
210
|
+
if (preflight.target === 'local') {
|
|
211
|
+
const targetRoot = path_1.default.dirname(path_1.default.dirname(preflight.targetPath));
|
|
212
|
+
await (0, config_write_target_1.ensureGitignoreCovers)(targetRoot, !!options.gitignore);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
104
215
|
function loginHostLines(resolved) {
|
|
105
216
|
if (resolved.isDefault) {
|
|
106
|
-
return [
|
|
107
|
-
`Logging into ${resolved.host} (SolidActions Cloud)`,
|
|
108
|
-
' Self-hosted or local dev? Pass --host <url> (or --dev for http://localhost:8000)',
|
|
109
|
-
];
|
|
217
|
+
return [`Logging into ${resolved.host} (SolidActions Cloud)`];
|
|
110
218
|
}
|
|
111
219
|
return [`Host: ${resolved.host}`];
|
|
112
220
|
}
|
|
113
|
-
|
|
114
|
-
* Prompt the user to pick a workspace from an already-fetched list. Auto-
|
|
115
|
-
* selects when there's exactly one. Returns undefined if none exist.
|
|
116
|
-
*/
|
|
117
|
-
async function selectWorkspaceInteractively(workspaces) {
|
|
221
|
+
async function selectWorkspaceInteractively(workspaces, dependencies = {}) {
|
|
118
222
|
if (workspaces.length === 0) {
|
|
119
223
|
console.log(chalk_1.default.yellow('No workspaces found. Create one at your SolidActions dashboard, then run `solidactions workspace set <name>`.'));
|
|
120
224
|
return undefined;
|
|
@@ -128,41 +232,86 @@ async function selectWorkspaceInteractively(workspaces) {
|
|
|
128
232
|
console.log(` ${chalk_1.default.white(`${i + 1}.`)} ${ws.name}`);
|
|
129
233
|
});
|
|
130
234
|
console.log('');
|
|
131
|
-
const rl =
|
|
132
|
-
|
|
133
|
-
|
|
235
|
+
const rl = dependencies.question
|
|
236
|
+
? null
|
|
237
|
+
: readline_1.default.createInterface({ input: process.stdin, output: process.stdout });
|
|
238
|
+
const question = dependencies.question ?? (async () => {
|
|
239
|
+
if (!rl || rl.closed)
|
|
240
|
+
return undefined;
|
|
241
|
+
return new Promise((resolve) => {
|
|
242
|
+
let answered = false;
|
|
243
|
+
const onClose = () => {
|
|
244
|
+
if (!answered)
|
|
245
|
+
resolve(undefined);
|
|
246
|
+
};
|
|
247
|
+
rl.once('close', onClose);
|
|
248
|
+
rl.question(chalk_1.default.blue('Enter number: '), (answer) => {
|
|
249
|
+
answered = true;
|
|
250
|
+
rl.removeListener('close', onClose);
|
|
251
|
+
resolve(answer);
|
|
252
|
+
});
|
|
253
|
+
});
|
|
134
254
|
});
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
255
|
+
try {
|
|
256
|
+
while (true) {
|
|
257
|
+
const answer = await question();
|
|
258
|
+
if (answer === undefined) {
|
|
259
|
+
console.log(chalk_1.default.yellow('Workspace selection cancelled. Run `solidactions workspace list`, then '
|
|
260
|
+
+ '`solidactions workspace set <name>` when ready.'));
|
|
261
|
+
return undefined;
|
|
262
|
+
}
|
|
263
|
+
const index = parseInt(answer, 10) - 1;
|
|
264
|
+
if (!isNaN(index) && index >= 0 && index < workspaces.length) {
|
|
265
|
+
return workspaces[index];
|
|
266
|
+
}
|
|
267
|
+
console.error(chalk_1.default.red('Invalid selection. Enter one of the numbers shown.'));
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
finally {
|
|
271
|
+
rl?.close();
|
|
140
272
|
}
|
|
141
|
-
return workspaces[index];
|
|
142
273
|
}
|
|
143
274
|
/**
|
|
144
|
-
* Shared tail of
|
|
145
|
-
*
|
|
146
|
-
*
|
|
275
|
+
* Shared tail of API-key and device login: resolve the workspace against an
|
|
276
|
+
* already-fetched list, persist the final config, and print success output.
|
|
277
|
+
* Device login passes its already-written, preflighted destination.
|
|
147
278
|
*/
|
|
148
|
-
async function completeLogin(config, workspaces, options, scope = null) {
|
|
279
|
+
async function completeLogin(config, workspaces, options, scope = null, preflight = null) {
|
|
149
280
|
// Device-flow tokens carry a scope (mode + workspace_ids) that later
|
|
150
281
|
// gates `workspace set`; absent for user-scoped Sanctum PATs.
|
|
151
282
|
if (scope) {
|
|
152
283
|
config.scopeMode = scope.mode;
|
|
153
284
|
config.scopedWorkspaceIds = scope.workspace_ids;
|
|
154
285
|
}
|
|
155
|
-
//
|
|
286
|
+
// Resolve the workspace. Device login has already persisted its base
|
|
287
|
+
// credential; API-key login still resolves before its first write.
|
|
156
288
|
if (options.workspace) {
|
|
157
289
|
const match = (0, workspace_lookup_1.matchWorkspace)(options.workspace, workspaces);
|
|
158
290
|
if (!match) {
|
|
159
|
-
|
|
291
|
+
if (preflight?.credentialPersisted) {
|
|
292
|
+
(0, config_1.writeConfigFile)(preflight.targetPath, config);
|
|
293
|
+
console.error(chalk_1.default.yellow(`Workspace "${options.workspace}" was not found. Authentication was saved to ${preflight.targetPath}.`));
|
|
294
|
+
console.error(chalk_1.default.yellow('Run `solidactions workspace list`, then `solidactions workspace set <name>` to finish setup.'));
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
console.error(chalk_1.default.red(`Workspace "${options.workspace}" not found. Run \`solidactions workspace list\` to list available workspaces.`));
|
|
298
|
+
}
|
|
160
299
|
process.exit(1);
|
|
161
300
|
return;
|
|
162
301
|
}
|
|
163
302
|
config.workspace = match.slug ?? match.name;
|
|
164
303
|
config.workspaceId = match.id;
|
|
165
304
|
}
|
|
305
|
+
else if (workspaces.length === 1) {
|
|
306
|
+
const selected = workspaces[0];
|
|
307
|
+
console.log(chalk_1.default.gray(`Auto-selected workspace: ${selected.name}`));
|
|
308
|
+
config.workspace = selected.slug ?? selected.name;
|
|
309
|
+
config.workspaceId = selected.id;
|
|
310
|
+
}
|
|
311
|
+
else if (workspaces.length === 0) {
|
|
312
|
+
console.log(chalk_1.default.yellow('No workspaces found. Create one at your SolidActions dashboard, then '
|
|
313
|
+
+ 'run `solidactions workspace set <name>`.'));
|
|
314
|
+
}
|
|
166
315
|
else if (process.stdin.isTTY) {
|
|
167
316
|
const selected = await selectWorkspaceInteractively(workspaces);
|
|
168
317
|
if (selected) {
|
|
@@ -171,29 +320,37 @@ async function completeLogin(config, workspaces, options, scope = null) {
|
|
|
171
320
|
}
|
|
172
321
|
}
|
|
173
322
|
else {
|
|
174
|
-
console.log(chalk_1.default.yellow('
|
|
323
|
+
console.log(chalk_1.default.yellow('Multiple workspaces are available, so no workspace was selected. '
|
|
324
|
+
+ 'Run `solidactions workspace list`, then `solidactions workspace set <name>`.'));
|
|
175
325
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
const wouldChange = existingRaw !== null && existingRaw.trim() !== JSON.stringify(config, null, 2).trim();
|
|
181
|
-
if (wouldChange) {
|
|
182
|
-
const backupPath = backupPathFor(targetPath);
|
|
183
|
-
const proceed = await (0, config_write_target_1.confirmOverwrite)(targetPath, backupPath);
|
|
184
|
-
if (!proceed) {
|
|
185
|
-
console.log(chalk_1.default.yellow('Aborted. No changes were made.'));
|
|
186
|
-
process.exit(0);
|
|
187
|
-
}
|
|
188
|
-
fs_1.default.copyFileSync(targetPath, backupPath);
|
|
189
|
-
console.log(chalk_1.default.gray(`Backup saved to ${backupPath}`));
|
|
326
|
+
let savedTargetPath;
|
|
327
|
+
if (preflight) {
|
|
328
|
+
savedTargetPath = preflight.targetPath;
|
|
329
|
+
(0, config_1.writeConfigFile)(preflight.targetPath, config);
|
|
190
330
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
331
|
+
else {
|
|
332
|
+
const target = await (0, config_write_target_1.decideWriteTarget)({ local: options.local, global: options.global }, undefined, LOGIN_REFUSAL_MESSAGE);
|
|
333
|
+
const targetPath = (0, config_write_target_1.pathForTarget)(target);
|
|
334
|
+
savedTargetPath = targetPath;
|
|
335
|
+
const existingRaw = fs_1.default.existsSync(targetPath) ? fs_1.default.readFileSync(targetPath, 'utf-8') : null;
|
|
336
|
+
const wouldChange = existingRaw !== null && existingRaw.trim() !== JSON.stringify(config, null, 2).trim();
|
|
337
|
+
if (wouldChange) {
|
|
338
|
+
const backupPath = backupPathFor(targetPath);
|
|
339
|
+
const proceed = await (0, config_write_target_1.confirmOverwrite)(targetPath, backupPath);
|
|
340
|
+
if (!proceed) {
|
|
341
|
+
console.log(chalk_1.default.yellow('Aborted. No changes were made.'));
|
|
342
|
+
process.exit(0);
|
|
343
|
+
}
|
|
344
|
+
fs_1.default.copyFileSync(targetPath, backupPath);
|
|
345
|
+
console.log(chalk_1.default.gray(`Backup saved to ${backupPath}`));
|
|
346
|
+
}
|
|
347
|
+
(0, config_1.writeConfigFile)(targetPath, config);
|
|
348
|
+
if (target === 'local') {
|
|
349
|
+
await (0, config_write_target_1.ensureGitignoreCovers)(process.cwd(), !!options.gitignore);
|
|
350
|
+
}
|
|
194
351
|
}
|
|
195
352
|
console.log(chalk_1.default.green('Logged in successfully!'));
|
|
196
|
-
console.log(chalk_1.default.gray(`Configuration saved to ${
|
|
353
|
+
console.log(chalk_1.default.gray(`Configuration saved to ${savedTargetPath}`));
|
|
197
354
|
console.log('');
|
|
198
355
|
console.log(chalk_1.default.blue('Next step — scaffold a new project (includes AI tooling):'));
|
|
199
356
|
console.log(chalk_1.default.gray(' solidactions init <project-name> Creates ./<project-name>/ with scaffold + AI skills'));
|