@univerjs-pro/collaboration-endpoint 1.0.2 → 1.0.4

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/README.md CHANGED
@@ -126,14 +126,11 @@ New-changes is an HTTP document-data request, but its ACK and broadcast are deli
126
126
 
127
127
  ```text
128
128
  HTTP new-changes { memberID }
129
- → Endpoint locates an online Session by memberID
130
- → verifies session.userID === current HTTP ctx.userID
131
- → verifies that the Session has JOINed the target Unit
132
- → calls the Service with the current HTTP ctx.userID and ctx.customData
133
- → sends ACK and broadcast over WebSocket
129
+ → calls the Service with current HTTP ctx.userID, ctx.customData, and body.memberID
130
+ → delivers ACK/reject/retry to a still-joined Session matching memberID/userID and broadcasts to other room members
134
131
  ```
135
132
 
136
- `memberID` is only used to locate a WebSocket Session and is not an identity credential by itself. Endpoint owns these associations and checks; the application does not need to implement them.
133
+ `memberID` is only used to locate a WebSocket Session and is not an identity credential by itself. Endpoint owns these associations and checks; the application does not need to implement them. Submission itself requires no online Session or JOIN; Service middleware controls write access.
137
134
 
138
135
  ## Middleware
139
136
 
package/README.zh-CN.md CHANGED
@@ -128,14 +128,11 @@ new-changes 是 HTTP 文档数据请求,但它的 ACK 和广播通过 WebSocke
128
128
 
129
129
  ```text
130
130
  HTTP new-changes { memberID }
131
- → Endpoint 使用 memberID 查找在线 Session
132
- → 验证 session.userID === 当前 HTTP ctx.userID
133
- → 验证 Session 已 JOIN 目标 Unit
134
- → 使用当前 HTTP 请求的 ctx.userID 和 ctx.customData 调用 Service
135
- → 通过 WebSocket 发送 ACK 和广播
131
+ → 使用当前 HTTP 请求的 ctx.userID、ctx.customData 和 body.memberID 调用 Service
132
+ → 向 memberID/userID 匹配且仍 JOIN 的连接投递 ACK/reject/retry,向其他房间成员广播
136
133
  ```
137
134
 
138
- `memberID` 只用于定位 WebSocket Session,不能单独作为身份凭据。这些关联和校验由 Endpoint 完成,应用不需要自己处理。
135
+ `memberID` 只用于定位 WebSocket Session,不能单独作为身份凭据。这些关联和校验由 Endpoint 完成,应用不需要自己处理。提交本身不要求在线 Session 或 JOIN,写权限由 Service middleware 控制。
139
136
 
140
137
  ## Middleware
