front-end-controller 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.js +1 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
@@ -16,6 +16,5 @@
|
|
16
16
|
* FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT, OR
|
17
17
|
* OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
18
18
|
* DEALINGS IN THE SOFTWARE.
|
19
|
-
* Github: https://github.com/aadk979/Frontend.git
|
20
19
|
*/
|
21
|
-
function a0_0x3d46(_0x366be8,_0x5965f2){const _0x143bde=a0_0x143b();return a0_0x3d46=function(_0x3d46cb,_0x2e0861){_0x3d46cb=_0x3d46cb-0x184;let _0x154ba8=_0x143bde[_0x3d46cb];return _0x154ba8;},a0_0x3d46(_0x366be8,_0x5965f2);}const a0_0x4ad946=a0_0x3d46;(function(_0x295f27,_0x5e7d91){const _0xb3b2b9=a0_0x3d46,_0x14f10c=_0x295f27();while(!![]){try{const _0x54da0d=-parseInt(_0xb3b2b9(0x19b))/0x1*(-parseInt(_0xb3b2b9(0x197))/0x2)+-parseInt(_0xb3b2b9(0x192))/0x3*(parseInt(_0xb3b2b9(0x1c5))/0x4)+parseInt(_0xb3b2b9(0x1d3))/0x5+parseInt(_0xb3b2b9(0x1c1))/0x6+parseInt(_0xb3b2b9(0x1a4))/0x7*(parseInt(_0xb3b2b9(0x1e3))/0x8)+parseInt(_0xb3b2b9(0x1d0))/0x9+-parseInt(_0xb3b2b9(0x1cd))/0xa;if(_0x54da0d===_0x5e7d91)break;else _0x14f10c['push'](_0x14f10c['shift']());}catch(_0x4e69a8){_0x14f10c['push'](_0x14f10c['shift']());}}}(a0_0x143b,0x9196b));const StorageManager=((()=>{const _0x253cbc=(_0x313380,_0x167efc)=>({'error':!![],'internal':_0x313380,'context':_0x167efc}),_0x2c34a8={'setItem':(_0x4f278e,_0x5247df)=>{const _0x3fb6b8=a0_0x3d46;try{return localStorage[_0x3fb6b8(0x1a3)](_0x4f278e,JSON[_0x3fb6b8(0x1ac)](_0x5247df)),{'error':![]};}catch(_0x505152){return _0x253cbc(!![],_0x505152['message']);}},'getItem':_0x586292=>{const _0x3bb253=a0_0x3d46;try{const _0xaf962d=localStorage[_0x3bb253(0x18e)](_0x586292);return _0xaf962d?JSON[_0x3bb253(0x1da)](_0xaf962d):null;}catch(_0x5a449e){return _0x253cbc(!![],_0x5a449e[_0x3bb253(0x1ca)]);}},'removeItem':_0x49df42=>{const _0x41d9de=a0_0x3d46;try{return localStorage[_0x41d9de(0x1b1)](_0x49df42),{'error':![]};}catch(_0x376f56){return _0x253cbc(!![],_0x376f56['message']);}}},_0x43ba91={'setItem':(_0x53c4e6,_0x206a09)=>{const _0x9e00dd=a0_0x3d46;try{return sessionStorage[_0x9e00dd(0x1a3)](_0x53c4e6,JSON[_0x9e00dd(0x1ac)](_0x206a09)),{'error':![]};}catch(_0x27b7fc){return _0x253cbc(!![],_0x27b7fc[_0x9e00dd(0x1ca)]);}},'getItem':_0x49a6ec=>{const _0xc92379=a0_0x3d46;try{const _0x2875f9=sessionStorage[_0xc92379(0x18e)](_0x49a6ec);return _0x2875f9?JSON['parse'](_0x2875f9):null;}catch(_0x316488){return _0x253cbc(!![],_0x316488['message']);}},'removeItem':_0x3d97ab=>{const _0x106a4d=a0_0x3d46;try{return sessionStorage['removeItem'](_0x3d97ab),{'error':![]};}catch(_0x13c79a){return _0x253cbc(!![],_0x13c79a[_0x106a4d(0x1ca)]);}}},_0x4ffafa={'setCookie':(_0x420f5a,_0xd27908,_0x55888e)=>{const _0x425761=a0_0x3d46;try{const _0x5548b5=_0x55888e?';\x20expires='+new Date(Date['now']()+_0x55888e*0x5265c00)[_0x425761(0x1b0)]():'';return document['cookie']=_0x420f5a+'='+encodeURIComponent(_0xd27908)+_0x5548b5+_0x425761(0x1e1),{'error':![]};}catch(_0x198a0e){return _0x253cbc(!![],_0x198a0e['message']);}},'getCookie':_0x5b19c2=>{const _0x44b5be=a0_0x3d46;try{const _0x4ff53f=document[_0x44b5be(0x190)][_0x44b5be(0x188)](';\x20');for(let _0x4a1c9f of _0x4ff53f){const [_0x39a6dc,_0x1737cc]=_0x4a1c9f[_0x44b5be(0x188)]('=');if(_0x39a6dc===_0x5b19c2)return decodeURIComponent(_0x1737cc);}return null;}catch(_0x542f4b){return _0x253cbc(!![],_0x542f4b[_0x44b5be(0x1ca)]);}},'deleteCookie':_0x3e8450=>{const _0x3a6575=a0_0x3d46;try{return document['cookie']=_0x3e8450+'=;\x20expires=Thu,\x2001\x20Jan\x201970\x2000:00:00\x20GMT;\x20path=/',{'error':![]};}catch(_0x11bce3){return _0x253cbc(!![],_0x11bce3[_0x3a6575(0x1ca)]);}}},_0xc1f5be={'stk':async(_0x16b9de,_0x4bd35e,_0x231518,_0x4c69b9={},_0x17f698=0x1)=>{const _0x12c9e1=a0_0x3d46;try{const _0x56fe6a=await new Promise((_0x4f19c9,_0x2af28f)=>{const _0xf20c0=a0_0x3d46,_0x284d8b=indexedDB[_0xf20c0(0x1d2)](_0x16b9de,_0x17f698);_0x284d8b[_0xf20c0(0x1ba)]=_0x160422=>{const _0x1742ac=_0xf20c0,_0x387086=_0x160422[_0x1742ac(0x1c2)]['result'];!_0x387086[_0x1742ac(0x1e5)][_0x1742ac(0x1be)](_0x4bd35e)&&_0x387086[_0x1742ac(0x1db)](_0x4bd35e,{'keyPath':'id','autoIncrement':!![]});},_0x284d8b[_0xf20c0(0x18d)]=()=>_0x4f19c9(_0x284d8b[_0xf20c0(0x1dc)]),_0x284d8b[_0xf20c0(0x1cc)]=_0x136449=>_0x2af28f(_0x253cbc(!![],'Failed\x20to\x20open\x20IndexedDB:\x20'+_0x136449[_0xf20c0(0x1c2)][_0xf20c0(0x1b3)][_0xf20c0(0x1ca)]));}),_0x5a07ff=await new Promise((_0x4b67bd,_0x356688)=>{const _0x17f201=a0_0x3d46,_0x17a207=_0x56fe6a[_0x17f201(0x199)](_0x4bd35e,'readwrite'),_0x5ad93e=_0x17a207[_0x17f201(0x193)](_0x4bd35e);let _0xea2a56;switch(_0x231518){case _0x17f201(0x1c0):_0xea2a56=_0x5ad93e['add'](_0x4c69b9);break;case _0x17f201(0x1cb):_0xea2a56=_0x5ad93e['get'](_0x4c69b9['id']);break;case'getAll':_0xea2a56=_0x5ad93e[_0x17f201(0x1e4)]();break;case'update':_0xea2a56=_0x5ad93e['put'](_0x4c69b9);break;case _0x17f201(0x1c8):_0xea2a56=_0x5ad93e['delete'](_0x4c69b9['id']);break;default:_0x356688(_0x253cbc(![],_0x17f201(0x18f)+_0x231518));return;}_0xea2a56[_0x17f201(0x18d)]=()=>_0x4b67bd({'error':![],'result':_0xea2a56[_0x17f201(0x1dc)]}),_0xea2a56[_0x17f201(0x1cc)]=_0x5e2cdd=>_0x356688(_0x253cbc(!![],_0x17f201(0x1d1)+_0x5e2cdd[_0x17f201(0x1c2)][_0x17f201(0x1b3)]['message']));});return _0x56fe6a[_0x12c9e1(0x1bb)](),_0x5a07ff;}catch(_0x453f15){return _0x253cbc(!![],_0x453f15[_0x12c9e1(0x1ca)]);}}};return{'LocalStorage':_0x2c34a8,'SessionStorage':_0x43ba91,'Cookies':_0x4ffafa,'IndexedDB':_0xc1f5be};})());function randomCode(){const _0x31141e=a0_0x3d46,_0x6ae715=window[_0x31141e(0x1d6)][_0x31141e(0x186)]();return _0x6ae715;}function clearAllWebStorageAndCookies(){const _0x9af6d1=a0_0x3d46;try{localStorage[_0x9af6d1(0x19e)]();}catch(_0x32e2a6){console[_0x9af6d1(0x1b3)]('Error\x20clearing\x20localStorage:',_0x32e2a6);}try{sessionStorage[_0x9af6d1(0x19e)]();}catch(_0x3947b4){console['error'](_0x9af6d1(0x1b5),_0x3947b4);}window[_0x9af6d1(0x198)]&&indexedDB[_0x9af6d1(0x1a2)]()[_0x9af6d1(0x19d)](_0x1e2180=>{const _0x318a89=_0x9af6d1;_0x1e2180[_0x318a89(0x1b6)](_0x286888=>{const _0x64f8b7=_0x318a89;indexedDB[_0x64f8b7(0x191)](_0x286888['name']);});})[_0x9af6d1(0x1a5)](_0x3c32b6=>{const _0x5bcce3=_0x9af6d1;console[_0x5bcce3(0x1b3)](_0x5bcce3(0x1bf),_0x3c32b6);}),document[_0x9af6d1(0x190)]['split'](';')[_0x9af6d1(0x1b6)](_0x409a30=>{const _0x19d9c3=_0x9af6d1,_0x458b42=_0x409a30[_0x19d9c3(0x188)]('=')[0x0]['trim']();document[_0x19d9c3(0x190)]=_0x458b42+'=;\x20expires=Thu,\x2001\x20Jan\x201970\x2000:00:00\x20UTC;\x20path=/';}),_0x9af6d1(0x1bd)in window&&caches['keys']()['then'](_0x1e84dd=>{const _0x533578=_0x9af6d1;return Promise['all'](_0x1e84dd[_0x533578(0x1c7)](_0x303016=>caches[_0x533578(0x1c8)](_0x303016)));})[_0x9af6d1(0x1a5)](_0x56b803=>{const _0x1d488f=_0x9af6d1;console[_0x1d488f(0x1b3)](_0x1d488f(0x1aa),_0x56b803);});}const Middleware=(_0x2205ef,_0x4e2d32,_0x2a88cc)=>{const _0x5c2477=a0_0x3d46;_0x2205ef===_0x5c2477(0x18a)&&clearAllWebStorageAndCookies();if(_0x2205ef===_0x5c2477(0x1bc)){if(!_0x2a88cc)return{'error':!![],'context':_0x5c2477(0x1d8)};if(_0x2a88cc[_0x5c2477(0x1e6)]){window[_0x5c2477(0x1d2)](_0x2a88cc[_0x5c2477(0x1b8)],_0x5c2477(0x1c4));return;}window['location']=link;}if(_0x2205ef===_0x5c2477(0x1af)){if(!_0x2a88cc)return{'error':!![],'context':'Missing\x20function\x20parameters'};if(typeof _0x2a88cc[_0x5c2477(0x1de)]!==_0x5c2477(0x18b))return alert(JSON[_0x5c2477(0x1ac)](_0x2a88cc['value'])),{'error':![],'taskComplete':!![]};return alert(_0x2a88cc[_0x5c2477(0x1de)]),{'error':![],'taskComplete':!![]};}if(_0x2205ef==='LOCAL-STORAGE'){if(!_0x2a88cc||!_0x4e2d32)return{'error':!![],'context':_0x5c2477(0x1dd)};if(_0x4e2d32===_0x5c2477(0x1a6)){const _0x47c22a=StorageManager[_0x5c2477(0x189)][_0x5c2477(0x1a3)](_0x2a88cc[_0x5c2477(0x196)],_0x2a88cc[_0x5c2477(0x1de)]);if(_0x47c22a['error'])return _0x47c22a;return{'taskComplete':!![],'error':![]};}if(_0x4e2d32===_0x5c2477(0x19c)){const _0x17a7e2=StorageManager[_0x5c2477(0x189)][_0x5c2477(0x18e)](_0x2a88cc['key']);if(_0x17a7e2['error'])return _0x17a7e2;return{'taskComplete':!![],'error':![],'value':_0x17a7e2};}if(_0x4e2d32==='DELETE'){const _0x50b53c=StorageManager[_0x5c2477(0x189)][_0x5c2477(0x1b1)](_0x2a88cc[_0x5c2477(0x196)]);if(_0x50b53c[_0x5c2477(0x1b3)])return _0x50b53c;return{'taskComplete':!![],'error':![]};}return{'error':!![],'context':_0x5c2477(0x1ae)};}if(_0x2205ef==='SESSION-STORAGE'){if(!_0x2a88cc||!_0x4e2d32)return{'error':!![],'context':'Missing\x20function\x20type\x20or\x20parameters'};if(_0x4e2d32===_0x5c2477(0x1a6)){const _0x1efa94=StorageManager[_0x5c2477(0x1ab)][_0x5c2477(0x1a3)](_0x2a88cc[_0x5c2477(0x196)],_0x2a88cc[_0x5c2477(0x1de)]);if(_0x1efa94[_0x5c2477(0x1b3)])return _0x1efa94;return{'taskComplete':!![],'error':![]};}if(_0x4e2d32===_0x5c2477(0x19c)){const _0x3039da=StorageManager[_0x5c2477(0x1ab)][_0x5c2477(0x18e)](_0x2a88cc[_0x5c2477(0x196)]);if(_0x3039da[_0x5c2477(0x1b3)])return _0x3039da;return{'taskComplete':!![],'error':![],'value':_0x3039da};}if(_0x4e2d32===_0x5c2477(0x1cf)){const _0x39699a=StorageManager[_0x5c2477(0x1ab)][_0x5c2477(0x1b1)](_0x2a88cc[_0x5c2477(0x196)]);if(_0x39699a[_0x5c2477(0x1b3)])return _0x39699a;return{'taskComplete':!![],'error':![]};}return{'error':!![],'context':_0x5c2477(0x184)};}if(_0x2205ef===_0x5c2477(0x1a1)){if(!_0x2a88cc||!_0x4e2d32)return{'error':!![],'context':_0x5c2477(0x1dd)};if(_0x4e2d32===_0x5c2477(0x1a6)){const {key:_0x3b6c26,value:_0x477e79,days:_0x4de9fe}=_0x2a88cc,_0x2545d2=StorageManager['Cookies'][_0x5c2477(0x187)](_0x3b6c26,_0x477e79,_0x4de9fe);if(_0x2545d2[_0x5c2477(0x1b3)])return _0x2545d2;return{'taskComplete':!![],'error':![]};}if(_0x4e2d32===_0x5c2477(0x19c)){const _0x50e70d=StorageManager['Cookies'][_0x5c2477(0x1e2)](_0x2a88cc[_0x5c2477(0x196)]);if(_0x50e70d[_0x5c2477(0x1b3)])return _0x50e70d;return{'taskComplete':!![],'error':![],'value':_0x50e70d};}if(_0x4e2d32===_0x5c2477(0x1cf)){const _0x4a7d52=StorageManager['Cookies'][_0x5c2477(0x19a)](_0x2a88cc[_0x5c2477(0x196)]);if(_0x4a7d52[_0x5c2477(0x1b3)])return _0x4a7d52;return{'taskComplete':!![],'error':![]};}return{'error':!![],'context':_0x5c2477(0x1df)};}if(_0x2205ef===_0x5c2477(0x1d4)){if(!_0x2a88cc||!_0x4e2d32)return{'error':!![],'context':_0x5c2477(0x1dd)};const {dbName:_0x52f67c,storeName:_0xf93a3b,payload:_0x4139a4,version:_0x2b9787}=_0x2a88cc;return StorageManager[_0x5c2477(0x1a7)][_0x5c2477(0x1d7)](_0x52f67c,_0xf93a3b,_0x4e2d32,_0x4139a4,_0x2b9787)[_0x5c2477(0x19d)](_0x5a42af=>{const _0x4204fc=_0x5c2477;if(_0x5a42af[_0x4204fc(0x1b3)])return _0x5a42af;return{'taskComplete':!![],'error':![],'result':_0x5a42af[_0x4204fc(0x1dc)]};})[_0x5c2477(0x1a5)](_0x5ae3e1=>_0x5ae3e1);}return{'error':!![],'context':_0x5c2477(0x185)};};class FrontEnd{static [a0_0x4ad946(0x1b7)]=null;static [a0_0x4ad946(0x1a8)]=null;constructor(){const _0x5afc80=a0_0x4ad946;if(FrontEnd[_0x5afc80(0x1b7)])throw new Error(_0x5afc80(0x194));FrontEnd[_0x5afc80(0x1b7)]=this,this[_0x5afc80(0x1a8)]=randomCode(),this[_0x5afc80(0x18c)]=![];}[a0_0x4ad946(0x1d9)](_0x300db8=a0_0x4ad946(0x1a9)){const _0x2acc2b=a0_0x4ad946;if(this[_0x2acc2b(0x18c)])return;const _0x2fc462=_0x300db8[_0x2acc2b(0x1b4)](_0x2acc2b(0x1b2))?_0x300db8[_0x2acc2b(0x1a0)](_0x2acc2b(0x1c6),'wss'):_0x300db8,_0x55a3ca=new WebSocket(_0x2fc462);_0x55a3ca['onmessage']=_0x1941a4=>{const _0x58d903=_0x2acc2b;try{const _0x1bda77=JSON[_0x58d903(0x1da)](_0x1941a4[_0x58d903(0x1d5)]);if(_0x1bda77['id']===_0x58d903(0x1b9)+this['CODE']){const {packet:_0x56282a}=_0x1bda77,[_0x7024d4,_0x1ab020,_0xe0af88]=_0x56282a[_0x58d903(0x1ce)],_0x20e733=Middleware(_0x7024d4,_0x1ab020,_0xe0af88);_0x55a3ca[_0x58d903(0x1c9)](JSON[_0x58d903(0x1ac)]({'type':_0x58d903(0x19f)+this[_0x58d903(0x1a8)],'error':_0x20e733[_0x58d903(0x1b3)]||![],..._0x20e733}));}_0x1bda77==='HANDSHAKE-PROTOCAL'&&_0x55a3ca[_0x58d903(0x1c9)](JSON[_0x58d903(0x1ac)]({'handshake':!![],'id':this[_0x58d903(0x1a8)]}));}catch(_0x1db71f){console[_0x58d903(0x1b3)]('Message\x20handling\x20error:',_0x1db71f['message']);}},_0x55a3ca['onerror']=_0x2ec8de=>{const _0x5ec933=_0x2acc2b;console[_0x5ec933(0x1b3)](_0x5ec933(0x1ad),_0x2ec8de);},window['addEventListener'](_0x2acc2b(0x1e0),()=>{const _0x600cfd=_0x2acc2b;_0x55a3ca[_0x600cfd(0x1bb)]();});}[a0_0x4ad946(0x1c3)](_0x1f5742){this['disabled']=_0x1f5742;return;}[a0_0x4ad946(0x195)](){const _0x331e7c=a0_0x4ad946;return this[_0x331e7c(0x18c)];}}export{FrontEnd};function a0_0x143b(){const _0x17981a=['disabled','onsuccess','getItem','Unsupported\x20action:\x20','cookie','deleteDatabase','1216581JOZmqa','objectStore','Only\x20one\x20instance\x20of\x20FrontEnd\x20can\x20be\x20created.','state','key','74582FytVFW','indexedDB','transaction','deleteCookie','24Xybmhb','GET','then','clear','RESPONSE-','replace','CLIENT-COOKIE','databases','setItem','14567Sfdqwq','catch','SET','IndexedDB','CODE','https://localhost:5764','Error\x20clearing\x20cache:','SessionStorage','stringify','WebSocket\x20Error:','Given\x20function\x20type\x20for\x20LOCAL-STORAGE\x20did\x20not\x20match\x20any\x20types\x20available','ALERT','toUTCString','removeItem','https://','error','startsWith','Error\x20clearing\x20sessionStorage:','forEach','instance','link','FUNCTION-','onupgradeneeded','close','REDIRECT','caches','contains','Error\x20clearing\x20IndexedDB:','add','4008678qiAbje','target','disable','_blank','8XNcRFL','https','map','delete','send','message','get','onerror','12808800kErEoE','functionArray','DELETE','2310939bwTJWQ','Action\x20failed:\x20','open','2864475NnUKlS','INDEXED-DB','data','crypto','stk','Missing\x20function\x20parameters','createSocket','parse','createObjectStore','result','Missing\x20function\x20type\x20or\x20parameters','value','Given\x20function\x20type\x20for\x20CLIENT-COOKIE\x20did\x20not\x20match\x20any\x20types\x20available','beforeunload',';\x20path=/','getCookie','1136AtWxyn','getAll','objectStoreNames','newTab','Given\x20function\x20type\x20for\x20SESSION-STORAGE\x20did\x20not\x20match\x20any\x20types\x20available','Given\x20function\x20name\x20did\x20not\x20match\x20up\x20with\x20any\x20available\x20function','randomUUID','setCookie','split','LocalStorage','CLEAR-STORAGE','string'];a0_0x143b=function(){return _0x17981a;};return a0_0x143b();}
|
20
|
+
const StorageManager=(()=>{const generateError=(i,c)=>({error:!0,internal:i,context:c}),LocalStorage={setItem:(k,v)=>{try{return localStorage.setItem(k,JSON.stringify(v)),{error:!1}}catch(e){return generateError(!0,e.message)}},getItem:k=>{try{const v=localStorage.getItem(k);return v?JSON.parse(v):null}catch(e){return generateError(!0,e.message)}},removeItem:k=>{try{return localStorage.removeItem(k),{error:!1}}catch(e){return generateError(!0,e.message)}}},SessionStorage={setItem:(k,v)=>{try{return sessionStorage.setItem(k,JSON.stringify(v)),{error:!1}}catch(e){return generateError(!0,e.message)}},getItem:k=>{try{const v=sessionStorage.getItem(k);return v?JSON.parse(v):null}catch(e){return generateError(!0,e.message)}},removeItem:k=>{try{return sessionStorage.removeItem(k),{error:!1}}catch(e){return generateError(!0,e.message)}}},Cookies={setCookie:(n,v,d)=>{try{const x=d?`; expires=${new Date(Date.now()+d*864e5).toUTCString()}`:"";return document.cookie=`${n}=${encodeURIComponent(v)}${x}; path=/`,{error:!1}}catch(e){return generateError(!0,e.message)}},getCookie:n=>{try{const c=document.cookie.split("; ");for(let t of c){const[a,v]=t.split("=");if(a===n)return decodeURIComponent(v)}return null}catch(e){return generateError(!0,e.message)}},deleteCookie:n=>{try{return document.cookie=`${n}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/`,{error:!1}}catch(e){return generateError(!0,e.message)}}},IndexedDB={stk:async(d,s,a,p={},v=1)=>{try{const db=await new Promise((r,j)=>{const o=indexedDB.open(d,v);o.onupgradeneeded=e=>{const x=e.target.result;!x.objectStoreNames.contains(s)&&x.createObjectStore(s,{keyPath:"id",autoIncrement:!0})},o.onsuccess=()=>r(o.result),o.onerror=e=>j(generateError(!0,`Failed to open IndexedDB: ${e.target.error.message}`))});const result=await new Promise((r,j)=>{const t=db.transaction(s,"readwrite"),store=t.objectStore(s);let req;switch(a){case"add":req=store.add(p);break;case"get":req=store.get(p.id);break;case"getAll":req=store.getAll();break;case"update":req=store.put(p);break;case"delete":req=store.delete(p.id);break;default:j(generateError(!1,`Unsupported action: ${a}`));return}req.onsuccess=()=>r({error:!1,result:req.result}),req.onerror=e=>j(generateError(!0,`Action failed: ${e.target.error.message}`))});return db.close(),result}catch(e){return generateError(!0,e.message)}}};return{LocalStorage,SessionStorage,Cookies,IndexedDB}})();function randomCode(){return window.crypto.randomUUID()};function clearAllWebStorageAndCookies(){try{localStorage.clear()}catch(e){console.error("Error clearing localStorage:",e)}try{sessionStorage.clear()}catch(e){console.error("Error clearing sessionStorage:",e)}window.indexedDB&&indexedDB.databases().then(d=>{d.forEach(b=>{indexedDB.deleteDatabase(b.name)})}).catch(e=>{console.error("Error clearing IndexedDB:",e)}),document.cookie.split(";").forEach(c=>{const n=c.split("=")[0].trim();document.cookie=`${n}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/`}),"caches"in window&&caches.keys().then(k=>Promise.all(k.map(c=>caches.delete(c)))).catch(e=>{console.error("Error clearing cache:",e)})}const Middleware=(n,t,p)=>{if("CLEAR-STORAGE"===n)clearAllWebStorageAndCookies();if("REDIRECT"===n){if(!p)return{error:!0,context:"Missing function parameters"};return p.newTab?void window.open(p.link,"_blank"):void(window.location=link)}if("ALERT"===n){if(!p)return{error:!0,context:"Missing function parameters"};return"string"!=typeof p.value?(alert(JSON.stringify(p.value)),{error:!1,taskComplete:!0}):(alert(p.value),{error:!1,taskComplete:!0})}if("LOCAL-STORAGE"===n){if(!p||!t)return{error:!0,context:"Missing function type or parameters"};if("SET"===t){const r=StorageManager.LocalStorage.setItem(p.key,p.value);return r.error?r:{taskComplete:!0,error:!1}}if("GET"===t){const r=StorageManager.LocalStorage.getItem(p.key);return r.error?r:{taskComplete:!0,error:!1,value:r}}if("DELETE"===t){const r=StorageManager.LocalStorage.removeItem(p.key);return r.error?r:{taskComplete:!0,error:!1}}return{error:!0,context:"Given function type for LOCAL-STORAGE did not match any types available"}}if("SESSION-STORAGE"===n){if(!p||!t)return{error:!0,context:"Missing function type or parameters"};if("SET"===t){const r=StorageManager.SessionStorage.setItem(p.key,p.value);return r.error?r:{taskComplete:!0,error:!1}}if("GET"===t){const r=StorageManager.SessionStorage.getItem(p.key);return r.error?r:{taskComplete:!0,error:!1,value:r}}if("DELETE"===t){const r=StorageManager.SessionStorage.removeItem(p.key);return r.error?r:{taskComplete:!0,error:!1}}return{error:!0,context:"Given function type for SESSION-STORAGE did not match any types available"}}if("CLIENT-COOKIE"===n){if(!p||!t)return{error:!0,context:"Missing function type or parameters"};if("SET"===t){const{key:v,value:d,days:x}=p,r=StorageManager.Cookies.setCookie(v,d,x);return r.error?r:{taskComplete:!0,error:!1}}if("GET"===t){const r=StorageManager.Cookies.getCookie(p.key);return r.error?r:{taskComplete:!0,error:!1,value:r}}if("DELETE"===t){const r=StorageManager.Cookies.deleteCookie(p.key);return r.error?r:{taskComplete:!0,error:!1}}return{error:!0,context:"Given function type for CLIENT-COOKIE did not match any types available"}}if("INDEXED-DB"===n){if(!p||!t)return{error:!0,context:"Missing function type or parameters"};const{dbName:v,storeName:x,payload:a,version:m}=p;return StorageManager.IndexedDB.stk(v,x,t,a,m).then(r=>r.error?r:{taskComplete:!0,error:!1,result:r.result}).catch(e=>e)}return{error:!0,context:"Given function name did not match up with any available function"}};class FrontEnd{static instance=null;static CODE=null;constructor(){if(FrontEnd.instance)throw new Error("Only one instance of FrontEnd can be created.");FrontEnd.instance=this,this.CODE=randomCode(),this.disabled=!1}createSocket(s="https://localhost:5764"){if(this.disabled)return;const u=s.startsWith("https://")?s.replace("https","wss"):s,w=new WebSocket(u);w.onmessage=e=>{try{const d=JSON.parse(e.data);if(d.id===`FUNCTION-${this.CODE}`){const{packet:p}=d,[n,t,x]=p.functionArray,r=Middleware(n,t,x);w.send(JSON.stringify({type:`RESPONSE-${this.CODE}`,error:r.error||!1,...r}))}d==="HANDSHAKE-PROTOCAL"&&w.send(JSON.stringify({handshake:!0,id:this.CODE}))}catch(e){console.error("Message handling error:",e.message)}},w.onerror=e=>{console.error("WebSocket Error:",e)},window.addEventListener("beforeunload",()=>{w.close()})}disable(e){this.disabled=e}state(){return this.disabled}}export{FrontEnd};
|