securewithtrace 0.15.0 → 0.16.0

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 CHANGED
@@ -66,12 +66,17 @@ tracecli vulnerabilities list --severity HIGH
66
66
  tracecli auth login
67
67
  tracecli auth status
68
68
  tracecli auth logout
69
- tracecli auth org list
70
- tracecli auth org current
71
- tracecli auth org switch <organization-id-or-slug>
72
69
  ```
73
70
 
74
- When your account belongs to multiple organizations, use `tracecli auth org switch` to set the active organization context used by repository, vulnerability, and pentest commands.
71
+ ### Organization context
72
+
73
+ ```bash
74
+ tracecli org list
75
+ tracecli org current
76
+ tracecli org switch <organization-id-or-slug>
77
+ ```
78
+
79
+ When your account belongs to multiple organizations, use `tracecli org switch` to set the active organization context used by repository, vulnerability, and pentest commands.
75
80
 
76
81
  ### Repositories
77
82
 
package/dist/index.js CHANGED
@@ -22645,6 +22645,7 @@ var PatchCapabilitiesResponseSchema = external_exports.object({
22645
22645
  });
22646
22646
  var OrganizationResponseSchema = external_exports.object({
22647
22647
  organizationId: external_exports.uuid(),
22648
+ workosOrganizationId: external_exports.string().optional(),
22648
22649
  name: external_exports.string(),
22649
22650
  slug: external_exports.string(),
22650
22651
  logoUrl: external_exports.string().nullable(),
@@ -24701,17 +24702,21 @@ async function pollForToken(clientId, deviceCode, options = {}) {
24701
24702
  }
24702
24703
  throw new Error("Authorization timed out. Please try again.");
24703
24704
  }
24704
- async function refreshAccessToken(clientId, refreshToken) {
24705
+ async function refreshAccessToken(clientId, refreshToken, organizationId) {
24706
+ const body = new URLSearchParams({
24707
+ grant_type: "refresh_token",
24708
+ client_id: clientId,
24709
+ refresh_token: refreshToken
24710
+ });
24711
+ if (organizationId && organizationId.trim().length > 0) {
24712
+ body.set("organization_id", organizationId);
24713
+ }
24705
24714
  const response = await fetch(WORKOS_TOKEN_URL, {
24706
24715
  method: "POST",
24707
24716
  headers: {
24708
24717
  "Content-Type": "application/x-www-form-urlencoded"
24709
24718
  },
24710
- body: new URLSearchParams({
24711
- grant_type: "refresh_token",
24712
- client_id: clientId,
24713
- refresh_token: refreshToken
24714
- })
24719
+ body
24715
24720
  });
24716
24721
  if (!response.ok) {
24717
24722
  const text = await response.text();
@@ -24899,6 +24904,24 @@ async function refreshStoredAccessToken() {
24899
24904
  return null;
24900
24905
  }
24901
24906
  }
24907
+ async function refreshStoredAccessTokenForOrganization(workosOrganizationId) {
24908
+ const clientId = getWorkosClientId();
24909
+ const refreshToken = readRefreshToken();
24910
+ if (!clientId || !refreshToken) {
24911
+ return false;
24912
+ }
24913
+ try {
24914
+ const tokenResponse = await refreshAccessToken(clientId, refreshToken, workosOrganizationId);
24915
+ const nextRefreshToken = tokenResponse.refresh_token ?? refreshToken;
24916
+ writeTokens(tokenResponse.access_token, nextRefreshToken);
24917
+ return true;
24918
+ } catch (error48) {
24919
+ if (error48 instanceof Error && (error48.message.includes(" 400 ") || error48.message.includes(" 401 "))) {
24920
+ removeToken();
24921
+ }
24922
+ return false;
24923
+ }
24924
+ }
24902
24925
  async function authenticatedRequest(request) {
24903
24926
  const token = readToken();
24904
24927
  if (!token) {
@@ -25172,9 +25195,15 @@ Use an organization ID or exact slug.`
25172
25195
  };
25173
25196
  }
25174
25197
  return {
25175
- error: `Organization '${input}' not found. Run \`tracecli auth org list\` to see available organizations.`
25198
+ error: `Organization '${input}' not found. Run \`tracecli org list\` to see available organizations.`
25176
25199
  };
25177
25200
  }
25201
+ async function refreshAfterOrganizationSwitch(workosOrganizationId, refreshForOrganization = (organizationId) => refreshStoredAccessTokenForOrganization(organizationId)) {
25202
+ if (!workosOrganizationId || workosOrganizationId.trim().length === 0) {
25203
+ return false;
25204
+ }
25205
+ return refreshForOrganization(workosOrganizationId);
25206
+ }
25178
25207
  function createLoginCommand() {
25179
25208
  return new Command("login").description("Authenticate with Trace").action(async () => {
25180
25209
  const existingToken = readToken();
@@ -25351,10 +25380,18 @@ function createOrgSwitchCommand() {
25351
25380
  process.exit(1);
25352
25381
  }
25353
25382
  writeSelectedOrganizationId(match.organization.organizationId);
25383
+ const refreshed = await refreshAfterOrganizationSwitch(
25384
+ match.organization.workosOrganizationId
25385
+ );
25354
25386
  console.log(
25355
25387
  `Active organization set to ${sanitizeForOutput(match.organization.name)} (${sanitizeForOutput(match.organization.slug)})`
25356
25388
  );
25357
25389
  console.log(` Org ID: ${match.organization.organizationId}`);
25390
+ if (!refreshed) {
25391
+ console.warn(
25392
+ "Token refresh for the selected organization was not completed. If repository commands fail, run `tracecli auth login` again."
25393
+ );
25394
+ }
25358
25395
  });
25359
25396
  }
25360
25397
  function createOrgCommand() {
@@ -25369,7 +25406,7 @@ function createAuthCommand() {
25369
25406
  auth.addCommand(createLoginCommand());
25370
25407
  auth.addCommand(createLogoutCommand());
25371
25408
  auth.addCommand(createStatusCommand());
25372
- auth.addCommand(createOrgCommand());
25409
+ auth.addCommand(createOrgCommand(), { hidden: true });
25373
25410
  return auth;
25374
25411
  }
25375
25412
 
@@ -26746,6 +26783,7 @@ program2.action(() => {
26746
26783
  program2.outputHelp();
26747
26784
  });
26748
26785
  program2.addCommand(createAuthCommand());
26786
+ program2.addCommand(createOrgCommand());
26749
26787
  program2.addCommand(createRepoCommand());
26750
26788
  program2.addCommand(createVulnerabilitiesCommand());
26751
26789
  program2.addCommand(createPentestCommand());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "securewithtrace",
3
- "version": "0.15.0",
3
+ "version": "0.16.0",
4
4
  "description": "Official Trace CLI for vulnerability intelligence in your terminal",
5
5
  "type": "module",
6
6
  "bin": {