141
138
 
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(_0x10135a,_0x260c9f,_0x37566b=''){return{'cmd':_0x10135a,'code':n['CmdRspCode']['OK'],'reason':'success','routeKey':_0x37566b,'infoRsp':{'memberID':_0x260c9f}};}function o(_0x1710e8,_0x2bc65d,_0x56f600,_0x2f8673){return{'cmd':n['CombCmd']['JOIN'],'code':_0x2bc65d,'reason':_0x2f8673,'routeKey':_0x1710e8,'joinRsp':{'roomInfos':_0x56f600}};}function s(_0x23f47f){return{'memberID':_0x23f47f['memberID'],'userID':_0x23f47f['userID'],'name':_0x23f47f['name'],..._0x23f47f['avatar']===void 0x0?{}:{'avatar':_0x23f47f['avatar']}};}function c(_0x3e666d,_0x314293){return{'cmd':n['CombCmd']['RECV'],'code':n['CmdRspCode']['OK'],'reason':'success','routeKey':_0x3e666d,'collaMsg':_0x314293};}function l(_0x4f9671,_0x343fea){return c(_0x4f9671,{'eventID':i['USERS_ENTER'],'joinEvent':{..._0x343fea,'avatar':_0x343fea['avatar']??''}});}function u(_0x402228,_0x3c6f77){return c(_0x402228,{'eventID':i['USERS_LEAVE'],'leaveEvent':_0x3c6f77});}function d(_0x553f49,_0x2b577b){return c(_0x553f49,{'eventID':i['UPDATE_CURSOR'],'updateCursorEvent':_0x2b577b});}function f(_0x520b81,_0x324c8b,_0x45a3a9){let _0x54ab98={[i['CHANGESET_ACK']]:'csAckEvent',[i['CHANGESET_REJ']]:'csRejEvent',[i['CHANGESET_SHOULD_RETRY']]:'csShouldRetryEvent',[i['NEW_CHANGESETS']]:'newCsEvent',[i['PERMISSION_REJ']]:'permissionRejEvent'}[_0x324c8b];return c(_0x520b81,{'eventID':_0x324c8b,[_0x54ab98]:{'cs':_0x45a3a9}});}function p(_0x5a920b,_0x46a49e,_0x4246cc){return c(_0x5a920b,{..._0x4246cc,'eventID':_0x46a49e});}var m=class{['_middlewares']=new Map();['use'](_0x2b491f,_0x3e0ca6){let _0x5d04cb=this['_middlewares']['get'](_0x2b491f)??[],_0x2bab0b=_0x3e0ca6;_0x5d04cb['push'](_0x2bab0b),this['_middlewares']['set'](_0x2b491f,_0x5d04cb);let _0x2bceac=!0x1;return{'dispose':()=>{if(_0x2bceac)return;_0x2bceac=!0x0;let _0x36b319=_0x5d04cb['indexOf'](_0x2bab0b);_0x36b319>=0x0&&_0x5d04cb['splice'](_0x36b319,0x1);}};}async['run'](_0x3ba22c,_0x26b665,_0x5d50db){let _0x45a027=[...this['_middlewares']['get'](_0x3ba22c)??[]],_0x3baef6=async _0x26af8d=>{let _0x397395=_0x45a027[_0x26af8d];if(!_0x397395){await _0x5d50db();return;}let _0x4162a0=!0x1,_0x17fdc4,_0x43be49=()=>{if(_0x4162a0)throw Error('Endpoint\x20middleware\x20for\x20'+String(_0x3ba22c)+'\x20called\x20next()\x20more\x20than\x20once');return _0x4162a0=!0x0,_0x17fdc4=_0x3baef6(_0x26af8d+0x1),_0x17fdc4;};try{await _0x397395(_0x26b665,_0x43be49);}catch(_0x22a8be){if(_0x17fdc4)try{await _0x17fdc4;}catch{}throw _0x22a8be;}if(!_0x4162a0)throw Error('Endpoint\x20middleware\x20for\x20'+String(_0x3ba22c)+'\x20completed\x20without\x20calling\x20next()');await _0x17fdc4;};await _0x3baef6(0x0);}['clear'](){this['_middlewares']['clear']();}},h={'code':n['ErrorCode']['OK'],'message':''};function g(_0x2ae0ac,_0x7f6384){if(!/^-?\d+$/['test'](_0x2ae0ac))throw new t['CollabError']('INVALID_REQUEST',_0x7f6384+'\x20must\x20be\x20an\x20integer');let _0x543017=Number(_0x2ae0ac);if(!Number['isSafeInteger'](_0x543017))throw new t['CollabError']('INVALID_REQUEST',_0x7f6384+'\x20is\x20outside\x20the\x20safe\x20integer\x20range');return _0x543017;}function _(_0x41aa31){if(_0x41aa31 instanceof r['NodeTransportError'])return _0x41aa31['code']==='REQUEST_BODY_TOO_LARGE'?{'status':0x19d,'error':{'code':n['ErrorCode']['INVALID_ARGUMENT'],'message':_0x41aa31['message']}}:_0x41aa31['code']==='INVALID_JSON'||_0x41aa31['code']==='REQUEST_ABORTED'?{'status':0x190,'error':{'code':n['ErrorCode']['INVALID_ARGUMENT'],'message':_0x41aa31['message']}}:{'status':0x1f7,'error':{'code':n['ErrorCode']['INTERNAL_ERROR'],'message':'Transport\x20unavailable'}};if(!(_0x41aa31 instanceof t['CollabError']))return{'status':0x1f4,'error':{'code':n['ErrorCode']['INTERNAL_ERROR'],'message':'Internal\x20server\x20error'}};let _0x31f00e={'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']}}[_0x41aa31['code']];return{'status':_0x31f00e['status'],'error':{'code':_0x31f00e['code'],'message':_0x41aa31['message']}};}function v(_0xb361aa,_0x23aa50,_0xe5bfe3){_0xb361aa['writableEnded']||_0xb361aa['destroyed']||(_0xb361aa['statusCode']=_0x23aa50,_0xb361aa['setHeader']('content-type','application/json;\x20charset=utf-8'),_0xb361aa['end'](JSON['stringify'](_0xe5bfe3,(_0x5b0027,_0x752f4f)=>_0x752f4f instanceof Uint8Array?Buffer['from'](_0x752f4f)['toString']('base64'):_0x752f4f)));}var y=class{['_tickets']=new Map();['_disposed']=!0x1;async['issue'](_0x1382e5,_0x203abd){if(this['_disposed'])throw Error('Session\x20ticket\x20store\x20is\x20disposed');if(!Number['isSafeInteger'](_0x203abd)||_0x203abd<=0x0)throw TypeError('Session\x20ticket\x20TTL\x20must\x20be\x20a\x20positive\x20safe\x20integer');this['_purgeExpired']();let _0x302c9d;do _0x302c9d=(0x0,e['randomBytes'])(0x20)['toString']('base64url');while(this['_tickets']['has'](_0x302c9d));return this['_tickets']['set'](_0x302c9d,{'record':_0x1382e5,'expiresAt':Date['now']()+_0x203abd}),_0x302c9d;}async['consume'](_0x3730c2){if(this['_disposed']||!_0x3730c2)return null;let _0xb92a12=this['_tickets']['get'](_0x3730c2);return!_0xb92a12||(this['_tickets']['delete'](_0x3730c2),_0xb92a12['expiresAt']<=Date['now']())?null:_0xb92a12['record'];}async['dispose'](){this['_disposed']||(this['_disposed']=!0x0,this['_tickets']['clear']());}['_purgeExpired'](){let _0x179f69=Date['now']();for(let [_0x1d901b,_0x6dcc89]of this['_tickets'])_0x6dcc89['expiresAt']<=_0x179f69&&this['_tickets']['delete'](_0x1d901b);}},b=0x5*0xea60;function x(_0x32d99e){if(!_0x32d99e['startsWith']('/')||_0x32d99e==='/'||_0x32d99e['endsWith']('/')||_0x32d99e['includes']('?')||_0x32d99e['includes']('#'))throw TypeError('protocolBasePath\x20must\x20be\x20an\x20absolute\x20path\x20without\x20a\x20trailing\x20slash');return _0x32d99e;}function S(_0x991fda){if(!_0x991fda||typeof _0x991fda!='object')throw new t['CollabError']('INVALID_REQUEST','Request\x20body\x20must\x20be\x20an\x20object');let _0x2cce57=_0x991fda;if(typeof _0x2cce57['unitID']!='string'||typeof _0x2cce57['memberID']!='string'||!Number['isSafeInteger'](_0x2cce57['type'])||!_0x2cce57['changeset']||typeof _0x2cce57['changeset']!='object')throw new t['CollabError']('INVALID_REQUEST','Invalid\x20new\x20changes\x20request');}function C(_0x31b947){if(!Array['isArray'](_0x31b947)||_0x31b947['length']===0x0||_0x31b947['some'](_0x280718=>typeof _0x280718!='string'||_0x280718['trim']()['length']===0x0))throw new t['CollabError']('INVALID_REQUEST','unitIds\x20must\x20be\x20a\x20non-empty\x20string\x20array');}function w(_0x244526){let _0x272796=_0x244526['getAll']('unitIds');C(_0x272796);let _0x31113d=_0x244526['getAll']('hardDelete');if(_0x31113d['length']>0x1||_0x31113d['length']===0x1&&_0x31113d[0x0]!=='true'&&_0x31113d[0x0]!=='false')throw new t['CollabError']('INVALID_REQUEST','hardDelete\x20must\x20be\x20true\x20or\x20false');return{'unitIds':_0x272796,'hardDelete':_0x31113d[0x0]==='true'};}function T(_0x4330df){if(!_0x4330df||typeof _0x4330df!='object')throw new t['CollabError']('INVALID_REQUEST','Request\x20body\x20must\x20be\x20an\x20object');C(_0x4330df['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(_0x54f277,_0x5591ae={}){if(this['_service']=_0x54f277,!_0x54f277)throw TypeError('UniverCollabEndpoint\x20requires\x20a\x20service');if(this['_ticketStore']=_0x5591ae['ticketStore']??new y(),this['_ownsTicketStore']=_0x5591ae['ticketStore']===void 0x0,this['_ticketTtlMs']=_0x5591ae['sessionTicketTtlMs']??b,!Number['isSafeInteger'](this['_ticketTtlMs'])||this['_ticketTtlMs']<=0x0)throw TypeError('sessionTicketTtlMs\x20must\x20be\x20a\x20positive\x20safe\x20integer');this['_protocolBasePath']=x(_0x5591ae['protocolBasePath']??'/universer-api'),this['_serviceSubscriptions']=[this['_service']['on']('changesetCommitted',_0x14f52b=>{this['_enqueueCommittedChangeset'](_0x14f52b['changeset'],_0x14f52b['memberID']);}),this['_service']['on']('unitsDeleted',_0x28519e=>{for(let _0xc38564 of _0x28519e['request']['unitIDs'])this['_deletedUnitIDs']['add'](_0xc38564);for(let _0x111dbe of _0x28519e['request']['unitIDs'])this['_enqueueUnitOutbound'](_0x111dbe,async()=>{this['_evictUnitRoom'](_0x111dbe);});}),this['_service']['on']('unitsRecovered',async _0x181b76=>{await Promise['all'](_0x181b76['request']['unitIDs']['map'](_0x42ae89=>this['_enqueueUnitOutbound'](_0x42ae89,async()=>{this['_deletedUnitIDs']['delete'](_0x42ae89);})));})];}['use'](_0x13378f,_0x1556d4){return this['_assertRunning'](),this['_middleware']['use'](_0x13378f,_0x1556d4);}['on'](_0x25ca16,_0x3e2274){this['_assertRunning']();let _0x485ac8=this['_listeners']['get'](_0x25ca16)??new Set(),_0x49ae1c=_0x3e2274;_0x485ac8['add'](_0x49ae1c),this['_listeners']['set'](_0x25ca16,_0x485ac8);let _0x1c7b96=!0x1;return{'dispose':()=>{_0x1c7b96||(_0x1c7b96=!0x0,_0x485ac8['delete'](_0x49ae1c));}};}['findJoinedSession'](_0x4b08c6){if(this['_disposed'])return null;let _0x2cf643=this['_bindingsByMember']['get'](_0x4b08c6['memberID']);return!_0x2cf643||_0x2cf643['session']['userID']!==_0x4b08c6['authenticatedUserID']||!_0x2cf643['joinedUnitIDs']['has'](_0x4b08c6['unitID'])?null:_0x2cf643['session'];}['findJoinedSessionByUser'](_0x5e763f){if(this['_disposed'])return null;for(let _0xdcc6a of this['_rooms']['get'](_0x5e763f['unitID'])?.['values']()??[])if(_0xdcc6a['session']['userID']===_0x5e763f['authenticatedUserID'])return _0xdcc6a['session'];return null;}async['invalidateUnitSessions'](_0x25d980){if(this['_assertRunning'](),typeof _0x25d980['unitID']!='string'||!_0x25d980['unitID'])throw TypeError('unitID\x20must\x20be\x20a\x20non-empty\x20string');if(_0x25d980['userID']!==void 0x0&&(typeof _0x25d980['userID']!='string'||!_0x25d980['userID']))throw TypeError('userID\x20must\x20be\x20a\x20non-empty\x20string\x20when\x20provided');await this['_enqueueUnitOutbound'](_0x25d980['unitID'],async()=>{let _0x57acc8=[...this['_rooms']['get'](_0x25d980['unitID'])?.['values']()??[]]['filter'](_0x5be725=>_0x25d980['userID']===void 0x0||_0x5be725['session']['userID']===_0x25d980['userID']);for(let _0x26ddd5 of _0x57acc8)_0x26ddd5['connection']['close'](0xfa3,'Unit\x20access\x20changed'),await this['_disconnectBinding'](_0x26ddd5,'session-evicted');});}async['publishTrustedUnitEvent'](_0x2568a2){this['_assertRunning']();let _0xfa2748=[...this['_rooms']['get'](_0x2568a2['unitID'])?.['keys']()??[]],_0x141182=this['_bindingsByMember']['get'](_0x2568a2['memberID'])?.['joinedUnitIDs']['has'](_0x2568a2['unitID'])?_0x2568a2['memberID']:void 0x0,_0x1b7408=p(_0x2568a2['unitID'],_0x2568a2['eventID'],_0x2568a2['data']);this['_enqueueUnitOutbound'](_0x2568a2['unitID'],async()=>{for(let _0x6d6859 of _0xfa2748){if(_0x6d6859===_0x141182)continue;let _0x11ca5a=this['_bindingsByMember']['get'](_0x6d6859);_0x11ca5a?.['joinedUnitIDs']['has'](_0x2568a2['unitID'])&&await this['_safeSend'](_0x11ca5a['connection'],_0x1b7408);}});}['register'](_0x55faa1){this['_assertRunning']();let _0x28590d=this['_protocolBasePath'],_0x32d9b6=_0x57fd3c=>_0x509815=>this['_handleHttp'](_0x509815,_0x57fd3c);_0x55faa1['get'](_0x28590d+'/user/session-ticket',_0x32d9b6('ticket')),_0x55faa1['delete'](_0x28590d+'/snapshot/-/units',_0x32d9b6('delete-units')),_0x55faa1['post'](_0x28590d+'/snapshot/-/units/recover',_0x32d9b6('recover-units')),_0x55faa1['post'](_0x28590d+'/comb/:type/unit/:unitID/new_changes',_0x32d9b6('new-changes')),_0x55faa1['get'](_0x28590d+'/snapshot/block/:type/unit/:unitID/block/:blockID',_0x32d9b6('deserialized-block')),_0x55faa1['get'](_0x28590d+'/snapshot/:type/unit/:unitID/rev/:revision',_0x32d9b6('unit')),_0x55faa1['get'](_0x28590d+'/snapshot/:type/unit/:unitID/block/:blockID',_0x32d9b6('block')),_0x55faa1['get'](_0x28590d+'/snapshot/:type/unit/:unitID/fetchmissing',_0x32d9b6('fetch-missing')),_0x55faa1['upgrade'](_0x28590d+'/comb/connect',_0x5893e8=>this['_handleUpgrade'](_0x5893e8));}async['_handleUpgrade'](_0x143f09){if(this['_disposed']){_0x143f09['reject'](0x1f7,'Endpoint\x20is\x20disposed');return;}let _0x2b5441=new URL(_0x143f09['incomingMessage']['url']??'/','http://localhost'),_0x435eb2=await this['_ticketStore']['consume'](_0x2b5441['searchParams']['get']('sessionTicket')??'');if(!_0x435eb2){_0x143f09['reject'](0x191,'Invalid\x20or\x20expired\x20session\x20ticket');return;}_0x143f09['accept']({'open':({connection:_0x5f8381})=>this['_openConnection'](_0x435eb2,_0x5f8381),'message':_0x2eea76=>this['_handleMessage'](_0x2eea76),'close':({connection:_0xa35ac3})=>this['_disconnectConnection'](_0xa35ac3,'connection-closed')});}async['dispose'](){if(this['_disposed'])return;this['_disposed']=!0x0;for(let _0x37c6de of this['_serviceSubscriptions'])_0x37c6de['dispose']();await Promise['allSettled']([...this['_outboundQueues']['values']()]);let _0x1f9995=[...this['_bindingsByConnection']['values']()];for(let _0x70529f of _0x1f9995)await this['_disconnectBinding'](_0x70529f,'endpoint-disposed'),_0x70529f['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'](_0x568fa4,_0x5c7478){try{this['_assertRunning']();let _0xe9f615=new URL(_0x568fa4['incomingMessage']['url']??'/','http://localhost');if(!_0x568fa4['userID'])throw new t['CollabError']('UNAUTHENTICATED','HTTP\x20user\x20is\x20not\x20authenticated');if(_0x5c7478==='ticket'){let _0xe63bab=await this['_ticketStore']['issue']({'userID':_0x568fa4['userID'],'customData':_0x568fa4['customData']},this['_ticketTtlMs']);v(_0x568fa4['response'],0xc8,{'error':h,'ticket':_0xe63bab});return;}let _0x82f7c={'userID':_0x568fa4['userID'],'customData':_0x568fa4['customData']};if(_0x5c7478==='delete-units'){let _0x2add53=w(_0xe9f615['searchParams']);await this['_service']['deleteUnits']({'unitIDs':_0x2add53['unitIds'],'hardDelete':_0x2add53['hardDelete']},_0x82f7c),v(_0x568fa4['response'],0xc8,{'error':h});return;}if(_0x5c7478==='recover-units'){let _0x4115ee=await _0x568fa4['readJson']();T(_0x4115ee),await this['_service']['recoverUnits']({'unitIDs':_0x4115ee['unitIds']},_0x82f7c),v(_0x568fa4['response'],0xc8,{'error':h});return;}let _0x544ed8=g(_0x568fa4['params']['type'],'type'),_0x16f3ff=_0x568fa4['params']['unitID'];if(_0x5c7478==='new-changes'){await this['_handleNewChanges'](_0x568fa4,_0x16f3ff,_0x544ed8);return;}switch(_0x5c7478){case'unit':{let _0x53a9f3=g(_0x568fa4['params']['revision'],'revision'),_0x764bff=await this['_service']['getUnitLoadData']({'unitID':_0x16f3ff,'type':_0x544ed8,'revision':_0x53a9f3},_0x82f7c);v(_0x568fa4['response'],0xc8,{'error':h,'snapshot':_0x764bff['snapshot'],'changesets':_0x764bff['changesets']});return;}case'block':case'deserialized-block':{let _0x1b58cd=await this['_service']['getSheetBlock']({'unitID':_0x16f3ff,'type':_0x544ed8,'blockID':_0x568fa4['params']['blockID']},_0x82f7c);if(!_0x1b58cd['block'])throw new t['CollabError']('UNIT_NOT_FOUND','Sheet\x20block\x20was\x20not\x20found');let _0x1fa03a=_0x5c7478==='deserialized-block'?{..._0x1b58cd['block'],'data':JSON['parse'](new TextDecoder()['decode'](_0x1b58cd['block']['data']))}:_0x1b58cd['block'];v(_0x568fa4['response'],0xc8,{'error':h,'block':_0x1fa03a});return;}case'fetch-missing':{let _0x2e45e3=g(_0xe9f615['searchParams']['get']('from')??'','from'),_0x520c5a=g(_0xe9f615['searchParams']['get']('to')??'','to'),_0x1cbd9d=await this['_service']['getChangesets']({'unitID':_0x16f3ff,'type':_0x544ed8,'from':_0x2e45e3,'to':_0x520c5a},_0x82f7c);v(_0x568fa4['response'],0xc8,{'error':h,'changesets':_0x1cbd9d['changesets']});return;}}}catch(_0x1b1bb8){let _0x5623ee=_(_0x1b1bb8 instanceof SyntaxError?new t['CollabError']('INTERNAL_ERROR','Stored\x20sheet\x20block\x20is\x20not\x20valid\x20JSON',{'cause':_0x1b1bb8}):_0x1b1bb8);v(_0x568fa4['response'],_0x5623ee['status'],{'error':_0x5623ee['error']});}}async['_openConnection'](_0x3cf08c,_0x62636f){try{let _0xc4d2eb=(0x0,e['randomUUID'])(),_0x5dc36c={'memberID':_0xc4d2eb,'userID':_0x3cf08c['userID'],'customData':_0x3cf08c['customData']},_0x2837ca={'memberID':_0xc4d2eb,'userID':_0x3cf08c['userID'],'name':_0x3cf08c['userID']},_0x2b8db5={'connection':_0x62636f,'session':_0x5dc36c,'member':_0x2837ca};await this['_middleware']['run']('connect',_0x2b8db5,()=>void 0x0);let _0x34a27a={'connection':_0x62636f,'session':_0x5dc36c,'member':_0x2837ca,'joinedUnitIDs':new Set()};this['_bindingsByConnection']['set'](_0x62636f['id'],_0x34a27a),this['_bindingsByMember']['set'](_0xc4d2eb,_0x34a27a);}catch(_0x175a7f){_0x62636f['close'](_0x175a7f instanceof t['CollabError']?0x3f0:0x3f3,_0x175a7f instanceof t['CollabError']?'Connection\x20rejected':'Endpoint\x20failure');}}async['_handleMessage'](_0x53538e){let _0x306245=this['_bindingsByConnection']['get'](_0x53538e['connection']['id']);if(!_0x306245){_0x53538e['connection']['close'](0x3f0,'WebSocket\x20Session\x20is\x20not\x20established');return;}if(typeof _0x53538e['data']!='string'){_0x53538e['connection']['close'](0x3eb,'Comb\x20messages\x20must\x20be\x20JSON\x20text');return;}let _0x34051e;try{let _0x84e791=JSON['parse'](_0x53538e['data']);if(!_0x84e791||typeof _0x84e791!='object')throw Error('invalid');_0x34051e=_0x84e791;}catch{_0x53538e['connection']['close'](0x3eb,'Invalid\x20Comb\x20JSON\x20message');return;}let _0x5382fb=typeof _0x34051e['routeKey']=='string'?_0x34051e['routeKey']:'';switch(_0x34051e['cmd']){case n['CombCmd']['HELLO']:case n['CombCmd']['HEARTBEAT']:await _0x53538e['connection']['send'](JSON['stringify'](a(_0x34051e['cmd'],_0x306245['member']['memberID'],_0x5382fb)));return;case n['CombCmd']['JOIN']:await this['_handleJoin'](_0x306245,_0x34051e,_0x5382fb);return;case n['CombCmd']['LEAVE']:await this['_handleLeave'](_0x306245,_0x34051e,_0x5382fb);return;case n['CombCmd']['INGEST']:if(_0x34051e['collaMsg']?.['eventID']!==i['UPDATE_CURSOR'])return;await this['_handlePresence'](_0x306245,_0x34051e,_0x53538e['customData']);return;default:return;}}async['_handleJoin'](_0x3fd702,_0x5609f1,_0x32160b){let _0x4ce2ad=_0x5609f1['joinReq']?.['rooms'],_0x49139c=_0x4ce2ad?.['length']?_0x4ce2ad['map'](_0x4bc36a=>_0x4bc36a['roomID']):_0x32160b?[_0x32160b]:[];if(_0x49139c['length']===0x0||_0x49139c['some'](_0x5cac7f=>typeof _0x5cac7f!='string'||!_0x5cac7f)){await _0x3fd702['connection']['send'](JSON['stringify'](o(_0x32160b,n['CmdRspCode']['FAIL'],{},'Invalid\x20JOIN\x20request')));return;}let _0x367091=[...new Set(_0x49139c)],_0x318a91=_0x367091['filter'](_0x15d6d0=>!_0x3fd702['joinedUnitIDs']['has'](_0x15d6d0));try{for(let _0x51527f of _0x367091)this['_assertJoinable'](_0x51527f);for(let _0x1ae082 of _0x318a91)await this['_middleware']['run']('joinUnit',{'session':_0x3fd702['session'],'unitID':_0x1ae082},()=>void 0x0);for(let _0x282d2d of _0x367091)this['_assertJoinable'](_0x282d2d);}catch(_0x225426){let _0x4b0880=_0x225426 instanceof t['CollabError']&&_0x225426['code']==='UNIT_NOT_FOUND'?n['CmdRspCode']['JOIN_ROOM_NOT_EXISTS']:_0x225426 instanceof t['CollabError']&&(_0x225426['code']==='PERMISSION_DENIED'||_0x225426['code']==='UNAUTHENTICATED')?n['CmdRspCode']['JOIN_ROOM_PERMISSION_DENIED']:n['CmdRspCode']['FAIL'];await _0x3fd702['connection']['send'](JSON['stringify'](o(_0x32160b||_0x367091[0x0],_0x4b0880,{},_0x225426 instanceof t['CollabError']?_0x225426['message']:'JOIN\x20failed')));return;}for(let _0x343477 of _0x318a91){let _0x290494=this['_rooms']['get'](_0x343477)??new Map();_0x290494['set'](_0x3fd702['member']['memberID'],_0x3fd702),this['_rooms']['set'](_0x343477,_0x290494),_0x3fd702['joinedUnitIDs']['add'](_0x343477);}let _0x301493={};for(let _0x46be52 of _0x367091)_0x301493[_0x46be52]={'roomID':_0x46be52,'members':[...this['_rooms']['get'](_0x46be52)?.['values']()??[]]['map'](_0x5919ab=>s(_0x5919ab['member']))};await _0x3fd702['connection']['send'](JSON['stringify'](o(_0x32160b||_0x367091[0x0],n['CmdRspCode']['OK'],_0x301493,'success')));for(let _0x5a25d5 of _0x318a91)await this['_broadcastToRoom'](_0x5a25d5,l(_0x5a25d5,s(_0x3fd702['member'])),_0x3fd702['member']['memberID']);}async['_handleLeave'](_0x2e4022,_0x501e6a,_0x1f6c6b){let _0xcb64dd=typeof _0x501e6a['leaveReq']?.['roomID']=='string'?_0x501e6a['leaveReq']['roomID']:_0x1f6c6b;_0xcb64dd&&await this['_leaveUnit'](_0x2e4022,_0xcb64dd,'client-leave');}async['_handlePresence'](_0x20f7ff,_0x23d491,_0x328f4b){let _0x4f752a=typeof _0x23d491['routeKey']=='string'?_0x23d491['routeKey']:'',_0x17ec2b=_0x23d491['collaMsg']?.['updateCursorEvent']?.['selection'];if(!_0x4f752a||!_0x20f7ff['joinedUnitIDs']['has'](_0x4f752a)||typeof _0x17ec2b!='string')return;let _0x4041dd={'unitID':_0x4f752a,'memberID':_0x20f7ff['member']['memberID'],'selection':_0x17ec2b};try{await this['_middleware']['run']('receivePresence',{'session':_0x20f7ff['session'],'unitID':_0x4f752a,'payload':_0x4041dd,'customData':_0x328f4b},()=>void 0x0);}catch(_0x4ba79f){if(_0x4ba79f instanceof t['CollabError'])return;throw _0x4ba79f;}if(typeof _0x4041dd['selection']!='string')return;let _0x532351=[...this['_rooms']['get'](_0x4f752a)?.['values']()??[]]['filter'](_0x184f88=>_0x184f88!==_0x20f7ff);for(let _0x5cac86 of _0x532351){let _0x2b4c48={'unitID':_0x4f752a,'memberID':_0x20f7ff['member']['memberID'],'selection':_0x4041dd['selection']};try{await this['_middleware']['run']('sendPresence',{'session':_0x20f7ff['session'],'unitID':_0x4f752a,'payload':_0x2b4c48,'customData':_0x328f4b,'targetMemberID':_0x5cac86['member']['memberID']},()=>void 0x0);}catch{continue;}typeof _0x2b4c48['selection']=='string'&&await this['_safeSend'](_0x5cac86['connection'],d(_0x4f752a,{'unitID':_0x4f752a,'memberID':_0x20f7ff['member']['memberID'],'selection':_0x2b4c48['selection']}));}}async['_handleNewChanges'](_0xd95458,_0x3df772,_0x1cdb7b){let _0x52e2f9=await _0xd95458['readJson']();if(S(_0x52e2f9),_0x52e2f9['unitID']!==_0x3df772||_0x52e2f9['type']!==_0x1cdb7b||_0x52e2f9['changeset']?.['unitID']!==_0x3df772||_0x52e2f9['changeset']['type']!==_0x1cdb7b)throw new t['CollabError']('INVALID_REQUEST','Route,\x20request\x20and\x20changeset\x20identity\x20must\x20match');let _0x5486e4=this['_bindingsByMember']['get'](_0x52e2f9['memberID']);if(!_0x5486e4||_0x5486e4['session']['userID']!==_0xd95458['userID'])throw new t['CollabError']('PERMISSION_DENIED','memberID\x20does\x20not\x20belong\x20to\x20the\x20authenticated\x20user');if(!_0x5486e4['joinedUnitIDs']['has'](_0x3df772))throw new t['CollabError']('PERMISSION_DENIED','Session\x20has\x20not\x20joined\x20this\x20unit');let _0x4af9fd=await this['_service']['submitChangeset']({'changeset':_0x52e2f9['changeset']},{'userID':_0xd95458['userID'],'memberID':_0x5486e4['session']['memberID'],'customData':_0xd95458['customData']});if(_0x4af9fd['status']==='already-committed')await this['_safeSend'](_0x5486e4['connection'],f(_0x3df772,i['CHANGESET_ACK'],_0x4af9fd['changeset']));else{if(_0x4af9fd['status']==='rejected'){let _0x1631ef=_0x4af9fd['error']['code']==='PERMISSION_DENIED'||_0x4af9fd['error']['code']==='UNAUTHENTICATED'?i['PERMISSION_REJ']:i['CHANGESET_REJ'];await this['_safeSend'](_0x5486e4['connection'],f(_0x3df772,_0x1631ef,this['_trustedClientChangeset'](_0x52e2f9['changeset'],_0x5486e4)));}else _0x4af9fd['status']==='retry'&&await this['_safeSend'](_0x5486e4['connection'],f(_0x3df772,i['CHANGESET_SHOULD_RETRY'],this['_trustedClientChangeset'](_0x52e2f9['changeset'],_0x5486e4)));}v(_0xd95458['response'],0xc8,{'error':h});}['_trustedClientChangeset'](_0x4c7ad5,_0x58c938){return{..._0x4c7ad5,'userID':_0x58c938['session']['userID'],'memberID':_0x58c938['session']['memberID']};}['_enqueueCommittedChangeset'](_0x34e63f,_0x57d022){if(this['_disposed'])return;let _0xf05e6c=_0x34e63f['unitID'],_0x4ea990=[...this['_rooms']['get'](_0xf05e6c)?.['keys']()??[]];this['_enqueueUnitOutbound'](_0xf05e6c,async()=>{for(let _0x21db8c of _0x4ea990){let _0x3094d0=this['_bindingsByMember']['get'](_0x21db8c);if(!_0x3094d0?.['joinedUnitIDs']['has'](_0xf05e6c))continue;let _0x1b2e19=_0x21db8c===_0x57d022?i['CHANGESET_ACK']:i['NEW_CHANGESETS'];await this['_safeSend'](_0x3094d0['connection'],f(_0xf05e6c,_0x1b2e19,_0x34e63f));}});}['_evictUnitRoom'](_0x1e7d0d){let _0x5b1d48=this['_rooms']['get'](_0x1e7d0d);if(_0x5b1d48){this['_rooms']['delete'](_0x1e7d0d);for(let _0x137655 of _0x5b1d48['values']())_0x137655['joinedUnitIDs']['delete'](_0x1e7d0d);}}['_enqueueUnitOutbound'](_0xfbedd9,_0x5df74b){let _0xf923b2=(this['_outboundQueues']['get'](_0xfbedd9)??Promise['resolve']())['catch'](()=>void 0x0)['then'](_0x5df74b);return this['_outboundQueues']['set'](_0xfbedd9,_0xf923b2),_0xf923b2['finally'](()=>{this['_outboundQueues']['get'](_0xfbedd9)===_0xf923b2&&this['_outboundQueues']['delete'](_0xfbedd9);}),_0xf923b2;}async['_disconnectConnection'](_0x368126,_0x5416a8){let _0xb6188b=this['_bindingsByConnection']['get'](_0x368126['id']);_0xb6188b&&await this['_disconnectBinding'](_0xb6188b,_0x5416a8);}async['_disconnectBinding'](_0x2c13ab,_0x449548){this['_bindingsByConnection']['delete'](_0x2c13ab['connection']['id']),this['_bindingsByMember']['delete'](_0x2c13ab['member']['memberID']);let _0x7410e9=[..._0x2c13ab['joinedUnitIDs']];for(let _0x4d3693 of _0x7410e9)await this['_leaveUnit'](_0x2c13ab,_0x4d3693,_0x449548);}async['_leaveUnit'](_0x31898a,_0x572e9f,_0x3684b1){if(!_0x31898a['joinedUnitIDs']['delete'](_0x572e9f))return!0x1;let _0x54ac24=this['_rooms']['get'](_0x572e9f);return _0x54ac24?.['delete'](_0x31898a['member']['memberID']),_0x54ac24?.['size']===0x0&&this['_rooms']['delete'](_0x572e9f),await this['_broadcastToRoom'](_0x572e9f,u(_0x572e9f,{'memberID':_0x31898a['member']['memberID'],'name':_0x31898a['member']['name']}),_0x31898a['member']['memberID']),await this['_emit']('memberLeftUnit',{'session':_0x31898a['session'],'unitID':_0x572e9f,'reason':_0x3684b1}),!0x0;}async['_broadcastToRoom'](_0x2c368a,_0x27742e,_0x188704){let _0x43bd34=[...this['_rooms']['get'](_0x2c368a)?.['values']()??[]];await Promise['allSettled'](_0x43bd34['filter'](_0x17f380=>_0x17f380['member']['memberID']!==_0x188704)['map'](_0x4d3a55=>this['_safeSend'](_0x4d3a55['connection'],_0x27742e)));}async['_safeSend'](_0x26303c,_0x460056){try{await _0x26303c['send'](JSON['stringify'](_0x460056));}catch{}}async['_emit'](_0x2a3530,_0x22167a){let _0xcede21=[...this['_listeners']['get'](_0x2a3530)??[]];for(let _0x625fc8 of _0xcede21)try{await _0x625fc8(_0x22167a);}catch{}}['_assertRunning'](){if(this['_disposed'])throw Error('UniverCollabEndpoint\x20is\x20disposed');}['_assertJoinable'](_0x58e85d){if(this['_deletedUnitIDs']['has'](_0x58e85d))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(_0x230d30,_0x4eec74,_0x49ebcb=''){return{'cmd':_0x230d30,'code':n['CmdRspCode']['OK'],'reason':'success','routeKey':_0x49ebcb,'infoRsp':{'memberID':_0x4eec74}};}function o(_0x1ccc50,_0x14fd61,_0x3dd245,_0x19d3a8){return{'cmd':n['CombCmd']['JOIN'],'code':_0x14fd61,'reason':_0x19d3a8,'routeKey':_0x1ccc50,'joinRsp':{'roomInfos':_0x3dd245}};}function s(_0x294aba){return{'memberID':_0x294aba['memberID'],'userID':_0x294aba['userID'],'name':_0x294aba['name'],..._0x294aba['avatar']===void 0x0?{}:{'avatar':_0x294aba['avatar']}};}function c(_0x5750ec,_0x3cbfaa){return{'cmd':n['CombCmd']['RECV'],'code':n['CmdRspCode']['OK'],'reason':'success','routeKey':_0x5750ec,'collaMsg':_0x3cbfaa};}function l(_0x46657d,_0x432d82){return c(_0x46657d,{'eventID':i['USERS_ENTER'],'joinEvent':{..._0x432d82,'avatar':_0x432d82['avatar']??''}});}function u(_0x54dc11,_0x3d0038){return c(_0x54dc11,{'eventID':i['USERS_LEAVE'],'leaveEvent':_0x3d0038});}function d(_0x1297bc,_0x134780){return c(_0x1297bc,{'eventID':i['UPDATE_CURSOR'],'updateCursorEvent':_0x134780});}function f(_0x2d1f75,_0x24ac53,_0x1b5090){let _0x325399={[i['CHANGESET_ACK']]:'csAckEvent',[i['CHANGESET_REJ']]:'csRejEvent',[i['CHANGESET_SHOULD_RETRY']]:'csShouldRetryEvent',[i['NEW_CHANGESETS']]:'newCsEvent',[i['PERMISSION_REJ']]:'permissionRejEvent'}[_0x24ac53];return c(_0x2d1f75,{'eventID':_0x24ac53,[_0x325399]:{'cs':_0x1b5090}});}function p(_0x535732,_0x22cffd,_0x1c58cd){return c(_0x535732,{..._0x1c58cd,'eventID':_0x22cffd});}var m=class{['_middlewares']=new Map();['use'](_0xe10989,_0x394de0){let _0x262d12=this['_middlewares']['get'](_0xe10989)??[],_0xcd2d61=_0x394de0;_0x262d12['push'](_0xcd2d61),this['_middlewares']['set'](_0xe10989,_0x262d12);let _0x360a15=!0x1;return{'dispose':()=>{if(_0x360a15)return;_0x360a15=!0x0;let _0x32f55b=_0x262d12['indexOf'](_0xcd2d61);_0x32f55b>=0x0&&_0x262d12['splice'](_0x32f55b,0x1);}};}async['run'](_0x286b17,_0x4f9b36,_0x3b7d8b){let _0x28985e=[...this['_middlewares']['get'](_0x286b17)??[]],_0xe98233=async _0x2e77ca=>{let _0x1f9627=_0x28985e[_0x2e77ca];if(!_0x1f9627){await _0x3b7d8b();return;}let _0x16c759=!0x1,_0x364a6d,_0x3f4c24=()=>{if(_0x16c759)throw Error('Endpoint\x20middleware\x20for\x20'+String(_0x286b17)+'\x20called\x20next()\x20more\x20than\x20once');return _0x16c759=!0x0,_0x364a6d=_0xe98233(_0x2e77ca+0x1),_0x364a6d;};try{await _0x1f9627(_0x4f9b36,_0x3f4c24);}catch(_0x33e034){if(_0x364a6d)try{await _0x364a6d;}catch{}throw _0x33e034;}if(!_0x16c759)throw Error('Endpoint\x20middleware\x20for\x20'+String(_0x286b17)+'\x20completed\x20without\x20calling\x20next()');await _0x364a6d;};await _0xe98233(0x0);}['clear'](){this['_middlewares']['clear']();}},h={'code':n['ErrorCode']['OK'],'message':''};function g(_0x17bb49,_0x2980de){if(!/^-?\d+$/['test'](_0x17bb49))throw new t['CollabError']('INVALID_REQUEST',_0x2980de+'\x20must\x20be\x20an\x20integer');let _0x1f0769=Number(_0x17bb49);if(!Number['isSafeInteger'](_0x1f0769))throw new t['CollabError']('INVALID_REQUEST',_0x2980de+'\x20is\x20outside\x20the\x20safe\x20integer\x20range');return _0x1f0769;}function _(_0xe0c16){if(_0xe0c16 instanceof r['NodeTransportError'])return _0xe0c16['code']==='REQUEST_BODY_TOO_LARGE'?{'status':0x19d,'error':{'code':n['ErrorCode']['INVALID_ARGUMENT'],'message':_0xe0c16['message']}}:_0xe0c16['code']==='INVALID_JSON'||_0xe0c16['code']==='REQUEST_ABORTED'?{'status':0x190,'error':{'code':n['ErrorCode']['INVALID_ARGUMENT'],'message':_0xe0c16['message']}}:{'status':0x1f7,'error':{'code':n['ErrorCode']['INTERNAL_ERROR'],'message':'Transport\x20unavailable'}};if(!(_0xe0c16 instanceof t['CollabError']))return{'status':0x1f4,'error':{'code':n['ErrorCode']['INTERNAL_ERROR'],'message':'Internal\x20server\x20error'}};let _0x167f74={'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']}}[_0xe0c16['code']];return{'status':_0x167f74['status'],'error':{'code':_0x167f74['code'],'message':_0xe0c16['message']}};}function v(_0x12fa2b,_0x2dfb81,_0x207f70){_0x12fa2b['writableEnded']||_0x12fa2b['destroyed']||(_0x12fa2b['statusCode']=_0x2dfb81,_0x12fa2b['setHeader']('content-type','application/json;\x20charset=utf-8'),_0x12fa2b['end'](JSON['stringify'](_0x207f70,function(_0x40e37a,_0x419551){let _0xc21867=this[_0x40e37a];return _0xc21867 instanceof Uint8Array?Buffer['from'](_0xc21867)['toString']('base64'):_0x419551;})));}var y=class{['_tickets']=new Map();['_disposed']=!0x1;async['issue'](_0x7b3954,_0x52fa00){if(this['_disposed'])throw Error('Session\x20ticket\x20store\x20is\x20disposed');if(!Number['isSafeInteger'](_0x52fa00)||_0x52fa00<=0x0)throw TypeError('Session\x20ticket\x20TTL\x20must\x20be\x20a\x20positive\x20safe\x20integer');this['_purgeExpired']();let _0x2c501b;do _0x2c501b=(0x0,e['randomBytes'])(0x20)['toString']('base64url');while(this['_tickets']['has'](_0x2c501b));return this['_tickets']['set'](_0x2c501b,{'record':_0x7b3954,'expiresAt':Date['now']()+_0x52fa00}),_0x2c501b;}async['consume'](_0x4c8e80){if(this['_disposed']||!_0x4c8e80)return null;let _0x455c9b=this['_tickets']['get'](_0x4c8e80);return!_0x455c9b||(this['_tickets']['delete'](_0x4c8e80),_0x455c9b['expiresAt']<=Date['now']())?null:_0x455c9b['record'];}async['dispose'](){this['_disposed']||(this['_disposed']=!0x0,this['_tickets']['clear']());}['_purgeExpired'](){let _0x468f20=Date['now']();for(let [_0x264126,_0x243ddb]of this['_tickets'])_0x243ddb['expiresAt']<=_0x468f20&&this['_tickets']['delete'](_0x264126);}},b=0x5*0xea60;function x(_0x1f9390){if(!_0x1f9390['startsWith']('/')||_0x1f9390==='/'||_0x1f9390['endsWith']('/')||_0x1f9390['includes']('?')||_0x1f9390['includes']('#'))throw TypeError('protocolBasePath\x20must\x20be\x20an\x20absolute\x20path\x20without\x20a\x20trailing\x20slash');return _0x1f9390;}function S(_0x688b92){if(!_0x688b92||typeof _0x688b92!='object')throw new t['CollabError']('INVALID_REQUEST','Request\x20body\x20must\x20be\x20an\x20object');let _0x54a7ef=_0x688b92;if(typeof _0x54a7ef['unitID']!='string'||typeof _0x54a7ef['memberID']!='string'||!Number['isSafeInteger'](_0x54a7ef['type'])||!_0x54a7ef['changeset']||typeof _0x54a7ef['changeset']!='object')throw new t['CollabError']('INVALID_REQUEST','Invalid\x20new\x20changes\x20request');}function C(_0x47ac43){if(!Array['isArray'](_0x47ac43)||_0x47ac43['length']===0x0||_0x47ac43['some'](_0x312321=>typeof _0x312321!='string'||_0x312321['trim']()['length']===0x0))throw new t['CollabError']('INVALID_REQUEST','unitIds\x20must\x20be\x20a\x20non-empty\x20string\x20array');}function w(_0x21f70c){let _0x3c6f98=_0x21f70c['getAll']('unitIds');C(_0x3c6f98);let _0x2f672e=_0x21f70c['getAll']('hardDelete');if(_0x2f672e['length']>0x1||_0x2f672e['length']===0x1&&_0x2f672e[0x0]!=='true'&&_0x2f672e[0x0]!=='false')throw new t['CollabError']('INVALID_REQUEST','hardDelete\x20must\x20be\x20true\x20or\x20false');return{'unitIds':_0x3c6f98,'hardDelete':_0x2f672e[0x0]==='true'};}function T(_0x34e5fe){if(!_0x34e5fe||typeof _0x34e5fe!='object')throw new t['CollabError']('INVALID_REQUEST','Request\x20body\x20must\x20be\x20an\x20object');C(_0x34e5fe['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(_0x163b18,_0x1788d5={}){if(this['_service']=_0x163b18,!_0x163b18)throw TypeError('UniverCollabEndpoint\x20requires\x20a\x20service');if(this['_ticketStore']=_0x1788d5['ticketStore']??new y(),this['_ownsTicketStore']=_0x1788d5['ticketStore']===void 0x0,this['_ticketTtlMs']=_0x1788d5['sessionTicketTtlMs']??b,!Number['isSafeInteger'](this['_ticketTtlMs'])||this['_ticketTtlMs']<=0x0)throw TypeError('sessionTicketTtlMs\x20must\x20be\x20a\x20positive\x20safe\x20integer');this['_protocolBasePath']=x(_0x1788d5['protocolBasePath']??'/universer-api'),this['_serviceSubscriptions']=[this['_service']['on']('changesetCommitted',_0x5c0d41=>{this['_enqueueCommittedChangeset'](_0x5c0d41['changeset'],_0x5c0d41['memberID']);}),this['_service']['on']('unitsDeleted',_0xee9072=>{for(let _0x122ac5 of _0xee9072['request']['unitIDs'])this['_deletedUnitIDs']['add'](_0x122ac5);for(let _0x73de33 of _0xee9072['request']['unitIDs'])this['_enqueueUnitOutbound'](_0x73de33,async()=>{this['_evictUnitRoom'](_0x73de33);});}),this['_service']['on']('unitsRecovered',async _0x4479b0=>{await Promise['all'](_0x4479b0['request']['unitIDs']['map'](_0x76241=>this['_enqueueUnitOutbound'](_0x76241,async()=>{this['_deletedUnitIDs']['delete'](_0x76241);})));})];}['use'](_0x4e1360,_0xfb52c6){return this['_assertRunning'](),this['_middleware']['use'](_0x4e1360,_0xfb52c6);}['on'](_0x262096,_0xfb3d34){this['_assertRunning']();let _0x3a1e5f=this['_listeners']['get'](_0x262096)??new Set(),_0x411912=_0xfb3d34;_0x3a1e5f['add'](_0x411912),this['_listeners']['set'](_0x262096,_0x3a1e5f);let _0x4aa428=!0x1;return{'dispose':()=>{_0x4aa428||(_0x4aa428=!0x0,_0x3a1e5f['delete'](_0x411912));}};}async['invalidateUnitSessions'](_0x538748){if(this['_assertRunning'](),typeof _0x538748['unitID']!='string'||!_0x538748['unitID'])throw TypeError('unitID\x20must\x20be\x20a\x20non-empty\x20string');if(_0x538748['userID']!==void 0x0&&(typeof _0x538748['userID']!='string'||!_0x538748['userID']))throw TypeError('userID\x20must\x20be\x20a\x20non-empty\x20string\x20when\x20provided');await this['_enqueueUnitOutbound'](_0x538748['unitID'],async()=>{let _0xb35c1a=[...this['_rooms']['get'](_0x538748['unitID'])?.['values']()??[]]['filter'](_0xb1c035=>_0x538748['userID']===void 0x0||_0xb1c035['session']['userID']===_0x538748['userID']);for(let _0x354d03 of _0xb35c1a)_0x354d03['connection']['close'](0xfa3,'Unit\x20access\x20changed'),await this['_disconnectBinding'](_0x354d03,'session-evicted');});}async['publishTrustedUnitEvent'](_0x840a06){this['_assertRunning']();let _0x1c2cda=[...this['_rooms']['get'](_0x840a06['unitID'])?.['keys']()??[]],_0x531924=p(_0x840a06['unitID'],_0x840a06['eventID'],_0x840a06['data']);this['_enqueueUnitOutbound'](_0x840a06['unitID'],async()=>{for(let _0x4133ae of _0x1c2cda){let _0x2c8c=this['_bindingsByMember']['get'](_0x4133ae);_0x2c8c?.['joinedUnitIDs']['has'](_0x840a06['unitID'])&&(_0x4133ae===_0x840a06['memberID']&&_0x2c8c['session']['userID']===_0x840a06['userID']||await this['_safeSend'](_0x2c8c['connection'],_0x531924));}});}['register'](_0xf191d0){this['_assertRunning']();let _0x115e60=this['_protocolBasePath'],_0x5f512a=_0x35c553=>_0xe025fd=>this['_handleHttp'](_0xe025fd,_0x35c553);_0xf191d0['get'](_0x115e60+'/user/session-ticket',_0x5f512a('ticket')),_0xf191d0['delete'](_0x115e60+'/snapshot/-/units',_0x5f512a('delete-units')),_0xf191d0['post'](_0x115e60+'/snapshot/-/units/recover',_0x5f512a('recover-units')),_0xf191d0['post'](_0x115e60+'/comb/:type/unit/:unitID/new_changes',_0x5f512a('new-changes')),_0xf191d0['get'](_0x115e60+'/snapshot/block/:type/unit/:unitID/block/:blockID',_0x5f512a('deserialized-block')),_0xf191d0['get'](_0x115e60+'/snapshot/:type/unit/:unitID/rev/:revision',_0x5f512a('unit')),_0xf191d0['get'](_0x115e60+'/snapshot/:type/unit/:unitID/block/:blockID',_0x5f512a('block')),_0xf191d0['get'](_0x115e60+'/snapshot/:type/unit/:unitID/fetchmissing',_0x5f512a('fetch-missing')),_0xf191d0['upgrade'](_0x115e60+'/comb/connect',_0x3b7e2e=>this['_handleUpgrade'](_0x3b7e2e));}async['_handleUpgrade'](_0x421def){if(this['_disposed']){_0x421def['reject'](0x1f7,'Endpoint\x20is\x20disposed');return;}let _0x25d6c4=new URL(_0x421def['incomingMessage']['url']??'/','http://localhost'),_0x13fc2b=await this['_ticketStore']['consume'](_0x25d6c4['searchParams']['get']('sessionTicket')??'');if(!_0x13fc2b){_0x421def['reject'](0x191,'Invalid\x20or\x20expired\x20session\x20ticket');return;}_0x421def['accept']({'open':({connection:_0x2214bf})=>this['_openConnection'](_0x13fc2b,_0x2214bf),'message':_0x275ee3=>this['_handleMessage'](_0x275ee3),'close':({connection:_0x5a0e7d})=>this['_disconnectConnection'](_0x5a0e7d,'connection-closed')});}async['dispose'](){if(this['_disposed'])return;this['_disposed']=!0x0;for(let _0x5ef05d of this['_serviceSubscriptions'])_0x5ef05d['dispose']();await Promise['allSettled']([...this['_outboundQueues']['values']()]);let _0x277031=[...this['_bindingsByConnection']['values']()];for(let _0x2df03a of _0x277031)await this['_disconnectBinding'](_0x2df03a,'endpoint-disposed'),_0x2df03a['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'](_0x180bfa,_0x51631e){try{this['_assertRunning']();let _0x1888d3=new URL(_0x180bfa['incomingMessage']['url']??'/','http://localhost');if(!_0x180bfa['userID'])throw new t['CollabError']('UNAUTHENTICATED','HTTP\x20user\x20is\x20not\x20authenticated');if(_0x51631e==='ticket'){let _0x1353e9=await this['_ticketStore']['issue']({'userID':_0x180bfa['userID'],'customData':_0x180bfa['customData']},this['_ticketTtlMs']);v(_0x180bfa['response'],0xc8,{'error':h,'ticket':_0x1353e9});return;}let _0x335160={'userID':_0x180bfa['userID'],'customData':_0x180bfa['customData']};if(_0x51631e==='delete-units'){let _0x357b7e=w(_0x1888d3['searchParams']);await this['_service']['deleteUnits']({'unitIDs':_0x357b7e['unitIds'],'hardDelete':_0x357b7e['hardDelete']},_0x335160),v(_0x180bfa['response'],0xc8,{'error':h});return;}if(_0x51631e==='recover-units'){let _0x4f057d=await _0x180bfa['readJson']();T(_0x4f057d),await this['_service']['recoverUnits']({'unitIDs':_0x4f057d['unitIds']},_0x335160),v(_0x180bfa['response'],0xc8,{'error':h});return;}let _0x2b4a1c=g(_0x180bfa['params']['type'],'type'),_0x340e68=_0x180bfa['params']['unitID'];if(_0x51631e==='new-changes'){await this['_handleNewChanges'](_0x180bfa,_0x340e68,_0x2b4a1c);return;}switch(_0x51631e){case'unit':{let _0x2eea1a=g(_0x180bfa['params']['revision'],'revision'),_0x1ba75c=await this['_service']['getUnitLoadData']({'unitID':_0x340e68,'type':_0x2b4a1c,'revision':_0x2eea1a},_0x335160);v(_0x180bfa['response'],0xc8,{'error':h,'snapshot':_0x1ba75c['snapshot'],'changesets':_0x1ba75c['changesets']});return;}case'block':case'deserialized-block':{let _0x15a19c=await this['_service']['getSheetBlock']({'unitID':_0x340e68,'type':_0x2b4a1c,'blockID':_0x180bfa['params']['blockID']},_0x335160);if(!_0x15a19c['block'])throw new t['CollabError']('UNIT_NOT_FOUND','Sheet\x20block\x20was\x20not\x20found');let _0x2956ab=_0x51631e==='deserialized-block'?{..._0x15a19c['block'],'data':JSON['parse'](new TextDecoder()['decode'](_0x15a19c['block']['data']))}:_0x15a19c['block'];v(_0x180bfa['response'],0xc8,{'error':h,'block':_0x2956ab});return;}case'fetch-missing':{let _0x3a77fa=g(_0x1888d3['searchParams']['get']('from')??'','from'),_0x1773d6=g(_0x1888d3['searchParams']['get']('to')??'','to'),_0x4fa54c=await this['_service']['getChangesets']({'unitID':_0x340e68,'type':_0x2b4a1c,'from':_0x3a77fa,'to':_0x1773d6},_0x335160);v(_0x180bfa['response'],0xc8,{'error':h,'changesets':_0x4fa54c['changesets']});return;}}}catch(_0x163e48){let _0x3c23ef=_(_0x163e48 instanceof SyntaxError?new t['CollabError']('INTERNAL_ERROR','Stored\x20sheet\x20block\x20is\x20not\x20valid\x20JSON',{'cause':_0x163e48}):_0x163e48);v(_0x180bfa['response'],_0x3c23ef['status'],{'error':_0x3c23ef['error']});}}async['_openConnection'](_0x3888b1,_0x64562a){try{let _0x2376c9=(0x0,e['randomUUID'])(),_0xae7cdf={'memberID':_0x2376c9,'userID':_0x3888b1['userID'],'customData':_0x3888b1['customData']},_0x5d6a29={'memberID':_0x2376c9,'userID':_0x3888b1['userID'],'name':_0x3888b1['userID']},_0x1cb49b={'connection':_0x64562a,'session':_0xae7cdf,'member':_0x5d6a29};await this['_middleware']['run']('connect',_0x1cb49b,()=>void 0x0);let _0xb4c559={'connection':_0x64562a,'session':_0xae7cdf,'member':_0x5d6a29,'joinedUnitIDs':new Set()};this['_bindingsByConnection']['set'](_0x64562a['id'],_0xb4c559),this['_bindingsByMember']['set'](_0x2376c9,_0xb4c559);}catch(_0x1d60f1){_0x64562a['close'](_0x1d60f1 instanceof t['CollabError']?0x3f0:0x3f3,_0x1d60f1 instanceof t['CollabError']?'Connection\x20rejected':'Endpoint\x20failure');}}async['_handleMessage'](_0x129c98){let _0x592aab=this['_bindingsByConnection']['get'](_0x129c98['connection']['id']);if(!_0x592aab){_0x129c98['connection']['close'](0x3f0,'WebSocket\x20Session\x20is\x20not\x20established');return;}if(typeof _0x129c98['data']!='string'){_0x129c98['connection']['close'](0x3eb,'Comb\x20messages\x20must\x20be\x20JSON\x20text');return;}let _0x4b64c2;try{let _0x2d2909=JSON['parse'](_0x129c98['data']);if(!_0x2d2909||typeof _0x2d2909!='object')throw Error('invalid');_0x4b64c2=_0x2d2909;}catch{_0x129c98['connection']['close'](0x3eb,'Invalid\x20Comb\x20JSON\x20message');return;}let _0x14475f=typeof _0x4b64c2['routeKey']=='string'?_0x4b64c2['routeKey']:'';switch(_0x4b64c2['cmd']){case n['CombCmd']['HELLO']:case n['CombCmd']['HEARTBEAT']:await _0x129c98['connection']['send'](JSON['stringify'](a(_0x4b64c2['cmd'],_0x592aab['member']['memberID'],_0x14475f)));return;case n['CombCmd']['JOIN']:await this['_handleJoin'](_0x592aab,_0x4b64c2,_0x14475f);return;case n['CombCmd']['LEAVE']:await this['_handleLeave'](_0x592aab,_0x4b64c2,_0x14475f);return;case n['CombCmd']['INGEST']:if(_0x4b64c2['collaMsg']?.['eventID']!==i['UPDATE_CURSOR'])return;await this['_handlePresence'](_0x592aab,_0x4b64c2,_0x129c98['customData']);return;default:return;}}async['_handleJoin'](_0x34125d,_0x3b9384,_0x3f8ffd){let _0x115d16=_0x3b9384['joinReq']?.['rooms'],_0x2798b6=_0x115d16?.['length']?_0x115d16['map'](_0xdd42f5=>_0xdd42f5['roomID']):_0x3f8ffd?[_0x3f8ffd]:[];if(_0x2798b6['length']===0x0||_0x2798b6['some'](_0x421966=>typeof _0x421966!='string'||!_0x421966)){await _0x34125d['connection']['send'](JSON['stringify'](o(_0x3f8ffd,n['CmdRspCode']['FAIL'],{},'Invalid\x20JOIN\x20request')));return;}let _0x58813b=[...new Set(_0x2798b6)],_0x568c55=_0x58813b['filter'](_0x31d874=>!_0x34125d['joinedUnitIDs']['has'](_0x31d874));try{for(let _0x586651 of _0x58813b)this['_assertJoinable'](_0x586651);for(let _0x211be2 of _0x568c55)await this['_middleware']['run']('joinUnit',{'session':_0x34125d['session'],'unitID':_0x211be2},()=>void 0x0);for(let _0x5c9da2 of _0x58813b)this['_assertJoinable'](_0x5c9da2);}catch(_0x42cf23){let _0x1b7415=_0x42cf23 instanceof t['CollabError']&&_0x42cf23['code']==='UNIT_NOT_FOUND'?n['CmdRspCode']['JOIN_ROOM_NOT_EXISTS']:_0x42cf23 instanceof t['CollabError']&&(_0x42cf23['code']==='PERMISSION_DENIED'||_0x42cf23['code']==='UNAUTHENTICATED')?n['CmdRspCode']['JOIN_ROOM_PERMISSION_DENIED']:n['CmdRspCode']['FAIL'];await _0x34125d['connection']['send'](JSON['stringify'](o(_0x3f8ffd||_0x58813b[0x0],_0x1b7415,{},_0x42cf23 instanceof t['CollabError']?_0x42cf23['message']:'JOIN\x20failed')));return;}for(let _0x926897 of _0x568c55){let _0x2187a7=this['_rooms']['get'](_0x926897)??new Map();_0x2187a7['set'](_0x34125d['member']['memberID'],_0x34125d),this['_rooms']['set'](_0x926897,_0x2187a7),_0x34125d['joinedUnitIDs']['add'](_0x926897);}let _0x4f0eda={};for(let _0x20ca94 of _0x58813b)_0x4f0eda[_0x20ca94]={'roomID':_0x20ca94,'members':[...this['_rooms']['get'](_0x20ca94)?.['values']()??[]]['map'](_0x3fa68a=>s(_0x3fa68a['member']))};await _0x34125d['connection']['send'](JSON['stringify'](o(_0x3f8ffd||_0x58813b[0x0],n['CmdRspCode']['OK'],_0x4f0eda,'success')));for(let _0x8f2152 of _0x568c55)await this['_broadcastToRoom'](_0x8f2152,l(_0x8f2152,s(_0x34125d['member'])),_0x34125d['member']['memberID']);}async['_handleLeave'](_0x14f36d,_0x28a9cb,_0x239008){let _0x573662=typeof _0x28a9cb['leaveReq']?.['roomID']=='string'?_0x28a9cb['leaveReq']['roomID']:_0x239008;_0x573662&&await this['_leaveUnit'](_0x14f36d,_0x573662,'client-leave');}async['_handlePresence'](_0x59ea0f,_0x5b3b41,_0x3cc01){let _0x57755f=typeof _0x5b3b41['routeKey']=='string'?_0x5b3b41['routeKey']:'',_0x5518d6=_0x5b3b41['collaMsg']?.['updateCursorEvent']?.['selection'];if(!_0x57755f||!_0x59ea0f['joinedUnitIDs']['has'](_0x57755f)||typeof _0x5518d6!='string')return;let _0x2c3615={'unitID':_0x57755f,'memberID':_0x59ea0f['member']['memberID'],'selection':_0x5518d6};try{await this['_middleware']['run']('receivePresence',{'session':_0x59ea0f['session'],'unitID':_0x57755f,'payload':_0x2c3615,'customData':_0x3cc01},()=>void 0x0);}catch(_0x4c0086){if(_0x4c0086 instanceof t['CollabError'])return;throw _0x4c0086;}if(typeof _0x2c3615['selection']!='string')return;let _0x391da8=[...this['_rooms']['get'](_0x57755f)?.['values']()??[]]['filter'](_0xded533=>_0xded533!==_0x59ea0f);for(let _0x5474b4 of _0x391da8){let _0x9e3c2d={'unitID':_0x57755f,'memberID':_0x59ea0f['member']['memberID'],'selection':_0x2c3615['selection']};try{await this['_middleware']['run']('sendPresence',{'session':_0x59ea0f['session'],'unitID':_0x57755f,'payload':_0x9e3c2d,'customData':_0x3cc01,'targetMemberID':_0x5474b4['member']['memberID']},()=>void 0x0);}catch{continue;}typeof _0x9e3c2d['selection']=='string'&&await this['_safeSend'](_0x5474b4['connection'],d(_0x57755f,{'unitID':_0x57755f,'memberID':_0x59ea0f['member']['memberID'],'selection':_0x9e3c2d['selection']}));}}async['_handleNewChanges'](_0x2967e7,_0x5a4f01,_0x35e1dd){let _0x2ea733=await _0x2967e7['readJson']();if(S(_0x2ea733),_0x2ea733['unitID']!==_0x5a4f01||_0x2ea733['type']!==_0x35e1dd||_0x2ea733['changeset']?.['unitID']!==_0x5a4f01||_0x2ea733['changeset']['type']!==_0x35e1dd)throw new t['CollabError']('INVALID_REQUEST','Route,\x20request\x20and\x20changeset\x20identity\x20must\x20match');let _0xb57c49=await this['_service']['submitChangeset']({'changeset':_0x2ea733['changeset']},{'userID':_0x2967e7['userID'],'memberID':_0x2ea733['memberID'],'customData':_0x2967e7['customData']});if(_0xb57c49['status']==='already-committed')await this['_sendSubmitResult'](_0x5a4f01,_0x2ea733['memberID'],_0x2967e7['userID'],i['CHANGESET_ACK'],_0xb57c49['changeset']);else{if(_0xb57c49['status']==='rejected'){let _0x1ff298=_0xb57c49['error']['code']==='PERMISSION_DENIED'||_0xb57c49['error']['code']==='UNAUTHENTICATED'?i['PERMISSION_REJ']:i['CHANGESET_REJ'];await this['_sendSubmitResult'](_0x5a4f01,_0x2ea733['memberID'],_0x2967e7['userID'],_0x1ff298,{..._0x2ea733['changeset'],'userID':_0x2967e7['userID'],'memberID':_0x2ea733['memberID']});}else _0xb57c49['status']==='retry'&&await this['_sendSubmitResult'](_0x5a4f01,_0x2ea733['memberID'],_0x2967e7['userID'],i['CHANGESET_SHOULD_RETRY'],{..._0x2ea733['changeset'],'userID':_0x2967e7['userID'],'memberID':_0x2ea733['memberID']});}v(_0x2967e7['response'],0xc8,{'error':h});}async['_sendSubmitResult'](_0x311a23,_0x29d1ad,_0x1dcac6,_0x5204ae,_0x24628c){if(this['_disposed'])return;let _0x4d4707=this['_bindingsByMember']['get'](_0x29d1ad);!_0x4d4707||_0x4d4707['session']['userID']!==_0x1dcac6||!_0x4d4707['joinedUnitIDs']['has'](_0x311a23)||await this['_safeSend'](_0x4d4707['connection'],f(_0x311a23,_0x5204ae,_0x24628c));}['_enqueueCommittedChangeset'](_0x259a09,_0x5f0fe3){if(this['_disposed'])return;let _0x406cce=_0x259a09['unitID'],_0x328caf=[...this['_rooms']['get'](_0x406cce)?.['keys']()??[]];this['_enqueueUnitOutbound'](_0x406cce,async()=>{let _0x1c1e8b=[],_0x31da3d;for(let _0x372a67 of _0x328caf){let _0xa2cdc5=this['_bindingsByMember']['get'](_0x372a67);if(!_0xa2cdc5?.['joinedUnitIDs']['has'](_0x406cce))continue;let _0x58e3eb=_0x372a67===_0x5f0fe3&&_0xa2cdc5['session']['userID']===_0x259a09['userID']?i['CHANGESET_ACK']:i['NEW_CHANGESETS'];if(_0x58e3eb===i['CHANGESET_ACK'])_0x1c1e8b['push'](this['_safeSend'](_0xa2cdc5['connection'],f(_0x406cce,_0x58e3eb,_0x259a09)));else try{_0x31da3d??=JSON['stringify'](f(_0x406cce,_0x58e3eb,_0x259a09)),_0x1c1e8b['push'](Promise['resolve'](_0xa2cdc5['connection']['send'](_0x31da3d)));}catch{}}await Promise['allSettled'](_0x1c1e8b);});}['_evictUnitRoom'](_0x46dcd4){let _0xc023ce=this['_rooms']['get'](_0x46dcd4);if(_0xc023ce){this['_rooms']['delete'](_0x46dcd4);for(let _0xe9d664 of _0xc023ce['values']())_0xe9d664['joinedUnitIDs']['delete'](_0x46dcd4);}}['_enqueueUnitOutbound'](_0x4d4c42,_0x5628bb){let _0x9d60c7=(this['_outboundQueues']['get'](_0x4d4c42)??Promise['resolve']())['catch'](()=>void 0x0)['then'](_0x5628bb);return this['_outboundQueues']['set'](_0x4d4c42,_0x9d60c7),_0x9d60c7['finally'](()=>{this['_outboundQueues']['get'](_0x4d4c42)===_0x9d60c7&&this['_outboundQueues']['delete'](_0x4d4c42);}),_0x9d60c7;}async['_disconnectConnection'](_0x862f4b,_0x319aa9){let _0x1652dc=this['_bindingsByConnection']['get'](_0x862f4b['id']);_0x1652dc&&await this['_disconnectBinding'](_0x1652dc,_0x319aa9);}async['_disconnectBinding'](_0x38417f,_0xaaf5ca){this['_bindingsByConnection']['delete'](_0x38417f['connection']['id']),this['_bindingsByMember']['delete'](_0x38417f['member']['memberID']);let _0x1d4849=[..._0x38417f['joinedUnitIDs']];for(let _0xd2e90a of _0x1d4849)await this['_leaveUnit'](_0x38417f,_0xd2e90a,_0xaaf5ca);}async['_leaveUnit'](_0x5b4596,_0x58013c,_0xbd8d21){if(!_0x5b4596['joinedUnitIDs']['delete'](_0x58013c))return!0x1;let _0x49d700=this['_rooms']['get'](_0x58013c);return _0x49d700?.['delete'](_0x5b4596['member']['memberID']),_0x49d700?.['size']===0x0&&this['_rooms']['delete'](_0x58013c),await this['_broadcastToRoom'](_0x58013c,u(_0x58013c,{'memberID':_0x5b4596['member']['memberID'],'name':_0x5b4596['member']['name']}),_0x5b4596['member']['memberID']),await this['_emit']('memberLeftUnit',{'session':_0x5b4596['session'],'unitID':_0x58013c,'reason':_0xbd8d21}),!0x0;}async['_broadcastToRoom'](_0x4f92f9,_0x2aa7aa,_0x532257){let _0x3cb82e=[...this['_rooms']['get'](_0x4f92f9)?.['values']()??[]];await Promise['allSettled'](_0x3cb82e['filter'](_0x19d83b=>_0x19d83b['member']['memberID']!==_0x532257)['map'](_0x2c8081=>this['_safeSend'](_0x2c8081['connection'],_0x2aa7aa)));}async['_safeSend'](_0x2e36b5,_0xc7ab1d){try{await _0x2e36b5['send'](JSON['stringify'](_0xc7ab1d));}catch{}}async['_emit'](_0x33db16,_0x51be12){let _0x2d7a73=[...this['_listeners']['get'](_0x33db16)??[]];for(let _0x3a0c5f of _0x2d7a73)try{await _0x3a0c5f(_0x51be12);}catch{}}['_assertRunning'](){if(this['_disposed'])throw Error('UniverCollabEndpoint\x20is\x20disposed');}['_assertJoinable'](_0x5143f8){if(this['_deletedUnitIDs']['has'](_0x5143f8))throw new t['CollabError']('UNIT_NOT_FOUND','Unit\x20has\x20been\x20deleted');}};exports['MemorySessionTicketStore']=y,exports['UniverCollabEndpoint']=E;
package/dist/index.d.ts CHANGED
@@ -21,19 +21,11 @@ declare class UniverCollabEndpoint implements NodeTransportEndpoint, ITrustedUni
21
21
  constructor(_service: Omit<IUniverCollabService, "dbAdapter">, options?: UniverCollabEndpointOptions);
22
22
  use<K extends EndpointMiddlewareAction>(action: K, middleware: EndpointMiddlewareMap[K]): Disposable;
23
23
  on<K extends keyof EndpointEventMap>(event: K, listener: EndpointListener<K>): Disposable;
24
- findJoinedSession(input: {
25
- readonly unitID: string;
26
- readonly memberID: string;
27
- readonly authenticatedUserID: string;
28
- }): EndpointSession | null;
29
- findJoinedSessionByUser(input: {
30
- readonly unitID: string;
31
- readonly authenticatedUserID: string;
32
- }): EndpointSession | null;
33
24
  invalidateUnitSessions(input: InvalidateUnitSessionsInput): Promise<void>;
34
25
  publishTrustedUnitEvent(input: {
35
26
  readonly unitID: string;
36
27
  readonly memberID: string;
28
+ readonly userID: string;
37
29
  readonly eventID: string;
38
30
  readonly data: Readonly<Record<string, unknown>>;
39
31
  }): Promise<void>;
@@ -47,7 +39,7 @@ declare class UniverCollabEndpoint implements NodeTransportEndpoint, ITrustedUni
47
39
  private _handleLeave;
48
40
  private _handlePresence;
49
41
  private _handleNewChanges;
50
- private _trustedClientChangeset;
42
+ private _sendSubmitResult;
51
43
  private _enqueueCommittedChangeset;
52
44
  private _evictUnitRoom;
53
45
  private _enqueueUnitOutbound;
@@ -93,18 +85,10 @@ interface EndpointSessionBinding {
93
85
  readonly joinedUnitIDs: ReadonlySet<string>;
94
86
  }
95
87
  interface ITrustedUnitRoomHost {
96
- findJoinedSession(input: {
97
- readonly unitID: string;
98
- readonly memberID: string;
99
- readonly authenticatedUserID: string;
100
- }): EndpointSession | null;
101
- findJoinedSessionByUser(input: {
102
- readonly unitID: string;
103
- readonly authenticatedUserID: string;
104
- }): EndpointSession | null;
105
88
  publishTrustedUnitEvent(input: {
106
89
  readonly unitID: string;
107
90
  readonly memberID: string;
91
+ readonly userID: string;
108
92
  readonly eventID: string;
109
93
  readonly data: Readonly<Record<string, unknown>>;
110
94
  }): Promise<void>;
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- const _0x42a26c=_0x2ea4;(function(_0x274d10,_0x32d250){const _0x161f8d=_0x2ea4,_0x1031d0=_0x274d10();while(!![]){try{const _0x4c1041=parseInt(_0x161f8d(0x7c))/0x1+parseInt(_0x161f8d(0x7e))/0x2*(-parseInt(_0x161f8d(0x74))/0x3)+-parseInt(_0x161f8d(0x73))/0x4*(-parseInt(_0x161f8d(0x7f))/0x5)+parseInt(_0x161f8d(0x7d))/0x6*(parseInt(_0x161f8d(0x7b))/0x7)+parseInt(_0x161f8d(0x75))/0x8+parseInt(_0x161f8d(0x7a))/0x9*(parseInt(_0x161f8d(0x78))/0xa)+-parseInt(_0x161f8d(0x79))/0xb*(parseInt(_0x161f8d(0x80))/0xc);if(_0x4c1041===_0x32d250)break;else _0x1031d0['push'](_0x1031d0['shift']());}catch(_0x55889b){_0x1031d0['push'](_0x1031d0['shift']());}}}(_0x34fb,0x21a6d));function _0x2ea4(_0x4607ad,_0x5d280b){_0x4607ad=_0x4607ad-0x73;const _0x34fb7a=_0x34fb();let _0x2ea462=_0x34fb7a[_0x4607ad];return _0x2ea462;}function _0x34fb(){const _0x5cf028=['1907640FwRYSE','UniverCollabEndpoint','MemorySessionTicketStore','2409810aqphgp','8925400RpRevo','9fgKtZI','898331qQQjKi','225598YzrgMW','6TePNKZ','52846tiDnpA','237155YFcJvf','12OCjilk','12chuURF','3AKWKzt'];_0x34fb=function(){return _0x5cf028;};return _0x34fb();}import _0x2e72b5 from'./index.cjs';const facadeExport0=_0x2e72b5[_0x42a26c(0x77)],facadeExport1=_0x2e72b5[_0x42a26c(0x76)];export{facadeExport0 as MemorySessionTicketStore,facadeExport1 as UniverCollabEndpoint};
1
+ const _0x47288c=_0x4f1e;(function(_0x277872,_0x466f3e){const _0x411f58=_0x4f1e,_0x454154=_0x277872();while(!![]){try{const _0x5d0cdb=-parseInt(_0x411f58(0xf2))/0x1*(parseInt(_0x411f58(0xf4))/0x2)+parseInt(_0x411f58(0xef))/0x3*(parseInt(_0x411f58(0xf9))/0x4)+-parseInt(_0x411f58(0xee))/0x5+-parseInt(_0x411f58(0xf3))/0x6*(-parseInt(_0x411f58(0xf7))/0x7)+-parseInt(_0x411f58(0xf0))/0x8+parseInt(_0x411f58(0xf5))/0x9+parseInt(_0x411f58(0xf6))/0xa*(-parseInt(_0x411f58(0xf8))/0xb);if(_0x5d0cdb===_0x466f3e)break;else _0x454154['push'](_0x454154['shift']());}catch(_0x5c7cb4){_0x454154['push'](_0x454154['shift']());}}}(_0x4a6b,0x6b26d));function _0x4f1e(_0x554a2a,_0x5bd3f1){_0x554a2a=_0x554a2a-0xee;const _0x4a6b12=_0x4a6b();let _0x4f1e46=_0x4a6b12[_0x554a2a];return _0x4f1e46;}import _0x41fc7e from'./index.cjs';function _0x4a6b(){const _0x45fef0=['2571944YxKXiz','MemorySessionTicketStore','27yhCZWj','42lUuXVD','4022YmiygJ','5683320RuSaXv','20sZzXLj','494347UbxipE','1612523mBKvIB','116ssAnMT','UniverCollabEndpoint','2503895OorNkO','49947KkkvMU'];_0x4a6b=function(){return _0x45fef0;};return _0x4a6b();}const facadeExport0=_0x41fc7e[_0x47288c(0xf1)],facadeExport1=_0x41fc7e[_0x47288c(0xfa)];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.2",
4
+ "version": "1.0.4",
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.2",
20
- "@univerjs-pro/collaboration-transport-node": "1.0.2",
21
- "@univerjs/protocol": "1.0.2"
19
+ "@univerjs-pro/collaboration-service": "1.0.4",
20
+ "@univerjs-pro/collaboration-transport-node": "1.0.4",
21
+ "@univerjs/protocol": "1.0.4"
22
22
  }
23
23
  }