@mesh-tech/mesh-cli 0.34.2 → 0.34.4

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/bin/mesh.js CHANGED
@@ -3909,6 +3909,7 @@ __export(login_exports, {
3909
3909
  clearContextConfig: () => clearContextConfig,
3910
3910
  clearCredentials: () => clearCredentials,
3911
3911
  decodeJwtPayload: () => decodeJwtPayload,
3912
+ deployableTenants: () => deployableTenants,
3912
3913
  deviceLoginWithReissue: () => deviceLoginWithReissue,
3913
3914
  discoverConfigForContext: () => discoverConfigForContext,
3914
3915
  discoverConfigFromWellKnown: () => discoverConfigFromWellKnown,
@@ -4225,12 +4226,7 @@ function login(context, config) {
4225
4226
  const idPayload = decodeJwtPayload(tokens.id_token);
4226
4227
  const email = idPayload.email ?? idPayload.preferred_username ?? "unknown";
4227
4228
  const sub = idPayload.sub;
4228
- let tenants = [];
4229
- try {
4230
- const accessPayload = decodeJwtPayload(tokens.access_token);
4231
- tenants = accessPayload["urn:mesh:tenants"] ?? [];
4232
- } catch {
4233
- }
4229
+ const tenants = deployableTenants(tokens.id_token, tokens.access_token);
4234
4230
  writeCredentials(context, {
4235
4231
  idToken: tokens.id_token,
4236
4232
  accessToken: tokens.access_token,
@@ -4346,12 +4342,7 @@ async function attemptDeviceCode(context, config) {
4346
4342
  const idPayload = decodeJwtPayload(tokens.id_token);
4347
4343
  const email = idPayload.email ?? idPayload.preferred_username ?? "unknown";
4348
4344
  const sub = idPayload.sub;
4349
- let tenants = [];
4350
- try {
4351
- const accessPayload = decodeJwtPayload(tokens.access_token);
4352
- tenants = accessPayload["urn:mesh:tenants"] ?? [];
4353
- } catch {
4354
- }
4345
+ const tenants = deployableTenants(tokens.id_token, tokens.access_token);
4355
4346
  writeCredentials(context, {
4356
4347
  idToken: tokens.id_token,
4357
4348
  accessToken: tokens.access_token,
@@ -4524,12 +4515,10 @@ async function showStatus(context, config) {
4524
4515
  );
4525
4516
  return;
4526
4517
  }
4527
- let tenants = [];
4518
+ const tenants = deployableTenants(creds.idToken, creds.accessToken);
4528
4519
  let audience = [];
4529
4520
  try {
4530
- const accessPayload = decodeJwtPayload(creds.accessToken);
4531
- tenants = accessPayload["urn:mesh:tenants"] ?? [];
4532
- audience = tokenAudience(accessPayload);
4521
+ audience = tokenAudience(decodeJwtPayload(creds.accessToken));
4533
4522
  } catch {
4534
4523
  }
4535
4524
  logSuccess(`Logged in as ${creds.email ?? "unknown"} (${context})`);
@@ -4552,6 +4541,19 @@ async function showStatus(context, config) {
4552
4541
  );
4553
4542
  }
4554
4543
  }
4544
+ function deployableTenants(idToken, accessToken) {
4545
+ for (const token of [idToken, accessToken]) {
4546
+ if (!token) continue;
4547
+ let claim;
4548
+ try {
4549
+ claim = decodeJwtPayload(token)[DEPLOY_TENANTS_CLAIM];
4550
+ } catch {
4551
+ continue;
4552
+ }
4553
+ if (Array.isArray(claim)) return claim.filter((t) => typeof t === "string");
4554
+ }
4555
+ return [];
4556
+ }
4555
4557
  function tokenAudience(payload) {
4556
4558
  const aud = payload.aud;
4557
4559
  if (typeof aud === "string") return [aud];
@@ -4974,7 +4976,7 @@ function readAllContextConfigs() {
4974
4976
  async function discoverConfigForContext(context) {
4975
4977
  return getContextConfig(context) ?? await discoverConfigGuarded(context);
4976
4978
  }
4977
- var CONFIG_DIR, CONFIG_FILE, CREDENTIALS_FILE, REDIRECT_PORT, REDIRECT_URI, BASE_SCOPES, atomicWriteCounter, MAX_DEVICE_CODES, RESERVED_REGISTRY_CONTEXT, NO_REGISTRY_DEPRECATED, REGISTRY_SEPARATE_HINT;
4979
+ var CONFIG_DIR, CONFIG_FILE, CREDENTIALS_FILE, REDIRECT_PORT, REDIRECT_URI, BASE_SCOPES, atomicWriteCounter, MAX_DEVICE_CODES, DEPLOY_TENANTS_CLAIM, RESERVED_REGISTRY_CONTEXT, NO_REGISTRY_DEPRECATED, REGISTRY_SEPARATE_HINT;
4978
4980
  var init_login = __esm({
4979
4981
  "packages/mesh-cli/src/commands/login.ts"() {
4980
4982
  "use strict";
@@ -4994,6 +4996,7 @@ var init_login = __esm({
4994
4996
  BASE_SCOPES = "openid email profile offline_access urn:zitadel:iam:org:project:id:zitadel:aud";
4995
4997
  atomicWriteCounter = 0;
4996
4998
  MAX_DEVICE_CODES = 3;
4999
+ DEPLOY_TENANTS_CLAIM = "urn:mesh:tenants";
4997
5000
  RESERVED_REGISTRY_CONTEXT = "registry";
4998
5001
  NO_REGISTRY_DEPRECATED = "--no-registry is deprecated and ignored: mesh login no longer touches the registry.";
4999
5002
  REGISTRY_SEPARATE_HINT = "Package registry access is separate from platform sign-in \u2014 run: mesh registry login";