@univerjs-pro/collaboration-exchange-endpoint 1.4.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@univerjs-pro/collaboration-exchange-service"),t=require("@univerjs-pro/collaboration-file-service"),n=require("@univerjs-pro/collaboration-service"),r=require("@univerjs-pro/collaboration-transport-node"),i=require("@univerjs/protocol");var a={code:i.ErrorCode.OK,message:``};function o(e){return{code:f(e),message:e instanceof Error?e.message:String(e)}}function s(e,t){e.writableEnded||e.destroyed||(e.statusCode=200,e.setHeader(`content-type`,`application/json; charset=utf-8`),e.end(JSON.stringify(t)))}var c={INVALID_REQUEST:i.ErrorCode.INVALID_ARGUMENT,UNAUTHENTICATED:i.ErrorCode.UNAUTHENTICATED,FILE_NOT_FOUND:i.ErrorCode.NOT_FOUND,TASK_NOT_FOUND:i.ErrorCode.NOT_FOUND,SERVICE_DISPOSED:i.ErrorCode.INTERNAL_ERROR},l={INVALID_REQUEST:i.ErrorCode.INVALID_ARGUMENT,PAYLOAD_TOO_LARGE:i.ErrorCode.INVALID_ARGUMENT,UNAUTHENTICATED:i.ErrorCode.UNAUTHENTICATED,PERMISSION_DENIED:i.ErrorCode.PERMISSION_DENIED,FILE_NOT_FOUND:i.ErrorCode.NOT_FOUND,UPLOAD_TIMEOUT:i.ErrorCode.INTERNAL_ERROR,STORAGE_FAILURE:i.ErrorCode.INTERNAL_ERROR,SERVICE_DISPOSED:i.ErrorCode.INTERNAL_ERROR},u={UNAUTHENTICATED:i.ErrorCode.UNAUTHENTICATED,INVALID_REQUEST:i.ErrorCode.INVALID_ARGUMENT,UNIT_NOT_FOUND:i.ErrorCode.NOT_FOUND,PERMISSION_DENIED:i.ErrorCode.PERMISSION_DENIED,OT_CONFLICT:i.ErrorCode.APPLY_REJECT,REVISION_MISMATCH:i.ErrorCode.CHANGESET_REVISION_CONFILICT,ADAPTER_FAILURE:i.ErrorCode.INTERNAL_ERROR,INTERNAL_ERROR:i.ErrorCode.INTERNAL_ERROR,LICENSE_INVALID:i.ErrorCode.LICENSE_INVALID,LICENSE_POLICY_INVALID:i.ErrorCode.LICENSE_POLICY_INVALID,LICENSE_VERSION_NOT_ALLOWED:i.ErrorCode.LICENSE_VERSION_NOT_ALLOWED,LICENSE_UNIT_TYPE_REJECTED:i.ErrorCode.LICENSE_UNIT_TYPE_REJECTED,LICENSE_DOMAIN_REJECTED:i.ErrorCode.LICENSE_DOMAIN_REJECTED},d=new Set([`INVALID_ARGUMENT`,`UNSUPPORTED_FORMAT`,`INVALID_FILE`,`INCOMPLETE_SNAPSHOT`]);function f(a){if(a instanceof e.ExchangeServiceError)return c[a.code];if(a instanceof t.FileError)return l[a.code]??i.ErrorCode.INTERNAL_ERROR;if(a instanceof n.CollabError)return u[a.code]??i.ErrorCode.INTERNAL_ERROR;if(a instanceof r.NodeTransportError)return a.code===`TRANSPORT_DISPOSED`?i.ErrorCode.INTERNAL_ERROR:i.ErrorCode.INVALID_ARGUMENT;let o=p(a);if(o!==void 0){if(d.has(o))return i.ErrorCode.INVALID_ARGUMENT;if(o.startsWith(`LICENSE_`)&&o in i.ErrorCode)return i.ErrorCode[o]}return i.ErrorCode.INTERNAL_ERROR}function p(e){if(!(e instanceof Error)||e.name!==`ExchangeError`)return;let t=e.code;return typeof t==`string`?t:void 0}function m(e){if(!e||!/^\d+$/.test(e))throw b(`Route type must be a UniverType number`);return Number(e)}function h(e,t){let n=v(t);return{type:e,fileID:n.fileID,outputType:n.outputType,...y(`sourceUnitID`,n.sourceUnitID),...y(`options`,n.options)}}function g(e,t){let n=v(t);return{type:e,format:n.format,...y(`unitID`,n.unitID),...y(`jsonID`,n.jsonID),...y(`options`,n.options)}}function _(t,n){switch(t.status){case`pending`:return{error:a,taskID:t.taskID,status:`pending`};case`failed`:return{error:n(t.error),taskID:t.taskID,status:`failed`};case`done`:if(t.kind===`import`){let{result:n}=t;return{error:a,taskID:t.taskID,status:`done`,import:{outputType:n.outputType,unitID:n.outputType===e.IMPORT_OUTPUT_TYPE.Unit?n.unitID:``,jsonID:n.outputType===e.IMPORT_OUTPUT_TYPE.Json?n.jsonID:``}}}return{error:a,taskID:t.taskID,status:`done`,export:{fileID:t.result.fileID,fileUrl:``}}}}function v(e){if(typeof e!=`object`||!e||Array.isArray(e))throw b(`Request body must be a JSON object`);return e}function y(e,t){return t==null?{}:{[e]:t}}function b(t){return new e.ExchangeServiceError(`INVALID_REQUEST`,t)}var x=class{_service;_routePrefix;_calls=new Set;_disposed=!1;_disposePromise;constructor(e,t={}){if(!e)throw TypeError(`UniverExchangeEndpoint requires a service`);this._service=e,this._routePrefix=C(t.routePrefix??`/universer-api`)}register(e){if(this._disposed)throw S();e.post(`${this._routePrefix}/exchange/:type/import`,e=>this._track(this._handleImport(e))),e.post(`${this._routePrefix}/exchange/:type/export`,e=>this._track(this._handleExport(e))),e.get(`${this._routePrefix}/exchange/task/:taskID`,e=>this._track(this._handleTask(e)))}dispose(){return this._disposePromise?this._disposePromise:(this._disposed=!0,this._disposePromise=Promise.allSettled([...this._calls]).then(()=>void 0),this._disposePromise)}async _handleImport(e){try{let t=this._context(e),n=h(m(e.params.type),await e.readJson()),r=await this._service.createImportTask(n,t);s(e.response,{error:a,taskID:r})}catch(t){s(e.response,{error:o(t),taskID:``})}}async _handleExport(e){try{let t=this._context(e),n=g(m(e.params.type),await e.readJson()),r=await this._service.createExportTask(n,t);s(e.response,{error:a,taskID:r})}catch(t){s(e.response,{error:o(t),taskID:``})}}async _handleTask(e){let t=e.params.taskID??``;try{let n=await this._service.getTask(t,this._context(e));s(e.response,_(n,o))}catch(n){s(e.response,{error:o(n),taskID:t,status:`failed`})}}_context(t){if(this._disposed)throw S();if(!t.userID)throw new e.ExchangeServiceError(`UNAUTHENTICATED`,`HTTP user is not authenticated`);return{userID:t.userID,customData:t.customData}}_track(e){return this._calls.add(e),e.finally(()=>this._calls.delete(e)).catch(()=>void 0),e}};function S(){return new e.ExchangeServiceError(`SERVICE_DISPOSED`,`Exchange Endpoint is disposed`)}function C(e){if(!e.startsWith(`/`)||e===`/`||e.endsWith(`/`)||e.includes(`//`))throw TypeError(`routePrefix must be an absolute path without a trailing slash`);return e}exports.UniverExchangeEndpoint=x;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@univerjs-pro/collaboration-exchange-service"),t=require("@univerjs-pro/collaboration-file-service"),n=require("@univerjs-pro/collaboration-service"),r=require("@univerjs-pro/collaboration-transport-node"),i=require("@univerjs/protocol");var a={code:i.ErrorCode.OK,message:``};function o(e){return{code:f(e),message:e instanceof Error?e.message:String(e)}}function s(e,t){e.writableEnded||e.destroyed||(e.statusCode=200,e.setHeader(`content-type`,`application/json; charset=utf-8`),e.end(JSON.stringify(t)))}var c={INVALID_REQUEST:i.ErrorCode.INVALID_ARGUMENT,UNAUTHENTICATED:i.ErrorCode.UNAUTHENTICATED,FILE_NOT_FOUND:i.ErrorCode.NOT_FOUND,TASK_NOT_FOUND:i.ErrorCode.NOT_FOUND,SERVICE_DISPOSED:i.ErrorCode.INTERNAL_ERROR},l={INVALID_REQUEST:i.ErrorCode.INVALID_ARGUMENT,PAYLOAD_TOO_LARGE:i.ErrorCode.INVALID_ARGUMENT,UNAUTHENTICATED:i.ErrorCode.UNAUTHENTICATED,PERMISSION_DENIED:i.ErrorCode.PERMISSION_DENIED,FILE_NOT_FOUND:i.ErrorCode.NOT_FOUND,UPLOAD_TIMEOUT:i.ErrorCode.INTERNAL_ERROR,STORAGE_FAILURE:i.ErrorCode.INTERNAL_ERROR,SERVICE_DISPOSED:i.ErrorCode.INTERNAL_ERROR},u={UNAUTHENTICATED:i.ErrorCode.UNAUTHENTICATED,INVALID_REQUEST:i.ErrorCode.INVALID_ARGUMENT,UNIT_NOT_FOUND:i.ErrorCode.NOT_FOUND,PERMISSION_DENIED:i.ErrorCode.PERMISSION_DENIED,OT_CONFLICT:i.ErrorCode.APPLY_REJECT,REVISION_MISMATCH:i.ErrorCode.CHANGESET_REVISION_CONFILICT,ADAPTER_FAILURE:i.ErrorCode.INTERNAL_ERROR,INTERNAL_ERROR:i.ErrorCode.INTERNAL_ERROR,LICENSE_INVALID:i.ErrorCode.LICENSE_INVALID,LICENSE_POLICY_INVALID:i.ErrorCode.LICENSE_POLICY_INVALID,LICENSE_VERSION_NOT_ALLOWED:i.ErrorCode.LICENSE_VERSION_NOT_ALLOWED,LICENSE_UNIT_TYPE_REJECTED:i.ErrorCode.LICENSE_UNIT_TYPE_REJECTED,LICENSE_DOMAIN_REJECTED:i.ErrorCode.LICENSE_DOMAIN_REJECTED},d=new Set([`INVALID_ARGUMENT`,`UNSUPPORTED_FORMAT`,`INVALID_FILE`,`INCOMPLETE_SNAPSHOT`]);function f(a){if(a instanceof e.ExchangeServiceError)return c[a.code];if(a instanceof t.FileError)return l[a.code]??i.ErrorCode.INTERNAL_ERROR;if(a instanceof n.CollabError)return u[a.code]??i.ErrorCode.INTERNAL_ERROR;if(a instanceof r.NodeTransportError)return a.code===`TRANSPORT_DISPOSED`?i.ErrorCode.INTERNAL_ERROR:i.ErrorCode.INVALID_ARGUMENT;let o=p(a);if(o!==void 0){if(d.has(o))return i.ErrorCode.INVALID_ARGUMENT;if(o.startsWith(`LICENSE_`)&&o in i.ErrorCode)return i.ErrorCode[o]}return i.ErrorCode.INTERNAL_ERROR}function p(e){if(!(e instanceof Error)||e.name!==`ExchangeError`)return;let t=e.code;return typeof t==`string`?t:void 0}function m(e){if(!e||!/^\d+$/.test(e))throw b(`Route type must be a UniverType number`);return Number(e)}function h(e,t){let n=v(t);return{type:e,fileID:n.fileID,outputType:n.outputType,...y(`sourceUnitID`,n.sourceUnitID),...y(`options`,n.options)}}function g(e,t){let n=v(t);return{type:e,format:n.format,...y(`unitID`,n.unitID),...y(`jsonID`,n.jsonID),...y(`options`,n.options)}}function _(t,n){switch(t.status){case`pending`:return{error:a,taskID:t.taskID,status:`pending`};case`failed`:return{error:n(t.error),taskID:t.taskID,status:`failed`};case`done`:if(t.kind===`import`){let{result:n}=t;return{error:a,taskID:t.taskID,status:`done`,import:{outputType:n.outputType,unitID:n.outputType===e.IMPORT_OUTPUT_TYPE.Unit?n.unitID:``,jsonID:n.outputType===e.IMPORT_OUTPUT_TYPE.Json?n.jsonID:``}}}return{error:a,taskID:t.taskID,status:`done`,export:{fileID:t.result.fileID,fileUrl:``}}}}function v(e){if(typeof e!=`object`||!e||Array.isArray(e))throw b(`Request body must be a JSON object`);return e}function y(e,t){return t==null?{}:{[e]:t}}function b(t){return new e.ExchangeServiceError(`INVALID_REQUEST`,t)}var x=class{_service;_routePrefix;_calls=new Set;_disposed=!1;_disposePromise;constructor(e,t={}){if(!e)throw TypeError(`UniverExchangeEndpoint requires a service`);this._service=e,this._routePrefix=C(t.routePrefix??`/universer-api`)}register(e){if(this._disposed)throw S();e.post(`${this._routePrefix}/exchange/:type/import`,e=>this._track(this._handleImport(e))),e.post(`${this._routePrefix}/exchange/:type/export`,e=>this._track(this._handleExport(e))),e.get(`${this._routePrefix}/exchange/task/:taskID`,e=>this._track(this._handleTask(e)))}dispose(){return this._disposePromise||=(this._disposed=!0,Promise.allSettled([...this._calls]).then(()=>void 0)),this._disposePromise}async _handleImport(e){try{let t=this._context(e),n=h(m(e.params.type),await e.readJson()),r=await this._service.createImportTask(n,t);s(e.response,{error:a,taskID:r})}catch(t){s(e.response,{error:o(t),taskID:``})}}async _handleExport(e){try{let t=this._context(e),n=g(m(e.params.type),await e.readJson()),r=await this._service.createExportTask(n,t);s(e.response,{error:a,taskID:r})}catch(t){s(e.response,{error:o(t),taskID:``})}}async _handleTask(e){let t=e.params.taskID??``;try{let n=await this._service.getTask(t,this._context(e));s(e.response,_(n,o))}catch(n){s(e.response,{error:o(n),taskID:t,status:`failed`})}}_context(t){if(this._disposed)throw S();if(!t.userID)throw new e.ExchangeServiceError(`UNAUTHENTICATED`,`HTTP user is not authenticated`);return{userID:t.userID,customData:t.customData}}_track(e){return this._calls.add(e),e.finally(()=>this._calls.delete(e)).catch(()=>void 0),e}};function S(){return new e.ExchangeServiceError(`SERVICE_DISPOSED`,`Exchange Endpoint is disposed`)}function C(e){if(!e.startsWith(`/`)||e===`/`||e.endsWith(`/`)||e.includes(`//`))throw TypeError(`routePrefix must be an absolute path without a trailing slash`);return e}exports.UniverExchangeEndpoint=x;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { IUniverExchangeService } from "@univerjs-pro/collaboration-exchange-service";
2
2
  import { NodeRouter, NodeTransportEndpoint } from "@univerjs-pro/collaboration-transport-node";
