@basmilius/http-client 1.2.2 → 1.3.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.
@@ -1,2 +1,2 @@
1
1
  var Ge=Object.defineProperty;var _e=Object.getOwnPropertyDescriptor;var Re=r=>{throw TypeError(r)};var P=(r,e,n,o)=>{for(var i=o>1?void 0:o?_e(e,n):e,u=r.length-1,l;u>=0;u--)(l=r[u])&&(i=(o?l(e,n,i):l(i))||i);return o&&i&&Ge(e,n,i),i};var De=(r,e,n)=>e.has(r)||Re("Cannot "+n);var h=(r,e,n)=>(De(r,e,"read from private field"),n?n.call(r):e.get(r)),y=(r,e,n)=>e.has(r)?Re("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(r):e.set(r,n),d=(r,e,n,o)=>(De(r,e,"write to private field"),o?o.call(r,n):e.set(r,n),n);function oe(r){return class extends r{constructor(...e){throw new Error("Adapters cannot be instantiated.")}}}function Be(){return(r,e)=>{r[e]=r[e].bind(r)}}function Le(r){return(e,n,o)=>{o.value=Fe(o.value,r,e)}}function Fe(r,e,n){let o=[],i=[],u=null;return(...l)=>(clearTimeout(u),u=setTimeout(async()=>{try{let c=await r.apply(n,l);o.forEach(b=>b(c))}catch(c){i.forEach(b=>b(c))}o=[],i=[]},e),new Promise((c,b)=>{o.push(c),i.push(b)}))}import{DateTime as Me}from"luxon";function U(r){return r=r||Me.now(),r.toFormat("yyyy-MM-dd HH-mm-ss")}function ge(r){let e={};do{if(r.name==="")break;for(let[n,o]of Object.entries(Object.getOwnPropertyDescriptors(r.prototype)))["constructor","clone","toJSON"].includes(n)||!o.get&&!o.set||(e[n]=o)}while(r=Object.getPrototypeOf(r));return e}function ee(r,e,n){r.prototype[e]=n}function Y(r,e,n){Object.defineProperty(r,e,{value:n})}var B=Symbol(),g=Symbol(),w=Symbol(),R=Symbol(),m=Symbol(),f=Symbol(),a=Symbol(),k=Symbol(),N=Symbol(),re=Symbol(),ne=Symbol();function s(r){return r&&typeof r=="object"&&r[m]}function ie(r,e){return!s(r)||!s(e)?r===e:JSON.stringify(r)===JSON.stringify(e)}function p(r){if(!s(r))throw new Error("@dto assert given object is not a class decorated with @Dto.")}var se=Symbol();function L(r,e=0,n){return function(...o){let i=se in r,u=r[se]??=new WeakMap,l=o[e],c=n!==void 0?o[n]:"self";if(typeof l!="object")return r.call(this,...o);if(u.has(l)||u.set(l,[]),u.get(l).includes(c)){!1;return}u.get(l).push(c);let b=r.call(this,...o);return!i&&delete r[se],b}}function ce(r){return p(r),r.clone()}function O(r){return p(r),r[R]}var Te=L(function(r,e,n,o){let i=r[ne];i(r,e,n,o),!1,r[f]&&Te(r[f],r[a],r[f][r[a]])},0,1),T=Te;var be=L(function(r){p(r),r[R]&&(r[R]=!1,!1,T(r,R,!1,!0)),!(!r[g]||r[g].length===0)&&r[g].filter(O).forEach(be)}),K=be;async function le(r,e){!s(r)||!O(r)||(await e(r),K(r))}function ae(r){return r?.value??r}function ue(r){return p(r),!r[R]}var we=L(function(r,e){p(r),r[R]||(r[R]=!0,!1,T(r,R,!0,!1)),r[f]&&we(r[f],r[a])}),I=we;function F(r,e,n){e[g]??=[],!e[g].includes(r)&&e[g].push(r),r[f]!==e&&(r[f]=e),r[a]!==n&&(r[a]=n)}function M(r,e,n){s(n)?F(n,r,e):Array.isArray(n)&&(n.some(s)&&n.filter(s).forEach(o=>F(o,r,e)),n[f]=r,n[a]=e)}function E(r,e){let n=r[re];n(r,e),!1}function me(r,e){if(g in e){let n=e[g].indexOf(r);e[g].splice(n,1)}r[f]=void 0,r[a]=void 0}function fe(r,e){s(e)?me(e,r):Array.isArray(e)&&(e.some(s)&&e.filter(s).forEach(n=>me(n,r)),e[f]=void 0,e[a]=void 0)}var xe={};import{customRef as Ke,markRaw as Ve}from"vue";var te={deleteProperty(r,e){if(Reflect.deleteProperty(r,e),pe(r,e))return!0;let n=r[f];return n&&T(n,r[a],n[r[a]]),n&&I(n,r[a]),!0},get(r,e,n){if(e===N)return!0;if(pe(r,e))return Reflect.get(r,e,n);let o=r[f];return o&&E(o,r[a]),Reflect.get(r,e)},set(r,e,n,o){if(pe(r,e))return Reflect.set(r,e,n,o);let i=r[f];return i&&T(i,r[a],i[r[a]]),i&&I(i,r[a]),Reflect.set(r,e,n)}};function pe(r,e){return typeof e=="symbol"||typeof r[e]=="function"||e==="length"}var Pe={get(r,e,n){if(e===N)return!0;if(typeof e=="symbol")return Reflect.get(r,e,n);let o=r[w][e];if(!o||!o.get)return Reflect.get(r,e,n);let i=o.get.call(r);return!1,E(r,e),M(r,e,i),i},getOwnPropertyDescriptor(r,e){return r[w][e]},ownKeys(r){return r[k]},set(r,e,n,o){if(typeof e=="symbol")return Reflect.set(r,e,n,o);let i=r[w][e];if(!i||!i.set)return Reflect.set(r,e,n,o);let u=i.get?.call(r)??void 0;return ie(n,u)||(fe(r,u),Array.isArray(n)&&!n[N]&&(n=new Proxy(n,te)),!1,i.set.call(r,n),M(r,e,n),I(r,e),T(r,e,n,u)),!0}};var Ie={get(r,e,n){return e==="__v_isRef"?!1:e===N?!0:e in r?Reflect.get(r,e,n):Reflect.get(r.value,e)},getOwnPropertyDescriptor(r,e){return Reflect.getOwnPropertyDescriptor(r.value,e)},ownKeys(r){return Reflect.ownKeys(r.value)},set(r,e,n,o){return e in r?Reflect.set(r,e,n,o):Reflect.set(r.value,e,n)}};var Ee={construct(r,e,n){e=e.map(i=>Array.isArray(i)?new Proxy(i,te):i);let o=Ke((i,u)=>{let l=Ve(Reflect.construct(r,e,n));l[B]=e,l[R]=!1,l[re]=i,l[ne]=u;let c=new Proxy(l,Pe);return{get:()=>(i(),c),set:()=>{}}});return new Proxy(o,Ie)}};function Ae(){let r=this;p(r);let e=Reflect.construct(r.prototype.constructor,r[B]);return Object.entries(this[w]).filter(([,n])=>!!n.set).map(([n])=>n).forEach(n=>e[n]=s(this[n])?this[n].clone():this[n]),e}function ke(r){for(let e in r){let n=this[w][e];s(this[e])&&typeof r[e]=="object"?this[e].fill(r[e]):n&&n.set&&(this[e]=r[e])}}function Ne(){return Object.fromEntries(this[k].map(r=>{let e=Reflect.get.call(this,this,r,this);return s(e)&&(e=e.toJSON()),[r,e]}))}function q(r){Qe(r);let e=Object.freeze(ge(r)),n=Object.keys(e);return Y(r.prototype,w,e),Y(r.prototype,m,r.name),Y(r.prototype,k,n),Y(r,Symbol.hasInstance,o=>typeof o=="object"&&o?.[m]===r.name),ee(r,"clone",Ae),ee(r,"fill",ke),ee(r,"toJSON",Ne),je(r)}function je(r){let e=new Proxy(r,Ee);return xe[r.name]=e,e}function Qe(r){let e=Object.getPrototypeOf(r.prototype);if(m in e)throw new Error(`\u26D4\uFE0F @dto ${r.name} cannot extend parent @dto ${e[m]}. A non-dto base implementation should be created with separate implementations. TL;DR a class marked as @dto cannot extend another @dto class.`)}if(!1){let r=console.error.bind(console),e=console.info.bind(console),n=console.log.bind(console),o=console.warn.bind(console),i=u=>(...l)=>{for(let c=l.length-1;c>=0;--c){let b=l[c];if(!s(b))continue;let de=ae(b);l.splice(c,1,`\u{1F4E6} ${de[m]}`,de.toJSON())}return u(...l)};console.error=i(r),console.info=i(e),console.log=i(n),console.warn=i(o)}var V,j,G=class{constructor(e,n){y(this,V);y(this,j);d(this,V,e),d(this,j,n)}get blob(){return h(this,V)}get name(){return h(this,j)}};V=new WeakMap,j=new WeakMap,G=P([q],G);var Q,v,$,J,X,_=class{constructor(e,n,o,i,u){y(this,Q);y(this,v);y(this,$);y(this,J);y(this,X);d(this,Q,e),d(this,v,n),d(this,$,o),d(this,J,i),d(this,X,u)}get items(){return h(this,Q)}get page(){return h(this,v)}get pageSize(){return h(this,$)}get pages(){return h(this,J)}get totalItems(){return h(this,X)}};Q=new WeakMap,v=new WeakMap,$=new WeakMap,J=new WeakMap,X=new WeakMap,_=P([q],_);var A=class{static parsePaginatedAdapter(e,n){return new _(e.items.map(n),e.page,e.pageSize,e.pages,e.totalItems)}static parseFileNameFromContentDispositionHeader(e){if(!e.startsWith("attachment"))return`download-${U()}`;let o=/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/.exec(e);return(o?.length||0)<2?`download-${U()}`:o[1].replaceAll("'","").replaceAll('"',"").replaceAll("/","-").replaceAll(":","-")}};A=P([oe],A);var Oe=(c=>(c.Delete="DELETE",c.Get="GET",c.Head="HEAD",c.Options="OPTIONS",c.Patch="PATCH",c.Post="POST",c.Put="PUT",c))(Oe||{});var qe=(t=>(t[t.Continue=100]="Continue",t[t.SwitchingProtocols=101]="SwitchingProtocols",t[t.Processing=102]="Processing",t[t.Ok=200]="Ok",t[t.Created=201]="Created",t[t.Accepted=202]="Accepted",t[t.NonAuthoritativeInformation=203]="NonAuthoritativeInformation",t[t.NoContent=204]="NoContent",t[t.ResetContent=205]="ResetContent",t[t.PartialContent=206]="PartialContent",t[t.MultiStatus=207]="MultiStatus",t[t.AlreadyReported=208]="AlreadyReported",t[t.ImUsed=226]="ImUsed",t[t.MultipleChoices=300]="MultipleChoices",t[t.MovedPermanently=301]="MovedPermanently",t[t.Found=302]="Found",t[t.SeeOther=303]="SeeOther",t[t.NotModified=304]="NotModified",t[t.UseProxy=305]="UseProxy",t[t.SwitchProxy=306]="SwitchProxy",t[t.TemporaryRedirect=307]="TemporaryRedirect",t[t.PermanentRedirect=308]="PermanentRedirect",t[t.BadRequest=400]="BadRequest",t[t.Unauthorized=401]="Unauthorized",t[t.PaymentRequired=402]="PaymentRequired",t[t.Forbidden=403]="Forbidden",t[t.NotFound=404]="NotFound",t[t.MethodNotAllowed=405]="MethodNotAllowed",t[t.NotAcceptable=406]="NotAcceptable",t[t.ProxyAuthenticationRequired=407]="ProxyAuthenticationRequired",t[t.RequestTimeout=408]="RequestTimeout",t[t.Conflict=409]="Conflict",t[t.Gone=410]="Gone",t[t.LengthRequired=411]="LengthRequired",t[t.PreconditionFailed=412]="PreconditionFailed",t[t.PayloadTooLarge=413]="PayloadTooLarge",t[t.UriTooLong=414]="UriTooLong",t[t.UnsupportedMediaType=415]="UnsupportedMediaType",t[t.RangeNotSatisfiable=416]="RangeNotSatisfiable",t[t.ExpectationFailed=417]="ExpectationFailed",t[t.IAmATeapot=418]="IAmATeapot",t[t.MisdirectedRequest=421]="MisdirectedRequest",t[t.UnprocessableEntity=422]="UnprocessableEntity",t[t.Locked=423]="Locked",t[t.FailedDependency=424]="FailedDependency",t[t.UpgradeRequired=426]="UpgradeRequired",t[t.PreconditionRequired=428]="PreconditionRequired",t[t.TooManyRequests=429]="TooManyRequests",t[t.RequestHeaderFieldsTooLarge=431]="RequestHeaderFieldsTooLarge",t[t.UnavailableForLegalReasons=451]="UnavailableForLegalReasons",t[t.InternalServerError=500]="InternalServerError",t[t.NotImplemented=501]="NotImplemented",t[t.BadGateway=502]="BadGateway",t[t.ServiceUnavailable=503]="ServiceUnavailable",t[t.GatewayTimeout=504]="GatewayTimeout",t[t.HttpVersionNotSupported=505]="HttpVersionNotSupported",t[t.VariantAlsoNegotiates=506]="VariantAlsoNegotiates",t[t.InsufficientStorage=507]="InsufficientStorage",t[t.LoopDetected=508]="LoopDetected",t[t.NotExtended=510]="NotExtended",t[t.NetworkAuthenticationRequired=511]="NetworkAuthenticationRequired",t))(qe||{});var x=class{get data(){return this.#e}get headers(){return this.#r.headers}get ok(){return this.statusCode>=200&&this.statusCode<300}get response(){return this.#r}get statusCode(){return this.#r.status}#e;#r;constructor(e,n){this.#e=e,this.#r=n}};var he=class{request(e,n){return new W(e,n)}};var Z=class r{get authToken(){return this.#e}set authToken(e){this.#e=e}get baseUrl(){return this.#n}get timezone(){return this.#r}set timezone(e){this.#r=e}#e;#r;#n;constructor(e,n){this.#e=e,this.#n=n,this.#r=Intl.DateTimeFormat().resolvedOptions().timeZone}onException(e,n){}onRequest(e){return e}onResponse(e){}static get instance(){if(r.#t===null)throw new Error("There is currently no HttpClient instance registered. Register one using the HttpClient.register() function.");return r.#t}static#t=null;static register(e){r.#t=e}};var ye=class r{#e;constructor(){this.#e=new URLSearchParams}build(){return this.#e.toString()}append(e,n){return this.#r(this.#e.append.bind(this.#e),e,n)}appendArray(e,n){return n==null?this:(n.forEach(o=>this.append(e,o)),this)}delete(e){return this.#e.delete(e),this}get(e){return this.#e.get(e)}getAll(e){return this.#e.getAll(e)}has(e){return this.#e.has(e)}set(e,n){return this.#r(this.#e.set.bind(this.#e),e,n)}#r(e,n,o){if(!o&&o!==!1)return this;switch(typeof o){case"boolean":e(n,o?"true":"false");break;case"number":e(n,o.toString(10));break;case"string":e(n,o);break}return this}static builder(){return new r}};var W=class r{get client(){return this.#e}get options(){return this.#n}get path(){return this.#r}set path(e){this.#r=e}get query(){return this.#t}set query(e){this.#t=e}#e;#r;#n={};#t=null;constructor(e,n){this.#e=n??Z.instance,this.#n.cache="no-cache",this.#n.method="GET",this.#r=e}bearerToken(e){return e=e??this.#e.authToken,e?this.header("Authorization",`Bearer ${e}`):(this.#n.headers&&"Authorization"in this.#n.headers&&delete this.#n.headers.Authorization,this)}body(e,n="application/octet-stream"){return e instanceof FormData?n=null:(Array.isArray(e)||typeof e=="object")&&(e=JSON.stringify(e),n="application/json"),this.#n.body=e,n!==null?this.header("Content-Type",n):this}asOrganization(e){return this.header("X-Organization-Id",e)}header(e,n){return this.#n.headers=this.#n.headers||{},this.#n.headers[e]=n,this}method(e){return this.#n.method=e,this}queryString(e){return this.#t=e,this}async fetch(){return this.#i().then(e=>e.json())}async fetchBlob(){let e=await this.#i();if(e.status!==200){let o=await e.json();throw"code"in o&&"error"in o&&"error_description"in o?new D(o.code,o.error,o.error_description,e.status):new D(-1,"failed_without_info","Request failed without any information from the backend.",e.status)}let n=e.headers.has("content-disposition")?A.parseFileNameFromContentDispositionHeader(e.headers.get("content-disposition")):`download-${U()}`;return new G(await e.blob(),n)}async runAdapter(e){let{data:n,response:o}=await this.#o();return new x(e(n),o)}async runArrayAdapter(e){return this.runAdapter(n=>n.map(e))}async runEmpty(){return await this.#o()}async runPaginatedAdapter(e){return this.runAdapter(n=>A.parsePaginatedAdapter(n,e))}async runData(){return await this.#o()}async runDataKey(e){let{data:n,response:o}=await this.#o();return new x(n[e],o)}async runStatusCode(){return(await this.#o()).statusCode}async#i(){let e=this.#e.onRequest(this),n=e.path;return e.query!==null&&(n+=`?${e.query.build()}`),await fetch(e.client.baseUrl+n,e.options).catch(o=>{throw this.#e.onException(o,e),o})}async#o(){return await this.#i().then(r.#s).then(e=>(this.#e.onResponse(e),e))}static async#s(e){if(e.status===204)return new x(null,e);if(e.headers.has("content-type")&&e.headers.get("content-type").startsWith("application/json")){let o=await e.json();if("code"in o&&"error"in o&&"error_description"in o)throw new D(o.code,o.error,o.error_description,e.status);return new x(o,e)}if(e.status===401||e.status===403)return new x(null,e);if((await e.text()).length===0&&e.status>=200&&e.status<300)return new x(null,e);throw new D(-1,"not_a_json_response","The response was not a JSON response.",e.status)}};var z,S,C,H,D=class{constructor(e,n,o,i){y(this,z);y(this,S);y(this,C);y(this,H);d(this,z,e),d(this,S,n),d(this,C,o),d(this,H,i)}get code(){return h(this,z)}get error(){return h(this,S)}get errorDescription(){return h(this,C)}get statusCode(){return h(this,H)}};z=new WeakMap,S=new WeakMap,C=new WeakMap,H=new WeakMap,D=P([q],D);function ve(r){return r instanceof D}function $e(r){return r instanceof D&&(r=r.statusCode),r===403||r===401}export{B as ARGS,x as BaseResponse,he as BaseService,G as BlobResponse,A as HttpAdapter,Z as HttpClient,Oe as HttpMethod,qe as HttpStatusCode,m as NAME,k as PROPERTIES,_ as Paginated,ye as QueryString,W as RequestBuilder,D as RequestError,oe as adapter,p as assertDto,Be as bound,ce as cloneDto,Le as debounce,q as dto,le as executeIfDtoDirtyAndMarkClean,s as isDto,ue as isDtoClean,O as isDtoDirty,ve as isRequestError,$e as isUnsanctionedRequest,K as markDtoClean,I as markDtoDirty,F as relateDtoTo,M as relateValueTo,E as trackDto,T as triggerDto};
2
- //# sourceMappingURL=basmilius.httpClient.js.map
2
+ //# sourceMappingURL=basmilius.http.client.js.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@basmilius/http-client",
3
3
  "description": "Http client for Vue projects.",
4
- "version": "1.2.2",
4
+ "version": "1.3.0",
5
5
  "engines": {
6
6
  "node": ">=22"
7
7
  },
@@ -9,13 +9,13 @@
9
9
  "dist/*"
10
10
  ],
