@univerjs/network 0.1.13 → 0.1.14

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/lib/cjs/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var F=Object.defineProperty;var U=(e,n,r)=>n in e?F(e,n,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[n]=r;var p=(e,n,r)=>(U(e,typeof n!="symbol"?n+"":n,r),r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("@univerjs/core"),m=require("rxjs"),u=require("rxjs/operators"),L=require("@wendellhu/redi"),I="application/json";class g{constructor(n){p(this,"_headers",new Map);typeof n=="string"?this._handleHeadersString(n):n instanceof Headers?this._handleHeaders(n):n&&this._handleHeadersConstructorProps(n)}forEach(n){this._headers.forEach((r,t)=>n(t,r))}has(n){return!!this._headers.has(n.toLowerCase())}get(n){const r=n.toLowerCase();return this._headers.has(r)?this._headers.get(r):null}toHeadersInit(){var r,t;const n={};return this._headers.forEach((s,a)=>{n[a]=s.join(",")}),(r=n.accept)!=null||(n.accept="application/json, text/plain, */*"),(t=n["content-type"])!=null||(n["content-type"]="application/json;charset=UTF-8"),n}_setHeader(n,r){const t=n.toLowerCase();this._headers.has(t)?this._headers.get(t).push(r.toString()):this._headers.set(t,[r.toString()])}_handleHeadersString(n){n.split(`
2
- `).forEach(r=>{const[t,s]=r.split(":");t&&s&&this._setHeader(t,s)})}_handleHeadersConstructorProps(n){Object.entries(n).forEach(([r,t])=>this._setHeader(r,t))}_handleHeaders(n){n.forEach((r,t)=>this._setHeader(t,r))}}const q=L.createIdentifier("network.http-implementation");class x{constructor(n){this.params=n}toString(){return this.params?Object.keys(this.params).map(n=>`${n}=${this.params[n]}`).join("&"):""}}let k=0;class _{constructor(n,r,t){p(this,"uid",k++);this.method=n,this.url=r,this.requestParams=t}get headers(){return this.requestParams.headers}get withCredentials(){return this.requestParams.withCredentials}get responseType(){return this.requestParams.responseType}getUrlWithParams(){var r,t;const n=(t=(r=this.requestParams)==null?void 0:r.params)==null?void 0:t.toString();return n?`${this.url}${this.url.includes("?")?"&":"?"}${n}`:this.url}getBody(){var t,s;const n=(t=this.headers.get("Content-Type"))!=null?t:I,r=(s=this.requestParams)==null?void 0:s.body;return n===I&&r&&typeof r=="object"?JSON.stringify(r):r?`${r}`:null}getHeadersInit(){return this.headers.toHeadersInit()}}class v{constructor({body:n,headers:r,status:t,statusText:s}){p(this,"body");p(this,"headers");p(this,"status");p(this,"statusText");this.body=n,this.headers=r,this.status=t,this.statusText=s}}class f{constructor({headers:n,status:r,statusText:t,error:s}){p(this,"headers");p(this,"status");p(this,"statusText");p(this,"error");this.headers=n,this.status=r,this.statusText=t,this.error=s}}class O{constructor(n,r,t){this.headers=n,this.status=r,this.statusText=t}}var M=Object.defineProperty,D=Object.getOwnPropertyDescriptor,j=(e,n,r,t)=>{for(var s=t>1?void 0:t?D(n,r):n,a=e.length-1,i;a>=0;a--)(i=e[a])&&(s=(t?i(n,r,s):i(s))||s);return t&&s&&M(n,r,s),s},B=(e,n)=>(r,t)=>n(r,t,e);exports.HTTPService=class extends y.Disposable{constructor(r){super();p(this,"_interceptors",[]);p(this,"_pipe");this._http=r}registerHTTPInterceptor(r){if(this._interceptors.indexOf(r)!==-1)throw new Error("[HTTPService]: The interceptor has already been registered!");return this._interceptors.push(r),this._interceptors=this._interceptors.sort((t,s)=>{var a,i;return((a=t.priority)!=null?a:0)-((i=s.priority)!=null?i:0)}),this._pipe=null,y.toDisposable(()=>y.remove(this._interceptors,r))}get(r,t){return this._request("GET",r,t)}post(r,t){return this._request("POST",r,t)}put(r,t){return this._request("PUT",r,t)}delete(r,t){return this._request("DELETE",r,t)}patch(r,t){return this._request("PATCH",r,t)}getSSE(r,t,s){var c,l;const a=new g(s==null?void 0:s.headers),i=new x(s==null?void 0:s.params),h=new _(r,t,{headers:a,params:i,withCredentials:(c=s==null?void 0:s.withCredentials)!=null?c:!1,responseType:(l=s==null?void 0:s.responseType)!=null?l:"json",body:["GET","DELETE"].includes(r)||s==null?void 0:s.body});return m.of(h).pipe(u.concatMap(o=>this._runInterceptorsAndImplementation(o)),u.map(o=>{if(o instanceof f)throw o;return o}))}async _request(r,t,s){var o,w;const a=new g(s==null?void 0:s.headers),i=new x(s==null?void 0:s.params),h=new _(r,t,{headers:a,params:i,withCredentials:(o=s==null?void 0:s.withCredentials)!=null?o:!1,responseType:(w=s==null?void 0:s.responseType)!=null?w:"json",body:["GET","DELETE"].includes(r)||s==null?void 0:s.body}),c=m.of(h).pipe(u.concatMap(d=>this._runInterceptorsAndImplementation(d))),l=await m.firstValueFrom(c);if(l instanceof v)return l;throw new Error(`${l.error}`)}_runInterceptorsAndImplementation(r){return this._pipe||(this._pipe=this._interceptors.map(t=>t.interceptor).reduceRight((t,s)=>$(t,s),(t,s)=>s(t))),this._pipe(r,t=>this._http.send(t))}};exports.HTTPService=j([B(0,q)],exports.HTTPService);function $(e,n){return(r,t)=>n(r,s=>e(s,t))}const G=200,W=300;var b=(e=>(e[e.Continue=100]="Continue",e[e.SwitchingProtocols=101]="SwitchingProtocols",e[e.Processing=102]="Processing",e[e.EarlyHints=103]="EarlyHints",e[e.Ok=200]="Ok",e[e.Created=201]="Created",e[e.Accepted=202]="Accepted",e[e.NonAuthoritativeInformation=203]="NonAuthoritativeInformation",e[e.NoContent=204]="NoContent",e[e.ResetContent=205]="ResetContent",e[e.PartialContent=206]="PartialContent",e[e.MultiStatus=207]="MultiStatus",e[e.AlreadyReported=208]="AlreadyReported",e[e.ImUsed=226]="ImUsed",e[e.MultipleChoices=300]="MultipleChoices",e[e.MovedPermanently=301]="MovedPermanently",e[e.Found=302]="Found",e[e.SeeOther=303]="SeeOther",e[e.NotModified=304]="NotModified",e[e.UseProxy=305]="UseProxy",e[e.Unused=306]="Unused",e[e.TemporaryRedirect=307]="TemporaryRedirect",e[e.PermanentRedirect=308]="PermanentRedirect",e[e.BadRequest=400]="BadRequest",e[e.Unauthorized=401]="Unauthorized",e[e.PaymentRequired=402]="PaymentRequired",e[e.Forbidden=403]="Forbidden",e[e.NotFound=404]="NotFound",e[e.MethodNotAllowed=405]="MethodNotAllowed",e[e.NotAcceptable=406]="NotAcceptable",e[e.ProxyAuthenticationRequired=407]="ProxyAuthenticationRequired",e[e.RequestTimeout=408]="RequestTimeout",e[e.Conflict=409]="Conflict",e[e.Gone=410]="Gone",e[e.LengthRequired=411]="LengthRequired",e[e.PreconditionFailed=412]="PreconditionFailed",e[e.PayloadTooLarge=413]="PayloadTooLarge",e[e.UriTooLong=414]="UriTooLong",e[e.UnsupportedMediaType=415]="UnsupportedMediaType",e[e.RangeNotSatisfiable=416]="RangeNotSatisfiable",e[e.ExpectationFailed=417]="ExpectationFailed",e[e.ImATeapot=418]="ImATeapot",e[e.MisdirectedRequest=421]="MisdirectedRequest",e[e.UnprocessableEntity=422]="UnprocessableEntity",e[e.Locked=423]="Locked",e[e.FailedDependency=424]="FailedDependency",e[e.TooEarly=425]="TooEarly",e[e.UpgradeRequired=426]="UpgradeRequired",e[e.PreconditionRequired=428]="PreconditionRequired",e[e.TooManyRequests=429]="TooManyRequests",e[e.RequestHeaderFieldsTooLarge=431]="RequestHeaderFieldsTooLarge",e[e.UnavailableForLegalReasons=451]="UnavailableForLegalReasons",e[e.InternalServerError=500]="InternalServerError",e[e.NotImplemented=501]="NotImplemented",e[e.BadGateway=502]="BadGateway",e[e.ServiceUnavailable=503]="ServiceUnavailable",e[e.GatewayTimeout=504]="GatewayTimeout",e[e.HttpVersionNotSupported=505]="HttpVersionNotSupported",e[e.VariantAlsoNegotiates=506]="VariantAlsoNegotiates",e[e.InsufficientStorage=507]="InsufficientStorage",e[e.LoopDetected=508]="LoopDetected",e[e.NotExtended=510]="NotExtended",e[e.NetworkAuthenticationRequired=511]="NetworkAuthenticationRequired",e))(b||{});class V{send(n){return new m.Observable(r=>{const t=new AbortController;return this._send(n,r,t).then(()=>{},s=>{r.error(new f({error:s}))}),()=>t.abort()})}async _send(n,r,t){var o,w;let s;try{const d=this._parseFetchParamsFromRequest(n);s=await fetch(n.getUrlWithParams(),{signal:t.signal,...d})}catch(d){r.error(new f({error:d,status:(o=d.status)!=null?o:0,statusText:(w=d.statusText)!=null?w:"Unknown Error",headers:d.headers}));return}const a=new g(s.headers),i=s.status,h=s.statusText;let c=null;s.body&&(c=await this._readBody(n,s,r)),i>=b.Ok&&i<b.MultipleChoices?r.next(new v({body:c,headers:a,status:i,statusText:h})):r.error(new f({error:c,status:i,statusText:h,headers:a})),r.complete()}async _readBody(n,r,t){var c;const s=[],a=r.body.getReader();let i=0;for(;;){const{done:l,value:o}=await a.read();if(l)break;s.push(o),i+=o.length}const h=X(s,i);try{const l=(c=r.headers.get("content-type"))!=null?c:"";return J(n,h,l)}catch(l){return t.error(new f({error:l,status:r.status,statusText:r.statusText,headers:new g(r.headers)})),null}}_parseFetchParamsFromRequest(n){return{method:n.method,headers:n.getHeadersInit(),body:n.getBody(),credentials:n.withCredentials?"include":void 0}}}function X(e,n){const r=new Uint8Array(n);let t=0;for(const s of e)r.set(s,t),t+=s.length;return r}const z=/^\)\]\}',?\n/;function J(e,n,r){switch(e.responseType){case"json":const t=new TextDecoder().decode(n).replace(z,"");return t===""?null:JSON.parse(t);case"text":return new TextDecoder().decode(n);case"blob":return new Blob([n],{type:r});case"arraybuffer":return n.buffer;default:throw new Error(`[FetchHTTPImplementation]: unknown response type: ${e.responseType}.`)}}class Y{send(n){return new m.Observable(r=>{const t=new XMLHttpRequest;t.open(n.method,n.getUrlWithParams()),n.withCredentials&&(t.withCredentials=!0),n.headers.forEach((c,l)=>t.setRequestHeader(c,l.join(","))),n.headers.has("Accept")||t.setRequestHeader("Accept","application/json, text/plain, */*"),n.headers.has("Content-Type")||t.setRequestHeader("Content-Type","application/json;charset=UTF-8");const s=()=>{const c=t.statusText||"OK",l=new g(t.getAllResponseHeaders());return new O(l,t.status,c)},a=()=>{const{headers:c,statusText:l,status:o}=s(),{responseType:w}=n;let d=null,E=null;o!==b.NoContent&&(d=typeof t.response>"u"?t.responseText:t.response);let R=o>=G&&o<W;if(w==="json"&&typeof d=="string"){const A=d;try{d=d?JSON.parse(d):null}catch(N){R=!1,d=A,E=N}}R?r.next(new v({body:d,headers:c,status:o,statusText:l})):r.error(new f({error:E,headers:c,status:o,statusText:l}))},i=c=>{const l=new f({error:c,status:t.status||0,statusText:t.statusText||"Unknown Error",headers:s().headers});r.error(l)};t.addEventListener("load",a),t.addEventListener("error",i),t.addEventListener("abort",i),t.addEventListener("timeout",i);const h=n.getBody();return t.send(h),()=>{t.readyState!==t.DONE&&t.abort(),t.removeEventListener("load",a),t.removeEventListener("error",i),t.removeEventListener("abort",i),t.removeEventListener("timeout",i)}})}}const K=L.createIdentifier("univer.socket");class Q extends y.Disposable{createSocket(n){try{const r=new WebSocket(n),t=new y.DisposableCollection;return{URL:n,close:(a,i)=>{r.close(a,i),t.dispose()},send:a=>{r.send(a)},open$:new m.Observable(a=>{const i=h=>a.next(h);r.addEventListener("open",i),t.add(y.toDisposable(()=>r.removeEventListener("open",i)))}).pipe(u.share()),close$:new m.Observable(a=>{const i=h=>a.next(h);r.addEventListener("close",i),t.add(y.toDisposable(()=>r.removeEventListener("close",i)))}).pipe(u.share()),error$:new m.Observable(a=>{const i=h=>a.next(h);r.addEventListener("error",i),t.add(y.toDisposable(()=>r.removeEventListener("error",i)))}).pipe(u.share()),message$:new m.Observable(a=>{const i=h=>a.next(h);r.addEventListener("message",i),t.add(y.toDisposable(()=>r.removeEventListener("message",i)))}).pipe(u.share())}}catch(r){return console.error(r),null}}}const Z=2,P=1e3,H=(e,n)=>n(e).pipe(u.retryWhen(r=>r.pipe(u.concatMap((t,s)=>s>Z?m.throwError(t):m.of(t)),m.delay(P)))),S=(e,n)=>{const r=[],t=new Set,s=()=>{var a;for(;t.size<((a=n==null?void 0:n.maxParallel)!=null?a:1)&&r.length>0;){const i=r.shift();t.add(i),i()}};return(a,i)=>new m.Observable(h=>{const c=()=>i(a).subscribe({next:o=>h.next(o),error:o=>h.next(o),complete:()=>h.complete()}),l=()=>{t.delete(c),y.remove(r,c),s()};return r.push(c),s(),l})};exports.FetchHTTPImplementation=V;exports.HTTPHeaders=g;exports.HTTPRequest=_;exports.HTTPResponse=v;exports.HTTPResponseError=f;exports.HTTPStatusCode=b;exports.IHTTPImplementation=q;exports.ISocketService=K;exports.ThresholdInterceptorFactory=S;exports.WebSocketService=Q;exports.XHRHTTPImplementation=Y;exports.retryInterceptor=H;
1
+ "use strict";var N=Object.defineProperty;var U=(e,n,r)=>n in e?N(e,n,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[n]=r;var p=(e,n,r)=>(U(e,typeof n!="symbol"?n+"":n,r),r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("@univerjs/core"),y=require("rxjs"),f=require("rxjs/operators"),L=require("@wendellhu/redi"),I="application/json";class g{constructor(n){p(this,"_headers",new Map);typeof n=="string"?this._handleHeadersString(n):n instanceof Headers?this._handleHeaders(n):n&&this._handleHeadersConstructorProps(n)}forEach(n){this._headers.forEach((r,t)=>n(t,r))}has(n){return!!this._headers.has(n.toLowerCase())}get(n){const r=n.toLowerCase();return this._headers.has(r)?this._headers.get(r):null}toHeadersInit(){var r,t;const n={};return this._headers.forEach((s,a)=>{n[a]=s.join(",")}),(r=n.accept)!=null||(n.accept="application/json, text/plain, */*"),(t=n["content-type"])!=null||(n["content-type"]="application/json;charset=UTF-8"),n}_setHeader(n,r){const t=n.toLowerCase();this._headers.has(t)?this._headers.get(t).push(r.toString()):this._headers.set(t,[r.toString()])}_handleHeadersString(n){n.split(`
2
+ `).forEach(r=>{const[t,s]=r.split(":");t&&s&&this._setHeader(t,s)})}_handleHeadersConstructorProps(n){Object.entries(n).forEach(([r,t])=>this._setHeader(r,t))}_handleHeaders(n){n.forEach((r,t)=>this._setHeader(t,r))}}const A=L.createIdentifier("network.http-implementation");class x{constructor(n){this.params=n}toString(){return this.params?Object.keys(this.params).map(n=>`${n}=${this.params[n]}`).join("&"):""}}let k=0;class _{constructor(n,r,t){p(this,"uid",k++);this.method=n,this.url=r,this.requestParams=t}get headers(){return this.requestParams.headers}get withCredentials(){return this.requestParams.withCredentials}get responseType(){return this.requestParams.responseType}getUrlWithParams(){var r,t;const n=(t=(r=this.requestParams)==null?void 0:r.params)==null?void 0:t.toString();return n?`${this.url}${this.url.includes("?")?"&":"?"}${n}`:this.url}getBody(){var t,s;const n=(t=this.headers.get("Content-Type"))!=null?t:I,r=(s=this.requestParams)==null?void 0:s.body;return n===I&&r&&typeof r=="object"?JSON.stringify(r):r?`${r}`:null}getHeadersInit(){return this.headers.toHeadersInit()}}class b{constructor({body:n,headers:r,status:t,statusText:s}){p(this,"body");p(this,"headers");p(this,"status");p(this,"statusText");this.body=n,this.headers=r,this.status=t,this.statusText=s}}class m{constructor({headers:n,status:r,statusText:t,error:s}){p(this,"headers");p(this,"status");p(this,"statusText");p(this,"error");this.headers=n,this.status=r,this.statusText=t,this.error=s}}class O{constructor(n,r,t){this.headers=n,this.status=r,this.statusText=t}}var M=Object.defineProperty,D=Object.getOwnPropertyDescriptor,j=(e,n,r,t)=>{for(var s=t>1?void 0:t?D(n,r):n,a=e.length-1,i;a>=0;a--)(i=e[a])&&(s=(t?i(n,r,s):i(s))||s);return t&&s&&M(n,r,s),s},B=(e,n)=>(r,t)=>n(r,t,e);exports.HTTPService=class extends u.Disposable{constructor(r){super();p(this,"_interceptors",[]);p(this,"_pipe");this._http=r}registerHTTPInterceptor(r){if(this._interceptors.indexOf(r)!==-1)throw new Error("[HTTPService]: The interceptor has already been registered!");return this._interceptors.push(r),this._interceptors=this._interceptors.sort((t,s)=>{var a,i;return((a=t.priority)!=null?a:0)-((i=s.priority)!=null?i:0)}),this._pipe=null,u.toDisposable(()=>u.remove(this._interceptors,r))}get(r,t){return this._request("GET",r,t)}post(r,t){return this._request("POST",r,t)}put(r,t){return this._request("PUT",r,t)}delete(r,t){return this._request("DELETE",r,t)}patch(r,t){return this._request("PATCH",r,t)}getSSE(r,t,s){var l,c;const a=new g(s==null?void 0:s.headers),i=new x(s==null?void 0:s.params),o=new _(r,t,{headers:a,params:i,withCredentials:(l=s==null?void 0:s.withCredentials)!=null?l:!1,responseType:(c=s==null?void 0:s.responseType)!=null?c:"json",body:["GET","DELETE"].includes(r)||s==null?void 0:s.body});return y.of(o).pipe(f.concatMap(h=>this._runInterceptorsAndImplementation(h)),f.map(h=>{if(h instanceof m)throw h;return h}))}async _request(r,t,s){var h,w;const a=new g(s==null?void 0:s.headers),i=new x(s==null?void 0:s.params),o=new _(r,t,{headers:a,params:i,withCredentials:(h=s==null?void 0:s.withCredentials)!=null?h:!1,responseType:(w=s==null?void 0:s.responseType)!=null?w:"json",body:["GET","DELETE"].includes(r)||s==null?void 0:s.body}),l=y.of(o).pipe(f.concatMap(d=>this._runInterceptorsAndImplementation(d))),c=await y.firstValueFrom(l);if(c instanceof b)return c;throw new Error(`${c.error}`)}_runInterceptorsAndImplementation(r){return this._pipe||(this._pipe=this._interceptors.map(t=>t.interceptor).reduceRight((t,s)=>$(t,s),(t,s)=>s(t))),this._pipe(r,t=>this._http.send(t))}};exports.HTTPService=j([B(0,A)],exports.HTTPService);function $(e,n){return(r,t)=>n(r,s=>e(s,t))}const G=200,V=300;var v=(e=>(e[e.Continue=100]="Continue",e[e.SwitchingProtocols=101]="SwitchingProtocols",e[e.Processing=102]="Processing",e[e.EarlyHints=103]="EarlyHints",e[e.Ok=200]="Ok",e[e.Created=201]="Created",e[e.Accepted=202]="Accepted",e[e.NonAuthoritativeInformation=203]="NonAuthoritativeInformation",e[e.NoContent=204]="NoContent",e[e.ResetContent=205]="ResetContent",e[e.PartialContent=206]="PartialContent",e[e.MultiStatus=207]="MultiStatus",e[e.AlreadyReported=208]="AlreadyReported",e[e.ImUsed=226]="ImUsed",e[e.MultipleChoices=300]="MultipleChoices",e[e.MovedPermanently=301]="MovedPermanently",e[e.Found=302]="Found",e[e.SeeOther=303]="SeeOther",e[e.NotModified=304]="NotModified",e[e.UseProxy=305]="UseProxy",e[e.Unused=306]="Unused",e[e.TemporaryRedirect=307]="TemporaryRedirect",e[e.PermanentRedirect=308]="PermanentRedirect",e[e.BadRequest=400]="BadRequest",e[e.Unauthorized=401]="Unauthorized",e[e.PaymentRequired=402]="PaymentRequired",e[e.Forbidden=403]="Forbidden",e[e.NotFound=404]="NotFound",e[e.MethodNotAllowed=405]="MethodNotAllowed",e[e.NotAcceptable=406]="NotAcceptable",e[e.ProxyAuthenticationRequired=407]="ProxyAuthenticationRequired",e[e.RequestTimeout=408]="RequestTimeout",e[e.Conflict=409]="Conflict",e[e.Gone=410]="Gone",e[e.LengthRequired=411]="LengthRequired",e[e.PreconditionFailed=412]="PreconditionFailed",e[e.PayloadTooLarge=413]="PayloadTooLarge",e[e.UriTooLong=414]="UriTooLong",e[e.UnsupportedMediaType=415]="UnsupportedMediaType",e[e.RangeNotSatisfiable=416]="RangeNotSatisfiable",e[e.ExpectationFailed=417]="ExpectationFailed",e[e.ImATeapot=418]="ImATeapot",e[e.MisdirectedRequest=421]="MisdirectedRequest",e[e.UnprocessableEntity=422]="UnprocessableEntity",e[e.Locked=423]="Locked",e[e.FailedDependency=424]="FailedDependency",e[e.TooEarly=425]="TooEarly",e[e.UpgradeRequired=426]="UpgradeRequired",e[e.PreconditionRequired=428]="PreconditionRequired",e[e.TooManyRequests=429]="TooManyRequests",e[e.RequestHeaderFieldsTooLarge=431]="RequestHeaderFieldsTooLarge",e[e.UnavailableForLegalReasons=451]="UnavailableForLegalReasons",e[e.InternalServerError=500]="InternalServerError",e[e.NotImplemented=501]="NotImplemented",e[e.BadGateway=502]="BadGateway",e[e.ServiceUnavailable=503]="ServiceUnavailable",e[e.GatewayTimeout=504]="GatewayTimeout",e[e.HttpVersionNotSupported=505]="HttpVersionNotSupported",e[e.VariantAlsoNegotiates=506]="VariantAlsoNegotiates",e[e.InsufficientStorage=507]="InsufficientStorage",e[e.LoopDetected=508]="LoopDetected",e[e.NotExtended=510]="NotExtended",e[e.NetworkAuthenticationRequired=511]="NetworkAuthenticationRequired",e))(v||{});class W{send(n){return new y.Observable(r=>{const t=new AbortController;return this._send(n,r,t).then(()=>{},s=>{r.error(new m({error:s}))}),()=>t.abort()})}async _send(n,r,t){var h,w;let s;try{const d=this._parseFetchParamsFromRequest(n);s=await fetch(n.getUrlWithParams(),{signal:t.signal,...d})}catch(d){r.error(new m({error:d,status:(h=d.status)!=null?h:0,statusText:(w=d.statusText)!=null?w:"Unknown Error",headers:d.headers}));return}const a=new g(s.headers),i=s.status,o=s.statusText;let l=null;s.body&&(l=await this._readBody(n,s,r)),i>=v.Ok&&i<v.MultipleChoices?r.next(new b({body:l,headers:a,status:i,statusText:o})):r.error(new m({error:l,status:i,statusText:o,headers:a})),r.complete()}async _readBody(n,r,t){var l;const s=[],a=r.body.getReader();let i=0;for(;;){const{done:c,value:h}=await a.read();if(c)break;s.push(h),i+=h.length}const o=X(s,i);try{const c=(l=r.headers.get("content-type"))!=null?l:"";return J(n,o,c)}catch(c){return t.error(new m({error:c,status:r.status,statusText:r.statusText,headers:new g(r.headers)})),null}}_parseFetchParamsFromRequest(n){return{method:n.method,headers:n.getHeadersInit(),body:n.getBody(),credentials:n.withCredentials?"include":void 0}}}function X(e,n){const r=new Uint8Array(n);let t=0;for(const s of e)r.set(s,t),t+=s.length;return r}const z=/^\)\]\}',?\n/;function J(e,n,r){switch(e.responseType){case"json":const t=new TextDecoder().decode(n).replace(z,"");return t===""?null:JSON.parse(t);case"text":return new TextDecoder().decode(n);case"blob":return new Blob([n],{type:r});case"arraybuffer":return n.buffer;default:throw new Error(`[FetchHTTPImplementation]: unknown response type: ${e.responseType}.`)}}class Y{send(n){return new y.Observable(r=>{const t=new XMLHttpRequest;t.open(n.method,n.getUrlWithParams()),n.withCredentials&&(t.withCredentials=!0),n.headers.forEach((l,c)=>t.setRequestHeader(l,c.join(","))),n.headers.has("Accept")||t.setRequestHeader("Accept","application/json, text/plain, */*"),n.headers.has("Content-Type")||t.setRequestHeader("Content-Type","application/json;charset=UTF-8");const s=()=>{const l=t.statusText||"OK",c=new g(t.getAllResponseHeaders());return new O(c,t.status,l)},a=()=>{const{headers:l,statusText:c,status:h}=s(),{responseType:w}=n;let d=null,E=null;h!==v.NoContent&&(d=typeof t.response>"u"?t.responseText:t.response);let R=h>=G&&h<V;if(w==="json"&&typeof d=="string"){const q=d;try{d=d?JSON.parse(d):null}catch(F){R=!1,d=q,E=F}}R?r.next(new b({body:d,headers:l,status:h,statusText:c})):r.error(new m({error:E,headers:l,status:h,statusText:c}))},i=l=>{const c=new m({error:l,status:t.status||0,statusText:t.statusText||"Unknown Error",headers:s().headers});r.error(c)};t.addEventListener("load",a),t.addEventListener("error",i),t.addEventListener("abort",i),t.addEventListener("timeout",i);const o=n.getBody();return t.send(o),()=>{t.readyState!==t.DONE&&t.abort(),t.removeEventListener("load",a),t.removeEventListener("error",i),t.removeEventListener("abort",i),t.removeEventListener("timeout",i)}})}}const K=L.createIdentifier("univer.socket");class Q extends u.Disposable{createSocket(n){try{const r=new WebSocket(n),t=new u.DisposableCollection;return{URL:n,close:(a,i)=>{r.close(a,i),t.dispose()},send:a=>{r.send(a)},open$:new y.Observable(a=>{const i=o=>a.next(o);r.addEventListener("open",i),t.add(u.toDisposable(()=>r.removeEventListener("open",i)))}).pipe(f.share()),close$:new y.Observable(a=>{const i=o=>a.next(o);r.addEventListener("close",i),t.add(u.toDisposable(()=>r.removeEventListener("close",i)))}).pipe(f.share()),error$:new y.Observable(a=>{const i=o=>a.next(o);r.addEventListener("error",i),t.add(u.toDisposable(()=>r.removeEventListener("error",i)))}).pipe(f.share()),message$:new y.Observable(a=>{const i=o=>a.next(o);r.addEventListener("message",i),t.add(u.toDisposable(()=>r.removeEventListener("message",i)))}).pipe(f.share())}}catch(r){return console.error(r),null}}}const Z=3,P=1e3,H=(e,n)=>{var s,a;const r=(s=n==null?void 0:n.maxRetryAttempts)!=null?s:Z,t=(a=n==null?void 0:n.delayInterval)!=null?a:P;return(i,o)=>o(i).pipe(f.retry({delay:t,count:r}))},S=e=>{const n=[],r=new Set,t=()=>{var s;for(;r.size<((s=e==null?void 0:e.maxParallel)!=null?s:1)&&n.length>0;){const a=n.shift();r.add(a),a()}};return(s,a)=>new y.Observable(i=>{const o=()=>a(s).subscribe({next:c=>i.next(c),error:c=>i.next(c),complete:()=>i.complete()}),l=()=>{r.delete(o),u.remove(n,o),t()};return n.push(o),t(),l})},C=e=>{const{errorStatusCodes:n,onAuthError:r}=e;return(s,a)=>a(s).pipe(y.catchError(i=>(i instanceof m&&n.some(o=>o===i.status)&&r(),y.throwError(()=>i))))};exports.AuthInterceptorFactory=C;exports.FetchHTTPImplementation=W;exports.HTTPHeaders=g;exports.HTTPRequest=_;exports.HTTPResponse=b;exports.HTTPResponseError=m;exports.HTTPStatusCode=v;exports.IHTTPImplementation=A;exports.ISocketService=K;exports.RetryInterceptorFactory=H;exports.ThresholdInterceptorFactory=S;exports.WebSocketService=Q;exports.XHRHTTPImplementation=Y;
package/lib/es/index.js CHANGED
@@ -1,65 +1,65 @@
1
1
  var O = Object.defineProperty;
