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

fetchff

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fetchff - npm Package Compare versions

Comparing version 2.7.3 to 2.8.0

2

dist/browser/index.global.js

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

(()=>{async function P(o,e){if(!e)return o;let s=Array.isArray(e)?e:[e],t={...o};for(let n of s)t=await n(t);return t}async function C(o,e){if(!e)return o;let s=Array.isArray(e)?e:[e],t=o;for(let n of s)t=await n(t);return t}var b=class extends Error{response;request;config;status;statusText;constructor(e,s,t){super(e),this.name="ResponseError",this.message=e,this.status=t.status,this.statusText=t.statusText,this.request=s,this.config=s,this.response=t}};function F(o,e){if(!e)return o;if(e instanceof URLSearchParams){let a=e.toString();return o.includes("?")?`${o}&${a}`:a?`${o}?${a}`:o}let s=[],t=function(a,r){r=typeof r=="function"?r():r,r=r===null||r===void 0?"":r,s[s.length]=encodeURIComponent(a)+"="+encodeURIComponent(r)},n=(a,r)=>{let u,c,p;if(a)if(Array.isArray(r))for(u=0,c=r.length;u<c;u++)n(a+"["+(typeof r[u]=="object"&&r[u]?u:"")+"]",r[u]);else if(typeof r=="object"&&r!==null)for(p in r)n(a+"["+p+"]",r[p]);else t(a,r);else if(Array.isArray(r))for(u=0,c=r.length;u<c;u++)t(r[u].name,r[u].value);else for(p in r)n(p,r[p]);return s},i=n("",e).join("&").replace(/%5B%5D/g,"[]");return o.includes("?")?`${o}&${i}`:i?`${o}?${i}`:o}function E(o,e){return e?o.replace(/:[a-zA-Z]+/gi,s=>{let t=s.substring(1);return String(e[t]?e[t]:s)}):o}function x(o){if(o==null)return!1;let e=typeof o;if(e==="string"||e==="number"||e==="boolean")return!0;if(e!=="object")return!1;if(Array.isArray(o))return!0;if(Buffer.isBuffer(o)||o instanceof Date)return!1;let s=Object.getPrototypeOf(o);return s===Object.prototype||s===null||typeof o.toJSON=="function"}async function H(o){return new Promise(e=>setTimeout(()=>e(!0),o))}var w="application/json",f=class{requestInstance;baseURL="";timeout=3e4;rejectCancelled=!1;strategy="reject";method="get";flattenResponse=!1;defaultResponse=null;fetcher;logger;requestsQueue;retry={retries:0,delay:1e3,maxDelay:3e4,resetTimeout:!0,backoff:1.5,retryOn:[408,409,425,429,500,502,503,504],shouldRetry:async()=>!0};config={};constructor({fetcher:e=null,timeout:s=null,rejectCancelled:t=!1,strategy:n=null,flattenResponse:l=null,defaultResponse:i={},logger:a=null,...r}){this.fetcher=e,this.timeout=s??this.timeout,this.strategy=n||this.strategy,this.rejectCancelled=t||this.rejectCancelled,this.flattenResponse=l||this.flattenResponse,this.defaultResponse=i,this.logger=a||null,this.requestsQueue=new WeakMap,this.baseURL=r.baseURL||r.apiUrl||"",this.method=r.method||this.method,this.config=r,this.retry={...this.retry,...r.retry||{}},this.requestInstance=this.isCustomFetcher()?e.create({...r,baseURL:this.baseURL,timeout:this.timeout}):null}getInstance(){return this.requestInstance}buildConfig(e,s,t){let n=(t.method||this.method).toUpperCase(),l=n==="GET"||n==="HEAD",i=E(e,t.urlPathParams||this.config.urlPathParams),a=t.params||this.config.params,r=t.body||t.data||this.config.body||this.config.data,u=!!(s&&(l||r)),c;if(l||(c=r||s),this.isCustomFetcher())return{...t,method:n,url:i,params:u?s:a,data:c};let p=t.withCredentials||this.config.withCredentials?"include":t.credentials;delete t.data,delete t.withCredentials;let h=a||u?F(i,a||s):i,g=h.includes("://")?"":t.baseURL||this.baseURL;return c&&typeof c!="string"&&!(c instanceof URLSearchParams)&&x(c)&&(c=JSON.stringify(c)),{...t,credentials:p,body:c,method:n,url:g+h,headers:{Accept:w+", text/plain, */*","Content-Type":w+";charset=utf-8",...t.headers||this.config.headers||{}}}}processError(e,s){var t;this.isRequestCancelled(e)||((t=this.logger)!=null&&t.warn&&this.logger.warn("API ERROR",e),s.onError&&s.onError(e),this.config.onError&&this.config.onError(e))}async outputErrorResponse(e,s,t){let n=this.isRequestCancelled(e),l=t.strategy||this.strategy,i=typeof t.rejectCancelled<"u"?t.rejectCancelled:this.rejectCancelled;if(!(n&&!i)){if(l==="silent")await new Promise(()=>null);else if(l==="reject")return Promise.reject(e)}return this.outputResponse(s,t,e)}isRequestCancelled(e){return e.name==="AbortError"||e.name==="CanceledError"}isCustomFetcher(){return this.fetcher!==null}addCancelToken(e){if(typeof AbortController>"u")return console.error("AbortController unavailable."),{};if(typeof e.cancellable<"u"?e.cancellable:this.config.cancellable){let n=this.requestsQueue.get(e);n&&n.controller.abort()}let t=new AbortController;return this.requestsQueue.set(e,{controller:t}),{signal:t.signal}}setupTimeout(e,s){let t=typeof e.timeout<"u"?e.timeout:this.timeout;if(t>0){let n=this.requestsQueue.get(e)||{};if(n!=null&&n.timeoutId){if(!s)return;clearTimeout(n.timeoutId)}let l=setTimeout(()=>{var r;let i=this.requestsQueue.get(e);if(!i)return;let a=new Error(`${e.url} aborted due to timeout`);a.name="TimeoutError",a.code=23,(r=i==null?void 0:i.controller)==null||r.abort(a)},t);this.requestsQueue.set(e,{...n,timeoutId:l})}}async request(e,s=null,t=null){var D,q,I,A;let n=null,l=t||{},i=this.buildConfig(e,s,l),a={...this.addCancelToken(i),...i},{retries:r,delay:u,backoff:c,retryOn:p,shouldRetry:h,maxDelay:R,resetTimeout:g}={...this.retry,...(a==null?void 0:a.retry)||{}},y=0,m=u;for(;y<=r;)try{if(this.setupTimeout(i,g),a=await P(a,a==null?void 0:a.onRequest),a=await P(a,(D=this.config)==null?void 0:D.onRequest),this.isCustomFetcher())n=await this.requestInstance.request(a);else if(n=await globalThis.fetch(a.url,a),n.config=a,n.data=await this.parseData(n),!n.ok)throw new b(`${a.url} failed! Status: ${n.status||null}`,a,n);return n=await C(n,a==null?void 0:a.onResponse),n=await C(n,(q=this.config)==null?void 0:q.onResponse),this.outputResponse(n,a)}catch(d){if(y===r||!await h(d,y)||!(p!=null&&p.includes(((I=d==null?void 0:d.response)==null?void 0:I.status)||(d==null?void 0:d.status))))return this.processError(d,a),this.outputErrorResponse(d,n,a);(A=this.logger)!=null&&A.warn&&this.logger.warn(`Attempt ${y+1} failed. Retrying in ${m}ms...`),await H(m),m*=c,m=Math.min(m,R),y++}return this.outputResponse(n,a)}async parseData(e){var n;if(!(e!=null&&e.body))return null;let s=String(((n=e.headers)==null?void 0:n.get("Content-Type"))||"").split(";")[0],t;try{if(s.includes(w)||s.includes("+json"))t=await e.json();else if(s.includes("multipart/form-data"))t=await e.formData();else if(s.includes("application/octet-stream"))t=await e.blob();else if(s.includes("application/x-www-form-urlencoded"))t=await e.formData();else if(s.includes("text/"))t=await e.text();else try{t=await e.clone().json()}catch{t=await e.text()}}catch{t=null}return t}processHeaders(e){let s=e.headers;if(!s)return{};let t={};if(s instanceof Headers)s.forEach((n,l)=>{t[l]=n});else if(typeof s=="object"&&s!==null)for(let[n,l]of Object.entries(s))t[n.toLowerCase()]=l;return t}flattenData(e){return e&&typeof e=="object"&&typeof e.data<"u"&&Object.keys(e).length===1?this.flattenData(e.data):e}outputResponse(e,s,t=null){let n=typeof s.defaultResponse<"u"?s.defaultResponse:this.defaultResponse,l=typeof s.flattenResponse<"u"?s.flattenResponse:this.flattenResponse;if(!e)return l?n:{error:t,headers:null,data:n,config:s};t!==null&&(t==null||delete t.response,t==null||delete t.request,t==null||delete t.config);let i=e==null?void 0:e.data;return(i==null||typeof i=="object"&&Object.keys(i).length===0)&&(i=n),l?this.flattenData(i):this.isCustomFetcher()?e:{body:e.body,blob:e.blob,json:e.json,text:e.text,clone:e.clone,bodyUsed:e.bodyUsed,arrayBuffer:e.arrayBuffer,formData:e.formData,ok:e.ok,redirected:e.redirected,type:e.type,url:e.url,status:e.status,statusText:e.statusText,error:t,data:i,headers:this.processHeaders(e),config:s}}};function M(o){let e=o.endpoints,s=new f(o);function t(){return s.getInstance()}function n(r){return console.error(`${r} endpoint must be added to 'endpoints'.`),Promise.resolve(null)}async function l(r,u={},c={},p={}){let R={...e[r]};return await s.request(R.url,u,{...R,...p,urlPathParams:c})}function i(r){return r in a?a[r]:e[r]?a.request.bind(null,r):n.bind(null,r)}let a={config:o,endpoints:e,requestHandler:s,getInstance:t,request:l};return new Proxy(a,{get:(r,u)=>i(u)})}async function _(o,e={}){return new f(e).request(o,null,e)}})();
"use strict";var fetchff=(()=>{var F=Object.defineProperty,re=Object.defineProperties,oe=Object.getOwnPropertyDescriptor,ae=Object.getOwnPropertyDescriptors,ie=Object.getOwnPropertyNames,W=Object.getOwnPropertySymbols;var Z=Object.prototype.hasOwnProperty,le=Object.prototype.propertyIsEnumerable;var k=(t,e,n)=>e in t?F(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,m=(t,e)=>{for(var n in e||(e={}))Z.call(e,n)&&k(t,n,e[n]);if(W)for(var n of W(e))le.call(e,n)&&k(t,n,e[n]);return t},w=(t,e)=>re(t,ae(e));var ue=(t,e)=>{for(var n in e)F(t,n,{get:e[n],enumerable:!0})},ce=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let l of ie(e))!Z.call(t,l)&&l!==n&&F(t,l,{get:()=>e[l],enumerable:!(o=oe(e,l))||o.enumerable});return t};var pe=t=>ce(F({},"__esModule",{value:!0}),t);var C=(t,e,n)=>k(t,typeof e!="symbol"?e+"":e,n);var me={};ue(me,{createApiFetcher:()=>fe,fetchf:()=>Re});async function L(t,e){if(!e)return t;let n=Array.isArray(e)?e:[e],o=m({},t);for(let l of n)o=await l(o);return o}async function $(t,e){if(!e)return t;let n=Array.isArray(e)?e:[e],o=t;for(let l of n)o=await l(o);return o}var U=class extends Error{constructor(n,o,l){super(n);C(this,"response");C(this,"request");C(this,"config");C(this,"status");C(this,"statusText");this.name="ResponseError",this.message=n,this.status=l.status,this.statusText=l.statusText,this.request=o,this.config=o,this.response=l}};function K(t,e){if(!e)return t;if(e instanceof URLSearchParams){let p=e.toString();return t.includes("?")?`${t}&${p}`:p?`${t}?${p}`:t}let n=[],o=function(p,r){r=typeof r=="function"?r():r,r=r===null||r===void 0?"":r,n[n.length]=encodeURIComponent(p)+"="+encodeURIComponent(r)},l=(p,r)=>{let d,g,s;if(p)if(Array.isArray(r))for(d=0,g=r.length;d<g;d++)l(p+"["+(typeof r[d]=="object"&&r[d]?d:"")+"]",r[d]);else if(typeof r=="object"&&r!==null)for(s in r)l(p+"["+s+"]",r[s]);else o(p,r);else if(Array.isArray(r))for(d=0,g=r.length;d<g;d++)o(r[d].name,r[d].value);else for(s in r)l(s,r[s]);return n},R=l("",e).join("&").replace(/%5B%5D/g,"[]");return t.includes("?")?`${t}&${R}`:R?`${t}?${R}`:t}function V(t,e){return e?t.replace(/:[a-zA-Z]+/gi,n=>{let o=n.substring(1);return String(e[o]?e[o]:n)}):t}function X(t){if(t==null)return!1;let e=typeof t;if(e==="string"||e==="number"||e==="boolean")return!0;if(e!=="object")return!1;if(Array.isArray(t))return!0;if(Buffer.isBuffer(t)||t instanceof Date)return!1;let n=Object.getPrototypeOf(t);return n===Object.prototype||n===null||typeof t.toJSON=="function"}async function v(t){return new Promise(e=>setTimeout(()=>e(!0),t))}function B(t){return t&&typeof t=="object"&&typeof t.data!="undefined"&&Object.keys(t).length===1?B(t.data):t}function ee(t){if(!t)return{};let e={};if(t instanceof Headers)t.forEach((n,o)=>{e[o]=n});else if(typeof t=="object"&&t!==null)for(let[n,o]of Object.entries(t))e[n.toLowerCase()]=o;return e}function D(t,e){t&&e in t&&delete t[e]}var T=new Map;async function te(t,e,n=0,o=!1,l=!0){let b=Date.now(),R=T.get(t);if(R){if(!R.isCancellable&&b-R.timestamp<n)return R.controller;R.isCancellable&&R.controller.abort(new DOMException("Aborted due to new request","AbortError")),R.timeoutId!==null&&clearTimeout(R.timeoutId),T.delete(t)}let p=new AbortController,r=l?setTimeout(()=>{let d=new DOMException(`${t.url} aborted due to timeout`,"TimeoutError");S(t,d)},e):null;return T.set(t,{controller:p,timeoutId:r,timestamp:b,isCancellable:o}),p}async function S(t,e=null){let n=T.get(t);n&&(e&&!n.controller.signal.aborted&&n.controller.abort(e),n.timeoutId!==null&&clearTimeout(n.timeoutId),T.delete(t))}var E="application/json",Q="Content-Type";async function ne(t){var o;if(!(t!=null&&t.body))return null;let e=String(((o=t.headers)==null?void 0:o.get(Q))||"").split(";")[0],n;try{if(e.includes(E)||e.includes("+json"))n=await t.json();else if(e.includes("multipart/form-data"))n=await t.formData();else if(e.includes("application/octet-stream"))n=await t.blob();else if(e.includes("application/x-www-form-urlencoded"))n=await t.formData();else if(e.includes("text/"))n=await t.text();else try{n=await t.clone().json()}catch(l){n=await t.text()}}catch(l){n=null}return n}var de={method:"GET",strategy:"reject",timeout:3e4,rejectCancelled:!1,dedupeTime:1e3,withCredentials:!1,flattenResponse:!1,defaultResponse:null,logger:null,fetcher:null,baseURL:"",retry:{retries:0,delay:1e3,maxDelay:3e4,resetTimeout:!0,backoff:1.5,retryOn:[408,409,425,429,500,502,503,504],shouldRetry:async()=>!0}};function M(t){let e=m(w(m({},de),{baseURL:t.apiUrl||""}),t),n=()=>e.fetcher!==null,o=n()?e.fetcher.create(w(m({},t),{baseURL:e.baseURL,timeout:e.timeout})):null,l=()=>o,b=(s,c,a)=>{let u=(a.method||e.method).toUpperCase(),P=u==="GET"||u==="HEAD",i=V(s,a.urlPathParams||e.urlPathParams||null),A=a.params||e.params,O=a.body||a.data||e.body||e.data,H=!!(c&&(P||O)),y;if(P||(y=O||c),n())return w(m({},a),{method:u,url:i,params:H?c:A,data:y});let N=(typeof a.withCredentials!="undefined"?a.withCredentials:e.withCredentials)?"include":a.credentials||e.credentials||void 0;D(a,"data"),D(a,"withCredentials");let q=A||H?K(i,A||c):i,j=q.includes("://")?"":a.baseURL||e.baseURL;return y&&typeof y!="string"&&!(y instanceof URLSearchParams)&&X(y)&&(y=JSON.stringify(y)),w(m({},a),{credentials:N,body:y,method:u,url:j+q,headers:m(m({Accept:E+", text/plain, */*","Accept-Encoding":"gzip, deflate, br",[Q]:E+";charset=utf-8"},e.headers||{}),a.headers||{})})},R=(s,c)=>{var a;r(s)||((a=e.logger)!=null&&a.warn&&e.logger.warn("API ERROR",s),c.onError&&c.onError(s),e.onError&&e.onError(s))},p=async(s,c,a)=>{let u=r(s),P=a.strategy||e.strategy,i=typeof a.rejectCancelled!="undefined"?a.rejectCancelled:e.rejectCancelled;if(!(u&&!i)){if(P==="silent")await new Promise(()=>null);else if(P==="reject")return Promise.reject(s)}return g(c,a,s)},r=s=>s.name==="AbortError"||s.name==="CanceledError",d=async(s,c=null,a=null)=>{var z,G;let u=null,i=b(s,c,a||{}),A=typeof i.timeout!="undefined"?i.timeout:e.timeout,O=typeof i.cancellable!="undefined"?i.cancellable:e.cancellable,H=typeof i.dedupeTime!="undefined"?i.dedupeTime:e.dedupeTime,{retries:y,delay:_,backoff:N,retryOn:q,shouldRetry:J,maxDelay:j,resetTimeout:se}=m(m({},e.retry),(i==null?void 0:i.retry)||{}),x=0,I=_;for(;x<=y;)try{let h=(await te(i,A,H,O,A>0&&(!y||se))).signal,f=m({signal:h},i);if(f=await L(f,f==null?void 0:f.onRequest),f=await L(f,e==null?void 0:e.onRequest),n())u=await o.request(f);else if(u=await fetch(f.url,f),u.config=f,u.data=await ne(u),!u.ok)throw new U(`${f.url} failed! Status: ${u.status||null}`,f,u);return u=await $(u,f==null?void 0:f.onResponse),u=await $(u,e==null?void 0:e.onResponse),S(i),g(u,f)}catch(Y){let h=Y,f=((z=h==null?void 0:h.response)==null?void 0:z.status)||(h==null?void 0:h.status)||0;if(x===y||!await J(h,x)||!(q!=null&&q.includes(f)))return R(h,i),S(i),p(h,u,i);(G=e.logger)!=null&&G.warn&&e.logger.warn(`Attempt ${x+1} failed. Retrying in ${I}ms...`),await v(I),I*=N,I=Math.min(I,j),x++}return g(u,i)},g=(s,c,a=null)=>{let u=typeof c.defaultResponse!="undefined"?c.defaultResponse:e.defaultResponse,P=typeof c.flattenResponse!="undefined"?c.flattenResponse:e.flattenResponse;if(!s)return P?u:{error:a,headers:null,data:u,config:c};D(a,"response"),D(a,"request"),D(a,"config");let i=s==null?void 0:s.data;return(i==null||typeof i=="object"&&Object.keys(i).length===0)&&(i=u),P?B(i):n()?s:{body:s.body,blob:s.blob,json:s.json,text:s.text,clone:s.clone,bodyUsed:s.bodyUsed,arrayBuffer:s.arrayBuffer,formData:s.formData,ok:s.ok,redirected:s.redirected,type:s.type,url:s.url,status:s.status,statusText:s.statusText,error:a,data:i,headers:ee(s.headers),config:c}};return{getInstance:l,buildConfig:b,config:t,request:d}}function fe(t){let e=t.endpoints,n=M(t);function o(){return n.getInstance()}function l(r){return console.error(`${r} endpoint must be added to 'endpoints'.`),Promise.resolve(null)}async function b(r,d={},g={},s={}){let c=e[r];return await n.request(c.url,d,w(m(m({},c||{}),s),{urlPathParams:g}))}function R(r){return r in p?p[r]:e[r]?p.request.bind(null,r):l.bind(null,r)}let p={config:t,endpoints:e,requestHandler:n,getInstance:o,request:b};return new Proxy(p,{get:(r,d)=>R(d)})}async function Re(t,e={}){return M(e).request(t,null,e)}return pe(me);})();
//# sourceMappingURL=index.global.js.map

