Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@frui.ts/apiclient

Package Overview
Dependencies
Maintainers
5
Versions
78
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@frui.ts/apiclient - npm Package Compare versions

Comparing version 1.0.0-beta.1 to 1.0.0-beta.2

246

dist/fruits-apiclient.es.js

@@ -1,95 +0,96 @@

import { bind } from "@frui.ts/helpers";
import { stringify } from "qs";
class FetchError extends Error {
constructor(response, content) {
super(response.statusText);
this.response = response;
this.content = content;
this.handled = false;
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 {
constructor(e, r) {
super(e.statusText);
n(this, "handled", !1);
this.response = e, this.content = r;
}
}
const jsonContentType = "application/json";
function appendContentTypeHeader(contentType, params) {
const y = "application/json";
function V(s, t) {
return {
...params,
...t,
headers: {
...params == null ? void 0 : params.headers,
"Content-Type": contentType
...t == null ? void 0 : t.headers,
"Content-Type": s
}
};
}
async function handleErrorStatusMiddleware(response) {
if (response.status >= 200 && response.status < 300) {
return response;
}
let content;
async function w(s) {
if (s.status >= 200 && s.status < 300)
return s;
let t;
try {
content = await response.json();
t = await s.json();
} catch {
throw new FetchError(response);
throw new c(s);
}
throw new FetchError(response, content);
throw new c(s, t);
}
class FetchApiConnector {
constructor(configuration) {
var _a, _b, _c, _d;
this.fetchFunction = (_a = configuration == null ? void 0 : configuration.fetchFunction) != null ? _a : bind(window.fetch, window);
this.serializer = (_b = configuration == null ? void 0 : configuration.serializer) != null ? _b : JSON.stringify;
this.middleware = (_c = configuration == null ? void 0 : configuration.middleware) != null ? _c : handleErrorStatusMiddleware;
const contentType = (_d = configuration == null ? void 0 : configuration.contentType) != null ? _d : jsonContentType;
this.appendContentHeader = (params) => appendContentTypeHeader(contentType, params);
class F {
constructor(t) {
n(this, "fetchFunction");
n(this, "serializer");
n(this, "middleware");
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);
}
get(url, params) {
return this.fetchFunction(url, { ...params, method: "GET" }).then(this.middleware);
get(t, e) {
return this.fetchFunction(t, { ...e, method: "GET" }).then(this.middleware);
}
post(url, body, params) {
return this.fetchFunction(url, { ...params, method: "POST", body }).then(this.middleware);
post(t, e, r) {
return this.fetchFunction(t, { ...r, method: "POST", body: e }).then(this.middleware);
}
postObject(url, content, params) {
return this.post(url, this.serializer(content), this.appendContentHeader(params));
postObject(t, e, r) {
return this.post(t, this.serializer(e), this.appendContentHeader(r));
}
put(url, body, params) {
return this.fetchFunction(url, { ...params, method: "PUT", body }).then(this.middleware);
put(t, e, r) {
return this.fetchFunction(t, { ...r, method: "PUT", body: e }).then(this.middleware);
}
putObject(url, content, params) {
return this.put(url, this.serializer(content), this.appendContentHeader(params));
putObject(t, e, r) {
return this.put(t, this.serializer(e), this.appendContentHeader(r));
}
patch(url, body, params) {
return this.fetchFunction(url, { ...params, method: "PATCH", body }).then(this.middleware);
patch(t, e, r) {
return this.fetchFunction(t, { ...r, method: "PATCH", body: e }).then(this.middleware);
}
patchObject(url, content, params) {
return this.patch(url, this.serializer(content), this.appendContentHeader(params));
patchObject(t, e, r) {
return this.patch(t, this.serializer(e), this.appendContentHeader(r));
}
delete(url, body, params) {
return this.fetchFunction(url, { ...params, method: "DELETE", body }).then(this.middleware);
delete(t, e, r) {
return this.fetchFunction(t, { ...r, method: "DELETE", body: e }).then(this.middleware);
}
deleteObject(url, content, params) {
return this.delete(url, this.serializer(content), this.appendContentHeader(params));
deleteObject(t, e, r) {
return this.delete(t, this.serializer(e), this.appendContentHeader(r));
}
}
const cleanupRegex = /\/+$/g;
const ContentTypes = {
const o = /\/+$/g, T = {
json: "application/json,text/json"
};
function appendAcceptHeader(params, acceptContentType) {
function i(s, t) {
return {
...params,
...s,
headers: {
...params == null ? void 0 : params.headers,
Accept: acceptContentType
...s == null ? void 0 : s.headers,
Accept: t
}
};
}
function appendUrl(base, ...segments) {
const basePath = base.replace(cleanupRegex, "");
return segments.length ? `${basePath}/${segments.join("/")}` : basePath;
function H(s, ...t) {
const e = s.replace(o, "");
return t.length ? `${e}/${t.join("/")}` : e;
}
const _RestRequestBuilder = class {
constructor(apiConnector, baseUrl, params) {
this.apiConnector = apiConnector;
this.baseUrl = baseUrl;
this.params = params;
this.objectContentType = ContentTypes.json;
this.objectDeserializer = (x) => x.json();
this.reset();
const p = class {
constructor(t, e, r) {
n(this, "urlValue");
n(this, "queryStringOptions");
n(this, "objectContentType", T.json);
n(this, "objectDeserializer", (t) => t.json());
this.apiConnector = t, this.baseUrl = e, this.params = r, this.reset();
}

@@ -100,80 +101,81 @@ get url() {

reset() {
this.urlValue = this.baseUrl.replace(cleanupRegex, "");
this.urlValue = this.baseUrl.replace(o, "");
}
path(path) {
this.urlValue += "/" + path;
return this;
path(t) {
return this.urlValue += "/" + t, this;
}
all(path) {
this.urlValue += "/" + path;
return this;
all(t) {
return this.urlValue += "/" + t, this;
}
one(path, id) {
this.urlValue += "/" + path;
if (id !== void 0) {
this.urlValue += `/${id}`;
}
return this;
one(t, e) {
return this.urlValue += "/" + t, e !== void 0 && (this.urlValue += `/${e}`), this;
}
get(queryParams) {
const requestUrl = this.appendQuery(this.urlValue, queryParams);
const params = appendAcceptHeader(this.params, this.objectContentType);
return this.apiConnector.get(requestUrl, params).then(this.objectDeserializer);
get(t) {
const e = this.appendQuery(this.urlValue, t), r = i(this.params, this.objectContentType);
return this.apiConnector.get(e, r).then(this.objectDeserializer);
}
getRaw(queryParams) {
const requestUrl = this.appendQuery(this.urlValue, queryParams);
return this.apiConnector.get(requestUrl, this.params);
getRaw(t) {
const e = this.appendQuery(this.urlValue, t);
return this.apiConnector.get(e, this.params);
}
post(content) {
const params = appendAcceptHeader(this.params, this.objectContentType);
return this.apiConnector.postObject(this.urlValue, content, params).then(this.objectDeserializer);
post(t) {
const e = i(this.params, this.objectContentType);
return this.apiConnector.postObject(this.urlValue, t, e).then(this.objectDeserializer);
}
postOnly(content) {
return this.apiConnector.postObject(this.urlValue, content, this.params);
postOnly(t) {
return this.apiConnector.postObject(this.urlValue, t, this.params);
}
postData(data) {
return this.apiConnector.post(this.urlValue, data, this.params);
postData(t) {
return this.apiConnector.post(this.urlValue, t, this.params);
}
put(content) {
const params = appendAcceptHeader(this.params, this.objectContentType);
return this.apiConnector.putObject(this.urlValue, content, params).then(this.objectDeserializer);
put(t) {
const e = i(this.params, this.objectContentType);
return this.apiConnector.putObject(this.urlValue, t, e).then(this.objectDeserializer);
}
putOnly(content) {
return this.apiConnector.putObject(this.urlValue, content, this.params);
putOnly(t) {
return this.apiConnector.putObject(this.urlValue, t, this.params);
}
putData(data) {
return this.apiConnector.put(this.urlValue, data, this.params);
putData(t) {
return this.apiConnector.put(this.urlValue, t, this.params);
}
patch(content) {
const params = appendAcceptHeader(this.params, this.objectContentType);
return this.apiConnector.patchObject(this.urlValue, content, params).then(this.objectDeserializer);
patch(t) {
const e = i(this.params, this.objectContentType);
return this.apiConnector.patchObject(this.urlValue, t, e).then(this.objectDeserializer);
}
patchOnly(content) {
return this.apiConnector.patchObject(this.urlValue, content, this.params);
patchOnly(t) {
return this.apiConnector.patchObject(this.urlValue, t, this.params);
}
patchData(data) {
return this.apiConnector.patch(this.urlValue, data, this.params);
patchData(t) {
return this.apiConnector.patch(this.urlValue, t, this.params);
}
delete(content) {
return content ? this.apiConnector.deleteObject(this.urlValue, content, this.params) : this.apiConnector.delete(this.urlValue, void 0, this.params);
delete(t) {
return t ? this.apiConnector.deleteObject(this.urlValue, t, this.params) : this.apiConnector.delete(this.urlValue, void 0, this.params);
}
withBaseUrl(url) {
this.urlValue = url;
return this;
withBaseUrl(t) {
return this.urlValue = t, this;
}
getQueryString(query, queryStringOptions) {
var _a;
return stringify(query, (_a = queryStringOptions != null ? queryStringOptions : this.queryStringOptions) != null ? _a : _RestRequestBuilder.DefaultQueryStringOptions);
getQueryString(t, e) {
var r;
return m(t, (r = e != null ? e : this.queryStringOptions) != null ? r : p.DefaultQueryStringOptions);
}
appendQuery(url, query, queryStringOptions) {
if (!query) {
return url;
}
const queryString = typeof query === "string" ? query : this.getQueryString(query, queryStringOptions);
return `${url}?${queryString}`;
appendQuery(t, e, r) {
if (!e)
return t;
const h = typeof e == "string" ? e : this.getQueryString(e, r);
return `${t}?${h}`;
}
};
let RestRequestBuilder = _RestRequestBuilder;
RestRequestBuilder.DefaultQueryStringOptions = { skipNulls: true };
export { ContentTypes, FetchApiConnector, FetchError, RestRequestBuilder, appendAcceptHeader, appendContentTypeHeader, appendUrl, handleErrorStatusMiddleware, jsonContentType };
let a = p;
n(a, "DefaultQueryStringOptions", { skipNulls: !0 });
export {
T as ContentTypes,
F as FetchApiConnector,
c as FetchError,
a as RestRequestBuilder,
i as appendAcceptHeader,
V as appendContentTypeHeader,
H as appendUrl,
w as handleErrorStatusMiddleware,
y as jsonContentType
};
//# sourceMappingURL=fruits-apiclient.es.js.map

@@ -1,2 +0,2 @@

(function(n,i){typeof exports=="object"&&typeof module!="undefined"?i(exports,require("@frui.ts/helpers"),require("qs")):typeof define=="function"&&define.amd?define(["exports","@frui.ts/helpers","qs"],i):(n=typeof globalThis!="undefined"?globalThis:n||self,i(n["fruits-apiclient"]={},n.helpers,n.qs))})(this,function(n,i,T){"use strict";class a extends Error{constructor(t,s){super(t.statusText),this.response=t,this.content=s,this.handled=!1}}const u="application/json";function l(e,t){return{...t,headers:{...t==null?void 0:t.headers,"Content-Type":e}}}async function p(e){if(e.status>=200&&e.status<300)return e;let t;try{t=await e.json()}catch{throw new a(e)}throw new a(e,t)}class m{constructor(t){var r,j,y,b;this.fetchFunction=(r=t==null?void 0:t.fetchFunction)!=null?r:i.bind(window.fetch,window),this.serializer=(j=t==null?void 0:t.serializer)!=null?j:JSON.stringify,this.middleware=(y=t==null?void 0:t.middleware)!=null?y:p;const s=(b=t==null?void 0:t.contentType)!=null?b:u;this.appendContentHeader=V=>l(s,V)}get(t,s){return this.fetchFunction(t,{...s,method:"GET"}).then(this.middleware)}post(t,s,r){return this.fetchFunction(t,{...r,method:"POST",body:s}).then(this.middleware)}postObject(t,s,r){return this.post(t,this.serializer(s),this.appendContentHeader(r))}put(t,s,r){return this.fetchFunction(t,{...r,method:"PUT",body:s}).then(this.middleware)}putObject(t,s,r){return this.put(t,this.serializer(s),this.appendContentHeader(r))}patch(t,s,r){return this.fetchFunction(t,{...r,method:"PATCH",body:s}).then(this.middleware)}patchObject(t,s,r){return this.patch(t,this.serializer(s),this.appendContentHeader(r))}delete(t,s,r){return this.fetchFunction(t,{...r,method:"DELETE",body:s}).then(this.middleware)}deleteObject(t,s,r){return this.delete(t,this.serializer(s),this.appendContentHeader(r))}}const c=/\/+$/g,o={json:"application/json,text/json"};function h(e,t){return{...e,headers:{...e==null?void 0:e.headers,Accept:t}}}function w(e,...t){const s=e.replace(c,"");return t.length?`${s}/${t.join("/")}`:s}const d=class{constructor(e,t,s){this.apiConnector=e,this.baseUrl=t,this.params=s,this.objectContentType=o.json,this.objectDeserializer=r=>r.json(),this.reset()}get url(){return this.urlValue}reset(){this.urlValue=this.baseUrl.replace(c,"")}path(e){return this.urlValue+="/"+e,this}all(e){return this.urlValue+="/"+e,this}one(e,t){return this.urlValue+="/"+e,t!==void 0&&(this.urlValue+=`/${t}`),this}get(e){const t=this.appendQuery(this.urlValue,e),s=h(this.params,this.objectContentType);return this.apiConnector.get(t,s).then(this.objectDeserializer)}getRaw(e){const t=this.appendQuery(this.urlValue,e);return this.apiConnector.get(t,this.params)}post(e){const t=h(this.params,this.objectContentType);return this.apiConnector.postObject(this.urlValue,e,t).then(this.objectDeserializer)}postOnly(e){return this.apiConnector.postObject(this.urlValue,e,this.params)}postData(e){return this.apiConnector.post(this.urlValue,e,this.params)}put(e){const t=h(this.params,this.objectContentType);return this.apiConnector.putObject(this.urlValue,e,t).then(this.objectDeserializer)}putOnly(e){return this.apiConnector.putObject(this.urlValue,e,this.params)}putData(e){return this.apiConnector.put(this.urlValue,e,this.params)}patch(e){const t=h(this.params,this.objectContentType);return this.apiConnector.patchObject(this.urlValue,e,t).then(this.objectDeserializer)}patchOnly(e){return this.apiConnector.patchObject(this.urlValue,e,this.params)}patchData(e){return this.apiConnector.patch(this.urlValue,e,this.params)}delete(e){return e?this.apiConnector.deleteObject(this.urlValue,e,this.params):this.apiConnector.delete(this.urlValue,void 0,this.params)}withBaseUrl(e){return this.urlValue=e,this}getQueryString(e,t){var s;return T.stringify(e,(s=t!=null?t:this.queryStringOptions)!=null?s:d.DefaultQueryStringOptions)}appendQuery(e,t,s){if(!t)return e;const r=typeof t=="string"?t:this.getQueryString(t,s);return`${e}?${r}`}};let C=d;C.DefaultQueryStringOptions={skipNulls:!0},n.ContentTypes=o,n.FetchApiConnector=m,n.FetchError=a,n.RestRequestBuilder=C,n.appendAcceptHeader=h,n.appendContentTypeHeader=l,n.appendUrl=w,n.handleErrorStatusMiddleware=p,n.jsonContentType=u,Object.defineProperties(n,{__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 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"}})});
//# sourceMappingURL=fruits-apiclient.umd.js.map

@@ -6,3 +6,3 @@ {

},
"version": "1.0.0-beta.1",
"version": "1.0.0-beta.2",
"description": "Frui.ts helpers for HTTP communication",

@@ -40,3 +40,3 @@ "keywords": [

"dependencies": {
"@frui.ts/helpers": "^1.0.0-beta.1",
"@frui.ts/helpers": "^1.0.0-beta.2",
"qs": "^6.11.0"

@@ -47,3 +47,3 @@ },

},
"gitHead": "1a7897ad15a6a5be5adc7e67725f174a1dbc6394"
"gitHead": "5d7b8915490794c56dcad28698a47e6e2a904e4e"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc