@flatkey-ai/cli 0.1.23 → 0.1.25
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/package.json +1 -1
- package/src/cli.js +46 -12
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -267,6 +267,7 @@ async function handleLogin(command, deps) {
|
|
|
267
267
|
});
|
|
268
268
|
const pollData = poll?.data ?? poll;
|
|
269
269
|
if (pollData?.status === "approved") {
|
|
270
|
+
const account = accountFromAuthData(pollData);
|
|
270
271
|
if (!pollData.api_key) {
|
|
271
272
|
const saved = await readConfig(deps.configDir);
|
|
272
273
|
if (typeof saved?.apiKey === "string" && saved.apiKey.trim() !== "") {
|
|
@@ -276,7 +277,7 @@ async function handleLogin(command, deps) {
|
|
|
276
277
|
deviceId,
|
|
277
278
|
userId: pollData.user_id ?? saved.auth?.userId,
|
|
278
279
|
tokenId: pollData.token_id ?? saved.auth?.tokenId,
|
|
279
|
-
account:
|
|
280
|
+
account: account ?? saved.auth?.account,
|
|
280
281
|
loginAt: Math.floor(Date.now() / 1000),
|
|
281
282
|
},
|
|
282
283
|
configDir: deps.configDir,
|
|
@@ -285,9 +286,7 @@ async function handleLogin(command, deps) {
|
|
|
285
286
|
? {
|
|
286
287
|
success: true,
|
|
287
288
|
configPath,
|
|
288
|
-
|
|
289
|
-
userId: pollData.user_id ?? saved.auth?.userId,
|
|
290
|
-
account: accountFromAuthData(pollData) ?? saved.auth?.account,
|
|
289
|
+
account: stripDisplayOnlyIds(account ?? saved.auth?.account),
|
|
291
290
|
reusedConfig: true,
|
|
292
291
|
}
|
|
293
292
|
: `Flatkey CLI already authorized. Saved config: ${configPath}`;
|
|
@@ -300,7 +299,7 @@ async function handleLogin(command, deps) {
|
|
|
300
299
|
deviceId,
|
|
301
300
|
userId: pollData.user_id,
|
|
302
301
|
tokenId: pollData.token_id,
|
|
303
|
-
account
|
|
302
|
+
account,
|
|
304
303
|
loginAt: Math.floor(Date.now() / 1000),
|
|
305
304
|
},
|
|
306
305
|
configDir: deps.configDir,
|
|
@@ -309,9 +308,7 @@ async function handleLogin(command, deps) {
|
|
|
309
308
|
? {
|
|
310
309
|
success: true,
|
|
311
310
|
configPath,
|
|
312
|
-
|
|
313
|
-
userId: pollData.user_id,
|
|
314
|
-
account: accountFromAuthData(pollData),
|
|
311
|
+
account: stripDisplayOnlyIds(account),
|
|
315
312
|
}
|
|
316
313
|
: `Flatkey CLI authorized. Saved config: ${configPath}`;
|
|
317
314
|
}
|
|
@@ -761,12 +758,13 @@ async function handleUtility(command, deps) {
|
|
|
761
758
|
};
|
|
762
759
|
if (command.group === "credits") return getCredits(options);
|
|
763
760
|
|
|
764
|
-
const status = await getStatus(options);
|
|
761
|
+
const status = sanitizeStatusResponse(await getStatus(options));
|
|
765
762
|
const account = effectiveAccountForStatus({ command, saved, apiKey });
|
|
766
763
|
if (!account || !status || typeof status !== "object" || Array.isArray(status) || status.account !== undefined) {
|
|
767
|
-
return status;
|
|
764
|
+
return command.options.json ? status : extractStatusDisplayFields(status);
|
|
768
765
|
}
|
|
769
|
-
|
|
766
|
+
const mergedStatus = sanitizeStatusResponse({ ...status, account });
|
|
767
|
+
return command.options.json ? mergedStatus : extractStatusDisplayFields(mergedStatus);
|
|
770
768
|
}
|
|
771
769
|
|
|
772
770
|
function effectiveAccountForStatus({ command, saved, apiKey }) {
|
|
@@ -778,16 +776,52 @@ function effectiveAccountForStatus({ command, saved, apiKey }) {
|
|
|
778
776
|
function accountFromAuthData(data) {
|
|
779
777
|
if (!data || typeof data !== "object") return null;
|
|
780
778
|
const email = data.account?.email ?? data.email ?? data.userEmail ?? data.user_email;
|
|
779
|
+
const name = data.account?.name ?? data.name;
|
|
781
780
|
const userId = data.account?.userId ?? data.account?.user_id ?? data.userId ?? data.user_id;
|
|
782
|
-
if (email === undefined && userId === undefined) return null;
|
|
781
|
+
if (email === undefined && name === undefined && userId === undefined) return null;
|
|
783
782
|
return Object.fromEntries(
|
|
784
783
|
Object.entries({
|
|
785
784
|
email,
|
|
785
|
+
name,
|
|
786
786
|
userId,
|
|
787
787
|
}).filter(([, value]) => value !== undefined && value !== null),
|
|
788
788
|
);
|
|
789
789
|
}
|
|
790
790
|
|
|
791
|
+
function sanitizeStatusResponse(status) {
|
|
792
|
+
if (!status || typeof status !== "object") return status;
|
|
793
|
+
if (Array.isArray(status)) {
|
|
794
|
+
return status.map((entry) => sanitizeStatusResponse(entry));
|
|
795
|
+
}
|
|
796
|
+
return Object.fromEntries(
|
|
797
|
+
Object.entries(status)
|
|
798
|
+
.filter(([key]) => !["userId", "user_id"].includes(key))
|
|
799
|
+
.map(([key, value]) => [key, sanitizeStatusResponse(value)]),
|
|
800
|
+
);
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
function stripDisplayOnlyIds(value) {
|
|
804
|
+
if (!value || typeof value !== "object") return value;
|
|
805
|
+
if (Array.isArray(value)) {
|
|
806
|
+
return value.map((entry) => stripDisplayOnlyIds(entry));
|
|
807
|
+
}
|
|
808
|
+
return Object.fromEntries(
|
|
809
|
+
Object.entries(value)
|
|
810
|
+
.filter(([key]) => !["userId", "user_id", "tokenId", "token_id"].includes(key))
|
|
811
|
+
.map(([key, nested]) => [key, stripDisplayOnlyIds(nested)]),
|
|
812
|
+
);
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
function extractStatusDisplayFields(status) {
|
|
816
|
+
if (!status || typeof status !== "object") return status;
|
|
817
|
+
const email = status.email ?? status.account?.email ?? status.user?.email;
|
|
818
|
+
const name = status.name ?? status.account?.name ?? status.user?.name;
|
|
819
|
+
const result = {};
|
|
820
|
+
if (email !== undefined) result.email = email;
|
|
821
|
+
if (name !== undefined) result.name = name;
|
|
822
|
+
return result;
|
|
823
|
+
}
|
|
824
|
+
|
|
791
825
|
async function handleModels(command, deps) {
|
|
792
826
|
const { resolveApiKey, resolveOrigins } = await import("./config.js");
|
|
793
827
|
const { getModels } = await import("./api.js");
|