summaryrefslogtreecommitdiff
path: root/backoffice/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'backoffice/index.js')
-rw-r--r--backoffice/index.js86
1 files changed, 51 insertions, 35 deletions
diff --git a/backoffice/index.js b/backoffice/index.js
index 9410585ae..3c1833fd2 100644
--- a/backoffice/index.js
+++ b/backoffice/index.js
@@ -15617,13 +15617,13 @@ function strToUTF8Arr(sDOMStr) {
}
return aBytes;
}
-var ErrorType = /* @__PURE__ */ ((ErrorType22) => {
- ErrorType22[ErrorType22["CLIENT"] = 0] = "CLIENT";
- ErrorType22[ErrorType22["SERVER"] = 1] = "SERVER";
- ErrorType22[ErrorType22["UNREADABLE"] = 2] = "UNREADABLE";
- ErrorType22[ErrorType22["TIMEOUT"] = 3] = "TIMEOUT";
- ErrorType22[ErrorType22["UNEXPECTED"] = 4] = "UNEXPECTED";
- return ErrorType22;
+var ErrorType = /* @__PURE__ */ ((ErrorType2) => {
+ ErrorType2[ErrorType2["CLIENT"] = 0] = "CLIENT";
+ ErrorType2[ErrorType2["SERVER"] = 1] = "SERVER";
+ ErrorType2[ErrorType2["UNREADABLE"] = 2] = "UNREADABLE";
+ ErrorType2[ErrorType2["TIMEOUT"] = 3] = "TIMEOUT";
+ ErrorType2[ErrorType2["UNEXPECTED"] = 4] = "UNEXPECTED";
+ return ErrorType2;
})(ErrorType || {});
function defaultRequestHandler(_0, _1) {
return __async(this, arguments, function* (baseUrl, endpoint, options = {}) {
@@ -19918,7 +19918,7 @@ function useBackendBaseRequest() {
const token = loginToken == null ? void 0 : loginToken.token;
const request = T2(
function requestImpl(endpoint, options = {}) {
- return requestHandler(backend, endpoint, __spreadValues({ token }, options)).then((res) => {
+ return requestHandler(backend, endpoint, __spreadProps(__spreadValues({}, options), { token })).then((res) => {
return res;
}).catch((err) => {
throw err;
@@ -20200,16 +20200,18 @@ function useManagementAPI(instanceId) {
});
mutateAll(/\/management\/instances/);
});
- const clearToken = () => __async(this, null, function* () {
+ const clearAccessToken = (currentToken) => __async(this, null, function* () {
yield request(`/management/instances/${instanceId}/auth`, {
method: "POST",
+ token: currentToken,
data: { method: "external" }
});
mutateAll(/\/management\/instances/);
});
- const setNewToken = (newToken) => __async(this, null, function* () {
+ const setNewAccessToken = (currentToken, newToken) => __async(this, null, function* () {
yield request(`/management/instances/${instanceId}/auth`, {
method: "POST",
+ token: currentToken,
data: { method: "token", token: newToken }
});
const resp = yield requestNewLoginToken(backendURL, newToken);
@@ -20221,7 +20223,7 @@ function useManagementAPI(instanceId) {
}
mutateAll(/\/management\/instances/);
});
- return { updateInstance, deleteInstance, setNewToken, clearToken };
+ return { updateInstance, deleteInstance, setNewAccessToken, clearAccessToken };
}
function useInstanceAPI() {
const { mutate: mutate2 } = useSWRConfig();
@@ -20249,16 +20251,18 @@ function useInstanceAPI() {
mutate2(["/private/instances", adminToken, backendURL], null);
mutate2([`/private/`], null);
});
- const clearToken = () => __async(this, null, function* () {
+ const clearAccessToken = (currentToken) => __async(this, null, function* () {
yield request(`/private/auth`, {
method: "POST",
+ token: currentToken,
data: { method: "external" }
});
mutate2([`/private/`], null);
});
- const setNewToken = (newToken) => __async(this, null, function* () {
+ const setNewAccessToken = (currentToken, newToken) => __async(this, null, function* () {
yield request(`/private/auth`, {
method: "POST",
+ token: currentToken,
data: { method: "token", token: newToken }
});
const resp = yield requestNewLoginToken(backendURL, newToken);
@@ -20270,7 +20274,7 @@ function useInstanceAPI() {
}
mutate2([`/private/`], null);
});
- return { updateInstance, deleteInstance, setNewToken, clearToken };
+ return { updateInstance, deleteInstance, setNewAccessToken, clearAccessToken };
}
function useInstanceDetails() {
const { fetcher } = useBackendInstanceRequest();
@@ -31790,17 +31794,15 @@ init_preact_module();
// src/paths/instance/token/DetailPage.tsx
init_preact_module();
init_hooks_module();
-function DetailPage({ instanceId, currentToken: oldToken, onBack, onNewToken, onClearToken }) {
+function DetailPage({ instanceId, hasToken, onBack, onNewToken, onClearToken }) {
const [form, setValue] = p3({
old_token: "",
new_token: "",
repeat_token: ""
});
const { i18n: i18n2 } = useTranslationContext();
- const hasOldtoken = !!oldToken;
- const hasInputTheCorrectOldToken = hasOldtoken && oldToken !== form.old_token;
const errors2 = {
- old_token: hasInputTheCorrectOldToken ? i18n2.str`is not the same as the current access token` : void 0,
+ old_token: hasToken && !form.old_token ? i18n2.str`you need your access token to perform the operation` : void 0,
new_token: !form.new_token ? i18n2.str`cannot be empty` : form.new_token === form.old_token ? i18n2.str`cannot be the same as the old token` : void 0,
repeat_token: form.new_token !== form.repeat_token ? i18n2.str`is not the same` : void 0
};
@@ -31813,11 +31815,12 @@ function DetailPage({ instanceId, currentToken: oldToken, onBack, onNewToken, on
return __async(this, null, function* () {
if (hasErrors)
return;
+ const ot = hasToken ? `secret-token:${form.old_token}` : void 0;
const nt = `secret-token:${form.new_token}`;
- onNewToken(nt);
+ onNewToken(ot, nt);
});
}
- return /* @__PURE__ */ h("div", null, /* @__PURE__ */ h("section", { class: "section" }, /* @__PURE__ */ h("section", { class: "hero is-hero-bar" }, /* @__PURE__ */ h("div", { class: "hero-body" }, /* @__PURE__ */ h("div", { class: "level" }, /* @__PURE__ */ h("div", { class: "level-left" }, /* @__PURE__ */ h("div", { class: "level-item" }, /* @__PURE__ */ h("span", { class: "is-size-4" }, "Instance id: ", /* @__PURE__ */ h("b", null, instanceId))))))), /* @__PURE__ */ h("hr", null), /* @__PURE__ */ h("div", { class: "columns" }, /* @__PURE__ */ h("div", { class: "column" }), /* @__PURE__ */ h("div", { class: "column is-four-fifths" }, /* @__PURE__ */ h(FormProvider, { errors: errors2, object: form, valueHandler: setValue }, hasOldtoken && /* @__PURE__ */ h(
+ return /* @__PURE__ */ h("div", null, /* @__PURE__ */ h("section", { class: "section" }, /* @__PURE__ */ h("section", { class: "hero is-hero-bar" }, /* @__PURE__ */ h("div", { class: "hero-body" }, /* @__PURE__ */ h("div", { class: "level" }, /* @__PURE__ */ h("div", { class: "level-left" }, /* @__PURE__ */ h("div", { class: "level-item" }, /* @__PURE__ */ h("span", { class: "is-size-4" }, "Instance id: ", /* @__PURE__ */ h("b", null, instanceId))))))), /* @__PURE__ */ h("hr", null), /* @__PURE__ */ h("div", { class: "columns" }, /* @__PURE__ */ h("div", { class: "column" }), /* @__PURE__ */ h("div", { class: "column is-four-fifths" }, /* @__PURE__ */ h(FormProvider, { errors: errors2, object: form, valueHandler: setValue }, /* @__PURE__ */ h(p2, null, hasToken && /* @__PURE__ */ h(p2, null, /* @__PURE__ */ h(
Input,
{
name: "old_token",
@@ -31825,12 +31828,18 @@ function DetailPage({ instanceId, currentToken: oldToken, onBack, onNewToken, on
tooltip: i18n2.str`access token currently in use`,
inputType: "password"
}
- ), !hasInputTheCorrectOldToken && /* @__PURE__ */ h(p2, null, hasOldtoken && /* @__PURE__ */ h(p2, null, /* @__PURE__ */ h("p", null, /* @__PURE__ */ h(i18n2.Translate, null, "Clearing the access token will mean public access to the instance.")), /* @__PURE__ */ h("div", { class: "buttons is-right mt-5" }, /* @__PURE__ */ h(
+ ), /* @__PURE__ */ h("p", null, /* @__PURE__ */ h(i18n2.Translate, null, "Clearing the access token will mean public access to the instance.")), /* @__PURE__ */ h("div", { class: "buttons is-right mt-5" }, /* @__PURE__ */ h(
"button",
{
- disabled: !!hasInputTheCorrectOldToken,
class: "button",
- onClick: onClearToken
+ onClick: () => {
+ if (hasToken) {
+ const ot = `secret-token:${form.old_token}`;
+ onClearToken(ot);
+ } else {
+ onClearToken(void 0);
+ }
+ }
},
/* @__PURE__ */ h(i18n2.Translate, null, "Clear token")
))), /* @__PURE__ */ h(
@@ -31862,7 +31871,6 @@ function DetailPage({ instanceId, currentToken: oldToken, onBack, onNewToken, on
// src/paths/instance/token/index.tsx
init_hooks_module();
-var PREFIX = "secret-token:";
function Token({
onLoadError,
onChange,
@@ -31871,19 +31879,27 @@ function Token({
}) {
const { i18n: i18n2 } = useTranslationContext();
const [notif, setNotif] = p3(void 0);
- const { clearToken, setNewToken } = useInstanceAPI();
- const { token: rootToken } = useBackendContext();
- const { token: instanceToken, id, admin } = useInstanceContext();
- const currentToken = !admin ? rootToken : instanceToken;
- const hasPrefix = currentToken !== void 0 && currentToken.token.startsWith(PREFIX);
+ const { clearAccessToken, setNewAccessToken } = useInstanceAPI();
+ const { id } = useInstanceContext();
+ const result = useInstanceDetails();
+ if (result.loading)
+ return /* @__PURE__ */ h(Loading, null);
+ if (!result.ok) {
+ if (result.type === ErrorType.CLIENT && result.status === HttpStatusCode.Unauthorized)
+ return onUnauthorized();
+ if (result.type === ErrorType.CLIENT && result.status === HttpStatusCode.NotFound)
+ return onNotFound();
+ return onLoadError(result);
+ }
+ const hasToken = result.data.auth.method === "token";
return /* @__PURE__ */ h(p2, null, /* @__PURE__ */ h(NotificationCard, { notification: notif }), /* @__PURE__ */ h(
DetailPage,
{
instanceId: id,
- currentToken: hasPrefix ? currentToken.token.substring(PREFIX.length) : currentToken == null ? void 0 : currentToken.token,
- onClearToken: () => __async(this, null, function* () {
+ hasToken,
+ onClearToken: (currentToken) => __async(this, null, function* () {
try {
- yield clearToken();
+ yield clearAccessToken(currentToken);
onChange();
} catch (error2) {
if (error2 instanceof Error) {
@@ -31895,9 +31911,9 @@ function Token({
}
}
}),
- onNewToken: (newToken) => __async(this, null, function* () {
+ onNewToken: (currentToken, newToken) => __async(this, null, function* () {
try {
- yield setNewToken(newToken);
+ yield setNewAccessToken(currentToken, newToken);
onChange();
} catch (error2) {
if (error2 instanceof Error) {
@@ -43073,7 +43089,7 @@ function ApplicationReadyRoutes() {
{
notification: {
message: i18n2.str`Access denied`,
- description: i18n2.str`Check your token is valid 1`,
+ description: i18n2.str`Check your token is valid`,
type: "ERROR"
}
}