@hyper-fetch/axios 8.1.0 โ†’ 8.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # ๐Ÿ›๏ธ Hyper Fetch Axios
2
2
 
3
- <p>
3
+ <p align="center">
4
+ <b>Use Axios as the HTTP engine for HyperFetch. Drop-in replacement with interceptors and all Axios features.</b>
5
+ </p>
6
+
7
+ <p align="center">
4
8
  <a href="https://bettertyped.com/">
5
9
  <img src="https://custom-icon-badges.demolab.com/static/v1?label=&message=BetterTyped&color=333&logo=BT" />
6
10
  </a>
@@ -13,57 +17,87 @@
13
17
  <a href="https://www.npmjs.com/package/@hyper-fetch/axios">
14
18
  <img src="https://custom-icon-badges.demolab.com/npm/v/@hyper-fetch/axios.svg?logo=npm&color=e76f51" />
15
19
  </a>
16
- <a href="https://github.com/BetterTyped/hyper-fetch">
17
- <img src="https://custom-icon-badges.demolab.com/badge/typescript-%23007ACC.svg?logo=typescript&logoColor=white" />
20
+ <a href="https://www.npmjs.com/package/@hyper-fetch/axios">
21
+ <img src="https://custom-icon-badges.demolab.com/npm/dm/@hyper-fetch/axios?logoColor=fff&logo=trending-up" />
18
22
  </a>
19
23
  <a href="https://github.com/BetterTyped/hyper-fetch">
20
- <img src="https://custom-icon-badges.demolab.com/badge/-Axios-E10098?logo=axios&logoColor=white" />
24
+ <img src="https://custom-icon-badges.demolab.com/badge/typescript-%23007ACC.svg?logo=typescript&logoColor=white" />
21
25
  </a>
22
- <a href="https://www.npmjs.com/package/@hyper-fetch/axios">
26
+ <a href="https://bundlephobia.com/package/@hyper-fetch/axios">
23
27
  <img src="https://custom-icon-badges.demolab.com/bundlephobia/minzip/@hyper-fetch/axios?color=64BC4B&logo=package" />
24
28
  </a>
25
29
  </p>
26
30
 
27
- ## About
31
+ ## ๐Ÿ“– About
32
+
33
+ This adapter replaces HyperFetch's built-in HTTP engine with Axios. You get all of Axios's features โ€” interceptors, automatic JSON transforms, request/response transforms โ€” while keeping HyperFetch's typed request system, caching, queuing, and React hooks.
34
+
35
+ ## ๐ŸŽฏ Key Capabilities
36
+
37
+ - ๐Ÿ”Œ **One line to switch** โ€” Replace the default HTTP engine with Axios without touching your requests
38
+ - ๐ŸŽฏ **Keep your interceptors** โ€” Use existing Axios request/response interceptors and error transforms
39
+ - โœจ **All HyperFetch features stay** โ€” Caching, queuing, types, offline support, React hooks โ€” nothing lost
40
+ - ๐Ÿ”ง **Bring your own instance** โ€” Pass a pre-configured Axios instance with custom defaults and auth headers
28
41
 
29
- **`Hyper Fetch Axios`** is adapter for Hyper Fetch. It enables seamless communication with Axios, simplifying the
30
- retrieval and manipulation of data. Benefit from the convenience and efficiency of Hyper Fetch.
42
+ ## ๐Ÿš€ Quick Start
31
43
 
32
- ## Features
44
+ ```bash
45
+ npm install @hyper-fetch/core @hyper-fetch/axios axios
46
+ ```
33
47
 
