From 5409d64409ddc9127142d902398d00e8496d949b Mon Sep 17 00:00:00 2001 From: Kitteh Date: Fri, 7 May 2021 11:07:03 +0100 Subject: [PATCH] Move pageState into a js file instead of in global window. --- src/PageState.js | 19 ++++-- src/allPages.js | 41 ++++++++++++ src/api.js | 81 ++++++++++++----------- src/formatDistance.js | 1 + src/globalPageState.js | 3 + src/main.js | 63 +----------------- src/pageUtils.js | 11 +-- src/pages/Home.js | 4 +- src/pages/KeyValue/KeyValueDelete.js | 1 + src/pages/KeyValue/KeyValueNew.js | 1 + src/pages/KeyValue/KeyValueSecret.js | 1 + src/pages/KeyValue/KeyValueSecretsEdit.js | 1 + src/pages/KeyValue/KeyValueVersions.js | 1 + src/pages/KeyValue/KeyValueView.js | 1 + src/pages/Me.js | 4 +- src/pages/SetLanguage.js | 1 + src/pages/TOTP/NewTOTP.js | 1 + src/pages/TOTP/TOTPView.js | 1 + src/pages/Template.js | 1 + src/pages/Transit/TransitDecrypt.js | 2 +- src/pages/Transit/TransitEncrypt.js | 1 + src/pages/Transit/TransitView.js | 1 + src/pages/Transit/TransitViewSecret.js | 1 + src/pages/Unseal.js | 9 ++- src/pages/index.js | 19 ------ src/utils.js | 8 --- 26 files changed, 125 insertions(+), 153 deletions(-) create mode 100644 src/allPages.js create mode 100644 src/globalPageState.js delete mode 100644 src/pages/index.js diff --git a/src/PageState.js b/src/PageState.js index dbf1dc3..5e6f4e2 100644 --- a/src/PageState.js +++ b/src/PageState.js @@ -1,4 +1,5 @@ import { Page } from "./types/Page.js"; +import { allPages } from "./allPages.js" import { getKeyByObjectPropertyValue, } from "./utils.js"; @@ -19,14 +20,16 @@ export class PageState extends Page { // the clunkyness of this approach, but for now, this works. get apiURL() { - return localStorage.getItem('apiURL') || ""; + let apiurl = localStorage.getItem('apiURL') || ""; + return apiurl.length > 0 ? apiurl : null; } set apiURL(value) { localStorage.setItem('apiURL', value); } get token() { - return localStorage.getItem('token') || ""; + let tok = localStorage.getItem('token') || ""; + return tok.length > 0 ? tok : null; } set token(value) { localStorage.setItem('token', value); @@ -91,14 +94,18 @@ export class PageState extends Page { } get currentPage() { let curPage = localStorage.getItem('currentPage') || "HOME"; - return realPages[curPage]; + return allPages[curPage]; } get currentPageString() { - let key = getKeyByObjectPropertyValue(realPages, this.currentPage); + let key = getKeyByObjectPropertyValue(allPages, this.currentPage); return key; } set currentPage(value) { - let key = getKeyByObjectPropertyValue(realPages, value); - localStorage.setItem('currentPage', key); + if (typeof page == 'object') { + let key = getKeyByObjectPropertyValue(allPages, value); + localStorage.setItem('currentPage', key); + } else { + localStorage.setItem('currentPage', value); + } } } \ No newline at end of file diff --git a/src/allPages.js b/src/allPages.js new file mode 100644 index 0000000..1c9a893 --- /dev/null +++ b/src/allPages.js @@ -0,0 +1,41 @@ +import { HomePage } from "./pages/Home.js"; +import { KeyValueDeletePage } from "./pages/KeyValue/KeyValueDelete.js"; +import { KeyValueNewPage } from "./pages/KeyValue/KeyValueNew.js"; +import { KeyValueSecretEditPage } from "./pages/KeyValue/KeyValueSecretsEdit.js"; +import { KeyValueSecretPage } from "./pages/KeyValue/KeyValueSecret.js"; +import { KeyValueVersionsPage } from "./pages/KeyValue/KeyValueVersions.js"; +import { KeyValueViewPage } from "./pages/KeyValue/KeyValueView.js"; +import { LoginPage } from "./pages/Login.js"; +import { MePage } from "./pages/Me.js"; +import { NewTOTPPage } from "./pages/TOTP/NewTOTP.js"; +import { PwGenPage } from "./pages/PwGen.js"; +import { SetLanguagePage } from "./pages/SetLanguage.js"; +import { SetVaultURLPage } from "./pages/SetVaultURL.js"; +import { TOTPViewPage } from "./pages/TOTP/TOTPView.js"; +import { TransitDecryptPage } from "./pages/Transit/TransitDecrypt.js"; +import { TransitEncryptPage } from "./pages/Transit/TransitEncrypt.js"; +import { TransitViewPage } from "./pages/Transit/TransitView.js"; +import { TransitViewSecretPage } from "./pages/Transit/TransitViewSecret.js"; +import { UnsealPage } from "./pages/Unseal.js"; + +export const allPages = { + HOME: new HomePage(), + ME: new MePage(), + TOTP: new TOTPViewPage(), + NEW_TOTP: new NewTOTPPage(), + LOGIN: new LoginPage(), + SET_VAULT_URL: new SetVaultURLPage(), + UNSEAL: new UnsealPage(), + SET_LANGUAGE: new SetLanguagePage(), + TRANSIT_VIEW: new TransitViewPage(), + TRANSIT_VIEW_SECRET: new TransitViewSecretPage(), + TRANSIT_ENCRYPT: new TransitEncryptPage(), + TRANSIT_DECRYPT: new TransitDecryptPage(), + KEY_VALUE_VIEW: new KeyValueViewPage(), + KEY_VALUE_SECRET: new KeyValueSecretPage(), + KEY_VALUE_VERSIONS: new KeyValueVersionsPage(), + KEY_VALUE_NEW_SECRET: new KeyValueNewPage(), + KEY_VALUE_DELETE: new KeyValueDeletePage(), + KEY_VALUE_SECRET_EDIT: new KeyValueSecretEditPage(), + PW_GEN: new PwGenPage(), +}; \ No newline at end of file diff --git a/src/api.js b/src/api.js index 8f8522d..fdbc286 100644 --- a/src/api.js +++ b/src/api.js @@ -1,10 +1,11 @@ import { DoesNotExistError } from "./types/internalErrors.js"; -import { getAPIURL, getObjectKeys, getToken, removeDoubleSlash } from "./utils.js"; +import { getObjectKeys, removeDoubleSlash } from "./utils.js"; +import { pageState } from "./globalPageState.js"; export async function lookupSelf() { - const request = new Request(getAPIURL() + "/v1/auth/token/lookup-self", { + const request = new Request(pageState.apiURL + "/v1/auth/token/lookup-self", { headers: { - "X-Vault-Token": getToken(), + "X-Vault-Token": pageState.token, } }); return fetch(request).then(response => { @@ -19,10 +20,10 @@ export async function lookupSelf() { } export async function renewSelf() { - const request = new Request(getAPIURL() + "/v1/auth/token/renew-self", { + const request = new Request(pageState.apiURL + "/v1/auth/token/renew-self", { method: 'POST', headers: { - "X-Vault-Token": getToken(), + "X-Vault-Token": pageState.token, 'Content-Type': 'application/json' }, body: JSON.stringify({}) @@ -37,10 +38,10 @@ export async function renewSelf() { } export async function sealVault() { - const request = new Request(getAPIURL() + "/v1/sys/seal", { + const request = new Request(pageState.apiURL + "/v1/sys/seal", { method: 'PUT', headers: { - "X-Vault-Token": getToken(), + "X-Vault-Token": pageState.token, }, }); return fetch(request).then(response => { @@ -53,7 +54,7 @@ export async function sealVault() { } export async function usernameLogin(username, password) { - const request = new Request(getAPIURL() + `/v1/auth/userpass/login/${username}`, { + const request = new Request(pageState.apiURL + `/v1/auth/userpass/login/${username}`, { method: 'POST', headers: { 'Content-Type': 'application/json' @@ -72,9 +73,9 @@ export async function usernameLogin(username, password) { } export async function getMounts() { - const request = new Request(getAPIURL() + "/v1/sys/internal/ui/mounts", { + const request = new Request(pageState.apiURL + "/v1/sys/internal/ui/mounts", { headers: { - "X-Vault-Token": getToken(), + "X-Vault-Token": pageState.token, } }); return fetch(request).then(response => { @@ -85,7 +86,7 @@ export async function getMounts() { } export async function getSealStatus() { - const request = new Request(getAPIURL() + "/v1/sys/seal-status"); + const request = new Request(pageState.apiURL + "/v1/sys/seal-status"); return fetch(request).then(response => { return response.json(); }).then(data => { @@ -94,7 +95,7 @@ export async function getSealStatus() { } export async function submitUnsealKey(key) { - const request = new Request(getAPIURL() + "/v1/sys/unseal", { + const request = new Request(pageState.apiURL + "/v1/sys/unseal", { method: "POST", headers: { 'Content-Type': 'application/json', @@ -115,11 +116,11 @@ export async function getCapabilities(baseMount, secretPath, name) { } export async function getCapabilitiesPath(path) { - const request = new Request(getAPIURL() + "/v1/sys/capabilities-self", { + const request = new Request(pageState.apiURL + "/v1/sys/capabilities-self", { method: "POST", headers: { 'Content-Type': 'application/json', - "X-Vault-Token": getToken(), + "X-Vault-Token": pageState.token, }, body: JSON.stringify( { @@ -142,9 +143,9 @@ export async function getSecrets(baseMount, mountType, secretPath) { // cubbyhole and v1 are identical secretURL = `/v1/${baseMount}/${secretPath.join("")}?list=true`; } - const request = new Request(getAPIURL() + secretURL, { + const request = new Request(pageState.apiURL + secretURL, { headers: { - "X-Vault-Token": getToken(), + "X-Vault-Token": pageState.token, } }); return fetch(request).then(response => { @@ -159,9 +160,9 @@ export async function getSecrets(baseMount, mountType, secretPath) { } export async function getSecretMetadata(baseMount, secretPath, name) { - const request = new Request(getAPIURL() + `/v1/${baseMount}/metadata/${secretPath.join("")}/${name}`, { + const request = new Request(pageState.apiURL + `/v1/${baseMount}/metadata/${secretPath.join("")}/${name}`, { headers: { - "X-Vault-Token": getToken(), + "X-Vault-Token": pageState.token, } }); @@ -185,10 +186,10 @@ export async function undeleteSecret(baseMount, secretPath, name, version = null version = String(versions[versions.length-1]); } - let request = new Request(getAPIURL() + secretURL, { + let request = new Request(pageState.apiURL + secretURL, { method: "POST", headers: { - 'X-Vault-Token': getToken(), + 'X-Vault-Token': pageState.token, 'Content-Type': 'application/json', }, body: JSON.stringify({ "versions": [version] }) @@ -209,9 +210,9 @@ export async function getSecret(baseMount, mountType, secretPath, name, version } else { secretURL = `/v1/${baseMount}/${secretPath.join("")}/${name}`; } - const request = new Request(getAPIURL() + secretURL, { + const request = new Request(pageState.apiURL + secretURL, { headers: { - "X-Vault-Token": getToken(), + "X-Vault-Token": pageState.token, } }); @@ -230,10 +231,10 @@ export async function deleteSecret(baseMount, mountType, secretPath, name, versi if (mountType == "kv-v2" && version != null) { secretURL = `/v1/${baseMount}/delete/${secretPath.join("")}/${name}`; secretURL = removeDoubleSlash(secretURL).replace(/\/$/, ""); - request = new Request(getAPIURL() + secretURL, { + request = new Request(pageState.apiURL + secretURL, { method: "POST", headers: { - 'X-Vault-Token': getToken(), + 'X-Vault-Token': pageState.token, 'Content-Type': 'application/json', }, body: version != null ? JSON.stringify({ "versions": [version] }) : "{}" @@ -245,10 +246,10 @@ export async function deleteSecret(baseMount, mountType, secretPath, name, versi secretURL = `/v1/${baseMount}/${secretPath.join("")}/${name}`; } secretURL = removeDoubleSlash(secretURL).replace(/\/$/, ""); - request = new Request(getAPIURL() + secretURL, { + request = new Request(pageState.apiURL + secretURL, { method: "DELETE", headers: { - 'X-Vault-Token': getToken() + 'X-Vault-Token': pageState.token }, }); } @@ -274,11 +275,11 @@ export async function createOrUpdateSecret(baseMount, mountType, secretPath, nam } secretURL = removeDoubleSlash(secretURL).replace(/\/$/, ""); - const request = new Request(getAPIURL() + secretURL, { + const request = new Request(pageState.apiURL + secretURL, { method: "POST", headers: { 'Content-Type': 'application/json', - 'X-Vault-Token': getToken() + 'X-Vault-Token': pageState.token }, body: JSON.stringify(APIData, null, 0) }); @@ -290,9 +291,9 @@ export async function createOrUpdateSecret(baseMount, mountType, secretPath, nam } export async function getTransitKeys(baseMount) { - const request = new Request(getAPIURL() + `/v1/${baseMount}/keys?list=true`, { + const request = new Request(pageState.apiURL + `/v1/${baseMount}/keys?list=true`, { headers: { - "X-Vault-Token": getToken(), + "X-Vault-Token": pageState.token, } }); return fetch(request).then(response => { @@ -306,11 +307,11 @@ export async function getTransitKeys(baseMount) { } export async function transitEncrypt(baseMount, name, data) { - const request = new Request(getAPIURL() + removeDoubleSlash(`/v1/${baseMount}/encrypt/${name}`), { + const request = new Request(pageState.apiURL + removeDoubleSlash(`/v1/${baseMount}/encrypt/${name}`), { method: 'POST', headers: { 'Content-Type': 'application/json', - 'X-Vault-Token': getToken() + 'X-Vault-Token': pageState.token }, body: JSON.stringify({plaintext: data}) }); @@ -325,11 +326,11 @@ export async function transitEncrypt(baseMount, name, data) { } export async function transitDecrypt(baseMount, name, data) { - const request = new Request(getAPIURL() + removeDoubleSlash(`/v1/${baseMount}/decrypt/${name}`), { + const request = new Request(pageState.apiURL + removeDoubleSlash(`/v1/${baseMount}/decrypt/${name}`), { method: 'POST', headers: { 'Content-Type': 'application/json', - 'X-Vault-Token': getToken() + 'X-Vault-Token': pageState.token }, body: JSON.stringify({ciphertext: data}) }); @@ -345,9 +346,9 @@ export async function transitDecrypt(baseMount, name, data) { export async function getTOTPKeys(baseMount) { - const request = new Request(getAPIURL() + `/v1/${baseMount}/keys?list=true`, { + const request = new Request(pageState.apiURL + `/v1/${baseMount}/keys?list=true`, { headers: { - "X-Vault-Token": getToken(), + "X-Vault-Token": pageState.token, } }); return fetch(request).then(response => { @@ -361,9 +362,9 @@ export async function getTOTPKeys(baseMount) { } export async function getTOTPCode(baseMount, name) { - const request = new Request(getAPIURL() + `/v1/${baseMount}/code/${name}`, { + const request = new Request(pageState.apiURL + `/v1/${baseMount}/code/${name}`, { headers: { - "X-Vault-Token": getToken(), + "X-Vault-Token": pageState.token, } }); return fetch(request).then(response => { @@ -374,11 +375,11 @@ export async function getTOTPCode(baseMount, name) { } export async function addNewTOTP(baseMount, parms) { - const request = new Request(getAPIURL() + removeDoubleSlash(`/v1/${baseMount}/keys/${parms.name}`), { + const request = new Request(pageState.apiURL + removeDoubleSlash(`/v1/${baseMount}/keys/${parms.name}`), { method: 'POST', headers: { 'Content-Type': 'application/json', - 'X-Vault-Token': getToken() + 'X-Vault-Token': pageState.token }, body: JSON.stringify(parms) }); diff --git a/src/formatDistance.js b/src/formatDistance.js index b2badf6..6d8bee9 100644 --- a/src/formatDistance.js +++ b/src/formatDistance.js @@ -1,5 +1,6 @@ import { de, enGB, fr, it, nl, ru } from 'date-fns/locale' import { formatDistance as formatDistanceReal} from 'date-fns'; +import { pageState } from "./globalPageState.js"; function getLocale() { return { diff --git a/src/globalPageState.js b/src/globalPageState.js new file mode 100644 index 0000000..24fb850 --- /dev/null +++ b/src/globalPageState.js @@ -0,0 +1,3 @@ +import { PageState } from "./PageState.js"; + +export const pageState = new PageState(); \ No newline at end of file diff --git a/src/main.js b/src/main.js index a0df0d6..696c5a5 100644 --- a/src/main.js +++ b/src/main.js @@ -13,80 +13,19 @@ import "prismjs/components/prism-json"; Prism.highlightAll(); /* eslint-enable */ -import { PageState } from "./PageState.js"; import { changePage, renderPage, } from "./pageUtils.js"; import { getSealStatus } from './api.js'; import { makeElement } from "./htmlUtils.js"; - -// Pages - -import { - HomePage, - KeyValueDeletePage, - KeyValueNewPage, - KeyValueSecretEditPage, - KeyValueSecretPage, - KeyValueVersionsPage, - KeyValueViewPage, - LoginPage, - MePage, - NewTOTPPage, - PwGenPage, - SetLanguagePage, - SetVaultURLPage, - TOTPViewPage, - TransitDecryptPage, - TransitEncryptPage, - TransitViewPage, - TransitViewSecretPage, - UnsealPage, -} from "./pages"; - -const pages = { - HOME: new HomePage(), - ME: new MePage(), - TOTP: new TOTPViewPage(), - NEW_TOTP: new NewTOTPPage(), - LOGIN: new LoginPage(), - SET_VAULT_URL: new SetVaultURLPage(), - UNSEAL: new UnsealPage(), - SET_LANGUAGE: new SetLanguagePage(), - TRANSIT_VIEW: new TransitViewPage(), - TRANSIT_VIEW_SECRET: new TransitViewSecretPage(), - TRANSIT_ENCRYPT: new TransitEncryptPage(), - TRANSIT_DECRYPT: new TransitDecryptPage(), - KEY_VALUE_VIEW: new KeyValueViewPage(), - KEY_VALUE_SECRET: new KeyValueSecretPage(), - KEY_VALUE_VERSIONS: new KeyValueVersionsPage(), - KEY_VALUE_NEW_SECRET: new KeyValueNewPage(), - KEY_VALUE_DELETE: new KeyValueDeletePage(), - KEY_VALUE_SECRET_EDIT: new KeyValueSecretEditPage(), - PW_GEN: new PwGenPage(), -}; +import { pageState } from "./globalPageState.js"; // Translations import { formatDistance } from './formatDistance.js'; import i18next from 'i18next'; import translations from './translations/index.mjs' -/*import "en-GB" as date_locale_en from 'date-fns/locale' - -function getDateLocale() { - let locales = { - en: - } -}*/ - - -// Globals - -var pageState = new PageState(); -window.pageState = pageState; -window.realPages = pages; - function ListItem(children) { return makeElement({ tag: "li", diff --git a/src/pageUtils.js b/src/pageUtils.js index 07fd315..f414d01 100644 --- a/src/pageUtils.js +++ b/src/pageUtils.js @@ -1,7 +1,6 @@ -import { getAPIURL } from "./utils.js"; import { getSealStatus, lookupSelf } from './api.js'; import { makeElement } from "./htmlUtils.js"; - +import { pageState } from "./globalPageState.js"; import UIkit from 'uikit/dist/js/uikit.min.js'; import i18next from 'i18next'; @@ -10,7 +9,7 @@ async function prePageChecksReal() { changePage("SET_LANGUAGE"); throw new Error("Language Not Set"); } - if (!getAPIURL()) { + if (!pageState.apiURL) { changePage("SET_VAULT_URL"); throw new Error("Vault URL Not Set"); } @@ -75,11 +74,7 @@ export function changePage(page, shouldSwitch = true) { if (pageState.currentPage && shouldSwitch) { pageState.currentPage.cleanup(); } - if (typeof page == 'object') { - pageState.currentPage = page; - } else { - pageState.currentPage = realPages[page]; - } + pageState.currentPage = page; if (shouldSwitch) { renderPage(); } diff --git a/src/pages/Home.js b/src/pages/Home.js index 81cea77..b1ba22e 100644 --- a/src/pages/Home.js +++ b/src/pages/Home.js @@ -1,8 +1,8 @@ import { Page } from "../types/Page.js"; import { changePage, prePageChecks, setErrorText } from "../pageUtils.js"; -import { getAPIURL } from "../utils.js"; import { getMounts, lookupSelf } from "../api.js"; import { makeElement } from "../htmlUtils.js"; +import { pageState } from "../globalPageState.js"; import i18next from 'i18next'; export class HomePage extends Page { @@ -21,7 +21,7 @@ export class HomePage extends Page { tag: "li", children: makeElement({ tag: "span", - html: i18next.t("vaulturl_text", {"text": getAPIURL()}) + html: i18next.t("vaulturl_text", {"text": pageState.apiURL}) }) }), makeElement({ diff --git a/src/pages/KeyValue/KeyValueDelete.js b/src/pages/KeyValue/KeyValueDelete.js index e352ba5..0f0626a 100644 --- a/src/pages/KeyValue/KeyValueDelete.js +++ b/src/pages/KeyValue/KeyValueDelete.js @@ -2,6 +2,7 @@ import { Page } from "../../types/Page.js"; import { changePage, setPageContent, setTitleElement } from "../../pageUtils.js"; import { deleteSecret } from "../../api.js"; import { makeElement } from "../../htmlUtils.js"; +import { pageState } from "../../globalPageState.js"; import i18next from 'i18next'; export class KeyValueDeletePage extends Page { diff --git a/src/pages/KeyValue/KeyValueNew.js b/src/pages/KeyValue/KeyValueNew.js index f0ebd6c..5aa5c82 100644 --- a/src/pages/KeyValue/KeyValueNew.js +++ b/src/pages/KeyValue/KeyValueNew.js @@ -2,6 +2,7 @@ import { Page } from "../../types/Page.js"; import { changePage, setErrorText, setPageContent, setTitleElement } from "../../pageUtils.js"; import { createOrUpdateSecret } from "../../api.js"; import { makeElement } from "../../htmlUtils.js"; +import { pageState } from "../../globalPageState.js"; import i18next from 'i18next'; export class KeyValueNewPage extends Page { diff --git a/src/pages/KeyValue/KeyValueSecret.js b/src/pages/KeyValue/KeyValueSecret.js index dcf03d5..691c9fa 100644 --- a/src/pages/KeyValue/KeyValueSecret.js +++ b/src/pages/KeyValue/KeyValueSecret.js @@ -3,6 +3,7 @@ import { Page } from "../../types/Page.js"; import { changePage, setPageContent, setTitleElement } from "../../pageUtils.js"; import { getCapabilities, getSecret, undeleteSecret } from "../../api.js"; import { makeElement } from "../../htmlUtils.js"; +import { pageState } from "../../globalPageState.js"; import Prism from "prismjs"; import i18next from 'i18next'; diff --git a/src/pages/KeyValue/KeyValueSecretsEdit.js b/src/pages/KeyValue/KeyValueSecretsEdit.js index d11de7e..4bffc58 100644 --- a/src/pages/KeyValue/KeyValueSecretsEdit.js +++ b/src/pages/KeyValue/KeyValueSecretsEdit.js @@ -3,6 +3,7 @@ import { Page } from "../../types/Page.js"; import { changePage, setErrorText, setPageContent, setTitleElement } from "../../pageUtils.js"; import { createOrUpdateSecret, getSecret } from "../../api.js"; import { makeElement } from "../../htmlUtils.js"; +import { pageState } from "../../globalPageState.js"; import { verifyJSONString } from "../../utils.js"; import i18next from 'i18next'; diff --git a/src/pages/KeyValue/KeyValueVersions.js b/src/pages/KeyValue/KeyValueVersions.js index 5745b51..53e8dea 100644 --- a/src/pages/KeyValue/KeyValueVersions.js +++ b/src/pages/KeyValue/KeyValueVersions.js @@ -2,6 +2,7 @@ import { Page } from "../../types/Page.js"; import { changePage, setPageContent, setTitleElement } from "../../pageUtils.js"; import { getSecretMetadata } from "../../api.js"; import { makeElement } from "../../htmlUtils.js"; +import { pageState } from "../../globalPageState.js"; import i18next from 'i18next'; diff --git a/src/pages/KeyValue/KeyValueView.js b/src/pages/KeyValue/KeyValueView.js index e0cec16..4ff95fa 100644 --- a/src/pages/KeyValue/KeyValueView.js +++ b/src/pages/KeyValue/KeyValueView.js @@ -3,6 +3,7 @@ import { Page } from "../../types/Page.js"; import { changePage, setErrorText, setTitleElement } from "../../pageUtils.js"; import { getSecrets } from "../../api.js"; import { makeElement } from "../../htmlUtils.js"; +import { pageState } from "../../globalPageState.js"; import i18next from 'i18next'; diff --git a/src/pages/Me.js b/src/pages/Me.js index 2f1b75d..42c91fb 100644 --- a/src/pages/Me.js +++ b/src/pages/Me.js @@ -1,8 +1,8 @@ import { Page } from "../types/Page.js"; import { addClipboardNotifications, changePage, prePageChecks, setErrorText, setPageContent } from "../pageUtils.js"; import { getCapabilitiesPath, renewSelf, sealVault } from "../api.js"; -import { getToken } from "../utils.js"; import { makeElement } from "../htmlUtils.js"; +import { pageState } from "../globalPageState.js"; import ClipboardJS from "clipboard"; import i18next from 'i18next'; @@ -35,7 +35,7 @@ export class MePage extends Page { tag: "a", text: i18next.t("copy_token_btn"), attributes: { - "data-clipboard-text": getToken(), + "data-clipboard-text": pageState.token, }, thenRun: (e) => { let clipboard = new ClipboardJS(e); diff --git a/src/pages/SetLanguage.js b/src/pages/SetLanguage.js index 4bce5c3..d5c4013 100644 --- a/src/pages/SetLanguage.js +++ b/src/pages/SetLanguage.js @@ -2,6 +2,7 @@ import { Margin } from "../elements/Margin.js"; import { Page } from "../types/Page.js"; import { changePage, setPageContent } from "../pageUtils.js"; import { makeElement } from "../htmlUtils.js"; +import { pageState } from "../globalPageState.js"; import i18next from 'i18next'; import translations from "../translations/index.mjs"; diff --git a/src/pages/TOTP/NewTOTP.js b/src/pages/TOTP/NewTOTP.js index fb0ae4e..a74f645 100644 --- a/src/pages/TOTP/NewTOTP.js +++ b/src/pages/TOTP/NewTOTP.js @@ -4,6 +4,7 @@ import { Page } from "../../types/Page.js"; import { addNewTOTP } from "../../api.js"; import { changePage, setErrorText, setPageContent, setTitleElement } from "../../pageUtils.js"; import { makeElement } from "../../htmlUtils.js"; +import { pageState } from "../../globalPageState.js"; import i18next from 'i18next'; export class NewTOTPPage extends Page { diff --git a/src/pages/TOTP/TOTPView.js b/src/pages/TOTP/TOTPView.js index c49ccfc..a209596 100644 --- a/src/pages/TOTP/TOTPView.js +++ b/src/pages/TOTP/TOTPView.js @@ -4,6 +4,7 @@ import { Page } from "../../types/Page.js"; import { changePage, setErrorText, setPageContent, setTitleElement } from "../../pageUtils.js"; import { getTOTPCode, getTOTPKeys } from "../../api.js"; import { makeElement } from "../../htmlUtils.js"; +import { pageState } from "../../globalPageState.js"; import i18next from 'i18next'; export class TOTPViewPage extends Page { diff --git a/src/pages/Template.js b/src/pages/Template.js index 59256bb..19f37b2 100644 --- a/src/pages/Template.js +++ b/src/pages/Template.js @@ -1,6 +1,7 @@ import { Page } from "../types/Page.js"; import { changePage, setPageContent, setTitleElement } from "../pageUtils.js"; import { makeElement } from "../htmlUtils.js"; +import { pageState } from "../globalPageState.js"; export class TemplatePage extends Page { constructor() { diff --git a/src/pages/Transit/TransitDecrypt.js b/src/pages/Transit/TransitDecrypt.js index 93a0a83..fb3ab8a 100644 --- a/src/pages/Transit/TransitDecrypt.js +++ b/src/pages/Transit/TransitDecrypt.js @@ -3,11 +3,11 @@ import { Margin } from "../../elements/Margin.js"; import { Page } from "../../types/Page.js"; import { changePage, setErrorText, setPageContent, setTitleElement } from "../../pageUtils.js"; import { makeElement } from "../../htmlUtils.js"; +import { pageState } from "../../globalPageState.js"; import { transitDecrypt } from "../../api.js"; import UIkit from 'uikit/dist/js/uikit.min.js'; import i18next from "i18next"; - export class TransitDecryptPage extends Page { constructor() { super(); diff --git a/src/pages/Transit/TransitEncrypt.js b/src/pages/Transit/TransitEncrypt.js index 5eeb598..9fc32a0 100644 --- a/src/pages/Transit/TransitEncrypt.js +++ b/src/pages/Transit/TransitEncrypt.js @@ -3,6 +3,7 @@ import { Margin } from "../../elements/Margin.js"; import { Page } from "../../types/Page.js"; import { changePage, setErrorText, setPageContent, setTitleElement } from "../../pageUtils.js"; import { makeElement } from "../../htmlUtils.js"; +import { pageState } from "../../globalPageState.js"; import { transitEncrypt } from "../../api.js"; import UIkit from 'uikit/dist/js/uikit.min.js'; import i18next from "i18next"; diff --git a/src/pages/Transit/TransitView.js b/src/pages/Transit/TransitView.js index 2d874c1..3928f56 100644 --- a/src/pages/Transit/TransitView.js +++ b/src/pages/Transit/TransitView.js @@ -3,6 +3,7 @@ import { Page } from "../../types/Page.js"; import { changePage, setErrorText, setTitleElement } from "../../pageUtils.js"; import { getTransitKeys } from "../../api.js"; import { makeElement } from "../../htmlUtils.js"; +import { pageState } from "../../globalPageState.js"; import i18next from 'i18next'; export class TransitViewPage extends Page { diff --git a/src/pages/Transit/TransitViewSecret.js b/src/pages/Transit/TransitViewSecret.js index 131cac8..4ac041c 100644 --- a/src/pages/Transit/TransitViewSecret.js +++ b/src/pages/Transit/TransitViewSecret.js @@ -1,6 +1,7 @@ import { Page } from "../../types/Page.js"; import { changePage, setPageContent, setTitleElement } from "../../pageUtils.js"; import { makeElement } from "../../htmlUtils.js"; +import { pageState } from "../../globalPageState.js"; import i18next from 'i18next'; export class TransitViewSecretPage extends Page { diff --git a/src/pages/Unseal.js b/src/pages/Unseal.js index dc0a068..a7ccfba 100644 --- a/src/pages/Unseal.js +++ b/src/pages/Unseal.js @@ -1,12 +1,11 @@ -import i18next from 'i18next'; - -import { changePage, setErrorText, setPageContent } from "../pageUtils.js"; -import { getSealStatus, submitUnsealKey } from "../api.js"; - import { MarginInline } from "../elements/MarginInline.js"; import { Page } from "../types/Page.js"; import { QRScanner } from "../elements/QRScanner.js"; +import { changePage, setErrorText, setPageContent } from "../pageUtils.js"; +import { getSealStatus, submitUnsealKey } from "../api.js"; import { makeElement } from "../htmlUtils.js"; +import i18next from 'i18next'; + const UnsealInputModes = { FORM_INPUT: "FORM_INPUT", diff --git a/src/pages/index.js b/src/pages/index.js deleted file mode 100644 index bfbcd27..0000000 --- a/src/pages/index.js +++ /dev/null @@ -1,19 +0,0 @@ -export { HomePage } from "./Home.js"; -export { LoginPage } from "./Login.js"; -export { SetVaultURLPage } from "./SetVaultURL.js"; -export { MePage } from "./Me.js"; -export { UnsealPage } from "./Unseal.js"; -export { PwGenPage } from "./PwGen.js"; -export { SetLanguagePage } from "./SetLanguage.js"; -export { TOTPViewPage } from "./TOTP/TOTPView.js"; -export { NewTOTPPage } from "./TOTP/NewTOTP.js"; -export { KeyValueViewPage } from "./KeyValue/KeyValueView.js"; -export { KeyValueSecretPage } from "./KeyValue/KeyValueSecret.js"; -export { KeyValueVersionsPage } from "./KeyValue/KeyValueVersions.js"; -export { KeyValueNewPage } from "./KeyValue/KeyValueNew.js"; -export { KeyValueDeletePage } from "./KeyValue/KeyValueDelete.js"; -export { KeyValueSecretEditPage } from "./KeyValue/KeyValueSecretsEdit.js"; -export { TransitViewPage } from "./Transit/TransitView.js"; -export { TransitViewSecretPage } from "./Transit/TransitViewSecret.js"; -export { TransitEncryptPage } from "./Transit/TransitEncrypt.js"; -export { TransitDecryptPage } from "./Transit/TransitDecrypt.js"; \ No newline at end of file diff --git a/src/utils.js b/src/utils.js index 4ad1235..290e904 100644 --- a/src/utils.js +++ b/src/utils.js @@ -18,12 +18,4 @@ export function verifyJSONString(str) { return false; } return true; -} - -export function getToken() { - return pageState.token.length > 0 ? pageState.token : null; -} - -export function getAPIURL() { - return pageState.apiURL.length > 0 ? pageState.apiURL : null; } \ No newline at end of file