3
3
 
4
- //#region src/endpoint.d.ts
4
+ // src/endpoint.d.ts
5
5
  /** @public */
6
6
  interface UniverExchangeEndpointOptions {
7
7
  /** Defaults to `/universer-api`; absolute, no trailing slash. */
@@ -29,5 +29,4 @@ declare class UniverExchangeEndpoint implements NodeTransportEndpoint {
29
29
  private _context;
30
30
  private _track;
31
31
  }
32
- //#endregion
33
32
  export { UniverExchangeEndpoint, type UniverExchangeEndpointOptions };
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "engines": {
12
12
  "node": ">=22"
13
13
  },
14
- "version": "1.4.0",
14
+ "version": "1.6.0",
15
15
  "main": "./dist/index.cjs",
16
16
  "module": "./dist/index.mjs",
17
17
  "types": "./dist/index.d.ts",
@@ -26,10 +26,10 @@
26
26
  "dist"
27
27
  ],
28
28
  "peerDependencies": {
29
- "@univerjs-pro/collaboration-exchange-service": "1.4.0",
30
- "@univerjs-pro/collaboration-file-service": "1.4.0",
31
- "@univerjs-pro/collaboration-service": "1.4.0",
32
- "@univerjs-pro/collaboration-transport-node": "1.4.0",
33
- "@univerjs/protocol": "1.4.0"
29
+ "@univerjs-pro/collaboration-exchange-service": "1.6.0",
30
+ "@univerjs-pro/collaboration-file-service": "1.6.0",
31
+ "@univerjs-pro/collaboration-service": "1.6.0",
32
+ "@univerjs-pro/collaboration-transport-node": "1.6.0",
33
+ "@univerjs/protocol": "1.6.0"
34
34
  }
35
35
  }