From cbf34afa892e9231e64d5f4c8158c041a9425f36 Mon Sep 17 00:00:00 2001 From: fzn0x Date: Wed, 15 May 2024 05:04:36 +0700 Subject: [PATCH] v0.1.0 --- deno_dist/Hyperfetch.test.ts | 36 +++++++++ deno_dist/Hyperfetch.ts | 109 +++++++++++++++------------ deno_dist/README.md | 37 ++++++++- deno_dist/utils/create-http-error.ts | 14 ++++ dist/Hyperfetch.d.ts.map | 2 +- dist/Hyperfetch.js | 1 - dist/Hyperfetch.js.map | 2 +- dist/hyperfetch-browser.min.js | 2 +- dist/hyperfetch-browser.min.js.map | 2 +- package.json | 2 +- 10 files changed, 149 insertions(+), 58 deletions(-) create mode 100644 deno_dist/utils/create-http-error.ts diff --git a/deno_dist/Hyperfetch.test.ts b/deno_dist/Hyperfetch.test.ts index b7abdfd..61c2bb8 100644 --- a/deno_dist/Hyperfetch.test.ts +++ b/deno_dist/Hyperfetch.test.ts @@ -1,4 +1,5 @@ import hypf from "node:hypf"; +import fs from "node:node:fs"; describe("Hyperfetch", () => { // TODO: create a local mock server for typicode @@ -6,6 +7,8 @@ describe("Hyperfetch", () => { "https://jsonplaceholder.typicode.com" ); + const hypfRequest2 = hypf.createRequest("http://localhost:3001"); + it("GET", async () => { const [getErr, getData] = await hypfRequest.get< Array<{ @@ -44,6 +47,39 @@ describe("Hyperfetch", () => { } }); + it("POST:upload", async () => { + const formdata = new FormData(); + const chunks: BlobPart[] = []; + + const stream = fs.createReadStream( + "C:/Users/User/Downloads/Screenshot 2024-05-14 060852.png" + ); + + // Create a promise to handle the stream end event + const streamEndPromise = new Promise((resolve, reject) => { + stream.on("data", (chunk) => chunks.push(chunk)); + stream.once("end", resolve); + stream.once("error", reject); + }); + + // Wait for the stream to finish + await streamEndPromise; + + // Convert chunks to Blob + const blob = new Blob(chunks); + formdata.append("image[]", blob); + + const [postErr, postData] = await hypfRequest2.post("/api/upload-file", { + body: formdata, + }); + + if (postErr) { + console.error("POST Error:", postErr); + } else { + console.log("POST Data:", postData); + } + }); + it("PUT", async () => { const [putErr, putData] = await hypfRequest.put( "/posts/1", diff --git a/deno_dist/Hyperfetch.ts b/deno_dist/Hyperfetch.ts index 124a855..25a0c04 100644 --- a/deno_dist/Hyperfetch.ts +++ b/deno_dist/Hyperfetch.ts @@ -19,6 +19,7 @@ import { } from "./constant.ts"; import { appendParams } from "./utils/append-params.ts"; +import { createHTTPError } from "./utils/create-http-error.ts"; const defaultBackoff = (retryCount: number, factor: number) => Math.pow(2, retryCount) * 1000 * factor; // Exponential backoff, starting from 1 second @@ -46,6 +47,21 @@ function createRequest( options = {}, data ): Promise<[Error | null, null]> => { + const { + method = "GET", + retries = 0, + backoff = defaultBackoff, + jitter = false, + jitterFactor = DEFAULT_JITTER_FACTOR, + backoffFactor = DEFAULT_BACKOFF_FACTOR, + timeout = DEFAULT_MAX_TIMEOUT, + retryOnTimeout = false, + params, + headers = {}, + signal, + ...otherOptions + } = options; + try { // Execute pre-request hook if (hooks?.preRequest) { @@ -53,27 +69,8 @@ function createRequest( } const fullUrl = `${baseUrl}${url}`; - const { - method = "GET", - retries = 0, - backoff = defaultBackoff, - jitter = false, - jitterFactor = DEFAULT_JITTER_FACTOR, - backoffFactor = DEFAULT_BACKOFF_FACTOR, - timeout = DEFAULT_MAX_TIMEOUT, - retryOnTimeout = false, - params, - headers = {}, - signal, - ...otherOptions - } = options; - - const reqHeaders = new Headers(options.headers); - // Set default Content-Type to application/json if not provided - if (!reqHeaders.get("Content-Type") && data && typeof data === "object") { - reqHeaders.set("Content-Type", "application/json"); - } + const reqHeaders = new Headers(headers); // Automatically detect and add Content-Length based on payload length const textEncoder = new TextEncoder(); @@ -93,6 +90,15 @@ function createRequest( } } + // Set default Content-Type to application/json if not provided + if (!reqHeaders.get("Content-Type") && data && typeof data === "object") { + if ( + !(((data as { body: FormData })?.body || data) instanceof FormData) + ) { + reqHeaders.set("Content-Type", "application/json"); + } + } + // Execute pre-timeout hook if (hooks?.preTimeout) { hooks.preTimeout(url, options); @@ -123,14 +129,7 @@ function createRequest( // Append params to the URL const urlWithParams = params ? appendParams(fullUrl, params) : fullUrl; - // Only checks Node.js for duplex compability, as other JS runtimes do full-duplex - // Streams are supported, but they inherently support one-way operations each. Combine them for pseudo full duplex. if (isReadableStreamSupported && !isWriteableStreamSupported && isNode) { - // The @ts-expect-error directive is used here because we are about to assign a value to a property - // that might not be officially recognized in the TypeScript types definitions for `otherOptions`. - // This tells TypeScript to expect a type error on the next line but to ignore it for compilation. - // This approach is often used when dealing with dynamic properties or when using features that TypeScript - // is not aware of, possibly due to using newer browser APIs or experimental features. // @ts-expect-error otherOptions.duplex = "half"; } @@ -153,28 +152,42 @@ function createRequest( otherOptions.duplex = "half"; } - const responsePromise = fetch(urlWithParams, { + const requestBody = + options.body instanceof FormData + ? options.body + : data + ? JSON.stringify(data) + : undefined; + + const requestOptions = { method, signal: isAbortControllerSupported ? globalThis.abortSignal : null, - headers, + headers: reqHeaders, ...otherOptions, - body: data ? JSON.stringify(data) : undefined, - }); + body: requestBody, + }; + + if (requestBody instanceof FormData) { + requestOptions.headers.delete("Content-Type"); + } + + const responsePromise = fetch(urlWithParams, requestOptions); clearTimeout(timeoutId); const response = await responsePromise; - if (!response.ok) { - throw new Error(`Network response was not ok: ${response.status}`); - } - const contentType = response.headers.get("content-type"); + const responseData = contentType && contentType.includes("application/json") ? await response.json() : await response.text(); + if (!response.ok) { + throw createHTTPError(response, responseData); + } + // Execute post-request hook if (hooks?.postRequest) { hooks.postRequest(url, options, data, [null, responseData]); @@ -193,33 +206,31 @@ function createRequest( if (error.name === "AbortError") { console.error("Request aborted:", error); } else if ( - options.retryOnTimeout && + retryOnTimeout && error.name === "TimeoutError" && - options.retries && - options.retries > 0 + retries && + retries > 0 ) { const delay = - options.jitter && options.jitterFactor - ? defaultJitter(options.jitterFactor) + jitter && jitterFactor + ? defaultJitter(jitterFactor) : defaultBackoff( - options.retries, - options.backoffFactor - ? options.backoffFactor - : DEFAULT_BACKOFF_FACTOR + retries, + backoffFactor ? backoffFactor : DEFAULT_BACKOFF_FACTOR ); if (DEBUG) { console.warn( - `Request timed out. Retrying in ${delay}ms... (Remaining retries: ${options.retries})` + `Request timed out. Retrying in ${delay}ms... (Remaining retries: ${retries})` ); } // Execute pre-retry hook if (hooks?.preRetry) { - hooks.preRetry(url, options, options.retries, options.retries); + hooks.preRetry(url, options, retries, retries); } await new Promise((resolve) => setTimeout(resolve, delay)); const [retryErr, retryData] = await request( url, - { ...options, retries: options.retries - 1 }, + { ...options, retries: retries - 1 }, data ); // Execute post-retry hook @@ -229,8 +240,8 @@ function createRequest( options, data, [retryErr, retryData], - options.retries, - options.retries - 1 + retries, + retries - 1 ); } return [retryErr, retryData]; diff --git a/deno_dist/README.md b/deno_dist/README.md index 97f44af..240556d 100644 --- a/deno_dist/README.md +++ b/deno_dist/README.md @@ -2,7 +2,7 @@

-Creates supertiny and stunning HTTP client for frontend apps. Best frontend wrapper for Fetch API. +Supertiny (4kB minified & 0 dependencies) and strong-typed HTTP client for Deno, Bun, Node.js, Cloudflare Workers and Browsers. ```sh # Node.js @@ -11,7 +11,7 @@ npm install hypf bun install hypf ``` -The idea of this tool is to provide frontend-only lightweight solution for fetching APIs with an easy wrapper: +The idea of this tool is to provide lightweight `fetch` wrapper for Node.js, Bun: ```js import hypf from "hypf"; @@ -36,7 +36,38 @@ if (postErr) { } ``` -or browsers +Cloudflare Workers: + +```ts +export default { + async fetch( + request: Request, + env: Env, + ctx: ExecutionContext + ): Promise { + const hypfInstance = await hypf.createRequest( + "https://jsonplaceholder.typicode.com" + ); + + const [getErr, getData] = await hypfInstance.get< + Array<{ + userId: number; + id: number; + title: string; + body: string; + }> + >("/posts"); + + if (getErr) { + console.error("GET Error:", getErr); + } + + return Response.json(getData); + }, +}; +``` + +and Browsers: ```html diff --git a/deno_dist/utils/create-http-error.ts b/deno_dist/utils/create-http-error.ts new file mode 100644 index 0000000..99fd359 --- /dev/null +++ b/deno_dist/utils/create-http-error.ts @@ -0,0 +1,14 @@ +export function createHTTPError(response: Response, responseData: Response) { + const code = response.status || response.status === 0 ? response.status : ""; + const title = response.statusText || ""; + const status = `${code} ${title}`.trim(); + const reason = status ? `status code ${status}` : "an unknown error"; + const error = new Error(reason); + + error.name = "HTTPError"; + + (error as any).response = response; + (error as any).data = responseData; + + return error; +} diff --git a/dist/Hyperfetch.d.ts.map b/dist/Hyperfetch.d.ts.map index 8d7355c..1393b23 100644 --- a/dist/Hyperfetch.d.ts.map +++ b/dist/Hyperfetch.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"Hyperfetch.d.ts","sourceRoot":"","sources":["../src/Hyperfetch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EAIrB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AA0B9C,iBAAS,aAAa,CACpB,OAAO,CAAC,EAAE,MAAM,EAChB,KAAK,CAAC,EAAE,KAAK,EACb,KAAK,UAAQ,GACZ,oBAAoB,CA0RtB;;;;AAED,wBAAiC"} \ No newline at end of file +{"version":3,"file":"Hyperfetch.d.ts","sourceRoot":"","sources":["../src/Hyperfetch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EAIrB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AA0B9C,iBAAS,aAAa,CACpB,OAAO,CAAC,EAAE,MAAM,EAChB,KAAK,CAAC,EAAE,KAAK,EACb,KAAK,UAAQ,GACZ,oBAAoB,CAwRtB;;;;AAED,wBAAiC"} \ No newline at end of file diff --git a/dist/Hyperfetch.js b/dist/Hyperfetch.js index 16315f4..c70b735 100644 --- a/dist/Hyperfetch.js +++ b/dist/Hyperfetch.js @@ -110,7 +110,6 @@ function createRequest(baseUrl, hooks, DEBUG = false) { if (requestBody instanceof FormData) { requestOptions.headers.delete("Content-Type"); } - console.log(requestOptions); const responsePromise = fetch(urlWithParams, requestOptions); clearTimeout(timeoutId); const response = yield responsePromise; diff --git a/dist/Hyperfetch.js.map b/dist/Hyperfetch.js.map index 817c3a5..2e0a631 100644 --- a/dist/Hyperfetch.js.map +++ b/dist/Hyperfetch.js.map @@ -1 +1 @@ -{"version":3,"file":"Hyperfetch.js","sourceRoot":"","sources":["../src/Hyperfetch.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAQA,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,mBAAmB,EACnB,0BAA0B,EAC1B,yBAAyB,EACzB,0BAA0B,EAC1B,iBAAiB,EACjB,oBAAoB,EACpB,MAAM,GACP,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAE/D,MAAM,cAAc,GAAG,CAAC,UAAkB,EAAE,MAAc,EAAE,EAAE,CAC5D,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,UAAU,CAAC,GAAG,IAAI,GAAG,MAAM,CAAC,CAAC,8CAA8C;AAEzF,MAAM,aAAa,GAAG,CAAC,MAAc,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,GAAG,MAAM,CAAC,CAAC,kCAAkC;AAE3G,oEAAoE;AACpE,MAAM,kBAAkB,GAAG,GAAG,EAAE,CAC9B,0BAA0B,CAAC,CAAC,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC,CAAC,IAAI,CAAC;AAEjE,SAAS,aAAa,CACpB,OAAgB,EAChB,KAAa,EACb,KAAK,GAAG,KAAK;IAEb,oDAAoD;IACpD,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE,CAAC;QACjC,MAAM,IAAI,KAAK,CACb,mEAAmE,CACpE,CAAC;IACJ,CAAC;IAED,MAAM,OAAO,GAAoB,YAIA,EAAE,iDAHjC,GAAG,GAAG,EAAE,EACR,OAAO,GAAG,EAAE,EACZ,IAAI;;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AAG,EAAE,OAAO,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC;QAC1D,OAAO,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,CAC9B,kBAAkB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,SAAS,EAAE,OAAO,EAAE,IAAI,CAAC;QAC5D,kBAAkB;KACnB,CAAC;AACJ,CAAC;AAED,eAAe,EAAE,aAAa,EAAE,CAAC"} \ No newline at end of file diff --git a/dist/hyperfetch-browser.min.js b/dist/hyperfetch-browser.min.js index dabd66c..3ae69e5 100644 --- a/dist/hyperfetch-browser.min.js +++ b/dist/hyperfetch-browser.min.js @@ -1,2 +1,2 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("hypf",[],t):"object"==typeof exports?exports.hypf=t():e.hypf=t()}(self,(()=>(()=>{"use strict";var e={d:(t,o)=>{for(var r in o)e.o(o,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:o[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{default:()=>y});const o=2147483647,r=.3,n=1,i="function"==typeof globalThis.AbortController,s="function"==typeof globalThis.ReadableStream,l="function"==typeof globalThis.WritableStream,a="function"==typeof globalThis.WebSocket,c="function"==typeof globalThis.RTCPeerConnection,u=(globalThis.FormData,"undefined"!=typeof process&&"node"===process.release.name);const f=(e,t)=>1e3*Math.pow(2,e)*t,p=e=>1e3*Math.random()*e,d=()=>i?globalThis.abortController:null,y={createRequest:function(e,t,y=!1){if("undefined"==typeof fetch)throw new Error("This library is intended for use in the browser environment only.");const b=(...d)=>{return g=this,h=[...d],T=function*(d="",g={},h){var m;const{method:T="GET",retries:j=0,backoff:O=f,jitter:v=!1,jitterFactor:R=n,backoffFactor:w=r,timeout:S=o,retryOnTimeout:C=!1,params:E,headers:P={},signal:x}=g,F=function(e,t){var o={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(o[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(r=Object.getOwnPropertySymbols(e);n{globalThis.abortController.abort(),(null==t?void 0:t.postTimeout)&&t.postTimeout(d,g)}),S):void 0,p=E?function(e,t){if(!t)return e;const o=new URL(e);return Object.entries(t).forEach((([e,t])=>o.searchParams.append(e,String(t)))),o.toString()}(o,E):o;s&&!l&&u&&(F.duplex="half"),!s&&l&&u&&(F.duplex="half"),s&&l&&u&&(F.duplex="half"),c&&u&&(F.duplex="half"),a&&u&&(F.duplex="half");const y=g.body instanceof FormData?g.body:h?JSON.stringify(h):void 0,b=Object.assign(Object.assign({method:T,signal:i?globalThis.abortSignal:null,headers:r},F),{body:y});y instanceof FormData&&b.headers.delete("Content-Type"),console.log(b);const j=fetch(p,b);clearTimeout(f);const O=yield j,v=O.headers.get("content-type"),R=v&&v.includes("application/json")?yield O.json():yield O.text();if(!O.ok)throw function(e,t){const o=`${e.status||0===e.status?e.status:""} ${e.statusText||""}`.trim(),r=new Error(o?`status code ${o}`:"an unknown error");return r.name="HTTPError",r.response=e,r.data=t,r}(O,R);return(null==t?void 0:t.postRequest)&&t.postRequest(d,g,h,[null,R]),[null,R]}catch(e){if((null==t?void 0:t.postRequest)&&e instanceof Error&&t.postRequest(d,g,h,[e,null]),e instanceof Error)if("AbortError"===e.name)console.error("Request aborted:",e);else{if(C&&"TimeoutError"===e.name&&j&&j>0){const e=v&&R?p(R):f(j,w||r);y&&console.warn(`Request timed out. Retrying in ${e}ms... (Remaining retries: ${j})`),(null==t?void 0:t.preRetry)&&t.preRetry(d,g,j,j),yield new Promise((t=>setTimeout(t,e)));const[o,n]=yield b(d,Object.assign(Object.assign({},g),{retries:j-1}),h);return(null==t?void 0:t.postRetry)&&t.postRetry(d,g,h,[o,n],j,j-1),[o,n]}if(g.retries&&g.retries>0){const e=g.jitter&&g.jitterFactor?p(g.jitterFactor):f(g.retries,g.backoffFactor?g.backoffFactor:r);y&&console.warn(`Request failed. Retrying in ${e}ms... (Remaining retries: ${g.retries})`),(null==t?void 0:t.preRetry)&&t.preRetry(d,g,g.retries,g.retries),yield new Promise((t=>setTimeout(t,e)));const[o,n]=yield b(d,Object.assign(Object.assign({},g),{retries:g.retries-1}),h);return(null==t?void 0:t.postRetry)&&t.postRetry(d,g,h,[o,n],g.retries,g.retries-1),[o,n]}}return e instanceof Error?[e,null]:[null,null]}},new((m=void 0)||(m=Promise))((function(e,t){function o(e){try{n(T.next(e))}catch(e){t(e)}}function r(e){try{n(T.throw(e))}catch(e){t(e)}}function n(t){var n;t.done?e(t.value):(n=t.value,n instanceof m?n:new m((function(e){e(n)}))).then(o,r)}n((T=T.apply(g,h||[])).next())}));var g,h,m,T},g=(e,t={})=>(o="GET",r={},n)=>b(e,Object.assign(Object.assign({method:o},t),r),n);return{get:(e,t,o)=>g(e,t)("GET",t,o),post:(e,t,o)=>g(e,t)("POST",t,o),put:(e,t,o)=>g(e,t)("PUT",t,o),delete:(e,t,o)=>g(e,t)("DELETE",t,o),patch:(e,t,o)=>g(e,t)("PATCH",t,o),options:(e,t,o)=>g(e,t)("OPTIONS",t,o),getAbortController:d}}};return t})())); +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("hypf",[],t):"object"==typeof exports?exports.hypf=t():e.hypf=t()}(self,(()=>(()=>{"use strict";var e={d:(t,o)=>{for(var r in o)e.o(o,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:o[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{default:()=>y});const o=2147483647,r=.3,n=1,i="function"==typeof globalThis.AbortController,s="function"==typeof globalThis.ReadableStream,a="function"==typeof globalThis.WritableStream,l="function"==typeof globalThis.WebSocket,c="function"==typeof globalThis.RTCPeerConnection,u=(globalThis.FormData,"undefined"!=typeof process&&"node"===process.release.name);const f=(e,t)=>1e3*Math.pow(2,e)*t,p=e=>1e3*Math.random()*e,d=()=>i?globalThis.abortController:null,y={createRequest:function(e,t,y=!1){if("undefined"==typeof fetch)throw new Error("This library is intended for use in the browser environment only.");const b=(...d)=>{return g=this,h=[...d],T=function*(d="",g={},h){var m;const{method:T="GET",retries:j=0,backoff:O=f,jitter:v=!1,jitterFactor:R=n,backoffFactor:w=r,timeout:S=o,retryOnTimeout:C=!1,params:E,headers:P={},signal:x}=g,F=function(e,t){var o={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(o[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(r=Object.getOwnPropertySymbols(e);n{globalThis.abortController.abort(),(null==t?void 0:t.postTimeout)&&t.postTimeout(d,g)}),S):void 0,p=E?function(e,t){if(!t)return e;const o=new URL(e);return Object.entries(t).forEach((([e,t])=>o.searchParams.append(e,String(t)))),o.toString()}(o,E):o;s&&!a&&u&&(F.duplex="half"),!s&&a&&u&&(F.duplex="half"),s&&a&&u&&(F.duplex="half"),c&&u&&(F.duplex="half"),l&&u&&(F.duplex="half");const y=g.body instanceof FormData?g.body:h?JSON.stringify(h):void 0,b=Object.assign(Object.assign({method:T,signal:i?globalThis.abortSignal:null,headers:r},F),{body:y});y instanceof FormData&&b.headers.delete("Content-Type");const j=fetch(p,b);clearTimeout(f);const O=yield j,v=O.headers.get("content-type"),R=v&&v.includes("application/json")?yield O.json():yield O.text();if(!O.ok)throw function(e,t){const o=`${e.status||0===e.status?e.status:""} ${e.statusText||""}`.trim(),r=new Error(o?`status code ${o}`:"an unknown error");return r.name="HTTPError",r.response=e,r.data=t,r}(O,R);return(null==t?void 0:t.postRequest)&&t.postRequest(d,g,h,[null,R]),[null,R]}catch(e){if((null==t?void 0:t.postRequest)&&e instanceof Error&&t.postRequest(d,g,h,[e,null]),e instanceof Error)if("AbortError"===e.name)console.error("Request aborted:",e);else{if(C&&"TimeoutError"===e.name&&j&&j>0){const e=v&&R?p(R):f(j,w||r);y&&console.warn(`Request timed out. Retrying in ${e}ms... (Remaining retries: ${j})`),(null==t?void 0:t.preRetry)&&t.preRetry(d,g,j,j),yield new Promise((t=>setTimeout(t,e)));const[o,n]=yield b(d,Object.assign(Object.assign({},g),{retries:j-1}),h);return(null==t?void 0:t.postRetry)&&t.postRetry(d,g,h,[o,n],j,j-1),[o,n]}if(g.retries&&g.retries>0){const e=g.jitter&&g.jitterFactor?p(g.jitterFactor):f(g.retries,g.backoffFactor?g.backoffFactor:r);y&&console.warn(`Request failed. Retrying in ${e}ms... (Remaining retries: ${g.retries})`),(null==t?void 0:t.preRetry)&&t.preRetry(d,g,g.retries,g.retries),yield new Promise((t=>setTimeout(t,e)));const[o,n]=yield b(d,Object.assign(Object.assign({},g),{retries:g.retries-1}),h);return(null==t?void 0:t.postRetry)&&t.postRetry(d,g,h,[o,n],g.retries,g.retries-1),[o,n]}}return e instanceof Error?[e,null]:[null,null]}},new((m=void 0)||(m=Promise))((function(e,t){function o(e){try{n(T.next(e))}catch(e){t(e)}}function r(e){try{n(T.throw(e))}catch(e){t(e)}}function n(t){var n;t.done?e(t.value):(n=t.value,n instanceof m?n:new m((function(e){e(n)}))).then(o,r)}n((T=T.apply(g,h||[])).next())}));var g,h,m,T},g=(e,t={})=>(o="GET",r={},n)=>b(e,Object.assign(Object.assign({method:o},t),r),n);return{get:(e,t,o)=>g(e,t)("GET",t,o),post:(e,t,o)=>g(e,t)("POST",t,o),put:(e,t,o)=>g(e,t)("PUT",t,o),delete:(e,t,o)=>g(e,t)("DELETE",t,o),patch:(e,t,o)=>g(e,t)("PATCH",t,o),options:(e,t,o)=>g(e,t)("OPTIONS",t,o),getAbortController:d}}};return t})())); //# sourceMappingURL=hyperfetch-browser.min.js.map \ No newline at end of file diff --git a/dist/hyperfetch-browser.min.js.map b/dist/hyperfetch-browser.min.js.map index 86553e2..f22772d 100644 --- a/dist/hyperfetch-browser.min.js.map +++ b/dist/hyperfetch-browser.min.js.map @@ -1 +1 @@ -{"version":3,"file":"hyperfetch-browser.min.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,OAAQ,GAAIH,GACO,iBAAZC,QACdA,QAAc,KAAID,IAElBD,EAAW,KAAIC,GAChB,CATD,CASGK,MAAM,I,mBCRT,IAAIC,EAAsB,CCA1BA,EAAwB,CAACL,EAASM,KACjC,IAAI,IAAIC,KAAOD,EACXD,EAAoBG,EAAEF,EAAYC,KAASF,EAAoBG,EAAER,EAASO,IAC5EE,OAAOC,eAAeV,EAASO,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,IAE1E,ECNDF,EAAwB,CAACQ,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,GCClFT,EAAyBL,IACH,oBAAXkB,QAA0BA,OAAOC,aAC1CV,OAAOC,eAAeV,EAASkB,OAAOC,YAAa,CAAEC,MAAO,WAE7DX,OAAOC,eAAeV,EAAS,aAAc,CAAEoB,OAAO,GAAO,G,mCCJvD,MAAMC,EAAsB,WAEtBC,EAAyB,GACzBC,EAAwB,EAExBC,EAC2B,mBAA/BC,WAAWC,gBACPC,EAC0B,mBAA9BF,WAAWG,eACPC,EAC0B,mBAA9BJ,WAAWK,eACPC,EAAuD,mBAAzBN,WAAWO,UACzCC,EAC6B,mBAAjCR,WAAWS,kBAEPC,GAD6BV,WAAWW,SAEhC,oBAAZC,SAAoD,SAAzBA,QAAQC,QAAQC,MCMpD,MAAMC,EAAiB,CAACC,EAAoBC,IAChB,IAA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,GACvDX,qBAEJ,G","sources":["webpack://hypf/webpack/universalModuleDefinition","webpack://hypf/webpack/bootstrap","webpack://hypf/webpack/runtime/define property getters","webpack://hypf/webpack/runtime/hasOwnProperty shorthand","webpack://hypf/webpack/runtime/make namespace object","webpack://hypf/./src/constant.ts","webpack://hypf/./src/Hyperfetch.ts","webpack://hypf/./src/utils/append-params.ts","webpack://hypf/./src/utils/create-http-error.ts"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"hypf\", [], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"hypf\"] = factory();\n\telse\n\t\troot[\"hypf\"] = factory();\n})(self, () => {\nreturn ","// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","// Default maximum recommended timeout in milliseconds (adjust as needed)\r\nexport const DEFAULT_MAX_TIMEOUT = 2147483647;\r\n\r\nexport const DEFAULT_BACKOFF_FACTOR = 0.3;\r\nexport const DEFAULT_JITTER_FACTOR = 1;\r\n\r\nexport const isAbortControllerSupported =\r\n typeof globalThis.AbortController === \"function\";\r\nexport const isReadableStreamSupported =\r\n typeof globalThis.ReadableStream === \"function\";\r\nexport const isWriteableStreamSupported =\r\n typeof globalThis.WritableStream === \"function\";\r\nexport const isWebsocketSupported = typeof globalThis.WebSocket === \"function\";\r\nexport const isWebRTCSupported =\r\n typeof globalThis.RTCPeerConnection === \"function\";\r\nexport const isFormDataSupported = typeof globalThis.FormData === \"function\";\r\nexport const isNode =\r\n typeof process !== \"undefined\" && process.release.name === \"node\";\r\n","import type {\r\n HttpRequestFunctions,\r\n RequestFunction,\r\n RequestOptions,\r\n HttpMethodFunction,\r\n} from \"./types/request.ts\";\r\nimport type { Hooks } from \"./types/hooks.ts\";\r\n\r\nimport {\r\n DEFAULT_BACKOFF_FACTOR,\r\n DEFAULT_JITTER_FACTOR,\r\n DEFAULT_MAX_TIMEOUT,\r\n isAbortControllerSupported,\r\n isReadableStreamSupported,\r\n isWriteableStreamSupported,\r\n isWebRTCSupported,\r\n isWebsocketSupported,\r\n isNode,\r\n} from \"./constant.js\";\r\n\r\nimport { appendParams } from \"./utils/append-params.js\";\r\nimport { createHTTPError } from \"./utils/create-http-error.js\";\r\n\r\nconst defaultBackoff = (retryCount: number, factor: number) =>\r\n Math.pow(2, retryCount) * 1000 * factor; // Exponential backoff, starting from 1 second\r\n\r\nconst defaultJitter = (factor: number) => Math.random() * 1000 * factor; // Randomized delay up to 1 second\r\n\r\n// Expose the AbortController instance through the library interface\r\nconst getAbortController = () =>\r\n isAbortControllerSupported ? globalThis.abortController : null;\r\n\r\nfunction createRequest(\r\n baseUrl?: string,\r\n hooks?: Hooks,\r\n DEBUG = false\r\n): HttpRequestFunctions {\r\n // Check if fetch is available (browser environment)\r\n if (typeof fetch === \"undefined\") {\r\n throw new Error(\r\n \"This library is intended for use in the browser environment only.\"\r\n );\r\n }\r\n\r\n const request: RequestFunction = async (\r\n url = \"\",\r\n options = {},\r\n data\r\n ): Promise<[Error | null, null]> => {\r\n const {\r\n method = \"GET\",\r\n retries = 0,\r\n backoff = defaultBackoff,\r\n jitter = false,\r\n jitterFactor = DEFAULT_JITTER_FACTOR,\r\n backoffFactor = DEFAULT_BACKOFF_FACTOR,\r\n timeout = DEFAULT_MAX_TIMEOUT,\r\n retryOnTimeout = false,\r\n params,\r\n headers = {},\r\n signal,\r\n ...otherOptions\r\n } = options;\r\n\r\n try {\r\n // Execute pre-request hook\r\n if (hooks?.preRequest) {\r\n hooks.preRequest(url, options);\r\n }\r\n\r\n const fullUrl = `${baseUrl}${url}`;\r\n\r\n const reqHeaders = new Headers(headers);\r\n\r\n // Automatically detect and add Content-Length based on payload length\r\n const textEncoder = new TextEncoder();\r\n if (!reqHeaders.get(\"Content-Length\") && data) {\r\n if (typeof data === \"string\") {\r\n reqHeaders.set(\r\n \"Content-Length\",\r\n String(textEncoder.encode(data).length)\r\n );\r\n } else if (\r\n reqHeaders.get(\"Content-Length\")?.includes(\"application/json\")\r\n ) {\r\n reqHeaders.set(\r\n \"Content-Length\",\r\n String(textEncoder.encode(JSON.stringify(data)).length)\r\n );\r\n }\r\n }\r\n\r\n // Set default Content-Type to application/json if not provided\r\n if (!reqHeaders.get(\"Content-Type\") && data && typeof data === \"object\") {\r\n if (\r\n !(((data as { body: FormData })?.body || data) instanceof FormData)\r\n ) {\r\n reqHeaders.set(\"Content-Type\", \"application/json\");\r\n }\r\n }\r\n\r\n // Execute pre-timeout hook\r\n if (hooks?.preTimeout) {\r\n hooks.preTimeout(url, options);\r\n }\r\n\r\n if (isAbortControllerSupported) {\r\n // Expose the AbortController instance\r\n globalThis.abortController = new AbortController();\r\n\r\n // Use the external AbortController instance\r\n globalThis.abortSignal = signal\r\n ? signal\r\n : globalThis.abortController.signal;\r\n }\r\n\r\n const timeoutId =\r\n timeout && isAbortControllerSupported\r\n ? setTimeout(() => {\r\n globalThis.abortController.abort();\r\n\r\n // Execute post-timeout hook\r\n if (hooks?.postTimeout) {\r\n hooks.postTimeout(url, options);\r\n }\r\n }, timeout)\r\n : undefined;\r\n\r\n // Append params to the URL\r\n const urlWithParams = params ? appendParams(fullUrl, params) : fullUrl;\r\n\r\n if (isReadableStreamSupported && !isWriteableStreamSupported && isNode) {\r\n // @ts-expect-error\r\n otherOptions.duplex = \"half\";\r\n }\r\n if (!isReadableStreamSupported && isWriteableStreamSupported && isNode) {\r\n // @ts-expect-error\r\n otherOptions.duplex = \"half\";\r\n }\r\n if (isReadableStreamSupported && isWriteableStreamSupported && isNode) {\r\n // @ts-expect-error\r\n otherOptions.duplex = \"half\";\r\n }\r\n // WebRTC is supported, allowing for full duplex communication.\r\n if (isWebRTCSupported && isNode) {\r\n // @ts-expect-error\r\n otherOptions.duplex = \"half\";\r\n }\r\n // WebSockets are supported, and thus full duplex communication is possible.\r\n if (isWebsocketSupported && isNode) {\r\n // @ts-expect-error\r\n otherOptions.duplex = \"half\";\r\n }\r\n\r\n const requestBody =\r\n options.body instanceof FormData\r\n ? options.body\r\n : data\r\n ? JSON.stringify(data)\r\n : undefined;\r\n\r\n const requestOptions = {\r\n method,\r\n signal: isAbortControllerSupported ? globalThis.abortSignal : null,\r\n headers: reqHeaders,\r\n ...otherOptions,\r\n body: requestBody,\r\n };\r\n\r\n if (requestBody instanceof FormData) {\r\n requestOptions.headers.delete(\"Content-Type\");\r\n }\r\n\r\n console.log(requestOptions);\r\n\r\n const responsePromise = fetch(urlWithParams, requestOptions);\r\n\r\n clearTimeout(timeoutId);\r\n\r\n const response = await responsePromise;\r\n\r\n const contentType = response.headers.get(\"content-type\");\r\n\r\n const responseData =\r\n contentType && contentType.includes(\"application/json\")\r\n ? await response.json()\r\n : await response.text();\r\n\r\n if (!response.ok) {\r\n throw createHTTPError(response, responseData);\r\n }\r\n\r\n // Execute post-request hook\r\n if (hooks?.postRequest) {\r\n hooks.postRequest(url, options, data, [null, responseData]);\r\n }\r\n\r\n return [null, responseData];\r\n } catch (error) {\r\n // Execute post-request hook for errors\r\n if (hooks?.postRequest) {\r\n if (error instanceof Error) {\r\n hooks.postRequest(url, options, data, [error, null]);\r\n }\r\n }\r\n\r\n if (error instanceof Error) {\r\n if (error.name === \"AbortError\") {\r\n console.error(\"Request aborted:\", error);\r\n } else if (\r\n retryOnTimeout &&\r\n error.name === \"TimeoutError\" &&\r\n retries &&\r\n retries > 0\r\n ) {\r\n const delay =\r\n jitter && jitterFactor\r\n ? defaultJitter(jitterFactor)\r\n : defaultBackoff(\r\n retries,\r\n backoffFactor ? backoffFactor : DEFAULT_BACKOFF_FACTOR\r\n );\r\n if (DEBUG) {\r\n console.warn(\r\n `Request timed out. Retrying in ${delay}ms... (Remaining retries: ${retries})`\r\n );\r\n }\r\n // Execute pre-retry hook\r\n if (hooks?.preRetry) {\r\n hooks.preRetry(url, options, retries, retries);\r\n }\r\n await new Promise((resolve) => setTimeout(resolve, delay));\r\n const [retryErr, retryData] = await request(\r\n url,\r\n { ...options, retries: retries - 1 },\r\n data\r\n );\r\n // Execute post-retry hook\r\n if (hooks?.postRetry) {\r\n hooks.postRetry(\r\n url,\r\n options,\r\n data,\r\n [retryErr, retryData],\r\n retries,\r\n retries - 1\r\n );\r\n }\r\n return [retryErr, retryData];\r\n } else if (options.retries && options.retries > 0) {\r\n const delay =\r\n options.jitter && options.jitterFactor\r\n ? defaultJitter(options.jitterFactor)\r\n : defaultBackoff(\r\n options.retries,\r\n options.backoffFactor\r\n ? options.backoffFactor\r\n : DEFAULT_BACKOFF_FACTOR\r\n );\r\n if (DEBUG) {\r\n console.warn(\r\n `Request failed. Retrying in ${delay}ms... (Remaining retries: ${options.retries})`\r\n );\r\n }\r\n // Execute pre-retry hook\r\n if (hooks?.preRetry) {\r\n hooks.preRetry(url, options, options.retries, options.retries);\r\n }\r\n await new Promise((resolve) => setTimeout(resolve, delay));\r\n const [retryErr, retryData] = await request(\r\n url,\r\n { ...options, retries: options.retries - 1 },\r\n data\r\n );\r\n // Execute post-retry hook\r\n if (hooks?.postRetry) {\r\n hooks.postRetry(\r\n url,\r\n options,\r\n data,\r\n [retryErr, retryData],\r\n options.retries,\r\n options.retries - 1\r\n );\r\n }\r\n return [retryErr, retryData];\r\n }\r\n }\r\n\r\n if (error instanceof Error) {\r\n return [error, null];\r\n }\r\n\r\n return [null, null];\r\n }\r\n };\r\n\r\n const httpMethodFunction: HttpMethodFunction =\r\n (url: string, options: RequestOptions = {}) =>\r\n (method = \"GET\", additionalOptions = {}, data) => {\r\n return request(url, { method, ...options, ...additionalOptions }, data);\r\n };\r\n\r\n return {\r\n get: (url, options, data) =>\r\n httpMethodFunction(url, options)(\"GET\", options, data),\r\n post: (url, options, data) =>\r\n httpMethodFunction(url, options)(\"POST\", options, data),\r\n put: (url, options, data) =>\r\n httpMethodFunction(url, options)(\"PUT\", options, data),\r\n delete: (url, options, data) =>\r\n httpMethodFunction(url, options)(\"DELETE\", options, data),\r\n patch: (url, options, data) =>\r\n httpMethodFunction(url, options)(\"PATCH\", options, data),\r\n options: (url, options, data) =>\r\n httpMethodFunction(url, options)(\"OPTIONS\", options, data),\r\n getAbortController,\r\n };\r\n}\r\n\r\nexport default { createRequest };\r\n","export function appendParams(\r\n url: string,\r\n params?: Record\r\n): string {\r\n if (!params) return url;\r\n\r\n const urlWithParams = new URL(url);\r\n Object.entries(params).forEach(([key, value]) =>\r\n urlWithParams.searchParams.append(key, String(value))\r\n );\r\n\r\n return urlWithParams.toString();\r\n}\r\n","export function createHTTPError(response: Response, responseData: Response) {\r\n const code = response.status || response.status === 0 ? response.status : \"\";\r\n const title = response.statusText || \"\";\r\n const status = `${code} ${title}`.trim();\r\n const reason = status ? `status code ${status}` : \"an unknown error\";\r\n const error = new Error(reason);\r\n\r\n error.name = \"HTTPError\";\r\n\r\n (error as any).response = response;\r\n (error as any).data = responseData;\r\n\r\n return error;\r\n}\r\n"],"names":["root","factory","exports","module","define","amd","self","__webpack_require__","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","DEFAULT_MAX_TIMEOUT","DEFAULT_BACKOFF_FACTOR","DEFAULT_JITTER_FACTOR","isAbortControllerSupported","globalThis","AbortController","isReadableStreamSupported","ReadableStream","isWriteableStreamSupported","WritableStream","isWebsocketSupported","WebSocket","isWebRTCSupported","RTCPeerConnection","isNode","FormData","process","release","name","defaultBackoff","retryCount","factor","Math","pow","defaultJitter","random","getAbortController","abortController","createRequest","baseUrl","hooks","DEBUG","fetch","Error","request","url","options","data","method","retries","backoff","jitter","jitterFactor","backoffFactor","timeout","retryOnTimeout","params","headers","signal","otherOptions","preRequest","fullUrl","reqHeaders","Headers","textEncoder","TextEncoder","set","String","encode","length","includes","JSON","stringify","body","preTimeout","abortSignal","timeoutId","setTimeout","abort","postTimeout","undefined","urlWithParams","URL","entries","forEach","searchParams","append","toString","appendParams","duplex","requestBody","requestOptions","delete","console","log","responsePromise","clearTimeout","response","contentType","responseData","json","text","ok","status","statusText","trim","error","createHTTPError","postRequest","delay","warn","preRetry","Promise","resolve","retryErr","retryData","postRetry","httpMethodFunction","additionalOptions","post","put","patch"],"sourceRoot":""} \ No newline at end of file +{"version":3,"file":"hyperfetch-browser.min.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,OAAQ,GAAIH,GACO,iBAAZC,QACdA,QAAc,KAAID,IAElBD,EAAW,KAAIC,GAChB,CATD,CASGK,MAAM,I,mBCRT,IAAIC,EAAsB,CCA1BA,EAAwB,CAACL,EAASM,KACjC,IAAI,IAAIC,KAAOD,EACXD,EAAoBG,EAAEF,EAAYC,KAASF,EAAoBG,EAAER,EAASO,IAC5EE,OAAOC,eAAeV,EAASO,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,IAE1E,ECNDF,EAAwB,CAACQ,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,GCClFT,EAAyBL,IACH,oBAAXkB,QAA0BA,OAAOC,aAC1CV,OAAOC,eAAeV,EAASkB,OAAOC,YAAa,CAAEC,MAAO,WAE7DX,OAAOC,eAAeV,EAAS,aAAc,CAAEoB,OAAO,GAAO,G,mCCJvD,MAAMC,EAAsB,WAEtBC,EAAyB,GACzBC,EAAw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EAASC,IACrBqE,EAAmBvE,EAAKC,EAAxBsE,CAAiC,SAAUtE,EAASC,GACtDyE,MAAO,CAAC3E,EAAKC,EAASC,IACpBqE,EAAmBvE,EAAKC,EAAxBsE,CAAiC,QAAStE,EAASC,GACrDD,QAAS,CAACD,EAAKC,EAASC,IACtBqE,EAAmBvE,EAAKC,EAAxBsE,CAAiC,UAAWtE,EAASC,GACvDX,qBAEJ,G","sources":["webpack://hypf/webpack/universalModuleDefinition","webpack://hypf/webpack/bootstrap","webpack://hypf/webpack/runtime/define property getters","webpack://hypf/webpack/runtime/hasOwnProperty shorthand","webpack://hypf/webpack/runtime/make namespace object","webpack://hypf/./src/constant.ts","webpack://hypf/./src/Hyperfetch.ts","webpack://hypf/./src/utils/append-params.ts","webpack://hypf/./src/utils/create-http-error.ts"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"hypf\", [], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"hypf\"] = factory();\n\telse\n\t\troot[\"hypf\"] = factory();\n})(self, () => {\nreturn ","// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","// Default maximum recommended timeout in milliseconds (adjust as needed)\r\nexport const DEFAULT_MAX_TIMEOUT = 2147483647;\r\n\r\nexport const DEFAULT_BACKOFF_FACTOR = 0.3;\r\nexport const DEFAULT_JITTER_FACTOR = 1;\r\n\r\nexport const isAbortControllerSupported =\r\n typeof globalThis.AbortController === \"function\";\r\nexport const isReadableStreamSupported =\r\n typeof globalThis.ReadableStream === \"function\";\r\nexport const isWriteableStreamSupported =\r\n typeof globalThis.WritableStream === \"function\";\r\nexport const isWebsocketSupported = typeof globalThis.WebSocket === \"function\";\r\nexport const isWebRTCSupported =\r\n typeof globalThis.RTCPeerConnection === \"function\";\r\nexport const isFormDataSupported = typeof globalThis.FormData === \"function\";\r\nexport const isNode =\r\n typeof process !== \"undefined\" && process.release.name === \"node\";\r\n","import type {\r\n HttpRequestFunctions,\r\n RequestFunction,\r\n RequestOptions,\r\n HttpMethodFunction,\r\n} from \"./types/request.ts\";\r\nimport type { Hooks } from \"./types/hooks.ts\";\r\n\r\nimport {\r\n DEFAULT_BACKOFF_FACTOR,\r\n DEFAULT_JITTER_FACTOR,\r\n DEFAULT_MAX_TIMEOUT,\r\n isAbortControllerSupported,\r\n isReadableStreamSupported,\r\n isWriteableStreamSupported,\r\n isWebRTCSupported,\r\n isWebsocketSupported,\r\n isNode,\r\n} from \"./constant.js\";\r\n\r\nimport { appendParams } from \"./utils/append-params.js\";\r\nimport { createHTTPError } from \"./utils/create-http-error.js\";\r\n\r\nconst defaultBackoff = (retryCount: number, factor: number) =>\r\n Math.pow(2, retryCount) * 1000 * factor; // Exponential backoff, starting from 1 second\r\n\r\nconst defaultJitter = (factor: number) => Math.random() * 1000 * factor; // Randomized delay up to 1 second\r\n\r\n// Expose the AbortController instance through the library interface\r\nconst getAbortController = () =>\r\n isAbortControllerSupported ? globalThis.abortController : null;\r\n\r\nfunction createRequest(\r\n baseUrl?: string,\r\n hooks?: Hooks,\r\n DEBUG = false\r\n): HttpRequestFunctions {\r\n // Check if fetch is available (browser environment)\r\n if (typeof fetch === \"undefined\") {\r\n throw new Error(\r\n \"This library is intended for use in the browser environment only.\"\r\n );\r\n }\r\n\r\n const request: RequestFunction = async (\r\n url = \"\",\r\n options = {},\r\n data\r\n ): Promise<[Error | null, null]> => {\r\n const {\r\n method = \"GET\",\r\n retries = 0,\r\n backoff = defaultBackoff,\r\n jitter = false,\r\n jitterFactor = DEFAULT_JITTER_FACTOR,\r\n backoffFactor = DEFAULT_BACKOFF_FACTOR,\r\n timeout = DEFAULT_MAX_TIMEOUT,\r\n retryOnTimeout = false,\r\n params,\r\n headers = {},\r\n signal,\r\n ...otherOptions\r\n } = options;\r\n\r\n try {\r\n // Execute pre-request hook\r\n if (hooks?.preRequest) {\r\n hooks.preRequest(url, options);\r\n }\r\n\r\n const fullUrl = `${baseUrl}${url}`;\r\n\r\n const reqHeaders = new Headers(headers);\r\n\r\n // Automatically detect and add Content-Length based on payload length\r\n const textEncoder = new TextEncoder();\r\n if (!reqHeaders.get(\"Content-Length\") && data) {\r\n if (typeof data === \"string\") {\r\n reqHeaders.set(\r\n \"Content-Length\",\r\n String(textEncoder.encode(data).length)\r\n );\r\n } else if (\r\n reqHeaders.get(\"Content-Length\")?.includes(\"application/json\")\r\n ) {\r\n reqHeaders.set(\r\n \"Content-Length\",\r\n String(textEncoder.encode(JSON.stringify(data)).length)\r\n );\r\n }\r\n }\r\n\r\n // Set default Content-Type to application/json if not provided\r\n if (!reqHeaders.get(\"Content-Type\") && data && typeof data === \"object\") {\r\n if (\r\n !(((data as { body: FormData })?.body || data) instanceof FormData)\r\n ) {\r\n reqHeaders.set(\"Content-Type\", \"application/json\");\r\n }\r\n }\r\n\r\n // Execute pre-timeout hook\r\n if (hooks?.preTimeout) {\r\n hooks.preTimeout(url, options);\r\n }\r\n\r\n if (isAbortControllerSupported) {\r\n // Expose the AbortController instance\r\n globalThis.abortController = new AbortController();\r\n\r\n // Use the external AbortController instance\r\n globalThis.abortSignal = signal\r\n ? signal\r\n : globalThis.abortController.signal;\r\n }\r\n\r\n const timeoutId =\r\n timeout && isAbortControllerSupported\r\n ? setTimeout(() => {\r\n globalThis.abortController.abort();\r\n\r\n // Execute post-timeout hook\r\n if (hooks?.postTimeout) {\r\n hooks.postTimeout(url, options);\r\n }\r\n }, timeout)\r\n : undefined;\r\n\r\n // Append params to the URL\r\n const urlWithParams = params ? appendParams(fullUrl, params) : fullUrl;\r\n\r\n if (isReadableStreamSupported && !isWriteableStreamSupported && isNode) {\r\n // @ts-expect-error\r\n otherOptions.duplex = \"half\";\r\n }\r\n if (!isReadableStreamSupported && isWriteableStreamSupported && isNode) {\r\n // @ts-expect-error\r\n otherOptions.duplex = \"half\";\r\n }\r\n if (isReadableStreamSupported && isWriteableStreamSupported && isNode) {\r\n // @ts-expect-error\r\n otherOptions.duplex = \"half\";\r\n }\r\n // WebRTC is supported, allowing for full duplex communication.\r\n if (isWebRTCSupported && isNode) {\r\n // @ts-expect-error\r\n otherOptions.duplex = \"half\";\r\n }\r\n // WebSockets are supported, and thus full duplex communication is possible.\r\n if (isWebsocketSupported && isNode) {\r\n // @ts-expect-error\r\n otherOptions.duplex = \"half\";\r\n }\r\n\r\n const requestBody =\r\n options.body instanceof FormData\r\n ? options.body\r\n : data\r\n ? JSON.stringify(data)\r\n : undefined;\r\n\r\n const requestOptions = {\r\n method,\r\n signal: isAbortControllerSupported ? globalThis.abortSignal : null,\r\n headers: reqHeaders,\r\n ...otherOptions,\r\n body: requestBody,\r\n };\r\n\r\n if (requestBody instanceof FormData) {\r\n requestOptions.headers.delete(\"Content-Type\");\r\n }\r\n\r\n const responsePromise = fetch(urlWithParams, requestOptions);\r\n\r\n clearTimeout(timeoutId);\r\n\r\n const response = await responsePromise;\r\n\r\n const contentType = response.headers.get(\"content-type\");\r\n\r\n const responseData =\r\n contentType && contentType.includes(\"application/json\")\r\n ? await response.json()\r\n : await response.text();\r\n\r\n if (!response.ok) {\r\n throw createHTTPError(response, responseData);\r\n }\r\n\r\n // Execute post-request hook\r\n if (hooks?.postRequest) {\r\n hooks.postRequest(url, options, data, [null, responseData]);\r\n }\r\n\r\n return [null, responseData];\r\n } catch (error) {\r\n // Execute post-request hook for errors\r\n if (hooks?.postRequest) {\r\n if (error instanceof Error) {\r\n hooks.postRequest(url, options, data, [error, null]);\r\n }\r\n }\r\n\r\n if (error instanceof Error) {\r\n if (error.name === \"AbortError\") {\r\n console.error(\"Request aborted:\", error);\r\n } else if (\r\n retryOnTimeout &&\r\n error.name === \"TimeoutError\" &&\r\n retries &&\r\n retries > 0\r\n ) {\r\n const delay =\r\n jitter && jitterFactor\r\n ? defaultJitter(jitterFactor)\r\n : defaultBackoff(\r\n retries,\r\n backoffFactor ? backoffFactor : DEFAULT_BACKOFF_FACTOR\r\n );\r\n if (DEBUG) {\r\n console.warn(\r\n `Request timed out. Retrying in ${delay}ms... (Remaining retries: ${retries})`\r\n );\r\n }\r\n // Execute pre-retry hook\r\n if (hooks?.preRetry) {\r\n hooks.preRetry(url, options, retries, retries);\r\n }\r\n await new Promise((resolve) => setTimeout(resolve, delay));\r\n const [retryErr, retryData] = await request(\r\n url,\r\n { ...options, retries: retries - 1 },\r\n data\r\n );\r\n // Execute post-retry hook\r\n if (hooks?.postRetry) {\r\n hooks.postRetry(\r\n url,\r\n options,\r\n data,\r\n [retryErr, retryData],\r\n retries,\r\n retries - 1\r\n );\r\n }\r\n return [retryErr, retryData];\r\n } else if (options.retries && options.retries > 0) {\r\n const delay =\r\n options.jitter && options.jitterFactor\r\n ? defaultJitter(options.jitterFactor)\r\n : defaultBackoff(\r\n options.retries,\r\n options.backoffFactor\r\n ? options.backoffFactor\r\n : DEFAULT_BACKOFF_FACTOR\r\n );\r\n if (DEBUG) {\r\n console.warn(\r\n `Request failed. Retrying in ${delay}ms... (Remaining retries: ${options.retries})`\r\n );\r\n }\r\n // Execute pre-retry hook\r\n if (hooks?.preRetry) {\r\n hooks.preRetry(url, options, options.retries, options.retries);\r\n }\r\n await new Promise((resolve) => setTimeout(resolve, delay));\r\n const [retryErr, retryData] = await request(\r\n url,\r\n { ...options, retries: options.retries - 1 },\r\n data\r\n );\r\n // Execute post-retry hook\r\n if (hooks?.postRetry) {\r\n hooks.postRetry(\r\n url,\r\n options,\r\n data,\r\n [retryErr, retryData],\r\n options.retries,\r\n options.retries - 1\r\n );\r\n }\r\n return [retryErr, retryData];\r\n }\r\n }\r\n\r\n if (error instanceof Error) {\r\n return [error, null];\r\n }\r\n\r\n return [null, null];\r\n }\r\n };\r\n\r\n const httpMethodFunction: HttpMethodFunction =\r\n (url: string, options: RequestOptions = {}) =>\r\n (method = \"GET\", additionalOptions = {}, data) => {\r\n return request(url, { method, ...options, ...additionalOptions }, data);\r\n };\r\n\r\n return {\r\n get: (url, options, data) =>\r\n httpMethodFunction(url, options)(\"GET\", options, data),\r\n post: (url, options, data) =>\r\n httpMethodFunction(url, options)(\"POST\", options, data),\r\n put: (url, options, data) =>\r\n httpMethodFunction(url, options)(\"PUT\", options, data),\r\n delete: (url, options, data) =>\r\n httpMethodFunction(url, options)(\"DELETE\", options, data),\r\n patch: (url, options, data) =>\r\n httpMethodFunction(url, options)(\"PATCH\", options, data),\r\n options: (url, options, data) =>\r\n httpMethodFunction(url, options)(\"OPTIONS\", options, data),\r\n getAbortController,\r\n };\r\n}\r\n\r\nexport default { createRequest };\r\n","export function appendParams(\r\n url: string,\r\n params?: Record\r\n): string {\r\n if (!params) return url;\r\n\r\n const urlWithParams = new URL(url);\r\n Object.entries(params).forEach(([key, value]) =>\r\n urlWithParams.searchParams.append(key, String(value))\r\n );\r\n\r\n return urlWithParams.toString();\r\n}\r\n","export function createHTTPError(response: Response, responseData: Response) {\r\n const code = response.status || response.status === 0 ? response.status : \"\";\r\n const title = response.statusText || \"\";\r\n const status = `${code} ${title}`.trim();\r\n const reason = status ? `status code ${status}` : \"an unknown error\";\r\n const error = new Error(reason);\r\n\r\n error.name = \"HTTPError\";\r\n\r\n (error as any).response = response;\r\n (error as any).data = responseData;\r\n\r\n return error;\r\n}\r\n"],"names":["root","factory","exports","module","define","amd","self","__webpack_require__","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","DEFAULT_MAX_TIMEOUT","DEFAULT_BACKOFF_FACTOR","DEFAULT_JITTER_FACTOR","isAbortControllerSupported","globalThis","AbortController","isReadableStreamSupported","ReadableStream","isWriteableStreamSupported","WritableStream","isWebsocketSupported","WebSocket","isWebRTCSupported","RTCPeerConnection","isNode","FormData","process","release","name","defaultBackoff","retryCount","factor","Math","pow","defaultJitter","random","getAbortController","abortController","createRequest","baseUrl","hooks","DEBUG","fetch","Error","request","url","options","data","method","retries","backoff","jitter","jitterFactor","backoffFactor","timeout","retryOnTimeout","params","headers","signal","otherOptions","preRequest","fullUrl","reqHeaders","Headers","textEncoder","TextEncoder","set","String","encode","length","includes","JSON","stringify","body","preTimeout","abortSignal","timeoutId","setTimeout","abort","postTimeout","undefined","urlWithParams","URL","entries","forEach","searchParams","append","toString","appendParams","duplex","requestBody","requestOptions","delete","responsePromise","clearTimeout","response","contentType","responseData","json","text","ok","status","statusText","trim","error","createHTTPError","postRequest","console","delay","warn","preRetry","Promise","resolve","retryErr","retryData","postRetry","httpMethodFunction","additionalOptions","post","put","patch"],"sourceRoot":""} \ No newline at end of file diff --git a/package.json b/package.json index a6f142f..51e5b16 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hypf", - "version": "0.0.9", + "version": "0.1.0", "description": "Supertiny and stunning HTTP client for frontend apps. Best frontend wrapper for Fetch API.", "main": "./dist/Hyperfetch.js", "repository": "fzn0x/hypf",