@@ -14,3 +14,3 @@ type RequestInterceptor = (config: RequestHandlerConfig) => RequestHandlerConfig | Promise<RequestHandlerConfig>;

data: T;
error: ResponseError<T>;
error: ResponseError<T> | null;
headers: HeadersObject & HeadersInit;

@@ -67,3 +67,3 @@ config: ExtendedRequestConfig;

*/
retryOn: number[];
retryOn?: number[];
/**

@@ -92,3 +92,3 @@ * A function to determine whether to retry based on the error and attempt number.

*/
defaultResponse?: unknown;
defaultResponse?: any;
/**

@@ -99,3 +99,4 @@ * If `true`, flattens the response object, extracting the data directly instead of keeping it nested.

/**
* If `true`, allows the request to be cancellable using an `AbortController`.
* If true, the ongoing previous requests will be automatically cancelled.
* @default false
*/

@@ -105,2 +106,3 @@ cancellable?: boolean;

* If `true`, rejects the request promise when the request is cancelled.
* @default false
*/

@@ -123,2 +125,3 @@ rejectCancelled?: boolean;

* The HTTP method to use for the request (e.g., 'GET', 'POST', etc.).
* @default GET
*/

@@ -171,2 +174,7 @@ method?: Method | string;

onError?: ErrorHandlerInterceptor;
/**
* Time window, in miliseconds, during which identical requests are deduplicated (treated as single request).
* @default 1000 (1 second)
*/
dedupeTime?: number;
}

