@univerjs-pro/collaboration-history-endpoint 1.0.0-beta.2

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 ADDED
@@ -0,0 +1,49 @@
1
+ # @univerjs-pro/collaboration-history-endpoint
2
+
3
+ English | [简体中文](./README.zh-CN.md)
4
+
5
+ A Node Transport Endpoint for the Univer History HTTP protocol. The frontend History UI uses it to read history entries, creators, and changesets.
6
+
7
+ ```text
8
+ History HTTP request
9
+ → Transport authentication middleware
10
+ → UniverHistoryEndpoint
11
+ → History Service middleware
12
+ → History Database Adapter / Collaboration Service
13
+ ```
14
+
15
+ ## Installation and registration
16
+
17
+ ```bash
18
+ pnpm add \
19
+ @univerjs-pro/collaboration-history-service \
20
+ @univerjs-pro/collaboration-history-endpoint \
21
+ @univerjs-pro/collaboration-endpoint \
22
+ @univerjs-pro/collaboration-transport-node
23
+ ```
24
+
25
+ ```ts
26
+ import { UniverCollabEndpoint } from '@univerjs-pro/collaboration-endpoint';
27
+ import { UniverHistoryEndpoint } from '@univerjs-pro/collaboration-history-endpoint';
28
+
29
+ const historyEndpoint = new UniverHistoryEndpoint(historyService);
30
+ const collabEndpoint = new UniverCollabEndpoint(collabService);
31
+
32
+ transport.use(authenticationMiddleware);
33
+ transport.register(historyEndpoint);
34
+ transport.register(collabEndpoint);
35
+ ```
36
+
37
+ Register authentication first, followed by History Endpoint and the main Collaboration Endpoint. History Endpoint uses the application-provided Transport `userID` and calls History Service APIs for protocol requests. It does not own authentication, ACLs, History storage, or segmentation policy.
38
+
39
+ ## HTTP routes
40
+
41
+ | Method | Path | Service action | Purpose |
42
+ | --- | --- | --- | --- |
43
+ | `GET` | `/universer-api/history/:unitID/list` | `getHistoryList` | Read history entries |
44
+ | `GET` | `/universer-api/history/:unitID/creators` | `listHistoryCreators` | Read history creators |
45
+ | `GET` | `/universer-api/history/:unitID/cs` | `getHistoryChangesets` | Read changesets for history revisions |
46
+
47
+ All three routes call History Service with `ctx.userID/customData` set by Transport middleware for the current HTTP request and enter the corresponding History Service middleware. History Endpoint does not create or read a WebSocket Session.
48
+
49
+ Install authorization middleware for every History Service action. Transport owns and disposes Endpoint; disposing Endpoint does not dispose History Service or its Database Adapter.
@@ -0,0 +1,54 @@
1
+ # @univerjs-pro/collaboration-history-endpoint
2
+
3
+ [English](./README.md) | [简体中文](./README.zh-CN.md)
4
+
5
+ Univer History HTTP Protocol 的 Node Transport Endpoint。前端 History UI 通过它读取历史
6
+ 条目、创建者和 changesets。
7
+
8
+ ```text
9
+ History HTTP 请求
10
+ → Transport authentication middleware
11
+ → UniverHistoryEndpoint
12
+ → History Service middleware
13
+ → History Database Adapter / Collaboration Service
14
+ ```
15
+
16
+ ## 安装与注册
17
+
18
+ ```bash
19
+ pnpm add \
20
+ @univerjs-pro/collaboration-history-service \
21
+ @univerjs-pro/collaboration-history-endpoint \
22
+ @univerjs-pro/collaboration-endpoint \
23
+ @univerjs-pro/collaboration-transport-node
24
+ ```
25
+
26
+ ```ts
27
+ import { UniverCollabEndpoint } from '@univerjs-pro/collaboration-endpoint';
28
+ import { UniverHistoryEndpoint } from '@univerjs-pro/collaboration-history-endpoint';
29
+
30
+ const historyEndpoint = new UniverHistoryEndpoint(historyService);
31
+ const collabEndpoint = new UniverCollabEndpoint(collabService);
32
+
33
+ transport.use(authenticationMiddleware);
34
+ transport.register(historyEndpoint);
35
+ transport.register(collabEndpoint);
36
+ ```
37
+
38
+ 先注册认证,再注册 History Endpoint 和主协同 Endpoint。History Endpoint 使用应用通过
39
+ Transport 提供的 `userID`,调用 History Service API 处理协议请求;它不负责认证、ACL、
40
+ History 存储或分段策略。
41
+
42
+ ## HTTP 路由
43
+
44
+ | Method | Path | Service action | 用途 |
45
+ | --- | --- | --- | --- |
46
+ | `GET` | `/universer-api/history/:unitID/list` | `getHistoryList` | 读取历史条目 |
47
+ | `GET` | `/universer-api/history/:unitID/creators` | `listHistoryCreators` | 读取历史创建者 |
48
+ | `GET` | `/universer-api/history/:unitID/cs` | `getHistoryChangesets` | 读取历史 revision 对应的 changesets |
49
+
50
+ 三条路由都使用当前 HTTP 请求由 Transport middleware 设置的 `ctx.userID/customData`,并
51
+ 进入对应 History Service middleware;History Endpoint 不创建或读取 WebSocket Session。
52
+
53
+ 应用应在 History Service 的各 action 安装权限 middleware。Transport 拥有并释放
54
+ Endpoint;释放 Endpoint 不会释放 History Service 或 Database Adapter。
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ Object['defineProperty'](exports,Symbol['toStringTag'],{'value':'Module'});let e=require('@univerjs-pro/collaboration-service'),t=require('@univerjs-pro/collaboration-transport-node'),n=require('@univerjs/protocol');var r={'code':n['ErrorCode']['OK'],'message':''},i=class{['_service'];['_disposed']=!0x1;constructor(_0x35b97b){if(this['_service']=_0x35b97b,!_0x35b97b)throw TypeError('UniverHistoryEndpoint\x20requires\x20a\x20service');}async['handleHttp'](_0x3eb93f,_0xb086eb){if(this['_disposed']){await _0xb086eb();return;}let _0x174371,_0x28b911;try{_0x174371=new URL(_0x3eb93f['incomingMessage']['url']??'/','http://localhost'),_0x28b911=o(_0x3eb93f['incomingMessage']['method'],_0x174371['pathname']);}catch(_0x20ddbe){d(_0x3eb93f['response'],_0x20ddbe);return;}if(!_0x28b911){await _0xb086eb();return;}try{if(!_0x3eb93f['userID'])throw new e['CollabError']('UNAUTHENTICATED','HTTP\x20user\x20is\x20not\x20authenticated');let _0x150525={'userID':_0x3eb93f['userID'],'customData':_0x3eb93f['customData']};switch(_0x28b911['name']){case'list':{let _0x4c59b0=await this['_service']['getHistoryList']({'unitID':_0x28b911['unitID'],'length':c(_0x174371['searchParams']['get']('length')),..._0x174371['searchParams']['get']('lastLabel')?{'lastLabel':_0x174371['searchParams']['get']('lastLabel')}:{},...u(_0x174371['searchParams']['get']('origin')),'userIDs':_0x174371['searchParams']['getAll']('userIds')['filter'](Boolean)},_0x150525);p(_0x3eb93f['response'],0xc8,{'error':r,...a(_0x4c59b0)});return;}case'creators':{let _0x5773fd=await this['_service']['listHistoryCreators']({'unitID':_0x28b911['unitID']},_0x150525);p(_0x3eb93f['response'],0xc8,{'error':r,'creators':_0x5773fd['creators']['map'](({userID:_0x14306f,..._0x3c1e99})=>({..._0x3c1e99,'userId':_0x14306f}))});return;}case'changesets':{let _0x494d0c=l(_0x174371['searchParams']['get']('startRevision'),'startRevision'),_0x56f69c=l(_0x174371['searchParams']['get']('endRevision'),'endRevision'),_0x2987bb=await this['_service']['getHistoryChangesets']({'unitID':_0x28b911['unitID'],'startRevision':_0x494d0c,'endRevision':_0x56f69c},_0x150525);p(_0x3eb93f['response'],0xc8,{'error':r,..._0x2987bb});return;}}}catch(_0x4b2c44){d(_0x3eb93f['response'],_0x4b2c44);}}['dispose'](){this['_disposed']=!0x0;}};function a(_0x3edddd){let _0x50e61a=Object['fromEntries'](Object['entries'](_0x3edddd['entities']['datas'])['map'](([_0x49ec99,{userID:_0x4d7fd5,unitID:_0x32418d,userIDs:_0x461e00,..._0x2327eb}])=>[_0x49ec99,{..._0x2327eb,'userId':_0x4d7fd5,'unitId':_0x32418d,'userIds':_0x461e00}]));return{..._0x3edddd,'entities':{..._0x3edddd['entities'],'datas':_0x50e61a}};}function o(_0x3ca9f9,_0x45f76a){if(_0x3ca9f9!=='GET')return null;let _0x42e017=_0x45f76a['split']('/')['filter'](Boolean);if(_0x42e017['length']!==0x4||_0x42e017[0x0]!=='universer-api'||_0x42e017[0x1]!=='history')return null;let _0x2549a1=s(_0x42e017[0x2]);if(!_0x2549a1)throw new e['CollabError']('INVALID_REQUEST','unitID\x20is\x20required');switch(_0x42e017[0x3]){case'list':return{'name':'list','unitID':_0x2549a1};case'creators':return{'name':'creators','unitID':_0x2549a1};case'cs':return{'name':'changesets','unitID':_0x2549a1};default:return null;}}function s(_0x3975db){try{return decodeURIComponent(_0x3975db);}catch{throw new e['CollabError']('INVALID_REQUEST','Route\x20contains\x20invalid\x20encoding');}}function c(_0x4c463a){return _0x4c463a===null||_0x4c463a===''?0x14:l(_0x4c463a,'length');}function l(_0x57e6b5,_0x170e1c){if(!_0x57e6b5||!/^\d+$/['test'](_0x57e6b5))throw new e['CollabError']('INVALID_REQUEST',_0x170e1c+'\x20must\x20be\x20a\x20positive\x20integer');let _0x5d0654=Number(_0x57e6b5);if(!Number['isSafeInteger'](_0x5d0654)||_0x5d0654<0x1)throw new e['CollabError']('INVALID_REQUEST',_0x170e1c+'\x20must\x20be\x20a\x20positive\x20integer');return _0x5d0654;}function u(_0x58ae71){if(_0x58ae71===null||_0x58ae71===''||_0x58ae71==='0')return{};if(_0x58ae71==='1'||_0x58ae71==='2')return{'origin':Number(_0x58ae71)};throw new e['CollabError']('INVALID_REQUEST','origin\x20must\x20be\x200,\x201\x20or\x202');}function d(_0x35257f,_0x4621f7){let _0xcb9ca1=f(_0x4621f7);p(_0x35257f,_0xcb9ca1['status'],{'error':_0xcb9ca1['error']});}function f(_0x509955){if(_0x509955 instanceof t['NodeTransportError'])return{'status':_0x509955['code']==='REQUEST_BODY_TOO_LARGE'?0x19d:_0x509955['code']==='TRANSPORT_DISPOSED'?0x1f7:0x190,'error':{'code':_0x509955['code']==='TRANSPORT_DISPOSED'?n['ErrorCode']['INTERNAL_ERROR']:n['ErrorCode']['INVALID_ARGUMENT'],'message':_0x509955['message']}};if(!(_0x509955 instanceof e['CollabError']))return{'status':0x1f4,'error':{'code':n['ErrorCode']['INTERNAL_ERROR'],'message':'Internal\x20server\x20error'}};let _0x1bf95d={'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']}}[_0x509955['code']];return{'status':_0x1bf95d['status'],'error':{'code':_0x1bf95d['code'],'message':_0x509955['message']}};}function p(_0x29993f,_0x4ad765,_0x53bce8){_0x29993f['writableEnded']||_0x29993f['destroyed']||(_0x29993f['statusCode']=_0x4ad765,_0x29993f['setHeader']('content-type','application/json;\x20charset=utf-8'),_0x29993f['end'](JSON['stringify'](_0x53bce8)));}exports['UniverHistoryEndpoint']=i;
@@ -0,0 +1,13 @@
1
+ import { IUniverHistoryService } from "@univerjs-pro/collaboration-history-service";
2
+ import { NodeHttpTransportContext, NodeTransportEndpoint, NodeTransportNext } from "@univerjs-pro/collaboration-transport-node";
3
+
4
+ //#region src/endpoint.d.ts
5
+ declare class UniverHistoryEndpoint implements NodeTransportEndpoint {
6
+ private readonly _service;
7
+ private _disposed;
8
+ constructor(_service: IUniverHistoryService);
9
+ handleHttp(context: NodeHttpTransportContext, next: NodeTransportNext): Promise<void>;
10
+ dispose(): void;
11
+ }
12
+ //#endregion
13
+ export { UniverHistoryEndpoint };
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ const _0x289fb6=_0x2b4c;(function(_0xc54626,_0x2403d0){const _0x2f09d0=_0x2b4c,_0x4effc2=_0xc54626();while(!![]){try{const _0x3eaef7=parseInt(_0x2f09d0(0xb1))/0x1+parseInt(_0x2f09d0(0xaf))/0x2+-parseInt(_0x2f09d0(0xb6))/0x3+-parseInt(_0x2f09d0(0xb4))/0x4*(-parseInt(_0x2f09d0(0xb7))/0x5)+-parseInt(_0x2f09d0(0xb8))/0x6*(parseInt(_0x2f09d0(0xb9))/0x7)+-parseInt(_0x2f09d0(0xb5))/0x8+parseInt(_0x2f09d0(0xb2))/0x9*(parseInt(_0x2f09d0(0xb0))/0xa);if(_0x3eaef7===_0x2403d0)break;else _0x4effc2['push'](_0x4effc2['shift']());}catch(_0x52dfec){_0x4effc2['push'](_0x4effc2['shift']());}}}(_0x2650,0xd002b));function _0x2b4c(_0x1a35f2,_0x5c1aa7){_0x1a35f2=_0x1a35f2-0xaf;const _0x2650c0=_0x2650();let _0x2b4cd5=_0x2650c0[_0x1a35f2];return _0x2b4cd5;}import _0x3d5575 from'./index.cjs';const facadeExport0=_0x3d5575[_0x289fb6(0xb3)];function _0x2650(){const _0x50965e=['4703517pzIRso','589405NdQWuK','114DJeUqD','225708WGSeFH','709036xEITSr','3953390xjVRJi','153391JgFMNx','63SGqfYj','UniverHistoryEndpoint','36MoPSAq','10429800kANKAz'];_0x2650=function(){return _0x50965e;};return _0x2650();}export{facadeExport0 as UniverHistoryEndpoint};
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@univerjs-pro/collaboration-history-endpoint",
3
+ "type": "module",
4
+ "version": "1.0.0-beta.2",
5
+ "main": "./dist/index.cjs",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.cjs"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "dependencies": {
19
+ "@univerjs-pro/collaboration-history-service": "1.0.0-beta.2",
20
+ "@univerjs-pro/collaboration-service": "1.0.0-beta.2",
21
+ "@univerjs-pro/collaboration-transport-node": "1.0.0-beta.2",
22
+ "@univerjs/protocol": "1.0.0-beta.2"
23
+ }
24
+ }