diff --git a/src/elements/CopyableInputBox.js b/src/elements/CopyableInputBox.ts similarity index 69% rename from src/elements/CopyableInputBox.js rename to src/elements/CopyableInputBox.ts index 7ad2099..7157aaa 100644 --- a/src/elements/CopyableInputBox.js +++ b/src/elements/CopyableInputBox.ts @@ -4,8 +4,12 @@ import { makeElement } from "../htmlUtils"; import ClipboardJS from "clipboard"; import i18next from "i18next"; -export function CopyableInputBox(text, copyable = true) { - let inputBoxDiv = makeElement({ tag: "div" }); +interface CopyableInputBoxType extends HTMLElement { + setText(text: string): void; +} + +export function CopyableInputBox(text: string, copyable = true): CopyableInputBoxType { + const inputBoxDiv = (makeElement({ tag: "div" }) as CopyableInputBoxType); let inputBoxCopyButton = null; if (copyable) { inputBoxCopyButton = makeElement({ @@ -17,26 +21,26 @@ export function CopyableInputBox(text, copyable = true) { "aria-label": i18next.t("copy_input_box_copy_icon_text") }, thenRun: (e) => { - let clipboard = new ClipboardJS(e); + const clipboard = new ClipboardJS(e); addClipboardNotifications(clipboard, 600); } }); } - let inputBoxInput = makeElement({ + const inputBoxInput = makeElement({ tag: "input", class: ["uk-input"], attributes: { "readonly": true, "type": "text" }, }); - let inputBoxInner = MarginInline([ + const inputBoxInner = MarginInline([ inputBoxCopyButton, inputBoxInput ]); inputBoxDiv.appendChild(inputBoxInner); inputBoxDiv.setText = function (text) { - inputBoxInput.value = `${text}`; + (inputBoxInput as HTMLInputElement).value = `${text}`; if (copyable) { inputBoxCopyButton.dataset.clipboardText = `${text}`; } diff --git a/src/elements/renewSelf.ts b/src/elements/renewSelf.ts new file mode 100644 index 0000000..06751f4 --- /dev/null +++ b/src/elements/renewSelf.ts @@ -0,0 +1,19 @@ +import { appendAPIURL, getHeaders } from "../api/apiUtils"; + +export async function renewSelf(): Promise { + const request = new Request(appendAPIURL("/v1/auth/token/renew-self"), { + method: 'POST', + headers: { + ...getHeaders(), + 'Content-Type': 'application/json' + }, + body: JSON.stringify({}) + }); + return fetch(request).then(response => { + return response.json(); + }).then(data => { + if ("errors" in data) { + throw new Error(data.errors[0]); + } + }); +} diff --git a/src/pages/KeyValue/KeyValueSecret.js b/src/pages/KeyValue/KeyValueSecret.js index 3176f8f..207c1b9 100644 --- a/src/pages/KeyValue/KeyValueSecret.js +++ b/src/pages/KeyValue/KeyValueSecret.js @@ -1,4 +1,4 @@ -import { CopyableInputBox } from "../../elements/CopyableInputBox.js"; +import { CopyableInputBox } from "../../elements/CopyableInputBox"; import { Page } from "../../types/Page"; import { changePage, setPageContent, setTitleElement } from "../../pageUtils"; import { getCapabilities } from "../../api/getCapabilities"; diff --git a/src/pages/PwGen.js b/src/pages/PwGen.js index 7df70a3..ac95f6a 100644 --- a/src/pages/PwGen.js +++ b/src/pages/PwGen.js @@ -1,4 +1,4 @@ -import { CopyableInputBox } from "../elements/CopyableInputBox.js"; +import { CopyableInputBox } from "../elements/CopyableInputBox"; import { Margin } from "../elements/Margin.js"; import { Page } from "../types/Page"; import { makeElement } from "../htmlUtils"; diff --git a/src/pages/TOTP/TOTPView.js b/src/pages/TOTP/TOTPView.js index 46a6047..7afa768 100644 --- a/src/pages/TOTP/TOTPView.js +++ b/src/pages/TOTP/TOTPView.js @@ -1,4 +1,4 @@ -import { CopyableInputBox } from "../../elements/CopyableInputBox.js"; +import { CopyableInputBox } from "../../elements/CopyableInputBox"; import { DoesNotExistError } from "../../types/internalErrors"; import { Page } from "../../types/Page"; import { changePage, setErrorText, setPageContent, setTitleElement } from "../../pageUtils";