securewithtrace 0.16.1 → 0.17.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 +41 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -24959,8 +24959,24 @@ async function authenticatedRequestSafe(request) {
|
|
|
24959
24959
|
return null;
|
|
24960
24960
|
}
|
|
24961
24961
|
}
|
|
24962
|
+
function extractOrganizationIdFromToken(token) {
|
|
24963
|
+
if (!token || token.trim().length === 0) {
|
|
24964
|
+
return null;
|
|
24965
|
+
}
|
|
24966
|
+
const parts = token.split(".");
|
|
24967
|
+
const payload = parts[1];
|
|
24968
|
+
if (!payload) {
|
|
24969
|
+
return null;
|
|
24970
|
+
}
|
|
24971
|
+
try {
|
|
24972
|
+
const decoded = JSON.parse(Buffer.from(payload, "base64url").toString("utf-8"));
|
|
24973
|
+
return typeof decoded.org_id === "string" && decoded.org_id.trim().length > 0 ? decoded.org_id : null;
|
|
24974
|
+
} catch {
|
|
24975
|
+
return null;
|
|
24976
|
+
}
|
|
24977
|
+
}
|
|
24962
24978
|
var SAFE_ID_PATTERN = /^[a-zA-Z0-9_-]+$/;
|
|
24963
|
-
function determineActiveOrganization(organizations, selectedOrganizationId) {
|
|
24979
|
+
function determineActiveOrganization(organizations, selectedOrganizationId, tokenOrganizationId) {
|
|
24964
24980
|
if (organizations.length === 0) {
|
|
24965
24981
|
return null;
|
|
24966
24982
|
}
|
|
@@ -24976,6 +24992,18 @@ function determineActiveOrganization(organizations, selectedOrganizationId) {
|
|
|
24976
24992
|
};
|
|
24977
24993
|
}
|
|
24978
24994
|
}
|
|
24995
|
+
if (tokenOrganizationId && SAFE_ID_PATTERN.test(tokenOrganizationId)) {
|
|
24996
|
+
const tokenOrganization = organizations.find(
|
|
24997
|
+
(organization) => organization.organizationId === tokenOrganizationId
|
|
24998
|
+
);
|
|
24999
|
+
if (tokenOrganization) {
|
|
25000
|
+
return {
|
|
25001
|
+
organization: tokenOrganization,
|
|
25002
|
+
source: "default",
|
|
25003
|
+
staleSelectionDetected: selectedOrganizationId != null
|
|
25004
|
+
};
|
|
25005
|
+
}
|
|
25006
|
+
}
|
|
24979
25007
|
const [fallbackOrganization] = organizations;
|
|
24980
25008
|
if (!fallbackOrganization) {
|
|
24981
25009
|
return null;
|
|
@@ -24996,7 +25024,12 @@ async function resolveOrganizationId(client) {
|
|
|
24996
25024
|
}
|
|
24997
25025
|
const organizations = result.body;
|
|
24998
25026
|
const selectedOrganizationId = readSelectedOrganizationId();
|
|
24999
|
-
const
|
|
25027
|
+
const tokenOrganizationId = extractOrganizationIdFromToken(readToken());
|
|
25028
|
+
const activeOrganization = determineActiveOrganization(
|
|
25029
|
+
organizations,
|
|
25030
|
+
selectedOrganizationId,
|
|
25031
|
+
tokenOrganizationId
|
|
25032
|
+
);
|
|
25000
25033
|
if (!activeOrganization) {
|
|
25001
25034
|
console.error("No organization found for your account.");
|
|
25002
25035
|
process.exit(1);
|
|
@@ -25032,7 +25065,12 @@ async function resolveOrganizationIdSafe(client) {
|
|
|
25032
25065
|
}
|
|
25033
25066
|
const organizations = result.body;
|
|
25034
25067
|
const selectedOrganizationId = readSelectedOrganizationId();
|
|
25035
|
-
const
|
|
25068
|
+
const tokenOrganizationId = extractOrganizationIdFromToken(readToken());
|
|
25069
|
+
const activeOrganization = determineActiveOrganization(
|
|
25070
|
+
organizations,
|
|
25071
|
+
selectedOrganizationId,
|
|
25072
|
+
tokenOrganizationId
|
|
25073
|
+
);
|
|
25036
25074
|
if (!activeOrganization) {
|
|
25037
25075
|
return null;
|
|
25038
25076
|
}
|