@univerjs-pro/collaboration-endpoint 1.0.1 → 1.0.3

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(_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;
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(_0xf8fb1f,_0x5efa02,_0x13ce21=''){return{'cmd':_0xf8fb1f,'code':n['CmdRspCode']['OK'],'reason':'success','routeKey':_0x13ce21,'infoRsp':{'memberID':_0x5efa02}};}function o(_0x4ab88e,_0x596e76,_0x4e48ed,_0x1e5a66){return{'cmd':n['CombCmd']['JOIN'],'code':_0x596e76,'reason':_0x1e5a66,'routeKey':_0x4ab88e,'joinRsp':{'roomInfos':_0x4e48ed}};}function s(_0x2e0c30){return{'memberID':_0x2e0c30['memberID'],'userID':_0x2e0c30['userID'],'name':_0x2e0c30['name'],..._0x2e0c30['avatar']===void 0x0?{}:{'avatar':_0x2e0c30['avatar']}};}function c(_0x459903,_0x19d640){return{'cmd':n['CombCmd']['RECV'],'code':n['CmdRspCode']['OK'],'reason':'success','routeKey':_0x459903,'collaMsg':_0x19d640};}function l(_0x2b79ae,_0x41ba1b){return c(_0x2b79ae,{'eventID':i['USERS_ENTER'],'joinEvent':{..._0x41ba1b,'avatar':_0x41ba1b['avatar']??''}});}function u(_0x466fd8,_0x291d69){return c(_0x466fd8,{'eventID':i['USERS_LEAVE'],'leaveEvent':_0x291d69});}function d(_0x188f8a,_0x291cba){return c(_0x188f8a,{'eventID':i['UPDATE_CURSOR'],'updateCursorEvent':_0x291cba});}function f(_0x594135,_0x82cf0,_0x4adbe3){let _0x2263d2={[i['CHANGESET_ACK']]:'csAckEvent',[i['CHANGESET_REJ']]:'csRejEvent',[i['CHANGESET_SHOULD_RETRY']]:'csShouldRetryEvent',[i['NEW_CHANGESETS']]:'newCsEvent',[i['PERMISSION_REJ']]:'permissionRejEvent'}[_0x82cf0];return c(_0x594135,{'eventID':_0x82cf0,[_0x2263d2]:{'cs':_0x4adbe3}});}function p(_0x5a167d,_0x3f93b5,_0x324420){return c(_0x5a167d,{..._0x324420,'eventID':_0x3f93b5});}var m=class{['_middlewares']=new Map();['use'](_0x1ea128,_0x316402){let _0x26b341=this['_middlewares']['get'](_0x1ea128)??[],_0x17c9d0=_0x316402;_0x26b341['push'](_0x17c9d0),this['_middlewares']['set'](_0x1ea128,_0x26b341);let _0x28bed7=!0x1;return{'dispose':()=>{if(_0x28bed7)return;_0x28bed7=!0x0;let _0x4bb3fe=_0x26b341['indexOf'](_0x17c9d0);_0x4bb3fe>=0x0&&_0x26b341['splice'](_0x4bb3fe,0x1);}};}async['run'](_0x4ebd90,_0x12dfb8,_0x22c10e){let _0x4a1a1e=[...this['_middlewares']['get'](_0x4ebd90)??[]],_0x5b2dca=async _0x2bc63f=>{let _0x5cfc08=_0x4a1a1e[_0x2bc63f];if(!_0x5cfc08){await _0x22c10e();return;}let _0x1d353c=!0x1,_0x2cf82e,_0x315744=()=>{if(_0x1d353c)throw Error('Endpoint\x20middleware\x20for\x20'+String(_0x4ebd90)+'\x20called\x20next()\x20more\x20than\x20once');return _0x1d353c=!0x0,_0x2cf82e=_0x5b2dca(_0x2bc63f+0x1),_0x2cf82e;};try{await _0x5cfc08(_0x12dfb8,_0x315744);}catch(_0x23bf88){if(_0x2cf82e)try{await _0x2cf82e;}catch{}throw _0x23bf88;}if(!_0x1d353c)throw Error('Endpoint\x20middleware\x20for\x20'+String(_0x4ebd90)+'\x20completed\x20without\x20calling\x20next()');await _0x2cf82e;};await _0x5b2dca(0x0);}['clear'](){this['_middlewares']['clear']();}},h={'code':n['ErrorCode']['OK'],'message':''};function g(_0x2a7726,_0x1c351b){if(!/^-?\d+$/['test'](_0x2a7726))throw new t['CollabError']('INVALID_REQUEST',_0x1c351b+'\x20must\x20be\x20an\x20integer');let _0x40c0fb=Number(_0x2a7726);if(!Number['isSafeInteger'](_0x40c0fb))throw new t['CollabError']('INVALID_REQUEST',_0x1c351b+'\x20is\x20outside\x20the\x20safe\x20integer\x20range');return _0x40c0fb;}function _(_0x69c83e){if(_0x69c83e instanceof r['NodeTransportError'])return _0x69c83e['code']==='REQUEST_BODY_TOO_LARGE'?{'status':0x19d,'error':{'code':n['ErrorCode']['INVALID_ARGUMENT'],'message':_0x69c83e['message']}}:_0x69c83e['code']==='INVALID_JSON'||_0x69c83e['code']==='REQUEST_ABORTED'?{'status':0x190,'error':{'code':n['ErrorCode']['INVALID_ARGUMENT'],'message':_0x69c83e['message']}}:{'status':0x1f7,'error':{'code':n['ErrorCode']['INTERNAL_ERROR'],'message':'Transport\x20unavailable'}};if(!(_0x69c83e instanceof t['CollabError']))return{'status':0x1f4,'error':{'code':n['ErrorCode']['INTERNAL_ERROR'],'message':'Internal\x20server\x20error'}};let _0x204a86={'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']}}[_0x69c83e['code']];return{'status':_0x204a86['status'],'error':{'code':_0x204a86['code'],'message':_0x69c83e['message']}};}function v(_0x78ce74,_0x39b652,_0x3cd94d){_0x78ce74['writableEnded']||_0x78ce74['destroyed']||(_0x78ce74['statusCode']=_0x39b652,_0x78ce74['setHeader']('content-type','application/json;\x20charset=utf-8'),_0x78ce74['end'](JSON['stringify'](_0x3cd94d,(_0x5b7647,_0x4dde24)=>_0x4dde24 instanceof Uint8Array?Buffer['from'](_0x4dde24)['toString']('base64'):_0x4dde24)));}var y=class{['_tickets']=new Map();['_disposed']=!0x1;async['issue'](_0x1113bc,_0x158028){if(this['_disposed'])throw Error('Session\x20ticket\x20store\x20is\x20disposed');if(!Number['isSafeInteger'](_0x158028)||_0x158028<=0x0)throw TypeError('Session\x20ticket\x20TTL\x20must\x20be\x20a\x20positive\x20safe\x20integer');this['_purgeExpired']();let _0x1d1f2c;do _0x1d1f2c=(0x0,e['randomBytes'])(0x20)['toString']('base64url');while(this['_tickets']['has'](_0x1d1f2c));return this['_tickets']['set'](_0x1d1f2c,{'record':_0x1113bc,'expiresAt':Date['now']()+_0x158028}),_0x1d1f2c;}async['consume'](_0x57814a){if(this['_disposed']||!_0x57814a)return null;let _0x5a4e19=this['_tickets']['get'](_0x57814a);return!_0x5a4e19||(this['_tickets']['delete'](_0x57814a),_0x5a4e19['expiresAt']<=Date['now']())?null:_0x5a4e19['record'];}async['dispose'](){this['_disposed']||(this['_disposed']=!0x0,this['_tickets']['clear']());}['_purgeExpired'](){let _0x3d4b2b=Date['now']();for(let [_0x2ca9e5,_0xbe5fbe]of this['_tickets'])_0xbe5fbe['expiresAt']<=_0x3d4b2b&&this['_tickets']['delete'](_0x2ca9e5);}},b=0x5*0xea60;function x(_0x1b601b){if(!_0x1b601b['startsWith']('/')||_0x1b601b==='/'||_0x1b601b['endsWith']('/')||_0x1b601b['includes']('?')||_0x1b601b['includes']('#'))throw TypeError('protocolBasePath\x20must\x20be\x20an\x20absolute\x20path\x20without\x20a\x20trailing\x20slash');return _0x1b601b;}function S(_0x4feb2d){if(!_0x4feb2d||typeof _0x4feb2d!='object')throw new t['CollabError']('INVALID_REQUEST','Request\x20body\x20must\x20be\x20an\x20object');let _0xd75b72=_0x4feb2d;if(typeof _0xd75b72['unitID']!='string'||typeof _0xd75b72['memberID']!='string'||!Number['isSafeInteger'](_0xd75b72['type'])||!_0xd75b72['changeset']||typeof _0xd75b72['changeset']!='object')throw new t['CollabError']('INVALID_REQUEST','Invalid\x20new\x20changes\x20request');}function C(_0x4ad70b){if(!Array['isArray'](_0x4ad70b)||_0x4ad70b['length']===0x0||_0x4ad70b['some'](_0x44d8b4=>typeof _0x44d8b4!='string'||_0x44d8b4['trim']()['length']===0x0))throw new t['CollabError']('INVALID_REQUEST','unitIds\x20must\x20be\x20a\x20non-empty\x20string\x20array');}function w(_0x4cc0c6){let _0x38f834=_0x4cc0c6['getAll']('unitIds');C(_0x38f834);let _0x1c93d5=_0x4cc0c6['getAll']('hardDelete');if(_0x1c93d5['length']>0x1||_0x1c93d5['length']===0x1&&_0x1c93d5[0x0]!=='true'&&_0x1c93d5[0x0]!=='false')throw new t['CollabError']('INVALID_REQUEST','hardDelete\x20must\x20be\x20true\x20or\x20false');return{'unitIds':_0x38f834,'hardDelete':_0x1c93d5[0x0]==='true'};}function T(_0x1304bc){if(!_0x1304bc||typeof _0x1304bc!='object')throw new t['CollabError']('INVALID_REQUEST','Request\x20body\x20must\x20be\x20an\x20object');C(_0x1304bc['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(_0x511db8,_0x48da6d={}){if(this['_service']=_0x511db8,!_0x511db8)throw TypeError('UniverCollabEndpoint\x20requires\x20a\x20service');if(this['_ticketStore']=_0x48da6d['ticketStore']??new y(),this['_ownsTicketStore']=_0x48da6d['ticketStore']===void 0x0,this['_ticketTtlMs']=_0x48da6d['sessionTicketTtlMs']??b,!Number['isSafeInteger'](this['_ticketTtlMs'])||this['_ticketTtlMs']<=0x0)throw TypeError('sessionTicketTtlMs\x20must\x20be\x20a\x20positive\x20safe\x20integer');this['_protocolBasePath']=x(_0x48da6d['protocolBasePath']??'/universer-api'),this['_serviceSubscriptions']=[this['_service']['on']('changesetCommitted',_0xd3e744=>{this['_enqueueCommittedChangeset'](_0xd3e744['changeset'],_0xd3e744['memberID']);}),this['_service']['on']('unitsDeleted',_0x1dd799=>{for(let _0x2ca482 of _0x1dd799['request']['unitIDs'])this['_deletedUnitIDs']['add'](_0x2ca482);for(let _0x34ebb9 of _0x1dd799['request']['unitIDs'])this['_enqueueUnitOutbound'](_0x34ebb9,async()=>{this['_evictUnitRoom'](_0x34ebb9);});}),this['_service']['on']('unitsRecovered',async _0x3f1423=>{await Promise['all'](_0x3f1423['request']['unitIDs']['map'](_0x4b88d8=>this['_enqueueUnitOutbound'](_0x4b88d8,async()=>{this['_deletedUnitIDs']['delete'](_0x4b88d8);})));})];}['use'](_0x560b22,_0x225edc){return this['_assertRunning'](),this['_middleware']['use'](_0x560b22,_0x225edc);}['on'](_0x56d951,_0x374b3b){this['_assertRunning']();let _0x4d0995=this['_listeners']['get'](_0x56d951)??new Set(),_0x43d16a=_0x374b3b;_0x4d0995['add'](_0x43d16a),this['_listeners']['set'](_0x56d951,_0x4d0995);let _0x292765=!0x1;return{'dispose':()=>{_0x292765||(_0x292765=!0x0,_0x4d0995['delete'](_0x43d16a));}};}['findJoinedSession'](_0x3f19ad){if(this['_disposed'])return null;let _0x90953c=this['_bindingsByMember']['get'](_0x3f19ad['memberID']);return!_0x90953c||_0x90953c['session']['userID']!==_0x3f19ad['authenticatedUserID']||!_0x90953c['joinedUnitIDs']['has'](_0x3f19ad['unitID'])?null:_0x90953c['session'];}['findJoinedSessionByUser'](_0x459c79){if(this['_disposed'])return null;for(let _0x54da80 of this['_rooms']['get'](_0x459c79['unitID'])?.['values']()??[])if(_0x54da80['session']['userID']===_0x459c79['authenticatedUserID'])return _0x54da80['session'];return null;}async['invalidateUnitSessions'](_0x1b2b23){if(this['_assertRunning'](),typeof _0x1b2b23['unitID']!='string'||!_0x1b2b23['unitID'])throw TypeError('unitID\x20must\x20be\x20a\x20non-empty\x20string');if(_0x1b2b23['userID']!==void 0x0&&(typeof _0x1b2b23['userID']!='string'||!_0x1b2b23['userID']))throw TypeError('userID\x20must\x20be\x20a\x20non-empty\x20string\x20when\x20provided');await this['_enqueueUnitOutbound'](_0x1b2b23['unitID'],async()=>{let _0x3d097a=[...this['_rooms']['get'](_0x1b2b23['unitID'])?.['values']()??[]]['filter'](_0xcd0bf3=>_0x1b2b23['userID']===void 0x0||_0xcd0bf3['session']['userID']===_0x1b2b23['userID']);for(let _0x5edf8b of _0x3d097a)_0x5edf8b['connection']['close'](0xfa3,'Unit\x20access\x20changed'),await this['_disconnectBinding'](_0x5edf8b,'session-evicted');});}async['publishTrustedUnitEvent'](_0x226261){this['_assertRunning']();let _0x14fe4c=[...this['_rooms']['get'](_0x226261['unitID'])?.['keys']()??[]],_0x33556a=this['_bindingsByMember']['get'](_0x226261['memberID'])?.['joinedUnitIDs']['has'](_0x226261['unitID'])?_0x226261['memberID']:void 0x0,_0x225b5b=p(_0x226261['unitID'],_0x226261['eventID'],_0x226261['data']);this['_enqueueUnitOutbound'](_0x226261['unitID'],async()=>{for(let _0x2e9a10 of _0x14fe4c){if(_0x2e9a10===_0x33556a)continue;let _0x501adb=this['_bindingsByMember']['get'](_0x2e9a10);_0x501adb?.['joinedUnitIDs']['has'](_0x226261['unitID'])&&await this['_safeSend'](_0x501adb['connection'],_0x225b5b);}});}['register'](_0x2700ba){this['_assertRunning']();let _0x3a1761=this['_protocolBasePath'],_0x561924=_0x4df195=>_0x1e9a52=>this['_handleHttp'](_0x1e9a52,_0x4df195);_0x2700ba['get'](_0x3a1761+'/user/session-ticket',_0x561924('ticket')),_0x2700ba['delete'](_0x3a1761+'/snapshot/-/units',_0x561924('delete-units')),_0x2700ba['post'](_0x3a1761+'/snapshot/-/units/recover',_0x561924('recover-units')),_0x2700ba['post'](_0x3a1761+'/comb/:type/unit/:unitID/new_changes',_0x561924('new-changes')),_0x2700ba['get'](_0x3a1761+'/snapshot/block/:type/unit/:unitID/block/:blockID',_0x561924('deserialized-block')),_0x2700ba['get'](_0x3a1761+'/snapshot/:type/unit/:unitID/rev/:revision',_0x561924('unit')),_0x2700ba['get'](_0x3a1761+'/snapshot/:type/unit/:unitID/block/:blockID',_0x561924('block')),_0x2700ba['get'](_0x3a1761+'/snapshot/:type/unit/:unitID/fetchmissing',_0x561924('fetch-missing')),_0x2700ba['upgrade'](_0x3a1761+'/comb/connect',_0x1fbd65=>this['_handleUpgrade'](_0x1fbd65));}async['_handleUpgrade'](_0x310af8){if(this['_disposed']){_0x310af8['reject'](0x1f7,'Endpoint\x20is\x20disposed');return;}let _0x865587=new URL(_0x310af8['incomingMessage']['url']??'/','http://localhost'),_0x5f5550=await this['_ticketStore']['consume'](_0x865587['searchParams']['get']('sessionTicket')??'');if(!_0x5f5550){_0x310af8['reject'](0x191,'Invalid\x20or\x20expired\x20session\x20ticket');return;}_0x310af8['accept']({'open':({connection:_0x334b75})=>this['_openConnection'](_0x5f5550,_0x334b75),'message':_0x22016c=>this['_handleMessage'](_0x22016c),'close':({connection:_0x11ccdf})=>this['_disconnectConnection'](_0x11ccdf,'connection-closed')});}async['dispose'](){if(this['_disposed'])return;this['_disposed']=!0x0;for(let _0x149de5 of this['_serviceSubscriptions'])_0x149de5['dispose']();await Promise['allSettled']([...this['_outboundQueues']['values']()]);let _0x6fadc6=[...this['_bindingsByConnection']['values']()];for(let _0x120553 of _0x6fadc6)await this['_disconnectBinding'](_0x120553,'endpoint-disposed'),_0x120553['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'](_0x36aa2a,_0x4cd103){try{this['_assertRunning']();let _0x292ff7=new URL(_0x36aa2a['incomingMessage']['url']??'/','http://localhost');if(!_0x36aa2a['userID'])throw new t['CollabError']('UNAUTHENTICATED','HTTP\x20user\x20is\x20not\x20authenticated');if(_0x4cd103==='ticket'){let _0x283d2b=await this['_ticketStore']['issue']({'userID':_0x36aa2a['userID'],'customData':_0x36aa2a['customData']},this['_ticketTtlMs']);v(_0x36aa2a['response'],0xc8,{'error':h,'ticket':_0x283d2b});return;}let _0x295c67={'userID':_0x36aa2a['userID'],'customData':_0x36aa2a['customData']};if(_0x4cd103==='delete-units'){let _0x5043c5=w(_0x292ff7['searchParams']);await this['_service']['deleteUnits']({'unitIDs':_0x5043c5['unitIds'],'hardDelete':_0x5043c5['hardDelete']},_0x295c67),v(_0x36aa2a['response'],0xc8,{'error':h});return;}if(_0x4cd103==='recover-units'){let _0x57a720=await _0x36aa2a['readJson']();T(_0x57a720),await this['_service']['recoverUnits']({'unitIDs':_0x57a720['unitIds']},_0x295c67),v(_0x36aa2a['response'],0xc8,{'error':h});return;}let _0x5f2a98=g(_0x36aa2a['params']['type'],'type'),_0x58b722=_0x36aa2a['params']['unitID'];if(_0x4cd103==='new-changes'){await this['_handleNewChanges'](_0x36aa2a,_0x58b722,_0x5f2a98);return;}switch(_0x4cd103){case'unit':{let _0x5dadec=g(_0x36aa2a['params']['revision'],'revision'),_0x43ac5b=await this['_service']['getUnitLoadData']({'unitID':_0x58b722,'type':_0x5f2a98,'revision':_0x5dadec},_0x295c67);v(_0x36aa2a['response'],0xc8,{'error':h,'snapshot':_0x43ac5b['snapshot'],'changesets':_0x43ac5b['changesets']});return;}case'block':case'deserialized-block':{let _0x4621a0=await this['_service']['getSheetBlock']({'unitID':_0x58b722,'type':_0x5f2a98,'blockID':_0x36aa2a['params']['blockID']},_0x295c67);if(!_0x4621a0['block'])throw new t['CollabError']('UNIT_NOT_FOUND','Sheet\x20block\x20was\x20not\x20found');let _0x42998f=_0x4cd103==='deserialized-block'?{..._0x4621a0['block'],'data':JSON['parse'](new TextDecoder()['decode'](_0x4621a0['block']['data']))}:_0x4621a0['block'];v(_0x36aa2a['response'],0xc8,{'error':h,'block':_0x42998f});return;}case'fetch-missing':{let _0x4d6bba=g(_0x292ff7['searchParams']['get']('from')??'','from'),_0x49f187=g(_0x292ff7['searchParams']['get']('to')??'','to'),_0x5339d7=await this['_service']['getChangesets']({'unitID':_0x58b722,'type':_0x5f2a98,'from':_0x4d6bba,'to':_0x49f187},_0x295c67);v(_0x36aa2a['response'],0xc8,{'error':h,'changesets':_0x5339d7['changesets']});return;}}}catch(_0x208075){let _0xea5489=_(_0x208075 instanceof SyntaxError?new t['CollabError']('INTERNAL_ERROR','Stored\x20sheet\x20block\x20is\x20not\x20valid\x20JSON',{'cause':_0x208075}):_0x208075);v(_0x36aa2a['response'],_0xea5489['status'],{'error':_0xea5489['error']});}}async['_openConnection'](_0x39d8d7,_0x426086){try{let _0x51feb3=(0x0,e['randomUUID'])(),_0x23a6f7={'memberID':_0x51feb3,'userID':_0x39d8d7['userID'],'customData':_0x39d8d7['customData']},_0x1d4670={'memberID':_0x51feb3,'userID':_0x39d8d7['userID'],'name':_0x39d8d7['userID']},_0x54ff8f={'connection':_0x426086,'session':_0x23a6f7,'member':_0x1d4670};await this['_middleware']['run']('connect',_0x54ff8f,()=>void 0x0);let _0x1b80ae={'connection':_0x426086,'session':_0x23a6f7,'member':_0x1d4670,'joinedUnitIDs':new Set()};this['_bindingsByConnection']['set'](_0x426086['id'],_0x1b80ae),this['_bindingsByMember']['set'](_0x51feb3,_0x1b80ae);}catch(_0x11e992){_0x426086['close'](_0x11e992 instanceof t['CollabError']?0x3f0:0x3f3,_0x11e992 instanceof t['CollabError']?'Connection\x20rejected':'Endpoint\x20failure');}}async['_handleMessage'](_0x4ed269){let _0x3c624e=this['_bindingsByConnection']['get'](_0x4ed269['connection']['id']);if(!_0x3c624e){_0x4ed269['connection']['close'](0x3f0,'WebSocket\x20Session\x20is\x20not\x20established');return;}if(typeof _0x4ed269['data']!='string'){_0x4ed269['connection']['close'](0x3eb,'Comb\x20messages\x20must\x20be\x20JSON\x20text');return;}let _0x1f2169;try{let _0x413ab7=JSON['parse'](_0x4ed269['data']);if(!_0x413ab7||typeof _0x413ab7!='object')throw Error('invalid');_0x1f2169=_0x413ab7;}catch{_0x4ed269['connection']['close'](0x3eb,'Invalid\x20Comb\x20JSON\x20message');return;}let _0x5b0e91=typeof _0x1f2169['routeKey']=='string'?_0x1f2169['routeKey']:'';switch(_0x1f2169['cmd']){case n['CombCmd']['HELLO']:case n['CombCmd']['HEARTBEAT']:await _0x4ed269['connection']['send'](JSON['stringify'](a(_0x1f2169['cmd'],_0x3c624e['member']['memberID'],_0x5b0e91)));return;case n['CombCmd']['JOIN']:await this['_handleJoin'](_0x3c624e,_0x1f2169,_0x5b0e91);return;case n['CombCmd']['LEAVE']:await this['_handleLeave'](_0x3c624e,_0x1f2169,_0x5b0e91);return;case n['CombCmd']['INGEST']:if(_0x1f2169['collaMsg']?.['eventID']!==i['UPDATE_CURSOR'])return;await this['_handlePresence'](_0x3c624e,_0x1f2169,_0x4ed269['customData']);return;default:return;}}async['_handleJoin'](_0x14c58e,_0x2c7624,_0x5543a0){let _0x22487e=_0x2c7624['joinReq']?.['rooms'],_0x36225d=_0x22487e?.['length']?_0x22487e['map'](_0x543092=>_0x543092['roomID']):_0x5543a0?[_0x5543a0]:[];if(_0x36225d['length']===0x0||_0x36225d['some'](_0x2fd942=>typeof _0x2fd942!='string'||!_0x2fd942)){await _0x14c58e['connection']['send'](JSON['stringify'](o(_0x5543a0,n['CmdRspCode']['FAIL'],{},'Invalid\x20JOIN\x20request')));return;}let _0x1dbb00=[...new Set(_0x36225d)],_0x25ac87=_0x1dbb00['filter'](_0x275330=>!_0x14c58e['joinedUnitIDs']['has'](_0x275330));try{for(let _0x32f5be of _0x1dbb00)this['_assertJoinable'](_0x32f5be);for(let _0x521e73 of _0x25ac87)await this['_middleware']['run']('joinUnit',{'session':_0x14c58e['session'],'unitID':_0x521e73},()=>void 0x0);for(let _0x35f0e5 of _0x1dbb00)this['_assertJoinable'](_0x35f0e5);}catch(_0xb20033){let _0x18fc4a=_0xb20033 instanceof t['CollabError']&&_0xb20033['code']==='UNIT_NOT_FOUND'?n['CmdRspCode']['JOIN_ROOM_NOT_EXISTS']:_0xb20033 instanceof t['CollabError']&&(_0xb20033['code']==='PERMISSION_DENIED'||_0xb20033['code']==='UNAUTHENTICATED')?n['CmdRspCode']['JOIN_ROOM_PERMISSION_DENIED']:n['CmdRspCode']['FAIL'];await _0x14c58e['connection']['send'](JSON['stringify'](o(_0x5543a0||_0x1dbb00[0x0],_0x18fc4a,{},_0xb20033 instanceof t['CollabError']?_0xb20033['message']:'JOIN\x20failed')));return;}for(let _0x1f1cad of _0x25ac87){let _0x4567d9=this['_rooms']['get'](_0x1f1cad)??new Map();_0x4567d9['set'](_0x14c58e['member']['memberID'],_0x14c58e),this['_rooms']['set'](_0x1f1cad,_0x4567d9),_0x14c58e['joinedUnitIDs']['add'](_0x1f1cad);}let _0x502a64={};for(let _0x3b6e1a of _0x1dbb00)_0x502a64[_0x3b6e1a]={'roomID':_0x3b6e1a,'members':[...this['_rooms']['get'](_0x3b6e1a)?.['values']()??[]]['map'](_0x387350=>s(_0x387350['member']))};await _0x14c58e['connection']['send'](JSON['stringify'](o(_0x5543a0||_0x1dbb00[0x0],n['CmdRspCode']['OK'],_0x502a64,'success')));for(let _0x4c5dc8 of _0x25ac87)await this['_broadcastToRoom'](_0x4c5dc8,l(_0x4c5dc8,s(_0x14c58e['member'])),_0x14c58e['member']['memberID']);}async['_handleLeave'](_0x16d01b,_0x16eddd,_0x4332fc){let _0x35271a=typeof _0x16eddd['leaveReq']?.['roomID']=='string'?_0x16eddd['leaveReq']['roomID']:_0x4332fc;_0x35271a&&await this['_leaveUnit'](_0x16d01b,_0x35271a,'client-leave');}async['_handlePresence'](_0xfa7c68,_0x22aeb4,_0x49c0ce){let _0x550464=typeof _0x22aeb4['routeKey']=='string'?_0x22aeb4['routeKey']:'',_0x2e5841=_0x22aeb4['collaMsg']?.['updateCursorEvent']?.['selection'];if(!_0x550464||!_0xfa7c68['joinedUnitIDs']['has'](_0x550464)||typeof _0x2e5841!='string')return;let _0x169851={'unitID':_0x550464,'memberID':_0xfa7c68['member']['memberID'],'selection':_0x2e5841};try{await this['_middleware']['run']('receivePresence',{'session':_0xfa7c68['session'],'unitID':_0x550464,'payload':_0x169851,'customData':_0x49c0ce},()=>void 0x0);}catch(_0x42e556){if(_0x42e556 instanceof t['CollabError'])return;throw _0x42e556;}if(typeof _0x169851['selection']!='string')return;let _0xc5229b=[...this['_rooms']['get'](_0x550464)?.['values']()??[]]['filter'](_0x16f0eb=>_0x16f0eb!==_0xfa7c68);for(let _0x2cab20 of _0xc5229b){let _0x23f937={'unitID':_0x550464,'memberID':_0xfa7c68['member']['memberID'],'selection':_0x169851['selection']};try{await this['_middleware']['run']('sendPresence',{'session':_0xfa7c68['session'],'unitID':_0x550464,'payload':_0x23f937,'customData':_0x49c0ce,'targetMemberID':_0x2cab20['member']['memberID']},()=>void 0x0);}catch{continue;}typeof _0x23f937['selection']=='string'&&await this['_safeSend'](_0x2cab20['connection'],d(_0x550464,{'unitID':_0x550464,'memberID':_0xfa7c68['member']['memberID'],'selection':_0x23f937['selection']}));}}async['_handleNewChanges'](_0x47d474,_0x3418d1,_0x50f024){let _0x5b8d45=await _0x47d474['readJson']();if(S(_0x5b8d45),_0x5b8d45['unitID']!==_0x3418d1||_0x5b8d45['type']!==_0x50f024||_0x5b8d45['changeset']?.['unitID']!==_0x3418d1||_0x5b8d45['changeset']['type']!==_0x50f024)throw new t['CollabError']('INVALID_REQUEST','Route,\x20request\x20and\x20changeset\x20identity\x20must\x20match');let _0x1ca63a=this['_bindingsByMember']['get'](_0x5b8d45['memberID']);if(!_0x1ca63a||_0x1ca63a['session']['userID']!==_0x47d474['userID'])throw new t['CollabError']('PERMISSION_DENIED','memberID\x20does\x20not\x20belong\x20to\x20the\x20authenticated\x20user');if(!_0x1ca63a['joinedUnitIDs']['has'](_0x3418d1))throw new t['CollabError']('PERMISSION_DENIED','Session\x20has\x20not\x20joined\x20this\x20unit');let _0x49f125=await this['_service']['submitChangeset']({'changeset':_0x5b8d45['changeset']},{'userID':_0x47d474['userID'],'memberID':_0x1ca63a['session']['memberID'],'customData':_0x47d474['customData']});if(_0x49f125['status']==='already-committed')await this['_safeSend'](_0x1ca63a['connection'],f(_0x3418d1,i['CHANGESET_ACK'],_0x49f125['changeset']));else{if(_0x49f125['status']==='rejected'){let _0x1ef191=_0x49f125['error']['code']==='PERMISSION_DENIED'||_0x49f125['error']['code']==='UNAUTHENTICATED'?i['PERMISSION_REJ']:i['CHANGESET_REJ'];await this['_safeSend'](_0x1ca63a['connection'],f(_0x3418d1,_0x1ef191,this['_trustedClientChangeset'](_0x5b8d45['changeset'],_0x1ca63a)));}else _0x49f125['status']==='retry'&&await this['_safeSend'](_0x1ca63a['connection'],f(_0x3418d1,i['CHANGESET_SHOULD_RETRY'],this['_trustedClientChangeset'](_0x5b8d45['changeset'],_0x1ca63a)));}v(_0x47d474['response'],0xc8,{'error':h});}['_trustedClientChangeset'](_0x5dfa60,_0x3733f5){return{..._0x5dfa60,'userID':_0x3733f5['session']['userID'],'memberID':_0x3733f5['session']['memberID']};}['_enqueueCommittedChangeset'](_0xd7ab18,_0x382fb6){if(this['_disposed'])return;let _0xeeea55=_0xd7ab18['unitID'],_0x460d94=[...this['_rooms']['get'](_0xeeea55)?.['keys']()??[]];this['_enqueueUnitOutbound'](_0xeeea55,async()=>{for(let _0x2d14e5 of _0x460d94){let _0x284691=this['_bindingsByMember']['get'](_0x2d14e5);if(!_0x284691?.['joinedUnitIDs']['has'](_0xeeea55))continue;let _0x52d77f=_0x2d14e5===_0x382fb6?i['CHANGESET_ACK']:i['NEW_CHANGESETS'];await this['_safeSend'](_0x284691['connection'],f(_0xeeea55,_0x52d77f,_0xd7ab18));}});}['_evictUnitRoom'](_0x502f07){let _0x5c2e9e=this['_rooms']['get'](_0x502f07);if(_0x5c2e9e){this['_rooms']['delete'](_0x502f07);for(let _0x414347 of _0x5c2e9e['values']())_0x414347['joinedUnitIDs']['delete'](_0x502f07);}}['_enqueueUnitOutbound'](_0x28dc5f,_0x24def3){let _0x467dc1=(this['_outboundQueues']['get'](_0x28dc5f)??Promise['resolve']())['catch'](()=>void 0x0)['then'](_0x24def3);return this['_outboundQueues']['set'](_0x28dc5f,_0x467dc1),_0x467dc1['finally'](()=>{this['_outboundQueues']['get'](_0x28dc5f)===_0x467dc1&&this['_outboundQueues']['delete'](_0x28dc5f);}),_0x467dc1;}async['_disconnectConnection'](_0x3ddce2,_0x598686){let _0x1ae48c=this['_bindingsByConnection']['get'](_0x3ddce2['id']);_0x1ae48c&&await this['_disconnectBinding'](_0x1ae48c,_0x598686);}async['_disconnectBinding'](_0x1cd2f8,_0x1f5450){this['_bindingsByConnection']['delete'](_0x1cd2f8['connection']['id']),this['_bindingsByMember']['delete'](_0x1cd2f8['member']['memberID']);let _0x120bcd=[..._0x1cd2f8['joinedUnitIDs']];for(let _0x4f7db0 of _0x120bcd)await this['_leaveUnit'](_0x1cd2f8,_0x4f7db0,_0x1f5450);}async['_leaveUnit'](_0x55c8f2,_0x5e27f9,_0x276db1){if(!_0x55c8f2['joinedUnitIDs']['delete'](_0x5e27f9))return!0x1;let _0x3bf1c7=this['_rooms']['get'](_0x5e27f9);return _0x3bf1c7?.['delete'](_0x55c8f2['member']['memberID']),_0x3bf1c7?.['size']===0x0&&this['_rooms']['delete'](_0x5e27f9),await this['_broadcastToRoom'](_0x5e27f9,u(_0x5e27f9,{'memberID':_0x55c8f2['member']['memberID'],'name':_0x55c8f2['member']['name']}),_0x55c8f2['member']['memberID']),await this['_emit']('memberLeftUnit',{'session':_0x55c8f2['session'],'unitID':_0x5e27f9,'reason':_0x276db1}),!0x0;}async['_broadcastToRoom'](_0x234459,_0x56ba5e,_0xaab365){let _0x461509=[...this['_rooms']['get'](_0x234459)?.['values']()??[]];await Promise['allSettled'](_0x461509['filter'](_0x266d98=>_0x266d98['member']['memberID']!==_0xaab365)['map'](_0x11e9c5=>this['_safeSend'](_0x11e9c5['connection'],_0x56ba5e)));}async['_safeSend'](_0xd660e7,_0x4f160d){try{await _0xd660e7['send'](JSON['stringify'](_0x4f160d));}catch{}}async['_emit'](_0x39ee80,_0x2c91b6){let _0x425040=[...this['_listeners']['get'](_0x39ee80)??[]];for(let _0x20a219 of _0x425040)try{await _0x20a219(_0x2c91b6);}catch{}}['_assertRunning'](){if(this['_disposed'])throw Error('UniverCollabEndpoint\x20is\x20disposed');}['_assertJoinable'](_0x323228){if(this['_deletedUnitIDs']['has'](_0x323228))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
- 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};
1
+ function _0x4486(_0x4cab98,_0x1eccd5){_0x4cab98=_0x4cab98-0x124;const _0x1c4118=_0x1c41();let _0x448662=_0x1c4118[_0x4cab98];return _0x448662;}function _0x1c41(){const _0x1f8371=['3514000iOimXs','427470vDsDyp','24fRSJjz','UniverCollabEndpoint','6cNHlly','36880GtECny','222FOPAKd','1415281FeGprv','4473297AHjwbT','1088789DinAsO','35044840guIzny'];_0x1c41=function(){return _0x1f8371;};return _0x1c41();}const _0x4aa9f6=_0x4486;(function(_0x453439,_0x1008b9){const _0x5a2046=_0x4486,_0xd09367=_0x453439();while(!![]){try{const _0x206319=-parseInt(_0x5a2046(0x128))/0x1+-parseInt(_0x5a2046(0x124))/0x2*(parseInt(_0x5a2046(0x125))/0x3)+parseInt(_0x5a2046(0x12c))/0x4*(-parseInt(_0x5a2046(0x12b))/0x5)+-parseInt(_0x5a2046(0x12e))/0x6*(-parseInt(_0x5a2046(0x126))/0x7)+parseInt(_0x5a2046(0x12a))/0x8+-parseInt(_0x5a2046(0x127))/0x9+parseInt(_0x5a2046(0x129))/0xa;if(_0x206319===_0x1008b9)break;else _0xd09367['push'](_0xd09367['shift']());}catch(_0x38c035){_0xd09367['push'](_0xd09367['shift']());}}}(_0x1c41,0xa6a4b));import _0x309df5 from'./index.cjs';const facadeExport0=_0x309df5['MemorySessionTicketStore'],facadeExport1=_0x309df5[_0x4aa9f6(0x12d)];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.1",
4
+ "version": "1.0.3",
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.1",
20
- "@univerjs-pro/collaboration-transport-node": "1.0.1",
21
- "@univerjs/protocol": "1.0.1"
19
+ "@univerjs-pro/collaboration-service": "1.0.3",
20
+ "@univerjs-pro/collaboration-transport-node": "1.0.3",
21
+ "@univerjs/protocol": "1.0.3"
22
22
  }
23
23
  }