@univerjs-pro/collaboration-endpoint 1.0.3 → 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 +3 -6
- package/README.zh-CN.md +3 -6
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +3 -19
- package/dist/index.mjs +1 -1
- package/package.json +4 -4
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
|
-
→
|
|
130
|
-
→
|
|
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
|
-
→
|
|
132
|
-
→
|
|
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(_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;
|
|
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
|
|
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
|
-
|
|
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.
|
|
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.
|
|
20
|
-
"@univerjs-pro/collaboration-transport-node": "1.0.
|
|
21
|
-
"@univerjs/protocol": "1.0.
|
|
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
|
}
|