@e-techsolutions/e-baas-sdk 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2037 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +2022 -1
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -2
package/dist/index.cjs
CHANGED
|
@@ -1 +1,2037 @@
|
|
|
1
|
-
'use strict';(function(stringArrayFunction,comparisonValue){function _0x3c8be3(_0x56d114,_0x542af1){return _0x20ed(_0x542af1- -0xd8,_0x56d114);}const stringArray=stringArrayFunction();while(!![]){try{const _0x181626=-parseInt(_0x3c8be3(0xf4,0x76))/0x1*(-parseInt(_0x3c8be3(-0x5f,-0x35))/0x2)+parseInt(_0x3c8be3(0xdb,0x6c))/0x3*(parseInt(_0x3c8be3(-0x28,-0x3d))/0x4)+parseInt(_0x3c8be3(-0x47,-0x1d))/0x5*(-parseInt(_0x3c8be3(0xee,0x98))/0x6)+parseInt(_0x3c8be3(-0x3,-0x52))/0x7+-parseInt(_0x3c8be3(-0x30,0x53))/0x8*(-parseInt(_0x3c8be3(-0x26,0x1))/0x9)+parseInt(_0x3c8be3(0x41,-0x15))/0xa+-parseInt(_0x3c8be3(0x41,0x95))/0xb*(parseInt(_0x3c8be3(-0x5f,0x28))/0xc);if(_0x181626===comparisonValue)break;else stringArray['push'](stringArray['shift']());}catch(_0x227be0){stringArray['push'](stringArray['shift']());}}}(_0x22b1,0x2022f));var axios=require('axios');function _0x20ed(_0x55cf9a,_0x3ce254){const _0x22b143=_0x22b1();return _0x20ed=function(_0x20edf0,_0x50c321){_0x20edf0=_0x20edf0-0x74;let _0x48b3cd=_0x22b143[_0x20edf0];if(_0x20ed['MsZBgA']===undefined){var _0x25c13e=function(_0x2f0dd6){const _0x52818a='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0xd1a62e='',_0x57adf5='';for(let _0x1bde22=0x0,_0x45f9e8,_0xa6898c,_0x356353=0x0;_0xa6898c=_0x2f0dd6['charAt'](_0x356353++);~_0xa6898c&&(_0x45f9e8=_0x1bde22%0x4?_0x45f9e8*0x40+_0xa6898c:_0xa6898c,_0x1bde22++%0x4)?_0xd1a62e+=String['fromCharCode'](0xff&_0x45f9e8>>(-0x2*_0x1bde22&0x6)):0x0){_0xa6898c=_0x52818a['indexOf'](_0xa6898c);}for(let _0x141813=0x0,_0x5062aa=_0xd1a62e['length'];_0x141813<_0x5062aa;_0x141813++){_0x57adf5+='%'+('00'+_0xd1a62e['charCodeAt'](_0x141813)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x57adf5);};_0x20ed['IYnzHf']=_0x25c13e,_0x55cf9a=arguments,_0x20ed['MsZBgA']=!![];}const _0x356518=_0x22b143[0x0],_0x120a89=_0x20edf0+_0x356518,_0x3f26a2=_0x55cf9a[_0x120a89];return!_0x3f26a2?(_0x48b3cd=_0x20ed['IYnzHf'](_0x48b3cd),_0x55cf9a[_0x120a89]=_0x48b3cd):_0x48b3cd=_0x3f26a2,_0x48b3cd;},_0x20ed(_0x55cf9a,_0x3ce254);}class EBaaSError extends Error{constructor(_0x2f0dd6,status=0x0,_0x52818a){super(_0x2f0dd6),this['name']='EBaaSError',this[_0x12fcec(0x237,0x2b7)]=status,this[_0x12fcec(0x216,0x1f7)]=_0x52818a;function _0x12fcec(_0x38f629,_0x5abf12){return _0x20ed(_0x38f629-0x132,_0x5abf12);}Error['captureStackTrace']&&Error['captureStackTrace'](this,EBaaSError);}['toJSON'](){function _0x3095d1(_0x1c07ee,_0x41ed26){return _0x20ed(_0x1c07ee-0x255,_0x41ed26);}return{'name':this[_0x3095d1(0x34a,0x390)],'message':this[_0x3095d1(0x37c,0x384)],'status':this['status'],'details':this['details'],'stack':this[_0x3095d1(0x3a1,0x390)]};}['toString'](){function _0x40063c(_0x5fd213,_0x2dd144){return _0x20ed(_0x2dd144- -0x112,_0x5fd213);}return this[_0x40063c(0x66,-0x1d)]+':\x20'+this[_0x40063c(0x85,0x15)]+_0x40063c(-0x3d,-0x1a)+this[_0x40063c(-0x41,-0xd)]+')';}}function _0x3178ce(_0x26b052,_0x11fd7a){return _0x20ed(_0x11fd7a- -0x144,_0x26b052);}class HttpClient{constructor(config){this[_0xeaa6c2(0x380,0x3b8)]=config['url'],this['apiKey']=config['apiKey'];function _0xeaa6c2(_0x359b04,_0x384335){return _0x20ed(_0x384335-0x330,_0x359b04);}this[_0xeaa6c2(0x3ab,0x3ef)]=axios['create']({'baseURL':this[_0xeaa6c2(0x405,0x3b8)],'timeout':config[_0xeaa6c2(0x4d4,0x451)]||0x2710,'headers':{'Content-Type':'application/json','apikey':this['apiKey'],...config['headers']}}),this['setupInterceptors']();}[_0x3178ce(-0x20,-0xd)](){function _0x3ef5e6(_0x10595d,_0x1a0de0){return _0x20ed(_0x10595d-0x362,_0x1a0de0);}this[_0x3ef5e6(0x421,0x3d8)][_0x3ef5e6(0x3f9,0x473)]['request']['use'](config=>{return config;},_0xd1a62e=>{function _0x3f6a8c(_0x313416,_0xf32d09){return _0x20ed(_0xf32d09-0xd7,_0x313416);}return Promise[_0x3f6a8c(0x1b6,0x176)](new EBaaSError(_0x3f6a8c(0x1f1,0x1c0),0x0,_0xd1a62e));}),this[_0x3ef5e6(0x421,0x3fb)]['interceptors']['response']['use'](response=>{return response;},_0x57adf5=>{const status=_0x57adf5['response']?.[_0x548a31(0x1ad,0x1de)]||0x0;function _0x548a31(_0x386c08,_0x2d0c72){return _0x20ed(_0x386c08-0xa8,_0x2d0c72);}const _0x1bde22=_0x57adf5['response']?.['data']?.['message']||_0x57adf5[_0x548a31(0x1cf,0x15c)]||_0x548a31(0x150,0x1d7),_0x45f9e8=_0x57adf5['response']?.['data']||_0x57adf5;return Promise[_0x548a31(0x147,0xdd)](new EBaaSError(_0x1bde22,status,_0x45f9e8));});}async[_0x3178ce(0x68,0x6)](_0xa6898c,config){function _0x13b61a(_0x5f4ed8,_0x5c2d65){return _0x20ed(_0x5f4ed8-0x172,_0x5c2d65);}try{const response=await this['client'][_0x13b61a(0x2bc,0x293)](_0xa6898c,config);return{'data':response['data'],'status':response['status'],'statusText':response[_0x13b61a(0x1f7,0x173)],'headers':response['headers']};}catch(_0x356353){throw this['handleError'](_0x356353);}}async[_0x3178ce(-0xe,0x3e)](_0x141813,data,config){function _0x5ee35e(_0x563ac4,_0x526a47){return _0x20ed(_0x563ac4-0x327,_0x526a47);}try{const response=await this['client'][_0x5ee35e(0x4a9,0x501)](_0x141813,data,config);return{'data':response[_0x5ee35e(0x453,0x4bb)],'status':response['status'],'statusText':response[_0x5ee35e(0x3ac,0x430)],'headers':response['headers']};}catch(_0x5062aa){throw this['handleError'](_0x5062aa);}}async[_0x3178ce(-0x2d,0x14)](_0xbf0e1,data,config){function _0x240d12(_0x562528,_0x173f28){return _0x20ed(_0x173f28-0x2e1,_0x562528);}try{const response=await this['client'][_0x240d12(0x3bc,0x439)](_0xbf0e1,data,config);return{'data':response['data'],'status':response['status'],'statusText':response['statusText'],'headers':response[_0x240d12(0x348,0x399)]};}catch(_0x541352){throw this[_0x240d12(0x3b9,0x430)](_0x541352);}}async['patch'](_0x4828af,data,config){function _0x4d37e4(_0x527b7f,_0x28931e){return _0x20ed(_0x28931e-0x2ea,_0x527b7f);}try{const response=await this[_0x4d37e4(0x32c,0x3a9)]['patch'](_0x4828af,data,config);return{'data':response[_0x4d37e4(0x39c,0x416)],'status':response['status'],'statusText':response[_0x4d37e4(0x320,0x36f)],'headers':response[_0x4d37e4(0x35e,0x3a2)]};}catch(_0x594ef8){throw this['handleError'](_0x594ef8);}}async['delete'](_0x2bd24a,config){function _0x3ba5f4(_0x1a4322,_0xe9e050){return _0x20ed(_0xe9e050- -0xf8,_0x1a4322);}try{const response=await this[_0x3ba5f4(-0x64,-0x39)]['delete'](_0x2bd24a,config);return{'data':response['data'],'status':response[_0x3ba5f4(0x1c,0xd)],'statusText':response['statusText'],'headers':response['headers']};}catch(_0x325554){throw this[_0x3ba5f4(-0x2e,0x57)](_0x325554);}}[_0x3178ce(-0xf0,-0x6a)](_0x1d4a46){function _0x2307b1(_0x27335f,_0xbfe743){return _0x20ed(_0xbfe743-0x39a,_0x27335f);}this['client']['defaults'][_0x2307b1(0x42a,0x452)][_0x2307b1(0x573,0x51e)]['Authorization']=_0x2307b1(0x40c,0x40e)+_0x1d4a46;}[_0x3178ce(-0xd2,-0x99)](){function _0x37c2cb(_0x1ccabe,_0x5560e0){return _0x20ed(_0x1ccabe-0x277,_0x5560e0);}delete this['client']['defaults']['headers'][_0x37c2cb(0x3fb,0x3b3)]['Authorization'],this['client'][_0x37c2cb(0x3ac,0x3a2)]['headers']['common']['Authorization']=_0x37c2cb(0x2eb,0x2d8)+this[_0x37c2cb(0x318,0x371)];}['handleError'](_0x55a145){function _0x4c5ef2(_0x235598,_0x46ab0b){return _0x20ed(_0x46ab0b-0x3af,_0x235598);}if(_0x55a145 instanceof EBaaSError)return _0x55a145;return new EBaaSError(_0x55a145[_0x4c5ef2(0x44f,0x4d6)]||_0x4c5ef2(0x520,0x50c),_0x55a145['status']||0x0,_0x55a145);}}class AuthClient{constructor(_0x21f9b9,_0x274aac){this[_0x1d7140(0x42c,0x452)]=null,this['httpClient']=_0x21f9b9,this[_0x1d7140(0x3a2,0x3cf)]=_0x274aac;function _0x1d7140(_0xe22b2d,_0x3588a0){return _0x20ed(_0x3588a0-0x340,_0xe22b2d);}this[_0x1d7140(0x3c3,0x3fc)]();}async[_0x3178ce(-0x39,0x33)](data){function _0x2337aa(_0x55d06d,_0x17f1a3){return _0x20ed(_0x17f1a3-0x3b9,_0x55d06d);}try{const response=await this[_0x2337aa(0x483,0x4d7)][_0x2337aa(0x4ba,0x53b)](_0x2337aa(0x44b,0x4ac),data);return response['data'][_0x2337aa(0x486,0x44d)]&&this['setSessionInternal'](response['data']['session']),response[_0x2337aa(0x552,0x4e5)];}catch(_0x26f184){throw this[_0x2337aa(0x461,0x4c0)](_0x26f184);}}async['signIn'](data){function _0x1e0f21(_0x3a74cd,_0x166854){return _0x20ed(_0x3a74cd- -0x6d,_0x166854);}try{const headers={};this[_0x1e0f21(0x22,0x51)]&&(headers['X-Workspace-ID']=this['workspaceId']);const response=await this['httpClient']['post'](_0x1e0f21(0x73,0x7f),data,{'headers':headers});return response[_0x1e0f21(0xbf,0xcf)][_0x1e0f21(0x27,0xd)]&&this['setSessionInternal'](response['data']['session']),response['data'];}catch(_0x184054){throw this[_0x1e0f21(0x9a,0x2d)](_0x184054);}}async['signOut'](){function _0x181084(_0x4447e9,_0x527969){return _0x20ed(_0x4447e9- -0x232,_0x527969);}try{await this['httpClient'][_0x181084(-0xb0,-0x77)]('/auth/v1/signout'),this[_0x181084(-0xbe,-0x43)]();}catch(_0x22c34d){this[_0x181084(-0xbe,-0x124)]();throw this['handleAuthError'](_0x22c34d);}}async['getUser'](){if(!this[_0x46c2e8(-0x55,-0x18)]?.['access_token'])return null;function _0x46c2e8(_0x3b13da,_0x1ac02b){return _0x20ed(_0x3b13da- -0x167,_0x1ac02b);}try{const response=await this['httpClient'][_0x46c2e8(-0x1d,0x1b)]('/auth/v1/user');return response['data']['user'];}catch(_0x216bff){if(_0x216bff instanceof EBaaSError&&_0x216bff['status']===0x191)return this['clearSession'](),null;throw this[_0x46c2e8(-0x60,-0x9c)](_0x216bff);}}async['refreshSession'](){function _0x5690b4(_0x29b6cc,_0x29e4a8){return _0x20ed(_0x29b6cc- -0x7f,_0x29e4a8);}if(!this[_0x5690b4(0x93,0xe4)]?.['refresh_token'])return null;try{const response=await this[_0x5690b4(0x9f,0x80)][_0x5690b4(0x103,0xc4)](_0x5690b4(0xef,0xa0),{'refresh_token':this[_0x5690b4(0x93,0x57)]['refresh_token']});if(response[_0x5690b4(0xad,0x31)][_0x5690b4(0x15,-0x4a)])return this['setSession'](response['data']['session']),response[_0x5690b4(0xad,0x73)]['session'];return null;}catch(_0x506879){this[_0x5690b4(0xf5,0x97)]();throw this['handleAuthError'](_0x506879);}}async[_0x3178ce(-0xa7,-0x25)](_0x1433a4){function _0x564cc3(_0x3a0946,_0x29b7a6){return _0x20ed(_0x29b7a6-0x2f3,_0x3a0946);}try{await this['httpClient'][_0x564cc3(0x445,0x475)](_0x564cc3(0x437,0x3b7),{'email':_0x1433a4});}catch(_0x43d18d){throw this['handleAuthError'](_0x43d18d);}}async[_0x3178ce(-0x4a,-0xc9)](data){function _0x106cfb(_0xcb1d66,_0x29e0b4){return _0x20ed(_0x29e0b4- -0x192,_0xcb1d66);}try{const response=await this['httpClient'][_0x106cfb(-0x10,-0x3a)](_0x106cfb(-0xb0,-0xd8),data);return response[_0x106cfb(-0x68,-0x66)][_0x106cfb(-0xf9,-0x107)];}catch(_0x4adcad){throw this['handleAuthError'](_0x4adcad);}}['getSession'](){return this['currentSession'];}[_0x3178ce(0x3,0x1c)](_0x3a6a16){function _0x5db334(_0xd6a0f6,_0x2c903d){return _0x20ed(_0x2c903d- -0x22e,_0xd6a0f6);}this[_0x5db334(-0x10a,-0x11c)]=_0x3a6a16,this[_0x5db334(-0xe2,-0x110)]['setAuthToken'](_0x3a6a16['access_token']),typeof localStorage!=='undefined'&&localStorage['setItem']('ebaas.auth.session',JSON['stringify'](_0x3a6a16));}['onAuthStateChange'](_0x27b0){return()=>{};}['setWorkspaceId'](_0x2d3ca6){function _0x3e5303(_0x2b9231,_0x4ba521){return _0x20ed(_0x4ba521-0x336,_0x2b9231);}this[_0x3e5303(0x395,0x3c5)]=_0x2d3ca6;}[_0x3178ce(-0xa3,-0x77)](_0x19df6e){function _0x4c4b65(_0xec97d2,_0x869677){return _0x20ed(_0xec97d2-0x2d9,_0x869677);}this['currentSession']=_0x19df6e,this[_0x4c4b65(0x3f7,0x43e)][_0x4c4b65(0x3b3,0x3c0)](_0x19df6e[_0x4c4b65(0x39f,0x327)]),typeof localStorage!=='undefined'&&localStorage['setItem'](_0x4c4b65(0x3ae,0x3a3),JSON['stringify'](_0x19df6e));}[_0x3178ce(0x47,0x30)](){this[_0x26e1e2(-0x19,0x25)]=null,this[_0x26e1e2(-0xd,-0x6)]['removeAuthToken']();function _0x26e1e2(_0x518c54,_0x2af9f3){return _0x20ed(_0x518c54- -0x12b,_0x2af9f3);}typeof localStorage!==_0x26e1e2(-0x4e,-0x2e)&&localStorage[_0x26e1e2(0x44,-0x3c)]('ebaas.auth.session');}['loadSession'](){function _0x5b509b(_0xf65a8a,_0x5de63f){return _0x20ed(_0x5de63f- -0x3cb,_0xf65a8a);}if(typeof localStorage!=='undefined'){const _0x15f960=localStorage['getItem'](_0x5b509b(-0x287,-0x2f6));if(_0x15f960)try{const _0x2756be=JSON[_0x5b509b(-0x314,-0x2a7)](_0x15f960);this['setSessionInternal'](_0x2756be);}catch(_0x5bc3ff){this['clearSession']();}}}[_0x3178ce(-0x4e,-0x3d)](_0x5b3029){if(_0x5b3029 instanceof EBaaSError)return _0x5b3029;function _0x34ca3e(_0x501b11,_0x5c87f8){return _0x20ed(_0x5c87f8- -0x2b,_0x501b11);}return new EBaaSError(_0x5b3029['message']||'Authentication\x20failed',_0x5b3029[_0x34ca3e(0x12a,0xda)]||0x0,_0x5b3029);}}class QueryBuilder{constructor(_0x1d9afb,_0x5ea773,_0x232de4,_0xbf6e67,_0x4300e8){this['httpClient']=_0x1d9afb,this['table']=_0x5ea773,this['schema']=_0x232de4,this['workspaceId']=_0xbf6e67,this['restUrl']=_0x4300e8||'/sdk/v1';function _0xecddbb(_0x43a221,_0x3c2861){return _0x20ed(_0x43a221-0x24,_0x3c2861);}this[_0xecddbb(0x188,0x1c5)]={'filters':[]};}['select'](_0x42771a='*',_0x4bf3d6){this[_0x5b2ff4(-0xc3,-0x144)]['select']=_0x42771a;function _0x5b2ff4(_0x49493d,_0xb9dc6e){return _0x20ed(_0x49493d- -0x227,_0xb9dc6e);}return this;}[_0x3178ce(-0x23,-0x73)](data,_0x260745){function _0x46d4f0(_0x2db45b,_0x1e3805){return _0x20ed(_0x2db45b-0x1c7,_0x1e3805);}return this[_0x46d4f0(0x330,0x375)]('POST',this['restUrl']+'/'+this[_0x46d4f0(0x348,0x3ca)]+'?operation=insert',{'data':data,'options':_0x260745});}['update'](data,_0x1b0b3a){this['query']['updateData']=data;function _0x156091(_0x4d1c04,_0x1624d1){return _0x20ed(_0x1624d1- -0x11,_0x4d1c04);}return this['query'][_0x156091(0x180,0x136)]=_0x1b0b3a,this;}['upsert'](data,_0x57af25){function _0x5b583c(_0x2e3567,_0x2bbeda){return _0x20ed(_0x2e3567-0x31b,_0x2bbeda);}return this[_0x5b583c(0x484,0x42d)]('POST',this['restUrl']+'/'+this[_0x5b583c(0x49c,0x42f)]+_0x5b583c(0x43d,0x441),{'data':data,'options':{..._0x57af25,'upsert':!![]}});}['delete'](_0x207de9){this['query']['deleteOptions']=_0x207de9,this['query'][_0x555cf3(0x221,0x20a)]=!![];function _0x555cf3(_0x26fb14,_0x2f41e7){return _0x20ed(_0x26fb14-0x15a,_0x2f41e7);}return this;}['eq'](_0x338636,_0x41be06){function _0x585dc0(_0x294cc6,_0x409709){return _0x20ed(_0x409709-0x29a,_0x294cc6);}return this[_0x585dc0(0x413,0x3fe)]['filters']['push']({'column':_0x338636,'operator':'eq','value':_0x41be06}),this;}['neq'](_0x482ae0,_0x23c1b7){this['query']['filters'][_0x4f2406(0x6a,0x92)]({'column':_0x482ae0,'operator':_0x4f2406(0xb4,0x78),'value':_0x23c1b7});function _0x4f2406(_0x3c3a32,_0x322ad5){return _0x20ed(_0x3c3a32- -0x28,_0x322ad5);}return this;}['gt'](_0x2b1194,_0xb7e6a7){return this['query']['filters']['push']({'column':_0x2b1194,'operator':'gt','value':_0xb7e6a7}),this;}[_0x3178ce(-0x70,0x5)](_0x18cd4f,_0x426cc6){function _0x4674a5(_0x3bb76f,_0xcb710c){return _0x20ed(_0xcb710c- -0x381,_0x3bb76f);}return this['query'][_0x4674a5(-0x1e1,-0x25e)][_0x4674a5(-0x325,-0x2ef)]({'column':_0x18cd4f,'operator':'gte','value':_0x426cc6}),this;}['lt'](_0x391b53,_0xbc4c27){function _0x52d1dd(_0x2a0be2,_0xbbbdc4){return _0x20ed(_0xbbbdc4-0x290,_0x2a0be2);}return this[_0x52d1dd(0x3d1,0x3f4)]['filters']['push']({'column':_0x391b53,'operator':'lt','value':_0xbc4c27}),this;}['lte'](_0x4e0bdf,_0x4d582a){function _0x21fd80(_0x5ee9d6,_0x4b8e1a){return _0x20ed(_0x5ee9d6- -0x257,_0x4b8e1a);}return this[_0x21fd80(-0xf3,-0x154)]['filters'][_0x21fd80(-0x1c5,-0x21b)]({'column':_0x4e0bdf,'operator':'lte','value':_0x4d582a}),this;}['like'](_0x55e9a4,_0x2eb034){this['query'][_0x35718a(0x51,-0x1d)][_0x35718a(-0x40,-0x99)]({'column':_0x55e9a4,'operator':_0x35718a(-0x1c,0x1c),'value':_0x2eb034});function _0x35718a(_0x2b04b9,_0xfab4f1){return _0x20ed(_0x2b04b9- -0xd2,_0xfab4f1);}return this;}[_0x3178ce(-0x9b,-0x95)](_0x5c5408,_0x56a324){function _0x191a05(_0x23c640,_0x5bc003){return _0x20ed(_0x5bc003-0x295,_0x23c640);}return this['query']['filters'][_0x191a05(0x367,0x327)]({'column':_0x5c5408,'operator':_0x191a05(0x354,0x344),'value':_0x56a324}),this;}['is'](_0xd6151d,_0x26dfb4){function _0x4f3156(_0x1bf13f,_0x49f55e){return _0x20ed(_0x49f55e- -0x27f,_0x1bf13f);}return this[_0x4f3156(-0xf5,-0x11b)][_0x4f3156(-0x137,-0x15c)][_0x4f3156(-0x1f7,-0x1ed)]({'column':_0xd6151d,'operator':'is','value':_0x26dfb4}),this;}['in'](_0xd8839f,_0x55d03d){function _0x6a4d93(_0xc9d4af,_0x4ebc8c){return _0x20ed(_0xc9d4af-0x3df,_0x4ebc8c);}return this[_0x6a4d93(0x543,0x52b)][_0x6a4d93(0x502,0x510)][_0x6a4d93(0x471,0x4aa)]({'column':_0xd8839f,'operator':'in','value':_0x55d03d}),this;}[_0x3178ce(0x61,0x39)](_0x31da75,_0x58aeb2){function _0x722006(_0x2a71dd,_0x55c17b){return _0x20ed(_0x2a71dd-0x282,_0x55c17b);}return this['query']['filters'][_0x722006(0x314,0x343)]({'column':_0x31da75,'operator':_0x722006(0x3ff,0x3f6),'value':_0x58aeb2}),this;}['match'](_0x1e0b50){return Object['entries'](_0x1e0b50)['forEach'](([_0x2c76b0,_0x2e9c98])=>{this['eq'](_0x2c76b0,_0x2e9c98);}),this;}['order'](_0x35f89b,_0x9b73df){function _0x418fdc(_0x208226,_0x486c50){return _0x20ed(_0x486c50- -0x39e,_0x208226);}return!this['query'][_0x418fdc(-0x2c2,-0x317)]&&(this['query']['order']=[]),this[_0x418fdc(-0x27f,-0x23a)]['order']['push']({'column':_0x35f89b,'ascending':_0x9b73df?.['ascending']!==![]}),this;}['limit'](count){this[_0x5e5a65(0x7c,0xab)][_0x5e5a65(-0x14,0x7)]=count;function _0x5e5a65(_0x128f04,_0x29575b){return _0x20ed(_0x128f04- -0xe8,_0x29575b);}return this;}['range'](from,_0x425468){function _0x44d792(_0x5ad335,_0x4a7389){return _0x20ed(_0x4a7389- -0xa1,_0x5ad335);}return this[_0x44d792(0x119,0xc3)]['range']={'from':from,'to':_0x425468},this;}async[_0x3178ce(-0x38,-0x11)](){function _0x54a924(_0x322b65,_0x453c89){return _0x20ed(_0x453c89-0x247,_0x322b65);}if(this['query'][_0x54a924(0x2a9,0x2fe)])return this[_0x54a924(0x368,0x3b0)]('PATCH',this[_0x54a924(0x3ba,0x357)]+'/'+this[_0x54a924(0x42a,0x3c8)],{'data':this['query']['updateData'],'options':this[_0x54a924(0x331,0x3ab)]['updateOptions'],'filters':this[_0x54a924(0x388,0x3ab)]['filters']});else return this[_0x54a924(0x35e,0x3ab)]['isDelete']?this[_0x54a924(0x380,0x3b0)]('DELETE',this['restUrl']+'/'+this['table']+'?operation=delete',{'options':this[_0x54a924(0x3d5,0x3ab)]['deleteOptions'],'filters':this['query']['filters']}):this['executeQuery']('GET',this[_0x54a924(0x3a6,0x357)]+'/'+this[_0x54a924(0x344,0x3c8)]+'?operation=select',{'select':this['query'][_0x54a924(0x3ae,0x35f)],'filters':this[_0x54a924(0x3eb,0x3ab)][_0x54a924(0x302,0x36a)],'order':this['query']['order'],'limit':this['query'][_0x54a924(0x2c9,0x31b)],'range':this['query'][_0x54a924(0x310,0x34a)]});}async['single'](){this[_0x2e4b4f(0x2ab,0x312)](0x1);function _0x2e4b4f(_0x1018ff,_0x2b465b){return _0x20ed(_0x2b465b-0x23e,_0x1018ff);}const result=await this[_0x2e4b4f(0x3de,0x371)]();return{'data':result['data']?.[0x0]||null,'error':result['error']};}async['executeQuery'](_0x4eaeae,_0x13c77c,_0x56f42f){function _0x4599a8(_0xf96f13,_0x5d7b59){return _0x20ed(_0x5d7b59- -0x223,_0xf96f13);}try{let response;const headers={};this['workspaceId']&&(headers['x-workspace-id']=this['workspaceId']);if(_0x4eaeae==='GET'){const _0xfbf8e=_0x13c77c[_0x4599a8(-0x12d,-0x1a5)]('?'),_0x4f2a78=_0xfbf8e[0x0],existingParams=new URLSearchParams(_0xfbf8e[0x1]||'');if(_0x56f42f[_0x4599a8(-0x17f,-0x10b)])existingParams['append'](_0x4599a8(-0xf9,-0x10b),_0x56f42f[_0x4599a8(-0x16c,-0x10b)]);_0x56f42f[_0x4599a8(-0x184,-0x100)]?.[_0x4599a8(-0x8c,-0xef)]&&_0x56f42f[_0x4599a8(-0xc2,-0x100)][_0x4599a8(-0x10c,-0x11b)](filter=>{function _0x5b9327(_0x55681a,_0x544372){return _0x20ed(_0x55681a-0x318,_0x544372);}existingParams['append'](filter[_0x5b9327(0x3f3,0x428)],filter['operator']+'.'+filter['value']);});if(_0x56f42f[_0x4599a8(-0x1b1,-0x19c)]?.[_0x4599a8(-0xad,-0xef)]){const orderStr=_0x56f42f['order']['map'](_0x32f5ff=>''+_0x32f5ff[_0x4599a8(-0x1a7,-0x148)]+(_0x32f5ff['ascending']?_0x4599a8(-0x142,-0x135):_0x4599a8(-0xd5,-0xf6)))['join'](',');existingParams[_0x4599a8(-0x138,-0x138)]('order',orderStr);}if(_0x56f42f[_0x4599a8(-0xf0,-0x14f)])existingParams[_0x4599a8(-0xb1,-0x138)]('limit',_0x56f42f['limit'][_0x4599a8(-0xfa,-0x116)]());_0x56f42f[_0x4599a8(-0x146,-0x120)]&&(existingParams['append']('offset',_0x56f42f[_0x4599a8(-0x109,-0x120)][_0x4599a8(-0x122,-0xbb)][_0x4599a8(-0x1a0,-0x116)]()),existingParams['append']('limit',(_0x56f42f[_0x4599a8(-0xe4,-0x120)]['to']-_0x56f42f['range'][_0x4599a8(-0xbc,-0xbb)]+0x1)['toString']())),response=await this[_0x4599a8(-0x142,-0x105)][_0x4599a8(-0x6b,-0xd9)](_0x4f2a78+'?'+existingParams['toString'](),{'headers':headers});}else{if(_0x4eaeae==='DELETE'){const _0x287997=_0x13c77c[_0x4599a8(-0x132,-0x1a5)]('?'),_0x1a1359=_0x287997[0x0],existingParams=new URLSearchParams(_0x287997[0x1]||'');!existingParams[_0x4599a8(-0x174,-0x10f)](_0x4599a8(-0x139,-0xcd))&&existingParams['append'](_0x4599a8(-0x52,-0xcd),_0x4599a8(-0x9f,-0xf3));_0x56f42f[_0x4599a8(-0xe1,-0x100)]?.['length']&&_0x56f42f['filters'][_0x4599a8(-0xb9,-0x11b)](filter=>{function _0x2e36b3(_0x5507b3,_0x3b1ad7){return _0x20ed(_0x3b1ad7-0x64,_0x5507b3);}existingParams['append'](filter[_0x2e36b3(0x186,0x13f)],filter[_0x2e36b3(0x1cf,0x180)]+'.'+filter['value']);});const deleteUrl=_0x1a1359+'?'+existingParams[_0x4599a8(-0xdc,-0x116)]();console['log']('\uD83D\uDD27 DELETE URL construída:',deleteUrl),console[_0x4599a8(-0xfa,-0x11f)]('\uD83D\uDD27 DELETE headers:',headers),console[_0x4599a8(-0x9c,-0x11f)]('\uD83D\uDD27 DELETE filtros originais:',_0x56f42f['filters']),response=await this['httpClient']['delete'](deleteUrl,{'headers':headers});}else{if(_0x4eaeae==='PATCH'){const _0x1e4c62=_0x13c77c[_0x4599a8(-0x120,-0x1a5)]('?'),_0x1cdfc0=_0x1e4c62[0x0],existingParams=new URLSearchParams(_0x1e4c62[0x1]||'');!existingParams[_0x4599a8(-0x9f,-0x10f)](_0x4599a8(-0x14e,-0xcd))&&existingParams['append'](_0x4599a8(-0x11a,-0xcd),'update');_0x56f42f['filters']?.[_0x4599a8(-0xe6,-0xef)]&&_0x56f42f['filters']['forEach'](filter=>{function _0xc0d575(_0x1300bf,_0xac2e53){return _0x20ed(_0x1300bf- -0x269,_0xac2e53);}existingParams[_0xc0d575(-0x17e,-0x163)](filter['column'],filter[_0xc0d575(-0x14d,-0x145)]+'.'+filter[_0xc0d575(-0x127,-0x166)]);});_0x56f42f[_0x4599a8(-0x77,-0xa0)]?.['prefer']&&(headers['Prefer']=_0x56f42f['options']['prefer']);const updateUrl=_0x1cdfc0+'?'+existingParams[_0x4599a8(-0x198,-0x116)]();response=await this['httpClient'][_0x4599a8(-0x109,-0x187)](updateUrl,_0x56f42f[_0x4599a8(-0x148,-0xf7)],{'headers':headers});}else{let _0x3c2892=_0x56f42f[_0x4599a8(-0x177,-0xf7)];!headers['Prefer']&&(headers[_0x4599a8(-0xf4,-0xf9)]='return=representation'),_0x56f42f[_0x4599a8(-0xf8,-0xa0)]?.['upsert']&&(headers['Prefer']='resolution=merge-duplicates,return=representation'),_0x56f42f[_0x4599a8(-0x19b,-0x17a)]&&(_0x3c2892=_0x56f42f['dataArray']),response=await this[_0x4599a8(-0x18c,-0x105)]['post'](_0x13c77c,_0x3c2892,{'headers':headers});}}}return{'data':response['data'],'error':null,'count':response[_0x4599a8(-0x10d,-0x16b)]?.['x-total-count']?parseInt(response['headers'][_0x4599a8(-0x3c,-0xc1)]):undefined};}catch(_0x2f00b3){return{'data':null,'error':_0x2f00b3 instanceof EBaaSError?_0x2f00b3:new EBaaSError(_0x2f00b3 instanceof Error?_0x2f00b3[_0x4599a8(-0x11c,-0xfc)]:_0x4599a8(-0xca,-0xa7),0x0,_0x2f00b3)};}}}class CustomDatabaseManager{constructor(_0x35e47c,_0x23d6f9){function _0x340746(_0xa46efd,_0x100314){return _0x20ed(_0xa46efd-0x18e,_0x100314);}this[_0x340746(0x2ac,0x30e)]=_0x35e47c,this[_0x340746(0x21d,0x1de)]=_0x23d6f9;}async[_0x3178ce(-0x116,-0x94)](){if(!this['workspaceId'])return{'hasCustomDatabase':![]};function _0x48f77e(_0x356a80,_0x215022){return _0x20ed(_0x215022-0x2da,_0x356a80);}try{const response=await this[_0x48f77e(0x3f9,0x3f8)][_0x48f77e(0x3a9,0x424)]('/admin/v1/workspace/custom-database',{'headers':{'x-workspace-id':this[_0x48f77e(0x3b1,0x369)]}});if(response['status']===0xc8&&response[_0x48f77e(0x40b,0x406)]?.[_0x48f77e(0x431,0x43f)]){const config=response['data'][_0x48f77e(0x489,0x43f)],_0x4d4af1={'host':config['postgresHost'],'port':config[_0x48f77e(0x37b,0x3d6)],'database':config['postgresDatabase'],'username':config[_0x48f77e(0x455,0x44c)],'password':'','schema':config['postgresSchema'],'sslEnabled':config[_0x48f77e(0x39f,0x368)]};return this[_0x48f77e(0x406,0x3c0)]={'hasCustomDatabase':!![],'config':config,'credentials':_0x4d4af1},this['detectedConfig'];}}catch(_0x53db5a){if(_0x53db5a?.['status']===0x194)return this[_0x48f77e(0x3ca,0x3c0)]={'hasCustomDatabase':![]},this['detectedConfig'];console['warn']('Failed to detect custom database configuration:',_0x53db5a);}return this[_0x48f77e(0x3ef,0x3c0)]={'hasCustomDatabase':![]},this['detectedConfig'];}async[_0x3178ce(-0xcc,-0x97)](_0x43820c){function _0x47eeb2(_0xc66a29,_0x48900b){return _0x20ed(_0xc66a29- -0xbe,_0x48900b);}try{const response=await this['httpClient'][_0x47eeb2(0xc4,0x11e)]('/admin/v1/workspace/custom-database/test-connection',_0x43820c,{'headers':this[_0x47eeb2(-0x2f,-0x64)]?{'X-Workspace-ID':this[_0x47eeb2(-0x2f,-0xb1)]}:{}});return response['data'];}catch(_0x45eb81){return{'success':![],'message':_0x45eb81?.[_0x47eeb2(0x69,0x2e)]||_0x47eeb2(0x3f,0x49)};}}async[_0x3178ce(-0xba,-0x9d)](_0x192ec1){if(!this[_0x5d8111(-0x2af,-0x289)])throw new Error('Workspace ID is required to configure custom database');const response=await this['httpClient']['post']('/admin/v1/workspace/custom-database',{'workspaceId':this[_0x5d8111(-0x2af,-0x241)],..._0x192ec1},{'headers':{'X-Workspace-ID':this[_0x5d8111(-0x2af,-0x2fd)]}}),config=response['data']['config'];function _0x5d8111(_0x5eb854,_0x1e4784){return _0x20ed(_0x5eb854- -0x33e,_0x1e4784);}return this['detectedConfig']={'hasCustomDatabase':!![],'config':config,'credentials':_0x192ec1},config;}async['removeCustomDatabase'](){if(!this[_0x36a40f(-0x1c3,-0x1c4)])throw new Error('Workspace ID is required to remove custom database');await this[_0x36a40f(-0x1b5,-0x135)]['delete']('/admin/v1/workspace/custom-database',{'headers':{'X-Workspace-ID':this[_0x36a40f(-0x24e,-0x1c4)]}});function _0x36a40f(_0x2068c4,_0x146155){return _0x20ed(_0x146155- -0x253,_0x2068c4);}this['detectedConfig']={'hasCustomDatabase':![]};}['getDetectedConfig'](){return this['detectedConfig'];}['hasCustomDatabase'](){function _0x24d709(_0x522187,_0x2fafbe){return _0x20ed(_0x522187-0x33e,_0x2fafbe);}return this['detectedConfig']?.[_0x24d709(0x489,0x480)]??![];}[_0x3178ce(-0x27,-0x96)](){return this['detectedConfig']?.['credentials'];}['setWorkspaceId'](_0xa07b93){function _0x1f1658(_0x4773fb,_0x51c054){return _0x20ed(_0x51c054-0x365,_0x4773fb);}this[_0x1f1658(0x42f,0x3f4)]=_0xa07b93,this['detectedConfig']=undefined;}[_0x3178ce(-0x4e,-0x1f)](){function _0x6d3c91(_0x1b309b,_0xb9dfce){return _0x20ed(_0x1b309b-0xa6,_0xb9dfce);}return this[_0x6d3c91(0x135,0xf6)];}[_0x3178ce(-0x8c,-0x65)](){function _0x4baff1(_0x40d32a,_0x3631a1){return _0x20ed(_0x3631a1- -0x175,_0x40d32a);}return{'workspaceId':this['workspaceId'],'hasConfig':this[_0x4baff1(-0x48,-0x2a)](),'configDetails':this['detectedConfig']?.[_0x4baff1(-0xec,-0x8b)]?{'host':this[_0x4baff1(-0xe9,-0x8f)]['credentials']['host'],'port':this[_0x4baff1(-0x60,-0x8f)]['credentials'][_0x4baff1(0x9,-0x58)],'database':this['detectedConfig'][_0x4baff1(-0xe9,-0x8b)]['database'],'schema':this[_0x4baff1(-0xd3,-0x8f)][_0x4baff1(-0x23,-0x8b)][_0x4baff1(0x16,-0xb)]||'public','sslEnabled':this[_0x4baff1(-0x6e,-0x8f)][_0x4baff1(-0x69,-0x8b)][_0x4baff1(-0x7d,-0xe7)]||![]}:undefined};}}class DatabaseClient{constructor(_0x528a6d,_0x115c9a,_0xc9b26b){function _0x5db15b(_0x11d898,_0x5a6e59){return _0x20ed(_0x11d898-0x375,_0x5a6e59);}this[_0x5db15b(0x493,0x46d)]=_0x528a6d,this[_0x5db15b(0x48e,0x418)]=new CustomDatabaseManager(_0x528a6d,_0x115c9a),this[_0x5db15b(0x485,0x4d1)]=_0xc9b26b||_0x5db15b(0x40b,0x3ff);}['from'](_0x345b20){function _0x110d19(_0x2b994b,_0x27370c){return _0x20ed(_0x2b994b-0x8b,_0x27370c);}return new QueryBuilder(this['httpClient'],_0x345b20,this['currentSchema'],this[_0x110d19(0x1a4,0x154)][_0x110d19(0x1b0,0x166)](),this[_0x110d19(0x19b,0x14c)]);}[_0x3178ce(-0x46,-0x7b)](_0x2c88f6,_0x452f65){function _0x479c04(_0x5771a1,_0x4e5473){return _0x20ed(_0x4e5473-0x25d,_0x5771a1);}return this['httpClient'][_0x479c04(0x39f,0x3df)](_0x479c04(0x3f1,0x368)+_0x2c88f6,_0x452f65);}[_0x3178ce(0x83,0x26)](_0x345c14){function _0x322919(_0x3051a7,_0x36d9e7){return _0x20ed(_0x36d9e7- -0x4e,_0x3051a7);}const _0x3d0b8d=new DatabaseClient(this['httpClient'],this['customDatabaseManager']['getWorkspaceId'](),this[_0x322919(0xab,0xc2)]);return _0x3d0b8d['currentSchema']=_0x345c14,_0x3d0b8d['customDatabaseManager']=this[_0x322919(0x14f,0xcb)],_0x3d0b8d;}async[_0x3178ce(-0x2c,-0x94)](){function _0x4d7a5a(_0x4ac105,_0xdaf34b){return _0x20ed(_0x4ac105- -0x2b6,_0xdaf34b);}return this[_0x4d7a5a(-0x19d,-0x1be)][_0x4d7a5a(-0x206,-0x268)]();}async[_0x3178ce(-0xb4,-0x79)](_0x5ebda0){return this['customDatabaseManager']['testConnection'](_0x5ebda0);}async[_0x3178ce(-0xd1,-0x9d)](_0xe3400a){function _0x376bec(_0xd24027,_0x11400b){return _0x20ed(_0xd24027-0x24f,_0x11400b);}return this[_0x376bec(0x368,0x357)][_0x376bec(0x2f6,0x278)](_0xe3400a);}async['removeCustomDatabase'](){function _0x331721(_0x18adb7,_0x4b87ec){return _0x20ed(_0x4b87ec-0x272,_0x18adb7);}return this['customDatabaseManager'][_0x331721(0x38b,0x381)]();}['isUsingCustomDatabase'](){function _0x110850(_0x2dcc09,_0x53ab0b){return _0x20ed(_0x53ab0b-0x1f2,_0x2dcc09);}return this[_0x110850(0x2d0,0x30b)][_0x110850(0x307,0x33d)]();}['getCustomDatabaseStatus'](){function _0x551aa7(_0x482f7b,_0x2ce502){return _0x20ed(_0x2ce502-0x351,_0x482f7b);}return this[_0x551aa7(0x44c,0x46a)][_0x551aa7(0x465,0x430)]();}[_0x3178ce(-0xaf,-0x3b)](_0x2b9657){function _0x59e3df(_0x371269,_0x1190e7){return _0x20ed(_0x371269- -0x24c,_0x1190e7);}this[_0x59e3df(-0x133,-0xcc)]['setWorkspaceId'](_0x2b9657);}async[_0x3178ce(0x7f,0x3a)](){function _0x4d56db(_0x1262a1,_0x2647e3){return _0x20ed(_0x1262a1- -0x13a,_0x2647e3);}try{await this[_0x4d56db(-0x21,0xd)][_0x4d56db(-0x8a,-0x35)]();}catch(_0x849b8b){console[_0x4d56db(0x1,-0x70)]('Failed to initialize custom database detection:',_0x849b8b);}}}class StorageBucket{constructor(_0x46f8c5,bucketId){function _0x5b15ab(_0x1d6a02,_0xa7bc8c){return _0x20ed(_0x1d6a02-0xbd,_0xa7bc8c);}this[_0x5b15ab(0x1db,0x260)]=_0x46f8c5,this[_0x5b15ab(0x1e5,0x173)]=bucketId;}async[_0x3178ce(-0x94,-0x75)](_0x34538c,_0x5ecfa8,_0x221704){function _0x1dcf4d(_0x5d65c7,_0x49191e){return _0x20ed(_0x5d65c7-0x1c4,_0x49191e);}try{const _0x391f7a=new FormData();if(_0x5ecfa8 instanceof File)_0x391f7a['append']('file',_0x5ecfa8);else{if(_0x5ecfa8 instanceof Blob)_0x391f7a[_0x1dcf4d(0x2af,0x2cc)]('file',_0x5ecfa8,_0x34538c);else{if(_0x5ecfa8 instanceof ArrayBuffer)_0x391f7a['append']('file',new Blob([_0x5ecfa8]),_0x34538c);else typeof _0x5ecfa8==='string'&&_0x391f7a[_0x1dcf4d(0x2af,0x2f0)](_0x1dcf4d(0x294,0x2b1),new Blob([_0x5ecfa8],{'type':_0x1dcf4d(0x276,0x233)}),_0x34538c);}}_0x391f7a['append']('path',_0x34538c);_0x221704?.[_0x1dcf4d(0x247,0x250)]&&_0x391f7a['append']('cacheControl',_0x221704['cacheControl']);_0x221704?.['contentType']&&_0x391f7a['append']('contentType',_0x221704[_0x1dcf4d(0x29c,0x2db)]);_0x221704?.['metadata']&&_0x391f7a['append']('metadata',JSON['stringify'](_0x221704['metadata']));const _0x5483d4='/storage/buckets/'+this['bucketId']+_0x1dcf4d(0x32b,0x362)+(_0x221704?.['upsert']?'?upsert=true':''),response=await this[_0x1dcf4d(0x2e2,0x29d)]['post'](_0x5483d4,_0x391f7a,{'headers':{'Content-Type':_0x1dcf4d(0x254,0x237)}});return{'data':response[_0x1dcf4d(0x2f0,0x336)],'error':null};}catch(_0x3a8865){return{'data':null,'error':_0x3a8865 instanceof EBaaSError?_0x3a8865:new EBaaSError(_0x3a8865 instanceof Error?_0x3a8865[_0x1dcf4d(0x2eb,0x367)]:'Failed\x20to\x20upload\x20file',0x0,_0x3a8865)};}}async[_0x3178ce(-0x37,0x41)](_0x5f4245,_0x3a6623){function _0x5782ad(_0x54df5d,_0x672c23){return _0x20ed(_0x672c23-0x269,_0x54df5d);}try{const _0xe9783e=new URLSearchParams();_0x3a6623?.['transform']&&Object['entries'](_0x3a6623[_0x5782ad(0x340,0x356)])['forEach'](([_0x15b618,_0x4cc04d])=>{_0x4cc04d!==undefined&&_0xe9783e['append'](_0x15b618,String(_0x4cc04d));});const _0x1d80a3='/storage/buckets/'+this['bucketId']+'/files/'+_0x5f4245+(_0xe9783e['toString']()?'?'+_0xe9783e['toString']():''),response=await this[_0x5782ad(0x308,0x387)][_0x5782ad(0x3f5,0x3b3)](_0x1d80a3,{'responseType':_0x5782ad(0x384,0x3ca)});return{'data':response['data'],'error':null};}catch(_0x36050){return{'data':null,'error':_0x36050 instanceof EBaaSError?_0x36050:new EBaaSError(_0x36050 instanceof Error?_0x36050['message']:'Failed\x20to\x20download\x20file',0x0,_0x36050)};}}async['list'](_0x55239e,_0x2ea6e0){function _0x3e2e94(_0x11bf16,_0x3c7f91){return _0x20ed(_0x11bf16- -0x2b8,_0x3c7f91);}try{const _0x3dfc42=new URLSearchParams();_0x55239e&&_0x3dfc42['append'](_0x3e2e94(-0x225,-0x21e),_0x55239e);_0x2ea6e0?.[_0x3e2e94(-0x1e4,-0x166)]&&_0x3dfc42['append'](_0x3e2e94(-0x1e4,-0x21b),String(_0x2ea6e0['limit']));_0x2ea6e0?.[_0x3e2e94(-0x1d1,-0x1d3)]&&_0x3dfc42[_0x3e2e94(-0x1cd,-0x14f)](_0x3e2e94(-0x1d1,-0x1de),String(_0x2ea6e0[_0x3e2e94(-0x1d1,-0x259)]));_0x2ea6e0?.['sortBy']&&_0x3dfc42[_0x3e2e94(-0x1cd,-0x1ec)](_0x3e2e94(-0x236,-0x287),JSON[_0x3e2e94(-0x1ee,-0x192)](_0x2ea6e0[_0x3e2e94(-0x236,-0x1da)]));_0x2ea6e0?.['search']&&_0x3dfc42['append'](_0x3e2e94(-0x155,-0xfb),_0x2ea6e0['search']);const _0x16c3f0=_0x3e2e94(-0x1a7,-0x123)+this[_0x3e2e94(-0x190,-0x1e6)]+_0x3e2e94(-0x151,-0x1b7)+(_0x3dfc42['toString']()?'?'+_0x3dfc42['toString']():''),response=await this['httpClient'][_0x3e2e94(-0x16e,-0x163)](_0x16c3f0);return{'data':response['data'],'error':null};}catch(_0x1b4599){return{'data':null,'error':_0x1b4599 instanceof EBaaSError?_0x1b4599:new EBaaSError(_0x1b4599 instanceof Error?_0x1b4599['message']:'Failed\x20to\x20list\x20files',0x0,_0x1b4599)};}}async['remove'](_0x34c377){function _0x586198(_0x77365d,_0x108723){return _0x20ed(_0x108723-0x35f,_0x77365d);}try{const response=await this[_0x586198(0x4e7,0x47d)][_0x586198(0x502,0x48f)](_0x586198(0x4d1,0x470)+this[_0x586198(0x44a,0x487)]+_0x586198(0x4fd,0x4c6),{'data':{'paths':_0x34c377}});return{'data':response[_0x586198(0x49e,0x48b)],'error':null};}catch(_0x2200ef){return{'data':null,'error':_0x2200ef instanceof EBaaSError?_0x2200ef:new EBaaSError(_0x2200ef instanceof Error?_0x2200ef['message']:'Failed\x20to\x20remove\x20files',0x0,_0x2200ef)};}}async[_0x3178ce(-0xbc,-0x3e)](fromPath,_0x37cdef){function _0x2bd9a7(_0x2fd43e,_0x30e638){return _0x20ed(_0x2fd43e-0x24e,_0x30e638);}try{const response=await this['httpClient']['post'](_0x2bd9a7(0x35f,0x32a)+this[_0x2bd9a7(0x376,0x3a9)]+_0x2bd9a7(0x2ee,0x2b1),{'sourceKey':fromPath,'destinationKey':_0x37cdef});return{'data':response[_0x2bd9a7(0x37a,0x3f3)],'error':null};}catch(_0x4b2644){return{'data':null,'error':_0x4b2644 instanceof EBaaSError?_0x4b2644:new EBaaSError(_0x4b2644 instanceof Error?_0x4b2644['message']:'Failed\x20to\x20move\x20file',0x0,_0x4b2644)};}}async['copy'](fromPath,_0x1941b9){function _0x231bf1(_0x47c807,_0x926304){return _0x20ed(_0x926304- -0x2e6,_0x47c807);}try{const response=await this['httpClient']['post']('/storage/buckets/'+this['bucketId']+'/files/copy',{'sourceKey':fromPath,'destinationKey':_0x1941b9});return{'data':response['data'],'error':null};}catch(_0x2a6db7){return{'data':null,'error':_0x2a6db7 instanceof EBaaSError?_0x2a6db7:new EBaaSError(_0x2a6db7 instanceof Error?_0x2a6db7[_0x231bf1(-0x235,-0x1bf)]:'Failed\x20to\x20copy\x20file',0x0,_0x2a6db7)};}}async[_0x3178ce(-0x4a,-0x83)](_0x151ee5,_0x18e53e,_0x45de3f){function _0x135cf4(_0xb5f2cd,_0x63f574){return _0x20ed(_0xb5f2cd-0x5a,_0x63f574);}try{const response=await this[_0x135cf4(0x178,0x13f)][_0x135cf4(0x1dc,0x1eb)](_0x135cf4(0x16b,0x192)+this['bucketId']+_0x135cf4(0x1cf,0x23c)+_0x151ee5+'/sign',{'expiresIn':_0x18e53e,..._0x45de3f});return{'data':response['data'],'error':null};}catch(_0x8b564){return{'data':null,'error':_0x8b564 instanceof EBaaSError?_0x8b564:new EBaaSError(_0x8b564 instanceof Error?_0x8b564[_0x135cf4(0x181,0x183)]:_0x135cf4(0x12c,0x168),0x0,_0x8b564)};}}['getPublicUrl'](_0x1b774a,_0x269492){const _0x440ef1=new URLSearchParams();function _0x2a3d59(_0x10a1ba,_0x39d77d){return _0x20ed(_0x10a1ba-0x2d2,_0x39d77d);}_0x269492?.[_0x2a3d59(0x3bf,0x39d)]&&Object[_0x2a3d59(0x451,0x44f)](_0x269492[_0x2a3d59(0x3bf,0x3ca)])[_0x2a3d59(0x3da,0x406)](([_0x50f120,_0x4d25e6])=>{_0x4d25e6!==undefined&&_0x440ef1['append'](_0x50f120,String(_0x4d25e6));});const _0xab2073=this[_0x2a3d59(0x3f0,0x3df)][_0x2a3d59(0x35a,0x354)]||'',_0x211a01=_0xab2073+'/storage/buckets/'+this['bucketId']+'/files/'+_0x1b774a+(_0x440ef1['toString']()?'?'+_0x440ef1[_0x2a3d59(0x3df,0x370)]():'');return{'data':{'publicUrl':_0x211a01}};}async['getFileInfo'](_0x2f9d42){function _0x449c97(_0x12b4fc,_0x132370){return _0x20ed(_0x12b4fc- -0x77,_0x132370);}try{const response=await this['httpClient'][_0x449c97(0xd3,0xa8)](_0x449c97(0x9a,0x9c)+this[_0x449c97(0xb1,0x88)]+_0x449c97(0xfe,0x162)+_0x2f9d42+_0x449c97(0x67,0x4e));return{'data':response['data'],'error':null};}catch(_0x369896){return{'data':null,'error':_0x369896 instanceof EBaaSError?_0x369896:new EBaaSError(_0x369896 instanceof Error?_0x369896[_0x449c97(0xb0,0xb5)]:_0x449c97(0x8,0x7),0x0,_0x369896)};}}async['updateFileMetadata'](_0xa719e5,metadata){function _0x2d89ab(_0x1c4781,_0x518843){return _0x20ed(_0x1c4781-0x195,_0x518843);}try{const response=await this['httpClient'][_0x2d89ab(0x2ed,0x2ab)]('/storage/buckets/'+this['bucketId']+_0x2d89ab(0x30a,0x363)+_0xa719e5+'/metadata',{'metadata':metadata});return{'data':response['data'],'error':null};}catch(_0x39d7dc){return{'data':null,'error':_0x39d7dc instanceof EBaaSError?_0x39d7dc:new EBaaSError(_0x39d7dc instanceof Error?_0x39d7dc['message']:'Failed\x20to\x20update\x20file\x20metadata',0x0,_0x39d7dc)};}}}class StorageClient{constructor(_0x1e8621){function _0x12b9e4(_0xaf396d,_0x358ae3){return _0x20ed(_0xaf396d-0x202,_0x358ae3);}this[_0x12b9e4(0x320,0x30a)]=_0x1e8621;}['from'](bucketId){function _0x4e0a2b(_0x3998a7,_0x46433b){return _0x20ed(_0x3998a7- -0x353,_0x46433b);}return new StorageBucket(this[_0x4e0a2b(-0x235,-0x1cc)],bucketId);}async[_0x3178ce(-0xc8,-0x9f)](_0x75c051,_0x2e45e4){function _0x28dfc0(_0x5c1866,_0x35a6c6){return _0x20ed(_0x35a6c6- -0x2ef,_0x5c1866);}try{const response=await this['httpClient']['post'](_0x28dfc0(-0x20b,-0x19f),{'id':_0x75c051,..._0x2e45e4});return{'data':response['data'],'error':null};}catch(_0x46dccf){return{'data':null,'error':_0x46dccf instanceof EBaaSError?_0x46dccf:new EBaaSError(_0x46dccf instanceof Error?_0x46dccf['message']:_0x28dfc0(-0x116,-0x176),0x0,_0x46dccf)};}}async[_0x3178ce(-0x30,0x1b)](_0x5c506e){function _0x2911f2(_0x2e12a3,_0x402695){return _0x20ed(_0x2e12a3-0x55,_0x402695);}try{const response=await this[_0x2911f2(0x173,0x1f3)]['get'](_0x2911f2(0x166,0xe4)+_0x5c506e);return{'data':response[_0x2911f2(0x181,0x122)],'error':null};}catch(_0x3acbc7){return{'data':null,'error':_0x3acbc7 instanceof EBaaSError?_0x3acbc7:new EBaaSError(_0x3acbc7 instanceof Error?_0x3acbc7['message']:'Failed\x20to\x20get\x20bucket',0x0,_0x3acbc7)};}}async[_0x3178ce(-0x89,-0x8b)](){function _0x4b594c(_0x765306,_0xbb3ab){return _0x20ed(_0x765306- -0xcf,_0xbb3ab);}try{const response=await this[_0x4b594c(0x4f,0xd0)]['get']('/storage/buckets');return{'data':response[_0x4b594c(0x5d,0x7f)],'error':null};}catch(_0x482f8d){return{'data':null,'error':_0x482f8d instanceof EBaaSError?_0x482f8d:new EBaaSError(_0x482f8d instanceof Error?_0x482f8d['message']:'Failed\x20to\x20list\x20buckets',0x0,_0x482f8d)};}}async[_0x3178ce(-0x2c,-0x5f)](_0x4e5bf2,_0xf4f493){function _0x492f91(_0x349d04,_0x2fff4a){return _0x20ed(_0x349d04- -0x24,_0x2fff4a);}try{const response=await this['httpClient']['put'](_0x492f91(0xed,0xa9)+_0x4e5bf2,_0xf4f493);return{'data':response[_0x492f91(0x108,0x133)],'error':null};}catch(_0x41ba01){return{'data':null,'error':_0x41ba01 instanceof EBaaSError?_0x41ba01:new EBaaSError(_0x41ba01 instanceof Error?_0x41ba01[_0x492f91(0x103,0x181)]:_0x492f91(0x66,0x26),0x0,_0x41ba01)};}}async['deleteBucket'](_0x176d46){function _0x3f75e8(_0x2046cc,_0x2d3212){return _0x20ed(_0x2046cc-0x63,_0x2d3212);}try{const response=await this['httpClient']['delete'](_0x3f75e8(0x174,0x19c)+_0x176d46);return{'data':response[_0x3f75e8(0x18f,0x1b2)],'error':null};}catch(_0x391457){return{'data':null,'error':_0x391457 instanceof EBaaSError?_0x391457:new EBaaSError(_0x391457 instanceof Error?_0x391457[_0x3f75e8(0x18a,0x17b)]:_0x3f75e8(0xdd,0xdf),0x0,_0x391457)};}}async[_0x3178ce(-0xd3,-0x58)](){function _0x61858f(_0xedfe74,_0x196b75){return _0x20ed(_0x196b75-0x1ed,_0xedfe74);}try{const response=await this['httpClient']['get'](_0x61858f(0x247,0x26d));return{'data':response['data'],'error':null};}catch(_0x2650ce){return{'data':null,'error':_0x2650ce instanceof EBaaSError?_0x2650ce:new EBaaSError(_0x2650ce instanceof Error?_0x2650ce['message']:'Failed\x20to\x20get\x20storage\x20usage',0x0,_0x2650ce)};}}}class EventManager{constructor(){this['events']=new Map(),this['maxListeners']=0xa;}['on'](_0x45d746,_0x5f2005){function _0x580e55(_0x3d5a34,_0x1c0561){return _0x20ed(_0x1c0561- -0x20a,_0x3d5a34);}!this['events']['has'](_0x45d746)&&this['events']['set'](_0x45d746,new Set()),this[_0x580e55(-0x8e,-0x114)]['get'](_0x45d746)['add'](_0x5f2005);}['off'](_0x1e13a0,_0x1b1fb6){if(!this[_0x42e553(0x4d2,0x4ae)]['has'](_0x1e13a0))return;function _0x42e553(_0x794561,_0x395e1c){return _0x20ed(_0x395e1c-0x3b8,_0x794561);}const _0x4994fd=this[_0x42e553(0x4fe,0x4ae)]['get'](_0x1e13a0);_0x1b1fb6?_0x4994fd[_0x42e553(0x510,0x4e8)](_0x1b1fb6):_0x4994fd[_0x42e553(0x486,0x45e)](),_0x4994fd['size']===0x0&&this['events']['delete'](_0x1e13a0);}[_0x3178ce(0x6f,-0x7)](_0x1b2745,..._0x3e0657){if(!this['events']['has'](_0x1b2745))return![];function _0x19e64a(_0x49c261,_0x2e2722){return _0x20ed(_0x2e2722- -0x3d7,_0x49c261);}const _0x341c6e=this[_0x19e64a(-0x288,-0x2e1)][_0x19e64a(-0x231,-0x28d)](_0x1b2745);for(const _0x1d8900 of _0x341c6e){try{_0x1d8900(..._0x3e0657);}catch(_0x22ba3b){console['error']('Error\x20in\x20event\x20listener\x20for\x20\x22'+_0x1b2745+'\x22:',_0x22ba3b);}}return _0x341c6e['size']>0x0;}['removeAllListeners'](_0x38cee1){function _0x362cfb(_0x289bd1,_0x1ffac9){return _0x20ed(_0x1ffac9-0x193,_0x289bd1);}_0x38cee1?this[_0x362cfb(0x2a0,0x289)][_0x362cfb(0x320,0x2c3)](_0x38cee1):this['events'][_0x362cfb(0x29a,0x239)]();}['listenerCount'](_0x1c8c6c){function _0x3f6700(_0x380359,_0xb7a977){return _0x20ed(_0xb7a977- -0x21c,_0x380359);}return this['events'][_0x3f6700(-0xe5,-0xd2)](_0x1c8c6c)?.['size']??0x0;}['eventNames'](){function _0xb2b153(_0x1e9947,_0x457e76){return _0x20ed(_0x457e76-0x26f,_0x1e9947);}return Array[_0xb2b153(0x363,0x3d7)](this['events']['keys']());}['listeners'](_0x2683e6){function _0x5d94bf(_0x4595bd,_0x22cbdd){return _0x20ed(_0x22cbdd- -0x9f,_0x4595bd);}return Array['from'](this[_0x5d94bf(0xae,0x57)]['get'](_0x2683e6)??[]);}[_0x3178ce(0x4a,0xe)](_0x81243e,_0x2bda2f){this['on'](_0x81243e,_0x2bda2f);}['removeListener'](_0x283d47,_0x3d4a3b){function _0x17cefa(_0x1f288d,_0x50d62e){return _0x20ed(_0x50d62e- -0x333,_0x1f288d);}this[_0x17cefa(-0x27d,-0x234)](_0x283d47,_0x3d4a3b);}['once'](_0x5b544e,_0x1addc4){const _0x1376b9=(..._0xab1c15)=>{this[_0x4187d1(0x15c,0x102)](_0x5b544e,_0x1376b9);function _0x4187d1(_0x449157,_0x5e6994){return _0x20ed(_0x5e6994-0x3,_0x449157);}_0x1addc4(..._0xab1c15);};this['on'](_0x5b544e,_0x1376b9);}[_0x3178ce(0x28,-0xe)](_0x272781,_0x531432){this['on'](_0x272781,_0x531432);}['prependOnceListener'](_0xcd90d3,_0x3cd842){const _0x5b24b9=(..._0x239969)=>{this['off'](_0xcd90d3,_0x5b24b9),_0x3cd842(..._0x239969);};this['on'](_0xcd90d3,_0x5b24b9);}['setMaxListeners'](_0x1fae8f){function _0x4d78af(_0x471049,_0x30e1f4){return _0x20ed(_0x30e1f4-0x47,_0x471049);}return this[_0x4d78af(0x214,0x1bd)]=_0x1fae8f,this;}[_0x3178ce(0x3,0x16)](){function _0x5750ce(_0xcab83f,_0x4572ef){return _0x20ed(_0x4572ef- -0x233,_0xcab83f);}return this[_0x5750ce(-0x130,-0xbd)];}['rawListeners'](_0x4c4ab4){function _0xeeb081(_0x29eb4c,_0x3250fc){return _0x20ed(_0x29eb4c-0x252,_0x3250fc);}return this[_0xeeb081(0x334,0x3b7)](_0x4c4ab4);}}class RealtimeChannel extends EventManager{constructor(_0x56ab7d,_0x49bb97){super(),this['joinedOnce']=![],this['state']='closed',this['subscriptions']=new Map(),this[_0xa6dd7c(0x4b5,0x505)]=_0x56ab7d;function _0xa6dd7c(_0x57614e,_0x36c0f8){return _0x20ed(_0x57614e-0x368,_0x36c0f8);}this['socket']=_0x49bb97;}[_0x3178ce(0x89,0x4)](_0x533d71){function _0x48bdcf(_0xa6d743,_0x111e16){return _0x20ed(_0xa6d743-0x1a0,_0x111e16);}return!this['joinedOnce']&&(this[_0x48bdcf(0x283,0x24d)]=!![],this['_join']()),_0x533d71&&this['on'](_0x48bdcf(0x2a5,0x246),_0x533d71),this;}['onPostgresChanges'](filter,_0x1f632a){const _0x535a1e=_0x406569(0x7b,0x4e)+JSON[_0x406569(-0xa6,-0x22)](filter);this['on'](_0x535a1e,_0x1f632a);const _0x54e174={'unsubscribe':()=>{this['off'](_0x535a1e,_0x1f632a);function _0x575d1b(_0x86f259,_0x5d691c){return _0x20ed(_0x86f259- -0x44,_0x5d691c);}this['subscriptions'][_0x575d1b(0xec,0xa3)](_0x535a1e);}};this['subscriptions']['set'](_0x535a1e,_0x54e174);function _0x406569(_0x39f0a7,_0x1da9cd){return _0x20ed(_0x1da9cd- -0xec,_0x39f0a7);}return this[_0x406569(0x3e,0x8f)]?.[_0x406569(0x90,0xe)]&&this[_0x406569(0xa7,0x65)]===_0x406569(0xd,0x8e)&&this[_0x406569(0x86,0x8f)][_0x406569(0x8,0x51)]('subscribe_postgres_changes',{'topic':this['topic'],'filter':filter,'ref':this[_0x406569(0x8c,0x52)]()}),_0x54e174;}['onBroadcast'](filter,_0x2a8b56){const _0x489d34='broadcast:'+JSON['stringify'](filter);this['on'](_0x489d34,_0x2a8b56);const _0x2cf2d7={'unsubscribe':()=>{function _0x3b3915(_0x3c83b3,_0x143dd5){return _0x20ed(_0x143dd5- -0x28d,_0x3c83b3);}this['off'](_0x489d34,_0x2a8b56),this[_0x3b3915(-0x23c,-0x210)]['delete'](_0x489d34);}};return this['subscriptions']['set'](_0x489d34,_0x2cf2d7),_0x2cf2d7;}['onPresence'](filter,_0x556bb3){const _0x4f546c=_0x280940(0x2f2,0x2ff)+JSON[_0x280940(0x269,0x2d7)](filter);this['on'](_0x4f546c,_0x556bb3);const _0x8402f1={'unsubscribe':()=>{function _0xed96c8(_0x526be7,_0x45b7ee){return _0x20ed(_0x45b7ee- -0x47,_0x526be7);}this['off'](_0x4f546c,_0x556bb3),this['subscriptions'][_0xed96c8(0x113,0xe9)](_0x4f546c);}};function _0x280940(_0x79ab34,_0x41873f){return _0x20ed(_0x79ab34-0x19f,_0x41873f);}return this['subscriptions']['set'](_0x4f546c,_0x8402f1),_0x8402f1;}['send'](_0x29ef36){return new Promise(_0x1658d4=>{function _0x38e730(_0x7739a7,_0x4da0c8){return _0x20ed(_0x7739a7- -0x3b1,_0x4da0c8);}this[_0x38e730(-0x236,-0x1cc)]?.[_0x38e730(-0x2b7,-0x25c)]&&this[_0x38e730(-0x260,-0x231)]==='joined'?(this[_0x38e730(-0x236,-0x1ac)]['emit']('broadcast',{'topic':this['topic'],'event':_0x29ef36[_0x38e730(-0x2f3,-0x2a7)],'payload':_0x29ef36,'ref':this[_0x38e730(-0x273,-0x2c0)]()}),_0x1658d4('ok')):_0x1658d4(_0x38e730(-0x272,-0x249));});}[_0x3178ce(-0x47,-0x98)](_0xf80bfc){return new Promise(_0x1a98f=>{function _0x5bcaea(_0x52126d,_0x919d95){return _0x20ed(_0x52126d-0x18,_0x919d95);}this['socket']?.[_0x5bcaea(0x112,0xaf)]&&this[_0x5bcaea(0x169,0x1a0)]===_0x5bcaea(0x192,0x11e)?(this[_0x5bcaea(0x193,0x1aa)][_0x5bcaea(0x155,0x1a2)](_0x5bcaea(0x16f,0x16b),{'topic':this['topic'],'event':_0x5bcaea(0xc4,0x7a),'payload':_0xf80bfc,'ref':this['makeRef']()}),_0x1a98f('ok')):_0x1a98f('error');});}[_0x3178ce(0x2,-0x2d)](){return new Promise(_0x5c1157=>{function _0x16fc29(_0x1ea205,_0x47fc95){return _0x20ed(_0x1ea205- -0x88,_0x47fc95);}this[_0x16fc29(0xf3,0xf4)]?.[_0x16fc29(0x72,0xab)]&&this[_0x16fc29(0xc9,0x7a)]==='joined'?(this['socket'][_0x16fc29(0xb5,0x64)](_0x16fc29(0xcf,0x117),{'topic':this[_0x16fc29(0xc5,0xb5)],'event':'untrack','ref':this[_0x16fc29(0xb6,0x62)]()}),_0x5c1157('ok')):_0x5c1157('error');});}[_0x3178ce(-0x38,0x17)](){return new Promise(_0x459d04=>{this['state']='leaving',this[_0x1387b9(-0x19a,-0x13b)][_0x1387b9(-0x10f,-0x180)](_0x168775=>{function _0x2683e0(_0x15f59a,_0x193979){return _0x20ed(_0x193979-0x2a1,_0x15f59a);}_0x168775[_0x2683e0(0x3dc,0x3fc)]();}),this[_0x1387b9(-0x19a,-0x123)][_0x1387b9(-0x171,-0xfc)]();this[_0x1387b9(-0x9c,-0x11e)]?.['connected']&&this[_0x1387b9(-0x9c,-0xbc)][_0x1387b9(-0xda,-0xcd)](_0x1387b9(-0x1a1,-0x1ba),{'topic':this[_0x1387b9(-0xca,-0x11d)],'ref':this[_0x1387b9(-0xd9,-0xf5)]()});this[_0x1387b9(-0xc6,-0xdb)]='closed',this['removeAllListeners']();function _0x1387b9(_0x2ca54e,_0x307366){return _0x20ed(_0x2ca54e- -0x217,_0x307366);}_0x459d04('ok');});}[_0x3178ce(-0x4c,-0x90)](){if(this[_0x12f438(0x28f,0x27b)]===_0x12f438(0x16e,0x1c2))return;function _0x12f438(_0x3373ba,_0x25880c){return _0x20ed(_0x25880c-0x12a,_0x3373ba);}this['state']=_0x12f438(0x1ac,0x201),this['socket']?.[_0x12f438(0x23b,0x224)]&&(this['socket'][_0x12f438(0x2d3,0x267)](_0x12f438(0x20f,0x21c),{'topic':this[_0x12f438(0x1f0,0x277)],'ref':this['makeRef']()}),setTimeout(()=>{function _0x2bf75e(_0x10c9f2,_0x3c0c91){return _0x20ed(_0x3c0c91- -0x264,_0x10c9f2);}this[_0x2bf75e(-0x184,-0x113)]===_0x2bf75e(-0x18b,-0x18d)&&(this['state']='joined',this['emit'](_0x2bf75e(-0x15f,-0x15f),_0x2bf75e(-0x1e0,-0x16b)));},0x64));}['_rejoin'](){function _0x26a431(_0x3f3563,_0x27db68){return _0x20ed(_0x3f3563- -0x222,_0x27db68);}this[_0x26a431(-0x13f,-0xb6)]&&(this[_0x26a431(-0x16e,-0x163)](),this['subscriptions']['forEach']((_0x2ba9e4,_0x2a6cb5)=>{function _0x8958c7(_0x2322ac,_0xba8367){return _0x20ed(_0x2322ac-0x1b1,_0xba8367);}if(_0x2a6cb5['startsWith'](_0x8958c7(0x2eb,0x285))){const filter=JSON['parse'](_0x2a6cb5['replace']('postgres_changes:',''));this['socket']?.['emit'](_0x8958c7(0x2d1,0x2fd),{'topic':this['topic'],'filter':filter,'ref':this[_0x8958c7(0x2ef,0x2d3)]()});}}));}['_trigger'](_0xfeb822,_0x261bbd){function _0x47423e(_0xfa9a62,_0x24282a){return _0x20ed(_0x24282a- -0xca,_0xfa9a62);}if(_0xfeb822==='postgres_changes'){const _0xa2d735='postgres_changes:'+JSON[_0x47423e(-0x10,0x0)](_0x261bbd['filter']||{});this['emit'](_0xa2d735,_0x261bbd);}else{if(_0xfeb822===_0x47423e(0x21,-0x51)){const _0x3b5a24=_0x47423e(0xd0,0x49)+JSON[_0x47423e(0x64,0x0)]({'event':_0x261bbd[_0x47423e(-0x10,-0xc)]});this['emit'](_0x3b5a24,_0x261bbd);}else{if(_0xfeb822==='presence'){const _0x47729e=_0x47423e(0x47,0x89)+JSON[_0x47423e(-0x81,0x0)]({'event':_0x261bbd['event']});this[_0x47423e(0x36,0x73)](_0x47729e,_0x261bbd);}}}this['emit'](_0xfeb822,_0x261bbd);}[_0x3178ce(-0x87,-0x5c)](_0x4072d7){this['state']=_0x4072d7;function _0x265637(_0xe8236,_0x2e5a16){return _0x20ed(_0x2e5a16- -0x244,_0xe8236);}let status;switch(_0x4072d7){case _0x265637(-0x11f,-0xca):status='SUBSCRIBED';break;case _0x265637(-0xe7,-0xfe):status='CHANNEL_ERROR';break;case _0x265637(-0xbf,-0xbe):status=_0x265637(-0x134,-0x136);break;default:return;}this[_0x265637(-0x9d,-0x107)](_0x265637(-0x15a,-0x13f),status);}['makeRef'](){function _0x424e25(_0x1778df,_0x461689){return _0x20ed(_0x1778df- -0x1bf,_0x461689);}return Math[_0x424e25(-0x122,-0xf1)]()[_0x424e25(-0xb2,-0x13b)](0x24)[_0x424e25(-0x83,-0xf1)](0x2,0xf);}[_0x3178ce(-0x109,-0xbb)](){function _0x51a6e7(_0x2e11e0,_0x3bd45c){return _0x20ed(_0x3bd45c-0x324,_0x2e11e0);}return this[_0x51a6e7(0x49d,0x475)];}}function getEnvironment(){function _0x203079(_0x533986,_0x191f58){return _0x20ed(_0x533986- -0x380,_0x191f58);}if(typeof navigator!==_0x203079(-0x2a3,-0x21c)&&navigator[_0x203079(-0x2f4,-0x34b)]==='ReactNative')return _0x203079(-0x291,-0x277);if(typeof window!==_0x203079(-0x2a3,-0x2bc)&&typeof document!=='undefined')return _0x203079(-0x2c0,-0x32e);if(typeof global!==_0x203079(-0x2a3,-0x291)&&typeof process!==_0x203079(-0x2a3,-0x266)&&process[_0x203079(-0x309,-0x299)]?.['node'])return _0x203079(-0x222,-0x225);return'browser';}function isSocketIOAvailable(){function _0x41125a(_0x57aa2c,_0x5f2856){return _0x20ed(_0x57aa2c-0x15,_0x5f2856);}try{const _0x162605=getEnvironment();switch(_0x162605){case _0x41125a(0x173,0x1b7):return typeof require!=='undefined'&&require[_0x41125a(0x195,0x19e)]&&!!require[_0x41125a(0x195,0x135)](_0x41125a(0x186,0x1d5));case'browser':if(typeof globalThis!==_0x41125a(0xf2,0x85)&&'io'in globalThis)return!![];return typeof require!==_0x41125a(0xf2,0xdf)&&require[_0x41125a(0x195,0x1dc)]&&!!require[_0x41125a(0x195,0x1dd)]('socket.io-client');case'react-native':try{return typeof require!=='undefined'&&!!require(_0x41125a(0x186,0x12c));}catch{return![];}default:return![];}}catch{return![];}}function getSocketIO(){try{if(typeof require!=='undefined')return require('socket.io-client');if(typeof globalThis!=='undefined'&&'io'in globalThis)return{'io':globalThis['io']};throw new Error('socket.io-client\x20not\x20available');}catch(_0x596072){throw new Error('Socket.io-client\x20não\x20está\x20disponível\x20neste\x20ambiente.\x20Para\x20usar\x20funcionalidades\x20de\x20realtime,\x20instale:\x20npm\x20install\x20socket.io-client');}}class WebSocketAdapter{constructor(){function _0x339e13(_0x468cbd,_0x5564ca){return _0x20ed(_0x5564ca- -0x232,_0x468cbd);}this[_0x339e13(-0x73,-0xb7)]=null;}async['connect'](_0x29bb5e,_0x6a0160){if(!isSocketIOAvailable())throw new Error('Socket.io-client não está disponível. Para usar funcionalidades de realtime, instale: npm install socket.io-client');const {io:_0x2ff2fd}=getSocketIO();return new Promise((_0x47a0c1,_0x78db9b)=>{this[_0x27976b(-0xc9,-0xed)]=_0x2ff2fd(_0x29bb5e,_0x6a0160);function _0x27976b(_0x5475ba,_0x327914){return _0x20ed(_0x327914- -0x268,_0x5475ba);}this['socket']['on']('connect',()=>_0x47a0c1()),this[_0x27976b(-0xc8,-0xed)]['on']('connect_error',_0x567c37=>_0x78db9b(_0x567c37));});}['disconnect'](){function _0x5ef23f(_0x124ed,_0x52449b){return _0x20ed(_0x124ed- -0x1f0,_0x52449b);}this[_0x5ef23f(-0x75,-0x9f)]&&(this['socket'][_0x5ef23f(-0xe4,-0xbb)](),this['socket']=null);}['emit'](_0x284155,data){function _0x4185ec(_0x2e9b75,_0x1cd899){return _0x20ed(_0x1cd899-0x3e8,_0x2e9b75);}this['socket']?.[_0x4185ec(0x52c,0x525)](_0x284155,data);}['on'](_0x1fee47,_0x1e95f1){function _0x3e88b1(_0x3db8e6,_0x525dbb){return _0x20ed(_0x525dbb- -0x1f6,_0x3db8e6);}this[_0x3e88b1(-0x81,-0x7b)]?.['on'](_0x1fee47,_0x1e95f1);}[_0x3178ce(-0x2a,-0x45)](_0x1b759b,_0x94468d){function _0x48ed4f(_0x5b8978,_0x49fbb5){return _0x20ed(_0x49fbb5-0x64,_0x5b8978);}_0x94468d?this[_0x48ed4f(0x1b4,0x1df)]?.[_0x48ed4f(0x10e,0x163)](_0x1b759b,_0x94468d):this[_0x48ed4f(0x25d,0x1df)]?.[_0x48ed4f(0x11c,0x163)](_0x1b759b);}get['connected'](){function _0x39802a(_0x377fb3,_0x364374){return _0x20ed(_0x377fb3- -0xa5,_0x364374);}return this[_0x39802a(0xd6,0x140)]?.['connected']??![];}}class ReactNativeSocketAdapter{constructor(){this['socket']=null;}async[_0x3178ce(-0xaa,-0x46)](_0x55f1bb,_0x1dd608){if(!isSocketIOAvailable())throw new Error('Socket.io-client\x20não\x20está\x20disponível.\x20Para\x20React\x20Native,\x20instale:\x20npm\x20install\x20socket.io-client');const {io:_0x47ee56}=getSocketIO();return new Promise((_0x45095b,_0x159a6a)=>{this[_0x17c79e(0x486,0x4e9)]=_0x47ee56(_0x55f1bb,{..._0x1dd608,'transports':[_0x17c79e(0x43a,0x3cf)],'upgrade':![],'autoConnect':!![]}),this['socket']['on']('connect',()=>_0x45095b());function _0x17c79e(_0x486289,_0x368d2){return _0x20ed(_0x486289-0x30b,_0x368d2);}this['socket']['on']('connect_error',_0x21411b=>_0x159a6a(_0x21411b));});}[_0x3178ce(-0x8d,-0x38)](){function _0x285c84(_0xdcc057,_0x2eb0eb){return _0x20ed(_0x2eb0eb-0x254,_0xdcc057);}this[_0x285c84(0x3c6,0x3cf)]&&(this['socket'][_0x285c84(0x34e,0x360)](),this['socket']=null);}[_0x3178ce(0x52,-0x7)](_0x3cc95d,data){function _0x48ce79(_0x5f47b7,_0x28c795){return _0x20ed(_0x28c795-0x162,_0x5f47b7);}this[_0x48ce79(0x2ca,0x2dd)]?.[_0x48ce79(0x280,0x29f)](_0x3cc95d,data);}['on'](_0x220f0b,_0x463244){this['socket']?.['on'](_0x220f0b,_0x463244);}['off'](_0x37d663,_0x163eb1){function _0x5d2d38(_0x290225,_0x44092c){return _0x20ed(_0x44092c-0x227,_0x290225);}_0x163eb1?this[_0x5d2d38(0x3e7,0x3a2)]?.[_0x5d2d38(0x34f,0x326)](_0x37d663,_0x163eb1):this['socket']?.[_0x5d2d38(0x377,0x326)](_0x37d663);}get['connected'](){function _0x2d5706(_0x54721e,_0x56032c){return _0x20ed(_0x54721e-0x22e,_0x56032c);}return this[_0x2d5706(0x3a9,0x417)]?.['connected']??![];}}function createSocketAdapter(){function _0x65cc29(_0x1df468,_0x39816c){return _0x20ed(_0x1df468-0x38c,_0x39816c);}const _0x3b05f8=getEnvironment();switch(_0x3b05f8){case _0x65cc29(0x47b,0x419):return new ReactNativeSocketAdapter();case _0x65cc29(0x44c,0x3d1):case _0x65cc29(0x4ea,0x4a4):default:return new WebSocketAdapter();}}function _0x22b1(){const _0x10ba9c=['AM9PBMvKt25Jzq','zgv0ywLSCW','DxbKyxrLqNvJA2v0','zgv0zwn0zwrdB25MAwC','B2zMC2v0','x3nLDfn0yxrL','uMvXDwvZDcbMywLSzwq','y3jLzgvUDgLHBhm','yxbWzw5K','z2v0vxnHz2u','DhjHBNnMB3jT','lMfZyW','CMvHy3qTBMf0AxzL','zw52','Bgv2zwW','AM9PBG','l2f1DgGVDJeVC2LNBNvW','rNvUy3rPB24GAw52B2nHDgLVBIbMywLSzwq','BMfTzq','zxzLBNrZ','rujHyvnfCNjVCG','icHtDgf0Dxm6ia','u1vcu0nssujfra','y29UBMvJDgvK','C3rVCMfNzq','Cg9ZDgDYzxnqB3j0','rMfPBgvKihrVihrLC3qGy29UBMvJDgLVBG','y29UBMvJDa','B2zM','mZu4ohjXz0vsAW','Aw52B2TL','DxbKyxrLrw52','CMfUz2u','Bg9N','C3rHDhvZ','Bw92zq','AgfUzgXLqxv0AevYCM9Y','zM9YrwfJAa','C2v0v29YA3nWywnLswq','l2z1BMn0Aw9UCY92mq','l3jWyY8','zgLZy29UBMvJDa','Dg9tDhjPBMC','q0Xpu0ve','CMvTB3zLq3vZDg9Trgf0ywjHC2u','CMvZDfvYBa','l3n0B3jHz2uVyNvJA2v0CY8','y3vYCMvUDfnLC3nPB24','yNjVywrJyxn0oG','AgfZ','Bwf4uMvJB25Uzwn0qxr0zw1WDhm','yxv0B0rLDgvJDen1C3rVBurHDgfIyxnL','Dw50CMfJAW','C2vSzwn0','y3vZDg9Trgf0ywjHC2vnyw5Hz2vY','qxv0AenSAwvUDa','zNvUy3rPB25Z','B3bLCMf0B3i','Cg9YDa','Ahr0CenSAwvUDa','CMvZzxrqyxnZD29Yza','C3vIC2nYAwjLx3bVC3rNCMvZx2nOyw5Nzxm','DgLTzw91Da','p29WzxjHDgLVBJ11ChnLCNq','zMLSDgvYCW','CgfYC2u','z2v0v29YA3nWywnLswq','CMvTB3zLqwXSq2HHBM5LBhm','BwvZC2fNzq','yNvJA2v0swq','x3jLAM9PBG','uhjLzMvY','mtuYyKTVwwLj','zgf0yq','lMrLC2m','rMfPBgvKihrVigDLDcbMDw5JDgLVBIbSB2DZ','D2vIC29JA2v0','zgvSzxrL','Cg9ZDgDYzxnFy2HHBMDLCW','BM93','zxHLy3v0zq','BgvUz3rO','zgvMyxvSDhm','ChjLCgvUzeXPC3rLBMvY','C2v0DxbjBNrLCMnLChrVCNm','DxjS','DMvYC2LVBG','Cg9ZDgDYzxnFy2HHBMDLCZO','D2fYBG','C3vIC3rYAw5N','zw1PDa','BwfRzvjLzG','zxjYB3i','zw50CNLWB2LUDa','igf0DgvTChrZoIa','DMfSDwu','z2v0q2HHBM5LBhm','mtqXnJnxvePOEeS','CMvJB25Uzwn0qxr0zw1WDhm','zxjYB3jLza','DxbKyxrLt3b0Aw9UCW','C3vIC2nYAwjL','z3rL','z2v0','AgfZq3vZDg9Trgf0ywjHC2u','C3rHy2S','Dg9WAwm','mtmXmdDvEwLKqwe','AgfUzgXLrxjYB3i','l3n0B3jHz2uVyNvJA2v0CW','C3rHDgu','ywrKtgLZDgvUzxi','ChjLC2vUy2u6','y29UBMvJDgLVBLn0yxrL','zgf0ywjHC2u','B3bLCMf0Aw9U','ChjLC2vUy2u','Chv0','Aw1WB3j0twfW','z2v0twf4tgLZDgvUzxjZ','Dw5ZDwjZy3jPyMu','z2v0q3vZDg9Trgf0ywjHC2vtDgf0Dxm','sfruucbYzxf1zxn0igzHAwXLza','BM9Kzq','z2v0qNvJA2v0','C2v0u2vZC2LVBG','yMXVyG','Ec10B3rHBc1JB3vUDa','C2vHCMnO','CxvLCNK','y29UzMLN','z2v0tg9NCW','l2zPBgvZ','zNjVBq','zxHLy3v0zvf1zxj5','C2nOzw1H','shr0CenSAwvUDa','y2HHBM5LBa','mteZmdHkt01fs0K','l2f1DgGVDJeVCMvMCMvZAa','CMvTB3zLsxrLBq','nKDtqNzpCq','C29JA2v0lMLVlwnSAwvUDa','Cg9ZDgDYzxnvC2vYBMfTzq','C2v0DxbizwfYDgjLyxq','y2XLyxjtzxnZAw9U','l2zPBgvZlW','Bwf4tgLZDgvUzxjZ','C2LNBLvW','AgvHCNrIzwf0sw50zxj2ywW','rMfPBgvKihrVignYzwf0zsbIDwnRzxq','AM9PBMvK','C29JA2v0','rgf0ywjHC2uGB3bLCMf0Aw9UigzHAwXLza','y29UDgfPBNm','Aw5PDgLHBgL6zq','zw50CMLLCW','CMvZB2X2zq','DgfIBgu','Cg9ZDa','B3b0Aw9UCW','y29TBw9U','zg93BMXVywq','y2XVC2vK','qMvHCMvYia','z2XVyMfS','BgvHDMu','DMvYC2LVBNm','rNvUy3rPB25Zq2XPzw50','yNjVywrJyxn0','rMfPBgvKihrVigrLBgv0zsbIDwnRzxq','DxbKyxrLvxnLCG','DMvYAwz5','C3vIC2nYAxb0Aw9UCW','C3bSAxq','rMfPBgvKihrVigDLDcbMAwXLigLUzM8','l3n0B3jHz2uVDxnHz2u','CgvYAw9K','C29YDej5','y2fJAgvdB250CM9S','zgLZy29UBMvJDgvK','C3rHDhvZvgv4Da','mtiZnJa4oejxuxrVDW','B3jKzxi','yMfZzvvsta','z2v0u3rHDgu','rMfPBgvKihrVihvWzgf0zsbIDwnRzxq','DxnLCG','ChjVzhvJDa','ms4XlJG','C3nSrw5HyMXLza','D29YA3nWywnLswq','BxvSDgLWyxj0l2zVCM0Tzgf0yq','y29UBMvJDgLUzW','ChvZAa','ChjLzML4','C2vZC2LVBG','y29UBMvJDf9LCNjVCG','l3nKAY92mq','Aw50zxjJzxb0B3jZ','BgvHDMLUzW','y29Kzq','vw5ZDxbWB3j0zwqGsfruucbTzxrOB2q6ia','nenuBNzHrG','Cgf0y2G','CMfUzg9T','C29JA2v0qwrHChrLCG','CMvQzwn0','l2zPBgvZl21VDMu','yxbPs2v5','l2z1BMn0Aw9UCY92ms8','mtbXwhvvs0K','rMfPBgvKihrVigrLCgXVEsbMDw5JDgLVBG','y3jLyxrLqNvJA2v0','y2XLyxi','y29UzMLNDxjLq3vZDg9Trgf0ywjHC2u','vw5RBM93BIbLCNjVCG','zgf0yufYCMf5','CMvHBhrPBwu','CMvTB3zLqxv0AfrVA2vU','DhjHy2S','DgvZDenVBM5Ly3rPB24','z2v0q3vZDg9Tq3jLzgvUDgLHBhm','AwXPA2u','zgv0zwn0q3vZDg9Trgf0ywjHC2u','l21LDhjPy3m','Dgv4Dc9WBgfPBG','yM9KEq','x2PVAw4','rMfPBgvKihrVignVBM5Ly3qGywz0zxiG','BgLRzq','DxbKyxrLrgf0yq','AgvHzgvYCW','BgLZDej1y2TLDhm','l2f1DgGVDJeVDxnLCG','mJK0odG1swzUCuPe','Bg9HzfnLC3nPB24','rgf0ywjHC2vdBgLLBNq','zxzLBNq','y2XPzw50','yNjVD3nLCG','y3jLyxrLu2LNBMvKvxjS','Bwv0Ag9K','mtuWnZq0mfbkt2jeDW','l2f1DgGVDJeVCMvZzxqTCgfZC3DVCMq','u3rVCMfNzunSAwvUDa','ywnJzxnZx3rVA2vU','AxnezwXLDgu','uMvHBhrPBwvdAgfUBMvS','CNbJ','C3rYAw5NAwz5','DgvZDen1C3rVBunVBM5Ly3rPB24','rujHyvndBgLLBNq','C2v0u2vZC2LVBKLUDgvYBMfS','y2HHBM5LBhm','DxbSB2fK','zMLSzq','Aw5Zzxj0','rMfPBgvKihrVignYzwf0zsbZAwDUzwqGvvjm','Aw5PDgLHBgL6zun1C3rVBurHDgfIyxnL','BgLTAxq','zwjHyxmUyxv0Ac5ZzxnZAw9U','l2rLCgXVEq','AM9PBMLUzW','y29UDgvUDfr5Cgu','ndC1ntzcD3flChy','C2v0qxv0AfrVA2vU','y29SDw1U','BMvX','Dw5KzwzPBMvK','l2LUzM8','z2v0u3rHDhvZ','l2f1DgGVDJeVC2rRl3nPz25PBG','q3vZDg9Trgf0ywjHC2vnyw5Hz2vY','BgLZDgvUzxjZ'];_0x22b1=function(){return _0x10ba9c;};return _0x22b1();}class RealtimeClient{constructor(_0xe6946c,_0x1b81bd,_0x2528e7={}){this[_0x39f01f(0x457,0x495)]=null,this['channels']=new Map(),this['connectionState']=_0x39f01f(0x360,0x2ee),this[_0x39f01f(0x421,0x445)]=0x0;function _0x39f01f(_0x30f45b,_0x908f87){return _0x20ed(_0x30f45b-0x2dc,_0x908f87);}this[_0x39f01f(0x3f1,0x392)]=0x5,this[_0x39f01f(0x414,0x45e)]=_0xe6946c,this[_0x39f01f(0x37d,0x33e)]=_0x1b81bd,this[_0x39f01f(0x45f,0x43f)]={'heartbeatInterval':0x7530,'reconnectInterval':0x1388,'maxReconnectAttempts':0x5,..._0x2528e7},this['socketAdapter']=createSocketAdapter();}[_0x3178ce(-0x29,-0x46)](){return new Promise(async(_0x108f0b,_0x52f178)=>{if(this['socketAdapter']['connected']){_0x108f0b();return;}this['connectionState']=_0x23233b(0x495,0x464);function _0x23233b(_0x484d5b,_0x3bb871){return _0x20ed(_0x3bb871-0x3d3,_0x484d5b);}try{await this['socketAdapter'][_0x23233b(0x4a4,0x4d1)](this[_0x23233b(0x58b,0x50b)],{'auth':{'apikey':this['apiKey']},'transports':[_0x23233b(0x559,0x502)],'reconnection':!![],'reconnectionDelay':this['options']['reconnectInterval'],'reconnectionAttempts':this['options']['maxReconnectAttempts'],...this['options']['socketOptions']}),this[_0x23233b(0x5d0,0x54e)]=this['socketAdapter']['socket'],this['socketAdapter']['on'](_0x23233b(0x558,0x4d1),()=>{this['connectionState']='connected',this['reconnectAttempts']=0x0,this[_0x1cc9f8(0x10d,0x157)]();function _0x1cc9f8(_0x52f4a2,_0x48252a){return _0x20ed(_0x52f4a2- -0x66,_0x48252a);}_0x108f0b();}),this['socketAdapter']['on'](_0x23233b(0x52a,0x4df),()=>{this[_0x358ef5(0x55a,0x515)]=_0x358ef5(0x48b,0x445);function _0x358ef5(_0x56380c,_0x4ea4e2){return _0x20ed(_0x4ea4e2-0x3c1,_0x56380c);}this[_0x358ef5(0x4d1,0x48f)][_0x358ef5(0x484,0x4c9)](channel=>{channel['_setState']('closed');});}),this['socketAdapter']['on']('connect_error',_0x40fbe6=>{this['connectionState']=_0x54c76e(0x433,0x43d),this[_0x54c76e(0x439,0x4bc)]++;function _0x54c76e(_0x3ad7c0,_0x50ab88){return _0x20ed(_0x3ad7c0-0x2f4,_0x50ab88);}this[_0x54c76e(0x439,0x4bd)]>=this['maxReconnectAttempts']&&_0x52f178(new Error(_0x54c76e(0x3a9,0x371)+this['maxReconnectAttempts']+_0x54c76e(0x435,0x3d4)+_0x40fbe6[_0x54c76e(0x41b,0x49a)]));}),this[_0x23233b(0x3e9,0x471)]['on']('reconnect',()=>{this[_0x477464(0x3bb,0x3ec)]='connected',this[_0x477464(0x3df,0x3dd)]=0x0;function _0x477464(_0x5ec483,_0x2cdcc5){return _0x20ed(_0x2cdcc5-0x298,_0x5ec483);}this['channels'][_0x477464(0x370,0x3a0)](channel=>{function _0x23ad34(_0x8f79e3,_0x2b0153){return _0x20ed(_0x8f79e3-0x29b,_0x2b0153);}channel[_0x23ad34(0x3c4,0x3e6)]();});}),this[_0x23233b(0x4d6,0x471)]['on']('postgres_changes',_0x19517e=>{const channel=this[_0x1b6223(-0x137,-0x166)][_0x1b6223(-0x12f,-0xea)](_0x19517e['topic']);function _0x1b6223(_0x5c14f3,_0x7bcca5){return _0x20ed(_0x7bcca5- -0x234,_0x5c14f3);}channel&&channel['_trigger'](_0x1b6223(-0xbb,-0x103),_0x19517e);}),this['socketAdapter']['on'](_0x23233b(0x416,0x44c),_0x22281d=>{const channel=this['channels']['get'](_0x22281d['topic']);channel&&channel['_trigger']('broadcast',_0x22281d);}),this['socketAdapter']['on']('presence',_0x40b63b=>{const channel=this['channels'][_0x591cdf(0x4dc,0x498)](_0x40b63b[_0x591cdf(0x4df,0x4d2)]);function _0x591cdf(_0xb95bbc,_0x3cbebd){return _0x20ed(_0xb95bbc-0x392,_0x3cbebd);}channel&&channel['_trigger'](_0x591cdf(0x4e9,0x509),_0x40b63b);});}catch(_0x291136){this['connectionState']=_0x23233b(0x4cd,0x512),_0x52f178(_0x291136);}});}[_0x3178ce(0x1a,-0x38)](){this['socketAdapter']&&(this[_0x2cf955(-0x1ed,-0x173)]['disconnect'](),this[_0x2cf955(-0x110,-0xa2)]=null);function _0x2cf955(_0x5bef6f,_0xce2ee6){return _0x20ed(_0x5bef6f- -0x28b,_0xce2ee6);}this['connectionState']=_0x2cf955(-0x207,-0x27c),this['channels']['clear']();}['channel'](_0x173259){if(this[_0xce0dbc(0x76,0xba)][_0xce0dbc(0xbc,0xf1)](_0x173259))return this['channels']['get'](_0x173259);function _0xce0dbc(_0x133593,_0x5035cb){return _0x20ed(_0x133593- -0x58,_0x5035cb);}const channel=new RealtimeChannel(_0x173259,this[_0xce0dbc(0x123,0x15a)]);return this['channels']['set'](_0x173259,channel),this['connectionState']==='connected'&&channel['_join'](),channel;}['removeChannel'](channel){function _0x3e5bae(_0x19730d,_0x572944){return _0x20ed(_0x19730d-0x34c,_0x572944);}const _0x2a6518=channel[_0x3e5bae(0x499,0x4fe)];this['channels']['has'](_0x2a6518)&&(this[_0x3e5bae(0x41a,0x3f3)][_0x3e5bae(0x47c,0x4fb)](_0x2a6518),channel['unsubscribe']());}[_0x3178ce(-0x21,-0x1e)](){this[_0x59d549(0x1c7,0x1ee)][_0x59d549(0x2a1,0x228)](channel=>{channel['unsubscribe']();});function _0x59d549(_0x1c6d24,_0x487547){return _0x20ed(_0x487547-0x120,_0x1c6d24);}this['channels']['clear']();}[_0x3178ce(0x1f,-0x1)](){function _0x46fefc(_0x14e2cc,_0x134de8){return _0x20ed(_0x134de8-0x3c9,_0x14e2cc);}return Array[_0x46fefc(0x5aa,0x531)](this[_0x46fefc(0x433,0x497)]['values']());}['isConnected'](){function _0x395021(_0x3f5de7,_0x369771){return _0x20ed(_0x369771-0x2c6,_0x3f5de7);}return this['connectionState']==='connected'&&this[_0x395021(0x2e2,0x364)]['connected'];}['getConnectionState'](){function _0x5007f2(_0x42765e,_0x40bec4){return _0x20ed(_0x42765e- -0x24a,_0x40bec4);}return this[_0x5007f2(-0xf6,-0x78)];}['onConnectionStateChange'](_0x54a911){function _0x5c3bb0(_0x14d62c,_0x13b9b8){return _0x20ed(_0x14d62c- -0x1fa,_0x13b9b8);}const _0x2d7c97=()=>_0x54a911(this['connectionState']);return this['socketAdapter']&&(this[_0x5c3bb0(-0x15c,-0x1de)]['on'](_0x5c3bb0(-0xfc,-0x140),()=>{this[_0x388320(0x42d,0x491)]='connected';function _0x388320(_0x2fcee3,_0x3f81cb){return _0x20ed(_0x3f81cb-0x33d,_0x2fcee3);}_0x2d7c97();}),this[_0x5c3bb0(-0x15c,-0xe9)]['on']('disconnect',()=>{this[_0x49d583(-0x16c,-0x117)]=_0x49d583(-0x23c,-0x27e);function _0x49d583(_0x2f2b39,_0x396c1e){return _0x20ed(_0x2f2b39- -0x2c0,_0x396c1e);}_0x2d7c97();}),this[_0x5c3bb0(-0x15c,-0x10e)]['on'](_0x5c3bb0(-0x165,-0xea),()=>{this['connectionState']='error',_0x2d7c97();})),()=>{function _0x45b753(_0xa71067,_0x47c719){return _0x20ed(_0xa71067-0x2c3,_0x47c719);}this['socketAdapter']&&(this[_0x45b753(0x361,0x32e)]['off']('connect',_0x2d7c97),this[_0x45b753(0x361,0x344)]['off']('disconnect',_0x2d7c97),this[_0x45b753(0x361,0x2f6)]['off'](_0x45b753(0x358,0x37b),_0x2d7c97));};}[_0x3178ce(0x46,0x2f)](){if(!this[_0x4b2271(0x42,-0x47)][_0x4b2271(0x37,0x2d)]||!this[_0x4b2271(-0xa3,-0xd6)])return;function _0x4b2271(_0x3c7108,_0x4536ab){return _0x20ed(_0x3c7108- -0x141,_0x4536ab);}const interval=setInterval(()=>{function _0x55ab2a(_0x5f5ca2,_0x4a0f5b){return _0x20ed(_0x5f5ca2-0x1d8,_0x4a0f5b);}this['socketAdapter']?.[_0x55ab2a(0x2d2,0x314)]?this[_0x55ab2a(0x276,0x243)][_0x55ab2a(0x315,0x363)]('heartbeat',{'timestamp':Date[_0x55ab2a(0x30a,0x308)]()}):clearInterval(interval);},this[_0x4b2271(0x42,-0x3f)]['heartbeatInterval']);}['_getSocket'](){function _0xb3032(_0xe45443,_0x4ee2af){return _0x20ed(_0xe45443- -0x264,_0x4ee2af);}return this[_0xb3032(-0xe9,-0x132)];}}class FunctionsClient{constructor(_0x1c7490){function _0x26b5e7(_0x36b562,_0x83c526){return _0x20ed(_0x36b562-0x28f,_0x83c526);}this[_0x26b5e7(0x3ad,0x407)]=_0x1c7490;}async['invoke'](_0x12a5ba,_0x110e07){function _0x298a20(_0x44dde2,_0x330746){return _0x20ed(_0x44dde2- -0x23b,_0x330746);}try{const _0xa16a0d=_0x110e07?.[_0x298a20(-0x179,-0x11b)]||'POST',headers={'Content-Type':'application/json',..._0x110e07?.[_0x298a20(-0x183,-0x171)]};let response;const _0x4ac6d7=_0x298a20(-0x199,-0x197)+_0x12a5ba;switch(_0xa16a0d['toUpperCase']()){case'GET':response=await this[_0x298a20(-0x11d,-0xe8)]['get'](_0x4ac6d7,{'headers':headers,'params':_0x110e07?.[_0x298a20(-0x188,-0x1c2)]});break;case'POST':response=await this['httpClient'][_0x298a20(-0xb9,-0xdc)](_0x4ac6d7,_0x110e07?.[_0x298a20(-0x188,-0x132)],{'headers':headers});break;case'PUT':response=await this[_0x298a20(-0x11d,-0x17d)][_0x298a20(-0xe3,-0x146)](_0x4ac6d7,_0x110e07?.['body'],{'headers':headers});break;case'PATCH':response=await this['httpClient'][_0x298a20(-0x19f,-0x15d)](_0x4ac6d7,_0x110e07?.['body'],{'headers':headers});break;case'DELETE':response=await this['httpClient']['delete'](_0x4ac6d7,{'headers':headers,'data':_0x110e07?.['body']});break;default:throw new EBaaSError(_0x298a20(-0x1a1,-0x165)+_0xa16a0d,0x190);}return{'data':response[_0x298a20(-0x10f,-0x195)],'error':null};}catch(_0x1d5ffa){return{'data':null,'error':_0x1d5ffa instanceof EBaaSError?_0x1d5ffa:new EBaaSError(_0x1d5ffa instanceof Error?_0x1d5ffa['message']:_0x298a20(-0x147,-0x18f),0x0,_0x1d5ffa)};}}async['list'](){function _0x6ed7f7(_0x10e00e,_0x4f2eab){return _0x20ed(_0x10e00e- -0x1cb,_0x4f2eab);}try{const response=await this['httpClient']['get'](_0x6ed7f7(-0xc1,-0xf6));return{'data':response[_0x6ed7f7(-0x9f,-0x124)],'error':null};}catch(_0x4337a4){return{'data':null,'error':_0x4337a4 instanceof EBaaSError?_0x4337a4:new EBaaSError(_0x4337a4 instanceof Error?_0x4337a4[_0x6ed7f7(-0xa4,-0xc1)]:'Failed\x20to\x20list\x20functions',0x0,_0x4337a4)};}}async['get'](_0x5c274a){function _0x365a18(_0x5cbaf7,_0x9817c7){return _0x20ed(_0x9817c7-0x8,_0x5cbaf7);}try{const response=await this[_0x365a18(0x10b,0x126)][_0x365a18(0xcb,0x152)](_0x365a18(0xbe,0xaa)+_0x5c274a+'/info');return{'data':response['data'],'error':null};}catch(_0x2966b8){return{'data':null,'error':_0x2966b8 instanceof EBaaSError?_0x2966b8:new EBaaSError(_0x2966b8 instanceof Error?_0x2966b8[_0x365a18(0x108,0x12f)]:'Failed\x20to\x20get\x20function',0x0,_0x2966b8)};}}async['deploy'](_0x53beee,_0x1a691e){function _0x38914b(_0x25aefa,_0x5ebe26){return _0x20ed(_0x5ebe26- -0x5,_0x25aefa);}try{const _0x1cbb4a=new FormData();if(_0x1a691e['code']instanceof File)_0x1cbb4a[_0x38914b(0xcc,0xe6)]('code',_0x1a691e['code']);else typeof _0x1a691e[_0x38914b(0xc5,0x94)]==='string'&&_0x1cbb4a['append']('code',new Blob([_0x1a691e[_0x38914b(0x1f,0x94)]],{'type':'text/plain'}),'index.ts');_0x1a691e[_0x38914b(0x18e,0x13b)]&&_0x1cbb4a[_0x38914b(0xbf,0xe6)](_0x38914b(0x173,0x13b),_0x1a691e['entrypoint']);_0x1a691e['env']&&_0x1cbb4a[_0x38914b(0x11a,0xe6)]('env',JSON[_0x38914b(0x82,0xc5)](_0x1a691e[_0x38914b(0xd0,0xeb)]));_0x1a691e['importMap']&&_0x1cbb4a[_0x38914b(0x9b,0xe6)]('importMap',JSON['stringify'](_0x1a691e[_0x38914b(0xf0,0x154)]));_0x1a691e[_0x38914b(0x7a,0x77)]!==undefined&&_0x1cbb4a[_0x38914b(0x97,0xe6)]('verify',String(_0x1a691e['verify']));const response=await this['httpClient'][_0x38914b(0x1f7,0x17d)]('/functions/v1/'+_0x53beee+_0x38914b(0x159,0xd1),_0x1cbb4a,{'headers':{'Content-Type':_0x38914b(0xcf,0x8b)}});return{'data':response[_0x38914b(0xdf,0x127)],'error':null};}catch(_0x403be7){return{'data':null,'error':_0x403be7 instanceof EBaaSError?_0x403be7:new EBaaSError(_0x403be7 instanceof Error?_0x403be7['message']:_0x38914b(0x9b,0x9f),0x0,_0x403be7)};}}async[_0x3178ce(-0x30,-0x14)](_0x485356){function _0x2316a0(_0x2105aa,_0x1c5830){return _0x20ed(_0x2105aa-0x255,_0x1c5830);}try{const response=await this[_0x2316a0(0x373,0x2f7)]['delete'](_0x2316a0(0x2f7,0x362)+_0x485356);return{'data':response['data'],'error':null};}catch(_0x39a408){return{'data':null,'error':_0x39a408 instanceof EBaaSError?_0x39a408:new EBaaSError(_0x39a408 instanceof Error?_0x39a408['message']:'Failed\x20to\x20delete\x20function',0x0,_0x39a408)};}}async[_0x3178ce(0x1e,-0x42)](_0x7c514c,_0x404cfa){function _0x1b6f9c(_0x15a057,_0x3155bd){return _0x20ed(_0x3155bd- -0x251,_0x15a057);}try{const response=await this['httpClient'][_0x1b6f9c(-0x92,-0xf9)](_0x1b6f9c(-0x204,-0x1af)+_0x7c514c+'/env',{'env':_0x404cfa});return{'data':response[_0x1b6f9c(-0xb5,-0x125)],'error':null};}catch(_0x39c120){return{'data':null,'error':_0x39c120 instanceof EBaaSError?_0x39c120:new EBaaSError(_0x39c120 instanceof Error?_0x39c120['message']:'Failed\x20to\x20update\x20function\x20environment',0x0,_0x39c120)};}}async[_0x3178ce(0xa2,0x22)](_0x10d611,_0x263494){function _0x513012(_0x4af91c,_0x1dd0fd){return _0x20ed(_0x1dd0fd-0x3a,_0x4af91c);}try{const _0x5e4998=new URLSearchParams();_0x263494?.[_0x513012(0x133,0x10e)]&&_0x5e4998[_0x513012(0x151,0x125)](_0x513012(0x121,0x10e),String(_0x263494[_0x513012(0xcc,0x10e)]));_0x263494?.['offset']&&_0x5e4998['append']('offset',String(_0x263494[_0x513012(0xa9,0x121)]));_0x263494?.['level']&&_0x5e4998[_0x513012(0x9f,0x125)]('level',_0x263494[_0x513012(0xc9,0x12b)]);const _0x830e8e='/functions/v1/'+_0x10d611+'/logs'+(_0x5e4998[_0x513012(0xeb,0x147)]()?'?'+_0x5e4998['toString']():''),response=await this[_0x513012(0x1d3,0x158)][_0x513012(0x1f6,0x184)](_0x830e8e);return{'data':response['data'],'error':null};}catch(_0x194d07){return{'data':null,'error':_0x194d07 instanceof EBaaSError?_0x194d07:new EBaaSError(_0x194d07 instanceof Error?_0x194d07['message']:_0x513012(0xfb,0x168),0x0,_0x194d07)};}}async['getMetrics'](_0x2da99a,_0x5cec8f){function _0x27ac0a(_0x3e77e,_0x22e70f){return _0x20ed(_0x22e70f- -0x3c0,_0x3e77e);}try{const _0x1acb0a=new URLSearchParams();_0x5cec8f?.[_0x27ac0a(-0x322,-0x33f)]&&_0x1acb0a[_0x27ac0a(-0x270,-0x2d5)]('period',_0x5cec8f['period']);const _0x2c0bb6=_0x27ac0a(-0x2dd,-0x31e)+_0x2da99a+_0x27ac0a(-0x2b0,-0x30f)+(_0x1acb0a[_0x27ac0a(-0x271,-0x2b3)]()?'?'+_0x1acb0a['toString']():''),response=await this['httpClient'][_0x27ac0a(-0x217,-0x276)](_0x2c0bb6);return{'data':response[_0x27ac0a(-0x2ba,-0x294)],'error':null};}catch(_0x4c54d3){return{'data':null,'error':_0x4c54d3 instanceof EBaaSError?_0x4c54d3:new EBaaSError(_0x4c54d3 instanceof Error?_0x4c54d3['message']:'Failed\x20to\x20get\x20function\x20metrics',0x0,_0x4c54d3)};}}}class EBaaSClient{constructor(_0x1eca81,_0x5e22ff,_0x4a04b8){this[_0x38b10d(0x1b7,0x18c)]=_0x4a04b8,this[_0x38b10d(0x152,0x14a)]=new HttpClient({'url':_0x1eca81,'apiKey':_0x5e22ff,'timeout':0x7530,'headers':_0x4a04b8?.[_0x38b10d(0xa9,0x133)]?.[_0x38b10d(0xec,0x140)]});function _0x38b10d(_0x2076f5,_0x139412){return _0x20ed(_0x2076f5-0x34,_0x139412);}this['auth']=new AuthClient(this['httpClient'],_0x4a04b8?.['database']?.['workspaceId']),this[_0x38b10d(0x189,0x14a)]=new DatabaseClient(this['httpClient'],_0x4a04b8?.[_0x38b10d(0x189,0x175)]?.['workspaceId'],_0x4a04b8?.['rest']?.['url']),this[_0x38b10d(0x12f,0x11e)]=new StorageClient(this['httpClient']),this['realtime']=new RealtimeClient(_0x1eca81,_0x5e22ff,_0x4a04b8?.[_0x38b10d(0xde,0x69)]),this[_0x38b10d(0x14f,0x109)]=new FunctionsClient(this['httpClient']),this['initializeCustomDatabase']();}['from'](_0x49e705){function _0x229db8(_0x25825a,_0x6e6d48){return _0x20ed(_0x6e6d48- -0xb6,_0x25825a);}return this[_0x229db8(0xdd,0x9f)][_0x229db8(0x9e,0xb2)](_0x49e705);}['rpc'](_0x10714e,_0x2a2f1c){function _0x1998ed(_0x26450f,_0x11b23e){return _0x20ed(_0x11b23e- -0x1eb,_0x26450f);}return this['database'][_0x1998ed(-0x144,-0x122)](_0x10714e,_0x2a2f1c);}['bucket'](_0x27ee71){function _0x1c9b26(_0x202208,_0x3cb4fb){return _0x20ed(_0x3cb4fb- -0x3b2,_0x202208);}return this['storage'][_0x1c9b26(-0x2ae,-0x24a)](_0x27ee71);}[_0x3178ce(-0x1,0x28)](_0x517450){function _0x1be52e(_0x4eb581,_0x1be1e4){return _0x20ed(_0x1be1e4-0x1f2,_0x4eb581);}return this[_0x1be52e(0x247,0x29c)]['channel'](_0x517450);}[_0x3178ce(0x4,-0x43)](_0x11cbf6,_0x56b45f){return this['functions']['invoke'](_0x11cbf6,_0x56b45f);}async[_0x3178ce(-0x63,-0x71)](){function _0x31a5eb(_0x2a3312,_0x5153a3){return _0x20ed(_0x5153a3-0x330,_0x2a3312);}if(this[_0x31a5eb(0x4c9,0x4b3)]?.[_0x31a5eb(0x4f9,0x485)]?.['autoDetectCustomDatabase'])try{await this[_0x31a5eb(0x4f5,0x485)]['initialize']();}catch(_0x2a6305){console[_0x31a5eb(0x422,0x46b)]('Failed to initialize custom database detection:',_0x2a6305);}}async['setWorkspaceId'](_0x179283){this['auth']['setWorkspaceId'](_0x179283);function _0x301359(_0x4594c9,_0x1d4cb6){return _0x20ed(_0x1d4cb6-0x239,_0x4594c9);}this[_0x301359(0x348,0x38e)][_0x301359(0x2f1,0x342)](_0x179283),this[_0x301359(0x3f4,0x3bc)]?.['database']?.[_0x301359(0x312,0x34f)]&&await this[_0x301359(0x346,0x38e)]['initialize']();}async['configureCustomDatabase'](_0x1f62f4){function _0x2b3603(_0x3a2a94,_0x4a3cb1){return _0x20ed(_0x3a2a94- -0x198,_0x4a3cb1);}await this[_0x2b3603(-0x43,-0x9a)][_0x2b3603(-0xf1,-0x76)](_0x1f62f4);}['getCustomDatabaseStatus'](){function _0x37cb(_0x57d560,_0x4cc46a){return _0x20ed(_0x57d560-0x363,_0x4cc46a);}return this[_0x37cb(0x4b8,0x466)][_0x37cb(0x4bf,0x457)]();}}function createClient(_0xf0c974,_0x11dfec,_0xfef3ca){return new EBaaSClient(_0xf0c974,_0x11dfec,_0xfef3ca);}const version=_0x3178ce(-0x121,-0xb7);exports[_0x3178ce(-0x82,-0x2a)]=AuthClient,exports[_0x3178ce(-0xb1,-0x63)]=CustomDatabaseManager,exports[_0x3178ce(-0x45,-0x87)]=DatabaseClient,exports[_0x3178ce(-0x80,-0x78)]=EBaaSClient,exports[_0x3178ce(-0x4e,-0x4d)]=EBaaSError,exports[_0x3178ce(-0x116,-0xcc)]=FunctionsClient,exports[_0x3178ce(-0x30,0x27)]=HttpClient,exports['QueryBuilder']=QueryBuilder,exports[_0x3178ce(-0x28,-0x7c)]=RealtimeChannel,exports['RealtimeClient']=RealtimeClient,exports['StorageBucket']=StorageBucket,exports[_0x3178ce(-0x36,-0x7f)]=StorageClient,exports['createClient']=createClient,exports[_0x3178ce(-0x32,-0xb)]=version;
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var axios = require('axios');
|
|
4
|
+
|
|
5
|
+
class EBaaSError extends Error {
|
|
6
|
+
constructor(message, status = 0, details) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = 'EBaaSError';
|
|
9
|
+
this.status = status;
|
|
10
|
+
this.details = details;
|
|
11
|
+
if (Error.captureStackTrace) {
|
|
12
|
+
Error.captureStackTrace(this, EBaaSError);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
toJSON() {
|
|
16
|
+
return {
|
|
17
|
+
name: this.name,
|
|
18
|
+
message: this.message,
|
|
19
|
+
status: this.status,
|
|
20
|
+
details: this.details,
|
|
21
|
+
stack: this.stack
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
toString() {
|
|
25
|
+
return `${this.name}: ${this.message} (Status: ${this.status})`;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
class HttpClient {
|
|
30
|
+
constructor(config) {
|
|
31
|
+
this.baseURL = config.url;
|
|
32
|
+
this.apiKey = config.apiKey;
|
|
33
|
+
this.client = axios.create({
|
|
34
|
+
baseURL: this.baseURL,
|
|
35
|
+
timeout: config.timeout || 10000,
|
|
36
|
+
headers: {
|
|
37
|
+
'Content-Type': 'application/json',
|
|
38
|
+
'apikey': this.apiKey,
|
|
39
|
+
...config.headers,
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
this.setupInterceptors();
|
|
43
|
+
}
|
|
44
|
+
setupInterceptors() {
|
|
45
|
+
// Request interceptor
|
|
46
|
+
this.client.interceptors.request.use((config) => {
|
|
47
|
+
return config;
|
|
48
|
+
}, (error) => {
|
|
49
|
+
return Promise.reject(new EBaaSError('Request failed', 0, error));
|
|
50
|
+
});
|
|
51
|
+
// Response interceptor
|
|
52
|
+
this.client.interceptors.response.use((response) => {
|
|
53
|
+
return response;
|
|
54
|
+
}, (error) => {
|
|
55
|
+
const status = error.response?.status || 0;
|
|
56
|
+
const message = error.response?.data?.message || error.message || 'Unknown error';
|
|
57
|
+
const details = error.response?.data || error;
|
|
58
|
+
return Promise.reject(new EBaaSError(message, status, details));
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
async get(url, config) {
|
|
62
|
+
try {
|
|
63
|
+
const response = await this.client.get(url, config);
|
|
64
|
+
return {
|
|
65
|
+
data: response.data,
|
|
66
|
+
status: response.status,
|
|
67
|
+
statusText: response.statusText,
|
|
68
|
+
headers: response.headers,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
throw this.handleError(error);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async post(url, data, config) {
|
|
76
|
+
try {
|
|
77
|
+
const response = await this.client.post(url, data, config);
|
|
78
|
+
return {
|
|
79
|
+
data: response.data,
|
|
80
|
+
status: response.status,
|
|
81
|
+
statusText: response.statusText,
|
|
82
|
+
headers: response.headers,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
throw this.handleError(error);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async put(url, data, config) {
|
|
90
|
+
try {
|
|
91
|
+
const response = await this.client.put(url, data, config);
|
|
92
|
+
return {
|
|
93
|
+
data: response.data,
|
|
94
|
+
status: response.status,
|
|
95
|
+
statusText: response.statusText,
|
|
96
|
+
headers: response.headers,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
throw this.handleError(error);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
async patch(url, data, config) {
|
|
104
|
+
try {
|
|
105
|
+
const response = await this.client.patch(url, data, config);
|
|
106
|
+
return {
|
|
107
|
+
data: response.data,
|
|
108
|
+
status: response.status,
|
|
109
|
+
statusText: response.statusText,
|
|
110
|
+
headers: response.headers,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
throw this.handleError(error);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
async delete(url, config) {
|
|
118
|
+
try {
|
|
119
|
+
const response = await this.client.delete(url, config);
|
|
120
|
+
return {
|
|
121
|
+
data: response.data,
|
|
122
|
+
status: response.status,
|
|
123
|
+
statusText: response.statusText,
|
|
124
|
+
headers: response.headers,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
throw this.handleError(error);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
setAuthToken(token) {
|
|
132
|
+
this.client.defaults.headers.common['Authorization'] = `Bearer ${token}`;
|
|
133
|
+
}
|
|
134
|
+
removeAuthToken() {
|
|
135
|
+
delete this.client.defaults.headers.common['Authorization'];
|
|
136
|
+
this.client.defaults.headers.common['Authorization'] = `Bearer ${this.apiKey}`;
|
|
137
|
+
}
|
|
138
|
+
handleError(error) {
|
|
139
|
+
if (error instanceof EBaaSError) {
|
|
140
|
+
return error;
|
|
141
|
+
}
|
|
142
|
+
return new EBaaSError(error.message || 'HTTP request failed', error.status || 0, error);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
class AuthClient {
|
|
147
|
+
constructor(httpClient, workspaceId) {
|
|
148
|
+
this.currentSession = null;
|
|
149
|
+
this.httpClient = httpClient;
|
|
150
|
+
this.workspaceId = workspaceId;
|
|
151
|
+
this.loadSession();
|
|
152
|
+
}
|
|
153
|
+
async signUp(data) {
|
|
154
|
+
try {
|
|
155
|
+
const headers = {};
|
|
156
|
+
console.log('🔍 [SDK DEBUG] SignUp - workspaceId:', this.workspaceId);
|
|
157
|
+
// Incluir x-workspace-id se workspaceId foi fornecido (igual ao signIn)
|
|
158
|
+
if (this.workspaceId) {
|
|
159
|
+
headers['x-workspace-id'] = this.workspaceId;
|
|
160
|
+
console.log('✅ [SDK DEBUG] SignUp - header x-workspace-id adicionado:', this.workspaceId);
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
console.log('❌ [SDK DEBUG] SignUp - workspaceId é undefined, header não adicionado');
|
|
164
|
+
}
|
|
165
|
+
console.log('🔍 [SDK DEBUG] SignUp - headers finais:', headers);
|
|
166
|
+
const response = await this.httpClient.post('/auth/v1/signup', data, {
|
|
167
|
+
headers
|
|
168
|
+
});
|
|
169
|
+
if (response.data.session) {
|
|
170
|
+
this.setSessionInternal(response.data.session);
|
|
171
|
+
}
|
|
172
|
+
return response.data;
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
throw this.handleAuthError(error);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
async signIn(data) {
|
|
179
|
+
try {
|
|
180
|
+
const headers = {};
|
|
181
|
+
// Incluir x-workspace-id se workspaceId foi fornecido
|
|
182
|
+
if (this.workspaceId) {
|
|
183
|
+
headers['x-workspace-id'] = this.workspaceId;
|
|
184
|
+
}
|
|
185
|
+
const response = await this.httpClient.post('/auth/v1/sdk/signin', data, {
|
|
186
|
+
headers
|
|
187
|
+
});
|
|
188
|
+
if (response.data.session) {
|
|
189
|
+
this.setSessionInternal(response.data.session);
|
|
190
|
+
}
|
|
191
|
+
return response.data;
|
|
192
|
+
}
|
|
193
|
+
catch (error) {
|
|
194
|
+
throw this.handleAuthError(error);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
async signOut() {
|
|
198
|
+
try {
|
|
199
|
+
await this.httpClient.post('/auth/v1/signout');
|
|
200
|
+
this.clearSession();
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
this.clearSession();
|
|
204
|
+
throw this.handleAuthError(error);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
async getUser() {
|
|
208
|
+
if (!this.currentSession?.access_token) {
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
try {
|
|
212
|
+
const response = await this.httpClient.get('/auth/v1/user');
|
|
213
|
+
return response.data.user;
|
|
214
|
+
}
|
|
215
|
+
catch (error) {
|
|
216
|
+
if (error instanceof EBaaSError && error.status === 401) {
|
|
217
|
+
this.clearSession();
|
|
218
|
+
return null;
|
|
219
|
+
}
|
|
220
|
+
throw this.handleAuthError(error);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
async refreshSession() {
|
|
224
|
+
if (!this.currentSession?.refresh_token) {
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
try {
|
|
228
|
+
const response = await this.httpClient.post('/auth/v1/refresh', {
|
|
229
|
+
refresh_token: this.currentSession.refresh_token
|
|
230
|
+
});
|
|
231
|
+
if (response.data.session) {
|
|
232
|
+
this.setSession(response.data.session);
|
|
233
|
+
return response.data.session;
|
|
234
|
+
}
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
catch (error) {
|
|
238
|
+
this.clearSession();
|
|
239
|
+
throw this.handleAuthError(error);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
async resetPassword(email) {
|
|
243
|
+
try {
|
|
244
|
+
await this.httpClient.post('/auth/v1/reset-password', { email });
|
|
245
|
+
}
|
|
246
|
+
catch (error) {
|
|
247
|
+
throw this.handleAuthError(error);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
async updateUser(data) {
|
|
251
|
+
try {
|
|
252
|
+
const response = await this.httpClient.put('/auth/v1/user', data);
|
|
253
|
+
return response.data.user;
|
|
254
|
+
}
|
|
255
|
+
catch (error) {
|
|
256
|
+
throw this.handleAuthError(error);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
getSession() {
|
|
260
|
+
return this.currentSession;
|
|
261
|
+
}
|
|
262
|
+
setSession(session) {
|
|
263
|
+
this.currentSession = session;
|
|
264
|
+
this.httpClient.setAuthToken(session.access_token);
|
|
265
|
+
// Persist session
|
|
266
|
+
if (typeof localStorage !== 'undefined') {
|
|
267
|
+
localStorage.setItem('ebaas.auth.session', JSON.stringify(session));
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
onAuthStateChange(callback) {
|
|
271
|
+
// Implementation for auth state change listener
|
|
272
|
+
// This would integrate with the actual auth state management system
|
|
273
|
+
return () => { };
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Atualiza o workspace ID (útil quando o usuário troca de workspace)
|
|
277
|
+
*/
|
|
278
|
+
setWorkspaceId(workspaceId) {
|
|
279
|
+
this.workspaceId = workspaceId;
|
|
280
|
+
}
|
|
281
|
+
setSessionInternal(session) {
|
|
282
|
+
this.currentSession = session;
|
|
283
|
+
this.httpClient.setAuthToken(session.access_token);
|
|
284
|
+
// Persist session
|
|
285
|
+
if (typeof localStorage !== 'undefined') {
|
|
286
|
+
localStorage.setItem('ebaas.auth.session', JSON.stringify(session));
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
clearSession() {
|
|
290
|
+
this.currentSession = null;
|
|
291
|
+
this.httpClient.removeAuthToken();
|
|
292
|
+
// Clear persisted session
|
|
293
|
+
if (typeof localStorage !== 'undefined') {
|
|
294
|
+
localStorage.removeItem('ebaas.auth.session');
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
loadSession() {
|
|
298
|
+
if (typeof localStorage !== 'undefined') {
|
|
299
|
+
const storedSession = localStorage.getItem('ebaas.auth.session');
|
|
300
|
+
if (storedSession) {
|
|
301
|
+
try {
|
|
302
|
+
const session = JSON.parse(storedSession);
|
|
303
|
+
this.setSessionInternal(session);
|
|
304
|
+
}
|
|
305
|
+
catch (error) {
|
|
306
|
+
this.clearSession();
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
handleAuthError(error) {
|
|
312
|
+
if (error instanceof EBaaSError) {
|
|
313
|
+
return error;
|
|
314
|
+
}
|
|
315
|
+
return new EBaaSError(error.message || 'Authentication failed', error.status || 0, error);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
class QueryBuilder {
|
|
320
|
+
constructor(httpClient, table, schema, workspaceId, restUrl) {
|
|
321
|
+
this.httpClient = httpClient;
|
|
322
|
+
this.table = table;
|
|
323
|
+
this.schema = schema;
|
|
324
|
+
this.workspaceId = workspaceId;
|
|
325
|
+
this.restUrl = restUrl || '/sdk/v1';
|
|
326
|
+
this.query = {
|
|
327
|
+
filters: []
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
select(columns = '*', options) {
|
|
331
|
+
this.query.select = columns;
|
|
332
|
+
return this;
|
|
333
|
+
}
|
|
334
|
+
insert(data, options) {
|
|
335
|
+
return this.executeQuery('POST', `${this.restUrl}/${this.table}?operation=insert`, { data, options });
|
|
336
|
+
}
|
|
337
|
+
update(data, options) {
|
|
338
|
+
this.query.updateData = data;
|
|
339
|
+
this.query.updateOptions = options;
|
|
340
|
+
return this;
|
|
341
|
+
}
|
|
342
|
+
upsert(data, options) {
|
|
343
|
+
return this.executeQuery('POST', `${this.restUrl}/${this.table}?operation=upsert`, {
|
|
344
|
+
data,
|
|
345
|
+
options: { ...options, upsert: true }
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
delete(options) {
|
|
349
|
+
this.query.deleteOptions = options;
|
|
350
|
+
this.query.isDelete = true;
|
|
351
|
+
return this;
|
|
352
|
+
}
|
|
353
|
+
// Filter methods
|
|
354
|
+
eq(column, value) {
|
|
355
|
+
this.query.filters.push({ column, operator: 'eq', value });
|
|
356
|
+
return this;
|
|
357
|
+
}
|
|
358
|
+
neq(column, value) {
|
|
359
|
+
this.query.filters.push({ column, operator: 'neq', value });
|
|
360
|
+
return this;
|
|
361
|
+
}
|
|
362
|
+
gt(column, value) {
|
|
363
|
+
this.query.filters.push({ column, operator: 'gt', value });
|
|
364
|
+
return this;
|
|
365
|
+
}
|
|
366
|
+
gte(column, value) {
|
|
367
|
+
this.query.filters.push({ column, operator: 'gte', value });
|
|
368
|
+
return this;
|
|
369
|
+
}
|
|
370
|
+
lt(column, value) {
|
|
371
|
+
this.query.filters.push({ column, operator: 'lt', value });
|
|
372
|
+
return this;
|
|
373
|
+
}
|
|
374
|
+
lte(column, value) {
|
|
375
|
+
this.query.filters.push({ column, operator: 'lte', value });
|
|
376
|
+
return this;
|
|
377
|
+
}
|
|
378
|
+
like(column, pattern) {
|
|
379
|
+
this.query.filters.push({ column, operator: 'like', value: pattern });
|
|
380
|
+
return this;
|
|
381
|
+
}
|
|
382
|
+
ilike(column, pattern) {
|
|
383
|
+
this.query.filters.push({ column, operator: 'ilike', value: pattern });
|
|
384
|
+
return this;
|
|
385
|
+
}
|
|
386
|
+
is(column, value) {
|
|
387
|
+
this.query.filters.push({ column, operator: 'is', value });
|
|
388
|
+
return this;
|
|
389
|
+
}
|
|
390
|
+
in(column, values) {
|
|
391
|
+
this.query.filters.push({ column, operator: 'in', value: values });
|
|
392
|
+
return this;
|
|
393
|
+
}
|
|
394
|
+
contains(column, value) {
|
|
395
|
+
this.query.filters.push({ column, operator: 'contains', value });
|
|
396
|
+
return this;
|
|
397
|
+
}
|
|
398
|
+
match(query) {
|
|
399
|
+
Object.entries(query).forEach(([column, value]) => {
|
|
400
|
+
this.eq(column, value);
|
|
401
|
+
});
|
|
402
|
+
return this;
|
|
403
|
+
}
|
|
404
|
+
// Ordering methods
|
|
405
|
+
order(column, options) {
|
|
406
|
+
if (!this.query.order) {
|
|
407
|
+
this.query.order = [];
|
|
408
|
+
}
|
|
409
|
+
this.query.order.push({
|
|
410
|
+
column,
|
|
411
|
+
ascending: options?.ascending !== false
|
|
412
|
+
});
|
|
413
|
+
return this;
|
|
414
|
+
}
|
|
415
|
+
// Limiting methods
|
|
416
|
+
limit(count) {
|
|
417
|
+
this.query.limit = count;
|
|
418
|
+
return this;
|
|
419
|
+
}
|
|
420
|
+
range(from, to) {
|
|
421
|
+
this.query.range = { from, to };
|
|
422
|
+
return this;
|
|
423
|
+
}
|
|
424
|
+
// Execution method for SELECT, UPDATE, or DELETE
|
|
425
|
+
async execute() {
|
|
426
|
+
// Detectar tipo de operação baseado nos dados do query
|
|
427
|
+
if (this.query.updateData) {
|
|
428
|
+
// UPDATE operation
|
|
429
|
+
return this.executeQuery('PATCH', `${this.restUrl}/${this.table}`, {
|
|
430
|
+
data: this.query.updateData,
|
|
431
|
+
options: this.query.updateOptions,
|
|
432
|
+
filters: this.query.filters
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
else if (this.query.isDelete) {
|
|
436
|
+
// DELETE operation
|
|
437
|
+
return this.executeQuery('DELETE', `${this.restUrl}/${this.table}?operation=delete`, {
|
|
438
|
+
options: this.query.deleteOptions,
|
|
439
|
+
filters: this.query.filters
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
else {
|
|
443
|
+
// SELECT operation (default)
|
|
444
|
+
return this.executeQuery('GET', `${this.restUrl}/${this.table}?operation=select`, {
|
|
445
|
+
select: this.query.select,
|
|
446
|
+
filters: this.query.filters,
|
|
447
|
+
order: this.query.order,
|
|
448
|
+
limit: this.query.limit,
|
|
449
|
+
range: this.query.range
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
// Single row execution
|
|
454
|
+
async single() {
|
|
455
|
+
this.limit(1);
|
|
456
|
+
const result = await this.execute();
|
|
457
|
+
return {
|
|
458
|
+
data: result.data?.[0] || null,
|
|
459
|
+
error: result.error,
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
async executeQuery(method, url, payload) {
|
|
463
|
+
try {
|
|
464
|
+
let response;
|
|
465
|
+
// Configurar headers obrigatórios
|
|
466
|
+
const headers = {};
|
|
467
|
+
if (this.workspaceId) {
|
|
468
|
+
headers['x-workspace-id'] = this.workspaceId;
|
|
469
|
+
}
|
|
470
|
+
if (method === 'GET') {
|
|
471
|
+
// Extrair parâmetros existentes da URL (como operation=select)
|
|
472
|
+
const urlParts = url.split('?');
|
|
473
|
+
const baseUrl = urlParts[0];
|
|
474
|
+
const existingParams = new URLSearchParams(urlParts[1] || '');
|
|
475
|
+
// Adicionar novos parâmetros de query
|
|
476
|
+
if (payload.select)
|
|
477
|
+
existingParams.append('select', payload.select);
|
|
478
|
+
// Converter filtros para formato PostgREST
|
|
479
|
+
if (payload.filters?.length) {
|
|
480
|
+
payload.filters.forEach((filter) => {
|
|
481
|
+
existingParams.append(filter.column, `${filter.operator}.${filter.value}`);
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
// Converter ordenação para formato PostgREST
|
|
485
|
+
if (payload.order?.length) {
|
|
486
|
+
const orderStr = payload.order.map((ord) => `${ord.column}${ord.ascending ? '.asc' : '.desc'}`).join(',');
|
|
487
|
+
existingParams.append('order', orderStr);
|
|
488
|
+
}
|
|
489
|
+
if (payload.limit)
|
|
490
|
+
existingParams.append('limit', payload.limit.toString());
|
|
491
|
+
if (payload.range) {
|
|
492
|
+
existingParams.append('offset', payload.range.from.toString());
|
|
493
|
+
existingParams.append('limit', (payload.range.to - payload.range.from + 1).toString());
|
|
494
|
+
}
|
|
495
|
+
response = await this.httpClient.get(`${baseUrl}?${existingParams.toString()}`, { headers });
|
|
496
|
+
}
|
|
497
|
+
else if (method === 'DELETE') {
|
|
498
|
+
// Para DELETE, os filtros devem estar na URL (query string), não no body
|
|
499
|
+
// Extrair parâmetros existentes da URL (como operation=delete)
|
|
500
|
+
const urlParts = url.split('?');
|
|
501
|
+
const baseUrl = urlParts[0];
|
|
502
|
+
const existingParams = new URLSearchParams(urlParts[1] || '');
|
|
503
|
+
// Adicionar parâmetro operation=delete se não estiver presente
|
|
504
|
+
if (!existingParams.has('operation')) {
|
|
505
|
+
existingParams.append('operation', 'delete');
|
|
506
|
+
}
|
|
507
|
+
if (payload.filters?.length) {
|
|
508
|
+
// Converter filtros para formato PostgREST
|
|
509
|
+
payload.filters.forEach((filter) => {
|
|
510
|
+
existingParams.append(filter.column, `${filter.operator}.${filter.value}`);
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
const deleteUrl = `${baseUrl}?${existingParams.toString()}`;
|
|
514
|
+
console.log('🔧 DELETE URL construída:', deleteUrl);
|
|
515
|
+
console.log('🔧 DELETE headers:', headers);
|
|
516
|
+
console.log('🔧 DELETE filtros originais:', payload.filters);
|
|
517
|
+
response = await this.httpClient.delete(deleteUrl, { headers });
|
|
518
|
+
}
|
|
519
|
+
else if (method === 'PATCH') {
|
|
520
|
+
// Para UPDATE (PATCH), os filtros também devem estar na URL
|
|
521
|
+
// Extrair parâmetros existentes da URL (como operation=update)
|
|
522
|
+
const urlParts = url.split('?');
|
|
523
|
+
const baseUrl = urlParts[0];
|
|
524
|
+
const existingParams = new URLSearchParams(urlParts[1] || '');
|
|
525
|
+
// Adicionar parâmetro operation=update se não estiver presente
|
|
526
|
+
if (!existingParams.has('operation')) {
|
|
527
|
+
existingParams.append('operation', 'update');
|
|
528
|
+
}
|
|
529
|
+
if (payload.filters?.length) {
|
|
530
|
+
// Converter filtros para formato PostgREST
|
|
531
|
+
payload.filters.forEach((filter) => {
|
|
532
|
+
existingParams.append(filter.column, `${filter.operator}.${filter.value}`);
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
// Adicionar headers Prefer se necessário
|
|
536
|
+
if (payload.options?.prefer) {
|
|
537
|
+
headers['Prefer'] = payload.options.prefer;
|
|
538
|
+
}
|
|
539
|
+
const updateUrl = `${baseUrl}?${existingParams.toString()}`;
|
|
540
|
+
response = await this.httpClient.patch(updateUrl, payload.data, { headers });
|
|
541
|
+
}
|
|
542
|
+
else {
|
|
543
|
+
// POST mantém o payload no body (para INSERT)
|
|
544
|
+
let postData = payload.data;
|
|
545
|
+
// Sempre retornar dados inseridos por padrão
|
|
546
|
+
if (!headers['Prefer']) {
|
|
547
|
+
headers['Prefer'] = 'return=representation';
|
|
548
|
+
}
|
|
549
|
+
// Se for upsert, adicionar header Prefer
|
|
550
|
+
if (payload.options?.upsert) {
|
|
551
|
+
headers['Prefer'] = 'resolution=merge-duplicates,return=representation';
|
|
552
|
+
}
|
|
553
|
+
// Se for inserção múltipla, usar dataArray
|
|
554
|
+
if (payload.dataArray) {
|
|
555
|
+
postData = payload.dataArray;
|
|
556
|
+
}
|
|
557
|
+
response = await this.httpClient.post(url, postData, { headers });
|
|
558
|
+
}
|
|
559
|
+
return {
|
|
560
|
+
data: response.data,
|
|
561
|
+
error: null,
|
|
562
|
+
count: response.headers?.['x-total-count'] ? parseInt(response.headers['x-total-count']) : undefined
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
catch (error) {
|
|
566
|
+
return {
|
|
567
|
+
data: null,
|
|
568
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Database operation failed', 0, error)
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
class CustomDatabaseManager {
|
|
575
|
+
constructor(httpClient, workspaceId) {
|
|
576
|
+
this.httpClient = httpClient;
|
|
577
|
+
this.workspaceId = workspaceId;
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* Detecta automaticamente se o workspace usa banco customizado
|
|
581
|
+
*/
|
|
582
|
+
async detectCustomDatabase() {
|
|
583
|
+
if (!this.workspaceId) {
|
|
584
|
+
return { hasCustomDatabase: false };
|
|
585
|
+
}
|
|
586
|
+
try {
|
|
587
|
+
// Busca a configuração do workspace
|
|
588
|
+
const response = await this.httpClient.get('/admin/v1/workspace/custom-database', {
|
|
589
|
+
headers: {
|
|
590
|
+
'x-workspace-id': this.workspaceId,
|
|
591
|
+
},
|
|
592
|
+
});
|
|
593
|
+
if (response.status === 200 && response.data?.config) {
|
|
594
|
+
const config = response.data.config;
|
|
595
|
+
// Converte para formato de credenciais do SDK
|
|
596
|
+
const credentials = {
|
|
597
|
+
host: config.postgresHost,
|
|
598
|
+
port: config.postgresPort,
|
|
599
|
+
database: config.postgresDatabase,
|
|
600
|
+
username: config.postgresUsername,
|
|
601
|
+
password: '', // Senha não é retornada pela API por segurança
|
|
602
|
+
schema: config.postgresSchema,
|
|
603
|
+
sslEnabled: config.sslEnabled,
|
|
604
|
+
};
|
|
605
|
+
this.detectedConfig = {
|
|
606
|
+
hasCustomDatabase: true,
|
|
607
|
+
config,
|
|
608
|
+
credentials,
|
|
609
|
+
};
|
|
610
|
+
return this.detectedConfig;
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
catch (error) {
|
|
614
|
+
// Se erro 404, significa que não há configuração customizada
|
|
615
|
+
if (error?.status === 404) {
|
|
616
|
+
this.detectedConfig = { hasCustomDatabase: false };
|
|
617
|
+
return this.detectedConfig;
|
|
618
|
+
}
|
|
619
|
+
console.warn('Failed to detect custom database configuration:', error);
|
|
620
|
+
}
|
|
621
|
+
this.detectedConfig = { hasCustomDatabase: false };
|
|
622
|
+
return this.detectedConfig;
|
|
623
|
+
}
|
|
624
|
+
/**
|
|
625
|
+
* Testa conexão com banco customizado
|
|
626
|
+
*/
|
|
627
|
+
async testConnection(credentials) {
|
|
628
|
+
try {
|
|
629
|
+
const response = await this.httpClient.post('/admin/v1/workspace/custom-database/test-connection', credentials, {
|
|
630
|
+
headers: this.workspaceId ? { 'X-Workspace-ID': this.workspaceId } : {},
|
|
631
|
+
});
|
|
632
|
+
return response.data;
|
|
633
|
+
}
|
|
634
|
+
catch (error) {
|
|
635
|
+
return {
|
|
636
|
+
success: false,
|
|
637
|
+
message: error?.message || 'Failed to test connection',
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
/**
|
|
642
|
+
* Configura credenciais customizadas para o workspace
|
|
643
|
+
*/
|
|
644
|
+
async configureCustomDatabase(credentials) {
|
|
645
|
+
if (!this.workspaceId) {
|
|
646
|
+
throw new Error('Workspace ID is required to configure custom database');
|
|
647
|
+
}
|
|
648
|
+
const response = await this.httpClient.post('/admin/v1/workspace/custom-database', {
|
|
649
|
+
workspaceId: this.workspaceId,
|
|
650
|
+
...credentials,
|
|
651
|
+
}, {
|
|
652
|
+
headers: {
|
|
653
|
+
'X-Workspace-ID': this.workspaceId,
|
|
654
|
+
},
|
|
655
|
+
});
|
|
656
|
+
const config = response.data.config;
|
|
657
|
+
// Atualiza a configuração detectada
|
|
658
|
+
this.detectedConfig = {
|
|
659
|
+
hasCustomDatabase: true,
|
|
660
|
+
config,
|
|
661
|
+
credentials,
|
|
662
|
+
};
|
|
663
|
+
return config;
|
|
664
|
+
}
|
|
665
|
+
/**
|
|
666
|
+
* Remove configuração de banco customizado
|
|
667
|
+
*/
|
|
668
|
+
async removeCustomDatabase() {
|
|
669
|
+
if (!this.workspaceId) {
|
|
670
|
+
throw new Error('Workspace ID is required to remove custom database');
|
|
671
|
+
}
|
|
672
|
+
await this.httpClient.delete('/admin/v1/workspace/custom-database', {
|
|
673
|
+
headers: {
|
|
674
|
+
'X-Workspace-ID': this.workspaceId,
|
|
675
|
+
},
|
|
676
|
+
});
|
|
677
|
+
// Limpa a configuração detectada
|
|
678
|
+
this.detectedConfig = { hasCustomDatabase: false };
|
|
679
|
+
}
|
|
680
|
+
/**
|
|
681
|
+
* Retorna a configuração detectada em cache
|
|
682
|
+
*/
|
|
683
|
+
getDetectedConfig() {
|
|
684
|
+
return this.detectedConfig;
|
|
685
|
+
}
|
|
686
|
+
/**
|
|
687
|
+
* Verifica se tem configuração customizada em cache
|
|
688
|
+
*/
|
|
689
|
+
hasCustomDatabase() {
|
|
690
|
+
return this.detectedConfig?.hasCustomDatabase ?? false;
|
|
691
|
+
}
|
|
692
|
+
/**
|
|
693
|
+
* Retorna as credenciais customizadas se disponíveis
|
|
694
|
+
*/
|
|
695
|
+
getCustomCredentials() {
|
|
696
|
+
return this.detectedConfig?.credentials;
|
|
697
|
+
}
|
|
698
|
+
/**
|
|
699
|
+
* Atualiza o workspace ID
|
|
700
|
+
*/
|
|
701
|
+
setWorkspaceId(workspaceId) {
|
|
702
|
+
this.workspaceId = workspaceId;
|
|
703
|
+
// Limpa configuração anterior quando workspace muda
|
|
704
|
+
this.detectedConfig = undefined;
|
|
705
|
+
}
|
|
706
|
+
/**
|
|
707
|
+
* Retorna o workspace ID atual
|
|
708
|
+
*/
|
|
709
|
+
getWorkspaceId() {
|
|
710
|
+
return this.workspaceId;
|
|
711
|
+
}
|
|
712
|
+
/**
|
|
713
|
+
* Retorna informações sobre o status do banco customizado
|
|
714
|
+
*/
|
|
715
|
+
getStatus() {
|
|
716
|
+
return {
|
|
717
|
+
workspaceId: this.workspaceId,
|
|
718
|
+
hasConfig: this.hasCustomDatabase(),
|
|
719
|
+
configDetails: this.detectedConfig?.credentials ? {
|
|
720
|
+
host: this.detectedConfig.credentials.host,
|
|
721
|
+
port: this.detectedConfig.credentials.port,
|
|
722
|
+
database: this.detectedConfig.credentials.database,
|
|
723
|
+
schema: this.detectedConfig.credentials.schema || 'public',
|
|
724
|
+
sslEnabled: this.detectedConfig.credentials.sslEnabled || false,
|
|
725
|
+
} : undefined,
|
|
726
|
+
};
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
class DatabaseClient {
|
|
731
|
+
constructor(httpClient, workspaceId, restUrl) {
|
|
732
|
+
this.httpClient = httpClient;
|
|
733
|
+
this.customDatabaseManager = new CustomDatabaseManager(httpClient, workspaceId);
|
|
734
|
+
this.restUrl = restUrl || '/sdk/v1';
|
|
735
|
+
}
|
|
736
|
+
from(table) {
|
|
737
|
+
return new QueryBuilder(this.httpClient, table, this.currentSchema, this.customDatabaseManager.getWorkspaceId(), this.restUrl);
|
|
738
|
+
}
|
|
739
|
+
rpc(fn, args) {
|
|
740
|
+
return this.httpClient.post(`/rpc/${fn}`, args);
|
|
741
|
+
}
|
|
742
|
+
schema(schema) {
|
|
743
|
+
const client = new DatabaseClient(this.httpClient, this.customDatabaseManager.getWorkspaceId(), this.restUrl);
|
|
744
|
+
client.currentSchema = schema;
|
|
745
|
+
client.customDatabaseManager = this.customDatabaseManager;
|
|
746
|
+
return client;
|
|
747
|
+
}
|
|
748
|
+
// Métodos para gerenciar banco customizado
|
|
749
|
+
/**
|
|
750
|
+
* Detecta automaticamente se o workspace usa banco customizado
|
|
751
|
+
*/
|
|
752
|
+
async detectCustomDatabase() {
|
|
753
|
+
return this.customDatabaseManager.detectCustomDatabase();
|
|
754
|
+
}
|
|
755
|
+
/**
|
|
756
|
+
* Testa conexão com credenciais customizadas
|
|
757
|
+
*/
|
|
758
|
+
async testCustomConnection(credentials) {
|
|
759
|
+
return this.customDatabaseManager.testConnection(credentials);
|
|
760
|
+
}
|
|
761
|
+
/**
|
|
762
|
+
* Configura banco customizado para o workspace
|
|
763
|
+
*/
|
|
764
|
+
async configureCustomDatabase(credentials) {
|
|
765
|
+
return this.customDatabaseManager.configureCustomDatabase(credentials);
|
|
766
|
+
}
|
|
767
|
+
/**
|
|
768
|
+
* Remove configuração de banco customizado
|
|
769
|
+
*/
|
|
770
|
+
async removeCustomDatabase() {
|
|
771
|
+
return this.customDatabaseManager.removeCustomDatabase();
|
|
772
|
+
}
|
|
773
|
+
/**
|
|
774
|
+
* Verifica se o workspace está usando banco customizado
|
|
775
|
+
*/
|
|
776
|
+
isUsingCustomDatabase() {
|
|
777
|
+
return this.customDatabaseManager.hasCustomDatabase();
|
|
778
|
+
}
|
|
779
|
+
/**
|
|
780
|
+
* Retorna informações sobre o banco customizado
|
|
781
|
+
*/
|
|
782
|
+
getCustomDatabaseStatus() {
|
|
783
|
+
return this.customDatabaseManager.getStatus();
|
|
784
|
+
}
|
|
785
|
+
/**
|
|
786
|
+
* Atualiza o workspace ID (útil quando o usuário troca de workspace)
|
|
787
|
+
*/
|
|
788
|
+
setWorkspaceId(workspaceId) {
|
|
789
|
+
this.customDatabaseManager.setWorkspaceId(workspaceId);
|
|
790
|
+
}
|
|
791
|
+
/**
|
|
792
|
+
* Inicializa a detecção automática do banco customizado
|
|
793
|
+
* Deve ser chamado após a autenticação se autoDetectCustomDatabase estiver habilitado
|
|
794
|
+
*/
|
|
795
|
+
async initialize() {
|
|
796
|
+
try {
|
|
797
|
+
await this.customDatabaseManager.detectCustomDatabase();
|
|
798
|
+
}
|
|
799
|
+
catch (error) {
|
|
800
|
+
console.warn('Failed to initialize custom database detection:', error);
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
class StorageBucket {
|
|
806
|
+
constructor(httpClient, bucketId) {
|
|
807
|
+
this.httpClient = httpClient;
|
|
808
|
+
this.bucketId = bucketId;
|
|
809
|
+
}
|
|
810
|
+
async upload(path, file, options) {
|
|
811
|
+
try {
|
|
812
|
+
const formData = new FormData();
|
|
813
|
+
if (file instanceof File) {
|
|
814
|
+
formData.append('file', file);
|
|
815
|
+
}
|
|
816
|
+
else if (file instanceof Blob) {
|
|
817
|
+
formData.append('file', file, path);
|
|
818
|
+
}
|
|
819
|
+
else if (file instanceof ArrayBuffer) {
|
|
820
|
+
formData.append('file', new Blob([file]), path);
|
|
821
|
+
}
|
|
822
|
+
else if (typeof file === 'string') {
|
|
823
|
+
formData.append('file', new Blob([file], { type: 'text/plain' }), path);
|
|
824
|
+
}
|
|
825
|
+
formData.append('path', path);
|
|
826
|
+
if (options?.cacheControl) {
|
|
827
|
+
formData.append('cacheControl', options.cacheControl);
|
|
828
|
+
}
|
|
829
|
+
if (options?.contentType) {
|
|
830
|
+
formData.append('contentType', options.contentType);
|
|
831
|
+
}
|
|
832
|
+
if (options?.metadata) {
|
|
833
|
+
formData.append('metadata', JSON.stringify(options.metadata));
|
|
834
|
+
}
|
|
835
|
+
const url = `/storage/buckets/${this.bucketId}/files${options?.upsert ? '?upsert=true' : ''}`;
|
|
836
|
+
const response = await this.httpClient.post(url, formData, {
|
|
837
|
+
headers: {
|
|
838
|
+
'Content-Type': 'multipart/form-data'
|
|
839
|
+
}
|
|
840
|
+
});
|
|
841
|
+
return {
|
|
842
|
+
data: response.data,
|
|
843
|
+
error: null
|
|
844
|
+
};
|
|
845
|
+
}
|
|
846
|
+
catch (error) {
|
|
847
|
+
return {
|
|
848
|
+
data: null,
|
|
849
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Failed to upload file', 0, error)
|
|
850
|
+
};
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
async download(path, options) {
|
|
854
|
+
try {
|
|
855
|
+
const params = new URLSearchParams();
|
|
856
|
+
if (options?.transform) {
|
|
857
|
+
Object.entries(options.transform).forEach(([key, value]) => {
|
|
858
|
+
if (value !== undefined) {
|
|
859
|
+
params.append(key, String(value));
|
|
860
|
+
}
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
const url = `/storage/buckets/${this.bucketId}/files/${path}${params.toString() ? `?${params.toString()}` : ''}`;
|
|
864
|
+
const response = await this.httpClient.get(url, {
|
|
865
|
+
responseType: 'blob'
|
|
866
|
+
});
|
|
867
|
+
return {
|
|
868
|
+
data: response.data,
|
|
869
|
+
error: null
|
|
870
|
+
};
|
|
871
|
+
}
|
|
872
|
+
catch (error) {
|
|
873
|
+
return {
|
|
874
|
+
data: null,
|
|
875
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Failed to download file', 0, error)
|
|
876
|
+
};
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
async list(prefix, options) {
|
|
880
|
+
try {
|
|
881
|
+
const params = new URLSearchParams();
|
|
882
|
+
if (prefix) {
|
|
883
|
+
params.append('prefix', prefix);
|
|
884
|
+
}
|
|
885
|
+
if (options?.limit) {
|
|
886
|
+
params.append('limit', String(options.limit));
|
|
887
|
+
}
|
|
888
|
+
if (options?.offset) {
|
|
889
|
+
params.append('offset', String(options.offset));
|
|
890
|
+
}
|
|
891
|
+
if (options?.sortBy) {
|
|
892
|
+
params.append('sortBy', JSON.stringify(options.sortBy));
|
|
893
|
+
}
|
|
894
|
+
if (options?.search) {
|
|
895
|
+
params.append('search', options.search);
|
|
896
|
+
}
|
|
897
|
+
const url = `/storage/buckets/${this.bucketId}/files${params.toString() ? `?${params.toString()}` : ''}`;
|
|
898
|
+
const response = await this.httpClient.get(url);
|
|
899
|
+
return {
|
|
900
|
+
data: response.data,
|
|
901
|
+
error: null
|
|
902
|
+
};
|
|
903
|
+
}
|
|
904
|
+
catch (error) {
|
|
905
|
+
return {
|
|
906
|
+
data: null,
|
|
907
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Failed to list files', 0, error)
|
|
908
|
+
};
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
async remove(paths) {
|
|
912
|
+
try {
|
|
913
|
+
const response = await this.httpClient.delete(`/storage/buckets/${this.bucketId}/files`, {
|
|
914
|
+
data: { paths }
|
|
915
|
+
});
|
|
916
|
+
return {
|
|
917
|
+
data: response.data,
|
|
918
|
+
error: null
|
|
919
|
+
};
|
|
920
|
+
}
|
|
921
|
+
catch (error) {
|
|
922
|
+
return {
|
|
923
|
+
data: null,
|
|
924
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Failed to remove files', 0, error)
|
|
925
|
+
};
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
async move(fromPath, toPath) {
|
|
929
|
+
try {
|
|
930
|
+
const response = await this.httpClient.post(`/storage/buckets/${this.bucketId}/files/move`, {
|
|
931
|
+
sourceKey: fromPath,
|
|
932
|
+
destinationKey: toPath
|
|
933
|
+
});
|
|
934
|
+
return {
|
|
935
|
+
data: response.data,
|
|
936
|
+
error: null
|
|
937
|
+
};
|
|
938
|
+
}
|
|
939
|
+
catch (error) {
|
|
940
|
+
return {
|
|
941
|
+
data: null,
|
|
942
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Failed to move file', 0, error)
|
|
943
|
+
};
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
async copy(fromPath, toPath) {
|
|
947
|
+
try {
|
|
948
|
+
const response = await this.httpClient.post(`/storage/buckets/${this.bucketId}/files/copy`, {
|
|
949
|
+
sourceKey: fromPath,
|
|
950
|
+
destinationKey: toPath
|
|
951
|
+
});
|
|
952
|
+
return {
|
|
953
|
+
data: response.data,
|
|
954
|
+
error: null
|
|
955
|
+
};
|
|
956
|
+
}
|
|
957
|
+
catch (error) {
|
|
958
|
+
return {
|
|
959
|
+
data: null,
|
|
960
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Failed to copy file', 0, error)
|
|
961
|
+
};
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
async createSignedUrl(path, expiresIn, options) {
|
|
965
|
+
try {
|
|
966
|
+
const response = await this.httpClient.post(`/storage/buckets/${this.bucketId}/files/${path}/sign`, {
|
|
967
|
+
expiresIn,
|
|
968
|
+
...options
|
|
969
|
+
});
|
|
970
|
+
return {
|
|
971
|
+
data: response.data,
|
|
972
|
+
error: null
|
|
973
|
+
};
|
|
974
|
+
}
|
|
975
|
+
catch (error) {
|
|
976
|
+
return {
|
|
977
|
+
data: null,
|
|
978
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Failed to create signed URL', 0, error)
|
|
979
|
+
};
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
getPublicUrl(path, options) {
|
|
983
|
+
const params = new URLSearchParams();
|
|
984
|
+
if (options?.transform) {
|
|
985
|
+
Object.entries(options.transform).forEach(([key, value]) => {
|
|
986
|
+
if (value !== undefined) {
|
|
987
|
+
params.append(key, String(value));
|
|
988
|
+
}
|
|
989
|
+
});
|
|
990
|
+
}
|
|
991
|
+
const baseUrl = this.httpClient['baseURL'] || '';
|
|
992
|
+
const publicUrl = `${baseUrl}/storage/buckets/${this.bucketId}/files/${path}${params.toString() ? `?${params.toString()}` : ''}`;
|
|
993
|
+
return {
|
|
994
|
+
data: {
|
|
995
|
+
publicUrl
|
|
996
|
+
}
|
|
997
|
+
};
|
|
998
|
+
}
|
|
999
|
+
async getFileInfo(path) {
|
|
1000
|
+
try {
|
|
1001
|
+
const response = await this.httpClient.get(`/storage/buckets/${this.bucketId}/files/${path}/info`);
|
|
1002
|
+
return {
|
|
1003
|
+
data: response.data,
|
|
1004
|
+
error: null
|
|
1005
|
+
};
|
|
1006
|
+
}
|
|
1007
|
+
catch (error) {
|
|
1008
|
+
return {
|
|
1009
|
+
data: null,
|
|
1010
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Failed to get file info', 0, error)
|
|
1011
|
+
};
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
async updateFileMetadata(path, metadata) {
|
|
1015
|
+
try {
|
|
1016
|
+
const response = await this.httpClient.put(`/storage/buckets/${this.bucketId}/files/${path}/metadata`, {
|
|
1017
|
+
metadata
|
|
1018
|
+
});
|
|
1019
|
+
return {
|
|
1020
|
+
data: response.data,
|
|
1021
|
+
error: null
|
|
1022
|
+
};
|
|
1023
|
+
}
|
|
1024
|
+
catch (error) {
|
|
1025
|
+
return {
|
|
1026
|
+
data: null,
|
|
1027
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Failed to update file metadata', 0, error)
|
|
1028
|
+
};
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
class StorageClient {
|
|
1034
|
+
constructor(httpClient) {
|
|
1035
|
+
this.httpClient = httpClient;
|
|
1036
|
+
}
|
|
1037
|
+
from(bucketId) {
|
|
1038
|
+
return new StorageBucket(this.httpClient, bucketId);
|
|
1039
|
+
}
|
|
1040
|
+
async createBucket(id, options) {
|
|
1041
|
+
try {
|
|
1042
|
+
const response = await this.httpClient.post('/storage/buckets', {
|
|
1043
|
+
id,
|
|
1044
|
+
...options
|
|
1045
|
+
});
|
|
1046
|
+
return {
|
|
1047
|
+
data: response.data,
|
|
1048
|
+
error: null
|
|
1049
|
+
};
|
|
1050
|
+
}
|
|
1051
|
+
catch (error) {
|
|
1052
|
+
return {
|
|
1053
|
+
data: null,
|
|
1054
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Failed to create bucket', 0, error)
|
|
1055
|
+
};
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
async getBucket(id) {
|
|
1059
|
+
try {
|
|
1060
|
+
const response = await this.httpClient.get(`/storage/buckets/${id}`);
|
|
1061
|
+
return {
|
|
1062
|
+
data: response.data,
|
|
1063
|
+
error: null
|
|
1064
|
+
};
|
|
1065
|
+
}
|
|
1066
|
+
catch (error) {
|
|
1067
|
+
return {
|
|
1068
|
+
data: null,
|
|
1069
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Failed to get bucket', 0, error)
|
|
1070
|
+
};
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
async listBuckets() {
|
|
1074
|
+
try {
|
|
1075
|
+
const response = await this.httpClient.get('/storage/buckets');
|
|
1076
|
+
return {
|
|
1077
|
+
data: response.data,
|
|
1078
|
+
error: null
|
|
1079
|
+
};
|
|
1080
|
+
}
|
|
1081
|
+
catch (error) {
|
|
1082
|
+
return {
|
|
1083
|
+
data: null,
|
|
1084
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Failed to list buckets', 0, error)
|
|
1085
|
+
};
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
async updateBucket(id, options) {
|
|
1089
|
+
try {
|
|
1090
|
+
const response = await this.httpClient.put(`/storage/buckets/${id}`, options);
|
|
1091
|
+
return {
|
|
1092
|
+
data: response.data,
|
|
1093
|
+
error: null
|
|
1094
|
+
};
|
|
1095
|
+
}
|
|
1096
|
+
catch (error) {
|
|
1097
|
+
return {
|
|
1098
|
+
data: null,
|
|
1099
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Failed to update bucket', 0, error)
|
|
1100
|
+
};
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
async deleteBucket(id) {
|
|
1104
|
+
try {
|
|
1105
|
+
const response = await this.httpClient.delete(`/storage/buckets/${id}`);
|
|
1106
|
+
return {
|
|
1107
|
+
data: response.data,
|
|
1108
|
+
error: null
|
|
1109
|
+
};
|
|
1110
|
+
}
|
|
1111
|
+
catch (error) {
|
|
1112
|
+
return {
|
|
1113
|
+
data: null,
|
|
1114
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Failed to delete bucket', 0, error)
|
|
1115
|
+
};
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
async getUsage() {
|
|
1119
|
+
try {
|
|
1120
|
+
const response = await this.httpClient.get('/storage/usage');
|
|
1121
|
+
return {
|
|
1122
|
+
data: response.data,
|
|
1123
|
+
error: null
|
|
1124
|
+
};
|
|
1125
|
+
}
|
|
1126
|
+
catch (error) {
|
|
1127
|
+
return {
|
|
1128
|
+
data: null,
|
|
1129
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Failed to get storage usage', 0, error)
|
|
1130
|
+
};
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
class EventManager {
|
|
1136
|
+
constructor() {
|
|
1137
|
+
this.events = new Map();
|
|
1138
|
+
this.maxListeners = 10;
|
|
1139
|
+
}
|
|
1140
|
+
on(event, callback) {
|
|
1141
|
+
if (!this.events.has(event)) {
|
|
1142
|
+
this.events.set(event, new Set());
|
|
1143
|
+
}
|
|
1144
|
+
this.events.get(event).add(callback);
|
|
1145
|
+
}
|
|
1146
|
+
off(event, callback) {
|
|
1147
|
+
if (!this.events.has(event))
|
|
1148
|
+
return;
|
|
1149
|
+
const eventCallbacks = this.events.get(event);
|
|
1150
|
+
if (callback) {
|
|
1151
|
+
eventCallbacks.delete(callback);
|
|
1152
|
+
}
|
|
1153
|
+
else {
|
|
1154
|
+
eventCallbacks.clear();
|
|
1155
|
+
}
|
|
1156
|
+
if (eventCallbacks.size === 0) {
|
|
1157
|
+
this.events.delete(event);
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
emit(event, ...args) {
|
|
1161
|
+
if (!this.events.has(event))
|
|
1162
|
+
return false;
|
|
1163
|
+
const eventCallbacks = this.events.get(event);
|
|
1164
|
+
for (const callback of eventCallbacks) {
|
|
1165
|
+
try {
|
|
1166
|
+
callback(...args);
|
|
1167
|
+
}
|
|
1168
|
+
catch (error) {
|
|
1169
|
+
console.error(`Error in event listener for "${event}":`, error);
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
return eventCallbacks.size > 0;
|
|
1173
|
+
}
|
|
1174
|
+
removeAllListeners(event) {
|
|
1175
|
+
if (event) {
|
|
1176
|
+
this.events.delete(event);
|
|
1177
|
+
}
|
|
1178
|
+
else {
|
|
1179
|
+
this.events.clear();
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
listenerCount(event) {
|
|
1183
|
+
return this.events.get(event)?.size ?? 0;
|
|
1184
|
+
}
|
|
1185
|
+
eventNames() {
|
|
1186
|
+
return Array.from(this.events.keys());
|
|
1187
|
+
}
|
|
1188
|
+
listeners(event) {
|
|
1189
|
+
return Array.from(this.events.get(event) ?? []);
|
|
1190
|
+
}
|
|
1191
|
+
addListener(event, callback) {
|
|
1192
|
+
this.on(event, callback);
|
|
1193
|
+
}
|
|
1194
|
+
removeListener(event, callback) {
|
|
1195
|
+
this.off(event, callback);
|
|
1196
|
+
}
|
|
1197
|
+
once(event, callback) {
|
|
1198
|
+
const onceWrapper = (...args) => {
|
|
1199
|
+
this.off(event, onceWrapper);
|
|
1200
|
+
callback(...args);
|
|
1201
|
+
};
|
|
1202
|
+
this.on(event, onceWrapper);
|
|
1203
|
+
}
|
|
1204
|
+
prependListener(event, callback) {
|
|
1205
|
+
this.on(event, callback);
|
|
1206
|
+
}
|
|
1207
|
+
prependOnceListener(event, callback) {
|
|
1208
|
+
const onceWrapper = (...args) => {
|
|
1209
|
+
this.off(event, onceWrapper);
|
|
1210
|
+
callback(...args);
|
|
1211
|
+
};
|
|
1212
|
+
this.on(event, onceWrapper);
|
|
1213
|
+
}
|
|
1214
|
+
setMaxListeners(max) {
|
|
1215
|
+
this.maxListeners = max;
|
|
1216
|
+
return this;
|
|
1217
|
+
}
|
|
1218
|
+
getMaxListeners() {
|
|
1219
|
+
return this.maxListeners;
|
|
1220
|
+
}
|
|
1221
|
+
rawListeners(event) {
|
|
1222
|
+
return this.listeners(event);
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1226
|
+
class RealtimeChannel extends EventManager {
|
|
1227
|
+
constructor(topic, socket) {
|
|
1228
|
+
super();
|
|
1229
|
+
this.joinedOnce = false;
|
|
1230
|
+
this.state = 'closed';
|
|
1231
|
+
this.subscriptions = new Map();
|
|
1232
|
+
this.topic = topic;
|
|
1233
|
+
this.socket = socket;
|
|
1234
|
+
}
|
|
1235
|
+
subscribe(callback) {
|
|
1236
|
+
if (!this.joinedOnce) {
|
|
1237
|
+
this.joinedOnce = true;
|
|
1238
|
+
this._join();
|
|
1239
|
+
}
|
|
1240
|
+
if (callback) {
|
|
1241
|
+
this.on('status', callback);
|
|
1242
|
+
}
|
|
1243
|
+
return this;
|
|
1244
|
+
}
|
|
1245
|
+
onPostgresChanges(filter, callback) {
|
|
1246
|
+
const eventKey = `postgres_changes:${JSON.stringify(filter)}`;
|
|
1247
|
+
this.on(eventKey, callback);
|
|
1248
|
+
const subscription = {
|
|
1249
|
+
unsubscribe: () => {
|
|
1250
|
+
this.off(eventKey, callback);
|
|
1251
|
+
this.subscriptions.delete(eventKey);
|
|
1252
|
+
}
|
|
1253
|
+
};
|
|
1254
|
+
this.subscriptions.set(eventKey, subscription);
|
|
1255
|
+
if (this.socket?.connected && this.state === 'joined') {
|
|
1256
|
+
this.socket.emit('subscribe_postgres_changes', {
|
|
1257
|
+
topic: this.topic,
|
|
1258
|
+
filter,
|
|
1259
|
+
ref: this.makeRef()
|
|
1260
|
+
});
|
|
1261
|
+
}
|
|
1262
|
+
return subscription;
|
|
1263
|
+
}
|
|
1264
|
+
onBroadcast(filter, callback) {
|
|
1265
|
+
const eventKey = `broadcast:${JSON.stringify(filter)}`;
|
|
1266
|
+
this.on(eventKey, callback);
|
|
1267
|
+
const subscription = {
|
|
1268
|
+
unsubscribe: () => {
|
|
1269
|
+
this.off(eventKey, callback);
|
|
1270
|
+
this.subscriptions.delete(eventKey);
|
|
1271
|
+
}
|
|
1272
|
+
};
|
|
1273
|
+
this.subscriptions.set(eventKey, subscription);
|
|
1274
|
+
return subscription;
|
|
1275
|
+
}
|
|
1276
|
+
onPresence(filter, callback) {
|
|
1277
|
+
const eventKey = `presence:${JSON.stringify(filter)}`;
|
|
1278
|
+
this.on(eventKey, callback);
|
|
1279
|
+
const subscription = {
|
|
1280
|
+
unsubscribe: () => {
|
|
1281
|
+
this.off(eventKey, callback);
|
|
1282
|
+
this.subscriptions.delete(eventKey);
|
|
1283
|
+
}
|
|
1284
|
+
};
|
|
1285
|
+
this.subscriptions.set(eventKey, subscription);
|
|
1286
|
+
return subscription;
|
|
1287
|
+
}
|
|
1288
|
+
send(payload) {
|
|
1289
|
+
return new Promise((resolve) => {
|
|
1290
|
+
if (this.socket?.connected && this.state === 'joined') {
|
|
1291
|
+
this.socket.emit('broadcast', {
|
|
1292
|
+
topic: this.topic,
|
|
1293
|
+
event: payload.event,
|
|
1294
|
+
payload: payload,
|
|
1295
|
+
ref: this.makeRef()
|
|
1296
|
+
});
|
|
1297
|
+
resolve('ok');
|
|
1298
|
+
}
|
|
1299
|
+
else {
|
|
1300
|
+
resolve('error');
|
|
1301
|
+
}
|
|
1302
|
+
});
|
|
1303
|
+
}
|
|
1304
|
+
track(payload) {
|
|
1305
|
+
return new Promise((resolve) => {
|
|
1306
|
+
if (this.socket?.connected && this.state === 'joined') {
|
|
1307
|
+
this.socket.emit('presence', {
|
|
1308
|
+
topic: this.topic,
|
|
1309
|
+
event: 'track',
|
|
1310
|
+
payload: payload,
|
|
1311
|
+
ref: this.makeRef()
|
|
1312
|
+
});
|
|
1313
|
+
resolve('ok');
|
|
1314
|
+
}
|
|
1315
|
+
else {
|
|
1316
|
+
resolve('error');
|
|
1317
|
+
}
|
|
1318
|
+
});
|
|
1319
|
+
}
|
|
1320
|
+
untrack() {
|
|
1321
|
+
return new Promise((resolve) => {
|
|
1322
|
+
if (this.socket?.connected && this.state === 'joined') {
|
|
1323
|
+
this.socket.emit('presence', {
|
|
1324
|
+
topic: this.topic,
|
|
1325
|
+
event: 'untrack',
|
|
1326
|
+
ref: this.makeRef()
|
|
1327
|
+
});
|
|
1328
|
+
resolve('ok');
|
|
1329
|
+
}
|
|
1330
|
+
else {
|
|
1331
|
+
resolve('error');
|
|
1332
|
+
}
|
|
1333
|
+
});
|
|
1334
|
+
}
|
|
1335
|
+
unsubscribe() {
|
|
1336
|
+
return new Promise((resolve) => {
|
|
1337
|
+
this.state = 'leaving';
|
|
1338
|
+
this.subscriptions.forEach(subscription => {
|
|
1339
|
+
subscription.unsubscribe();
|
|
1340
|
+
});
|
|
1341
|
+
this.subscriptions.clear();
|
|
1342
|
+
if (this.socket?.connected) {
|
|
1343
|
+
this.socket.emit('leave', {
|
|
1344
|
+
topic: this.topic,
|
|
1345
|
+
ref: this.makeRef()
|
|
1346
|
+
});
|
|
1347
|
+
}
|
|
1348
|
+
this.state = 'closed';
|
|
1349
|
+
this.removeAllListeners();
|
|
1350
|
+
resolve('ok');
|
|
1351
|
+
});
|
|
1352
|
+
}
|
|
1353
|
+
_join() {
|
|
1354
|
+
if (this.state === 'leaving')
|
|
1355
|
+
return;
|
|
1356
|
+
this.state = 'joining';
|
|
1357
|
+
if (this.socket?.connected) {
|
|
1358
|
+
this.socket.emit('join', {
|
|
1359
|
+
topic: this.topic,
|
|
1360
|
+
ref: this.makeRef()
|
|
1361
|
+
});
|
|
1362
|
+
setTimeout(() => {
|
|
1363
|
+
if (this.state === 'joining') {
|
|
1364
|
+
this.state = 'joined';
|
|
1365
|
+
this.emit('status', 'SUBSCRIBED');
|
|
1366
|
+
}
|
|
1367
|
+
}, 100);
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
_rejoin() {
|
|
1371
|
+
if (this.joinedOnce) {
|
|
1372
|
+
this._join();
|
|
1373
|
+
this.subscriptions.forEach((_subscription, eventKey) => {
|
|
1374
|
+
if (eventKey.startsWith('postgres_changes:')) {
|
|
1375
|
+
const filter = JSON.parse(eventKey.replace('postgres_changes:', ''));
|
|
1376
|
+
this.socket?.emit('subscribe_postgres_changes', {
|
|
1377
|
+
topic: this.topic,
|
|
1378
|
+
filter,
|
|
1379
|
+
ref: this.makeRef()
|
|
1380
|
+
});
|
|
1381
|
+
}
|
|
1382
|
+
});
|
|
1383
|
+
}
|
|
1384
|
+
}
|
|
1385
|
+
_trigger(event, payload) {
|
|
1386
|
+
if (event === 'postgres_changes') {
|
|
1387
|
+
const eventKey = `postgres_changes:${JSON.stringify(payload.filter || {})}`;
|
|
1388
|
+
this.emit(eventKey, payload);
|
|
1389
|
+
}
|
|
1390
|
+
else if (event === 'broadcast') {
|
|
1391
|
+
const eventKey = `broadcast:${JSON.stringify({ event: payload.event })}`;
|
|
1392
|
+
this.emit(eventKey, payload);
|
|
1393
|
+
}
|
|
1394
|
+
else if (event === 'presence') {
|
|
1395
|
+
const eventKey = `presence:${JSON.stringify({ event: payload.event })}`;
|
|
1396
|
+
this.emit(eventKey, payload);
|
|
1397
|
+
}
|
|
1398
|
+
this.emit(event, payload);
|
|
1399
|
+
}
|
|
1400
|
+
_setState(state) {
|
|
1401
|
+
this.state = state;
|
|
1402
|
+
let status;
|
|
1403
|
+
switch (state) {
|
|
1404
|
+
case 'joined':
|
|
1405
|
+
status = 'SUBSCRIBED';
|
|
1406
|
+
break;
|
|
1407
|
+
case 'errored':
|
|
1408
|
+
status = 'CHANNEL_ERROR';
|
|
1409
|
+
break;
|
|
1410
|
+
case 'closed':
|
|
1411
|
+
status = 'CLOSED';
|
|
1412
|
+
break;
|
|
1413
|
+
default:
|
|
1414
|
+
return;
|
|
1415
|
+
}
|
|
1416
|
+
this.emit('status', status);
|
|
1417
|
+
}
|
|
1418
|
+
makeRef() {
|
|
1419
|
+
return Math.random().toString(36).substring(2, 15);
|
|
1420
|
+
}
|
|
1421
|
+
getState() {
|
|
1422
|
+
return this.state;
|
|
1423
|
+
}
|
|
1424
|
+
}
|
|
1425
|
+
|
|
1426
|
+
function getEnvironment() {
|
|
1427
|
+
if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
|
|
1428
|
+
return 'react-native';
|
|
1429
|
+
}
|
|
1430
|
+
if (typeof window !== 'undefined' && typeof document !== 'undefined') {
|
|
1431
|
+
return 'browser';
|
|
1432
|
+
}
|
|
1433
|
+
if (typeof global !== 'undefined' && typeof process !== 'undefined' && process.versions?.node) {
|
|
1434
|
+
return 'node';
|
|
1435
|
+
}
|
|
1436
|
+
return 'browser';
|
|
1437
|
+
}
|
|
1438
|
+
function isSocketIOAvailable() {
|
|
1439
|
+
try {
|
|
1440
|
+
const env = getEnvironment();
|
|
1441
|
+
switch (env) {
|
|
1442
|
+
case 'node':
|
|
1443
|
+
return typeof require !== 'undefined' && require.resolve && !!require.resolve('socket.io-client');
|
|
1444
|
+
case 'browser':
|
|
1445
|
+
if (typeof globalThis !== 'undefined' && 'io' in globalThis) {
|
|
1446
|
+
return true;
|
|
1447
|
+
}
|
|
1448
|
+
return typeof require !== 'undefined' && require.resolve && !!require.resolve('socket.io-client');
|
|
1449
|
+
case 'react-native':
|
|
1450
|
+
try {
|
|
1451
|
+
return typeof require !== 'undefined' && !!require('socket.io-client');
|
|
1452
|
+
}
|
|
1453
|
+
catch {
|
|
1454
|
+
return false;
|
|
1455
|
+
}
|
|
1456
|
+
default:
|
|
1457
|
+
return false;
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
catch {
|
|
1461
|
+
return false;
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
function getSocketIO() {
|
|
1465
|
+
try {
|
|
1466
|
+
if (typeof require !== 'undefined') {
|
|
1467
|
+
return require('socket.io-client');
|
|
1468
|
+
}
|
|
1469
|
+
if (typeof globalThis !== 'undefined' && 'io' in globalThis) {
|
|
1470
|
+
return { io: globalThis.io };
|
|
1471
|
+
}
|
|
1472
|
+
throw new Error('socket.io-client not available');
|
|
1473
|
+
}
|
|
1474
|
+
catch (error) {
|
|
1475
|
+
throw new Error(`Socket.io-client não está disponível neste ambiente. Para usar funcionalidades de realtime, instale: npm install socket.io-client`);
|
|
1476
|
+
}
|
|
1477
|
+
}
|
|
1478
|
+
class WebSocketAdapter {
|
|
1479
|
+
constructor() {
|
|
1480
|
+
this.socket = null;
|
|
1481
|
+
}
|
|
1482
|
+
async connect(url, options) {
|
|
1483
|
+
if (!isSocketIOAvailable()) {
|
|
1484
|
+
throw new Error('Socket.io-client não está disponível. Para usar funcionalidades de realtime, instale: npm install socket.io-client');
|
|
1485
|
+
}
|
|
1486
|
+
const { io } = getSocketIO();
|
|
1487
|
+
return new Promise((resolve, reject) => {
|
|
1488
|
+
this.socket = io(url, options);
|
|
1489
|
+
this.socket.on('connect', () => resolve());
|
|
1490
|
+
this.socket.on('connect_error', (error) => reject(error));
|
|
1491
|
+
});
|
|
1492
|
+
}
|
|
1493
|
+
disconnect() {
|
|
1494
|
+
if (this.socket) {
|
|
1495
|
+
this.socket.disconnect();
|
|
1496
|
+
this.socket = null;
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
emit(event, data) {
|
|
1500
|
+
this.socket?.emit(event, data);
|
|
1501
|
+
}
|
|
1502
|
+
on(event, callback) {
|
|
1503
|
+
this.socket?.on(event, callback);
|
|
1504
|
+
}
|
|
1505
|
+
off(event, callback) {
|
|
1506
|
+
if (callback) {
|
|
1507
|
+
this.socket?.off(event, callback);
|
|
1508
|
+
}
|
|
1509
|
+
else {
|
|
1510
|
+
this.socket?.off(event);
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1513
|
+
get connected() {
|
|
1514
|
+
return this.socket?.connected ?? false;
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1517
|
+
class ReactNativeSocketAdapter {
|
|
1518
|
+
constructor() {
|
|
1519
|
+
this.socket = null;
|
|
1520
|
+
}
|
|
1521
|
+
async connect(url, options) {
|
|
1522
|
+
if (!isSocketIOAvailable()) {
|
|
1523
|
+
throw new Error('Socket.io-client não está disponível. Para React Native, instale: npm install socket.io-client');
|
|
1524
|
+
}
|
|
1525
|
+
const { io } = getSocketIO();
|
|
1526
|
+
return new Promise((resolve, reject) => {
|
|
1527
|
+
this.socket = io(url, {
|
|
1528
|
+
...options,
|
|
1529
|
+
transports: ['websocket'],
|
|
1530
|
+
upgrade: false,
|
|
1531
|
+
autoConnect: true,
|
|
1532
|
+
});
|
|
1533
|
+
this.socket.on('connect', () => resolve());
|
|
1534
|
+
this.socket.on('connect_error', (error) => reject(error));
|
|
1535
|
+
});
|
|
1536
|
+
}
|
|
1537
|
+
disconnect() {
|
|
1538
|
+
if (this.socket) {
|
|
1539
|
+
this.socket.disconnect();
|
|
1540
|
+
this.socket = null;
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
emit(event, data) {
|
|
1544
|
+
this.socket?.emit(event, data);
|
|
1545
|
+
}
|
|
1546
|
+
on(event, callback) {
|
|
1547
|
+
this.socket?.on(event, callback);
|
|
1548
|
+
}
|
|
1549
|
+
off(event, callback) {
|
|
1550
|
+
if (callback) {
|
|
1551
|
+
this.socket?.off(event, callback);
|
|
1552
|
+
}
|
|
1553
|
+
else {
|
|
1554
|
+
this.socket?.off(event);
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1557
|
+
get connected() {
|
|
1558
|
+
return this.socket?.connected ?? false;
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
function createSocketAdapter() {
|
|
1562
|
+
const env = getEnvironment();
|
|
1563
|
+
switch (env) {
|
|
1564
|
+
case 'react-native':
|
|
1565
|
+
return new ReactNativeSocketAdapter();
|
|
1566
|
+
case 'browser':
|
|
1567
|
+
case 'node':
|
|
1568
|
+
default:
|
|
1569
|
+
return new WebSocketAdapter();
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1572
|
+
|
|
1573
|
+
class RealtimeClient {
|
|
1574
|
+
constructor(url, apiKey, options = {}) {
|
|
1575
|
+
this.socket = null;
|
|
1576
|
+
this.channels = new Map();
|
|
1577
|
+
this.connectionState = 'disconnected';
|
|
1578
|
+
this.reconnectAttempts = 0;
|
|
1579
|
+
this.maxReconnectAttempts = 5;
|
|
1580
|
+
this.url = url;
|
|
1581
|
+
this.apiKey = apiKey;
|
|
1582
|
+
this.options = {
|
|
1583
|
+
heartbeatInterval: 30000,
|
|
1584
|
+
reconnectInterval: 5000,
|
|
1585
|
+
maxReconnectAttempts: 5,
|
|
1586
|
+
...options
|
|
1587
|
+
};
|
|
1588
|
+
this.socketAdapter = createSocketAdapter();
|
|
1589
|
+
}
|
|
1590
|
+
connect() {
|
|
1591
|
+
return new Promise(async (resolve, reject) => {
|
|
1592
|
+
if (this.socketAdapter.connected) {
|
|
1593
|
+
resolve();
|
|
1594
|
+
return;
|
|
1595
|
+
}
|
|
1596
|
+
this.connectionState = 'connecting';
|
|
1597
|
+
try {
|
|
1598
|
+
await this.socketAdapter.connect(this.url, {
|
|
1599
|
+
auth: {
|
|
1600
|
+
apikey: this.apiKey
|
|
1601
|
+
},
|
|
1602
|
+
transports: ['websocket'],
|
|
1603
|
+
reconnection: true,
|
|
1604
|
+
reconnectionDelay: this.options.reconnectInterval,
|
|
1605
|
+
reconnectionAttempts: this.options.maxReconnectAttempts,
|
|
1606
|
+
...this.options.socketOptions
|
|
1607
|
+
});
|
|
1608
|
+
this.socket = this.socketAdapter.socket;
|
|
1609
|
+
this.socketAdapter.on('connect', () => {
|
|
1610
|
+
this.connectionState = 'connected';
|
|
1611
|
+
this.reconnectAttempts = 0;
|
|
1612
|
+
this.setupHeartbeat();
|
|
1613
|
+
resolve();
|
|
1614
|
+
});
|
|
1615
|
+
this.socketAdapter.on('disconnect', () => {
|
|
1616
|
+
this.connectionState = 'disconnected';
|
|
1617
|
+
this.channels.forEach(channel => {
|
|
1618
|
+
channel._setState('closed');
|
|
1619
|
+
});
|
|
1620
|
+
});
|
|
1621
|
+
this.socketAdapter.on('connect_error', (error) => {
|
|
1622
|
+
this.connectionState = 'error';
|
|
1623
|
+
this.reconnectAttempts++;
|
|
1624
|
+
if (this.reconnectAttempts >= this.maxReconnectAttempts) {
|
|
1625
|
+
reject(new Error(`Failed to connect after ${this.maxReconnectAttempts} attempts: ${error.message}`));
|
|
1626
|
+
}
|
|
1627
|
+
});
|
|
1628
|
+
this.socketAdapter.on('reconnect', () => {
|
|
1629
|
+
this.connectionState = 'connected';
|
|
1630
|
+
this.reconnectAttempts = 0;
|
|
1631
|
+
this.channels.forEach(channel => {
|
|
1632
|
+
channel._rejoin();
|
|
1633
|
+
});
|
|
1634
|
+
});
|
|
1635
|
+
this.socketAdapter.on('postgres_changes', (payload) => {
|
|
1636
|
+
const channel = this.channels.get(payload.topic);
|
|
1637
|
+
if (channel) {
|
|
1638
|
+
channel._trigger('postgres_changes', payload);
|
|
1639
|
+
}
|
|
1640
|
+
});
|
|
1641
|
+
this.socketAdapter.on('broadcast', (payload) => {
|
|
1642
|
+
const channel = this.channels.get(payload.topic);
|
|
1643
|
+
if (channel) {
|
|
1644
|
+
channel._trigger('broadcast', payload);
|
|
1645
|
+
}
|
|
1646
|
+
});
|
|
1647
|
+
this.socketAdapter.on('presence', (payload) => {
|
|
1648
|
+
const channel = this.channels.get(payload.topic);
|
|
1649
|
+
if (channel) {
|
|
1650
|
+
channel._trigger('presence', payload);
|
|
1651
|
+
}
|
|
1652
|
+
});
|
|
1653
|
+
}
|
|
1654
|
+
catch (error) {
|
|
1655
|
+
this.connectionState = 'error';
|
|
1656
|
+
reject(error);
|
|
1657
|
+
}
|
|
1658
|
+
});
|
|
1659
|
+
}
|
|
1660
|
+
disconnect() {
|
|
1661
|
+
if (this.socketAdapter) {
|
|
1662
|
+
this.socketAdapter.disconnect();
|
|
1663
|
+
this.socket = null;
|
|
1664
|
+
}
|
|
1665
|
+
this.connectionState = 'disconnected';
|
|
1666
|
+
this.channels.clear();
|
|
1667
|
+
}
|
|
1668
|
+
channel(topic) {
|
|
1669
|
+
if (this.channels.has(topic)) {
|
|
1670
|
+
return this.channels.get(topic);
|
|
1671
|
+
}
|
|
1672
|
+
const channel = new RealtimeChannel(topic, this.socket);
|
|
1673
|
+
this.channels.set(topic, channel);
|
|
1674
|
+
if (this.connectionState === 'connected') {
|
|
1675
|
+
channel._join();
|
|
1676
|
+
}
|
|
1677
|
+
return channel;
|
|
1678
|
+
}
|
|
1679
|
+
removeChannel(channel) {
|
|
1680
|
+
const topic = channel.topic;
|
|
1681
|
+
if (this.channels.has(topic)) {
|
|
1682
|
+
this.channels.delete(topic);
|
|
1683
|
+
channel.unsubscribe();
|
|
1684
|
+
}
|
|
1685
|
+
}
|
|
1686
|
+
removeAllChannels() {
|
|
1687
|
+
this.channels.forEach(channel => {
|
|
1688
|
+
channel.unsubscribe();
|
|
1689
|
+
});
|
|
1690
|
+
this.channels.clear();
|
|
1691
|
+
}
|
|
1692
|
+
getChannels() {
|
|
1693
|
+
return Array.from(this.channels.values());
|
|
1694
|
+
}
|
|
1695
|
+
isConnected() {
|
|
1696
|
+
return this.connectionState === 'connected' && this.socketAdapter.connected;
|
|
1697
|
+
}
|
|
1698
|
+
getConnectionState() {
|
|
1699
|
+
return this.connectionState;
|
|
1700
|
+
}
|
|
1701
|
+
onConnectionStateChange(callback) {
|
|
1702
|
+
const handler = () => callback(this.connectionState);
|
|
1703
|
+
if (this.socketAdapter) {
|
|
1704
|
+
this.socketAdapter.on('connect', () => {
|
|
1705
|
+
this.connectionState = 'connected';
|
|
1706
|
+
handler();
|
|
1707
|
+
});
|
|
1708
|
+
this.socketAdapter.on('disconnect', () => {
|
|
1709
|
+
this.connectionState = 'disconnected';
|
|
1710
|
+
handler();
|
|
1711
|
+
});
|
|
1712
|
+
this.socketAdapter.on('connect_error', () => {
|
|
1713
|
+
this.connectionState = 'error';
|
|
1714
|
+
handler();
|
|
1715
|
+
});
|
|
1716
|
+
}
|
|
1717
|
+
return () => {
|
|
1718
|
+
if (this.socketAdapter) {
|
|
1719
|
+
this.socketAdapter.off('connect', handler);
|
|
1720
|
+
this.socketAdapter.off('disconnect', handler);
|
|
1721
|
+
this.socketAdapter.off('connect_error', handler);
|
|
1722
|
+
}
|
|
1723
|
+
};
|
|
1724
|
+
}
|
|
1725
|
+
setupHeartbeat() {
|
|
1726
|
+
if (!this.options.heartbeatInterval || !this.socketAdapter)
|
|
1727
|
+
return;
|
|
1728
|
+
const interval = setInterval(() => {
|
|
1729
|
+
if (this.socketAdapter?.connected) {
|
|
1730
|
+
this.socketAdapter.emit('heartbeat', { timestamp: Date.now() });
|
|
1731
|
+
}
|
|
1732
|
+
else {
|
|
1733
|
+
clearInterval(interval);
|
|
1734
|
+
}
|
|
1735
|
+
}, this.options.heartbeatInterval);
|
|
1736
|
+
}
|
|
1737
|
+
_getSocket() {
|
|
1738
|
+
return this.socket;
|
|
1739
|
+
}
|
|
1740
|
+
}
|
|
1741
|
+
|
|
1742
|
+
class FunctionsClient {
|
|
1743
|
+
constructor(httpClient) {
|
|
1744
|
+
this.httpClient = httpClient;
|
|
1745
|
+
}
|
|
1746
|
+
async invoke(functionName, options) {
|
|
1747
|
+
try {
|
|
1748
|
+
const method = options?.method || 'POST';
|
|
1749
|
+
const headers = {
|
|
1750
|
+
'Content-Type': 'application/json',
|
|
1751
|
+
...options?.headers
|
|
1752
|
+
};
|
|
1753
|
+
let response;
|
|
1754
|
+
const url = `/functions/v1/${functionName}`;
|
|
1755
|
+
switch (method.toUpperCase()) {
|
|
1756
|
+
case 'GET':
|
|
1757
|
+
response = await this.httpClient.get(url, {
|
|
1758
|
+
headers,
|
|
1759
|
+
params: options?.body
|
|
1760
|
+
});
|
|
1761
|
+
break;
|
|
1762
|
+
case 'POST':
|
|
1763
|
+
response = await this.httpClient.post(url, options?.body, { headers });
|
|
1764
|
+
break;
|
|
1765
|
+
case 'PUT':
|
|
1766
|
+
response = await this.httpClient.put(url, options?.body, { headers });
|
|
1767
|
+
break;
|
|
1768
|
+
case 'PATCH':
|
|
1769
|
+
response = await this.httpClient.patch(url, options?.body, { headers });
|
|
1770
|
+
break;
|
|
1771
|
+
case 'DELETE':
|
|
1772
|
+
response = await this.httpClient.delete(url, {
|
|
1773
|
+
headers,
|
|
1774
|
+
data: options?.body
|
|
1775
|
+
});
|
|
1776
|
+
break;
|
|
1777
|
+
default:
|
|
1778
|
+
throw new EBaaSError(`Unsupported HTTP method: ${method}`, 400);
|
|
1779
|
+
}
|
|
1780
|
+
return {
|
|
1781
|
+
data: response.data,
|
|
1782
|
+
error: null
|
|
1783
|
+
};
|
|
1784
|
+
}
|
|
1785
|
+
catch (error) {
|
|
1786
|
+
return {
|
|
1787
|
+
data: null,
|
|
1788
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Function invocation failed', 0, error)
|
|
1789
|
+
};
|
|
1790
|
+
}
|
|
1791
|
+
}
|
|
1792
|
+
async list() {
|
|
1793
|
+
try {
|
|
1794
|
+
const response = await this.httpClient.get('/functions/v1');
|
|
1795
|
+
return {
|
|
1796
|
+
data: response.data,
|
|
1797
|
+
error: null
|
|
1798
|
+
};
|
|
1799
|
+
}
|
|
1800
|
+
catch (error) {
|
|
1801
|
+
return {
|
|
1802
|
+
data: null,
|
|
1803
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Failed to list functions', 0, error)
|
|
1804
|
+
};
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
async get(functionName) {
|
|
1808
|
+
try {
|
|
1809
|
+
const response = await this.httpClient.get(`/functions/v1/${functionName}/info`);
|
|
1810
|
+
return {
|
|
1811
|
+
data: response.data,
|
|
1812
|
+
error: null
|
|
1813
|
+
};
|
|
1814
|
+
}
|
|
1815
|
+
catch (error) {
|
|
1816
|
+
return {
|
|
1817
|
+
data: null,
|
|
1818
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Failed to get function', 0, error)
|
|
1819
|
+
};
|
|
1820
|
+
}
|
|
1821
|
+
}
|
|
1822
|
+
async deploy(functionName, options) {
|
|
1823
|
+
try {
|
|
1824
|
+
const formData = new FormData();
|
|
1825
|
+
if (options.code instanceof File) {
|
|
1826
|
+
formData.append('code', options.code);
|
|
1827
|
+
}
|
|
1828
|
+
else if (typeof options.code === 'string') {
|
|
1829
|
+
formData.append('code', new Blob([options.code], { type: 'text/plain' }), 'index.ts');
|
|
1830
|
+
}
|
|
1831
|
+
if (options.entrypoint) {
|
|
1832
|
+
formData.append('entrypoint', options.entrypoint);
|
|
1833
|
+
}
|
|
1834
|
+
if (options.env) {
|
|
1835
|
+
formData.append('env', JSON.stringify(options.env));
|
|
1836
|
+
}
|
|
1837
|
+
if (options.importMap) {
|
|
1838
|
+
formData.append('importMap', JSON.stringify(options.importMap));
|
|
1839
|
+
}
|
|
1840
|
+
if (options.verify !== undefined) {
|
|
1841
|
+
formData.append('verify', String(options.verify));
|
|
1842
|
+
}
|
|
1843
|
+
const response = await this.httpClient.post(`/functions/v1/${functionName}/deploy`, formData, {
|
|
1844
|
+
headers: {
|
|
1845
|
+
'Content-Type': 'multipart/form-data'
|
|
1846
|
+
}
|
|
1847
|
+
});
|
|
1848
|
+
return {
|
|
1849
|
+
data: response.data,
|
|
1850
|
+
error: null
|
|
1851
|
+
};
|
|
1852
|
+
}
|
|
1853
|
+
catch (error) {
|
|
1854
|
+
return {
|
|
1855
|
+
data: null,
|
|
1856
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Failed to deploy function', 0, error)
|
|
1857
|
+
};
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
async delete(functionName) {
|
|
1861
|
+
try {
|
|
1862
|
+
const response = await this.httpClient.delete(`/functions/v1/${functionName}`);
|
|
1863
|
+
return {
|
|
1864
|
+
data: response.data,
|
|
1865
|
+
error: null
|
|
1866
|
+
};
|
|
1867
|
+
}
|
|
1868
|
+
catch (error) {
|
|
1869
|
+
return {
|
|
1870
|
+
data: null,
|
|
1871
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Failed to delete function', 0, error)
|
|
1872
|
+
};
|
|
1873
|
+
}
|
|
1874
|
+
}
|
|
1875
|
+
async updateEnv(functionName, env) {
|
|
1876
|
+
try {
|
|
1877
|
+
const response = await this.httpClient.put(`/functions/v1/${functionName}/env`, { env });
|
|
1878
|
+
return {
|
|
1879
|
+
data: response.data,
|
|
1880
|
+
error: null
|
|
1881
|
+
};
|
|
1882
|
+
}
|
|
1883
|
+
catch (error) {
|
|
1884
|
+
return {
|
|
1885
|
+
data: null,
|
|
1886
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Failed to update function environment', 0, error)
|
|
1887
|
+
};
|
|
1888
|
+
}
|
|
1889
|
+
}
|
|
1890
|
+
async getLogs(functionName, options) {
|
|
1891
|
+
try {
|
|
1892
|
+
const params = new URLSearchParams();
|
|
1893
|
+
if (options?.limit) {
|
|
1894
|
+
params.append('limit', String(options.limit));
|
|
1895
|
+
}
|
|
1896
|
+
if (options?.offset) {
|
|
1897
|
+
params.append('offset', String(options.offset));
|
|
1898
|
+
}
|
|
1899
|
+
if (options?.level) {
|
|
1900
|
+
params.append('level', options.level);
|
|
1901
|
+
}
|
|
1902
|
+
const url = `/functions/v1/${functionName}/logs${params.toString() ? `?${params.toString()}` : ''}`;
|
|
1903
|
+
const response = await this.httpClient.get(url);
|
|
1904
|
+
return {
|
|
1905
|
+
data: response.data,
|
|
1906
|
+
error: null
|
|
1907
|
+
};
|
|
1908
|
+
}
|
|
1909
|
+
catch (error) {
|
|
1910
|
+
return {
|
|
1911
|
+
data: null,
|
|
1912
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Failed to get function logs', 0, error)
|
|
1913
|
+
};
|
|
1914
|
+
}
|
|
1915
|
+
}
|
|
1916
|
+
async getMetrics(functionName, options) {
|
|
1917
|
+
try {
|
|
1918
|
+
const params = new URLSearchParams();
|
|
1919
|
+
if (options?.period) {
|
|
1920
|
+
params.append('period', options.period);
|
|
1921
|
+
}
|
|
1922
|
+
const url = `/functions/v1/${functionName}/metrics${params.toString() ? `?${params.toString()}` : ''}`;
|
|
1923
|
+
const response = await this.httpClient.get(url);
|
|
1924
|
+
return {
|
|
1925
|
+
data: response.data,
|
|
1926
|
+
error: null
|
|
1927
|
+
};
|
|
1928
|
+
}
|
|
1929
|
+
catch (error) {
|
|
1930
|
+
return {
|
|
1931
|
+
data: null,
|
|
1932
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Failed to get function metrics', 0, error)
|
|
1933
|
+
};
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
}
|
|
1937
|
+
|
|
1938
|
+
class EBaaSClient {
|
|
1939
|
+
constructor(supabaseUrl, supabaseKey, options) {
|
|
1940
|
+
this.options = options;
|
|
1941
|
+
// Initialize HTTP client
|
|
1942
|
+
this.httpClient = new HttpClient({
|
|
1943
|
+
url: supabaseUrl,
|
|
1944
|
+
apiKey: supabaseKey,
|
|
1945
|
+
timeout: 30000,
|
|
1946
|
+
headers: options?.global?.headers
|
|
1947
|
+
});
|
|
1948
|
+
// Initialize all modules
|
|
1949
|
+
this.auth = new AuthClient(this.httpClient, options?.database?.workspaceId);
|
|
1950
|
+
this.database = new DatabaseClient(this.httpClient, options?.database?.workspaceId, options?.rest?.url);
|
|
1951
|
+
this.storage = new StorageClient(this.httpClient);
|
|
1952
|
+
this.realtime = new RealtimeClient(supabaseUrl, supabaseKey, options?.realtime);
|
|
1953
|
+
this.functions = new FunctionsClient(this.httpClient);
|
|
1954
|
+
// Initialize custom database detection if enabled
|
|
1955
|
+
this.initializeCustomDatabase();
|
|
1956
|
+
}
|
|
1957
|
+
// Convenience method for database access
|
|
1958
|
+
from(table) {
|
|
1959
|
+
return this.database.from(table);
|
|
1960
|
+
}
|
|
1961
|
+
// Convenience method for RPC calls
|
|
1962
|
+
rpc(fn, args) {
|
|
1963
|
+
return this.database.rpc(fn, args);
|
|
1964
|
+
}
|
|
1965
|
+
// Convenience method for storage bucket access
|
|
1966
|
+
bucket(id) {
|
|
1967
|
+
return this.storage.from(id);
|
|
1968
|
+
}
|
|
1969
|
+
// Convenience method for realtime channel access
|
|
1970
|
+
channel(name) {
|
|
1971
|
+
return this.realtime.channel(name);
|
|
1972
|
+
}
|
|
1973
|
+
// Convenience method for edge functions
|
|
1974
|
+
invoke(functionName, options) {
|
|
1975
|
+
return this.functions.invoke(functionName, options);
|
|
1976
|
+
}
|
|
1977
|
+
/**
|
|
1978
|
+
* Inicializa a detecção automática de banco customizado
|
|
1979
|
+
*/
|
|
1980
|
+
async initializeCustomDatabase() {
|
|
1981
|
+
if (this.options?.database?.autoDetectCustomDatabase) {
|
|
1982
|
+
try {
|
|
1983
|
+
await this.database.initialize();
|
|
1984
|
+
}
|
|
1985
|
+
catch (error) {
|
|
1986
|
+
console.warn('Failed to initialize custom database detection:', error);
|
|
1987
|
+
}
|
|
1988
|
+
}
|
|
1989
|
+
}
|
|
1990
|
+
/**
|
|
1991
|
+
* Atualiza o workspace ID para todos os módulos que precisam
|
|
1992
|
+
*/
|
|
1993
|
+
async setWorkspaceId(workspaceId) {
|
|
1994
|
+
this.auth.setWorkspaceId(workspaceId);
|
|
1995
|
+
this.database.setWorkspaceId(workspaceId);
|
|
1996
|
+
// Se auto-detecção estiver habilitada, re-detecta configuração para o novo workspace
|
|
1997
|
+
if (this.options?.database?.autoDetectCustomDatabase) {
|
|
1998
|
+
await this.database.initialize();
|
|
1999
|
+
}
|
|
2000
|
+
}
|
|
2001
|
+
/**
|
|
2002
|
+
* Configura credenciais customizadas diretamente
|
|
2003
|
+
*/
|
|
2004
|
+
async configureCustomDatabase(credentials) {
|
|
2005
|
+
await this.database.configureCustomDatabase(credentials);
|
|
2006
|
+
}
|
|
2007
|
+
/**
|
|
2008
|
+
* Retorna informações sobre o banco customizado
|
|
2009
|
+
*/
|
|
2010
|
+
getCustomDatabaseStatus() {
|
|
2011
|
+
return this.database.getCustomDatabaseStatus();
|
|
2012
|
+
}
|
|
2013
|
+
}
|
|
2014
|
+
// Factory function similar to Supabase's createClient
|
|
2015
|
+
function createClient(supabaseUrl, supabaseKey, options) {
|
|
2016
|
+
return new EBaaSClient(supabaseUrl, supabaseKey, options);
|
|
2017
|
+
}
|
|
2018
|
+
|
|
2019
|
+
// Main client export
|
|
2020
|
+
// Version
|
|
2021
|
+
const version = "1.1.8";
|
|
2022
|
+
|
|
2023
|
+
exports.AuthClient = AuthClient;
|
|
2024
|
+
exports.CustomDatabaseManager = CustomDatabaseManager;
|
|
2025
|
+
exports.DatabaseClient = DatabaseClient;
|
|
2026
|
+
exports.EBaaSClient = EBaaSClient;
|
|
2027
|
+
exports.EBaaSError = EBaaSError;
|
|
2028
|
+
exports.FunctionsClient = FunctionsClient;
|
|
2029
|
+
exports.HttpClient = HttpClient;
|
|
2030
|
+
exports.QueryBuilder = QueryBuilder;
|
|
2031
|
+
exports.RealtimeChannel = RealtimeChannel;
|
|
2032
|
+
exports.RealtimeClient = RealtimeClient;
|
|
2033
|
+
exports.StorageBucket = StorageBucket;
|
|
2034
|
+
exports.StorageClient = StorageClient;
|
|
2035
|
+
exports.createClient = createClient;
|
|
2036
|
+
exports.version = version;
|
|
2037
|
+
//# sourceMappingURL=index.cjs.map
|