@keystrokehq/cli 0.0.136 → 0.0.137
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/index.mjs +28 -26
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -4781,9 +4781,11 @@ async function runDeviceLogin(options) {
|
|
|
4781
4781
|
});
|
|
4782
4782
|
if (!tokenResult.error) {
|
|
4783
4783
|
const token = tokenResult.data;
|
|
4784
|
+
const organizationId = token.scope?.trim();
|
|
4784
4785
|
return {
|
|
4785
4786
|
accessToken: token.access_token,
|
|
4786
|
-
expiresIn: token.expires_in
|
|
4787
|
+
expiresIn: token.expires_in,
|
|
4788
|
+
organizationId: organizationId || void 0
|
|
4787
4789
|
};
|
|
4788
4790
|
}
|
|
4789
4791
|
const errorPayload = tokenResult.error;
|
|
@@ -8674,6 +8676,15 @@ async function activateOrganization(config, organizationId) {
|
|
|
8674
8676
|
platform.setActiveOrganizationId(membership.organization.id);
|
|
8675
8677
|
return membership;
|
|
8676
8678
|
}
|
|
8679
|
+
function resolveOrganizationIdForLogin(organizations, options = {}) {
|
|
8680
|
+
if (options.organizationRef ?? options.organizationId) return resolveOrganizationRef(organizations, options.organizationRef ?? options.organizationId).organization.id;
|
|
8681
|
+
for (const candidateId of [options.deviceOrganizationId, options.storedOrganizationId]) {
|
|
8682
|
+
const organizationId = candidateId?.trim();
|
|
8683
|
+
if (organizationId && organizations.some((entry) => entry.organization.id === organizationId)) return organizationId;
|
|
8684
|
+
}
|
|
8685
|
+
if (organizations.length === 1) return organizations[0].organization.id;
|
|
8686
|
+
return [...organizations].sort((left, right) => left.organization.slug.localeCompare(right.organization.slug))[0].organization.id;
|
|
8687
|
+
}
|
|
8677
8688
|
async function pickOrganization(config, organizations, organizationRef) {
|
|
8678
8689
|
if (organizationRef) return activateOrganization(config, resolveOrganizationRef(organizations, organizationRef).organization.id);
|
|
8679
8690
|
if (!process.stdin.isTTY) {
|
|
@@ -8697,33 +8708,21 @@ async function selectActiveOrganization(config, options = {}) {
|
|
|
8697
8708
|
async function syncActiveOrganizationAfterLogin(config, options = {}) {
|
|
8698
8709
|
const organizations = await listOrganizations(config);
|
|
8699
8710
|
if (organizations.length === 0) throw new Error(`No organization found — create one at ${getWebUrl(config)}`);
|
|
8700
|
-
|
|
8701
|
-
|
|
8702
|
-
|
|
8703
|
-
|
|
8704
|
-
|
|
8705
|
-
}
|
|
8706
|
-
if (organizations.length === 1) {
|
|
8707
|
-
const membership = await activateOrganization(config, organizations[0].organization.id);
|
|
8708
|
-
process.stdout.write(`Using organization ${membership.organization.name}\n`);
|
|
8709
|
-
return membership;
|
|
8710
|
-
}
|
|
8711
|
-
if (options.organizationRef ?? options.organizationId) {
|
|
8712
|
-
const membership = await pickOrganization(config, organizations, options.organizationRef ?? options.organizationId);
|
|
8713
|
-
process.stdout.write(`Using organization ${membership.organization.name}\n`);
|
|
8714
|
-
return membership;
|
|
8715
|
-
}
|
|
8716
|
-
const membership = await pickOrganization(config, organizations);
|
|
8717
|
-
process.stdout.write(`Using organization ${membership.organization.name}\n`);
|
|
8718
|
-
return membership;
|
|
8711
|
+
return activateOrganization(config, resolveOrganizationIdForLogin(organizations, {
|
|
8712
|
+
organizationRef: options.organizationRef,
|
|
8713
|
+
organizationId: options.organizationId,
|
|
8714
|
+
deviceOrganizationId: options.deviceOrganizationId,
|
|
8715
|
+
storedOrganizationId: config.get("activeOrganizationId")
|
|
8716
|
+
}));
|
|
8719
8717
|
}
|
|
8720
8718
|
async function ensureActiveOrganization(config) {
|
|
8719
|
+
const organizations = await listOrganizations(config);
|
|
8720
|
+
if (organizations.length === 0) throw new Error("No organization found. Run `keystroke auth login` after creating one in the dashboard.");
|
|
8721
8721
|
const storedId = config.get("activeOrganizationId");
|
|
8722
|
-
if (storedId) {
|
|
8722
|
+
if (storedId && organizations.some((entry) => entry.organization.id === storedId)) {
|
|
8723
8723
|
await activateOrganization(config, storedId);
|
|
8724
8724
|
return;
|
|
8725
8725
|
}
|
|
8726
|
-
const organizations = await listOrganizations(config);
|
|
8727
8726
|
if (organizations.length === 1) {
|
|
8728
8727
|
await activateOrganization(config, organizations[0].organization.id);
|
|
8729
8728
|
return;
|
|
@@ -9299,7 +9298,7 @@ function resolveAuthLoginTargets(options, config) {
|
|
|
9299
9298
|
//#endregion
|
|
9300
9299
|
//#region src/commands/auth/login.ts
|
|
9301
9300
|
function registerAuthLoginCommand(auth) {
|
|
9302
|
-
auth.command("login").description("Authenticate via browser device flow").option("--web-url <url>", "Web dashboard origin (omit to use production defaults; local dev: http://localhost:3000)").option("--platform-url <url>", "Platform API origin (derived from web URL when omitted)").option("--org <slug>", "Active organization slug (
|
|
9301
|
+
auth.command("login").description("Authenticate via browser device flow").option("--web-url <url>", "Web dashboard origin (omit to use production defaults; local dev: http://localhost:3000)").option("--platform-url <url>", "Platform API origin (derived from web URL when omitted)").option("--org <slug>", "Active organization slug (overrides browser default)").action(async (options) => {
|
|
9303
9302
|
const config = createCliConfig();
|
|
9304
9303
|
const { webUrl, platformUrl } = resolveAuthLoginTargets(options, config);
|
|
9305
9304
|
config.set("webUrl", webUrl);
|
|
@@ -9312,9 +9311,12 @@ function registerAuthLoginCommand(auth) {
|
|
|
9312
9311
|
});
|
|
9313
9312
|
setAccessToken(platformUrl, result.accessToken);
|
|
9314
9313
|
const user = await getSessionWithBearer(platformUrl, result.accessToken);
|
|
9315
|
-
|
|
9316
|
-
|
|
9317
|
-
|
|
9314
|
+
const membership = await syncActiveOrganizationAfterLogin(config, {
|
|
9315
|
+
organizationRef: options.org,
|
|
9316
|
+
deviceOrganizationId: result.organizationId
|
|
9317
|
+
});
|
|
9318
|
+
if (user) process.stdout.write(`Logged in as ${user.name} (${user.email}) — organization ${membership.organization.name}\n`);
|
|
9319
|
+
else process.stdout.write(`Logged in to ${webUrl} — organization ${membership.organization.name}\n`);
|
|
9318
9320
|
} catch (error) {
|
|
9319
9321
|
process.stderr.write(`${formatCliError(error, "Login failed", {
|
|
9320
9322
|
webUrl,
|