@bobtail.software/b-ssr 1.0.6 → 1.0.8

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.
@@ -1,3 +1,9 @@
1
+ declare class ApiClientError extends Error {
2
+ readonly status: number;
3
+ readonly statusText: string;
4
+ readonly body: unknown;
5
+ constructor(message: string, status: number, statusText: string, body: unknown);
6
+ }
1
7
  type ClientArgs<TArgs extends {
2
8
  params?: unknown;
3
9
  query?: unknown;
@@ -17,4 +23,4 @@ declare function createClientRpc<TArgs extends {
17
23
  body?: unknown;
18
24
  }, TReturn>({ method, url, isMultipart }: RpcClientOptions): (args: ClientArgs<TArgs>) => Promise<TReturn>;
19
25
 
20
- export { type RpcClientOptions, createClientRpc };
26
+ export { ApiClientError, type RpcClientOptions, createClientRpc };
@@ -1 +1 @@
1
- function y(r){return r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function w(r,s){let t=r;for(let i in s)if(Object.prototype.hasOwnProperty.call(s,i)){let a=s[i];if(a==null)continue;let c=encodeURIComponent(String(a)),g=new RegExp(`:${y(i)}(\\??)`,"g");t=t.replace(g,c)}t=t.replace(/\/:[a-zA-Z0-9_]+\?/g,"");let p=t.match(/:[a-zA-Z0-9_]+/g);if(p)throw new Error(`Error al compilar la URL. Faltan par\xE1metros requeridos: ${p.join(", ")}`);return t}function h({method:r,url:s,isMultipart:t}){return async p=>{let{params:i={},query:a={},body:c}=p,g=w(s,i),d=new URL(g,window.location.origin);a&&Object.entries(a).forEach(([n,e])=>{e!=null&&d.searchParams.append(n,String(e))});let l={method:r,headers:{},credentials:"include"};if(r==="POST")if(t){let n=new FormData,e=c?{...c}:{};"file"in e&&e.file instanceof File&&(n.append("file",e.file),delete e.file),Object.entries(e).forEach(([u,f])=>{n.append(u,String(f))}),l.body=n}else l.headers["Content-Type"]="application/json",l.headers.Accept="application/json",l.body=JSON.stringify(c||{});let o=await fetch(d.toString(),l);if(!o.ok){let n;try{n=await o.json()}catch{}throw new Error(n?.error?.message||n?.message||`La solicitud fall\xF3 con estado ${o.status}`)}if(!(o.headers.get("Content-Length")==="0"||o.status===204))return o.json()}}export{h as createClientRpc};
1
+ var f=class extends Error{status;statusText;body;constructor(o,e,c,i){super(o),this.name="ApiClientError",this.status=e,this.statusText=c,this.body=i}};function w(s){return s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function h(s,o){let e=s;for(let i in o)if(Object.prototype.hasOwnProperty.call(o,i)){let l=o[i];if(l==null)continue;let u=encodeURIComponent(String(l)),d=new RegExp(`:${w(i)}(\\??)`,"g");e=e.replace(d,u)}e=e.replace(/\/:[a-zA-Z0-9_]+\?/g,"");let c=e.match(/:[a-zA-Z0-9_]+/g);if(c)throw new Error(`Error al compilar la URL. Faltan par\xE1metros requeridos: ${c.join(", ")}`);return e}function m({method:s,url:o,isMultipart:e}){return async c=>{let{params:i={},query:l={},body:u}=c,d=h(o,i),y=new URL(d,window.location.origin);l&&Object.entries(l).forEach(([r,n])=>{n!=null&&y.searchParams.append(r,String(n))});let p={method:s,headers:{},credentials:"include"};if(s==="POST")if(e){let r=new FormData,n=u?{...u}:{};"file"in n&&n.file instanceof File&&(r.append("file",n.file),delete n.file),Object.entries(n).forEach(([a,g])=>{r.append(a,String(g))}),p.body=r}else p.headers["Content-Type"]="application/json",p.headers.Accept="application/json",p.body=JSON.stringify(u||{});let t=await fetch(y.toString(),p);if(!t.ok){let r=`Request failed with status ${t.status} (${t.statusText})`,n=null,a="";try{n=await t.json(),a=n?.error?.message||n?.message}catch{try{a=await t.text(),n=a}catch{}}let g=a?`${r}: ${a}`:r;throw new f(g,t.status,t.statusText,n)}if(!(t.headers.get("Content-Length")==="0"||t.status===204))return t.json()}}export{f as ApiClientError,m as createClientRpc};