@@ -176,128 +184,11 @@ interface BaseRequestHandlerConfig extends RequestConfig {

apiUrl?: string;
logger?: unknown;
logger?: any;
}
type RequestConfig = ExtendedRequestConfig;
type RequestHandlerConfig = BaseRequestHandlerConfig;
type RequestsQueue = WeakMap<RequestConfig, QueueItem>;
interface QueueItem {
controller: AbortController;
timeoutId?: NodeJS.Timeout;
}
/**
* Generic Request Handler
* It creates an Request Fetcher instance and handles requests within that instance
* It handles errors depending on a chosen error handling strategy
*/
declare class RequestHandler {
requestInstance: FetcherInstance;
baseURL: string;
timeout: number;
rejectCancelled: boolean;
strategy: ErrorHandlingStrategy;
method: Method | string;
flattenResponse: boolean;
defaultResponse: any;
protected fetcher: FetcherInstance;
protected logger: any;
protected requestsQueue: RequestsQueue;
protected retry: RetryOptions;
interface RequestHandlerReturnType {
config: RequestHandlerConfig;
constructor({ fetcher, timeout, rejectCancelled, strategy, flattenResponse, defaultResponse, logger, ...config }: RequestHandlerConfig);
/**
* Get Provider Instance
*
* @returns {FetcherInstance} Provider's instance
*/
getInstance(): FetcherInstance;
/**
* Build request configuration
*
* @param {string} url - Request url
* @param {QueryParamsOrBody} data - Query Params in case of GET and HEAD requests, body payload otherwise
* @param {RequestConfig} config - Request config passed when making the request
* @returns {RequestConfig} - Provider's instance
*/
protected buildConfig(url: string, data: QueryParamsOrBody, config: RequestConfig): RequestConfig;
/**
* Process global Request Error
*
* @param {ResponseError} error Error instance
* @param {RequestConfig} requestConfig Per endpoint request config
* @returns {void}
*/
protected processError(error: ResponseError, requestConfig: RequestConfig): void;
/**
* Output default response in case of an error, depending on chosen strategy
*
* @param {ResponseError} error Error instance
* @param {FetchResponse} response Response
* @param {RequestConfig} requestConfig Per endpoint request config
* @returns {*} Error response
*/
protected outputErrorResponse(error: ResponseError, response: FetchResponse, requestConfig: RequestConfig): Promise<any>;
/**
* Output error response depending on chosen strategy
*
* @param {ResponseError} error Error instance
* @returns {boolean} True if request is aborted
*/
isRequestCancelled(error: ResponseError): boolean;
/**
* Detects if a custom fetcher is utilized
*
* @returns {boolean} True if it's a custom fetcher
*/
protected isCustomFetcher(): boolean;
/**
* Automatically Cancel Previous Requests using AbortController when "cancellable" is defined
*
* @param {RequestConfig} requestConfig Per endpoint request config
* @returns {Object} Controller Signal to abort
*/
protected addCancelToken(requestConfig: RequestConfig): Partial<Record<'signal', AbortSignal>>;
/**
* Sets up a timeout to automatically abort the request if it exceeds the specified time.
*
* @param {RequestConfig} requestConfig - The configuration object for the request.
* @param {boolean} resetTimeout - Whether to reset the timeout.
*/
protected setupTimeout(requestConfig: RequestConfig, resetTimeout: boolean): void;
/**
* Handle Request depending on used strategy
*
* @param {string} url - Request url
* @param {QueryParamsOrBody} data - Query Params in case of GET and HEAD requests, body payload otherwise
* @param {RequestConfig} config - Request config
* @throws {ResponseError}
* @returns {Promise<ResponseData & FetchResponse<ResponseData>>} Response Data
*/
request<ResponseData = APIResponse>(url: string, data?: QueryParamsOrBody, config?: RequestConfig): Promise<ResponseData & FetchResponse<ResponseData>>;
/**
* Parses the response data based on the Content-Type header.
*
* @param response - The Response object to parse.
* @returns A Promise that resolves to the parsed data.
*/
parseData<ResponseData = APIResponse>(response: FetchResponse<ResponseData>): Promise<any>;
processHeaders<ResponseData>(response: FetchResponse<ResponseData>): HeadersObject;
/**
* Recursively flattens the data object if it meets specific criteria.
*
* The method checks if the provided `data` is an object with exactly one property named `data`.
* If so, it recursively flattens the `data` property. Otherwise, it returns the `data` as-is.
*
* @param {any} data - The data to be flattened. Can be of any type, including objects, arrays, or primitives.
* @returns {any} - The flattened data if the criteria are met; otherwise, the original `data`.
*/
protected flattenData(data: any): any;
/**
* Output response
*
* @param response - Response payload
* @param {RequestConfig} requestConfig - Request config
* @param error - whether the response is erroneous
* @returns {ResponseData | FetchResponse<ResponseData>} Response data
*/
protected outputResponse<ResponseData = APIResponse>(response: FetchResponse<ResponseData>, requestConfig: RequestConfig, error?: any): ResponseData | FetchResponse<ResponseData>;
getInstance: () => FetcherInstance;
buildConfig: (url: string, data: QueryParamsOrBody, config: RequestConfig) => RequestConfig;
request: <ResponseData = unknown>(url: string, data?: QueryParamsOrBody, config?: RequestConfig | null) => Promise<ResponseData & FetchResponse<ResponseData>>;
}

@@ -326,3 +217,6 @@

};
type EndpointsConfig<EndpointsMethods> = Record<keyof EndpointsMethods | string, RequestConfig>;
type RequestConfigUrlRequired = Omit<RequestConfig, 'url'> & {
url: string;
};
type EndpointsConfig<EndpointsMethods> = Record<keyof EndpointsMethods | string, RequestConfigUrlRequired>;
type EndpointsConfigPart<EndpointsCfg, EndpointsMethods extends object> = [

@@ -335,3 +229,3 @@ EndpointsCfg

endpoints: EndpointsConfig<EndpointsMethods>;
requestHandler: RequestHandler;
requestHandler: RequestHandlerReturnType;
getInstance: () => FetcherInstance;

@@ -353,3 +247,3 @@ request: <ResponseData = APIResponse>(endpointName: keyof EndpointsMethods | string, queryParams?: QueryParams, urlPathParams?: UrlPathParams, requestConfig?: RequestConfig) => Promise<ResponseData & FetchResponse<ResponseData>>;

* @param {number} config.timeout - You can set the timeout for particular request in milliseconds.
* @param {number} config.cancellable - If true, the previous requests will be automatically cancelled.
* @param {number} config.cancellable - If true, the ongoing previous requests will be automatically cancelled.
* @param {number} config.rejectCancelled - If true and request is set to cancellable, a cancelled request promise will be rejected. By default, instead of rejecting the promise, defaultResponse is returned.

@@ -409,2 +303,2 @@ * @param {number} config.timeout - Request timeout

export { type APIResponse, type ApiHandlerConfig, type ApiHandlerMethods, type ApiHandlerReturnType, type BodyPayload, type Endpoint, type EndpointsConfig, type ErrorHandlingStrategy, type ExtendedResponse, type FetchResponse, type FetcherInstance, type HeadersObject, type Method, type NativeFetch, type QueryParams, type QueryParamsOrBody, type QueueItem, type RequestConfig, type RequestHandlerConfig, type RequestsQueue, type ResponseError, type RetryOptions, type UrlPathParams, createApiFetcher, fetchf };
export { type APIResponse, type ApiHandlerConfig, type ApiHandlerMethods, type ApiHandlerReturnType, type BodyPayload, type Endpoint, type EndpointsConfig, type ErrorHandlingStrategy, type ExtendedResponse, type FetchResponse, type FetcherInstance, type HeadersObject, type Method, type NativeFetch, type QueryParams, type QueryParamsOrBody, type RequestConfig, type RequestHandlerConfig, type RequestHandlerReturnType, type ResponseError, type RetryOptions, type UrlPathParams, createApiFetcher, fetchf };

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

var P=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var Q=Object.prototype.hasOwnProperty;var S=(o,e)=>{for(var s in e)P(o,s,{get:e[s],enumerable:!0})},j=(o,e,s,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of O(e))!Q.call(o,n)&&n!==s&&P(o,n,{get:()=>e[n],enumerable:!(t=U(e,n))||t.enumerable});return o};var k=o=>j(P({},"__esModule",{value:!0}),o);var B={};S(B,{createApiFetcher:()=>L,fetchf:()=>$});module.exports=k(B);async function C(o,e){if(!e)return o;let s=Array.isArray(e)?e:[e],t={...o};for(let n of s)t=await n(t);return t}async function w(o,e){if(!e)return o;let s=Array.isArray(e)?e:[e],t=o;for(let n of s)t=await n(t);return t}var b=class extends Error{response;request;config;status;statusText;constructor(e,s,t){super(e),this.name="ResponseError",this.message=e,this.status=t.status,this.statusText=t.statusText,this.request=s,this.config=s,this.response=t}};function E(o,e){if(!e)return o;if(e instanceof URLSearchParams){let a=e.toString();return o.includes("?")?`${o}&${a}`:a?`${o}?${a}`:o}let s=[],t=function(a,r){r=typeof r=="function"?r():r,r=r===null||r===void 0?"":r,s[s.length]=encodeURIComponent(a)+"="+encodeURIComponent(r)},n=(a,r)=>{let u,c,p;if(a)if(Array.isArray(r))for(u=0,c=r.length;u<c;u++)n(a+"["+(typeof r[u]=="object"&&r[u]?u:"")+"]",r[u]);else if(typeof r=="object"&&r!==null)for(p in r)n(a+"["+p+"]",r[p]);else t(a,r);else if(Array.isArray(r))for(u=0,c=r.length;u<c;u++)t(r[u].name,r[u].value);else for(p in r)n(p,r[p]);return s},i=n("",e).join("&").replace(/%5B%5D/g,"[]");return o.includes("?")?`${o}&${i}`:i?`${o}?${i}`:o}function x(o,e){return e?o.replace(/:[a-zA-Z]+/gi,s=>{let t=s.substring(1);return String(e[t]?e[t]:s)}):o}function H(o){if(o==null)return!1;let e=typeof o;if(e==="string"||e==="number"||e==="boolean")return!0;if(e!=="object")return!1;if(Array.isArray(o))return!0;if(Buffer.isBuffer(o)||o instanceof Date)return!1;let s=Object.getPrototypeOf(o);return s===Object.prototype||s===null||typeof o.toJSON=="function"}async function T(o){return new Promise(e=>setTimeout(()=>e(!0),o))}var D="application/json",f=class{requestInstance;baseURL="";timeout=3e4;rejectCancelled=!1;strategy="reject";method="get";flattenResponse=!1;defaultResponse=null;fetcher;logger;requestsQueue;retry={retries:0,delay:1e3,maxDelay:3e4,resetTimeout:!0,backoff:1.5,retryOn:[408,409,425,429,500,502,503,504],shouldRetry:async()=>!0};config={};constructor({fetcher:e=null,timeout:s=null,rejectCancelled:t=!1,strategy:n=null,flattenResponse:l=null,defaultResponse:i={},logger:a=null,...r}){this.fetcher=e,this.timeout=s??this.timeout,this.strategy=n||this.strategy,this.rejectCancelled=t||this.rejectCancelled,this.flattenResponse=l||this.flattenResponse,this.defaultResponse=i,this.logger=a||null,this.requestsQueue=new WeakMap,this.baseURL=r.baseURL||r.apiUrl||"",this.method=r.method||this.method,this.config=r,this.retry={...this.retry,...r.retry||{}},this.requestInstance=this.isCustomFetcher()?e.create({...r,baseURL:this.baseURL,timeout:this.timeout}):null}getInstance(){return this.requestInstance}buildConfig(e,s,t){let n=(t.method||this.method).toUpperCase(),l=n==="GET"||n==="HEAD",i=x(e,t.urlPathParams||this.config.urlPathParams),a=t.params||this.config.params,r=t.body||t.data||this.config.body||this.config.data,u=!!(s&&(l||r)),c;if(l||(c=r||s),this.isCustomFetcher())return{...t,method:n,url:i,params:u?s:a,data:c};let p=t.withCredentials||this.config.withCredentials?"include":t.credentials;delete t.data,delete t.withCredentials;let h=a||u?E(i,a||s):i,g=h.includes("://")?"":t.baseURL||this.baseURL;return c&&typeof c!="string"&&!(c instanceof URLSearchParams)&&H(c)&&(c=JSON.stringify(c)),{...t,credentials:p,body:c,method:n,url:g+h,headers:{Accept:D+", text/plain, */*","Content-Type":D+";charset=utf-8",...t.headers||this.config.headers||{}}}}processError(e,s){var t;this.isRequestCancelled(e)||((t=this.logger)!=null&&t.warn&&this.logger.warn("API ERROR",e),s.onError&&s.onError(e),this.config.onError&&this.config.onError(e))}async outputErrorResponse(e,s,t){let n=this.isRequestCancelled(e),l=t.strategy||this.strategy,i=typeof t.rejectCancelled<"u"?t.rejectCancelled:this.rejectCancelled;if(!(n&&!i)){if(l==="silent")await new Promise(()=>null);else if(l==="reject")return Promise.reject(e)}return this.outputResponse(s,t,e)}isRequestCancelled(e){return e.name==="AbortError"||e.name==="CanceledError"}isCustomFetcher(){return this.fetcher!==null}addCancelToken(e){if(typeof AbortController>"u")return console.error("AbortController unavailable."),{};if(typeof e.cancellable<"u"?e.cancellable:this.config.cancellable){let n=this.requestsQueue.get(e);n&&n.controller.abort()}let t=new AbortController;return this.requestsQueue.set(e,{controller:t}),{signal:t.signal}}setupTimeout(e,s){let t=typeof e.timeout<"u"?e.timeout:this.timeout;if(t>0){let n=this.requestsQueue.get(e)||{};if(n!=null&&n.timeoutId){if(!s)return;clearTimeout(n.timeoutId)}let l=setTimeout(()=>{var r;let i=this.requestsQueue.get(e);if(!i)return;let a=new Error(`${e.url} aborted due to timeout`);a.name="TimeoutError",a.code=23,(r=i==null?void 0:i.controller)==null||r.abort(a)},t);this.requestsQueue.set(e,{...n,timeoutId:l})}}async request(e,s=null,t=null){var q,I,A,F;let n=null,l=t||{},i=this.buildConfig(e,s,l),a={...this.addCancelToken(i),...i},{retries:r,delay:u,backoff:c,retryOn:p,shouldRetry:h,maxDelay:R,resetTimeout:g}={...this.retry,...(a==null?void 0:a.retry)||{}},y=0,m=u;for(;y<=r;)try{if(this.setupTimeout(i,g),a=await C(a,a==null?void 0:a.onRequest),a=await C(a,(q=this.config)==null?void 0:q.onRequest),this.isCustomFetcher())n=await this.requestInstance.request(a);else if(n=await globalThis.fetch(a.url,a),n.config=a,n.data=await this.parseData(n),!n.ok)throw new b(`${a.url} failed! Status: ${n.status||null}`,a,n);return n=await w(n,a==null?void 0:a.onResponse),n=await w(n,(I=this.config)==null?void 0:I.onResponse),this.outputResponse(n,a)}catch(d){if(y===r||!await h(d,y)||!(p!=null&&p.includes(((A=d==null?void 0:d.response)==null?void 0:A.status)||(d==null?void 0:d.status))))return this.processError(d,a),this.outputErrorResponse(d,n,a);(F=this.logger)!=null&&F.warn&&this.logger.warn(`Attempt ${y+1} failed. Retrying in ${m}ms...`),await T(m),m*=c,m=Math.min(m,R),y++}return this.outputResponse(n,a)}async parseData(e){var n;if(!(e!=null&&e.body))return null;let s=String(((n=e.headers)==null?void 0:n.get("Content-Type"))||"").split(";")[0],t;try{if(s.includes(D)||s.includes("+json"))t=await e.json();else if(s.includes("multipart/form-data"))t=await e.formData();else if(s.includes("application/octet-stream"))t=await e.blob();else if(s.includes("application/x-www-form-urlencoded"))t=await e.formData();else if(s.includes("text/"))t=await e.text();else try{t=await e.clone().json()}catch{t=await e.text()}}catch{t=null}return t}processHeaders(e){let s=e.headers;if(!s)return{};let t={};if(s instanceof Headers)s.forEach((n,l)=>{t[l]=n});else if(typeof s=="object"&&s!==null)for(let[n,l]of Object.entries(s))t[n.toLowerCase()]=l;return t}flattenData(e){return e&&typeof e=="object"&&typeof e.data<"u"&&Object.keys(e).length===1?this.flattenData(e.data):e}outputResponse(e,s,t=null){let n=typeof s.defaultResponse<"u"?s.defaultResponse:this.defaultResponse,l=typeof s.flattenResponse<"u"?s.flattenResponse:this.flattenResponse;if(!e)return l?n:{error:t,headers:null,data:n,config:s};t!==null&&(t==null||delete t.response,t==null||delete t.request,t==null||delete t.config);let i=e==null?void 0:e.data;return(i==null||typeof i=="object"&&Object.keys(i).length===0)&&(i=n),l?this.flattenData(i):this.isCustomFetcher()?e:{body:e.body,blob:e.blob,json:e.json,text:e.text,clone:e.clone,bodyUsed:e.bodyUsed,arrayBuffer:e.arrayBuffer,formData:e.formData,ok:e.ok,redirected:e.redirected,type:e.type,url:e.url,status:e.status,statusText:e.statusText,error:t,data:i,headers:this.processHeaders(e),config:s}}};function L(o){let e=o.endpoints,s=new f(o);function t(){return s.getInstance()}function n(r){return console.error(`${r} endpoint must be added to 'endpoints'.`),Promise.resolve(null)}async function l(r,u={},c={},p={}){let R={...e[r]};return await s.request(R.url,u,{...R,...p,urlPathParams:c})}function i(r){return r in a?a[r]:e[r]?a.request.bind(null,r):n.bind(null,r)}let a={config:o,endpoints:e,requestHandler:s,getInstance:t,request:l};return new Proxy(a,{get:(r,u)=>i(u)})}async function $(o,e={}){return new f(e).request(o,null,e)}0&&(module.exports={createApiFetcher,fetchf});
"use strict";var F=Object.defineProperty,re=Object.defineProperties,oe=Object.getOwnPropertyDescriptor,ae=Object.getOwnPropertyDescriptors,ie=Object.getOwnPropertyNames,W=Object.getOwnPropertySymbols;var Z=Object.prototype.hasOwnProperty,le=Object.prototype.propertyIsEnumerable;var k=(t,e,n)=>e in t?F(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,m=(t,e)=>{for(var n in e||(e={}))Z.call(e,n)&&k(t,n,e[n]);if(W)for(var n of W(e))le.call(e,n)&&k(t,n,e[n]);return t},w=(t,e)=>re(t,ae(e));var ue=(t,e)=>{for(var n in e)F(t,n,{get:e[n],enumerable:!0})},ce=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let l of ie(e))!Z.call(t,l)&&l!==n&&F(t,l,{get:()=>e[l],enumerable:!(o=oe(e,l))||o.enumerable});return t};var pe=t=>ce(F({},"__esModule",{value:!0}),t);var C=(t,e,n)=>k(t,typeof e!="symbol"?e+"":e,n);var me={};ue(me,{createApiFetcher:()=>fe,fetchf:()=>Re});module.exports=pe(me);async function L(t,e){if(!e)return t;let n=Array.isArray(e)?e:[e],o=m({},t);for(let l of n)o=await l(o);return o}async function $(t,e){if(!e)return t;let n=Array.isArray(e)?e:[e],o=t;for(let l of n)o=await l(o);return o}var U=class extends Error{constructor(n,o,l){super(n);C(this,"response");C(this,"request");C(this,"config");C(this,"status");C(this,"statusText");this.name="ResponseError",this.message=n,this.status=l.status,this.statusText=l.statusText,this.request=o,this.config=o,this.response=l}};function K(t,e){if(!e)return t;if(e instanceof URLSearchParams){let p=e.toString();return t.includes("?")?`${t}&${p}`:p?`${t}?${p}`:t}let n=[],o=function(p,r){r=typeof r=="function"?r():r,r=r===null||r===void 0?"":r,n[n.length]=encodeURIComponent(p)+"="+encodeURIComponent(r)},l=(p,r)=>{let d,g,s;if(p)if(Array.isArray(r))for(d=0,g=r.length;d<g;d++)l(p+"["+(typeof r[d]=="object"&&r[d]?d:"")+"]",r[d]);else if(typeof r=="object"&&r!==null)for(s in r)l(p+"["+s+"]",r[s]);else o(p,r);else if(Array.isArray(r))for(d=0,g=r.length;d<g;d++)o(r[d].name,r[d].value);else for(s in r)l(s,r[s]);return n},R=l("",e).join("&").replace(/%5B%5D/g,"[]");return t.includes("?")?`${t}&${R}`:R?`${t}?${R}`:t}function V(t,e){return e?t.replace(/:[a-zA-Z]+/gi,n=>{let o=n.substring(1);return String(e[o]?e[o]:n)}):t}function X(t){if(t==null)return!1;let e=typeof t;if(e==="string"||e==="number"||e==="boolean")return!0;if(e!=="object")return!1;if(Array.isArray(t))return!0;if(Buffer.isBuffer(t)||t instanceof Date)return!1;let n=Object.getPrototypeOf(t);return n===Object.prototype||n===null||typeof t.toJSON=="function"}async function v(t){return new Promise(e=>setTimeout(()=>e(!0),t))}function B(t){return t&&typeof t=="object"&&typeof t.data!="undefined"&&Object.keys(t).length===1?B(t.data):t}function ee(t){if(!t)return{};let e={};if(t instanceof Headers)t.forEach((n,o)=>{e[o]=n});else if(typeof t=="object"&&t!==null)for(let[n,o]of Object.entries(t))e[n.toLowerCase()]=o;return e}function D(t,e){t&&e in t&&delete t[e]}var T=new Map;async function te(t,e,n=0,o=!1,l=!0){let b=Date.now(),R=T.get(t);if(R){if(!R.isCancellable&&b-R.timestamp<n)return R.controller;R.isCancellable&&R.controller.abort(new DOMException("Aborted due to new request","AbortError")),R.timeoutId!==null&&clearTimeout(R.timeoutId),T.delete(t)}let p=new AbortController,r=l?setTimeout(()=>{let d=new DOMException(`${t.url} aborted due to timeout`,"TimeoutError");S(t,d)},e):null;return T.set(t,{controller:p,timeoutId:r,timestamp:b,isCancellable:o}),p}async function S(t,e=null){let n=T.get(t);n&&(e&&!n.controller.signal.aborted&&n.controller.abort(e),n.timeoutId!==null&&clearTimeout(n.timeoutId),T.delete(t))}var E="application/json",Q="Content-Type";async function ne(t){var o;if(!(t!=null&&t.body))return null;let e=String(((o=t.headers)==null?void 0:o.get(Q))||"").split(";")[0],n;try{if(e.includes(E)||e.includes("+json"))n=await t.json();else if(e.includes("multipart/form-data"))n=await t.formData();else if(e.includes("application/octet-stream"))n=await t.blob();else if(e.includes("application/x-www-form-urlencoded"))n=await t.formData();else if(e.includes("text/"))n=await t.text();else try{n=await t.clone().json()}catch(l){n=await t.text()}}catch(l){n=null}return n}var de={method:"GET",strategy:"reject",timeout:3e4,rejectCancelled:!1,dedupeTime:1e3,withCredentials:!1,flattenResponse:!1,defaultResponse:null,logger:null,fetcher:null,baseURL:"",retry:{retries:0,delay:1e3,maxDelay:3e4,resetTimeout:!0,backoff:1.5,retryOn:[408,409,425,429,500,502,503,504],shouldRetry:async()=>!0}};function M(t){let e=m(w(m({},de),{baseURL:t.apiUrl||""}),t),n=()=>e.fetcher!==null,o=n()?e.fetcher.create(w(m({},t),{baseURL:e.baseURL,timeout:e.timeout})):null,l=()=>o,b=(s,c,a)=>{let u=(a.method||e.method).toUpperCase(),P=u==="GET"||u==="HEAD",i=V(s,a.urlPathParams||e.urlPathParams||null),A=a.params||e.params,O=a.body||a.data||e.body||e.data,H=!!(c&&(P||O)),y;if(P||(y=O||c),n())return w(m({},a),{method:u,url:i,params:H?c:A,data:y});let N=(typeof a.withCredentials!="undefined"?a.withCredentials:e.withCredentials)?"include":a.credentials||e.credentials||void 0;D(a,"data"),D(a,"withCredentials");let q=A||H?K(i,A||c):i,j=q.includes("://")?"":a.baseURL||e.baseURL;return y&&typeof y!="string"&&!(y instanceof URLSearchParams)&&X(y)&&(y=JSON.stringify(y)),w(m({},a),{credentials:N,body:y,method:u,url:j+q,headers:m(m({Accept:E+", text/plain, */*","Accept-Encoding":"gzip, deflate, br",[Q]:E+";charset=utf-8"},e.headers||{}),a.headers||{})})},R=(s,c)=>{var a;r(s)||((a=e.logger)!=null&&a.warn&&e.logger.warn("API ERROR",s),c.onError&&c.onError(s),e.onError&&e.onError(s))},p=async(s,c,a)=>{let u=r(s),P=a.strategy||e.strategy,i=typeof a.rejectCancelled!="undefined"?a.rejectCancelled:e.rejectCancelled;if(!(u&&!i)){if(P==="silent")await new Promise(()=>null);else if(P==="reject")return Promise.reject(s)}return g(c,a,s)},r=s=>s.name==="AbortError"||s.name==="CanceledError",d=async(s,c=null,a=null)=>{var z,G;let u=null,i=b(s,c,a||{}),A=typeof i.timeout!="undefined"?i.timeout:e.timeout,O=typeof i.cancellable!="undefined"?i.cancellable:e.cancellable,H=typeof i.dedupeTime!="undefined"?i.dedupeTime:e.dedupeTime,{retries:y,delay:_,backoff:N,retryOn:q,shouldRetry:J,maxDelay:j,resetTimeout:se}=m(m({},e.retry),(i==null?void 0:i.retry)||{}),x=0,I=_;for(;x<=y;)try{let h=(await te(i,A,H,O,A>0&&(!y||se))).signal,f=m({signal:h},i);if(f=await L(f,f==null?void 0:f.onRequest),f=await L(f,e==null?void 0:e.onRequest),n())u=await o.request(f);else if(u=await fetch(f.url,f),u.config=f,u.data=await ne(u),!u.ok)throw new U(`${f.url} failed! Status: ${u.status||null}`,f,u);return u=await $(u,f==null?void 0:f.onResponse),u=await $(u,e==null?void 0:e.onResponse),S(i),g(u,f)}catch(Y){let h=Y,f=((z=h==null?void 0:h.response)==null?void 0:z.status)||(h==null?void 0:h.status)||0;if(x===y||!await J(h,x)||!(q!=null&&q.includes(f)))return R(h,i),S(i),p(h,u,i);(G=e.logger)!=null&&G.warn&&e.logger.warn(`Attempt ${x+1} failed. Retrying in ${I}ms...`),await v(I),I*=N,I=Math.min(I,j),x++}return g(u,i)},g=(s,c,a=null)=>{let u=typeof c.defaultResponse!="undefined"?c.defaultResponse:e.defaultResponse,P=typeof c.flattenResponse!="undefined"?c.flattenResponse:e.flattenResponse;if(!s)return P?u:{error:a,headers:null,data:u,config:c};D(a,"response"),D(a,"request"),D(a,"config");let i=s==null?void 0:s.data;return(i==null||typeof i=="object"&&Object.keys(i).length===0)&&(i=u),P?B(i):n()?s:{body:s.body,blob:s.blob,json:s.json,text:s.text,clone:s.clone,bodyUsed:s.bodyUsed,arrayBuffer:s.arrayBuffer,formData:s.formData,ok:s.ok,redirected:s.redirected,type:s.type,url:s.url,status:s.status,statusText:s.statusText,error:a,data:i,headers:ee(s.headers),config:c}};return{getInstance:l,buildConfig:b,config:t,request:d}}function fe(t){let e=t.endpoints,n=M(t);function o(){return n.getInstance()}function l(r){return console.error(`${r} endpoint must be added to 'endpoints'.`),Promise.resolve(null)}async function b(r,d={},g={},s={}){let c=e[r];return await n.request(c.url,d,w(m(m({},c||{}),s),{urlPathParams:g}))}function R(r){return r in p?p[r]:e[r]?p.request.bind(null,r):l.bind(null,r)}let p={config:t,endpoints:e,requestHandler:n,getInstance:o,request:b};return new Proxy(p,{get:(r,d)=>R(d)})}async function Re(t,e={}){return M(e).request(t,null,e)}0&&(module.exports={createApiFetcher,fetchf});
//# sourceMappingURL=index.js.map
{
"version": "2.7.3",
"version": "2.8.0",
"license": "UNLICENSED",

@@ -29,6 +29,6 @@ "name": "fetchff",

"scripts": {
"start": "tsup src/index.ts --watch",
"build": "node ./scripts/build.js",
"build:browser": "tsup src/index.ts --dts --format esm,iife --sourcemap --env.NODE_ENV production --minify --dts-resolve",
"build:node": "tsup src/index.ts --dts --format cjs --sourcemap --env.NODE_ENV production --minify",
"build": "npm run build:node && npm run build:browser && npm run build:cleanup",
"build:browser": "tsup --format esm,iife --out-dir dist/browser --env.NODE_ENV production",
"build:node": "tsup --format cjs --out-dir dist/node --env.NODE_ENV production",
"build:cleanup": "rm -f dist/browser/index.d.mts dist/node/index.d.ts && mv dist/browser/index.d.ts dist/index.d.ts",
"types-check": "tsc --noEmit",

@@ -38,3 +38,3 @@ "test": "jest --forceExit --coverage --detectOpenHandles",

"release": "npm version patch && git push --tags",
"prepare": "npm run build",
"prepublishOnly": "npm run build",
"size": "size-limit",

@@ -62,3 +62,3 @@ "analyze": "size-limit --why"

"@types/jest": "29.5.12",
"eslint": "9.8.0",
"eslint": "9.10.0",
"eslint-config-prettier": "9.1.0",

@@ -69,11 +69,12 @@ "eslint-plugin-prettier": "5.2.1",

"prettier": "3.3.3",
"promise-any": "0.2.0",
"rollup-plugin-bundle-imports": "1.5.1",
"size-limit": "11.1.4",
"ts-jest": "29.2.4",
"tslib": "2.6.3",
"tslib": "2.7.0",
"tsup": "8.2.4",
"typescript": "5.5.4",
"typescript-eslint": "8.0.1"
"typescript": "5.6.2",
"typescript-eslint": "8.5.0"
},
"optionalDependencies": {
"@rollup/rollup-linux-x64-gnu": "4.21.3"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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