34
- ๐Ÿ”ฎ **Simple setup** - [Read more](https://hyperfetch.bettertyped.com/docs/guides/basic/setup)
48
+ ```ts
49
+ import { createClient } from "@hyper-fetch/core";
50
+ import { AxiosAdapter } from "@hyper-fetch/axios";
35
51
 
36
- ๐ŸŽฏ **Request cancellation** - [Read more](https://hyperfetch.bettertyped.com/docs/guides/advanced/cancellation)
52
+ const client = createClient({ url: "https://api.example.com" }).setAdapter(AxiosAdapter());
53
+ ```
37
54
 
38
- โœจ **Window Focus/Blur Events** -
39
- [Read more](https://hyperfetch.bettertyped.com/docs/guides/react/core/window-focus-blur)
55
+ ## ๐Ÿ“š Documentation
40
56
 
41
- ๐Ÿš€ **Queueing** - [Read more](https://hyperfetch.bettertyped.com/docs/guides/advanced/queueing)
57
+ - [Axios Adapter Docs](https://hyperfetch.bettertyped.com/docs/integrations/adapter-axios)
58
+ - [Getting Started](https://hyperfetch.bettertyped.com/docs/getting-started/quick-start)
59
+ - [API Reference](https://hyperfetch.bettertyped.com/api/)
42
60
 
43
- ๐Ÿ’Ž **Automatic caching** - [Read more](https://hyperfetch.bettertyped.com/docs/core/cache)
61
+ ## ๐Ÿ’ก Examples
44
62
 
45
- ๐Ÿช„ **Persistence** - [Read more](https://hyperfetch.bettertyped.com/docs/guides/advanced/persistence)
63
+ ### Use with Axios interceptors
46
64
 
47
- ๐ŸŽŠ **SSR Support** - [Read more](https://hyperfetch.bettertyped.com/docs/getting-started/environment)
65
+ ```ts
66
+ import axios from "axios";
67
+ import { createClient } from "@hyper-fetch/core";
68
+ import { AxiosAdapter } from "@hyper-fetch/axios";
48
69
 
49
- ๐Ÿ”‹ **Offline First** - [Read more](https://hyperfetch.bettertyped.com/docs/guides/advanced/offline)
70
+ const axiosInstance = axios.create({ baseURL: "https://api.example.com" });
50
71
 
51
- ๐Ÿ“ก **Built-in adapter** - [Read more](https://hyperfetch.bettertyped.com/docs/core/adapter)
72
+ axiosInstance.interceptors.request.use((config) => {
73
+ config.headers.Authorization = `Bearer ${getToken()}`;
74
+ return config;
75
+ });
52
76
 
53
- ๐Ÿงช **Easy to test** - [Read more](https://hyperfetch.bettertyped.com/docs/getting-started/testing)
77
+ axiosInstance.interceptors.response.use(
78
+ (response) => response,
79
+ (error) => {
80
+ if (error.response?.status === 401) refreshToken();
81
+ return Promise.reject(error);
82
+ },
83
+ );
54
84
 
55
- ๐ŸŽŸ **Authentication** - [Read more](https://hyperfetch.bettertyped.com/docs/guides/basic/authentication)
85
+ const client = createClient({ url: "https://api.example.com" }).setAdapter(
86
+ AxiosAdapter({ instance: axiosInstance }),
87
+ );
88
+ ```
56
89
 
57
- ๐Ÿ’ก **Prefetching** - [Read more](https://hyperfetch.bettertyped.com/docs/guides/advanced/prefetching)
90
+ ### Create typed requests (same as core)
58
91
 
59
- ## Help us keep working on this project โค๏ธ
92
+ ```ts
93
+ const getUsers = client.createRequest<{ response: User[] }>()({
94
+ endpoint: "/users",
95
+ method: "GET",
96
+ });
60
97
 
61
- - [Become a Sponsor on GitHub](https://github.com/sponsors/prc5)
98
+ const { data, error } = await getUsers.send();
99
+ ```
62
100
 
63
- ## Sources
101
+ ## License
64
102
 
65
- - #### [Installation](https://hyperfetch.bettertyped.com/docs/getting-started/installation)
66
- - #### [Docs](https://hyperfetch.bettertyped.com/)
67
- - #### [API](https://hyperfetch.bettertyped.com/api/)
68
- - #### [NPM](https://www.npmjs.com/package/@hyper-fetch/axios)
69
- - #### [Guides](https://hyperfetch.bettertyped.com/guides/Basic/Setup)
103
+ [MIT](https://github.com/BetterTyped/hyper-fetch/blob/main/License.md)
@@ -2,5 +2,6 @@ import { Adapter } from '@hyper-fetch/core';
2
2
  import { Method as AxiosMethods, AxiosRequestConfig } from 'axios';
3
3
  import { AxiosExtra } from './adapter.types';
4
4
  export type AxiosAdapterType = typeof AxiosAdapter;
5
+ /** Pre-configured adapter that uses Axios as the underlying HTTP transport. Supports upload/download progress and abort. */
5
6
  export declare const AxiosAdapter: Adapter<Omit<AxiosRequestConfig<any>, "url" | "baseURL" | "method" | "onUploadProgress" | "onDownloadProgress" | "data">, AxiosMethods, number, AxiosExtra, string | import('@hyper-fetch/core').QueryParamsType | import('@hyper-fetch/core').EmptyTypes, undefined, string, import('@hyper-fetch/core').DefaultMapperType, (queryParams: import('@hyper-fetch/core').QueryParamsType | string | import('@hyper-fetch/core').EmptyTypes, options?: import('@hyper-fetch/core').QueryStringifyOptionsType) => string, import('@hyper-fetch/core').DefaultMapperType, import('@hyper-fetch/core').DefaultMapperType>;
6
7
  //# sourceMappingURL=adapter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/adapter/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAwB,MAAM,mBAAmB,CAAC;AAClE,OAAO,KAAK,EAAE,MAAM,IAAI,YAAY,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAGxE,OAAO,KAAK,EAAE,UAAU,EAAmB,MAAM,iBAAiB,CAAC;AAEnE,MAAM,MAAM,gBAAgB,GAAG,OAAO,YAAY,CAAC;AAEnD,eAAO,MAAM,YAAY,qlBAgFtB,CAAC"}
1
+ {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/adapter/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAwB,MAAM,mBAAmB,CAAC;AAClE,OAAO,KAAK,EAAE,MAAM,IAAI,YAAY,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAGxE,OAAO,KAAK,EAAE,UAAU,EAAmB,MAAM,iBAAiB,CAAC;AAEnE,MAAM,MAAM,gBAAgB,GAAG,OAAO,YAAY,CAAC;AAEnD,4HAA4H;AAC5H,eAAO,MAAM,YAAY,qlBAgFtB,CAAC"}
package/dist/index.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Adapter, stringifyQueryParams } from "@hyper-fetch/core";
2
2
  import axios, { AxiosHeaders } from "axios";
3
3
  //#region src/adapter/adapter.ts
4
+ /** Pre-configured adapter that uses Axios as the underlying HTTP transport. Supports upload/download progress and abort. */
4
5
  var AxiosAdapter = new Adapter({
5
6
  name: "axios-adapter",
6
7
  defaultMethod: "GET",
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/adapter/adapter.ts"],"sourcesContent":["import { Adapter, stringifyQueryParams } from \"@hyper-fetch/core\";\nimport type { Method as AxiosMethods, AxiosRequestConfig } from \"axios\";\nimport axios, { AxiosHeaders } from \"axios\";\n\nimport type { AxiosExtra, RawAxiosHeaders } from \"./adapter.types\";\n\nexport type AxiosAdapterType = typeof AxiosAdapter;\n\nexport const AxiosAdapter = new Adapter<\n Omit<AxiosRequestConfig, \"url\" | \"baseURL\" | \"method\" | \"onUploadProgress\" | \"onDownloadProgress\" | \"data\">,\n AxiosMethods,\n number,\n AxiosExtra\n>({\n name: \"axios-adapter\",\n defaultMethod: \"GET\",\n defaultExtra: { headers: {} },\n systemErrorStatus: 0,\n systemErrorExtra: { headers: {} },\n})\n .setQueryParamsMapper(stringifyQueryParams)\n .setFetcher(\n async ({\n url,\n endpoint,\n queryParams,\n request,\n headers,\n payload,\n adapter,\n adapterOptions,\n onError,\n onResponseEnd,\n onRequestEnd,\n createAbortListener,\n onResponseProgress,\n onRequestProgress,\n onResponseStart,\n onBeforeRequest,\n onRequestStart,\n onSuccess,\n getAbortController,\n }) => {\n const { method } = request;\n\n const fullUrl = `${url}${endpoint}${queryParams}`;\n\n onBeforeRequest();\n\n const controller = getAbortController();\n const unmountListener = () =>\n createAbortListener({\n status: 0,\n extra: { headers: {} },\n });\n\n onRequestStart();\n axios({\n ...adapterOptions,\n data: payload,\n method,\n url: fullUrl,\n signal: controller?.signal,\n headers: new AxiosHeaders(headers as RawAxiosHeaders),\n onUploadProgress: (progressEvent) => {\n onRequestProgress(progressEvent);\n },\n onDownloadProgress: (progressEvent) => {\n onRequestEnd();\n onResponseStart();\n onResponseProgress(progressEvent);\n },\n })\n .then((response) => {\n onSuccess({ data: response.data, status: response.status, extra: { headers: response.headers } });\n onResponseEnd();\n })\n .catch((error) => {\n onError({\n error,\n status: error.response?.status || adapter.systemErrorStatus,\n extra: { headers: error.response?.headers },\n });\n })\n .finally(() => {\n unmountListener();\n });\n },\n );\n"],"mappings":";;;AAQA,IAAa,eAAe,IAAI,QAK9B;CACA,MAAM;CACN,eAAe;CACf,cAAc,EAAE,SAAS,EAAE,EAAE;CAC7B,mBAAmB;CACnB,kBAAkB,EAAE,SAAS,EAAE,EAAE;CAClC,CAAC,CACC,qBAAqB,qBAAqB,CAC1C,WACC,OAAO,EACL,KACA,UACA,aACA,SACA,SACA,SACA,SACA,gBACA,SACA,eACA,cACA,qBACA,oBACA,mBACA,iBACA,iBACA,gBACA,WACA,yBACI;CACJ,MAAM,EAAE,WAAW;CAEnB,MAAM,UAAU,GAAG,MAAM,WAAW;AAEpC,kBAAiB;CAEjB,MAAM,aAAa,oBAAoB;CACvC,MAAM,wBACJ,oBAAoB;EAClB,QAAQ;EACR,OAAO,EAAE,SAAS,EAAE,EAAE;EACvB,CAAC;AAEJ,iBAAgB;AAChB,OAAM;EACJ,GAAG;EACH,MAAM;EACN;EACA,KAAK;EACL,QAAQ,YAAY;EACpB,SAAS,IAAI,aAAa,QAA2B;EACrD,mBAAmB,kBAAkB;AACnC,qBAAkB,cAAc;;EAElC,qBAAqB,kBAAkB;AACrC,iBAAc;AACd,oBAAiB;AACjB,sBAAmB,cAAc;;EAEpC,CAAC,CACC,MAAM,aAAa;AAClB,YAAU;GAAE,MAAM,SAAS;GAAM,QAAQ,SAAS;GAAQ,OAAO,EAAE,SAAS,SAAS,SAAS;GAAE,CAAC;AACjG,iBAAe;GACf,CACD,OAAO,UAAU;AAChB,UAAQ;GACN;GACA,QAAQ,MAAM,UAAU,UAAU,QAAQ;GAC1C,OAAO,EAAE,SAAS,MAAM,UAAU,SAAS;GAC5C,CAAC;GACF,CACD,cAAc;AACb,mBAAiB;GACjB;EAEP"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/adapter/adapter.ts"],"sourcesContent":["import { Adapter, stringifyQueryParams } from \"@hyper-fetch/core\";\nimport type { Method as AxiosMethods, AxiosRequestConfig } from \"axios\";\nimport axios, { AxiosHeaders } from \"axios\";\n\nimport type { AxiosExtra, RawAxiosHeaders } from \"./adapter.types\";\n\nexport type AxiosAdapterType = typeof AxiosAdapter;\n\n/** Pre-configured adapter that uses Axios as the underlying HTTP transport. Supports upload/download progress and abort. */\nexport const AxiosAdapter = new Adapter<\n Omit<AxiosRequestConfig, \"url\" | \"baseURL\" | \"method\" | \"onUploadProgress\" | \"onDownloadProgress\" | \"data\">,\n AxiosMethods,\n number,\n AxiosExtra\n>({\n name: \"axios-adapter\",\n defaultMethod: \"GET\",\n defaultExtra: { headers: {} },\n systemErrorStatus: 0,\n systemErrorExtra: { headers: {} },\n})\n .setQueryParamsMapper(stringifyQueryParams)\n .setFetcher(\n async ({\n url,\n endpoint,\n queryParams,\n request,\n headers,\n payload,\n adapter,\n adapterOptions,\n onError,\n onResponseEnd,\n onRequestEnd,\n createAbortListener,\n onResponseProgress,\n onRequestProgress,\n onResponseStart,\n onBeforeRequest,\n onRequestStart,\n onSuccess,\n getAbortController,\n }) => {\n const { method } = request;\n\n const fullUrl = `${url}${endpoint}${queryParams}`;\n\n onBeforeRequest();\n\n const controller = getAbortController();\n const unmountListener = () =>\n createAbortListener({\n status: 0,\n extra: { headers: {} },\n });\n\n onRequestStart();\n axios({\n ...adapterOptions,\n data: payload,\n method,\n url: fullUrl,\n signal: controller?.signal,\n headers: new AxiosHeaders(headers as RawAxiosHeaders),\n onUploadProgress: (progressEvent) => {\n onRequestProgress(progressEvent);\n },\n onDownloadProgress: (progressEvent) => {\n onRequestEnd();\n onResponseStart();\n onResponseProgress(progressEvent);\n },\n })\n .then((response) => {\n onSuccess({ data: response.data, status: response.status, extra: { headers: response.headers } });\n onResponseEnd();\n })\n .catch((error) => {\n onError({\n error,\n status: error.response?.status || adapter.systemErrorStatus,\n extra: { headers: error.response?.headers },\n });\n })\n .finally(() => {\n unmountListener();\n });\n },\n );\n"],"mappings":";;;;AASA,IAAa,eAAe,IAAI,QAK9B;CACA,MAAM;CACN,eAAe;CACf,cAAc,EAAE,SAAS,EAAE,EAAE;CAC7B,mBAAmB;CACnB,kBAAkB,EAAE,SAAS,EAAE,EAAE;CAClC,CAAC,CACC,qBAAqB,qBAAqB,CAC1C,WACC,OAAO,EACL,KACA,UACA,aACA,SACA,SACA,SACA,SACA,gBACA,SACA,eACA,cACA,qBACA,oBACA,mBACA,iBACA,iBACA,gBACA,WACA,yBACI;CACJ,MAAM,EAAE,WAAW;CAEnB,MAAM,UAAU,GAAG,MAAM,WAAW;AAEpC,kBAAiB;CAEjB,MAAM,aAAa,oBAAoB;CACvC,MAAM,wBACJ,oBAAoB;EAClB,QAAQ;EACR,OAAO,EAAE,SAAS,EAAE,EAAE;EACvB,CAAC;AAEJ,iBAAgB;AAChB,OAAM;EACJ,GAAG;EACH,MAAM;EACN;EACA,KAAK;EACL,QAAQ,YAAY;EACpB,SAAS,IAAI,aAAa,QAA2B;EACrD,mBAAmB,kBAAkB;AACnC,qBAAkB,cAAc;;EAElC,qBAAqB,kBAAkB;AACrC,iBAAc;AACd,oBAAiB;AACjB,sBAAmB,cAAc;;EAEpC,CAAC,CACC,MAAM,aAAa;AAClB,YAAU;GAAE,MAAM,SAAS;GAAM,QAAQ,SAAS;GAAQ,OAAO,EAAE,SAAS,SAAS,SAAS;GAAE,CAAC;AACjG,iBAAe;GACf,CACD,OAAO,UAAU;AAChB,UAAQ;GACN;GACA,QAAQ,MAAM,UAAU,UAAU,QAAQ;GAC1C,OAAO,EAAE,SAAS,MAAM,UAAU,SAAS;GAC5C,CAAC;GACF,CACD,cAAc;AACb,mBAAiB;GACjB;EAEP"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyper-fetch/axios",
3
- "version": "8.1.0",
3
+ "version": "8.2.0",
4
4
  "description": "Simple axios adapter for Hyper Fetch",
5
5
  "author": "Maciej Pyrc <maciekpyrc@gmail.com>, Kacper Skawina <kacper.skawina@gmail.com>",
6
6
  "homepage": "https://hyperfetch.bettertyped.com/",
@@ -6,6 +6,7 @@ import type { AxiosExtra, RawAxiosHeaders } from "./adapter.types";
6
6
 
7
7
  export type AxiosAdapterType = typeof AxiosAdapter;
8
8
 
9
+ /** Pre-configured adapter that uses Axios as the underlying HTTP transport. Supports upload/download progress and abort. */
9
10
  export const AxiosAdapter = new Adapter<
10
11
  Omit<AxiosRequestConfig, "url" | "baseURL" | "method" | "onUploadProgress" | "onDownloadProgress" | "data">,
11
12
  AxiosMethods,