From 7b0ca40c4fdcaac8a125d1256d96953598340151 Mon Sep 17 00:00:00 2001 From: Roberto Guagliardo Date: Sun, 1 Feb 2026 02:20:28 +0000 Subject: [PATCH] feat: implement user authentication and license management system - Added schema for users, licenses, and license hostnames in the database. - Created storage utility for reading and writing JSON files. - Developed user service for user registration, authentication, and retrieval. - Implemented authentication middleware to protect routes. - Built LicenseCard component to display license details. - Created SiteNav component for navigation with user authentication status. - Established AuthContext for managing authentication state and actions. - Developed Home page to display available plugins. - Created LicenseManager page for managing licenses with forms for creation and verification. - Implemented PluginDetail page to show detailed information about a specific plugin. - Added utility functions for date formatting. --- .env.example | 10 + dist/assets/index-BlY_enN1.js | 68 +++++ dist/assets/index-CgskK80a.css | 1 + dist/index.html | 16 ++ docker-compose.yml | 13 +- package-lock.json | 216 +++++++++++++++ package.json | 5 +- server/index.js | 358 +++++++++++-------------- server/lib/cache.js | 21 ++ server/lib/config.js | 29 ++ server/lib/db.js | 11 + server/lib/licenseService.js | 192 +++++++++++++ server/lib/pluginService.js | 204 ++++++++++++++ server/lib/schema.js | 57 ++++ server/lib/storage.js | 19 ++ server/lib/userService.js | 69 +++++ server/middleware/auth.js | 23 ++ src/App.css | 305 ++++++++++++++++++++- src/App.jsx | 217 +-------------- src/components/LicenseCard.jsx | 65 +++++ src/components/SiteNav.jsx | 29 ++ src/context/AuthContext.jsx | 140 ++++++++++ src/main.jsx | 5 +- src/pages/Home.jsx | 89 ++++++ src/pages/LicenseManager.jsx | 476 +++++++++++++++++++++++++++++++++ src/pages/PluginDetail.jsx | 125 +++++++++ src/utils/dates.js | 9 + 27 files changed, 2344 insertions(+), 428 deletions(-) create mode 100644 .env.example create mode 100644 dist/assets/index-BlY_enN1.js create mode 100644 dist/assets/index-CgskK80a.css create mode 100644 dist/index.html create mode 100644 server/lib/cache.js create mode 100644 server/lib/config.js create mode 100644 server/lib/db.js create mode 100644 server/lib/licenseService.js create mode 100644 server/lib/pluginService.js create mode 100644 server/lib/schema.js create mode 100644 server/lib/storage.js create mode 100644 server/lib/userService.js create mode 100644 server/middleware/auth.js create mode 100644 src/components/LicenseCard.jsx create mode 100644 src/components/SiteNav.jsx create mode 100644 src/context/AuthContext.jsx create mode 100644 src/pages/Home.jsx create mode 100644 src/pages/LicenseManager.jsx create mode 100644 src/pages/PluginDetail.jsx create mode 100644 src/utils/dates.js diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..aeb914b --- /dev/null +++ b/.env.example @@ -0,0 +1,10 @@ +# MariaDB / MySQL connection +DB_HOST=127.0.0.1 +DB_PORT=3306 +DB_USER=root +DB_PASSWORD=secret +DB_NAME=siti_plugin_repo + +# Authentication +JWT_SECRET=please-change-me +JWT_EXPIRES_IN=7d diff --git a/dist/assets/index-BlY_enN1.js b/dist/assets/index-BlY_enN1.js new file mode 100644 index 0000000..eb7d9af --- /dev/null +++ b/dist/assets/index-BlY_enN1.js @@ -0,0 +1,68 @@ +function ff(e,t){for(var n=0;nr[l]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const l of document.querySelectorAll('link[rel="modulepreload"]'))r(l);new MutationObserver(l=>{for(const i of l)if(i.type==="childList")for(const o of i.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&r(o)}).observe(document,{childList:!0,subtree:!0});function n(l){const i={};return l.integrity&&(i.integrity=l.integrity),l.referrerPolicy&&(i.referrerPolicy=l.referrerPolicy),l.crossOrigin==="use-credentials"?i.credentials="include":l.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function r(l){if(l.ep)return;l.ep=!0;const i=n(l);fetch(l.href,i)}})();function df(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Os={exports:{}},jl={},Is={exports:{}},I={};/** + * @license React + * react.production.min.js + * + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */var mr=Symbol.for("react.element"),pf=Symbol.for("react.portal"),hf=Symbol.for("react.fragment"),mf=Symbol.for("react.strict_mode"),vf=Symbol.for("react.profiler"),gf=Symbol.for("react.provider"),yf=Symbol.for("react.context"),wf=Symbol.for("react.forward_ref"),Sf=Symbol.for("react.suspense"),kf=Symbol.for("react.memo"),xf=Symbol.for("react.lazy"),hu=Symbol.iterator;function Ef(e){return e===null||typeof e!="object"?null:(e=hu&&e[hu]||e["@@iterator"],typeof e=="function"?e:null)}var Ms={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},Ds=Object.assign,Fs={};function kn(e,t,n){this.props=e,this.context=t,this.refs=Fs,this.updater=n||Ms}kn.prototype.isReactComponent={};kn.prototype.setState=function(e,t){if(typeof e!="object"&&typeof e!="function"&&e!=null)throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,e,t,"setState")};kn.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function Us(){}Us.prototype=kn.prototype;function go(e,t,n){this.props=e,this.context=t,this.refs=Fs,this.updater=n||Ms}var yo=go.prototype=new Us;yo.constructor=go;Ds(yo,kn.prototype);yo.isPureReactComponent=!0;var mu=Array.isArray,As=Object.prototype.hasOwnProperty,wo={current:null},Bs={key:!0,ref:!0,__self:!0,__source:!0};function Vs(e,t,n){var r,l={},i=null,o=null;if(t!=null)for(r in t.ref!==void 0&&(o=t.ref),t.key!==void 0&&(i=""+t.key),t)As.call(t,r)&&!Bs.hasOwnProperty(r)&&(l[r]=t[r]);var s=arguments.length-2;if(s===1)l.children=n;else if(1>>1,U=N[D];if(0>>1;Dl(Pn,O))Gel(Kt,Pn)?(N[D]=Kt,N[Ge]=O,D=Ge):(N[D]=Pn,N[Xe]=O,D=Xe);else if(Gel(Kt,O))N[D]=Kt,N[Ge]=O,D=Ge;else break e}}return z}function l(N,z){var O=N.sortIndex-z.sortIndex;return O!==0?O:N.id-z.id}if(typeof performance=="object"&&typeof performance.now=="function"){var i=performance;e.unstable_now=function(){return i.now()}}else{var o=Date,s=o.now();e.unstable_now=function(){return o.now()-s}}var u=[],a=[],m=1,h=null,v=3,w=!1,g=!1,y=!1,x=typeof setTimeout=="function"?setTimeout:null,d=typeof clearTimeout=="function"?clearTimeout:null,c=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function p(N){for(var z=n(a);z!==null;){if(z.callback===null)r(a);else if(z.startTime<=N)r(a),z.sortIndex=z.expirationTime,t(u,z);else break;z=n(a)}}function k(N){if(y=!1,p(N),!g)if(n(u)!==null)g=!0,Tt(C);else{var z=n(a);z!==null&&jn(k,z.startTime-N)}}function C(N,z){g=!1,y&&(y=!1,d(L),L=-1),w=!0;var O=v;try{for(p(z),h=n(u);h!==null&&(!(h.expirationTime>z)||N&&!G());){var D=h.callback;if(typeof D=="function"){h.callback=null,v=h.priorityLevel;var U=D(h.expirationTime<=z);z=e.unstable_now(),typeof U=="function"?h.callback=U:h===n(u)&&r(u),p(z)}else r(u);h=n(u)}if(h!==null)var Rt=!0;else{var Xe=n(a);Xe!==null&&jn(k,Xe.startTime-z),Rt=!1}return Rt}finally{h=null,v=O,w=!1}}var P=!1,_=null,L=-1,A=5,R=-1;function G(){return!(e.unstable_now()-RN||125D?(N.sortIndex=O,t(a,N),n(u)===null&&N===n(a)&&(y?(d(L),L=-1):y=!0,jn(k,O-D))):(N.sortIndex=U,t(u,N),g||w||(g=!0,Tt(C))),N},e.unstable_shouldYield=G,e.unstable_wrapCallback=function(N){var z=v;return function(){var O=v;v=z;try{return N.apply(this,arguments)}finally{v=O}}}})(Xs);Ks.exports=Xs;var Mf=Ks.exports;/** + * @license React + * react-dom.production.min.js + * + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */var Df=S,Ce=Mf;function E(e){for(var t="https://reactjs.org/docs/error-decoder.html?invariant="+e,n=1;n"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),wi=Object.prototype.hasOwnProperty,Ff=/^[:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD][:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]*$/,gu={},yu={};function Uf(e){return wi.call(yu,e)?!0:wi.call(gu,e)?!1:Ff.test(e)?yu[e]=!0:(gu[e]=!0,!1)}function Af(e,t,n,r){if(n!==null&&n.type===0)return!1;switch(typeof t){case"function":case"symbol":return!0;case"boolean":return r?!1:n!==null?!n.acceptsBooleans:(e=e.toLowerCase().slice(0,5),e!=="data-"&&e!=="aria-");default:return!1}}function Bf(e,t,n,r){if(t===null||typeof t>"u"||Af(e,t,n,r))return!0;if(r)return!1;if(n!==null)switch(n.type){case 3:return!t;case 4:return t===!1;case 5:return isNaN(t);case 6:return isNaN(t)||1>t}return!1}function me(e,t,n,r,l,i,o){this.acceptsBooleans=t===2||t===3||t===4,this.attributeName=r,this.attributeNamespace=l,this.mustUseProperty=n,this.propertyName=e,this.type=t,this.sanitizeURL=i,this.removeEmptyString=o}var oe={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){oe[e]=new me(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var t=e[0];oe[t]=new me(t,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){oe[e]=new me(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){oe[e]=new me(e,2,!1,e,null,!1,!1)});"allowFullScreen async autoFocus autoPlay controls default defer disabled disablePictureInPicture disableRemotePlayback formNoValidate hidden loop noModule noValidate open playsInline readOnly required reversed scoped seamless itemScope".split(" ").forEach(function(e){oe[e]=new me(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){oe[e]=new me(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){oe[e]=new me(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){oe[e]=new me(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){oe[e]=new me(e,5,!1,e.toLowerCase(),null,!1,!1)});var ko=/[\-:]([a-z])/g;function xo(e){return e[1].toUpperCase()}"accent-height alignment-baseline arabic-form baseline-shift cap-height clip-path clip-rule color-interpolation color-interpolation-filters color-profile color-rendering dominant-baseline enable-background fill-opacity fill-rule flood-color flood-opacity font-family font-size font-size-adjust font-stretch font-style font-variant font-weight glyph-name glyph-orientation-horizontal glyph-orientation-vertical horiz-adv-x horiz-origin-x image-rendering letter-spacing lighting-color marker-end marker-mid marker-start overline-position overline-thickness paint-order panose-1 pointer-events rendering-intent shape-rendering stop-color stop-opacity strikethrough-position strikethrough-thickness stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity stroke-width text-anchor text-decoration text-rendering underline-position underline-thickness unicode-bidi unicode-range units-per-em v-alphabetic v-hanging v-ideographic v-mathematical vector-effect vert-adv-y vert-origin-x vert-origin-y word-spacing writing-mode xmlns:xlink x-height".split(" ").forEach(function(e){var t=e.replace(ko,xo);oe[t]=new me(t,1,!1,e,null,!1,!1)});"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(e){var t=e.replace(ko,xo);oe[t]=new me(t,1,!1,e,"http://www.w3.org/1999/xlink",!1,!1)});["xml:base","xml:lang","xml:space"].forEach(function(e){var t=e.replace(ko,xo);oe[t]=new me(t,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){oe[e]=new me(e,1,!1,e.toLowerCase(),null,!1,!1)});oe.xlinkHref=new me("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){oe[e]=new me(e,1,!1,e.toLowerCase(),null,!0,!0)});function Eo(e,t,n,r){var l=oe.hasOwnProperty(t)?oe[t]:null;(l!==null?l.type!==0:r||!(2s||l[o]!==i[s]){var u=` +`+l[o].replace(" at new "," at ");return e.displayName&&u.includes("")&&(u=u.replace("",e.displayName)),u}while(1<=o&&0<=s);break}}}finally{Gl=!1,Error.prepareStackTrace=n}return(e=e?e.displayName||e.name:"")?Fn(e):""}function Vf(e){switch(e.tag){case 5:return Fn(e.type);case 16:return Fn("Lazy");case 13:return Fn("Suspense");case 19:return Fn("SuspenseList");case 0:case 2:case 15:return e=Yl(e.type,!1),e;case 11:return e=Yl(e.type.render,!1),e;case 1:return e=Yl(e.type,!0),e;default:return""}}function Ei(e){if(e==null)return null;if(typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case Yt:return"Fragment";case Gt:return"Portal";case Si:return"Profiler";case Co:return"StrictMode";case ki:return"Suspense";case xi:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case Js:return(e.displayName||"Context")+".Consumer";case Ys:return(e._context.displayName||"Context")+".Provider";case No:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case jo:return t=e.displayName||null,t!==null?t:Ei(e.type)||"Memo";case ut:t=e._payload,e=e._init;try{return Ei(e(t))}catch{}}return null}function $f(e){var t=e.type;switch(e.tag){case 24:return"Cache";case 9:return(t.displayName||"Context")+".Consumer";case 10:return(t._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return e=t.render,e=e.displayName||e.name||"",t.displayName||(e!==""?"ForwardRef("+e+")":"ForwardRef");case 7:return"Fragment";case 5:return t;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return Ei(t);case 8:return t===Co?"StrictMode":"Mode";case 22:return"Offscreen";case 12:return"Profiler";case 21:return"Scope";case 13:return"Suspense";case 19:return"SuspenseList";case 25:return"TracingMarker";case 1:case 0:case 17:case 2:case 14:case 15:if(typeof t=="function")return t.displayName||t.name||null;if(typeof t=="string")return t}return null}function Et(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function qs(e){var t=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(t==="checkbox"||t==="radio")}function Wf(e){var t=qs(e)?"checked":"value",n=Object.getOwnPropertyDescriptor(e.constructor.prototype,t),r=""+e[t];if(!e.hasOwnProperty(t)&&typeof n<"u"&&typeof n.get=="function"&&typeof n.set=="function"){var l=n.get,i=n.set;return Object.defineProperty(e,t,{configurable:!0,get:function(){return l.call(this)},set:function(o){r=""+o,i.call(this,o)}}),Object.defineProperty(e,t,{enumerable:n.enumerable}),{getValue:function(){return r},setValue:function(o){r=""+o},stopTracking:function(){e._valueTracker=null,delete e[t]}}}}function Nr(e){e._valueTracker||(e._valueTracker=Wf(e))}function bs(e){if(!e)return!1;var t=e._valueTracker;if(!t)return!0;var n=t.getValue(),r="";return e&&(r=qs(e)?e.checked?"true":"false":e.value),e=r,e!==n?(t.setValue(e),!0):!1}function el(e){if(e=e||(typeof document<"u"?document:void 0),typeof e>"u")return null;try{return e.activeElement||e.body}catch{return e.body}}function Ci(e,t){var n=t.checked;return X({},t,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:n??e._wrapperState.initialChecked})}function Su(e,t){var n=t.defaultValue==null?"":t.defaultValue,r=t.checked!=null?t.checked:t.defaultChecked;n=Et(t.value!=null?t.value:n),e._wrapperState={initialChecked:r,initialValue:n,controlled:t.type==="checkbox"||t.type==="radio"?t.checked!=null:t.value!=null}}function ea(e,t){t=t.checked,t!=null&&Eo(e,"checked",t,!1)}function Ni(e,t){ea(e,t);var n=Et(t.value),r=t.type;if(n!=null)r==="number"?(n===0&&e.value===""||e.value!=n)&&(e.value=""+n):e.value!==""+n&&(e.value=""+n);else if(r==="submit"||r==="reset"){e.removeAttribute("value");return}t.hasOwnProperty("value")?ji(e,t.type,n):t.hasOwnProperty("defaultValue")&&ji(e,t.type,Et(t.defaultValue)),t.checked==null&&t.defaultChecked!=null&&(e.defaultChecked=!!t.defaultChecked)}function ku(e,t,n){if(t.hasOwnProperty("value")||t.hasOwnProperty("defaultValue")){var r=t.type;if(!(r!=="submit"&&r!=="reset"||t.value!==void 0&&t.value!==null))return;t=""+e._wrapperState.initialValue,n||t===e.value||(e.value=t),e.defaultValue=t}n=e.name,n!==""&&(e.name=""),e.defaultChecked=!!e._wrapperState.initialChecked,n!==""&&(e.name=n)}function ji(e,t,n){(t!=="number"||el(e.ownerDocument)!==e)&&(n==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+n&&(e.defaultValue=""+n))}var Un=Array.isArray;function un(e,t,n,r){if(e=e.options,t){t={};for(var l=0;l"+t.valueOf().toString()+"",t=jr.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;t.firstChild;)e.appendChild(t.firstChild)}});function Zn(e,t){if(t){var n=e.firstChild;if(n&&n===e.lastChild&&n.nodeType===3){n.nodeValue=t;return}}e.textContent=t}var Vn={animationIterationCount:!0,aspectRatio:!0,borderImageOutset:!0,borderImageSlice:!0,borderImageWidth:!0,boxFlex:!0,boxFlexGroup:!0,boxOrdinalGroup:!0,columnCount:!0,columns:!0,flex:!0,flexGrow:!0,flexPositive:!0,flexShrink:!0,flexNegative:!0,flexOrder:!0,gridArea:!0,gridRow:!0,gridRowEnd:!0,gridRowSpan:!0,gridRowStart:!0,gridColumn:!0,gridColumnEnd:!0,gridColumnSpan:!0,gridColumnStart:!0,fontWeight:!0,lineClamp:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,tabSize:!0,widows:!0,zIndex:!0,zoom:!0,fillOpacity:!0,floodOpacity:!0,stopOpacity:!0,strokeDasharray:!0,strokeDashoffset:!0,strokeMiterlimit:!0,strokeOpacity:!0,strokeWidth:!0},Hf=["Webkit","ms","Moz","O"];Object.keys(Vn).forEach(function(e){Hf.forEach(function(t){t=t+e.charAt(0).toUpperCase()+e.substring(1),Vn[t]=Vn[e]})});function la(e,t,n){return t==null||typeof t=="boolean"||t===""?"":n||typeof t!="number"||t===0||Vn.hasOwnProperty(e)&&Vn[e]?(""+t).trim():t+"px"}function ia(e,t){e=e.style;for(var n in t)if(t.hasOwnProperty(n)){var r=n.indexOf("--")===0,l=la(n,t[n],r);n==="float"&&(n="cssFloat"),r?e.setProperty(n,l):e[n]=l}}var Qf=X({menuitem:!0},{area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0});function Li(e,t){if(t){if(Qf[e]&&(t.children!=null||t.dangerouslySetInnerHTML!=null))throw Error(E(137,e));if(t.dangerouslySetInnerHTML!=null){if(t.children!=null)throw Error(E(60));if(typeof t.dangerouslySetInnerHTML!="object"||!("__html"in t.dangerouslySetInnerHTML))throw Error(E(61))}if(t.style!=null&&typeof t.style!="object")throw Error(E(62))}}function Ti(e,t){if(e.indexOf("-")===-1)return typeof t.is=="string";switch(e){case"annotation-xml":case"color-profile":case"font-face":case"font-face-src":case"font-face-uri":case"font-face-format":case"font-face-name":case"missing-glyph":return!1;default:return!0}}var Ri=null;function Po(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var zi=null,sn=null,an=null;function Cu(e){if(e=yr(e)){if(typeof zi!="function")throw Error(E(280));var t=e.stateNode;t&&(t=Rl(t),zi(e.stateNode,e.type,t))}}function oa(e){sn?an?an.push(e):an=[e]:sn=e}function ua(){if(sn){var e=sn,t=an;if(an=sn=null,Cu(e),t)for(e=0;e>>=0,e===0?32:31-(nd(e)/rd|0)|0}var Pr=64,_r=4194304;function An(e){switch(e&-e){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return e&4194240;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return e&130023424;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 1073741824;default:return e}}function ll(e,t){var n=e.pendingLanes;if(n===0)return 0;var r=0,l=e.suspendedLanes,i=e.pingedLanes,o=n&268435455;if(o!==0){var s=o&~l;s!==0?r=An(s):(i&=o,i!==0&&(r=An(i)))}else o=n&~l,o!==0?r=An(o):i!==0&&(r=An(i));if(r===0)return 0;if(t!==0&&t!==r&&!(t&l)&&(l=r&-r,i=t&-t,l>=i||l===16&&(i&4194240)!==0))return t;if(r&4&&(r|=n&16),t=e.entangledLanes,t!==0)for(e=e.entanglements,t&=r;0n;n++)t.push(e);return t}function vr(e,t,n){e.pendingLanes|=t,t!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,t=31-Fe(t),e[t]=n}function ud(e,t){var n=e.pendingLanes&~t;e.pendingLanes=t,e.suspendedLanes=0,e.pingedLanes=0,e.expiredLanes&=t,e.mutableReadLanes&=t,e.entangledLanes&=t,t=e.entanglements;var r=e.eventTimes;for(e=e.expirationTimes;0=Wn),Ou=" ",Iu=!1;function Pa(e,t){switch(e){case"keyup":return Md.indexOf(t.keyCode)!==-1;case"keydown":return t.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function _a(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var Jt=!1;function Fd(e,t){switch(e){case"compositionend":return _a(t);case"keypress":return t.which!==32?null:(Iu=!0,Ou);case"textInput":return e=t.data,e===Ou&&Iu?null:e;default:return null}}function Ud(e,t){if(Jt)return e==="compositionend"||!Mo&&Pa(e,t)?(e=Na(),Hr=zo=ft=null,Jt=!1,e):null;switch(e){case"paste":return null;case"keypress":if(!(t.ctrlKey||t.altKey||t.metaKey)||t.ctrlKey&&t.altKey){if(t.char&&1=t)return{node:n,offset:t-e};e=r}e:{for(;n;){if(n.nextSibling){n=n.nextSibling;break e}n=n.parentNode}n=void 0}n=Uu(n)}}function za(e,t){return e&&t?e===t?!0:e&&e.nodeType===3?!1:t&&t.nodeType===3?za(e,t.parentNode):"contains"in e?e.contains(t):e.compareDocumentPosition?!!(e.compareDocumentPosition(t)&16):!1:!1}function Oa(){for(var e=window,t=el();t instanceof e.HTMLIFrameElement;){try{var n=typeof t.contentWindow.location.href=="string"}catch{n=!1}if(n)e=t.contentWindow;else break;t=el(e.document)}return t}function Do(e){var t=e&&e.nodeName&&e.nodeName.toLowerCase();return t&&(t==="input"&&(e.type==="text"||e.type==="search"||e.type==="tel"||e.type==="url"||e.type==="password")||t==="textarea"||e.contentEditable==="true")}function Xd(e){var t=Oa(),n=e.focusedElem,r=e.selectionRange;if(t!==n&&n&&n.ownerDocument&&za(n.ownerDocument.documentElement,n)){if(r!==null&&Do(n)){if(t=r.start,e=r.end,e===void 0&&(e=t),"selectionStart"in n)n.selectionStart=t,n.selectionEnd=Math.min(e,n.value.length);else if(e=(t=n.ownerDocument||document)&&t.defaultView||window,e.getSelection){e=e.getSelection();var l=n.textContent.length,i=Math.min(r.start,l);r=r.end===void 0?i:Math.min(r.end,l),!e.extend&&i>r&&(l=r,r=i,i=l),l=Au(n,i);var o=Au(n,r);l&&o&&(e.rangeCount!==1||e.anchorNode!==l.node||e.anchorOffset!==l.offset||e.focusNode!==o.node||e.focusOffset!==o.offset)&&(t=t.createRange(),t.setStart(l.node,l.offset),e.removeAllRanges(),i>r?(e.addRange(t),e.extend(o.node,o.offset)):(t.setEnd(o.node,o.offset),e.addRange(t)))}}for(t=[],e=n;e=e.parentNode;)e.nodeType===1&&t.push({element:e,left:e.scrollLeft,top:e.scrollTop});for(typeof n.focus=="function"&&n.focus(),n=0;n=document.documentMode,Zt=null,Ui=null,Qn=null,Ai=!1;function Bu(e,t,n){var r=n.window===n?n.document:n.nodeType===9?n:n.ownerDocument;Ai||Zt==null||Zt!==el(r)||(r=Zt,"selectionStart"in r&&Do(r)?r={start:r.selectionStart,end:r.selectionEnd}:(r=(r.ownerDocument&&r.ownerDocument.defaultView||window).getSelection(),r={anchorNode:r.anchorNode,anchorOffset:r.anchorOffset,focusNode:r.focusNode,focusOffset:r.focusOffset}),Qn&&rr(Qn,r)||(Qn=r,r=ul(Ui,"onSelect"),0en||(e.current=Qi[en],Qi[en]=null,en--)}function B(e,t){en++,Qi[en]=e.current,e.current=t}var Ct={},ce=jt(Ct),ye=jt(!1),At=Ct;function hn(e,t){var n=e.type.contextTypes;if(!n)return Ct;var r=e.stateNode;if(r&&r.__reactInternalMemoizedUnmaskedChildContext===t)return r.__reactInternalMemoizedMaskedChildContext;var l={},i;for(i in n)l[i]=t[i];return r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=t,e.__reactInternalMemoizedMaskedChildContext=l),l}function we(e){return e=e.childContextTypes,e!=null}function al(){$(ye),$(ce)}function Xu(e,t,n){if(ce.current!==Ct)throw Error(E(168));B(ce,t),B(ye,n)}function $a(e,t,n){var r=e.stateNode;if(t=t.childContextTypes,typeof r.getChildContext!="function")return n;r=r.getChildContext();for(var l in r)if(!(l in t))throw Error(E(108,$f(e)||"Unknown",l));return X({},n,r)}function cl(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||Ct,At=ce.current,B(ce,e),B(ye,ye.current),!0}function Gu(e,t,n){var r=e.stateNode;if(!r)throw Error(E(169));n?(e=$a(e,t,At),r.__reactInternalMemoizedMergedChildContext=e,$(ye),$(ce),B(ce,e)):$(ye),B(ye,n)}var Ze=null,zl=!1,ai=!1;function Wa(e){Ze===null?Ze=[e]:Ze.push(e)}function ip(e){zl=!0,Wa(e)}function Pt(){if(!ai&&Ze!==null){ai=!0;var e=0,t=F;try{var n=Ze;for(F=1;e>=o,l-=o,qe=1<<32-Fe(t)+l|n<L?(A=_,_=null):A=_.sibling;var R=v(d,_,p[L],k);if(R===null){_===null&&(_=A);break}e&&_&&R.alternate===null&&t(d,_),c=i(R,c,L),P===null?C=R:P.sibling=R,P=R,_=A}if(L===p.length)return n(d,_),W&&zt(d,L),C;if(_===null){for(;LL?(A=_,_=null):A=_.sibling;var G=v(d,_,R.value,k);if(G===null){_===null&&(_=A);break}e&&_&&G.alternate===null&&t(d,_),c=i(G,c,L),P===null?C=G:P.sibling=G,P=G,_=A}if(R.done)return n(d,_),W&&zt(d,L),C;if(_===null){for(;!R.done;L++,R=p.next())R=h(d,R.value,k),R!==null&&(c=i(R,c,L),P===null?C=R:P.sibling=R,P=R);return W&&zt(d,L),C}for(_=r(d,_);!R.done;L++,R=p.next())R=w(_,d,L,R.value,k),R!==null&&(e&&R.alternate!==null&&_.delete(R.key===null?L:R.key),c=i(R,c,L),P===null?C=R:P.sibling=R,P=R);return e&&_.forEach(function(fe){return t(d,fe)}),W&&zt(d,L),C}function x(d,c,p,k){if(typeof p=="object"&&p!==null&&p.type===Yt&&p.key===null&&(p=p.props.children),typeof p=="object"&&p!==null){switch(p.$$typeof){case Cr:e:{for(var C=p.key,P=c;P!==null;){if(P.key===C){if(C=p.type,C===Yt){if(P.tag===7){n(d,P.sibling),c=l(P,p.props.children),c.return=d,d=c;break e}}else if(P.elementType===C||typeof C=="object"&&C!==null&&C.$$typeof===ut&&Zu(C)===P.type){n(d,P.sibling),c=l(P,p.props),c.ref=In(d,P,p),c.return=d,d=c;break e}n(d,P);break}else t(d,P);P=P.sibling}p.type===Yt?(c=Ut(p.props.children,d.mode,k,p.key),c.return=d,d=c):(k=qr(p.type,p.key,p.props,null,d.mode,k),k.ref=In(d,c,p),k.return=d,d=k)}return o(d);case Gt:e:{for(P=p.key;c!==null;){if(c.key===P)if(c.tag===4&&c.stateNode.containerInfo===p.containerInfo&&c.stateNode.implementation===p.implementation){n(d,c.sibling),c=l(c,p.children||[]),c.return=d,d=c;break e}else{n(d,c);break}else t(d,c);c=c.sibling}c=gi(p,d.mode,k),c.return=d,d=c}return o(d);case ut:return P=p._init,x(d,c,P(p._payload),k)}if(Un(p))return g(d,c,p,k);if(Ln(p))return y(d,c,p,k);Mr(d,p)}return typeof p=="string"&&p!==""||typeof p=="number"?(p=""+p,c!==null&&c.tag===6?(n(d,c.sibling),c=l(c,p),c.return=d,d=c):(n(d,c),c=vi(p,d.mode,k),c.return=d,d=c),o(d)):n(d,c)}return x}var vn=Xa(!0),Ga=Xa(!1),pl=jt(null),hl=null,rn=null,Bo=null;function Vo(){Bo=rn=hl=null}function $o(e){var t=pl.current;$(pl),e._currentValue=t}function Gi(e,t,n){for(;e!==null;){var r=e.alternate;if((e.childLanes&t)!==t?(e.childLanes|=t,r!==null&&(r.childLanes|=t)):r!==null&&(r.childLanes&t)!==t&&(r.childLanes|=t),e===n)break;e=e.return}}function fn(e,t){hl=e,Bo=rn=null,e=e.dependencies,e!==null&&e.firstContext!==null&&(e.lanes&t&&(ge=!0),e.firstContext=null)}function Re(e){var t=e._currentValue;if(Bo!==e)if(e={context:e,memoizedValue:t,next:null},rn===null){if(hl===null)throw Error(E(308));rn=e,hl.dependencies={lanes:0,firstContext:e}}else rn=rn.next=e;return t}var Mt=null;function Wo(e){Mt===null?Mt=[e]:Mt.push(e)}function Ya(e,t,n,r){var l=t.interleaved;return l===null?(n.next=n,Wo(t)):(n.next=l.next,l.next=n),t.interleaved=n,rt(e,r)}function rt(e,t){e.lanes|=t;var n=e.alternate;for(n!==null&&(n.lanes|=t),n=e,e=e.return;e!==null;)e.childLanes|=t,n=e.alternate,n!==null&&(n.childLanes|=t),n=e,e=e.return;return n.tag===3?n.stateNode:null}var st=!1;function Ho(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function Ja(e,t){e=e.updateQueue,t.updateQueue===e&&(t.updateQueue={baseState:e.baseState,firstBaseUpdate:e.firstBaseUpdate,lastBaseUpdate:e.lastBaseUpdate,shared:e.shared,effects:e.effects})}function et(e,t){return{eventTime:e,lane:t,tag:0,payload:null,callback:null,next:null}}function yt(e,t,n){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,M&2){var l=r.pending;return l===null?t.next=t:(t.next=l.next,l.next=t),r.pending=t,rt(e,n)}return l=r.interleaved,l===null?(t.next=t,Wo(r)):(t.next=l.next,l.next=t),r.interleaved=t,rt(e,n)}function Kr(e,t,n){if(t=t.updateQueue,t!==null&&(t=t.shared,(n&4194240)!==0)){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,Lo(e,n)}}function qu(e,t){var n=e.updateQueue,r=e.alternate;if(r!==null&&(r=r.updateQueue,n===r)){var l=null,i=null;if(n=n.firstBaseUpdate,n!==null){do{var o={eventTime:n.eventTime,lane:n.lane,tag:n.tag,payload:n.payload,callback:n.callback,next:null};i===null?l=i=o:i=i.next=o,n=n.next}while(n!==null);i===null?l=i=t:i=i.next=t}else l=i=t;n={baseState:r.baseState,firstBaseUpdate:l,lastBaseUpdate:i,shared:r.shared,effects:r.effects},e.updateQueue=n;return}e=n.lastBaseUpdate,e===null?n.firstBaseUpdate=t:e.next=t,n.lastBaseUpdate=t}function ml(e,t,n,r){var l=e.updateQueue;st=!1;var i=l.firstBaseUpdate,o=l.lastBaseUpdate,s=l.shared.pending;if(s!==null){l.shared.pending=null;var u=s,a=u.next;u.next=null,o===null?i=a:o.next=a,o=u;var m=e.alternate;m!==null&&(m=m.updateQueue,s=m.lastBaseUpdate,s!==o&&(s===null?m.firstBaseUpdate=a:s.next=a,m.lastBaseUpdate=u))}if(i!==null){var h=l.baseState;o=0,m=a=u=null,s=i;do{var v=s.lane,w=s.eventTime;if((r&v)===v){m!==null&&(m=m.next={eventTime:w,lane:0,tag:s.tag,payload:s.payload,callback:s.callback,next:null});e:{var g=e,y=s;switch(v=t,w=n,y.tag){case 1:if(g=y.payload,typeof g=="function"){h=g.call(w,h,v);break e}h=g;break e;case 3:g.flags=g.flags&-65537|128;case 0:if(g=y.payload,v=typeof g=="function"?g.call(w,h,v):g,v==null)break e;h=X({},h,v);break e;case 2:st=!0}}s.callback!==null&&s.lane!==0&&(e.flags|=64,v=l.effects,v===null?l.effects=[s]:v.push(s))}else w={eventTime:w,lane:v,tag:s.tag,payload:s.payload,callback:s.callback,next:null},m===null?(a=m=w,u=h):m=m.next=w,o|=v;if(s=s.next,s===null){if(s=l.shared.pending,s===null)break;v=s,s=v.next,v.next=null,l.lastBaseUpdate=v,l.shared.pending=null}}while(!0);if(m===null&&(u=h),l.baseState=u,l.firstBaseUpdate=a,l.lastBaseUpdate=m,t=l.shared.interleaved,t!==null){l=t;do o|=l.lane,l=l.next;while(l!==t)}else i===null&&(l.shared.lanes=0);$t|=o,e.lanes=o,e.memoizedState=h}}function bu(e,t,n){if(e=t.effects,t.effects=null,e!==null)for(t=0;tn?n:4,e(!0);var r=fi.transition;fi.transition={};try{e(!1),t()}finally{F=n,fi.transition=r}}function pc(){return ze().memoizedState}function ap(e,t,n){var r=St(e);if(n={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null},hc(e))mc(t,n);else if(n=Ya(e,t,n,r),n!==null){var l=pe();Ue(n,e,r,l),vc(n,t,r)}}function cp(e,t,n){var r=St(e),l={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null};if(hc(e))mc(t,l);else{var i=e.alternate;if(e.lanes===0&&(i===null||i.lanes===0)&&(i=t.lastRenderedReducer,i!==null))try{var o=t.lastRenderedState,s=i(o,n);if(l.hasEagerState=!0,l.eagerState=s,Ae(s,o)){var u=t.interleaved;u===null?(l.next=l,Wo(t)):(l.next=u.next,u.next=l),t.interleaved=l;return}}catch{}finally{}n=Ya(e,t,l,r),n!==null&&(l=pe(),Ue(n,e,r,l),vc(n,t,r))}}function hc(e){var t=e.alternate;return e===K||t!==null&&t===K}function mc(e,t){Kn=gl=!0;var n=e.pending;n===null?t.next=t:(t.next=n.next,n.next=t),e.pending=t}function vc(e,t,n){if(n&4194240){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,Lo(e,n)}}var yl={readContext:Re,useCallback:ue,useContext:ue,useEffect:ue,useImperativeHandle:ue,useInsertionEffect:ue,useLayoutEffect:ue,useMemo:ue,useReducer:ue,useRef:ue,useState:ue,useDebugValue:ue,useDeferredValue:ue,useTransition:ue,useMutableSource:ue,useSyncExternalStore:ue,useId:ue,unstable_isNewReconciler:!1},fp={readContext:Re,useCallback:function(e,t){return We().memoizedState=[e,t===void 0?null:t],e},useContext:Re,useEffect:ts,useImperativeHandle:function(e,t,n){return n=n!=null?n.concat([e]):null,Gr(4194308,4,sc.bind(null,t,e),n)},useLayoutEffect:function(e,t){return Gr(4194308,4,e,t)},useInsertionEffect:function(e,t){return Gr(4,2,e,t)},useMemo:function(e,t){var n=We();return t=t===void 0?null:t,e=e(),n.memoizedState=[e,t],e},useReducer:function(e,t,n){var r=We();return t=n!==void 0?n(t):t,r.memoizedState=r.baseState=t,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:e,lastRenderedState:t},r.queue=e,e=e.dispatch=ap.bind(null,K,e),[r.memoizedState,e]},useRef:function(e){var t=We();return e={current:e},t.memoizedState=e},useState:es,useDebugValue:qo,useDeferredValue:function(e){return We().memoizedState=e},useTransition:function(){var e=es(!1),t=e[0];return e=sp.bind(null,e[1]),We().memoizedState=e,[t,e]},useMutableSource:function(){},useSyncExternalStore:function(e,t,n){var r=K,l=We();if(W){if(n===void 0)throw Error(E(407));n=n()}else{if(n=t(),re===null)throw Error(E(349));Vt&30||ec(r,t,n)}l.memoizedState=n;var i={value:n,getSnapshot:t};return l.queue=i,ts(nc.bind(null,r,i,e),[e]),r.flags|=2048,fr(9,tc.bind(null,r,i,n,t),void 0,null),n},useId:function(){var e=We(),t=re.identifierPrefix;if(W){var n=be,r=qe;n=(r&~(1<<32-Fe(r)-1)).toString(32)+n,t=":"+t+"R"+n,n=ar++,0<\/script>",e=e.removeChild(e.firstChild)):typeof r.is=="string"?e=o.createElement(n,{is:r.is}):(e=o.createElement(n),n==="select"&&(o=e,r.multiple?o.multiple=!0:r.size&&(o.size=r.size))):e=o.createElementNS(e,n),e[He]=t,e[or]=r,jc(e,t,!1,!1),t.stateNode=e;e:{switch(o=Ti(n,r),n){case"dialog":V("cancel",e),V("close",e),l=r;break;case"iframe":case"object":case"embed":V("load",e),l=r;break;case"video":case"audio":for(l=0;lwn&&(t.flags|=128,r=!0,Mn(i,!1),t.lanes=4194304)}else{if(!r)if(e=vl(o),e!==null){if(t.flags|=128,r=!0,n=e.updateQueue,n!==null&&(t.updateQueue=n,t.flags|=4),Mn(i,!0),i.tail===null&&i.tailMode==="hidden"&&!o.alternate&&!W)return se(t),null}else 2*q()-i.renderingStartTime>wn&&n!==1073741824&&(t.flags|=128,r=!0,Mn(i,!1),t.lanes=4194304);i.isBackwards?(o.sibling=t.child,t.child=o):(n=i.last,n!==null?n.sibling=o:t.child=o,i.last=o)}return i.tail!==null?(t=i.tail,i.rendering=t,i.tail=t.sibling,i.renderingStartTime=q(),t.sibling=null,n=Q.current,B(Q,r?n&1|2:n&1),t):(se(t),null);case 22:case 23:return lu(),r=t.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(t.flags|=8192),r&&t.mode&1?ke&1073741824&&(se(t),t.subtreeFlags&6&&(t.flags|=8192)):se(t),null;case 24:return null;case 25:return null}throw Error(E(156,t.tag))}function wp(e,t){switch(Uo(t),t.tag){case 1:return we(t.type)&&al(),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return gn(),$(ye),$(ce),Xo(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 5:return Ko(t),null;case 13:if($(Q),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(E(340));mn()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return $(Q),null;case 4:return gn(),null;case 10:return $o(t.type._context),null;case 22:case 23:return lu(),null;case 24:return null;default:return null}}var Fr=!1,ae=!1,Sp=typeof WeakSet=="function"?WeakSet:Set,j=null;function ln(e,t){var n=e.ref;if(n!==null)if(typeof n=="function")try{n(null)}catch(r){Y(e,t,r)}else n.current=null}function ro(e,t,n){try{n()}catch(r){Y(e,t,r)}}var ds=!1;function kp(e,t){if(Bi=il,e=Oa(),Do(e)){if("selectionStart"in e)var n={start:e.selectionStart,end:e.selectionEnd};else e:{n=(n=e.ownerDocument)&&n.defaultView||window;var r=n.getSelection&&n.getSelection();if(r&&r.rangeCount!==0){n=r.anchorNode;var l=r.anchorOffset,i=r.focusNode;r=r.focusOffset;try{n.nodeType,i.nodeType}catch{n=null;break e}var o=0,s=-1,u=-1,a=0,m=0,h=e,v=null;t:for(;;){for(var w;h!==n||l!==0&&h.nodeType!==3||(s=o+l),h!==i||r!==0&&h.nodeType!==3||(u=o+r),h.nodeType===3&&(o+=h.nodeValue.length),(w=h.firstChild)!==null;)v=h,h=w;for(;;){if(h===e)break t;if(v===n&&++a===l&&(s=o),v===i&&++m===r&&(u=o),(w=h.nextSibling)!==null)break;h=v,v=h.parentNode}h=w}n=s===-1||u===-1?null:{start:s,end:u}}else n=null}n=n||{start:0,end:0}}else n=null;for(Vi={focusedElem:e,selectionRange:n},il=!1,j=t;j!==null;)if(t=j,e=t.child,(t.subtreeFlags&1028)!==0&&e!==null)e.return=t,j=e;else for(;j!==null;){t=j;try{var g=t.alternate;if(t.flags&1024)switch(t.tag){case 0:case 11:case 15:break;case 1:if(g!==null){var y=g.memoizedProps,x=g.memoizedState,d=t.stateNode,c=d.getSnapshotBeforeUpdate(t.elementType===t.type?y:Ie(t.type,y),x);d.__reactInternalSnapshotBeforeUpdate=c}break;case 3:var p=t.stateNode.containerInfo;p.nodeType===1?p.textContent="":p.nodeType===9&&p.documentElement&&p.removeChild(p.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(E(163))}}catch(k){Y(t,t.return,k)}if(e=t.sibling,e!==null){e.return=t.return,j=e;break}j=t.return}return g=ds,ds=!1,g}function Xn(e,t,n){var r=t.updateQueue;if(r=r!==null?r.lastEffect:null,r!==null){var l=r=r.next;do{if((l.tag&e)===e){var i=l.destroy;l.destroy=void 0,i!==void 0&&ro(t,n,i)}l=l.next}while(l!==r)}}function Ml(e,t){if(t=t.updateQueue,t=t!==null?t.lastEffect:null,t!==null){var n=t=t.next;do{if((n.tag&e)===e){var r=n.create;n.destroy=r()}n=n.next}while(n!==t)}}function lo(e){var t=e.ref;if(t!==null){var n=e.stateNode;switch(e.tag){case 5:e=n;break;default:e=n}typeof t=="function"?t(e):t.current=e}}function Lc(e){var t=e.alternate;t!==null&&(e.alternate=null,Lc(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&(delete t[He],delete t[or],delete t[Hi],delete t[rp],delete t[lp])),e.stateNode=null,e.return=null,e.dependencies=null,e.memoizedProps=null,e.memoizedState=null,e.pendingProps=null,e.stateNode=null,e.updateQueue=null}function Tc(e){return e.tag===5||e.tag===3||e.tag===4}function ps(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||Tc(e.return))return null;e=e.return}for(e.sibling.return=e.return,e=e.sibling;e.tag!==5&&e.tag!==6&&e.tag!==18;){if(e.flags&2||e.child===null||e.tag===4)continue e;e.child.return=e,e=e.child}if(!(e.flags&2))return e.stateNode}}function io(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?n.nodeType===8?n.parentNode.insertBefore(e,t):n.insertBefore(e,t):(n.nodeType===8?(t=n.parentNode,t.insertBefore(e,n)):(t=n,t.appendChild(e)),n=n._reactRootContainer,n!=null||t.onclick!==null||(t.onclick=sl));else if(r!==4&&(e=e.child,e!==null))for(io(e,t,n),e=e.sibling;e!==null;)io(e,t,n),e=e.sibling}function oo(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?n.insertBefore(e,t):n.appendChild(e);else if(r!==4&&(e=e.child,e!==null))for(oo(e,t,n),e=e.sibling;e!==null;)oo(e,t,n),e=e.sibling}var le=null,Me=!1;function ot(e,t,n){for(n=n.child;n!==null;)Rc(e,t,n),n=n.sibling}function Rc(e,t,n){if(Qe&&typeof Qe.onCommitFiberUnmount=="function")try{Qe.onCommitFiberUnmount(Pl,n)}catch{}switch(n.tag){case 5:ae||ln(n,t);case 6:var r=le,l=Me;le=null,ot(e,t,n),le=r,Me=l,le!==null&&(Me?(e=le,n=n.stateNode,e.nodeType===8?e.parentNode.removeChild(n):e.removeChild(n)):le.removeChild(n.stateNode));break;case 18:le!==null&&(Me?(e=le,n=n.stateNode,e.nodeType===8?si(e.parentNode,n):e.nodeType===1&&si(e,n),tr(e)):si(le,n.stateNode));break;case 4:r=le,l=Me,le=n.stateNode.containerInfo,Me=!0,ot(e,t,n),le=r,Me=l;break;case 0:case 11:case 14:case 15:if(!ae&&(r=n.updateQueue,r!==null&&(r=r.lastEffect,r!==null))){l=r=r.next;do{var i=l,o=i.destroy;i=i.tag,o!==void 0&&(i&2||i&4)&&ro(n,t,o),l=l.next}while(l!==r)}ot(e,t,n);break;case 1:if(!ae&&(ln(n,t),r=n.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=n.memoizedProps,r.state=n.memoizedState,r.componentWillUnmount()}catch(s){Y(n,t,s)}ot(e,t,n);break;case 21:ot(e,t,n);break;case 22:n.mode&1?(ae=(r=ae)||n.memoizedState!==null,ot(e,t,n),ae=r):ot(e,t,n);break;default:ot(e,t,n)}}function hs(e){var t=e.updateQueue;if(t!==null){e.updateQueue=null;var n=e.stateNode;n===null&&(n=e.stateNode=new Sp),t.forEach(function(r){var l=Tp.bind(null,e,r);n.has(r)||(n.add(r),r.then(l,l))})}}function Oe(e,t){var n=t.deletions;if(n!==null)for(var r=0;rl&&(l=o),r&=~i}if(r=l,r=q()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*Ep(r/1960))-r,10e?16:e,dt===null)var r=!1;else{if(e=dt,dt=null,kl=0,M&6)throw Error(E(331));var l=M;for(M|=4,j=e.current;j!==null;){var i=j,o=i.child;if(j.flags&16){var s=i.deletions;if(s!==null){for(var u=0;uq()-nu?Ft(e,0):tu|=n),Se(e,t)}function Ac(e,t){t===0&&(e.mode&1?(t=_r,_r<<=1,!(_r&130023424)&&(_r=4194304)):t=1);var n=pe();e=rt(e,t),e!==null&&(vr(e,t,n),Se(e,n))}function Lp(e){var t=e.memoizedState,n=0;t!==null&&(n=t.retryLane),Ac(e,n)}function Tp(e,t){var n=0;switch(e.tag){case 13:var r=e.stateNode,l=e.memoizedState;l!==null&&(n=l.retryLane);break;case 19:r=e.stateNode;break;default:throw Error(E(314))}r!==null&&r.delete(t),Ac(e,n)}var Bc;Bc=function(e,t,n){if(e!==null)if(e.memoizedProps!==t.pendingProps||ye.current)ge=!0;else{if(!(e.lanes&n)&&!(t.flags&128))return ge=!1,gp(e,t,n);ge=!!(e.flags&131072)}else ge=!1,W&&t.flags&1048576&&Ha(t,dl,t.index);switch(t.lanes=0,t.tag){case 2:var r=t.type;Yr(e,t),e=t.pendingProps;var l=hn(t,ce.current);fn(t,n),l=Yo(null,t,r,e,l,n);var i=Jo();return t.flags|=1,typeof l=="object"&&l!==null&&typeof l.render=="function"&&l.$$typeof===void 0?(t.tag=1,t.memoizedState=null,t.updateQueue=null,we(r)?(i=!0,cl(t)):i=!1,t.memoizedState=l.state!==null&&l.state!==void 0?l.state:null,Ho(t),l.updater=Il,t.stateNode=l,l._reactInternals=t,Ji(t,r,e,n),t=bi(null,t,r,!0,i,n)):(t.tag=0,W&&i&&Fo(t),de(null,t,l,n),t=t.child),t;case 16:r=t.elementType;e:{switch(Yr(e,t),e=t.pendingProps,l=r._init,r=l(r._payload),t.type=r,l=t.tag=zp(r),e=Ie(r,e),l){case 0:t=qi(null,t,r,e,n);break e;case 1:t=as(null,t,r,e,n);break e;case 11:t=us(null,t,r,e,n);break e;case 14:t=ss(null,t,r,Ie(r.type,e),n);break e}throw Error(E(306,r,""))}return t;case 0:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:Ie(r,l),qi(e,t,r,l,n);case 1:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:Ie(r,l),as(e,t,r,l,n);case 3:e:{if(Ec(t),e===null)throw Error(E(387));r=t.pendingProps,i=t.memoizedState,l=i.element,Ja(e,t),ml(t,r,null,n);var o=t.memoizedState;if(r=o.element,i.isDehydrated)if(i={element:r,isDehydrated:!1,cache:o.cache,pendingSuspenseBoundaries:o.pendingSuspenseBoundaries,transitions:o.transitions},t.updateQueue.baseState=i,t.memoizedState=i,t.flags&256){l=yn(Error(E(423)),t),t=cs(e,t,r,n,l);break e}else if(r!==l){l=yn(Error(E(424)),t),t=cs(e,t,r,n,l);break e}else for(xe=gt(t.stateNode.containerInfo.firstChild),Ee=t,W=!0,De=null,n=Ga(t,null,r,n),t.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling;else{if(mn(),r===l){t=lt(e,t,n);break e}de(e,t,r,n)}t=t.child}return t;case 5:return Za(t),e===null&&Xi(t),r=t.type,l=t.pendingProps,i=e!==null?e.memoizedProps:null,o=l.children,$i(r,l)?o=null:i!==null&&$i(r,i)&&(t.flags|=32),xc(e,t),de(e,t,o,n),t.child;case 6:return e===null&&Xi(t),null;case 13:return Cc(e,t,n);case 4:return Qo(t,t.stateNode.containerInfo),r=t.pendingProps,e===null?t.child=vn(t,null,r,n):de(e,t,r,n),t.child;case 11:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:Ie(r,l),us(e,t,r,l,n);case 7:return de(e,t,t.pendingProps,n),t.child;case 8:return de(e,t,t.pendingProps.children,n),t.child;case 12:return de(e,t,t.pendingProps.children,n),t.child;case 10:e:{if(r=t.type._context,l=t.pendingProps,i=t.memoizedProps,o=l.value,B(pl,r._currentValue),r._currentValue=o,i!==null)if(Ae(i.value,o)){if(i.children===l.children&&!ye.current){t=lt(e,t,n);break e}}else for(i=t.child,i!==null&&(i.return=t);i!==null;){var s=i.dependencies;if(s!==null){o=i.child;for(var u=s.firstContext;u!==null;){if(u.context===r){if(i.tag===1){u=et(-1,n&-n),u.tag=2;var a=i.updateQueue;if(a!==null){a=a.shared;var m=a.pending;m===null?u.next=u:(u.next=m.next,m.next=u),a.pending=u}}i.lanes|=n,u=i.alternate,u!==null&&(u.lanes|=n),Gi(i.return,n,t),s.lanes|=n;break}u=u.next}}else if(i.tag===10)o=i.type===t.type?null:i.child;else if(i.tag===18){if(o=i.return,o===null)throw Error(E(341));o.lanes|=n,s=o.alternate,s!==null&&(s.lanes|=n),Gi(o,n,t),o=i.sibling}else o=i.child;if(o!==null)o.return=i;else for(o=i;o!==null;){if(o===t){o=null;break}if(i=o.sibling,i!==null){i.return=o.return,o=i;break}o=o.return}i=o}de(e,t,l.children,n),t=t.child}return t;case 9:return l=t.type,r=t.pendingProps.children,fn(t,n),l=Re(l),r=r(l),t.flags|=1,de(e,t,r,n),t.child;case 14:return r=t.type,l=Ie(r,t.pendingProps),l=Ie(r.type,l),ss(e,t,r,l,n);case 15:return Sc(e,t,t.type,t.pendingProps,n);case 17:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:Ie(r,l),Yr(e,t),t.tag=1,we(r)?(e=!0,cl(t)):e=!1,fn(t,n),gc(t,r,l),Ji(t,r,l,n),bi(null,t,r,!0,e,n);case 19:return Nc(e,t,n);case 22:return kc(e,t,n)}throw Error(E(156,t.tag))};function Vc(e,t){return ha(e,t)}function Rp(e,t,n,r){this.tag=e,this.key=n,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=t,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=r,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function Le(e,t,n,r){return new Rp(e,t,n,r)}function ou(e){return e=e.prototype,!(!e||!e.isReactComponent)}function zp(e){if(typeof e=="function")return ou(e)?1:0;if(e!=null){if(e=e.$$typeof,e===No)return 11;if(e===jo)return 14}return 2}function kt(e,t){var n=e.alternate;return n===null?(n=Le(e.tag,t,e.key,e.mode),n.elementType=e.elementType,n.type=e.type,n.stateNode=e.stateNode,n.alternate=e,e.alternate=n):(n.pendingProps=t,n.type=e.type,n.flags=0,n.subtreeFlags=0,n.deletions=null),n.flags=e.flags&14680064,n.childLanes=e.childLanes,n.lanes=e.lanes,n.child=e.child,n.memoizedProps=e.memoizedProps,n.memoizedState=e.memoizedState,n.updateQueue=e.updateQueue,t=e.dependencies,n.dependencies=t===null?null:{lanes:t.lanes,firstContext:t.firstContext},n.sibling=e.sibling,n.index=e.index,n.ref=e.ref,n}function qr(e,t,n,r,l,i){var o=2;if(r=e,typeof e=="function")ou(e)&&(o=1);else if(typeof e=="string")o=5;else e:switch(e){case Yt:return Ut(n.children,l,i,t);case Co:o=8,l|=8;break;case Si:return e=Le(12,n,t,l|2),e.elementType=Si,e.lanes=i,e;case ki:return e=Le(13,n,t,l),e.elementType=ki,e.lanes=i,e;case xi:return e=Le(19,n,t,l),e.elementType=xi,e.lanes=i,e;case Zs:return Fl(n,l,i,t);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case Ys:o=10;break e;case Js:o=9;break e;case No:o=11;break e;case jo:o=14;break e;case ut:o=16,r=null;break e}throw Error(E(130,e==null?e:typeof e,""))}return t=Le(o,n,t,l),t.elementType=e,t.type=r,t.lanes=i,t}function Ut(e,t,n,r){return e=Le(7,e,r,t),e.lanes=n,e}function Fl(e,t,n,r){return e=Le(22,e,r,t),e.elementType=Zs,e.lanes=n,e.stateNode={isHidden:!1},e}function vi(e,t,n){return e=Le(6,e,null,t),e.lanes=n,e}function gi(e,t,n){return t=Le(4,e.children!==null?e.children:[],e.key,t),t.lanes=n,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}function Op(e,t,n,r,l){this.tag=t,this.containerInfo=e,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=Zl(0),this.expirationTimes=Zl(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Zl(0),this.identifierPrefix=r,this.onRecoverableError=l,this.mutableSourceEagerHydrationData=null}function uu(e,t,n,r,l,i,o,s,u){return e=new Op(e,t,n,s,u),t===1?(t=1,i===!0&&(t|=8)):t=0,i=Le(3,null,null,t),e.current=i,i.stateNode=e,i.memoizedState={element:r,isDehydrated:n,cache:null,transitions:null,pendingSuspenseBoundaries:null},Ho(i),e}function Ip(e,t,n){var r=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(Qc)}catch(e){console.error(e)}}Qc(),Qs.exports=Ne;var Ap=Qs.exports,Kc,xs=Ap;Kc=xs.createRoot,xs.hydrateRoot;/** + * @remix-run/router v1.23.2 + * + * Copyright (c) Remix Software Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE.md file in the root directory of this source tree. + * + * @license MIT + */function pr(){return pr=Object.assign?Object.assign.bind():function(e){for(var t=1;t"u")throw new Error(t)}function fu(e,t){if(!e){typeof console<"u"&&console.warn(t);try{throw new Error(t)}catch{}}}function Vp(){return Math.random().toString(36).substr(2,8)}function Cs(e,t){return{usr:e.state,key:e.key,idx:t}}function fo(e,t,n,r){return n===void 0&&(n=null),pr({pathname:typeof e=="string"?e:e.pathname,search:"",hash:""},typeof t=="string"?Cn(t):t,{state:n,key:t&&t.key||r||Vp()})}function Cl(e){let{pathname:t="/",search:n="",hash:r=""}=e;return n&&n!=="?"&&(t+=n.charAt(0)==="?"?n:"?"+n),r&&r!=="#"&&(t+=r.charAt(0)==="#"?r:"#"+r),t}function Cn(e){let t={};if(e){let n=e.indexOf("#");n>=0&&(t.hash=e.substr(n),e=e.substr(0,n));let r=e.indexOf("?");r>=0&&(t.search=e.substr(r),e=e.substr(0,r)),e&&(t.pathname=e)}return t}function $p(e,t,n,r){r===void 0&&(r={});let{window:l=document.defaultView,v5Compat:i=!1}=r,o=l.history,s=pt.Pop,u=null,a=m();a==null&&(a=0,o.replaceState(pr({},o.state,{idx:a}),""));function m(){return(o.state||{idx:null}).idx}function h(){s=pt.Pop;let x=m(),d=x==null?null:x-a;a=x,u&&u({action:s,location:y.location,delta:d})}function v(x,d){s=pt.Push;let c=fo(y.location,x,d);a=m()+1;let p=Cs(c,a),k=y.createHref(c);try{o.pushState(p,"",k)}catch(C){if(C instanceof DOMException&&C.name==="DataCloneError")throw C;l.location.assign(k)}i&&u&&u({action:s,location:y.location,delta:1})}function w(x,d){s=pt.Replace;let c=fo(y.location,x,d);a=m();let p=Cs(c,a),k=y.createHref(c);o.replaceState(p,"",k),i&&u&&u({action:s,location:y.location,delta:0})}function g(x){let d=l.location.origin!=="null"?l.location.origin:l.location.href,c=typeof x=="string"?x:Cl(x);return c=c.replace(/ $/,"%20"),J(d,"No window.location.(origin|href) available to create URL for href: "+c),new URL(c,d)}let y={get action(){return s},get location(){return e(l,o)},listen(x){if(u)throw new Error("A history only accepts one active listener");return l.addEventListener(Es,h),u=x,()=>{l.removeEventListener(Es,h),u=null}},createHref(x){return t(l,x)},createURL:g,encodeLocation(x){let d=g(x);return{pathname:d.pathname,search:d.search,hash:d.hash}},push:v,replace:w,go(x){return o.go(x)}};return y}var Ns;(function(e){e.data="data",e.deferred="deferred",e.redirect="redirect",e.error="error"})(Ns||(Ns={}));function Wp(e,t,n){return n===void 0&&(n="/"),Hp(e,t,n)}function Hp(e,t,n,r){let l=typeof t=="string"?Cn(t):t,i=Sn(l.pathname||"/",n);if(i==null)return null;let o=Xc(e);Qp(o);let s=null;for(let u=0;s==null&&u{let u={relativePath:s===void 0?i.path||"":s,caseSensitive:i.caseSensitive===!0,childrenIndex:o,route:i};u.relativePath.startsWith("/")&&(J(u.relativePath.startsWith(r),'Absolute route path "'+u.relativePath+'" nested under path '+('"'+r+'" is not valid. An absolute child route path ')+"must start with the combined path of all its parent routes."),u.relativePath=u.relativePath.slice(r.length));let a=xt([r,u.relativePath]),m=n.concat(u);i.children&&i.children.length>0&&(J(i.index!==!0,"Index routes must not have child routes. Please remove "+('all child routes from route path "'+a+'".')),Xc(i.children,t,m,a)),!(i.path==null&&!i.index)&&t.push({path:a,score:qp(a,i.index),routesMeta:m})};return e.forEach((i,o)=>{var s;if(i.path===""||!((s=i.path)!=null&&s.includes("?")))l(i,o);else for(let u of Gc(i.path))l(i,o,u)}),t}function Gc(e){let t=e.split("/");if(t.length===0)return[];let[n,...r]=t,l=n.endsWith("?"),i=n.replace(/\?$/,"");if(r.length===0)return l?[i,""]:[i];let o=Gc(r.join("/")),s=[];return s.push(...o.map(u=>u===""?i:[i,u].join("/"))),l&&s.push(...o),s.map(u=>e.startsWith("/")&&u===""?"/":u)}function Qp(e){e.sort((t,n)=>t.score!==n.score?n.score-t.score:bp(t.routesMeta.map(r=>r.childrenIndex),n.routesMeta.map(r=>r.childrenIndex)))}const Kp=/^:[\w-]+$/,Xp=3,Gp=2,Yp=1,Jp=10,Zp=-2,js=e=>e==="*";function qp(e,t){let n=e.split("/"),r=n.length;return n.some(js)&&(r+=Zp),t&&(r+=Gp),n.filter(l=>!js(l)).reduce((l,i)=>l+(Kp.test(i)?Xp:i===""?Yp:Jp),r)}function bp(e,t){return e.length===t.length&&e.slice(0,-1).every((r,l)=>r===t[l])?e[e.length-1]-t[t.length-1]:0}function eh(e,t,n){let{routesMeta:r}=e,l={},i="/",o=[];for(let s=0;s{let{paramName:v,isOptional:w}=m;if(v==="*"){let y=s[h]||"";o=i.slice(0,i.length-y.length).replace(/(.)\/+$/,"$1")}const g=s[h];return w&&!g?a[v]=void 0:a[v]=(g||"").replace(/%2F/g,"/"),a},{}),pathname:i,pathnameBase:o,pattern:e}}function th(e,t,n){t===void 0&&(t=!1),n===void 0&&(n=!0),fu(e==="*"||!e.endsWith("*")||e.endsWith("/*"),'Route path "'+e+'" will be treated as if it were '+('"'+e.replace(/\*$/,"/*")+'" because the `*` character must ')+"always follow a `/` in the pattern. To get rid of this warning, "+('please change the route path to "'+e.replace(/\*$/,"/*")+'".'));let r=[],l="^"+e.replace(/\/*\*?$/,"").replace(/^\/*/,"/").replace(/[\\.*+^${}|()[\]]/g,"\\$&").replace(/\/:([\w-]+)(\?)?/g,(o,s,u)=>(r.push({paramName:s,isOptional:u!=null}),u?"/?([^\\/]+)?":"/([^\\/]+)"));return e.endsWith("*")?(r.push({paramName:"*"}),l+=e==="*"||e==="/*"?"(.*)$":"(?:\\/(.+)|\\/*)$"):n?l+="\\/*$":e!==""&&e!=="/"&&(l+="(?:(?=\\/|$))"),[new RegExp(l,t?void 0:"i"),r]}function nh(e){try{return e.split("/").map(t=>decodeURIComponent(t).replace(/\//g,"%2F")).join("/")}catch(t){return fu(!1,'The URL path "'+e+'" could not be decoded because it is is a malformed URL segment. This is probably due to a bad percent '+("encoding ("+t+").")),e}}function Sn(e,t){if(t==="/")return e;if(!e.toLowerCase().startsWith(t.toLowerCase()))return null;let n=t.endsWith("/")?t.length-1:t.length,r=e.charAt(n);return r&&r!=="/"?null:e.slice(n)||"/"}const rh=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,lh=e=>rh.test(e);function ih(e,t){t===void 0&&(t="/");let{pathname:n,search:r="",hash:l=""}=typeof e=="string"?Cn(e):e,i;if(n)if(lh(n))i=n;else{if(n.includes("//")){let o=n;n=n.replace(/\/\/+/g,"/"),fu(!1,"Pathnames cannot have embedded double slashes - normalizing "+(o+" -> "+n))}n.startsWith("/")?i=Ps(n.substring(1),"/"):i=Ps(n,t)}else i=t;return{pathname:i,search:sh(r),hash:ah(l)}}function Ps(e,t){let n=t.replace(/\/+$/,"").split("/");return e.split("/").forEach(l=>{l===".."?n.length>1&&n.pop():l!=="."&&n.push(l)}),n.length>1?n.join("/"):"/"}function yi(e,t,n,r){return"Cannot include a '"+e+"' character in a manually specified "+("`to."+t+"` field ["+JSON.stringify(r)+"]. Please separate it out to the ")+("`to."+n+"` field. Alternatively you may provide the full path as ")+'a string in and the router will parse it for you.'}function oh(e){return e.filter((t,n)=>n===0||t.route.path&&t.route.path.length>0)}function Yc(e,t){let n=oh(e);return t?n.map((r,l)=>l===n.length-1?r.pathname:r.pathnameBase):n.map(r=>r.pathnameBase)}function Jc(e,t,n,r){r===void 0&&(r=!1);let l;typeof e=="string"?l=Cn(e):(l=pr({},e),J(!l.pathname||!l.pathname.includes("?"),yi("?","pathname","search",l)),J(!l.pathname||!l.pathname.includes("#"),yi("#","pathname","hash",l)),J(!l.search||!l.search.includes("#"),yi("#","search","hash",l)));let i=e===""||l.pathname==="",o=i?"/":l.pathname,s;if(o==null)s=n;else{let h=t.length-1;if(!r&&o.startsWith("..")){let v=o.split("/");for(;v[0]==="..";)v.shift(),h-=1;l.pathname=v.join("/")}s=h>=0?t[h]:"/"}let u=ih(l,s),a=o&&o!=="/"&&o.endsWith("/"),m=(i||o===".")&&n.endsWith("/");return!u.pathname.endsWith("/")&&(a||m)&&(u.pathname+="/"),u}const xt=e=>e.join("/").replace(/\/\/+/g,"/"),uh=e=>e.replace(/\/+$/,"").replace(/^\/*/,"/"),sh=e=>!e||e==="?"?"":e.startsWith("?")?e:"?"+e,ah=e=>!e||e==="#"?"":e.startsWith("#")?e:"#"+e;function ch(e){return e!=null&&typeof e.status=="number"&&typeof e.statusText=="string"&&typeof e.internal=="boolean"&&"data"in e}const Zc=["post","put","patch","delete"];new Set(Zc);const fh=["get",...Zc];new Set(fh);/** + * React Router v6.30.3 + * + * Copyright (c) Remix Software Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE.md file in the root directory of this source tree. + * + * @license MIT + */function hr(){return hr=Object.assign?Object.assign.bind():function(e){for(var t=1;t{s.current=!0}),S.useCallback(function(a,m){if(m===void 0&&(m={}),!s.current)return;if(typeof a=="number"){r.go(a);return}let h=Jc(a,JSON.parse(o),i,m.relative==="path");e==null&&t!=="/"&&(h.pathname=h.pathname==="/"?t:xt([t,h.pathname])),(m.replace?r.replace:r.push)(h,m.state,m)},[t,r,o,i,e])}function mh(){let{matches:e}=S.useContext(Lt),t=e[e.length-1];return t?t.params:{}}function Hl(e,t){let{relative:n}=t===void 0?{}:t,{future:r}=S.useContext(_t),{matches:l}=S.useContext(Lt),{pathname:i}=kr(),o=JSON.stringify(Yc(l,r.v7_relativeSplatPath));return S.useMemo(()=>Jc(e,JSON.parse(o),i,n==="path"),[e,o,i,n])}function vh(e,t){return gh(e,t)}function gh(e,t,n,r){Sr()||J(!1);let{navigator:l}=S.useContext(_t),{matches:i}=S.useContext(Lt),o=i[i.length-1],s=o?o.params:{};o&&o.pathname;let u=o?o.pathnameBase:"/";o&&o.route;let a=kr(),m;if(t){var h;let x=typeof t=="string"?Cn(t):t;u==="/"||(h=x.pathname)!=null&&h.startsWith(u)||J(!1),m=x}else m=a;let v=m.pathname||"/",w=v;if(u!=="/"){let x=u.replace(/^\//,"").split("/");w="/"+v.replace(/^\//,"").split("/").slice(x.length).join("/")}let g=Wp(e,{pathname:w}),y=xh(g&&g.map(x=>Object.assign({},x,{params:Object.assign({},s,x.params),pathname:xt([u,l.encodeLocation?l.encodeLocation(x.pathname).pathname:x.pathname]),pathnameBase:x.pathnameBase==="/"?u:xt([u,l.encodeLocation?l.encodeLocation(x.pathnameBase).pathname:x.pathnameBase])})),i,n,r);return t&&y?S.createElement(Wl.Provider,{value:{location:hr({pathname:"/",search:"",hash:"",state:null,key:"default"},m),navigationType:pt.Pop}},y):y}function yh(){let e=jh(),t=ch(e)?e.status+" "+e.statusText:e instanceof Error?e.message:JSON.stringify(e),n=e instanceof Error?e.stack:null,l={padding:"0.5rem",backgroundColor:"rgba(200,200,200, 0.5)"};return S.createElement(S.Fragment,null,S.createElement("h2",null,"Unexpected Application Error!"),S.createElement("h3",{style:{fontStyle:"italic"}},t),n?S.createElement("pre",{style:l},n):null,null)}const wh=S.createElement(yh,null);class Sh extends S.Component{constructor(t){super(t),this.state={location:t.location,revalidation:t.revalidation,error:t.error}}static getDerivedStateFromError(t){return{error:t}}static getDerivedStateFromProps(t,n){return n.location!==t.location||n.revalidation!=="idle"&&t.revalidation==="idle"?{error:t.error,location:t.location,revalidation:t.revalidation}:{error:t.error!==void 0?t.error:n.error,location:n.location,revalidation:t.revalidation||n.revalidation}}componentDidCatch(t,n){console.error("React Router caught the following error during render",t,n)}render(){return this.state.error!==void 0?S.createElement(Lt.Provider,{value:this.props.routeContext},S.createElement(bc.Provider,{value:this.state.error,children:this.props.component})):this.props.children}}function kh(e){let{routeContext:t,match:n,children:r}=e,l=S.useContext($l);return l&&l.static&&l.staticContext&&(n.route.errorElement||n.route.ErrorBoundary)&&(l.staticContext._deepestRenderedBoundaryId=n.route.id),S.createElement(Lt.Provider,{value:t},r)}function xh(e,t,n,r){var l;if(t===void 0&&(t=[]),n===void 0&&(n=null),r===void 0&&(r=null),e==null){var i;if(!n)return null;if(n.errors)e=n.matches;else if((i=r)!=null&&i.v7_partialHydration&&t.length===0&&!n.initialized&&n.matches.length>0)e=n.matches;else return null}let o=e,s=(l=n)==null?void 0:l.errors;if(s!=null){let m=o.findIndex(h=>h.route.id&&(s==null?void 0:s[h.route.id])!==void 0);m>=0||J(!1),o=o.slice(0,Math.min(o.length,m+1))}let u=!1,a=-1;if(n&&r&&r.v7_partialHydration)for(let m=0;m=0?o=o.slice(0,a+1):o=[o[0]];break}}}return o.reduceRight((m,h,v)=>{let w,g=!1,y=null,x=null;n&&(w=s&&h.route.id?s[h.route.id]:void 0,y=h.route.errorElement||wh,u&&(a<0&&v===0?(_h("route-fallback"),g=!0,x=null):a===v&&(g=!0,x=h.route.hydrateFallbackElement||null)));let d=t.concat(o.slice(0,v+1)),c=()=>{let p;return w?p=y:g?p=x:h.route.Component?p=S.createElement(h.route.Component,null):h.route.element?p=h.route.element:p=m,S.createElement(kh,{match:h,routeContext:{outlet:m,matches:d,isDataRoute:n!=null},children:p})};return n&&(h.route.ErrorBoundary||h.route.errorElement||v===0)?S.createElement(Sh,{location:n.location,revalidation:n.revalidation,component:y,error:w,children:c(),routeContext:{outlet:null,matches:d,isDataRoute:!0}}):c()},null)}var tf=function(e){return e.UseBlocker="useBlocker",e.UseRevalidator="useRevalidator",e.UseNavigateStable="useNavigate",e}(tf||{}),nf=function(e){return e.UseBlocker="useBlocker",e.UseLoaderData="useLoaderData",e.UseActionData="useActionData",e.UseRouteError="useRouteError",e.UseNavigation="useNavigation",e.UseRouteLoaderData="useRouteLoaderData",e.UseMatches="useMatches",e.UseRevalidator="useRevalidator",e.UseNavigateStable="useNavigate",e.UseRouteId="useRouteId",e}(nf||{});function Eh(e){let t=S.useContext($l);return t||J(!1),t}function Ch(e){let t=S.useContext(qc);return t||J(!1),t}function Nh(e){let t=S.useContext(Lt);return t||J(!1),t}function rf(e){let t=Nh(),n=t.matches[t.matches.length-1];return n.route.id||J(!1),n.route.id}function jh(){var e;let t=S.useContext(bc),n=Ch(),r=rf();return t!==void 0?t:(e=n.errors)==null?void 0:e[r]}function Ph(){let{router:e}=Eh(tf.UseNavigateStable),t=rf(nf.UseNavigateStable),n=S.useRef(!1);return ef(()=>{n.current=!0}),S.useCallback(function(l,i){i===void 0&&(i={}),n.current&&(typeof l=="number"?e.navigate(l):e.navigate(l,hr({fromRouteId:t},i)))},[e,t])}const _s={};function _h(e,t,n){_s[e]||(_s[e]=!0)}function Lh(e,t){e==null||e.v7_startTransition,e==null||e.v7_relativeSplatPath}function br(e){J(!1)}function Th(e){let{basename:t="/",children:n=null,location:r,navigationType:l=pt.Pop,navigator:i,static:o=!1,future:s}=e;Sr()&&J(!1);let u=t.replace(/^\/*/,"/"),a=S.useMemo(()=>({basename:u,navigator:i,static:o,future:hr({v7_relativeSplatPath:!1},s)}),[u,s,i,o]);typeof r=="string"&&(r=Cn(r));let{pathname:m="/",search:h="",hash:v="",state:w=null,key:g="default"}=r,y=S.useMemo(()=>{let x=Sn(m,u);return x==null?null:{location:{pathname:x,search:h,hash:v,state:w,key:g},navigationType:l}},[u,m,h,v,w,g,l]);return y==null?null:S.createElement(_t.Provider,{value:a},S.createElement(Wl.Provider,{children:n,value:y}))}function Rh(e){let{children:t,location:n}=e;return vh(ho(t),n)}new Promise(()=>{});function ho(e,t){t===void 0&&(t=[]);let n=[];return S.Children.forEach(e,(r,l)=>{if(!S.isValidElement(r))return;let i=[...t,l];if(r.type===S.Fragment){n.push.apply(n,ho(r.props.children,i));return}r.type!==br&&J(!1),!r.props.index||!r.props.children||J(!1);let o={id:r.props.id||i.join("-"),caseSensitive:r.props.caseSensitive,element:r.props.element,Component:r.props.Component,index:r.props.index,path:r.props.path,loader:r.props.loader,action:r.props.action,errorElement:r.props.errorElement,ErrorBoundary:r.props.ErrorBoundary,hasErrorBoundary:r.props.ErrorBoundary!=null||r.props.errorElement!=null,shouldRevalidate:r.props.shouldRevalidate,handle:r.props.handle,lazy:r.props.lazy};r.props.children&&(o.children=ho(r.props.children,i)),n.push(o)}),n}/** + * React Router DOM v6.30.3 + * + * Copyright (c) Remix Software Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE.md file in the root directory of this source tree. + * + * @license MIT + */function Nl(){return Nl=Object.assign?Object.assign.bind():function(e){for(var t=1;t=0)&&(n[l]=e[l]);return n}function zh(e){return!!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}function Oh(e,t){return e.button===0&&(!t||t==="_self")&&!zh(e)}const Ih=["onClick","relative","reloadDocument","replace","state","target","to","preventScrollReset","viewTransition"],Mh=["aria-current","caseSensitive","className","end","style","to","viewTransition","children"],Dh="6";try{window.__reactRouterVersion=Dh}catch{}const Fh=S.createContext({isTransitioning:!1}),Uh="startTransition",Ls=_f[Uh];function Ah(e){let{basename:t,children:n,future:r,window:l}=e,i=S.useRef();i.current==null&&(i.current=Bp({window:l,v5Compat:!0}));let o=i.current,[s,u]=S.useState({action:o.action,location:o.location}),{v7_startTransition:a}=r||{},m=S.useCallback(h=>{a&&Ls?Ls(()=>u(h)):u(h)},[u,a]);return S.useLayoutEffect(()=>o.listen(m),[o,m]),S.useEffect(()=>Lh(r),[r]),S.createElement(Th,{basename:t,children:n,location:s.location,navigationType:s.action,navigator:o,future:r})}const Bh=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",Vh=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,Ql=S.forwardRef(function(t,n){let{onClick:r,relative:l,reloadDocument:i,replace:o,state:s,target:u,to:a,preventScrollReset:m,viewTransition:h}=t,v=lf(t,Ih),{basename:w}=S.useContext(_t),g,y=!1;if(typeof a=="string"&&Vh.test(a)&&(g=a,Bh))try{let p=new URL(window.location.href),k=a.startsWith("//")?new URL(p.protocol+a):new URL(a),C=Sn(k.pathname,w);k.origin===p.origin&&C!=null?a=C+k.search+k.hash:y=!0}catch{}let x=dh(a,{relative:l}),d=Wh(a,{replace:o,state:s,target:u,preventScrollReset:m,relative:l,viewTransition:h});function c(p){r&&r(p),p.defaultPrevented||d(p)}return S.createElement("a",Nl({},v,{href:g||x,onClick:y||i?r:c,ref:n,target:u}))}),Ts=S.forwardRef(function(t,n){let{"aria-current":r="page",caseSensitive:l=!1,className:i="",end:o=!1,style:s,to:u,viewTransition:a,children:m}=t,h=lf(t,Mh),v=Hl(u,{relative:h.relative}),w=kr(),g=S.useContext(qc),{navigator:y,basename:x}=S.useContext(_t),d=g!=null&&Hh(v)&&a===!0,c=y.encodeLocation?y.encodeLocation(v).pathname:v.pathname,p=w.pathname,k=g&&g.navigation&&g.navigation.location?g.navigation.location.pathname:null;l||(p=p.toLowerCase(),k=k?k.toLowerCase():null,c=c.toLowerCase()),k&&x&&(k=Sn(k,x)||k);const C=c!=="/"&&c.endsWith("/")?c.length-1:c.length;let P=p===c||!o&&p.startsWith(c)&&p.charAt(C)==="/",_=k!=null&&(k===c||!o&&k.startsWith(c)&&k.charAt(c.length)==="/"),L={isActive:P,isPending:_,isTransitioning:d},A=P?r:void 0,R;typeof i=="function"?R=i(L):R=[i,P?"active":null,_?"pending":null,d?"transitioning":null].filter(Boolean).join(" ");let G=typeof s=="function"?s(L):s;return S.createElement(Ql,Nl({},h,{"aria-current":A,className:R,ref:n,style:G,to:u,viewTransition:a}),typeof m=="function"?m(L):m)});var mo;(function(e){e.UseScrollRestoration="useScrollRestoration",e.UseSubmit="useSubmit",e.UseSubmitFetcher="useSubmitFetcher",e.UseFetcher="useFetcher",e.useViewTransitionState="useViewTransitionState"})(mo||(mo={}));var Rs;(function(e){e.UseFetcher="useFetcher",e.UseFetchers="useFetchers",e.UseScrollRestoration="useScrollRestoration"})(Rs||(Rs={}));function $h(e){let t=S.useContext($l);return t||J(!1),t}function Wh(e,t){let{target:n,replace:r,state:l,preventScrollReset:i,relative:o,viewTransition:s}=t===void 0?{}:t,u=ph(),a=kr(),m=Hl(e,{relative:o});return S.useCallback(h=>{if(Oh(h,n)){h.preventDefault();let v=r!==void 0?r:Cl(a)===Cl(m);u(e,{replace:v,state:l,preventScrollReset:i,relative:o,viewTransition:s})}},[a,u,m,r,l,n,e,i,o,s])}function Hh(e,t){t===void 0&&(t={});let n=S.useContext(Fh);n==null&&J(!1);let{basename:r}=$h(mo.useViewTransitionState),l=Hl(e,{relative:t.relative});if(!n.isTransitioning)return!1;let i=Sn(n.currentLocation.pathname,r)||n.currentLocation.pathname,o=Sn(n.nextLocation.pathname,r)||n.nextLocation.pathname;return po(l.pathname,o)!=null||po(l.pathname,i)!=null}const of=S.createContext(null);function zs(){try{return localStorage.getItem("authToken")||""}catch{return""}}function Br(e){try{e?localStorage.setItem("authToken",e):localStorage.removeItem("authToken")}catch{}}function Qh({children:e}){const[t,n]=S.useState(zs),[r,l]=S.useState(null),[i,o]=S.useState(!!zs()),[s,u]=S.useState(null);S.useEffect(()=>{if(!t){l(null),o(!1),u(null);return}let g=!1;return o(!0),fetch("/api/auth/me",{headers:{Authorization:`Bearer ${t}`}}).then(async y=>{const x=await y.json().catch(()=>({}));if(!y.ok)throw new Error(x.error||"Kon sessie niet verifiëren.");g||(l(x.user||null),u(null))}).catch(()=>{g||(l(null),n(""),Br(""))}).finally(()=>{g||o(!1)}),()=>{g=!0}},[t]);async function a(g){u(null);const y=await fetch("/api/auth/login",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(g)}),x=await y.json().catch(()=>({}));if(!y.ok)throw new Error(x.error||"Login mislukt.");return n(x.token),Br(x.token),l(x.user),x.user}async function m(g){u(null);const y=await fetch("/api/auth/register",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(g)}),x=await y.json().catch(()=>({}));if(!y.ok)throw new Error(x.error||"Registratie mislukt.");return n(x.token),Br(x.token),l(x.user),x.user}function h(){n(""),Br(""),l(null)}const v=S.useMemo(()=>(g,y={})=>{const x={...y.headers||{},...t?{Authorization:`Bearer ${t}`}:{}};return fetch(g,{...y,headers:x})},[t]),w={user:r,token:t,loading:i,error:s,login:a,register:m,logout:h,authFetch:v};return f.jsx(of.Provider,{value:w,children:e})}function uf(){const e=S.useContext(of);if(!e)throw new Error("useAuth moet binnen een AuthProvider gebruikt worden");return e}function Kh(){const e=({isActive:r})=>r?"nav-link active":"nav-link",{user:t,logout:n}=uf();return f.jsxs("nav",{className:"site-nav",children:[f.jsx(Ql,{className:"nav-logo",to:"/",children:"Siti Plugin Repo"}),f.jsxs("div",{className:"nav-links",children:[f.jsx(Ts,{to:"/",end:!0,className:e,children:"Plugins"}),f.jsx(Ts,{to:"/licenses",className:e,children:"Licenties"})]}),f.jsx("div",{className:"nav-user",children:t?f.jsxs(f.Fragment,{children:[f.jsxs("span",{className:"nav-user-name",children:["Hallo, ",t.name]}),f.jsx("button",{className:"ghost ghost-small",type:"button",onClick:n,children:"Uitloggen"})]}):f.jsx("span",{className:"nav-user-guest",children:"Niet ingelogd"})})]})}function Xh(){const[e,t]=S.useState([]),[n,r]=S.useState(!0),[l,i]=S.useState(null),[o,s]=S.useState(null);return S.useEffect(()=>{async function u(){try{const a=await fetch("/api/plugins");if(!a.ok)throw new Error("Kon plugins niet laden");const m=await a.json();t(m.items||[]),s(m.updatedAt)}catch{i("Laden van GitHub data is mislukt.")}finally{r(!1)}}u()},[]),f.jsxs("div",{className:"page",children:[f.jsxs("header",{className:"hero",children:[f.jsxs("div",{children:[f.jsx("p",{className:"eyebrow",children:"WordPress plugin overzicht"}),f.jsx("h1",{children:"Siti Plugin Repo"}),f.jsx("p",{className:"subtitle",children:"Al je publieke WordPress plugins op één plek."})]}),f.jsx("a",{className:"cta",href:"https://github.com/SitiWeb",target:"_blank",rel:"noreferrer",children:"GitHub SitiWeb"})]}),f.jsxs("section",{className:"grid",children:[n&&f.jsx("div",{className:"state",children:"Bezig met laden…"}),l&&f.jsx("div",{className:"state error",children:l}),!n&&!l&&e.length===0&&f.jsx("div",{className:"state",children:"Geen repositories gevonden."}),e.map(u=>{var h,v;const a=((h=u.manifest)==null?void 0:h.plugin_name)||u.name,m=((v=u.manifest)==null?void 0:v.description)||u.description;return f.jsxs("article",{className:"card",children:[f.jsxs("div",{className:"card-header",children:[f.jsx("h2",{children:a}),f.jsx("span",{className:"pill",children:u.fullName})]}),f.jsx("p",{children:m}),f.jsxs("div",{className:"meta",children:[f.jsxs("span",{children:["★ ",u.stars]}),f.jsxs("span",{children:["Forks ",u.forks]}),f.jsxs("span",{children:["Issues ",u.issues]})]}),u.topics.length>0&&f.jsx("div",{className:"topics",children:u.topics.slice(0,4).map(w=>f.jsx("span",{className:"topic",children:w},w))}),f.jsxs("div",{className:"actions",children:[f.jsx(Ql,{className:"link",to:`/plugin/${u.fullName}`,children:"Bekijk details →"}),f.jsx("a",{className:"ghost",href:u.repoUrl,target:"_blank",rel:"noreferrer",children:"GitHub"})]})]},u.fullName)})]}),f.jsx("footer",{className:"footer",children:f.jsxs("span",{children:["Laatste sync: ",o?new Date(o).toLocaleString("nl-NL"):"-"]})})]})}function Gh(){const{owner:e,repo:t}=mh(),[n,r]=S.useState(null),[l,i]=S.useState(!0),[o,s]=S.useState(null);S.useEffect(()=>{async function y(){try{const x=await fetch(`/api/plugins/${e}/${t}`);if(!x.ok)throw new Error("Kon details niet laden");const d=await x.json();r(d)}catch{s("Laden van plugin details is mislukt.")}finally{i(!1)}}y()},[e,t]);const u=n==null?void 0:n.manifest,a=(u==null?void 0:u.plugin_name)||(n==null?void 0:n.name)||t,m=(u==null?void 0:u.description)||(n==null?void 0:n.description),h=(u==null?void 0:u.author)||"-",v=(u==null?void 0:u.version)||"-",w=S.useMemo(()=>(n==null?void 0:n.releases)||[],[n]),g=S.useMemo(()=>(n==null?void 0:n.commits)||[],[n]);return f.jsxs("div",{className:"page",children:[f.jsxs("header",{className:"detail-hero",children:[f.jsxs("div",{children:[f.jsx("p",{className:"eyebrow",children:"Plugin details"}),f.jsx("h1",{children:a}),f.jsx("p",{className:"subtitle",children:m})]}),f.jsxs("div",{className:"detail-actions",children:[f.jsx(Ql,{className:"ghost",to:"/",children:"← Terug"}),(n==null?void 0:n.repoUrl)&&f.jsx("a",{className:"cta",href:n.repoUrl,target:"_blank",rel:"noreferrer",children:"GitHub"})]})]}),l&&f.jsx("div",{className:"state",children:"Bezig met laden…"}),o&&f.jsx("div",{className:"state error",children:o}),!l&&!o&&n&&f.jsxs("section",{className:"detail-grid",children:[f.jsxs("div",{className:"card",children:[f.jsx("h2",{children:"Manifest"}),f.jsxs("div",{className:"detail-list",children:[f.jsxs("div",{children:[f.jsx("span",{children:"Naam"}),f.jsx("strong",{children:a})]}),f.jsxs("div",{children:[f.jsx("span",{children:"Versie"}),f.jsx("strong",{children:v})]}),f.jsxs("div",{children:[f.jsx("span",{children:"Auteur"}),f.jsx("strong",{children:h})]}),f.jsxs("div",{children:[f.jsx("span",{children:"Repository"}),f.jsx("strong",{children:n.fullName})]})]}),(u==null?void 0:u.author_url)&&f.jsx("a",{className:"link",href:u.author_url,target:"_blank",rel:"noreferrer",children:"Auteur website →"})]}),f.jsxs("div",{className:"card",children:[f.jsx("h2",{children:"Releases"}),w.length===0&&f.jsx("p",{children:"Geen releases gevonden."}),f.jsx("ul",{className:"list",children:w.map(y=>f.jsxs("li",{children:[f.jsx("a",{href:y.url,target:"_blank",rel:"noreferrer",children:y.name}),f.jsx("span",{children:y.publishedAt?new Date(y.publishedAt).toLocaleDateString("nl-NL"):"-"})]},y.tag))})]}),f.jsxs("div",{className:"card",children:[f.jsx("h2",{children:"Recente commits"}),g.length===0&&f.jsx("p",{children:"Geen commits gevonden."}),f.jsx("ul",{className:"list",children:g.map(y=>{var x;return f.jsxs("li",{children:[f.jsx("a",{href:y.url,target:"_blank",rel:"noreferrer",children:((x=y.message)==null?void 0:x.split(` +`)[0])||y.sha.slice(0,7)}),f.jsx("span",{children:y.author||"-"})]},y.sha)})})]})]})]})}const sf="nl-NL";function vo(e,t=sf){return e?new Date(e).toLocaleString(t):"-"}function Yh(e,t=sf){return e?new Date(e).toLocaleDateString(t):"-"}function Jh({license:e}){const t=e.hostnames||[],n=e.primaryHostname||"Nog niet gekoppeld";return f.jsxs("article",{className:"card license-card",children:[f.jsxs("div",{className:"license-card-header",children:[f.jsxs("div",{children:[f.jsx("h3",{children:e.pluginName||e.label||"Licentie"}),f.jsx("p",{className:"license-subtitle",children:e.repoFullName||"-"})]}),f.jsx("span",{className:"pill",children:e.key})]}),f.jsxs("div",{className:"detail-list license-detail-list",children:[f.jsxs("div",{children:[f.jsx("span",{children:"Versie"}),f.jsx("strong",{children:e.pluginVersion||"-"})]}),f.jsxs("div",{children:[f.jsx("span",{children:"Hostname"}),f.jsx("strong",{children:n})]}),f.jsxs("div",{children:[f.jsx("span",{children:"Aangemaakt"}),f.jsx("strong",{children:Yh(e.createdAt)})]}),f.jsxs("div",{children:[f.jsx("span",{children:"Laatste check"}),f.jsx("strong",{children:vo(e.lastVersionCheckAt)})]})]}),e.note&&f.jsxs("p",{className:"license-note",children:["Notitie: ",e.note]}),t.length>0&&f.jsxs("div",{className:"host-list",children:[f.jsx("p",{className:"hint",children:"Hostnames"}),f.jsx("ul",{children:t.map(r=>f.jsxs("li",{children:[f.jsxs("div",{children:[f.jsx("strong",{children:r.hostname}),f.jsxs("span",{children:[r.hits||0," checks"]})]}),f.jsx("span",{children:vo(r.lastSeenAt)})]},`${r.hostname}-${r.firstSeenAt||r.lastSeenAt}`))})]}),f.jsxs("div",{className:"license-links",children:[e.repoUrl&&f.jsx("a",{className:"link",href:e.repoUrl,target:"_blank",rel:"noreferrer",children:"Repository →"}),e.pluginName&&f.jsx("span",{className:"ghost-pill",children:e.pluginName})]})]})}function Zh(){var pu;const{user:e,token:t,authFetch:n,login:r,register:l,loading:i}=uf(),[o,s]=S.useState([]),[u,a]=S.useState([]),[m,h]=S.useState(""),[v,w]=S.useState(""),[g,y]=S.useState(""),[x,d]=S.useState(!0),[c,p]=S.useState(null),[k,C]=S.useState(!1),[P,_]=S.useState(!1),[L,A]=S.useState(null),[R,G]=S.useState(null),[fe,Be]=S.useState(null),[Nn,xr]=S.useState(!1),[Tt,jn]=S.useState(""),[N,z]=S.useState(""),O=!!(e&&t);S.useEffect(()=>{let T=!1;async function H(){var Z;d(!0),p(null);try{const Ve=await fetch("/api/plugins"),Ye=await Ve.json().catch(()=>({}));if(!Ve.ok)throw new Error(Ye.error||"Kon plugins niet laden.");if(T)return;a(Ye.items||[]);const _n=(Z=Ye.items)==null?void 0:Z[0];if(_n){const af=_n.ownerRepo||_n.fullName;h(cf=>cf||af)}}catch(Ve){T||p(Ve.message||"Kon plugins niet laden.")}finally{T||d(!1)}}return H(),()=>{T=!0}},[]);const D=S.useCallback(async(T=!0)=>{if(!t){s([]),A(null),T&&G({variant:"error",message:"Log in om licenties te beheren."});return}T&&G(null),_(!0);try{const H=await n("/api/licenses"),Z=await H.json().catch(()=>({}));if(H.status===401)throw new Error("Sessie verlopen, log opnieuw in.");if(!H.ok)throw new Error(Z.error||"Kon licenties niet laden.");s(Z.items||[]),A(Z.updatedAt)}catch(H){T&&G({variant:"error",message:H.message})}finally{_(!1)}},[n,t]);S.useEffect(()=>{D(!1)},[D]),S.useEffect(()=>{if(!m&&u.length>0){const T=u[0].ownerRepo||u[0].fullName;h(T)}},[u,m]);const U=S.useMemo(()=>u.find(T=>(T.ownerRepo||T.fullName)===m)||null,[u,m]),Rt=S.useMemo(()=>{const T=H=>H?new Date(H).getTime():0;return[...o].sort((H,Z)=>T(Z.createdAt)-T(H.createdAt))},[o]);async function Xe(T){var H;if(T.preventDefault(),G(null),!O){G({variant:"error",message:"Log in om een licentie aan te maken."});return}if(!U){G({variant:"error",message:"Selecteer een plugin."});return}C(!0);try{const Z={label:v.trim()||((H=U.manifest)==null?void 0:H.plugin_name)||U.name||U.fullName,note:g.trim()||void 0,repo:{repo:U.ownerRepo||U.fullName,provider:U.provider||"github",baseUrl:U.baseUrl}},Ve=await n("/api/licenses",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Z)}),Ye=await Ve.json().catch(()=>({}));if(Ve.status===401)throw new Error("Sessie verlopen, log opnieuw in.");if(!Ve.ok)throw new Error(Ye.error||"Licentie aanmaken mislukt.");s(_n=>[Ye,..._n]),G({variant:"success",message:"Licentie aangemaakt."}),w(""),y("")}catch(Z){G({variant:"error",message:Z.message})}finally{C(!1)}}async function Pn(T){if(T.preventDefault(),Be(null),!Tt.trim()||!N.trim()){Be({ok:!1,message:"Vul zowel licentiecode als hostname in."});return}xr(!0);try{const H=await fetch("/api/licenses/verify",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:Tt.trim(),hostname:N.trim()})}),Z=await H.json().catch(()=>({}));if(!H.ok)throw new Error(Z.error||"Controle mislukt.");Be({ok:!0,data:Z}),Z.license&&s(Ve=>Ve.map(Ye=>Ye.key===Z.license.key?Z.license:Ye))}catch(H){Be({ok:!1,message:H.message})}finally{xr(!1)}}const Ge=S.useCallback(async T=>{await r(T),await D(!1)},[r,D]),Kt=S.useCallback(async T=>{await l(T),await D(!1)},[l,D]),du=x||i&&!!t;return f.jsxs("div",{className:"page",children:[f.jsxs("header",{className:"hero",children:[f.jsxs("div",{children:[f.jsx("p",{className:"eyebrow",children:"Licentiebeheer"}),f.jsx("h1",{children:"Licenties"}),f.jsx("p",{className:"subtitle",children:"Maak licenties voor iedere plugin en beheer welke hostname de licentie daadwerkelijk gebruikt."}),f.jsx("p",{className:"hint",children:"Een licentie is geldig voor één hostname. De eerste hostname die controleert wordt automatisch gekoppeld als licentiehouder."})]}),f.jsx("button",{className:"ghost",type:"button",onClick:()=>D(),disabled:P||!O,children:P?"Vernieuwen…":"Vernieuw lijst"})]}),f.jsxs("div",{className:"license-meta-bar",children:[f.jsxs("span",{children:["Actieve licenties: ",o.length]}),f.jsxs("span",{children:["Laatste update: ",vo(L)]}),e&&f.jsxs("span",{children:["Ingelogd als: ",e.email]})]}),du&&f.jsx("div",{className:"state",children:"Bezig met laden…"}),c&&f.jsx("div",{className:"state error",children:c}),!du&&!c&&f.jsxs(f.Fragment,{children:[f.jsxs("section",{className:"license-forms",children:[O?f.jsxs("article",{className:"card",children:[f.jsx("h2",{children:"Nieuwe licentie"}),f.jsx("p",{className:"hint",children:"Kies een plugin en genereer direct een licentiesleutel."}),f.jsxs("form",{className:"form-grid",onSubmit:Xe,children:[f.jsxs("label",{className:"field",children:[f.jsx("span",{children:"Plugin"}),f.jsx("select",{value:m,onChange:T=>h(T.target.value),disabled:u.length===0,children:u.map(T=>{var Z;const H=T.ownerRepo||T.fullName;return f.jsxs("option",{value:H,children:[((Z=T.manifest)==null?void 0:Z.plugin_name)||T.name," (",T.fullName,")"]},H)})})]}),f.jsxs("label",{className:"field",children:[f.jsx("span",{children:"Label (optioneel)"}),f.jsx("input",{value:v,onChange:T=>w(T.target.value),placeholder:"Naam of klant"})]}),f.jsxs("label",{className:"field",children:[f.jsx("span",{children:"Notitie"}),f.jsx("textarea",{value:g,onChange:T=>y(T.target.value),placeholder:"Bijv. contactpersoon of extra info",rows:3})]}),f.jsx("button",{className:"cta",type:"submit",disabled:k||!U,children:k?"Aanmaken…":"Licentie aanmaken"})]}),R&&f.jsx("div",{className:`state inline ${R.variant==="error"?"error":"success"}`,children:R.message})]}):f.jsx(qh,{onLogin:Ge,onRegister:Kt}),f.jsxs("article",{className:"card",children:[f.jsx("h2",{children:"Test of valideer"}),f.jsx("p",{className:"hint",children:"Gebruik dit formulier zoals de plugin dat zou doen om de huidige versie en hostname te controleren."}),f.jsxs("form",{className:"form-grid",onSubmit:Pn,children:[f.jsxs("label",{className:"field",children:[f.jsx("span",{children:"Licentiecode"}),f.jsx("input",{value:Tt,onChange:T=>jn(T.target.value),placeholder:"SITI-XXXX-XXXX"})]}),f.jsxs("label",{className:"field",children:[f.jsx("span",{children:"Hostname"}),f.jsx("input",{value:N,onChange:T=>z(T.target.value),placeholder:"voorbeeld.nl"})]}),f.jsx("button",{className:"ghost",type:"submit",disabled:Nn,children:Nn?"Controleren…":"Controleer licentie"})]}),fe&&fe.ok&&((pu=fe.data)==null?void 0:pu.license)&&f.jsxs("div",{className:"state success inline",children:[f.jsx("strong",{children:"Licentie geldig"}),f.jsxs("p",{children:[fe.data.license.pluginName||"Plugin"," — versie ",fe.data.license.pluginVersion||"-"]}),f.jsxs("p",{children:["Gekoppeld aan: ",f.jsx("strong",{children:fe.data.license.primaryHostname||"Nog niet gekoppeld"})]})]}),fe&&!fe.ok&&f.jsx("div",{className:"state error inline",children:fe.message})]})]}),O?f.jsx("section",{className:"license-grid",children:Rt.length===0?f.jsx("div",{className:"state",children:"Nog geen licenties aangemaakt."}):Rt.map(T=>f.jsx(Jh,{license:T},T.id||T.key))}):f.jsx("div",{className:"state",children:"Log in of registreer om licenties te bekijken en te beheren."})]})]})}function qh({onLogin:e,onRegister:t}){const[n,r]=S.useState("login"),[l,i]=S.useState({identifier:"",password:""}),[o,s]=S.useState({username:"",name:"",email:"",password:""}),[u,a]=S.useState(null),[m,h]=S.useState(!1);async function v(w){w.preventDefault(),a(null),h(!0);try{n==="login"?(await e(l),a({variant:"success",message:"Succesvol ingelogd."})):(await t(o),a({variant:"success",message:"Account aangemaakt en ingelogd."}))}catch(g){a({variant:"error",message:g.message||"Actie mislukt."})}finally{h(!1)}}return f.jsxs("article",{className:"card auth-card",children:[f.jsxs("div",{className:"auth-tabs",children:[f.jsx("button",{type:"button",className:n==="login"?"auth-tab active":"auth-tab",onClick:()=>r("login"),disabled:m,children:"Inloggen"}),f.jsx("button",{type:"button",className:n==="register"?"auth-tab active":"auth-tab",onClick:()=>r("register"),disabled:m,children:"Registreren"})]}),f.jsxs("form",{className:"form-grid",onSubmit:v,children:[n==="login"?f.jsxs(f.Fragment,{children:[f.jsxs("label",{className:"field",children:[f.jsx("span",{children:"Gebruikersnaam of e-mail"}),f.jsx("input",{value:l.identifier,onChange:w=>i(g=>({...g,identifier:w.target.value})),placeholder:"jouwnaam of mail"})]}),f.jsxs("label",{className:"field",children:[f.jsx("span",{children:"Wachtwoord"}),f.jsx("input",{type:"password",value:l.password,onChange:w=>i(g=>({...g,password:w.target.value})),placeholder:"••••••••"})]})]}):f.jsxs(f.Fragment,{children:[f.jsxs("label",{className:"field",children:[f.jsx("span",{children:"Gebruikersnaam"}),f.jsx("input",{value:o.username,onChange:w=>s(g=>({...g,username:w.target.value})),placeholder:"gebruikersnaam"})]}),f.jsxs("label",{className:"field",children:[f.jsx("span",{children:"Naam"}),f.jsx("input",{value:o.name,onChange:w=>s(g=>({...g,name:w.target.value})),placeholder:"Volledige naam"})]}),f.jsxs("label",{className:"field",children:[f.jsx("span",{children:"E-mailadres"}),f.jsx("input",{type:"email",value:o.email,onChange:w=>s(g=>({...g,email:w.target.value})),placeholder:"naam@bedrijf.nl"})]}),f.jsxs("label",{className:"field",children:[f.jsx("span",{children:"Wachtwoord"}),f.jsx("input",{type:"password",value:o.password,onChange:w=>s(g=>({...g,password:w.target.value})),placeholder:"Minimaal 8 karakters"})]})]}),f.jsx("button",{className:"cta",type:"submit",disabled:m,children:m?"Verwerken…":n==="login"?"Inloggen":"Registreren"})]}),u&&f.jsx("div",{className:`state inline ${u.variant==="error"?"error":"success"}`,children:u.message})]})}function bh(){return f.jsxs("div",{className:"app",children:[f.jsx(Kh,{}),f.jsxs(Rh,{children:[f.jsx(br,{path:"/",element:f.jsx(Xh,{})}),f.jsx(br,{path:"/plugin/:owner/:repo",element:f.jsx(Gh,{})}),f.jsx(br,{path:"/licenses",element:f.jsx(Zh,{})})]})]})}Kc(document.getElementById("root")).render(f.jsx(Ws.StrictMode,{children:f.jsx(Ah,{children:f.jsx(Qh,{children:f.jsx(bh,{})})})})); diff --git a/dist/assets/index-CgskK80a.css b/dist/assets/index-CgskK80a.css new file mode 100644 index 0000000..8af0a6a --- /dev/null +++ b/dist/assets/index-CgskK80a.css @@ -0,0 +1 @@ +:root{color-scheme:light dark}.app{min-height:100vh;background:radial-gradient(circle at top,#f5f7ff,#fff 45%);color:#0f172a;font-family:Inter,system-ui,sans-serif;padding:48px 8vw 64px}.site-nav{display:flex;align-items:center;justify-content:space-between;gap:16px;margin-bottom:32px;flex-wrap:wrap}.nav-logo{font-weight:700;color:inherit;text-decoration:none;font-size:1.1rem}.nav-links{display:flex;gap:12px}.nav-user{display:flex;align-items:center;gap:8px;font-size:.9rem;color:#475569}.nav-user-name{font-weight:600}.nav-user-guest{color:#94a3b8;font-size:.85rem}.nav-link{padding:8px 16px;border-radius:999px;border:1px solid transparent;text-decoration:none;color:#475569;font-weight:600}.nav-link.active{background:#eef2ff;color:#4338ca;border-color:#c7d2fe}.page{display:flex;flex-direction:column;gap:32px}.hero{display:flex;align-items:center;justify-content:space-between;gap:24px;margin-bottom:48px;flex-wrap:wrap}.eyebrow{text-transform:uppercase;letter-spacing:.2em;font-size:12px;color:#6366f1;font-weight:600;margin:0 0 8px}.hero h1{font-size:clamp(2.4rem,4vw,3.4rem);margin:0 0 8px}.subtitle{margin:0;font-size:1.1rem;color:#475569;max-width:520px}.hint{margin:8px 0 0;font-size:.9rem;color:#64748b}.cta{background:#4f46e5;color:#fff;padding:12px 20px;border-radius:999px;text-decoration:none;font-weight:600;box-shadow:0 8px 24px #4f46e533;transition:transform .2s ease,box-shadow .2s ease;display:inline-flex;align-items:center;justify-content:center;border:none;cursor:pointer}.cta:hover{transform:translateY(-2px);box-shadow:0 12px 30px #4f46e54d}.ghost{border:1px solid #c7d2fe;color:#4338ca;padding:8px 14px;border-radius:999px;text-decoration:none;font-weight:600;display:inline-flex;align-items:center;justify-content:center;gap:8px;background:transparent;cursor:pointer}.ghost-small{padding:6px 12px;font-size:.85rem}.grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(240px,1fr));gap:20px}.actions{display:flex;align-items:center;gap:12px;margin-top:auto}.card{background:#fff;border-radius:20px;padding:24px;box-shadow:0 12px 30px #0f172a14;display:flex;flex-direction:column;gap:12px}.card-header{display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap}.card h2{margin:0;font-size:1.3rem}.card p{margin:0;color:#475569}.pill{background:#eef2ff;color:#4338ca;font-size:.75rem;font-weight:600;padding:4px 10px;border-radius:999px}.meta{display:flex;gap:12px;font-size:.9rem;color:#64748b}.topics{display:flex;flex-wrap:wrap;gap:8px}.topic{background:#f1f5f9;color:#475569;font-size:.75rem;padding:4px 8px;border-radius:999px}.link{color:#4f46e5;font-weight:600;text-decoration:none}.state{background:#fff;border-radius:16px;padding:20px;box-shadow:0 10px 20px #0f172a14;color:#475569}.state.error{background:#fee2e2;color:#b91c1c}.state.success{background:#dcfce7;color:#166534}.state.inline{margin-top:16px;padding:16px}.footer{margin-top:48px;color:#94a3b8;font-size:.9rem}.detail-hero{display:flex;align-items:center;justify-content:space-between;gap:24px;flex-wrap:wrap}.detail-actions{display:flex;align-items:center;gap:12px}.detail-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(280px,1fr));gap:20px}.detail-list{display:grid;gap:12px;margin:16px 0}.detail-list div{display:flex;flex-direction:column;gap:4px;color:#64748b}.detail-list strong{color:inherit}.list{list-style:none;padding:0;margin:12px 0 0;display:grid;gap:12px}.list li{display:flex;justify-content:space-between;gap:12px;color:#64748b}.list a{color:#4f46e5;text-decoration:none;font-weight:600}.license-meta-bar{display:flex;gap:24px;flex-wrap:wrap;color:#64748b;font-size:.95rem}.license-forms{display:grid;grid-template-columns:repeat(auto-fit,minmax(280px,1fr));gap:20px}.form-grid{display:flex;flex-direction:column;gap:16px}.field{display:flex;flex-direction:column;gap:8px;font-size:.9rem;color:#475569}.field input,.field select,.field textarea{border-radius:12px;border:1px solid #e2e8f0;padding:10px 14px;font-size:1rem;font-family:inherit;background:#fff;color:inherit}.license-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(280px,1fr));gap:20px}.license-card-header{display:flex;justify-content:space-between;align-items:center;gap:12px}.license-card h3{margin:0}.license-subtitle{margin:4px 0 0;color:#94a3b8;font-size:.9rem}.license-note{margin-top:4px;font-size:.95rem;color:#475569}.license-detail-list{margin-top:0}.host-list ul{list-style:none;padding:0;margin:8px 0 0;display:flex;flex-direction:column;gap:8px}.host-list li{display:flex;justify-content:space-between;align-items:center;gap:12px;font-size:.9rem;color:#64748b}.host-list li strong{color:inherit}.license-links{display:flex;align-items:center;justify-content:space-between;flex-wrap:wrap;gap:12px;margin-top:auto}.ghost-pill{border:1px solid #cbd5f5;border-radius:999px;padding:4px 10px;font-size:.85rem;color:#475569}.auth-card{gap:16px}.auth-tabs{display:flex;gap:8px}.auth-tab{flex:1;border-radius:999px;border:1px solid #e2e8f0;background:#f8fafc;padding:8px 12px;font-weight:600;cursor:pointer;color:#475569}.auth-tab.active{background:#eef2ff;border-color:#c7d2fe;color:#4338ca}@media (max-width: 600px){.app{padding:40px 6vw 56px}.hero{align-items:flex-start}}@media (prefers-color-scheme: dark){.app{background:radial-gradient(circle at top,#1e1b4b,#0b1120 50%);color:#e2e8f0}.site-nav{border-color:#6366f166}.nav-link{color:#cbd5f5}.nav-link.active{background:#4f46e533;border-color:#4f46e566;color:#faf5ff}.nav-user{color:#cbd5f5}.nav-user-guest{color:#94a3b8}.subtitle{color:#cbd5f5}.card{background:#0f172a;box-shadow:0 12px 30px #0f172a59}.card p{color:#cbd5f5}.pill{background:#312e81;color:#e0e7ff}.meta{color:#94a3b8}.topic{background:#1e293b;color:#cbd5f5}.link{color:#a5b4fc}.ghost{border-color:#4f46e5;color:#e0e7ff}.auth-tab{border-color:#312e81;background:#1e1b4b;color:#cbd5f5}.auth-tab.active{background:#4f46e533;border-color:#4f46e599;color:#faf5ff}.hint,.license-meta-bar,.license-note{color:#cbd5f5}.field input,.field select,.field textarea{background:#1e1b4b;border-color:#312e81;color:#e2e8f0}.host-list li,.detail-list div,.list li{color:#cbd5f5}.list a{color:#a5b4fc}.state{background:#0f172a;color:#cbd5f5;box-shadow:0 10px 20px #0f172a66}.state.error{background:#7f1d1d;color:#fee2e2}.state.success{background:#14532d;color:#bbf7d0}.ghost-pill{border-color:#4f46e5;color:#cbd5f5}.footer{color:#94a3b8}}*{box-sizing:border-box}body{margin:0;background:#fff}@media (prefers-color-scheme: dark){body{background:#0b1120}}img{max-width:100%;display:block} diff --git a/dist/index.html b/dist/index.html new file mode 100644 index 0000000..e2ba835 --- /dev/null +++ b/dist/index.html @@ -0,0 +1,16 @@ + + + + + + + Siti Plugin Repo + + + + + +
+ + + \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 84049db..707a616 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,11 +1,20 @@ services: siti-plugin-repo: - image: siti-plugin-repo:latest - build: . + image: siti-plugin-repo:local + build: + context: . + pull_policy: never container_name: siti-plugin-repo ports: - "${HOST_PORT:-8080}:${PORT:-3001}" environment: PORT: "${PORT:-3001}" CACHE_TTL_MS: "${CACHE_TTL_MS:-600000}" + DB_HOST: "${DB_HOST:-127.0.0.1}" + DB_PORT: "${DB_PORT:-3306}" + DB_USER: "${DB_USER:-sitiapp}" + DB_PASSWORD: "${DB_PASSWORD:-sitiapp}" + DB_NAME: "${DB_NAME:-siti_plugin_repo}" + JWT_SECRET: "${JWT_SECRET:-change-me}" + JWT_EXPIRES_IN: "${JWT_EXPIRES_IN:-7d}" restart: unless-stopped diff --git a/package-lock.json b/package-lock.json index 3424415..0fe3486 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,7 +8,10 @@ "name": "siti-plugin-repo", "version": "0.1.0", "dependencies": { + "bcryptjs": "^3.0.3", "express": "^4.19.2", + "jsonwebtoken": "^9.0.3", + "mysql2": "^3.16.2", "react": "^18.2.0", "react-dom": "^18.2.0", "react-router-dom": "^6.23.1" @@ -1117,6 +1120,14 @@ "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==" }, + "node_modules/aws-ssl-profiles": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/aws-ssl-profiles/-/aws-ssl-profiles-1.1.2.tgz", + "integrity": "sha512-NZKeq9AfyQvEeNlN0zSYAaWrmBffJh3IELMZfRpJVWgrpEbtEpnjvzqBPf+mxoI287JohRDoa+/nsfqqiZmF6g==", + "engines": { + "node": ">= 6.0.0" + } + }, "node_modules/baseline-browser-mapping": { "version": "2.9.19", "resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.9.19.tgz", @@ -1126,6 +1137,14 @@ "baseline-browser-mapping": "dist/cli.js" } }, + "node_modules/bcryptjs": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/bcryptjs/-/bcryptjs-3.0.3.tgz", + "integrity": "sha512-GlF5wPWnSa/X5LKM1o0wz0suXIINz1iHRLvTS+sLyi7XPbe5ycmYI3DlZqVGZZtDgl4DmasFg7gOB3JYbphV5g==", + "bin": { + "bcrypt": "bin/bcrypt" + } + }, "node_modules/body-parser": { "version": "1.20.4", "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.4.tgz", @@ -1195,6 +1214,11 @@ "node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7" } }, + "node_modules/buffer-equal-constant-time": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz", + "integrity": "sha512-zRpUiDwd/xk6ADqPMATG8vc9VPrkck7T07OIx0gnjmJAnHnTVXNQG3vfvWNuiZIkwu9KrKdA1iJKfsfTVxE6NA==" + }, "node_modules/bytes": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", @@ -1305,6 +1329,14 @@ } } }, + "node_modules/denque": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/denque/-/denque-2.1.0.tgz", + "integrity": "sha512-HVQE3AAb/pxF8fQAoiqpvg9i3evqug3hoiwakOyZAwJm+6vZehbkYXZ0l4JxS+I3QxM97v5aaRNhj8v5oBhekw==", + "engines": { + "node": ">=0.10" + } + }, "node_modules/depd": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", @@ -1335,6 +1367,14 @@ "node": ">= 0.4" } }, + "node_modules/ecdsa-sig-formatter": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz", + "integrity": "sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ==", + "dependencies": { + "safe-buffer": "^5.0.1" + } + }, "node_modules/ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", @@ -1567,6 +1607,14 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/generate-function": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/generate-function/-/generate-function-2.3.1.tgz", + "integrity": "sha512-eeB5GfMNeevm/GRYq20ShmsaGcmI81kIX2K9XQx5miC8KdHaC6Jm0qQ8ZNeGOi7wYB8OsdxKs+Y2oVuTFuVwKQ==", + "dependencies": { + "is-property": "^1.0.2" + } + }, "node_modules/gensync": { "version": "1.0.0-beta.2", "resolved": "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz", @@ -1687,6 +1735,11 @@ "node": ">= 0.10" } }, + "node_modules/is-property": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/is-property/-/is-property-1.0.2.tgz", + "integrity": "sha512-Ks/IoX00TtClbGQr4TWXemAnktAQvYB7HzcCxDGqEZU6oCmb2INHuOoKxbtR+HFkmYWBKv/dOZtGRiAjDhj92g==" + }, "node_modules/js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", @@ -1716,6 +1769,97 @@ "node": ">=6" } }, + "node_modules/jsonwebtoken": { + "version": "9.0.3", + "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-9.0.3.tgz", + "integrity": "sha512-MT/xP0CrubFRNLNKvxJ2BYfy53Zkm++5bX9dtuPbqAeQpTVe0MQTFhao8+Cp//EmJp244xt6Drw/GVEGCUj40g==", + "dependencies": { + "jws": "^4.0.1", + "lodash.includes": "^4.3.0", + "lodash.isboolean": "^3.0.3", + "lodash.isinteger": "^4.0.4", + "lodash.isnumber": "^3.0.3", + "lodash.isplainobject": "^4.0.6", + "lodash.isstring": "^4.0.1", + "lodash.once": "^4.0.0", + "ms": "^2.1.1", + "semver": "^7.5.4" + }, + "engines": { + "node": ">=12", + "npm": ">=6" + } + }, + "node_modules/jsonwebtoken/node_modules/semver": { + "version": "7.7.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.3.tgz", + "integrity": "sha512-SdsKMrI9TdgjdweUSR9MweHA4EJ8YxHn8DFaDisvhVlUOe4BF1tLD7GAj0lIqWVl+dPb/rExr0Btby5loQm20Q==", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/jwa": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/jwa/-/jwa-2.0.1.tgz", + "integrity": "sha512-hRF04fqJIP8Abbkq5NKGN0Bbr3JxlQ+qhZufXVr0DvujKy93ZCbXZMHDL4EOtodSbCWxOqR8MS1tXA5hwqCXDg==", + "dependencies": { + "buffer-equal-constant-time": "^1.0.1", + "ecdsa-sig-formatter": "1.0.11", + "safe-buffer": "^5.0.1" + } + }, + "node_modules/jws": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/jws/-/jws-4.0.1.tgz", + "integrity": "sha512-EKI/M/yqPncGUUh44xz0PxSidXFr/+r0pA70+gIYhjv+et7yxM+s29Y+VGDkovRofQem0fs7Uvf4+YmAdyRduA==", + "dependencies": { + "jwa": "^2.0.1", + "safe-buffer": "^5.0.1" + } + }, + "node_modules/lodash.includes": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz", + "integrity": "sha512-W3Bx6mdkRTGtlJISOvVD/lbqjTlPPUDTMnlXZFnVwi9NKJ6tiAk6LVdlhZMm17VZisqhKcgzpO5Wz91PCt5b0w==" + }, + "node_modules/lodash.isboolean": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz", + "integrity": "sha512-Bz5mupy2SVbPHURB98VAcw+aHh4vRV5IPNhILUCsOzRmsTmSQ17jIuqopAentWoehktxGd9e/hbIXq980/1QJg==" + }, + "node_modules/lodash.isinteger": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz", + "integrity": "sha512-DBwtEWN2caHQ9/imiNeEA5ys1JoRtRfY3d7V9wkqtbycnAmTvRRmbHKDV4a0EYc678/dia0jrte4tjYwVBaZUA==" + }, + "node_modules/lodash.isnumber": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz", + "integrity": "sha512-QYqzpfwO3/CWf3XP+Z+tkQsfaLL/EnUlXWVkIk5FUPc4sBdTehEqZONuyRt2P67PXAk+NXmTBcc97zw9t1FQrw==" + }, + "node_modules/lodash.isplainobject": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz", + "integrity": "sha512-oSXzaWypCMHkPC3NvBEaPHf0KsA5mvPrOPgQWDsbg8n7orZ290M0BmC/jgRZ4vcJ6DTAhjrsSYgdsW/F+MFOBA==" + }, + "node_modules/lodash.isstring": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz", + "integrity": "sha512-0wJxfxH1wgO3GrbuP+dTTk7op+6L41QCXbGINEmD+ny/G/eCqGzxyCsh7159S+mgDDcoarnBw6PC1PS5+wUGgw==" + }, + "node_modules/lodash.once": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz", + "integrity": "sha512-Sb487aTOCr9drQVL8pIxOzVhafOjZN9UU54hiN8PU3uAiSV7lx1yYNpbNmex2PK6dSJoNTSJUUswT651yww3Mg==" + }, + "node_modules/long": { + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/long/-/long-5.3.2.tgz", + "integrity": "sha512-mNAgZ1GmyNhD7AuqnTG3/VQ26o760+ZYBPKjPvugO8+nLbYfX6TVpJPseBvopbdY+qpZ/lKUnmEc1LeZYS3QAA==" + }, "node_modules/loose-envify": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", @@ -1736,6 +1880,20 @@ "yallist": "^3.0.2" } }, + "node_modules/lru.min": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/lru.min/-/lru.min-1.1.3.tgz", + "integrity": "sha512-Lkk/vx6ak3rYkRR0Nhu4lFUT2VDnQSxBe8Hbl7f36358p6ow8Bnvr8lrLt98H8J1aGxfhbX4Fs5tYg2+FTwr5Q==", + "engines": { + "bun": ">=1.0.0", + "deno": ">=1.30.0", + "node": ">=8.0.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wellwelwel" + } + }, "node_modules/math-intrinsics": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", @@ -1803,6 +1961,51 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" }, + "node_modules/mysql2": { + "version": "3.16.2", + "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-3.16.2.tgz", + "integrity": "sha512-JsqBpYNy7pH20lGfPuSyRSIcCxSeAIwxWADpV64nP9KeyN3ZKpHZgjKXuBKsh7dH6FbOvf1bOgoVKjSUPXRMTw==", + "dependencies": { + "aws-ssl-profiles": "^1.1.2", + "denque": "^2.1.0", + "generate-function": "^2.3.1", + "iconv-lite": "^0.7.2", + "long": "^5.3.2", + "lru.min": "^1.1.3", + "named-placeholders": "^1.1.6", + "seq-queue": "^0.0.5", + "sqlstring": "^2.3.3" + }, + "engines": { + "node": ">= 8.0" + } + }, + "node_modules/mysql2/node_modules/iconv-lite": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.7.2.tgz", + "integrity": "sha512-im9DjEDQ55s9fL4EYzOAv0yMqmMBSZp6G0VvFyTMPKWxiSBHUj9NW/qqLmXUwXrrM7AvqSlTCfvqRb0cM8yYqw==", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + }, + "engines": { + "node": ">=0.10.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/named-placeholders": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/named-placeholders/-/named-placeholders-1.1.6.tgz", + "integrity": "sha512-Tz09sEL2EEuv5fFowm419c1+a/jSMiBjI9gHxVLrVdbUkkNUUfjsVYs9pVZu5oCon/kmRh9TfLEObFtkVxmY0w==", + "dependencies": { + "lru.min": "^1.1.0" + }, + "engines": { + "node": ">=8.0.0" + } + }, "node_modules/nanoid": { "version": "3.3.11", "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.11.tgz", @@ -2135,6 +2338,11 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" }, + "node_modules/seq-queue": { + "version": "0.0.5", + "resolved": "https://registry.npmjs.org/seq-queue/-/seq-queue-0.0.5.tgz", + "integrity": "sha512-hr3Wtp/GZIc/6DAGPDcV4/9WoZhjrkXsi5B/07QgX8tsdc6ilr7BFM6PM6rbdAX1kFSDYeZGLipIZZKyQP0O5Q==" + }, "node_modules/serve-static": { "version": "1.16.3", "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.16.3.tgz", @@ -2231,6 +2439,14 @@ "node": ">=0.10.0" } }, + "node_modules/sqlstring": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/sqlstring/-/sqlstring-2.3.3.tgz", + "integrity": "sha512-qC9iz2FlN7DQl3+wjwn3802RTyjCx7sDvfQEXchwa6CWOx07/WVfh91gBmQ9fahw8snwGEWU3xGzOt4tFyHLxg==", + "engines": { + "node": ">= 0.6" + } + }, "node_modules/statuses": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz", diff --git a/package.json b/package.json index b01048a..a855c01 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,10 @@ "start": "node server/index.js" }, "dependencies": { + "bcryptjs": "^3.0.3", "express": "^4.19.2", + "jsonwebtoken": "^9.0.3", + "mysql2": "^3.16.2", "react": "^18.2.0", "react-dom": "^18.2.0", "react-router-dom": "^6.23.1" @@ -20,4 +23,4 @@ "@vitejs/plugin-react": "^4.2.0", "vite": "^5.0.0" } -} \ No newline at end of file +} diff --git a/server/index.js b/server/index.js index fcb313c..e743b2d 100644 --- a/server/index.js +++ b/server/index.js @@ -1,218 +1,83 @@ import express from "express"; import path from "path"; -import { fileURLToPath } from "url"; -import fs from "fs/promises"; +import { + fetchCommits, + fetchManifest, + fetchRepo, + fetchReleases, + normalizeRepoInput, + parseRepoEntry, + readRepos +} from "./lib/pluginService.js"; +import { + buildLicensePayload, + createLicense, + findLicenseByKey, + getLicenseById, + listLicensesByUser, + touchLicenseHostname +} from "./lib/licenseService.js"; +import { HOST, PATHS, PORT } from "./lib/config.js"; +import { ensureSchema } from "./lib/schema.js"; +import { authenticateUser, registerUser } from "./lib/userService.js"; +import { requireAuth } from "./middleware/auth.js"; const app = express(); -const PORT = process.env.PORT || 3001; -const CACHE_TTL_MS = Number(process.env.CACHE_TTL_MS || 10 * 60 * 1000); +app.use(express.json()); -const __filename = fileURLToPath(import.meta.url); -const __dirname = path.dirname(__filename); -const rootDir = path.resolve(__dirname, ".."); -const distDir = path.join(rootDir, "dist"); -const reposFile = path.join(__dirname, "repos.json"); - -const cache = new Map(); - -function parseRepoEntry(entry) { - // support legacy string entries and object entries - if (typeof entry === "string") { - return { - provider: "github", - ownerRepo: entry, - baseUrl: "https://github.com" - }; - } - const provider = (entry.provider || "github").toLowerCase(); - const ownerRepo = entry.repo || entry.ownerRepo || ""; - const baseUrl = entry.baseUrl || (provider === "github" ? "https://github.com" : entry.baseUrl || ""); - return { provider, ownerRepo, baseUrl }; +try { + await ensureSchema(); +} catch (error) { + console.error("Kon database schema niet initialiseren:", error); + process.exit(1); } -async function readRepos() { - const content = await fs.readFile(reposFile, "utf-8"); - const parsed = JSON.parse(content); - return Array.isArray(parsed) ? parsed : []; -} - -function getCached(key) { - const entry = cache.get(key); - if (!entry) return null; - if (Date.now() > entry.expiresAt) { - cache.delete(key); - return null; - } - return entry.value; -} - -function setCached(key, value) { - cache.set(key, { value, expiresAt: Date.now() + CACHE_TTL_MS }); -} - -async function fetchJson(url, cacheKey, opts = {}) { - const cached = getCached(cacheKey); - if (cached) return cached; - const headers = { - "User-Agent": "siti-plugin-repo", - Accept: "application/json" - }; - // prefer GitHub API accept header when talking to github.com/api - if (!opts.provider || opts.provider === "github") { - headers.Accept = "application/vnd.github+json"; - } - - const response = await fetch(url, { headers }); - if (!response.ok) { - throw new Error(`${opts.provider || "git"} request failed for ${url}`); - } - const data = await response.json().catch(async () => { - // attempt to read text for non-json responses - const text = await response.text(); - try { - return JSON.parse(text); - } catch { - return null; +app.post("/api/auth/register", async (req, res) => { + try { + const { username, name, email, password } = req.body || {}; + if (!username || !name || !email || !password) { + return res.status(400).json({ error: "Vul gebruikersnaam, naam, e-mail en wachtwoord in." }); } - }); - setCached(cacheKey, data); - return data; -} - -async function fetchRepo(entry) { - const { provider, ownerRepo, baseUrl } = parseRepoEntry(entry); - const cacheKey = `repo:${provider}:${ownerRepo}`; - const cached = getCached(cacheKey); - if (cached) return cached; - - let data; - if (provider === "gitea") { - const url = `${baseUrl.replace(/\/$/, "")}/api/v1/repos/${ownerRepo}`; - data = await fetchJson(url, `repo-raw:${provider}:${ownerRepo}`, { provider }); - const mapped = { - fullName: data.full_name || `${ownerRepo}`, - name: data.name || ownerRepo.split("/")[1] || ownerRepo, - description: data.description || null, - repoUrl: `${baseUrl.replace(/\/$/, "")}/${ownerRepo}`, - defaultBranch: data.default_branch || data.default_branch || "main", - stars: data.stargazers_count || data.watchers || 0, - forks: data.forks_count || data.forks || 0, - issues: data.open_issues_count || 0, - updatedAt: data.updated_at || data.updated || null, - topics: data.topics || [] - }; - setCached(cacheKey, mapped); - return mapped; - } - - // default: github - data = await fetchJson(`https://api.github.com/repos/${ownerRepo}`, `repo-raw:github:${ownerRepo}`, { provider: "github" }); - const mapped = { - fullName: data.full_name, - name: data.name, - description: data.description, - repoUrl: data.html_url, - defaultBranch: data.default_branch, - stars: data.stargazers_count, - forks: data.forks_count, - issues: data.open_issues_count, - updatedAt: data.updated_at, - topics: data.topics || [] - }; - setCached(cacheKey, mapped); - return mapped; -} - -async function fetchManifest(entry, defaultBranch) { - const { provider, ownerRepo, baseUrl } = parseRepoEntry(entry); - const cacheKey = `manifest:${provider}:${ownerRepo}`; - const cached = getCached(cacheKey); - if (cached) return cached; - - const branches = [defaultBranch, "main", "master"].filter(Boolean); - const [owner, repo] = ownerRepo.split("/"); - for (const branch of branches) { - let url; - if (provider === "gitea") { - url = `${baseUrl.replace(/\/$/, "")}/repos/${owner}/${repo}/raw/${branch}/manifest.json`; - } else { - url = `https://raw.githubusercontent.com/${ownerRepo}/${branch}/manifest.json`; + if (password.length < 8) { + return res.status(400).json({ error: "Wachtwoord moet minimaal 8 karakters zijn." }); } - const response = await fetch(url, { headers: { "User-Agent": "siti-plugin-repo" } }); - if (response.ok) { - const manifest = await response.json().catch(() => null); - setCached(cacheKey, manifest); - return manifest; + const { user, token } = await registerUser({ + username: String(username).trim(), + name: String(name).trim(), + email: String(email).trim().toLowerCase(), + password: String(password) + }); + res.status(201).json({ token, user }); + } catch (error) { + if (error?.code === "ER_DUP_ENTRY") { + const field = error.meta === "EMAIL" ? "e-mailadres" : "gebruikersnaam"; + return res.status(409).json({ error: `Dit ${field} is al in gebruik.` }); } + res.status(500).json({ error: "Registratie mislukt." }); } - return null; -} +}); -async function fetchReleases(entry) { - const { provider, ownerRepo, baseUrl } = parseRepoEntry(entry); - if (provider === "gitea") { - const url = `${baseUrl.replace(/\/$/, "")}/api/v1/repos/${ownerRepo}/releases?limit=5`; - const data = await fetchJson(url, `releases:${provider}:${ownerRepo}`, { provider }); - return Array.isArray(data) - ? data.map((release) => ({ - tag: release.tag_name || release.name, - name: release.name || release.tag_name, - url: release.html_url || `${baseUrl.replace(/\/$/, "")}/${ownerRepo}/releases`, - publishedAt: release.published_at || release.created_at - })) - : []; +app.post("/api/auth/login", async (req, res) => { + try { + const { identifier, password } = req.body || {}; + if (!identifier || !password) { + return res.status(400).json({ error: "Vul gebruikersnaam/e-mail en wachtwoord in." }); + } + const { user, token } = await authenticateUser(String(identifier).trim(), String(password)); + res.json({ token, user }); + } catch (error) { + const message = error?.meta === "INVALID_CREDENTIALS" ? "Onjuiste inloggegevens." : "Login mislukt."; + res.status(401).json({ error: message }); } +}); - const data = await fetchJson( - `https://api.github.com/repos/${ownerRepo}/releases?per_page=5`, - `releases:github:${ownerRepo}`, - { provider: "github" } - ); - return Array.isArray(data) - ? data.map((release) => ({ - tag: release.tag_name, - name: release.name || release.tag_name, - url: release.html_url, - publishedAt: release.published_at - })) - : []; -} - -async function fetchCommits(entry) { - const { provider, ownerRepo, baseUrl } = parseRepoEntry(entry); - if (provider === "gitea") { - const url = `${baseUrl.replace(/\/$/, "")}/api/v1/repos/${ownerRepo}/commits?limit=5`; - const data = await fetchJson(url, `commits:${provider}:${ownerRepo}`, { provider }); - return Array.isArray(data) - ? data.map((commit) => ({ - sha: commit.sha, - message: commit.commit?.message || commit.message, - author: commit.commit?.author?.name || commit.author?.name, - date: commit.commit?.author?.date || commit.author?.date, - url: commit.html_url || `${baseUrl.replace(/\/$/, "")}/${ownerRepo}/commit/${commit.sha}` - })) - : []; - } - - const data = await fetchJson( - `https://api.github.com/repos/${ownerRepo}/commits?per_page=5`, - `commits:github:${ownerRepo}`, - { provider: "github" } - ); - return Array.isArray(data) - ? data.map((commit) => ({ - sha: commit.sha, - message: commit.commit?.message, - author: commit.commit?.author?.name, - date: commit.commit?.author?.date, - url: commit.html_url - })) - : []; -} +app.get("/api/auth/me", requireAuth, (req, res) => { + res.json({ user: req.user }); +}); app.get("/api/plugins", async (_req, res) => { try { - const repos = await readRepos(); + const repos = await readRepos(PATHS.reposFile); const results = await Promise.all( repos.map(async (repo) => { try { @@ -225,13 +90,19 @@ app.get("/api/plugins", async (_req, res) => { fullName: parsed.ownerRepo, name: parsed.ownerRepo.split("/")[1] || parsed.ownerRepo, description: "Kon gegevens niet ophalen.", - repoUrl: parsed.provider === "gitea" ? `${parsed.baseUrl.replace(/\/$/, "")}/${parsed.ownerRepo}` : `https://github.com/${parsed.ownerRepo}`, + repoUrl: + parsed.provider === "gitea" + ? `${parsed.baseUrl.replace(/\/$/, "")}/${parsed.ownerRepo}` + : `https://github.com/${parsed.ownerRepo}`, stars: 0, forks: 0, issues: 0, updatedAt: null, topics: [], - manifest: null + manifest: null, + provider: parsed.provider, + ownerRepo: parsed.ownerRepo, + baseUrl: parsed.baseUrl }; } }) @@ -272,12 +143,91 @@ app.get("/api/plugins/:owner/:repo", async (req, res) => { } }); -app.use(express.static(distDir)); -app.get("*", (_req, res) => { - res.sendFile(path.join(distDir, "index.html")); +app.get("/api/licenses", requireAuth, async (req, res) => { + try { + const payload = await listLicensesByUser(req.user.id); + res.json({ + count: payload.length, + updatedAt: new Date().toISOString(), + items: payload + }); + } catch (error) { + res.status(500).json({ error: "Kon licenties niet laden." }); + } +}); + +app.post("/api/licenses", requireAuth, async (req, res) => { + try { + const body = req.body || {}; + const repoInput = + typeof body.repo === "object" + ? body.repo + : typeof body.plugin === "object" + ? body.plugin + : body.repo || body.ownerRepo || body.fullName || body.plugin; + const repoEntry = + normalizeRepoInput(repoInput, { + repo: body.ownerRepo || body.fullName || body.repo, + provider: body.provider, + baseUrl: body.baseUrl + }) || null; + + if (!repoEntry) { + return res.status(400).json({ error: "Kies een plugin om de licentie aan te koppelen." }); + } + + try { + await fetchRepo(repoEntry); + } catch (error) { + return res.status(400).json({ error: "Kon plugin gegevens niet ophalen." }); + } + + const payload = await createLicense(req.user.id, { + label: body.label?.trim(), + note: body.note?.trim(), + repo: repoEntry + }); + res.status(201).json(payload); + } catch (error) { + res.status(500).json({ error: "Kon licentie niet aanmaken." }); + } +}); + +app.post("/api/licenses/verify", async (req, res) => { + try { + const { key, hostname } = req.body || {}; + if (!key || !hostname) { + return res.status(400).json({ valid: false, error: "Licentiecode en hostname zijn verplicht." }); + } + const license = await findLicenseByKey(String(key).trim()); + if (!license) { + return res.status(404).json({ valid: false, error: "Licentie niet gevonden." }); + } + + const result = await touchLicenseHostname(license, hostname); + if (!result.ok) { + const status = result.conflict ? 403 : 400; + return res.status(status).json({ valid: false, error: result.error, boundHostname: license.primary_hostname }); + } + + const freshLicense = await getLicenseById(license.id); + const payload = await buildLicensePayload(freshLicense); + res.json({ + valid: true, + hostname: payload.primaryHostname, + boundNow: !!result.boundNow, + license: payload + }); + } catch (error) { + res.status(500).json({ valid: false, error: "Validatie mislukt." }); + } +}); + +app.use(express.static(PATHS.distDir)); +app.get("*", (_req, res) => { + res.sendFile(path.join(PATHS.distDir, "index.html")); }); -const HOST = process.env.HOST || "::"; app.listen(PORT, HOST, () => { console.log(`Server draait op http://${HOST}:${PORT}`); }); diff --git a/server/lib/cache.js b/server/lib/cache.js new file mode 100644 index 0000000..f3a304b --- /dev/null +++ b/server/lib/cache.js @@ -0,0 +1,21 @@ +import { CACHE_TTL_MS } from "./config.js"; + +const cache = new Map(); + +export function getCached(key) { + const entry = cache.get(key); + if (!entry) return null; + if (Date.now() > entry.expiresAt) { + cache.delete(key); + return null; + } + return entry.value; +} + +export function setCached(key, value, ttlMs = CACHE_TTL_MS) { + cache.set(key, { value, expiresAt: Date.now() + ttlMs }); +} + +export function clearCached(key) { + cache.delete(key); +} diff --git a/server/lib/config.js b/server/lib/config.js new file mode 100644 index 0000000..132c6f8 --- /dev/null +++ b/server/lib/config.js @@ -0,0 +1,29 @@ +import path from "path"; +import { fileURLToPath } from "url"; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +const serverDir = path.resolve(__dirname, ".."); +const rootDir = path.resolve(serverDir, ".."); + +export const PATHS = { + serverDir, + rootDir, + distDir: path.join(rootDir, "dist"), + reposFile: path.join(serverDir, "repos.json") +}; + +export const PORT = process.env.PORT || 3001; +export const HOST = process.env.HOST || "::"; +export const CACHE_TTL_MS = Number(process.env.CACHE_TTL_MS || 10 * 60 * 1000); + +export const DB_CONFIG = { + host: process.env.DB_HOST || "127.0.0.1", + port: Number(process.env.DB_PORT || 3306), + user: process.env.DB_USER || "root", + password: process.env.DB_PASSWORD || "", + database: process.env.DB_NAME || "siti_plugin_repo" +}; + +export const JWT_SECRET = process.env.JWT_SECRET || "change-me-in-production"; +export const JWT_EXPIRES_IN = process.env.JWT_EXPIRES_IN || "7d"; diff --git a/server/lib/db.js b/server/lib/db.js new file mode 100644 index 0000000..9a96f38 --- /dev/null +++ b/server/lib/db.js @@ -0,0 +1,11 @@ +import mysql from "mysql2/promise"; +import { DB_CONFIG } from "./config.js"; + +const pool = mysql.createPool({ + ...DB_CONFIG, + waitForConnections: true, + connectionLimit: Number(process.env.DB_POOL_SIZE || 10), + namedPlaceholders: false +}); + +export default pool; diff --git a/server/lib/licenseService.js b/server/lib/licenseService.js new file mode 100644 index 0000000..5cdfc72 --- /dev/null +++ b/server/lib/licenseService.js @@ -0,0 +1,192 @@ +import crypto from "crypto"; +import db from "./db.js"; +import { fetchManifest, fetchRepo, normalizeRepoInput } from "./pluginService.js"; + +function toIso(value) { + return value ? new Date(value).toISOString() : null; +} + +export function generateLicenseKey() { + const raw = crypto.randomBytes(8).toString("hex").toUpperCase(); + const segments = raw.match(/.{1,4}/g) || []; + return `SITI-${segments.slice(0, 4).join("-")}`; +} + +export function normalizeHostname(value) { + return value ? value.trim().toLowerCase() : null; +} + +export async function listLicensesByUser(userId) { + const [rows] = await db.query(`SELECT * FROM licenses WHERE user_id = ? ORDER BY created_at DESC`, [userId]); + return Promise.all(rows.map((row) => buildLicensePayload(row))); +} + +export async function getLicenseById(id) { + const [rows] = await db.query(`SELECT * FROM licenses WHERE id = ? LIMIT 1`, [id]); + return rows[0] || null; +} + +export async function findLicenseByKey(key) { + const [rows] = await db.query(`SELECT * FROM licenses WHERE license_key = ? LIMIT 1`, [key]); + return rows[0] || null; +} + +export async function createLicense(userId, { label, note, repo }) { + const repoEntry = normalizeRepoInput(repo); + if (!repoEntry) { + const error = new Error("Ongeldige plugin referentie."); + error.meta = "INVALID_REPO"; + throw error; + } + + let licenseId = null; + for (let attempt = 0; attempt < 5; attempt += 1) { + const id = crypto.randomUUID(); + const licenseKey = generateLicenseKey(); + try { + await db.query( + `INSERT INTO licenses ( + id, user_id, license_key, label, note, + repo_provider, repo_name, repo_base_url, + created_at, updated_at + ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, NOW(), NOW())`, + [ + id, + userId, + licenseKey, + label || repoEntry.repo, + note || null, + repoEntry.provider || "github", + repoEntry.repo, + repoEntry.baseUrl || (repoEntry.provider === "github" ? "https://github.com" : null) + ] + ); + licenseId = id; + break; + } catch (error) { + if (error?.code === "ER_DUP_ENTRY") { + continue; + } + throw error; + } + } + + if (!licenseId) { + throw new Error("Kon licentie niet opslaan."); + } + + return buildLicensePayload(await getLicenseById(licenseId)); +} + +export async function buildLicensePayload(row) { + if (!row) return null; + const repoEntry = normalizeRepoInput({ + repo: row.repo_name, + provider: row.repo_provider, + baseUrl: row.repo_base_url + }); + const [hostnameRows] = await db.query( + `SELECT hostname, normalized, first_seen_at, last_seen_at, hits + FROM license_hostnames WHERE license_id = ? ORDER BY first_seen_at ASC`, + [row.id] + ); + const hostnames = hostnameRows.map((entry) => ({ + hostname: entry.hostname, + normalized: entry.normalized, + firstSeenAt: toIso(entry.first_seen_at), + lastSeenAt: toIso(entry.last_seen_at), + hits: entry.hits + })); + + if (!repoEntry) { + return { + id: row.id, + key: row.license_key, + label: row.label, + note: row.note, + hostnames, + createdAt: toIso(row.created_at), + updatedAt: toIso(row.updated_at), + lastVersionCheckAt: toIso(row.last_version_check_at), + primaryHostname: row.primary_hostname, + primaryHostnameNormalized: row.primary_hostname_normalized, + repoFullName: row.repo_name, + repoUrl: null, + pluginName: row.label, + pluginVersion: null, + repo: null + }; + } + + try { + const info = await fetchRepo(repoEntry); + const manifest = await fetchManifest(repoEntry, info.defaultBranch).catch(() => null); + return { + id: row.id, + key: row.license_key, + label: row.label, + note: row.note, + createdAt: toIso(row.created_at), + updatedAt: toIso(row.updated_at), + lastVersionCheckAt: toIso(row.last_version_check_at), + primaryHostname: row.primary_hostname, + primaryHostnameNormalized: row.primary_hostname_normalized, + repoFullName: info.fullName, + repoUrl: info.repoUrl, + pluginName: manifest?.plugin_name || info.name || row.label, + pluginVersion: manifest?.version || null, + repo: repoEntry, + hostnames + }; + } catch (error) { + return { + id: row.id, + key: row.license_key, + label: row.label, + note: row.note, + createdAt: toIso(row.created_at), + updatedAt: toIso(row.updated_at), + lastVersionCheckAt: toIso(row.last_version_check_at), + primaryHostname: row.primary_hostname, + primaryHostnameNormalized: row.primary_hostname_normalized, + repoFullName: row.repo_name, + repoUrl: repoEntry?.baseUrl ? `${repoEntry.baseUrl.replace(/\/$/, "")}/${row.repo_name}` : null, + pluginName: row.label, + pluginVersion: null, + repo: repoEntry, + hostnames + }; + } +} + +export async function touchLicenseHostname(license, hostname) { + const normalizedHost = normalizeHostname(hostname); + if (!normalizedHost) { + return { ok: false, error: "Ongeldige hostname." }; + } + const trimmed = hostname.trim(); + if (!license.primary_hostname_normalized) { + await db.query( + `UPDATE licenses SET primary_hostname = ?, primary_hostname_normalized = ?, last_version_check_at = NOW(), updated_at = NOW() + WHERE id = ?`, + [trimmed, normalizedHost, license.id] + ); + } else if (license.primary_hostname_normalized !== normalizedHost) { + return { + ok: false, + conflict: true, + error: `Licentie hoort bij ${license.primary_hostname || "een andere site"}.` + }; + } else { + await db.query(`UPDATE licenses SET last_version_check_at = NOW(), updated_at = NOW() WHERE id = ?`, [license.id]); + } + + await db.query( + `INSERT INTO license_hostnames (license_id, hostname, normalized, first_seen_at, last_seen_at, hits) + VALUES (?, ?, ?, NOW(), NOW(), 1) + ON DUPLICATE KEY UPDATE hostname = VALUES(hostname), last_seen_at = NOW(), hits = hits + 1`, + [license.id, trimmed, normalizedHost] + ); + + return { ok: true, boundNow: !license.primary_hostname_normalized, normalized: normalizedHost }; +} diff --git a/server/lib/pluginService.js b/server/lib/pluginService.js new file mode 100644 index 0000000..70f7ae1 --- /dev/null +++ b/server/lib/pluginService.js @@ -0,0 +1,204 @@ +import { readJsonFile } from "./storage.js"; +import { getCached, setCached } from "./cache.js"; + +export function parseRepoEntry(entry) { + if (typeof entry === "string") { + return { + provider: "github", + ownerRepo: entry, + baseUrl: "https://github.com" + }; + } + const provider = (entry?.provider || "github").toLowerCase(); + const ownerRepo = entry?.repo || entry?.ownerRepo || ""; + const baseUrl = entry?.baseUrl || (provider === "github" ? "https://github.com" : ""); + return { provider, ownerRepo, baseUrl }; +} + +export function normalizeRepoInput(input, extras = {}) { + if (typeof input === "string") { + return normalizeRepoInput({ repo: input }, extras); + } + const source = input && typeof input === "object" ? input : {}; + const repo = source.repo || source.ownerRepo || source.fullName || extras.repo; + if (!repo) { + return null; + } + const provider = (source.provider || extras.provider || "github").toLowerCase(); + const normalized = { + repo, + provider + }; + const baseUrl = source.baseUrl || extras.baseUrl || (provider === "github" ? "https://github.com" : undefined); + if (baseUrl) { + normalized.baseUrl = baseUrl; + } + return normalized; +} + +export async function readRepos(reposFile) { + const parsed = await readJsonFile(reposFile, []); + return Array.isArray(parsed) ? parsed : []; +} + +async function fetchJson(url, cacheKey, opts = {}) { + const cached = getCached(cacheKey); + if (cached) return cached; + const headers = { + "User-Agent": "siti-plugin-repo", + Accept: "application/json" + }; + if (!opts.provider || opts.provider === "github") { + headers.Accept = "application/vnd.github+json"; + } + const response = await fetch(url, { headers }); + if (!response.ok) { + throw new Error(`${opts.provider || "git"} request failed for ${url}`); + } + const data = await response.json().catch(async () => { + const text = await response.text(); + try { + return JSON.parse(text); + } catch { + return null; + } + }); + setCached(cacheKey, data); + return data; +} + +export async function fetchRepo(entry) { + const { provider, ownerRepo, baseUrl } = parseRepoEntry(entry); + const cacheKey = `repo:${provider}:${ownerRepo}`; + const cached = getCached(cacheKey); + if (cached) return cached; + + let data; + if (provider === "gitea") { + const url = `${baseUrl.replace(/\/$/, "")}/api/v1/repos/${ownerRepo}`; + data = await fetchJson(url, `repo-raw:${provider}:${ownerRepo}`, { provider }); + const mapped = { + fullName: data.full_name || `${ownerRepo}`, + name: data.name || ownerRepo.split("/")[1] || ownerRepo, + description: data.description || null, + repoUrl: `${baseUrl.replace(/\/$/, "")}/${ownerRepo}`, + defaultBranch: data.default_branch || "main", + stars: data.stargazers_count || data.watchers || 0, + forks: data.forks_count || data.forks || 0, + issues: data.open_issues_count || 0, + updatedAt: data.updated_at || data.updated || null, + topics: data.topics || [], + provider, + ownerRepo, + baseUrl + }; + setCached(cacheKey, mapped); + return mapped; + } + + data = await fetchJson(`https://api.github.com/repos/${ownerRepo}`, `repo-raw:github:${ownerRepo}`, { provider: "github" }); + const mapped = { + fullName: data.full_name, + name: data.name, + description: data.description, + repoUrl: data.html_url, + defaultBranch: data.default_branch, + stars: data.stargazers_count, + forks: data.forks_count, + issues: data.open_issues_count, + updatedAt: data.updated_at, + topics: data.topics || [], + provider, + ownerRepo, + baseUrl: "https://github.com" + }; + setCached(cacheKey, mapped); + return mapped; +} + +export async function fetchManifest(entry, defaultBranch) { + const { provider, ownerRepo, baseUrl } = parseRepoEntry(entry); + const cacheKey = `manifest:${provider}:${ownerRepo}`; + const cached = getCached(cacheKey); + if (cached) return cached; + + const branches = [defaultBranch, "main", "master"].filter(Boolean); + const [owner, repo] = ownerRepo.split("/"); + for (const branch of branches) { + let url; + if (provider === "gitea") { + url = `${baseUrl.replace(/\/$/, "")}/repos/${owner}/${repo}/raw/${branch}/manifest.json`; + } else { + url = `https://raw.githubusercontent.com/${ownerRepo}/${branch}/manifest.json`; + } + const response = await fetch(url, { headers: { "User-Agent": "siti-plugin-repo" } }); + if (response.ok) { + const manifest = await response.json().catch(() => null); + setCached(cacheKey, manifest); + return manifest; + } + } + return null; +} + +export async function fetchReleases(entry) { + const { provider, ownerRepo, baseUrl } = parseRepoEntry(entry); + if (provider === "gitea") { + const url = `${baseUrl.replace(/\/$/, "")}/api/v1/repos/${ownerRepo}/releases?limit=5`; + const data = await fetchJson(url, `releases:${provider}:${ownerRepo}`, { provider }); + return Array.isArray(data) + ? data.map((release) => ({ + tag: release.tag_name || release.name, + name: release.name || release.tag_name, + url: release.html_url || `${baseUrl.replace(/\/$/, "")}/${ownerRepo}/releases`, + publishedAt: release.published_at || release.created_at + })) + : []; + } + + const data = await fetchJson( + `https://api.github.com/repos/${ownerRepo}/releases?per_page=5`, + `releases:github:${ownerRepo}`, + { provider: "github" } + ); + return Array.isArray(data) + ? data.map((release) => ({ + tag: release.tag_name, + name: release.name || release.tag_name, + url: release.html_url, + publishedAt: release.published_at + })) + : []; +} + +export async function fetchCommits(entry) { + const { provider, ownerRepo, baseUrl } = parseRepoEntry(entry); + if (provider === "gitea") { + const url = `${baseUrl.replace(/\/$/, "")}/api/v1/repos/${ownerRepo}/commits?limit=5`; + const data = await fetchJson(url, `commits:${provider}:${ownerRepo}`, { provider }); + return Array.isArray(data) + ? data.map((commit) => ({ + sha: commit.sha, + message: commit.commit?.message || commit.message, + author: commit.commit?.author?.name || commit.author?.name, + date: commit.commit?.author?.date || commit.author?.date, + url: commit.html_url || `${baseUrl.replace(/\/$/, "")}/${ownerRepo}/commit/${commit.sha}` + })) + : []; + } + + const data = await fetchJson( + `https://api.github.com/repos/${ownerRepo}/commits?per_page=5`, + `commits:github:${ownerRepo}`, + { provider: "github" } + ); + return Array.isArray(data) + ? data.map((commit) => ({ + sha: commit.sha, + message: commit.commit?.message, + author: commit.commit?.author?.name, + date: commit.commit?.author?.date, + url: commit.html_url + })) + : []; +} diff --git a/server/lib/schema.js b/server/lib/schema.js new file mode 100644 index 0000000..1c06c27 --- /dev/null +++ b/server/lib/schema.js @@ -0,0 +1,57 @@ +import db from "./db.js"; + +async function createUsersTable() { + await db.query(` + CREATE TABLE IF NOT EXISTS users ( + id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, + username VARCHAR(50) NOT NULL UNIQUE, + name VARCHAR(120) NOT NULL, + email VARCHAR(120) NOT NULL UNIQUE, + password_hash VARCHAR(255) NOT NULL, + created_at DATETIME DEFAULT CURRENT_TIMESTAMP + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + `); +} + +async function createLicensesTable() { + await db.query(` + CREATE TABLE IF NOT EXISTS licenses ( + id CHAR(36) NOT NULL PRIMARY KEY, + user_id INT UNSIGNED NOT NULL, + license_key VARCHAR(64) NOT NULL UNIQUE, + label VARCHAR(255), + note TEXT, + repo_provider VARCHAR(32) NOT NULL, + repo_name VARCHAR(255) NOT NULL, + repo_base_url VARCHAR(255), + created_at DATETIME DEFAULT CURRENT_TIMESTAMP, + updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + last_version_check_at DATETIME NULL, + primary_hostname VARCHAR(255) NULL, + primary_hostname_normalized VARCHAR(255) NULL, + FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + `); +} + +async function createLicenseHostnamesTable() { + await db.query(` + CREATE TABLE IF NOT EXISTS license_hostnames ( + id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, + license_id CHAR(36) NOT NULL, + hostname VARCHAR(255) NOT NULL, + normalized VARCHAR(255) NOT NULL, + first_seen_at DATETIME NOT NULL, + last_seen_at DATETIME NOT NULL, + hits INT UNSIGNED NOT NULL DEFAULT 1, + UNIQUE KEY unique_license_host (license_id, normalized), + FOREIGN KEY (license_id) REFERENCES licenses(id) ON DELETE CASCADE + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + `); +} + +export async function ensureSchema() { + await createUsersTable(); + await createLicensesTable(); + await createLicenseHostnamesTable(); +} diff --git a/server/lib/storage.js b/server/lib/storage.js new file mode 100644 index 0000000..2834849 --- /dev/null +++ b/server/lib/storage.js @@ -0,0 +1,19 @@ +import fs from "fs/promises"; + +export async function readJsonFile(filePath, fallback = []) { + try { + const content = await fs.readFile(filePath, "utf-8"); + const parsed = JSON.parse(content); + return parsed ?? fallback; + } catch (error) { + if (error.code === "ENOENT") { + await fs.writeFile(filePath, JSON.stringify(fallback, null, 2)); + return fallback; + } + throw error; + } +} + +export async function writeJsonFile(filePath, data) { + await fs.writeFile(filePath, JSON.stringify(data, null, 2)); +} diff --git a/server/lib/userService.js b/server/lib/userService.js new file mode 100644 index 0000000..66b2af7 --- /dev/null +++ b/server/lib/userService.js @@ -0,0 +1,69 @@ +import bcrypt from "bcryptjs"; +import jwt from "jsonwebtoken"; +import db from "./db.js"; +import { JWT_SECRET, JWT_EXPIRES_IN } from "./config.js"; + +function serializeUser(row) { + if (!row) return null; + return { + id: row.id, + username: row.username, + name: row.name, + email: row.email, + createdAt: row.created_at ? new Date(row.created_at).toISOString() : null + }; +} + +function signToken(userId) { + return jwt.sign({ sub: userId }, JWT_SECRET, { expiresIn: JWT_EXPIRES_IN }); +} + +export async function registerUser({ username, name, email, password }) { + const passwordHash = await bcrypt.hash(password, 10); + try { + const [result] = await db.query( + `INSERT INTO users (username, name, email, password_hash) VALUES (?, ?, ?, ?)`, + [username, name, email, passwordHash] + ); + const user = await getUserById(result.insertId); + const token = signToken(user.id); + return { user, token }; + } catch (error) { + if (error?.code === "ER_DUP_ENTRY") { + const message = error.sqlMessage || "Duplicate"; + if (message.includes("username")) { + error.meta = "USERNAME"; + } else if (message.includes("email")) { + error.meta = "EMAIL"; + } + } + throw error; + } +} + +export async function authenticateUser(identifier, password) { + const [rows] = await db.query( + `SELECT * FROM users WHERE username = ? OR email = ? LIMIT 1`, + [identifier, identifier] + ); + if (rows.length === 0) { + const err = new Error("Onjuiste inloggegevens."); + err.meta = "INVALID_CREDENTIALS"; + throw err; + } + const row = rows[0]; + const ok = await bcrypt.compare(password, row.password_hash); + if (!ok) { + const err = new Error("Onjuiste inloggegevens."); + err.meta = "INVALID_CREDENTIALS"; + throw err; + } + const user = serializeUser(row); + const token = signToken(user.id); + return { user, token }; +} + +export async function getUserById(id) { + const [rows] = await db.query(`SELECT id, username, name, email, created_at FROM users WHERE id = ? LIMIT 1`, [id]); + return serializeUser(rows[0]); +} diff --git a/server/middleware/auth.js b/server/middleware/auth.js new file mode 100644 index 0000000..a82d891 --- /dev/null +++ b/server/middleware/auth.js @@ -0,0 +1,23 @@ +import jwt from "jsonwebtoken"; +import { JWT_SECRET } from "../lib/config.js"; +import { getUserById } from "../lib/userService.js"; + +export async function requireAuth(req, res, next) { + const authHeader = req.headers.authorization || ""; + const token = authHeader.startsWith("Bearer ") ? authHeader.slice(7).trim() : null; + if (!token) { + return res.status(401).json({ error: "Inloggen vereist." }); + } + try { + const payload = jwt.verify(token, JWT_SECRET); + const user = await getUserById(payload.sub); + if (!user) { + return res.status(401).json({ error: "Gebruiker niet gevonden." }); + } + req.user = user; + req.token = token; + next(); + } catch (error) { + return res.status(401).json({ error: "Ongeldige of verlopen token." }); + } +} diff --git a/src/App.css b/src/App.css index 7b51df5..9f7214d 100644 --- a/src/App.css +++ b/src/App.css @@ -10,6 +10,59 @@ padding: 48px 8vw 64px; } +.site-nav { + display: flex; + align-items: center; + justify-content: space-between; + gap: 16px; + margin-bottom: 32px; + flex-wrap: wrap; +} + +.nav-logo { + font-weight: 700; + color: inherit; + text-decoration: none; + font-size: 1.1rem; +} + +.nav-links { + display: flex; + gap: 12px; +} + +.nav-user { + display: flex; + align-items: center; + gap: 8px; + font-size: 0.9rem; + color: #475569; +} + +.nav-user-name { + font-weight: 600; +} + +.nav-user-guest { + color: #94a3b8; + font-size: 0.85rem; +} + +.nav-link { + padding: 8px 16px; + border-radius: 999px; + border: 1px solid transparent; + text-decoration: none; + color: #475569; + font-weight: 600; +} + +.nav-link.active { + background: #eef2ff; + color: #4338ca; + border-color: #c7d2fe; +} + .page { display: flex; flex-direction: column; @@ -46,6 +99,12 @@ max-width: 520px; } +.hint { + margin: 8px 0 0; + font-size: 0.9rem; + color: #64748b; +} + .cta { background: #4f46e5; color: #fff; @@ -55,6 +114,11 @@ font-weight: 600; box-shadow: 0 8px 24px rgba(79, 70, 229, 0.2); transition: transform 0.2s ease, box-shadow 0.2s ease; + display: inline-flex; + align-items: center; + justify-content: center; + border: none; + cursor: pointer; } .cta:hover { @@ -62,6 +126,26 @@ box-shadow: 0 12px 30px rgba(79, 70, 229, 0.3); } +.ghost { + border: 1px solid #c7d2fe; + color: #4338ca; + padding: 8px 14px; + border-radius: 999px; + text-decoration: none; + font-weight: 600; + display: inline-flex; + align-items: center; + justify-content: center; + gap: 8px; + background: transparent; + cursor: pointer; +} + +.ghost-small { + padding: 6px 12px; + font-size: 0.85rem; +} + .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); @@ -139,15 +223,6 @@ text-decoration: none; } -.ghost { - border: 1px solid #c7d2fe; - color: #4338ca; - padding: 8px 14px; - border-radius: 999px; - text-decoration: none; - font-weight: 600; -} - .state { background: #fff; border-radius: 16px; @@ -161,6 +236,16 @@ color: #b91c1c; } +.state.success { + background: #dcfce7; + color: #166534; +} + +.state.inline { + margin-top: 16px; + padding: 16px; +} + .footer { margin-top: 48px; color: #94a3b8; @@ -225,6 +310,144 @@ font-weight: 600; } +.license-meta-bar { + display: flex; + gap: 24px; + flex-wrap: wrap; + color: #64748b; + font-size: 0.95rem; +} + +.license-forms { + display: grid; + grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); + gap: 20px; +} + +.form-grid { + display: flex; + flex-direction: column; + gap: 16px; +} + +.field { + display: flex; + flex-direction: column; + gap: 8px; + font-size: 0.9rem; + color: #475569; +} + +.field input, +.field select, +.field textarea { + border-radius: 12px; + border: 1px solid #e2e8f0; + padding: 10px 14px; + font-size: 1rem; + font-family: inherit; + background: #fff; + color: inherit; +} + +.license-grid { + display: grid; + grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); + gap: 20px; +} + +.license-card-header { + display: flex; + justify-content: space-between; + align-items: center; + gap: 12px; +} + +.license-card h3 { + margin: 0; +} + +.license-subtitle { + margin: 4px 0 0; + color: #94a3b8; + font-size: 0.9rem; +} + +.license-note { + margin-top: 4px; + font-size: 0.95rem; + color: #475569; +} + +.license-detail-list { + margin-top: 0; +} + +.host-list ul { + list-style: none; + padding: 0; + margin: 8px 0 0; + display: flex; + flex-direction: column; + gap: 8px; +} + +.host-list li { + display: flex; + justify-content: space-between; + align-items: center; + gap: 12px; + font-size: 0.9rem; + color: #64748b; +} + +.host-list li strong { + color: inherit; +} + +.license-links { + display: flex; + align-items: center; + justify-content: space-between; + flex-wrap: wrap; + gap: 12px; + margin-top: auto; +} + +.ghost-pill { + border: 1px solid #cbd5f5; + border-radius: 999px; + padding: 4px 10px; + font-size: 0.85rem; + color: #475569; +} + +.auth-card { + gap: 16px; +} + +.auth-tabs { + display: flex; + gap: 8px; +} + +.auth-tab { + flex: 1; + border-radius: 999px; + border: 1px solid #e2e8f0; + background: #f8fafc; + padding: 8px 12px; + font-weight: 600; + cursor: pointer; + color: #475569; +} + +.auth-tab.active { + background: #eef2ff; + border-color: #c7d2fe; + color: #4338ca; +} + @media (max-width: 600px) { .app { padding: 40px 6vw 56px; @@ -241,6 +464,28 @@ color: #e2e8f0; } + .site-nav { + border-color: rgba(99, 102, 241, 0.4); + } + + .nav-link { + color: #cbd5f5; + } + + .nav-link.active { + background: rgba(79, 70, 229, 0.2); + border-color: rgba(79, 70, 229, 0.4); + color: #faf5ff; + } + + .nav-user { + color: #cbd5f5; + } + + .nav-user-guest { + color: #94a3b8; + } + .subtitle { color: #cbd5f5; } @@ -277,6 +522,36 @@ color: #e0e7ff; } + .auth-tab { + border-color: #312e81; + background: #1e1b4b; + color: #cbd5f5; + } + + .auth-tab.active { + background: rgba(79, 70, 229, 0.2); + border-color: rgba(79, 70, 229, 0.6); + color: #faf5ff; + } + + .hint, + .license-meta-bar, + .license-note { + color: #cbd5f5; + } + + .field input, + .field select, + .field textarea { + background: #1e1b4b; + border-color: #312e81; + color: #e2e8f0; + } + + .host-list li { + color: #cbd5f5; + } + .detail-list div { color: #cbd5f5; } @@ -300,7 +575,17 @@ color: #fee2e2; } + .state.success { + background: #14532d; + color: #bbf7d0; + } + + .ghost-pill { + border-color: #4f46e5; + color: #cbd5f5; + } + .footer { color: #94a3b8; } -} \ No newline at end of file +} diff --git a/src/App.jsx b/src/App.jsx index 83ea030..dee343b 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,221 +1,18 @@ -import { useEffect, useMemo, useState } from "react"; -import { Link, Route, Routes, useParams } from "react-router-dom"; +import { Route, Routes } from "react-router-dom"; +import SiteNav from "./components/SiteNav.jsx"; +import Home from "./pages/Home.jsx"; +import PluginDetail from "./pages/PluginDetail.jsx"; +import LicenseManager from "./pages/LicenseManager.jsx"; import "./App.css"; -function Home() { - const [plugins, setPlugins] = useState([]); - const [loading, setLoading] = useState(true); - const [error, setError] = useState(null); - const [lastSync, setLastSync] = useState(null); - - useEffect(() => { - async function loadPlugins() { - try { - const response = await fetch("/api/plugins"); - if (!response.ok) { - throw new Error("Kon plugins niet laden"); - } - const data = await response.json(); - setPlugins(data.items || []); - setLastSync(data.updatedAt); - } catch (err) { - setError("Laden van GitHub data is mislukt."); - } finally { - setLoading(false); - } - } - - loadPlugins(); - }, []); - - return ( -
-
-
-

WordPress plugin overzicht

-

Siti Plugin Repo

-

Al je publieke WordPress plugins op één plek.

-
- - GitHub SitiWeb - -
- -
- {loading &&
Bezig met laden…
} - {error &&
{error}
} - {!loading && !error && plugins.length === 0 && ( -
Geen repositories gevonden.
- )} - {plugins.map((plugin) => { - const displayName = plugin.manifest?.plugin_name || plugin.name; - const description = plugin.manifest?.description || plugin.description; - return ( -
-
-

{displayName}

- {plugin.fullName} -
-

{description}

-
- ★ {plugin.stars} - Forks {plugin.forks} - Issues {plugin.issues} -
- {plugin.topics.length > 0 && ( -
- {plugin.topics.slice(0, 4).map((topic) => ( - {topic} - ))} -
- )} -
- - Bekijk details → - - - GitHub - -
-
- ); - })} -
- -
- - Laatste sync: {lastSync ? new Date(lastSync).toLocaleString("nl-NL") : "-"} - -
-
- ); -} - -function PluginDetail() { - const { owner, repo } = useParams(); - const [data, setData] = useState(null); - const [loading, setLoading] = useState(true); - const [error, setError] = useState(null); - - useEffect(() => { - async function loadDetail() { - try { - const response = await fetch(`/api/plugins/${owner}/${repo}`); - if (!response.ok) { - throw new Error("Kon details niet laden"); - } - const detail = await response.json(); - setData(detail); - } catch (err) { - setError("Laden van plugin details is mislukt."); - } finally { - setLoading(false); - } - } - - loadDetail(); - }, [owner, repo]); - - const manifest = data?.manifest; - const displayName = manifest?.plugin_name || data?.name || repo; - const description = manifest?.description || data?.description; - const author = manifest?.author || "-"; - const version = manifest?.version || "-"; - - const releases = useMemo(() => data?.releases || [], [data]); - const commits = useMemo(() => data?.commits || [], [data]); - - return ( -
-
-
-

Plugin details

-

{displayName}

-

{description}

-
-
- ← Terug - {data?.repoUrl && ( - - GitHub - - )} -
-
- - {loading &&
Bezig met laden…
} - {error &&
{error}
} - - {!loading && !error && data && ( -
-
-

Manifest

-
-
- Naam - {displayName} -
-
- Versie - {version} -
-
- Auteur - {author} -
-
- Repository - {data.fullName} -
-
- {manifest?.author_url && ( - - Auteur website → - - )} -
- -
-

Releases

- {releases.length === 0 &&

Geen releases gevonden.

} -
    - {releases.map((release) => ( -
  • - - {release.name} - - {release.publishedAt ? new Date(release.publishedAt).toLocaleDateString("nl-NL") : "-"} -
  • - ))} -
-
- -
-

Recente commits

- {commits.length === 0 &&

Geen commits gevonden.

} - -
-
- )} -
- ); -} - export default function App() { return (
+ } /> } /> + } />
); diff --git a/src/components/LicenseCard.jsx b/src/components/LicenseCard.jsx new file mode 100644 index 0000000..e21dfe5 --- /dev/null +++ b/src/components/LicenseCard.jsx @@ -0,0 +1,65 @@ +import { formatDate, formatDateTime } from "../utils/dates.js"; + +export default function LicenseCard({ license }) { + const hostnames = license.hostnames || []; + const primaryHostname = license.primaryHostname || "Nog niet gekoppeld"; + + return ( +
+
+
+

{license.pluginName || license.label || "Licentie"}

+

{license.repoFullName || "-"}

+
+ {license.key} +
+ +
+
+ Versie + {license.pluginVersion || "-"} +
+
+ Hostname + {primaryHostname} +
+
+ Aangemaakt + {formatDate(license.createdAt)} +
+
+ Laatste check + {formatDateTime(license.lastVersionCheckAt)} +
+
+ + {license.note &&

Notitie: {license.note}

} + + {hostnames.length > 0 && ( +
+

Hostnames

+
    + {hostnames.map((host) => ( +
  • +
    + {host.hostname} + {host.hits || 0} checks +
    + {formatDateTime(host.lastSeenAt)} +
  • + ))} +
+
+ )} + +
+ {license.repoUrl && ( + + Repository → + + )} + {license.pluginName && {license.pluginName}} +
+
+ ); +} diff --git a/src/components/SiteNav.jsx b/src/components/SiteNav.jsx new file mode 100644 index 0000000..d174699 --- /dev/null +++ b/src/components/SiteNav.jsx @@ -0,0 +1,29 @@ +import { Link, NavLink } from "react-router-dom"; +import { useAuth } from "../context/AuthContext.jsx"; + +export default function SiteNav() { + const linkClass = ({ isActive }) => (isActive ? "nav-link active" : "nav-link"); + const { user, logout } = useAuth(); + + return ( + + ); +} diff --git a/src/context/AuthContext.jsx b/src/context/AuthContext.jsx new file mode 100644 index 0000000..1ff611b --- /dev/null +++ b/src/context/AuthContext.jsx @@ -0,0 +1,140 @@ +import { createContext, useContext, useEffect, useMemo, useState } from "react"; + +const AuthContext = createContext(null); + +function getStoredToken() { + try { + return localStorage.getItem("authToken") || ""; + } catch { + return ""; + } +} + +function persistToken(token) { + try { + if (token) { + localStorage.setItem("authToken", token); + } else { + localStorage.removeItem("authToken"); + } + } catch { + // ignore storage issues + } +} + +export function AuthProvider({ children }) { + const [token, setToken] = useState(getStoredToken); + const [user, setUser] = useState(null); + const [loading, setLoading] = useState(Boolean(getStoredToken())); + const [error, setError] = useState(null); + + useEffect(() => { + if (!token) { + setUser(null); + setLoading(false); + setError(null); + return; + } + let cancelled = false; + setLoading(true); + fetch("/api/auth/me", { + headers: { Authorization: `Bearer ${token}` } + }) + .then(async (response) => { + const data = await response.json().catch(() => ({})); + if (!response.ok) { + throw new Error(data.error || "Kon sessie niet verifiëren."); + } + if (!cancelled) { + setUser(data.user || null); + setError(null); + } + }) + .catch(() => { + if (!cancelled) { + setUser(null); + setToken(""); + persistToken(""); + } + }) + .finally(() => { + if (!cancelled) { + setLoading(false); + } + }); + return () => { + cancelled = true; + }; + }, [token]); + + async function login(credentials) { + setError(null); + const response = await fetch("/api/auth/login", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify(credentials) + }); + const data = await response.json().catch(() => ({})); + if (!response.ok) { + throw new Error(data.error || "Login mislukt."); + } + setToken(data.token); + persistToken(data.token); + setUser(data.user); + return data.user; + } + + async function register(credentials) { + setError(null); + const response = await fetch("/api/auth/register", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify(credentials) + }); + const data = await response.json().catch(() => ({})); + if (!response.ok) { + throw new Error(data.error || "Registratie mislukt."); + } + setToken(data.token); + persistToken(data.token); + setUser(data.user); + return data.user; + } + + function logout() { + setToken(""); + persistToken(""); + setUser(null); + } + + const authFetch = useMemo(() => { + return (url, options = {}) => { + const headers = { + ...(options.headers || {}), + ...(token ? { Authorization: `Bearer ${token}` } : {}) + }; + return fetch(url, { ...options, headers }); + }; + }, [token]); + + const value = { + user, + token, + loading, + error, + login, + register, + logout, + authFetch + }; + + return {children}; +} + +export function useAuth() { + const ctx = useContext(AuthContext); + if (!ctx) { + throw new Error("useAuth moet binnen een AuthProvider gebruikt worden"); + } + return ctx; +} diff --git a/src/main.jsx b/src/main.jsx index 0a98d00..b20ed23 100644 --- a/src/main.jsx +++ b/src/main.jsx @@ -2,12 +2,15 @@ import React from "react"; import { createRoot } from "react-dom/client"; import { BrowserRouter } from "react-router-dom"; import App from "./App.jsx"; +import { AuthProvider } from "./context/AuthContext.jsx"; import "./index.css"; createRoot(document.getElementById("root")).render( - + + + ); diff --git a/src/pages/Home.jsx b/src/pages/Home.jsx new file mode 100644 index 0000000..4eae28a --- /dev/null +++ b/src/pages/Home.jsx @@ -0,0 +1,89 @@ +import { useEffect, useState } from "react"; +import { Link } from "react-router-dom"; + +export default function Home() { + const [plugins, setPlugins] = useState([]); + const [loading, setLoading] = useState(true); + const [error, setError] = useState(null); + const [lastSync, setLastSync] = useState(null); + + useEffect(() => { + async function loadPlugins() { + try { + const response = await fetch("/api/plugins"); + if (!response.ok) { + throw new Error("Kon plugins niet laden"); + } + const data = await response.json(); + setPlugins(data.items || []); + setLastSync(data.updatedAt); + } catch (err) { + setError("Laden van GitHub data is mislukt."); + } finally { + setLoading(false); + } + } + + loadPlugins(); + }, []); + + return ( +
+
+
+

WordPress plugin overzicht

+

Siti Plugin Repo

+

Al je publieke WordPress plugins op één plek.

+
+ + GitHub SitiWeb + +
+ +
+ {loading &&
Bezig met laden…
} + {error &&
{error}
} + {!loading && !error && plugins.length === 0 && ( +
Geen repositories gevonden.
+ )} + {plugins.map((plugin) => { + const displayName = plugin.manifest?.plugin_name || plugin.name; + const description = plugin.manifest?.description || plugin.description; + return ( +
+
+

{displayName}

+ {plugin.fullName} +
+

{description}

+
+ ★ {plugin.stars} + Forks {plugin.forks} + Issues {plugin.issues} +
+ {plugin.topics.length > 0 && ( +
+ {plugin.topics.slice(0, 4).map((topic) => ( + {topic} + ))} +
+ )} +
+ + Bekijk details → + + + GitHub + +
+
+ ); + })} +
+ +
+ Laatste sync: {lastSync ? new Date(lastSync).toLocaleString("nl-NL") : "-"} +
+
+ ); +} diff --git a/src/pages/LicenseManager.jsx b/src/pages/LicenseManager.jsx new file mode 100644 index 0000000..47426eb --- /dev/null +++ b/src/pages/LicenseManager.jsx @@ -0,0 +1,476 @@ +import { useCallback, useEffect, useMemo, useState } from "react"; +import LicenseCard from "../components/LicenseCard.jsx"; +import { formatDateTime } from "../utils/dates.js"; +import { useAuth } from "../context/AuthContext.jsx"; + +export default function LicenseManager() { + const { user, token, authFetch, login, register: registerUser, loading: authLoading } = useAuth(); + const [licenses, setLicenses] = useState([]); + const [plugins, setPlugins] = useState([]); + const [selectedPluginId, setSelectedPluginId] = useState(""); + const [label, setLabel] = useState(""); + const [note, setNote] = useState(""); + const [loading, setLoading] = useState(true); + const [error, setError] = useState(null); + const [creating, setCreating] = useState(false); + const [refreshing, setRefreshing] = useState(false); + const [lastSync, setLastSync] = useState(null); + const [formStatus, setFormStatus] = useState(null); + const [verifyStatus, setVerifyStatus] = useState(null); + const [verifying, setVerifying] = useState(false); + const [verifyKey, setVerifyKey] = useState(""); + const [verifyHostname, setVerifyHostname] = useState(""); + + const isAuthenticated = Boolean(user && token); + + useEffect(() => { + let cancelled = false; + async function loadPlugins() { + setLoading(true); + setError(null); + try { + const response = await fetch("/api/plugins"); + const data = await response.json().catch(() => ({})); + if (!response.ok) { + throw new Error(data.error || "Kon plugins niet laden."); + } + if (cancelled) return; + setPlugins(data.items || []); + const firstPlugin = data.items?.[0]; + if (firstPlugin) { + const defaultId = firstPlugin.ownerRepo || firstPlugin.fullName; + setSelectedPluginId((prev) => prev || defaultId); + } + } catch (err) { + if (!cancelled) { + setError(err.message || "Kon plugins niet laden."); + } + } finally { + if (!cancelled) { + setLoading(false); + } + } + } + loadPlugins(); + return () => { + cancelled = true; + }; + }, []); + + const refreshLicenses = useCallback( + async (showStatus = true) => { + if (!token) { + setLicenses([]); + setLastSync(null); + if (showStatus) { + setFormStatus({ variant: "error", message: "Log in om licenties te beheren." }); + } + return; + } + if (showStatus) { + setFormStatus(null); + } + setRefreshing(true); + try { + const response = await authFetch("/api/licenses"); + const data = await response.json().catch(() => ({})); + if (response.status === 401) { + throw new Error("Sessie verlopen, log opnieuw in."); + } + if (!response.ok) { + throw new Error(data.error || "Kon licenties niet laden."); + } + setLicenses(data.items || []); + setLastSync(data.updatedAt); + } catch (err) { + if (showStatus) { + setFormStatus({ variant: "error", message: err.message }); + } + } finally { + setRefreshing(false); + } + }, + [authFetch, token] + ); + + useEffect(() => { + refreshLicenses(false); + }, [refreshLicenses]); + + useEffect(() => { + if (!selectedPluginId && plugins.length > 0) { + const fallback = plugins[0].ownerRepo || plugins[0].fullName; + setSelectedPluginId(fallback); + } + }, [plugins, selectedPluginId]); + + const selectedPlugin = useMemo( + () => plugins.find((plugin) => (plugin.ownerRepo || plugin.fullName) === selectedPluginId) || null, + [plugins, selectedPluginId] + ); + + const sortedLicenses = useMemo(() => { + const getTime = (value) => (value ? new Date(value).getTime() : 0); + return [...licenses].sort((a, b) => getTime(b.createdAt) - getTime(a.createdAt)); + }, [licenses]); + + async function handleCreateLicense(event) { + event.preventDefault(); + setFormStatus(null); + if (!isAuthenticated) { + setFormStatus({ variant: "error", message: "Log in om een licentie aan te maken." }); + return; + } + if (!selectedPlugin) { + setFormStatus({ variant: "error", message: "Selecteer een plugin." }); + return; + } + setCreating(true); + try { + const payload = { + label: + label.trim() || + selectedPlugin.manifest?.plugin_name || + selectedPlugin.name || + selectedPlugin.fullName, + note: note.trim() || undefined, + repo: { + repo: selectedPlugin.ownerRepo || selectedPlugin.fullName, + provider: selectedPlugin.provider || "github", + baseUrl: selectedPlugin.baseUrl + } + }; + const response = await authFetch("/api/licenses", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify(payload) + }); + const data = await response.json().catch(() => ({})); + if (response.status === 401) { + throw new Error("Sessie verlopen, log opnieuw in."); + } + if (!response.ok) { + throw new Error(data.error || "Licentie aanmaken mislukt."); + } + setLicenses((prev) => [data, ...prev]); + setFormStatus({ variant: "success", message: "Licentie aangemaakt." }); + setLabel(""); + setNote(""); + } catch (err) { + setFormStatus({ variant: "error", message: err.message }); + } finally { + setCreating(false); + } + } + + async function handleVerifyLicense(event) { + event.preventDefault(); + setVerifyStatus(null); + if (!verifyKey.trim() || !verifyHostname.trim()) { + setVerifyStatus({ ok: false, message: "Vul zowel licentiecode als hostname in." }); + return; + } + setVerifying(true); + try { + const response = await fetch("/api/licenses/verify", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + key: verifyKey.trim(), + hostname: verifyHostname.trim() + }) + }); + const data = await response.json().catch(() => ({})); + if (!response.ok) { + throw new Error(data.error || "Controle mislukt."); + } + setVerifyStatus({ ok: true, data }); + if (data.license) { + setLicenses((prev) => prev.map((license) => (license.key === data.license.key ? data.license : license))); + } + } catch (err) { + setVerifyStatus({ ok: false, message: err.message }); + } finally { + setVerifying(false); + } + } + + const handleLogin = useCallback( + async (credentials) => { + await login(credentials); + await refreshLicenses(false); + }, + [login, refreshLicenses] + ); + + const handleRegister = useCallback( + async (payload) => { + await registerUser(payload); + await refreshLicenses(false); + }, + [registerUser, refreshLicenses] + ); + + const isLoadingState = loading || (authLoading && Boolean(token)); + + return ( +
+
+
+

Licentiebeheer

+

Licenties

+

+ Maak licenties voor iedere plugin en beheer welke hostname de licentie daadwerkelijk gebruikt. +

+

+ Een licentie is geldig voor één hostname. De eerste hostname die controleert wordt automatisch gekoppeld als + licentiehouder. +

+
+ +
+ +
+ Actieve licenties: {licenses.length} + Laatste update: {formatDateTime(lastSync)} + {user && Ingelogd als: {user.email}} +
+ + {isLoadingState &&
Bezig met laden…
} + {error &&
{error}
} + + {!isLoadingState && !error && ( + <> +
+ {isAuthenticated ? ( +
+

Nieuwe licentie

+

Kies een plugin en genereer direct een licentiesleutel.

+
+ + +