"use strict";(()=>{var e={};e.id=9419,e.ids=[9419],e.modules={30671:(e,t)=>{Object.defineProperty(t,"M",{enumerable:!0,get:function(){return function e(t,a){return a in t?t[a]:"then"in t&&"function"==typeof t.then?t.then(t=>e(t,a)):"function"==typeof t&&"default"===a?t:void 0}}})},50665:(e,t,a)=>{a.r(t),a.d(t,{config:()=>R,default:()=>C,getServerSideProps:()=>T,getStaticPaths:()=>M,getStaticProps:()=>O,reportWebVitals:()=>K,routeModule:()=>H,unstable_getServerProps:()=>F,unstable_getServerSideProps:()=>I,unstable_getStaticParams:()=>Q,unstable_getStaticPaths:()=>q,unstable_getStaticProps:()=>B});var s,r={};a.r(r),a.d(r,{ApiKeysContext:()=>P,default:()=>L,getServerSideProps:()=>E});var l=a(63865),n=a(9455),i=a(30671),c=a(5583),o=a(19796),d=a(8732),p=a(82015),u=a.n(p),h=a(25562),m=a(92702),y=a(53926),x=a(66485),f=a(91140),g=a(46169),_=a(16757),v=a(55904);function A({apiKeyObject:e,setTargetApiKey:t}){let[a,s]=u().useState(!1);return(0,d.jsxs)("div",{className:"card no-hover justify-between items-center"+(e.scope.match(/fullAccess/)?" green":""),onClick:a=>{a.target?.closest("button")||(t(e),(0,f.PB)("target-media-popup"))},children:[a&&(0,d.jsx)(_.A,{width:"20px"}),(0,d.jsxs)("div",{className:"text-sm flex-wrap",children:[(0,d.jsx)("div",{children:e.scope.match(/readOnly/)?(0,d.jsx)("span",{className:"notification"}):e.scope.match(/fullAccess/)?(0,d.jsx)("span",{className:"notification success"}):"No Scope"}),(0,d.jsx)("span",{className:"title text-xl",style:{fontSize:"16px"},children:e.name}),(0,d.jsxs)("span",{className:"text-slate-400 ",children:["Created: ",e.date_created.substring(0,24)]})]}),(0,d.jsxs)(v.A,{children:[(0,d.jsx)("button",{className:"outlined light-gray small-text",onClick:t=>{alert(e.apiKeyPayload)},children:"Reveal Api Key"}),(0,d.jsx)("button",{className:"outlined light-gray small-text",onClick:t=>{navigator.clipboard.writeText(e.apiKeyPayload).then(()=>{alert("Api Key Copied To Clipboard")})},children:"Copy Api Key"}),(0,d.jsx)("button",{className:"outlined light-gray small-text"+(a?" pointer-events-none opacity-40":""),onClick:t=>{s(!0),window.confirm("Delete this Api Key?")?(0,g.A)("/api/deleteApiKey",{method:"post",body:e},!0).then(e=>{}).finally(()=>{window.location.reload()}):s(!1)},children:"Delete Api Key"})]})]})}function j({user:e,apiKeys:t,setTargetApiKey:a}){return(0,d.jsx)(u().Fragment,{children:(0,d.jsxs)("section",{className:"p-0 items-start gap-4 overflow-visible bg-transparent border-transparent",children:[(0,d.jsx)("div",{className:"w-full flex-col items-stretch gap-4",children:t&&a&&t[0]&&t.map((e,t)=>(0,d.jsx)(A,{apiKeyObject:e,setTargetApiKey:a},t))}),!t||!t[0]&&(0,d.jsxs)("div",{className:"button outlined gray dashed w-full p-10 flex-col",onClick:e=>{(0,f.PB)("add-new-api-key-popup")},children:[(0,d.jsx)("span",{className:"text-slate-400",children:"No Api Keys Added."}),(0,d.jsx)("span",{className:"",children:"Add Api Key"})]})]})})}function S(){let{user:e,apiKeys:t,setApiKeys:a,setTargetApiKey:s}=u().useContext(P);return(0,d.jsxs)(u().Fragment,{children:[(0,d.jsxs)("div",{className:"flex-col items-start gap-0 w-full",children:[(0,d.jsxs)("div",{className:"w-full justify-between flex-wrap",children:[(0,d.jsx)("h1",{className:"text-3xl m-0",children:"Api Keys"}),(0,d.jsxs)("button",{className:"flex items-center gap-2",onClick:e=>{(0,f.PB)("add-new-api-key-popup")},children:[(0,d.jsx)("span",{className:"symbol",children:"+"}),(0,d.jsx)("span",{children:"Add New Api Key"})]})]}),(0,d.jsx)(y.A,{user:e})]}),e?.verification_status?.toString().match(/1/)?(0,d.jsx)(j,{apiKeys:t,setTargetApiKey:s,user:e}):(0,d.jsx)(x.A,{})]})}function b({targetApiKey:e}){let[t,a]=u().useState(!1);return(0,d.jsxs)(f.Ay,{title:"target-api-key-preview-popup",noContainer:!0,fullPage:!0,children:[t&&(0,d.jsx)(_.A,{}),e&&(0,d.jsx)(u().Fragment,{children:(0,d.jsx)("span",{children:"Target Api Key"})})]})}var N=a(24872);function k(){async function e(e){return await (0,N.A)({tableName:"api_keys",columnName:"slug",value:e})}let[t,a]=u().useState(!1),[r,l]=u().useState(null);return(0,d.jsxs)(f.Ay,{title:"add-new-api-key-popup",children:[t&&(0,d.jsx)(_.A,{}),(0,d.jsx)("h4",{className:"m-0",children:"Add New Api Key"}),(0,d.jsxs)("form",{className:"w-full flex flex-col items-stretch gap-2",onSubmit:e=>{e.preventDefault(),a(!0);let t=e.target,s={api_key_name:t.api_key_name.value,api_key_slug:t.api_key_slug.value,api_key_scope:t.api_key_scope.value,target_database:t.target_database?.value||void 0,target_table:t.target_table?.value||void 0};(0,g.A)("/api/addApiKey",{method:"post",body:s},!0).then(e=>{e.success?window.location.reload():setTimeout(()=>{a(!1)},2e3)})},children:[r&&(0,d.jsx)("div",{children:(0,d.jsx)("span",{children:r})}),(0,d.jsxs)("div",{className:"flex flex-col items-start gap-0.5 w-full",children:[(0,d.jsx)("label",{htmlFor:"api_key_name",children:"Api Key Name"}),(0,d.jsx)("input",{type:"text",name:"api_key_name",id:"api_key_name",placeholder:"Api Key Name",onInput:e=>{let t=e.target;t&&(t.closest("form").api_key_slug.value=t.value.toLowerCase().replace(/ /g,"_").replace(/[^a-zA-Z0-9-_]/g,""))},required:!0})]}),(0,d.jsxs)("div",{className:"flex flex-col items-start gap-0.5 w-full",children:[(0,d.jsx)("label",{htmlFor:"api_key_slug",children:"Api Key Slug"}),(0,d.jsx)("input",{type:"text",name:"api_key_slug",id:"api_key_slug",placeholder:"Api Key Slug",onInput:t=>{let a=t.target;a?.value.match(/./)?(a?.classList.remove("warning"),l(null)):a?.classList.add("warning"),window.clearTimeout(s),s=setTimeout(()=>{e(a.value).then(e=>{e.result?(a?.classList.add("warning"),l("Duplicate Table Name")):(a?.classList.remove("warning"),l(null))})},300)},required:!0})]}),(0,d.jsxs)("div",{className:"flex flex-col items-start gap-0.5 w-full",children:[(0,d.jsxs)("div",{className:"",children:[(0,d.jsx)("label",{htmlFor:"api_key_scope",children:"Api Scope"}),(0,d.jsxs)("div",{className:"dropdown-wrapper reversed",children:[(0,d.jsx)("span",{className:"px-2 py-1 bg-slate-100 rounded-full text-xs font-semibold",children:"Info"}),(0,d.jsx)("div",{className:"dropdown always left-aligned -ml-10 -mb-2",style:{minWidth:"300px"},children:(0,d.jsxs)("div",{className:"flex-col items-start gap-2 text-sm leading-snug",children:[(0,d.jsx)("span",{children:"Scope is the range of access the API Key can have"}),(0,d.jsxs)("ul",{className:"ml-0 pl-4 flex flex-col gap-2",children:[(0,d.jsx)("li",{children:(0,d.jsxs)("span",{children:[(0,d.jsx)("b",{children:"Read Only:"})," Can only read from databases"]})}),(0,d.jsx)("li",{children:(0,d.jsxs)("span",{children:[(0,d.jsx)("b",{children:"Full Access:"})," Can read and Write to databases"]})})]})]})})]})]}),(0,d.jsxs)("select",{name:"api_key_scope",id:"api_key_scope",children:[(0,d.jsx)("option",{value:"readOnly",children:"Read Only"}),(0,d.jsx)("option",{value:"fullAccess",children:"Full Access"})]})]}),(0,d.jsxs)("div",{className:"flex flex-col items-start gap-0.5 w-full",children:[(0,d.jsx)("label",{htmlFor:"target_database",children:"Target Databases"}),(0,d.jsx)("input",{type:"text",name:"target_database",id:"target_database",placeholder:"Target Databases (optional). Comma Separated"})]}),(0,d.jsxs)("div",{className:"flex flex-col items-start gap-0.5 w-full",children:[(0,d.jsx)("label",{htmlFor:"target_table",children:"Target Tables"}),(0,d.jsx)("input",{type:"text",name:"target_table",id:"target_table",placeholder:"Target Tables (optional). Comma Separated"})]}),(0,d.jsx)("button",{type:"submit",className:t?" pointer-events-none opacity-40":"",children:"Create New Api Key"})]})]})}var D=a(71934),w=a(71205);let P=u().createContext({});function L({user:e,fetchedApiKeys:t}){let a=(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("title",{children:"Api Keys | Datasquirel"}),(0,d.jsx)("meta",{name:"description",content:"Welcome to your data app"})]}),[s,r]=u().useState(t),[l,n]=u().useState(null),[i,c]=u().useState(null);return(0,d.jsx)(P.Provider,{value:{user:e,apiKeys:s,setApiKeys:r,targetApiKey:i,setTargetApiKey:c,newApiKey:l,setNewApiKey:n},children:(0,d.jsxs)(u().Fragment,{children:[(0,d.jsx)(h.A,{head:a,user:e,children:(0,d.jsx)(S,{})}),i&&(0,d.jsx)(b,{targetApiKey:i}),(0,d.jsx)(k,{})]})})}async function E({req:e,res:t,query:a}){let s=await (0,m.A)(e,t);if(!s?.logged_in_status)return{redirect:{destination:"/logout",permanent:!1}};let r=await (0,D.A)(`SELECT * FROM api_keys WHERE user_id='${s.id}'`),l=[];if(r&&r[0])for(let e=0;e{a.d(t,{Ay:()=>i,PB:()=>c,fs:()=>o});var s=a(8732),r=a(58150),l=a(82015),n=a.n(l);function i({children:e,title:t,data:a,fullPage:l,wrapperClasses:i,closePopupDispatch:c,wrapperStyle:d,noContainer:p}){return l?(0,s.jsxs)("div",{className:"popup-bg overflow-hidden "+(i||""),"data-popupid":t||null,style:d,children:[p?(0,s.jsx)(n().Fragment,{children:e}):(0,s.jsx)("div",{className:"relative w-full h-full z-50","data-data":a?JSON.stringify(a):"",children:e}),(0,s.jsx)("button",{className:"popup-cancel-button fixed outlined gray",onClick:e=>{o(),c&&c()},children:(0,s.jsx)(r.A,{color:"white",size:20})}),(0,s.jsx)("div",{className:"popup-canceller",onClick:e=>{o(),c&&c()}})]}):(0,s.jsxs)("div",{className:"popup-bg","data-popupid":t||null,children:[p?(0,s.jsx)(n().Fragment,{children:e}):(0,s.jsxs)("div",{className:"popup-content-container minimal-scrollbars","data-data":a?JSON.stringify(a):"",children:[e,(0,s.jsx)("button",{className:"outlined gray popup-cancel-button",onClick:e=>{o(),c&&c()},children:(0,s.jsx)("span",{className:"font-normal",children:"✖"})})]}),p&&(0,s.jsx)("button",{className:"gray popup-cancel-button",onClick:e=>{o(),c&&c()},children:(0,s.jsx)("span",{className:"font-normal",children:"✖"})}),(0,s.jsx)("div",{className:"popup-canceller",onClick:e=>{o(),c&&c()}})]})}function c(e,t){let a=document.querySelector(`[data-popupid='${e}']`);a&&(a.style.display="flex",t?.(a))}function o(e){document.querySelectorAll("[data-popupid]").forEach(e=>{e.style.display="none"}),e?.()}},66485:(e,t,a)=>{a.d(t,{A:()=>r});var s=a(8732);function r(){return(0,s.jsxs)("a",{href:"/email-verification",className:"card w-full items-center justify-center py-4 gap-2",children:[(0,s.jsx)("img",{src:"/images/warning.png",alt:"Down Arrow",width:25,className:""}),(0,s.jsx)("span",{children:"Your Account is not verified. Please verify your account."})]})}a(82015)},55904:(e,t,a)=>{a.d(t,{A:()=>n});var s=a(8732),r=a(82015),l=a.n(r);function n({children:e,column:t,className:a}){let r=l().useRef();return(0,s.jsx)("div",{className:"items-stretch gap-0"+(t?" flex-col":" flex-wrap xl:flex-nowrap")+(a?" "+a:""),ref:r,children:e})}},24872:(e,t,a)=>{a.d(t,{A:()=>r});var s=a(46169);async function r({tableName:e,columnName:t,value:a,dbFullName:r,dispatch:l,userId:n,dbId:i}){return await (0,s.A)(`/api/checkDuplicateData?tableName=${e}&type=${t}&value=${a}${r?"&dbFullName="+r:""}${n?"&userId="+n:""}${i?"&dbId="+i:""}`)}},23293:(e,t,a)=>{a.d(t,{A:()=>s});let s=(0,a(82544).A)("ArrowLeft",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]])},92441:(e,t,a)=>{a.d(t,{A:()=>s});let s=(0,a(82544).A)("BookText",[["path",{d:"M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H20v20H6.5a2.5 2.5 0 0 1 0-5H20",key:"t4utmx"}],["path",{d:"M8 7h6",key:"1f0q6e"}],["path",{d:"M8 11h8",key:"vwpz6n"}]])},34637:(e,t,a)=>{a.d(t,{A:()=>s});let s=(0,a(82544).A)("Database",[["ellipse",{cx:"12",cy:"5",rx:"9",ry:"3",key:"msslwz"}],["path",{d:"M3 5V19A9 3 0 0 0 21 19V5",key:"1wlel7"}],["path",{d:"M3 12A9 3 0 0 0 21 12",key:"mv7ke4"}]])},29743:(e,t,a)=>{a.d(t,{A:()=>s});let s=(0,a(82544).A)("FileKey2",[["path",{d:"M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v6",key:"rc0qvx"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["circle",{cx:"4",cy:"16",r:"2",key:"1ehqvc"}],["path",{d:"m10 10-4.5 4.5",key:"7fwrp6"}],["path",{d:"m9 11 1 1",key:"wa6s5q"}]])},10643:(e,t,a)=>{a.d(t,{A:()=>s});let s=(0,a(82544).A)("Globe",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20",key:"13o1zl"}],["path",{d:"M2 12h20",key:"9i4pu4"}]])},66916:(e,t,a)=>{a.d(t,{A:()=>s});let s=(0,a(82544).A)("HardDrive",[["line",{x1:"22",x2:"2",y1:"12",y2:"12",key:"1y58io"}],["path",{d:"M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"oot6mr"}],["line",{x1:"6",x2:"6.01",y1:"16",y2:"16",key:"sgf278"}],["line",{x1:"10",x2:"10.01",y1:"16",y2:"16",key:"1l4acy"}]])},83158:(e,t,a)=>{a.d(t,{A:()=>s});let s=(0,a(82544).A)("Images",[["path",{d:"M18 22H4a2 2 0 0 1-2-2V6",key:"pblm9e"}],["path",{d:"m22 13-1.296-1.296a2.41 2.41 0 0 0-3.408 0L11 18",key:"nf6bnh"}],["circle",{cx:"12",cy:"8",r:"2",key:"1822b1"}],["rect",{width:"16",height:"16",x:"6",y:"2",rx:"2",key:"12espp"}]])},66918:(e,t,a)=>{a.d(t,{A:()=>s});let s=(0,a(82544).A)("RotateCw",[["path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8",key:"1p45f6"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}]])},10321:(e,t,a)=>{a.d(t,{A:()=>s});let s=(0,a(82544).A)("ShieldEllipsis",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M8 12h.01",key:"czm47f"}],["path",{d:"M12 12h.01",key:"1mp3jc"}],["path",{d:"M16 12h.01",key:"1l6xoz"}]])},25294:(e,t,a)=>{a.d(t,{A:()=>s});let s=(0,a(82544).A)("Users",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["path",{d:"M22 21v-2a4 4 0 0 0-3-3.87",key:"kshegd"}],["path",{d:"M16 3.13a4 4 0 0 1 0 7.75",key:"1da9ce"}]])},58150:(e,t,a)=>{a.d(t,{A:()=>s});let s=(0,a(82544).A)("X",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]])},71205:(e,t,a)=>{a.d(t,{A:()=>n});var s=a(55511),r=a(79428),l=a(48243);function n({encryptedString:e,encryptionKey:t,encryptionSalt:a}){if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let{key:n,salt:i,keyLen:c,algorithm:o,bufferAllocSize:d}=(0,l.A)({encryptionKey:t});if(!n?.match(/.{8,}/))return console.log("Decrption key is invalid"),e;if(!i?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let p=(0,s.scryptSync)(n,i,c),u=r.Buffer.alloc(d,0),h=(0,s.createDecipheriv)(o,p,u);try{let t=h.update(e,"hex","utf8");return t+=h.final("utf8")}catch(t){return console.log("Error in decrypting =>",t.message),e}}},71934:(e,t,a)=>{a.d(t,{A:()=>r});var s=a(51779);async function r(...e){let t=(0,s.A)();try{if(!t)throw Error("No Connection provided to DB_HANDLER function!");let a=await t.query(...e);return JSON.parse(JSON.stringify(a))}catch(e){return console.log("DB Error =>",e),{success:!1,error:e.message}}finally{await t?.end()}}},51779:(e,t,a)=>{a.d(t,{A:()=>l});var s=a(9973),r=a.n(s);function l(e){return e?.ro?DSQL_READ_ONLY_DB_CONN||r()({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_READ_ONLY_USERNAME,password:process.env.DSQL_DB_READ_ONLY_PASSWORD,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4"}}):e?.fa?global.DSQL_FULL_ACCESS_DB_CONN||r()({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_FULL_ACCESS_USERNAME,password:process.env.DSQL_DB_FULL_ACCESS_PASSWORD,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4"}}):global.DSQL_DB_CONN||r()({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_USERNAME,password:process.env.DSQL_DB_PASSWORD,database:e?.noDb?void 0:process.env.DSQL_DB_NAME,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4"}})}},48243:(e,t,a)=>{a.d(t,{A:()=>s});function s(e){return{key:e?.encryptionKey||process.env.DSQL_ENCRYPTION_PASSWORD,keyLen:process.env.DSQL_ENCRYPTION_KEY_LENGTH?Number(process.env.DSQL_ENCRYPTION_KEY_LENGTH):24,salt:e?.encryptionSalt||process.env.DSQL_ENCRYPTION_SALT,apiKey:e?.apiKey||process.env.DSQL_API_KEY,algorithm:e?.algorithm||process.env.DSQL_ENCRYPTION_ALGORITHM||"aes-192-cbc",bufferAllocSize:e?.bufferAllocSize||(process.env.DSQL_ENCRYPTION_BUFFER_ALLOCATION_SIZE?function(e,t){try{let t=Number(e);if("number"!=typeof t||isNaN(t))return 0;return Math.round(t)}catch(e){return console.log(`Numberfy ERROR: ${e.message}`),0}}(process.env.DSQL_ENCRYPTION_BUFFER_ALLOCATION_SIZE):void 0)||16}}},9455:(e,t)=>{Object.defineProperty(t,"A",{enumerable:!0,get:function(){return a}});var a=function(e){return e.PAGES="PAGES",e.PAGES_API="PAGES_API",e.APP_PAGE="APP_PAGE",e.APP_ROUTE="APP_ROUTE",e.IMAGE="IMAGE",e}({})},13893:e=>{e.exports=require("@moduletrace/datasquirel/dist/client/fetch")},39908:e=>{e.exports=require("@moduletrace/datasquirel/dist/users/user-auth")},40361:e=>{e.exports=require("next/dist/compiled/next-server/pages.runtime.prod.js")},27912:e=>{e.exports=require("next/head")},82015:e=>{e.exports=require("react")},22326:e=>{e.exports=require("react-dom")},8732:e=>{e.exports=require("react/jsx-runtime")},9973:e=>{e.exports=require("serverless-mysql")},79428:e=>{e.exports=require("buffer")},55511:e=>{e.exports=require("crypto")},33873:e=>{e.exports=require("path")}};var t=require("../../../webpack-runtime.js");t.C(e);var a=e=>t(t.s=e),s=t.X(0,[883,9821,9796,5392],()=>a(50665));module.exports=s})();