@frui.ts/apiclient
Advanced tools
Comparing version 1.0.0-beta.6 to 1.0.0-rc.1
@@ -1,7 +0,7 @@ | ||
var C = Object.defineProperty; | ||
var j = (s, t, e) => t in s ? C(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e; | ||
var n = (s, t, e) => (j(s, typeof t != "symbol" ? t + "" : t, e), e); | ||
import { bind as b } from "@frui.ts/helpers"; | ||
import { stringify as m } from "qs"; | ||
class c extends Error { | ||
var o = Object.defineProperty; | ||
var c = (s, t, e) => t in s ? o(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e; | ||
var n = (s, t, e) => (c(s, typeof t != "symbol" ? t + "" : t, e), e); | ||
import { bind as d } from "@frui.ts/helpers"; | ||
import { stringify as C } from "qs"; | ||
class p extends Error { | ||
constructor(e, r) { | ||
@@ -13,4 +13,4 @@ super(e.statusText); | ||
} | ||
const y = "application/json"; | ||
function V(s, t) { | ||
const j = "application/json"; | ||
function y(s, t) { | ||
return { | ||
@@ -24,3 +24,3 @@ ...t, | ||
} | ||
async function w(s) { | ||
async function b(s) { | ||
if (s.status >= 200 && s.status < 300) | ||
@@ -32,7 +32,7 @@ return s; | ||
} catch { | ||
throw new c(s); | ||
throw new p(s); | ||
} | ||
throw new c(s, t); | ||
throw new p(s, t); | ||
} | ||
class F { | ||
class T { | ||
constructor(t) { | ||
@@ -43,31 +43,39 @@ n(this, "fetchFunction"); | ||
n(this, "appendContentHeader"); | ||
var r, h, l, u; | ||
this.fetchFunction = (r = t == null ? void 0 : t.fetchFunction) != null ? r : b(window.fetch, window), this.serializer = (h = t == null ? void 0 : t.serializer) != null ? h : JSON.stringify, this.middleware = (l = t == null ? void 0 : t.middleware) != null ? l : w; | ||
const e = (u = t == null ? void 0 : t.contentType) != null ? u : y; | ||
this.appendContentHeader = (d) => V(e, d); | ||
this.fetchFunction = (t == null ? void 0 : t.fetchFunction) ?? d(window.fetch, window), this.serializer = (t == null ? void 0 : t.serializer) ?? JSON.stringify, this.middleware = (t == null ? void 0 : t.middleware) ?? b; | ||
const e = (t == null ? void 0 : t.contentType) ?? j; | ||
this.appendContentHeader = (r) => y(e, r); | ||
} | ||
/** Sends a HTTP GET request */ | ||
get(t, e) { | ||
return this.fetchFunction(t, { ...e, method: "GET" }).then(this.middleware); | ||
} | ||
/** Sends the provided body as a HTTP POST request */ | ||
post(t, e, r) { | ||
return this.fetchFunction(t, { ...r, method: "POST", body: e }).then(this.middleware); | ||
} | ||
/** Serializes the provided content and sends it as a HTTP POST request */ | ||
postObject(t, e, r) { | ||
return this.post(t, this.serializer(e), this.appendContentHeader(r)); | ||
} | ||
/** Sends the provided body as a HTTP PUT request */ | ||
put(t, e, r) { | ||
return this.fetchFunction(t, { ...r, method: "PUT", body: e }).then(this.middleware); | ||
} | ||
/** Serializes the provided content and sends it as a HTTP PUT request */ | ||
putObject(t, e, r) { | ||
return this.put(t, this.serializer(e), this.appendContentHeader(r)); | ||
} | ||
/** Sends the provided body as a HTTP PATCH request */ | ||
patch(t, e, r) { | ||
return this.fetchFunction(t, { ...r, method: "PATCH", body: e }).then(this.middleware); | ||
} | ||
/** Serializes the provided content and sends it as a HTTP PATCH request */ | ||
patchObject(t, e, r) { | ||
return this.patch(t, this.serializer(e), this.appendContentHeader(r)); | ||
} | ||
/** Sends the provided body as a HTTP DELETE request */ | ||
delete(t, e, r) { | ||
return this.fetchFunction(t, { ...r, method: "DELETE", body: e }).then(this.middleware); | ||
} | ||
/** Serializes the provided content and sends it as a HTTP DELETE request */ | ||
deleteObject(t, e, r) { | ||
@@ -77,3 +85,3 @@ return this.delete(t, this.serializer(e), this.appendContentHeader(r)); | ||
} | ||
const o = /\/+$/g, T = { | ||
const l = /\/+$/g, m = { | ||
json: "application/json,text/json" | ||
@@ -90,11 +98,11 @@ }; | ||
} | ||
function H(s, ...t) { | ||
const e = s.replace(o, ""); | ||
function z(s, ...t) { | ||
const e = s.replace(l, ""); | ||
return t.length ? `${e}/${t.join("/")}` : e; | ||
} | ||
const p = class { | ||
const a = class { | ||
constructor(t, e, r) { | ||
n(this, "urlValue"); | ||
n(this, "queryStringOptions"); | ||
n(this, "objectContentType", T.json); | ||
n(this, "objectContentType", m.json); | ||
n(this, "objectDeserializer", (t) => t.json()); | ||
@@ -107,3 +115,3 @@ this.apiConnector = t, this.baseUrl = e, this.params = r, this.reset(); | ||
reset() { | ||
this.urlValue = this.baseUrl.replace(o, ""); | ||
this.urlValue = this.baseUrl.replace(l, ""); | ||
} | ||
@@ -164,4 +172,3 @@ path(t) { | ||
getQueryString(t, e) { | ||
var r; | ||
return m(t, (r = e != null ? e : this.queryStringOptions) != null ? r : p.DefaultQueryStringOptions); | ||
return C(t, e ?? this.queryStringOptions ?? a.DefaultQueryStringOptions); | ||
} | ||
@@ -171,19 +178,19 @@ appendQuery(t, e, r) { | ||
return t; | ||
const h = typeof e == "string" ? e : this.getQueryString(e, r); | ||
return `${t}?${h}`; | ||
const u = typeof e == "string" ? e : this.getQueryString(e, r); | ||
return `${t}?${u}`; | ||
} | ||
}; | ||
let a = p; | ||
n(a, "DefaultQueryStringOptions", { skipNulls: !0 }); | ||
let h = a; | ||
n(h, "DefaultQueryStringOptions", { skipNulls: !0 }); | ||
export { | ||
T as ContentTypes, | ||
F as FetchApiConnector, | ||
c as FetchError, | ||
a as RestRequestBuilder, | ||
m as ContentTypes, | ||
T as FetchApiConnector, | ||
p as FetchError, | ||
h as RestRequestBuilder, | ||
i as appendAcceptHeader, | ||
V as appendContentTypeHeader, | ||
H as appendUrl, | ||
w as handleErrorStatusMiddleware, | ||
y as jsonContentType | ||
y as appendContentTypeHeader, | ||
z as appendUrl, | ||
b as handleErrorStatusMiddleware, | ||
j as jsonContentType | ||
}; | ||
//# sourceMappingURL=fruits-apiclient.es.js.map |
@@ -1,2 +0,2 @@ | ||
(function(s,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("@frui.ts/helpers"),require("qs")):typeof define=="function"&&define.amd?define(["exports","@frui.ts/helpers","qs"],i):(s=typeof globalThis<"u"?globalThis:s||self,i(s["fruits-apiclient"]={},s.helpers,s.qs))})(this,function(s,i,a){"use strict";var O=Object.defineProperty;var z=(s,i,a)=>i in s?O(s,i,{enumerable:!0,configurable:!0,writable:!0,value:a}):s[i]=a;var h=(s,i,a)=>(z(s,typeof i!="symbol"?i+"":i,a),a);class c extends Error{constructor(e,r){super(e.statusText);h(this,"handled",!1);this.response=e,this.content=r}}const d="application/json";function C(n,t){return{...t,headers:{...t==null?void 0:t.headers,"Content-Type":n}}}async function j(n){if(n.status>=200&&n.status<300)return n;let t;try{t=await n.json()}catch{throw new c(n)}throw new c(n,t)}class w{constructor(t){h(this,"fetchFunction");h(this,"serializer");h(this,"middleware");h(this,"appendContentHeader");var r,l,m,T;this.fetchFunction=(r=t==null?void 0:t.fetchFunction)!=null?r:i.bind(window.fetch,window),this.serializer=(l=t==null?void 0:t.serializer)!=null?l:JSON.stringify,this.middleware=(m=t==null?void 0:t.middleware)!=null?m:j;const e=(T=t==null?void 0:t.contentType)!=null?T:d;this.appendContentHeader=f=>C(e,f)}get(t,e){return this.fetchFunction(t,{...e,method:"GET"}).then(this.middleware)}post(t,e,r){return this.fetchFunction(t,{...r,method:"POST",body:e}).then(this.middleware)}postObject(t,e,r){return this.post(t,this.serializer(e),this.appendContentHeader(r))}put(t,e,r){return this.fetchFunction(t,{...r,method:"PUT",body:e}).then(this.middleware)}putObject(t,e,r){return this.put(t,this.serializer(e),this.appendContentHeader(r))}patch(t,e,r){return this.fetchFunction(t,{...r,method:"PATCH",body:e}).then(this.middleware)}patchObject(t,e,r){return this.patch(t,this.serializer(e),this.appendContentHeader(r))}delete(t,e,r){return this.fetchFunction(t,{...r,method:"DELETE",body:e}).then(this.middleware)}deleteObject(t,e,r){return this.delete(t,this.serializer(e),this.appendContentHeader(r))}}const y=/\/+$/g,b={json:"application/json,text/json"};function u(n,t){return{...n,headers:{...n==null?void 0:n.headers,Accept:t}}}function V(n,...t){const e=n.replace(y,"");return t.length?`${e}/${t.join("/")}`:e}const o=class{constructor(t,e,r){h(this,"urlValue");h(this,"queryStringOptions");h(this,"objectContentType",b.json);h(this,"objectDeserializer",t=>t.json());this.apiConnector=t,this.baseUrl=e,this.params=r,this.reset()}get url(){return this.urlValue}reset(){this.urlValue=this.baseUrl.replace(y,"")}path(t){return this.urlValue+="/"+t,this}all(t){return this.urlValue+="/"+t,this}one(t,e){return this.urlValue+="/"+t,e!==void 0&&(this.urlValue+=`/${e}`),this}get(t){const e=this.appendQuery(this.urlValue,t),r=u(this.params,this.objectContentType);return this.apiConnector.get(e,r).then(this.objectDeserializer)}getRaw(t){const e=this.appendQuery(this.urlValue,t);return this.apiConnector.get(e,this.params)}post(t){const e=u(this.params,this.objectContentType);return this.apiConnector.postObject(this.urlValue,t,e).then(this.objectDeserializer)}postOnly(t){return this.apiConnector.postObject(this.urlValue,t,this.params)}postData(t){return this.apiConnector.post(this.urlValue,t,this.params)}put(t){const e=u(this.params,this.objectContentType);return this.apiConnector.putObject(this.urlValue,t,e).then(this.objectDeserializer)}putOnly(t){return this.apiConnector.putObject(this.urlValue,t,this.params)}putData(t){return this.apiConnector.put(this.urlValue,t,this.params)}patch(t){const e=u(this.params,this.objectContentType);return this.apiConnector.patchObject(this.urlValue,t,e).then(this.objectDeserializer)}patchOnly(t){return this.apiConnector.patchObject(this.urlValue,t,this.params)}patchData(t){return this.apiConnector.patch(this.urlValue,t,this.params)}delete(t){return t?this.apiConnector.deleteObject(this.urlValue,t,this.params):this.apiConnector.delete(this.urlValue,void 0,this.params)}withBaseUrl(t){return this.urlValue=t,this}getQueryString(t,e){var r;return a.stringify(t,(r=e!=null?e:this.queryStringOptions)!=null?r:o.DefaultQueryStringOptions)}appendQuery(t,e,r){if(!e)return t;const l=typeof e=="string"?e:this.getQueryString(e,r);return`${t}?${l}`}};let p=o;h(p,"DefaultQueryStringOptions",{skipNulls:!0}),s.ContentTypes=b,s.FetchApiConnector=w,s.FetchError=c,s.RestRequestBuilder=p,s.appendAcceptHeader=u,s.appendContentTypeHeader=C,s.appendUrl=V,s.handleErrorStatusMiddleware=j,s.jsonContentType=d,Object.defineProperties(s,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); | ||
(function(s,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("@frui.ts/helpers"),require("qs")):typeof define=="function"&&define.amd?define(["exports","@frui.ts/helpers","qs"],i):(s=typeof globalThis<"u"?globalThis:s||self,i(s["fruits-apiclient"]={},s.helpers,s.qs))})(this,function(s,i,a){"use strict";var w=Object.defineProperty;var O=(s,i,a)=>i in s?w(s,i,{enumerable:!0,configurable:!0,writable:!0,value:a}):s[i]=a;var h=(s,i,a)=>(O(s,typeof i!="symbol"?i+"":i,a),a);class l extends Error{constructor(e,r){super(e.statusText);h(this,"handled",!1);this.response=e,this.content=r}}const o="application/json";function d(n,t){return{...t,headers:{...t==null?void 0:t.headers,"Content-Type":n}}}async function C(n){if(n.status>=200&&n.status<300)return n;let t;try{t=await n.json()}catch{throw new l(n)}throw new l(n,t)}class b{constructor(t){h(this,"fetchFunction");h(this,"serializer");h(this,"middleware");h(this,"appendContentHeader");this.fetchFunction=(t==null?void 0:t.fetchFunction)??i.bind(window.fetch,window),this.serializer=(t==null?void 0:t.serializer)??JSON.stringify,this.middleware=(t==null?void 0:t.middleware)??C;const e=(t==null?void 0:t.contentType)??o;this.appendContentHeader=r=>d(e,r)}get(t,e){return this.fetchFunction(t,{...e,method:"GET"}).then(this.middleware)}post(t,e,r){return this.fetchFunction(t,{...r,method:"POST",body:e}).then(this.middleware)}postObject(t,e,r){return this.post(t,this.serializer(e),this.appendContentHeader(r))}put(t,e,r){return this.fetchFunction(t,{...r,method:"PUT",body:e}).then(this.middleware)}putObject(t,e,r){return this.put(t,this.serializer(e),this.appendContentHeader(r))}patch(t,e,r){return this.fetchFunction(t,{...r,method:"PATCH",body:e}).then(this.middleware)}patchObject(t,e,r){return this.patch(t,this.serializer(e),this.appendContentHeader(r))}delete(t,e,r){return this.fetchFunction(t,{...r,method:"DELETE",body:e}).then(this.middleware)}deleteObject(t,e,r){return this.delete(t,this.serializer(e),this.appendContentHeader(r))}}const j=/\/+$/g,y={json:"application/json,text/json"};function u(n,t){return{...n,headers:{...n==null?void 0:n.headers,Accept:t}}}function m(n,...t){const e=n.replace(j,"");return t.length?`${e}/${t.join("/")}`:e}const c=class{constructor(t,e,r){h(this,"urlValue");h(this,"queryStringOptions");h(this,"objectContentType",y.json);h(this,"objectDeserializer",t=>t.json());this.apiConnector=t,this.baseUrl=e,this.params=r,this.reset()}get url(){return this.urlValue}reset(){this.urlValue=this.baseUrl.replace(j,"")}path(t){return this.urlValue+="/"+t,this}all(t){return this.urlValue+="/"+t,this}one(t,e){return this.urlValue+="/"+t,e!==void 0&&(this.urlValue+=`/${e}`),this}get(t){const e=this.appendQuery(this.urlValue,t),r=u(this.params,this.objectContentType);return this.apiConnector.get(e,r).then(this.objectDeserializer)}getRaw(t){const e=this.appendQuery(this.urlValue,t);return this.apiConnector.get(e,this.params)}post(t){const e=u(this.params,this.objectContentType);return this.apiConnector.postObject(this.urlValue,t,e).then(this.objectDeserializer)}postOnly(t){return this.apiConnector.postObject(this.urlValue,t,this.params)}postData(t){return this.apiConnector.post(this.urlValue,t,this.params)}put(t){const e=u(this.params,this.objectContentType);return this.apiConnector.putObject(this.urlValue,t,e).then(this.objectDeserializer)}putOnly(t){return this.apiConnector.putObject(this.urlValue,t,this.params)}putData(t){return this.apiConnector.put(this.urlValue,t,this.params)}patch(t){const e=u(this.params,this.objectContentType);return this.apiConnector.patchObject(this.urlValue,t,e).then(this.objectDeserializer)}patchOnly(t){return this.apiConnector.patchObject(this.urlValue,t,this.params)}patchData(t){return this.apiConnector.patch(this.urlValue,t,this.params)}delete(t){return t?this.apiConnector.deleteObject(this.urlValue,t,this.params):this.apiConnector.delete(this.urlValue,void 0,this.params)}withBaseUrl(t){return this.urlValue=t,this}getQueryString(t,e){return a.stringify(t,e??this.queryStringOptions??c.DefaultQueryStringOptions)}appendQuery(t,e,r){if(!e)return t;const T=typeof e=="string"?e:this.getQueryString(e,r);return`${t}?${T}`}};let p=c;h(p,"DefaultQueryStringOptions",{skipNulls:!0}),s.ContentTypes=y,s.FetchApiConnector=b,s.FetchError=l,s.RestRequestBuilder=p,s.appendAcceptHeader=u,s.appendContentTypeHeader=d,s.appendUrl=m,s.handleErrorStatusMiddleware=C,s.jsonContentType=o,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})}); | ||
//# sourceMappingURL=fruits-apiclient.umd.js.map |
@@ -6,3 +6,3 @@ { | ||
}, | ||
"version": "1.0.0-beta.6", | ||
"version": "1.0.0-rc.1", | ||
"description": "Frui.ts helpers for HTTP communication", | ||
@@ -40,4 +40,4 @@ "keywords": [ | ||
"dependencies": { | ||
"@frui.ts/helpers": "^1.0.0-beta.6", | ||
"qs": "^6.11.0" | ||
"@frui.ts/helpers": "^1.0.0-rc.1", | ||
"qs": "^6.11.2" | ||
}, | ||
@@ -47,3 +47,3 @@ "devDependencies": { | ||
}, | ||
"gitHead": "adf52b1d60660fc686182547cca34af079bdecf4" | ||
"gitHead": "c17e77c7246207827d09d34cadbb54b07ebbd82e" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
50132
294
Updated@frui.ts/helpers@^1.0.0-rc.1
Updatedqs@^6.11.2