securewithtrace 0.19.0 → 0.20.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/dist/index.js +278 -265
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -25624,267 +25624,6 @@ function removeToken() {
|
|
|
25624
25624
|
return removed;
|
|
25625
25625
|
}
|
|
25626
25626
|
|
|
25627
|
-
// src/api-client.ts
|
|
25628
|
-
var readTokenSafe = readToken;
|
|
25629
|
-
var PRODUCTION_API_URL = "https://api.securewithtrace.com";
|
|
25630
|
-
var UNAUTHORIZED_STATUS = 401;
|
|
25631
|
-
function getApiBaseUrl() {
|
|
25632
|
-
const raw = process.env["TRACE_API_URL"];
|
|
25633
|
-
if (!raw) {
|
|
25634
|
-
return PRODUCTION_API_URL;
|
|
25635
|
-
}
|
|
25636
|
-
let parsed;
|
|
25637
|
-
try {
|
|
25638
|
-
parsed = new URL(raw);
|
|
25639
|
-
} catch {
|
|
25640
|
-
console.error(`Invalid TRACE_API_URL: '${raw}' is not a valid URL. Using default.`);
|
|
25641
|
-
return PRODUCTION_API_URL;
|
|
25642
|
-
}
|
|
25643
|
-
if (parsed.protocol !== "https:") {
|
|
25644
|
-
console.error("Invalid TRACE_API_URL: only https:// is allowed. Using default.");
|
|
25645
|
-
return PRODUCTION_API_URL;
|
|
25646
|
-
}
|
|
25647
|
-
const hostname3 = parsed.hostname;
|
|
25648
|
-
if (hostname3 === "localhost" || hostname3 === "127.0.0.1" || hostname3 === "0.0.0.0" || hostname3 === "::1" || hostname3.startsWith("10.") || hostname3.startsWith("192.168.") || /^172\.(1[6-9]|2[0-9]|3[01])\./.test(hostname3)) {
|
|
25649
|
-
console.error(
|
|
25650
|
-
"Invalid TRACE_API_URL: private/reserved hostnames are not allowed. Using default."
|
|
25651
|
-
);
|
|
25652
|
-
return PRODUCTION_API_URL;
|
|
25653
|
-
}
|
|
25654
|
-
return raw.replace(/\/+$/, "");
|
|
25655
|
-
}
|
|
25656
|
-
function createClient(token) {
|
|
25657
|
-
return initClient(v1Contract, {
|
|
25658
|
-
baseUrl: getApiBaseUrl(),
|
|
25659
|
-
baseHeaders: {
|
|
25660
|
-
Authorization: `Bearer ${token}`
|
|
25661
|
-
}
|
|
25662
|
-
});
|
|
25663
|
-
}
|
|
25664
|
-
function getWorkosClientId() {
|
|
25665
|
-
const clientId = "client_01KEZ01W5Q3107GTBY51WQ67HT";
|
|
25666
|
-
if (!clientId || clientId.trim().length === 0) {
|
|
25667
|
-
return null;
|
|
25668
|
-
}
|
|
25669
|
-
return clientId;
|
|
25670
|
-
}
|
|
25671
|
-
async function refreshStoredAccessToken() {
|
|
25672
|
-
const clientId = getWorkosClientId();
|
|
25673
|
-
const refreshToken = readRefreshToken();
|
|
25674
|
-
if (!clientId || !refreshToken) {
|
|
25675
|
-
return null;
|
|
25676
|
-
}
|
|
25677
|
-
try {
|
|
25678
|
-
const tokenResponse = await refreshAccessToken(clientId, refreshToken);
|
|
25679
|
-
const nextRefreshToken = tokenResponse.refresh_token ?? refreshToken;
|
|
25680
|
-
writeTokens(tokenResponse.access_token, nextRefreshToken);
|
|
25681
|
-
return tokenResponse.access_token;
|
|
25682
|
-
} catch (error48) {
|
|
25683
|
-
if (error48 instanceof Error && (error48.message.includes(" 400 ") || error48.message.includes(" 401 "))) {
|
|
25684
|
-
removeToken();
|
|
25685
|
-
}
|
|
25686
|
-
return null;
|
|
25687
|
-
}
|
|
25688
|
-
}
|
|
25689
|
-
async function refreshStoredAccessTokenForOrganization(workosOrganizationId) {
|
|
25690
|
-
const clientId = getWorkosClientId();
|
|
25691
|
-
const refreshToken = readRefreshToken();
|
|
25692
|
-
if (!clientId || !refreshToken) {
|
|
25693
|
-
return false;
|
|
25694
|
-
}
|
|
25695
|
-
try {
|
|
25696
|
-
const tokenResponse = await refreshAccessToken(clientId, refreshToken, workosOrganizationId);
|
|
25697
|
-
const nextRefreshToken = tokenResponse.refresh_token ?? refreshToken;
|
|
25698
|
-
writeTokens(tokenResponse.access_token, nextRefreshToken);
|
|
25699
|
-
return true;
|
|
25700
|
-
} catch (error48) {
|
|
25701
|
-
if (error48 instanceof Error && (error48.message.includes(" 400 ") || error48.message.includes(" 401 "))) {
|
|
25702
|
-
removeToken();
|
|
25703
|
-
}
|
|
25704
|
-
return false;
|
|
25705
|
-
}
|
|
25706
|
-
}
|
|
25707
|
-
async function authenticatedRequest(request) {
|
|
25708
|
-
const token = readToken();
|
|
25709
|
-
if (!token) {
|
|
25710
|
-
console.error("Not logged in. Run `tracecli auth login` first.");
|
|
25711
|
-
process.exit(1);
|
|
25712
|
-
}
|
|
25713
|
-
const firstResult = await request(createClient(token));
|
|
25714
|
-
if (firstResult.status !== UNAUTHORIZED_STATUS) {
|
|
25715
|
-
return firstResult;
|
|
25716
|
-
}
|
|
25717
|
-
const refreshedToken = await refreshStoredAccessToken();
|
|
25718
|
-
if (!refreshedToken) {
|
|
25719
|
-
return firstResult;
|
|
25720
|
-
}
|
|
25721
|
-
return request(createClient(refreshedToken));
|
|
25722
|
-
}
|
|
25723
|
-
async function authenticatedRequestSafe(request) {
|
|
25724
|
-
const token = readTokenSafe();
|
|
25725
|
-
if (!token) {
|
|
25726
|
-
return null;
|
|
25727
|
-
}
|
|
25728
|
-
try {
|
|
25729
|
-
const firstResult = await request(createClient(token));
|
|
25730
|
-
if (firstResult.status !== UNAUTHORIZED_STATUS) {
|
|
25731
|
-
return firstResult;
|
|
25732
|
-
}
|
|
25733
|
-
const refreshedToken = await refreshStoredAccessToken();
|
|
25734
|
-
if (!refreshedToken) {
|
|
25735
|
-
return firstResult;
|
|
25736
|
-
}
|
|
25737
|
-
return await request(createClient(refreshedToken));
|
|
25738
|
-
} catch {
|
|
25739
|
-
return null;
|
|
25740
|
-
}
|
|
25741
|
-
}
|
|
25742
|
-
function extractOrganizationIdFromToken(token) {
|
|
25743
|
-
if (!token || token.trim().length === 0) {
|
|
25744
|
-
return null;
|
|
25745
|
-
}
|
|
25746
|
-
const parts = token.split(".");
|
|
25747
|
-
const payload = parts[1];
|
|
25748
|
-
if (!payload) {
|
|
25749
|
-
return null;
|
|
25750
|
-
}
|
|
25751
|
-
try {
|
|
25752
|
-
const decoded = JSON.parse(Buffer.from(payload, "base64url").toString("utf-8"));
|
|
25753
|
-
return typeof decoded.org_id === "string" && decoded.org_id.trim().length > 0 ? decoded.org_id : null;
|
|
25754
|
-
} catch {
|
|
25755
|
-
return null;
|
|
25756
|
-
}
|
|
25757
|
-
}
|
|
25758
|
-
var SAFE_ID_PATTERN = /^[a-zA-Z0-9_-]+$/;
|
|
25759
|
-
function determineActiveOrganization(organizations, selectedOrganizationId, tokenOrganizationId) {
|
|
25760
|
-
if (organizations.length === 0) {
|
|
25761
|
-
return null;
|
|
25762
|
-
}
|
|
25763
|
-
if (selectedOrganizationId && SAFE_ID_PATTERN.test(selectedOrganizationId)) {
|
|
25764
|
-
const selectedOrganization = organizations.find(
|
|
25765
|
-
(organization) => organization.organizationId === selectedOrganizationId
|
|
25766
|
-
);
|
|
25767
|
-
if (selectedOrganization) {
|
|
25768
|
-
return {
|
|
25769
|
-
organization: selectedOrganization,
|
|
25770
|
-
source: "selected",
|
|
25771
|
-
staleSelectionDetected: false
|
|
25772
|
-
};
|
|
25773
|
-
}
|
|
25774
|
-
}
|
|
25775
|
-
if (tokenOrganizationId && SAFE_ID_PATTERN.test(tokenOrganizationId)) {
|
|
25776
|
-
const tokenOrganization = organizations.find(
|
|
25777
|
-
(organization) => organization.organizationId === tokenOrganizationId
|
|
25778
|
-
);
|
|
25779
|
-
if (tokenOrganization) {
|
|
25780
|
-
return {
|
|
25781
|
-
organization: tokenOrganization,
|
|
25782
|
-
source: "default",
|
|
25783
|
-
staleSelectionDetected: selectedOrganizationId != null
|
|
25784
|
-
};
|
|
25785
|
-
}
|
|
25786
|
-
}
|
|
25787
|
-
const [fallbackOrganization] = organizations;
|
|
25788
|
-
if (!fallbackOrganization) {
|
|
25789
|
-
return null;
|
|
25790
|
-
}
|
|
25791
|
-
return {
|
|
25792
|
-
organization: fallbackOrganization,
|
|
25793
|
-
source: "default",
|
|
25794
|
-
staleSelectionDetected: selectedOrganizationId != null
|
|
25795
|
-
};
|
|
25796
|
-
}
|
|
25797
|
-
async function resolveOrganizationId(client) {
|
|
25798
|
-
const result = client ? await client.organization.listMyOrganizations() : await authenticatedRequest(
|
|
25799
|
-
(authenticatedClient) => authenticatedClient.organization.listMyOrganizations()
|
|
25800
|
-
);
|
|
25801
|
-
if (result.status !== 200) {
|
|
25802
|
-
console.error(`Failed to resolve organization (status ${result.status}).`);
|
|
25803
|
-
process.exit(1);
|
|
25804
|
-
}
|
|
25805
|
-
const organizations = result.body;
|
|
25806
|
-
const selectedOrganizationId = readSelectedOrganizationId();
|
|
25807
|
-
const tokenOrganizationId = extractOrganizationIdFromToken(readToken());
|
|
25808
|
-
const activeOrganization = determineActiveOrganization(
|
|
25809
|
-
organizations,
|
|
25810
|
-
selectedOrganizationId,
|
|
25811
|
-
tokenOrganizationId
|
|
25812
|
-
);
|
|
25813
|
-
if (!activeOrganization) {
|
|
25814
|
-
console.error("No organization found for your account.");
|
|
25815
|
-
process.exit(1);
|
|
25816
|
-
}
|
|
25817
|
-
const id = activeOrganization.organization.organizationId;
|
|
25818
|
-
if (!SAFE_ID_PATTERN.test(id)) {
|
|
25819
|
-
console.error("Invalid organization ID received from API.");
|
|
25820
|
-
process.exit(1);
|
|
25821
|
-
}
|
|
25822
|
-
if (activeOrganization.staleSelectionDetected) {
|
|
25823
|
-
removeSelectedOrganizationId();
|
|
25824
|
-
writeSelectedOrganizationId(id);
|
|
25825
|
-
if (selectedOrganizationId) {
|
|
25826
|
-
console.warn(
|
|
25827
|
-
`Stored organization '${selectedOrganizationId}' is unavailable. Using '${activeOrganization.organization.name}' (${id}) instead.`
|
|
25828
|
-
);
|
|
25829
|
-
}
|
|
25830
|
-
} else if (activeOrganization.source === "default") {
|
|
25831
|
-
writeSelectedOrganizationId(id);
|
|
25832
|
-
}
|
|
25833
|
-
return id;
|
|
25834
|
-
}
|
|
25835
|
-
async function resolveOrganizationIdSafe(client) {
|
|
25836
|
-
try {
|
|
25837
|
-
const result = client ? await client.organization.listMyOrganizations() : await authenticatedRequestSafe(
|
|
25838
|
-
(authenticatedClient) => authenticatedClient.organization.listMyOrganizations()
|
|
25839
|
-
);
|
|
25840
|
-
if (!result) {
|
|
25841
|
-
return null;
|
|
25842
|
-
}
|
|
25843
|
-
if (result.status !== 200) {
|
|
25844
|
-
return null;
|
|
25845
|
-
}
|
|
25846
|
-
const organizations = result.body;
|
|
25847
|
-
const selectedOrganizationId = readSelectedOrganizationId();
|
|
25848
|
-
const tokenOrganizationId = extractOrganizationIdFromToken(readToken());
|
|
25849
|
-
const activeOrganization = determineActiveOrganization(
|
|
25850
|
-
organizations,
|
|
25851
|
-
selectedOrganizationId,
|
|
25852
|
-
tokenOrganizationId
|
|
25853
|
-
);
|
|
25854
|
-
if (!activeOrganization) {
|
|
25855
|
-
return null;
|
|
25856
|
-
}
|
|
25857
|
-
const id = activeOrganization.organization.organizationId;
|
|
25858
|
-
if (!SAFE_ID_PATTERN.test(id)) {
|
|
25859
|
-
return null;
|
|
25860
|
-
}
|
|
25861
|
-
if (activeOrganization.staleSelectionDetected) {
|
|
25862
|
-
removeSelectedOrganizationId();
|
|
25863
|
-
writeSelectedOrganizationId(id);
|
|
25864
|
-
} else if (activeOrganization.source === "default") {
|
|
25865
|
-
writeSelectedOrganizationId(id);
|
|
25866
|
-
}
|
|
25867
|
-
return id;
|
|
25868
|
-
} catch {
|
|
25869
|
-
return null;
|
|
25870
|
-
}
|
|
25871
|
-
}
|
|
25872
|
-
|
|
25873
|
-
// src/format.ts
|
|
25874
|
-
var SEVERITY_ORDER = {
|
|
25875
|
-
CRITICAL: 0,
|
|
25876
|
-
HIGH: 1,
|
|
25877
|
-
MEDIUM: 2,
|
|
25878
|
-
LOW: 3,
|
|
25879
|
-
INFORMATIONAL: 4
|
|
25880
|
-
};
|
|
25881
|
-
function formatStatus(status) {
|
|
25882
|
-
return status.toLowerCase().replace("_", " ");
|
|
25883
|
-
}
|
|
25884
|
-
function tsvSafe(value) {
|
|
25885
|
-
return (value ?? "").replace(/[\t\r\n]/g, " ");
|
|
25886
|
-
}
|
|
25887
|
-
|
|
25888
25627
|
// ../../node_modules/.bun/chalk@5.6.2/node_modules/chalk/source/vendor/ansi-styles/index.js
|
|
25889
25628
|
var ANSI_BACKGROUND_OFFSET = 10;
|
|
25890
25629
|
var wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
|
|
@@ -26409,6 +26148,9 @@ function colorSuccess(text, colorizer = source_default) {
|
|
|
26409
26148
|
function colorError(text, colorizer = source_default) {
|
|
26410
26149
|
return colorizer.red(text);
|
|
26411
26150
|
}
|
|
26151
|
+
function colorWarningPrefix(text, colorizer = source_default) {
|
|
26152
|
+
return `${colorizer.yellow.bold("Warning:")} ${text}`;
|
|
26153
|
+
}
|
|
26412
26154
|
function colorWarning(text, colorizer = source_default) {
|
|
26413
26155
|
return colorizer.yellow(text);
|
|
26414
26156
|
}
|
|
@@ -26419,6 +26161,273 @@ function colorAccentUnderline(text, colorizer = source_default) {
|
|
|
26419
26161
|
return colorizer.underline.cyan(text);
|
|
26420
26162
|
}
|
|
26421
26163
|
|
|
26164
|
+
// src/api-client.ts
|
|
26165
|
+
var readTokenSafe = readToken;
|
|
26166
|
+
var PRODUCTION_API_URL = "https://api.securewithtrace.com";
|
|
26167
|
+
var UNAUTHORIZED_STATUS = 401;
|
|
26168
|
+
function getApiBaseUrl() {
|
|
26169
|
+
const raw = process.env["TRACE_API_URL"];
|
|
26170
|
+
if (!raw) {
|
|
26171
|
+
return PRODUCTION_API_URL;
|
|
26172
|
+
}
|
|
26173
|
+
let parsed;
|
|
26174
|
+
try {
|
|
26175
|
+
parsed = new URL(raw);
|
|
26176
|
+
} catch {
|
|
26177
|
+
console.error(
|
|
26178
|
+
colorWarning(`Invalid TRACE_API_URL: '${raw}' is not a valid URL. Using default.`)
|
|
26179
|
+
);
|
|
26180
|
+
return PRODUCTION_API_URL;
|
|
26181
|
+
}
|
|
26182
|
+
if (parsed.protocol !== "https:") {
|
|
26183
|
+
console.error(colorWarning("Invalid TRACE_API_URL: only https:// is allowed. Using default."));
|
|
26184
|
+
return PRODUCTION_API_URL;
|
|
26185
|
+
}
|
|
26186
|
+
const hostname3 = parsed.hostname;
|
|
26187
|
+
if (hostname3 === "localhost" || hostname3 === "127.0.0.1" || hostname3 === "0.0.0.0" || hostname3 === "::1" || hostname3.startsWith("10.") || hostname3.startsWith("192.168.") || /^172\.(1[6-9]|2[0-9]|3[01])\./.test(hostname3)) {
|
|
26188
|
+
console.error(
|
|
26189
|
+
colorWarning(
|
|
26190
|
+
"Invalid TRACE_API_URL: private/reserved hostnames are not allowed. Using default."
|
|
26191
|
+
)
|
|
26192
|
+
);
|
|
26193
|
+
return PRODUCTION_API_URL;
|
|
26194
|
+
}
|
|
26195
|
+
return raw.replace(/\/+$/, "");
|
|
26196
|
+
}
|
|
26197
|
+
function createClient(token) {
|
|
26198
|
+
return initClient(v1Contract, {
|
|
26199
|
+
baseUrl: getApiBaseUrl(),
|
|
26200
|
+
baseHeaders: {
|
|
26201
|
+
Authorization: `Bearer ${token}`
|
|
26202
|
+
}
|
|
26203
|
+
});
|
|
26204
|
+
}
|
|
26205
|
+
function getWorkosClientId() {
|
|
26206
|
+
const clientId = "client_01KEZ01W5Q3107GTBY51WQ67HT";
|
|
26207
|
+
if (!clientId || clientId.trim().length === 0) {
|
|
26208
|
+
return null;
|
|
26209
|
+
}
|
|
26210
|
+
return clientId;
|
|
26211
|
+
}
|
|
26212
|
+
async function refreshStoredAccessToken() {
|
|
26213
|
+
const clientId = getWorkosClientId();
|
|
26214
|
+
const refreshToken = readRefreshToken();
|
|
26215
|
+
if (!clientId || !refreshToken) {
|
|
26216
|
+
return null;
|
|
26217
|
+
}
|
|
26218
|
+
try {
|
|
26219
|
+
const tokenResponse = await refreshAccessToken(clientId, refreshToken);
|
|
26220
|
+
const nextRefreshToken = tokenResponse.refresh_token ?? refreshToken;
|
|
26221
|
+
writeTokens(tokenResponse.access_token, nextRefreshToken);
|
|
26222
|
+
return tokenResponse.access_token;
|
|
26223
|
+
} catch (error48) {
|
|
26224
|
+
if (error48 instanceof Error && (error48.message.includes(" 400 ") || error48.message.includes(" 401 "))) {
|
|
26225
|
+
removeToken();
|
|
26226
|
+
}
|
|
26227
|
+
return null;
|
|
26228
|
+
}
|
|
26229
|
+
}
|
|
26230
|
+
async function refreshStoredAccessTokenForOrganization(workosOrganizationId) {
|
|
26231
|
+
const clientId = getWorkosClientId();
|
|
26232
|
+
const refreshToken = readRefreshToken();
|
|
26233
|
+
if (!clientId || !refreshToken) {
|
|
26234
|
+
return false;
|
|
26235
|
+
}
|
|
26236
|
+
try {
|
|
26237
|
+
const tokenResponse = await refreshAccessToken(clientId, refreshToken, workosOrganizationId);
|
|
26238
|
+
const nextRefreshToken = tokenResponse.refresh_token ?? refreshToken;
|
|
26239
|
+
writeTokens(tokenResponse.access_token, nextRefreshToken);
|
|
26240
|
+
return true;
|
|
26241
|
+
} catch (error48) {
|
|
26242
|
+
if (error48 instanceof Error && (error48.message.includes(" 400 ") || error48.message.includes(" 401 "))) {
|
|
26243
|
+
removeToken();
|
|
26244
|
+
}
|
|
26245
|
+
return false;
|
|
26246
|
+
}
|
|
26247
|
+
}
|
|
26248
|
+
async function authenticatedRequest(request) {
|
|
26249
|
+
const token = readToken();
|
|
26250
|
+
if (!token) {
|
|
26251
|
+
console.error(colorError("Not logged in. Run `tracecli auth login` first."));
|
|
26252
|
+
process.exit(1);
|
|
26253
|
+
}
|
|
26254
|
+
const firstResult = await request(createClient(token));
|
|
26255
|
+
if (firstResult.status !== UNAUTHORIZED_STATUS) {
|
|
26256
|
+
return firstResult;
|
|
26257
|
+
}
|
|
26258
|
+
const refreshedToken = await refreshStoredAccessToken();
|
|
26259
|
+
if (!refreshedToken) {
|
|
26260
|
+
return firstResult;
|
|
26261
|
+
}
|
|
26262
|
+
return request(createClient(refreshedToken));
|
|
26263
|
+
}
|
|
26264
|
+
async function authenticatedRequestSafe(request) {
|
|
26265
|
+
const token = readTokenSafe();
|
|
26266
|
+
if (!token) {
|
|
26267
|
+
return null;
|
|
26268
|
+
}
|
|
26269
|
+
try {
|
|
26270
|
+
const firstResult = await request(createClient(token));
|
|
26271
|
+
if (firstResult.status !== UNAUTHORIZED_STATUS) {
|
|
26272
|
+
return firstResult;
|
|
26273
|
+
}
|
|
26274
|
+
const refreshedToken = await refreshStoredAccessToken();
|
|
26275
|
+
if (!refreshedToken) {
|
|
26276
|
+
return firstResult;
|
|
26277
|
+
}
|
|
26278
|
+
return await request(createClient(refreshedToken));
|
|
26279
|
+
} catch {
|
|
26280
|
+
return null;
|
|
26281
|
+
}
|
|
26282
|
+
}
|
|
26283
|
+
function extractOrganizationIdFromToken(token) {
|
|
26284
|
+
if (!token || token.trim().length === 0) {
|
|
26285
|
+
return null;
|
|
26286
|
+
}
|
|
26287
|
+
const parts = token.split(".");
|
|
26288
|
+
const payload = parts[1];
|
|
26289
|
+
if (!payload) {
|
|
26290
|
+
return null;
|
|
26291
|
+
}
|
|
26292
|
+
try {
|
|
26293
|
+
const decoded = JSON.parse(Buffer.from(payload, "base64url").toString("utf-8"));
|
|
26294
|
+
return typeof decoded.org_id === "string" && decoded.org_id.trim().length > 0 ? decoded.org_id : null;
|
|
26295
|
+
} catch {
|
|
26296
|
+
return null;
|
|
26297
|
+
}
|
|
26298
|
+
}
|
|
26299
|
+
var SAFE_ID_PATTERN = /^[a-zA-Z0-9_-]+$/;
|
|
26300
|
+
function determineActiveOrganization(organizations, selectedOrganizationId, tokenOrganizationId) {
|
|
26301
|
+
if (organizations.length === 0) {
|
|
26302
|
+
return null;
|
|
26303
|
+
}
|
|
26304
|
+
if (selectedOrganizationId && SAFE_ID_PATTERN.test(selectedOrganizationId)) {
|
|
26305
|
+
const selectedOrganization = organizations.find(
|
|
26306
|
+
(organization) => organization.organizationId === selectedOrganizationId
|
|
26307
|
+
);
|
|
26308
|
+
if (selectedOrganization) {
|
|
26309
|
+
return {
|
|
26310
|
+
organization: selectedOrganization,
|
|
26311
|
+
source: "selected",
|
|
26312
|
+
staleSelectionDetected: false
|
|
26313
|
+
};
|
|
26314
|
+
}
|
|
26315
|
+
}
|
|
26316
|
+
if (tokenOrganizationId && SAFE_ID_PATTERN.test(tokenOrganizationId)) {
|
|
26317
|
+
const tokenOrganization = organizations.find(
|
|
26318
|
+
(organization) => organization.organizationId === tokenOrganizationId
|
|
26319
|
+
);
|
|
26320
|
+
if (tokenOrganization) {
|
|
26321
|
+
return {
|
|
26322
|
+
organization: tokenOrganization,
|
|
26323
|
+
source: "default",
|
|
26324
|
+
staleSelectionDetected: selectedOrganizationId != null
|
|
26325
|
+
};
|
|
26326
|
+
}
|
|
26327
|
+
}
|
|
26328
|
+
const [fallbackOrganization] = organizations;
|
|
26329
|
+
if (!fallbackOrganization) {
|
|
26330
|
+
return null;
|
|
26331
|
+
}
|
|
26332
|
+
return {
|
|
26333
|
+
organization: fallbackOrganization,
|
|
26334
|
+
source: "default",
|
|
26335
|
+
staleSelectionDetected: selectedOrganizationId != null
|
|
26336
|
+
};
|
|
26337
|
+
}
|
|
26338
|
+
async function resolveOrganizationId(client) {
|
|
26339
|
+
const result = client ? await client.organization.listMyOrganizations() : await authenticatedRequest(
|
|
26340
|
+
(authenticatedClient) => authenticatedClient.organization.listMyOrganizations()
|
|
26341
|
+
);
|
|
26342
|
+
if (result.status !== 200) {
|
|
26343
|
+
console.error(colorError(`Failed to resolve organization (status ${result.status}).`));
|
|
26344
|
+
process.exit(1);
|
|
26345
|
+
}
|
|
26346
|
+
const organizations = result.body;
|
|
26347
|
+
const selectedOrganizationId = readSelectedOrganizationId();
|
|
26348
|
+
const tokenOrganizationId = extractOrganizationIdFromToken(readToken());
|
|
26349
|
+
const activeOrganization = determineActiveOrganization(
|
|
26350
|
+
organizations,
|
|
26351
|
+
selectedOrganizationId,
|
|
26352
|
+
tokenOrganizationId
|
|
26353
|
+
);
|
|
26354
|
+
if (!activeOrganization) {
|
|
26355
|
+
console.error(colorError("No organization found for your account."));
|
|
26356
|
+
process.exit(1);
|
|
26357
|
+
}
|
|
26358
|
+
const id = activeOrganization.organization.organizationId;
|
|
26359
|
+
if (!SAFE_ID_PATTERN.test(id)) {
|
|
26360
|
+
console.error(colorError("Invalid organization ID received from API."));
|
|
26361
|
+
process.exit(1);
|
|
26362
|
+
}
|
|
26363
|
+
if (activeOrganization.staleSelectionDetected) {
|
|
26364
|
+
removeSelectedOrganizationId();
|
|
26365
|
+
writeSelectedOrganizationId(id);
|
|
26366
|
+
if (selectedOrganizationId) {
|
|
26367
|
+
console.warn(
|
|
26368
|
+
colorWarning(
|
|
26369
|
+
`Stored organization '${selectedOrganizationId}' is unavailable. Using '${activeOrganization.organization.name}' (${id}) instead.`
|
|
26370
|
+
)
|
|
26371
|
+
);
|
|
26372
|
+
}
|
|
26373
|
+
} else if (activeOrganization.source === "default") {
|
|
26374
|
+
writeSelectedOrganizationId(id);
|
|
26375
|
+
}
|
|
26376
|
+
return id;
|
|
26377
|
+
}
|
|
26378
|
+
async function resolveOrganizationIdSafe(client) {
|
|
26379
|
+
try {
|
|
26380
|
+
const result = client ? await client.organization.listMyOrganizations() : await authenticatedRequestSafe(
|
|
26381
|
+
(authenticatedClient) => authenticatedClient.organization.listMyOrganizations()
|
|
26382
|
+
);
|
|
26383
|
+
if (!result) {
|
|
26384
|
+
return null;
|
|
26385
|
+
}
|
|
26386
|
+
if (result.status !== 200) {
|
|
26387
|
+
return null;
|
|
26388
|
+
}
|
|
26389
|
+
const organizations = result.body;
|
|
26390
|
+
const selectedOrganizationId = readSelectedOrganizationId();
|
|
26391
|
+
const tokenOrganizationId = extractOrganizationIdFromToken(readToken());
|
|
26392
|
+
const activeOrganization = determineActiveOrganization(
|
|
26393
|
+
organizations,
|
|
26394
|
+
selectedOrganizationId,
|
|
26395
|
+
tokenOrganizationId
|
|
26396
|
+
);
|
|
26397
|
+
if (!activeOrganization) {
|
|
26398
|
+
return null;
|
|
26399
|
+
}
|
|
26400
|
+
const id = activeOrganization.organization.organizationId;
|
|
26401
|
+
if (!SAFE_ID_PATTERN.test(id)) {
|
|
26402
|
+
return null;
|
|
26403
|
+
}
|
|
26404
|
+
if (activeOrganization.staleSelectionDetected) {
|
|
26405
|
+
removeSelectedOrganizationId();
|
|
26406
|
+
writeSelectedOrganizationId(id);
|
|
26407
|
+
} else if (activeOrganization.source === "default") {
|
|
26408
|
+
writeSelectedOrganizationId(id);
|
|
26409
|
+
}
|
|
26410
|
+
return id;
|
|
26411
|
+
} catch {
|
|
26412
|
+
return null;
|
|
26413
|
+
}
|
|
26414
|
+
}
|
|
26415
|
+
|
|
26416
|
+
// src/format.ts
|
|
26417
|
+
var SEVERITY_ORDER = {
|
|
26418
|
+
CRITICAL: 0,
|
|
26419
|
+
HIGH: 1,
|
|
26420
|
+
MEDIUM: 2,
|
|
26421
|
+
LOW: 3,
|
|
26422
|
+
INFORMATIONAL: 4
|
|
26423
|
+
};
|
|
26424
|
+
function formatStatus(status) {
|
|
26425
|
+
return status.toLowerCase().replace("_", " ");
|
|
26426
|
+
}
|
|
26427
|
+
function tsvSafe(value) {
|
|
26428
|
+
return (value ?? "").replace(/[\t\r\n]/g, " ");
|
|
26429
|
+
}
|
|
26430
|
+
|
|
26422
26431
|
// src/auth/commands.ts
|
|
26423
26432
|
function getClientId() {
|
|
26424
26433
|
const clientId = "client_01KEZ01W5Q3107GTBY51WQ67HT";
|
|
@@ -28304,7 +28313,7 @@ Examples:
|
|
|
28304
28313
|
installationToken = cloneTokenResult.token;
|
|
28305
28314
|
cloneTokenFailure = cloneTokenResult.failure;
|
|
28306
28315
|
if (cloneTokenFailure) {
|
|
28307
|
-
console.warn(buildCloneTokenFailureWarning(cloneUrl, cloneTokenFailure));
|
|
28316
|
+
console.warn(colorWarning(buildCloneTokenFailureWarning(cloneUrl, cloneTokenFailure)));
|
|
28308
28317
|
}
|
|
28309
28318
|
}
|
|
28310
28319
|
const effectiveUrl = installationToken ? urlWithUsername(cloneUrl) : cloneUrl;
|
|
@@ -28336,7 +28345,9 @@ Examples:
|
|
|
28336
28345
|
if (exitCode !== 0) {
|
|
28337
28346
|
if (!installationToken && cloneTokenFailure) {
|
|
28338
28347
|
console.error(
|
|
28339
|
-
|
|
28348
|
+
colorError(
|
|
28349
|
+
"Clone failed while Trace clone credentials were unavailable. Resolve the warning above and retry."
|
|
28350
|
+
)
|
|
28340
28351
|
);
|
|
28341
28352
|
}
|
|
28342
28353
|
process.exit(1);
|
|
@@ -28350,11 +28361,13 @@ Examples:
|
|
|
28350
28361
|
const resetExitCode = await resetProc.exited;
|
|
28351
28362
|
if (resetExitCode !== 0) {
|
|
28352
28363
|
console.error(
|
|
28353
|
-
|
|
28364
|
+
colorWarningPrefix(
|
|
28365
|
+
"failed to reset remote URL \u2014 the token username may persist in .git/config"
|
|
28366
|
+
)
|
|
28354
28367
|
);
|
|
28355
28368
|
}
|
|
28356
28369
|
}
|
|
28357
|
-
console.log(`Repository cloned into ${targetDir}`);
|
|
28370
|
+
console.log(colorSuccess(`Repository cloned into ${targetDir}`));
|
|
28358
28371
|
} finally {
|
|
28359
28372
|
if (askPassScript) {
|
|
28360
28373
|
rmSync2(askPassScript.replace(/\/[^/]+$/, ""), { recursive: true, force: true });
|