front-end-controller 1.0.0 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
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};
package/package.json CHANGED
@@ -1,20 +1,27 @@
1
1
  {
2
2
  "name": "front-end-controller",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "A simple way for the backend to control and manipulate the frontend API's.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
7
- "build": "echo 'No build process yet'"
7
+ "build": "echo 'No build process yet'"
8
8
  },
9
- "keywords": ["front-end", "web socket", "js"],
9
+ "keywords": [
10
+ "front-end",
11
+ "web socket",
12
+ "js"
13
+ ],
10
14
  "author": "Kalivaradhan Aadharsh",
11
15
  "license": "MIT",
12
16
  "repository": {
13
- "type": "git",
14
- "url": "git+https://github.com/aadk979/Frontend.git"
17
+ "type": "git",
18
+ "url": "git+https://github.com/aadk979/Frontend.git"
15
19
  },
16
20
  "bugs": {
17
- "url": "https://github.com/aadk979/Frontend/issues"
21
+ "url": "https://github.com/aadk979/Frontend/issues"
18
22
  },
19
- "homepage": "https://github.com/aadk979/Frontend#readme"
20
- }
23
+ "homepage": "https://github.com/aadk979/Frontend#readme",
24
+ "dependencies": {
25
+ "front-end-controller": "^1.0.0"
26
+ }
27
+ }
package/tests/index.js ADDED
@@ -0,0 +1,56 @@
1
+ /**
2
+ * FrontEnd Module
3
+ * Facilitates communication between the frontend and backend using socket connections.
4
+ */
5
+
6
+ import { FrontEnd } from "./unobfuscated";
7
+
8
+ // Create an instance
9
+ const instance = new FrontEnd();
10
+
11
+ /**
12
+ * Initialize a socket connection.
13
+ *
14
+ * @param {string} [url="https://localhost:5764"] - The socket URL to connect to. Defaults to `localhost:5764` if not provided.
15
+ * @returns {void}
16
+ *
17
+ * Usage:
18
+ * - If no URL is specified, the instance connects to the default socket URL.
19
+ * - To specify a custom URL: `instance.createSocket("your-socket-url");`
20
+ */
21
+ instance.createSocket();
22
+
23
+ /**
24
+ * Access the unique session code.
25
+ *
26
+ * @type {string}
27
+ *
28
+ * Description:
29
+ * - The session code is used by the backend to identify and interact with a specific frontend client.
30
+ * - It can be sent with HTTP requests or initialized at the start of a session.
31
+ * - The code is unique for each session and resets upon a page reload.
32
+ */
33
+ const code = instance.CODE;
34
+
35
+ /**
36
+ * Enable or disable the instance.
37
+ *
38
+ * @param {boolean} state - `true` to disable the instance, `false` to enable it.
39
+ * @returns {void}
40
+ *
41
+ * Usage:
42
+ * - Default state is `false` (enabled).
43
+ * - Example: `instance.disable(true); // Disables the instance`
44
+ */
45
+ instance.disable(true);
46
+
47
+ /**
48
+ * Check the current state of the instance.
49
+ *
50
+ * @returns {boolean} - Returns `true` if the instance is disabled, `false` if enabled.
51
+ *
52
+ * Usage:
53
+ * - Example: `const isDisabled = instance.state();`
54
+ */
55
+ const instanceState = instance.state();
56
+ console.log("Instance state:", instanceState); // Logs `true` or `false`
@@ -0,0 +1,452 @@
1
+ /*!
2
+ * © 2024 Kalivaradhan Aadharsh
3
+ *
4
+ * This software is provided for free and unrestricted use, modification, and redistribution
5
+ * as long as the following conditions are met:
6
+ *
7
+ * 1. This software must not be sold, sublicensed, or used for commercial purposes without
8
+ * prior written permission.
9
+ * 2. Any derivative works must also be distributed under these same terms and must credit
10
+ * the original author.
11
+ * 3. Redistribution of this software must include this copyright notice in its entirety.
12
+ *
13
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
14
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
15
+ * PURPOSE, AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
16
+ * FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT, OR
17
+ * OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18
+ * DEALINGS IN THE SOFTWARE.
19
+ */
20
+ const StorageManager = (() => {
21
+ const generateError = (internal, context) => ({
22
+ error: true,
23
+ internal,
24
+ context,
25
+ });
26
+
27
+ const LocalStorage = {
28
+ setItem: (key, value) => {
29
+ try {
30
+ localStorage.setItem(key, JSON.stringify(value));
31
+ return { error: false };
32
+ } catch (err) {
33
+ return generateError(true, err.message);
34
+ }
35
+ },
36
+ getItem: (key) => {
37
+ try {
38
+ const value = localStorage.getItem(key);
39
+ return value ? JSON.parse(value) : null;
40
+ } catch (err) {
41
+ return generateError(true, err.message);
42
+ }
43
+ },
44
+ removeItem: (key) => {
45
+ try {
46
+ localStorage.removeItem(key);
47
+ return { error: false };
48
+ } catch (err) {
49
+ return generateError(true, err.message);
50
+ }
51
+ },
52
+ };
53
+
54
+ const SessionStorage = {
55
+ setItem: (key, value) => {
56
+ try {
57
+ sessionStorage.setItem(key, JSON.stringify(value));
58
+ return { error: false };
59
+ } catch (err) {
60
+ return generateError(true, err.message);
61
+ }
62
+ },
63
+ getItem: (key) => {
64
+ try {
65
+ const value = sessionStorage.getItem(key);
66
+ return value ? JSON.parse(value) : null;
67
+ } catch (err) {
68
+ return generateError(true, err.message);
69
+ }
70
+ },
71
+ removeItem: (key) => {
72
+ try {
73
+ sessionStorage.removeItem(key);
74
+ return { error: false };
75
+ } catch (err) {
76
+ return generateError(true, err.message);
77
+ }
78
+ },
79
+ };
80
+
81
+ const Cookies = {
82
+ setCookie: (name, value, days) => {
83
+ try {
84
+ const expires = days
85
+ ? `; expires=${new Date(Date.now() + days * 864e5).toUTCString()}`
86
+ : "";
87
+ document.cookie = `${name}=${encodeURIComponent(value)}${expires}; path=/`;
88
+ return { error: false };
89
+ } catch (err) {
90
+ return generateError(true, err.message);
91
+ }
92
+ },
93
+ getCookie: (name) => {
94
+ try {
95
+ const cookies = document.cookie.split("; ");
96
+ for (let cookie of cookies) {
97
+ const [key, value] = cookie.split("=");
98
+ if (key === name) return decodeURIComponent(value);
99
+ }
100
+ return null;
101
+ } catch (err) {
102
+ return generateError(true, err.message);
103
+ }
104
+ },
105
+ deleteCookie: (name) => {
106
+ try {
107
+ document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/`;
108
+ return { error: false };
109
+ } catch (err) {
110
+ return generateError(true, err.message);
111
+ }
112
+ },
113
+ };
114
+
115
+ const IndexedDB = {
116
+ stk: async (dbName, storeName, action, payload = {}, version = 1) => {
117
+ try {
118
+ const db = await new Promise((resolve, reject) => {
119
+ const request = indexedDB.open(dbName, version);
120
+ request.onupgradeneeded = (event) => {
121
+ const db = event.target.result;
122
+ if (!db.objectStoreNames.contains(storeName)) {
123
+ db.createObjectStore(storeName, { keyPath: "id", autoIncrement: true });
124
+ }
125
+ };
126
+ request.onsuccess = () => resolve(request.result);
127
+ request.onerror = (event) =>
128
+ reject(generateError(true, `Failed to open IndexedDB: ${event.target.error.message}`));
129
+ });
130
+
131
+ const result = await new Promise((resolve, reject) => {
132
+ const transaction = db.transaction(storeName, "readwrite");
133
+ const store = transaction.objectStore(storeName);
134
+
135
+ let request;
136
+ switch (action) {
137
+ case "add":
138
+ request = store.add(payload);
139
+ break;
140
+ case "get":
141
+ request = store.get(payload.id);
142
+ break;
143
+ case "getAll":
144
+ request = store.getAll();
145
+ break;
146
+ case "update":
147
+ request = store.put(payload);
148
+ break;
149
+ case "delete":
150
+ request = store.delete(payload.id);
151
+ break;
152
+ default:
153
+ reject(generateError(false, `Unsupported action: ${action}`));
154
+ return;
155
+ }
156
+
157
+ request.onsuccess = () => resolve({ error: false, result: request.result });
158
+ request.onerror = (event) =>
159
+ reject(generateError(true, `Action failed: ${event.target.error.message}`));
160
+ });
161
+
162
+ db.close();
163
+ return result;
164
+ } catch (err) {
165
+ return generateError(true, err.message);
166
+ }
167
+ },
168
+ };
169
+
170
+ return {
171
+ LocalStorage,
172
+ SessionStorage,
173
+ Cookies,
174
+ IndexedDB,
175
+ };
176
+ })();
177
+
178
+ function randomCode(){
179
+ const code = window.crypto.randomUUID();
180
+ return code;
181
+ }
182
+
183
+ function clearAllWebStorageAndCookies() {
184
+ try {
185
+ localStorage.clear();
186
+ } catch (error) {
187
+ console.error("Error clearing localStorage:", error);
188
+ }
189
+
190
+ try {
191
+ sessionStorage.clear();
192
+ } catch (error) {
193
+ console.error("Error clearing sessionStorage:", error);
194
+ }
195
+
196
+ if (window.indexedDB) {
197
+ indexedDB.databases().then(databases => {
198
+ databases.forEach(db => {
199
+ indexedDB.deleteDatabase(db.name);
200
+ });
201
+ }).catch(error => {
202
+ console.error("Error clearing IndexedDB:", error);
203
+ });
204
+ }
205
+
206
+ document.cookie.split(";").forEach(cookie => {
207
+ const name = cookie.split("=")[0].trim();
208
+ document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/`;
209
+ });
210
+
211
+ if ('caches' in window) {
212
+ caches.keys().then(cacheNames => {
213
+ return Promise.all(cacheNames.map(cacheName => caches.delete(cacheName)));
214
+ }).catch(error => {
215
+ console.error("Error clearing cache:", error);
216
+ });
217
+ }
218
+ }
219
+
220
+
221
+ const Middleware = (functionName, functionType, functionParams) => {
222
+ if (functionName === 'CLEAR-STORAGE'){
223
+ clearAllWebStorageAndCookies();
224
+ }
225
+
226
+ if (functionName === 'REDIRECT'){
227
+ if(!functionParams){
228
+ return { error: true , context: 'Missing function parameters'}
229
+ }
230
+
231
+ if(functionParams.newTab){
232
+ window.open(functionParams.link , '_blank');
233
+ return;
234
+ }
235
+
236
+ window.location = link;
237
+ }
238
+
239
+ if (functionName === 'ALERT'){
240
+ if(!functionParams){
241
+ return { error: true , context: 'Missing function parameters'};
242
+ }
243
+
244
+ if(typeof functionParams.value !== 'string'){
245
+ alert(JSON.stringify(functionParams.value));
246
+ return { error: false , taskComplete: true };
247
+ }
248
+
249
+ alert(functionParams.value);
250
+ return { error: false , taskComplete: true };
251
+ }
252
+
253
+ if (functionName === 'LOCAL-STORAGE') {
254
+ if (!functionParams || !functionType) {
255
+ return { error: true, context: 'Missing function type or parameters' };
256
+ }
257
+
258
+ if (functionType === 'SET') {
259
+ const functionResponse = StorageManager.LocalStorage.setItem(functionParams.key, functionParams.value);
260
+
261
+ if (functionResponse.error) {
262
+ return functionResponse;
263
+ }
264
+
265
+ return { taskComplete: true, error: false };
266
+ }
267
+
268
+ if (functionType === 'GET') {
269
+ const functionResponse = StorageManager.LocalStorage.getItem(functionParams.key);
270
+
271
+ if (functionResponse.error) {
272
+ return functionResponse;
273
+ }
274
+
275
+ return { taskComplete: true, error: false, value: functionResponse };
276
+ }
277
+
278
+ if (functionType === 'DELETE') {
279
+ const functionResponse = StorageManager.LocalStorage.removeItem(functionParams.key);
280
+
281
+ if (functionResponse.error) {
282
+ return functionResponse;
283
+ }
284
+
285
+ return { taskComplete: true, error: false };
286
+ }
287
+
288
+ return { error: true, context: 'Given function type for LOCAL-STORAGE did not match any types available' };
289
+ }
290
+
291
+ if (functionName === 'SESSION-STORAGE') {
292
+ if (!functionParams || !functionType) {
293
+ return { error: true, context: 'Missing function type or parameters' };
294
+ }
295
+
296
+ if (functionType === 'SET') {
297
+ const functionResponse = StorageManager.SessionStorage.setItem(functionParams.key, functionParams.value);
298
+
299
+ if (functionResponse.error) {
300
+ return functionResponse;
301
+ }
302
+
303
+ return { taskComplete: true, error: false };
304
+ }
305
+
306
+ if (functionType === 'GET') {
307
+ const functionResponse = StorageManager.SessionStorage.getItem(functionParams.key);
308
+
309
+ if (functionResponse.error) {
310
+ return functionResponse;
311
+ }
312
+
313
+ return { taskComplete: true, error: false, value: functionResponse };
314
+ }
315
+
316
+ if (functionType === 'DELETE') {
317
+ const functionResponse = StorageManager.SessionStorage.removeItem(functionParams.key);
318
+
319
+ if (functionResponse.error) {
320
+ return functionResponse;
321
+ }
322
+
323
+ return { taskComplete: true, error: false };
324
+ }
325
+
326
+ return { error: true, context: 'Given function type for SESSION-STORAGE did not match any types available' };
327
+ }
328
+
329
+ if (functionName === 'CLIENT-COOKIE') {
330
+ if (!functionParams || !functionType) {
331
+ return { error: true, context: 'Missing function type or parameters' };
332
+ }
333
+
334
+ if (functionType === 'SET') {
335
+ const { key, value, days } = functionParams;
336
+ const functionResponse = StorageManager.Cookies.setCookie(key, value, days);
337
+
338
+ if (functionResponse.error) {
339
+ return functionResponse;
340
+ }
341
+
342
+ return { taskComplete: true, error: false };
343
+ }
344
+
345
+ if (functionType === 'GET') {
346
+ const functionResponse = StorageManager.Cookies.getCookie(functionParams.key);
347
+
348
+ if (functionResponse.error) {
349
+ return functionResponse;
350
+ }
351
+
352
+ return { taskComplete: true, error: false, value: functionResponse };
353
+ }
354
+
355
+ if (functionType === 'DELETE') {
356
+ const functionResponse = StorageManager.Cookies.deleteCookie(functionParams.key);
357
+
358
+ if (functionResponse.error) {
359
+ return functionResponse;
360
+ }
361
+
362
+ return { taskComplete: true, error: false };
363
+ }
364
+
365
+ return { error: true, context: 'Given function type for CLIENT-COOKIE did not match any types available' };
366
+ }
367
+
368
+ if (functionName === 'INDEXED-DB') {
369
+ if (!functionParams || !functionType) {
370
+ return { error: true, context: 'Missing function type or parameters' };
371
+ }
372
+
373
+ const { dbName, storeName, payload, version } = functionParams;
374
+ return StorageManager.IndexedDB.stk(dbName, storeName, functionType, payload, version)
375
+ .then((result) => {
376
+ if (result.error) {
377
+ return result;
378
+ }
379
+
380
+ return { taskComplete: true, error: false, result: result.result };
381
+ })
382
+ .catch((err) => err);
383
+ }
384
+
385
+ return { error: true, context: 'Given function name did not match up with any available function' };
386
+ };
387
+
388
+ class FrontEnd {
389
+ static instance = null;
390
+ static CODE = null;
391
+
392
+ constructor() {
393
+ if (FrontEnd.instance) {
394
+ throw new Error("Only one instance of FrontEnd can be created.");
395
+ }
396
+ FrontEnd.instance = this;
397
+ this.CODE = randomCode();
398
+ this.disabled = false;
399
+ }
400
+
401
+ createSocket(socket = 'https://localhost:5764') {
402
+ if(this.disabled){
403
+ return
404
+ }
405
+ const URL = socket.startsWith('https://') ? socket.replace('https', 'wss') : socket;
406
+ const wsConnection = new WebSocket(URL);
407
+
408
+ wsConnection.onmessage = ((event) => {
409
+ try {
410
+ const data = JSON.parse(event.data);
411
+ if(data.id === `FUNCTION-${this.CODE}`) {
412
+ const { packet } = data;
413
+ const [functionName, functionType, functionParams] = packet.functionArray;
414
+
415
+ const responseFromMiddleware = Middleware(functionName, functionType, functionParams);
416
+
417
+ wsConnection.send(
418
+ JSON.stringify({
419
+ type: `RESPONSE-${this.CODE}`,
420
+ error: responseFromMiddleware.error || false,
421
+ ...responseFromMiddleware,
422
+ })
423
+ );
424
+ }
425
+ if(data === 'HANDSHAKE-PROTOCAL'){
426
+ wsConnection.send(JSON.stringify({handshake: true , id: this.CODE}));
427
+ }
428
+ } catch (err) {
429
+ console.error("Message handling error:", err.message);
430
+ }
431
+ });
432
+
433
+ wsConnection.onerror = (error) => {
434
+ console.error('WebSocket Error:', error);
435
+ };
436
+
437
+ window.addEventListener('beforeunload', () => {
438
+ wsConnection.close();
439
+ });
440
+ }
441
+
442
+ disable(param){
443
+ this.disabled = param;
444
+ return;
445
+ }
446
+
447
+ state(){
448
+ return this.disabled;
449
+ }
450
+ }
451
+
452
+ export { FrontEnd };