@flatkey-ai/cli 0.1.13 → 0.1.15
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/README.md +0 -4
- package/package.json +1 -1
- package/src/api.js +6 -2
- package/src/cli.js +24 -2
- package/src/config.js +1 -1
package/README.md
CHANGED
|
@@ -244,10 +244,6 @@ npm test
|
|
|
244
244
|
node bin/flatkey.js --version
|
|
245
245
|
```
|
|
246
246
|
|
|
247
|
-
## Star History
|
|
248
|
-
|
|
249
|
-
[](https://www.star-history.com/#flatkey-ai/flatkey-cli&Date)
|
|
250
|
-
|
|
251
247
|
## Links
|
|
252
248
|
|
|
253
249
|
- Website: [flatkey.ai](https://flatkey.ai/?utm_source=github&utm_medium=readme&utm_campaign=flatkey_cli_links)
|
package/package.json
CHANGED
package/src/api.js
CHANGED
|
@@ -295,11 +295,15 @@ function extractErrorMessage(body, status) {
|
|
|
295
295
|
: typeof body?.message === "string"
|
|
296
296
|
? body.message
|
|
297
297
|
: undefined;
|
|
298
|
-
if (message
|
|
298
|
+
if (isAuthTokenError(message)) return missingApiKeyMessage();
|
|
299
299
|
if (message) return message;
|
|
300
300
|
return `Flatkey API request failed with HTTP ${status}`;
|
|
301
301
|
}
|
|
302
302
|
|
|
303
|
+
function isAuthTokenError(message) {
|
|
304
|
+
return message === "Token not provided" || /^Invalid token\b/i.test(message ?? "");
|
|
305
|
+
}
|
|
306
|
+
|
|
303
307
|
function missingApiKeyMessage() {
|
|
304
|
-
return "Missing Flatkey API key.
|
|
308
|
+
return "Missing or invalid Flatkey API key. Run `flatkey login`, or create a key at https://console.flatkey.ai/keys and run `flatkey onboard --api-key <key>`.";
|
|
305
309
|
}
|
package/src/cli.js
CHANGED
|
@@ -215,7 +215,7 @@ export async function runCommand(command, deps = {}) {
|
|
|
215
215
|
}
|
|
216
216
|
|
|
217
217
|
async function handleLogin(command, deps) {
|
|
218
|
-
const { ensureDeviceId, resolveOrigins, writeAuthConfig } = await import("./config.js");
|
|
218
|
+
const { ensureDeviceId, readConfig, resolveOrigins, writeAuthConfig } = await import("./config.js");
|
|
219
219
|
const { createDeviceAuthorization, pollDeviceAuthorization } = await import("./api.js");
|
|
220
220
|
const deviceId = await ensureDeviceId({ configDir: deps.configDir });
|
|
221
221
|
const version = await readPackageVersion();
|
|
@@ -256,7 +256,29 @@ async function handleLogin(command, deps) {
|
|
|
256
256
|
const pollData = poll?.data ?? poll;
|
|
257
257
|
if (pollData?.status === "approved") {
|
|
258
258
|
if (!pollData.api_key) {
|
|
259
|
-
|
|
259
|
+
const saved = await readConfig(deps.configDir);
|
|
260
|
+
if (typeof saved?.apiKey === "string" && saved.apiKey.trim() !== "") {
|
|
261
|
+
const configPath = await writeAuthConfig({
|
|
262
|
+
apiKey: saved.apiKey,
|
|
263
|
+
auth: {
|
|
264
|
+
deviceId,
|
|
265
|
+
userId: pollData.user_id ?? saved.auth?.userId,
|
|
266
|
+
tokenId: pollData.token_id ?? saved.auth?.tokenId,
|
|
267
|
+
loginAt: Math.floor(Date.now() / 1000),
|
|
268
|
+
},
|
|
269
|
+
configDir: deps.configDir,
|
|
270
|
+
});
|
|
271
|
+
return command.options.json
|
|
272
|
+
? {
|
|
273
|
+
success: true,
|
|
274
|
+
configPath,
|
|
275
|
+
tokenId: pollData.token_id ?? saved.auth?.tokenId,
|
|
276
|
+
userId: pollData.user_id ?? saved.auth?.userId,
|
|
277
|
+
reusedConfig: true,
|
|
278
|
+
}
|
|
279
|
+
: `Flatkey CLI already authorized. Saved config: ${configPath}`;
|
|
280
|
+
}
|
|
281
|
+
throw new Error("Flatkey login was approved, but no API key was returned. The authorization may have already been consumed. Run `flatkey login` again.");
|
|
260
282
|
}
|
|
261
283
|
const configPath = await writeAuthConfig({
|
|
262
284
|
apiKey: pollData.api_key,
|
package/src/config.js
CHANGED
|
@@ -26,7 +26,7 @@ export async function resolveApiKey({
|
|
|
26
26
|
if (env.FLATKEY_API_KEY) return env.FLATKEY_API_KEY;
|
|
27
27
|
|
|
28
28
|
throw new Error(
|
|
29
|
-
"Missing Flatkey API key.
|
|
29
|
+
"Missing or invalid Flatkey API key. Run `flatkey login`, or create a key at https://console.flatkey.ai/keys and run `flatkey onboard --api-key <key>`.",
|
|
30
30
|
);
|
|
31
31
|
}
|
|
32
32
|
|