@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.esm.js
CHANGED
|
@@ -1 +1,2022 @@
|
|
|
1
|
-
(function(stringArrayFunction,comparisonValue){const stringArray=stringArrayFunction();function _0x27fc1b(_0x13daec,_0x545080){return _0x46d3(_0x13daec-0x309,_0x545080);}while(!![]){try{const _0x7a8ed8=-parseInt(_0x27fc1b(0x482,0x446))/0x1+parseInt(_0x27fc1b(0x55d,0x5cf))/0x2*(-parseInt(_0x27fc1b(0x466,0x40c))/0x3)+-parseInt(_0x27fc1b(0x51c,0x589))/0x4+parseInt(_0x27fc1b(0x49e,0x50c))/0x5*(-parseInt(_0x27fc1b(0x4d7,0x507))/0x6)+-parseInt(_0x27fc1b(0x54a,0x54a))/0x7*(parseInt(_0x27fc1b(0x4b2,0x50a))/0x8)+parseInt(_0x27fc1b(0x4b1,0x4b7))/0x9+parseInt(_0x27fc1b(0x478,0x3f1))/0xa;if(_0x7a8ed8===comparisonValue)break;else stringArray['push'](stringArray['shift']());}catch(_0x498775){stringArray['push'](stringArray['shift']());}}}(_0x1ed3,0xb4896));import axios from'axios';function _0x46d3(_0x4b98e2,_0x4220ff){const _0x1ed34a=_0x1ed3();return _0x46d3=function(_0x46d366,_0x5a555f){_0x46d366=_0x46d366-0x14d;let _0x9f5936=_0x1ed34a[_0x46d366];if(_0x46d3['SWDoWb']===undefined){var _0x3a3327=function(_0x46e9df){const _0x2b9a15='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0xd92010='',_0x39eb4e='';for(let _0x13b141=0x0,_0x49db59,_0x423aab,_0x1427ae=0x0;_0x423aab=_0x46e9df['charAt'](_0x1427ae++);~_0x423aab&&(_0x49db59=_0x13b141%0x4?_0x49db59*0x40+_0x423aab:_0x423aab,_0x13b141++%0x4)?_0xd92010+=String['fromCharCode'](0xff&_0x49db59>>(-0x2*_0x13b141&0x6)):0x0){_0x423aab=_0x2b9a15['indexOf'](_0x423aab);}for(let _0x4942ab=0x0,_0x24a908=_0xd92010['length'];_0x4942ab<_0x24a908;_0x4942ab++){_0x39eb4e+='%'+('00'+_0xd92010['charCodeAt'](_0x4942ab)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x39eb4e);};_0x46d3['IfoNgL']=_0x3a3327,_0x4b98e2=arguments,_0x46d3['SWDoWb']=!![];}const _0x3320aa=_0x1ed34a[0x0],_0x52b71f=_0x46d366+_0x3320aa,_0x5cd24b=_0x4b98e2[_0x52b71f];return!_0x5cd24b?(_0x9f5936=_0x46d3['IfoNgL'](_0x9f5936),_0x4b98e2[_0x52b71f]=_0x9f5936):_0x9f5936=_0x5cd24b,_0x9f5936;},_0x46d3(_0x4b98e2,_0x4220ff);}class EBaaSError extends Error{constructor(_0x46e9df,status=0x0,_0x2b9a15){super(_0x46e9df),this['name']='EBaaSError';function _0x2c88e2(_0x3af8ab,_0x5a60a0){return _0x46d3(_0x5a60a0-0x1b1,_0x3af8ab);}this[_0x2c88e2(0x358,0x309)]=status,this[_0x2c88e2(0x437,0x408)]=_0x2b9a15,Error['captureStackTrace']&&Error['captureStackTrace'](this,EBaaSError);}['toJSON'](){function _0x413905(_0x111034,_0x168b04){return _0x46d3(_0x111034- -0x143,_0x168b04);}return{'name':this[_0x413905(0x1b,0x9d)],'message':this['message'],'status':this[_0x413905(0x15,0x6e)],'details':this[_0x413905(0x114,0x96)],'stack':this[_0x413905(0x120,0x132)]};}[_0x294921(-0xa,-0x21)](){function _0x18650d(_0xc0e78d,_0x41d469){return _0x46d3(_0xc0e78d- -0x2f9,_0x41d469);}return this['name']+':\x20'+this['message']+_0x18650d(-0x134,-0xc7)+this['status']+')';}}class HttpClient{constructor(config){this['baseURL']=config[_0x19c64a(0x28a,0x2a7)],this[_0x19c64a(0x38d,0x35e)]=config[_0x19c64a(0x37d,0x35e)];function _0x19c64a(_0x17e5d4,_0x3eaad4){return _0x46d3(_0x3eaad4-0x151,_0x17e5d4);}this['client']=axios[_0x19c64a(0x3b6,0x39a)]({'baseURL':this['baseURL'],'timeout':config[_0x19c64a(0x33c,0x32b)]||0x2710,'headers':{'Content-Type':'application/json','apikey':this['apiKey'],...config['headers']}}),this[_0x19c64a(0x315,0x321)]();}[_0x294921(-0x4d,0x22)](){this['client']['interceptors']['request']['use'](config=>{return config;},_0xd92010=>{function _0xa174ec(_0x49b344,_0x455f87){return _0x46d3(_0x455f87- -0x2a5,_0x49b344);}return Promise[_0xa174ec(-0xa4,-0xe9)](new EBaaSError('Request\x20failed',0x0,_0xd92010));});function _0x30e2e3(_0x5df2b2,_0xc56c7f){return _0x46d3(_0x5df2b2- -0x3a7,_0xc56c7f);}this[_0x30e2e3(-0x1d4,-0x19c)]['interceptors']['response'][_0x30e2e3(-0x1de,-0x221)](response=>{return response;},_0x39eb4e=>{const status=_0x39eb4e[_0x45db50(0x19a,0x1e8)]?.['status']||0x0,_0x13b141=_0x39eb4e['response']?.['data']?.['message']||_0x39eb4e[_0x45db50(0x286,0x258)]||'Unknown\x20error',_0x49db59=_0x39eb4e['response']?.[_0x45db50(0x17a,0x1bd)]||_0x39eb4e;function _0x45db50(_0xf60450,_0x182318){return _0x46d3(_0x182318- -0x4,_0xf60450);}return Promise['reject'](new EBaaSError(_0x13b141,status,_0x49db59));});}async['get'](_0x423aab,config){function _0xce36d1(_0x51cb18,_0x19e0a7){return _0x46d3(_0x51cb18- -0xe3,_0x19e0a7);}try{const response=await this['client'][_0xce36d1(0x14c,0x169)](_0x423aab,config);return{'data':response[_0xce36d1(0xde,0x140)],'status':response[_0xce36d1(0x75,0xfd)],'statusText':response['statusText'],'headers':response['headers']};}catch(_0x1427ae){throw this['handleError'](_0x1427ae);}}async[_0x294921(-0x4f,-0x3d)](_0x4942ab,data,config){function _0x66bb5d(_0x10f6bf,_0x2edba4){return _0x46d3(_0x10f6bf- -0x229,_0x2edba4);}try{const response=await this[_0x66bb5d(-0x56,-0xba)]['post'](_0x4942ab,data,config);return{'data':response[_0x66bb5d(-0x68,-0x3e)],'status':response[_0x66bb5d(-0xd1,-0x14b)],'statusText':response[_0x66bb5d(-0x28,0xf)],'headers':response['headers']};}catch(_0x24a908){throw this[_0x66bb5d(-0x7a,-0x40)](_0x24a908);}}async[_0x294921(-0x33,-0x4e)](_0x5d9fc9,data,config){function _0x36b4eb(_0x39d0ec,_0x56bace){return _0x46d3(_0x56bace-0xaf,_0x39d0ec);}try{const response=await this[_0x36b4eb(0x27a,0x282)]['put'](_0x5d9fc9,data,config);return{'data':response[_0x36b4eb(0x287,0x270)],'status':response['status'],'statusText':response['statusText'],'headers':response['headers']};}catch(_0x51f9e5){throw this['handleError'](_0x51f9e5);}}async['patch'](_0x4b61cc,data,config){function _0x398b73(_0x5018d5,_0x8d6328){return _0x46d3(_0x5018d5- -0x301,_0x8d6328);}try{const response=await this['client']['patch'](_0x4b61cc,data,config);return{'data':response['data'],'status':response[_0x398b73(-0x1a9,-0x1e3)],'statusText':response[_0x398b73(-0x100,-0x8a)],'headers':response[_0x398b73(-0x1a7,-0x155)]};}catch(_0x6a438){throw this[_0x398b73(-0x152,-0x1c0)](_0x6a438);}}async[_0x294921(0x4b,-0x2a)](_0x24db05,config){function _0x1f0122(_0x54aa37,_0x2d3539){return _0x46d3(_0x2d3539- -0x37f,_0x54aa37);}try{const response=await this[_0x1f0122(-0x1a3,-0x1ac)][_0x1f0122(-0x179,-0x1fb)](_0x24db05,config);return{'data':response['data'],'status':response['status'],'statusText':response['statusText'],'headers':response[_0x1f0122(-0x279,-0x225)]};}catch(_0x55eace){throw this['handleError'](_0x55eace);}}[_0x294921(0x19,0x89)](_0x1fe112){function _0x888845(_0x4973db,_0x487777){return _0x46d3(_0x4973db-0x326,_0x487777);}this[_0x888845(0x4f9,0x48b)][_0x888845(0x56b,0x57a)][_0x888845(0x480,0x400)]['common']['Authorization']=_0x888845(0x4a9,0x502)+_0x1fe112;}[_0x294921(0x70,0x21)](){function _0x28d1c4(_0x221b8e,_0x2b9991){return _0x46d3(_0x2b9991- -0x13d,_0x221b8e);}delete this[_0x28d1c4(0x70,0x96)][_0x28d1c4(0xd9,0x108)]['headers'][_0x28d1c4(0x193,0x10b)]['Authorization'],this['client']['defaults'][_0x28d1c4(0x1f,0x1d)]['common']['Authorization']='Bearer\x20'+this[_0x28d1c4(0x12c,0xd0)];}['handleError'](_0x123f33){if(_0x123f33 instanceof EBaaSError)return _0x123f33;function _0x52f111(_0x15d296,_0x1f4e8e){return _0x46d3(_0x15d296-0x35c,_0x1f4e8e);}return new EBaaSError(_0x123f33[_0x52f111(0x5b8,0x52e)]||'HTTP\x20request\x20failed',_0x123f33[_0x52f111(0x4b4,0x464)]||0x0,_0x123f33);}}class AuthClient{constructor(_0x3454ed,_0x196b50){function _0x3795f6(_0x45ea0e,_0x377424){return _0x46d3(_0x377424-0x2b4,_0x45ea0e);}this['currentSession']=null,this[_0x3795f6(0x40e,0x467)]=_0x3454ed,this[_0x3795f6(0x44c,0x474)]=_0x196b50,this['loadSession']();}async['signUp'](data){function _0x507409(_0xcf53f4,_0xa77c86){return _0x46d3(_0xcf53f4-0x258,_0xa77c86);}try{const response=await this['httpClient'][_0x507409(0x3c9,0x455)]('/auth/v1/signup',data);return response[_0x507409(0x419,0x444)]['session']&&this['setSessionInternal'](response['data']['session']),response[_0x507409(0x419,0x4a3)];}catch(_0x51a8f7){throw this['handleAuthError'](_0x51a8f7);}}async[_0x294921(0x3a,0x55)](data){function _0x27137c(_0x583e22,_0x1e2cd1){return _0x46d3(_0x583e22- -0x313,_0x1e2cd1);}try{const headers={};this['workspaceId']&&(headers['X-Workspace-ID']=this['workspaceId']);const response=await this['httpClient']['post']('/auth/v1/sdk/signin',data,{'headers':headers});return response['data']['session']&&this[_0x27137c(-0x1b8,-0x133)](response['data']['session']),response[_0x27137c(-0x152,-0x174)];}catch(_0x45f9c3){throw this[_0x27137c(-0x10c,-0x13a)](_0x45f9c3);}}async['signOut'](){function _0x462eae(_0x258661,_0x1f2ad1){return _0x46d3(_0x1f2ad1-0x193,_0x258661);}try{await this['httpClient']['post']('/auth/v1/signout'),this[_0x462eae(0x3af,0x3d9)]();}catch(_0x2ca483){this[_0x462eae(0x36c,0x3d9)]();throw this['handleAuthError'](_0x2ca483);}}async[_0x294921(0x111,0xaa)](){if(!this[_0x43654b(0x352,0x34b)]?.['access_token'])return null;function _0x43654b(_0x1d5af1,_0x3d80cc){return _0x46d3(_0x3d80cc-0x1fc,_0x1d5af1);}try{const response=await this[_0x43654b(0x331,0x3af)]['get'](_0x43654b(0x426,0x39d));return response['data'][_0x43654b(0x42c,0x443)];}catch(_0x586832){if(_0x586832 instanceof EBaaSError&&_0x586832['status']===0x191)return this['clearSession'](),null;throw this[_0x43654b(0x41e,0x403)](_0x586832);}}async['refreshSession'](){function _0x39d02e(_0x53596,_0x58dc3d){return _0x46d3(_0x53596-0x2d4,_0x58dc3d);}if(!this['currentSession']?.[_0x39d02e(0x4ad,0x495)])return null;try{const response=await this['httpClient'][_0x39d02e(0x445,0x47b)]('/auth/v1/refresh',{'refresh_token':this[_0x39d02e(0x423,0x435)]['refresh_token']});if(response[_0x39d02e(0x495,0x49a)][_0x39d02e(0x4eb,0x4e2)])return this[_0x39d02e(0x4f7,0x580)](response[_0x39d02e(0x495,0x495)][_0x39d02e(0x4eb,0x517)]),response['data']['session'];return null;}catch(_0x5f1238){this[_0x39d02e(0x51a,0x592)]();throw this['handleAuthError'](_0x5f1238);}}async[_0x294921(0x23,0xaf)](_0x398042){function _0x546d19(_0x572d9e,_0x45d955){return _0x46d3(_0x572d9e- -0x365,_0x45d955);}try{await this['httpClient'][_0x546d19(-0x1f4,-0x1b0)](_0x546d19(-0x178,-0x140),{'email':_0x398042});}catch(_0x48860b){throw this['handleAuthError'](_0x48860b);}}async[_0x294921(0x18,0x50)](data){function _0x240698(_0x2c3616,_0x3bf6b1){return _0x46d3(_0x2c3616-0x1a0,_0x3bf6b1);}try{const response=await this['httpClient']['put']('/auth/v1/user',data);return response[_0x240698(0x361,0x3a2)]['user'];}catch(_0xfbdf38){throw this['handleAuthError'](_0xfbdf38);}}['getSession'](){function _0x316303(_0x5d6767,_0x26f4c7){return _0x46d3(_0x5d6767-0x2c,_0x26f4c7);}return this[_0x316303(0x17b,0x114)];}[_0x294921(0x68,0x75)](_0x58055b){this['currentSession']=_0x58055b,this['httpClient']['setAuthToken'](_0x58055b['access_token']);function _0x3f60e2(_0x127185,_0x399bcd){return _0x46d3(_0x127185-0x3b0,_0x399bcd);}typeof localStorage!==_0x3f60e2(0x582,0x5b6)&&localStorage[_0x3f60e2(0x572,0x54b)]('ebaas.auth.session',JSON['stringify'](_0x58055b));}[_0x294921(-0xa5,-0x2e)](_0x3aea47){return()=>{};}[_0x294921(0xa,-0x27)](_0x5c9cf5){function _0x3a2721(_0x2e8db3,_0x32c2a4){return _0x46d3(_0x32c2a4-0x213,_0x2e8db3);}this[_0x3a2721(0x399,0x3d3)]=_0x5c9cf5;}[_0x294921(-0x27,-0x53)](_0x11b980){function _0x396711(_0x360952,_0x4a2752){return _0x46d3(_0x4a2752- -0x384,_0x360952);}this[_0x396711(-0x1ab,-0x235)]=_0x11b980,this[_0x396711(-0x16a,-0x1d1)]['setAuthToken'](_0x11b980['access_token']),typeof localStorage!==_0x396711(-0x203,-0x1b2)&&localStorage['setItem'](_0x396711(-0x12f,-0x154),JSON[_0x396711(-0x262,-0x228)](_0x11b980));}[_0x294921(0x88,0x98)](){this[_0x1fd3bc(0xff,0xd6)]=null,this['httpClient'][_0x1fd3bc(0x1ac,0x156)]();function _0x1fd3bc(_0x3c81f8,_0x5cef3c){return _0x46d3(_0x5cef3c- -0x79,_0x3c81f8);}typeof localStorage!==_0x1fd3bc(0x18f,0x159)&&localStorage[_0x1fd3bc(0xaa,0x111)]('ebaas.auth.session');}['loadSession'](){function _0xd6881d(_0x91fdb2,_0x5ded93){return _0x46d3(_0x91fdb2- -0x121,_0x5ded93);}if(typeof localStorage!==_0xd6881d(0xb1,0x82)){const _0xf8e11f=localStorage['getItem']('ebaas.auth.session');if(_0xf8e11f)try{const _0x372407=JSON['parse'](_0xf8e11f);this[_0xd6881d(0x3a,0x7e)](_0x372407);}catch(_0x25b0b0){this[_0xd6881d(0x125,0xcc)]();}}}[_0x294921(0x6c,0x59)](_0x439fd6){if(_0x439fd6 instanceof EBaaSError)return _0x439fd6;return new EBaaSError(_0x439fd6['message']||'Authentication\x20failed',_0x439fd6['status']||0x0,_0x439fd6);}}class QueryBuilder{constructor(_0x4c616a,_0x2b18d3,_0x151c20,_0x461a59,_0x1e978c){this['httpClient']=_0x4c616a,this['table']=_0x2b18d3,this[_0x10f673(0x314,0x32e)]=_0x151c20,this['workspaceId']=_0x461a59;function _0x10f673(_0x36e538,_0x1b7206){return _0x46d3(_0x36e538-0xdc,_0x1b7206);}this[_0x10f673(0x24e,0x27d)]=_0x1e978c||'/sdk/v1',this[_0x10f673(0x2ed,0x2fc)]={'filters':[]};}[_0x294921(-0x44,-0x14)](_0x27c7d3='*',_0xa54851){function _0x537377(_0x54d9f9,_0x363a20){return _0x46d3(_0x363a20-0x6e,_0x54d9f9);}return this[_0x537377(0x2e5,0x27f)]['select']=_0x27c7d3,this;}[_0x294921(0x76,0x2)](data,_0x39fd46){function _0x4c376e(_0x30bfab,_0x14ee73){return _0x46d3(_0x30bfab-0x29c,_0x14ee73);}return this['executeQuery']('POST',this['restUrl']+'/'+this[_0x4c376e(0x498,0x461)]+_0x4c376e(0x453,0x429),{'data':data,'options':_0x39fd46});}[_0x294921(0x50,0x11)](data,_0x3e993c){this['query'][_0x30192b(-0x151,-0x196)]=data,this[_0x30192b(-0x18d,-0x1ec)]['updateOptions']=_0x3e993c;function _0x30192b(_0x107e1e,_0x6c451f){return _0x46d3(_0x107e1e- -0x39e,_0x6c451f);}return this;}['upsert'](data,_0x161097){function _0x4b0fe3(_0x14daeb,_0xbf18a5){return _0x46d3(_0xbf18a5-0x188,_0x14daeb);}return this[_0x4b0fe3(0x349,0x3c2)]('POST',this['restUrl']+'/'+this[_0x4b0fe3(0x3b0,0x384)]+_0x4b0fe3(0x355,0x38d),{'data':data,'options':{..._0x161097,'upsert':!![]}});}[_0x294921(0x38,-0x2a)](_0x245f16){function _0x2b9412(_0x2f7119,_0x3cee9a){return _0x46d3(_0x3cee9a- -0x21f,_0x2f7119);}return this[_0x2b9412(0x7e,-0xe)][_0x2b9412(-0x106,-0x87)]=_0x245f16,this['query'][_0x2b9412(-0x1a,-0x49)]=!![],this;}['eq'](_0x4024a0,_0x5422f5){this[_0x205e16(0x3c,-0x34)]['filters']['push']({'column':_0x4024a0,'operator':'eq','value':_0x5422f5});function _0x205e16(_0x56c20d,_0x182315){return _0x46d3(_0x56c20d- -0x1d5,_0x182315);}return this;}['neq'](_0x20b8e1,_0x4bb2bc){this[_0x4a8459(0x36c,0x383)][_0x4a8459(0x3d7,0x38b)][_0x4a8459(0x398,0x336)]({'column':_0x20b8e1,'operator':'neq','value':_0x4bb2bc});function _0x4a8459(_0x59d5d4,_0x4efd15){return _0x46d3(_0x4efd15-0x172,_0x59d5d4);}return this;}['gt'](_0x3c4032,_0x494e9f){this['query']['filters'][_0xbf7d3d(0x52d,0x58c)]({'column':_0x3c4032,'operator':'gt','value':_0x494e9f});function _0xbf7d3d(_0x4f7ad8,_0x14bdac){return _0x46d3(_0x14bdac-0x3c8,_0x4f7ad8);}return this;}[_0x294921(0xbf,0x7a)](_0x249400,_0x21a002){function _0x4dc382(_0x166111,_0x4af1fb){return _0x46d3(_0x166111- -0x1e5,_0x4af1fb);}return this[_0x4dc382(0x2c,0xa9)][_0x4dc382(0x34,0x58)]['push']({'column':_0x249400,'operator':_0x4dc382(0x43,-0x11),'value':_0x21a002}),this;}['lt'](_0x6d19c9,_0x7e86db){this[_0xff8829(0x235,0x2a6)]['filters'][_0xff8829(0x1e8,0x178)]({'column':_0x6d19c9,'operator':'lt','value':_0x7e86db});function _0xff8829(_0x168478,_0x25d628){return _0x46d3(_0x168478-0x24,_0x25d628);}return this;}['lte'](_0x1abe3f,_0x1eb1d4){function _0x935c19(_0x2fb795,_0x62ba07){return _0x46d3(_0x62ba07- -0x23a,_0x2fb795);}return this[_0x935c19(0x1f,-0x29)][_0x935c19(-0x16,-0x21)]['push']({'column':_0x1abe3f,'operator':_0x935c19(0x21,0x28),'value':_0x1eb1d4}),this;}['like'](_0x2112b7,_0x6ff611){function _0x1e72a4(_0x18257b,_0x34c9df){return _0x46d3(_0x34c9df-0xa4,_0x18257b);}return this['query']['filters'][_0x1e72a4(0x204,0x268)]({'column':_0x2112b7,'operator':_0x1e72a4(0x1ba,0x21c),'value':_0x6ff611}),this;}['ilike'](_0x5c8c35,_0x19b555){this[_0x526165(0x5e2,0x58c)]['filters']['push']({'column':_0x5c8c35,'operator':_0x526165(0x5b9,0x59d),'value':_0x19b555});function _0x526165(_0x28a756,_0x1fcc18){return _0x46d3(_0x28a756-0x3d1,_0x1fcc18);}return this;}['is'](_0x20b021,_0x5e78d5){this['query'][_0x44f8df(0x451,0x3f6)][_0x44f8df(0x3fc,0x410)]({'column':_0x20b021,'operator':'is','value':_0x5e78d5});function _0x44f8df(_0x276ffb,_0x369440){return _0x46d3(_0x276ffb-0x238,_0x369440);}return this;}['in'](_0x561173,_0x5b8d99){this[_0x183ce2(0xcf,0x129)][_0x183ce2(0x13b,0x131)]['push']({'column':_0x561173,'operator':'in','value':_0x5b8d99});function _0x183ce2(_0x2a8037,_0x4d7754){return _0x46d3(_0x4d7754- -0xe8,_0x2a8037);}return this;}[_0x294921(0x52,-0x2f)](_0x3af99b,_0xfdb906){this['query']['filters'][_0x41854f(0x5a1,0x600)]({'column':_0x3af99b,'operator':_0x41854f(0x55c,0x53f),'value':_0xfdb906});function _0x41854f(_0x15738a,_0x4a2974){return _0x46d3(_0x15738a-0x3dd,_0x4a2974);}return this;}[_0x294921(0x25,-0x61)](_0x9de57c){Object[_0x24ff13(0x388,0x34c)](_0x9de57c)['forEach'](([_0x1c03c0,_0x548139])=>{this['eq'](_0x1c03c0,_0x548139);});function _0x24ff13(_0x13984a,_0xce36e4){return _0x46d3(_0x13984a-0x18d,_0xce36e4);}return this;}[_0x294921(0xa3,0xa0)](_0x4f301d,_0x2f7ec4){!this['query'][_0x4b6114(-0x117,-0xc0)]&&(this['query']['order']=[]);this[_0x4b6114(-0x105,-0xfd)]['order']['push']({'column':_0x4f301d,'ascending':_0x2f7ec4?.['ascending']!==![]});function _0x4b6114(_0xf8871b,_0x2db352){return _0x46d3(_0x2db352- -0x30e,_0xf8871b);}return this;}[_0x294921(-0xcf,-0x5e)](count){return this['query']['limit']=count,this;}[_0x294921(0x29,-0x45)](from,_0x51c078){return this['query']['range']={'from':from,'to':_0x51c078},this;}async[_0x294921(0x7f,0x68)](){function _0x26f514(_0x243474,_0x766ee5){return _0x46d3(_0x766ee5-0x32b,_0x243474);}if(this[_0x26f514(0x5af,0x53c)]['updateData'])return this['executeQuery']('PATCH',this['restUrl']+'/'+this[_0x26f514(0x4f2,0x527)],{'data':this[_0x26f514(0x591,0x53c)]['updateData'],'options':this['query'][_0x26f514(0x582,0x53d)],'filters':this['query'][_0x26f514(0x516,0x544)]});else return this[_0x26f514(0x513,0x53c)][_0x26f514(0x4db,0x501)]?this['executeQuery']('DELETE',this[_0x26f514(0x41f,0x49d)]+'/'+this[_0x26f514(0x552,0x527)]+'?operation=delete',{'options':this['query'][_0x26f514(0x503,0x4c3)],'filters':this[_0x26f514(0x56c,0x53c)]['filters']}):this[_0x26f514(0x581,0x565)]('GET',this[_0x26f514(0x499,0x49d)]+'/'+this[_0x26f514(0x561,0x527)]+_0x26f514(0x57a,0x53f),{'select':this[_0x26f514(0x4fa,0x53c)][_0x26f514(0x4a5,0x4c5)],'filters':this['query'][_0x26f514(0x4fd,0x544)],'order':this['query']['order'],'limit':this['query']['limit'],'range':this[_0x26f514(0x504,0x53c)]['range']});}async[_0x294921(-0xad,-0x40)](){this['limit'](0x1);function _0x271d9c(_0x437dd9,_0x3fb1e8){return _0x46d3(_0x437dd9- -0x1e2,_0x3fb1e8);}const result=await this[_0x271d9c(0x34,0x26)]();return{'data':result['data']?.[0x0]||null,'error':result['error']};}async['executeQuery'](_0x3335f2,_0x16b908,_0x45771a){function _0x872c06(_0x493b71,_0x261836){return _0x46d3(_0x261836-0x264,_0x493b71);}try{let response;const headers={};this['workspaceId']&&(headers['x-workspace-id']=this['workspaceId']);if(_0x3335f2==='GET'){const _0x37681b=_0x16b908[_0x872c06(0x3d2,0x3e2)]('?'),_0x2187e7=_0x37681b[0x0],existingParams=new URLSearchParams(_0x37681b[0x1]||'');if(_0x45771a['select'])existingParams[_0x872c06(0x39d,0x416)](_0x872c06(0x3a5,0x3fe),_0x45771a[_0x872c06(0x375,0x3fe)]);_0x45771a[_0x872c06(0x4d8,0x47d)]?.['length']&&_0x45771a['filters']['forEach'](filter=>{function _0x56986f(_0x1102f5,_0x5d8117){return _0x46d3(_0x1102f5-0x368,_0x5d8117);}existingParams[_0x56986f(0x51a,0x4ae)](filter['column'],filter['operator']+'.'+filter[_0x56986f(0x532,0x4bf)]);});if(_0x45771a['order']?.[_0x872c06(0x3ef,0x403)]){const orderStr=_0x45771a[_0x872c06(0x4a4,0x4b2)][_0x872c06(0x40d,0x3c6)](_0x573b3d=>''+_0x573b3d['column']+(_0x573b3d['ascending']?_0x872c06(0x4ae,0x438):_0x872c06(0x484,0x402)))[_0x872c06(0x43e,0x45d)](',');existingParams[_0x872c06(0x433,0x416)](_0x872c06(0x475,0x4b2),orderStr);}if(_0x45771a['limit'])existingParams[_0x872c06(0x48b,0x416)](_0x872c06(0x421,0x3b4),_0x45771a['limit'][_0x872c06(0x393,0x3f1)]());_0x45771a['range']&&(existingParams[_0x872c06(0x459,0x416)]('offset',_0x45771a[_0x872c06(0x3d3,0x3cd)][_0x872c06(0x490,0x499)]['toString']()),existingParams[_0x872c06(0x43e,0x416)](_0x872c06(0x3b3,0x3b4),(_0x45771a[_0x872c06(0x44f,0x3cd)]['to']-_0x45771a['range']['from']+0x1)[_0x872c06(0x41b,0x3f1)]())),response=await this[_0x872c06(0x48b,0x417)]['get'](_0x2187e7+'?'+existingParams['toString'](),{'headers':headers});}else{if(_0x3335f2==='DELETE'){const _0x1710cb=_0x16b908['split']('?'),_0x5baa68=_0x1710cb[0x0],existingParams=new URLSearchParams(_0x1710cb[0x1]||'');!existingParams['has'](_0x872c06(0x41a,0x47c))&&existingParams['append']('operation','delete');_0x45771a['filters']?.[_0x872c06(0x37f,0x403)]&&_0x45771a['filters']['forEach'](filter=>{function _0x1c980e(_0x5e6e3a,_0x388b05){return _0x46d3(_0x388b05-0x1f2,_0x5e6e3a);}existingParams[_0x1c980e(0x341,0x3a4)](filter[_0x1c980e(0x3ae,0x383)],filter[_0x1c980e(0x3ab,0x3b5)]+'.'+filter[_0x1c980e(0x387,0x3bc)]);});const deleteUrl=_0x5baa68+'?'+existingParams['toString']();console[_0x872c06(0x460,0x46a)]('\uD83D\uDD27 DELETE URL construída:',deleteUrl),console[_0x872c06(0x4a5,0x46a)]('\uD83D\uDD27 DELETE headers:',headers),console['log']('\uD83D\uDD27 DELETE filtros originais:',_0x45771a['filters']),response=await this['httpClient'][_0x872c06(0x45e,0x3e8)](deleteUrl,{'headers':headers});}else{if(_0x3335f2==='PATCH'){const _0x5ef162=_0x16b908[_0x872c06(0x39b,0x3e2)]('?'),_0x5d4139=_0x5ef162[0x0],existingParams=new URLSearchParams(_0x5ef162[0x1]||'');!existingParams[_0x872c06(0x3b7,0x435)]('operation')&&existingParams[_0x872c06(0x3d1,0x416)]('operation',_0x872c06(0x3e2,0x423));_0x45771a['filters']?.['length']&&_0x45771a['filters'][_0x872c06(0x437,0x3c3)](filter=>{function _0x36aa56(_0x1826e2,_0x29797b){return _0x46d3(_0x29797b- -0x1df,_0x1826e2);}existingParams['append'](filter['column'],filter[_0x36aa56(0x62,-0x1c)]+'.'+filter[_0x36aa56(-0x34,-0x15)]);});_0x45771a['options']?.[_0x872c06(0x4f6,0x4c5)]&&(headers[_0x872c06(0x414,0x3e6)]=_0x45771a[_0x872c06(0x470,0x3f8)][_0x872c06(0x48e,0x4c5)]);const updateUrl=_0x5d4139+'?'+existingParams[_0x872c06(0x40a,0x3f1)]();response=await this['httpClient'][_0x872c06(0x40c,0x42a)](updateUrl,_0x45771a[_0x872c06(0x492,0x425)],{'headers':headers});}else{let _0x37b02b=_0x45771a[_0x872c06(0x436,0x425)];!headers['Prefer']&&(headers['Prefer']=_0x872c06(0x515,0x4b4)),_0x45771a['options']?.['upsert']&&(headers['Prefer']=_0x872c06(0x3a4,0x3e5)),_0x45771a[_0x872c06(0x3eb,0x3ef)]&&(_0x37b02b=_0x45771a[_0x872c06(0x3d0,0x3ef)]),response=await this[_0x872c06(0x3aa,0x417)][_0x872c06(0x34f,0x3d5)](_0x16b908,_0x37b02b,{'headers':headers});}}}return{'data':response['data'],'error':null,'count':response['headers']?.[_0x872c06(0x44b,0x3ff)]?parseInt(response[_0x872c06(0x347,0x3be)]['x-total-count']):undefined};}catch(_0x51de63){return{'data':null,'error':_0x51de63 instanceof EBaaSError?_0x51de63:new EBaaSError(_0x51de63 instanceof Error?_0x51de63[_0x872c06(0x526,0x4c0)]:_0x872c06(0x4c3,0x45c),0x0,_0x51de63)};}}}class CustomDatabaseManager{constructor(_0x1d3c77,_0x150e4c){this[_0x3a99df(0x149,0x1cd)]=_0x1d3c77;function _0x3a99df(_0x5872b1,_0xd61cb3){return _0x46d3(_0x5872b1- -0x6a,_0xd61cb3);}this['workspaceId']=_0x150e4c;}async[_0x294921(-0xc7,-0x46)](){function _0x4df875(_0x377714,_0x42a0c4){return _0x46d3(_0x377714-0x1e0,_0x42a0c4);}if(!this['workspaceId'])return{'hasCustomDatabase':![]};try{const response=await this['httpClient']['get']('/admin/v1/workspace/custom-database',{'headers':{'x-workspace-id':this[_0x4df875(0x3a0,0x360)]}});if(response['status']===0xc8&&response[_0x4df875(0x3a1,0x38a)]?.[_0x4df875(0x385,0x323)]){const config=response['data']['config'],_0x4f460f={'host':config[_0x4df875(0x35d,0x2f2)],'port':config[_0x4df875(0x40a,0x37f)],'database':config['postgresDatabase'],'username':config['postgresUsername'],'password':'','schema':config[_0x4df875(0x354,0x345)],'sslEnabled':config[_0x4df875(0x366,0x2f3)]};return this['detectedConfig']={'hasCustomDatabase':!![],'config':config,'credentials':_0x4f460f},this['detectedConfig'];}}catch(_0x51e3cd){if(_0x51e3cd?.[_0x4df875(0x338,0x2b5)]===0x194)return this['detectedConfig']={'hasCustomDatabase':![]},this[_0x4df875(0x43e,0x404)];console[_0x4df875(0x3d0,0x3b0)]('Failed to detect custom database configuration:',_0x51e3cd);}return this[_0x4df875(0x43e,0x43a)]={'hasCustomDatabase':![]},this['detectedConfig'];}async['testConnection'](_0x2dd835){function _0x4fbb1f(_0x2b6bbf,_0x3a2f9b){return _0x46d3(_0x2b6bbf- -0x170,_0x3a2f9b);}try{const response=await this[_0x4fbb1f(0x43,0x25)][_0x4fbb1f(0x1,-0x6)]('/admin/v1/workspace/custom-database/test-connection',_0x2dd835,{'headers':this['workspaceId']?{'X-Workspace-ID':this['workspaceId']}:{}});return response['data'];}catch(_0x4d2495){return{'success':![],'message':_0x4d2495?.['message']||'Failed\x20to\x20test\x20connection'};}}async['configureCustomDatabase'](_0x25f721){if(!this['workspaceId'])throw new Error('Workspace ID is required to configure custom database');const response=await this['httpClient'][_0x76b320(0x66,-0x1e)]('/admin/v1/workspace/custom-database',{'workspaceId':this[_0x76b320(-0x33,0x31)],..._0x25f721},{'headers':{'X-Workspace-ID':this[_0x76b320(0x66,0x31)]}});function _0x76b320(_0x376ec8,_0x27a3a5){return _0x46d3(_0x27a3a5- -0x18f,_0x376ec8);}const config=response[_0x76b320(0x79,0x32)][_0x76b320(0x6c,0x16)];return this['detectedConfig']={'hasCustomDatabase':!![],'config':config,'credentials':_0x25f721},config;}async[_0x294921(0x1a,-0xa)](){if(!this[_0x13fd17(0x98,0xe2)])throw new Error('Workspace ID is required to remove custom database');await this['httpClient'][_0x13fd17(0xf0,0xa6)]('/admin/v1/workspace/custom-database',{'headers':{'X-Workspace-ID':this[_0x13fd17(0xe2,0xe2)]}});function _0x13fd17(_0x422494,_0x29d9b6){return _0x46d3(_0x29d9b6- -0xde,_0x422494);}this[_0x13fd17(0x1e2,0x180)]={'hasCustomDatabase':![]};}[_0x294921(-0xc6,-0x3e)](){function _0x578cd0(_0xe53021,_0x2a8109){return _0x46d3(_0xe53021- -0x30e,_0x2a8109);}return this[_0x578cd0(-0xb0,-0xa6)];}['hasCustomDatabase'](){function _0x324c2c(_0x355d0a,_0x28f2d3){return _0x46d3(_0x355d0a-0x173,_0x28f2d3);}return this[_0x324c2c(0x3d1,0x43d)]?.[_0x324c2c(0x36a,0x32f)]??![];}[_0x294921(0x3b,0x73)](){function _0x12a9a7(_0x38a129,_0x1f1c5e){return _0x46d3(_0x38a129-0x22b,_0x1f1c5e);}return this[_0x12a9a7(0x489,0x4bb)]?.['credentials'];}['setWorkspaceId'](_0xbb9bab){this['workspaceId']=_0xbb9bab;function _0x3c26c0(_0x17a2cb,_0x36119a){return _0x46d3(_0x36119a-0x3e1,_0x17a2cb);}this[_0x3c26c0(0x687,0x63f)]=undefined;}['getWorkspaceId'](){return this['workspaceId'];}[_0x294921(-0x15,-0x4a)](){function _0x144d1b(_0x512e72,_0x558aec){return _0x46d3(_0x512e72-0x3ab,_0x558aec);}return{'workspaceId':this['workspaceId'],'hasConfig':this['hasCustomDatabase'](),'configDetails':this['detectedConfig']?.['credentials']?{'host':this['detectedConfig'][_0x144d1b(0x5cb,0x60e)]['host'],'port':this[_0x144d1b(0x609,0x618)]['credentials']['port'],'database':this['detectedConfig'][_0x144d1b(0x5cb,0x56f)][_0x144d1b(0x59c,0x601)],'schema':this[_0x144d1b(0x609,0x5d0)]['credentials']['schema']||_0x144d1b(0x4f9,0x4a8),'sslEnabled':this['detectedConfig']['credentials'][_0x144d1b(0x531,0x597)]||![]}:undefined};}}class DatabaseClient{constructor(_0x4fd1e8,_0x98aff3,_0x17c0b9){this['httpClient']=_0x4fd1e8,this['customDatabaseManager']=new CustomDatabaseManager(_0x4fd1e8,_0x98aff3);function _0x23beb2(_0x30cd44,_0x60fd57){return _0x46d3(_0x60fd57-0x80,_0x30cd44);}this[_0x23beb2(0x1de,0x1f2)]=_0x17c0b9||'/sdk/v1';}[_0x294921(0x81,0x87)](_0x1d2846){function _0x155545(_0x2aee9b,_0xf3202){return _0x46d3(_0x2aee9b-0x361,_0xf3202);}return new QueryBuilder(this['httpClient'],_0x1d2846,this[_0x155545(0x55b,0x59b)],this['customDatabaseManager'][_0x155545(0x55e,0x5d4)](),this[_0x155545(0x4d3,0x475)]);}[_0x294921(-0x94,-0xb)](_0x4087e1,_0x59f4b5){return this['httpClient']['post']('/rpc/'+_0x4087e1,_0x59f4b5);}[_0x294921(0x53,0x8a)](_0x4b1fca){const _0x23b900=new DatabaseClient(this['httpClient'],this[_0x3f8beb(0x2d1,0x2e5)]['getWorkspaceId'](),this[_0x3f8beb(0x2a3,0x291)]);_0x23b900[_0x3f8beb(0x32b,0x325)]=_0x4b1fca;function _0x3f8beb(_0x32c5cc,_0x3d784a){return _0x46d3(_0x32c5cc-0x131,_0x3d784a);}return _0x23b900[_0x3f8beb(0x2d1,0x2fb)]=this['customDatabaseManager'],_0x23b900;}async[_0x294921(-0x85,-0x46)](){function _0x20c2fc(_0x55e833,_0x225978){return _0x46d3(_0x225978- -0xd2,_0x55e833);}return this[_0x20c2fc(0xee,0xce)]['detectCustomDatabase']();}async['testCustomConnection'](_0xb4cad9){function _0x166339(_0x4a68b8,_0x43fbe5){return _0x46d3(_0x4a68b8- -0x8a,_0x43fbe5);}return this[_0x166339(0x116,0x184)][_0x166339(0x15a,0x112)](_0xb4cad9);}async[_0x294921(0x27,0x48)](_0x46f577){function _0x56db48(_0x4fa32e,_0x4b6961){return _0x46d3(_0x4b6961-0x348,_0x4fa32e);}return this['customDatabaseManager'][_0x56db48(0x581,0x53e)](_0x46f577);}async['removeCustomDatabase'](){function _0x2f6e70(_0x11882a,_0x2fa683){return _0x46d3(_0x11882a-0x1e7,_0x2fa683);}return this[_0x2f6e70(0x387,0x33e)]['removeCustomDatabase']();}[_0x294921(0x7f,0x5c)](){return this['customDatabaseManager']['hasCustomDatabase']();}['getCustomDatabaseStatus'](){function _0x1df653(_0x1c4517,_0x221011){return _0x46d3(_0x221011- -0xa7,_0x1c4517);}return this[_0x1df653(0x70,0xf9)]['getStatus']();}['setWorkspaceId'](_0x55b584){function _0x5888dd(_0x1b34d1,_0x3bb5ac){return _0x46d3(_0x3bb5ac-0x56,_0x1b34d1);}this[_0x5888dd(0x275,0x1f6)]['setWorkspaceId'](_0x55b584);}async['initialize'](){function _0x14a01f(_0x29898e,_0x3eb13b){return _0x46d3(_0x29898e-0x229,_0x3eb13b);}try{await this[_0x14a01f(0x3c9,0x3af)]['detectCustomDatabase']();}catch(_0x517453){console[_0x14a01f(0x419,0x38d)]('Failed to initialize custom database detection:',_0x517453);}}}class StorageBucket{constructor(_0x5eb694,bucketId){function _0x403b77(_0x3003ba,_0x381e0e){return _0x46d3(_0x3003ba- -0x3c,_0x381e0e);}this[_0x403b77(0x177,0x15e)]=_0x5eb694,this[_0x403b77(0x18c,0x1cd)]=bucketId;}async['upload'](_0xfcb033,_0x12b0fa,_0x27e882){function _0x1d3a18(_0xdfd1d9,_0x2e399a){return _0x46d3(_0x2e399a- -0x312,_0xdfd1d9);}try{const _0x36f057=new FormData();if(_0x12b0fa instanceof File)_0x36f057['append']('file',_0x12b0fa);else{if(_0x12b0fa instanceof Blob)_0x36f057[_0x1d3a18(-0x14e,-0x160)](_0x1d3a18(-0xfa,-0x13d),_0x12b0fa,_0xfcb033);else{if(_0x12b0fa instanceof ArrayBuffer)_0x36f057[_0x1d3a18(-0x160,-0x160)]('file',new Blob([_0x12b0fa]),_0xfcb033);else typeof _0x12b0fa==='string'&&_0x36f057['append']('file',new Blob([_0x12b0fa],{'type':'text/plain'}),_0xfcb033);}}_0x36f057['append']('path',_0xfcb033);_0x27e882?.['cacheControl']&&_0x36f057['append'](_0x1d3a18(-0x146,-0x133),_0x27e882[_0x1d3a18(-0x1bf,-0x133)]);_0x27e882?.[_0x1d3a18(-0x71,-0xd2)]&&_0x36f057[_0x1d3a18(-0xd5,-0x160)]('contentType',_0x27e882['contentType']);_0x27e882?.[_0x1d3a18(-0xb3,-0xeb)]&&_0x36f057['append'](_0x1d3a18(-0x8c,-0xeb),JSON[_0x1d3a18(-0x173,-0x1b6)](_0x27e882[_0x1d3a18(-0x13b,-0xeb)]));const _0x53d828='/storage/buckets/'+this[_0x1d3a18(-0xc3,-0x14a)]+'/files'+(_0x27e882?.['upsert']?_0x1d3a18(-0x124,-0xd5):''),response=await this[_0x1d3a18(-0x15b,-0x15f)][_0x1d3a18(-0x1cc,-0x1a1)](_0x53d828,_0x36f057,{'headers':{'Content-Type':_0x1d3a18(-0x1f8,-0x17c)}});return{'data':response[_0x1d3a18(-0x114,-0x151)],'error':null};}catch(_0x1e1e66){return{'data':null,'error':_0x1e1e66 instanceof EBaaSError?_0x1e1e66:new EBaaSError(_0x1e1e66 instanceof Error?_0x1e1e66['message']:_0x1d3a18(-0x11d,-0x102),0x0,_0x1e1e66)};}}async[_0x294921(0xb7,0x45)](_0x2abe66,_0x225a79){function _0x1d7f87(_0x539e06,_0x2f15d8){return _0x46d3(_0x2f15d8-0xe,_0x539e06);}try{const _0x1b1f85=new URLSearchParams();_0x225a79?.['transform']&&Object[_0x1d7f87(0x1a0,0x209)](_0x225a79[_0x1d7f87(0x21b,0x23a)])['forEach'](([_0x3d13fc,_0x6c562b])=>{_0x6c562b!==undefined&&_0x1b1f85['append'](_0x3d13fc,String(_0x6c562b));});const _0x168a63='/storage/buckets/'+this['bucketId']+_0x1d7f87(0x1da,0x263)+_0x2abe66+(_0x1b1f85[_0x1d7f87(0x1a8,0x19b)]()?'?'+_0x1b1f85['toString']():''),response=await this[_0x1d7f87(0x237,0x1c1)][_0x1d7f87(0x1dc,0x23d)](_0x168a63,{'responseType':'blob'});return{'data':response['data'],'error':null};}catch(_0x24bf86){return{'data':null,'error':_0x24bf86 instanceof EBaaSError?_0x24bf86:new EBaaSError(_0x24bf86 instanceof Error?_0x24bf86[_0x1d7f87(0x272,0x26a)]:_0x1d7f87(0x22d,0x1d5),0x0,_0x24bf86)};}}async[_0x294921(-0x6c,0x8)](_0x2d802a,_0x3111ad){function _0x54ff48(_0x1a4c9d,_0x32dc2c){return _0x46d3(_0x1a4c9d- -0x63,_0x32dc2c);}try{const _0x4b1a60=new URLSearchParams();_0x2d802a&&_0x4b1a60['append']('prefix',_0x2d802a);_0x3111ad?.['limit']&&_0x4b1a60[_0x54ff48(0x14f,0xfc)](_0x54ff48(0xed,0x113),String(_0x3111ad['limit']));_0x3111ad?.['offset']&&_0x4b1a60['append'](_0x54ff48(0x104,0x88),String(_0x3111ad[_0x54ff48(0x104,0x146)]));_0x3111ad?.[_0x54ff48(0x184,0x1f7)]&&_0x4b1a60[_0x54ff48(0x14f,0x1c4)]('sortBy',JSON['stringify'](_0x3111ad['sortBy']));_0x3111ad?.['search']&&_0x4b1a60[_0x54ff48(0x14f,0x167)]('search',_0x3111ad['search']);const _0x3b8cf8='/storage/buckets/'+this['bucketId']+'/files'+(_0x4b1a60['toString']()?'?'+_0x4b1a60['toString']():''),response=await this[_0x54ff48(0x150,0x103)]['get'](_0x3b8cf8);return{'data':response['data'],'error':null};}catch(_0x2fbe07){return{'data':null,'error':_0x2fbe07 instanceof EBaaSError?_0x2fbe07:new EBaaSError(_0x2fbe07 instanceof Error?_0x2fbe07['message']:'Failed\x20to\x20list\x20files',0x0,_0x2fbe07)};}}async[_0x294921(0xa,0x88)](_0x103f3a){function _0x22c37b(_0x28d780,_0x1eb27a){return _0x46d3(_0x1eb27a-0x4c,_0x28d780);}try{const response=await this['httpClient']['delete'](_0x22c37b(0x185,0x1dc)+this['bucketId']+_0x22c37b(0x282,0x27d),{'data':{'paths':_0x103f3a}});return{'data':response['data'],'error':null};}catch(_0x2dc9ff){return{'data':null,'error':_0x2dc9ff instanceof EBaaSError?_0x2dc9ff:new EBaaSError(_0x2dc9ff instanceof Error?_0x2dc9ff[_0x22c37b(0x325,0x2a8)]:_0x22c37b(0x226,0x1d8),0x0,_0x2dc9ff)};}}async[_0x294921(0x5b,0x7)](fromPath,_0x351076){function _0x2a5ab0(_0x479594,_0x530879){return _0x46d3(_0x530879-0x398,_0x479594);}try{const response=await this[_0x2a5ab0(0x5ae,0x54b)]['post']('/storage/buckets/'+this[_0x2a5ab0(0x5d5,0x560)]+_0x2a5ab0(0x5ca,0x5eb),{'sourceKey':fromPath,'destinationKey':_0x351076});return{'data':response[_0x2a5ab0(0x5c9,0x559)],'error':null};}catch(_0x441e42){return{'data':null,'error':_0x441e42 instanceof EBaaSError?_0x441e42:new EBaaSError(_0x441e42 instanceof Error?_0x441e42[_0x2a5ab0(0x62a,0x5f4)]:'Failed\x20to\x20move\x20file',0x0,_0x441e42)};}}async[_0x294921(-0x55,0x1e)](fromPath,_0x292289){function _0xab4545(_0xae8b6f,_0x1f6da0){return _0x46d3(_0x1f6da0-0x19e,_0xae8b6f);}try{const response=await this['httpClient'][_0xab4545(0x306,0x30f)](_0xab4545(0x380,0x32e)+this['bucketId']+'/files/copy',{'sourceKey':fromPath,'destinationKey':_0x292289});return{'data':response['data'],'error':null};}catch(_0x5372b3){return{'data':null,'error':_0x5372b3 instanceof EBaaSError?_0x5372b3:new EBaaSError(_0x5372b3 instanceof Error?_0x5372b3['message']:_0xab4545(0x328,0x2f1),0x0,_0x5372b3)};}}async['createSignedUrl'](_0x121faa,_0x270372,_0x233a24){function _0x5c3bc3(_0x2c4c6e,_0x4e5f17){return _0x46d3(_0x4e5f17- -0xf8,_0x2c4c6e);}try{const response=await this[_0x5c3bc3(0x37,0xbb)]['post']('/storage/buckets/'+this[_0x5c3bc3(0x122,0xd0)]+_0x5c3bc3(0x1cb,0x15d)+_0x121faa+_0x5c3bc3(0x128,0xa1),{'expiresIn':_0x270372,..._0x233a24});return{'data':response['data'],'error':null};}catch(_0x2aa398){return{'data':null,'error':_0x2aa398 instanceof EBaaSError?_0x2aa398:new EBaaSError(_0x2aa398 instanceof Error?_0x2aa398['message']:_0x5c3bc3(0x51,0x9f),0x0,_0x2aa398)};}}['getPublicUrl'](_0x1b3615,_0xf71ed5){const _0x521b9f=new URLSearchParams();function _0x358fbe(_0x519f9f,_0x2d273a){return _0x46d3(_0x519f9f- -0x267,_0x2d273a);}_0xf71ed5?.['transform']&&Object['entries'](_0xf71ed5[_0x358fbe(-0x3b,0x2)])[_0x358fbe(-0x108,-0x12e)](([_0x4111eb,_0x1deec9])=>{_0x1deec9!==undefined&&_0x521b9f['append'](_0x4111eb,String(_0x1deec9));});const _0x377305=this['httpClient'][_0x358fbe(-0x2c,-0x6e)]||'',_0x6bb8fe=_0x377305+_0x358fbe(-0xd7,-0x13a)+this['bucketId']+_0x358fbe(-0x12,0x20)+_0x1b3615+(_0x521b9f['toString']()?'?'+_0x521b9f[_0x358fbe(-0xda,-0xe5)]():'');return{'data':{'publicUrl':_0x6bb8fe}};}async[_0x294921(0xe5,0x85)](_0x184d7a){function _0x3a3791(_0xbc1b95,_0x578ac3){return _0x46d3(_0x578ac3- -0x1a6,_0xbc1b95);}try{const response=await this[_0x3a3791(0x16,0xd)][_0x3a3791(0x31,0x89)](_0x3a3791(0x49,-0x16)+this['bucketId']+'/files/'+_0x184d7a+'/info');return{'data':response[_0x3a3791(0x3d,0x1b)],'error':null};}catch(_0x24df5f){return{'data':null,'error':_0x24df5f instanceof EBaaSError?_0x24df5f:new EBaaSError(_0x24df5f instanceof Error?_0x24df5f['message']:'Failed\x20to\x20get\x20file\x20info',0x0,_0x24df5f)};}}async['updateFileMetadata'](_0x3aa78b,metadata){function _0x33d6f6(_0x5f1208,_0x1057f6){return _0x46d3(_0x1057f6- -0x287,_0x5f1208);}try{const response=await this[_0x33d6f6(-0x7f,-0xd4)]['put'](_0x33d6f6(-0xf7,-0xf7)+this['bucketId']+_0x33d6f6(0x2f,-0x32)+_0x3aa78b+'/metadata',{'metadata':metadata});return{'data':response[_0x33d6f6(-0x12e,-0xc6)],'error':null};}catch(_0x44192c){return{'data':null,'error':_0x44192c instanceof EBaaSError?_0x44192c:new EBaaSError(_0x44192c instanceof Error?_0x44192c['message']:_0x33d6f6(-0xb8,-0xbc),0x0,_0x44192c)};}}}class StorageClient{constructor(_0x3348d3){this['httpClient']=_0x3348d3;}[_0x294921(0xd1,0x87)](bucketId){return new StorageBucket(this['httpClient'],bucketId);}async[_0x294921(-0xce,-0x48)](_0x3d6209,_0x406b4b){function _0x1594b6(_0x25a4bc,_0x12e362){return _0x46d3(_0x25a4bc-0x2ab,_0x12e362);}try{const response=await this['httpClient']['post']('/storage/buckets',{'id':_0x3d6209,..._0x406b4b});return{'data':response['data'],'error':null};}catch(_0x20dc7d){return{'data':null,'error':_0x20dc7d instanceof EBaaSError?_0x20dc7d:new EBaaSError(_0x20dc7d instanceof Error?_0x20dc7d[_0x1594b6(0x507,0x4de)]:'Failed\x20to\x20create\x20bucket',0x0,_0x20dc7d)};}}async['getBucket'](_0x58f659){function _0x1fe553(_0x4eaf2c,_0x5ca4df){return _0x46d3(_0x4eaf2c-0xd5,_0x5ca4df);}try{const response=await this[_0x1fe553(0x288,0x293)]['get'](_0x1fe553(0x265,0x232)+_0x58f659);return{'data':response['data'],'error':null};}catch(_0xd6e9bb){return{'data':null,'error':_0xd6e9bb instanceof EBaaSError?_0xd6e9bb:new EBaaSError(_0xd6e9bb instanceof Error?_0xd6e9bb['message']:_0x1fe553(0x2b2,0x25b),0x0,_0xd6e9bb)};}}async[_0x294921(-0xa4,-0x44)](){function _0x13979d(_0x34cc56,_0x5072b1){return _0x46d3(_0x34cc56- -0x203,_0x5072b1);}try{const response=await this[_0x13979d(-0x50,0x20)][_0x13979d(0x2c,0xaa)]('/storage/buckets');return{'data':response['data'],'error':null};}catch(_0x5aa400){return{'data':null,'error':_0x5aa400 instanceof EBaaSError?_0x5aa400:new EBaaSError(_0x5aa400 instanceof Error?_0x5aa400['message']:_0x13979d(-0xa0,-0x113),0x0,_0x5aa400)};}}async['updateBucket'](_0x39c42a,_0x480b9e){function _0x4cc340(_0x1fc3e4,_0x55a2d2){return _0x46d3(_0x1fc3e4- -0x341,_0x55a2d2);}try{const response=await this[_0x4cc340(-0x18e,-0x138)][_0x4cc340(-0x1e1,-0x1f3)](_0x4cc340(-0x1b1,-0x195)+_0x39c42a,_0x480b9e);return{'data':response[_0x4cc340(-0x180,-0x170)],'error':null};}catch(_0x34f550){return{'data':null,'error':_0x34f550 instanceof EBaaSError?_0x34f550:new EBaaSError(_0x34f550 instanceof Error?_0x34f550['message']:_0x4cc340(-0x19b,-0x185),0x0,_0x34f550)};}}async['deleteBucket'](_0x2980d2){function _0x150d64(_0x55243b,_0x1e49fa){return _0x46d3(_0x55243b-0x68,_0x1e49fa);}try{const response=await this['httpClient']['delete'](_0x150d64(0x1f8,0x1f4)+_0x2980d2);return{'data':response['data'],'error':null};}catch(_0x2bce25){return{'data':null,'error':_0x2bce25 instanceof EBaaSError?_0x2bce25:new EBaaSError(_0x2bce25 instanceof Error?_0x2bce25[_0x150d64(0x2c4,0x2ca)]:'Failed\x20to\x20delete\x20bucket',0x0,_0x2bce25)};}}async['getUsage'](){function _0x44d3b4(_0x2e8d1e,_0x152b56){return _0x46d3(_0x2e8d1e-0xcf,_0x152b56);}try{const response=await this[_0x44d3b4(0x282,0x2df)]['get'](_0x44d3b4(0x2d7,0x30d));return{'data':response['data'],'error':null};}catch(_0x47d104){return{'data':null,'error':_0x47d104 instanceof EBaaSError?_0x47d104:new EBaaSError(_0x47d104 instanceof Error?_0x47d104['message']:_0x44d3b4(0x224,0x1ae),0x0,_0x47d104)};}}}class EventManager{constructor(){function _0x13c229(_0x81c0a8,_0x265b52){return _0x46d3(_0x81c0a8- -0x332,_0x265b52);}this['events']=new Map(),this[_0x13c229(-0x1cd,-0x15f)]=0xa;}['on'](_0x961cd2,_0x315750){function _0x16956e(_0x104046,_0x34d592){return _0x46d3(_0x104046- -0x9b,_0x34d592);}!this[_0x16956e(0x1bf,0x137)][_0x16956e(0x136,0x155)](_0x961cd2)&&this['events']['set'](_0x961cd2,new Set()),this[_0x16956e(0x1bf,0x1ed)]['get'](_0x961cd2)[_0x16956e(0x173,0x169)](_0x315750);}[_0x294921(0xb4,0x2e)](_0x31e2c2,_0x66f0c0){function _0xf81f7f(_0x473ff8,_0x2bcf42){return _0x46d3(_0x473ff8- -0x71,_0x2bcf42);}if(!this['events']['has'](_0x31e2c2))return;const _0xe04138=this[_0xf81f7f(0x1e9,0x256)][_0xf81f7f(0x1be,0x1ba)](_0x31e2c2);_0x66f0c0?_0xe04138[_0xf81f7f(0x113,0x103)](_0x66f0c0):_0xe04138['clear'](),_0xe04138[_0xf81f7f(0x1cd,0x238)]===0x0&&this[_0xf81f7f(0x1e9,0x216)][_0xf81f7f(0x113,0x136)](_0x31e2c2);}['emit'](_0x1459c5,..._0x32483e){if(!this[_0x2d89ff(0x5be,0x541)]['has'](_0x1459c5))return![];const _0x58ebb4=this[_0x2d89ff(0x5be,0x5df)][_0x2d89ff(0x593,0x510)](_0x1459c5);function _0x2d89ff(_0x29f04f,_0x219d19){return _0x46d3(_0x29f04f-0x364,_0x219d19);}for(const _0xf74873 of _0x58ebb4){try{_0xf74873(..._0x32483e);}catch(_0x5431b5){console['error']('Error\x20in\x20event\x20listener\x20for\x20\x22'+_0x1459c5+'\x22:',_0x5431b5);}}return _0x58ebb4[_0x2d89ff(0x5a2,0x5f7)]>0x0;}['removeAllListeners'](_0x32bded){function _0x5e0fc3(_0x5e34c0,_0xd8eb19){return _0x46d3(_0x5e34c0- -0x308,_0xd8eb19);}_0x32bded?this[_0x5e0fc3(-0xae,-0x97)]['delete'](_0x32bded):this['events']['clear']();}['listenerCount'](_0x260b12){function _0x8121ec(_0x537a69,_0x4d4b36){return _0x46d3(_0x537a69-0x3b3,_0x4d4b36);}return this['events'][_0x8121ec(0x5e2,0x5ff)](_0x260b12)?.['size']??0x0;}['eventNames'](){function _0x2695c3(_0x276d07,_0x4bd95b){return _0x46d3(_0x276d07-0x1a1,_0x4bd95b);}return Array['from'](this['events'][_0x2695c3(0x326,0x3a4)]());}['listeners'](_0x780f1c){function _0x55c835(_0x563d3e,_0x48c971){return _0x46d3(_0x48c971- -0xf,_0x563d3e);}return Array[_0x55c835(0x2a8,0x226)](this[_0x55c835(0x22f,0x24b)][_0x55c835(0x24e,0x220)](_0x780f1c)??[]);}[_0x294921(0x46,0x6e)](_0x31eccf,_0x50ec08){this['on'](_0x31eccf,_0x50ec08);}['removeListener'](_0x3701e3,_0x32b89f){this['off'](_0x3701e3,_0x32b89f);}['once'](_0x4b9d4f,_0x233769){const _0x126db7=(..._0x473e96)=>{this['off'](_0x4b9d4f,_0x126db7),_0x233769(..._0x473e96);};this['on'](_0x4b9d4f,_0x126db7);}['prependListener'](_0x5ab693,_0x4de130){this['on'](_0x5ab693,_0x4de130);}[_0x294921(0x7b,0x33)](_0x4e75a8,_0x4139c6){const _0x3f9cb6=(..._0x4e63cd)=>{this['off'](_0x4e75a8,_0x3f9cb6),_0x4139c6(..._0x4e63cd);};this['on'](_0x4e75a8,_0x3f9cb6);}[_0x294921(0x58,-0xc)](_0x382185){this[_0x3319f4(0x23c,0x28f)]=_0x382185;function _0x3319f4(_0x373cca,_0x4ee421){return _0x46d3(_0x4ee421-0x12a,_0x373cca);}return this;}[_0x294921(-0x6e,-0x1b)](){function _0xd7a4e2(_0x46903e,_0x10b347){return _0x46d3(_0x46903e-0xe5,_0x10b347);}return this[_0xd7a4e2(0x24a,0x2ac)];}['rawListeners'](_0x452110){return this['listeners'](_0x452110);}}function _0x294921(_0x1e8750,_0x5d58be){return _0x46d3(_0x5d58be- -0x1ae,_0x1e8750);}class RealtimeChannel extends EventManager{constructor(_0x13cb2f,_0x3034d0){super(),this[_0x4d77d0(0x3b1,0x343)]=![],this[_0x4d77d0(0x3b5,0x36b)]=_0x4d77d0(0x349,0x327);function _0x4d77d0(_0x1fce69,_0x530a01){return _0x46d3(_0x1fce69-0x1cf,_0x530a01);}this['subscriptions']=new Map(),this['topic']=_0x13cb2f,this[_0x4d77d0(0x328,0x2de)]=_0x3034d0;}['subscribe'](_0x3b65f9){!this[_0x18472d(-0xda,-0xcb)]&&(this['joinedOnce']=!![],this['_join']());_0x3b65f9&&this['on'](_0x18472d(-0x17f,-0x155),_0x3b65f9);function _0x18472d(_0x15d3e8,_0x233e15){return _0x46d3(_0x233e15- -0x2ad,_0x15d3e8);}return this;}['onPostgresChanges'](filter,_0xf4243b){const _0x138da1='postgres_changes:'+JSON['stringify'](filter);this['on'](_0x138da1,_0xf4243b);function _0x2f1936(_0x1e3638,_0x288791){return _0x46d3(_0x288791-0x124,_0x1e3638);}const _0x11ef56={'unsubscribe':()=>{function _0x2736d7(_0x44a4a8,_0x15fc7f){return _0x46d3(_0x15fc7f- -0x35c,_0x44a4a8);}this['off'](_0x138da1,_0xf4243b),this[_0x2736d7(-0x156,-0x168)]['delete'](_0x138da1);}};return this[_0x2f1936(0x335,0x318)]['set'](_0x138da1,_0x11ef56),this['socket']?.[_0x2f1936(0x2f5,0x33f)]&&this['state']==='joined'&&this['socket']['emit']('subscribe_postgres_changes',{'topic':this[_0x2f1936(0x2f3,0x342)],'filter':filter,'ref':this['makeRef']()}),_0x11ef56;}[_0x294921(0x7d,0x35)](filter,_0x5f17bf){const _0x47bf8b='broadcast:'+JSON['stringify'](filter);this['on'](_0x47bf8b,_0x5f17bf);const _0x3734b9={'unsubscribe':()=>{this[_0x42bd34(0x42a,0x467)](_0x47bf8b,_0x5f17bf);function _0x42bd34(_0x51ea37,_0x25644d){return _0x46d3(_0x51ea37-0x24e,_0x25644d);}this['subscriptions']['delete'](_0x47bf8b);}};this['subscriptions'][_0x146f85(-0x274,-0x1ed)](_0x47bf8b,_0x3734b9);function _0x146f85(_0x2ac0fa,_0x35725a){return _0x46d3(_0x35725a- -0x360,_0x2ac0fa);}return _0x3734b9;}[_0x294921(-0x7e,-0x20)](filter,_0x1682ac){const _0x4e3ec9=_0x528273(-0x1c8,-0x1f8)+JSON['stringify'](filter);this['on'](_0x4e3ec9,_0x1682ac);function _0x528273(_0x30bdde,_0x3ab3ce){return _0x46d3(_0x3ab3ce- -0x3a2,_0x30bdde);}const _0x1275f2={'unsubscribe':()=>{this['off'](_0x4e3ec9,_0x1682ac);function _0x5df842(_0xc9cd97,_0x5b7dc1){return _0x46d3(_0xc9cd97- -0x28a,_0x5b7dc1);}this['subscriptions'][_0x5df842(-0x106,-0x176)](_0x4e3ec9);}};return this[_0x528273(-0x225,-0x1ae)][_0x528273(-0x24c,-0x22f)](_0x4e3ec9,_0x1275f2),_0x1275f2;}[_0x294921(0x2e,0x7b)](_0x5a4ba2){return new Promise(_0x179ca5=>{function _0x2714ab(_0x581ce4,_0x35df6b){return _0x46d3(_0x581ce4-0x163,_0x35df6b);}this['socket']?.[_0x2714ab(0x37e,0x305)]&&this[_0x2714ab(0x349,0x30c)]==='joined'?(this[_0x2714ab(0x2bc,0x2b8)]['emit'](_0x2714ab(0x34d,0x364),{'topic':this[_0x2714ab(0x381,0x353)],'event':_0x5a4ba2['event'],'payload':_0x5a4ba2,'ref':this[_0x2714ab(0x33e,0x38d)]()}),_0x179ca5('ok')):_0x179ca5(_0x2714ab(0x2d8,0x35f));});}['track'](_0x75e26d){return new Promise(_0x14353b=>{function _0x433747(_0x2527a1,_0x184cdd){return _0x46d3(_0x2527a1-0xbc,_0x184cdd);}this['socket']?.['connected']&&this[_0x433747(0x2a2,0x2ef)]===_0x433747(0x263,0x233)?(this['socket']['emit'](_0x433747(0x213,0x254),{'topic':this[_0x433747(0x2da,0x30c)],'event':'track','payload':_0x75e26d,'ref':this[_0x433747(0x297,0x265)]()}),_0x14353b('ok')):_0x14353b('error');});}['untrack'](){return new Promise(_0x16f6ee=>{function _0x2226f6(_0x164dc0,_0x1f739b){return _0x46d3(_0x164dc0- -0x395,_0x1f739b);}this['socket']?.[_0x2226f6(-0x17a,-0xf9)]&&this['state']===_0x2226f6(-0x1ee,-0x271)?(this['socket'][_0x2226f6(-0x15c,-0x122)](_0x2226f6(-0x23e,-0x2c6),{'topic':this['topic'],'event':'untrack','ref':this['makeRef']()}),_0x16f6ee('ok')):_0x16f6ee(_0x2226f6(-0x220,-0x21d));});}[_0x294921(0x7c,0xa3)](){return new Promise(_0x1a6bd4=>{function _0x195c7c(_0x1ec16b,_0x327db0){return _0x46d3(_0x327db0-0xe2,_0x1ec16b);}this['state']=_0x195c7c(0x2ee,0x2cb),this['subscriptions'][_0x195c7c(0x261,0x241)](_0x4ce858=>{function _0x10ea1c(_0xaafdf4,_0x195b57){return _0x46d3(_0xaafdf4- -0x196,_0x195b57);}_0x4ce858[_0x10ea1c(0xbb,0xb3)]();}),this['subscriptions'][_0x195c7c(0x2c0,0x2d1)](),this['socket']?.[_0x195c7c(0x32e,0x2fd)]&&this['socket']['emit'](_0x195c7c(0x354,0x32e),{'topic':this[_0x195c7c(0x284,0x300)],'ref':this[_0x195c7c(0x2de,0x2bd)]()}),this[_0x195c7c(0x31b,0x2c8)]='closed',this[_0x195c7c(0x2f2,0x2ee)](),_0x1a6bd4('ok');});}[_0x294921(0xa6,0x9c)](){function _0xe8a895(_0x5ccea9,_0xb96e3b){return _0x46d3(_0xb96e3b- -0x17d,_0x5ccea9);}if(this[_0xe8a895(0x35,0x69)]==='leaving')return;this['state']=_0xe8a895(0x73,0xce),this[_0xe8a895(-0x50,-0x24)]?.['connected']&&(this['socket']['emit']('join',{'topic':this['topic'],'ref':this['makeRef']()}),setTimeout(()=>{function _0x437638(_0x498426,_0x429068){return _0x46d3(_0x429068- -0x2e7,_0x498426);}this[_0x437638(-0x181,-0x101)]==='joining'&&(this[_0x437638(-0x186,-0x101)]=_0x437638(-0x13b,-0x140),this[_0x437638(-0x40,-0xae)]('status',_0x437638(-0xdc,-0xde)));},0x64));}['_rejoin'](){function _0x41875c(_0x37a692,_0x2bc96d){return _0x46d3(_0x37a692-0x220,_0x2bc96d);}this[_0x41875c(0x402,0x38c)]&&(this['_join'](),this[_0x41875c(0x414,0x3f8)]['forEach']((_0x2fa2b8,_0x45c10a)=>{function _0x1d9a00(_0x412894,_0x448faf){return _0x46d3(_0x412894- -0x34a,_0x448faf);}if(_0x45c10a['startsWith'](_0x1d9a00(-0x1de,-0x1a6))){const filter=JSON['parse'](_0x45c10a['replace']('postgres_changes:',''));this['socket']?.[_0x1d9a00(-0x111,-0x8c)](_0x1d9a00(-0x148,-0xf6),{'topic':this['topic'],'filter':filter,'ref':this['makeRef']()});}}));}['_trigger'](_0x2760fc,_0x4de603){if(_0x2760fc==='postgres_changes'){const _0x1b9144=_0x139743(0x4b8,0x52a)+JSON['stringify'](_0x4de603[_0x139743(0x590,0x616)]||{});this[_0x139743(0x585,0x5e3)](_0x1b9144,_0x4de603);}else{if(_0x2760fc===_0x139743(0x536,0x552)){const _0x58681c='broadcast:'+JSON[_0x139743(0x4a8,0x458)]({'event':_0x4de603[_0x139743(0x4db,0x482)]});this['emit'](_0x58681c,_0x4de603);}else{if(_0x2760fc===_0x139743(0x4a3,0x461)){const _0x406293='presence:'+JSON['stringify']({'event':_0x4de603['event']});this['emit'](_0x406293,_0x4de603);}}}function _0x139743(_0x20b8cd,_0x2be4bb){return _0x46d3(_0x20b8cd-0x34c,_0x2be4bb);}this['emit'](_0x2760fc,_0x4de603);}[_0x294921(0x10,0x56)](_0x105763){function _0x2b6e32(_0x4b4001,_0x5a6a99){return _0x46d3(_0x5a6a99- -0x3aa,_0x4b4001);}this[_0x2b6e32(-0x149,-0x1c4)]=_0x105763;let status;switch(_0x105763){case'joined':status='SUBSCRIBED';break;case'errored':status='CHANNEL_ERROR';break;case'closed':status='CLOSED';break;default:return;}this[_0x2b6e32(-0x13d,-0x171)]('status',status);}[_0x294921(0x8,0x2d)](){function _0x4a67f0(_0x1b4a18,_0x38e669){return _0x46d3(_0x1b4a18-0x297,_0x38e669);}return Math[_0x4a67f0(0x4f6,0x582)]()['toString'](0x24)['substring'](0x2,0xf);}[_0x294921(0x27,0x80)](){return this['state'];}}function getEnvironment(){function _0x20683f(_0x3986e9,_0x3a81cd){return _0x46d3(_0x3986e9- -0xcd,_0x3a81cd);}if(typeof navigator!==_0x20683f(0x105,0x122)&&navigator['product']==='ReactNative')return _0x20683f(0xa0,0x7e);if(typeof window!==_0x20683f(0x105,0x102)&&typeof document!==_0x20683f(0x105,0x190))return _0x20683f(0x14d,0xc8);if(typeof global!==_0x20683f(0x105,0x12b)&&typeof process!==_0x20683f(0x105,0xc7)&&process[_0x20683f(0xde,0x114)]?.[_0x20683f(0x189,0x181)])return _0x20683f(0x189,0x1eb);return _0x20683f(0x14d,0x12c);}function _0x1ed3(){const _0x297fbe=['C29JA2v0qwrHChrLCG','z2v0twf4tgLZDgvUzxjZ','B3b0Aw9UCW','nuL4tgv6Bq','BxvSDgLWyxj0l2zVCM0Tzgf0yq','rMfPBgvKihrVignYzwf0zsbZAwDUzwqGvvjm','zgvSzxrLt3b0Aw9UCW','l3nPz24','C2vSzwn0','Ec10B3rHBc1JB3vUDa','Aw52B2TL','DMfSDwvZ','lMrLC2m','BgvUz3rO','y3vZDg9Trgf0ywjHC2vnyw5Hz2vY','l2f1DgGVDJeVDxnLCG','C2v0twf4tgLZDgvUzxjZ','CNbJ','CMvTB3zLq3vZDg9Trgf0ywjHC2u','y29UzMLN','rMfPBgvKihrVihvWzgf0zsbIDwnRzxq','AM9PBMvK','ota5mtG2m2TyrKz3za','mta0DfPZwvn0','ChjLC2vUy2u6','DMvYC2LVBNm','CMvHBhrPBwu','y29UBMvJDf9LCNjVCG','D2vIC29JA2v0','AgfUzgXLrxjYB3i','Aw5Zzxj0','C3rVCMfNzq','yxbWzw5K','Ahr0CenSAwvUDa','zgvWBg95','Bw92zq','BgLZDa','p29WzxjHDgLVBJ1PBNnLCNq','z2v0q29UBMvJDgLVBLn0yxrL','Cg9ZDgDYzxnFy2HHBMDLCW','zgLZy29UBMvJDgvK','z2XVyMfS','CMvQzwn0','yM9KEq','DxbKyxrLrw52','DxbKyxrL','D29YA3nWywnLswq','zgf0yq','C2v0sxrLBq','B3bLCMf0B3i','ChvZAa','icHtDgf0Dxm6ia','Cgf0y2G','rMfPBgvKihrVigrVD25SB2fKigzPBgu','yNvJA2v0swq','DxnL','DMfSDwu','rMfPBgvKihrVihvWzgf0zsbMAwXLig1LDgfKyxrH','y29WEq','Aw5KzxGUDhm','nJy3nZm0D3z2DhPq','CMvTB3zLqxv0AfrVA2vU','C2v0DxbjBNrLCMnLChrVCNm','AgfZ','Dw5KzwzPBMvK','y2XPzw50','lMfZyW','zMLSzq','AxnezwXLDgu','y29UBMvJDgLUzW','C29JA2v0t3b0Aw9UCW','CMvMCMvZAf90B2TLBG','DgLTzw91Da','BwfRzvjLzG','B2zM','rMfPBgvKihrVigDLDcbIDwnRzxq','zw50CNLWB2LUDa','y2fJAgvdB250CM9S','rMfPBgvKihrVigrLCgXVEsbMDw5JDgLVBG','ChjLCgvUze9Uy2vmAxn0zw5LCG','AM9PBMvKt25Jzq','B25cCM9HzgnHC3q','DgvZDenVBM5Ly3rPB24','rMfPBgvKihrVigDLDcbMDw5JDgLVBIbTzxrYAwnZ','C3rHDgu','C29YDej5','AwXPA2u','BgvHDMLUzW','yNjVywrJyxn0','rNvUy3rPB24GAw52B2nHDgLVBIbMywLSzwq','CMvZCg9UC2u','l2f1DgGVDJeVCMvZzxqTCgfZC3DVCMq','Aw5PDgLHBgL6zq','y2XLyxi','D2fYBG','zgf0ywjHC2u','z2v0tg9NCW','zg93BMXVywq','C3vIC2nYAxb0Aw9UCW','u29JA2v0lMLVlwnSAwvUDcbUW6nVigvZDmoHigrPC3bVBSoTDMvSlIbqyxjHifjLywn0ie5HDgL2zsWGAw5ZDgfSztOGBNbTigLUC3rHBgWGC29JA2v0lMLVlwnSAwvUDa','y29UzMLNDxjLq3vZDg9Trgf0ywjHC2u','AgfZq3vZDg9Trgf0ywjHC2u','rgf0ywjHC2uGB3bLCMf0Aw9UigzHAwXLza','AM9PBG','y3vYCMvUDfnJAgvTyq','zw50CMLLCW','DgfIBgu','z2v0v29YA3nWywnLswq','DxbKyxrLvxnLCG','rMfPBgvKihrVigXPC3qGzNvUy3rPB25Z','zgLZy29UBMvJDa','C3rHDhvZvgv4Da','C3vIC2nYAwjLx3bVC3rNCMvZx2nOyw5Nzxm','C2LNBKLU','x3nLDfn0yxrL','p29WzxjHDgLVBJ11ChnLCNq','Bg9N','AgfUzgXLqxv0AevYCM9Y','l3n0B3jHz2uVDxnHz2u','u1vcu0nssujfra','AxnvC2LUz0n1C3rVBurHDgfIyxnL','x3rYAwDNzxi','CMvTB3zLqwXStgLZDgvUzxjZ','yxbPs2v5','ywrK','CMvTB3zLq2HHBM5LBa','rMfPBgvKihrVihvWBg9HzcbMAwXL','CxvLCNK','DxbKyxrLt3b0Aw9UCW','ntG0odu0nhr1Eej4DW','p29WzxjHDgLVBJ1ZzwXLy3q','z2v0twv0CMLJCW','zxHLy3v0zq','C2vZC2LVBG','B3bLCMf0Aw9U','zMLSDgvYCW','yNjVD3nLCG','y29UBMvJDgvK','ywrKtgLZDgvUzxi','l2z1BMn0Aw9UCY92ms8','Dg9WAwm','y29UBMvJDa','y3jLzgvUDgLHBhm','z2v0q3vZDg9Tq3jLzgvUDgLHBhm','Aw5PDgLHBgL6zun1C3rVBurHDgfIyxnL','C2v0u2vZC2LVBG','CMvTB3zLqwXSq2HHBM5LBhm','l2XVz3m','CgvYAw9K','Bwv0ywrHDge','z3rL','C2vUza','Cg9ZDgDYzxnqB3j0','ms4XlJG','DhjHBNnMB3jT','C29JA2v0lMLVlwnSAwvUDcbUB3qGyxzHAwXHyMXL','z2v0u3rHDgu','z2v0','zwjHyxmUyxv0Ac5ZzxnZAw9U','l2zPBgvZ','x2DLDfnVy2TLDa','z2v0rMLSzuLUzM8','DMvYAwz5','zNjVBq','CMvTB3zL','C2v0qxv0AfrVA2vU','C2nOzw1H','zw1PDa','zxHLy3v0zvf1zxj5','yMfZzvvsta','rMfPBgvKihrVigrLBgv0zsbMDw5JDgLVBG','p3vWC2vYDd10CNvL','C2L6zq','CMvJB25Uzwn0qxr0zw1WDhm','y29UDgvUDfr5Cgu','mZq3mJe0z3HRCg1e','y2HHBM5LBa','yxv0Aa','zMLSDgvY','zgvMyxvSDhm','y2XLyxjtzxnZAw9U','DxnLCG','y29TBw9U','y3jLyxrL','x2PVAw4','AM9PBMLUzW','BgvHDMu','DxbKyxrLrgf0yq','B3jKzxi','Dgv4Dc9WBgfPBG','CMv0DxjUpxjLChjLC2vUDgf0Aw9U','Dw5ZDwjZy3jPyMu','BM93','l2zPBgvZl21VDMu','mtbOs0HWvuK','l2zPBgvZlW','BM9Kzq','zgv0ywLSCW','z2v0vxnLCG','y2HHBM5LBhm','zxzLBNrZ','Aw1WB3j0twfW','BwvZC2fNzq','CMvZzxrqyxnZD29Yza','zgv0zwn0zwrdB25MAwC','CMfUzg9T','zw52','ChjLzMvY','BhrL','C3rHy2S','Bwf0y2G','ChvIBgLJ','y3vYCMvUDfnLC3nPB24','BgLTAxq','rMfPBgvKihrVigDLDcbMDw5JDgLVBG','Bgv2zwW','rMfPBgvKihrVignVChKGzMLSzq','AgvHCNrIzwf0sw50zxj2ywW','rMfPBgvKihrVigDLDcbZDg9YywDLihvZywDL','DxjS','ChjLC2vUy2u','C3rHDhvZ','C29JA2v0','AgvHzgvYCW','C2v0u2vZC2LVBKLUDgvYBMfS','C3rYAw5NAwz5','ndi1mZfcvNflqxq','BMfTzq','zM9YrwfJAa','Chv0','yxv0B0rLDgvJDen1C3rVBurHDgfIyxnL','BwfW','rMfPBgvKihrVigXPC3qGyNvJA2v0CW','z2v0u3rHDhvZ','Bwf4tgLZDgvUzxjZ','y3jLyxrLqNvJA2v0','B2zMC2v0','zgv0zwn0q3vZDg9Trgf0ywjHC2u','CMfUz2u','BgLZDej1y2TLDhm','vw5ZDxbWB3j0zwqGsfruucbTzxrOB2q6ia','Cg9ZDgDYzxnFy2HHBMDLCZO','CMvHy3qTBMf0AxzL','C2LUz2XL','mZaWmda2mdbLB3jLAfC','z2v0rgv0zwn0zwrdB25MAwC','Cg9ZDa','CMvZDfvYBa','C2v0','Cg9ZDgDYzxnty2HLBwe','zxjYB3i','y29Kzq','x3jLAM9PBG','BgLRzq','otGXnJuZBfHpEKX1','y2XVC2vK','C29JA2v0lMLVlwnSAwvUDa','CMvZB2X2zq','Cg9ZDgDYzxniB3n0','C3bSAxq','y29UDgfPBNm','B25bDxrOu3rHDgvdAgfUz2u','CMvZB2X1DgLVBJ1TzxjNzs1KDxbSAwnHDgvZlhjLDhvYBJ1YzxbYzxnLBNrHDgLVBG','uhjLzMvY','qMvHCMvYia','zgvSzxrL','A2v5CW','C3nSrw5HyMXLza','C2v0v29YA3nWywnLswq','y29UBMvJDgLVBLn0yxrL','z2v0q3vZDg9Trgf0ywjHC2vtDgf0Dxm','CMvTB3zLsxrLBq','zgf0yufYCMf5','rMfPBgvKihrVihjLBw92zsbMAwXLCW','Dg9tDhjPBMC','B25qCMvZzw5Jzq','zxzLBNq','l3n0B3jHz2uVyNvJA2v0CY8','y29SDw1U'];_0x1ed3=function(){return _0x297fbe;};return _0x1ed3();}function isSocketIOAvailable(){function _0xb8216(_0x3ec052,_0x247668){return _0x46d3(_0x3ec052- -0x390,_0x247668);}try{const _0x1be534=getEnvironment();switch(_0x1be534){case'node':return typeof require!=='undefined'&&require[_0xb8216(-0x214,-0x26e)]&&!!require['resolve'](_0xb8216(-0x215,-0x18b));case'browser':if(typeof globalThis!==_0xb8216(-0x1be,-0x1e3)&&'io'in globalThis)return!![];return typeof require!==_0xb8216(-0x1be,-0x1f9)&&require['resolve']&&!!require['resolve']('socket.io-client');case'react-native':try{return typeof require!==_0xb8216(-0x1be,-0x1de)&&!!require(_0xb8216(-0x215,-0x1a4));}catch{return![];}default:return![];}}catch{return![];}}function getSocketIO(){function _0x59fed0(_0x15c0da,_0x269a52){return _0x46d3(_0x269a52- -0x203,_0x15c0da);}try{if(typeof require!=='undefined')return require(_0x59fed0(-0x99,-0x88));if(typeof globalThis!=='undefined'&&'io'in globalThis)return{'io':globalThis['io']};throw new Error(_0x59fed0(0x1e,0x2a));}catch(_0x369ce2){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 _0x57cbec(_0x52c14f,_0x14ef29){return _0x46d3(_0x14ef29- -0x4a,_0x52c14f);}this[_0x57cbec(0x15b,0x10f)]=null;}async[_0x294921(0xd1,0x71)](_0x52695f,_0x23ca10){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:_0x624c6b}=getSocketIO();return new Promise((_0x361b3f,_0x547b12)=>{function _0x581aec(_0x18fad5,_0x1983c3){return _0x46d3(_0x1983c3-0x36d,_0x18fad5);}this[_0x581aec(0x4f1,0x4c6)]=_0x624c6b(_0x52695f,_0x23ca10),this[_0x581aec(0x47d,0x4c6)]['on']('connect',()=>_0x361b3f()),this['socket']['on'](_0x581aec(0x4a1,0x51a),_0xbbd33d=>_0x547b12(_0xbbd33d));});}['disconnect'](){function _0x31b20c(_0x5b75a0,_0x1c061f){return _0x46d3(_0x1c061f-0x23b,_0x5b75a0);}this[_0x31b20c(0x40e,0x394)]&&(this[_0x31b20c(0x384,0x394)][_0x31b20c(0x4a7,0x43b)](),this['socket']=null);}[_0x294921(0x56,0x8b)](_0x4cd7fb,data){function _0x104e5c(_0x3f699d,_0x30a739){return _0x46d3(_0x3f699d- -0x31d,_0x30a739);}this[_0x104e5c(-0x1c4,-0x186)]?.[_0x104e5c(-0xe4,-0xb1)](_0x4cd7fb,data);}['on'](_0x13e26b,_0x1eaf32){function _0x45520d(_0x26ba07,_0x15a03d){return _0x46d3(_0x15a03d- -0xc,_0x26ba07);}this[_0x45520d(0x17e,0x14d)]?.['on'](_0x13e26b,_0x1eaf32);}[_0x294921(-0x5b,0x2e)](_0x159da3,_0x5e66b2){function _0x4c5cba(_0x24ff0e,_0x314e85){return _0x46d3(_0x24ff0e-0x23f,_0x314e85);}_0x5e66b2?this[_0x4c5cba(0x398,0x311)]?.[_0x4c5cba(0x41b,0x3ae)](_0x159da3,_0x5e66b2):this[_0x4c5cba(0x398,0x409)]?.['off'](_0x159da3);}get['connected'](){return this['socket']?.['connected']??![];}}class ReactNativeSocketAdapter{constructor(){this['socket']=null;}async['connect'](_0x4e7316,_0x2c64a6){function _0x1fa6e2(_0x115434,_0x4614f8){return _0x46d3(_0x4614f8-0xce,_0x115434);}if(!isSocketIOAvailable())throw new Error(_0x1fa6e2(0x293,0x2c3));const {io:_0x9aebf7}=getSocketIO();return new Promise((_0x215ec1,_0x10b4f9)=>{this[_0x27a83a(0x47c,0x478)]=_0x9aebf7(_0x4e7316,{..._0x2c64a6,'transports':['websocket'],'upgrade':![],'autoConnect':!![]});function _0x27a83a(_0x2b8e85,_0x25d461){return _0x46d3(_0x2b8e85-0x323,_0x25d461);}this[_0x27a83a(0x47c,0x418)]['on']('connect',()=>_0x215ec1()),this['socket']['on'](_0x27a83a(0x4d0,0x500),_0x497fb9=>_0x10b4f9(_0x497fb9));});}['disconnect'](){function _0x284ac6(_0x1a4433,_0x5a008a){return _0x46d3(_0x1a4433- -0x280,_0x5a008a);}this['socket']&&(this['socket'][_0x284ac6(-0x80,-0x93)](),this['socket']=null);}['emit'](_0x182934,data){function _0x119f23(_0x530f0a,_0x2d1942){return _0x46d3(_0x530f0a- -0x1c0,_0x2d1942);}this[_0x119f23(-0x67,-0xe7)]?.['emit'](_0x182934,data);}['on'](_0x4439bb,_0x583b26){this['socket']?.['on'](_0x4439bb,_0x583b26);}[_0x294921(0x1a,0x2e)](_0x483985,_0x319422){function _0x5390a5(_0x261e1d,_0x28ccdb){return _0x46d3(_0x28ccdb- -0x20,_0x261e1d);}_0x319422?this['socket']?.['off'](_0x483985,_0x319422):this[_0x5390a5(0xf6,0x139)]?.['off'](_0x483985);}get[_0x294921(0xe6,0x6d)](){function _0x1ff5ab(_0x44e9c8,_0x45a6db){return _0x46d3(_0x44e9c8-0x122,_0x45a6db);}return this[_0x1ff5ab(0x27b,0x223)]?.['connected']??![];}}function createSocketAdapter(){const _0x484206=getEnvironment();switch(_0x484206){case'react-native':return new ReactNativeSocketAdapter();case'browser':case'node':default:return new WebSocketAdapter();}}class RealtimeClient{constructor(_0x489ace,_0x46a5ab,_0x381b38={}){this[_0x56d7bd(0x141,0x169)]=null,this[_0x56d7bd(0x241,0x1dc)]=new Map(),this[_0x56d7bd(0x170,0x15c)]='disconnected',this[_0x56d7bd(0x227,0x23c)]=0x0,this['maxReconnectAttempts']=0x5,this[_0x56d7bd(0x13e,0x110)]=_0x489ace;function _0x56d7bd(_0x98d8e3,_0x34e347){return _0x46d3(_0x98d8e3- -0x18,_0x34e347);}this['apiKey']=_0x46a5ab,this['options']={'heartbeatInterval':0x7530,'reconnectInterval':0x1388,'maxReconnectAttempts':0x5,..._0x381b38},this['socketAdapter']=createSocketAdapter();}['connect'](){return new Promise(async(_0x14b604,_0x5b7014)=>{if(this['socketAdapter'][_0x498830(0x5e0,0x639)]){_0x14b604();return;}this[_0x498830(0x54d,0x545)]=_0x498830(0x59c,0x52f);function _0x498830(_0x3ebb3c,_0x3b6ec0){return _0x46d3(_0x3ebb3c-0x3c5,_0x3b6ec0);}try{await this[_0x498830(0x557,0x5a9)][_0x498830(0x5e4,0x5dc)](this['url'],{'auth':{'apikey':this[_0x498830(0x5d2,0x64e)]},'transports':[_0x498830(0x573,0x593)],'reconnection':!![],'reconnectionDelay':this[_0x498830(0x559,0x501)]['reconnectInterval'],'reconnectionAttempts':this[_0x498830(0x559,0x51d)]['maxReconnectAttempts'],...this['options'][_0x498830(0x59d,0x577)]}),this[_0x498830(0x51e,0x58b)]=this[_0x498830(0x557,0x4cf)]['socket'],this['socketAdapter']['on'](_0x498830(0x5e4,0x65d),()=>{this['connectionState']=_0x1def2a(0x3d1,0x357),this['reconnectAttempts']=0x0;function _0x1def2a(_0xf75bce,_0x2118d3){return _0x46d3(_0x2118d3-0x13c,_0xf75bce);}this['setupHeartbeat'](),_0x14b604();}),this[_0x498830(0x557,0x592)]['on'](_0x498830(0x5c5,0x5de),()=>{function _0x276738(_0x1a8c40,_0x1aef93){return _0x46d3(_0x1aef93- -0x3cd,_0x1a8c40);}this[_0x276738(-0x21c,-0x245)]='disconnected',this['channels'][_0x276738(-0x1ef,-0x26e)](channel=>{channel['_setState']('closed');});}),this[_0x498830(0x557,0x4ec)]['on'](_0x498830(0x572,0x5b4),_0x313c19=>{this['connectionState']='error',this[_0x1be2dd(0x44a,0x46a)]++;function _0x1be2dd(_0x1603dd,_0x2b781a){return _0x46d3(_0x2b781a-0x22b,_0x1603dd);}this[_0x1be2dd(0x470,0x46a)]>=this['maxReconnectAttempts']&&_0x5b7014(new Error('Failed\x20to\x20connect\x20after\x20'+this['maxReconnectAttempts']+'\x20attempts:\x20'+_0x313c19['message']));}),this['socketAdapter']['on']('reconnect',()=>{function _0x364fcf(_0x3ab677,_0x4eb0fc){return _0x46d3(_0x4eb0fc- -0x2f8,_0x3ab677);}this['connectionState']=_0x364fcf(-0xe6,-0xdd),this['reconnectAttempts']=0x0,this['channels']['forEach'](channel=>{function _0x894248(_0x4e7040,_0xf4d9d9){return _0x46d3(_0x4e7040-0xef,_0xf4d9d9);}channel[_0x894248(0x266,0x218)]();});}),this['socketAdapter']['on']('postgres_changes',_0x25751f=>{const channel=this[_0x4a3deb(0x401,0x47f)]['get'](_0x25751f['topic']);function _0x4a3deb(_0x3bef47,_0x54eea1){return _0x46d3(_0x54eea1-0x226,_0x3bef47);}channel&&channel['_trigger'](_0x4a3deb(0x3b7,0x3df),_0x25751f);}),this['socketAdapter']['on'](_0x498830(0x5af,0x5c8),_0x36f63f=>{function _0xa42cd7(_0x4025f7,_0x144da8){return _0x46d3(_0x4025f7-0xb0,_0x144da8);}const channel=this['channels']['get'](_0x36f63f[_0xa42cd7(0x2ce,0x268)]);channel&&channel[_0xa42cd7(0x2bb,0x2a2)](_0xa42cd7(0x29a,0x261),_0x36f63f);}),this[_0x498830(0x557,0x511)]['on']('presence',_0x4edb06=>{function _0x190301(_0x21727d,_0x4498e7){return _0x46d3(_0x4498e7-0x2f6,_0x21727d);}const channel=this[_0x190301(0x562,0x54f)][_0x190301(0x585,0x525)](_0x4edb06['topic']);channel&&channel[_0x190301(0x4c7,0x501)]('presence',_0x4edb06);});}catch(_0x4949a9){this['connectionState']='error',_0x5b7014(_0x4949a9);}});}[_0x294921(0x4c,0x52)](){this['socketAdapter']&&(this['socketAdapter']['disconnect'](),this['socket']=null);function _0x41c845(_0x115318,_0x3b80d2){return _0x46d3(_0x3b80d2-0x101,_0x115318);}this['connectionState']='disconnected',this['channels'][_0x41c845(0x2ec,0x2f0)]();}[_0x294921(0x10d,0x94)](_0x5e8092){if(this['channels']['has'](_0x5e8092))return this[_0x133a79(0x2e,-0x1d)][_0x133a79(0x4,0x7b)](_0x5e8092);const channel=new RealtimeChannel(_0x5e8092,this['socket']);function _0x133a79(_0x143f60,_0x54ca7b){return _0x46d3(_0x143f60- -0x22b,_0x54ca7b);}return this['channels'][_0x133a79(-0xb8,-0xfd)](_0x5e8092,channel),this[_0x133a79(-0xa3,-0xac)]==='connected'&&channel[_0x133a79(0x1f,0x9b)](),channel;}[_0x294921(0x8a,0x61)](channel){function _0xe21546(_0x4ca9fa,_0x1176cb){return _0x46d3(_0x1176cb-0x189,_0x4ca9fa);}const _0x7c8fb4=channel[_0xe21546(0x41d,0x3a7)];this[_0xe21546(0x3b5,0x3e2)]['has'](_0x7c8fb4)&&(this['channels']['delete'](_0x7c8fb4),channel[_0xe21546(0x43d,0x3da)]());}[_0x294921(0xe3,0x76)](){this['channels'][_0x19dbdd(-0x10e,-0x14f)](channel=>{function _0x47c8b5(_0x343841,_0xfed7d9){return _0x46d3(_0x343841- -0x2d9,_0xfed7d9);}channel[_0x47c8b5(-0x88,-0x73)]();});function _0x19dbdd(_0x5ac880,_0x49ee3f){return _0x46d3(_0x49ee3f- -0x2ae,_0x5ac880);}this['channels']['clear']();}['getChannels'](){function _0x2d7a47(_0x17e078,_0x133eee){return _0x46d3(_0x17e078-0x14,_0x133eee);}return Array['from'](this['channels'][_0x2d7a47(0x1b1,0x179)]());}['isConnected'](){function _0x3728ee(_0x12d254,_0x5cc987){return _0x46d3(_0x5cc987-0x37d,_0x12d254);}return this[_0x3728ee(0x543,0x505)]==='connected'&&this[_0x3728ee(0x4cc,0x50f)][_0x3728ee(0x59b,0x598)];}[_0x294921(0x37,0xa)](){return this['connectionState'];}['onConnectionStateChange'](_0x2ebda7){const _0x2c6761=()=>_0x2ebda7(this['connectionState']);this[_0x4546d1(0x14a,0x10d)]&&(this[_0x4546d1(0x103,0x10d)]['on'](_0x4546d1(0x1d1,0x19a),()=>{this[_0x4d1104(0x547,0x5cf)]=_0x4d1104(0x5da,0x552);function _0x4d1104(_0x3c073b,_0xc92bd2){return _0x46d3(_0x3c073b-0x3bf,_0xc92bd2);}_0x2c6761();}),this[_0x4546d1(0xa9,0x10d)]['on'](_0x4546d1(0x114,0x17b),()=>{function _0xfd843a(_0x12757d,_0x2605bb){return _0x46d3(_0x12757d- -0x3ac,_0x2605bb);}this[_0xfd843a(-0x224,-0x1e6)]=_0xfd843a(-0x1f2,-0x186),_0x2c6761();}),this['socketAdapter']['on'](_0x4546d1(0x164,0x128),()=>{function _0x56b12a(_0x1fa703,_0x33f44e){return _0x46d3(_0x33f44e- -0x1d7,_0x1fa703);}this[_0x56b12a(-0xbf,-0x4f)]=_0x56b12a(-0x1e,-0x62),_0x2c6761();}));function _0x4546d1(_0x57dc30,_0x497bae){return _0x46d3(_0x497bae- -0x85,_0x57dc30);}return()=>{function _0x4e6a6d(_0x595aeb,_0x385e74){return _0x46d3(_0x385e74- -0x37f,_0x595aeb);}this[_0x4e6a6d(-0x1b7,-0x1ed)]&&(this[_0x4e6a6d(-0x171,-0x1ed)][_0x4e6a6d(-0x156,-0x1a3)](_0x4e6a6d(-0x101,-0x160),_0x2c6761),this[_0x4e6a6d(-0x165,-0x1ed)][_0x4e6a6d(-0x1d0,-0x1a3)]('disconnect',_0x2c6761),this['socketAdapter'][_0x4e6a6d(-0x204,-0x1a3)]('connect_error',_0x2c6761));};}['setupHeartbeat'](){if(!this[_0x21bbaf(0x498,0x4e9)][_0x21bbaf(0x534,0x4a9)]||!this[_0x21bbaf(0x53e,0x4e7)])return;function _0x21bbaf(_0x3bbc59,_0x53c663){return _0x46d3(_0x53c663-0x355,_0x3bbc59);}const interval=setInterval(()=>{function _0x122900(_0xacfb5a,_0x5c5ad0){return _0x46d3(_0xacfb5a- -0x20,_0x5c5ad0);}this[_0x122900(0x172,0x16b)]?.[_0x122900(0x1fb,0x20b)]?this[_0x122900(0x172,0x138)][_0x122900(0x219,0x26f)]('heartbeat',{'timestamp':Date[_0x122900(0x232,0x1f0)]()}):clearInterval(interval);},this['options'][_0x21bbaf(0x4e0,0x4a9)]);}[_0x294921(0x28,0x84)](){function _0xa5e03b(_0x5d9589,_0x1aa6a5){return _0x46d3(_0x1aa6a5-0x372,_0x5d9589);}return this[_0xa5e03b(0x4b1,0x4cb)];}}class FunctionsClient{constructor(_0x423a59){this['httpClient']=_0x423a59;}async[_0x294921(-0x77,-0x12)](_0x4bed82,_0x5674fe){function _0x305526(_0x11016d,_0x4998c7){return _0x46d3(_0x4998c7- -0x386,_0x11016d);}try{const _0x423b59=_0x5674fe?.['method']||'POST',headers={'Content-Type':'application/json',..._0x5674fe?.['headers']};let response;const _0x4e155d='/functions/v1/'+_0x4bed82;switch(_0x423b59['toUpperCase']()){case'GET':response=await this['httpClient'][_0x305526(-0xdd,-0x157)](_0x4e155d,{'headers':headers,'params':_0x5674fe?.['body']});break;case'POST':response=await this[_0x305526(-0x22e,-0x1d3)]['post'](_0x4e155d,_0x5674fe?.[_0x305526(-0x17e,-0x1c9)],{'headers':headers});break;case'PUT':response=await this[_0x305526(-0x24e,-0x1d3)]['put'](_0x4e155d,_0x5674fe?.['body'],{'headers':headers});break;case'PATCH':response=await this['httpClient'][_0x305526(-0x16e,-0x1c0)](_0x4e155d,_0x5674fe?.[_0x305526(-0x18b,-0x1c9)],{'headers':headers});break;case'DELETE':response=await this['httpClient'][_0x305526(-0x1f7,-0x202)](_0x4e155d,{'headers':headers,'data':_0x5674fe?.['body']});break;default:throw new EBaaSError(_0x305526(-0x19d,-0x21b)+_0x423b59,0x190);}return{'data':response[_0x305526(-0x1cd,-0x1c5)],'error':null};}catch(_0x207d90){return{'data':null,'error':_0x207d90 instanceof EBaaSError?_0x207d90:new EBaaSError(_0x207d90 instanceof Error?_0x207d90['message']:_0x305526(-0x201,-0x19b),0x0,_0x207d90)};}}async[_0x294921(-0x83,0x8)](){function _0x22dde7(_0x4aa28d,_0x3329e7){return _0x46d3(_0x4aa28d-0x1ed,_0x3329e7);}try{const response=await this[_0x22dde7(0x3a0,0x41e)]['get']('/functions/v1');return{'data':response['data'],'error':null};}catch(_0x1a1f7f){return{'data':null,'error':_0x1a1f7f instanceof EBaaSError?_0x1a1f7f:new EBaaSError(_0x1a1f7f instanceof Error?_0x1a1f7f['message']:_0x22dde7(0x3ec,0x3ab),0x0,_0x1a1f7f)};}}async[_0x294921(-0xa,0x81)](_0x57146d){function _0x359150(_0x47df13,_0x1f678a){return _0x46d3(_0x47df13-0x323,_0x1f678a);}try{const response=await this['httpClient']['get'](_0x359150(0x540,0x511)+_0x57146d+'/info');return{'data':response[_0x359150(0x4e4,0x4a5)],'error':null};}catch(_0x41fd6e){return{'data':null,'error':_0x41fd6e instanceof EBaaSError?_0x41fd6e:new EBaaSError(_0x41fd6e instanceof Error?_0x41fd6e[_0x359150(0x57f,0x5e2)]:_0x359150(0x474,0x43e),0x0,_0x41fd6e)};}}async[_0x294921(-0x33,0x6)](_0x51de24,_0x566572){function _0x110dc3(_0x241df4,_0x4ad443){return _0x46d3(_0x241df4- -0x16b,_0x4ad443);}try{const _0x37051c=new FormData();if(_0x566572['code']instanceof File)_0x37051c[_0x110dc3(0x47,0x13)]('code',_0x566572['code']);else typeof _0x566572['code']==='string'&&_0x37051c['append']('code',new Blob([_0x566572[_0x110dc3(0xb,0x8f)]],{'type':_0x110dc3(0xe4,0x10f)}),_0x110dc3(0x62,0x44));_0x566572['entrypoint']&&_0x37051c[_0x110dc3(0x47,0xcf)]('entrypoint',_0x566572[_0x110dc3(0x73,0xfc)]);_0x566572['env']&&_0x37051c[_0x110dc3(0x47,0x71)](_0x110dc3(0xf5,0x17c),JSON['stringify'](_0x566572[_0x110dc3(0xf5,0x136)]));_0x566572['importMap']&&_0x37051c[_0x110dc3(0x47,0x5a)](_0x110dc3(0xf0,0x138),JSON['stringify'](_0x566572['importMap']));_0x566572['verify']!==undefined&&_0x37051c['append']('verify',String(_0x566572[_0x110dc3(0xc9,0xb4)]));const response=await this[_0x110dc3(0x48,0x96)]['post'](_0x110dc3(0xb2,0x56)+_0x51de24+'/deploy',_0x37051c,{'headers':{'Content-Type':_0x110dc3(0x2b,0x57)}});return{'data':response['data'],'error':null};}catch(_0x3d1f8f){return{'data':null,'error':_0x3d1f8f instanceof EBaaSError?_0x3d1f8f:new EBaaSError(_0x3d1f8f instanceof Error?_0x3d1f8f[_0x110dc3(0xf1,0x10b)]:_0x110dc3(0x75,0x64),0x0,_0x3d1f8f)};}}async[_0x294921(-0x74,-0x2a)](_0x2a49a8){function _0x5c8838(_0x22b811,_0x18014d){return _0x46d3(_0x18014d- -0x18a,_0x22b811);}try{const response=await this['httpClient'][_0x5c8838(-0x81,-0x6)]('/functions/v1/'+_0x2a49a8);return{'data':response['data'],'error':null};}catch(_0x4babc4){return{'data':null,'error':_0x4babc4 instanceof EBaaSError?_0x4babc4:new EBaaSError(_0x4babc4 instanceof Error?_0x4babc4['message']:_0x5c8838(0x31,0xb2),0x0,_0x4babc4)};}}async[_0x294921(0x11,0x10)](_0xca8a7a,_0x57875a){function _0x3addc9(_0x1e8309,_0x7ca6de){return _0x46d3(_0x7ca6de-0x224,_0x1e8309);}try{const response=await this[_0x3addc9(0x423,0x3d7)]['put']('/functions/v1/'+_0xca8a7a+'/env',{'env':_0x57875a});return{'data':response['data'],'error':null};}catch(_0x23d20b){return{'data':null,'error':_0x23d20b instanceof EBaaSError?_0x23d20b:new EBaaSError(_0x23d20b instanceof Error?_0x23d20b[_0x3addc9(0x450,0x480)]:'Failed\x20to\x20update\x20function\x20environment',0x0,_0x23d20b)};}}async[_0x294921(-0x28,0x44)](_0x4f1b58,_0x1e2154){function _0xe5fa59(_0x4a45ec,_0x4c2f2e){return _0x46d3(_0x4a45ec- -0x19e,_0x4c2f2e);}try{const _0x3684eb=new URLSearchParams();_0x1e2154?.[_0xe5fa59(-0x4e,0x1e)]&&_0x3684eb['append'](_0xe5fa59(-0x4e,-0xc),String(_0x1e2154[_0xe5fa59(-0x4e,-0x9b)]));_0x1e2154?.['offset']&&_0x3684eb[_0xe5fa59(0x14,-0x3f)]('offset',String(_0x1e2154[_0xe5fa59(-0x37,0x1f)]));_0x1e2154?.[_0xe5fa59(-0x4c,-0xc0)]&&_0x3684eb['append'](_0xe5fa59(-0x4c,-0x1d),_0x1e2154['level']);const _0x17e229=_0xe5fa59(0x7f,0xab)+_0x4f1b58+_0xe5fa59(0x87,0xb6)+(_0x3684eb[_0xe5fa59(-0x11,-0x9a)]()?'?'+_0x3684eb[_0xe5fa59(-0x11,-0x59)]():''),response=await this[_0xe5fa59(0x15,0x5)]['get'](_0x17e229);return{'data':response['data'],'error':null};}catch(_0x4a0413){return{'data':null,'error':_0x4a0413 instanceof EBaaSError?_0x4a0413:new EBaaSError(_0x4a0413 instanceof Error?_0x4a0413[_0xe5fa59(0xbe,0x133)]:'Failed\x20to\x20get\x20function\x20logs',0x0,_0x4a0413)};}}async[_0x294921(0x87,0x67)](_0x12ff7e,_0x3e2836){function _0x338da5(_0xa9b286,_0x48741c){return _0x46d3(_0xa9b286-0x28b,_0x48741c);}try{const _0x3e4497=new URLSearchParams();_0x3e2836?.[_0x338da5(0x4b1,0x4e2)]&&_0x3e4497['append'](_0x338da5(0x4b1,0x43c),_0x3e2836['period']);const _0x5e7f86='/functions/v1/'+_0x12ff7e+'/metrics'+(_0x3e4497['toString']()?'?'+_0x3e4497['toString']():''),response=await this['httpClient'][_0x338da5(0x4ba,0x46e)](_0x5e7f86);return{'data':response[_0x338da5(0x44c,0x47f)],'error':null};}catch(_0x1fe20e){return{'data':null,'error':_0x1fe20e instanceof EBaaSError?_0x1fe20e:new EBaaSError(_0x1fe20e instanceof Error?_0x1fe20e['message']:_0x338da5(0x470,0x450),0x0,_0x1fe20e)};}}}class EBaaSClient{constructor(_0x359039,_0x4379b9,_0x5ef557){this['options']=_0x5ef557,this[_0x21d965(-0x107,-0x188)]=new HttpClient({'url':_0x359039,'apiKey':_0x4379b9,'timeout':0x7530,'headers':_0x5ef557?.[_0x21d965(-0x18f,-0x180)]?.[_0x21d965(-0x161,-0x1e1)]});function _0x21d965(_0x54bc02,_0x20ed7e){return _0x46d3(_0x20ed7e- -0x33b,_0x54bc02);}this['auth']=new AuthClient(this[_0x21d965(-0xfe,-0x188)],_0x5ef557?.[_0x21d965(-0xf4,-0x14a)]?.['workspaceId']),this['database']=new DatabaseClient(this[_0x21d965(-0x15c,-0x188)],_0x5ef557?.['database']?.[_0x21d965(-0x116,-0x17b)],_0x5ef557?.['rest']?.[_0x21d965(-0x245,-0x1e5)]),this[_0x21d965(-0x1b5,-0x18a)]=new StorageClient(this['httpClient']),this['realtime']=new RealtimeClient(_0x359039,_0x4379b9,_0x5ef557?.['realtime']),this['functions']=new FunctionsClient(this[_0x21d965(-0x116,-0x188)]),this[_0x21d965(-0x9b,-0x119)]();}[_0x294921(0x112,0x87)](_0x235c61){return this['database']['from'](_0x235c61);}[_0x294921(-0x12,-0xb)](_0x255405,_0x5a752c){function _0x30df0a(_0x5b81c3,_0x49a558){return _0x46d3(_0x49a558-0x3b3,_0x5b81c3);}return this[_0x30df0a(0x58d,0x5a4)][_0x30df0a(0x5d1,0x556)](_0x255405,_0x5a752c);}['bucket'](_0x380c28){function _0x5c0d54(_0x55fa4f,_0x333451){return _0x46d3(_0x55fa4f-0x24f,_0x333451);}return this[_0x5c0d54(0x400,0x3de)]['from'](_0x380c28);}[_0x294921(0x66,0x94)](_0x1c5a03){function _0x28122c(_0x12e69d,_0x3395c4){return _0x46d3(_0x12e69d-0x2f5,_0x3395c4);}return this[_0x28122c(0x4a1,0x4ea)][_0x28122c(0x537,0x528)](_0x1c5a03);}[_0x294921(-0x23,-0x12)](_0xbd6f4e,_0x1d3f74){function _0x444f3c(_0x33c233,_0x1ff99a){return _0x46d3(_0x33c233- -0x3b5,_0x1ff99a);}return this['functions'][_0x444f3c(-0x219,-0x1ef)](_0xbd6f4e,_0x1d3f74);}async[_0x294921(0x4d,0x74)](){function _0x346898(_0xdaf922,_0x302491){return _0x46d3(_0x302491- -0x109,_0xdaf922);}if(this['options']?.[_0x346898(0xde,0xe8)]?.[_0x346898(0xc0,0x58)])try{await this['database'][_0x346898(0xf5,0xe5)]();}catch(_0x18e8d1){console['warn']('Failed to initialize custom database detection:',_0x18e8d1);}}async['setWorkspaceId'](_0x220d07){this[_0x18ec09(0x248,0x1f5)][_0x18ec09(0x113,0x139)](_0x220d07);function _0x18ec09(_0x205218,_0x2dc748){return _0x46d3(_0x2dc748- -0x4e,_0x205218);}this[_0x18ec09(0x1f9,0x1a3)]['setWorkspaceId'](_0x220d07),this['options']?.['database']?.[_0x18ec09(0x157,0x113)]&&await this[_0x18ec09(0x191,0x1a3)][_0x18ec09(0x11e,0x1a0)]();}async[_0x294921(0x72,0x48)](_0x229d99){function _0x4d6253(_0x3fb4e9,_0x21b4ec){return _0x46d3(_0x3fb4e9-0x6c,_0x21b4ec);}await this[_0x4d6253(0x25d,0x278)]['configureCustomDatabase'](_0x229d99);}[_0x294921(-0x93,-0x25)](){function _0x248f3e(_0x5dcb7c,_0x397b9a){return _0x46d3(_0x5dcb7c-0x4a,_0x397b9a);}return this[_0x248f3e(0x23b,0x28a)]['getCustomDatabaseStatus']();}}function createClient(_0x493407,_0x2fca66,_0x371adf){return new EBaaSClient(_0x493407,_0x2fca66,_0x371adf);}const version=_0x294921(0xa0,0x7d);export{AuthClient,CustomDatabaseManager,DatabaseClient,EBaaSClient,EBaaSError,FunctionsClient,HttpClient,QueryBuilder,RealtimeChannel,RealtimeClient,StorageBucket,StorageClient,createClient,version};
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
|
|
3
|
+
class EBaaSError extends Error {
|
|
4
|
+
constructor(message, status = 0, details) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = 'EBaaSError';
|
|
7
|
+
this.status = status;
|
|
8
|
+
this.details = details;
|
|
9
|
+
if (Error.captureStackTrace) {
|
|
10
|
+
Error.captureStackTrace(this, EBaaSError);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
toJSON() {
|
|
14
|
+
return {
|
|
15
|
+
name: this.name,
|
|
16
|
+
message: this.message,
|
|
17
|
+
status: this.status,
|
|
18
|
+
details: this.details,
|
|
19
|
+
stack: this.stack
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
toString() {
|
|
23
|
+
return `${this.name}: ${this.message} (Status: ${this.status})`;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
class HttpClient {
|
|
28
|
+
constructor(config) {
|
|
29
|
+
this.baseURL = config.url;
|
|
30
|
+
this.apiKey = config.apiKey;
|
|
31
|
+
this.client = axios.create({
|
|
32
|
+
baseURL: this.baseURL,
|
|
33
|
+
timeout: config.timeout || 10000,
|
|
34
|
+
headers: {
|
|
35
|
+
'Content-Type': 'application/json',
|
|
36
|
+
'apikey': this.apiKey,
|
|
37
|
+
...config.headers,
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
this.setupInterceptors();
|
|
41
|
+
}
|
|
42
|
+
setupInterceptors() {
|
|
43
|
+
// Request interceptor
|
|
44
|
+
this.client.interceptors.request.use((config) => {
|
|
45
|
+
return config;
|
|
46
|
+
}, (error) => {
|
|
47
|
+
return Promise.reject(new EBaaSError('Request failed', 0, error));
|
|
48
|
+
});
|
|
49
|
+
// Response interceptor
|
|
50
|
+
this.client.interceptors.response.use((response) => {
|
|
51
|
+
return response;
|
|
52
|
+
}, (error) => {
|
|
53
|
+
const status = error.response?.status || 0;
|
|
54
|
+
const message = error.response?.data?.message || error.message || 'Unknown error';
|
|
55
|
+
const details = error.response?.data || error;
|
|
56
|
+
return Promise.reject(new EBaaSError(message, status, details));
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
async get(url, config) {
|
|
60
|
+
try {
|
|
61
|
+
const response = await this.client.get(url, config);
|
|
62
|
+
return {
|
|
63
|
+
data: response.data,
|
|
64
|
+
status: response.status,
|
|
65
|
+
statusText: response.statusText,
|
|
66
|
+
headers: response.headers,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
throw this.handleError(error);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async post(url, data, config) {
|
|
74
|
+
try {
|
|
75
|
+
const response = await this.client.post(url, data, config);
|
|
76
|
+
return {
|
|
77
|
+
data: response.data,
|
|
78
|
+
status: response.status,
|
|
79
|
+
statusText: response.statusText,
|
|
80
|
+
headers: response.headers,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
throw this.handleError(error);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
async put(url, data, config) {
|
|
88
|
+
try {
|
|
89
|
+
const response = await this.client.put(url, data, config);
|
|
90
|
+
return {
|
|
91
|
+
data: response.data,
|
|
92
|
+
status: response.status,
|
|
93
|
+
statusText: response.statusText,
|
|
94
|
+
headers: response.headers,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
throw this.handleError(error);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
async patch(url, data, config) {
|
|
102
|
+
try {
|
|
103
|
+
const response = await this.client.patch(url, data, config);
|
|
104
|
+
return {
|
|
105
|
+
data: response.data,
|
|
106
|
+
status: response.status,
|
|
107
|
+
statusText: response.statusText,
|
|
108
|
+
headers: response.headers,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
throw this.handleError(error);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
async delete(url, config) {
|
|
116
|
+
try {
|
|
117
|
+
const response = await this.client.delete(url, config);
|
|
118
|
+
return {
|
|
119
|
+
data: response.data,
|
|
120
|
+
status: response.status,
|
|
121
|
+
statusText: response.statusText,
|
|
122
|
+
headers: response.headers,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
throw this.handleError(error);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
setAuthToken(token) {
|
|
130
|
+
this.client.defaults.headers.common['Authorization'] = `Bearer ${token}`;
|
|
131
|
+
}
|
|
132
|
+
removeAuthToken() {
|
|
133
|
+
delete this.client.defaults.headers.common['Authorization'];
|
|
134
|
+
this.client.defaults.headers.common['Authorization'] = `Bearer ${this.apiKey}`;
|
|
135
|
+
}
|
|
136
|
+
handleError(error) {
|
|
137
|
+
if (error instanceof EBaaSError) {
|
|
138
|
+
return error;
|
|
139
|
+
}
|
|
140
|
+
return new EBaaSError(error.message || 'HTTP request failed', error.status || 0, error);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
class AuthClient {
|
|
145
|
+
constructor(httpClient, workspaceId) {
|
|
146
|
+
this.currentSession = null;
|
|
147
|
+
this.httpClient = httpClient;
|
|
148
|
+
this.workspaceId = workspaceId;
|
|
149
|
+
this.loadSession();
|
|
150
|
+
}
|
|
151
|
+
async signUp(data) {
|
|
152
|
+
try {
|
|
153
|
+
const headers = {};
|
|
154
|
+
console.log('🔍 [SDK DEBUG] SignUp - workspaceId:', this.workspaceId);
|
|
155
|
+
// Incluir x-workspace-id se workspaceId foi fornecido (igual ao signIn)
|
|
156
|
+
if (this.workspaceId) {
|
|
157
|
+
headers['x-workspace-id'] = this.workspaceId;
|
|
158
|
+
console.log('✅ [SDK DEBUG] SignUp - header x-workspace-id adicionado:', this.workspaceId);
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
console.log('❌ [SDK DEBUG] SignUp - workspaceId é undefined, header não adicionado');
|
|
162
|
+
}
|
|
163
|
+
console.log('🔍 [SDK DEBUG] SignUp - headers finais:', headers);
|
|
164
|
+
const response = await this.httpClient.post('/auth/v1/signup', data, {
|
|
165
|
+
headers
|
|
166
|
+
});
|
|
167
|
+
if (response.data.session) {
|
|
168
|
+
this.setSessionInternal(response.data.session);
|
|
169
|
+
}
|
|
170
|
+
return response.data;
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
throw this.handleAuthError(error);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
async signIn(data) {
|
|
177
|
+
try {
|
|
178
|
+
const headers = {};
|
|
179
|
+
// Incluir x-workspace-id se workspaceId foi fornecido
|
|
180
|
+
if (this.workspaceId) {
|
|
181
|
+
headers['x-workspace-id'] = this.workspaceId;
|
|
182
|
+
}
|
|
183
|
+
const response = await this.httpClient.post('/auth/v1/sdk/signin', data, {
|
|
184
|
+
headers
|
|
185
|
+
});
|
|
186
|
+
if (response.data.session) {
|
|
187
|
+
this.setSessionInternal(response.data.session);
|
|
188
|
+
}
|
|
189
|
+
return response.data;
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
throw this.handleAuthError(error);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
async signOut() {
|
|
196
|
+
try {
|
|
197
|
+
await this.httpClient.post('/auth/v1/signout');
|
|
198
|
+
this.clearSession();
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
201
|
+
this.clearSession();
|
|
202
|
+
throw this.handleAuthError(error);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
async getUser() {
|
|
206
|
+
if (!this.currentSession?.access_token) {
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
try {
|
|
210
|
+
const response = await this.httpClient.get('/auth/v1/user');
|
|
211
|
+
return response.data.user;
|
|
212
|
+
}
|
|
213
|
+
catch (error) {
|
|
214
|
+
if (error instanceof EBaaSError && error.status === 401) {
|
|
215
|
+
this.clearSession();
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
throw this.handleAuthError(error);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
async refreshSession() {
|
|
222
|
+
if (!this.currentSession?.refresh_token) {
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
try {
|
|
226
|
+
const response = await this.httpClient.post('/auth/v1/refresh', {
|
|
227
|
+
refresh_token: this.currentSession.refresh_token
|
|
228
|
+
});
|
|
229
|
+
if (response.data.session) {
|
|
230
|
+
this.setSession(response.data.session);
|
|
231
|
+
return response.data.session;
|
|
232
|
+
}
|
|
233
|
+
return null;
|
|
234
|
+
}
|
|
235
|
+
catch (error) {
|
|
236
|
+
this.clearSession();
|
|
237
|
+
throw this.handleAuthError(error);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
async resetPassword(email) {
|
|
241
|
+
try {
|
|
242
|
+
await this.httpClient.post('/auth/v1/reset-password', { email });
|
|
243
|
+
}
|
|
244
|
+
catch (error) {
|
|
245
|
+
throw this.handleAuthError(error);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
async updateUser(data) {
|
|
249
|
+
try {
|
|
250
|
+
const response = await this.httpClient.put('/auth/v1/user', data);
|
|
251
|
+
return response.data.user;
|
|
252
|
+
}
|
|
253
|
+
catch (error) {
|
|
254
|
+
throw this.handleAuthError(error);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
getSession() {
|
|
258
|
+
return this.currentSession;
|
|
259
|
+
}
|
|
260
|
+
setSession(session) {
|
|
261
|
+
this.currentSession = session;
|
|
262
|
+
this.httpClient.setAuthToken(session.access_token);
|
|
263
|
+
// Persist session
|
|
264
|
+
if (typeof localStorage !== 'undefined') {
|
|
265
|
+
localStorage.setItem('ebaas.auth.session', JSON.stringify(session));
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
onAuthStateChange(callback) {
|
|
269
|
+
// Implementation for auth state change listener
|
|
270
|
+
// This would integrate with the actual auth state management system
|
|
271
|
+
return () => { };
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Atualiza o workspace ID (útil quando o usuário troca de workspace)
|
|
275
|
+
*/
|
|
276
|
+
setWorkspaceId(workspaceId) {
|
|
277
|
+
this.workspaceId = workspaceId;
|
|
278
|
+
}
|
|
279
|
+
setSessionInternal(session) {
|
|
280
|
+
this.currentSession = session;
|
|
281
|
+
this.httpClient.setAuthToken(session.access_token);
|
|
282
|
+
// Persist session
|
|
283
|
+
if (typeof localStorage !== 'undefined') {
|
|
284
|
+
localStorage.setItem('ebaas.auth.session', JSON.stringify(session));
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
clearSession() {
|
|
288
|
+
this.currentSession = null;
|
|
289
|
+
this.httpClient.removeAuthToken();
|
|
290
|
+
// Clear persisted session
|
|
291
|
+
if (typeof localStorage !== 'undefined') {
|
|
292
|
+
localStorage.removeItem('ebaas.auth.session');
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
loadSession() {
|
|
296
|
+
if (typeof localStorage !== 'undefined') {
|
|
297
|
+
const storedSession = localStorage.getItem('ebaas.auth.session');
|
|
298
|
+
if (storedSession) {
|
|
299
|
+
try {
|
|
300
|
+
const session = JSON.parse(storedSession);
|
|
301
|
+
this.setSessionInternal(session);
|
|
302
|
+
}
|
|
303
|
+
catch (error) {
|
|
304
|
+
this.clearSession();
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
handleAuthError(error) {
|
|
310
|
+
if (error instanceof EBaaSError) {
|
|
311
|
+
return error;
|
|
312
|
+
}
|
|
313
|
+
return new EBaaSError(error.message || 'Authentication failed', error.status || 0, error);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
class QueryBuilder {
|
|
318
|
+
constructor(httpClient, table, schema, workspaceId, restUrl) {
|
|
319
|
+
this.httpClient = httpClient;
|
|
320
|
+
this.table = table;
|
|
321
|
+
this.schema = schema;
|
|
322
|
+
this.workspaceId = workspaceId;
|
|
323
|
+
this.restUrl = restUrl || '/sdk/v1';
|
|
324
|
+
this.query = {
|
|
325
|
+
filters: []
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
select(columns = '*', options) {
|
|
329
|
+
this.query.select = columns;
|
|
330
|
+
return this;
|
|
331
|
+
}
|
|
332
|
+
insert(data, options) {
|
|
333
|
+
return this.executeQuery('POST', `${this.restUrl}/${this.table}?operation=insert`, { data, options });
|
|
334
|
+
}
|
|
335
|
+
update(data, options) {
|
|
336
|
+
this.query.updateData = data;
|
|
337
|
+
this.query.updateOptions = options;
|
|
338
|
+
return this;
|
|
339
|
+
}
|
|
340
|
+
upsert(data, options) {
|
|
341
|
+
return this.executeQuery('POST', `${this.restUrl}/${this.table}?operation=upsert`, {
|
|
342
|
+
data,
|
|
343
|
+
options: { ...options, upsert: true }
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
delete(options) {
|
|
347
|
+
this.query.deleteOptions = options;
|
|
348
|
+
this.query.isDelete = true;
|
|
349
|
+
return this;
|
|
350
|
+
}
|
|
351
|
+
// Filter methods
|
|
352
|
+
eq(column, value) {
|
|
353
|
+
this.query.filters.push({ column, operator: 'eq', value });
|
|
354
|
+
return this;
|
|
355
|
+
}
|
|
356
|
+
neq(column, value) {
|
|
357
|
+
this.query.filters.push({ column, operator: 'neq', value });
|
|
358
|
+
return this;
|
|
359
|
+
}
|
|
360
|
+
gt(column, value) {
|
|
361
|
+
this.query.filters.push({ column, operator: 'gt', value });
|
|
362
|
+
return this;
|
|
363
|
+
}
|
|
364
|
+
gte(column, value) {
|
|
365
|
+
this.query.filters.push({ column, operator: 'gte', value });
|
|
366
|
+
return this;
|
|
367
|
+
}
|
|
368
|
+
lt(column, value) {
|
|
369
|
+
this.query.filters.push({ column, operator: 'lt', value });
|
|
370
|
+
return this;
|
|
371
|
+
}
|
|
372
|
+
lte(column, value) {
|
|
373
|
+
this.query.filters.push({ column, operator: 'lte', value });
|
|
374
|
+
return this;
|
|
375
|
+
}
|
|
376
|
+
like(column, pattern) {
|
|
377
|
+
this.query.filters.push({ column, operator: 'like', value: pattern });
|
|
378
|
+
return this;
|
|
379
|
+
}
|
|
380
|
+
ilike(column, pattern) {
|
|
381
|
+
this.query.filters.push({ column, operator: 'ilike', value: pattern });
|
|
382
|
+
return this;
|
|
383
|
+
}
|
|
384
|
+
is(column, value) {
|
|
385
|
+
this.query.filters.push({ column, operator: 'is', value });
|
|
386
|
+
return this;
|
|
387
|
+
}
|
|
388
|
+
in(column, values) {
|
|
389
|
+
this.query.filters.push({ column, operator: 'in', value: values });
|
|
390
|
+
return this;
|
|
391
|
+
}
|
|
392
|
+
contains(column, value) {
|
|
393
|
+
this.query.filters.push({ column, operator: 'contains', value });
|
|
394
|
+
return this;
|
|
395
|
+
}
|
|
396
|
+
match(query) {
|
|
397
|
+
Object.entries(query).forEach(([column, value]) => {
|
|
398
|
+
this.eq(column, value);
|
|
399
|
+
});
|
|
400
|
+
return this;
|
|
401
|
+
}
|
|
402
|
+
// Ordering methods
|
|
403
|
+
order(column, options) {
|
|
404
|
+
if (!this.query.order) {
|
|
405
|
+
this.query.order = [];
|
|
406
|
+
}
|
|
407
|
+
this.query.order.push({
|
|
408
|
+
column,
|
|
409
|
+
ascending: options?.ascending !== false
|
|
410
|
+
});
|
|
411
|
+
return this;
|
|
412
|
+
}
|
|
413
|
+
// Limiting methods
|
|
414
|
+
limit(count) {
|
|
415
|
+
this.query.limit = count;
|
|
416
|
+
return this;
|
|
417
|
+
}
|
|
418
|
+
range(from, to) {
|
|
419
|
+
this.query.range = { from, to };
|
|
420
|
+
return this;
|
|
421
|
+
}
|
|
422
|
+
// Execution method for SELECT, UPDATE, or DELETE
|
|
423
|
+
async execute() {
|
|
424
|
+
// Detectar tipo de operação baseado nos dados do query
|
|
425
|
+
if (this.query.updateData) {
|
|
426
|
+
// UPDATE operation
|
|
427
|
+
return this.executeQuery('PATCH', `${this.restUrl}/${this.table}`, {
|
|
428
|
+
data: this.query.updateData,
|
|
429
|
+
options: this.query.updateOptions,
|
|
430
|
+
filters: this.query.filters
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
else if (this.query.isDelete) {
|
|
434
|
+
// DELETE operation
|
|
435
|
+
return this.executeQuery('DELETE', `${this.restUrl}/${this.table}?operation=delete`, {
|
|
436
|
+
options: this.query.deleteOptions,
|
|
437
|
+
filters: this.query.filters
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
else {
|
|
441
|
+
// SELECT operation (default)
|
|
442
|
+
return this.executeQuery('GET', `${this.restUrl}/${this.table}?operation=select`, {
|
|
443
|
+
select: this.query.select,
|
|
444
|
+
filters: this.query.filters,
|
|
445
|
+
order: this.query.order,
|
|
446
|
+
limit: this.query.limit,
|
|
447
|
+
range: this.query.range
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
// Single row execution
|
|
452
|
+
async single() {
|
|
453
|
+
this.limit(1);
|
|
454
|
+
const result = await this.execute();
|
|
455
|
+
return {
|
|
456
|
+
data: result.data?.[0] || null,
|
|
457
|
+
error: result.error,
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
async executeQuery(method, url, payload) {
|
|
461
|
+
try {
|
|
462
|
+
let response;
|
|
463
|
+
// Configurar headers obrigatórios
|
|
464
|
+
const headers = {};
|
|
465
|
+
if (this.workspaceId) {
|
|
466
|
+
headers['x-workspace-id'] = this.workspaceId;
|
|
467
|
+
}
|
|
468
|
+
if (method === 'GET') {
|
|
469
|
+
// Extrair parâmetros existentes da URL (como operation=select)
|
|
470
|
+
const urlParts = url.split('?');
|
|
471
|
+
const baseUrl = urlParts[0];
|
|
472
|
+
const existingParams = new URLSearchParams(urlParts[1] || '');
|
|
473
|
+
// Adicionar novos parâmetros de query
|
|
474
|
+
if (payload.select)
|
|
475
|
+
existingParams.append('select', payload.select);
|
|
476
|
+
// Converter filtros para formato PostgREST
|
|
477
|
+
if (payload.filters?.length) {
|
|
478
|
+
payload.filters.forEach((filter) => {
|
|
479
|
+
existingParams.append(filter.column, `${filter.operator}.${filter.value}`);
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
// Converter ordenação para formato PostgREST
|
|
483
|
+
if (payload.order?.length) {
|
|
484
|
+
const orderStr = payload.order.map((ord) => `${ord.column}${ord.ascending ? '.asc' : '.desc'}`).join(',');
|
|
485
|
+
existingParams.append('order', orderStr);
|
|
486
|
+
}
|
|
487
|
+
if (payload.limit)
|
|
488
|
+
existingParams.append('limit', payload.limit.toString());
|
|
489
|
+
if (payload.range) {
|
|
490
|
+
existingParams.append('offset', payload.range.from.toString());
|
|
491
|
+
existingParams.append('limit', (payload.range.to - payload.range.from + 1).toString());
|
|
492
|
+
}
|
|
493
|
+
response = await this.httpClient.get(`${baseUrl}?${existingParams.toString()}`, { headers });
|
|
494
|
+
}
|
|
495
|
+
else if (method === 'DELETE') {
|
|
496
|
+
// Para DELETE, os filtros devem estar na URL (query string), não no body
|
|
497
|
+
// Extrair parâmetros existentes da URL (como operation=delete)
|
|
498
|
+
const urlParts = url.split('?');
|
|
499
|
+
const baseUrl = urlParts[0];
|
|
500
|
+
const existingParams = new URLSearchParams(urlParts[1] || '');
|
|
501
|
+
// Adicionar parâmetro operation=delete se não estiver presente
|
|
502
|
+
if (!existingParams.has('operation')) {
|
|
503
|
+
existingParams.append('operation', 'delete');
|
|
504
|
+
}
|
|
505
|
+
if (payload.filters?.length) {
|
|
506
|
+
// Converter filtros para formato PostgREST
|
|
507
|
+
payload.filters.forEach((filter) => {
|
|
508
|
+
existingParams.append(filter.column, `${filter.operator}.${filter.value}`);
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
const deleteUrl = `${baseUrl}?${existingParams.toString()}`;
|
|
512
|
+
console.log('🔧 DELETE URL construída:', deleteUrl);
|
|
513
|
+
console.log('🔧 DELETE headers:', headers);
|
|
514
|
+
console.log('🔧 DELETE filtros originais:', payload.filters);
|
|
515
|
+
response = await this.httpClient.delete(deleteUrl, { headers });
|
|
516
|
+
}
|
|
517
|
+
else if (method === 'PATCH') {
|
|
518
|
+
// Para UPDATE (PATCH), os filtros também devem estar na URL
|
|
519
|
+
// Extrair parâmetros existentes da URL (como operation=update)
|
|
520
|
+
const urlParts = url.split('?');
|
|
521
|
+
const baseUrl = urlParts[0];
|
|
522
|
+
const existingParams = new URLSearchParams(urlParts[1] || '');
|
|
523
|
+
// Adicionar parâmetro operation=update se não estiver presente
|
|
524
|
+
if (!existingParams.has('operation')) {
|
|
525
|
+
existingParams.append('operation', 'update');
|
|
526
|
+
}
|
|
527
|
+
if (payload.filters?.length) {
|
|
528
|
+
// Converter filtros para formato PostgREST
|
|
529
|
+
payload.filters.forEach((filter) => {
|
|
530
|
+
existingParams.append(filter.column, `${filter.operator}.${filter.value}`);
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
// Adicionar headers Prefer se necessário
|
|
534
|
+
if (payload.options?.prefer) {
|
|
535
|
+
headers['Prefer'] = payload.options.prefer;
|
|
536
|
+
}
|
|
537
|
+
const updateUrl = `${baseUrl}?${existingParams.toString()}`;
|
|
538
|
+
response = await this.httpClient.patch(updateUrl, payload.data, { headers });
|
|
539
|
+
}
|
|
540
|
+
else {
|
|
541
|
+
// POST mantém o payload no body (para INSERT)
|
|
542
|
+
let postData = payload.data;
|
|
543
|
+
// Sempre retornar dados inseridos por padrão
|
|
544
|
+
if (!headers['Prefer']) {
|
|
545
|
+
headers['Prefer'] = 'return=representation';
|
|
546
|
+
}
|
|
547
|
+
// Se for upsert, adicionar header Prefer
|
|
548
|
+
if (payload.options?.upsert) {
|
|
549
|
+
headers['Prefer'] = 'resolution=merge-duplicates,return=representation';
|
|
550
|
+
}
|
|
551
|
+
// Se for inserção múltipla, usar dataArray
|
|
552
|
+
if (payload.dataArray) {
|
|
553
|
+
postData = payload.dataArray;
|
|
554
|
+
}
|
|
555
|
+
response = await this.httpClient.post(url, postData, { headers });
|
|
556
|
+
}
|
|
557
|
+
return {
|
|
558
|
+
data: response.data,
|
|
559
|
+
error: null,
|
|
560
|
+
count: response.headers?.['x-total-count'] ? parseInt(response.headers['x-total-count']) : undefined
|
|
561
|
+
};
|
|
562
|
+
}
|
|
563
|
+
catch (error) {
|
|
564
|
+
return {
|
|
565
|
+
data: null,
|
|
566
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Database operation failed', 0, error)
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
class CustomDatabaseManager {
|
|
573
|
+
constructor(httpClient, workspaceId) {
|
|
574
|
+
this.httpClient = httpClient;
|
|
575
|
+
this.workspaceId = workspaceId;
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* Detecta automaticamente se o workspace usa banco customizado
|
|
579
|
+
*/
|
|
580
|
+
async detectCustomDatabase() {
|
|
581
|
+
if (!this.workspaceId) {
|
|
582
|
+
return { hasCustomDatabase: false };
|
|
583
|
+
}
|
|
584
|
+
try {
|
|
585
|
+
// Busca a configuração do workspace
|
|
586
|
+
const response = await this.httpClient.get('/admin/v1/workspace/custom-database', {
|
|
587
|
+
headers: {
|
|
588
|
+
'x-workspace-id': this.workspaceId,
|
|
589
|
+
},
|
|
590
|
+
});
|
|
591
|
+
if (response.status === 200 && response.data?.config) {
|
|
592
|
+
const config = response.data.config;
|
|
593
|
+
// Converte para formato de credenciais do SDK
|
|
594
|
+
const credentials = {
|
|
595
|
+
host: config.postgresHost,
|
|
596
|
+
port: config.postgresPort,
|
|
597
|
+
database: config.postgresDatabase,
|
|
598
|
+
username: config.postgresUsername,
|
|
599
|
+
password: '', // Senha não é retornada pela API por segurança
|
|
600
|
+
schema: config.postgresSchema,
|
|
601
|
+
sslEnabled: config.sslEnabled,
|
|
602
|
+
};
|
|
603
|
+
this.detectedConfig = {
|
|
604
|
+
hasCustomDatabase: true,
|
|
605
|
+
config,
|
|
606
|
+
credentials,
|
|
607
|
+
};
|
|
608
|
+
return this.detectedConfig;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
catch (error) {
|
|
612
|
+
// Se erro 404, significa que não há configuração customizada
|
|
613
|
+
if (error?.status === 404) {
|
|
614
|
+
this.detectedConfig = { hasCustomDatabase: false };
|
|
615
|
+
return this.detectedConfig;
|
|
616
|
+
}
|
|
617
|
+
console.warn('Failed to detect custom database configuration:', error);
|
|
618
|
+
}
|
|
619
|
+
this.detectedConfig = { hasCustomDatabase: false };
|
|
620
|
+
return this.detectedConfig;
|
|
621
|
+
}
|
|
622
|
+
/**
|
|
623
|
+
* Testa conexão com banco customizado
|
|
624
|
+
*/
|
|
625
|
+
async testConnection(credentials) {
|
|
626
|
+
try {
|
|
627
|
+
const response = await this.httpClient.post('/admin/v1/workspace/custom-database/test-connection', credentials, {
|
|
628
|
+
headers: this.workspaceId ? { 'X-Workspace-ID': this.workspaceId } : {},
|
|
629
|
+
});
|
|
630
|
+
return response.data;
|
|
631
|
+
}
|
|
632
|
+
catch (error) {
|
|
633
|
+
return {
|
|
634
|
+
success: false,
|
|
635
|
+
message: error?.message || 'Failed to test connection',
|
|
636
|
+
};
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
/**
|
|
640
|
+
* Configura credenciais customizadas para o workspace
|
|
641
|
+
*/
|
|
642
|
+
async configureCustomDatabase(credentials) {
|
|
643
|
+
if (!this.workspaceId) {
|
|
644
|
+
throw new Error('Workspace ID is required to configure custom database');
|
|
645
|
+
}
|
|
646
|
+
const response = await this.httpClient.post('/admin/v1/workspace/custom-database', {
|
|
647
|
+
workspaceId: this.workspaceId,
|
|
648
|
+
...credentials,
|
|
649
|
+
}, {
|
|
650
|
+
headers: {
|
|
651
|
+
'X-Workspace-ID': this.workspaceId,
|
|
652
|
+
},
|
|
653
|
+
});
|
|
654
|
+
const config = response.data.config;
|
|
655
|
+
// Atualiza a configuração detectada
|
|
656
|
+
this.detectedConfig = {
|
|
657
|
+
hasCustomDatabase: true,
|
|
658
|
+
config,
|
|
659
|
+
credentials,
|
|
660
|
+
};
|
|
661
|
+
return config;
|
|
662
|
+
}
|
|
663
|
+
/**
|
|
664
|
+
* Remove configuração de banco customizado
|
|
665
|
+
*/
|
|
666
|
+
async removeCustomDatabase() {
|
|
667
|
+
if (!this.workspaceId) {
|
|
668
|
+
throw new Error('Workspace ID is required to remove custom database');
|
|
669
|
+
}
|
|
670
|
+
await this.httpClient.delete('/admin/v1/workspace/custom-database', {
|
|
671
|
+
headers: {
|
|
672
|
+
'X-Workspace-ID': this.workspaceId,
|
|
673
|
+
},
|
|
674
|
+
});
|
|
675
|
+
// Limpa a configuração detectada
|
|
676
|
+
this.detectedConfig = { hasCustomDatabase: false };
|
|
677
|
+
}
|
|
678
|
+
/**
|
|
679
|
+
* Retorna a configuração detectada em cache
|
|
680
|
+
*/
|
|
681
|
+
getDetectedConfig() {
|
|
682
|
+
return this.detectedConfig;
|
|
683
|
+
}
|
|
684
|
+
/**
|
|
685
|
+
* Verifica se tem configuração customizada em cache
|
|
686
|
+
*/
|
|
687
|
+
hasCustomDatabase() {
|
|
688
|
+
return this.detectedConfig?.hasCustomDatabase ?? false;
|
|
689
|
+
}
|
|
690
|
+
/**
|
|
691
|
+
* Retorna as credenciais customizadas se disponíveis
|
|
692
|
+
*/
|
|
693
|
+
getCustomCredentials() {
|
|
694
|
+
return this.detectedConfig?.credentials;
|
|
695
|
+
}
|
|
696
|
+
/**
|
|
697
|
+
* Atualiza o workspace ID
|
|
698
|
+
*/
|
|
699
|
+
setWorkspaceId(workspaceId) {
|
|
700
|
+
this.workspaceId = workspaceId;
|
|
701
|
+
// Limpa configuração anterior quando workspace muda
|
|
702
|
+
this.detectedConfig = undefined;
|
|
703
|
+
}
|
|
704
|
+
/**
|
|
705
|
+
* Retorna o workspace ID atual
|
|
706
|
+
*/
|
|
707
|
+
getWorkspaceId() {
|
|
708
|
+
return this.workspaceId;
|
|
709
|
+
}
|
|
710
|
+
/**
|
|
711
|
+
* Retorna informações sobre o status do banco customizado
|
|
712
|
+
*/
|
|
713
|
+
getStatus() {
|
|
714
|
+
return {
|
|
715
|
+
workspaceId: this.workspaceId,
|
|
716
|
+
hasConfig: this.hasCustomDatabase(),
|
|
717
|
+
configDetails: this.detectedConfig?.credentials ? {
|
|
718
|
+
host: this.detectedConfig.credentials.host,
|
|
719
|
+
port: this.detectedConfig.credentials.port,
|
|
720
|
+
database: this.detectedConfig.credentials.database,
|
|
721
|
+
schema: this.detectedConfig.credentials.schema || 'public',
|
|
722
|
+
sslEnabled: this.detectedConfig.credentials.sslEnabled || false,
|
|
723
|
+
} : undefined,
|
|
724
|
+
};
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
class DatabaseClient {
|
|
729
|
+
constructor(httpClient, workspaceId, restUrl) {
|
|
730
|
+
this.httpClient = httpClient;
|
|
731
|
+
this.customDatabaseManager = new CustomDatabaseManager(httpClient, workspaceId);
|
|
732
|
+
this.restUrl = restUrl || '/sdk/v1';
|
|
733
|
+
}
|
|
734
|
+
from(table) {
|
|
735
|
+
return new QueryBuilder(this.httpClient, table, this.currentSchema, this.customDatabaseManager.getWorkspaceId(), this.restUrl);
|
|
736
|
+
}
|
|
737
|
+
rpc(fn, args) {
|
|
738
|
+
return this.httpClient.post(`/rpc/${fn}`, args);
|
|
739
|
+
}
|
|
740
|
+
schema(schema) {
|
|
741
|
+
const client = new DatabaseClient(this.httpClient, this.customDatabaseManager.getWorkspaceId(), this.restUrl);
|
|
742
|
+
client.currentSchema = schema;
|
|
743
|
+
client.customDatabaseManager = this.customDatabaseManager;
|
|
744
|
+
return client;
|
|
745
|
+
}
|
|
746
|
+
// Métodos para gerenciar banco customizado
|
|
747
|
+
/**
|
|
748
|
+
* Detecta automaticamente se o workspace usa banco customizado
|
|
749
|
+
*/
|
|
750
|
+
async detectCustomDatabase() {
|
|
751
|
+
return this.customDatabaseManager.detectCustomDatabase();
|
|
752
|
+
}
|
|
753
|
+
/**
|
|
754
|
+
* Testa conexão com credenciais customizadas
|
|
755
|
+
*/
|
|
756
|
+
async testCustomConnection(credentials) {
|
|
757
|
+
return this.customDatabaseManager.testConnection(credentials);
|
|
758
|
+
}
|
|
759
|
+
/**
|
|
760
|
+
* Configura banco customizado para o workspace
|
|
761
|
+
*/
|
|
762
|
+
async configureCustomDatabase(credentials) {
|
|
763
|
+
return this.customDatabaseManager.configureCustomDatabase(credentials);
|
|
764
|
+
}
|
|
765
|
+
/**
|
|
766
|
+
* Remove configuração de banco customizado
|
|
767
|
+
*/
|
|
768
|
+
async removeCustomDatabase() {
|
|
769
|
+
return this.customDatabaseManager.removeCustomDatabase();
|
|
770
|
+
}
|
|
771
|
+
/**
|
|
772
|
+
* Verifica se o workspace está usando banco customizado
|
|
773
|
+
*/
|
|
774
|
+
isUsingCustomDatabase() {
|
|
775
|
+
return this.customDatabaseManager.hasCustomDatabase();
|
|
776
|
+
}
|
|
777
|
+
/**
|
|
778
|
+
* Retorna informações sobre o banco customizado
|
|
779
|
+
*/
|
|
780
|
+
getCustomDatabaseStatus() {
|
|
781
|
+
return this.customDatabaseManager.getStatus();
|
|
782
|
+
}
|
|
783
|
+
/**
|
|
784
|
+
* Atualiza o workspace ID (útil quando o usuário troca de workspace)
|
|
785
|
+
*/
|
|
786
|
+
setWorkspaceId(workspaceId) {
|
|
787
|
+
this.customDatabaseManager.setWorkspaceId(workspaceId);
|
|
788
|
+
}
|
|
789
|
+
/**
|
|
790
|
+
* Inicializa a detecção automática do banco customizado
|
|
791
|
+
* Deve ser chamado após a autenticação se autoDetectCustomDatabase estiver habilitado
|
|
792
|
+
*/
|
|
793
|
+
async initialize() {
|
|
794
|
+
try {
|
|
795
|
+
await this.customDatabaseManager.detectCustomDatabase();
|
|
796
|
+
}
|
|
797
|
+
catch (error) {
|
|
798
|
+
console.warn('Failed to initialize custom database detection:', error);
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
class StorageBucket {
|
|
804
|
+
constructor(httpClient, bucketId) {
|
|
805
|
+
this.httpClient = httpClient;
|
|
806
|
+
this.bucketId = bucketId;
|
|
807
|
+
}
|
|
808
|
+
async upload(path, file, options) {
|
|
809
|
+
try {
|
|
810
|
+
const formData = new FormData();
|
|
811
|
+
if (file instanceof File) {
|
|
812
|
+
formData.append('file', file);
|
|
813
|
+
}
|
|
814
|
+
else if (file instanceof Blob) {
|
|
815
|
+
formData.append('file', file, path);
|
|
816
|
+
}
|
|
817
|
+
else if (file instanceof ArrayBuffer) {
|
|
818
|
+
formData.append('file', new Blob([file]), path);
|
|
819
|
+
}
|
|
820
|
+
else if (typeof file === 'string') {
|
|
821
|
+
formData.append('file', new Blob([file], { type: 'text/plain' }), path);
|
|
822
|
+
}
|
|
823
|
+
formData.append('path', path);
|
|
824
|
+
if (options?.cacheControl) {
|
|
825
|
+
formData.append('cacheControl', options.cacheControl);
|
|
826
|
+
}
|
|
827
|
+
if (options?.contentType) {
|
|
828
|
+
formData.append('contentType', options.contentType);
|
|
829
|
+
}
|
|
830
|
+
if (options?.metadata) {
|
|
831
|
+
formData.append('metadata', JSON.stringify(options.metadata));
|
|
832
|
+
}
|
|
833
|
+
const url = `/storage/buckets/${this.bucketId}/files${options?.upsert ? '?upsert=true' : ''}`;
|
|
834
|
+
const response = await this.httpClient.post(url, formData, {
|
|
835
|
+
headers: {
|
|
836
|
+
'Content-Type': 'multipart/form-data'
|
|
837
|
+
}
|
|
838
|
+
});
|
|
839
|
+
return {
|
|
840
|
+
data: response.data,
|
|
841
|
+
error: null
|
|
842
|
+
};
|
|
843
|
+
}
|
|
844
|
+
catch (error) {
|
|
845
|
+
return {
|
|
846
|
+
data: null,
|
|
847
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Failed to upload file', 0, error)
|
|
848
|
+
};
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
async download(path, options) {
|
|
852
|
+
try {
|
|
853
|
+
const params = new URLSearchParams();
|
|
854
|
+
if (options?.transform) {
|
|
855
|
+
Object.entries(options.transform).forEach(([key, value]) => {
|
|
856
|
+
if (value !== undefined) {
|
|
857
|
+
params.append(key, String(value));
|
|
858
|
+
}
|
|
859
|
+
});
|
|
860
|
+
}
|
|
861
|
+
const url = `/storage/buckets/${this.bucketId}/files/${path}${params.toString() ? `?${params.toString()}` : ''}`;
|
|
862
|
+
const response = await this.httpClient.get(url, {
|
|
863
|
+
responseType: 'blob'
|
|
864
|
+
});
|
|
865
|
+
return {
|
|
866
|
+
data: response.data,
|
|
867
|
+
error: null
|
|
868
|
+
};
|
|
869
|
+
}
|
|
870
|
+
catch (error) {
|
|
871
|
+
return {
|
|
872
|
+
data: null,
|
|
873
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Failed to download file', 0, error)
|
|
874
|
+
};
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
async list(prefix, options) {
|
|
878
|
+
try {
|
|
879
|
+
const params = new URLSearchParams();
|
|
880
|
+
if (prefix) {
|
|
881
|
+
params.append('prefix', prefix);
|
|
882
|
+
}
|
|
883
|
+
if (options?.limit) {
|
|
884
|
+
params.append('limit', String(options.limit));
|
|
885
|
+
}
|
|
886
|
+
if (options?.offset) {
|
|
887
|
+
params.append('offset', String(options.offset));
|
|
888
|
+
}
|
|
889
|
+
if (options?.sortBy) {
|
|
890
|
+
params.append('sortBy', JSON.stringify(options.sortBy));
|
|
891
|
+
}
|
|
892
|
+
if (options?.search) {
|
|
893
|
+
params.append('search', options.search);
|
|
894
|
+
}
|
|
895
|
+
const url = `/storage/buckets/${this.bucketId}/files${params.toString() ? `?${params.toString()}` : ''}`;
|
|
896
|
+
const response = await this.httpClient.get(url);
|
|
897
|
+
return {
|
|
898
|
+
data: response.data,
|
|
899
|
+
error: null
|
|
900
|
+
};
|
|
901
|
+
}
|
|
902
|
+
catch (error) {
|
|
903
|
+
return {
|
|
904
|
+
data: null,
|
|
905
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Failed to list files', 0, error)
|
|
906
|
+
};
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
async remove(paths) {
|
|
910
|
+
try {
|
|
911
|
+
const response = await this.httpClient.delete(`/storage/buckets/${this.bucketId}/files`, {
|
|
912
|
+
data: { paths }
|
|
913
|
+
});
|
|
914
|
+
return {
|
|
915
|
+
data: response.data,
|
|
916
|
+
error: null
|
|
917
|
+
};
|
|
918
|
+
}
|
|
919
|
+
catch (error) {
|
|
920
|
+
return {
|
|
921
|
+
data: null,
|
|
922
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Failed to remove files', 0, error)
|
|
923
|
+
};
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
async move(fromPath, toPath) {
|
|
927
|
+
try {
|
|
928
|
+
const response = await this.httpClient.post(`/storage/buckets/${this.bucketId}/files/move`, {
|
|
929
|
+
sourceKey: fromPath,
|
|
930
|
+
destinationKey: toPath
|
|
931
|
+
});
|
|
932
|
+
return {
|
|
933
|
+
data: response.data,
|
|
934
|
+
error: null
|
|
935
|
+
};
|
|
936
|
+
}
|
|
937
|
+
catch (error) {
|
|
938
|
+
return {
|
|
939
|
+
data: null,
|
|
940
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Failed to move file', 0, error)
|
|
941
|
+
};
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
async copy(fromPath, toPath) {
|
|
945
|
+
try {
|
|
946
|
+
const response = await this.httpClient.post(`/storage/buckets/${this.bucketId}/files/copy`, {
|
|
947
|
+
sourceKey: fromPath,
|
|
948
|
+
destinationKey: toPath
|
|
949
|
+
});
|
|
950
|
+
return {
|
|
951
|
+
data: response.data,
|
|
952
|
+
error: null
|
|
953
|
+
};
|
|
954
|
+
}
|
|
955
|
+
catch (error) {
|
|
956
|
+
return {
|
|
957
|
+
data: null,
|
|
958
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Failed to copy file', 0, error)
|
|
959
|
+
};
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
async createSignedUrl(path, expiresIn, options) {
|
|
963
|
+
try {
|
|
964
|
+
const response = await this.httpClient.post(`/storage/buckets/${this.bucketId}/files/${path}/sign`, {
|
|
965
|
+
expiresIn,
|
|
966
|
+
...options
|
|
967
|
+
});
|
|
968
|
+
return {
|
|
969
|
+
data: response.data,
|
|
970
|
+
error: null
|
|
971
|
+
};
|
|
972
|
+
}
|
|
973
|
+
catch (error) {
|
|
974
|
+
return {
|
|
975
|
+
data: null,
|
|
976
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Failed to create signed URL', 0, error)
|
|
977
|
+
};
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
getPublicUrl(path, options) {
|
|
981
|
+
const params = new URLSearchParams();
|
|
982
|
+
if (options?.transform) {
|
|
983
|
+
Object.entries(options.transform).forEach(([key, value]) => {
|
|
984
|
+
if (value !== undefined) {
|
|
985
|
+
params.append(key, String(value));
|
|
986
|
+
}
|
|
987
|
+
});
|
|
988
|
+
}
|
|
989
|
+
const baseUrl = this.httpClient['baseURL'] || '';
|
|
990
|
+
const publicUrl = `${baseUrl}/storage/buckets/${this.bucketId}/files/${path}${params.toString() ? `?${params.toString()}` : ''}`;
|
|
991
|
+
return {
|
|
992
|
+
data: {
|
|
993
|
+
publicUrl
|
|
994
|
+
}
|
|
995
|
+
};
|
|
996
|
+
}
|
|
997
|
+
async getFileInfo(path) {
|
|
998
|
+
try {
|
|
999
|
+
const response = await this.httpClient.get(`/storage/buckets/${this.bucketId}/files/${path}/info`);
|
|
1000
|
+
return {
|
|
1001
|
+
data: response.data,
|
|
1002
|
+
error: null
|
|
1003
|
+
};
|
|
1004
|
+
}
|
|
1005
|
+
catch (error) {
|
|
1006
|
+
return {
|
|
1007
|
+
data: null,
|
|
1008
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Failed to get file info', 0, error)
|
|
1009
|
+
};
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
async updateFileMetadata(path, metadata) {
|
|
1013
|
+
try {
|
|
1014
|
+
const response = await this.httpClient.put(`/storage/buckets/${this.bucketId}/files/${path}/metadata`, {
|
|
1015
|
+
metadata
|
|
1016
|
+
});
|
|
1017
|
+
return {
|
|
1018
|
+
data: response.data,
|
|
1019
|
+
error: null
|
|
1020
|
+
};
|
|
1021
|
+
}
|
|
1022
|
+
catch (error) {
|
|
1023
|
+
return {
|
|
1024
|
+
data: null,
|
|
1025
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Failed to update file metadata', 0, error)
|
|
1026
|
+
};
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
class StorageClient {
|
|
1032
|
+
constructor(httpClient) {
|
|
1033
|
+
this.httpClient = httpClient;
|
|
1034
|
+
}
|
|
1035
|
+
from(bucketId) {
|
|
1036
|
+
return new StorageBucket(this.httpClient, bucketId);
|
|
1037
|
+
}
|
|
1038
|
+
async createBucket(id, options) {
|
|
1039
|
+
try {
|
|
1040
|
+
const response = await this.httpClient.post('/storage/buckets', {
|
|
1041
|
+
id,
|
|
1042
|
+
...options
|
|
1043
|
+
});
|
|
1044
|
+
return {
|
|
1045
|
+
data: response.data,
|
|
1046
|
+
error: null
|
|
1047
|
+
};
|
|
1048
|
+
}
|
|
1049
|
+
catch (error) {
|
|
1050
|
+
return {
|
|
1051
|
+
data: null,
|
|
1052
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Failed to create bucket', 0, error)
|
|
1053
|
+
};
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
async getBucket(id) {
|
|
1057
|
+
try {
|
|
1058
|
+
const response = await this.httpClient.get(`/storage/buckets/${id}`);
|
|
1059
|
+
return {
|
|
1060
|
+
data: response.data,
|
|
1061
|
+
error: null
|
|
1062
|
+
};
|
|
1063
|
+
}
|
|
1064
|
+
catch (error) {
|
|
1065
|
+
return {
|
|
1066
|
+
data: null,
|
|
1067
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Failed to get bucket', 0, error)
|
|
1068
|
+
};
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
async listBuckets() {
|
|
1072
|
+
try {
|
|
1073
|
+
const response = await this.httpClient.get('/storage/buckets');
|
|
1074
|
+
return {
|
|
1075
|
+
data: response.data,
|
|
1076
|
+
error: null
|
|
1077
|
+
};
|
|
1078
|
+
}
|
|
1079
|
+
catch (error) {
|
|
1080
|
+
return {
|
|
1081
|
+
data: null,
|
|
1082
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Failed to list buckets', 0, error)
|
|
1083
|
+
};
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
async updateBucket(id, options) {
|
|
1087
|
+
try {
|
|
1088
|
+
const response = await this.httpClient.put(`/storage/buckets/${id}`, options);
|
|
1089
|
+
return {
|
|
1090
|
+
data: response.data,
|
|
1091
|
+
error: null
|
|
1092
|
+
};
|
|
1093
|
+
}
|
|
1094
|
+
catch (error) {
|
|
1095
|
+
return {
|
|
1096
|
+
data: null,
|
|
1097
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Failed to update bucket', 0, error)
|
|
1098
|
+
};
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
async deleteBucket(id) {
|
|
1102
|
+
try {
|
|
1103
|
+
const response = await this.httpClient.delete(`/storage/buckets/${id}`);
|
|
1104
|
+
return {
|
|
1105
|
+
data: response.data,
|
|
1106
|
+
error: null
|
|
1107
|
+
};
|
|
1108
|
+
}
|
|
1109
|
+
catch (error) {
|
|
1110
|
+
return {
|
|
1111
|
+
data: null,
|
|
1112
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Failed to delete bucket', 0, error)
|
|
1113
|
+
};
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
async getUsage() {
|
|
1117
|
+
try {
|
|
1118
|
+
const response = await this.httpClient.get('/storage/usage');
|
|
1119
|
+
return {
|
|
1120
|
+
data: response.data,
|
|
1121
|
+
error: null
|
|
1122
|
+
};
|
|
1123
|
+
}
|
|
1124
|
+
catch (error) {
|
|
1125
|
+
return {
|
|
1126
|
+
data: null,
|
|
1127
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Failed to get storage usage', 0, error)
|
|
1128
|
+
};
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
class EventManager {
|
|
1134
|
+
constructor() {
|
|
1135
|
+
this.events = new Map();
|
|
1136
|
+
this.maxListeners = 10;
|
|
1137
|
+
}
|
|
1138
|
+
on(event, callback) {
|
|
1139
|
+
if (!this.events.has(event)) {
|
|
1140
|
+
this.events.set(event, new Set());
|
|
1141
|
+
}
|
|
1142
|
+
this.events.get(event).add(callback);
|
|
1143
|
+
}
|
|
1144
|
+
off(event, callback) {
|
|
1145
|
+
if (!this.events.has(event))
|
|
1146
|
+
return;
|
|
1147
|
+
const eventCallbacks = this.events.get(event);
|
|
1148
|
+
if (callback) {
|
|
1149
|
+
eventCallbacks.delete(callback);
|
|
1150
|
+
}
|
|
1151
|
+
else {
|
|
1152
|
+
eventCallbacks.clear();
|
|
1153
|
+
}
|
|
1154
|
+
if (eventCallbacks.size === 0) {
|
|
1155
|
+
this.events.delete(event);
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
emit(event, ...args) {
|
|
1159
|
+
if (!this.events.has(event))
|
|
1160
|
+
return false;
|
|
1161
|
+
const eventCallbacks = this.events.get(event);
|
|
1162
|
+
for (const callback of eventCallbacks) {
|
|
1163
|
+
try {
|
|
1164
|
+
callback(...args);
|
|
1165
|
+
}
|
|
1166
|
+
catch (error) {
|
|
1167
|
+
console.error(`Error in event listener for "${event}":`, error);
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
return eventCallbacks.size > 0;
|
|
1171
|
+
}
|
|
1172
|
+
removeAllListeners(event) {
|
|
1173
|
+
if (event) {
|
|
1174
|
+
this.events.delete(event);
|
|
1175
|
+
}
|
|
1176
|
+
else {
|
|
1177
|
+
this.events.clear();
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
listenerCount(event) {
|
|
1181
|
+
return this.events.get(event)?.size ?? 0;
|
|
1182
|
+
}
|
|
1183
|
+
eventNames() {
|
|
1184
|
+
return Array.from(this.events.keys());
|
|
1185
|
+
}
|
|
1186
|
+
listeners(event) {
|
|
1187
|
+
return Array.from(this.events.get(event) ?? []);
|
|
1188
|
+
}
|
|
1189
|
+
addListener(event, callback) {
|
|
1190
|
+
this.on(event, callback);
|
|
1191
|
+
}
|
|
1192
|
+
removeListener(event, callback) {
|
|
1193
|
+
this.off(event, callback);
|
|
1194
|
+
}
|
|
1195
|
+
once(event, callback) {
|
|
1196
|
+
const onceWrapper = (...args) => {
|
|
1197
|
+
this.off(event, onceWrapper);
|
|
1198
|
+
callback(...args);
|
|
1199
|
+
};
|
|
1200
|
+
this.on(event, onceWrapper);
|
|
1201
|
+
}
|
|
1202
|
+
prependListener(event, callback) {
|
|
1203
|
+
this.on(event, callback);
|
|
1204
|
+
}
|
|
1205
|
+
prependOnceListener(event, callback) {
|
|
1206
|
+
const onceWrapper = (...args) => {
|
|
1207
|
+
this.off(event, onceWrapper);
|
|
1208
|
+
callback(...args);
|
|
1209
|
+
};
|
|
1210
|
+
this.on(event, onceWrapper);
|
|
1211
|
+
}
|
|
1212
|
+
setMaxListeners(max) {
|
|
1213
|
+
this.maxListeners = max;
|
|
1214
|
+
return this;
|
|
1215
|
+
}
|
|
1216
|
+
getMaxListeners() {
|
|
1217
|
+
return this.maxListeners;
|
|
1218
|
+
}
|
|
1219
|
+
rawListeners(event) {
|
|
1220
|
+
return this.listeners(event);
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
class RealtimeChannel extends EventManager {
|
|
1225
|
+
constructor(topic, socket) {
|
|
1226
|
+
super();
|
|
1227
|
+
this.joinedOnce = false;
|
|
1228
|
+
this.state = 'closed';
|
|
1229
|
+
this.subscriptions = new Map();
|
|
1230
|
+
this.topic = topic;
|
|
1231
|
+
this.socket = socket;
|
|
1232
|
+
}
|
|
1233
|
+
subscribe(callback) {
|
|
1234
|
+
if (!this.joinedOnce) {
|
|
1235
|
+
this.joinedOnce = true;
|
|
1236
|
+
this._join();
|
|
1237
|
+
}
|
|
1238
|
+
if (callback) {
|
|
1239
|
+
this.on('status', callback);
|
|
1240
|
+
}
|
|
1241
|
+
return this;
|
|
1242
|
+
}
|
|
1243
|
+
onPostgresChanges(filter, callback) {
|
|
1244
|
+
const eventKey = `postgres_changes:${JSON.stringify(filter)}`;
|
|
1245
|
+
this.on(eventKey, callback);
|
|
1246
|
+
const subscription = {
|
|
1247
|
+
unsubscribe: () => {
|
|
1248
|
+
this.off(eventKey, callback);
|
|
1249
|
+
this.subscriptions.delete(eventKey);
|
|
1250
|
+
}
|
|
1251
|
+
};
|
|
1252
|
+
this.subscriptions.set(eventKey, subscription);
|
|
1253
|
+
if (this.socket?.connected && this.state === 'joined') {
|
|
1254
|
+
this.socket.emit('subscribe_postgres_changes', {
|
|
1255
|
+
topic: this.topic,
|
|
1256
|
+
filter,
|
|
1257
|
+
ref: this.makeRef()
|
|
1258
|
+
});
|
|
1259
|
+
}
|
|
1260
|
+
return subscription;
|
|
1261
|
+
}
|
|
1262
|
+
onBroadcast(filter, callback) {
|
|
1263
|
+
const eventKey = `broadcast:${JSON.stringify(filter)}`;
|
|
1264
|
+
this.on(eventKey, callback);
|
|
1265
|
+
const subscription = {
|
|
1266
|
+
unsubscribe: () => {
|
|
1267
|
+
this.off(eventKey, callback);
|
|
1268
|
+
this.subscriptions.delete(eventKey);
|
|
1269
|
+
}
|
|
1270
|
+
};
|
|
1271
|
+
this.subscriptions.set(eventKey, subscription);
|
|
1272
|
+
return subscription;
|
|
1273
|
+
}
|
|
1274
|
+
onPresence(filter, callback) {
|
|
1275
|
+
const eventKey = `presence:${JSON.stringify(filter)}`;
|
|
1276
|
+
this.on(eventKey, callback);
|
|
1277
|
+
const subscription = {
|
|
1278
|
+
unsubscribe: () => {
|
|
1279
|
+
this.off(eventKey, callback);
|
|
1280
|
+
this.subscriptions.delete(eventKey);
|
|
1281
|
+
}
|
|
1282
|
+
};
|
|
1283
|
+
this.subscriptions.set(eventKey, subscription);
|
|
1284
|
+
return subscription;
|
|
1285
|
+
}
|
|
1286
|
+
send(payload) {
|
|
1287
|
+
return new Promise((resolve) => {
|
|
1288
|
+
if (this.socket?.connected && this.state === 'joined') {
|
|
1289
|
+
this.socket.emit('broadcast', {
|
|
1290
|
+
topic: this.topic,
|
|
1291
|
+
event: payload.event,
|
|
1292
|
+
payload: payload,
|
|
1293
|
+
ref: this.makeRef()
|
|
1294
|
+
});
|
|
1295
|
+
resolve('ok');
|
|
1296
|
+
}
|
|
1297
|
+
else {
|
|
1298
|
+
resolve('error');
|
|
1299
|
+
}
|
|
1300
|
+
});
|
|
1301
|
+
}
|
|
1302
|
+
track(payload) {
|
|
1303
|
+
return new Promise((resolve) => {
|
|
1304
|
+
if (this.socket?.connected && this.state === 'joined') {
|
|
1305
|
+
this.socket.emit('presence', {
|
|
1306
|
+
topic: this.topic,
|
|
1307
|
+
event: 'track',
|
|
1308
|
+
payload: payload,
|
|
1309
|
+
ref: this.makeRef()
|
|
1310
|
+
});
|
|
1311
|
+
resolve('ok');
|
|
1312
|
+
}
|
|
1313
|
+
else {
|
|
1314
|
+
resolve('error');
|
|
1315
|
+
}
|
|
1316
|
+
});
|
|
1317
|
+
}
|
|
1318
|
+
untrack() {
|
|
1319
|
+
return new Promise((resolve) => {
|
|
1320
|
+
if (this.socket?.connected && this.state === 'joined') {
|
|
1321
|
+
this.socket.emit('presence', {
|
|
1322
|
+
topic: this.topic,
|
|
1323
|
+
event: 'untrack',
|
|
1324
|
+
ref: this.makeRef()
|
|
1325
|
+
});
|
|
1326
|
+
resolve('ok');
|
|
1327
|
+
}
|
|
1328
|
+
else {
|
|
1329
|
+
resolve('error');
|
|
1330
|
+
}
|
|
1331
|
+
});
|
|
1332
|
+
}
|
|
1333
|
+
unsubscribe() {
|
|
1334
|
+
return new Promise((resolve) => {
|
|
1335
|
+
this.state = 'leaving';
|
|
1336
|
+
this.subscriptions.forEach(subscription => {
|
|
1337
|
+
subscription.unsubscribe();
|
|
1338
|
+
});
|
|
1339
|
+
this.subscriptions.clear();
|
|
1340
|
+
if (this.socket?.connected) {
|
|
1341
|
+
this.socket.emit('leave', {
|
|
1342
|
+
topic: this.topic,
|
|
1343
|
+
ref: this.makeRef()
|
|
1344
|
+
});
|
|
1345
|
+
}
|
|
1346
|
+
this.state = 'closed';
|
|
1347
|
+
this.removeAllListeners();
|
|
1348
|
+
resolve('ok');
|
|
1349
|
+
});
|
|
1350
|
+
}
|
|
1351
|
+
_join() {
|
|
1352
|
+
if (this.state === 'leaving')
|
|
1353
|
+
return;
|
|
1354
|
+
this.state = 'joining';
|
|
1355
|
+
if (this.socket?.connected) {
|
|
1356
|
+
this.socket.emit('join', {
|
|
1357
|
+
topic: this.topic,
|
|
1358
|
+
ref: this.makeRef()
|
|
1359
|
+
});
|
|
1360
|
+
setTimeout(() => {
|
|
1361
|
+
if (this.state === 'joining') {
|
|
1362
|
+
this.state = 'joined';
|
|
1363
|
+
this.emit('status', 'SUBSCRIBED');
|
|
1364
|
+
}
|
|
1365
|
+
}, 100);
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
_rejoin() {
|
|
1369
|
+
if (this.joinedOnce) {
|
|
1370
|
+
this._join();
|
|
1371
|
+
this.subscriptions.forEach((_subscription, eventKey) => {
|
|
1372
|
+
if (eventKey.startsWith('postgres_changes:')) {
|
|
1373
|
+
const filter = JSON.parse(eventKey.replace('postgres_changes:', ''));
|
|
1374
|
+
this.socket?.emit('subscribe_postgres_changes', {
|
|
1375
|
+
topic: this.topic,
|
|
1376
|
+
filter,
|
|
1377
|
+
ref: this.makeRef()
|
|
1378
|
+
});
|
|
1379
|
+
}
|
|
1380
|
+
});
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
_trigger(event, payload) {
|
|
1384
|
+
if (event === 'postgres_changes') {
|
|
1385
|
+
const eventKey = `postgres_changes:${JSON.stringify(payload.filter || {})}`;
|
|
1386
|
+
this.emit(eventKey, payload);
|
|
1387
|
+
}
|
|
1388
|
+
else if (event === 'broadcast') {
|
|
1389
|
+
const eventKey = `broadcast:${JSON.stringify({ event: payload.event })}`;
|
|
1390
|
+
this.emit(eventKey, payload);
|
|
1391
|
+
}
|
|
1392
|
+
else if (event === 'presence') {
|
|
1393
|
+
const eventKey = `presence:${JSON.stringify({ event: payload.event })}`;
|
|
1394
|
+
this.emit(eventKey, payload);
|
|
1395
|
+
}
|
|
1396
|
+
this.emit(event, payload);
|
|
1397
|
+
}
|
|
1398
|
+
_setState(state) {
|
|
1399
|
+
this.state = state;
|
|
1400
|
+
let status;
|
|
1401
|
+
switch (state) {
|
|
1402
|
+
case 'joined':
|
|
1403
|
+
status = 'SUBSCRIBED';
|
|
1404
|
+
break;
|
|
1405
|
+
case 'errored':
|
|
1406
|
+
status = 'CHANNEL_ERROR';
|
|
1407
|
+
break;
|
|
1408
|
+
case 'closed':
|
|
1409
|
+
status = 'CLOSED';
|
|
1410
|
+
break;
|
|
1411
|
+
default:
|
|
1412
|
+
return;
|
|
1413
|
+
}
|
|
1414
|
+
this.emit('status', status);
|
|
1415
|
+
}
|
|
1416
|
+
makeRef() {
|
|
1417
|
+
return Math.random().toString(36).substring(2, 15);
|
|
1418
|
+
}
|
|
1419
|
+
getState() {
|
|
1420
|
+
return this.state;
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
|
|
1424
|
+
function getEnvironment() {
|
|
1425
|
+
if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
|
|
1426
|
+
return 'react-native';
|
|
1427
|
+
}
|
|
1428
|
+
if (typeof window !== 'undefined' && typeof document !== 'undefined') {
|
|
1429
|
+
return 'browser';
|
|
1430
|
+
}
|
|
1431
|
+
if (typeof global !== 'undefined' && typeof process !== 'undefined' && process.versions?.node) {
|
|
1432
|
+
return 'node';
|
|
1433
|
+
}
|
|
1434
|
+
return 'browser';
|
|
1435
|
+
}
|
|
1436
|
+
function isSocketIOAvailable() {
|
|
1437
|
+
try {
|
|
1438
|
+
const env = getEnvironment();
|
|
1439
|
+
switch (env) {
|
|
1440
|
+
case 'node':
|
|
1441
|
+
return typeof require !== 'undefined' && require.resolve && !!require.resolve('socket.io-client');
|
|
1442
|
+
case 'browser':
|
|
1443
|
+
if (typeof globalThis !== 'undefined' && 'io' in globalThis) {
|
|
1444
|
+
return true;
|
|
1445
|
+
}
|
|
1446
|
+
return typeof require !== 'undefined' && require.resolve && !!require.resolve('socket.io-client');
|
|
1447
|
+
case 'react-native':
|
|
1448
|
+
try {
|
|
1449
|
+
return typeof require !== 'undefined' && !!require('socket.io-client');
|
|
1450
|
+
}
|
|
1451
|
+
catch {
|
|
1452
|
+
return false;
|
|
1453
|
+
}
|
|
1454
|
+
default:
|
|
1455
|
+
return false;
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
catch {
|
|
1459
|
+
return false;
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
function getSocketIO() {
|
|
1463
|
+
try {
|
|
1464
|
+
if (typeof require !== 'undefined') {
|
|
1465
|
+
return require('socket.io-client');
|
|
1466
|
+
}
|
|
1467
|
+
if (typeof globalThis !== 'undefined' && 'io' in globalThis) {
|
|
1468
|
+
return { io: globalThis.io };
|
|
1469
|
+
}
|
|
1470
|
+
throw new Error('socket.io-client not available');
|
|
1471
|
+
}
|
|
1472
|
+
catch (error) {
|
|
1473
|
+
throw new Error(`Socket.io-client não está disponível neste ambiente. Para usar funcionalidades de realtime, instale: npm install socket.io-client`);
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1476
|
+
class WebSocketAdapter {
|
|
1477
|
+
constructor() {
|
|
1478
|
+
this.socket = null;
|
|
1479
|
+
}
|
|
1480
|
+
async connect(url, options) {
|
|
1481
|
+
if (!isSocketIOAvailable()) {
|
|
1482
|
+
throw new Error('Socket.io-client não está disponível. Para usar funcionalidades de realtime, instale: npm install socket.io-client');
|
|
1483
|
+
}
|
|
1484
|
+
const { io } = getSocketIO();
|
|
1485
|
+
return new Promise((resolve, reject) => {
|
|
1486
|
+
this.socket = io(url, options);
|
|
1487
|
+
this.socket.on('connect', () => resolve());
|
|
1488
|
+
this.socket.on('connect_error', (error) => reject(error));
|
|
1489
|
+
});
|
|
1490
|
+
}
|
|
1491
|
+
disconnect() {
|
|
1492
|
+
if (this.socket) {
|
|
1493
|
+
this.socket.disconnect();
|
|
1494
|
+
this.socket = null;
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
emit(event, data) {
|
|
1498
|
+
this.socket?.emit(event, data);
|
|
1499
|
+
}
|
|
1500
|
+
on(event, callback) {
|
|
1501
|
+
this.socket?.on(event, callback);
|
|
1502
|
+
}
|
|
1503
|
+
off(event, callback) {
|
|
1504
|
+
if (callback) {
|
|
1505
|
+
this.socket?.off(event, callback);
|
|
1506
|
+
}
|
|
1507
|
+
else {
|
|
1508
|
+
this.socket?.off(event);
|
|
1509
|
+
}
|
|
1510
|
+
}
|
|
1511
|
+
get connected() {
|
|
1512
|
+
return this.socket?.connected ?? false;
|
|
1513
|
+
}
|
|
1514
|
+
}
|
|
1515
|
+
class ReactNativeSocketAdapter {
|
|
1516
|
+
constructor() {
|
|
1517
|
+
this.socket = null;
|
|
1518
|
+
}
|
|
1519
|
+
async connect(url, options) {
|
|
1520
|
+
if (!isSocketIOAvailable()) {
|
|
1521
|
+
throw new Error('Socket.io-client não está disponível. Para React Native, instale: npm install socket.io-client');
|
|
1522
|
+
}
|
|
1523
|
+
const { io } = getSocketIO();
|
|
1524
|
+
return new Promise((resolve, reject) => {
|
|
1525
|
+
this.socket = io(url, {
|
|
1526
|
+
...options,
|
|
1527
|
+
transports: ['websocket'],
|
|
1528
|
+
upgrade: false,
|
|
1529
|
+
autoConnect: true,
|
|
1530
|
+
});
|
|
1531
|
+
this.socket.on('connect', () => resolve());
|
|
1532
|
+
this.socket.on('connect_error', (error) => reject(error));
|
|
1533
|
+
});
|
|
1534
|
+
}
|
|
1535
|
+
disconnect() {
|
|
1536
|
+
if (this.socket) {
|
|
1537
|
+
this.socket.disconnect();
|
|
1538
|
+
this.socket = null;
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
emit(event, data) {
|
|
1542
|
+
this.socket?.emit(event, data);
|
|
1543
|
+
}
|
|
1544
|
+
on(event, callback) {
|
|
1545
|
+
this.socket?.on(event, callback);
|
|
1546
|
+
}
|
|
1547
|
+
off(event, callback) {
|
|
1548
|
+
if (callback) {
|
|
1549
|
+
this.socket?.off(event, callback);
|
|
1550
|
+
}
|
|
1551
|
+
else {
|
|
1552
|
+
this.socket?.off(event);
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1555
|
+
get connected() {
|
|
1556
|
+
return this.socket?.connected ?? false;
|
|
1557
|
+
}
|
|
1558
|
+
}
|
|
1559
|
+
function createSocketAdapter() {
|
|
1560
|
+
const env = getEnvironment();
|
|
1561
|
+
switch (env) {
|
|
1562
|
+
case 'react-native':
|
|
1563
|
+
return new ReactNativeSocketAdapter();
|
|
1564
|
+
case 'browser':
|
|
1565
|
+
case 'node':
|
|
1566
|
+
default:
|
|
1567
|
+
return new WebSocketAdapter();
|
|
1568
|
+
}
|
|
1569
|
+
}
|
|
1570
|
+
|
|
1571
|
+
class RealtimeClient {
|
|
1572
|
+
constructor(url, apiKey, options = {}) {
|
|
1573
|
+
this.socket = null;
|
|
1574
|
+
this.channels = new Map();
|
|
1575
|
+
this.connectionState = 'disconnected';
|
|
1576
|
+
this.reconnectAttempts = 0;
|
|
1577
|
+
this.maxReconnectAttempts = 5;
|
|
1578
|
+
this.url = url;
|
|
1579
|
+
this.apiKey = apiKey;
|
|
1580
|
+
this.options = {
|
|
1581
|
+
heartbeatInterval: 30000,
|
|
1582
|
+
reconnectInterval: 5000,
|
|
1583
|
+
maxReconnectAttempts: 5,
|
|
1584
|
+
...options
|
|
1585
|
+
};
|
|
1586
|
+
this.socketAdapter = createSocketAdapter();
|
|
1587
|
+
}
|
|
1588
|
+
connect() {
|
|
1589
|
+
return new Promise(async (resolve, reject) => {
|
|
1590
|
+
if (this.socketAdapter.connected) {
|
|
1591
|
+
resolve();
|
|
1592
|
+
return;
|
|
1593
|
+
}
|
|
1594
|
+
this.connectionState = 'connecting';
|
|
1595
|
+
try {
|
|
1596
|
+
await this.socketAdapter.connect(this.url, {
|
|
1597
|
+
auth: {
|
|
1598
|
+
apikey: this.apiKey
|
|
1599
|
+
},
|
|
1600
|
+
transports: ['websocket'],
|
|
1601
|
+
reconnection: true,
|
|
1602
|
+
reconnectionDelay: this.options.reconnectInterval,
|
|
1603
|
+
reconnectionAttempts: this.options.maxReconnectAttempts,
|
|
1604
|
+
...this.options.socketOptions
|
|
1605
|
+
});
|
|
1606
|
+
this.socket = this.socketAdapter.socket;
|
|
1607
|
+
this.socketAdapter.on('connect', () => {
|
|
1608
|
+
this.connectionState = 'connected';
|
|
1609
|
+
this.reconnectAttempts = 0;
|
|
1610
|
+
this.setupHeartbeat();
|
|
1611
|
+
resolve();
|
|
1612
|
+
});
|
|
1613
|
+
this.socketAdapter.on('disconnect', () => {
|
|
1614
|
+
this.connectionState = 'disconnected';
|
|
1615
|
+
this.channels.forEach(channel => {
|
|
1616
|
+
channel._setState('closed');
|
|
1617
|
+
});
|
|
1618
|
+
});
|
|
1619
|
+
this.socketAdapter.on('connect_error', (error) => {
|
|
1620
|
+
this.connectionState = 'error';
|
|
1621
|
+
this.reconnectAttempts++;
|
|
1622
|
+
if (this.reconnectAttempts >= this.maxReconnectAttempts) {
|
|
1623
|
+
reject(new Error(`Failed to connect after ${this.maxReconnectAttempts} attempts: ${error.message}`));
|
|
1624
|
+
}
|
|
1625
|
+
});
|
|
1626
|
+
this.socketAdapter.on('reconnect', () => {
|
|
1627
|
+
this.connectionState = 'connected';
|
|
1628
|
+
this.reconnectAttempts = 0;
|
|
1629
|
+
this.channels.forEach(channel => {
|
|
1630
|
+
channel._rejoin();
|
|
1631
|
+
});
|
|
1632
|
+
});
|
|
1633
|
+
this.socketAdapter.on('postgres_changes', (payload) => {
|
|
1634
|
+
const channel = this.channels.get(payload.topic);
|
|
1635
|
+
if (channel) {
|
|
1636
|
+
channel._trigger('postgres_changes', payload);
|
|
1637
|
+
}
|
|
1638
|
+
});
|
|
1639
|
+
this.socketAdapter.on('broadcast', (payload) => {
|
|
1640
|
+
const channel = this.channels.get(payload.topic);
|
|
1641
|
+
if (channel) {
|
|
1642
|
+
channel._trigger('broadcast', payload);
|
|
1643
|
+
}
|
|
1644
|
+
});
|
|
1645
|
+
this.socketAdapter.on('presence', (payload) => {
|
|
1646
|
+
const channel = this.channels.get(payload.topic);
|
|
1647
|
+
if (channel) {
|
|
1648
|
+
channel._trigger('presence', payload);
|
|
1649
|
+
}
|
|
1650
|
+
});
|
|
1651
|
+
}
|
|
1652
|
+
catch (error) {
|
|
1653
|
+
this.connectionState = 'error';
|
|
1654
|
+
reject(error);
|
|
1655
|
+
}
|
|
1656
|
+
});
|
|
1657
|
+
}
|
|
1658
|
+
disconnect() {
|
|
1659
|
+
if (this.socketAdapter) {
|
|
1660
|
+
this.socketAdapter.disconnect();
|
|
1661
|
+
this.socket = null;
|
|
1662
|
+
}
|
|
1663
|
+
this.connectionState = 'disconnected';
|
|
1664
|
+
this.channels.clear();
|
|
1665
|
+
}
|
|
1666
|
+
channel(topic) {
|
|
1667
|
+
if (this.channels.has(topic)) {
|
|
1668
|
+
return this.channels.get(topic);
|
|
1669
|
+
}
|
|
1670
|
+
const channel = new RealtimeChannel(topic, this.socket);
|
|
1671
|
+
this.channels.set(topic, channel);
|
|
1672
|
+
if (this.connectionState === 'connected') {
|
|
1673
|
+
channel._join();
|
|
1674
|
+
}
|
|
1675
|
+
return channel;
|
|
1676
|
+
}
|
|
1677
|
+
removeChannel(channel) {
|
|
1678
|
+
const topic = channel.topic;
|
|
1679
|
+
if (this.channels.has(topic)) {
|
|
1680
|
+
this.channels.delete(topic);
|
|
1681
|
+
channel.unsubscribe();
|
|
1682
|
+
}
|
|
1683
|
+
}
|
|
1684
|
+
removeAllChannels() {
|
|
1685
|
+
this.channels.forEach(channel => {
|
|
1686
|
+
channel.unsubscribe();
|
|
1687
|
+
});
|
|
1688
|
+
this.channels.clear();
|
|
1689
|
+
}
|
|
1690
|
+
getChannels() {
|
|
1691
|
+
return Array.from(this.channels.values());
|
|
1692
|
+
}
|
|
1693
|
+
isConnected() {
|
|
1694
|
+
return this.connectionState === 'connected' && this.socketAdapter.connected;
|
|
1695
|
+
}
|
|
1696
|
+
getConnectionState() {
|
|
1697
|
+
return this.connectionState;
|
|
1698
|
+
}
|
|
1699
|
+
onConnectionStateChange(callback) {
|
|
1700
|
+
const handler = () => callback(this.connectionState);
|
|
1701
|
+
if (this.socketAdapter) {
|
|
1702
|
+
this.socketAdapter.on('connect', () => {
|
|
1703
|
+
this.connectionState = 'connected';
|
|
1704
|
+
handler();
|
|
1705
|
+
});
|
|
1706
|
+
this.socketAdapter.on('disconnect', () => {
|
|
1707
|
+
this.connectionState = 'disconnected';
|
|
1708
|
+
handler();
|
|
1709
|
+
});
|
|
1710
|
+
this.socketAdapter.on('connect_error', () => {
|
|
1711
|
+
this.connectionState = 'error';
|
|
1712
|
+
handler();
|
|
1713
|
+
});
|
|
1714
|
+
}
|
|
1715
|
+
return () => {
|
|
1716
|
+
if (this.socketAdapter) {
|
|
1717
|
+
this.socketAdapter.off('connect', handler);
|
|
1718
|
+
this.socketAdapter.off('disconnect', handler);
|
|
1719
|
+
this.socketAdapter.off('connect_error', handler);
|
|
1720
|
+
}
|
|
1721
|
+
};
|
|
1722
|
+
}
|
|
1723
|
+
setupHeartbeat() {
|
|
1724
|
+
if (!this.options.heartbeatInterval || !this.socketAdapter)
|
|
1725
|
+
return;
|
|
1726
|
+
const interval = setInterval(() => {
|
|
1727
|
+
if (this.socketAdapter?.connected) {
|
|
1728
|
+
this.socketAdapter.emit('heartbeat', { timestamp: Date.now() });
|
|
1729
|
+
}
|
|
1730
|
+
else {
|
|
1731
|
+
clearInterval(interval);
|
|
1732
|
+
}
|
|
1733
|
+
}, this.options.heartbeatInterval);
|
|
1734
|
+
}
|
|
1735
|
+
_getSocket() {
|
|
1736
|
+
return this.socket;
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
|
|
1740
|
+
class FunctionsClient {
|
|
1741
|
+
constructor(httpClient) {
|
|
1742
|
+
this.httpClient = httpClient;
|
|
1743
|
+
}
|
|
1744
|
+
async invoke(functionName, options) {
|
|
1745
|
+
try {
|
|
1746
|
+
const method = options?.method || 'POST';
|
|
1747
|
+
const headers = {
|
|
1748
|
+
'Content-Type': 'application/json',
|
|
1749
|
+
...options?.headers
|
|
1750
|
+
};
|
|
1751
|
+
let response;
|
|
1752
|
+
const url = `/functions/v1/${functionName}`;
|
|
1753
|
+
switch (method.toUpperCase()) {
|
|
1754
|
+
case 'GET':
|
|
1755
|
+
response = await this.httpClient.get(url, {
|
|
1756
|
+
headers,
|
|
1757
|
+
params: options?.body
|
|
1758
|
+
});
|
|
1759
|
+
break;
|
|
1760
|
+
case 'POST':
|
|
1761
|
+
response = await this.httpClient.post(url, options?.body, { headers });
|
|
1762
|
+
break;
|
|
1763
|
+
case 'PUT':
|
|
1764
|
+
response = await this.httpClient.put(url, options?.body, { headers });
|
|
1765
|
+
break;
|
|
1766
|
+
case 'PATCH':
|
|
1767
|
+
response = await this.httpClient.patch(url, options?.body, { headers });
|
|
1768
|
+
break;
|
|
1769
|
+
case 'DELETE':
|
|
1770
|
+
response = await this.httpClient.delete(url, {
|
|
1771
|
+
headers,
|
|
1772
|
+
data: options?.body
|
|
1773
|
+
});
|
|
1774
|
+
break;
|
|
1775
|
+
default:
|
|
1776
|
+
throw new EBaaSError(`Unsupported HTTP method: ${method}`, 400);
|
|
1777
|
+
}
|
|
1778
|
+
return {
|
|
1779
|
+
data: response.data,
|
|
1780
|
+
error: null
|
|
1781
|
+
};
|
|
1782
|
+
}
|
|
1783
|
+
catch (error) {
|
|
1784
|
+
return {
|
|
1785
|
+
data: null,
|
|
1786
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Function invocation failed', 0, error)
|
|
1787
|
+
};
|
|
1788
|
+
}
|
|
1789
|
+
}
|
|
1790
|
+
async list() {
|
|
1791
|
+
try {
|
|
1792
|
+
const response = await this.httpClient.get('/functions/v1');
|
|
1793
|
+
return {
|
|
1794
|
+
data: response.data,
|
|
1795
|
+
error: null
|
|
1796
|
+
};
|
|
1797
|
+
}
|
|
1798
|
+
catch (error) {
|
|
1799
|
+
return {
|
|
1800
|
+
data: null,
|
|
1801
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Failed to list functions', 0, error)
|
|
1802
|
+
};
|
|
1803
|
+
}
|
|
1804
|
+
}
|
|
1805
|
+
async get(functionName) {
|
|
1806
|
+
try {
|
|
1807
|
+
const response = await this.httpClient.get(`/functions/v1/${functionName}/info`);
|
|
1808
|
+
return {
|
|
1809
|
+
data: response.data,
|
|
1810
|
+
error: null
|
|
1811
|
+
};
|
|
1812
|
+
}
|
|
1813
|
+
catch (error) {
|
|
1814
|
+
return {
|
|
1815
|
+
data: null,
|
|
1816
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Failed to get function', 0, error)
|
|
1817
|
+
};
|
|
1818
|
+
}
|
|
1819
|
+
}
|
|
1820
|
+
async deploy(functionName, options) {
|
|
1821
|
+
try {
|
|
1822
|
+
const formData = new FormData();
|
|
1823
|
+
if (options.code instanceof File) {
|
|
1824
|
+
formData.append('code', options.code);
|
|
1825
|
+
}
|
|
1826
|
+
else if (typeof options.code === 'string') {
|
|
1827
|
+
formData.append('code', new Blob([options.code], { type: 'text/plain' }), 'index.ts');
|
|
1828
|
+
}
|
|
1829
|
+
if (options.entrypoint) {
|
|
1830
|
+
formData.append('entrypoint', options.entrypoint);
|
|
1831
|
+
}
|
|
1832
|
+
if (options.env) {
|
|
1833
|
+
formData.append('env', JSON.stringify(options.env));
|
|
1834
|
+
}
|
|
1835
|
+
if (options.importMap) {
|
|
1836
|
+
formData.append('importMap', JSON.stringify(options.importMap));
|
|
1837
|
+
}
|
|
1838
|
+
if (options.verify !== undefined) {
|
|
1839
|
+
formData.append('verify', String(options.verify));
|
|
1840
|
+
}
|
|
1841
|
+
const response = await this.httpClient.post(`/functions/v1/${functionName}/deploy`, formData, {
|
|
1842
|
+
headers: {
|
|
1843
|
+
'Content-Type': 'multipart/form-data'
|
|
1844
|
+
}
|
|
1845
|
+
});
|
|
1846
|
+
return {
|
|
1847
|
+
data: response.data,
|
|
1848
|
+
error: null
|
|
1849
|
+
};
|
|
1850
|
+
}
|
|
1851
|
+
catch (error) {
|
|
1852
|
+
return {
|
|
1853
|
+
data: null,
|
|
1854
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Failed to deploy function', 0, error)
|
|
1855
|
+
};
|
|
1856
|
+
}
|
|
1857
|
+
}
|
|
1858
|
+
async delete(functionName) {
|
|
1859
|
+
try {
|
|
1860
|
+
const response = await this.httpClient.delete(`/functions/v1/${functionName}`);
|
|
1861
|
+
return {
|
|
1862
|
+
data: response.data,
|
|
1863
|
+
error: null
|
|
1864
|
+
};
|
|
1865
|
+
}
|
|
1866
|
+
catch (error) {
|
|
1867
|
+
return {
|
|
1868
|
+
data: null,
|
|
1869
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Failed to delete function', 0, error)
|
|
1870
|
+
};
|
|
1871
|
+
}
|
|
1872
|
+
}
|
|
1873
|
+
async updateEnv(functionName, env) {
|
|
1874
|
+
try {
|
|
1875
|
+
const response = await this.httpClient.put(`/functions/v1/${functionName}/env`, { env });
|
|
1876
|
+
return {
|
|
1877
|
+
data: response.data,
|
|
1878
|
+
error: null
|
|
1879
|
+
};
|
|
1880
|
+
}
|
|
1881
|
+
catch (error) {
|
|
1882
|
+
return {
|
|
1883
|
+
data: null,
|
|
1884
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Failed to update function environment', 0, error)
|
|
1885
|
+
};
|
|
1886
|
+
}
|
|
1887
|
+
}
|
|
1888
|
+
async getLogs(functionName, options) {
|
|
1889
|
+
try {
|
|
1890
|
+
const params = new URLSearchParams();
|
|
1891
|
+
if (options?.limit) {
|
|
1892
|
+
params.append('limit', String(options.limit));
|
|
1893
|
+
}
|
|
1894
|
+
if (options?.offset) {
|
|
1895
|
+
params.append('offset', String(options.offset));
|
|
1896
|
+
}
|
|
1897
|
+
if (options?.level) {
|
|
1898
|
+
params.append('level', options.level);
|
|
1899
|
+
}
|
|
1900
|
+
const url = `/functions/v1/${functionName}/logs${params.toString() ? `?${params.toString()}` : ''}`;
|
|
1901
|
+
const response = await this.httpClient.get(url);
|
|
1902
|
+
return {
|
|
1903
|
+
data: response.data,
|
|
1904
|
+
error: null
|
|
1905
|
+
};
|
|
1906
|
+
}
|
|
1907
|
+
catch (error) {
|
|
1908
|
+
return {
|
|
1909
|
+
data: null,
|
|
1910
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Failed to get function logs', 0, error)
|
|
1911
|
+
};
|
|
1912
|
+
}
|
|
1913
|
+
}
|
|
1914
|
+
async getMetrics(functionName, options) {
|
|
1915
|
+
try {
|
|
1916
|
+
const params = new URLSearchParams();
|
|
1917
|
+
if (options?.period) {
|
|
1918
|
+
params.append('period', options.period);
|
|
1919
|
+
}
|
|
1920
|
+
const url = `/functions/v1/${functionName}/metrics${params.toString() ? `?${params.toString()}` : ''}`;
|
|
1921
|
+
const response = await this.httpClient.get(url);
|
|
1922
|
+
return {
|
|
1923
|
+
data: response.data,
|
|
1924
|
+
error: null
|
|
1925
|
+
};
|
|
1926
|
+
}
|
|
1927
|
+
catch (error) {
|
|
1928
|
+
return {
|
|
1929
|
+
data: null,
|
|
1930
|
+
error: error instanceof EBaaSError ? error : new EBaaSError(error instanceof Error ? error.message : 'Failed to get function metrics', 0, error)
|
|
1931
|
+
};
|
|
1932
|
+
}
|
|
1933
|
+
}
|
|
1934
|
+
}
|
|
1935
|
+
|
|
1936
|
+
class EBaaSClient {
|
|
1937
|
+
constructor(supabaseUrl, supabaseKey, options) {
|
|
1938
|
+
this.options = options;
|
|
1939
|
+
// Initialize HTTP client
|
|
1940
|
+
this.httpClient = new HttpClient({
|
|
1941
|
+
url: supabaseUrl,
|
|
1942
|
+
apiKey: supabaseKey,
|
|
1943
|
+
timeout: 30000,
|
|
1944
|
+
headers: options?.global?.headers
|
|
1945
|
+
});
|
|
1946
|
+
// Initialize all modules
|
|
1947
|
+
this.auth = new AuthClient(this.httpClient, options?.database?.workspaceId);
|
|
1948
|
+
this.database = new DatabaseClient(this.httpClient, options?.database?.workspaceId, options?.rest?.url);
|
|
1949
|
+
this.storage = new StorageClient(this.httpClient);
|
|
1950
|
+
this.realtime = new RealtimeClient(supabaseUrl, supabaseKey, options?.realtime);
|
|
1951
|
+
this.functions = new FunctionsClient(this.httpClient);
|
|
1952
|
+
// Initialize custom database detection if enabled
|
|
1953
|
+
this.initializeCustomDatabase();
|
|
1954
|
+
}
|
|
1955
|
+
// Convenience method for database access
|
|
1956
|
+
from(table) {
|
|
1957
|
+
return this.database.from(table);
|
|
1958
|
+
}
|
|
1959
|
+
// Convenience method for RPC calls
|
|
1960
|
+
rpc(fn, args) {
|
|
1961
|
+
return this.database.rpc(fn, args);
|
|
1962
|
+
}
|
|
1963
|
+
// Convenience method for storage bucket access
|
|
1964
|
+
bucket(id) {
|
|
1965
|
+
return this.storage.from(id);
|
|
1966
|
+
}
|
|
1967
|
+
// Convenience method for realtime channel access
|
|
1968
|
+
channel(name) {
|
|
1969
|
+
return this.realtime.channel(name);
|
|
1970
|
+
}
|
|
1971
|
+
// Convenience method for edge functions
|
|
1972
|
+
invoke(functionName, options) {
|
|
1973
|
+
return this.functions.invoke(functionName, options);
|
|
1974
|
+
}
|
|
1975
|
+
/**
|
|
1976
|
+
* Inicializa a detecção automática de banco customizado
|
|
1977
|
+
*/
|
|
1978
|
+
async initializeCustomDatabase() {
|
|
1979
|
+
if (this.options?.database?.autoDetectCustomDatabase) {
|
|
1980
|
+
try {
|
|
1981
|
+
await this.database.initialize();
|
|
1982
|
+
}
|
|
1983
|
+
catch (error) {
|
|
1984
|
+
console.warn('Failed to initialize custom database detection:', error);
|
|
1985
|
+
}
|
|
1986
|
+
}
|
|
1987
|
+
}
|
|
1988
|
+
/**
|
|
1989
|
+
* Atualiza o workspace ID para todos os módulos que precisam
|
|
1990
|
+
*/
|
|
1991
|
+
async setWorkspaceId(workspaceId) {
|
|
1992
|
+
this.auth.setWorkspaceId(workspaceId);
|
|
1993
|
+
this.database.setWorkspaceId(workspaceId);
|
|
1994
|
+
// Se auto-detecção estiver habilitada, re-detecta configuração para o novo workspace
|
|
1995
|
+
if (this.options?.database?.autoDetectCustomDatabase) {
|
|
1996
|
+
await this.database.initialize();
|
|
1997
|
+
}
|
|
1998
|
+
}
|
|
1999
|
+
/**
|
|
2000
|
+
* Configura credenciais customizadas diretamente
|
|
2001
|
+
*/
|
|
2002
|
+
async configureCustomDatabase(credentials) {
|
|
2003
|
+
await this.database.configureCustomDatabase(credentials);
|
|
2004
|
+
}
|
|
2005
|
+
/**
|
|
2006
|
+
* Retorna informações sobre o banco customizado
|
|
2007
|
+
*/
|
|
2008
|
+
getCustomDatabaseStatus() {
|
|
2009
|
+
return this.database.getCustomDatabaseStatus();
|
|
2010
|
+
}
|
|
2011
|
+
}
|
|
2012
|
+
// Factory function similar to Supabase's createClient
|
|
2013
|
+
function createClient(supabaseUrl, supabaseKey, options) {
|
|
2014
|
+
return new EBaaSClient(supabaseUrl, supabaseKey, options);
|
|
2015
|
+
}
|
|
2016
|
+
|
|
2017
|
+
// Main client export
|
|
2018
|
+
// Version
|
|
2019
|
+
const version = "1.1.8";
|
|
2020
|
+
|
|
2021
|
+
export { AuthClient, CustomDatabaseManager, DatabaseClient, EBaaSClient, EBaaSError, FunctionsClient, HttpClient, QueryBuilder, RealtimeChannel, RealtimeClient, StorageBucket, StorageClient, createClient, version };
|
|
2022
|
+
//# sourceMappingURL=index.esm.js.map
|