@univerjs-pro/collaboration-endpoint 1.0.0 → 1.0.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 CHANGED
@@ -1 +1 @@
1
- Object['defineProperty'](exports,Symbol['toStringTag'],{'value':'Module'});let e=require('node:crypto'),t=require('@univerjs-pro/collaboration-service'),n=require('@univerjs/protocol'),r=require('@univerjs-pro/collaboration-transport-node');var i={'CHANGESET_ACK':'changeset_ack','CHANGESET_REJ':'changeset_rej','CHANGESET_SHOULD_RETRY':'changeset_should_retry','NEW_CHANGESETS':'new_changesets','PERMISSION_REJ':'permission_rej','UPDATE_CURSOR':'update_cursor','USERS_ENTER':'users_enter','USERS_LEAVE':'users_leave'};function a(_0x1a2566,_0x47f4d9,_0x58fd76=''){return{'cmd':_0x1a2566,'code':n['CmdRspCode']['OK'],'reason':'success','routeKey':_0x58fd76,'infoRsp':{'memberID':_0x47f4d9}};}function o(_0x2cd3c7,_0x3dcf30,_0x5c2ef0,_0xe7325a){return{'cmd':n['CombCmd']['JOIN'],'code':_0x3dcf30,'reason':_0xe7325a,'routeKey':_0x2cd3c7,'joinRsp':{'roomInfos':_0x5c2ef0}};}function s(_0x22607a){return{'memberID':_0x22607a['memberID'],'userID':_0x22607a['userID'],'name':_0x22607a['name'],..._0x22607a['avatar']===void 0x0?{}:{'avatar':_0x22607a['avatar']}};}function c(_0x4cf1a4,_0x167e7b){return{'cmd':n['CombCmd']['RECV'],'code':n['CmdRspCode']['OK'],'reason':'success','routeKey':_0x4cf1a4,'collaMsg':_0x167e7b};}function l(_0x416400,_0x37101d){return c(_0x416400,{'eventID':i['USERS_ENTER'],'joinEvent':{..._0x37101d,'avatar':_0x37101d['avatar']??''}});}function u(_0x55d23b,_0x69601f){return c(_0x55d23b,{'eventID':i['USERS_LEAVE'],'leaveEvent':_0x69601f});}function d(_0x88d713,_0x4db448){return c(_0x88d713,{'eventID':i['UPDATE_CURSOR'],'updateCursorEvent':_0x4db448});}function f(_0x4e978a,_0x4538f0,_0x240eb1){let _0x20efa4={[i['CHANGESET_ACK']]:'csAckEvent',[i['CHANGESET_REJ']]:'csRejEvent',[i['CHANGESET_SHOULD_RETRY']]:'csShouldRetryEvent',[i['NEW_CHANGESETS']]:'newCsEvent',[i['PERMISSION_REJ']]:'permissionRejEvent'}[_0x4538f0];return c(_0x4e978a,{'eventID':_0x4538f0,[_0x20efa4]:{'cs':_0x240eb1}});}function p(_0x44d1bc,_0xc3e448,_0x133496){return c(_0x44d1bc,{..._0x133496,'eventID':_0xc3e448});}var m=class{['_middlewares']=new Map();['use'](_0x16448b,_0x5cf3f6){let _0x1187a6=this['_middlewares']['get'](_0x16448b)??[],_0x4ece2b=_0x5cf3f6;_0x1187a6['push'](_0x4ece2b),this['_middlewares']['set'](_0x16448b,_0x1187a6);let _0x249256=!0x1;return{'dispose':()=>{if(_0x249256)return;_0x249256=!0x0;let _0x340114=_0x1187a6['indexOf'](_0x4ece2b);_0x340114>=0x0&&_0x1187a6['splice'](_0x340114,0x1);}};}async['run'](_0x470129,_0x5861d3,_0x4e0c18){let _0x17bc95=[...this['_middlewares']['get'](_0x470129)??[]],_0x1bd1b5=async _0x5b2136=>{let _0x23ce26=_0x17bc95[_0x5b2136];if(!_0x23ce26){await _0x4e0c18();return;}let _0x4889fa=!0x1,_0x4d905e,_0x20cfaa=()=>{if(_0x4889fa)throw Error('Endpoint\x20middleware\x20for\x20'+String(_0x470129)+'\x20called\x20next()\x20more\x20than\x20once');return _0x4889fa=!0x0,_0x4d905e=_0x1bd1b5(_0x5b2136+0x1),_0x4d905e;};try{await _0x23ce26(_0x5861d3,_0x20cfaa);}catch(_0x428634){if(_0x4d905e)try{await _0x4d905e;}catch{}throw _0x428634;}if(!_0x4889fa)throw Error('Endpoint\x20middleware\x20for\x20'+String(_0x470129)+'\x20completed\x20without\x20calling\x20next()');await _0x4d905e;};await _0x1bd1b5(0x0);}['clear'](){this['_middlewares']['clear']();}},h={'code':n['ErrorCode']['OK'],'message':''};function g(_0x1ca71f,_0x5373a4){if(!/^-?\d+$/['test'](_0x1ca71f))throw new t['CollabError']('INVALID_REQUEST',_0x5373a4+'\x20must\x20be\x20an\x20integer');let _0x1040f8=Number(_0x1ca71f);if(!Number['isSafeInteger'](_0x1040f8))throw new t['CollabError']('INVALID_REQUEST',_0x5373a4+'\x20is\x20outside\x20the\x20safe\x20integer\x20range');return _0x1040f8;}function _(_0x11e721){if(_0x11e721 instanceof r['NodeTransportError'])return _0x11e721['code']==='REQUEST_BODY_TOO_LARGE'?{'status':0x19d,'error':{'code':n['ErrorCode']['INVALID_ARGUMENT'],'message':_0x11e721['message']}}:_0x11e721['code']==='INVALID_JSON'||_0x11e721['code']==='REQUEST_ABORTED'?{'status':0x190,'error':{'code':n['ErrorCode']['INVALID_ARGUMENT'],'message':_0x11e721['message']}}:{'status':0x1f7,'error':{'code':n['ErrorCode']['INTERNAL_ERROR'],'message':'Transport\x20unavailable'}};if(!(_0x11e721 instanceof t['CollabError']))return{'status':0x1f4,'error':{'code':n['ErrorCode']['INTERNAL_ERROR'],'message':'Internal\x20server\x20error'}};let _0x43f84d={'UNAUTHENTICATED':{'status':0x191,'code':n['ErrorCode']['UNAUTHENTICATED']},'INVALID_REQUEST':{'status':0x190,'code':n['ErrorCode']['INVALID_ARGUMENT']},'UNIT_NOT_FOUND':{'status':0x194,'code':n['ErrorCode']['NOT_FOUND']},'PERMISSION_DENIED':{'status':0x193,'code':n['ErrorCode']['PERMISSION_DENIED']},'OT_CONFLICT':{'status':0x199,'code':n['ErrorCode']['APPLY_REJECT']},'REVISION_MISMATCH':{'status':0x199,'code':n['ErrorCode']['CHANGESET_REVISION_CONFILICT']},'ADAPTER_FAILURE':{'status':0x1f7,'code':n['ErrorCode']['INTERNAL_ERROR']},'INTERNAL_ERROR':{'status':0x1f4,'code':n['ErrorCode']['INTERNAL_ERROR']}}[_0x11e721['code']];return{'status':_0x43f84d['status'],'error':{'code':_0x43f84d['code'],'message':_0x11e721['message']}};}function v(_0x22dd95,_0x43316a,_0x15c863){_0x22dd95['writableEnded']||_0x22dd95['destroyed']||(_0x22dd95['statusCode']=_0x43316a,_0x22dd95['setHeader']('content-type','application/json;\x20charset=utf-8'),_0x22dd95['end'](JSON['stringify'](_0x15c863,(_0x4ee84f,_0x56b9e7)=>_0x56b9e7 instanceof Uint8Array?Buffer['from'](_0x56b9e7)['toString']('base64'):_0x56b9e7)));}var y=class{['_tickets']=new Map();['_disposed']=!0x1;async['issue'](_0x1c25b1,_0x3dd8e8){if(this['_disposed'])throw Error('Session\x20ticket\x20store\x20is\x20disposed');if(!Number['isSafeInteger'](_0x3dd8e8)||_0x3dd8e8<=0x0)throw TypeError('Session\x20ticket\x20TTL\x20must\x20be\x20a\x20positive\x20safe\x20integer');this['_purgeExpired']();let _0x3f4170;do _0x3f4170=(0x0,e['randomBytes'])(0x20)['toString']('base64url');while(this['_tickets']['has'](_0x3f4170));return this['_tickets']['set'](_0x3f4170,{'record':_0x1c25b1,'expiresAt':Date['now']()+_0x3dd8e8}),_0x3f4170;}async['consume'](_0x5f2e19){if(this['_disposed']||!_0x5f2e19)return null;let _0x40d176=this['_tickets']['get'](_0x5f2e19);return!_0x40d176||(this['_tickets']['delete'](_0x5f2e19),_0x40d176['expiresAt']<=Date['now']())?null:_0x40d176['record'];}async['dispose'](){this['_disposed']||(this['_disposed']=!0x0,this['_tickets']['clear']());}['_purgeExpired'](){let _0x576615=Date['now']();for(let [_0x4b4faa,_0x3dd4fa]of this['_tickets'])_0x3dd4fa['expiresAt']<=_0x576615&&this['_tickets']['delete'](_0x4b4faa);}},b=0x5*0xea60;function x(_0xa83720){if(!_0xa83720['startsWith']('/')||_0xa83720==='/'||_0xa83720['endsWith']('/')||_0xa83720['includes']('?')||_0xa83720['includes']('#'))throw TypeError('protocolBasePath\x20must\x20be\x20an\x20absolute\x20path\x20without\x20a\x20trailing\x20slash');return _0xa83720;}function S(_0x31921f){if(!_0x31921f||typeof _0x31921f!='object')throw new t['CollabError']('INVALID_REQUEST','Request\x20body\x20must\x20be\x20an\x20object');let _0x461a90=_0x31921f;if(typeof _0x461a90['unitID']!='string'||typeof _0x461a90['memberID']!='string'||!Number['isSafeInteger'](_0x461a90['type'])||!_0x461a90['changeset']||typeof _0x461a90['changeset']!='object')throw new t['CollabError']('INVALID_REQUEST','Invalid\x20new\x20changes\x20request');}function C(_0x16f2c9){if(!Array['isArray'](_0x16f2c9)||_0x16f2c9['length']===0x0||_0x16f2c9['some'](_0x51d6dc=>typeof _0x51d6dc!='string'||_0x51d6dc['trim']()['length']===0x0))throw new t['CollabError']('INVALID_REQUEST','unitIds\x20must\x20be\x20a\x20non-empty\x20string\x20array');}function w(_0x320714){let _0x3d2680=_0x320714['getAll']('unitIds');C(_0x3d2680);let _0x1806e7=_0x320714['getAll']('hardDelete');if(_0x1806e7['length']>0x1||_0x1806e7['length']===0x1&&_0x1806e7[0x0]!=='true'&&_0x1806e7[0x0]!=='false')throw new t['CollabError']('INVALID_REQUEST','hardDelete\x20must\x20be\x20true\x20or\x20false');return{'unitIds':_0x3d2680,'hardDelete':_0x1806e7[0x0]==='true'};}function T(_0x560a65){if(!_0x560a65||typeof _0x560a65!='object')throw new t['CollabError']('INVALID_REQUEST','Request\x20body\x20must\x20be\x20an\x20object');C(_0x560a65['unitIds']);}var E=class{['_service'];['_middleware']=new m();['_listeners']=new Map();['_bindingsByConnection']=new Map();['_bindingsByMember']=new Map();['_rooms']=new Map();['_outboundQueues']=new Map();['_ticketStore'];['_ownsTicketStore'];['_ticketTtlMs'];['_protocolBasePath'];['_serviceSubscriptions'];['_deletedUnitIDs']=new Set();['_disposed']=!0x1;constructor(_0x5d61d2,_0x5789a7={}){if(this['_service']=_0x5d61d2,!_0x5d61d2)throw TypeError('UniverCollabEndpoint\x20requires\x20a\x20service');if(this['_ticketStore']=_0x5789a7['ticketStore']??new y(),this['_ownsTicketStore']=_0x5789a7['ticketStore']===void 0x0,this['_ticketTtlMs']=_0x5789a7['sessionTicketTtlMs']??b,!Number['isSafeInteger'](this['_ticketTtlMs'])||this['_ticketTtlMs']<=0x0)throw TypeError('sessionTicketTtlMs\x20must\x20be\x20a\x20positive\x20safe\x20integer');this['_protocolBasePath']=x(_0x5789a7['protocolBasePath']??'/universer-api'),this['_serviceSubscriptions']=[this['_service']['on']('changesetCommitted',_0x31fc5d=>{this['_enqueueCommittedChangeset'](_0x31fc5d['changeset'],_0x31fc5d['memberID']);}),this['_service']['on']('unitsDeleted',_0x563c93=>{for(let _0x4125d6 of _0x563c93['request']['unitIDs'])this['_deletedUnitIDs']['add'](_0x4125d6);for(let _0x39631c of _0x563c93['request']['unitIDs'])this['_enqueueUnitOutbound'](_0x39631c,async()=>{this['_evictUnitRoom'](_0x39631c);});}),this['_service']['on']('unitsRecovered',async _0x10c727=>{await Promise['all'](_0x10c727['request']['unitIDs']['map'](_0xa78841=>this['_enqueueUnitOutbound'](_0xa78841,async()=>{this['_deletedUnitIDs']['delete'](_0xa78841);})));})];}['use'](_0x4547cb,_0x29dff6){return this['_assertRunning'](),this['_middleware']['use'](_0x4547cb,_0x29dff6);}['on'](_0x35943f,_0x2b3c68){this['_assertRunning']();let _0xf06b1e=this['_listeners']['get'](_0x35943f)??new Set(),_0x460e22=_0x2b3c68;_0xf06b1e['add'](_0x460e22),this['_listeners']['set'](_0x35943f,_0xf06b1e);let _0x2e8e24=!0x1;return{'dispose':()=>{_0x2e8e24||(_0x2e8e24=!0x0,_0xf06b1e['delete'](_0x460e22));}};}['findJoinedSession'](_0xc1c898){if(this['_disposed'])return null;let _0x346e0e=this['_bindingsByMember']['get'](_0xc1c898['memberID']);return!_0x346e0e||_0x346e0e['session']['userID']!==_0xc1c898['authenticatedUserID']||!_0x346e0e['joinedUnitIDs']['has'](_0xc1c898['unitID'])?null:_0x346e0e['session'];}['findJoinedSessionByUser'](_0x2aed05){if(this['_disposed'])return null;for(let _0x139e16 of this['_rooms']['get'](_0x2aed05['unitID'])?.['values']()??[])if(_0x139e16['session']['userID']===_0x2aed05['authenticatedUserID'])return _0x139e16['session'];return null;}async['invalidateUnitSessions'](_0x4193a0){if(this['_assertRunning'](),typeof _0x4193a0['unitID']!='string'||!_0x4193a0['unitID'])throw TypeError('unitID\x20must\x20be\x20a\x20non-empty\x20string');if(_0x4193a0['userID']!==void 0x0&&(typeof _0x4193a0['userID']!='string'||!_0x4193a0['userID']))throw TypeError('userID\x20must\x20be\x20a\x20non-empty\x20string\x20when\x20provided');await this['_enqueueUnitOutbound'](_0x4193a0['unitID'],async()=>{let _0x2c62fe=[...this['_rooms']['get'](_0x4193a0['unitID'])?.['values']()??[]]['filter'](_0xb7039=>_0x4193a0['userID']===void 0x0||_0xb7039['session']['userID']===_0x4193a0['userID']);for(let _0x2413f1 of _0x2c62fe)_0x2413f1['connection']['close'](0xfa3,'Unit\x20access\x20changed'),await this['_disconnectBinding'](_0x2413f1,'session-evicted');});}async['publishTrustedUnitEvent'](_0xd06b27){this['_assertRunning']();let _0x7ca261=[...this['_rooms']['get'](_0xd06b27['unitID'])?.['keys']()??[]],_0x2c5d06=this['_bindingsByMember']['get'](_0xd06b27['memberID'])?.['joinedUnitIDs']['has'](_0xd06b27['unitID'])?_0xd06b27['memberID']:void 0x0,_0x529018=p(_0xd06b27['unitID'],_0xd06b27['eventID'],_0xd06b27['data']);this['_enqueueUnitOutbound'](_0xd06b27['unitID'],async()=>{for(let _0x174a40 of _0x7ca261){if(_0x174a40===_0x2c5d06)continue;let _0x63b3e5=this['_bindingsByMember']['get'](_0x174a40);_0x63b3e5?.['joinedUnitIDs']['has'](_0xd06b27['unitID'])&&await this['_safeSend'](_0x63b3e5['connection'],_0x529018);}});}['register'](_0x189358){this['_assertRunning']();let _0x9266b1=this['_protocolBasePath'],_0x5012e0=_0x502909=>_0x52c476=>this['_handleHttp'](_0x52c476,_0x502909);_0x189358['get'](_0x9266b1+'/user/session-ticket',_0x5012e0('ticket')),_0x189358['delete'](_0x9266b1+'/snapshot/-/units',_0x5012e0('delete-units')),_0x189358['post'](_0x9266b1+'/snapshot/-/units/recover',_0x5012e0('recover-units')),_0x189358['post'](_0x9266b1+'/comb/:type/unit/:unitID/new_changes',_0x5012e0('new-changes')),_0x189358['get'](_0x9266b1+'/snapshot/block/:type/unit/:unitID/block/:blockID',_0x5012e0('deserialized-block')),_0x189358['get'](_0x9266b1+'/snapshot/:type/unit/:unitID/rev/:revision',_0x5012e0('unit')),_0x189358['get'](_0x9266b1+'/snapshot/:type/unit/:unitID/block/:blockID',_0x5012e0('block')),_0x189358['get'](_0x9266b1+'/snapshot/:type/unit/:unitID/fetchmissing',_0x5012e0('fetch-missing')),_0x189358['upgrade'](_0x9266b1+'/comb/connect',_0x13a4eb=>this['_handleUpgrade'](_0x13a4eb));}async['_handleUpgrade'](_0x15b911){if(this['_disposed']){_0x15b911['reject'](0x1f7,'Endpoint\x20is\x20disposed');return;}let _0x3cc7ad=new URL(_0x15b911['incomingMessage']['url']??'/','http://localhost'),_0x1db683=await this['_ticketStore']['consume'](_0x3cc7ad['searchParams']['get']('sessionTicket')??'');if(!_0x1db683){_0x15b911['reject'](0x191,'Invalid\x20or\x20expired\x20session\x20ticket');return;}_0x15b911['accept']({'open':({connection:_0x340aaf})=>this['_openConnection'](_0x1db683,_0x340aaf),'message':_0x5f14d0=>this['_handleMessage'](_0x5f14d0),'close':({connection:_0xf02477})=>this['_disconnectConnection'](_0xf02477,'connection-closed')});}async['dispose'](){if(this['_disposed'])return;this['_disposed']=!0x0;for(let _0x2ee950 of this['_serviceSubscriptions'])_0x2ee950['dispose']();await Promise['allSettled']([...this['_outboundQueues']['values']()]);let _0x1ada70=[...this['_bindingsByConnection']['values']()];for(let _0x2660aa of _0x1ada70)await this['_disconnectBinding'](_0x2660aa,'endpoint-disposed'),_0x2660aa['connection']['close'](0x3e9,'Endpoint\x20disposed');this['_bindingsByConnection']['clear'](),this['_bindingsByMember']['clear'](),this['_rooms']['clear'](),this['_outboundQueues']['clear'](),this['_middleware']['clear'](),this['_listeners']['clear'](),this['_ownsTicketStore']&&await this['_ticketStore']['dispose']?.();}async['_handleHttp'](_0x1a6e39,_0x3e744b){try{this['_assertRunning']();let _0x47d33d=new URL(_0x1a6e39['incomingMessage']['url']??'/','http://localhost');if(!_0x1a6e39['userID'])throw new t['CollabError']('UNAUTHENTICATED','HTTP\x20user\x20is\x20not\x20authenticated');if(_0x3e744b==='ticket'){let _0x4926a3=await this['_ticketStore']['issue']({'userID':_0x1a6e39['userID'],'customData':_0x1a6e39['customData']},this['_ticketTtlMs']);v(_0x1a6e39['response'],0xc8,{'error':h,'ticket':_0x4926a3});return;}let _0x34eae0={'userID':_0x1a6e39['userID'],'customData':_0x1a6e39['customData']};if(_0x3e744b==='delete-units'){let _0x1209e5=w(_0x47d33d['searchParams']);await this['_service']['deleteUnits']({'unitIDs':_0x1209e5['unitIds'],'hardDelete':_0x1209e5['hardDelete']},_0x34eae0),v(_0x1a6e39['response'],0xc8,{'error':h});return;}if(_0x3e744b==='recover-units'){let _0x263e99=await _0x1a6e39['readJson']();T(_0x263e99),await this['_service']['recoverUnits']({'unitIDs':_0x263e99['unitIds']},_0x34eae0),v(_0x1a6e39['response'],0xc8,{'error':h});return;}let _0x338457=g(_0x1a6e39['params']['type'],'type'),_0x574d2=_0x1a6e39['params']['unitID'];if(_0x3e744b==='new-changes'){await this['_handleNewChanges'](_0x1a6e39,_0x574d2,_0x338457);return;}switch(_0x3e744b){case'unit':{let _0x3db0d5=g(_0x1a6e39['params']['revision'],'revision'),_0x3b7719=await this['_service']['getUnitLoadData']({'unitID':_0x574d2,'type':_0x338457,'revision':_0x3db0d5},_0x34eae0);v(_0x1a6e39['response'],0xc8,{'error':h,'snapshot':_0x3b7719['snapshot'],'changesets':_0x3b7719['changesets']});return;}case'block':case'deserialized-block':{let _0x2bc931=await this['_service']['getSheetBlock']({'unitID':_0x574d2,'type':_0x338457,'blockID':_0x1a6e39['params']['blockID']},_0x34eae0);if(!_0x2bc931['block'])throw new t['CollabError']('UNIT_NOT_FOUND','Sheet\x20block\x20was\x20not\x20found');let _0x2ad549=_0x3e744b==='deserialized-block'?{..._0x2bc931['block'],'data':JSON['parse'](new TextDecoder()['decode'](_0x2bc931['block']['data']))}:_0x2bc931['block'];v(_0x1a6e39['response'],0xc8,{'error':h,'block':_0x2ad549});return;}case'fetch-missing':{let _0x58072b=g(_0x47d33d['searchParams']['get']('from')??'','from'),_0x383583=g(_0x47d33d['searchParams']['get']('to')??'','to'),_0x49fdf3=await this['_service']['getChangesets']({'unitID':_0x574d2,'type':_0x338457,'from':_0x58072b,'to':_0x383583},_0x34eae0);v(_0x1a6e39['response'],0xc8,{'error':h,'changesets':_0x49fdf3['changesets']});return;}}}catch(_0x194380){let _0x1ef186=_(_0x194380 instanceof SyntaxError?new t['CollabError']('INTERNAL_ERROR','Stored\x20sheet\x20block\x20is\x20not\x20valid\x20JSON',{'cause':_0x194380}):_0x194380);v(_0x1a6e39['response'],_0x1ef186['status'],{'error':_0x1ef186['error']});}}async['_openConnection'](_0xcb73df,_0x4f3026){try{let _0x435fae=(0x0,e['randomUUID'])(),_0x28ba7a={'memberID':_0x435fae,'userID':_0xcb73df['userID'],'customData':_0xcb73df['customData']},_0x24c10b={'memberID':_0x435fae,'userID':_0xcb73df['userID'],'name':_0xcb73df['userID']},_0x1c2fbb={'connection':_0x4f3026,'session':_0x28ba7a,'member':_0x24c10b};await this['_middleware']['run']('connect',_0x1c2fbb,()=>void 0x0);let _0x1d19d0={'connection':_0x4f3026,'session':_0x28ba7a,'member':_0x24c10b,'joinedUnitIDs':new Set()};this['_bindingsByConnection']['set'](_0x4f3026['id'],_0x1d19d0),this['_bindingsByMember']['set'](_0x435fae,_0x1d19d0);}catch(_0x3dac72){_0x4f3026['close'](_0x3dac72 instanceof t['CollabError']?0x3f0:0x3f3,_0x3dac72 instanceof t['CollabError']?'Connection\x20rejected':'Endpoint\x20failure');}}async['_handleMessage'](_0x1c5d2e){let _0x220889=this['_bindingsByConnection']['get'](_0x1c5d2e['connection']['id']);if(!_0x220889){_0x1c5d2e['connection']['close'](0x3f0,'WebSocket\x20Session\x20is\x20not\x20established');return;}if(typeof _0x1c5d2e['data']!='string'){_0x1c5d2e['connection']['close'](0x3eb,'Comb\x20messages\x20must\x20be\x20JSON\x20text');return;}let _0x145e9c;try{let _0x25b224=JSON['parse'](_0x1c5d2e['data']);if(!_0x25b224||typeof _0x25b224!='object')throw Error('invalid');_0x145e9c=_0x25b224;}catch{_0x1c5d2e['connection']['close'](0x3eb,'Invalid\x20Comb\x20JSON\x20message');return;}let _0x5ea736=typeof _0x145e9c['routeKey']=='string'?_0x145e9c['routeKey']:'';switch(_0x145e9c['cmd']){case n['CombCmd']['HELLO']:case n['CombCmd']['HEARTBEAT']:await _0x1c5d2e['connection']['send'](JSON['stringify'](a(_0x145e9c['cmd'],_0x220889['member']['memberID'],_0x5ea736)));return;case n['CombCmd']['JOIN']:await this['_handleJoin'](_0x220889,_0x145e9c,_0x5ea736);return;case n['CombCmd']['LEAVE']:await this['_handleLeave'](_0x220889,_0x145e9c,_0x5ea736);return;case n['CombCmd']['INGEST']:if(_0x145e9c['collaMsg']?.['eventID']!==i['UPDATE_CURSOR'])return;await this['_handlePresence'](_0x220889,_0x145e9c,_0x1c5d2e['customData']);return;default:return;}}async['_handleJoin'](_0x33fc33,_0x4e8e6a,_0x3508f5){let _0x252570=_0x4e8e6a['joinReq']?.['rooms'],_0x42d6d2=_0x252570?.['length']?_0x252570['map'](_0x47385e=>_0x47385e['roomID']):_0x3508f5?[_0x3508f5]:[];if(_0x42d6d2['length']===0x0||_0x42d6d2['some'](_0x127387=>typeof _0x127387!='string'||!_0x127387)){await _0x33fc33['connection']['send'](JSON['stringify'](o(_0x3508f5,n['CmdRspCode']['FAIL'],{},'Invalid\x20JOIN\x20request')));return;}let _0x21b96d=[...new Set(_0x42d6d2)],_0x29e21d=_0x21b96d['filter'](_0x38bbf0=>!_0x33fc33['joinedUnitIDs']['has'](_0x38bbf0));try{for(let _0x7b9899 of _0x21b96d)this['_assertJoinable'](_0x7b9899);for(let _0x4fe3a9 of _0x29e21d)await this['_middleware']['run']('joinUnit',{'session':_0x33fc33['session'],'unitID':_0x4fe3a9},()=>void 0x0);for(let _0xa8433a of _0x21b96d)this['_assertJoinable'](_0xa8433a);}catch(_0x2fa002){let _0x12c639=_0x2fa002 instanceof t['CollabError']&&_0x2fa002['code']==='UNIT_NOT_FOUND'?n['CmdRspCode']['JOIN_ROOM_NOT_EXISTS']:_0x2fa002 instanceof t['CollabError']&&(_0x2fa002['code']==='PERMISSION_DENIED'||_0x2fa002['code']==='UNAUTHENTICATED')?n['CmdRspCode']['JOIN_ROOM_PERMISSION_DENIED']:n['CmdRspCode']['FAIL'];await _0x33fc33['connection']['send'](JSON['stringify'](o(_0x3508f5||_0x21b96d[0x0],_0x12c639,{},_0x2fa002 instanceof t['CollabError']?_0x2fa002['message']:'JOIN\x20failed')));return;}for(let _0x77a20c of _0x29e21d){let _0x3a7dcb=this['_rooms']['get'](_0x77a20c)??new Map();_0x3a7dcb['set'](_0x33fc33['member']['memberID'],_0x33fc33),this['_rooms']['set'](_0x77a20c,_0x3a7dcb),_0x33fc33['joinedUnitIDs']['add'](_0x77a20c);}let _0x376adf={};for(let _0x435a88 of _0x21b96d)_0x376adf[_0x435a88]={'roomID':_0x435a88,'members':[...this['_rooms']['get'](_0x435a88)?.['values']()??[]]['map'](_0x963b2e=>s(_0x963b2e['member']))};await _0x33fc33['connection']['send'](JSON['stringify'](o(_0x3508f5||_0x21b96d[0x0],n['CmdRspCode']['OK'],_0x376adf,'success')));for(let _0x83ba25 of _0x29e21d)await this['_broadcastToRoom'](_0x83ba25,l(_0x83ba25,s(_0x33fc33['member'])),_0x33fc33['member']['memberID']);}async['_handleLeave'](_0x500a38,_0x5d40c9,_0x235808){let _0x28ed4b=typeof _0x5d40c9['leaveReq']?.['roomID']=='string'?_0x5d40c9['leaveReq']['roomID']:_0x235808;_0x28ed4b&&await this['_leaveUnit'](_0x500a38,_0x28ed4b,'client-leave');}async['_handlePresence'](_0x49ab8b,_0x2d58cf,_0x53bb57){let _0x32c054=typeof _0x2d58cf['routeKey']=='string'?_0x2d58cf['routeKey']:'',_0x1363d9=_0x2d58cf['collaMsg']?.['updateCursorEvent']?.['selection'];if(!_0x32c054||!_0x49ab8b['joinedUnitIDs']['has'](_0x32c054)||typeof _0x1363d9!='string')return;let _0x44a892={'unitID':_0x32c054,'memberID':_0x49ab8b['member']['memberID'],'selection':_0x1363d9};try{await this['_middleware']['run']('receivePresence',{'session':_0x49ab8b['session'],'unitID':_0x32c054,'payload':_0x44a892,'customData':_0x53bb57},()=>void 0x0);}catch(_0x5639a9){if(_0x5639a9 instanceof t['CollabError'])return;throw _0x5639a9;}if(typeof _0x44a892['selection']!='string')return;let _0x3fc2e5=[...this['_rooms']['get'](_0x32c054)?.['values']()??[]]['filter'](_0x3d3997=>_0x3d3997!==_0x49ab8b);for(let _0x203e04 of _0x3fc2e5){let _0x24af1e={'unitID':_0x32c054,'memberID':_0x49ab8b['member']['memberID'],'selection':_0x44a892['selection']};try{await this['_middleware']['run']('sendPresence',{'session':_0x49ab8b['session'],'unitID':_0x32c054,'payload':_0x24af1e,'customData':_0x53bb57,'targetMemberID':_0x203e04['member']['memberID']},()=>void 0x0);}catch{continue;}typeof _0x24af1e['selection']=='string'&&await this['_safeSend'](_0x203e04['connection'],d(_0x32c054,{'unitID':_0x32c054,'memberID':_0x49ab8b['member']['memberID'],'selection':_0x24af1e['selection']}));}}async['_handleNewChanges'](_0x4fcd18,_0x2ac2cd,_0x1463e9){let _0xb04559=await _0x4fcd18['readJson']();if(S(_0xb04559),_0xb04559['unitID']!==_0x2ac2cd||_0xb04559['type']!==_0x1463e9||_0xb04559['changeset']?.['unitID']!==_0x2ac2cd||_0xb04559['changeset']['type']!==_0x1463e9)throw new t['CollabError']('INVALID_REQUEST','Route,\x20request\x20and\x20changeset\x20identity\x20must\x20match');let _0x3e33e5=this['_bindingsByMember']['get'](_0xb04559['memberID']);if(!_0x3e33e5||_0x3e33e5['session']['userID']!==_0x4fcd18['userID'])throw new t['CollabError']('PERMISSION_DENIED','memberID\x20does\x20not\x20belong\x20to\x20the\x20authenticated\x20user');if(!_0x3e33e5['joinedUnitIDs']['has'](_0x2ac2cd))throw new t['CollabError']('PERMISSION_DENIED','Session\x20has\x20not\x20joined\x20this\x20unit');let _0x574035=await this['_service']['submitChangeset']({'changeset':_0xb04559['changeset']},{'userID':_0x4fcd18['userID'],'memberID':_0x3e33e5['session']['memberID'],'customData':_0x4fcd18['customData']});if(_0x574035['status']==='already-committed')await this['_safeSend'](_0x3e33e5['connection'],f(_0x2ac2cd,i['CHANGESET_ACK'],_0x574035['changeset']));else{if(_0x574035['status']==='rejected'){let _0x225e7f=_0x574035['error']['code']==='PERMISSION_DENIED'||_0x574035['error']['code']==='UNAUTHENTICATED'?i['PERMISSION_REJ']:i['CHANGESET_REJ'];await this['_safeSend'](_0x3e33e5['connection'],f(_0x2ac2cd,_0x225e7f,this['_trustedClientChangeset'](_0xb04559['changeset'],_0x3e33e5)));}else _0x574035['status']==='retry'&&await this['_safeSend'](_0x3e33e5['connection'],f(_0x2ac2cd,i['CHANGESET_SHOULD_RETRY'],this['_trustedClientChangeset'](_0xb04559['changeset'],_0x3e33e5)));}v(_0x4fcd18['response'],0xc8,{'error':h});}['_trustedClientChangeset'](_0x40b6f1,_0x14b829){return{..._0x40b6f1,'userID':_0x14b829['session']['userID'],'memberID':_0x14b829['session']['memberID']};}['_enqueueCommittedChangeset'](_0x1864fc,_0x3cf3be){if(this['_disposed'])return;let _0x212725=_0x1864fc['unitID'],_0x394b6c=[...this['_rooms']['get'](_0x212725)?.['keys']()??[]];this['_enqueueUnitOutbound'](_0x212725,async()=>{for(let _0x1dbd00 of _0x394b6c){let _0x554ec7=this['_bindingsByMember']['get'](_0x1dbd00);if(!_0x554ec7?.['joinedUnitIDs']['has'](_0x212725))continue;let _0x5425fd=_0x1dbd00===_0x3cf3be?i['CHANGESET_ACK']:i['NEW_CHANGESETS'];await this['_safeSend'](_0x554ec7['connection'],f(_0x212725,_0x5425fd,_0x1864fc));}});}['_evictUnitRoom'](_0x55676c){let _0x5a40ec=this['_rooms']['get'](_0x55676c);if(_0x5a40ec){this['_rooms']['delete'](_0x55676c);for(let _0x1f9a5f of _0x5a40ec['values']())_0x1f9a5f['joinedUnitIDs']['delete'](_0x55676c);}}['_enqueueUnitOutbound'](_0x3f9afc,_0x12b8a8){let _0x5aa25b=(this['_outboundQueues']['get'](_0x3f9afc)??Promise['resolve']())['catch'](()=>void 0x0)['then'](_0x12b8a8);return this['_outboundQueues']['set'](_0x3f9afc,_0x5aa25b),_0x5aa25b['finally'](()=>{this['_outboundQueues']['get'](_0x3f9afc)===_0x5aa25b&&this['_outboundQueues']['delete'](_0x3f9afc);}),_0x5aa25b;}async['_disconnectConnection'](_0x182dc2,_0x50965c){let _0xbc39bc=this['_bindingsByConnection']['get'](_0x182dc2['id']);_0xbc39bc&&await this['_disconnectBinding'](_0xbc39bc,_0x50965c);}async['_disconnectBinding'](_0x4ccf3c,_0x554404){this['_bindingsByConnection']['delete'](_0x4ccf3c['connection']['id']),this['_bindingsByMember']['delete'](_0x4ccf3c['member']['memberID']);let _0x203817=[..._0x4ccf3c['joinedUnitIDs']];for(let _0x5c035c of _0x203817)await this['_leaveUnit'](_0x4ccf3c,_0x5c035c,_0x554404);}async['_leaveUnit'](_0x27af92,_0x2c57b5,_0x9c6593){if(!_0x27af92['joinedUnitIDs']['delete'](_0x2c57b5))return!0x1;let _0x589100=this['_rooms']['get'](_0x2c57b5);return _0x589100?.['delete'](_0x27af92['member']['memberID']),_0x589100?.['size']===0x0&&this['_rooms']['delete'](_0x2c57b5),await this['_broadcastToRoom'](_0x2c57b5,u(_0x2c57b5,{'memberID':_0x27af92['member']['memberID'],'name':_0x27af92['member']['name']}),_0x27af92['member']['memberID']),await this['_emit']('memberLeftUnit',{'session':_0x27af92['session'],'unitID':_0x2c57b5,'reason':_0x9c6593}),!0x0;}async['_broadcastToRoom'](_0x515cc0,_0x170d1f,_0x4e2959){let _0x45b478=[...this['_rooms']['get'](_0x515cc0)?.['values']()??[]];await Promise['allSettled'](_0x45b478['filter'](_0x254379=>_0x254379['member']['memberID']!==_0x4e2959)['map'](_0x5a710d=>this['_safeSend'](_0x5a710d['connection'],_0x170d1f)));}async['_safeSend'](_0x331b1c,_0x311543){try{await _0x331b1c['send'](JSON['stringify'](_0x311543));}catch{}}async['_emit'](_0x6fd9e4,_0x38c738){let _0x5c9b54=[...this['_listeners']['get'](_0x6fd9e4)??[]];for(let _0xdca2a5 of _0x5c9b54)try{await _0xdca2a5(_0x38c738);}catch{}}['_assertRunning'](){if(this['_disposed'])throw Error('UniverCollabEndpoint\x20is\x20disposed');}['_assertJoinable'](_0x2c1c4f){if(this['_deletedUnitIDs']['has'](_0x2c1c4f))throw new t['CollabError']('UNIT_NOT_FOUND','Unit\x20has\x20been\x20deleted');}};exports['MemorySessionTicketStore']=y,exports['UniverCollabEndpoint']=E;
1
+ Object['defineProperty'](exports,Symbol['toStringTag'],{'value':'Module'});let e=require('node:crypto'),t=require('@univerjs-pro/collaboration-service'),n=require('@univerjs/protocol'),r=require('@univerjs-pro/collaboration-transport-node');var i={'CHANGESET_ACK':'changeset_ack','CHANGESET_REJ':'changeset_rej','CHANGESET_SHOULD_RETRY':'changeset_should_retry','NEW_CHANGESETS':'new_changesets','PERMISSION_REJ':'permission_rej','UPDATE_CURSOR':'update_cursor','USERS_ENTER':'users_enter','USERS_LEAVE':'users_leave'};function a(_0x3b5a25,_0x199040,_0x1d8ac0=''){return{'cmd':_0x3b5a25,'code':n['CmdRspCode']['OK'],'reason':'success','routeKey':_0x1d8ac0,'infoRsp':{'memberID':_0x199040}};}function o(_0x2459fc,_0x520050,_0x3ad4dc,_0xb220cd){return{'cmd':n['CombCmd']['JOIN'],'code':_0x520050,'reason':_0xb220cd,'routeKey':_0x2459fc,'joinRsp':{'roomInfos':_0x3ad4dc}};}function s(_0x44d46e){return{'memberID':_0x44d46e['memberID'],'userID':_0x44d46e['userID'],'name':_0x44d46e['name'],..._0x44d46e['avatar']===void 0x0?{}:{'avatar':_0x44d46e['avatar']}};}function c(_0x525f65,_0x57e5d7){return{'cmd':n['CombCmd']['RECV'],'code':n['CmdRspCode']['OK'],'reason':'success','routeKey':_0x525f65,'collaMsg':_0x57e5d7};}function l(_0x2929bf,_0x1a3d15){return c(_0x2929bf,{'eventID':i['USERS_ENTER'],'joinEvent':{..._0x1a3d15,'avatar':_0x1a3d15['avatar']??''}});}function u(_0x191492,_0x4c4f10){return c(_0x191492,{'eventID':i['USERS_LEAVE'],'leaveEvent':_0x4c4f10});}function d(_0xc6479f,_0x1d19c3){return c(_0xc6479f,{'eventID':i['UPDATE_CURSOR'],'updateCursorEvent':_0x1d19c3});}function f(_0x226f9e,_0x3b8867,_0xeb8d20){let _0x5b639b={[i['CHANGESET_ACK']]:'csAckEvent',[i['CHANGESET_REJ']]:'csRejEvent',[i['CHANGESET_SHOULD_RETRY']]:'csShouldRetryEvent',[i['NEW_CHANGESETS']]:'newCsEvent',[i['PERMISSION_REJ']]:'permissionRejEvent'}[_0x3b8867];return c(_0x226f9e,{'eventID':_0x3b8867,[_0x5b639b]:{'cs':_0xeb8d20}});}function p(_0x22cc61,_0x2c2faf,_0x4dfebc){return c(_0x22cc61,{..._0x4dfebc,'eventID':_0x2c2faf});}var m=class{['_middlewares']=new Map();['use'](_0x5ed542,_0x9ba20d){let _0x1a43c7=this['_middlewares']['get'](_0x5ed542)??[],_0x48e132=_0x9ba20d;_0x1a43c7['push'](_0x48e132),this['_middlewares']['set'](_0x5ed542,_0x1a43c7);let _0x1e5433=!0x1;return{'dispose':()=>{if(_0x1e5433)return;_0x1e5433=!0x0;let _0x34fa0a=_0x1a43c7['indexOf'](_0x48e132);_0x34fa0a>=0x0&&_0x1a43c7['splice'](_0x34fa0a,0x1);}};}async['run'](_0x588a67,_0x19f9e5,_0x15ab38){let _0x10fa65=[...this['_middlewares']['get'](_0x588a67)??[]],_0x2ece91=async _0x33c27e=>{let _0x20f2a1=_0x10fa65[_0x33c27e];if(!_0x20f2a1){await _0x15ab38();return;}let _0x5a1fc8=!0x1,_0x4d68ec,_0x5c94b8=()=>{if(_0x5a1fc8)throw Error('Endpoint\x20middleware\x20for\x20'+String(_0x588a67)+'\x20called\x20next()\x20more\x20than\x20once');return _0x5a1fc8=!0x0,_0x4d68ec=_0x2ece91(_0x33c27e+0x1),_0x4d68ec;};try{await _0x20f2a1(_0x19f9e5,_0x5c94b8);}catch(_0x17f583){if(_0x4d68ec)try{await _0x4d68ec;}catch{}throw _0x17f583;}if(!_0x5a1fc8)throw Error('Endpoint\x20middleware\x20for\x20'+String(_0x588a67)+'\x20completed\x20without\x20calling\x20next()');await _0x4d68ec;};await _0x2ece91(0x0);}['clear'](){this['_middlewares']['clear']();}},h={'code':n['ErrorCode']['OK'],'message':''};function g(_0x51f9c8,_0x58efa7){if(!/^-?\d+$/['test'](_0x51f9c8))throw new t['CollabError']('INVALID_REQUEST',_0x58efa7+'\x20must\x20be\x20an\x20integer');let _0x47a01e=Number(_0x51f9c8);if(!Number['isSafeInteger'](_0x47a01e))throw new t['CollabError']('INVALID_REQUEST',_0x58efa7+'\x20is\x20outside\x20the\x20safe\x20integer\x20range');return _0x47a01e;}function _(_0x40d03c){if(_0x40d03c instanceof r['NodeTransportError'])return _0x40d03c['code']==='REQUEST_BODY_TOO_LARGE'?{'status':0x19d,'error':{'code':n['ErrorCode']['INVALID_ARGUMENT'],'message':_0x40d03c['message']}}:_0x40d03c['code']==='INVALID_JSON'||_0x40d03c['code']==='REQUEST_ABORTED'?{'status':0x190,'error':{'code':n['ErrorCode']['INVALID_ARGUMENT'],'message':_0x40d03c['message']}}:{'status':0x1f7,'error':{'code':n['ErrorCode']['INTERNAL_ERROR'],'message':'Transport\x20unavailable'}};if(!(_0x40d03c instanceof t['CollabError']))return{'status':0x1f4,'error':{'code':n['ErrorCode']['INTERNAL_ERROR'],'message':'Internal\x20server\x20error'}};let _0x42c7c5={'UNAUTHENTICATED':{'status':0x191,'code':n['ErrorCode']['UNAUTHENTICATED']},'INVALID_REQUEST':{'status':0x190,'code':n['ErrorCode']['INVALID_ARGUMENT']},'UNIT_NOT_FOUND':{'status':0x194,'code':n['ErrorCode']['NOT_FOUND']},'PERMISSION_DENIED':{'status':0x193,'code':n['ErrorCode']['PERMISSION_DENIED']},'OT_CONFLICT':{'status':0x199,'code':n['ErrorCode']['APPLY_REJECT']},'REVISION_MISMATCH':{'status':0x199,'code':n['ErrorCode']['CHANGESET_REVISION_CONFILICT']},'ADAPTER_FAILURE':{'status':0x1f7,'code':n['ErrorCode']['INTERNAL_ERROR']},'INTERNAL_ERROR':{'status':0x1f4,'code':n['ErrorCode']['INTERNAL_ERROR']}}[_0x40d03c['code']];return{'status':_0x42c7c5['status'],'error':{'code':_0x42c7c5['code'],'message':_0x40d03c['message']}};}function v(_0x33f483,_0x5a486f,_0x367b1a){_0x33f483['writableEnded']||_0x33f483['destroyed']||(_0x33f483['statusCode']=_0x5a486f,_0x33f483['setHeader']('content-type','application/json;\x20charset=utf-8'),_0x33f483['end'](JSON['stringify'](_0x367b1a,(_0x35bc9f,_0x262ac2)=>_0x262ac2 instanceof Uint8Array?Buffer['from'](_0x262ac2)['toString']('base64'):_0x262ac2)));}var y=class{['_tickets']=new Map();['_disposed']=!0x1;async['issue'](_0x4459ef,_0x2a1565){if(this['_disposed'])throw Error('Session\x20ticket\x20store\x20is\x20disposed');if(!Number['isSafeInteger'](_0x2a1565)||_0x2a1565<=0x0)throw TypeError('Session\x20ticket\x20TTL\x20must\x20be\x20a\x20positive\x20safe\x20integer');this['_purgeExpired']();let _0x3c314d;do _0x3c314d=(0x0,e['randomBytes'])(0x20)['toString']('base64url');while(this['_tickets']['has'](_0x3c314d));return this['_tickets']['set'](_0x3c314d,{'record':_0x4459ef,'expiresAt':Date['now']()+_0x2a1565}),_0x3c314d;}async['consume'](_0x502f22){if(this['_disposed']||!_0x502f22)return null;let _0x20a659=this['_tickets']['get'](_0x502f22);return!_0x20a659||(this['_tickets']['delete'](_0x502f22),_0x20a659['expiresAt']<=Date['now']())?null:_0x20a659['record'];}async['dispose'](){this['_disposed']||(this['_disposed']=!0x0,this['_tickets']['clear']());}['_purgeExpired'](){let _0x1c75a6=Date['now']();for(let [_0xab4b10,_0x141204]of this['_tickets'])_0x141204['expiresAt']<=_0x1c75a6&&this['_tickets']['delete'](_0xab4b10);}},b=0x5*0xea60;function x(_0x518816){if(!_0x518816['startsWith']('/')||_0x518816==='/'||_0x518816['endsWith']('/')||_0x518816['includes']('?')||_0x518816['includes']('#'))throw TypeError('protocolBasePath\x20must\x20be\x20an\x20absolute\x20path\x20without\x20a\x20trailing\x20slash');return _0x518816;}function S(_0x878ba4){if(!_0x878ba4||typeof _0x878ba4!='object')throw new t['CollabError']('INVALID_REQUEST','Request\x20body\x20must\x20be\x20an\x20object');let _0x224fa8=_0x878ba4;if(typeof _0x224fa8['unitID']!='string'||typeof _0x224fa8['memberID']!='string'||!Number['isSafeInteger'](_0x224fa8['type'])||!_0x224fa8['changeset']||typeof _0x224fa8['changeset']!='object')throw new t['CollabError']('INVALID_REQUEST','Invalid\x20new\x20changes\x20request');}function C(_0x344579){if(!Array['isArray'](_0x344579)||_0x344579['length']===0x0||_0x344579['some'](_0x59bbdb=>typeof _0x59bbdb!='string'||_0x59bbdb['trim']()['length']===0x0))throw new t['CollabError']('INVALID_REQUEST','unitIds\x20must\x20be\x20a\x20non-empty\x20string\x20array');}function w(_0x3db7f4){let _0x427f59=_0x3db7f4['getAll']('unitIds');C(_0x427f59);let _0x13818d=_0x3db7f4['getAll']('hardDelete');if(_0x13818d['length']>0x1||_0x13818d['length']===0x1&&_0x13818d[0x0]!=='true'&&_0x13818d[0x0]!=='false')throw new t['CollabError']('INVALID_REQUEST','hardDelete\x20must\x20be\x20true\x20or\x20false');return{'unitIds':_0x427f59,'hardDelete':_0x13818d[0x0]==='true'};}function T(_0x158580){if(!_0x158580||typeof _0x158580!='object')throw new t['CollabError']('INVALID_REQUEST','Request\x20body\x20must\x20be\x20an\x20object');C(_0x158580['unitIds']);}var E=class{['_service'];['_middleware']=new m();['_listeners']=new Map();['_bindingsByConnection']=new Map();['_bindingsByMember']=new Map();['_rooms']=new Map();['_outboundQueues']=new Map();['_ticketStore'];['_ownsTicketStore'];['_ticketTtlMs'];['_protocolBasePath'];['_serviceSubscriptions'];['_deletedUnitIDs']=new Set();['_disposed']=!0x1;constructor(_0x8cdb0a,_0x2b8221={}){if(this['_service']=_0x8cdb0a,!_0x8cdb0a)throw TypeError('UniverCollabEndpoint\x20requires\x20a\x20service');if(this['_ticketStore']=_0x2b8221['ticketStore']??new y(),this['_ownsTicketStore']=_0x2b8221['ticketStore']===void 0x0,this['_ticketTtlMs']=_0x2b8221['sessionTicketTtlMs']??b,!Number['isSafeInteger'](this['_ticketTtlMs'])||this['_ticketTtlMs']<=0x0)throw TypeError('sessionTicketTtlMs\x20must\x20be\x20a\x20positive\x20safe\x20integer');this['_protocolBasePath']=x(_0x2b8221['protocolBasePath']??'/universer-api'),this['_serviceSubscriptions']=[this['_service']['on']('changesetCommitted',_0x53bba4=>{this['_enqueueCommittedChangeset'](_0x53bba4['changeset'],_0x53bba4['memberID']);}),this['_service']['on']('unitsDeleted',_0x525d03=>{for(let _0x4e5bf3 of _0x525d03['request']['unitIDs'])this['_deletedUnitIDs']['add'](_0x4e5bf3);for(let _0x172d32 of _0x525d03['request']['unitIDs'])this['_enqueueUnitOutbound'](_0x172d32,async()=>{this['_evictUnitRoom'](_0x172d32);});}),this['_service']['on']('unitsRecovered',async _0x32a7fd=>{await Promise['all'](_0x32a7fd['request']['unitIDs']['map'](_0x41f5e8=>this['_enqueueUnitOutbound'](_0x41f5e8,async()=>{this['_deletedUnitIDs']['delete'](_0x41f5e8);})));})];}['use'](_0xdbb03f,_0x1c2b59){return this['_assertRunning'](),this['_middleware']['use'](_0xdbb03f,_0x1c2b59);}['on'](_0x3f471d,_0x5ca038){this['_assertRunning']();let _0x174162=this['_listeners']['get'](_0x3f471d)??new Set(),_0xdc590e=_0x5ca038;_0x174162['add'](_0xdc590e),this['_listeners']['set'](_0x3f471d,_0x174162);let _0x2e647e=!0x1;return{'dispose':()=>{_0x2e647e||(_0x2e647e=!0x0,_0x174162['delete'](_0xdc590e));}};}['findJoinedSession'](_0x5b7c47){if(this['_disposed'])return null;let _0x5addb1=this['_bindingsByMember']['get'](_0x5b7c47['memberID']);return!_0x5addb1||_0x5addb1['session']['userID']!==_0x5b7c47['authenticatedUserID']||!_0x5addb1['joinedUnitIDs']['has'](_0x5b7c47['unitID'])?null:_0x5addb1['session'];}['findJoinedSessionByUser'](_0x5e66d1){if(this['_disposed'])return null;for(let _0xaecc05 of this['_rooms']['get'](_0x5e66d1['unitID'])?.['values']()??[])if(_0xaecc05['session']['userID']===_0x5e66d1['authenticatedUserID'])return _0xaecc05['session'];return null;}async['invalidateUnitSessions'](_0x136c8e){if(this['_assertRunning'](),typeof _0x136c8e['unitID']!='string'||!_0x136c8e['unitID'])throw TypeError('unitID\x20must\x20be\x20a\x20non-empty\x20string');if(_0x136c8e['userID']!==void 0x0&&(typeof _0x136c8e['userID']!='string'||!_0x136c8e['userID']))throw TypeError('userID\x20must\x20be\x20a\x20non-empty\x20string\x20when\x20provided');await this['_enqueueUnitOutbound'](_0x136c8e['unitID'],async()=>{let _0x4f017c=[...this['_rooms']['get'](_0x136c8e['unitID'])?.['values']()??[]]['filter'](_0x3e5cc8=>_0x136c8e['userID']===void 0x0||_0x3e5cc8['session']['userID']===_0x136c8e['userID']);for(let _0x128712 of _0x4f017c)_0x128712['connection']['close'](0xfa3,'Unit\x20access\x20changed'),await this['_disconnectBinding'](_0x128712,'session-evicted');});}async['publishTrustedUnitEvent'](_0x28e226){this['_assertRunning']();let _0x3dfa4f=[...this['_rooms']['get'](_0x28e226['unitID'])?.['keys']()??[]],_0x312045=this['_bindingsByMember']['get'](_0x28e226['memberID'])?.['joinedUnitIDs']['has'](_0x28e226['unitID'])?_0x28e226['memberID']:void 0x0,_0x26a25a=p(_0x28e226['unitID'],_0x28e226['eventID'],_0x28e226['data']);this['_enqueueUnitOutbound'](_0x28e226['unitID'],async()=>{for(let _0x577b4f of _0x3dfa4f){if(_0x577b4f===_0x312045)continue;let _0x239dd4=this['_bindingsByMember']['get'](_0x577b4f);_0x239dd4?.['joinedUnitIDs']['has'](_0x28e226['unitID'])&&await this['_safeSend'](_0x239dd4['connection'],_0x26a25a);}});}['register'](_0x53172d){this['_assertRunning']();let _0x3834eb=this['_protocolBasePath'],_0x685892=_0x31a2f2=>_0x4f522c=>this['_handleHttp'](_0x4f522c,_0x31a2f2);_0x53172d['get'](_0x3834eb+'/user/session-ticket',_0x685892('ticket')),_0x53172d['delete'](_0x3834eb+'/snapshot/-/units',_0x685892('delete-units')),_0x53172d['post'](_0x3834eb+'/snapshot/-/units/recover',_0x685892('recover-units')),_0x53172d['post'](_0x3834eb+'/comb/:type/unit/:unitID/new_changes',_0x685892('new-changes')),_0x53172d['get'](_0x3834eb+'/snapshot/block/:type/unit/:unitID/block/:blockID',_0x685892('deserialized-block')),_0x53172d['get'](_0x3834eb+'/snapshot/:type/unit/:unitID/rev/:revision',_0x685892('unit')),_0x53172d['get'](_0x3834eb+'/snapshot/:type/unit/:unitID/block/:blockID',_0x685892('block')),_0x53172d['get'](_0x3834eb+'/snapshot/:type/unit/:unitID/fetchmissing',_0x685892('fetch-missing')),_0x53172d['upgrade'](_0x3834eb+'/comb/connect',_0x507f51=>this['_handleUpgrade'](_0x507f51));}async['_handleUpgrade'](_0x36e227){if(this['_disposed']){_0x36e227['reject'](0x1f7,'Endpoint\x20is\x20disposed');return;}let _0x43dee5=new URL(_0x36e227['incomingMessage']['url']??'/','http://localhost'),_0x2653ae=await this['_ticketStore']['consume'](_0x43dee5['searchParams']['get']('sessionTicket')??'');if(!_0x2653ae){_0x36e227['reject'](0x191,'Invalid\x20or\x20expired\x20session\x20ticket');return;}_0x36e227['accept']({'open':({connection:_0x82dbf5})=>this['_openConnection'](_0x2653ae,_0x82dbf5),'message':_0x2ffe2f=>this['_handleMessage'](_0x2ffe2f),'close':({connection:_0x402c12})=>this['_disconnectConnection'](_0x402c12,'connection-closed')});}async['dispose'](){if(this['_disposed'])return;this['_disposed']=!0x0;for(let _0x233d57 of this['_serviceSubscriptions'])_0x233d57['dispose']();await Promise['allSettled']([...this['_outboundQueues']['values']()]);let _0xe1b72a=[...this['_bindingsByConnection']['values']()];for(let _0x36cde3 of _0xe1b72a)await this['_disconnectBinding'](_0x36cde3,'endpoint-disposed'),_0x36cde3['connection']['close'](0x3e9,'Endpoint\x20disposed');this['_bindingsByConnection']['clear'](),this['_bindingsByMember']['clear'](),this['_rooms']['clear'](),this['_outboundQueues']['clear'](),this['_middleware']['clear'](),this['_listeners']['clear'](),this['_ownsTicketStore']&&await this['_ticketStore']['dispose']?.();}async['_handleHttp'](_0x6a10cb,_0x5070f0){try{this['_assertRunning']();let _0x2547ab=new URL(_0x6a10cb['incomingMessage']['url']??'/','http://localhost');if(!_0x6a10cb['userID'])throw new t['CollabError']('UNAUTHENTICATED','HTTP\x20user\x20is\x20not\x20authenticated');if(_0x5070f0==='ticket'){let _0x50d0cd=await this['_ticketStore']['issue']({'userID':_0x6a10cb['userID'],'customData':_0x6a10cb['customData']},this['_ticketTtlMs']);v(_0x6a10cb['response'],0xc8,{'error':h,'ticket':_0x50d0cd});return;}let _0x287baa={'userID':_0x6a10cb['userID'],'customData':_0x6a10cb['customData']};if(_0x5070f0==='delete-units'){let _0x32704c=w(_0x2547ab['searchParams']);await this['_service']['deleteUnits']({'unitIDs':_0x32704c['unitIds'],'hardDelete':_0x32704c['hardDelete']},_0x287baa),v(_0x6a10cb['response'],0xc8,{'error':h});return;}if(_0x5070f0==='recover-units'){let _0x2c3dd3=await _0x6a10cb['readJson']();T(_0x2c3dd3),await this['_service']['recoverUnits']({'unitIDs':_0x2c3dd3['unitIds']},_0x287baa),v(_0x6a10cb['response'],0xc8,{'error':h});return;}let _0xc07bb8=g(_0x6a10cb['params']['type'],'type'),_0x2185db=_0x6a10cb['params']['unitID'];if(_0x5070f0==='new-changes'){await this['_handleNewChanges'](_0x6a10cb,_0x2185db,_0xc07bb8);return;}switch(_0x5070f0){case'unit':{let _0x5ba9d9=g(_0x6a10cb['params']['revision'],'revision'),_0xc88e77=await this['_service']['getUnitLoadData']({'unitID':_0x2185db,'type':_0xc07bb8,'revision':_0x5ba9d9},_0x287baa);v(_0x6a10cb['response'],0xc8,{'error':h,'snapshot':_0xc88e77['snapshot'],'changesets':_0xc88e77['changesets']});return;}case'block':case'deserialized-block':{let _0x4b0a01=await this['_service']['getSheetBlock']({'unitID':_0x2185db,'type':_0xc07bb8,'blockID':_0x6a10cb['params']['blockID']},_0x287baa);if(!_0x4b0a01['block'])throw new t['CollabError']('UNIT_NOT_FOUND','Sheet\x20block\x20was\x20not\x20found');let _0x10ef30=_0x5070f0==='deserialized-block'?{..._0x4b0a01['block'],'data':JSON['parse'](new TextDecoder()['decode'](_0x4b0a01['block']['data']))}:_0x4b0a01['block'];v(_0x6a10cb['response'],0xc8,{'error':h,'block':_0x10ef30});return;}case'fetch-missing':{let _0x5a0781=g(_0x2547ab['searchParams']['get']('from')??'','from'),_0x165678=g(_0x2547ab['searchParams']['get']('to')??'','to'),_0x32e650=await this['_service']['getChangesets']({'unitID':_0x2185db,'type':_0xc07bb8,'from':_0x5a0781,'to':_0x165678},_0x287baa);v(_0x6a10cb['response'],0xc8,{'error':h,'changesets':_0x32e650['changesets']});return;}}}catch(_0x406a6c){let _0x20fedc=_(_0x406a6c instanceof SyntaxError?new t['CollabError']('INTERNAL_ERROR','Stored\x20sheet\x20block\x20is\x20not\x20valid\x20JSON',{'cause':_0x406a6c}):_0x406a6c);v(_0x6a10cb['response'],_0x20fedc['status'],{'error':_0x20fedc['error']});}}async['_openConnection'](_0x2326dd,_0x1ceee7){try{let _0x81ef9c=(0x0,e['randomUUID'])(),_0x63f255={'memberID':_0x81ef9c,'userID':_0x2326dd['userID'],'customData':_0x2326dd['customData']},_0x1a9c2d={'memberID':_0x81ef9c,'userID':_0x2326dd['userID'],'name':_0x2326dd['userID']},_0x3786a8={'connection':_0x1ceee7,'session':_0x63f255,'member':_0x1a9c2d};await this['_middleware']['run']('connect',_0x3786a8,()=>void 0x0);let _0x58d86c={'connection':_0x1ceee7,'session':_0x63f255,'member':_0x1a9c2d,'joinedUnitIDs':new Set()};this['_bindingsByConnection']['set'](_0x1ceee7['id'],_0x58d86c),this['_bindingsByMember']['set'](_0x81ef9c,_0x58d86c);}catch(_0x25e7ec){_0x1ceee7['close'](_0x25e7ec instanceof t['CollabError']?0x3f0:0x3f3,_0x25e7ec instanceof t['CollabError']?'Connection\x20rejected':'Endpoint\x20failure');}}async['_handleMessage'](_0x389734){let _0x314e44=this['_bindingsByConnection']['get'](_0x389734['connection']['id']);if(!_0x314e44){_0x389734['connection']['close'](0x3f0,'WebSocket\x20Session\x20is\x20not\x20established');return;}if(typeof _0x389734['data']!='string'){_0x389734['connection']['close'](0x3eb,'Comb\x20messages\x20must\x20be\x20JSON\x20text');return;}let _0x3397e1;try{let _0x4d02d4=JSON['parse'](_0x389734['data']);if(!_0x4d02d4||typeof _0x4d02d4!='object')throw Error('invalid');_0x3397e1=_0x4d02d4;}catch{_0x389734['connection']['close'](0x3eb,'Invalid\x20Comb\x20JSON\x20message');return;}let _0x50a37c=typeof _0x3397e1['routeKey']=='string'?_0x3397e1['routeKey']:'';switch(_0x3397e1['cmd']){case n['CombCmd']['HELLO']:case n['CombCmd']['HEARTBEAT']:await _0x389734['connection']['send'](JSON['stringify'](a(_0x3397e1['cmd'],_0x314e44['member']['memberID'],_0x50a37c)));return;case n['CombCmd']['JOIN']:await this['_handleJoin'](_0x314e44,_0x3397e1,_0x50a37c);return;case n['CombCmd']['LEAVE']:await this['_handleLeave'](_0x314e44,_0x3397e1,_0x50a37c);return;case n['CombCmd']['INGEST']:if(_0x3397e1['collaMsg']?.['eventID']!==i['UPDATE_CURSOR'])return;await this['_handlePresence'](_0x314e44,_0x3397e1,_0x389734['customData']);return;default:return;}}async['_handleJoin'](_0x3761a3,_0x330366,_0x1c0dd5){let _0x21834d=_0x330366['joinReq']?.['rooms'],_0x1566ee=_0x21834d?.['length']?_0x21834d['map'](_0x53c904=>_0x53c904['roomID']):_0x1c0dd5?[_0x1c0dd5]:[];if(_0x1566ee['length']===0x0||_0x1566ee['some'](_0x2d2875=>typeof _0x2d2875!='string'||!_0x2d2875)){await _0x3761a3['connection']['send'](JSON['stringify'](o(_0x1c0dd5,n['CmdRspCode']['FAIL'],{},'Invalid\x20JOIN\x20request')));return;}let _0x1c8ccb=[...new Set(_0x1566ee)],_0x14f51e=_0x1c8ccb['filter'](_0x522a97=>!_0x3761a3['joinedUnitIDs']['has'](_0x522a97));try{for(let _0x3003a0 of _0x1c8ccb)this['_assertJoinable'](_0x3003a0);for(let _0x5bbfbb of _0x14f51e)await this['_middleware']['run']('joinUnit',{'session':_0x3761a3['session'],'unitID':_0x5bbfbb},()=>void 0x0);for(let _0x596909 of _0x1c8ccb)this['_assertJoinable'](_0x596909);}catch(_0x259d3f){let _0x225d25=_0x259d3f instanceof t['CollabError']&&_0x259d3f['code']==='UNIT_NOT_FOUND'?n['CmdRspCode']['JOIN_ROOM_NOT_EXISTS']:_0x259d3f instanceof t['CollabError']&&(_0x259d3f['code']==='PERMISSION_DENIED'||_0x259d3f['code']==='UNAUTHENTICATED')?n['CmdRspCode']['JOIN_ROOM_PERMISSION_DENIED']:n['CmdRspCode']['FAIL'];await _0x3761a3['connection']['send'](JSON['stringify'](o(_0x1c0dd5||_0x1c8ccb[0x0],_0x225d25,{},_0x259d3f instanceof t['CollabError']?_0x259d3f['message']:'JOIN\x20failed')));return;}for(let _0x13028f of _0x14f51e){let _0x1764c7=this['_rooms']['get'](_0x13028f)??new Map();_0x1764c7['set'](_0x3761a3['member']['memberID'],_0x3761a3),this['_rooms']['set'](_0x13028f,_0x1764c7),_0x3761a3['joinedUnitIDs']['add'](_0x13028f);}let _0x5b65ff={};for(let _0x8e888a of _0x1c8ccb)_0x5b65ff[_0x8e888a]={'roomID':_0x8e888a,'members':[...this['_rooms']['get'](_0x8e888a)?.['values']()??[]]['map'](_0x27e363=>s(_0x27e363['member']))};await _0x3761a3['connection']['send'](JSON['stringify'](o(_0x1c0dd5||_0x1c8ccb[0x0],n['CmdRspCode']['OK'],_0x5b65ff,'success')));for(let _0x4a0232 of _0x14f51e)await this['_broadcastToRoom'](_0x4a0232,l(_0x4a0232,s(_0x3761a3['member'])),_0x3761a3['member']['memberID']);}async['_handleLeave'](_0x45df9b,_0x340ca8,_0x2aa2a9){let _0x407a7c=typeof _0x340ca8['leaveReq']?.['roomID']=='string'?_0x340ca8['leaveReq']['roomID']:_0x2aa2a9;_0x407a7c&&await this['_leaveUnit'](_0x45df9b,_0x407a7c,'client-leave');}async['_handlePresence'](_0x2978af,_0x346a60,_0x3a2e28){let _0x5137aa=typeof _0x346a60['routeKey']=='string'?_0x346a60['routeKey']:'',_0x5e7121=_0x346a60['collaMsg']?.['updateCursorEvent']?.['selection'];if(!_0x5137aa||!_0x2978af['joinedUnitIDs']['has'](_0x5137aa)||typeof _0x5e7121!='string')return;let _0x223973={'unitID':_0x5137aa,'memberID':_0x2978af['member']['memberID'],'selection':_0x5e7121};try{await this['_middleware']['run']('receivePresence',{'session':_0x2978af['session'],'unitID':_0x5137aa,'payload':_0x223973,'customData':_0x3a2e28},()=>void 0x0);}catch(_0x5bc4af){if(_0x5bc4af instanceof t['CollabError'])return;throw _0x5bc4af;}if(typeof _0x223973['selection']!='string')return;let _0x3bce8a=[...this['_rooms']['get'](_0x5137aa)?.['values']()??[]]['filter'](_0x4a27ae=>_0x4a27ae!==_0x2978af);for(let _0x1c840a of _0x3bce8a){let _0x3a43e2={'unitID':_0x5137aa,'memberID':_0x2978af['member']['memberID'],'selection':_0x223973['selection']};try{await this['_middleware']['run']('sendPresence',{'session':_0x2978af['session'],'unitID':_0x5137aa,'payload':_0x3a43e2,'customData':_0x3a2e28,'targetMemberID':_0x1c840a['member']['memberID']},()=>void 0x0);}catch{continue;}typeof _0x3a43e2['selection']=='string'&&await this['_safeSend'](_0x1c840a['connection'],d(_0x5137aa,{'unitID':_0x5137aa,'memberID':_0x2978af['member']['memberID'],'selection':_0x3a43e2['selection']}));}}async['_handleNewChanges'](_0x5f330e,_0x1ae8f6,_0x433822){let _0x1032af=await _0x5f330e['readJson']();if(S(_0x1032af),_0x1032af['unitID']!==_0x1ae8f6||_0x1032af['type']!==_0x433822||_0x1032af['changeset']?.['unitID']!==_0x1ae8f6||_0x1032af['changeset']['type']!==_0x433822)throw new t['CollabError']('INVALID_REQUEST','Route,\x20request\x20and\x20changeset\x20identity\x20must\x20match');let _0x139af=this['_bindingsByMember']['get'](_0x1032af['memberID']);if(!_0x139af||_0x139af['session']['userID']!==_0x5f330e['userID'])throw new t['CollabError']('PERMISSION_DENIED','memberID\x20does\x20not\x20belong\x20to\x20the\x20authenticated\x20user');if(!_0x139af['joinedUnitIDs']['has'](_0x1ae8f6))throw new t['CollabError']('PERMISSION_DENIED','Session\x20has\x20not\x20joined\x20this\x20unit');let _0x3a02ce=await this['_service']['submitChangeset']({'changeset':_0x1032af['changeset']},{'userID':_0x5f330e['userID'],'memberID':_0x139af['session']['memberID'],'customData':_0x5f330e['customData']});if(_0x3a02ce['status']==='already-committed')await this['_safeSend'](_0x139af['connection'],f(_0x1ae8f6,i['CHANGESET_ACK'],_0x3a02ce['changeset']));else{if(_0x3a02ce['status']==='rejected'){let _0x2f2bfd=_0x3a02ce['error']['code']==='PERMISSION_DENIED'||_0x3a02ce['error']['code']==='UNAUTHENTICATED'?i['PERMISSION_REJ']:i['CHANGESET_REJ'];await this['_safeSend'](_0x139af['connection'],f(_0x1ae8f6,_0x2f2bfd,this['_trustedClientChangeset'](_0x1032af['changeset'],_0x139af)));}else _0x3a02ce['status']==='retry'&&await this['_safeSend'](_0x139af['connection'],f(_0x1ae8f6,i['CHANGESET_SHOULD_RETRY'],this['_trustedClientChangeset'](_0x1032af['changeset'],_0x139af)));}v(_0x5f330e['response'],0xc8,{'error':h});}['_trustedClientChangeset'](_0x1912af,_0x55b319){return{..._0x1912af,'userID':_0x55b319['session']['userID'],'memberID':_0x55b319['session']['memberID']};}['_enqueueCommittedChangeset'](_0x46201d,_0x1471c6){if(this['_disposed'])return;let _0x2f767a=_0x46201d['unitID'],_0x5807de=[...this['_rooms']['get'](_0x2f767a)?.['keys']()??[]];this['_enqueueUnitOutbound'](_0x2f767a,async()=>{for(let _0xfd8ce8 of _0x5807de){let _0x32a7f3=this['_bindingsByMember']['get'](_0xfd8ce8);if(!_0x32a7f3?.['joinedUnitIDs']['has'](_0x2f767a))continue;let _0x9752ed=_0xfd8ce8===_0x1471c6?i['CHANGESET_ACK']:i['NEW_CHANGESETS'];await this['_safeSend'](_0x32a7f3['connection'],f(_0x2f767a,_0x9752ed,_0x46201d));}});}['_evictUnitRoom'](_0x291ddb){let _0xac128f=this['_rooms']['get'](_0x291ddb);if(_0xac128f){this['_rooms']['delete'](_0x291ddb);for(let _0x3eed06 of _0xac128f['values']())_0x3eed06['joinedUnitIDs']['delete'](_0x291ddb);}}['_enqueueUnitOutbound'](_0xe2f37d,_0x25eeca){let _0x55a2cb=(this['_outboundQueues']['get'](_0xe2f37d)??Promise['resolve']())['catch'](()=>void 0x0)['then'](_0x25eeca);return this['_outboundQueues']['set'](_0xe2f37d,_0x55a2cb),_0x55a2cb['finally'](()=>{this['_outboundQueues']['get'](_0xe2f37d)===_0x55a2cb&&this['_outboundQueues']['delete'](_0xe2f37d);}),_0x55a2cb;}async['_disconnectConnection'](_0x3da702,_0x264e66){let _0x2122c3=this['_bindingsByConnection']['get'](_0x3da702['id']);_0x2122c3&&await this['_disconnectBinding'](_0x2122c3,_0x264e66);}async['_disconnectBinding'](_0xd4caa2,_0x33c016){this['_bindingsByConnection']['delete'](_0xd4caa2['connection']['id']),this['_bindingsByMember']['delete'](_0xd4caa2['member']['memberID']);let _0x2093dc=[..._0xd4caa2['joinedUnitIDs']];for(let _0x597ef0 of _0x2093dc)await this['_leaveUnit'](_0xd4caa2,_0x597ef0,_0x33c016);}async['_leaveUnit'](_0x34133b,_0x5be34e,_0x113a15){if(!_0x34133b['joinedUnitIDs']['delete'](_0x5be34e))return!0x1;let _0x21d44a=this['_rooms']['get'](_0x5be34e);return _0x21d44a?.['delete'](_0x34133b['member']['memberID']),_0x21d44a?.['size']===0x0&&this['_rooms']['delete'](_0x5be34e),await this['_broadcastToRoom'](_0x5be34e,u(_0x5be34e,{'memberID':_0x34133b['member']['memberID'],'name':_0x34133b['member']['name']}),_0x34133b['member']['memberID']),await this['_emit']('memberLeftUnit',{'session':_0x34133b['session'],'unitID':_0x5be34e,'reason':_0x113a15}),!0x0;}async['_broadcastToRoom'](_0x36c05d,_0x1f81ca,_0x189a1f){let _0x12568a=[...this['_rooms']['get'](_0x36c05d)?.['values']()??[]];await Promise['allSettled'](_0x12568a['filter'](_0x277f69=>_0x277f69['member']['memberID']!==_0x189a1f)['map'](_0x4cc5f3=>this['_safeSend'](_0x4cc5f3['connection'],_0x1f81ca)));}async['_safeSend'](_0x5ab2e3,_0x2c4131){try{await _0x5ab2e3['send'](JSON['stringify'](_0x2c4131));}catch{}}async['_emit'](_0x5a7f38,_0xd93087){let _0x4a465f=[...this['_listeners']['get'](_0x5a7f38)??[]];for(let _0x257243 of _0x4a465f)try{await _0x257243(_0xd93087);}catch{}}['_assertRunning'](){if(this['_disposed'])throw Error('UniverCollabEndpoint\x20is\x20disposed');}['_assertJoinable'](_0x3190c5){if(this['_deletedUnitIDs']['has'](_0x3190c5))throw new t['CollabError']('UNIT_NOT_FOUND','Unit\x20has\x20been\x20deleted');}};exports['MemorySessionTicketStore']=y,exports['UniverCollabEndpoint']=E;
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- const _0x18e651=_0x59d3;(function(_0x412547,_0x41f397){const _0x2116f3=_0x59d3,_0x8562a6=_0x412547();while(!![]){try{const _0x2d1cf2=-parseInt(_0x2116f3(0xc3))/0x1+parseInt(_0x2116f3(0xc9))/0x2*(-parseInt(_0x2116f3(0xc8))/0x3)+parseInt(_0x2116f3(0xbf))/0x4+parseInt(_0x2116f3(0xc2))/0x5*(parseInt(_0x2116f3(0xca))/0x6)+-parseInt(_0x2116f3(0xc4))/0x7*(parseInt(_0x2116f3(0xc7))/0x8)+parseInt(_0x2116f3(0xc5))/0x9+parseInt(_0x2116f3(0xc1))/0xa*(parseInt(_0x2116f3(0xc0))/0xb);if(_0x2d1cf2===_0x41f397)break;else _0x8562a6['push'](_0x8562a6['shift']());}catch(_0x2fffa9){_0x8562a6['push'](_0x8562a6['shift']());}}}(_0x2ff8,0xbaf87));function _0x2ff8(){const _0x9cb722=['30ATPPXR','935TyeEuk','275887fKfHhj','258986UqGzIW','4330836bZxCWf','MemorySessionTicketStore','96ligVNG','165VmVyZA','9678hIlrSv','34122tzXDnl','5728QonoDH','754358dRoeOY'];_0x2ff8=function(){return _0x9cb722;};return _0x2ff8();}import _0x3639f9 from'./index.cjs';const facadeExport0=_0x3639f9[_0x18e651(0xc6)],facadeExport1=_0x3639f9['UniverCollabEndpoint'];function _0x59d3(_0x42ae56,_0x4ca965){_0x42ae56=_0x42ae56-0xbf;const _0x2ff8cc=_0x2ff8();let _0x59d3c9=_0x2ff8cc[_0x42ae56];return _0x59d3c9;}export{facadeExport0 as MemorySessionTicketStore,facadeExport1 as UniverCollabEndpoint};
1
+ function _0x24f6(_0x293d99,_0x2c3c54){_0x293d99=_0x293d99-0xbe;const _0xacf3a5=_0xacf3();let _0x24f6bb=_0xacf3a5[_0x293d99];return _0x24f6bb;}const _0x1b0d91=_0x24f6;function _0xacf3(){const _0x1e4029=['1185270cVsjnp','242bnEqRt','242976TpknZO','192vIqmoQ','1374590oczrog','3AMCCyG','UniverCollabEndpoint','9589380zWPCKD','6594uTFZuv','12LwunSM','63873YVxrdd','20XPUChF','604518HSvhMu','MemorySessionTicketStore'];_0xacf3=function(){return _0x1e4029;};return _0xacf3();}(function(_0x5a2c4f,_0x31af75){const _0x5e04ba=_0x24f6,_0x2ccf14=_0x5a2c4f();while(!![]){try{const _0x321560=parseInt(_0x5e04ba(0xc8))/0x1*(-parseInt(_0x5e04ba(0xcb))/0x2)+-parseInt(_0x5e04ba(0xc1))/0x3*(-parseInt(_0x5e04ba(0xc0))/0x4)+parseInt(_0x5e04ba(0xc3))/0x5*(parseInt(_0x5e04ba(0xbe))/0x6)+-parseInt(_0x5e04ba(0xc7))/0x7+-parseInt(_0x5e04ba(0xc6))/0x8*(parseInt(_0x5e04ba(0xbf))/0x9)+-parseInt(_0x5e04ba(0xca))/0xa+-parseInt(_0x5e04ba(0xc4))/0xb*(-parseInt(_0x5e04ba(0xc5))/0xc);if(_0x321560===_0x31af75)break;else _0x2ccf14['push'](_0x2ccf14['shift']());}catch(_0x2fcdcb){_0x2ccf14['push'](_0x2ccf14['shift']());}}}(_0xacf3,0x906cf));import _0x5ab885 from'./index.cjs';const facadeExport0=_0x5ab885[_0x1b0d91(0xc2)],facadeExport1=_0x5ab885[_0x1b0d91(0xc9)];export{facadeExport0 as MemorySessionTicketStore,facadeExport1 as UniverCollabEndpoint};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@univerjs-pro/collaboration-endpoint",
3
3
  "type": "module",
4
- "version": "1.0.0",
4
+ "version": "1.0.1",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
7
7
  "types": "./dist/index.d.ts",
@@ -16,8 +16,8 @@
16
16
  "dist"
17
17
  ],
18
18
  "dependencies": {
19
- "@univerjs-pro/collaboration-service": "1.0.0",
20
- "@univerjs-pro/collaboration-transport-node": "1.0.0",
21
- "@univerjs/protocol": "1.0.0"
19
+ "@univerjs-pro/collaboration-service": "1.0.1",
20
+ "@univerjs-pro/collaboration-transport-node": "1.0.1",
21
+ "@univerjs/protocol": "1.0.1"
22
22
  }
23
23
  }