11
11
  "type": "module",
12
- "main": "./dist/basmilius.httpClient.js",
13
- "module": "./dist/basmilius.httpClient.js",
12
+ "main": "./dist/basmilius.http.client.js",
13
+ "module": "./dist/basmilius.http.client.js",
14
14
  "types": "./dist/index.d.ts",
15
15
  "exports": {
16
16
  ".": {
17
17
  "types": "./dist/index.d.ts",
18
- "default": "./dist/basmilius.httpClient.js"
18
+ "default": "./dist/basmilius.http.client.js"
19
19
  }
20
20
  },
21
21
  "sideEffects": false,
@@ -39,7 +39,7 @@
39
39
  "scripts": {
40
40
  "build": "pnpm esbuild && pnpm gentypes",
41
41
  "dev": "pnpm esbuild && concurrently -k -c magenta,cyan,green -n code,types,alias 'pnpm esbuild:watch' 'tsc -w' 'tsc-alias -w'",
42
- "esbuild": "esbuild src/index.ts --bundle --minify --sourcemap --target=esnext --external:luxon --external:vue --platform=browser --format=esm --outfile=dist/basmilius.httpClient.js",
42
+ "esbuild": "esbuild src/index.ts --bundle --minify --sourcemap --target=esnext --external:luxon --external:vue --platform=browser --format=esm --outfile=dist/basmilius.http.client.js",
43
43
  "esbuild:watch": "pnpm esbuild --watch",
44
44
  "gentypes": "tsc && tsc-alias"
45
45
  }