diff --git a/src/api.js b/src/api.js index 41479b8..baee3e6 100644 --- a/src/api.js +++ b/src/api.js @@ -1,5 +1,5 @@ import { DoesNotExistError } from "./types/internalErrors.js"; -import { getAPIURL, getToken, removeDoubleSlash } from "./utils.js"; +import { getAPIURL, getObjectKeys, getToken, removeDoubleSlash } from "./utils.js"; export async function lookupSelf() { const request = new Request(getAPIURL() + "/v1/auth/token/lookup-self", { @@ -181,8 +181,8 @@ export async function undeleteSecret(baseMount, secretPath, name, version = null pageState.currentSecretPath, pageState.currentSecret ); - let versions = Array.from(new Map(Object.entries(meta.versions)).keys()) - version = String(versions[versions.length-1]) + let versions = getObjectKeys(meta.versions); + version = String(versions[versions.length-1]); } let request = new Request(getAPIURL() + secretURL, { diff --git a/src/utils.js b/src/utils.js index 94d977e..4ad1235 100644 --- a/src/utils.js +++ b/src/utils.js @@ -2,8 +2,10 @@ export function removeDoubleSlash(str) { return str.replace(/\/\/+/g, "/"); } +export const getObjectKeys = (obj) => Object.getOwnPropertyNames(obj); + export function getKeyByObjectPropertyValue(map, searchValue) { - for (let key of Object.getOwnPropertyNames(map)) { + for (let key of getObjectKeys(map)) { if (map[key] === searchValue) return key; } @@ -23,5 +25,5 @@ export function getToken() { } export function getAPIURL() { - return pageState.apiURL.length > 0 ? pageState.apiURL : null + return pageState.apiURL.length > 0 ? pageState.apiURL : null; } \ No newline at end of file