diff --git a/src/components/Admin/Actions/ListLogs.tsx b/src/components/Admin/Actions/ListLogs.tsx new file mode 100644 index 0000000..1a364b0 --- /dev/null +++ b/src/components/Admin/Actions/ListLogs.tsx @@ -0,0 +1,73 @@ +import React from "react"; +import { LogResults, ListLogsPageProps } from "../interfaces"; +import { getAppHelper } from "../Utils"; + +export const ListLogs: React.FC = (props) => { + const { pageName = "", csrfToken = "" } = props; + const { setProps } = getAppHelper(pageName); + const [results, setResults] = React.useState([]); + + const onSubmit = () => { + const data = {} as { logId: string }; + + Array.from(document.querySelectorAll("input")).forEach(input => { + const key = input.getAttribute("id") as string; + data[key] = input.value; + }); + + if (!data.logId) { + setProps({ + ...props, + dialog: { className: "alert-danger", message: "You must provide a log id" } + }); + } + + fetch(`/admp/logs?logId=${data.logId}`, { + method: 'get', + headers: { "X-Apiker-Csrf": csrfToken } + }) + .then(r => r.json().then(res => ({ status: r.status, body: res }))) + .then(data => { + const { status, body = {} } = data; + const { entries = [] } = body; + const isSucessful = status === 200; + + const message = isSucessful ? "Action performed successfully" : "Failure returned by the endpoint."; + + setProps({ + ...props, + dialog: { className: isSucessful ? "alert-primary" : "alert-danger", message } + }); + + setResults(entries); + }) + .catch(error => { + setProps({ + ...props, + dialog: { className: "alert-danger", message: error?.message } + }); + }) + }; + + return ( +
+
+ + +
+ {(results && results.length) ? results.map((result) => ( +
+
+
    + {Object.keys(result).map((key) => ( +
  • {key} + {key === "time" ? new Date(result[key] as string).toLocaleString() : result[key]} +
  • + ))} +
+
+
+ )) : null} +
+ ); +} \ No newline at end of file diff --git a/src/components/Admin/Admin.ts b/src/components/Admin/Admin.ts index 7889d7e..e4f2846 100644 --- a/src/components/Admin/Admin.ts +++ b/src/components/Admin/Admin.ts @@ -1,7 +1,7 @@ import { Handler, RequestParams } from "../Request"; import { resRaw } from "../Response"; import { apikerPagesStatic } from "../Static"; -import { bansEndpoint, loginEndpoint, searchBansEndpoint, sendEmailEndpoint, updateUserEndpoint } from "./Api"; +import { searchLogsEndpoint, bansEndpoint, loginEndpoint, searchBansEndpoint, sendEmailEndpoint, updateUserEndpoint } from "./Api"; import { adminPanelPage } from "./Panel"; import { adminCsrfCheckMiddleware, adminMiddleware } from "./middleware"; @@ -17,6 +17,7 @@ export const getAdminRoutes = () => ({ "/admp/login": (params: RequestParams) => adminCsrfCheckMiddleware(params, loginEndpoint), // Check for admin logged in and CSRF + "/admp/logs": (params: RequestParams) => adminMiddleware(params, searchLogsEndpoint), "/admp/bans": (params: RequestParams) => adminMiddleware(params, bansEndpoint), "/admp/bans/:userId": (params: RequestParams) => adminMiddleware(params, searchBansEndpoint), "/admp/email": (params: RequestParams) => adminMiddleware(params, sendEmailEndpoint), diff --git a/src/components/Admin/Api/index.ts b/src/components/Admin/Api/index.ts index fdce8cb..78865e0 100644 --- a/src/components/Admin/Api/index.ts +++ b/src/components/Admin/Api/index.ts @@ -1,3 +1,4 @@ +export * from "./logsEndpoint"; export * from "./bansEndpoint"; export * from "./loginEndpoint"; export * from "./sendEmailEndpoint"; diff --git a/src/components/Admin/Api/logsEndpoint.ts b/src/components/Admin/Api/logsEndpoint.ts new file mode 100644 index 0000000..63099b2 --- /dev/null +++ b/src/components/Admin/Api/logsEndpoint.ts @@ -0,0 +1,17 @@ +import { getLogEntries } from '../../Logging'; +import { Handler } from '../../Request'; +import { res, res_400 } from '../../Response'; + +export const searchLogsEndpoint: Handler = async (params) => { + const { request } = params; + const url = new URL(request.url); + const search = new URLSearchParams(url.search); + const logId = search.get("logId") || ""; + + if(!logId){ + return res_400(); + } + + const entries = await getLogEntries(logId, 100); + return res({ entries }); +} \ No newline at end of file diff --git a/src/components/Admin/Api/updateUserEndpoint.ts b/src/components/Admin/Api/updateUserEndpoint.ts index 43766fd..48b15c4 100644 --- a/src/components/Admin/Api/updateUserEndpoint.ts +++ b/src/components/Admin/Api/updateUserEndpoint.ts @@ -44,12 +44,18 @@ export const updateUserEndpoint: Handler = async ({ state, body, request }) => { } /** Do not allow user update of admin, unless same user */ - if(request.method === "PUT" || request.method === "DELETE"){ + if(request.method === "PUT"){ if(user?.email !== userEmail && user?.role === "admin"){ return res_401(); } } + if(request.method === "DELETE"){ + if(user?.role === "admin"){ + return res_401(); + } + } + let updatedFields: { email?: string } = {}; if(request.method === "PUT"){ const { email } = body?.updatedUser ? JSON.parse(body.updatedUser) : {} as User; diff --git a/src/components/Admin/Panel.tsx b/src/components/Admin/Panel.tsx index 4a7db6c..9916899 100644 --- a/src/components/Admin/Panel.tsx +++ b/src/components/Admin/Panel.tsx @@ -19,6 +19,7 @@ import { SearchBans } from "./Actions/SearchBans"; import { SendEmail } from "./Actions/SendEmail"; import { UpdateUser } from "./Actions/UpdateUser"; import { DeleteUser } from "./Actions/DeleteUser"; +import { ListLogs } from "./Actions/ListLogs"; export const adminPanelPage: Handler = async ({ state }) => { const pageName = "AdminPanelPage"; @@ -40,6 +41,7 @@ const actionsComponent = { banUser: BanUser, unbanUser: UnbanUser, searchBans: SearchBans, + listLogs: ListLogs, sendEmail: SendEmail, updateUser: UpdateUser, deleteUser: DeleteUser @@ -52,6 +54,8 @@ export const AdminPanelPage: React.FC = (props) => { if(isAdminLoggedIn){ actions = authActions; + } else { + actions = defaultActions; } const onDropdownItemClick = (action: Action) => { diff --git a/src/components/Admin/constants.ts b/src/components/Admin/constants.ts index 38a462e..77e1bcd 100644 --- a/src/components/Admin/constants.ts +++ b/src/components/Admin/constants.ts @@ -22,6 +22,10 @@ export const authActions: Actions = [ id: "searchBans", displayName: "Search Bans" }, + { + id: "listLogs", + displayName: "List Logs" + }, { id: "sendEmail", displayName: "Send Email" diff --git a/src/components/Admin/interfaces.ts b/src/components/Admin/interfaces.ts index e51b1c8..02d9c64 100644 --- a/src/components/Admin/interfaces.ts +++ b/src/components/Admin/interfaces.ts @@ -50,6 +50,7 @@ export interface LoginPageProps extends AdminPanelPageProps {} export interface BanUserPageProps extends AdminPanelPageProps {} export interface UnbanUserPageProps extends AdminPanelPageProps {} export interface SearchBansPageProps extends AdminPanelPageProps {} +export interface ListLogsPageProps extends AdminPanelPageProps {} export interface SendEmailPageProps extends AdminPanelPageProps {} export interface UpdateUserPageProps extends AdminPanelPageProps {} export interface DeleteUserPageProps extends AdminPanelPageProps {} \ No newline at end of file diff --git a/src/components/Static/staticPages.ts b/src/components/Static/staticPages.ts index ae36061..b2f2a15 100644 --- a/src/components/Static/staticPages.ts +++ b/src/components/Static/staticPages.ts @@ -1 +1 @@ -export const apikerPagesStatic = `var pages=function(e,t,a,n,r){"use strict";function l(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=l(e),o=l(a),i=l(n),u=l(r),c=function(){return c=Object.assign||function(e){for(var t,a=1,n=arguments.length;a

Email Reset

If you received this email, it means that you\\'ve used the Reset Password feature. If so, click the following link to proceed:

Reset User Email

If you have not initiated this request, please disregard this message. The link will expire in 5 minutes.

',verifyAccount:'

Verify Account

If you received this email, it means that you\\'ve created an account at {appName}. If so, click the following link to activate your account:

Activate account

If you have not initiated this request, please disregard this message. The link will expire in 5 minutes.

'},b=function(e){var t=e.onButtonClick,a=e.onChange,n=e.buttonLabel,r=e.value;return s.default.useEffect((function(){var e=function(){var e=document.querySelector("#input-group-1 input"),t=document.querySelector("#input-group-1 button"),a=parseFloat(t.offsetWidth);e.style.maxWidth="calc(100% - ".concat(a,"px - 15px)")};window.addEventListener("resize",e),e()}),[]),s.default.createElement("div",{className:"input-group mt-2",id:"input-group-1"},s.default.createElement("input",{className:"form-control form-control-lg",id:"userEmail",type:"email",placeholder:"User Email",onChange:a,value:r}),s.default.createElement("button",{className:"btn btn-outline-secondary",type:"button",onClick:t},n))},y={login:function(e){var t=e.isSetup,a=e.pageName,n=void 0===a?"":a,r=e.csrfToken,l=void 0===r?"":r,o=g(n).setProps;return s.default.createElement("div",{className:"action-wrapper"},t&&s.default.createElement("div",{className:"alert alert-primary mb-0",role:"alert"},"Welcome to Apiker! Please setup your account in order to manage your app."),s.default.createElement("form",{className:"login-form",onSubmit:function(){var t=new FormData;Array.from(document.querySelectorAll("input")).forEach((function(e){var a=e.getAttribute("id");t.append(a,e.value)})),fetch("/admp/login",{method:"post",body:t,headers:{"X-Apiker-Csrf":l}}).then((function(e){return e.json().then((function(t){return{status:e.status,body:t}}))})).then((function(t){var a=200===t.status,n=a?void 0:e.action,r=a?"Sucess! You can now select a new action":"Failure returned by the endpoint.";o(c(c({},e),{action:n,actions:m,dialog:{className:a?"alert-primary":"alert-danger",message:r}}))})).catch((function(t){o(c(c({},e),{dialog:{className:"alert-danger",message:null==t?void 0:t.message}}))}))}},s.default.createElement("input",{className:"form-control form-control-lg mt-2",id:"email",type:"email",placeholder:"Email"}),s.default.createElement("input",{className:"form-control form-control-lg mt-2",id:"password",type:"password",placeholder:"Password"}),s.default.createElement("button",{className:"btn btn-primary mt-2 action-btn",type:"submit"},t?"Setup User":"Submit")))},banUser:function(e){var t=e.pageName,a=void 0===t?"":t,n=e.csrfToken,r=void 0===n?"":n,l=g(a).setProps;return s.default.createElement("div",{className:"action-wrapper"},s.default.createElement("form",{className:"login-form",onSubmit:function(){var t=new FormData;Array.from(document.querySelectorAll("input")).forEach((function(e){var a=e.getAttribute("id");t.append(a,e.value)})),fetch("/admp/bans",{method:"post",body:t,headers:{"X-Apiker-Csrf":r}}).then((function(e){return e.json().then((function(t){return{status:e.status,body:t}}))})).then((function(t){var a=200===t.status,n=a?"Action performed successfully":"Failure returned by the endpoint.";l(c(c({},e),{dialog:{className:a?"alert-primary":"alert-danger",message:n}}))})).catch((function(t){l(c(c({},e),{dialog:{className:"alert-danger",message:null==t?void 0:t.message}}))}))}},s.default.createElement("input",{className:"form-control form-control-lg mt-2",id:"userId",type:"text",placeholder:"User ID"}),s.default.createElement("button",{className:"btn btn-primary mt-2 action-btn",type:"submit"},"Submit")))},unbanUser:function(e){var t=e.pageName,a=void 0===t?"":t,n=e.csrfToken,r=void 0===n?"":n,l=g(a).setProps;return s.default.createElement("div",{className:"action-wrapper"},s.default.createElement("form",{className:"login-form",onSubmit:function(){var t=new FormData;Array.from(document.querySelectorAll("input")).forEach((function(e){var a=e.getAttribute("id");t.append(a,e.value)})),fetch("/admp/bans",{method:"delete",body:t,headers:{"X-Apiker-Csrf":r}}).then((function(e){return e.json().then((function(t){return{status:e.status,body:t}}))})).then((function(t){var a=200===t.status,n=a?"Action performed successfully":"Failure returned by the endpoint.";l(c(c({},e),{dialog:{className:a?"alert-primary":"alert-danger",message:n}}))})).catch((function(t){l(c(c({},e),{dialog:{className:"alert-danger",message:null==t?void 0:t.message}}))}))}},s.default.createElement("input",{className:"form-control form-control-lg mt-2",id:"userId",type:"text",placeholder:"User ID"}),s.default.createElement("button",{className:"btn btn-primary mt-2 action-btn",type:"submit"},"Submit")))},searchBans:function(e){var t=e.pageName,a=void 0===t?"":t,n=e.csrfToken,r=void 0===n?"":n,l=g(a).setProps,o=s.default.useState([]),i=o[0],u=o[1];return s.default.createElement("div",{className:"action-wrapper"},s.default.createElement("form",{className:"login-form",onSubmit:function(){var t={};Array.from(document.querySelectorAll("input")).forEach((function(e){var a=e.getAttribute("id");t[a]=e.value})),t.userId||l(c(c({},e),{dialog:{className:"alert-danger",message:"You must provide an user id"}})),fetch("/admp/bans/".concat(t.userId),{method:"get",headers:{"X-Apiker-Csrf":r}}).then((function(e){return e.json().then((function(t){return{status:e.status,body:t}}))})).then((function(t){var a=t.status,n=t.body,r=(void 0===n?{}:n).entries,s=200===a,o=(void 0===r?[]:r).map((function(e){return{time:e.time,id:e.id,clientId:e.clientId,countryCode:e.countryCode,pathname:e.pathname,issuedBy:e.issuedBy}})),i=s?"Action performed successfully":"Failure returned by the endpoint.";l(c(c({},e),{dialog:{className:s?"alert-primary":"alert-danger",message:i}})),u(o)})).catch((function(t){l(c(c({},e),{dialog:{className:"alert-danger",message:null==t?void 0:t.message}}))}))}},s.default.createElement("input",{className:"form-control form-control-lg mt-2",id:"userId",type:"text",placeholder:"User ID"}),s.default.createElement("button",{className:"btn btn-primary mt-2 action-btn",type:"submit"},"Submit")),i&&i.length?i.map((function(e){var t=e.time,a=e.id,n=e.clientId,r=e.countryCode,l=e.pathname,o=e.issuedBy;return s.default.createElement("div",{className:"results-container"},s.default.createElement("div",{className:"results-item"},s.default.createElement("ul",null,s.default.createElement("li",null,s.default.createElement("span",{className:"title"},"time")," ",s.default.createElement("span",{className:"text",title:new Date(t).toLocaleString()},new Date(t).toLocaleString())),s.default.createElement("li",null,s.default.createElement("span",{className:"title"},"id")," ",s.default.createElement("span",{className:"text",title:a},a)),s.default.createElement("li",null,s.default.createElement("span",{className:"title"},"clientId")," ",s.default.createElement("span",{className:"text",title:n},n)),s.default.createElement("li",null,s.default.createElement("span",{className:"title"},"countryCode")," ",s.default.createElement("span",{className:"text",title:r},r)),s.default.createElement("li",null,s.default.createElement("span",{className:"title"},"pathname")," ",s.default.createElement("span",{className:"text",title:l},l)),s.default.createElement("li",null,s.default.createElement("span",{className:"title"},"issuedBy")," ",s.default.createElement("span",{className:"text",title:o},o)))))})):null)},sendEmail:function(e){var t=s.default.useState(),a=t[0],n=t[1],r=e.pageName,l=void 0===r?"":r,o=e.csrfToken,i=void 0===o?"":o,u=g(l).setProps,d=s.default.createElement("div",{className:"btn-group mt-2"},s.default.createElement("button",{className:"btn btn-transparent btn-lg dropdown-toggle action-dropdown",type:"button",id:"main-dropdown","data-bs-toggle":"dropdown","aria-expanded":"false"},a||"Email template"),s.default.createElement("ul",{className:"dropdown-menu","aria-labelledby":"main-dropdown"},Object.keys(v).map((function(e){return s.default.createElement("li",{key:e},s.default.createElement("a",{className:"dropdown-item",href:"#",onClick:function(){n(e)}},e))}))));return s.default.createElement("div",{className:"action-wrapper"},s.default.createElement("div",{className:"alert alert-warning mb-0 mt-2",role:"alert"},s.default.createElement("b",null,"Note:"),' This option requires the "email" and "authRoutes" options to be enabled.'),s.default.createElement("form",{className:"login-form",onSubmit:function(){var t=new FormData;a&&(Array.from(document.querySelectorAll("input")).forEach((function(e){var a=e.getAttribute("id");t.append(a,e.value)})),t.append("template",a),fetch("/admp/email",{method:"post",body:t,headers:{"X-Apiker-Csrf":i}}).then((function(e){return e.json().then((function(t){return{status:e.status,body:t}}))})).then((function(t){var a=t.status,n=200===a||201===a,r=n?"Action performed successfully":"Failure returned by the endpoint.";u(c(c({},e),{dialog:{className:n?"alert-primary":"alert-danger",message:r}}))})).catch((function(t){u(c(c({},e),{dialog:{className:"alert-danger",message:null==t?void 0:t.message}}))})))}},s.default.createElement("input",{className:"form-control form-control-lg mt-2",id:"userEmail",type:"email",placeholder:"User Email"}),d,a?s.default.createElement("pre",{className:"m-0 mt-2"},s.default.createElement("code",null,v[a])):null,s.default.createElement("button",{className:"btn btn-primary mt-2 action-btn",type:"submit"},"Submit")))},updateUser:function(e){var t=s.default.useRef(""),a=s.default.useState(""),n=a[0],r=a[1],l=s.default.useState(""),o=l[0],i=l[1],u=e.pageName,d=void 0===u?"":u,m=e.csrfToken,f=void 0===m?"":m,p=g(d).setProps,h=function(e,t){var a;try{a=JSON.parse(e)}catch(e){}if(a){var n=JSON.stringify(a);r(n),t&&t(n)}};return console.log("partialUser",n),s.default.createElement("div",{className:"action-wrapper"},s.default.createElement("form",{className:"login-form",onSubmit:function(){if(o.trim())if(t.current&&n&&t.current!==n){var a=new FormData;Array.from(document.querySelectorAll("input")).forEach((function(e){var t=e.getAttribute("id");a.append(t,e.value)})),a.append("updatedUser",n),fetch("/admp/user",{method:"put",body:a,headers:{"X-Apiker-Csrf":f}}).then((function(e){return e.json().then((function(t){return{status:e.status,body:t}}))})).then((function(t){var a=200===t.status,n=a?"Action performed successfully":"Failure returned by the endpoint.";p(c(c({},e),{dialog:{className:a?"alert-primary":"alert-danger",message:n}}))})).catch((function(t){p(c(c({},e),{dialog:{className:"alert-danger",message:null==t?void 0:t.message}}))}))}else p(c(c({},e),{dialog:{className:"alert-danger",message:"Please fill out the fields correctly"}}));else p(c(c({},e),{dialog:{className:"alert-danger",message:"You must provide the user email"}}))}},s.default.createElement(b,{value:o,onButtonClick:function(){console.log("onUserEmailChange",o),fetch("/admp/user?"+new URLSearchParams({userEmail:o}),{method:"get",headers:{"X-Apiker-Csrf":f}}).then((function(e){return e.json().then((function(t){return{status:e.status,body:t}}))})).then((function(a){var n=a.status,r=a.body,l=(void 0===r?{}:r).partialUser;if(200===n)if(l){var s=JSON.stringify(l);h(s,(function(e){t.current=e})),p(c(c({},e),{dialog:{className:"alert-primary",message:"Action performed successfully"}}))}else p(c(c({},e),{dialog:{className:"alert-danger",message:"Endpoint error"}}));else p(c(c({},e),{dialog:{className:"alert-danger",message:"User not found!"}}));console.log(a)})).catch((function(e){console.log(e)}))},onChange:function(e){return i(e.target.value)},buttonLabel:"Find"}),n?s.default.createElement("textarea",{className:"m-0 mt-2",onChange:function(e){return h(e.target.value)},value:JSON.stringify(JSON.parse(n),null,2)}):null,s.default.createElement("button",{className:"btn btn-primary mt-2 action-btn",type:"submit"},"Submit")))},deleteUser:function(e){var t=s.default.useState(!1),a=t[0],n=t[1],r=s.default.useState(!1),l=r[0],o=r[1],i=e.pageName,u=void 0===i?"":i,d=e.csrfToken,m=void 0===d?"":d,f=g(u).setProps;return s.default.createElement("div",{className:"action-wrapper"},s.default.createElement("form",{className:"login-form",onSubmit:function(){var t;if((null===(t=document.getElementById("userEmail"))||void 0===t?void 0:t.value).trim())if(a&&l){var r=new FormData;Array.from(document.querySelectorAll("input")).forEach((function(e){var t=e.getAttribute("id");r.append(t,e.value)})),fetch("/admp/user",{method:"delete",body:r,headers:{"X-Apiker-Csrf":m}}).then((function(e){return e.json().then((function(t){return{status:e.status,body:t}}))})).then((function(t){var a=200===t.status,n=a?"Action performed successfully":"Failure returned by the endpoint.";f(c(c({},e),{dialog:{className:a?"alert-primary":"alert-danger",message:n}}))})).catch((function(t){f(c(c({},e),{dialog:{className:"alert-danger",message:null==t?void 0:t.message}}))}))}else n(!0);else f(c(c({},e),{dialog:{className:"alert-danger",message:"You must provide the user email"}}))}},s.default.createElement("input",{className:"form-control form-control-lg mt-2",id:"userEmail",type:"text",placeholder:"User Email"}),l||!a?s.default.createElement("button",{className:"btn btn-primary mt-2 action-btn",type:"submit"},"Submit"):s.default.createElement("button",{className:"btn btn-danger mt-2 action-btn",type:"button",onClick:function(){o(!0)}},"Are you sure? This cannot be undone")))}};return{AdminPanelPage:function(e){var t=e.userSignedIp,a=e.isAdminLoggedIn,n=e.action,r=e.actions,l=void 0===r?d:r,o=e.dialog,i=e.pageName,u=g(void 0===i?"":i).setProps,v=n?y[n.id]:null;a&&(l=m);var b=s.default.createElement("div",{className:"btn-group"},s.default.createElement("button",{className:"btn btn-transparent btn-lg dropdown-toggle action-dropdown",type:"button",id:"main-dropdown","data-bs-toggle":"dropdown","aria-expanded":"false"},n?n.displayName:"Select action"),s.default.createElement("ul",{className:"dropdown-menu","aria-labelledby":"main-dropdown"},l.map((function(t){var a=t.id,n=t.displayName;return s.default.createElement("li",{key:a},s.default.createElement("a",{className:"dropdown-item",href:"#",onClick:function(){return function(t){u(c(c({},e),{action:t,dialog:void 0}))}(t)}},n))}))));return s.default.createElement(s.default.Fragment,null,s.default.createElement(f,null,o&&s.default.createElement(h,c({},e))),s.default.createElement(p,null,b,v&&s.default.createElement(v,c({},e)),t&&s.default.createElement("div",{className:"signed-ip"},"Your ID: ",t)))},ReactDOM:u.default}}(React,0,(function(){}),(function(){}),ReactDOM);`; +export const apikerPagesStatic = `var pages=function(e,t,a,n,l){"use strict";function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=r(e),o=r(a),i=r(n),u=r(l),c=function(){return c=Object.assign||function(e){for(var t,a=1,n=arguments.length;a

Email Reset

If you received this email, it means that you\\'ve used the Reset Password feature. If so, click the following link to proceed:

Reset User Email

If you have not initiated this request, please disregard this message. The link will expire in 5 minutes.

',verifyAccount:'

Verify Account

If you received this email, it means that you\\'ve created an account at {appName}. If so, click the following link to activate your account:

Activate account

If you have not initiated this request, please disregard this message. The link will expire in 5 minutes.

'},b=function(e){var t=e.onButtonClick,a=e.onChange,n=e.buttonLabel,l=e.value;return s.default.useEffect((function(){var e=function(){var e=document.querySelector("#input-group-1 input"),t=document.querySelector("#input-group-1 button"),a=parseFloat(t.offsetWidth);e.style.maxWidth="calc(100% - ".concat(a,"px - 15px)")};window.addEventListener("resize",e),e()}),[]),s.default.createElement("div",{className:"input-group mt-2",id:"input-group-1"},s.default.createElement("input",{className:"form-control form-control-lg",id:"userEmail",type:"email",placeholder:"User Email",onChange:a,value:l}),s.default.createElement("button",{className:"btn btn-outline-secondary",type:"button",onClick:t},n))},y={login:function(e){var t=e.isSetup,a=e.pageName,n=void 0===a?"":a,l=e.csrfToken,r=void 0===l?"":l,o=g(n).setProps;return s.default.createElement("div",{className:"action-wrapper"},t&&s.default.createElement("div",{className:"alert alert-primary mb-0",role:"alert"},"Welcome to Apiker! Please setup your account in order to manage your app."),s.default.createElement("form",{className:"login-form",onSubmit:function(){var t=new FormData;Array.from(document.querySelectorAll("input")).forEach((function(e){var a=e.getAttribute("id");t.append(a,e.value)})),fetch("/admp/login",{method:"post",body:t,headers:{"X-Apiker-Csrf":r}}).then((function(e){return e.json().then((function(t){return{status:e.status,body:t}}))})).then((function(t){var a=200===t.status,n=a?void 0:e.action,l=a?"Sucess! You can now select a new action":"Failure returned by the endpoint.";o(c(c({},e),{action:n,actions:m,dialog:{className:a?"alert-primary":"alert-danger",message:l}}))})).catch((function(t){o(c(c({},e),{dialog:{className:"alert-danger",message:null==t?void 0:t.message}}))}))}},s.default.createElement("input",{className:"form-control form-control-lg mt-2",id:"email",type:"email",placeholder:"Email"}),s.default.createElement("input",{className:"form-control form-control-lg mt-2",id:"password",type:"password",placeholder:"Password"}),s.default.createElement("button",{className:"btn btn-primary mt-2 action-btn",type:"submit"},t?"Setup User":"Submit")))},banUser:function(e){var t=e.pageName,a=void 0===t?"":t,n=e.csrfToken,l=void 0===n?"":n,r=g(a).setProps;return s.default.createElement("div",{className:"action-wrapper"},s.default.createElement("form",{className:"login-form",onSubmit:function(){var t=new FormData;Array.from(document.querySelectorAll("input")).forEach((function(e){var a=e.getAttribute("id");t.append(a,e.value)})),fetch("/admp/bans",{method:"post",body:t,headers:{"X-Apiker-Csrf":l}}).then((function(e){return e.json().then((function(t){return{status:e.status,body:t}}))})).then((function(t){var a=200===t.status,n=a?"Action performed successfully":"Failure returned by the endpoint.";r(c(c({},e),{dialog:{className:a?"alert-primary":"alert-danger",message:n}}))})).catch((function(t){r(c(c({},e),{dialog:{className:"alert-danger",message:null==t?void 0:t.message}}))}))}},s.default.createElement("input",{className:"form-control form-control-lg mt-2",id:"userId",type:"text",placeholder:"User ID"}),s.default.createElement("button",{className:"btn btn-primary mt-2 action-btn",type:"submit"},"Submit")))},unbanUser:function(e){var t=e.pageName,a=void 0===t?"":t,n=e.csrfToken,l=void 0===n?"":n,r=g(a).setProps;return s.default.createElement("div",{className:"action-wrapper"},s.default.createElement("form",{className:"login-form",onSubmit:function(){var t=new FormData;Array.from(document.querySelectorAll("input")).forEach((function(e){var a=e.getAttribute("id");t.append(a,e.value)})),fetch("/admp/bans",{method:"delete",body:t,headers:{"X-Apiker-Csrf":l}}).then((function(e){return e.json().then((function(t){return{status:e.status,body:t}}))})).then((function(t){var a=200===t.status,n=a?"Action performed successfully":"Failure returned by the endpoint.";r(c(c({},e),{dialog:{className:a?"alert-primary":"alert-danger",message:n}}))})).catch((function(t){r(c(c({},e),{dialog:{className:"alert-danger",message:null==t?void 0:t.message}}))}))}},s.default.createElement("input",{className:"form-control form-control-lg mt-2",id:"userId",type:"text",placeholder:"User ID"}),s.default.createElement("button",{className:"btn btn-primary mt-2 action-btn",type:"submit"},"Submit")))},searchBans:function(e){var t=e.pageName,a=void 0===t?"":t,n=e.csrfToken,l=void 0===n?"":n,r=g(a).setProps,o=s.default.useState([]),i=o[0],u=o[1];return s.default.createElement("div",{className:"action-wrapper"},s.default.createElement("form",{className:"login-form",onSubmit:function(){var t={};Array.from(document.querySelectorAll("input")).forEach((function(e){var a=e.getAttribute("id");t[a]=e.value})),t.userId||r(c(c({},e),{dialog:{className:"alert-danger",message:"You must provide an user id"}})),fetch("/admp/bans/".concat(t.userId),{method:"get",headers:{"X-Apiker-Csrf":l}}).then((function(e){return e.json().then((function(t){return{status:e.status,body:t}}))})).then((function(t){var a=t.status,n=t.body,l=(void 0===n?{}:n).entries,s=200===a,o=(void 0===l?[]:l).map((function(e){return{time:e.time,id:e.id,clientId:e.clientId,countryCode:e.countryCode,pathname:e.pathname,issuedBy:e.issuedBy}})),i=s?"Action performed successfully":"Failure returned by the endpoint.";r(c(c({},e),{dialog:{className:s?"alert-primary":"alert-danger",message:i}})),u(o)})).catch((function(t){r(c(c({},e),{dialog:{className:"alert-danger",message:null==t?void 0:t.message}}))}))}},s.default.createElement("input",{className:"form-control form-control-lg mt-2",id:"userId",type:"text",placeholder:"User ID"}),s.default.createElement("button",{className:"btn btn-primary mt-2 action-btn",type:"submit"},"Submit")),i&&i.length?i.map((function(e){var t=e.time,a=e.id,n=e.clientId,l=e.countryCode,r=e.pathname,o=e.issuedBy;return s.default.createElement("div",{className:"results-container"},s.default.createElement("div",{className:"results-item"},s.default.createElement("ul",null,s.default.createElement("li",null,s.default.createElement("span",{className:"title"},"time")," ",s.default.createElement("span",{className:"text",title:new Date(t).toLocaleString()},new Date(t).toLocaleString())),s.default.createElement("li",null,s.default.createElement("span",{className:"title"},"id")," ",s.default.createElement("span",{className:"text",title:a},a)),s.default.createElement("li",null,s.default.createElement("span",{className:"title"},"clientId")," ",s.default.createElement("span",{className:"text",title:n},n)),s.default.createElement("li",null,s.default.createElement("span",{className:"title"},"countryCode")," ",s.default.createElement("span",{className:"text",title:l},l)),s.default.createElement("li",null,s.default.createElement("span",{className:"title"},"pathname")," ",s.default.createElement("span",{className:"text",title:r},r)),s.default.createElement("li",null,s.default.createElement("span",{className:"title"},"issuedBy")," ",s.default.createElement("span",{className:"text",title:o},o)))))})):null)},listLogs:function(e){var t=e.pageName,a=void 0===t?"":t,n=e.csrfToken,l=void 0===n?"":n,r=g(a).setProps,o=s.default.useState([]),i=o[0],u=o[1];return s.default.createElement("div",{className:"action-wrapper"},s.default.createElement("form",{className:"login-form",onSubmit:function(){var t={};Array.from(document.querySelectorAll("input")).forEach((function(e){var a=e.getAttribute("id");t[a]=e.value})),t.logId||r(c(c({},e),{dialog:{className:"alert-danger",message:"You must provide a log id"}})),fetch("/admp/logs?logId=".concat(t.logId),{method:"get",headers:{"X-Apiker-Csrf":l}}).then((function(e){return e.json().then((function(t){return{status:e.status,body:t}}))})).then((function(t){var a=t.status,n=t.body,l=(void 0===n?{}:n).entries,s=void 0===l?[]:l,o=200===a,i=o?"Action performed successfully":"Failure returned by the endpoint.";r(c(c({},e),{dialog:{className:o?"alert-primary":"alert-danger",message:i}})),u(s)})).catch((function(t){r(c(c({},e),{dialog:{className:"alert-danger",message:null==t?void 0:t.message}}))}))}},s.default.createElement("input",{className:"form-control form-control-lg mt-2",id:"logId",type:"text",placeholder:"Log ID"}),s.default.createElement("button",{className:"btn btn-primary mt-2 action-btn",type:"submit"},"Submit")),i&&i.length?i.map((function(e){return s.default.createElement("div",{className:"results-container"},s.default.createElement("div",{className:"results-item"},s.default.createElement("ul",null,Object.keys(e).map((function(t){return s.default.createElement("li",null,s.default.createElement("span",{className:"title"},t)," ",s.default.createElement("span",{className:"text",title:"time"===t?new Date(e[t]).toLocaleString():e[t]},"time"===t?new Date(e[t]).toLocaleString():e[t]))})))))})):null)},sendEmail:function(e){var t=s.default.useState(),a=t[0],n=t[1],l=e.pageName,r=void 0===l?"":l,o=e.csrfToken,i=void 0===o?"":o,u=g(r).setProps,d=s.default.createElement("div",{className:"btn-group mt-2"},s.default.createElement("button",{className:"btn btn-transparent btn-lg dropdown-toggle action-dropdown",type:"button",id:"main-dropdown","data-bs-toggle":"dropdown","aria-expanded":"false"},a||"Email template"),s.default.createElement("ul",{className:"dropdown-menu","aria-labelledby":"main-dropdown"},Object.keys(h).map((function(e){return s.default.createElement("li",{key:e},s.default.createElement("a",{className:"dropdown-item",href:"#",onClick:function(){n(e)}},e))}))));return s.default.createElement("div",{className:"action-wrapper"},s.default.createElement("div",{className:"alert alert-warning mb-0 mt-2",role:"alert"},s.default.createElement("b",null,"Note:"),' This option requires the "email" and "authRoutes" options to be enabled.'),s.default.createElement("form",{className:"login-form",onSubmit:function(){var t=new FormData;a&&(Array.from(document.querySelectorAll("input")).forEach((function(e){var a=e.getAttribute("id");t.append(a,e.value)})),t.append("template",a),fetch("/admp/email",{method:"post",body:t,headers:{"X-Apiker-Csrf":i}}).then((function(e){return e.json().then((function(t){return{status:e.status,body:t}}))})).then((function(t){var a=t.status,n=200===a||201===a,l=n?"Action performed successfully":"Failure returned by the endpoint.";u(c(c({},e),{dialog:{className:n?"alert-primary":"alert-danger",message:l}}))})).catch((function(t){u(c(c({},e),{dialog:{className:"alert-danger",message:null==t?void 0:t.message}}))})))}},s.default.createElement("input",{className:"form-control form-control-lg mt-2",id:"userEmail",type:"email",placeholder:"User Email"}),d,a?s.default.createElement("pre",{className:"m-0 mt-2"},s.default.createElement("code",null,h[a])):null,s.default.createElement("button",{className:"btn btn-primary mt-2 action-btn",type:"submit"},"Submit")))},updateUser:function(e){var t=s.default.useRef(""),a=s.default.useState(""),n=a[0],l=a[1],r=s.default.useState(""),o=r[0],i=r[1],u=e.pageName,d=void 0===u?"":u,m=e.csrfToken,f=void 0===m?"":m,p=g(d).setProps,v=function(e,t){var a;try{a=JSON.parse(e)}catch(e){}if(a){var n=JSON.stringify(a);l(n),t&&t(n)}};return console.log("partialUser",n),s.default.createElement("div",{className:"action-wrapper"},s.default.createElement("form",{className:"login-form",onSubmit:function(){if(o.trim())if(t.current&&n&&t.current!==n){var a=new FormData;Array.from(document.querySelectorAll("input")).forEach((function(e){var t=e.getAttribute("id");a.append(t,e.value)})),a.append("updatedUser",n),fetch("/admp/user",{method:"put",body:a,headers:{"X-Apiker-Csrf":f}}).then((function(e){return e.json().then((function(t){return{status:e.status,body:t}}))})).then((function(t){var a=200===t.status,n=a?"Action performed successfully":"Failure returned by the endpoint.";p(c(c({},e),{dialog:{className:a?"alert-primary":"alert-danger",message:n}}))})).catch((function(t){p(c(c({},e),{dialog:{className:"alert-danger",message:null==t?void 0:t.message}}))}))}else p(c(c({},e),{dialog:{className:"alert-danger",message:"Please fill out the fields correctly"}}));else p(c(c({},e),{dialog:{className:"alert-danger",message:"You must provide the user email"}}))}},s.default.createElement(b,{value:o,onButtonClick:function(){console.log("onUserEmailChange",o),fetch("/admp/user?"+new URLSearchParams({userEmail:o}),{method:"get",headers:{"X-Apiker-Csrf":f}}).then((function(e){return e.json().then((function(t){return{status:e.status,body:t}}))})).then((function(a){var n=a.status,l=a.body,r=(void 0===l?{}:l).partialUser;if(200===n)if(r){var s=JSON.stringify(r);v(s,(function(e){t.current=e})),p(c(c({},e),{dialog:{className:"alert-primary",message:"Action performed successfully"}}))}else p(c(c({},e),{dialog:{className:"alert-danger",message:"Endpoint error"}}));else p(c(c({},e),{dialog:{className:"alert-danger",message:"User not found!"}}));console.log(a)})).catch((function(e){console.log(e)}))},onChange:function(e){return i(e.target.value)},buttonLabel:"Find"}),n?s.default.createElement("textarea",{className:"m-0 mt-2",onChange:function(e){return v(e.target.value)},value:JSON.stringify(JSON.parse(n),null,2)}):null,s.default.createElement("button",{className:"btn btn-primary mt-2 action-btn",type:"submit"},"Submit")))},deleteUser:function(e){var t=s.default.useState(!1),a=t[0],n=t[1],l=s.default.useState(!1),r=l[0],o=l[1],i=e.pageName,u=void 0===i?"":i,d=e.csrfToken,m=void 0===d?"":d,f=g(u).setProps;return s.default.createElement("div",{className:"action-wrapper"},s.default.createElement("form",{className:"login-form",onSubmit:function(){var t;if((null===(t=document.getElementById("userEmail"))||void 0===t?void 0:t.value).trim())if(a&&r){var l=new FormData;Array.from(document.querySelectorAll("input")).forEach((function(e){var t=e.getAttribute("id");l.append(t,e.value)})),fetch("/admp/user",{method:"delete",body:l,headers:{"X-Apiker-Csrf":m}}).then((function(e){return e.json().then((function(t){return{status:e.status,body:t}}))})).then((function(t){var a=200===t.status,n=a?"Action performed successfully":"Failure returned by the endpoint.";f(c(c({},e),{dialog:{className:a?"alert-primary":"alert-danger",message:n}}))})).catch((function(t){f(c(c({},e),{dialog:{className:"alert-danger",message:null==t?void 0:t.message}}))}))}else n(!0);else f(c(c({},e),{dialog:{className:"alert-danger",message:"You must provide the user email"}}))}},s.default.createElement("input",{className:"form-control form-control-lg mt-2",id:"userEmail",type:"text",placeholder:"User Email"}),r||!a?s.default.createElement("button",{className:"btn btn-primary mt-2 action-btn",type:"submit"},"Submit"):s.default.createElement("button",{className:"btn btn-danger mt-2 action-btn",type:"button",onClick:function(){o(!0)}},"Are you sure? This cannot be undone")))}};return{AdminPanelPage:function(e){var t=e.userSignedIp,a=e.isAdminLoggedIn,n=e.action,l=e.actions,r=void 0===l?d:l,o=e.dialog,i=e.pageName,u=g(void 0===i?"":i).setProps,h=n?y[n.id]:null;r=a?m:d;var b=s.default.createElement("div",{className:"btn-group"},s.default.createElement("button",{className:"btn btn-transparent btn-lg dropdown-toggle action-dropdown",type:"button",id:"main-dropdown","data-bs-toggle":"dropdown","aria-expanded":"false"},n?n.displayName:"Select action"),s.default.createElement("ul",{className:"dropdown-menu","aria-labelledby":"main-dropdown"},r.map((function(t){var a=t.id,n=t.displayName;return s.default.createElement("li",{key:a},s.default.createElement("a",{className:"dropdown-item",href:"#",onClick:function(){return function(t){u(c(c({},e),{action:t,dialog:void 0}))}(t)}},n))}))));return s.default.createElement(s.default.Fragment,null,s.default.createElement(f,null,o&&s.default.createElement(v,c({},e))),s.default.createElement(p,null,b,h&&s.default.createElement(h,c({},e)),t&&s.default.createElement("div",{className:"signed-ip"},"Your ID: ",t)))},ReactDOM:u.default}}(React,0,(function(){}),(function(){}),ReactDOM);`;