@flatkey-ai/cli 0.1.14 → 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/cli.js +24 -2
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/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,
|