2
- var j = (e, t, n) => t in e ? O(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
- var p = (e, t, n) => (j(e, typeof t != "symbol" ? t + "" : t, n), n);
4
- import { Disposable as N, toDisposable as w, remove as U, DisposableCollection as D } from "@univerjs/core";
5
- import { of as v, firstValueFrom as B, Observable as m, throwError as $, delay as G } from "rxjs";
6
- import { concatMap as R, map as V, share as g, retryWhen as W } from "rxjs/operators";
7
- import { createIdentifier as F } from "@wendellhu/redi";
8
- const L = "application/json";
9
- class u {
10
- constructor(t) {
2
+ var D = (e, r, n) => r in e ? O(e, r, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[r] = n;
3
+ var p = (e, r, n) => (D(e, typeof r != "symbol" ? r + "" : r, n), n);
4
+ import { Disposable as F, toDisposable as f, remove as N, DisposableCollection as j } from "@univerjs/core";
5
+ import { of as x, firstValueFrom as B, Observable as m, catchError as $, throwError as G } from "rxjs";
6
+ import { concatMap as b, map as V, share as g, retry as W } from "rxjs/operators";
7
+ import { createIdentifier as U } from "@wendellhu/redi";
8
+ const I = "application/json";
9
+ class w {
10
+ constructor(r) {
11
11
  p(this, "_headers", /* @__PURE__ */ new Map());
12
- typeof t == "string" ? this._handleHeadersString(t) : t instanceof Headers ? this._handleHeaders(t) : t && this._handleHeadersConstructorProps(t);
12
+ typeof r == "string" ? this._handleHeadersString(r) : r instanceof Headers ? this._handleHeaders(r) : r && this._handleHeadersConstructorProps(r);
13
13
  }
14
- forEach(t) {
15
- this._headers.forEach((n, r) => t(r, n));
14
+ forEach(r) {
15
+ this._headers.forEach((n, t) => r(t, n));
16
16
  }
17
- has(t) {
18
- return !!this._headers.has(t.toLowerCase());
17
+ has(r) {
18
+ return !!this._headers.has(r.toLowerCase());
19
19
  }
20
- get(t) {
21
- const n = t.toLowerCase();
20
+ get(r) {
21
+ const n = r.toLowerCase();
22
22
  return this._headers.has(n) ? this._headers.get(n) : null;
23
23
  }
24
24
  toHeadersInit() {
25
- var n, r;
26
- const t = {};
25
+ var n, t;
26
+ const r = {};
27
27
  return this._headers.forEach((s, a) => {
28
- t[a] = s.join(",");
29
- }), (n = t.accept) != null || (t.accept = "application/json, text/plain, */*"), (r = t["content-type"]) != null || (t["content-type"] = "application/json;charset=UTF-8"), t;
28
+ r[a] = s.join(",");
29
+ }), (n = r.accept) != null || (r.accept = "application/json, text/plain, */*"), (t = r["content-type"]) != null || (r["content-type"] = "application/json;charset=UTF-8"), r;
30
30
  }
31
- _setHeader(t, n) {
32
- const r = t.toLowerCase();
33
- this._headers.has(r) ? this._headers.get(r).push(n.toString()) : this._headers.set(r, [n.toString()]);
31
+ _setHeader(r, n) {
32
+ const t = r.toLowerCase();
33
+ this._headers.has(t) ? this._headers.get(t).push(n.toString()) : this._headers.set(t, [n.toString()]);
34
34
  }
35
- _handleHeadersString(t) {
36
- t.split(`
35
+ _handleHeadersString(r) {
36
+ r.split(`
37
37
  `).forEach((n) => {
38
- const [r, s] = n.split(":");
39
- r && s && this._setHeader(r, s);
38
+ const [t, s] = n.split(":");
39
+ t && s && this._setHeader(t, s);
40
40
  });
41
41
  }
42
- _handleHeadersConstructorProps(t) {
43
- Object.entries(t).forEach(([n, r]) => this._setHeader(n, r));
42
+ _handleHeadersConstructorProps(r) {
43
+ Object.entries(r).forEach(([n, t]) => this._setHeader(n, t));
44
44
  }
45
- _handleHeaders(t) {
46
- t.forEach((n, r) => this._setHeader(r, n));
45
+ _handleHeaders(r) {
46
+ r.forEach((n, t) => this._setHeader(t, n));
47
47
  }
48
48
  }
49
- const X = F("network.http-implementation");
50
- class I {
51
- constructor(t) {
52
- this.params = t;
49
+ const X = U("network.http-implementation");
50
+ class L {
51
+ constructor(r) {
52
+ this.params = r;
53
53
  }
54
54
  toString() {
55
- return this.params ? Object.keys(this.params).map((t) => `${t}=${this.params[t]}`).join("&") : "";
55
+ return this.params ? Object.keys(this.params).map((r) => `${r}=${this.params[r]}`).join("&") : "";
56
56
  }
57
57
  }
58
58
  let z = 0;
59
59
  class A {
60
- constructor(t, n, r) {
60
+ constructor(r, n, t) {
61
61
  p(this, "uid", z++);
62
- this.method = t, this.url = n, this.requestParams = r;
62
+ this.method = r, this.url = n, this.requestParams = t;
63
63
  }
64
64
  get headers() {
65
65
  return this.requestParams.headers;
@@ -71,64 +71,64 @@ class A {
71
71
  return this.requestParams.responseType;
72
72
  }
73
73
  getUrlWithParams() {
74
- var n, r;
75
- const t = (r = (n = this.requestParams) == null ? void 0 : n.params) == null ? void 0 : r.toString();
76
- return t ? `${this.url}${this.url.includes("?") ? "&" : "?"}${t}` : this.url;
74
+ var n, t;
75
+ const r = (t = (n = this.requestParams) == null ? void 0 : n.params) == null ? void 0 : t.toString();
76
+ return r ? `${this.url}${this.url.includes("?") ? "&" : "?"}${r}` : this.url;
77
77
  }
78
78
  getBody() {
79
- var r, s;
80
- const t = (r = this.headers.get("Content-Type")) != null ? r : L, n = (s = this.requestParams) == null ? void 0 : s.body;
81
- return t === L && n && typeof n == "object" ? JSON.stringify(n) : n ? `${n}` : null;
79
+ var t, s;
80
+ const r = (t = this.headers.get("Content-Type")) != null ? t : I, n = (s = this.requestParams) == null ? void 0 : s.body;
81
+ return r === I && n && typeof n == "object" ? JSON.stringify(n) : n ? `${n}` : null;
82
82
  }
83
83
  getHeadersInit() {
84
84
  return this.headers.toHeadersInit();
85
85
  }
86
86
  }
87
- class b {
87
+ class R {
88
88
  constructor({
89
- body: t,
89
+ body: r,
90
90
  headers: n,
91
- status: r,
91
+ status: t,
92
92
  statusText: s
93
93
  }) {
94
94
  p(this, "body");
95
95
  p(this, "headers");
96
96
  p(this, "status");
97
97
  p(this, "statusText");
98
- this.body = t, this.headers = n, this.status = r, this.statusText = s;
98
+ this.body = r, this.headers = n, this.status = t, this.statusText = s;
99
99
  }
100
100
  }
101
101
  class y {
102
102
  constructor({
103
- headers: t,
103
+ headers: r,
104
104
  status: n,
105
- statusText: r,
105
+ statusText: t,
106
106
  error: s
107
107
  }) {
108
108
  p(this, "headers");
109
109
  p(this, "status");
110
110
  p(this, "statusText");
111
111
  p(this, "error");
112
- this.headers = t, this.status = n, this.statusText = r, this.error = s;
112
+ this.headers = r, this.status = n, this.statusText = t, this.error = s;
113
113
  }
114
114
  }
115
115
  class J {
116
- constructor(t, n, r) {
117
- this.headers = t, this.status = n, this.statusText = r;
116
+ constructor(r, n, t) {
117
+ this.headers = r, this.status = n, this.statusText = t;
118
118
  }
119
119
  }
120
- var Y = Object.defineProperty, K = Object.getOwnPropertyDescriptor, Q = (e, t, n, r) => {
121
- for (var s = r > 1 ? void 0 : r ? K(t, n) : t, a = e.length - 1, i; a >= 0; a--)
122
- (i = e[a]) && (s = (r ? i(t, n, s) : i(s)) || s);
123
- return r && s && Y(t, n, s), s;
124
- }, Z = (e, t) => (n, r) => t(n, r, e);
125
- let q = class extends N {
126
- constructor(t) {
120
+ var Y = Object.defineProperty, K = Object.getOwnPropertyDescriptor, Q = (e, r, n, t) => {
121
+ for (var s = t > 1 ? void 0 : t ? K(r, n) : r, a = e.length - 1, i; a >= 0; a--)
122
+ (i = e[a]) && (s = (t ? i(r, n, s) : i(s)) || s);
123
+ return t && s && Y(r, n, s), s;
124
+ }, Z = (e, r) => (n, t) => r(n, t, e);
125
+ let q = class extends F {
126
+ constructor(r) {
127
127
  super();
128
128
  p(this, "_interceptors", []);
129
129
  // eslint-disable-next-line ts/no-explicit-any
130
130
  p(this, "_pipe");
131
- this._http = t;
131
+ this._http = r;
132
132
  }
133
133
  /**
134
134
  * Register an HTTP interceptor.
@@ -136,41 +136,41 @@ let q = class extends N {
136
136
  * @param interceptor the http interceptor
137
137
  * @returns a disposable handler to remove the interceptor
138
138
  */
139
- registerHTTPInterceptor(t) {
140
- if (this._interceptors.indexOf(t) !== -1)
139
+ registerHTTPInterceptor(r) {
140
+ if (this._interceptors.indexOf(r) !== -1)
141
141
  throw new Error("[HTTPService]: The interceptor has already been registered!");
142
- return this._interceptors.push(t), this._interceptors = this._interceptors.sort((n, r) => {
142
+ return this._interceptors.push(r), this._interceptors = this._interceptors.sort((n, t) => {
143
143
  var s, a;
144
- return ((s = n.priority) != null ? s : 0) - ((a = r.priority) != null ? a : 0);
145
- }), this._pipe = null, w(() => U(this._interceptors, t));
144
+ return ((s = n.priority) != null ? s : 0) - ((a = t.priority) != null ? a : 0);
145
+ }), this._pipe = null, f(() => N(this._interceptors, r));
146
146
  }
147
- get(t, n) {
148
- return this._request("GET", t, n);
147
+ get(r, n) {
148
+ return this._request("GET", r, n);
149
149
  }
150
- post(t, n) {
151
- return this._request("POST", t, n);
150
+ post(r, n) {
151
+ return this._request("POST", r, n);
152
152
  }
153
- put(t, n) {
154
- return this._request("PUT", t, n);
153
+ put(r, n) {
154
+ return this._request("PUT", r, n);
155
155
  }
156
- delete(t, n) {
157
- return this._request("DELETE", t, n);
156
+ delete(r, n) {
157
+ return this._request("DELETE", r, n);
158
158
  }
159
- patch(t, n) {
160
- return this._request("PATCH", t, n);
159
+ patch(r, n) {
160
+ return this._request("PATCH", r, n);
161
161
  }
162
- getSSE(t, n, r) {
163
- var l, c;
164
- const s = new u(r == null ? void 0 : r.headers), a = new I(r == null ? void 0 : r.params), i = new A(t, n, {
162
+ getSSE(r, n, t) {
163
+ var c, l;
164
+ const s = new w(t == null ? void 0 : t.headers), a = new L(t == null ? void 0 : t.params), i = new A(r, n, {
165
165
  headers: s,
166
166
  params: a,
167
- withCredentials: (l = r == null ? void 0 : r.withCredentials) != null ? l : !1,
167
+ withCredentials: (c = t == null ? void 0 : t.withCredentials) != null ? c : !1,
168
168
  // default value for withCredentials is false by MDN
169
- responseType: (c = r == null ? void 0 : r.responseType) != null ? c : "json",
170
- body: ["GET", "DELETE"].includes(t) || r == null ? void 0 : r.body
169
+ responseType: (l = t == null ? void 0 : t.responseType) != null ? l : "json",
170
+ body: ["GET", "DELETE"].includes(r) || t == null ? void 0 : t.body
171
171
  });
172
- return v(i).pipe(
173
- R((o) => this._runInterceptorsAndImplementation(o)),
172
+ return x(i).pipe(
173
+ b((o) => this._runInterceptorsAndImplementation(o)),
174
174
  V((o) => {
175
175
  if (o instanceof y)
176
176
  throw o;
@@ -179,29 +179,29 @@ let q = class extends N {
179
179
  );
180
180
  }
181
181
  /** The HTTP request implementations */
182
- async _request(t, n, r) {
182
+ async _request(r, n, t) {
183
183
  var o, h;
184
- const s = new u(r == null ? void 0 : r.headers), a = new I(r == null ? void 0 : r.params), i = new A(t, n, {
184
+ const s = new w(t == null ? void 0 : t.headers), a = new L(t == null ? void 0 : t.params), i = new A(r, n, {
185
185
  headers: s,
186
186
  params: a,
187
- withCredentials: (o = r == null ? void 0 : r.withCredentials) != null ? o : !1,
187
+ withCredentials: (o = t == null ? void 0 : t.withCredentials) != null ? o : !1,
188
188
  // default value for withCredentials is false by MDN
189
- responseType: (h = r == null ? void 0 : r.responseType) != null ? h : "json",
190
- body: ["GET", "DELETE"].includes(t) || r == null ? void 0 : r.body
191
- }), l = v(i).pipe(
192
- R((f) => this._runInterceptorsAndImplementation(f))
193
- ), c = await B(l);
194
- if (c instanceof b)
195
- return c;
196
- throw new Error(`${c.error}`);
189
+ responseType: (h = t == null ? void 0 : t.responseType) != null ? h : "json",
190
+ body: ["GET", "DELETE"].includes(r) || t == null ? void 0 : t.body
191
+ }), c = x(i).pipe(
192
+ b((u) => this._runInterceptorsAndImplementation(u))
193
+ ), l = await B(c);
194
+ if (l instanceof R)
195
+ return l;
196
+ throw new Error(`${l.error}`);
197
197
  }
198
198
  // eslint-disable-next-line ts/no-explicit-any
199
- _runInterceptorsAndImplementation(t) {
199
+ _runInterceptorsAndImplementation(r) {
200
200
  return this._pipe || (this._pipe = this._interceptors.map((n) => n.interceptor).reduceRight(
201
- (n, r) => P(n, r),
202
- (n, r) => r(n)
201
+ (n, t) => P(n, t),
202
+ (n, t) => t(n)
203
203
  )), this._pipe(
204
- t,
204
+ r,
205
205
  (n) => this._http.send(n)
206
206
  /* final handler */
207
207
  );
@@ -210,57 +210,57 @@ let q = class extends N {
210
210
  q = Q([
211
211
  Z(0, X)
212
212
  ], q);
213
- function P(e, t) {
214
- return (n, r) => t(n, (s) => e(s, r));
213
+ function P(e, r) {
214
+ return (n, t) => r(n, (s) => e(s, t));
215
215
  }
216
216
  const H = 200, S = 300;
217
217
  var E = /* @__PURE__ */ ((e) => (e[e.Continue = 100] = "Continue", e[e.SwitchingProtocols = 101] = "SwitchingProtocols", e[e.Processing = 102] = "Processing", e[e.EarlyHints = 103] = "EarlyHints", e[e.Ok = 200] = "Ok", e[e.Created = 201] = "Created", e[e.Accepted = 202] = "Accepted", e[e.NonAuthoritativeInformation = 203] = "NonAuthoritativeInformation", e[e.NoContent = 204] = "NoContent", e[e.ResetContent = 205] = "ResetContent", e[e.PartialContent = 206] = "PartialContent", e[e.MultiStatus = 207] = "MultiStatus", e[e.AlreadyReported = 208] = "AlreadyReported", e[e.ImUsed = 226] = "ImUsed", e[e.MultipleChoices = 300] = "MultipleChoices", e[e.MovedPermanently = 301] = "MovedPermanently", e[e.Found = 302] = "Found", e[e.SeeOther = 303] = "SeeOther", e[e.NotModified = 304] = "NotModified", e[e.UseProxy = 305] = "UseProxy", e[e.Unused = 306] = "Unused", e[e.TemporaryRedirect = 307] = "TemporaryRedirect", e[e.PermanentRedirect = 308] = "PermanentRedirect", e[e.BadRequest = 400] = "BadRequest", e[e.Unauthorized = 401] = "Unauthorized", e[e.PaymentRequired = 402] = "PaymentRequired", e[e.Forbidden = 403] = "Forbidden", e[e.NotFound = 404] = "NotFound", e[e.MethodNotAllowed = 405] = "MethodNotAllowed", e[e.NotAcceptable = 406] = "NotAcceptable", e[e.ProxyAuthenticationRequired = 407] = "ProxyAuthenticationRequired", e[e.RequestTimeout = 408] = "RequestTimeout", e[e.Conflict = 409] = "Conflict", e[e.Gone = 410] = "Gone", e[e.LengthRequired = 411] = "LengthRequired", e[e.PreconditionFailed = 412] = "PreconditionFailed", e[e.PayloadTooLarge = 413] = "PayloadTooLarge", e[e.UriTooLong = 414] = "UriTooLong", e[e.UnsupportedMediaType = 415] = "UnsupportedMediaType", e[e.RangeNotSatisfiable = 416] = "RangeNotSatisfiable", e[e.ExpectationFailed = 417] = "ExpectationFailed", e[e.ImATeapot = 418] = "ImATeapot", e[e.MisdirectedRequest = 421] = "MisdirectedRequest", e[e.UnprocessableEntity = 422] = "UnprocessableEntity", e[e.Locked = 423] = "Locked", e[e.FailedDependency = 424] = "FailedDependency", e[e.TooEarly = 425] = "TooEarly", e[e.UpgradeRequired = 426] = "UpgradeRequired", e[e.PreconditionRequired = 428] = "PreconditionRequired", e[e.TooManyRequests = 429] = "TooManyRequests", e[e.RequestHeaderFieldsTooLarge = 431] = "RequestHeaderFieldsTooLarge", e[e.UnavailableForLegalReasons = 451] = "UnavailableForLegalReasons", e[e.InternalServerError = 500] = "InternalServerError", e[e.NotImplemented = 501] = "NotImplemented", e[e.BadGateway = 502] = "BadGateway", e[e.ServiceUnavailable = 503] = "ServiceUnavailable", e[e.GatewayTimeout = 504] = "GatewayTimeout", e[e.HttpVersionNotSupported = 505] = "HttpVersionNotSupported", e[e.VariantAlsoNegotiates = 506] = "VariantAlsoNegotiates", e[e.InsufficientStorage = 507] = "InsufficientStorage", e[e.LoopDetected = 508] = "LoopDetected", e[e.NotExtended = 510] = "NotExtended", e[e.NetworkAuthenticationRequired = 511] = "NetworkAuthenticationRequired", e))(E || {});
218
- class oe {
219
- send(t) {
218
+ class ce {
219
+ send(r) {
220
220
  return new m((n) => {
221
- const r = new AbortController();
222
- return this._send(t, n, r).then(() => {
221
+ const t = new AbortController();
222
+ return this._send(r, n, t).then(() => {
223
223
  }, (s) => {
224
224
  n.error(new y({
225
225
  error: s
226
226
  }));
227
- }), () => r.abort();
227
+ }), () => t.abort();
228
228
  });
229
229
  }
230
- async _send(t, n, r) {
231
- var h, f;
230
+ async _send(r, n, t) {
231
+ var h, u;
232
232
  let s;
233
233
  try {
234
- const d = this._parseFetchParamsFromRequest(t);
235
- s = await fetch(t.getUrlWithParams(), {
236
- signal: r.signal,
234
+ const d = this._parseFetchParamsFromRequest(r);
235
+ s = await fetch(r.getUrlWithParams(), {
236
+ signal: t.signal,
237
237
  ...d
238
238
  });
239
239
  } catch (d) {
240
240
  n.error(new y({
241
241
  error: d,
242
242
  status: (h = d.status) != null ? h : 0,
243
- statusText: (f = d.statusText) != null ? f : "Unknown Error",
243
+ statusText: (u = d.statusText) != null ? u : "Unknown Error",
244
244
  headers: d.headers
245
245
  }));
246
246
  return;
247
247
  }
248
- const a = new u(s.headers), i = s.status, l = s.statusText;
249
- let c = null;
250
- s.body && (c = await this._readBody(t, s, n)), i >= E.Ok && i < E.MultipleChoices ? n.next(new b({
251
- body: c,
248
+ const a = new w(s.headers), i = s.status, c = s.statusText;
249
+ let l = null;
250
+ s.body && (l = await this._readBody(r, s, n)), i >= E.Ok && i < E.MultipleChoices ? n.next(new R({
251
+ body: l,
252
252
  headers: a,
253
253
  status: i,
254
- statusText: l
254
+ statusText: c
255
255
  })) : n.error(new y({
256
- error: c,
256
+ error: l,
257
257
  status: i,
258
- statusText: l,
258
+ statusText: c,
259
259
  headers: a
260
260
  })), n.complete();
261
261
  }
262
- async _readBody(t, n, r) {
263
- var c;
262
+ async _readBody(r, n, t) {
263
+ var l;
264
264
  const s = [], a = n.body.getReader();
265
265
  let i = 0;
266
266
  for (; ; ) {
@@ -269,132 +269,132 @@ class oe {
269
269
  break;
270
270
  s.push(h), i += h.length;
271
271
  }
272
- const l = C(s, i);
272
+ const c = C(s, i);
273
273
  try {
274
- const o = (c = n.headers.get("content-type")) != null ? c : "";
275
- return ee(t, l, o);
274
+ const o = (l = n.headers.get("content-type")) != null ? l : "";
275
+ return ee(r, c, o);
276
276
  } catch (o) {
277
- return r.error(new y({
277
+ return t.error(new y({
278
278
  error: o,
279
279
  status: n.status,
280
280
  statusText: n.statusText,
281
- headers: new u(n.headers)
281
+ headers: new w(n.headers)
282
282
  })), null;
283
283
  }
284
284
  }
285
- _parseFetchParamsFromRequest(t) {
285
+ _parseFetchParamsFromRequest(r) {
286
286
  return {
287
- method: t.method,
288
- headers: t.getHeadersInit(),
289
- body: t.getBody(),
290
- credentials: t.withCredentials ? "include" : void 0
287
+ method: r.method,
288
+ headers: r.getHeadersInit(),
289
+ body: r.getBody(),
290
+ credentials: r.withCredentials ? "include" : void 0
291
291
  };
292
292
  }
293
293
  }
294
- function C(e, t) {
295
- const n = new Uint8Array(t);
296
- let r = 0;
294
+ function C(e, r) {
295
+ const n = new Uint8Array(r);
296
+ let t = 0;
297
297
  for (const s of e)
298
- n.set(s, r), r += s.length;
298
+ n.set(s, t), t += s.length;
299
299
  return n;
300
300
  }
301
301
  const T = /^\)\]\}',?\n/;
302
- function ee(e, t, n) {
302
+ function ee(e, r, n) {
303
303
  switch (e.responseType) {
304
304
  case "json":
305
- const r = new TextDecoder().decode(t).replace(T, "");
306
- return r === "" ? null : JSON.parse(r);
305
+ const t = new TextDecoder().decode(r).replace(T, "");
306
+ return t === "" ? null : JSON.parse(t);
307
307
  case "text":
308
- return new TextDecoder().decode(t);
308
+ return new TextDecoder().decode(r);
309
309
  case "blob":
310
- return new Blob([t], { type: n });
310
+ return new Blob([r], { type: n });
311
311
  case "arraybuffer":
312
- return t.buffer;
312
+ return r.buffer;
313
313
  default:
314
314
  throw new Error(`[FetchHTTPImplementation]: unknown response type: ${e.responseType}.`);
315
315
  }
316
316
  }
317
317
  class le {
318
- send(t) {
318
+ send(r) {
319
319
  return new m((n) => {
320
- const r = new XMLHttpRequest();
321
- r.open(t.method, t.getUrlWithParams()), t.withCredentials && (r.withCredentials = !0), t.headers.forEach((c, o) => r.setRequestHeader(c, o.join(","))), t.headers.has("Accept") || r.setRequestHeader("Accept", "application/json, text/plain, */*"), t.headers.has("Content-Type") || r.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
320
+ const t = new XMLHttpRequest();
321
+ t.open(r.method, r.getUrlWithParams()), r.withCredentials && (t.withCredentials = !0), r.headers.forEach((l, o) => t.setRequestHeader(l, o.join(","))), r.headers.has("Accept") || t.setRequestHeader("Accept", "application/json, text/plain, */*"), r.headers.has("Content-Type") || t.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
322
322
  const s = () => {
323
- const c = r.statusText || "OK", o = new u(r.getAllResponseHeaders());
324
- return new J(o, r.status, c);
323
+ const l = t.statusText || "OK", o = new w(t.getAllResponseHeaders());
324
+ return new J(o, t.status, l);
325
325
  }, a = () => {
326
- const { headers: c, statusText: o, status: h } = s(), { responseType: f } = t;
326
+ const { headers: l, statusText: o, status: h } = s(), { responseType: u } = r;
327
327
  let d = null, _ = null;
328
- h !== E.NoContent && (d = typeof r.response > "u" ? r.responseText : r.response);
329
- let x = h >= H && h < S;
330
- if (f === "json" && typeof d == "string") {
328
+ h !== E.NoContent && (d = typeof t.response > "u" ? t.responseText : t.response);
329
+ let v = h >= H && h < S;
330
+ if (u === "json" && typeof d == "string") {
331
331
  const k = d;
332
332
  try {
333
333
  d = d ? JSON.parse(d) : null;
334
334
  } catch (M) {
335
- x = !1, d = k, _ = M;
335
+ v = !1, d = k, _ = M;
336
336
  }
337
337
  }
338
- x ? n.next(
339
- new b({
338
+ v ? n.next(
339
+ new R({
340
340
  body: d,
341
- headers: c,
341
+ headers: l,
342
342
  status: h,
343
343
  statusText: o
344
344
  })
345
345
  ) : n.error(
346
346
  new y({
347
347
  error: _,
348
- headers: c,
348
+ headers: l,
349
349
  status: h,
350
350
  statusText: o
351
351
  })
352
352
  );
353
- }, i = (c) => {
353
+ }, i = (l) => {
354
354
  const o = new y({
355
- error: c,
356
- status: r.status || 0,
357
- statusText: r.statusText || "Unknown Error",
355
+ error: l,
356
+ status: t.status || 0,
357
+ statusText: t.statusText || "Unknown Error",
358
358
  headers: s().headers
359
359
  });
360
360
  n.error(o);
361
361
  };
362
- r.addEventListener("load", a), r.addEventListener("error", i), r.addEventListener("abort", i), r.addEventListener("timeout", i);
363
- const l = t.getBody();
364
- return r.send(l), () => {
365
- r.readyState !== r.DONE && r.abort(), r.removeEventListener("load", a), r.removeEventListener("error", i), r.removeEventListener("abort", i), r.removeEventListener("timeout", i);
362
+ t.addEventListener("load", a), t.addEventListener("error", i), t.addEventListener("abort", i), t.addEventListener("timeout", i);
363
+ const c = r.getBody();
364
+ return t.send(c), () => {
365
+ t.readyState !== t.DONE && t.abort(), t.removeEventListener("load", a), t.removeEventListener("error", i), t.removeEventListener("abort", i), t.removeEventListener("timeout", i);
366
366
  };
367
367
  });
368
368
  }
369
369
  }
370
- const he = F("univer.socket");
371
- class de extends N {
372
- createSocket(t) {
370
+ const he = U("univer.socket");
371
+ class de extends F {
372
+ createSocket(r) {
373
373
  try {
374
- const n = new WebSocket(t), r = new D();
374
+ const n = new WebSocket(r), t = new j();
375
375
  return {
376
- URL: t,
376
+ URL: r,
377
377
  close: (a, i) => {
378
- n.close(a, i), r.dispose();
378
+ n.close(a, i), t.dispose();
379
379
  },
380
380
  send: (a) => {
381
381
  n.send(a);
382
382
  },
383
383
  open$: new m((a) => {
384
- const i = (l) => a.next(l);
385
- n.addEventListener("open", i), r.add(w(() => n.removeEventListener("open", i)));
384
+ const i = (c) => a.next(c);
385
+ n.addEventListener("open", i), t.add(f(() => n.removeEventListener("open", i)));
386
386
  }).pipe(g()),
387
387
  close$: new m((a) => {
388
- const i = (l) => a.next(l);
389
- n.addEventListener("close", i), r.add(w(() => n.removeEventListener("close", i)));
388
+ const i = (c) => a.next(c);
389
+ n.addEventListener("close", i), t.add(f(() => n.removeEventListener("close", i)));
390
390
  }).pipe(g()),
391
391
  error$: new m((a) => {
392
- const i = (l) => a.next(l);
393
- n.addEventListener("error", i), r.add(w(() => n.removeEventListener("error", i)));
392
+ const i = (c) => a.next(c);
393
+ n.addEventListener("error", i), t.add(f(() => n.removeEventListener("error", i)));
394
394
  }).pipe(g()),
395
395
  message$: new m((a) => {
396
- const i = (l) => a.next(l);
397
- n.addEventListener("message", i), r.add(w(() => n.removeEventListener("message", i)));
396
+ const i = (c) => a.next(c);
397
+ n.addEventListener("message", i), t.add(f(() => n.removeEventListener("message", i)));
398
398
  }).pipe(g())
399
399
  };
400
400
  } catch (n) {
@@ -402,42 +402,47 @@ class de extends N {
402
402
  }
403
403
  }
404
404
  }
405
- const re = 2, te = 1e3, pe = (e, t) => t(e).pipe(
406
- W((n) => n.pipe(
407
- R((r, s) => s > re ? $(r) : v(r)),
408
- G(te)
409
- ))
410
- ), me = (e, t) => {
411
- const n = [], r = /* @__PURE__ */ new Set(), s = () => {
412
- var a;
413
- for (; r.size < ((a = t == null ? void 0 : t.maxParallel) != null ? a : 1) && n.length > 0; ) {
414
- const i = n.shift();
415
- r.add(i), i();
405
+ const re = 3, te = 1e3, pe = (e, r) => {
406
+ var s, a;
407
+ const n = (s = r == null ? void 0 : r.maxRetryAttempts) != null ? s : re, t = (a = r == null ? void 0 : r.delayInterval) != null ? a : te;
408
+ return (i, c) => c(i).pipe(W({ delay: t, count: n }));
409
+ }, ye = (e) => {
410
+ const r = [], n = /* @__PURE__ */ new Set(), t = () => {
411
+ var s;
412
+ for (; n.size < ((s = e == null ? void 0 : e.maxParallel) != null ? s : 1) && r.length > 0; ) {
413
+ const a = r.shift();
414
+ n.add(a), a();
416
415
  }
417
416
  };
418
- return (a, i) => new m((l) => {
419
- const c = () => i(a).subscribe({
420
- next: (h) => l.next(h),
421
- error: (h) => l.next(h),
422
- complete: () => l.complete()
423
- }), o = () => {
424
- r.delete(c), U(n, c), s();
417
+ return (s, a) => new m((i) => {
418
+ const c = () => a(s).subscribe({
419
+ next: (o) => i.next(o),
420
+ error: (o) => i.next(o),
421
+ complete: () => i.complete()
422
+ }), l = () => {
423
+ n.delete(c), N(r, c), t();
425
424
  };
426
- return n.push(c), s(), o;
425
+ return r.push(c), t(), l;
427
426
  });
427
+ }, me = (e) => {
428
+ const { errorStatusCodes: r, onAuthError: n } = e;
429
+ return (s, a) => a(s).pipe(
430
+ $((i) => (i instanceof y && r.some((c) => c === i.status) && n(), G(() => i)))
431
+ );
428
432
  };
429
433
  export {
430
- oe as FetchHTTPImplementation,
431
- u as HTTPHeaders,
434
+ me as AuthInterceptorFactory,
435
+ ce as FetchHTTPImplementation,
436
+ w as HTTPHeaders,
432
437
  A as HTTPRequest,
433
- b as HTTPResponse,
438
+ R as HTTPResponse,
434
439
  y as HTTPResponseError,
435
440
  q as HTTPService,
436
441
  E as HTTPStatusCode,
437
442
  X as IHTTPImplementation,
438
443
  he as ISocketService,
439
- me as ThresholdInterceptorFactory,
444
+ pe as RetryInterceptorFactory,
445
+ ye as ThresholdInterceptorFactory,
440
446
  de as WebSocketService,
441
- le as XHRHTTPImplementation,
442
- pe as retryInterceptor
447
+ le as XHRHTTPImplementation
443
448
  };
@@ -24,5 +24,6 @@ export { HTTPResponse, type HTTPEvent, HTTPResponseError } from './services/http
24
24
  export { type ISocket, ISocketService, type SocketBodyType, WebSocketService, } from './services/web-socket/web-socket.service';
25
25
  export type { IRequestParams, IPostRequestParams } from './services/http/http.service';
26
26
  export type { HTTPHandlerFn, HTTPInterceptorFn, HTTPInterceptorFnFactory } from './services/http/interceptor';
27
- export { retryInterceptor } from './services/http/interceptors/retry-interceptor';
27
+ export { RetryInterceptorFactory, type IRetryInterceptorFactoryParams } from './services/http/interceptors/retry-interceptor';
28
28
  export { ThresholdInterceptorFactory } from './services/http/interceptors/threshold-interceptor';
29
+ export { AuthInterceptorFactory, type IAuthInterceptorParams } from './services/http/interceptors/auth-interceptor';
@@ -1,5 +1,4 @@
1
1
  import { Observable } from 'rxjs';
2
- import { IAccessor } from '@wendellhu/redi';
3
2
  import { HTTPRequest } from './request';
4
3
  import { HTTPEvent } from './response';
5
4
 
@@ -25,4 +24,4 @@ export type HTTPHandlerFn = (request: HTTPRequest) => Observable<HTTPEvent<unkno
25
24
  */
26
25
  export type HTTPInterceptorFn = (request: HTTPRequest, next: HTTPHandlerFn) => Observable<HTTPEvent<unknown>>;
27
26
  export type RequestPipe<T> = (req: HTTPRequest, finalHandlerFn: HTTPHandlerFn) => Observable<HTTPEvent<T>>;
28
- export type HTTPInterceptorFnFactory = (accessor: IAccessor, params?: any) => HTTPInterceptorFn;
27
+ export type HTTPInterceptorFnFactory<T extends unknown[] = []> = (...args: T) => HTTPInterceptorFn;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export {};
@@ -0,0 +1,7 @@
1
+ import { HTTPInterceptorFnFactory } from '../interceptor';
2
+
3
+ export interface IAuthInterceptorParams {
4
+ errorStatusCodes: number[];
5
+ onAuthError: () => void;
6
+ }
7
+ export declare const AuthInterceptorFactory: HTTPInterceptorFnFactory<[IAuthInterceptorParams]>;
@@ -1,3 +1,8 @@
1
- import { HTTPInterceptorFn } from '../interceptor';
1
+ import { Nullable } from '@univerjs/core';
2
+ import { HTTPInterceptorFnFactory } from '../interceptor';
2
3
 
3
- export declare const retryInterceptor: HTTPInterceptorFn;
4
+ export interface IRetryInterceptorFactoryParams {
5
+ maxRetryAttempts?: number;
6
+ delayInterval?: number;
7
+ }
8
+ export declare const RetryInterceptorFactory: HTTPInterceptorFnFactory<[Nullable<undefined>, Nullable<IRetryInterceptorFactoryParams>]>;
@@ -1,6 +1,7 @@
1
+ import { Nullable } from '@univerjs/core';
1
2
  import { HTTPInterceptorFnFactory } from '../interceptor';
2
3
 
3
4
  export interface IThresholdInterceptorFactoryParams {
4
5
  maxParallel?: number;
5
6
  }
6
- export declare const ThresholdInterceptorFactory: HTTPInterceptorFnFactory;
7
+ export declare const ThresholdInterceptorFactory: HTTPInterceptorFnFactory<[Nullable<IThresholdInterceptorFactoryParams>]>;
package/lib/umd/index.js CHANGED
@@ -1,2 +1,2 @@
1
- (function(c,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("@univerjs/core"),require("rxjs"),require("rxjs/operators"),require("@wendellhu/redi")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs","rxjs/operators","@wendellhu/redi"],d):(c=typeof globalThis<"u"?globalThis:c||self,d(c.UniverNetwork={},c.UniverCore,c.rxjs,c.rxjs.operators,c["@wendellhu/redi"]))})(this,function(c,d,m,f,I){"use strict";var S=Object.defineProperty;var C=(c,d,m)=>d in c?S(c,d,{enumerable:!0,configurable:!0,writable:!0,value:m}):c[d]=m;var y=(c,d,m)=>(C(c,typeof d!="symbol"?d+"":d,m),m);const L="application/json";class g{constructor(t){y(this,"_headers",new Map);typeof t=="string"?this._handleHeadersString(t):t instanceof Headers?this._handleHeaders(t):t&&this._handleHeadersConstructorProps(t)}forEach(t){this._headers.forEach((n,r)=>t(r,n))}has(t){return!!this._headers.has(t.toLowerCase())}get(t){const n=t.toLowerCase();return this._headers.has(n)?this._headers.get(n):null}toHeadersInit(){var n,r;const t={};return this._headers.forEach((s,a)=>{t[a]=s.join(",")}),(n=t.accept)!=null||(t.accept="application/json, text/plain, */*"),(r=t["content-type"])!=null||(t["content-type"]="application/json;charset=UTF-8"),t}_setHeader(t,n){const r=t.toLowerCase();this._headers.has(r)?this._headers.get(r).push(n.toString()):this._headers.set(r,[n.toString()])}_handleHeadersString(t){t.split(`
2
- `).forEach(n=>{const[r,s]=n.split(":");r&&s&&this._setHeader(r,s)})}_handleHeadersConstructorProps(t){Object.entries(t).forEach(([n,r])=>this._setHeader(n,r))}_handleHeaders(t){t.forEach((n,r)=>this._setHeader(r,n))}}const q=I.createIdentifier("network.http-implementation");class A{constructor(t){this.params=t}toString(){return this.params?Object.keys(this.params).map(t=>`${t}=${this.params[t]}`).join("&"):""}}let U=0;class _{constructor(t,n,r){y(this,"uid",U++);this.method=t,this.url=n,this.requestParams=r}get headers(){return this.requestParams.headers}get withCredentials(){return this.requestParams.withCredentials}get responseType(){return this.requestParams.responseType}getUrlWithParams(){var n,r;const t=(r=(n=this.requestParams)==null?void 0:n.params)==null?void 0:r.toString();return t?`${this.url}${this.url.includes("?")?"&":"?"}${t}`:this.url}getBody(){var r,s;const t=(r=this.headers.get("Content-Type"))!=null?r:L,n=(s=this.requestParams)==null?void 0:s.body;return t===L&&n&&typeof n=="object"?JSON.stringify(n):n?`${n}`:null}getHeadersInit(){return this.headers.toHeadersInit()}}class E{constructor({body:t,headers:n,status:r,statusText:s}){y(this,"body");y(this,"headers");y(this,"status");y(this,"statusText");this.body=t,this.headers=n,this.status=r,this.statusText=s}}class w{constructor({headers:t,status:n,statusText:r,error:s}){y(this,"headers");y(this,"status");y(this,"statusText");y(this,"error");this.headers=t,this.status=n,this.statusText=r,this.error=s}}class F{constructor(t,n,r){this.headers=t,this.status=n,this.statusText=r}}var k=Object.defineProperty,x=Object.getOwnPropertyDescriptor,O=(e,t,n,r)=>{for(var s=r>1?void 0:r?x(t,n):t,a=e.length-1,i;a>=0;a--)(i=e[a])&&(s=(r?i(t,n,s):i(s))||s);return r&&s&&k(t,n,s),s},M=(e,t)=>(n,r)=>t(n,r,e);c.HTTPService=class extends d.Disposable{constructor(n){super();y(this,"_interceptors",[]);y(this,"_pipe");this._http=n}registerHTTPInterceptor(n){if(this._interceptors.indexOf(n)!==-1)throw new Error("[HTTPService]: The interceptor has already been registered!");return this._interceptors.push(n),this._interceptors=this._interceptors.sort((r,s)=>{var a,i;return((a=r.priority)!=null?a:0)-((i=s.priority)!=null?i:0)}),this._pipe=null,d.toDisposable(()=>d.remove(this._interceptors,n))}get(n,r){return this._request("GET",n,r)}post(n,r){return this._request("POST",n,r)}put(n,r){return this._request("PUT",n,r)}delete(n,r){return this._request("DELETE",n,r)}patch(n,r){return this._request("PATCH",n,r)}getSSE(n,r,s){var l,h;const a=new g(s==null?void 0:s.headers),i=new A(s==null?void 0:s.params),p=new _(n,r,{headers:a,params:i,withCredentials:(l=s==null?void 0:s.withCredentials)!=null?l:!1,responseType:(h=s==null?void 0:s.responseType)!=null?h:"json",body:["GET","DELETE"].includes(n)||s==null?void 0:s.body});return m.of(p).pipe(f.concatMap(o=>this._runInterceptorsAndImplementation(o)),f.map(o=>{if(o instanceof w)throw o;return o}))}async _request(n,r,s){var o,v;const a=new g(s==null?void 0:s.headers),i=new A(s==null?void 0:s.params),p=new _(n,r,{headers:a,params:i,withCredentials:(o=s==null?void 0:s.withCredentials)!=null?o:!1,responseType:(v=s==null?void 0:s.responseType)!=null?v:"json",body:["GET","DELETE"].includes(n)||s==null?void 0:s.body}),l=m.of(p).pipe(f.concatMap(u=>this._runInterceptorsAndImplementation(u))),h=await m.firstValueFrom(l);if(h instanceof E)return h;throw new Error(`${h.error}`)}_runInterceptorsAndImplementation(n){return this._pipe||(this._pipe=this._interceptors.map(r=>r.interceptor).reduceRight((r,s)=>D(r,s),(r,s)=>s(r))),this._pipe(n,r=>this._http.send(r))}},c.HTTPService=O([M(0,q)],c.HTTPService);function D(e,t){return(n,r)=>t(n,s=>e(s,r))}const j=200,B=300;var b=(e=>(e[e.Continue=100]="Continue",e[e.SwitchingProtocols=101]="SwitchingProtocols",e[e.Processing=102]="Processing",e[e.EarlyHints=103]="EarlyHints",e[e.Ok=200]="Ok",e[e.Created=201]="Created",e[e.Accepted=202]="Accepted",e[e.NonAuthoritativeInformation=203]="NonAuthoritativeInformation",e[e.NoContent=204]="NoContent",e[e.ResetContent=205]="ResetContent",e[e.PartialContent=206]="PartialContent",e[e.MultiStatus=207]="MultiStatus",e[e.AlreadyReported=208]="AlreadyReported",e[e.ImUsed=226]="ImUsed",e[e.MultipleChoices=300]="MultipleChoices",e[e.MovedPermanently=301]="MovedPermanently",e[e.Found=302]="Found",e[e.SeeOther=303]="SeeOther",e[e.NotModified=304]="NotModified",e[e.UseProxy=305]="UseProxy",e[e.Unused=306]="Unused",e[e.TemporaryRedirect=307]="TemporaryRedirect",e[e.PermanentRedirect=308]="PermanentRedirect",e[e.BadRequest=400]="BadRequest",e[e.Unauthorized=401]="Unauthorized",e[e.PaymentRequired=402]="PaymentRequired",e[e.Forbidden=403]="Forbidden",e[e.NotFound=404]="NotFound",e[e.MethodNotAllowed=405]="MethodNotAllowed",e[e.NotAcceptable=406]="NotAcceptable",e[e.ProxyAuthenticationRequired=407]="ProxyAuthenticationRequired",e[e.RequestTimeout=408]="RequestTimeout",e[e.Conflict=409]="Conflict",e[e.Gone=410]="Gone",e[e.LengthRequired=411]="LengthRequired",e[e.PreconditionFailed=412]="PreconditionFailed",e[e.PayloadTooLarge=413]="PayloadTooLarge",e[e.UriTooLong=414]="UriTooLong",e[e.UnsupportedMediaType=415]="UnsupportedMediaType",e[e.RangeNotSatisfiable=416]="RangeNotSatisfiable",e[e.ExpectationFailed=417]="ExpectationFailed",e[e.ImATeapot=418]="ImATeapot",e[e.MisdirectedRequest=421]="MisdirectedRequest",e[e.UnprocessableEntity=422]="UnprocessableEntity",e[e.Locked=423]="Locked",e[e.FailedDependency=424]="FailedDependency",e[e.TooEarly=425]="TooEarly",e[e.UpgradeRequired=426]="UpgradeRequired",e[e.PreconditionRequired=428]="PreconditionRequired",e[e.TooManyRequests=429]="TooManyRequests",e[e.RequestHeaderFieldsTooLarge=431]="RequestHeaderFieldsTooLarge",e[e.UnavailableForLegalReasons=451]="UnavailableForLegalReasons",e[e.InternalServerError=500]="InternalServerError",e[e.NotImplemented=501]="NotImplemented",e[e.BadGateway=502]="BadGateway",e[e.ServiceUnavailable=503]="ServiceUnavailable",e[e.GatewayTimeout=504]="GatewayTimeout",e[e.HttpVersionNotSupported=505]="HttpVersionNotSupported",e[e.VariantAlsoNegotiates=506]="VariantAlsoNegotiates",e[e.InsufficientStorage=507]="InsufficientStorage",e[e.LoopDetected=508]="LoopDetected",e[e.NotExtended=510]="NotExtended",e[e.NetworkAuthenticationRequired=511]="NetworkAuthenticationRequired",e))(b||{});class ${send(t){return new m.Observable(n=>{const r=new AbortController;return this._send(t,n,r).then(()=>{},s=>{n.error(new w({error:s}))}),()=>r.abort()})}async _send(t,n,r){var o,v;let s;try{const u=this._parseFetchParamsFromRequest(t);s=await fetch(t.getUrlWithParams(),{signal:r.signal,...u})}catch(u){n.error(new w({error:u,status:(o=u.status)!=null?o:0,statusText:(v=u.statusText)!=null?v:"Unknown Error",headers:u.headers}));return}const a=new g(s.headers),i=s.status,p=s.statusText;let l=null;s.body&&(l=await this._readBody(t,s,n)),i>=b.Ok&&i<b.MultipleChoices?n.next(new E({body:l,headers:a,status:i,statusText:p})):n.error(new w({error:l,status:i,statusText:p,headers:a})),n.complete()}async _readBody(t,n,r){var l;const s=[],a=n.body.getReader();let i=0;for(;;){const{done:h,value:o}=await a.read();if(h)break;s.push(o),i+=o.length}const p=G(s,i);try{const h=(l=n.headers.get("content-type"))!=null?l:"";return V(t,p,h)}catch(h){return r.error(new w({error:h,status:n.status,statusText:n.statusText,headers:new g(n.headers)})),null}}_parseFetchParamsFromRequest(t){return{method:t.method,headers:t.getHeadersInit(),body:t.getBody(),credentials:t.withCredentials?"include":void 0}}}function G(e,t){const n=new Uint8Array(t);let r=0;for(const s of e)n.set(s,r),r+=s.length;return n}const W=/^\)\]\}',?\n/;function V(e,t,n){switch(e.responseType){case"json":const r=new TextDecoder().decode(t).replace(W,"");return r===""?null:JSON.parse(r);case"text":return new TextDecoder().decode(t);case"blob":return new Blob([t],{type:n});case"arraybuffer":return t.buffer;default:throw new Error(`[FetchHTTPImplementation]: unknown response type: ${e.responseType}.`)}}class X{send(t){return new m.Observable(n=>{const r=new XMLHttpRequest;r.open(t.method,t.getUrlWithParams()),t.withCredentials&&(r.withCredentials=!0),t.headers.forEach((l,h)=>r.setRequestHeader(l,h.join(","))),t.headers.has("Accept")||r.setRequestHeader("Accept","application/json, text/plain, */*"),t.headers.has("Content-Type")||r.setRequestHeader("Content-Type","application/json;charset=UTF-8");const s=()=>{const l=r.statusText||"OK",h=new g(r.getAllResponseHeaders());return new F(h,r.status,l)},a=()=>{const{headers:l,statusText:h,status:o}=s(),{responseType:v}=t;let u=null,R=null;o!==b.NoContent&&(u=typeof r.response>"u"?r.responseText:r.response);let N=o>=j&&o<B;if(v==="json"&&typeof u=="string"){const P=u;try{u=u?JSON.parse(u):null}catch(H){N=!1,u=P,R=H}}N?n.next(new E({body:u,headers:l,status:o,statusText:h})):n.error(new w({error:R,headers:l,status:o,statusText:h}))},i=l=>{const h=new w({error:l,status:r.status||0,statusText:r.statusText||"Unknown Error",headers:s().headers});n.error(h)};r.addEventListener("load",a),r.addEventListener("error",i),r.addEventListener("abort",i),r.addEventListener("timeout",i);const p=t.getBody();return r.send(p),()=>{r.readyState!==r.DONE&&r.abort(),r.removeEventListener("load",a),r.removeEventListener("error",i),r.removeEventListener("abort",i),r.removeEventListener("timeout",i)}})}}const z=I.createIdentifier("univer.socket");class J extends d.Disposable{createSocket(t){try{const n=new WebSocket(t),r=new d.DisposableCollection;return{URL:t,close:(a,i)=>{n.close(a,i),r.dispose()},send:a=>{n.send(a)},open$:new m.Observable(a=>{const i=p=>a.next(p);n.addEventListener("open",i),r.add(d.toDisposable(()=>n.removeEventListener("open",i)))}).pipe(f.share()),close$:new m.Observable(a=>{const i=p=>a.next(p);n.addEventListener("close",i),r.add(d.toDisposable(()=>n.removeEventListener("close",i)))}).pipe(f.share()),error$:new m.Observable(a=>{const i=p=>a.next(p);n.addEventListener("error",i),r.add(d.toDisposable(()=>n.removeEventListener("error",i)))}).pipe(f.share()),message$:new m.Observable(a=>{const i=p=>a.next(p);n.addEventListener("message",i),r.add(d.toDisposable(()=>n.removeEventListener("message",i)))}).pipe(f.share())}}catch(n){return console.error(n),null}}}const Y=2,K=1e3,Q=(e,t)=>t(e).pipe(f.retryWhen(n=>n.pipe(f.concatMap((r,s)=>s>Y?m.throwError(r):m.of(r)),m.delay(K)))),Z=(e,t)=>{const n=[],r=new Set,s=()=>{var a;for(;r.size<((a=t==null?void 0:t.maxParallel)!=null?a:1)&&n.length>0;){const i=n.shift();r.add(i),i()}};return(a,i)=>new m.Observable(p=>{const l=()=>i(a).subscribe({next:o=>p.next(o),error:o=>p.next(o),complete:()=>p.complete()}),h=()=>{r.delete(l),d.remove(n,l),s()};return n.push(l),s(),h})};c.FetchHTTPImplementation=$,c.HTTPHeaders=g,c.HTTPRequest=_,c.HTTPResponse=E,c.HTTPResponseError=w,c.HTTPStatusCode=b,c.IHTTPImplementation=q,c.ISocketService=z,c.ThresholdInterceptorFactory=Z,c.WebSocketService=J,c.XHRHTTPImplementation=X,c.retryInterceptor=Q,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
1
+ (function(c,h){typeof exports=="object"&&typeof module<"u"?h(exports,require("@univerjs/core"),require("rxjs"),require("rxjs/operators"),require("@wendellhu/redi")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs","rxjs/operators","@wendellhu/redi"],h):(c=typeof globalThis<"u"?globalThis:c||self,h(c.UniverNetwork={},c.UniverCore,c.rxjs,c.rxjs.operators,c["@wendellhu/redi"]))})(this,function(c,h,u,w,I){"use strict";var C=Object.defineProperty;var T=(c,h,u)=>h in c?C(c,h,{enumerable:!0,configurable:!0,writable:!0,value:u}):c[h]=u;var m=(c,h,u)=>(T(c,typeof h!="symbol"?h+"":h,u),u);const L="application/json";class E{constructor(n){m(this,"_headers",new Map);typeof n=="string"?this._handleHeadersString(n):n instanceof Headers?this._handleHeaders(n):n&&this._handleHeadersConstructorProps(n)}forEach(n){this._headers.forEach((t,r)=>n(r,t))}has(n){return!!this._headers.has(n.toLowerCase())}get(n){const t=n.toLowerCase();return this._headers.has(t)?this._headers.get(t):null}toHeadersInit(){var t,r;const n={};return this._headers.forEach((s,a)=>{n[a]=s.join(",")}),(t=n.accept)!=null||(n.accept="application/json, text/plain, */*"),(r=n["content-type"])!=null||(n["content-type"]="application/json;charset=UTF-8"),n}_setHeader(n,t){const r=n.toLowerCase();this._headers.has(r)?this._headers.get(r).push(t.toString()):this._headers.set(r,[t.toString()])}_handleHeadersString(n){n.split(`
2
+ `).forEach(t=>{const[r,s]=t.split(":");r&&s&&this._setHeader(r,s)})}_handleHeadersConstructorProps(n){Object.entries(n).forEach(([t,r])=>this._setHeader(t,r))}_handleHeaders(n){n.forEach((t,r)=>this._setHeader(r,t))}}const A=I.createIdentifier("network.http-implementation");class q{constructor(n){this.params=n}toString(){return this.params?Object.keys(this.params).map(n=>`${n}=${this.params[n]}`).join("&"):""}}let N=0;class _{constructor(n,t,r){m(this,"uid",N++);this.method=n,this.url=t,this.requestParams=r}get headers(){return this.requestParams.headers}get withCredentials(){return this.requestParams.withCredentials}get responseType(){return this.requestParams.responseType}getUrlWithParams(){var t,r;const n=(r=(t=this.requestParams)==null?void 0:t.params)==null?void 0:r.toString();return n?`${this.url}${this.url.includes("?")?"&":"?"}${n}`:this.url}getBody(){var r,s;const n=(r=this.headers.get("Content-Type"))!=null?r:L,t=(s=this.requestParams)==null?void 0:s.body;return n===L&&t&&typeof t=="object"?JSON.stringify(t):t?`${t}`:null}getHeadersInit(){return this.headers.toHeadersInit()}}class b{constructor({body:n,headers:t,status:r,statusText:s}){m(this,"body");m(this,"headers");m(this,"status");m(this,"statusText");this.body=n,this.headers=t,this.status=r,this.statusText=s}}class f{constructor({headers:n,status:t,statusText:r,error:s}){m(this,"headers");m(this,"status");m(this,"statusText");m(this,"error");this.headers=n,this.status=t,this.statusText=r,this.error=s}}class U{constructor(n,t,r){this.headers=n,this.status=t,this.statusText=r}}var x=Object.defineProperty,k=Object.getOwnPropertyDescriptor,O=(e,n,t,r)=>{for(var s=r>1?void 0:r?k(n,t):n,a=e.length-1,i;a>=0;a--)(i=e[a])&&(s=(r?i(n,t,s):i(s))||s);return r&&s&&x(n,t,s),s},M=(e,n)=>(t,r)=>n(t,r,e);c.HTTPService=class extends h.Disposable{constructor(t){super();m(this,"_interceptors",[]);m(this,"_pipe");this._http=t}registerHTTPInterceptor(t){if(this._interceptors.indexOf(t)!==-1)throw new Error("[HTTPService]: The interceptor has already been registered!");return this._interceptors.push(t),this._interceptors=this._interceptors.sort((r,s)=>{var a,i;return((a=r.priority)!=null?a:0)-((i=s.priority)!=null?i:0)}),this._pipe=null,h.toDisposable(()=>h.remove(this._interceptors,t))}get(t,r){return this._request("GET",t,r)}post(t,r){return this._request("POST",t,r)}put(t,r){return this._request("PUT",t,r)}delete(t,r){return this._request("DELETE",t,r)}patch(t,r){return this._request("PATCH",t,r)}getSSE(t,r,s){var d,l;const a=new E(s==null?void 0:s.headers),i=new q(s==null?void 0:s.params),o=new _(t,r,{headers:a,params:i,withCredentials:(d=s==null?void 0:s.withCredentials)!=null?d:!1,responseType:(l=s==null?void 0:s.responseType)!=null?l:"json",body:["GET","DELETE"].includes(t)||s==null?void 0:s.body});return u.of(o).pipe(w.concatMap(p=>this._runInterceptorsAndImplementation(p)),w.map(p=>{if(p instanceof f)throw p;return p}))}async _request(t,r,s){var p,v;const a=new E(s==null?void 0:s.headers),i=new q(s==null?void 0:s.params),o=new _(t,r,{headers:a,params:i,withCredentials:(p=s==null?void 0:s.withCredentials)!=null?p:!1,responseType:(v=s==null?void 0:s.responseType)!=null?v:"json",body:["GET","DELETE"].includes(t)||s==null?void 0:s.body}),d=u.of(o).pipe(w.concatMap(y=>this._runInterceptorsAndImplementation(y))),l=await u.firstValueFrom(d);if(l instanceof b)return l;throw new Error(`${l.error}`)}_runInterceptorsAndImplementation(t){return this._pipe||(this._pipe=this._interceptors.map(r=>r.interceptor).reduceRight((r,s)=>D(r,s),(r,s)=>s(r))),this._pipe(t,r=>this._http.send(r))}},c.HTTPService=O([M(0,A)],c.HTTPService);function D(e,n){return(t,r)=>n(t,s=>e(s,r))}const j=200,B=300;var g=(e=>(e[e.Continue=100]="Continue",e[e.SwitchingProtocols=101]="SwitchingProtocols",e[e.Processing=102]="Processing",e[e.EarlyHints=103]="EarlyHints",e[e.Ok=200]="Ok",e[e.Created=201]="Created",e[e.Accepted=202]="Accepted",e[e.NonAuthoritativeInformation=203]="NonAuthoritativeInformation",e[e.NoContent=204]="NoContent",e[e.ResetContent=205]="ResetContent",e[e.PartialContent=206]="PartialContent",e[e.MultiStatus=207]="MultiStatus",e[e.AlreadyReported=208]="AlreadyReported",e[e.ImUsed=226]="ImUsed",e[e.MultipleChoices=300]="MultipleChoices",e[e.MovedPermanently=301]="MovedPermanently",e[e.Found=302]="Found",e[e.SeeOther=303]="SeeOther",e[e.NotModified=304]="NotModified",e[e.UseProxy=305]="UseProxy",e[e.Unused=306]="Unused",e[e.TemporaryRedirect=307]="TemporaryRedirect",e[e.PermanentRedirect=308]="PermanentRedirect",e[e.BadRequest=400]="BadRequest",e[e.Unauthorized=401]="Unauthorized",e[e.PaymentRequired=402]="PaymentRequired",e[e.Forbidden=403]="Forbidden",e[e.NotFound=404]="NotFound",e[e.MethodNotAllowed=405]="MethodNotAllowed",e[e.NotAcceptable=406]="NotAcceptable",e[e.ProxyAuthenticationRequired=407]="ProxyAuthenticationRequired",e[e.RequestTimeout=408]="RequestTimeout",e[e.Conflict=409]="Conflict",e[e.Gone=410]="Gone",e[e.LengthRequired=411]="LengthRequired",e[e.PreconditionFailed=412]="PreconditionFailed",e[e.PayloadTooLarge=413]="PayloadTooLarge",e[e.UriTooLong=414]="UriTooLong",e[e.UnsupportedMediaType=415]="UnsupportedMediaType",e[e.RangeNotSatisfiable=416]="RangeNotSatisfiable",e[e.ExpectationFailed=417]="ExpectationFailed",e[e.ImATeapot=418]="ImATeapot",e[e.MisdirectedRequest=421]="MisdirectedRequest",e[e.UnprocessableEntity=422]="UnprocessableEntity",e[e.Locked=423]="Locked",e[e.FailedDependency=424]="FailedDependency",e[e.TooEarly=425]="TooEarly",e[e.UpgradeRequired=426]="UpgradeRequired",e[e.PreconditionRequired=428]="PreconditionRequired",e[e.TooManyRequests=429]="TooManyRequests",e[e.RequestHeaderFieldsTooLarge=431]="RequestHeaderFieldsTooLarge",e[e.UnavailableForLegalReasons=451]="UnavailableForLegalReasons",e[e.InternalServerError=500]="InternalServerError",e[e.NotImplemented=501]="NotImplemented",e[e.BadGateway=502]="BadGateway",e[e.ServiceUnavailable=503]="ServiceUnavailable",e[e.GatewayTimeout=504]="GatewayTimeout",e[e.HttpVersionNotSupported=505]="HttpVersionNotSupported",e[e.VariantAlsoNegotiates=506]="VariantAlsoNegotiates",e[e.InsufficientStorage=507]="InsufficientStorage",e[e.LoopDetected=508]="LoopDetected",e[e.NotExtended=510]="NotExtended",e[e.NetworkAuthenticationRequired=511]="NetworkAuthenticationRequired",e))(g||{});class ${send(n){return new u.Observable(t=>{const r=new AbortController;return this._send(n,t,r).then(()=>{},s=>{t.error(new f({error:s}))}),()=>r.abort()})}async _send(n,t,r){var p,v;let s;try{const y=this._parseFetchParamsFromRequest(n);s=await fetch(n.getUrlWithParams(),{signal:r.signal,...y})}catch(y){t.error(new f({error:y,status:(p=y.status)!=null?p:0,statusText:(v=y.statusText)!=null?v:"Unknown Error",headers:y.headers}));return}const a=new E(s.headers),i=s.status,o=s.statusText;let d=null;s.body&&(d=await this._readBody(n,s,t)),i>=g.Ok&&i<g.MultipleChoices?t.next(new b({body:d,headers:a,status:i,statusText:o})):t.error(new f({error:d,status:i,statusText:o,headers:a})),t.complete()}async _readBody(n,t,r){var d;const s=[],a=t.body.getReader();let i=0;for(;;){const{done:l,value:p}=await a.read();if(l)break;s.push(p),i+=p.length}const o=G(s,i);try{const l=(d=t.headers.get("content-type"))!=null?d:"";return W(n,o,l)}catch(l){return r.error(new f({error:l,status:t.status,statusText:t.statusText,headers:new E(t.headers)})),null}}_parseFetchParamsFromRequest(n){return{method:n.method,headers:n.getHeadersInit(),body:n.getBody(),credentials:n.withCredentials?"include":void 0}}}function G(e,n){const t=new Uint8Array(n);let r=0;for(const s of e)t.set(s,r),r+=s.length;return t}const V=/^\)\]\}',?\n/;function W(e,n,t){switch(e.responseType){case"json":const r=new TextDecoder().decode(n).replace(V,"");return r===""?null:JSON.parse(r);case"text":return new TextDecoder().decode(n);case"blob":return new Blob([n],{type:t});case"arraybuffer":return n.buffer;default:throw new Error(`[FetchHTTPImplementation]: unknown response type: ${e.responseType}.`)}}class X{send(n){return new u.Observable(t=>{const r=new XMLHttpRequest;r.open(n.method,n.getUrlWithParams()),n.withCredentials&&(r.withCredentials=!0),n.headers.forEach((d,l)=>r.setRequestHeader(d,l.join(","))),n.headers.has("Accept")||r.setRequestHeader("Accept","application/json, text/plain, */*"),n.headers.has("Content-Type")||r.setRequestHeader("Content-Type","application/json;charset=UTF-8");const s=()=>{const d=r.statusText||"OK",l=new E(r.getAllResponseHeaders());return new U(l,r.status,d)},a=()=>{const{headers:d,statusText:l,status:p}=s(),{responseType:v}=n;let y=null,R=null;p!==g.NoContent&&(y=typeof r.response>"u"?r.responseText:r.response);let F=p>=j&&p<B;if(v==="json"&&typeof y=="string"){const H=y;try{y=y?JSON.parse(y):null}catch(S){F=!1,y=H,R=S}}F?t.next(new b({body:y,headers:d,status:p,statusText:l})):t.error(new f({error:R,headers:d,status:p,statusText:l}))},i=d=>{const l=new f({error:d,status:r.status||0,statusText:r.statusText||"Unknown Error",headers:s().headers});t.error(l)};r.addEventListener("load",a),r.addEventListener("error",i),r.addEventListener("abort",i),r.addEventListener("timeout",i);const o=n.getBody();return r.send(o),()=>{r.readyState!==r.DONE&&r.abort(),r.removeEventListener("load",a),r.removeEventListener("error",i),r.removeEventListener("abort",i),r.removeEventListener("timeout",i)}})}}const z=I.createIdentifier("univer.socket");class J extends h.Disposable{createSocket(n){try{const t=new WebSocket(n),r=new h.DisposableCollection;return{URL:n,close:(a,i)=>{t.close(a,i),r.dispose()},send:a=>{t.send(a)},open$:new u.Observable(a=>{const i=o=>a.next(o);t.addEventListener("open",i),r.add(h.toDisposable(()=>t.removeEventListener("open",i)))}).pipe(w.share()),close$:new u.Observable(a=>{const i=o=>a.next(o);t.addEventListener("close",i),r.add(h.toDisposable(()=>t.removeEventListener("close",i)))}).pipe(w.share()),error$:new u.Observable(a=>{const i=o=>a.next(o);t.addEventListener("error",i),r.add(h.toDisposable(()=>t.removeEventListener("error",i)))}).pipe(w.share()),message$:new u.Observable(a=>{const i=o=>a.next(o);t.addEventListener("message",i),r.add(h.toDisposable(()=>t.removeEventListener("message",i)))}).pipe(w.share())}}catch(t){return console.error(t),null}}}const Y=3,K=1e3,Q=(e,n)=>{var s,a;const t=(s=n==null?void 0:n.maxRetryAttempts)!=null?s:Y,r=(a=n==null?void 0:n.delayInterval)!=null?a:K;return(i,o)=>o(i).pipe(w.retry({delay:r,count:t}))},Z=e=>{const n=[],t=new Set,r=()=>{var s;for(;t.size<((s=e==null?void 0:e.maxParallel)!=null?s:1)&&n.length>0;){const a=n.shift();t.add(a),a()}};return(s,a)=>new u.Observable(i=>{const o=()=>a(s).subscribe({next:l=>i.next(l),error:l=>i.next(l),complete:()=>i.complete()}),d=()=>{t.delete(o),h.remove(n,o),r()};return n.push(o),r(),d})},P=e=>{const{errorStatusCodes:n,onAuthError:t}=e;return(s,a)=>a(s).pipe(u.catchError(i=>(i instanceof f&&n.some(o=>o===i.status)&&t(),u.throwError(()=>i))))};c.AuthInterceptorFactory=P,c.FetchHTTPImplementation=$,c.HTTPHeaders=E,c.HTTPRequest=_,c.HTTPResponse=b,c.HTTPResponseError=f,c.HTTPStatusCode=g,c.IHTTPImplementation=A,c.ISocketService=z,c.RetryInterceptorFactory=Q,c.ThresholdInterceptorFactory=Z,c.WebSocketService=J,c.XHRHTTPImplementation=X,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/network",
3
- "version": "0.1.13",
3
+ "version": "0.1.14",
4
4
  "private": false,
5
5
  "author": "DreamNum <developer@univer.ai>",
6
6
  "license": "Apache-2.0",
@@ -44,14 +44,10 @@
44
44
  "files": [
45
45
  "lib"
46
46
  ],
47
- "engines": {
48
- "node": ">=16.0.0",
49
- "npm": ">=8.0.0"
50
- },
51
47
  "peerDependencies": {
52
48
  "@wendellhu/redi": "0.15.2",
53
49
  "rxjs": ">=7.0.0",
54
- "@univerjs/core": "0.1.13"
50
+ "@univerjs/core": "0.1.14"
55
51
  },
56
52
  "devDependencies": {
57
53
  "@wendellhu/redi": "0.15.2",
@@ -59,8 +55,21 @@
59
55
  "typescript": "^5.4.5",
60
56
  "vite": "^5.2.12",
61
57
  "vitest": "^1.6.0",
62
- "@univerjs/core": "0.1.13",
63
- "@univerjs/shared": "0.1.13"
58
+ "@univerjs/shared": "0.1.14",
59
+ "@univerjs/core": "0.1.14"
60
+ },
61
+ "univerSpace": {
62
+ ".": {
63
+ "import": "./lib/es/index.js",
64
+ "require": "./lib/cjs/index.js",
65
+ "types": "./lib/types/index.d.ts"
66
+ },
67
+ "./*": {
68
+ "import": "./lib/es/*",
69
+ "require": "./lib/cjs/*",
70
+ "types": "./lib/types/index.d.ts"
71
+ },
72
+ "./lib/*": "./lib/*"
64
73
  },
65
74
  "scripts": {
66
75
  "test": "vitest run",